preact-missing-hooks 4.4.0 → 4.6.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 +144 -17
- package/dist/index.d.ts +2 -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 +310 -0
- package/dist/usePrefetch.d.ts +44 -0
- package/dist/useRBAC.d.ts +102 -0
- package/docs/README.md +107 -0
- package/docs/index.html +50 -0
- package/docs/main.js +132 -0
- package/llm.package.json +105 -216
- package/llm.package.txt +29 -47
- package/package.json +13 -2
- package/src/index.ts +2 -0
- package/src/usePrefetch.ts +92 -0
- package/src/useRBAC.ts +380 -0
- package/tests/usePrefetch.test.tsx +107 -0
- package/tests/useRBAC.test.tsx +212 -0
package/Readme.md
CHANGED
|
@@ -27,6 +27,7 @@ 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)`.
|
|
30
31
|
- **`useClipboard`** — Copy and paste text with the Clipboard API, with copied/error state.
|
|
31
32
|
- **`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
33
|
- **`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 +36,8 @@ A lightweight, extendable collection of React-like hooks for Preact, including u
|
|
|
35
36
|
- **`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
37
|
- **`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
38
|
- **`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.
|
|
39
|
+
- **`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`.
|
|
40
|
+
- **`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
41
|
- Fully TypeScript compatible
|
|
39
42
|
- Bundled with Microbundle
|
|
40
43
|
- Zero dependencies (peer: `preact` or `react` — use `/react` for React)
|
|
@@ -71,12 +74,13 @@ import { useThreadedWorker, useClipboard } from "preact-missing-hooks";
|
|
|
71
74
|
```ts
|
|
72
75
|
import { useThreadedWorker } from "preact-missing-hooks/useThreadedWorker";
|
|
73
76
|
import { useClipboard } from "preact-missing-hooks/useClipboard";
|
|
77
|
+
import { usePrefetch } from "preact-missing-hooks/usePrefetch";
|
|
74
78
|
import { useWebRTCIP } from "preact-missing-hooks/useWebRTCIP";
|
|
75
79
|
import { useWasmCompute } from "preact-missing-hooks/useWasmCompute";
|
|
76
80
|
import { useWorkerNotifications } from "preact-missing-hooks/useWorkerNotifications";
|
|
77
81
|
```
|
|
78
82
|
|
|
79
|
-
All hooks are available: `useTransition`, `useMutationObserver`, `useEventBus`, `useWrappedChildren`, `usePreferredTheme`, `useNetworkState`, `useClipboard`, `useRageClick`, `useThreadedWorker`, `useIndexedDB`, `useWebRTCIP`, `useWasmCompute`, `useWorkerNotifications`, `useLLMMetadata`.
|
|
83
|
+
All hooks are available: `useTransition`, `useMutationObserver`, `useEventBus`, `useWrappedChildren`, `usePreferredTheme`, `useNetworkState`, `useClipboard`, `usePrefetch`, `useRageClick`, `useThreadedWorker`, `useIndexedDB`, `useWebRTCIP`, `useWasmCompute`, `useWorkerNotifications`, `useLLMMetadata`, `useRefPrint`, `useRBAC`.
|
|
80
84
|
|
|
81
85
|
---
|
|
82
86
|
|
|
@@ -131,22 +135,25 @@ Or open `docs/index.html` after building (see [docs/README.md](docs/README.md) f
|
|
|
131
135
|
|
|
132
136
|
**Usage at a glance:**
|
|
133
137
|
|
|
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
|
-
| [
|
|
143
|
-
| [
|
|
144
|
-
| [
|
|
145
|
-
| [
|
|
146
|
-
| [
|
|
147
|
-
| [
|
|
148
|
-
| [
|
|
149
|
-
| [
|
|
138
|
+
| Hook | One-liner |
|
|
139
|
+
| ------------------------------------------------- | --------------------------------------------------------------------------------------------- |
|
|
140
|
+
| [useTransition](#usetransition) | `const [startTransition, isPending] = useTransition();` |
|
|
141
|
+
| [useMutationObserver](#usemutationobserver) | `useMutationObserver(ref, callback, { childList: true });` |
|
|
142
|
+
| [useEventBus](#useeventbus) | `const { emit, on } = useEventBus();` |
|
|
143
|
+
| [useWrappedChildren](#usewrappedchildren) | `const wrapped = useWrappedChildren(children, { className: 'x' });` |
|
|
144
|
+
| [usePreferredTheme](#usepreferredtheme) | `const theme = usePreferredTheme(); // 'light' \| 'dark' \| 'no-preference'` |
|
|
145
|
+
| [useNetworkState](#usenetworkstate) | `const { online, effectiveType } = useNetworkState();` |
|
|
146
|
+
| [usePrefetch](#useprefetch) | `const { prefetch, isPrefetched } = usePrefetch();` |
|
|
147
|
+
| [useClipboard](#useclipboard) | `const { copy, paste, copied } = useClipboard();` |
|
|
148
|
+
| [useRageClick](#userageclick) | `useRageClick(ref, { onRageClick, threshold: 5 });` |
|
|
149
|
+
| [useThreadedWorker](#usethreadedworker) | `const { run, loading, result } = useThreadedWorker(fn, { mode: 'sequential' });` |
|
|
150
|
+
| [useIndexedDB](#useindexeddb) | `const { db, isReady } = useIndexedDB({ name, version, tables });` |
|
|
151
|
+
| [useWebRTCIP](#usewebrtcip) | `const { ips, loading, error } = useWebRTCIP({ timeout: 3000 });` |
|
|
152
|
+
| [useWasmCompute](#usewasmcompute) | `const { compute, result, ready } = useWasmCompute({ wasmUrl });` |
|
|
153
|
+
| [useWorkerNotifications](#useworkernotifications) | `const { progress, eventHistory } = useWorkerNotifications(worker);` |
|
|
154
|
+
| [useLLMMetadata](#usellmmetadata) | `useLLMMetadata({ route: pathname, mode: 'auto-extract' });` |
|
|
155
|
+
| [useRefPrint](#userefprint) | `const { print } = useRefPrint(printRef, { documentTitle: 'Report' });` |
|
|
156
|
+
| [useRBAC](#userbac) | `const { can, hasRole, roles } = useRBAC({ userSource, roleDefinitions, roleCapabilities });` |
|
|
150
157
|
|
|
151
158
|
---
|
|
152
159
|
|
|
@@ -349,6 +356,33 @@ function PasteInput() {
|
|
|
349
356
|
|
|
350
357
|
---
|
|
351
358
|
|
|
359
|
+
### `usePrefetch`
|
|
360
|
+
|
|
361
|
+
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).
|
|
362
|
+
|
|
363
|
+
```tsx
|
|
364
|
+
import { usePrefetch } from "preact-missing-hooks";
|
|
365
|
+
|
|
366
|
+
function NavLink({ href, children }) {
|
|
367
|
+
const { prefetch, isPrefetched } = usePrefetch();
|
|
368
|
+
return (
|
|
369
|
+
<a href={href} onMouseEnter={() => prefetch(href)}>
|
|
370
|
+
{children}
|
|
371
|
+
{isPrefetched(href) && " ✓"}
|
|
372
|
+
</a>
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Prefetch API data
|
|
377
|
+
function DataLoader() {
|
|
378
|
+
const { prefetch } = usePrefetch();
|
|
379
|
+
prefetch("/api/user", { as: "fetch" });
|
|
380
|
+
// ...
|
|
381
|
+
}
|
|
382
|
+
```
|
|
383
|
+
|
|
384
|
+
---
|
|
385
|
+
|
|
352
386
|
### `useRageClick`
|
|
353
387
|
|
|
354
388
|
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 +722,99 @@ function App() {
|
|
|
688
722
|
|
|
689
723
|
---
|
|
690
724
|
|
|
725
|
+
### `useRefPrint`
|
|
726
|
+
|
|
727
|
+
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).
|
|
728
|
+
|
|
729
|
+
```tsx
|
|
730
|
+
import { useRef } from "preact/hooks";
|
|
731
|
+
import { useRefPrint } from "preact-missing-hooks";
|
|
732
|
+
|
|
733
|
+
function Report() {
|
|
734
|
+
const printRef = useRef<HTMLDivElement>(null);
|
|
735
|
+
const { print } = useRefPrint(printRef, {
|
|
736
|
+
documentTitle: "Monthly Report",
|
|
737
|
+
downloadAsPdf: true,
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
return (
|
|
741
|
+
<div>
|
|
742
|
+
<div ref={printRef}>
|
|
743
|
+
<h1>Report content</h1>
|
|
744
|
+
<p>Only this section is printed when you click Print.</p>
|
|
745
|
+
</div>
|
|
746
|
+
<button onClick={print}>Print / Save as PDF</button>
|
|
747
|
+
</div>
|
|
748
|
+
);
|
|
749
|
+
}
|
|
750
|
+
```
|
|
751
|
+
|
|
752
|
+
---
|
|
753
|
+
|
|
754
|
+
### `useRBAC`
|
|
755
|
+
|
|
756
|
+
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.
|
|
757
|
+
|
|
758
|
+
**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.
|
|
759
|
+
|
|
760
|
+
```tsx
|
|
761
|
+
import { useRBAC } from "preact-missing-hooks";
|
|
762
|
+
|
|
763
|
+
const roleDefinitions = [
|
|
764
|
+
{ role: "admin", condition: (u) => u?.role === "admin" },
|
|
765
|
+
{
|
|
766
|
+
role: "editor",
|
|
767
|
+
condition: (u) => u?.role === "editor" || u?.role === "admin",
|
|
768
|
+
},
|
|
769
|
+
{ role: "viewer", condition: (u) => !!u?.id },
|
|
770
|
+
];
|
|
771
|
+
const roleCapabilities = {
|
|
772
|
+
admin: ["*"],
|
|
773
|
+
editor: ["posts:edit", "posts:create", "posts:read"],
|
|
774
|
+
viewer: ["posts:read"],
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
function App() {
|
|
778
|
+
const { user, roles, capabilities, hasRole, can, setUserInStorage } = useRBAC(
|
|
779
|
+
{
|
|
780
|
+
userSource: { type: "localStorage", key: "user" },
|
|
781
|
+
roleDefinitions,
|
|
782
|
+
roleCapabilities,
|
|
783
|
+
}
|
|
784
|
+
);
|
|
785
|
+
|
|
786
|
+
const login = (role) => {
|
|
787
|
+
setUserInStorage(
|
|
788
|
+
{ id: 1, role, email: role + "@app.com" },
|
|
789
|
+
"localStorage",
|
|
790
|
+
"user"
|
|
791
|
+
);
|
|
792
|
+
};
|
|
793
|
+
const logout = () => setUserInStorage(null, "localStorage", "user");
|
|
794
|
+
|
|
795
|
+
return (
|
|
796
|
+
<div>
|
|
797
|
+
{!user ? (
|
|
798
|
+
<div>
|
|
799
|
+
<button onClick={() => login("admin")}>Login as Admin</button>
|
|
800
|
+
<button onClick={() => login("editor")}>Login as Editor</button>
|
|
801
|
+
<button onClick={() => login("viewer")}>Login as Viewer</button>
|
|
802
|
+
</div>
|
|
803
|
+
) : (
|
|
804
|
+
<div>
|
|
805
|
+
<p>Roles: {roles.join(", ")}</p>
|
|
806
|
+
{can("posts:edit") && <button>Edit post</button>}
|
|
807
|
+
{can("*") && <button>Admin panel</button>}
|
|
808
|
+
<button onClick={logout}>Logout</button>
|
|
809
|
+
</div>
|
|
810
|
+
)}
|
|
811
|
+
</div>
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
```
|
|
815
|
+
|
|
816
|
+
---
|
|
817
|
+
|
|
691
818
|
## Built With
|
|
692
819
|
|
|
693
820
|
- [Preact](https://preactjs.com)
|
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 g(e){var n=p(e,2048);if(!n)return"";try{var t=new URL(n);if("http:"===t.protocol||"https:"===t.protocol)return n}catch(e){}return""}function h(e){try{if("undefined"==typeof window)return!1;var n=window.getComputedStyle(e);return"none"!==n.display&&"hidden"!==n.visibility&&"0"!==n.opacity}catch(e){return!1}}function y(e){var n={};try{for(var t,r=i(Object.keys(e).slice(0,20));!(t=r()).done;){var o=t.value,u=p(o,50);if(u){var a=e[o];"string"==typeof a?n[u]=a.slice(0,500):"number"==typeof a&&Number.isFinite(a)||"boolean"==typeof a?n[u]=a:Array.isArray(a)&&(n[u]=a.map(function(e){return p(e,200)}).filter(Boolean).slice(0,20))}}}catch(e){}return n}function w(){try{if("undefined"==typeof document||!document.querySelectorAll)return;document.querySelectorAll('script[data-llm="true"]').forEach(function(e){return e.remove()})}catch(e){}}var b="use-ref-print-target",E="use-ref-print-styles",k="\n@media print {\n body * {\n visibility: hidden;\n }\n ."+b+",\n ."+b+" * {\n visibility: visible;\n }\n ."+b+" {\n position: absolute !important;\n left: 0 !important;\n top: 0 !important;\n width: 100% !important;\n }\n}\n";exports.useClipboard=function(n){void 0===n&&(n={});var t=n.resetDelay,r=void 0===t?2e3:t,o=e.useState(!1),i=o[0],u=o[1],a=e.useState(null),s=a[0],l=a[1],f=e.useCallback(function(){u(!1),l(null)},[]);return{copy:e.useCallback(function(e){try{if(l(null),"undefined"==typeof navigator||!navigator.clipboard){var n=new Error("Clipboard API is not available");return l(n),Promise.resolve(!1)}return Promise.resolve(c(function(){return Promise.resolve(navigator.clipboard.writeText(e)).then(function(){return u(!0),r>0&&setTimeout(function(){return u(!1)},r),!0})},function(e){var n=e instanceof Error?e:new Error(String(e));return l(n),!1}))}catch(e){return Promise.reject(e)}},[r]),paste:e.useCallback(function(){try{if(l(null),"undefined"==typeof navigator||!navigator.clipboard){var e=new Error("Clipboard API is not available");return l(e),Promise.resolve("")}return Promise.resolve(c(function(){return Promise.resolve(navigator.clipboard.readText())},function(e){var n=e instanceof Error?e:new Error(String(e));return l(n),""}))}catch(e){return Promise.reject(e)}},[]),copied:i,error:s,reset:f}},exports.useEventBus=function(){return{emit:e.useCallback(function(e){var n=arguments,t=r.get(e);t&&t.forEach(function(e){return e.apply(void 0,[].slice.call(n,1))})},[]),on:e.useCallback(function(e,n){var t=r.get(e);return t||(t=new Set,r.set(e,t)),t.add(n),function(){t.delete(n),0===t.size&&r.delete(e)}},[])}},exports.useIndexedDB=function(n){var t=e.useState(null),r=t[0],o=t[1],a=e.useState(null),c=a[0],d=a[1],v=e.useState(!1),p=v[0],m=v[1],g=e.useRef(n);return g.current=n,e.useEffect(function(){var e=!1;d(null),m(!1),o(null);var n=g.current;return function(e){var n=e.name+"_v"+e.version,t=s.get(n);return t||(t=function(e){return new Promise(function(n,t){var r=indexedDB.open(e.name,e.version);r.onerror=function(){var e;return t(null!=(e=r.error)?e:new DOMException("Failed to open database"))},r.onsuccess=function(){return n(r.result)},r.onupgradeneeded=function(n){for(var t=n.target.result,r=e.tables,o=0,u=Object.keys(r);o<u.length;o++){var a=u[o],c=r[a];if(!t.objectStoreNames.contains(a)){var s,l=t.createObjectStore(a,{keyPath:c.keyPath,autoIncrement:null!=(s=c.autoIncrement)&&s});if(c.indexes)for(var f,d=i(c.indexes);!(f=d()).done;){var v=f.value;l.createIndex(v,v,{unique:!1})}}}}})}(e),s.set(n,t),t)}({name:n.name,version:n.version,tables:n.tables}).then(function(n){if(e)n.close();else{var t=function(e){return{get db(){return e},hasTable:function(n){return e.objectStoreNames.contains(n)},table:function(n){return function(e,n){return function(e,n){function t(t){return e.transaction([n],t).objectStore(n)}return{insert:function(e,n){return f(l(t("readwrite").add(e)),n)},update:function(e,n,r){var o=t("readwrite");return f(l(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var t=u({},e,n);return l(o.put(t))}).then(function(){}),r)},delete:function(e,n){return f(l(t("readwrite").delete(e)).then(function(){}),n)},exists:function(e){return l(t("readonly").getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var r=t("readonly").openCursor(),o=[];return f(new Promise(function(n,t){r.onsuccess=function(){var t=r.result;t?(e(t.value)&&o.push(t.value),t.continue()):n(o)},r.onerror=function(){var e;return t(null!=(e=r.error)?e:new DOMException("Unknown error"))}}),n)},upsert:function(e,n){return f(l(t("readwrite").put(e)),n)},bulkInsert:function(e,n){var r=t("readwrite"),o=[];if(0===e.length)return f(Promise.resolve(o),n);var i=0;return f(new Promise(function(n,t){e.forEach(function(u,a){var c=r.add(u);c.onsuccess=function(){o[a]=c.result,++i===e.length&&n(o)},c.onerror=function(){var e;return t(null!=(e=c.error)?e:new DOMException("Unknown error"))}})}),n)},clear:function(e){return f(l(t("readwrite").clear()).then(function(){}),e)},count:function(e){return f(l(t("readonly").count()),null!=e?e:{})}}}(e,n)}(e,n)},transaction:function(n,t,r,o){var i=e.transaction(n,t),a={table:function(e){return function(e,n){return function(e,n){function t(){return e.objectStore(n)}return{insert:function(e,n){return f(l(t().add(e)),n)},update:function(e,n,r){var o=t();return f(l(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var t=u({},e,n);return l(o.put(t))}).then(function(){}),r)},delete:function(e,n){return f(l(t().delete(e)).then(function(){}),n)},exists:function(e){return l(t().getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var r=t().openCursor(),o=[];return f(new Promise(function(n,t){r.onsuccess=function(){var t=r.result;t?(e(t.value)&&o.push(t.value),t.continue()):n(o)},r.onerror=function(){var e;return t(null!=(e=r.error)?e:new DOMException("Unknown error"))}}),n)},upsert:function(e,n){return f(l(t().put(e)),n)},bulkInsert:function(e,n){var r=t(),o=[];if(0===e.length)return f(Promise.resolve(o),n);var i=0;return f(new Promise(function(n,t){e.forEach(function(u,a){var c=r.add(u);c.onsuccess=function(){o[a]=c.result,++i===e.length&&n(o)},c.onerror=function(){var e;return t(null!=(e=c.error)?e:new DOMException("Unknown error"))}})}),n)},clear:function(e){return f(l(t().clear()).then(function(){}),e)},count:function(e){return f(l(t().count()),null!=e?e:{})}}}(e,n)}(i,e)}},c=new Promise(function(e,n){i.oncomplete=function(){return e()},i.onerror=function(){var e;return n(null!=(e=i.error)?e:new DOMException("Transaction failed"))}}),s=r(a);return function(e,n){return n?e.then(function(){return null==n.onSuccess?void 0:n.onSuccess()}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}(Promise.resolve(s).then(function(){return c}),o)}}}(n);o(t),m(!0)}}).catch(function(n){e||d(n)}),function(){e=!0}},[n.name,n.version]),{db:r,isReady:p,error:c}},exports.useLLMMetadata=function(e){var n=t.useRef(null);t.useEffect(function(){try{if("undefined"==typeof window)return;var t=function(e){return null==e||"object"!=typeof e?{route:"/"}:{route:p(e.route,2048)||"/",mode:"auto-extract"===e.mode?"auto-extract":"manual",title:void 0!==e.title?p(e.title,200):void 0,description:void 0!==e.description?p(e.description,2e3):void 0,tags:void 0!==e.tags?m(e.tags):void 0,canonicalUrl:void 0!==e.canonicalUrl?g(e.canonicalUrl):void 0,language:void 0!==e.language?p(e.language,20):void 0,ogType:void 0!==e.ogType?p(e.ogType,50):void 0,ogImage:void 0!==e.ogImage?g(e.ogImage):void 0,ogImageAlt:void 0!==e.ogImageAlt?p(e.ogImageAlt,200):void 0,siteName:void 0!==e.siteName?p(e.siteName,100):void 0,author:void 0!==e.author?p(e.author,200):void 0,publishedTime:void 0!==e.publishedTime?p(e.publishedTime,50):void 0,modifiedTime:void 0!==e.modifiedTime?p(e.modifiedTime,50):void 0,robots:void 0!==e.robots?p(e.robots,100):void 0,extra:void 0===e.extra||"object"!=typeof e.extra||Array.isArray(e.extra)?void 0:y(e.extra)}}(e),r=function(e){try{var n=(new Date).toISOString(),t={route:e.route,generatedAt:n};if("auto-extract"===e.mode){var r,o,u=function(){var e={title:"",outline:[],description:""};try{if("undefined"==typeof document)return e;var n=p(document.title,200),t=[],r="";try{for(var o,u=document.querySelectorAll("nav, footer, [role='navigation'], [role='contentinfo'], script, style, noscript"),a=function(e){for(var n,t=i(u);!(n=t()).done;)if(n.value.contains(e))return!0;return!1},c=i(document.querySelectorAll("h1, h2"));!(o=c()).done;){var s=o.value;if(t.length>=50)break;if(h(s)&&!a(s)){var l=p(s.textContent,300);l&&t.push(l)}}for(var f,d=document.querySelectorAll("p"),v=[],m=i(d);!(f=m()).done;){var g=f.value;if(v.length>=3)break;if(h(g)&&!a(g)){var y=p(g.textContent,1e3);y&&v.push(y)}}r=v.join(" ").trim().slice(0,2e3)||""}catch(e){}return{title:n,outline:t,description:r}}catch(n){return e}}();t.title=(null!=(r=e.title)?r:u.title)||void 0,t.description=(null!=(o=e.description)?o:u.description)||void 0,u.outline.length>0&&(t.outline=u.outline)}else void 0!==e.title&&""!==e.title&&(t.title=e.title),void 0!==e.description&&""!==e.description&&(t.description=e.description);return e.tags&&e.tags.length>0&&(t.tags=e.tags),e.canonicalUrl&&(t.canonicalUrl=e.canonicalUrl),e.language&&(t.language=e.language),e.ogType&&(t.ogType=e.ogType),e.ogImage&&(t.ogImage=e.ogImage),e.ogImageAlt&&(t.ogImageAlt=e.ogImageAlt),e.siteName&&(t.siteName=e.siteName),e.author&&(t.author=e.author),e.publishedTime&&(t.publishedTime=e.publishedTime),e.modifiedTime&&(t.modifiedTime=e.modifiedTime),e.robots&&(t.robots=e.robots),e.extra&&Object.keys(e.extra).length>0&&(t.extra=e.extra),t}catch(n){var a;return{route:null!=(a=null==e?void 0:e.route)?a:"/",generatedAt:(new Date).toISOString()}}}(t),o=JSON.stringify(r);if(n.current===o)return;return n.current=o,w(),function(e){try{if("undefined"==typeof document||!document.head)return;var n=document.createElement("script");n.type="application/llm+json",n.setAttribute("data-llm","true"),n.textContent=JSON.stringify(e),document.head.appendChild(n)}catch(e){}}(r),function(){w(),n.current=null}}catch(e){}},[null==e?void 0:e.route,null==e?void 0:e.mode,null==e?void 0:e.title,null==e?void 0:e.description,null==e?void 0:e.tags,null==e?void 0:e.canonicalUrl,null==e?void 0:e.language,null==e?void 0:e.ogType,null==e?void 0:e.ogImage,null==e?void 0:e.ogImageAlt,null==e?void 0:e.siteName,null==e?void 0:e.author,null==e?void 0:e.publishedTime,null==e?void 0:e.modifiedTime,null==e?void 0:e.robots])},exports.useMutationObserver=function(n,t,r){e.useEffect(function(){var e=n.current;if(e){var o=new MutationObserver(t);return o.observe(e,r),function(){return o.disconnect()}}},[n,t,r])},exports.useNetworkState=function(){var n=e.useState(a),t=n[0],r=n[1];return e.useEffect(function(){if("undefined"!=typeof window){var e=function(){return r(a())};window.addEventListener("online",e),window.addEventListener("offline",e);var n=navigator.connection;return null!=n&&n.addEventListener&&n.addEventListener("change",e),function(){window.removeEventListener("online",e),window.removeEventListener("offline",e),null!=n&&n.removeEventListener&&n.removeEventListener("change",e)}}},[]),t},exports.usePreferredTheme=function(){var n=e.useState(function(){if("undefined"==typeof window)return"no-preference";var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");return e.matches?"dark":n.matches?"light":"no-preference"}),t=n[0],r=n[1];return e.useEffect(function(){if("undefined"!=typeof window){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=function(e){r(e.matches?"dark":"light")},t=function(){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");r(e.matches?"dark":n.matches?"light":"no-preference")};e.addEventListener("change",n);var o=window.matchMedia("(prefers-color-scheme: light)");return o.addEventListener("change",t),function(){e.removeEventListener("change",n),o.removeEventListener("change",t)}}},[]),t},exports.useRageClick=function(n,t){var r=t.onRageClick,o=t.threshold,i=void 0===o?5:o,u=t.timeWindow,a=void 0===u?1e3:u,c=t.distanceThreshold,s=void 0===c?30:c,l=e.useRef(r);l.current=r;var f=e.useRef([]);e.useEffect(function(){var e=n.current;if(e){var t=function(e){var n=Date.now(),t={time:n,x:e.clientX,y:e.clientY},r=n-a,o=f.current.filter(function(e){return e.time>=r});if(o.push(t),Infinity!==s){var u=o.filter(function(e){return n=e,r=t,Math.hypot(r.x-n.x,r.y-n.y)<=s;var n,r});if(u.length>=i)return l.current({count:u.length,event:e}),void(f.current=[])}else if(o.length>=i)return l.current({count:o.length,event:e}),void(f.current=[]);f.current=o};return e.addEventListener("click",t),function(){return e.removeEventListener("click",t)}}},[n,i,a,s])},exports.useRefPrint=function(n,t){void 0===t&&(t={});var r=t.documentTitle,o=e.useRef("");return{print:e.useCallback(function(){var e=n.current;if(e&&"undefined"!=typeof window&&window.print){var t=document.getElementById(E);t||((t=document.createElement("style")).id=E,t.textContent=k,document.head.appendChild(t)),e.classList.add(b),r&&(o.current=document.title,document.title=r);var i=function(){e.classList.remove(b),r&&void 0!==o.current&&(document.title=o.current)};if("onafterprint"in window){var u=function(){i(),window.removeEventListener("afterprint",u)};window.addEventListener("afterprint",u)}window.print(),setTimeout(i,1e3)}},[n,r])}},exports.useThreadedWorker=function(n,t){var r=t.concurrency,o="sequential"===t.mode?1:Math.max(1,void 0===r?4:r),i=e.useState(!1),u=i[0],a=i[1],c=e.useState(void 0),s=c[0],l=c[1],f=e.useState(void 0),d=f[0],v=f[1],p=e.useState(0),m=p[0],g=p[1],h=e.useRef([]),y=e.useRef(0),w=e.useRef(0),b=e.useRef(!1),E=e.useRef(n);E.current=n;var k=e.useCallback(function(){g(h.current.length+w.current)},[]),S=e.useCallback(function(){if(!(b.current||w.current>=o)){if(0===h.current.length)return 0===w.current&&a(!1),void k();h.current.sort(function(e,n){return e.priority!==n.priority?e.priority-n.priority:e.sequence-n.sequence});var e=h.current.shift();w.current+=1,a(!0),k(),(0,E.current)(e.data).then(function(n){l(n),v(void 0),e.resolve(n)}).catch(function(n){v(n),e.reject(n)}).finally(function(){w.current-=1,k(),S()}),h.current.length>0&&w.current<o&&S()}},[o,k]),x=e.useCallback(function(e,n){var t;if(b.current)return Promise.reject(new Error("Worker is terminated"));var r=null!=(t=null==n?void 0:n.priority)?t:1,o=++y.current,i=new Promise(function(n,t){h.current.push({data:e,priority:r,sequence:o,resolve:n,reject:t})});return k(),a(!0),queueMicrotask(S),i},[S,k]),T=e.useCallback(function(){var e=h.current;h.current=[],e.forEach(function(e){return e.reject(new Error("Task cleared from queue"))}),k(),0===w.current&&a(!1)},[k]),C=e.useCallback(function(){b.current=!0,T()},[T]);return e.useEffect(function(){return function(){b.current=!0}},[]),{run:x,loading:u,result:s,error:d,queueSize:m,clearQueue:T,terminate:C}},exports.useTransition=function(){var n=e.useState(!1),t=n[0],r=n[1];return[e.useCallback(function(e){r(!0),Promise.resolve().then(function(){e(),r(!1)})},[]),t]},exports.useWasmCompute=function(n){var t=n.wasmUrl,r=n.exportName,o=void 0===r?"compute":r,i=n.workerUrl,u=n.importObject,a=e.useState(void 0),c=a[0],s=a[1],l=e.useState(!0),f=l[0],d=l[1],v=e.useState(null),p=v[0],m=v[1],g=e.useState(!1),h=g[0],y=g[1],w=e.useRef(null),b=e.useRef(null),E=e.useRef(null);return e.useEffect(function(){if("undefined"==typeof window)return m("useWasmCompute is not available during SSR"),void d(!1);if("undefined"==typeof Worker)return m("Worker is not supported in this environment"),void d(!1);if("undefined"==typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)return m("WebAssembly is not supported in this environment"),void d(!1);m(null),y(!1);var e=function(e){if(e)return new Worker(e);var n=new Blob(["\nself.onmessage = async (e) => {\n const d = e.data;\n if (d.type === 'init') {\n try {\n const res = await fetch(d.wasmUrl);\n const buf = await res.arrayBuffer();\n const mod = await WebAssembly.instantiate(buf, d.importObject || {});\n self.wasmInstance = mod.instance;\n self.exportName = d.exportName || 'compute';\n self.postMessage({ type: 'ready' });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n return;\n }\n if (d.type === 'compute') {\n try {\n const fn = self.wasmInstance.exports[self.exportName];\n if (typeof fn !== 'function') {\n self.postMessage({ type: 'error', error: 'Export \"' + self.exportName + '\" is not a function' });\n return;\n }\n const result = fn(d.input);\n self.postMessage({ type: 'result', result: result });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n }\n};\n"],{type:"application/javascript"}),t=URL.createObjectURL(n),r=new Worker(t);return URL.revokeObjectURL(t),r}(i);w.current=e;var n=function(e){var n,t=null!=(n=e.data)?n:{},r=t.type,o=t.result,i=t.error;return"ready"===r?(y(!0),void d(!1)):"error"===r?(m(null!=i?i:"Unknown error"),d(!1),void(E.current&&(E.current(new Error(i)),b.current=null,E.current=null))):void("result"===r&&(s(o),d(!1),b.current&&(b.current(o),b.current=null,E.current=null)))};return e.addEventListener("message",n),e.postMessage({type:"init",wasmUrl:t,exportName:o,importObject:null!=u?u:{}}),function(){e.removeEventListener("message",n),e.terminate(),w.current=null,E.current&&(E.current(new Error("Worker terminated")),b.current=null,E.current=null)}},[t,o,i,u]),{compute:e.useCallback(function(e){return new Promise(function(n,t){w.current&&h?p?t(new Error(p)):(b.current=n,E.current=t,d(!0),w.current.postMessage({type:"compute",input:e})):t(new Error("WASM not ready"))})},[h,p]),result:c,loading:f,error:p,ready:h}},exports.useWebRTCIP=function(n){void 0===n&&(n={});var t=n.stunServers,r=void 0===t?v:t,o=n.timeout,i=void 0===o?3e3:o,u=n.onDetect,a=e.useState([]),c=a[0],s=a[1],l=e.useState(!0),f=l[0],p=l[1],m=e.useState(null),g=m[0],h=m[1],y=e.useRef(null),w=e.useRef(null),b=e.useRef(new Set),E=e.useRef(u);return E.current=u,e.useEffect(function(){if("undefined"==typeof window)return p(!1),void h("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return p(!1),void h("RTCPeerConnection is not available");var e=new Set;b.current=e;var n=function(){w.current&&(clearTimeout(w.current),w.current=null),y.current&&(y.current.close(),y.current=null),p(!1)},t=function(n){e.has(n)||(e.add(n),s(function(e){return[].concat(e,[n])}),null==E.current||E.current(n))};try{var o=new RTCPeerConnection({iceServers:[{urls:r}]});y.current=o,o.onicecandidate=function(e){var n,r=e.candidate;r&&r.candidate&&((n=r.candidate.match(d))?[].concat(n):[]).forEach(t)},o.createDataChannel(""),o.createOffer().then(function(e){return o.setLocalDescription(e)}).catch(function(e){h(e instanceof Error?e.message:"Failed to create offer"),n()}),w.current=setTimeout(function(){return n()},i)}catch(e){h(e instanceof Error?e.message:"WebRTC setup failed"),n()}return function(){n()}},[r.join(","),i]),{ips:c,loading:f,error:g}},exports.useWorkerNotifications=function(n,t){void 0===t&&(t={});var r=t.maxHistory,o=void 0===r?100:r,i=t.throughputWindowMs,u=void 0===i?1e3:i,a=e.useState([]),c=a[0],s=a[1],l=e.useState(0),f=l[0],d=l[1],v=e.useState(0),p=v[0],m=v[1],g=e.useState([]),h=g[0],y=g[1],w=e.useState(0),b=w[0],E=w[1],k=e.useRef([]),S=e.useRef(0),x=e.useRef(0);e.useEffect(function(){if(n){var e=function(e){var n=function(e){if(null==e||"object"!=typeof e)return null;var n=e.type;return"task_start"!==n&&"task_end"!==n&&"task_fail"!==n&&"queue_size"!==n?null:{type:n,taskId:"string"==typeof e.taskId?e.taskId:void 0,duration:"number"==typeof e.duration?e.duration:void 0,error:"string"==typeof e.error?e.error:void 0,size:"number"==typeof e.size?e.size:void 0,timestamp:Date.now()}}(e.data);if(n)if(y(function(e){return[].concat(e,[n]).slice(-o)}),"task_start"===n.type&&n.taskId)s(function(e){return e.includes(n.taskId)?e:[].concat(e,[n.taskId])});else if("task_end"===n.type){n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),d(function(e){return e+1});var t=Date.now()-u;k.current=[].concat(k.current.filter(function(e){return e>=t}),[n.timestamp]),"number"==typeof n.duration&&(S.current+=n.duration,x.current+=1)}else"task_fail"===n.type?(n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),m(function(e){return e+1})):"queue_size"===n.type&&"number"==typeof n.size&&E(n.size)};return n.addEventListener("message",e),function(){return n.removeEventListener("message",e)}}},[n,o]);var T=e.useMemo(function(){var e=x.current;return e>0?S.current/e:0},[h]),C=e.useMemo(function(){var e=Date.now()-u;return k.current.filter(function(n){return n>=e}).length/(u/1e3)},[h,u]),I=e.useMemo(function(){return{runningTasks:c,completedCount:f,failedCount:p,averageDurationMs:T,throughputPerSecond:C,currentQueueSize:b,totalProcessed:f+p,recentEventCount:h.length}},[c,f,p,T,C,b,h.length]);return{runningTasks:c,completedCount:f,failedCount:p,eventHistory:h,averageDurationMs:T,throughputPerSecond:C,currentQueueSize:b,progress:I}},exports.useWrappedChildren=function(t,r,o){return void 0===o&&(o="preserve"),e.useMemo(function(){if(!t)return t;var e=function(e){if(!n.isValidElement(e))return e;var t,i=e.props||{};t="override"===o?u({},i,r):u({},r,i);var a=null==i?void 0:i.style,c=null==r?void 0:r.style;return a&&c&&"object"==typeof a&&"object"==typeof c&&(t.style="override"===o?u({},a,c):u({},c,a)),n.cloneElement(e,t)};return Array.isArray(t)?t.map(e):e(t)},[t,r,o])};
|
|
1
|
+
var e=require("preact/hooks"),n=require("preact"),t=require("preact/compat"),r=new Map;function o(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=Array(n);t<n;t++)r[t]=e[t];return r}function i(e,n){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return o(e,n);var t={}.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?o(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)({}).hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},u.apply(null,arguments)}function a(){if("undefined"==typeof navigator)return{online:!0};var e={online:navigator.onLine},n=navigator.connection;return n&&(void 0!==n.effectiveType&&(e.effectiveType=n.effectiveType),void 0!==n.downlink&&(e.downlink=n.downlink),void 0!==n.rtt&&(e.rtt=n.rtt),void 0!==n.saveData&&(e.saveData=n.saveData),void 0!==n.type&&(e.connectionType=n.type)),e}function c(e,n){try{var t=e()}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}var s=new Map;function l(e){return new Promise(function(n,t){e.onsuccess=function(){return n(e.result)},e.onerror=function(){var n;return t(null!=(n=e.error)?n:new DOMException("Unknown IndexedDB error"))}})}function f(e,n){return n?e.then(function(e){return null==n.onSuccess||n.onSuccess(e),e}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}var d=/\b(?:25[0-5]|2[0-4]\d|1?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|1?\d{1,2})){3}\b/g,v=["stun:stun.l.google.com:19302"];function p(e,n){if(null==e)return"";var t=("string"==typeof e?e:String(e)).trim();return t.length>n?t.slice(0,n):t}function m(e){if(!Array.isArray(e))return[];for(var n=[],t=0;t<e.length&&n.length<50;t++){var r=p(e[t],100);r&&n.push(r)}return n}function 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])};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|