@yuktishaalaa/yuktai 3.0.14 → 3.0.16

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,18 @@
1
+ function f(n){try{let a=window.getComputedStyle(n);if(a.display==="none"||a.visibility==="hidden"||a.opacity==="0"||n.hidden)return!1;let t=n.getBoundingClientRect();return!(t.width===0&&t.height===0)}catch{return!0}}function T(){let n=[],a=new Set,t=e=>{let r=e.trim();r&&r.length>10&&!a.has(r)&&(a.add(r),n.push(r))};document.title&&t(document.title);let o=['meta[name="description"]','meta[name="keywords"]','meta[property="og:title"]','meta[property="og:description"]','meta[name="twitter:title"]','meta[name="twitter:description"]'];for(let e of o){let r=document.querySelector(e)?.getAttribute("content");r&&t(r)}let l=["h1","h2","h3","h4","h5","h6","p","blockquote","q","pre","code","li","dt","dd","th","td","caption","a","b","strong","em","i","u","s","abbr","acronym","cite","dfn","mark","small","sub","sup","ins","del","bdi","bdo","article","section","aside","nav","header","footer","main","summary","details","figcaption","figure","address","time","output","label","legend","option","button","font","center","span","div","[role='heading']","[role='main']","[role='article']","[role='region']","[role='complementary']","[role='contentinfo']","[role='navigation']","[role='banner']","[role='listitem']","[role='cell']","[role='columnheader']","[role='rowheader']"],c=document.querySelectorAll(l.join(","));for(let e of c){if(e.closest("[data-yuktai-panel]")||!f(e)||e.querySelector("p, h1, h2, h3, h4, h5, h6, li, td, th, div, article, section, blockquote, pre"))continue;let i=e.innerText?.trim();if(i&&i.length>10&&t(i),!i){let d=e.textContent?.trim();d&&d.length>10&&t(d)}let s=e.getAttribute("aria-label")?.trim();s&&s.length>5&&t(s);let u=e.getAttribute("aria-description")?.trim();u&&u.length>5&&t(u);let m=e.getAttribute("aria-valuetext")?.trim();m&&t(m);let p=e.getAttribute("title")?.trim();p&&p.length>5&&t(p);let b=e.getAttribute("data-label")?.trim();b&&t(b);let y=e.getAttribute("data-title")?.trim();y&&t(y),e.querySelectorAll("img").forEach(d=>{let g=d.getAttribute("alt")?.trim();g&&g.length>5&&t(g);let h=d.getAttribute("title")?.trim();h&&h.length>5&&t(h)})}document.querySelectorAll("img").forEach(e=>{if(e.closest("[data-yuktai-panel]")||!f(e))return;let r=e.getAttribute("alt")?.trim(),i=e.getAttribute("title")?.trim();r&&r.length>5&&t(r),i&&i.length>5&&t(i)}),document.querySelectorAll("input:not([type=hidden]), textarea").forEach(e=>{if(e.closest("[data-yuktai-panel]")||!f(e))return;e.placeholder&&t(e.placeholder),e.value&&e.value.length>3&&t(e.value);let r=e.getAttribute("aria-label")?.trim();r&&t(r)}),document.querySelectorAll("select").forEach(e=>{e.closest("[data-yuktai-panel]")||f(e)&&Array.from(e.options).forEach(r=>{r.text?.trim().length>3&&t(r.text.trim())})}),document.querySelectorAll("td, th").forEach(e=>{if(e.closest("[data-yuktai-panel]")||!f(e))return;let r=e.innerText?.trim();r&&r.length>3&&t(r)});try{document.querySelectorAll("iframe").forEach(e=>{try{let r=e.contentDocument;if(!r)return;let i=r.body?.innerText?.trim();i&&i.length>20&&t(i.slice(0,500))}catch{}})}catch{}return document.querySelectorAll("a").forEach(e=>{if(e.closest("[data-yuktai-panel]")||!f(e))return;let r=e.innerText?.trim();r&&r.length>3&&r.length<100&&t(r)}),n.join(" ").slice(0,5e3)}function E(n){let a=n.getAttribute("aria-label")?.trim();if(a)return a;let t=n.getAttribute("aria-labelledby");if(t){let i=document.getElementById(t);if(i)return i.innerText?.trim()||""}if(n.id){let i=document.querySelector(`label[for="${n.id}"]`);if(i)return i.innerText?.trim()||""}let o=n.closest("label");if(o){let i=o.cloneNode(!0);return i.querySelectorAll("input, select, textarea").forEach(s=>s.remove()),i.innerText?.trim()||""}if((n instanceof HTMLInputElement||n instanceof HTMLTextAreaElement)&&n.placeholder)return n.placeholder;if(n.name)return n.name.replace(/[_-]/g," ");let l=n.previousSibling;if(l?.nodeType===Node.TEXT_NODE){let i=l.textContent?.trim();if(i&&i.length>1)return i}let c=n.previousElementSibling;if(c){let i=c.innerText?.trim();if(i&&i.length>1&&i.length<60)return i}let e=n.closest("td, th");if(e){let i=e.previousElementSibling;if(i){let s=i.innerText?.trim();if(s&&s.length>1)return s}}let r=n.getAttribute("title")?.trim();return r||(n instanceof HTMLInputElement?n.type:"field")}function x(){let n=[],a=document.querySelectorAll(["input:not([type=hidden])","input:not([type=submit])","input:not([type=button])","input:not([type=reset])","input:not([type=image])","select","textarea","[contenteditable='true']","[role='textbox']","[role='combobox']","[role='spinbutton']","[role='searchbox']","[role='listbox']"].join(", "));for(let t of a){if(t.closest("[data-yuktai-panel]")||!f(t))continue;if(t instanceof HTMLInputElement){let l=t.type.toLowerCase();if(["submit","button","reset","image"].includes(l))continue}let o=E(t);n.push({label:o,type:t instanceof HTMLInputElement?t.type:t.tagName.toLowerCase(),placeholder:(t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)&&t.placeholder||"",required:t.required||t.getAttribute("aria-required")==="true"||t.getAttribute("data-required")==="true",element:t})}return n}function L(n,a=3e3){n.scrollIntoView({behavior:"smooth",block:"center"}),n.style.outline="3px solid #0d9488",n.style.outlineOffset="3px";try{n.focus()}catch{}setTimeout(()=>{n.style.outline="",n.style.outlineOffset=""},a)}function A(n){let a=n.toLowerCase(),t=document.querySelectorAll("h1, h2, h3, h4, h5, h6, section, article, [id], [aria-label], [role='heading'], [role='region']");for(let o of t){if(o.closest("[data-yuktai-panel]")||!f(o))continue;if((o.innerText||o.getAttribute("id")||o.getAttribute("aria-label")||o.getAttribute("name")||"").toLowerCase().includes(a))return o.scrollIntoView({behavior:"smooth",block:"center"}),o.style.outline="2px solid #0d9488",o.style.outlineOffset="4px",setTimeout(()=>{o.style.outline="",o.style.outlineOffset=""},2500),!0}return!1}async function M(n,a,t){let o=window,l=o.LanguageModel||o.ai?.languageModel;if(!l)throw new Error("Gemini Nano not available");let c=await l.create({systemPrompt:`You are a helpful web accessibility agent.
2
+ Create a simple action plan to help a user complete a task on a webpage.
3
+ Rules:
4
+ - Maximum 5 steps
5
+ - Short and clear \u2014 no jargon
6
+ - If filling a form \u2014 list each field and what to enter
7
+ - No markdown \u2014 no asterisks, no bold, no headers
8
+ - Number each step: 1. 2. 3.`}),r=`Page content: ${n}${t?`
9
+ The page has form fields the user may need to fill.`:""}
10
+
11
+ User task: ${a}
12
+
13
+ Action plan:`,i=await c.prompt(r);return c.destroy(),i?.trim()||""}async function H(n,a){let{askPageWithTransformers:t}=await import("./transformers-rag-HW4QKA5T.mjs");return(await t(`How do I: ${a}`)).answer||"I could not create a plan for this task."}async function S(n,a,t){if(!n.trim())return{success:!1,steps:[],error:"Please tell me what you want to do."};if(!a)return{success:!1,steps:[],error:"No AI engine available on this device."};let o=[],l=(c,e="info")=>{let r={text:c,type:e};o.push(r),t(r)};try{l("\u{1F4D6} Reading page content...","info");let c=T(),e=x(),r=e.length>0;c.length<50&&l("\u26A0\uFE0F Page content is very limited. This may be a static image page.","error"),l(r?`\u{1F4CB} Found ${e.length} form field${e.length!==1?"s":""} on this page`:"\u{1F4C4} No form fields found \u2014 this appears to be a content page","info"),l("\u{1F916} Creating action plan...","info");let i="";try{a==="gemini"?i=await M(c,n,r):i=await H(c,n)}catch{i=r?`1. Locate the form on this page
14
+ 2. Fill each required field
15
+ 3. Review your answers
16
+ 4. Submit the form`:`1. Read the page carefully
17
+ 2. Find the section relevant to your task
18
+ 3. Follow the on-page instructions`}if(i&&(l("\u2705 Your action plan:","success"),i.split(/\n/).map(s=>s.replace(/\*\*/g,"").replace(/\*/g,"").trim()).filter(s=>s.length>5).slice(0,6).forEach(s=>l(` ${s}`,"action"))),r){let s=e[0];l(`\u{1F3AF} First field: "${s.label}"${s.required?" \u2605 required":""}`,"field"),L(s.element),e.length>1&&l(`\u{1F4DD} All ${e.length} fields: ${e.map(u=>u.label).join(" \u2192 ")}`,"info")}else{let s=n.toLowerCase().split(/\s+/).filter(m=>m.length>3),u=!1;for(let m of s)if(A(m)){l(`\u{1F3AF} Scrolled to relevant section: "${m}"`,"action"),u=!0;break}u||l("\u{1F4A1} Scroll through the page to find what you need.","info")}return l("\u2705 Ready. Follow the steps above. Ask me again if you need more help.","success"),{success:!0,steps:o}}catch(c){let e=c instanceof Error?c.message:"Agent error.";return l(`\u26A0\uFE0F ${e}`,"error"),{success:!1,steps:o,error:e}}}export{T as getPageText,L as highlightField,S as runAgent,x as scanFormFields,A as scrollToSection};
package/dist/index.d.mts CHANGED
@@ -97,8 +97,9 @@ interface YuktAIWrapperProps {
97
97
  children: ReactNode;
98
98
  config?: Partial<A11yConfig>;
99
99
  showRag?: boolean;
100
+ showAgent?: boolean;
100
101
  }
101
- declare function YuktAIWrapper({ position, children, config: configOverrides, showRag, }: YuktAIWrapperProps): react_jsx_runtime.JSX.Element;
102
+ declare function YuktAIWrapper({ position, children, config: configOverrides, showRag, showAgent, }: YuktAIWrapperProps): react_jsx_runtime.JSX.Element;
102
103
 
103
104
  declare const aiPlugin: {
104
105
  name: string;
package/dist/index.d.ts CHANGED
@@ -97,8 +97,9 @@ interface YuktAIWrapperProps {
97
97
  children: ReactNode;
98
98
  config?: Partial<A11yConfig>;
99
99
  showRag?: boolean;
100
+ showAgent?: boolean;
100
101
  }
101
- declare function YuktAIWrapper({ position, children, config: configOverrides, showRag, }: YuktAIWrapperProps): react_jsx_runtime.JSX.Element;
102
+ declare function YuktAIWrapper({ position, children, config: configOverrides, showRag, showAgent, }: YuktAIWrapperProps): react_jsx_runtime.JSX.Element;
102
103
 
103
104
  declare const aiPlugin: {
104
105
  name: string;