@yuktishaalaa/yuktai 3.0.11 → 3.0.12
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var m=null,g=null,i=!1,u=!1;async function p(){if(!u){if(i){for(;i;)await new Promise(e=>setTimeout(e,200));return}i=!0;try{let{pipeline:e,env:t}=await import("@huggingface/transformers");t.allowRemoteModels=!0,t.allowLocalModels=!1,typeof window<"u"&&typeof caches<"u"?t.useBrowserCache=!0:t.useBrowserCache=!1,m=await e("feature-extraction","Xenova/all-MiniLM-L6-v2",{device:typeof navigator<"u"&&"gpu"in navigator?"webgpu":"wasm"}),g=await e("question-answering","Xenova/distilbert-base-cased-distilled-squad",{device:typeof navigator<"u"&&"gpu"in navigator?"webgpu":"wasm"}),u=!0,i=!1,console.log("yuktai: Transformers.js models loaded \u2705")}catch(e){throw i=!1,console.error("yuktai: Transformers.js model load failed",e),e}}}function w(){return new Promise(e=>{let t=setTimeout(e,1500),r=new MutationObserver(()=>{clearTimeout(t),t=setTimeout(()=>{r.disconnect(),e()},500)});r.observe(document.body,{childList:!0,subtree:!0})})}function h(){let e=[],t=document.querySelectorAll("*");for(let r of t){if(r.closest("[data-yuktai-panel]"))continue;let o=r.innerText?.trim();o&&o.length>30&&e.push(o);let s=r.getAttribute("aria-label");s&&s.length>10&&e.push(s),(r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement)&&r.placeholder&&e.push(r.placeholder)}return e.join(" ").slice(0,8e3)}function y(e,t=200,r=50){if(typeof e!="string")try{e=String(e??"")}catch{return[]}let o=e.trim();if(!o)return[];let s=Math.min(r,Math.floor(t/2)),n=o.split(/\s+/),a=[],l=t-s;for(let c=0;c<n.length;c+=l){let f=n.slice(c,c+t).join(" ");f.trim().length>20&&a.push(f)}return a}function b(e,t){let r=0,o=0,s=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n],o+=e[n]*e[n],s+=t[n]*t[n];return r/(Math.sqrt(o)*Math.sqrt(s)+1e-8)}async function d(e){let t=await m(e,{pooling:"mean",normalize:!0}),r=t?.data??t;return Array.from(r)}async function v(e,t,r=3){let o=await d(e),s=await Promise.all(t.map(async n=>{let a=await d(n),l=b(o,a);return{chunk:n,score:l}}));return s.sort((n,a)=>a.score-n.score),s.slice(0,r).map(n=>n.chunk)}async function M(e){if(!e.trim())return{success:!1,answer:"",error:"Please type a question."};try{await p(),await w();let t=h();if(!t||t.length<50)return{success:!1,answer:"",error:"Not enough content on this page."};let r=y(t);if(r.length===0)return{success:!1,answer:"",error:"Could not process page content."};let s=(await v(e,r,3)).join(" ... "),n=await g(e,s);return!n?.answer||n.answer.trim().length===0?{success:!0,answer:"I could not find a specific answer on this page."}:{success:!0,answer:n.answer.trim()}}catch(t){return console.error("yuktai: Transformers RAG error",t),{success:!1,answer:"",error:t instanceof Error?t.message:"Transformers.js error."}}}function k(){try{return typeof WebAssembly<"u"&&typeof Worker<"u"}catch{return!1}}function P(){return u?"ready":i?"loading":"idle"}export{M as a,k as b,P as c};
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ Keep answer short (2\u20133 sentences).
|
|
|
3
3
|
If not found say: "I could not find that on this page."`,outputLanguage:"en"})}catch{a=await n.create()}let s=`Page:
|
|
4
4
|
${i}
|
|
5
5
|
|
|
6
|
-
Q: ${e}`,o=await a.prompt(s);return a?.destroy&&a.destroy(),{success:!0,answer:o?.trim()||"No answer found."}}catch(t){return{success:!1,answer:"",error:t instanceof Error?t.message:"Error occurred"}}}var Re=xe(()=>{"use strict";p()});var gt={};he(gt,{askPageWithTransformers:()=>ze,getModelLoadStatus:()=>X,isTransformersSupported:()=>J});async function Xt(){if(!Ie){if(G){for(;G;)await new Promise(e=>setTimeout(e,200));return}G=!0;try{let{pipeline:e,env:t}=await import("@huggingface/transformers");t.allowRemoteModels=!0,t.allowLocalModels=!1,t.useBrowserCache=!0,ft=await e("feature-extraction","Xenova/all-MiniLM-L6-v2",{device:typeof navigator<"u"&&"gpu"in navigator?"webgpu":"wasm"}),mt=await e("question-answering","Xenova/distilbert-base-cased-distilled-squad",{device:typeof navigator<"u"&&"gpu"in navigator?"webgpu":"wasm"}),Ie=!0,G=!1,console.log("yuktai: Transformers.js models loaded \u2705")}catch(e){throw G=!1,console.error("yuktai: Transformers.js model load failed",e),e}}}function Qt(){return new Promise(e=>{let t=setTimeout(e,1500),n=new MutationObserver(()=>{clearTimeout(t),t=setTimeout(()=>{n.disconnect(),e()},500)});n.observe(document.body,{childList:!0,subtree:!0})})}function Zt(){let e=[],t=document.querySelectorAll("*");for(let n of t){if(n.closest("[data-yuktai-panel]"))continue;let i=n.innerText?.trim();i&&i.length>30&&e.push(i);let a=n.getAttribute("aria-label");a&&a.length>10&&e.push(a),(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement)&&n.placeholder&&e.push(n.placeholder)}return e.join(" ").slice(0,8e3)}function en(e,t=200,n=50){if(typeof e!="string")try{e=String(e??"")}catch{return[]}let i=e.trim();if(!i)return[];let a=Math.min(n,Math.floor(t/2)),s=i.split(/\s+/),o=[],c=t-a;for(let b=0;b<s.length;b+=c){let u=s.slice(b,b+t).join(" ");u.trim().length>20&&o.push(u)}return o}function tn(e,t){let n=0,i=0,a=0;for(let s=0;s<e.length;s++)n+=e[s]*t[s],i+=e[s]*e[s],a+=t[s]*t[s];return n/(Math.sqrt(i)*Math.sqrt(a)+1e-8)}async function pt(e){let t=await ft(e,{pooling:"mean",normalize:!0}),n=t?.data??t;return Array.from(n)}async function nn(e,t,n=3){let i=await pt(e),a=await Promise.all(t.map(async s=>{let o=await pt(s),c=tn(i,o);return{chunk:s,score:c}}));return a.sort((s,o)=>o.score-s.score),a.slice(0,n).map(s=>s.chunk)}async function ze(e){if(!e.trim())return{success:!1,answer:"",error:"Please type a question."};try{await Xt(),await Qt();let t=Zt();if(!t||t.length<50)return{success:!1,answer:"",error:"Not enough content on this page."};let n=en(t);if(n.length===0)return{success:!1,answer:"",error:"Could not process page content."};let a=(await nn(e,n,3)).join(" ... "),s=await mt(e,a);return!s?.answer||s.answer.trim().length===0?{success:!0,answer:"I could not find a specific answer on this page."}:{success:!0,answer:s.answer.trim()}}catch(t){return console.error("yuktai: Transformers RAG error",t),{success:!1,answer:"",error:t instanceof Error?t.message:"Transformers.js error."}}}function J(){try{return typeof WebAssembly<"u"&&typeof Worker<"u"}catch{return!1}}function X(){return Ie?"ready":G?"loading":"idle"}var ft,mt,G,Ie,pe=xe(()=>{"use strict";p();ft=null,mt=null,G=!1,Ie=!1});var un={};he(un,{Runtime:()=>W,YuktAI:()=>dn,YuktAIWrapper:()=>fe,aiPlugin:()=>Z,default:()=>fe,voicePlugin:()=>ee,wcag:()=>C,wcagPlugin:()=>C});module.exports=Tt(un);p();p();p();function Oe(){let e=window;return e.Rewriter||e.ai?.rewriter||null}async function we(){try{let e=Oe();if(!e)return!1;if(typeof e.availability=="function"){let t=await e.availability();return t==="readily"||t==="available"||t==="downloadable"}return typeof e.capabilities=="function"?(await e.capabilities())?.available!=="no":typeof e.create=="function"}catch{return!1}}async function Et(e){if(!e||e.trim().length<20)return{success:!1,original:e,rewritten:e,error:"Text too short"};try{let t=Oe();if(!t)throw new Error("Rewriter API not available");let n=await t.create({tone:"more-casual",format:"plain-text",length:"as-is",outputLanguage:"en"}),i=await n.rewrite(e,{context:"Rewrite this text in simple plain English. Use short sentences. Avoid jargon. Make it easy to understand for everyone."});return n.destroy(),{success:!0,original:e,rewritten:i.trim()}}catch(t){return{success:!1,original:e,rewritten:e,error:t instanceof Error?t.message:"Rewrite failed"}}}async function De(){if(!await we())return{fixed:0,error:"Chrome Built-in AI Rewriter not available. Enable via chrome://flags."};let t=document.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li, blockquote, td, th, label, figcaption"),n=0;for(let i of t){let a=i.innerText?.trim();if(!a||a.length<20||i.closest("[data-yuktai-panel]"))continue;let s=await Et(a);s.success&&s.rewritten!==a&&(i.dataset.yuktaiOriginal=a,i.innerText=s.rewritten,n++)}return{fixed:n}}function Ge(){let e=document.querySelectorAll("[data-yuktai-original]");for(let t of e){let n=t.dataset.yuktaiOriginal;n&&(t.innerText=n,delete t.dataset.yuktaiOriginal)}}p();var qe="yuktai-summary-box";function _e(){let e=window;return e.Summarizer||e.ai?.summarizer||null}async function ve(){try{let e=_e();if(!e)return!1;if(typeof e.availability=="function"){let t=await e.availability();return t==="readily"||t==="available"||t==="downloadable"}return typeof e.capabilities=="function"?(await e.capabilities())?.available!=="no":typeof e.create=="function"}catch{return!1}}function Ct(){let e=document.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li, blockquote, article, section"),t=[];for(let n of e){if(n.closest("[data-yuktai-panel]"))continue;let i=window.getComputedStyle(n);if(i.display==="none"||i.visibility==="hidden")continue;let a=n.innerText?.trim();a&&a.length>10&&t.push(a)}return t.join(" ").slice(0,5e3)}async function je(){if(!await ve())return{success:!1,summary:"",error:"Chrome Built-in AI Summarizer not available. Enable via chrome://flags."};let t=Ct();if(!t||t.length<100)return{success:!1,summary:"",error:"Not enough text on this page to summarise."};try{let n=_e();if(!n)throw new Error("Summarizer API not available");let i=await n.create({type:"tl;dr",format:"plain-text",length:"short",outputLanguage:"en"}),a=await i.summarize(t,{context:"Summarise this page in 2-3 simple sentences for a screen reader user who wants to know if this page is relevant to them."});return i.destroy(),Lt(a.trim()),{success:!0,summary:a.trim()}}catch(n){return{success:!1,summary:"",error:n instanceof Error?n.message:"Summary failed"}}}function Lt(e){oe();let t=document.createElement("div");t.id=qe,t.setAttribute("data-yuktai-panel","true"),t.setAttribute("role","region"),t.setAttribute("aria-label","Page summary by yuktai"),t.style.cssText=`
|
|
6
|
+
Q: ${e}`,o=await a.prompt(s);return a?.destroy&&a.destroy(),{success:!0,answer:o?.trim()||"No answer found."}}catch(t){return{success:!1,answer:"",error:t instanceof Error?t.message:"Error occurred"}}}var Re=xe(()=>{"use strict";p()});var gt={};he(gt,{askPageWithTransformers:()=>ze,getModelLoadStatus:()=>X,isTransformersSupported:()=>J});async function Xt(){if(!Ie){if(G){for(;G;)await new Promise(e=>setTimeout(e,200));return}G=!0;try{let{pipeline:e,env:t}=await import("@huggingface/transformers");t.allowRemoteModels=!0,t.allowLocalModels=!1,typeof window<"u"&&typeof caches<"u"?t.useBrowserCache=!0:t.useBrowserCache=!1,ft=await e("feature-extraction","Xenova/all-MiniLM-L6-v2",{device:typeof navigator<"u"&&"gpu"in navigator?"webgpu":"wasm"}),mt=await e("question-answering","Xenova/distilbert-base-cased-distilled-squad",{device:typeof navigator<"u"&&"gpu"in navigator?"webgpu":"wasm"}),Ie=!0,G=!1,console.log("yuktai: Transformers.js models loaded \u2705")}catch(e){throw G=!1,console.error("yuktai: Transformers.js model load failed",e),e}}}function Qt(){return new Promise(e=>{let t=setTimeout(e,1500),n=new MutationObserver(()=>{clearTimeout(t),t=setTimeout(()=>{n.disconnect(),e()},500)});n.observe(document.body,{childList:!0,subtree:!0})})}function Zt(){let e=[],t=document.querySelectorAll("*");for(let n of t){if(n.closest("[data-yuktai-panel]"))continue;let i=n.innerText?.trim();i&&i.length>30&&e.push(i);let a=n.getAttribute("aria-label");a&&a.length>10&&e.push(a),(n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement)&&n.placeholder&&e.push(n.placeholder)}return e.join(" ").slice(0,8e3)}function en(e,t=200,n=50){if(typeof e!="string")try{e=String(e??"")}catch{return[]}let i=e.trim();if(!i)return[];let a=Math.min(n,Math.floor(t/2)),s=i.split(/\s+/),o=[],c=t-a;for(let b=0;b<s.length;b+=c){let u=s.slice(b,b+t).join(" ");u.trim().length>20&&o.push(u)}return o}function tn(e,t){let n=0,i=0,a=0;for(let s=0;s<e.length;s++)n+=e[s]*t[s],i+=e[s]*e[s],a+=t[s]*t[s];return n/(Math.sqrt(i)*Math.sqrt(a)+1e-8)}async function pt(e){let t=await ft(e,{pooling:"mean",normalize:!0}),n=t?.data??t;return Array.from(n)}async function nn(e,t,n=3){let i=await pt(e),a=await Promise.all(t.map(async s=>{let o=await pt(s),c=tn(i,o);return{chunk:s,score:c}}));return a.sort((s,o)=>o.score-s.score),a.slice(0,n).map(s=>s.chunk)}async function ze(e){if(!e.trim())return{success:!1,answer:"",error:"Please type a question."};try{await Xt(),await Qt();let t=Zt();if(!t||t.length<50)return{success:!1,answer:"",error:"Not enough content on this page."};let n=en(t);if(n.length===0)return{success:!1,answer:"",error:"Could not process page content."};let a=(await nn(e,n,3)).join(" ... "),s=await mt(e,a);return!s?.answer||s.answer.trim().length===0?{success:!0,answer:"I could not find a specific answer on this page."}:{success:!0,answer:s.answer.trim()}}catch(t){return console.error("yuktai: Transformers RAG error",t),{success:!1,answer:"",error:t instanceof Error?t.message:"Transformers.js error."}}}function J(){try{return typeof WebAssembly<"u"&&typeof Worker<"u"}catch{return!1}}function X(){return Ie?"ready":G?"loading":"idle"}var ft,mt,G,Ie,pe=xe(()=>{"use strict";p();ft=null,mt=null,G=!1,Ie=!1});var un={};he(un,{Runtime:()=>W,YuktAI:()=>dn,YuktAIWrapper:()=>fe,aiPlugin:()=>Z,default:()=>fe,voicePlugin:()=>ee,wcag:()=>C,wcagPlugin:()=>C});module.exports=Tt(un);p();p();p();function Oe(){let e=window;return e.Rewriter||e.ai?.rewriter||null}async function we(){try{let e=Oe();if(!e)return!1;if(typeof e.availability=="function"){let t=await e.availability();return t==="readily"||t==="available"||t==="downloadable"}return typeof e.capabilities=="function"?(await e.capabilities())?.available!=="no":typeof e.create=="function"}catch{return!1}}async function Et(e){if(!e||e.trim().length<20)return{success:!1,original:e,rewritten:e,error:"Text too short"};try{let t=Oe();if(!t)throw new Error("Rewriter API not available");let n=await t.create({tone:"more-casual",format:"plain-text",length:"as-is",outputLanguage:"en"}),i=await n.rewrite(e,{context:"Rewrite this text in simple plain English. Use short sentences. Avoid jargon. Make it easy to understand for everyone."});return n.destroy(),{success:!0,original:e,rewritten:i.trim()}}catch(t){return{success:!1,original:e,rewritten:e,error:t instanceof Error?t.message:"Rewrite failed"}}}async function De(){if(!await we())return{fixed:0,error:"Chrome Built-in AI Rewriter not available. Enable via chrome://flags."};let t=document.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li, blockquote, td, th, label, figcaption"),n=0;for(let i of t){let a=i.innerText?.trim();if(!a||a.length<20||i.closest("[data-yuktai-panel]"))continue;let s=await Et(a);s.success&&s.rewritten!==a&&(i.dataset.yuktaiOriginal=a,i.innerText=s.rewritten,n++)}return{fixed:n}}function Ge(){let e=document.querySelectorAll("[data-yuktai-original]");for(let t of e){let n=t.dataset.yuktaiOriginal;n&&(t.innerText=n,delete t.dataset.yuktaiOriginal)}}p();var qe="yuktai-summary-box";function _e(){let e=window;return e.Summarizer||e.ai?.summarizer||null}async function ve(){try{let e=_e();if(!e)return!1;if(typeof e.availability=="function"){let t=await e.availability();return t==="readily"||t==="available"||t==="downloadable"}return typeof e.capabilities=="function"?(await e.capabilities())?.available!=="no":typeof e.create=="function"}catch{return!1}}function Ct(){let e=document.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li, blockquote, article, section"),t=[];for(let n of e){if(n.closest("[data-yuktai-panel]"))continue;let i=window.getComputedStyle(n);if(i.display==="none"||i.visibility==="hidden")continue;let a=n.innerText?.trim();a&&a.length>10&&t.push(a)}return t.join(" ").slice(0,5e3)}async function je(){if(!await ve())return{success:!1,summary:"",error:"Chrome Built-in AI Summarizer not available. Enable via chrome://flags."};let t=Ct();if(!t||t.length<100)return{success:!1,summary:"",error:"Not enough text on this page to summarise."};try{let n=_e();if(!n)throw new Error("Summarizer API not available");let i=await n.create({type:"tl;dr",format:"plain-text",length:"short",outputLanguage:"en"}),a=await i.summarize(t,{context:"Summarise this page in 2-3 simple sentences for a screen reader user who wants to know if this page is relevant to them."});return i.destroy(),Lt(a.trim()),{success:!0,summary:a.trim()}}catch(n){return{success:!1,summary:"",error:n instanceof Error?n.message:"Summary failed"}}}function Lt(e){oe();let t=document.createElement("div");t.id=qe,t.setAttribute("data-yuktai-panel","true"),t.setAttribute("role","region"),t.setAttribute("aria-label","Page summary by yuktai"),t.style.cssText=`
|
|
7
7
|
position: fixed;
|
|
8
8
|
top: 0;
|
|
9
9
|
left: 0;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as ze}from"./chunk-3VGU4YGK.mjs";import{a as He,b as te,c as ae}from"./chunk-
|
|
1
|
+
import{a as ze}from"./chunk-3VGU4YGK.mjs";import{a as He,b as te,c as ae}from"./chunk-R7HFPJ7V.mjs";function We(){let e=window;return e.Rewriter||e.ai?.rewriter||null}async function xe(){try{let e=We();if(!e)return!1;if(typeof e.availability=="function"){let t=await e.availability();return t==="readily"||t==="available"||t==="downloadable"}return typeof e.capabilities=="function"?(await e.capabilities())?.available!=="no":typeof e.create=="function"}catch{return!1}}async function ct(e){if(!e||e.trim().length<20)return{success:!1,original:e,rewritten:e,error:"Text too short"};try{let t=We();if(!t)throw new Error("Rewriter API not available");let a=await t.create({tone:"more-casual",format:"plain-text",length:"as-is",outputLanguage:"en"}),i=await a.rewrite(e,{context:"Rewrite this text in simple plain English. Use short sentences. Avoid jargon. Make it easy to understand for everyone."});return a.destroy(),{success:!0,original:e,rewritten:i.trim()}}catch(t){return{success:!1,original:e,rewritten:e,error:t instanceof Error?t.message:"Rewrite failed"}}}async function $e(){if(!await xe())return{fixed:0,error:"Chrome Built-in AI Rewriter not available. Enable via chrome://flags."};let t=document.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li, blockquote, td, th, label, figcaption"),a=0;for(let i of t){let n=i.innerText?.trim();if(!n||n.length<20||i.closest("[data-yuktai-panel]"))continue;let l=await ct(n);l.success&&l.rewritten!==n&&(i.dataset.yuktaiOriginal=n,i.innerText=l.rewritten,a++)}return{fixed:a}}function Fe(){let e=document.querySelectorAll("[data-yuktai-original]");for(let t of e){let a=t.dataset.yuktaiOriginal;a&&(t.innerText=a,delete t.dataset.yuktaiOriginal)}}var Be="yuktai-summary-box";function Ne(){let e=window;return e.Summarizer||e.ai?.summarizer||null}async function he(){try{let e=Ne();if(!e)return!1;if(typeof e.availability=="function"){let t=await e.availability();return t==="readily"||t==="available"||t==="downloadable"}return typeof e.capabilities=="function"?(await e.capabilities())?.available!=="no":typeof e.create=="function"}catch{return!1}}function ut(){let e=document.querySelectorAll("p, h1, h2, h3, h4, h5, h6, li, blockquote, article, section"),t=[];for(let a of e){if(a.closest("[data-yuktai-panel]"))continue;let i=window.getComputedStyle(a);if(i.display==="none"||i.visibility==="hidden")continue;let n=a.innerText?.trim();n&&n.length>10&&t.push(n)}return t.join(" ").slice(0,5e3)}async function Oe(){if(!await he())return{success:!1,summary:"",error:"Chrome Built-in AI Summarizer not available. Enable via chrome://flags."};let t=ut();if(!t||t.length<100)return{success:!1,summary:"",error:"Not enough text on this page to summarise."};try{let a=Ne();if(!a)throw new Error("Summarizer API not available");let i=await a.create({type:"tl;dr",format:"plain-text",length:"short",outputLanguage:"en"}),n=await i.summarize(t,{context:"Summarise this page in 2-3 simple sentences for a screen reader user who wants to know if this page is relevant to them."});return i.destroy(),pt(n.trim()),{success:!0,summary:n.trim()}}catch(a){return{success:!1,summary:"",error:a instanceof Error?a.message:"Summary failed"}}}function pt(e){oe();let t=document.createElement("div");t.id=Be,t.setAttribute("data-yuktai-panel","true"),t.setAttribute("role","region"),t.setAttribute("aria-label","Page summary by yuktai"),t.style.cssText=`
|
|
2
2
|
position: fixed;
|
|
3
3
|
top: 0;
|
|
4
4
|
left: 0;
|
|
@@ -382,4 +382,4 @@ import{a as ze}from"./chunk-3VGU4YGK.mjs";import{a as He,b as te,c as ae}from"./
|
|
|
382
382
|
values="0.95 0.05 0 0 0 0 0.433 0.567 0 0 0 0.475 0.525 0 0 0 0 0 1 0"/>
|
|
383
383
|
</filter>
|
|
384
384
|
</defs>
|
|
385
|
-
`,document.body.appendChild(e),Ue=e}function ot(e){let t={critical:20,serious:10,moderate:5,minor:2},a=e.details.reduce((i,n)=>i+(t[n.severity]||0),0);return Math.max(0,Math.min(100,100-a))}var C={name:"yuktai-a11y",version:"4.0.0",observer:null,async execute(e){if(!e.enabled)return this.stopObserver(),"yuktai: disabled.";D=e,Rt(e),Pt(),It(),St(),Tt(),e.showSkipLinks!==!1&&At(),e.showPreferencePanel,Mt(e);let t=this.applyFixes(e);t.score=ot(t),e.showAuditBadge&&Ct(t),e.timeoutWarning&&it(e.timeoutWarning),e.autoFix&&this.startObserver(e),e.plainEnglish&&await Qe(!0),e.summarisePage&&await Ze(!0),e.translateLanguage&&e.translateLanguage!=="en"&&await et(e.translateLanguage),e.voiceControl&&await tt(!0),e.smartLabels&&await at(!0);let a=`${t.fixed} fixes applied. Score: ${t.score}/100.`;return m(a,t.score>=90?"success":"info",!1),`yuktai v4.0.0: ${a} Scanned ${t.scanned} elements in ${t.renderTime}ms.`},applyFixes(e){let t={fixed:0,scanned:0,renderTime:0,score:100,details:[]};if(typeof document>"u")return t;let a=performance.now(),i=document.querySelectorAll("*");t.scanned=i.length;let n=(l,o,d,g)=>{t.details.push({tag:l,fix:o,severity:d,element:g.outerHTML.slice(0,100)}),t.fixed++};return i.forEach(l=>{let o=l,d=o.tagName.toLowerCase();if(d==="html"&&!o.getAttribute("lang")&&(o.setAttribute("lang","en"),n(d,'lang="en" added',"critical",o)),d==="meta"){let u=o.getAttribute("name"),v=o.getAttribute("content")||"";u==="viewport"&&v.includes("user-scalable=no")&&(o.setAttribute("content",v.replace("user-scalable=no","user-scalable=yes")),n(d,"user-scalable=yes restored","serious",o)),u==="viewport"&&/maximum-scale=1(?:[^0-9]|$)/.test(v)&&(o.setAttribute("content",v.replace(/maximum-scale=1(?=[^0-9]|$)/,"maximum-scale=5")),n(d,"maximum-scale=5 restored","serious",o))}if(d==="main"&&!o.getAttribute("tabindex")&&(o.setAttribute("tabindex","-1"),o.getAttribute("id")||o.setAttribute("id","main-content")),d==="img"&&(o.hasAttribute("alt")||(o.setAttribute("alt",""),o.setAttribute("aria-hidden","true"),n(d,'alt="" aria-hidden="true"',"serious",o))),d==="svg"&&(!o.getAttribute("aria-hidden")&&!o.getAttribute("aria-label")&&!l.querySelector("title")&&(o.setAttribute("aria-hidden","true"),n(d,'aria-hidden="true" (decorative svg)',"minor",o)),o.getAttribute("focusable")||o.setAttribute("focusable","false")),d==="iframe"&&!o.getAttribute("title")&&!o.getAttribute("aria-label")&&(o.setAttribute("title","embedded content"),o.setAttribute("aria-label","embedded content"),n(d,"title + aria-label added","serious",o)),d==="button"){if(!o.innerText?.trim()&&!o.getAttribute("aria-label")){let u=o.getAttribute("title")||"button";o.setAttribute("aria-label",u),n(d,`aria-label="${u}" (empty button)`,"critical",o)}o.hasAttribute("disabled")&&!o.getAttribute("aria-disabled")&&(o.setAttribute("aria-disabled","true"),t.fixed++)}if(d==="a"){let u=o;!o.innerText?.trim()&&!o.getAttribute("aria-label")&&(o.setAttribute("aria-label",o.getAttribute("title")||"link"),n(d,"aria-label added (empty link)","critical",o)),u.target==="_blank"&&!u.rel?.includes("noopener")&&(u.rel="noopener noreferrer",t.fixed++)}if(Xe.has(d)){let u=o;if(!o.getAttribute("aria-label")&&!o.getAttribute("aria-labelledby")){let v=o.getAttribute("placeholder")||o.getAttribute("name")||d;o.setAttribute("aria-label",v),n(d,`aria-label="${v}"`,"serious",o)}if(o.hasAttribute("required")&&!o.getAttribute("aria-required")&&(o.setAttribute("aria-required","true"),t.fixed++),d==="input"&&!u.autocomplete){let v=u.name||"";u.type==="email"||v.includes("email")?u.autocomplete="email":u.type==="tel"||v.includes("tel")?u.autocomplete="tel":u.type==="password"&&(u.autocomplete="current-password"),t.fixed++}}d==="th"&&!o.getAttribute("scope")&&(o.setAttribute("scope",o.closest("thead")?"col":"row"),n(d,"scope added to <th>","moderate",o)),Ee[d]&&!o.getAttribute("role")&&(o.setAttribute("role",Ee[d]),n(d,`role="${Ee[d]}"`,"minor",o));let g=o.getAttribute("role")||"";g==="tab"&&!o.getAttribute("aria-selected")&&(o.setAttribute("aria-selected","false"),t.fixed++),["alert","status","log"].includes(g)&&!o.getAttribute("aria-live")&&(o.setAttribute("aria-live",g==="alert"?"assertive":"polite"),n(d,`aria-live added on role=${g}`,"moderate",o)),g==="combobox"&&!o.getAttribute("aria-expanded")&&(o.setAttribute("aria-expanded","false"),n(d,'aria-expanded="false" on combobox',"serious",o)),(g==="checkbox"||g==="radio")&&!o.getAttribute("aria-checked")&&(o.setAttribute("aria-checked","false"),n(d,`aria-checked="false" on role=${g}`,"serious",o))}),t.renderTime=parseFloat((performance.now()-a).toFixed(2)),t},scan(){let e={fixed:0,scanned:0,renderTime:0,score:100,details:[]};if(typeof document>"u")return e;let t=performance.now(),a=document.querySelectorAll("*");e.scanned=a.length;let i=(n,l,o,d)=>e.details.push({tag:n,fix:l,severity:o,element:d.outerHTML.slice(0,100)});return a.forEach(n=>{let l=n,o=l.tagName.toLowerCase();(o==="a"||o==="button")&&!l.innerText?.trim()&&!l.getAttribute("aria-label")&&i(o,"needs aria-label (empty)","critical",l),o==="img"&&!l.hasAttribute("alt")&&i(o,"needs alt text","serious",l),Xe.has(o)&&!l.getAttribute("aria-label")&&!l.getAttribute("aria-labelledby")&&i(o,"needs aria-label","serious",l),o==="iframe"&&!l.getAttribute("title")&&!l.getAttribute("aria-label")&&i(o,"iframe needs title","serious",l)}),e.fixed=e.details.length,e.score=ot(e),e.renderTime=parseFloat((performance.now()-t).toFixed(2)),e},startObserver(e){this.observer||typeof document>"u"||(this.observer=new MutationObserver(()=>this.applyFixes(e)),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!1}))},stopObserver(){this.observer?.disconnect(),this.observer=null},announce:m,speak:Ce,showVisualAlert:nt,trapFocus:ce,handlePlainEnglish:Qe,handleSummarisePage:Ze,handleTranslate:et,handleVoiceControl:tt,handleSmartLabels:at,SUPPORTED_LANGUAGES:ie};import Bt,{useEffect as q,useState as L,useCallback as Q}from"react";import{forwardRef as zt,useEffect as ue,useState as H}from"react";import{jsx as r,jsxs as p}from"react/jsx-runtime";var Le={highContrast:!1,reduceMotion:!1,autoFix:!0,dyslexiaFont:!1,fontScale:100,localFont:"",darkMode:!1,largeTargets:!1,speechEnabled:!1,colorBlindMode:"none",showAuditBadge:!1,timeoutWarning:void 0,plainEnglish:!1,summarisePage:!1,translateLanguage:"en",voiceControl:!1,smartLabels:!1},G=[80,90,100,110,120,130],Ht=[{value:"none",label:"None"},{value:"deuteranopia",label:"Deuteranopia"},{value:"protanopia",label:"Protanopia"},{value:"tritanopia",label:"Tritanopia"},{value:"achromatopsia",label:"Greyscale"}],Wt=["Prompt API for Gemini Nano","Summarization API for Gemini Nano","Writer API for Gemini Nano","Rewriter API for Gemini Nano","Translation API"];function $t(){let[e,t]=H(typeof window<"u"?window.innerWidth:1024);return ue(()=>{let a=()=>t(window.innerWidth);return window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]),{isMobile:e<=480,isTablet:e>480&&e<=768}}function Ft({checked:e,onChange:t,label:a,disabled:i=!1}){return p("label",{"aria-label":a,style:{position:"relative",display:"inline-flex",width:"40px",height:"24px",cursor:i?"not-allowed":"pointer",flexShrink:0,opacity:i?.4:1},children:[r("input",{type:"checkbox",checked:e,disabled:i,onChange:n=>t(n.target.checked),style:{opacity:0,width:0,height:0,position:"absolute"}}),r("span",{style:{position:"absolute",inset:0,borderRadius:"99px",background:e?"#0d9488":"#cbd5e1",transition:"background 0.2s"}}),r("span",{style:{position:"absolute",top:"3px",left:e?"19px":"3px",width:"18px",height:"18px",background:"#fff",borderRadius:"50%",transition:"left 0.2s",boxShadow:"0 1px 3px rgba(0,0,0,0.2)",pointerEvents:"none"}})]})}function _({label:e,color:t="#64748b",badge:a,concept:i}){return p("div",{style:{margin:"10px 18px 4px"},children:[p("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r("p",{style:{margin:0,fontSize:"10px",fontWeight:600,color:t,letterSpacing:"0.06em",textTransform:"uppercase"},children:e}),a&&r("span",{style:{fontSize:"9px",fontWeight:500,padding:"1px 7px",borderRadius:"99px",background:"#f5f3ff",color:"#7c3aed",border:"0.5px solid #c4b5fd",whiteSpace:"nowrap"},children:a})]}),i&&r("p",{style:{margin:"2px 0 0",fontSize:"9px",color:"#94a3b8",fontStyle:"italic"},children:i})]})}function M({icon:e,label:t,desc:a,checked:i,onChange:n,disabled:l=!1,disabledReason:o,tip:d}){return p("div",{title:l?o:d,style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 18px",gap:"12px"},children:[p("div",{style:{display:"flex",alignItems:"center",gap:"10px",flex:1,minWidth:0},children:[r("span",{"aria-hidden":"true",style:{width:"32px",height:"32px",borderRadius:"8px",background:l?"#f1f5f9":"#f0fdfa",color:l?"#94a3b8":"#0d9488",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"15px",flexShrink:0,fontWeight:700},children:e}),p("div",{style:{minWidth:0},children:[r("p",{style:{margin:0,fontSize:"13px",fontWeight:500,color:l?"#94a3b8":"#0f172a",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t}),r("p",{style:{margin:0,fontSize:"10px",color:"#94a3b8"},children:l?o:a})]})]}),r(Ft,{checked:i,onChange:n,label:`Toggle ${t}`,disabled:l})]})}function k(){return r("div",{style:{height:"1px",background:"#f1f5f9"}})}function X({steps:e}){return p("div",{style:{margin:"0 18px 8px",padding:"8px 10px",background:"#f8fafc",borderRadius:"8px",border:"0.5px solid #e2e8f0"},children:[r("p",{style:{margin:"0 0 4px",fontSize:"9px",fontWeight:600,color:"#64748b",textTransform:"uppercase",letterSpacing:"0.05em"},children:"How to use"}),e.map((t,a)=>p("p",{style:{margin:"0 0 2px",fontSize:"10px",color:"#475569"},children:[a+1,". ",t]},a))]})}var Me=zt(({position:e,settings:t,report:a,isActive:i,aiSupported:n,voiceSupported:l,set:o,onApply:d,onReset:g,onClose:u},v)=>{let{isMobile:x,isTablet:j}=$t(),[Z,me]=H([]),[R,$]=H(""),[I,P]=H(""),[h,K]=H(!1),[f,z]=H(null),[S,F]=H("idle");ue(()=>{let s=window;!!(s.LanguageModel||s.ai?.languageModel)&&n?z("gemini"):te()&&z("transformers")},[n]),ue(()=>{if(f!=="transformers")return;let s=setInterval(()=>{F(ae())},500);return()=>clearInterval(s)},[f]);let b=async()=>{if(!(!R.trim()||h)){if(!f){P("\u26A0\uFE0F No AI engine available on this device.");return}K(!0),P("");try{let s;f==="gemini"?s=await ze(R):(F("loading"),s=await He(R),F("ready")),P(s.success&&s.answer?s.answer.replace(/\*\*(.*?)\*\*/g,"$1").replace(/\*(.*?)\*/g,"$1").replace(/#+\s/g,"").trim():"\u26A0\uFE0F "+(s.error||"No answer found on this page"))}catch{P("\u26A0\uFE0F Failed to get answer. Please try again.")}K(!1)}};ue(()=>{(async()=>{try{let B=window;if(!B.queryLocalFonts)return;let ge=await B.queryLocalFonts(),be=[...new Set(ge.map(ye=>ye.family))].sort();me(be.slice(0,50))}catch{}})()},[]);let ee=f==="gemini"?"Gemini Nano":f==="transformers"?"Transformers.js \xB7 All devices":"Detecting...",Y=f==="transformers"&&S==="loading"?"Loading AI model... (first time only)":"...",U=x?{position:"fixed",bottom:0,left:0,right:0,zIndex:9999,background:"#fff",border:"1px solid #e2e8f0",borderRadius:"16px 16px 0 0",boxShadow:"0 -8px 32px rgba(0,0,0,0.12)",maxHeight:"90vh",overflowY:"auto",fontFamily:"system-ui,-apple-system,sans-serif",width:"100%"}:{position:"fixed",bottom:"84px",[e]:"24px",zIndex:9999,width:j?"300px":"320px",maxWidth:"calc(100vw - 48px)",background:"#fff",border:"1px solid #e2e8f0",borderRadius:"16px",boxShadow:"0 8px 32px rgba(0,0,0,0.12)",maxHeight:"80vh",overflowY:"auto",fontFamily:"system-ui,-apple-system,sans-serif"};return p("div",{ref:v,role:"dialog","aria-modal":"true","aria-label":"yuktai accessibility preferences","data-yuktai-panel":"true",style:U,children:[p("div",{style:{padding:"14px 18px 12px",borderBottom:"1px solid #f1f5f9",display:"flex",alignItems:"flex-start",justifyContent:"space-between",position:"sticky",top:0,background:"#fff",zIndex:1},children:[p("div",{children:[p("div",{style:{display:"flex",alignItems:"center",gap:"7px",marginBottom:"4px",flexWrap:"wrap"},children:[r("span",{style:{fontSize:"10px",fontWeight:700,padding:"2px 7px",borderRadius:"99px",background:"#f0fdfa",color:"#0d9488",letterSpacing:"0.05em",fontFamily:"monospace"},children:"@yuktishaalaa/yuktai v2.1.0"}),i&&r("span",{style:{fontSize:"10px",fontWeight:700,padding:"2px 7px",borderRadius:"99px",background:"#f0fdfa",color:"#0f766e",border:"1px solid #99f6e4"},children:"\u25CF ACTIVE"})]}),r("p",{style:{margin:"0 0 1px",fontSize:"15px",fontWeight:600,color:"#0f172a"},children:"Accessibility"}),r("p",{style:{margin:0,fontSize:"11px",color:"#64748b"},children:"WCAG 2.2 \xB7 Open source \xB7 Zero cost \xB7 All devices"})]}),r("button",{onClick:u,"aria-label":"Close accessibility panel",style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"#94a3b8",fontSize:"20px",lineHeight:1,borderRadius:"6px",flexShrink:0,minWidth:x?"44px":"auto",minHeight:x?"44px":"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:"\xD7"})]}),r(_,{label:"\u267F Core Accessibility",concept:"Rule-based engine \u2014 works on all browsers and devices"}),r(X,{steps:["Toggle any feature on","Click Apply settings","Preferences saved automatically"]}),r(M,{icon:"\u{1F527}",label:"Auto-fix ARIA",desc:"Injects missing labels and roles automatically",checked:t.autoFix,onChange:s=>o("autoFix",s),tip:"Fixes aria-label, alt text, roles on every element"}),r(k,{}),r(M,{icon:"\u{1F50A}",label:"Speak on focus",desc:"Browser reads elements aloud as you tab",checked:t.speechEnabled,onChange:s=>o("speechEnabled",s),tip:"Uses browser SpeechSynthesis \u2014 no install needed"}),r(k,{}),r(M,{icon:"\u{1F399}\uFE0F",label:"Voice control",desc:"Say commands to navigate the page",checked:t.voiceControl,onChange:s=>o("voiceControl",s),disabled:!l,disabledReason:"Not supported in this browser",tip:'Say "scroll down", "go to main", "click"'}),r(k,{}),r(_,{label:"\u{1F916} AI Features",color:"#7c3aed",badge:"Gemini Nano",concept:"Large Language Model running privately on your device \u2014 Chrome 127+ only"}),r("div",{style:{margin:"4px 18px 6px",padding:"8px 10px",background:n?"#f0fdfa":"#f5f3ff",borderRadius:"8px",border:`0.5px solid ${n?"#99f6e4":"#c4b5fd"}`,fontSize:"10px",color:n?"#0f766e":"#7c3aed",lineHeight:1.5},children:n?"\u2705 Gemini Nano detected \u2014 AI features ready. Runs privately on your device.":"\u2699\uFE0F AI features need one-time setup \u2014 see guide below."}),!n&&p("div",{style:{margin:"0 18px 8px",padding:"10px 12px",background:"#fafafa",borderRadius:"8px",border:"0.5px solid #e2e8f0",fontSize:"11px",color:"#475569",lineHeight:1.7},children:[r("p",{style:{margin:"0 0 6px",fontWeight:600,color:"#0f172a",fontSize:"11px"},children:"\u{1F6E0} One-time setup \u2014 5 steps:"}),p("p",{style:{margin:"0 0 3px"},children:["1. Open Chrome \u2192 ",r("code",{style:{background:"#f1f5f9",padding:"1px 5px",borderRadius:"4px",fontSize:"10px",color:"#0d9488",fontFamily:"monospace"},children:"chrome://flags"})]}),r("p",{style:{margin:"0 0 3px"},children:"2. Enable each flag:"}),r("div",{style:{display:"flex",flexDirection:"column",gap:"2px",margin:"4px 0 6px 10px"},children:Wt.map(s=>p("span",{style:{fontSize:"10px",color:"#7c3aed",fontFamily:"monospace"},children:["\u2192 ",s]},s))}),p("p",{style:{margin:"0 0 3px"},children:["3. Click ",r("strong",{style:{color:"#0f172a"},children:"Relaunch"})]}),p("p",{style:{margin:"0 0 3px"},children:["4. ",r("code",{style:{background:"#f1f5f9",padding:"1px 5px",borderRadius:"4px",fontSize:"10px",color:"#0d9488",fontFamily:"monospace"},children:"chrome://components"})," \u2192 Optimization Guide On Device Model \u2192 Check for update"]}),r("p",{style:{margin:"0"},children:"5. Refresh \u2014 AI features unlock automatically \u2705"})]}),r(M,{icon:"\u{1F4DD}",label:"Plain English mode",desc:"Rewrites complex text in simple language",checked:t.plainEnglish,onChange:s=>o("plainEnglish",s),disabled:!n,disabledReason:"Enable Gemini Nano \u2014 see setup above",tip:"AI concept: LLM text rewriting"}),r(k,{}),r(M,{icon:"\u{1F4CB}",label:"Summarise page",desc:"3-sentence summary appears at top",checked:t.summarisePage,onChange:s=>o("summarisePage",s),disabled:!n,disabledReason:"Enable Gemini Nano \u2014 see setup above",tip:"AI concept: Abstractive summarisation"}),r(k,{}),r(M,{icon:"\u{1F3F7}\uFE0F",label:"Smart aria-labels",desc:"AI generates meaningful labels for elements",checked:t.smartLabels,onChange:s=>o("smartLabels",s),disabled:!n,disabledReason:"Enable Gemini Nano \u2014 see setup above",tip:"AI concept: Context-aware label generation"}),r(k,{}),r(_,{label:"\u{1F441}\uFE0F Visual",concept:"CSS filter-based \u2014 works on all browsers and devices"}),r(X,{steps:["Toggle any visual mode","Changes apply instantly","Works on mobile and desktop"]}),r(M,{icon:"\u25D1",label:"High contrast",desc:"Boosts contrast for low vision users",checked:t.highContrast,onChange:s=>o("highContrast",s),tip:"CSS filter: contrast()"}),r(k,{}),r(M,{icon:"\u{1F319}",label:"Dark mode",desc:"Inverts colours \u2014 easy on eyes at night",checked:t.darkMode,onChange:s=>o("darkMode",s),tip:"CSS filter: invert + hue-rotate"}),r(k,{}),r(M,{icon:"\u23F8\uFE0F",label:"Reduce motion",desc:"Disables all animations",checked:t.reduceMotion,onChange:s=>o("reduceMotion",s),tip:"WCAG 2.3.3 \u2014 vestibular disorders"}),r(k,{}),r(M,{icon:"\u{1F446}",label:"Large targets",desc:"44\xD744px minimum touch targets",checked:t.largeTargets,onChange:s=>o("largeTargets",s),tip:"WCAG 2.5.8 \u2014 motor impaired users"}),r(k,{}),p("div",{style:{padding:"10px 18px"},children:[r("p",{style:{margin:"0 0 2px",fontSize:"12px",fontWeight:500,color:"#0f172a"},children:"\u{1F3A8} Colour blindness"}),r("p",{style:{margin:"0 0 8px",fontSize:"10px",color:"#94a3b8"},children:"SVG colour matrix filters \u2014 all devices"}),r("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:Ht.map(s=>r("button",{onClick:()=>o("colorBlindMode",s.value),"aria-pressed":t.colorBlindMode===s.value,style:{padding:"4px 10px",borderRadius:"20px",fontSize:"11px",fontWeight:500,border:`1px solid ${t.colorBlindMode===s.value?"#0d9488":"#e2e8f0"}`,background:t.colorBlindMode===s.value?"#f0fdfa":"#fff",color:t.colorBlindMode===s.value?"#0d9488":"#64748b",cursor:"pointer",minHeight:x?"36px":"auto"},children:s.label},s.value))})]}),r(k,{}),r(_,{label:"\u{1F524} Font",concept:"Browser Font API + CSS \u2014 Chrome 103+"}),r(X,{steps:["Toggle dyslexia font or pick from device","Adjust size with + / \u2212","Saved across visits"]}),r(M,{icon:"Aa",label:"Dyslexia-friendly font",desc:"Atkinson Hyperlegible \u2014 research-backed",checked:t.dyslexiaFont,onChange:s=>o("dyslexiaFont",s),tip:"By Braille Institute \u2014 free and open source"}),r(k,{}),p("div",{style:{padding:"10px 18px"},children:[r("p",{style:{margin:"0 0 2px",fontSize:"12px",fontWeight:500,color:"#0f172a"},children:"\u{1F5A5}\uFE0F Local font"}),r("p",{style:{margin:"0 0 8px",fontSize:"10px",color:"#94a3b8"},children:"window.queryLocalFonts() \u2014 Chrome 103+"}),Z.length>0?p("select",{value:t.localFont,onChange:s=>o("localFont",s.target.value),"aria-label":"Choose a font from your device",style:{width:"100%",padding:"8px 10px",borderRadius:"8px",border:"1px solid #e2e8f0",fontSize:"13px",color:"#0f172a",background:"#fff",cursor:"pointer",height:x?"44px":"36px"},children:[r("option",{value:"",children:"System default"}),Z.map(s=>r("option",{value:s,style:{fontFamily:s},children:s},s))]}):r("p",{style:{margin:0,fontSize:"11px",color:"#94a3b8"},children:"Allow font access when Chrome prompts you."})]}),r(k,{}),p("div",{style:{padding:"10px 18px 14px"},children:[p("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"10px"},children:[p("div",{children:[r("p",{style:{margin:0,fontSize:"12px",fontWeight:500,color:"#0f172a"},children:"\u{1F4CF} Text size"}),r("p",{style:{margin:0,fontSize:"10px",color:"#94a3b8"},children:"Scales all text on the page"})]}),p("span",{style:{fontSize:"12px",fontWeight:600,color:"#0d9488",background:"#f0fdfa",padding:"2px 8px",borderRadius:"99px"},children:[t.fontScale,"%"]})]}),p("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r("button",{onClick:()=>{let s=G.indexOf(t.fontScale);s>0&&o("fontScale",G[s-1])},disabled:t.fontScale<=80,"aria-label":"Decrease text size",style:{width:x?"44px":"30px",height:x?"44px":"30px",borderRadius:"8px",border:"1px solid #e2e8f0",background:"#fff",cursor:t.fontScale<=80?"not-allowed":"pointer",fontSize:"16px",color:t.fontScale<=80?"#cbd5e1":"#0f172a",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:"\u2212"}),r("div",{style:{flex:1,display:"flex",gap:"3px"},children:G.map(s=>r("button",{onClick:()=>o("fontScale",s),"aria-label":`Set text size to ${s}%`,style:{flex:1,height:"6px",borderRadius:"99px",border:"none",cursor:"pointer",padding:0,background:s<=t.fontScale?"#0d9488":"#e2e8f0",transition:"background 0.15s"}},s))}),r("button",{onClick:()=>{let s=G.indexOf(t.fontScale);s<G.length-1&&o("fontScale",G[s+1])},disabled:t.fontScale>=130,"aria-label":"Increase text size",style:{width:x?"44px":"30px",height:x?"44px":"30px",borderRadius:"8px",border:"1px solid #e2e8f0",background:"#fff",cursor:t.fontScale>=130?"not-allowed":"pointer",fontSize:"16px",color:t.fontScale>=130?"#cbd5e1":"#0f172a",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:"+"})]})]}),r(k,{}),r(_,{label:"\u{1F310} Translate",color:"#7c3aed",badge:"Gemini Nano",concept:"Chrome Translation API \u2014 on device, no internet after setup"}),r(X,{steps:["Enable Gemini Nano first","Pick your language","Full page translates instantly"]}),p("div",{style:{padding:"6px 18px 12px"},children:[r("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:ie.slice(0,x?8:18).map(s=>r("button",{onClick:()=>o("translateLanguage",s.code),"aria-pressed":t.translateLanguage===s.code,disabled:!n,style:{padding:"4px 10px",borderRadius:"20px",fontSize:"11px",fontWeight:500,border:`1px solid ${t.translateLanguage===s.code?"#7c3aed":"#e2e8f0"}`,background:t.translateLanguage===s.code?"#f5f3ff":"#fff",color:t.translateLanguage===s.code?"#7c3aed":"#64748b",cursor:n?"pointer":"not-allowed",opacity:n?1:.5,minHeight:x?"36px":"auto"},children:s.label},s.code))}),!n&&r("p",{style:{margin:"6px 0 0",fontSize:"10px",color:"#94a3b8"},children:"Enable Gemini Nano using the setup guide above."})]}),r(k,{}),r(_,{label:"\u{1F4AC} Ask This Page",color:"#0d9488",badge:ee,concept:"RAG \u2014 Retrieval Augmented Generation. Works on all devices including mobile."}),r(X,{steps:["Type any question about this page","Press Ask or hit Enter",f==="transformers"?"Transformers.js answers \u2014 works on mobile, offline":"Gemini Nano reads page and answers privately","Zero cost. No data leaves your device."]}),p("div",{style:{margin:"0 18px 8px",padding:"6px 10px",background:f==="gemini"?"#f0fdfa":f==="transformers"?"#f5f3ff":"#f8fafc",borderRadius:"8px",border:`0.5px solid ${f==="gemini"?"#99f6e4":f==="transformers"?"#c4b5fd":"#e2e8f0"}`,fontSize:"10px",color:f==="gemini"?"#0f766e":f==="transformers"?"#7c3aed":"#94a3b8"},children:[f==="gemini"&&"\u2705 Using Gemini Nano \u2014 on device, private, instant",f==="transformers"&&"\u2705 Using Transformers.js \u2014 works on mobile and all browsers",!f&&"\u23F3 Detecting AI engine...",f==="transformers"&&S==="loading"&&" \xB7 Loading model...",f==="transformers"&&S==="ready"&&" \xB7 Model ready \u2705"]}),p("div",{style:{padding:"0 18px 14px"},children:[p("div",{style:{display:"flex",gap:"6px",marginBottom:"8px"},children:[r("input",{type:"text",value:R,onChange:s=>$(s.target.value),onKeyDown:s=>{s.key==="Enter"&&b()},placeholder:"e.g. What does this page do?",disabled:h||!f,"aria-label":"Ask a question about this page",style:{flex:1,padding:"8px 10px",borderRadius:"8px",border:"1px solid #e2e8f0",fontSize:"12px",color:"#0f172a",background:f?"#fff":"#f8fafc",outline:"none",height:x?"44px":"36px"}}),r("button",{onClick:b,disabled:h||!R.trim()||!f,"aria-label":"Ask question",style:{padding:"8px 14px",borderRadius:"8px",border:"none",background:f&&R.trim()&&!h?"#0d9488":"#e2e8f0",color:f&&R.trim()&&!h?"#fff":"#94a3b8",fontSize:"12px",fontWeight:600,cursor:f&&R.trim()&&!h?"pointer":"not-allowed",flexShrink:0,height:x?"44px":"36px",minWidth:"52px",transition:"background 0.2s"},children:h?Y:"Ask"})]}),I&&p("div",{role:"status","aria-live":"polite",style:{padding:"10px 12px",background:"#f0fdfa",border:"1px solid #99f6e4",borderRadius:"8px",fontSize:"12px",color:"#0f766e",lineHeight:1.6,maxHeight:"180px",overflowY:"auto"},children:[r("strong",{style:{display:"block",marginBottom:"4px",fontSize:"11px",color:"#0d9488"},children:"\u{1F4AC} Answer"}),I,r("button",{onClick:()=>{P(""),$("")},style:{display:"block",marginTop:"6px",background:"none",border:"none",color:"#94a3b8",fontSize:"10px",cursor:"pointer",padding:0},children:"Clear"})]})]}),a&&r("div",{role:"status",style:{margin:"0 14px 10px",padding:"8px 12px",background:"#f0fdfa",border:"1px solid #99f6e4",borderRadius:"8px",fontSize:"12px",color:"#0f766e",fontWeight:500,fontFamily:"monospace"},children:a.fixed>0?`\u2713 ${a.fixed} fixes \xB7 ${a.scanned} nodes \xB7 ${a.renderTime}ms \xB7 Score: ${a.score}/100`:`\u2713 0 auto-fixes needed \xB7 ${a.scanned} nodes \xB7 ${a.renderTime}ms`}),p("div",{style:{display:"flex",gap:"8px",padding:"12px 14px 14px",position:x?"sticky":"relative",bottom:x?0:"auto",background:"#fff",borderTop:"1px solid #f1f5f9"},children:[r("button",{onClick:g,style:{flex:1,padding:x?"12px 0":"8px 0",fontSize:"13px",fontWeight:500,borderRadius:"9px",border:"1px solid #e2e8f0",background:"#fff",color:"#64748b",cursor:"pointer"},children:"Reset"}),r("button",{onClick:d,style:{flex:2,padding:x?"12px 0":"8px 0",fontSize:"13px",fontWeight:600,borderRadius:"9px",border:"none",background:"#0d9488",color:"#fff",cursor:"pointer"},children:"Apply settings"})]})]})});Me.displayName="WidgetPanel";import{Fragment as Ot,jsx as A,jsxs as V}from"react/jsx-runtime";async function Nt(){try{if(typeof window>"u")return!1;let e=window;if(e.LanguageModel)try{if(typeof e.LanguageModel.availability=="function"){let a=await e.LanguageModel.availability();if(a==="readily"||a==="available"||a==="downloadable")return!0}else return!0}catch{}if(e.Summarizer)try{let a=await e.Summarizer.availability?.();if(!a||a==="readily"||a==="available")return!0}catch{}if(e.Rewriter)try{let a=await e.Rewriter.availability?.();if(!a||a==="readily"||a==="available")return!0}catch{}if(e.Writer)try{let a=await e.Writer.availability?.();if(!a||a==="readily"||a==="available")return!0}catch{}let t=e.ai||globalThis.ai;if(t){if(t.languageModel?.availability)try{let a=await t.languageModel.availability();if(a==="readily"||a==="available")return!0}catch{}if(t.languageModel&&typeof t.languageModel.create=="function"||t.summarizer||t.rewriter||t.writer||t.languageModel)return!0}return!!(e.Translator||e.translation?.canTranslate)}catch{return!1}}function Re({position:e="left",children:t,config:a={},showRag:i=!1}){let[n,l]=L(!1),[o,d]=L(Le),[g,u]=L(null),[v,x]=L(!1),[j,Z]=L(!1),[me,R]=L(!1),$=Bt.useRef(null),[I,P]=L(!1),[h,K]=L(""),[f,z]=L(""),[S,F]=L(!1),[b,ee]=L(null),[Y,U]=L("idle");q(()=>{if(typeof window>"u")return;let c=window;!!(c.LanguageModel||c.ai?.languageModel)&&j?ee("gemini"):te()&&ee("transformers")},[j]),q(()=>{if(b!=="transformers")return;let c=setInterval(()=>U(ae()),500);return()=>clearInterval(c)},[b]);let s=Q(async()=>{if(!(!h.trim()||S)){if(!b){z("\u26A0\uFE0F No AI engine available on this device.");return}F(!0),z("");try{let c;if(b==="gemini"){let{askPage:w}=await import("./rag-MKBAGH6J.mjs");c=await w(h)}else{U("loading");let{askPageWithTransformers:w}=await import("./transformers-rag-UDP6IYPT.mjs");c=await w(h),U("ready")}z(c.success&&c.answer?c.answer.replace(/\*\*(.*?)\*\*/g,"$1").replace(/\*(.*?)\*/g,"$1").replace(/#+\s/g,"").trim():"\u26A0\uFE0F "+(c.error||"No answer found."))}catch{z("\u26A0\uFE0F Something went wrong. Please try again.")}F(!1)}},[h,S,b]);q(()=>{if(typeof window>"u")return;let w=setTimeout(async()=>{let J=window;console.log("yuktai: Checking AI APIs..."),console.log("yuktai: window.LanguageModel =",J.LanguageModel);let Ie=await Nt();Z(Ie),console.log(Ie?"yuktai: Chrome Built-in AI detected \u2705":"yuktai: Chrome Built-in AI not detected \u2014 Transformers.js will handle RAG on mobile"),R(!!(J.SpeechRecognition||J.webkitSpeechRecognition))},800);return()=>clearTimeout(w)},[]),q(()=>{if(!(typeof window>"u"))try{let c=localStorage.getItem("yuktai-a11y-prefs");c&&d(w=>({...w,...JSON.parse(c)}))}catch{}},[]);let B=Q(async c=>{let w={enabled:!0,highContrast:c.highContrast,darkMode:c.darkMode,reduceMotion:c.reduceMotion,largeTargets:c.largeTargets,speechEnabled:c.speechEnabled,autoFix:c.autoFix,dyslexiaFont:c.dyslexiaFont,localFont:c.localFont,fontSizeMultiplier:c.fontScale/100,colorBlindMode:c.colorBlindMode,showAuditBadge:c.showAuditBadge,showSkipLinks:!0,showPreferencePanel:!1,plainEnglish:c.plainEnglish,summarisePage:c.summarisePage,translateLanguage:c.translateLanguage,voiceControl:c.voiceControl,smartLabels:c.smartLabels,...a};await C.execute(w),u(C.applyFixes(w)),x(!0)},[a]),ge=Q(async()=>{try{localStorage.setItem("yuktai-a11y-prefs",JSON.stringify(o))}catch{}await B(o),l(!1)},[o,B]),be=Q(()=>{d(Le);try{localStorage.removeItem("yuktai-a11y-prefs")}catch{}let c=document.documentElement;["data-yuktai-high-contrast","data-yuktai-dark","data-yuktai-reduce-motion","data-yuktai-large-targets","data-yuktai-keyboard","data-yuktai-dyslexia"].forEach(w=>c.removeAttribute(w)),document.body.style.filter="",document.body.style.fontFamily="",document.documentElement.style.fontSize="",u(null),x(!1)},[]),ye=Q((c,w)=>{d(J=>({...J,[c]:w}))},[]);q(()=>{let c=w=>{w.key==="Escape"&&(n&&l(!1),I&&P(!1))};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[n,I]),q(()=>{n&&$.current&&C.trapFocus($.current)},[n]);let st=b==="transformers"&&Y==="loading"?"Loading AI... (first time only)":"...",Pe=b==="gemini"?"Gemini Nano \xB7 On device \xB7 Instant":b==="transformers"?"Transformers.js \xB7 All devices \xB7 Offline":"Detecting engine...",lt={position:"fixed",bottom:"24px",[e]:"24px",zIndex:9998,width:"52px",height:"52px",borderRadius:"50%",background:v?"#0d9488":"#1a73e8",color:"#fff",border:"none",cursor:"pointer",fontSize:"22px",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 16px rgba(0,0,0,0.25)",transition:"transform 0.15s, background 0.2s"},dt={position:"fixed",bottom:"84px",[e]:"24px",zIndex:9998,width:"52px",height:"52px",borderRadius:"50%",background:I?"#7c3aed":"#6d28d9",color:"#fff",border:"none",cursor:"pointer",fontSize:"22px",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 16px rgba(0,0,0,0.25)",transition:"transform 0.15s, background 0.2s"};return V(Ot,{children:[t,i&&A("button",{style:dt,"aria-label":"Ask a question about this page","aria-haspopup":"dialog","aria-expanded":I,title:`Ask this page \xB7 ${Pe}`,onClick:()=>{P(c=>!c),l(!1)},onMouseEnter:c=>{c.currentTarget.style.transform="scale(1.08)"},onMouseLeave:c=>{c.currentTarget.style.transform="scale(1)"},children:"\u{1F4AC}"}),i&&I&&V("div",{role:"dialog","aria-modal":"true","aria-label":"Ask this page","data-yuktai-panel":"true",style:{position:"fixed",bottom:"148px",[e]:"24px",zIndex:9999,width:"300px",maxWidth:"calc(100vw - 48px)",background:"#fff",border:"1px solid #e2e8f0",borderRadius:"16px",boxShadow:"0 8px 32px rgba(0,0,0,0.12)",fontFamily:"system-ui,-apple-system,sans-serif",padding:"14px"},children:[V("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:"10px"},children:[V("div",{children:[A("p",{style:{margin:"0 0 2px",fontSize:"13px",fontWeight:600,color:"#0f172a"},children:"\u{1F4AC} Ask this page"}),A("p",{style:{margin:0,fontSize:"10px",color:b==="gemini"?"#0d9488":"#7c3aed"},children:Pe}),b==="transformers"&&Y==="loading"&&A("p",{style:{margin:"2px 0 0",fontSize:"9px",color:"#94a3b8"},children:"Downloading AI model \u2014 first time only (~90MB)"}),b==="transformers"&&Y==="ready"&&A("p",{style:{margin:"2px 0 0",fontSize:"9px",color:"#0d9488"},children:"Model ready \u2705 \u2014 works offline now"})]}),A("button",{onClick:()=>P(!1),"aria-label":"Close ask panel",style:{background:"none",border:"none",cursor:"pointer",color:"#94a3b8",fontSize:"18px",lineHeight:1,padding:"2px",borderRadius:"4px"},children:"\xD7"})]}),V("div",{style:{display:"flex",gap:"6px",marginBottom:"8px"},children:[A("input",{type:"text",value:h,onChange:c=>K(c.target.value),onKeyDown:c=>{c.key==="Enter"&&s()},placeholder:"e.g. What does this page do?",disabled:S||!b,"aria-label":"Ask a question about this page",style:{flex:1,padding:"8px 10px",borderRadius:"8px",border:"1px solid #e2e8f0",fontSize:"12px",color:"#0f172a",background:b?"#fff":"#f8fafc",outline:"none",height:"36px"}}),A("button",{onClick:s,disabled:S||!h.trim()||!b,"aria-label":"Submit question",style:{padding:"8px 12px",borderRadius:"8px",border:"none",background:b&&h.trim()&&!S?"#7c3aed":"#e2e8f0",color:b&&h.trim()&&!S?"#fff":"#94a3b8",fontSize:"12px",fontWeight:600,cursor:b&&h.trim()&&!S?"pointer":"not-allowed",height:"36px",minWidth:"48px",transition:"background 0.2s"},children:S?st:"Ask"})]}),f&&V("div",{style:{padding:"10px",background:"#f5f3ff",borderRadius:"8px",fontSize:"12px",color:"#4c1d95",lineHeight:1.6,maxHeight:"180px",overflowY:"auto"},children:[A("strong",{style:{display:"block",marginBottom:"4px",fontSize:"11px",color:"#7c3aed"},children:"\u{1F4AC} Answer"}),f,A("button",{onClick:()=>{z(""),K("")},style:{display:"block",marginTop:"6px",background:"none",border:"none",color:"#94a3b8",fontSize:"10px",cursor:"pointer",padding:0},children:"Clear"})]}),!b&&A("p",{style:{margin:"4px 0 0",fontSize:"10px",color:"#94a3b8"},children:"Detecting AI engine..."})]}),A("button",{style:lt,"aria-label":"Open accessibility preferences","aria-haspopup":"dialog","aria-expanded":n,"data-yuktai-pref-toggle":"true",onClick:()=>{l(c=>!c),P(!1)},onMouseEnter:c=>{c.currentTarget.style.transform="scale(1.08)"},onMouseLeave:c=>{c.currentTarget.style.transform="scale(1)"},children:"\u267F"}),n&&A(Me,{ref:$,position:e,settings:o,report:g,isActive:v,aiSupported:j,voiceSupported:me,set:ye,onApply:ge,onReset:be,onClose:()=>l(!1)})]})}var pe={name:"ai.text",async execute(e){return`\u{1F916} YuktAI says: ${e}`}};var fe={name:"voice.text",async execute(e){return!e||e.trim()===""?"\u{1F3A4} No speech detected":`\u{1F3A4} You said: ${e}`}};var W=class{plugins=new Map;register(t,a){if(!a||typeof a.execute!="function")throw new Error(`Invalid plugin: ${t}`);this.plugins.set(t,a)}use(t){return this.plugins.get(t)}async run(t,a){try{let i=this.use(t);if(!i)throw new Error(`Plugin not found: ${t}`);return await i.execute(a)}catch(i){throw console.error(`[YuktAI Runtime Error in ${t}]:`,i),i}}getPlugins(){return Array.from(this.plugins.keys())}};function Dt(){if(typeof globalThis>"u")return new W;if(!globalThis.__yuktai_runtime__){let e=new W;e.register(C.name,C),e.register(pe.name,pe),e.register(fe.name,fe),globalThis.__yuktai_runtime__=e}return globalThis.__yuktai_runtime__}var rt=typeof window<"u"?Dt():new W,za={wcagPlugin:C,list(){return rt.getPlugins()},use(e){return rt.use(e)},fix(e){return C.applyFixes({enabled:!0,autoFix:!0,...e})},scan(){return C.scan()}};export{W as Runtime,za as YuktAI,Re as YuktAIWrapper,pe as aiPlugin,Re as default,fe as voicePlugin,C as wcag,C as wcagPlugin};
|
|
385
|
+
`,document.body.appendChild(e),Ue=e}function ot(e){let t={critical:20,serious:10,moderate:5,minor:2},a=e.details.reduce((i,n)=>i+(t[n.severity]||0),0);return Math.max(0,Math.min(100,100-a))}var C={name:"yuktai-a11y",version:"4.0.0",observer:null,async execute(e){if(!e.enabled)return this.stopObserver(),"yuktai: disabled.";D=e,Rt(e),Pt(),It(),St(),Tt(),e.showSkipLinks!==!1&&At(),e.showPreferencePanel,Mt(e);let t=this.applyFixes(e);t.score=ot(t),e.showAuditBadge&&Ct(t),e.timeoutWarning&&it(e.timeoutWarning),e.autoFix&&this.startObserver(e),e.plainEnglish&&await Qe(!0),e.summarisePage&&await Ze(!0),e.translateLanguage&&e.translateLanguage!=="en"&&await et(e.translateLanguage),e.voiceControl&&await tt(!0),e.smartLabels&&await at(!0);let a=`${t.fixed} fixes applied. Score: ${t.score}/100.`;return m(a,t.score>=90?"success":"info",!1),`yuktai v4.0.0: ${a} Scanned ${t.scanned} elements in ${t.renderTime}ms.`},applyFixes(e){let t={fixed:0,scanned:0,renderTime:0,score:100,details:[]};if(typeof document>"u")return t;let a=performance.now(),i=document.querySelectorAll("*");t.scanned=i.length;let n=(l,o,d,g)=>{t.details.push({tag:l,fix:o,severity:d,element:g.outerHTML.slice(0,100)}),t.fixed++};return i.forEach(l=>{let o=l,d=o.tagName.toLowerCase();if(d==="html"&&!o.getAttribute("lang")&&(o.setAttribute("lang","en"),n(d,'lang="en" added',"critical",o)),d==="meta"){let u=o.getAttribute("name"),v=o.getAttribute("content")||"";u==="viewport"&&v.includes("user-scalable=no")&&(o.setAttribute("content",v.replace("user-scalable=no","user-scalable=yes")),n(d,"user-scalable=yes restored","serious",o)),u==="viewport"&&/maximum-scale=1(?:[^0-9]|$)/.test(v)&&(o.setAttribute("content",v.replace(/maximum-scale=1(?=[^0-9]|$)/,"maximum-scale=5")),n(d,"maximum-scale=5 restored","serious",o))}if(d==="main"&&!o.getAttribute("tabindex")&&(o.setAttribute("tabindex","-1"),o.getAttribute("id")||o.setAttribute("id","main-content")),d==="img"&&(o.hasAttribute("alt")||(o.setAttribute("alt",""),o.setAttribute("aria-hidden","true"),n(d,'alt="" aria-hidden="true"',"serious",o))),d==="svg"&&(!o.getAttribute("aria-hidden")&&!o.getAttribute("aria-label")&&!l.querySelector("title")&&(o.setAttribute("aria-hidden","true"),n(d,'aria-hidden="true" (decorative svg)',"minor",o)),o.getAttribute("focusable")||o.setAttribute("focusable","false")),d==="iframe"&&!o.getAttribute("title")&&!o.getAttribute("aria-label")&&(o.setAttribute("title","embedded content"),o.setAttribute("aria-label","embedded content"),n(d,"title + aria-label added","serious",o)),d==="button"){if(!o.innerText?.trim()&&!o.getAttribute("aria-label")){let u=o.getAttribute("title")||"button";o.setAttribute("aria-label",u),n(d,`aria-label="${u}" (empty button)`,"critical",o)}o.hasAttribute("disabled")&&!o.getAttribute("aria-disabled")&&(o.setAttribute("aria-disabled","true"),t.fixed++)}if(d==="a"){let u=o;!o.innerText?.trim()&&!o.getAttribute("aria-label")&&(o.setAttribute("aria-label",o.getAttribute("title")||"link"),n(d,"aria-label added (empty link)","critical",o)),u.target==="_blank"&&!u.rel?.includes("noopener")&&(u.rel="noopener noreferrer",t.fixed++)}if(Xe.has(d)){let u=o;if(!o.getAttribute("aria-label")&&!o.getAttribute("aria-labelledby")){let v=o.getAttribute("placeholder")||o.getAttribute("name")||d;o.setAttribute("aria-label",v),n(d,`aria-label="${v}"`,"serious",o)}if(o.hasAttribute("required")&&!o.getAttribute("aria-required")&&(o.setAttribute("aria-required","true"),t.fixed++),d==="input"&&!u.autocomplete){let v=u.name||"";u.type==="email"||v.includes("email")?u.autocomplete="email":u.type==="tel"||v.includes("tel")?u.autocomplete="tel":u.type==="password"&&(u.autocomplete="current-password"),t.fixed++}}d==="th"&&!o.getAttribute("scope")&&(o.setAttribute("scope",o.closest("thead")?"col":"row"),n(d,"scope added to <th>","moderate",o)),Ee[d]&&!o.getAttribute("role")&&(o.setAttribute("role",Ee[d]),n(d,`role="${Ee[d]}"`,"minor",o));let g=o.getAttribute("role")||"";g==="tab"&&!o.getAttribute("aria-selected")&&(o.setAttribute("aria-selected","false"),t.fixed++),["alert","status","log"].includes(g)&&!o.getAttribute("aria-live")&&(o.setAttribute("aria-live",g==="alert"?"assertive":"polite"),n(d,`aria-live added on role=${g}`,"moderate",o)),g==="combobox"&&!o.getAttribute("aria-expanded")&&(o.setAttribute("aria-expanded","false"),n(d,'aria-expanded="false" on combobox',"serious",o)),(g==="checkbox"||g==="radio")&&!o.getAttribute("aria-checked")&&(o.setAttribute("aria-checked","false"),n(d,`aria-checked="false" on role=${g}`,"serious",o))}),t.renderTime=parseFloat((performance.now()-a).toFixed(2)),t},scan(){let e={fixed:0,scanned:0,renderTime:0,score:100,details:[]};if(typeof document>"u")return e;let t=performance.now(),a=document.querySelectorAll("*");e.scanned=a.length;let i=(n,l,o,d)=>e.details.push({tag:n,fix:l,severity:o,element:d.outerHTML.slice(0,100)});return a.forEach(n=>{let l=n,o=l.tagName.toLowerCase();(o==="a"||o==="button")&&!l.innerText?.trim()&&!l.getAttribute("aria-label")&&i(o,"needs aria-label (empty)","critical",l),o==="img"&&!l.hasAttribute("alt")&&i(o,"needs alt text","serious",l),Xe.has(o)&&!l.getAttribute("aria-label")&&!l.getAttribute("aria-labelledby")&&i(o,"needs aria-label","serious",l),o==="iframe"&&!l.getAttribute("title")&&!l.getAttribute("aria-label")&&i(o,"iframe needs title","serious",l)}),e.fixed=e.details.length,e.score=ot(e),e.renderTime=parseFloat((performance.now()-t).toFixed(2)),e},startObserver(e){this.observer||typeof document>"u"||(this.observer=new MutationObserver(()=>this.applyFixes(e)),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!1}))},stopObserver(){this.observer?.disconnect(),this.observer=null},announce:m,speak:Ce,showVisualAlert:nt,trapFocus:ce,handlePlainEnglish:Qe,handleSummarisePage:Ze,handleTranslate:et,handleVoiceControl:tt,handleSmartLabels:at,SUPPORTED_LANGUAGES:ie};import Bt,{useEffect as q,useState as L,useCallback as Q}from"react";import{forwardRef as zt,useEffect as ue,useState as H}from"react";import{jsx as r,jsxs as p}from"react/jsx-runtime";var Le={highContrast:!1,reduceMotion:!1,autoFix:!0,dyslexiaFont:!1,fontScale:100,localFont:"",darkMode:!1,largeTargets:!1,speechEnabled:!1,colorBlindMode:"none",showAuditBadge:!1,timeoutWarning:void 0,plainEnglish:!1,summarisePage:!1,translateLanguage:"en",voiceControl:!1,smartLabels:!1},G=[80,90,100,110,120,130],Ht=[{value:"none",label:"None"},{value:"deuteranopia",label:"Deuteranopia"},{value:"protanopia",label:"Protanopia"},{value:"tritanopia",label:"Tritanopia"},{value:"achromatopsia",label:"Greyscale"}],Wt=["Prompt API for Gemini Nano","Summarization API for Gemini Nano","Writer API for Gemini Nano","Rewriter API for Gemini Nano","Translation API"];function $t(){let[e,t]=H(typeof window<"u"?window.innerWidth:1024);return ue(()=>{let a=()=>t(window.innerWidth);return window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]),{isMobile:e<=480,isTablet:e>480&&e<=768}}function Ft({checked:e,onChange:t,label:a,disabled:i=!1}){return p("label",{"aria-label":a,style:{position:"relative",display:"inline-flex",width:"40px",height:"24px",cursor:i?"not-allowed":"pointer",flexShrink:0,opacity:i?.4:1},children:[r("input",{type:"checkbox",checked:e,disabled:i,onChange:n=>t(n.target.checked),style:{opacity:0,width:0,height:0,position:"absolute"}}),r("span",{style:{position:"absolute",inset:0,borderRadius:"99px",background:e?"#0d9488":"#cbd5e1",transition:"background 0.2s"}}),r("span",{style:{position:"absolute",top:"3px",left:e?"19px":"3px",width:"18px",height:"18px",background:"#fff",borderRadius:"50%",transition:"left 0.2s",boxShadow:"0 1px 3px rgba(0,0,0,0.2)",pointerEvents:"none"}})]})}function _({label:e,color:t="#64748b",badge:a,concept:i}){return p("div",{style:{margin:"10px 18px 4px"},children:[p("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r("p",{style:{margin:0,fontSize:"10px",fontWeight:600,color:t,letterSpacing:"0.06em",textTransform:"uppercase"},children:e}),a&&r("span",{style:{fontSize:"9px",fontWeight:500,padding:"1px 7px",borderRadius:"99px",background:"#f5f3ff",color:"#7c3aed",border:"0.5px solid #c4b5fd",whiteSpace:"nowrap"},children:a})]}),i&&r("p",{style:{margin:"2px 0 0",fontSize:"9px",color:"#94a3b8",fontStyle:"italic"},children:i})]})}function M({icon:e,label:t,desc:a,checked:i,onChange:n,disabled:l=!1,disabledReason:o,tip:d}){return p("div",{title:l?o:d,style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"10px 18px",gap:"12px"},children:[p("div",{style:{display:"flex",alignItems:"center",gap:"10px",flex:1,minWidth:0},children:[r("span",{"aria-hidden":"true",style:{width:"32px",height:"32px",borderRadius:"8px",background:l?"#f1f5f9":"#f0fdfa",color:l?"#94a3b8":"#0d9488",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"15px",flexShrink:0,fontWeight:700},children:e}),p("div",{style:{minWidth:0},children:[r("p",{style:{margin:0,fontSize:"13px",fontWeight:500,color:l?"#94a3b8":"#0f172a",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:t}),r("p",{style:{margin:0,fontSize:"10px",color:"#94a3b8"},children:l?o:a})]})]}),r(Ft,{checked:i,onChange:n,label:`Toggle ${t}`,disabled:l})]})}function k(){return r("div",{style:{height:"1px",background:"#f1f5f9"}})}function X({steps:e}){return p("div",{style:{margin:"0 18px 8px",padding:"8px 10px",background:"#f8fafc",borderRadius:"8px",border:"0.5px solid #e2e8f0"},children:[r("p",{style:{margin:"0 0 4px",fontSize:"9px",fontWeight:600,color:"#64748b",textTransform:"uppercase",letterSpacing:"0.05em"},children:"How to use"}),e.map((t,a)=>p("p",{style:{margin:"0 0 2px",fontSize:"10px",color:"#475569"},children:[a+1,". ",t]},a))]})}var Me=zt(({position:e,settings:t,report:a,isActive:i,aiSupported:n,voiceSupported:l,set:o,onApply:d,onReset:g,onClose:u},v)=>{let{isMobile:x,isTablet:j}=$t(),[Z,me]=H([]),[R,$]=H(""),[I,P]=H(""),[h,K]=H(!1),[f,z]=H(null),[S,F]=H("idle");ue(()=>{let s=window;!!(s.LanguageModel||s.ai?.languageModel)&&n?z("gemini"):te()&&z("transformers")},[n]),ue(()=>{if(f!=="transformers")return;let s=setInterval(()=>{F(ae())},500);return()=>clearInterval(s)},[f]);let b=async()=>{if(!(!R.trim()||h)){if(!f){P("\u26A0\uFE0F No AI engine available on this device.");return}K(!0),P("");try{let s;f==="gemini"?s=await ze(R):(F("loading"),s=await He(R),F("ready")),P(s.success&&s.answer?s.answer.replace(/\*\*(.*?)\*\*/g,"$1").replace(/\*(.*?)\*/g,"$1").replace(/#+\s/g,"").trim():"\u26A0\uFE0F "+(s.error||"No answer found on this page"))}catch{P("\u26A0\uFE0F Failed to get answer. Please try again.")}K(!1)}};ue(()=>{(async()=>{try{let B=window;if(!B.queryLocalFonts)return;let ge=await B.queryLocalFonts(),be=[...new Set(ge.map(ye=>ye.family))].sort();me(be.slice(0,50))}catch{}})()},[]);let ee=f==="gemini"?"Gemini Nano":f==="transformers"?"Transformers.js \xB7 All devices":"Detecting...",Y=f==="transformers"&&S==="loading"?"Loading AI model... (first time only)":"...",U=x?{position:"fixed",bottom:0,left:0,right:0,zIndex:9999,background:"#fff",border:"1px solid #e2e8f0",borderRadius:"16px 16px 0 0",boxShadow:"0 -8px 32px rgba(0,0,0,0.12)",maxHeight:"90vh",overflowY:"auto",fontFamily:"system-ui,-apple-system,sans-serif",width:"100%"}:{position:"fixed",bottom:"84px",[e]:"24px",zIndex:9999,width:j?"300px":"320px",maxWidth:"calc(100vw - 48px)",background:"#fff",border:"1px solid #e2e8f0",borderRadius:"16px",boxShadow:"0 8px 32px rgba(0,0,0,0.12)",maxHeight:"80vh",overflowY:"auto",fontFamily:"system-ui,-apple-system,sans-serif"};return p("div",{ref:v,role:"dialog","aria-modal":"true","aria-label":"yuktai accessibility preferences","data-yuktai-panel":"true",style:U,children:[p("div",{style:{padding:"14px 18px 12px",borderBottom:"1px solid #f1f5f9",display:"flex",alignItems:"flex-start",justifyContent:"space-between",position:"sticky",top:0,background:"#fff",zIndex:1},children:[p("div",{children:[p("div",{style:{display:"flex",alignItems:"center",gap:"7px",marginBottom:"4px",flexWrap:"wrap"},children:[r("span",{style:{fontSize:"10px",fontWeight:700,padding:"2px 7px",borderRadius:"99px",background:"#f0fdfa",color:"#0d9488",letterSpacing:"0.05em",fontFamily:"monospace"},children:"@yuktishaalaa/yuktai v2.1.0"}),i&&r("span",{style:{fontSize:"10px",fontWeight:700,padding:"2px 7px",borderRadius:"99px",background:"#f0fdfa",color:"#0f766e",border:"1px solid #99f6e4"},children:"\u25CF ACTIVE"})]}),r("p",{style:{margin:"0 0 1px",fontSize:"15px",fontWeight:600,color:"#0f172a"},children:"Accessibility"}),r("p",{style:{margin:0,fontSize:"11px",color:"#64748b"},children:"WCAG 2.2 \xB7 Open source \xB7 Zero cost \xB7 All devices"})]}),r("button",{onClick:u,"aria-label":"Close accessibility panel",style:{background:"none",border:"none",cursor:"pointer",padding:"4px",color:"#94a3b8",fontSize:"20px",lineHeight:1,borderRadius:"6px",flexShrink:0,minWidth:x?"44px":"auto",minHeight:x?"44px":"auto",display:"flex",alignItems:"center",justifyContent:"center"},children:"\xD7"})]}),r(_,{label:"\u267F Core Accessibility",concept:"Rule-based engine \u2014 works on all browsers and devices"}),r(X,{steps:["Toggle any feature on","Click Apply settings","Preferences saved automatically"]}),r(M,{icon:"\u{1F527}",label:"Auto-fix ARIA",desc:"Injects missing labels and roles automatically",checked:t.autoFix,onChange:s=>o("autoFix",s),tip:"Fixes aria-label, alt text, roles on every element"}),r(k,{}),r(M,{icon:"\u{1F50A}",label:"Speak on focus",desc:"Browser reads elements aloud as you tab",checked:t.speechEnabled,onChange:s=>o("speechEnabled",s),tip:"Uses browser SpeechSynthesis \u2014 no install needed"}),r(k,{}),r(M,{icon:"\u{1F399}\uFE0F",label:"Voice control",desc:"Say commands to navigate the page",checked:t.voiceControl,onChange:s=>o("voiceControl",s),disabled:!l,disabledReason:"Not supported in this browser",tip:'Say "scroll down", "go to main", "click"'}),r(k,{}),r(_,{label:"\u{1F916} AI Features",color:"#7c3aed",badge:"Gemini Nano",concept:"Large Language Model running privately on your device \u2014 Chrome 127+ only"}),r("div",{style:{margin:"4px 18px 6px",padding:"8px 10px",background:n?"#f0fdfa":"#f5f3ff",borderRadius:"8px",border:`0.5px solid ${n?"#99f6e4":"#c4b5fd"}`,fontSize:"10px",color:n?"#0f766e":"#7c3aed",lineHeight:1.5},children:n?"\u2705 Gemini Nano detected \u2014 AI features ready. Runs privately on your device.":"\u2699\uFE0F AI features need one-time setup \u2014 see guide below."}),!n&&p("div",{style:{margin:"0 18px 8px",padding:"10px 12px",background:"#fafafa",borderRadius:"8px",border:"0.5px solid #e2e8f0",fontSize:"11px",color:"#475569",lineHeight:1.7},children:[r("p",{style:{margin:"0 0 6px",fontWeight:600,color:"#0f172a",fontSize:"11px"},children:"\u{1F6E0} One-time setup \u2014 5 steps:"}),p("p",{style:{margin:"0 0 3px"},children:["1. Open Chrome \u2192 ",r("code",{style:{background:"#f1f5f9",padding:"1px 5px",borderRadius:"4px",fontSize:"10px",color:"#0d9488",fontFamily:"monospace"},children:"chrome://flags"})]}),r("p",{style:{margin:"0 0 3px"},children:"2. Enable each flag:"}),r("div",{style:{display:"flex",flexDirection:"column",gap:"2px",margin:"4px 0 6px 10px"},children:Wt.map(s=>p("span",{style:{fontSize:"10px",color:"#7c3aed",fontFamily:"monospace"},children:["\u2192 ",s]},s))}),p("p",{style:{margin:"0 0 3px"},children:["3. Click ",r("strong",{style:{color:"#0f172a"},children:"Relaunch"})]}),p("p",{style:{margin:"0 0 3px"},children:["4. ",r("code",{style:{background:"#f1f5f9",padding:"1px 5px",borderRadius:"4px",fontSize:"10px",color:"#0d9488",fontFamily:"monospace"},children:"chrome://components"})," \u2192 Optimization Guide On Device Model \u2192 Check for update"]}),r("p",{style:{margin:"0"},children:"5. Refresh \u2014 AI features unlock automatically \u2705"})]}),r(M,{icon:"\u{1F4DD}",label:"Plain English mode",desc:"Rewrites complex text in simple language",checked:t.plainEnglish,onChange:s=>o("plainEnglish",s),disabled:!n,disabledReason:"Enable Gemini Nano \u2014 see setup above",tip:"AI concept: LLM text rewriting"}),r(k,{}),r(M,{icon:"\u{1F4CB}",label:"Summarise page",desc:"3-sentence summary appears at top",checked:t.summarisePage,onChange:s=>o("summarisePage",s),disabled:!n,disabledReason:"Enable Gemini Nano \u2014 see setup above",tip:"AI concept: Abstractive summarisation"}),r(k,{}),r(M,{icon:"\u{1F3F7}\uFE0F",label:"Smart aria-labels",desc:"AI generates meaningful labels for elements",checked:t.smartLabels,onChange:s=>o("smartLabels",s),disabled:!n,disabledReason:"Enable Gemini Nano \u2014 see setup above",tip:"AI concept: Context-aware label generation"}),r(k,{}),r(_,{label:"\u{1F441}\uFE0F Visual",concept:"CSS filter-based \u2014 works on all browsers and devices"}),r(X,{steps:["Toggle any visual mode","Changes apply instantly","Works on mobile and desktop"]}),r(M,{icon:"\u25D1",label:"High contrast",desc:"Boosts contrast for low vision users",checked:t.highContrast,onChange:s=>o("highContrast",s),tip:"CSS filter: contrast()"}),r(k,{}),r(M,{icon:"\u{1F319}",label:"Dark mode",desc:"Inverts colours \u2014 easy on eyes at night",checked:t.darkMode,onChange:s=>o("darkMode",s),tip:"CSS filter: invert + hue-rotate"}),r(k,{}),r(M,{icon:"\u23F8\uFE0F",label:"Reduce motion",desc:"Disables all animations",checked:t.reduceMotion,onChange:s=>o("reduceMotion",s),tip:"WCAG 2.3.3 \u2014 vestibular disorders"}),r(k,{}),r(M,{icon:"\u{1F446}",label:"Large targets",desc:"44\xD744px minimum touch targets",checked:t.largeTargets,onChange:s=>o("largeTargets",s),tip:"WCAG 2.5.8 \u2014 motor impaired users"}),r(k,{}),p("div",{style:{padding:"10px 18px"},children:[r("p",{style:{margin:"0 0 2px",fontSize:"12px",fontWeight:500,color:"#0f172a"},children:"\u{1F3A8} Colour blindness"}),r("p",{style:{margin:"0 0 8px",fontSize:"10px",color:"#94a3b8"},children:"SVG colour matrix filters \u2014 all devices"}),r("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:Ht.map(s=>r("button",{onClick:()=>o("colorBlindMode",s.value),"aria-pressed":t.colorBlindMode===s.value,style:{padding:"4px 10px",borderRadius:"20px",fontSize:"11px",fontWeight:500,border:`1px solid ${t.colorBlindMode===s.value?"#0d9488":"#e2e8f0"}`,background:t.colorBlindMode===s.value?"#f0fdfa":"#fff",color:t.colorBlindMode===s.value?"#0d9488":"#64748b",cursor:"pointer",minHeight:x?"36px":"auto"},children:s.label},s.value))})]}),r(k,{}),r(_,{label:"\u{1F524} Font",concept:"Browser Font API + CSS \u2014 Chrome 103+"}),r(X,{steps:["Toggle dyslexia font or pick from device","Adjust size with + / \u2212","Saved across visits"]}),r(M,{icon:"Aa",label:"Dyslexia-friendly font",desc:"Atkinson Hyperlegible \u2014 research-backed",checked:t.dyslexiaFont,onChange:s=>o("dyslexiaFont",s),tip:"By Braille Institute \u2014 free and open source"}),r(k,{}),p("div",{style:{padding:"10px 18px"},children:[r("p",{style:{margin:"0 0 2px",fontSize:"12px",fontWeight:500,color:"#0f172a"},children:"\u{1F5A5}\uFE0F Local font"}),r("p",{style:{margin:"0 0 8px",fontSize:"10px",color:"#94a3b8"},children:"window.queryLocalFonts() \u2014 Chrome 103+"}),Z.length>0?p("select",{value:t.localFont,onChange:s=>o("localFont",s.target.value),"aria-label":"Choose a font from your device",style:{width:"100%",padding:"8px 10px",borderRadius:"8px",border:"1px solid #e2e8f0",fontSize:"13px",color:"#0f172a",background:"#fff",cursor:"pointer",height:x?"44px":"36px"},children:[r("option",{value:"",children:"System default"}),Z.map(s=>r("option",{value:s,style:{fontFamily:s},children:s},s))]}):r("p",{style:{margin:0,fontSize:"11px",color:"#94a3b8"},children:"Allow font access when Chrome prompts you."})]}),r(k,{}),p("div",{style:{padding:"10px 18px 14px"},children:[p("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:"10px"},children:[p("div",{children:[r("p",{style:{margin:0,fontSize:"12px",fontWeight:500,color:"#0f172a"},children:"\u{1F4CF} Text size"}),r("p",{style:{margin:0,fontSize:"10px",color:"#94a3b8"},children:"Scales all text on the page"})]}),p("span",{style:{fontSize:"12px",fontWeight:600,color:"#0d9488",background:"#f0fdfa",padding:"2px 8px",borderRadius:"99px"},children:[t.fontScale,"%"]})]}),p("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r("button",{onClick:()=>{let s=G.indexOf(t.fontScale);s>0&&o("fontScale",G[s-1])},disabled:t.fontScale<=80,"aria-label":"Decrease text size",style:{width:x?"44px":"30px",height:x?"44px":"30px",borderRadius:"8px",border:"1px solid #e2e8f0",background:"#fff",cursor:t.fontScale<=80?"not-allowed":"pointer",fontSize:"16px",color:t.fontScale<=80?"#cbd5e1":"#0f172a",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:"\u2212"}),r("div",{style:{flex:1,display:"flex",gap:"3px"},children:G.map(s=>r("button",{onClick:()=>o("fontScale",s),"aria-label":`Set text size to ${s}%`,style:{flex:1,height:"6px",borderRadius:"99px",border:"none",cursor:"pointer",padding:0,background:s<=t.fontScale?"#0d9488":"#e2e8f0",transition:"background 0.15s"}},s))}),r("button",{onClick:()=>{let s=G.indexOf(t.fontScale);s<G.length-1&&o("fontScale",G[s+1])},disabled:t.fontScale>=130,"aria-label":"Increase text size",style:{width:x?"44px":"30px",height:x?"44px":"30px",borderRadius:"8px",border:"1px solid #e2e8f0",background:"#fff",cursor:t.fontScale>=130?"not-allowed":"pointer",fontSize:"16px",color:t.fontScale>=130?"#cbd5e1":"#0f172a",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:"+"})]})]}),r(k,{}),r(_,{label:"\u{1F310} Translate",color:"#7c3aed",badge:"Gemini Nano",concept:"Chrome Translation API \u2014 on device, no internet after setup"}),r(X,{steps:["Enable Gemini Nano first","Pick your language","Full page translates instantly"]}),p("div",{style:{padding:"6px 18px 12px"},children:[r("div",{style:{display:"flex",flexWrap:"wrap",gap:"6px"},children:ie.slice(0,x?8:18).map(s=>r("button",{onClick:()=>o("translateLanguage",s.code),"aria-pressed":t.translateLanguage===s.code,disabled:!n,style:{padding:"4px 10px",borderRadius:"20px",fontSize:"11px",fontWeight:500,border:`1px solid ${t.translateLanguage===s.code?"#7c3aed":"#e2e8f0"}`,background:t.translateLanguage===s.code?"#f5f3ff":"#fff",color:t.translateLanguage===s.code?"#7c3aed":"#64748b",cursor:n?"pointer":"not-allowed",opacity:n?1:.5,minHeight:x?"36px":"auto"},children:s.label},s.code))}),!n&&r("p",{style:{margin:"6px 0 0",fontSize:"10px",color:"#94a3b8"},children:"Enable Gemini Nano using the setup guide above."})]}),r(k,{}),r(_,{label:"\u{1F4AC} Ask This Page",color:"#0d9488",badge:ee,concept:"RAG \u2014 Retrieval Augmented Generation. Works on all devices including mobile."}),r(X,{steps:["Type any question about this page","Press Ask or hit Enter",f==="transformers"?"Transformers.js answers \u2014 works on mobile, offline":"Gemini Nano reads page and answers privately","Zero cost. No data leaves your device."]}),p("div",{style:{margin:"0 18px 8px",padding:"6px 10px",background:f==="gemini"?"#f0fdfa":f==="transformers"?"#f5f3ff":"#f8fafc",borderRadius:"8px",border:`0.5px solid ${f==="gemini"?"#99f6e4":f==="transformers"?"#c4b5fd":"#e2e8f0"}`,fontSize:"10px",color:f==="gemini"?"#0f766e":f==="transformers"?"#7c3aed":"#94a3b8"},children:[f==="gemini"&&"\u2705 Using Gemini Nano \u2014 on device, private, instant",f==="transformers"&&"\u2705 Using Transformers.js \u2014 works on mobile and all browsers",!f&&"\u23F3 Detecting AI engine...",f==="transformers"&&S==="loading"&&" \xB7 Loading model...",f==="transformers"&&S==="ready"&&" \xB7 Model ready \u2705"]}),p("div",{style:{padding:"0 18px 14px"},children:[p("div",{style:{display:"flex",gap:"6px",marginBottom:"8px"},children:[r("input",{type:"text",value:R,onChange:s=>$(s.target.value),onKeyDown:s=>{s.key==="Enter"&&b()},placeholder:"e.g. What does this page do?",disabled:h||!f,"aria-label":"Ask a question about this page",style:{flex:1,padding:"8px 10px",borderRadius:"8px",border:"1px solid #e2e8f0",fontSize:"12px",color:"#0f172a",background:f?"#fff":"#f8fafc",outline:"none",height:x?"44px":"36px"}}),r("button",{onClick:b,disabled:h||!R.trim()||!f,"aria-label":"Ask question",style:{padding:"8px 14px",borderRadius:"8px",border:"none",background:f&&R.trim()&&!h?"#0d9488":"#e2e8f0",color:f&&R.trim()&&!h?"#fff":"#94a3b8",fontSize:"12px",fontWeight:600,cursor:f&&R.trim()&&!h?"pointer":"not-allowed",flexShrink:0,height:x?"44px":"36px",minWidth:"52px",transition:"background 0.2s"},children:h?Y:"Ask"})]}),I&&p("div",{role:"status","aria-live":"polite",style:{padding:"10px 12px",background:"#f0fdfa",border:"1px solid #99f6e4",borderRadius:"8px",fontSize:"12px",color:"#0f766e",lineHeight:1.6,maxHeight:"180px",overflowY:"auto"},children:[r("strong",{style:{display:"block",marginBottom:"4px",fontSize:"11px",color:"#0d9488"},children:"\u{1F4AC} Answer"}),I,r("button",{onClick:()=>{P(""),$("")},style:{display:"block",marginTop:"6px",background:"none",border:"none",color:"#94a3b8",fontSize:"10px",cursor:"pointer",padding:0},children:"Clear"})]})]}),a&&r("div",{role:"status",style:{margin:"0 14px 10px",padding:"8px 12px",background:"#f0fdfa",border:"1px solid #99f6e4",borderRadius:"8px",fontSize:"12px",color:"#0f766e",fontWeight:500,fontFamily:"monospace"},children:a.fixed>0?`\u2713 ${a.fixed} fixes \xB7 ${a.scanned} nodes \xB7 ${a.renderTime}ms \xB7 Score: ${a.score}/100`:`\u2713 0 auto-fixes needed \xB7 ${a.scanned} nodes \xB7 ${a.renderTime}ms`}),p("div",{style:{display:"flex",gap:"8px",padding:"12px 14px 14px",position:x?"sticky":"relative",bottom:x?0:"auto",background:"#fff",borderTop:"1px solid #f1f5f9"},children:[r("button",{onClick:g,style:{flex:1,padding:x?"12px 0":"8px 0",fontSize:"13px",fontWeight:500,borderRadius:"9px",border:"1px solid #e2e8f0",background:"#fff",color:"#64748b",cursor:"pointer"},children:"Reset"}),r("button",{onClick:d,style:{flex:2,padding:x?"12px 0":"8px 0",fontSize:"13px",fontWeight:600,borderRadius:"9px",border:"none",background:"#0d9488",color:"#fff",cursor:"pointer"},children:"Apply settings"})]})]})});Me.displayName="WidgetPanel";import{Fragment as Ot,jsx as A,jsxs as V}from"react/jsx-runtime";async function Nt(){try{if(typeof window>"u")return!1;let e=window;if(e.LanguageModel)try{if(typeof e.LanguageModel.availability=="function"){let a=await e.LanguageModel.availability();if(a==="readily"||a==="available"||a==="downloadable")return!0}else return!0}catch{}if(e.Summarizer)try{let a=await e.Summarizer.availability?.();if(!a||a==="readily"||a==="available")return!0}catch{}if(e.Rewriter)try{let a=await e.Rewriter.availability?.();if(!a||a==="readily"||a==="available")return!0}catch{}if(e.Writer)try{let a=await e.Writer.availability?.();if(!a||a==="readily"||a==="available")return!0}catch{}let t=e.ai||globalThis.ai;if(t){if(t.languageModel?.availability)try{let a=await t.languageModel.availability();if(a==="readily"||a==="available")return!0}catch{}if(t.languageModel&&typeof t.languageModel.create=="function"||t.summarizer||t.rewriter||t.writer||t.languageModel)return!0}return!!(e.Translator||e.translation?.canTranslate)}catch{return!1}}function Re({position:e="left",children:t,config:a={},showRag:i=!1}){let[n,l]=L(!1),[o,d]=L(Le),[g,u]=L(null),[v,x]=L(!1),[j,Z]=L(!1),[me,R]=L(!1),$=Bt.useRef(null),[I,P]=L(!1),[h,K]=L(""),[f,z]=L(""),[S,F]=L(!1),[b,ee]=L(null),[Y,U]=L("idle");q(()=>{if(typeof window>"u")return;let c=window;!!(c.LanguageModel||c.ai?.languageModel)&&j?ee("gemini"):te()&&ee("transformers")},[j]),q(()=>{if(b!=="transformers")return;let c=setInterval(()=>U(ae()),500);return()=>clearInterval(c)},[b]);let s=Q(async()=>{if(!(!h.trim()||S)){if(!b){z("\u26A0\uFE0F No AI engine available on this device.");return}F(!0),z("");try{let c;if(b==="gemini"){let{askPage:w}=await import("./rag-MKBAGH6J.mjs");c=await w(h)}else{U("loading");let{askPageWithTransformers:w}=await import("./transformers-rag-YMF5WLGC.mjs");c=await w(h),U("ready")}z(c.success&&c.answer?c.answer.replace(/\*\*(.*?)\*\*/g,"$1").replace(/\*(.*?)\*/g,"$1").replace(/#+\s/g,"").trim():"\u26A0\uFE0F "+(c.error||"No answer found."))}catch{z("\u26A0\uFE0F Something went wrong. Please try again.")}F(!1)}},[h,S,b]);q(()=>{if(typeof window>"u")return;let w=setTimeout(async()=>{let J=window;console.log("yuktai: Checking AI APIs..."),console.log("yuktai: window.LanguageModel =",J.LanguageModel);let Ie=await Nt();Z(Ie),console.log(Ie?"yuktai: Chrome Built-in AI detected \u2705":"yuktai: Chrome Built-in AI not detected \u2014 Transformers.js will handle RAG on mobile"),R(!!(J.SpeechRecognition||J.webkitSpeechRecognition))},800);return()=>clearTimeout(w)},[]),q(()=>{if(!(typeof window>"u"))try{let c=localStorage.getItem("yuktai-a11y-prefs");c&&d(w=>({...w,...JSON.parse(c)}))}catch{}},[]);let B=Q(async c=>{let w={enabled:!0,highContrast:c.highContrast,darkMode:c.darkMode,reduceMotion:c.reduceMotion,largeTargets:c.largeTargets,speechEnabled:c.speechEnabled,autoFix:c.autoFix,dyslexiaFont:c.dyslexiaFont,localFont:c.localFont,fontSizeMultiplier:c.fontScale/100,colorBlindMode:c.colorBlindMode,showAuditBadge:c.showAuditBadge,showSkipLinks:!0,showPreferencePanel:!1,plainEnglish:c.plainEnglish,summarisePage:c.summarisePage,translateLanguage:c.translateLanguage,voiceControl:c.voiceControl,smartLabels:c.smartLabels,...a};await C.execute(w),u(C.applyFixes(w)),x(!0)},[a]),ge=Q(async()=>{try{localStorage.setItem("yuktai-a11y-prefs",JSON.stringify(o))}catch{}await B(o),l(!1)},[o,B]),be=Q(()=>{d(Le);try{localStorage.removeItem("yuktai-a11y-prefs")}catch{}let c=document.documentElement;["data-yuktai-high-contrast","data-yuktai-dark","data-yuktai-reduce-motion","data-yuktai-large-targets","data-yuktai-keyboard","data-yuktai-dyslexia"].forEach(w=>c.removeAttribute(w)),document.body.style.filter="",document.body.style.fontFamily="",document.documentElement.style.fontSize="",u(null),x(!1)},[]),ye=Q((c,w)=>{d(J=>({...J,[c]:w}))},[]);q(()=>{let c=w=>{w.key==="Escape"&&(n&&l(!1),I&&P(!1))};return window.addEventListener("keydown",c),()=>window.removeEventListener("keydown",c)},[n,I]),q(()=>{n&&$.current&&C.trapFocus($.current)},[n]);let st=b==="transformers"&&Y==="loading"?"Loading AI... (first time only)":"...",Pe=b==="gemini"?"Gemini Nano \xB7 On device \xB7 Instant":b==="transformers"?"Transformers.js \xB7 All devices \xB7 Offline":"Detecting engine...",lt={position:"fixed",bottom:"24px",[e]:"24px",zIndex:9998,width:"52px",height:"52px",borderRadius:"50%",background:v?"#0d9488":"#1a73e8",color:"#fff",border:"none",cursor:"pointer",fontSize:"22px",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 16px rgba(0,0,0,0.25)",transition:"transform 0.15s, background 0.2s"},dt={position:"fixed",bottom:"84px",[e]:"24px",zIndex:9998,width:"52px",height:"52px",borderRadius:"50%",background:I?"#7c3aed":"#6d28d9",color:"#fff",border:"none",cursor:"pointer",fontSize:"22px",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 4px 16px rgba(0,0,0,0.25)",transition:"transform 0.15s, background 0.2s"};return V(Ot,{children:[t,i&&A("button",{style:dt,"aria-label":"Ask a question about this page","aria-haspopup":"dialog","aria-expanded":I,title:`Ask this page \xB7 ${Pe}`,onClick:()=>{P(c=>!c),l(!1)},onMouseEnter:c=>{c.currentTarget.style.transform="scale(1.08)"},onMouseLeave:c=>{c.currentTarget.style.transform="scale(1)"},children:"\u{1F4AC}"}),i&&I&&V("div",{role:"dialog","aria-modal":"true","aria-label":"Ask this page","data-yuktai-panel":"true",style:{position:"fixed",bottom:"148px",[e]:"24px",zIndex:9999,width:"300px",maxWidth:"calc(100vw - 48px)",background:"#fff",border:"1px solid #e2e8f0",borderRadius:"16px",boxShadow:"0 8px 32px rgba(0,0,0,0.12)",fontFamily:"system-ui,-apple-system,sans-serif",padding:"14px"},children:[V("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start",marginBottom:"10px"},children:[V("div",{children:[A("p",{style:{margin:"0 0 2px",fontSize:"13px",fontWeight:600,color:"#0f172a"},children:"\u{1F4AC} Ask this page"}),A("p",{style:{margin:0,fontSize:"10px",color:b==="gemini"?"#0d9488":"#7c3aed"},children:Pe}),b==="transformers"&&Y==="loading"&&A("p",{style:{margin:"2px 0 0",fontSize:"9px",color:"#94a3b8"},children:"Downloading AI model \u2014 first time only (~90MB)"}),b==="transformers"&&Y==="ready"&&A("p",{style:{margin:"2px 0 0",fontSize:"9px",color:"#0d9488"},children:"Model ready \u2705 \u2014 works offline now"})]}),A("button",{onClick:()=>P(!1),"aria-label":"Close ask panel",style:{background:"none",border:"none",cursor:"pointer",color:"#94a3b8",fontSize:"18px",lineHeight:1,padding:"2px",borderRadius:"4px"},children:"\xD7"})]}),V("div",{style:{display:"flex",gap:"6px",marginBottom:"8px"},children:[A("input",{type:"text",value:h,onChange:c=>K(c.target.value),onKeyDown:c=>{c.key==="Enter"&&s()},placeholder:"e.g. What does this page do?",disabled:S||!b,"aria-label":"Ask a question about this page",style:{flex:1,padding:"8px 10px",borderRadius:"8px",border:"1px solid #e2e8f0",fontSize:"12px",color:"#0f172a",background:b?"#fff":"#f8fafc",outline:"none",height:"36px"}}),A("button",{onClick:s,disabled:S||!h.trim()||!b,"aria-label":"Submit question",style:{padding:"8px 12px",borderRadius:"8px",border:"none",background:b&&h.trim()&&!S?"#7c3aed":"#e2e8f0",color:b&&h.trim()&&!S?"#fff":"#94a3b8",fontSize:"12px",fontWeight:600,cursor:b&&h.trim()&&!S?"pointer":"not-allowed",height:"36px",minWidth:"48px",transition:"background 0.2s"},children:S?st:"Ask"})]}),f&&V("div",{style:{padding:"10px",background:"#f5f3ff",borderRadius:"8px",fontSize:"12px",color:"#4c1d95",lineHeight:1.6,maxHeight:"180px",overflowY:"auto"},children:[A("strong",{style:{display:"block",marginBottom:"4px",fontSize:"11px",color:"#7c3aed"},children:"\u{1F4AC} Answer"}),f,A("button",{onClick:()=>{z(""),K("")},style:{display:"block",marginTop:"6px",background:"none",border:"none",color:"#94a3b8",fontSize:"10px",cursor:"pointer",padding:0},children:"Clear"})]}),!b&&A("p",{style:{margin:"4px 0 0",fontSize:"10px",color:"#94a3b8"},children:"Detecting AI engine..."})]}),A("button",{style:lt,"aria-label":"Open accessibility preferences","aria-haspopup":"dialog","aria-expanded":n,"data-yuktai-pref-toggle":"true",onClick:()=>{l(c=>!c),P(!1)},onMouseEnter:c=>{c.currentTarget.style.transform="scale(1.08)"},onMouseLeave:c=>{c.currentTarget.style.transform="scale(1)"},children:"\u267F"}),n&&A(Me,{ref:$,position:e,settings:o,report:g,isActive:v,aiSupported:j,voiceSupported:me,set:ye,onApply:ge,onReset:be,onClose:()=>l(!1)})]})}var pe={name:"ai.text",async execute(e){return`\u{1F916} YuktAI says: ${e}`}};var fe={name:"voice.text",async execute(e){return!e||e.trim()===""?"\u{1F3A4} No speech detected":`\u{1F3A4} You said: ${e}`}};var W=class{plugins=new Map;register(t,a){if(!a||typeof a.execute!="function")throw new Error(`Invalid plugin: ${t}`);this.plugins.set(t,a)}use(t){return this.plugins.get(t)}async run(t,a){try{let i=this.use(t);if(!i)throw new Error(`Plugin not found: ${t}`);return await i.execute(a)}catch(i){throw console.error(`[YuktAI Runtime Error in ${t}]:`,i),i}}getPlugins(){return Array.from(this.plugins.keys())}};function Dt(){if(typeof globalThis>"u")return new W;if(!globalThis.__yuktai_runtime__){let e=new W;e.register(C.name,C),e.register(pe.name,pe),e.register(fe.name,fe),globalThis.__yuktai_runtime__=e}return globalThis.__yuktai_runtime__}var rt=typeof window<"u"?Dt():new W,za={wcagPlugin:C,list(){return rt.getPlugins()},use(e){return rt.use(e)},fix(e){return C.applyFixes({enabled:!0,autoFix:!0,...e})},scan(){return C.scan()}};export{W as Runtime,za as YuktAI,Re as YuktAIWrapper,pe as aiPlugin,Re as default,fe as voicePlugin,C as wcag,C as wcagPlugin};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c}from"./chunk-
|
|
1
|
+
import{a,b,c}from"./chunk-R7HFPJ7V.mjs";export{a as askPageWithTransformers,c as getModelLoadStatus,b as isTransformersSupported};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yuktishaalaa/yuktai",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.12",
|
|
4
4
|
"description": "Universal runtime accessibility plugin — auto-fixes WCAG 2.2 violations with on-device AI features. Zero API keys.",
|
|
5
5
|
"author": "Sandeep Miriyala — Yuktishaalaa AI Lab",
|
|
6
6
|
"license": "ISC",
|
package/dist/chunk-32BY5XON.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var m=null,g=null,i=!1,u=!1;async function p(){if(!u){if(i){for(;i;)await new Promise(e=>setTimeout(e,200));return}i=!0;try{let{pipeline:e,env:t}=await import("@huggingface/transformers");t.allowRemoteModels=!0,t.allowLocalModels=!1,t.useBrowserCache=!0,m=await e("feature-extraction","Xenova/all-MiniLM-L6-v2",{device:typeof navigator<"u"&&"gpu"in navigator?"webgpu":"wasm"}),g=await e("question-answering","Xenova/distilbert-base-cased-distilled-squad",{device:typeof navigator<"u"&&"gpu"in navigator?"webgpu":"wasm"}),u=!0,i=!1,console.log("yuktai: Transformers.js models loaded \u2705")}catch(e){throw i=!1,console.error("yuktai: Transformers.js model load failed",e),e}}}function w(){return new Promise(e=>{let t=setTimeout(e,1500),r=new MutationObserver(()=>{clearTimeout(t),t=setTimeout(()=>{r.disconnect(),e()},500)});r.observe(document.body,{childList:!0,subtree:!0})})}function h(){let e=[],t=document.querySelectorAll("*");for(let r of t){if(r.closest("[data-yuktai-panel]"))continue;let o=r.innerText?.trim();o&&o.length>30&&e.push(o);let s=r.getAttribute("aria-label");s&&s.length>10&&e.push(s),(r instanceof HTMLInputElement||r instanceof HTMLTextAreaElement)&&r.placeholder&&e.push(r.placeholder)}return e.join(" ").slice(0,8e3)}function y(e,t=200,r=50){if(typeof e!="string")try{e=String(e??"")}catch{return[]}let o=e.trim();if(!o)return[];let s=Math.min(r,Math.floor(t/2)),n=o.split(/\s+/),a=[],l=t-s;for(let c=0;c<n.length;c+=l){let f=n.slice(c,c+t).join(" ");f.trim().length>20&&a.push(f)}return a}function b(e,t){let r=0,o=0,s=0;for(let n=0;n<e.length;n++)r+=e[n]*t[n],o+=e[n]*e[n],s+=t[n]*t[n];return r/(Math.sqrt(o)*Math.sqrt(s)+1e-8)}async function d(e){let t=await m(e,{pooling:"mean",normalize:!0}),r=t?.data??t;return Array.from(r)}async function v(e,t,r=3){let o=await d(e),s=await Promise.all(t.map(async n=>{let a=await d(n),l=b(o,a);return{chunk:n,score:l}}));return s.sort((n,a)=>a.score-n.score),s.slice(0,r).map(n=>n.chunk)}async function M(e){if(!e.trim())return{success:!1,answer:"",error:"Please type a question."};try{await p(),await w();let t=h();if(!t||t.length<50)return{success:!1,answer:"",error:"Not enough content on this page."};let r=y(t);if(r.length===0)return{success:!1,answer:"",error:"Could not process page content."};let s=(await v(e,r,3)).join(" ... "),n=await g(e,s);return!n?.answer||n.answer.trim().length===0?{success:!0,answer:"I could not find a specific answer on this page."}:{success:!0,answer:n.answer.trim()}}catch(t){return console.error("yuktai: Transformers RAG error",t),{success:!1,answer:"",error:t instanceof Error?t.message:"Transformers.js error."}}}function k(){try{return typeof WebAssembly<"u"&&typeof Worker<"u"}catch{return!1}}function P(){return u?"ready":i?"loading":"idle"}export{M as a,k as b,P as c};
|