@yuktishaalaa/yuktai 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";"use client";var N=Object.create;var v=Object.defineProperty;var $=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var n in t)v(e,n,{get:t[n],enumerable:!0})},F=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of O(t))!q.call(e,o)&&o!==n&&v(e,o,{get:()=>t[o],enumerable:!(i=$(t,o))||i.enumerable});return e};var E=(e,t,n)=>(n=e!=null?N(W(e)):{},F(t||!e||!e.__esModule?v(n,"default",{value:e,enumerable:!0}):n,e)),H=e=>F(v({},"__esModule",{value:!0}),e);var U={};D(U,{YuktAI:()=>B,YuktAIWrapper:()=>S,default:()=>V});module.exports=H(U);var k=class{plugins=new Map;register(t,n){if(!n||typeof n.execute!="function")throw new Error(`Invalid plugin: ${t}`);this.plugins.set(t,n)}use(t){return this.plugins.get(t)}async run(t,n){try{let i=this.use(t);if(!i)throw new Error(`Plugin not found: ${t}`);return await i.execute(n)}catch(i){throw console.error(`[YuktAI Runtime Error in ${t}]:`,i),i}}getPlugins(){return Array.from(this.plugins.keys())}};var w={name:"ai.text",async execute(e){return`\u{1F916} YuktAI says: ${e}`}};var C={name:"voice.text",async execute(e){return!e||e.trim()===""?"\u{1F3A4} No speech detected":`\u{1F3A4} You said: ${e}`}};var M=E(require("tesseract.js"),1),b=null,I=null;function z(e){let t=new TextDecoder("utf-8",{fatal:!1}).decode(new Uint8Array(e.slice(0,2e3)));return/[\u0C00-\u0C7F]/.test(t)?"tel":/[\u0900-\u097F]/.test(t)?"hin":/[\u0B80-\u0BFF]/.test(t)?"tam":/[\u4E00-\u9FFF]/.test(t)?"chi_sim":/[\u3040-\u30FF]/.test(t)?"jpn":/[\u0600-\u06FF]/.test(t)?"ara":/[\u0400-\u04FF]/.test(t)?"rus":"eng"}async function Y(e){return b&&I===e||(b&&(await b.terminate(),b=null),b=await M.default.createWorker({langPath:"/tessdata",logger:()=>{}}),await b.loadLanguage(e),await b.initialize(e),I=e),b}var R={name:"image.ocr.smart",async execute(e){try{if(!e?.file)return"\u274C No file provided";let t=e.file instanceof Blob?e.file:new Blob([e.file],{type:e.type??"image/png"}),n=e.lang||z(await t.arrayBuffer())||"eng",i=await Y(n),{data:o}=await i.recognize(t),a=o.text?.trim();return a?{language:n,confidence:Math.round(o.confidence??0),text:a}:"\u26A0\uFE0F No text detected"}catch(t){return console.error("[ocrSmartPlugin]",t),"\u274C OCR failed"}}};var p={name:"ui.a11y.pro",version:"1.0.1",observer:null,async execute(e){if(!e?.enabled)return this.stopObserver(),"yuktai-a11y: disabled";try{let t=this.applyFixes(e);if(e.autoFix&&this.startObserver(e),this.ensureLiveRegion(),this.announce(`Accessibility active. ${t.fixed} fixes applied.`),e.validate){let n=this.validatePage();return{...t,validation:n}}return t}catch(t){return console.error("WCAG Plugin execution error:",t),{fixed:0,scanned:0,errors:[t.message]}}},applyFixes(e){let t={fixed:0,scanned:0,errors:[]};if(typeof document>"u")return t;let n=e.root||document,i=e.skipFixes||[];try{let o=n.querySelectorAll("a,button,input,select,textarea,img,table,[onclick],[tabindex],h1,h2,h3,h4,h5,h6,iframe,video,audio,[role],[aria-label],[aria-labelledby]");t.scanned=o.length;let a=0;if(o.forEach(m=>{try{let r=m,s=r.tagName.toLowerCase();if(!i.includes("headings")&&/^h[1-6]$/.test(s)){let u=parseInt(s[1]);u>a+1&&a!==0&&(r.setAttribute("aria-level",String(a+1)),t.fixed++),a=u}if(!i.includes("buttons")&&(s==="a"||s==="button")&&!r.innerText.trim()&&!r.getAttribute("aria-label")){let u=r.getAttribute("title")||r.getAttribute("aria-label")||"Interactive element";r.setAttribute("aria-label",u),t.fixed++}if(i.includes("clickables")||(r.hasAttribute("onclick")||typeof window<"u"&&window.getComputedStyle(r).cursor==="pointer")&&!["button","a","input","select","textarea"].includes(s)&&(r.getAttribute("role")||(r.setAttribute("role","button"),t.fixed++),r.tabIndex<0&&(r.tabIndex=0,t.fixed++),r._yuktKeyBound||(r.addEventListener("keydown",f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),r.click())}),r._yuktKeyBound=!0)),!i.includes("forms")&&["input","select","textarea"].includes(s)){if(!r.getAttribute("aria-label")&&!r.getAttribute("aria-labelledby")){let u=r.getAttribute("placeholder")||r.getAttribute("name")||r.getAttribute("title")||s;r.setAttribute("aria-label",u),t.fixed++}r.hasAttribute("required")&&!r.getAttribute("aria-required")&&(r.setAttribute("aria-required","true"),t.fixed++)}!i.includes("images")&&s==="img"&&!r.hasAttribute("alt")&&(r.setAttribute("alt",""),r.setAttribute("aria-hidden","true"),t.fixed++),!i.includes("tables")&&s==="table"&&!m.querySelector("th")&&(r.getAttribute("role")||(r.setAttribute("role","grid"),t.fixed++)),!i.includes("media")&&["video","audio"].includes(s)&&(r.hasAttribute("controls")||(r.setAttribute("controls","true"),t.fixed++)),!i.includes("iframes")&&s==="iframe"&&!r.getAttribute("title")&&(r.setAttribute("title","Embedded content"),t.fixed++)}catch(r){t.errors.push(`Error fixing element ${m.tagName}: ${r.message}`)}}),e.highContrast&&(document.documentElement.style.filter="contrast(1.15) brightness(1.05)"),e.reduceMotion&&(document.documentElement.style.scrollBehavior="auto",!document.getElementById("yukt-reduce-motion"))){let m=document.createElement("style");m.id="yukt-reduce-motion",m.textContent="*, *::before, *::after { transition: none !important; animation: none !important; }",document.head.appendChild(m)}}catch(o){t.errors.push(`General error in applyFixes: ${o.message}`)}return t},startObserver(e){this.observer||typeof document>"u"||(this.observer=new MutationObserver(t=>{clearTimeout(this._mutationTimer),this._mutationTimer=setTimeout(()=>{t.forEach(n=>{n.addedNodes.forEach(i=>{i instanceof HTMLElement&&this.applyFixes({...e,root:i})})})},100)}),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!1}))},stopObserver(){this.observer&&(this.observer.disconnect(),this.observer=null),this._mutationTimer&&clearTimeout(this._mutationTimer)},cleanup(){this.stopObserver(),this.removeLiveRegion();let e=document.getElementById("yukt-reduce-motion");e&&e.remove(),typeof document<"u"&&(document.documentElement.style.filter="",document.documentElement.style.scrollBehavior="")},ensureLiveRegion(){if(typeof document>"u"||document.getElementById("yukt-sr-announcer"))return;let e=document.createElement("div");e.id="yukt-sr-announcer",e.setAttribute("aria-live","polite"),e.setAttribute("aria-atomic","true"),e.style.cssText="position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden;",document.body.appendChild(e)},removeLiveRegion(){if(typeof document>"u")return;let e=document.getElementById("yukt-sr-announcer");e&&e.remove()},announce(e){if(typeof document>"u")return;let t=document.getElementById("yukt-sr-announcer");t&&(t.textContent="",setTimeout(()=>{t.textContent=e},50))},checkContrast(e,t,n=4.5){try{return(o=>{let a=document.createElement("div");a.style.color=o,a.style.backgroundColor=t,document.body.appendChild(a);let m=window.getComputedStyle(a).color,r=window.getComputedStyle(a).backgroundColor;a.remove();let s=m.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/),u=r.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(!s||!u)return 1;let f=this.rgbToLuminance(parseInt(s[1]),parseInt(s[2]),parseInt(s[3])),x=this.rgbToLuminance(parseInt(u[1]),parseInt(u[2]),parseInt(u[3])),c=Math.max(f,x),g=Math.min(f,x);return(c+.05)/(g+.05)})(e)>=n}catch(i){return console.warn("Contrast check failed:",i),!0}},validatePage(){let e=[],t=[];if(typeof document>"u")return{score:0,issues:["Server-side rendering detected"],recommendations:[]};document.documentElement.getAttribute("lang")||(e.push("Missing lang attribute on html element"),t.push('Add lang attribute to <html> element (e.g., <html lang="en">)')),document.title||(e.push("Missing page title"),t.push("Add a descriptive <title> element")),document.querySelectorAll('a,button,input,select,textarea,[tabindex]:not([tabindex="-1"])').length===0&&(e.push("No keyboard-focusable elements found"),t.push("Ensure interactive elements are keyboard accessible"));let i=document.querySelectorAll("img:not([alt])");i.length>0&&(e.push(`${i.length} images missing alt text`),t.push("Add descriptive alt text to all images"));let o=Array.from(document.querySelectorAll("h1,h2,h3,h4,h5,h6")),a=0;return o.forEach((r,s)=>{let u=parseInt(r.tagName[1]);s>0&&u>a+1&&(e.push(`Skipped heading level: ${r.tagName} after h${a}`),t.push("Ensure heading hierarchy is sequential")),a=u}),{score:Math.max(0,100-e.length*10),issues:e,recommendations:t}}};var h=E(require("react"),1),T=E(require("react-dom/client"),1),L=require("react/jsx-runtime");function A(e){if(!h.default.isValidElement(e))return e;let t=e,n={...t.props};if((t.type==="input"||t.type==="textarea"||t.type==="select")&&!n["aria-label"]&&!n["aria-labelledby"]&&(n["aria-label"]=n.placeholder||n.name||`${t.type} field`),t.type==="button"&&!n["aria-label"]&&!n.children&&(n["aria-label"]="Interactive button"),t.type==="img"&&(n.alt||(n.alt="",n["aria-hidden"]="true")),(t.type==="div"||t.type==="span")&&n.onClick){n.role="button",n.tabIndex=0;let o=n.onClick;n.onKeyDown=a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),o(a))}}let i=h.default.Children.map(n.children,o=>h.default.isValidElement(o)?A(o):o);return h.default.cloneElement(t,n,i)}function _(e,t){let n=document.querySelector(t);if(!n)throw new Error(`[YuktAI] Target container not found: ${t}`);let i=A(e);T.default.createRoot(n).render((0,L.jsx)(h.default.StrictMode,{children:i}))}var d=require("react");var l=require("react/jsx-runtime"),K={enabled:!0,highContrast:!1,reduceMotion:!1,autoFix:!0,dyslexiaFont:!1,fontScale:100};function S({children:e}){let t=e?A(e):null,[n,i]=(0,d.useState)(!1),[o,a]=(0,d.useState)(K),[m,r]=(0,d.useState)(!1),s=(0,d.useRef)(null),u=(0,d.useRef)(null),f=(c,g)=>a(y=>({...y,[c]:g}));(0,d.useEffect)(()=>((async()=>(await p.execute({enabled:!0,autoFix:!0}),r(!0)))(),()=>p.stopObserver()),[]),(0,d.useEffect)(()=>{if(!n)return;let c=g=>{s.current&&!s.current.contains(g.target)&&u.current&&!u.current.contains(g.target)&&i(!1)};return document.addEventListener("mousedown",c),()=>document.removeEventListener("mousedown",c)},[n]);let x=(0,d.useCallback)(async()=>{let c={enabled:!0,highContrast:o.highContrast,reduceMotion:o.reduceMotion,autoFix:o.autoFix};await p.execute(c),document.documentElement.style.fontSize=`${o.fontScale}%`;let g=document.getElementById("yuktai-dyslexia");if(o.dyslexiaFont){if(!g){let y=document.createElement("style");y.id="yuktai-dyslexia",y.textContent="body, body * { font-family: 'Georgia', serif !important; letter-spacing: 0.05em !important; line-height: 1.8 !important; }",document.head.appendChild(y)}}else g?.remove();i(!1)},[o]);return(0,l.jsxs)(l.Fragment,{children:[t,(0,l.jsx)("button",{ref:u,onClick:()=>i(!n),style:{position:"fixed",bottom:20,right:20,width:50,height:50,borderRadius:"50%",background:"#0d9488",color:"#fff",border:"none",cursor:"pointer",zIndex:9999,boxShadow:"0 4px 12px rgba(0,0,0,0.15)"},children:(0,l.jsx)("svg",{viewBox:"0 0 24 24",width:"24",height:"24",fill:"currentColor",children:(0,l.jsx)("path",{d:"M12 2c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2zm9 7h-6v13h-2v-6h-2v6H9V9H3V7h18v2z"})})}),n&&(0,l.jsxs)("div",{ref:s,style:{position:"fixed",bottom:80,right:20,width:280,background:"#fff",borderRadius:12,padding:16,boxShadow:"0 10px 25px rgba(0,0,0,0.1)",zIndex:9999,border:"1px solid #eee"},children:[(0,l.jsx)("h4",{style:{margin:"0 0 15px",color:"#333"},children:"Accessibility Menu"}),(0,l.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[(0,l.jsxs)("label",{style:{fontSize:13,display:"flex",justifyContent:"space-between"},children:["High Contrast ",(0,l.jsx)("input",{type:"checkbox",checked:o.highContrast,onChange:c=>f("highContrast",c.target.checked)})]}),(0,l.jsxs)("label",{style:{fontSize:13,display:"flex",justifyContent:"space-between"},children:["Dyslexia Font ",(0,l.jsx)("input",{type:"checkbox",checked:o.dyslexiaFont,onChange:c=>f("dyslexiaFont",c.target.checked)})]}),(0,l.jsx)("button",{onClick:x,style:{marginTop:10,padding:8,background:"#0d9488",color:"#fff",border:"none",borderRadius:4,cursor:"pointer"},children:"Save Settings"})]})]})]})}function G(){if(!globalThis.__yuktai_runtime__){let e=new k;e.register(w.name,w),e.register(C.name,C),e.register(R.name,R),e.register(p.name,p),globalThis.__yuktai_runtime__=e}return globalThis.__yuktai_runtime__}var P=G(),B={render:_,list(){return P.getPlugins()},use(e){return P.use(e)}},V=B;0&&(module.exports={YuktAI,YuktAIWrapper});
1
+ "use strict";"use client";var B=Object.create;var y=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var W=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var q=(e,t)=>{for(var n in t)y(e,n,{get:t[n],enumerable:!0})},I=(e,t,n,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of $(t))!O.call(e,o)&&o!==n&&y(e,o,{get:()=>t[o],enumerable:!(i=N(t,o))||i.enumerable});return e};var A=(e,t,n)=>(n=e!=null?B(W(e)):{},I(t||!e||!e.__esModule?y(n,"default",{value:e,enumerable:!0}):n,e)),z=e=>I(y({},"__esModule",{value:!0}),e);var V={};q(V,{YuktAI:()=>_,YuktAIWrapper:()=>R,default:()=>G});module.exports=z(V);var x=class{plugins=new Map;register(t,n){if(!n||typeof n.execute!="function")throw new Error(`Invalid plugin: ${t}`);this.plugins.set(t,n)}use(t){return this.plugins.get(t)}async run(t,n){try{let i=this.use(t);if(!i)throw new Error(`Plugin not found: ${t}`);return await i.execute(n)}catch(i){throw console.error(`[YuktAI Runtime Error in ${t}]:`,i),i}}getPlugins(){return Array.from(this.plugins.keys())}};var w={name:"ai.text",async execute(e){return`\u{1F916} YuktAI says: ${e}`}};var C={name:"voice.text",async execute(e){return!e||e.trim()===""?"\u{1F3A4} No speech detected":`\u{1F3A4} You said: ${e}`}};var S=A(require("tesseract.js"),1),p=null,F=null;function D(e){let t=new TextDecoder("utf-8",{fatal:!1}).decode(new Uint8Array(e.slice(0,2e3)));return/[\u0C00-\u0C7F]/.test(t)?"tel":/[\u0900-\u097F]/.test(t)?"hin":/[\u0B80-\u0BFF]/.test(t)?"tam":/[\u4E00-\u9FFF]/.test(t)?"chi_sim":/[\u3040-\u30FF]/.test(t)?"jpn":/[\u0600-\u06FF]/.test(t)?"ara":/[\u0400-\u04FF]/.test(t)?"rus":"eng"}async function H(e){return p&&F===e||(p&&(await p.terminate(),p=null),p=await S.default.createWorker({langPath:"/tessdata",logger:()=>{}}),await p.loadLanguage(e),await p.initialize(e),F=e),p}var E={name:"image.ocr.smart",async execute(e){try{if(!e?.file)return"\u274C No file provided";let t=e.file instanceof Blob?e.file:new Blob([e.file],{type:e.type??"image/png"}),n=e.lang||D(await t.arrayBuffer())||"eng",i=await H(n),{data:o}=await i.recognize(t),a=o.text?.trim();return a?{language:n,confidence:Math.round(o.confidence??0),text:a}:"\u26A0\uFE0F No text detected"}catch(t){return console.error("[ocrSmartPlugin]",t),"\u274C OCR failed"}}};var b={name:"ui.a11y.pro",version:"1.0.1",observer:null,async execute(e){if(!e?.enabled)return this.stopObserver(),"yuktai-a11y: disabled";try{let t=this.applyFixes(e);if(e.autoFix&&this.startObserver(e),this.ensureLiveRegion(),this.announce(`Accessibility active. ${t.fixed} fixes applied.`),e.validate){let n=this.validatePage();return{...t,validation:n}}return t}catch(t){return console.error("WCAG Plugin execution error:",t),{fixed:0,scanned:0,errors:[t.message]}}},applyFixes(e){let t={fixed:0,scanned:0,errors:[]};if(typeof document>"u")return t;let n=e.root||document,i=e.skipFixes||[];try{let o=n.querySelectorAll("a,button,input,select,textarea,img,table,[onclick],[tabindex],h1,h2,h3,h4,h5,h6,iframe,video,audio,[role],[aria-label],[aria-labelledby]");t.scanned=o.length;let a=0;if(o.forEach(d=>{try{let r=d,l=r.tagName.toLowerCase();if(!i.includes("headings")&&/^h[1-6]$/.test(l)){let u=parseInt(l[1]);u>a+1&&a!==0&&(r.setAttribute("aria-level",String(a+1)),t.fixed++),a=u}if(!i.includes("buttons")&&(l==="a"||l==="button")&&!r.innerText.trim()&&!r.getAttribute("aria-label")){let u=r.getAttribute("title")||r.getAttribute("aria-label")||"Interactive element";r.setAttribute("aria-label",u),t.fixed++}if(i.includes("clickables")||(r.hasAttribute("onclick")||typeof window<"u"&&window.getComputedStyle(r).cursor==="pointer")&&!["button","a","input","select","textarea"].includes(l)&&(r.getAttribute("role")||(r.setAttribute("role","button"),t.fixed++),r.tabIndex<0&&(r.tabIndex=0,t.fixed++),r._yuktKeyBound||(r.addEventListener("keydown",s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),r.click())}),r._yuktKeyBound=!0)),!i.includes("forms")&&["input","select","textarea"].includes(l)){if(!r.getAttribute("aria-label")&&!r.getAttribute("aria-labelledby")){let u=r.getAttribute("placeholder")||r.getAttribute("name")||r.getAttribute("title")||l;r.setAttribute("aria-label",u),t.fixed++}r.hasAttribute("required")&&!r.getAttribute("aria-required")&&(r.setAttribute("aria-required","true"),t.fixed++)}!i.includes("images")&&l==="img"&&!r.hasAttribute("alt")&&(r.setAttribute("alt",""),r.setAttribute("aria-hidden","true"),t.fixed++),!i.includes("tables")&&l==="table"&&!d.querySelector("th")&&(r.getAttribute("role")||(r.setAttribute("role","grid"),t.fixed++)),!i.includes("media")&&["video","audio"].includes(l)&&(r.hasAttribute("controls")||(r.setAttribute("controls","true"),t.fixed++)),!i.includes("iframes")&&l==="iframe"&&!r.getAttribute("title")&&(r.setAttribute("title","Embedded content"),t.fixed++)}catch(r){t.errors.push(`Error fixing element ${d.tagName}: ${r.message}`)}}),e.highContrast&&(document.documentElement.style.filter="contrast(1.15) brightness(1.05)"),e.reduceMotion&&(document.documentElement.style.scrollBehavior="auto",!document.getElementById("yukt-reduce-motion"))){let d=document.createElement("style");d.id="yukt-reduce-motion",d.textContent="*, *::before, *::after { transition: none !important; animation: none !important; }",document.head.appendChild(d)}}catch(o){t.errors.push(`General error in applyFixes: ${o.message}`)}return t},startObserver(e){this.observer||typeof document>"u"||(this.observer=new MutationObserver(t=>{clearTimeout(this._mutationTimer),this._mutationTimer=setTimeout(()=>{t.forEach(n=>{n.addedNodes.forEach(i=>{i instanceof HTMLElement&&this.applyFixes({...e,root:i})})})},100)}),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!1}))},stopObserver(){this.observer&&(this.observer.disconnect(),this.observer=null),this._mutationTimer&&clearTimeout(this._mutationTimer)},cleanup(){this.stopObserver(),this.removeLiveRegion();let e=document.getElementById("yukt-reduce-motion");e&&e.remove(),typeof document<"u"&&(document.documentElement.style.filter="",document.documentElement.style.scrollBehavior="")},ensureLiveRegion(){if(typeof document>"u"||document.getElementById("yukt-sr-announcer"))return;let e=document.createElement("div");e.id="yukt-sr-announcer",e.setAttribute("aria-live","polite"),e.setAttribute("aria-atomic","true"),e.style.cssText="position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden;",document.body.appendChild(e)},removeLiveRegion(){if(typeof document>"u")return;let e=document.getElementById("yukt-sr-announcer");e&&e.remove()},announce(e){if(typeof document>"u")return;let t=document.getElementById("yukt-sr-announcer");t&&(t.textContent="",setTimeout(()=>{t.textContent=e},50))},checkContrast(e,t,n=4.5){try{return(o=>{let a=document.createElement("div");a.style.color=o,a.style.backgroundColor=t,document.body.appendChild(a);let d=window.getComputedStyle(a).color,r=window.getComputedStyle(a).backgroundColor;a.remove();let l=d.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/),u=r.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(!l||!u)return 1;let s=this.rgbToLuminance(parseInt(l[1]),parseInt(l[2]),parseInt(l[3])),f=this.rgbToLuminance(parseInt(u[1]),parseInt(u[2]),parseInt(u[3])),g=Math.max(s,f),k=Math.min(s,f);return(g+.05)/(k+.05)})(e)>=n}catch(i){return console.warn("Contrast check failed:",i),!0}},validatePage(){let e=[],t=[];if(typeof document>"u")return{score:0,issues:["Server-side rendering detected"],recommendations:[]};document.documentElement.getAttribute("lang")||(e.push("Missing lang attribute on html element"),t.push('Add lang attribute to <html> element (e.g., <html lang="en">)')),document.title||(e.push("Missing page title"),t.push("Add a descriptive <title> element")),document.querySelectorAll('a,button,input,select,textarea,[tabindex]:not([tabindex="-1"])').length===0&&(e.push("No keyboard-focusable elements found"),t.push("Ensure interactive elements are keyboard accessible"));let i=document.querySelectorAll("img:not([alt])");i.length>0&&(e.push(`${i.length} images missing alt text`),t.push("Add descriptive alt text to all images"));let o=Array.from(document.querySelectorAll("h1,h2,h3,h4,h5,h6")),a=0;return o.forEach((r,l)=>{let u=parseInt(r.tagName[1]);l>0&&u>a+1&&(e.push(`Skipped heading level: ${r.tagName} after h${a}`),t.push("Ensure heading hierarchy is sequential")),a=u}),{score:Math.max(0,100-e.length*10),issues:e,recommendations:t}}};var h=A(require("react"),1),M=A(require("react-dom/client"),1),T=require("react/jsx-runtime");function v(e){if(!h.default.isValidElement(e))return e;let t=e,n={...t.props};if((t.type==="input"||t.type==="textarea"||t.type==="select")&&!n["aria-label"]&&!n["aria-labelledby"]&&(n["aria-label"]=n.placeholder||n.name||`${t.type} field`),t.type==="button"&&!n["aria-label"]&&!n.children&&(n["aria-label"]="Interactive button"),t.type==="img"&&(n.alt||(n.alt="",n["aria-hidden"]="true")),(t.type==="div"||t.type==="span")&&n.onClick){n.role="button",n.tabIndex=0;let o=n.onClick;n.onKeyDown=a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),o(a))}}let i=h.default.Children.map(n.children,o=>h.default.isValidElement(o)?v(o):o);return h.default.cloneElement(t,n,i)}function P(e,t){let n=document.querySelector(t);if(!n)throw new Error(`[YuktAI] Target container not found: ${t}`);let i=v(e);M.default.createRoot(n).render((0,T.jsx)(h.default.StrictMode,{children:i}))}var m=require("react");var c=require("react/jsx-runtime"),Y={enabled:!0,highContrast:!1,reduceMotion:!1,autoFix:!0,dyslexiaFont:!1,fontScale:100};function R({children:e}){let t=e?v(e):null,[n,i]=(0,m.useState)(!1),[o,a]=(0,m.useState)(Y),d=(0,m.useRef)(null),r=(0,m.useRef)(null),l=(s,f)=>a(g=>({...g,[s]:f}));(0,m.useEffect)(()=>((async()=>await b.execute({enabled:!0,autoFix:!0}))(),()=>b.stopObserver()),[]),(0,m.useEffect)(()=>{if(!n)return;let s=f=>{let g=r.current?.contains(f.target),k=d.current?.contains(f.target);!g&&!k&&i(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[n]);let u=(0,m.useCallback)(async()=>{let s={enabled:!0,highContrast:o.highContrast,reduceMotion:o.reduceMotion,autoFix:o.autoFix};await b.execute(s),document.documentElement.style.fontSize=`${o.fontScale}%`;let f=document.getElementById("yuktai-dyslexia");if(o.dyslexiaFont){if(!f){let g=document.createElement("style");g.id="yuktai-dyslexia",g.textContent="body, body * { font-family: 'Georgia', serif !important; letter-spacing: 0.05em !important; line-height: 1.8 !important; }",document.head.appendChild(g)}}else f?.remove();i(!1)},[o]);return(0,c.jsxs)(c.Fragment,{children:[t,(0,c.jsx)("button",{ref:r,onClick:s=>{s.stopPropagation(),i(f=>!f)},"aria-label":"Accessibility Menu",style:{position:"fixed",bottom:20,right:20,width:56,height:56,borderRadius:"50%",background:"#0d9488",color:"#fff",border:"none",cursor:"pointer",zIndex:1e4,boxShadow:"0 4px 20px rgba(0,0,0,0.3)",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,c.jsx)("svg",{viewBox:"0 0 24 24",width:"32",height:"32",fill:"currentColor",style:{pointerEvents:"none"},children:(0,c.jsx)("path",{d:"M12 2c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2zm9 7h-6v13h-2v-6h-2v6H9V9H3V7h18v2z"})})}),n&&(0,c.jsxs)("div",{ref:d,onClick:s=>s.stopPropagation(),style:{position:"fixed",bottom:90,right:20,width:280,background:"#ffffff",borderRadius:16,padding:20,boxShadow:"0 10px 40px rgba(0,0,0,0.2)",zIndex:10001,border:"1px solid #e5e7eb",color:"#111827",fontFamily:"sans-serif"},children:[(0,c.jsx)("h4",{style:{margin:"0 0 15px",fontSize:18,fontWeight:600},children:"Accessibility Menu"}),(0,c.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[(0,c.jsxs)("label",{style:{fontSize:14,display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer"},children:["High Contrast",(0,c.jsx)("input",{type:"checkbox",style:{width:18,height:18},checked:o.highContrast,onChange:s=>l("highContrast",s.target.checked)})]}),(0,c.jsxs)("label",{style:{fontSize:14,display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer"},children:["Dyslexia Font",(0,c.jsx)("input",{type:"checkbox",style:{width:18,height:18},checked:o.dyslexiaFont,onChange:s=>l("dyslexiaFont",s.target.checked)})]}),(0,c.jsx)("button",{onClick:u,style:{marginTop:10,padding:"12px",background:"#0d9488",color:"#fff",border:"none",borderRadius:8,fontWeight:600,cursor:"pointer",transition:"background 0.2s"},children:"Apply Changes"})]})]})]})}function K(){if(!globalThis.__yuktai_runtime__){let e=new x;e.register(w.name,w),e.register(C.name,C),e.register(E.name,E),e.register(b.name,b),globalThis.__yuktai_runtime__=e}return globalThis.__yuktai_runtime__}var L=K(),_={render:P,list(){return L.getPlugins()},use(e){return L.use(e)}},G=_;0&&(module.exports={YuktAI,YuktAIWrapper});
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use client";var v=class{plugins=new Map;register(e,n){if(!n||typeof n.execute!="function")throw new Error(`Invalid plugin: ${e}`);this.plugins.set(e,n)}use(e){return this.plugins.get(e)}async run(e,n){try{let i=this.use(e);if(!i)throw new Error(`Plugin not found: ${e}`);return await i.execute(n)}catch(i){throw console.error(`[YuktAI Runtime Error in ${e}]:`,i),i}}getPlugins(){return Array.from(this.plugins.keys())}};var A={name:"ai.text",async execute(t){return`\u{1F916} YuktAI says: ${t}`}};var E={name:"voice.text",async execute(t){return!t||t.trim()===""?"\u{1F3A4} No speech detected":`\u{1F3A4} You said: ${t}`}};import _ from"tesseract.js";var f=null,R=null;function L(t){let e=new TextDecoder("utf-8",{fatal:!1}).decode(new Uint8Array(t.slice(0,2e3)));return/[\u0C00-\u0C7F]/.test(e)?"tel":/[\u0900-\u097F]/.test(e)?"hin":/[\u0B80-\u0BFF]/.test(e)?"tam":/[\u4E00-\u9FFF]/.test(e)?"chi_sim":/[\u3040-\u30FF]/.test(e)?"jpn":/[\u0600-\u06FF]/.test(e)?"ara":/[\u0400-\u04FF]/.test(e)?"rus":"eng"}async function P(t){return f&&R===t||(f&&(await f.terminate(),f=null),f=await _.createWorker({langPath:"/tessdata",logger:()=>{}}),await f.loadLanguage(t),await f.initialize(t),R=t),f}var w={name:"image.ocr.smart",async execute(t){try{if(!t?.file)return"\u274C No file provided";let e=t.file instanceof Blob?t.file:new Blob([t.file],{type:t.type??"image/png"}),n=t.lang||L(await e.arrayBuffer())||"eng",i=await P(n),{data:o}=await i.recognize(e),a=o.text?.trim();return a?{language:n,confidence:Math.round(o.confidence??0),text:a}:"\u26A0\uFE0F No text detected"}catch(e){return console.error("[ocrSmartPlugin]",e),"\u274C OCR failed"}}};var g={name:"ui.a11y.pro",version:"1.0.1",observer:null,async execute(t){if(!t?.enabled)return this.stopObserver(),"yuktai-a11y: disabled";try{let e=this.applyFixes(t);if(t.autoFix&&this.startObserver(t),this.ensureLiveRegion(),this.announce(`Accessibility active. ${e.fixed} fixes applied.`),t.validate){let n=this.validatePage();return{...e,validation:n}}return e}catch(e){return console.error("WCAG Plugin execution error:",e),{fixed:0,scanned:0,errors:[e.message]}}},applyFixes(t){let e={fixed:0,scanned:0,errors:[]};if(typeof document>"u")return e;let n=t.root||document,i=t.skipFixes||[];try{let o=n.querySelectorAll("a,button,input,select,textarea,img,table,[onclick],[tabindex],h1,h2,h3,h4,h5,h6,iframe,video,audio,[role],[aria-label],[aria-labelledby]");e.scanned=o.length;let a=0;if(o.forEach(c=>{try{let r=c,s=r.tagName.toLowerCase();if(!i.includes("headings")&&/^h[1-6]$/.test(s)){let u=parseInt(s[1]);u>a+1&&a!==0&&(r.setAttribute("aria-level",String(a+1)),e.fixed++),a=u}if(!i.includes("buttons")&&(s==="a"||s==="button")&&!r.innerText.trim()&&!r.getAttribute("aria-label")){let u=r.getAttribute("title")||r.getAttribute("aria-label")||"Interactive element";r.setAttribute("aria-label",u),e.fixed++}if(i.includes("clickables")||(r.hasAttribute("onclick")||typeof window<"u"&&window.getComputedStyle(r).cursor==="pointer")&&!["button","a","input","select","textarea"].includes(s)&&(r.getAttribute("role")||(r.setAttribute("role","button"),e.fixed++),r.tabIndex<0&&(r.tabIndex=0,e.fixed++),r._yuktKeyBound||(r.addEventListener("keydown",d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),r.click())}),r._yuktKeyBound=!0)),!i.includes("forms")&&["input","select","textarea"].includes(s)){if(!r.getAttribute("aria-label")&&!r.getAttribute("aria-labelledby")){let u=r.getAttribute("placeholder")||r.getAttribute("name")||r.getAttribute("title")||s;r.setAttribute("aria-label",u),e.fixed++}r.hasAttribute("required")&&!r.getAttribute("aria-required")&&(r.setAttribute("aria-required","true"),e.fixed++)}!i.includes("images")&&s==="img"&&!r.hasAttribute("alt")&&(r.setAttribute("alt",""),r.setAttribute("aria-hidden","true"),e.fixed++),!i.includes("tables")&&s==="table"&&!c.querySelector("th")&&(r.getAttribute("role")||(r.setAttribute("role","grid"),e.fixed++)),!i.includes("media")&&["video","audio"].includes(s)&&(r.hasAttribute("controls")||(r.setAttribute("controls","true"),e.fixed++)),!i.includes("iframes")&&s==="iframe"&&!r.getAttribute("title")&&(r.setAttribute("title","Embedded content"),e.fixed++)}catch(r){e.errors.push(`Error fixing element ${c.tagName}: ${r.message}`)}}),t.highContrast&&(document.documentElement.style.filter="contrast(1.15) brightness(1.05)"),t.reduceMotion&&(document.documentElement.style.scrollBehavior="auto",!document.getElementById("yukt-reduce-motion"))){let c=document.createElement("style");c.id="yukt-reduce-motion",c.textContent="*, *::before, *::after { transition: none !important; animation: none !important; }",document.head.appendChild(c)}}catch(o){e.errors.push(`General error in applyFixes: ${o.message}`)}return e},startObserver(t){this.observer||typeof document>"u"||(this.observer=new MutationObserver(e=>{clearTimeout(this._mutationTimer),this._mutationTimer=setTimeout(()=>{e.forEach(n=>{n.addedNodes.forEach(i=>{i instanceof HTMLElement&&this.applyFixes({...t,root:i})})})},100)}),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!1}))},stopObserver(){this.observer&&(this.observer.disconnect(),this.observer=null),this._mutationTimer&&clearTimeout(this._mutationTimer)},cleanup(){this.stopObserver(),this.removeLiveRegion();let t=document.getElementById("yukt-reduce-motion");t&&t.remove(),typeof document<"u"&&(document.documentElement.style.filter="",document.documentElement.style.scrollBehavior="")},ensureLiveRegion(){if(typeof document>"u"||document.getElementById("yukt-sr-announcer"))return;let t=document.createElement("div");t.id="yukt-sr-announcer",t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.cssText="position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden;",document.body.appendChild(t)},removeLiveRegion(){if(typeof document>"u")return;let t=document.getElementById("yukt-sr-announcer");t&&t.remove()},announce(t){if(typeof document>"u")return;let e=document.getElementById("yukt-sr-announcer");e&&(e.textContent="",setTimeout(()=>{e.textContent=t},50))},checkContrast(t,e,n=4.5){try{return(o=>{let a=document.createElement("div");a.style.color=o,a.style.backgroundColor=e,document.body.appendChild(a);let c=window.getComputedStyle(a).color,r=window.getComputedStyle(a).backgroundColor;a.remove();let s=c.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/),u=r.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(!s||!u)return 1;let d=this.rgbToLuminance(parseInt(s[1]),parseInt(s[2]),parseInt(s[3])),x=this.rgbToLuminance(parseInt(u[1]),parseInt(u[2]),parseInt(u[3])),l=Math.max(d,x),m=Math.min(d,x);return(l+.05)/(m+.05)})(t)>=n}catch(i){return console.warn("Contrast check failed:",i),!0}},validatePage(){let t=[],e=[];if(typeof document>"u")return{score:0,issues:["Server-side rendering detected"],recommendations:[]};document.documentElement.getAttribute("lang")||(t.push("Missing lang attribute on html element"),e.push('Add lang attribute to <html> element (e.g., <html lang="en">)')),document.title||(t.push("Missing page title"),e.push("Add a descriptive <title> element")),document.querySelectorAll('a,button,input,select,textarea,[tabindex]:not([tabindex="-1"])').length===0&&(t.push("No keyboard-focusable elements found"),e.push("Ensure interactive elements are keyboard accessible"));let i=document.querySelectorAll("img:not([alt])");i.length>0&&(t.push(`${i.length} images missing alt text`),e.push("Add descriptive alt text to all images"));let o=Array.from(document.querySelectorAll("h1,h2,h3,h4,h5,h6")),a=0;return o.forEach((r,s)=>{let u=parseInt(r.tagName[1]);s>0&&u>a+1&&(t.push(`Skipped heading level: ${r.tagName} after h${a}`),e.push("Ensure heading hierarchy is sequential")),a=u}),{score:Math.max(0,100-t.length*10),issues:t,recommendations:e}}};import h from"react";import B from"react-dom/client";import{jsx as N}from"react/jsx-runtime";function k(t){if(!h.isValidElement(t))return t;let e=t,n={...e.props};if((e.type==="input"||e.type==="textarea"||e.type==="select")&&!n["aria-label"]&&!n["aria-labelledby"]&&(n["aria-label"]=n.placeholder||n.name||`${e.type} field`),e.type==="button"&&!n["aria-label"]&&!n.children&&(n["aria-label"]="Interactive button"),e.type==="img"&&(n.alt||(n.alt="",n["aria-hidden"]="true")),(e.type==="div"||e.type==="span")&&n.onClick){n.role="button",n.tabIndex=0;let o=n.onClick;n.onKeyDown=a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),o(a))}}let i=h.Children.map(n.children,o=>h.isValidElement(o)?k(o):o);return h.cloneElement(e,n,i)}function S(t,e){let n=document.querySelector(e);if(!n)throw new Error(`[YuktAI] Target container not found: ${e}`);let i=k(t);B.createRoot(n).render(N(h.StrictMode,{children:i}))}import{useState as C,useEffect as F,useRef as I,useCallback as $}from"react";import{Fragment as W,jsx as b,jsxs as y}from"react/jsx-runtime";var O={enabled:!0,highContrast:!1,reduceMotion:!1,autoFix:!0,dyslexiaFont:!1,fontScale:100};function M({children:t}){let e=t?k(t):null,[n,i]=C(!1),[o,a]=C(O),[c,r]=C(!1),s=I(null),u=I(null),d=(l,m)=>a(p=>({...p,[l]:m}));F(()=>((async()=>(await g.execute({enabled:!0,autoFix:!0}),r(!0)))(),()=>g.stopObserver()),[]),F(()=>{if(!n)return;let l=m=>{s.current&&!s.current.contains(m.target)&&u.current&&!u.current.contains(m.target)&&i(!1)};return document.addEventListener("mousedown",l),()=>document.removeEventListener("mousedown",l)},[n]);let x=$(async()=>{let l={enabled:!0,highContrast:o.highContrast,reduceMotion:o.reduceMotion,autoFix:o.autoFix};await g.execute(l),document.documentElement.style.fontSize=`${o.fontScale}%`;let m=document.getElementById("yuktai-dyslexia");if(o.dyslexiaFont){if(!m){let p=document.createElement("style");p.id="yuktai-dyslexia",p.textContent="body, body * { font-family: 'Georgia', serif !important; letter-spacing: 0.05em !important; line-height: 1.8 !important; }",document.head.appendChild(p)}}else m?.remove();i(!1)},[o]);return y(W,{children:[e,b("button",{ref:u,onClick:()=>i(!n),style:{position:"fixed",bottom:20,right:20,width:50,height:50,borderRadius:"50%",background:"#0d9488",color:"#fff",border:"none",cursor:"pointer",zIndex:9999,boxShadow:"0 4px 12px rgba(0,0,0,0.15)"},children:b("svg",{viewBox:"0 0 24 24",width:"24",height:"24",fill:"currentColor",children:b("path",{d:"M12 2c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2zm9 7h-6v13h-2v-6h-2v6H9V9H3V7h18v2z"})})}),n&&y("div",{ref:s,style:{position:"fixed",bottom:80,right:20,width:280,background:"#fff",borderRadius:12,padding:16,boxShadow:"0 10px 25px rgba(0,0,0,0.1)",zIndex:9999,border:"1px solid #eee"},children:[b("h4",{style:{margin:"0 0 15px",color:"#333"},children:"Accessibility Menu"}),y("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[y("label",{style:{fontSize:13,display:"flex",justifyContent:"space-between"},children:["High Contrast ",b("input",{type:"checkbox",checked:o.highContrast,onChange:l=>d("highContrast",l.target.checked)})]}),y("label",{style:{fontSize:13,display:"flex",justifyContent:"space-between"},children:["Dyslexia Font ",b("input",{type:"checkbox",checked:o.dyslexiaFont,onChange:l=>d("dyslexiaFont",l.target.checked)})]}),b("button",{onClick:x,style:{marginTop:10,padding:8,background:"#0d9488",color:"#fff",border:"none",borderRadius:4,cursor:"pointer"},children:"Save Settings"})]})]})]})}function q(){if(!globalThis.__yuktai_runtime__){let t=new v;t.register(A.name,A),t.register(E.name,E),t.register(w.name,w),t.register(g.name,g),globalThis.__yuktai_runtime__=t}return globalThis.__yuktai_runtime__}var T=q(),D={render:S,list(){return T.getPlugins()},use(t){return T.use(t)}},de=D;export{D as YuktAI,M as YuktAIWrapper,de as default};
1
+ "use client";var y=class{plugins=new Map;register(e,r){if(!r||typeof r.execute!="function")throw new Error(`Invalid plugin: ${e}`);this.plugins.set(e,r)}use(e){return this.plugins.get(e)}async run(e,r){try{let i=this.use(e);if(!i)throw new Error(`Plugin not found: ${e}`);return await i.execute(r)}catch(i){throw console.error(`[YuktAI Runtime Error in ${e}]:`,i),i}}getPlugins(){return Array.from(this.plugins.keys())}};var k={name:"ai.text",async execute(t){return`\u{1F916} YuktAI says: ${t}`}};var A={name:"voice.text",async execute(t){return!t||t.trim()===""?"\u{1F3A4} No speech detected":`\u{1F3A4} You said: ${t}`}};import P from"tesseract.js";var m=null,C=null;function T(t){let e=new TextDecoder("utf-8",{fatal:!1}).decode(new Uint8Array(t.slice(0,2e3)));return/[\u0C00-\u0C7F]/.test(e)?"tel":/[\u0900-\u097F]/.test(e)?"hin":/[\u0B80-\u0BFF]/.test(e)?"tam":/[\u4E00-\u9FFF]/.test(e)?"chi_sim":/[\u3040-\u30FF]/.test(e)?"jpn":/[\u0600-\u06FF]/.test(e)?"ara":/[\u0400-\u04FF]/.test(e)?"rus":"eng"}async function L(t){return m&&C===t||(m&&(await m.terminate(),m=null),m=await P.createWorker({langPath:"/tessdata",logger:()=>{}}),await m.loadLanguage(t),await m.initialize(t),C=t),m}var w={name:"image.ocr.smart",async execute(t){try{if(!t?.file)return"\u274C No file provided";let e=t.file instanceof Blob?t.file:new Blob([t.file],{type:t.type??"image/png"}),r=t.lang||T(await e.arrayBuffer())||"eng",i=await L(r),{data:o}=await i.recognize(e),a=o.text?.trim();return a?{language:r,confidence:Math.round(o.confidence??0),text:a}:"\u26A0\uFE0F No text detected"}catch(e){return console.error("[ocrSmartPlugin]",e),"\u274C OCR failed"}}};var g={name:"ui.a11y.pro",version:"1.0.1",observer:null,async execute(t){if(!t?.enabled)return this.stopObserver(),"yuktai-a11y: disabled";try{let e=this.applyFixes(t);if(t.autoFix&&this.startObserver(t),this.ensureLiveRegion(),this.announce(`Accessibility active. ${e.fixed} fixes applied.`),t.validate){let r=this.validatePage();return{...e,validation:r}}return e}catch(e){return console.error("WCAG Plugin execution error:",e),{fixed:0,scanned:0,errors:[e.message]}}},applyFixes(t){let e={fixed:0,scanned:0,errors:[]};if(typeof document>"u")return e;let r=t.root||document,i=t.skipFixes||[];try{let o=r.querySelectorAll("a,button,input,select,textarea,img,table,[onclick],[tabindex],h1,h2,h3,h4,h5,h6,iframe,video,audio,[role],[aria-label],[aria-labelledby]");e.scanned=o.length;let a=0;if(o.forEach(c=>{try{let n=c,l=n.tagName.toLowerCase();if(!i.includes("headings")&&/^h[1-6]$/.test(l)){let u=parseInt(l[1]);u>a+1&&a!==0&&(n.setAttribute("aria-level",String(a+1)),e.fixed++),a=u}if(!i.includes("buttons")&&(l==="a"||l==="button")&&!n.innerText.trim()&&!n.getAttribute("aria-label")){let u=n.getAttribute("title")||n.getAttribute("aria-label")||"Interactive element";n.setAttribute("aria-label",u),e.fixed++}if(i.includes("clickables")||(n.hasAttribute("onclick")||typeof window<"u"&&window.getComputedStyle(n).cursor==="pointer")&&!["button","a","input","select","textarea"].includes(l)&&(n.getAttribute("role")||(n.setAttribute("role","button"),e.fixed++),n.tabIndex<0&&(n.tabIndex=0,e.fixed++),n._yuktKeyBound||(n.addEventListener("keydown",s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),n.click())}),n._yuktKeyBound=!0)),!i.includes("forms")&&["input","select","textarea"].includes(l)){if(!n.getAttribute("aria-label")&&!n.getAttribute("aria-labelledby")){let u=n.getAttribute("placeholder")||n.getAttribute("name")||n.getAttribute("title")||l;n.setAttribute("aria-label",u),e.fixed++}n.hasAttribute("required")&&!n.getAttribute("aria-required")&&(n.setAttribute("aria-required","true"),e.fixed++)}!i.includes("images")&&l==="img"&&!n.hasAttribute("alt")&&(n.setAttribute("alt",""),n.setAttribute("aria-hidden","true"),e.fixed++),!i.includes("tables")&&l==="table"&&!c.querySelector("th")&&(n.getAttribute("role")||(n.setAttribute("role","grid"),e.fixed++)),!i.includes("media")&&["video","audio"].includes(l)&&(n.hasAttribute("controls")||(n.setAttribute("controls","true"),e.fixed++)),!i.includes("iframes")&&l==="iframe"&&!n.getAttribute("title")&&(n.setAttribute("title","Embedded content"),e.fixed++)}catch(n){e.errors.push(`Error fixing element ${c.tagName}: ${n.message}`)}}),t.highContrast&&(document.documentElement.style.filter="contrast(1.15) brightness(1.05)"),t.reduceMotion&&(document.documentElement.style.scrollBehavior="auto",!document.getElementById("yukt-reduce-motion"))){let c=document.createElement("style");c.id="yukt-reduce-motion",c.textContent="*, *::before, *::after { transition: none !important; animation: none !important; }",document.head.appendChild(c)}}catch(o){e.errors.push(`General error in applyFixes: ${o.message}`)}return e},startObserver(t){this.observer||typeof document>"u"||(this.observer=new MutationObserver(e=>{clearTimeout(this._mutationTimer),this._mutationTimer=setTimeout(()=>{e.forEach(r=>{r.addedNodes.forEach(i=>{i instanceof HTMLElement&&this.applyFixes({...t,root:i})})})},100)}),this.observer.observe(document.body,{childList:!0,subtree:!0,attributes:!1}))},stopObserver(){this.observer&&(this.observer.disconnect(),this.observer=null),this._mutationTimer&&clearTimeout(this._mutationTimer)},cleanup(){this.stopObserver(),this.removeLiveRegion();let t=document.getElementById("yukt-reduce-motion");t&&t.remove(),typeof document<"u"&&(document.documentElement.style.filter="",document.documentElement.style.scrollBehavior="")},ensureLiveRegion(){if(typeof document>"u"||document.getElementById("yukt-sr-announcer"))return;let t=document.createElement("div");t.id="yukt-sr-announcer",t.setAttribute("aria-live","polite"),t.setAttribute("aria-atomic","true"),t.style.cssText="position:absolute;left:-9999px;width:1px;height:1px;overflow:hidden;",document.body.appendChild(t)},removeLiveRegion(){if(typeof document>"u")return;let t=document.getElementById("yukt-sr-announcer");t&&t.remove()},announce(t){if(typeof document>"u")return;let e=document.getElementById("yukt-sr-announcer");e&&(e.textContent="",setTimeout(()=>{e.textContent=t},50))},checkContrast(t,e,r=4.5){try{return(o=>{let a=document.createElement("div");a.style.color=o,a.style.backgroundColor=e,document.body.appendChild(a);let c=window.getComputedStyle(a).color,n=window.getComputedStyle(a).backgroundColor;a.remove();let l=c.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/),u=n.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(!l||!u)return 1;let s=this.rgbToLuminance(parseInt(l[1]),parseInt(l[2]),parseInt(l[3])),d=this.rgbToLuminance(parseInt(u[1]),parseInt(u[2]),parseInt(u[3])),f=Math.max(s,d),v=Math.min(s,d);return(f+.05)/(v+.05)})(t)>=r}catch(i){return console.warn("Contrast check failed:",i),!0}},validatePage(){let t=[],e=[];if(typeof document>"u")return{score:0,issues:["Server-side rendering detected"],recommendations:[]};document.documentElement.getAttribute("lang")||(t.push("Missing lang attribute on html element"),e.push('Add lang attribute to <html> element (e.g., <html lang="en">)')),document.title||(t.push("Missing page title"),e.push("Add a descriptive <title> element")),document.querySelectorAll('a,button,input,select,textarea,[tabindex]:not([tabindex="-1"])').length===0&&(t.push("No keyboard-focusable elements found"),e.push("Ensure interactive elements are keyboard accessible"));let i=document.querySelectorAll("img:not([alt])");i.length>0&&(t.push(`${i.length} images missing alt text`),e.push("Add descriptive alt text to all images"));let o=Array.from(document.querySelectorAll("h1,h2,h3,h4,h5,h6")),a=0;return o.forEach((n,l)=>{let u=parseInt(n.tagName[1]);l>0&&u>a+1&&(t.push(`Skipped heading level: ${n.tagName} after h${a}`),e.push("Ensure heading hierarchy is sequential")),a=u}),{score:Math.max(0,100-t.length*10),issues:t,recommendations:e}}};import b from"react";import _ from"react-dom/client";import{jsx as B}from"react/jsx-runtime";function x(t){if(!b.isValidElement(t))return t;let e=t,r={...e.props};if((e.type==="input"||e.type==="textarea"||e.type==="select")&&!r["aria-label"]&&!r["aria-labelledby"]&&(r["aria-label"]=r.placeholder||r.name||`${e.type} field`),e.type==="button"&&!r["aria-label"]&&!r.children&&(r["aria-label"]="Interactive button"),e.type==="img"&&(r.alt||(r.alt="",r["aria-hidden"]="true")),(e.type==="div"||e.type==="span")&&r.onClick){r.role="button",r.tabIndex=0;let o=r.onClick;r.onKeyDown=a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),o(a))}}let i=b.Children.map(r.children,o=>b.isValidElement(o)?x(o):o);return b.cloneElement(e,r,i)}function E(t,e){let r=document.querySelector(e);if(!r)throw new Error(`[YuktAI] Target container not found: ${e}`);let i=x(t);_.createRoot(r).render(B(b.StrictMode,{children:i}))}import{useState as R,useEffect as I,useRef as F,useCallback as N}from"react";import{Fragment as W,jsx as p,jsxs as h}from"react/jsx-runtime";var $={enabled:!0,highContrast:!1,reduceMotion:!1,autoFix:!0,dyslexiaFont:!1,fontScale:100};function S({children:t}){let e=t?x(t):null,[r,i]=R(!1),[o,a]=R($),c=F(null),n=F(null),l=(s,d)=>a(f=>({...f,[s]:d}));I(()=>((async()=>await g.execute({enabled:!0,autoFix:!0}))(),()=>g.stopObserver()),[]),I(()=>{if(!r)return;let s=d=>{let f=n.current?.contains(d.target),v=c.current?.contains(d.target);!f&&!v&&i(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[r]);let u=N(async()=>{let s={enabled:!0,highContrast:o.highContrast,reduceMotion:o.reduceMotion,autoFix:o.autoFix};await g.execute(s),document.documentElement.style.fontSize=`${o.fontScale}%`;let d=document.getElementById("yuktai-dyslexia");if(o.dyslexiaFont){if(!d){let f=document.createElement("style");f.id="yuktai-dyslexia",f.textContent="body, body * { font-family: 'Georgia', serif !important; letter-spacing: 0.05em !important; line-height: 1.8 !important; }",document.head.appendChild(f)}}else d?.remove();i(!1)},[o]);return h(W,{children:[e,p("button",{ref:n,onClick:s=>{s.stopPropagation(),i(d=>!d)},"aria-label":"Accessibility Menu",style:{position:"fixed",bottom:20,right:20,width:56,height:56,borderRadius:"50%",background:"#0d9488",color:"#fff",border:"none",cursor:"pointer",zIndex:1e4,boxShadow:"0 4px 20px rgba(0,0,0,0.3)",display:"flex",alignItems:"center",justifyContent:"center"},children:p("svg",{viewBox:"0 0 24 24",width:"32",height:"32",fill:"currentColor",style:{pointerEvents:"none"},children:p("path",{d:"M12 2c1.1 0 2 .9 2 2s-.9 2-2 2-2-.9-2-2 .9-2 2-2zm9 7h-6v13h-2v-6h-2v6H9V9H3V7h18v2z"})})}),r&&h("div",{ref:c,onClick:s=>s.stopPropagation(),style:{position:"fixed",bottom:90,right:20,width:280,background:"#ffffff",borderRadius:16,padding:20,boxShadow:"0 10px 40px rgba(0,0,0,0.2)",zIndex:10001,border:"1px solid #e5e7eb",color:"#111827",fontFamily:"sans-serif"},children:[p("h4",{style:{margin:"0 0 15px",fontSize:18,fontWeight:600},children:"Accessibility Menu"}),h("div",{style:{display:"flex",flexDirection:"column",gap:14},children:[h("label",{style:{fontSize:14,display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer"},children:["High Contrast",p("input",{type:"checkbox",style:{width:18,height:18},checked:o.highContrast,onChange:s=>l("highContrast",s.target.checked)})]}),h("label",{style:{fontSize:14,display:"flex",justifyContent:"space-between",alignItems:"center",cursor:"pointer"},children:["Dyslexia Font",p("input",{type:"checkbox",style:{width:18,height:18},checked:o.dyslexiaFont,onChange:s=>l("dyslexiaFont",s.target.checked)})]}),p("button",{onClick:u,style:{marginTop:10,padding:"12px",background:"#0d9488",color:"#fff",border:"none",borderRadius:8,fontWeight:600,cursor:"pointer",transition:"background 0.2s"},children:"Apply Changes"})]})]})]})}function O(){if(!globalThis.__yuktai_runtime__){let t=new y;t.register(k.name,k),t.register(A.name,A),t.register(w.name,w),t.register(g.name,g),globalThis.__yuktai_runtime__=t}return globalThis.__yuktai_runtime__}var M=O(),q={render:E,list(){return M.getPlugins()},use(t){return M.use(t)}},ce=q;export{q as YuktAI,S as YuktAIWrapper,ce as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuktishaalaa/yuktai",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Privacy-first, offline-first Indic language AI and Web Orchestrator",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -57,4 +57,4 @@
57
57
  "tsup": "^8.5.1",
58
58
  "typescript": "^5.0.0"
59
59
  }
60
- }
60
+ }