preact-missing-hooks 4.6.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- import{useState as e,useCallback as n,useEffect as r,useMemo as t,useRef as o}from"preact/hooks";import{isValidElement as i,cloneElement as u}from"preact";import{useRef as a,useEffect as c}from"preact/compat";function l(){var r=e(!1),t=r[0],o=r[1];return[n(function(e){o(!0),Promise.resolve().then(function(){e(),o(!1)})},[]),t]}function s(e,n,t){r(function(){var r=e.current;if(r){var o=new MutationObserver(n);return o.observe(r,t),function(){return o.disconnect()}}},[e,n,t])}var f=new Map;function d(){var e=n(function(e){var n=arguments,r=f.get(e);r&&r.forEach(function(e){return e.apply(void 0,[].slice.call(n,1))})},[]);return{emit:e,on:n(function(e,n){var r=f.get(e);return r||(r=new Set,f.set(e,r)),r.add(n),function(){r.delete(n),0===r.size&&f.delete(e)}},[])}}function v(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=Array(n);r<n;r++)t[r]=e[r];return t}function p(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return v(e,n);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function m(){return m=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)({}).hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},m.apply(null,arguments)}function h(e,n,r){return void 0===r&&(r="preserve"),t(function(){if(!e)return e;var t=function(e){if(!i(e))return e;var t,o=e.props||{};t="override"===r?m({},o,n):m({},n,o);var a=null==o?void 0:o.style,c=null==n?void 0:n.style;return a&&c&&"object"==typeof a&&"object"==typeof c&&(t.style="override"===r?m({},a,c):m({},c,a)),u(e,t)};return Array.isArray(e)?e.map(t):t(e)},[e,n,r])}function g(){var n=e(function(){if("undefined"==typeof window)return"no-preference";var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");return e.matches?"dark":n.matches?"light":"no-preference"}),t=n[0],o=n[1];return r(function(){if("undefined"!=typeof window){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=function(e){o(e.matches?"dark":"light")},r=function(){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");o(e.matches?"dark":n.matches?"light":"no-preference")};e.addEventListener("change",n);var t=window.matchMedia("(prefers-color-scheme: light)");return t.addEventListener("change",r),function(){e.removeEventListener("change",n),t.removeEventListener("change",r)}}},[]),t}function y(){if("undefined"==typeof navigator)return{online:!0};var e={online:navigator.onLine},n=navigator.connection;return n&&(void 0!==n.effectiveType&&(e.effectiveType=n.effectiveType),void 0!==n.downlink&&(e.downlink=n.downlink),void 0!==n.rtt&&(e.rtt=n.rtt),void 0!==n.saveData&&(e.saveData=n.saveData),void 0!==n.type&&(e.connectionType=n.type)),e}function w(){var n=e(y),t=n[0],o=n[1];return r(function(){if("undefined"!=typeof window){var e=function(){return o(y())};window.addEventListener("online",e),window.addEventListener("offline",e);var n=navigator.connection;return null!=n&&n.addEventListener&&n.addEventListener("change",e),function(){window.removeEventListener("online",e),window.removeEventListener("offline",e),null!=n&&n.removeEventListener&&n.removeEventListener("change",e)}}},[]),t}function b(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}function S(r){void 0===r&&(r={});var t=r.resetDelay,o=void 0===t?2e3:t,i=e(!1),u=i[0],a=i[1],c=e(null),l=c[0],s=c[1],f=n(function(){a(!1),s(null)},[]);return{copy:n(function(e){try{if(s(null),"undefined"==typeof navigator||!navigator.clipboard){var n=new Error("Clipboard API is not available");return s(n),Promise.resolve(!1)}return Promise.resolve(b(function(){return Promise.resolve(navigator.clipboard.writeText(e)).then(function(){return a(!0),o>0&&setTimeout(function(){return a(!1)},o),!0})},function(e){var n=e instanceof Error?e:new Error(String(e));return s(n),!1}))}catch(e){return Promise.reject(e)}},[o]),paste:n(function(){try{if(s(null),"undefined"==typeof navigator||!navigator.clipboard){var e=new Error("Clipboard API is not available");return s(e),Promise.resolve("")}return Promise.resolve(b(function(){return Promise.resolve(navigator.clipboard.readText())},function(e){var n=e instanceof Error?e:new Error(String(e));return s(n),""}))}catch(e){return Promise.reject(e)}},[]),copied:u,error:l,reset:f}}function E(e,n){var t=n.onRageClick,i=n.threshold,u=void 0===i?5:i,a=n.timeWindow,c=void 0===a?1e3:a,l=n.distanceThreshold,s=void 0===l?30:l,f=o(t);f.current=t;var d=o([]);r(function(){var n=e.current;if(n){var r=function(e){var n=Date.now(),r={time:n,x:e.clientX,y:e.clientY},t=n-c,o=d.current.filter(function(e){return e.time>=t});if(o.push(r),Infinity!==s){var i=o.filter(function(e){return n=e,t=r,Math.hypot(t.x-n.x,t.y-n.y)<=s;var n,t});if(i.length>=u)return f.current({count:i.length,event:e}),void(d.current=[])}else if(o.length>=u)return f.current({count:o.length,event:e}),void(d.current=[]);d.current=o};return n.addEventListener("click",r),function(){return n.removeEventListener("click",r)}}},[e,u,c,s])}function k(t,i){var u=i.concurrency,a="sequential"===i.mode?1:Math.max(1,void 0===u?4:u),c=e(!1),l=c[0],s=c[1],f=e(void 0),d=f[0],v=f[1],p=e(void 0),m=p[0],h=p[1],g=e(0),y=g[0],w=g[1],b=o([]),S=o(0),E=o(0),k=o(!1),I=o(t);I.current=t;var x=n(function(){w(b.current.length+E.current)},[]),T=n(function(){if(!(k.current||E.current>=a)){if(0===b.current.length)return 0===E.current&&s(!1),void x();b.current.sort(function(e,n){return e.priority!==n.priority?e.priority-n.priority:e.sequence-n.sequence});var e=b.current.shift();E.current+=1,s(!0),x(),(0,I.current)(e.data).then(function(n){v(n),h(void 0),e.resolve(n)}).catch(function(n){h(n),e.reject(n)}).finally(function(){E.current-=1,x(),T()}),b.current.length>0&&E.current<a&&T()}},[a,x]),A=n(function(e,n){var r;if(k.current)return Promise.reject(new Error("Worker is terminated"));var t=null!=(r=null==n?void 0:n.priority)?r:1,o=++S.current,i=new Promise(function(n,r){b.current.push({data:e,priority:t,sequence:o,resolve:n,reject:r})});return x(),s(!0),queueMicrotask(T),i},[T,x]),P=n(function(){var e=b.current;b.current=[],e.forEach(function(e){return e.reject(new Error("Task cleared from queue"))}),x(),0===E.current&&s(!1)},[x]),j=n(function(){k.current=!0,P()},[P]);return r(function(){return function(){k.current=!0}},[]),{run:A,loading:l,result:d,error:m,queueSize:y,clearQueue:P,terminate:j}}var I=new Map;function x(e){return new Promise(function(n,r){e.onsuccess=function(){return n(e.result)},e.onerror=function(){var n;return r(null!=(n=e.error)?n:new DOMException("Unknown IndexedDB error"))}})}function T(e,n){return n?e.then(function(e){return null==n.onSuccess||n.onSuccess(e),e}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}function A(n){var t=e(null),i=t[0],u=t[1],a=e(null),c=a[0],l=a[1],s=e(!1),f=s[0],d=s[1],v=o(n);return v.current=n,r(function(){var e=!1;l(null),d(!1),u(null);var n=v.current;return function(e){var n=e.name+"_v"+e.version,r=I.get(n);return r||(r=function(e){return new Promise(function(n,r){var t=indexedDB.open(e.name,e.version);t.onerror=function(){var e;return r(null!=(e=t.error)?e:new DOMException("Failed to open database"))},t.onsuccess=function(){return n(t.result)},t.onupgradeneeded=function(n){for(var r=n.target.result,t=e.tables,o=0,i=Object.keys(t);o<i.length;o++){var u=i[o],a=t[u];if(!r.objectStoreNames.contains(u)){var c,l=r.createObjectStore(u,{keyPath:a.keyPath,autoIncrement:null!=(c=a.autoIncrement)&&c});if(a.indexes)for(var s,f=p(a.indexes);!(s=f()).done;){var d=s.value;l.createIndex(d,d,{unique:!1})}}}}})}(e),I.set(n,r),r)}({name:n.name,version:n.version,tables:n.tables}).then(function(n){if(e)n.close();else{var r=function(e){return{get db(){return e},hasTable:function(n){return e.objectStoreNames.contains(n)},table:function(n){return function(e,n){return function(e,n){function r(r){return e.transaction([n],r).objectStore(n)}return{insert:function(e,n){return T(x(r("readwrite").add(e)),n)},update:function(e,n,t){var o=r("readwrite");return T(x(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=m({},e,n);return x(o.put(r))}).then(function(){}),t)},delete:function(e,n){return T(x(r("readwrite").delete(e)).then(function(){}),n)},exists:function(e){return x(r("readonly").getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r("readonly").openCursor(),o=[];return T(new Promise(function(n,r){t.onsuccess=function(){var r=t.result;r?(e(r.value)&&o.push(r.value),r.continue()):n(o)},t.onerror=function(){var e;return r(null!=(e=t.error)?e:new DOMException("Unknown error"))}}),n)},upsert:function(e,n){return T(x(r("readwrite").put(e)),n)},bulkInsert:function(e,n){var t=r("readwrite"),o=[];if(0===e.length)return T(Promise.resolve(o),n);var i=0;return T(new Promise(function(n,r){e.forEach(function(u,a){var c=t.add(u);c.onsuccess=function(){o[a]=c.result,++i===e.length&&n(o)},c.onerror=function(){var e;return r(null!=(e=c.error)?e:new DOMException("Unknown error"))}})}),n)},clear:function(e){return T(x(r("readwrite").clear()).then(function(){}),e)},count:function(e){return T(x(r("readonly").count()),null!=e?e:{})}}}(e,n)}(e,n)},transaction:function(n,r,t,o){var i=e.transaction(n,r),u={table:function(e){return function(e,n){return function(e,n){function r(){return e.objectStore(n)}return{insert:function(e,n){return T(x(r().add(e)),n)},update:function(e,n,t){var o=r();return T(x(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=m({},e,n);return x(o.put(r))}).then(function(){}),t)},delete:function(e,n){return T(x(r().delete(e)).then(function(){}),n)},exists:function(e){return x(r().getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r().openCursor(),o=[];return T(new Promise(function(n,r){t.onsuccess=function(){var r=t.result;r?(e(r.value)&&o.push(r.value),r.continue()):n(o)},t.onerror=function(){var e;return r(null!=(e=t.error)?e:new DOMException("Unknown error"))}}),n)},upsert:function(e,n){return T(x(r().put(e)),n)},bulkInsert:function(e,n){var t=r(),o=[];if(0===e.length)return T(Promise.resolve(o),n);var i=0;return T(new Promise(function(n,r){e.forEach(function(u,a){var c=t.add(u);c.onsuccess=function(){o[a]=c.result,++i===e.length&&n(o)},c.onerror=function(){var e;return r(null!=(e=c.error)?e:new DOMException("Unknown error"))}})}),n)},clear:function(e){return T(x(r().clear()).then(function(){}),e)},count:function(e){return T(x(r().count()),null!=e?e:{})}}}(e,n)}(i,e)}},a=new Promise(function(e,n){i.oncomplete=function(){return e()},i.onerror=function(){var e;return n(null!=(e=i.error)?e:new DOMException("Transaction failed"))}}),c=t(u);return function(e,n){return n?e.then(function(){return null==n.onSuccess?void 0:n.onSuccess()}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}(Promise.resolve(c).then(function(){return a}),o)}}}(n);u(r),d(!0)}}).catch(function(n){e||l(n)}),function(){e=!0}},[n.name,n.version]),{db:i,isReady:f,error:c}}var P=/\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,j=["stun:stun.l.google.com:19302"];function O(n){void 0===n&&(n={});var t=n.stunServers,i=void 0===t?j:t,u=n.timeout,a=void 0===u?3e3:u,c=n.onDetect,l=e([]),s=l[0],f=l[1],d=e(!0),v=d[0],p=d[1],m=e(null),h=m[0],g=m[1],y=o(null),w=o(null),b=o(new Set),S=o(c);return S.current=c,r(function(){if("undefined"==typeof window)return p(!1),void g("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return p(!1),void g("RTCPeerConnection is not available");var e=new Set;b.current=e;var n=function(){w.current&&(clearTimeout(w.current),w.current=null),y.current&&(y.current.close(),y.current=null),p(!1)},r=function(n){e.has(n)||(e.add(n),f(function(e){return[].concat(e,[n])}),null==S.current||S.current(n))};try{var t=new RTCPeerConnection({iceServers:[{urls:i}]});y.current=t,t.onicecandidate=function(e){var n,t=e.candidate;t&&t.candidate&&((n=t.candidate.match(P))?[].concat(n):[]).forEach(r)},t.createDataChannel(""),t.createOffer().then(function(e){return t.setLocalDescription(e)}).catch(function(e){g(e instanceof Error?e.message:"Failed to create offer"),n()}),w.current=setTimeout(function(){return n()},a)}catch(e){g(e instanceof Error?e.message:"WebRTC setup failed"),n()}return function(){n()}},[i.join(","),a]),{ips:s,loading:v,error:h}}function M(t){var i=t.wasmUrl,u=t.exportName,a=void 0===u?"compute":u,c=t.workerUrl,l=t.importObject,s=e(void 0),f=s[0],d=s[1],v=e(!0),p=v[0],m=v[1],h=e(null),g=h[0],y=h[1],w=e(!1),b=w[0],S=w[1],E=o(null),k=o(null),I=o(null);return r(function(){if("undefined"==typeof window)return y("useWasmCompute is not available during SSR"),void m(!1);if("undefined"==typeof Worker)return y("Worker is not supported in this environment"),void m(!1);if("undefined"==typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)return y("WebAssembly is not supported in this environment"),void m(!1);y(null),S(!1);var e=function(e){if(e)return new Worker(e);var n=new Blob(["\nself.onmessage = async (e) => {\n const d = e.data;\n if (d.type === 'init') {\n try {\n const res = await fetch(d.wasmUrl);\n const buf = await res.arrayBuffer();\n const mod = await WebAssembly.instantiate(buf, d.importObject || {});\n self.wasmInstance = mod.instance;\n self.exportName = d.exportName || 'compute';\n self.postMessage({ type: 'ready' });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n return;\n }\n if (d.type === 'compute') {\n try {\n const fn = self.wasmInstance.exports[self.exportName];\n if (typeof fn !== 'function') {\n self.postMessage({ type: 'error', error: 'Export \"' + self.exportName + '\" is not a function' });\n return;\n }\n const result = fn(d.input);\n self.postMessage({ type: 'result', result: result });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n }\n};\n"],{type:"application/javascript"}),r=URL.createObjectURL(n),t=new Worker(r);return URL.revokeObjectURL(r),t}(c);E.current=e;var n=function(e){var n,r=null!=(n=e.data)?n:{},t=r.type,o=r.result,i=r.error;return"ready"===t?(S(!0),void m(!1)):"error"===t?(y(null!=i?i:"Unknown error"),m(!1),void(I.current&&(I.current(new Error(i)),k.current=null,I.current=null))):void("result"===t&&(d(o),m(!1),k.current&&(k.current(o),k.current=null,I.current=null)))};return e.addEventListener("message",n),e.postMessage({type:"init",wasmUrl:i,exportName:a,importObject:null!=l?l:{}}),function(){e.removeEventListener("message",n),e.terminate(),E.current=null,I.current&&(I.current(new Error("Worker terminated")),k.current=null,I.current=null)}},[i,a,c,l]),{compute:n(function(e){return new Promise(function(n,r){E.current&&b?g?r(new Error(g)):(k.current=n,I.current=r,m(!0),E.current.postMessage({type:"compute",input:e})):r(new Error("WASM not ready"))})},[b,g]),result:f,loading:p,error:g,ready:b}}function C(n,i){void 0===i&&(i={});var u=i.maxHistory,a=void 0===u?100:u,c=i.throughputWindowMs,l=void 0===c?1e3:c,s=e([]),f=s[0],d=s[1],v=e(0),p=v[0],m=v[1],h=e(0),g=h[0],y=h[1],w=e([]),b=w[0],S=w[1],E=e(0),k=E[0],I=E[1],x=o([]),T=o(0),A=o(0);r(function(){if(n){var e=function(e){var n=function(e){if(null==e||"object"!=typeof e)return null;var n=e.type;return"task_start"!==n&&"task_end"!==n&&"task_fail"!==n&&"queue_size"!==n?null:{type:n,taskId:"string"==typeof e.taskId?e.taskId:void 0,duration:"number"==typeof e.duration?e.duration:void 0,error:"string"==typeof e.error?e.error:void 0,size:"number"==typeof e.size?e.size:void 0,timestamp:Date.now()}}(e.data);if(n)if(S(function(e){return[].concat(e,[n]).slice(-a)}),"task_start"===n.type&&n.taskId)d(function(e){return e.includes(n.taskId)?e:[].concat(e,[n.taskId])});else if("task_end"===n.type){n.taskId&&d(function(e){return e.filter(function(e){return e!==n.taskId})}),m(function(e){return e+1});var r=Date.now()-l;x.current=[].concat(x.current.filter(function(e){return e>=r}),[n.timestamp]),"number"==typeof n.duration&&(T.current+=n.duration,A.current+=1)}else"task_fail"===n.type?(n.taskId&&d(function(e){return e.filter(function(e){return e!==n.taskId})}),y(function(e){return e+1})):"queue_size"===n.type&&"number"==typeof n.size&&I(n.size)};return n.addEventListener("message",e),function(){return n.removeEventListener("message",e)}}},[n,a]);var P=t(function(){var e=A.current;return e>0?T.current/e:0},[b]),j=t(function(){var e=Date.now()-l;return x.current.filter(function(n){return n>=e}).length/(l/1e3)},[b,l]),O=t(function(){return{runningTasks:f,completedCount:p,failedCount:g,averageDurationMs:P,throughputPerSecond:j,currentQueueSize:k,totalProcessed:p+g,recentEventCount:b.length}},[f,p,g,P,j,k,b.length]);return{runningTasks:f,completedCount:p,failedCount:g,eventHistory:b,averageDurationMs:P,throughputPerSecond:j,currentQueueSize:k,progress:O}}function L(e,n){if(null==e)return"";var r=("string"==typeof e?e:String(e)).trim();return r.length>n?r.slice(0,n):r}function D(e){if(!Array.isArray(e))return[];for(var n=[],r=0;r<e.length&&n.length<50;r++){var t=L(e[r],100);t&&n.push(t)}return n}function N(e){var n=L(e,2048);if(!n)return"";try{var r=new URL(n);if("http:"===r.protocol||"https:"===r.protocol)return n}catch(e){}return""}function U(e){try{if("undefined"==typeof window)return!1;var n=window.getComputedStyle(e);return"none"!==n.display&&"hidden"!==n.visibility&&"0"!==n.opacity}catch(e){return!1}}function q(e){var n={};try{for(var r,t=p(Object.keys(e).slice(0,20));!(r=t()).done;){var o=r.value,i=L(o,50);if(i){var u=e[o];"string"==typeof u?n[i]=u.slice(0,500):"number"==typeof u&&Number.isFinite(u)||"boolean"==typeof u?n[i]=u:Array.isArray(u)&&(n[i]=u.map(function(e){return L(e,200)}).filter(Boolean).slice(0,20))}}}catch(e){}return n}function R(){try{if("undefined"==typeof document||!document.querySelectorAll)return;document.querySelectorAll('script[data-llm="true"]').forEach(function(e){return e.remove()})}catch(e){}}function W(e){var n=a(null);c(function(){try{if("undefined"==typeof window)return;var r=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?D(e.tags):void 0,canonicalUrl:void 0!==e.canonicalUrl?N(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?N(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:q(e.extra)}}(e),t=function(e){try{var n=(new Date).toISOString(),r={route:e.route,generatedAt:n};if("auto-extract"===e.mode){var t,o,i=function(){var e={title:"",outline:[],description:""};try{if("undefined"==typeof document)return e;var n=L(document.title,200),r=[],t="";try{for(var o,i=document.querySelectorAll("nav, footer, [role='navigation'], [role='contentinfo'], script, style, noscript"),u=function(e){for(var n,r=p(i);!(n=r()).done;)if(n.value.contains(e))return!0;return!1},a=p(document.querySelectorAll("h1, h2"));!(o=a()).done;){var c=o.value;if(r.length>=50)break;if(U(c)&&!u(c)){var l=L(c.textContent,300);l&&r.push(l)}}for(var s,f=document.querySelectorAll("p"),d=[],v=p(f);!(s=v()).done;){var m=s.value;if(d.length>=3)break;if(U(m)&&!u(m)){var h=L(m.textContent,1e3);h&&d.push(h)}}t=d.join(" ").trim().slice(0,2e3)||""}catch(e){}return{title:n,outline:r,description:t}}catch(n){return e}}();r.title=(null!=(t=e.title)?t:i.title)||void 0,r.description=(null!=(o=e.description)?o:i.description)||void 0,i.outline.length>0&&(r.outline=i.outline)}else void 0!==e.title&&""!==e.title&&(r.title=e.title),void 0!==e.description&&""!==e.description&&(r.description=e.description);return e.tags&&e.tags.length>0&&(r.tags=e.tags),e.canonicalUrl&&(r.canonicalUrl=e.canonicalUrl),e.language&&(r.language=e.language),e.ogType&&(r.ogType=e.ogType),e.ogImage&&(r.ogImage=e.ogImage),e.ogImageAlt&&(r.ogImageAlt=e.ogImageAlt),e.siteName&&(r.siteName=e.siteName),e.author&&(r.author=e.author),e.publishedTime&&(r.publishedTime=e.publishedTime),e.modifiedTime&&(r.modifiedTime=e.modifiedTime),e.robots&&(r.robots=e.robots),e.extra&&Object.keys(e.extra).length>0&&(r.extra=e.extra),r}catch(n){var u;return{route:null!=(u=null==e?void 0:e.route)?u:"/",generatedAt:(new Date).toISOString()}}}(r),o=JSON.stringify(t);if(n.current===o)return;return n.current=o,R(),function(e){try{if("undefined"==typeof document||!document.head)return;var n=document.createElement("script");n.type="application/llm+json",n.setAttribute("data-llm","true"),n.textContent=JSON.stringify(e),document.head.appendChild(n)}catch(e){}}(t),function(){R(),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])}var z="use-ref-print-target",_="use-ref-print-styles",J="\n@media print {\n body * {\n visibility: hidden;\n }\n ."+z+",\n ."+z+" * {\n visibility: visible;\n }\n ."+z+" {\n position: absolute !important;\n left: 0 !important;\n top: 0 !important;\n width: 100% !important;\n }\n}\n";function B(e,r){void 0===r&&(r={});var t=r.documentTitle,i=o("");return{print:n(function(){var n=e.current;if(n&&"undefined"!=typeof window&&window.print){var r=document.getElementById(_);r||((r=document.createElement("style")).id=_,r.textContent=J,document.head.appendChild(r)),n.classList.add(z),t&&(i.current=document.title,document.title=t);var o=function(){n.classList.remove(z),t&&void 0!==i.current&&(document.title=i.current)};if("onafterprint"in window){var u=function(){o(),window.removeEventListener("afterprint",u)};window.addEventListener("afterprint",u)}window.print(),setTimeout(o,1e3)}},[e,t])}}function F(e,n){if("undefined"==typeof window)return null;var r="localStorage"===e?window.localStorage:window.sessionStorage;try{var t=r.getItem(n);if(null==t)return null;var o=JSON.parse(t);return o&&"object"==typeof o?o:null}catch(e){return null}}function K(e,n){if("undefined"==typeof window)return[];var r="localStorage"===e?window.localStorage:window.sessionStorage;try{var t=r.getItem(n);if(null==t)return[];var o=JSON.parse(t);return Array.isArray(o)?o.filter(function(e){return"string"==typeof e}):[]}catch(e){return[]}}function Q(e,n){return n.filter(function(n){return n.condition(e)}).map(function(e){return e.role})}function H(e,n){for(var r,t=new Set,o=p(e);!(r=o()).done;){var i=n[r.value];if(Array.isArray(i))for(var u,a=p(i);!(u=a()).done;)t.add(u.value)}return Array.from(t)}function G(t){var i=t.userSource,u=o(t);u.current=t;var a=e(null),c=a[0],l=a[1],s=e([]),f=s[0],d=s[1],v=e([]),p=v[0],m=v[1],h=e(!1),g=h[0],y=h[1],w=e(null),b=w[0],S=w[1],E=n(function(){try{var e=u.current,n=e.userSource,r=e.roleDefinitions,t=e.roleCapabilities,o=e.capabilitiesOverride;S(null);var i=null,a=[],c=[],s=function(e,u){try{var s=function(e,u){try{var s=function(){function e(){function e(){l(i),d(a),m(c)}var n=function(){if(o){var e=function(){if("localStorage"===o.type){var e=K("localStorage",o.key);e.length>0&&(c=e)}else{var n=function(){if("sessionStorage"===o.type){var e=K("sessionStorage",o.key);e.length>0&&(c=e)}else{var n=function(){if("api"===o.type)return Promise.resolve(o.fetch()).then(function(e){c=e})}();if(n&&n.then)return n.then(function(){})}}();if(n&&n.then)return n.then(function(){})}}();if(e&&e.then)return e.then(function(){})}}();return n&&n.then?n.then(e):e()}var u=function(){if("localStorage"===n.type)i=F("localStorage",n.key),a=Q(i,r),c=H(a,t);else{var e=function(){if("sessionStorage"===n.type)i=F("sessionStorage",n.key),a=Q(i,r),c=H(a,t);else{var e=function(){if("api"===n.type)return Promise.resolve(n.fetch()).then(function(e){a=Q(i=e,r),c=H(a,t)});var e=function(){if("memory"===n.type)i=n.getUser(),a=Q(i,r),c=H(a,t);else{var e=function(){if("custom"===n.type)return Promise.resolve(Promise.resolve(n.getAuth())).then(function(e){var n,o,u;i=null!=(n=e.user)?n:null,a=null!=(o=e.roles)?o:Q(i,r),c=null!=(u=e.capabilities)?u:H(a,t)})}();if(e&&e.then)return e.then(function(){})}}();return e&&e.then?e.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}}();if(e&&e.then)return e.then(function(){})}}();return u&&u.then?u.then(e):e()}()}catch(e){return u(e)}return s&&s.then?s.then(void 0,u):s}(0,function(e){S(e instanceof Error?e:new Error(String(e))),l(null),d([]),m([])})}catch(e){return u(!0,e)}return s&&s.then?s.then(u.bind(null,!1),u.bind(null,!0)):u(!1,s)}(0,function(e,n){if(y(!0),e)throw n;return n});return Promise.resolve(s&&s.then?s.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[]);r(function(){E()},[E]),r(function(){if("undefined"!=typeof window){var e="localStorage"===i.type||"sessionStorage"===i.type?i.key:null;if(e){var n=function(n){n.key===e&&E()};return window.addEventListener("storage",n),function(){return window.removeEventListener("storage",n)}}}},[i.type,"localStorage"===i.type||"sessionStorage"===i.type?i.key:"",E]);var k=n(function(e){return f.includes(e)},[f]),I=n(function(e){return function(e,n){return!!e.includes("*")||e.includes(n)}(p,e)},[p]),x=I,T=n(function(){return E()},[E]),A=n(function(e,n,r){if("undefined"!=typeof window){var t="localStorage"===n?window.localStorage:window.sessionStorage;null==e?t.removeItem(r):t.setItem(r,JSON.stringify(e)),("localStorage"===i.type&&"localStorage"===n&&i.key===r||"sessionStorage"===i.type&&"sessionStorage"===n&&i.key===r)&&E()}},[i,E]),P=n(function(e,n,r){"undefined"!=typeof window&&("localStorage"===n?window.localStorage:window.sessionStorage).setItem(r,JSON.stringify(e))},[]),j=n(function(e,n,r){"undefined"!=typeof window&&("localStorage"===n?window.localStorage:window.sessionStorage).setItem(r,JSON.stringify(e))},[]);return{user:c,roles:f,capabilities:p,isReady:g,error:b,hasRole:k,hasCapability:I,can:x,refetch:T,setUserInStorage:A,setRolesInStorage:P,setCapabilitiesInStorage:j}}function X(){var r=o(new Set),t=e(0)[1];return{prefetch:n(function(e,n){var o,i=null==e?void 0:e.trim();i&&(r.current.has(i)||("document"===(null!=(o=null==n?void 0:n.as)?o:"document")?function(e){if("undefined"!=typeof document){for(var n=document.querySelectorAll('link[rel="prefetch"]'),r=0;r<n.length;r++)if(n[r].href===e)return;var 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(function(){})}(i),r.current.add(i),t(function(e){return e+1})))},[]),isPrefetched:n(function(e){var n;return r.current.has(null!=(n=null==e?void 0:e.trim())?n:"")},[])}}export{S as useClipboard,d as useEventBus,A as useIndexedDB,W as useLLMMetadata,s as useMutationObserver,w as useNetworkState,g as usePreferredTheme,X as usePrefetch,G as useRBAC,E as useRageClick,B as useRefPrint,k as useThreadedWorker,l as useTransition,M as useWasmCompute,O as useWebRTCIP,C as useWorkerNotifications,h as useWrappedChildren};
1
+ import{useState as e,useCallback as n,useEffect as r,useMemo as t,useRef as o}from"preact/hooks";import{isValidElement as i,cloneElement as u}from"preact";import{useRef as a,useEffect as c}from"preact/compat";function l(){var r=e(!1),t=r[0],o=r[1];return[n(function(e){o(!0),Promise.resolve().then(function(){e(),o(!1)})},[]),t]}function s(e,n,t){r(function(){var r=e.current;if(r){var o=new MutationObserver(n);return o.observe(r,t),function(){return o.disconnect()}}},[e,n,t])}var f=new Map;function d(){var e=n(function(e){var n=arguments,r=f.get(e);r&&r.forEach(function(e){return e.apply(void 0,[].slice.call(n,1))})},[]);return{emit:e,on:n(function(e,n){var r=f.get(e);return r||(r=new Set,f.set(e,r)),r.add(n),function(){r.delete(n),0===r.size&&f.delete(e)}},[])}}function v(e,n){(null==n||n>e.length)&&(n=e.length);for(var r=0,t=Array(n);r<n;r++)t[r]=e[r];return t}function p(e,n){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,n){if(e){if("string"==typeof e)return v(e,n);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?v(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var t=0;return function(){return t>=e.length?{done:!0}:{done:!1,value:e[t++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function m(){return m=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)({}).hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},m.apply(null,arguments)}function h(e,n,r){return void 0===r&&(r="preserve"),t(function(){if(!e)return e;var t=function(e){if(!i(e))return e;var t,o=e.props||{};t="override"===r?m({},o,n):m({},n,o);var a=null==o?void 0:o.style,c=null==n?void 0:n.style;return a&&c&&"object"==typeof a&&"object"==typeof c&&(t.style="override"===r?m({},a,c):m({},c,a)),u(e,t)};return Array.isArray(e)?e.map(t):t(e)},[e,n,r])}function g(){var n=e(function(){if("undefined"==typeof window)return"no-preference";var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");return e.matches?"dark":n.matches?"light":"no-preference"}),t=n[0],o=n[1];return r(function(){if("undefined"!=typeof window){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=function(e){o(e.matches?"dark":"light")},r=function(){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");o(e.matches?"dark":n.matches?"light":"no-preference")};e.addEventListener("change",n);var t=window.matchMedia("(prefers-color-scheme: light)");return t.addEventListener("change",r),function(){e.removeEventListener("change",n),t.removeEventListener("change",r)}}},[]),t}function y(){if("undefined"==typeof navigator)return{online:!0};var e={online:navigator.onLine},n=navigator.connection;return n&&(void 0!==n.effectiveType&&(e.effectiveType=n.effectiveType),void 0!==n.downlink&&(e.downlink=n.downlink),void 0!==n.rtt&&(e.rtt=n.rtt),void 0!==n.saveData&&(e.saveData=n.saveData),void 0!==n.type&&(e.connectionType=n.type)),e}function w(){var n=e(y),t=n[0],o=n[1];return r(function(){if("undefined"!=typeof window){var e=function(){return o(y())};window.addEventListener("online",e),window.addEventListener("offline",e);var n=navigator.connection;return null!=n&&n.addEventListener&&n.addEventListener("change",e),function(){window.removeEventListener("online",e),window.removeEventListener("offline",e),null!=n&&n.removeEventListener&&n.removeEventListener("change",e)}}},[]),t}function b(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}function S(r){void 0===r&&(r={});var t=r.resetDelay,o=void 0===t?2e3:t,i=e(!1),u=i[0],a=i[1],c=e(null),l=c[0],s=c[1],f=n(function(){a(!1),s(null)},[]);return{copy:n(function(e){try{if(s(null),"undefined"==typeof navigator||!navigator.clipboard){var n=new Error("Clipboard API is not available");return s(n),Promise.resolve(!1)}return Promise.resolve(b(function(){return Promise.resolve(navigator.clipboard.writeText(e)).then(function(){return a(!0),o>0&&setTimeout(function(){return a(!1)},o),!0})},function(e){var n=e instanceof Error?e:new Error(String(e));return s(n),!1}))}catch(e){return Promise.reject(e)}},[o]),paste:n(function(){try{if(s(null),"undefined"==typeof navigator||!navigator.clipboard){var e=new Error("Clipboard API is not available");return s(e),Promise.resolve("")}return Promise.resolve(b(function(){return Promise.resolve(navigator.clipboard.readText())},function(e){var n=e instanceof Error?e:new Error(String(e));return s(n),""}))}catch(e){return Promise.reject(e)}},[]),copied:u,error:l,reset:f}}function E(e,n){var t=n.onRageClick,i=n.threshold,u=void 0===i?5:i,a=n.timeWindow,c=void 0===a?1e3:a,l=n.distanceThreshold,s=void 0===l?30:l,f=o(t);f.current=t;var d=o([]);r(function(){var n=e.current;if(n){var r=function(e){var n=Date.now(),r={time:n,x:e.clientX,y:e.clientY},t=n-c,o=d.current.filter(function(e){return e.time>=t});if(o.push(r),Infinity!==s){var i=o.filter(function(e){return n=e,t=r,Math.hypot(t.x-n.x,t.y-n.y)<=s;var n,t});if(i.length>=u)return f.current({count:i.length,event:e}),void(d.current=[])}else if(o.length>=u)return f.current({count:o.length,event:e}),void(d.current=[]);d.current=o};return n.addEventListener("click",r),function(){return n.removeEventListener("click",r)}}},[e,u,c,s])}function k(t,i){var u=i.concurrency,a="sequential"===i.mode?1:Math.max(1,void 0===u?4:u),c=e(!1),l=c[0],s=c[1],f=e(void 0),d=f[0],v=f[1],p=e(void 0),m=p[0],h=p[1],g=e(0),y=g[0],w=g[1],b=o([]),S=o(0),E=o(0),k=o(!1),I=o(t);I.current=t;var x=n(function(){w(b.current.length+E.current)},[]),T=n(function(){if(!(k.current||E.current>=a)){if(0===b.current.length)return 0===E.current&&s(!1),void x();b.current.sort(function(e,n){return e.priority!==n.priority?e.priority-n.priority:e.sequence-n.sequence});var e=b.current.shift();E.current+=1,s(!0),x(),(0,I.current)(e.data).then(function(n){v(n),h(void 0),e.resolve(n)}).catch(function(n){h(n),e.reject(n)}).finally(function(){E.current-=1,x(),T()}),b.current.length>0&&E.current<a&&T()}},[a,x]),P=n(function(e,n){var r;if(k.current)return Promise.reject(new Error("Worker is terminated"));var t=null!=(r=null==n?void 0:n.priority)?r:1,o=++S.current,i=new Promise(function(n,r){b.current.push({data:e,priority:t,sequence:o,resolve:n,reject:r})});return x(),s(!0),queueMicrotask(T),i},[T,x]),A=n(function(){var e=b.current;b.current=[],e.forEach(function(e){return e.reject(new Error("Task cleared from queue"))}),x(),0===E.current&&s(!1)},[x]),j=n(function(){k.current=!0,A()},[A]);return r(function(){return function(){k.current=!0}},[]),{run:P,loading:l,result:d,error:m,queueSize:y,clearQueue:A,terminate:j}}var I=new Map;function x(e){return new Promise(function(n,r){e.onsuccess=function(){return n(e.result)},e.onerror=function(){var n;return r(null!=(n=e.error)?n:new DOMException("Unknown IndexedDB error"))}})}function T(e,n){return n?e.then(function(e){return null==n.onSuccess||n.onSuccess(e),e}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}function P(n){var t=e(null),i=t[0],u=t[1],a=e(null),c=a[0],l=a[1],s=e(!1),f=s[0],d=s[1],v=o(n);return v.current=n,r(function(){var e=!1;l(null),d(!1),u(null);var n=v.current;return function(e){var n=e.name+"_v"+e.version,r=I.get(n);return r||(r=function(e){return new Promise(function(n,r){var t=indexedDB.open(e.name,e.version);t.onerror=function(){var e;return r(null!=(e=t.error)?e:new DOMException("Failed to open database"))},t.onsuccess=function(){return n(t.result)},t.onupgradeneeded=function(n){for(var r=n.target.result,t=e.tables,o=0,i=Object.keys(t);o<i.length;o++){var u=i[o],a=t[u];if(!r.objectStoreNames.contains(u)){var c,l=r.createObjectStore(u,{keyPath:a.keyPath,autoIncrement:null!=(c=a.autoIncrement)&&c});if(a.indexes)for(var s,f=p(a.indexes);!(s=f()).done;){var d=s.value;l.createIndex(d,d,{unique:!1})}}}}})}(e),I.set(n,r),r)}({name:n.name,version:n.version,tables:n.tables}).then(function(n){if(e)n.close();else{var r=function(e){return{get db(){return e},hasTable:function(n){return e.objectStoreNames.contains(n)},table:function(n){return function(e,n){return function(e,n){function r(r){return e.transaction([n],r).objectStore(n)}return{insert:function(e,n){return T(x(r("readwrite").add(e)),n)},update:function(e,n,t){var o=r("readwrite");return T(x(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=m({},e,n);return x(o.put(r))}).then(function(){}),t)},delete:function(e,n){return T(x(r("readwrite").delete(e)).then(function(){}),n)},exists:function(e){return x(r("readonly").getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r("readonly").openCursor(),o=[];return T(new Promise(function(n,r){t.onsuccess=function(){var r=t.result;r?(e(r.value)&&o.push(r.value),r.continue()):n(o)},t.onerror=function(){var e;return r(null!=(e=t.error)?e:new DOMException("Unknown error"))}}),n)},upsert:function(e,n){return T(x(r("readwrite").put(e)),n)},bulkInsert:function(e,n){var t=r("readwrite"),o=[];if(0===e.length)return T(Promise.resolve(o),n);var i=0;return T(new Promise(function(n,r){e.forEach(function(u,a){var c=t.add(u);c.onsuccess=function(){o[a]=c.result,++i===e.length&&n(o)},c.onerror=function(){var e;return r(null!=(e=c.error)?e:new DOMException("Unknown error"))}})}),n)},clear:function(e){return T(x(r("readwrite").clear()).then(function(){}),e)},count:function(e){return T(x(r("readonly").count()),null!=e?e:{})}}}(e,n)}(e,n)},transaction:function(n,r,t,o){var i=e.transaction(n,r),u={table:function(e){return function(e,n){return function(e,n){function r(){return e.objectStore(n)}return{insert:function(e,n){return T(x(r().add(e)),n)},update:function(e,n,t){var o=r();return T(x(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=m({},e,n);return x(o.put(r))}).then(function(){}),t)},delete:function(e,n){return T(x(r().delete(e)).then(function(){}),n)},exists:function(e){return x(r().getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r().openCursor(),o=[];return T(new Promise(function(n,r){t.onsuccess=function(){var r=t.result;r?(e(r.value)&&o.push(r.value),r.continue()):n(o)},t.onerror=function(){var e;return r(null!=(e=t.error)?e:new DOMException("Unknown error"))}}),n)},upsert:function(e,n){return T(x(r().put(e)),n)},bulkInsert:function(e,n){var t=r(),o=[];if(0===e.length)return T(Promise.resolve(o),n);var i=0;return T(new Promise(function(n,r){e.forEach(function(u,a){var c=t.add(u);c.onsuccess=function(){o[a]=c.result,++i===e.length&&n(o)},c.onerror=function(){var e;return r(null!=(e=c.error)?e:new DOMException("Unknown error"))}})}),n)},clear:function(e){return T(x(r().clear()).then(function(){}),e)},count:function(e){return T(x(r().count()),null!=e?e:{})}}}(e,n)}(i,e)}},a=new Promise(function(e,n){i.oncomplete=function(){return e()},i.onerror=function(){var e;return n(null!=(e=i.error)?e:new DOMException("Transaction failed"))}}),c=t(u);return function(e,n){return n?e.then(function(){return null==n.onSuccess?void 0:n.onSuccess()}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}(Promise.resolve(c).then(function(){return a}),o)}}}(n);u(r),d(!0)}}).catch(function(n){e||l(n)}),function(){e=!0}},[n.name,n.version]),{db:i,isReady:f,error:c}}var A=/\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,j=["stun:stun.l.google.com:19302"];function M(n){void 0===n&&(n={});var t=n.stunServers,i=void 0===t?j:t,u=n.timeout,a=void 0===u?3e3:u,c=n.onDetect,l=e([]),s=l[0],f=l[1],d=e(!0),v=d[0],p=d[1],m=e(null),h=m[0],g=m[1],y=o(null),w=o(null),b=o(new Set),S=o(c);return S.current=c,r(function(){if("undefined"==typeof window)return p(!1),void g("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return p(!1),void g("RTCPeerConnection is not available");var e=new Set;b.current=e;var n=function(){w.current&&(clearTimeout(w.current),w.current=null),y.current&&(y.current.close(),y.current=null),p(!1)},r=function(n){e.has(n)||(e.add(n),f(function(e){return[].concat(e,[n])}),null==S.current||S.current(n))};try{var t=new RTCPeerConnection({iceServers:[{urls:i}]});y.current=t,t.onicecandidate=function(e){var n,t=e.candidate;t&&t.candidate&&((n=t.candidate.match(A))?[].concat(n):[]).forEach(r)},t.createDataChannel(""),t.createOffer().then(function(e){return t.setLocalDescription(e)}).catch(function(e){g(e instanceof Error?e.message:"Failed to create offer"),n()}),w.current=setTimeout(function(){return n()},a)}catch(e){g(e instanceof Error?e.message:"WebRTC setup failed"),n()}return function(){n()}},[i.join(","),a]),{ips:s,loading:v,error:h}}function O(t){var i=t.wasmUrl,u=t.exportName,a=void 0===u?"compute":u,c=t.workerUrl,l=t.importObject,s=e(void 0),f=s[0],d=s[1],v=e(!0),p=v[0],m=v[1],h=e(null),g=h[0],y=h[1],w=e(!1),b=w[0],S=w[1],E=o(null),k=o(null),I=o(null);return r(function(){if("undefined"==typeof window)return y("useWasmCompute is not available during SSR"),void m(!1);if("undefined"==typeof Worker)return y("Worker is not supported in this environment"),void m(!1);if("undefined"==typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)return y("WebAssembly is not supported in this environment"),void m(!1);y(null),S(!1);var e=function(e){if(e)return new Worker(e);var n=new Blob(["\nself.onmessage = async (e) => {\n const d = e.data;\n if (d.type === 'init') {\n try {\n const res = await fetch(d.wasmUrl);\n const buf = await res.arrayBuffer();\n const mod = await WebAssembly.instantiate(buf, d.importObject || {});\n self.wasmInstance = mod.instance;\n self.exportName = d.exportName || 'compute';\n self.postMessage({ type: 'ready' });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n return;\n }\n if (d.type === 'compute') {\n try {\n const fn = self.wasmInstance.exports[self.exportName];\n if (typeof fn !== 'function') {\n self.postMessage({ type: 'error', error: 'Export \"' + self.exportName + '\" is not a function' });\n return;\n }\n const result = fn(d.input);\n self.postMessage({ type: 'result', result: result });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n }\n};\n"],{type:"application/javascript"}),r=URL.createObjectURL(n),t=new Worker(r);return URL.revokeObjectURL(r),t}(c);E.current=e;var n=function(e){var n,r=null!=(n=e.data)?n:{},t=r.type,o=r.result,i=r.error;return"ready"===t?(S(!0),void m(!1)):"error"===t?(y(null!=i?i:"Unknown error"),m(!1),void(I.current&&(I.current(new Error(i)),k.current=null,I.current=null))):void("result"===t&&(d(o),m(!1),k.current&&(k.current(o),k.current=null,I.current=null)))};return e.addEventListener("message",n),e.postMessage({type:"init",wasmUrl:i,exportName:a,importObject:null!=l?l:{}}),function(){e.removeEventListener("message",n),e.terminate(),E.current=null,I.current&&(I.current(new Error("Worker terminated")),k.current=null,I.current=null)}},[i,a,c,l]),{compute:n(function(e){return new Promise(function(n,r){E.current&&b?g?r(new Error(g)):(k.current=n,I.current=r,m(!0),E.current.postMessage({type:"compute",input:e})):r(new Error("WASM not ready"))})},[b,g]),result:f,loading:p,error:g,ready:b}}function C(n,i){void 0===i&&(i={});var u=i.maxHistory,a=void 0===u?100:u,c=i.throughputWindowMs,l=void 0===c?1e3:c,s=e([]),f=s[0],d=s[1],v=e(0),p=v[0],m=v[1],h=e(0),g=h[0],y=h[1],w=e([]),b=w[0],S=w[1],E=e(0),k=E[0],I=E[1],x=o([]),T=o(0),P=o(0);r(function(){if(n){var e=function(e){var n=function(e){if(null==e||"object"!=typeof e)return null;var n=e.type;return"task_start"!==n&&"task_end"!==n&&"task_fail"!==n&&"queue_size"!==n?null:{type:n,taskId:"string"==typeof e.taskId?e.taskId:void 0,duration:"number"==typeof e.duration?e.duration:void 0,error:"string"==typeof e.error?e.error:void 0,size:"number"==typeof e.size?e.size:void 0,timestamp:Date.now()}}(e.data);if(n)if(S(function(e){return[].concat(e,[n]).slice(-a)}),"task_start"===n.type&&n.taskId)d(function(e){return e.includes(n.taskId)?e:[].concat(e,[n.taskId])});else if("task_end"===n.type){n.taskId&&d(function(e){return e.filter(function(e){return e!==n.taskId})}),m(function(e){return e+1});var r=Date.now()-l;x.current=[].concat(x.current.filter(function(e){return e>=r}),[n.timestamp]),"number"==typeof n.duration&&(T.current+=n.duration,P.current+=1)}else"task_fail"===n.type?(n.taskId&&d(function(e){return e.filter(function(e){return e!==n.taskId})}),y(function(e){return e+1})):"queue_size"===n.type&&"number"==typeof n.size&&I(n.size)};return n.addEventListener("message",e),function(){return n.removeEventListener("message",e)}}},[n,a]);var A=t(function(){var e=P.current;return e>0?T.current/e:0},[b]),j=t(function(){var e=Date.now()-l;return x.current.filter(function(n){return n>=e}).length/(l/1e3)},[b,l]),M=t(function(){return{runningTasks:f,completedCount:p,failedCount:g,averageDurationMs:A,throughputPerSecond:j,currentQueueSize:k,totalProcessed:p+g,recentEventCount:b.length}},[f,p,g,A,j,k,b.length]);return{runningTasks:f,completedCount:p,failedCount:g,eventHistory:b,averageDurationMs:A,throughputPerSecond:j,currentQueueSize:k,progress:M}}function L(e,n){if(null==e)return"";var r=("string"==typeof e?e:String(e)).trim();return r.length>n?r.slice(0,n):r}function D(e){if(!Array.isArray(e))return[];for(var n=[],r=0;r<e.length&&n.length<50;r++){var t=L(e[r],100);t&&n.push(t)}return n}function N(e){var n=L(e,2048);if(!n)return"";try{var r=new URL(n);if("http:"===r.protocol||"https:"===r.protocol)return n}catch(e){}return""}function U(e){try{if("undefined"==typeof window)return!1;var n=window.getComputedStyle(e);return"none"!==n.display&&"hidden"!==n.visibility&&"0"!==n.opacity}catch(e){return!1}}function q(e){var n={};try{for(var r,t=p(Object.keys(e).slice(0,20));!(r=t()).done;){var o=r.value,i=L(o,50);if(i){var u=e[o];"string"==typeof u?n[i]=u.slice(0,500):"number"==typeof u&&Number.isFinite(u)||"boolean"==typeof u?n[i]=u:Array.isArray(u)&&(n[i]=u.map(function(e){return L(e,200)}).filter(Boolean).slice(0,20))}}}catch(e){}return n}function R(){try{if("undefined"==typeof document||!document.querySelectorAll)return;document.querySelectorAll('script[data-llm="true"]').forEach(function(e){return e.remove()})}catch(e){}}function W(e){var n=a(null);c(function(){try{if("undefined"==typeof window)return;var r=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?D(e.tags):void 0,canonicalUrl:void 0!==e.canonicalUrl?N(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?N(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:q(e.extra)}}(e),t=function(e){try{var n=(new Date).toISOString(),r={route:e.route,generatedAt:n};if("auto-extract"===e.mode){var t,o,i=function(){var e={title:"",outline:[],description:""};try{if("undefined"==typeof document)return e;var n=L(document.title,200),r=[],t="";try{for(var o,i=document.querySelectorAll("nav, footer, [role='navigation'], [role='contentinfo'], script, style, noscript"),u=function(e){for(var n,r=p(i);!(n=r()).done;)if(n.value.contains(e))return!0;return!1},a=p(document.querySelectorAll("h1, h2"));!(o=a()).done;){var c=o.value;if(r.length>=50)break;if(U(c)&&!u(c)){var l=L(c.textContent,300);l&&r.push(l)}}for(var s,f=document.querySelectorAll("p"),d=[],v=p(f);!(s=v()).done;){var m=s.value;if(d.length>=3)break;if(U(m)&&!u(m)){var h=L(m.textContent,1e3);h&&d.push(h)}}t=d.join(" ").trim().slice(0,2e3)||""}catch(e){}return{title:n,outline:r,description:t}}catch(n){return e}}();r.title=(null!=(t=e.title)?t:i.title)||void 0,r.description=(null!=(o=e.description)?o:i.description)||void 0,i.outline.length>0&&(r.outline=i.outline)}else void 0!==e.title&&""!==e.title&&(r.title=e.title),void 0!==e.description&&""!==e.description&&(r.description=e.description);return e.tags&&e.tags.length>0&&(r.tags=e.tags),e.canonicalUrl&&(r.canonicalUrl=e.canonicalUrl),e.language&&(r.language=e.language),e.ogType&&(r.ogType=e.ogType),e.ogImage&&(r.ogImage=e.ogImage),e.ogImageAlt&&(r.ogImageAlt=e.ogImageAlt),e.siteName&&(r.siteName=e.siteName),e.author&&(r.author=e.author),e.publishedTime&&(r.publishedTime=e.publishedTime),e.modifiedTime&&(r.modifiedTime=e.modifiedTime),e.robots&&(r.robots=e.robots),e.extra&&Object.keys(e.extra).length>0&&(r.extra=e.extra),r}catch(n){var u;return{route:null!=(u=null==e?void 0:e.route)?u:"/",generatedAt:(new Date).toISOString()}}}(r),o=JSON.stringify(t);if(n.current===o)return;return n.current=o,R(),function(e){try{if("undefined"==typeof document||!document.head)return;var n=document.createElement("script");n.type="application/llm+json",n.setAttribute("data-llm","true"),n.textContent=JSON.stringify(e),document.head.appendChild(n)}catch(e){}}(t),function(){R(),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])}var z="use-ref-print-target",_="use-ref-print-styles",J="\n@media print {\n body * {\n visibility: hidden;\n }\n ."+z+",\n ."+z+" * {\n visibility: visible;\n }\n ."+z+" {\n position: absolute !important;\n left: 0 !important;\n top: 0 !important;\n width: 100% !important;\n }\n}\n";function B(e,r){void 0===r&&(r={});var t=r.documentTitle,i=o("");return{print:n(function(){var n=e.current;if(n&&"undefined"!=typeof window&&window.print){var r=document.getElementById(_);r||((r=document.createElement("style")).id=_,r.textContent=J,document.head.appendChild(r)),n.classList.add(z),t&&(i.current=document.title,document.title=t);var o=function(){n.classList.remove(z),t&&void 0!==i.current&&(document.title=i.current)};if("onafterprint"in window){var u=function(){o(),window.removeEventListener("afterprint",u)};window.addEventListener("afterprint",u)}window.print(),setTimeout(o,1e3)}},[e,t])}}function F(e,n){if("undefined"==typeof window)return null;var r="localStorage"===e?window.localStorage:window.sessionStorage;try{var t=r.getItem(n);if(null==t)return null;var o=JSON.parse(t);return o&&"object"==typeof o?o:null}catch(e){return null}}function K(e,n){if("undefined"==typeof window)return[];var r="localStorage"===e?window.localStorage:window.sessionStorage;try{var t=r.getItem(n);if(null==t)return[];var o=JSON.parse(t);return Array.isArray(o)?o.filter(function(e){return"string"==typeof e}):[]}catch(e){return[]}}function Q(e,n){return n.filter(function(n){return n.condition(e)}).map(function(e){return e.role})}function H(e,n){for(var r,t=new Set,o=p(e);!(r=o()).done;){var i=n[r.value];if(Array.isArray(i))for(var u,a=p(i);!(u=a()).done;)t.add(u.value)}return Array.from(t)}function G(t){var i=t.userSource,u=o(t);u.current=t;var a=e(null),c=a[0],l=a[1],s=e([]),f=s[0],d=s[1],v=e([]),p=v[0],m=v[1],h=e(!1),g=h[0],y=h[1],w=e(null),b=w[0],S=w[1],E=n(function(){try{var e=u.current,n=e.userSource,r=e.roleDefinitions,t=e.roleCapabilities,o=e.capabilitiesOverride;S(null);var i=null,a=[],c=[],s=function(e,u){try{var s=function(e,u){try{var s=function(){function e(){function e(){l(i),d(a),m(c)}var n=function(){if(o){var e=function(){if("localStorage"===o.type){var e=K("localStorage",o.key);e.length>0&&(c=e)}else{var n=function(){if("sessionStorage"===o.type){var e=K("sessionStorage",o.key);e.length>0&&(c=e)}else{var n=function(){if("api"===o.type)return Promise.resolve(o.fetch()).then(function(e){c=e})}();if(n&&n.then)return n.then(function(){})}}();if(n&&n.then)return n.then(function(){})}}();if(e&&e.then)return e.then(function(){})}}();return n&&n.then?n.then(e):e()}var u=function(){if("localStorage"===n.type)i=F("localStorage",n.key),a=Q(i,r),c=H(a,t);else{var e=function(){if("sessionStorage"===n.type)i=F("sessionStorage",n.key),a=Q(i,r),c=H(a,t);else{var e=function(){if("api"===n.type)return Promise.resolve(n.fetch()).then(function(e){a=Q(i=e,r),c=H(a,t)});var e=function(){if("memory"===n.type)i=n.getUser(),a=Q(i,r),c=H(a,t);else{var e=function(){if("custom"===n.type)return Promise.resolve(Promise.resolve(n.getAuth())).then(function(e){var n,o,u;i=null!=(n=e.user)?n:null,a=null!=(o=e.roles)?o:Q(i,r),c=null!=(u=e.capabilities)?u:H(a,t)})}();if(e&&e.then)return e.then(function(){})}}();return e&&e.then?e.then(function(){}):void 0}();if(e&&e.then)return e.then(function(){})}}();if(e&&e.then)return e.then(function(){})}}();return u&&u.then?u.then(e):e()}()}catch(e){return u(e)}return s&&s.then?s.then(void 0,u):s}(0,function(e){S(e instanceof Error?e:new Error(String(e))),l(null),d([]),m([])})}catch(e){return u(!0,e)}return s&&s.then?s.then(u.bind(null,!1),u.bind(null,!0)):u(!1,s)}(0,function(e,n){if(y(!0),e)throw n;return n});return Promise.resolve(s&&s.then?s.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[]);r(function(){E()},[E]),r(function(){if("undefined"!=typeof window){var e="localStorage"===i.type||"sessionStorage"===i.type?i.key:null;if(e){var n=function(n){n.key===e&&E()};return window.addEventListener("storage",n),function(){return window.removeEventListener("storage",n)}}}},[i.type,"localStorage"===i.type||"sessionStorage"===i.type?i.key:"",E]);var k=n(function(e){return f.includes(e)},[f]),I=n(function(e){return function(e,n){return!!e.includes("*")||e.includes(n)}(p,e)},[p]),x=I,T=n(function(){return E()},[E]),P=n(function(e,n,r){if("undefined"!=typeof window){var t="localStorage"===n?window.localStorage:window.sessionStorage;null==e?t.removeItem(r):t.setItem(r,JSON.stringify(e)),("localStorage"===i.type&&"localStorage"===n&&i.key===r||"sessionStorage"===i.type&&"sessionStorage"===n&&i.key===r)&&E()}},[i,E]),A=n(function(e,n,r){"undefined"!=typeof window&&("localStorage"===n?window.localStorage:window.sessionStorage).setItem(r,JSON.stringify(e))},[]),j=n(function(e,n,r){"undefined"!=typeof window&&("localStorage"===n?window.localStorage:window.sessionStorage).setItem(r,JSON.stringify(e))},[]);return{user:c,roles:f,capabilities:p,isReady:g,error:b,hasRole:k,hasCapability:I,can:x,refetch:T,setUserInStorage:P,setRolesInStorage:A,setCapabilitiesInStorage:j}}function X(){var r=o(new Set),t=e(0)[1];return{prefetch:n(function(e,n){var o,i=null==e?void 0:e.trim();i&&(r.current.has(i)||("document"===(null!=(o=null==n?void 0:n.as)?o:"document")?function(e){if("undefined"!=typeof document){for(var n=document.querySelectorAll('link[rel="prefetch"]'),r=0;r<n.length;r++)if(n[r].href===e)return;var 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(function(){})}(i),r.current.add(i),t(function(e){return e+1})))},[]),isPrefetched:n(function(e){var n;return r.current.has(null!=(n=null==e?void 0:e.trim())?n:"")},[])}}function Y(t,i){void 0===i&&(i={});var u=i.intervalMs,a=void 0===u?1e3:u,c=i.immediate,l=void 0===c||c,s=i.enabled,f=void 0===s||s,d=e(null),v=d[0],p=d[1],m=e(!1),h=m[0],g=m[1],y=e(null),w=y[0],b=y[1],S=e(0),E=S[0],k=S[1],I=e(!1),x=I[0],T=I[1],P=o(null),A=o(t);A.current=t;var j=n(function(){null!=P.current&&(clearInterval(P.current),P.current=null),T(!1)},[]),M=n(function(){try{var e=function(e,n){try{var r=(b(null),Promise.resolve(A.current()).then(function(e){k(function(e){return e+1}),e.done&&(j(),g(!0),void 0!==e.data&&p(e.data))}))}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}(0,function(e){var n=e instanceof Error?e:new Error(String(e));b(n),j()});return Promise.resolve(e&&e.then?e.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[j]),O=n(function(){f&&!x&&(T(!0),l&&M(),P.current=setInterval(M,a))},[f,l,a,x,M]);return r(function(){return f&&O(),function(){j()}},[f]),{data:v,done:h,error:w,pollCount:E,start:O,stop:j}}export{S as useClipboard,d as useEventBus,P as useIndexedDB,W as useLLMMetadata,s as useMutationObserver,w as useNetworkState,Y as usePoll,g as usePreferredTheme,X as usePrefetch,G as useRBAC,E as useRageClick,B as useRefPrint,k as useThreadedWorker,l as useTransition,O as useWasmCompute,M as useWebRTCIP,C as useWorkerNotifications,h as useWrappedChildren};
2
2
  //# sourceMappingURL=index.module.js.map