preact-missing-hooks 4.6.0 → 4.7.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 +33 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +1 -1
- package/dist/index.modern.mjs.map +1 -1
- package/dist/index.module.js +1 -1
- package/dist/index.module.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/react.js +78 -0
- package/dist/usePoll.d.ts +47 -0
- package/docs/README.md +1 -0
- package/docs/main.js +31 -0
- package/llm.package.json +57 -72
- package/llm.package.txt +21 -19
- package/package.json +7 -1
- package/src/index.ts +1 -0
- package/src/usePoll.ts +110 -0
- package/tests/usePoll.test.tsx +110 -0
package/Readme.md
CHANGED
|
@@ -28,6 +28,7 @@ A lightweight, extendable collection of React-like hooks for Preact, including u
|
|
|
28
28
|
- **`usePreferredTheme`** — Detects the user's preferred color scheme (light/dark) from system preferences.
|
|
29
29
|
- **`useNetworkState`** — Tracks online/offline status and connection details (type, downlink, RTT, save-data).
|
|
30
30
|
- **`usePrefetch`** — Preload URLs (documents or data) so they are cached before navigation or use. Ideal for link hover or route preloading. Returns `prefetch(url, options?)` and `isPrefetched(url)`.
|
|
31
|
+
- **`usePoll`** — Polls an async function at a fixed interval until it returns `{ done: true, data? }`. Stops on error. Returns `data`, `done`, `error`, `pollCount`, `start`, `stop`. Good for readiness checks or waiting on a backend job.
|
|
31
32
|
- **`useClipboard`** — Copy and paste text with the Clipboard API, with copied/error state.
|
|
32
33
|
- **`useRageClick`** — Detects rage clicks (repeated rapid clicks in the same spot). Use with Sentry or similar to detect and fix rage-click issues and lower rage-click-related support.
|
|
33
34
|
- **`useThreadedWorker`** — Run async work in a queue with **sequential** (single worker, priority-ordered) or **parallel** (worker pool) mode. Optional priority (1 = highest); FIFO within same priority.
|
|
@@ -75,12 +76,13 @@ import { useThreadedWorker, useClipboard } from "preact-missing-hooks";
|
|
|
75
76
|
import { useThreadedWorker } from "preact-missing-hooks/useThreadedWorker";
|
|
76
77
|
import { useClipboard } from "preact-missing-hooks/useClipboard";
|
|
77
78
|
import { usePrefetch } from "preact-missing-hooks/usePrefetch";
|
|
79
|
+
import { usePoll } from "preact-missing-hooks/usePoll";
|
|
78
80
|
import { useWebRTCIP } from "preact-missing-hooks/useWebRTCIP";
|
|
79
81
|
import { useWasmCompute } from "preact-missing-hooks/useWasmCompute";
|
|
80
82
|
import { useWorkerNotifications } from "preact-missing-hooks/useWorkerNotifications";
|
|
81
83
|
```
|
|
82
84
|
|
|
83
|
-
All hooks are available: `useTransition`, `useMutationObserver`, `useEventBus`, `useWrappedChildren`, `usePreferredTheme`, `useNetworkState`, `useClipboard`, `usePrefetch`, `useRageClick`, `useThreadedWorker`, `useIndexedDB`, `useWebRTCIP`, `useWasmCompute`, `useWorkerNotifications`, `useLLMMetadata`, `useRefPrint`, `useRBAC`.
|
|
85
|
+
All hooks are available: `useTransition`, `useMutationObserver`, `useEventBus`, `useWrappedChildren`, `usePreferredTheme`, `useNetworkState`, `useClipboard`, `usePrefetch`, `usePoll`, `useRageClick`, `useThreadedWorker`, `useIndexedDB`, `useWebRTCIP`, `useWasmCompute`, `useWorkerNotifications`, `useLLMMetadata`, `useRefPrint`, `useRBAC`.
|
|
84
86
|
|
|
85
87
|
---
|
|
86
88
|
|
|
@@ -144,6 +146,7 @@ Or open `docs/index.html` after building (see [docs/README.md](docs/README.md) f
|
|
|
144
146
|
| [usePreferredTheme](#usepreferredtheme) | `const theme = usePreferredTheme(); // 'light' \| 'dark' \| 'no-preference'` |
|
|
145
147
|
| [useNetworkState](#usenetworkstate) | `const { online, effectiveType } = useNetworkState();` |
|
|
146
148
|
| [usePrefetch](#useprefetch) | `const { prefetch, isPrefetched } = usePrefetch();` |
|
|
149
|
+
| [usePoll](#usepoll) | `const { data, done, pollCount, stop } = usePoll(pollFn, { intervalMs });` |
|
|
147
150
|
| [useClipboard](#useclipboard) | `const { copy, paste, copied } = useClipboard();` |
|
|
148
151
|
| [useRageClick](#userageclick) | `useRageClick(ref, { onRageClick, threshold: 5 });` |
|
|
149
152
|
| [useThreadedWorker](#usethreadedworker) | `const { run, loading, result } = useThreadedWorker(fn, { mode: 'sequential' });` |
|
|
@@ -383,6 +386,35 @@ function DataLoader() {
|
|
|
383
386
|
|
|
384
387
|
---
|
|
385
388
|
|
|
389
|
+
### `usePoll`
|
|
390
|
+
|
|
391
|
+
Polls an async function at a fixed interval until it returns `{ done: true, data? }`. Stops on error. Options: `intervalMs`, `immediate`, `enabled`. Returns `data`, `done`, `error`, `pollCount`, `start`, `stop`.
|
|
392
|
+
|
|
393
|
+
```tsx
|
|
394
|
+
import { usePoll } from "preact-missing-hooks";
|
|
395
|
+
|
|
396
|
+
function StatusPoller() {
|
|
397
|
+
const { data, done, error, pollCount, stop } = usePoll(
|
|
398
|
+
async () => {
|
|
399
|
+
const res = await fetch("/api/job/status");
|
|
400
|
+
const json = await res.json();
|
|
401
|
+
return json.ready ? { done: true, data: json } : { done: false };
|
|
402
|
+
},
|
|
403
|
+
{ intervalMs: 1000, immediate: true }
|
|
404
|
+
);
|
|
405
|
+
|
|
406
|
+
if (error) return <div>Error: {error.message}</div>;
|
|
407
|
+
if (done) return <div>Result: {JSON.stringify(data)}</div>;
|
|
408
|
+
return (
|
|
409
|
+
<div>
|
|
410
|
+
Polling… ({pollCount} calls) <button onClick={stop}>Stop</button>
|
|
411
|
+
</div>
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
---
|
|
417
|
+
|
|
386
418
|
### `useRageClick`
|
|
387
419
|
|
|
388
420
|
Detects rage clicks (multiple rapid clicks in the same area), e.g. when the UI is unresponsive. Report them to [Sentry](https://docs.sentry.io/product/issues/issue-details/replay-issues/rage-clicks/) or your error tracker to surface rage-click issues and lower rage-click-related support.
|
package/dist/index.d.ts
CHANGED
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 h(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 g(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",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],h=e.useRef(n);return h.current=n,e.useEffect(function(){var e=!1;d(null),m(!1),o(null);var n=h.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?h(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?h(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(g(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 h=f.value;if(v.length>=3)break;if(g(h)&&!a(h)){var y=p(h.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.usePrefetch=function(){var n=e.useRef(new Set),t=e.useState(0)[1];return{prefetch:e.useCallback(function(e,r){var o,i=null==e?void 0:e.trim();i&&(n.current.has(i)||("document"===(null!=(o=null==r?void 0:r.as)?o:"document")?function(e){if("undefined"!=typeof document){for(var n=document.querySelectorAll('link[rel="prefetch"]'),t=0;t<n.length;t++)if(n[t].href===e)return;var r=document.createElement("link");r.rel="prefetch",r.href=e,document.head.appendChild(r)}}(i):function(e){"undefined"!=typeof fetch&&fetch(e,{method:"GET",mode:"cors"}).catch(function(){})}(i),n.current.add(i),t(function(e){return e+1})))},[]),isPrefetched:e.useCallback(function(e){var t;return n.current.has(null!=(t=null==e?void 0:e.trim())?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],h=e.useState(null),g=h[0],y=h[1],w=e.useCallback(function(){try{var e=r.current,n=e.userSource,t=e.roleDefinitions,o=e.roleCapabilities,i=e.capabilitiesOverride;y(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){y(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]),P=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]),A=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:g,hasRole:b,hasCapability:S,can:k,refetch:T,setUserInStorage:P,setRolesInStorage:A,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],h=p[1],g=e.useRef([]),y=e.useRef(0),w=e.useRef(0),b=e.useRef(!1),S=e.useRef(n);S.current=n;var k=e.useCallback(function(){h(g.current.length+w.current)},[]),E=e.useCallback(function(){if(!(b.current||w.current>=o)){if(0===g.current.length)return 0===w.current&&a(!1),void k();g.current.sort(function(e,n){return e.priority!==n.priority?e.priority-n.priority:e.sequence-n.sequence});var e=g.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()}),g.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=++y.current,i=new Promise(function(n,t){g.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=g.current;g.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],h=e.useState(!1),g=h[0],y=h[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),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(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&&g?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"))})},[g,p]),result:c,loading:f,error:p,ready:g}},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),h=m[0],g=m[1],y=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 g("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return p(!1),void g("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==S.current||S.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){g(e instanceof Error?e.message:"Failed to create offer"),n()}),w.current=setTimeout(function(){return n()},i)}catch(e){g(e instanceof Error?e.message:"WebRTC setup failed"),n()}return function(){n()}},[r.join(","),i]),{ips:c,loading:f,error:h}},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],h=e.useState([]),g=h[0],y=h[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(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&&(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},[g]),I=e.useMemo(function(){var e=Date.now()-u;return k.current.filter(function(n){return n>=e}).length/(u/1e3)},[g,u]),T=e.useMemo(function(){return{runningTasks:c,completedCount:f,failedCount:p,averageDurationMs:C,throughputPerSecond:I,currentQueueSize:b,totalProcessed:f+p,recentEventCount:g.length}},[c,f,p,C,I,b,g.length]);return{runningTasks:c,completedCount:f,failedCount:p,eventHistory:g,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])};
|
|
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 h(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 g(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",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],h=e.useRef(n);return h.current=n,e.useEffect(function(){var e=!1;d(null),m(!1),o(null);var n=h.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?h(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?h(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(g(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 h=f.value;if(v.length>=3)break;if(g(h)&&!a(h)){var y=p(h.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.usePoll=function(n,t){void 0===t&&(t={});var r=t.intervalMs,o=void 0===r?1e3:r,i=t.immediate,u=void 0===i||i,a=t.enabled,c=void 0===a||a,s=e.useState(null),l=s[0],f=s[1],d=e.useState(!1),v=d[0],p=d[1],m=e.useState(null),h=m[0],g=m[1],y=e.useState(0),w=y[0],b=y[1],S=e.useState(!1),k=S[0],E=S[1],x=e.useRef(null),C=e.useRef(n);C.current=n;var I=e.useCallback(function(){null!=x.current&&(clearInterval(x.current),x.current=null),E(!1)},[]),P=e.useCallback(function(){try{var e=function(e,n){try{var t=(g(null),Promise.resolve(C.current()).then(function(e){b(function(e){return e+1}),e.done&&(I(),p(!0),void 0!==e.data&&f(e.data))}))}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(0,function(e){var n=e instanceof Error?e:new Error(String(e));g(n),I()});return Promise.resolve(e&&e.then?e.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[I]),T=e.useCallback(function(){c&&!k&&(E(!0),u&&P(),x.current=setInterval(P,o))},[c,u,o,k,P]);return e.useEffect(function(){return c&&T(),function(){I()}},[c]),{data:l,done:v,error:h,pollCount:w,start:T,stop:I}},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.usePrefetch=function(){var n=e.useRef(new Set),t=e.useState(0)[1];return{prefetch:e.useCallback(function(e,r){var o,i=null==e?void 0:e.trim();i&&(n.current.has(i)||("document"===(null!=(o=null==r?void 0:r.as)?o:"document")?function(e){if("undefined"!=typeof document){for(var n=document.querySelectorAll('link[rel="prefetch"]'),t=0;t<n.length;t++)if(n[t].href===e)return;var r=document.createElement("link");r.rel="prefetch",r.href=e,document.head.appendChild(r)}}(i):function(e){"undefined"!=typeof fetch&&fetch(e,{method:"GET",mode:"cors"}).catch(function(){})}(i),n.current.add(i),t(function(e){return e+1})))},[]),isPrefetched:e.useCallback(function(e){var t;return n.current.has(null!=(t=null==e?void 0:e.trim())?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],h=e.useState(null),g=h[0],y=h[1],w=e.useCallback(function(){try{var e=r.current,n=e.userSource,t=e.roleDefinitions,o=e.roleCapabilities,i=e.capabilitiesOverride;y(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){y(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,P=e.useCallback(function(){return w()},[w]),T=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]),R=e.useCallback(function(e,n,t){"undefined"!=typeof window&&("localStorage"===n?window.localStorage:window.sessionStorage).setItem(t,JSON.stringify(e))},[]),A=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:g,hasRole:b,hasCapability:S,can:k,refetch:P,setUserInStorage:T,setRolesInStorage:R,setCapabilitiesInStorage:A}},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],h=p[1],g=e.useRef([]),y=e.useRef(0),w=e.useRef(0),b=e.useRef(!1),S=e.useRef(n);S.current=n;var k=e.useCallback(function(){h(g.current.length+w.current)},[]),E=e.useCallback(function(){if(!(b.current||w.current>=o)){if(0===g.current.length)return 0===w.current&&a(!1),void k();g.current.sort(function(e,n){return e.priority!==n.priority?e.priority-n.priority:e.sequence-n.sequence});var e=g.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()}),g.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=++y.current,i=new Promise(function(n,t){g.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=g.current;g.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],h=e.useState(!1),g=h[0],y=h[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),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(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&&g?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"))})},[g,p]),result:c,loading:f,error:p,ready:g}},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),h=m[0],g=m[1],y=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 g("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return p(!1),void g("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==S.current||S.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){g(e instanceof Error?e.message:"Failed to create offer"),n()}),w.current=setTimeout(function(){return n()},i)}catch(e){g(e instanceof Error?e.message:"WebRTC setup failed"),n()}return function(){n()}},[r.join(","),i]),{ips:c,loading:f,error:h}},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],h=e.useState([]),g=h[0],y=h[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(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&&(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},[g]),I=e.useMemo(function(){var e=Date.now()-u;return k.current.filter(function(n){return n>=e}).length/(u/1e3)},[g,u]),P=e.useMemo(function(){return{runningTasks:c,completedCount:f,failedCount:p,averageDurationMs:C,throughputPerSecond:I,currentQueueSize:b,totalProcessed:f+p,recentEventCount:g.length}},[c,f,p,C,I,b,g.length]);return{runningTasks:c,completedCount:f,failedCount:p,eventHistory:g,averageDurationMs:C,throughputPerSecond:I,currentQueueSize:b,progress:P}},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
|