index.js
  1  "use strict";
  2  var __create = Object.create;
  3  var __defProp = Object.defineProperty;
  4  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5  var __getOwnPropNames = Object.getOwnPropertyNames;
  6  var __getProtoOf = Object.getPrototypeOf;
  7  var __hasOwnProp = Object.prototype.hasOwnProperty;
  8  var __export = (target, all) => {
  9    for (var name in all)
 10      __defProp(target, name, { get: all[name], enumerable: true });
 11  };
 12  var __copyProps = (to, from, except, desc) => {
 13    if (from && typeof from === "object" || typeof from === "function") {
 14      for (let key of __getOwnPropNames(from))
 15        if (!__hasOwnProp.call(to, key) && key !== except)
 16          __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
 17    }
 18    return to;
 19  };
 20  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
 21    isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
 22    mod
 23  ));
 24  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
 25  
 26  // src/index.ts
 27  var src_exports = {};
 28  __export(src_exports, {
 29    __DEV__: () => __DEV__,
 30    __TEST__: () => __TEST__,
 31    arrayToObject: () => arrayToObject,
 32    callAll: () => callAll,
 33    callAllHandlers: () => callAllHandlers,
 34    capitalize: () => capitalize,
 35    clamp: () => clamp,
 36    clampPercentage: () => clampPercentage,
 37    cleanObject: () => cleanObject,
 38    cleanObjectKeys: () => cleanObjectKeys,
 39    clsx: () => clsx,
 40    compact: () => compact,
 41    copyObject: () => copyObject,
 42    dataAttr: () => dataAttr,
 43    debounce: () => debounce,
 44    extractProperty: () => extractProperty,
 45    get: () => get,
 46    getGregorianYearOffset: () => getGregorianYearOffset,
 47    getInertValue: () => getInertValue,
 48    getKeyValue: () => getKeyValue,
 49    getMargin: () => getMargin,
 50    getProp: () => getProp,
 51    getUniqueID: () => getUniqueID,
 52    intersectionBy: () => intersectionBy,
 53    isArray: () => isArray,
 54    isEmpty: () => isEmpty,
 55    isEmptyArray: () => isEmptyArray,
 56    isEmptyObject: () => isEmptyObject,
 57    isFunction: () => isFunction,
 58    isNumeric: () => isNumeric,
 59    isObject: () => isObject,
 60    isPatternNumeric: () => isPatternNumeric,
 61    isReact19: () => isReact19,
 62    kebabCase: () => kebabCase,
 63    mapKeys: () => mapKeys,
 64    objectToDeps: () => objectToDeps,
 65    omit: () => omit,
 66    omitObject: () => omitObject,
 67    range: () => range,
 68    removeEvents: () => removeEvents,
 69    renameProp: () => renameProp,
 70    safeAriaLabel: () => safeAriaLabel,
 71    safeText: () => safeText,
 72    uniqBy: () => uniqBy,
 73    warn: () => warn
 74  });
 75  module.exports = __toCommonJS(src_exports);
 76  
 77  // src/assertion.ts
 78  var __DEV__ = process.env.NODE_ENV !== "production";
 79  var __TEST__ = process.env.NODE_ENV === "test";
 80  function isArray(value) {
 81    return Array.isArray(value);
 82  }
 83  function isEmptyArray(value) {
 84    return isArray(value) && value.length === 0;
 85  }
 86  function isObject(value) {
 87    const type = typeof value;
 88    return value != null && (type === "object" || type === "function") && !isArray(value);
 89  }
 90  function isEmptyObject(value) {
 91    return isObject(value) && Object.keys(value).length === 0;
 92  }
 93  function isEmpty(value) {
 94    if (isArray(value))
 95      return isEmptyArray(value);
 96    if (isObject(value))
 97      return isEmptyObject(value);
 98    if (value == null || value === "")
 99      return true;
100    return false;
101  }
102  function isFunction(value) {
103    return typeof value === "function";
104  }
105  var dataAttr = (condition) => condition ? "true" : void 0;
106  var isNumeric = (value) => value != null && parseInt(value.toString(), 10) > 0;
107  
108  // src/clsx.ts
109  function toVal(mix) {
110    var k, y, str = "";
111    if (typeof mix === "string" || typeof mix === "number") {
112      str += mix;
113    } else if (typeof mix === "object") {
114      if (Array.isArray(mix)) {
115        for (k = 0; k < mix.length; k++) {
116          if (mix[k]) {
117            if (y = toVal(mix[k])) {
118              str && (str += " ");
119              str += y;
120            }
121          }
122        }
123      } else {
124        for (k in mix) {
125          if (mix[k]) {
126            str && (str += " ");
127            str += k;
128          }
129        }
130      }
131    }
132    return str;
133  }
134  function clsx(...args) {
135    var i = 0, tmp, x, str = "";
136    while (i < args.length) {
137      if (tmp = args[i++]) {
138        if (x = toVal(tmp)) {
139          str && (str += " ");
140          str += x;
141        }
142      }
143    }
144    return str;
145  }
146  
147  // src/object.ts
148  var renameProp = (oldProp, newProp, { [oldProp]: old, ...others }) => ({
149    [newProp]: old,
150    ...others
151  });
152  var copyObject = (obj) => {
153    if (!isObject(obj))
154      return obj;
155    if (obj instanceof Array)
156      return [...obj];
157    return { ...obj };
158  };
159  var omitObject = (obj, omitKeys) => {
160    if (!isObject(obj))
161      return obj;
162    if (obj instanceof Array)
163      return [...obj];
164    const newObj = { ...obj };
165    omitKeys.forEach((key) => newObj[key] && delete newObj[key]);
166    return newObj;
167  };
168  var cleanObject = (obj) => {
169    if (!isObject(obj))
170      return obj;
171    if (obj instanceof Array)
172      return [...obj];
173    const newObj = { ...obj };
174    Object.keys(newObj).forEach((key) => {
175      if (newObj[key] === void 0 || newObj[key] === null) {
176        delete newObj[key];
177      }
178    });
179    return newObj;
180  };
181  var cleanObjectKeys = (obj, keys = []) => {
182    if (!isObject(obj))
183      return obj;
184    if (obj instanceof Array)
185      return [...obj];
186    const newObj = { ...obj };
187    keys.forEach((key) => {
188      if (newObj[key]) {
189        delete newObj[key];
190      }
191    });
192    return newObj;
193  };
194  var getKeyValue = (obj, key) => {
195    if (!isObject(obj))
196      return obj;
197    if (obj instanceof Array)
198      return [...obj];
199    return obj[key];
200  };
201  var getProp = (obj, path, fallback, index) => {
202    const key = typeof path === "string" ? path.split(".") : [path];
203    for (index = 0; index < key.length; index += 1) {
204      if (!obj)
205        break;
206      obj = obj[key[index]];
207    }
208    return obj === void 0 ? fallback : obj;
209  };
210  var arrayToObject = (arr) => {
211    if (!arr.length || !Array.isArray(arr))
212      return {};
213    return arr.reduce((acc, item) => {
214      return { ...acc, ...item };
215    }, {});
216  };
217  function compact(object) {
218    const clone = Object.assign({}, object);
219    for (let key in clone) {
220      if (clone[key] === void 0)
221        delete clone[key];
222    }
223    return clone;
224  }
225  
226  // src/text.ts
227  var safeText = (text) => {
228    if ((text == null ? void 0 : text.length) <= 4)
229      return text;
230    return text == null ? void 0 : text.slice(0, 3);
231  };
232  var safeAriaLabel = (...texts) => {
233    let ariaLabel = " ";
234    for (const text of texts) {
235      if (typeof text === "string" && text.length > 0) {
236        ariaLabel = text;
237        break;
238      }
239    }
240    return ariaLabel;
241  };
242  
243  // src/dimensions.ts
244  var getMargin = (num) => {
245    return `calc(${num * 15.25}pt + 1px * ${num - 1})`;
246  };
247  
248  // src/functions.ts
249  var import_react = __toESM(require("react"));
250  var capitalize = (s) => {
251    return s ? s.charAt(0).toUpperCase() + s.slice(1).toLowerCase() : "";
252  };
253  function callAllHandlers(...fns) {
254    return function func(event) {
255      fns.some((fn) => {
256        fn == null ? void 0 : fn(event);
257        return event == null ? void 0 : event.defaultPrevented;
258      });
259    };
260  }
261  function callAll(...fns) {
262    return function mergedFn(arg) {
263      fns.forEach((fn) => {
264        fn == null ? void 0 : fn(arg);
265      });
266    };
267  }
268  function extractProperty(key, defaultValue, ...objs) {
269    let result = defaultValue;
270    for (const obj of objs) {
271      if (obj && key in obj && !!obj[key]) {
272        result = obj[key];
273      }
274    }
275    return result;
276  }
277  function getUniqueID(prefix) {
278    return `${prefix}-${Math.floor(Math.random() * 1e6)}`;
279  }
280  function removeEvents(input) {
281    for (const key in input) {
282      if (key.startsWith("on")) {
283        delete input[key];
284      }
285    }
286    return input;
287  }
288  function objectToDeps(obj) {
289    if (!obj || typeof obj !== "object") {
290      return "";
291    }
292    try {
293      return JSON.stringify(obj);
294    } catch (e) {
295      return "";
296    }
297  }
298  function debounce(func, waitMilliseconds = 0) {
299    let timeout;
300    return function(...args) {
301      const later = () => {
302        timeout = void 0;
303        func.apply(this, args);
304      };
305      if (timeout !== void 0) {
306        clearTimeout(timeout);
307      }
308      timeout = setTimeout(later, waitMilliseconds);
309    };
310  }
311  function uniqBy(arr, iteratee) {
312    if (typeof iteratee === "string") {
313      iteratee = (item) => item[iteratee];
314    }
315    return arr.filter((x, i, self) => i === self.findIndex((y) => iteratee(x) === iteratee(y)));
316  }
317  var omit = (obj, keys) => {
318    const res = Object.assign({}, obj);
319    keys.forEach((key) => {
320      delete res[key];
321    });
322    return res;
323  };
324  var kebabCase = (s) => {
325    return s.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase();
326  };
327  var mapKeys = (obj, iteratee) => {
328    return Object.fromEntries(
329      Object.entries(obj).map(([key, value]) => [iteratee(value, key), value])
330    );
331  };
332  var get = (object, path, defaultValue) => {
333    const keys = Array.isArray(path) ? path : path.replace(/\[(\d+)\]/g, ".$1").split(".");
334    let res = object;
335    for (const key of keys) {
336      res = res == null ? void 0 : res[key];
337      if (res === void 0) {
338        return defaultValue;
339      }
340    }
341    return res;
342  };
343  var intersectionBy = (...args) => {
344    if (args.length < 2) {
345      throw new Error("intersectionBy requires at least two arrays and an iteratee");
346    }
347    const iteratee = args[args.length - 1];
348    const arrays = args.slice(0, -1);
349    if (arrays.length === 0) {
350      return [];
351    }
352    const getIterateeValue = (item) => {
353      if (typeof iteratee === "function") {
354        return iteratee(item);
355      } else if (typeof iteratee === "string") {
356        return item[iteratee];
357      } else {
358        throw new Error("Iteratee must be a function or a string key of the array elements");
359      }
360    };
361    const [first, ...rest] = arrays;
362    const transformedFirst = first.map((item) => getIterateeValue(item));
363    const transformedSets = rest.map(
364      (array) => new Set(array.map((item) => getIterateeValue(item)))
365    );
366    const res = [];
367    const seen = /* @__PURE__ */ new Set();
368    for (let i = 0; i < first.length; i++) {
369      const item = first[i];
370      const transformed = transformedFirst[i];
371      if (seen.has(transformed)) {
372        continue;
373      }
374      const existsInAll = transformedSets.every((set) => set.has(transformed));
375      if (existsInAll) {
376        res.push(item);
377        seen.add(transformed);
378      }
379    }
380    return res;
381  };
382  var isReact19 = () => {
383    return import_react.default.version.split(".")[0] === "19";
384  };
385  var getInertValue = (v) => {
386    return isReact19() ? v : v ? "" : void 0;
387  };
388  
389  // src/numbers.ts
390  function range(start, end) {
391    const length = end - start + 1;
392    return Array.from({ length }, (_, index) => index + start);
393  }
394  function clamp(value, min, max) {
395    return Math.min(Math.max(value, min), max);
396  }
397  function clampPercentage(value, max = 100) {
398    return Math.min(Math.max(value, 0), max);
399  }
400  
401  // src/console.ts
402  var warningStack = {};
403  function warn(message, component, ...args) {
404    const tag = component ? ` [${component}]` : " ";
405    const log = `[Next UI]${tag}: ${message}`;
406    if (typeof console === "undefined")
407      return;
408    if (warningStack[log])
409      return;
410    warningStack[log] = true;
411    if (process.env.NODE_ENV !== "production") {
412      return console.warn(log, args);
413    }
414  }
415  
416  // src/dates.ts
417  function getGregorianYearOffset(identifier) {
418    switch (identifier) {
419      case "buddhist":
420        return 543;
421      case "ethiopic":
422      case "ethioaa":
423        return -8;
424      case "coptic":
425        return -284;
426      case "hebrew":
427        return 3760;
428      case "indian":
429        return -78;
430      case "islamic-civil":
431      case "islamic-tbla":
432      case "islamic-umalqura":
433        return -579;
434      case "persian":
435        return -600;
436      case "roc":
437      case "japanese":
438      case "gregory":
439      default:
440        return 0;
441    }
442  }
443  
444  // src/regex.ts
445  var isPatternNumeric = (pattern) => {
446    const numericPattern = /(^|\W)[0-9](\W|$)/;
447    return numericPattern.test(pattern) && !/[^\d\^$\[\]\(\)\*\+\-\.\|]/.test(pattern);
448  };
449  // Annotate the CommonJS export names for ESM import in node:
450  0 && (module.exports = {
451    __DEV__,
452    __TEST__,
453    arrayToObject,
454    callAll,
455    callAllHandlers,
456    capitalize,
457    clamp,
458    clampPercentage,
459    cleanObject,
460    cleanObjectKeys,
461    clsx,
462    compact,
463    copyObject,
464    dataAttr,
465    debounce,
466    extractProperty,
467    get,
468    getGregorianYearOffset,
469    getInertValue,
470    getKeyValue,
471    getMargin,
472    getProp,
473    getUniqueID,
474    intersectionBy,
475    isArray,
476    isEmpty,
477    isEmptyArray,
478    isEmptyObject,
479    isFunction,
480    isNumeric,
481    isObject,
482    isPatternNumeric,
483    isReact19,
484    kebabCase,
485    mapKeys,
486    objectToDeps,
487    omit,
488    omitObject,
489    range,
490    removeEvents,
491    renameProp,
492    safeAriaLabel,
493    safeText,
494    uniqBy,
495    warn
496  });