grab 0.1.35 → 0.1.36

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.
Files changed (86) hide show
  1. package/dist/copy-content-3pnWacho.d.cts +218 -0
  2. package/dist/copy-content-DH6fBB50.d.ts +218 -0
  3. package/dist/core/index.cjs +1 -1
  4. package/dist/core/index.d.cts +2 -2
  5. package/dist/core/index.d.ts +2 -2
  6. package/dist/core/index.js +1 -1
  7. package/dist/core-B9aCRu_r.cjs +4374 -0
  8. package/dist/core-BNG77P9u.js +20 -0
  9. package/dist/core-BaM4pWDg.cjs +20 -0
  10. package/dist/core-BgAHCKe7.js +4492 -0
  11. package/dist/core-BnZu88Zq.js +20 -0
  12. package/dist/core-BoXxu65H.js +20 -0
  13. package/dist/core-Bw1MUegr.cjs +4374 -0
  14. package/dist/core-C-uBKPnx.js +20 -0
  15. package/dist/core-CMd2PuB-.cjs +20 -0
  16. package/dist/core-CN7fVz1T.cjs +4377 -0
  17. package/dist/core-C_moHA9D.js +20 -0
  18. package/dist/core-CoEZwalZ.js +4489 -0
  19. package/dist/core-Cyu0n7SO.js +20 -0
  20. package/dist/core-DMVlP9g5.js +20 -0
  21. package/dist/core-XXPjZNnn.cjs +20 -0
  22. package/dist/core-_t0msYhT.cjs +20 -0
  23. package/dist/core-eVrmPJ2u.cjs +20 -0
  24. package/dist/core-epcog0yL.cjs +20 -0
  25. package/dist/core-foLKkb5_.cjs +20 -0
  26. package/dist/core-kGODXK-N.js +4489 -0
  27. package/dist/create-element-selector-B5J9_3Fw.cjs +9 -0
  28. package/dist/create-element-selector-BEaSanPh.cjs +9 -0
  29. package/dist/create-element-selector-BR_zDrcL.js +296 -0
  30. package/dist/create-element-selector-C3VxTCEX.js +9 -0
  31. package/dist/create-element-selector-CIj_4oMe.js +9 -0
  32. package/dist/create-element-selector-C_6sG1Bd.js +296 -0
  33. package/dist/create-element-selector-ChuWL5x4.cjs +9 -0
  34. package/dist/create-element-selector-CufggNcJ.js +9 -0
  35. package/dist/create-element-selector-D1FizysC.js +9 -0
  36. package/dist/create-element-selector-D4_cMOfX.cjs +307 -0
  37. package/dist/create-element-selector-Dw4Hh5vX.cjs +307 -0
  38. package/dist/create-element-selector-pHsYuaOR.cjs +9 -0
  39. package/dist/freeze-updates-1bWq0iRj.cjs +3340 -0
  40. package/dist/freeze-updates-7yZ9p4Jb.cjs +52 -0
  41. package/dist/freeze-updates-B2R6sKrS.js +52 -0
  42. package/dist/freeze-updates-BUIl_I9a.js +52 -0
  43. package/dist/freeze-updates-D7wc1FFo.js +52 -0
  44. package/dist/freeze-updates-DC22uWxG.cjs +3347 -0
  45. package/dist/freeze-updates-DFjQ3htO.js +52 -0
  46. package/dist/freeze-updates-DIifOZze.js +2921 -0
  47. package/dist/freeze-updates-D_ae-e4T.js +2920 -0
  48. package/dist/freeze-updates-DdIqMW8Y.cjs +52 -0
  49. package/dist/freeze-updates-DvAOKSWG.cjs +52 -0
  50. package/dist/freeze-updates-F-dFqbvY.cjs +52 -0
  51. package/dist/index-CkMIwkYj.d.ts +413 -0
  52. package/dist/index-DR5AjI5S.d.cts +413 -0
  53. package/dist/index.cjs +1 -1
  54. package/dist/index.d.cts +2 -2
  55. package/dist/index.d.ts +2 -2
  56. package/dist/index.global.js +13 -13
  57. package/dist/index.js +1 -1
  58. package/dist/primitives.cjs +1 -1
  59. package/dist/primitives.d.cts +1 -1
  60. package/dist/primitives.d.ts +1 -1
  61. package/dist/primitives.js +1 -1
  62. package/dist/renderer-B65BudlT.cjs +9 -0
  63. package/dist/renderer-BRENw6lS.cjs +3205 -0
  64. package/dist/renderer-Bxc3RS-J.cjs +3205 -0
  65. package/dist/renderer-CD-Ju8A3.js +3205 -0
  66. package/dist/renderer-D0a4h1bK.cjs +9 -0
  67. package/dist/renderer-D3dvNcvm.cjs +9 -0
  68. package/dist/renderer-DQoIdFmy.js +9 -0
  69. package/dist/renderer-Dc20mGte.js +9 -0
  70. package/dist/renderer-DmNPMFh8.js +3205 -0
  71. package/dist/renderer-Dnyqr-yC.cjs +9 -0
  72. package/dist/renderer-gEdmDcCb.js +9 -0
  73. package/dist/renderer-kDb-jNJX.js +9 -0
  74. package/dist/state-BAZpSiUU.js +9 -0
  75. package/dist/state-BPvTpQtD.js +9 -0
  76. package/dist/state-Bn3fhsQ8.cjs +9 -0
  77. package/dist/state-BwCmdtcN.cjs +1306 -0
  78. package/dist/state-CFntkBxv.js +1696 -0
  79. package/dist/state-CR6-uxRM.cjs +9 -0
  80. package/dist/state-DQNAhhCY.cjs +1306 -0
  81. package/dist/state-Dgr3LbNH.cjs +9 -0
  82. package/dist/state-Ds-1VLFt.js +9 -0
  83. package/dist/state-Dt16Hkud.js +9 -0
  84. package/dist/state-LuyoMylH.js +1696 -0
  85. package/dist/state-x2vKMZfm.cjs +9 -0
  86. package/package.json +2 -2
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license MIT
3
+ *
4
+ * Copyright (c) 2025 Aiden Bai
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ const e=require(`./freeze-updates-F-dFqbvY.cjs`),t=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),n=(n,r)=>{let i=r?.componentName??`div`,a={version:e.pt,content:n,entries:r?.entries??[{tagName:r?.tagName,componentName:i,content:n,commentText:r?.commentText}],timestamp:Date.now()},o=e=>{e.preventDefault(),e.clipboardData?.setData(`text/plain`,n),e.clipboardData?.setData(`text/html`,`<meta charset='utf-8'><pre><code>${t(n)}</code></pre>`),e.clipboardData?.setData(`application/x-react-grab`,JSON.stringify(a))};document.addEventListener(`copy`,o);let s=document.createElement(`textarea`);s.value=n,s.style.position=`fixed`,s.style.left=`-9999px`,s.ariaHidden=`true`,document.body.appendChild(s),s.select();try{return typeof document.execCommand==`function`?document.execCommand(`copy`):!1}finally{document.removeEventListener(`copy`,o),s.remove()}},r=new Set([`role`,`name`,`aria-label`,`rel`,`href`]),i=e=>{if(!/^[a-z-]{3,}$/i.test(e))return!1;let t=e.split(/-|[A-Z]/);for(let e of t)if(e.length<=2||/[^aeiou]{4,}/i.test(e))return!1;return!0},a=(e,t)=>{let n=r.has(e)||e.startsWith(`data-`)&&i(e),a=i(t)&&t.length<100||t.startsWith(`#`)&&i(t.slice(1));return n&&a},o=e=>{let t=e[0].name;for(let n=1;n<e.length;n++)t=`${e[n].name} > ${t}`;return t},s=e=>{let t=0;for(let n of e)t+=n.penalty;return t},c=(e,t)=>s(e)-s(t),l=(e,t)=>{let n=e.parentNode;if(!n)return;let r=n.firstChild;if(!r)return;let i=0;for(;r&&(r.nodeType===Node.ELEMENT_NODE&&(t===void 0||r.tagName.toLowerCase()===t)&&i++,r!==e);)r=r.nextSibling;return i},u=(e,t)=>e===`html`?`html`:`${e}:nth-child(${t})`,d=(e,t)=>e===`html`?`html`:`${e}:nth-of-type(${t})`,f=(e,t)=>{let n=[],r=e.getAttribute(`id`),a=e.tagName.toLowerCase();r&&i(r)&&n.push({name:`#${CSS.escape(r)}`,penalty:0});for(let t of e.classList)i(t)&&n.push({name:`.${CSS.escape(t)}`,penalty:1});for(let r of e.attributes)t(r.name,r.value)&&n.push({name:`[${CSS.escape(r.name)}="${CSS.escape(r.value)}"]`,penalty:2});n.push({name:a,penalty:5});let o=l(e,a);o!==void 0&&n.push({name:d(a,o),penalty:10});let s=l(e);return s!==void 0&&n.push({name:u(a,s),penalty:50}),n},p=(t,n=e.X,r=[])=>{if(n<=0)return[];if(t.length===0)return[r];let i=[];for(let e of t[0]){let a=n-i.length;if(a<=0)break;i.push(...p(t.slice(1),a,[...r,e]))}return i},m=(e,t)=>{let n=t.getRootNode?.();return n instanceof ShadowRoot?n:e.nodeType===Node.DOCUMENT_NODE?e:e.ownerDocument},h=(e,t)=>t.querySelectorAll(o(e)).length===1,g=(e,t)=>{let n=e,r=[];for(;n&&n!==t;){let e=n.tagName.toLowerCase(),t=l(n,e);if(t===void 0)return;r.push({name:d(e,t),penalty:10}),n=n.parentElement}return h(r,t)?r:void 0},_=(e,t,n,r)=>{if(e.nodeType!==Node.ELEMENT_NODE)throw Error(`Can't generate CSS selector for non-element node type.`);if(e.tagName.toLowerCase()===`html`)return`html`;let i=m(t,e),a=Date.now(),s=[],l=e,u=0,d;for(;l&&l!==i&&!d;)if(s.push(f(l,r)),l=l.parentElement,u++,u>=3){let t=p(s);t.sort(c);for(let r of t){if(Date.now()-a>n){let t=g(e,i);if(!t)throw Error(`Timeout: Can't find a unique selector after ${n}ms`);return o(t)}if(h(r,i)){d=r;break}}}if(!d&&u<3){let e=p(s);e.sort(c);for(let t of e){if(Date.now()-a>n)break;if(h(t,i)){d=t;break}}}if(!d)throw Error(`Selector was not found.`);return o(d)},v=e=>typeof CSS<`u`&&typeof CSS.escape==`function`?CSS.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,e=>`\\${e}`),y=e=>e.ownerDocument.body??e.ownerDocument.documentElement,b=new Set([`data-testid`,`data-test-id`,`data-test`,`data-cy`,`data-qa`,`aria-label`,`role`,`name`,`title`,`alt`]),x=e=>e.length>0&&e.length<=120,S=(e,t)=>{try{let n=e.ownerDocument.querySelectorAll(t);return n.length===1&&n[0]===e}catch{return!1}},C=e=>{if(e instanceof HTMLElement&&e.id){let t=`#${v(e.id)}`;if(S(e,t))return t}for(let t of b){let n=e.getAttribute(t);if(!n||!x(n))continue;let r=`[${t}=${JSON.stringify(n)}]`;if(S(e,r))return r;let i=`${e.tagName.toLowerCase()}${r}`;if(S(e,i))return i}return null},w=e=>{let t=[],n=y(e),r=e;for(;r;){if(r instanceof HTMLElement&&r.id){t.unshift(`#${v(r.id)}`);break}let e=r.parentElement;if(!e){t.unshift(r.tagName.toLowerCase());break}let i=Array.from(e.children).indexOf(r),a=i>=0?i+1:1;if(t.unshift(`${r.tagName.toLowerCase()}:nth-child(${a})`),e===n){t.unshift(n.tagName.toLowerCase());break}r=e}return t.join(` > `)},T=(e,t=!0)=>{let n=C(e);if(n)return n;if(t)try{let t=_(e,y(e),200,(e,t)=>a(e,t)||b.has(e)&&x(t));if(t)return t}catch{}return w(e)};Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return T}});
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license MIT
3
+ *
4
+ * Copyright (c) 2025 Aiden Bai
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ import{Y as e,ft as t}from"./freeze-updates-D7wc1FFo.js";const n=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),r=(e,r)=>{let i=r?.componentName??`div`,a={version:t,content:e,entries:r?.entries??[{tagName:r?.tagName,componentName:i,content:e,commentText:r?.commentText}],timestamp:Date.now()},o=t=>{t.preventDefault(),t.clipboardData?.setData(`text/plain`,e),t.clipboardData?.setData(`text/html`,`<meta charset='utf-8'><pre><code>${n(e)}</code></pre>`),t.clipboardData?.setData(`application/x-react-grab`,JSON.stringify(a))};document.addEventListener(`copy`,o);let s=document.createElement(`textarea`);s.value=e,s.style.position=`fixed`,s.style.left=`-9999px`,s.ariaHidden=`true`,document.body.appendChild(s),s.select();try{return typeof document.execCommand==`function`?document.execCommand(`copy`):!1}finally{document.removeEventListener(`copy`,o),s.remove()}},i=new Set([`role`,`name`,`aria-label`,`rel`,`href`]),a=e=>{if(!/^[a-z-]{3,}$/i.test(e))return!1;let t=e.split(/-|[A-Z]/);for(let e of t)if(e.length<=2||/[^aeiou]{4,}/i.test(e))return!1;return!0},o=(e,t)=>{let n=i.has(e)||e.startsWith(`data-`)&&a(e),r=a(t)&&t.length<100||t.startsWith(`#`)&&a(t.slice(1));return n&&r},s=e=>{let t=e[0].name;for(let n=1;n<e.length;n++)t=`${e[n].name} > ${t}`;return t},c=e=>{let t=0;for(let n of e)t+=n.penalty;return t},l=(e,t)=>c(e)-c(t),u=(e,t)=>{let n=e.parentNode;if(!n)return;let r=n.firstChild;if(!r)return;let i=0;for(;r&&(r.nodeType===Node.ELEMENT_NODE&&(t===void 0||r.tagName.toLowerCase()===t)&&i++,r!==e);)r=r.nextSibling;return i},d=(e,t)=>e===`html`?`html`:`${e}:nth-child(${t})`,f=(e,t)=>e===`html`?`html`:`${e}:nth-of-type(${t})`,p=(e,t)=>{let n=[],r=e.getAttribute(`id`),i=e.tagName.toLowerCase();r&&a(r)&&n.push({name:`#${CSS.escape(r)}`,penalty:0});for(let t of e.classList)a(t)&&n.push({name:`.${CSS.escape(t)}`,penalty:1});for(let r of e.attributes)t(r.name,r.value)&&n.push({name:`[${CSS.escape(r.name)}="${CSS.escape(r.value)}"]`,penalty:2});n.push({name:i,penalty:5});let o=u(e,i);o!==void 0&&n.push({name:f(i,o),penalty:10});let s=u(e);return s!==void 0&&n.push({name:d(i,s),penalty:50}),n},m=(t,n=e,r=[])=>{if(n<=0)return[];if(t.length===0)return[r];let i=[];for(let e of t[0]){let a=n-i.length;if(a<=0)break;i.push(...m(t.slice(1),a,[...r,e]))}return i},h=(e,t)=>{let n=t.getRootNode?.();return n instanceof ShadowRoot?n:e.nodeType===Node.DOCUMENT_NODE?e:e.ownerDocument},g=(e,t)=>t.querySelectorAll(s(e)).length===1,_=(e,t)=>{let n=e,r=[];for(;n&&n!==t;){let e=n.tagName.toLowerCase(),t=u(n,e);if(t===void 0)return;r.push({name:f(e,t),penalty:10}),n=n.parentElement}return g(r,t)?r:void 0},v=(e,t,n,r)=>{if(e.nodeType!==Node.ELEMENT_NODE)throw Error(`Can't generate CSS selector for non-element node type.`);if(e.tagName.toLowerCase()===`html`)return`html`;let i=h(t,e),a=Date.now(),o=[],c=e,u=0,d;for(;c&&c!==i&&!d;)if(o.push(p(c,r)),c=c.parentElement,u++,u>=3){let t=m(o);t.sort(l);for(let r of t){if(Date.now()-a>n){let t=_(e,i);if(!t)throw Error(`Timeout: Can't find a unique selector after ${n}ms`);return s(t)}if(g(r,i)){d=r;break}}}if(!d&&u<3){let e=m(o);e.sort(l);for(let t of e){if(Date.now()-a>n)break;if(g(t,i)){d=t;break}}}if(!d)throw Error(`Selector was not found.`);return s(d)},y=e=>typeof CSS<`u`&&typeof CSS.escape==`function`?CSS.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,e=>`\\${e}`),b=e=>e.ownerDocument.body??e.ownerDocument.documentElement,x=new Set([`data-testid`,`data-test-id`,`data-test`,`data-cy`,`data-qa`,`aria-label`,`role`,`name`,`title`,`alt`]),S=e=>e.length>0&&e.length<=120,C=(e,t)=>{try{let n=e.ownerDocument.querySelectorAll(t);return n.length===1&&n[0]===e}catch{return!1}},w=e=>{if(e instanceof HTMLElement&&e.id){let t=`#${y(e.id)}`;if(C(e,t))return t}for(let t of x){let n=e.getAttribute(t);if(!n||!S(n))continue;let r=`[${t}=${JSON.stringify(n)}]`;if(C(e,r))return r;let i=`${e.tagName.toLowerCase()}${r}`;if(C(e,i))return i}return null},T=e=>{let t=[],n=b(e),r=e;for(;r;){if(r instanceof HTMLElement&&r.id){t.unshift(`#${y(r.id)}`);break}let e=r.parentElement;if(!e){t.unshift(r.tagName.toLowerCase());break}let i=Array.from(e.children).indexOf(r),a=i>=0?i+1:1;if(t.unshift(`${r.tagName.toLowerCase()}:nth-child(${a})`),e===n){t.unshift(n.tagName.toLowerCase());break}r=e}return t.join(` > `)},E=(e,t=!0)=>{let n=w(e);if(n)return n;if(t)try{let t=v(e,b(e),200,(e,t)=>o(e,t)||x.has(e)&&S(t));if(t)return t}catch{}return T(e)};export{r as n,E as t};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @license MIT
3
+ *
4
+ * Copyright (c) 2025 Aiden Bai
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ import{X as e,pt as t}from"./freeze-updates-DFjQ3htO.js";const n=e=>e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`),r=(e,r)=>{let i=r?.componentName??`div`,a={version:t,content:e,entries:r?.entries??[{tagName:r?.tagName,componentName:i,content:e,commentText:r?.commentText}],timestamp:Date.now()},o=t=>{t.preventDefault(),t.clipboardData?.setData(`text/plain`,e),t.clipboardData?.setData(`text/html`,`<meta charset='utf-8'><pre><code>${n(e)}</code></pre>`),t.clipboardData?.setData(`application/x-react-grab`,JSON.stringify(a))};document.addEventListener(`copy`,o);let s=document.createElement(`textarea`);s.value=e,s.style.position=`fixed`,s.style.left=`-9999px`,s.ariaHidden=`true`,document.body.appendChild(s),s.select();try{return typeof document.execCommand==`function`?document.execCommand(`copy`):!1}finally{document.removeEventListener(`copy`,o),s.remove()}},i=new Set([`role`,`name`,`aria-label`,`rel`,`href`]),a=e=>{if(!/^[a-z-]{3,}$/i.test(e))return!1;let t=e.split(/-|[A-Z]/);for(let e of t)if(e.length<=2||/[^aeiou]{4,}/i.test(e))return!1;return!0},o=(e,t)=>{let n=i.has(e)||e.startsWith(`data-`)&&a(e),r=a(t)&&t.length<100||t.startsWith(`#`)&&a(t.slice(1));return n&&r},s=e=>{let t=e[0].name;for(let n=1;n<e.length;n++)t=`${e[n].name} > ${t}`;return t},c=e=>{let t=0;for(let n of e)t+=n.penalty;return t},l=(e,t)=>c(e)-c(t),u=(e,t)=>{let n=e.parentNode;if(!n)return;let r=n.firstChild;if(!r)return;let i=0;for(;r&&(r.nodeType===Node.ELEMENT_NODE&&(t===void 0||r.tagName.toLowerCase()===t)&&i++,r!==e);)r=r.nextSibling;return i},d=(e,t)=>e===`html`?`html`:`${e}:nth-child(${t})`,f=(e,t)=>e===`html`?`html`:`${e}:nth-of-type(${t})`,p=(e,t)=>{let n=[],r=e.getAttribute(`id`),i=e.tagName.toLowerCase();r&&a(r)&&n.push({name:`#${CSS.escape(r)}`,penalty:0});for(let t of e.classList)a(t)&&n.push({name:`.${CSS.escape(t)}`,penalty:1});for(let r of e.attributes)t(r.name,r.value)&&n.push({name:`[${CSS.escape(r.name)}="${CSS.escape(r.value)}"]`,penalty:2});n.push({name:i,penalty:5});let o=u(e,i);o!==void 0&&n.push({name:f(i,o),penalty:10});let s=u(e);return s!==void 0&&n.push({name:d(i,s),penalty:50}),n},m=(t,n=e,r=[])=>{if(n<=0)return[];if(t.length===0)return[r];let i=[];for(let e of t[0]){let a=n-i.length;if(a<=0)break;i.push(...m(t.slice(1),a,[...r,e]))}return i},h=(e,t)=>{let n=t.getRootNode?.();return n instanceof ShadowRoot?n:e.nodeType===Node.DOCUMENT_NODE?e:e.ownerDocument},g=(e,t)=>t.querySelectorAll(s(e)).length===1,_=(e,t)=>{let n=e,r=[];for(;n&&n!==t;){let e=n.tagName.toLowerCase(),t=u(n,e);if(t===void 0)return;r.push({name:f(e,t),penalty:10}),n=n.parentElement}return g(r,t)?r:void 0},v=(e,t,n,r)=>{if(e.nodeType!==Node.ELEMENT_NODE)throw Error(`Can't generate CSS selector for non-element node type.`);if(e.tagName.toLowerCase()===`html`)return`html`;let i=h(t,e),a=Date.now(),o=[],c=e,u=0,d;for(;c&&c!==i&&!d;)if(o.push(p(c,r)),c=c.parentElement,u++,u>=3){let t=m(o);t.sort(l);for(let r of t){if(Date.now()-a>n){let t=_(e,i);if(!t)throw Error(`Timeout: Can't find a unique selector after ${n}ms`);return s(t)}if(g(r,i)){d=r;break}}}if(!d&&u<3){let e=m(o);e.sort(l);for(let t of e){if(Date.now()-a>n)break;if(g(t,i)){d=t;break}}}if(!d)throw Error(`Selector was not found.`);return s(d)},y=e=>typeof CSS<`u`&&typeof CSS.escape==`function`?CSS.escape(e):e.replace(/[^a-zA-Z0-9_-]/g,e=>`\\${e}`),b=e=>e.ownerDocument.body??e.ownerDocument.documentElement,x=new Set([`data-testid`,`data-test-id`,`data-test`,`data-cy`,`data-qa`,`aria-label`,`role`,`name`,`title`,`alt`]),S=e=>e.length>0&&e.length<=120,C=(e,t)=>{try{let n=e.ownerDocument.querySelectorAll(t);return n.length===1&&n[0]===e}catch{return!1}},w=e=>{if(e instanceof HTMLElement&&e.id){let t=`#${y(e.id)}`;if(C(e,t))return t}for(let t of x){let n=e.getAttribute(t);if(!n||!S(n))continue;let r=`[${t}=${JSON.stringify(n)}]`;if(C(e,r))return r;let i=`${e.tagName.toLowerCase()}${r}`;if(C(e,i))return i}return null},T=e=>{let t=[],n=b(e),r=e;for(;r;){if(r instanceof HTMLElement&&r.id){t.unshift(`#${y(r.id)}`);break}let e=r.parentElement;if(!e){t.unshift(r.tagName.toLowerCase());break}let i=Array.from(e.children).indexOf(r),a=i>=0?i+1:1;if(t.unshift(`${r.tagName.toLowerCase()}:nth-child(${a})`),e===n){t.unshift(n.tagName.toLowerCase());break}r=e}return t.join(` > `)},E=(e,t=!0)=>{let n=w(e);if(n)return n;if(t)try{let t=v(e,b(e),200,(e,t)=>o(e,t)||x.has(e)&&S(t));if(t)return t}catch{}return T(e)};export{r as n,E as t};
@@ -0,0 +1,307 @@
1
+ /**
2
+ * @license MIT
3
+ *
4
+ * Copyright (c) 2025 Aiden Bai
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ const require_freeze_updates = require('./freeze-updates-DC22uWxG.cjs');
10
+
11
+ //#region src/utils/copy-content.ts
12
+ const REACT_GRAB_MIME_TYPE = "application/x-react-grab";
13
+ const escapeHtml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
14
+ const copyContent = (content, options) => {
15
+ const elementName = options?.componentName ?? "div";
16
+ const reactGrabMetadata = {
17
+ version: require_freeze_updates.VERSION,
18
+ content,
19
+ entries: options?.entries ?? [{
20
+ tagName: options?.tagName,
21
+ componentName: elementName,
22
+ content,
23
+ commentText: options?.commentText
24
+ }],
25
+ timestamp: Date.now()
26
+ };
27
+ const copyHandler = (event) => {
28
+ event.preventDefault();
29
+ event.clipboardData?.setData("text/plain", content);
30
+ event.clipboardData?.setData("text/html", `<meta charset='utf-8'><pre><code>${escapeHtml(content)}</code></pre>`);
31
+ event.clipboardData?.setData(REACT_GRAB_MIME_TYPE, JSON.stringify(reactGrabMetadata));
32
+ };
33
+ document.addEventListener("copy", copyHandler);
34
+ const textarea = document.createElement("textarea");
35
+ textarea.value = content;
36
+ textarea.style.position = "fixed";
37
+ textarea.style.left = "-9999px";
38
+ textarea.ariaHidden = "true";
39
+ document.body.appendChild(textarea);
40
+ textarea.select();
41
+ try {
42
+ if (typeof document.execCommand !== "function") return false;
43
+ return document.execCommand("copy");
44
+ } finally {
45
+ document.removeEventListener("copy", copyHandler);
46
+ textarea.remove();
47
+ }
48
+ };
49
+
50
+ //#endregion
51
+ //#region src/utils/find-unique-selector.ts
52
+ const SEED_MIN_LENGTH = 3;
53
+ const ATTR_VALUE_MAX_LENGTH_CHARS = 100;
54
+ const PENALTY_ID = 0;
55
+ const PENALTY_CLASS = 1;
56
+ const PENALTY_ATTR = 2;
57
+ const PENALTY_TAG = 5;
58
+ const PENALTY_NTH_OF_TYPE = 10;
59
+ const PENALTY_NTH_CHILD = 50;
60
+ const ACCEPTED_ATTR_NAMES = new Set([
61
+ "role",
62
+ "name",
63
+ "aria-label",
64
+ "rel",
65
+ "href"
66
+ ]);
67
+ const isWordLike = (text) => {
68
+ if (!/^[a-z-]{3,}$/i.test(text)) return false;
69
+ const segments = text.split(/-|[A-Z]/);
70
+ for (const segment of segments) {
71
+ if (segment.length <= 2) return false;
72
+ if (/[^aeiou]{4,}/i.test(segment)) return false;
73
+ }
74
+ return true;
75
+ };
76
+ const isAcceptedAttr = (attributeName, attributeValue) => {
77
+ const nameIsAccepted = ACCEPTED_ATTR_NAMES.has(attributeName) || attributeName.startsWith("data-") && isWordLike(attributeName);
78
+ const valueIsAccepted = isWordLike(attributeValue) && attributeValue.length < ATTR_VALUE_MAX_LENGTH_CHARS || attributeValue.startsWith("#") && isWordLike(attributeValue.slice(1));
79
+ return nameIsAccepted && valueIsAccepted;
80
+ };
81
+ const buildSelectorString = (path) => {
82
+ let result = path[0].name;
83
+ for (let index = 1; index < path.length; index++) result = `${path[index].name} > ${result}`;
84
+ return result;
85
+ };
86
+ const calculatePenalty = (path) => {
87
+ let total = 0;
88
+ for (const selectorNode of path) total += selectorNode.penalty;
89
+ return total;
90
+ };
91
+ const comparePenalty = (pathA, pathB) => calculatePenalty(pathA) - calculatePenalty(pathB);
92
+ const getChildIndex = (element, filterTagName) => {
93
+ const parentNode = element.parentNode;
94
+ if (!parentNode) return void 0;
95
+ let sibling = parentNode.firstChild;
96
+ if (!sibling) return void 0;
97
+ let position = 0;
98
+ while (sibling) {
99
+ if (sibling.nodeType === Node.ELEMENT_NODE && (filterTagName === void 0 || sibling.tagName.toLowerCase() === filterTagName)) position++;
100
+ if (sibling === element) break;
101
+ sibling = sibling.nextSibling;
102
+ }
103
+ return position;
104
+ };
105
+ const formatNthChild = (tagName, childPosition) => tagName === "html" ? "html" : `${tagName}:nth-child(${childPosition})`;
106
+ const formatNthOfType = (tagName, typePosition) => tagName === "html" ? "html" : `${tagName}:nth-of-type(${typePosition})`;
107
+ const collectCandidateNodes = (element, attrFilter) => {
108
+ const candidates = [];
109
+ const elementId = element.getAttribute("id");
110
+ const elementTagName = element.tagName.toLowerCase();
111
+ if (elementId && isWordLike(elementId)) candidates.push({
112
+ name: `#${CSS.escape(elementId)}`,
113
+ penalty: PENALTY_ID
114
+ });
115
+ for (const className of element.classList) if (isWordLike(className)) candidates.push({
116
+ name: `.${CSS.escape(className)}`,
117
+ penalty: PENALTY_CLASS
118
+ });
119
+ for (const attribute of element.attributes) if (attrFilter(attribute.name, attribute.value)) candidates.push({
120
+ name: `[${CSS.escape(attribute.name)}="${CSS.escape(attribute.value)}"]`,
121
+ penalty: PENALTY_ATTR
122
+ });
123
+ candidates.push({
124
+ name: elementTagName,
125
+ penalty: PENALTY_TAG
126
+ });
127
+ const typePosition = getChildIndex(element, elementTagName);
128
+ if (typePosition !== void 0) candidates.push({
129
+ name: formatNthOfType(elementTagName, typePosition),
130
+ penalty: PENALTY_NTH_OF_TYPE
131
+ });
132
+ const childPosition = getChildIndex(element);
133
+ if (childPosition !== void 0) candidates.push({
134
+ name: formatNthChild(elementTagName, childPosition),
135
+ penalty: PENALTY_NTH_CHILD
136
+ });
137
+ return candidates;
138
+ };
139
+ const collectCombinations = (stack, budget = require_freeze_updates.MAX_SELECTOR_COMBINATIONS, currentPath = []) => {
140
+ if (budget <= 0) return [];
141
+ if (stack.length === 0) return [currentPath];
142
+ const results = [];
143
+ for (const selectorNode of stack[0]) {
144
+ const remainingBudget = budget - results.length;
145
+ if (remainingBudget <= 0) break;
146
+ results.push(...collectCombinations(stack.slice(1), remainingBudget, [...currentPath, selectorNode]));
147
+ }
148
+ return results;
149
+ };
150
+ const resolveRootDocument = (rootNode, targetElement) => {
151
+ const attachedRoot = targetElement.getRootNode?.();
152
+ if (attachedRoot instanceof ShadowRoot) return attachedRoot;
153
+ if (rootNode.nodeType === Node.DOCUMENT_NODE) return rootNode;
154
+ return rootNode.ownerDocument;
155
+ };
156
+ const isSelectorUnique = (selectorPath, rootDocument) => rootDocument.querySelectorAll(buildSelectorString(selectorPath)).length === 1;
157
+ const buildFallbackPath = (targetElement, rootDocument) => {
158
+ let currentElement = targetElement;
159
+ const path = [];
160
+ while (currentElement && currentElement !== rootDocument) {
161
+ const currentTagName = currentElement.tagName.toLowerCase();
162
+ const typePosition = getChildIndex(currentElement, currentTagName);
163
+ if (typePosition === void 0) return void 0;
164
+ path.push({
165
+ name: formatNthOfType(currentTagName, typePosition),
166
+ penalty: PENALTY_NTH_OF_TYPE
167
+ });
168
+ currentElement = currentElement.parentElement;
169
+ }
170
+ return isSelectorUnique(path, rootDocument) ? path : void 0;
171
+ };
172
+ const findUniqueSelector = (targetElement, root, timeoutMs, attrFilter) => {
173
+ if (targetElement.nodeType !== Node.ELEMENT_NODE) throw new Error("Can't generate CSS selector for non-element node type.");
174
+ if (targetElement.tagName.toLowerCase() === "html") return "html";
175
+ const rootDocument = resolveRootDocument(root, targetElement);
176
+ const startTime = Date.now();
177
+ const ancestorStack = [];
178
+ let currentElement = targetElement;
179
+ let depth = 0;
180
+ let foundPath;
181
+ while (currentElement && currentElement !== rootDocument && !foundPath) {
182
+ ancestorStack.push(collectCandidateNodes(currentElement, attrFilter));
183
+ currentElement = currentElement.parentElement;
184
+ depth++;
185
+ if (depth >= SEED_MIN_LENGTH) {
186
+ const candidatePaths = collectCombinations(ancestorStack);
187
+ candidatePaths.sort(comparePenalty);
188
+ for (const candidatePath of candidatePaths) {
189
+ if (Date.now() - startTime > timeoutMs) {
190
+ const fallbackPath = buildFallbackPath(targetElement, rootDocument);
191
+ if (!fallbackPath) throw new Error(`Timeout: Can't find a unique selector after ${timeoutMs}ms`);
192
+ return buildSelectorString(fallbackPath);
193
+ }
194
+ if (isSelectorUnique(candidatePath, rootDocument)) {
195
+ foundPath = candidatePath;
196
+ break;
197
+ }
198
+ }
199
+ }
200
+ }
201
+ if (!foundPath && depth < SEED_MIN_LENGTH) {
202
+ const remainingPaths = collectCombinations(ancestorStack);
203
+ remainingPaths.sort(comparePenalty);
204
+ for (const candidatePath of remainingPaths) {
205
+ if (Date.now() - startTime > timeoutMs) break;
206
+ if (isSelectorUnique(candidatePath, rootDocument)) {
207
+ foundPath = candidatePath;
208
+ break;
209
+ }
210
+ }
211
+ }
212
+ if (!foundPath) throw new Error("Selector was not found.");
213
+ return buildSelectorString(foundPath);
214
+ };
215
+
216
+ //#endregion
217
+ //#region src/utils/create-element-selector.ts
218
+ const escapeCssIdentifier = (value) => {
219
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") return CSS.escape(value);
220
+ return value.replace(/[^a-zA-Z0-9_-]/g, (character) => `\\${character}`);
221
+ };
222
+ const getFinderRoot = (element) => element.ownerDocument.body ?? element.ownerDocument.documentElement;
223
+ const PREFERRED_SELECTOR_ATTRIBUTE_NAMES = new Set([
224
+ "data-testid",
225
+ "data-test-id",
226
+ "data-test",
227
+ "data-cy",
228
+ "data-qa",
229
+ "aria-label",
230
+ "role",
231
+ "name",
232
+ "title",
233
+ "alt"
234
+ ]);
235
+ const isPreferredAttributeValueSafe = (value) => value.length > 0 && value.length <= 120;
236
+ const isSelectorUniqueForElement = (element, selector) => {
237
+ try {
238
+ const matchingElements = element.ownerDocument.querySelectorAll(selector);
239
+ return matchingElements.length === 1 && matchingElements[0] === element;
240
+ } catch {
241
+ return false;
242
+ }
243
+ };
244
+ const createFastElementSelector = (element) => {
245
+ if (element instanceof HTMLElement && element.id) {
246
+ const idSelector = `#${escapeCssIdentifier(element.id)}`;
247
+ if (isSelectorUniqueForElement(element, idSelector)) return idSelector;
248
+ }
249
+ for (const attributeName of PREFERRED_SELECTOR_ATTRIBUTE_NAMES) {
250
+ const attributeValue = element.getAttribute(attributeName);
251
+ if (!attributeValue) continue;
252
+ if (!isPreferredAttributeValueSafe(attributeValue)) continue;
253
+ const attributeOnlySelector = `[${attributeName}=${JSON.stringify(attributeValue)}]`;
254
+ if (isSelectorUniqueForElement(element, attributeOnlySelector)) return attributeOnlySelector;
255
+ const tagSelector = `${element.tagName.toLowerCase()}${attributeOnlySelector}`;
256
+ if (isSelectorUniqueForElement(element, tagSelector)) return tagSelector;
257
+ }
258
+ return null;
259
+ };
260
+ const createNthChildSelector = (element) => {
261
+ const segments = [];
262
+ const root = getFinderRoot(element);
263
+ let currentElement = element;
264
+ while (currentElement) {
265
+ if (currentElement instanceof HTMLElement && currentElement.id) {
266
+ segments.unshift(`#${escapeCssIdentifier(currentElement.id)}`);
267
+ break;
268
+ }
269
+ const parentElement = currentElement.parentElement;
270
+ if (!parentElement) {
271
+ segments.unshift(currentElement.tagName.toLowerCase());
272
+ break;
273
+ }
274
+ const siblingIndex = Array.from(parentElement.children).indexOf(currentElement);
275
+ const nthChild = siblingIndex >= 0 ? siblingIndex + 1 : 1;
276
+ segments.unshift(`${currentElement.tagName.toLowerCase()}:nth-child(${nthChild})`);
277
+ if (parentElement === root) {
278
+ segments.unshift(root.tagName.toLowerCase());
279
+ break;
280
+ }
281
+ currentElement = parentElement;
282
+ }
283
+ return segments.join(" > ");
284
+ };
285
+ const createElementSelector = (element, shouldUseFinder = true) => {
286
+ const fastSelector = createFastElementSelector(element);
287
+ if (fastSelector) return fastSelector;
288
+ if (shouldUseFinder) try {
289
+ const selector = findUniqueSelector(element, getFinderRoot(element), 200, (attributeName, attributeValue) => isAcceptedAttr(attributeName, attributeValue) || PREFERRED_SELECTOR_ATTRIBUTE_NAMES.has(attributeName) && isPreferredAttributeValueSafe(attributeValue));
290
+ if (selector) return selector;
291
+ } catch {}
292
+ return createNthChildSelector(element);
293
+ };
294
+
295
+ //#endregion
296
+ Object.defineProperty(exports, 'copyContent', {
297
+ enumerable: true,
298
+ get: function () {
299
+ return copyContent;
300
+ }
301
+ });
302
+ Object.defineProperty(exports, 'createElementSelector', {
303
+ enumerable: true,
304
+ get: function () {
305
+ return createElementSelector;
306
+ }
307
+ });
@@ -0,0 +1,307 @@
1
+ /**
2
+ * @license MIT
3
+ *
4
+ * Copyright (c) 2025 Aiden Bai
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE file in the root directory of this source tree.
8
+ */
9
+ const require_freeze_updates = require('./freeze-updates-1bWq0iRj.cjs');
10
+
11
+ //#region src/utils/copy-content.ts
12
+ const REACT_GRAB_MIME_TYPE = "application/x-react-grab";
13
+ const escapeHtml = (text) => text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
14
+ const copyContent = (content, options) => {
15
+ const elementName = options?.componentName ?? "div";
16
+ const reactGrabMetadata = {
17
+ version: require_freeze_updates.VERSION,
18
+ content,
19
+ entries: options?.entries ?? [{
20
+ tagName: options?.tagName,
21
+ componentName: elementName,
22
+ content,
23
+ commentText: options?.commentText
24
+ }],
25
+ timestamp: Date.now()
26
+ };
27
+ const copyHandler = (event) => {
28
+ event.preventDefault();
29
+ event.clipboardData?.setData("text/plain", content);
30
+ event.clipboardData?.setData("text/html", `<meta charset='utf-8'><pre><code>${escapeHtml(content)}</code></pre>`);
31
+ event.clipboardData?.setData(REACT_GRAB_MIME_TYPE, JSON.stringify(reactGrabMetadata));
32
+ };
33
+ document.addEventListener("copy", copyHandler);
34
+ const textarea = document.createElement("textarea");
35
+ textarea.value = content;
36
+ textarea.style.position = "fixed";
37
+ textarea.style.left = "-9999px";
38
+ textarea.ariaHidden = "true";
39
+ document.body.appendChild(textarea);
40
+ textarea.select();
41
+ try {
42
+ if (typeof document.execCommand !== "function") return false;
43
+ return document.execCommand("copy");
44
+ } finally {
45
+ document.removeEventListener("copy", copyHandler);
46
+ textarea.remove();
47
+ }
48
+ };
49
+
50
+ //#endregion
51
+ //#region src/utils/find-unique-selector.ts
52
+ const SEED_MIN_LENGTH = 3;
53
+ const ATTR_VALUE_MAX_LENGTH_CHARS = 100;
54
+ const PENALTY_ID = 0;
55
+ const PENALTY_CLASS = 1;
56
+ const PENALTY_ATTR = 2;
57
+ const PENALTY_TAG = 5;
58
+ const PENALTY_NTH_OF_TYPE = 10;
59
+ const PENALTY_NTH_CHILD = 50;
60
+ const ACCEPTED_ATTR_NAMES = new Set([
61
+ "role",
62
+ "name",
63
+ "aria-label",
64
+ "rel",
65
+ "href"
66
+ ]);
67
+ const isWordLike = (text) => {
68
+ if (!/^[a-z-]{3,}$/i.test(text)) return false;
69
+ const segments = text.split(/-|[A-Z]/);
70
+ for (const segment of segments) {
71
+ if (segment.length <= 2) return false;
72
+ if (/[^aeiou]{4,}/i.test(segment)) return false;
73
+ }
74
+ return true;
75
+ };
76
+ const isAcceptedAttr = (attributeName, attributeValue) => {
77
+ const nameIsAccepted = ACCEPTED_ATTR_NAMES.has(attributeName) || attributeName.startsWith("data-") && isWordLike(attributeName);
78
+ const valueIsAccepted = isWordLike(attributeValue) && attributeValue.length < ATTR_VALUE_MAX_LENGTH_CHARS || attributeValue.startsWith("#") && isWordLike(attributeValue.slice(1));
79
+ return nameIsAccepted && valueIsAccepted;
80
+ };
81
+ const buildSelectorString = (path) => {
82
+ let result = path[0].name;
83
+ for (let index = 1; index < path.length; index++) result = `${path[index].name} > ${result}`;
84
+ return result;
85
+ };
86
+ const calculatePenalty = (path) => {
87
+ let total = 0;
88
+ for (const selectorNode of path) total += selectorNode.penalty;
89
+ return total;
90
+ };
91
+ const comparePenalty = (pathA, pathB) => calculatePenalty(pathA) - calculatePenalty(pathB);
92
+ const getChildIndex = (element, filterTagName) => {
93
+ const parentNode = element.parentNode;
94
+ if (!parentNode) return void 0;
95
+ let sibling = parentNode.firstChild;
96
+ if (!sibling) return void 0;
97
+ let position = 0;
98
+ while (sibling) {
99
+ if (sibling.nodeType === Node.ELEMENT_NODE && (filterTagName === void 0 || sibling.tagName.toLowerCase() === filterTagName)) position++;
100
+ if (sibling === element) break;
101
+ sibling = sibling.nextSibling;
102
+ }
103
+ return position;
104
+ };
105
+ const formatNthChild = (tagName, childPosition) => tagName === "html" ? "html" : `${tagName}:nth-child(${childPosition})`;
106
+ const formatNthOfType = (tagName, typePosition) => tagName === "html" ? "html" : `${tagName}:nth-of-type(${typePosition})`;
107
+ const collectCandidateNodes = (element, attrFilter) => {
108
+ const candidates = [];
109
+ const elementId = element.getAttribute("id");
110
+ const elementTagName = element.tagName.toLowerCase();
111
+ if (elementId && isWordLike(elementId)) candidates.push({
112
+ name: `#${CSS.escape(elementId)}`,
113
+ penalty: PENALTY_ID
114
+ });
115
+ for (const className of element.classList) if (isWordLike(className)) candidates.push({
116
+ name: `.${CSS.escape(className)}`,
117
+ penalty: PENALTY_CLASS
118
+ });
119
+ for (const attribute of element.attributes) if (attrFilter(attribute.name, attribute.value)) candidates.push({
120
+ name: `[${CSS.escape(attribute.name)}="${CSS.escape(attribute.value)}"]`,
121
+ penalty: PENALTY_ATTR
122
+ });
123
+ candidates.push({
124
+ name: elementTagName,
125
+ penalty: PENALTY_TAG
126
+ });
127
+ const typePosition = getChildIndex(element, elementTagName);
128
+ if (typePosition !== void 0) candidates.push({
129
+ name: formatNthOfType(elementTagName, typePosition),
130
+ penalty: PENALTY_NTH_OF_TYPE
131
+ });
132
+ const childPosition = getChildIndex(element);
133
+ if (childPosition !== void 0) candidates.push({
134
+ name: formatNthChild(elementTagName, childPosition),
135
+ penalty: PENALTY_NTH_CHILD
136
+ });
137
+ return candidates;
138
+ };
139
+ const collectCombinations = (stack, budget = require_freeze_updates.MAX_SELECTOR_COMBINATIONS, currentPath = []) => {
140
+ if (budget <= 0) return [];
141
+ if (stack.length === 0) return [currentPath];
142
+ const results = [];
143
+ for (const selectorNode of stack[0]) {
144
+ const remainingBudget = budget - results.length;
145
+ if (remainingBudget <= 0) break;
146
+ results.push(...collectCombinations(stack.slice(1), remainingBudget, [...currentPath, selectorNode]));
147
+ }
148
+ return results;
149
+ };
150
+ const resolveRootDocument = (rootNode, targetElement) => {
151
+ const attachedRoot = targetElement.getRootNode?.();
152
+ if (attachedRoot instanceof ShadowRoot) return attachedRoot;
153
+ if (rootNode.nodeType === Node.DOCUMENT_NODE) return rootNode;
154
+ return rootNode.ownerDocument;
155
+ };
156
+ const isSelectorUnique = (selectorPath, rootDocument) => rootDocument.querySelectorAll(buildSelectorString(selectorPath)).length === 1;
157
+ const buildFallbackPath = (targetElement, rootDocument) => {
158
+ let currentElement = targetElement;
159
+ const path = [];
160
+ while (currentElement && currentElement !== rootDocument) {
161
+ const currentTagName = currentElement.tagName.toLowerCase();
162
+ const typePosition = getChildIndex(currentElement, currentTagName);
163
+ if (typePosition === void 0) return void 0;
164
+ path.push({
165
+ name: formatNthOfType(currentTagName, typePosition),
166
+ penalty: PENALTY_NTH_OF_TYPE
167
+ });
168
+ currentElement = currentElement.parentElement;
169
+ }
170
+ return isSelectorUnique(path, rootDocument) ? path : void 0;
171
+ };
172
+ const findUniqueSelector = (targetElement, root, timeoutMs, attrFilter) => {
173
+ if (targetElement.nodeType !== Node.ELEMENT_NODE) throw new Error("Can't generate CSS selector for non-element node type.");
174
+ if (targetElement.tagName.toLowerCase() === "html") return "html";
175
+ const rootDocument = resolveRootDocument(root, targetElement);
176
+ const startTime = Date.now();
177
+ const ancestorStack = [];
178
+ let currentElement = targetElement;
179
+ let depth = 0;
180
+ let foundPath;
181
+ while (currentElement && currentElement !== rootDocument && !foundPath) {
182
+ ancestorStack.push(collectCandidateNodes(currentElement, attrFilter));
183
+ currentElement = currentElement.parentElement;
184
+ depth++;
185
+ if (depth >= SEED_MIN_LENGTH) {
186
+ const candidatePaths = collectCombinations(ancestorStack);
187
+ candidatePaths.sort(comparePenalty);
188
+ for (const candidatePath of candidatePaths) {
189
+ if (Date.now() - startTime > timeoutMs) {
190
+ const fallbackPath = buildFallbackPath(targetElement, rootDocument);
191
+ if (!fallbackPath) throw new Error(`Timeout: Can't find a unique selector after ${timeoutMs}ms`);
192
+ return buildSelectorString(fallbackPath);
193
+ }
194
+ if (isSelectorUnique(candidatePath, rootDocument)) {
195
+ foundPath = candidatePath;
196
+ break;
197
+ }
198
+ }
199
+ }
200
+ }
201
+ if (!foundPath && depth < SEED_MIN_LENGTH) {
202
+ const remainingPaths = collectCombinations(ancestorStack);
203
+ remainingPaths.sort(comparePenalty);
204
+ for (const candidatePath of remainingPaths) {
205
+ if (Date.now() - startTime > timeoutMs) break;
206
+ if (isSelectorUnique(candidatePath, rootDocument)) {
207
+ foundPath = candidatePath;
208
+ break;
209
+ }
210
+ }
211
+ }
212
+ if (!foundPath) throw new Error("Selector was not found.");
213
+ return buildSelectorString(foundPath);
214
+ };
215
+
216
+ //#endregion
217
+ //#region src/utils/create-element-selector.ts
218
+ const escapeCssIdentifier = (value) => {
219
+ if (typeof CSS !== "undefined" && typeof CSS.escape === "function") return CSS.escape(value);
220
+ return value.replace(/[^a-zA-Z0-9_-]/g, (character) => `\\${character}`);
221
+ };
222
+ const getFinderRoot = (element) => element.ownerDocument.body ?? element.ownerDocument.documentElement;
223
+ const PREFERRED_SELECTOR_ATTRIBUTE_NAMES = new Set([
224
+ "data-testid",
225
+ "data-test-id",
226
+ "data-test",
227
+ "data-cy",
228
+ "data-qa",
229
+ "aria-label",
230
+ "role",
231
+ "name",
232
+ "title",
233
+ "alt"
234
+ ]);
235
+ const isPreferredAttributeValueSafe = (value) => value.length > 0 && value.length <= 120;
236
+ const isSelectorUniqueForElement = (element, selector) => {
237
+ try {
238
+ const matchingElements = element.ownerDocument.querySelectorAll(selector);
239
+ return matchingElements.length === 1 && matchingElements[0] === element;
240
+ } catch {
241
+ return false;
242
+ }
243
+ };
244
+ const createFastElementSelector = (element) => {
245
+ if (element instanceof HTMLElement && element.id) {
246
+ const idSelector = `#${escapeCssIdentifier(element.id)}`;
247
+ if (isSelectorUniqueForElement(element, idSelector)) return idSelector;
248
+ }
249
+ for (const attributeName of PREFERRED_SELECTOR_ATTRIBUTE_NAMES) {
250
+ const attributeValue = element.getAttribute(attributeName);
251
+ if (!attributeValue) continue;
252
+ if (!isPreferredAttributeValueSafe(attributeValue)) continue;
253
+ const attributeOnlySelector = `[${attributeName}=${JSON.stringify(attributeValue)}]`;
254
+ if (isSelectorUniqueForElement(element, attributeOnlySelector)) return attributeOnlySelector;
255
+ const tagSelector = `${element.tagName.toLowerCase()}${attributeOnlySelector}`;
256
+ if (isSelectorUniqueForElement(element, tagSelector)) return tagSelector;
257
+ }
258
+ return null;
259
+ };
260
+ const createNthChildSelector = (element) => {
261
+ const segments = [];
262
+ const root = getFinderRoot(element);
263
+ let currentElement = element;
264
+ while (currentElement) {
265
+ if (currentElement instanceof HTMLElement && currentElement.id) {
266
+ segments.unshift(`#${escapeCssIdentifier(currentElement.id)}`);
267
+ break;
268
+ }
269
+ const parentElement = currentElement.parentElement;
270
+ if (!parentElement) {
271
+ segments.unshift(currentElement.tagName.toLowerCase());
272
+ break;
273
+ }
274
+ const siblingIndex = Array.from(parentElement.children).indexOf(currentElement);
275
+ const nthChild = siblingIndex >= 0 ? siblingIndex + 1 : 1;
276
+ segments.unshift(`${currentElement.tagName.toLowerCase()}:nth-child(${nthChild})`);
277
+ if (parentElement === root) {
278
+ segments.unshift(root.tagName.toLowerCase());
279
+ break;
280
+ }
281
+ currentElement = parentElement;
282
+ }
283
+ return segments.join(" > ");
284
+ };
285
+ const createElementSelector = (element, shouldUseFinder = true) => {
286
+ const fastSelector = createFastElementSelector(element);
287
+ if (fastSelector) return fastSelector;
288
+ if (shouldUseFinder) try {
289
+ const selector = findUniqueSelector(element, getFinderRoot(element), 200, (attributeName, attributeValue) => isAcceptedAttr(attributeName, attributeValue) || PREFERRED_SELECTOR_ATTRIBUTE_NAMES.has(attributeName) && isPreferredAttributeValueSafe(attributeValue));
290
+ if (selector) return selector;
291
+ } catch {}
292
+ return createNthChildSelector(element);
293
+ };
294
+
295
+ //#endregion
296
+ Object.defineProperty(exports, 'copyContent', {
297
+ enumerable: true,
298
+ get: function () {
299
+ return copyContent;
300
+ }
301
+ });
302
+ Object.defineProperty(exports, 'createElementSelector', {
303
+ enumerable: true,
304
+ get: function () {
305
+ return createElementSelector;
306
+ }
307
+ });