diff --git a/js/libs/vendors/detect/detect.min.js b/js/libs/vendors/detect/detect.min.js index 7f3e65de..8d112384 100644 --- a/js/libs/vendors/detect/detect.min.js +++ b/js/libs/vendors/detect/detect.min.js @@ -1,10 +1,10 @@ // Adobe Corp. internal project "webpage-blueprint-detector" - Author: catalan@adobe.com -(()=>{{let s=i=>{typeof i[0]=="string"&&!i[0].startsWith("[detect]")&&(i[0]=`[detect] ${i[0]}`)},e=console.log;console.log=(...i)=>{s(i),e(...i)},console.debug=(...i)=>{window.DEBUG&&(s(i),e(...i))};let n=console.warn;console.warn=(...i)=>{s(i),n(...i)};let t=console.error;console.error=(...i)=>{s(i),t(...i)}}function T(s){return s.toString(16)}function H(s,e,n,t){return T(s)+T(e)+T(n)+T(t)}var v=class s{constructor({r:e,g:n,b:t,a:i=1,name:r=""}){this.name=r,this.r=e,this.g=n,this.b=t,this.a=i}toHex(){return H(this.r,this.g,this.b,this.a)}static fromRGBA(e){let n=e.replace("rgba(","").replace(")","").split(",").map(t=>parseInt(t.trim()));return new s({r:n[0],g:n[1],b:n[2],a:n[3]})}toRGBA(){return`rgba(${this.r}, ${this.g}, ${this.b}, ${this.a})`}withAlpha(e){return new s({...this,a:e})}static random(e=!1){let n=Math.round(Math.random()*255),t=Math.round(Math.random()*255),i=Math.round(Math.random()*255),r=e?Math.random():1;return new s({name:`rand-${n}-${t}-${i}-${r}`,r:n,g:t,b:i,a:r})}static fromHex(e){let n=parseInt(e.substring(0,2),16),t=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16),r=parseInt(e.substring(6,8),16);return new s({name:`hex-${n}-${t}-${i}-${r}`,r:n,g:t,b:i,a:r})}};function L(s,e){let n=Math.max(0,Math.min(s.x+s.width,e.x+e.width)-Math.max(s.x,e.x)),t=Math.max(0,Math.min(s.y+s.height,e.y+e.height)-Math.max(s.y,e.y)),i=n*t,r=e.width*e.height;return i/r*100}function R(s,e){let n=s.getBoundingClientRect();return{left:n.left+e.document.scrollingElement.scrollLeft,top:n.top+e.document.scrollingElement.scrollTop}}var S=class s{constructor(e,n,t,i,r){this.id=crypto.randomUUID(),this.x=Math.floor(e),this.y=Math.floor(n),this.width=Math.floor(t),this.height=Math.floor(i),this.div=r,this.children=[],this.prediction=null,this.layout=null}static fromDiv(e,n){let t=e.getBoundingClientRect(),i=R(e,n);return new s(i.left,i.top,t.width,t.height,e)}static areBoxesLaidOutAsGrid(e){console.log("areBoxesLaidOutAsGrid");try{if(e.length<2)return!1;let n=e.slice().sort((o,l)=>o.x-l.x||o.y-l.y),t=e.slice().sort((o,l)=>o.y-l.y||o.x-l.x);console.log(n),console.log(t);let i=[];for(let o=1;o1)return!1;let c=[];for(let o=1;o1)}finally{return!0}}contains(e,n=!0){return n?e.x-e.width>=this.x-this.width&&e.x+e.width<=this.x+this.width&&e.y-e.height>=this.y-this.height&&e.y+e.height<=this.y+this.height:L(this,e)>75}intersects(e){return!(e.x-e.width>this.x+this.width||e.x+e.widththis.y+this.height||e.y+e.height=this.x+this.width&&e.y-e.height<=this.y-this.height&&e.y+e.height>=this.y+this.height}addChild(e){this.children.push(e)}isChild(e){return this.children.some(this.isChild)}determineLayout(){if(this.layout={numCols:D(this.children),numRows:O(this.children)},this.layout.numCols>1){let e=[],n=this.children.slice().sort((t,i)=>t.y-i.y);for(let t=0;tr.x-c.x))}this.children=e,console.log("sortedBoxes",e)}return this.layout}toJSONString(){function e(t){return{id:t.id,x:t.x,y:t.y,width:t.width,height:t.height,layout:t.layout,prediction:t.prediction,template:t.template,xpath:t.xpath,xpathWithDetails:t.xpathWithDetails,children:t.children.map(e)}}let n=e(this);return console.log(n),n}};function D(s){if(!s.length)return 0;let e=[];return s.slice().sort((n,t)=>n.x-t.x).forEach(n=>{let t=n.x,i=n.x+n.width,r=e[e.length-1];r?t>=r-5&&e.push(i):e.push(i)}),e.length}function O(s){if(!s.length)return 0;let e=[];return s.slice().sort((n,t)=>n.y-t.y).forEach(n=>{let t=n.y,i=n.y+n.height,r=e[e.length-1];r?t>=r-5&&e.push(i):e.push(i)}),e.length}var p=class s{static getXPath(e,n,t=!1){for(var i=n.getElementsByTagName("*"),r=[];e&&e.nodeType==1;e=e.parentNode)if(t)if(e.hasAttribute("id")){for(var c=0,a=0;a1));a++);if(c==1)return r.unshift('id("'+e.getAttribute("id")+'")'),r.join("/");r.unshift(e.localName.toLowerCase()+'[@id="'+e.getAttribute("id")+'"]')}else e.hasAttribute("class")&&r.unshift(e.localName.toLowerCase()+'[@class="'+[...e.classList].join(" ").trim()+'"]');else{for(var o=1,l=e.previousSibling;l;l=l.previousSibling)l.localName==e.localName&&(o+=1);r.unshift(e.localName.toLowerCase()+"["+o+"]")}return r.length?"/"+r.join("/"):null}static isVisible(e,n){if(!e)return!1;if(e.nodeType===n.Node.DOCUMENT_NODE)return!0;if(e.nodeType===n.Node.ELEMENT_NODE){let t=n.getComputedStyle(e);return t.display.includes("none")||t.visibility.includes("hidden")||t.opacity==="0"?!1:s.isVisible(e.parentNode,n)}}static isUserVisible(e,n){if(!s.isVisible(e,n))return!1;let t=e.getBoundingClientRect(),{width:i,height:r}=s.getPageSize(n.document);return!(t.height===0||t.width===0)}static getNSiblingsDivs(e,n,t=null){let i=t;isNaN(t)||(i=a=>a===t);let r="",c=[];e.querySelectorAll("div").forEach(a=>{let o=s.getXPath(a,n),l=o.substring(0,o.lastIndexOf("["));c[l]?c[l].push(a):c[l]=[a]});for(let a in c)if(i(c[a].length)){r=a;break}return c[r]||null}static getPageSize(e){var n=e.documentElement,t=e.body,i=Math.max(n.clientWidth,n.scrollWidth,n.offsetWidth,t.scrollWidth,t.offsetWidth),r=Math.max(n.clientHeight,n.scrollHeight,n.offsetHeight,t.scrollHeight,t.offsetHeight);return{width:i,height:r}}static getOffsetRect(e,n){let t=e.getBoundingClientRect(),i=n.document?.scrollingElement?.scrollLeft||0,r=n.document?.scrollingElement?.scrollTop||0;return{x:t.left+i,y:t.top+r,width:t.width,height:t.height}}static checkElStackUpCSSClasses(e,n){let t=e;for(;t;){if(t.classList.contains(n))return!0;t=t.parentElement}return!1}static getAllVisibleElements=(e=document.body,n)=>{let t=[...e.querySelectorAll("*")].filter(c=>!["IFRAME","NOSCRIPT","BR","EM","STRONG","STYLE","SCRIPT"].includes(c.nodeName)).reduce((c,a,o)=>{var l=a.closest("svg");return!(l!==null&&l!==a)&&!c.includes(a.nodeName)&&c.push(a.nodeName),c},[]);console.debug("DOM node types:",t);let r=[...e.querySelectorAll(t.join(","))].filter(c=>s.isUserVisible(c,n));return console.log(`found ${r.length} visible elements in the page.`),r}};var C=class{constructor(...e){e.reduce((n,t,i)=>(n[t]=1<n|t,0)}setFlag(e){this.#e|=e}unsetFlag(e){this.#e&=~e}isFlagSet(e){return(this.#e&e)!==0}areOnlyFlagsSet(...e){let n=e.reduce((t,i)=>t|i,0);return this.#e===n}getFlags(e){return Object.keys(e).filter(n=>this.isFlagSet(e[n]))}};function E(s){var e=0,n=s.length,t=0;if(n>0)for(;t{let t=n[n.length-1]||{},i=[s[0]];return e.forEach((r,c)=>{let a=Number.isInteger(r)?n[r]:t[r];i.push(a,s[c+1])}),i.join("")}}function I(s,e){let n=null,t=null;return n=[...s.querySelectorAll("*")].some(i=>{let r=e.getComputedStyle(i),c=i.getBoundingClientRect(),a=r.backgroundImage||"none",o="none";if(o&&o.includes("rgba")&&Color.fromRGBA(o).a===0&&(o="none"),a.includes("none")&&o.includes("none"))return!1;if(a||o)return t=i,!0}),n||(n=[...s.querySelectorAll("img")].some(i=>p.isUserVisible(i,e)),n)?t:n}var u=window.xp??{},b=class{constructor({sectionType:e,sectionFeatures:n,template:t,confidence:i}){this.sectionType=e,this.sectionFeatures=n,this.template=t,this.confidence=i}},M=[{name:"carousel",predictFn:(s,e,n,t,i)=>{console.log(s.div),console.groupCollapsed(">>> carousel");let r=p.getNSiblingsDivs(s.div,i.document,c=>c>=2);if(r){console.log("predict carousel"),console.log(r);let c={};r.forEach(o=>{let l=p.getXPath(o,i.document),d=[...o.querySelectorAll("div")].map(m=>p.getXPath(m,i.document).slice(l.length));console.log(d);let h=E(d.join(` -`));console.log(h),c[h]?c[h].push(o):c[h]=[o]}),console.groupEnd();let a=Object.keys(c).filter(o=>c[o].length>1);if(c[a]){let o=!1,l=!1;if(c[a].forEach(d=>{let h=d.getBoundingClientRect();!p.isVisible(d,i)||h.x+h.width>i.innerWidth?l=!0:o=!0}),o&&l)return!0}return!1}return console.groupEnd(),!1}},{name:"columns",predictFn:(s,e,n,t,i)=>(console.log("flags",t.getFlags(g)),t.isFlagSet(g.isGridLayout))},{name:"hero",predictFn:(s,e,n,t,i)=>s.height<=i.innerHeight&&t.isFlagSet(g.hasBackground)&&t.isFlagSet(g.hasHeading)&&t.isFlagSet(g.hasCTA)},{name:"default-content",predictFn:(s,e,n,t,i)=>{let r=!0;[...s.div.querySelectorAll("img")].some(o=>{let l=o.getBoundingClientRect();return l.width>50&&l.height>50})&&(r=!1);let a=!s.children.some(o=>(console.log(o.prediction?.sectionType),!["heading","text","text+icons"].includes(o.prediction?.sectionType)));return console.log("childrenOnlyTextLike",a),t.isFlagSet(g.hasTexts)&&!t.isFlagSet(g.hasImages)&&!t.isFlagSet(g.hasBackground)||!t.isFlagSet(g.isGridLayout)&&a&&t.isFlagSet(g.hasTexts)&&r&&!t.isFlagSet(g.hasBackground)}}];u.DOM=p;u.Flags=C;u.FlagSet=w;function P(s,e){let n=e.document.createElement("a");document.body.appendChild(n);let t=e.getComputedStyle(n);return[...s.querySelectorAll("a")].find(r=>{if(["background","background-color","background-image"].find(o=>{let l=e.getComputedStyle(r);return console.log(o,l[o],t[o]),l[o]!==t[o]}))return console.log("hasBackground"),!0;let a=0;return["left","right","top","bottom"].forEach(o=>{let l=e.getComputedStyle(r).getPropertyValue(`border-${o}-style`);console.log(o,l,t[`border-${o}-style`]),l!==t[`border-${o}-style`]&&a++}),a>1?(console.log("bordersNum"),!0):!1})!==void 0}var q=[new v({name:"violet",r:148,g:0,b:211}),new v({name:"indigo",r:75,g:0,b:130}),new v({name:"blue",r:0,g:0,b:255}),new v({name:"green",r:0,g:255,b:0}),new v({name:"yellow",r:255,g:255,b:0}),new v({name:"orange",r:255,g:127,b:0}),new v({name:"red",r:255,g:0,b:0})];u.filterDivs=s=>{let e=s.filter(t=>{let i=t.getBoundingClientRect(),{width:r,height:c}=p.getPageSize();return!t.classList.contains("xp-ui")&&!t.closest(".xp-ui")&&i.width!==0&&i.height!==0&&i.width*i.height>5e3&&i.width*i.height<.8*r*c&&p.isVisible(t,window)});console.log(e.length),console.log(e.map(t=>t));let n=e.filter(t=>{let i=t.parentElement;for(;i;){let r=t.getBoundingClientRect(),c=i.getBoundingClientRect();if(c.width===0||c.height===0){i=i.parentElement;continue}if(r.width>=.9*c.width&&r.height>=.9*c.height)return!1;i=i.parentElement}return!0});return console.log(n.length),console.log(n.map(t=>t)),n};var $=B`position:absolute;z-index:10000000;left:${0}px;top:${1}px;width:${2}px;height:${3}px;border:2px solid ${4};`,F=(s,{window:e,target:n=document.body,padding:t=0,color:i=null,label:r=null})=>{let c=i||"rgba(0, 0, 255, 1)",a=p.getOffsetRect(s.div,e),o=document.createElement("div");o.dataset.boxId=s.id,o.dataset.boxXpath=s.xpath,o.dataset.boxXpathWithDetails=s.xpathWithDetails,o.dataset.layout=JSON.stringify(s.layout);let l=(({id:d,x:h,y:m,width:f,height:x,xpath:y,layout:k})=>({id:d,x:h,y:m,width:f,height:x,xpath:y,layout:k}))(s);if((s.layout.numCols>1||s.layout.numRows>1)&&(l.childrenXpaths=s.children.map(d=>({xpath:d.xpath,xpathWithDetails:d.xpathWithDetails}))),o.dataset.boxData=JSON.stringify(l),o.className="xp-overlay",o.style=$(a.x+t,a.y+t,a.width-t*2-4,a.height-t*2-4,c),r){let d=e.document.createElement("div");d.className="xp-overlay-label",d.textContent=r,o.appendChild(d)}n.appendChild(o)};function N(s,e,n=0,t=q,i=null,r=0){s.forEach((c,a)=>{let o=i||t[a%(t.length-1)],l=r===0?1:Math.max(.1,.5-r*.1),d=o.withAlpha(l).toRGBA();c.color=d,F(c,{window:e,target:e.document.body,padding:n,color:d,label:`layout: ${c.layout.numCols}x${c.layout.numRows}`}),c.children.length>0&&N(c.children,e,n+4,t,o,r+1)})}var g=new C("isFromRootBox","hasHeader","hasTexts","hasBackground","hasHeading","hasCTA","hasImages","hasMultipleColumns","hasMultipleRows","isGridLayout","isInsideAHeaderLikeElement","isInsideAFooterLikeElement");function A(s,e,n=null,t,i=!0){if(s.ignored)return null;let r="unknown",c=new w,a=s.div;if(i&&c.setFlag(g.isFromRootBox),a){let l=a.cloneNode(!0);l.querySelectorAll("script, style, link, meta, noscript").forEach(k=>k.remove()),l.textContent.replaceAll(" ","").replaceAll(` -`,"").trim().length>0&&c.setFlag(g.hasTexts),([...a.querySelectorAll("img, picture, svg")].length>0||["IMG","PICTURE","SVG"].includes(a.nodeName))&&c.setFlag(g.hasImages),!!I(s.div,t)&&c.setFlag(g.hasBackground),([...a.querySelectorAll("h1, h2, h3, h4, h5, h6")].length>0||["H1","H2","H3","H4","H5","H6"].includes(a.nodeName))&&c.setFlag(g.hasHeading),P(a,t)&&c.setFlag(g.hasCTA);let y=s.determineLayout();y.numRows>1&&c.setFlag(g.hasMultipleRows),y.numCols>1&&c.setFlag(g.hasMultipleColumns),y.numCols>1&&S.areBoxesLaidOutAsGrid(s.children)&&c.setFlag(g.isGridLayout),(a.closest("header, .header")||p.checkElStackUpCSSClasses(a,"header"))&&c.setFlag(g.isInsideAHeaderLikeElement),(a.closest("footer, .footer")||p.checkElStackUpCSSClasses(a,"footer"))&&c.setFlag(g.isInsideAFooterLikeElement)}let o=s.children;if(o.forEach((...l)=>{A(...l,t,!1)}),!i){let l=M.find(d=>d.predictFn(s,e,null,c,t));l&&(r=l.name)}if(o.length===0&&c.isFlagSet(g.isFromRootBox)&&e===0||o.length>0&&o.every(l=>l.prediction.sectionFeatures.includes("isInsideAHeaderLikeElement"))?r="header":o.length>0&&o.every(l=>l.prediction.sectionFeatures.includes("isInsideAFooterLikeElement"))&&(r="footer"),s.prediction=new b({sectionType:r,sectionFeatures:c.getFlags(g),confidence:-1}),console.group("prediction"),console.log("prediction"),console.log(c.getFlags(g)),console.log(a),console.log("section prediction:",s.prediction),console.groupEnd(),i){let l=function(f,x){return f.children.find(y=>y.prediction.sectionType===x?!0:l(y))},d=function(f,x){let y=f.children.slice(x)[0];return!y||y.children.length===0?f.div&&f.prediction.sectionType==="unknown"?f:y:d(y,x)};if(!l(s,"header")){let f=d(s,0);f&&(f.prediction=new b({sectionType:"header",sectionFeatures:f.prediction.sectionFeatures,confidence:-1}))}if(!l(s,"footer")){let f=d(s,-1);f&&(f.prediction=new b({sectionType:"footer",sectionFeatures:f.prediction.sectionFeatures,confidence:-1}))}}return s.prediction}function G(){let s=[...document.body.querySelectorAll("*")].filter(t=>!["IFRAME","NOSCRIPT","BR","EM","STRONG","STYLE","SCRIPT"].includes(t.nodeName)).reduce((t,i,r)=>{var c=i.closest("svg");return!(c!==null&&c!==i)&&!t.includes(i.nodeName)&&t.push(i.nodeName),t},[]);console.log("DOM node types:",s);let e=[...document.querySelectorAll(s.join(","))],n=u.filterDivs(e);return console.log(`found ${n.length} visible divs to show!`),n}u.getAllVisibleDivs=G;u.buildBoxTree=(s,e)=>{let n=new S(0,0,e.innerWidth,e.document.scrollingElement.scrollHeight),t=s.map(l=>S.fromDiv(l,e));function i(l,d,h){d.forEach((m,f)=>{if(h.has(f))return;if(l.contains(m,!1)){let y=m;l.addChild(y),h.add(f),i(y,d,h)}})}i(n,t,new Set);function r(l){l.determineLayout(),l.children.forEach(r)}r(n);function c(l){if(l.children.length===1&&l.layout.numCols===1){let d=l.children[0];l.children=d.children,c(l),l.determineLayout()}else l.children.forEach(c)}c(n);function a(l){l.children.length>1&&l.layout.numCols===1&&l.children.every(d=>d.layout.numRows===0&&d.layout.numCols===0)?(l.children=[],a(l),l.determineLayout()):l.children.forEach(a)}a(n);function o(l){if(l.children.length>1){let d=l.children[0].layout.numCols;if(l.layout.numRows>1&&l.layout.numCols===1&&l.children.every(h=>h.layout.numRows===1&&h.layout.numCols>1&&h.layout.numCols===d)){console.log("mergeMultiSingleRowColums",l);let h=[];l.children.forEach(m=>{h.push(...m.children)}),l.children=h,l.determineLayout()}else l.children.forEach(o)}}return o(n),r(n),n};u.getVerticalBoxesFromHierarchy=(s,e=!0)=>{let n={...s};function t(i){let r=i.children;if(r.some(a=>r.some(o=>a!==o&&!a.isInside(o)&&(a.x>=o.x+o.width||a.x+a.width<=o.x)))){i.setChildren([]);return}else for(let a=0;a{document.body.style.cursor="crosshair",u.ui.overlaysDiv().addEventListener("click",e=>{let n=e.target;n.classList.contains("xp-overlay")&&n.remove(),u.ignoreElementForDection(n.dataset.boxId),document.body.style.removeProperty("cursor")},{once:!0})};u.ignoreElementForDection=s=>{function e(n){if(n.id===s){let t=function(i){[...u.ui.overlaysDiv().querySelectorAll(".xp-overlay")].forEach(c=>{c.dataset.boxId===i.id&&c.remove()}),i.children.forEach(t)};return n.ignored=!0,t(n),!0}else return n.children.some(e)}e(u.boxes)};u.predictPage=s=>{if(u.boxes?.children?.length>0){let n=function(i){i.ignored||(i.prediction&&i.prediction.sectionType!=="unknown"||i.prediction&&i.prediction.sectionType==="unknown"&&i.children.length===0?(e.push(i),console.warn(i.div,i.prediction),u.ui&&F(i,{window:s,padding:0,color:"rgba(0, 255, 0, 1)",label:i.prediction.sectionType})):i.children.forEach(n))};u.ui?.resetOverlays(),A(u.boxes,0,null,s);let e=[];n(u.boxes);let t=u.boxes.children.map(i=>{let r=[p.getXPath(i.div,document)];return r.push(...i.children.map(c=>"- "+p.getXPath(c.div,document))),r.join(` +(()=>{{let o=i=>{typeof i[0]=="string"&&!i[0].startsWith("[detect]")&&(i[0]=`[detect] ${i[0]}`)},e=console.log;console.log=(...i)=>{o(i),e(...i)},console.debug=(...i)=>{window.DEBUG&&(o(i),e(...i))};let n=console.warn;console.warn=(...i)=>{o(i),n(...i)};let t=console.error;console.error=(...i)=>{o(i),t(...i)}}function T(o){return o.toString(16)}function L(o,e,n,t){return T(o)+T(e)+T(n)+T(t)}var v=class o{constructor({r:e,g:n,b:t,a:i=1,name:r=""}){this.name=r,this.r=e,this.g=n,this.b=t,this.a=i}toHex(){return L(this.r,this.g,this.b,this.a)}static fromRGBA(e){let n=e.replace("rgba(","").replace(")","").split(",").map(t=>parseInt(t.trim()));return new o({r:n[0],g:n[1],b:n[2],a:n[3]})}toRGBA(){return`rgba(${this.r}, ${this.g}, ${this.b}, ${this.a})`}withAlpha(e){return new o({...this,a:e})}static random(e=!1){let n=Math.round(Math.random()*255),t=Math.round(Math.random()*255),i=Math.round(Math.random()*255),r=e?Math.random():1;return new o({name:`rand-${n}-${t}-${i}-${r}`,r:n,g:t,b:i,a:r})}static fromHex(e){let n=parseInt(e.substring(0,2),16),t=parseInt(e.substring(2,4),16),i=parseInt(e.substring(4,6),16),r=parseInt(e.substring(6,8),16);return new o({name:`hex-${n}-${t}-${i}-${r}`,r:n,g:t,b:i,a:r})}};function O(o,e){let n=Math.max(0,Math.min(o.x+o.width,e.x+e.width)-Math.max(o.x,e.x)),t=Math.max(0,Math.min(o.y+o.height,e.y+e.height)-Math.max(o.y,e.y)),i=n*t,r=e.width*e.height;return i/r*100}function D(o,e){let n=o.getBoundingClientRect();return{left:n.left+e.document.scrollingElement.scrollLeft,top:n.top+e.document.scrollingElement.scrollTop}}var S=class o{constructor(e,n,t,i,r){this.id=crypto.randomUUID(),this.x=Math.floor(e),this.y=Math.floor(n),this.width=Math.floor(t),this.height=Math.floor(i),this.div=r,this.children=[],this.prediction=null,this.layout=null}static fromDiv(e,n){let t=e.getBoundingClientRect(),i=D(e,n);return new o(i.left,i.top,t.width,t.height,e)}static areBoxesLaidOutAsGrid(e){console.log("areBoxesLaidOutAsGrid");try{if(e.length<2)return!1;let n=e.slice().sort((l,s)=>l.x-s.x||l.y-s.y),t=e.slice().sort((l,s)=>l.y-s.y||l.x-s.x);console.log(n),console.log(t);let i=[];for(let l=1;l1)return!1;let c=[];for(let l=1;l1)}finally{return!0}}contains(e,n=!0){return n?e.x-e.width>=this.x-this.width&&e.x+e.width<=this.x+this.width&&e.y-e.height>=this.y-this.height&&e.y+e.height<=this.y+this.height:O(this,e)>75}intersects(e){return!(e.x-e.width>this.x+this.width||e.x+e.widththis.y+this.height||e.y+e.height=this.x+this.width&&e.y-e.height<=this.y-this.height&&e.y+e.height>=this.y+this.height}addChild(e){this.children.push(e)}isChild(e){return this.children.some(this.isChild)}determineLayout(){if(this.layout={numCols:M(this.children),numRows:P(this.children)},this.layout.numCols>1){let e=[],n=this.children.slice().sort((t,i)=>t.y-i.y);for(let t=0;tr.x-c.x))}this.children=e,console.log("sortedBoxes",e)}return this.layout}toJSONString(){function e(t){return{id:t.id,x:t.x,y:t.y,width:t.width,height:t.height,layout:t.layout,prediction:t.prediction,template:t.template,xpath:t.xpath,xpathWithDetails:t.xpathWithDetails,children:t.children.map(e)}}let n=e(this);return console.log(n),n}};function M(o){if(!o.length)return 0;let e=[];return o.slice().sort((n,t)=>n.x-t.x).forEach(n=>{let t=n.x,i=n.x+n.width,r=e[e.length-1];r?t>=r-5&&e.push(i):e.push(i)}),e.length}function P(o){if(!o.length)return 0;let e=[];return o.slice().sort((n,t)=>n.y-t.y).forEach(n=>{let t=n.y,i=n.y+n.height,r=e[e.length-1];r?t>=r-5&&e.push(i):e.push(i)}),e.length}var p=class o{static getXPath(e,n,t=!1){for(var i=n.getElementsByTagName("*"),r=[];e&&e.nodeType==1;e=e.parentNode)if(t)if(e.hasAttribute("id")){for(var c=0,a=0;a1));a++);if(c==1)return r.unshift('id("'+e.getAttribute("id")+'")'),r.join("/");r.unshift(e.localName.toLowerCase()+'[@id="'+e.getAttribute("id")+'"]')}else e.hasAttribute("class")&&r.unshift(e.localName.toLowerCase()+'[@class="'+[...e.classList].join(" ").trim()+'"]');else{for(var l=1,s=e.previousSibling;s;s=s.previousSibling)s.localName==e.localName&&(l+=1);r.unshift(e.localName.toLowerCase()+"["+l+"]")}return r.length?"/"+r.join("/"):null}static isVisible(e,n){if(!e)return!1;if(e.nodeType===n.Node.DOCUMENT_NODE)return!0;if(e.nodeType===n.Node.ELEMENT_NODE){let t=n.getComputedStyle(e);return t.display.includes("none")||t.visibility.includes("hidden")||t.opacity==="0"?!1:o.isVisible(e.parentNode,n)}}static isUserVisible(e,n){if(!o.isVisible(e,n))return!1;let t=e.getBoundingClientRect(),{width:i,height:r}=o.getPageSize(n.document);return!(t.height===0||t.width===0)}static getNSiblingsDivs(e,n,t=null){let i=t;isNaN(t)||(i=a=>a===t);let r="",c=[];e.querySelectorAll("div").forEach(a=>{let l=o.getXPath(a,n),s=l.substring(0,l.lastIndexOf("["));c[s]?c[s].push(a):c[s]=[a]});for(let a in c)if(i(c[a].length)){r=a;break}return c[r]||null}static getPageSize(e){var n=e.documentElement,t=e.body,i=Math.max(n.clientWidth,n.scrollWidth,n.offsetWidth,t.scrollWidth,t.offsetWidth),r=Math.max(n.clientHeight,n.scrollHeight,n.offsetHeight,t.scrollHeight,t.offsetHeight);return{width:i,height:r}}static getOffsetRect(e,n){let t=e.getBoundingClientRect(),i=n.document?.scrollingElement?.scrollLeft||0,r=n.document?.scrollingElement?.scrollTop||0;return{x:t.left+i,y:t.top+r,width:t.width,height:t.height}}static checkElStackUpCSSClasses(e,n){let t=e;for(;t;){if(t.classList.contains(n))return!0;t=t.parentElement}return!1}static getAllVisibleElements=(e=document.body,n)=>{let t=[...e.querySelectorAll("*")].filter(c=>!["IFRAME","NOSCRIPT","BR","EM","STRONG","STYLE","SCRIPT"].includes(c.nodeName)).reduce((c,a,l)=>{var s=a.closest("svg");return!(s!==null&&s!==a)&&!c.includes(a.nodeName)&&c.push(a.nodeName),c},[]);console.debug("DOM node types:",t);let r=[...e.querySelectorAll(t.join(","))].filter(c=>o.isUserVisible(c,n));return console.log(`found ${r.length} visible elements in the page.`),r}};var C=class{constructor(...e){e.reduce((n,t,i)=>(n[t]=1<n|t,0)}setFlag(e){this.#e|=e}unsetFlag(e){this.#e&=~e}isFlagSet(e){return(this.#e&e)!==0}areOnlyFlagsSet(...e){let n=e.reduce((t,i)=>t|i,0);return this.#e===n}getFlags(e){return Object.keys(e).filter(n=>this.isFlagSet(e[n]))}};function E(o){var e=0,n=o.length,t=0;if(n>0)for(;t{let t=n[n.length-1]||{},i=[o[0]];return e.forEach((r,c)=>{let a=Number.isInteger(r)?n[r]:t[r];i.push(a,o[c+1])}),i.join("")}}function I(o,e){let n=null,t=null;return n=[...o.querySelectorAll("*")].some(i=>{let r=e.getComputedStyle(i),c=i.getBoundingClientRect(),a=r.backgroundImage||"none",l="none";if(l&&l.includes("rgba")&&Color.fromRGBA(l).a===0&&(l="none"),a.includes("none")&&l.includes("none"))return!1;if(a||l)return t=i,!0}),n||(n=[...o.querySelectorAll("img")].some(i=>p.isUserVisible(i,e)),n)?t:n}var u=window.xp??{},b=class{constructor({sectionType:e,sectionFeatures:n,template:t,confidence:i}){this.sectionType=e,this.sectionFeatures=n,this.template=t,this.confidence=i}},q=[{name:"carousel",predictFn:(o,e,n,t,i)=>{console.log(o.div),console.groupCollapsed(">>> carousel");let r=p.getNSiblingsDivs(o.div,i.document,c=>c>=2);if(r){console.log("predict carousel"),console.log(r);let c={};r.forEach(l=>{let s=p.getXPath(l,i.document),d=[...l.querySelectorAll("div")].map(y=>p.getXPath(y,i.document).slice(s.length));console.log(d);let h=E(d.join(` +`));console.log(h),c[h]?c[h].push(l):c[h]=[l]}),console.groupEnd();let a=Object.keys(c).filter(l=>c[l].length>1);if(c[a]){let l=!1,s=!1;if(c[a].forEach(d=>{let h=d.getBoundingClientRect();!p.isVisible(d,i)||h.x+h.width>i.innerWidth?s=!0:l=!0}),l&&s)return!0}return!1}return console.groupEnd(),!1}},{name:"columns",predictFn:(o,e,n,t,i)=>(console.log("flags",t.getFlags(g)),t.isFlagSet(g.isGridLayout))},{name:"hero",predictFn:(o,e,n,t,i)=>o.height<=i.innerHeight&&t.isFlagSet(g.hasBackground)&&t.isFlagSet(g.hasHeading)&&t.isFlagSet(g.hasCTA)},{name:"default-content",predictFn:(o,e,n,t,i)=>{let r=!0;[...o.div.querySelectorAll("img")].some(l=>{let s=l.getBoundingClientRect();return s.width>50&&s.height>50})&&(r=!1);let a=!o.children.some(l=>(console.log(l.prediction?.sectionType),!["heading","text","text+icons"].includes(l.prediction?.sectionType)));return console.log("childrenOnlyTextLike",a),t.isFlagSet(g.hasTexts)&&!t.isFlagSet(g.hasImages)&&!t.isFlagSet(g.hasBackground)||!t.isFlagSet(g.isGridLayout)&&a&&t.isFlagSet(g.hasTexts)&&r&&!t.isFlagSet(g.hasBackground)}}];u.DOM=p;u.Flags=C;u.FlagSet=w;function $(o,e){let n=e.document.createElement("a");document.body.appendChild(n);let t=e.getComputedStyle(n);return[...o.querySelectorAll("a")].find(r=>{if(["background","background-color","background-image"].find(l=>{let s=e.getComputedStyle(r);return console.log(l,s[l],t[l]),s[l]!==t[l]}))return console.log("hasBackground"),!0;let a=0;return["left","right","top","bottom"].forEach(l=>{let s=e.getComputedStyle(r).getPropertyValue(`border-${l}-style`);console.log(l,s,t[`border-${l}-style`]),s!==t[`border-${l}-style`]&&a++}),a>1?(console.log("bordersNum"),!0):!1})!==void 0}var G=[new v({name:"violet",r:148,g:0,b:211}),new v({name:"indigo",r:75,g:0,b:130}),new v({name:"blue",r:0,g:0,b:255}),new v({name:"green",r:0,g:255,b:0}),new v({name:"yellow",r:255,g:255,b:0}),new v({name:"orange",r:255,g:127,b:0}),new v({name:"red",r:255,g:0,b:0})];u.filterDivs=o=>{let e=o.filter(t=>{let i=t.getBoundingClientRect(),{width:r,height:c}=p.getPageSize();return!t.classList.contains("xp-ui")&&!t.closest(".xp-ui")&&i.width!==0&&i.height!==0&&i.width*i.height>5e3&&i.width*i.height<.8*r*c&&p.isVisible(t,window)});console.log(e.length),console.log(e.map(t=>t));let n=e.filter(t=>{let i=t.parentElement;for(;i;){let r=t.getBoundingClientRect(),c=i.getBoundingClientRect();if(c.width===0||c.height===0){i=i.parentElement;continue}if(r.width>=.9*c.width&&r.height>=.9*c.height)return!1;i=i.parentElement}return!0});return console.log(n.length),console.log(n.map(t=>t)),n};var U=B`position:absolute;z-index:10000000;left:${0}px;top:${1}px;width:${2}px;height:${3}px;border:2px solid ${4};`,F=(o,{window:e,target:n=document.body,padding:t=0,color:i=null,label:r=null})=>{let c=i||"rgba(0, 0, 255, 1)",a=p.getOffsetRect(o.div,e),s=n.closest("body").getBoundingClientRect().y||0,d=document.createElement("div");d.dataset.boxId=o.id,d.dataset.boxXpath=o.xpath,d.dataset.boxXpathWithDetails=o.xpathWithDetails,d.dataset.layout=JSON.stringify(o.layout);let h=(({id:y,x:f,y:x,width:m,height:k,xpath:H,layout:R})=>({id:y,x:f,y:x,width:m,height:k,xpath:H,layout:R}))(o);if((o.layout.numCols>1||o.layout.numRows>1)&&(h.childrenXpaths=o.children.map(y=>({xpath:y.xpath,xpathWithDetails:y.xpathWithDetails}))),d.dataset.boxData=JSON.stringify(h),d.className="xp-overlay",d.style=U(a.x+t,a.y+t-s,a.width-t*2-4,a.height-t*2-4,c),r){let y=e.document.createElement("div");y.className="xp-overlay-label",y.textContent=r,d.appendChild(y)}n.appendChild(d)};function N(o,e,n=0,t=G,i=null,r=0){o.forEach((c,a)=>{let l=i||t[a%(t.length-1)],s=r===0?1:Math.max(.1,.5-r*.1),d=l.withAlpha(s).toRGBA();c.color=d,F(c,{window:e,target:e.document.body,padding:n,color:d,label:`layout: ${c.layout.numCols}x${c.layout.numRows}`}),c.children.length>0&&N(c.children,e,n+4,t,l,r+1)})}var g=new C("isFromRootBox","hasHeader","hasTexts","hasBackground","hasHeading","hasCTA","hasImages","hasMultipleColumns","hasMultipleRows","isGridLayout","isInsideAHeaderLikeElement","isInsideAFooterLikeElement");function A(o,e,n=null,t,i=!0){if(o.ignored)return null;let r="unknown",c=new w,a=o.div;if(i&&c.setFlag(g.isFromRootBox),a){let s=a.cloneNode(!0);s.querySelectorAll("script, style, link, meta, noscript").forEach(k=>k.remove()),s.textContent.replaceAll(" ","").replaceAll(` +`,"").trim().length>0&&c.setFlag(g.hasTexts),([...a.querySelectorAll("img, picture, svg")].length>0||["IMG","PICTURE","SVG"].includes(a.nodeName))&&c.setFlag(g.hasImages),!!I(o.div,t)&&c.setFlag(g.hasBackground),([...a.querySelectorAll("h1, h2, h3, h4, h5, h6")].length>0||["H1","H2","H3","H4","H5","H6"].includes(a.nodeName))&&c.setFlag(g.hasHeading),$(a,t)&&c.setFlag(g.hasCTA);let m=o.determineLayout();m.numRows>1&&c.setFlag(g.hasMultipleRows),m.numCols>1&&c.setFlag(g.hasMultipleColumns),m.numCols>1&&S.areBoxesLaidOutAsGrid(o.children)&&c.setFlag(g.isGridLayout),(a.closest("header, .header")||p.checkElStackUpCSSClasses(a,"header"))&&c.setFlag(g.isInsideAHeaderLikeElement),(a.closest("footer, .footer")||p.checkElStackUpCSSClasses(a,"footer"))&&c.setFlag(g.isInsideAFooterLikeElement)}let l=o.children;if(l.forEach((...s)=>{A(...s,t,!1)}),!i){let s=q.find(d=>d.predictFn(o,e,null,c,t));s&&(r=s.name)}if(l.length===0&&c.isFlagSet(g.isFromRootBox)&&e===0||l.length>0&&l.every(s=>s.prediction.sectionFeatures.includes("isInsideAHeaderLikeElement"))?r="header":l.length>0&&l.every(s=>s.prediction.sectionFeatures.includes("isInsideAFooterLikeElement"))&&(r="footer"),o.prediction=new b({sectionType:r,sectionFeatures:c.getFlags(g),confidence:-1}),console.group("prediction"),console.log("prediction"),console.log(c.getFlags(g)),console.log(a),console.log("section prediction:",o.prediction),console.groupEnd(),i){let s=function(f,x){return f.children.find(m=>m.prediction.sectionType===x?!0:s(m))},d=function(f,x){let m=f.children.slice(x)[0];return!m||m.children.length===0?f.div&&f.prediction.sectionType==="unknown"?f:m:d(m,x)};if(!s(o,"header")){let f=d(o,0);f&&(f.prediction=new b({sectionType:"header",sectionFeatures:f.prediction.sectionFeatures,confidence:-1}))}if(!s(o,"footer")){let f=d(o,-1);f&&(f.prediction=new b({sectionType:"footer",sectionFeatures:f.prediction.sectionFeatures,confidence:-1}))}}return o.prediction}function z(){let o=[...document.body.querySelectorAll("*")].filter(t=>!["IFRAME","NOSCRIPT","BR","EM","STRONG","STYLE","SCRIPT"].includes(t.nodeName)).reduce((t,i,r)=>{var c=i.closest("svg");return!(c!==null&&c!==i)&&!t.includes(i.nodeName)&&t.push(i.nodeName),t},[]);console.log("DOM node types:",o);let e=[...document.querySelectorAll(o.join(","))],n=u.filterDivs(e);return console.log(`found ${n.length} visible divs to show!`),n}u.getAllVisibleDivs=z;u.buildBoxTree=(o,e)=>{let n=new S(0,0,e.innerWidth,e.document.scrollingElement.scrollHeight),t=o.map(s=>S.fromDiv(s,e));function i(s,d,h){d.forEach((y,f)=>{if(h.has(f))return;if(s.contains(y,!1)){let m=y;s.addChild(m),h.add(f),i(m,d,h)}})}i(n,t,new Set);function r(s){s.determineLayout(),s.children.forEach(r)}r(n);function c(s){if(s.children.length===1&&s.layout.numCols===1){let d=s.children[0];s.children=d.children,c(s),s.determineLayout()}else s.children.forEach(c)}c(n);function a(s){s.children.length>1&&s.layout.numCols===1&&s.children.every(d=>d.layout.numRows===0&&d.layout.numCols===0)?(s.children=[],a(s),s.determineLayout()):s.children.forEach(a)}a(n);function l(s){if(s.children.length>1){let d=s.children[0].layout.numCols;if(s.layout.numRows>1&&s.layout.numCols===1&&s.children.every(h=>h.layout.numRows===1&&h.layout.numCols>1&&h.layout.numCols===d)){console.log("mergeMultiSingleRowColums",s);let h=[];s.children.forEach(y=>{h.push(...y.children)}),s.children=h,s.determineLayout()}else s.children.forEach(l)}}return l(n),r(n),n};u.getVerticalBoxesFromHierarchy=(o,e=!0)=>{let n={...o};function t(i){let r=i.children;if(r.some(a=>r.some(l=>a!==l&&!a.isInside(l)&&(a.x>=l.x+l.width||a.x+a.width<=l.x)))){i.setChildren([]);return}else for(let a=0;a{document.body.style.cursor="crosshair",u.ui.overlaysDiv().addEventListener("click",e=>{let n=e.target;n.classList.contains("xp-overlay")&&n.remove(),u.ignoreElementForDection(n.dataset.boxId),document.body.style.removeProperty("cursor")},{once:!0})};u.ignoreElementForDection=o=>{function e(n){if(n.id===o){let t=function(i){[...u.ui.overlaysDiv().querySelectorAll(".xp-overlay")].forEach(c=>{c.dataset.boxId===i.id&&c.remove()}),i.children.forEach(t)};return n.ignored=!0,t(n),!0}else return n.children.some(e)}e(u.boxes)};u.predictPage=o=>{if(u.boxes?.children?.length>0){let n=function(i){i.ignored||(i.prediction&&i.prediction.sectionType!=="unknown"||i.prediction&&i.prediction.sectionType==="unknown"&&i.children.length===0?(e.push(i),console.warn(i.div,i.prediction),u.ui&&F(i,{window:o,padding:0,color:"rgba(0, 255, 0, 1)",label:i.prediction.sectionType})):i.children.forEach(n))};u.ui?.resetOverlays(),A(u.boxes,0,null,o);let e=[];n(u.boxes);let t=u.boxes.children.map(i=>{let r=[p.getXPath(i.div,document)];return r.push(...i.children.map(c=>"- "+p.getXPath(c.div,document))),r.join(` `)||""}).join(` -`)||"";return u.boxes.template={raw:t,hash:E(t)},u.predictedBoxes=e,console.log("final boxes",u.boxes),console.log("predicted boxes",u.predictedBoxes),u.ui?.toggleOverlays(!0),u.boxes}};u.detectSections=async(s,e,n={autoDetect:!1})=>{u.ui?.resetOverlays();let{document:t}=e,i=p.getAllVisibleElements(s,e);console.log("visible divs",i),i=i.filter(o=>{let l=o.getBoundingClientRect();return l.width*l.height>22e3}),console.log("filtered divs",i);let r=u.buildBoxTree(i,e);console.log("boxes hierarchy",r);function c(o,l){o.div&&(o.xpath=p.getXPath(o.div,l),o.xpathWithDetails=p.getXPath(o.div,l,!0),o.id=`box-id-${E(o.xpath)}`),o.children&&o.children.length>0&&o.children.forEach(d=>c(d,l))}c(r,t),u.boxes=r;let a=r.children.map(o=>{let l=[o.xpath];return l.push(...o.children.map(d=>"- "+d.xpath)),l.join(` +`)||"";return u.boxes.template={raw:t,hash:E(t)},u.predictedBoxes=e,console.log("final boxes",u.boxes),console.log("predicted boxes",u.predictedBoxes),u.ui?.toggleOverlays(!0),u.boxes}};u.detectSections=async(o,e,n={autoDetect:!1})=>{u.ui?.resetOverlays();let{document:t}=e,i=p.getAllVisibleElements(o,e);console.log("visible divs",i),i=i.filter(l=>{let s=l.getBoundingClientRect();return s.width*s.height>1e4}),console.log("filtered divs",i);let r=u.buildBoxTree(i,e);console.log("boxes hierarchy",r);function c(l,s){l.div&&(l.xpath=p.getXPath(l.div,s),l.xpathWithDetails=p.getXPath(l.div,s,!0),l.id=`box-id-${E(l.xpath)}`),l.children&&l.children.length>0&&l.children.forEach(d=>c(d,s))}c(r,t),u.boxes=r;let a=r.children.map(l=>{let s=[l.xpath];return s.push(...l.children.map(d=>"- "+d.xpath)),s.join(` `)||""}).join(` -`)||"";if(console.log("template",a),u.template={raw:a,hash:E(a)},!n.autoDetect)N(r.children,e);else if(u.boxes?.children?.length>0){let l=function(h){h.ignored||(h.prediction&&h.prediction.sectionType!=="unknown"||h.prediction&&h.prediction.sectionType==="unknown"&&h.children.length===0?o.push(h):h.children.forEach(l))};A(u.boxes,0,null,e);let o=[];l(u.boxes),o.forEach(h=>{F(h,{window:e,target:e.document.body,padding:0,color:h.color,label:h.prediction.sectionType})});let d=u.boxes.children.map(h=>{let m=[p.getXPath(h.div,t)];return m.push(...h.children.map(f=>"- "+p.getXPath(f.div,t))),m.join(` +`)||"";if(console.log("template",a),u.template={raw:a,hash:E(a)},!n.autoDetect)N(r.children,e);else if(u.boxes?.children?.length>0){let s=function(h){h.ignored||(h.prediction&&h.prediction.sectionType!=="unknown"||h.prediction&&h.prediction.sectionType==="unknown"&&h.children.length===0?l.push(h):h.children.forEach(s))};A(u.boxes,0,null,e);let l=[];s(u.boxes),l.forEach(h=>{F(h,{window:e,target:e.document.body,padding:0,color:h.color,label:h.prediction.sectionType})});let d=u.boxes.children.map(h=>{let y=[p.getXPath(h.div,t)];return y.push(...h.children.map(f=>"- "+p.getXPath(f.div,t))),y.join(` `)||""}).join(` -`)||"";u.boxes.template={raw:d,hash:E(d)},u.boxes.predictedBoxes=o,console.log("final boxes",u.boxes),u.ui?.toggleOverlays(!0)}return u.ui?.toggleOverlays(!0),u.boxes};window.xp=u;})(); +`)||"";u.boxes.template={raw:d,hash:E(d)},u.boxes.predictedBoxes=l,console.log("final boxes",u.boxes),u.ui?.toggleOverlays(!0)}return u.ui?.toggleOverlays(!0),u.boxes};window.xp=u;})();