preact-missing-hooks 4.6.0 → 4.8.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 s}from"preact";import{useRef as c,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 c=null==r?void 0:r.style,u=null==t?void 0:t.style;return c&&u&&"object"==typeof c&&"object"==typeof u&&(o.style="override"===n?p({},c,u):p({},u,c)),s(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),[s,c]=e(null),u=t(()=>{i(!1),c(null)},[]);return{copy:t(async e=>{if(c(null),"undefined"==typeof navigator||!navigator.clipboard){const e=new Error("Clipboard API is not available");return c(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 c(t),!1}},[r]),paste:t(async()=>{if(c(null),"undefined"==typeof navigator||!navigator.clipboard){const e=new Error("Clipboard API is not available");return c(e),""}try{return await navigator.clipboard.readText()}catch(e){const t=e instanceof Error?e:new Error(String(e));return c(t),""}},[]),copied:o,error:s,reset:u}}function w(e,t){const{onRageClick:r,threshold:i=5,timeWindow:s=1e3,distanceThreshold:c=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-s,o=a.current.filter(e=>e.time>=r);if(o.push(n),Infinity!==c){const t=o.filter(e=>{return t=e,r=n,Math.hypot(r.x-t.x,r.y-t.y)<=c;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,s,c])}function b(r,i){const{mode:s,concurrency:c=4}=i,u="sequential"===s?1:Math.max(1,c),[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 k=t(()=>{y(v.current.length+w.current)},[]),E=t(()=>{if(b.current)return;if(w.current>=u)return;if(0===v.current.length)return 0===w.current&&l(!1),void k();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),k(),(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,k(),E()}),v.current.length>0&&w.current<u&&E()},[u,k]),x=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 k(),l(!0),queueMicrotask(E),i},[E,k]),I=t(()=>{const e=v.current;v.current=[],e.forEach(e=>e.reject(new Error("Task cleared from queue"))),k(),0===w.current&&l(!1)},[k]),T=t(()=>{b.current=!0,I()},[I]);return n(()=>()=>{b.current=!0},[]),{run:x,loading:a,result:d,error:p,queueSize:g,clearQueue:I,terminate:T}}const S=new Map;function k(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 E(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 x(t){const[r,i]=e(null),[s,c]=e(null),[u,a]=e(!1),l=o(t);return l.current=t,n(()=>{let e=!1;c(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)=>E(k(n("readwrite").add(e)),t),update(e,t,r){const o=n("readwrite");return E(k(o.get(e)).then(e=>{if(void 0===e)throw new DOMException("Key not found","NotFoundError");const n=p({},e,t);return k(o.put(n))}).then(()=>{}),r)},delete:(e,t)=>E(k(n("readwrite").delete(e)).then(()=>{}),t),exists:e=>k(n("readonly").getKey(e)).then(e=>void 0!==e),query(e,t){const r=n("readonly").openCursor(),o=[];return E(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)=>E(k(n("readwrite").put(e)),t),bulkInsert(e,t){const r=n("readwrite"),o=[];if(0===e.length)return E(Promise.resolve(o),t);let i=0;return E(new Promise((t,n)=>{e.forEach((s,c)=>{const u=r.add(s);u.onsuccess=()=>{o[c]=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=>E(k(n("readwrite").clear()).then(()=>{}),e),count:e=>E(k(n("readonly").count()),null!=e?e:{})}}(e,t)}(e,t),transaction(t,n,r,o){const i=e.transaction(t,n),s={table:e=>function(e,t){return function(e,t){function n(){return e.objectStore(t)}return{insert:(e,t)=>E(k(n().add(e)),t),update(e,t,r){const o=n();return E(k(o.get(e)).then(e=>{if(void 0===e)throw new DOMException("Key not found","NotFoundError");const n=p({},e,t);return k(o.put(n))}).then(()=>{}),r)},delete:(e,t)=>E(k(n().delete(e)).then(()=>{}),t),exists:e=>k(n().getKey(e)).then(e=>void 0!==e),query(e,t){const r=n().openCursor(),o=[];return E(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)=>E(k(n().put(e)),t),bulkInsert(e,t){const r=n(),o=[];if(0===e.length)return E(Promise.resolve(o),t);let i=0;return E(new Promise((t,n)=>{e.forEach((s,c)=>{const u=r.add(s);u.onsuccess=()=>{o[c]=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=>E(k(n().clear()).then(()=>{}),e),count:e=>E(k(n().count()),null!=e?e:{})}}(e,t)}(i,e)},c=new Promise((e,t)=>{i.oncomplete=()=>e(),i.onerror=()=>{var e;return t(null!=(e=i.error)?e:new DOMException("Transaction failed"))}}),u=r(s);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(()=>c),o)}}}(t);i(n),a(!0)}).catch(t=>{e||c(t)}),()=>{e=!0}},[t.name,t.version]),{db:r,isReady:u,error:s}}const I=/\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 O(t={}){const{stunServers:r=T,timeout:i=A,onDetect:s}=t,[c,u]=e([]),[a,l]=e(!0),[d,f]=e(null),p=o(null),m=o(null),g=o(new Set),y=o(s);return y.current=s,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(I);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:c,loading:a,error:d}}function M(r){const{wasmUrl:i,exportName:s="compute",workerUrl:c,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}(c);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:s,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,s,c,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:s=100,throughputWindowMs:c=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(-s)),"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()-c;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,s]);const S=r(()=>{const e=b.current;return e>0?w.current/e:0},[m]),k=r(()=>{const e=Date.now()-c;return h.current.filter(t=>t>=e).length/(c/1e3)},[m,c]),E=r(()=>({runningTasks:u,completedCount:l,failedCount:f,averageDurationMs:S,throughputPerSecond:k,currentQueueSize:y,totalProcessed:l+f,recentEventCount:m.length}),[u,l,f,S,k,y,m.length]);return{runningTasks:u,completedCount:l,failedCount:f,eventHistory:m,averageDurationMs:S,throughputPerSecond:k,currentQueueSize:y,progress:E}}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=c(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"),s=[];for(const e of i){if(s.length>=3)break;if(D(e)&&!t(e)){const t=L(e.textContent,1e3);t&&s.push(t)}}r=s.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,s=o(r);s.current=r;const[c,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}=s.current;y(null);let o=null,i=[],c=[];try{if("localStorage"===e.type)o=J("localStorage",e.key),i=F(o,t),c=$(i,n);else if("sessionStorage"===e.type)o=J("sessionStorage",e.key),i=F(o,t),c=$(i,n);else if("api"===e.type)o=await e.fetch(),i=F(o,t),c=$(i,n);else if("memory"===e.type)o=e.getUser(),i=F(o,t),c=$(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),c=null!=(p=r.capabilities)?p:$(i,n)}if(r)if("localStorage"===r.type){const e=B("localStorage",r.key);e.length>0&&(c=e)}else if("sessionStorage"===r.type){const e=B("sessionStorage",r.key);e.length>0&&(c=e)}else"api"===r.type&&(c=await r.fetch());u(o),l(i),f(c)}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]),k=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]),E=t((e,t,n)=>{"undefined"!=typeof window&&("localStorage"===t?window.localStorage:window.sessionStorage).setItem(n,JSON.stringify(e))},[]),x=t((e,t,n)=>{"undefined"!=typeof window&&("localStorage"===t?window.localStorage:window.sessionStorage).setItem(n,JSON.stringify(e))},[]);return{user:c,roles:a,capabilities:d,isReady:p,error:g,hasRole:h,hasCapability:w,can:b,refetch:S,setUserInStorage:k,setRolesInStorage:E,setCapabilitiesInStorage:x}}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:"")},[])}}export{h as useClipboard,f as useEventBus,x as useIndexedDB,q as useLLMMetadata,l as useMutationObserver,v as useNetworkState,g as usePreferredTheme,Q as usePrefetch,K as useRBAC,w as useRageClick,_ as useRefPrint,b as useThreadedWorker,a as useTransition,M as useWasmCompute,O as useWebRTCIP,C as useWorkerNotifications,m as useWrappedChildren};
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 a}from"preact";import{useRef as c,useEffect as l}from"preact/compat";function u(){const[n,r]=e(!1);return[t(e=>{r(!0),Promise.resolve().then(()=>{e(),r(!1)})},[]),n]}function s(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 c=null==r?void 0:r.style,l=null==t?void 0:t.style;return c&&l&&"object"==typeof c&&"object"==typeof l&&(o.style="override"===n?p({},c,l):p({},l,c)),a(e,o)};return Array.isArray(e)?e.map(r):r(e)},[e,t,n])}function v(){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 g(){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 h(){const[t,r]=e(g);return n(()=>{if("undefined"==typeof window)return;const e=()=>r(g());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 w(n={}){const{resetDelay:r=2e3}=n,[o,i]=e(!1),[a,c]=e(null),l=t(()=>{i(!1),c(null)},[]);return{copy:t(async e=>{if(c(null),"undefined"==typeof navigator||!navigator.clipboard){const e=new Error("Clipboard API is not available");return c(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 c(t),!1}},[r]),paste:t(async()=>{if(c(null),"undefined"==typeof navigator||!navigator.clipboard){const e=new Error("Clipboard API is not available");return c(e),""}try{return await navigator.clipboard.readText()}catch(e){const t=e instanceof Error?e:new Error(String(e));return c(t),""}},[]),copied:o,error:a,reset:l}}function y(e,t){const{onRageClick:r,threshold:i=5,timeWindow:a=1e3,distanceThreshold:c=30}=t,l=o(r);l.current=r;const u=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-a,o=u.current.filter(e=>e.time>=r);if(o.push(n),Infinity!==c){const t=o.filter(e=>{return t=e,r=n,Math.hypot(r.x-t.x,r.y-t.y)<=c;var t,r});if(t.length>=i)return l.current({count:t.length,event:e}),void(u.current=[])}else if(o.length>=i)return l.current({count:o.length,event:e}),void(u.current=[]);u.current=o};return t.addEventListener("click",n),()=>t.removeEventListener("click",n)},[e,i,a,c])}function b(r,i){const{mode:a,concurrency:c=4}=i,l="sequential"===a?1:Math.max(1,c),[u,s]=e(!1),[d,f]=e(void 0),[p,m]=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=t(()=>{g(h.current.length+y.current)},[]),k=t(()=>{if(b.current)return;if(y.current>=l)return;if(0===h.current.length)return 0===y.current&&s(!1),void S();h.current.sort((e,t)=>e.priority!==t.priority?e.priority-t.priority:e.sequence-t.sequence);const e=h.current.shift();y.current+=1,s(!0),S(),(0,E.current)(e.data).then(t=>{f(t),m(void 0),e.resolve(t)}).catch(t=>{m(t),e.reject(t)}).finally(()=>{y.current-=1,S(),k()}),h.current.length>0&&y.current<l&&k()},[l,S]),x=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=++w.current,i=new Promise((t,n)=>{h.current.push({data:e,priority:r,sequence:o,resolve:t,reject:n})});return S(),s(!0),queueMicrotask(k),i},[k,S]),I=t(()=>{const e=h.current;h.current=[],e.forEach(e=>e.reject(new Error("Task cleared from queue"))),S(),0===y.current&&s(!1)},[S]),L=t(()=>{b.current=!0,I()},[I]);return n(()=>()=>{b.current=!0},[]),{run:x,loading:u,result:d,error:p,queueSize:v,clearQueue:I,terminate:L}}const E=new Map;function S(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 x(t){const[r,i]=e(null),[a,c]=e(null),[l,u]=e(!1),s=o(t);return s.current=t,n(()=>{let e=!1;c(null),u(!1),i(null);const{name:t,version:n,tables:r}=s.current;return function(e){const t=`${e.name}_v${e.version}`;let n=E.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),E.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(S(n("readwrite").add(e)),t),update(e,t,r){const o=n("readwrite");return k(S(o.get(e)).then(e=>{if(void 0===e)throw new DOMException("Key not found","NotFoundError");const n=p({},e,t);return S(o.put(n))}).then(()=>{}),r)},delete:(e,t)=>k(S(n("readwrite").delete(e)).then(()=>{}),t),exists:e=>S(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(S(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((a,c)=>{const l=r.add(a);l.onsuccess=()=>{o[c]=l.result,i++,i===e.length&&t(o)},l.onerror=()=>{var e;return n(null!=(e=l.error)?e:new DOMException("Unknown error"))}})}),t)},clear:e=>k(S(n("readwrite").clear()).then(()=>{}),e),count:e=>k(S(n("readonly").count()),null!=e?e:{})}}(e,t)}(e,t),transaction(t,n,r,o){const i=e.transaction(t,n),a={table:e=>function(e,t){return function(e,t){function n(){return e.objectStore(t)}return{insert:(e,t)=>k(S(n().add(e)),t),update(e,t,r){const o=n();return k(S(o.get(e)).then(e=>{if(void 0===e)throw new DOMException("Key not found","NotFoundError");const n=p({},e,t);return S(o.put(n))}).then(()=>{}),r)},delete:(e,t)=>k(S(n().delete(e)).then(()=>{}),t),exists:e=>S(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(S(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((a,c)=>{const l=r.add(a);l.onsuccess=()=>{o[c]=l.result,i++,i===e.length&&t(o)},l.onerror=()=>{var e;return n(null!=(e=l.error)?e:new DOMException("Unknown error"))}})}),t)},clear:e=>k(S(n().clear()).then(()=>{}),e),count:e=>k(S(n().count()),null!=e?e:{})}}(e,t)}(i,e)},c=new Promise((e,t)=>{i.oncomplete=()=>e(),i.onerror=()=>{var e;return t(null!=(e=i.error)?e:new DOMException("Transaction failed"))}}),l=r(a);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(l).then(()=>c),o)}}}(t);i(n),u(!0)}).catch(t=>{e||c(t)}),()=>{e=!0}},[t.name,t.version]),{db:r,isReady:l,error:a}}const I=/\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,L=["stun:stun.l.google.com:19302"],T=3e3;function M(t={}){const{stunServers:r=L,timeout:i=T,onDetect:a}=t,[c,l]=e([]),[u,s]=e(!0),[d,f]=e(null),p=o(null),m=o(null),v=o(new Set),g=o(a);return g.current=a,n(()=>{if("undefined"==typeof window)return s(!1),void f("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return s(!1),void f("RTCPeerConnection is not available");const e=new Set;v.current=e;const t=()=>{m.current&&(clearTimeout(m.current),m.current=null),p.current&&(p.current.close(),p.current=null),s(!1)},n=t=>{e.has(t)||(e.add(t),l(e=>[...e,t]),null==g.current||g.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(I);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:c,loading:u,error:d}}function A(r){const{wasmUrl:i,exportName:a="compute",workerUrl:c,importObject:l}=r,[u,s]=e(void 0),[d,f]=e(!0),[p,m]=e(null),[v,g]=e(!1),h=o(null),w=o(null),y=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),g(!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}(c);h.current=e;const t=e=>{var t;const{type:n,result:r,error:o}=null!=(t=e.data)?t:{};return"ready"===n?(g(!0),void f(!1)):"error"===n?(m(null!=o?o:"Unknown error"),f(!1),void(y.current&&(y.current(new Error(o)),w.current=null,y.current=null))):void("result"===n&&(s(r),f(!1),w.current&&(w.current(r),w.current=null,y.current=null)))};return e.addEventListener("message",t),e.postMessage({type:"init",wasmUrl:i,exportName:a,importObject:null!=l?l:{}}),()=>{e.removeEventListener("message",t),e.terminate(),h.current=null,y.current&&(y.current(new Error("Worker terminated")),w.current=null,y.current=null)}},[i,a,c,l]),{compute:t(e=>new Promise((t,n)=>{h.current&&v?p?n(new Error(p)):(w.current=t,y.current=n,f(!0),h.current.postMessage({type:"compute",input:e})):n(new Error("WASM not ready"))}),[v,p]),result:u,loading:d,error:p,ready:v}}function C(t,i={}){const{maxHistory:a=100,throughputWindowMs:c=1e3}=i,[l,u]=e([]),[s,d]=e(0),[f,p]=e(0),[m,v]=e([]),[g,h]=e(0),w=o([]),y=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(v(e=>[...e,t].slice(-a)),"task_start"===t.type&&t.taskId)u(e=>e.includes(t.taskId)?e:[...e,t.taskId]);else if("task_end"===t.type){t.taskId&&u(e=>e.filter(e=>e!==t.taskId)),d(e=>e+1);const e=Date.now()-c;w.current=[...w.current.filter(t=>t>=e),t.timestamp],"number"==typeof t.duration&&(y.current+=t.duration,b.current+=1)}else"task_fail"===t.type?(t.taskId&&u(e=>e.filter(e=>e!==t.taskId)),p(e=>e+1)):"queue_size"===t.type&&"number"==typeof t.size&&h(t.size)};return t.addEventListener("message",e),()=>t.removeEventListener("message",e)},[t,a]);const E=r(()=>{const e=b.current;return e>0?y.current/e:0},[m]),S=r(()=>{const e=Date.now()-c;return w.current.filter(t=>t>=e).length/(c/1e3)},[m,c]),k=r(()=>({runningTasks:l,completedCount:s,failedCount:f,averageDurationMs:E,throughputPerSecond:S,currentQueueSize:g,totalProcessed:s+f,recentEventCount:m.length}),[l,s,f,E,S,g,m.length]);return{runningTasks:l,completedCount:s,failedCount:f,eventHistory:m,averageDurationMs:E,throughputPerSecond:S,currentQueueSize:g,progress:k}}function P(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 O(e){if(!Array.isArray(e))return[];const t=[];for(let n=0;n<e.length&&t.length<50;n++){const r=P(e[n],100);r&&t.push(r)}return t}function D(e){const t=P(e,2048);if(!t)return"";try{const e=new URL(t);if("http:"===e.protocol||"https:"===e.protocol)return t}catch(e){}return""}function j(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=P(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=>P(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 R(e){const t=c(null);l(()=>{try{if("undefined"==typeof window)return;const n=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?O(e.tags):void 0,canonicalUrl:void 0!==e.canonicalUrl?D(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?D(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: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=P(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(j(e)&&!t(e)){const t=P(e.textContent,300);t&&n.push(t)}}const i=document.querySelectorAll("p"),a=[];for(const e of i){if(a.length>=3)break;if(j(e)&&!t(e)){const t=P(e.textContent,1e3);t&&a.push(t)}}r=a.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 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 B(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(q);n||(n=document.createElement("style"),n.id=q,n.textContent=z,document.head.appendChild(n)),t.classList.add(W),r&&(i.current=document.title,document.title=r);const o=()=>{t.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 _(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 J(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 H(e,t){return t.filter(t=>t.condition(e)).map(e=>e.role)}function F(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 $(r){const{userSource:i}=r,a=o(r);a.current=r;const[c,l]=e(null),[u,s]=e([]),[d,f]=e([]),[p,m]=e(!1),[v,g]=e(null),h=t(async()=>{const{userSource:e,roleDefinitions:t,roleCapabilities:n,capabilitiesOverride:r}=a.current;g(null);let o=null,i=[],c=[];try{if("localStorage"===e.type)o=_("localStorage",e.key),i=H(o,t),c=F(i,n);else if("sessionStorage"===e.type)o=_("sessionStorage",e.key),i=H(o,t),c=F(i,n);else if("api"===e.type)o=await e.fetch(),i=H(o,t),c=F(i,n);else if("memory"===e.type)o=e.getUser(),i=H(o,t),c=F(i,n);else if("custom"===e.type){var u,d,p;const r=await Promise.resolve(e.getAuth());o=null!=(u=r.user)?u:null,i=null!=(d=r.roles)?d:H(o,t),c=null!=(p=r.capabilities)?p:F(i,n)}if(r)if("localStorage"===r.type){const e=J("localStorage",r.key);e.length>0&&(c=e)}else if("sessionStorage"===r.type){const e=J("sessionStorage",r.key);e.length>0&&(c=e)}else"api"===r.type&&(c=await r.fetch());l(o),s(i),f(c)}catch(e){g(e instanceof Error?e:new Error(String(e))),l(null),s([]),f([])}finally{m(!0)}},[]);n(()=>{h()},[h]),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&&h()};return window.addEventListener("storage",t),()=>window.removeEventListener("storage",t)},[i.type,"localStorage"===i.type||"sessionStorage"===i.type?i.key:"",h]);const w=t(e=>u.includes(e),[u]),y=t(e=>function(e,t){return!!e.includes("*")||e.includes(t)}(d,e),[d]),b=y,E=t(()=>h(),[h]),S=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)&&h()},[i,h]),k=t((e,t,n)=>{"undefined"!=typeof window&&("localStorage"===t?window.localStorage:window.sessionStorage).setItem(n,JSON.stringify(e))},[]),x=t((e,t,n)=>{"undefined"!=typeof window&&("localStorage"===t?window.localStorage:window.sessionStorage).setItem(n,JSON.stringify(e))},[]);return{user:c,roles:u,capabilities:d,isReady:p,error:v,hasRole:w,hasCapability:y,can:b,refetch:E,setUserInStorage:S,setRolesInStorage:k,setCapabilitiesInStorage:x}}function K(){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 Q(r,i={}){const{intervalMs:a=1e3,immediate:c=!0,enabled:l=!0}=i,[u,s]=e(null),[d,f]=e(!1),[p,m]=e(null),[v,g]=e(0),[h,w]=e(!1),y=o(null),b=o(r);b.current=r;const E=t(()=>{null!=y.current&&(clearInterval(y.current),y.current=null),w(!1)},[]),S=t(async()=>{try{m(null);const e=await b.current();g(e=>e+1),e.done&&(E(),f(!0),void 0!==e.data&&s(e.data))}catch(e){const t=e instanceof Error?e:new Error(String(e));m(t),E()}},[E]),k=t(()=>{l&&!h&&(w(!0),c&&S(),y.current=setInterval(S,a))},[l,c,a,h,S]);return n(()=>(l&&k(),()=>{E()}),[l]),{data:u,done:d,error:p,pollCount:v,start:k,stop:E}}const G={userAgent:"",language:"en",languages:["en"],platform:"",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"};function X(){var e,t,n,r,o,i,a,c,l,u,s,d,f,p;if("undefined"==typeof navigator)return G;const m=navigator,v=void 0!==globalThis.screen?globalThis.screen:null,g=void 0!==globalThis.window?globalThis.window:null,h={userAgent:null!=(e=m.userAgent)?e:"",language:null!=(t=m.language)?t:"",languages:m.languages?[...m.languages]:[],platform:null!=(n=m.platform)?n:"",cookieEnabled:Boolean(m.cookieEnabled),online:Boolean(m.onLine),maxTouchPoints:null!=(r=m.maxTouchPoints)?r:0,vendor:null!=(o=m.vendor)?o:"",touch:(null!=(i=m.maxTouchPoints)?i:0)>0,screen:{width:null!=(a=null==v?void 0:v.width)?a:0,height:null!=(c=null==v?void 0:v.height)?c:0,availWidth:null!=(l=null==v?void 0:v.availWidth)?l:0,availHeight:null!=(u=null==v?void 0:v.availHeight)?u:0,colorDepth:null!=(s=null==v?void 0:v.colorDepth)?s:24,pixelRatio:null!=(d=null==g?void 0:g.devicePixelRatio)?d:1},viewport:{width:null!=(f=null==g?void 0:g.innerWidth)?f:0,height:null!=(p=null==g?void 0:g.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"};"number"==typeof m.hardwareConcurrency&&(h.hardwareConcurrency=m.hardwareConcurrency),"number"==typeof m.deviceMemory&&(h.deviceMemory=m.deviceMemory);const w=m.userAgentData;var y;return w&&(h.userAgentData={mobile:Boolean(w.mobile),platform:null!=(y=w.platform)?y:"",brands:w.brands?[...w.brands]:[]}),h}function Y(r={}){const{includeBattery:o=!0,batteryPollIntervalMs:i=6e4}=r,[a,c]=e(()=>X()),l=t(()=>{c(e=>{const t=X();return e.battery?p({},t,{battery:e.battery}):t})},[]);return n(()=>{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 t=null==window.matchMedia?void 0:window.matchMedia("(prefers-reduced-motion: reduce)"),n=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==t||null==t.addEventListener||t.addEventListener("change",o),null==n||null==n.addEventListener||n.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==t||null==t.removeEventListener||t.removeEventListener("change",o),null==n||null==n.removeEventListener||n.removeEventListener("change",o),null==r||null==r.removeEventListener||r.removeEventListener("change",o)}},[l]),n(()=>{if(!o||"undefined"==typeof navigator)return;let e,t=!1;const n=async()=>{const e=await async function(){if("undefined"==typeof navigator)return;const e=navigator.getBattery;if(e)try{const t=await e.call(navigator);return{charging:t.charging,level:t.level}}catch(e){return}}();t||void 0===e||c(t=>p({},t,{battery:e}))};return n(),i>0&&(e=setInterval(()=>{n()},i)),()=>{t=!0,void 0!==e&&clearInterval(e)}},[o,i]),a}export{X as getDeviceData,w as useClipboard,Y as useDeviceData,f as useEventBus,x as useIndexedDB,R as useLLMMetadata,s as useMutationObserver,h as useNetworkState,Q as usePoll,v as usePreferredTheme,K as usePrefetch,$ as useRBAC,y as useRageClick,B as useRefPrint,b as useThreadedWorker,u as useTransition,A as useWasmCompute,M as useWebRTCIP,C as useWorkerNotifications,m as useWrappedChildren};
2
2
  //# sourceMappingURL=index.modern.mjs.map