UNPKG

@playbooks/ui

Version:

An interface library for Playbooks.

767 lines (766 loc) 32.6 kB
import React__default from "react"; import "react/jsx-runtime"; React__default.createContext(null); var accounting = { exports: {} }; /*! * accounting.js v0.4.1 * Copyright 2014 Open Exchange Rates * * Freely distributable under the MIT license. * Portions of accounting.js are inspired or borrowed from underscore.js * * Full details and documentation: * http://openexchangerates.github.io/accounting.js/ */ var hasRequiredAccounting; function requireAccounting() { if (hasRequiredAccounting) return accounting.exports; hasRequiredAccounting = 1; (function(module, exports) { (function(root, undefined$1) { var lib = {}; lib.version = "0.4.1"; lib.settings = { currency: { symbol: "$", // default currency symbol is '$' format: "%s%v", // controls output: %s = symbol, %v = value (can be object, see docs) decimal: ".", // decimal point separator thousand: ",", // thousands separator precision: 2, // decimal places grouping: 3 // digit grouping (not implemented yet) }, number: { precision: 0, // default precision on numbers is 0 grouping: 3, // digit grouping (not implemented yet) thousand: ",", decimal: "." } }; var nativeMap = Array.prototype.map, nativeIsArray = Array.isArray, toString = Object.prototype.toString; function isString(obj) { return !!(obj === "" || obj && obj.charCodeAt && obj.substr); } function isArray(obj) { return nativeIsArray ? nativeIsArray(obj) : toString.call(obj) === "[object Array]"; } function isObject(obj) { return obj && toString.call(obj) === "[object Object]"; } function defaults(object, defs) { var key; object = object || {}; defs = defs || {}; for (key in defs) { if (defs.hasOwnProperty(key)) { if (object[key] == null) object[key] = defs[key]; } } return object; } function map(obj, iterator, context) { var results = [], i, j; if (!obj) return results; if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context); for (i = 0, j = obj.length; i < j; i++) { results[i] = iterator.call(context, obj[i], i, obj); } return results; } function checkPrecision(val, base) { val = Math.round(Math.abs(val)); return isNaN(val) ? base : val; } function checkCurrencyFormat(format) { var defaults2 = lib.settings.currency.format; if (typeof format === "function") format = format(); if (isString(format) && format.match("%v")) { return { pos: format, neg: format.replace("-", "").replace("%v", "-%v"), zero: format }; } else if (!format || !format.pos || !format.pos.match("%v")) { return !isString(defaults2) ? defaults2 : lib.settings.currency.format = { pos: defaults2, neg: defaults2.replace("%v", "-%v"), zero: defaults2 }; } return format; } var unformat = lib.unformat = lib.parse = function(value, decimal) { if (isArray(value)) { return map(value, function(val) { return unformat(val, decimal); }); } value = value || 0; if (typeof value === "number") return value; decimal = decimal || lib.settings.number.decimal; var regex = new RegExp("[^0-9-" + decimal + "]", ["g"]), unformatted = parseFloat( ("" + value).replace(/\((.*)\)/, "-$1").replace(regex, "").replace(decimal, ".") // make sure decimal point is standard ); return !isNaN(unformatted) ? unformatted : 0; }; var toFixed = lib.toFixed = function(value, precision) { precision = checkPrecision(precision, lib.settings.number.precision); var power = Math.pow(10, precision); return (Math.round(lib.unformat(value) * power) / power).toFixed(precision); }; var formatNumber = lib.formatNumber = lib.format = function(number, precision, thousand, decimal) { if (isArray(number)) { return map(number, function(val) { return formatNumber(val, precision, thousand, decimal); }); } number = unformat(number); var opts = defaults( isObject(precision) ? precision : { precision, thousand, decimal }, lib.settings.number ), usePrecision = checkPrecision(opts.precision), negative = number < 0 ? "-" : "", base = parseInt(toFixed(Math.abs(number || 0), usePrecision), 10) + "", mod = base.length > 3 ? base.length % 3 : 0; return negative + (mod ? base.substr(0, mod) + opts.thousand : "") + base.substr(mod).replace(/(\d{3})(?=\d)/g, "$1" + opts.thousand) + (usePrecision ? opts.decimal + toFixed(Math.abs(number), usePrecision).split(".")[1] : ""); }; var formatMoney = lib.formatMoney = function(number, symbol, precision, thousand, decimal, format) { if (isArray(number)) { return map(number, function(val) { return formatMoney(val, symbol, precision, thousand, decimal, format); }); } number = unformat(number); var opts = defaults( isObject(symbol) ? symbol : { symbol, precision, thousand, decimal, format }, lib.settings.currency ), formats = checkCurrencyFormat(opts.format), useFormat = number > 0 ? formats.pos : number < 0 ? formats.neg : formats.zero; return useFormat.replace("%s", opts.symbol).replace("%v", formatNumber(Math.abs(number), checkPrecision(opts.precision), opts.thousand, opts.decimal)); }; lib.formatColumn = function(list, symbol, precision, thousand, decimal, format) { if (!list) return []; var opts = defaults( isObject(symbol) ? symbol : { symbol, precision, thousand, decimal, format }, lib.settings.currency ), formats = checkCurrencyFormat(opts.format), padAfterSymbol = formats.pos.indexOf("%s") < formats.pos.indexOf("%v") ? true : false, maxLength = 0, formatted = map(list, function(val, i) { if (isArray(val)) { return lib.formatColumn(val, opts); } else { val = unformat(val); var useFormat = val > 0 ? formats.pos : val < 0 ? formats.neg : formats.zero, fVal = useFormat.replace("%s", opts.symbol).replace("%v", formatNumber(Math.abs(val), checkPrecision(opts.precision), opts.thousand, opts.decimal)); if (fVal.length > maxLength) maxLength = fVal.length; return fVal; } }); return map(formatted, function(val, i) { if (isString(val) && val.length < maxLength) { return padAfterSymbol ? val.replace(opts.symbol, opts.symbol + new Array(maxLength - val.length + 1).join(" ")) : new Array(maxLength - val.length + 1).join(" ") + val; } return val; }); }; { if (module.exports) { exports = module.exports = lib; } exports.accounting = lib; } })(); })(accounting, accounting.exports); return accounting.exports; } requireAccounting(); var dist = {}; var abbreviateNumber = {}; var _const = {}; var hasRequired_const; function require_const() { if (hasRequired_const) return _const; hasRequired_const = 1; Object.defineProperty(_const, "__esModule", { value: true }); _const.defaultSymbols = ["", "k", "M", "G", "T", "P", "E"]; return _const; } var hasRequiredAbbreviateNumber; function requireAbbreviateNumber() { if (hasRequiredAbbreviateNumber) return abbreviateNumber; hasRequiredAbbreviateNumber = 1; Object.defineProperty(abbreviateNumber, "__esModule", { value: true }); var const_1 = require_const(); var defaultOptions = { padding: true, symbols: const_1.defaultSymbols }; function abbreviateNumber$1(num, digit, options) { if (digit === void 0) { digit = 1; } if (Array.isArray(options)) { options = { symbols: options }; } var _a = Object.assign({}, defaultOptions, options), symbols = _a.symbols, padding = _a.padding; var sign = Math.sign(num) >= 0; num = Math.abs(num); var tier = Math.log10(num) / 3 | 0; if (tier == 0) return (!sign ? "-" : "") + num.toString(); var suffix = symbols[tier]; if (!suffix) throw new RangeError(); var scale = Math.pow(10, tier * 3); var scaled = num / scale; var rounded = scaled.toFixed(digit); if (!padding) { rounded = String(Number(rounded)); } return (!sign ? "-" : "") + rounded + suffix; } abbreviateNumber.abbreviateNumber = abbreviateNumber$1; return abbreviateNumber; } var unabbreviateNumber = {}; var utils = {}; var hasRequiredUtils; function requireUtils() { if (hasRequiredUtils) return utils; hasRequiredUtils = 1; Object.defineProperty(utils, "__esModule", { value: true }); utils.symbolPow = function(index) { if (index === void 0) { index = 0; } return Math.pow(10, index * 3); }; return utils; } var hasRequiredUnabbreviateNumber; function requireUnabbreviateNumber() { if (hasRequiredUnabbreviateNumber) return unabbreviateNumber; hasRequiredUnabbreviateNumber = 1; Object.defineProperty(unabbreviateNumber, "__esModule", { value: true }); var const_1 = require_const(); var utils_1 = requireUtils(); function unabbreviateNumber$1(num, symbols) { if (symbols === void 0) { symbols = const_1.defaultSymbols; } var numberPattern = "[+-]?([0-9]*[.])?[0-9]+"; var symbolPattern = "" + symbols.join("|"); var pattern = "^(" + numberPattern + ")(" + symbolPattern + ")$"; var regex = new RegExp(pattern); var match = num.match(pattern) || []; if (regex.test(num) && match.length > 3) { var symbol = match[3]; var symbolValue = utils_1.symbolPow(symbols.indexOf(symbol)); var pureNum = Number(match[1]); return pureNum * symbolValue; } else { throw Error("This is not a valid input"); } } unabbreviateNumber.unabbreviateNumber = unabbreviateNumber$1; return unabbreviateNumber; } var hasRequiredDist; function requireDist() { if (hasRequiredDist) return dist; hasRequiredDist = 1; (function(exports) { function __export(m) { for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; } Object.defineProperty(exports, "__esModule", { value: true }); __export(requireAbbreviateNumber()); __export(requireUnabbreviateNumber()); })(dist); return dist; } requireDist(); var build = {}; var countUp_umd$1 = { exports: {} }; var countUp_umd = countUp_umd$1.exports; var hasRequiredCountUp_umd; function requireCountUp_umd() { if (hasRequiredCountUp_umd) return countUp_umd$1.exports; hasRequiredCountUp_umd = 1; (function(module, exports) { !function(t, i) { i(exports); }(countUp_umd, function(t) { var i = function() { return i = Object.assign || function(t2) { for (var i2, n2 = 1, s = arguments.length; n2 < s; n2++) for (var e in i2 = arguments[n2]) Object.prototype.hasOwnProperty.call(i2, e) && (t2[e] = i2[e]); return t2; }, i.apply(this, arguments); }, n = function() { function t2(t3, n2, s) { var e = this; this.endVal = n2, this.options = s, this.version = "2.9.0", this.defaults = { startVal: 0, decimalPlaces: 0, duration: 2, useEasing: true, useGrouping: true, useIndianSeparators: false, smartEasingThreshold: 999, smartEasingAmount: 333, separator: ",", decimal: ".", prefix: "", suffix: "", enableScrollSpy: false, scrollSpyDelay: 200, scrollSpyOnce: false }, this.finalEndVal = null, this.useEasing = true, this.countDown = false, this.error = "", this.startVal = 0, this.paused = true, this.once = false, this.count = function(t4) { e.startTime || (e.startTime = t4); var i2 = t4 - e.startTime; e.remaining = e.duration - i2, e.useEasing ? e.countDown ? e.frameVal = e.startVal - e.easingFn(i2, 0, e.startVal - e.endVal, e.duration) : e.frameVal = e.easingFn(i2, e.startVal, e.endVal - e.startVal, e.duration) : e.frameVal = e.startVal + (e.endVal - e.startVal) * (i2 / e.duration); var n3 = e.countDown ? e.frameVal < e.endVal : e.frameVal > e.endVal; e.frameVal = n3 ? e.endVal : e.frameVal, e.frameVal = Number(e.frameVal.toFixed(e.options.decimalPlaces)), e.printValue(e.frameVal), i2 < e.duration ? e.rAF = requestAnimationFrame(e.count) : null !== e.finalEndVal ? e.update(e.finalEndVal) : e.options.onCompleteCallback && e.options.onCompleteCallback(); }, this.formatNumber = function(t4) { var i2, n3, s2, a, o = t4 < 0 ? "-" : ""; i2 = Math.abs(t4).toFixed(e.options.decimalPlaces); var r = (i2 += "").split("."); if (n3 = r[0], s2 = r.length > 1 ? e.options.decimal + r[1] : "", e.options.useGrouping) { a = ""; for (var l = 3, u = 0, h = 0, p = n3.length; h < p; ++h) e.options.useIndianSeparators && 4 === h && (l = 2, u = 1), 0 !== h && u % l == 0 && (a = e.options.separator + a), u++, a = n3[p - h - 1] + a; n3 = a; } return e.options.numerals && e.options.numerals.length && (n3 = n3.replace(/[0-9]/g, function(t5) { return e.options.numerals[+t5]; }), s2 = s2.replace(/[0-9]/g, function(t5) { return e.options.numerals[+t5]; })), o + e.options.prefix + n3 + s2 + e.options.suffix; }, this.easeOutExpo = function(t4, i2, n3, s2) { return n3 * (1 - Math.pow(2, -10 * t4 / s2)) * 1024 / 1023 + i2; }, this.options = i(i({}, this.defaults), s), this.formattingFn = this.options.formattingFn ? this.options.formattingFn : this.formatNumber, this.easingFn = this.options.easingFn ? this.options.easingFn : this.easeOutExpo, this.el = "string" == typeof t3 ? document.getElementById(t3) : t3, n2 = null == n2 ? this.parse(this.el.innerHTML) : n2, this.startVal = this.validateValue(this.options.startVal), this.frameVal = this.startVal, this.endVal = this.validateValue(n2), this.options.decimalPlaces = Math.max(this.options.decimalPlaces), this.resetDuration(), this.options.separator = String(this.options.separator), this.useEasing = this.options.useEasing, "" === this.options.separator && (this.options.useGrouping = false), this.el ? this.printValue(this.startVal) : this.error = "[CountUp] target is null or undefined", "undefined" != typeof window && this.options.enableScrollSpy && (this.error ? console.error(this.error, t3) : (window.onScrollFns = window.onScrollFns || [], window.onScrollFns.push(function() { return e.handleScroll(e); }), window.onscroll = function() { window.onScrollFns.forEach(function(t4) { return t4(); }); }, this.handleScroll(this))); } return t2.prototype.handleScroll = function(t3) { if (t3 && window && !t3.once) { var i2 = window.innerHeight + window.scrollY, n2 = t3.el.getBoundingClientRect(), s = n2.top + window.pageYOffset, e = n2.top + n2.height + window.pageYOffset; e < i2 && e > window.scrollY && t3.paused ? (t3.paused = false, setTimeout(function() { return t3.start(); }, t3.options.scrollSpyDelay), t3.options.scrollSpyOnce && (t3.once = true)) : (window.scrollY > e || s > i2) && !t3.paused && t3.reset(); } }, t2.prototype.determineDirectionAndSmartEasing = function() { var t3 = this.finalEndVal ? this.finalEndVal : this.endVal; this.countDown = this.startVal > t3; var i2 = t3 - this.startVal; if (Math.abs(i2) > this.options.smartEasingThreshold && this.options.useEasing) { this.finalEndVal = t3; var n2 = this.countDown ? 1 : -1; this.endVal = t3 + n2 * this.options.smartEasingAmount, this.duration = this.duration / 2; } else this.endVal = t3, this.finalEndVal = null; null !== this.finalEndVal ? this.useEasing = false : this.useEasing = this.options.useEasing; }, t2.prototype.start = function(t3) { this.error || (this.options.onStartCallback && this.options.onStartCallback(), t3 && (this.options.onCompleteCallback = t3), this.duration > 0 ? (this.determineDirectionAndSmartEasing(), this.paused = false, this.rAF = requestAnimationFrame(this.count)) : this.printValue(this.endVal)); }, t2.prototype.pauseResume = function() { this.paused ? (this.startTime = null, this.duration = this.remaining, this.startVal = this.frameVal, this.determineDirectionAndSmartEasing(), this.rAF = requestAnimationFrame(this.count)) : cancelAnimationFrame(this.rAF), this.paused = !this.paused; }, t2.prototype.reset = function() { cancelAnimationFrame(this.rAF), this.paused = true, this.resetDuration(), this.startVal = this.validateValue(this.options.startVal), this.frameVal = this.startVal, this.printValue(this.startVal); }, t2.prototype.update = function(t3) { cancelAnimationFrame(this.rAF), this.startTime = null, this.endVal = this.validateValue(t3), this.endVal !== this.frameVal && (this.startVal = this.frameVal, null == this.finalEndVal && this.resetDuration(), this.finalEndVal = null, this.determineDirectionAndSmartEasing(), this.rAF = requestAnimationFrame(this.count)); }, t2.prototype.printValue = function(t3) { var i2; if (this.el) { var n2 = this.formattingFn(t3); if (null === (i2 = this.options.plugin) || void 0 === i2 ? void 0 : i2.render) this.options.plugin.render(this.el, n2); else if ("INPUT" === this.el.tagName) this.el.value = n2; else "text" === this.el.tagName || "tspan" === this.el.tagName ? this.el.textContent = n2 : this.el.innerHTML = n2; } }, t2.prototype.ensureNumber = function(t3) { return "number" == typeof t3 && !isNaN(t3); }, t2.prototype.validateValue = function(t3) { var i2 = Number(t3); return this.ensureNumber(i2) ? i2 : (this.error = "[CountUp] invalid start or end value: ".concat(t3), null); }, t2.prototype.resetDuration = function() { this.startTime = null, this.duration = 1e3 * Number(this.options.duration), this.remaining = this.duration; }, t2.prototype.parse = function(t3) { var i2 = function(t4) { return t4.replace(/([.,'  ])/g, "\\$1"); }, n2 = i2(this.options.separator), s = i2(this.options.decimal), e = t3.replace(new RegExp(n2, "g"), "").replace(new RegExp(s, "g"), "."); return parseFloat(e); }, t2; }(); t.CountUp = n; }); })(countUp_umd$1, countUp_umd$1.exports); return countUp_umd$1.exports; } var hasRequiredBuild; function requireBuild() { if (hasRequiredBuild) return build; hasRequiredBuild = 1; Object.defineProperty(build, "__esModule", { value: true }); var React$1 = React__default; var countup_js = requireCountUp_umd(); function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = true, o = false; try { if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = true) ; } catch (r2) { o = true, n = r2; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function(r2) { return Object.getOwnPropertyDescriptor(e, r2).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function(r2) { _defineProperty(e, r2, t[r2]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r2) { Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2)); }); } return e; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _extends() { _extends = Object.assign ? Object.assign.bind() : function(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var useIsomorphicLayoutEffect = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined" ? React$1.useLayoutEffect : React$1.useEffect; function useEventCallback(fn) { var ref = React$1.useRef(fn); useIsomorphicLayoutEffect(function() { ref.current = fn; }); return React$1.useCallback(function() { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return ref.current.apply(void 0, args); }, []); } var createCountUpInstance = function createCountUpInstance2(el, props) { var decimal = props.decimal, decimals = props.decimals, duration = props.duration, easingFn = props.easingFn, end = props.end, formattingFn = props.formattingFn, numerals = props.numerals, prefix = props.prefix, separator = props.separator, start = props.start, suffix = props.suffix, useEasing = props.useEasing, useGrouping = props.useGrouping, useIndianSeparators = props.useIndianSeparators, enableScrollSpy = props.enableScrollSpy, scrollSpyDelay = props.scrollSpyDelay, scrollSpyOnce = props.scrollSpyOnce, plugin = props.plugin; return new countup_js.CountUp(el, end, { startVal: start, duration, decimal, decimalPlaces: decimals, easingFn, formattingFn, numerals, separator, prefix, suffix, plugin, useEasing, useIndianSeparators, useGrouping, enableScrollSpy, scrollSpyDelay, scrollSpyOnce }); }; var _excluded$1 = ["ref", "startOnMount", "enableReinitialize", "delay", "onEnd", "onStart", "onPauseResume", "onReset", "onUpdate"]; var DEFAULTS = { decimal: ".", separator: ",", delay: null, prefix: "", suffix: "", duration: 2, start: 0, decimals: 0, startOnMount: true, enableReinitialize: true, useEasing: true, useGrouping: true, useIndianSeparators: false }; var useCountUp = function useCountUp2(props) { var filteredProps = Object.fromEntries(Object.entries(props).filter(function(_ref) { var _ref2 = _slicedToArray(_ref, 2), value = _ref2[1]; return value !== void 0; })); var _useMemo = React$1.useMemo(function() { return _objectSpread2(_objectSpread2({}, DEFAULTS), filteredProps); }, [props]), ref = _useMemo.ref, startOnMount = _useMemo.startOnMount, enableReinitialize = _useMemo.enableReinitialize, delay = _useMemo.delay, onEnd = _useMemo.onEnd, onStart = _useMemo.onStart, onPauseResume = _useMemo.onPauseResume, onReset = _useMemo.onReset, onUpdate = _useMemo.onUpdate, instanceProps = _objectWithoutProperties(_useMemo, _excluded$1); var countUpRef = React$1.useRef(); var timerRef = React$1.useRef(); var isInitializedRef = React$1.useRef(false); var createInstance = useEventCallback(function() { return createCountUpInstance(typeof ref === "string" ? ref : ref.current, instanceProps); }); var getCountUp = useEventCallback(function(recreate) { var countUp = countUpRef.current; if (countUp && !recreate) { return countUp; } var newCountUp = createInstance(); countUpRef.current = newCountUp; return newCountUp; }); var start = useEventCallback(function() { var run = function run2() { return getCountUp(true).start(function() { onEnd === null || onEnd === void 0 || onEnd({ pauseResume, reset, start: restart, update }); }); }; if (delay && delay > 0) { timerRef.current = setTimeout(run, delay * 1e3); } else { run(); } onStart === null || onStart === void 0 || onStart({ pauseResume, reset, update }); }); var pauseResume = useEventCallback(function() { getCountUp().pauseResume(); onPauseResume === null || onPauseResume === void 0 || onPauseResume({ reset, start: restart, update }); }); var reset = useEventCallback(function() { if (getCountUp().el) { timerRef.current && clearTimeout(timerRef.current); getCountUp().reset(); onReset === null || onReset === void 0 || onReset({ pauseResume, start: restart, update }); } }); var update = useEventCallback(function(newEnd) { getCountUp().update(newEnd); onUpdate === null || onUpdate === void 0 || onUpdate({ pauseResume, reset, start: restart }); }); var restart = useEventCallback(function() { reset(); start(); }); var maybeInitialize = useEventCallback(function(shouldReset) { if (startOnMount) { if (shouldReset) { reset(); } start(); } }); React$1.useEffect(function() { if (!isInitializedRef.current) { isInitializedRef.current = true; maybeInitialize(); } else if (enableReinitialize) { maybeInitialize(true); } }, [enableReinitialize, isInitializedRef, maybeInitialize, delay, props.start, props.suffix, props.prefix, props.duration, props.separator, props.decimals, props.decimal, props.formattingFn]); React$1.useEffect(function() { return function() { reset(); }; }, [reset]); return { start: restart, pauseResume, reset, update, getCountUp }; }; var _excluded = ["className", "redraw", "containerProps", "children", "style"]; var CountUp = function CountUp2(props) { var className = props.className, redraw = props.redraw, containerProps = props.containerProps, children = props.children, style = props.style, useCountUpProps = _objectWithoutProperties(props, _excluded); var containerRef = React$1.useRef(null); var isInitializedRef = React$1.useRef(false); var _useCountUp = useCountUp(_objectSpread2(_objectSpread2({}, useCountUpProps), {}, { ref: containerRef, startOnMount: typeof children !== "function" || props.delay === 0, // component manually restarts enableReinitialize: false })), start = _useCountUp.start, reset = _useCountUp.reset, updateCountUp = _useCountUp.update, pauseResume = _useCountUp.pauseResume, getCountUp = _useCountUp.getCountUp; var restart = useEventCallback(function() { start(); }); var update = useEventCallback(function(end) { if (!props.preserveValue) { reset(); } updateCountUp(end); }); var initializeOnMount = useEventCallback(function() { if (typeof props.children === "function") { if (!(containerRef.current instanceof Element)) { console.error(`Couldn't find attached element to hook the CountUp instance into! Try to attach "containerRef" from the render prop to a an Element, eg. <span ref={containerRef} />.`); return; } } getCountUp(); }); React$1.useEffect(function() { initializeOnMount(); }, [initializeOnMount]); React$1.useEffect(function() { if (isInitializedRef.current) { update(props.end); } }, [props.end, update]); var redrawDependencies = redraw && props; React$1.useEffect(function() { if (redraw && isInitializedRef.current) { restart(); } }, [restart, redraw, redrawDependencies]); React$1.useEffect(function() { if (!redraw && isInitializedRef.current) { restart(); } }, [restart, redraw, props.start, props.suffix, props.prefix, props.duration, props.separator, props.decimals, props.decimal, props.className, props.formattingFn]); React$1.useEffect(function() { isInitializedRef.current = true; }, []); if (typeof children === "function") { return children({ countUpRef: containerRef, start, reset, update: updateCountUp, pauseResume, getCountUp }); } return /* @__PURE__ */ React$1.createElement("span", _extends({ className, ref: containerRef, style }, containerProps), typeof props.start !== "undefined" ? getCountUp().formattingFn(props.start) : ""); }; build.default = CountUp; build.useCountUp = useCountUp; return build; } requireBuild();