preact-missing-hooks 4.7.0 → 4.9.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.
@@ -1,2 +1,2 @@
1
- import{useState as e,useCallback as t,useEffect as n,useMemo as r,useRef as o}from"preact/hooks";import{isValidElement as i,cloneElement as c}from"preact";import{useRef as s,useEffect as u}from"preact/compat";function a(){const[n,r]=e(!1);return[t(e=>{r(!0),Promise.resolve().then(()=>{e(),r(!1)})},[]),n]}function l(e,t,r){n(()=>{const n=e.current;if(!n)return;const o=new MutationObserver(t);return o.observe(n,r),()=>o.disconnect()},[e,t,r])}const d=new Map;function f(){return{emit:t((e,...t)=>{const n=d.get(e);n&&n.forEach(e=>e(...t))},[]),on:t((e,t)=>{let n=d.get(e);return n||(n=new Set,d.set(e,n)),n.add(t),()=>{n.delete(t),0===n.size&&d.delete(e)}},[])}}function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},p.apply(null,arguments)}function m(e,t,n="preserve"){return r(()=>{if(!e)return e;const r=e=>{if(!i(e))return e;const r=e.props||{};let o;o="override"===n?p({},r,t):p({},t,r);const s=null==r?void 0:r.style,u=null==t?void 0:t.style;return s&&u&&"object"==typeof s&&"object"==typeof u&&(o.style="override"===n?p({},s,u):p({},u,s)),c(e,o)};return Array.isArray(e)?e.map(r):r(e)},[e,t,n])}function g(){const[t,r]=e(()=>{if("undefined"==typeof window)return"no-preference";const e=window.matchMedia("(prefers-color-scheme: dark)"),t=window.matchMedia("(prefers-color-scheme: light)");return e.matches?"dark":t.matches?"light":"no-preference"});return n(()=>{if("undefined"==typeof window)return;const e=window.matchMedia("(prefers-color-scheme: dark)"),t=e=>{r(e.matches?"dark":"light")},n=()=>{const e=window.matchMedia("(prefers-color-scheme: dark)"),t=window.matchMedia("(prefers-color-scheme: light)");r(e.matches?"dark":t.matches?"light":"no-preference")};e.addEventListener("change",t);const o=window.matchMedia("(prefers-color-scheme: light)");return o.addEventListener("change",n),()=>{e.removeEventListener("change",t),o.removeEventListener("change",n)}},[]),t}function y(){if("undefined"==typeof navigator)return{online:!0};const e={online:navigator.onLine},t=navigator.connection;return t&&(void 0!==t.effectiveType&&(e.effectiveType=t.effectiveType),void 0!==t.downlink&&(e.downlink=t.downlink),void 0!==t.rtt&&(e.rtt=t.rtt),void 0!==t.saveData&&(e.saveData=t.saveData),void 0!==t.type&&(e.connectionType=t.type)),e}function v(){const[t,r]=e(y);return n(()=>{if("undefined"==typeof window)return;const e=()=>r(y());window.addEventListener("online",e),window.addEventListener("offline",e);const t=navigator.connection;return null!=t&&t.addEventListener&&t.addEventListener("change",e),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",e),null!=t&&t.removeEventListener&&t.removeEventListener("change",e)}},[]),t}function h(n={}){const{resetDelay:r=2e3}=n,[o,i]=e(!1),[c,s]=e(null),u=t(()=>{i(!1),s(null)},[]);return{copy:t(async e=>{if(s(null),"undefined"==typeof navigator||!navigator.clipboard){const e=new Error("Clipboard API is not available");return s(e),!1}try{return await navigator.clipboard.writeText(e),i(!0),r>0&&setTimeout(()=>i(!1),r),!0}catch(e){const t=e instanceof Error?e:new Error(String(e));return s(t),!1}},[r]),paste:t(async()=>{if(s(null),"undefined"==typeof navigator||!navigator.clipboard){const e=new Error("Clipboard API is not available");return s(e),""}try{return await navigator.clipboard.readText()}catch(e){const t=e instanceof Error?e:new Error(String(e));return s(t),""}},[]),copied:o,error:c,reset:u}}function w(e,t){const{onRageClick:r,threshold:i=5,timeWindow:c=1e3,distanceThreshold:s=30}=t,u=o(r);u.current=r;const a=o([]);n(()=>{const t=e.current;if(!t)return;const n=e=>{const t=Date.now(),n={time:t,x:e.clientX,y:e.clientY},r=t-c,o=a.current.filter(e=>e.time>=r);if(o.push(n),Infinity!==s){const t=o.filter(e=>{return t=e,r=n,Math.hypot(r.x-t.x,r.y-t.y)<=s;var t,r});if(t.length>=i)return u.current({count:t.length,event:e}),void(a.current=[])}else if(o.length>=i)return u.current({count:o.length,event:e}),void(a.current=[]);a.current=o};return t.addEventListener("click",n),()=>t.removeEventListener("click",n)},[e,i,c,s])}function b(r,i){const{mode:c,concurrency:s=4}=i,u="sequential"===c?1:Math.max(1,s),[a,l]=e(!1),[d,f]=e(void 0),[p,m]=e(void 0),[g,y]=e(0),v=o([]),h=o(0),w=o(0),b=o(!1),S=o(r);S.current=r;const E=t(()=>{y(v.current.length+w.current)},[]),k=t(()=>{if(b.current)return;if(w.current>=u)return;if(0===v.current.length)return 0===w.current&&l(!1),void E();v.current.sort((e,t)=>e.priority!==t.priority?e.priority-t.priority:e.sequence-t.sequence);const e=v.current.shift();w.current+=1,l(!0),E(),(0,S.current)(e.data).then(t=>{f(t),m(void 0),e.resolve(t)}).catch(t=>{m(t),e.reject(t)}).finally(()=>{w.current-=1,E(),k()}),v.current.length>0&&w.current<u&&k()},[u,E]),I=t((e,t)=>{var n;if(b.current)return Promise.reject(new Error("Worker is terminated"));const r=null!=(n=null==t?void 0:t.priority)?n:1,o=++h.current,i=new Promise((t,n)=>{v.current.push({data:e,priority:r,sequence:o,resolve:t,reject:n})});return E(),l(!0),queueMicrotask(k),i},[k,E]),x=t(()=>{const e=v.current;v.current=[],e.forEach(e=>e.reject(new Error("Task cleared from queue"))),E(),0===w.current&&l(!1)},[E]),T=t(()=>{b.current=!0,x()},[x]);return n(()=>()=>{b.current=!0},[]),{run:I,loading:a,result:d,error:p,queueSize:g,clearQueue:x,terminate:T}}const S=new Map;function E(e){return new Promise((t,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>{var t;return n(null!=(t=e.error)?t:new DOMException("Unknown IndexedDB error"))}})}function k(e,t){return t?e.then(e=>(null==t.onSuccess||t.onSuccess(e),e)).catch(e=>{throw null==t.onError||t.onError(e),e}):e}function I(t){const[r,i]=e(null),[c,s]=e(null),[u,a]=e(!1),l=o(t);return l.current=t,n(()=>{let e=!1;s(null),a(!1),i(null);const{name:t,version:n,tables:r}=l.current;return function(e){const t=`${e.name}_v${e.version}`;let n=S.get(t);return n||(n=function(e){return new Promise((t,n)=>{const r=indexedDB.open(e.name,e.version);r.onerror=()=>{var e;return n(null!=(e=r.error)?e:new DOMException("Failed to open database"))},r.onsuccess=()=>t(r.result),r.onupgradeneeded=t=>{const n=t.target.result,r=e.tables;for(const e of Object.keys(r)){const t=r[e];if(!n.objectStoreNames.contains(e)){var o;const r=n.createObjectStore(e,{keyPath:t.keyPath,autoIncrement:null!=(o=t.autoIncrement)&&o});if(t.indexes)for(const e of t.indexes)r.createIndex(e,e,{unique:!1})}}}})}(e),S.set(t,n),n)}({name:t,version:n,tables:r}).then(t=>{if(e)return void t.close();const n=function(e){return{get db(){return e},hasTable:t=>e.objectStoreNames.contains(t),table:t=>function(e,t){return function(e,t){function n(n){return e.transaction([t],n).objectStore(t)}return{insert:(e,t)=>k(E(n("readwrite").add(e)),t),update(e,t,r){const o=n("readwrite");return k(E(o.get(e)).then(e=>{if(void 0===e)throw new DOMException("Key not found","NotFoundError");const n=p({},e,t);return E(o.put(n))}).then(()=>{}),r)},delete:(e,t)=>k(E(n("readwrite").delete(e)).then(()=>{}),t),exists:e=>E(n("readonly").getKey(e)).then(e=>void 0!==e),query(e,t){const r=n("readonly").openCursor(),o=[];return k(new Promise((t,n)=>{r.onsuccess=()=>{const n=r.result;n?(e(n.value)&&o.push(n.value),n.continue()):t(o)},r.onerror=()=>{var e;return n(null!=(e=r.error)?e:new DOMException("Unknown error"))}}),t)},upsert:(e,t)=>k(E(n("readwrite").put(e)),t),bulkInsert(e,t){const r=n("readwrite"),o=[];if(0===e.length)return k(Promise.resolve(o),t);let i=0;return k(new Promise((t,n)=>{e.forEach((c,s)=>{const u=r.add(c);u.onsuccess=()=>{o[s]=u.result,i++,i===e.length&&t(o)},u.onerror=()=>{var e;return n(null!=(e=u.error)?e:new DOMException("Unknown error"))}})}),t)},clear:e=>k(E(n("readwrite").clear()).then(()=>{}),e),count:e=>k(E(n("readonly").count()),null!=e?e:{})}}(e,t)}(e,t),transaction(t,n,r,o){const i=e.transaction(t,n),c={table:e=>function(e,t){return function(e,t){function n(){return e.objectStore(t)}return{insert:(e,t)=>k(E(n().add(e)),t),update(e,t,r){const o=n();return k(E(o.get(e)).then(e=>{if(void 0===e)throw new DOMException("Key not found","NotFoundError");const n=p({},e,t);return E(o.put(n))}).then(()=>{}),r)},delete:(e,t)=>k(E(n().delete(e)).then(()=>{}),t),exists:e=>E(n().getKey(e)).then(e=>void 0!==e),query(e,t){const r=n().openCursor(),o=[];return k(new Promise((t,n)=>{r.onsuccess=()=>{const n=r.result;n?(e(n.value)&&o.push(n.value),n.continue()):t(o)},r.onerror=()=>{var e;return n(null!=(e=r.error)?e:new DOMException("Unknown error"))}}),t)},upsert:(e,t)=>k(E(n().put(e)),t),bulkInsert(e,t){const r=n(),o=[];if(0===e.length)return k(Promise.resolve(o),t);let i=0;return k(new Promise((t,n)=>{e.forEach((c,s)=>{const u=r.add(c);u.onsuccess=()=>{o[s]=u.result,i++,i===e.length&&t(o)},u.onerror=()=>{var e;return n(null!=(e=u.error)?e:new DOMException("Unknown error"))}})}),t)},clear:e=>k(E(n().clear()).then(()=>{}),e),count:e=>k(E(n().count()),null!=e?e:{})}}(e,t)}(i,e)},s=new Promise((e,t)=>{i.oncomplete=()=>e(),i.onerror=()=>{var e;return t(null!=(e=i.error)?e:new DOMException("Transaction failed"))}}),u=r(c);return function(e,t){return t?e.then(()=>null==t.onSuccess?void 0:t.onSuccess()).catch(e=>{throw null==t.onError||t.onError(e),e}):e}(Promise.resolve(u).then(()=>s),o)}}}(t);i(n),a(!0)}).catch(t=>{e||s(t)}),()=>{e=!0}},[t.name,t.version]),{db:r,isReady:u,error:c}}const x=/\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,T=["stun:stun.l.google.com:19302"],A=3e3;function M(t={}){const{stunServers:r=T,timeout:i=A,onDetect:c}=t,[s,u]=e([]),[a,l]=e(!0),[d,f]=e(null),p=o(null),m=o(null),g=o(new Set),y=o(c);return y.current=c,n(()=>{if("undefined"==typeof window)return l(!1),void f("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return l(!1),void f("RTCPeerConnection is not available");const e=new Set;g.current=e;const t=()=>{m.current&&(clearTimeout(m.current),m.current=null),p.current&&(p.current.close(),p.current=null),l(!1)},n=t=>{e.has(t)||(e.add(t),u(e=>[...e,t]),null==y.current||y.current(t))};try{const e=new RTCPeerConnection({iceServers:[{urls:r}]});p.current=e,e.onicecandidate=e=>{const t=e.candidate;t&&t.candidate&&function(e){const t=e.match(x);return t?[...t]:[]}(t.candidate).forEach(n)},e.createDataChannel(""),e.createOffer().then(t=>e.setLocalDescription(t)).catch(e=>{f(e instanceof Error?e.message:"Failed to create offer"),t()}),m.current=setTimeout(()=>t(),i)}catch(e){f(e instanceof Error?e.message:"WebRTC setup failed"),t()}return()=>{t()}},[r.join(","),i]),{ips:s,loading:a,error:d}}function O(r){const{wasmUrl:i,exportName:c="compute",workerUrl:s,importObject:u}=r,[a,l]=e(void 0),[d,f]=e(!0),[p,m]=e(null),[g,y]=e(!1),v=o(null),h=o(null),w=o(null);return n(()=>{if("undefined"==typeof window)return m("useWasmCompute is not available during SSR"),void f(!1);if("undefined"==typeof Worker)return m("Worker is not supported in this environment"),void f(!1);if("undefined"==typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)return m("WebAssembly is not supported in this environment"),void f(!1);m(null),y(!1);const e=function(e){if(e)return new Worker(e);const t=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"}),n=URL.createObjectURL(t),r=new Worker(n);return URL.revokeObjectURL(n),r}(s);v.current=e;const t=e=>{var t;const{type:n,result:r,error:o}=null!=(t=e.data)?t:{};return"ready"===n?(y(!0),void f(!1)):"error"===n?(m(null!=o?o:"Unknown error"),f(!1),void(w.current&&(w.current(new Error(o)),h.current=null,w.current=null))):void("result"===n&&(l(r),f(!1),h.current&&(h.current(r),h.current=null,w.current=null)))};return e.addEventListener("message",t),e.postMessage({type:"init",wasmUrl:i,exportName:c,importObject:null!=u?u:{}}),()=>{e.removeEventListener("message",t),e.terminate(),v.current=null,w.current&&(w.current(new Error("Worker terminated")),h.current=null,w.current=null)}},[i,c,s,u]),{compute:t(e=>new Promise((t,n)=>{v.current&&g?p?n(new Error(p)):(h.current=t,w.current=n,f(!0),v.current.postMessage({type:"compute",input:e})):n(new Error("WASM not ready"))}),[g,p]),result:a,loading:d,error:p,ready:g}}function C(t,i={}){const{maxHistory:c=100,throughputWindowMs:s=1e3}=i,[u,a]=e([]),[l,d]=e(0),[f,p]=e(0),[m,g]=e([]),[y,v]=e(0),h=o([]),w=o(0),b=o(0);n(()=>{if(!t)return;const e=e=>{const t=function(e){if(null==e||"object"!=typeof e)return null;const t=e.type;return"task_start"!==t&&"task_end"!==t&&"task_fail"!==t&&"queue_size"!==t?null:{type:t,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(t)if(g(e=>[...e,t].slice(-c)),"task_start"===t.type&&t.taskId)a(e=>e.includes(t.taskId)?e:[...e,t.taskId]);else if("task_end"===t.type){t.taskId&&a(e=>e.filter(e=>e!==t.taskId)),d(e=>e+1);const e=Date.now()-s;h.current=[...h.current.filter(t=>t>=e),t.timestamp],"number"==typeof t.duration&&(w.current+=t.duration,b.current+=1)}else"task_fail"===t.type?(t.taskId&&a(e=>e.filter(e=>e!==t.taskId)),p(e=>e+1)):"queue_size"===t.type&&"number"==typeof t.size&&v(t.size)};return t.addEventListener("message",e),()=>t.removeEventListener("message",e)},[t,c]);const S=r(()=>{const e=b.current;return e>0?w.current/e:0},[m]),E=r(()=>{const e=Date.now()-s;return h.current.filter(t=>t>=e).length/(s/1e3)},[m,s]),k=r(()=>({runningTasks:u,completedCount:l,failedCount:f,averageDurationMs:S,throughputPerSecond:E,currentQueueSize:y,totalProcessed:l+f,recentEventCount:m.length}),[u,l,f,S,E,y,m.length]);return{runningTasks:u,completedCount:l,failedCount:f,eventHistory:m,averageDurationMs:S,throughputPerSecond:E,currentQueueSize:y,progress:k}}function L(e,t){if(null==e)return"";const n=("string"==typeof e?e:String(e)).trim();return n.length>t?n.slice(0,t):n}function j(e){if(!Array.isArray(e))return[];const t=[];for(let n=0;n<e.length&&t.length<50;n++){const r=L(e[n],100);r&&t.push(r)}return t}function P(e){const t=L(e,2048);if(!t)return"";try{const e=new URL(t);if("http:"===e.protocol||"https:"===e.protocol)return t}catch(e){}return""}function D(e){try{if("undefined"==typeof window)return!1;const t=window.getComputedStyle(e);return"none"!==t.display&&"hidden"!==t.visibility&&"0"!==t.opacity}catch(e){return!1}}function N(e){const t={};try{for(const n of Object.keys(e).slice(0,20)){const r=L(n,50);if(!r)continue;const o=e[n];"string"==typeof o?t[r]=o.slice(0,500):"number"==typeof o&&Number.isFinite(o)||"boolean"==typeof o?t[r]=o:Array.isArray(o)&&(t[r]=o.map(e=>L(e,200)).filter(Boolean).slice(0,20))}}catch(e){}return t}function U(){try{if("undefined"==typeof document||!document.querySelectorAll)return;document.querySelectorAll('script[data-llm="true"]').forEach(e=>e.remove())}catch(e){}}function q(e){const t=s(null);u(()=>{try{if("undefined"==typeof window)return;const n=function(e){return null==e||"object"!=typeof e?{route:"/"}:{route:L(e.route,2048)||"/",mode:"auto-extract"===e.mode?"auto-extract":"manual",title:void 0!==e.title?L(e.title,200):void 0,description:void 0!==e.description?L(e.description,2e3):void 0,tags:void 0!==e.tags?j(e.tags):void 0,canonicalUrl:void 0!==e.canonicalUrl?P(e.canonicalUrl):void 0,language:void 0!==e.language?L(e.language,20):void 0,ogType:void 0!==e.ogType?L(e.ogType,50):void 0,ogImage:void 0!==e.ogImage?P(e.ogImage):void 0,ogImageAlt:void 0!==e.ogImageAlt?L(e.ogImageAlt,200):void 0,siteName:void 0!==e.siteName?L(e.siteName,100):void 0,author:void 0!==e.author?L(e.author,200):void 0,publishedTime:void 0!==e.publishedTime?L(e.publishedTime,50):void 0,modifiedTime:void 0!==e.modifiedTime?L(e.modifiedTime,50):void 0,robots:void 0!==e.robots?L(e.robots,100):void 0,extra:void 0===e.extra||"object"!=typeof e.extra||Array.isArray(e.extra)?void 0:N(e.extra)}}(e),r=function(e){try{const r=(new Date).toISOString(),o={route:e.route,generatedAt:r};if("auto-extract"===e.mode){var t,n;const r=function(){const e={title:"",outline:[],description:""};try{if("undefined"==typeof document)return e;const t=L(document.title,200),n=[];let r="";try{const e=document.querySelectorAll("nav, footer, [role='navigation'], [role='contentinfo'], script, style, noscript"),t=t=>{for(const n of e)if(n.contains(t))return!0;return!1},o=document.querySelectorAll("h1, h2");for(const e of o){if(n.length>=50)break;if(D(e)&&!t(e)){const t=L(e.textContent,300);t&&n.push(t)}}const i=document.querySelectorAll("p"),c=[];for(const e of i){if(c.length>=3)break;if(D(e)&&!t(e)){const t=L(e.textContent,1e3);t&&c.push(t)}}r=c.join(" ").trim().slice(0,2e3)||""}catch(e){}return{title:t,outline:n,description:r}}catch(t){return e}}();o.title=(null!=(t=e.title)?t:r.title)||void 0,o.description=(null!=(n=e.description)?n:r.description)||void 0,r.outline.length>0&&(o.outline=r.outline)}else void 0!==e.title&&""!==e.title&&(o.title=e.title),void 0!==e.description&&""!==e.description&&(o.description=e.description);return e.tags&&e.tags.length>0&&(o.tags=e.tags),e.canonicalUrl&&(o.canonicalUrl=e.canonicalUrl),e.language&&(o.language=e.language),e.ogType&&(o.ogType=e.ogType),e.ogImage&&(o.ogImage=e.ogImage),e.ogImageAlt&&(o.ogImageAlt=e.ogImageAlt),e.siteName&&(o.siteName=e.siteName),e.author&&(o.author=e.author),e.publishedTime&&(o.publishedTime=e.publishedTime),e.modifiedTime&&(o.modifiedTime=e.modifiedTime),e.robots&&(o.robots=e.robots),e.extra&&Object.keys(e.extra).length>0&&(o.extra=e.extra),o}catch(t){var r;return{route:null!=(r=null==e?void 0:e.route)?r:"/",generatedAt:(new Date).toISOString()}}}(n),o=JSON.stringify(r);if(t.current===o)return;return t.current=o,U(),function(e){try{if("undefined"==typeof document||!document.head)return;const t=document.createElement("script");t.type="application/llm+json",t.setAttribute("data-llm","true"),t.textContent=JSON.stringify(e),document.head.appendChild(t)}catch(e){}}(r),()=>{U(),t.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])}const R="use-ref-print-target",W="use-ref-print-styles",z=`\n@media print {\n body * {\n visibility: hidden;\n }\n .${R},\n .${R} * {\n visibility: visible;\n }\n .${R} {\n position: absolute !important;\n left: 0 !important;\n top: 0 !important;\n width: 100% !important;\n }\n}\n`;function _(e,n={}){const{documentTitle:r}=n,i=o("");return{print:t(()=>{const t=e.current;if(!t||"undefined"==typeof window||!window.print)return;let n=document.getElementById(W);n||(n=document.createElement("style"),n.id=W,n.textContent=z,document.head.appendChild(n)),t.classList.add(R),r&&(i.current=document.title,document.title=r);const o=()=>{t.classList.remove(R),r&&void 0!==i.current&&(document.title=i.current)};if("onafterprint"in window){const e=()=>{o(),window.removeEventListener("afterprint",e)};window.addEventListener("afterprint",e)}window.print(),setTimeout(o,1e3)},[e,r])}}function J(e,t){if("undefined"==typeof window)return null;const n="localStorage"===e?window.localStorage:window.sessionStorage;try{const e=n.getItem(t);if(null==e)return null;const r=JSON.parse(e);return r&&"object"==typeof r?r:null}catch(e){return null}}function B(e,t){if("undefined"==typeof window)return[];const n="localStorage"===e?window.localStorage:window.sessionStorage;try{const e=n.getItem(t);if(null==e)return[];const r=JSON.parse(e);return Array.isArray(r)?r.filter(e=>"string"==typeof e):[]}catch(e){return[]}}function F(e,t){return t.filter(t=>t.condition(e)).map(e=>e.role)}function $(e,t){const n=new Set;for(const r of e){const e=t[r];if(Array.isArray(e))for(const t of e)n.add(t)}return Array.from(n)}function K(r){const{userSource:i}=r,c=o(r);c.current=r;const[s,u]=e(null),[a,l]=e([]),[d,f]=e([]),[p,m]=e(!1),[g,y]=e(null),v=t(async()=>{const{userSource:e,roleDefinitions:t,roleCapabilities:n,capabilitiesOverride:r}=c.current;y(null);let o=null,i=[],s=[];try{if("localStorage"===e.type)o=J("localStorage",e.key),i=F(o,t),s=$(i,n);else if("sessionStorage"===e.type)o=J("sessionStorage",e.key),i=F(o,t),s=$(i,n);else if("api"===e.type)o=await e.fetch(),i=F(o,t),s=$(i,n);else if("memory"===e.type)o=e.getUser(),i=F(o,t),s=$(i,n);else if("custom"===e.type){var a,d,p;const r=await Promise.resolve(e.getAuth());o=null!=(a=r.user)?a:null,i=null!=(d=r.roles)?d:F(o,t),s=null!=(p=r.capabilities)?p:$(i,n)}if(r)if("localStorage"===r.type){const e=B("localStorage",r.key);e.length>0&&(s=e)}else if("sessionStorage"===r.type){const e=B("sessionStorage",r.key);e.length>0&&(s=e)}else"api"===r.type&&(s=await r.fetch());u(o),l(i),f(s)}catch(e){y(e instanceof Error?e:new Error(String(e))),u(null),l([]),f([])}finally{m(!0)}},[]);n(()=>{v()},[v]),n(()=>{if("undefined"==typeof window)return;const e="localStorage"===i.type||"sessionStorage"===i.type?i.key:null;if(!e)return;const t=t=>{t.key===e&&v()};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[i.type,"localStorage"===i.type||"sessionStorage"===i.type?i.key:"",v]);const h=t(e=>a.includes(e),[a]),w=t(e=>function(e,t){return!!e.includes("*")||e.includes(t)}(d,e),[d]),b=w,S=t(()=>v(),[v]),E=t((e,t,n)=>{if("undefined"==typeof window)return;const r="localStorage"===t?window.localStorage:window.sessionStorage;null==e?r.removeItem(n):r.setItem(n,JSON.stringify(e)),("localStorage"===i.type&&"localStorage"===t&&i.key===n||"sessionStorage"===i.type&&"sessionStorage"===t&&i.key===n)&&v()},[i,v]),k=t((e,t,n)=>{"undefined"!=typeof window&&("localStorage"===t?window.localStorage:window.sessionStorage).setItem(n,JSON.stringify(e))},[]),I=t((e,t,n)=>{"undefined"!=typeof window&&("localStorage"===t?window.localStorage:window.sessionStorage).setItem(n,JSON.stringify(e))},[]);return{user:s,roles:a,capabilities:d,isReady:p,error:g,hasRole:h,hasCapability:w,can:b,refetch:S,setUserInStorage:E,setRolesInStorage:k,setCapabilitiesInStorage:I}}function Q(){const n=o(new Set),[,r]=e(0);return{prefetch:t((e,t)=>{var o;const i=null==e?void 0:e.trim();i&&(n.current.has(i)||("document"===(null!=(o=null==t?void 0:t.as)?o:"document")?function(e){if("undefined"==typeof document)return;const t=document.querySelectorAll('link[rel="prefetch"]');for(let n=0;n<t.length;n++)if(t[n].href===e)return;const n=document.createElement("link");n.rel="prefetch",n.href=e,document.head.appendChild(n)}(i):function(e){"undefined"!=typeof fetch&&fetch(e,{method:"GET",mode:"cors"}).catch(()=>{})}(i),n.current.add(i),r(e=>e+1)))},[]),isPrefetched:t(e=>{var t;return n.current.has(null!=(t=null==e?void 0:e.trim())?t:"")},[])}}function H(r,i={}){const{intervalMs:c=1e3,immediate:s=!0,enabled:u=!0}=i,[a,l]=e(null),[d,f]=e(!1),[p,m]=e(null),[g,y]=e(0),[v,h]=e(!1),w=o(null),b=o(r);b.current=r;const S=t(()=>{null!=w.current&&(clearInterval(w.current),w.current=null),h(!1)},[]),E=t(async()=>{try{m(null);const e=await b.current();y(e=>e+1),e.done&&(S(),f(!0),void 0!==e.data&&l(e.data))}catch(e){const t=e instanceof Error?e:new Error(String(e));m(t),S()}},[S]),k=t(()=>{u&&!v&&(h(!0),s&&E(),w.current=setInterval(E,c))},[u,s,c,v,E]);return n(()=>(u&&k(),()=>{S()}),[u]),{data:a,done:d,error:p,pollCount:g,start:k,stop:S}}export{h as useClipboard,f as useEventBus,I as useIndexedDB,q as useLLMMetadata,l as useMutationObserver,v as useNetworkState,H as usePoll,g as usePreferredTheme,Q as usePrefetch,K as useRBAC,w as useRageClick,_ as useRefPrint,b as useThreadedWorker,a as useTransition,O as useWasmCompute,M as useWebRTCIP,C as useWorkerNotifications,m as useWrappedChildren};
1
+ import{useState as e,useCallback as n,useEffect as t,useMemo as r,useRef as o}from"preact/hooks";import{isValidElement as i,cloneElement as a}from"preact";import{useRef as s,useEffect as c}from"preact/compat";function l(){const[t,r]=e(!1);return[n(e=>{r(!0),Promise.resolve().then(()=>{e(),r(!1)})},[]),t]}function u(e,n,r){t(()=>{const t=e.current;if(!t)return;const o=new MutationObserver(n);return o.observe(t,r),()=>o.disconnect()},[e,n,r])}const d=new Map;function f(){return{emit:n((e,...n)=>{const t=d.get(e);t&&t.forEach(e=>e(...n))},[]),on:n((e,n)=>{let t=d.get(e);return t||(t=new Set,d.set(e,t)),t.add(n),()=>{t.delete(n),0===t.size&&d.delete(e)}},[])}}function m(){return m=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},m.apply(null,arguments)}function p(e,n,t="preserve"){return r(()=>{if(!e)return e;const r=e=>{if(!i(e))return e;const r=e.props||{};let o;o="override"===t?m({},r,n):m({},n,r);const s=null==r?void 0:r.style,c=null==n?void 0:n.style;return s&&c&&"object"==typeof s&&"object"==typeof c&&(o.style="override"===t?m({},s,c):m({},c,s)),a(e,o)};return Array.isArray(e)?e.map(r):r(e)},[e,n,t])}function v(){const[n,r]=e(()=>{if("undefined"==typeof window)return"no-preference";const e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");return e.matches?"dark":n.matches?"light":"no-preference"});return t(()=>{if("undefined"==typeof window)return;const e=window.matchMedia("(prefers-color-scheme: dark)"),n=e=>{r(e.matches?"dark":"light")},t=()=>{const 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);const o=window.matchMedia("(prefers-color-scheme: light)");return o.addEventListener("change",t),()=>{e.removeEventListener("change",n),o.removeEventListener("change",t)}},[]),n}function g(){if("undefined"==typeof navigator)return{online:!0};const 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 h(){const[n,r]=e(g);return t(()=>{if("undefined"==typeof window)return;const e=()=>r(g());window.addEventListener("online",e),window.addEventListener("offline",e);const n=navigator.connection;return null!=n&&n.addEventListener&&n.addEventListener("change",e),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",e),null!=n&&n.removeEventListener&&n.removeEventListener("change",e)}},[]),n}function w(t={}){const{resetDelay:r=2e3}=t,[o,i]=e(!1),[a,s]=e(null),c=n(()=>{i(!1),s(null)},[]);return{copy:n(async e=>{if(s(null),"undefined"==typeof navigator||!navigator.clipboard){const e=new Error("Clipboard API is not available");return s(e),!1}try{return await navigator.clipboard.writeText(e),i(!0),r>0&&setTimeout(()=>i(!1),r),!0}catch(e){const n=e instanceof Error?e:new Error(String(e));return s(n),!1}},[r]),paste:n(async()=>{if(s(null),"undefined"==typeof navigator||!navigator.clipboard){const e=new Error("Clipboard API is not available");return s(e),""}try{return await navigator.clipboard.readText()}catch(e){const n=e instanceof Error?e:new Error(String(e));return s(n),""}},[]),copied:o,error:a,reset:c}}function y(e,n){const{onRageClick:r,threshold:i=5,timeWindow:a=1e3,distanceThreshold:s=30}=n,c=o(r);c.current=r;const l=o([]);t(()=>{const n=e.current;if(!n)return;const t=e=>{const n=Date.now(),t={time:n,x:e.clientX,y:e.clientY},r=n-a,o=l.current.filter(e=>e.time>=r);if(o.push(t),Infinity!==s){const n=o.filter(e=>{return n=e,r=t,Math.hypot(r.x-n.x,r.y-n.y)<=s;var n,r});if(n.length>=i)return c.current({count:n.length,event:e}),void(l.current=[])}else if(o.length>=i)return c.current({count:o.length,event:e}),void(l.current=[]);l.current=o};return n.addEventListener("click",t),()=>n.removeEventListener("click",t)},[e,i,a,s])}function b(r,i){const{mode:a,concurrency:s=4}=i,c="sequential"===a?1:Math.max(1,s),[l,u]=e(!1),[d,f]=e(void 0),[m,p]=e(void 0),[v,g]=e(0),h=o([]),w=o(0),y=o(0),b=o(!1),E=o(r);E.current=r;const S=n(()=>{g(h.current.length+y.current)},[]),k=n(()=>{if(b.current)return;if(y.current>=c)return;if(0===h.current.length)return 0===y.current&&u(!1),void S();h.current.sort((e,n)=>e.priority!==n.priority?e.priority-n.priority:e.sequence-n.sequence);const e=h.current.shift();y.current+=1,u(!0),S(),(0,E.current)(e.data).then(n=>{f(n),p(void 0),e.resolve(n)}).catch(n=>{p(n),e.reject(n)}).finally(()=>{y.current-=1,S(),k()}),h.current.length>0&&y.current<c&&k()},[c,S]),x=n((e,n)=>{var t;if(b.current)return Promise.reject(new Error("Worker is terminated"));const r=null!=(t=null==n?void 0:n.priority)?t:1,o=++w.current,i=new Promise((n,t)=>{h.current.push({data:e,priority:r,sequence:o,resolve:n,reject:t})});return S(),u(!0),queueMicrotask(k),i},[k,S]),L=n(()=>{const e=h.current;h.current=[],e.forEach(e=>e.reject(new Error("Task cleared from queue"))),S(),0===y.current&&u(!1)},[S]),I=n(()=>{b.current=!0,L()},[L]);return t(()=>()=>{b.current=!0},[]),{run:x,loading:l,result:d,error:m,queueSize:v,clearQueue:L,terminate:I}}const E=new Map;function S(e){return new Promise((n,t)=>{e.onsuccess=()=>n(e.result),e.onerror=()=>{var n;return t(null!=(n=e.error)?n:new DOMException("Unknown IndexedDB error"))}})}function k(e,n){return n?e.then(e=>(null==n.onSuccess||n.onSuccess(e),e)).catch(e=>{throw null==n.onError||n.onError(e),e}):e}function x(n){const[r,i]=e(null),[a,s]=e(null),[c,l]=e(!1),u=o(n);return u.current=n,t(()=>{let e=!1;s(null),l(!1),i(null);const{name:n,version:t,tables:r}=u.current;return function(e){const n=`${e.name}_v${e.version}`;let t=E.get(n);return t||(t=function(e){return new Promise((n,t)=>{const r=indexedDB.open(e.name,e.version);r.onerror=()=>{var e;return t(null!=(e=r.error)?e:new DOMException("Failed to open database"))},r.onsuccess=()=>n(r.result),r.onupgradeneeded=n=>{const t=n.target.result,r=e.tables;for(const e of Object.keys(r)){const n=r[e];if(!t.objectStoreNames.contains(e)){var o;const r=t.createObjectStore(e,{keyPath:n.keyPath,autoIncrement:null!=(o=n.autoIncrement)&&o});if(n.indexes)for(const e of n.indexes)r.createIndex(e,e,{unique:!1})}}}})}(e),E.set(n,t),t)}({name:n,version:t,tables:r}).then(n=>{if(e)return void n.close();const t=function(e){return{get db(){return e},hasTable:n=>e.objectStoreNames.contains(n),table:n=>function(e,n){return function(e,n){function t(t){return e.transaction([n],t).objectStore(n)}return{insert:(e,n)=>k(S(t("readwrite").add(e)),n),update(e,n,r){const o=t("readwrite");return k(S(o.get(e)).then(e=>{if(void 0===e)throw new DOMException("Key not found","NotFoundError");const t=m({},e,n);return S(o.put(t))}).then(()=>{}),r)},delete:(e,n)=>k(S(t("readwrite").delete(e)).then(()=>{}),n),exists:e=>S(t("readonly").getKey(e)).then(e=>void 0!==e),query(e,n){const r=t("readonly").openCursor(),o=[];return k(new Promise((n,t)=>{r.onsuccess=()=>{const t=r.result;t?(e(t.value)&&o.push(t.value),t.continue()):n(o)},r.onerror=()=>{var e;return t(null!=(e=r.error)?e:new DOMException("Unknown error"))}}),n)},upsert:(e,n)=>k(S(t("readwrite").put(e)),n),bulkInsert(e,n){const r=t("readwrite"),o=[];if(0===e.length)return k(Promise.resolve(o),n);let i=0;return k(new Promise((n,t)=>{e.forEach((a,s)=>{const c=r.add(a);c.onsuccess=()=>{o[s]=c.result,i++,i===e.length&&n(o)},c.onerror=()=>{var e;return t(null!=(e=c.error)?e:new DOMException("Unknown error"))}})}),n)},clear:e=>k(S(t("readwrite").clear()).then(()=>{}),e),count:e=>k(S(t("readonly").count()),null!=e?e:{})}}(e,n)}(e,n),transaction(n,t,r,o){const i=e.transaction(n,t),a={table:e=>function(e,n){return function(e,n){function t(){return e.objectStore(n)}return{insert:(e,n)=>k(S(t().add(e)),n),update(e,n,r){const o=t();return k(S(o.get(e)).then(e=>{if(void 0===e)throw new DOMException("Key not found","NotFoundError");const t=m({},e,n);return S(o.put(t))}).then(()=>{}),r)},delete:(e,n)=>k(S(t().delete(e)).then(()=>{}),n),exists:e=>S(t().getKey(e)).then(e=>void 0!==e),query(e,n){const r=t().openCursor(),o=[];return k(new Promise((n,t)=>{r.onsuccess=()=>{const t=r.result;t?(e(t.value)&&o.push(t.value),t.continue()):n(o)},r.onerror=()=>{var e;return t(null!=(e=r.error)?e:new DOMException("Unknown error"))}}),n)},upsert:(e,n)=>k(S(t().put(e)),n),bulkInsert(e,n){const r=t(),o=[];if(0===e.length)return k(Promise.resolve(o),n);let i=0;return k(new Promise((n,t)=>{e.forEach((a,s)=>{const c=r.add(a);c.onsuccess=()=>{o[s]=c.result,i++,i===e.length&&n(o)},c.onerror=()=>{var e;return t(null!=(e=c.error)?e:new DOMException("Unknown error"))}})}),n)},clear:e=>k(S(t().clear()).then(()=>{}),e),count:e=>k(S(t().count()),null!=e?e:{})}}(e,n)}(i,e)},s=new Promise((e,n)=>{i.oncomplete=()=>e(),i.onerror=()=>{var e;return n(null!=(e=i.error)?e:new DOMException("Transaction failed"))}}),c=r(a);return function(e,n){return n?e.then(()=>null==n.onSuccess?void 0:n.onSuccess()).catch(e=>{throw null==n.onError||n.onError(e),e}):e}(Promise.resolve(c).then(()=>s),o)}}}(n);i(t),l(!0)}).catch(n=>{e||s(n)}),()=>{e=!0}},[n.name,n.version]),{db:r,isReady:c,error:a}}const L=/\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,I=["stun:stun.l.google.com:19302"],T=3e3;function M(n={}){const{stunServers:r=I,timeout:i=T,onDetect:a}=n,[s,c]=e([]),[l,u]=e(!0),[d,f]=e(null),m=o(null),p=o(null),v=o(new Set),g=o(a);return g.current=a,t(()=>{if("undefined"==typeof window)return u(!1),void f("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return u(!1),void f("RTCPeerConnection is not available");const e=new Set;v.current=e;const n=()=>{p.current&&(clearTimeout(p.current),p.current=null),m.current&&(m.current.close(),m.current=null),u(!1)},t=n=>{e.has(n)||(e.add(n),c(e=>[...e,n]),null==g.current||g.current(n))};try{const e=new RTCPeerConnection({iceServers:[{urls:r}]});m.current=e,e.onicecandidate=e=>{const n=e.candidate;n&&n.candidate&&function(e){const n=e.match(L);return n?[...n]:[]}(n.candidate).forEach(t)},e.createDataChannel(""),e.createOffer().then(n=>e.setLocalDescription(n)).catch(e=>{f(e instanceof Error?e.message:"Failed to create offer"),n()}),p.current=setTimeout(()=>n(),i)}catch(e){f(e instanceof Error?e.message:"WebRTC setup failed"),n()}return()=>{n()}},[r.join(","),i]),{ips:s,loading:l,error:d}}function A(r){const{wasmUrl:i,exportName:a="compute",workerUrl:s,importObject:c}=r,[l,u]=e(void 0),[d,f]=e(!0),[m,p]=e(null),[v,g]=e(!1),h=o(null),w=o(null),y=o(null);return t(()=>{if("undefined"==typeof window)return p("useWasmCompute is not available during SSR"),void f(!1);if("undefined"==typeof Worker)return p("Worker is not supported in this environment"),void f(!1);if("undefined"==typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)return p("WebAssembly is not supported in this environment"),void f(!1);p(null),g(!1);const e=function(e){if(e)return new Worker(e);const 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}(s);h.current=e;const n=e=>{var n;const{type:t,result:r,error:o}=null!=(n=e.data)?n:{};return"ready"===t?(g(!0),void f(!1)):"error"===t?(p(null!=o?o:"Unknown error"),f(!1),void(y.current&&(y.current(new Error(o)),w.current=null,y.current=null))):void("result"===t&&(u(r),f(!1),w.current&&(w.current(r),w.current=null,y.current=null)))};return e.addEventListener("message",n),e.postMessage({type:"init",wasmUrl:i,exportName:a,importObject:null!=c?c:{}}),()=>{e.removeEventListener("message",n),e.terminate(),h.current=null,y.current&&(y.current(new Error("Worker terminated")),w.current=null,y.current=null)}},[i,a,s,c]),{compute:n(e=>new Promise((n,t)=>{h.current&&v?m?t(new Error(m)):(w.current=n,y.current=t,f(!0),h.current.postMessage({type:"compute",input:e})):t(new Error("WASM not ready"))}),[v,m]),result:l,loading:d,error:m,ready:v}}function O(n,i={}){const{maxHistory:a=100,throughputWindowMs:s=1e3}=i,[c,l]=e([]),[u,d]=e(0),[f,m]=e(0),[p,v]=e([]),[g,h]=e(0),w=o([]),y=o(0),b=o(0);t(()=>{if(!n)return;const e=e=>{const n=function(e){if(null==e||"object"!=typeof e)return null;const 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(v(e=>[...e,n].slice(-a)),"task_start"===n.type&&n.taskId)l(e=>e.includes(n.taskId)?e:[...e,n.taskId]);else if("task_end"===n.type){n.taskId&&l(e=>e.filter(e=>e!==n.taskId)),d(e=>e+1);const e=Date.now()-s;w.current=[...w.current.filter(n=>n>=e),n.timestamp],"number"==typeof n.duration&&(y.current+=n.duration,b.current+=1)}else"task_fail"===n.type?(n.taskId&&l(e=>e.filter(e=>e!==n.taskId)),m(e=>e+1)):"queue_size"===n.type&&"number"==typeof n.size&&h(n.size)};return n.addEventListener("message",e),()=>n.removeEventListener("message",e)},[n,a]);const E=r(()=>{const e=b.current;return e>0?y.current/e:0},[p]),S=r(()=>{const e=Date.now()-s;return w.current.filter(n=>n>=e).length/(s/1e3)},[p,s]),k=r(()=>({runningTasks:c,completedCount:u,failedCount:f,averageDurationMs:E,throughputPerSecond:S,currentQueueSize:g,totalProcessed:u+f,recentEventCount:p.length}),[c,u,f,E,S,g,p.length]);return{runningTasks:c,completedCount:u,failedCount:f,eventHistory:p,averageDurationMs:E,throughputPerSecond:S,currentQueueSize:g,progress:k}}function C(e,n){if(null==e)return"";const t=("string"==typeof e?e:String(e)).trim();return t.length>n?t.slice(0,n):t}function P(e){if(!Array.isArray(e))return[];const n=[];for(let t=0;t<e.length&&n.length<50;t++){const r=C(e[t],100);r&&n.push(r)}return n}function D(e){const n=C(e,2048);if(!n)return"";try{const e=new URL(n);if("http:"===e.protocol||"https:"===e.protocol)return n}catch(e){}return""}function j(e){try{if("undefined"==typeof window)return!1;const n=window.getComputedStyle(e);return"none"!==n.display&&"hidden"!==n.visibility&&"0"!==n.opacity}catch(e){return!1}}function U(e){const n={};try{for(const t of Object.keys(e).slice(0,20)){const r=C(t,50);if(!r)continue;const o=e[t];"string"==typeof o?n[r]=o.slice(0,500):"number"==typeof o&&Number.isFinite(o)||"boolean"==typeof o?n[r]=o:Array.isArray(o)&&(n[r]=o.map(e=>C(e,200)).filter(Boolean).slice(0,20))}}catch(e){}return n}function N(){try{if("undefined"==typeof document||!document.querySelectorAll)return;document.querySelectorAll('script[data-llm="true"]').forEach(e=>e.remove())}catch(e){}}function R(e){const n=s(null);c(()=>{try{if("undefined"==typeof window)return;const t=function(e){return null==e||"object"!=typeof e?{route:"/"}:{route:C(e.route,2048)||"/",mode:"auto-extract"===e.mode?"auto-extract":"manual",title:void 0!==e.title?C(e.title,200):void 0,description:void 0!==e.description?C(e.description,2e3):void 0,tags:void 0!==e.tags?P(e.tags):void 0,canonicalUrl:void 0!==e.canonicalUrl?D(e.canonicalUrl):void 0,language:void 0!==e.language?C(e.language,20):void 0,ogType:void 0!==e.ogType?C(e.ogType,50):void 0,ogImage:void 0!==e.ogImage?D(e.ogImage):void 0,ogImageAlt:void 0!==e.ogImageAlt?C(e.ogImageAlt,200):void 0,siteName:void 0!==e.siteName?C(e.siteName,100):void 0,author:void 0!==e.author?C(e.author,200):void 0,publishedTime:void 0!==e.publishedTime?C(e.publishedTime,50):void 0,modifiedTime:void 0!==e.modifiedTime?C(e.modifiedTime,50):void 0,robots:void 0!==e.robots?C(e.robots,100):void 0,extra:void 0===e.extra||"object"!=typeof e.extra||Array.isArray(e.extra)?void 0:U(e.extra)}}(e),r=function(e){try{const r=(new Date).toISOString(),o={route:e.route,generatedAt:r};if("auto-extract"===e.mode){var n,t;const r=function(){const e={title:"",outline:[],description:""};try{if("undefined"==typeof document)return e;const n=C(document.title,200),t=[];let r="";try{const e=document.querySelectorAll("nav, footer, [role='navigation'], [role='contentinfo'], script, style, noscript"),n=n=>{for(const t of e)if(t.contains(n))return!0;return!1},o=document.querySelectorAll("h1, h2");for(const e of o){if(t.length>=50)break;if(j(e)&&!n(e)){const n=C(e.textContent,300);n&&t.push(n)}}const i=document.querySelectorAll("p"),a=[];for(const e of i){if(a.length>=3)break;if(j(e)&&!n(e)){const n=C(e.textContent,1e3);n&&a.push(n)}}r=a.join(" ").trim().slice(0,2e3)||""}catch(e){}return{title:n,outline:t,description:r}}catch(n){return e}}();o.title=(null!=(n=e.title)?n:r.title)||void 0,o.description=(null!=(t=e.description)?t:r.description)||void 0,r.outline.length>0&&(o.outline=r.outline)}else void 0!==e.title&&""!==e.title&&(o.title=e.title),void 0!==e.description&&""!==e.description&&(o.description=e.description);return e.tags&&e.tags.length>0&&(o.tags=e.tags),e.canonicalUrl&&(o.canonicalUrl=e.canonicalUrl),e.language&&(o.language=e.language),e.ogType&&(o.ogType=e.ogType),e.ogImage&&(o.ogImage=e.ogImage),e.ogImageAlt&&(o.ogImageAlt=e.ogImageAlt),e.siteName&&(o.siteName=e.siteName),e.author&&(o.author=e.author),e.publishedTime&&(o.publishedTime=e.publishedTime),e.modifiedTime&&(o.modifiedTime=e.modifiedTime),e.robots&&(o.robots=e.robots),e.extra&&Object.keys(e.extra).length>0&&(o.extra=e.extra),o}catch(n){var r;return{route:null!=(r=null==e?void 0:e.route)?r:"/",generatedAt:(new Date).toISOString()}}}(t),o=JSON.stringify(r);if(n.current===o)return;return n.current=o,N(),function(e){try{if("undefined"==typeof document||!document.head)return;const 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),()=>{N(),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])}const W="use-ref-print-target",q="use-ref-print-styles",z=`\n@media print {\n body * {\n visibility: hidden;\n }\n .${W},\n .${W} * {\n visibility: visible;\n }\n .${W} {\n position: absolute !important;\n left: 0 !important;\n top: 0 !important;\n width: 100% !important;\n }\n}\n`;function _(e,t={}){const{documentTitle:r}=t,i=o("");return{print:n(()=>{const n=e.current;if(!n||"undefined"==typeof window||!window.print)return;let t=document.getElementById(q);t||(t=document.createElement("style"),t.id=q,t.textContent=z,document.head.appendChild(t)),n.classList.add(W),r&&(i.current=document.title,document.title=r);const o=()=>{n.classList.remove(W),r&&void 0!==i.current&&(document.title=i.current)};if("onafterprint"in window){const e=()=>{o(),window.removeEventListener("afterprint",e)};window.addEventListener("afterprint",e)}window.print(),setTimeout(o,1e3)},[e,r])}}function B(e,n){if("undefined"==typeof window)return null;const t="localStorage"===e?window.localStorage:window.sessionStorage;try{const e=t.getItem(n);if(null==e)return null;const r=JSON.parse(e);return r&&"object"==typeof r?r:null}catch(e){return null}}function H(e,n){if("undefined"==typeof window)return[];const t="localStorage"===e?window.localStorage:window.sessionStorage;try{const e=t.getItem(n);if(null==e)return[];const r=JSON.parse(e);return Array.isArray(r)?r.filter(e=>"string"==typeof e):[]}catch(e){return[]}}function V(e,n){return n.filter(n=>n.condition(e)).map(e=>e.role)}function F(e,n){const t=new Set;for(const r of e){const e=n[r];if(Array.isArray(e))for(const n of e)t.add(n)}return Array.from(t)}function J(r){const{userSource:i}=r,a=o(r);a.current=r;const[s,c]=e(null),[l,u]=e([]),[d,f]=e([]),[m,p]=e(!1),[v,g]=e(null),h=n(async()=>{const{userSource:e,roleDefinitions:n,roleCapabilities:t,capabilitiesOverride:r}=a.current;g(null);let o=null,i=[],s=[];try{if("localStorage"===e.type)o=B("localStorage",e.key),i=V(o,n),s=F(i,t);else if("sessionStorage"===e.type)o=B("sessionStorage",e.key),i=V(o,n),s=F(i,t);else if("api"===e.type)o=await e.fetch(),i=V(o,n),s=F(i,t);else if("memory"===e.type)o=e.getUser(),i=V(o,n),s=F(i,t);else if("custom"===e.type){var l,d,m;const r=await Promise.resolve(e.getAuth());o=null!=(l=r.user)?l:null,i=null!=(d=r.roles)?d:V(o,n),s=null!=(m=r.capabilities)?m:F(i,t)}if(r)if("localStorage"===r.type){const e=H("localStorage",r.key);e.length>0&&(s=e)}else if("sessionStorage"===r.type){const e=H("sessionStorage",r.key);e.length>0&&(s=e)}else"api"===r.type&&(s=await r.fetch());c(o),u(i),f(s)}catch(e){g(e instanceof Error?e:new Error(String(e))),c(null),u([]),f([])}finally{p(!0)}},[]);t(()=>{h()},[h]),t(()=>{if("undefined"==typeof window)return;const e="localStorage"===i.type||"sessionStorage"===i.type?i.key:null;if(!e)return;const n=n=>{n.key===e&&h()};return window.addEventListener("storage",n),()=>window.removeEventListener("storage",n)},[i.type,"localStorage"===i.type||"sessionStorage"===i.type?i.key:"",h]);const w=n(e=>l.includes(e),[l]),y=n(e=>function(e,n){return!!e.includes("*")||e.includes(n)}(d,e),[d]),b=y,E=n(()=>h(),[h]),S=n((e,n,t)=>{if("undefined"==typeof window)return;const r="localStorage"===n?window.localStorage:window.sessionStorage;null==e?r.removeItem(t):r.setItem(t,JSON.stringify(e)),("localStorage"===i.type&&"localStorage"===n&&i.key===t||"sessionStorage"===i.type&&"sessionStorage"===n&&i.key===t)&&h()},[i,h]),k=n((e,n,t)=>{"undefined"!=typeof window&&("localStorage"===n?window.localStorage:window.sessionStorage).setItem(t,JSON.stringify(e))},[]),x=n((e,n,t)=>{"undefined"!=typeof window&&("localStorage"===n?window.localStorage:window.sessionStorage).setItem(t,JSON.stringify(e))},[]);return{user:s,roles:l,capabilities:d,isReady:m,error:v,hasRole:w,hasCapability:y,can:b,refetch:E,setUserInStorage:S,setRolesInStorage:k,setCapabilitiesInStorage:x}}function $(){const t=o(new Set),[,r]=e(0);return{prefetch:n((e,n)=>{var o;const i=null==e?void 0:e.trim();i&&(t.current.has(i)||("document"===(null!=(o=null==n?void 0:n.as)?o:"document")?function(e){if("undefined"==typeof document)return;const n=document.querySelectorAll('link[rel="prefetch"]');for(let t=0;t<n.length;t++)if(n[t].href===e)return;const t=document.createElement("link");t.rel="prefetch",t.href=e,document.head.appendChild(t)}(i):function(e){"undefined"!=typeof fetch&&fetch(e,{method:"GET",mode:"cors"}).catch(()=>{})}(i),t.current.add(i),r(e=>e+1)))},[]),isPrefetched:n(e=>{var n;return t.current.has(null!=(n=null==e?void 0:e.trim())?n:"")},[])}}function K(r,i={}){const{intervalMs:a=1e3,immediate:s=!0,enabled:c=!0}=i,[l,u]=e(null),[d,f]=e(!1),[m,p]=e(null),[v,g]=e(0),[h,w]=e(!1),y=o(null),b=o(r);b.current=r;const E=n(()=>{null!=y.current&&(clearInterval(y.current),y.current=null),w(!1)},[]),S=n(async()=>{try{p(null);const e=await b.current();g(e=>e+1),e.done&&(E(),f(!0),void 0!==e.data&&u(e.data))}catch(e){const n=e instanceof Error?e:new Error(String(e));p(n),E()}},[E]),k=n(()=>{c&&!h&&(w(!0),s&&S(),y.current=setInterval(S,a))},[c,s,a,h,S]);return t(()=>(c&&k(),()=>{E()}),[c]),{data:l,done:d,error:m,pollCount:v,start:k,stop:E}}const Q={name:"Unknown",version:""},X={name:"Unknown",version:""},G={userAgent:"",language:"en",languages:["en"],platform:"",browser:Q,os:X,cookieEnabled:!1,online:!0,maxTouchPoints:0,vendor:"",touch:!1,screen:{width:0,height:0,availWidth:0,availHeight:0,colorDepth:24,pixelRatio:1},viewport:{width:0,height:0},reducedMotion:!1,colorScheme:"no-preference"},Y=/not.?a.?brand/i;function Z(e){const n=m({},Q),t=m({},X);if(!e)return{browser:n,os:t};const r=e.match(/Windows NT ([\d.]+)/);if(r)t.name="Windows",t.version=r[1];else{const n=e.match(/Mac OS X ([\d._]+)/);if(n)t.name="macOS",t.version=n[1].replace(/_/g,".");else{const n=e.match(/Android ([\d.]+)/);if(n)t.name="Android",t.version=n[1];else{const n=e.match(/(?:iPhone OS|CPU OS) ([\d_]+)/);if(n)t.name="iOS",t.version=n[1].replace(/_/g,".");else if(/Linux/.test(e)){var o;t.name="Linux";const n=e.match(/Linux ([\d.]+)/);t.version=null!=(o=null==n?void 0:n[1])?o:""}}}}const i=e.match(/Edg(?:A|iOS)?\/([\d.]+)/),a=e.match(/OPR\/([\d.]+)/),s=e.match(/Firefox\/([\d.]+)/),c=/Version\/([\d.]+)/.test(e)&&/Safari/.test(e)&&!/Chrome|Chromium|Edg|OPR/.test(e)?e.match(/Version\/([\d.]+)/):null,l=e.match(/Chrome\/([\d.]+)/);return i?(n.name="Edge",n.version=i[1]):a?(n.name="Opera",n.version=a[1]):s?(n.name="Firefox",n.version=s[1]):c?(n.name="Safari",n.version=c[1]):l&&(n.name="Chrome",n.version=l[1]),{browser:n,os:t}}function ee(e){const n=e.find(e=>!Y.test(e.brand)),t=null!=n?n:e[0];return t?{name:t.brand,version:t.version}:m({},Q)}function ne(){var e,n,t,r,o,i,a,s,c,l,u,d,f,p;if("undefined"==typeof navigator)return G;const v=navigator,g=void 0!==globalThis.screen?globalThis.screen:null,h=void 0!==globalThis.window?globalThis.window:null,w=null!=(e=v.userAgent)?e:"",y=Z(w),b=v.userAgentData,{browser:E,os:S}=b?function(e,n){var t,r;return{browser:null!=(t=e.brands)&&t.length?ee(e.brands):m({},n.browser),os:{name:(null==(r=e.platform)?void 0:r.trim())||n.os.name,version:n.os.version}}}(b,y):y,k={userAgent:w,language:null!=(n=v.language)?n:"",languages:v.languages?[...v.languages]:[],platform:null!=(t=v.platform)?t:"",browser:E,os:S,cookieEnabled:Boolean(v.cookieEnabled),online:Boolean(v.onLine),maxTouchPoints:null!=(r=v.maxTouchPoints)?r:0,vendor:null!=(o=v.vendor)?o:"",touch:(null!=(i=v.maxTouchPoints)?i:0)>0,screen:{width:null!=(a=null==g?void 0:g.width)?a:0,height:null!=(s=null==g?void 0:g.height)?s:0,availWidth:null!=(c=null==g?void 0:g.availWidth)?c:0,availHeight:null!=(l=null==g?void 0:g.availHeight)?l:0,colorDepth:null!=(u=null==g?void 0:g.colorDepth)?u:24,pixelRatio:null!=(d=null==h?void 0:h.devicePixelRatio)?d:1},viewport:{width:null!=(f=null==h?void 0:h.innerWidth)?f:0,height:null!=(p=null==h?void 0:h.innerHeight)?p:0},reducedMotion:!("undefined"==typeof window||!window.matchMedia)&&window.matchMedia("(prefers-reduced-motion: reduce)").matches,colorScheme:"undefined"!=typeof window&&window.matchMedia?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":window.matchMedia("(prefers-color-scheme: light)").matches?"light":"no-preference":"no-preference"};var x;return"number"==typeof v.hardwareConcurrency&&(k.hardwareConcurrency=v.hardwareConcurrency),"number"==typeof v.deviceMemory&&(k.deviceMemory=v.deviceMemory),b&&(k.userAgentData={mobile:Boolean(b.mobile),platform:null!=(x=b.platform)?x:"",brands:b.brands?[...b.brands]:[]}),k}function te(r={}){const{includeBattery:o=!0,batteryPollIntervalMs:i=6e4,includeHighEntropy:a=!0}=r,[s,c]=e(()=>ne()),l=n(()=>{c(e=>m({},ne(),e.battery?{battery:e.battery}:{}))},[]);return t(()=>{if("undefined"==typeof window)return;const e=()=>l();window.addEventListener("resize",e),window.addEventListener("orientationchange",e),window.addEventListener("online",l),window.addEventListener("offline",l);const n=null==window.matchMedia?void 0:window.matchMedia("(prefers-reduced-motion: reduce)"),t=null==window.matchMedia?void 0:window.matchMedia("(prefers-color-scheme: dark)"),r=null==window.matchMedia?void 0:window.matchMedia("(prefers-color-scheme: light)"),o=()=>l();return null==n||null==n.addEventListener||n.addEventListener("change",o),null==t||null==t.addEventListener||t.addEventListener("change",o),null==r||null==r.addEventListener||r.addEventListener("change",o),()=>{window.removeEventListener("resize",e),window.removeEventListener("orientationchange",e),window.removeEventListener("online",l),window.removeEventListener("offline",l),null==n||null==n.removeEventListener||n.removeEventListener("change",o),null==t||null==t.removeEventListener||t.removeEventListener("change",o),null==r||null==r.removeEventListener||r.removeEventListener("change",o)}},[l]),t(()=>{if(!a||"undefined"==typeof navigator)return;const e=navigator.userAgentData;if(null==e||!e.getHighEntropyValues)return;let n=!1;return(async()=>{const t=ne(),r=await async function(e,n){if(e.getHighEntropyValues)try{var t,r;const o=await e.getHighEntropyValues(["platformVersion","fullVersionList"]);return{browser:null!=(t=o.fullVersionList)&&t.length?ee(o.fullVersionList):m({},n.browser),os:{name:n.os.name,version:(null==(r=o.platformVersion)?void 0:r.trim())||n.os.version}}}catch(e){return}}(e,{browser:t.browser,os:t.os});!n&&r&&c(e=>m({},e,{browser:r.browser,os:r.os}))})(),()=>{n=!0}},[a]),t(()=>{if(!o||"undefined"==typeof navigator)return;let e,n=!1;const t=async()=>{const e=await async function(){if("undefined"==typeof navigator)return;const e=navigator.getBattery;if(e)try{const n=await e.call(navigator);return{charging:n.charging,level:n.level}}catch(e){return}}();n||void 0===e||c(n=>m({},n,{battery:e}))};return t(),i>0&&(e=setInterval(()=>{t()},i)),()=>{n=!0,void 0!==e&&clearInterval(e)}},[o,i]),s}export{ne as getDeviceData,Z as parseUserAgent,w as useClipboard,te as useDeviceData,f as useEventBus,x as useIndexedDB,R as useLLMMetadata,u as useMutationObserver,h as useNetworkState,K as usePoll,v as usePreferredTheme,$ as usePrefetch,J as useRBAC,y as useRageClick,_ as useRefPrint,b as useThreadedWorker,l as useTransition,A as useWasmCompute,M as useWebRTCIP,O as useWorkerNotifications,p as useWrappedChildren};
2
2
  //# sourceMappingURL=index.modern.mjs.map