@yuktishaalaa/yuktai 1.0.5 → 1.0.10
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 +1 -7
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +1 -7
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
"use strict";"use client";var B=Object.create;var v=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,O=Object.prototype.hasOwnProperty;var z=(t,n)=>{for(var a in n)v(t,a,{get:n[a],enumerable:!0})},L=(t,n,a,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of $(n))!O.call(t,i)&&i!==a&&v(t,i,{get:()=>n[i],enumerable:!(e=N(n,i))||e.enumerable});return t};var w=(t,n,a)=>(a=t!=null?B(D(t)):{},L(n||!t||!t.__esModule?v(a,"default",{value:t,enumerable:!0}):a,t)),q=t=>L(v({},"__esModule",{value:!0}),t);var j={};z(j,{YuktAI:()=>W,YuktAIWrapper:()=>S,default:()=>V});module.exports=q(j);var A=class{plugins=new Map;register(n,a){if(!a||typeof a.execute!="function")throw new Error(`Invalid plugin: ${n}`);this.plugins.set(n,a)}use(n){return this.plugins.get(n)}async run(n,a){try{let e=this.use(n);if(!e)throw new Error(`Plugin not found: ${n}`);return await e.execute(a)}catch(e){throw console.error(`[YuktAI Runtime Error in ${n}]:`,e),e}}getPlugins(){return Array.from(this.plugins.keys())}};var C={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}`}};var F=w(require("tesseract.js"),1),b=null,I=null;function H(t){let n=new TextDecoder("utf-8",{fatal:!1}).decode(new Uint8Array(t.slice(0,2e3)));return/[\u0C00-\u0C7F]/.test(n)?"tel":/[\u0900-\u097F]/.test(n)?"hin":/[\u0B80-\u0BFF]/.test(n)?"tam":/[\u4E00-\u9FFF]/.test(n)?"chi_sim":/[\u3040-\u30FF]/.test(n)?"jpn":/[\u0600-\u06FF]/.test(n)?"ara":/[\u0400-\u04FF]/.test(n)?"rus":"eng"}async function K(t){return b&&I===t||(b&&(await b.terminate(),b=null),b=await F.default.createWorker({langPath:"/tessdata",logger:()=>{}}),await b.loadLanguage(t),await b.initialize(t),I=t),b}var R={name:"image.ocr.smart",async execute(t){try{if(!t?.file)return"\u274C No file provided";let n=t.file instanceof Blob?t.file:new Blob([t.file],{type:t.type??"image/png"}),a=t.lang||H(await n.arrayBuffer())||"eng",e=await K(a),{data:i}=await e.recognize(n),o=i.text?.trim();return o?{language:a,confidence:Math.round(i.confidence??0),text:o}:"\u26A0\uFE0F No text detected"}catch(n){return console.error("[ocrSmartPlugin]",n),"\u274C OCR failed"}}};var h={name:"ui.a11y.pro",version:"1.0.1",observer:null,async execute(t){if(!t?.enabled)return this.stopObserver(),"yuktai-a11y: disabled";try{let n=this.applyFixes(t);if(t.autoFix&&this.startObserver(t),this.ensureLiveRegion(),this.announce(`Accessibility active. ${n.fixed} fixes applied.`),t.validate){let a=this.validatePage();return{...n,validation:a}}return n}catch(n){return console.error("WCAG Plugin execution error:",n),{fixed:0,scanned:0,errors:[n.message]}}},applyFixes(t){let n={fixed:0,scanned:0,errors:[]};if(typeof document>"u")return n;let a=t.root||document,e=t.skipFixes||[];try{let i=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]");n.scanned=i.length;let o=0;if(i.forEach(d=>{try{let r=d,l=r.tagName.toLowerCase();if(!e.includes("headings")&&/^h[1-6]$/.test(l)){let c=parseInt(l[1]);c>o+1&&o!==0&&(r.setAttribute("aria-level",String(o+1)),n.fixed++),o=c}if(!e.includes("buttons")&&(l==="a"||l==="button")&&!r.innerText.trim()&&!r.getAttribute("aria-label")){let c=r.getAttribute("title")||r.getAttribute("aria-label")||"Interactive element";r.setAttribute("aria-label",c),n.fixed++}if(e.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"),n.fixed++),r.tabIndex<0&&(r.tabIndex=0,n.fixed++),r._yuktKeyBound||(r.addEventListener("keydown",f=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),r.click())}),r._yuktKeyBound=!0)),!e.includes("forms")&&["input","select","textarea"].includes(l)){if(!r.getAttribute("aria-label")&&!r.getAttribute("aria-labelledby")){let c=r.getAttribute("placeholder")||r.getAttribute("name")||r.getAttribute("title")||l;r.setAttribute("aria-label",c),n.fixed++}r.hasAttribute("required")&&!r.getAttribute("aria-required")&&(r.setAttribute("aria-required","true"),n.fixed++)}!e.includes("images")&&l==="img"&&!r.hasAttribute("alt")&&(r.setAttribute("alt",""),r.setAttribute("aria-hidden","true"),n.fixed++),!e.includes("tables")&&l==="table"&&!d.querySelector("th")&&(r.getAttribute("role")||(r.setAttribute("role","grid"),n.fixed++)),!e.includes("media")&&["video","audio"].includes(l)&&(r.hasAttribute("controls")||(r.setAttribute("controls","true"),n.fixed++)),!e.includes("iframes")&&l==="iframe"&&!r.getAttribute("title")&&(r.setAttribute("title","Embedded content"),n.fixed++)}catch(r){n.errors.push(`Error fixing element ${d.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 d=document.createElement("style");d.id="yukt-reduce-motion",d.textContent="*, *::before, *::after { transition: none !important; animation: none !important; }",document.head.appendChild(d)}}catch(i){n.errors.push(`General error in applyFixes: ${i.message}`)}return n},startObserver(t){this.observer||typeof document>"u"||(this.observer=new MutationObserver(n=>{clearTimeout(this._mutationTimer),this._mutationTimer=setTimeout(()=>{n.forEach(a=>{a.addedNodes.forEach(e=>{e instanceof HTMLElement&&this.applyFixes({...t,root:e})})})},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 n=document.getElementById("yukt-sr-announcer");n&&(n.textContent="",setTimeout(()=>{n.textContent=t},50))},checkContrast(t,n,a=4.5){try{return(i=>{let o=document.createElement("div");o.style.color=i,o.style.backgroundColor=n,document.body.appendChild(o);let d=window.getComputedStyle(o).color,r=window.getComputedStyle(o).backgroundColor;o.remove();let l=d.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/),c=r.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(!l||!c)return 1;let f=this.rgbToLuminance(parseInt(l[1]),parseInt(l[2]),parseInt(l[3])),x=this.rgbToLuminance(parseInt(c[1]),parseInt(c[2]),parseInt(c[3])),s=Math.max(f,x),g=Math.min(f,x);return(s+.05)/(g+.05)})(t)>=a}catch(e){return console.warn("Contrast check failed:",e),!0}},validatePage(){let t=[],n=[];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"),n.push('Add lang attribute to <html> element (e.g., <html lang="en">)')),document.title||(t.push("Missing page title"),n.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"),n.push("Ensure interactive elements are keyboard accessible"));let e=document.querySelectorAll("img:not([alt])");e.length>0&&(t.push(`${e.length} images missing alt text`),n.push("Add descriptive alt text to all images"));let i=Array.from(document.querySelectorAll("h1,h2,h3,h4,h5,h6")),o=0;return i.forEach((r,l)=>{let c=parseInt(r.tagName[1]);l>0&&c>o+1&&(t.push(`Skipped heading level: ${r.tagName} after h${o}`),n.push("Ensure heading hierarchy is sequential")),o=c}),{score:Math.max(0,100-t.length*10),issues:t,recommendations:n}}};var y=w(require("react"),1),T=w(require("react-dom/client"),1),_=require("react/jsx-runtime");function k(t,n=!0){if(!n||!y.default.isValidElement(t))return t;let a=t,e={...a.props},i=a.type;["input","textarea","select"].includes(i)&&!e["aria-label"]&&!e["aria-labelledby"]&&(e["aria-label"]=e.placeholder||e.name||`${i} input`),i==="button"&&!e["aria-label"]&&!e.children&&(e["aria-label"]="action button"),i==="a"&&(e.href&&!e["aria-label"]&&!e.children&&(e["aria-label"]=`Link to ${e.href}`),e.target==="_blank"&&!e.rel&&(e.rel="noopener noreferrer")),i==="img"&&(e.alt===void 0||e.alt===null)&&(e.alt="",e["aria-hidden"]="true"),["video","audio","iframe"].includes(i)&&(e.title||(e.title=e.name||`${i} content`));let o={nav:"navigation",header:"banner",footer:"contentinfo",main:"main",aside:"complementary",section:"region"};if(o[i]&&(e.role||(e.role=o[i]),i==="section"&&!e["aria-label"]&&e.title&&(e["aria-label"]=e.title)),i==="table"&&(e.role||(e.role="table"),e["aria-label"]||(e["aria-label"]="Data representation")),["ul","ol"].includes(i)&&!e.role&&(e.role="list"),i==="li"&&!e.role&&(e.role="listitem"),(i==="div"||i==="span"||i==="section")&&e.onClick&&(e.role||(e.role="button"),e.tabIndex===void 0&&(e.tabIndex=0),!e.onKeyDown)){let r=e.onClick;e.onKeyDown=l=>{(l.key==="Enter"||l.key===" ")&&(l.preventDefault(),r(l))}}["h1","h2","h3","h4","h5","h6"].includes(i)&&!e.id&&typeof e.children=="string"&&(e.id=e.children.toLowerCase().trim().replace(/\s+/g,"-")),i==="dialog"&&(e["aria-modal"]||(e["aria-modal"]="true"));let d=y.default.Children.map(e.children,r=>y.default.isValidElement(r)?k(r,n):r);return y.default.cloneElement(a,e,d)}function M(t,n,a=!0){let e=document.querySelector(n);if(!e)return;let i=k(t,a);T.default.createRoot(e).render((0,_.jsx)(y.default.StrictMode,{children:i}))}var m=require("react");var u=require("react/jsx-runtime"),G={enabled:!0,highContrast:!1,dyslexiaFont:!1,fontScale:100,wcagLevel:"AA"};function S({children:t}){let[n,a]=(0,m.useState)(!1),[e,i]=(0,m.useState)(!1),[o,d]=(0,m.useState)(G),r=(0,m.useRef)(null),l=(0,m.useRef)(null);(0,m.useEffect)(()=>(a(!0),(async()=>await h.execute({enabled:o.enabled,autoFix:!0,level:o.wcagLevel}))(),()=>h.stopObserver()),[]);let c=(0,m.useCallback)(async s=>{await h.execute({enabled:s.enabled,highContrast:s.highContrast,autoFix:!0,level:s.wcagLevel}),document.documentElement.style.fontSize=`${s.fontScale}%`;let g="yuktai-dyslexia-css",p=document.getElementById(g);s.dyslexiaFont?p||(p=document.createElement("style"),p.id=g,p.textContent=`
|
|
2
|
-
body, body * {
|
|
3
|
-
font-family: 'OpenDyslexic', 'Georgia', serif !important;
|
|
4
|
-
line-height: 1.6 !important;
|
|
5
|
-
letter-spacing: 0.02em !important;
|
|
6
|
-
}
|
|
7
|
-
`,document.head.appendChild(p)):p?.remove()},[]),f=(s,g)=>{let p={...o,[s]:g};d(p),c(p)};(0,m.useEffect)(()=>{if(!e)return;let s=g=>{!r.current?.contains(g.target)&&!l.current?.contains(g.target)&&i(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[e]);let x=n?k(t,o.enabled):t;return(0,u.jsxs)(u.Fragment,{children:[x,(0,u.jsx)("button",{ref:l,onClick:s=>{s.stopPropagation(),i(!e)},"aria-label":"Accessibility Menu","aria-expanded":e,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",transition:"transform 0.2s"},onMouseEnter:s=>s.currentTarget.style.transform="scale(1.1)",onMouseLeave:s=>s.currentTarget.style.transform="scale(1)",children:(0,u.jsx)("svg",{viewBox:"0 0 24 24",width:"30",height:"30",fill:"currentColor",children:(0,u.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"})})}),e&&(0,u.jsxs)("div",{ref:r,role:"dialog","aria-modal":"true",style:{position:"fixed",bottom:90,right:20,width:300,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:"system-ui, -apple-system, sans-serif"},children:[(0,u.jsx)("h3",{style:{margin:"0 0 20px",fontSize:18,fontWeight:700},children:"Accessibility Suite"}),(0,u.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[(0,u.jsxs)("label",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:14,fontWeight:500},children:["AI Auto-Fix Engine",(0,u.jsx)("input",{type:"checkbox",checked:o.enabled,onChange:s=>f("enabled",s.target.checked),style:{cursor:"pointer",width:18,height:18}})]}),(0,u.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[(0,u.jsxs)("span",{style:{fontSize:13,color:"#64748b"},children:["Font Scale: ",o.fontScale,"%"]}),(0,u.jsx)("input",{type:"range",min:"100",max:"200",step:"10",value:o.fontScale,onChange:s=>f("fontScale",parseInt(s.target.value)),style:{cursor:"pointer",accentColor:"#0d9488"}})]}),(0,u.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[(0,u.jsx)("span",{style:{fontSize:13,color:"#64748b"},children:"Compliance Level"}),(0,u.jsx)("div",{style:{display:"flex",gap:4},children:["A","AA","AAA"].map(s=>(0,u.jsx)("button",{onClick:()=>f("wcagLevel",s),style:{flex:1,padding:"8px 0",borderRadius:8,cursor:"pointer",border:o.wcagLevel===s?"2px solid #0d9488":"1px solid #e2e8f0",background:o.wcagLevel===s?"#f0fdfa":"#fff",color:o.wcagLevel===s?"#0d9488":"#64748b",fontSize:12,fontWeight:"bold"},children:s},s))})]}),(0,u.jsxs)("label",{style:{display:"flex",justifyContent:"space-between",fontSize:14,cursor:"pointer"},children:["High Contrast",(0,u.jsx)("input",{type:"checkbox",checked:o.highContrast,onChange:s=>f("highContrast",s.target.checked)})]}),(0,u.jsxs)("label",{style:{display:"flex",justifyContent:"space-between",fontSize:14,cursor:"pointer"},children:["Dyslexia Font",(0,u.jsx)("input",{type:"checkbox",checked:o.dyslexiaFont,onChange:s=>f("dyslexiaFont",s.target.checked)})]})]}),(0,u.jsx)("button",{onClick:()=>i(!1),style:{width:"100%",marginTop:24,padding:12,background:"#0f172a",color:"#fff",border:"none",borderRadius:10,fontWeight:600,cursor:"pointer"},children:"Done"})]})]})}function Y(){if(!globalThis.__yuktai_runtime__){let t=new A;t.register(C.name,C),t.register(E.name,E),t.register(R.name,R),t.register(h.name,h),globalThis.__yuktai_runtime__=t}return globalThis.__yuktai_runtime__}var P=Y(),W={render:M,list(){return P.getPlugins()},use(t){return P.use(t)}},V=W;0&&(module.exports={YuktAI,YuktAIWrapper});
|
|
1
|
+
"use strict";"use client";var B=Object.create;var h=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var D=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var z=(e,t)=>{for(var o in t)h(e,o,{get:t[o],enumerable:!0})},T=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let l of O(t))!$.call(e,l)&&l!==o&&h(e,l,{get:()=>t[l],enumerable:!(i=N(t,l))||i.enumerable});return e};var A=(e,t,o)=>(o=e!=null?B(D(e)):{},T(t||!e||!e.__esModule?h(o,"default",{value:e,enumerable:!0}):o,e)),q=e=>T(h({},"__esModule",{value:!0}),e);var G={};z(G,{YuktAI:()=>P,YuktAIWrapper:()=>C,default:()=>Y});module.exports=q(G);var x=class{plugins=new Map;register(t,o){if(!o||typeof o.execute!="function")throw new Error(`Invalid plugin: ${t}`);this.plugins.set(t,o)}use(t){return this.plugins.get(t)}async run(t,o){try{let i=this.use(t);if(!i)throw new Error(`Plugin not found: ${t}`);return await i.execute(o)}catch(i){throw console.error(`[YuktAI Runtime Error in ${t}]:`,i),i}}getPlugins(){return Array.from(this.plugins.keys())}};var k={name:"ai.text",async execute(e){return`\u{1F916} YuktAI says: ${e}`}};var w={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 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"}),o=e.lang||W(await t.arrayBuffer())||"eng",i=await H(o),{data:l}=await i.recognize(t),r=l.text?.trim();return r?{language:o,confidence:Math.round(l.confidence??0),text:r}:"\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 o=this.validatePage();return{...t,validation:o}}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 o=e.root||document,i=e.skipFixes||[];try{let l=o.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 r=0;if(l.forEach(s=>{try{let n=s,u=n.tagName.toLowerCase();if(!i.includes("headings")&&/^h[1-6]$/.test(u)){let c=parseInt(u[1]);c>r+1&&r!==0&&(n.setAttribute("aria-level",String(r+1)),t.fixed++),r=c}if(!i.includes("buttons")&&(u==="a"||u==="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(i.includes("clickables")||(n.hasAttribute("onclick")||typeof window<"u"&&window.getComputedStyle(n).cursor==="pointer")&&!["button","a","input","select","textarea"].includes(u)&&(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)),!i.includes("forms")&&["input","select","textarea"].includes(u)){if(!n.getAttribute("aria-label")&&!n.getAttribute("aria-labelledby")){let c=n.getAttribute("placeholder")||n.getAttribute("name")||n.getAttribute("title")||u;n.setAttribute("aria-label",c),t.fixed++}n.hasAttribute("required")&&!n.getAttribute("aria-required")&&(n.setAttribute("aria-required","true"),t.fixed++)}!i.includes("images")&&u==="img"&&!n.hasAttribute("alt")&&(n.setAttribute("alt",""),n.setAttribute("aria-hidden","true"),t.fixed++),!i.includes("tables")&&u==="table"&&!s.querySelector("th")&&(n.getAttribute("role")||(n.setAttribute("role","grid"),t.fixed++)),!i.includes("media")&&["video","audio"].includes(u)&&(n.hasAttribute("controls")||(n.setAttribute("controls","true"),t.fixed++)),!i.includes("iframes")&&u==="iframe"&&!n.getAttribute("title")&&(n.setAttribute("title","Embedded content"),t.fixed++)}catch(n){t.errors.push(`Error fixing element ${s.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 s=document.createElement("style");s.id="yukt-reduce-motion",s.textContent="*, *::before, *::after { transition: none !important; animation: none !important; }",document.head.appendChild(s)}}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(o=>{o.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,o=4.5){try{return(l=>{let r=document.createElement("div");r.style.color=l,r.style.backgroundColor=t,document.body.appendChild(r);let s=window.getComputedStyle(r).color,n=window.getComputedStyle(r).backgroundColor;r.remove();let u=s.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/),c=n.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(!u||!c)return 1;let d=this.rgbToLuminance(parseInt(u[1]),parseInt(u[2]),parseInt(u[3])),f=this.rgbToLuminance(parseInt(c[1]),parseInt(c[2]),parseInt(c[3])),p=Math.max(d,f),y=Math.min(d,f);return(p+.05)/(y+.05)})(e)>=o}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 l=Array.from(document.querySelectorAll("h1,h2,h3,h4,h5,h6")),r=0;return l.forEach((n,u)=>{let c=parseInt(n.tagName[1]);u>0&&c>r+1&&(e.push(`Skipped heading level: ${n.tagName} after h${r}`),t.push("Ensure heading hierarchy is sequential")),r=c}),{score:Math.max(0,100-e.length*10),issues:e,recommendations:t}}};var b=A(require("react"),1),_=A(require("react-dom/client"),1),F=require("react/jsx-runtime");function v(e,t=!0,o={fixes:0,nodes:0,renderTime:0}){let i=o.nodes===0?performance.now():0;if(!b.default.isValidElement(e))return e;o.nodes++;let l=e,r={...l.props},s=l.type,n=!1;if(t){if(["input","textarea","select"].includes(s)&&!r["aria-label"]&&!r["aria-labelledby"]&&(r["aria-label"]=r.placeholder||r.name||`${s} field`,n=!0),s==="img"&&(r.alt===void 0||r.alt===null)&&(r.alt="",r["aria-hidden"]="true",n=!0),["video","audio","iframe"].includes(s)&&!r.title&&(r.title=r.name||`${s} content`,n=!0),s==="a"&&r.target==="_blank"&&!r.rel&&(r.rel="noopener noreferrer",n=!0),(s==="div"||s==="span")&&r.onClick&&(r.role||(r.role="button",n=!0),r.tabIndex===void 0&&(r.tabIndex=0,n=!0),!r.onKeyDown)){let f=r.onClick;r.onKeyDown=p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),f(p))},n=!0}let d={nav:"navigation",header:"banner",footer:"contentinfo",main:"main"};d[s]&&!r.role&&(r.role=d[s],n=!0),["ul","ol"].includes(s)&&!r.role&&(r.role="list",n=!0),s==="li"&&!r.role&&(r.role="listitem",n=!0),n&&o.fixes++}let u=b.default.Children.map(r.children,d=>b.default.isValidElement(d)?v(d,t,o):d),c=b.default.cloneElement(l,r,u);return i>0&&(o.renderTime=parseFloat((performance.now()-i).toFixed(2))),c}function M(e,t,o=!0){let i=document.querySelector(t);if(!i)return;let r=v(e,o,{fixes:0,nodes:0,renderTime:0});_.default.createRoot(i).render((0,F.jsx)(b.default.StrictMode,{children:r}))}var m=require("react");var a=require("react/jsx-runtime");function C({children:e}){let[t,o]=(0,m.useState)(!1),[i,l]=(0,m.useState)(!1),[r,s]=(0,m.useState)(!1),[n,u]=(0,m.useState)({fixes:0,nodes:0,renderTime:0}),c=(0,m.useRef)(null);(0,m.useEffect)(()=>{o(!0)},[]);let d=(0,m.useMemo)(()=>{let f={fixes:0,nodes:0,renderTime:0},p=v(e,i,f);return t&&setTimeout(()=>{u(y=>y.fixes===f.fixes&&y.nodes===f.nodes?y:{...f})},0),p},[e,i,t]);return(0,m.useEffect)(()=>{if(!r)return;let f=p=>{c.current&&!c.current.contains(p.target)&&s(!1)};return document.addEventListener("mousedown",f),()=>document.removeEventListener("mousedown",f)},[r]),t?(0,a.jsxs)(a.Fragment,{children:[d,(0,a.jsx)("button",{onClick:()=>s(!0),"aria-label":"Open Accessibility Menu",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"}),r&&(0,a.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, -apple-system, sans-serif"},children:[(0,a.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"20px"},children:[(0,a.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[(0,a.jsx)("span",{style:{fontSize:"22px"},children:"\u267F"}),(0,a.jsx)("strong",{style:{fontSize:"18px",color:"#1a202c"},children:"ADA accessibility"})]}),(0,a.jsx)("button",{onClick:()=>s(!1),style:{background:"none",border:"none",fontSize:"24px",color:"#a0aec0",cursor:"pointer"},children:"\xD7"})]}),(0,a.jsx)("button",{onClick:()=>l(!i),style:{width:"100%",padding:"16px",borderRadius:"12px",border:"none",cursor:"pointer",fontWeight:"700",fontSize:"16px",background:i?"#dcfce7":"#eff6ff",color:i?"#065f46":"#2563eb",transition:"all 0.2s ease-in-out",marginBottom:"20px"},children:i?"Disable ADA Engine":"Enable ADA Engine"}),(0,a.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"16px",marginBottom:"24px"},children:[(0,a.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"12px",fontSize:"14px",color:"#4a5568",cursor:"pointer"},children:[(0,a.jsx)("input",{type:"checkbox",checked:i,readOnly:!0,style:{width:"16px",height:"16px"}}),"High contrast"]}),(0,a.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:"12px",fontSize:"14px",color:"#4a5568",cursor:"pointer"},children:[(0,a.jsx)("input",{type:"checkbox",checked:i,readOnly:!0,style:{width:"16px",height:"16px"}}),"Keyboard navigation hints"]})]}),(0,a.jsx)("div",{style:{borderTop:"1px solid #edf2f7",paddingTop:"16px",fontSize:"12px",lineHeight:"1.5",color:"#718096"},children:i?(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{style:{color:"#2d3748",fontWeight:"600",marginBottom:"4px"},children:["yuktai-a11y: ",n.fixes," fixes applied."]}),(0,a.jsxs)("div",{children:["Nodes scanned: ",n.nodes]}),(0,a.jsxs)("div",{children:["Render time: ",(0,a.jsxs)("span",{style:{color:"#4a5568"},children:[n.renderTime,"ms"]})]})]}):(0,a.jsx)("div",{style:{color:"#a0aec0",fontStyle:"italic"},children:"ADA Engine is offline."})}),(0,a.jsx)("button",{onClick:()=>s(!1),style:{width:"100%",marginTop:"20px",padding:"12px",background:"#1a202c",color:"#fff",borderRadius:"8px",border:"none",cursor:"pointer",fontWeight:"600"},children:"Done"})]})]}):(0,a.jsx)(a.Fragment,{children:e})}function K(){if(!globalThis.__yuktai_runtime__){let e=new x;e.register(k.name,k),e.register(w.name,w),e.register(E.name,E),e.register(R.name,R),globalThis.__yuktai_runtime__=e}return globalThis.__yuktai_runtime__}var L=K(),P={render:M,list(){return L.getPlugins()},use(e){return L.use(e)}},Y=P;0&&(module.exports={YuktAI,YuktAIWrapper});
|
package/dist/index.d.cts
CHANGED
|
@@ -21,14 +21,13 @@ declare class Runtime {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* Standard DOM Mount Renderer
|
|
24
|
+
* Standard DOM Mount Renderer for legacy mounting
|
|
25
25
|
*/
|
|
26
26
|
declare function render(element: React.ReactNode, selector: string, enabled?: boolean): void;
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
declare function YuktAIWrapper({ children }: {
|
|
29
29
|
children?: React.ReactNode;
|
|
30
|
-
}
|
|
31
|
-
declare function YuktAIWrapper({ children }: YuktAIWrapperProps): react_jsx_runtime.JSX.Element;
|
|
30
|
+
}): react_jsx_runtime.JSX.Element;
|
|
32
31
|
|
|
33
32
|
declare global {
|
|
34
33
|
var __yuktai_runtime__: Runtime | undefined;
|
package/dist/index.d.ts
CHANGED
|
@@ -21,14 +21,13 @@ declare class Runtime {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* Standard DOM Mount Renderer
|
|
24
|
+
* Standard DOM Mount Renderer for legacy mounting
|
|
25
25
|
*/
|
|
26
26
|
declare function render(element: React.ReactNode, selector: string, enabled?: boolean): void;
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
declare function YuktAIWrapper({ children }: {
|
|
29
29
|
children?: React.ReactNode;
|
|
30
|
-
}
|
|
31
|
-
declare function YuktAIWrapper({ children }: YuktAIWrapperProps): react_jsx_runtime.JSX.Element;
|
|
30
|
+
}): react_jsx_runtime.JSX.Element;
|
|
32
31
|
|
|
33
32
|
declare global {
|
|
34
33
|
var __yuktai_runtime__: Runtime | undefined;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1 @@
|
|
|
1
|
-
"use client";var v=class{plugins=new Map;register(n,l){if(!l||typeof l.execute!="function")throw new Error(`Invalid plugin: ${n}`);this.plugins.set(n,l)}use(n){return this.plugins.get(n)}async run(n,l){try{let e=this.use(n);if(!e)throw new Error(`Plugin not found: ${n}`);return await e.execute(l)}catch(e){throw console.error(`[YuktAI Runtime Error in ${n}]:`,e),e}}getPlugins(){return Array.from(this.plugins.keys())}};var k={name:"ai.text",async execute(t){return`\u{1F916} YuktAI says: ${t}`}};var w={name:"voice.text",async execute(t){return!t||t.trim()===""?"\u{1F3A4} No speech detected":`\u{1F3A4} You said: ${t}`}};import M from"tesseract.js";var p=null,R=null;function _(t){let n=new TextDecoder("utf-8",{fatal:!1}).decode(new Uint8Array(t.slice(0,2e3)));return/[\u0C00-\u0C7F]/.test(n)?"tel":/[\u0900-\u097F]/.test(n)?"hin":/[\u0B80-\u0BFF]/.test(n)?"tam":/[\u4E00-\u9FFF]/.test(n)?"chi_sim":/[\u3040-\u30FF]/.test(n)?"jpn":/[\u0600-\u06FF]/.test(n)?"ara":/[\u0400-\u04FF]/.test(n)?"rus":"eng"}async function P(t){return p&&R===t||(p&&(await p.terminate(),p=null),p=await M.createWorker({langPath:"/tessdata",logger:()=>{}}),await p.loadLanguage(t),await p.initialize(t),R=t),p}var C={name:"image.ocr.smart",async execute(t){try{if(!t?.file)return"\u274C No file provided";let n=t.file instanceof Blob?t.file:new Blob([t.file],{type:t.type??"image/png"}),l=t.lang||_(await n.arrayBuffer())||"eng",e=await P(l),{data:i}=await e.recognize(n),o=i.text?.trim();return o?{language:l,confidence:Math.round(i.confidence??0),text:o}:"\u26A0\uFE0F No text detected"}catch(n){return console.error("[ocrSmartPlugin]",n),"\u274C OCR failed"}}};var h={name:"ui.a11y.pro",version:"1.0.1",observer:null,async execute(t){if(!t?.enabled)return this.stopObserver(),"yuktai-a11y: disabled";try{let n=this.applyFixes(t);if(t.autoFix&&this.startObserver(t),this.ensureLiveRegion(),this.announce(`Accessibility active. ${n.fixed} fixes applied.`),t.validate){let l=this.validatePage();return{...n,validation:l}}return n}catch(n){return console.error("WCAG Plugin execution error:",n),{fixed:0,scanned:0,errors:[n.message]}}},applyFixes(t){let n={fixed:0,scanned:0,errors:[]};if(typeof document>"u")return n;let l=t.root||document,e=t.skipFixes||[];try{let i=l.querySelectorAll("a,button,input,select,textarea,img,table,[onclick],[tabindex],h1,h2,h3,h4,h5,h6,iframe,video,audio,[role],[aria-label],[aria-labelledby]");n.scanned=i.length;let o=0;if(i.forEach(c=>{try{let r=c,s=r.tagName.toLowerCase();if(!e.includes("headings")&&/^h[1-6]$/.test(s)){let u=parseInt(s[1]);u>o+1&&o!==0&&(r.setAttribute("aria-level",String(o+1)),n.fixed++),o=u}if(!e.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),n.fixed++}if(e.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"),n.fixed++),r.tabIndex<0&&(r.tabIndex=0,n.fixed++),r._yuktKeyBound||(r.addEventListener("keydown",d=>{(d.key==="Enter"||d.key===" ")&&(d.preventDefault(),r.click())}),r._yuktKeyBound=!0)),!e.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),n.fixed++}r.hasAttribute("required")&&!r.getAttribute("aria-required")&&(r.setAttribute("aria-required","true"),n.fixed++)}!e.includes("images")&&s==="img"&&!r.hasAttribute("alt")&&(r.setAttribute("alt",""),r.setAttribute("aria-hidden","true"),n.fixed++),!e.includes("tables")&&s==="table"&&!c.querySelector("th")&&(r.getAttribute("role")||(r.setAttribute("role","grid"),n.fixed++)),!e.includes("media")&&["video","audio"].includes(s)&&(r.hasAttribute("controls")||(r.setAttribute("controls","true"),n.fixed++)),!e.includes("iframes")&&s==="iframe"&&!r.getAttribute("title")&&(r.setAttribute("title","Embedded content"),n.fixed++)}catch(r){n.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(i){n.errors.push(`General error in applyFixes: ${i.message}`)}return n},startObserver(t){this.observer||typeof document>"u"||(this.observer=new MutationObserver(n=>{clearTimeout(this._mutationTimer),this._mutationTimer=setTimeout(()=>{n.forEach(l=>{l.addedNodes.forEach(e=>{e instanceof HTMLElement&&this.applyFixes({...t,root:e})})})},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 n=document.getElementById("yukt-sr-announcer");n&&(n.textContent="",setTimeout(()=>{n.textContent=t},50))},checkContrast(t,n,l=4.5){try{return(i=>{let o=document.createElement("div");o.style.color=i,o.style.backgroundColor=n,document.body.appendChild(o);let c=window.getComputedStyle(o).color,r=window.getComputedStyle(o).backgroundColor;o.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])),a=Math.max(d,x),m=Math.min(d,x);return(a+.05)/(m+.05)})(t)>=l}catch(e){return console.warn("Contrast check failed:",e),!0}},validatePage(){let t=[],n=[];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"),n.push('Add lang attribute to <html> element (e.g., <html lang="en">)')),document.title||(t.push("Missing page title"),n.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"),n.push("Ensure interactive elements are keyboard accessible"));let e=document.querySelectorAll("img:not([alt])");e.length>0&&(t.push(`${e.length} images missing alt text`),n.push("Add descriptive alt text to all images"));let i=Array.from(document.querySelectorAll("h1,h2,h3,h4,h5,h6")),o=0;return i.forEach((r,s)=>{let u=parseInt(r.tagName[1]);s>0&&u>o+1&&(t.push(`Skipped heading level: ${r.tagName} after h${o}`),n.push("Ensure heading hierarchy is sequential")),o=u}),{score:Math.max(0,100-t.length*10),issues:t,recommendations:n}}};import y from"react";import W from"react-dom/client";import{jsx as B}from"react/jsx-runtime";function A(t,n=!0){if(!n||!y.isValidElement(t))return t;let l=t,e={...l.props},i=l.type;["input","textarea","select"].includes(i)&&!e["aria-label"]&&!e["aria-labelledby"]&&(e["aria-label"]=e.placeholder||e.name||`${i} input`),i==="button"&&!e["aria-label"]&&!e.children&&(e["aria-label"]="action button"),i==="a"&&(e.href&&!e["aria-label"]&&!e.children&&(e["aria-label"]=`Link to ${e.href}`),e.target==="_blank"&&!e.rel&&(e.rel="noopener noreferrer")),i==="img"&&(e.alt===void 0||e.alt===null)&&(e.alt="",e["aria-hidden"]="true"),["video","audio","iframe"].includes(i)&&(e.title||(e.title=e.name||`${i} content`));let o={nav:"navigation",header:"banner",footer:"contentinfo",main:"main",aside:"complementary",section:"region"};if(o[i]&&(e.role||(e.role=o[i]),i==="section"&&!e["aria-label"]&&e.title&&(e["aria-label"]=e.title)),i==="table"&&(e.role||(e.role="table"),e["aria-label"]||(e["aria-label"]="Data representation")),["ul","ol"].includes(i)&&!e.role&&(e.role="list"),i==="li"&&!e.role&&(e.role="listitem"),(i==="div"||i==="span"||i==="section")&&e.onClick&&(e.role||(e.role="button"),e.tabIndex===void 0&&(e.tabIndex=0),!e.onKeyDown)){let r=e.onClick;e.onKeyDown=s=>{(s.key==="Enter"||s.key===" ")&&(s.preventDefault(),r(s))}}["h1","h2","h3","h4","h5","h6"].includes(i)&&!e.id&&typeof e.children=="string"&&(e.id=e.children.toLowerCase().trim().replace(/\s+/g,"-")),i==="dialog"&&(e["aria-modal"]||(e["aria-modal"]="true"));let c=y.Children.map(e.children,r=>y.isValidElement(r)?A(r,n):r);return y.cloneElement(l,e,c)}function S(t,n,l=!0){let e=document.querySelector(n);if(!e)return;let i=A(t,l);W.createRoot(e).render(B(y.StrictMode,{children:i}))}import{useState as E,useEffect as L,useRef as I,useCallback as N}from"react";import{Fragment as D,jsx as f,jsxs as b}from"react/jsx-runtime";var $={enabled:!0,highContrast:!1,dyslexiaFont:!1,fontScale:100,wcagLevel:"AA"};function F({children:t}){let[n,l]=E(!1),[e,i]=E(!1),[o,c]=E($),r=I(null),s=I(null);L(()=>(l(!0),(async()=>await h.execute({enabled:o.enabled,autoFix:!0,level:o.wcagLevel}))(),()=>h.stopObserver()),[]);let u=N(async a=>{await h.execute({enabled:a.enabled,highContrast:a.highContrast,autoFix:!0,level:a.wcagLevel}),document.documentElement.style.fontSize=`${a.fontScale}%`;let m="yuktai-dyslexia-css",g=document.getElementById(m);a.dyslexiaFont?g||(g=document.createElement("style"),g.id=m,g.textContent=`
|
|
2
|
-
body, body * {
|
|
3
|
-
font-family: 'OpenDyslexic', 'Georgia', serif !important;
|
|
4
|
-
line-height: 1.6 !important;
|
|
5
|
-
letter-spacing: 0.02em !important;
|
|
6
|
-
}
|
|
7
|
-
`,document.head.appendChild(g)):g?.remove()},[]),d=(a,m)=>{let g={...o,[a]:m};c(g),u(g)};L(()=>{if(!e)return;let a=m=>{!r.current?.contains(m.target)&&!s.current?.contains(m.target)&&i(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[e]);let x=n?A(t,o.enabled):t;return b(D,{children:[x,f("button",{ref:s,onClick:a=>{a.stopPropagation(),i(!e)},"aria-label":"Accessibility Menu","aria-expanded":e,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",transition:"transform 0.2s"},onMouseEnter:a=>a.currentTarget.style.transform="scale(1.1)",onMouseLeave:a=>a.currentTarget.style.transform="scale(1)",children:f("svg",{viewBox:"0 0 24 24",width:"30",height:"30",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"})})}),e&&b("div",{ref:r,role:"dialog","aria-modal":"true",style:{position:"fixed",bottom:90,right:20,width:300,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:"system-ui, -apple-system, sans-serif"},children:[f("h3",{style:{margin:"0 0 20px",fontSize:18,fontWeight:700},children:"Accessibility Suite"}),b("div",{style:{display:"flex",flexDirection:"column",gap:20},children:[b("label",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",fontSize:14,fontWeight:500},children:["AI Auto-Fix Engine",f("input",{type:"checkbox",checked:o.enabled,onChange:a=>d("enabled",a.target.checked),style:{cursor:"pointer",width:18,height:18}})]}),b("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[b("span",{style:{fontSize:13,color:"#64748b"},children:["Font Scale: ",o.fontScale,"%"]}),f("input",{type:"range",min:"100",max:"200",step:"10",value:o.fontScale,onChange:a=>d("fontScale",parseInt(a.target.value)),style:{cursor:"pointer",accentColor:"#0d9488"}})]}),b("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[f("span",{style:{fontSize:13,color:"#64748b"},children:"Compliance Level"}),f("div",{style:{display:"flex",gap:4},children:["A","AA","AAA"].map(a=>f("button",{onClick:()=>d("wcagLevel",a),style:{flex:1,padding:"8px 0",borderRadius:8,cursor:"pointer",border:o.wcagLevel===a?"2px solid #0d9488":"1px solid #e2e8f0",background:o.wcagLevel===a?"#f0fdfa":"#fff",color:o.wcagLevel===a?"#0d9488":"#64748b",fontSize:12,fontWeight:"bold"},children:a},a))})]}),b("label",{style:{display:"flex",justifyContent:"space-between",fontSize:14,cursor:"pointer"},children:["High Contrast",f("input",{type:"checkbox",checked:o.highContrast,onChange:a=>d("highContrast",a.target.checked)})]}),b("label",{style:{display:"flex",justifyContent:"space-between",fontSize:14,cursor:"pointer"},children:["Dyslexia Font",f("input",{type:"checkbox",checked:o.dyslexiaFont,onChange:a=>d("dyslexiaFont",a.target.checked)})]})]}),f("button",{onClick:()=>i(!1),style:{width:"100%",marginTop:24,padding:12,background:"#0f172a",color:"#fff",border:"none",borderRadius:10,fontWeight:600,cursor:"pointer"},children:"Done"})]})]})}function O(){if(!globalThis.__yuktai_runtime__){let t=new v;t.register(k.name,k),t.register(w.name,w),t.register(C.name,C),t.register(h.name,h),globalThis.__yuktai_runtime__=t}return globalThis.__yuktai_runtime__}var T=O(),z={render:S,list(){return T.getPlugins()},use(t){return T.use(t)}},de=z;export{z as YuktAI,F as YuktAIWrapper,de as default};
|
|
1
|
+
"use client";var h=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 i=this.use(t);if(!i)throw new Error(`Plugin not found: ${t}`);return await i.execute(s)}catch(i){throw console.error(`[YuktAI Runtime Error in ${t}]:`,i),i}}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 M from"tesseract.js";var g=null,C=null;function F(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 g&&C===e||(g&&(await g.terminate(),g=null),g=await M.createWorker({langPath:"/tessdata",logger:()=>{}}),await g.loadLanguage(e),await g.initialize(e),C=e),g}var w={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||F(await t.arrayBuffer())||"eng",i=await L(s),{data:u}=await i.recognize(t),r=u.text?.trim();return r?{language:s,confidence:Math.round(u.confidence??0),text:r}:"\u26A0\uFE0F No text detected"}catch(t){return console.error("[ocrSmartPlugin]",t),"\u274C OCR failed"}}};var E={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,i=e.skipFixes||[];try{let u=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=u.length;let r=0;if(u.forEach(o=>{try{let n=o,a=n.tagName.toLowerCase();if(!i.includes("headings")&&/^h[1-6]$/.test(a)){let l=parseInt(a[1]);l>r+1&&r!==0&&(n.setAttribute("aria-level",String(r+1)),t.fixed++),r=l}if(!i.includes("buttons")&&(a==="a"||a==="button")&&!n.innerText.trim()&&!n.getAttribute("aria-label")){let l=n.getAttribute("title")||n.getAttribute("aria-label")||"Interactive element";n.setAttribute("aria-label",l),t.fixed++}if(i.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)),!i.includes("forms")&&["input","select","textarea"].includes(a)){if(!n.getAttribute("aria-label")&&!n.getAttribute("aria-labelledby")){let l=n.getAttribute("placeholder")||n.getAttribute("name")||n.getAttribute("title")||a;n.setAttribute("aria-label",l),t.fixed++}n.hasAttribute("required")&&!n.getAttribute("aria-required")&&(n.setAttribute("aria-required","true"),t.fixed++)}!i.includes("images")&&a==="img"&&!n.hasAttribute("alt")&&(n.setAttribute("alt",""),n.setAttribute("aria-hidden","true"),t.fixed++),!i.includes("tables")&&a==="table"&&!o.querySelector("th")&&(n.getAttribute("role")||(n.setAttribute("role","grid"),t.fixed++)),!i.includes("media")&&["video","audio"].includes(a)&&(n.hasAttribute("controls")||(n.setAttribute("controls","true"),t.fixed++)),!i.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(s=>{s.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,s=4.5){try{return(u=>{let r=document.createElement("div");r.style.color=u,r.style.backgroundColor=t,document.body.appendChild(r);let o=window.getComputedStyle(r).color,n=window.getComputedStyle(r).backgroundColor;r.remove();let a=o.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/),l=n.match(/rgb\((\d+),\s*(\d+),\s*(\d+)\)/);if(!a||!l)return 1;let c=this.rgbToLuminance(parseInt(a[1]),parseInt(a[2]),parseInt(a[3])),d=this.rgbToLuminance(parseInt(l[1]),parseInt(l[2]),parseInt(l[3])),p=Math.max(c,d),b=Math.min(c,d);return(p+.05)/(b+.05)})(e)>=s}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 u=Array.from(document.querySelectorAll("h1,h2,h3,h4,h5,h6")),r=0;return u.forEach((n,a)=>{let l=parseInt(n.tagName[1]);a>0&&l>r+1&&(e.push(`Skipped heading level: ${n.tagName} after h${r}`),t.push("Ensure heading hierarchy is sequential")),r=l}),{score:Math.max(0,100-e.length*10),issues:e,recommendations:t}}};import y from"react";import P from"react-dom/client";import{jsx as B}from"react/jsx-runtime";function x(e,t=!0,s={fixes:0,nodes:0,renderTime:0}){let i=s.nodes===0?performance.now():0;if(!y.isValidElement(e))return e;s.nodes++;let u=e,r={...u.props},o=u.type,n=!1;if(t){if(["input","textarea","select"].includes(o)&&!r["aria-label"]&&!r["aria-labelledby"]&&(r["aria-label"]=r.placeholder||r.name||`${o} field`,n=!0),o==="img"&&(r.alt===void 0||r.alt===null)&&(r.alt="",r["aria-hidden"]="true",n=!0),["video","audio","iframe"].includes(o)&&!r.title&&(r.title=r.name||`${o} content`,n=!0),o==="a"&&r.target==="_blank"&&!r.rel&&(r.rel="noopener noreferrer",n=!0),(o==="div"||o==="span")&&r.onClick&&(r.role||(r.role="button",n=!0),r.tabIndex===void 0&&(r.tabIndex=0,n=!0),!r.onKeyDown)){let d=r.onClick;r.onKeyDown=p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),d(p))},n=!0}let c={nav:"navigation",header:"banner",footer:"contentinfo",main:"main"};c[o]&&!r.role&&(r.role=c[o],n=!0),["ul","ol"].includes(o)&&!r.role&&(r.role="list",n=!0),o==="li"&&!r.role&&(r.role="listitem",n=!0),n&&s.fixes++}let a=y.Children.map(r.children,c=>y.isValidElement(c)?x(c,t,s):c),l=y.cloneElement(u,r,a);return i>0&&(s.renderTime=parseFloat((performance.now()-i).toFixed(2))),l}function T(e,t,s=!0){let i=document.querySelector(t);if(!i)return;let r=x(e,s,{fixes:0,nodes:0,renderTime:0});P.createRoot(i).render(B(y.StrictMode,{children:r}))}import{useState as v,useEffect as I,useRef as N,useMemo as O}from"react";import{Fragment as R,jsx as m,jsxs as f}from"react/jsx-runtime";function S({children:e}){let[t,s]=v(!1),[i,u]=v(!1),[r,o]=v(!1),[n,a]=v({fixes:0,nodes:0,renderTime:0}),l=N(null);I(()=>{s(!0)},[]);let c=O(()=>{let d={fixes:0,nodes:0,renderTime:0},p=x(e,i,d);return t&&setTimeout(()=>{a(b=>b.fixes===d.fixes&&b.nodes===d.nodes?b:{...d})},0),p},[e,i,t]);return I(()=>{if(!r)return;let d=p=>{l.current&&!l.current.contains(p.target)&&o(!1)};return document.addEventListener("mousedown",d),()=>document.removeEventListener("mousedown",d)},[r]),t?f(R,{children:[c,m("button",{onClick:()=>o(!0),"aria-label":"Open Accessibility Menu",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"}),r&&f("div",{ref:l,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, -apple-system, sans-serif"},children:[f("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"center",marginBottom:"20px"},children:[f("div",{style:{display:"flex",alignItems:"center",gap:"12px"},children:[m("span",{style:{fontSize:"22px"},children:"\u267F"}),m("strong",{style:{fontSize:"18px",color:"#1a202c"},children:"ADA accessibility"})]}),m("button",{onClick:()=>o(!1),style:{background:"none",border:"none",fontSize:"24px",color:"#a0aec0",cursor:"pointer"},children:"\xD7"})]}),m("button",{onClick:()=>u(!i),style:{width:"100%",padding:"16px",borderRadius:"12px",border:"none",cursor:"pointer",fontWeight:"700",fontSize:"16px",background:i?"#dcfce7":"#eff6ff",color:i?"#065f46":"#2563eb",transition:"all 0.2s ease-in-out",marginBottom:"20px"},children:i?"Disable ADA Engine":"Enable ADA Engine"}),f("div",{style:{display:"flex",flexDirection:"column",gap:"16px",marginBottom:"24px"},children:[f("label",{style:{display:"flex",alignItems:"center",gap:"12px",fontSize:"14px",color:"#4a5568",cursor:"pointer"},children:[m("input",{type:"checkbox",checked:i,readOnly:!0,style:{width:"16px",height:"16px"}}),"High contrast"]}),f("label",{style:{display:"flex",alignItems:"center",gap:"12px",fontSize:"14px",color:"#4a5568",cursor:"pointer"},children:[m("input",{type:"checkbox",checked:i,readOnly:!0,style:{width:"16px",height:"16px"}}),"Keyboard navigation hints"]})]}),m("div",{style:{borderTop:"1px solid #edf2f7",paddingTop:"16px",fontSize:"12px",lineHeight:"1.5",color:"#718096"},children:i?f(R,{children:[f("div",{style:{color:"#2d3748",fontWeight:"600",marginBottom:"4px"},children:["yuktai-a11y: ",n.fixes," fixes applied."]}),f("div",{children:["Nodes scanned: ",n.nodes]}),f("div",{children:["Render time: ",f("span",{style:{color:"#4a5568"},children:[n.renderTime,"ms"]})]})]}):m("div",{style:{color:"#a0aec0",fontStyle:"italic"},children:"ADA Engine is offline."})}),m("button",{onClick:()=>o(!1),style:{width:"100%",marginTop:"20px",padding:"12px",background:"#1a202c",color:"#fff",borderRadius:"8px",border:"none",cursor:"pointer",fontWeight:"600"},children:"Done"})]})]}):m(R,{children:e})}function D(){if(!globalThis.__yuktai_runtime__){let e=new h;e.register(A.name,A),e.register(k.name,k),e.register(w.name,w),e.register(E.name,E),globalThis.__yuktai_runtime__=e}return globalThis.__yuktai_runtime__}var _=D(),$={render:T,list(){return _.getPlugins()},use(e){return _.use(e)}},ue=$;export{$ as YuktAI,S as YuktAIWrapper,ue as default};
|