@react-hive/honey-utils 4.1.0 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -188,6 +188,36 @@ parseJson('{name:"Mike"}');
188
188
  // ➜ null
189
189
  ```
190
190
 
191
+ ### Storage Utilities
192
+
193
+ ```ts
194
+ import { readLocalStorageJson, writeLocalStorageJson } from '@react-hive/honey-utils';
195
+
196
+ /**
197
+ * Store a value in localStorage as JSON
198
+ */
199
+ writeLocalStorageJson('basket', [{ productId: 'p1', quantity: 2 }]);
200
+ // ➜ true
201
+
202
+ /**
203
+ * Read it back
204
+ */
205
+ readLocalStorageJson<{ productId: string; quantity: number }[]>('basket');
206
+ // ➜ [{ productId: 'p1', quantity: 2 }]
207
+
208
+ /**
209
+ * Nothing stored, invalid JSON, or storage that cannot be read returns null
210
+ */
211
+ readLocalStorageJson('missing');
212
+ // ➜ null
213
+
214
+ /**
215
+ * A write that fails (storage full, private mode, a circular value) returns false rather than throwing
216
+ */
217
+ writeLocalStorageJson('basket', circularValue);
218
+ // ➜ false
219
+ ```
220
+
191
221
  ### Array Utilities
192
222
 
193
223
  ```ts
@@ -442,7 +472,8 @@ import {
442
472
  isValidDate,
443
473
  isRegExp,
444
474
  isMap,
445
- isSet
475
+ isSet,
476
+ isEnumValue,
446
477
  } from '@react-hive/honey-utils';
447
478
 
448
479
  /**
@@ -518,6 +549,19 @@ isMap(new Map());
518
549
  // ➜ true
519
550
  isSet(new Set());
520
551
  // ➜ true
552
+
553
+ /**
554
+ * Check if value is one of a string enum's values
555
+ */
556
+ enum Fruit {
557
+ APPLE = 'apple',
558
+ PEAR = 'pear',
559
+ }
560
+
561
+ isEnumValue(Fruit, 'apple');
562
+ // ➜ true
563
+ isEnumValue(Fruit, 'APPLE');
564
+ // ➜ false
521
565
  ```
522
566
 
523
567
  ### Math Utilities
@@ -752,6 +796,7 @@ function divide(a: number, b: number): number {
752
796
  - `isSymbol(value: unknown): value is symbol` - Checks if a value is a `Symbol`.
753
797
  - `isBlob(value: unknown): value is Blob` — Checks if a value is a `Blob`.
754
798
  - `isError(value: unknown): value is Error` — Checks if a value is an `Error` object.
799
+ - `isEnumValue<Value extends string>(enumObject: Record<string, Value>, value: unknown): value is Value` - Checks if a value is one of a string enum's values, narrowing it to the enum's type.
755
800
 
756
801
  ### Math Utilities
757
802
 
@@ -771,6 +816,8 @@ function divide(a: number, b: number): number {
771
816
 
772
817
  - `isLocalStorageReadable(): boolean` - Determines whether `localStorage` can be safely read from. This check works even when writes fail (e.g., due to `QuotaExceededError`) and ensures that calling `getItem()` does not throw in restricted environments.
773
818
  - `getLocalStorageCapabilities(): LocalStorageCapabilities` - Detects the browser's read and write capabilities for `localStorage`. Readability is determined by safe execution of `getItem()`, while writability requires successful `setItem()` and `removeItem()`.
819
+ - `readLocalStorageJson<Value>(key: string): Nullable<Value>` - Reads the value stored as JSON under a key in `localStorage`. Returns `null` when nothing is stored, the stored value is not valid JSON, or storage cannot be read (SSR, disabled storage, sandboxed iframes). Never throws. The value is cast to `Value`, not validated.
820
+ - `writeLocalStorageJson(key: string, value: unknown): boolean` - Stores a value under a key in `localStorage` as JSON. Returns `true` once stored, or `false` when storage cannot be written (`QuotaExceededError`, private mode, restricted contexts, SSR) or the value cannot be serialised. Never throws.
774
821
 
775
822
  ### Geometry
776
823
 
package/dist/README.md CHANGED
@@ -188,6 +188,36 @@ parseJson('{name:"Mike"}');
188
188
  // ➜ null
189
189
  ```
190
190
 
191
+ ### Storage Utilities
192
+
193
+ ```ts
194
+ import { readLocalStorageJson, writeLocalStorageJson } from '@react-hive/honey-utils';
195
+
196
+ /**
197
+ * Store a value in localStorage as JSON
198
+ */
199
+ writeLocalStorageJson('basket', [{ productId: 'p1', quantity: 2 }]);
200
+ // ➜ true
201
+
202
+ /**
203
+ * Read it back
204
+ */
205
+ readLocalStorageJson<{ productId: string; quantity: number }[]>('basket');
206
+ // ➜ [{ productId: 'p1', quantity: 2 }]
207
+
208
+ /**
209
+ * Nothing stored, invalid JSON, or storage that cannot be read returns null
210
+ */
211
+ readLocalStorageJson('missing');
212
+ // ➜ null
213
+
214
+ /**
215
+ * A write that fails (storage full, private mode, a circular value) returns false rather than throwing
216
+ */
217
+ writeLocalStorageJson('basket', circularValue);
218
+ // ➜ false
219
+ ```
220
+
191
221
  ### Array Utilities
192
222
 
193
223
  ```ts
@@ -442,7 +472,8 @@ import {
442
472
  isValidDate,
443
473
  isRegExp,
444
474
  isMap,
445
- isSet
475
+ isSet,
476
+ isEnumValue,
446
477
  } from '@react-hive/honey-utils';
447
478
 
448
479
  /**
@@ -518,6 +549,19 @@ isMap(new Map());
518
549
  // ➜ true
519
550
  isSet(new Set());
520
551
  // ➜ true
552
+
553
+ /**
554
+ * Check if value is one of a string enum's values
555
+ */
556
+ enum Fruit {
557
+ APPLE = 'apple',
558
+ PEAR = 'pear',
559
+ }
560
+
561
+ isEnumValue(Fruit, 'apple');
562
+ // ➜ true
563
+ isEnumValue(Fruit, 'APPLE');
564
+ // ➜ false
521
565
  ```
