text: !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("flatted"),require("mithril")):"function"==typeof define&&define.amd?define(["exports","flatted","mithril"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).mithrilHooks={},t.flatted,t.m)}(this,(function(t,e,s){"use strict";function n(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var o=n(s);let r;const a=Function.prototype.call.bind(Function.prototype.call),u=()=>o.default.redraw(),i=t=>{const e=r,{depsIndex:s}=e;e.depsIndex+=1;const n=e.depsStates[s]||[],o=void 0===t||!!Array.isArray(t)&&(t.length>0?!t.every(((t,e)=>t===n[e])):!e.setup);return void 0!==t&&(e.depsStates[s]=t),o},c=(t=!1)=>(e,s)=>{const n=r;if(i(s)){const{depsIndex:s}=n,o=()=>{const t=e();"function"==typeof t&&(n.teardowns.set(s,t),n.teardowns.set("_",u))},r=n.teardowns.get(s);try{"function"==typeof r&&r()}finally{n.teardowns.delete(s)}n.updates.push(t?()=>new Promise((t=>requestAnimationFrame(t))).then(o):o)}},d=(t,s)=>{const n=r,o=n.statesIndex;return n.statesIndex+=1,n.setup||(n.states[o]=t),[n.states[o],t=>{const r=n.states[o],a=s?s(t,o):t;n.states[o]=a,e.stringify(a)!==e.stringify(r)&&u()},o]},f=c(!0),p=c();const l=(t,e)=>{const s=r,n=i(e),[o,a]=s.setup?d():d(t());return s.setup&&n&&a(t()),o};t.useCallback=(t,e)=>l((()=>t),e),t.useEffect=f,t.useLayoutEffect=p,t.useMemo=l,t.useReducer=function(t,e,s){const n=r,o=!n.setup&&s?s(e):e;return(()=>{const[e,s,r]=d(o);return[e,e=>{const o=n.states[r];return s(t(o,e))}]})()},t.useRef=t=>{const[e]=d({current:t});return e},t.useState=t=>{const e=r;return d(t,((t,s)=>"function"==typeof t?t(e.states[s],s):t))},t.withHooks=(t,e)=>{const s=t=>{const e=r;r=t.state;try{t.state.updates.forEach(a)}finally{Object.assign(t.state,{setup:!0,updates:[],depsIndex:0,statesIndex:0}),r=e}};return{oninit:t=>{Object.assign(t.state,{setup:!1,states:[],statesIndex:0,depsStates:[],depsIndex:0,updates:[],cleanups:new Map,teardowns:new Map})},oncreate:s,onupdate:s,view:s=>{const n=r;r=s.state;try{return t(Object.assign(Object.assign(Object.assign({},e),s.attrs),{vnode:s,children:s.children}))}catch(t){console.error(t)}finally{r=n}},onremove:t=>{const e=r;r=t.state;try{t.state.teardowns.forEach(a)}finally{r=e}}}},Object.defineProperty(t,"__esModule",{value:!0})}));
  //# sourceMappingURL=mithril-hooks.js.map
  