preact-missing-hooks 4.4.0 → 4.5.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/dist/index.d.ts CHANGED
@@ -13,3 +13,4 @@ export * from "./useWasmCompute";
13
13
  export * from "./useWorkerNotifications";
14
14
  export * from "./useLLMMetadata";
15
15
  export * from "./useRefPrint";
16
+ export * from "./useRBAC";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var e=require("preact/hooks"),n=require("preact"),t=require("preact/compat"),r=new Map;function o(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=Array(n);t<n;t++)r[t]=e[t];return r}function i(e,n){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return o(e,n);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)({}).hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},u.apply(null,arguments)}function a(){if("undefined"==typeof navigator)return{online:!0};var e={online:navigator.onLine},n=navigator.connection;return n&&(void 0!==n.effectiveType&&(e.effectiveType=n.effectiveType),void 0!==n.downlink&&(e.downlink=n.downlink),void 0!==n.rtt&&(e.rtt=n.rtt),void 0!==n.saveData&&(e.saveData=n.saveData),void 0!==n.type&&(e.connectionType=n.type)),e}function c(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}var s=new Map;function l(e){return new Promise(function(n,t){e.onsuccess=function(){return n(e.result)},e.onerror=function(){var n;return t(null!=(n=e.error)?n:new DOMException("Unknown IndexedDB error"))}})}function f(e,n){return n?e.then(function(e){return null==n.onSuccess||n.onSuccess(e),e}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}var d=/\b(?:25[0-5]|2[0-4]\d|1?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|1?\d{1,2})){3}\b/g,v=["stun:stun.l.google.com:19302"];function p(e,n){if(null==e)return"";var t=("string"==typeof e?e:String(e)).trim();return t.length>n?t.slice(0,n):t}function m(e){if(!Array.isArray(e))return[];for(var n=[],t=0;t<e.length&&n.length<50;t++){var r=p(e[t],100);r&&n.push(r)}return n}function g(e){var n=p(e,2048);if(!n)return"";try{var t=new URL(n);if("http:"===t.protocol||"https:"===t.protocol)return n}catch(e){}return""}function h(e){try{if("undefined"==typeof window)return!1;var n=window.getComputedStyle(e);return"none"!==n.display&&"hidden"!==n.visibility&&"0"!==n.opacity}catch(e){return!1}}function y(e){var n={};try{for(var t,r=i(Object.keys(e).slice(0,20));!(t=r()).done;){var o=t.value,u=p(o,50);if(u){var a=e[o];"string"==typeof a?n[u]=a.slice(0,500):"number"==typeof a&&Number.isFinite(a)||"boolean"==typeof a?n[u]=a:Array.isArray(a)&&(n[u]=a.map(function(e){return p(e,200)}).filter(Boolean).slice(0,20))}}}catch(e){}return n}function w(){try{if("undefined"==typeof document||!document.querySelectorAll)return;document.querySelectorAll('script[data-llm="true"]').forEach(function(e){return e.remove()})}catch(e){}}var b="use-ref-print-target",E="use-ref-print-styles",k="\n@media print {\n body * {\n visibility: hidden;\n }\n ."+b+",\n ."+b+" * {\n visibility: visible;\n }\n ."+b+" {\n position: absolute !important;\n left: 0 !important;\n top: 0 !important;\n width: 100% !important;\n }\n}\n";exports.useClipboard=function(n){void 0===n&&(n={});var t=n.resetDelay,r=void 0===t?2e3:t,o=e.useState(!1),i=o[0],u=o[1],a=e.useState(null),s=a[0],l=a[1],f=e.useCallback(function(){u(!1),l(null)},[]);return{copy:e.useCallback(function(e){try{if(l(null),"undefined"==typeof navigator||!navigator.clipboard){var n=new Error("Clipboard API is not available");return l(n),Promise.resolve(!1)}return Promise.resolve(c(function(){return Promise.resolve(navigator.clipboard.writeText(e)).then(function(){return u(!0),r>0&&setTimeout(function(){return u(!1)},r),!0})},function(e){var n=e instanceof Error?e:new Error(String(e));return l(n),!1}))}catch(e){return Promise.reject(e)}},[r]),paste:e.useCallback(function(){try{if(l(null),"undefined"==typeof navigator||!navigator.clipboard){var e=new Error("Clipboard API is not available");return l(e),Promise.resolve("")}return Promise.resolve(c(function(){return Promise.resolve(navigator.clipboard.readText())},function(e){var n=e instanceof Error?e:new Error(String(e));return l(n),""}))}catch(e){return Promise.reject(e)}},[]),copied:i,error:s,reset:f}},exports.useEventBus=function(){return{emit:e.useCallback(function(e){var n=arguments,t=r.get(e);t&&t.forEach(function(e){return e.apply(void 0,[].slice.call(n,1))})},[]),on:e.useCallback(function(e,n){var t=r.get(e);return t||(t=new Set,r.set(e,t)),t.add(n),function(){t.delete(n),0===t.size&&r.delete(e)}},[])}},exports.useIndexedDB=function(n){var t=e.useState(null),r=t[0],o=t[1],a=e.useState(null),c=a[0],d=a[1],v=e.useState(!1),p=v[0],m=v[1],g=e.useRef(n);return g.current=n,e.useEffect(function(){var e=!1;d(null),m(!1),o(null);var n=g.current;return function(e){var n=e.name+"_v"+e.version,t=s.get(n);return t||(t=function(e){return new Promise(function(n,t){var r=indexedDB.open(e.name,e.version);r.onerror=function(){var e;return t(null!=(e=r.error)?e:new DOMException("Failed to open database"))},r.onsuccess=function(){return n(r.result)},r.onupgradeneeded=function(n){for(var t=n.target.result,r=e.tables,o=0,u=Object.keys(r);o<u.length;o++){var a=u[o],c=r[a];if(!t.objectStoreNames.contains(a)){var s,l=t.createObjectStore(a,{keyPath:c.keyPath,autoIncrement:null!=(s=c.autoIncrement)&&s});if(c.indexes)for(var f,d=i(c.indexes);!(f=d()).done;){var v=f.value;l.createIndex(v,v,{unique:!1})}}}}})}(e),s.set(n,t),t)}({name:n.name,version:n.version,tables:n.tables}).then(function(n){if(e)n.close();else{var t=function(e){return{get db(){return e},hasTable:function(n){return e.objectStoreNames.contains(n)},table:function(n){return function(e,n){return function(e,n){function t(t){return e.transaction([n],t).objectStore(n)}return{insert:function(e,n){return f(l(t("readwrite").add(e)),n)},update:function(e,n,r){var o=t("readwrite");return f(l(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var t=u({},e,n);return l(o.put(t))}).then(function(){}),r)},delete:function(e,n){return f(l(t("readwrite").delete(e)).then(function(){}),n)},exists:function(e){return l(t("readonly").getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var r=t("readonly").openCursor(),o=[];return f(new Promise(function(n,t){r.onsuccess=function(){var t=r.result;t?(e(t.value)&&o.push(t.value),t.continue()):n(o)},r.onerror=function(){var e;return t(null!=(e=r.error)?e:new DOMException("Unknown error"))}}),n)},upsert:function(e,n){return f(l(t("readwrite").put(e)),n)},bulkInsert:function(e,n){var r=t("readwrite"),o=[];if(0===e.length)return f(Promise.resolve(o),n);var i=0;return f(new Promise(function(n,t){e.forEach(function(u,a){var c=r.add(u);c.onsuccess=function(){o[a]=c.result,++i===e.length&&n(o)},c.onerror=function(){var e;return t(null!=(e=c.error)?e:new DOMException("Unknown error"))}})}),n)},clear:function(e){return f(l(t("readwrite").clear()).then(function(){}),e)},count:function(e){return f(l(t("readonly").count()),null!=e?e:{})}}}(e,n)}(e,n)},transaction:function(n,t,r,o){var i=e.transaction(n,t),a={table:function(e){return function(e,n){return function(e,n){function t(){return e.objectStore(n)}return{insert:function(e,n){return f(l(t().add(e)),n)},update:function(e,n,r){var o=t();return f(l(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var t=u({},e,n);return l(o.put(t))}).then(function(){}),r)},delete:function(e,n){return f(l(t().delete(e)).then(function(){}),n)},exists:function(e){return l(t().getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var r=t().openCursor(),o=[];return f(new Promise(function(n,t){r.onsuccess=function(){var t=r.result;t?(e(t.value)&&o.push(t.value),t.continue()):n(o)},r.onerror=function(){var e;return t(null!=(e=r.error)?e:new DOMException("Unknown error"))}}),n)},upsert:function(e,n){return f(l(t().put(e)),n)},bulkInsert:function(e,n){var r=t(),o=[];if(0===e.length)return f(Promise.resolve(o),n);var i=0;return f(new Promise(function(n,t){e.forEach(function(u,a){var c=r.add(u);c.onsuccess=function(){o[a]=c.result,++i===e.length&&n(o)},c.onerror=function(){var e;return t(null!=(e=c.error)?e:new DOMException("Unknown error"))}})}),n)},clear:function(e){return f(l(t().clear()).then(function(){}),e)},count:function(e){return f(l(t().count()),null!=e?e:{})}}}(e,n)}(i,e)}},c=new Promise(function(e,n){i.oncomplete=function(){return e()},i.onerror=function(){var e;return n(null!=(e=i.error)?e:new DOMException("Transaction failed"))}}),s=r(a);return function(e,n){return n?e.then(function(){return null==n.onSuccess?void 0:n.onSuccess()}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}(Promise.resolve(s).then(function(){return c}),o)}}}(n);o(t),m(!0)}}).catch(function(n){e||d(n)}),function(){e=!0}},[n.name,n.version]),{db:r,isReady:p,error:c}},exports.useLLMMetadata=function(e){var n=t.useRef(null);t.useEffect(function(){try{if("undefined"==typeof window)return;var t=function(e){return null==e||"object"!=typeof e?{route:"/"}:{route:p(e.route,2048)||"/",mode:"auto-extract"===e.mode?"auto-extract":"manual",title:void 0!==e.title?p(e.title,200):void 0,description:void 0!==e.description?p(e.description,2e3):void 0,tags:void 0!==e.tags?m(e.tags):void 0,canonicalUrl:void 0!==e.canonicalUrl?g(e.canonicalUrl):void 0,language:void 0!==e.language?p(e.language,20):void 0,ogType:void 0!==e.ogType?p(e.ogType,50):void 0,ogImage:void 0!==e.ogImage?g(e.ogImage):void 0,ogImageAlt:void 0!==e.ogImageAlt?p(e.ogImageAlt,200):void 0,siteName:void 0!==e.siteName?p(e.siteName,100):void 0,author:void 0!==e.author?p(e.author,200):void 0,publishedTime:void 0!==e.publishedTime?p(e.publishedTime,50):void 0,modifiedTime:void 0!==e.modifiedTime?p(e.modifiedTime,50):void 0,robots:void 0!==e.robots?p(e.robots,100):void 0,extra:void 0===e.extra||"object"!=typeof e.extra||Array.isArray(e.extra)?void 0:y(e.extra)}}(e),r=function(e){try{var n=(new Date).toISOString(),t={route:e.route,generatedAt:n};if("auto-extract"===e.mode){var r,o,u=function(){var e={title:"",outline:[],description:""};try{if("undefined"==typeof document)return e;var n=p(document.title,200),t=[],r="";try{for(var o,u=document.querySelectorAll("nav, footer, [role='navigation'], [role='contentinfo'], script, style, noscript"),a=function(e){for(var n,t=i(u);!(n=t()).done;)if(n.value.contains(e))return!0;return!1},c=i(document.querySelectorAll("h1, h2"));!(o=c()).done;){var s=o.value;if(t.length>=50)break;if(h(s)&&!a(s)){var l=p(s.textContent,300);l&&t.push(l)}}for(var f,d=document.querySelectorAll("p"),v=[],m=i(d);!(f=m()).done;){var g=f.value;if(v.length>=3)break;if(h(g)&&!a(g)){var y=p(g.textContent,1e3);y&&v.push(y)}}r=v.join(" ").trim().slice(0,2e3)||""}catch(e){}return{title:n,outline:t,description:r}}catch(n){return e}}();t.title=(null!=(r=e.title)?r:u.title)||void 0,t.description=(null!=(o=e.description)?o:u.description)||void 0,u.outline.length>0&&(t.outline=u.outline)}else void 0!==e.title&&""!==e.title&&(t.title=e.title),void 0!==e.description&&""!==e.description&&(t.description=e.description);return e.tags&&e.tags.length>0&&(t.tags=e.tags),e.canonicalUrl&&(t.canonicalUrl=e.canonicalUrl),e.language&&(t.language=e.language),e.ogType&&(t.ogType=e.ogType),e.ogImage&&(t.ogImage=e.ogImage),e.ogImageAlt&&(t.ogImageAlt=e.ogImageAlt),e.siteName&&(t.siteName=e.siteName),e.author&&(t.author=e.author),e.publishedTime&&(t.publishedTime=e.publishedTime),e.modifiedTime&&(t.modifiedTime=e.modifiedTime),e.robots&&(t.robots=e.robots),e.extra&&Object.keys(e.extra).length>0&&(t.extra=e.extra),t}catch(n){var a;return{route:null!=(a=null==e?void 0:e.route)?a:"/",generatedAt:(new Date).toISOString()}}}(t),o=JSON.stringify(r);if(n.current===o)return;return n.current=o,w(),function(e){try{if("undefined"==typeof document||!document.head)return;var n=document.createElement("script");n.type="application/llm+json",n.setAttribute("data-llm","true"),n.textContent=JSON.stringify(e),document.head.appendChild(n)}catch(e){}}(r),function(){w(),n.current=null}}catch(e){}},[null==e?void 0:e.route,null==e?void 0:e.mode,null==e?void 0:e.title,null==e?void 0:e.description,null==e?void 0:e.tags,null==e?void 0:e.canonicalUrl,null==e?void 0:e.language,null==e?void 0:e.ogType,null==e?void 0:e.ogImage,null==e?void 0:e.ogImageAlt,null==e?void 0:e.siteName,null==e?void 0:e.author,null==e?void 0:e.publishedTime,null==e?void 0:e.modifiedTime,null==e?void 0:e.robots])},exports.useMutationObserver=function(n,t,r){e.useEffect(function(){var e=n.current;if(e){var o=new MutationObserver(t);return o.observe(e,r),function(){return o.disconnect()}}},[n,t,r])},exports.useNetworkState=function(){var n=e.useState(a),t=n[0],r=n[1];return e.useEffect(function(){if("undefined"!=typeof window){var e=function(){return r(a())};window.addEventListener("online",e),window.addEventListener("offline",e);var n=navigator.connection;return null!=n&&n.addEventListener&&n.addEventListener("change",e),function(){window.removeEventListener("online",e),window.removeEventListener("offline",e),null!=n&&n.removeEventListener&&n.removeEventListener("change",e)}}},[]),t},exports.usePreferredTheme=function(){var n=e.useState(function(){if("undefined"==typeof window)return"no-preference";var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");return e.matches?"dark":n.matches?"light":"no-preference"}),t=n[0],r=n[1];return e.useEffect(function(){if("undefined"!=typeof window){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=function(e){r(e.matches?"dark":"light")},t=function(){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");r(e.matches?"dark":n.matches?"light":"no-preference")};e.addEventListener("change",n);var o=window.matchMedia("(prefers-color-scheme: light)");return o.addEventListener("change",t),function(){e.removeEventListener("change",n),o.removeEventListener("change",t)}}},[]),t},exports.useRageClick=function(n,t){var r=t.onRageClick,o=t.threshold,i=void 0===o?5:o,u=t.timeWindow,a=void 0===u?1e3:u,c=t.distanceThreshold,s=void 0===c?30:c,l=e.useRef(r);l.current=r;var f=e.useRef([]);e.useEffect(function(){var e=n.current;if(e){var t=function(e){var n=Date.now(),t={time:n,x:e.clientX,y:e.clientY},r=n-a,o=f.current.filter(function(e){return e.time>=r});if(o.push(t),Infinity!==s){var u=o.filter(function(e){return n=e,r=t,Math.hypot(r.x-n.x,r.y-n.y)<=s;var n,r});if(u.length>=i)return l.current({count:u.length,event:e}),void(f.current=[])}else if(o.length>=i)return l.current({count:o.length,event:e}),void(f.current=[]);f.current=o};return e.addEventListener("click",t),function(){return e.removeEventListener("click",t)}}},[n,i,a,s])},exports.useRefPrint=function(n,t){void 0===t&&(t={});var r=t.documentTitle,o=e.useRef("");return{print:e.useCallback(function(){var e=n.current;if(e&&"undefined"!=typeof window&&window.print){var t=document.getElementById(E);t||((t=document.createElement("style")).id=E,t.textContent=k,document.head.appendChild(t)),e.classList.add(b),r&&(o.current=document.title,document.title=r);var i=function(){e.classList.remove(b),r&&void 0!==o.current&&(document.title=o.current)};if("onafterprint"in window){var u=function(){i(),window.removeEventListener("afterprint",u)};window.addEventListener("afterprint",u)}window.print(),setTimeout(i,1e3)}},[n,r])}},exports.useThreadedWorker=function(n,t){var r=t.concurrency,o="sequential"===t.mode?1:Math.max(1,void 0===r?4:r),i=e.useState(!1),u=i[0],a=i[1],c=e.useState(void 0),s=c[0],l=c[1],f=e.useState(void 0),d=f[0],v=f[1],p=e.useState(0),m=p[0],g=p[1],h=e.useRef([]),y=e.useRef(0),w=e.useRef(0),b=e.useRef(!1),E=e.useRef(n);E.current=n;var k=e.useCallback(function(){g(h.current.length+w.current)},[]),S=e.useCallback(function(){if(!(b.current||w.current>=o)){if(0===h.current.length)return 0===w.current&&a(!1),void k();h.current.sort(function(e,n){return e.priority!==n.priority?e.priority-n.priority:e.sequence-n.sequence});var e=h.current.shift();w.current+=1,a(!0),k(),(0,E.current)(e.data).then(function(n){l(n),v(void 0),e.resolve(n)}).catch(function(n){v(n),e.reject(n)}).finally(function(){w.current-=1,k(),S()}),h.current.length>0&&w.current<o&&S()}},[o,k]),x=e.useCallback(function(e,n){var t;if(b.current)return Promise.reject(new Error("Worker is terminated"));var r=null!=(t=null==n?void 0:n.priority)?t:1,o=++y.current,i=new Promise(function(n,t){h.current.push({data:e,priority:r,sequence:o,resolve:n,reject:t})});return k(),a(!0),queueMicrotask(S),i},[S,k]),T=e.useCallback(function(){var e=h.current;h.current=[],e.forEach(function(e){return e.reject(new Error("Task cleared from queue"))}),k(),0===w.current&&a(!1)},[k]),C=e.useCallback(function(){b.current=!0,T()},[T]);return e.useEffect(function(){return function(){b.current=!0}},[]),{run:x,loading:u,result:s,error:d,queueSize:m,clearQueue:T,terminate:C}},exports.useTransition=function(){var n=e.useState(!1),t=n[0],r=n[1];return[e.useCallback(function(e){r(!0),Promise.resolve().then(function(){e(),r(!1)})},[]),t]},exports.useWasmCompute=function(n){var t=n.wasmUrl,r=n.exportName,o=void 0===r?"compute":r,i=n.workerUrl,u=n.importObject,a=e.useState(void 0),c=a[0],s=a[1],l=e.useState(!0),f=l[0],d=l[1],v=e.useState(null),p=v[0],m=v[1],g=e.useState(!1),h=g[0],y=g[1],w=e.useRef(null),b=e.useRef(null),E=e.useRef(null);return e.useEffect(function(){if("undefined"==typeof window)return m("useWasmCompute is not available during SSR"),void d(!1);if("undefined"==typeof Worker)return m("Worker is not supported in this environment"),void d(!1);if("undefined"==typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)return m("WebAssembly is not supported in this environment"),void d(!1);m(null),y(!1);var e=function(e){if(e)return new Worker(e);var n=new Blob(["\nself.onmessage = async (e) => {\n const d = e.data;\n if (d.type === 'init') {\n try {\n const res = await fetch(d.wasmUrl);\n const buf = await res.arrayBuffer();\n const mod = await WebAssembly.instantiate(buf, d.importObject || {});\n self.wasmInstance = mod.instance;\n self.exportName = d.exportName || 'compute';\n self.postMessage({ type: 'ready' });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n return;\n }\n if (d.type === 'compute') {\n try {\n const fn = self.wasmInstance.exports[self.exportName];\n if (typeof fn !== 'function') {\n self.postMessage({ type: 'error', error: 'Export \"' + self.exportName + '\" is not a function' });\n return;\n }\n const result = fn(d.input);\n self.postMessage({ type: 'result', result: result });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n }\n};\n"],{type:"application/javascript"}),t=URL.createObjectURL(n),r=new Worker(t);return URL.revokeObjectURL(t),r}(i);w.current=e;var n=function(e){var n,t=null!=(n=e.data)?n:{},r=t.type,o=t.result,i=t.error;return"ready"===r?(y(!0),void d(!1)):"error"===r?(m(null!=i?i:"Unknown error"),d(!1),void(E.current&&(E.current(new Error(i)),b.current=null,E.current=null))):void("result"===r&&(s(o),d(!1),b.current&&(b.current(o),b.current=null,E.current=null)))};return e.addEventListener("message",n),e.postMessage({type:"init",wasmUrl:t,exportName:o,importObject:null!=u?u:{}}),function(){e.removeEventListener("message",n),e.terminate(),w.current=null,E.current&&(E.current(new Error("Worker terminated")),b.current=null,E.current=null)}},[t,o,i,u]),{compute:e.useCallback(function(e){return new Promise(function(n,t){w.current&&h?p?t(new Error(p)):(b.current=n,E.current=t,d(!0),w.current.postMessage({type:"compute",input:e})):t(new Error("WASM not ready"))})},[h,p]),result:c,loading:f,error:p,ready:h}},exports.useWebRTCIP=function(n){void 0===n&&(n={});var t=n.stunServers,r=void 0===t?v:t,o=n.timeout,i=void 0===o?3e3:o,u=n.onDetect,a=e.useState([]),c=a[0],s=a[1],l=e.useState(!0),f=l[0],p=l[1],m=e.useState(null),g=m[0],h=m[1],y=e.useRef(null),w=e.useRef(null),b=e.useRef(new Set),E=e.useRef(u);return E.current=u,e.useEffect(function(){if("undefined"==typeof window)return p(!1),void h("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return p(!1),void h("RTCPeerConnection is not available");var e=new Set;b.current=e;var n=function(){w.current&&(clearTimeout(w.current),w.current=null),y.current&&(y.current.close(),y.current=null),p(!1)},t=function(n){e.has(n)||(e.add(n),s(function(e){return[].concat(e,[n])}),null==E.current||E.current(n))};try{var o=new RTCPeerConnection({iceServers:[{urls:r}]});y.current=o,o.onicecandidate=function(e){var n,r=e.candidate;r&&r.candidate&&((n=r.candidate.match(d))?[].concat(n):[]).forEach(t)},o.createDataChannel(""),o.createOffer().then(function(e){return o.setLocalDescription(e)}).catch(function(e){h(e instanceof Error?e.message:"Failed to create offer"),n()}),w.current=setTimeout(function(){return n()},i)}catch(e){h(e instanceof Error?e.message:"WebRTC setup failed"),n()}return function(){n()}},[r.join(","),i]),{ips:c,loading:f,error:g}},exports.useWorkerNotifications=function(n,t){void 0===t&&(t={});var r=t.maxHistory,o=void 0===r?100:r,i=t.throughputWindowMs,u=void 0===i?1e3:i,a=e.useState([]),c=a[0],s=a[1],l=e.useState(0),f=l[0],d=l[1],v=e.useState(0),p=v[0],m=v[1],g=e.useState([]),h=g[0],y=g[1],w=e.useState(0),b=w[0],E=w[1],k=e.useRef([]),S=e.useRef(0),x=e.useRef(0);e.useEffect(function(){if(n){var e=function(e){var n=function(e){if(null==e||"object"!=typeof e)return null;var n=e.type;return"task_start"!==n&&"task_end"!==n&&"task_fail"!==n&&"queue_size"!==n?null:{type:n,taskId:"string"==typeof e.taskId?e.taskId:void 0,duration:"number"==typeof e.duration?e.duration:void 0,error:"string"==typeof e.error?e.error:void 0,size:"number"==typeof e.size?e.size:void 0,timestamp:Date.now()}}(e.data);if(n)if(y(function(e){return[].concat(e,[n]).slice(-o)}),"task_start"===n.type&&n.taskId)s(function(e){return e.includes(n.taskId)?e:[].concat(e,[n.taskId])});else if("task_end"===n.type){n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),d(function(e){return e+1});var t=Date.now()-u;k.current=[].concat(k.current.filter(function(e){return e>=t}),[n.timestamp]),"number"==typeof n.duration&&(S.current+=n.duration,x.current+=1)}else"task_fail"===n.type?(n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),m(function(e){return e+1})):"queue_size"===n.type&&"number"==typeof n.size&&E(n.size)};return n.addEventListener("message",e),function(){return n.removeEventListener("message",e)}}},[n,o]);var T=e.useMemo(function(){var e=x.current;return e>0?S.current/e:0},[h]),C=e.useMemo(function(){var e=Date.now()-u;return k.current.filter(function(n){return n>=e}).length/(u/1e3)},[h,u]),I=e.useMemo(function(){return{runningTasks:c,completedCount:f,failedCount:p,averageDurationMs:T,throughputPerSecond:C,currentQueueSize:b,totalProcessed:f+p,recentEventCount:h.length}},[c,f,p,T,C,b,h.length]);return{runningTasks:c,completedCount:f,failedCount:p,eventHistory:h,averageDurationMs:T,throughputPerSecond:C,currentQueueSize:b,progress:I}},exports.useWrappedChildren=function(t,r,o){return void 0===o&&(o="preserve"),e.useMemo(function(){if(!t)return t;var e=function(e){if(!n.isValidElement(e))return e;var t,i=e.props||{};t="override"===o?u({},i,r):u({},r,i);var a=null==i?void 0:i.style,c=null==r?void 0:r.style;return a&&c&&"object"==typeof a&&"object"==typeof c&&(t.style="override"===o?u({},a,c):u({},c,a)),n.cloneElement(e,t)};return Array.isArray(t)?t.map(e):e(t)},[t,r,o])};
1
+ var e=require("preact/hooks"),n=require("preact"),t=require("preact/compat"),r=new Map;function o(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=Array(n);t<n;t++)r[t]=e[t];return r}function i(e,n){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return o(e,n);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)({}).hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},u.apply(null,arguments)}function a(){if("undefined"==typeof navigator)return{online:!0};var e={online:navigator.onLine},n=navigator.connection;return n&&(void 0!==n.effectiveType&&(e.effectiveType=n.effectiveType),void 0!==n.downlink&&(e.downlink=n.downlink),void 0!==n.rtt&&(e.rtt=n.rtt),void 0!==n.saveData&&(e.saveData=n.saveData),void 0!==n.type&&(e.connectionType=n.type)),e}function c(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}var s=new Map;function l(e){return new Promise(function(n,t){e.onsuccess=function(){return n(e.result)},e.onerror=function(){var n;return t(null!=(n=e.error)?n:new DOMException("Unknown IndexedDB error"))}})}function f(e,n){return n?e.then(function(e){return null==n.onSuccess||n.onSuccess(e),e}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}var d=/\b(?:25[0-5]|2[0-4]\d|1?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|1?\d{1,2})){3}\b/g,v=["stun:stun.l.google.com:19302"];function p(e,n){if(null==e)return"";var t=("string"==typeof e?e:String(e)).trim();return t.length>n?t.slice(0,n):t}function m(e){if(!Array.isArray(e))return[];for(var n=[],t=0;t<e.length&&n.length<50;t++){var r=p(e[t],100);r&&n.push(r)}return n}function g(e){var n=p(e,2048);if(!n)return"";try{var t=new URL(n);if("http:"===t.protocol||"https:"===t.protocol)return n}catch(e){}return""}function y(e){try{if("undefined"==typeof window)return!1;var n=window.getComputedStyle(e);return"none"!==n.display&&"hidden"!==n.visibility&&"0"!==n.opacity}catch(e){return!1}}function h(e){var n={};try{for(var t,r=i(Object.keys(e).slice(0,20));!(t=r()).done;){var o=t.value,u=p(o,50);if(u){var a=e[o];"string"==typeof a?n[u]=a.slice(0,500):"number"==typeof a&&Number.isFinite(a)||"boolean"==typeof a?n[u]=a:Array.isArray(a)&&(n[u]=a.map(function(e){return p(e,200)}).filter(Boolean).slice(0,20))}}}catch(e){}return n}function w(){try{if("undefined"==typeof document||!document.querySelectorAll)return;document.querySelectorAll('script[data-llm="true"]').forEach(function(e){return e.remove()})}catch(e){}}var b="use-ref-print-target",S="use-ref-print-styles",k="\n@media print {\n body * {\n visibility: hidden;\n }\n ."+b+",\n ."+b+" * {\n visibility: visible;\n }\n ."+b+" {\n position: absolute !important;\n left: 0 !important;\n top: 0 !important;\n width: 100% !important;\n }\n}\n";function E(e,n){if("undefined"==typeof window)return null;var t="localStorage"===e?window.localStorage:window.sessionStorage;try{var r=t.getItem(n);if(null==r)return null;var o=JSON.parse(r);return o&&"object"==typeof o?o:null}catch(e){return null}}function x(e,n){if("undefined"==typeof window)return[];var t="localStorage"===e?window.localStorage:window.sessionStorage;try{var r=t.getItem(n);if(null==r)return[];var o=JSON.parse(r);return Array.isArray(o)?o.filter(function(e){return"string"==typeof e}):[]}catch(e){return[]}}function C(e,n){return n.filter(function(n){return n.condition(e)}).map(function(e){return e.role})}function I(e,n){for(var t,r=new Set,o=i(e);!(t=o()).done;){var u=n[t.value];if(Array.isArray(u))for(var a,c=i(u);!(a=c()).done;)r.add(a.value)}return Array.from(r)}exports.useClipboard=function(n){void 0===n&&(n={});var t=n.resetDelay,r=void 0===t?2e3:t,o=e.useState(!1),i=o[0],u=o[1],a=e.useState(null),s=a[0],l=a[1],f=e.useCallback(function(){u(!1),l(null)},[]);return{copy:e.useCallback(function(e){try{if(l(null),"undefined"==typeof navigator||!navigator.clipboard){var n=new Error("Clipboard API is not available");return l(n),Promise.resolve(!1)}return Promise.resolve(c(function(){return Promise.resolve(navigator.clipboard.writeText(e)).then(function(){return u(!0),r>0&&setTimeout(function(){return u(!1)},r),!0})},function(e){var n=e instanceof Error?e:new Error(String(e));return l(n),!1}))}catch(e){return Promise.reject(e)}},[r]),paste:e.useCallback(function(){try{if(l(null),"undefined"==typeof navigator||!navigator.clipboard){var e=new Error("Clipboard API is not available");return l(e),Promise.resolve("")}return Promise.resolve(c(function(){return Promise.resolve(navigator.clipboard.readText())},function(e){var n=e instanceof Error?e:new Error(String(e));return l(n),""}))}catch(e){return Promise.reject(e)}},[]),copied:i,error:s,reset:f}},exports.useEventBus=function(){return{emit:e.useCallback(function(e){var n=arguments,t=r.get(e);t&&t.forEach(function(e){return e.apply(void 0,[].slice.call(n,1))})},[]),on:e.useCallback(function(e,n){var t=r.get(e);return t||(t=new Set,r.set(e,t)),t.add(n),function(){t.delete(n),0===t.size&&r.delete(e)}},[])}},exports.useIndexedDB=function(n){var t=e.useState(null),r=t[0],o=t[1],a=e.useState(null),c=a[0],d=a[1],v=e.useState(!1),p=v[0],m=v[1],g=e.useRef(n);return g.current=n,e.useEffect(function(){var e=!1;d(null),m(!1),o(null);var n=g.current;return function(e){var n=e.name+"_v"+e.version,t=s.get(n);return t||(t=function(e){return new Promise(function(n,t){var r=indexedDB.open(e.name,e.version);r.onerror=function(){var e;return t(null!=(e=r.error)?e:new DOMException("Failed to open database"))},r.onsuccess=function(){return n(r.result)},r.onupgradeneeded=function(n){for(var t=n.target.result,r=e.tables,o=0,u=Object.keys(r);o<u.length;o++){var a=u[o],c=r[a];if(!t.objectStoreNames.contains(a)){var s,l=t.createObjectStore(a,{keyPath:c.keyPath,autoIncrement:null!=(s=c.autoIncrement)&&s});if(c.indexes)for(var f,d=i(c.indexes);!(f=d()).done;){var v=f.value;l.createIndex(v,v,{unique:!1})}}}}})}(e),s.set(n,t),t)}({name:n.name,version:n.version,tables:n.tables}).then(function(n){if(e)n.close();else{var t=function(e){return{get db(){return e},hasTable:function(n){return e.objectStoreNames.contains(n)},table:function(n){return function(e,n){return function(e,n){function t(t){return e.transaction([n],t).objectStore(n)}return{insert:function(e,n){return f(l(t("readwrite").add(e)),n)},update:function(e,n,r){var o=t("readwrite");return f(l(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var t=u({},e,n);return l(o.put(t))}).then(function(){}),r)},delete:function(e,n){return f(l(t("readwrite").delete(e)).then(function(){}),n)},exists:function(e){return l(t("readonly").getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var r=t("readonly").openCursor(),o=[];return f(new Promise(function(n,t){r.onsuccess=function(){var t=r.result;t?(e(t.value)&&o.push(t.value),t.continue()):n(o)},r.onerror=function(){var e;return t(null!=(e=r.error)?e:new DOMException("Unknown error"))}}),n)},upsert:function(e,n){return f(l(t("readwrite").put(e)),n)},bulkInsert:function(e,n){var r=t("readwrite"),o=[];if(0===e.length)return f(Promise.resolve(o),n);var i=0;return f(new Promise(function(n,t){e.forEach(function(u,a){var c=r.add(u);c.onsuccess=function(){o[a]=c.result,++i===e.length&&n(o)},c.onerror=function(){var e;return t(null!=(e=c.error)?e:new DOMException("Unknown error"))}})}),n)},clear:function(e){return f(l(t("readwrite").clear()).then(function(){}),e)},count:function(e){return f(l(t("readonly").count()),null!=e?e:{})}}}(e,n)}(e,n)},transaction:function(n,t,r,o){var i=e.transaction(n,t),a={table:function(e){return function(e,n){return function(e,n){function t(){return e.objectStore(n)}return{insert:function(e,n){return f(l(t().add(e)),n)},update:function(e,n,r){var o=t();return f(l(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var t=u({},e,n);return l(o.put(t))}).then(function(){}),r)},delete:function(e,n){return f(l(t().delete(e)).then(function(){}),n)},exists:function(e){return l(t().getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var r=t().openCursor(),o=[];return f(new Promise(function(n,t){r.onsuccess=function(){var t=r.result;t?(e(t.value)&&o.push(t.value),t.continue()):n(o)},r.onerror=function(){var e;return t(null!=(e=r.error)?e:new DOMException("Unknown error"))}}),n)},upsert:function(e,n){return f(l(t().put(e)),n)},bulkInsert:function(e,n){var r=t(),o=[];if(0===e.length)return f(Promise.resolve(o),n);var i=0;return f(new Promise(function(n,t){e.forEach(function(u,a){var c=r.add(u);c.onsuccess=function(){o[a]=c.result,++i===e.length&&n(o)},c.onerror=function(){var e;return t(null!=(e=c.error)?e:new DOMException("Unknown error"))}})}),n)},clear:function(e){return f(l(t().clear()).then(function(){}),e)},count:function(e){return f(l(t().count()),null!=e?e:{})}}}(e,n)}(i,e)}},c=new Promise(function(e,n){i.oncomplete=function(){return e()},i.onerror=function(){var e;return n(null!=(e=i.error)?e:new DOMException("Transaction failed"))}}),s=r(a);return function(e,n){return n?e.then(function(){return null==n.onSuccess?void 0:n.onSuccess()}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}(Promise.resolve(s).then(function(){return c}),o)}}}(n);o(t),m(!0)}}).catch(function(n){e||d(n)}),function(){e=!0}},[n.name,n.version]),{db:r,isReady:p,error:c}},exports.useLLMMetadata=function(e){var n=t.useRef(null);t.useEffect(function(){try{if("undefined"==typeof window)return;var t=function(e){return null==e||"object"!=typeof e?{route:"/"}:{route:p(e.route,2048)||"/",mode:"auto-extract"===e.mode?"auto-extract":"manual",title:void 0!==e.title?p(e.title,200):void 0,description:void 0!==e.description?p(e.description,2e3):void 0,tags:void 0!==e.tags?m(e.tags):void 0,canonicalUrl:void 0!==e.canonicalUrl?g(e.canonicalUrl):void 0,language:void 0!==e.language?p(e.language,20):void 0,ogType:void 0!==e.ogType?p(e.ogType,50):void 0,ogImage:void 0!==e.ogImage?g(e.ogImage):void 0,ogImageAlt:void 0!==e.ogImageAlt?p(e.ogImageAlt,200):void 0,siteName:void 0!==e.siteName?p(e.siteName,100):void 0,author:void 0!==e.author?p(e.author,200):void 0,publishedTime:void 0!==e.publishedTime?p(e.publishedTime,50):void 0,modifiedTime:void 0!==e.modifiedTime?p(e.modifiedTime,50):void 0,robots:void 0!==e.robots?p(e.robots,100):void 0,extra:void 0===e.extra||"object"!=typeof e.extra||Array.isArray(e.extra)?void 0:h(e.extra)}}(e),r=function(e){try{var n=(new Date).toISOString(),t={route:e.route,generatedAt:n};if("auto-extract"===e.mode){var r,o,u=function(){var e={title:"",outline:[],description:""};try{if("undefined"==typeof document)return e;var n=p(document.title,200),t=[],r="";try{for(var o,u=document.querySelectorAll("nav, footer, [role='navigation'], [role='contentinfo'], script, style, noscript"),a=function(e){for(var n,t=i(u);!(n=t()).done;)if(n.value.contains(e))return!0;return!1},c=i(document.querySelectorAll("h1, h2"));!(o=c()).done;){var s=o.value;if(t.length>=50)break;if(y(s)&&!a(s)){var l=p(s.textContent,300);l&&t.push(l)}}for(var f,d=document.querySelectorAll("p"),v=[],m=i(d);!(f=m()).done;){var g=f.value;if(v.length>=3)break;if(y(g)&&!a(g)){var h=p(g.textContent,1e3);h&&v.push(h)}}r=v.join(" ").trim().slice(0,2e3)||""}catch(e){}return{title:n,outline:t,description:r}}catch(n){return e}}();t.title=(null!=(r=e.title)?r:u.title)||void 0,t.description=(null!=(o=e.description)?o:u.description)||void 0,u.outline.length>0&&(t.outline=u.outline)}else void 0!==e.title&&""!==e.title&&(t.title=e.title),void 0!==e.description&&""!==e.description&&(t.description=e.description);return e.tags&&e.tags.length>0&&(t.tags=e.tags),e.canonicalUrl&&(t.canonicalUrl=e.canonicalUrl),e.language&&(t.language=e.language),e.ogType&&(t.ogType=e.ogType),e.ogImage&&(t.ogImage=e.ogImage),e.ogImageAlt&&(t.ogImageAlt=e.ogImageAlt),e.siteName&&(t.siteName=e.siteName),e.author&&(t.author=e.author),e.publishedTime&&(t.publishedTime=e.publishedTime),e.modifiedTime&&(t.modifiedTime=e.modifiedTime),e.robots&&(t.robots=e.robots),e.extra&&Object.keys(e.extra).length>0&&(t.extra=e.extra),t}catch(n){var a;return{route:null!=(a=null==e?void 0:e.route)?a:"/",generatedAt:(new Date).toISOString()}}}(t),o=JSON.stringify(r);if(n.current===o)return;return n.current=o,w(),function(e){try{if("undefined"==typeof document||!document.head)return;var n=document.createElement("script");n.type="application/llm+json",n.setAttribute("data-llm","true"),n.textContent=JSON.stringify(e),document.head.appendChild(n)}catch(e){}}(r),function(){w(),n.current=null}}catch(e){}},[null==e?void 0:e.route,null==e?void 0:e.mode,null==e?void 0:e.title,null==e?void 0:e.description,null==e?void 0:e.tags,null==e?void 0:e.canonicalUrl,null==e?void 0:e.language,null==e?void 0:e.ogType,null==e?void 0:e.ogImage,null==e?void 0:e.ogImageAlt,null==e?void 0:e.siteName,null==e?void 0:e.author,null==e?void 0:e.publishedTime,null==e?void 0:e.modifiedTime,null==e?void 0:e.robots])},exports.useMutationObserver=function(n,t,r){e.useEffect(function(){var e=n.current;if(e){var o=new MutationObserver(t);return o.observe(e,r),function(){return o.disconnect()}}},[n,t,r])},exports.useNetworkState=function(){var n=e.useState(a),t=n[0],r=n[1];return e.useEffect(function(){if("undefined"!=typeof window){var e=function(){return r(a())};window.addEventListener("online",e),window.addEventListener("offline",e);var n=navigator.connection;return null!=n&&n.addEventListener&&n.addEventListener("change",e),function(){window.removeEventListener("online",e),window.removeEventListener("offline",e),null!=n&&n.removeEventListener&&n.removeEventListener("change",e)}}},[]),t},exports.usePreferredTheme=function(){var n=e.useState(function(){if("undefined"==typeof window)return"no-preference";var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");return e.matches?"dark":n.matches?"light":"no-preference"}),t=n[0],r=n[1];return e.useEffect(function(){if("undefined"!=typeof window){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=function(e){r(e.matches?"dark":"light")},t=function(){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");r(e.matches?"dark":n.matches?"light":"no-preference")};e.addEventListener("change",n);var o=window.matchMedia("(prefers-color-scheme: light)");return o.addEventListener("change",t),function(){e.removeEventListener("change",n),o.removeEventListener("change",t)}}},[]),t},exports.useRBAC=function(n){var t=n.userSource,r=e.useRef(n);r.current=n;var o=e.useState(null),i=o[0],u=o[1],a=e.useState([]),c=a[0],s=a[1],l=e.useState([]),f=l[0],d=l[1],v=e.useState(!1),p=v[0],m=v[1],g=e.useState(null),y=g[0],h=g[1],w=e.useCallback(function(){try{var e=r.current,n=e.userSource,t=e.roleDefinitions,o=e.roleCapabilities,i=e.capabilitiesOverride;h(null);var a=null,c=[],l=[],f=function(e,r){try{var f=function(e,r){try{var f=function(){function e(){function e(){u(a),s(c),d(l)}var n=function(){if(i){var e=function(){if("localStorage"===i.type){var e=x("localStorage",i.key);e.length>0&&(l=e)}else{var n=function(){if("sessionStorage"===i.type){var e=x("sessionStorage",i.key);e.length>0&&(l=e)}else{var n=function(){if("api"===i.type)return Promise.resolve(i.fetch()).then(function(e){l=e})}();if(n&&n.then)return n.then(function(){})}}();if(n&&n.then)return n.then(function(){})}}();if(e&&e.then)return e.then(function(){})}}();return n&&n.then?n.then(e):e()}var r=function(){if("localStorage"===n.type)a=E("localStorage",n.key),c=C(a,t),l=I(c,o);else{var e=function(){if("sessionStorage"===n.type)a=E("sessionStorage",n.key),c=C(a,t),l=I(c,o);else{var e=function(){if("api"===n.type)return Promise.resolve(n.fetch()).then(function(e){c=C(a=e,t),l=I(c,o)});var e=function(){if("memory"===n.type)a=n.getUser(),c=C(a,t),l=I(c,o);else{var e=function(){if("custom"===n.type)return Promise.resolve(Promise.resolve(n.getAuth())).then(function(e){var n,r,i;a=null!=(n=e.user)?n:null,c=null!=(r=e.roles)?r:C(a,t),l=null!=(i=e.capabilities)?i:I(c,o)})}();if(e&&e.then)return e.then(function(){})}}();return e&&e.then?e.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}}();if(e&&e.then)return e.then(function(){})}}();return r&&r.then?r.then(e):e()}()}catch(e){return r(e)}return f&&f.then?f.then(void 0,r):f}(0,function(e){h(e instanceof Error?e:new Error(String(e))),u(null),s([]),d([])})}catch(e){return r(!0,e)}return f&&f.then?f.then(r.bind(null,!1),r.bind(null,!0)):r(!1,f)}(0,function(e,n){if(m(!0),e)throw n;return n});return Promise.resolve(f&&f.then?f.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[]);e.useEffect(function(){w()},[w]),e.useEffect(function(){if("undefined"!=typeof window){var e="localStorage"===t.type||"sessionStorage"===t.type?t.key:null;if(e){var n=function(n){n.key===e&&w()};return window.addEventListener("storage",n),function(){return window.removeEventListener("storage",n)}}}},[t.type,"localStorage"===t.type||"sessionStorage"===t.type?t.key:"",w]);var b=e.useCallback(function(e){return c.includes(e)},[c]),S=e.useCallback(function(e){return function(e,n){return!!e.includes("*")||e.includes(n)}(f,e)},[f]),k=S,T=e.useCallback(function(){return w()},[w]),A=e.useCallback(function(e,n,r){if("undefined"!=typeof window){var o="localStorage"===n?window.localStorage:window.sessionStorage;null==e?o.removeItem(r):o.setItem(r,JSON.stringify(e)),("localStorage"===t.type&&"localStorage"===n&&t.key===r||"sessionStorage"===t.type&&"sessionStorage"===n&&t.key===r)&&w()}},[t,w]),P=e.useCallback(function(e,n,t){"undefined"!=typeof window&&("localStorage"===n?window.localStorage:window.sessionStorage).setItem(t,JSON.stringify(e))},[]),R=e.useCallback(function(e,n,t){"undefined"!=typeof window&&("localStorage"===n?window.localStorage:window.sessionStorage).setItem(t,JSON.stringify(e))},[]);return{user:i,roles:c,capabilities:f,isReady:p,error:y,hasRole:b,hasCapability:S,can:k,refetch:T,setUserInStorage:A,setRolesInStorage:P,setCapabilitiesInStorage:R}},exports.useRageClick=function(n,t){var r=t.onRageClick,o=t.threshold,i=void 0===o?5:o,u=t.timeWindow,a=void 0===u?1e3:u,c=t.distanceThreshold,s=void 0===c?30:c,l=e.useRef(r);l.current=r;var f=e.useRef([]);e.useEffect(function(){var e=n.current;if(e){var t=function(e){var n=Date.now(),t={time:n,x:e.clientX,y:e.clientY},r=n-a,o=f.current.filter(function(e){return e.time>=r});if(o.push(t),Infinity!==s){var u=o.filter(function(e){return n=e,r=t,Math.hypot(r.x-n.x,r.y-n.y)<=s;var n,r});if(u.length>=i)return l.current({count:u.length,event:e}),void(f.current=[])}else if(o.length>=i)return l.current({count:o.length,event:e}),void(f.current=[]);f.current=o};return e.addEventListener("click",t),function(){return e.removeEventListener("click",t)}}},[n,i,a,s])},exports.useRefPrint=function(n,t){void 0===t&&(t={});var r=t.documentTitle,o=e.useRef("");return{print:e.useCallback(function(){var e=n.current;if(e&&"undefined"!=typeof window&&window.print){var t=document.getElementById(S);t||((t=document.createElement("style")).id=S,t.textContent=k,document.head.appendChild(t)),e.classList.add(b),r&&(o.current=document.title,document.title=r);var i=function(){e.classList.remove(b),r&&void 0!==o.current&&(document.title=o.current)};if("onafterprint"in window){var u=function(){i(),window.removeEventListener("afterprint",u)};window.addEventListener("afterprint",u)}window.print(),setTimeout(i,1e3)}},[n,r])}},exports.useThreadedWorker=function(n,t){var r=t.concurrency,o="sequential"===t.mode?1:Math.max(1,void 0===r?4:r),i=e.useState(!1),u=i[0],a=i[1],c=e.useState(void 0),s=c[0],l=c[1],f=e.useState(void 0),d=f[0],v=f[1],p=e.useState(0),m=p[0],g=p[1],y=e.useRef([]),h=e.useRef(0),w=e.useRef(0),b=e.useRef(!1),S=e.useRef(n);S.current=n;var k=e.useCallback(function(){g(y.current.length+w.current)},[]),E=e.useCallback(function(){if(!(b.current||w.current>=o)){if(0===y.current.length)return 0===w.current&&a(!1),void k();y.current.sort(function(e,n){return e.priority!==n.priority?e.priority-n.priority:e.sequence-n.sequence});var e=y.current.shift();w.current+=1,a(!0),k(),(0,S.current)(e.data).then(function(n){l(n),v(void 0),e.resolve(n)}).catch(function(n){v(n),e.reject(n)}).finally(function(){w.current-=1,k(),E()}),y.current.length>0&&w.current<o&&E()}},[o,k]),x=e.useCallback(function(e,n){var t;if(b.current)return Promise.reject(new Error("Worker is terminated"));var r=null!=(t=null==n?void 0:n.priority)?t:1,o=++h.current,i=new Promise(function(n,t){y.current.push({data:e,priority:r,sequence:o,resolve:n,reject:t})});return k(),a(!0),queueMicrotask(E),i},[E,k]),C=e.useCallback(function(){var e=y.current;y.current=[],e.forEach(function(e){return e.reject(new Error("Task cleared from queue"))}),k(),0===w.current&&a(!1)},[k]),I=e.useCallback(function(){b.current=!0,C()},[C]);return e.useEffect(function(){return function(){b.current=!0}},[]),{run:x,loading:u,result:s,error:d,queueSize:m,clearQueue:C,terminate:I}},exports.useTransition=function(){var n=e.useState(!1),t=n[0],r=n[1];return[e.useCallback(function(e){r(!0),Promise.resolve().then(function(){e(),r(!1)})},[]),t]},exports.useWasmCompute=function(n){var t=n.wasmUrl,r=n.exportName,o=void 0===r?"compute":r,i=n.workerUrl,u=n.importObject,a=e.useState(void 0),c=a[0],s=a[1],l=e.useState(!0),f=l[0],d=l[1],v=e.useState(null),p=v[0],m=v[1],g=e.useState(!1),y=g[0],h=g[1],w=e.useRef(null),b=e.useRef(null),S=e.useRef(null);return e.useEffect(function(){if("undefined"==typeof window)return m("useWasmCompute is not available during SSR"),void d(!1);if("undefined"==typeof Worker)return m("Worker is not supported in this environment"),void d(!1);if("undefined"==typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)return m("WebAssembly is not supported in this environment"),void d(!1);m(null),h(!1);var e=function(e){if(e)return new Worker(e);var n=new Blob(["\nself.onmessage = async (e) => {\n const d = e.data;\n if (d.type === 'init') {\n try {\n const res = await fetch(d.wasmUrl);\n const buf = await res.arrayBuffer();\n const mod = await WebAssembly.instantiate(buf, d.importObject || {});\n self.wasmInstance = mod.instance;\n self.exportName = d.exportName || 'compute';\n self.postMessage({ type: 'ready' });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n return;\n }\n if (d.type === 'compute') {\n try {\n const fn = self.wasmInstance.exports[self.exportName];\n if (typeof fn !== 'function') {\n self.postMessage({ type: 'error', error: 'Export \"' + self.exportName + '\" is not a function' });\n return;\n }\n const result = fn(d.input);\n self.postMessage({ type: 'result', result: result });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n }\n};\n"],{type:"application/javascript"}),t=URL.createObjectURL(n),r=new Worker(t);return URL.revokeObjectURL(t),r}(i);w.current=e;var n=function(e){var n,t=null!=(n=e.data)?n:{},r=t.type,o=t.result,i=t.error;return"ready"===r?(h(!0),void d(!1)):"error"===r?(m(null!=i?i:"Unknown error"),d(!1),void(S.current&&(S.current(new Error(i)),b.current=null,S.current=null))):void("result"===r&&(s(o),d(!1),b.current&&(b.current(o),b.current=null,S.current=null)))};return e.addEventListener("message",n),e.postMessage({type:"init",wasmUrl:t,exportName:o,importObject:null!=u?u:{}}),function(){e.removeEventListener("message",n),e.terminate(),w.current=null,S.current&&(S.current(new Error("Worker terminated")),b.current=null,S.current=null)}},[t,o,i,u]),{compute:e.useCallback(function(e){return new Promise(function(n,t){w.current&&y?p?t(new Error(p)):(b.current=n,S.current=t,d(!0),w.current.postMessage({type:"compute",input:e})):t(new Error("WASM not ready"))})},[y,p]),result:c,loading:f,error:p,ready:y}},exports.useWebRTCIP=function(n){void 0===n&&(n={});var t=n.stunServers,r=void 0===t?v:t,o=n.timeout,i=void 0===o?3e3:o,u=n.onDetect,a=e.useState([]),c=a[0],s=a[1],l=e.useState(!0),f=l[0],p=l[1],m=e.useState(null),g=m[0],y=m[1],h=e.useRef(null),w=e.useRef(null),b=e.useRef(new Set),S=e.useRef(u);return S.current=u,e.useEffect(function(){if("undefined"==typeof window)return p(!1),void y("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return p(!1),void y("RTCPeerConnection is not available");var e=new Set;b.current=e;var n=function(){w.current&&(clearTimeout(w.current),w.current=null),h.current&&(h.current.close(),h.current=null),p(!1)},t=function(n){e.has(n)||(e.add(n),s(function(e){return[].concat(e,[n])}),null==S.current||S.current(n))};try{var o=new RTCPeerConnection({iceServers:[{urls:r}]});h.current=o,o.onicecandidate=function(e){var n,r=e.candidate;r&&r.candidate&&((n=r.candidate.match(d))?[].concat(n):[]).forEach(t)},o.createDataChannel(""),o.createOffer().then(function(e){return o.setLocalDescription(e)}).catch(function(e){y(e instanceof Error?e.message:"Failed to create offer"),n()}),w.current=setTimeout(function(){return n()},i)}catch(e){y(e instanceof Error?e.message:"WebRTC setup failed"),n()}return function(){n()}},[r.join(","),i]),{ips:c,loading:f,error:g}},exports.useWorkerNotifications=function(n,t){void 0===t&&(t={});var r=t.maxHistory,o=void 0===r?100:r,i=t.throughputWindowMs,u=void 0===i?1e3:i,a=e.useState([]),c=a[0],s=a[1],l=e.useState(0),f=l[0],d=l[1],v=e.useState(0),p=v[0],m=v[1],g=e.useState([]),y=g[0],h=g[1],w=e.useState(0),b=w[0],S=w[1],k=e.useRef([]),E=e.useRef(0),x=e.useRef(0);e.useEffect(function(){if(n){var e=function(e){var n=function(e){if(null==e||"object"!=typeof e)return null;var n=e.type;return"task_start"!==n&&"task_end"!==n&&"task_fail"!==n&&"queue_size"!==n?null:{type:n,taskId:"string"==typeof e.taskId?e.taskId:void 0,duration:"number"==typeof e.duration?e.duration:void 0,error:"string"==typeof e.error?e.error:void 0,size:"number"==typeof e.size?e.size:void 0,timestamp:Date.now()}}(e.data);if(n)if(h(function(e){return[].concat(e,[n]).slice(-o)}),"task_start"===n.type&&n.taskId)s(function(e){return e.includes(n.taskId)?e:[].concat(e,[n.taskId])});else if("task_end"===n.type){n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),d(function(e){return e+1});var t=Date.now()-u;k.current=[].concat(k.current.filter(function(e){return e>=t}),[n.timestamp]),"number"==typeof n.duration&&(E.current+=n.duration,x.current+=1)}else"task_fail"===n.type?(n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),m(function(e){return e+1})):"queue_size"===n.type&&"number"==typeof n.size&&S(n.size)};return n.addEventListener("message",e),function(){return n.removeEventListener("message",e)}}},[n,o]);var C=e.useMemo(function(){var e=x.current;return e>0?E.current/e:0},[y]),I=e.useMemo(function(){var e=Date.now()-u;return k.current.filter(function(n){return n>=e}).length/(u/1e3)},[y,u]),T=e.useMemo(function(){return{runningTasks:c,completedCount:f,failedCount:p,averageDurationMs:C,throughputPerSecond:I,currentQueueSize:b,totalProcessed:f+p,recentEventCount:y.length}},[c,f,p,C,I,b,y.length]);return{runningTasks:c,completedCount:f,failedCount:p,eventHistory:y,averageDurationMs:C,throughputPerSecond:I,currentQueueSize:b,progress:T}},exports.useWrappedChildren=function(t,r,o){return void 0===o&&(o="preserve"),e.useMemo(function(){if(!t)return t;var e=function(e){if(!n.isValidElement(e))return e;var t,i=e.props||{};t="override"===o?u({},i,r):u({},r,i);var a=null==i?void 0:i.style,c=null==r?void 0:r.style;return a&&c&&"object"==typeof a&&"object"==typeof c&&(t.style="override"===o?u({},a,c):u({},c,a)),n.cloneElement(e,t)};return Array.isArray(t)?t.map(e):e(t)},[t,r,o])};
2
2
  //# sourceMappingURL=index.js.map