Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@dopt/ai-assistant-context

Package Overview
Dependencies
Maintainers
5
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dopt/ai-assistant-context - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

2

dist/cjs/index.cjs.js

@@ -1,3 +0,3 @@

"use strict";const htmlToImageMod=require("html-to-image-mod");var r=(p,u,n)=>new Promise((a,o)=>{var i=t=>{try{e(n.next(t))}catch(d){o(d)}},h=t=>{try{e(n.throw(t))}catch(d){o(d)}},e=t=>t.done?a(t.value):Promise.resolve(t.value).then(i,h);e((n=n.apply(p,u)).next())});const document$1={generate(){return r(this,null,function*(){if(!window||!document)throw new Error("Cannot generate page context in a headless environment");return{type:"document",value:{url:document.URL,title:document.title,width:window.innerWidth,height:window.innerHeight}}})}};var s=(p,u,n)=>new Promise((a,o)=>{var i=t=>{try{e(n.next(t))}catch(d){o(d)}},h=t=>{try{e(n.throw(t))}catch(d){o(d)}},e=t=>t.done?a(t.value):Promise.resolve(t.value).then(i,h);e((n=n.apply(p,u)).next())});const element={generate(p){return s(this,arguments,function*({element:u}){const{top:n,left:a}=u.getBoundingClientRect();return{type:"element",value:{position:{top:n,left:a},content:u instanceof HTMLElement?u.innerText:"",tag:u.tagName.toLowerCase()}}})}};var S$1=(p,u,n)=>new Promise((a,o)=>{var i=t=>{try{e(n.next(t))}catch(d){o(d)}},h=t=>{try{e(n.throw(t))}catch(d){o(d)}},e=t=>t.done?a(t.value):Promise.resolve(t.value).then(i,h);e((n=n.apply(p,u)).next())});function c(p,u){return p.length<=u?p:p.substring(0,u)+"..."}const L=new Set(["iframe","style","script","noscript","meta","canvas","template","audio","embed","video","link","map","area","slot","source","svg","math","object","portal"]),w=new Set(["label","div","pre","abbr","b","bdi","bdo","br","dfn","em","i","kbd","mark","q","rp","rt","ruby","s","samp","small","span","strong","sub","sup","u","var","wbr"]);function M(p){const u=[];function n(a){if(a.type==="text"){a=a;const e=`<text>${a.value}</text>`;u.push(e);return}a=a;const o=Object.entries(a.attributes).map(([e,t])=>`${e}=${JSON.stringify(t)}`).join(" "),i=a.children.length>0,h=`<${a.type}${o.length>0?" "+o:""}${i?"":" /"}>`;if(u.push(h),i){a.children.forEach(t=>n(t));const e=`</${a.type}>`;u.push(e)}}return n(p),u.join("").replace(/[ ]+/g," ")}function v(p){var u;if(!window||!document)throw new Error("Cannot generate semantic content in a headless environment");const n={type:"component",attributes:{},children:[]},a=[{parent:n,child:p}],o=new Map;for(document.querySelectorAll("label").forEach(i=>{o.set(i.htmlFor,i.innerText)});a.length>0;){const{parent:i,child:h}=a.shift();if(h.nodeType===Node.TEXT_NODE){const e=(u=h.nodeValue)==null?void 0:u.trim();e&&e.length>0&&i.children.push({type:"text",value:c(e,100)})}if(h.nodeType===Node.ELEMENT_NODE){const e=h;if(e.ariaHidden==="true")continue;const t=e.tagName.toLowerCase();if(L.has(t))continue;const d=e.role!=null||!w.has(t);let f=null;if(d){const l={};e.role&&(l.role=e.role),e.title&&e.title.length>0&&(l.title=c(e.title,25)),e.ariaLabel&&e.ariaLabel.length>0&&(l.label=c(e.ariaLabel,25));const g=o.get(e.id);g&&g.length>0&&(l.label=c(g,25));const T=e.getAttribute("aria-labelledby");if(T&&T.length>0){const y=[];for(const P of T.split(" ")){const H=document.getElementById(P);H&&y.push(H.innerText)}const k=c(y.join(" "),25);k.length>0&&(l.label=k)}const C=e.getAttribute("aria-describedby");if(C&&C.length>0){const y=[];for(const P of C.split(" ")){const H=document.getElementById(P);H&&y.push(H.innerText)}const k=c(y.join(" "),25);k.length>0&&(l.description=k)}const $=e.getAttribute("href");$&&$.length>0&&(l.href=c($,25));const N=e.getAttribute("alt");N&&N.length>0&&(l.alt=c(N,25));const b=e.getAttribute("value");b&&b.length>0&&(l.value=c(b,25)),e instanceof HTMLFormElement&&(e.name.length>0&&(l.name=e.name),e.method.length>0&&(l.method=e.method)),e instanceof HTMLInputElement&&(e.value&&e.value.length>0&&(l.value=c(e.value,25)),e.name.length>0&&(l.name=e.name),l.checked=String(e.checked),!l.value&&e.placeholder.length>0&&(l.value=c(e.placeholder,25))),e instanceof HTMLOptionElement&&(l.selected=String(e.selected)),f={type:t,attributes:l,children:[]},i.children.push(f)}h.childNodes.forEach(l=>{a.push({parent:f!=null?f:i,child:l})})}}return M(n)}const semantic={generate(p){return S$1(this,arguments,function*({element:u}){var n,a;let o=(n=u.parentElement)!=null?n:u;for(;o.parentElement&&o.parentElement.innerText===(o instanceof HTMLElement?o.innerText:"");)o=o.parentElement;let i=(a=o.parentElement)!=null?a:o;for(;i.parentElement&&i.parentElement.innerText===(i instanceof HTMLElement?i.innerText:"");)i=i.parentElement;return{type:"semantic",value:{semanticContent:v(o),neighboringSemanticContent:v(i)}}})}};var E=(p,u,n)=>new Promise((a,o)=>{var i=t=>{try{e(n.next(t))}catch(d){o(d)}},h=t=>{try{e(n.throw(t))}catch(d){o(d)}},e=t=>t.done?a(t.value):Promise.resolve(t.value).then(i,h);e((n=n.apply(p,u)).next())});const x=1024,S=512,m=4,R="red",visual={generate(p,u){return E(this,arguments,function*({element:n},a){if(!window||!document)throw new Error("Cannot generate visual context in a headless environment");const{height:o,width:i}=document.body.getBoundingClientRect();let h,e;o>i?(h=Math.min(x,o),e=h*i/o):(e=Math.min(x,i),h=e*o/i);const t=S/Math.max(h,e),d={},f={x:0,y:0,width:0,height:0};if(n){const{top:l,bottom:g,left:T,right:C,height:$,width:N}=n.getBoundingClientRect();if(C<0||T>i||g<0||l>o)n=void 0;else{let b=0,y=0;T<=0?b-=T:e-C<=0&&(b-=-(e-C)),l<=0?y-=l:h-g<=0&&(y-=-(h-g)),(b!==0||y!==0)&&(d.translate=`${b}px ${y}px`),f.x=T+b,f.width=N,f.y=l+y,f.height=$}}try{const l=yield htmlToImageMod.toCanvas(document.body,{skipFonts:!0,filter:g=>!(g.classList&&g.classList.contains("dopt-contextual-assistant__popover")||g.tagName&&["video","img"].includes(g.tagName.toLowerCase())),height:h,width:e,pixelRatio:t,style:d});if(n){const g=l.getContext("2d");g&&(g.strokeStyle=R,g.lineWidth=m,g.strokeRect(f.x*t-m,f.y*t-m,f.width*t+2*m,f.height*t+2*m))}return{type:"visual",value:l.toDataURL()}}catch(l){return a==null||a.error(["Failed to capture the page, returning null.",`Details: ${l.message}`,`Stack: ${l.stack}`].join(`
"use strict";const htmlToImageMod=require("html-to-image-mod");var r=(d,i,n)=>new Promise((o,l)=>{var c=t=>{try{e(n.next(t))}catch(u){l(u)}},h=t=>{try{e(n.throw(t))}catch(u){l(u)}},e=t=>t.done?o(t.value):Promise.resolve(t.value).then(c,h);e((n=n.apply(d,i)).next())});const document$1={generate(){return r(this,null,function*(){if(!window||!document)throw new Error("Cannot generate page context in a headless environment");return{type:"document",value:{url:document.URL,title:document.title,width:window.innerWidth,height:window.innerHeight}}})}};var s$1=(d,i,n)=>new Promise((o,l)=>{var c=t=>{try{e(n.next(t))}catch(u){l(u)}},h=t=>{try{e(n.throw(t))}catch(u){l(u)}},e=t=>t.done?o(t.value):Promise.resolve(t.value).then(c,h);e((n=n.apply(d,i)).next())});const element={generate(d){return s$1(this,arguments,function*({element:i}){const{top:n,left:o}=i.getBoundingClientRect();return{type:"element",value:{position:{top:n,left:o},content:i instanceof HTMLElement?i.innerText:"",tag:i.tagName.toLowerCase()}}})}};var S$1=(d,i,n)=>new Promise((o,l)=>{var c=t=>{try{e(n.next(t))}catch(u){l(u)}},h=t=>{try{e(n.throw(t))}catch(u){l(u)}},e=t=>t.done?o(t.value):Promise.resolve(t.value).then(c,h);e((n=n.apply(d,i)).next())});function s(d,i){return d.length<=i?d:d.substring(0,i)+"..."}const L=new Set(["iframe","style","script","noscript","meta","canvas","template","audio","embed","video","link","map","area","slot","source","svg","math","object","portal"]),w=new Set(["label","div","pre","abbr","b","bdi","bdo","br","dfn","em","i","kbd","mark","q","rp","rt","ruby","s","samp","small","span","strong","sub","sup","u","var","wbr"]);function M(d){const i=[];function n(o){if(o.type==="text"){o=o;const e=`<text>${o.value}</text>`;i.push(e);return}o=o;const l=Object.entries(o.attributes).map(([e,t])=>`${e}=${JSON.stringify(t)}`).join(" "),c=o.children.length>0,h=`<${o.type}${l.length>0?" "+l:""}${c?"":" /"}>`;if(i.push(h),c){o.children.forEach(t=>n(t));const e=`</${o.type}>`;i.push(e)}}return n(d),i.join("").replace(/[ ]+/g," ")}function v(d){var i;if(!window||!document)throw new Error("Cannot generate semantic content in a headless environment");const n={type:"component",attributes:{},children:[]},o=[{parent:n,child:d}],l=new Map;for(document.querySelectorAll("label").forEach(c=>{l.set(c.htmlFor,c.innerText)});o.length>0;){const{parent:c,child:h}=o.shift();if(h.nodeType===Node.TEXT_NODE){const e=(i=h.nodeValue)==null?void 0:i.trim();e&&e.length>0&&c.children.push({type:"text",value:s(e,100)})}if(h.nodeType===Node.ELEMENT_NODE){const e=h;if(e.ariaHidden==="true")continue;const t=e.tagName.toLowerCase();if(L.has(t))continue;const u=e.role!=null||!w.has(t);let g=null;if(u){const a={};e.role&&(a.role=e.role),e.title&&e.title.length>0&&(a.title=s(e.title,25)),e.ariaLabel&&e.ariaLabel.length>0&&(a.label=s(e.ariaLabel,25));const p=l.get(e.id);p&&p.length>0&&(a.label=s(p,25));const b=e.getAttribute("aria-labelledby");if(b&&b.length>0){const f=[];for(const H of b.split(" ")){const k=document.getElementById(H);k&&f.push(k.innerText)}const N=s(f.join(" "),25);N.length>0&&(a.label=N)}const T=e.getAttribute("aria-describedby");if(T&&T.length>0){const f=[];for(const H of T.split(" ")){const k=document.getElementById(H);k&&f.push(k.innerText)}const N=s(f.join(" "),25);N.length>0&&(a.description=N)}const C=e.getAttribute("href");C&&C.length>0&&(a.href=s(C,25));const $=e.getAttribute("alt");$&&$.length>0&&(a.alt=s($,25));const y=e.getAttribute("value");y&&y.length>0&&(a.value=s(y,25)),e instanceof HTMLFormElement&&(e.name.length>0&&(a.name=e.name),e.method.length>0&&(a.method=e.method)),e instanceof HTMLInputElement&&(e.value&&e.value.length>0&&(a.value=s(e.value,25)),e.name.length>0&&(a.name=e.name),a.checked=String(e.checked),!a.value&&e.placeholder.length>0&&(a.value=s(e.placeholder,25))),e instanceof HTMLOptionElement&&(a.selected=String(e.selected)),g={type:t,attributes:a,children:[]},c.children.push(g)}h.childNodes.forEach(a=>{o.push({parent:g!=null?g:c,child:a})})}}return M(n)}const semantic={generate(d){return S$1(this,arguments,function*({element:i}){let n=i;for(;n.parentElement&&n.parentElement.innerText===(n instanceof HTMLElement?n.innerText:"");)n=n.parentElement;let o=n;for(;o.parentElement&&o.parentElement.innerText===(o instanceof HTMLElement?o.innerText:"");)o=o.parentElement;return{type:"semantic",value:{semanticContent:v(n),neighboringSemanticContent:v(o)}}})}};var E=(d,i,n)=>new Promise((o,l)=>{var c=t=>{try{e(n.next(t))}catch(u){l(u)}},h=t=>{try{e(n.throw(t))}catch(u){l(u)}},e=t=>t.done?o(t.value):Promise.resolve(t.value).then(c,h);e((n=n.apply(d,i)).next())});const x=1024,S=512,m=4,R="red",visual={generate(d,i){return E(this,arguments,function*({element:n},o){if(!window||!document)throw new Error("Cannot generate visual context in a headless environment");const{height:l,width:c}=document.body.getBoundingClientRect();let h,e;l>c?(h=Math.min(x,l),e=h*c/l):(e=Math.min(x,c),h=e*l/c);const t=S/Math.max(h,e),u={},g={x:0,y:0,width:0,height:0};if(n){const{top:a,bottom:p,left:b,right:T,height:C,width:$}=n.getBoundingClientRect();if(T<0||b>c||p<0||a>l)n=void 0;else{let y=0,f=0;b<=0?y-=b:e-T<=0&&(y-=-(e-T)),a<=0?f-=a:h-p<=0&&(f-=-(h-p)),(y!==0||f!==0)&&(u.translate=`${y}px ${f}px`),g.x=b+y,g.width=$,g.y=a+f,g.height=C}}try{const a=yield htmlToImageMod.toCanvas(document.body,{skipFonts:!0,filter:p=>!(p.classList&&p.classList.contains("dopt-contextual-assistant__popover")||p.tagName&&["video","img"].includes(p.tagName.toLowerCase())),height:h,width:e,pixelRatio:t,style:u});if(n){const p=a.getContext("2d");p&&(p.strokeStyle=R,p.lineWidth=m,p.strokeRect(g.x*t-m,g.y*t-m,g.width*t+2*m,g.height*t+2*m))}return{type:"visual",value:a.toDataURL()}}catch(a){return o==null||o.error(["Failed to capture the page, returning null.",`Details: ${a.message}`,`Stack: ${a.stack}`].join(`
`)),null}})}};exports.document=document$1,exports.element=element,exports.semantic=semantic,exports.visual=visual;
//# sourceMappingURL=index.cjs.js.map

@@ -1,3 +0,3 @@

import{toCanvas as $}from"html-to-image-mod";var M=(h,l,n)=>new Promise((o,r)=>{var a=t=>{try{e(n.next(t))}catch(c){r(c)}},s=t=>{try{e(n.throw(t))}catch(c){r(c)}},e=t=>t.done?o(t.value):Promise.resolve(t.value).then(a,s);e((n=n.apply(h,l)).next())});const N={generate(){return M(this,null,function*(){if(!window||!document)throw new Error("Cannot generate page context in a headless environment");return{type:"document",value:{url:document.URL,title:document.title,width:window.innerWidth,height:window.innerHeight}}})}};var S=(h,l,n)=>new Promise((o,r)=>{var a=t=>{try{e(n.next(t))}catch(c){r(c)}},s=t=>{try{e(n.throw(t))}catch(c){r(c)}},e=t=>t.done?o(t.value):Promise.resolve(t.value).then(a,s);e((n=n.apply(h,l)).next())});const k={generate(h){return S(this,arguments,function*({element:l}){const{top:n,left:o}=l.getBoundingClientRect();return{type:"element",value:{position:{top:n,left:o},content:l instanceof HTMLElement?l.innerText:"",tag:l.tagName.toLowerCase()}}})}};var H=(h,l,n)=>new Promise((o,r)=>{var a=t=>{try{e(n.next(t))}catch(c){r(c)}},s=t=>{try{e(n.throw(t))}catch(c){r(c)}},e=t=>t.done?o(t.value):Promise.resolve(t.value).then(a,s);e((n=n.apply(h,l)).next())});function p(h,l){return h.length<=l?h:h.substring(0,l)+"..."}const P=new Set(["iframe","style","script","noscript","meta","canvas","template","audio","embed","video","link","map","area","slot","source","svg","math","object","portal"]),R=new Set(["label","div","pre","abbr","b","bdi","bdo","br","dfn","em","i","kbd","mark","q","rp","rt","ruby","s","samp","small","span","strong","sub","sup","u","var","wbr"]);function j(h){const l=[];function n(o){if(o.type==="text"){o=o;const e=`<text>${o.value}</text>`;l.push(e);return}o=o;const r=Object.entries(o.attributes).map(([e,t])=>`${e}=${JSON.stringify(t)}`).join(" "),a=o.children.length>0,s=`<${o.type}${r.length>0?" "+r:""}${a?"":" /"}>`;if(l.push(s),a){o.children.forEach(t=>n(t));const e=`</${o.type}>`;l.push(e)}}return n(h),l.join("").replace(/[ ]+/g," ")}function L(h){var l;if(!window||!document)throw new Error("Cannot generate semantic content in a headless environment");const n={type:"component",attributes:{},children:[]},o=[{parent:n,child:h}],r=new Map;for(document.querySelectorAll("label").forEach(a=>{r.set(a.htmlFor,a.innerText)});o.length>0;){const{parent:a,child:s}=o.shift();if(s.nodeType===Node.TEXT_NODE){const e=(l=s.nodeValue)==null?void 0:l.trim();e&&e.length>0&&a.children.push({type:"text",value:p(e,100)})}if(s.nodeType===Node.ELEMENT_NODE){const e=s;if(e.ariaHidden==="true")continue;const t=e.tagName.toLowerCase();if(P.has(t))continue;const c=e.role!=null||!R.has(t);let d=null;if(c){const i={};e.role&&(i.role=e.role),e.title&&e.title.length>0&&(i.title=p(e.title,25)),e.ariaLabel&&e.ariaLabel.length>0&&(i.label=p(e.ariaLabel,25));const u=r.get(e.id);u&&u.length>0&&(i.label=p(u,25));const v=e.getAttribute("aria-labelledby");if(v&&v.length>0){const m=[];for(const T of v.split(" ")){const x=document.getElementById(T);x&&m.push(x.innerText)}const b=p(m.join(" "),25);b.length>0&&(i.label=b)}const f=e.getAttribute("aria-describedby");if(f&&f.length>0){const m=[];for(const T of f.split(" ")){const x=document.getElementById(T);x&&m.push(x.innerText)}const b=p(m.join(" "),25);b.length>0&&(i.description=b)}const y=e.getAttribute("href");y&&y.length>0&&(i.href=p(y,25));const w=e.getAttribute("alt");w&&w.length>0&&(i.alt=p(w,25));const g=e.getAttribute("value");g&&g.length>0&&(i.value=p(g,25)),e instanceof HTMLFormElement&&(e.name.length>0&&(i.name=e.name),e.method.length>0&&(i.method=e.method)),e instanceof HTMLInputElement&&(e.value&&e.value.length>0&&(i.value=p(e.value,25)),e.name.length>0&&(i.name=e.name),i.checked=String(e.checked),!i.value&&e.placeholder.length>0&&(i.value=p(e.placeholder,25))),e instanceof HTMLOptionElement&&(i.selected=String(e.selected)),d={type:t,attributes:i,children:[]},a.children.push(d)}s.childNodes.forEach(i=>{o.push({parent:d!=null?d:a,child:i})})}}return j(n)}const A={generate(h){return H(this,arguments,function*({element:l}){var n,o;let r=(n=l.parentElement)!=null?n:l;for(;r.parentElement&&r.parentElement.innerText===(r instanceof HTMLElement?r.innerText:"");)r=r.parentElement;let a=(o=r.parentElement)!=null?o:r;for(;a.parentElement&&a.parentElement.innerText===(a instanceof HTMLElement?a.innerText:"");)a=a.parentElement;return{type:"semantic",value:{semanticContent:L(r),neighboringSemanticContent:L(a)}}})}};var B=(h,l,n)=>new Promise((o,r)=>{var a=t=>{try{e(n.next(t))}catch(c){r(c)}},s=t=>{try{e(n.throw(t))}catch(c){r(c)}},e=t=>t.done?o(t.value):Promise.resolve(t.value).then(a,s);e((n=n.apply(h,l)).next())});const C=1024,O=512,E=4,D="red",F={generate(h,l){return B(this,arguments,function*({element:n},o){if(!window||!document)throw new Error("Cannot generate visual context in a headless environment");const{height:r,width:a}=document.body.getBoundingClientRect();let s,e;r>a?(s=Math.min(C,r),e=s*a/r):(e=Math.min(C,a),s=e*r/a);const t=O/Math.max(s,e),c={},d={x:0,y:0,width:0,height:0};if(n){const{top:i,bottom:u,left:v,right:f,height:y,width:w}=n.getBoundingClientRect();if(f<0||v>a||u<0||i>r)n=void 0;else{let g=0,m=0;v<=0?g-=v:e-f<=0&&(g-=-(e-f)),i<=0?m-=i:s-u<=0&&(m-=-(s-u)),(g!==0||m!==0)&&(c.translate=`${g}px ${m}px`),d.x=v+g,d.width=w,d.y=i+m,d.height=y}}try{const i=yield $(document.body,{skipFonts:!0,filter:u=>!(u.classList&&u.classList.contains("dopt-contextual-assistant__popover")||u.tagName&&["video","img"].includes(u.tagName.toLowerCase())),height:s,width:e,pixelRatio:t,style:c});if(n){const u=i.getContext("2d");u&&(u.strokeStyle=D,u.lineWidth=E,u.strokeRect(d.x*t-E,d.y*t-E,d.width*t+2*E,d.height*t+2*E))}return{type:"visual",value:i.toDataURL()}}catch(i){return o==null||o.error(["Failed to capture the page, returning null.",`Details: ${i.message}`,`Stack: ${i.stack}`].join(`
import{toCanvas as $}from"html-to-image-mod";var M=(h,a,n)=>new Promise((o,i)=>{var l=t=>{try{e(n.next(t))}catch(c){i(c)}},s=t=>{try{e(n.throw(t))}catch(c){i(c)}},e=t=>t.done?o(t.value):Promise.resolve(t.value).then(l,s);e((n=n.apply(h,a)).next())});const N={generate(){return M(this,null,function*(){if(!window||!document)throw new Error("Cannot generate page context in a headless environment");return{type:"document",value:{url:document.URL,title:document.title,width:window.innerWidth,height:window.innerHeight}}})}};var S=(h,a,n)=>new Promise((o,i)=>{var l=t=>{try{e(n.next(t))}catch(c){i(c)}},s=t=>{try{e(n.throw(t))}catch(c){i(c)}},e=t=>t.done?o(t.value):Promise.resolve(t.value).then(l,s);e((n=n.apply(h,a)).next())});const k={generate(h){return S(this,arguments,function*({element:a}){const{top:n,left:o}=a.getBoundingClientRect();return{type:"element",value:{position:{top:n,left:o},content:a instanceof HTMLElement?a.innerText:"",tag:a.tagName.toLowerCase()}}})}};var H=(h,a,n)=>new Promise((o,i)=>{var l=t=>{try{e(n.next(t))}catch(c){i(c)}},s=t=>{try{e(n.throw(t))}catch(c){i(c)}},e=t=>t.done?o(t.value):Promise.resolve(t.value).then(l,s);e((n=n.apply(h,a)).next())});function p(h,a){return h.length<=a?h:h.substring(0,a)+"..."}const P=new Set(["iframe","style","script","noscript","meta","canvas","template","audio","embed","video","link","map","area","slot","source","svg","math","object","portal"]),R=new Set(["label","div","pre","abbr","b","bdi","bdo","br","dfn","em","i","kbd","mark","q","rp","rt","ruby","s","samp","small","span","strong","sub","sup","u","var","wbr"]);function j(h){const a=[];function n(o){if(o.type==="text"){o=o;const e=`<text>${o.value}</text>`;a.push(e);return}o=o;const i=Object.entries(o.attributes).map(([e,t])=>`${e}=${JSON.stringify(t)}`).join(" "),l=o.children.length>0,s=`<${o.type}${i.length>0?" "+i:""}${l?"":" /"}>`;if(a.push(s),l){o.children.forEach(t=>n(t));const e=`</${o.type}>`;a.push(e)}}return n(h),a.join("").replace(/[ ]+/g," ")}function L(h){var a;if(!window||!document)throw new Error("Cannot generate semantic content in a headless environment");const n={type:"component",attributes:{},children:[]},o=[{parent:n,child:h}],i=new Map;for(document.querySelectorAll("label").forEach(l=>{i.set(l.htmlFor,l.innerText)});o.length>0;){const{parent:l,child:s}=o.shift();if(s.nodeType===Node.TEXT_NODE){const e=(a=s.nodeValue)==null?void 0:a.trim();e&&e.length>0&&l.children.push({type:"text",value:p(e,100)})}if(s.nodeType===Node.ELEMENT_NODE){const e=s;if(e.ariaHidden==="true")continue;const t=e.tagName.toLowerCase();if(P.has(t))continue;const c=e.role!=null||!R.has(t);let d=null;if(c){const r={};e.role&&(r.role=e.role),e.title&&e.title.length>0&&(r.title=p(e.title,25)),e.ariaLabel&&e.ariaLabel.length>0&&(r.label=p(e.ariaLabel,25));const u=i.get(e.id);u&&u.length>0&&(r.label=p(u,25));const v=e.getAttribute("aria-labelledby");if(v&&v.length>0){const m=[];for(const T of v.split(" ")){const x=document.getElementById(T);x&&m.push(x.innerText)}const b=p(m.join(" "),25);b.length>0&&(r.label=b)}const f=e.getAttribute("aria-describedby");if(f&&f.length>0){const m=[];for(const T of f.split(" ")){const x=document.getElementById(T);x&&m.push(x.innerText)}const b=p(m.join(" "),25);b.length>0&&(r.description=b)}const y=e.getAttribute("href");y&&y.length>0&&(r.href=p(y,25));const w=e.getAttribute("alt");w&&w.length>0&&(r.alt=p(w,25));const g=e.getAttribute("value");g&&g.length>0&&(r.value=p(g,25)),e instanceof HTMLFormElement&&(e.name.length>0&&(r.name=e.name),e.method.length>0&&(r.method=e.method)),e instanceof HTMLInputElement&&(e.value&&e.value.length>0&&(r.value=p(e.value,25)),e.name.length>0&&(r.name=e.name),r.checked=String(e.checked),!r.value&&e.placeholder.length>0&&(r.value=p(e.placeholder,25))),e instanceof HTMLOptionElement&&(r.selected=String(e.selected)),d={type:t,attributes:r,children:[]},l.children.push(d)}s.childNodes.forEach(r=>{o.push({parent:d!=null?d:l,child:r})})}}return j(n)}const A={generate(h){return H(this,arguments,function*({element:a}){let n=a;for(;n.parentElement&&n.parentElement.innerText===(n instanceof HTMLElement?n.innerText:"");)n=n.parentElement;let o=n;for(;o.parentElement&&o.parentElement.innerText===(o instanceof HTMLElement?o.innerText:"");)o=o.parentElement;return{type:"semantic",value:{semanticContent:L(n),neighboringSemanticContent:L(o)}}})}};var B=(h,a,n)=>new Promise((o,i)=>{var l=t=>{try{e(n.next(t))}catch(c){i(c)}},s=t=>{try{e(n.throw(t))}catch(c){i(c)}},e=t=>t.done?o(t.value):Promise.resolve(t.value).then(l,s);e((n=n.apply(h,a)).next())});const C=1024,O=512,E=4,D="red",F={generate(h,a){return B(this,arguments,function*({element:n},o){if(!window||!document)throw new Error("Cannot generate visual context in a headless environment");const{height:i,width:l}=document.body.getBoundingClientRect();let s,e;i>l?(s=Math.min(C,i),e=s*l/i):(e=Math.min(C,l),s=e*i/l);const t=O/Math.max(s,e),c={},d={x:0,y:0,width:0,height:0};if(n){const{top:r,bottom:u,left:v,right:f,height:y,width:w}=n.getBoundingClientRect();if(f<0||v>l||u<0||r>i)n=void 0;else{let g=0,m=0;v<=0?g-=v:e-f<=0&&(g-=-(e-f)),r<=0?m-=r:s-u<=0&&(m-=-(s-u)),(g!==0||m!==0)&&(c.translate=`${g}px ${m}px`),d.x=v+g,d.width=w,d.y=r+m,d.height=y}}try{const r=yield $(document.body,{skipFonts:!0,filter:u=>!(u.classList&&u.classList.contains("dopt-contextual-assistant__popover")||u.tagName&&["video","img"].includes(u.tagName.toLowerCase())),height:s,width:e,pixelRatio:t,style:c});if(n){const u=r.getContext("2d");u&&(u.strokeStyle=D,u.lineWidth=E,u.strokeRect(d.x*t-E,d.y*t-E,d.width*t+2*E,d.height*t+2*E))}return{type:"visual",value:r.toDataURL()}}catch(r){return o==null||o.error(["Failed to capture the page, returning null.",`Details: ${r.message}`,`Stack: ${r.stack}`].join(`
`)),null}})}};export{N as document,k as element,A as semantic,F as visual};
//# sourceMappingURL=index.esm.js.map
{
"name": "@dopt/ai-assistant-context",
"version": "0.0.6",
"version": "0.0.7",
"private": false,

@@ -34,3 +34,3 @@ "description": "Input context for the AI assistants",

"html-to-image-mod": "1.11.11-1",
"@dopt/ai-assistant-definition": "0.0.4",
"@dopt/ai-assistant-definition": "0.0.5",
"@dopt/logger": "0.2.0"

@@ -37,0 +37,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc