preact-missing-hooks 4.5.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 CHANGED
@@ -27,6 +27,8 @@ A lightweight, extendable collection of React-like hooks for Preact, including u
27
27
  - **`useWrappedChildren`** — Injects props into child components with flexible merging strategies.
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
+ - **`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.
30
32
  - **`useClipboard`** — Copy and paste text with the Clipboard API, with copied/error state.
31
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.
32
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.
@@ -35,6 +37,8 @@ A lightweight, extendable collection of React-like hooks for Preact, including u
35
37
  - **`useWasmCompute`** — Runs WebAssembly computation off the main thread via a Web Worker. Validates environment (browser, Worker, WebAssembly) and returns `compute(input)`, `result`, `loading`, `error`, `ready`.
36
38
  - **`useWorkerNotifications`** — Listens to a Worker's messages and maintains state: running tasks, completed/failed counts, event history, average task duration, throughput per second, and queue size. Worker posts `task_start` / `task_end` / `task_fail` / `queue_size`; returns `progress` (default view of all active worker data) plus individual stats.
37
39
  - **`useLLMMetadata`** — Injects an AI-readable metadata block into the document head on route change. Works in React 18+ and Preact 10+. Supports **manual** (title, description, tags) and **auto-extract** (from `document.title`, visible `h1`/`h2`, first 3 `p`). Cacheable, SSR-safe, no router dependency.
40
+ - **`useRefPrint`** — Binds a ref to a printable section and provides `print()` to open the native print dialog. Uses `@media print` CSS so only that section is printed (or saved as PDF). Options: `documentTitle`, `downloadAsPdf`.
41
+ - **`useRBAC`** — Frontend-only role-based access control. Define roles with conditions, assign capabilities per role. Pluggable user source: `localStorage`, `sessionStorage`, API, memory, or custom. Returns `user`, `roles`, `capabilities`, `hasRole(role)`, `can(capability)`, and storage helpers.
38
42
  - Fully TypeScript compatible
39
43
  - Bundled with Microbundle
40
44
  - Zero dependencies (peer: `preact` or `react` — use `/react` for React)
@@ -71,12 +75,14 @@ import { useThreadedWorker, useClipboard } from "preact-missing-hooks";
71
75
  ```ts
72
76
  import { useThreadedWorker } from "preact-missing-hooks/useThreadedWorker";
73
77
  import { useClipboard } from "preact-missing-hooks/useClipboard";
78
+ import { usePrefetch } from "preact-missing-hooks/usePrefetch";
79
+ import { usePoll } from "preact-missing-hooks/usePoll";
74
80
  import { useWebRTCIP } from "preact-missing-hooks/useWebRTCIP";
75
81
  import { useWasmCompute } from "preact-missing-hooks/useWasmCompute";
76
82
  import { useWorkerNotifications } from "preact-missing-hooks/useWorkerNotifications";
77
83
  ```
78
84
 
79
- All hooks are available: `useTransition`, `useMutationObserver`, `useEventBus`, `useWrappedChildren`, `usePreferredTheme`, `useNetworkState`, `useClipboard`, `useRageClick`, `useThreadedWorker`, `useIndexedDB`, `useWebRTCIP`, `useWasmCompute`, `useWorkerNotifications`, `useLLMMetadata`.
85
+ All hooks are available: `useTransition`, `useMutationObserver`, `useEventBus`, `useWrappedChildren`, `usePreferredTheme`, `useNetworkState`, `useClipboard`, `usePrefetch`, `usePoll`, `useRageClick`, `useThreadedWorker`, `useIndexedDB`, `useWebRTCIP`, `useWasmCompute`, `useWorkerNotifications`, `useLLMMetadata`, `useRefPrint`, `useRBAC`.
80
86
 
81
87
  ---
82
88
 
@@ -131,22 +137,26 @@ Or open `docs/index.html` after building (see [docs/README.md](docs/README.md) f
131
137
 
132
138
  **Usage at a glance:**
133
139
 
134
- | Hook | One-liner |
135
- | ------------------------------------------------- | --------------------------------------------------------------------------------- |
136
- | [useTransition](#usetransition) | `const [startTransition, isPending] = useTransition();` |
137
- | [useMutationObserver](#usemutationobserver) | `useMutationObserver(ref, callback, { childList: true });` |
138
- | [useEventBus](#useeventbus) | `const { emit, on } = useEventBus();` |
139
- | [useWrappedChildren](#usewrappedchildren) | `const wrapped = useWrappedChildren(children, { className: 'x' });` |
140
- | [usePreferredTheme](#usepreferredtheme) | `const theme = usePreferredTheme(); // 'light' \| 'dark' \| 'no-preference'` |
141
- | [useNetworkState](#usenetworkstate) | `const { online, effectiveType } = useNetworkState();` |
142
- | [useClipboard](#useclipboard) | `const { copy, paste, copied } = useClipboard();` |
143
- | [useRageClick](#userageclick) | `useRageClick(ref, { onRageClick, threshold: 5 });` |
144
- | [useThreadedWorker](#usethreadedworker) | `const { run, loading, result } = useThreadedWorker(fn, { mode: 'sequential' });` |
145
- | [useIndexedDB](#useindexeddb) | `const { db, isReady } = useIndexedDB({ name, version, tables });` |
146
- | [useWebRTCIP](#usewebrtcip) | `const { ips, loading, error } = useWebRTCIP({ timeout: 3000 });` |
147
- | [useWasmCompute](#usewasmcompute) | `const { compute, result, ready } = useWasmCompute({ wasmUrl });` |
148
- | [useWorkerNotifications](#useworkernotifications) | `const { progress, eventHistory } = useWorkerNotifications(worker);` |
149
- | [useLLMMetadata](#usellmmetadata) | `useLLMMetadata({ route: pathname, mode: 'auto-extract' });` |
140
+ | Hook | One-liner |
141
+ | ------------------------------------------------- | --------------------------------------------------------------------------------------------- |
142
+ | [useTransition](#usetransition) | `const [startTransition, isPending] = useTransition();` |
143
+ | [useMutationObserver](#usemutationobserver) | `useMutationObserver(ref, callback, { childList: true });` |
144
+ | [useEventBus](#useeventbus) | `const { emit, on } = useEventBus();` |
145
+ | [useWrappedChildren](#usewrappedchildren) | `const wrapped = useWrappedChildren(children, { className: 'x' });` |
146
+ | [usePreferredTheme](#usepreferredtheme) | `const theme = usePreferredTheme(); // 'light' \| 'dark' \| 'no-preference'` |
147
+ | [useNetworkState](#usenetworkstate) | `const { online, effectiveType } = useNetworkState();` |
148
+ | [usePrefetch](#useprefetch) | `const { prefetch, isPrefetched } = usePrefetch();` |
149
+ | [usePoll](#usepoll) | `const { data, done, pollCount, stop } = usePoll(pollFn, { intervalMs });` |
150
+ | [useClipboard](#useclipboard) | `const { copy, paste, copied } = useClipboard();` |
151
+ | [useRageClick](#userageclick) | `useRageClick(ref, { onRageClick, threshold: 5 });` |
152
+ | [useThreadedWorker](#usethreadedworker) | `const { run, loading, result } = useThreadedWorker(fn, { mode: 'sequential' });` |
153
+ | [useIndexedDB](#useindexeddb) | `const { db, isReady } = useIndexedDB({ name, version, tables });` |
154
+ | [useWebRTCIP](#usewebrtcip) | `const { ips, loading, error } = useWebRTCIP({ timeout: 3000 });` |
155
+ | [useWasmCompute](#usewasmcompute) | `const { compute, result, ready } = useWasmCompute({ wasmUrl });` |
156
+ | [useWorkerNotifications](#useworkernotifications) | `const { progress, eventHistory } = useWorkerNotifications(worker);` |
157
+ | [useLLMMetadata](#usellmmetadata) | `useLLMMetadata({ route: pathname, mode: 'auto-extract' });` |
158
+ | [useRefPrint](#userefprint) | `const { print } = useRefPrint(printRef, { documentTitle: 'Report' });` |
159
+ | [useRBAC](#userbac) | `const { can, hasRole, roles } = useRBAC({ userSource, roleDefinitions, roleCapabilities });` |
150
160
 
151
161
  ---
152
162
 
@@ -349,6 +359,62 @@ function PasteInput() {
349
359
 
350
360
  ---
351
361
 
362
+ ### `usePrefetch`
363
+
364
+ Preload URLs (documents or data) so they are cached before navigation or use. Ideal for link hover or route preloading. Use `prefetch(url)` with optional `{ as: 'document' | 'fetch' }`; `as: 'fetch'` warms the HTTP cache (e.g. for API URLs).
365
+
366
+ ```tsx
367
+ import { usePrefetch } from "preact-missing-hooks";
368
+
369
+ function NavLink({ href, children }) {
370
+ const { prefetch, isPrefetched } = usePrefetch();
371
+ return (
372
+ <a href={href} onMouseEnter={() => prefetch(href)}>
373
+ {children}
374
+ {isPrefetched(href) && " ✓"}
375
+ </a>
376
+ );
377
+ }
378
+
379
+ // Prefetch API data
380
+ function DataLoader() {
381
+ const { prefetch } = usePrefetch();
382
+ prefetch("/api/user", { as: "fetch" });
383
+ // ...
384
+ }
385
+ ```
386
+
387
+ ---
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
+
352
418
  ### `useRageClick`
353
419
 
354
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.
@@ -688,6 +754,99 @@ function App() {
688
754
 
689
755
  ---
690
756
 
757
+ ### `useRefPrint`
758
+
759
+ Binds a ref to a DOM section and provides `print()` to open the native print dialog. Uses `@media print` CSS so only that section is visible when printing (user can then print or choose “Save as PDF”). Options: `documentTitle` (title for the print document), `downloadAsPdf` (hint that the same flow supports saving as PDF).
760
+
761
+ ```tsx
762
+ import { useRef } from "preact/hooks";
763
+ import { useRefPrint } from "preact-missing-hooks";
764
+
765
+ function Report() {
766
+ const printRef = useRef<HTMLDivElement>(null);
767
+ const { print } = useRefPrint(printRef, {
768
+ documentTitle: "Monthly Report",
769
+ downloadAsPdf: true,
770
+ });
771
+
772
+ return (
773
+ <div>
774
+ <div ref={printRef}>
775
+ <h1>Report content</h1>
776
+ <p>Only this section is printed when you click Print.</p>
777
+ </div>
778
+ <button onClick={print}>Print / Save as PDF</button>
779
+ </div>
780
+ );
781
+ }
782
+ ```
783
+
784
+ ---
785
+
786
+ ### `useRBAC`
787
+
788
+ Frontend-only role-based access control. Define roles with a condition (e.g. `user.role === 'admin'`), assign capabilities per role (use `'*'` for full access), and plug in where the current user comes from: `localStorage`, `sessionStorage`, API, memory, or a custom getter. Returns `user`, `roles`, `capabilities`, `hasRole(role)`, `can(capability)`, `refetch`, and helpers like `setUserInStorage` for persisting auth in storage.
789
+
790
+ **User source types:** `localStorage`, `sessionStorage` (key to read user JSON), `api` (`fetch` returning user), `memory` (`getUser()`), `custom` (`getAuth()` returning `{ user?, roles?, capabilities? }`). Optional `capabilitiesOverride` can read capabilities from storage or API instead of deriving from roles.
791
+
792
+ ```tsx
793
+ import { useRBAC } from "preact-missing-hooks";
794
+
795
+ const roleDefinitions = [
796
+ { role: "admin", condition: (u) => u?.role === "admin" },
797
+ {
798
+ role: "editor",
799
+ condition: (u) => u?.role === "editor" || u?.role === "admin",
800
+ },
801
+ { role: "viewer", condition: (u) => !!u?.id },
802
+ ];
803
+ const roleCapabilities = {
804
+ admin: ["*"],
805
+ editor: ["posts:edit", "posts:create", "posts:read"],
806
+ viewer: ["posts:read"],
807
+ };
808
+
809
+ function App() {
810
+ const { user, roles, capabilities, hasRole, can, setUserInStorage } = useRBAC(
811
+ {
812
+ userSource: { type: "localStorage", key: "user" },
813
+ roleDefinitions,
814
+ roleCapabilities,
815
+ }
816
+ );
817
+
818
+ const login = (role) => {
819
+ setUserInStorage(
820
+ { id: 1, role, email: role + "@app.com" },
821
+ "localStorage",
822
+ "user"
823
+ );
824
+ };
825
+ const logout = () => setUserInStorage(null, "localStorage", "user");
826
+
827
+ return (
828
+ <div>
829
+ {!user ? (
830
+ <div>
831
+ <button onClick={() => login("admin")}>Login as Admin</button>
832
+ <button onClick={() => login("editor")}>Login as Editor</button>
833
+ <button onClick={() => login("viewer")}>Login as Viewer</button>
834
+ </div>
835
+ ) : (
836
+ <div>
837
+ <p>Roles: {roles.join(", ")}</p>
838
+ {can("posts:edit") && <button>Edit post</button>}
839
+ {can("*") && <button>Admin panel</button>}
840
+ <button onClick={logout}>Logout</button>
841
+ </div>
842
+ )}
843
+ </div>
844
+ );
845
+ }
846
+ ```
847
+
848
+ ---
849
+
691
850
  ## Built With
692
851
 
693
852
  - [Preact](https://preactjs.com)
package/dist/index.d.ts CHANGED
@@ -14,3 +14,5 @@ export * from "./useWorkerNotifications";
14
14
  export * from "./useLLMMetadata";
15
15
  export * from "./useRefPrint";
16
16
  export * from "./useRBAC";
17
+ export * from "./usePrefetch";
18
+ export * from "./usePoll";
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 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])};
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