@yuktishaalaa/yuktai 1.0.10 → 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 +1 -1
- package/dist/index.d.cts +0 -3
- package/dist/index.d.ts +0 -3
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
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});
|
|
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,9 +20,6 @@ declare class Runtime {
|
|
|
20
20
|
getPlugins(): string[];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
* Standard DOM Mount Renderer for legacy mounting
|
|
25
|
-
*/
|
|
26
23
|
declare function render(element: React.ReactNode, selector: string, enabled?: boolean): void;
|
|
27
24
|
|
|
28
25
|
declare function YuktAIWrapper({ children }: {
|
package/dist/index.d.ts
CHANGED
|
@@ -20,9 +20,6 @@ declare class Runtime {
|
|
|
20
20
|
getPlugins(): string[];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
* Standard DOM Mount Renderer for legacy mounting
|
|
25
|
-
*/
|
|
26
23
|
declare function render(element: React.ReactNode, selector: string, enabled?: boolean): void;
|
|
27
24
|
|
|
28
25
|
declare function YuktAIWrapper({ children }: {
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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};
|
|
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};
|