-
Notifications
You must be signed in to change notification settings - Fork 149
chore: merge to 0.81-stable merge base #2733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| const hasValidReproducer = entities.some(entity => { | ||
| const hasPullRequestRepoLink = containsPattern( | ||
| entity.body, | ||
| `https?:\/\/github\.com\/facebook\/react-native\/pull\/\d+\/?`, |
Check failure
Code scanning / CodeQL
Useless regular-expression character escape High
regular expression
| const hasValidReproducer = entities.some(entity => { | ||
| const hasPullRequestRepoLink = containsPattern( | ||
| entity.body, | ||
| `https?:\/\/github\.com\/facebook\/react-native\/pull\/\d+\/?`, |
Check failure
Code scanning / CodeQL
Useless regular-expression character escape High
regular expression
| @@ -1 +1 @@ | |||
| function e(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function t(r,n,o,i,a,s){if(i<=o)return;const l=function(t,r,n,o,i){const a=t[i];e(t,o,i);let s=n;for(let i=n;i<o;++i)r(t[i],a)<0&&(e(t,s,i),++s);return e(t,o,s),s}(r,n,o,i,Math.floor(Math.random()*(i-o))+o);a<l&&t(r,n,o,l-1,a,s),l<s&&t(r,n,l+1,i,a,s)}function r(e,t,r,n){const o=[];let i=0,a=0;for(;i<e.length&&a<t.length;){const s=r(e[i],t[a]);!n&&s||o.push(s<=0?e[i]:t[a]),s<=0&&i++,s>=0&&a++}if(n){for(;i<e.length;)o.push(e[i++]);for(;a<t.length;)o.push(t[a++])}return o}function n(e,t,r,n,o){let i=n||0,a=void 0!==o?o:e.length;for(;i<a;){const n=i+a>>1;r(t,e[n])>0?i=n+1:a=n}return a}function o(e,t,r){const n="END"===r;if(0===e.length)return null;let o=0,i=e.length-1,a=0,s=!1,l=!1,u=0;do{u=o+(i-o)/2,a=n?Math.ceil(u):Math.floor(u),s=t(e[a]),l=s===n,l?o=Math.min(i,a+(o===a?1:0)):i=Math.max(o,a+(i===a?-1:0))}while(i!==o);return t(e[o])?o:null}var i=Object.freeze({__proto__:null,removeElement:(e,t,r)=>{let n=e.indexOf(t);if(-1===n)return!1;if(r)return e.splice(n,1),!0;for(let r=n+1,o=e.length;r<o;++r)e[r]!==t&&(e[n++]=e[r]);return e.length=n,!0},sortRange:function(e,r,n,o,i,a){return 0===n&&o===e.length-1&&0===i&&a>=o?e.sort(r):t(e,r,n,o,i,a),e},binaryIndexOf:(e,t,r)=>{const o=n(e,t,r);return o<e.length&&0===r(t,e[o])?o:-1},intersectOrdered:(e,t,n)=>r(e,t,n,!1),mergeOrdered:(e,t,n)=>r(e,t,n,!0),DEFAULT_COMPARATOR:(e,t)=>e<t?-1:e>t?1:0,lowerBound:n,upperBound:function(e,t,r,n,o){let i=n||0,a=void 0!==o?o:e.length;for(;i<a;){const n=i+a>>1;r(t,e[n])>=0?i=n+1:a=n}return a},nearestIndexFromBeginning:function(e,t){return o(e,t,"BEGINNING")},nearestIndexFromEnd:function(e,t){return o(e,t,"END")},arrayDoesNotContainNullOrUndefined:function(e){return!e.includes(null)&&!e.includes(void 0)}}),a=Object.freeze({__proto__:null});var s=Object.freeze({__proto__:null,isValid:e=>!isNaN(e.getTime()),toISO8601Compact:e=>{function t(e){return(e>9?"":"0")+e}return e.getFullYear()+t(e.getMonth()+1)+t(e.getDate())+"T"+t(e.getHours())+t(e.getMinutes())+t(e.getSeconds())}});var l=Object.freeze({__proto__:null,EmptyUrlString:"",EmptyRawPathString:"",EmptyEncodedPathString:""});var u=Object.freeze({__proto__:null,deepActiveElement:function(e){let t=e.activeElement;for(;t&&t.shadowRoot&&t.shadowRoot.activeElement;)t=t.shadowRoot.activeElement;return t},getEnclosingShadowRootForNode:function(e){let t=e.parentNodeOrShadowHost();for(;t;){if(t instanceof ShadowRoot)return t;t=t.parentNodeOrShadowHost()}return null},rangeOfWord:function(e,t,r,n,o){let i,a,s=0,l=0;if(n||(n=e),o&&"backward"!==o&&"both"!==o)i=e,s=t;else{let o=e;for(;o;){if(o===n){i||(i=n);break}if(o.nodeType===Node.TEXT_NODE&&null!==o.nodeValue){for(let n=o===e?t-1:o.nodeValue.length-1;n>=0;--n)if(-1!==r.indexOf(o.nodeValue[n])){i=o,s=n+1;break}}if(i)break;o=o.traversePreviousNode(n)}i||(i=n,s=0)}if(o&&"forward"!==o&&"both"!==o)a=e,l=t;else{let o=e;for(;o;){if(o===n){a||(a=n);break}if(o.nodeType===Node.TEXT_NODE&&null!==o.nodeValue){for(let n=o===e?t:0;n<o.nodeValue.length;++n)if(-1!==r.indexOf(o.nodeValue[n])){a=o,l=n;break}}if(a)break;o=o.traverseNextNode(n)}a||(a=n,l=n.nodeType===Node.TEXT_NODE?n.nodeValue?.length||0:n.childNodes.length)}if(!e.ownerDocument)throw new Error("No `ownerDocument` found for rootNode");const u=e.ownerDocument.createRange();return u.setStart(i,s),u.setEnd(a,l),u}});const c=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]);var f=Object.freeze({__proto__:null,ENTER_KEY:"Enter",ESCAPE_KEY:"Escape",TAB_KEY:"Tab",ARROW_KEYS:c,keyIsArrowKey:function(e){return c.has(e)},isEscKey:function(e){return"Escape"===e.key},isEnterOrSpaceKey:function(e){return"Enter"===e.key||" "===e.key}});class h{map=new Map;set(e,t){let r=this.map.get(e);r||(r=new Set,this.map.set(e,r)),r.add(t)}get(e){return this.map.get(e)||new Set}has(e){return this.map.has(e)}hasValue(e,t){const r=this.map.get(e);return!!r&&r.has(t)}get size(){return this.map.size}delete(e,t){const r=this.get(e);if(!r)return!1;const n=r.delete(t);return r.size||this.map.delete(e),n}deleteAll(e){this.map.delete(e)}keysArray(){return[...this.map.keys()]}keys(){return this.map.keys()}valuesArray(){const e=[];for(const t of this.map.values())e.push(...t.values());return e}clear(){this.map.clear()}}var p=Object.freeze({__proto__:null,inverse:function(e){const t=new h;for(const[r,n]of e.entries())t.set(n,r);return t},Multimap:h,getWithDefault:function(e,t,r){let n=e.get(t);return n||(n=r(t),e.set(t,n)),n}});const d=new Set(["application/ecmascript","application/javascript","application/json","application/json+protobuf","application/vnd.dart","application/xml","application/x-aspx","application/x-javascript","application/x-jsp","application/x-httpd-php"]);function g(e,t,r=0){for(let n=r;n<e.length;n++)if(t.includes(e[n]))return n;return-1}function m(e,t,r=0){for(let n=r;n<e.length;n++)if(!t.includes(e[n]))return n;return-1}var b=Object.freeze({__proto__:null,isTextType:function(e){return e.startsWith("text/")||e.endsWith("+json")||e.endsWith("+xml")||d.has(e)},parseContentType:function(e){if("*/*"===e)return{mimeType:null,charset:null};const{mimeType:t,params:r}=function(e){e=e.trim();let t=g(e," \t;(");t<0&&(t=e.length);const r=e.indexOf("/");if(r<0||r>t)return{mimeType:null,params:new Map};const n=e.substring(0,t).toLowerCase(),o=new Map;let i=e.indexOf(";",t);for(;i>=0&&i<e.length;){if(++i,i=m(e," \t",i),i<0)continue;const t=i;if(i=g(e,";=",i),i<0||";"===e[i])continue;const r=e.substring(t,i).toLowerCase();++i,i=m(e," \t",i);let n="";if(!(i<0||";"===e[i])){if('"'!==e[i]){const t=i;i=e.indexOf(";",i);const r=i>=0?i:e.length;n=e.substring(t,r).trimEnd()}else{for(++i;i<e.length&&'"'!==e[i];)"\\"===e[i]&&i+1<e.length&&++i,n+=e[i],++i;i=e.indexOf(";",i)}o.has(r)||o.set(r,n)}}return{mimeType:n,params:o}}(e);return{mimeType:t,charset:r.get("charset")?.toLowerCase().trim()??null}}});const w=(e,t)=>{for(e=Math.round(e),t=Math.round(t);0!==t;){const r=t;t=e%t,e=r}return e},x=new Map([["8∶5","16∶10"]]);var _=Object.freeze({__proto__:null,clamp:(e,t,r)=>{let n=e;return e<t?n=t:e>r&&(n=r),n},mod:(e,t)=>(e%t+t)%t,bytesToString:e=>{if(e<1e3)return`${e.toFixed(0)} B`;const t=e/1e3;if(t<100)return`${t.toFixed(1)} kB`;if(t<1e3)return`${t.toFixed(0)} kB`;const r=t/1e3;return r<100?`${r.toFixed(1)} MB`:`${r.toFixed(0)} MB`},toFixedIfFloating:e=>{if(!e||Number.isNaN(Number(e)))return e;const t=Number(e);return t%1?t.toFixed(3):String(t)},floor:(e,t=0)=>{const r=Math.pow(10,t);return Math.floor(e*r)/r},greatestCommonDivisor:w,aspectRatio:(e,t)=>{const r=w(e,t);0!==r&&(e/=r,t/=r);const n=`${e}∶${t}`;return x.get(n)||n},withThousandsSeparator:function(e){let t=String(e);const r=/(\d+)(\d{3})/;for(;t.match(r);)t=t.replace(r,"$1 $2");return t}});var E=Object.freeze({__proto__:null,promiseWithResolvers:function(){let e,t;return{promise:new Promise(((r,n)=>{e=r,t=n})),resolve:e,reject:t}}});const O=(e,t)=>{let r=!1;for(let n=0;n<t.length;++n)if(-1!==e.indexOf(t.charAt(n))){r=!0;break}if(!r)return String(e);let n="";for(let r=0;r<e.length;++r)-1!==t.indexOf(e.charAt(r))&&(n+="\\"),n+=e.charAt(r);return n},N=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),y=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),A=(e,t)=>{const r=[];let n=e.indexOf(t);for(;-1!==n;)r.push(n),n=e.indexOf(t,n+t.length);return r},v=/^([a-z0-9]+(?:-[a-z0-9]+)*\.)*[a-z0-9]+(?:-[a-z0-9]+)*$/,S="^[]{}()\\.^$*+?|-,",C=function(){return S},T=function(e,t){let r="";for(let t=0;t<e.length;++t){const n=e.charAt(t);-1!==C().indexOf(n)&&(r+="\\"),r+=n}return new RegExp(r,t||"")};const U=/[A-Z]{2,}(?=[A-Z0-9][a-z0-9]+|\b|_)|[A-Za-z][0-9]+[a-z]?|[A-Z]?[a-z]+|[0-9][A-Za-z]+|[A-Z]|[0-9]+|[.]/g,M=function(e){return e.match?.(U)?.map((e=>e.toLowerCase())).join("-").replaceAll("-.-",".")||e};var R=Object.freeze({__proto__:null,escapeCharacters:O,formatAsJSLiteral:e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=(e,t,r,n)=>{if(r){if(y.has(r))return y.get(r);return"\\x"+N(r.charCodeAt(0),2)}if(n){return"\\u"+N(n.charCodeAt(0),4)}return t?y.get(t)||"":e};let o="",i="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(i="'",o=e.replaceAll(r,n)):(i="`",o=e.replaceAll(t,n)):(i='"',o=e.replaceAll(t,n)):(i="'",o=e.replaceAll(t,n)),`${i}${o}${i}`},sprintf:(e,...t)=>{let r=0;return e.replaceAll(/%(?:(\d+)\$)?(?:\.(\d*))?([%dfs])/g,((e,n,o,i)=>{if("%"===i)return"%";if(void 0!==n&&(r=parseInt(n,10)-1,r<0))throw new RangeError(`Invalid parameter index ${r+1}`);if(r>=t.length)throw new RangeError(`Expected at least ${r+1} format parameters, but only ${t.length} where given.`);if("s"===i){const e=String(t[r++]);return void 0!==o?e.substring(0,Number(o)):e}let a=Number(t[r++]);return isNaN(a)&&(a=0),"d"===i?String(Math.floor(a)).padStart(Number(o),"0"):void 0!==o?a.toFixed(Number(o)):String(a)}))},toBase64:e=>{function t(e){return e<26?e+65:e<52?e+71:e<62?e-4:62===e?43:63===e?47:65}const r=(new TextEncoder).encode(e.toString()),n=r.length;let o,i="";if(0===n)return i;let a=0;for(let e=0;e<n;e++)o=e%3,a|=r[e]<<(16>>>o&24),2===o&&(i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),t(a>>>6&63),t(63&a)),a=0);return 0===o?i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),61,61):1===o&&(i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),t(a>>>6&63),61)),i},findIndexesOfSubString:A,findLineEndingIndexes:e=>{const t=A(e,"\n");return t.push(e.length),t},isWhitespace:e=>/^\s*$/.test(e),trimURL:(e,t)=>{let r=e.replace(/^(https|http|file):\/\//i,"");return t&&r.toLowerCase().startsWith(t.toLowerCase())&&(r=r.substr(t.length)),r},collapseWhitespace:e=>e.replace(/[\s\xA0]+/g," "),reverse:e=>e.split("").reverse().join(""),replaceControlCharacters:e=>e.replace(/[\0-\x08\x0B\f\x0E-\x1F\x80-\x9F]/g,"�"),countWtf8Bytes:e=>{let t=0;for(let r=0;r<e.length;r++){const n=e.charCodeAt(r);if(n<=127)t++;else if(n<=2047)t+=2;else if(n<55296||57343<n)t+=3;else{if(n<=56319&&r+1<e.length){const n=e.charCodeAt(r+1);if(56320<=n&&n<=57343){t+=4,r++;continue}}t+=3}}return t},stripLineBreaks:e=>e.replace(/(\r)?\n/g,""),isExtendedKebabCase:e=>v.test(e),toTitleCase:e=>e.substring(0,1).toUpperCase()+e.substring(1),removeURLFragment:e=>{const t=new URL(e);return t.hash="",t.toString()},regexSpecialCharacters:C,filterRegex:function(e){let t="^(?:.*\\0)?";for(let r=0;r<e.length;++r){let n=e.charAt(r);-1!==S.indexOf(n)&&(n="\\"+n),t+="[^\\0"+n+"]*"+n}return new RegExp(t,"i")},createSearchRegex:function(e,t,r,n=!1){const o=t?"g":"gi";let i;if(r)try{i=new RegExp(e,o)}catch(e){}return i||(i=T(e,o)),n&&i&&(i=new RegExp(`\\b${i.source}\\b`,o)),i},caseInsensetiveComparator:function(e,t){return(e=e.toUpperCase())===(t=t.toUpperCase())?0:e>t?1:-1},hashCode:function(e){if(!e)return 0;const t=4294967291;let r=0,n=1;for(let o=0;o<e.length;o++){r=(r+n*(1506996573*e.charCodeAt(o)))%t,n=1345575271*n%t}return r=(r+n*(t-1))%t,Math.abs(0|r)},compare:(e,t)=>e>t?1:e<t?-1:0,trimMiddle:(e,t)=>{if(e.length<=t)return String(e);let r=t>>1,n=t-r-1;return e.codePointAt(e.length-n-1)>=65536&&(--n,++r),r>0&&e.codePointAt(r-1)>=65536&&--r,e.substr(0,r)+"…"+e.substr(e.length-n,n)},trimEndWithMaxLength:(e,t)=>e.length<=t?String(e):e.substr(0,t-1)+"…",escapeForRegExp:e=>O(e,S),naturalOrderComparator:(e,t)=>{const r=/^\d+|^\D+/;let n,o,i,a;for(;;){if(!e)return t?-1:0;if(!t)return 1;if(n=e.match(r)[0],o=t.match(r)[0],i=!Number.isNaN(Number(n)),a=!Number.isNaN(Number(o)),i&&!a)return-1;if(a&&!i)return 1;if(i&&a){const e=Number(n)-Number(o);if(e)return e;if(n.length!==o.length)return Number(n)||Number(o)?o.length-n.length:n.length-o.length}else if(n!==o)return n<o?-1:1;e=e.substring(n.length),t=t.substring(o.length)}},base64ToSize:function(e){if(!e)return 0;let t=3*e.length/4;return"="===e[e.length-1]&&t--,e.length>1&&"="===e[e.length-2]&&t--,t},SINGLE_QUOTE:"'",DOUBLE_QUOTE:'"',findUnclosedCssQuote:function(e){let t="";for(let r=0;r<e.length;++r){const n=e[r];"\\"!==n?"'"!==n&&'"'!==n||(t===n?t="":""===t&&(t=n)):r++}return t},countUnmatchedLeftParentheses:e=>{let t=0;for(const r of e)"("===r?t++:")"===r&&t>0&&t--;return t},createPlainTextSearchRegex:T,toLowerCaseString:function(e){return e.toLowerCase()},toKebabCase:M,toKebabCaseKeys:function(e){const t={};for(const[r,n]of Object.entries(e))t[M(r)]=n;return t},replaceLast:function(e,t,r){const n=e.lastIndexOf(t);return-1===n?e:e.slice(0,n)+e.slice(n).replace(t,r)},stringifyWithPrecision:function(e,t=2){if(0===t)return e.toFixed(0);const r=e.toFixed(t).replace(/\.?0*$/,"");return"-0"===r?"0":r},concatBase64:function(e,t){if(0===e.length||!e.endsWith("="))return e+t;const r=e.substring(0,e.length-4),n=e.substring(e.length-4);return r+window.btoa(window.atob(n)+window.atob(t))}});var z=Object.freeze({__proto__:null,secondsToMilliSeconds:function(e){return 1e3*e},milliSecondsToSeconds:function(e){return e/1e3},microSecondsToMilliSeconds:function(e){return e/1e3}});class L extends Uint32Array{getValue(e){return this[e]}setValue(e,t){this[e]=t}asUint32ArrayOrFail(){return this}asArrayOrFail(){throw new Error("Not an array")}}class j{#e;#t;length;constructor(e,t){this.#e=[],this.length=e;let r=1;for(;;){r*=2,this.#t=Math.ceil(e/r);try{if(void 0!==t&&this.#t>t)throw new RangeError;for(let e=0;e<r;++e)this.#e[e]=new Uint32Array(this.#t);return}catch(e){if(this.#t<1e6)throw e}}}getValue(e){if(e>=0&&e<this.length){const t=this.#t;return this.#e[Math.floor(e/t)][e%t]}return this.#e[0][-1]}setValue(e,t){if(e>=0&&e<this.length){const r=this.#t;this.#e[Math.floor(e/r)][e%r]=t}}asUint32ArrayOrFail(){throw new Error("Not a Uint32Array")}asArrayOrFail(){throw new Error("Not an array")}}class F extends Array{getValue(e){return this[e]}setValue(e,t){this[e]=t}asUint32ArrayOrFail(){throw new Error("Not a Uint32Array")}asArrayOrFail(){return this}}class $ extends Uint8Array{constructor(e){super(Math.ceil(e/8))}getBit(e){return 0!==(this[e>>3]&1<<(7&e))}setBit(e){this[e>>3]|=1<<(7&e)}clearBit(e){this[e>>3]&=~(1<<(7&e))}previous(e){for(;e!==e>>3<<3;)if(--e,this.getBit(e))return e;let t;for(t=(e>>3)-1;t>=0&&0===this[t];--t);if(t<0)return-1;for(e=7+(t<<3);e>=t<<3;--e)if(this.getBit(e))return e;throw new Error("Unreachable")}}var B=Object.freeze({__proto__:null,createExpandableBigUint32Array:function(){return new F},createFixedBigUint32Array:function(e,t){try{if(void 0!==t&&e>t)throw new RangeError;return new L(e)}catch{return new j(e,t)}},createBitVector:function(e){return new $(e)}});function k(e,t){if(null==e)throw new Error(`Expected given value to not be null/undefined but it was: ${e}${t?`\n${t}`:""}`)}function V(e,t){throw new Error(t)}function D(e){return e}var I=Object.freeze({__proto__:null,assertNotNullOrUndefined:k,assertNever:V,assertUnhandled:D});var W=Object.freeze({__proto__:null,LocalizedEmptyString:""});class K extends Error{message;constructor(e){super(e),this.message=e}}var P=Object.freeze({__proto__:null,UserVisibleError:K,isUserVisibleError:function(e){return"object"==typeof e&&null!==e&&e instanceof K}});export{i as ArrayUtilities,a as Brand,u as DOMUtilities,s as DateUtilities,l as DevToolsPath,f as KeyboardUtilities,p as MapUtilities,b as MimeType,_ as NumberUtilities,E as PromiseUtilities,R as StringUtilities,z as Timing,I as TypeScriptUtilities,B as TypedArrayUtilities,W as UIString,P as UserVisibleError,V as assertNever,k as assertNotNullOrUndefined,D as assertUnhandled}; | |||
| function e(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function t(r,n,o,i,a,s){if(i<=o)return;const l=function(t,r,n,o,i){const a=t[i];e(t,o,i);let s=n;for(let i=n;i<o;++i)r(t[i],a)<0&&(e(t,s,i),++s);return e(t,o,s),s}(r,n,o,i,Math.floor(Math.random()*(i-o))+o);a<l&&t(r,n,o,l-1,a,s),l<s&&t(r,n,l+1,i,a,s)}function r(e,t,r,n){const o=[];let i=0,a=0;for(;i<e.length&&a<t.length;){const s=r(e[i],t[a]);!n&&s||o.push(s<=0?e[i]:t[a]),s<=0&&i++,s>=0&&a++}if(n){for(;i<e.length;)o.push(e[i++]);for(;a<t.length;)o.push(t[a++])}return o}function n(e,t,r,n,o){let i=n||0,a=void 0!==o?o:e.length;for(;i<a;){const n=i+a>>1;r(t,e[n])>0?i=n+1:a=n}return a}function o(e,t,r){const n="END"===r;if(0===e.length)return null;let o=0,i=e.length-1,a=0,s=!1,l=!1,u=0;do{u=o+(i-o)/2,a=n?Math.ceil(u):Math.floor(u),s=t(e[a]),l=s===n,l?o=Math.min(i,a+(o===a?1:0)):i=Math.max(o,a+(i===a?-1:0))}while(i!==o);return t(e[o])?o:null}var i=Object.freeze({__proto__:null,DEFAULT_COMPARATOR:(e,t)=>e<t?-1:e>t?1:0,arrayDoesNotContainNullOrUndefined:function(e){return!e.includes(null)&&!e.includes(void 0)},binaryIndexOf:(e,t,r)=>{const o=n(e,t,r);return o<e.length&&0===r(t,e[o])?o:-1},intersectOrdered:(e,t,n)=>r(e,t,n,!1),lowerBound:n,mergeOrdered:(e,t,n)=>r(e,t,n,!0),nearestIndexFromBeginning:function(e,t){return o(e,t,"BEGINNING")},nearestIndexFromEnd:function(e,t){return o(e,t,"END")},removeElement:(e,t,r)=>{let n=e.indexOf(t);if(-1===n)return!1;if(r)return e.splice(n,1),!0;for(let r=n+1,o=e.length;r<o;++r)e[r]!==t&&(e[n++]=e[r]);return e.length=n,!0},sortRange:function(e,r,n,o,i,a){return 0===n&&o===e.length-1&&0===i&&a>=o?e.sort(r):t(e,r,n,o,i,a),e},upperBound:function(e,t,r,n,o){let i=n||0,a=void 0!==o?o:e.length;for(;i<a;){const n=i+a>>1;r(t,e[n])>=0?i=n+1:a=n}return a}}),a=Object.freeze({__proto__:null}),s=Object.freeze({__proto__:null});var l=Object.freeze({__proto__:null,isValid:e=>!isNaN(e.getTime()),toISO8601Compact:e=>{function t(e){return(e>9?"":"0")+e}return e.getFullYear()+t(e.getMonth()+1)+t(e.getDate())+"T"+t(e.getHours())+t(e.getMinutes())+t(e.getSeconds())}});var u=Object.freeze({__proto__:null,EmptyEncodedPathString:"",EmptyRawPathString:"",EmptyUrlString:"",urlString:(e,...t)=>String.raw({raw:e},...t)});var c=Object.freeze({__proto__:null,deepActiveElement:function(e){let t=e.activeElement;for(;t?.shadowRoot?.activeElement;)t=t.shadowRoot.activeElement;return t},getEnclosingShadowRootForNode:function(e){let t=e.parentNodeOrShadowHost();for(;t;){if(t instanceof ShadowRoot)return t;t=t.parentNodeOrShadowHost()}return null},rangeOfWord:function(e,t,r,n,o){let i,a,s=0,l=0;if(n||(n=e),o&&"backward"!==o&&"both"!==o)i=e,s=t;else{let o=e;for(;o;){if(o===n){i||(i=n);break}if(o.nodeType===Node.TEXT_NODE&&null!==o.nodeValue){for(let n=o===e?t-1:o.nodeValue.length-1;n>=0;--n)if(-1!==r.indexOf(o.nodeValue[n])){i=o,s=n+1;break}}if(i)break;o=o.traversePreviousNode(n)}i||(i=n,s=0)}if(o&&"forward"!==o&&"both"!==o)a=e,l=t;else{let o=e;for(;o;){if(o===n){a||(a=n);break}if(o.nodeType===Node.TEXT_NODE&&null!==o.nodeValue){for(let n=o===e?t:0;n<o.nodeValue.length;++n)if(-1!==r.indexOf(o.nodeValue[n])){a=o,l=n;break}}if(a)break;o=o.traverseNextNode(n)}a||(a=n,l=n.nodeType===Node.TEXT_NODE?n.nodeValue?.length||0:n.childNodes.length)}if(!e.ownerDocument)throw new Error("No `ownerDocument` found for rootNode");const u=e.ownerDocument.createRange();return u.setStart(i,s),u.setEnd(a,l),u}});const f=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]);var h=Object.freeze({__proto__:null,ARROW_KEYS:f,ENTER_KEY:"Enter",ESCAPE_KEY:"Escape",TAB_KEY:"Tab",isEnterOrSpaceKey:function(e){return"Enter"===e.key||" "===e.key},isEscKey:function(e){return"Escape"===e.key},keyIsArrowKey:function(e){return f.has(e)}});class p{map=new Map;set(e,t){let r=this.map.get(e);r||(r=new Set,this.map.set(e,r)),r.add(t)}get(e){return this.map.get(e)||new Set}has(e){return this.map.has(e)}hasValue(e,t){const r=this.map.get(e);return!!r&&r.has(t)}get size(){return this.map.size}delete(e,t){const r=this.get(e);if(!r)return!1;const n=r.delete(t);return r.size||this.map.delete(e),n}deleteAll(e){this.map.delete(e)}keysArray(){return[...this.map.keys()]}keys(){return this.map.keys()}valuesArray(){const e=[];for(const t of this.map.values())e.push(...t.values());return e}clear(){this.map.clear()}}var g=Object.freeze({__proto__:null,Multimap:p,getWithDefault:function(e,t,r){let n=e.get(t);return null==n&&(n=r(t),e.set(t,n)),n},inverse:function(e){const t=new p;for(const[r,n]of e.entries())t.set(n,r);return t}});const d=new Set(["application/ecmascript","application/javascript","application/json","application/json+protobuf","application/mpegurl","application/vnd.apple.mpegurl","application/vnd.dart","application/xml","application/x-aspx","application/x-javascript","application/x-jsp","application/x-httpd-php","application/x-mpegurl","audio/mpegurl","audio/x-mpegurl"]);function m(e,t,r=0){for(let n=r;n<e.length;n++)if(t.includes(e[n]))return n;return-1}function b(e,t,r=0){for(let n=r;n<e.length;n++)if(!t.includes(e[n]))return n;return-1}var w=Object.freeze({__proto__:null,isTextType:function(e){return e.startsWith("text/")||e.startsWith("multipart/")||e.includes("+json")||e.endsWith("+xml")||d.has(e)},parseContentType:function(e){if("*/*"===e)return{mimeType:null,charset:null};const{mimeType:t,params:r}=function(e){e=e.trim();let t=m(e," \t;(");t<0&&(t=e.length);const r=e.indexOf("/");if(r<0||r>t)return{mimeType:null,params:new Map};const n=e.substring(0,t).toLowerCase(),o=new Map;let i=e.indexOf(";",t);for(;i>=0&&i<e.length;){if(++i,i=b(e," \t",i),i<0)continue;const t=i;if(i=m(e,";=",i),i<0||";"===e[i])continue;const r=e.substring(t,i).toLowerCase();++i,i=b(e," \t",i);let n="";if(!(i<0||";"===e[i])){if('"'!==e[i]){const t=i;i=e.indexOf(";",i);const r=i>=0?i:e.length;n=e.substring(t,r).trimEnd()}else{for(++i;i<e.length&&'"'!==e[i];)"\\"===e[i]&&i+1<e.length&&++i,n+=e[i],++i;i=e.indexOf(";",i)}o.has(r)||o.set(r,n)}}return{mimeType:n,params:o}}(e);return{mimeType:t,charset:r.get("charset")?.toLowerCase().trim()??null}}});const _=(e,t)=>{for(e=Math.round(e),t=Math.round(t);0!==t;){const r=t;t=e%t,e=r}return e},x=new Map([["8∶5","16∶10"]]);var E=Object.freeze({__proto__:null,aspectRatio:(e,t)=>{const r=_(e,t);0!==r&&(e/=r,t/=r);const n=`${e}∶${t}`;return x.get(n)||n},clamp:(e,t,r)=>{let n=e;return e<t?n=t:e>r&&(n=r),n},floor:(e,t=0)=>{if(t>0&&t<1)return t=1/t,Math.floor(e/t)*t;const r=Math.pow(10,t);return Math.floor(e*r)/r},greatestCommonDivisor:_,mod:(e,t)=>(e%t+t)%t,toFixedIfFloating:e=>{if(!e||Number.isNaN(Number(e)))return e;const t=Number(e);return t%1?t.toFixed(3):String(t)},withThousandsSeparator:function(e){let t=String(e);const r=/(\d+)(\d{3})/;for(;t.match(r);)t=t.replace(r,"$1 $2");return t}});const O=(e,t)=>{let r=!1;for(let n=0;n<t.length;++n)if(-1!==e.indexOf(t.charAt(n))){r=!0;break}if(!r)return String(e);let n="";for(let r=0;r<e.length;++r)-1!==t.indexOf(e.charAt(r))&&(n+="\\"),n+=e.charAt(r);return n},N=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),y=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),A=(e,t)=>{const r=[];let n=e.indexOf(t);for(;-1!==n;)r.push(n),n=e.indexOf(t,n+t.length);return r},S=/^([a-z0-9]+(?:-[a-z0-9]+)*\.)*[a-z0-9]+(?:-[a-z0-9]+)*$/,v="^[]{}()\\.^$*+?|-,",C=function(){return v},T=function(e,t){let r="";for(let t=0;t<e.length;++t){const n=e.charAt(t);-1!==C().indexOf(n)&&(r+="\\"),r+=n}return new RegExp(r,t||"")};const U=/[A-Z]{2,}(?=[A-Z0-9][a-z0-9]+|\b|_)|[A-Za-z][0-9]+[a-z]?|[A-Z]?[a-z]+|[0-9][A-Za-z]+|[A-Z]|[0-9]+|[.]/g,z=function(e){return e.match?.(U)?.map((e=>e.toLowerCase())).join("-").replaceAll("-.-",".")||e};var L=Object.freeze({__proto__:null,DOUBLE_QUOTE:'"',SINGLE_QUOTE:"'",base64ToSize:function(e){if(!e)return 0;let t=3*e.length/4;return"="===e[e.length-1]&&t--,e.length>1&&"="===e[e.length-2]&&t--,t},caseInsensetiveComparator:function(e,t){return(e=e.toUpperCase())===(t=t.toUpperCase())?0:e>t?1:-1},collapseWhitespace:e=>e.replace(/[\s\xA0]+/g," "),compare:(e,t)=>e>t?1:e<t?-1:0,concatBase64:function(e,t){if(0===e.length||!e.endsWith("="))return e+t;const r=e.substring(0,e.length-4),n=e.substring(e.length-4);return r+window.btoa(window.atob(n)+window.atob(t))},countUnmatchedLeftParentheses:e=>{let t=0;for(const r of e)"("===r?t++:")"===r&&t>0&&t--;return t},countWtf8Bytes:e=>{let t=0;for(let r=0;r<e.length;r++){const n=e.charCodeAt(r);if(n<=127)t++;else if(n<=2047)t+=2;else if(n<55296||57343<n)t+=3;else{if(n<=56319&&r+1<e.length){const n=e.charCodeAt(r+1);if(56320<=n&&n<=57343){t+=4,r++;continue}}t+=3}}return t},createPlainTextSearchRegex:T,createSearchRegex:function(e,t,r,n=!1){const o=t?"g":"gi";let i;if(r)try{i=new RegExp(e,o)}catch{}return i||(i=T(e,o)),n&&i&&(i=new RegExp(`\\b${i.source}\\b`,o)),i},escapeCharacters:O,escapeForRegExp:e=>O(e,v),filterRegex:function(e){let t="^(?:.*\\0)?";for(let r=0;r<e.length;++r){let n=e.charAt(r);-1!==v.indexOf(n)&&(n="\\"+n),t+="[^\\0"+n+"]*"+n}return new RegExp(t,"i")},findIndexesOfSubString:A,findLineEndingIndexes:e=>{const t=A(e,"\n");return t.push(e.length),t},findUnclosedCssQuote:function(e){let t="";for(let r=0;r<e.length;++r){const n=e[r];"\\"!==n?"'"!==n&&'"'!==n||(t===n?t="":""===t&&(t=n)):r++}return t},formatAsJSLiteral:e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=(e,t,r,n)=>{if(r){if(y.has(r))return y.get(r);return"\\x"+N(r.charCodeAt(0),2)}if(n){return"\\u"+N(n.charCodeAt(0),4)}return t?y.get(t)||"":e};let o="",i="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(i="'",o=e.replaceAll(r,n)):(i="`",o=e.replaceAll(t,n)):(i='"',o=e.replaceAll(t,n)):(i="'",o=e.replaceAll(t,n)),`${i}${o}${i}`},hashCode:function(e){if(!e)return 0;const t=4294967291;let r=0,n=1;for(let o=0;o<e.length;o++){r=(r+n*(1506996573*e.charCodeAt(o)))%t,n=1345575271*n%t}return r=(r+n*(t-1))%t,Math.abs(0|r)},isExtendedKebabCase:e=>S.test(e),isWhitespace:e=>/^\s*$/.test(e),naturalOrderComparator:(e,t)=>{const r=/^\d+|^\D+/;let n,o,i,a;for(;;){if(!e)return t?-1:0;if(!t)return 1;if(n=e.match(r)[0],o=t.match(r)[0],i=!Number.isNaN(Number(n)),a=!Number.isNaN(Number(o)),i&&!a)return-1;if(a&&!i)return 1;if(i&&a){const e=Number(n)-Number(o);if(e)return e;if(n.length!==o.length)return Number(n)||Number(o)?o.length-n.length:n.length-o.length}else if(n!==o)return n<o?-1:1;e=e.substring(n.length),t=t.substring(o.length)}},regexSpecialCharacters:C,removeURLFragment:e=>{const t=new URL(e);return t.hash="",t.toString()},replaceControlCharacters:e=>e.replace(/[\0-\x08\x0B\f\x0E-\x1F\x80-\x9F]/g,"�"),replaceLast:function(e,t,r){const n=e.lastIndexOf(t);return-1===n?e:e.slice(0,n)+e.slice(n).replace(t,r)},reverse:e=>e.split("").reverse().join(""),sprintf:(e,...t)=>{let r=0;return e.replaceAll(/%(?:(\d+)\$)?(?:\.(\d*))?([%dfs])/g,((e,n,o,i)=>{if("%"===i)return"%";if(void 0!==n&&(r=parseInt(n,10)-1,r<0))throw new RangeError(`Invalid parameter index ${r+1}`);if(r>=t.length)throw new RangeError(`Expected at least ${r+1} format parameters, but only ${t.length} where given.`);if("s"===i){const e=String(t[r++]);return void 0!==o?e.substring(0,Number(o)):e}let a=Number(t[r++]);return isNaN(a)&&(a=0),"d"===i?String(Math.floor(a)).padStart(Number(o),"0"):void 0!==o?a.toFixed(Number(o)):String(a)}))},stringifyWithPrecision:function(e,t=2){if(0===t)return e.toFixed(0);const r=e.toFixed(t).replace(/\.?0*$/,"");return"-0"===r?"0":r},stripLineBreaks:e=>e.replace(/(\r)?\n/g,""),toBase64:e=>{function t(e){return e<26?e+65:e<52?e+71:e<62?e-4:62===e?43:63===e?47:65}const r=(new TextEncoder).encode(e.toString()),n=r.length;let o,i="";if(0===n)return i;let a=0;for(let e=0;e<n;e++)o=e%3,a|=r[e]<<(16>>>o&24),2===o&&(i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),t(a>>>6&63),t(63&a)),a=0);return 0===o?i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),61,61):1===o&&(i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),t(a>>>6&63),61)),i},toKebabCase:z,toKebabCaseKeys:function(e){const t={};for(const[r,n]of Object.entries(e))t[z(r)]=n;return t},toLowerCaseString:function(e){return e.toLowerCase()},toTitleCase:e=>e.substring(0,1).toUpperCase()+e.substring(1),trimEndWithMaxLength:(e,t)=>e.length<=t?String(e):e.substr(0,t-1)+"…",trimMiddle:(e,t)=>{if(e.length<=t)return String(e);let r=t>>1,n=t-r-1;return e.codePointAt(e.length-n-1)>=65536&&(--n,++r),r>0&&e.codePointAt(r-1)>=65536&&--r,e.substr(0,r)+"…"+e.substr(e.length-n,n)},trimURL:(e,t)=>{let r=e.replace(/^(https|http|file):\/\//i,"");return t&&r.toLowerCase().startsWith(t.toLowerCase())&&(r=r.substr(t.length)),r}});var M=Object.freeze({__proto__:null,microSecondsToMilliSeconds:function(e){return e/1e3},milliSecondsToSeconds:function(e){return e/1e3}});class R extends Uint32Array{getValue(e){return this[e]}setValue(e,t){this[e]=t}asUint32ArrayOrFail(){return this}asArrayOrFail(){throw new Error("Not an array")}}class j{#e;#t;length;constructor(e,t){this.#e=[],this.length=e;let r=1;for(;;){r*=2,this.#t=Math.ceil(e/r);try{if(void 0!==t&&this.#t>t)throw new RangeError;for(let e=0;e<r;++e)this.#e[e]=new Uint32Array(this.#t);return}catch(e){if(this.#t<1e6)throw e}}}getValue(e){if(e>=0&&e<this.length){const t=this.#t;return this.#e[Math.floor(e/t)][e%t]}return this.#e[0][-1]}setValue(e,t){if(e>=0&&e<this.length){const r=this.#t;this.#e[Math.floor(e/r)][e%r]=t}}asUint32ArrayOrFail(){throw new Error("Not a Uint32Array")}asArrayOrFail(){throw new Error("Not an array")}}class F extends Array{getValue(e){return this[e]}setValue(e,t){this[e]=t}asUint32ArrayOrFail(){throw new Error("Not a Uint32Array")}asArrayOrFail(){return this}}class $ extends Uint8Array{constructor(e){super("number"==typeof e?Math.ceil(e/8):e)}getBit(e){return 0!==(this[e>>3]&1<<(7&e))}setBit(e){this[e>>3]|=1<<(7&e)}clearBit(e){this[e>>3]&=~(1<<(7&e))}previous(e){for(;e!==e>>3<<3;)if(--e,this.getBit(e))return e;let t=(e>>3)-1;for(;t>=0&&0===this[t];)--t;if(t<0)return-1;for(e=7+(t<<3);e>=t<<3;--e)if(this.getBit(e))return e;throw new Error("Unreachable")}}var B=Object.freeze({__proto__:null,createBitVector:function(e){return new $(e)},createExpandableBigUint32Array:function(){return new F},createFixedBigUint32Array:function(e,t){try{if(void 0!==t&&e>t)throw new RangeError;return new R(e)}catch{return new j(e,t)}}});function V(e,t){if(null==e)throw new Error(`Expected given value to not be null/undefined but it was: ${e}${t?`\n${t}`:""}`)}function k(e,t){throw new Error(t)}function D(e){return e}var I=Object.freeze({__proto__:null,assertNever:k,assertNotNullOrUndefined:V,assertUnhandled:D});var W=Object.freeze({__proto__:null,LocalizedEmptyString:""});class K extends Error{message;constructor(e){super(e),this.message=e}}var P=Object.freeze({__proto__:null,UserVisibleError:K,isUserVisibleError:function(e){return"object"==typeof e&&null!==e&&e instanceof K}});export{i as ArrayUtilities,a as Brand,s as Constructor,c as DOMUtilities,l as DateUtilities,u as DevToolsPath,h as KeyboardUtilities,g as MapUtilities,w as MimeType,E as NumberUtilities,L as StringUtilities,M as Timing,I as TypeScriptUtilities,B as TypedArrayUtilities,W as UIString,P as UserVisibleError,k as assertNever,V as assertNotNullOrUndefined,D as assertUnhandled}; | |||
Check failure
Code scanning / CodeQL
Incomplete multi-character sanitization High library
<!--
| @@ -1 +1 @@ | |||
| function e(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function t(r,n,o,i,a,s){if(i<=o)return;const l=function(t,r,n,o,i){const a=t[i];e(t,o,i);let s=n;for(let i=n;i<o;++i)r(t[i],a)<0&&(e(t,s,i),++s);return e(t,o,s),s}(r,n,o,i,Math.floor(Math.random()*(i-o))+o);a<l&&t(r,n,o,l-1,a,s),l<s&&t(r,n,l+1,i,a,s)}function r(e,t,r,n){const o=[];let i=0,a=0;for(;i<e.length&&a<t.length;){const s=r(e[i],t[a]);!n&&s||o.push(s<=0?e[i]:t[a]),s<=0&&i++,s>=0&&a++}if(n){for(;i<e.length;)o.push(e[i++]);for(;a<t.length;)o.push(t[a++])}return o}function n(e,t,r,n,o){let i=n||0,a=void 0!==o?o:e.length;for(;i<a;){const n=i+a>>1;r(t,e[n])>0?i=n+1:a=n}return a}function o(e,t,r){const n="END"===r;if(0===e.length)return null;let o=0,i=e.length-1,a=0,s=!1,l=!1,u=0;do{u=o+(i-o)/2,a=n?Math.ceil(u):Math.floor(u),s=t(e[a]),l=s===n,l?o=Math.min(i,a+(o===a?1:0)):i=Math.max(o,a+(i===a?-1:0))}while(i!==o);return t(e[o])?o:null}var i=Object.freeze({__proto__:null,removeElement:(e,t,r)=>{let n=e.indexOf(t);if(-1===n)return!1;if(r)return e.splice(n,1),!0;for(let r=n+1,o=e.length;r<o;++r)e[r]!==t&&(e[n++]=e[r]);return e.length=n,!0},sortRange:function(e,r,n,o,i,a){return 0===n&&o===e.length-1&&0===i&&a>=o?e.sort(r):t(e,r,n,o,i,a),e},binaryIndexOf:(e,t,r)=>{const o=n(e,t,r);return o<e.length&&0===r(t,e[o])?o:-1},intersectOrdered:(e,t,n)=>r(e,t,n,!1),mergeOrdered:(e,t,n)=>r(e,t,n,!0),DEFAULT_COMPARATOR:(e,t)=>e<t?-1:e>t?1:0,lowerBound:n,upperBound:function(e,t,r,n,o){let i=n||0,a=void 0!==o?o:e.length;for(;i<a;){const n=i+a>>1;r(t,e[n])>=0?i=n+1:a=n}return a},nearestIndexFromBeginning:function(e,t){return o(e,t,"BEGINNING")},nearestIndexFromEnd:function(e,t){return o(e,t,"END")},arrayDoesNotContainNullOrUndefined:function(e){return!e.includes(null)&&!e.includes(void 0)}}),a=Object.freeze({__proto__:null});var s=Object.freeze({__proto__:null,isValid:e=>!isNaN(e.getTime()),toISO8601Compact:e=>{function t(e){return(e>9?"":"0")+e}return e.getFullYear()+t(e.getMonth()+1)+t(e.getDate())+"T"+t(e.getHours())+t(e.getMinutes())+t(e.getSeconds())}});var l=Object.freeze({__proto__:null,EmptyUrlString:"",EmptyRawPathString:"",EmptyEncodedPathString:""});var u=Object.freeze({__proto__:null,deepActiveElement:function(e){let t=e.activeElement;for(;t&&t.shadowRoot&&t.shadowRoot.activeElement;)t=t.shadowRoot.activeElement;return t},getEnclosingShadowRootForNode:function(e){let t=e.parentNodeOrShadowHost();for(;t;){if(t instanceof ShadowRoot)return t;t=t.parentNodeOrShadowHost()}return null},rangeOfWord:function(e,t,r,n,o){let i,a,s=0,l=0;if(n||(n=e),o&&"backward"!==o&&"both"!==o)i=e,s=t;else{let o=e;for(;o;){if(o===n){i||(i=n);break}if(o.nodeType===Node.TEXT_NODE&&null!==o.nodeValue){for(let n=o===e?t-1:o.nodeValue.length-1;n>=0;--n)if(-1!==r.indexOf(o.nodeValue[n])){i=o,s=n+1;break}}if(i)break;o=o.traversePreviousNode(n)}i||(i=n,s=0)}if(o&&"forward"!==o&&"both"!==o)a=e,l=t;else{let o=e;for(;o;){if(o===n){a||(a=n);break}if(o.nodeType===Node.TEXT_NODE&&null!==o.nodeValue){for(let n=o===e?t:0;n<o.nodeValue.length;++n)if(-1!==r.indexOf(o.nodeValue[n])){a=o,l=n;break}}if(a)break;o=o.traverseNextNode(n)}a||(a=n,l=n.nodeType===Node.TEXT_NODE?n.nodeValue?.length||0:n.childNodes.length)}if(!e.ownerDocument)throw new Error("No `ownerDocument` found for rootNode");const u=e.ownerDocument.createRange();return u.setStart(i,s),u.setEnd(a,l),u}});const c=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]);var f=Object.freeze({__proto__:null,ENTER_KEY:"Enter",ESCAPE_KEY:"Escape",TAB_KEY:"Tab",ARROW_KEYS:c,keyIsArrowKey:function(e){return c.has(e)},isEscKey:function(e){return"Escape"===e.key},isEnterOrSpaceKey:function(e){return"Enter"===e.key||" "===e.key}});class h{map=new Map;set(e,t){let r=this.map.get(e);r||(r=new Set,this.map.set(e,r)),r.add(t)}get(e){return this.map.get(e)||new Set}has(e){return this.map.has(e)}hasValue(e,t){const r=this.map.get(e);return!!r&&r.has(t)}get size(){return this.map.size}delete(e,t){const r=this.get(e);if(!r)return!1;const n=r.delete(t);return r.size||this.map.delete(e),n}deleteAll(e){this.map.delete(e)}keysArray(){return[...this.map.keys()]}keys(){return this.map.keys()}valuesArray(){const e=[];for(const t of this.map.values())e.push(...t.values());return e}clear(){this.map.clear()}}var p=Object.freeze({__proto__:null,inverse:function(e){const t=new h;for(const[r,n]of e.entries())t.set(n,r);return t},Multimap:h,getWithDefault:function(e,t,r){let n=e.get(t);return n||(n=r(t),e.set(t,n)),n}});const d=new Set(["application/ecmascript","application/javascript","application/json","application/json+protobuf","application/vnd.dart","application/xml","application/x-aspx","application/x-javascript","application/x-jsp","application/x-httpd-php"]);function g(e,t,r=0){for(let n=r;n<e.length;n++)if(t.includes(e[n]))return n;return-1}function m(e,t,r=0){for(let n=r;n<e.length;n++)if(!t.includes(e[n]))return n;return-1}var b=Object.freeze({__proto__:null,isTextType:function(e){return e.startsWith("text/")||e.endsWith("+json")||e.endsWith("+xml")||d.has(e)},parseContentType:function(e){if("*/*"===e)return{mimeType:null,charset:null};const{mimeType:t,params:r}=function(e){e=e.trim();let t=g(e," \t;(");t<0&&(t=e.length);const r=e.indexOf("/");if(r<0||r>t)return{mimeType:null,params:new Map};const n=e.substring(0,t).toLowerCase(),o=new Map;let i=e.indexOf(";",t);for(;i>=0&&i<e.length;){if(++i,i=m(e," \t",i),i<0)continue;const t=i;if(i=g(e,";=",i),i<0||";"===e[i])continue;const r=e.substring(t,i).toLowerCase();++i,i=m(e," \t",i);let n="";if(!(i<0||";"===e[i])){if('"'!==e[i]){const t=i;i=e.indexOf(";",i);const r=i>=0?i:e.length;n=e.substring(t,r).trimEnd()}else{for(++i;i<e.length&&'"'!==e[i];)"\\"===e[i]&&i+1<e.length&&++i,n+=e[i],++i;i=e.indexOf(";",i)}o.has(r)||o.set(r,n)}}return{mimeType:n,params:o}}(e);return{mimeType:t,charset:r.get("charset")?.toLowerCase().trim()??null}}});const w=(e,t)=>{for(e=Math.round(e),t=Math.round(t);0!==t;){const r=t;t=e%t,e=r}return e},x=new Map([["8∶5","16∶10"]]);var _=Object.freeze({__proto__:null,clamp:(e,t,r)=>{let n=e;return e<t?n=t:e>r&&(n=r),n},mod:(e,t)=>(e%t+t)%t,bytesToString:e=>{if(e<1e3)return`${e.toFixed(0)} B`;const t=e/1e3;if(t<100)return`${t.toFixed(1)} kB`;if(t<1e3)return`${t.toFixed(0)} kB`;const r=t/1e3;return r<100?`${r.toFixed(1)} MB`:`${r.toFixed(0)} MB`},toFixedIfFloating:e=>{if(!e||Number.isNaN(Number(e)))return e;const t=Number(e);return t%1?t.toFixed(3):String(t)},floor:(e,t=0)=>{const r=Math.pow(10,t);return Math.floor(e*r)/r},greatestCommonDivisor:w,aspectRatio:(e,t)=>{const r=w(e,t);0!==r&&(e/=r,t/=r);const n=`${e}∶${t}`;return x.get(n)||n},withThousandsSeparator:function(e){let t=String(e);const r=/(\d+)(\d{3})/;for(;t.match(r);)t=t.replace(r,"$1 $2");return t}});var E=Object.freeze({__proto__:null,promiseWithResolvers:function(){let e,t;return{promise:new Promise(((r,n)=>{e=r,t=n})),resolve:e,reject:t}}});const O=(e,t)=>{let r=!1;for(let n=0;n<t.length;++n)if(-1!==e.indexOf(t.charAt(n))){r=!0;break}if(!r)return String(e);let n="";for(let r=0;r<e.length;++r)-1!==t.indexOf(e.charAt(r))&&(n+="\\"),n+=e.charAt(r);return n},N=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),y=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),A=(e,t)=>{const r=[];let n=e.indexOf(t);for(;-1!==n;)r.push(n),n=e.indexOf(t,n+t.length);return r},v=/^([a-z0-9]+(?:-[a-z0-9]+)*\.)*[a-z0-9]+(?:-[a-z0-9]+)*$/,S="^[]{}()\\.^$*+?|-,",C=function(){return S},T=function(e,t){let r="";for(let t=0;t<e.length;++t){const n=e.charAt(t);-1!==C().indexOf(n)&&(r+="\\"),r+=n}return new RegExp(r,t||"")};const U=/[A-Z]{2,}(?=[A-Z0-9][a-z0-9]+|\b|_)|[A-Za-z][0-9]+[a-z]?|[A-Z]?[a-z]+|[0-9][A-Za-z]+|[A-Z]|[0-9]+|[.]/g,M=function(e){return e.match?.(U)?.map((e=>e.toLowerCase())).join("-").replaceAll("-.-",".")||e};var R=Object.freeze({__proto__:null,escapeCharacters:O,formatAsJSLiteral:e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=(e,t,r,n)=>{if(r){if(y.has(r))return y.get(r);return"\\x"+N(r.charCodeAt(0),2)}if(n){return"\\u"+N(n.charCodeAt(0),4)}return t?y.get(t)||"":e};let o="",i="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(i="'",o=e.replaceAll(r,n)):(i="`",o=e.replaceAll(t,n)):(i='"',o=e.replaceAll(t,n)):(i="'",o=e.replaceAll(t,n)),`${i}${o}${i}`},sprintf:(e,...t)=>{let r=0;return e.replaceAll(/%(?:(\d+)\$)?(?:\.(\d*))?([%dfs])/g,((e,n,o,i)=>{if("%"===i)return"%";if(void 0!==n&&(r=parseInt(n,10)-1,r<0))throw new RangeError(`Invalid parameter index ${r+1}`);if(r>=t.length)throw new RangeError(`Expected at least ${r+1} format parameters, but only ${t.length} where given.`);if("s"===i){const e=String(t[r++]);return void 0!==o?e.substring(0,Number(o)):e}let a=Number(t[r++]);return isNaN(a)&&(a=0),"d"===i?String(Math.floor(a)).padStart(Number(o),"0"):void 0!==o?a.toFixed(Number(o)):String(a)}))},toBase64:e=>{function t(e){return e<26?e+65:e<52?e+71:e<62?e-4:62===e?43:63===e?47:65}const r=(new TextEncoder).encode(e.toString()),n=r.length;let o,i="";if(0===n)return i;let a=0;for(let e=0;e<n;e++)o=e%3,a|=r[e]<<(16>>>o&24),2===o&&(i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),t(a>>>6&63),t(63&a)),a=0);return 0===o?i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),61,61):1===o&&(i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),t(a>>>6&63),61)),i},findIndexesOfSubString:A,findLineEndingIndexes:e=>{const t=A(e,"\n");return t.push(e.length),t},isWhitespace:e=>/^\s*$/.test(e),trimURL:(e,t)=>{let r=e.replace(/^(https|http|file):\/\//i,"");return t&&r.toLowerCase().startsWith(t.toLowerCase())&&(r=r.substr(t.length)),r},collapseWhitespace:e=>e.replace(/[\s\xA0]+/g," "),reverse:e=>e.split("").reverse().join(""),replaceControlCharacters:e=>e.replace(/[\0-\x08\x0B\f\x0E-\x1F\x80-\x9F]/g,"�"),countWtf8Bytes:e=>{let t=0;for(let r=0;r<e.length;r++){const n=e.charCodeAt(r);if(n<=127)t++;else if(n<=2047)t+=2;else if(n<55296||57343<n)t+=3;else{if(n<=56319&&r+1<e.length){const n=e.charCodeAt(r+1);if(56320<=n&&n<=57343){t+=4,r++;continue}}t+=3}}return t},stripLineBreaks:e=>e.replace(/(\r)?\n/g,""),isExtendedKebabCase:e=>v.test(e),toTitleCase:e=>e.substring(0,1).toUpperCase()+e.substring(1),removeURLFragment:e=>{const t=new URL(e);return t.hash="",t.toString()},regexSpecialCharacters:C,filterRegex:function(e){let t="^(?:.*\\0)?";for(let r=0;r<e.length;++r){let n=e.charAt(r);-1!==S.indexOf(n)&&(n="\\"+n),t+="[^\\0"+n+"]*"+n}return new RegExp(t,"i")},createSearchRegex:function(e,t,r,n=!1){const o=t?"g":"gi";let i;if(r)try{i=new RegExp(e,o)}catch(e){}return i||(i=T(e,o)),n&&i&&(i=new RegExp(`\\b${i.source}\\b`,o)),i},caseInsensetiveComparator:function(e,t){return(e=e.toUpperCase())===(t=t.toUpperCase())?0:e>t?1:-1},hashCode:function(e){if(!e)return 0;const t=4294967291;let r=0,n=1;for(let o=0;o<e.length;o++){r=(r+n*(1506996573*e.charCodeAt(o)))%t,n=1345575271*n%t}return r=(r+n*(t-1))%t,Math.abs(0|r)},compare:(e,t)=>e>t?1:e<t?-1:0,trimMiddle:(e,t)=>{if(e.length<=t)return String(e);let r=t>>1,n=t-r-1;return e.codePointAt(e.length-n-1)>=65536&&(--n,++r),r>0&&e.codePointAt(r-1)>=65536&&--r,e.substr(0,r)+"…"+e.substr(e.length-n,n)},trimEndWithMaxLength:(e,t)=>e.length<=t?String(e):e.substr(0,t-1)+"…",escapeForRegExp:e=>O(e,S),naturalOrderComparator:(e,t)=>{const r=/^\d+|^\D+/;let n,o,i,a;for(;;){if(!e)return t?-1:0;if(!t)return 1;if(n=e.match(r)[0],o=t.match(r)[0],i=!Number.isNaN(Number(n)),a=!Number.isNaN(Number(o)),i&&!a)return-1;if(a&&!i)return 1;if(i&&a){const e=Number(n)-Number(o);if(e)return e;if(n.length!==o.length)return Number(n)||Number(o)?o.length-n.length:n.length-o.length}else if(n!==o)return n<o?-1:1;e=e.substring(n.length),t=t.substring(o.length)}},base64ToSize:function(e){if(!e)return 0;let t=3*e.length/4;return"="===e[e.length-1]&&t--,e.length>1&&"="===e[e.length-2]&&t--,t},SINGLE_QUOTE:"'",DOUBLE_QUOTE:'"',findUnclosedCssQuote:function(e){let t="";for(let r=0;r<e.length;++r){const n=e[r];"\\"!==n?"'"!==n&&'"'!==n||(t===n?t="":""===t&&(t=n)):r++}return t},countUnmatchedLeftParentheses:e=>{let t=0;for(const r of e)"("===r?t++:")"===r&&t>0&&t--;return t},createPlainTextSearchRegex:T,toLowerCaseString:function(e){return e.toLowerCase()},toKebabCase:M,toKebabCaseKeys:function(e){const t={};for(const[r,n]of Object.entries(e))t[M(r)]=n;return t},replaceLast:function(e,t,r){const n=e.lastIndexOf(t);return-1===n?e:e.slice(0,n)+e.slice(n).replace(t,r)},stringifyWithPrecision:function(e,t=2){if(0===t)return e.toFixed(0);const r=e.toFixed(t).replace(/\.?0*$/,"");return"-0"===r?"0":r},concatBase64:function(e,t){if(0===e.length||!e.endsWith("="))return e+t;const r=e.substring(0,e.length-4),n=e.substring(e.length-4);return r+window.btoa(window.atob(n)+window.atob(t))}});var z=Object.freeze({__proto__:null,secondsToMilliSeconds:function(e){return 1e3*e},milliSecondsToSeconds:function(e){return e/1e3},microSecondsToMilliSeconds:function(e){return e/1e3}});class L extends Uint32Array{getValue(e){return this[e]}setValue(e,t){this[e]=t}asUint32ArrayOrFail(){return this}asArrayOrFail(){throw new Error("Not an array")}}class j{#e;#t;length;constructor(e,t){this.#e=[],this.length=e;let r=1;for(;;){r*=2,this.#t=Math.ceil(e/r);try{if(void 0!==t&&this.#t>t)throw new RangeError;for(let e=0;e<r;++e)this.#e[e]=new Uint32Array(this.#t);return}catch(e){if(this.#t<1e6)throw e}}}getValue(e){if(e>=0&&e<this.length){const t=this.#t;return this.#e[Math.floor(e/t)][e%t]}return this.#e[0][-1]}setValue(e,t){if(e>=0&&e<this.length){const r=this.#t;this.#e[Math.floor(e/r)][e%r]=t}}asUint32ArrayOrFail(){throw new Error("Not a Uint32Array")}asArrayOrFail(){throw new Error("Not an array")}}class F extends Array{getValue(e){return this[e]}setValue(e,t){this[e]=t}asUint32ArrayOrFail(){throw new Error("Not a Uint32Array")}asArrayOrFail(){return this}}class $ extends Uint8Array{constructor(e){super(Math.ceil(e/8))}getBit(e){return 0!==(this[e>>3]&1<<(7&e))}setBit(e){this[e>>3]|=1<<(7&e)}clearBit(e){this[e>>3]&=~(1<<(7&e))}previous(e){for(;e!==e>>3<<3;)if(--e,this.getBit(e))return e;let t;for(t=(e>>3)-1;t>=0&&0===this[t];--t);if(t<0)return-1;for(e=7+(t<<3);e>=t<<3;--e)if(this.getBit(e))return e;throw new Error("Unreachable")}}var B=Object.freeze({__proto__:null,createExpandableBigUint32Array:function(){return new F},createFixedBigUint32Array:function(e,t){try{if(void 0!==t&&e>t)throw new RangeError;return new L(e)}catch{return new j(e,t)}},createBitVector:function(e){return new $(e)}});function k(e,t){if(null==e)throw new Error(`Expected given value to not be null/undefined but it was: ${e}${t?`\n${t}`:""}`)}function V(e,t){throw new Error(t)}function D(e){return e}var I=Object.freeze({__proto__:null,assertNotNullOrUndefined:k,assertNever:V,assertUnhandled:D});var W=Object.freeze({__proto__:null,LocalizedEmptyString:""});class K extends Error{message;constructor(e){super(e),this.message=e}}var P=Object.freeze({__proto__:null,UserVisibleError:K,isUserVisibleError:function(e){return"object"==typeof e&&null!==e&&e instanceof K}});export{i as ArrayUtilities,a as Brand,u as DOMUtilities,s as DateUtilities,l as DevToolsPath,f as KeyboardUtilities,p as MapUtilities,b as MimeType,_ as NumberUtilities,E as PromiseUtilities,R as StringUtilities,z as Timing,I as TypeScriptUtilities,B as TypedArrayUtilities,W as UIString,P as UserVisibleError,V as assertNever,k as assertNotNullOrUndefined,D as assertUnhandled}; | |||
| function e(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function t(r,n,o,i,a,s){if(i<=o)return;const l=function(t,r,n,o,i){const a=t[i];e(t,o,i);let s=n;for(let i=n;i<o;++i)r(t[i],a)<0&&(e(t,s,i),++s);return e(t,o,s),s}(r,n,o,i,Math.floor(Math.random()*(i-o))+o);a<l&&t(r,n,o,l-1,a,s),l<s&&t(r,n,l+1,i,a,s)}function r(e,t,r,n){const o=[];let i=0,a=0;for(;i<e.length&&a<t.length;){const s=r(e[i],t[a]);!n&&s||o.push(s<=0?e[i]:t[a]),s<=0&&i++,s>=0&&a++}if(n){for(;i<e.length;)o.push(e[i++]);for(;a<t.length;)o.push(t[a++])}return o}function n(e,t,r,n,o){let i=n||0,a=void 0!==o?o:e.length;for(;i<a;){const n=i+a>>1;r(t,e[n])>0?i=n+1:a=n}return a}function o(e,t,r){const n="END"===r;if(0===e.length)return null;let o=0,i=e.length-1,a=0,s=!1,l=!1,u=0;do{u=o+(i-o)/2,a=n?Math.ceil(u):Math.floor(u),s=t(e[a]),l=s===n,l?o=Math.min(i,a+(o===a?1:0)):i=Math.max(o,a+(i===a?-1:0))}while(i!==o);return t(e[o])?o:null}var i=Object.freeze({__proto__:null,DEFAULT_COMPARATOR:(e,t)=>e<t?-1:e>t?1:0,arrayDoesNotContainNullOrUndefined:function(e){return!e.includes(null)&&!e.includes(void 0)},binaryIndexOf:(e,t,r)=>{const o=n(e,t,r);return o<e.length&&0===r(t,e[o])?o:-1},intersectOrdered:(e,t,n)=>r(e,t,n,!1),lowerBound:n,mergeOrdered:(e,t,n)=>r(e,t,n,!0),nearestIndexFromBeginning:function(e,t){return o(e,t,"BEGINNING")},nearestIndexFromEnd:function(e,t){return o(e,t,"END")},removeElement:(e,t,r)=>{let n=e.indexOf(t);if(-1===n)return!1;if(r)return e.splice(n,1),!0;for(let r=n+1,o=e.length;r<o;++r)e[r]!==t&&(e[n++]=e[r]);return e.length=n,!0},sortRange:function(e,r,n,o,i,a){return 0===n&&o===e.length-1&&0===i&&a>=o?e.sort(r):t(e,r,n,o,i,a),e},upperBound:function(e,t,r,n,o){let i=n||0,a=void 0!==o?o:e.length;for(;i<a;){const n=i+a>>1;r(t,e[n])>=0?i=n+1:a=n}return a}}),a=Object.freeze({__proto__:null}),s=Object.freeze({__proto__:null});var l=Object.freeze({__proto__:null,isValid:e=>!isNaN(e.getTime()),toISO8601Compact:e=>{function t(e){return(e>9?"":"0")+e}return e.getFullYear()+t(e.getMonth()+1)+t(e.getDate())+"T"+t(e.getHours())+t(e.getMinutes())+t(e.getSeconds())}});var u=Object.freeze({__proto__:null,EmptyEncodedPathString:"",EmptyRawPathString:"",EmptyUrlString:"",urlString:(e,...t)=>String.raw({raw:e},...t)});var c=Object.freeze({__proto__:null,deepActiveElement:function(e){let t=e.activeElement;for(;t?.shadowRoot?.activeElement;)t=t.shadowRoot.activeElement;return t},getEnclosingShadowRootForNode:function(e){let t=e.parentNodeOrShadowHost();for(;t;){if(t instanceof ShadowRoot)return t;t=t.parentNodeOrShadowHost()}return null},rangeOfWord:function(e,t,r,n,o){let i,a,s=0,l=0;if(n||(n=e),o&&"backward"!==o&&"both"!==o)i=e,s=t;else{let o=e;for(;o;){if(o===n){i||(i=n);break}if(o.nodeType===Node.TEXT_NODE&&null!==o.nodeValue){for(let n=o===e?t-1:o.nodeValue.length-1;n>=0;--n)if(-1!==r.indexOf(o.nodeValue[n])){i=o,s=n+1;break}}if(i)break;o=o.traversePreviousNode(n)}i||(i=n,s=0)}if(o&&"forward"!==o&&"both"!==o)a=e,l=t;else{let o=e;for(;o;){if(o===n){a||(a=n);break}if(o.nodeType===Node.TEXT_NODE&&null!==o.nodeValue){for(let n=o===e?t:0;n<o.nodeValue.length;++n)if(-1!==r.indexOf(o.nodeValue[n])){a=o,l=n;break}}if(a)break;o=o.traverseNextNode(n)}a||(a=n,l=n.nodeType===Node.TEXT_NODE?n.nodeValue?.length||0:n.childNodes.length)}if(!e.ownerDocument)throw new Error("No `ownerDocument` found for rootNode");const u=e.ownerDocument.createRange();return u.setStart(i,s),u.setEnd(a,l),u}});const f=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]);var h=Object.freeze({__proto__:null,ARROW_KEYS:f,ENTER_KEY:"Enter",ESCAPE_KEY:"Escape",TAB_KEY:"Tab",isEnterOrSpaceKey:function(e){return"Enter"===e.key||" "===e.key},isEscKey:function(e){return"Escape"===e.key},keyIsArrowKey:function(e){return f.has(e)}});class p{map=new Map;set(e,t){let r=this.map.get(e);r||(r=new Set,this.map.set(e,r)),r.add(t)}get(e){return this.map.get(e)||new Set}has(e){return this.map.has(e)}hasValue(e,t){const r=this.map.get(e);return!!r&&r.has(t)}get size(){return this.map.size}delete(e,t){const r=this.get(e);if(!r)return!1;const n=r.delete(t);return r.size||this.map.delete(e),n}deleteAll(e){this.map.delete(e)}keysArray(){return[...this.map.keys()]}keys(){return this.map.keys()}valuesArray(){const e=[];for(const t of this.map.values())e.push(...t.values());return e}clear(){this.map.clear()}}var g=Object.freeze({__proto__:null,Multimap:p,getWithDefault:function(e,t,r){let n=e.get(t);return null==n&&(n=r(t),e.set(t,n)),n},inverse:function(e){const t=new p;for(const[r,n]of e.entries())t.set(n,r);return t}});const d=new Set(["application/ecmascript","application/javascript","application/json","application/json+protobuf","application/mpegurl","application/vnd.apple.mpegurl","application/vnd.dart","application/xml","application/x-aspx","application/x-javascript","application/x-jsp","application/x-httpd-php","application/x-mpegurl","audio/mpegurl","audio/x-mpegurl"]);function m(e,t,r=0){for(let n=r;n<e.length;n++)if(t.includes(e[n]))return n;return-1}function b(e,t,r=0){for(let n=r;n<e.length;n++)if(!t.includes(e[n]))return n;return-1}var w=Object.freeze({__proto__:null,isTextType:function(e){return e.startsWith("text/")||e.startsWith("multipart/")||e.includes("+json")||e.endsWith("+xml")||d.has(e)},parseContentType:function(e){if("*/*"===e)return{mimeType:null,charset:null};const{mimeType:t,params:r}=function(e){e=e.trim();let t=m(e," \t;(");t<0&&(t=e.length);const r=e.indexOf("/");if(r<0||r>t)return{mimeType:null,params:new Map};const n=e.substring(0,t).toLowerCase(),o=new Map;let i=e.indexOf(";",t);for(;i>=0&&i<e.length;){if(++i,i=b(e," \t",i),i<0)continue;const t=i;if(i=m(e,";=",i),i<0||";"===e[i])continue;const r=e.substring(t,i).toLowerCase();++i,i=b(e," \t",i);let n="";if(!(i<0||";"===e[i])){if('"'!==e[i]){const t=i;i=e.indexOf(";",i);const r=i>=0?i:e.length;n=e.substring(t,r).trimEnd()}else{for(++i;i<e.length&&'"'!==e[i];)"\\"===e[i]&&i+1<e.length&&++i,n+=e[i],++i;i=e.indexOf(";",i)}o.has(r)||o.set(r,n)}}return{mimeType:n,params:o}}(e);return{mimeType:t,charset:r.get("charset")?.toLowerCase().trim()??null}}});const _=(e,t)=>{for(e=Math.round(e),t=Math.round(t);0!==t;){const r=t;t=e%t,e=r}return e},x=new Map([["8∶5","16∶10"]]);var E=Object.freeze({__proto__:null,aspectRatio:(e,t)=>{const r=_(e,t);0!==r&&(e/=r,t/=r);const n=`${e}∶${t}`;return x.get(n)||n},clamp:(e,t,r)=>{let n=e;return e<t?n=t:e>r&&(n=r),n},floor:(e,t=0)=>{if(t>0&&t<1)return t=1/t,Math.floor(e/t)*t;const r=Math.pow(10,t);return Math.floor(e*r)/r},greatestCommonDivisor:_,mod:(e,t)=>(e%t+t)%t,toFixedIfFloating:e=>{if(!e||Number.isNaN(Number(e)))return e;const t=Number(e);return t%1?t.toFixed(3):String(t)},withThousandsSeparator:function(e){let t=String(e);const r=/(\d+)(\d{3})/;for(;t.match(r);)t=t.replace(r,"$1 $2");return t}});const O=(e,t)=>{let r=!1;for(let n=0;n<t.length;++n)if(-1!==e.indexOf(t.charAt(n))){r=!0;break}if(!r)return String(e);let n="";for(let r=0;r<e.length;++r)-1!==t.indexOf(e.charAt(r))&&(n+="\\"),n+=e.charAt(r);return n},N=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),y=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),A=(e,t)=>{const r=[];let n=e.indexOf(t);for(;-1!==n;)r.push(n),n=e.indexOf(t,n+t.length);return r},S=/^([a-z0-9]+(?:-[a-z0-9]+)*\.)*[a-z0-9]+(?:-[a-z0-9]+)*$/,v="^[]{}()\\.^$*+?|-,",C=function(){return v},T=function(e,t){let r="";for(let t=0;t<e.length;++t){const n=e.charAt(t);-1!==C().indexOf(n)&&(r+="\\"),r+=n}return new RegExp(r,t||"")};const U=/[A-Z]{2,}(?=[A-Z0-9][a-z0-9]+|\b|_)|[A-Za-z][0-9]+[a-z]?|[A-Z]?[a-z]+|[0-9][A-Za-z]+|[A-Z]|[0-9]+|[.]/g,z=function(e){return e.match?.(U)?.map((e=>e.toLowerCase())).join("-").replaceAll("-.-",".")||e};var L=Object.freeze({__proto__:null,DOUBLE_QUOTE:'"',SINGLE_QUOTE:"'",base64ToSize:function(e){if(!e)return 0;let t=3*e.length/4;return"="===e[e.length-1]&&t--,e.length>1&&"="===e[e.length-2]&&t--,t},caseInsensetiveComparator:function(e,t){return(e=e.toUpperCase())===(t=t.toUpperCase())?0:e>t?1:-1},collapseWhitespace:e=>e.replace(/[\s\xA0]+/g," "),compare:(e,t)=>e>t?1:e<t?-1:0,concatBase64:function(e,t){if(0===e.length||!e.endsWith("="))return e+t;const r=e.substring(0,e.length-4),n=e.substring(e.length-4);return r+window.btoa(window.atob(n)+window.atob(t))},countUnmatchedLeftParentheses:e=>{let t=0;for(const r of e)"("===r?t++:")"===r&&t>0&&t--;return t},countWtf8Bytes:e=>{let t=0;for(let r=0;r<e.length;r++){const n=e.charCodeAt(r);if(n<=127)t++;else if(n<=2047)t+=2;else if(n<55296||57343<n)t+=3;else{if(n<=56319&&r+1<e.length){const n=e.charCodeAt(r+1);if(56320<=n&&n<=57343){t+=4,r++;continue}}t+=3}}return t},createPlainTextSearchRegex:T,createSearchRegex:function(e,t,r,n=!1){const o=t?"g":"gi";let i;if(r)try{i=new RegExp(e,o)}catch{}return i||(i=T(e,o)),n&&i&&(i=new RegExp(`\\b${i.source}\\b`,o)),i},escapeCharacters:O,escapeForRegExp:e=>O(e,v),filterRegex:function(e){let t="^(?:.*\\0)?";for(let r=0;r<e.length;++r){let n=e.charAt(r);-1!==v.indexOf(n)&&(n="\\"+n),t+="[^\\0"+n+"]*"+n}return new RegExp(t,"i")},findIndexesOfSubString:A,findLineEndingIndexes:e=>{const t=A(e,"\n");return t.push(e.length),t},findUnclosedCssQuote:function(e){let t="";for(let r=0;r<e.length;++r){const n=e[r];"\\"!==n?"'"!==n&&'"'!==n||(t===n?t="":""===t&&(t=n)):r++}return t},formatAsJSLiteral:e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=(e,t,r,n)=>{if(r){if(y.has(r))return y.get(r);return"\\x"+N(r.charCodeAt(0),2)}if(n){return"\\u"+N(n.charCodeAt(0),4)}return t?y.get(t)||"":e};let o="",i="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(i="'",o=e.replaceAll(r,n)):(i="`",o=e.replaceAll(t,n)):(i='"',o=e.replaceAll(t,n)):(i="'",o=e.replaceAll(t,n)),`${i}${o}${i}`},hashCode:function(e){if(!e)return 0;const t=4294967291;let r=0,n=1;for(let o=0;o<e.length;o++){r=(r+n*(1506996573*e.charCodeAt(o)))%t,n=1345575271*n%t}return r=(r+n*(t-1))%t,Math.abs(0|r)},isExtendedKebabCase:e=>S.test(e),isWhitespace:e=>/^\s*$/.test(e),naturalOrderComparator:(e,t)=>{const r=/^\d+|^\D+/;let n,o,i,a;for(;;){if(!e)return t?-1:0;if(!t)return 1;if(n=e.match(r)[0],o=t.match(r)[0],i=!Number.isNaN(Number(n)),a=!Number.isNaN(Number(o)),i&&!a)return-1;if(a&&!i)return 1;if(i&&a){const e=Number(n)-Number(o);if(e)return e;if(n.length!==o.length)return Number(n)||Number(o)?o.length-n.length:n.length-o.length}else if(n!==o)return n<o?-1:1;e=e.substring(n.length),t=t.substring(o.length)}},regexSpecialCharacters:C,removeURLFragment:e=>{const t=new URL(e);return t.hash="",t.toString()},replaceControlCharacters:e=>e.replace(/[\0-\x08\x0B\f\x0E-\x1F\x80-\x9F]/g,"�"),replaceLast:function(e,t,r){const n=e.lastIndexOf(t);return-1===n?e:e.slice(0,n)+e.slice(n).replace(t,r)},reverse:e=>e.split("").reverse().join(""),sprintf:(e,...t)=>{let r=0;return e.replaceAll(/%(?:(\d+)\$)?(?:\.(\d*))?([%dfs])/g,((e,n,o,i)=>{if("%"===i)return"%";if(void 0!==n&&(r=parseInt(n,10)-1,r<0))throw new RangeError(`Invalid parameter index ${r+1}`);if(r>=t.length)throw new RangeError(`Expected at least ${r+1} format parameters, but only ${t.length} where given.`);if("s"===i){const e=String(t[r++]);return void 0!==o?e.substring(0,Number(o)):e}let a=Number(t[r++]);return isNaN(a)&&(a=0),"d"===i?String(Math.floor(a)).padStart(Number(o),"0"):void 0!==o?a.toFixed(Number(o)):String(a)}))},stringifyWithPrecision:function(e,t=2){if(0===t)return e.toFixed(0);const r=e.toFixed(t).replace(/\.?0*$/,"");return"-0"===r?"0":r},stripLineBreaks:e=>e.replace(/(\r)?\n/g,""),toBase64:e=>{function t(e){return e<26?e+65:e<52?e+71:e<62?e-4:62===e?43:63===e?47:65}const r=(new TextEncoder).encode(e.toString()),n=r.length;let o,i="";if(0===n)return i;let a=0;for(let e=0;e<n;e++)o=e%3,a|=r[e]<<(16>>>o&24),2===o&&(i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),t(a>>>6&63),t(63&a)),a=0);return 0===o?i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),61,61):1===o&&(i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),t(a>>>6&63),61)),i},toKebabCase:z,toKebabCaseKeys:function(e){const t={};for(const[r,n]of Object.entries(e))t[z(r)]=n;return t},toLowerCaseString:function(e){return e.toLowerCase()},toTitleCase:e=>e.substring(0,1).toUpperCase()+e.substring(1),trimEndWithMaxLength:(e,t)=>e.length<=t?String(e):e.substr(0,t-1)+"…",trimMiddle:(e,t)=>{if(e.length<=t)return String(e);let r=t>>1,n=t-r-1;return e.codePointAt(e.length-n-1)>=65536&&(--n,++r),r>0&&e.codePointAt(r-1)>=65536&&--r,e.substr(0,r)+"…"+e.substr(e.length-n,n)},trimURL:(e,t)=>{let r=e.replace(/^(https|http|file):\/\//i,"");return t&&r.toLowerCase().startsWith(t.toLowerCase())&&(r=r.substr(t.length)),r}});var M=Object.freeze({__proto__:null,microSecondsToMilliSeconds:function(e){return e/1e3},milliSecondsToSeconds:function(e){return e/1e3}});class R extends Uint32Array{getValue(e){return this[e]}setValue(e,t){this[e]=t}asUint32ArrayOrFail(){return this}asArrayOrFail(){throw new Error("Not an array")}}class j{#e;#t;length;constructor(e,t){this.#e=[],this.length=e;let r=1;for(;;){r*=2,this.#t=Math.ceil(e/r);try{if(void 0!==t&&this.#t>t)throw new RangeError;for(let e=0;e<r;++e)this.#e[e]=new Uint32Array(this.#t);return}catch(e){if(this.#t<1e6)throw e}}}getValue(e){if(e>=0&&e<this.length){const t=this.#t;return this.#e[Math.floor(e/t)][e%t]}return this.#e[0][-1]}setValue(e,t){if(e>=0&&e<this.length){const r=this.#t;this.#e[Math.floor(e/r)][e%r]=t}}asUint32ArrayOrFail(){throw new Error("Not a Uint32Array")}asArrayOrFail(){throw new Error("Not an array")}}class F extends Array{getValue(e){return this[e]}setValue(e,t){this[e]=t}asUint32ArrayOrFail(){throw new Error("Not a Uint32Array")}asArrayOrFail(){return this}}class $ extends Uint8Array{constructor(e){super("number"==typeof e?Math.ceil(e/8):e)}getBit(e){return 0!==(this[e>>3]&1<<(7&e))}setBit(e){this[e>>3]|=1<<(7&e)}clearBit(e){this[e>>3]&=~(1<<(7&e))}previous(e){for(;e!==e>>3<<3;)if(--e,this.getBit(e))return e;let t=(e>>3)-1;for(;t>=0&&0===this[t];)--t;if(t<0)return-1;for(e=7+(t<<3);e>=t<<3;--e)if(this.getBit(e))return e;throw new Error("Unreachable")}}var B=Object.freeze({__proto__:null,createBitVector:function(e){return new $(e)},createExpandableBigUint32Array:function(){return new F},createFixedBigUint32Array:function(e,t){try{if(void 0!==t&&e>t)throw new RangeError;return new R(e)}catch{return new j(e,t)}}});function V(e,t){if(null==e)throw new Error(`Expected given value to not be null/undefined but it was: ${e}${t?`\n${t}`:""}`)}function k(e,t){throw new Error(t)}function D(e){return e}var I=Object.freeze({__proto__:null,assertNever:k,assertNotNullOrUndefined:V,assertUnhandled:D});var W=Object.freeze({__proto__:null,LocalizedEmptyString:""});class K extends Error{message;constructor(e){super(e),this.message=e}}var P=Object.freeze({__proto__:null,UserVisibleError:K,isUserVisibleError:function(e){return"object"==typeof e&&null!==e&&e instanceof K}});export{i as ArrayUtilities,a as Brand,s as Constructor,c as DOMUtilities,l as DateUtilities,u as DevToolsPath,h as KeyboardUtilities,g as MapUtilities,w as MimeType,E as NumberUtilities,L as StringUtilities,M as Timing,I as TypeScriptUtilities,B as TypedArrayUtilities,W as UIString,P as UserVisibleError,k as assertNever,V as assertNotNullOrUndefined,D as assertUnhandled}; | |||
Check failure
Code scanning / CodeQL
Incomplete multi-character sanitization High library
<!--
| @@ -1 +1 @@ | |||
| function e(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function t(r,n,o,i,a,s){if(i<=o)return;const l=function(t,r,n,o,i){const a=t[i];e(t,o,i);let s=n;for(let i=n;i<o;++i)r(t[i],a)<0&&(e(t,s,i),++s);return e(t,o,s),s}(r,n,o,i,Math.floor(Math.random()*(i-o))+o);a<l&&t(r,n,o,l-1,a,s),l<s&&t(r,n,l+1,i,a,s)}function r(e,t,r,n){const o=[];let i=0,a=0;for(;i<e.length&&a<t.length;){const s=r(e[i],t[a]);!n&&s||o.push(s<=0?e[i]:t[a]),s<=0&&i++,s>=0&&a++}if(n){for(;i<e.length;)o.push(e[i++]);for(;a<t.length;)o.push(t[a++])}return o}function n(e,t,r,n,o){let i=n||0,a=void 0!==o?o:e.length;for(;i<a;){const n=i+a>>1;r(t,e[n])>0?i=n+1:a=n}return a}function o(e,t,r){const n="END"===r;if(0===e.length)return null;let o=0,i=e.length-1,a=0,s=!1,l=!1,u=0;do{u=o+(i-o)/2,a=n?Math.ceil(u):Math.floor(u),s=t(e[a]),l=s===n,l?o=Math.min(i,a+(o===a?1:0)):i=Math.max(o,a+(i===a?-1:0))}while(i!==o);return t(e[o])?o:null}var i=Object.freeze({__proto__:null,removeElement:(e,t,r)=>{let n=e.indexOf(t);if(-1===n)return!1;if(r)return e.splice(n,1),!0;for(let r=n+1,o=e.length;r<o;++r)e[r]!==t&&(e[n++]=e[r]);return e.length=n,!0},sortRange:function(e,r,n,o,i,a){return 0===n&&o===e.length-1&&0===i&&a>=o?e.sort(r):t(e,r,n,o,i,a),e},binaryIndexOf:(e,t,r)=>{const o=n(e,t,r);return o<e.length&&0===r(t,e[o])?o:-1},intersectOrdered:(e,t,n)=>r(e,t,n,!1),mergeOrdered:(e,t,n)=>r(e,t,n,!0),DEFAULT_COMPARATOR:(e,t)=>e<t?-1:e>t?1:0,lowerBound:n,upperBound:function(e,t,r,n,o){let i=n||0,a=void 0!==o?o:e.length;for(;i<a;){const n=i+a>>1;r(t,e[n])>=0?i=n+1:a=n}return a},nearestIndexFromBeginning:function(e,t){return o(e,t,"BEGINNING")},nearestIndexFromEnd:function(e,t){return o(e,t,"END")},arrayDoesNotContainNullOrUndefined:function(e){return!e.includes(null)&&!e.includes(void 0)}}),a=Object.freeze({__proto__:null});var s=Object.freeze({__proto__:null,isValid:e=>!isNaN(e.getTime()),toISO8601Compact:e=>{function t(e){return(e>9?"":"0")+e}return e.getFullYear()+t(e.getMonth()+1)+t(e.getDate())+"T"+t(e.getHours())+t(e.getMinutes())+t(e.getSeconds())}});var l=Object.freeze({__proto__:null,EmptyUrlString:"",EmptyRawPathString:"",EmptyEncodedPathString:""});var u=Object.freeze({__proto__:null,deepActiveElement:function(e){let t=e.activeElement;for(;t&&t.shadowRoot&&t.shadowRoot.activeElement;)t=t.shadowRoot.activeElement;return t},getEnclosingShadowRootForNode:function(e){let t=e.parentNodeOrShadowHost();for(;t;){if(t instanceof ShadowRoot)return t;t=t.parentNodeOrShadowHost()}return null},rangeOfWord:function(e,t,r,n,o){let i,a,s=0,l=0;if(n||(n=e),o&&"backward"!==o&&"both"!==o)i=e,s=t;else{let o=e;for(;o;){if(o===n){i||(i=n);break}if(o.nodeType===Node.TEXT_NODE&&null!==o.nodeValue){for(let n=o===e?t-1:o.nodeValue.length-1;n>=0;--n)if(-1!==r.indexOf(o.nodeValue[n])){i=o,s=n+1;break}}if(i)break;o=o.traversePreviousNode(n)}i||(i=n,s=0)}if(o&&"forward"!==o&&"both"!==o)a=e,l=t;else{let o=e;for(;o;){if(o===n){a||(a=n);break}if(o.nodeType===Node.TEXT_NODE&&null!==o.nodeValue){for(let n=o===e?t:0;n<o.nodeValue.length;++n)if(-1!==r.indexOf(o.nodeValue[n])){a=o,l=n;break}}if(a)break;o=o.traverseNextNode(n)}a||(a=n,l=n.nodeType===Node.TEXT_NODE?n.nodeValue?.length||0:n.childNodes.length)}if(!e.ownerDocument)throw new Error("No `ownerDocument` found for rootNode");const u=e.ownerDocument.createRange();return u.setStart(i,s),u.setEnd(a,l),u}});const c=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]);var f=Object.freeze({__proto__:null,ENTER_KEY:"Enter",ESCAPE_KEY:"Escape",TAB_KEY:"Tab",ARROW_KEYS:c,keyIsArrowKey:function(e){return c.has(e)},isEscKey:function(e){return"Escape"===e.key},isEnterOrSpaceKey:function(e){return"Enter"===e.key||" "===e.key}});class h{map=new Map;set(e,t){let r=this.map.get(e);r||(r=new Set,this.map.set(e,r)),r.add(t)}get(e){return this.map.get(e)||new Set}has(e){return this.map.has(e)}hasValue(e,t){const r=this.map.get(e);return!!r&&r.has(t)}get size(){return this.map.size}delete(e,t){const r=this.get(e);if(!r)return!1;const n=r.delete(t);return r.size||this.map.delete(e),n}deleteAll(e){this.map.delete(e)}keysArray(){return[...this.map.keys()]}keys(){return this.map.keys()}valuesArray(){const e=[];for(const t of this.map.values())e.push(...t.values());return e}clear(){this.map.clear()}}var p=Object.freeze({__proto__:null,inverse:function(e){const t=new h;for(const[r,n]of e.entries())t.set(n,r);return t},Multimap:h,getWithDefault:function(e,t,r){let n=e.get(t);return n||(n=r(t),e.set(t,n)),n}});const d=new Set(["application/ecmascript","application/javascript","application/json","application/json+protobuf","application/vnd.dart","application/xml","application/x-aspx","application/x-javascript","application/x-jsp","application/x-httpd-php"]);function g(e,t,r=0){for(let n=r;n<e.length;n++)if(t.includes(e[n]))return n;return-1}function m(e,t,r=0){for(let n=r;n<e.length;n++)if(!t.includes(e[n]))return n;return-1}var b=Object.freeze({__proto__:null,isTextType:function(e){return e.startsWith("text/")||e.endsWith("+json")||e.endsWith("+xml")||d.has(e)},parseContentType:function(e){if("*/*"===e)return{mimeType:null,charset:null};const{mimeType:t,params:r}=function(e){e=e.trim();let t=g(e," \t;(");t<0&&(t=e.length);const r=e.indexOf("/");if(r<0||r>t)return{mimeType:null,params:new Map};const n=e.substring(0,t).toLowerCase(),o=new Map;let i=e.indexOf(";",t);for(;i>=0&&i<e.length;){if(++i,i=m(e," \t",i),i<0)continue;const t=i;if(i=g(e,";=",i),i<0||";"===e[i])continue;const r=e.substring(t,i).toLowerCase();++i,i=m(e," \t",i);let n="";if(!(i<0||";"===e[i])){if('"'!==e[i]){const t=i;i=e.indexOf(";",i);const r=i>=0?i:e.length;n=e.substring(t,r).trimEnd()}else{for(++i;i<e.length&&'"'!==e[i];)"\\"===e[i]&&i+1<e.length&&++i,n+=e[i],++i;i=e.indexOf(";",i)}o.has(r)||o.set(r,n)}}return{mimeType:n,params:o}}(e);return{mimeType:t,charset:r.get("charset")?.toLowerCase().trim()??null}}});const w=(e,t)=>{for(e=Math.round(e),t=Math.round(t);0!==t;){const r=t;t=e%t,e=r}return e},x=new Map([["8∶5","16∶10"]]);var _=Object.freeze({__proto__:null,clamp:(e,t,r)=>{let n=e;return e<t?n=t:e>r&&(n=r),n},mod:(e,t)=>(e%t+t)%t,bytesToString:e=>{if(e<1e3)return`${e.toFixed(0)} B`;const t=e/1e3;if(t<100)return`${t.toFixed(1)} kB`;if(t<1e3)return`${t.toFixed(0)} kB`;const r=t/1e3;return r<100?`${r.toFixed(1)} MB`:`${r.toFixed(0)} MB`},toFixedIfFloating:e=>{if(!e||Number.isNaN(Number(e)))return e;const t=Number(e);return t%1?t.toFixed(3):String(t)},floor:(e,t=0)=>{const r=Math.pow(10,t);return Math.floor(e*r)/r},greatestCommonDivisor:w,aspectRatio:(e,t)=>{const r=w(e,t);0!==r&&(e/=r,t/=r);const n=`${e}∶${t}`;return x.get(n)||n},withThousandsSeparator:function(e){let t=String(e);const r=/(\d+)(\d{3})/;for(;t.match(r);)t=t.replace(r,"$1 $2");return t}});var E=Object.freeze({__proto__:null,promiseWithResolvers:function(){let e,t;return{promise:new Promise(((r,n)=>{e=r,t=n})),resolve:e,reject:t}}});const O=(e,t)=>{let r=!1;for(let n=0;n<t.length;++n)if(-1!==e.indexOf(t.charAt(n))){r=!0;break}if(!r)return String(e);let n="";for(let r=0;r<e.length;++r)-1!==t.indexOf(e.charAt(r))&&(n+="\\"),n+=e.charAt(r);return n},N=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),y=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),A=(e,t)=>{const r=[];let n=e.indexOf(t);for(;-1!==n;)r.push(n),n=e.indexOf(t,n+t.length);return r},v=/^([a-z0-9]+(?:-[a-z0-9]+)*\.)*[a-z0-9]+(?:-[a-z0-9]+)*$/,S="^[]{}()\\.^$*+?|-,",C=function(){return S},T=function(e,t){let r="";for(let t=0;t<e.length;++t){const n=e.charAt(t);-1!==C().indexOf(n)&&(r+="\\"),r+=n}return new RegExp(r,t||"")};const U=/[A-Z]{2,}(?=[A-Z0-9][a-z0-9]+|\b|_)|[A-Za-z][0-9]+[a-z]?|[A-Z]?[a-z]+|[0-9][A-Za-z]+|[A-Z]|[0-9]+|[.]/g,M=function(e){return e.match?.(U)?.map((e=>e.toLowerCase())).join("-").replaceAll("-.-",".")||e};var R=Object.freeze({__proto__:null,escapeCharacters:O,formatAsJSLiteral:e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=(e,t,r,n)=>{if(r){if(y.has(r))return y.get(r);return"\\x"+N(r.charCodeAt(0),2)}if(n){return"\\u"+N(n.charCodeAt(0),4)}return t?y.get(t)||"":e};let o="",i="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(i="'",o=e.replaceAll(r,n)):(i="`",o=e.replaceAll(t,n)):(i='"',o=e.replaceAll(t,n)):(i="'",o=e.replaceAll(t,n)),`${i}${o}${i}`},sprintf:(e,...t)=>{let r=0;return e.replaceAll(/%(?:(\d+)\$)?(?:\.(\d*))?([%dfs])/g,((e,n,o,i)=>{if("%"===i)return"%";if(void 0!==n&&(r=parseInt(n,10)-1,r<0))throw new RangeError(`Invalid parameter index ${r+1}`);if(r>=t.length)throw new RangeError(`Expected at least ${r+1} format parameters, but only ${t.length} where given.`);if("s"===i){const e=String(t[r++]);return void 0!==o?e.substring(0,Number(o)):e}let a=Number(t[r++]);return isNaN(a)&&(a=0),"d"===i?String(Math.floor(a)).padStart(Number(o),"0"):void 0!==o?a.toFixed(Number(o)):String(a)}))},toBase64:e=>{function t(e){return e<26?e+65:e<52?e+71:e<62?e-4:62===e?43:63===e?47:65}const r=(new TextEncoder).encode(e.toString()),n=r.length;let o,i="";if(0===n)return i;let a=0;for(let e=0;e<n;e++)o=e%3,a|=r[e]<<(16>>>o&24),2===o&&(i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),t(a>>>6&63),t(63&a)),a=0);return 0===o?i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),61,61):1===o&&(i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),t(a>>>6&63),61)),i},findIndexesOfSubString:A,findLineEndingIndexes:e=>{const t=A(e,"\n");return t.push(e.length),t},isWhitespace:e=>/^\s*$/.test(e),trimURL:(e,t)=>{let r=e.replace(/^(https|http|file):\/\//i,"");return t&&r.toLowerCase().startsWith(t.toLowerCase())&&(r=r.substr(t.length)),r},collapseWhitespace:e=>e.replace(/[\s\xA0]+/g," "),reverse:e=>e.split("").reverse().join(""),replaceControlCharacters:e=>e.replace(/[\0-\x08\x0B\f\x0E-\x1F\x80-\x9F]/g,"�"),countWtf8Bytes:e=>{let t=0;for(let r=0;r<e.length;r++){const n=e.charCodeAt(r);if(n<=127)t++;else if(n<=2047)t+=2;else if(n<55296||57343<n)t+=3;else{if(n<=56319&&r+1<e.length){const n=e.charCodeAt(r+1);if(56320<=n&&n<=57343){t+=4,r++;continue}}t+=3}}return t},stripLineBreaks:e=>e.replace(/(\r)?\n/g,""),isExtendedKebabCase:e=>v.test(e),toTitleCase:e=>e.substring(0,1).toUpperCase()+e.substring(1),removeURLFragment:e=>{const t=new URL(e);return t.hash="",t.toString()},regexSpecialCharacters:C,filterRegex:function(e){let t="^(?:.*\\0)?";for(let r=0;r<e.length;++r){let n=e.charAt(r);-1!==S.indexOf(n)&&(n="\\"+n),t+="[^\\0"+n+"]*"+n}return new RegExp(t,"i")},createSearchRegex:function(e,t,r,n=!1){const o=t?"g":"gi";let i;if(r)try{i=new RegExp(e,o)}catch(e){}return i||(i=T(e,o)),n&&i&&(i=new RegExp(`\\b${i.source}\\b`,o)),i},caseInsensetiveComparator:function(e,t){return(e=e.toUpperCase())===(t=t.toUpperCase())?0:e>t?1:-1},hashCode:function(e){if(!e)return 0;const t=4294967291;let r=0,n=1;for(let o=0;o<e.length;o++){r=(r+n*(1506996573*e.charCodeAt(o)))%t,n=1345575271*n%t}return r=(r+n*(t-1))%t,Math.abs(0|r)},compare:(e,t)=>e>t?1:e<t?-1:0,trimMiddle:(e,t)=>{if(e.length<=t)return String(e);let r=t>>1,n=t-r-1;return e.codePointAt(e.length-n-1)>=65536&&(--n,++r),r>0&&e.codePointAt(r-1)>=65536&&--r,e.substr(0,r)+"…"+e.substr(e.length-n,n)},trimEndWithMaxLength:(e,t)=>e.length<=t?String(e):e.substr(0,t-1)+"…",escapeForRegExp:e=>O(e,S),naturalOrderComparator:(e,t)=>{const r=/^\d+|^\D+/;let n,o,i,a;for(;;){if(!e)return t?-1:0;if(!t)return 1;if(n=e.match(r)[0],o=t.match(r)[0],i=!Number.isNaN(Number(n)),a=!Number.isNaN(Number(o)),i&&!a)return-1;if(a&&!i)return 1;if(i&&a){const e=Number(n)-Number(o);if(e)return e;if(n.length!==o.length)return Number(n)||Number(o)?o.length-n.length:n.length-o.length}else if(n!==o)return n<o?-1:1;e=e.substring(n.length),t=t.substring(o.length)}},base64ToSize:function(e){if(!e)return 0;let t=3*e.length/4;return"="===e[e.length-1]&&t--,e.length>1&&"="===e[e.length-2]&&t--,t},SINGLE_QUOTE:"'",DOUBLE_QUOTE:'"',findUnclosedCssQuote:function(e){let t="";for(let r=0;r<e.length;++r){const n=e[r];"\\"!==n?"'"!==n&&'"'!==n||(t===n?t="":""===t&&(t=n)):r++}return t},countUnmatchedLeftParentheses:e=>{let t=0;for(const r of e)"("===r?t++:")"===r&&t>0&&t--;return t},createPlainTextSearchRegex:T,toLowerCaseString:function(e){return e.toLowerCase()},toKebabCase:M,toKebabCaseKeys:function(e){const t={};for(const[r,n]of Object.entries(e))t[M(r)]=n;return t},replaceLast:function(e,t,r){const n=e.lastIndexOf(t);return-1===n?e:e.slice(0,n)+e.slice(n).replace(t,r)},stringifyWithPrecision:function(e,t=2){if(0===t)return e.toFixed(0);const r=e.toFixed(t).replace(/\.?0*$/,"");return"-0"===r?"0":r},concatBase64:function(e,t){if(0===e.length||!e.endsWith("="))return e+t;const r=e.substring(0,e.length-4),n=e.substring(e.length-4);return r+window.btoa(window.atob(n)+window.atob(t))}});var z=Object.freeze({__proto__:null,secondsToMilliSeconds:function(e){return 1e3*e},milliSecondsToSeconds:function(e){return e/1e3},microSecondsToMilliSeconds:function(e){return e/1e3}});class L extends Uint32Array{getValue(e){return this[e]}setValue(e,t){this[e]=t}asUint32ArrayOrFail(){return this}asArrayOrFail(){throw new Error("Not an array")}}class j{#e;#t;length;constructor(e,t){this.#e=[],this.length=e;let r=1;for(;;){r*=2,this.#t=Math.ceil(e/r);try{if(void 0!==t&&this.#t>t)throw new RangeError;for(let e=0;e<r;++e)this.#e[e]=new Uint32Array(this.#t);return}catch(e){if(this.#t<1e6)throw e}}}getValue(e){if(e>=0&&e<this.length){const t=this.#t;return this.#e[Math.floor(e/t)][e%t]}return this.#e[0][-1]}setValue(e,t){if(e>=0&&e<this.length){const r=this.#t;this.#e[Math.floor(e/r)][e%r]=t}}asUint32ArrayOrFail(){throw new Error("Not a Uint32Array")}asArrayOrFail(){throw new Error("Not an array")}}class F extends Array{getValue(e){return this[e]}setValue(e,t){this[e]=t}asUint32ArrayOrFail(){throw new Error("Not a Uint32Array")}asArrayOrFail(){return this}}class $ extends Uint8Array{constructor(e){super(Math.ceil(e/8))}getBit(e){return 0!==(this[e>>3]&1<<(7&e))}setBit(e){this[e>>3]|=1<<(7&e)}clearBit(e){this[e>>3]&=~(1<<(7&e))}previous(e){for(;e!==e>>3<<3;)if(--e,this.getBit(e))return e;let t;for(t=(e>>3)-1;t>=0&&0===this[t];--t);if(t<0)return-1;for(e=7+(t<<3);e>=t<<3;--e)if(this.getBit(e))return e;throw new Error("Unreachable")}}var B=Object.freeze({__proto__:null,createExpandableBigUint32Array:function(){return new F},createFixedBigUint32Array:function(e,t){try{if(void 0!==t&&e>t)throw new RangeError;return new L(e)}catch{return new j(e,t)}},createBitVector:function(e){return new $(e)}});function k(e,t){if(null==e)throw new Error(`Expected given value to not be null/undefined but it was: ${e}${t?`\n${t}`:""}`)}function V(e,t){throw new Error(t)}function D(e){return e}var I=Object.freeze({__proto__:null,assertNotNullOrUndefined:k,assertNever:V,assertUnhandled:D});var W=Object.freeze({__proto__:null,LocalizedEmptyString:""});class K extends Error{message;constructor(e){super(e),this.message=e}}var P=Object.freeze({__proto__:null,UserVisibleError:K,isUserVisibleError:function(e){return"object"==typeof e&&null!==e&&e instanceof K}});export{i as ArrayUtilities,a as Brand,u as DOMUtilities,s as DateUtilities,l as DevToolsPath,f as KeyboardUtilities,p as MapUtilities,b as MimeType,_ as NumberUtilities,E as PromiseUtilities,R as StringUtilities,z as Timing,I as TypeScriptUtilities,B as TypedArrayUtilities,W as UIString,P as UserVisibleError,V as assertNever,k as assertNotNullOrUndefined,D as assertUnhandled}; | |||
| function e(e,t,r){const n=e[t];e[t]=e[r],e[r]=n}function t(r,n,o,i,a,s){if(i<=o)return;const l=function(t,r,n,o,i){const a=t[i];e(t,o,i);let s=n;for(let i=n;i<o;++i)r(t[i],a)<0&&(e(t,s,i),++s);return e(t,o,s),s}(r,n,o,i,Math.floor(Math.random()*(i-o))+o);a<l&&t(r,n,o,l-1,a,s),l<s&&t(r,n,l+1,i,a,s)}function r(e,t,r,n){const o=[];let i=0,a=0;for(;i<e.length&&a<t.length;){const s=r(e[i],t[a]);!n&&s||o.push(s<=0?e[i]:t[a]),s<=0&&i++,s>=0&&a++}if(n){for(;i<e.length;)o.push(e[i++]);for(;a<t.length;)o.push(t[a++])}return o}function n(e,t,r,n,o){let i=n||0,a=void 0!==o?o:e.length;for(;i<a;){const n=i+a>>1;r(t,e[n])>0?i=n+1:a=n}return a}function o(e,t,r){const n="END"===r;if(0===e.length)return null;let o=0,i=e.length-1,a=0,s=!1,l=!1,u=0;do{u=o+(i-o)/2,a=n?Math.ceil(u):Math.floor(u),s=t(e[a]),l=s===n,l?o=Math.min(i,a+(o===a?1:0)):i=Math.max(o,a+(i===a?-1:0))}while(i!==o);return t(e[o])?o:null}var i=Object.freeze({__proto__:null,DEFAULT_COMPARATOR:(e,t)=>e<t?-1:e>t?1:0,arrayDoesNotContainNullOrUndefined:function(e){return!e.includes(null)&&!e.includes(void 0)},binaryIndexOf:(e,t,r)=>{const o=n(e,t,r);return o<e.length&&0===r(t,e[o])?o:-1},intersectOrdered:(e,t,n)=>r(e,t,n,!1),lowerBound:n,mergeOrdered:(e,t,n)=>r(e,t,n,!0),nearestIndexFromBeginning:function(e,t){return o(e,t,"BEGINNING")},nearestIndexFromEnd:function(e,t){return o(e,t,"END")},removeElement:(e,t,r)=>{let n=e.indexOf(t);if(-1===n)return!1;if(r)return e.splice(n,1),!0;for(let r=n+1,o=e.length;r<o;++r)e[r]!==t&&(e[n++]=e[r]);return e.length=n,!0},sortRange:function(e,r,n,o,i,a){return 0===n&&o===e.length-1&&0===i&&a>=o?e.sort(r):t(e,r,n,o,i,a),e},upperBound:function(e,t,r,n,o){let i=n||0,a=void 0!==o?o:e.length;for(;i<a;){const n=i+a>>1;r(t,e[n])>=0?i=n+1:a=n}return a}}),a=Object.freeze({__proto__:null}),s=Object.freeze({__proto__:null});var l=Object.freeze({__proto__:null,isValid:e=>!isNaN(e.getTime()),toISO8601Compact:e=>{function t(e){return(e>9?"":"0")+e}return e.getFullYear()+t(e.getMonth()+1)+t(e.getDate())+"T"+t(e.getHours())+t(e.getMinutes())+t(e.getSeconds())}});var u=Object.freeze({__proto__:null,EmptyEncodedPathString:"",EmptyRawPathString:"",EmptyUrlString:"",urlString:(e,...t)=>String.raw({raw:e},...t)});var c=Object.freeze({__proto__:null,deepActiveElement:function(e){let t=e.activeElement;for(;t?.shadowRoot?.activeElement;)t=t.shadowRoot.activeElement;return t},getEnclosingShadowRootForNode:function(e){let t=e.parentNodeOrShadowHost();for(;t;){if(t instanceof ShadowRoot)return t;t=t.parentNodeOrShadowHost()}return null},rangeOfWord:function(e,t,r,n,o){let i,a,s=0,l=0;if(n||(n=e),o&&"backward"!==o&&"both"!==o)i=e,s=t;else{let o=e;for(;o;){if(o===n){i||(i=n);break}if(o.nodeType===Node.TEXT_NODE&&null!==o.nodeValue){for(let n=o===e?t-1:o.nodeValue.length-1;n>=0;--n)if(-1!==r.indexOf(o.nodeValue[n])){i=o,s=n+1;break}}if(i)break;o=o.traversePreviousNode(n)}i||(i=n,s=0)}if(o&&"forward"!==o&&"both"!==o)a=e,l=t;else{let o=e;for(;o;){if(o===n){a||(a=n);break}if(o.nodeType===Node.TEXT_NODE&&null!==o.nodeValue){for(let n=o===e?t:0;n<o.nodeValue.length;++n)if(-1!==r.indexOf(o.nodeValue[n])){a=o,l=n;break}}if(a)break;o=o.traverseNextNode(n)}a||(a=n,l=n.nodeType===Node.TEXT_NODE?n.nodeValue?.length||0:n.childNodes.length)}if(!e.ownerDocument)throw new Error("No `ownerDocument` found for rootNode");const u=e.ownerDocument.createRange();return u.setStart(i,s),u.setEnd(a,l),u}});const f=new Set(["ArrowUp","ArrowDown","ArrowLeft","ArrowRight"]);var h=Object.freeze({__proto__:null,ARROW_KEYS:f,ENTER_KEY:"Enter",ESCAPE_KEY:"Escape",TAB_KEY:"Tab",isEnterOrSpaceKey:function(e){return"Enter"===e.key||" "===e.key},isEscKey:function(e){return"Escape"===e.key},keyIsArrowKey:function(e){return f.has(e)}});class p{map=new Map;set(e,t){let r=this.map.get(e);r||(r=new Set,this.map.set(e,r)),r.add(t)}get(e){return this.map.get(e)||new Set}has(e){return this.map.has(e)}hasValue(e,t){const r=this.map.get(e);return!!r&&r.has(t)}get size(){return this.map.size}delete(e,t){const r=this.get(e);if(!r)return!1;const n=r.delete(t);return r.size||this.map.delete(e),n}deleteAll(e){this.map.delete(e)}keysArray(){return[...this.map.keys()]}keys(){return this.map.keys()}valuesArray(){const e=[];for(const t of this.map.values())e.push(...t.values());return e}clear(){this.map.clear()}}var g=Object.freeze({__proto__:null,Multimap:p,getWithDefault:function(e,t,r){let n=e.get(t);return null==n&&(n=r(t),e.set(t,n)),n},inverse:function(e){const t=new p;for(const[r,n]of e.entries())t.set(n,r);return t}});const d=new Set(["application/ecmascript","application/javascript","application/json","application/json+protobuf","application/mpegurl","application/vnd.apple.mpegurl","application/vnd.dart","application/xml","application/x-aspx","application/x-javascript","application/x-jsp","application/x-httpd-php","application/x-mpegurl","audio/mpegurl","audio/x-mpegurl"]);function m(e,t,r=0){for(let n=r;n<e.length;n++)if(t.includes(e[n]))return n;return-1}function b(e,t,r=0){for(let n=r;n<e.length;n++)if(!t.includes(e[n]))return n;return-1}var w=Object.freeze({__proto__:null,isTextType:function(e){return e.startsWith("text/")||e.startsWith("multipart/")||e.includes("+json")||e.endsWith("+xml")||d.has(e)},parseContentType:function(e){if("*/*"===e)return{mimeType:null,charset:null};const{mimeType:t,params:r}=function(e){e=e.trim();let t=m(e," \t;(");t<0&&(t=e.length);const r=e.indexOf("/");if(r<0||r>t)return{mimeType:null,params:new Map};const n=e.substring(0,t).toLowerCase(),o=new Map;let i=e.indexOf(";",t);for(;i>=0&&i<e.length;){if(++i,i=b(e," \t",i),i<0)continue;const t=i;if(i=m(e,";=",i),i<0||";"===e[i])continue;const r=e.substring(t,i).toLowerCase();++i,i=b(e," \t",i);let n="";if(!(i<0||";"===e[i])){if('"'!==e[i]){const t=i;i=e.indexOf(";",i);const r=i>=0?i:e.length;n=e.substring(t,r).trimEnd()}else{for(++i;i<e.length&&'"'!==e[i];)"\\"===e[i]&&i+1<e.length&&++i,n+=e[i],++i;i=e.indexOf(";",i)}o.has(r)||o.set(r,n)}}return{mimeType:n,params:o}}(e);return{mimeType:t,charset:r.get("charset")?.toLowerCase().trim()??null}}});const _=(e,t)=>{for(e=Math.round(e),t=Math.round(t);0!==t;){const r=t;t=e%t,e=r}return e},x=new Map([["8∶5","16∶10"]]);var E=Object.freeze({__proto__:null,aspectRatio:(e,t)=>{const r=_(e,t);0!==r&&(e/=r,t/=r);const n=`${e}∶${t}`;return x.get(n)||n},clamp:(e,t,r)=>{let n=e;return e<t?n=t:e>r&&(n=r),n},floor:(e,t=0)=>{if(t>0&&t<1)return t=1/t,Math.floor(e/t)*t;const r=Math.pow(10,t);return Math.floor(e*r)/r},greatestCommonDivisor:_,mod:(e,t)=>(e%t+t)%t,toFixedIfFloating:e=>{if(!e||Number.isNaN(Number(e)))return e;const t=Number(e);return t%1?t.toFixed(3):String(t)},withThousandsSeparator:function(e){let t=String(e);const r=/(\d+)(\d{3})/;for(;t.match(r);)t=t.replace(r,"$1 $2");return t}});const O=(e,t)=>{let r=!1;for(let n=0;n<t.length;++n)if(-1!==e.indexOf(t.charAt(n))){r=!0;break}if(!r)return String(e);let n="";for(let r=0;r<e.length;++r)-1!==t.indexOf(e.charAt(r))&&(n+="\\"),n+=e.charAt(r);return n},N=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),y=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),A=(e,t)=>{const r=[];let n=e.indexOf(t);for(;-1!==n;)r.push(n),n=e.indexOf(t,n+t.length);return r},S=/^([a-z0-9]+(?:-[a-z0-9]+)*\.)*[a-z0-9]+(?:-[a-z0-9]+)*$/,v="^[]{}()\\.^$*+?|-,",C=function(){return v},T=function(e,t){let r="";for(let t=0;t<e.length;++t){const n=e.charAt(t);-1!==C().indexOf(n)&&(r+="\\"),r+=n}return new RegExp(r,t||"")};const U=/[A-Z]{2,}(?=[A-Z0-9][a-z0-9]+|\b|_)|[A-Za-z][0-9]+[a-z]?|[A-Z]?[a-z]+|[0-9][A-Za-z]+|[A-Z]|[0-9]+|[.]/g,z=function(e){return e.match?.(U)?.map((e=>e.toLowerCase())).join("-").replaceAll("-.-",".")||e};var L=Object.freeze({__proto__:null,DOUBLE_QUOTE:'"',SINGLE_QUOTE:"'",base64ToSize:function(e){if(!e)return 0;let t=3*e.length/4;return"="===e[e.length-1]&&t--,e.length>1&&"="===e[e.length-2]&&t--,t},caseInsensetiveComparator:function(e,t){return(e=e.toUpperCase())===(t=t.toUpperCase())?0:e>t?1:-1},collapseWhitespace:e=>e.replace(/[\s\xA0]+/g," "),compare:(e,t)=>e>t?1:e<t?-1:0,concatBase64:function(e,t){if(0===e.length||!e.endsWith("="))return e+t;const r=e.substring(0,e.length-4),n=e.substring(e.length-4);return r+window.btoa(window.atob(n)+window.atob(t))},countUnmatchedLeftParentheses:e=>{let t=0;for(const r of e)"("===r?t++:")"===r&&t>0&&t--;return t},countWtf8Bytes:e=>{let t=0;for(let r=0;r<e.length;r++){const n=e.charCodeAt(r);if(n<=127)t++;else if(n<=2047)t+=2;else if(n<55296||57343<n)t+=3;else{if(n<=56319&&r+1<e.length){const n=e.charCodeAt(r+1);if(56320<=n&&n<=57343){t+=4,r++;continue}}t+=3}}return t},createPlainTextSearchRegex:T,createSearchRegex:function(e,t,r,n=!1){const o=t?"g":"gi";let i;if(r)try{i=new RegExp(e,o)}catch{}return i||(i=T(e,o)),n&&i&&(i=new RegExp(`\\b${i.source}\\b`,o)),i},escapeCharacters:O,escapeForRegExp:e=>O(e,v),filterRegex:function(e){let t="^(?:.*\\0)?";for(let r=0;r<e.length;++r){let n=e.charAt(r);-1!==v.indexOf(n)&&(n="\\"+n),t+="[^\\0"+n+"]*"+n}return new RegExp(t,"i")},findIndexesOfSubString:A,findLineEndingIndexes:e=>{const t=A(e,"\n");return t.push(e.length),t},findUnclosedCssQuote:function(e){let t="";for(let r=0;r<e.length;++r){const n=e[r];"\\"!==n?"'"!==n&&'"'!==n||(t===n?t="":""===t&&(t=n)):r++}return t},formatAsJSLiteral:e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=(e,t,r,n)=>{if(r){if(y.has(r))return y.get(r);return"\\x"+N(r.charCodeAt(0),2)}if(n){return"\\u"+N(n.charCodeAt(0),4)}return t?y.get(t)||"":e};let o="",i="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(i="'",o=e.replaceAll(r,n)):(i="`",o=e.replaceAll(t,n)):(i='"',o=e.replaceAll(t,n)):(i="'",o=e.replaceAll(t,n)),`${i}${o}${i}`},hashCode:function(e){if(!e)return 0;const t=4294967291;let r=0,n=1;for(let o=0;o<e.length;o++){r=(r+n*(1506996573*e.charCodeAt(o)))%t,n=1345575271*n%t}return r=(r+n*(t-1))%t,Math.abs(0|r)},isExtendedKebabCase:e=>S.test(e),isWhitespace:e=>/^\s*$/.test(e),naturalOrderComparator:(e,t)=>{const r=/^\d+|^\D+/;let n,o,i,a;for(;;){if(!e)return t?-1:0;if(!t)return 1;if(n=e.match(r)[0],o=t.match(r)[0],i=!Number.isNaN(Number(n)),a=!Number.isNaN(Number(o)),i&&!a)return-1;if(a&&!i)return 1;if(i&&a){const e=Number(n)-Number(o);if(e)return e;if(n.length!==o.length)return Number(n)||Number(o)?o.length-n.length:n.length-o.length}else if(n!==o)return n<o?-1:1;e=e.substring(n.length),t=t.substring(o.length)}},regexSpecialCharacters:C,removeURLFragment:e=>{const t=new URL(e);return t.hash="",t.toString()},replaceControlCharacters:e=>e.replace(/[\0-\x08\x0B\f\x0E-\x1F\x80-\x9F]/g,"�"),replaceLast:function(e,t,r){const n=e.lastIndexOf(t);return-1===n?e:e.slice(0,n)+e.slice(n).replace(t,r)},reverse:e=>e.split("").reverse().join(""),sprintf:(e,...t)=>{let r=0;return e.replaceAll(/%(?:(\d+)\$)?(?:\.(\d*))?([%dfs])/g,((e,n,o,i)=>{if("%"===i)return"%";if(void 0!==n&&(r=parseInt(n,10)-1,r<0))throw new RangeError(`Invalid parameter index ${r+1}`);if(r>=t.length)throw new RangeError(`Expected at least ${r+1} format parameters, but only ${t.length} where given.`);if("s"===i){const e=String(t[r++]);return void 0!==o?e.substring(0,Number(o)):e}let a=Number(t[r++]);return isNaN(a)&&(a=0),"d"===i?String(Math.floor(a)).padStart(Number(o),"0"):void 0!==o?a.toFixed(Number(o)):String(a)}))},stringifyWithPrecision:function(e,t=2){if(0===t)return e.toFixed(0);const r=e.toFixed(t).replace(/\.?0*$/,"");return"-0"===r?"0":r},stripLineBreaks:e=>e.replace(/(\r)?\n/g,""),toBase64:e=>{function t(e){return e<26?e+65:e<52?e+71:e<62?e-4:62===e?43:63===e?47:65}const r=(new TextEncoder).encode(e.toString()),n=r.length;let o,i="";if(0===n)return i;let a=0;for(let e=0;e<n;e++)o=e%3,a|=r[e]<<(16>>>o&24),2===o&&(i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),t(a>>>6&63),t(63&a)),a=0);return 0===o?i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),61,61):1===o&&(i+=String.fromCharCode(t(a>>>18&63),t(a>>>12&63),t(a>>>6&63),61)),i},toKebabCase:z,toKebabCaseKeys:function(e){const t={};for(const[r,n]of Object.entries(e))t[z(r)]=n;return t},toLowerCaseString:function(e){return e.toLowerCase()},toTitleCase:e=>e.substring(0,1).toUpperCase()+e.substring(1),trimEndWithMaxLength:(e,t)=>e.length<=t?String(e):e.substr(0,t-1)+"…",trimMiddle:(e,t)=>{if(e.length<=t)return String(e);let r=t>>1,n=t-r-1;return e.codePointAt(e.length-n-1)>=65536&&(--n,++r),r>0&&e.codePointAt(r-1)>=65536&&--r,e.substr(0,r)+"…"+e.substr(e.length-n,n)},trimURL:(e,t)=>{let r=e.replace(/^(https|http|file):\/\//i,"");return t&&r.toLowerCase().startsWith(t.toLowerCase())&&(r=r.substr(t.length)),r}});var M=Object.freeze({__proto__:null,microSecondsToMilliSeconds:function(e){return e/1e3},milliSecondsToSeconds:function(e){return e/1e3}});class R extends Uint32Array{getValue(e){return this[e]}setValue(e,t){this[e]=t}asUint32ArrayOrFail(){return this}asArrayOrFail(){throw new Error("Not an array")}}class j{#e;#t;length;constructor(e,t){this.#e=[],this.length=e;let r=1;for(;;){r*=2,this.#t=Math.ceil(e/r);try{if(void 0!==t&&this.#t>t)throw new RangeError;for(let e=0;e<r;++e)this.#e[e]=new Uint32Array(this.#t);return}catch(e){if(this.#t<1e6)throw e}}}getValue(e){if(e>=0&&e<this.length){const t=this.#t;return this.#e[Math.floor(e/t)][e%t]}return this.#e[0][-1]}setValue(e,t){if(e>=0&&e<this.length){const r=this.#t;this.#e[Math.floor(e/r)][e%r]=t}}asUint32ArrayOrFail(){throw new Error("Not a Uint32Array")}asArrayOrFail(){throw new Error("Not an array")}}class F extends Array{getValue(e){return this[e]}setValue(e,t){this[e]=t}asUint32ArrayOrFail(){throw new Error("Not a Uint32Array")}asArrayOrFail(){return this}}class $ extends Uint8Array{constructor(e){super("number"==typeof e?Math.ceil(e/8):e)}getBit(e){return 0!==(this[e>>3]&1<<(7&e))}setBit(e){this[e>>3]|=1<<(7&e)}clearBit(e){this[e>>3]&=~(1<<(7&e))}previous(e){for(;e!==e>>3<<3;)if(--e,this.getBit(e))return e;let t=(e>>3)-1;for(;t>=0&&0===this[t];)--t;if(t<0)return-1;for(e=7+(t<<3);e>=t<<3;--e)if(this.getBit(e))return e;throw new Error("Unreachable")}}var B=Object.freeze({__proto__:null,createBitVector:function(e){return new $(e)},createExpandableBigUint32Array:function(){return new F},createFixedBigUint32Array:function(e,t){try{if(void 0!==t&&e>t)throw new RangeError;return new R(e)}catch{return new j(e,t)}}});function V(e,t){if(null==e)throw new Error(`Expected given value to not be null/undefined but it was: ${e}${t?`\n${t}`:""}`)}function k(e,t){throw new Error(t)}function D(e){return e}var I=Object.freeze({__proto__:null,assertNever:k,assertNotNullOrUndefined:V,assertUnhandled:D});var W=Object.freeze({__proto__:null,LocalizedEmptyString:""});class K extends Error{message;constructor(e){super(e),this.message=e}}var P=Object.freeze({__proto__:null,UserVisibleError:K,isUserVisibleError:function(e){return"object"==typeof e&&null!==e&&e instanceof K}});export{i as ArrayUtilities,a as Brand,s as Constructor,c as DOMUtilities,l as DateUtilities,u as DevToolsPath,h as KeyboardUtilities,g as MapUtilities,w as MimeType,E as NumberUtilities,L as StringUtilities,M as Timing,I as TypeScriptUtilities,B as TypedArrayUtilities,W as UIString,P as UserVisibleError,k as assertNever,V as assertNotNullOrUndefined,D as assertUnhandled}; | |||
Check failure
Code scanning / CodeQL
Incomplete multi-character sanitization High library
<!--
| @@ -1 +1 @@ | |||
| var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t||(t={})),function(e){e.Navigation="navigation"}(n||(n={}));var r=Object.freeze({__proto__:null,get AssertedEventType(){return n},get SelectorType(){return e},get StepType(){return t}});function i(e){throw new Error(`Unknown step type: ${e.type}`)}const a=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function p(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function l(e){return"object"==typeof e&&null!==e}function c(e){return"string"==typeof e}function u(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function d(e){if(p(e,"target")&&c(e.target))return e.target}function w(e){if(p(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(p(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(p(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function g(e,t){if(p(e,t))return h(e,t)}function y(e,t){if(p(e,t))return S(e,t)}function b(e,t){if(p(e,t))return m(e,t)}function S(e,t){if(p(e,t)){const n=e[t];if(c(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!p(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!c(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!c(e))throw new Error("Selector element is not a string");return e})):e}))}function v(e){if(p(e,"selectors"))return E(e)}function L(e){if(!l(e))throw new Error("Asserted event is not an object");if(!p(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:y(e,"url"),title:y(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(p(t,"timeout")&&u(t.timeout)&&!j(t.timeout))throw new Error(R);return{type:e,assertedEvents:p(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:p(t,"timeout")&&u(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:d(t)}}function x(e,t){return{...A(e,t),frame:w(t)}}function C(e,t){return{...x(e,t),selectors:E(t)}}function T(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:g(e,"duration")},n=y(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const i=y(e,"button");if(i){if(!function(e){return"string"==typeof e&&s.has(e)}(i))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=i}return t}function $(e,n){if(!l(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!p(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!c(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...C(t.Click,e),...T(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...C(t.DoubleClick,e),...T(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...C(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...C(t.Change,e),type:t.Change,value:S(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:S(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:S(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...x(t.Scroll,e),type:t.Scroll,x:g(e,"x"),y:g(e,"y"),selectors:v(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:d(e),url:S(e,"url")}}(e);case t.CustomStep:return function(e){if(!p(e,"name"))throw new Error("customStep is missing name");if(!c(e.name))throw new Error("customStep's name is not a string");return{...x(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:p(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=y(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(p(e,"attributes")&&(!l(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(p(e,"properties")&&!l(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...C(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:g(e,"count"),visible:b(e,"visible"),attributes:p(e,"attributes")?e.attributes:void 0,properties:p(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!p(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...x(t.WaitForExpression,e),type:t.WaitForExpression,expression:S(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function N(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push($(r,n));return t}const P=1,I=3e4,R=`Timeout is not between ${P} and ${I} milliseconds`;function j(e){return e>=P&&e<=I}function W(e){if(!l(e))throw new Error("Recording is not an object");if(!p(e,"title"))throw new Error("Recording is missing `title`");if(!c(e.title))throw new Error("Recording `title` is not a string");if(p(e,"timeout")&&!u(e.timeout))throw new Error("Recording `timeout` is not a number");if(!p(e,"steps"))throw new Error("Recording is missing `steps`");if(p(e,"timeout")&&u(e.timeout)&&!j(e.timeout))throw new Error(R);return t={title:e.title,timeout:p(e,"timeout")&&u(e.timeout)?e.timeout:void 0,selectorAttribute:p(e,"selectorAttribute")&&c(e.selectorAttribute)?e.selectorAttribute:void 0,steps:N(e.steps)},JSON.parse(JSON.stringify(t));var t}function B(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}function O(t){function n(e){return e.replace(/['"()]/g,"\\$&")}Array.isArray(t)||(t=[t]);return t.map((t=>{switch(B(t)){case e.ARIA:return`::-p-aria(${n(t.substring(e.ARIA.length+1))})`;case e.CSS:return t;case e.XPath:return`::-p-xpath(${n(t.substring(e.XPath.length+1))})`;case e.Pierce:return`:scope >>> ${t.substring(e.Pierce.length+1)}`;case e.Text:return`::-p-text(${n(t.substring(e.Text.length+1))})`}})).join(" >>>> ")}class D{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class H extends D{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const i=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+i)}}class K{#e;#t=0;#n=[];constructor(e){this.#e=e}appendLine(e){const t=e.split("\n").map((e=>e?this.#e.repeat(this.#t)+e.trimEnd():""));return this.#n.push(...t),this}startBlock(){return this.#t++,this}endBlock(){if(this.#t--,this.#t<0)throw new Error("Extra endBlock");return this}toString(){return this.#n.join("\n")+"\n"}getIndent(){return this.#e}getSize(){return this.#n.length}}function V(e,t){const n=[];return U(e,n,1,t),n.join("")}function U(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(X(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let i=0;i<e.length;i++)t.push(r.repeat(n)),U(e[i],t,n+1,r),i!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const i=Object.keys(e);for(let a=0;a<i.length;a++){const o=i[a],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),U(s,t,n+1,r),a!==i.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}const q=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),M=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),X=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(M.has(n))return M.get(n);return"\\x"+q(n.charCodeAt(0),2)}if(r){return"\\u"+q(r.charCodeAt(0),4)}return t?M.get(t)||"":e};let i="",a="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(a="'",i=e.replace(n,r)):(a="`",i=e.replace(t,r)):(a='"',i=e.replace(t,r)):(a="'",i=e.replace(t,r)),`${a}${i}${a}`};class J extends D{#r=!1;async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v22.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||Y};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine(""),this.#r=!1}async afterAllSteps(e,t){if(e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine(""),this.#r)for(const t of _.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),this.#i(e,t),t.assertedEvents){e.appendLine("const promises = [];"),e.appendLine("const startWaitingForEvents = () => {").startBlock();for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}e.endBlock().appendLine("}")}this.#a(e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}#o(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${V(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))}#s(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)}#i(e,t){this.#o(e,t.target||"main"),t.frame&&this.#s(e,t.frame)}#p(e,t,n){e.appendLine("await puppeteer.Locator.race([").startBlock(),e.appendLine(t.selectors.map((n=>`${t.frame?"frame":"targetPage"}.locator(${V(O(n),e.getIndent())})`)).join(",\n")),e.endBlock().appendLine("])"),e.startBlock().appendLine(".setTimeout(timeout)"),t.assertedEvents?.length&&e.appendLine(".on('action', () => startWaitingForEvents())"),n(),e.endBlock()}#l(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#c(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),e.appendLine(" count: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#u(e,t){this.#p(e,t,(()=>{e.appendLine(".hover();")}))}#f(e,t){this.#p(e,t,(()=>{e.appendLine(`.fill(${V(t.value,e.getIndent())});`)}))}#d(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")}#w(e,t){e.appendLine(`await targetPage.keyboard.down(${V(t.key,e.getIndent())});`)}#h(e,t){e.appendLine(`await targetPage.keyboard.up(${V(t.key,e.getIndent())});`)}#m(e,t){e.appendLine("await targetPage.close()")}#g(e,t){e.appendLine(`await targetPage.setViewport(${V({width:t.width,height:t.height},e.getIndent())})`)}#y(e,t){"selectors"in t?this.#p(e,t,(()=>{e.appendLine(`.scroll({ scrollTop: ${t.y}, scrollLeft: ${t.x}});`)})):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)}#a(e,n){switch(n.type){case t.Click:return this.#l(e,n);case t.DoubleClick:return this.#c(e,n);case t.Hover:return this.#u(e,n);case t.Change:return this.#f(e,n);case t.EmulateNetworkConditions:return this.#d(e,n);case t.KeyDown:return this.#w(e,n);case t.KeyUp:return this.#h(e,n);case t.Close:return this.#m(e,n);case t.SetViewport:return this.#g(e,n);case t.Scroll:return this.#y(e,n);case t.Navigate:return this.#b(e,n);case t.WaitForElement:return this.#S(e,n);case t.WaitForExpression:return this.#E(e,n);case t.CustomStep:return;default:return i(n)}}#b(e,t){t.assertedEvents?.length&&e.appendLine("startWaitingForEvents();"),e.appendLine(`await targetPage.goto(${V(t.url,e.getIndent())});`)}#E(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${V(t.expression,e.getIndent())}, { timeout });`)}#S(e,t){this.#r=!0,e.appendLine(`await waitForElement(${V(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)}}const Y=5e3,_="async function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}",z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",G=z.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map),Q=31,Z=32,ee=2147483647;function te(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>ee)throw new Error("Only integers between 0 and "+ee+" are supported");const t=[];do{let n=e&Q;(e>>>=5)>0&&(n|=Z),t.push(z[n])}while(0!==e);return t.join("")}function ne(e){const t=[],n=e.split("");let r=0,i=0;for(const e of n){const n=G.get(e);r|=(n&Q)<<i,i+=5;n&Z||(t.push(r),r=0,i=0)}return t}const re="//# recorderSourceMap=";async function ie(e,t){t||(t={});const n=t.extension??new J,r=t.writer??new K(t.indentation??" ");await(n.beforeAllSteps?.(r,e));const i=[1];for(const t of e.steps){const a=r.getSize();await(n.beforeEachStep?.(r,t,e)),await n.stringifyStep(r,t,e),await(n.afterEachStep?.(r,t,e));const o=r.getSize();i.push(a,o-a)}return await(n.afterAllSteps?.(r,e)),r.appendLine(re+function(e){const t=[];for(const n of e)t.push(te(n));return t.join("")}(i)),r.toString()}async function ae(e,t){t||(t={});let n=t.extension;n||(n=new J),t.indentation||(t.indentation=" ");const r=t.writer??new K(t.indentation??" ");return await(n.beforeEachStep?.(r,e)),await n.stringifyStep(r,e),await(n.afterEachStep?.(r,e)),r.toString()}function oe(e){return e.trim().startsWith(re)}function se(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(oe(n))return ne(n.trim().substring(re.length))}}function pe(e){return e.split("\n").filter((e=>!oe(e))).join("\n")}class le{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}const ce={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};function ue(e){return new Promise((t=>{setTimeout(t,e)}))}class fe extends le{browser;page;timeout;constructor(e,t,n){super(),this.browser=e,this.page=t,this.timeout=n?.timeout||5e3}async#v(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}}#L(e,t){return e.timeout||t?.timeout||this.timeout}async runStep(e,t){const n=this.#L(e,t),r=this.page,i=this.browser,a=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const i=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),a=await i.page();if(!a)return null;return a.setDefaultTimeout(r),a}(i,r,e,n);let o=null;if(!a&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||a;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await this.#v(s);const p=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,p,n)}async runStepInFrame(e,r,a,o,p){let l=null;const c=()=>{l=async function(e,t,r){const i=[];if(t.assertedEvents)for(const a of t.assertedEvents){if(a.type!==n.Navigation)throw new Error(`Event type ${a.type} is not supported`);i.push(e.waitForNavigation({timeout:r}))}await Promise.all(i)}(o,e,p)},u=this.page.locatorRace;switch(e.type){case t.DoubleClick:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({count:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}});break;case t.Click:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}});break;case t.Hover:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).hover();break;case t.EmulateNetworkConditions:c(),await r.emulateNetworkConditions(e);break;case t.KeyDown:c(),await r.keyboard.down(e.key),await ue(100);break;case t.KeyUp:c(),await r.keyboard.up(e.key),await ue(100);break;case t.Close:"close"in a&&(c(),await a.close());break;case t.Change:await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).fill(e.value);break;case t.SetViewport:"setViewport"in a&&(c(),await a.setViewport(e));break;case t.Scroll:"selectors"in e?await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).scroll({scrollLeft:e.x||0,scrollTop:e.y||0}):(c(),await o.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0));break;case t.Navigate:c(),await o.goto(e.url);break;case t.WaitForElement:try{c(),await async function(e,t,n){const{count:r=1,operator:i=">=",visible:a=!0,properties:o,attributes:s}=e,p=ce[i];await async function(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}((async()=>{const n=await async function(e,t){for(const n of e){const e=await we(n,t);if(e.length)return e}return[]}(e.selectors,t);let i=p(n.length,r);const l=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),i&&(o||s)&&(i=await l.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,i]of Object.entries(e))if(!r(i,t[n]))return!1;return!0}}),o,s)),await l.dispose(),i===a}),n)}(e,o,p)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:c(),await o.waitForFunction(e.expression,{timeout:p});break;case t.CustomStep:break;default:i(e)}await l}}class de extends fe{async afterAllSteps(){await this.browser.close()}}async function we(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function he(e,t,n){await(e.beforeEachStep?.(t,n)),await e.runStep(t,n),await(e.afterEachStep?.(t,n))}class me{#k;#F;#A=!1;constructor(e){this.#F=e}abort(){this.#A=!0}set flow(e){this.#k=e}async runBeforeAllSteps(e){await(this.#F.beforeAllSteps?.(e))}async runAfterAllSteps(e){await(this.#F.afterAllSteps?.(e))}async runStep(e){await he(this.#F,e)}async run(){if(!this.#k)throw new Error("Set the flow on the runner instance before calling `run`.");const e=this.#k;if(this.#A=!1,await(this.#F.beforeAllSteps?.(e)),this.#A)return!1;for(const t of e.steps){if(this.#A)return await(this.#F.afterAllSteps?.(e)),!1;await he(this.#F,t,e)}return await(this.#F.afterAllSteps?.(e)),!0}}async function ge(e,t){const n=e instanceof le?void 0:e,r=new me((e instanceof le?e:t)??await async function(){const{default:e}=await import("puppeteer"),t=await e.launch(),n=await t.newPage();return new de(t,n)}());return n&&(r.flow=n),r}class ye extends D{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${V(t,e.getIndent())});`)}}function be(e){return Boolean(e.type===t.Navigate||e.assertedEvents?.some((e=>e.type===n.Navigation)))}function Se(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ee extends J{#x=!1;async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${V({screenEmulation:{disabled:!0}},e.getIndent())}`),Se(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${V(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const i=be(n);i?(this.#x&&(e.appendLine("await lhFlow.endTimespan();"),this.#x=!1),e.appendLine("await lhFlow.startNavigation();")):this.#x||(e.appendLine("await lhFlow.startTimespan();"),this.#x=!0),await super.stringifyStep(e,n,r),i&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){this.#x&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}class ve extends fe{#C=!1;#T=!1;#$;async createFlowResult(){if(!this.#$)throw new Error("Cannot get flow result before running the flow");return this.#$.createFlowResult()}async beforeAllSteps(e){await(super.beforeAllSteps?.(e));const{startFlow:t,desktopConfig:n}=await import("lighthouse");let r;Se(e)||(r=n),this.#$=await t(this.page,{config:r,flags:{screenEmulation:{disabled:!0}},name:e.title})}async beforeEachStep(e,n){await(super.beforeEachStep?.(e,n)),e.type!==t.SetViewport&&(be(e)?(this.#C&&(await this.#$.endTimespan(),this.#C=!1),await this.#$.startNavigation(),this.#T=!0):this.#C||(await this.#$.startTimespan(),this.#C=!0))}async afterEachStep(e,t){this.#T&&(await this.#$.endNavigation(),this.#T=!1),await(super.afterEachStep?.(e,t))}async afterAllSteps(e){this.#C&&await this.#$.endTimespan(),await(super.afterAllSteps?.(e))}}export{n as AssertedEventType,H as JSONStringifyExtension,ve as LighthouseRunnerExtension,Ee as LighthouseStringifyExtension,ye as PuppeteerReplayStringifyExtension,fe as PuppeteerRunnerExtension,de as PuppeteerRunnerOwningBrowserExtension,J as PuppeteerStringifyExtension,me as Runner,le as RunnerExtension,r as Schema,e as SelectorType,t as StepType,D as StringifyExtension,i as assertAllStepTypesAreHandled,ge as createRunner,X as formatAsJSLiteral,V as formatJSONAsJS,B as getSelectorType,I as maxTimeout,P as minTimeout,s as mouseButtonMap,W as parse,se as parseSourceMap,$ as parseStep,o as pointerDeviceTypes,O as selectorToPElementSelector,ie as stringify,ae as stringifyStep,pe as stripSourceMap,a as typeableInputTypes,j as validTimeout}; | |||
| var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t||(t={})),function(e){e.Navigation="navigation"}(n||(n={}));var r=Object.freeze({__proto__:null,get AssertedEventType(){return n},get SelectorType(){return e},get StepType(){return t}});function i(e){throw new Error(`Unknown step type: ${e.type}`)}const a=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function p(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function l(e){return"object"==typeof e&&null!==e}function c(e){return"string"==typeof e}function u(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function d(e){if(p(e,"target")&&c(e.target))return e.target}function w(e){if(p(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(p(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(p(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function g(e,t){if(p(e,t))return h(e,t)}function y(e,t){if(p(e,t))return S(e,t)}function b(e,t){if(p(e,t))return m(e,t)}function S(e,t){if(p(e,t)){const n=e[t];if(c(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!p(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!c(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!c(e))throw new Error("Selector element is not a string");return e})):e}))}function v(e){if(p(e,"selectors"))return E(e)}function L(e){if(!l(e))throw new Error("Asserted event is not an object");if(!p(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:y(e,"url"),title:y(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(p(t,"timeout")&&u(t.timeout)&&!j(t.timeout))throw new Error(R);return{type:e,assertedEvents:p(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:p(t,"timeout")&&u(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:d(t)}}function x(e,t){return{...A(e,t),frame:w(t)}}function C(e,t){return{...x(e,t),selectors:E(t)}}function T(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:g(e,"duration")},n=y(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const i=y(e,"button");if(i){if(!function(e){return"string"==typeof e&&s.has(e)}(i))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=i}return t}function $(e,n){if(!l(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!p(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!c(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...C(t.Click,e),...T(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...C(t.DoubleClick,e),...T(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...C(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...C(t.Change,e),type:t.Change,value:S(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:S(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:S(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...x(t.Scroll,e),type:t.Scroll,x:g(e,"x"),y:g(e,"y"),selectors:v(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:d(e),url:S(e,"url")}}(e);case t.CustomStep:return function(e){if(!p(e,"name"))throw new Error("customStep is missing name");if(!c(e.name))throw new Error("customStep's name is not a string");return{...x(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:p(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=y(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(p(e,"attributes")&&(!l(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(p(e,"properties")&&!l(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...C(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:g(e,"count"),visible:b(e,"visible"),attributes:p(e,"attributes")?e.attributes:void 0,properties:p(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!p(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...x(t.WaitForExpression,e),type:t.WaitForExpression,expression:S(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function N(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push($(r,n));return t}const P=1,I=3e4,R=`Timeout is not between ${P} and ${I} milliseconds`;function j(e){return e>=P&&e<=I}function B(e){if(!l(e))throw new Error("Recording is not an object");if(!p(e,"title"))throw new Error("Recording is missing `title`");if(!c(e.title))throw new Error("Recording `title` is not a string");if(p(e,"timeout")&&!u(e.timeout))throw new Error("Recording `timeout` is not a number");if(!p(e,"steps"))throw new Error("Recording is missing `steps`");if(p(e,"timeout")&&u(e.timeout)&&!j(e.timeout))throw new Error(R);return t={title:e.title,timeout:p(e,"timeout")&&u(e.timeout)?e.timeout:void 0,selectorAttribute:p(e,"selectorAttribute")&&c(e.selectorAttribute)?e.selectorAttribute:void 0,steps:N(e.steps)},JSON.parse(JSON.stringify(t));var t}function W(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}function O(t){function n(e){return e.replace(/['"()]/g,"\\$&")}Array.isArray(t)||(t=[t]);return t.map((t=>{switch(W(t)){case e.ARIA:return`::-p-aria(${n(t.substring(e.ARIA.length+1))})`;case e.CSS:return t;case e.XPath:return`::-p-xpath(${n(t.substring(e.XPath.length+1))})`;case e.Pierce:return`:scope >>> ${t.substring(e.Pierce.length+1)}`;case e.Text:return`::-p-text(${n(t.substring(e.Text.length+1))})`}})).join(" >>>> ")}class D{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class H extends D{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const i=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+i)}}class K{#e;#t=0;#n=[];constructor(e){this.#e=e}appendLine(e){const t=e.split("\n").map((e=>e?this.#e.repeat(this.#t)+e.trimEnd():""));return this.#n.push(...t),this}startBlock(){return this.#t++,this}endBlock(){if(this.#t--,this.#t<0)throw new Error("Extra endBlock");return this}toString(){return this.#n.join("\n")+"\n"}getIndent(){return this.#e}getSize(){return this.#n.length}}function V(e,t){const n=[];return U(e,n,1,t),n.join("")}function U(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(X(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let i=0;i<e.length;i++)t.push(r.repeat(n)),U(e[i],t,n+1,r),i!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const i=Object.keys(e);for(let a=0;a<i.length;a++){const o=i[a],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),U(s,t,n+1,r),a!==i.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}const q=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),M=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),X=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(M.has(n))return M.get(n);return"\\x"+q(n.charCodeAt(0),2)}if(r){return"\\u"+q(r.charCodeAt(0),4)}return t?M.get(t)||"":e};let i="",a="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(a="'",i=e.replace(n,r)):(a="`",i=e.replace(t,r)):(a='"',i=e.replace(t,r)):(a="'",i=e.replace(t,r)),`${a}${i}${a}`};class J extends D{#r=!1;#i;constructor(e="chrome"){super(),this.#i=e}async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v23.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),"firefox"===this.#i?e.appendLine("const browser = await puppeteer.launch({browser: 'firefox'});"):e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||Y};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine(""),this.#r=!1}async afterAllSteps(e,t){if(e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine(""),this.#r)for(const t of _.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,r,i){e.appendLine("{").startBlock(),void 0!==r.timeout&&e.appendLine(`const timeout = ${r.timeout};`),this.#a(e,r);const a=r.assertedEvents&&r.type!==t.Navigate;if(a){e.appendLine("const promises = [];"),e.appendLine("const startWaitingForEvents = () => {").startBlock();for(const t of r.assertedEvents){if(t.type!==n.Navigation)throw new Error(`Event type ${t.type} is not supported`);e.appendLine(`promises.push(${"frame"in r&&r.frame?"frame":"targetPage"}.waitForNavigation());`)}e.endBlock().appendLine("}")}this.#o(e,r),a&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}#s(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${V(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))}#p(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)}#a(e,t){this.#s(e,t.target||"main"),t.frame&&this.#p(e,t.frame)}#l(e,t,n){e.appendLine("await puppeteer.Locator.race([").startBlock(),e.appendLine(t.selectors.map((n=>`${t.frame?"frame":"targetPage"}.locator(${V(O(n),e.getIndent())})`)).join(",\n")),e.endBlock().appendLine("])"),e.startBlock().appendLine(".setTimeout(timeout)"),t.assertedEvents?.length&&e.appendLine(".on('action', () => startWaitingForEvents())"),n(),e.endBlock()}#c(e,t){this.#l(e,t,(()=>{e.appendLine(".click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#u(e,t){this.#l(e,t,(()=>{e.appendLine(".click({"),e.appendLine(" count: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#f(e,t){this.#l(e,t,(()=>{e.appendLine(".hover();")}))}#d(e,t){this.#l(e,t,(()=>{e.appendLine(`.fill(${V(t.value,e.getIndent())});`)}))}#w(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")}#h(e,t){e.appendLine(`await targetPage.keyboard.down(${V(t.key,e.getIndent())});`)}#m(e,t){e.appendLine(`await targetPage.keyboard.up(${V(t.key,e.getIndent())});`)}#g(e,t){e.appendLine("await targetPage.close()")}#y(e,t){e.appendLine(`await targetPage.setViewport(${V({width:t.width,height:t.height},e.getIndent())})`)}#b(e,t){"selectors"in t?this.#l(e,t,(()=>{e.appendLine(`.scroll({ scrollTop: ${t.y}, scrollLeft: ${t.x}});`)})):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)}#o(e,n){switch(n.type){case t.Click:return this.#c(e,n);case t.DoubleClick:return this.#u(e,n);case t.Hover:return this.#f(e,n);case t.Change:return this.#d(e,n);case t.EmulateNetworkConditions:return this.#w(e,n);case t.KeyDown:return this.#h(e,n);case t.KeyUp:return this.#m(e,n);case t.Close:return this.#g(e,n);case t.SetViewport:return this.#y(e,n);case t.Scroll:return this.#b(e,n);case t.Navigate:return this.#S(e,n);case t.WaitForElement:return this.#E(e,n);case t.WaitForExpression:return this.#v(e,n);case t.CustomStep:return;default:return i(n)}}#S(e,t){e.appendLine(`await targetPage.goto(${V(t.url,e.getIndent())});`)}#v(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${V(t.expression,e.getIndent())}, { timeout });`)}#E(e,t){this.#r=!0,e.appendLine(`await waitForElement(${V(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)}}const Y=5e3,_="async function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}",z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",G=z.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map),Q=2147483647;function Z(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>Q)throw new Error("Only integers between 0 and "+Q+" are supported");const t=[];do{let n=31&e;(e>>>=5)>0&&(n|=32),t.push(z[n])}while(0!==e);return t.join("")}function ee(e){const t=[],n=e.split("");let r=0,i=0;for(const e of n){const n=G.get(e);r|=(31&n)<<i,i+=5;32&n||(t.push(r),r=0,i=0)}return t}const te="//# recorderSourceMap=";async function ne(e,t){t||(t={});const n=t.extension??new J,r=t.writer??new K(t.indentation??" ");await(n.beforeAllSteps?.(r,e));const i=[1];for(const t of e.steps){const a=r.getSize();await(n.beforeEachStep?.(r,t,e)),await n.stringifyStep(r,t,e),await(n.afterEachStep?.(r,t,e));const o=r.getSize();i.push(a,o-a)}return await(n.afterAllSteps?.(r,e)),r.appendLine(te+function(e){const t=[];for(const n of e)t.push(Z(n));return t.join("")}(i)),r.toString()}async function re(e,t){t||(t={});let n=t.extension;n||(n=new J),t.indentation||(t.indentation=" ");const r=t.writer??new K(t.indentation??" ");return await(n.beforeEachStep?.(r,e)),await n.stringifyStep(r,e),await(n.afterEachStep?.(r,e)),r.toString()}function ie(e){return e.trim().startsWith(te)}function ae(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(ie(n))return ee(n.trim().substring(22))}}function oe(e){return e.split("\n").filter((e=>!ie(e))).join("\n")}class se{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}const pe={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};function le(e){return new Promise((t=>{setTimeout(t,e)}))}class ce extends se{browser;page;timeout;constructor(e,t,n){super(),this.browser=e,this.page=t,this.timeout=n?.timeout||5e3}async#L(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}}#k(e,t){return e.timeout||t?.timeout||this.timeout}async runStep(e,t){const n=this.#k(e,t),r=this.page,i=this.browser,a=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const i=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),a=await i.page();if(!a)return null;return a.setDefaultTimeout(r),a}(i,r,e,n);let o=null;!a&&e.target&&(o=await r.waitForFrame(e.target,{timeout:n}));const s=o||a;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await this.#L(s);const p=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,p,n)}async runStepInFrame(e,r,a,o,p){let l=null;const c=()=>{l=async function(e,t,r){const i=[];if(t.assertedEvents)for(const a of t.assertedEvents){if(a.type!==n.Navigation)throw new Error(`Event type ${a.type} is not supported`);i.push(e.waitForNavigation({timeout:r}))}await Promise.all(i)}(o,e,p)},u=this.page.locatorRace;switch(e.type){case t.DoubleClick:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({count:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}});break;case t.Click:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}});break;case t.Hover:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).hover();break;case t.EmulateNetworkConditions:c(),await r.emulateNetworkConditions(e);break;case t.KeyDown:c(),await r.keyboard.down(e.key),await le(100);break;case t.KeyUp:c(),await r.keyboard.up(e.key),await le(100);break;case t.Close:"close"in a&&(c(),await a.close());break;case t.Change:await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).fill(e.value);break;case t.SetViewport:"setViewport"in a&&(c(),await a.setViewport(e));break;case t.Scroll:"selectors"in e?await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).scroll({scrollLeft:e.x||0,scrollTop:e.y||0}):(c(),await o.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0));break;case t.Navigate:c(),await o.goto(e.url);break;case t.WaitForElement:try{c(),await async function(e,t,n){const{count:r=1,operator:i=">=",visible:a=!0,properties:o,attributes:s}=e,p=pe[i];await async function(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}((async()=>{const n=await async function(e,t){for(const n of e){const e=await fe(n,t);if(e.length)return e}return[]}(e.selectors,t);let i=p(n.length,r);const l=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),i&&(o||s)&&(i=await l.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,i]of Object.entries(e))if(!r(i,t[n]))return!1;return!0}}),o,s)),await l.dispose(),i===a}),n)}(e,o,p)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:c(),await o.waitForFunction(e.expression,{timeout:p});break;case t.CustomStep:break;default:i(e)}await l}}class ue extends ce{async afterAllSteps(){await this.browser.close()}}async function fe(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function de(e,t,n){await(e.beforeEachStep?.(t,n)),await e.runStep(t,n),await(e.afterEachStep?.(t,n))}class we{#F;#A;#x=!1;constructor(e){this.#A=e}abort(){this.#x=!0}set flow(e){this.#F=e}async runBeforeAllSteps(e){await(this.#A.beforeAllSteps?.(e))}async runAfterAllSteps(e){await(this.#A.afterAllSteps?.(e))}async runStep(e){await de(this.#A,e)}async run(){if(!this.#F)throw new Error("Set the flow on the runner instance before calling `run`.");const e=this.#F;if(this.#x=!1,await(this.#A.beforeAllSteps?.(e)),this.#x)return!1;for(const t of e.steps){if(this.#x)return await(this.#A.afterAllSteps?.(e)),!1;await de(this.#A,t,e)}return await(this.#A.afterAllSteps?.(e)),!0}}async function he(e,t){const n=e instanceof se?void 0:e,r=new we((e instanceof se?e:t)??await async function(){const{default:e}=await import("puppeteer"),t=await e.launch(),n=await t.newPage();return new ue(t,n)}());return n&&(r.flow=n),r}class me extends D{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${V(t,e.getIndent())});`)}}function ge(e){return Boolean(e.type===t.Navigate||e.assertedEvents?.some((e=>e.type===n.Navigation)))}function ye(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class be extends J{#C=!1;async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${V({screenEmulation:{disabled:!0}},e.getIndent())}`),ye(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${V(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const i=ge(n);i?(this.#C&&(e.appendLine("await lhFlow.endTimespan();"),this.#C=!1),e.appendLine("await lhFlow.startNavigation();")):this.#C||(e.appendLine("await lhFlow.startTimespan();"),this.#C=!0),await super.stringifyStep(e,n,r),i&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){this.#C&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}class Se extends ce{#T=!1;#$=!1;#N;async createFlowResult(){if(!this.#N)throw new Error("Cannot get flow result before running the flow");return this.#N.createFlowResult()}async beforeAllSteps(e){await(super.beforeAllSteps?.(e));const{startFlow:t,desktopConfig:n}=await import("lighthouse");let r;ye(e)||(r=n),this.#N=await t(this.page,{config:r,flags:{screenEmulation:{disabled:!0}},name:e.title})}async beforeEachStep(e,n){await(super.beforeEachStep?.(e,n)),e.type!==t.SetViewport&&(ge(e)?(this.#T&&(await this.#N.endTimespan(),this.#T=!1),await this.#N.startNavigation(),this.#$=!0):this.#T||(await this.#N.startTimespan(),this.#T=!0))}async afterEachStep(e,t){this.#$&&(await this.#N.endNavigation(),this.#$=!1),await(super.afterEachStep?.(e,t))}async afterAllSteps(e){this.#T&&await this.#N.endTimespan(),await(super.afterAllSteps?.(e))}}export{n as AssertedEventType,H as JSONStringifyExtension,Se as LighthouseRunnerExtension,be as LighthouseStringifyExtension,me as PuppeteerReplayStringifyExtension,ce as PuppeteerRunnerExtension,ue as PuppeteerRunnerOwningBrowserExtension,J as PuppeteerStringifyExtension,we as Runner,se as RunnerExtension,r as Schema,e as SelectorType,t as StepType,D as StringifyExtension,i as assertAllStepTypesAreHandled,he as createRunner,X as formatAsJSLiteral,V as formatJSONAsJS,W as getSelectorType,I as maxTimeout,P as minTimeout,s as mouseButtonMap,B as parse,ae as parseSourceMap,$ as parseStep,o as pointerDeviceTypes,O as selectorToPElementSelector,ne as stringify,re as stringifyStep,oe as stripSourceMap,a as typeableInputTypes,j as validTimeout}; | |||
Check failure
Code scanning / CodeQL
Incomplete multi-character sanitization High library
<!--
| @@ -1 +1 @@ | |||
| var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t||(t={})),function(e){e.Navigation="navigation"}(n||(n={}));var r=Object.freeze({__proto__:null,get AssertedEventType(){return n},get SelectorType(){return e},get StepType(){return t}});function i(e){throw new Error(`Unknown step type: ${e.type}`)}const a=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function p(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function l(e){return"object"==typeof e&&null!==e}function c(e){return"string"==typeof e}function u(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function d(e){if(p(e,"target")&&c(e.target))return e.target}function w(e){if(p(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(p(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(p(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function g(e,t){if(p(e,t))return h(e,t)}function y(e,t){if(p(e,t))return S(e,t)}function b(e,t){if(p(e,t))return m(e,t)}function S(e,t){if(p(e,t)){const n=e[t];if(c(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!p(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!c(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!c(e))throw new Error("Selector element is not a string");return e})):e}))}function v(e){if(p(e,"selectors"))return E(e)}function L(e){if(!l(e))throw new Error("Asserted event is not an object");if(!p(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:y(e,"url"),title:y(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(p(t,"timeout")&&u(t.timeout)&&!j(t.timeout))throw new Error(R);return{type:e,assertedEvents:p(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:p(t,"timeout")&&u(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:d(t)}}function x(e,t){return{...A(e,t),frame:w(t)}}function C(e,t){return{...x(e,t),selectors:E(t)}}function T(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:g(e,"duration")},n=y(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const i=y(e,"button");if(i){if(!function(e){return"string"==typeof e&&s.has(e)}(i))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=i}return t}function $(e,n){if(!l(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!p(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!c(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...C(t.Click,e),...T(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...C(t.DoubleClick,e),...T(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...C(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...C(t.Change,e),type:t.Change,value:S(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:S(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:S(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...x(t.Scroll,e),type:t.Scroll,x:g(e,"x"),y:g(e,"y"),selectors:v(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:d(e),url:S(e,"url")}}(e);case t.CustomStep:return function(e){if(!p(e,"name"))throw new Error("customStep is missing name");if(!c(e.name))throw new Error("customStep's name is not a string");return{...x(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:p(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=y(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(p(e,"attributes")&&(!l(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(p(e,"properties")&&!l(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...C(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:g(e,"count"),visible:b(e,"visible"),attributes:p(e,"attributes")?e.attributes:void 0,properties:p(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!p(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...x(t.WaitForExpression,e),type:t.WaitForExpression,expression:S(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function N(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push($(r,n));return t}const P=1,I=3e4,R=`Timeout is not between ${P} and ${I} milliseconds`;function j(e){return e>=P&&e<=I}function W(e){if(!l(e))throw new Error("Recording is not an object");if(!p(e,"title"))throw new Error("Recording is missing `title`");if(!c(e.title))throw new Error("Recording `title` is not a string");if(p(e,"timeout")&&!u(e.timeout))throw new Error("Recording `timeout` is not a number");if(!p(e,"steps"))throw new Error("Recording is missing `steps`");if(p(e,"timeout")&&u(e.timeout)&&!j(e.timeout))throw new Error(R);return t={title:e.title,timeout:p(e,"timeout")&&u(e.timeout)?e.timeout:void 0,selectorAttribute:p(e,"selectorAttribute")&&c(e.selectorAttribute)?e.selectorAttribute:void 0,steps:N(e.steps)},JSON.parse(JSON.stringify(t));var t}function B(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}function O(t){function n(e){return e.replace(/['"()]/g,"\\$&")}Array.isArray(t)||(t=[t]);return t.map((t=>{switch(B(t)){case e.ARIA:return`::-p-aria(${n(t.substring(e.ARIA.length+1))})`;case e.CSS:return t;case e.XPath:return`::-p-xpath(${n(t.substring(e.XPath.length+1))})`;case e.Pierce:return`:scope >>> ${t.substring(e.Pierce.length+1)}`;case e.Text:return`::-p-text(${n(t.substring(e.Text.length+1))})`}})).join(" >>>> ")}class D{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class H extends D{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const i=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+i)}}class K{#e;#t=0;#n=[];constructor(e){this.#e=e}appendLine(e){const t=e.split("\n").map((e=>e?this.#e.repeat(this.#t)+e.trimEnd():""));return this.#n.push(...t),this}startBlock(){return this.#t++,this}endBlock(){if(this.#t--,this.#t<0)throw new Error("Extra endBlock");return this}toString(){return this.#n.join("\n")+"\n"}getIndent(){return this.#e}getSize(){return this.#n.length}}function V(e,t){const n=[];return U(e,n,1,t),n.join("")}function U(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(X(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let i=0;i<e.length;i++)t.push(r.repeat(n)),U(e[i],t,n+1,r),i!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const i=Object.keys(e);for(let a=0;a<i.length;a++){const o=i[a],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),U(s,t,n+1,r),a!==i.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}const q=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),M=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),X=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(M.has(n))return M.get(n);return"\\x"+q(n.charCodeAt(0),2)}if(r){return"\\u"+q(r.charCodeAt(0),4)}return t?M.get(t)||"":e};let i="",a="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(a="'",i=e.replace(n,r)):(a="`",i=e.replace(t,r)):(a='"',i=e.replace(t,r)):(a="'",i=e.replace(t,r)),`${a}${i}${a}`};class J extends D{#r=!1;async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v22.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||Y};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine(""),this.#r=!1}async afterAllSteps(e,t){if(e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine(""),this.#r)for(const t of _.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),this.#i(e,t),t.assertedEvents){e.appendLine("const promises = [];"),e.appendLine("const startWaitingForEvents = () => {").startBlock();for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}e.endBlock().appendLine("}")}this.#a(e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}#o(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${V(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))}#s(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)}#i(e,t){this.#o(e,t.target||"main"),t.frame&&this.#s(e,t.frame)}#p(e,t,n){e.appendLine("await puppeteer.Locator.race([").startBlock(),e.appendLine(t.selectors.map((n=>`${t.frame?"frame":"targetPage"}.locator(${V(O(n),e.getIndent())})`)).join(",\n")),e.endBlock().appendLine("])"),e.startBlock().appendLine(".setTimeout(timeout)"),t.assertedEvents?.length&&e.appendLine(".on('action', () => startWaitingForEvents())"),n(),e.endBlock()}#l(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#c(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),e.appendLine(" count: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#u(e,t){this.#p(e,t,(()=>{e.appendLine(".hover();")}))}#f(e,t){this.#p(e,t,(()=>{e.appendLine(`.fill(${V(t.value,e.getIndent())});`)}))}#d(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")}#w(e,t){e.appendLine(`await targetPage.keyboard.down(${V(t.key,e.getIndent())});`)}#h(e,t){e.appendLine(`await targetPage.keyboard.up(${V(t.key,e.getIndent())});`)}#m(e,t){e.appendLine("await targetPage.close()")}#g(e,t){e.appendLine(`await targetPage.setViewport(${V({width:t.width,height:t.height},e.getIndent())})`)}#y(e,t){"selectors"in t?this.#p(e,t,(()=>{e.appendLine(`.scroll({ scrollTop: ${t.y}, scrollLeft: ${t.x}});`)})):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)}#a(e,n){switch(n.type){case t.Click:return this.#l(e,n);case t.DoubleClick:return this.#c(e,n);case t.Hover:return this.#u(e,n);case t.Change:return this.#f(e,n);case t.EmulateNetworkConditions:return this.#d(e,n);case t.KeyDown:return this.#w(e,n);case t.KeyUp:return this.#h(e,n);case t.Close:return this.#m(e,n);case t.SetViewport:return this.#g(e,n);case t.Scroll:return this.#y(e,n);case t.Navigate:return this.#b(e,n);case t.WaitForElement:return this.#S(e,n);case t.WaitForExpression:return this.#E(e,n);case t.CustomStep:return;default:return i(n)}}#b(e,t){t.assertedEvents?.length&&e.appendLine("startWaitingForEvents();"),e.appendLine(`await targetPage.goto(${V(t.url,e.getIndent())});`)}#E(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${V(t.expression,e.getIndent())}, { timeout });`)}#S(e,t){this.#r=!0,e.appendLine(`await waitForElement(${V(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)}}const Y=5e3,_="async function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}",z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",G=z.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map),Q=31,Z=32,ee=2147483647;function te(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>ee)throw new Error("Only integers between 0 and "+ee+" are supported");const t=[];do{let n=e&Q;(e>>>=5)>0&&(n|=Z),t.push(z[n])}while(0!==e);return t.join("")}function ne(e){const t=[],n=e.split("");let r=0,i=0;for(const e of n){const n=G.get(e);r|=(n&Q)<<i,i+=5;n&Z||(t.push(r),r=0,i=0)}return t}const re="//# recorderSourceMap=";async function ie(e,t){t||(t={});const n=t.extension??new J,r=t.writer??new K(t.indentation??" ");await(n.beforeAllSteps?.(r,e));const i=[1];for(const t of e.steps){const a=r.getSize();await(n.beforeEachStep?.(r,t,e)),await n.stringifyStep(r,t,e),await(n.afterEachStep?.(r,t,e));const o=r.getSize();i.push(a,o-a)}return await(n.afterAllSteps?.(r,e)),r.appendLine(re+function(e){const t=[];for(const n of e)t.push(te(n));return t.join("")}(i)),r.toString()}async function ae(e,t){t||(t={});let n=t.extension;n||(n=new J),t.indentation||(t.indentation=" ");const r=t.writer??new K(t.indentation??" ");return await(n.beforeEachStep?.(r,e)),await n.stringifyStep(r,e),await(n.afterEachStep?.(r,e)),r.toString()}function oe(e){return e.trim().startsWith(re)}function se(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(oe(n))return ne(n.trim().substring(re.length))}}function pe(e){return e.split("\n").filter((e=>!oe(e))).join("\n")}class le{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}const ce={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};function ue(e){return new Promise((t=>{setTimeout(t,e)}))}class fe extends le{browser;page;timeout;constructor(e,t,n){super(),this.browser=e,this.page=t,this.timeout=n?.timeout||5e3}async#v(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}}#L(e,t){return e.timeout||t?.timeout||this.timeout}async runStep(e,t){const n=this.#L(e,t),r=this.page,i=this.browser,a=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const i=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),a=await i.page();if(!a)return null;return a.setDefaultTimeout(r),a}(i,r,e,n);let o=null;if(!a&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||a;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await this.#v(s);const p=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,p,n)}async runStepInFrame(e,r,a,o,p){let l=null;const c=()=>{l=async function(e,t,r){const i=[];if(t.assertedEvents)for(const a of t.assertedEvents){if(a.type!==n.Navigation)throw new Error(`Event type ${a.type} is not supported`);i.push(e.waitForNavigation({timeout:r}))}await Promise.all(i)}(o,e,p)},u=this.page.locatorRace;switch(e.type){case t.DoubleClick:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({count:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}});break;case t.Click:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}});break;case t.Hover:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).hover();break;case t.EmulateNetworkConditions:c(),await r.emulateNetworkConditions(e);break;case t.KeyDown:c(),await r.keyboard.down(e.key),await ue(100);break;case t.KeyUp:c(),await r.keyboard.up(e.key),await ue(100);break;case t.Close:"close"in a&&(c(),await a.close());break;case t.Change:await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).fill(e.value);break;case t.SetViewport:"setViewport"in a&&(c(),await a.setViewport(e));break;case t.Scroll:"selectors"in e?await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).scroll({scrollLeft:e.x||0,scrollTop:e.y||0}):(c(),await o.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0));break;case t.Navigate:c(),await o.goto(e.url);break;case t.WaitForElement:try{c(),await async function(e,t,n){const{count:r=1,operator:i=">=",visible:a=!0,properties:o,attributes:s}=e,p=ce[i];await async function(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}((async()=>{const n=await async function(e,t){for(const n of e){const e=await we(n,t);if(e.length)return e}return[]}(e.selectors,t);let i=p(n.length,r);const l=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),i&&(o||s)&&(i=await l.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,i]of Object.entries(e))if(!r(i,t[n]))return!1;return!0}}),o,s)),await l.dispose(),i===a}),n)}(e,o,p)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:c(),await o.waitForFunction(e.expression,{timeout:p});break;case t.CustomStep:break;default:i(e)}await l}}class de extends fe{async afterAllSteps(){await this.browser.close()}}async function we(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function he(e,t,n){await(e.beforeEachStep?.(t,n)),await e.runStep(t,n),await(e.afterEachStep?.(t,n))}class me{#k;#F;#A=!1;constructor(e){this.#F=e}abort(){this.#A=!0}set flow(e){this.#k=e}async runBeforeAllSteps(e){await(this.#F.beforeAllSteps?.(e))}async runAfterAllSteps(e){await(this.#F.afterAllSteps?.(e))}async runStep(e){await he(this.#F,e)}async run(){if(!this.#k)throw new Error("Set the flow on the runner instance before calling `run`.");const e=this.#k;if(this.#A=!1,await(this.#F.beforeAllSteps?.(e)),this.#A)return!1;for(const t of e.steps){if(this.#A)return await(this.#F.afterAllSteps?.(e)),!1;await he(this.#F,t,e)}return await(this.#F.afterAllSteps?.(e)),!0}}async function ge(e,t){const n=e instanceof le?void 0:e,r=new me((e instanceof le?e:t)??await async function(){const{default:e}=await import("puppeteer"),t=await e.launch(),n=await t.newPage();return new de(t,n)}());return n&&(r.flow=n),r}class ye extends D{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${V(t,e.getIndent())});`)}}function be(e){return Boolean(e.type===t.Navigate||e.assertedEvents?.some((e=>e.type===n.Navigation)))}function Se(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ee extends J{#x=!1;async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${V({screenEmulation:{disabled:!0}},e.getIndent())}`),Se(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${V(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const i=be(n);i?(this.#x&&(e.appendLine("await lhFlow.endTimespan();"),this.#x=!1),e.appendLine("await lhFlow.startNavigation();")):this.#x||(e.appendLine("await lhFlow.startTimespan();"),this.#x=!0),await super.stringifyStep(e,n,r),i&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){this.#x&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}class ve extends fe{#C=!1;#T=!1;#$;async createFlowResult(){if(!this.#$)throw new Error("Cannot get flow result before running the flow");return this.#$.createFlowResult()}async beforeAllSteps(e){await(super.beforeAllSteps?.(e));const{startFlow:t,desktopConfig:n}=await import("lighthouse");let r;Se(e)||(r=n),this.#$=await t(this.page,{config:r,flags:{screenEmulation:{disabled:!0}},name:e.title})}async beforeEachStep(e,n){await(super.beforeEachStep?.(e,n)),e.type!==t.SetViewport&&(be(e)?(this.#C&&(await this.#$.endTimespan(),this.#C=!1),await this.#$.startNavigation(),this.#T=!0):this.#C||(await this.#$.startTimespan(),this.#C=!0))}async afterEachStep(e,t){this.#T&&(await this.#$.endNavigation(),this.#T=!1),await(super.afterEachStep?.(e,t))}async afterAllSteps(e){this.#C&&await this.#$.endTimespan(),await(super.afterAllSteps?.(e))}}export{n as AssertedEventType,H as JSONStringifyExtension,ve as LighthouseRunnerExtension,Ee as LighthouseStringifyExtension,ye as PuppeteerReplayStringifyExtension,fe as PuppeteerRunnerExtension,de as PuppeteerRunnerOwningBrowserExtension,J as PuppeteerStringifyExtension,me as Runner,le as RunnerExtension,r as Schema,e as SelectorType,t as StepType,D as StringifyExtension,i as assertAllStepTypesAreHandled,ge as createRunner,X as formatAsJSLiteral,V as formatJSONAsJS,B as getSelectorType,I as maxTimeout,P as minTimeout,s as mouseButtonMap,W as parse,se as parseSourceMap,$ as parseStep,o as pointerDeviceTypes,O as selectorToPElementSelector,ie as stringify,ae as stringifyStep,pe as stripSourceMap,a as typeableInputTypes,j as validTimeout}; | |||
| var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t||(t={})),function(e){e.Navigation="navigation"}(n||(n={}));var r=Object.freeze({__proto__:null,get AssertedEventType(){return n},get SelectorType(){return e},get StepType(){return t}});function i(e){throw new Error(`Unknown step type: ${e.type}`)}const a=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function p(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function l(e){return"object"==typeof e&&null!==e}function c(e){return"string"==typeof e}function u(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function d(e){if(p(e,"target")&&c(e.target))return e.target}function w(e){if(p(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(p(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(p(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function g(e,t){if(p(e,t))return h(e,t)}function y(e,t){if(p(e,t))return S(e,t)}function b(e,t){if(p(e,t))return m(e,t)}function S(e,t){if(p(e,t)){const n=e[t];if(c(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!p(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!c(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!c(e))throw new Error("Selector element is not a string");return e})):e}))}function v(e){if(p(e,"selectors"))return E(e)}function L(e){if(!l(e))throw new Error("Asserted event is not an object");if(!p(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:y(e,"url"),title:y(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(p(t,"timeout")&&u(t.timeout)&&!j(t.timeout))throw new Error(R);return{type:e,assertedEvents:p(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:p(t,"timeout")&&u(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:d(t)}}function x(e,t){return{...A(e,t),frame:w(t)}}function C(e,t){return{...x(e,t),selectors:E(t)}}function T(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:g(e,"duration")},n=y(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const i=y(e,"button");if(i){if(!function(e){return"string"==typeof e&&s.has(e)}(i))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=i}return t}function $(e,n){if(!l(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!p(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!c(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...C(t.Click,e),...T(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...C(t.DoubleClick,e),...T(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...C(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...C(t.Change,e),type:t.Change,value:S(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:S(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:S(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...x(t.Scroll,e),type:t.Scroll,x:g(e,"x"),y:g(e,"y"),selectors:v(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:d(e),url:S(e,"url")}}(e);case t.CustomStep:return function(e){if(!p(e,"name"))throw new Error("customStep is missing name");if(!c(e.name))throw new Error("customStep's name is not a string");return{...x(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:p(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=y(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(p(e,"attributes")&&(!l(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(p(e,"properties")&&!l(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...C(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:g(e,"count"),visible:b(e,"visible"),attributes:p(e,"attributes")?e.attributes:void 0,properties:p(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!p(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...x(t.WaitForExpression,e),type:t.WaitForExpression,expression:S(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function N(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push($(r,n));return t}const P=1,I=3e4,R=`Timeout is not between ${P} and ${I} milliseconds`;function j(e){return e>=P&&e<=I}function B(e){if(!l(e))throw new Error("Recording is not an object");if(!p(e,"title"))throw new Error("Recording is missing `title`");if(!c(e.title))throw new Error("Recording `title` is not a string");if(p(e,"timeout")&&!u(e.timeout))throw new Error("Recording `timeout` is not a number");if(!p(e,"steps"))throw new Error("Recording is missing `steps`");if(p(e,"timeout")&&u(e.timeout)&&!j(e.timeout))throw new Error(R);return t={title:e.title,timeout:p(e,"timeout")&&u(e.timeout)?e.timeout:void 0,selectorAttribute:p(e,"selectorAttribute")&&c(e.selectorAttribute)?e.selectorAttribute:void 0,steps:N(e.steps)},JSON.parse(JSON.stringify(t));var t}function W(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}function O(t){function n(e){return e.replace(/['"()]/g,"\\$&")}Array.isArray(t)||(t=[t]);return t.map((t=>{switch(W(t)){case e.ARIA:return`::-p-aria(${n(t.substring(e.ARIA.length+1))})`;case e.CSS:return t;case e.XPath:return`::-p-xpath(${n(t.substring(e.XPath.length+1))})`;case e.Pierce:return`:scope >>> ${t.substring(e.Pierce.length+1)}`;case e.Text:return`::-p-text(${n(t.substring(e.Text.length+1))})`}})).join(" >>>> ")}class D{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class H extends D{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const i=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+i)}}class K{#e;#t=0;#n=[];constructor(e){this.#e=e}appendLine(e){const t=e.split("\n").map((e=>e?this.#e.repeat(this.#t)+e.trimEnd():""));return this.#n.push(...t),this}startBlock(){return this.#t++,this}endBlock(){if(this.#t--,this.#t<0)throw new Error("Extra endBlock");return this}toString(){return this.#n.join("\n")+"\n"}getIndent(){return this.#e}getSize(){return this.#n.length}}function V(e,t){const n=[];return U(e,n,1,t),n.join("")}function U(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(X(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let i=0;i<e.length;i++)t.push(r.repeat(n)),U(e[i],t,n+1,r),i!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const i=Object.keys(e);for(let a=0;a<i.length;a++){const o=i[a],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),U(s,t,n+1,r),a!==i.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}const q=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),M=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),X=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(M.has(n))return M.get(n);return"\\x"+q(n.charCodeAt(0),2)}if(r){return"\\u"+q(r.charCodeAt(0),4)}return t?M.get(t)||"":e};let i="",a="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(a="'",i=e.replace(n,r)):(a="`",i=e.replace(t,r)):(a='"',i=e.replace(t,r)):(a="'",i=e.replace(t,r)),`${a}${i}${a}`};class J extends D{#r=!1;#i;constructor(e="chrome"){super(),this.#i=e}async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v23.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),"firefox"===this.#i?e.appendLine("const browser = await puppeteer.launch({browser: 'firefox'});"):e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||Y};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine(""),this.#r=!1}async afterAllSteps(e,t){if(e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine(""),this.#r)for(const t of _.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,r,i){e.appendLine("{").startBlock(),void 0!==r.timeout&&e.appendLine(`const timeout = ${r.timeout};`),this.#a(e,r);const a=r.assertedEvents&&r.type!==t.Navigate;if(a){e.appendLine("const promises = [];"),e.appendLine("const startWaitingForEvents = () => {").startBlock();for(const t of r.assertedEvents){if(t.type!==n.Navigation)throw new Error(`Event type ${t.type} is not supported`);e.appendLine(`promises.push(${"frame"in r&&r.frame?"frame":"targetPage"}.waitForNavigation());`)}e.endBlock().appendLine("}")}this.#o(e,r),a&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}#s(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${V(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))}#p(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)}#a(e,t){this.#s(e,t.target||"main"),t.frame&&this.#p(e,t.frame)}#l(e,t,n){e.appendLine("await puppeteer.Locator.race([").startBlock(),e.appendLine(t.selectors.map((n=>`${t.frame?"frame":"targetPage"}.locator(${V(O(n),e.getIndent())})`)).join(",\n")),e.endBlock().appendLine("])"),e.startBlock().appendLine(".setTimeout(timeout)"),t.assertedEvents?.length&&e.appendLine(".on('action', () => startWaitingForEvents())"),n(),e.endBlock()}#c(e,t){this.#l(e,t,(()=>{e.appendLine(".click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#u(e,t){this.#l(e,t,(()=>{e.appendLine(".click({"),e.appendLine(" count: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#f(e,t){this.#l(e,t,(()=>{e.appendLine(".hover();")}))}#d(e,t){this.#l(e,t,(()=>{e.appendLine(`.fill(${V(t.value,e.getIndent())});`)}))}#w(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")}#h(e,t){e.appendLine(`await targetPage.keyboard.down(${V(t.key,e.getIndent())});`)}#m(e,t){e.appendLine(`await targetPage.keyboard.up(${V(t.key,e.getIndent())});`)}#g(e,t){e.appendLine("await targetPage.close()")}#y(e,t){e.appendLine(`await targetPage.setViewport(${V({width:t.width,height:t.height},e.getIndent())})`)}#b(e,t){"selectors"in t?this.#l(e,t,(()=>{e.appendLine(`.scroll({ scrollTop: ${t.y}, scrollLeft: ${t.x}});`)})):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)}#o(e,n){switch(n.type){case t.Click:return this.#c(e,n);case t.DoubleClick:return this.#u(e,n);case t.Hover:return this.#f(e,n);case t.Change:return this.#d(e,n);case t.EmulateNetworkConditions:return this.#w(e,n);case t.KeyDown:return this.#h(e,n);case t.KeyUp:return this.#m(e,n);case t.Close:return this.#g(e,n);case t.SetViewport:return this.#y(e,n);case t.Scroll:return this.#b(e,n);case t.Navigate:return this.#S(e,n);case t.WaitForElement:return this.#E(e,n);case t.WaitForExpression:return this.#v(e,n);case t.CustomStep:return;default:return i(n)}}#S(e,t){e.appendLine(`await targetPage.goto(${V(t.url,e.getIndent())});`)}#v(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${V(t.expression,e.getIndent())}, { timeout });`)}#E(e,t){this.#r=!0,e.appendLine(`await waitForElement(${V(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)}}const Y=5e3,_="async function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}",z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",G=z.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map),Q=2147483647;function Z(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>Q)throw new Error("Only integers between 0 and "+Q+" are supported");const t=[];do{let n=31&e;(e>>>=5)>0&&(n|=32),t.push(z[n])}while(0!==e);return t.join("")}function ee(e){const t=[],n=e.split("");let r=0,i=0;for(const e of n){const n=G.get(e);r|=(31&n)<<i,i+=5;32&n||(t.push(r),r=0,i=0)}return t}const te="//# recorderSourceMap=";async function ne(e,t){t||(t={});const n=t.extension??new J,r=t.writer??new K(t.indentation??" ");await(n.beforeAllSteps?.(r,e));const i=[1];for(const t of e.steps){const a=r.getSize();await(n.beforeEachStep?.(r,t,e)),await n.stringifyStep(r,t,e),await(n.afterEachStep?.(r,t,e));const o=r.getSize();i.push(a,o-a)}return await(n.afterAllSteps?.(r,e)),r.appendLine(te+function(e){const t=[];for(const n of e)t.push(Z(n));return t.join("")}(i)),r.toString()}async function re(e,t){t||(t={});let n=t.extension;n||(n=new J),t.indentation||(t.indentation=" ");const r=t.writer??new K(t.indentation??" ");return await(n.beforeEachStep?.(r,e)),await n.stringifyStep(r,e),await(n.afterEachStep?.(r,e)),r.toString()}function ie(e){return e.trim().startsWith(te)}function ae(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(ie(n))return ee(n.trim().substring(22))}}function oe(e){return e.split("\n").filter((e=>!ie(e))).join("\n")}class se{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}const pe={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};function le(e){return new Promise((t=>{setTimeout(t,e)}))}class ce extends se{browser;page;timeout;constructor(e,t,n){super(),this.browser=e,this.page=t,this.timeout=n?.timeout||5e3}async#L(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}}#k(e,t){return e.timeout||t?.timeout||this.timeout}async runStep(e,t){const n=this.#k(e,t),r=this.page,i=this.browser,a=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const i=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),a=await i.page();if(!a)return null;return a.setDefaultTimeout(r),a}(i,r,e,n);let o=null;!a&&e.target&&(o=await r.waitForFrame(e.target,{timeout:n}));const s=o||a;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await this.#L(s);const p=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,p,n)}async runStepInFrame(e,r,a,o,p){let l=null;const c=()=>{l=async function(e,t,r){const i=[];if(t.assertedEvents)for(const a of t.assertedEvents){if(a.type!==n.Navigation)throw new Error(`Event type ${a.type} is not supported`);i.push(e.waitForNavigation({timeout:r}))}await Promise.all(i)}(o,e,p)},u=this.page.locatorRace;switch(e.type){case t.DoubleClick:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({count:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}});break;case t.Click:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}});break;case t.Hover:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).hover();break;case t.EmulateNetworkConditions:c(),await r.emulateNetworkConditions(e);break;case t.KeyDown:c(),await r.keyboard.down(e.key),await le(100);break;case t.KeyUp:c(),await r.keyboard.up(e.key),await le(100);break;case t.Close:"close"in a&&(c(),await a.close());break;case t.Change:await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).fill(e.value);break;case t.SetViewport:"setViewport"in a&&(c(),await a.setViewport(e));break;case t.Scroll:"selectors"in e?await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).scroll({scrollLeft:e.x||0,scrollTop:e.y||0}):(c(),await o.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0));break;case t.Navigate:c(),await o.goto(e.url);break;case t.WaitForElement:try{c(),await async function(e,t,n){const{count:r=1,operator:i=">=",visible:a=!0,properties:o,attributes:s}=e,p=pe[i];await async function(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}((async()=>{const n=await async function(e,t){for(const n of e){const e=await fe(n,t);if(e.length)return e}return[]}(e.selectors,t);let i=p(n.length,r);const l=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),i&&(o||s)&&(i=await l.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,i]of Object.entries(e))if(!r(i,t[n]))return!1;return!0}}),o,s)),await l.dispose(),i===a}),n)}(e,o,p)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:c(),await o.waitForFunction(e.expression,{timeout:p});break;case t.CustomStep:break;default:i(e)}await l}}class ue extends ce{async afterAllSteps(){await this.browser.close()}}async function fe(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function de(e,t,n){await(e.beforeEachStep?.(t,n)),await e.runStep(t,n),await(e.afterEachStep?.(t,n))}class we{#F;#A;#x=!1;constructor(e){this.#A=e}abort(){this.#x=!0}set flow(e){this.#F=e}async runBeforeAllSteps(e){await(this.#A.beforeAllSteps?.(e))}async runAfterAllSteps(e){await(this.#A.afterAllSteps?.(e))}async runStep(e){await de(this.#A,e)}async run(){if(!this.#F)throw new Error("Set the flow on the runner instance before calling `run`.");const e=this.#F;if(this.#x=!1,await(this.#A.beforeAllSteps?.(e)),this.#x)return!1;for(const t of e.steps){if(this.#x)return await(this.#A.afterAllSteps?.(e)),!1;await de(this.#A,t,e)}return await(this.#A.afterAllSteps?.(e)),!0}}async function he(e,t){const n=e instanceof se?void 0:e,r=new we((e instanceof se?e:t)??await async function(){const{default:e}=await import("puppeteer"),t=await e.launch(),n=await t.newPage();return new ue(t,n)}());return n&&(r.flow=n),r}class me extends D{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${V(t,e.getIndent())});`)}}function ge(e){return Boolean(e.type===t.Navigate||e.assertedEvents?.some((e=>e.type===n.Navigation)))}function ye(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class be extends J{#C=!1;async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${V({screenEmulation:{disabled:!0}},e.getIndent())}`),ye(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${V(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const i=ge(n);i?(this.#C&&(e.appendLine("await lhFlow.endTimespan();"),this.#C=!1),e.appendLine("await lhFlow.startNavigation();")):this.#C||(e.appendLine("await lhFlow.startTimespan();"),this.#C=!0),await super.stringifyStep(e,n,r),i&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){this.#C&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}class Se extends ce{#T=!1;#$=!1;#N;async createFlowResult(){if(!this.#N)throw new Error("Cannot get flow result before running the flow");return this.#N.createFlowResult()}async beforeAllSteps(e){await(super.beforeAllSteps?.(e));const{startFlow:t,desktopConfig:n}=await import("lighthouse");let r;ye(e)||(r=n),this.#N=await t(this.page,{config:r,flags:{screenEmulation:{disabled:!0}},name:e.title})}async beforeEachStep(e,n){await(super.beforeEachStep?.(e,n)),e.type!==t.SetViewport&&(ge(e)?(this.#T&&(await this.#N.endTimespan(),this.#T=!1),await this.#N.startNavigation(),this.#$=!0):this.#T||(await this.#N.startTimespan(),this.#T=!0))}async afterEachStep(e,t){this.#$&&(await this.#N.endNavigation(),this.#$=!1),await(super.afterEachStep?.(e,t))}async afterAllSteps(e){this.#T&&await this.#N.endTimespan(),await(super.afterAllSteps?.(e))}}export{n as AssertedEventType,H as JSONStringifyExtension,Se as LighthouseRunnerExtension,be as LighthouseStringifyExtension,me as PuppeteerReplayStringifyExtension,ce as PuppeteerRunnerExtension,ue as PuppeteerRunnerOwningBrowserExtension,J as PuppeteerStringifyExtension,we as Runner,se as RunnerExtension,r as Schema,e as SelectorType,t as StepType,D as StringifyExtension,i as assertAllStepTypesAreHandled,he as createRunner,X as formatAsJSLiteral,V as formatJSONAsJS,W as getSelectorType,I as maxTimeout,P as minTimeout,s as mouseButtonMap,B as parse,ae as parseSourceMap,$ as parseStep,o as pointerDeviceTypes,O as selectorToPElementSelector,ne as stringify,re as stringifyStep,oe as stripSourceMap,a as typeableInputTypes,j as validTimeout}; | |||
Check failure
Code scanning / CodeQL
Incomplete multi-character sanitization High library
<!--
| @@ -1 +1 @@ | |||
| var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t||(t={})),function(e){e.Navigation="navigation"}(n||(n={}));var r=Object.freeze({__proto__:null,get AssertedEventType(){return n},get SelectorType(){return e},get StepType(){return t}});function i(e){throw new Error(`Unknown step type: ${e.type}`)}const a=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function p(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function l(e){return"object"==typeof e&&null!==e}function c(e){return"string"==typeof e}function u(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function d(e){if(p(e,"target")&&c(e.target))return e.target}function w(e){if(p(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(p(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(p(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function g(e,t){if(p(e,t))return h(e,t)}function y(e,t){if(p(e,t))return S(e,t)}function b(e,t){if(p(e,t))return m(e,t)}function S(e,t){if(p(e,t)){const n=e[t];if(c(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!p(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!c(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!c(e))throw new Error("Selector element is not a string");return e})):e}))}function v(e){if(p(e,"selectors"))return E(e)}function L(e){if(!l(e))throw new Error("Asserted event is not an object");if(!p(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:y(e,"url"),title:y(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(p(t,"timeout")&&u(t.timeout)&&!j(t.timeout))throw new Error(R);return{type:e,assertedEvents:p(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:p(t,"timeout")&&u(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:d(t)}}function x(e,t){return{...A(e,t),frame:w(t)}}function C(e,t){return{...x(e,t),selectors:E(t)}}function T(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:g(e,"duration")},n=y(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const i=y(e,"button");if(i){if(!function(e){return"string"==typeof e&&s.has(e)}(i))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=i}return t}function $(e,n){if(!l(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!p(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!c(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...C(t.Click,e),...T(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...C(t.DoubleClick,e),...T(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...C(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...C(t.Change,e),type:t.Change,value:S(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:S(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:S(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...x(t.Scroll,e),type:t.Scroll,x:g(e,"x"),y:g(e,"y"),selectors:v(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:d(e),url:S(e,"url")}}(e);case t.CustomStep:return function(e){if(!p(e,"name"))throw new Error("customStep is missing name");if(!c(e.name))throw new Error("customStep's name is not a string");return{...x(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:p(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=y(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(p(e,"attributes")&&(!l(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(p(e,"properties")&&!l(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...C(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:g(e,"count"),visible:b(e,"visible"),attributes:p(e,"attributes")?e.attributes:void 0,properties:p(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!p(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...x(t.WaitForExpression,e),type:t.WaitForExpression,expression:S(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function N(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push($(r,n));return t}const P=1,I=3e4,R=`Timeout is not between ${P} and ${I} milliseconds`;function j(e){return e>=P&&e<=I}function W(e){if(!l(e))throw new Error("Recording is not an object");if(!p(e,"title"))throw new Error("Recording is missing `title`");if(!c(e.title))throw new Error("Recording `title` is not a string");if(p(e,"timeout")&&!u(e.timeout))throw new Error("Recording `timeout` is not a number");if(!p(e,"steps"))throw new Error("Recording is missing `steps`");if(p(e,"timeout")&&u(e.timeout)&&!j(e.timeout))throw new Error(R);return t={title:e.title,timeout:p(e,"timeout")&&u(e.timeout)?e.timeout:void 0,selectorAttribute:p(e,"selectorAttribute")&&c(e.selectorAttribute)?e.selectorAttribute:void 0,steps:N(e.steps)},JSON.parse(JSON.stringify(t));var t}function B(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}function O(t){function n(e){return e.replace(/['"()]/g,"\\$&")}Array.isArray(t)||(t=[t]);return t.map((t=>{switch(B(t)){case e.ARIA:return`::-p-aria(${n(t.substring(e.ARIA.length+1))})`;case e.CSS:return t;case e.XPath:return`::-p-xpath(${n(t.substring(e.XPath.length+1))})`;case e.Pierce:return`:scope >>> ${t.substring(e.Pierce.length+1)}`;case e.Text:return`::-p-text(${n(t.substring(e.Text.length+1))})`}})).join(" >>>> ")}class D{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class H extends D{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const i=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+i)}}class K{#e;#t=0;#n=[];constructor(e){this.#e=e}appendLine(e){const t=e.split("\n").map((e=>e?this.#e.repeat(this.#t)+e.trimEnd():""));return this.#n.push(...t),this}startBlock(){return this.#t++,this}endBlock(){if(this.#t--,this.#t<0)throw new Error("Extra endBlock");return this}toString(){return this.#n.join("\n")+"\n"}getIndent(){return this.#e}getSize(){return this.#n.length}}function V(e,t){const n=[];return U(e,n,1,t),n.join("")}function U(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(X(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let i=0;i<e.length;i++)t.push(r.repeat(n)),U(e[i],t,n+1,r),i!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const i=Object.keys(e);for(let a=0;a<i.length;a++){const o=i[a],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),U(s,t,n+1,r),a!==i.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}const q=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),M=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),X=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(M.has(n))return M.get(n);return"\\x"+q(n.charCodeAt(0),2)}if(r){return"\\u"+q(r.charCodeAt(0),4)}return t?M.get(t)||"":e};let i="",a="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(a="'",i=e.replace(n,r)):(a="`",i=e.replace(t,r)):(a='"',i=e.replace(t,r)):(a="'",i=e.replace(t,r)),`${a}${i}${a}`};class J extends D{#r=!1;async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v22.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||Y};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine(""),this.#r=!1}async afterAllSteps(e,t){if(e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine(""),this.#r)for(const t of _.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,t,r){if(e.appendLine("{").startBlock(),void 0!==t.timeout&&e.appendLine(`const timeout = ${t.timeout};`),this.#i(e,t),t.assertedEvents){e.appendLine("const promises = [];"),e.appendLine("const startWaitingForEvents = () => {").startBlock();for(const r of t.assertedEvents){if(r.type!==n.Navigation)throw new Error(`Event type ${r.type} is not supported`);e.appendLine(`promises.push(${"frame"in t&&t.frame?"frame":"targetPage"}.waitForNavigation());`)}e.endBlock().appendLine("}")}this.#a(e,t),t.assertedEvents&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}#o(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${V(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))}#s(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)}#i(e,t){this.#o(e,t.target||"main"),t.frame&&this.#s(e,t.frame)}#p(e,t,n){e.appendLine("await puppeteer.Locator.race([").startBlock(),e.appendLine(t.selectors.map((n=>`${t.frame?"frame":"targetPage"}.locator(${V(O(n),e.getIndent())})`)).join(",\n")),e.endBlock().appendLine("])"),e.startBlock().appendLine(".setTimeout(timeout)"),t.assertedEvents?.length&&e.appendLine(".on('action', () => startWaitingForEvents())"),n(),e.endBlock()}#l(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#c(e,t){this.#p(e,t,(()=>{e.appendLine(".click({"),e.appendLine(" count: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#u(e,t){this.#p(e,t,(()=>{e.appendLine(".hover();")}))}#f(e,t){this.#p(e,t,(()=>{e.appendLine(`.fill(${V(t.value,e.getIndent())});`)}))}#d(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")}#w(e,t){e.appendLine(`await targetPage.keyboard.down(${V(t.key,e.getIndent())});`)}#h(e,t){e.appendLine(`await targetPage.keyboard.up(${V(t.key,e.getIndent())});`)}#m(e,t){e.appendLine("await targetPage.close()")}#g(e,t){e.appendLine(`await targetPage.setViewport(${V({width:t.width,height:t.height},e.getIndent())})`)}#y(e,t){"selectors"in t?this.#p(e,t,(()=>{e.appendLine(`.scroll({ scrollTop: ${t.y}, scrollLeft: ${t.x}});`)})):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)}#a(e,n){switch(n.type){case t.Click:return this.#l(e,n);case t.DoubleClick:return this.#c(e,n);case t.Hover:return this.#u(e,n);case t.Change:return this.#f(e,n);case t.EmulateNetworkConditions:return this.#d(e,n);case t.KeyDown:return this.#w(e,n);case t.KeyUp:return this.#h(e,n);case t.Close:return this.#m(e,n);case t.SetViewport:return this.#g(e,n);case t.Scroll:return this.#y(e,n);case t.Navigate:return this.#b(e,n);case t.WaitForElement:return this.#S(e,n);case t.WaitForExpression:return this.#E(e,n);case t.CustomStep:return;default:return i(n)}}#b(e,t){t.assertedEvents?.length&&e.appendLine("startWaitingForEvents();"),e.appendLine(`await targetPage.goto(${V(t.url,e.getIndent())});`)}#E(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${V(t.expression,e.getIndent())}, { timeout });`)}#S(e,t){this.#r=!0,e.appendLine(`await waitForElement(${V(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)}}const Y=5e3,_="async function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}",z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",G=z.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map),Q=31,Z=32,ee=2147483647;function te(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>ee)throw new Error("Only integers between 0 and "+ee+" are supported");const t=[];do{let n=e&Q;(e>>>=5)>0&&(n|=Z),t.push(z[n])}while(0!==e);return t.join("")}function ne(e){const t=[],n=e.split("");let r=0,i=0;for(const e of n){const n=G.get(e);r|=(n&Q)<<i,i+=5;n&Z||(t.push(r),r=0,i=0)}return t}const re="//# recorderSourceMap=";async function ie(e,t){t||(t={});const n=t.extension??new J,r=t.writer??new K(t.indentation??" ");await(n.beforeAllSteps?.(r,e));const i=[1];for(const t of e.steps){const a=r.getSize();await(n.beforeEachStep?.(r,t,e)),await n.stringifyStep(r,t,e),await(n.afterEachStep?.(r,t,e));const o=r.getSize();i.push(a,o-a)}return await(n.afterAllSteps?.(r,e)),r.appendLine(re+function(e){const t=[];for(const n of e)t.push(te(n));return t.join("")}(i)),r.toString()}async function ae(e,t){t||(t={});let n=t.extension;n||(n=new J),t.indentation||(t.indentation=" ");const r=t.writer??new K(t.indentation??" ");return await(n.beforeEachStep?.(r,e)),await n.stringifyStep(r,e),await(n.afterEachStep?.(r,e)),r.toString()}function oe(e){return e.trim().startsWith(re)}function se(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(oe(n))return ne(n.trim().substring(re.length))}}function pe(e){return e.split("\n").filter((e=>!oe(e))).join("\n")}class le{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}const ce={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};function ue(e){return new Promise((t=>{setTimeout(t,e)}))}class fe extends le{browser;page;timeout;constructor(e,t,n){super(),this.browser=e,this.page=t,this.timeout=n?.timeout||5e3}async#v(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}}#L(e,t){return e.timeout||t?.timeout||this.timeout}async runStep(e,t){const n=this.#L(e,t),r=this.page,i=this.browser,a=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const i=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),a=await i.page();if(!a)return null;return a.setDefaultTimeout(r),a}(i,r,e,n);let o=null;if(!a&&e.target){const t=r.frames();for(const n of t)if(n.isOOPFrame()&&n.url()===e.target){o=n;break}o||(o=await r.waitForFrame(e.target,{timeout:n}))}const s=o||a;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await this.#v(s);const p=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,p,n)}async runStepInFrame(e,r,a,o,p){let l=null;const c=()=>{l=async function(e,t,r){const i=[];if(t.assertedEvents)for(const a of t.assertedEvents){if(a.type!==n.Navigation)throw new Error(`Event type ${a.type} is not supported`);i.push(e.waitForNavigation({timeout:r}))}await Promise.all(i)}(o,e,p)},u=this.page.locatorRace;switch(e.type){case t.DoubleClick:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({count:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}});break;case t.Click:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}});break;case t.Hover:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).hover();break;case t.EmulateNetworkConditions:c(),await r.emulateNetworkConditions(e);break;case t.KeyDown:c(),await r.keyboard.down(e.key),await ue(100);break;case t.KeyUp:c(),await r.keyboard.up(e.key),await ue(100);break;case t.Close:"close"in a&&(c(),await a.close());break;case t.Change:await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).fill(e.value);break;case t.SetViewport:"setViewport"in a&&(c(),await a.setViewport(e));break;case t.Scroll:"selectors"in e?await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).scroll({scrollLeft:e.x||0,scrollTop:e.y||0}):(c(),await o.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0));break;case t.Navigate:c(),await o.goto(e.url);break;case t.WaitForElement:try{c(),await async function(e,t,n){const{count:r=1,operator:i=">=",visible:a=!0,properties:o,attributes:s}=e,p=ce[i];await async function(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}((async()=>{const n=await async function(e,t){for(const n of e){const e=await we(n,t);if(e.length)return e}return[]}(e.selectors,t);let i=p(n.length,r);const l=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),i&&(o||s)&&(i=await l.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,i]of Object.entries(e))if(!r(i,t[n]))return!1;return!0}}),o,s)),await l.dispose(),i===a}),n)}(e,o,p)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:c(),await o.waitForFunction(e.expression,{timeout:p});break;case t.CustomStep:break;default:i(e)}await l}}class de extends fe{async afterAllSteps(){await this.browser.close()}}async function we(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function he(e,t,n){await(e.beforeEachStep?.(t,n)),await e.runStep(t,n),await(e.afterEachStep?.(t,n))}class me{#k;#F;#A=!1;constructor(e){this.#F=e}abort(){this.#A=!0}set flow(e){this.#k=e}async runBeforeAllSteps(e){await(this.#F.beforeAllSteps?.(e))}async runAfterAllSteps(e){await(this.#F.afterAllSteps?.(e))}async runStep(e){await he(this.#F,e)}async run(){if(!this.#k)throw new Error("Set the flow on the runner instance before calling `run`.");const e=this.#k;if(this.#A=!1,await(this.#F.beforeAllSteps?.(e)),this.#A)return!1;for(const t of e.steps){if(this.#A)return await(this.#F.afterAllSteps?.(e)),!1;await he(this.#F,t,e)}return await(this.#F.afterAllSteps?.(e)),!0}}async function ge(e,t){const n=e instanceof le?void 0:e,r=new me((e instanceof le?e:t)??await async function(){const{default:e}=await import("puppeteer"),t=await e.launch(),n=await t.newPage();return new de(t,n)}());return n&&(r.flow=n),r}class ye extends D{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${V(t,e.getIndent())});`)}}function be(e){return Boolean(e.type===t.Navigate||e.assertedEvents?.some((e=>e.type===n.Navigation)))}function Se(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class Ee extends J{#x=!1;async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${V({screenEmulation:{disabled:!0}},e.getIndent())}`),Se(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${V(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const i=be(n);i?(this.#x&&(e.appendLine("await lhFlow.endTimespan();"),this.#x=!1),e.appendLine("await lhFlow.startNavigation();")):this.#x||(e.appendLine("await lhFlow.startTimespan();"),this.#x=!0),await super.stringifyStep(e,n,r),i&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){this.#x&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}class ve extends fe{#C=!1;#T=!1;#$;async createFlowResult(){if(!this.#$)throw new Error("Cannot get flow result before running the flow");return this.#$.createFlowResult()}async beforeAllSteps(e){await(super.beforeAllSteps?.(e));const{startFlow:t,desktopConfig:n}=await import("lighthouse");let r;Se(e)||(r=n),this.#$=await t(this.page,{config:r,flags:{screenEmulation:{disabled:!0}},name:e.title})}async beforeEachStep(e,n){await(super.beforeEachStep?.(e,n)),e.type!==t.SetViewport&&(be(e)?(this.#C&&(await this.#$.endTimespan(),this.#C=!1),await this.#$.startNavigation(),this.#T=!0):this.#C||(await this.#$.startTimespan(),this.#C=!0))}async afterEachStep(e,t){this.#T&&(await this.#$.endNavigation(),this.#T=!1),await(super.afterEachStep?.(e,t))}async afterAllSteps(e){this.#C&&await this.#$.endTimespan(),await(super.afterAllSteps?.(e))}}export{n as AssertedEventType,H as JSONStringifyExtension,ve as LighthouseRunnerExtension,Ee as LighthouseStringifyExtension,ye as PuppeteerReplayStringifyExtension,fe as PuppeteerRunnerExtension,de as PuppeteerRunnerOwningBrowserExtension,J as PuppeteerStringifyExtension,me as Runner,le as RunnerExtension,r as Schema,e as SelectorType,t as StepType,D as StringifyExtension,i as assertAllStepTypesAreHandled,ge as createRunner,X as formatAsJSLiteral,V as formatJSONAsJS,B as getSelectorType,I as maxTimeout,P as minTimeout,s as mouseButtonMap,W as parse,se as parseSourceMap,$ as parseStep,o as pointerDeviceTypes,O as selectorToPElementSelector,ie as stringify,ae as stringifyStep,pe as stripSourceMap,a as typeableInputTypes,j as validTimeout}; | |||
| var e,t,n;!function(e){e.CSS="css",e.ARIA="aria",e.Text="text",e.XPath="xpath",e.Pierce="pierce"}(e||(e={})),function(e){e.Change="change",e.Click="click",e.Close="close",e.CustomStep="customStep",e.DoubleClick="doubleClick",e.EmulateNetworkConditions="emulateNetworkConditions",e.Hover="hover",e.KeyDown="keyDown",e.KeyUp="keyUp",e.Navigate="navigate",e.Scroll="scroll",e.SetViewport="setViewport",e.WaitForElement="waitForElement",e.WaitForExpression="waitForExpression"}(t||(t={})),function(e){e.Navigation="navigation"}(n||(n={}));var r=Object.freeze({__proto__:null,get AssertedEventType(){return n},get SelectorType(){return e},get StepType(){return t}});function i(e){throw new Error(`Unknown step type: ${e.type}`)}const a=new Set(["textarea","text","url","tel","search","password","number","email"]),o=new Set(["mouse","pen","touch"]),s=new Map([["primary","left"],["auxiliary","middle"],["secondary","right"],["back","back"],["forward","forward"]]);function p(e,t){if(!Object.prototype.hasOwnProperty.call(e,t))return!1;return void 0!==e[t]}function l(e){return"object"==typeof e&&null!==e}function c(e){return"string"==typeof e}function u(e){return"number"==typeof e}function f(e){return Array.isArray(e)}function d(e){if(p(e,"target")&&c(e.target))return e.target}function w(e){if(p(e,"frame")){if(f(t=e.frame)&&t.every((e=>Number.isInteger(e))))return e.frame;throw new Error("Step `frame` is not an integer array")}var t}function h(e,t){if(p(e,t)){const n=e[t];if(u(n))return n}throw new Error(`Step.${t} is not a number`)}function m(e,t){if(p(e,t)){const n=e[t];if("boolean"==typeof n)return n}throw new Error(`Step.${t} is not a boolean`)}function g(e,t){if(p(e,t))return h(e,t)}function y(e,t){if(p(e,t))return S(e,t)}function b(e,t){if(p(e,t))return m(e,t)}function S(e,t){if(p(e,t)){const n=e[t];if(c(n))return n}throw new Error(`Step.${t} is not a string`)}function E(e){if(!p(e,"selectors"))throw new Error("Step does not have required selectors");if(!f(e.selectors))throw new Error("Step selectors are not an array");if(0===e.selectors.length)throw new Error("Step does not have required selectors");return e.selectors.map((e=>{if(!c(e)&&!f(e))throw new Error("Selector is not an array or string");return f(e)?e.map((e=>{if(!c(e))throw new Error("Selector element is not a string");return e})):e}))}function v(e){if(p(e,"selectors"))return E(e)}function L(e){if(!l(e))throw new Error("Asserted event is not an object");if(!p(e,"type"))throw new Error("Asserted event is missing type");if(e.type===n.Navigation)return{type:n.Navigation,url:y(e,"url"),title:y(e,"title")};throw new Error("Unknown assertedEvent type")}function k(e){if(f(e))return e.map(L)}function F(e,t){if(p(t,"timeout")&&u(t.timeout)&&!j(t.timeout))throw new Error(R);return{type:e,assertedEvents:p(t,"assertedEvents")?k(t.assertedEvents):void 0,timeout:p(t,"timeout")&&u(t.timeout)?t.timeout:void 0}}function A(e,t){return{...F(e,t),target:d(t)}}function x(e,t){return{...A(e,t),frame:w(t)}}function C(e,t){return{...x(e,t),selectors:E(t)}}function T(e){const t={offsetX:h(e,"offsetX"),offsetY:h(e,"offsetY"),duration:g(e,"duration")},n=y(e,"deviceType");if(n){if("string"!=typeof(r=n)||!o.has(r))throw new Error(`'deviceType' for click steps must be one of the following: ${[...o].join(", ")}`);t.deviceType=n}var r;const i=y(e,"button");if(i){if(!function(e){return"string"==typeof e&&s.has(e)}(i))throw new Error(`'button' for click steps must be one of the following: ${[...s.keys()].join(", ")}`);t.button=i}return t}function $(e,n){if(!l(e))throw new Error(n?`Step ${n} is not an object`:"Step is not an object");if(!p(e,"type"))throw new Error(n?`Step ${n} does not have a type`:"Step does not have a type");if(!c(e.type))throw new Error(n?`Type of the step ${n} is not a string`:"Type of the step is not a string");switch(e.type){case t.Click:return function(e){return{...C(t.Click,e),...T(e),type:t.Click}}(e);case t.DoubleClick:return function(e){return{...C(t.DoubleClick,e),...T(e),type:t.DoubleClick}}(e);case t.Hover:return function(e){return{...C(t.Hover,e),type:t.Hover}}(e);case t.Change:return function(e){return{...C(t.Change,e),type:t.Change,value:S(e,"value")}}(e);case t.KeyDown:return function(e){return{...A(t.KeyDown,e),type:t.KeyDown,key:S(e,"key")}}(e);case t.KeyUp:return function(e){return{...A(t.KeyUp,e),type:t.KeyUp,key:S(e,"key")}}(e);case t.EmulateNetworkConditions:return function(e){return{...A(t.EmulateNetworkConditions,e),type:t.EmulateNetworkConditions,download:h(e,"download"),upload:h(e,"upload"),latency:h(e,"latency")}}(e);case t.Close:return function(e){return{...A(t.Close,e),type:t.Close}}(e);case t.SetViewport:return function(e){return{...A(t.SetViewport,e),type:t.SetViewport,width:h(e,"width"),height:h(e,"height"),deviceScaleFactor:h(e,"deviceScaleFactor"),isMobile:m(e,"isMobile"),hasTouch:m(e,"hasTouch"),isLandscape:m(e,"isLandscape")}}(e);case t.Scroll:return function(e){return{...x(t.Scroll,e),type:t.Scroll,x:g(e,"x"),y:g(e,"y"),selectors:v(e)}}(e);case t.Navigate:return function(e){return{...A(t.Navigate,e),type:t.Navigate,target:d(e),url:S(e,"url")}}(e);case t.CustomStep:return function(e){if(!p(e,"name"))throw new Error("customStep is missing name");if(!c(e.name))throw new Error("customStep's name is not a string");return{...x(t.CustomStep,e),type:t.CustomStep,name:e.name,parameters:p(e,"parameters")?e.parameters:void 0}}(e);case t.WaitForElement:return function(e){const n=y(e,"operator");if(n&&">="!==n&&"=="!==n&&"<="!==n)throw new Error("WaitForElement step's operator is not one of '>=','==','<='");if(p(e,"attributes")&&(!l(e.attributes)||Object.values(e.attributes).some((e=>"string"!=typeof e))))throw new Error("WaitForElement step's attribute is not a dictionary of strings");if(p(e,"properties")&&!l(e.properties))throw new Error("WaitForElement step's attribute is not an object");return{...C(t.WaitForElement,e),type:t.WaitForElement,operator:n,count:g(e,"count"),visible:b(e,"visible"),attributes:p(e,"attributes")?e.attributes:void 0,properties:p(e,"properties")?e.properties:void 0}}(e);case t.WaitForExpression:return function(e){if(!p(e,"expression"))throw new Error("waitForExpression step is missing `expression`");return{...x(t.WaitForExpression,e),type:t.WaitForExpression,expression:S(e,"expression")}}(e);default:throw new Error(`Step type ${e.type} is not supported`)}}function N(e){const t=[];if(!f(e))throw new Error("Recording `steps` is not an array");for(const[n,r]of e.entries())t.push($(r,n));return t}const P=1,I=3e4,R=`Timeout is not between ${P} and ${I} milliseconds`;function j(e){return e>=P&&e<=I}function B(e){if(!l(e))throw new Error("Recording is not an object");if(!p(e,"title"))throw new Error("Recording is missing `title`");if(!c(e.title))throw new Error("Recording `title` is not a string");if(p(e,"timeout")&&!u(e.timeout))throw new Error("Recording `timeout` is not a number");if(!p(e,"steps"))throw new Error("Recording is missing `steps`");if(p(e,"timeout")&&u(e.timeout)&&!j(e.timeout))throw new Error(R);return t={title:e.title,timeout:p(e,"timeout")&&u(e.timeout)?e.timeout:void 0,selectorAttribute:p(e,"selectorAttribute")&&c(e.selectorAttribute)?e.selectorAttribute:void 0,steps:N(e.steps)},JSON.parse(JSON.stringify(t));var t}function W(t){for(const n of Object.values(e))if(t.startsWith(`${n}/`))return n;return e.CSS}function O(t){function n(e){return e.replace(/['"()]/g,"\\$&")}Array.isArray(t)||(t=[t]);return t.map((t=>{switch(W(t)){case e.ARIA:return`::-p-aria(${n(t.substring(e.ARIA.length+1))})`;case e.CSS:return t;case e.XPath:return`::-p-xpath(${n(t.substring(e.XPath.length+1))})`;case e.Pierce:return`:scope >>> ${t.substring(e.Pierce.length+1)}`;case e.Text:return`::-p-text(${n(t.substring(e.Text.length+1))})`}})).join(" >>>> ")}class D{async beforeAllSteps(e,t){}async afterAllSteps(e,t){}async beforeEachStep(e,t,n){}async stringifyStep(e,t,n){}async afterEachStep(e,t,n){}}class H extends D{async beforeAllSteps(e,t){const n={...t,steps:void 0},r=JSON.stringify(n,null,e.getIndent()).split("\n");r.pop(),r[r.length-1]+=",",r.push(e.getIndent()+'"steps": ['),e.appendLine(r.join("\n")).startBlock().startBlock()}async afterAllSteps(e){e.endBlock().endBlock().appendLine(e.getIndent()+"]").appendLine("}")}async stringifyStep(e,t,n){const r=JSON.stringify(t,null,e.getIndent());if(!n)return void e.appendLine(r);const i=n.steps.lastIndexOf(t)===n.steps.length-1?"":",";e.appendLine(r+i)}}class K{#e;#t=0;#n=[];constructor(e){this.#e=e}appendLine(e){const t=e.split("\n").map((e=>e?this.#e.repeat(this.#t)+e.trimEnd():""));return this.#n.push(...t),this}startBlock(){return this.#t++,this}endBlock(){if(this.#t--,this.#t<0)throw new Error("Extra endBlock");return this}toString(){return this.#n.join("\n")+"\n"}getIndent(){return this.#e}getSize(){return this.#n.length}}function V(e,t){const n=[];return U(e,n,1,t),n.join("")}function U(e,t=[],n=1,r=" "){switch(typeof e){case"bigint":case"symbol":case"function":case"undefined":throw new Error("Invalid JSON");case"number":case"boolean":t.push(String(e));break;case"string":t.push(X(e));break;case"object":if(null===e)t.push("null");else if(Array.isArray(e)){t.push("[\n");for(let i=0;i<e.length;i++)t.push(r.repeat(n)),U(e[i],t,n+1,r),i!==e.length-1&&t.push(","),t.push("\n");t.push(r.repeat(n-1)+"]")}else{t.push("{\n");const i=Object.keys(e);for(let a=0;a<i.length;a++){const o=i[a],s=e[o];void 0!==s&&(t.push(r.repeat(n)),t.push(o),t.push(": "),U(s,t,n+1,r),a!==i.length-1&&t.push(","),t.push("\n"))}t.push(r.repeat(n-1)+"}")}break;default:throw new Error("Unknown object type")}return t}const q=(e,t)=>e.toString(16).toUpperCase().padStart(t,"0"),M=new Map([["\b","\\b"],["\f","\\f"],["\n","\\n"],["\r","\\r"],["\t","\\t"],["\v","\\v"],["'","\\'"],["\\","\\\\"],["\x3c!--","\\x3C!--"],["<script","\\x3Cscript"],["</script","\\x3C/script"]]),X=e=>{const t=/(\\|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,n=/(\\|'|<(?:!--|\/?script))|(\p{Control})|(\p{Surrogate})/gu,r=(e,t,n,r)=>{if(n){if(M.has(n))return M.get(n);return"\\x"+q(n.charCodeAt(0),2)}if(r){return"\\u"+q(r.charCodeAt(0),4)}return t?M.get(t)||"":e};let i="",a="";return e.includes("'")?e.includes('"')?e.includes("`")||e.includes("${")?(a="'",i=e.replace(n,r)):(a="`",i=e.replace(t,r)):(a='"',i=e.replace(t,r)):(a="'",i=e.replace(t,r)),`${a}${i}${a}`};class J extends D{#r=!1;#i;constructor(e="chrome"){super(),this.#i=e}async beforeAllSteps(e,t){e.appendLine("const puppeteer = require('puppeteer'); // v23.0.0 or later"),e.appendLine(""),e.appendLine("(async () => {").startBlock(),"firefox"===this.#i?e.appendLine("const browser = await puppeteer.launch({browser: 'firefox'});"):e.appendLine("const browser = await puppeteer.launch();"),e.appendLine("const page = await browser.newPage();"),e.appendLine(`const timeout = ${t.timeout||Y};`),e.appendLine("page.setDefaultTimeout(timeout);"),e.appendLine(""),this.#r=!1}async afterAllSteps(e,t){if(e.appendLine(""),e.appendLine("await browser.close();"),e.appendLine(""),this.#r)for(const t of _.split("\n"))e.appendLine(t);e.endBlock().appendLine("})().catch(err => {").startBlock(),e.appendLine("console.error(err);"),e.appendLine("process.exit(1);"),e.endBlock().appendLine("});")}async stringifyStep(e,r,i){e.appendLine("{").startBlock(),void 0!==r.timeout&&e.appendLine(`const timeout = ${r.timeout};`),this.#a(e,r);const a=r.assertedEvents&&r.type!==t.Navigate;if(a){e.appendLine("const promises = [];"),e.appendLine("const startWaitingForEvents = () => {").startBlock();for(const t of r.assertedEvents){if(t.type!==n.Navigation)throw new Error(`Event type ${t.type} is not supported`);e.appendLine(`promises.push(${"frame"in r&&r.frame?"frame":"targetPage"}.waitForNavigation());`)}e.endBlock().appendLine("}")}this.#o(e,r),a&&e.appendLine("await Promise.all(promises);"),e.endBlock().appendLine("}")}#s(e,t){"main"===t?e.appendLine("const targetPage = page;"):(e.appendLine(`const target = await browser.waitForTarget(t => t.url() === ${V(t,e.getIndent())}, { timeout });`),e.appendLine("const targetPage = await target.page();"),e.appendLine("targetPage.setDefaultTimeout(timeout);"))}#p(e,t){e.appendLine("let frame = targetPage.mainFrame();");for(const n of t)e.appendLine(`frame = frame.childFrames()[${n}];`)}#a(e,t){this.#s(e,t.target||"main"),t.frame&&this.#p(e,t.frame)}#l(e,t,n){e.appendLine("await puppeteer.Locator.race([").startBlock(),e.appendLine(t.selectors.map((n=>`${t.frame?"frame":"targetPage"}.locator(${V(O(n),e.getIndent())})`)).join(",\n")),e.endBlock().appendLine("])"),e.startBlock().appendLine(".setTimeout(timeout)"),t.assertedEvents?.length&&e.appendLine(".on('action', () => startWaitingForEvents())"),n(),e.endBlock()}#c(e,t){this.#l(e,t,(()=>{e.appendLine(".click({"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#u(e,t){this.#l(e,t,(()=>{e.appendLine(".click({"),e.appendLine(" count: 2,"),t.duration&&e.appendLine(` delay: ${t.duration},`),t.button&&e.appendLine(` button: '${s.get(t.button)}',`),e.appendLine(" offset: {"),e.appendLine(` x: ${t.offsetX},`),e.appendLine(` y: ${t.offsetY},`),e.appendLine(" },"),e.appendLine("});")}))}#f(e,t){this.#l(e,t,(()=>{e.appendLine(".hover();")}))}#d(e,t){this.#l(e,t,(()=>{e.appendLine(`.fill(${V(t.value,e.getIndent())});`)}))}#w(e,t){e.appendLine("await targetPage.emulateNetworkConditions({"),e.appendLine(` offline: ${!t.download&&!t.upload},`),e.appendLine(` downloadThroughput: ${t.download},`),e.appendLine(` uploadThroughput: ${t.upload},`),e.appendLine(` latency: ${t.latency},`),e.appendLine("});")}#h(e,t){e.appendLine(`await targetPage.keyboard.down(${V(t.key,e.getIndent())});`)}#m(e,t){e.appendLine(`await targetPage.keyboard.up(${V(t.key,e.getIndent())});`)}#g(e,t){e.appendLine("await targetPage.close()")}#y(e,t){e.appendLine(`await targetPage.setViewport(${V({width:t.width,height:t.height},e.getIndent())})`)}#b(e,t){"selectors"in t?this.#l(e,t,(()=>{e.appendLine(`.scroll({ scrollTop: ${t.y}, scrollLeft: ${t.x}});`)})):e.appendLine(`await targetPage.evaluate((x, y) => { window.scroll(x, y); }, ${t.x}, ${t.y})`)}#o(e,n){switch(n.type){case t.Click:return this.#c(e,n);case t.DoubleClick:return this.#u(e,n);case t.Hover:return this.#f(e,n);case t.Change:return this.#d(e,n);case t.EmulateNetworkConditions:return this.#w(e,n);case t.KeyDown:return this.#h(e,n);case t.KeyUp:return this.#m(e,n);case t.Close:return this.#g(e,n);case t.SetViewport:return this.#y(e,n);case t.Scroll:return this.#b(e,n);case t.Navigate:return this.#S(e,n);case t.WaitForElement:return this.#E(e,n);case t.WaitForExpression:return this.#v(e,n);case t.CustomStep:return;default:return i(n)}}#S(e,t){e.appendLine(`await targetPage.goto(${V(t.url,e.getIndent())});`)}#v(e,t){e.appendLine(`await ${t.frame?"frame":"targetPage"}.waitForFunction(${V(t.expression,e.getIndent())}, { timeout });`)}#E(e,t){this.#r=!0,e.appendLine(`await waitForElement(${V(t,e.getIndent())}, ${t.frame?"frame":"targetPage"}, timeout);`)}}const Y=5e3,_="async function waitForElement(step, frame, timeout) {\n const {\n count = 1,\n operator = '>=',\n visible = true,\n properties,\n attributes,\n } = step;\n const compFn = {\n '==': (a, b) => a === b,\n '>=': (a, b) => a >= b,\n '<=': (a, b) => a <= b,\n }[operator];\n await waitForFunction(async () => {\n const elements = await querySelectorsAll(step.selectors, frame);\n let result = compFn(elements.length, count);\n const elementsHandle = await frame.evaluateHandle((...elements) => {\n return elements;\n }, ...elements);\n await Promise.all(elements.map((element) => element.dispose()));\n if (result && (properties || attributes)) {\n result = await elementsHandle.evaluate(\n (elements, properties, attributes) => {\n for (const element of elements) {\n if (attributes) {\n for (const [name, value] of Object.entries(attributes)) {\n if (element.getAttribute(name) !== value) {\n return false;\n }\n }\n }\n if (properties) {\n if (!isDeepMatch(properties, element)) {\n return false;\n }\n }\n }\n return true;\n\n function isDeepMatch(a, b) {\n if (a === b) {\n return true;\n }\n if ((a && !b) || (!a && b)) {\n return false;\n }\n if (!(a instanceof Object) || !(b instanceof Object)) {\n return false;\n }\n for (const [key, value] of Object.entries(a)) {\n if (!isDeepMatch(value, b[key])) {\n return false;\n }\n }\n return true;\n }\n },\n properties,\n attributes\n );\n }\n await elementsHandle.dispose();\n return result === visible;\n }, timeout);\n}\n\nasync function querySelectorsAll(selectors, frame) {\n for (const selector of selectors) {\n const result = await querySelectorAll(selector, frame);\n if (result.length) {\n return result;\n }\n }\n return [];\n}\n\nasync function querySelectorAll(selector, frame) {\n if (!Array.isArray(selector)) {\n selector = [selector];\n }\n if (!selector.length) {\n throw new Error('Empty selector provided to querySelectorAll');\n }\n let elements = [];\n for (let i = 0; i < selector.length; i++) {\n const part = selector[i];\n if (i === 0) {\n elements = await frame.$$(part);\n } else {\n const tmpElements = elements;\n elements = [];\n for (const el of tmpElements) {\n elements.push(...(await el.$$(part)));\n }\n }\n if (elements.length === 0) {\n return [];\n }\n if (i < selector.length - 1) {\n const tmpElements = [];\n for (const el of elements) {\n const newEl = (await el.evaluateHandle(el => el.shadowRoot ? el.shadowRoot : el)).asElement();\n if (newEl) {\n tmpElements.push(newEl);\n }\n }\n elements = tmpElements;\n }\n }\n return elements;\n}\n\nasync function waitForFunction(fn, timeout) {\n let isActive = true;\n const timeoutId = setTimeout(() => {\n isActive = false;\n }, timeout);\n while (isActive) {\n const result = await fn();\n if (result) {\n clearTimeout(timeoutId);\n return;\n }\n await new Promise(resolve => setTimeout(resolve, 100));\n }\n throw new Error('Timed out');\n}",z="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",G=z.split("").reduce(((e,t,n)=>(e.set(t,n),e)),new Map),Q=2147483647;function Z(e){if(e<0)throw new Error("Only postive integers and zero are supported");if(e>Q)throw new Error("Only integers between 0 and "+Q+" are supported");const t=[];do{let n=31&e;(e>>>=5)>0&&(n|=32),t.push(z[n])}while(0!==e);return t.join("")}function ee(e){const t=[],n=e.split("");let r=0,i=0;for(const e of n){const n=G.get(e);r|=(31&n)<<i,i+=5;32&n||(t.push(r),r=0,i=0)}return t}const te="//# recorderSourceMap=";async function ne(e,t){t||(t={});const n=t.extension??new J,r=t.writer??new K(t.indentation??" ");await(n.beforeAllSteps?.(r,e));const i=[1];for(const t of e.steps){const a=r.getSize();await(n.beforeEachStep?.(r,t,e)),await n.stringifyStep(r,t,e),await(n.afterEachStep?.(r,t,e));const o=r.getSize();i.push(a,o-a)}return await(n.afterAllSteps?.(r,e)),r.appendLine(te+function(e){const t=[];for(const n of e)t.push(Z(n));return t.join("")}(i)),r.toString()}async function re(e,t){t||(t={});let n=t.extension;n||(n=new J),t.indentation||(t.indentation=" ");const r=t.writer??new K(t.indentation??" ");return await(n.beforeEachStep?.(r,e)),await n.stringifyStep(r,e),await(n.afterEachStep?.(r,e)),r.toString()}function ie(e){return e.trim().startsWith(te)}function ae(e){const t=e.split("\n");for(let e=t.length-1;e>=0;e--){const n=t[e];if(ie(n))return ee(n.trim().substring(22))}}function oe(e){return e.split("\n").filter((e=>!ie(e))).join("\n")}class se{async beforeAllSteps(e){}async afterAllSteps(e){}async beforeEachStep(e,t){}async runStep(e,t){}async afterEachStep(e,t){}}const pe={"==":(e,t)=>e===t,">=":(e,t)=>e>=t,"<=":(e,t)=>e<=t};function le(e){return new Promise((t=>{setTimeout(t,e)}))}class ce extends se{browser;page;timeout;constructor(e,t,n){super(),this.browser=e,this.page=t,this.timeout=n?.timeout||5e3}async#L(e){try{await e._client().send("Emulation.setAutomationOverride",{enabled:!0})}catch{}}#k(e,t){return e.timeout||t?.timeout||this.timeout}async runStep(e,t){const n=this.#k(e,t),r=this.page,i=this.browser,a=await async function(e,t,n,r){if(!n.target||"main"===n.target)return t;const i=await e.waitForTarget((e=>e.url()===n.target),{timeout:r}),a=await i.page();if(!a)return null;return a.setDefaultTimeout(r),a}(i,r,e,n);let o=null;!a&&e.target&&(o=await r.waitForFrame(e.target,{timeout:n}));const s=o||a;if(!s)throw new Error("Target is not found for step: "+JSON.stringify(e));await this.#L(s);const p=await async function(e,t){let n="mainFrame"in e?e.mainFrame():e;if("frame"in t&&t.frame)for(const e of t.frame)n=n.childFrames()[e];return n}(s,e);await this.runStepInFrame(e,r,s,p,n)}async runStepInFrame(e,r,a,o,p){let l=null;const c=()=>{l=async function(e,t,r){const i=[];if(t.assertedEvents)for(const a of t.assertedEvents){if(a.type!==n.Navigation)throw new Error(`Event type ${a.type} is not supported`);i.push(e.waitForNavigation({timeout:r}))}await Promise.all(i)}(o,e,p)},u=this.page.locatorRace;switch(e.type){case t.DoubleClick:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({count:2,button:e.button&&s.get(e.button),delay:e.duration,offset:{x:e.offsetX,y:e.offsetY}});break;case t.Click:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).click({delay:e.duration,button:e.button&&s.get(e.button),offset:{x:e.offsetX,y:e.offsetY}});break;case t.Hover:await u(e.selectors.map((e=>o.locator(O(e))))).setTimeout(p).on("action",(()=>c())).hover();break;case t.EmulateNetworkConditions:c(),await r.emulateNetworkConditions(e);break;case t.KeyDown:c(),await r.keyboard.down(e.key),await le(100);break;case t.KeyUp:c(),await r.keyboard.up(e.key),await le(100);break;case t.Close:"close"in a&&(c(),await a.close());break;case t.Change:await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).fill(e.value);break;case t.SetViewport:"setViewport"in a&&(c(),await a.setViewport(e));break;case t.Scroll:"selectors"in e?await u(e.selectors.map((e=>o.locator(O(e))))).on("action",(()=>c())).setTimeout(p).scroll({scrollLeft:e.x||0,scrollTop:e.y||0}):(c(),await o.evaluate(((e,t)=>{window.scroll(e,t)}),e.x||0,e.y||0));break;case t.Navigate:c(),await o.goto(e.url);break;case t.WaitForElement:try{c(),await async function(e,t,n){const{count:r=1,operator:i=">=",visible:a=!0,properties:o,attributes:s}=e,p=pe[i];await async function(e,t){let n=!0;const r=setTimeout((()=>{n=!1}),t);for(;n;){if(await e())return void clearTimeout(r);await new Promise((e=>setTimeout(e,100)))}throw new Error("Timed out")}((async()=>{const n=await async function(e,t){for(const n of e){const e=await fe(n,t);if(e.length)return e}return[]}(e.selectors,t);let i=p(n.length,r);const l=await t.evaluateHandle(((...e)=>e),...n);return await Promise.all(n.map((e=>e.dispose()))),i&&(o||s)&&(i=await l.evaluate(((e,t,n)=>{if(n)for(const t of e)for(const[e,r]of Object.entries(n))if(t.getAttribute(e)!==r)return!1;if(t)for(const n of e)if(!r(t,n))return!1;return!0;function r(e,t){if(e===t)return!0;if(e&&!t||!e&&t)return!1;if(!(e instanceof Object&&t instanceof Object))return!1;for(const[n,i]of Object.entries(e))if(!r(i,t[n]))return!1;return!0}}),o,s)),await l.dispose(),i===a}),n)}(e,o,p)}catch(e){throw"Timed out"===e.message?new Error("waitForElement timed out. The element(s) could not be found."):e}break;case t.WaitForExpression:c(),await o.waitForFunction(e.expression,{timeout:p});break;case t.CustomStep:break;default:i(e)}await l}}class ue extends ce{async afterAllSteps(){await this.browser.close()}}async function fe(e,t){if(Array.isArray(e)||(e=[e]),!e.length)throw new Error("Empty selector provided to querySelectorAll");let n=await t.$$(e[0]);if(!n.length)return[];for(const t of e.slice(1,e.length))if(n=(await Promise.all(n.map((async e=>{const n=await e.evaluateHandle((e=>e.shadowRoot?e.shadowRoot:e)),r=await n.$$(t);return n.dispose(),e.dispose(),r})))).flat(),!n.length)return[];return n}async function de(e,t,n){await(e.beforeEachStep?.(t,n)),await e.runStep(t,n),await(e.afterEachStep?.(t,n))}class we{#F;#A;#x=!1;constructor(e){this.#A=e}abort(){this.#x=!0}set flow(e){this.#F=e}async runBeforeAllSteps(e){await(this.#A.beforeAllSteps?.(e))}async runAfterAllSteps(e){await(this.#A.afterAllSteps?.(e))}async runStep(e){await de(this.#A,e)}async run(){if(!this.#F)throw new Error("Set the flow on the runner instance before calling `run`.");const e=this.#F;if(this.#x=!1,await(this.#A.beforeAllSteps?.(e)),this.#x)return!1;for(const t of e.steps){if(this.#x)return await(this.#A.afterAllSteps?.(e)),!1;await de(this.#A,t,e)}return await(this.#A.afterAllSteps?.(e)),!0}}async function he(e,t){const n=e instanceof se?void 0:e,r=new we((e instanceof se?e:t)??await async function(){const{default:e}=await import("puppeteer"),t=await e.launch(),n=await t.newPage();return new ue(t,n)}());return n&&(r.flow=n),r}class me extends D{async beforeAllSteps(e){e.appendLine("import url from 'url';"),e.appendLine("import { createRunner } from '@puppeteer/replay';"),e.appendLine(""),e.appendLine("export async function run(extension) {").startBlock(),e.appendLine("const runner = await createRunner(extension);"),e.appendLine(""),e.appendLine("await runner.runBeforeAllSteps();"),e.appendLine("")}async afterAllSteps(e){e.appendLine(""),e.appendLine("await runner.runAfterAllSteps();").endBlock().appendLine("}"),e.appendLine(""),e.appendLine("if (process && import.meta.url === url.pathToFileURL(process.argv[1]).href) {").startBlock().appendLine("run()").endBlock().appendLine("}")}async stringifyStep(e,t){e.appendLine(`await runner.runStep(${V(t,e.getIndent())});`)}}function ge(e){return Boolean(e.type===t.Navigate||e.assertedEvents?.some((e=>e.type===n.Navigation)))}function ye(e){for(const n of e.steps)if(n.type===t.SetViewport)return n.isMobile;return!1}class be extends J{#C=!1;async beforeAllSteps(e,t){e.appendLine("const fs = require('fs');"),await super.beforeAllSteps(e,t),e.appendLine("const lhApi = await import('lighthouse'); // v10.0.0 or later");e.appendLine(`const flags = ${V({screenEmulation:{disabled:!0}},e.getIndent())}`),ye(t)?e.appendLine("const config = undefined;"):e.appendLine("const config = lhApi.desktopConfig;"),e.appendLine(`const lhFlow = await lhApi.startFlow(page, {name: ${V(t.title,e.getIndent())}, config, flags});`)}async stringifyStep(e,n,r){if(n.type===t.SetViewport)return void await super.stringifyStep(e,n,r);const i=ge(n);i?(this.#C&&(e.appendLine("await lhFlow.endTimespan();"),this.#C=!1),e.appendLine("await lhFlow.startNavigation();")):this.#C||(e.appendLine("await lhFlow.startTimespan();"),this.#C=!0),await super.stringifyStep(e,n,r),i&&e.appendLine("await lhFlow.endNavigation();")}async afterAllSteps(e,t){this.#C&&e.appendLine("await lhFlow.endTimespan();"),e.appendLine("const lhFlowReport = await lhFlow.generateReport();"),e.appendLine("fs.writeFileSync(__dirname + '/flow.report.html', lhFlowReport)"),await super.afterAllSteps(e,t)}}class Se extends ce{#T=!1;#$=!1;#N;async createFlowResult(){if(!this.#N)throw new Error("Cannot get flow result before running the flow");return this.#N.createFlowResult()}async beforeAllSteps(e){await(super.beforeAllSteps?.(e));const{startFlow:t,desktopConfig:n}=await import("lighthouse");let r;ye(e)||(r=n),this.#N=await t(this.page,{config:r,flags:{screenEmulation:{disabled:!0}},name:e.title})}async beforeEachStep(e,n){await(super.beforeEachStep?.(e,n)),e.type!==t.SetViewport&&(ge(e)?(this.#T&&(await this.#N.endTimespan(),this.#T=!1),await this.#N.startNavigation(),this.#$=!0):this.#T||(await this.#N.startTimespan(),this.#T=!0))}async afterEachStep(e,t){this.#$&&(await this.#N.endNavigation(),this.#$=!1),await(super.afterEachStep?.(e,t))}async afterAllSteps(e){this.#T&&await this.#N.endTimespan(),await(super.afterAllSteps?.(e))}}export{n as AssertedEventType,H as JSONStringifyExtension,Se as LighthouseRunnerExtension,be as LighthouseStringifyExtension,me as PuppeteerReplayStringifyExtension,ce as PuppeteerRunnerExtension,ue as PuppeteerRunnerOwningBrowserExtension,J as PuppeteerStringifyExtension,we as Runner,se as RunnerExtension,r as Schema,e as SelectorType,t as StepType,D as StringifyExtension,i as assertAllStepTypesAreHandled,he as createRunner,X as formatAsJSLiteral,V as formatJSONAsJS,W as getSelectorType,I as maxTimeout,P as minTimeout,s as mouseButtonMap,B as parse,ae as parseSourceMap,$ as parseStep,o as pointerDeviceTypes,O as selectorToPElementSelector,ne as stringify,re as stringifyStep,oe as stripSourceMap,a as typeableInputTypes,j as validTimeout}; | |||
Check failure
Code scanning / CodeQL
Incomplete multi-character sanitization High library
<!--
| import*as e from"../code_highlighter/code_highlighter.js";import*as t from"../../lit-html/lit-html.js";import*as o from"../../visual_logging/visual_logging.js";const s=new CSSStyleSheet;s.replaceSync(".token-variable{color:var(--sys-color-token-variable)}.token-property{color:var(--sys-color-token-property)}.token-type{color:var(--sys-color-token-type)}.token-variable-special{color:var(--sys-color-token-variable-special)}.token-definition{color:var(--sys-color-token-definition)}.token-builtin{color:var(--sys-color-token-builtin)}.token-number{color:var(--sys-color-token-number)}.token-string{color:var(--sys-color-token-string)}.token-string-special{color:var(--sys-color-token-string-special)}.token-atom{color:var(--sys-color-token-atom)}.token-keyword{color:var(--sys-color-token-keyword)}.token-comment{color:var(--sys-color-token-comment)}.token-meta{color:var(--sys-color-token-meta)}.token-invalid{color:var(--sys-color-error)}.token-tag{color:var(--sys-color-token-tag)}.token-attribute{color:var(--sys-color-token-attribute)}.token-attribute-value{color:var(--sys-color-token-attribute-value)}.token-inserted{color:var(--sys-color-token-inserted)}.token-deleted{color:var(--sys-color-token-deleted)}.token-heading{color:var(--sys-color-token-variable-special);font-weight:bold}.token-link{color:var(--sys-color-token-variable-special);text-decoration:underline}.token-strikethrough{text-decoration:strike-through}.token-strong{font-weight:bold}.token-emphasis{font-style:italic}\n/*# sourceURL=codeHighlighter.css */\n");const i=new CSSStyleSheet;i.replaceSync('*{box-sizing:border-box;font-size:inherit;margin:0;padding:0}:host{position:relative}devtools-editable-content{background:transparent;border:none;color:var(--override-color-recorder-input,var(--sys-color-on-surface));cursor:text;display:inline-block;line-height:18px;min-height:18px;min-width:0.5em;outline:none;overflow-wrap:anywhere}devtools-editable-content:hover,\ndevtools-editable-content:focus{box-shadow:0 0 0 1px var(--sys-color-divider);border-radius:2px}devtools-editable-content[placeholder]:empty::before{content:attr(placeholder);color:var(--sys-color-on-surface);opacity:50%}devtools-editable-content[placeholder]:empty:focus::before{content:""}devtools-suggestion-box{position:absolute;display:none}devtools-editable-content:focus ~ devtools-suggestion-box{display:block}.suggestions{background-color:var(--sys-color-cdt-base-container);box-shadow:var(--drop-shadow);min-height:1em;min-width:150px;overflow-x:hidden;overflow-y:auto;position:relative;z-index:100;max-height:350px}.suggestions > li{padding:1px;border:1px solid transparent;white-space:nowrap;font-family:var(--source-code-font-family);font-size:var(--source-code-font-size);color:var(--sys-color-on-surface)}.suggestions > li:hover{background-color:var(--sys-color-state-hover-on-subtle)}.suggestions > li.selected{background-color:var(--sys-color-primary);color:var(--sys-color-cdt-base-container)}.strikethrough{text-decoration:line-through}\n/*# sourceURL=suggestionInput.css */\n');var n=self&&self.__decorate||function(e,t,o,s){var i,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,o,s);else for(var l=e.length-1;l>=0;l--)(i=e[l])&&(r=(n<3?i(r):n>3?i(t,o,r):i(t,o))||r);return n>3&&r&&Object.defineProperty(t,o,r),r};function r(e,t="Assertion failed!"){if(!e)throw new Error(t)}const{html:l,Decorators:a,Directives:c,LitElement:h}=t,{customElement:d,property:u,state:g}=a,{classMap:p}=c,v={hasChanged:(e,t)=>JSON.stringify(e)!==JSON.stringify(t)};let y=class extends HTMLElement{static get observedAttributes(){return["disabled","placeholder"]}set disabled(e){this.contentEditable=String(!e)}get disabled(){return"true"!==this.contentEditable}set value(e){this.innerText=e,this.#e()}get value(){return this.innerText}set mimeType(e){this.#t=e,this.#e()}get mimeType(){return this.#t}#t="";constructor(){super(),this.contentEditable="true",this.tabIndex=0,this.addEventListener("focus",(()=>{this.innerHTML=this.innerText})),this.addEventListener("blur",this.#e.bind(this))}#e(){this.#t&&e.CodeHighlighter.highlightNode(this,this.#t)}attributeChangedCallback(e,t,o){if("disabled"===e)this.disabled=null!==o}};y=n([d("devtools-editable-content")],y);class b extends Event{static eventName="suggest";constructor(e){super(b.eventName),this.suggestion=e}}class m extends Event{static eventName="suggestioninit";listeners;constructor(e){super(m.eventName),this.listeners=e}}const k=(e,t)=>e.toLowerCase().startsWith(t.toLowerCase());let f=class extends h{static styles=[i];#o=[];constructor(){super(),this.options=[],this.expression="",this.cursor=0}#s=e=>{if(r(e instanceof KeyboardEvent,"Bound to the wrong event."),this.#o.length>0)switch(e.key){case"ArrowDown":e.stopPropagation(),e.preventDefault(),this.#i(1);break;case"ArrowUp":e.stopPropagation(),e.preventDefault(),this.#i(-1)}if("Enter"===e.key)this.#o[this.cursor]&&this.#n(this.#o[this.cursor]),e.preventDefault()};#i(e){var t,o;this.cursor=(t=this.cursor+e,o=this.#o.length,(t%o+o)%o)}#n(e){this.dispatchEvent(new b(e))}connectedCallback(){super.connectedCallback(),this.dispatchEvent(new m([["keydown",this.#s]]))}willUpdate(e){e.has("options")&&(this.options=Object.freeze([...this.options].sort())),(e.has("expression")||e.has("options"))&&(this.cursor=0,this.#o=this.options.filter((e=>(this.suggestionFilter||k)(e,this.expression))))}render(){if(0!==this.#o.length)return l`<ul class="suggestions"> | ||
| ${this.#o.map(((e,t)=>l`<li | ||
| class=${p({selected:t===this.cursor})} | ||
| import*as e from"../code_highlighter/code_highlighter.js";import*as t from"../../lit/lit.js";import*as o from"../../visual_logging/visual_logging.js";var s={cssText:`.token-variable{color:var(--sys-color-token-variable)}.token-property{color:var(--sys-color-token-property)}.token-type{color:var(--sys-color-token-type)}.token-variable-special{color:var(--sys-color-token-variable-special)}.token-definition{color:var(--sys-color-token-definition)}.token-builtin{color:var(--sys-color-token-builtin)}.token-number{color:var(--sys-color-token-number)}.token-string{color:var(--sys-color-token-string)}.token-string-special{color:var(--sys-color-token-string-special)}.token-atom{color:var(--sys-color-token-atom)}.token-keyword{color:var(--sys-color-token-keyword)}.token-comment{color:var(--sys-color-token-comment)}.token-meta{color:var(--sys-color-token-meta)}.token-invalid{color:var(--sys-color-error)}.token-tag{color:var(--sys-color-token-tag)}.token-attribute{color:var(--sys-color-token-attribute)}.token-attribute-value{color:var(--sys-color-token-attribute-value)}.token-inserted{color:var(--sys-color-token-inserted)}.token-deleted{color:var(--sys-color-token-deleted)}.token-heading{color:var(--sys-color-token-variable-special);font-weight:bold}.token-link{color:var(--sys-color-token-variable-special);text-decoration:underline}.token-strikethrough{text-decoration:line-through}.token-strong{font-weight:bold}.token-emphasis{font-style:italic}\n/*# sourceURL=${import.meta.resolve("./codeHighlighter.css")} */\n`},i={cssText:`*{box-sizing:border-box;font-size:inherit;margin:0;padding:0}:host{position:relative}devtools-editable-content{background:transparent;border:none;color:var(--override-color-recorder-input,var(--sys-color-on-surface));cursor:text;display:inline-block;line-height:18px;min-height:18px;min-width:0.5em;outline:none;overflow-wrap:anywhere}devtools-editable-content:hover,\ndevtools-editable-content:focus{box-shadow:0 0 0 1px var(--sys-color-divider);border-radius:2px}devtools-editable-content[placeholder]:empty::before{content:attr(placeholder);color:var(--sys-color-on-surface);opacity:50%}devtools-editable-content[placeholder]:empty:focus::before{content:""}devtools-suggestion-box{position:absolute;display:none}devtools-editable-content:focus ~ devtools-suggestion-box{display:block}.suggestions{background-color:var(--sys-color-cdt-base-container);box-shadow:var(--drop-shadow);min-height:1em;min-width:150px;overflow:hidden auto;position:relative;z-index:100;max-height:350px}.suggestions > li{padding:1px;border:1px solid transparent;white-space:nowrap;font-family:var(--source-code-font-family);font-size:var(--source-code-font-size);color:var(--sys-color-on-surface)}.suggestions > li:hover{background-color:var(--sys-color-state-hover-on-subtle)}.suggestions > li.selected{background-color:var(--sys-color-primary);color:var(--sys-color-cdt-base-container)}.strikethrough{text-decoration:line-through}\n/*# sourceURL=${import.meta.resolve("./suggestionInput.css")} */\n`},n=self&&self.__decorate||function(e,t,o,s){var i,n=arguments.length,r=n<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,o):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,o,s);else for(var l=e.length-1;l>=0;l--)(i=e[l])&&(r=(n<3?i(r):n>3?i(t,o,r):i(t,o))||r);return n>3&&r&&Object.defineProperty(t,o,r),r};const r=new CSSStyleSheet;r.replaceSync(s.cssText);const l=new CSSStyleSheet;l.replaceSync(i.cssText);function a(e,t="Assertion failed!"){if(!e)throw new Error(t)}const{html:c,Decorators:h,Directives:d,LitElement:u}=t,{customElement:g,property:p,state:v}=h,{classMap:y}=d,b={hasChanged:(e,t)=>JSON.stringify(e)!==JSON.stringify(t),attribute:!1};let m=class extends HTMLElement{static get observedAttributes(){return["disabled","placeholder"]}set disabled(e){this.contentEditable=String(!e)}get disabled(){return"true"!==this.contentEditable}set value(e){this.innerText=e,this.#e()}get value(){return this.innerText}set mimeType(e){this.#t=e,this.#e()}get mimeType(){return this.#t}#t="";constructor(){super(),this.contentEditable="true",this.tabIndex=0,this.addEventListener("focus",(()=>{this.innerHTML=this.innerText})),this.addEventListener("blur",this.#e.bind(this))}#e(){this.#t&&e.CodeHighlighter.highlightNode(this,this.#t)}attributeChangedCallback(e,t,o){if("disabled"===e)this.disabled=null!==o}};m=n([g("devtools-editable-content")],m);class k extends Event{static eventName="suggest";constructor(e){super(k.eventName),this.suggestion=e}}class f extends Event{static eventName="suggestioninit";listeners;constructor(e){super(f.eventName),this.listeners=e}}const x=(e,t)=>e.toLowerCase().startsWith(t.toLowerCase());let w=class extends u{static styles=[l];#o=[];constructor(){super(),this.options=[],this.expression="",this.cursor=0}#s=e=>{if(a(e instanceof KeyboardEvent,"Bound to the wrong event."),this.#o.length>0)switch(e.key){case"ArrowDown":e.stopPropagation(),e.preventDefault(),this.#i(1);break;case"ArrowUp":e.stopPropagation(),e.preventDefault(),this.#i(-1)}if("Enter"===e.key)this.#o[this.cursor]&&this.#n(this.#o[this.cursor]),e.preventDefault()};#i(e){var t,o;this.cursor=(t=this.cursor+e,o=this.#o.length,(t%o+o)%o)}#n(e){this.dispatchEvent(new k(e))}connectedCallback(){super.connectedCallback(),this.dispatchEvent(new f([["keydown",this.#s]]))}willUpdate(e){e.has("options")&&(this.options=Object.freeze([...this.options].sort())),(e.has("expression")||e.has("options"))&&(this.cursor=0,this.#o=this.options.filter((e=>(this.suggestionFilter||x)(e,this.expression))))}render(){if(0!==this.#o.length)return c`<ul class="suggestions"> |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium library
DOM text
| @@ -1 +1 @@ | |||
| import*as e from"../../../../core/common/common.js";import*as t from"../../../../core/host/host.js";import*as n from"../../../../core/i18n/i18n.js";import*as i from"../../../../core/platform/platform.js";import*as o from"../../../../core/sdk/sdk.js";import*as r from"../../../../models/bindings/bindings.js";import*as s from"../../../visual_logging/visual_logging.js";import*as a from"../../legacy.js";import*as c from"../../../../models/breakpoints/breakpoints.js";import*as l from"../../../../models/text_utils/text_utils.js";import*as d from"../../../../models/workspace/workspace.js";const u=new CSSStyleSheet;u.replaceSync(".image-preview-container{background:transparent;text-align:center;border-spacing:0}.image-preview-container img{margin:6px 0;max-width:100px;max-height:100px;background-image:var(--image-file-checker);user-select:text;vertical-align:top;-webkit-user-drag:auto}.image-container{padding:0}.image-container > div{min-height:50px;display:flex;align-items:center;justify-content:center;cursor:pointer}.image-preview-container .row{line-height:1.2;vertical-align:baseline}.image-preview-container .title{padding-right:0.5em;text-align:right;color:var(--sys-color-token-subtle);white-space:nowrap}.image-preview-container .description{white-space:nowrap;text-align:left;color:var(--sys-color-on-surface)}.image-preview-container .description-link{max-width:20em}.image-preview-container .source-link{white-space:normal;word-break:break-all;color:var(--sys-color-primary);cursor:pointer}\n/*# sourceURL=imagePreview.css */\n");const p={unknownSource:"unknown source",imageFromS:"Image from {PH1}",fileSize:"File size:",intrinsicSize:"Intrinsic size:",renderedSize:"Rendered size:",currentSource:"Current source:",renderedAspectRatio:"Rendered aspect ratio:",intrinsicAspectRatio:"Intrinsic aspect ratio:"},g=n.i18n.registerUIStrings("ui/legacy/components/utils/ImagePreview.ts",p),m=n.i18n.getLocalizedString.bind(void 0,g);function h(t){return null!==t&&t.resourceType()===e.ResourceType.resourceTypes.Image}var k=Object.freeze({__proto__:null,ImagePreview:class{static async build(e,n,r,s={precomputedFeatures:void 0,imageAltText:void 0}){const{precomputedFeatures:a,imageAltText:c}=s,l=e.model(o.ResourceTreeModel.ResourceTreeModel);if(!l)return null;let d=l.resourceForURL(n),g=n;if(!h(d)&&a&&a.currentSrc&&(g=a.currentSrc,d=l.resourceForURL(g)),!d||!h(d))return null;const k=d,L=d.displayName,C=d.content?d.content:d.url.split("base64,")[1],b=d.contentSize(),f=b||i.StringUtilities.base64ToSize(C),w=f>0?i.NumberUtilities.bytesToString(f):"";return new Promise((e=>{const n=document.createElement("img");n.addEventListener("load",(function(){const o=document.createElement("div"),s=o.attachShadow({mode:"open"});s.adoptedStyleSheets=[u];const c=s.createChild("table");c.className="image-preview-container";const l=c.createChild("tr").createChild("td","image-container");l.colSpan=2;const d=l.createChild("div");d.title=L,d.appendChild(n),d.addEventListener("click",(()=>{t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(g)}));const h=n.naturalWidth,k=n.naturalHeight,C=a?a.renderedWidth:h,b=a?a.renderedHeight:k;if(r){const e=c.createChild("tr","row");e.createChild("td","title").textContent=m(p.renderedSize),e.createChild("td","description").textContent=`${C} × ${b} px`;const t=c.createChild("tr","row");if(t.createChild("td","title").textContent=m(p.renderedAspectRatio),t.createChild("td","description").textContent=i.NumberUtilities.aspectRatio(C,b),b!==k||C!==h){const e=c.createChild("tr","row");e.createChild("td","title").textContent=m(p.intrinsicSize),e.createChild("td","description").textContent=`${h} × ${k} px`;const t=c.createChild("tr","row");t.createChild("td","title").textContent=m(p.intrinsicAspectRatio),t.createChild("td","description").textContent=i.NumberUtilities.aspectRatio(h,k)}}const f=c.createChild("tr","row");f.createChild("td","title").textContent=m(p.fileSize),f.createChild("td","description").textContent=w;const v=c.createChild("tr","row");v.createChild("td","title").textContent=m(p.currentSource);const I=i.StringUtilities.trimMiddle(g,100),S=v.createChild("td","description description-link").createChild("span","source-link");S.textContent=I,S.addEventListener("click",(()=>{t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(g)})),e(o)}),!1),n.addEventListener("error",(()=>e(null)),!1),c&&(n.alt=c),k.populateImageSource(n)}))}static async loadDimensionsForNode(e){if(!e.nodeName()||"img"!==e.nodeName().toLowerCase())return;const t=await e.resolveToObject("");if(!t)return;const n=await t.callFunctionJSON((function(){return{renderedWidth:this.width,renderedHeight:this.height,currentSrc:this.currentSrc}}),void 0);return t.release(),n}static defaultAltTextForImageURL(t){const n=new e.ParsedURL.ParsedURL(t),i=n.isValid?n.displayName:m(p.unknownSource);return m(p.imageFromS,{PH1:i})}}});const L=new CSSStyleSheet;L.replaceSync(":host{display:inline}:host(.width-constrained){display:inline-block;width:100%}.stack-preview-async-description{padding:3px 0 1px;font-weight:bold}.stack-preview-container.width-constrained{display:block;width:100%}.stack-preview-container .ignore-list-link{opacity:60%}.stack-preview-container > tr{height:16px;line-height:16px}.stack-preview-container td{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-inline:2px}.stack-preview-container.width-constrained td.link{width:100%;max-width:0}.stack-preview-container .function-name{max-width:80em}.stack-preview-container:not(.show-hidden-rows) > tr.hidden-row{display:none}.stack-preview-container > tr.show-all-link,\n.stack-preview-container > tr.show-less-link{font-style:italic}.stack-preview-container.show-hidden-rows > tr.show-all-link{display:none}.stack-preview-container:not(.show-hidden-rows) > tr.show-less-link{display:none}\n/*# sourceURL=jsUtils.css */\n");const C={unknown:"(unknown)",auto:"auto",revealInS:"Reveal in {PH1}",reveal:"Reveal",openUsingS:"Open using {PH1}",linkHandling:"Link handling:"},b=n.i18n.registerUIStrings("ui/legacy/components/utils/Linkifier.ts",C),f=n.i18n.getLocalizedString.bind(void 0,b),w=new Set;let v=null;const I=new WeakMap,S=new WeakMap,x=new WeakMap,y=new Map;let T,U;class N extends e.ObjectWrapper.ObjectWrapper{maxLength;anchorsByTarget;locationPoolByTarget;useLinkDecorator;constructor(e,t){super(),this.maxLength=e||a.UIUtils.MaxLengthForDisplayedURLs,this.anchorsByTarget=new Map,this.locationPoolByTarget=new Map,this.useLinkDecorator=Boolean(t),w.add(this),o.TargetManager.TargetManager.instance().observeTargets(this)}static setLinkDecorator(e){console.assert(!v,"Cannot re-register link decorator."),v=e,e.addEventListener("LinkIconChanged",(function(e){const t=e.data,n=I.get(t)||[];for(const e of n)N.updateLinkDecorations(e)}));for(const e of w)e.updateAllAnchorDecorations()}updateAllAnchorDecorations(){for(const e of this.anchorsByTarget.values())for(const t of e)N.updateLinkDecorations(t)}static bindUILocation(e,t){const n=N.linkInfo(e);if(!n)return;if(n.uiLocation=t,!t)return;const i=t.uiSourceCode;let o=I.get(i);o||(o=new Set,I.set(i,o)),o.add(e)}static unbindUILocation(e){const t=N.linkInfo(e);if(!t||!t.uiLocation)return;const n=t.uiLocation.uiSourceCode;t.uiLocation=null;const i=I.get(n);i&&i.delete(e)}static bindBreakpoint(e,t){const n=N.linkInfo(e);if(!n)return;const i=c.BreakpointManager.BreakpointManager.instance().findBreakpoint(t);i&&(n.revealable=i)}static unbindBreakpoint(e){const t=N.linkInfo(e);t&&t.revealable&&(t.revealable=null)}targetAdded(e){this.anchorsByTarget.set(e,[]),this.locationPoolByTarget.set(e,new r.LiveLocation.LiveLocationPool)}targetRemoved(e){const t=this.locationPoolByTarget.get(e);if(this.locationPoolByTarget.delete(e),!t)return;t.disposeAll();const n=this.anchorsByTarget.get(e);if(n){this.anchorsByTarget.delete(e);for(const e of n){const t=N.linkInfo(e);if(!t)continue;t.liveLocation=null,N.unbindUILocation(e);const n=t.fallback;n&&e.replaceWith(n)}}}maybeLinkifyScriptLocation(e,t,n,i,s){let a=null;const c={lineNumber:i,maxLength:this.maxLength,columnNumber:s?.columnNumber,showColumnNumber:Boolean(s?.showColumnNumber),className:s?.className,tabStop:s?.tabStop,inlineFrameIndex:s?.inlineFrameIndex??0,userMetric:s?.userMetric,jslogContext:s?.jslogContext||"script-location"},{columnNumber:l,className:d=""}=c;if(n&&(a=N.linkifyURL(n,c)),!e||e.isDisposed())return a;const u=e.model(o.DebuggerModel.DebuggerModel);if(!u)return a;const p=t?u.createRawLocationByScriptId(t,i||0,l,c.inlineFrameIndex):u.createRawLocationByURL(n,i||0,l,c.inlineFrameIndex,!0);if(!p)return a;const g={tabStop:s?.tabStop,jslogContext:"script-location"},{link:m,linkInfo:h}=N.createLink(a&&a.textContent?a.textContent:"",d,g);h.enableDecorator=this.useLinkDecorator,h.fallback=a,h.userMetric=s?.userMetric;const k=this.locationPoolByTarget.get(p.debuggerModel.target());if(!k)return a;const L={showColumnNumber:c.showColumnNumber??!1,revealBreakpoint:s?.revealBreakpoint};r.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createLiveLocation(p,(async e=>{await this.updateAnchor(m,L,e),this.dispatchEventToListeners("liveLocationUpdated",e)}).bind(this),k).then((e=>{e&&(h.liveLocation=e)}));return this.anchorsByTarget.get(p.debuggerModel.target()).push(m),m}linkifyScriptLocation(e,t,n,i,o){const r=this.maybeLinkifyScriptLocation(e,t,n,i,o),s={lineNumber:i,maxLength:this.maxLength,className:o?.className,columnNumber:o?.columnNumber,showColumnNumber:Boolean(o?.showColumnNumber),inlineFrameIndex:o?.inlineFrameIndex??0,tabStop:o?.tabStop,userMetric:o?.userMetric,jslogContext:o?.jslogContext||"script-source-url"};return r||N.linkifyURL(n,s)}linkifyRawLocation(e,t,n){return this.linkifyScriptLocation(e.debuggerModel.target(),e.scriptId,t,e.lineNumber,{columnNumber:e.columnNumber,className:n,inlineFrameIndex:e.inlineFrameIndex})}maybeLinkifyConsoleCallFrame(e,t,n){const i={...n,columnNumber:t.columnNumber,inlineFrameIndex:n?.inlineFrameIndex??0};return this.maybeLinkifyScriptLocation(e,String(t.scriptId),t.url,t.lineNumber,i)}linkifyStackTraceTopFrame(e,t){console.assert(t.callFrames.length>0);const{url:n,lineNumber:i,columnNumber:s}=t.callFrames[0],a=N.linkifyURL(n,{lineNumber:i,columnNumber:s,showColumnNumber:!1,inlineFrameIndex:0,maxLength:this.maxLength,preventClick:!0,jslogContext:"script-source-url"});if(!e)return a;const c=this.locationPoolByTarget.get(e);if(!c)return console.assert(e.isDisposed()),a;console.assert(!e.isDisposed());const l=e.model(o.DebuggerModel.DebuggerModel),{link:d,linkInfo:u}=N.createLink("","",{jslogContext:"script-location"});u.enableDecorator=this.useLinkDecorator,u.fallback=a;const p={showColumnNumber:!1};r.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createStackTraceTopFrameLiveLocation(l.createRawLocationsByStackTrace(t),(async e=>{await this.updateAnchor(d,p,e),this.dispatchEventToListeners("liveLocationUpdated",e)}).bind(this),c).then((e=>{u.liveLocation=e}));return this.anchorsByTarget.get(e).push(d),d}linkifyCSSLocation(e,t){const{link:n,linkInfo:i}=N.createLink("",t||"",{tabStop:!0,jslogContext:"css-location"});i.enableDecorator=this.useLinkDecorator;const o=this.locationPoolByTarget.get(e.cssModel().target());if(!o)return n;const s={showColumnNumber:!1};r.CSSWorkspaceBinding.CSSWorkspaceBinding.instance().createLiveLocation(e,(async e=>{await this.updateAnchor(n,s,e),this.dispatchEventToListeners("liveLocationUpdated",e)}).bind(this),o).then((e=>{i.liveLocation=e}));return this.anchorsByTarget.get(e.cssModel().target()).push(n),n}reset(){for(const e of[...this.anchorsByTarget.keys()])this.targetRemoved(e),this.targetAdded(e);this.listeners?.clear()}dispose(){for(const e of[...this.anchorsByTarget.keys()])this.targetRemoved(e);o.TargetManager.TargetManager.instance().unobserveTargets(this),w.delete(this)}async updateAnchor(t,n,i){N.unbindUILocation(t),n.revealBreakpoint&&N.unbindBreakpoint(t);const o=await i.uiLocation();if(!o){if(i instanceof r.CSSWorkspaceBinding.LiveLocation){const n=i.header();n&&n.ownerNode&&(t.addEventListener("click",(t=>{t.consume(!0),e.Revealer.reveal(n.ownerNode||null)}),!1),N.setTrimmedText(t,"<style>"))}return t.classList.add("invalid-link"),void t.removeAttribute("role")}N.bindUILocation(t,o),n.revealBreakpoint&&N.bindBreakpoint(t,o);const s=o.linkText(!0,n.showColumnNumber);N.setTrimmedText(t,s,this.maxLength);let c=o.uiSourceCode.url();"application/wasm"===o.uiSourceCode.mimeType()?"number"==typeof o.columnNumber&&(c+=`:0x${o.columnNumber.toString(16)}`):(c+=":"+(o.lineNumber+1),n.showColumnNumber&&"number"==typeof o.columnNumber&&(c+=":"+(o.columnNumber+1))),a.Tooltip.Tooltip.install(t,c),t.classList.toggle("ignore-list-link",await i.isIgnoreListed()),N.updateLinkDecorations(t)}static updateLinkDecorations(e){const t=N.linkInfo(e);if(!t||!t.enableDecorator)return;if(!v||!t.uiLocation)return;t.icon&&t.icon.parentElement&&e.removeChild(t.icon);const n=v.linkIcon(t.uiLocation.uiSourceCode);n&&(n.style.setProperty("margin-right","2px"),e.insertBefore(n,e.firstChild)),t.icon=n}static linkifyURL(t,n){const i=(n=n||{showColumnNumber:!1,inlineFrameIndex:0}).text,o=n.className||"",s=n.lineNumber,c=n.columnNumber,l=n.showColumnNumber,d=n.preventClick,u=n.maxLength||a.UIUtils.MaxLengthForDisplayedURLs,p=n.bypassURLTrimming;if(!t||e.ParsedURL.schemeIs(t,"javascript:")){const e=document.createElement("span");return o&&(e.className=o),e.textContent=i||t||f(C.unknown),e}let g=i||r.ResourceUtils.displayNameForURL(t);"number"!=typeof s||i||(g+=":"+(s+1),l&&"number"==typeof c&&(g+=":"+(c+1)));const m={maxLength:u,title:g!==t?t:"",href:t,preventClick:d,tabStop:n.tabStop,bypassURLTrimming:p,jslogContext:n.jslogContext||"url"},{link:h,linkInfo:k}=N.createLink(g,o,m);return s&&(k.lineNumber=s),c&&(k.columnNumber=c),k.userMetric=n?.userMetric,h}static linkifyRevealable(e,t,n,i,o,r){const s={maxLength:a.UIUtils.MaxLengthForDisplayedURLs,href:n,title:i,jslogContext:r},{link:c,linkInfo:l}=N.createLink(t,o||"",s);return l.revealable=e,c}static createLink(e,t,n={}){const{maxLength:i,title:o,href:r,preventClick:c,tabStop:l,bypassURLTrimming:d,jslogContext:u}=n,p=document.createElement(n.preventClick?"span":"button");t&&(p.className=t),p.classList.add("devtools-link"),n.preventClick||p.classList.add("text-button","link-style"),o&&a.Tooltip.Tooltip.install(p,o),r&&(p.href=r),p.setAttribute("jslog",`${s.link(u).track({click:!0})}`),e instanceof HTMLElement?p.appendChild(e):d?(p.classList.add("devtools-link-styled-trim"),N.appendTextWithoutHashes(p,e)):N.setTrimmedText(p,e,i);const g={icon:null,enableDecorator:!1,uiLocation:null,liveLocation:null,url:r||null,lineNumber:null,columnNumber:null,inlineFrameIndex:0,revealable:null,fallback:null};return S.set(p,g),c?p.classList.add("devtools-link-prevent-click"):p.addEventListener("click",(e=>{N.handleClick(e)&&e.consume(!0)}),!1),a.ARIAUtils.markAsLink(p),p.tabIndex=l?0:-1,{link:p,linkInfo:g}}static setTrimmedText(e,t,n){if(e.removeChildren(),n&&t.length>n){const i=function(e,t){let n=Math.floor(t/2),i=e.length-Math.ceil(t/2)+1;const o=e.codePointAt(i-1);void 0!==o&&o>=65536&&(i++,n++);const r=e.codePointAt(n-1);void 0!==r&&n>0&&r>=65536&&n--;return[e.substring(0,n),e.substring(n,i),e.substring(i)]}(t,n);N.appendTextWithoutHashes(e,i[0]),N.appendHiddenText(e,i[1]),N.appendTextWithoutHashes(e,i[2])}else N.appendTextWithoutHashes(e,t)}static appendTextWithoutHashes(e,t){const n=l.TextUtils.Utils.splitStringByRegexes(t,[/[a-f0-9]{20,}/g]);for(const t of n)-1===t.regexIndex?a.UIUtils.createTextChild(e,t.value):(a.UIUtils.createTextChild(e,t.value.substring(0,7)),N.appendHiddenText(e,t.value.substring(7)))}static appendHiddenText(e,t){const n=a.UIUtils.createTextChild(e.createChild("span","devtools-link-ellipsis"),"…");x.set(n,t)}static untruncatedNodeText(e){return x.get(e)||e.textContent||""}static linkInfo(e){return e&&S.get(e)||null}static handleClick(e){const t=e.currentTarget;if(a.UIUtils.isBeingEdited(e.target)||t.hasSelection())return!1;const n=N.linkInfo(t);return!!n&&N.invokeFirstAction(n)}static handleClickFromNewComponentLand(e){N.invokeFirstAction(e)}static invokeFirstAction(e){const n=N.linkActions(e);return!!n.length&&(n[0].handler.call(null),e.userMetric&&t.userMetrics.actionTaken(e.userMetric),!0)}static linkHandlerSetting(){return T||(T=e.Settings.Settings.instance().createSetting("open-link-handler",f(C.auto))),T}static registerLinkHandler(e,t){y.set(e,t),F.instance().update()}static unregisterLinkHandler(e){y.delete(e),F.instance().update()}static uiLocation(e){const t=N.linkInfo(e);return t?t.uiLocation:null}static linkActions(n){const o=[];if(!n)return o;let s=i.DevToolsPath.EmptyUrlString,c=null;if(n.uiLocation)c=n.uiLocation,s=c.uiSourceCode.contentURL();else if(n.url){s=n.url;const t=d.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(s)||d.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(e.ParsedURL.ParsedURL.urlWithoutHash(s));c=t?t.uiLocation(n.lineNumber||0,n.columnNumber||0):null}const l=s?r.ResourceUtils.resourceForURL(s):null,u=c?c.uiSourceCode:l,p=n.revealable||c||l;if(p){const t=e.Revealer.revealDestination(p);o.push({section:"reveal",title:t?f(C.revealInS,{PH1:t}):f(C.reveal),jslogContext:"reveal",handler:()=>e.Revealer.reveal(p)})}if(u){const e=c?c.lineNumber:n.lineNumber||0;for(const t of y.keys()){const n=y.get(t);if(!n)continue;const i={section:"reveal",title:f(C.openUsingS,{PH1:t}),jslogContext:"open-using",handler:n.bind(null,u,e)};t===N.linkHandlerSetting().get()?o.unshift(i):o.push(i)}}if((l||n.url)&&(o.push({section:"reveal",title:a.UIUtils.openLinkExternallyLabel(),jslogContext:"open-in-new-tab",handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(s)}),o.push({section:"clipboard",title:a.UIUtils.copyLinkAddressLabel(),jslogContext:"copy-link-address",handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(s)})),c&&c.uiSourceCode){const e=c.uiSourceCode;o.push({section:"clipboard",title:a.UIUtils.copyFileNameLabel(),jslogContext:"copy-file-name",handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(e.displayName())})}return o}}class F{element;constructor(){this.element=document.createElement("select"),this.element.classList.add("chrome-select"),this.element.addEventListener("change",this.onChange.bind(this),!1),this.update()}static instance(e={forceNew:null}){const{forceNew:t}=e;return U&&!t||(U=new F),U}update(){this.element.removeChildren();const e=[...y.keys()];e.unshift(f(C.auto));for(const t of e){const e=document.createElement("option");e.textContent=t,e.selected=t===N.linkHandlerSetting().get(),this.element.appendChild(e)}this.element.disabled=e.length<=1}onChange(e){if(!e.target)return;const t=e.target.value;N.linkHandlerSetting().set(t)}settingElement(){return a.SettingsUI.createCustomSetting(f(C.linkHandling),this.element)}}let D=!1;D||(D=!0,window.addEventListener("linkifieractivated",(function(e){const t=e;N.handleClickFromNewComponentLand(t.data)})));var R=Object.freeze({__proto__:null,Linkifier:N,LinkContextMenuProvider:class{appendApplicableItems(e,t,n){let i=n;for(;i&&!S.get(i);)i=i.parentNodeOrShadowHost();const o=i,r=N.linkInfo(o);if(!r)return;const s=N.linkActions(r);for(const e of s)t.section(e.section).appendItem(e.title,e.handler,{jslogContext:e.jslogContext})}},LinkHandlerSettingUI:F,ContentProviderContextMenuProvider:class{appendApplicableItems(n,i,r){const s=r.contentURL();if(s){e.ParsedURL.schemeIs(s,"file:")||i.revealSection().appendItem(a.UIUtils.openLinkExternallyLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(s.endsWith(":formatted")?e.ParsedURL.ParsedURL.slice(s,0,s.lastIndexOf(":")):s)),{jslogContext:"open-in-new-tab"});for(const e of y.keys()){const t=y.get(e);t&&i.revealSection().appendItem(f(C.openUsingS,{PH1:e}),t.bind(null,r,0),{jslogContext:"open-using"})}r instanceof o.NetworkRequest.NetworkRequest||(i.clipboardSection().appendItem(a.UIUtils.copyLinkAddressLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(s)),{jslogContext:"copy-link-address"}),r instanceof d.UISourceCode.UISourceCode?i.clipboardSection().appendItem(a.UIUtils.copyFileNameLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(r.displayName())),{jslogContext:"copy-file-name"}):i.clipboardSection().appendItem(a.UIUtils.copyFileNameLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(r.displayName)),{jslogContext:"copy-file-name"}))}}}});const M={removeFromIgnore:"Remove from ignore list",addToIgnore:"Add script to ignore list",showSMoreFrames:"{n, plural, =1 {Show # more frame} other {Show # more frames}}",showLess:"Show less",unknownSource:"unknown"},H=n.i18n.registerUIStrings("ui/legacy/components/utils/JSPresentationUtils.ts",M),B=n.i18n.getLocalizedString.bind(void 0,H);function j(e,t){const n=new a.ContextMenu.ContextMenu(t);t.consume(!0);const i=N.uiLocation(e);i&&r.IgnoreListManager.IgnoreListManager.instance().canIgnoreListUISourceCode(i.uiSourceCode)&&(r.IgnoreListManager.IgnoreListManager.instance().isUserIgnoreListedURL(i.uiSourceCode.url())?n.debugSection().appendItem(B(M.removeFromIgnore),(()=>r.IgnoreListManager.IgnoreListManager.instance().unIgnoreListUISourceCode(i.uiSourceCode)),{jslogContext:"remove-from-ignore-list"}):n.debugSection().appendItem(B(M.addToIgnore),(()=>r.IgnoreListManager.IgnoreListManager.instance().ignoreListUISourceCode(i.uiSourceCode)),{jslogContext:"add-to-ignore-list"})),n.appendApplicableItems(t),n.show()}function P(t,n,i,c,l,d){const u=[];if(l){const t=new e.Throttler.Throttler(100);i.addEventListener("liveLocationUpdated",(()=>{t.schedule((async()=>function(e,t){let n=0,i=t.length;for(let e=t.length-1;e>=0;e--){const o=t[e];if("link"in o&&o.link){const e=N.uiLocation(o.link);e&&r.IgnoreListManager.IgnoreListManager.instance().isUserOrSourceMapIgnoreListedUISourceCode(e.uiSourceCode)&&(o.ignoreListHide=!0),o.ignoreListHide&&n++}"asyncDescription"in o&&(n>0&&n===i-e-1&&(o.ignoreListHide=!0),i=e,n=0)}e(t)}(l,u)))}))}function p(e,t=void 0){let l=null;t&&(l={asyncDescription:a.UIUtils.asyncStackTraceLabel(e.description,t),ignoreListHide:!1},u.push(l));let p=0,g=!1;for(const t of e.callFrames){let e=!1;const l=a.UIUtils.beautifyFunctionName(t.functionName),m=i.maybeLinkifyConsoleCallFrame(n,t,{showColumnNumber:d,tabStop:Boolean(c),inlineFrameIndex:0,revealBreakpoint:g});if(m){m.setAttribute("jslog",`${s.link("stack-trace").track({click:!0})}`),m.addEventListener("contextmenu",j.bind(null,m));const t=N.uiLocation(m);t&&r.IgnoreListManager.IgnoreListManager.instance().isUserOrSourceMapIgnoreListedUISourceCode(t.uiSourceCode)&&(e=!0),m.textContent||(m.textContent=B(M.unknownSource))}e&&++p,u.push({functionName:l,link:m,ignoreListHide:e}),g=[o.DebuggerModel.COND_BREAKPOINT_SOURCE_URL,o.DebuggerModel.LOGPOINT_SOURCE_URL].includes(t.url)}l&&p>0&&p===e.callFrames.length&&(l.ignoreListHide=!0)}p(t);let g=t.callFrames;for(let e=t.parent;e;e=e.parent)e.callFrames.length&&p(e,g),g=e.callFrames;return u}function A(e,t){e.removeChildren();let n=0;const i=[];for(const o of t){const t=e.createChild("tr");"asyncDescription"in o?(t.createChild("td").textContent="\n",t.createChild("td","stack-preview-async-description").textContent=o.asyncDescription,t.createChild("td"),t.createChild("td")):(t.createChild("td").textContent="\n",t.createChild("td","function-name").textContent=o.functionName,t.createChild("td").textContent=" @ ",o.link&&(t.createChild("td","link").appendChild(o.link),i.push(o.link)),o.ignoreListHide&&++n),o.ignoreListHide&&t.classList.add("hidden-row"),e.appendChild(t)}if(n){const t=e.createChild("tr","show-all-link");t.createChild("td").textContent="\n";const i=t.createChild("td");i.colSpan=4;const o=i.createChild("span","link");o.textContent=B(M.showSMoreFrames,{n:n}),o.addEventListener("click",(()=>{e.classList.add("show-hidden-rows"),a.GlassPane.GlassPane.containerMoved(e)}),!1);const r=e.createChild("tr","show-less-link");r.createChild("td").textContent="\n";const s=r.createChild("td");s.colSpan=4;const c=s.createChild("span","link");c.textContent=B(M.showLess),c.addEventListener("click",(()=>{e.classList.remove("show-hidden-rows"),a.GlassPane.GlassPane.containerMoved(e)}),!1)}return i}var E=Object.freeze({__proto__:null,buildStackTraceRows:P,buildStackTracePreviewContents:function(e,t,n={widthConstrained:!1,stackTrace:void 0,tabStops:void 0}){const{stackTrace:i,tabStops:o}=n,r=document.createElement("span");r.classList.add("monospace"),r.classList.add("stack-preview-container"),r.classList.toggle("width-constrained",n.widthConstrained),r.style.display="inline-block";const s=a.UIUtils.createShadowRootWithCoreStyles(r,{cssFile:[L],delegatesFocus:void 0}).createChild("table","stack-preview-container");if(s.classList.toggle("width-constrained",n.widthConstrained),!i)return{element:r,links:[]};const c=A.bind(null,s);return{element:r,links:A(s,P(i,e,t,o,c,n.showColumnNumber))}}});var _=Object.freeze({__proto__:null,reload:function(){a.DockController.DockController.instance().canDock()&&"undocked"===a.DockController.DockController.instance().dockSide()&&t.InspectorFrontendHost.InspectorFrontendHostInstance.setIsDocked(!0,(function(){})),t.InspectorFrontendHost.InspectorFrontendHostInstance.reattach((()=>window.location.reload()))}});const W={websocketDisconnected:"WebSocket disconnected"},z=n.i18n.registerUIStrings("ui/legacy/components/utils/TargetDetachedDialog.ts",W),O=n.i18n.getLocalizedString.bind(void 0,z);class $ extends o.SDKModel.SDKModel{static hideCrashedDialog;constructor(e){super(e),e.registerInspectorDispatcher(this),e.inspectorAgent().invoke_enable(),e.parentTarget()?.type()===o.Target.Type.Browser&&$.hideCrashedDialog&&($.hideCrashedDialog.call(null),$.hideCrashedDialog=null)}detached({reason:e}){a.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(e)}static webSocketConnectionLost(){a.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(O(W.websocketDisconnected))}targetCrashed(){if($.hideCrashedDialog)return;const e=this.target().parentTarget();if(e&&e.type()!==o.Target.Type.Browser)return;const t=new a.Dialog.Dialog("target-crashed");t.setSizeBehavior("MeasureContent"),t.addCloseButton(),t.setDimmed(!0),$.hideCrashedDialog=t.hide.bind(t),new a.TargetCrashedScreen.TargetCrashedScreen((()=>{$.hideCrashedDialog=null})).show(t.contentElement),t.show()}targetReloadedAfterCrash(){this.target().runtimeAgent().invoke_runIfWaitingForDebugger(),$.hideCrashedDialog&&($.hideCrashedDialog.call(null),$.hideCrashedDialog=null)}}o.SDKModel.SDKModel.register($,{capabilities:2048,autostart:!0});var G=Object.freeze({__proto__:null,TargetDetachedDialog:$});export{k as ImagePreview,E as JSPresentationUtils,R as Linkifier,_ as Reload,G as TargetDetachedDialog}; | |||
| import*as e from"../../../../core/common/common.js";import*as t from"../../../../core/host/host.js";import*as n from"../../../../core/i18n/i18n.js";import*as o from"../../../../core/platform/platform.js";import*as i from"../../../../core/sdk/sdk.js";import*as r from"../../../../models/bindings/bindings.js";import*as s from"../../../visual_logging/visual_logging.js";import*as a from"../../legacy.js";import*as c from"../../../../models/breakpoints/breakpoints.js";import*as l from"../../../../models/text_utils/text_utils.js";import*as d from"../../../../models/workspace/workspace.js";var u={cssText:`.image-preview-container{background:transparent;text-align:center;border-spacing:0}.image-preview-container img{margin:6px 0;max-width:100px;max-height:100px;background-image:var(--image-file-checker);user-select:text;vertical-align:top;-webkit-user-drag:auto}.image-container{padding:0}.image-container > div{min-height:50px;display:flex;align-items:center;justify-content:center;cursor:pointer}.image-container > div.start{justify-content:start}.image-preview-container .row{line-height:1.2;vertical-align:baseline}.image-preview-container .title{padding-right:0.5em;color:var(--sys-color-token-subtle);white-space:nowrap;&.start{text-align:start}&.center{text-align:end}}.image-preview-container .description{white-space:nowrap;text-align:left;color:var(--sys-color-on-surface)}.image-preview-container .description-link{max-width:20em}.image-preview-container .source-link{white-space:normal;word-break:break-all;color:var(--sys-color-primary);cursor:pointer}\n/*# sourceURL=${import.meta.resolve("./imagePreview.css")} */\n`};const p={unknownSource:"unknown source",imageFromS:"Image from {PH1}",fileSize:"File size:",intrinsicSize:"Intrinsic size:",renderedSize:"Rendered size:",currentSource:"Current source:",renderedAspectRatio:"Rendered aspect ratio:",intrinsicAspectRatio:"Intrinsic aspect ratio:"},g=n.i18n.registerUIStrings("ui/legacy/components/utils/ImagePreview.ts",p),h=n.i18n.getLocalizedString.bind(void 0,g);function m(t){return null!==t&&t.resourceType()===e.ResourceType.resourceTypes.Image}var k=Object.freeze({__proto__:null,ImagePreview:class{static async build(e,r,s,a={precomputedFeatures:void 0,imageAltText:void 0,align:"center"}){const{precomputedFeatures:c,imageAltText:l,align:d}=a;let g=i.ResourceTreeModel.ResourceTreeModel.resourceForURL(r),k=r;if(!m(g)&&c&&c.currentSrc&&(k=c.currentSrc,g=i.ResourceTreeModel.ResourceTreeModel.resourceForURL(k)),!g||!m(g))return null;const C=g,b=g.displayName,L=g.content?g.content:g.url.split("base64,")[1],f=g.contentSize(),v=f||o.StringUtilities.base64ToSize(L),w=v>0?n.ByteUtilities.bytesToString(v):"";return await new Promise((e=>{const n=document.createElement("img");n.addEventListener("load",(function(){const i=document.createElement("div"),r=i.attachShadow({mode:"open"});r.createChild("style").textContent=u.cssText;const l=r.createChild("table");l.className="image-preview-container";const g=l.createChild("tr").createChild("td","image-container");g.colSpan=2;const m=g.createChild("div",` ${d}`);m.title=b,m.appendChild(n),m.addEventListener("click",(()=>{t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(k)}));const C=n.naturalWidth,L=n.naturalHeight,f=c?c.renderedWidth:C,v=c?c.renderedHeight:L;if(s){const e=l.createChild("tr","row");e.createChild("td",`title ${d}`).textContent=h(p.renderedSize),e.createChild("td","description").textContent=`${f} × ${v} px`;const t=l.createChild("tr","row");if(t.createChild("td",`title ${d}`).textContent=h(p.renderedAspectRatio),t.createChild("td","description").textContent=o.NumberUtilities.aspectRatio(f,v),v!==L||f!==C){const e=l.createChild("tr","row");e.createChild("td",`title ${d}`).textContent=h(p.intrinsicSize),e.createChild("td","description").textContent=`${C} × ${L} px`;const t=l.createChild("tr","row");t.createChild("td",`title ${d}`).textContent=h(p.intrinsicAspectRatio),t.createChild("td","description").textContent=o.NumberUtilities.aspectRatio(C,L)}}if(!a.hideFileData){const e=l.createChild("tr","row");e.createChild("td",`title ${d}`).textContent=h(p.fileSize),e.createChild("td","description").textContent=w;const n=l.createChild("tr","row");n.createChild("td",`title ${d}`).textContent=h(p.currentSource);const i=o.StringUtilities.trimMiddle(k,100),r=n.createChild("td","description description-link").createChild("span","source-link");r.textContent=i,r.addEventListener("click",(()=>{t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(k)}))}e(i)}),!1),n.addEventListener("error",(()=>e(null)),!1),l&&(n.alt=l),C.populateImageSource(n)}))}static async loadDimensionsForNode(e){if(!e.nodeName()||"img"!==e.nodeName().toLowerCase())return;const t=await e.resolveToObject("");if(!t)return;const n=await t.callFunctionJSON((function(){return{renderedWidth:this.width,renderedHeight:this.height,currentSrc:this.currentSrc}}),void 0);return t.release(),n}static defaultAltTextForImageURL(t){const n=new e.ParsedURL.ParsedURL(t),o=n.isValid?n.displayName:h(p.unknownSource);return h(p.imageFromS,{PH1:o})}}}),C={cssText:`:host{display:inline}:host(.width-constrained){display:inline-block;width:100%}.stack-preview-async-description{padding:3px 0 1px;font-weight:bold}.stack-preview-container{--display-ignored-row:none;--display-toggle-link:var(--override-display-stack-preview-toggle-link,none);& > tfoot > tr{font-style:italic;display:var(--display-toggle-link)}& > tbody{display:var(--override-display-stack-preview-tbody,table-row-group);& > tr{height:16px;line-height:16px;&:has(td.link > .ignore-list-link){opacity:60%;display:var(--display-ignored-row)}}&:has(tr > td.link > .ignore-list-link){&:not(:has(tr > td.link > .devtools-link:not(.ignore-list-link))){.stack-preview-async-row{display:var(--display-ignored-row)}}}}&:not(:has(tbody > tr > td.link > .devtools-link:not(.ignore-list-link))),\n &.show-hidden-rows{--display-ignored-row:table-row}&:has(tbody > tr > td.link > .ignore-list-link):has(tbody > tr > td.link > .devtools-link:not(.ignore-list-link)){--display-toggle-link:table-row}td{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;padding-inline:2px;&.link{overflow:visible;& > button.text-button.devtools-link{background-color:inherit}}}&.width-constrained{display:block;width:100%;td.link{width:100%;max-width:0}}.function-name{max-width:80em}&.show-hidden-rows > tfoot > tr.show-all-link{--display-toggle-link:none}&:not(.show-hidden-rows) > tfoot > tr.show-less-link{--display-toggle-link:none}}.css-inserted-text::before{content:attr(data-inserted-text)}\n/*# sourceURL=${import.meta.resolve("./jsUtils.css")} */\n`};const b={unknown:"(unknown)",auto:"auto",revealInS:"Reveal in {PH1}",reveal:"Reveal",openUsingS:"Open using {PH1}",linkHandling:"Link handling:"},L=n.i18n.registerUIStrings("ui/legacy/components/utils/Linkifier.ts",b),f=n.i18n.getLocalizedString.bind(void 0,L),v=new Set;let w=null;const y=new WeakMap,I=new WeakMap,x=new WeakMap,S=new Map;let T,U;class N extends e.ObjectWrapper.ObjectWrapper{maxLength;anchorsByTarget=new Map;locationPoolByTarget=new Map;useLinkDecorator;#e;constructor(e,t){super(),this.maxLength=e||a.UIUtils.MaxLengthForDisplayedURLs,this.useLinkDecorator=Boolean(t),this.#e=new WeakMap,v.add(this),i.TargetManager.TargetManager.instance().observeTargets(this),d.Workspace.WorkspaceImpl.instance().addEventListener(d.Workspace.Events.WorkingCopyChanged,this.#t,this),d.Workspace.WorkspaceImpl.instance().addEventListener(d.Workspace.Events.WorkingCopyCommitted,this.#t,this)}#t({data:{uiSourceCode:e}}){const t=y.get(e);if(t)for(const e of t){const t=this.#e.get(e);t&&t.call(this,e)}}static setLinkDecorator(e){console.assert(!w,"Cannot re-register link decorator."),w=e,e.addEventListener("LinkIconChanged",(function(e){const t=e.data,n=y.get(t)||[];for(const e of n)N.updateLinkDecorations(e)}));for(const e of v)e.updateAllAnchorDecorations()}updateAllAnchorDecorations(){for(const e of this.anchorsByTarget.values())for(const t of e)N.updateLinkDecorations(t)}static bindUILocation(e,t){const n=N.linkInfo(e);if(!n)return;if(n.uiLocation=t,!t)return;const o=t.uiSourceCode;let i=y.get(o);i||(i=new Set,y.set(o,i)),i.add(e)}static bindUILocationForTest(e,t){N.bindUILocation(e,t)}static unbindUILocation(e){const t=N.linkInfo(e);if(!t?.uiLocation)return;const n=t.uiLocation.uiSourceCode;t.uiLocation=null;const o=y.get(n);o&&o.delete(e)}static bindBreakpoint(e,t){const n=N.linkInfo(e);if(!n)return;const o=c.BreakpointManager.BreakpointManager.instance().findBreakpoint(t);o&&(n.revealable=o)}static unbindBreakpoint(e){const t=N.linkInfo(e);t?.revealable&&(t.revealable=null)}targetAdded(e){this.anchorsByTarget.set(e,[]),this.locationPoolByTarget.set(e,new r.LiveLocation.LiveLocationPool)}targetRemoved(e){const t=this.locationPoolByTarget.get(e);if(this.locationPoolByTarget.delete(e),!t)return;t.disposeAll();const n=this.anchorsByTarget.get(e);if(n){this.anchorsByTarget.delete(e);for(const e of n){const t=N.linkInfo(e);if(!t)continue;t.liveLocation=null,N.unbindUILocation(e);const n=t.fallback;n&&e.replaceWith(n)}}}maybeLinkifyScriptLocation(e,t,n,o,s){let a=null;const c={lineNumber:o,maxLength:this.maxLength,columnNumber:s?.columnNumber,showColumnNumber:Boolean(s?.showColumnNumber),className:s?.className,tabStop:s?.tabStop,inlineFrameIndex:s?.inlineFrameIndex??0,userMetric:s?.userMetric,jslogContext:s?.jslogContext||"script-location",omitOrigin:s?.omitOrigin},{columnNumber:l,className:d=""}=c;if(n&&(a=N.linkifyURL(n,c)),!e||e.isDisposed())return a;const u=e.model(i.DebuggerModel.DebuggerModel);if(!u)return a;const p=t?u.createRawLocationByScriptId(t,o||0,l,c.inlineFrameIndex):u.createRawLocationByURL(n,o||0,l,c.inlineFrameIndex,!0);if(!p)return a;const g={tabStop:s?.tabStop,jslogContext:"script-location"},{link:h,linkInfo:m}=N.createLink(a?.textContent?a.textContent:"",d,g);m.enableDecorator=this.useLinkDecorator,m.fallback=a,m.userMetric=s?.userMetric;const k=this.locationPoolByTarget.get(p.debuggerModel.target());if(!k)return a;const C={showColumnNumber:c.showColumnNumber??!1,revealBreakpoint:s?.revealBreakpoint};r.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createLiveLocation(p,(async e=>{await this.updateAnchor(h,C,e),this.dispatchEventToListeners("liveLocationUpdated",e)}).bind(this),k).then((e=>{e&&(m.liveLocation=e)}));return this.anchorsByTarget.get(p.debuggerModel.target()).push(h),h}linkifyScriptLocation(e,t,n,o,i){const r=this.maybeLinkifyScriptLocation(e,t,n,o,i),s={lineNumber:o,maxLength:this.maxLength,className:i?.className,columnNumber:i?.columnNumber,showColumnNumber:Boolean(i?.showColumnNumber),inlineFrameIndex:i?.inlineFrameIndex??0,tabStop:i?.tabStop,userMetric:i?.userMetric,jslogContext:i?.jslogContext||"script-source-url"};return r||N.linkifyURL(n,s)}linkifyRawLocation(e,t,n){return this.linkifyScriptLocation(e.debuggerModel.target(),e.scriptId,t,e.lineNumber,{columnNumber:e.columnNumber,className:n,inlineFrameIndex:e.inlineFrameIndex})}maybeLinkifyConsoleCallFrame(e,t,n){const o={...n,columnNumber:t.columnNumber,inlineFrameIndex:n?.inlineFrameIndex??0};return this.maybeLinkifyScriptLocation(e,String(t.scriptId),t.url,t.lineNumber,o)}linkifyStackTraceTopFrame(e,t){console.assert(t.callFrames.length>0);const{url:n,lineNumber:o,columnNumber:s}=t.callFrames[0],a=N.linkifyURL(n,{lineNumber:o,columnNumber:s,showColumnNumber:!1,inlineFrameIndex:0,maxLength:this.maxLength,preventClick:!0,jslogContext:"script-source-url"});if(!e)return a;const c=this.locationPoolByTarget.get(e);if(!c)return console.assert(e.isDisposed()),a;console.assert(!e.isDisposed());const l=e.model(i.DebuggerModel.DebuggerModel),{link:d,linkInfo:u}=N.createLink("","",{jslogContext:"script-location"});u.enableDecorator=this.useLinkDecorator,u.fallback=a;const p={showColumnNumber:!1};r.DebuggerWorkspaceBinding.DebuggerWorkspaceBinding.instance().createStackTraceTopFrameLiveLocation(l.createRawLocationsByStackTrace(t),(async e=>{await this.updateAnchor(d,p,e),this.dispatchEventToListeners("liveLocationUpdated",e)}).bind(this),c).then((e=>{u.liveLocation=e}));return this.anchorsByTarget.get(e).push(d),d}linkifyCSSLocation(e,t){const{link:n,linkInfo:o}=N.createLink("",t||"",{tabStop:!0,jslogContext:"css-location"});o.enableDecorator=this.useLinkDecorator;const i=this.locationPoolByTarget.get(e.cssModel().target());if(!i)return n;const s={showColumnNumber:!1};r.CSSWorkspaceBinding.CSSWorkspaceBinding.instance().createLiveLocation(e,(async e=>{await this.updateAnchor(n,s,e),this.dispatchEventToListeners("liveLocationUpdated",e)}).bind(this),i).then((e=>{o.liveLocation=e}));return this.anchorsByTarget.get(e.cssModel().target()).push(n),n}reset(){for(const e of[...this.anchorsByTarget.keys()])this.targetRemoved(e),this.targetAdded(e);this.listeners?.clear()}dispose(){d.Workspace.WorkspaceImpl.instance().removeEventListener(d.Workspace.Events.WorkingCopyChanged,this.#t,this),d.Workspace.WorkspaceImpl.instance().removeEventListener(d.Workspace.Events.WorkingCopyCommitted,this.#t,this);for(const e of[...this.anchorsByTarget.keys()])this.targetRemoved(e);i.TargetManager.TargetManager.instance().unobserveTargets(this),v.delete(this)}async updateAnchor(t,n,o){N.unbindUILocation(t),n.revealBreakpoint&&N.unbindBreakpoint(t);const i=await o.uiLocation();if(!i){if(o instanceof r.CSSWorkspaceBinding.LiveLocation){const n=o.header();n?.ownerNode&&(t.addEventListener("click",(t=>{t.consume(!0),e.Revealer.reveal(n.ownerNode||null)}),!1),N.setTrimmedText(t,"<style>"))}return t.classList.add("invalid-link"),void t.removeAttribute("role")}N.bindUILocation(t,i),n.revealBreakpoint&&N.bindBreakpoint(t,i);const s=i.linkText(!0,n.showColumnNumber);N.setTrimmedText(t,s,this.maxLength),this.#e.set(t,(function(e){this.updateAnchor(e,n,o)}));let c=i.uiSourceCode.url();"application/wasm"===i.uiSourceCode.mimeType()?"number"==typeof i.columnNumber&&(c+=`:0x${i.columnNumber.toString(16)}`):(c+=":"+(i.lineNumber+1),n.showColumnNumber&&"number"==typeof i.columnNumber&&(c+=":"+(i.columnNumber+1))),a.Tooltip.Tooltip.install(t,c),t.classList.toggle("ignore-list-link",await o.isIgnoreListed()),N.updateLinkDecorations(t)}static updateLinkDecorations(e){const t=N.linkInfo(e);if(!t?.enableDecorator)return;if(!w||!t.uiLocation)return;t.icon?.parentElement&&e.removeChild(t.icon);const n=w.linkIcon(t.uiLocation.uiSourceCode);n&&(n.style.setProperty("margin-right","2px"),e.insertBefore(n,e.firstChild)),t.icon=n}static linkifyURL(t,n){const o=(n=n||{showColumnNumber:!1,inlineFrameIndex:0}).text,i=n.className||"",s=n.lineNumber,c=n.columnNumber,l=n.showColumnNumber,d=n.preventClick,u=n.maxLength||a.UIUtils.MaxLengthForDisplayedURLs,p=n.bypassURLTrimming,g=n.omitOrigin;if(!t||e.ParsedURL.schemeIs(t,"javascript:")){const e=document.createElement("span");return i&&(e.className=i),e.textContent=o||t||f(b.unknown),e}let h=o||r.ResourceUtils.displayNameForURL(t);if(g){const e=URL.parse(t);e&&(h=t.replace(e.origin,""))}"number"!=typeof s||o||(h+=":"+(s+1),l&&"number"==typeof c&&(h+=":"+(c+1)));const m={maxLength:u,title:h!==t?t:"",href:t,preventClick:d,tabStop:n.tabStop,bypassURLTrimming:p,jslogContext:n.jslogContext||"url"},{link:k,linkInfo:C}=N.createLink(h,i,m);return s&&(C.lineNumber=s),c&&(C.columnNumber=c),C.userMetric=n?.userMetric,k}static linkifyRevealable(e,t,n,o,i,r){const s={maxLength:a.UIUtils.MaxLengthForDisplayedURLs,href:n,title:o,jslogContext:r},{link:c,linkInfo:l}=N.createLink(t,i||"",s);return l.revealable=e,c}static createLink(e,t,n={}){const{maxLength:o,title:i,href:r,preventClick:c,tabStop:l,bypassURLTrimming:d,jslogContext:u}=n,p=document.createElement(n.preventClick?"span":"button");t&&(p.className=t),p.classList.add("devtools-link"),n.preventClick||p.classList.add("text-button","link-style"),i&&a.Tooltip.Tooltip.install(p,i),r&&(p.href=r),p.setAttribute("jslog",`${s.link(u).track({click:!0})}`),e instanceof HTMLElement?p.appendChild(e):d?(p.classList.add("devtools-link-styled-trim"),N.appendTextWithoutHashes(p,e)):N.setTrimmedText(p,e,o);const g={icon:null,enableDecorator:!1,uiLocation:null,liveLocation:null,url:r||null,lineNumber:null,columnNumber:null,inlineFrameIndex:0,revealable:null,fallback:null};return I.set(p,g),c?p.classList.add("devtools-link-prevent-click"):p.addEventListener("click",(e=>{N.handleClick(e)&&e.consume(!0)}),!1),a.ARIAUtils.markAsLink(p),p.tabIndex=l?0:-1,{link:p,linkInfo:g}}static setTrimmedText(e,t,n){if(e.removeChildren(),n&&t.length>n){const o=function(e,t){let n=Math.floor(t/2),o=e.length-Math.ceil(t/2)+1;const i=e.codePointAt(o-1);void 0!==i&&i>=65536&&(o++,n++);const r=e.codePointAt(n-1);void 0!==r&&n>0&&r>=65536&&n--;return[e.substring(0,n),e.substring(n,o),e.substring(o)]}(t,n);N.appendTextWithoutHashes(e,o[0]),N.appendHiddenText(e,o[1]),N.appendTextWithoutHashes(e,o[2])}else N.appendTextWithoutHashes(e,t)}static appendTextWithoutHashes(e,t){const n=l.TextUtils.Utils.splitStringByRegexes(t,[/[a-f0-9]{20,}/g]);for(const t of n)-1===t.regexIndex?a.UIUtils.createTextChild(e,t.value):(a.UIUtils.createTextChild(e,t.value.substring(0,7)),N.appendHiddenText(e,t.value.substring(7)))}static appendHiddenText(e,t){const n=a.UIUtils.createTextChild(e.createChild("span","devtools-link-ellipsis"),"…");x.set(n,t)}static untruncatedNodeText(e){return x.get(e)||e.textContent||""}static linkInfo(e){return e&&I.get(e)||null}static handleClick(e){const t=e.currentTarget;if(a.UIUtils.isBeingEdited(e.target)||t.hasSelection())return!1;const n=N.linkInfo(t);return!!n&&N.invokeFirstAction(n)}static handleClickFromNewComponentLand(e){N.invokeFirstAction(e)}static invokeFirstAction(e){const n=N.linkActions(e);return!!n.length&&(n[0].handler.call(null),e.userMetric&&t.userMetrics.actionTaken(e.userMetric),!0)}static linkHandlerSetting(){return T||(T=e.Settings.Settings.instance().createSetting("open-link-handler",f(b.auto))),T}static registerLinkHandler(e,t){S.set(e,t),D.instance().update()}static unregisterLinkHandler(e){S.delete(e),D.instance().update()}static uiLocation(e){const t=N.linkInfo(e);return t?t.uiLocation:null}static linkActions(n){const i=[];if(!n)return i;let s=o.DevToolsPath.EmptyUrlString,c=null;if(n.uiLocation)c=n.uiLocation,s=c.uiSourceCode.contentURL();else if(n.url){s=n.url;const t=d.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(s)||d.Workspace.WorkspaceImpl.instance().uiSourceCodeForURL(e.ParsedURL.ParsedURL.urlWithoutHash(s));c=t?t.uiLocation(n.lineNumber||0,n.columnNumber||0):null}const l=s?r.ResourceUtils.resourceForURL(s):null,u=c?c.uiSourceCode:l,p=n.revealable||c||l;if(p){const t=e.Revealer.revealDestination(p);i.push({section:"reveal",title:t?f(b.revealInS,{PH1:t}):f(b.reveal),jslogContext:"reveal",handler:()=>e.Revealer.reveal(p)})}if(u){const e=c?c.lineNumber:n.lineNumber||0;for(const t of S.keys()){const n=S.get(t);if(!n)continue;const o={section:"reveal",title:f(b.openUsingS,{PH1:t}),jslogContext:"open-using",handler:n.bind(null,u,e)};t===N.linkHandlerSetting().get()?i.unshift(o):i.push(o)}}if((l||n.url)&&(i.push({section:"reveal",title:a.UIUtils.openLinkExternallyLabel(),jslogContext:"open-in-new-tab",handler:()=>a.UIUtils.openInNewTab(s)}),i.push({section:"clipboard",title:a.UIUtils.copyLinkAddressLabel(),jslogContext:"copy-link-address",handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(s)})),c?.uiSourceCode){const e=c.uiSourceCode;i.push({section:"clipboard",title:a.UIUtils.copyFileNameLabel(),jslogContext:"copy-file-name",handler:()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(e.displayName())})}return i}}class D{element;constructor(){this.element=document.createElement("select"),this.element.addEventListener("change",this.onChange.bind(this),!1),this.update()}static instance(e={forceNew:null}){const{forceNew:t}=e;return U&&!t||(U=new D),U}update(){this.element.removeChildren();const e=[...S.keys()];e.unshift(f(b.auto));for(const t of e){const e=document.createElement("option");e.textContent=t,e.selected=t===N.linkHandlerSetting().get(),this.element.appendChild(e)}this.element.disabled=e.length<=1}onChange(e){if(!e.target)return;const t=e.target.value;N.linkHandlerSetting().set(t)}settingElement(){return a.SettingsUI.createCustomSetting(f(b.linkHandling),this.element)}}let R=!1;R||(R=!0,window.addEventListener("linkifieractivated",(function(e){const t=e;N.handleClickFromNewComponentLand(t.data)})));var F=Object.freeze({__proto__:null,ContentProviderContextMenuProvider:class{appendApplicableItems(n,o,r){const s=r.contentURL();if(s){e.ParsedURL.schemeIs(s,"file:")||o.revealSection().appendItem(a.UIUtils.openLinkExternallyLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.openInNewTab(s.endsWith(":formatted")?e.ParsedURL.ParsedURL.slice(s,0,s.lastIndexOf(":")):s)),{jslogContext:"open-in-new-tab"});for(const e of S.keys()){const t=S.get(e);t&&o.revealSection().appendItem(f(b.openUsingS,{PH1:e}),t.bind(null,r,0),{jslogContext:"open-using"})}r instanceof i.NetworkRequest.NetworkRequest||(o.clipboardSection().appendItem(a.UIUtils.copyLinkAddressLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(s)),{jslogContext:"copy-link-address"}),r instanceof d.UISourceCode.UISourceCode?o.clipboardSection().appendItem(a.UIUtils.copyFileNameLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(r.displayName())),{jslogContext:"copy-file-name"}):o.clipboardSection().appendItem(a.UIUtils.copyFileNameLabel(),(()=>t.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(r.displayName)),{jslogContext:"copy-file-name"}))}}},LinkContextMenuProvider:class{appendApplicableItems(e,t,n){let o=n;for(;o&&!I.get(o);)o=o.parentNodeOrShadowHost();const i=o,r=N.linkInfo(i);if(!r)return;const s=N.linkActions(r);for(const e of s)t.section(e.section).appendItem(e.title,e.handler,{jslogContext:e.jslogContext})}},LinkHandlerSettingUI:D,Linkifier:N});const M={removeFromIgnore:"Remove from ignore list",addToIgnore:"Add script to ignore list",showMoreFrames:"Show ignore-listed frames",showLess:"Show less",unknownSource:"unknown"},E=n.i18n.registerUIStrings("ui/legacy/components/utils/JSPresentationUtils.ts",M),W=n.i18n.getLocalizedString.bind(void 0,E);function B(e,t){const n=new a.ContextMenu.ContextMenu(t);t.consume(!0);const o=N.uiLocation(e);o&&r.IgnoreListManager.IgnoreListManager.instance().canIgnoreListUISourceCode(o.uiSourceCode)&&(r.IgnoreListManager.IgnoreListManager.instance().isUserIgnoreListedURL(o.uiSourceCode.url())?n.debugSection().appendItem(W(M.removeFromIgnore),(()=>r.IgnoreListManager.IgnoreListManager.instance().unIgnoreListUISourceCode(o.uiSourceCode)),{jslogContext:"remove-from-ignore-list"}):n.debugSection().appendItem(W(M.addToIgnore),(()=>r.IgnoreListManager.IgnoreListManager.instance().ignoreListUISourceCode(o.uiSourceCode)),{jslogContext:"add-to-ignore-list"})),n.appendApplicableItems(t),n.show()}function j(t,n,o,r,c,l){const d=[];if(c){const t=new e.Throttler.Throttler(100);o.addEventListener("liveLocationUpdated",(()=>{t.schedule((async()=>c(d)))}))}function u(e,t=void 0){let c=null;t&&(c={asyncDescription:a.UIUtils.asyncStackTraceLabel(e.description,t)},d.push(c));let u=!1;for(const t of e.callFrames){const e=a.UIUtils.beautifyFunctionName(t.functionName),c=o.maybeLinkifyConsoleCallFrame(n,t,{showColumnNumber:l,tabStop:Boolean(r),inlineFrameIndex:0,revealBreakpoint:u});c&&(c.setAttribute("jslog",`${s.link("stack-trace").track({click:!0})}`),c.addEventListener("contextmenu",B.bind(null,c)),c.textContent||(c.textContent=W(M.unknownSource))),d.push({functionName:e,link:c}),u=[i.DebuggerModel.COND_BREAKPOINT_SOURCE_URL,i.DebuggerModel.LOGPOINT_SOURCE_URL].includes(t.url)}}u(t);let p=t.callFrames;for(let e=t.parent;e;e=e.parent)e.callFrames.length&&u(e,p),p=e.callFrames;return d}function H(e,t,n){e.removeChildren();const o=[];let i=null;for(const t of n){i&&!("asyncDescription"in t)||(i=e.createChild("tbody"));const n=i.createChild("tr");"asyncDescription"in t?(n.createChild("td").textContent="\n",n.createChild("td","stack-preview-async-description").textContent=t.asyncDescription,n.createChild("td"),n.createChild("td"),n.classList.add("stack-preview-async-row")):(n.createChild("td").textContent="\n",n.createChild("td","function-name").textContent=t.functionName,n.createChild("td").textContent=" @ ",t.link&&(n.createChild("td","link").appendChild(t.link),o.push(t.link)))}i=e.createChild("tfoot");const r=i.createChild("tr","show-all-link");r.createChild("td");const s=r.createChild("td");s.colSpan=4;const c=s.createChild("span","link");c.createChild("span","css-inserted-text").setAttribute("data-inserted-text",W(M.showMoreFrames)),c.addEventListener("click",(()=>{e.classList.add("show-hidden-rows"),t.classList.add("show-hidden-rows"),a.GlassPane.GlassPane.containerMoved(e)}),!1);const l=i.createChild("tr","show-less-link");l.createChild("td");const d=l.createChild("td");d.colSpan=4;const u=d.createChild("span","link");return u.createChild("span","css-inserted-text").setAttribute("data-inserted-text",W(M.showLess)),u.addEventListener("click",(()=>{e.classList.remove("show-hidden-rows"),t.classList.remove("show-hidden-rows"),a.GlassPane.GlassPane.containerMoved(e)}),!1),o}var A=Object.freeze({__proto__:null,buildStackTracePreviewContents:function(e,t,n={widthConstrained:!1,stackTrace:void 0,tabStops:void 0}){const{stackTrace:o,tabStops:i}=n,r=document.createElement("span");r.classList.add("monospace"),r.classList.add("stack-preview-container"),r.classList.toggle("width-constrained",n.widthConstrained),r.style.display="inline-block";const s=a.UIUtils.createShadowRootWithCoreStyles(r,{cssFile:C}).createChild("table","stack-preview-container");s.classList.toggle("width-constrained",n.widthConstrained);const c=H.bind(null,s,r);return{element:r,links:H(s,r,j(o??{callFrames:[]},e,t,i,c,n.showColumnNumber))}},buildStackTraceRows:j});var P=Object.freeze({__proto__:null,reload:function(){a.DockController.DockController.instance().canDock()&&"undocked"===a.DockController.DockController.instance().dockSide()&&t.InspectorFrontendHost.InspectorFrontendHostInstance.setIsDocked(!0,(function(){})),t.InspectorFrontendHost.InspectorFrontendHostInstance.reattach((()=>window.location.reload()))}});const _={websocketDisconnected:"WebSocket disconnected",websocketDisconnectedUnregisteredDevice:"The corresponding app for this DevTools session cannot be found. Please relaunch DevTools from the terminal.",websocketDisconnectedConnectionLost:"Connection lost to corresponding device.",websocketDisconnectedNewDebuggerOpened:"Disconnected due to opening a second DevTools window for the same app."},O=n.i18n.registerUIStrings("ui/legacy/components/utils/TargetDetachedDialog.ts",_),z=n.i18n.getLocalizedString.bind(void 0,O);class $ extends i.SDKModel.SDKModel{static hideCrashedDialog;constructor(e){super(e),e.registerInspectorDispatcher(this),e.inspectorAgent().invoke_enable(),e.parentTarget()?.type()===i.Target.Type.BROWSER&&$.hideCrashedDialog&&($.hideCrashedDialog.call(null),$.hideCrashedDialog=null)}detached({reason:e}){a.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(e)}static getCustomUiReason(e){return e?"1011"===e.code&&e.reason?.includes("[UNREGISTERED_DEVICE]")?z(_.websocketDisconnectedUnregisteredDevice):"1000"===e.code&&e.reason?.includes("[CONNECTION_LOST]")?z(_.websocketDisconnectedConnectionLost):"1000"===e.code&&e.reason?.includes("[NEW_DEBUGGER_OPENED]")?z(_.websocketDisconnectedNewDebuggerOpened):null:null}static connectionLost(e){const t=$.getCustomUiReason(e)||z(_.websocketDisconnected);a.RemoteDebuggingTerminatedScreen.RemoteDebuggingTerminatedScreen.show(t,e)}targetCrashed(){if($.hideCrashedDialog)return;const e=this.target().parentTarget();if(e&&e.type()!==i.Target.Type.BROWSER)return;const t=new a.Dialog.Dialog("target-crashed");t.setSizeBehavior("MeasureContent"),t.addCloseButton(),t.setDimmed(!0),$.hideCrashedDialog=t.hide.bind(t),new a.TargetCrashedScreen.TargetCrashedScreen((()=>{$.hideCrashedDialog=null})).show(t.contentElement),t.show()}targetReloadedAfterCrash(){this.target().runtimeAgent().invoke_runIfWaitingForDebugger(),$.hideCrashedDialog&&($.hideCrashedDialog.call(null),$.hideCrashedDialog=null)}}i.SDKModel.SDKModel.register($,{capabilities:2048,autostart:!0});var G=Object.freeze({__proto__:null,TargetDetachedDialog:$});export{k as ImagePreview,A as JSPresentationUtils,F as Linkifier,P as Reload,G as TargetDetachedDialog}; | |||
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium library
Summary:
Merge up to where
0.81-stableforked from main, determined by runninggit merge-base main 0.81-stableon the upstream React Native repoTest Plan:
CI should pass. Local pass of affected areas
Notes
1c51d66
RCTMaxCachableImageCountmaybe?