preact-missing-hooks 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.js CHANGED
@@ -1 +1 @@
1
- var e=require("react/hooks"),n=require("react"),r=new Map;function t(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 o(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 t(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)?t(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)({}).hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},u.apply(null,arguments)}function i(){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 a(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}var c=new Map;function s(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 f(e,n){return n?e.then(function(e){return null==n.onSuccess||n.onSuccess(e),e}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}var l=/\b(?:25[0-5]|2[0-4]\d|1?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|1?\d{1,2})){3}\b/g,d=["stun:stun.l.google.com:19302"];exports.useClipboard=function(n){void 0===n&&(n={});var r=n.resetDelay,t=void 0===r?2e3:r,o=e.useState(!1),u=o[0],i=o[1],c=e.useState(null),s=c[0],f=c[1],l=e.useCallback(function(){i(!1),f(null)},[]);return{copy:e.useCallback(function(e){try{if(f(null),"undefined"==typeof navigator||!navigator.clipboard){var n=new Error("Clipboard API is not available");return f(n),Promise.resolve(!1)}return Promise.resolve(a(function(){return Promise.resolve(navigator.clipboard.writeText(e)).then(function(){return i(!0),t>0&&setTimeout(function(){return i(!1)},t),!0})},function(e){var n=e instanceof Error?e:new Error(String(e));return f(n),!1}))}catch(e){return Promise.reject(e)}},[t]),paste:e.useCallback(function(){try{if(f(null),"undefined"==typeof navigator||!navigator.clipboard){var e=new Error("Clipboard API is not available");return f(e),Promise.resolve("")}return Promise.resolve(a(function(){return Promise.resolve(navigator.clipboard.readText())},function(e){var n=e instanceof Error?e:new Error(String(e));return f(n),""}))}catch(e){return Promise.reject(e)}},[]),copied:u,error:s,reset:l}},exports.useEventBus=function(){return{emit:e.useCallback(function(e){var n=arguments,t=r.get(e);t&&t.forEach(function(e){return e.apply(void 0,[].slice.call(n,1))})},[]),on:e.useCallback(function(e,n){var t=r.get(e);return t||(t=new Set,r.set(e,t)),t.add(n),function(){t.delete(n),0===t.size&&r.delete(e)}},[])}},exports.useIndexedDB=function(n){var r=e.useState(null),t=r[0],i=r[1],a=e.useState(null),l=a[0],d=a[1],v=e.useState(!1),p=v[0],m=v[1],h=e.useRef(n);return h.current=n,e.useEffect(function(){var e=!1;d(null),m(!1),i(null);var n=h.current;return function(e){var n=e.name+"_v"+e.version,r=c.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,u=0,i=Object.keys(t);u<i.length;u++){var a=i[u],c=t[a];if(!r.objectStoreNames.contains(a)){var s,f=r.createObjectStore(a,{keyPath:c.keyPath,autoIncrement:null!=(s=c.autoIncrement)&&s});if(c.indexes)for(var l,d=o(c.indexes);!(l=d()).done;){var v=l.value;f.createIndex(v,v,{unique:!1})}}}}})}(e),c.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 f(s(r("readwrite").add(e)),n)},update:function(e,n,t){var o=r("readwrite");return f(s(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=u({},e,n);return s(o.put(r))}).then(function(){}),t)},delete:function(e,n){return f(s(r("readwrite").delete(e)).then(function(){}),n)},exists:function(e){return s(r("readonly").getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r("readonly").openCursor(),o=[];return f(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 f(s(r("readwrite").put(e)),n)},bulkInsert:function(e,n){var t=r("readwrite"),o=[];if(0===e.length)return f(Promise.resolve(o),n);var u=0;return f(new Promise(function(n,r){e.forEach(function(i,a){var c=t.add(i);c.onsuccess=function(){o[a]=c.result,++u===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 f(s(r("readwrite").clear()).then(function(){}),e)},count:function(e){return f(s(r("readonly").count()),null!=e?e:{})}}}(e,n)}(e,n)},transaction:function(n,r,t,o){var i=e.transaction(n,r),a={table:function(e){return function(e,n){return function(e,n){function r(){return e.objectStore(n)}return{insert:function(e,n){return f(s(r().add(e)),n)},update:function(e,n,t){var o=r();return f(s(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=u({},e,n);return s(o.put(r))}).then(function(){}),t)},delete:function(e,n){return f(s(r().delete(e)).then(function(){}),n)},exists:function(e){return s(r().getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r().openCursor(),o=[];return f(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 f(s(r().put(e)),n)},bulkInsert:function(e,n){var t=r(),o=[];if(0===e.length)return f(Promise.resolve(o),n);var u=0;return f(new Promise(function(n,r){e.forEach(function(i,a){var c=t.add(i);c.onsuccess=function(){o[a]=c.result,++u===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 f(s(r().clear()).then(function(){}),e)},count:function(e){return f(s(r().count()),null!=e?e:{})}}}(e,n)}(i,e)}},c=new Promise(function(e,n){i.oncomplete=function(){return e()},i.onerror=function(){var e;return n(null!=(e=i.error)?e:new DOMException("Transaction failed"))}}),l=t(a);return function(e,n){return n?e.then(function(){return null==n.onSuccess?void 0:n.onSuccess()}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}(Promise.resolve(l).then(function(){return c}),o)}}}(n);i(r),m(!0)}}).catch(function(n){e||d(n)}),function(){e=!0}},[n.name,n.version]),{db:t,isReady:p,error:l}},exports.useMutationObserver=function(n,r,t){e.useEffect(function(){var e=n.current;if(e){var o=new MutationObserver(r);return o.observe(e,t),function(){return o.disconnect()}}},[n,r,t])},exports.useNetworkState=function(){var n=e.useState(i),r=n[0],t=n[1];return e.useEffect(function(){if("undefined"!=typeof window){var e=function(){return t(i())};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)}}},[]),r},exports.usePreferredTheme=function(){var n=e.useState(function(){if("undefined"==typeof window)return"no-preference";var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");return e.matches?"dark":n.matches?"light":"no-preference"}),r=n[0],t=n[1];return e.useEffect(function(){if("undefined"!=typeof window){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=function(e){t(e.matches?"dark":"light")},r=function(){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");t(e.matches?"dark":n.matches?"light":"no-preference")};e.addEventListener("change",n);var o=window.matchMedia("(prefers-color-scheme: light)");return o.addEventListener("change",r),function(){e.removeEventListener("change",n),o.removeEventListener("change",r)}}},[]),r},exports.useRageClick=function(n,r){var t=r.onRageClick,o=r.threshold,u=void 0===o?5:o,i=r.timeWindow,a=void 0===i?1e3:i,c=r.distanceThreshold,s=void 0===c?30:c,f=e.useRef(t);f.current=t;var l=e.useRef([]);e.useEffect(function(){var e=n.current;if(e){var r=function(e){var n=Date.now(),r={time:n,x:e.clientX,y:e.clientY},t=n-a,o=l.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(l.current=[])}else if(o.length>=u)return f.current({count:o.length,event:e}),void(l.current=[]);l.current=o};return e.addEventListener("click",r),function(){return e.removeEventListener("click",r)}}},[n,u,a,s])},exports.useThreadedWorker=function(n,r){var t=r.concurrency,o="sequential"===r.mode?1:Math.max(1,void 0===t?4:t),u=e.useState(!1),i=u[0],a=u[1],c=e.useState(void 0),s=c[0],f=c[1],l=e.useState(void 0),d=l[0],v=l[1],p=e.useState(0),m=p[0],h=p[1],y=e.useRef([]),w=e.useRef(0),g=e.useRef(0),b=e.useRef(!1),k=e.useRef(n);k.current=n;var E=e.useCallback(function(){h(y.current.length+g.current)},[]),S=e.useCallback(function(){if(!(b.current||g.current>=o)){if(0===y.current.length)return 0===g.current&&a(!1),void E();y.current.sort(function(e,n){return e.priority!==n.priority?e.priority-n.priority:e.sequence-n.sequence});var e=y.current.shift();g.current+=1,a(!0),E(),(0,k.current)(e.data).then(function(n){f(n),v(void 0),e.resolve(n)}).catch(function(n){v(n),e.reject(n)}).finally(function(){g.current-=1,E(),S()}),y.current.length>0&&g.current<o&&S()}},[o,E]),x=e.useCallback(function(e,n){var r;if(b.current)return Promise.reject(new Error("Worker is terminated"));var t=null!=(r=null==n?void 0:n.priority)?r:1,o=++w.current,u=new Promise(function(n,r){y.current.push({data:e,priority:t,sequence:o,resolve:n,reject:r})});return E(),a(!0),queueMicrotask(S),u},[S,E]),C=e.useCallback(function(){var e=y.current;y.current=[],e.forEach(function(e){return e.reject(new Error("Task cleared from queue"))}),E(),0===g.current&&a(!1)},[E]),M=e.useCallback(function(){b.current=!0,C()},[C]);return e.useEffect(function(){return function(){b.current=!0}},[]),{run:x,loading:i,result:s,error:d,queueSize:m,clearQueue:C,terminate:M}},exports.useTransition=function(){var n=e.useState(!1),r=n[0],t=n[1];return[e.useCallback(function(e){t(!0),Promise.resolve().then(function(){e(),t(!1)})},[]),r]},exports.useWasmCompute=function(n){var r=n.wasmUrl,t=n.exportName,o=void 0===t?"compute":t,u=n.workerUrl,i=n.importObject,a=e.useState(void 0),c=a[0],s=a[1],f=e.useState(!0),l=f[0],d=f[1],v=e.useState(null),p=v[0],m=v[1],h=e.useState(!1),y=h[0],w=h[1],g=e.useRef(null),b=e.useRef(null),k=e.useRef(null);return e.useEffect(function(){if("undefined"==typeof window)return m("useWasmCompute is not available during SSR"),void d(!1);if("undefined"==typeof Worker)return m("Worker is not supported in this environment"),void d(!1);if("undefined"==typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)return m("WebAssembly is not supported in this environment"),void d(!1);m(null),w(!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}(u);g.current=e;var n=function(e){var n,r=null!=(n=e.data)?n:{},t=r.type,o=r.result,u=r.error;return"ready"===t?(w(!0),void d(!1)):"error"===t?(m(null!=u?u:"Unknown error"),d(!1),void(k.current&&(k.current(new Error(u)),b.current=null,k.current=null))):void("result"===t&&(s(o),d(!1),b.current&&(b.current(o),b.current=null,k.current=null)))};return e.addEventListener("message",n),e.postMessage({type:"init",wasmUrl:r,exportName:o,importObject:null!=i?i:{}}),function(){e.removeEventListener("message",n),e.terminate(),g.current=null,k.current&&(k.current(new Error("Worker terminated")),b.current=null,k.current=null)}},[r,o,u,i]),{compute:e.useCallback(function(e){return new Promise(function(n,r){g.current&&y?p?r(new Error(p)):(b.current=n,k.current=r,d(!0),g.current.postMessage({type:"compute",input:e})):r(new Error("WASM not ready"))})},[y,p]),result:c,loading:l,error:p,ready:y}},exports.useWebRTCIP=function(n){void 0===n&&(n={});var r=n.stunServers,t=void 0===r?d:r,o=n.timeout,u=void 0===o?3e3:o,i=n.onDetect,a=e.useState([]),c=a[0],s=a[1],f=e.useState(!0),v=f[0],p=f[1],m=e.useState(null),h=m[0],y=m[1],w=e.useRef(null),g=e.useRef(null),b=e.useRef(new Set),k=e.useRef(i);return k.current=i,e.useEffect(function(){if("undefined"==typeof window)return p(!1),void y("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return p(!1),void y("RTCPeerConnection is not available");var e=new Set;b.current=e;var n=function(){g.current&&(clearTimeout(g.current),g.current=null),w.current&&(w.current.close(),w.current=null),p(!1)},r=function(n){e.has(n)||(e.add(n),s(function(e){return[].concat(e,[n])}),null==k.current||k.current(n))};try{var o=new RTCPeerConnection({iceServers:[{urls:t}]});w.current=o,o.onicecandidate=function(e){var n,t=e.candidate;t&&t.candidate&&((n=t.candidate.match(l))?[].concat(n):[]).forEach(r)},o.createDataChannel(""),o.createOffer().then(function(e){return o.setLocalDescription(e)}).catch(function(e){y(e instanceof Error?e.message:"Failed to create offer"),n()}),g.current=setTimeout(function(){return n()},u)}catch(e){y(e instanceof Error?e.message:"WebRTC setup failed"),n()}return function(){n()}},[t.join(","),u]),{ips:c,loading:v,error:h}},exports.useWorkerNotifications=function(n,r){void 0===r&&(r={});var t=r.maxHistory,o=void 0===t?100:t,u=r.throughputWindowMs,i=void 0===u?1e3:u,a=e.useState([]),c=a[0],s=a[1],f=e.useState(0),l=f[0],d=f[1],v=e.useState(0),p=v[0],m=v[1],h=e.useState([]),y=h[0],w=h[1],g=e.useState(0),b=g[0],k=g[1],E=e.useRef([]),S=e.useRef(0),x=e.useRef(0);e.useEffect(function(){if(n){var e=function(e){var n=function(e){if(null==e||"object"!=typeof e)return null;var n=e.type;return"task_start"!==n&&"task_end"!==n&&"task_fail"!==n&&"queue_size"!==n?null:{type:n,taskId:"string"==typeof e.taskId?e.taskId:void 0,duration:"number"==typeof e.duration?e.duration:void 0,error:"string"==typeof e.error?e.error:void 0,size:"number"==typeof e.size?e.size:void 0,timestamp:Date.now()}}(e.data);if(n)if(w(function(e){return[].concat(e,[n]).slice(-o)}),"task_start"===n.type&&n.taskId)s(function(e){return e.includes(n.taskId)?e:[].concat(e,[n.taskId])});else if("task_end"===n.type){n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),d(function(e){return e+1});var r=Date.now()-i;E.current=[].concat(E.current.filter(function(e){return e>=r}),[n.timestamp]),"number"==typeof n.duration&&(S.current+=n.duration,x.current+=1)}else"task_fail"===n.type?(n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),m(function(e){return e+1})):"queue_size"===n.type&&"number"==typeof n.size&&k(n.size)};return n.addEventListener("message",e),function(){return n.removeEventListener("message",e)}}},[n,o]);var C=e.useMemo(function(){var e=x.current;return e>0?S.current/e:0},[y]),M=e.useMemo(function(){var e=Date.now()-i;return E.current.filter(function(n){return n>=e}).length/(i/1e3)},[y,i]),P=e.useMemo(function(){return{runningTasks:c,completedCount:l,failedCount:p,averageDurationMs:C,throughputPerSecond:M,currentQueueSize:b,totalProcessed:l+p,recentEventCount:y.length}},[c,l,p,C,M,b,y.length]);return{runningTasks:c,completedCount:l,failedCount:p,eventHistory:y,averageDurationMs:C,throughputPerSecond:M,currentQueueSize:b,progress:P}},exports.useWrappedChildren=function(r,t,o){return void 0===o&&(o="preserve"),e.useMemo(function(){if(!r)return r;var e=function(e){if(!n.isValidElement(e))return e;var r,i=e.props||{};r="override"===o?u({},i,t):u({},t,i);var a=null==i?void 0:i.style,c=null==t?void 0:t.style;return a&&c&&"object"==typeof a&&"object"==typeof c&&(r.style="override"===o?u({},a,c):u({},c,a)),n.cloneElement(e,r)};return Array.isArray(r)?r.map(e):e(r)},[r,t,o])};
1
+ var e=require("react/hooks"),n=require("react"),r=new Map;function t(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 o(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 t(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)?t(e,n):void 0}}(e))||n&&e&&"number"==typeof e.length){r&&(e=r);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(){return u=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var r=arguments[n];for(var t in r)({}).hasOwnProperty.call(r,t)&&(e[t]=r[t])}return e},u.apply(null,arguments)}function i(){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 a(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}var c=new Map;function s(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 l(e,n){return n?e.then(function(e){return null==n.onSuccess||n.onSuccess(e),e}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}var f=/\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,d=["stun:stun.l.google.com:19302"];function v(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 p(e){if(!Array.isArray(e))return[];for(var n=[],r=0;r<e.length&&n.length<50;r++){var t=v(e[r],100);t&&n.push(t)}return n}function m(e){var n=v(e,2048);if(!n)return"";try{var r=new URL(n);if("http:"===r.protocol||"https:"===r.protocol)return n}catch(e){}return""}function g(e){try{if("undefined"==typeof window)return!1;var n=window.getComputedStyle(e);return"none"!==n.display&&"hidden"!==n.visibility&&"0"!==n.opacity}catch(e){return!1}}function h(e){var n={};try{for(var r,t=o(Object.keys(e).slice(0,20));!(r=t()).done;){var u=r.value,i=v(u,50);if(i){var a=e[u];"string"==typeof a?n[i]=a.slice(0,500):"number"==typeof a&&Number.isFinite(a)||"boolean"==typeof a?n[i]=a:Array.isArray(a)&&(n[i]=a.map(function(e){return v(e,200)}).filter(Boolean).slice(0,20))}}}catch(e){}return n}function y(){try{if("undefined"==typeof document||!document.querySelectorAll)return;document.querySelectorAll('script[data-llm="true"]').forEach(function(e){return e.remove()})}catch(e){}}exports.useClipboard=function(n){void 0===n&&(n={});var r=n.resetDelay,t=void 0===r?2e3:r,o=e.useState(!1),u=o[0],i=o[1],c=e.useState(null),s=c[0],l=c[1],f=e.useCallback(function(){i(!1),l(null)},[]);return{copy:e.useCallback(function(e){try{if(l(null),"undefined"==typeof navigator||!navigator.clipboard){var n=new Error("Clipboard API is not available");return l(n),Promise.resolve(!1)}return Promise.resolve(a(function(){return Promise.resolve(navigator.clipboard.writeText(e)).then(function(){return i(!0),t>0&&setTimeout(function(){return i(!1)},t),!0})},function(e){var n=e instanceof Error?e:new Error(String(e));return l(n),!1}))}catch(e){return Promise.reject(e)}},[t]),paste:e.useCallback(function(){try{if(l(null),"undefined"==typeof navigator||!navigator.clipboard){var e=new Error("Clipboard API is not available");return l(e),Promise.resolve("")}return Promise.resolve(a(function(){return Promise.resolve(navigator.clipboard.readText())},function(e){var n=e instanceof Error?e:new Error(String(e));return l(n),""}))}catch(e){return Promise.reject(e)}},[]),copied:u,error:s,reset:f}},exports.useEventBus=function(){return{emit:e.useCallback(function(e){var n=arguments,t=r.get(e);t&&t.forEach(function(e){return e.apply(void 0,[].slice.call(n,1))})},[]),on:e.useCallback(function(e,n){var t=r.get(e);return t||(t=new Set,r.set(e,t)),t.add(n),function(){t.delete(n),0===t.size&&r.delete(e)}},[])}},exports.useIndexedDB=function(n){var r=e.useState(null),t=r[0],i=r[1],a=e.useState(null),f=a[0],d=a[1],v=e.useState(!1),p=v[0],m=v[1],g=e.useRef(n);return g.current=n,e.useEffect(function(){var e=!1;d(null),m(!1),i(null);var n=g.current;return function(e){var n=e.name+"_v"+e.version,r=c.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,u=0,i=Object.keys(t);u<i.length;u++){var a=i[u],c=t[a];if(!r.objectStoreNames.contains(a)){var s,l=r.createObjectStore(a,{keyPath:c.keyPath,autoIncrement:null!=(s=c.autoIncrement)&&s});if(c.indexes)for(var f,d=o(c.indexes);!(f=d()).done;){var v=f.value;l.createIndex(v,v,{unique:!1})}}}}})}(e),c.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 l(s(r("readwrite").add(e)),n)},update:function(e,n,t){var o=r("readwrite");return l(s(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=u({},e,n);return s(o.put(r))}).then(function(){}),t)},delete:function(e,n){return l(s(r("readwrite").delete(e)).then(function(){}),n)},exists:function(e){return s(r("readonly").getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r("readonly").openCursor(),o=[];return l(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 l(s(r("readwrite").put(e)),n)},bulkInsert:function(e,n){var t=r("readwrite"),o=[];if(0===e.length)return l(Promise.resolve(o),n);var u=0;return l(new Promise(function(n,r){e.forEach(function(i,a){var c=t.add(i);c.onsuccess=function(){o[a]=c.result,++u===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 l(s(r("readwrite").clear()).then(function(){}),e)},count:function(e){return l(s(r("readonly").count()),null!=e?e:{})}}}(e,n)}(e,n)},transaction:function(n,r,t,o){var i=e.transaction(n,r),a={table:function(e){return function(e,n){return function(e,n){function r(){return e.objectStore(n)}return{insert:function(e,n){return l(s(r().add(e)),n)},update:function(e,n,t){var o=r();return l(s(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=u({},e,n);return s(o.put(r))}).then(function(){}),t)},delete:function(e,n){return l(s(r().delete(e)).then(function(){}),n)},exists:function(e){return s(r().getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r().openCursor(),o=[];return l(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 l(s(r().put(e)),n)},bulkInsert:function(e,n){var t=r(),o=[];if(0===e.length)return l(Promise.resolve(o),n);var u=0;return l(new Promise(function(n,r){e.forEach(function(i,a){var c=t.add(i);c.onsuccess=function(){o[a]=c.result,++u===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 l(s(r().clear()).then(function(){}),e)},count:function(e){return l(s(r().count()),null!=e?e:{})}}}(e,n)}(i,e)}},c=new Promise(function(e,n){i.oncomplete=function(){return e()},i.onerror=function(){var e;return n(null!=(e=i.error)?e:new DOMException("Transaction failed"))}}),f=t(a);return function(e,n){return n?e.then(function(){return null==n.onSuccess?void 0:n.onSuccess()}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}(Promise.resolve(f).then(function(){return c}),o)}}}(n);i(r),m(!0)}}).catch(function(n){e||d(n)}),function(){e=!0}},[n.name,n.version]),{db:t,isReady:p,error:f}},exports.useLLMMetadata=function(e){var r=n.useRef(null);n.useEffect(function(){try{if("undefined"==typeof window)return;var n=function(e){return null==e||"object"!=typeof e?{route:"/"}:{route:v(e.route,2048)||"/",mode:"auto-extract"===e.mode?"auto-extract":"manual",title:void 0!==e.title?v(e.title,200):void 0,description:void 0!==e.description?v(e.description,2e3):void 0,tags:void 0!==e.tags?p(e.tags):void 0,canonicalUrl:void 0!==e.canonicalUrl?m(e.canonicalUrl):void 0,language:void 0!==e.language?v(e.language,20):void 0,ogType:void 0!==e.ogType?v(e.ogType,50):void 0,ogImage:void 0!==e.ogImage?m(e.ogImage):void 0,ogImageAlt:void 0!==e.ogImageAlt?v(e.ogImageAlt,200):void 0,siteName:void 0!==e.siteName?v(e.siteName,100):void 0,author:void 0!==e.author?v(e.author,200):void 0,publishedTime:void 0!==e.publishedTime?v(e.publishedTime,50):void 0,modifiedTime:void 0!==e.modifiedTime?v(e.modifiedTime,50):void 0,robots:void 0!==e.robots?v(e.robots,100):void 0,extra:void 0===e.extra||"object"!=typeof e.extra||Array.isArray(e.extra)?void 0:h(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,u,i=function(){var e={title:"",outline:[],description:""};try{if("undefined"==typeof document)return e;var n=v(document.title,200),r=[],t="";try{for(var u,i=document.querySelectorAll("nav, footer, [role='navigation'], [role='contentinfo'], script, style, noscript"),a=function(e){for(var n,r=o(i);!(n=r()).done;)if(n.value.contains(e))return!0;return!1},c=o(document.querySelectorAll("h1, h2"));!(u=c()).done;){var s=u.value;if(r.length>=50)break;if(g(s)&&!a(s)){var l=v(s.textContent,300);l&&r.push(l)}}for(var f,d=document.querySelectorAll("p"),p=[],m=o(d);!(f=m()).done;){var h=f.value;if(p.length>=3)break;if(g(h)&&!a(h)){var y=v(h.textContent,1e3);y&&p.push(y)}}t=p.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!=(u=e.description)?u: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 a;return{route:null!=(a=null==e?void 0:e.route)?a:"/",generatedAt:(new Date).toISOString()}}}(n),u=JSON.stringify(t);if(r.current===u)return;return r.current=u,y(),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(){y(),r.current=null}}catch(e){}},[null==e?void 0:e.route,null==e?void 0:e.mode,null==e?void 0:e.title,null==e?void 0:e.description,null==e?void 0:e.tags,null==e?void 0:e.canonicalUrl,null==e?void 0:e.language,null==e?void 0:e.ogType,null==e?void 0:e.ogImage,null==e?void 0:e.ogImageAlt,null==e?void 0:e.siteName,null==e?void 0:e.author,null==e?void 0:e.publishedTime,null==e?void 0:e.modifiedTime,null==e?void 0:e.robots])},exports.useMutationObserver=function(n,r,t){e.useEffect(function(){var e=n.current;if(e){var o=new MutationObserver(r);return o.observe(e,t),function(){return o.disconnect()}}},[n,r,t])},exports.useNetworkState=function(){var n=e.useState(i),r=n[0],t=n[1];return e.useEffect(function(){if("undefined"!=typeof window){var e=function(){return t(i())};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)}}},[]),r},exports.usePreferredTheme=function(){var n=e.useState(function(){if("undefined"==typeof window)return"no-preference";var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");return e.matches?"dark":n.matches?"light":"no-preference"}),r=n[0],t=n[1];return e.useEffect(function(){if("undefined"!=typeof window){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=function(e){t(e.matches?"dark":"light")},r=function(){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");t(e.matches?"dark":n.matches?"light":"no-preference")};e.addEventListener("change",n);var o=window.matchMedia("(prefers-color-scheme: light)");return o.addEventListener("change",r),function(){e.removeEventListener("change",n),o.removeEventListener("change",r)}}},[]),r},exports.useRageClick=function(n,r){var t=r.onRageClick,o=r.threshold,u=void 0===o?5:o,i=r.timeWindow,a=void 0===i?1e3:i,c=r.distanceThreshold,s=void 0===c?30:c,l=e.useRef(t);l.current=t;var f=e.useRef([]);e.useEffect(function(){var e=n.current;if(e){var r=function(e){var n=Date.now(),r={time:n,x:e.clientX,y:e.clientY},t=n-a,o=f.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 l.current({count:i.length,event:e}),void(f.current=[])}else if(o.length>=u)return l.current({count:o.length,event:e}),void(f.current=[]);f.current=o};return e.addEventListener("click",r),function(){return e.removeEventListener("click",r)}}},[n,u,a,s])},exports.useThreadedWorker=function(n,r){var t=r.concurrency,o="sequential"===r.mode?1:Math.max(1,void 0===t?4:t),u=e.useState(!1),i=u[0],a=u[1],c=e.useState(void 0),s=c[0],l=c[1],f=e.useState(void 0),d=f[0],v=f[1],p=e.useState(0),m=p[0],g=p[1],h=e.useRef([]),y=e.useRef(0),w=e.useRef(0),b=e.useRef(!1),k=e.useRef(n);k.current=n;var S=e.useCallback(function(){g(h.current.length+w.current)},[]),E=e.useCallback(function(){if(!(b.current||w.current>=o)){if(0===h.current.length)return 0===w.current&&a(!1),void S();h.current.sort(function(e,n){return e.priority!==n.priority?e.priority-n.priority:e.sequence-n.sequence});var e=h.current.shift();w.current+=1,a(!0),S(),(0,k.current)(e.data).then(function(n){l(n),v(void 0),e.resolve(n)}).catch(function(n){v(n),e.reject(n)}).finally(function(){w.current-=1,S(),E()}),h.current.length>0&&w.current<o&&E()}},[o,S]),x=e.useCallback(function(e,n){var r;if(b.current)return Promise.reject(new Error("Worker is terminated"));var t=null!=(r=null==n?void 0:n.priority)?r:1,o=++y.current,u=new Promise(function(n,r){h.current.push({data:e,priority:t,sequence:o,resolve:n,reject:r})});return S(),a(!0),queueMicrotask(E),u},[E,S]),T=e.useCallback(function(){var e=h.current;h.current=[],e.forEach(function(e){return e.reject(new Error("Task cleared from queue"))}),S(),0===w.current&&a(!1)},[S]),C=e.useCallback(function(){b.current=!0,T()},[T]);return e.useEffect(function(){return function(){b.current=!0}},[]),{run:x,loading:i,result:s,error:d,queueSize:m,clearQueue:T,terminate:C}},exports.useTransition=function(){var n=e.useState(!1),r=n[0],t=n[1];return[e.useCallback(function(e){t(!0),Promise.resolve().then(function(){e(),t(!1)})},[]),r]},exports.useWasmCompute=function(n){var r=n.wasmUrl,t=n.exportName,o=void 0===t?"compute":t,u=n.workerUrl,i=n.importObject,a=e.useState(void 0),c=a[0],s=a[1],l=e.useState(!0),f=l[0],d=l[1],v=e.useState(null),p=v[0],m=v[1],g=e.useState(!1),h=g[0],y=g[1],w=e.useRef(null),b=e.useRef(null),k=e.useRef(null);return e.useEffect(function(){if("undefined"==typeof window)return m("useWasmCompute is not available during SSR"),void d(!1);if("undefined"==typeof Worker)return m("Worker is not supported in this environment"),void d(!1);if("undefined"==typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)return m("WebAssembly is not supported in this environment"),void d(!1);m(null),y(!1);var e=function(e){if(e)return new Worker(e);var n=new Blob(["\nself.onmessage = async (e) => {\n const d = e.data;\n if (d.type === 'init') {\n try {\n const res = await fetch(d.wasmUrl);\n const buf = await res.arrayBuffer();\n const mod = await WebAssembly.instantiate(buf, d.importObject || {});\n self.wasmInstance = mod.instance;\n self.exportName = d.exportName || 'compute';\n self.postMessage({ type: 'ready' });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n return;\n }\n if (d.type === 'compute') {\n try {\n const fn = self.wasmInstance.exports[self.exportName];\n if (typeof fn !== 'function') {\n self.postMessage({ type: 'error', error: 'Export \"' + self.exportName + '\" is not a function' });\n return;\n }\n const result = fn(d.input);\n self.postMessage({ type: 'result', result: result });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n }\n};\n"],{type:"application/javascript"}),r=URL.createObjectURL(n),t=new Worker(r);return URL.revokeObjectURL(r),t}(u);w.current=e;var n=function(e){var n,r=null!=(n=e.data)?n:{},t=r.type,o=r.result,u=r.error;return"ready"===t?(y(!0),void d(!1)):"error"===t?(m(null!=u?u:"Unknown error"),d(!1),void(k.current&&(k.current(new Error(u)),b.current=null,k.current=null))):void("result"===t&&(s(o),d(!1),b.current&&(b.current(o),b.current=null,k.current=null)))};return e.addEventListener("message",n),e.postMessage({type:"init",wasmUrl:r,exportName:o,importObject:null!=i?i:{}}),function(){e.removeEventListener("message",n),e.terminate(),w.current=null,k.current&&(k.current(new Error("Worker terminated")),b.current=null,k.current=null)}},[r,o,u,i]),{compute:e.useCallback(function(e){return new Promise(function(n,r){w.current&&h?p?r(new Error(p)):(b.current=n,k.current=r,d(!0),w.current.postMessage({type:"compute",input:e})):r(new Error("WASM not ready"))})},[h,p]),result:c,loading:f,error:p,ready:h}},exports.useWebRTCIP=function(n){void 0===n&&(n={});var r=n.stunServers,t=void 0===r?d:r,o=n.timeout,u=void 0===o?3e3:o,i=n.onDetect,a=e.useState([]),c=a[0],s=a[1],l=e.useState(!0),v=l[0],p=l[1],m=e.useState(null),g=m[0],h=m[1],y=e.useRef(null),w=e.useRef(null),b=e.useRef(new Set),k=e.useRef(i);return k.current=i,e.useEffect(function(){if("undefined"==typeof window)return p(!1),void h("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return p(!1),void h("RTCPeerConnection is not available");var e=new Set;b.current=e;var n=function(){w.current&&(clearTimeout(w.current),w.current=null),y.current&&(y.current.close(),y.current=null),p(!1)},r=function(n){e.has(n)||(e.add(n),s(function(e){return[].concat(e,[n])}),null==k.current||k.current(n))};try{var o=new RTCPeerConnection({iceServers:[{urls:t}]});y.current=o,o.onicecandidate=function(e){var n,t=e.candidate;t&&t.candidate&&((n=t.candidate.match(f))?[].concat(n):[]).forEach(r)},o.createDataChannel(""),o.createOffer().then(function(e){return o.setLocalDescription(e)}).catch(function(e){h(e instanceof Error?e.message:"Failed to create offer"),n()}),w.current=setTimeout(function(){return n()},u)}catch(e){h(e instanceof Error?e.message:"WebRTC setup failed"),n()}return function(){n()}},[t.join(","),u]),{ips:c,loading:v,error:g}},exports.useWorkerNotifications=function(n,r){void 0===r&&(r={});var t=r.maxHistory,o=void 0===t?100:t,u=r.throughputWindowMs,i=void 0===u?1e3:u,a=e.useState([]),c=a[0],s=a[1],l=e.useState(0),f=l[0],d=l[1],v=e.useState(0),p=v[0],m=v[1],g=e.useState([]),h=g[0],y=g[1],w=e.useState(0),b=w[0],k=w[1],S=e.useRef([]),E=e.useRef(0),x=e.useRef(0);e.useEffect(function(){if(n){var e=function(e){var n=function(e){if(null==e||"object"!=typeof e)return null;var n=e.type;return"task_start"!==n&&"task_end"!==n&&"task_fail"!==n&&"queue_size"!==n?null:{type:n,taskId:"string"==typeof e.taskId?e.taskId:void 0,duration:"number"==typeof e.duration?e.duration:void 0,error:"string"==typeof e.error?e.error:void 0,size:"number"==typeof e.size?e.size:void 0,timestamp:Date.now()}}(e.data);if(n)if(y(function(e){return[].concat(e,[n]).slice(-o)}),"task_start"===n.type&&n.taskId)s(function(e){return e.includes(n.taskId)?e:[].concat(e,[n.taskId])});else if("task_end"===n.type){n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),d(function(e){return e+1});var r=Date.now()-i;S.current=[].concat(S.current.filter(function(e){return e>=r}),[n.timestamp]),"number"==typeof n.duration&&(E.current+=n.duration,x.current+=1)}else"task_fail"===n.type?(n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),m(function(e){return e+1})):"queue_size"===n.type&&"number"==typeof n.size&&k(n.size)};return n.addEventListener("message",e),function(){return n.removeEventListener("message",e)}}},[n,o]);var T=e.useMemo(function(){var e=x.current;return e>0?E.current/e:0},[h]),C=e.useMemo(function(){var e=Date.now()-i;return S.current.filter(function(n){return n>=e}).length/(i/1e3)},[h,i]),I=e.useMemo(function(){return{runningTasks:c,completedCount:f,failedCount:p,averageDurationMs:T,throughputPerSecond:C,currentQueueSize:b,totalProcessed:f+p,recentEventCount:h.length}},[c,f,p,T,C,b,h.length]);return{runningTasks:c,completedCount:f,failedCount:p,eventHistory:h,averageDurationMs:T,throughputPerSecond:C,currentQueueSize:b,progress:I}},exports.useWrappedChildren=function(r,t,o){return void 0===o&&(o="preserve"),e.useMemo(function(){if(!r)return r;var e=function(e){if(!n.isValidElement(e))return e;var r,i=e.props||{};r="override"===o?u({},i,t):u({},t,i);var a=null==i?void 0:i.style,c=null==t?void 0:t.style;return a&&c&&"object"==typeof a&&"object"==typeof c&&(r.style="override"===o?u({},a,c):u({},c,a)),n.cloneElement(e,r)};return Array.isArray(r)?r.map(e):e(r)},[r,t,o])};
@@ -1 +1 @@
1
- import{useState as e,useCallback as r,useEffect as n,useMemo as t,useRef as o}from"react/hooks";import{isValidElement as s,cloneElement as i}from"react";function c(){const[n,t]=e(!1);return[r(e=>{t(!0),Promise.resolve().then(()=>{e(),t(!1)})},[]),n]}function u(e,r,t){n(()=>{const n=e.current;if(!n)return;const o=new MutationObserver(r);return o.observe(n,t),()=>o.disconnect()},[e,r,t])}const a=new Map;function l(){return{emit:r((e,...r)=>{const n=a.get(e);n&&n.forEach(e=>e(...r))},[]),on:r((e,r)=>{let n=a.get(e);return n||(n=new Set,a.set(e,n)),n.add(r),()=>{n.delete(r),0===n.size&&a.delete(e)}},[])}}function d(){return d=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var t in n)({}).hasOwnProperty.call(n,t)&&(e[t]=n[t])}return e},d.apply(null,arguments)}function f(e,r,n="preserve"){return t(()=>{if(!e)return e;const t=e=>{if(!s(e))return e;const t=e.props||{};let o;o="override"===n?d({},t,r):d({},r,t);const c=null==t?void 0:t.style,u=null==r?void 0:r.style;return c&&u&&"object"==typeof c&&"object"==typeof u&&(o.style="override"===n?d({},c,u):d({},u,c)),i(e,o)};return Array.isArray(e)?e.map(t):t(e)},[e,r,n])}function p(){const[r,t]=e(()=>{if("undefined"==typeof window)return"no-preference";const e=window.matchMedia("(prefers-color-scheme: dark)"),r=window.matchMedia("(prefers-color-scheme: light)");return e.matches?"dark":r.matches?"light":"no-preference"});return n(()=>{if("undefined"==typeof window)return;const e=window.matchMedia("(prefers-color-scheme: dark)"),r=e=>{t(e.matches?"dark":"light")},n=()=>{const e=window.matchMedia("(prefers-color-scheme: dark)"),r=window.matchMedia("(prefers-color-scheme: light)");t(e.matches?"dark":r.matches?"light":"no-preference")};e.addEventListener("change",r);const o=window.matchMedia("(prefers-color-scheme: light)");return o.addEventListener("change",n),()=>{e.removeEventListener("change",r),o.removeEventListener("change",n)}},[]),r}function v(){if("undefined"==typeof navigator)return{online:!0};const e={online:navigator.onLine},r=navigator.connection;return r&&(void 0!==r.effectiveType&&(e.effectiveType=r.effectiveType),void 0!==r.downlink&&(e.downlink=r.downlink),void 0!==r.rtt&&(e.rtt=r.rtt),void 0!==r.saveData&&(e.saveData=r.saveData),void 0!==r.type&&(e.connectionType=r.type)),e}function m(){const[r,t]=e(v);return n(()=>{if("undefined"==typeof window)return;const e=()=>t(v());window.addEventListener("online",e),window.addEventListener("offline",e);const r=navigator.connection;return null!=r&&r.addEventListener&&r.addEventListener("change",e),()=>{window.removeEventListener("online",e),window.removeEventListener("offline",e),null!=r&&r.removeEventListener&&r.removeEventListener("change",e)}},[]),r}function h(n={}){const{resetDelay:t=2e3}=n,[o,s]=e(!1),[i,c]=e(null),u=r(()=>{s(!1),c(null)},[]);return{copy:r(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),s(!0),t>0&&setTimeout(()=>s(!1),t),!0}catch(e){const r=e instanceof Error?e:new Error(String(e));return c(r),!1}},[t]),paste:r(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 r=e instanceof Error?e:new Error(String(e));return c(r),""}},[]),copied:o,error:i,reset:u}}function w(e,r){const{onRageClick:t,threshold:s=5,timeWindow:i=1e3,distanceThreshold:c=30}=r,u=o(t);u.current=t;const a=o([]);n(()=>{const r=e.current;if(!r)return;const n=e=>{const r=Date.now(),n={time:r,x:e.clientX,y:e.clientY},t=r-i,o=a.current.filter(e=>e.time>=t);if(o.push(n),Infinity!==c){const r=o.filter(e=>{return r=e,t=n,Math.hypot(t.x-r.x,t.y-r.y)<=c;var r,t});if(r.length>=s)return u.current({count:r.length,event:e}),void(a.current=[])}else if(o.length>=s)return u.current({count:o.length,event:e}),void(a.current=[]);a.current=o};return r.addEventListener("click",n),()=>r.removeEventListener("click",n)},[e,s,i,c])}function y(t,s){const{mode:i,concurrency:c=4}=s,u="sequential"===i?1:Math.max(1,c),[a,l]=e(!1),[d,f]=e(void 0),[p,v]=e(void 0),[m,h]=e(0),w=o([]),y=o(0),g=o(0),b=o(!1),E=o(t);E.current=t;const k=r(()=>{h(w.current.length+g.current)},[]),x=r(()=>{if(b.current)return;if(g.current>=u)return;if(0===w.current.length)return 0===g.current&&l(!1),void k();w.current.sort((e,r)=>e.priority!==r.priority?e.priority-r.priority:e.sequence-r.sequence);const e=w.current.shift();g.current+=1,l(!0),k(),(0,E.current)(e.data).then(r=>{f(r),v(void 0),e.resolve(r)}).catch(r=>{v(r),e.reject(r)}).finally(()=>{g.current-=1,k(),x()}),w.current.length>0&&g.current<u&&x()},[u,k]),M=r((e,r)=>{var n;if(b.current)return Promise.reject(new Error("Worker is terminated"));const t=null!=(n=null==r?void 0:r.priority)?n:1,o=++y.current,s=new Promise((r,n)=>{w.current.push({data:e,priority:t,sequence:o,resolve:r,reject:n})});return k(),l(!0),queueMicrotask(x),s},[x,k]),S=r(()=>{const e=w.current;w.current=[],e.forEach(e=>e.reject(new Error("Task cleared from queue"))),k(),0===g.current&&l(!1)},[k]),P=r(()=>{b.current=!0,S()},[S]);return n(()=>()=>{b.current=!0},[]),{run:M,loading:a,result:d,error:p,queueSize:m,clearQueue:S,terminate:P}}const g=new Map;function b(e){return new Promise((r,n)=>{e.onsuccess=()=>r(e.result),e.onerror=()=>{var r;return n(null!=(r=e.error)?r:new DOMException("Unknown IndexedDB error"))}})}function E(e,r){return r?e.then(e=>(null==r.onSuccess||r.onSuccess(e),e)).catch(e=>{throw null==r.onError||r.onError(e),e}):e}function k(r){const[t,s]=e(null),[i,c]=e(null),[u,a]=e(!1),l=o(r);return l.current=r,n(()=>{let e=!1;c(null),a(!1),s(null);const{name:r,version:n,tables:t}=l.current;return function(e){const r=`${e.name}_v${e.version}`;let n=g.get(r);return n||(n=function(e){return new Promise((r,n)=>{const t=indexedDB.open(e.name,e.version);t.onerror=()=>{var e;return n(null!=(e=t.error)?e:new DOMException("Failed to open database"))},t.onsuccess=()=>r(t.result),t.onupgradeneeded=r=>{const n=r.target.result,t=e.tables;for(const e of Object.keys(t)){const r=t[e];if(!n.objectStoreNames.contains(e)){var o;const t=n.createObjectStore(e,{keyPath:r.keyPath,autoIncrement:null!=(o=r.autoIncrement)&&o});if(r.indexes)for(const e of r.indexes)t.createIndex(e,e,{unique:!1})}}}})}(e),g.set(r,n),n)}({name:r,version:n,tables:t}).then(r=>{if(e)return void r.close();const n=function(e){return{get db(){return e},hasTable:r=>e.objectStoreNames.contains(r),table:r=>function(e,r){return function(e,r){function n(n){return e.transaction([r],n).objectStore(r)}return{insert:(e,r)=>E(b(n("readwrite").add(e)),r),update(e,r,t){const o=n("readwrite");return E(b(o.get(e)).then(e=>{if(void 0===e)throw new DOMException("Key not found","NotFoundError");const n=d({},e,r);return b(o.put(n))}).then(()=>{}),t)},delete:(e,r)=>E(b(n("readwrite").delete(e)).then(()=>{}),r),exists:e=>b(n("readonly").getKey(e)).then(e=>void 0!==e),query(e,r){const t=n("readonly").openCursor(),o=[];return E(new Promise((r,n)=>{t.onsuccess=()=>{const n=t.result;n?(e(n.value)&&o.push(n.value),n.continue()):r(o)},t.onerror=()=>{var e;return n(null!=(e=t.error)?e:new DOMException("Unknown error"))}}),r)},upsert:(e,r)=>E(b(n("readwrite").put(e)),r),bulkInsert(e,r){const t=n("readwrite"),o=[];if(0===e.length)return E(Promise.resolve(o),r);let s=0;return E(new Promise((r,n)=>{e.forEach((i,c)=>{const u=t.add(i);u.onsuccess=()=>{o[c]=u.result,s++,s===e.length&&r(o)},u.onerror=()=>{var e;return n(null!=(e=u.error)?e:new DOMException("Unknown error"))}})}),r)},clear:e=>E(b(n("readwrite").clear()).then(()=>{}),e),count:e=>E(b(n("readonly").count()),null!=e?e:{})}}(e,r)}(e,r),transaction(r,n,t,o){const s=e.transaction(r,n),i={table:e=>function(e,r){return function(e,r){function n(){return e.objectStore(r)}return{insert:(e,r)=>E(b(n().add(e)),r),update(e,r,t){const o=n();return E(b(o.get(e)).then(e=>{if(void 0===e)throw new DOMException("Key not found","NotFoundError");const n=d({},e,r);return b(o.put(n))}).then(()=>{}),t)},delete:(e,r)=>E(b(n().delete(e)).then(()=>{}),r),exists:e=>b(n().getKey(e)).then(e=>void 0!==e),query(e,r){const t=n().openCursor(),o=[];return E(new Promise((r,n)=>{t.onsuccess=()=>{const n=t.result;n?(e(n.value)&&o.push(n.value),n.continue()):r(o)},t.onerror=()=>{var e;return n(null!=(e=t.error)?e:new DOMException("Unknown error"))}}),r)},upsert:(e,r)=>E(b(n().put(e)),r),bulkInsert(e,r){const t=n(),o=[];if(0===e.length)return E(Promise.resolve(o),r);let s=0;return E(new Promise((r,n)=>{e.forEach((i,c)=>{const u=t.add(i);u.onsuccess=()=>{o[c]=u.result,s++,s===e.length&&r(o)},u.onerror=()=>{var e;return n(null!=(e=u.error)?e:new DOMException("Unknown error"))}})}),r)},clear:e=>E(b(n().clear()).then(()=>{}),e),count:e=>E(b(n().count()),null!=e?e:{})}}(e,r)}(s,e)},c=new Promise((e,r)=>{s.oncomplete=()=>e(),s.onerror=()=>{var e;return r(null!=(e=s.error)?e:new DOMException("Transaction failed"))}}),u=t(i);return function(e,r){return r?e.then(()=>null==r.onSuccess?void 0:r.onSuccess()).catch(e=>{throw null==r.onError||r.onError(e),e}):e}(Promise.resolve(u).then(()=>c),o)}}}(r);s(n),a(!0)}).catch(r=>{e||c(r)}),()=>{e=!0}},[r.name,r.version]),{db:t,isReady:u,error:i}}const x=/\b(?:25[0-5]|2[0-4]\d|1?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|1?\d{1,2})){3}\b/g,M=["stun:stun.l.google.com:19302"],S=3e3;function P(r={}){const{stunServers:t=M,timeout:s=S,onDetect:i}=r,[c,u]=e([]),[a,l]=e(!0),[d,f]=e(null),p=o(null),v=o(null),m=o(new Set),h=o(i);return h.current=i,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;m.current=e;const r=()=>{v.current&&(clearTimeout(v.current),v.current=null),p.current&&(p.current.close(),p.current=null),l(!1)},n=r=>{e.has(r)||(e.add(r),u(e=>[...e,r]),null==h.current||h.current(r))};try{const e=new RTCPeerConnection({iceServers:[{urls:t}]});p.current=e,e.onicecandidate=e=>{const r=e.candidate;r&&r.candidate&&function(e){const r=e.match(x);return r?[...r]:[]}(r.candidate).forEach(n)},e.createDataChannel(""),e.createOffer().then(r=>e.setLocalDescription(r)).catch(e=>{f(e instanceof Error?e.message:"Failed to create offer"),r()}),v.current=setTimeout(()=>r(),s)}catch(e){f(e instanceof Error?e.message:"WebRTC setup failed"),r()}return()=>{r()}},[t.join(","),s]),{ips:c,loading:a,error:d}}function D(t){const{wasmUrl:s,exportName:i="compute",workerUrl:c,importObject:u}=t,[a,l]=e(void 0),[d,f]=e(!0),[p,v]=e(null),[m,h]=e(!1),w=o(null),y=o(null),g=o(null);return n(()=>{if("undefined"==typeof window)return v("useWasmCompute is not available during SSR"),void f(!1);if("undefined"==typeof Worker)return v("Worker is not supported in this environment"),void f(!1);if("undefined"==typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)return v("WebAssembly is not supported in this environment"),void f(!1);v(null),h(!1);const e=function(e){if(e)return new Worker(e);const r=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(r),t=new Worker(n);return URL.revokeObjectURL(n),t}(c);w.current=e;const r=e=>{var r;const{type:n,result:t,error:o}=null!=(r=e.data)?r:{};return"ready"===n?(h(!0),void f(!1)):"error"===n?(v(null!=o?o:"Unknown error"),f(!1),void(g.current&&(g.current(new Error(o)),y.current=null,g.current=null))):void("result"===n&&(l(t),f(!1),y.current&&(y.current(t),y.current=null,g.current=null)))};return e.addEventListener("message",r),e.postMessage({type:"init",wasmUrl:s,exportName:i,importObject:null!=u?u:{}}),()=>{e.removeEventListener("message",r),e.terminate(),w.current=null,g.current&&(g.current(new Error("Worker terminated")),y.current=null,g.current=null)}},[s,i,c,u]),{compute:r(e=>new Promise((r,n)=>{w.current&&m?p?n(new Error(p)):(y.current=r,g.current=n,f(!0),w.current.postMessage({type:"compute",input:e})):n(new Error("WASM not ready"))}),[m,p]),result:a,loading:d,error:p,ready:m}}function L(r,s={}){const{maxHistory:i=100,throughputWindowMs:c=1e3}=s,[u,a]=e([]),[l,d]=e(0),[f,p]=e(0),[v,m]=e([]),[h,w]=e(0),y=o([]),g=o(0),b=o(0);n(()=>{if(!r)return;const e=e=>{const r=function(e){if(null==e||"object"!=typeof e)return null;const r=e.type;return"task_start"!==r&&"task_end"!==r&&"task_fail"!==r&&"queue_size"!==r?null:{type:r,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(r)if(m(e=>[...e,r].slice(-i)),"task_start"===r.type&&r.taskId)a(e=>e.includes(r.taskId)?e:[...e,r.taskId]);else if("task_end"===r.type){r.taskId&&a(e=>e.filter(e=>e!==r.taskId)),d(e=>e+1);const e=Date.now()-c;y.current=[...y.current.filter(r=>r>=e),r.timestamp],"number"==typeof r.duration&&(g.current+=r.duration,b.current+=1)}else"task_fail"===r.type?(r.taskId&&a(e=>e.filter(e=>e!==r.taskId)),p(e=>e+1)):"queue_size"===r.type&&"number"==typeof r.size&&w(r.size)};return r.addEventListener("message",e),()=>r.removeEventListener("message",e)},[r,i]);const E=t(()=>{const e=b.current;return e>0?g.current/e:0},[v]),k=t(()=>{const e=Date.now()-c;return y.current.filter(r=>r>=e).length/(c/1e3)},[v,c]),x=t(()=>({runningTasks:u,completedCount:l,failedCount:f,averageDurationMs:E,throughputPerSecond:k,currentQueueSize:h,totalProcessed:l+f,recentEventCount:v.length}),[u,l,f,E,k,h,v.length]);return{runningTasks:u,completedCount:l,failedCount:f,eventHistory:v,averageDurationMs:E,throughputPerSecond:k,currentQueueSize:h,progress:x}}export{h as useClipboard,l as useEventBus,k as useIndexedDB,u as useMutationObserver,m as useNetworkState,p as usePreferredTheme,w as useRageClick,y as useThreadedWorker,c as useTransition,D as useWasmCompute,P as useWebRTCIP,L as useWorkerNotifications,f as useWrappedChildren};
1
+ import{useState as e,useCallback as t,useEffect as n,useMemo as r,useRef as o}from"react/hooks";import{isValidElement as i,cloneElement as u,useRef as c,useEffect as s}from"react";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,s=null==t?void 0:t.style;return c&&s&&"object"==typeof c&&"object"==typeof s&&(o.style="override"===n?p({},c,s):p({},s,c)),u(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 y(n={}){const{resetDelay:r=2e3}=n,[o,i]=e(!1),[u,c]=e(null),s=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:u,reset:s}}function w(e,t){const{onRageClick:r,threshold:i=5,timeWindow:u=1e3,distanceThreshold:c=30}=t,s=o(r);s.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-u,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 s.current({count:t.length,event:e}),void(a.current=[])}else if(o.length>=i)return s.current({count:o.length,event:e}),void(a.current=[]);a.current=o};return t.addEventListener("click",n),()=>t.removeEventListener("click",n)},[e,i,u,c])}function b(r,i){const{mode:u,concurrency:c=4}=i,s="sequential"===u?1:Math.max(1,c),[a,l]=e(!1),[d,f]=e(void 0),[p,m]=e(void 0),[v,g]=e(0),h=o([]),y=o(0),w=o(0),b=o(!1),E=o(r);E.current=r;const k=t(()=>{g(h.current.length+w.current)},[]),x=t(()=>{if(b.current)return;if(w.current>=s)return;if(0===h.current.length)return 0===w.current&&l(!1),void k();h.current.sort((e,t)=>e.priority!==t.priority?e.priority-t.priority:e.sequence-t.sequence);const e=h.current.shift();w.current+=1,l(!0),k(),(0,E.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(),x()}),h.current.length>0&&w.current<s&&x()},[s,k]),S=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=++y.current,i=new Promise((t,n)=>{h.current.push({data:e,priority:r,sequence:o,resolve:t,reject:n})});return k(),l(!0),queueMicrotask(x),i},[x,k]),T=t(()=>{const e=h.current;h.current=[],e.forEach(e=>e.reject(new Error("Task cleared from queue"))),k(),0===w.current&&l(!1)},[k]),I=t(()=>{b.current=!0,T()},[T]);return n(()=>()=>{b.current=!0},[]),{run:S,loading:a,result:d,error:p,queueSize:v,clearQueue:T,terminate:I}}const E=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 x(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 S(t){const[r,i]=e(null),[u,c]=e(null),[s,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=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)=>x(k(n("readwrite").add(e)),t),update(e,t,r){const o=n("readwrite");return x(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)=>x(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 x(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)=>x(k(n("readwrite").put(e)),t),bulkInsert(e,t){const r=n("readwrite"),o=[];if(0===e.length)return x(Promise.resolve(o),t);let i=0;return x(new Promise((t,n)=>{e.forEach((u,c)=>{const s=r.add(u);s.onsuccess=()=>{o[c]=s.result,i++,i===e.length&&t(o)},s.onerror=()=>{var e;return n(null!=(e=s.error)?e:new DOMException("Unknown error"))}})}),t)},clear:e=>x(k(n("readwrite").clear()).then(()=>{}),e),count:e=>x(k(n("readonly").count()),null!=e?e:{})}}(e,t)}(e,t),transaction(t,n,r,o){const i=e.transaction(t,n),u={table:e=>function(e,t){return function(e,t){function n(){return e.objectStore(t)}return{insert:(e,t)=>x(k(n().add(e)),t),update(e,t,r){const o=n();return x(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)=>x(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 x(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)=>x(k(n().put(e)),t),bulkInsert(e,t){const r=n(),o=[];if(0===e.length)return x(Promise.resolve(o),t);let i=0;return x(new Promise((t,n)=>{e.forEach((u,c)=>{const s=r.add(u);s.onsuccess=()=>{o[c]=s.result,i++,i===e.length&&t(o)},s.onerror=()=>{var e;return n(null!=(e=s.error)?e:new DOMException("Unknown error"))}})}),t)},clear:e=>x(k(n().clear()).then(()=>{}),e),count:e=>x(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"))}}),s=r(u);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(s).then(()=>c),o)}}}(t);i(n),a(!0)}).catch(t=>{e||c(t)}),()=>{e=!0}},[t.name,t.version]),{db:r,isReady:s,error:u}}const T=/\b(?:25[0-5]|2[0-4]\d|1?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|1?\d{1,2})){3}\b/g,I=["stun:stun.l.google.com:19302"],M=3e3;function A(t={}){const{stunServers:r=I,timeout:i=M,onDetect:u}=t,[c,s]=e([]),[a,l]=e(!0),[d,f]=e(null),p=o(null),m=o(null),v=o(new Set),g=o(u);return g.current=u,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;v.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),s(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(T);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 j(r){const{wasmUrl:i,exportName:u="compute",workerUrl:c,importObject:s}=r,[a,l]=e(void 0),[d,f]=e(!0),[p,m]=e(null),[v,g]=e(!1),h=o(null),y=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),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(w.current&&(w.current(new Error(o)),y.current=null,w.current=null))):void("result"===n&&(l(r),f(!1),y.current&&(y.current(r),y.current=null,w.current=null)))};return e.addEventListener("message",t),e.postMessage({type:"init",wasmUrl:i,exportName:u,importObject:null!=s?s:{}}),()=>{e.removeEventListener("message",t),e.terminate(),h.current=null,w.current&&(w.current(new Error("Worker terminated")),y.current=null,w.current=null)}},[i,u,c,s]),{compute:t(e=>new Promise((t,n)=>{h.current&&v?p?n(new Error(p)):(y.current=t,w.current=n,f(!0),h.current.postMessage({type:"compute",input:e})):n(new Error("WASM not ready"))}),[v,p]),result:a,loading:d,error:p,ready:v}}function O(t,i={}){const{maxHistory:u=100,throughputWindowMs:c=1e3}=i,[s,a]=e([]),[l,d]=e(0),[f,p]=e(0),[m,v]=e([]),[g,h]=e(0),y=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(v(e=>[...e,t].slice(-u)),"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;y.current=[...y.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&&h(t.size)};return t.addEventListener("message",e),()=>t.removeEventListener("message",e)},[t,u]);const E=r(()=>{const e=b.current;return e>0?w.current/e:0},[m]),k=r(()=>{const e=Date.now()-c;return y.current.filter(t=>t>=e).length/(c/1e3)},[m,c]),x=r(()=>({runningTasks:s,completedCount:l,failedCount:f,averageDurationMs:E,throughputPerSecond:k,currentQueueSize:g,totalProcessed:l+f,recentEventCount:m.length}),[s,l,f,E,k,g,m.length]);return{runningTasks:s,completedCount:l,failedCount:f,eventHistory:m,averageDurationMs:E,throughputPerSecond:k,currentQueueSize:g,progress:x}}function D(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 P(e){if(!Array.isArray(e))return[];const t=[];for(let n=0;n<e.length&&t.length<50;n++){const r=D(e[n],100);r&&t.push(r)}return t}function C(e){const t=D(e,2048);if(!t)return"";try{const e=new URL(t);if("http:"===e.protocol||"https:"===e.protocol)return t}catch(e){}return""}function L(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 U(e){const t={};try{for(const n of Object.keys(e).slice(0,20)){const r=D(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=>D(e,200)).filter(Boolean).slice(0,20))}}catch(e){}return t}function N(){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);s(()=>{try{if("undefined"==typeof window)return;const n=function(e){return null==e||"object"!=typeof e?{route:"/"}:{route:D(e.route,2048)||"/",mode:"auto-extract"===e.mode?"auto-extract":"manual",title:void 0!==e.title?D(e.title,200):void 0,description:void 0!==e.description?D(e.description,2e3):void 0,tags:void 0!==e.tags?P(e.tags):void 0,canonicalUrl:void 0!==e.canonicalUrl?C(e.canonicalUrl):void 0,language:void 0!==e.language?D(e.language,20):void 0,ogType:void 0!==e.ogType?D(e.ogType,50):void 0,ogImage:void 0!==e.ogImage?C(e.ogImage):void 0,ogImageAlt:void 0!==e.ogImageAlt?D(e.ogImageAlt,200):void 0,siteName:void 0!==e.siteName?D(e.siteName,100):void 0,author:void 0!==e.author?D(e.author,200):void 0,publishedTime:void 0!==e.publishedTime?D(e.publishedTime,50):void 0,modifiedTime:void 0!==e.modifiedTime?D(e.modifiedTime,50):void 0,robots:void 0!==e.robots?D(e.robots,100):void 0,extra:void 0===e.extra||"object"!=typeof e.extra||Array.isArray(e.extra)?void 0:U(e.extra)}}(e),r=function(e){try{const r=(new Date).toISOString(),o={route:e.route,generatedAt:r};if("auto-extract"===e.mode){var t,n;const r=function(){const e={title:"",outline:[],description:""};try{if("undefined"==typeof document)return e;const t=D(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(L(e)&&!t(e)){const t=D(e.textContent,300);t&&n.push(t)}}const i=document.querySelectorAll("p"),u=[];for(const e of i){if(u.length>=3)break;if(L(e)&&!t(e)){const t=D(e.textContent,1e3);t&&u.push(t)}}r=u.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,N(),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),()=>{N(),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])}export{y as useClipboard,f as useEventBus,S as useIndexedDB,q as useLLMMetadata,l as useMutationObserver,h as useNetworkState,v as usePreferredTheme,w as useRageClick,b as useThreadedWorker,a as useTransition,j as useWasmCompute,A as useWebRTCIP,O as useWorkerNotifications,m as useWrappedChildren};
@@ -1 +1 @@
1
- import{useState as n,useCallback as e,useEffect as r,useMemo as t,useRef as o}from"react/hooks";import{isValidElement as u,cloneElement as i}from"react";function c(){var r=n(!1),t=r[0],o=r[1];return[e(function(n){o(!0),Promise.resolve().then(function(){n(),o(!1)})},[]),t]}function a(n,e,t){r(function(){var r=n.current;if(r){var o=new MutationObserver(e);return o.observe(r,t),function(){return o.disconnect()}}},[n,e,t])}var s=new Map;function f(){var n=e(function(n){var e=arguments,r=s.get(n);r&&r.forEach(function(n){return n.apply(void 0,[].slice.call(e,1))})},[]);return{emit:n,on:e(function(n,e){var r=s.get(n);return r||(r=new Set,s.set(n,r)),r.add(e),function(){r.delete(e),0===r.size&&s.delete(n)}},[])}}function l(n,e){(null==e||e>n.length)&&(e=n.length);for(var r=0,t=Array(e);r<e;r++)t[r]=n[r];return t}function d(n,e){var r="undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(r)return(r=r.call(n)).next.bind(r);if(Array.isArray(n)||(r=function(n,e){if(n){if("string"==typeof n)return l(n,e);var r={}.toString.call(n).slice(8,-1);return"Object"===r&&n.constructor&&(r=n.constructor.name),"Map"===r||"Set"===r?Array.from(n):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?l(n,e):void 0}}(n))||e&&n&&"number"==typeof n.length){r&&(n=r);var t=0;return function(){return t>=n.length?{done:!0}:{done:!1,value:n[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 v(){return v=Object.assign?Object.assign.bind():function(n){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var t in r)({}).hasOwnProperty.call(r,t)&&(n[t]=r[t])}return n},v.apply(null,arguments)}function p(n,e,r){return void 0===r&&(r="preserve"),t(function(){if(!n)return n;var t=function(n){if(!u(n))return n;var t,o=n.props||{};t="override"===r?v({},o,e):v({},e,o);var c=null==o?void 0:o.style,a=null==e?void 0:e.style;return c&&a&&"object"==typeof c&&"object"==typeof a&&(t.style="override"===r?v({},c,a):v({},a,c)),i(n,t)};return Array.isArray(n)?n.map(t):t(n)},[n,e,r])}function m(){var e=n(function(){if("undefined"==typeof window)return"no-preference";var n=window.matchMedia("(prefers-color-scheme: dark)"),e=window.matchMedia("(prefers-color-scheme: light)");return n.matches?"dark":e.matches?"light":"no-preference"}),t=e[0],o=e[1];return r(function(){if("undefined"!=typeof window){var n=window.matchMedia("(prefers-color-scheme: dark)"),e=function(n){o(n.matches?"dark":"light")},r=function(){var n=window.matchMedia("(prefers-color-scheme: dark)"),e=window.matchMedia("(prefers-color-scheme: light)");o(n.matches?"dark":e.matches?"light":"no-preference")};n.addEventListener("change",e);var t=window.matchMedia("(prefers-color-scheme: light)");return t.addEventListener("change",r),function(){n.removeEventListener("change",e),t.removeEventListener("change",r)}}},[]),t}function h(){if("undefined"==typeof navigator)return{online:!0};var n={online:navigator.onLine},e=navigator.connection;return e&&(void 0!==e.effectiveType&&(n.effectiveType=e.effectiveType),void 0!==e.downlink&&(n.downlink=e.downlink),void 0!==e.rtt&&(n.rtt=e.rtt),void 0!==e.saveData&&(n.saveData=e.saveData),void 0!==e.type&&(n.connectionType=e.type)),n}function y(){var e=n(h),t=e[0],o=e[1];return r(function(){if("undefined"!=typeof window){var n=function(){return o(h())};window.addEventListener("online",n),window.addEventListener("offline",n);var e=navigator.connection;return null!=e&&e.addEventListener&&e.addEventListener("change",n),function(){window.removeEventListener("online",n),window.removeEventListener("offline",n),null!=e&&e.removeEventListener&&e.removeEventListener("change",n)}}},[]),t}function w(n,e){try{var r=n()}catch(n){return e(n)}return r&&r.then?r.then(void 0,e):r}function g(r){void 0===r&&(r={});var t=r.resetDelay,o=void 0===t?2e3:t,u=n(!1),i=u[0],c=u[1],a=n(null),s=a[0],f=a[1],l=e(function(){c(!1),f(null)},[]);return{copy:e(function(n){try{if(f(null),"undefined"==typeof navigator||!navigator.clipboard){var e=new Error("Clipboard API is not available");return f(e),Promise.resolve(!1)}return Promise.resolve(w(function(){return Promise.resolve(navigator.clipboard.writeText(n)).then(function(){return c(!0),o>0&&setTimeout(function(){return c(!1)},o),!0})},function(n){var e=n instanceof Error?n:new Error(String(n));return f(e),!1}))}catch(n){return Promise.reject(n)}},[o]),paste:e(function(){try{if(f(null),"undefined"==typeof navigator||!navigator.clipboard){var n=new Error("Clipboard API is not available");return f(n),Promise.resolve("")}return Promise.resolve(w(function(){return Promise.resolve(navigator.clipboard.readText())},function(n){var e=n instanceof Error?n:new Error(String(n));return f(e),""}))}catch(n){return Promise.reject(n)}},[]),copied:i,error:s,reset:l}}function b(n,e){var t=e.onRageClick,u=e.threshold,i=void 0===u?5:u,c=e.timeWindow,a=void 0===c?1e3:c,s=e.distanceThreshold,f=void 0===s?30:s,l=o(t);l.current=t;var d=o([]);r(function(){var e=n.current;if(e){var r=function(n){var e=Date.now(),r={time:e,x:n.clientX,y:n.clientY},t=e-a,o=d.current.filter(function(n){return n.time>=t});if(o.push(r),Infinity!==f){var u=o.filter(function(n){return e=n,t=r,Math.hypot(t.x-e.x,t.y-e.y)<=f;var e,t});if(u.length>=i)return l.current({count:u.length,event:n}),void(d.current=[])}else if(o.length>=i)return l.current({count:o.length,event:n}),void(d.current=[]);d.current=o};return e.addEventListener("click",r),function(){return e.removeEventListener("click",r)}}},[n,i,a,f])}function E(t,u){var i=u.concurrency,c="sequential"===u.mode?1:Math.max(1,void 0===i?4:i),a=n(!1),s=a[0],f=a[1],l=n(void 0),d=l[0],v=l[1],p=n(void 0),m=p[0],h=p[1],y=n(0),w=y[0],g=y[1],b=o([]),E=o(0),k=o(0),P=o(!1),x=o(t);x.current=t;var M=e(function(){g(b.current.length+k.current)},[]),S=e(function(){if(!(P.current||k.current>=c)){if(0===b.current.length)return 0===k.current&&f(!1),void M();b.current.sort(function(n,e){return n.priority!==e.priority?n.priority-e.priority:n.sequence-e.sequence});var n=b.current.shift();k.current+=1,f(!0),M(),(0,x.current)(n.data).then(function(e){v(e),h(void 0),n.resolve(e)}).catch(function(e){h(e),n.reject(e)}).finally(function(){k.current-=1,M(),S()}),b.current.length>0&&k.current<c&&S()}},[c,M]),j=e(function(n,e){var r;if(P.current)return Promise.reject(new Error("Worker is terminated"));var t=null!=(r=null==e?void 0:e.priority)?r:1,o=++E.current,u=new Promise(function(e,r){b.current.push({data:n,priority:t,sequence:o,resolve:e,reject:r})});return M(),f(!0),queueMicrotask(S),u},[S,M]),I=e(function(){var n=b.current;b.current=[],n.forEach(function(n){return n.reject(new Error("Task cleared from queue"))}),M(),0===k.current&&f(!1)},[M]),D=e(function(){P.current=!0,I()},[I]);return r(function(){return function(){P.current=!0}},[]),{run:j,loading:s,result:d,error:m,queueSize:w,clearQueue:I,terminate:D}}var k=new Map;function P(n){return new Promise(function(e,r){n.onsuccess=function(){return e(n.result)},n.onerror=function(){var e;return r(null!=(e=n.error)?e:new DOMException("Unknown IndexedDB error"))}})}function x(n,e){return e?n.then(function(n){return null==e.onSuccess||e.onSuccess(n),n}).catch(function(n){throw null==e.onError||e.onError(n),n}):n}function M(e){var t=n(null),u=t[0],i=t[1],c=n(null),a=c[0],s=c[1],f=n(!1),l=f[0],p=f[1],m=o(e);return m.current=e,r(function(){var n=!1;s(null),p(!1),i(null);var e=m.current;return function(n){var e=n.name+"_v"+n.version,r=k.get(e);return r||(r=function(n){return new Promise(function(e,r){var t=indexedDB.open(n.name,n.version);t.onerror=function(){var n;return r(null!=(n=t.error)?n:new DOMException("Failed to open database"))},t.onsuccess=function(){return e(t.result)},t.onupgradeneeded=function(e){for(var r=e.target.result,t=n.tables,o=0,u=Object.keys(t);o<u.length;o++){var i=u[o],c=t[i];if(!r.objectStoreNames.contains(i)){var a,s=r.createObjectStore(i,{keyPath:c.keyPath,autoIncrement:null!=(a=c.autoIncrement)&&a});if(c.indexes)for(var f,l=d(c.indexes);!(f=l()).done;){var v=f.value;s.createIndex(v,v,{unique:!1})}}}}})}(n),k.set(e,r),r)}({name:e.name,version:e.version,tables:e.tables}).then(function(e){if(n)e.close();else{var r=function(n){return{get db(){return n},hasTable:function(e){return n.objectStoreNames.contains(e)},table:function(e){return function(n,e){return function(n,e){function r(r){return n.transaction([e],r).objectStore(e)}return{insert:function(n,e){return x(P(r("readwrite").add(n)),e)},update:function(n,e,t){var o=r("readwrite");return x(P(o.get(n)).then(function(n){if(void 0===n)throw new DOMException("Key not found","NotFoundError");var r=v({},n,e);return P(o.put(r))}).then(function(){}),t)},delete:function(n,e){return x(P(r("readwrite").delete(n)).then(function(){}),e)},exists:function(n){return P(r("readonly").getKey(n)).then(function(n){return void 0!==n})},query:function(n,e){var t=r("readonly").openCursor(),o=[];return x(new Promise(function(e,r){t.onsuccess=function(){var r=t.result;r?(n(r.value)&&o.push(r.value),r.continue()):e(o)},t.onerror=function(){var n;return r(null!=(n=t.error)?n:new DOMException("Unknown error"))}}),e)},upsert:function(n,e){return x(P(r("readwrite").put(n)),e)},bulkInsert:function(n,e){var t=r("readwrite"),o=[];if(0===n.length)return x(Promise.resolve(o),e);var u=0;return x(new Promise(function(e,r){n.forEach(function(i,c){var a=t.add(i);a.onsuccess=function(){o[c]=a.result,++u===n.length&&e(o)},a.onerror=function(){var n;return r(null!=(n=a.error)?n:new DOMException("Unknown error"))}})}),e)},clear:function(n){return x(P(r("readwrite").clear()).then(function(){}),n)},count:function(n){return x(P(r("readonly").count()),null!=n?n:{})}}}(n,e)}(n,e)},transaction:function(e,r,t,o){var u=n.transaction(e,r),i={table:function(n){return function(n,e){return function(n,e){function r(){return n.objectStore(e)}return{insert:function(n,e){return x(P(r().add(n)),e)},update:function(n,e,t){var o=r();return x(P(o.get(n)).then(function(n){if(void 0===n)throw new DOMException("Key not found","NotFoundError");var r=v({},n,e);return P(o.put(r))}).then(function(){}),t)},delete:function(n,e){return x(P(r().delete(n)).then(function(){}),e)},exists:function(n){return P(r().getKey(n)).then(function(n){return void 0!==n})},query:function(n,e){var t=r().openCursor(),o=[];return x(new Promise(function(e,r){t.onsuccess=function(){var r=t.result;r?(n(r.value)&&o.push(r.value),r.continue()):e(o)},t.onerror=function(){var n;return r(null!=(n=t.error)?n:new DOMException("Unknown error"))}}),e)},upsert:function(n,e){return x(P(r().put(n)),e)},bulkInsert:function(n,e){var t=r(),o=[];if(0===n.length)return x(Promise.resolve(o),e);var u=0;return x(new Promise(function(e,r){n.forEach(function(i,c){var a=t.add(i);a.onsuccess=function(){o[c]=a.result,++u===n.length&&e(o)},a.onerror=function(){var n;return r(null!=(n=a.error)?n:new DOMException("Unknown error"))}})}),e)},clear:function(n){return x(P(r().clear()).then(function(){}),n)},count:function(n){return x(P(r().count()),null!=n?n:{})}}}(n,e)}(u,n)}},c=new Promise(function(n,e){u.oncomplete=function(){return n()},u.onerror=function(){var n;return e(null!=(n=u.error)?n:new DOMException("Transaction failed"))}}),a=t(i);return function(n,e){return e?n.then(function(){return null==e.onSuccess?void 0:e.onSuccess()}).catch(function(n){throw null==e.onError||e.onError(n),n}):n}(Promise.resolve(a).then(function(){return c}),o)}}}(e);i(r),p(!0)}}).catch(function(e){n||s(e)}),function(){n=!0}},[e.name,e.version]),{db:u,isReady:l,error:a}}var S=/\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 I(e){void 0===e&&(e={});var t=e.stunServers,u=void 0===t?j:t,i=e.timeout,c=void 0===i?3e3:i,a=e.onDetect,s=n([]),f=s[0],l=s[1],d=n(!0),v=d[0],p=d[1],m=n(null),h=m[0],y=m[1],w=o(null),g=o(null),b=o(new Set),E=o(a);return E.current=a,r(function(){if("undefined"==typeof window)return p(!1),void y("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return p(!1),void y("RTCPeerConnection is not available");var n=new Set;b.current=n;var e=function(){g.current&&(clearTimeout(g.current),g.current=null),w.current&&(w.current.close(),w.current=null),p(!1)},r=function(e){n.has(e)||(n.add(e),l(function(n){return[].concat(n,[e])}),null==E.current||E.current(e))};try{var t=new RTCPeerConnection({iceServers:[{urls:u}]});w.current=t,t.onicecandidate=function(n){var e,t=n.candidate;t&&t.candidate&&((e=t.candidate.match(S))?[].concat(e):[]).forEach(r)},t.createDataChannel(""),t.createOffer().then(function(n){return t.setLocalDescription(n)}).catch(function(n){y(n instanceof Error?n.message:"Failed to create offer"),e()}),g.current=setTimeout(function(){return e()},c)}catch(n){y(n instanceof Error?n.message:"WebRTC setup failed"),e()}return function(){e()}},[u.join(","),c]),{ips:f,loading:v,error:h}}function D(t){var u=t.wasmUrl,i=t.exportName,c=void 0===i?"compute":i,a=t.workerUrl,s=t.importObject,f=n(void 0),l=f[0],d=f[1],v=n(!0),p=v[0],m=v[1],h=n(null),y=h[0],w=h[1],g=n(!1),b=g[0],E=g[1],k=o(null),P=o(null),x=o(null);return r(function(){if("undefined"==typeof window)return w("useWasmCompute is not available during SSR"),void m(!1);if("undefined"==typeof Worker)return w("Worker is not supported in this environment"),void m(!1);if("undefined"==typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)return w("WebAssembly is not supported in this environment"),void m(!1);w(null),E(!1);var n=function(n){if(n)return new Worker(n);var e=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(e),t=new Worker(r);return URL.revokeObjectURL(r),t}(a);k.current=n;var e=function(n){var e,r=null!=(e=n.data)?e:{},t=r.type,o=r.result,u=r.error;return"ready"===t?(E(!0),void m(!1)):"error"===t?(w(null!=u?u:"Unknown error"),m(!1),void(x.current&&(x.current(new Error(u)),P.current=null,x.current=null))):void("result"===t&&(d(o),m(!1),P.current&&(P.current(o),P.current=null,x.current=null)))};return n.addEventListener("message",e),n.postMessage({type:"init",wasmUrl:u,exportName:c,importObject:null!=s?s:{}}),function(){n.removeEventListener("message",e),n.terminate(),k.current=null,x.current&&(x.current(new Error("Worker terminated")),P.current=null,x.current=null)}},[u,c,a,s]),{compute:e(function(n){return new Promise(function(e,r){k.current&&b?y?r(new Error(y)):(P.current=e,x.current=r,m(!0),k.current.postMessage({type:"compute",input:n})):r(new Error("WASM not ready"))})},[b,y]),result:l,loading:p,error:y,ready:b}}function L(e,u){void 0===u&&(u={});var i=u.maxHistory,c=void 0===i?100:i,a=u.throughputWindowMs,s=void 0===a?1e3:a,f=n([]),l=f[0],d=f[1],v=n(0),p=v[0],m=v[1],h=n(0),y=h[0],w=h[1],g=n([]),b=g[0],E=g[1],k=n(0),P=k[0],x=k[1],M=o([]),S=o(0),j=o(0);r(function(){if(e){var n=function(n){var e=function(n){if(null==n||"object"!=typeof n)return null;var e=n.type;return"task_start"!==e&&"task_end"!==e&&"task_fail"!==e&&"queue_size"!==e?null:{type:e,taskId:"string"==typeof n.taskId?n.taskId:void 0,duration:"number"==typeof n.duration?n.duration:void 0,error:"string"==typeof n.error?n.error:void 0,size:"number"==typeof n.size?n.size:void 0,timestamp:Date.now()}}(n.data);if(e)if(E(function(n){return[].concat(n,[e]).slice(-c)}),"task_start"===e.type&&e.taskId)d(function(n){return n.includes(e.taskId)?n:[].concat(n,[e.taskId])});else if("task_end"===e.type){e.taskId&&d(function(n){return n.filter(function(n){return n!==e.taskId})}),m(function(n){return n+1});var r=Date.now()-s;M.current=[].concat(M.current.filter(function(n){return n>=r}),[e.timestamp]),"number"==typeof e.duration&&(S.current+=e.duration,j.current+=1)}else"task_fail"===e.type?(e.taskId&&d(function(n){return n.filter(function(n){return n!==e.taskId})}),w(function(n){return n+1})):"queue_size"===e.type&&"number"==typeof e.size&&x(e.size)};return e.addEventListener("message",n),function(){return e.removeEventListener("message",n)}}},[e,c]);var I=t(function(){var n=j.current;return n>0?S.current/n:0},[b]),D=t(function(){var n=Date.now()-s;return M.current.filter(function(e){return e>=n}).length/(s/1e3)},[b,s]),L=t(function(){return{runningTasks:l,completedCount:p,failedCount:y,averageDurationMs:I,throughputPerSecond:D,currentQueueSize:P,totalProcessed:p+y,recentEventCount:b.length}},[l,p,y,I,D,P,b.length]);return{runningTasks:l,completedCount:p,failedCount:y,eventHistory:b,averageDurationMs:I,throughputPerSecond:D,currentQueueSize:P,progress:L}}export{g as useClipboard,f as useEventBus,M as useIndexedDB,a as useMutationObserver,y as useNetworkState,m as usePreferredTheme,b as useRageClick,E as useThreadedWorker,c as useTransition,D as useWasmCompute,I as useWebRTCIP,L as useWorkerNotifications,p as useWrappedChildren};
1
+ import{useState as e,useCallback as n,useEffect as r,useMemo as t,useRef as o}from"react/hooks";import{isValidElement as i,cloneElement as u,useRef as a,useEffect as c}from"react";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 g(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 h(){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 E(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 k(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 x(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],g=p[1],h=e(0),y=h[0],w=h[1],b=o([]),E=o(0),k=o(0),x=o(!1),S=o(t);S.current=t;var T=n(function(){w(b.current.length+k.current)},[]),I=n(function(){if(!(x.current||k.current>=a)){if(0===b.current.length)return 0===k.current&&s(!1),void T();b.current.sort(function(e,n){return e.priority!==n.priority?e.priority-n.priority:e.sequence-n.sequence});var e=b.current.shift();k.current+=1,s(!0),T(),(0,S.current)(e.data).then(function(n){v(n),g(void 0),e.resolve(n)}).catch(function(n){g(n),e.reject(n)}).finally(function(){k.current-=1,T(),I()}),b.current.length>0&&k.current<a&&I()}},[a,T]),A=n(function(e,n){var r;if(x.current)return Promise.reject(new Error("Worker is terminated"));var t=null!=(r=null==n?void 0:n.priority)?r:1,o=++E.current,i=new Promise(function(n,r){b.current.push({data:e,priority:t,sequence:o,resolve:n,reject:r})});return T(),s(!0),queueMicrotask(I),i},[I,T]),P=n(function(){var e=b.current;b.current=[],e.forEach(function(e){return e.reject(new Error("Task cleared from queue"))}),T(),0===k.current&&s(!1)},[T]),M=n(function(){x.current=!0,P()},[P]);return r(function(){return function(){x.current=!0}},[]),{run:A,loading:l,result:d,error:m,queueSize:y,clearQueue:P,terminate:M}}var S=new Map;function T(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 I(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=S.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),S.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 I(T(r("readwrite").add(e)),n)},update:function(e,n,t){var o=r("readwrite");return I(T(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=m({},e,n);return T(o.put(r))}).then(function(){}),t)},delete:function(e,n){return I(T(r("readwrite").delete(e)).then(function(){}),n)},exists:function(e){return T(r("readonly").getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r("readonly").openCursor(),o=[];return I(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 I(T(r("readwrite").put(e)),n)},bulkInsert:function(e,n){var t=r("readwrite"),o=[];if(0===e.length)return I(Promise.resolve(o),n);var i=0;return I(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 I(T(r("readwrite").clear()).then(function(){}),e)},count:function(e){return I(T(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 I(T(r().add(e)),n)},update:function(e,n,t){var o=r();return I(T(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=m({},e,n);return T(o.put(r))}).then(function(){}),t)},delete:function(e,n){return I(T(r().delete(e)).then(function(){}),n)},exists:function(e){return T(r().getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r().openCursor(),o=[];return I(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 I(T(r().put(e)),n)},bulkInsert:function(e,n){var t=r(),o=[];if(0===e.length)return I(Promise.resolve(o),n);var i=0;return I(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 I(T(r().clear()).then(function(){}),e)},count:function(e){return I(T(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,M=["stun:stun.l.google.com:19302"];function j(n){void 0===n&&(n={});var t=n.stunServers,i=void 0===t?M: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),g=m[0],h=m[1],y=o(null),w=o(null),b=o(new Set),E=o(c);return E.current=c,r(function(){if("undefined"==typeof window)return p(!1),void h("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return p(!1),void h("RTCPeerConnection is not available");var e=new Set;b.current=e;var n=function(){w.current&&(clearTimeout(w.current),w.current=null),y.current&&(y.current.close(),y.current=null),p(!1)},r=function(n){e.has(n)||(e.add(n),f(function(e){return[].concat(e,[n])}),null==E.current||E.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){h(e instanceof Error?e.message:"Failed to create offer"),n()}),w.current=setTimeout(function(){return n()},a)}catch(e){h(e instanceof Error?e.message:"WebRTC setup failed"),n()}return function(){n()}},[i.join(","),a]),{ips:s,loading:v,error:g}}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],g=e(null),h=g[0],y=g[1],w=e(!1),b=w[0],E=w[1],k=o(null),x=o(null),S=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),E(!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);k.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?(E(!0),void m(!1)):"error"===t?(y(null!=i?i:"Unknown error"),m(!1),void(S.current&&(S.current(new Error(i)),x.current=null,S.current=null))):void("result"===t&&(d(o),m(!1),x.current&&(x.current(o),x.current=null,S.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(),k.current=null,S.current&&(S.current(new Error("Worker terminated")),x.current=null,S.current=null)}},[i,a,c,l]),{compute:n(function(e){return new Promise(function(n,r){k.current&&b?h?r(new Error(h)):(x.current=n,S.current=r,m(!0),k.current.postMessage({type:"compute",input:e})):r(new Error("WASM not ready"))})},[b,h]),result:f,loading:p,error:h,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],g=e(0),h=g[0],y=g[1],w=e([]),b=w[0],E=w[1],k=e(0),x=k[0],S=k[1],T=o([]),I=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(E(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;T.current=[].concat(T.current.filter(function(e){return e>=r}),[n.timestamp]),"number"==typeof n.duration&&(I.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&&S(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?I.current/e:0},[b]),M=t(function(){var e=Date.now()-l;return T.current.filter(function(n){return n>=e}).length/(l/1e3)},[b,l]),j=t(function(){return{runningTasks:f,completedCount:p,failedCount:h,averageDurationMs:P,throughputPerSecond:M,currentQueueSize:x,totalProcessed:p+h,recentEventCount:b.length}},[f,p,h,P,M,x,b.length]);return{runningTasks:f,completedCount:p,failedCount:h,eventHistory:b,averageDurationMs:P,throughputPerSecond:M,currentQueueSize:x,progress:j}}function D(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 L(e){if(!Array.isArray(e))return[];for(var n=[],r=0;r<e.length&&n.length<50;r++){var t=D(e[r],100);t&&n.push(t)}return n}function U(e){var n=D(e,2048);if(!n)return"";try{var r=new URL(n);if("http:"===r.protocol||"https:"===r.protocol)return n}catch(e){}return""}function N(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=D(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 D(e,200)}).filter(Boolean).slice(0,20))}}}catch(e){}return n}function W(){try{if("undefined"==typeof document||!document.querySelectorAll)return;document.querySelectorAll('script[data-llm="true"]').forEach(function(e){return e.remove()})}catch(e){}}function R(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:D(e.route,2048)||"/",mode:"auto-extract"===e.mode?"auto-extract":"manual",title:void 0!==e.title?D(e.title,200):void 0,description:void 0!==e.description?D(e.description,2e3):void 0,tags:void 0!==e.tags?L(e.tags):void 0,canonicalUrl:void 0!==e.canonicalUrl?U(e.canonicalUrl):void 0,language:void 0!==e.language?D(e.language,20):void 0,ogType:void 0!==e.ogType?D(e.ogType,50):void 0,ogImage:void 0!==e.ogImage?U(e.ogImage):void 0,ogImageAlt:void 0!==e.ogImageAlt?D(e.ogImageAlt,200):void 0,siteName:void 0!==e.siteName?D(e.siteName,100):void 0,author:void 0!==e.author?D(e.author,200):void 0,publishedTime:void 0!==e.publishedTime?D(e.publishedTime,50):void 0,modifiedTime:void 0!==e.modifiedTime?D(e.modifiedTime,50):void 0,robots:void 0!==e.robots?D(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=D(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(N(c)&&!u(c)){var l=D(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(N(m)&&!u(m)){var g=D(m.textContent,1e3);g&&d.push(g)}}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,W(),function(e){try{if("undefined"==typeof document||!document.head)return;var n=document.createElement("script");n.type="application/llm+json",n.setAttribute("data-llm","true"),n.textContent=JSON.stringify(e),document.head.appendChild(n)}catch(e){}}(t),function(){W(),n.current=null}}catch(e){}},[null==e?void 0:e.route,null==e?void 0:e.mode,null==e?void 0:e.title,null==e?void 0:e.description,null==e?void 0:e.tags,null==e?void 0:e.canonicalUrl,null==e?void 0:e.language,null==e?void 0:e.ogType,null==e?void 0:e.ogImage,null==e?void 0:e.ogImageAlt,null==e?void 0:e.siteName,null==e?void 0:e.author,null==e?void 0:e.publishedTime,null==e?void 0:e.modifiedTime,null==e?void 0:e.robots])}export{E as useClipboard,d as useEventBus,A as useIndexedDB,R as useLLMMetadata,s as useMutationObserver,w as useNetworkState,h as usePreferredTheme,k as useRageClick,x as useThreadedWorker,l as useTransition,O as useWasmCompute,j as useWebRTCIP,C as useWorkerNotifications,g as useWrappedChildren};
package/dist/react.umd.js CHANGED
@@ -1 +1 @@
1
- !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react/hooks"),require("react")):"function"==typeof define&&define.amd?define(["exports","react/hooks","react"],n):n((e||self).preactMissingHooks={},e.hooks,e.react)}(this,function(e,n,r){var t=new Map;function o(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 u(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 o(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)?o(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 i(){return i=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},i.apply(null,arguments)}function a(){if("undefined"==typeof navigator)return{online:!0};var e={online:navigator.onLine},n=navigator.connection;return n&&(void 0!==n.effectiveType&&(e.effectiveType=n.effectiveType),void 0!==n.downlink&&(e.downlink=n.downlink),void 0!==n.rtt&&(e.rtt=n.rtt),void 0!==n.saveData&&(e.saveData=n.saveData),void 0!==n.type&&(e.connectionType=n.type)),e}function c(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}var s=new Map;function f(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 l(e,n){return n?e.then(function(e){return null==n.onSuccess||n.onSuccess(e),e}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}var d=/\b(?:25[0-5]|2[0-4]\d|1?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|1?\d{1,2})){3}\b/g,v=["stun:stun.l.google.com:19302"];e.useClipboard=function(e){void 0===e&&(e={});var r=e.resetDelay,t=void 0===r?2e3:r,o=n.useState(!1),u=o[0],i=o[1],a=n.useState(null),s=a[0],f=a[1],l=n.useCallback(function(){i(!1),f(null)},[]);return{copy:n.useCallback(function(e){try{if(f(null),"undefined"==typeof navigator||!navigator.clipboard){var n=new Error("Clipboard API is not available");return f(n),Promise.resolve(!1)}return Promise.resolve(c(function(){return Promise.resolve(navigator.clipboard.writeText(e)).then(function(){return i(!0),t>0&&setTimeout(function(){return i(!1)},t),!0})},function(e){var n=e instanceof Error?e:new Error(String(e));return f(n),!1}))}catch(e){return Promise.reject(e)}},[t]),paste:n.useCallback(function(){try{if(f(null),"undefined"==typeof navigator||!navigator.clipboard){var e=new Error("Clipboard API is not available");return f(e),Promise.resolve("")}return Promise.resolve(c(function(){return Promise.resolve(navigator.clipboard.readText())},function(e){var n=e instanceof Error?e:new Error(String(e));return f(n),""}))}catch(e){return Promise.reject(e)}},[]),copied:u,error:s,reset:l}},e.useEventBus=function(){var e=n.useCallback(function(e){var n=arguments,r=t.get(e);r&&r.forEach(function(e){return e.apply(void 0,[].slice.call(n,1))})},[]);return{emit:e,on:n.useCallback(function(e,n){var r=t.get(e);return r||(r=new Set,t.set(e,r)),r.add(n),function(){r.delete(n),0===r.size&&t.delete(e)}},[])}},e.useIndexedDB=function(e){var r=n.useState(null),t=r[0],o=r[1],a=n.useState(null),c=a[0],d=a[1],v=n.useState(!1),p=v[0],m=v[1],h=n.useRef(e);return h.current=e,n.useEffect(function(){var e=!1;d(null),m(!1),o(null);var n=h.current;return function(e){var n=e.name+"_v"+e.version,r=s.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 a=i[o],c=t[a];if(!r.objectStoreNames.contains(a)){var s,f=r.createObjectStore(a,{keyPath:c.keyPath,autoIncrement:null!=(s=c.autoIncrement)&&s});if(c.indexes)for(var l,d=u(c.indexes);!(l=d()).done;){var v=l.value;f.createIndex(v,v,{unique:!1})}}}}})}(e),s.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 l(f(r("readwrite").add(e)),n)},update:function(e,n,t){var o=r("readwrite");return l(f(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=i({},e,n);return f(o.put(r))}).then(function(){}),t)},delete:function(e,n){return l(f(r("readwrite").delete(e)).then(function(){}),n)},exists:function(e){return f(r("readonly").getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r("readonly").openCursor(),o=[];return l(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 l(f(r("readwrite").put(e)),n)},bulkInsert:function(e,n){var t=r("readwrite"),o=[];if(0===e.length)return l(Promise.resolve(o),n);var u=0;return l(new Promise(function(n,r){e.forEach(function(i,a){var c=t.add(i);c.onsuccess=function(){o[a]=c.result,++u===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 l(f(r("readwrite").clear()).then(function(){}),e)},count:function(e){return l(f(r("readonly").count()),null!=e?e:{})}}}(e,n)}(e,n)},transaction:function(n,r,t,o){var u=e.transaction(n,r),a={table:function(e){return function(e,n){return function(e,n){function r(){return e.objectStore(n)}return{insert:function(e,n){return l(f(r().add(e)),n)},update:function(e,n,t){var o=r();return l(f(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=i({},e,n);return f(o.put(r))}).then(function(){}),t)},delete:function(e,n){return l(f(r().delete(e)).then(function(){}),n)},exists:function(e){return f(r().getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r().openCursor(),o=[];return l(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 l(f(r().put(e)),n)},bulkInsert:function(e,n){var t=r(),o=[];if(0===e.length)return l(Promise.resolve(o),n);var u=0;return l(new Promise(function(n,r){e.forEach(function(i,a){var c=t.add(i);c.onsuccess=function(){o[a]=c.result,++u===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 l(f(r().clear()).then(function(){}),e)},count:function(e){return l(f(r().count()),null!=e?e:{})}}}(e,n)}(u,e)}},c=new Promise(function(e,n){u.oncomplete=function(){return e()},u.onerror=function(){var e;return n(null!=(e=u.error)?e:new DOMException("Transaction failed"))}}),s=t(a);return function(e,n){return n?e.then(function(){return null==n.onSuccess?void 0:n.onSuccess()}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}(Promise.resolve(s).then(function(){return c}),o)}}}(n);o(r),m(!0)}}).catch(function(n){e||d(n)}),function(){e=!0}},[e.name,e.version]),{db:t,isReady:p,error:c}},e.useMutationObserver=function(e,r,t){n.useEffect(function(){var n=e.current;if(n){var o=new MutationObserver(r);return o.observe(n,t),function(){return o.disconnect()}}},[e,r,t])},e.useNetworkState=function(){var e=n.useState(a),r=e[0],t=e[1];return n.useEffect(function(){if("undefined"!=typeof window){var e=function(){return t(a())};window.addEventListener("online",e),window.addEventListener("offline",e);var n=navigator.connection;return null!=n&&n.addEventListener&&n.addEventListener("change",e),function(){window.removeEventListener("online",e),window.removeEventListener("offline",e),null!=n&&n.removeEventListener&&n.removeEventListener("change",e)}}},[]),r},e.usePreferredTheme=function(){var e=n.useState(function(){if("undefined"==typeof window)return"no-preference";var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");return e.matches?"dark":n.matches?"light":"no-preference"}),r=e[0],t=e[1];return n.useEffect(function(){if("undefined"!=typeof window){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=function(e){t(e.matches?"dark":"light")},r=function(){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");t(e.matches?"dark":n.matches?"light":"no-preference")};e.addEventListener("change",n);var o=window.matchMedia("(prefers-color-scheme: light)");return o.addEventListener("change",r),function(){e.removeEventListener("change",n),o.removeEventListener("change",r)}}},[]),r},e.useRageClick=function(e,r){var t=r.onRageClick,o=r.threshold,u=void 0===o?5:o,i=r.timeWindow,a=void 0===i?1e3:i,c=r.distanceThreshold,s=void 0===c?30:c,f=n.useRef(t);f.current=t;var l=n.useRef([]);n.useEffect(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-a,o=l.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(l.current=[])}else if(o.length>=u)return f.current({count:o.length,event:e}),void(l.current=[]);l.current=o};return n.addEventListener("click",r),function(){return n.removeEventListener("click",r)}}},[e,u,a,s])},e.useThreadedWorker=function(e,r){var t=r.concurrency,o="sequential"===r.mode?1:Math.max(1,void 0===t?4:t),u=n.useState(!1),i=u[0],a=u[1],c=n.useState(void 0),s=c[0],f=c[1],l=n.useState(void 0),d=l[0],v=l[1],p=n.useState(0),m=p[0],h=p[1],y=n.useRef([]),w=n.useRef(0),g=n.useRef(0),b=n.useRef(!1),k=n.useRef(e);k.current=e;var E=n.useCallback(function(){h(y.current.length+g.current)},[]),S=n.useCallback(function(){if(!(b.current||g.current>=o)){if(0===y.current.length)return 0===g.current&&a(!1),void E();y.current.sort(function(e,n){return e.priority!==n.priority?e.priority-n.priority:e.sequence-n.sequence});var e=y.current.shift();g.current+=1,a(!0),E(),(0,k.current)(e.data).then(function(n){f(n),v(void 0),e.resolve(n)}).catch(function(n){v(n),e.reject(n)}).finally(function(){g.current-=1,E(),S()}),y.current.length>0&&g.current<o&&S()}},[o,E]),M=n.useCallback(function(e,n){var r;if(b.current)return Promise.reject(new Error("Worker is terminated"));var t=null!=(r=null==n?void 0:n.priority)?r:1,o=++w.current,u=new Promise(function(n,r){y.current.push({data:e,priority:t,sequence:o,resolve:n,reject:r})});return E(),a(!0),queueMicrotask(S),u},[S,E]),C=n.useCallback(function(){var e=y.current;y.current=[],e.forEach(function(e){return e.reject(new Error("Task cleared from queue"))}),E(),0===g.current&&a(!1)},[E]),x=n.useCallback(function(){b.current=!0,C()},[C]);return n.useEffect(function(){return function(){b.current=!0}},[]),{run:M,loading:i,result:s,error:d,queueSize:m,clearQueue:C,terminate:x}},e.useTransition=function(){var e=n.useState(!1),r=e[0],t=e[1];return[n.useCallback(function(e){t(!0),Promise.resolve().then(function(){e(),t(!1)})},[]),r]},e.useWasmCompute=function(e){var r=e.wasmUrl,t=e.exportName,o=void 0===t?"compute":t,u=e.workerUrl,i=e.importObject,a=n.useState(void 0),c=a[0],s=a[1],f=n.useState(!0),l=f[0],d=f[1],v=n.useState(null),p=v[0],m=v[1],h=n.useState(!1),y=h[0],w=h[1],g=n.useRef(null),b=n.useRef(null),k=n.useRef(null);return n.useEffect(function(){if("undefined"==typeof window)return m("useWasmCompute is not available during SSR"),void d(!1);if("undefined"==typeof Worker)return m("Worker is not supported in this environment"),void d(!1);if("undefined"==typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)return m("WebAssembly is not supported in this environment"),void d(!1);m(null),w(!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}(u);g.current=e;var n=function(e){var n,r=null!=(n=e.data)?n:{},t=r.type,o=r.result,u=r.error;return"ready"===t?(w(!0),void d(!1)):"error"===t?(m(null!=u?u:"Unknown error"),d(!1),void(k.current&&(k.current(new Error(u)),b.current=null,k.current=null))):void("result"===t&&(s(o),d(!1),b.current&&(b.current(o),b.current=null,k.current=null)))};return e.addEventListener("message",n),e.postMessage({type:"init",wasmUrl:r,exportName:o,importObject:null!=i?i:{}}),function(){e.removeEventListener("message",n),e.terminate(),g.current=null,k.current&&(k.current(new Error("Worker terminated")),b.current=null,k.current=null)}},[r,o,u,i]),{compute:n.useCallback(function(e){return new Promise(function(n,r){g.current&&y?p?r(new Error(p)):(b.current=n,k.current=r,d(!0),g.current.postMessage({type:"compute",input:e})):r(new Error("WASM not ready"))})},[y,p]),result:c,loading:l,error:p,ready:y}},e.useWebRTCIP=function(e){void 0===e&&(e={});var r=e.stunServers,t=void 0===r?v:r,o=e.timeout,u=void 0===o?3e3:o,i=e.onDetect,a=n.useState([]),c=a[0],s=a[1],f=n.useState(!0),l=f[0],p=f[1],m=n.useState(null),h=m[0],y=m[1],w=n.useRef(null),g=n.useRef(null),b=n.useRef(new Set),k=n.useRef(i);return k.current=i,n.useEffect(function(){if("undefined"==typeof window)return p(!1),void y("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return p(!1),void y("RTCPeerConnection is not available");var e=new Set;b.current=e;var n=function(){g.current&&(clearTimeout(g.current),g.current=null),w.current&&(w.current.close(),w.current=null),p(!1)},r=function(n){e.has(n)||(e.add(n),s(function(e){return[].concat(e,[n])}),null==k.current||k.current(n))};try{var o=new RTCPeerConnection({iceServers:[{urls:t}]});w.current=o,o.onicecandidate=function(e){var n,t=e.candidate;t&&t.candidate&&((n=t.candidate.match(d))?[].concat(n):[]).forEach(r)},o.createDataChannel(""),o.createOffer().then(function(e){return o.setLocalDescription(e)}).catch(function(e){y(e instanceof Error?e.message:"Failed to create offer"),n()}),g.current=setTimeout(function(){return n()},u)}catch(e){y(e instanceof Error?e.message:"WebRTC setup failed"),n()}return function(){n()}},[t.join(","),u]),{ips:c,loading:l,error:h}},e.useWorkerNotifications=function(e,r){void 0===r&&(r={});var t=r.maxHistory,o=void 0===t?100:t,u=r.throughputWindowMs,i=void 0===u?1e3:u,a=n.useState([]),c=a[0],s=a[1],f=n.useState(0),l=f[0],d=f[1],v=n.useState(0),p=v[0],m=v[1],h=n.useState([]),y=h[0],w=h[1],g=n.useState(0),b=g[0],k=g[1],E=n.useRef([]),S=n.useRef(0),M=n.useRef(0);n.useEffect(function(){if(e){var n=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(w(function(e){return[].concat(e,[n]).slice(-o)}),"task_start"===n.type&&n.taskId)s(function(e){return e.includes(n.taskId)?e:[].concat(e,[n.taskId])});else if("task_end"===n.type){n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),d(function(e){return e+1});var r=Date.now()-i;E.current=[].concat(E.current.filter(function(e){return e>=r}),[n.timestamp]),"number"==typeof n.duration&&(S.current+=n.duration,M.current+=1)}else"task_fail"===n.type?(n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),m(function(e){return e+1})):"queue_size"===n.type&&"number"==typeof n.size&&k(n.size)};return e.addEventListener("message",n),function(){return e.removeEventListener("message",n)}}},[e,o]);var C=n.useMemo(function(){var e=M.current;return e>0?S.current/e:0},[y]),x=n.useMemo(function(){var e=Date.now()-i;return E.current.filter(function(n){return n>=e}).length/(i/1e3)},[y,i]),P=n.useMemo(function(){return{runningTasks:c,completedCount:l,failedCount:p,averageDurationMs:C,throughputPerSecond:x,currentQueueSize:b,totalProcessed:l+p,recentEventCount:y.length}},[c,l,p,C,x,b,y.length]);return{runningTasks:c,completedCount:l,failedCount:p,eventHistory:y,averageDurationMs:C,throughputPerSecond:x,currentQueueSize:b,progress:P}},e.useWrappedChildren=function(e,t,o){return void 0===o&&(o="preserve"),n.useMemo(function(){if(!e)return e;var n=function(e){if(!r.isValidElement(e))return e;var n,u=e.props||{};n="override"===o?i({},u,t):i({},t,u);var a=null==u?void 0:u.style,c=null==t?void 0:t.style;return a&&c&&"object"==typeof a&&"object"==typeof c&&(n.style="override"===o?i({},a,c):i({},c,a)),r.cloneElement(e,n)};return Array.isArray(e)?e.map(n):n(e)},[e,t,o])}});
1
+ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("react/hooks"),require("react")):"function"==typeof define&&define.amd?define(["exports","react/hooks","react"],n):n((e||self).preactMissingHooks={},e.hooks,e.react)}(this,function(e,n,r){var t=new Map;function o(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 u(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 o(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)?o(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 i(){return i=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},i.apply(null,arguments)}function a(){if("undefined"==typeof navigator)return{online:!0};var e={online:navigator.onLine},n=navigator.connection;return n&&(void 0!==n.effectiveType&&(e.effectiveType=n.effectiveType),void 0!==n.downlink&&(e.downlink=n.downlink),void 0!==n.rtt&&(e.rtt=n.rtt),void 0!==n.saveData&&(e.saveData=n.saveData),void 0!==n.type&&(e.connectionType=n.type)),e}function c(e,n){try{var r=e()}catch(e){return n(e)}return r&&r.then?r.then(void 0,n):r}var s=new Map;function l(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 f(e,n){return n?e.then(function(e){return null==n.onSuccess||n.onSuccess(e),e}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}var d=/\b(?:25[0-5]|2[0-4]\d|1?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|1?\d{1,2})){3}\b/g,v=["stun:stun.l.google.com:19302"];function p(e,n){if(null==e)return"";var r=("string"==typeof e?e:String(e)).trim();return r.length>n?r.slice(0,n):r}function m(e){if(!Array.isArray(e))return[];for(var n=[],r=0;r<e.length&&n.length<50;r++){var t=p(e[r],100);t&&n.push(t)}return n}function g(e){var n=p(e,2048);if(!n)return"";try{var r=new URL(n);if("http:"===r.protocol||"https:"===r.protocol)return n}catch(e){}return""}function h(e){try{if("undefined"==typeof window)return!1;var n=window.getComputedStyle(e);return"none"!==n.display&&"hidden"!==n.visibility&&"0"!==n.opacity}catch(e){return!1}}function y(e){var n={};try{for(var r,t=u(Object.keys(e).slice(0,20));!(r=t()).done;){var o=r.value,i=p(o,50);if(i){var a=e[o];"string"==typeof a?n[i]=a.slice(0,500):"number"==typeof a&&Number.isFinite(a)||"boolean"==typeof a?n[i]=a:Array.isArray(a)&&(n[i]=a.map(function(e){return p(e,200)}).filter(Boolean).slice(0,20))}}}catch(e){}return n}function w(){try{if("undefined"==typeof document||!document.querySelectorAll)return;document.querySelectorAll('script[data-llm="true"]').forEach(function(e){return e.remove()})}catch(e){}}e.useClipboard=function(e){void 0===e&&(e={});var r=e.resetDelay,t=void 0===r?2e3:r,o=n.useState(!1),u=o[0],i=o[1],a=n.useState(null),s=a[0],l=a[1],f=n.useCallback(function(){i(!1),l(null)},[]);return{copy:n.useCallback(function(e){try{if(l(null),"undefined"==typeof navigator||!navigator.clipboard){var n=new Error("Clipboard API is not available");return l(n),Promise.resolve(!1)}return Promise.resolve(c(function(){return Promise.resolve(navigator.clipboard.writeText(e)).then(function(){return i(!0),t>0&&setTimeout(function(){return i(!1)},t),!0})},function(e){var n=e instanceof Error?e:new Error(String(e));return l(n),!1}))}catch(e){return Promise.reject(e)}},[t]),paste:n.useCallback(function(){try{if(l(null),"undefined"==typeof navigator||!navigator.clipboard){var e=new Error("Clipboard API is not available");return l(e),Promise.resolve("")}return Promise.resolve(c(function(){return Promise.resolve(navigator.clipboard.readText())},function(e){var n=e instanceof Error?e:new Error(String(e));return l(n),""}))}catch(e){return Promise.reject(e)}},[]),copied:u,error:s,reset:f}},e.useEventBus=function(){var e=n.useCallback(function(e){var n=arguments,r=t.get(e);r&&r.forEach(function(e){return e.apply(void 0,[].slice.call(n,1))})},[]);return{emit:e,on:n.useCallback(function(e,n){var r=t.get(e);return r||(r=new Set,t.set(e,r)),r.add(n),function(){r.delete(n),0===r.size&&t.delete(e)}},[])}},e.useIndexedDB=function(e){var r=n.useState(null),t=r[0],o=r[1],a=n.useState(null),c=a[0],d=a[1],v=n.useState(!1),p=v[0],m=v[1],g=n.useRef(e);return g.current=e,n.useEffect(function(){var e=!1;d(null),m(!1),o(null);var n=g.current;return function(e){var n=e.name+"_v"+e.version,r=s.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 a=i[o],c=t[a];if(!r.objectStoreNames.contains(a)){var s,l=r.createObjectStore(a,{keyPath:c.keyPath,autoIncrement:null!=(s=c.autoIncrement)&&s});if(c.indexes)for(var f,d=u(c.indexes);!(f=d()).done;){var v=f.value;l.createIndex(v,v,{unique:!1})}}}}})}(e),s.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 f(l(r("readwrite").add(e)),n)},update:function(e,n,t){var o=r("readwrite");return f(l(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=i({},e,n);return l(o.put(r))}).then(function(){}),t)},delete:function(e,n){return f(l(r("readwrite").delete(e)).then(function(){}),n)},exists:function(e){return l(r("readonly").getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r("readonly").openCursor(),o=[];return f(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 f(l(r("readwrite").put(e)),n)},bulkInsert:function(e,n){var t=r("readwrite"),o=[];if(0===e.length)return f(Promise.resolve(o),n);var u=0;return f(new Promise(function(n,r){e.forEach(function(i,a){var c=t.add(i);c.onsuccess=function(){o[a]=c.result,++u===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 f(l(r("readwrite").clear()).then(function(){}),e)},count:function(e){return f(l(r("readonly").count()),null!=e?e:{})}}}(e,n)}(e,n)},transaction:function(n,r,t,o){var u=e.transaction(n,r),a={table:function(e){return function(e,n){return function(e,n){function r(){return e.objectStore(n)}return{insert:function(e,n){return f(l(r().add(e)),n)},update:function(e,n,t){var o=r();return f(l(o.get(e)).then(function(e){if(void 0===e)throw new DOMException("Key not found","NotFoundError");var r=i({},e,n);return l(o.put(r))}).then(function(){}),t)},delete:function(e,n){return f(l(r().delete(e)).then(function(){}),n)},exists:function(e){return l(r().getKey(e)).then(function(e){return void 0!==e})},query:function(e,n){var t=r().openCursor(),o=[];return f(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 f(l(r().put(e)),n)},bulkInsert:function(e,n){var t=r(),o=[];if(0===e.length)return f(Promise.resolve(o),n);var u=0;return f(new Promise(function(n,r){e.forEach(function(i,a){var c=t.add(i);c.onsuccess=function(){o[a]=c.result,++u===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 f(l(r().clear()).then(function(){}),e)},count:function(e){return f(l(r().count()),null!=e?e:{})}}}(e,n)}(u,e)}},c=new Promise(function(e,n){u.oncomplete=function(){return e()},u.onerror=function(){var e;return n(null!=(e=u.error)?e:new DOMException("Transaction failed"))}}),s=t(a);return function(e,n){return n?e.then(function(){return null==n.onSuccess?void 0:n.onSuccess()}).catch(function(e){throw null==n.onError||n.onError(e),e}):e}(Promise.resolve(s).then(function(){return c}),o)}}}(n);o(r),m(!0)}}).catch(function(n){e||d(n)}),function(){e=!0}},[e.name,e.version]),{db:t,isReady:p,error:c}},e.useLLMMetadata=function(e){var n=r.useRef(null);r.useEffect(function(){try{if("undefined"==typeof window)return;var r=function(e){return null==e||"object"!=typeof e?{route:"/"}:{route:p(e.route,2048)||"/",mode:"auto-extract"===e.mode?"auto-extract":"manual",title:void 0!==e.title?p(e.title,200):void 0,description:void 0!==e.description?p(e.description,2e3):void 0,tags:void 0!==e.tags?m(e.tags):void 0,canonicalUrl:void 0!==e.canonicalUrl?g(e.canonicalUrl):void 0,language:void 0!==e.language?p(e.language,20):void 0,ogType:void 0!==e.ogType?p(e.ogType,50):void 0,ogImage:void 0!==e.ogImage?g(e.ogImage):void 0,ogImageAlt:void 0!==e.ogImageAlt?p(e.ogImageAlt,200):void 0,siteName:void 0!==e.siteName?p(e.siteName,100):void 0,author:void 0!==e.author?p(e.author,200):void 0,publishedTime:void 0!==e.publishedTime?p(e.publishedTime,50):void 0,modifiedTime:void 0!==e.modifiedTime?p(e.modifiedTime,50):void 0,robots:void 0!==e.robots?p(e.robots,100):void 0,extra:void 0===e.extra||"object"!=typeof e.extra||Array.isArray(e.extra)?void 0:y(e.extra)}}(e),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=p(document.title,200),r=[],t="";try{for(var o,i=document.querySelectorAll("nav, footer, [role='navigation'], [role='contentinfo'], script, style, noscript"),a=function(e){for(var n,r=u(i);!(n=r()).done;)if(n.value.contains(e))return!0;return!1},c=u(document.querySelectorAll("h1, h2"));!(o=c()).done;){var s=o.value;if(r.length>=50)break;if(h(s)&&!a(s)){var l=p(s.textContent,300);l&&r.push(l)}}for(var f,d=document.querySelectorAll("p"),v=[],m=u(d);!(f=m()).done;){var g=f.value;if(v.length>=3)break;if(h(g)&&!a(g)){var y=p(g.textContent,1e3);y&&v.push(y)}}t=v.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 a;return{route:null!=(a=null==e?void 0:e.route)?a:"/",generatedAt:(new Date).toISOString()}}}(r),o=JSON.stringify(t);if(n.current===o)return;return n.current=o,w(),function(e){try{if("undefined"==typeof document||!document.head)return;var n=document.createElement("script");n.type="application/llm+json",n.setAttribute("data-llm","true"),n.textContent=JSON.stringify(e),document.head.appendChild(n)}catch(e){}}(t),function(){w(),n.current=null}}catch(e){}},[null==e?void 0:e.route,null==e?void 0:e.mode,null==e?void 0:e.title,null==e?void 0:e.description,null==e?void 0:e.tags,null==e?void 0:e.canonicalUrl,null==e?void 0:e.language,null==e?void 0:e.ogType,null==e?void 0:e.ogImage,null==e?void 0:e.ogImageAlt,null==e?void 0:e.siteName,null==e?void 0:e.author,null==e?void 0:e.publishedTime,null==e?void 0:e.modifiedTime,null==e?void 0:e.robots])},e.useMutationObserver=function(e,r,t){n.useEffect(function(){var n=e.current;if(n){var o=new MutationObserver(r);return o.observe(n,t),function(){return o.disconnect()}}},[e,r,t])},e.useNetworkState=function(){var e=n.useState(a),r=e[0],t=e[1];return n.useEffect(function(){if("undefined"!=typeof window){var e=function(){return t(a())};window.addEventListener("online",e),window.addEventListener("offline",e);var n=navigator.connection;return null!=n&&n.addEventListener&&n.addEventListener("change",e),function(){window.removeEventListener("online",e),window.removeEventListener("offline",e),null!=n&&n.removeEventListener&&n.removeEventListener("change",e)}}},[]),r},e.usePreferredTheme=function(){var e=n.useState(function(){if("undefined"==typeof window)return"no-preference";var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");return e.matches?"dark":n.matches?"light":"no-preference"}),r=e[0],t=e[1];return n.useEffect(function(){if("undefined"!=typeof window){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=function(e){t(e.matches?"dark":"light")},r=function(){var e=window.matchMedia("(prefers-color-scheme: dark)"),n=window.matchMedia("(prefers-color-scheme: light)");t(e.matches?"dark":n.matches?"light":"no-preference")};e.addEventListener("change",n);var o=window.matchMedia("(prefers-color-scheme: light)");return o.addEventListener("change",r),function(){e.removeEventListener("change",n),o.removeEventListener("change",r)}}},[]),r},e.useRageClick=function(e,r){var t=r.onRageClick,o=r.threshold,u=void 0===o?5:o,i=r.timeWindow,a=void 0===i?1e3:i,c=r.distanceThreshold,s=void 0===c?30:c,l=n.useRef(t);l.current=t;var f=n.useRef([]);n.useEffect(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-a,o=f.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 l.current({count:i.length,event:e}),void(f.current=[])}else if(o.length>=u)return l.current({count:o.length,event:e}),void(f.current=[]);f.current=o};return n.addEventListener("click",r),function(){return n.removeEventListener("click",r)}}},[e,u,a,s])},e.useThreadedWorker=function(e,r){var t=r.concurrency,o="sequential"===r.mode?1:Math.max(1,void 0===t?4:t),u=n.useState(!1),i=u[0],a=u[1],c=n.useState(void 0),s=c[0],l=c[1],f=n.useState(void 0),d=f[0],v=f[1],p=n.useState(0),m=p[0],g=p[1],h=n.useRef([]),y=n.useRef(0),w=n.useRef(0),b=n.useRef(!1),k=n.useRef(e);k.current=e;var S=n.useCallback(function(){g(h.current.length+w.current)},[]),E=n.useCallback(function(){if(!(b.current||w.current>=o)){if(0===h.current.length)return 0===w.current&&a(!1),void S();h.current.sort(function(e,n){return e.priority!==n.priority?e.priority-n.priority:e.sequence-n.sequence});var e=h.current.shift();w.current+=1,a(!0),S(),(0,k.current)(e.data).then(function(n){l(n),v(void 0),e.resolve(n)}).catch(function(n){v(n),e.reject(n)}).finally(function(){w.current-=1,S(),E()}),h.current.length>0&&w.current<o&&E()}},[o,S]),x=n.useCallback(function(e,n){var r;if(b.current)return Promise.reject(new Error("Worker is terminated"));var t=null!=(r=null==n?void 0:n.priority)?r:1,o=++y.current,u=new Promise(function(n,r){h.current.push({data:e,priority:t,sequence:o,resolve:n,reject:r})});return S(),a(!0),queueMicrotask(E),u},[E,S]),T=n.useCallback(function(){var e=h.current;h.current=[],e.forEach(function(e){return e.reject(new Error("Task cleared from queue"))}),S(),0===w.current&&a(!1)},[S]),C=n.useCallback(function(){b.current=!0,T()},[T]);return n.useEffect(function(){return function(){b.current=!0}},[]),{run:x,loading:i,result:s,error:d,queueSize:m,clearQueue:T,terminate:C}},e.useTransition=function(){var e=n.useState(!1),r=e[0],t=e[1];return[n.useCallback(function(e){t(!0),Promise.resolve().then(function(){e(),t(!1)})},[]),r]},e.useWasmCompute=function(e){var r=e.wasmUrl,t=e.exportName,o=void 0===t?"compute":t,u=e.workerUrl,i=e.importObject,a=n.useState(void 0),c=a[0],s=a[1],l=n.useState(!0),f=l[0],d=l[1],v=n.useState(null),p=v[0],m=v[1],g=n.useState(!1),h=g[0],y=g[1],w=n.useRef(null),b=n.useRef(null),k=n.useRef(null);return n.useEffect(function(){if("undefined"==typeof window)return m("useWasmCompute is not available during SSR"),void d(!1);if("undefined"==typeof Worker)return m("Worker is not supported in this environment"),void d(!1);if("undefined"==typeof WebAssembly||"function"!=typeof WebAssembly.instantiate)return m("WebAssembly is not supported in this environment"),void d(!1);m(null),y(!1);var e=function(e){if(e)return new Worker(e);var n=new Blob(["\nself.onmessage = async (e) => {\n const d = e.data;\n if (d.type === 'init') {\n try {\n const res = await fetch(d.wasmUrl);\n const buf = await res.arrayBuffer();\n const mod = await WebAssembly.instantiate(buf, d.importObject || {});\n self.wasmInstance = mod.instance;\n self.exportName = d.exportName || 'compute';\n self.postMessage({ type: 'ready' });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n return;\n }\n if (d.type === 'compute') {\n try {\n const fn = self.wasmInstance.exports[self.exportName];\n if (typeof fn !== 'function') {\n self.postMessage({ type: 'error', error: 'Export \"' + self.exportName + '\" is not a function' });\n return;\n }\n const result = fn(d.input);\n self.postMessage({ type: 'result', result: result });\n } catch (err) {\n self.postMessage({ type: 'error', error: (err && err.message) || String(err) });\n }\n }\n};\n"],{type:"application/javascript"}),r=URL.createObjectURL(n),t=new Worker(r);return URL.revokeObjectURL(r),t}(u);w.current=e;var n=function(e){var n,r=null!=(n=e.data)?n:{},t=r.type,o=r.result,u=r.error;return"ready"===t?(y(!0),void d(!1)):"error"===t?(m(null!=u?u:"Unknown error"),d(!1),void(k.current&&(k.current(new Error(u)),b.current=null,k.current=null))):void("result"===t&&(s(o),d(!1),b.current&&(b.current(o),b.current=null,k.current=null)))};return e.addEventListener("message",n),e.postMessage({type:"init",wasmUrl:r,exportName:o,importObject:null!=i?i:{}}),function(){e.removeEventListener("message",n),e.terminate(),w.current=null,k.current&&(k.current(new Error("Worker terminated")),b.current=null,k.current=null)}},[r,o,u,i]),{compute:n.useCallback(function(e){return new Promise(function(n,r){w.current&&h?p?r(new Error(p)):(b.current=n,k.current=r,d(!0),w.current.postMessage({type:"compute",input:e})):r(new Error("WASM not ready"))})},[h,p]),result:c,loading:f,error:p,ready:h}},e.useWebRTCIP=function(e){void 0===e&&(e={});var r=e.stunServers,t=void 0===r?v:r,o=e.timeout,u=void 0===o?3e3:o,i=e.onDetect,a=n.useState([]),c=a[0],s=a[1],l=n.useState(!0),f=l[0],p=l[1],m=n.useState(null),g=m[0],h=m[1],y=n.useRef(null),w=n.useRef(null),b=n.useRef(new Set),k=n.useRef(i);return k.current=i,n.useEffect(function(){if("undefined"==typeof window)return p(!1),void h("WebRTC IP detection is not available during SSR");if("undefined"==typeof RTCPeerConnection)return p(!1),void h("RTCPeerConnection is not available");var e=new Set;b.current=e;var n=function(){w.current&&(clearTimeout(w.current),w.current=null),y.current&&(y.current.close(),y.current=null),p(!1)},r=function(n){e.has(n)||(e.add(n),s(function(e){return[].concat(e,[n])}),null==k.current||k.current(n))};try{var o=new RTCPeerConnection({iceServers:[{urls:t}]});y.current=o,o.onicecandidate=function(e){var n,t=e.candidate;t&&t.candidate&&((n=t.candidate.match(d))?[].concat(n):[]).forEach(r)},o.createDataChannel(""),o.createOffer().then(function(e){return o.setLocalDescription(e)}).catch(function(e){h(e instanceof Error?e.message:"Failed to create offer"),n()}),w.current=setTimeout(function(){return n()},u)}catch(e){h(e instanceof Error?e.message:"WebRTC setup failed"),n()}return function(){n()}},[t.join(","),u]),{ips:c,loading:f,error:g}},e.useWorkerNotifications=function(e,r){void 0===r&&(r={});var t=r.maxHistory,o=void 0===t?100:t,u=r.throughputWindowMs,i=void 0===u?1e3:u,a=n.useState([]),c=a[0],s=a[1],l=n.useState(0),f=l[0],d=l[1],v=n.useState(0),p=v[0],m=v[1],g=n.useState([]),h=g[0],y=g[1],w=n.useState(0),b=w[0],k=w[1],S=n.useRef([]),E=n.useRef(0),x=n.useRef(0);n.useEffect(function(){if(e){var n=function(e){var n=function(e){if(null==e||"object"!=typeof e)return null;var n=e.type;return"task_start"!==n&&"task_end"!==n&&"task_fail"!==n&&"queue_size"!==n?null:{type:n,taskId:"string"==typeof e.taskId?e.taskId:void 0,duration:"number"==typeof e.duration?e.duration:void 0,error:"string"==typeof e.error?e.error:void 0,size:"number"==typeof e.size?e.size:void 0,timestamp:Date.now()}}(e.data);if(n)if(y(function(e){return[].concat(e,[n]).slice(-o)}),"task_start"===n.type&&n.taskId)s(function(e){return e.includes(n.taskId)?e:[].concat(e,[n.taskId])});else if("task_end"===n.type){n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),d(function(e){return e+1});var r=Date.now()-i;S.current=[].concat(S.current.filter(function(e){return e>=r}),[n.timestamp]),"number"==typeof n.duration&&(E.current+=n.duration,x.current+=1)}else"task_fail"===n.type?(n.taskId&&s(function(e){return e.filter(function(e){return e!==n.taskId})}),m(function(e){return e+1})):"queue_size"===n.type&&"number"==typeof n.size&&k(n.size)};return e.addEventListener("message",n),function(){return e.removeEventListener("message",n)}}},[e,o]);var T=n.useMemo(function(){var e=x.current;return e>0?E.current/e:0},[h]),C=n.useMemo(function(){var e=Date.now()-i;return S.current.filter(function(n){return n>=e}).length/(i/1e3)},[h,i]),I=n.useMemo(function(){return{runningTasks:c,completedCount:f,failedCount:p,averageDurationMs:T,throughputPerSecond:C,currentQueueSize:b,totalProcessed:f+p,recentEventCount:h.length}},[c,f,p,T,C,b,h.length]);return{runningTasks:c,completedCount:f,failedCount:p,eventHistory:h,averageDurationMs:T,throughputPerSecond:C,currentQueueSize:b,progress:I}},e.useWrappedChildren=function(e,t,o){return void 0===o&&(o="preserve"),n.useMemo(function(){if(!e)return e;var n=function(e){if(!r.isValidElement(e))return e;var n,u=e.props||{};n="override"===o?i({},u,t):i({},t,u);var a=null==u?void 0:u.style,c=null==t?void 0:t.style;return a&&c&&"object"==typeof a&&"object"==typeof c&&(n.style="override"===o?i({},a,c):i({},c,a)),r.cloneElement(e,n)};return Array.isArray(e)?e.map(n):n(e)},[e,t,o])}});
@@ -0,0 +1,71 @@
1
+ /** Open Graph / content type for og:type. */
2
+ export type OGType = "website" | "article" | "profile" | "video.other" | "product" | "music.song" | "book";
3
+ /** Config for the useLLMMetadata hook. All fields optional except route. */
4
+ export interface LLMConfig {
5
+ /** Current route path (e.g. "/blog/ai-hooks"). Changes trigger metadata update. */
6
+ route: string;
7
+ /** "manual" = use title/description/tags from config. "auto-extract" = derive from DOM. */
8
+ mode?: "manual" | "auto-extract";
9
+ /** Page title (manual mode). */
10
+ title?: string;
11
+ /** Page description (manual mode). */
12
+ description?: string;
13
+ /** Tags/keywords (manual mode). */
14
+ tags?: string[];
15
+ /** Canonical URL (absolute). */
16
+ canonicalUrl?: string;
17
+ /** Content language (e.g. "en", "en-US"). */
18
+ language?: string;
19
+ /** Open Graph type (website, article, etc.). */
20
+ ogType?: OGType;
21
+ /** OG image URL (absolute). */
22
+ ogImage?: string;
23
+ /** OG image alt text. */
24
+ ogImageAlt?: string;
25
+ /** Site name (e.g. for social previews). */
26
+ siteName?: string;
27
+ /** Author name (for articles). */
28
+ author?: string;
29
+ /** ISO date string (article publish). */
30
+ publishedTime?: string;
31
+ /** ISO date string (article last modified). */
32
+ modifiedTime?: string;
33
+ /** Robots hint (e.g. "index, follow"). */
34
+ robots?: string;
35
+ /** Extra key-value pairs (e.g. section, category). Keys/values are sanitized. */
36
+ extra?: Record<string, string | number | boolean | string[]>;
37
+ }
38
+ /** Payload injected as JSON in the LLM script tag. Only includes defined, safe values. */
39
+ export interface LLMPayload {
40
+ route: string;
41
+ title?: string;
42
+ description?: string;
43
+ tags?: string[];
44
+ outline?: string[];
45
+ canonicalUrl?: string;
46
+ language?: string;
47
+ ogType?: string;
48
+ ogImage?: string;
49
+ ogImageAlt?: string;
50
+ siteName?: string;
51
+ author?: string;
52
+ publishedTime?: string;
53
+ modifiedTime?: string;
54
+ robots?: string;
55
+ generatedAt: string;
56
+ extra?: Record<string, string | number | boolean | string[]>;
57
+ }
58
+ /**
59
+ * Production-ready hook: injects an AI-readable metadata block into the document head
60
+ * when the route changes. Framework-agnostic (React 18+ and Preact 10+ via aliasing).
61
+ *
62
+ * - Rich structure: route, title, description, tags, outline (auto), canonicalUrl, language,
63
+ * ogType, ogImage, ogImageAlt, siteName, author, publishedTime, modifiedTime, robots, extra.
64
+ * - Safe usage: never throws; invalid/missing config is normalized; DOM and JSON are guarded.
65
+ * - Cacheable: if the generated payload is unchanged, the script is not replaced.
66
+ * - SSR-safe: no-op when window/document is undefined.
67
+ * - Cleans up on unmount (removes the script).
68
+ *
69
+ * @param config - Route (required), mode, and optional metadata fields. Can be partial; defaults applied.
70
+ */
71
+ export declare function useLLMMetadata(config: LLMConfig | null | undefined): void;
package/docs/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # Preact Missing Hooks — Demo & Usage
2
+
3
+ This folder contains a **live demo** of all hooks from `preact-missing-hooks`. Each hook is shown with a short flow description, example code, and an interactive “Live” panel.
4
+
5
+ ## Running the demo
6
+
7
+ ### Option 1: Local build + static server (recommended)
8
+
9
+ From the project root:
10
+
11
+ ```bash
12
+ npm run build
13
+ npx serve -l 5000
14
+ ```
15
+
16
+ Then open **http://localhost:5000/docs/** in your browser. The demo will load the built package from `../dist/index.module.js`.
17
+
18
+ ### Option 2: Demo script
19
+
20
+ From the project root you can use the existing demo script:
21
+
22
+ ```bash
23
+ npm run demo
24
+ ```
25
+
26
+ Then open **http://localhost:5000/docs/** (or the port shown).
27
+
28
+ ### Option 3: Unpkg (no build)
29
+
30
+ Open `docs/index.html` in a browser that supports ES modules and import maps. The demo will load Preact and `preact-missing-hooks` from unpkg. Some features (e.g. `useWasmCompute` with a local WASM file) may be limited when opened as a file.
31
+
32
+ ---
33
+
34
+ ## What the demo includes
35
+
36
+ | Hook | What you can try |
37
+ | -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
38
+ | **useTransition** | Deferred state update; button shows “Pending…” then count. |
39
+ | **useMutationObserver** | Add a node in the observed area; see mutation count. |
40
+ | **useEventBus** | Emit “greet” and see the message in another part of the UI. |
41
+ | **useWrappedChildren** | Children buttons get injected styles. |
42
+ | **usePreferredTheme** | Shows light / dark / no-preference from system. |
43
+ | **useNetworkState** | Online/offline and connection type. |
44
+ | **useClipboard** | Copy and paste; see “Copied!” and pasted text. |
45
+ | **useRageClick** | Click the area 3+ times quickly; rage click count. |
46
+ | **useThreadedWorker** | Run a task; see loading and result. |
47
+ | **useIndexedDB** | Insert, bulk insert, query, update, delete, clear. |
48
+ | **useWebRTCIP** | Detect IP via WebRTC (may take a few seconds). |
49
+ | **useWasmCompute** | Run WASM in a worker (needs `add.wasm` in docs). |
50
+ | **useWorkerNotifications** | Run/fail tasks and queue updates; toasts show events. |
51
+ | **useLLMMetadata** | Change “route” with buttons; see injected script info in the Live panel and `<script data-llm="true">` in the document head. Safe with `null`/`undefined` config (minimal payload with `route: "/"`). |
52
+
53
+ ---
54
+
55
+ ## Demo usage patterns
56
+
57
+ ### Minimal Preact example
58
+
59
+ ```js
60
+ import { h, render } from "preact";
61
+ import { useState } from "preact/hooks";
62
+ import { useClipboard, usePreferredTheme } from "preact-missing-hooks";
63
+
64
+ function App() {
65
+ const { copy, copied } = useClipboard();
66
+ const theme = usePreferredTheme();
67
+ return h(
68
+ "div",
69
+ {},
70
+ h("button", { onClick: () => copy("Hi") }, copied ? "Copied!" : "Copy"),
71
+ h("span", {}, " Theme: " + theme)
72
+ );
73
+ }
74
+ render(h(App), document.getElementById("root"));
75
+ ```
76
+
77
+ ### With React
78
+
79
+ ```jsx
80
+ import { useTransition, useLLMMetadata } from "preact-missing-hooks/react";
81
+ import { useLocation } from "react-router-dom";
82
+
83
+ function App() {
84
+ const { pathname } = useLocation();
85
+ useLLMMetadata({ route: pathname, mode: "auto-extract", tags: ["my-app"] });
86
+ const [startTransition, isPending] = useTransition();
87
+ // ...
88
+ }
89
+ ```
90
+
91
+ ### useLLMMetadata in the demo
92
+
93
+ The **useLLMMetadata** Live panel simulates route changes. Click “Route: /”, “Route: /blog”, or “Route: /docs”. Each change:
94
+
95
+ 1. Removes any existing `<script data-llm="true">`.
96
+ 2. Injects a new script with `type="application/llm+json"` containing `route`, `title`, `description`, `tags`, and `generatedAt`.
97
+
98
+ Inspect the page’s `<head>` in DevTools to see the script. The Live panel shows a short summary of the injected payload. The hook never throws: passing `null` or `undefined` as config is safe and yields a minimal payload with `route: "/"` and `generatedAt`.
99
+
100
+ ---
101
+
102
+ ## File layout
103
+
104
+ - **index.html** — Page shell, styles, and import map; mounts the app into `#root`.
105
+ - **main.js** — Imports the package and Preact, defines demo components and the `HOOKS` list, renders the app.
106
+
107
+ To add a new hook to the demo:
108
+
109
+ 1. Import it in `main.js` from the package.
110
+ 2. Implement a `DemoXxx` component that uses the hook.
111
+ 3. Add an entry to the `HOOKS` array with `name`, `flow`, `summary`, `code`, and `Live: DemoXxx`.