apply-hooks
Version:
A high-quality & reliable JavaScript Hooks library.
2 lines (1 loc) • 20.8 kB
JavaScript
var wHooks=function(t){"use strict";const e={},n=e.toString,r=t=>n.call(t),i=t=>{const e=r(t),n=/\s+([a-zA-Z0-9]+)]/.exec(e);return n?n[1].toLowerCase():""},s=t=>"object"===i(t),o=/^0b[01]+$/i,h=/^[-+]0x[0-9a-f]+$/i,l=/^\s+|\s+$/g,a=/^0o[0-7]+$/i,u=parseInt,c=t=>{const e=i(t);if(["bigint"].includes(e))return t;if(["undefined","symbol","function","map","set"].includes(e))return NaN;if("object"===e){const e="function"==typeof t.valueOf?t.valueOf():t;t=s(e)?`${e}`:e}if(["null","string","boolean"].includes(e))return+t;t=(t+="").replace(l,"");const n=o.test(t);return n||a.test(t)?u(t.slice(2),n?2:8):h.test(t)?NaN:+t},d=1/0,f=Number.MAX_VALUE;function p(t){if(!t)return 0===t?t:0;const e=c(t);if(t===d||t===-1/0){return(t<0?-1:1)*f}return e===t?t:0}function g(t){const e=p(t),n=e%1;return n?e-n:e}const b=t=>"function"===i(t),m=t=>"null"===i(t),v=t=>"undefined"===i(t),x=t=>!m(t)&&t===t.window,y=t=>{const e=!!t&&t.length;return!(m(t)||v(t)||b(t)||x(t)||v(e)||m(e))},w=t=>{let e;if("SELECT"===t.nodeName)t.focus(),e=t.value;else if("INPUT"===t.nodeName||"TEXTAREA"===t.nodeName){const n=t,r=n.hasAttribute("readonly");r||n.setAttribute("readonly",""),n.select(),n.setSelectionRange(0,n.value.length),r||n.removeAttribute("readonly"),e=n.value}else{const n=t;n.hasAttribute("contenteditable")&&n.focus();const r=window.getSelection(),i=document.createRange();i.selectNodeContents(n),r.removeAllRanges(),r.addRange(i),e=r.toString()}return e},E=e.hasOwnProperty,S=E.toString,z=Object.getPrototypeOf,A=S.call(Object),k=t=>{if(!t||"object"!==i(t))return!1;const e=z(t);if(!e)return!0;const n=E.call(e,"constructor")&&e.constructor;return"function"==typeof n&&S.call(n)===A},T=t=>"array"===i(t),O=t=>"string"===i(t),q=t=>"number"===i(t),C=()=>!("undefined"==typeof window||!window.document||!window.document.createElement);function j(t,...e){let n=0;for(;n<arguments.length;n+=1){const e=arguments[n];for(const n in e)t[n]=e[n]}return t}const I={read:function(t){return'"'===t[0]&&(t=t.slice(1,-1)),t.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(t){return encodeURIComponent(t).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},N=(t,e,n)=>{if(!s(t)&&!T(t)&&!y(t))return console.warn(`${t} non iterator`),!1;if(n=self||void 0,T(t)||y(t)){const r=t;let i=0;for(;i<r.length;i+=1){const t=r[i];if(!1===e.call(n,t,i))return!1}}else{const r=t;for(const t in r){if(!1===e.call(n,r[t],t))return!1}}return!0};const P=(t,e,n)=>{if(v(document))return;n=j({},{path:"/"},n),q(n.expires)&&(n.expires=new Date(Date.now()+864e5*n.expires)),n.expires&&(n.expires=n.expires.toUTCString()),t=encodeURIComponent(t).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);let r="";for(const t in n)n[t]&&(r+="; "+t,!0!==n[t]&&(r+="="+n[t].split(";")[0]));const i=t+"="+I.write(e)+r;return document.cookie=i},B=t=>{if(v(document))return;const e=document.cookie?document.cookie.split("; "):[],n={};for(let r=0;r<e.length;r++){let i=e[r].split("="),s=i.slice(1).join("=");try{let e=decodeURIComponent(i[0]);if(n[e]=I.read(s),t===e)break}catch(t){}}return t?n[t]:n},L=P,R=(t,e={})=>{P(t,"",j({},e,{expires:-1}))},D=Array.from,U=Array.prototype.slice,F=t=>s(t)?t:document.querySelector(t);class ${val;next;constructor(t,e){this.val=t,this.next=e,this.val=t,this.next=e||null}}class M{max;head;size;constructor(t){this.max=t,this.head=null,this.max=t||1/0,this.size=0}push(t){if(this.isFull())return!1;const e=new $(t);if(null===this.head)return this.head=e,this.size+=1,!0;let n=this.head;for(;n&&n.next;)n=n.next;return n.next=e,this.size+=1,!0}pop(){if(this.isEmpty())return!1;if(null===this.head?.next){const t=this.head.val;return this.size-=1,this.head=null,t}let t=this.head;for(;t&&t.next&&t.next.next;)t=t.next;const e=t.next.val;return t.next=null,this.size-=1,e}peek(){if(this.isEmpty())return!1;let t=this.head;for(;t&&t.next;)t=t.next;return t.val}isEmpty(){return 0===this.size}isFull(){return this.size===this.max}toString(t=","){const e=[];let n=this.head;for(;n;)e.push(n.val),n=n.next;return e.join(t)}}class _{max;size;stack;constructor(t){this.max=t,this.max=t||1/0,this.size=0,this.stack=[]}push(t){return!this.isFull()&&(this.stack.push(t),this.size+=1,!0)}pop(){if(this.isEmpty())return!1;const t=this.stack.pop();return this.size-=1,t}peek(){return!this.isEmpty()&&this.stack[this.size-1]}isEmpty(){return 0===this.size}isFull(){return this.size===this.max}toString(t=","){return this.stack.join(t)}}class K{queue;constructor(){this.queue=[]}enqueue(t){return this.queue.push(t),!0}dequeue(){return!this.isEmpty()&&this.queue.shift()}front(){return!this.isEmpty()&&this.queue[0]}isEmpty(){return 0===this.queue.length}getSize(){return this.queue.length}toString(t=","){return this.queue.join(t)}}class X{val;next;constructor(t,e){this.val=t,this.next=e,this.val=t,this.next=e||null}}class H{head;size;constructor(){this.head=null,this.size=0}enqueue(t){const e=new X(t);if(null===this.head)return this.head=e,this.size+=1,!0;let n=this.head;for(;n&&n.next;)n=n.next;return n.next=e,this.size+=1,!0}dequeue(){if(this.isEmpty())return!1;const t=this.head;return this.head=t.next,this.size-=1,t.val}front(){return!this.isEmpty()&&this.head.val}isEmpty(){return 0===this.size}getSize(){return this.size}toString(t=","){const e=[];let n=this.head;for(;n;)e.push(n.val),n=n.next;return e.join(t)}}const Q=new Set;let V=[],W=!1;const Z=()=>{if(!1===W)return;let t=setTimeout((()=>{G(),clearTimeout(t),Z()}),1e3/60)},G=()=>{if(V.length<=0)return;const t=[],e=[];let n=0;for(;n<V.length;n+=1){const r=V[n],{cb:i,endCount:s,computedCount:o,computedTime:h,prevTime:l,id:a}=r,u=+new Date;if(u-l>h){if(s!==o){const e={...r,computedCount:o+1,prevTime:u};t.push(e)}e.push(a),i()}}V=t.concat(V.filter((t=>!e.includes(t.id))))},J=()=>{W||(W=!0,Z())},Y=()=>W=!1,tt=t=>{const{cb:e,loopCount:n,loopTime:r}=Object.assign({},{loopCount:1,loopTime:1e3/60},t);if(Q.has(e))return;Q.add(e);const i={id:`${+new Date}_${1e4*Math.random()|0}`,cb:e,endCount:n,computedCount:1,prevTime:0,computedTime:r};V.push(i),!1===W&&J()};class et{val;next;constructor(t,e){this.val=t,this.next=e,this.val=t,this.next=e||null}}class nt{head;length;constructor(){this.head=null,this.length=0}append(t){const e=new et(t);if(null===this.head)return this.head=e,this.length+=1,!0;let n=this.head;for(;n&&n.next;)n=n.next;return n.next=e,this.length+=1,!0}insert(t,e=this.length){if(e<0||e>this.length)return!1;const n=new et(t);if(0===e)return n.next=this.head,this.head=n,this.length+=1,!0;if(e===this.length)return this.append(t);let r=this.head,i=0;for(;++i<e;)r=r.next;return n.next=r.next,r.next=n,this.length+=1,!0}getAll(){const t=[];let e=this.head;for(;e;)t.push(e.val),e=e.next;return t}get(t){if(t<0||t>=this.length)return!1;let e=this.head;for(;e;){if(0===t)return e.val;e=e.next}return!1}indexOf(t){if(this.isEmpty())return-1;let e=this.head,n=0;for(;e;){if(t===e.val)return n;e=e.next,n+=1}return-1}update(t,e){if(t<0||t>=this.length)return!1;let n=this.head,r=0;for(;n;){if(r===t)return n.val=e,!0;n=n.next,r+=1}return!1}removeAt(t){if(t<0||t>=this.length)return!1;if(0===t){const t=this.head.val;return this.head=this.head?.next,this.length-=1,t}let e=this.head,n=0;for(;++n<t;)e=e?.next;const r=e.next.val;return e.next=e?.next?.next,this.length-=1,r}remove(t){return this.removeAt(this.indexOf(t))}isEmpty(){return 0===this.length}size(){return this.length}toString(t=","){const e=[];let n=this.head;for(;n;)e.push(n.val),n=n.next;return e.join(t)}}const rt=()=>{const t=new nt;return{append:t.append.bind(t),insert:t.insert.bind(t),get:t.get.bind(t),indexOf:t.indexOf.bind(t),update:t.update.bind(t),removeAt:t.removeAt.bind(t),remove:t.remove.bind(t),isEmpty:t.isEmpty.bind(t),size:t.size.bind(t),toString:t.toString.bind(t),getAll:t.getAll.bind(t),_self:t}};class it{append;insert;getAll;getSize;getIsEmpty;get;removeAt;lastSort;constructor(){const{append:t,insert:e,getAll:n,size:r,isEmpty:i,get:s,removeAt:o}=rt();this.append=t,this.insert=e,this.getAll=n,this.getSize=r,this.getIsEmpty=i,this.get=s,this.removeAt=o,this.lastSort=-1}enqueue(t,e){if(e&&!q(e))return!1;if(e&&q(e)&&e<0)return!1;if(v(e)){this.lastSort+=1;const e={sort:this.lastSort,val:t};return this.append(e),!0}const n=this.getAll().map((t=>t.sort));let r=0;for(;r<n.length;){if(n[r]>=e)break;r+=1}return this.insert({val:t,sort:e},r),this.lastSort=this.get(this.size()-1).sort+1,!0}dequeue(){if(this.isEmpty())return!1;const t=this.removeAt(0);return"boolean"==typeof t?t:t.val}front(){if(this.isEmpty())return!1;const t=this.get(0);return"boolean"==typeof t?t:t.val}isEmpty(){return this.getIsEmpty()}size(){return this.getSize()}toString(t=","){return this.getAll().map((t=>t.val)).join(t)}}class st{val;next;prev;constructor(t){this.val=t,this.val=t,this.next=null,this.prev=null}}class ot{head;tail;length;constructor(){this.head=null,this.tail=null,this.length=0}append(t){const e=new st(t);if(null===this.head)return this.head=e,this.tail=e,this.length+=1,!0;let n=this.head;for(;n&&n.next;)n=n.next;return e.prev=n,n.next=e,this.tail=e,this.length+=1,!0}insert(t,e=this.length){if(e<0||e>this.length)return!1;const n=new st(t);if(0===e)return this.head.prev=n,n.next=this.head,this.head=n,this.length+=1,!0;if(e===this.length)return this.append(t);let r=this.head,i=0;for(;++i<e;)r=r?.next;return n.next=r?.next,r.next.prev=n,n.prev=r,r.next=n,this.length+=1,!0}get(t){if(t<0||t>=this.length)return!1;let e=this.head,n=0;for(;n++<t;)e=e?.next;return e?.val}indexOf(t){if(this.isEmpty())return-1;let e=0,n=this.head;for(;n;){if(n.val===t)return e;n=n.next,e+=1}return-1}update(t,e){if(t<0||t>=this.length)return!1;let n=0,r=this.head;for(;r;){if(t===n++){r.val=e;break}r=r.next}return!0}removeAt(t){if(t<0||t>=this.length)return!1;if(0===t){const t=this.head?.val;return 1===this.length?(this.head=null,this.tail=null):(this.head=this.head?.next,this.head.prev=null),this.length-=1,t}if(t===this.length-1){const t=this.tail?.val;return this.tail=this.tail?.prev,this.tail.next=null,this.length-=1,t}let e=0,n=this.head;for(;++e<t;)n=n?.next;const r=n?.next?.val;return n.next.next.prev=n,n.next=n.next.next,this.length-=1,r}remove(t){return this.removeAt(this.indexOf(t))}isEmpty(){return 0===this.length}size(){return this.length}forwardString(t=","){const e=[];let n=this.tail;for(;n;)e.push(n.val),n=n.prev;return e.join(t)}backwardString(t=","){const e=[];let n=this.head;for(;n;)e.push(n.val),n=n.next;return e.join(t)}}class ht{data;constructor(t=[]){this.data=t,this.data=[],this.initData(t)}initData(t){t.forEach((t=>{this.offer(t)}))}peek(){return!this.isEmpty()&&this.data[0]}poll(){if(this.isEmpty())return!1;const t=this.data[0];return 1===this.data.length?(this.data.length=0,t):(this.data[0]=this.data.pop(),this.downBubble(0),t)}downBubble(t){const e=this.data.length-1;for(;t<e;){const n=1+(t<<1),r=n+1;if(n>e)break;const i=this.data[n],s=this.data[r]||0,o=this.data[t];if(o>i&&o>s)break;const h=i<s?r:n;if(h===t)break;this.swap(t,h),t=h}}swap(t,e){t!==e&&([this.data[t],this.data[e]]=[this.data[e],this.data[t]])}upBubble(t){for(;0!==t;){const e=t-1>>1,n=this.data[t];if(this.data[e]>=n)break;this.swap(e,t),t=e}}offer(t){return this.data.push(t),1===this.data.length||this.upBubble(this.data.length-1),!0}isEmpty(){return 0===this.data.length}size=()=>this.data.length}class lt{data;constructor(t=[]){this.data=t,this.data=[],this.initData(t)}initData(t){t.forEach((t=>{this.offer(t)}))}peek(){return!this.isEmpty()&&this.data[0]}size(){return this.data.length}offer(t){return this.data.push(t),1===this.size()||this.upBubble(this.size()-1),!0}poll(){if(this.isEmpty())return!1;const t=this.data[0];return 1===this.size()?(this.data=[],t):(this.data[0]=this.data.pop(),this.downBubble(0),t)}upBubble(t){for(;this.data[t]<this.data[t-1>>1];){const e=t-1>>1;this.swap(t,e),t=e}}swap(t,e){t!==e&&([this.data[t],this.data[e]]=[this.data[e],this.data[t]])}downBubble(t){const e=this.size()-1;for(;t<e;){const n=1+(t<<1),r=n+1;if(n>e)break;const i=this.data[n],s=this.data[r]||1/0,o=this.data[t];if(o<i&&o<s)break;const h=i<s?n:r;if(h===t)break;this.swap(t,h),t=h}}isEmpty(){return 0===this.data.length}}class at{content;constructor(t=[]){this.content=[],t.forEach((t=>{this.add(t)}))}[Symbol.iterator]=()=>{const t=this.content.length,e=this.values();let n=0;return{next:()=>({value:[e[n],e[n]],done:n++>=t})}};size(){return this.content.length}add(t){return!this.has(t)&&(this.content.push(t),!0)}forEach(t,e){N(this.content,t,e)}clear(){this.content.length=0}delete(t){if(!this.has(t))return!1;const e=this.content.indexOf(t);return this.content.splice(e,1),!0}has(t){return this.content.includes(t)}keys(){return this.content}values(){return this.content}entries(){const t=this.content.length,e=this.values();let n=0;return{next:()=>({value:[e[n],e[n]],done:n++>=t})}}}class ut{value;left=null;right=null;constructor(t,e=null,n=null){this.value=t,this.left=e,this.right=n}}const ct=t=>t;class dt{root;length=0;data;cb;constructor(t,e){this.root=null,T(t)?(t.forEach((t=>this.insert(t))),this.cb=e||ct):b(t)&&(this.cb=t)}insert(t){const e=new ut(t);let n=null;const r=(t,e)=>{if(null===t)return;const i=this.cb(e),s=this.cb(t.value);n=t,r(i<s?t.left:t.right,e)};if(null===this.root)return this.root=e,this.length+=1,!0;r(this.root,t);const i=this.cb(t),s=this.cb(n.value);return n[i<s?"left":"right"]=e,this.length+=1,!0}search(t){if(this.isEmpty())return!1;let e=this.root;for(;e;){const n=this.cb(e.value);if(n===t)return e.value;e=n<t?e.right:e.left}return!1}inOrderTraverse(t){const e=n=>{null!==n&&(e(n.left),t(n.value),e(n.right))};e(this.root)}preOrderTraverse(t){const e=n=>{null!==n&&(t(n.value),e(n.left),e(n.right))};e(this.root)}postOrderTraverse(t){const e=n=>{null!==n&&(e(n.left),e(n.right),t(n.value))};e(this.root)}sequenceOrderTraverse(t){const e=[this.root];for(;e.length;){const n=e.shift();n&&(t(n.value),e.push(n.left),e.push(n.right))}}min(t=this.root){if(this.isEmpty())return!1;let e=t,n=t;for(;e;)n=e,e=e.left?e.left:e.right;return n.value}max(t=this.root){if(this.isEmpty())return!1;let e=t,n=t;for(;e;)n=e,e=e.right?e.right:e.left;return n.value}isEmpty(){return 0===this.length}size(){return this.length}toKeysArray(t){const e=[];return(t=(t||this.sequenceOrderTraverse).bind(this))((t=>e.push(this.cb(t)))),e}getSuccessor(t){let e=t,n=t.right,r=t;for(;null!=n;)r=e,e=n,n=n.left;return e!=t.right&&(r.left=e.right,e.right=t.right),e}remove(t){if(this.isEmpty())return!1;let e=null,n=null,r=this.root,i=!0;for(;r;){const s=this.cb(r.value);if(s===t){e=r;break}n=r,s<t?(r=r.right,i=!1):(r=r.left,i=!0)}if(null===e)return!1;let s=0;if(e.left&&(s+=1),e.right&&(s+=1),0===s)return e===this.root?this.root=null:i?n.left=null:n.right=null,this.length-=1,e.value;if(1===s)return this.root===e?this.root=e.left||e.right:i?n.left=e.left||e.right:n.right=e.left||e.right,this.length-=1,e.value;let o=this.getSuccessor(e);return e===this.root?this.root=o:i?n.left=o:n.right=o,o.left=e.left,this.length-=1,e.value}}const ft=t=>{if(t.length<=1)return t;let e=t.length-1;for(;e>=0;){for(let n=0;n<e;n+=1){t[n]>t[n+1]&&([t[n],t[n+1]]=[t[n+1],t[n]])}e-=1}return t},pt=t=>{if(t.length<=1)return t;const e=t.length;let n=0;for(;n<e;n+=1){let r=t[n],i=n;for(let s=n+1;s<e;s+=1){const e=t[s];e<r&&(r=e,i=s)}i!==n&&([t[n],t[i]]=[t[i],t[n]])}return t},gt=t=>{if(t.length<=1)return t;const e=t.length;let n=1;for(;n<e;n+=1){const e=t[n];let r=n-1;for(;r>=0&&e<t[r];)[t[r+1],t[r]]=[t[r],t[r+1]],r-=1}return t},bt=t=>{if(t.length<=1)return t;let e=t.length-1>>1;for(;e>=1;){let n=e;for(;n<t.length;n+=1){const r=t[n];let i=n-e;for(;i>=0&&r<t[i];)[t[i+e],t[i]]=[t[i],t[i+e]],i-=e}e>>=1}return t},mt=t=>{if(t.length<=1)return t;const e=t.length-1>>1,n=t[e],r=[],i=[];let s=0;for(;s<t.length;s+=1)s!==e&&(t[s]>n?i:r).push(t[s]);return mt(r).concat(n).concat(mt(i))},vt=(t,e,n)=>{if(e>=n)return;const r=e+(n-e>>1);vt(t,e,r),vt(t,r+1,n),((t,e,n,r)=>{const i=new Array(r-e+1);let s=0,o=e,h=n+1;for(;o<=n&&h<=r;)i[s++]=t[o]<t[h]?t[o++]:t[h++];for(;o<=n;)i[s++]=t[o++];for(;h<=r;)i[s++]=t[h++];let l=0;for(;l<i.length;l+=1)t[e+l]=i[l]})(t,e,r,n)},xt=t=>(t.length<=1||vt(t,0,t.length-1),t);return t.converter=I,t.each=N,t.getTag=r,t.isArray=T,t.isArrayLike=y,t.isBrowser=C,t.isEmptyObject=t=>{if(!k(t)||Object.getOwnPropertySymbols(t).length>0)return!1;let e;for(e in t)return!1;return!0},t.isFunction=b,t.isNull=m,t.isNumber=q,t.isObject=s,t.isPlainObject=k,t.isPrime=t=>{const e=0|Math.sqrt(t);let n=2;for(;n<=e;n+=1)if(t%n==0)return!1;return!0},t.isPromise=t=>(s(t)||"promise"===i(t))&&Reflect.has(t,"then")&&b(t.then),t.isString=O,t.isSymbol=t=>{const e=typeof t;return"symbol"===e||"object"===e&&!!t&&"[object Symbol]"===r(t)},t.isUndefined=v,t.isWindow=x,t.mergeAssign=j,t.select=w,t.toFinite=p,t.toInteger=g,t.toNumber=c,t.toType=i,t.useArrayChunk=(t,e=0)=>{(v(t)||m(t))&&console.error("params <array> must be Array or ArrayLike"),y(t)&&(t=D(t)),T(t)||console.error("params <array> must be Array or ArrayLike");const n=Math.max(g(e),0);if(0===t.length||0===n)return[t];let r=0,i=0;const s=Math.ceil(t.length/n),o=new Array(s);for(;r<s;)o[r++]=U.call(t,i,i+=n);return o},t.useBinarySearchTree=(t=[])=>{const e=new dt(t);return{insert:e.insert.bind(e),search:e.search.bind(e),inOrderTraverse:e.inOrderTraverse.bind(e),preOrderTraverse:e.preOrderTraverse.bind(e),postOrderTraverse:e.postOrderTraverse.bind(e),sequenceOrderTraverse:e.sequenceOrderTraverse.bind(e),min:e.min.bind(e),max:e.max.bind(e),remove:e.remove.bind(e),isEmpty:e.isEmpty.bind(e),size:e.size.bind(e),toKeysArray:e.toKeysArray.bind(e)}},t.useClipboard=()=>{C()||console.error("must be running in browser"),navigator.clipboard||console.error("not support API<navigator.clipboard> copy/ cut content fail");const t=t=>{const e=F(t),n=w(e);return new Promise((t=>{navigator.clipboard?navigator.clipboard.writeText(n).then((()=>{t(n)})).catch((()=>t(!1))):t(!1)}))};return{copy:t,cut:e=>new Promise((n=>{t(e).then((t=>{if(""===t)return n(!1);n(t);const r=F(e);if(r.hasAttribute("disabled")||r.hasAttribute("readonly"))return;const i=r;"INPUT"===i.tagName||"TEXTAREA"===i.tagName?i.value="":"DIV"!==i.tagName&&"SPAN"!==i.tagName||(i.innerText="")}))})),moveToClipboard:t=>new Promise((e=>{navigator.clipboard.writeText(t).then((()=>{e(t)})).catch((()=>{e(!1)}))}))}},t.useCompact=t=>{if(m(t)||!T(t))return[];const e=[];for(const n of t)if(b(n)){n()&&e.push(n)}else n&&e.push(n);return e},t.useCookie=(t,e)=>[e=>{O(e=e||t)||console.error("cookie key must exist");return B(e)},(n,r,i)=>(O(n=t||n)||console.error("cookie key must string"),v(r)?R(n):L(n,r,e||i),!0),()=>B()],t.useDoublyLinkedList=()=>{const t=new ot;return{append:t.append.bind(t),insert:t.insert.bind(t),get:t.get.bind(t),indexOf:t.indexOf.bind(t),update:t.update.bind(t),removeAt:t.removeAt.bind(t),remove:t.remove.bind(t),isEmpty:t.isEmpty.bind(t),size:t.size.bind(t),forwardString:t.forwardString.bind(t),backwardString:t.backwardString.bind(t)}},t.useEventLoop=()=>[tt,Y,J],t.useHeap=function(t,e){let n=t||[],r=e||"big";T(n)||(r="big"===n?"big":"small",n=[]);const i="big"===r?new ht(n):new lt(n);return{poll:i.poll.bind(i),offer:i.offer.bind(i),isEmpty:i.isEmpty.bind(i),size:i.size.bind(i),peek:i.peek.bind(i)}},t.useInterval=(t,e)=>{let n,r,i=0;q(e)?i=e:s(e)&&(i=e.interval||0,n=e.conditionCb),r=window.setInterval((()=>{!(!n||!b(n))&&!!n()&&(clearInterval(r),r=null),t()}),i);return[()=>{null!==r&&(clearInterval(r),r=null)}]},t.useLinkedList=rt,t.useMount=t=>{b(t)||console.error(`useMount: parameter \`fn\` expected to be a function, but got "${typeof t}".`),C()||console.error("The running environment must be a window environment");const e=(...e)=>t?.(...e);window.addEventListener("load",e);return[()=>window.removeEventListener("load",e)]},t.usePriorityQueue=()=>{const t=new it;return{enqueue:t.enqueue.bind(t),dequeue:t.dequeue.bind(t),front:t.front.bind(t),isEmpty:t.isEmpty.bind(t),getSize:t.size.bind(t),toString:t.toString.bind(t)}},t.useQueue=(t=0)=>{const e=new(0===t?K:H);return[e.enqueue.bind(e),e.dequeue.bind(e),e.front.bind(e),e.isEmpty.bind(e),e.getSize.bind(e),e.toString.bind(e)]},t.useSet=(t=[])=>{const e=new at(t),n=e.size.bind(e),r=e.add.bind(e),i=e.clear.bind(e),s=e.delete.bind(e),o=e.entries.bind(e),h=e.forEach.bind(e);return{size:n,add:r,clear:i,del:s,entries:o,has:e.has.bind(e),forEach:h,keys:e.keys.bind(e),values:e.values.bind(e)}},t.useSort=()=>({bubbleSort:ft,selectionSort:pt,insertionSort:gt,hillSort:bt,fastSort:mt,mergeSort:xt}),t.useStack=(t=0,e)=>{const n=new(0===t?_:M)(e);return[n.push.bind(n),n.pop.bind(n),n.peek.bind(n),n.isEmpty.bind(n),n.toString.bind(n),()=>n.size]},t.useTimeout=function(t,e){let n;q(e)||v(e)||console.error("params <delay> no value transfer or must be a number"),e=e||0,n=setTimeout((()=>{t(),clearTimeout(n),n=null}),e)},Object.defineProperty(t,"__esModule",{value:!0}),t}({});