UNPKG

@react-native/debugger-frontend

Version:
8 lines (7 loc) 49.6 kB
import*as e from"../../../../core/common/common.js";import*as t from"../../../../core/i18n/i18n.js";import*as n from"../../../components/icon_button/icon_button.js";import*as i from"../../legacy.js";import*as o from"../../../../core/host/host.js";import*as s from"../../../../core/platform/platform.js";import*as r from"../../../../core/sdk/sdk.js";import*as a from"../../../../models/text_utils/text_utils.js";import*as l from"../../../components/text_editor/text_editor.js";import*as c from"../../../visual_logging/visual_logging.js";import*as p from"../../../../models/formatter/formatter.js";import*as d from"../../../../models/source_map_scopes/source_map_scopes.js";import*as h from"../../../../third_party/acorn/acorn.js";import*as u from"../utils/utils.js";var m={cssText:`.custom-expandable-section{display:inline-flex;flex-direction:column}.custom-expand-icon{user-select:none;margin-right:4px;margin-bottom:-4px}.custom-expandable-section-standard-section{display:inline-flex}.custom-expandable-section-default-body{padding-left:12px}\n/*# sourceURL=${import.meta.resolve("./customPreviewComponent.css")} */\n`};const b={emptyD:"empty × {PH1}",empty:"empty",thePropertyIsComputedWithAGetter:"The property is computed with a getter"},v=t.i18n.registerUIStrings("ui/legacy/components/object_ui/RemoteObjectPreviewFormatter.ts",b),y=t.i18n.getLocalizedString.bind(void 0,v);class g{static objectPropertyComparator(e,t){return n(e)-n(t);function n(e){return"[[PromiseState]]"===e.name?1:"[[PromiseResult]]"===e.name?2:"[[GeneratorState]]"===e.name||"[[PrimitiveValue]]"===e.name||"[[WeakRefTarget]]"===e.name?3:"function"===e.type||e.name.startsWith("#")?5:4}}appendObjectPreview(e,t,n){const o=t.description,s=new Set(["arraybuffer","dataview","error","null","regexp","webassemblymemory","internal#entry","trustedtype"]);if("object"!==t.type||t.subtype&&s.has(t.subtype)||n)return void e.appendChild(this.renderPropertyPreview(t.type,t.subtype,void 0,o));const a="array"===t.subtype||"typedarray"===t.subtype;if(o){let n;if(a){const e=r.RemoteObject.RemoteObject.arrayLength(t),i=e>1?"("+e+")":"",s=r.RemoteObject.RemoteObject.arrayNameFromDescription(o);n="Array"===s?i:s+i}else{n="Object"===o?"":o}n.length>0&&(e.createChild("span","object-description").textContent=n+" ")}const l=e.createChild("span","object-properties-preview");if(i.UIUtils.createTextChild(l,a?"[":"{"),t.entries?this.appendEntriesPreview(l,t):a?this.appendArrayPropertiesPreview(l,t):this.appendObjectPropertiesPreview(l,t),t.overflow){const e=l.textContent&&l.textContent.length>1?", …":"…";l.createChild("span").textContent=e}i.UIUtils.createTextChild(l,a?"]":"}")}abbreviateFullQualifiedClassName(e){const t=e.split(".");for(let e=0;e<t.length-1;++e)t[e]=s.StringUtilities.trimMiddle(t[e],3);return t.join(".")}appendObjectPropertiesPreview(e,t){const n=t.properties.filter((e=>"accessor"!==e.type)).sort(g.objectPropertyComparator);for(let o=0;o<n.length;++o){o>0&&i.UIUtils.createTextChild(e,", ");const s=n[o],r=s.name;if("promise"===t.subtype&&"[[PromiseState]]"===r){e.appendChild(this.renderDisplayName("<"+s.value+">"));const t=o+1<n.length?n[o+1]:null;t&&"[[PromiseResult]]"===t.name&&("pending"!==s.value&&(i.UIUtils.createTextChild(e,": "),e.appendChild(this.renderPropertyPreviewOrAccessor([t]))),o++)}else"generator"===t.subtype&&"[[GeneratorState]]"===r?e.appendChild(this.renderDisplayName("<"+s.value+">")):"[[PrimitiveValue]]"===r?e.appendChild(this.renderPropertyPreviewOrAccessor([s])):"[[WeakRefTarget]]"===r?"undefined"===s.type?e.appendChild(this.renderDisplayName("<cleared>")):e.appendChild(this.renderPropertyPreviewOrAccessor([s])):(e.appendChild(this.renderDisplayName(r)),i.UIUtils.createTextChild(e,": "),e.appendChild(this.renderPropertyPreviewOrAccessor([s])))}}appendArrayPropertiesPreview(e,t){const n=r.RemoteObject.RemoteObject.arrayLength(t),o=t.properties.filter((e=>-1!==a(e.name))).sort((function(e,t){return a(e.name)-a(t.name)})),s=t.properties.filter((e=>-1===a(e.name))).sort(g.objectPropertyComparator);function a(e){const t=Number(e)>>>0;return String(t)===e&&t<n?t:-1}const l=!t.overflow;let c=-1,p=!1;for(let t=0;t<o.length;++t){p&&i.UIUtils.createTextChild(e,", ");const n=o[t],s=a(n.name);l&&s-c>1&&(d(s),i.UIUtils.createTextChild(e,", ")),l||t===s||(e.appendChild(this.renderDisplayName(n.name)),i.UIUtils.createTextChild(e,": ")),e.appendChild(this.renderPropertyPreviewOrAccessor([n])),c=s,p=!0}l&&n-c>1&&(p&&i.UIUtils.createTextChild(e,", "),d(n));for(let t=0;t<s.length;++t){p&&i.UIUtils.createTextChild(e,", ");const n=s[t];e.appendChild(this.renderDisplayName(n.name)),i.UIUtils.createTextChild(e,": "),e.appendChild(this.renderPropertyPreviewOrAccessor([n])),p=!0}function d(t){const n=e.createChild("span","object-value-undefined"),i=t-c-1;n.textContent=1!==i?y(b.emptyD,{PH1:i}):y(b.empty),p=!0}}appendEntriesPreview(e,t){if(t.entries)for(let n=0;n<t.entries.length;++n){n>0&&i.UIUtils.createTextChild(e,", ");const o=t.entries[n];o.key&&(this.appendObjectPreview(e,o.key,!0),i.UIUtils.createTextChild(e," => ")),this.appendObjectPreview(e,o.value,!0)}}renderDisplayName(e){const t=document.createElement("span");t.classList.add("name");const n=/^\s|\s$|^$|\n/.test(e);return t.textContent=n?'"'+e.replace(/\n/g,"↵")+'"':e,t}renderPropertyPreviewOrAccessor(e){const t=e[e.length-1];if(!t)throw new Error("Could not find property");return this.renderPropertyPreview(t.type,t.subtype,t.name,t.value)}renderPropertyPreview(e,t,n,o){const r=document.createElement("span");if(r.classList.add("object-value-"+(t||e)),o=o||"","accessor"===e)return r.textContent="(...)",i.Tooltip.Tooltip.install(r,y(b.thePropertyIsComputedWithAGetter)),r;if("function"===e)return r.textContent="ƒ",r;if("object"===e&&"trustedtype"===t&&n)return f(r,o,n),r;if("object"===e&&"node"===t&&o)return x(r,o),r;if("string"===e)return i.UIUtils.createTextChildren(r,s.StringUtilities.formatAsJSLiteral(o)),r;if("object"===e&&!t){let e=this.abbreviateFullQualifiedClassName(o);return"Object"===e&&(e="{…}"),r.textContent=e,i.Tooltip.Tooltip.install(r,o),r}return r.textContent=o,r}}const x=function(e,t){const n=t.match(/([^#.]+)(#[^.]+)?(\..*)?/);n&&(e.createChild("span","webkit-html-tag-name").textContent=n[1],n[2]&&(e.createChild("span","webkit-html-attribute-value").textContent=n[2]),n[3]&&(e.createChild("span","webkit-html-attribute-name").textContent=n[3]))},f=function(e,t,n){i.UIUtils.createTextChildren(e,`${n} `);const o=document.createElement("span");o.classList.add("object-value-string"),i.UIUtils.createTextChildren(o,'"',t.replace(/\n/g,"↵"),'"'),e.appendChild(o)};var w=Object.freeze({__proto__:null,RemoteObjectPreviewFormatter:g,createSpanForTrustedType:f,createSpansForNodeTitle:x});class C{static wrapObjectLiteral(e){const t=/^\s*\{\s*(.*)\s*\}[\s;]*$/.exec(e);if(null===t)return e;const[,n]=t;let i=0;for(const t of n)if("{"===t)i++;else if("}"===t&&--i<0)return e;const o=e=>{h.parse(e,{ecmaVersion:2022,allowAwaitOutsideFunction:!0,ranges:!1,allowReturnOutsideFunction:!0})};try{o("return {"+n+"};");const e="({"+n+"})";return o(e),e}catch{return e}}static async evaluateAndBuildPreview(e,t,n,o,s,a,l=!1,c=!1){const h=i.Context.Context.instance().flavor(r.RuntimeModel.ExecutionContext),u=e.length>j;if(!e||!h||t&&u)return{preview:document.createDocumentFragment(),result:null};let m=e;const b=h.debuggerModel.selectedCallFrame();if(b?.script.isJavaScript()){const e=await d.NamesResolver.allVariablesInCallFrame(b);try{m=await p.FormatterWorkerPool.formatterWorkerPool().javaScriptSubstitute(m,e)}catch{}}m=C.wrapObjectLiteral(m);const v={expression:m,generatePreview:!0,includeCommandLineAPI:!0,throwOnSideEffect:t,timeout:o,objectGroup:a,disableBreaks:!0,replMode:n,silent:c},y=await h.evaluate(v,!1,l);return{preview:C.buildEvaluationPreview(y,s),result:y}}static buildEvaluationPreview(e,t){const n=document.createDocumentFragment();if("error"in e)return n;if(e.exceptionDetails?.exception?.description){const i=e.exceptionDetails.exception.description;return(i.startsWith("TypeError: ")||t)&&(n.createChild("span").textContent=e.exceptionDetails.text+" "+i),n}const i=new g,{preview:o,type:r,subtype:a,className:l,description:c}=e.object;if(o&&"object"===r&&"node"!==a&&"trustedtype"!==a)i.appendObjectPreview(n,o,!1);else{const e=i.renderPropertyPreview(r,a,l,s.StringUtilities.trimEndWithMaxLength(c||"",400));n.appendChild(e)}return n}}const j=2e3;var E=Object.freeze({__proto__:null,JavaScriptREPL:C}),P={cssText:`.object-properties-section-dimmed{opacity:60%}.object-properties-section{padding:0;color:var(--sys-color-on-surface);display:flex;flex-direction:column}.object-properties-section li{user-select:text;&::before{margin-right:2px}}.object-properties-section li.editing-sub-part{padding:3px 12px 8px 6px;margin:-1px -6px -8px;text-overflow:clip}.object-properties-section li.editing{margin-left:10px;text-overflow:clip}.tree-outline ol.title-less-mode{padding-left:0}.object-properties-section .own-property{font-weight:bold}.object-properties-section .synthetic-property{color:var(--sys-color-token-subtle)}.object-properties-section .private-property-hash{color:var(--sys-color-on-surface)}.object-properties-section-root-element{display:flex;flex-direction:row}.object-properties-section .editable-div{overflow:hidden}.name-and-value{overflow:hidden;line-height:16px;display:flex;white-space:nowrap}.name-and-value .separator{white-space:pre;flex-shrink:0}.editing-sub-part .name-and-value{overflow:visible;display:inline-flex}.property-prompt{margin-left:4px}.tree-outline.hide-selection-when-blurred .selected:focus-visible{background:none}.tree-outline.hide-selection-when-blurred .selected:focus-visible ::slotted(*),\n.tree-outline.hide-selection-when-blurred .selected:focus-visible .tree-element-title,\n.tree-outline.hide-selection-when-blurred .selected:focus-visible .name-and-value,\n.tree-outline.hide-selection-when-blurred .selected:focus-visible .gray-info-message{background:var(--sys-color-state-focus-highlight);border-radius:2px}@media (forced-colors: active){.object-properties-section-dimmed{opacity:100%}.tree-outline.hide-selection-when-blurred .selected:focus-visible{background:Highlight}.tree-outline li:hover .tree-element-title,\n .tree-outline li.selected .tree-element-title{color:ButtonText}.tree-outline.hide-selection-when-blurred .selected:focus-visible .tree-element-title,\n .tree-outline.hide-selection-when-blurred .selected:focus-visible .name-and-value{background:transparent;box-shadow:none}.tree-outline.hide-selection-when-blurred .selected:focus-visible span,\n .tree-outline.hide-selection-when-blurred .selected:focus-visible .gray-info-message{color:HighlightText}.tree-outline-disclosure:hover li.parent::before{background-color:ButtonText}}\n/*# sourceURL=${import.meta.resolve("./objectPropertiesSection.css")} */\n`},T={cssText:`.value.object-value-node:hover{background-color:var(--sys-color-state-hover-on-subtle)}.object-value-function-prefix,\n.object-value-boolean{color:var(--sys-color-token-attribute-value)}.object-value-function{font-style:italic}.object-value-function.linkified:hover{--override-linkified-hover-background:rgb(0 0 0/10%);background-color:var(--override-linkified-hover-background);cursor:pointer}.theme-with-dark-background .object-value-function.linkified:hover,\n:host-context(.theme-with-dark-background) .object-value-function.linkified:hover{--override-linkified-hover-background:rgb(230 230 230/10%)}.object-value-number{color:var(--sys-color-token-attribute-value)}.object-value-bigint{color:var(--sys-color-token-comment)}.object-value-string,\n.object-value-regexp,\n.object-value-symbol{white-space:pre;unicode-bidi:-webkit-isolate;color:var(--sys-color-token-property-special)}.object-value-node{position:relative;vertical-align:baseline;color:var(--sys-color-token-variable);white-space:nowrap}.object-value-null,\n.object-value-undefined{color:var(--sys-color-state-disabled)}.object-value-unavailable{color:var(--sys-color-token-tag)}.object-value-calculate-value-button:hover{text-decoration:underline}.object-properties-section-custom-section{display:inline-flex;flex-direction:column}.theme-with-dark-background .object-value-number,\n:host-context(.theme-with-dark-background) .object-value-number,\n.theme-with-dark-background .object-value-boolean,\n:host-context(.theme-with-dark-background) .object-value-boolean{--override-primitive-dark-mode-color:hsl(252deg 100% 75%);color:var(--override-primitive-dark-mode-color)}.object-properties-section .object-description{color:var(--sys-color-token-subtle)}.value .object-properties-preview{white-space:nowrap}.name{color:var(--sys-color-token-tag);flex-shrink:0}.object-properties-preview .name{color:var(--sys-color-token-subtle)}@media (forced-colors: active){.object-value-calculate-value-button:hover{forced-color-adjust:none;color:Highlight}}\n/*# sourceURL=${import.meta.resolve("./objectValue.css")} */\n`};const O={exceptionS:"[Exception: {PH1}]",unknown:"unknown",expandRecursively:"Expand recursively",collapseChildren:"Collapse children",noProperties:"No properties",dots:"(...)",invokePropertyGetter:"Invoke property getter",showAllD:"Show all {PH1}",valueUnavailable:"<value unavailable>",valueNotAccessibleToTheDebugger:"Value is not accessible to the debugger",copyValue:"Copy value",copyPropertyPath:"Copy property path",stringIsTooLargeToEdit:"<string is too large to edit>",showMoreS:"Show more ({PH1})",longTextWasTruncatedS:"long text was truncated ({PH1})",copy:"Copy",openInMemoryInpector:"Open in Memory inspector panel"},I=t.i18n.registerUIStrings("ui/legacy/components/object_ui/ObjectPropertiesSection.ts",O),S=t.i18n.getLocalizedString.bind(void 0,I),k=new WeakMap,L=new WeakMap;class M extends i.TreeOutline.TreeOutlineInShadow{object;editable;objectTreeElementInternal;titleElement;skipProtoInternal;constructor(e,t,n,i){super(),this.object=e,this.editable=!0,i||this.hideOverflow(),this.setFocusable(!0),this.setShowSelectionOnKeyboardFocus(!0),this.objectTreeElementInternal=new U(e,n),this.appendChild(this.objectTreeElementInternal),"string"!=typeof t&&t?(this.titleElement=t,this.element.appendChild(t)):(this.titleElement=this.element.createChild("span"),this.titleElement.textContent=t||""),this.titleElement instanceof HTMLElement&&!this.titleElement.hasAttribute("tabIndex")&&(this.titleElement.tabIndex=-1),L.set(this.element,this),this.registerRequiredCSS(T,P),this.rootElement().childrenListElement.classList.add("source-code","object-properties-section")}static defaultObjectPresentation(e,t,n,i){const o=M.defaultObjectPropertiesSection(e,t,n,i);return e.hasChildren?o.element:o.titleElement}static defaultObjectPropertiesSection(e,t,n,o){const s=document.createElement("span");s.classList.add("source-code");const r=i.UIUtils.createShadowRootWithCoreStyles(s,{cssFile:T}),a=M.createPropertyValue(e,!1,!0);r.appendChild(a.element);const l=new M(e,s,t);return l.editable=!1,n&&l.skipProto(),o&&l.setEditable(!1),l}static compareProperties(e,t){if(!e.synthetic&&t.synthetic)return 1;if(!t.synthetic&&e.synthetic)return-1;if(!e.isOwn&&t.isOwn)return 1;if(!t.isOwn&&e.isOwn)return-1;if(!e.enumerable&&t.enumerable)return 1;if(!t.enumerable&&e.enumerable)return-1;if(e.symbol&&!t.symbol)return 1;if(t.symbol&&!e.symbol)return-1;if(e.private&&!t.private)return 1;if(t.private&&!e.private)return-1;const n=e.name,i=t.name;return n.startsWith("_")&&!i.startsWith("_")?1:i.startsWith("_")&&!n.startsWith("_")?-1:s.StringUtilities.naturalOrderComparator(n,i)}static createNameElement(e,t){return null===e?i.Fragment.html`<span class="name"></span>`:/^\s|\s$|^$|\n/.test(e)?i.Fragment.html`<span class="name">"${e.replace(/\n/g,"↵")}"</span>`:t?i.Fragment.html`<span class="name"> <span class="private-property-hash">${e[0]}</span>${e.substring(1)} </span>`:i.Fragment.html`<span class="name">${e}</span>`}static valueElementForFunctionDescription(e,t,n){const o=document.createElement("span");o.classList.add("object-value-function");const r=(e=e||"").replace(/^function [gs]et /,"function ").replace(/^function [gs]et\(/,"function(").replace(/^[gs]et /,"");n=n||"";const a=r.match(/^(async\s+function)/),l=r.startsWith("function*"),c=r.startsWith("*"),p=!l&&r.startsWith("function"),d=r.startsWith("class ")||r.startsWith("class{"),h=r.indexOf("=>"),u=!a&&!l&&!p&&!d&&h>0;let m;if(d){m=r.substring(5);const e=/^[^{\s]+/.exec(m.trim());let t=n;e&&(t=e[0].trim()||n),v("class",m,t)}else if(a)m=r.substring(a[1].length),v("async ƒ",m,b(m));else if(l)m=r.substring(9),v("ƒ*",m,b(m));else if(c)m=r.substring(1),v("ƒ*",m,b(m));else if(p)m=r.substring(8),v("ƒ",m,b(m));else if(u){const e=60;let t=r;n?t=n+"()":r.length>e&&(t=r.substring(0,h+2)+" {…}"),v("",r,t)}else v("ƒ",r,b(r));return i.Tooltip.Tooltip.install(o,s.StringUtilities.trimEndWithMaxLength(e,500)),o;function b(e){const t=e.indexOf("("),i=e.match(/\)\s*{/);if(-1!==t&&void 0!==i?.index&&i.index>t){return(e.substring(0,t).trim()||n)+e.substring(t,i.index+1)}return n+"()"}function v(e,n,r){e.length&&(o.createChild("span","object-value-function-prefix").textContent=e+" "),t?i.UIUtils.createTextChild(o,s.StringUtilities.trimEndWithMaxLength(n.trim(),200)):i.UIUtils.createTextChild(o,r.replace(/\n/g," "))}}static createPropertyValueWithCustomSupport(e,t,n,i,o,s,r){if(e.customPreview()){const t=new X(e).element;return t.classList.add("object-properties-section-custom-section"),new $(t)}return M.createPropertyValue(e,t,n,i,o,s,r)}static appendMemoryIcon(t,o,s){if(!o.isLinearMemoryInspectable())return;const a=new n.Icon.Icon;a.data={iconName:"memory",color:"var(--icon-default)",width:"16px",height:"13px"},a.addEventListener("click",(t=>{t.consume(),e.Revealer.reveal(new r.RemoteObject.LinearMemoryInspectable(o,s))})),a.setAttribute("jslog",`${c.action("open-memory-inspector").track({click:!0})}`);const l=S(O.openInMemoryInpector);i.Tooltip.Tooltip.install(a,l),i.ARIAUtils.setLabel(a,l),a.style.setProperty("vertical-align","sub"),a.style.setProperty("cursor","pointer"),t.appendChild(a)}static createPropertyValue(n,o,a,l,c,p=!1,d){let h;const u=n.type,m=n.subtype,b=n.description||"",v=n.className;if("object"===u&&"internal#location"===m){const e=n.debuggerModel().createRawLocationByScriptId(n.value.scriptId,n.value.lineNumber,n.value.columnNumber);if(e&&c)return new $(c.linkifyRawLocation(e,s.DevToolsPath.EmptyUrlString));h=new $(function(){const e=document.createElement("span");return e.textContent="<"+S(O.unknown)+">",i.Tooltip.Tooltip.install(e,b||""),e}())}else if("string"===u&&"string"==typeof b)h=y();else if("object"===u&&"trustedtype"===m)h=function(){const e=document.createElement("span");e.classList.add("object-value-trustedtype");const t=`${v} "${b}"`;let n;if(t.length>A)n=new H(e,t,50);else{const o=y();i.UIUtils.createTextChild(e,`${v} `),e.appendChild(o.element),n=new $(e),i.Tooltip.Tooltip.install(e,t)}return n}();else if("function"===u)h=new $(M.valueElementForFunctionDescription(b));else if("object"===u&&"node"===m&&b)h=new $(function(){const t=document.createElement("span");return t.classList.add("object-value-node"),x(t,b),t.addEventListener("click",(t=>{e.Revealer.reveal(n),t.consume(!0)}),!1),t.addEventListener("mousemove",(()=>r.OverlayModel.OverlayModel.highlightObjectAsDOMNode(n)),!1),t.addEventListener("mouseleave",(()=>r.OverlayModel.OverlayModel.hideDOMNodeHighlight()),!1),t}());else{const e=document.createElement("span");if(e.classList.add("object-value-"+(m||u)),n.preview&&a){(new g).appendObjectPreview(e,n.preview,!1),h=new $(e),i.Tooltip.Tooltip.install(h.element,b||"")}else b.length>A?h=new H(e,b,50):(h=new $(e),h.element.textContent=b,i.Tooltip.Tooltip.install(h.element,b));p||this.appendMemoryIcon(e,n,d)}if(o){const e=document.createElement("span");e.classList.add("error"),e.classList.add("value"),e.appendChild(t.i18n.getFormatLocalizedString(I,O.exceptionS,{PH1:h.element})),h.element=e}return h.element.classList.add("value"),h;function y(){const e=document.createElement("span");e.classList.add("object-value-string");const t=JSON.stringify(b);let n;return b.length>A?n=new H(e,t,50):(i.UIUtils.createTextChild(e,t),n=new $(e),i.Tooltip.Tooltip.install(e,b)),n}}static formatObjectAsFunction(t,n,i,o){return t.debuggerModel().functionDetailsPromise(t).then((function(s){i&&s?.location&&(n.classList.add("linkified"),n.addEventListener("click",(()=>(e.Revealer.reveal(s.location),!1))));let r=o?"":"anonymous";s?.functionName&&(r=s.functionName);const a=M.valueElementForFunctionDescription(t.description,o,r);n.appendChild(a)}))}static isDisplayableProperty(e,t){if(!t?.synthetic)return!0;const n=e.name;return!("[[Entries]]"===t.name&&("length"===n||"__proto__"===n))}skipProto(){this.skipProtoInternal=!0}expand(){this.objectTreeElementInternal.expand()}setEditable(e){this.editable=e}objectTreeElement(){return this.objectTreeElementInternal}enableContextMenu(){this.element.addEventListener("contextmenu",this.contextMenuEventFired.bind(this),!1)}contextMenuEventFired(e){const t=new i.ContextMenu.ContextMenu(e);t.appendApplicableItems(this.object),this.object instanceof r.RemoteObject.LocalJSONObject&&(t.viewSection().appendItem(S(O.expandRecursively),this.objectTreeElementInternal.expandRecursively.bind(this.objectTreeElementInternal,100),{jslogContext:"expand-recursively"}),t.viewSection().appendItem(S(O.collapseChildren),this.objectTreeElementInternal.collapseChildren.bind(this.objectTreeElementInternal),{jslogContext:"collapse-children"})),t.show()}titleLessMode(){this.objectTreeElementInternal.listItemElement.classList.add("hidden"),this.objectTreeElementInternal.childrenListElement.classList.add("title-less-mode"),this.objectTreeElementInternal.expand()}}const A=1e4;class R extends i.TreeOutline.TreeOutlineInShadow{editable;constructor(e){super(),this.registerRequiredCSS(T,P),this.editable=!e?.readOnly,this.contentElement.classList.add("source-code"),this.contentElement.classList.add("object-properties-section")}}class U extends i.TreeOutline.TreeElement{object;linkifier;emptyPlaceholder;propertiesMode;extraProperties;targetObject;toggleOnClick;constructor(e,t,n,i=1,o=[],s=e){super(document.createElement("slot")),this.object=e,this.linkifier=t,this.emptyPlaceholder=n,this.propertiesMode=i,this.extraProperties=o,this.targetObject=s,this.setExpandable(!0),this.selectable=!0,this.toggleOnClick=!0,this.listItemElement.classList.add("object-properties-section-root-element"),this.listItemElement.addEventListener("contextmenu",this.onContextMenu.bind(this),!1)}onexpand(){this.treeOutline&&this.treeOutline.element.classList.add("expanded")}oncollapse(){this.treeOutline&&this.treeOutline.element.classList.remove("expanded")}ondblclick(e){return!0}onContextMenu(e){const t=new i.ContextMenu.ContextMenu(e);if(t.appendApplicableItems(this.object),this.object instanceof r.RemoteObject.LocalJSONObject){const{value:e}=this.object,n="object"==typeof e?JSON.stringify(e,null,2):e,i=()=>{o.userMetrics.actionTaken(o.UserMetrics.Action.NetworkPanelCopyValue),o.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(n)};t.clipboardSection().appendItem(S(O.copyValue),i,{jslogContext:"copy-value"})}t.viewSection().appendItem(S(O.expandRecursively),this.expandRecursively.bind(this,100),{jslogContext:"expand-recursively"}),t.viewSection().appendItem(S(O.collapseChildren),this.collapseChildren.bind(this),{jslogContext:"collapse-children"}),t.show()}async onpopulate(){const e=this.treeOutline,t=!!e&&Boolean(e.skipProtoInternal);return await N.populate(this,this.object,t,!1,this.linkifier,this.emptyPlaceholder,this.propertiesMode,this.extraProperties,this.targetObject)}}class N extends i.TreeOutline.TreeElement{property;toggleOnClick;highlightChanges;linkifier;maxNumPropertiesToShow;nameElement;valueElement;rowContainer;readOnly;prompt;editableDiv;propertyValue;expandedValueElement;constructor(e,t){super(),this.property=e,this.toggleOnClick=!0,this.highlightChanges=[],this.linkifier=t,this.maxNumPropertiesToShow=200,this.listItemElement.addEventListener("contextmenu",this.contextMenuFired.bind(this),!1),this.listItemElement.dataset.objectPropertyNameForTest=e.name,this.setExpandRecursively("[[Prototype]]"!==e.name)}static async populate(e,t,n,i,o,s,a=1,l,c){if(t.arrayLength()>100)return e.removeChildren(),void F.populateArray(e,t,0,t.arrayLength()-1,o);let p,d=null;switch(a){case 0:({properties:p}=await t.getAllProperties(!1,!0));break;case 1:({properties:p,internalProperties:d}=await r.RemoteObject.RemoteObject.loadFromObjectPerProto(t,!0))}e.removeChildren(),p&&(void 0!==l&&p.push(...l),N.populateWithProperties(e,p,d,n,i,c||t,o,s))}static populateWithProperties(e,t,n,i,o,s,a,l){t.sort(M.compareProperties);const c=(n=n||[]).find((e=>"[[Entries]]"===e.name));if(c){k.set(c,s);const t=new N(c,a);t.setExpandable(!0),t.expand(),e.appendChild(t)}const p=[];for(let n=0;n<t.length;++n){const i=t[n];if(k.set(i,s),!M.isDisplayableProperty(i,e.property))continue;if(i.isOwn&&!o){if(i.getter){const e=new r.RemoteObject.RemoteObjectProperty("get "+i.name,i.getter,!1);k.set(e,s),p.push(e)}if(i.setter){const e=new r.RemoteObject.RemoteObjectProperty("set "+i.name,i.setter,!1);k.set(e,s),p.push(e)}}if(i.getter||!i.isAccessorProperty()){const t=new N(i,a);"memories"===i.name&&"Memories"===i.value?.className&&(t.updateExpandable(),t.isExpandable()&&t.expand()),e.appendChild(t)}}for(let t=0;t<p.length;++t)e.appendChild(new N(p[t],a));for(const t of n){k.set(t,s);const n=new N(t,a);"[[Entries]]"!==t.name&&("[[Prototype]]"===t.name&&i||e.appendChild(n))}N.appendEmptyPlaceholderIfNeeded(e,l)}static appendEmptyPlaceholderIfNeeded(e,t){if(e.childCount())return;const n=document.createElement("div");n.classList.add("gray-info-message"),n.textContent=t||S(O.noProperties);const o=new i.TreeOutline.TreeElement(n);e.appendChild(o)}static createRemoteObjectAccessorPropertySpan(e,t,n){const o=document.createElement("span"),s=o.createChild("span");if(s.textContent=S(O.dots),!e)return o;function r(e){let t=this;const n=JSON.parse(e);for(let e=0,i=n.length;e<i;++e)t=t[n[e]];return t}return s.classList.add("object-value-calculate-value-button"),i.Tooltip.Tooltip.install(s,S(O.invokePropertyGetter)),s.addEventListener("click",(function(i){i.consume(),e&&e.callFunction(r,[{value:JSON.stringify(t)}]).then(n)}),!1),o}setSearchRegex(e,t){let n=i.UIUtils.highlightedSearchResultClassName;if(t&&(n+=" "+t),this.revertHighlightChanges(),this.applySearch(e,this.nameElement,n),this.property.value){"object"!==this.property.value.type&&this.applySearch(e,this.valueElement,n)}return Boolean(this.highlightChanges.length)}applySearch(e,t,n){const o=[],s=t.textContent||"";e.lastIndex=0;let r=e.exec(s);for(;r;)o.push(new a.TextRange.SourceRange(r.index,r[0].length)),r=e.exec(s);o.length&&i.UIUtils.highlightRangesWithStyleClass(t,o,n,this.highlightChanges)}showAllPropertiesElementSelected(e){return this.removeChild(e),this.children().forEach((e=>{e.hidden=!1})),!1}createShowAllPropertiesButton(){const e=document.createElement("div");e.classList.add("object-value-calculate-value-button"),e.textContent=S(O.dots),i.Tooltip.Tooltip.install(e,S(O.showAllD,{PH1:this.childCount()}));const t=this.children();for(let e=this.maxNumPropertiesToShow;e<this.childCount();++e)t[e].hidden=!0;const n=new i.TreeOutline.TreeElement(e);n.onselect=this.showAllPropertiesElementSelected.bind(this,n),this.appendChild(n)}revertHighlightChanges(){i.UIUtils.revertDomChanges(this.highlightChanges),this.highlightChanges=[]}async onpopulate(){const e=this.property.value;console.assert(void 0!==e);const t=this.treeOutline,n=!!t&&Boolean(t.skipProtoInternal),i="[[Prototype]]"!==this.property.name?e:k.get(this.property);i&&(await N.populate(this,e,n,!1,this.linkifier,void 0,void 0,void 0,i),this.childCount()>this.maxNumPropertiesToShow&&this.createShowAllPropertiesButton())}ondblclick(e){const t=e.target,n=t.isSelfOrDescendant(this.valueElement)||this.expandedValueElement&&t.isSelfOrDescendant(this.expandedValueElement);return this.property.value&&!this.property.value.customPreview()&&n&&(this.property.writable||this.property.setter)&&this.startEditing(),!1}onenter(){return!(!this.property.value||this.property.value.customPreview()||!this.property.writable&&!this.property.setter)&&(this.startEditing(),!0)}onattach(){this.update(),this.updateExpandable()}onexpand(){this.showExpandedValueElement(!0)}oncollapse(){this.showExpandedValueElement(!1)}showExpandedValueElement(e){this.expandedValueElement&&(e?this.rowContainer.replaceChild(this.expandedValueElement,this.valueElement):this.rowContainer.replaceChild(this.valueElement,this.expandedValueElement))}createExpandedValueElement(e,t){if(!(e.hasChildren&&!e.customPreview()&&"node"!==e.subtype&&"function"!==e.type&&("object"!==e.type||e.preview)))return null;const n=document.createElement("span");return n.classList.add("value"),"Object"===e.description?n.textContent="":n.setTextContentTruncatedIfNeeded(e.description||""),n.classList.add("object-value-"+(e.subtype||e.type)),i.Tooltip.Tooltip.install(n,e.description||""),t||M.appendMemoryIcon(n,e),n}update(){this.nameElement=M.createNameElement(this.property.name,this.property.private),this.property.enumerable||this.nameElement.classList.add("object-properties-section-dimmed"),this.property.isOwn&&this.nameElement.classList.add("own-property"),this.property.synthetic&&this.nameElement.classList.add("synthetic-property"),this.updatePropertyPath();const e=this.property.synthetic&&"[[Entries]]"===this.property.name;if(e)this.valueElement=document.createElement("span"),this.valueElement.classList.add("value");else if(this.property.value){const e="[[Prototype]]"!==this.property.name;this.propertyValue=M.createPropertyValueWithCustomSupport(this.property.value,this.property.wasThrown,e,this.listItemElement,this.linkifier,this.property.synthetic,this.path()),this.valueElement=this.propertyValue.element}else if(this.property.getter){this.valueElement=document.createElement("span");const e=this.valueElement.createChild("span");e.textContent=S(O.dots),e.classList.add("object-value-calculate-value-button"),i.Tooltip.Tooltip.install(e,S(O.invokePropertyGetter));const t=k.get(this.property),n=this.property.getter;e.addEventListener("click",(e=>{e.consume();t.callFunction("\n function invokeGetter(getter) {\n return Function.prototype.apply.call(getter, this, []);\n }",[r.RemoteObject.RemoteObject.toCallArgument(n)]).then(this.onInvokeGetterClick.bind(this))}),!1)}else this.valueElement=document.createElement("span"),this.valueElement.classList.add("object-value-unavailable"),this.valueElement.textContent=S(O.valueUnavailable),i.Tooltip.Tooltip.install(this.valueElement,S(O.valueNotAccessibleToTheDebugger));const t=this.valueElement.textContent;this.property.value&&t&&!this.property.wasThrown&&(this.expandedValueElement=this.createExpandedValueElement(this.property.value,this.property.synthetic));let n;n=e?i.Fragment.html` <span class='name-and-value'>${""}${this.nameElement}</span> `:i.Fragment.html` <span class='name-and-value'>${""}${this.nameElement}<span class='separator'>: </span>${this.valueElement}</span> `,this.listItemElement.removeChildren(),this.rowContainer=n,this.listItemElement.appendChild(this.rowContainer)}updatePropertyPath(){if(this.nameElement.title)return;const e=this.property.name;if(this.property.synthetic)return void i.Tooltip.Tooltip.install(this.nameElement,e);const t=this.parent instanceof N&&this.parent.nameElement&&!this.parent.property.synthetic?this.parent.nameElement.title:"";this.property.private||/^(?:[$_\p{ID_Start}])(?:[$_\u200C\u200D\p{ID_Continue}])*$/u.test(e)?i.Tooltip.Tooltip.install(this.nameElement,t?`${t}.${e}`:e):/^(?:0|[1-9]\d*)$/.test(e)?i.Tooltip.Tooltip.install(this.nameElement,`${t}[${e}]`):i.Tooltip.Tooltip.install(this.nameElement,`${t}[${JSON.stringify(e)}]`)}contextMenuFired(e){const t=new i.ContextMenu.ContextMenu(e);if(t.appendApplicableItems(this),this.property.symbol&&t.appendApplicableItems(this.property.symbol),this.property.value&&(t.appendApplicableItems(this.property.value),k.get(this.property)instanceof r.RemoteObject.LocalJSONObject)){const{value:{value:e}}=this.property,n="object"==typeof e?JSON.stringify(e,null,2):e,i=()=>{o.userMetrics.actionTaken(o.UserMetrics.Action.NetworkPanelCopyValue),o.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(n)};t.clipboardSection().appendItem(S(O.copyValue),i,{jslogContext:"copy-value"})}if(!this.property.synthetic&&this.nameElement?.title){const e=o.InspectorFrontendHost.InspectorFrontendHostInstance.copyText.bind(o.InspectorFrontendHost.InspectorFrontendHostInstance,this.nameElement.title);t.clipboardSection().appendItem(S(O.copyPropertyPath),e,{jslogContext:"copy-property-path"})}k.get(this.property)instanceof r.RemoteObject.LocalJSONObject&&(t.viewSection().appendItem(S(O.expandRecursively),this.expandRecursively.bind(this,100),{jslogContext:"expand-recursively"}),t.viewSection().appendItem(S(O.collapseChildren),this.collapseChildren.bind(this),{jslogContext:"collapse-children"})),this.propertyValue&&this.propertyValue.appendApplicableItems(e,t,{}),t.show()}startEditing(){const e=this.treeOutline;if(this.prompt||!e||!e.editable||this.readOnly)return;if(this.editableDiv=this.rowContainer.createChild("span","editable-div"),this.property.value){let e=this.property.value.description;"string"===this.property.value.type&&"string"==typeof e&&(e=`"${e}"`),this.editableDiv.setTextContentTruncatedIfNeeded(e,S(O.stringIsTooLargeToEdit))}const t=this.editableDiv.textContent||"";this.setExpandable(!1),this.listItemElement.classList.add("editing-sub-part"),this.valueElement.classList.add("hidden"),this.prompt=new D;const n=this.prompt.attachAndStartEditing(this.editableDiv,this.editingCommitted.bind(this,t));n.classList.add("property-prompt");const i=this.listItemElement.getComponentSelection();i&&i.selectAllChildren(this.editableDiv),n.addEventListener("keydown",this.promptKeyDown.bind(this,t),!1)}editingEnded(){this.prompt&&(this.prompt.detach(),delete this.prompt),this.editableDiv.remove(),this.updateExpandable(),this.listItemElement.scrollLeft=0,this.listItemElement.classList.remove("editing-sub-part"),this.select()}editingCancelled(){this.valueElement.classList.remove("hidden"),this.editingEnded()}async editingCommitted(e){const t=this.prompt?this.prompt.text():"";t!==e?(this.editingEnded(),await this.applyExpression(t)):this.editingCancelled()}promptKeyDown(e,t){const n=t;return"Enter"===n.key?(n.consume(),void this.editingCommitted(e)):n.key===s.KeyboardUtilities.ESCAPE_KEY?(n.consume(),void this.editingCancelled()):void 0}async applyExpression(e){const t=r.RemoteObject.RemoteObject.toCallArgument(this.property.symbol||this.property.name);if(e=C.wrapObjectLiteral(e.trim()),this.property.synthetic){let t=!1;if(e&&(t=await this.property.setSyntheticValue(e)),t){const e=this.parent;e&&(e.invalidateChildren(),e.onpopulate())}else this.update();return}const n=k.get(this.property),i=e?n.setPropertyValue(t,e):n.deleteProperty(t);if(await i)this.update();else if(e){const e=this.parent;e&&(e.invalidateChildren(),e.onpopulate())}else this.parent&&this.parent.removeChild(this)}onInvokeGetterClick(e){e.object&&(this.property.value=e.object,this.property.wasThrown=e.wasThrown||!1,this.update(),this.invalidateChildren(),this.updateExpandable())}updateExpandable(){this.property.value?this.setExpandable(!this.property.value.customPreview()&&this.property.value.hasChildren&&!this.property.wasThrown):this.setExpandable(!1)}path(){return this.nameElement.title}}class F extends i.TreeOutline.TreeElement{toggleOnClick;fromIndex;toIndex;object;propertyCount;linkifier;constructor(e,t,n,i,o){super(s.StringUtilities.sprintf("[%d … %d]",t,n),!0),this.toggleOnClick=!0,this.fromIndex=t,this.toIndex=n,this.object=e,this.propertyCount=i,this.linkifier=o}static async populateArray(e,t,n,i,o){await F.populateRanges(e,t,n,i,!0,o)}static async populateRanges(e,t,n,i,o,s){const r=await t.callFunctionJSON((function(e,t,n,i){if(void 0===e||void 0===t||void 0===i||void 0===n)return;let o=null;const s=t-e>=i&&ArrayBuffer.isView(this);function*r(n){if(void 0!==e&&void 0!==t&&void 0!==i)if(t-e<i)for(let i=e;i<=t;++i)i in n&&(yield i);else{o=o||Object.getOwnPropertyNames(n);for(let n=0;n<o.length;++n){const i=o[n],s=Number(i)>>>0;String(s)===i&&e<=s&&s<=t&&(yield s)}}}let a=0;if(s)a=t-e+1;else for(const e of r(this))++a;let l=a;l=a<=n?a:Math.pow(n,Math.ceil(Math.log(a)/Math.log(n))-1);const c=[];if(s)for(let n=e;n<=t;n+=l){const e=n;let i=e+l-1;i>t&&(i=t),c.push([e,i,i-e+1])}else{a=0;let e=-1,t=0;for(const n of r(this))-1===e&&(e=n),t=n,++a===l&&(c.push([e,t,a]),a=0,e=-1);a>0&&c.push([e,t,a])}return{ranges:c}}),[{value:n},{value:i},{value:F.bucketThreshold},{value:F.sparseIterationThreshold}]);await async function(n){if(!n)return;const i=n.ranges;if(1===i.length)await F.populateAsFragment(e,t,i[0][0],i[0][1],s);else for(let n=0;n<i.length;++n){const o=i[n][0],r=i[n][1],a=i[n][2];o===r?await F.populateAsFragment(e,t,o,r,s):e.appendChild(new F(t,o,r,a,s))}o&&await F.populateNonIndexProperties(e,t,s)}(r)}static async populateAsFragment(e,t,n,i,o){const s=await t.callFunction((function(e,t,n){const i=Object.create(null);if(void 0===e||void 0===t||void 0===n)return;if(t-e<n)for(let n=e;n<=t;++n)n in this&&(i[n]=this[n]);else{const n=Object.getOwnPropertyNames(this);for(let o=0;o<n.length;++o){const s=n[o],r=Number(s)>>>0;String(r)===s&&e<=r&&r<=t&&(i[r]=this[r])}}return i}),[{value:n},{value:i},{value:F.sparseIterationThreshold}]);if(!s.object||s.wasThrown)return;const r=s.object,a=await r.getAllProperties(!1,!0);r.release();const l=a.properties;if(l){l.sort(M.compareProperties);for(let t=0;t<l.length;++t){k.set(l[t],this.object);const n=new N(l[t],o);n.readOnly=!0,e.appendChild(n)}}}static async populateNonIndexProperties(e,t,n){const{properties:i,internalProperties:o}=await r.RemoteObject.RemoteObject.loadFromObjectPerProto(t,!0,!0);i&&N.populateWithProperties(e,i,o,!1,!1,t,n)}async onpopulate(){this.propertyCount>=F.bucketThreshold?await F.populateRanges(this,this.object,this.fromIndex,this.toIndex,!1,this.linkifier):await F.populateAsFragment(this,this.object,this.fromIndex,this.toIndex,this.linkifier)}onattach(){this.listItemElement.classList.add("object-properties-section-name")}static bucketThreshold=100;static sparseIterationThreshold=25e4}class D extends i.TextPrompt.TextPrompt{constructor(){super(),this.initialize(l.JavaScript.completeInContext)}}class _{static#e=new WeakMap;static#t=new WeakMap;#n=new Set;constructor(e){e.addEventListener(i.TreeOutline.Events.ElementAttached,this.#i,this),e.addEventListener(i.TreeOutline.Events.ElementExpanded,this.#o,this),e.addEventListener(i.TreeOutline.Events.ElementCollapsed,this.#s,this)}watchSection(e,t){_.#t.set(t,e),this.#n.has(e)&&t.expand()}stopWatchSectionsWithId(e){for(const t of this.#n)t.startsWith(e+":")&&this.#n.delete(t)}#i(e){const t=e.data;t.isExpandable()&&this.#n.has(this.#r(t))&&t.expand()}#o(e){const t=e.data;this.#n.add(this.#r(t))}#s(e){const t=e.data;this.#n.delete(this.#r(t))}#r(e){const t=_.#e.get(e);if(t)return t;let n=e,i=n;if(!e.treeOutline)throw new Error("No tree outline available");const o=e.treeOutline.rootElement();let s;for(;n!==o;){let e="";e=n.property?n.property.name:"string"==typeof n.title?n.title:n.title.textContent||"",s=e+(s?"."+s:""),i=n,n.parent&&(n=n.parent)}return s=_.#t.get(i)+(s?":"+s:""),_.#e.set(e,s),s}}let V;class W{static instance(e={forceNew:!1}){const{forceNew:t}=e;return V&&!t||(V=new W),V}async render(e,t){if(!(e instanceof r.RemoteObject.RemoteObject))throw new Error("Can't render "+e);const n=(t=t||{title:void 0,editable:void 0}).title,i=new M(e,n);return n||i.titleLessMode(),i.editable=Boolean(t.editable),{node:i.element,tree:i}}}class ${element;constructor(e){this.element=e}appendApplicableItems(e,t,n){}}class H extends ${text;maxLength;expandElement;maxDisplayableTextLength;expandElementText;copyButtonText;constructor(e,n,o){super(e);const r=e.createChild("span");this.text=n,this.maxLength=o,r.textContent=n.slice(0,o),i.Tooltip.Tooltip.install(r,`${n.slice(0,o)}…`),this.expandElement=r.createChild("button"),this.maxDisplayableTextLength=1e7;const a=s.StringUtilities.countWtf8Bytes(n),l=t.ByteUtilities.bytesToString(a);this.text.length<this.maxDisplayableTextLength?(this.expandElementText=S(O.showMoreS,{PH1:l}),this.expandElement.setAttribute("data-text",this.expandElementText),this.expandElement.setAttribute("jslog",`${c.action("expand").track({click:!0})}`),this.expandElement.classList.add("expandable-inline-button"),this.expandElement.addEventListener("click",this.expandText.bind(this))):(this.expandElement.setAttribute("data-text",S(O.longTextWasTruncatedS,{PH1:l})),this.expandElement.classList.add("undisplayable-text")),this.copyButtonText=S(O.copy);const p=r.createChild("button","expandable-inline-button");p.setAttribute("data-text",this.copyButtonText),p.setAttribute("jslog",`${c.action("copy").track({click:!0})}`),p.addEventListener("click",this.copyText.bind(this))}appendApplicableItems(e,t,n){this.text.length<this.maxDisplayableTextLength&&this.expandElement&&t.clipboardSection().appendItem(this.expandElementText||"",this.expandText.bind(this),{jslogContext:"show-more"}),t.clipboardSection().appendItem(this.copyButtonText,this.copyText.bind(this),{jslogContext:"copy"})}expandText(){this.expandElement&&(this.expandElement.parentElement&&this.expandElement.parentElement.insertBefore(document.createTextNode(this.text.slice(this.maxLength)),this.expandElement),this.expandElement.remove(),this.expandElement=null)}copyText(){o.InspectorFrontendHost.InspectorFrontendHostInstance.copyText(this.text)}}var B=Object.freeze({__proto__:null,ArrayGroupingTreeElement:F,ExpandableTextPropertyValue:H,InitialVisibleChildrenLimit:200,ObjectPropertiesSection:M,ObjectPropertiesSectionsTreeExpandController:_,ObjectPropertiesSectionsTreeOutline:R,ObjectPropertyPrompt:D,ObjectPropertyTreeElement:N,ObjectPropertyValue:$,Renderer:W,RootElement:U,getObjectPropertiesSectionFrom:e=>L.get(e)});const J={showAsJavascriptObject:"Show as JavaScript object"},G=t.i18n.registerUIStrings("ui/legacy/components/object_ui/CustomPreviewComponent.ts",J),z=t.i18n.getLocalizedString.bind(void 0,G);class K{sectionElement;object;expanded;cachedContent;header;expandIcon;constructor(t){this.sectionElement=document.createElement("span"),this.sectionElement.classList.add("custom-expandable-section"),this.object=t,this.expanded=!1,this.cachedContent=null;const i=t.customPreview();if(!i)return;let o;try{o=JSON.parse(i.header)}catch(t){return void e.Console.Console.instance().error("Broken formatter: header is invalid json "+t)}this.header=this.renderJSONMLTag(o),this.header.nodeType!==Node.TEXT_NODE?(i.bodyGetterId&&(this.header instanceof Element&&this.header.classList.add("custom-expandable-section-header"),this.header.addEventListener("click",this.onClick.bind(this),!1),this.expandIcon=n.Icon.create("triangle-right","custom-expand-icon"),this.header.insertBefore(this.expandIcon,this.header.firstChild)),this.sectionElement.appendChild(this.header)):e.Console.Console.instance().error("Broken formatter: header should be an element node.")}element(){return this.sectionElement}renderJSONMLTag(e){return Array.isArray(e)?"object"===e[0]?this.layoutObjectTag(e):this.renderElement(e):document.createTextNode(String(e))}renderElement(t){const n=t.shift();if(!q.includes(n))return e.Console.Console.instance().error("Broken formatter: element "+n+" is not allowed!"),document.createElement("span");const i=document.createElement(n);if("object"==typeof t[0]&&!Array.isArray(t[0])){const e=t.shift();for(const t in e){const n=e[t];"style"===t&&"string"==typeof n&&i.setAttribute(t,n)}}return this.appendJsonMLTags(i,t),i}layoutObjectTag(e){e.shift();const t=e.shift(),n=this.object.runtimeModel().createRemoteObject(t);if(n.customPreview())return new K(n).element();const i=M.defaultObjectPresentation(n);return i.classList.toggle("custom-expandable-section-standard-section",n.hasChildren),i}appendJsonMLTags(e,t){for(let n=0;n<t.length;++n)e.appendChild(this.renderJSONMLTag(t[n]))}onClick(e){e.consume(!0),this.cachedContent?this.toggleExpand():this.loadBody()}toggleExpand(){this.expanded=!this.expanded,this.header instanceof Element&&this.header.classList.toggle("expanded",this.expanded),this.cachedContent instanceof Element&&this.cachedContent.classList.toggle("hidden",!this.expanded),this.expandIcon&&(this.expanded?this.expandIcon.name="triangle-down":this.expandIcon.name="triangle-right")}defaultBodyTreeOutline;async loadBody(){const e=this.object.customPreview();if(e&&e.bodyGetterId){const t=await this.object.callFunctionJSON((e=>e()),[{objectId:e.bodyGetterId}]);null===t?(this.defaultBodyTreeOutline=new R({readOnly:!0}),this.defaultBodyTreeOutline.setShowSelectionOnKeyboardFocus(!0,!1),this.defaultBodyTreeOutline.element.classList.add("custom-expandable-section-default-body"),N.populate(this.defaultBodyTreeOutline.rootElement(),this.object,!1,!1),this.cachedContent=this.defaultBodyTreeOutline.element):this.cachedContent=this.renderJSONMLTag(t),this.sectionElement.appendChild(this.cachedContent),this.toggleExpand()}}}const q=["span","div","ol","li","table","tr","td"];class X{object;customPreviewSection;element;constructor(e){this.object=e,this.customPreviewSection=new K(e),this.element=document.createElement("span"),this.element.classList.add("source-code");const t=i.UIUtils.createShadowRootWithCoreStyles(this.element,{cssFile:m});this.element.addEventListener("contextmenu",this.contextMenuEventFired.bind(this),!1),t.appendChild(this.customPreviewSection.element())}expandIfPossible(){const e=this.object.customPreview();e&&e.bodyGetterId&&this.customPreviewSection&&this.customPreviewSection.loadBody()}contextMenuEventFired(e){const t=new i.ContextMenu.ContextMenu(e);this.customPreviewSection&&t.revealSection().appendItem(z(J.showAsJavascriptObject),this.disassemble.bind(this),{jslogContext:"show-as-javascript-object"}),t.appendApplicableItems(this.object),t.show()}disassemble(){this.element.shadowRoot&&(this.element.shadowRoot.textContent="",this.customPreviewSection=null,this.element.shadowRoot.appendChild(M.defaultObjectPresentation(this.object)))}}var Q=Object.freeze({__proto__:null,CustomPreviewComponent:X,CustomPreviewSection:K}),Y={cssText:`.widget:has(.object-popover-tree){padding:0;border-radius:var(--sys-shape-corner-extra-small)}.object-popover-content{display:flex;position:relative;overflow:hidden;flex:1 1 auto;flex-direction:column}.object-popover-title{text-overflow:ellipsis;overflow:hidden;white-space:nowrap;font-weight:bold;padding-left:18px;padding-bottom:2px;padding-top:var(--sys-size-3);flex-shrink:0}.object-popover-tree{border-top:1px solid var(--sys-color-divider);overflow:auto;width:100%;height:calc(100% - 13px)}.object-popover-container{display:inline-block}.object-popover-description-box{padding:6px;max-width:350px;line-height:1.4}.object-popover-footer{margin-top:8px}\n/*# sourceURL=${import.meta.resolve("./objectPopover.css")} */\n`};const Z={learnMore:"Learn more"},ee=t.i18n.registerUIStrings("ui/legacy/components/object_ui/ObjectPopoverHelper.ts",Z),te=t.i18n.getLocalizedString.bind(void 0,ee);class ne{linkifier;resultHighlightedAsDOM;constructor(e,t){this.linkifier=e,this.resultHighlightedAsDOM=t}dispose(){this.resultHighlightedAsDOM&&r.OverlayModel.OverlayModel.hideDOMNodeHighlight(),this.linkifier&&this.linkifier.dispose()}static async buildObjectPopover(e,t){const n=s.StringUtilities.trimEndWithMaxLength(e.description||"",ie);let o=null;if("function"===e.type||"object"===e.type){let s=null,a=!1;if("node"===e.subtype&&(r.OverlayModel.OverlayModel.highlightObjectAsDOMNode(e),a=!0),e.customPreview()){const t=new X(e);t.expandIfPossible(),o=t.element}else{o=document.createElement("div"),o.classList.add("object-popover-content"),t.registerRequiredCSS(T,Y);const i=o.createChild("div","object-popover-title");"function"===e.type?(i.classList.add("source-code"),i.appendChild(M.valueElementForFunctionDescription(e.description))):(i.classList.add("monospace"),i.createChild("span").textContent=n),s=new u.Linkifier.Linkifier;const r=new M(e,"",s,!0);r.element.classList.add("object-popover-tree"),r.titleLessMode(),o.appendChild(r.element)}return o.dataset.stableNameForTest="object-popover-content",t.setMaxContentSize(new i.Geometry.Size(300,250)),t.setSizeBehavior("SetExactSize"),t.contentElement.appendChild(o),new ne(s,a)}o=document.createElement("span"),o.dataset.stableNameForTest="object-popover-content",t.registerRequiredCSS(T,Y);const a=o.createChild("span","monospace object-value-"+e.type);return a.style.whiteSpace="pre","string"===e.type?i.UIUtils.createTextChildren(a,`"${n}"`):a.textContent=n,t.contentElement.appendChild(o),new ne(null,!1)}static buildDescriptionPopover(e,t,n){const o=document.createElement("div");o.classList.add("object-popover-description-box");const s=document.createElement("div");s.dataset.stableNameForTest="object-popover-content",n.registerRequiredCSS(Y),s.textContent=e;const r=i.XLink.XLink.create(t,te(Z.learnMore),void 0,void 0,"learn-more"),a=document.createElement("div");return a.classList.add("object-popover-footer"),a.appendChild(r),o.appendChild(s),o.appendChild(a),n.contentElement.appendChild(o),new ne(null,!1)}}const ie=1e4;var oe=Object.freeze({__proto__:null,ObjectPopoverHelper:ne});export{Q as CustomPreviewComponent,E as JavaScriptREPL,oe as ObjectPopoverHelper,B as ObjectPropertiesSection,w as RemoteObjectPreviewFormatter};