@yuktishaalaa/yuktai 1.0.8 → 1.0.11

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 D=Object.create;var A=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var z=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var H=(e,t)=>{for(var a in t)A(e,a,{get:t[a],enumerable:!0})},F=(e,t,a,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of $(t))!q.call(e,n)&&n!==a&&A(e,n,{get:()=>t[n],enumerable:!(o=O(t,n))||o.enumerable});return e};var E=(e,t,a)=>(a=e!=null?D(z(e)):{},F(t||!e||!e.__esModule?A(a,"default",{value:e,enumerable:!0}):a,e)),K=e=>F(A({},"__esModule",{value:!0}),e);var Z={};H(Z,{YuktAI:()=>N,YuktAIWrapper:()=>L,default:()=>U});module.exports=K(Z);var k=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 o=this.use(t);if(!o)throw new Error(`Plugin not found: ${t}`);return await o.execute(a)}catch(o){throw console.error(`[YuktAI Runtime Error in ${t}]:`,o),o}}getPlugins(){return Array.from(this.plugins.keys())}};var R={name:"ai.text",async execute(e){return`\u{1F916} YuktAI says: ${e}`}};var S={name:"voice.text",async execute(e){return!e||e.trim()===""?"\u{1F3A4} No speech detected":`\u{1F3A4} You said: ${e}`}};var P=E(require("tesseract.js"),1),b=null,_=null;function Y(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 G(e){return b&&_===e||(b&&(await b.terminate(),b=null),b=await P.default.createWorker({langPath:"/tessdata",logger:()=>{}}),await b.loadLanguage(e),await b.initialize(e),_=e),b}var I={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"}),a=e.lang||Y(await t.arrayBuffer())||"eng",o=await G(a),{data:n}=await o.recognize(t),i=n.text?.trim();return i?{language:a,confidence:Math.round(n.confidence??0),text:i}:"\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 a=this.validatePage();return{...t,validation:a}}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 a=e.root||document,o=e.skipFixes||[];try{let n=a.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=n.length;let i=0;if(n.forEach(s=>{try{let r=s,u=r.tagName.toLowerCase();if(!o.includes("headings")&&/^h[1-6]$/.test(u)){let c=parseInt(u[1]);c>i+1&&i!==0&&(r.setAttribute("aria-level",String(i+1)),t.fixed++),i=c}if(!o.includes("buttons")&&(u==="a"||u==="button")&&!r.innerText.trim()&&!r.getAttribute("aria-label")){let c=r.getAttribute("title")||r.getAttribute("aria-label")||"Interactive element";r.setAttribute("aria-label",c),t.fixed++}if(o.includes("clickables")||(r.hasAttribute("onclick")||typeof window<"u"&&window.getComputedStyle(r).cursor==="pointer")&&!["button","a","input","select","textarea"].includes(u)&&(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)),!o.includes("forms")&&["input","select","textarea"].includes(u)){if(!r.getAttribute("aria-label")&&!r.getAttribute("aria-labelledby")){let c=r.getAttribute("placeholder")||r.getAttribute("name")||r.getAttribute("title")||u;r.setAttribute("aria-label",c),t.fixed++}r.hasAttribute("required")&&!r.getAttribute("aria-required")&&(r.setAttribute("aria-required","true"),t.fixed++)}!o.includes("images")&&u==="img"&&!r.hasAttribute("alt")&&(r.setAttribute("alt",""),r.setAttribute("aria-hidden","true"),t.fixed++),!o.includes("tables")&&u==="table"&&!s.querySelector("th")&&(r.getAttribute("role")||(r.setAttribute("role","grid"),t.fixed++)),!o.includes("media")&&["video","audio"].includes(u)&&(r.hasAttribute("controls")||(r.setAttribute("controls","true"),t.fixed++)),!o.includes("iframes")&&u==="iframe"&&!r.getAttribute("title")&&(r.setAttribute("title","Embedded content"),t.fixed++)}catch(r){t.errors.push(`Error fixing element ${s.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 s=document.createElement("style");s.id="yukt-reduce-motion",s.textContent="*, *::before, *::after { transition: none !important; animation: none !important; }",document.head.appendChild(s)}}catch(n){t.errors.push(`General error in applyFixes: ${n.message}`)}return t},startObserver(e){this.observer||typeof document>"u"||(this.observer=new MutationObserver(t=>{clearTimeout(this._mutationTimer),this._mutationTimer=setTimeout(()=>{t.forEach(a=>{a.addedNodes.forEach(o=>{o instanceof HTMLElement&&this.applyFixes({...e,root:o})})})},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,a=4.5){try{return(n=>{let i=document.createElement("div");i.style.color=n,i.style.backgroundColor=t,document.body.appendChild(i);let s=window.getComputedStyle(i).color,r=window.getComputedStyle(i).backgroundColor;i.remove();let u=s.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/),c=r.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(!u||!c)return 1;let f=this.rgbToLuminance(parseInt(u[1]),parseInt(u[2]),parseInt(u[3])),x=this.rgbToLuminance(parseInt(c[1]),parseInt(c[2]),parseInt(c[3])),h=Math.max(f,x),C=Math.min(f,x);return(h+.05)/(C+.05)})(e)>=a}catch(o){return console.warn("Contrast check failed:",o),!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 o=document.querySelectorAll("img:not([alt])");o.length>0&&(e.push(`${o.length} images missing alt text`),t.push("Add descriptive alt text to all images"));let n=Array.from(document.querySelectorAll("h1,h2,h3,h4,h5,h6")),i=0;return n.forEach((r,u)=>{let c=parseInt(r.tagName[1]);u>0&&c>i+1&&(e.push(`Skipped heading level: ${r.tagName} after h${i}`),t.push("Ensure heading hierarchy is sequential")),i=c}),{score:Math.max(0,100-e.length*10),issues:e,recommendations:t}}};var y=E(require("react"),1),T=E(require("react-dom/client"),1),B=require("react/jsx-runtime");function w(e,t=!0,a){if(!t||!y.default.isValidElement(e))return e;let o=e,n={...o.props},i=o.type,s=!1;["input","textarea","select"].includes(i)&&!n["aria-label"]&&!n["aria-labelledby"]&&(n["aria-label"]=n.placeholder||n.name||`${i} input`,s=!0),i==="button"&&!n["aria-label"]&&!n.children&&(n["aria-label"]="action button",s=!0),i==="a"&&(n.href&&!n["aria-label"]&&!n.children&&(n["aria-label"]=`Link to ${n.href}`,s=!0),n.target==="_blank"&&!n.rel&&(n.rel="noopener noreferrer",s=!0)),i==="img"&&(n.alt===void 0||n.alt===null)&&(n.alt="",n["aria-hidden"]="true",s=!0),["video","audio","iframe"].includes(i)&&(n.title||(n.title=n.name||`${i} content`,s=!0));let r={nav:"navigation",header:"banner",footer:"contentinfo",main:"main",aside:"complementary",section:"region"};if(r[i]&&(n.role||(n.role=r[i],s=!0)),i==="table"&&(n.role||(n.role="table",s=!0)),["ul","ol"].includes(i)&&!n.role&&(n.role="list",s=!0),(i==="div"||i==="span")&&n.onClick&&(n.role||(n.role="button",s=!0),n.tabIndex===void 0&&(n.tabIndex=0,s=!0),!n.onKeyDown)){let c=n.onClick;n.onKeyDown=f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),c(f))},s=!0}["h1","h2","h3","h4","h5","h6"].includes(i)&&!n.id&&typeof n.children=="string"&&(n.id=n.children.toLowerCase().trim().replace(/\s+/g,"-"),s=!0),s&&a&&a();let u=y.default.Children.map(n.children,c=>y.default.isValidElement(c)?w(c,t,a):c);return y.default.cloneElement(o,n,u)}function M(e,t,a=!0){let o=document.querySelector(t);if(!o)return;let n=w(e,a);T.default.createRoot(o).render((0,B.jsx)(y.default.StrictMode,{children:n}))}var g=require("react");var l=require("react/jsx-runtime"),j={enabled:!0,highContrast:!1,dyslexiaFont:!1,fontScale:100,wcagLevel:"AA"};function L({children:e}){let[t,a]=(0,g.useState)(!1),[o,n]=(0,g.useState)(!1),[i,s]=(0,g.useState)(j),[r,u]=(0,g.useState)(0),c=(0,g.useRef)(null),f=(0,g.useRef)(null);(0,g.useEffect)(()=>(a(!0),(async()=>await p.execute({enabled:i.enabled,autoFix:!0,level:i.wcagLevel}))(),()=>p.stopObserver()),[]);let x=(0,g.useCallback)(async d=>{await p.execute({enabled:d.enabled,highContrast:d.highContrast,autoFix:!0,level:d.wcagLevel}),document.documentElement.style.fontSize=`${d.fontScale}%`;let v="yuktai-dyslexia-css",m=document.getElementById(v);d.dyslexiaFont?m||(m=document.createElement("style"),m.id=v,m.textContent="body, body * { font-family: 'OpenDyslexic', 'Georgia', serif !important; line-height: 1.6 !important; }",document.head.appendChild(m)):m?.remove()},[]),h=(d,v)=>{let m={...i,[d]:v};s(m),x(m),d==="enabled"&&u(0)},C=t?w(e,i.enabled,()=>u(d=>d+1)):e;return(0,l.jsxs)(l.Fragment,{children:[C,(0,l.jsxs)("button",{ref:f,onClick:d=>{d.stopPropagation(),n(!o)},"aria-label":"Accessibility Menu",style:{position:"fixed",bottom:20,right:20,width:60,height:60,borderRadius:"50%",background:i.enabled?"#0d9488":"#4b5563",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,l.jsx)("svg",{viewBox:"0 0 24 24",width:"32",height:"32",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"})}),i.enabled&&r>0&&(0,l.jsx)("span",{style:{position:"absolute",top:-4,right:-4,background:"#ef4444",color:"white",borderRadius:"50%",padding:"2px 6px",fontSize:10,fontWeight:"bold"},children:r})]}),o&&(0,l.jsxs)("div",{ref:c,style:{position:"fixed",bottom:90,right:20,width:320,background:"#fff",borderRadius:16,padding:24,boxShadow:"0 10px 40px rgba(0,0,0,0.2)",zIndex:10001,border:"1px solid #e5e7eb",color:"#111827",fontFamily:"sans-serif"},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:20},children:[(0,l.jsx)("h3",{style:{margin:0,fontSize:18},children:"YuktAI Engine"}),(0,l.jsx)("span",{style:{fontSize:11,fontWeight:700,color:i.enabled?"#0d9488":"#94a3b8"},children:i.enabled?"\u25CF ONLINE":"\u25CB OFFLINE"})]}),(0,l.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[(0,l.jsxs)("button",{onClick:()=>h("enabled",!i.enabled),style:{width:"100%",padding:"12px",borderRadius:10,cursor:"pointer",background:i.enabled?"#f0fdf4":"#f8fafc",border:i.enabled?"2px solid #0d9488":"1px solid #cbd5e1",color:i.enabled?"#065f46":"#475569",fontWeight:600,display:"flex",justifyContent:"space-between"},children:[i.enabled?"Disable ADA Engine":"Enable ADA Engine",(0,l.jsx)("span",{children:i.enabled?"\u2713":"\u2192"})]}),i.enabled&&(0,l.jsxs)("div",{style:{padding:"10px",background:"#f1f5f9",borderRadius:8,fontSize:12},children:["\u{1F680} ",(0,l.jsx)("strong",{children:r})," potential accessibility issues auto-fixed."]}),(0,l.jsx)("div",{style:{borderBottom:"1px solid #f1f5f9",margin:"8px 0"}}),(0,l.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[(0,l.jsxs)("span",{style:{fontSize:12,color:"#64748b"},children:["Zoom Level: ",i.fontScale,"%"]}),(0,l.jsx)("input",{type:"range",min:"100",max:"200",step:"10",value:i.fontScale,onChange:d=>h("fontScale",parseInt(d.target.value)),style:{accentColor:"#0d9488"}})]}),(0,l.jsxs)("label",{style:{display:"flex",justifyContent:"space-between",fontSize:14},children:["Contrast Mode ",(0,l.jsx)("input",{type:"checkbox",checked:i.highContrast,onChange:d=>h("highContrast",d.target.checked)})]}),(0,l.jsxs)("label",{style:{display:"flex",justifyContent:"space-between",fontSize:14},children:["Dyslexia Font ",(0,l.jsx)("input",{type:"checkbox",checked:i.dyslexiaFont,onChange:d=>h("dyslexiaFont",d.target.checked)})]})]}),(0,l.jsx)("button",{onClick:()=>n(!1),style:{width:"100%",marginTop:24,padding:12,background:"#0f172a",color:"#fff",border:"none",borderRadius:8,fontWeight:600,cursor:"pointer"},children:"Done"})]})]})}function V(){if(!globalThis.__yuktai_runtime__){let e=new k;e.register(R.name,R),e.register(S.name,S),e.register(I.name,I),e.register(p.name,p),globalThis.__yuktai_runtime__=e}return globalThis.__yuktai_runtime__}var W=V(),N={render:M,list(){return W.getPlugins()},use(e){return W.use(e)}},U=N;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 O=Object.getPrototypeOf,q=Object.prototype.hasOwnProperty;var D=(e,t)=>{for(var i in t)y(e,i,{get:t[i],enumerable:!0})},T=(e,t,i,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let u of $(t))!q.call(e,u)&&u!==i&&y(e,u,{get:()=>t[u],enumerable:!(r=N(t,u))||r.enumerable});return e};var A=(e,t,i)=>(i=e!=null?B(O(e)):{},T(t||!e||!e.__esModule?y(i,"default",{value:e,enumerable:!0}):i,e)),z=e=>T(y({},"__esModule",{value:!0}),e);var G={};D(G,{YuktAI:()=>P,YuktAIWrapper:()=>C,default:()=>K});module.exports=z(G);var h=class{plugins=new Map;register(t,i){if(!i||typeof i.execute!="function")throw new Error(`Invalid plugin: ${t}`);this.plugins.set(t,i)}use(t){return this.plugins.get(t)}async run(t,i){try{let r=this.use(t);if(!r)throw new Error(`Plugin not found: ${t}`);return await r.execute(i)}catch(r){throw console.error(`[YuktAI Runtime Error in ${t}]:`,r),r}}getPlugins(){return Array.from(this.plugins.keys())}};var k={name:"ai.text",async execute(e){return`\u{1F916} YuktAI says: ${e}`}};var E={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),g=null,I=null;function W(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 g&&I===e||(g&&(await g.terminate(),g=null),g=await S.default.createWorker({langPath:"/tessdata",logger:()=>{}}),await g.loadLanguage(e),await g.initialize(e),I=e),g}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"}),i=e.lang||W(await t.arrayBuffer())||"eng",r=await H(i),{data:u}=await r.recognize(t),s=u.text?.trim();return s?{language:i,confidence:Math.round(u.confidence??0),text:s}:"\u26A0\uFE0F No text detected"}catch(t){return console.error("[ocrSmartPlugin]",t),"\u274C OCR failed"}}};var w={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 i=this.validatePage();return{...t,validation:i}}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 i=e.root||document,r=e.skipFixes||[];try{let u=i.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=u.length;let s=0;if(u.forEach(o=>{try{let n=o,a=n.tagName.toLowerCase();if(!r.includes("headings")&&/^h[1-6]$/.test(a)){let c=parseInt(a[1]);c>s+1&&s!==0&&(n.setAttribute("aria-level",String(s+1)),t.fixed++),s=c}if(!r.includes("buttons")&&(a==="a"||a==="button")&&!n.innerText.trim()&&!n.getAttribute("aria-label")){let c=n.getAttribute("title")||n.getAttribute("aria-label")||"Interactive element";n.setAttribute("aria-label",c),t.fixed++}if(r.includes("clickables")||(n.hasAttribute("onclick")||typeof window<"u"&&window.getComputedStyle(n).cursor==="pointer")&&!["button","a","input","select","textarea"].includes(a)&&(n.getAttribute("role")||(n.setAttribute("role","button"),t.fixed++),n.tabIndex<0&&(n.tabIndex=0,t.fixed++),n._yuktKeyBound||(n.addEventListener("keydown",d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),n.click())}),n._yuktKeyBound=!0)),!r.includes("forms")&&["input","select","textarea"].includes(a)){if(!n.getAttribute("aria-label")&&!n.getAttribute("aria-labelledby")){let c=n.getAttribute("placeholder")||n.getAttribute("name")||n.getAttribute("title")||a;n.setAttribute("aria-label",c),t.fixed++}n.hasAttribute("required")&&!n.getAttribute("aria-required")&&(n.setAttribute("aria-required","true"),t.fixed++)}!r.includes("images")&&a==="img"&&!n.hasAttribute("alt")&&(n.setAttribute("alt",""),n.setAttribute("aria-hidden","true"),t.fixed++),!r.includes("tables")&&a==="table"&&!o.querySelector("th")&&(n.getAttribute("role")||(n.setAttribute("role","grid"),t.fixed++)),!r.includes("media")&&["video","audio"].includes(a)&&(n.hasAttribute("controls")||(n.setAttribute("controls","true"),t.fixed++)),!r.includes("iframes")&&a==="iframe"&&!n.getAttribute("title")&&(n.setAttribute("title","Embedded content"),t.fixed++)}catch(n){t.errors.push(`Error fixing element ${o.tagName}: ${n.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 o=document.createElement("style");o.id="yukt-reduce-motion",o.textContent="*, *::before, *::after { transition: none !important; animation: none !important; }",document.head.appendChild(o)}}catch(u){t.errors.push(`General error in applyFixes: ${u.message}`)}return t},startObserver(e){this.observer||typeof document>"u"||(this.observer=new MutationObserver(t=>{clearTimeout(this._mutationTimer),this._mutationTimer=setTimeout(()=>{t.forEach(i=>{i.addedNodes.forEach(r=>{r instanceof HTMLElement&&this.applyFixes({...e,root:r})})})},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,i=4.5){try{return(u=>{let s=document.createElement("div");s.style.color=u,s.style.backgroundColor=t,document.body.appendChild(s);let o=window.getComputedStyle(s).color,n=window.getComputedStyle(s).backgroundColor;s.remove();let a=o.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/),c=n.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(!a||!c)return 1;let d=this.rgbToLuminance(parseInt(a[1]),parseInt(a[2]),parseInt(a[3])),m=this.rgbToLuminance(parseInt(c[1]),parseInt(c[2]),parseInt(c[3])),b=Math.max(d,m),v=Math.min(d,m);return(b+.05)/(v+.05)})(e)>=i}catch(r){return console.warn("Contrast check failed:",r),!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 r=document.querySelectorAll("img:not([alt])");r.length>0&&(e.push(`${r.length} images missing alt text`),t.push("Add descriptive alt text to all images"));let u=Array.from(document.querySelectorAll("h1,h2,h3,h4,h5,h6")),s=0;return u.forEach((n,a)=>{let c=parseInt(n.tagName[1]);a>0&&c>s+1&&(e.push(`Skipped heading level: ${n.tagName} after h${s}`),t.push("Ensure heading hierarchy is sequential")),s=c}),{score:Math.max(0,100-e.length*10),issues:e,recommendations:t}}};var p=A(require("react"),1),_=A(require("react-dom/client"),1),M=require("react/jsx-runtime");function x(e,t=!0,i={fixes:0,nodes:0,renderTime:0}){let r=i.nodes===0,u=r?performance.now():0;if(!p.default.isValidElement(e))return e;i.nodes++;let s=e,o={...s.props},n=s.type,a=!1;t&&(["input","textarea","select"].includes(n)&&!o["aria-label"]&&(o["aria-label"]=o.placeholder||o.name||`${n} field`,a=!0),n==="img"&&(o.alt===void 0||o.alt===null)&&(o.alt="",o["aria-hidden"]="true",a=!0),(n==="div"||n==="span")&&o.onClick&&(o.role||(o.role="button",a=!0),o.tabIndex===void 0&&(o.tabIndex=0,a=!0)),a&&i.fixes++);let c=p.default.Children.map(o.children,m=>p.default.isValidElement(m)?x(m,t,i):m),d=p.default.cloneElement(s,o,c);return r&&(i.renderTime=parseFloat((performance.now()-u).toFixed(2))),d}function F(e,t,i=!0){let r=document.querySelector(t);if(!r)return;let s=x(e,i,{fixes:0,nodes:0,renderTime:0});_.default.createRoot(r).render((0,M.jsx)(p.default.StrictMode,{children:s}))}var f=require("react");var l=require("react/jsx-runtime");function C({children:e}){let[t,i]=(0,f.useState)(!1),[r,u]=(0,f.useState)(!1),[s,o]=(0,f.useState)(!1),[n,a]=(0,f.useState)({fixes:0,nodes:0,renderTime:0}),c=(0,f.useRef)(null);(0,f.useEffect)(()=>{i(!0)},[]);let d={fixes:0,nodes:0,renderTime:0},m=(0,f.useMemo)(()=>x(e,r,d),[e,r]);return(0,f.useEffect)(()=>{t&&(n.fixes!==d.fixes||n.nodes!==d.nodes)&&a({...d})},[m,r,t]),(0,f.useEffect)(()=>{if(!s)return;let b=v=>{c.current&&!c.current.contains(v.target)&&o(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[s]),t?(0,l.jsxs)(l.Fragment,{children:[m,(0,l.jsx)("button",{onClick:()=>o(!0),style:{position:"fixed",bottom:25,right:25,width:60,height:60,borderRadius:"50%",background:"#1a202c",color:"white",border:"none",cursor:"pointer",zIndex:9999,boxShadow:"0 4px 20px rgba(0,0,0,0.25)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"28px"},children:"\u267F"}),s&&(0,l.jsxs)("div",{ref:c,style:{position:"fixed",bottom:95,right:25,width:340,background:"#ffffff",borderRadius:"20px",padding:"24px",boxShadow:"0 10px 40px rgba(0,0,0,0.15)",zIndex:1e4,border:"1px solid #f0f0f0",fontFamily:"system-ui, sans-serif"},children:[(0,l.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"20px"},children:[(0,l.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[(0,l.jsx)("span",{style:{fontSize:"22px"},children:"\u267F"}),(0,l.jsx)("strong",{style:{fontSize:"18px"},children:"ADA accessibility"})]}),(0,l.jsx)("button",{onClick:()=>o(!1),style:{background:"none",border:"none",cursor:"pointer",fontSize:"20px"},children:"\xD7"})]}),(0,l.jsx)("button",{onClick:()=>u(!r),style:{width:"100%",padding:"16px",borderRadius:"12px",border:"none",cursor:"pointer",fontWeight:"700",background:r?"#dcfce7":"#eff6ff",color:r?"#065f46":"#2563eb",marginBottom:"20px"},children:r?"Disable ADA Engine":"Enable ADA Engine"}),(0,l.jsx)("div",{style:{borderTop:"1px solid #edf2f7",paddingTop:"16px",fontSize:"12px",color:"#718096"},children:r?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{style:{color:"#2d3748",fontWeight:"600",marginBottom:"4px"},children:["yuktai-a11y: ",n.fixes," fixes applied."]}),(0,l.jsxs)("div",{children:["Nodes scanned: ",n.nodes]}),(0,l.jsxs)("div",{style:{marginTop:"4px",color:"#a0aec0"},children:["Render time: ",n.renderTime,"ms"]})]}):(0,l.jsx)("div",{style:{fontStyle:"italic"},children:"ADA Engine is offline."})})]})]}):(0,l.jsx)(l.Fragment,{children:e})}function Y(){if(!globalThis.__yuktai_runtime__){let e=new h;e.register(k.name,k),e.register(E.name,E),e.register(R.name,R),e.register(w.name,w),globalThis.__yuktai_runtime__=e}return globalThis.__yuktai_runtime__}var L=Y(),P={render:F,list(){return L.getPlugins()},use(e){return L.use(e)}},K=P;0&&(module.exports={YuktAI,YuktAIWrapper});
package/dist/index.d.cts CHANGED
@@ -20,15 +20,11 @@ declare class Runtime {
20
20
  getPlugins(): string[];
21
21
  }
22
22
 
23
- /**
24
- * Standard DOM Mount Renderer
25
- */
26
23
  declare function render(element: React.ReactNode, selector: string, enabled?: boolean): void;
27
24
 
28
- interface YuktAIWrapperProps {
25
+ declare function YuktAIWrapper({ children }: {
29
26
  children?: React.ReactNode;
30
- }
31
- declare function YuktAIWrapper({ children }: YuktAIWrapperProps): react_jsx_runtime.JSX.Element;
27
+ }): react_jsx_runtime.JSX.Element;
32
28
 
33
29
  declare global {
34
30
  var __yuktai_runtime__: Runtime | undefined;
package/dist/index.d.ts CHANGED
@@ -20,15 +20,11 @@ declare class Runtime {
20
20
  getPlugins(): string[];
21
21
  }
22
22
 
23
- /**
24
- * Standard DOM Mount Renderer
25
- */
26
23
  declare function render(element: React.ReactNode, selector: string, enabled?: boolean): void;
27
24
 
28
- interface YuktAIWrapperProps {
25
+ declare function YuktAIWrapper({ children }: {
29
26
  children?: React.ReactNode;
30
- }
31
- declare function YuktAIWrapper({ children }: YuktAIWrapperProps): react_jsx_runtime.JSX.Element;
27
+ }): react_jsx_runtime.JSX.Element;
32
28
 
33
29
  declare global {
34
30
  var __yuktai_runtime__: Runtime | undefined;
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use client";var A=class{plugins=new Map;register(t,s){if(!s||typeof s.execute!="function")throw new Error(`Invalid plugin: ${t}`);this.plugins.set(t,s)}use(t){return this.plugins.get(t)}async run(t,s){try{let o=this.use(t);if(!o)throw new Error(`Plugin not found: ${t}`);return await o.execute(s)}catch(o){throw console.error(`[YuktAI Runtime Error in ${t}]:`,o),o}}getPlugins(){return Array.from(this.plugins.keys())}};var E={name:"ai.text",async execute(e){return`\u{1F916} YuktAI says: ${e}`}};var R={name:"voice.text",async execute(e){return!e||e.trim()===""?"\u{1F3A4} No speech detected":`\u{1F3A4} You said: ${e}`}};import T from"tesseract.js";var b=null,I=null;function M(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 B(e){return b&&I===e||(b&&(await b.terminate(),b=null),b=await T.createWorker({langPath:"/tessdata",logger:()=>{}}),await b.loadLanguage(e),await b.initialize(e),I=e),b}var S={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"}),s=e.lang||M(await t.arrayBuffer())||"eng",o=await B(s),{data:n}=await o.recognize(t),i=n.text?.trim();return i?{language:s,confidence:Math.round(n.confidence??0),text:i}:"\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 s=this.validatePage();return{...t,validation:s}}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 s=e.root||document,o=e.skipFixes||[];try{let n=s.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=n.length;let i=0;if(n.forEach(a=>{try{let r=a,l=r.tagName.toLowerCase();if(!o.includes("headings")&&/^h[1-6]$/.test(l)){let u=parseInt(l[1]);u>i+1&&i!==0&&(r.setAttribute("aria-level",String(i+1)),t.fixed++),i=u}if(!o.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(o.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",d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),r.click())}),r._yuktKeyBound=!0)),!o.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++)}!o.includes("images")&&l==="img"&&!r.hasAttribute("alt")&&(r.setAttribute("alt",""),r.setAttribute("aria-hidden","true"),t.fixed++),!o.includes("tables")&&l==="table"&&!a.querySelector("th")&&(r.getAttribute("role")||(r.setAttribute("role","grid"),t.fixed++)),!o.includes("media")&&["video","audio"].includes(l)&&(r.hasAttribute("controls")||(r.setAttribute("controls","true"),t.fixed++)),!o.includes("iframes")&&l==="iframe"&&!r.getAttribute("title")&&(r.setAttribute("title","Embedded content"),t.fixed++)}catch(r){t.errors.push(`Error fixing element ${a.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 a=document.createElement("style");a.id="yukt-reduce-motion",a.textContent="*, *::before, *::after { transition: none !important; animation: none !important; }",document.head.appendChild(a)}}catch(n){t.errors.push(`General error in applyFixes: ${n.message}`)}return t},startObserver(e){this.observer||typeof document>"u"||(this.observer=new MutationObserver(t=>{clearTimeout(this._mutationTimer),this._mutationTimer=setTimeout(()=>{t.forEach(s=>{s.addedNodes.forEach(o=>{o instanceof HTMLElement&&this.applyFixes({...e,root:o})})})},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,s=4.5){try{return(n=>{let i=document.createElement("div");i.style.color=n,i.style.backgroundColor=t,document.body.appendChild(i);let a=window.getComputedStyle(i).color,r=window.getComputedStyle(i).backgroundColor;i.remove();let l=a.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/),u=r.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(!l||!u)return 1;let d=this.rgbToLuminance(parseInt(l[1]),parseInt(l[2]),parseInt(l[3])),x=this.rgbToLuminance(parseInt(u[1]),parseInt(u[2]),parseInt(u[3])),h=Math.max(d,x),C=Math.min(d,x);return(h+.05)/(C+.05)})(e)>=s}catch(o){return console.warn("Contrast check failed:",o),!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 o=document.querySelectorAll("img:not([alt])");o.length>0&&(e.push(`${o.length} images missing alt text`),t.push("Add descriptive alt text to all images"));let n=Array.from(document.querySelectorAll("h1,h2,h3,h4,h5,h6")),i=0;return n.forEach((r,l)=>{let u=parseInt(r.tagName[1]);l>0&&u>i+1&&(e.push(`Skipped heading level: ${r.tagName} after h${i}`),t.push("Ensure heading hierarchy is sequential")),i=u}),{score:Math.max(0,100-e.length*10),issues:e,recommendations:t}}};import y from"react";import W from"react-dom/client";import{jsx as N}from"react/jsx-runtime";function k(e,t=!0,s){if(!t||!y.isValidElement(e))return e;let o=e,n={...o.props},i=o.type,a=!1;["input","textarea","select"].includes(i)&&!n["aria-label"]&&!n["aria-labelledby"]&&(n["aria-label"]=n.placeholder||n.name||`${i} input`,a=!0),i==="button"&&!n["aria-label"]&&!n.children&&(n["aria-label"]="action button",a=!0),i==="a"&&(n.href&&!n["aria-label"]&&!n.children&&(n["aria-label"]=`Link to ${n.href}`,a=!0),n.target==="_blank"&&!n.rel&&(n.rel="noopener noreferrer",a=!0)),i==="img"&&(n.alt===void 0||n.alt===null)&&(n.alt="",n["aria-hidden"]="true",a=!0),["video","audio","iframe"].includes(i)&&(n.title||(n.title=n.name||`${i} content`,a=!0));let r={nav:"navigation",header:"banner",footer:"contentinfo",main:"main",aside:"complementary",section:"region"};if(r[i]&&(n.role||(n.role=r[i],a=!0)),i==="table"&&(n.role||(n.role="table",a=!0)),["ul","ol"].includes(i)&&!n.role&&(n.role="list",a=!0),(i==="div"||i==="span")&&n.onClick&&(n.role||(n.role="button",a=!0),n.tabIndex===void 0&&(n.tabIndex=0,a=!0),!n.onKeyDown)){let u=n.onClick;n.onKeyDown=d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),u(d))},a=!0}["h1","h2","h3","h4","h5","h6"].includes(i)&&!n.id&&typeof n.children=="string"&&(n.id=n.children.toLowerCase().trim().replace(/\s+/g,"-"),a=!0),a&&s&&s();let l=y.Children.map(n.children,u=>y.isValidElement(u)?k(u,t,s):u);return y.cloneElement(o,n,l)}function L(e,t,s=!0){let o=document.querySelector(t);if(!o)return;let n=k(e,s);W.createRoot(o).render(N(y.StrictMode,{children:n}))}import{useState as w,useEffect as D,useRef as F,useCallback as O}from"react";import{Fragment as z,jsx as f,jsxs as g}from"react/jsx-runtime";var $={enabled:!0,highContrast:!1,dyslexiaFont:!1,fontScale:100,wcagLevel:"AA"};function _({children:e}){let[t,s]=w(!1),[o,n]=w(!1),[i,a]=w($),[r,l]=w(0),u=F(null),d=F(null);D(()=>(s(!0),(async()=>await p.execute({enabled:i.enabled,autoFix:!0,level:i.wcagLevel}))(),()=>p.stopObserver()),[]);let x=O(async c=>{await p.execute({enabled:c.enabled,highContrast:c.highContrast,autoFix:!0,level:c.wcagLevel}),document.documentElement.style.fontSize=`${c.fontScale}%`;let v="yuktai-dyslexia-css",m=document.getElementById(v);c.dyslexiaFont?m||(m=document.createElement("style"),m.id=v,m.textContent="body, body * { font-family: 'OpenDyslexic', 'Georgia', serif !important; line-height: 1.6 !important; }",document.head.appendChild(m)):m?.remove()},[]),h=(c,v)=>{let m={...i,[c]:v};a(m),x(m),c==="enabled"&&l(0)},C=t?k(e,i.enabled,()=>l(c=>c+1)):e;return g(z,{children:[C,g("button",{ref:d,onClick:c=>{c.stopPropagation(),n(!o)},"aria-label":"Accessibility Menu",style:{position:"fixed",bottom:20,right:20,width:60,height:60,borderRadius:"50%",background:i.enabled?"#0d9488":"#4b5563",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:[f("svg",{viewBox:"0 0 24 24",width:"32",height:"32",fill:"currentColor",children:f("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"})}),i.enabled&&r>0&&f("span",{style:{position:"absolute",top:-4,right:-4,background:"#ef4444",color:"white",borderRadius:"50%",padding:"2px 6px",fontSize:10,fontWeight:"bold"},children:r})]}),o&&g("div",{ref:u,style:{position:"fixed",bottom:90,right:20,width:320,background:"#fff",borderRadius:16,padding:24,boxShadow:"0 10px 40px rgba(0,0,0,0.2)",zIndex:10001,border:"1px solid #e5e7eb",color:"#111827",fontFamily:"sans-serif"},children:[g("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:20},children:[f("h3",{style:{margin:0,fontSize:18},children:"YuktAI Engine"}),f("span",{style:{fontSize:11,fontWeight:700,color:i.enabled?"#0d9488":"#94a3b8"},children:i.enabled?"\u25CF ONLINE":"\u25CB OFFLINE"})]}),g("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[g("button",{onClick:()=>h("enabled",!i.enabled),style:{width:"100%",padding:"12px",borderRadius:10,cursor:"pointer",background:i.enabled?"#f0fdf4":"#f8fafc",border:i.enabled?"2px solid #0d9488":"1px solid #cbd5e1",color:i.enabled?"#065f46":"#475569",fontWeight:600,display:"flex",justifyContent:"space-between"},children:[i.enabled?"Disable ADA Engine":"Enable ADA Engine",f("span",{children:i.enabled?"\u2713":"\u2192"})]}),i.enabled&&g("div",{style:{padding:"10px",background:"#f1f5f9",borderRadius:8,fontSize:12},children:["\u{1F680} ",f("strong",{children:r})," potential accessibility issues auto-fixed."]}),f("div",{style:{borderBottom:"1px solid #f1f5f9",margin:"8px 0"}}),g("div",{style:{display:"flex",flexDirection:"column",gap:4},children:[g("span",{style:{fontSize:12,color:"#64748b"},children:["Zoom Level: ",i.fontScale,"%"]}),f("input",{type:"range",min:"100",max:"200",step:"10",value:i.fontScale,onChange:c=>h("fontScale",parseInt(c.target.value)),style:{accentColor:"#0d9488"}})]}),g("label",{style:{display:"flex",justifyContent:"space-between",fontSize:14},children:["Contrast Mode ",f("input",{type:"checkbox",checked:i.highContrast,onChange:c=>h("highContrast",c.target.checked)})]}),g("label",{style:{display:"flex",justifyContent:"space-between",fontSize:14},children:["Dyslexia Font ",f("input",{type:"checkbox",checked:i.dyslexiaFont,onChange:c=>h("dyslexiaFont",c.target.checked)})]})]}),f("button",{onClick:()=>n(!1),style:{width:"100%",marginTop:24,padding:12,background:"#0f172a",color:"#fff",border:"none",borderRadius:8,fontWeight:600,cursor:"pointer"},children:"Done"})]})]})}function q(){if(!globalThis.__yuktai_runtime__){let e=new A;e.register(E.name,E),e.register(R.name,R),e.register(S.name,S),e.register(p.name,p),globalThis.__yuktai_runtime__=e}return globalThis.__yuktai_runtime__}var P=q(),H={render:L,list(){return P.getPlugins()},use(e){return P.use(e)}},ge=H;export{H as YuktAI,_ as YuktAIWrapper,ge as default};
1
+ "use client";var y=class{plugins=new Map;register(t,s){if(!s||typeof s.execute!="function")throw new Error(`Invalid plugin: ${t}`);this.plugins.set(t,s)}use(t){return this.plugins.get(t)}async run(t,s){try{let r=this.use(t);if(!r)throw new Error(`Plugin not found: ${t}`);return await r.execute(s)}catch(r){throw console.error(`[YuktAI Runtime Error in ${t}]:`,r),r}}getPlugins(){return Array.from(this.plugins.keys())}};var A={name:"ai.text",async execute(e){return`\u{1F916} YuktAI says: ${e}`}};var k={name:"voice.text",async execute(e){return!e||e.trim()===""?"\u{1F3A4} No speech detected":`\u{1F3A4} You said: ${e}`}};import F from"tesseract.js";var f=null,T=null;function M(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 L(e){return f&&T===e||(f&&(await f.terminate(),f=null),f=await F.createWorker({langPath:"/tessdata",logger:()=>{}}),await f.loadLanguage(e),await f.initialize(e),T=e),f}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"}),s=e.lang||M(await t.arrayBuffer())||"eng",r=await L(s),{data:l}=await r.recognize(t),o=l.text?.trim();return o?{language:s,confidence:Math.round(l.confidence??0),text:o}:"\u26A0\uFE0F No text detected"}catch(t){return console.error("[ocrSmartPlugin]",t),"\u274C OCR failed"}}};var R={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 s=this.validatePage();return{...t,validation:s}}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 s=e.root||document,r=e.skipFixes||[];try{let l=s.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=l.length;let o=0;if(l.forEach(i=>{try{let n=i,a=n.tagName.toLowerCase();if(!r.includes("headings")&&/^h[1-6]$/.test(a)){let u=parseInt(a[1]);u>o+1&&o!==0&&(n.setAttribute("aria-level",String(o+1)),t.fixed++),o=u}if(!r.includes("buttons")&&(a==="a"||a==="button")&&!n.innerText.trim()&&!n.getAttribute("aria-label")){let u=n.getAttribute("title")||n.getAttribute("aria-label")||"Interactive element";n.setAttribute("aria-label",u),t.fixed++}if(r.includes("clickables")||(n.hasAttribute("onclick")||typeof window<"u"&&window.getComputedStyle(n).cursor==="pointer")&&!["button","a","input","select","textarea"].includes(a)&&(n.getAttribute("role")||(n.setAttribute("role","button"),t.fixed++),n.tabIndex<0&&(n.tabIndex=0,t.fixed++),n._yuktKeyBound||(n.addEventListener("keydown",c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),n.click())}),n._yuktKeyBound=!0)),!r.includes("forms")&&["input","select","textarea"].includes(a)){if(!n.getAttribute("aria-label")&&!n.getAttribute("aria-labelledby")){let u=n.getAttribute("placeholder")||n.getAttribute("name")||n.getAttribute("title")||a;n.setAttribute("aria-label",u),t.fixed++}n.hasAttribute("required")&&!n.getAttribute("aria-required")&&(n.setAttribute("aria-required","true"),t.fixed++)}!r.includes("images")&&a==="img"&&!n.hasAttribute("alt")&&(n.setAttribute("alt",""),n.setAttribute("aria-hidden","true"),t.fixed++),!r.includes("tables")&&a==="table"&&!i.querySelector("th")&&(n.getAttribute("role")||(n.setAttribute("role","grid"),t.fixed++)),!r.includes("media")&&["video","audio"].includes(a)&&(n.hasAttribute("controls")||(n.setAttribute("controls","true"),t.fixed++)),!r.includes("iframes")&&a==="iframe"&&!n.getAttribute("title")&&(n.setAttribute("title","Embedded content"),t.fixed++)}catch(n){t.errors.push(`Error fixing element ${i.tagName}: ${n.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 i=document.createElement("style");i.id="yukt-reduce-motion",i.textContent="*, *::before, *::after { transition: none !important; animation: none !important; }",document.head.appendChild(i)}}catch(l){t.errors.push(`General error in applyFixes: ${l.message}`)}return t},startObserver(e){this.observer||typeof document>"u"||(this.observer=new MutationObserver(t=>{clearTimeout(this._mutationTimer),this._mutationTimer=setTimeout(()=>{t.forEach(s=>{s.addedNodes.forEach(r=>{r instanceof HTMLElement&&this.applyFixes({...e,root:r})})})},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,s=4.5){try{return(l=>{let o=document.createElement("div");o.style.color=l,o.style.backgroundColor=t,document.body.appendChild(o);let i=window.getComputedStyle(o).color,n=window.getComputedStyle(o).backgroundColor;o.remove();let a=i.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/),u=n.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(!a||!u)return 1;let c=this.rgbToLuminance(parseInt(a[1]),parseInt(a[2]),parseInt(a[3])),d=this.rgbToLuminance(parseInt(u[1]),parseInt(u[2]),parseInt(u[3])),b=Math.max(c,d),v=Math.min(c,d);return(b+.05)/(v+.05)})(e)>=s}catch(r){return console.warn("Contrast check failed:",r),!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 r=document.querySelectorAll("img:not([alt])");r.length>0&&(e.push(`${r.length} images missing alt text`),t.push("Add descriptive alt text to all images"));let l=Array.from(document.querySelectorAll("h1,h2,h3,h4,h5,h6")),o=0;return l.forEach((n,a)=>{let u=parseInt(n.tagName[1]);a>0&&u>o+1&&(e.push(`Skipped heading level: ${n.tagName} after h${o}`),t.push("Ensure heading hierarchy is sequential")),o=u}),{score:Math.max(0,100-e.length*10),issues:e,recommendations:t}}};import p from"react";import P from"react-dom/client";import{jsx as B}from"react/jsx-runtime";function h(e,t=!0,s={fixes:0,nodes:0,renderTime:0}){let r=s.nodes===0,l=r?performance.now():0;if(!p.isValidElement(e))return e;s.nodes++;let o=e,i={...o.props},n=o.type,a=!1;t&&(["input","textarea","select"].includes(n)&&!i["aria-label"]&&(i["aria-label"]=i.placeholder||i.name||`${n} field`,a=!0),n==="img"&&(i.alt===void 0||i.alt===null)&&(i.alt="",i["aria-hidden"]="true",a=!0),(n==="div"||n==="span")&&i.onClick&&(i.role||(i.role="button",a=!0),i.tabIndex===void 0&&(i.tabIndex=0,a=!0)),a&&s.fixes++);let u=p.Children.map(i.children,d=>p.isValidElement(d)?h(d,t,s):d),c=p.cloneElement(o,i,u);return r&&(s.renderTime=parseFloat((performance.now()-l).toFixed(2))),c}function I(e,t,s=!0){let r=document.querySelector(t);if(!r)return;let o=h(e,s,{fixes:0,nodes:0,renderTime:0});P.createRoot(r).render(B(p.StrictMode,{children:o}))}import{useState as x,useEffect as w,useRef as N,useMemo as $}from"react";import{Fragment as C,jsx as m,jsxs as g}from"react/jsx-runtime";function S({children:e}){let[t,s]=x(!1),[r,l]=x(!1),[o,i]=x(!1),[n,a]=x({fixes:0,nodes:0,renderTime:0}),u=N(null);w(()=>{s(!0)},[]);let c={fixes:0,nodes:0,renderTime:0},d=$(()=>h(e,r,c),[e,r]);return w(()=>{t&&(n.fixes!==c.fixes||n.nodes!==c.nodes)&&a({...c})},[d,r,t]),w(()=>{if(!o)return;let b=v=>{u.current&&!u.current.contains(v.target)&&i(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[o]),t?g(C,{children:[d,m("button",{onClick:()=>i(!0),style:{position:"fixed",bottom:25,right:25,width:60,height:60,borderRadius:"50%",background:"#1a202c",color:"white",border:"none",cursor:"pointer",zIndex:9999,boxShadow:"0 4px 20px rgba(0,0,0,0.25)",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"28px"},children:"\u267F"}),o&&g("div",{ref:u,style:{position:"fixed",bottom:95,right:25,width:340,background:"#ffffff",borderRadius:"20px",padding:"24px",boxShadow:"0 10px 40px rgba(0,0,0,0.15)",zIndex:1e4,border:"1px solid #f0f0f0",fontFamily:"system-ui, sans-serif"},children:[g("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:"20px"},children:[g("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[m("span",{style:{fontSize:"22px"},children:"\u267F"}),m("strong",{style:{fontSize:"18px"},children:"ADA accessibility"})]}),m("button",{onClick:()=>i(!1),style:{background:"none",border:"none",cursor:"pointer",fontSize:"20px"},children:"\xD7"})]}),m("button",{onClick:()=>l(!r),style:{width:"100%",padding:"16px",borderRadius:"12px",border:"none",cursor:"pointer",fontWeight:"700",background:r?"#dcfce7":"#eff6ff",color:r?"#065f46":"#2563eb",marginBottom:"20px"},children:r?"Disable ADA Engine":"Enable ADA Engine"}),m("div",{style:{borderTop:"1px solid #edf2f7",paddingTop:"16px",fontSize:"12px",color:"#718096"},children:r?g(C,{children:[g("div",{style:{color:"#2d3748",fontWeight:"600",marginBottom:"4px"},children:["yuktai-a11y: ",n.fixes," fixes applied."]}),g("div",{children:["Nodes scanned: ",n.nodes]}),g("div",{style:{marginTop:"4px",color:"#a0aec0"},children:["Render time: ",n.renderTime,"ms"]})]}):m("div",{style:{fontStyle:"italic"},children:"ADA Engine is offline."})})]})]}):m(C,{children:e})}function O(){if(!globalThis.__yuktai_runtime__){let e=new y;e.register(A.name,A),e.register(k.name,k),e.register(E.name,E),e.register(R.name,R),globalThis.__yuktai_runtime__=e}return globalThis.__yuktai_runtime__}var _=O(),q={render:I,list(){return _.getPlugins()},use(e){return _.use(e)}},le=q;export{q as YuktAI,S as YuktAIWrapper,le as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuktishaalaa/yuktai",
3
- "version": "1.0.8",
3
+ "version": "1.0.11",
4
4
  "description": "Privacy-first, offline-first Indic language AI and Web Orchestrator",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",