522
566
 
523
567
  ### Math Utilities
@@ -752,6 +796,7 @@ function divide(a: number, b: number): number {
752
796
  - `isSymbol(value: unknown): value is symbol` - Checks if a value is a `Symbol`.
753
797
  - `isBlob(value: unknown): value is Blob` — Checks if a value is a `Blob`.
754
798
  - `isError(value: unknown): value is Error` — Checks if a value is an `Error` object.
799
+ - `isEnumValue<Value extends string>(enumObject: Record<string, Value>, value: unknown): value is Value` - Checks if a value is one of a string enum's values, narrowing it to the enum's type.
755
800
 
756
801
  ### Math Utilities
757
802
 
@@ -771,6 +816,8 @@ function divide(a: number, b: number): number {
771
816
 
772
817
  - `isLocalStorageReadable(): boolean` - Determines whether `localStorage` can be safely read from. This check works even when writes fail (e.g., due to `QuotaExceededError`) and ensures that calling `getItem()` does not throw in restricted environments.
773
818
  - `getLocalStorageCapabilities(): LocalStorageCapabilities` - Detects the browser's read and write capabilities for `localStorage`. Readability is determined by safe execution of `getItem()`, while writability requires successful `setItem()` and `removeItem()`.
819
+ - `readLocalStorageJson<Value>(key: string): Nullable<Value>` - Reads the value stored as JSON under a key in `localStorage`. Returns `null` when nothing is stored, the stored value is not valid JSON, or storage cannot be read (SSR, disabled storage, sandboxed iframes). Never throws. The value is cast to `Value`, not validated.
820
+ - `writeLocalStorageJson(key: string, value: unknown): boolean` - Stores a value under a key in `localStorage` as JSON. Returns `true` once stored, or `false` when storage cannot be written (`QuotaExceededError`, private mode, restricted contexts, SSR) or the value cannot be serialised. Never throws.
774
821
 
775
822
  ### Geometry
776
823
 
@@ -1 +1,2 @@
1
1
  export * from './local-storage';
2
+ export * from './local-storage-json';
@@ -0,0 +1,29 @@
1
+ import type { Nullable } from '~/types';
2
+ /**
3
+ * Reads the value stored as JSON under a key in `localStorage`.
4
+ *
5
+ * Never throws: storage that cannot be read at all (SSR, disabled storage, sandboxed iframes, strict
6
+ * privacy modes) reads as nothing stored, as does a value that is not JSON.
7
+ *
8
+ * The value is only cast to `Value`, not checked against it - something stored by an older version
9
+ * of the app, or by hand, can be of any shape, so check it before relying on it.
10
+ *
11
+ * @param key - The `localStorage` key to read.
12
+ *
13
+ * @returns The parsed value, or `null` when nothing is stored under the key, what is stored is not
14
+ * valid JSON, or storage cannot be read.
15
+ */
16
+ export declare const readLocalStorageJson: <Value>(key: string) => Nullable<Value>;
17
+ /**
18
+ * Stores a value under a key in `localStorage`, as JSON.
19
+ *
20
+ * Never throws: a write that fails - storage full (`QuotaExceededError`), Safari Private Mode,
21
+ * security-restricted contexts, SSR, or a value `JSON.stringify()` cannot serialise (a circular
22
+ * reference, a `BigInt`) - reports `false` instead.
23
+ *
24
+ * @param key - The `localStorage` key to write.
25
+ * @param value - Any JSON-serialisable value.
26
+ *
27
+ * @returns `true` once the value is stored, `false` when it could not be.
28
+ */
29
+ export declare const writeLocalStorageJson: (key: string, value: unknown) => boolean;
package/dist/guards.d.ts CHANGED
@@ -203,3 +203,26 @@ export declare const isInteger: (value: unknown) => value is number;
203
203
  * ```
204
204
  */
205
205
  export declare const isDecimal: (value: unknown) => value is number;
206
+ /**
207
+ * Checks if a value is one of a string enum's values.
208
+ *
209
+ * @template Value - The type of the enum's values.
210
+ *
211
+ * @param enumObject - The enum, or any object whose values are the allowed strings.
212
+ * @param value - The value to check.
213
+ *
214
+ * @returns `true` if the value is one of the enum's values; otherwise, `false`.
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * enum Fruit {
219
+ * APPLE = 'apple',
220
+ * PEAR = 'pear',
221
+ * }
222
+ *
223
+ * isEnumValue(Fruit, 'apple'); // true
224
+ * isEnumValue(Fruit, 'APPLE'); // false
225
+ * isEnumValue(Fruit, null); // false
226
+ * ```
227
+ */
228
+ export declare const isEnumValue: <Value extends string>(enumObject: Record<string, Value>, value: unknown) => value is Value;
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- (()=>{"use strict";const e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}};let t={};e.r(t),e.d(t,{DATA_TRANSFER_JSON_MIME:()=>ae,FOCUSABLE_HTML_TAGS:()=>i,applyInertiaStep:()=>Ce,assert:()=>p,blobToFile:()=>xe,calculateCenterOffset:()=>me,calculateEuclideanDistance:()=>Pe,calculateMovingSpeed:()=>Be,calculatePercentage:()=>De,camelToDashCase:()=>ke,camelToWords:()=>Re,centerElementInContainer:()=>ge,chunk:()=>N,clamp:()=>Ne,clampOffsetToOverflow:()=>pe,cloneBlob:()=>n,compact:()=>_,compose:()=>f,decodeBase64:()=>Ke,decodeBase64Json:()=>Qe,definedProps:()=>_e,delay:()=>ee,difference:()=>h,downloadFile:()=>se,encodeBase64:()=>et,encodeBase64Json:()=>tt,everyAsync:()=>G,fileListToFiles:()=>Ae,filterParallel:()=>q,filterSequential:()=>Z,findAsync:()=>Q,findCharIndices:()=>Ue,flattenTree:()=>Je,forEachChar:()=>We,generateEphemeralId:()=>Ee,getAdjacentItems:()=>R,getDOMRectIntersectionRatio:()=>Te,getDataTransferJson:()=>ie,getElementOffsetRect:()=>r,getFocusableHtmlElements:()=>s,getLocalStorageCapabilities:()=>be,getTreeChildren:()=>Ze,getWordsInitials:()=>Ye,getXOverflowWidth:()=>fe,getYOverflowHeight:()=>de,hasXOverflow:()=>ue,hasYOverflow:()=>he,hashString:()=>Le,hexWithAlpha:()=>Ve,intersection:()=>m,invokeIfFunction:()=>Ie,isAnchorHtmlElement:()=>a,isArray:()=>$,isBlob:()=>I,isBool:()=>A,isContentEditableHtmlElement:()=>l,isDate:()=>M,isDecimal:()=>L,isDefined:()=>w,isEmptyArray:()=>k,isEmptyObject:()=>v,isError:()=>O,isFile:()=>Se,isFiniteNumber:()=>B,isFunction:()=>H,isHtmlElementFocusable:()=>o,isInteger:()=>D,isLocalStorageReadable:()=>we,isMap:()=>T,isNil:()=>y,isNilOrEmptyString:()=>Xe,isNull:()=>g,isNumber:()=>S,isObject:()=>x,isPromise:()=>Y,isRegExp:()=>E,isSet:()=>F,isString:()=>oe,isSymbol:()=>P,isUndefined:()=>b,isValidDate:()=>C,moveFocusWithinContainer:()=>c,noop:()=>X,not:()=>U,once:()=>W,parse2DMatrix:()=>ye,parseFileName:()=>He,parseJson:()=>re,pipe:()=>u,readFilesFromDataTransfer:()=>Me,reduceAsync:()=>K,replaceHistorySearchParams:()=>ce,resolveAxisDelta:()=>Fe,resolveBoundedDelta:()=>Oe,retry:()=>ne,runParallel:()=>J,runSequential:()=>z,searchTree:()=>qe,setDataTransferJson:()=>le,someAsync:()=>V,splitMapJoin:()=>ze,splitStringIntoWords:()=>je,timeout:()=>te,toKebabCase:()=>$e,toggleArrayItem:()=>j,traverseFileSystemDirectory:()=>ve,unique:()=>d});const n=e=>new Blob([e],{type:e.type}),r=e=>new DOMRect(e.offsetLeft,e.offsetTop,e.clientWidth,e.clientHeight),a=e=>"A"===e.tagName,l=e=>"true"===e.getAttribute("contenteditable"),i=["INPUT","SELECT","TEXTAREA","BUTTON","A"],o=e=>{if(!e)return!1;const t=window.getComputedStyle(e);if("hidden"===t.visibility||"none"===t.display)return!1;if("disabled"in e&&e.disabled)return!1;const n=e.getAttribute("tabindex");return"-1"!==n&&(i.includes(e.tagName)?!a(e)||""!==e.href:!!l(e)||null!==n)},s=e=>Array.from(e.querySelectorAll("*")).filter(o),c=(e,t=null,{wrap:n=!0,getNextIndex:r}={})=>{const a=document.activeElement,l=t??a?.parentElement;if(!a||!l)return;const i=s(l);if(0===i.length)return;const o=i.indexOf(a);if(-1===o)return;let c;r?c=r(o,e,i):"next"===e?(c=o+1,c>=i.length&&(c=n?0:null)):(c=o-1,c<0&&(c=n?i.length-1:null)),null!==c&&i[c]?.focus()},u=(...e)=>t=>e.reduce((e,t)=>t(e),t),f=(...e)=>t=>e.reduceRight((e,t)=>t(e),t),h=(e,t)=>e.filter(e=>!t.includes(e)),d=e=>[...new Set(e)],m=(...e)=>{if(0===e.length)return[];if(1===e.length)return[...e[0]];const[t,...n]=e;return d(t).filter(e=>n.every(t=>t.includes(e)))};function p(e,t){if(!e)throw new Error(t)}const g=e=>null===e,y=e=>null==e,w=e=>null!=e,b=e=>void 0===e,S=e=>"number"==typeof e,A=e=>"boolean"==typeof e,x=e=>"object"==typeof e,v=e=>x(e)&&!g(e)&&0===Object.keys(e).length,M=e=>e instanceof Date,I=e=>e instanceof Blob,O=e=>e instanceof Error,C=e=>M(e)&&!isNaN(e.getTime()),E=e=>e instanceof RegExp,T=e=>e instanceof Map,F=e=>e instanceof Set,P=e=>"symbol"==typeof e,B=e=>S(e)&&isFinite(e),D=e=>S(e)&&Number.isInteger(e),L=e=>B(e)&&!Number.isInteger(e),N=(e,t)=>(p(t>0,"Chunk size must be greater than 0"),Array.from({length:Math.ceil(e.length/t)},(n,r)=>e.slice(r*t,(r+1)*t))),_=e=>e.filter(Boolean),$=e=>Array.isArray(e),k=e=>$(e)&&0===e.length,R=(e,t,n)=>{if(!e?.length||!t)return{previousItem:null,currentItem:null,nextItem:null};const r=e.findIndex(e=>n(e,t));return-1===r?{previousItem:null,currentItem:null,nextItem:null}:{previousItem:r>0?e[r-1]:null,currentItem:e[r],nextItem:r<e.length-1?e[r+1]:null}},j=(e,t,n)=>{const r=e.includes(t);return r===(n??!r)?e:r?h(e,[t]):[...e,t]},X=()=>{},H=e=>"function"==typeof e,U=e=>(...t)=>!e(...t),W=e=>{let t,n=!1;return function(...r){return n||(n=!0,t=e.apply(this,r)),t}},Y=e=>H(e?.then),z=async(e,t)=>{const n=[];for(let r=0;r<e.length;r++)n.push(await t(e[r],r,e));return n},J=async(e,t)=>Promise.all(e.map(t)),Z=async(e,t)=>{const n=[];for(let r=0;r<e.length;r++){const a=e[r];await t(a,r,e)&&n.push(a)}return n},q=async(e,t)=>{const n=await J(e,async(e,n,r)=>!!await t(e,n,r)&&e);return _(n)},V=async(e,t)=>{for(let n=0;n<e.length;n++)if(await t(e[n],n,e))return!0;return!1},G=async(e,t)=>{for(let n=0;n<e.length;n++)if(!await t(e[n],n,e))return!1;return!0},K=async(e,t,n)=>{let r=n;for(let n=0;n<e.length;n++)r=await t(r,e[n],n,e);return r},Q=async(e,t)=>{for(let n=0;n<e.length;n++)if(await t(e[n],n,e))return e[n];return null},ee=e=>new Promise(t=>setTimeout(t,e)),te=async(e,t,n="Operation timed out")=>{try{return await Promise.race([e,ee(t).then(()=>Promise.reject(new Error(n)))])}finally{}},ne=(e,{maxAttempts:t=3,delayMs:n=300,backoff:r=!0,onRetry:a}={})=>async(...l)=>{let i;for(let o=1;o<=t;o++)try{return await e(...l)}catch(e){if(i=e,o<t){a?.(o,e);const t=r?n*2**(o-1):n;await ee(t)}}throw i},re=e=>{try{return JSON.parse(e)}catch{return null}},ae="application/json",le=(e,t)=>{e.setData(ae,JSON.stringify(t))},ie=e=>{const t=e.getData(ae);return t?re(t):null},oe=e=>"string"==typeof e,se=(e,{fileName:t,target:n}={})=>{if(b(document))return;const r=document.createElement("a");let a=null;try{const l=oe(e)?e:a=URL.createObjectURL(e);r.href=l,t&&(r.download=t),n&&(r.target=n),document.body.appendChild(r),r.click()}finally{r.remove(),a&&setTimeout(()=>{p(a,"Object URL should not be null"),URL.revokeObjectURL(a)},0)}},ce=e=>{const t=e.toString();window.history.replaceState(window.history.state,"",`${window.location.pathname}${t?`?${t}`:""}${window.location.hash}`)},ue=e=>e.scrollWidth>e.clientWidth,fe=e=>Math.max(0,e.scrollWidth-e.clientWidth),he=e=>e.scrollHeight>e.clientHeight,de=e=>Math.max(0,e.scrollHeight-e.clientHeight),me=({containerSize:e,elementOffset:t,elementSize:n})=>-(t+n/2-e/2),pe=(e,t)=>t<=0?0:Math.max(-t,Math.min(e,0)),ge=(e,t,{axis:n="both",shouldClamp:r=!0}={})=>{let a=0,l=0;if("x"===n||"both"===n){const n=me({containerSize:e.clientWidth,elementOffset:t.offsetLeft,elementSize:t.clientWidth});a=r?pe(n,fe(e)):n}if("y"===n||"both"===n){const n=me({containerSize:e.clientHeight,elementOffset:t.offsetTop,elementSize:t.clientHeight});l=r?pe(n,de(e)):n}e.style.transform=`translate(${a}px, ${l}px)`},ye=e=>{const t=window.getComputedStyle(e).getPropertyValue("transform").match(/^matrix\((.+)\)$/);if(!t)return{translateX:0,translateY:0,scaleX:1,scaleY:1,skewX:0,skewY:0};const[n,r,a,l,i,o]=t[1].split(", ").map(parseFloat);return{translateX:i,translateY:o,scaleX:n,scaleY:l,skewX:a,skewY:r}},we=()=>{if("undefined"==typeof window||!window.localStorage)return!1;try{return window.localStorage.getItem("__non_existing_key__"),!0}catch{return!1}},be=()=>{if(!we())return{readable:!1,writable:!1};try{const e="__test_write__";return window.localStorage.setItem(e,"1"),window.localStorage.removeItem(e),{readable:!0,writable:!0}}catch{}return{readable:!0,writable:!1}},Se=e=>e instanceof File,Ae=e=>{if(!e)return[];const t=[];for(let n=0;n<e.length;n++)t.push(e[n]);return t},xe=(e,t)=>new File([e],t,{type:e.type}),ve=async(e,{skipFiles:t=[".DS_Store","Thumbs.db","desktop.ini","ehthumbs.db",".Spotlight-V100",".Trashes",".fseventsd","__MACOSX"]}={})=>{const n=new Set(t),r=await(async e=>{const t=e.createReader(),n=async()=>new Promise((e,r)=>{t.readEntries(async t=>{if(t.length)try{const r=await n();e([...t,...r])}catch(e){r(e)}else e([])},r)});return n()})(e);return(await J(r,async e=>e.isDirectory?ve(e,{skipFiles:t}):n.has(e.name)?[]:[await new Promise((t,n)=>{e.file(t,n)})])).flat()},Me=async(e,t={})=>{const n=e?.items;if(!n)return[];const r=[];for(let e=0;e<n.length;e++){const a=n[e];if("webkitGetAsEntry"in a){const e=a.webkitGetAsEntry?.();if(e?.isDirectory){r.push(ve(e,t));continue}if(e?.isFile){r.push(new Promise((t,n)=>e.file(e=>t([e]),n)));continue}}const l=a.getAsFile();l&&r.push(Promise.resolve([l]))}return(await Promise.all(r)).flat()},Ie=(e,...t)=>"function"==typeof e?e(...t):e,Oe=({delta:e,value:t,min:n,max:r})=>{if(0===e)return null;const a=t+e;return e<0?t<=n?null:Math.max(a,n):e>0?t>=r?null:Math.min(a,r):null},Ce=({value:e,min:t,max:n,velocityPxMs:r,deltaTimeMs:a,friction:l=.002,minVelocityPxMs:i=.01,emaAlpha:o=.2})=>{if(Math.abs(r)<i)return null;const s=Oe({delta:r*a,value:e,min:t,max:n});if(null===s)return null;const c=r*Math.exp(-l*a),u=o>0?r*(1-o)+c*o:c;return Math.abs(u)<i?null:{value:s,velocityPxMs:u}},Ee=()=>`${Math.floor(1e3*performance.now()).toString(36)}${Math.random().toString(36).slice(2,10)}`,Te=(e,t)=>Math.max(0,Math.min(e.right,t.right)-Math.max(e.left,t.left))*Math.max(0,Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top))/(t.width*t.height),Fe=(e,t,{allowFallback:n=!0,invert:r=!0}={})=>{const a=r?-1:1;switch(t){case"x":return{deltaX:a*(0!==e.deltaX?e.deltaX:n?e.deltaY:0),deltaY:0};case"y":return{deltaX:0,deltaY:a*e.deltaY};default:return{deltaX:a*e.deltaX,deltaY:a*e.deltaY}}},Pe=(e,t,n,r)=>{const a=n-e,l=r-t;return Math.hypot(a,l)},Be=(e,t)=>Math.abs(e/t),De=(e,t)=>e*t/100,Le=e=>{let t=5381;for(let n=0;n<e.length;n++)t=33*t^e.charCodeAt(n);return(t>>>0).toString(36)},Ne=(e,t,n)=>Math.min(Math.max(e,t),n),_e=e=>Object.entries(e).reduce((e,[t,n])=>(void 0!==n&&(e[t]=n),e),{}),$e=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),ke=e=>{const t=e.charAt(0),n=e.slice(1);return t.toLowerCase()+n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)},Re=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1 $2"),je=e=>0===e.length?[]:e.split(" ").filter(Boolean),Xe=e=>""===e||y(e),He=e=>{const t=e.lastIndexOf(".");return t<=0||t===e.length-1?[e,""]:[e.slice(0,t),e.slice(t+1).toLowerCase()]},Ue=(e,t)=>{if(0===e.length)return[];const n=t.charCodeAt(0),r=[];for(let t=0;t<e.length;t++)e.charCodeAt(t)===n&&r.push(t);return r},We=(e,t,n)=>{if(0===e.length)return;const r=e.length;for(let a=0;a<r;a++){const l=e[a],i={charIndex:a,prevChar:a>0?e[a-1]:null,nextChar:a<r-1?e[a+1]:null};n?.(l,i)||t(l,i)}},Ye=(e,t=1/0)=>0===e.length?"":je(e).slice(0,t).map(e=>e[0]).join("").toUpperCase(),ze=(e,t,n,r=t)=>e.split(t).map((e,t)=>n(e.trim(),t)).join(r),Je=(e,t,n,r=[],a=void 0,l=0)=>(e?.forEach(e=>{const{[n]:i,...o}=e,s=e[n],c=Array.isArray(s);if(r.push({...o,parentId:a,depthLevel:l,childCount:c?s.length:0}),c){const a=e[t];Je(s,t,n,r,a,l+1)}}),r),Ze=(e,t,n)=>e.filter(e=>e.parentId===t&&(!n||n(e))),qe=(e,t,n,r)=>{const a=je(r.toLowerCase());if(!a.length)return e;const l=e.reduce((e,n,r)=>(e[n[t]]=r,e),{});return e.reduce((r,i)=>{const o=i[n];if(!o)return r;if(r.some(e=>e[t]===i[t]))return r;const s=je(o.toLowerCase());if(a.every(e=>s.some(t=>t.startsWith(e))))if(b(i.parentId)){r.push(i);const n=a=>{a.childCount&&e.forEach(e=>{e.parentId===a[t]&&(r.push(e),n(e))})};n(i)}else{const t=n=>{const a=l[n.parentId],i=e[a];b(i.parentId)||t(i);const o=r.length?r[r.length-1].parentId:null;(g(o)||o!==n.parentId)&&(p(i,"[@react-hive/honey-utils]: Parent node was not found."),r.push(i))};t(i),r.push(i)}return r},[])},Ve=(e,t)=>{p(t>=0&&t<=1,`[@react-hive/honey-utils]: Alpha "${t}" must be a number between 0 and 1.`);const n=e.match(/^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/);p(n,`[@react-hive/honey-utils]: Invalid hex format: ${e}`);const r=n[1];return`#${(3===r.length?r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r)+Math.round(255*t).toString(16).toUpperCase().padStart(2,"0")}`},Ge=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,Ke=e=>{if(!Ge.test(e))return null;try{return new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode((e=>{if("function"==typeof Uint8Array.fromBase64)return Uint8Array.fromBase64(e);if("undefined"!=typeof Buffer)return Buffer.from(e,"base64");const t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n})(e))}catch{return null}},Qe=e=>{const t=Ke(e);return null===t?null:re(t)},et=e=>(e=>{if("function"==typeof e.toBase64)return e.toBase64();if("undefined"!=typeof Buffer)return Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64");let t="";for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)})((new TextEncoder).encode(e)),tt=e=>et(JSON.stringify(e));module.exports=t})();
1
+ (()=>{"use strict";const e={d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}};let t={};e.r(t),e.d(t,{DATA_TRANSFER_JSON_MIME:()=>le,FOCUSABLE_HTML_TAGS:()=>i,applyInertiaStep:()=>Fe,assert:()=>p,blobToFile:()=>Me,calculateCenterOffset:()=>pe,calculateEuclideanDistance:()=>Le,calculateMovingSpeed:()=>Ne,calculatePercentage:()=>_e,camelToDashCase:()=>Xe,camelToWords:()=>He,centerElementInContainer:()=>ye,chunk:()=>_,clamp:()=>je,clampOffsetToOverflow:()=>ge,cloneBlob:()=>n,compact:()=>$,compose:()=>f,decodeBase64:()=>tt,decodeBase64Json:()=>nt,definedProps:()=>ke,delay:()=>te,difference:()=>h,downloadFile:()=>ce,encodeBase64:()=>rt,encodeBase64Json:()=>at,everyAsync:()=>K,fileListToFiles:()=>Ie,filterParallel:()=>q,filterSequential:()=>V,findAsync:()=>ee,findCharIndices:()=>Je,flattenTree:()=>qe,forEachChar:()=>ze,generateEphemeralId:()=>Pe,getAdjacentItems:()=>R,getDOMRectIntersectionRatio:()=>Be,getDataTransferJson:()=>oe,getElementOffsetRect:()=>r,getFocusableHtmlElements:()=>s,getLocalStorageCapabilities:()=>Se,getTreeChildren:()=>Ge,getWordsInitials:()=>Ze,getXOverflowWidth:()=>he,getYOverflowHeight:()=>me,hasXOverflow:()=>fe,hasYOverflow:()=>de,hashString:()=>$e,hexWithAlpha:()=>Qe,intersection:()=>m,invokeIfFunction:()=>Ee,isAnchorHtmlElement:()=>a,isArray:()=>j,isBlob:()=>M,isBool:()=>A,isContentEditableHtmlElement:()=>l,isDate:()=>I,isDecimal:()=>L,isDefined:()=>w,isEmptyArray:()=>k,isEmptyObject:()=>v,isEnumValue:()=>N,isError:()=>O,isFile:()=>ve,isFiniteNumber:()=>B,isFunction:()=>U,isHtmlElementFocusable:()=>o,isInteger:()=>D,isLocalStorageReadable:()=>be,isMap:()=>T,isNil:()=>y,isNilOrEmptyString:()=>We,isNull:()=>g,isNumber:()=>S,isObject:()=>x,isPromise:()=>J,isRegExp:()=>E,isSet:()=>F,isString:()=>se,isSymbol:()=>P,isUndefined:()=>b,isValidDate:()=>C,moveFocusWithinContainer:()=>c,noop:()=>H,not:()=>W,once:()=>Y,parse2DMatrix:()=>we,parseFileName:()=>Ye,parseJson:()=>ae,pipe:()=>u,readFilesFromDataTransfer:()=>Ce,readLocalStorageJson:()=>Ae,reduceAsync:()=>Q,replaceHistorySearchParams:()=>ue,resolveAxisDelta:()=>De,resolveBoundedDelta:()=>Te,retry:()=>re,runParallel:()=>Z,runSequential:()=>z,searchTree:()=>Ke,setDataTransferJson:()=>ie,someAsync:()=>G,splitMapJoin:()=>Ve,splitStringIntoWords:()=>Ue,timeout:()=>ne,toKebabCase:()=>Re,toggleArrayItem:()=>X,traverseFileSystemDirectory:()=>Oe,unique:()=>d,writeLocalStorageJson:()=>xe});const n=e=>new Blob([e],{type:e.type}),r=e=>new DOMRect(e.offsetLeft,e.offsetTop,e.clientWidth,e.clientHeight),a=e=>"A"===e.tagName,l=e=>"true"===e.getAttribute("contenteditable"),i=["INPUT","SELECT","TEXTAREA","BUTTON","A"],o=e=>{if(!e)return!1;const t=window.getComputedStyle(e);if("hidden"===t.visibility||"none"===t.display)return!1;if("disabled"in e&&e.disabled)return!1;const n=e.getAttribute("tabindex");return"-1"!==n&&(i.includes(e.tagName)?!a(e)||""!==e.href:!!l(e)||null!==n)},s=e=>Array.from(e.querySelectorAll("*")).filter(o),c=(e,t=null,{wrap:n=!0,getNextIndex:r}={})=>{const a=document.activeElement,l=t??a?.parentElement;if(!a||!l)return;const i=s(l);if(0===i.length)return;const o=i.indexOf(a);if(-1===o)return;let c;r?c=r(o,e,i):"next"===e?(c=o+1,c>=i.length&&(c=n?0:null)):(c=o-1,c<0&&(c=n?i.length-1:null)),null!==c&&i[c]?.focus()},u=(...e)=>t=>e.reduce((e,t)=>t(e),t),f=(...e)=>t=>e.reduceRight((e,t)=>t(e),t),h=(e,t)=>e.filter(e=>!t.includes(e)),d=e=>[...new Set(e)],m=(...e)=>{if(0===e.length)return[];if(1===e.length)return[...e[0]];const[t,...n]=e;return d(t).filter(e=>n.every(t=>t.includes(e)))};function p(e,t){if(!e)throw new Error(t)}const g=e=>null===e,y=e=>null==e,w=e=>null!=e,b=e=>void 0===e,S=e=>"number"==typeof e,A=e=>"boolean"==typeof e,x=e=>"object"==typeof e,v=e=>x(e)&&!g(e)&&0===Object.keys(e).length,I=e=>e instanceof Date,M=e=>e instanceof Blob,O=e=>e instanceof Error,C=e=>I(e)&&!isNaN(e.getTime()),E=e=>e instanceof RegExp,T=e=>e instanceof Map,F=e=>e instanceof Set,P=e=>"symbol"==typeof e,B=e=>S(e)&&isFinite(e),D=e=>S(e)&&Number.isInteger(e),L=e=>B(e)&&!Number.isInteger(e),N=(e,t)=>Object.values(e).includes(t),_=(e,t)=>(p(t>0,"Chunk size must be greater than 0"),Array.from({length:Math.ceil(e.length/t)},(n,r)=>e.slice(r*t,(r+1)*t))),$=e=>e.filter(Boolean),j=e=>Array.isArray(e),k=e=>j(e)&&0===e.length,R=(e,t,n)=>{if(!e?.length||!t)return{previousItem:null,currentItem:null,nextItem:null};const r=e.findIndex(e=>n(e,t));return-1===r?{previousItem:null,currentItem:null,nextItem:null}:{previousItem:r>0?e[r-1]:null,currentItem:e[r],nextItem:r<e.length-1?e[r+1]:null}},X=(e,t,n)=>{const r=e.includes(t);return r===(n??!r)?e:r?h(e,[t]):[...e,t]},H=()=>{},U=e=>"function"==typeof e,W=e=>(...t)=>!e(...t),Y=e=>{let t,n=!1;return function(...r){return n||(n=!0,t=e.apply(this,r)),t}},J=e=>U(e?.then),z=async(e,t)=>{const n=[];for(let r=0;r<e.length;r++)n.push(await t(e[r],r,e));return n},Z=async(e,t)=>Promise.all(e.map(t)),V=async(e,t)=>{const n=[];for(let r=0;r<e.length;r++){const a=e[r];await t(a,r,e)&&n.push(a)}return n},q=async(e,t)=>{const n=await Z(e,async(e,n,r)=>!!await t(e,n,r)&&e);return $(n)},G=async(e,t)=>{for(let n=0;n<e.length;n++)if(await t(e[n],n,e))return!0;return!1},K=async(e,t)=>{for(let n=0;n<e.length;n++)if(!await t(e[n],n,e))return!1;return!0},Q=async(e,t,n)=>{let r=n;for(let n=0;n<e.length;n++)r=await t(r,e[n],n,e);return r},ee=async(e,t)=>{for(let n=0;n<e.length;n++)if(await t(e[n],n,e))return e[n];return null},te=e=>new Promise(t=>setTimeout(t,e)),ne=async(e,t,n="Operation timed out")=>{try{return await Promise.race([e,te(t).then(()=>Promise.reject(new Error(n)))])}finally{}},re=(e,{maxAttempts:t=3,delayMs:n=300,backoff:r=!0,onRetry:a}={})=>async(...l)=>{let i;for(let o=1;o<=t;o++)try{return await e(...l)}catch(e){if(i=e,o<t){a?.(o,e);const t=r?n*2**(o-1):n;await te(t)}}throw i},ae=e=>{try{return JSON.parse(e)}catch{return null}},le="application/json",ie=(e,t)=>{e.setData(le,JSON.stringify(t))},oe=e=>{const t=e.getData(le);return t?ae(t):null},se=e=>"string"==typeof e,ce=(e,{fileName:t,target:n}={})=>{if(b(document))return;const r=document.createElement("a");let a=null;try{const l=se(e)?e:a=URL.createObjectURL(e);r.href=l,t&&(r.download=t),n&&(r.target=n),document.body.appendChild(r),r.click()}finally{r.remove(),a&&setTimeout(()=>{p(a,"Object URL should not be null"),URL.revokeObjectURL(a)},0)}},ue=e=>{const t=e.toString();window.history.replaceState(window.history.state,"",`${window.location.pathname}${t?`?${t}`:""}${window.location.hash}`)},fe=e=>e.scrollWidth>e.clientWidth,he=e=>Math.max(0,e.scrollWidth-e.clientWidth),de=e=>e.scrollHeight>e.clientHeight,me=e=>Math.max(0,e.scrollHeight-e.clientHeight),pe=({containerSize:e,elementOffset:t,elementSize:n})=>-(t+n/2-e/2),ge=(e,t)=>t<=0?0:Math.max(-t,Math.min(e,0)),ye=(e,t,{axis:n="both",shouldClamp:r=!0}={})=>{let a=0,l=0;if("x"===n||"both"===n){const n=pe({containerSize:e.clientWidth,elementOffset:t.offsetLeft,elementSize:t.clientWidth});a=r?ge(n,he(e)):n}if("y"===n||"both"===n){const n=pe({containerSize:e.clientHeight,elementOffset:t.offsetTop,elementSize:t.clientHeight});l=r?ge(n,me(e)):n}e.style.transform=`translate(${a}px, ${l}px)`},we=e=>{const t=window.getComputedStyle(e).getPropertyValue("transform").match(/^matrix\((.+)\)$/);if(!t)return{translateX:0,translateY:0,scaleX:1,scaleY:1,skewX:0,skewY:0};const[n,r,a,l,i,o]=t[1].split(", ").map(parseFloat);return{translateX:i,translateY:o,scaleX:n,scaleY:l,skewX:a,skewY:r}},be=()=>{if("undefined"==typeof window||!window.localStorage)return!1;try{return window.localStorage.getItem("__non_existing_key__"),!0}catch{return!1}},Se=()=>{if(!be())return{readable:!1,writable:!1};try{const e="__test_write__";return window.localStorage.setItem(e,"1"),window.localStorage.removeItem(e),{readable:!0,writable:!0}}catch{}return{readable:!0,writable:!1}},Ae=e=>{try{const t=window.localStorage.getItem(e);return null===t?null:ae(t)}catch{return null}},xe=(e,t)=>{try{return window.localStorage.setItem(e,JSON.stringify(t)),!0}catch{return!1}},ve=e=>e instanceof File,Ie=e=>{if(!e)return[];const t=[];for(let n=0;n<e.length;n++)t.push(e[n]);return t},Me=(e,t)=>new File([e],t,{type:e.type}),Oe=async(e,{skipFiles:t=[".DS_Store","Thumbs.db","desktop.ini","ehthumbs.db",".Spotlight-V100",".Trashes",".fseventsd","__MACOSX"]}={})=>{const n=new Set(t),r=await(async e=>{const t=e.createReader(),n=async()=>new Promise((e,r)=>{t.readEntries(async t=>{if(t.length)try{const r=await n();e([...t,...r])}catch(e){r(e)}else e([])},r)});return n()})(e);return(await Z(r,async e=>e.isDirectory?Oe(e,{skipFiles:t}):n.has(e.name)?[]:[await new Promise((t,n)=>{e.file(t,n)})])).flat()},Ce=async(e,t={})=>{const n=e?.items;if(!n)return[];const r=[];for(let e=0;e<n.length;e++){const a=n[e];if("webkitGetAsEntry"in a){const e=a.webkitGetAsEntry?.();if(e?.isDirectory){r.push(Oe(e,t));continue}if(e?.isFile){r.push(new Promise((t,n)=>e.file(e=>t([e]),n)));continue}}const l=a.getAsFile();l&&r.push(Promise.resolve([l]))}return(await Promise.all(r)).flat()},Ee=(e,...t)=>"function"==typeof e?e(...t):e,Te=({delta:e,value:t,min:n,max:r})=>{if(0===e)return null;const a=t+e;return e<0?t<=n?null:Math.max(a,n):e>0?t>=r?null:Math.min(a,r):null},Fe=({value:e,min:t,max:n,velocityPxMs:r,deltaTimeMs:a,friction:l=.002,minVelocityPxMs:i=.01,emaAlpha:o=.2})=>{if(Math.abs(r)<i)return null;const s=Te({delta:r*a,value:e,min:t,max:n});if(null===s)return null;const c=r*Math.exp(-l*a),u=o>0?r*(1-o)+c*o:c;return Math.abs(u)<i?null:{value:s,velocityPxMs:u}},Pe=()=>`${Math.floor(1e3*performance.now()).toString(36)}${Math.random().toString(36).slice(2,10)}`,Be=(e,t)=>Math.max(0,Math.min(e.right,t.right)-Math.max(e.left,t.left))*Math.max(0,Math.min(e.bottom,t.bottom)-Math.max(e.top,t.top))/(t.width*t.height),De=(e,t,{allowFallback:n=!0,invert:r=!0}={})=>{const a=r?-1:1;switch(t){case"x":return{deltaX:a*(0!==e.deltaX?e.deltaX:n?e.deltaY:0),deltaY:0};case"y":return{deltaX:0,deltaY:a*e.deltaY};default:return{deltaX:a*e.deltaX,deltaY:a*e.deltaY}}},Le=(e,t,n,r)=>{const a=n-e,l=r-t;return Math.hypot(a,l)},Ne=(e,t)=>Math.abs(e/t),_e=(e,t)=>e*t/100,$e=e=>{let t=5381;for(let n=0;n<e.length;n++)t=33*t^e.charCodeAt(n);return(t>>>0).toString(36)},je=(e,t,n)=>Math.min(Math.max(e,t),n),ke=e=>Object.entries(e).reduce((e,[t,n])=>(void 0!==n&&(e[t]=n),e),{}),Re=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Xe=e=>{const t=e.charAt(0),n=e.slice(1);return t.toLowerCase()+n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)},He=e=>e.replace(/([a-z0-9])([A-Z])/g,"$1 $2"),Ue=e=>0===e.length?[]:e.split(" ").filter(Boolean),We=e=>""===e||y(e),Ye=e=>{const t=e.lastIndexOf(".");return t<=0||t===e.length-1?[e,""]:[e.slice(0,t),e.slice(t+1).toLowerCase()]},Je=(e,t)=>{if(0===e.length)return[];const n=t.charCodeAt(0),r=[];for(let t=0;t<e.length;t++)e.charCodeAt(t)===n&&r.push(t);return r},ze=(e,t,n)=>{if(0===e.length)return;const r=e.length;for(let a=0;a<r;a++){const l=e[a],i={charIndex:a,prevChar:a>0?e[a-1]:null,nextChar:a<r-1?e[a+1]:null};n?.(l,i)||t(l,i)}},Ze=(e,t=1/0)=>0===e.length?"":Ue(e).slice(0,t).map(e=>e[0]).join("").toUpperCase(),Ve=(e,t,n,r=t)=>e.split(t).map((e,t)=>n(e.trim(),t)).join(r),qe=(e,t,n,r=[],a=void 0,l=0)=>(e?.forEach(e=>{const{[n]:i,...o}=e,s=e[n],c=Array.isArray(s);if(r.push({...o,parentId:a,depthLevel:l,childCount:c?s.length:0}),c){const a=e[t];qe(s,t,n,r,a,l+1)}}),r),Ge=(e,t,n)=>e.filter(e=>e.parentId===t&&(!n||n(e))),Ke=(e,t,n,r)=>{const a=Ue(r.toLowerCase());if(!a.length)return e;const l=e.reduce((e,n,r)=>(e[n[t]]=r,e),{});return e.reduce((r,i)=>{const o=i[n];if(!o)return r;if(r.some(e=>e[t]===i[t]))return r;const s=Ue(o.toLowerCase());if(a.every(e=>s.some(t=>t.startsWith(e))))if(b(i.parentId)){r.push(i);const n=a=>{a.childCount&&e.forEach(e=>{e.parentId===a[t]&&(r.push(e),n(e))})};n(i)}else{const t=n=>{const a=l[n.parentId],i=e[a];b(i.parentId)||t(i);const o=r.length?r[r.length-1].parentId:null;(g(o)||o!==n.parentId)&&(p(i,"[@react-hive/honey-utils]: Parent node was not found."),r.push(i))};t(i),r.push(i)}return r},[])},Qe=(e,t)=>{p(t>=0&&t<=1,`[@react-hive/honey-utils]: Alpha "${t}" must be a number between 0 and 1.`);const n=e.match(/^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/);p(n,`[@react-hive/honey-utils]: Invalid hex format: ${e}`);const r=n[1];return`#${(3===r.length?r[0]+r[0]+r[1]+r[1]+r[2]+r[2]:r)+Math.round(255*t).toString(16).toUpperCase().padStart(2,"0")}`},et=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,tt=e=>{if(!et.test(e))return null;try{return new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}).decode((e=>{if("function"==typeof Uint8Array.fromBase64)return Uint8Array.fromBase64(e);if("undefined"!=typeof Buffer)return Buffer.from(e,"base64");const t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n})(e))}catch{return null}},nt=e=>{const t=tt(e);return null===t?null:ae(t)},rt=e=>(e=>{if("function"==typeof e.toBase64)return e.toBase64();if("undefined"!=typeof Buffer)return Buffer.from(e.buffer,e.byteOffset,e.byteLength).toString("base64");let t="";for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return btoa(t)})((new TextEncoder).encode(e)),at=e=>rt(JSON.stringify(e));module.exports=t})();
2
2
  //# sourceMappingURL=index.cjs.map