@runtypelabs/persona 4.8.0 → 4.10.0
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/README.md +14 -1
- package/dist/animations/glyph-cycle.d.cts +1 -1
- package/dist/animations/glyph-cycle.d.ts +1 -1
- package/dist/animations/{types-BsZtXPKK.d.cts → types-4ROVJ1gA.d.cts} +42 -0
- package/dist/animations/{types-BsZtXPKK.d.ts → types-4ROVJ1gA.d.ts} +42 -0
- package/dist/animations/wipe.d.cts +1 -1
- package/dist/animations/wipe.d.ts +1 -1
- package/dist/chunk-IO5VVUKP.js +3 -0
- package/dist/chunk-IPVK3KOM.js +1 -0
- package/dist/chunk-UPO4GUFC.js +1 -0
- package/dist/codegen.cjs +6 -6
- package/dist/codegen.js +8 -8
- package/dist/context-mentions-7S5KVUTG.js +169 -0
- package/dist/context-mentions-inline-TTCN7ZM2.js +4 -0
- package/dist/context-mentions-inline.cjs +4 -0
- package/dist/context-mentions-inline.d.cts +203 -0
- package/dist/context-mentions-inline.d.ts +203 -0
- package/dist/context-mentions-inline.js +4 -0
- package/dist/context-mentions.cjs +295 -0
- package/dist/context-mentions.d.cts +7025 -0
- package/dist/context-mentions.d.ts +7025 -0
- package/dist/context-mentions.js +295 -0
- package/dist/index.cjs +72 -64
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +634 -3
- package/dist/index.d.ts +634 -3
- package/dist/index.global.js +59 -51
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +64 -56
- package/dist/index.js.map +1 -1
- package/dist/launcher.global.js +2 -2
- package/dist/launcher.global.js.map +1 -1
- package/dist/plugin-kit.cjs +1 -1
- package/dist/plugin-kit.d.cts +17 -0
- package/dist/plugin-kit.d.ts +17 -0
- package/dist/plugin-kit.js +1 -1
- package/dist/smart-dom-reader.cjs +17 -16
- package/dist/smart-dom-reader.d.cts +507 -1
- package/dist/smart-dom-reader.d.ts +507 -1
- package/dist/smart-dom-reader.js +17 -16
- package/dist/theme-editor-preview.cjs +236 -57
- package/dist/theme-editor-preview.d.cts +485 -1
- package/dist/theme-editor-preview.d.ts +485 -1
- package/dist/theme-editor-preview.js +53 -47
- package/dist/theme-editor.cjs +7 -7
- package/dist/theme-editor.d.cts +473 -0
- package/dist/theme-editor.d.ts +473 -0
- package/dist/theme-editor.js +5 -5
- package/dist/theme-reference.cjs +1 -1
- package/dist/theme-reference.d.cts +2 -0
- package/dist/theme-reference.d.ts +2 -0
- package/dist/widget.css +1 -1
- package/package.json +15 -3
- package/src/client.test.ts +69 -0
- package/src/client.ts +65 -51
- package/src/components/artifact-pane.test.ts +47 -0
- package/src/components/artifact-pane.ts +25 -2
- package/src/components/composer-parts.ts +3 -12
- package/src/components/context-mention-button.test.ts +70 -0
- package/src/components/context-mention-button.ts +82 -0
- package/src/components/context-mention-chip.ts +134 -0
- package/src/components/context-mention-menu.test.ts +508 -0
- package/src/components/context-mention-menu.ts +0 -0
- package/src/components/message-bubble.test.ts +175 -0
- package/src/components/message-bubble.ts +177 -19
- package/src/components/panel.ts +7 -10
- package/src/context-mentions-bundle.test.ts +163 -0
- package/src/context-mentions-entry.ts +185 -0
- package/src/context-mentions-inline-entry.test.ts +136 -0
- package/src/context-mentions-inline-entry.ts +226 -0
- package/src/context-mentions-inline-loader.test.ts +30 -0
- package/src/context-mentions-inline-loader.ts +36 -0
- package/src/context-mentions-inline.ts +15 -0
- package/src/context-mentions-loader.ts +32 -0
- package/src/context-mentions.ts +16 -0
- package/src/index-core.ts +27 -0
- package/src/index-global.ts +51 -0
- package/src/markdown-parsers-loader.ts +35 -44
- package/src/plugin-kit.test.ts +40 -0
- package/src/plugin-kit.ts +39 -5
- package/src/runtime/init-update-reset.test.ts +81 -0
- package/src/runtime/init.test.ts +62 -0
- package/src/runtime/init.ts +7 -14
- package/src/session.mentions.test.ts +175 -0
- package/src/session.test.ts +52 -4
- package/src/session.ts +121 -5
- package/src/smart-dom-reader.test.ts +129 -2
- package/src/smart-dom-reader.ts +127 -1
- package/src/styles/context-mention-menu-css.ts +176 -0
- package/src/styles/widget.css +243 -126
- package/src/theme-editor/sections.ts +3 -3
- package/src/types/theme.ts +2 -0
- package/src/types.ts +542 -0
- package/src/ui.artifact-pane-gating.test.ts +11 -1
- package/src/ui.attachments-drop.test.ts +90 -0
- package/src/ui.header-update-stability.test.ts +149 -0
- package/src/ui.launcher-update-merge.test.ts +83 -0
- package/src/ui.mention-submit.test.ts +235 -0
- package/src/ui.send-button-stream-update.test.ts +69 -0
- package/src/ui.ts +379 -84
- package/src/utils/chunk-loader.test.ts +97 -0
- package/src/utils/chunk-loader.ts +88 -0
- package/src/utils/composer-contenteditable.test.ts +507 -0
- package/src/utils/composer-contenteditable.ts +626 -0
- package/src/utils/composer-document.test.ts +280 -0
- package/src/utils/composer-document.ts +293 -0
- package/src/utils/composer-history.test.ts +35 -7
- package/src/utils/composer-history.ts +30 -20
- package/src/utils/composer-input.ts +159 -0
- package/src/utils/config-merge.test.ts +131 -0
- package/src/utils/config-merge.ts +61 -0
- package/src/utils/context-mention-controller.test.ts +1215 -0
- package/src/utils/context-mention-controller.ts +1186 -0
- package/src/utils/context-mention-manager.test.ts +422 -0
- package/src/utils/context-mention-manager.ts +410 -0
- package/src/utils/context-mention-orchestrator.test.ts +538 -0
- package/src/utils/context-mention-orchestrator.ts +348 -0
- package/src/utils/live-region.test.ts +108 -0
- package/src/utils/live-region.ts +94 -0
- package/src/utils/mention-channels.ts +63 -0
- package/src/utils/mention-llm-format.test.ts +91 -0
- package/src/utils/mention-llm-format.ts +79 -0
- package/src/utils/mention-matcher.test.ts +86 -0
- package/src/utils/mention-matcher.ts +221 -0
- package/src/utils/mention-token.ts +72 -0
- package/src/utils/mention-trigger.test.ts +155 -0
- package/src/utils/mention-trigger.ts +156 -0
- package/src/utils/theme.test.ts +54 -4
- package/src/utils/theme.ts +6 -3
- package/src/utils/tokens.ts +27 -11
package/dist/plugin-kit.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var E=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var H=Object.prototype.hasOwnProperty;var C=(e,t)=>{for(var o in t)E(e,o,{get:t[o],enumerable:!0})},z=(e,t,o,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of M(t))!H.call(e,r)&&r!==o&&E(e,r,{get:()=>t[r],enumerable:!(i=O(t,r))||i.enumerable});return e};var N=e=>z(E({},"__esModule",{value:!0}),e);var j={};C(j,{createPopover:()=>A,getStyleRoot:()=>y,injectStyles:()=>I,isEditableEventTarget:()=>W});module.exports=N(j);function y(e){let t=e.getRootNode?.();return t instanceof ShadowRoot||t instanceof Document?t:e.ownerDocument??document}function h(e,t,o){let i=e instanceof Document?e.head:e,r=t.replace(/["\\]/g,"\\$&");if(i.querySelector(`style[data-persona-plugin-style="${r}"]`))return;let d=(e instanceof Document?e:e.ownerDocument??document).createElement("style");d.setAttribute("data-persona-plugin-style",t),d.textContent=o,i.appendChild(d)}function I(e,t,o){if(e instanceof Document||e instanceof ShadowRoot){h(e,t,o);return}let i=e;if(i.isConnected){h(y(i),t,o);return}let r=i.ownerDocument??document;h(r,t,o),queueMicrotask(()=>{let l=y(i);l!==r&&h(l,t,o)})}function $(e){let t=e.getRootNode?.();return t instanceof ShadowRoot?t:(e.ownerDocument??document).body}function A(e){let{anchor:t,content:o,placement:i="bottom-start",offset:r=6,matchAnchorWidth:l=!1,horizontalOffset:d,verticalOffset:L,zIndex:x=2147483e3,onOpen:P,onDismiss:D}=e,T=e.container??$(t),c=!1,f=null,v=()=>{if(!c)return;let n=t.getBoundingClientRect();o.style.position="fixed",l&&(o.style.minWidth=`${n.width}px`),d&&(o.style.maxWidth=`${n.width}px`);let a=o.getBoundingClientRect(),s=L?.()??null,p=s!=null?n.top+s:n.top,w=i==="top-start"||i==="top-end"?p-r-a.height:n.bottom+r,m=i==="bottom-end"||i==="top-end"?n.right-a.width:n.left,b=d?.()??null;if(b!=null){let S=Math.max(n.left,n.right-a.width);m=Math.min(Math.max(n.left+b,n.left),S)}o.style.top=`${w}px`,o.style.left=`${m}px`},u=()=>{c&&(c=!1,f&&(f(),f=null),o.remove())},R=()=>{if(c)return;c=!0,x!=null&&(o.style.zIndex=String(x)),T.appendChild(o),v();let n=(t.ownerDocument??document).defaultView??window,a=t.ownerDocument??document,s=()=>{if(!t.isConnected){u(),D?.("anchor-removed");return}v()},p=g=>{let m=typeof g.composedPath=="function"?g.composedPath():[];m.includes(o)||m.includes(t)||(u(),D?.("outside"))},w=n.setTimeout(()=>{a.addEventListener("pointerdown",p,!0)},0);n.addEventListener("scroll",s,!0),n.addEventListener("resize",s),f=()=>{n.clearTimeout(w),a.removeEventListener("pointerdown",p,!0),n.removeEventListener("scroll",s,!0),n.removeEventListener("resize",s)},P?.()};return{get isOpen(){return c},open:R,close:u,toggle:()=>c?u():R(),reposition:v,destroy:u}}function W(e){return(typeof e.composedPath=="function"?e.composedPath():[]).some(o=>o instanceof HTMLElement&&(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))}0&&(module.exports={createPopover,getStyleRoot,injectStyles,isEditableEventTarget});
|
package/dist/plugin-kit.d.cts
CHANGED
|
@@ -41,6 +41,23 @@ interface PopoverOptions {
|
|
|
41
41
|
offset?: number;
|
|
42
42
|
/** Set `content`'s `min-width` to the anchor's width. Default `false`. */
|
|
43
43
|
matchAnchorWidth?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Horizontal anchoring override for `*-start` placements. Returns the desired
|
|
46
|
+
* left offset in px measured from the anchor's LEFT edge (e.g. the `@` trigger's
|
|
47
|
+
* x within the composer), or `null` to left-align with the anchor as usual. When
|
|
48
|
+
* this option is present the content is content-sized and capped to the anchor's
|
|
49
|
+
* width, and the resolved left is clamped so the content never overflows the
|
|
50
|
+
* anchor's left/right edges (Slack-style: a near-right trigger shifts the menu
|
|
51
|
+
* left to fit). Omit it entirely for plain anchor-left/right placement.
|
|
52
|
+
*/
|
|
53
|
+
horizontalOffset?: () => number | null;
|
|
54
|
+
/**
|
|
55
|
+
* Vertical anchoring override for `top-*` placements. Returns the desired
|
|
56
|
+
* anchor point's top offset in px measured from the anchor's TOP edge (e.g.
|
|
57
|
+
* the trigger line's top within the composer), or `null` to use the anchor's
|
|
58
|
+
* top edge as usual.
|
|
59
|
+
*/
|
|
60
|
+
verticalOffset?: () => number | null;
|
|
44
61
|
/**
|
|
45
62
|
* Inline `z-index` for `content`. Default `2147483000` so it overlays the rest
|
|
46
63
|
* of the widget. Pass `null` to leave z-index to your own CSS.
|
package/dist/plugin-kit.d.ts
CHANGED
|
@@ -41,6 +41,23 @@ interface PopoverOptions {
|
|
|
41
41
|
offset?: number;
|
|
42
42
|
/** Set `content`'s `min-width` to the anchor's width. Default `false`. */
|
|
43
43
|
matchAnchorWidth?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Horizontal anchoring override for `*-start` placements. Returns the desired
|
|
46
|
+
* left offset in px measured from the anchor's LEFT edge (e.g. the `@` trigger's
|
|
47
|
+
* x within the composer), or `null` to left-align with the anchor as usual. When
|
|
48
|
+
* this option is present the content is content-sized and capped to the anchor's
|
|
49
|
+
* width, and the resolved left is clamped so the content never overflows the
|
|
50
|
+
* anchor's left/right edges (Slack-style: a near-right trigger shifts the menu
|
|
51
|
+
* left to fit). Omit it entirely for plain anchor-left/right placement.
|
|
52
|
+
*/
|
|
53
|
+
horizontalOffset?: () => number | null;
|
|
54
|
+
/**
|
|
55
|
+
* Vertical anchoring override for `top-*` placements. Returns the desired
|
|
56
|
+
* anchor point's top offset in px measured from the anchor's TOP edge (e.g.
|
|
57
|
+
* the trigger line's top within the composer), or `null` to use the anchor's
|
|
58
|
+
* top edge as usual.
|
|
59
|
+
*/
|
|
60
|
+
verticalOffset?: () => number | null;
|
|
44
61
|
/**
|
|
45
62
|
* Inline `z-index` for `content`. Default `2147483000` so it overlays the rest
|
|
46
63
|
* of the widget. Pass `null` to leave z-index to your own CSS.
|
package/dist/plugin-kit.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function R(t){let e=t.getRootNode?.();return e instanceof ShadowRoot||e instanceof Document?e:t.ownerDocument??document}function h(t,e,o){let i=t instanceof Document?t.head:t,r=e.replace(/["\\]/g,"\\$&");if(i.querySelector(`style[data-persona-plugin-style="${r}"]`))return;let d=(t instanceof Document?t:t.ownerDocument??document).createElement("style");d.setAttribute("data-persona-plugin-style",e),d.textContent=o,i.appendChild(d)}function O(t,e,o){if(t instanceof Document||t instanceof ShadowRoot){h(t,e,o);return}let i=t;if(i.isConnected){h(R(i),e,o);return}let r=i.ownerDocument??document;h(r,e,o),queueMicrotask(()=>{let l=R(i);l!==r&&h(l,e,o)})}function S(t){let e=t.getRootNode?.();return e instanceof ShadowRoot?e:(t.ownerDocument??document).body}function M(t){let{anchor:e,content:o,placement:i="bottom-start",offset:r=6,matchAnchorWidth:l=!1,horizontalOffset:d,verticalOffset:b,zIndex:E=2147483e3,onOpen:L,onDismiss:y}=t,P=t.container??S(e),c=!1,f=null,v=()=>{if(!c)return;let n=e.getBoundingClientRect();o.style.position="fixed",l&&(o.style.minWidth=`${n.width}px`),d&&(o.style.maxWidth=`${n.width}px`);let a=o.getBoundingClientRect(),s=b?.()??null,p=s!=null?n.top+s:n.top,w=i==="top-start"||i==="top-end"?p-r-a.height:n.bottom+r,m=i==="bottom-end"||i==="top-end"?n.right-a.width:n.left,D=d?.()??null;if(D!=null){let T=Math.max(n.left,n.right-a.width);m=Math.min(Math.max(n.left+D,n.left),T)}o.style.top=`${w}px`,o.style.left=`${m}px`},u=()=>{c&&(c=!1,f&&(f(),f=null),o.remove())},x=()=>{if(c)return;c=!0,E!=null&&(o.style.zIndex=String(E)),P.appendChild(o),v();let n=(e.ownerDocument??document).defaultView??window,a=e.ownerDocument??document,s=()=>{if(!e.isConnected){u(),y?.("anchor-removed");return}v()},p=g=>{let m=typeof g.composedPath=="function"?g.composedPath():[];m.includes(o)||m.includes(e)||(u(),y?.("outside"))},w=n.setTimeout(()=>{a.addEventListener("pointerdown",p,!0)},0);n.addEventListener("scroll",s,!0),n.addEventListener("resize",s),f=()=>{n.clearTimeout(w),a.removeEventListener("pointerdown",p,!0),n.removeEventListener("scroll",s,!0),n.removeEventListener("resize",s)},L?.()};return{get isOpen(){return c},open:x,close:u,toggle:()=>c?u():x(),reposition:v,destroy:u}}function H(t){return(typeof t.composedPath=="function"?t.composedPath():[]).some(o=>o instanceof HTMLElement&&(o.tagName==="INPUT"||o.tagName==="TEXTAREA"||o.isContentEditable))}export{M as createPopover,R as getStyleRoot,O as injectStyles,H as isEditableEventTarget};
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
"use strict";var $=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var J=Object.getOwnPropertyNames;var Q=Object.prototype.hasOwnProperty;var Z=(o,e,t)=>e in o?$(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var tt=(o,e)=>{for(var t in e)$(o,t,{get:e[t],enumerable:!0})},et=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of J(e))!Q.call(o,r)&&r!==t&&$(o,r,{get:()=>e[r],enumerable:!(n=Y(e,r))||n.enumerable});return o};var nt=o=>et($({},"__esModule",{value:!0}),o);var w=(o,e,t)=>Z(o,typeof e!="symbol"?e+"":e,t);var At={};tt(At,{collectSmartDomContext:()=>K,createSmartDomReaderContextProvider:()=>vt,smartDomResultToEnriched:()=>N});module.exports=nt(At);var D=Object.defineProperty,rt=Object.getOwnPropertyDescriptor,ot=Object.getOwnPropertyNames,F=Object.prototype.hasOwnProperty,C=(o,e)=>()=>(o&&(e=o(o=0)),e),st=(o,e)=>{let t={};for(var n in o)D(t,n,{get:o[n],enumerable:!0});return e||D(t,Symbol.toStringTag,{value:"Module"}),t},at=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(var r=ot(e),s=0,a=r.length,i;s<a;s++)i=r[s],!F.call(o,i)&&i!==t&&D(o,i,{get:(c=>e[c]).bind(null,i),enumerable:!(n=rt(e,i))||n.enumerable});return o},it=o=>F.call(o,"module.exports")?o["module.exports"]:at(D({},"__esModule",{value:!0}),o),ct=void 0,T,V=C((()=>{T=class S{static findMainContent(e){let t=e.querySelector('main, [role="main"]');return t||(e.body?S.detectMainContent(e.body):e.documentElement)}static detectMainContent(e){let t=[];if(S.collectCandidates(e,t,15),t.length===0)return e;t.sort((r,s)=>S.calculateContentScore(s)-S.calculateContentScore(r));let n=t[0];for(let r=1;r<t.length;r++){let s=t[r];!t.some((a,i)=>i!==r&&a.contains(s))&&S.calculateContentScore(s)>S.calculateContentScore(n)&&(n=s)}return n}static collectCandidates(e,t,n){S.calculateContentScore(e)>=n&&t.push(e),Array.from(e.children).forEach(r=>{S.collectCandidates(r,t,n)})}static calculateContentScore(e){let t=0,n=["article","content","main-container","main","main-content","post","entry"],r=["content","main","article","post","entry"];n.forEach(u=>{e.classList.contains(u)&&(t+=10)}),r.forEach(u=>{e.id?.toLowerCase().includes(u)&&(t+=10)});let s=e.tagName.toLowerCase();["article","main","section"].includes(s)&&(t+=8);let a=e.getElementsByTagName("p").length;t+=Math.min(a*2,10);let i=e.querySelectorAll("h1, h2, h3").length;t+=Math.min(i*3,9);let c=e.textContent?.trim().length||0;c>300&&(t+=Math.min(Math.floor(c/300)*2,10));let l=S.calculateLinkDensity(e);l<.3?t+=5:l>.5&&(t-=5),(e.hasAttribute("data-main")||e.hasAttribute("data-content")||e.hasAttribute("itemprop"))&&(t+=8);let d=e.getAttribute("role");return(d==="main"||d==="article")&&(t+=10),e.matches("aside, nav, header, footer, .sidebar, .navigation, .menu, .ad, .advertisement")&&(t-=10),e.getElementsByTagName("form").length>2&&(t-=5),Math.max(0,t)}static calculateLinkDensity(e){let t=e.getElementsByTagName("a"),n=0;for(let s of Array.from(t))n+=s.textContent?.length||0;let r=e.textContent?.length||1;return n/r}static isNavigation(e){if(e.tagName.toLowerCase()==="nav"||e.getAttribute("role")==="navigation")return!0;let t=[/nav/i,/menu/i,/sidebar/i,/toolbar/i],n=`${e.className} ${e.id}`.toLowerCase();return t.some(r=>r.test(n))}static isSupplementary(e){if(e.tagName.toLowerCase()==="aside"||e.getAttribute("role")==="complementary")return!0;let t=[/sidebar/i,/widget/i,/related/i,/advertisement/i,/social/i],n=`${e.className} ${e.id}`.toLowerCase();return t.some(r=>r.test(n))}static detectLandmarks(e){let t={navigation:[],main:[],complementary:[],contentinfo:[],banner:[],search:[],form:[],region:[]};for(let[n,r]of Object.entries({navigation:'nav, [role="navigation"]',main:'main, [role="main"]',complementary:'aside, [role="complementary"]',contentinfo:'footer, [role="contentinfo"]',banner:'header, [role="banner"]',search:'[role="search"]',form:'form[aria-label], form[aria-labelledby], [role="form"]',region:'section[aria-label], section[aria-labelledby], [role="region"]'})){let s=e.querySelectorAll(r);t[n]=Array.from(s)}return t}}})),b,I=C((()=>{b=class x{static generateSelectors(e){let t=e.ownerDocument||document,n=[];e.id&&x.isUniqueId(e.id,t)&&n.push({type:"id",value:`#${CSS.escape(e.id)}`,score:100});let r=x.getDataTestId(e);if(r){let h=`[data-testid="${CSS.escape(r)}"]`;n.push({type:"data-testid",value:h,score:90+(x.isUniqueSelectorSafe(h,t)?5:0)})}let s=e.getAttribute("role"),a=e.getAttribute("aria-label");if(s&&a){let h=`[role="${CSS.escape(s)}"][aria-label="${CSS.escape(a)}"]`;n.push({type:"role-aria",value:h,score:85+(x.isUniqueSelectorSafe(h,t)?5:0)})}let i=e.getAttribute("name");if(i){let h=`[name="${CSS.escape(i)}"]`;n.push({type:"name",value:h,score:78+(x.isUniqueSelectorSafe(h,t)?5:0)})}let c=x.generateCSSSelector(e,t),l=(c.match(/:nth-child\(/g)||[]).length*10,d=c.includes(".")?8:0,u=Math.max(0,70+d-l);n.push({type:"class-path",value:c,score:u});let f=x.generateXPath(e,t);n.push({type:"xpath",value:f,score:40});let m=x.generateTextBasedSelector(e);m&&n.push({type:"text",value:m,score:30}),n.sort((h,L)=>L.score-h.score);let y={css:n.find(h=>h.type!=="xpath"&&h.type!=="text")?.value||c,xpath:f,candidates:n};return m&&(y.textBased=m),r&&(y.dataTestId=r),a&&(y.ariaLabel=a),y}static generateCSSSelector(e,t){if(e.id&&x.isUniqueId(e.id,t))return`#${CSS.escape(e.id)}`;let n=x.getDataTestId(e);if(n)return`[data-testid="${CSS.escape(n)}"]`;let r=[],s=e;for(;s&&s.nodeType===Node.ELEMENT_NODE;){let a=s.nodeName.toLowerCase();if(s.id&&x.isUniqueId(s.id,t)){a=`#${CSS.escape(s.id)}`,r.unshift(a);break}let i=x.getMeaningfulClasses(s);i.length>0&&(a+=`.${i.map(l=>CSS.escape(l)).join(".")}`);let c=s.parentElement?.children;if(c&&c.length>1){let l=Array.from(c).indexOf(s);(l>0||!x.isUniqueSelector(a,s.parentElement))&&(a+=`:nth-child(${l+1})`)}r.unshift(a),s=s.parentElement}return x.optimizePath(r,e,t)}static generateXPath(e,t){if(e.id&&x.isUniqueId(e.id,t))return`//*[@id="${e.id}"]`;let n=[],r=e;for(;r&&r.nodeType===Node.ELEMENT_NODE;){let s=r.nodeName.toLowerCase();if(r.id&&x.isUniqueId(r.id,t)){n.unshift(`//*[@id="${r.id}"]`);break}let a=s,i=r.parentElement?.children;if(i){let c=Array.from(i).filter(l=>l.nodeName.toLowerCase()===s);if(c.length>1){let l=c.indexOf(r)+1;a+=`[${l}]`}}n.unshift(a),r=r.parentElement}return`//${n.join("/")}`}static generateTextBasedSelector(e){let t=e.textContent?.trim();if(!t||t.length>50)return;let n=e.nodeName.toLowerCase();if(["button","a","label"].includes(n))return`${n}:contains("${t.replace(/['"\\]/g,"\\$&")}")`}static getDataTestId(e){return e.getAttribute("data-testid")||e.getAttribute("data-test-id")||e.getAttribute("data-test")||e.getAttribute("data-cy")||void 0}static isUniqueId(e,t){return t.querySelectorAll(`#${CSS.escape(e)}`).length===1}static isUniqueSelector(e,t){try{return t.querySelectorAll(e).length===1}catch{return!1}}static isUniqueSelectorSafe(e,t){try{return t.querySelectorAll(e).length===1}catch{return!1}}static getMeaningfulClasses(e){let t=Array.from(e.classList),n=[/^(p|m|w|h|text|bg|border|flex|grid|col|row)-/,/^(xs|sm|md|lg|xl|2xl):/,/^(hover|focus|active|disabled|checked):/,/^js-/,/^is-/,/^has-/];return t.filter(r=>r.length<3?!1:!n.some(s=>s.test(r))).slice(0,2)}static optimizePath(e,t,n){for(let r=0;r<e.length-1;r++){let s=e.slice(r).join(" > ");try{let a=n.querySelectorAll(s);if(a.length===1&&a[0]===t)return s}catch{}}return e.join(" > ")}static getContextPath(e){let t=[],n=e,r=0,s=5;for(;n&&n!==e.ownerDocument?.body&&r<s;){let a=n.nodeName.toLowerCase(),i=a;if(n.id)i=`${a}#${n.id}`;else if(n.className&&typeof n.className=="string"){let l=n.className.split(" ")[0];l&&(i=`${a}.${l}`)}let c=n.getAttribute("role");c&&(i+=`[role="${c}"]`),t.unshift(i),n=n.parentElement,r++}return t}}})),g,U=C((()=>{var o;I(),g=(o=class{static isVisible(t,n){let r=t.getBoundingClientRect(),s=n||t.ownerDocument?.defaultView?.getComputedStyle(t);return s?r.width>0&&r.height>0&&s.display!=="none"&&s.visibility!=="hidden"&&s.opacity!=="0"&&t.offsetParent!==null:!1}static isInViewport(t,n){let r=t.getBoundingClientRect(),s=n||{width:t.ownerDocument?.defaultView?.innerWidth||0,height:t.ownerDocument?.defaultView?.innerHeight||0};return r.top<s.height&&r.bottom>0&&r.left<s.width&&r.right>0}static passesFilter(t,n){if(!n)return!0;let r=t;if(n.excludeSelectors?.length){for(let a of n.excludeSelectors)if(t.matches(a))return!1}if(n.includeSelectors?.length){let a=!1;for(let i of n.includeSelectors)if(t.matches(i)){a=!0;break}if(!a)return!1}if(n.tags?.length&&!n.tags.includes(t.tagName.toLowerCase()))return!1;let s=r.textContent?.toLowerCase()||"";if(n.textContains?.length){let a=!1;for(let i of n.textContains)if(s.includes(i.toLowerCase())){a=!0;break}if(!a)return!1}if(n.textMatches?.length){let a=!1;for(let i of n.textMatches)if(i.test(s)){a=!0;break}if(!a)return!1}if(n.hasAttributes?.length){for(let a of n.hasAttributes)if(!t.hasAttribute(a))return!1}if(n.attributeValues)for(let[a,i]of Object.entries(n.attributeValues)){let c=t.getAttribute(a);if(!c)return!1;if(typeof i=="string"){if(c!==i)return!1}else if(i instanceof RegExp&&!i.test(c))return!1}if(n.withinSelectors?.length){let a=!1;for(let i of n.withinSelectors)if(t.closest(i)){a=!0;break}if(!a)return!1}if(n.interactionTypes?.length){let a=o.getInteractionInfo(t),i=!1;for(let c of n.interactionTypes)if(a[c]){i=!0;break}if(!i)return!1}if(n.nearText){let a=t.parentElement;if(!a||!a.textContent?.toLowerCase().includes(n.nearText.toLowerCase()))return!1}return!0}static extractElement(t,n,r=0){if(n.maxDepth&&r>n.maxDepth||!n.includeHidden&&!o.isVisible(t)||n.viewportOnly&&!o.isInViewport(t)||!o.passesFilter(t,n.filter))return null;let s=t,a={tag:t.tagName.toLowerCase(),text:o.getElementText(t,n),selector:b.generateSelectors(t),attributes:o.getRelevantAttributes(t,n),context:o.getElementContext(t),interaction:o.getInteractionInfo(t)};if(n.mode==="full"&&o.isSemanticContainer(t)){let i=[];if(n.includeShadowDOM&&s.shadowRoot){let l=o.extractChildren(s.shadowRoot,n,r+1);i.push(...l)}let c=o.extractChildren(t,n,r+1);i.push(...c),i.length>0&&(a.children=i)}return a}static extractChildren(t,n,r){let s=[],a=t.querySelectorAll("*");for(let i of Array.from(a)){if(o.hasExtractedAncestor(i,a))continue;let c=o.extractElement(i,n,r);c&&s.push(c)}return s}static hasExtractedAncestor(t,n){let r=t.parentElement;for(;r;){if(Array.from(n).includes(r))return!0;r=r.parentElement}return!1}static getRelevantAttributes(t,n){let r=["id","class","name","type","value","placeholder","href","src","alt","title","action","method","aria-label","aria-describedby","aria-controls","role","disabled","readonly","required","checked","min","max","pattern","step","autocomplete","data-testid","data-test","data-cy"],s={},a=n.attributeTruncateLength??100,i=n.dataAttributeTruncateLength??50;for(let c of r){let l=t.getAttribute(c);l&&(s[c]=l.length>a?`${l.substring(0,a)}...`:l)}for(let c of t.attributes)c.name.startsWith("data-")&&!r.includes(c.name)&&(s[c.name]=c.value.length>i?`${c.value.substring(0,i)}...`:c.value);return s}static getElementContext(t){let n={parentChain:b.getContextPath(t)},r=t.closest("form");r&&(n.nearestForm=b.generateSelectors(r).css);let s=t.closest('section, [role="region"]');s&&(n.nearestSection=b.generateSelectors(s).css);let a=t.closest('main, [role="main"]');a&&(n.nearestMain=b.generateSelectors(a).css);let i=t.closest('nav, [role="navigation"]');return i&&(n.nearestNav=b.generateSelectors(i).css),n}static getInteractionInfo(t){let n=t,r={};(n.onclick||t.getAttribute("onclick")||t.matches('button, a[href], [role="button"], [tabindex]:not([tabindex="-1"])'))&&(r.click=!0),(n.onchange||t.getAttribute("onchange")||t.matches("input, select, textarea"))&&(r.change=!0),(n.onsubmit||t.getAttribute("onsubmit")||t.matches("form"))&&(r.submit=!0),t.matches('a[href], button[type="submit"]')&&(r.nav=!0),(n.hasAttribute("disabled")||n.getAttribute("aria-disabled")==="true")&&(r.disabled=!0),o.isVisible(t)||(r.hidden=!0);let s=t.getAttribute("role");if(s&&(r.role=s),t.matches("input, textarea, select, button")){let a=t.form||t.closest("form");a&&(r.form=b.generateSelectors(a).css)}return r}static getElementText(t,n){if(t.matches("input, textarea")){let a=t;return a.value||a.placeholder||""}if(t.matches("img"))return t.alt||"";let r=t.textContent?.trim()||"",s=n?.textTruncateLength;return s&&r.length>s?`${r.substring(0,s)}...`:r}static isSemanticContainer(t){return t.matches('article, section, nav, aside, main, header, footer, form, table, ul, ol, dl, figure, details, dialog, [role="region"], [role="navigation"], [role="main"], [role="complementary"]')}static getInteractiveElements(t,n){let r=[],s=o.INTERACTIVE_SELECTORS.join(", "),a=t.querySelectorAll(s);for(let i of Array.from(a)){let c=o.extractElement(i,n);c&&r.push(c)}if(n.customSelectors)for(let i of n.customSelectors)try{let c=t.querySelectorAll(i);for(let l of Array.from(c)){let d=o.extractElement(l,n);d&&r.push(d)}}catch{console.warn(`Invalid custom selector: ${i}`)}return r}static getSemanticElements(t,n){let r=[],s=o.SEMANTIC_SELECTORS.join(", "),a=t.querySelectorAll(s);for(let i of Array.from(a)){let c=o.extractElement(i,n);c&&r.push(c)}return r}},w(o,"INTERACTIVE_SELECTORS",["button","a[href]",'input:not([type="hidden"])',"textarea","select",'[role="button"]',"[onclick]",'[contenteditable="true"]',"summary",'[tabindex]:not([tabindex="-1"])']),w(o,"SEMANTIC_SELECTORS",["h1","h2","h3","h4","h5","h6","article","section","nav","aside","main","header","footer","form","table","ul","ol","img[alt]","figure","video","audio",'[role="navigation"]','[role="main"]','[role="complementary"]','[role="contentinfo"]']),o)}));function A(o,e){let t=(o??"").trim();if(!e||t.length<=e)return t;let n=["login","log in","sign in","sign up","submit","search","filter","add to cart","next","continue"],r=t.toLowerCase(),s=n.map(l=>({k:l,i:r.indexOf(l)})).find(l=>l.i>-1),a=Math.max(0,Math.floor(e*.66));if(s&&s.i>a){let l=Math.max(12,e-a-5),d=Math.max(0,s.i-Math.floor(l/2)),u=Math.min(t.length,d+l);return`${t.slice(0,a).trimEnd()} \u2026 ${t.slice(d,u).trim()}\u2026`}let i=t.slice(0,e),c=i.lastIndexOf(" ");return`${c>32?i.slice(0,c):i}\u2026`}function lt(o){return o.selector?.css||""}function ut(o){let e=5381;for(let t=0;t<o.length;t++)e=e*33^o.charCodeAt(t);return`sec-${(e>>>0).toString(36)}`}function W(o){switch(o){case"header":return"\u{1F9ED}";case"navigation":return"\u{1F4D1}";case"main":return"\u{1F4C4}";case"sections":return"\u{1F5C2}\uFE0F";case"sidebar":return"\u{1F4DA}";case"footer":return"\u{1F53B}";case"modals":return"\u{1F4AC}";default:return"\u{1F539}"}}function M(o,e){let t=A(o.text||o.attributes?.ariaLabel,e?.maxTextLength??80),n=lt(o),r=o.tag.toLowerCase(),s=o.interaction?.submit?"submit":o.interaction?.click?"click":o.interaction?.change?"change":void 0,a=s?` (${s})`:"";return`- ${r.toUpperCase()}: ${t||"(no text)"} \u2192 \`${n}\`${a}`}function dt(o){let e=[];e.push(...o.buttons.map(i=>i.selector?.css||"")),e.push(...o.links.map(i=>i.selector?.css||"")),e.push(...o.inputs.map(i=>i.selector?.css||"")),e.push(...o.clickable.map(i=>i.selector?.css||""));let t=e.length||1,n=e.filter(i=>i.startsWith("#")).length,r=e.filter(i=>/\[data-testid=/.test(i)).length,s=e.filter(i=>/:nth-child\(/.test(i)).length,a=n+r;return`Selector quality: ${Math.round(a/t*100)}% stable (ID/data-testid), ${Math.round(s/t*100)}% structural (:nth-child)`}function ft(o,e){let t=[],n=r=>typeof e?.maxElements=="number"?r.slice(0,e.maxElements):r;if(o.buttons.length){t.push("Buttons:");for(let r of n(o.buttons))t.push(M(r,e))}if(o.links.length){t.push("Links:");for(let r of n(o.links))t.push(M(r,e))}if(o.inputs.length){t.push("Inputs:");for(let r of n(o.inputs))t.push(M(r,e))}if(o.clickable.length){t.push("Other Clickable:");for(let r of n(o.clickable))t.push(M(r,e))}if(o.forms.length){t.push("Forms:");for(let r of n(o.forms))t.push(`- FORM: action=${r.action??"-"} method=${r.method??"-"} \u2192 \`${r.selector}\``)}return t.join(`
|
|
2
|
-
`)}function
|
|
1
|
+
"use strict";var w=Object.defineProperty;var J=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var tt=Object.prototype.hasOwnProperty;var et=(o,e,t)=>e in o?w(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var nt=(o,e)=>{for(var t in e)w(o,t,{get:e[t],enumerable:!0})},rt=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Z(e))!tt.call(o,r)&&r!==t&&w(o,r,{get:()=>e[r],enumerable:!(n=J(e,r))||n.enumerable});return o};var ot=o=>rt(w({},"__esModule",{value:!0}),o);var M=(o,e,t)=>et(o,typeof e!="symbol"?e+"":e,t);var Ot={};nt(Ot,{collectSmartDomContext:()=>P,createSmartDomMentionSource:()=>Rt,createSmartDomReaderContextProvider:()=>wt,smartDomResultToEnriched:()=>q});module.exports=ot(Ot);var R=Object.defineProperty,it=Object.getOwnPropertyDescriptor,st=Object.getOwnPropertyNames,F=Object.prototype.hasOwnProperty,C=(o,e)=>()=>(o&&(e=o(o=0)),e),at=(o,e)=>{let t={};for(var n in o)R(t,n,{get:o[n],enumerable:!0});return e||R(t,Symbol.toStringTag,{value:"Module"}),t},ct=(o,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(var r=st(e),i=0,s=r.length,a;i<s;i++)a=r[i],!F.call(o,a)&&a!==t&&R(o,a,{get:(c=>e[c]).bind(null,a),enumerable:!(n=it(e,a))||n.enumerable});return o},lt=o=>F.call(o,"module.exports")?o["module.exports"]:ct(R({},"__esModule",{value:!0}),o),ut=void 0,T,U=C((()=>{T=class y{static findMainContent(e){let t=e.querySelector('main, [role="main"]');return t||(e.body?y.detectMainContent(e.body):e.documentElement)}static detectMainContent(e){let t=[];if(y.collectCandidates(e,t,15),t.length===0)return e;t.sort((r,i)=>y.calculateContentScore(i)-y.calculateContentScore(r));let n=t[0];for(let r=1;r<t.length;r++){let i=t[r];!t.some((s,a)=>a!==r&&s.contains(i))&&y.calculateContentScore(i)>y.calculateContentScore(n)&&(n=i)}return n}static collectCandidates(e,t,n){y.calculateContentScore(e)>=n&&t.push(e),Array.from(e.children).forEach(r=>{y.collectCandidates(r,t,n)})}static calculateContentScore(e){let t=0,n=["article","content","main-container","main","main-content","post","entry"],r=["content","main","article","post","entry"];n.forEach(u=>{e.classList.contains(u)&&(t+=10)}),r.forEach(u=>{e.id?.toLowerCase().includes(u)&&(t+=10)});let i=e.tagName.toLowerCase();["article","main","section"].includes(i)&&(t+=8);let s=e.getElementsByTagName("p").length;t+=Math.min(s*2,10);let a=e.querySelectorAll("h1, h2, h3").length;t+=Math.min(a*3,9);let c=e.textContent?.trim().length||0;c>300&&(t+=Math.min(Math.floor(c/300)*2,10));let l=y.calculateLinkDensity(e);l<.3?t+=5:l>.5&&(t-=5),(e.hasAttribute("data-main")||e.hasAttribute("data-content")||e.hasAttribute("itemprop"))&&(t+=8);let d=e.getAttribute("role");return(d==="main"||d==="article")&&(t+=10),e.matches("aside, nav, header, footer, .sidebar, .navigation, .menu, .ad, .advertisement")&&(t-=10),e.getElementsByTagName("form").length>2&&(t-=5),Math.max(0,t)}static calculateLinkDensity(e){let t=e.getElementsByTagName("a"),n=0;for(let i of Array.from(t))n+=i.textContent?.length||0;let r=e.textContent?.length||1;return n/r}static isNavigation(e){if(e.tagName.toLowerCase()==="nav"||e.getAttribute("role")==="navigation")return!0;let t=[/nav/i,/menu/i,/sidebar/i,/toolbar/i],n=`${e.className} ${e.id}`.toLowerCase();return t.some(r=>r.test(n))}static isSupplementary(e){if(e.tagName.toLowerCase()==="aside"||e.getAttribute("role")==="complementary")return!0;let t=[/sidebar/i,/widget/i,/related/i,/advertisement/i,/social/i],n=`${e.className} ${e.id}`.toLowerCase();return t.some(r=>r.test(n))}static detectLandmarks(e){let t={navigation:[],main:[],complementary:[],contentinfo:[],banner:[],search:[],form:[],region:[]};for(let[n,r]of Object.entries({navigation:'nav, [role="navigation"]',main:'main, [role="main"]',complementary:'aside, [role="complementary"]',contentinfo:'footer, [role="contentinfo"]',banner:'header, [role="banner"]',search:'[role="search"]',form:'form[aria-label], form[aria-labelledby], [role="form"]',region:'section[aria-label], section[aria-labelledby], [role="region"]'})){let i=e.querySelectorAll(r);t[n]=Array.from(i)}return t}}})),b,N=C((()=>{b=class x{static generateSelectors(e){let t=e.ownerDocument||document,n=[];e.id&&x.isUniqueId(e.id,t)&&n.push({type:"id",value:`#${CSS.escape(e.id)}`,score:100});let r=x.getDataTestId(e);if(r){let h=`[data-testid="${CSS.escape(r)}"]`;n.push({type:"data-testid",value:h,score:90+(x.isUniqueSelectorSafe(h,t)?5:0)})}let i=e.getAttribute("role"),s=e.getAttribute("aria-label");if(i&&s){let h=`[role="${CSS.escape(i)}"][aria-label="${CSS.escape(s)}"]`;n.push({type:"role-aria",value:h,score:85+(x.isUniqueSelectorSafe(h,t)?5:0)})}let a=e.getAttribute("name");if(a){let h=`[name="${CSS.escape(a)}"]`;n.push({type:"name",value:h,score:78+(x.isUniqueSelectorSafe(h,t)?5:0)})}let c=x.generateCSSSelector(e,t),l=(c.match(/:nth-child\(/g)||[]).length*10,d=c.includes(".")?8:0,u=Math.max(0,70+d-l);n.push({type:"class-path",value:c,score:u});let m=x.generateXPath(e,t);n.push({type:"xpath",value:m,score:40});let f=x.generateTextBasedSelector(e);f&&n.push({type:"text",value:f,score:30}),n.sort((h,L)=>L.score-h.score);let S={css:n.find(h=>h.type!=="xpath"&&h.type!=="text")?.value||c,xpath:m,candidates:n};return f&&(S.textBased=f),r&&(S.dataTestId=r),s&&(S.ariaLabel=s),S}static generateCSSSelector(e,t){if(e.id&&x.isUniqueId(e.id,t))return`#${CSS.escape(e.id)}`;let n=x.getDataTestId(e);if(n)return`[data-testid="${CSS.escape(n)}"]`;let r=[],i=e;for(;i&&i.nodeType===Node.ELEMENT_NODE;){let s=i.nodeName.toLowerCase();if(i.id&&x.isUniqueId(i.id,t)){s=`#${CSS.escape(i.id)}`,r.unshift(s);break}let a=x.getMeaningfulClasses(i);a.length>0&&(s+=`.${a.map(l=>CSS.escape(l)).join(".")}`);let c=i.parentElement?.children;if(c&&c.length>1){let l=Array.from(c).indexOf(i);(l>0||!x.isUniqueSelector(s,i.parentElement))&&(s+=`:nth-child(${l+1})`)}r.unshift(s),i=i.parentElement}return x.optimizePath(r,e,t)}static generateXPath(e,t){if(e.id&&x.isUniqueId(e.id,t))return`//*[@id="${e.id}"]`;let n=[],r=e;for(;r&&r.nodeType===Node.ELEMENT_NODE;){let i=r.nodeName.toLowerCase();if(r.id&&x.isUniqueId(r.id,t)){n.unshift(`//*[@id="${r.id}"]`);break}let s=i,a=r.parentElement?.children;if(a){let c=Array.from(a).filter(l=>l.nodeName.toLowerCase()===i);if(c.length>1){let l=c.indexOf(r)+1;s+=`[${l}]`}}n.unshift(s),r=r.parentElement}return`//${n.join("/")}`}static generateTextBasedSelector(e){let t=e.textContent?.trim();if(!t||t.length>50)return;let n=e.nodeName.toLowerCase();if(["button","a","label"].includes(n))return`${n}:contains("${t.replace(/['"\\]/g,"\\$&")}")`}static getDataTestId(e){return e.getAttribute("data-testid")||e.getAttribute("data-test-id")||e.getAttribute("data-test")||e.getAttribute("data-cy")||void 0}static isUniqueId(e,t){return t.querySelectorAll(`#${CSS.escape(e)}`).length===1}static isUniqueSelector(e,t){try{return t.querySelectorAll(e).length===1}catch{return!1}}static isUniqueSelectorSafe(e,t){try{return t.querySelectorAll(e).length===1}catch{return!1}}static getMeaningfulClasses(e){let t=Array.from(e.classList),n=[/^(p|m|w|h|text|bg|border|flex|grid|col|row)-/,/^(xs|sm|md|lg|xl|2xl):/,/^(hover|focus|active|disabled|checked):/,/^js-/,/^is-/,/^has-/];return t.filter(r=>r.length<3?!1:!n.some(i=>i.test(r))).slice(0,2)}static optimizePath(e,t,n){for(let r=0;r<e.length-1;r++){let i=e.slice(r).join(" > ");try{let s=n.querySelectorAll(i);if(s.length===1&&s[0]===t)return i}catch{}}return e.join(" > ")}static getContextPath(e){let t=[],n=e,r=0,i=5;for(;n&&n!==e.ownerDocument?.body&&r<i;){let s=n.nodeName.toLowerCase(),a=s;if(n.id)a=`${s}#${n.id}`;else if(n.className&&typeof n.className=="string"){let l=n.className.split(" ")[0];l&&(a=`${s}.${l}`)}let c=n.getAttribute("role");c&&(a+=`[role="${c}"]`),t.unshift(a),n=n.parentElement,r++}return t}}})),g,V=C((()=>{var o;N(),g=(o=class{static isVisible(t,n){let r=t.getBoundingClientRect(),i=n||t.ownerDocument?.defaultView?.getComputedStyle(t);return i?r.width>0&&r.height>0&&i.display!=="none"&&i.visibility!=="hidden"&&i.opacity!=="0"&&t.offsetParent!==null:!1}static isInViewport(t,n){let r=t.getBoundingClientRect(),i=n||{width:t.ownerDocument?.defaultView?.innerWidth||0,height:t.ownerDocument?.defaultView?.innerHeight||0};return r.top<i.height&&r.bottom>0&&r.left<i.width&&r.right>0}static passesFilter(t,n){if(!n)return!0;let r=t;if(n.excludeSelectors?.length){for(let s of n.excludeSelectors)if(t.matches(s))return!1}if(n.includeSelectors?.length){let s=!1;for(let a of n.includeSelectors)if(t.matches(a)){s=!0;break}if(!s)return!1}if(n.tags?.length&&!n.tags.includes(t.tagName.toLowerCase()))return!1;let i=r.textContent?.toLowerCase()||"";if(n.textContains?.length){let s=!1;for(let a of n.textContains)if(i.includes(a.toLowerCase())){s=!0;break}if(!s)return!1}if(n.textMatches?.length){let s=!1;for(let a of n.textMatches)if(a.test(i)){s=!0;break}if(!s)return!1}if(n.hasAttributes?.length){for(let s of n.hasAttributes)if(!t.hasAttribute(s))return!1}if(n.attributeValues)for(let[s,a]of Object.entries(n.attributeValues)){let c=t.getAttribute(s);if(!c)return!1;if(typeof a=="string"){if(c!==a)return!1}else if(a instanceof RegExp&&!a.test(c))return!1}if(n.withinSelectors?.length){let s=!1;for(let a of n.withinSelectors)if(t.closest(a)){s=!0;break}if(!s)return!1}if(n.interactionTypes?.length){let s=o.getInteractionInfo(t),a=!1;for(let c of n.interactionTypes)if(s[c]){a=!0;break}if(!a)return!1}if(n.nearText){let s=t.parentElement;if(!s||!s.textContent?.toLowerCase().includes(n.nearText.toLowerCase()))return!1}return!0}static extractElement(t,n,r=0){if(n.maxDepth&&r>n.maxDepth||!n.includeHidden&&!o.isVisible(t)||n.viewportOnly&&!o.isInViewport(t)||!o.passesFilter(t,n.filter))return null;let i=t,s={tag:t.tagName.toLowerCase(),text:o.getElementText(t,n),selector:b.generateSelectors(t),attributes:o.getRelevantAttributes(t,n),context:o.getElementContext(t),interaction:o.getInteractionInfo(t)};if(n.mode==="full"&&o.isSemanticContainer(t)){let a=[];if(n.includeShadowDOM&&i.shadowRoot){let l=o.extractChildren(i.shadowRoot,n,r+1);a.push(...l)}let c=o.extractChildren(t,n,r+1);a.push(...c),a.length>0&&(s.children=a)}return s}static extractChildren(t,n,r){let i=[],s=t.querySelectorAll("*");for(let a of Array.from(s)){if(o.hasExtractedAncestor(a,s))continue;let c=o.extractElement(a,n,r);c&&i.push(c)}return i}static hasExtractedAncestor(t,n){let r=t.parentElement;for(;r;){if(Array.from(n).includes(r))return!0;r=r.parentElement}return!1}static getRelevantAttributes(t,n){let r=["id","class","name","type","value","placeholder","href","src","alt","title","action","method","aria-label","aria-describedby","aria-controls","role","disabled","readonly","required","checked","min","max","pattern","step","autocomplete","data-testid","data-test","data-cy"],i={},s=n.attributeTruncateLength??100,a=n.dataAttributeTruncateLength??50;for(let c of r){let l=t.getAttribute(c);l&&(i[c]=l.length>s?`${l.substring(0,s)}...`:l)}for(let c of t.attributes)c.name.startsWith("data-")&&!r.includes(c.name)&&(i[c.name]=c.value.length>a?`${c.value.substring(0,a)}...`:c.value);return i}static getElementContext(t){let n={parentChain:b.getContextPath(t)},r=t.closest("form");r&&(n.nearestForm=b.generateSelectors(r).css);let i=t.closest('section, [role="region"]');i&&(n.nearestSection=b.generateSelectors(i).css);let s=t.closest('main, [role="main"]');s&&(n.nearestMain=b.generateSelectors(s).css);let a=t.closest('nav, [role="navigation"]');return a&&(n.nearestNav=b.generateSelectors(a).css),n}static getInteractionInfo(t){let n=t,r={};(n.onclick||t.getAttribute("onclick")||t.matches('button, a[href], [role="button"], [tabindex]:not([tabindex="-1"])'))&&(r.click=!0),(n.onchange||t.getAttribute("onchange")||t.matches("input, select, textarea"))&&(r.change=!0),(n.onsubmit||t.getAttribute("onsubmit")||t.matches("form"))&&(r.submit=!0),t.matches('a[href], button[type="submit"]')&&(r.nav=!0),(n.hasAttribute("disabled")||n.getAttribute("aria-disabled")==="true")&&(r.disabled=!0),o.isVisible(t)||(r.hidden=!0);let i=t.getAttribute("role");if(i&&(r.role=i),t.matches("input, textarea, select, button")){let s=t.form||t.closest("form");s&&(r.form=b.generateSelectors(s).css)}return r}static getElementText(t,n){if(t.matches("input, textarea")){let s=t;return s.value||s.placeholder||""}if(t.matches("img"))return t.alt||"";let r=t.textContent?.trim()||"",i=n?.textTruncateLength;return i&&r.length>i?`${r.substring(0,i)}...`:r}static isSemanticContainer(t){return t.matches('article, section, nav, aside, main, header, footer, form, table, ul, ol, dl, figure, details, dialog, [role="region"], [role="navigation"], [role="main"], [role="complementary"]')}static getInteractiveElements(t,n){let r=[],i=o.INTERACTIVE_SELECTORS.join(", "),s=t.querySelectorAll(i);for(let a of Array.from(s)){let c=o.extractElement(a,n);c&&r.push(c)}if(n.customSelectors)for(let a of n.customSelectors)try{let c=t.querySelectorAll(a);for(let l of Array.from(c)){let d=o.extractElement(l,n);d&&r.push(d)}}catch{console.warn(`Invalid custom selector: ${a}`)}return r}static getSemanticElements(t,n){let r=[],i=o.SEMANTIC_SELECTORS.join(", "),s=t.querySelectorAll(i);for(let a of Array.from(s)){let c=o.extractElement(a,n);c&&r.push(c)}return r}},M(o,"INTERACTIVE_SELECTORS",["button","a[href]",'input:not([type="hidden"])',"textarea","select",'[role="button"]',"[onclick]",'[contenteditable="true"]',"summary",'[tabindex]:not([tabindex="-1"])']),M(o,"SEMANTIC_SELECTORS",["h1","h2","h3","h4","h5","h6","article","section","nav","aside","main","header","footer","form","table","ul","ol","img[alt]","figure","video","audio",'[role="navigation"]','[role="main"]','[role="complementary"]','[role="contentinfo"]']),o)}));function A(o,e){let t=(o??"").trim();if(!e||t.length<=e)return t;let n=["login","log in","sign in","sign up","submit","search","filter","add to cart","next","continue"],r=t.toLowerCase(),i=n.map(l=>({k:l,i:r.indexOf(l)})).find(l=>l.i>-1),s=Math.max(0,Math.floor(e*.66));if(i&&i.i>s){let l=Math.max(12,e-s-5),d=Math.max(0,i.i-Math.floor(l/2)),u=Math.min(t.length,d+l);return`${t.slice(0,s).trimEnd()} \u2026 ${t.slice(d,u).trim()}\u2026`}let a=t.slice(0,e),c=a.lastIndexOf(" ");return`${c>32?a.slice(0,c):a}\u2026`}function dt(o){return o.selector?.css||""}function mt(o){let e=5381;for(let t=0;t<o.length;t++)e=e*33^o.charCodeAt(t);return`sec-${(e>>>0).toString(36)}`}function B(o){switch(o){case"header":return"\u{1F9ED}";case"navigation":return"\u{1F4D1}";case"main":return"\u{1F4C4}";case"sections":return"\u{1F5C2}\uFE0F";case"sidebar":return"\u{1F4DA}";case"footer":return"\u{1F53B}";case"modals":return"\u{1F4AC}";default:return"\u{1F539}"}}function $(o,e){let t=A(o.text||o.attributes?.ariaLabel,e?.maxTextLength??80),n=dt(o),r=o.tag.toLowerCase(),i=o.interaction?.submit?"submit":o.interaction?.click?"click":o.interaction?.change?"change":void 0,s=i?` (${i})`:"";return`- ${r.toUpperCase()}: ${t||"(no text)"} \u2192 \`${n}\`${s}`}function ft(o){let e=[];e.push(...o.buttons.map(a=>a.selector?.css||"")),e.push(...o.links.map(a=>a.selector?.css||"")),e.push(...o.inputs.map(a=>a.selector?.css||"")),e.push(...o.clickable.map(a=>a.selector?.css||""));let t=e.length||1,n=e.filter(a=>a.startsWith("#")).length,r=e.filter(a=>/\[data-testid=/.test(a)).length,i=e.filter(a=>/:nth-child\(/.test(a)).length,s=n+r;return`Selector quality: ${Math.round(s/t*100)}% stable (ID/data-testid), ${Math.round(i/t*100)}% structural (:nth-child)`}function ht(o,e){let t=[],n=r=>typeof e?.maxElements=="number"?r.slice(0,e.maxElements):r;if(o.buttons.length){t.push("Buttons:");for(let r of n(o.buttons))t.push($(r,e))}if(o.links.length){t.push("Links:");for(let r of n(o.links))t.push($(r,e))}if(o.inputs.length){t.push("Inputs:");for(let r of n(o.inputs))t.push($(r,e))}if(o.clickable.length){t.push("Other Clickable:");for(let r of n(o.clickable))t.push($(r,e))}if(o.forms.length){t.push("Forms:");for(let r of n(o.forms))t.push(`- FORM: action=${r.action??"-"} method=${r.method??"-"} \u2192 \`${r.selector}\``)}return t.join(`
|
|
2
|
+
`)}function W(o){let e=B("region"),t=mt(`${o.selector}|${o.label??""}|${o.role??""}`),n=o.label?` ${o.label}`:"",r=[];o.buttonCount&&r.push(`${o.buttonCount} buttons`),o.linkCount&&r.push(`${o.linkCount} links`),o.inputCount&&r.push(`${o.inputCount} inputs`),o.textPreview&&r.push(`\u201C${A(o.textPreview,80)}\u201D`);let i=r.length?`: ${r.join(", ")}`:"";return`${e} ${n} \u2192 \`${o.selector}\` [${t}]${i}`}function D(o,e,t="section"){return`<page ${[e?.title?`title="${H(e?.title)}"`:null,e?.url?`url="${H(e?.url)}"`:null].filter(Boolean).join(" ")}>
|
|
3
3
|
<${t}><![CDATA[
|
|
4
4
|
${o}
|
|
5
5
|
]]></${t}>
|
|
6
|
-
</page>`}function H(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function j(o){return o.charAt(0).toUpperCase()+o.slice(1)}var
|
|
7
|
-
`),t,"outline")}static region(o,e={},t){let n=[];n.push("# Region Details"),(t?.title||t?.url)&&(n.push(`Title: ${t?.title??""}`.trim()),n.push(`URL: ${t?.url??""}`.trim())),n.push("");let r=o.interactive;if(o.page){let
|
|
8
|
-
`),t,"section")}static content(o,e={},t){let n=[];if(n.push("# Content"),n.push(`Selector: \`${o.selector}\``),n.push(""),o.text.headings?.length){n.push("Headings:");for(let r of o.text.headings)n.push(`- H${r.level}: ${A(r.text,e.maxTextLength??120)}`);n.push("")}if(o.text.paragraphs?.length){let r=typeof e.maxElements=="number"?e.maxElements:o.text.paragraphs.length;n.push("Paragraphs:");for(let
|
|
9
|
-
`),t,"content")}}}));function ht(){if(typeof window<"u"){let o=window,e=o.SmartDOMReader;if(typeof e=="function")return e;let t=o.SmartDOMReaderNamespace;if(t&&typeof t.SmartDOMReader=="function")return t.SmartDOMReader}try{if(typeof ct=="function"){let o=(_(),it(xt));if(o&&typeof o.SmartDOMReader=="function")return o.SmartDOMReader;if(o&&typeof o.default=="function")return o.default}}catch{}}var z,gt=C((()=>{V(),I(),U(),z=class p{static extractStructure(e){let t={},n=e.querySelector('header, [role="banner"], .header, #header');n&&(t.header=p.analyzeRegion(n));let r=e.querySelectorAll('nav, [role="navigation"], .nav, .navigation');if(r.length>0&&(t.navigation=Array.from(r).map(u=>p.analyzeRegion(u))),e instanceof Document){let u=T.findMainContent(e);if(u){t.main=p.analyzeRegion(u);let f=u.querySelectorAll('section, article, [role="region"]');f.length>0&&(t.sections=Array.from(f).filter(m=>!m.closest("nav, header, footer")).map(m=>p.analyzeRegion(m)))}}else{t.main=p.analyzeRegion(e);let u=e.querySelectorAll('section, article, [role="region"]');u.length>0&&(t.sections=Array.from(u).filter(f=>!f.closest("nav, header, footer")).map(f=>p.analyzeRegion(f)))}let s=e.querySelectorAll('aside, [role="complementary"], .sidebar, #sidebar');s.length>0&&(t.sidebar=Array.from(s).map(u=>p.analyzeRegion(u)));let a=e.querySelector('footer, [role="contentinfo"], .footer, #footer');a&&(t.footer=p.analyzeRegion(a));let i=e.querySelectorAll('[role="dialog"], .modal, .popup, .overlay'),c=Array.from(i).filter(u=>g.isVisible(u));c.length>0&&(t.modals=c.map(u=>p.analyzeRegion(u)));let l=p.extractFormOverview(e),d=p.calculateSummary(e,t,l);return{regions:t,forms:l,summary:d,suggestions:p.generateSuggestions(t,d)}}static extractRegion(e,t,n={},r){let s=t.querySelector(e);if(!s)return null;let a=r??ht();if(!a)throw new Error("SmartDOMReader is unavailable. Ensure the Smart DOM Reader module is loaded before calling extractRegion.");return new a(n).extract(s,n)}static extractContent(e,t,n={}){let r=t.querySelector(e);if(!r)return null;let s={selector:e,text:{},metadata:{wordCount:0,hasInteractive:!1}};if(n.includeHeadings!==!1){let c=r.querySelectorAll("h1, h2, h3, h4, h5, h6");s.text.headings=Array.from(c).map(l=>({level:Number.parseInt(l.tagName[1],10),text:p.getTextContent(l,n.maxTextLength)}))}let a=r.querySelectorAll("p");if(a.length>0&&(s.text.paragraphs=Array.from(a).map(c=>p.getTextContent(c,n.maxTextLength)).filter(c=>c.length>0)),n.includeLists!==!1){let c=r.querySelectorAll("ul, ol");s.text.lists=Array.from(c).map(l=>({type:l.tagName.toLowerCase(),items:Array.from(l.querySelectorAll("li")).map(d=>p.getTextContent(d,n.maxTextLength))}))}if(n.includeTables!==!1){let c=r.querySelectorAll("table");s.tables=Array.from(c).map(l=>({headers:Array.from(l.querySelectorAll("th")).map(d=>p.getTextContent(d)),rows:Array.from(l.querySelectorAll("tr")).filter(d=>d.querySelector("td")).map(d=>Array.from(d.querySelectorAll("td")).map(u=>p.getTextContent(u)))}))}if(n.includeMedia!==!1){let c=r.querySelectorAll("img"),l=r.querySelectorAll("video"),d=r.querySelectorAll("audio");s.media=[...Array.from(c).map(u=>{let f={type:"img"},m=u.getAttribute("alt"),y=u.getAttribute("src");return m&&(f.alt=m),y&&(f.src=y),f}),...Array.from(l).map(u=>{let f={type:"video"},m=u.getAttribute("src");return m&&(f.src=m),f}),...Array.from(d).map(u=>{let f={type:"audio"},m=u.getAttribute("src");return m&&(f.src=m),f})]}let i=r.textContent||"";return s.metadata.wordCount=i.trim().split(/\s+/).length,s.metadata.hasInteractive=r.querySelectorAll("button, a, input, textarea, select").length>0,s}static analyzeRegion(e){let t=b.generateSelectors(e).css,n=e.querySelectorAll('button, [role="button"]'),r=e.querySelectorAll("a[href]"),s=e.querySelectorAll("input, textarea, select"),a=e.querySelectorAll("form"),i=e.querySelectorAll("ul, ol"),c=e.querySelectorAll("table"),l=e.querySelectorAll("img, video, audio"),d=n.length+r.length+s.length,u,f=e.getAttribute("aria-label");if(f)u=f;else if(e.getAttribute("aria-labelledby")){let v=e.getAttribute("aria-labelledby");if(v){let P=e.ownerDocument?.getElementById(v);P&&(u=P.textContent?.trim())}}else{let v=e.querySelector("h1, h2, h3");v&&(u=v.textContent?.trim())}let m=e.textContent?.trim()||"",y=m.length>50?`${m.substring(0,50)}...`:m,h={selector:t,interactiveCount:d,hasForm:a.length>0,hasList:i.length>0,hasTable:c.length>0,hasMedia:l.length>0};u&&(h.label=u);let L=e.getAttribute("role");return L&&(h.role=L),n.length>0&&(h.buttonCount=n.length),r.length>0&&(h.linkCount=r.length),s.length>0&&(h.inputCount=s.length),y.length>0&&(h.textPreview=y),h}static extractFormOverview(e){let t=e.querySelectorAll("form");return Array.from(t).map(n=>{let r=n.querySelectorAll("input, textarea, select"),s=b.generateSelectors(n).css,a="unknown";n.closest('header, [role="banner"]')?a="header":n.closest('nav, [role="navigation"]')?a="navigation":n.closest('main, [role="main"]')?a="main":n.closest('aside, [role="complementary"]')?a="sidebar":n.closest('footer, [role="contentinfo"]')&&(a="footer");let i,c=n.getAttribute("id")?.toLowerCase(),l=n.getAttribute("class")?.toLowerCase(),d=n.getAttribute("action")?.toLowerCase(),u=n.querySelector('input[type="email"]'),f=n.querySelector('input[type="password"]');n.querySelector('input[type="search"]')||c?.includes("search")||l?.includes("search")?i="search":f&&u?i="login":f?i="authentication":c?.includes("contact")||l?.includes("contact")?i="contact":c?.includes("subscribe")||l?.includes("subscribe")?i="subscription":(d?.includes("checkout")||l?.includes("checkout"))&&(i="checkout");let m={selector:s,location:a,inputCount:r.length};return i&&(m.purpose=i),m})}static calculateSummary(e,t,n){let r=e.querySelectorAll("button, a[href], input, textarea, select"),s=e.querySelectorAll('section, article, [role="region"]'),a=(t.modals?.length||0)>0,i=[".error",".alert-danger",'[role="alert"]'].some(u=>{let f=e.querySelector(u);return f?g.isVisible(f):!1}),c=[".loading",".spinner",'[aria-busy="true"]'].some(u=>{let f=e.querySelector(u);return f?g.isVisible(f):!1}),l={totalInteractive:r.length,totalForms:n.length,totalSections:s.length,hasModals:a,hasErrors:i,isLoading:c},d=t.main?.selector;return d&&(l.mainContentSelector=d),l}static generateSuggestions(e,t){let n=[];return t.hasErrors&&n.push("Page has error indicators - check error messages before interacting"),t.isLoading&&n.push("Page appears to be loading - wait or check loading state"),t.hasModals&&n.push("Modal/dialog is open - may need to interact with or close it first"),e.main&&e.main.interactiveCount>10&&n.push(`Main content has ${e.main.interactiveCount} interactive elements - consider filtering`),t.totalForms>0&&n.push(`Found ${t.totalForms} form(s) on the page`),e.main||n.push("No clear main content area detected - may need to explore regions"),n}static getTextContent(e,t){let n=e.textContent?.trim()||"";return t&&n.length>t?`${n.substring(0,t)}...`:n}}})),pt=C((()=>{})),xt=st({ContentDetection:()=>T,MarkdownFormatter:()=>B,ProgressiveExtractor:()=>z,SelectorGenerator:()=>b,SmartDOMReader:()=>E,default:()=>E}),E,_=C((()=>{V(),I(),U(),mt(),gt(),pt(),E=class R{constructor(e={}){w(this,"options");this.options={mode:e.mode||"interactive",maxDepth:e.maxDepth||5,includeHidden:e.includeHidden||!1,includeShadowDOM:e.includeShadowDOM??!0,includeIframes:e.includeIframes||!1,viewportOnly:e.viewportOnly||!1,mainContentOnly:e.mainContentOnly||!1,customSelectors:e.customSelectors||[],...e.attributeTruncateLength!==void 0&&{attributeTruncateLength:e.attributeTruncateLength},...e.dataAttributeTruncateLength!==void 0&&{dataAttributeTruncateLength:e.dataAttributeTruncateLength},...e.textTruncateLength!==void 0&&{textTruncateLength:e.textTruncateLength},...e.filter!==void 0&&{filter:e.filter}}}extract(e=document,t){let n=Date.now(),r=e instanceof Document?e:e.ownerDocument,s={...this.options,...t},a=e instanceof Document?r:e;s.mainContentOnly&&e instanceof Document&&(a=T.findMainContent(r));let i=this.extractPageState(r),c=this.extractLandmarks(r),l=this.extractInteractiveElements(a,s),d={mode:s.mode,timestamp:n,page:i,landmarks:c,interactive:l};if(s.mode==="full"){let u=this.extractSemanticElements(a,s),f=this.extractMetadata(r,a,s);return{...d,semantic:u,metadata:f}}return d}extractPageState(e){let t=this.getFocusedElement(e);return{url:e.location?.href||"",title:e.title||"",hasErrors:this.detectErrors(e),isLoading:this.detectLoading(e),hasModals:this.detectModals(e),...t!==void 0&&{hasFocus:t}}}extractLandmarks(e){let t=T.detectLandmarks(e);return{navigation:this.elementsToSelectors(t.navigation||[]),main:this.elementsToSelectors(t.main||[]),forms:this.elementsToSelectors(t.form||[]),headers:this.elementsToSelectors(t.banner||[]),footers:this.elementsToSelectors(t.contentinfo||[]),articles:this.elementsToSelectors(t.region||[]),sections:this.elementsToSelectors(t.region||[])}}elementsToSelectors(e){return e.map(t=>b.generateSelectors(t).css)}extractInteractiveElements(e,t){let n=[],r=[],s=[],a=[];return e.querySelectorAll('button, [role="button"], input[type="button"], input[type="submit"]').forEach(i=>{if(this.shouldIncludeElement(i,t)){let c=g.extractElement(i,t);c&&n.push(c)}}),e.querySelectorAll("a[href]").forEach(i=>{if(this.shouldIncludeElement(i,t)){let c=g.extractElement(i,t);c&&r.push(c)}}),e.querySelectorAll('input:not([type="button"]):not([type="submit"]), textarea, select').forEach(i=>{if(this.shouldIncludeElement(i,t)){let c=g.extractElement(i,t);c&&s.push(c)}}),t.customSelectors&&t.customSelectors.forEach(i=>{e.querySelectorAll(i).forEach(c=>{if(this.shouldIncludeElement(c,t)){let l=g.extractElement(c,t);l&&a.push(l)}})}),{buttons:n,links:r,inputs:s,forms:this.extractForms(e,t),clickable:a}}extractForms(e,t){let n=[];return e.querySelectorAll("form").forEach(r=>{if(!this.shouldIncludeElement(r,t))return;let s=[],a=[];r.querySelectorAll('input:not([type="button"]):not([type="submit"]), textarea, select').forEach(d=>{let u=g.extractElement(d,t);u&&s.push(u)}),r.querySelectorAll('button, input[type="button"], input[type="submit"]').forEach(d=>{let u=g.extractElement(d,t);u&&a.push(u)});let i=r.getAttribute("action"),c=r.getAttribute("method"),l={selector:b.generateSelectors(r).css,inputs:s,buttons:a};i&&(l.action=i),c&&(l.method=c),n.push(l)}),n}extractSemanticElements(e,t){let n=[],r=[],s=[],a=[],i=[];return e.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(c=>{if(this.shouldIncludeElement(c,t)){let l=g.extractElement(c,t);l&&n.push(l)}}),e.querySelectorAll("img").forEach(c=>{if(this.shouldIncludeElement(c,t)){let l=g.extractElement(c,t);l&&r.push(l)}}),e.querySelectorAll("table").forEach(c=>{if(this.shouldIncludeElement(c,t)){let l=g.extractElement(c,t);l&&s.push(l)}}),e.querySelectorAll("ul, ol").forEach(c=>{if(this.shouldIncludeElement(c,t)){let l=g.extractElement(c,t);l&&a.push(l)}}),e.querySelectorAll('article, [role="article"]').forEach(c=>{if(this.shouldIncludeElement(c,t)){let l=g.extractElement(c,t);l&&i.push(l)}}),{headings:n,images:r,tables:s,lists:a,articles:i}}extractMetadata(e,t,n){let r=t.querySelectorAll("*"),s=t.querySelectorAll("button, a, input, textarea, select, h1, h2, h3, h4, h5, h6, img, table, ul, ol, article").length,a={totalElements:r.length,extractedElements:s};n.mainContentOnly&&t instanceof Element&&(a.mainContent=b.generateSelectors(t).css);let i=e.documentElement.getAttribute("lang");return i&&(a.language=i),a}shouldIncludeElement(e,t){return!(!t.includeHidden&&!g.isVisible(e)||t.viewportOnly&&!g.isInViewport(e)||t.filter&&!g.passesFilter(e,t.filter))}detectErrors(e){return[".error",".alert-danger",'[role="alert"]',".error-message"].some(t=>{let n=e.querySelector(t);return n?g.isVisible(n):!1})}detectLoading(e){return[".loading",".spinner",'[aria-busy="true"]',".loader"].some(t=>{let n=e.querySelector(t);return n?g.isVisible(n):!1})}detectModals(e){return['[role="dialog"]',".modal",".popup",".overlay"].some(t=>{let n=e.querySelector(t);return n?g.isVisible(n):!1})}getFocusedElement(e){let t=e.activeElement;if(t&&t!==e.body)return b.generateSelectors(t).css}static extractInteractive(e,t={}){return new R({...t,mode:"interactive"}).extract(e)}static extractFull(e,t={}){return new R({...t,mode:"full"}).extract(e)}static extractFromElement(e,t="interactive",n={}){return new R({...n,mode:t}).extract(e)}}}));_();var bt=new Set(["id","data-testid","role-aria","name","class-path","css-path"]);function X(o){let e=o.trim();return e.startsWith("/")||e.startsWith("(")||e.startsWith("./")}function yt(o){let e=o.selector.candidates;if(e&&e.length>0){let n=null;for(let r of e)bt.has(r.type)&&(!r.value||X(r.value)||(!n||r.score>n.score)&&(n=r));if(n)return n.value}let t=o.selector.css;return t&&!X(t)?t:null}function St(o){let e=o.tag.toLowerCase(),t=o.interaction.role??o.attributes.role;return e==="a"&&(o.interaction.nav||o.attributes.href!=null)?"navigable":e==="input"||e==="select"||e==="textarea"||t==="textbox"||t==="combobox"||t==="listbox"||t==="spinbutton"||o.interaction.change&&!o.interaction.click?"input":e==="button"||t==="button"||o.interaction.click||o.interaction.submit?"clickable":"static"}function Et(o){let e={...o.attributes},t=o.interaction.role;return t&&!e.role&&(e.role=t),e}function Ct(o,e){return e?[o.selector.css,o.selector.xpath,o.context.nearestForm,o.context.nearestSection,o.context.nearestMain,o.context.nearestNav,...o.selector.candidates?.map(n=>n.value)??[],...o.context.parentChain].some(n=>!!n&&n.includes(e)):!1}function N(o,e={}){let t=e.includeSemantic??!0,n=e.excludeSelector??".persona-host",r=e.maxTextLength??200,s=[o.interactive.buttons,o.interactive.links,o.interactive.inputs,o.interactive.clickable];t&&o.semantic&&s.push(o.semantic.headings,o.semantic.images,o.semantic.tables,o.semantic.lists,o.semantic.articles);let a=[],i=new Set,c=l=>{if(Ct(l,n))return!0;let d=yt(l);if(d&&!i.has(d)&&(i.add(d),a.push({selector:d,tagName:l.tag.toLowerCase(),text:(l.text??"").trim().substring(0,r),role:l.interaction.role??l.attributes.role??null,interactivity:St(l),attributes:Et(l)}),e.maxElements&&a.length>=e.maxElements))return!1;if(l.children){for(let u of l.children)if(!c(u))return!1}return!0};for(let l of s)if(l){for(let d of l)if(!c(d))return a}return a}var O=100;function G(o,e={}){if(o.length===0)return"No page elements found.";let t=e.mode??"structured",n=[];if(t==="structured"){let s=o.map(a=>a.formattedSummary).filter(a=>!!a&&a.length>0);s.length>0&&n.push(`Structured summaries:
|
|
10
|
-
${
|
|
6
|
+
</page>`}function H(o){return o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function j(o){return o.charAt(0).toUpperCase()+o.slice(1)}var _,gt=C((()=>{_=class{static structure(o,e={},t){let n=[];n.push("# Page Outline"),(t?.title||t?.url)&&(n.push(`Title: ${t?.title??""}`.trim()),n.push(`URL: ${t?.url??""}`.trim())),n.push("");let r=o.regions,i=[["header",r.header],["navigation",r.navigation],["main",r.main],["sections",r.sections],["sidebar",r.sidebar],["footer",r.footer],["modals",r.modals]];for(let[s,a]of i){if(!a)continue;let c=B(s);if(Array.isArray(a)){if(!a.length)continue;n.push(`## ${c} ${j(s)}`);for(let l of a)n.push(W(l))}else n.push(`## ${c} ${j(s)}`),n.push(W(a));n.push("")}if(o.suggestions?.length){n.push("## Suggestions");for(let s of o.suggestions)n.push(`- ${s}`);n.push("")}return n.push("Next: choose a region (by selector or [sectionId]) and call dom_extract_region for actionable details."),D(n.join(`
|
|
7
|
+
`),t,"outline")}static region(o,e={},t){let n=[];n.push("# Region Details"),(t?.title||t?.url)&&(n.push(`Title: ${t?.title??""}`.trim()),n.push(`URL: ${t?.url??""}`.trim())),n.push("");let r=o.interactive;if(o.page){let a=[o.page.hasErrors?"errors: yes":"errors: no",o.page.isLoading?"loading: yes":"loading: no",o.page.hasModals?"modals: yes":"modals: no"];n.push(`Page state: ${a.join(", ")}`)}let i=[],s=a=>a?a.length:0;return i.push(`${s(r.buttons)} buttons`),i.push(`${s(r.links)} links`),i.push(`${s(r.inputs)} inputs`),r.forms?.length&&i.push(`${s(r.forms)} forms`),n.push(`Summary: ${i.join(", ")}`),n.push(ft(r)),n.push(""),n.push(ht(r,e)),n.push(""),n.push("Next: write a script using the most stable selectors above. If selectors look unstable, rerun dom_extract_region with higher detail or call dom_extract_content for text context."),D(n.join(`
|
|
8
|
+
`),t,"section")}static content(o,e={},t){let n=[];if(n.push("# Content"),n.push(`Selector: \`${o.selector}\``),n.push(""),o.text.headings?.length){n.push("Headings:");for(let r of o.text.headings)n.push(`- H${r.level}: ${A(r.text,e.maxTextLength??120)}`);n.push("")}if(o.text.paragraphs?.length){let r=typeof e.maxElements=="number"?e.maxElements:o.text.paragraphs.length;n.push("Paragraphs:");for(let i of o.text.paragraphs.slice(0,r))n.push(`- ${A(i,e.maxTextLength??200)}`);n.push("")}if(o.text.lists?.length){n.push("Lists:");for(let r of o.text.lists){n.push(`- ${r.type.toUpperCase()}:`);let i=typeof e.maxElements=="number"?e.maxElements:r.items.length;for(let s of r.items.slice(0,i))n.push(` - ${A(s,e.maxTextLength??120)}`)}n.push("")}if(o.tables?.length){n.push("Tables:");for(let r of o.tables){n.push(`- Headers: ${r.headers.join(" | ")}`);let i=typeof e.maxElements=="number"?e.maxElements:r.rows.length;for(let s of r.rows.slice(0,i))n.push(` - ${s.join(" | ")}`)}n.push("")}if(o.media?.length){n.push("Media:");let r=typeof e.maxElements=="number"?e.maxElements:o.media.length;for(let i of o.media.slice(0,r))n.push(`- ${i.type.toUpperCase()}: ${i.alt??""} ${i.src?`\u2192 ${i.src}`:""}`.trim());n.push("")}return n.push("Next: if text is insufficient for targeting, call dom_extract_region for interactive selectors."),D(n.join(`
|
|
9
|
+
`),t,"content")}}}));function pt(){if(typeof window<"u"){let o=window,e=o.SmartDOMReader;if(typeof e=="function")return e;let t=o.SmartDOMReaderNamespace;if(t&&typeof t.SmartDOMReader=="function")return t.SmartDOMReader}try{if(typeof ut=="function"){let o=(X(),lt(St));if(o&&typeof o.SmartDOMReader=="function")return o.SmartDOMReader;if(o&&typeof o.default=="function")return o.default}}catch{}}var z,xt=C((()=>{U(),N(),V(),z=class p{static extractStructure(e){let t={},n=e.querySelector('header, [role="banner"], .header, #header');n&&(t.header=p.analyzeRegion(n));let r=e.querySelectorAll('nav, [role="navigation"], .nav, .navigation');if(r.length>0&&(t.navigation=Array.from(r).map(u=>p.analyzeRegion(u))),e instanceof Document){let u=T.findMainContent(e);if(u){t.main=p.analyzeRegion(u);let m=u.querySelectorAll('section, article, [role="region"]');m.length>0&&(t.sections=Array.from(m).filter(f=>!f.closest("nav, header, footer")).map(f=>p.analyzeRegion(f)))}}else{t.main=p.analyzeRegion(e);let u=e.querySelectorAll('section, article, [role="region"]');u.length>0&&(t.sections=Array.from(u).filter(m=>!m.closest("nav, header, footer")).map(m=>p.analyzeRegion(m)))}let i=e.querySelectorAll('aside, [role="complementary"], .sidebar, #sidebar');i.length>0&&(t.sidebar=Array.from(i).map(u=>p.analyzeRegion(u)));let s=e.querySelector('footer, [role="contentinfo"], .footer, #footer');s&&(t.footer=p.analyzeRegion(s));let a=e.querySelectorAll('[role="dialog"], .modal, .popup, .overlay'),c=Array.from(a).filter(u=>g.isVisible(u));c.length>0&&(t.modals=c.map(u=>p.analyzeRegion(u)));let l=p.extractFormOverview(e),d=p.calculateSummary(e,t,l);return{regions:t,forms:l,summary:d,suggestions:p.generateSuggestions(t,d)}}static extractRegion(e,t,n={},r){let i=t.querySelector(e);if(!i)return null;let s=r??pt();if(!s)throw new Error("SmartDOMReader is unavailable. Ensure the Smart DOM Reader module is loaded before calling extractRegion.");return new s(n).extract(i,n)}static extractContent(e,t,n={}){let r=t.querySelector(e);if(!r)return null;let i={selector:e,text:{},metadata:{wordCount:0,hasInteractive:!1}};if(n.includeHeadings!==!1){let c=r.querySelectorAll("h1, h2, h3, h4, h5, h6");i.text.headings=Array.from(c).map(l=>({level:Number.parseInt(l.tagName[1],10),text:p.getTextContent(l,n.maxTextLength)}))}let s=r.querySelectorAll("p");if(s.length>0&&(i.text.paragraphs=Array.from(s).map(c=>p.getTextContent(c,n.maxTextLength)).filter(c=>c.length>0)),n.includeLists!==!1){let c=r.querySelectorAll("ul, ol");i.text.lists=Array.from(c).map(l=>({type:l.tagName.toLowerCase(),items:Array.from(l.querySelectorAll("li")).map(d=>p.getTextContent(d,n.maxTextLength))}))}if(n.includeTables!==!1){let c=r.querySelectorAll("table");i.tables=Array.from(c).map(l=>({headers:Array.from(l.querySelectorAll("th")).map(d=>p.getTextContent(d)),rows:Array.from(l.querySelectorAll("tr")).filter(d=>d.querySelector("td")).map(d=>Array.from(d.querySelectorAll("td")).map(u=>p.getTextContent(u)))}))}if(n.includeMedia!==!1){let c=r.querySelectorAll("img"),l=r.querySelectorAll("video"),d=r.querySelectorAll("audio");i.media=[...Array.from(c).map(u=>{let m={type:"img"},f=u.getAttribute("alt"),S=u.getAttribute("src");return f&&(m.alt=f),S&&(m.src=S),m}),...Array.from(l).map(u=>{let m={type:"video"},f=u.getAttribute("src");return f&&(m.src=f),m}),...Array.from(d).map(u=>{let m={type:"audio"},f=u.getAttribute("src");return f&&(m.src=f),m})]}let a=r.textContent||"";return i.metadata.wordCount=a.trim().split(/\s+/).length,i.metadata.hasInteractive=r.querySelectorAll("button, a, input, textarea, select").length>0,i}static analyzeRegion(e){let t=b.generateSelectors(e).css,n=e.querySelectorAll('button, [role="button"]'),r=e.querySelectorAll("a[href]"),i=e.querySelectorAll("input, textarea, select"),s=e.querySelectorAll("form"),a=e.querySelectorAll("ul, ol"),c=e.querySelectorAll("table"),l=e.querySelectorAll("img, video, audio"),d=n.length+r.length+i.length,u,m=e.getAttribute("aria-label");if(m)u=m;else if(e.getAttribute("aria-labelledby")){let v=e.getAttribute("aria-labelledby");if(v){let k=e.ownerDocument?.getElementById(v);k&&(u=k.textContent?.trim())}}else{let v=e.querySelector("h1, h2, h3");v&&(u=v.textContent?.trim())}let f=e.textContent?.trim()||"",S=f.length>50?`${f.substring(0,50)}...`:f,h={selector:t,interactiveCount:d,hasForm:s.length>0,hasList:a.length>0,hasTable:c.length>0,hasMedia:l.length>0};u&&(h.label=u);let L=e.getAttribute("role");return L&&(h.role=L),n.length>0&&(h.buttonCount=n.length),r.length>0&&(h.linkCount=r.length),i.length>0&&(h.inputCount=i.length),S.length>0&&(h.textPreview=S),h}static extractFormOverview(e){let t=e.querySelectorAll("form");return Array.from(t).map(n=>{let r=n.querySelectorAll("input, textarea, select"),i=b.generateSelectors(n).css,s="unknown";n.closest('header, [role="banner"]')?s="header":n.closest('nav, [role="navigation"]')?s="navigation":n.closest('main, [role="main"]')?s="main":n.closest('aside, [role="complementary"]')?s="sidebar":n.closest('footer, [role="contentinfo"]')&&(s="footer");let a,c=n.getAttribute("id")?.toLowerCase(),l=n.getAttribute("class")?.toLowerCase(),d=n.getAttribute("action")?.toLowerCase(),u=n.querySelector('input[type="email"]'),m=n.querySelector('input[type="password"]');n.querySelector('input[type="search"]')||c?.includes("search")||l?.includes("search")?a="search":m&&u?a="login":m?a="authentication":c?.includes("contact")||l?.includes("contact")?a="contact":c?.includes("subscribe")||l?.includes("subscribe")?a="subscription":(d?.includes("checkout")||l?.includes("checkout"))&&(a="checkout");let f={selector:i,location:s,inputCount:r.length};return a&&(f.purpose=a),f})}static calculateSummary(e,t,n){let r=e.querySelectorAll("button, a[href], input, textarea, select"),i=e.querySelectorAll('section, article, [role="region"]'),s=(t.modals?.length||0)>0,a=[".error",".alert-danger",'[role="alert"]'].some(u=>{let m=e.querySelector(u);return m?g.isVisible(m):!1}),c=[".loading",".spinner",'[aria-busy="true"]'].some(u=>{let m=e.querySelector(u);return m?g.isVisible(m):!1}),l={totalInteractive:r.length,totalForms:n.length,totalSections:i.length,hasModals:s,hasErrors:a,isLoading:c},d=t.main?.selector;return d&&(l.mainContentSelector=d),l}static generateSuggestions(e,t){let n=[];return t.hasErrors&&n.push("Page has error indicators - check error messages before interacting"),t.isLoading&&n.push("Page appears to be loading - wait or check loading state"),t.hasModals&&n.push("Modal/dialog is open - may need to interact with or close it first"),e.main&&e.main.interactiveCount>10&&n.push(`Main content has ${e.main.interactiveCount} interactive elements - consider filtering`),t.totalForms>0&&n.push(`Found ${t.totalForms} form(s) on the page`),e.main||n.push("No clear main content area detected - may need to explore regions"),n}static getTextContent(e,t){let n=e.textContent?.trim()||"";return t&&n.length>t?`${n.substring(0,t)}...`:n}}})),bt=C((()=>{})),St=at({ContentDetection:()=>T,MarkdownFormatter:()=>_,ProgressiveExtractor:()=>z,SelectorGenerator:()=>b,SmartDOMReader:()=>E,default:()=>E}),E,X=C((()=>{U(),N(),V(),gt(),xt(),bt(),E=class I{constructor(e={}){M(this,"options");this.options={mode:e.mode||"interactive",maxDepth:e.maxDepth||5,includeHidden:e.includeHidden||!1,includeShadowDOM:e.includeShadowDOM??!0,includeIframes:e.includeIframes||!1,viewportOnly:e.viewportOnly||!1,mainContentOnly:e.mainContentOnly||!1,customSelectors:e.customSelectors||[],...e.attributeTruncateLength!==void 0&&{attributeTruncateLength:e.attributeTruncateLength},...e.dataAttributeTruncateLength!==void 0&&{dataAttributeTruncateLength:e.dataAttributeTruncateLength},...e.textTruncateLength!==void 0&&{textTruncateLength:e.textTruncateLength},...e.filter!==void 0&&{filter:e.filter}}}extract(e=document,t){let n=Date.now(),r=e instanceof Document?e:e.ownerDocument,i={...this.options,...t},s=e instanceof Document?r:e;i.mainContentOnly&&e instanceof Document&&(s=T.findMainContent(r));let a=this.extractPageState(r),c=this.extractLandmarks(r),l=this.extractInteractiveElements(s,i),d={mode:i.mode,timestamp:n,page:a,landmarks:c,interactive:l};if(i.mode==="full"){let u=this.extractSemanticElements(s,i),m=this.extractMetadata(r,s,i);return{...d,semantic:u,metadata:m}}return d}extractPageState(e){let t=this.getFocusedElement(e);return{url:e.location?.href||"",title:e.title||"",hasErrors:this.detectErrors(e),isLoading:this.detectLoading(e),hasModals:this.detectModals(e),...t!==void 0&&{hasFocus:t}}}extractLandmarks(e){let t=T.detectLandmarks(e);return{navigation:this.elementsToSelectors(t.navigation||[]),main:this.elementsToSelectors(t.main||[]),forms:this.elementsToSelectors(t.form||[]),headers:this.elementsToSelectors(t.banner||[]),footers:this.elementsToSelectors(t.contentinfo||[]),articles:this.elementsToSelectors(t.region||[]),sections:this.elementsToSelectors(t.region||[])}}elementsToSelectors(e){return e.map(t=>b.generateSelectors(t).css)}extractInteractiveElements(e,t){let n=[],r=[],i=[],s=[];return e.querySelectorAll('button, [role="button"], input[type="button"], input[type="submit"]').forEach(a=>{if(this.shouldIncludeElement(a,t)){let c=g.extractElement(a,t);c&&n.push(c)}}),e.querySelectorAll("a[href]").forEach(a=>{if(this.shouldIncludeElement(a,t)){let c=g.extractElement(a,t);c&&r.push(c)}}),e.querySelectorAll('input:not([type="button"]):not([type="submit"]), textarea, select').forEach(a=>{if(this.shouldIncludeElement(a,t)){let c=g.extractElement(a,t);c&&i.push(c)}}),t.customSelectors&&t.customSelectors.forEach(a=>{e.querySelectorAll(a).forEach(c=>{if(this.shouldIncludeElement(c,t)){let l=g.extractElement(c,t);l&&s.push(l)}})}),{buttons:n,links:r,inputs:i,forms:this.extractForms(e,t),clickable:s}}extractForms(e,t){let n=[];return e.querySelectorAll("form").forEach(r=>{if(!this.shouldIncludeElement(r,t))return;let i=[],s=[];r.querySelectorAll('input:not([type="button"]):not([type="submit"]), textarea, select').forEach(d=>{let u=g.extractElement(d,t);u&&i.push(u)}),r.querySelectorAll('button, input[type="button"], input[type="submit"]').forEach(d=>{let u=g.extractElement(d,t);u&&s.push(u)});let a=r.getAttribute("action"),c=r.getAttribute("method"),l={selector:b.generateSelectors(r).css,inputs:i,buttons:s};a&&(l.action=a),c&&(l.method=c),n.push(l)}),n}extractSemanticElements(e,t){let n=[],r=[],i=[],s=[],a=[];return e.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(c=>{if(this.shouldIncludeElement(c,t)){let l=g.extractElement(c,t);l&&n.push(l)}}),e.querySelectorAll("img").forEach(c=>{if(this.shouldIncludeElement(c,t)){let l=g.extractElement(c,t);l&&r.push(l)}}),e.querySelectorAll("table").forEach(c=>{if(this.shouldIncludeElement(c,t)){let l=g.extractElement(c,t);l&&i.push(l)}}),e.querySelectorAll("ul, ol").forEach(c=>{if(this.shouldIncludeElement(c,t)){let l=g.extractElement(c,t);l&&s.push(l)}}),e.querySelectorAll('article, [role="article"]').forEach(c=>{if(this.shouldIncludeElement(c,t)){let l=g.extractElement(c,t);l&&a.push(l)}}),{headings:n,images:r,tables:i,lists:s,articles:a}}extractMetadata(e,t,n){let r=t.querySelectorAll("*"),i=t.querySelectorAll("button, a, input, textarea, select, h1, h2, h3, h4, h5, h6, img, table, ul, ol, article").length,s={totalElements:r.length,extractedElements:i};n.mainContentOnly&&t instanceof Element&&(s.mainContent=b.generateSelectors(t).css);let a=e.documentElement.getAttribute("lang");return a&&(s.language=a),s}shouldIncludeElement(e,t){return!(!t.includeHidden&&!g.isVisible(e)||t.viewportOnly&&!g.isInViewport(e)||t.filter&&!g.passesFilter(e,t.filter))}detectErrors(e){return[".error",".alert-danger",'[role="alert"]',".error-message"].some(t=>{let n=e.querySelector(t);return n?g.isVisible(n):!1})}detectLoading(e){return[".loading",".spinner",'[aria-busy="true"]',".loader"].some(t=>{let n=e.querySelector(t);return n?g.isVisible(n):!1})}detectModals(e){return['[role="dialog"]',".modal",".popup",".overlay"].some(t=>{let n=e.querySelector(t);return n?g.isVisible(n):!1})}getFocusedElement(e){let t=e.activeElement;if(t&&t!==e.body)return b.generateSelectors(t).css}static extractInteractive(e,t={}){return new I({...t,mode:"interactive"}).extract(e)}static extractFull(e,t={}){return new I({...t,mode:"full"}).extract(e)}static extractFromElement(e,t="interactive",n={}){return new I({...n,mode:t}).extract(e)}}}));X();var yt=new Set(["id","data-testid","role-aria","name","class-path","css-path"]);function G(o){let e=o.trim();return e.startsWith("/")||e.startsWith("(")||e.startsWith("./")}function Et(o){let e=o.selector.candidates;if(e&&e.length>0){let n=null;for(let r of e)yt.has(r.type)&&(!r.value||G(r.value)||(!n||r.score>n.score)&&(n=r));if(n)return n.value}let t=o.selector.css;return t&&!G(t)?t:null}function Ct(o){let e=o.tag.toLowerCase(),t=o.interaction.role??o.attributes.role;return e==="a"&&(o.interaction.nav||o.attributes.href!=null)?"navigable":e==="input"||e==="select"||e==="textarea"||t==="textbox"||t==="combobox"||t==="listbox"||t==="spinbutton"||o.interaction.change&&!o.interaction.click?"input":e==="button"||t==="button"||o.interaction.click||o.interaction.submit?"clickable":"static"}function vt(o){let e={...o.attributes},t=o.interaction.role;return t&&!e.role&&(e.role=t),e}function At(o,e){return e?[o.selector.css,o.selector.xpath,o.context.nearestForm,o.context.nearestSection,o.context.nearestMain,o.context.nearestNav,...o.selector.candidates?.map(n=>n.value)??[],...o.context.parentChain].some(n=>!!n&&n.includes(e)):!1}function q(o,e={}){let t=e.includeSemantic??!0,n=e.excludeSelector??".persona-host",r=e.maxTextLength??200,i=[o.interactive.buttons,o.interactive.links,o.interactive.inputs,o.interactive.clickable];t&&o.semantic&&i.push(o.semantic.headings,o.semantic.images,o.semantic.tables,o.semantic.lists,o.semantic.articles);let s=[],a=new Set,c=l=>{if(At(l,n))return!0;let d=Et(l);if(d&&!a.has(d)&&(a.add(d),s.push({selector:d,tagName:l.tag.toLowerCase(),text:(l.text??"").trim().substring(0,r),role:l.interaction.role??l.attributes.role??null,interactivity:Ct(l),attributes:vt(l)}),e.maxElements&&s.length>=e.maxElements))return!1;if(l.children){for(let u of l.children)if(!c(u))return!1}return!0};for(let l of i)if(l){for(let d of l)if(!c(d))return s}return s}var O=100;function Y(o,e={}){if(o.length===0)return"No page elements found.";let t=e.mode??"structured",n=[];if(t==="structured"){let i=o.map(s=>s.formattedSummary).filter(s=>!!s&&s.length>0);i.length>0&&n.push(`Structured summaries:
|
|
10
|
+
${i.map(s=>`- ${s.split(`
|
|
11
11
|
`).join(`
|
|
12
12
|
`)}`).join(`
|
|
13
|
-
`)}`)}let r={clickable:[],navigable:[],input:[],static:[]};for(let
|
|
14
|
-
${
|
|
15
|
-
`)}`)}if(r.navigable.length>0){let
|
|
16
|
-
${
|
|
17
|
-
`)}`)}if(r.input.length>0){let
|
|
18
|
-
${
|
|
19
|
-
`)}`)}if(r.static.length>0){let
|
|
20
|
-
${
|
|
13
|
+
`)}`)}let r={clickable:[],navigable:[],input:[],static:[]};for(let i of o)t==="structured"&&i.formattedSummary||r[i.interactivity].push(i);if(r.clickable.length>0){let i=r.clickable.map(s=>`- ${s.selector}: "${s.text.substring(0,O)}" (clickable)`);n.push(`Interactive elements:
|
|
14
|
+
${i.join(`
|
|
15
|
+
`)}`)}if(r.navigable.length>0){let i=r.navigable.map(s=>`- ${s.selector}${s.attributes.href?`[href="${s.attributes.href}"]`:""}: "${s.text.substring(0,O)}" (navigable)`);n.push(`Navigation links:
|
|
16
|
+
${i.join(`
|
|
17
|
+
`)}`)}if(r.input.length>0){let i=r.input.map(s=>`- ${s.selector}${s.attributes.type?`[type="${s.attributes.type}"]`:""}: "${s.text.substring(0,O)}" (input)`);n.push(`Form inputs:
|
|
18
|
+
${i.join(`
|
|
19
|
+
`)}`)}if(r.static.length>0){let i=r.static.map(s=>`- ${s.selector}: "${s.text.substring(0,O)}"`);n.push(`Content:
|
|
20
|
+
${i.join(`
|
|
21
21
|
`)}`)}return n.join(`
|
|
22
22
|
|
|
23
|
-
`)}function K(o={}){let e=o.mode??"interactive",t;if(o.root)t=E.extractFromElement(o.root,e,o.extractionOptions);else{let n=o.document??(typeof document<"u"?document:void 0);if(!n)return[];t=e==="full"?E.extractFull(n,o.extractionOptions):E.extractInteractive(n,o.extractionOptions)}return
|
|
23
|
+
`)}function Tt(o,e){if(!o)return!0;let t=0;for(let n=0;n<e.length&&t<o.length;n++)e[n]===o[t]&&t++;return t===o.length}function Lt(o,e){let t=o.toLowerCase(),n=e.toLowerCase();return t.startsWith(n)?0:o.replace(/([a-z])([A-Z])/g,"$1 $2").split(/[\s\-_/.]+/).some(i=>i.toLowerCase().startsWith(n))?1:Tt(n,t)?2:3}function K(o,e){let t=o.recencyScore??0,n=e.recencyScore??0;return n!==t?n-t:o.label.localeCompare(e.label)}function Q(o,e){let t=e.trim();if(!t)return[...o].sort(K);let n=[];for(let r of o){let i=Lt(r.label,t);i!==3&&n.push({item:r,tier:i})}return n.sort((r,i)=>r.tier!==i.tier?r.tier-i.tier:K(r.item,i.item)),n.map(r=>r.item)}function P(o={}){let e=o.mode??"interactive",t;if(o.root)t=E.extractFromElement(o.root,e,o.extractionOptions);else{let n=o.document??(typeof document<"u"?document:void 0);if(!n)return[];t=e==="full"?E.extractFull(n,o.extractionOptions):E.extractInteractive(n,o.extractionOptions)}return q(t,{includeSemantic:o.includeSemantic??e==="full",excludeSelector:o.excludeSelector,maxTextLength:o.maxTextLength,maxElements:o.maxElements})}function wt(o={}){let e=o.contextKey??"pageContext";return()=>{let t=P(o);return t.length===0?{}:{[e]:Y(t)}}}var Mt=2e3,$t=o=>{switch(o){case"clickable":return"mouse-pointer-click";case"input":return"text-cursor-input";case"navigable":return"link";default:return"text"}},It=o=>{let t=(o.attributes["aria-label"]||o.text||o.tagName).trim(),n=t.length>48?`${t.slice(0,47)}\u2026`:t||o.tagName,r=[o.role??o.tagName,o.interactivity].filter(Boolean);return{id:o.selector,label:n,description:r.join(" \xB7 "),iconName:$t(o.interactivity),group:void 0}};function Rt(o={}){let e=o.id??"page",t=o.label??"Page",n=null,r=0,i=()=>{let s=P(o).map(a=>{let c=It(a);return o.mapItem?o.mapItem(a,c):c});return r=Date.now(),s};return{id:e,label:t,resolveOn:"submit",search:s=>{let a=!n||Date.now()-r>Mt;return(!n||s===""&&a)&&(n=i()),Q(n,s)},resolve:s=>{let a=o.document??(typeof document<"u"?document:void 0),c="";try{c=a?.querySelector(s.id)?.textContent?.trim()??""}catch{}return{llmAppend:`Page element "${s.label}" (${s.id}):
|
|
24
|
+
${c||"(no text)"}`,context:{selector:s.id}}}}}0&&(module.exports={collectSmartDomContext,createSmartDomMentionSource,createSmartDomReaderContextProvider,smartDomResultToEnriched});
|