🚀. Socket Launch Week Day 2:Introducing Manifest Alerts.Learn more
Sign In

@react-stately/utils

Package Overview
Dependencies
Maintainers
2
Versions
1321
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-stately/utils - npm Package Compare versions

Comparing version
3.11.0
to
3.12.0
+2
dist/types/src/index.d.ts
export { useControlledState } from 'react-stately/useControlledState';
export { clamp, snapValueToStep, toFixedNumber } from 'react-stately/private/utils/number';
+3
-3

@@ -1,3 +0,3 @@

import {useControlledState as $458b0a5536c1a7cf$export$40bfa8c7b0832715} from "./useControlledState.mjs";
import {clamp as $9446cca9a3875146$export$7d15b64cf5a3a4c4, snapValueToStep as $9446cca9a3875146$export$cb6e0bb50bc19463, toFixedNumber as $9446cca9a3875146$export$b6268554fba451f} from "./number.mjs";
import {useControlledState as $fd7ccfc2ebe0ae74$re_export$useControlledState} from "react-stately/useControlledState";
import {clamp as $fd7ccfc2ebe0ae74$re_export$clamp, snapValueToStep as $fd7ccfc2ebe0ae74$re_export$snapValueToStep, toFixedNumber as $fd7ccfc2ebe0ae74$re_export$toFixedNumber} from "react-stately/private/utils/number";

@@ -18,3 +18,3 @@ /*

export {$458b0a5536c1a7cf$export$40bfa8c7b0832715 as useControlledState, $9446cca9a3875146$export$7d15b64cf5a3a4c4 as clamp, $9446cca9a3875146$export$cb6e0bb50bc19463 as snapValueToStep, $9446cca9a3875146$export$b6268554fba451f as toFixedNumber};
export {$fd7ccfc2ebe0ae74$re_export$useControlledState as useControlledState, $fd7ccfc2ebe0ae74$re_export$clamp as clamp, $fd7ccfc2ebe0ae74$re_export$snapValueToStep as snapValueToStep, $fd7ccfc2ebe0ae74$re_export$toFixedNumber as toFixedNumber};
//# sourceMappingURL=module.js.map

@@ -1,3 +0,3 @@

var $8d8fdfab47455712$exports = require("./useControlledState.main.js");
var $ac8e4d4816275668$exports = require("./number.main.js");
var $g1Hlx$reactstatelyuseControlledState = require("react-stately/useControlledState");
var $g1Hlx$reactstatelyprivateutilsnumber = require("react-stately/private/utils/number");

@@ -9,6 +9,6 @@

$parcel$export(module.exports, "useControlledState", () => $8d8fdfab47455712$exports.useControlledState);
$parcel$export(module.exports, "clamp", () => $ac8e4d4816275668$exports.clamp);
$parcel$export(module.exports, "snapValueToStep", () => $ac8e4d4816275668$exports.snapValueToStep);
$parcel$export(module.exports, "toFixedNumber", () => $ac8e4d4816275668$exports.toFixedNumber);
$parcel$export(module.exports, "useControlledState", function () { return $g1Hlx$reactstatelyuseControlledState.useControlledState; });
$parcel$export(module.exports, "clamp", function () { return $g1Hlx$reactstatelyprivateutilsnumber.clamp; });
$parcel$export(module.exports, "snapValueToStep", function () { return $g1Hlx$reactstatelyprivateutilsnumber.snapValueToStep; });
$parcel$export(module.exports, "toFixedNumber", function () { return $g1Hlx$reactstatelyprivateutilsnumber.toFixedNumber; });
/*

@@ -15,0 +15,0 @@ * Copyright 2020 Adobe. All rights reserved.

@@ -1,1 +0,1 @@

{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useControlledState} from './useControlledState';\nexport {clamp, snapValueToStep, toFixedNumber} from './number';\n"],"names":[],"version":3,"file":"main.js.map"}
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useControlledState} from 'react-stately/useControlledState';\n\nexport {clamp, snapValueToStep, toFixedNumber} from 'react-stately/private/utils/number';\n"],"names":[],"version":3,"file":"main.js.map"}

@@ -1,3 +0,3 @@

import {useControlledState as $458b0a5536c1a7cf$export$40bfa8c7b0832715} from "./useControlledState.module.js";
import {clamp as $9446cca9a3875146$export$7d15b64cf5a3a4c4, snapValueToStep as $9446cca9a3875146$export$cb6e0bb50bc19463, toFixedNumber as $9446cca9a3875146$export$b6268554fba451f} from "./number.module.js";
import {useControlledState as $fd7ccfc2ebe0ae74$re_export$useControlledState} from "react-stately/useControlledState";
import {clamp as $fd7ccfc2ebe0ae74$re_export$clamp, snapValueToStep as $fd7ccfc2ebe0ae74$re_export$snapValueToStep, toFixedNumber as $fd7ccfc2ebe0ae74$re_export$toFixedNumber} from "react-stately/private/utils/number";

@@ -18,3 +18,3 @@ /*

export {$458b0a5536c1a7cf$export$40bfa8c7b0832715 as useControlledState, $9446cca9a3875146$export$7d15b64cf5a3a4c4 as clamp, $9446cca9a3875146$export$cb6e0bb50bc19463 as snapValueToStep, $9446cca9a3875146$export$b6268554fba451f as toFixedNumber};
export {$fd7ccfc2ebe0ae74$re_export$useControlledState as useControlledState, $fd7ccfc2ebe0ae74$re_export$clamp as clamp, $fd7ccfc2ebe0ae74$re_export$snapValueToStep as snapValueToStep, $fd7ccfc2ebe0ae74$re_export$toFixedNumber as toFixedNumber};
//# sourceMappingURL=module.js.map

@@ -1,1 +0,1 @@

{"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useControlledState} from './useControlledState';\nexport {clamp, snapValueToStep, toFixedNumber} from './number';\n"],"names":[],"version":3,"file":"module.js.map"}
{"mappings":";;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-stately/utils/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useControlledState} from 'react-stately/useControlledState';\n\nexport {clamp, snapValueToStep, toFixedNumber} from 'react-stately/private/utils/number';\n"],"names":[],"version":3,"file":"module.js.map"}
{
"name": "@react-stately/utils",
"version": "3.11.0",
"version": "3.12.0",
"description": "Spectrum UI components in React",

@@ -9,11 +9,11 @@ "license": "Apache-2.0",

"exports": {
"source": "./src/index.ts",
"types": [
"./dist/types.d.ts",
"./src/index.ts"
],
"import": "./dist/import.mjs",
"require": "./dist/main.js"
".": {
"source": "./src/index.ts",
"types": "./dist/types/src/index.d.ts",
"import": "./dist/import.mjs",
"require": "./dist/main.js"
},
"./package.json": "./package.json"
},
"types": "dist/types.d.ts",
"types": "dist/types/src/index.d.ts",
"source": "src/index.ts",

@@ -30,6 +30,8 @@ "files": [

"peerDependencies": {
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1",
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1"
},
"dependencies": {
"@swc/helpers": "^0.5.0"
"@swc/helpers": "^0.5.0",
"react-stately": "3.46.0"
},

@@ -39,3 +41,6 @@ "publishConfig": {

},
"gitHead": "4d838da5bfe36abb35aed166995a9ef63825370f"
"targets": {
"types": false
},
"gitHead": "a6999bdf494a2e9c0381a5881908328bdd22ddae"
}

@@ -12,3 +12,4 @@ /*

*/
export {useControlledState} from './useControlledState';
export {clamp, snapValueToStep, toFixedNumber} from './number';
export {useControlledState} from 'react-stately/useControlledState';
export {clamp, snapValueToStep, toFixedNumber} from 'react-stately/private/utils/number';
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$export(module.exports, "clamp", () => $ac8e4d4816275668$export$7d15b64cf5a3a4c4);
$parcel$export(module.exports, "snapValueToStep", () => $ac8e4d4816275668$export$cb6e0bb50bc19463);
$parcel$export(module.exports, "toFixedNumber", () => $ac8e4d4816275668$export$b6268554fba451f);
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/ /**
* Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step.
*/ function $ac8e4d4816275668$export$7d15b64cf5a3a4c4(value, min = -Infinity, max = Infinity) {
let newValue = Math.min(Math.max(value, min), max);
return newValue;
}
function $ac8e4d4816275668$export$e1a7b8e69ef6c52f(value, step) {
let roundedValue = value;
let precision = 0;
let stepString = step.toString();
// Handle negative exponents in exponential notation (e.g., "1e-7" → precision 8)
let eIndex = stepString.toLowerCase().indexOf('e-');
if (eIndex > 0) precision = Math.abs(Math.floor(Math.log10(Math.abs(step)))) + eIndex;
else {
let pointIndex = stepString.indexOf('.');
if (pointIndex >= 0) precision = stepString.length - pointIndex;
}
if (precision > 0) {
let pow = Math.pow(10, precision);
roundedValue = Math.round(roundedValue * pow) / pow;
}
return roundedValue;
}
function $ac8e4d4816275668$export$cb6e0bb50bc19463(value, min, max, step) {
min = Number(min);
max = Number(max);
let remainder = (value - (isNaN(min) ? 0 : min)) % step;
let snappedValue = $ac8e4d4816275668$export$e1a7b8e69ef6c52f(Math.abs(remainder) * 2 >= step ? value + Math.sign(remainder) * (step - Math.abs(remainder)) : value - remainder, step);
if (!isNaN(min)) {
if (snappedValue < min) snappedValue = min;
else if (!isNaN(max) && snappedValue > max) snappedValue = min + Math.floor($ac8e4d4816275668$export$e1a7b8e69ef6c52f((max - min) / step, step)) * step;
} else if (!isNaN(max) && snappedValue > max) snappedValue = Math.floor($ac8e4d4816275668$export$e1a7b8e69ef6c52f(max / step, step)) * step;
// correct floating point behavior by rounding to step precision
snappedValue = $ac8e4d4816275668$export$e1a7b8e69ef6c52f(snappedValue, step);
return snappedValue;
}
function $ac8e4d4816275668$export$b6268554fba451f(value, digits, base = 10) {
const pow = Math.pow(base, digits);
return Math.round(value * pow) / pow;
}
//# sourceMappingURL=number.main.js.map
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC,GAED;;CAEC,GACM,SAAS,0CAAM,KAAa,EAAE,MAAc,CAAC,QAAQ,EAAE,MAAc,QAAQ;IAClF,IAAI,WAAW,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,OAAO,MAAM;IAC9C,OAAO;AACT;AAEO,SAAS,0CAAqB,KAAa,EAAE,IAAY;IAC9D,IAAI,eAAe;IACnB,IAAI,YAAY;IAChB,IAAI,aAAa,KAAK,QAAQ;IAC9B,iFAAiF;IACjF,IAAI,SAAS,WAAW,WAAW,GAAG,OAAO,CAAC;IAC9C,IAAI,SAAS,GACX,YAAY,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC,WAAW;SAC1D;QACL,IAAI,aAAa,WAAW,OAAO,CAAC;QACpC,IAAI,cAAc,GAChB,YAAY,WAAW,MAAM,GAAG;IAEpC;IACA,IAAI,YAAY,GAAG;QACjB,IAAI,MAAM,KAAK,GAAG,CAAC,IAAI;QACvB,eAAe,KAAK,KAAK,CAAC,eAAe,OAAO;IAClD;IACA,OAAO;AACT;AAEO,SAAS,0CAAgB,KAAa,EAAE,GAAuB,EAAE,GAAuB,EAAE,IAAY;IAC3G,MAAM,OAAO;IACb,MAAM,OAAO;IACb,IAAI,YAAa,AAAC,CAAA,QAAS,CAAA,MAAM,OAAO,IAAI,GAAE,CAAC,IAAK;IACpD,IAAI,eAAe,0CAAqB,KAAK,GAAG,CAAC,aAAa,KAAK,OAC/D,QAAQ,KAAK,IAAI,CAAC,aAAc,CAAA,OAAO,KAAK,GAAG,CAAC,UAAS,IACzD,QAAQ,WAAW;IAEvB,IAAI,CAAC,MAAM,MAAM;QACf,IAAI,eAAe,KACjB,eAAe;aACV,IAAI,CAAC,MAAM,QAAQ,eAAe,KACvC,eAAe,MAAM,KAAK,KAAK,CAAC,0CAAqB,AAAC,CAAA,MAAM,GAAE,IAAK,MAAM,SAAS;IAEtF,OAAO,IAAI,CAAC,MAAM,QAAQ,eAAe,KACvC,eAAe,KAAK,KAAK,CAAC,0CAAqB,MAAM,MAAM,SAAS;IAGtE,gEAAgE;IAChE,eAAe,0CAAqB,cAAc;IAElD,OAAO;AACT;AAGO,SAAS,yCAAc,KAAa,EAAE,MAAc,EAAE,OAAe,EAAE;IAC5E,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM;IAE3B,OAAO,KAAK,KAAK,CAAC,QAAQ,OAAO;AACnC","sources":["packages/@react-stately/utils/src/number.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n/**\n * Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step.\n */\nexport function clamp(value: number, min: number = -Infinity, max: number = Infinity): number {\n let newValue = Math.min(Math.max(value, min), max);\n return newValue;\n}\n\nexport function roundToStepPrecision(value: number, step: number): number {\n let roundedValue = value;\n let precision = 0;\n let stepString = step.toString();\n // Handle negative exponents in exponential notation (e.g., \"1e-7\" → precision 8)\n let eIndex = stepString.toLowerCase().indexOf('e-');\n if (eIndex > 0) {\n precision = Math.abs(Math.floor(Math.log10(Math.abs(step)))) + eIndex;\n } else {\n let pointIndex = stepString.indexOf('.');\n if (pointIndex >= 0) {\n precision = stepString.length - pointIndex;\n }\n }\n if (precision > 0) {\n let pow = Math.pow(10, precision);\n roundedValue = Math.round(roundedValue * pow) / pow;\n }\n return roundedValue;\n}\n\nexport function snapValueToStep(value: number, min: number | undefined, max: number | undefined, step: number): number {\n min = Number(min);\n max = Number(max);\n let remainder = ((value - (isNaN(min) ? 0 : min)) % step);\n let snappedValue = roundToStepPrecision(Math.abs(remainder) * 2 >= step\n ? value + Math.sign(remainder) * (step - Math.abs(remainder))\n : value - remainder, step);\n\n if (!isNaN(min)) {\n if (snappedValue < min) {\n snappedValue = min;\n } else if (!isNaN(max) && snappedValue > max) {\n snappedValue = min + Math.floor(roundToStepPrecision((max - min) / step, step)) * step;\n }\n } else if (!isNaN(max) && snappedValue > max) {\n snappedValue = Math.floor(roundToStepPrecision(max / step, step)) * step;\n }\n\n // correct floating point behavior by rounding to step precision\n snappedValue = roundToStepPrecision(snappedValue, step);\n\n return snappedValue;\n}\n\n/* Takes a value and rounds off to the number of digits. */\nexport function toFixedNumber(value: number, digits: number, base: number = 10): number {\n const pow = Math.pow(base, digits);\n\n return Math.round(value * pow) / pow;\n}\n"],"names":[],"version":3,"file":"number.main.js.map"}
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/ /**
* Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step.
*/ function $9446cca9a3875146$export$7d15b64cf5a3a4c4(value, min = -Infinity, max = Infinity) {
let newValue = Math.min(Math.max(value, min), max);
return newValue;
}
function $9446cca9a3875146$export$e1a7b8e69ef6c52f(value, step) {
let roundedValue = value;
let precision = 0;
let stepString = step.toString();
// Handle negative exponents in exponential notation (e.g., "1e-7" → precision 8)
let eIndex = stepString.toLowerCase().indexOf('e-');
if (eIndex > 0) precision = Math.abs(Math.floor(Math.log10(Math.abs(step)))) + eIndex;
else {
let pointIndex = stepString.indexOf('.');
if (pointIndex >= 0) precision = stepString.length - pointIndex;
}
if (precision > 0) {
let pow = Math.pow(10, precision);
roundedValue = Math.round(roundedValue * pow) / pow;
}
return roundedValue;
}
function $9446cca9a3875146$export$cb6e0bb50bc19463(value, min, max, step) {
min = Number(min);
max = Number(max);
let remainder = (value - (isNaN(min) ? 0 : min)) % step;
let snappedValue = $9446cca9a3875146$export$e1a7b8e69ef6c52f(Math.abs(remainder) * 2 >= step ? value + Math.sign(remainder) * (step - Math.abs(remainder)) : value - remainder, step);
if (!isNaN(min)) {
if (snappedValue < min) snappedValue = min;
else if (!isNaN(max) && snappedValue > max) snappedValue = min + Math.floor($9446cca9a3875146$export$e1a7b8e69ef6c52f((max - min) / step, step)) * step;
} else if (!isNaN(max) && snappedValue > max) snappedValue = Math.floor($9446cca9a3875146$export$e1a7b8e69ef6c52f(max / step, step)) * step;
// correct floating point behavior by rounding to step precision
snappedValue = $9446cca9a3875146$export$e1a7b8e69ef6c52f(snappedValue, step);
return snappedValue;
}
function $9446cca9a3875146$export$b6268554fba451f(value, digits, base = 10) {
const pow = Math.pow(base, digits);
return Math.round(value * pow) / pow;
}
export {$9446cca9a3875146$export$7d15b64cf5a3a4c4 as clamp, $9446cca9a3875146$export$e1a7b8e69ef6c52f as roundToStepPrecision, $9446cca9a3875146$export$cb6e0bb50bc19463 as snapValueToStep, $9446cca9a3875146$export$b6268554fba451f as toFixedNumber};
//# sourceMappingURL=number.module.js.map
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/ /**
* Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step.
*/ function $9446cca9a3875146$export$7d15b64cf5a3a4c4(value, min = -Infinity, max = Infinity) {
let newValue = Math.min(Math.max(value, min), max);
return newValue;
}
function $9446cca9a3875146$export$e1a7b8e69ef6c52f(value, step) {
let roundedValue = value;
let precision = 0;
let stepString = step.toString();
// Handle negative exponents in exponential notation (e.g., "1e-7" → precision 8)
let eIndex = stepString.toLowerCase().indexOf('e-');
if (eIndex > 0) precision = Math.abs(Math.floor(Math.log10(Math.abs(step)))) + eIndex;
else {
let pointIndex = stepString.indexOf('.');
if (pointIndex >= 0) precision = stepString.length - pointIndex;
}
if (precision > 0) {
let pow = Math.pow(10, precision);
roundedValue = Math.round(roundedValue * pow) / pow;
}
return roundedValue;
}
function $9446cca9a3875146$export$cb6e0bb50bc19463(value, min, max, step) {
min = Number(min);
max = Number(max);
let remainder = (value - (isNaN(min) ? 0 : min)) % step;
let snappedValue = $9446cca9a3875146$export$e1a7b8e69ef6c52f(Math.abs(remainder) * 2 >= step ? value + Math.sign(remainder) * (step - Math.abs(remainder)) : value - remainder, step);
if (!isNaN(min)) {
if (snappedValue < min) snappedValue = min;
else if (!isNaN(max) && snappedValue > max) snappedValue = min + Math.floor($9446cca9a3875146$export$e1a7b8e69ef6c52f((max - min) / step, step)) * step;
} else if (!isNaN(max) && snappedValue > max) snappedValue = Math.floor($9446cca9a3875146$export$e1a7b8e69ef6c52f(max / step, step)) * step;
// correct floating point behavior by rounding to step precision
snappedValue = $9446cca9a3875146$export$e1a7b8e69ef6c52f(snappedValue, step);
return snappedValue;
}
function $9446cca9a3875146$export$b6268554fba451f(value, digits, base = 10) {
const pow = Math.pow(base, digits);
return Math.round(value * pow) / pow;
}
export {$9446cca9a3875146$export$7d15b64cf5a3a4c4 as clamp, $9446cca9a3875146$export$e1a7b8e69ef6c52f as roundToStepPrecision, $9446cca9a3875146$export$cb6e0bb50bc19463 as snapValueToStep, $9446cca9a3875146$export$b6268554fba451f as toFixedNumber};
//# sourceMappingURL=number.module.js.map
{"mappings":"AAAA;;;;;;;;;;CAUC,GAED;;CAEC,GACM,SAAS,0CAAM,KAAa,EAAE,MAAc,CAAC,QAAQ,EAAE,MAAc,QAAQ;IAClF,IAAI,WAAW,KAAK,GAAG,CAAC,KAAK,GAAG,CAAC,OAAO,MAAM;IAC9C,OAAO;AACT;AAEO,SAAS,0CAAqB,KAAa,EAAE,IAAY;IAC9D,IAAI,eAAe;IACnB,IAAI,YAAY;IAChB,IAAI,aAAa,KAAK,QAAQ;IAC9B,iFAAiF;IACjF,IAAI,SAAS,WAAW,WAAW,GAAG,OAAO,CAAC;IAC9C,IAAI,SAAS,GACX,YAAY,KAAK,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK,KAAK,CAAC,KAAK,GAAG,CAAC,WAAW;SAC1D;QACL,IAAI,aAAa,WAAW,OAAO,CAAC;QACpC,IAAI,cAAc,GAChB,YAAY,WAAW,MAAM,GAAG;IAEpC;IACA,IAAI,YAAY,GAAG;QACjB,IAAI,MAAM,KAAK,GAAG,CAAC,IAAI;QACvB,eAAe,KAAK,KAAK,CAAC,eAAe,OAAO;IAClD;IACA,OAAO;AACT;AAEO,SAAS,0CAAgB,KAAa,EAAE,GAAuB,EAAE,GAAuB,EAAE,IAAY;IAC3G,MAAM,OAAO;IACb,MAAM,OAAO;IACb,IAAI,YAAa,AAAC,CAAA,QAAS,CAAA,MAAM,OAAO,IAAI,GAAE,CAAC,IAAK;IACpD,IAAI,eAAe,0CAAqB,KAAK,GAAG,CAAC,aAAa,KAAK,OAC/D,QAAQ,KAAK,IAAI,CAAC,aAAc,CAAA,OAAO,KAAK,GAAG,CAAC,UAAS,IACzD,QAAQ,WAAW;IAEvB,IAAI,CAAC,MAAM,MAAM;QACf,IAAI,eAAe,KACjB,eAAe;aACV,IAAI,CAAC,MAAM,QAAQ,eAAe,KACvC,eAAe,MAAM,KAAK,KAAK,CAAC,0CAAqB,AAAC,CAAA,MAAM,GAAE,IAAK,MAAM,SAAS;IAEtF,OAAO,IAAI,CAAC,MAAM,QAAQ,eAAe,KACvC,eAAe,KAAK,KAAK,CAAC,0CAAqB,MAAM,MAAM,SAAS;IAGtE,gEAAgE;IAChE,eAAe,0CAAqB,cAAc;IAElD,OAAO;AACT;AAGO,SAAS,yCAAc,KAAa,EAAE,MAAc,EAAE,OAAe,EAAE;IAC5E,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM;IAE3B,OAAO,KAAK,KAAK,CAAC,QAAQ,OAAO;AACnC","sources":["packages/@react-stately/utils/src/number.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n/**\n * Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step.\n */\nexport function clamp(value: number, min: number = -Infinity, max: number = Infinity): number {\n let newValue = Math.min(Math.max(value, min), max);\n return newValue;\n}\n\nexport function roundToStepPrecision(value: number, step: number): number {\n let roundedValue = value;\n let precision = 0;\n let stepString = step.toString();\n // Handle negative exponents in exponential notation (e.g., \"1e-7\" → precision 8)\n let eIndex = stepString.toLowerCase().indexOf('e-');\n if (eIndex > 0) {\n precision = Math.abs(Math.floor(Math.log10(Math.abs(step)))) + eIndex;\n } else {\n let pointIndex = stepString.indexOf('.');\n if (pointIndex >= 0) {\n precision = stepString.length - pointIndex;\n }\n }\n if (precision > 0) {\n let pow = Math.pow(10, precision);\n roundedValue = Math.round(roundedValue * pow) / pow;\n }\n return roundedValue;\n}\n\nexport function snapValueToStep(value: number, min: number | undefined, max: number | undefined, step: number): number {\n min = Number(min);\n max = Number(max);\n let remainder = ((value - (isNaN(min) ? 0 : min)) % step);\n let snappedValue = roundToStepPrecision(Math.abs(remainder) * 2 >= step\n ? value + Math.sign(remainder) * (step - Math.abs(remainder))\n : value - remainder, step);\n\n if (!isNaN(min)) {\n if (snappedValue < min) {\n snappedValue = min;\n } else if (!isNaN(max) && snappedValue > max) {\n snappedValue = min + Math.floor(roundToStepPrecision((max - min) / step, step)) * step;\n }\n } else if (!isNaN(max) && snappedValue > max) {\n snappedValue = Math.floor(roundToStepPrecision(max / step, step)) * step;\n }\n\n // correct floating point behavior by rounding to step precision\n snappedValue = roundToStepPrecision(snappedValue, step);\n\n return snappedValue;\n}\n\n/* Takes a value and rounds off to the number of digits. */\nexport function toFixedNumber(value: number, digits: number, base: number = 10): number {\n const pow = Math.pow(base, digits);\n\n return Math.round(value * pow) / pow;\n}\n"],"names":[],"version":3,"file":"number.module.js.map"}
import { SetStateAction } from "react";
export function useControlledState<T, C = T>(value: Exclude<T, undefined>, defaultValue: Exclude<T, undefined> | undefined, onChange?: (v: C, ...args: any[]) => void): [T, (value: SetStateAction<T>, ...args: any[]) => void];
export function useControlledState<T, C = T>(value: Exclude<T, undefined> | undefined, defaultValue: Exclude<T, undefined>, onChange?: (v: C, ...args: any[]) => void): [T, (value: SetStateAction<T>, ...args: any[]) => void];
/**
* Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step.
*/
export function clamp(value: number, min?: number, max?: number): number;
export function snapValueToStep(value: number, min: number | undefined, max: number | undefined, step: number): number;
export function toFixedNumber(value: number, digits: number, base?: number): number;
//# sourceMappingURL=types.d.ts.map
{"mappings":";AAmBA,mCAAmC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,SAAS,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC;AAChO,mCAAmC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,GAAG,SAAS,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,CAAC,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,CAAC;ACRhO;;GAEG;AACH,sBAAsB,KAAK,EAAE,MAAM,EAAE,GAAG,GAAE,MAAkB,EAAE,GAAG,GAAE,MAAiB,GAAG,MAAM,CAG5F;AAuBD,gCAAgC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAsBrH;AAGD,8BAA8B,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,GAAE,MAAW,GAAG,MAAM,CAItF","sources":["packages/@react-stately/utils/src/packages/@react-stately/utils/src/useControlledState.ts","packages/@react-stately/utils/src/packages/@react-stately/utils/src/number.ts","packages/@react-stately/utils/src/packages/@react-stately/utils/src/index.ts","packages/@react-stately/utils/src/index.ts"],"sourcesContent":[null,null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useControlledState} from './useControlledState';\nexport {clamp, snapValueToStep, toFixedNumber} from './number';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
var $ecn6s$react = require("react");
function $parcel$interopDefault(a) {
return a && a.__esModule ? a.default : a;
}
function $parcel$export(e, n, v, s) {
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
}
$parcel$export(module.exports, "useControlledState", () => $8d8fdfab47455712$export$40bfa8c7b0832715);
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
var $8d8fdfab47455712$var$_React_useInsertionEffect;
// Use the earliest effect possible to reset the ref below.
const $8d8fdfab47455712$var$useEarlyEffect = typeof document !== 'undefined' ? ($8d8fdfab47455712$var$_React_useInsertionEffect = (0, ($parcel$interopDefault($ecn6s$react)))['useInsertionEffect']) !== null && $8d8fdfab47455712$var$_React_useInsertionEffect !== void 0 ? $8d8fdfab47455712$var$_React_useInsertionEffect : (0, ($parcel$interopDefault($ecn6s$react))).useLayoutEffect : ()=>{};
function $8d8fdfab47455712$export$40bfa8c7b0832715(value, defaultValue, onChange) {
// Store the value in both state and a ref. The state value will only be used when uncontrolled.
// The ref is used to track the most current value, which is passed to the function setState callback.
let [stateValue, setStateValue] = (0, $ecn6s$react.useState)(value || defaultValue);
let valueRef = (0, $ecn6s$react.useRef)(stateValue);
let isControlledRef = (0, $ecn6s$react.useRef)(value !== undefined);
let isControlled = value !== undefined;
(0, $ecn6s$react.useEffect)(()=>{
let wasControlled = isControlledRef.current;
if (wasControlled !== isControlled && process.env.NODE_ENV !== 'production') console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`);
isControlledRef.current = isControlled;
}, [
isControlled
]);
// After each render, update the ref to the current value.
// This ensures that the setState callback argument is reset.
// Note: the effect should not have any dependencies so that controlled values always reset.
let currentValue = isControlled ? value : stateValue;
$8d8fdfab47455712$var$useEarlyEffect(()=>{
valueRef.current = currentValue;
});
let [, forceUpdate] = (0, $ecn6s$react.useReducer)(()=>({}), {});
let setValue = (0, $ecn6s$react.useCallback)((value, ...args)=>{
// @ts-ignore - TS doesn't know that T cannot be a function.
let newValue = typeof value === 'function' ? value(valueRef.current) : value;
if (!Object.is(valueRef.current, newValue)) {
// Update the ref so that the next setState callback has the most recent value.
valueRef.current = newValue;
setStateValue(newValue);
// Always trigger a re-render, even when controlled, so that the layout effect above runs to reset the value.
forceUpdate();
// Trigger onChange. Note that if setState is called multiple times in a single event,
// onChange will be called for each one instead of only once.
onChange === null || onChange === void 0 ? void 0 : onChange(newValue, ...args);
}
}, [
onChange
]);
return [
currentValue,
setValue
];
}
//# sourceMappingURL=useControlledState.main.js.map
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;IAMG;AAFJ,2DAA2D;AAC3D,MAAM,uCAA+C,OAAO,aAAa,cACrE,CAAA,kDAAA,CAAA,GAAA,sCAAI,CAAC,CAAC,qBAAqB,cAA3B,6DAAA,kDAA+B,CAAA,GAAA,sCAAI,EAAE,eAAe,GACpD,KAAO;AAIJ,SAAS,0CAA6B,KAAQ,EAAE,YAAe,EAAE,QAAyC;IAC/G,gGAAgG;IAChG,sGAAsG;IACtG,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,qBAAO,EAAE,SAAS;IACpD,IAAI,WAAW,CAAA,GAAA,mBAAK,EAAE;IAEtB,IAAI,kBAAkB,CAAA,GAAA,mBAAK,EAAE,UAAU;IACvC,IAAI,eAAe,UAAU;IAC7B,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,gBAAgB,gBAAgB,OAAO;QAC3C,IAAI,kBAAkB,gBAAgB,QAAQ,GAAG,CAAC,QAAQ,KAAK,cAC7D,QAAQ,IAAI,CAAC,CAAC,+BAA+B,EAAE,gBAAgB,eAAe,eAAe,IAAI,EAAE,eAAe,eAAe,eAAe,CAAC,CAAC;QAEpJ,gBAAgB,OAAO,GAAG;IAC5B,GAAG;QAAC;KAAa;IAEjB,0DAA0D;IAC1D,6DAA6D;IAC7D,4FAA4F;IAC5F,IAAI,eAAe,eAAe,QAAQ;IAC1C,qCAAe;QACb,SAAS,OAAO,GAAG;IACrB;IAEA,IAAI,GAAG,YAAY,GAAG,CAAA,GAAA,uBAAS,EAAE,IAAO,CAAA,CAAC,CAAA,GAAI,CAAC;IAC9C,IAAI,WAAW,CAAA,GAAA,wBAAU,EAAE,CAAC,OAA0B,GAAG;QACvD,4DAA4D;QAC5D,IAAI,WAAW,OAAO,UAAU,aAAa,MAAM,SAAS,OAAO,IAAI;QACvE,IAAI,CAAC,OAAO,EAAE,CAAC,SAAS,OAAO,EAAE,WAAW;YAC1C,+EAA+E;YAC/E,SAAS,OAAO,GAAG;YAEnB,cAAc;YAEd,6GAA6G;YAC7G;YAEA,sFAAsF;YACtF,6DAA6D;YAC7D,qBAAA,+BAAA,SAAW,aAAa;QAC1B;IACF,GAAG;QAAC;KAAS;IAEb,OAAO;QAAC;QAAc;KAAS;AACjC","sources":["packages/@react-stately/utils/src/useControlledState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport React, {SetStateAction, useCallback, useEffect, useReducer, useRef, useState} from 'react';\n\n// Use the earliest effect possible to reset the ref below.\nconst useEarlyEffect: typeof React.useLayoutEffect = typeof document !== 'undefined'\n ? React['useInsertionEffect'] ?? React.useLayoutEffect\n : () => {};\n\nexport function useControlledState<T, C = T>(value: Exclude<T, undefined>, defaultValue: Exclude<T, undefined> | undefined, onChange?: (v: C, ...args: any[]) => void): [T, (value: SetStateAction<T>, ...args: any[]) => void];\nexport function useControlledState<T, C = T>(value: Exclude<T, undefined> | undefined, defaultValue: Exclude<T, undefined>, onChange?: (v: C, ...args: any[]) => void): [T, (value: SetStateAction<T>, ...args: any[]) => void];\nexport function useControlledState<T, C = T>(value: T, defaultValue: T, onChange?: (v: C, ...args: any[]) => void): [T, (value: SetStateAction<T>, ...args: any[]) => void] {\n // Store the value in both state and a ref. The state value will only be used when uncontrolled.\n // The ref is used to track the most current value, which is passed to the function setState callback.\n let [stateValue, setStateValue] = useState(value || defaultValue);\n let valueRef = useRef(stateValue);\n\n let isControlledRef = useRef(value !== undefined);\n let isControlled = value !== undefined;\n useEffect(() => {\n let wasControlled = isControlledRef.current;\n if (wasControlled !== isControlled && process.env.NODE_ENV !== 'production') {\n console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`);\n }\n isControlledRef.current = isControlled;\n }, [isControlled]);\n\n // After each render, update the ref to the current value.\n // This ensures that the setState callback argument is reset.\n // Note: the effect should not have any dependencies so that controlled values always reset.\n let currentValue = isControlled ? value : stateValue;\n useEarlyEffect(() => {\n valueRef.current = currentValue;\n });\n\n let [, forceUpdate] = useReducer(() => ({}), {});\n let setValue = useCallback((value: SetStateAction<T>, ...args: any[]) => {\n // @ts-ignore - TS doesn't know that T cannot be a function.\n let newValue = typeof value === 'function' ? value(valueRef.current) : value;\n if (!Object.is(valueRef.current, newValue)) {\n // Update the ref so that the next setState callback has the most recent value.\n valueRef.current = newValue;\n\n setStateValue(newValue);\n\n // Always trigger a re-render, even when controlled, so that the layout effect above runs to reset the value.\n forceUpdate();\n\n // Trigger onChange. Note that if setState is called multiple times in a single event,\n // onChange will be called for each one instead of only once.\n onChange?.(newValue, ...args);\n }\n }, [onChange]);\n\n return [currentValue, setValue];\n}\n"],"names":[],"version":3,"file":"useControlledState.main.js.map"}
import $3whtM$react, {useState as $3whtM$useState, useRef as $3whtM$useRef, useEffect as $3whtM$useEffect, useReducer as $3whtM$useReducer, useCallback as $3whtM$useCallback} from "react";
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
var $458b0a5536c1a7cf$var$_React_useInsertionEffect;
// Use the earliest effect possible to reset the ref below.
const $458b0a5536c1a7cf$var$useEarlyEffect = typeof document !== 'undefined' ? ($458b0a5536c1a7cf$var$_React_useInsertionEffect = (0, $3whtM$react)['useInsertionEffect']) !== null && $458b0a5536c1a7cf$var$_React_useInsertionEffect !== void 0 ? $458b0a5536c1a7cf$var$_React_useInsertionEffect : (0, $3whtM$react).useLayoutEffect : ()=>{};
function $458b0a5536c1a7cf$export$40bfa8c7b0832715(value, defaultValue, onChange) {
// Store the value in both state and a ref. The state value will only be used when uncontrolled.
// The ref is used to track the most current value, which is passed to the function setState callback.
let [stateValue, setStateValue] = (0, $3whtM$useState)(value || defaultValue);
let valueRef = (0, $3whtM$useRef)(stateValue);
let isControlledRef = (0, $3whtM$useRef)(value !== undefined);
let isControlled = value !== undefined;
(0, $3whtM$useEffect)(()=>{
let wasControlled = isControlledRef.current;
if (wasControlled !== isControlled && process.env.NODE_ENV !== 'production') console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`);
isControlledRef.current = isControlled;
}, [
isControlled
]);
// After each render, update the ref to the current value.
// This ensures that the setState callback argument is reset.
// Note: the effect should not have any dependencies so that controlled values always reset.
let currentValue = isControlled ? value : stateValue;
$458b0a5536c1a7cf$var$useEarlyEffect(()=>{
valueRef.current = currentValue;
});
let [, forceUpdate] = (0, $3whtM$useReducer)(()=>({}), {});
let setValue = (0, $3whtM$useCallback)((value, ...args)=>{
// @ts-ignore - TS doesn't know that T cannot be a function.
let newValue = typeof value === 'function' ? value(valueRef.current) : value;
if (!Object.is(valueRef.current, newValue)) {
// Update the ref so that the next setState callback has the most recent value.
valueRef.current = newValue;
setStateValue(newValue);
// Always trigger a re-render, even when controlled, so that the layout effect above runs to reset the value.
forceUpdate();
// Trigger onChange. Note that if setState is called multiple times in a single event,
// onChange will be called for each one instead of only once.
onChange === null || onChange === void 0 ? void 0 : onChange(newValue, ...args);
}
}, [
onChange
]);
return [
currentValue,
setValue
];
}
export {$458b0a5536c1a7cf$export$40bfa8c7b0832715 as useControlledState};
//# sourceMappingURL=useControlledState.module.js.map
import $3whtM$react, {useState as $3whtM$useState, useRef as $3whtM$useRef, useEffect as $3whtM$useEffect, useReducer as $3whtM$useReducer, useCallback as $3whtM$useCallback} from "react";
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
var $458b0a5536c1a7cf$var$_React_useInsertionEffect;
// Use the earliest effect possible to reset the ref below.
const $458b0a5536c1a7cf$var$useEarlyEffect = typeof document !== 'undefined' ? ($458b0a5536c1a7cf$var$_React_useInsertionEffect = (0, $3whtM$react)['useInsertionEffect']) !== null && $458b0a5536c1a7cf$var$_React_useInsertionEffect !== void 0 ? $458b0a5536c1a7cf$var$_React_useInsertionEffect : (0, $3whtM$react).useLayoutEffect : ()=>{};
function $458b0a5536c1a7cf$export$40bfa8c7b0832715(value, defaultValue, onChange) {
// Store the value in both state and a ref. The state value will only be used when uncontrolled.
// The ref is used to track the most current value, which is passed to the function setState callback.
let [stateValue, setStateValue] = (0, $3whtM$useState)(value || defaultValue);
let valueRef = (0, $3whtM$useRef)(stateValue);
let isControlledRef = (0, $3whtM$useRef)(value !== undefined);
let isControlled = value !== undefined;
(0, $3whtM$useEffect)(()=>{
let wasControlled = isControlledRef.current;
if (wasControlled !== isControlled && process.env.NODE_ENV !== 'production') console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`);
isControlledRef.current = isControlled;
}, [
isControlled
]);
// After each render, update the ref to the current value.
// This ensures that the setState callback argument is reset.
// Note: the effect should not have any dependencies so that controlled values always reset.
let currentValue = isControlled ? value : stateValue;
$458b0a5536c1a7cf$var$useEarlyEffect(()=>{
valueRef.current = currentValue;
});
let [, forceUpdate] = (0, $3whtM$useReducer)(()=>({}), {});
let setValue = (0, $3whtM$useCallback)((value, ...args)=>{
// @ts-ignore - TS doesn't know that T cannot be a function.
let newValue = typeof value === 'function' ? value(valueRef.current) : value;
if (!Object.is(valueRef.current, newValue)) {
// Update the ref so that the next setState callback has the most recent value.
valueRef.current = newValue;
setStateValue(newValue);
// Always trigger a re-render, even when controlled, so that the layout effect above runs to reset the value.
forceUpdate();
// Trigger onChange. Note that if setState is called multiple times in a single event,
// onChange will be called for each one instead of only once.
onChange === null || onChange === void 0 ? void 0 : onChange(newValue, ...args);
}
}, [
onChange
]);
return [
currentValue,
setValue
];
}
export {$458b0a5536c1a7cf$export$40bfa8c7b0832715 as useControlledState};
//# sourceMappingURL=useControlledState.module.js.map
{"mappings":";;AAAA;;;;;;;;;;CAUC;IAMG;AAFJ,2DAA2D;AAC3D,MAAM,uCAA+C,OAAO,aAAa,cACrE,CAAA,kDAAA,CAAA,GAAA,YAAI,CAAC,CAAC,qBAAqB,cAA3B,6DAAA,kDAA+B,CAAA,GAAA,YAAI,EAAE,eAAe,GACpD,KAAO;AAIJ,SAAS,0CAA6B,KAAQ,EAAE,YAAe,EAAE,QAAyC;IAC/G,gGAAgG;IAChG,sGAAsG;IACtG,IAAI,CAAC,YAAY,cAAc,GAAG,CAAA,GAAA,eAAO,EAAE,SAAS;IACpD,IAAI,WAAW,CAAA,GAAA,aAAK,EAAE;IAEtB,IAAI,kBAAkB,CAAA,GAAA,aAAK,EAAE,UAAU;IACvC,IAAI,eAAe,UAAU;IAC7B,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,gBAAgB,gBAAgB,OAAO;QAC3C,IAAI,kBAAkB,gBAAgB,QAAQ,GAAG,CAAC,QAAQ,KAAK,cAC7D,QAAQ,IAAI,CAAC,CAAC,+BAA+B,EAAE,gBAAgB,eAAe,eAAe,IAAI,EAAE,eAAe,eAAe,eAAe,CAAC,CAAC;QAEpJ,gBAAgB,OAAO,GAAG;IAC5B,GAAG;QAAC;KAAa;IAEjB,0DAA0D;IAC1D,6DAA6D;IAC7D,4FAA4F;IAC5F,IAAI,eAAe,eAAe,QAAQ;IAC1C,qCAAe;QACb,SAAS,OAAO,GAAG;IACrB;IAEA,IAAI,GAAG,YAAY,GAAG,CAAA,GAAA,iBAAS,EAAE,IAAO,CAAA,CAAC,CAAA,GAAI,CAAC;IAC9C,IAAI,WAAW,CAAA,GAAA,kBAAU,EAAE,CAAC,OAA0B,GAAG;QACvD,4DAA4D;QAC5D,IAAI,WAAW,OAAO,UAAU,aAAa,MAAM,SAAS,OAAO,IAAI;QACvE,IAAI,CAAC,OAAO,EAAE,CAAC,SAAS,OAAO,EAAE,WAAW;YAC1C,+EAA+E;YAC/E,SAAS,OAAO,GAAG;YAEnB,cAAc;YAEd,6GAA6G;YAC7G;YAEA,sFAAsF;YACtF,6DAA6D;YAC7D,qBAAA,+BAAA,SAAW,aAAa;QAC1B;IACF,GAAG;QAAC;KAAS;IAEb,OAAO;QAAC;QAAc;KAAS;AACjC","sources":["packages/@react-stately/utils/src/useControlledState.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport React, {SetStateAction, useCallback, useEffect, useReducer, useRef, useState} from 'react';\n\n// Use the earliest effect possible to reset the ref below.\nconst useEarlyEffect: typeof React.useLayoutEffect = typeof document !== 'undefined'\n ? React['useInsertionEffect'] ?? React.useLayoutEffect\n : () => {};\n\nexport function useControlledState<T, C = T>(value: Exclude<T, undefined>, defaultValue: Exclude<T, undefined> | undefined, onChange?: (v: C, ...args: any[]) => void): [T, (value: SetStateAction<T>, ...args: any[]) => void];\nexport function useControlledState<T, C = T>(value: Exclude<T, undefined> | undefined, defaultValue: Exclude<T, undefined>, onChange?: (v: C, ...args: any[]) => void): [T, (value: SetStateAction<T>, ...args: any[]) => void];\nexport function useControlledState<T, C = T>(value: T, defaultValue: T, onChange?: (v: C, ...args: any[]) => void): [T, (value: SetStateAction<T>, ...args: any[]) => void] {\n // Store the value in both state and a ref. The state value will only be used when uncontrolled.\n // The ref is used to track the most current value, which is passed to the function setState callback.\n let [stateValue, setStateValue] = useState(value || defaultValue);\n let valueRef = useRef(stateValue);\n\n let isControlledRef = useRef(value !== undefined);\n let isControlled = value !== undefined;\n useEffect(() => {\n let wasControlled = isControlledRef.current;\n if (wasControlled !== isControlled && process.env.NODE_ENV !== 'production') {\n console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`);\n }\n isControlledRef.current = isControlled;\n }, [isControlled]);\n\n // After each render, update the ref to the current value.\n // This ensures that the setState callback argument is reset.\n // Note: the effect should not have any dependencies so that controlled values always reset.\n let currentValue = isControlled ? value : stateValue;\n useEarlyEffect(() => {\n valueRef.current = currentValue;\n });\n\n let [, forceUpdate] = useReducer(() => ({}), {});\n let setValue = useCallback((value: SetStateAction<T>, ...args: any[]) => {\n // @ts-ignore - TS doesn't know that T cannot be a function.\n let newValue = typeof value === 'function' ? value(valueRef.current) : value;\n if (!Object.is(valueRef.current, newValue)) {\n // Update the ref so that the next setState callback has the most recent value.\n valueRef.current = newValue;\n\n setStateValue(newValue);\n\n // Always trigger a re-render, even when controlled, so that the layout effect above runs to reset the value.\n forceUpdate();\n\n // Trigger onChange. Note that if setState is called multiple times in a single event,\n // onChange will be called for each one instead of only once.\n onChange?.(newValue, ...args);\n }\n }, [onChange]);\n\n return [currentValue, setValue];\n}\n"],"names":[],"version":3,"file":"useControlledState.module.js.map"}
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
/**
* Takes a value and forces it to the closest min/max if it's outside. Also forces it to the closest valid step.
*/
export function clamp(value: number, min: number = -Infinity, max: number = Infinity): number {
let newValue = Math.min(Math.max(value, min), max);
return newValue;
}
export function roundToStepPrecision(value: number, step: number): number {
let roundedValue = value;
let precision = 0;
let stepString = step.toString();
// Handle negative exponents in exponential notation (e.g., "1e-7" → precision 8)
let eIndex = stepString.toLowerCase().indexOf('e-');
if (eIndex > 0) {
precision = Math.abs(Math.floor(Math.log10(Math.abs(step)))) + eIndex;
} else {
let pointIndex = stepString.indexOf('.');
if (pointIndex >= 0) {
precision = stepString.length - pointIndex;
}
}
if (precision > 0) {
let pow = Math.pow(10, precision);
roundedValue = Math.round(roundedValue * pow) / pow;
}
return roundedValue;
}
export function snapValueToStep(value: number, min: number | undefined, max: number | undefined, step: number): number {
min = Number(min);
max = Number(max);
let remainder = ((value - (isNaN(min) ? 0 : min)) % step);
let snappedValue = roundToStepPrecision(Math.abs(remainder) * 2 >= step
? value + Math.sign(remainder) * (step - Math.abs(remainder))
: value - remainder, step);
if (!isNaN(min)) {
if (snappedValue < min) {
snappedValue = min;
} else if (!isNaN(max) && snappedValue > max) {
snappedValue = min + Math.floor(roundToStepPrecision((max - min) / step, step)) * step;
}
} else if (!isNaN(max) && snappedValue > max) {
snappedValue = Math.floor(roundToStepPrecision(max / step, step)) * step;
}
// correct floating point behavior by rounding to step precision
snappedValue = roundToStepPrecision(snappedValue, step);
return snappedValue;
}
/* Takes a value and rounds off to the number of digits. */
export function toFixedNumber(value: number, digits: number, base: number = 10): number {
const pow = Math.pow(base, digits);
return Math.round(value * pow) / pow;
}
/*
* Copyright 2020 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import React, {SetStateAction, useCallback, useEffect, useReducer, useRef, useState} from 'react';
// Use the earliest effect possible to reset the ref below.
const useEarlyEffect: typeof React.useLayoutEffect = typeof document !== 'undefined'
? React['useInsertionEffect'] ?? React.useLayoutEffect
: () => {};
export function useControlledState<T, C = T>(value: Exclude<T, undefined>, defaultValue: Exclude<T, undefined> | undefined, onChange?: (v: C, ...args: any[]) => void): [T, (value: SetStateAction<T>, ...args: any[]) => void];
export function useControlledState<T, C = T>(value: Exclude<T, undefined> | undefined, defaultValue: Exclude<T, undefined>, onChange?: (v: C, ...args: any[]) => void): [T, (value: SetStateAction<T>, ...args: any[]) => void];
export function useControlledState<T, C = T>(value: T, defaultValue: T, onChange?: (v: C, ...args: any[]) => void): [T, (value: SetStateAction<T>, ...args: any[]) => void] {
// Store the value in both state and a ref. The state value will only be used when uncontrolled.
// The ref is used to track the most current value, which is passed to the function setState callback.
let [stateValue, setStateValue] = useState(value || defaultValue);
let valueRef = useRef(stateValue);
let isControlledRef = useRef(value !== undefined);
let isControlled = value !== undefined;
useEffect(() => {
let wasControlled = isControlledRef.current;
if (wasControlled !== isControlled && process.env.NODE_ENV !== 'production') {
console.warn(`WARN: A component changed from ${wasControlled ? 'controlled' : 'uncontrolled'} to ${isControlled ? 'controlled' : 'uncontrolled'}.`);
}
isControlledRef.current = isControlled;
}, [isControlled]);
// After each render, update the ref to the current value.
// This ensures that the setState callback argument is reset.
// Note: the effect should not have any dependencies so that controlled values always reset.
let currentValue = isControlled ? value : stateValue;
useEarlyEffect(() => {
valueRef.current = currentValue;
});
let [, forceUpdate] = useReducer(() => ({}), {});
let setValue = useCallback((value: SetStateAction<T>, ...args: any[]) => {
// @ts-ignore - TS doesn't know that T cannot be a function.
let newValue = typeof value === 'function' ? value(valueRef.current) : value;
if (!Object.is(valueRef.current, newValue)) {
// Update the ref so that the next setState callback has the most recent value.
valueRef.current = newValue;
setStateValue(newValue);
// Always trigger a re-render, even when controlled, so that the layout effect above runs to reset the value.
forceUpdate();
// Trigger onChange. Note that if setState is called multiple times in a single event,
// onChange will be called for each one instead of only once.
onChange?.(newValue, ...args);
}
}, [onChange]);
return [currentValue, setValue];
}