@lytjs/devtools 3.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -290,7 +290,7 @@
290
290
  background: rgba(203, 166, 247, 0.1);
291
291
  border-radius: 2px;
292
292
  transition: all 0.15s ease;
293
- `;let t=e.getBoundingClientRect();this.highlightOverlay.style.left=`${t.left}px`,this.highlightOverlay.style.top=`${t.top}px`,this.highlightOverlay.style.width=`${t.width}px`,this.highlightOverlay.style.height=`${t.height}px`,document.body.appendChild(this.highlightOverlay)}clearHighlight(){this.highlightOverlay&&(this.highlightOverlay.remove(),this.highlightOverlay=null)}destroy(){this.styleEl.remove(),this.panelEl.remove(),this.clearHighlight(),window.removeEventListener("resize",this.onWindowResize),this.tabRenderers.clear()}};var E=new Map,M=[],w=[],xe=0,F=null,C={},U=!1;function ze(){return`comp_${++xe}`}function $e(){return`evt_${++xe}`}function ye(s){var t;if(!s)return"Unknown";let e=s.type||s.options;return e?e.name?e.name:e.render&&e.render.name?e.render.name:e.setup&&e.setup.name?e.setup.name:e._isComponentDefine&&((t=e.options)!=null&&t.name)?e.options.name:"Anonymous":"Anonymous"}function S(s){if(s===null||typeof s!="object")return s;if(Array.isArray(s))return s.map(t=>S(t));let e={};for(let t of Object.keys(s))e[t]=S(s[t]);return e}function Be(s,e){return s===e?!1:typeof s!=typeof e?!0:s===null||e===null?s!==e:typeof s=="object"?JSON.stringify(s)!==JSON.stringify(e):s!==e}function Ae(s,e){let t=e.split("."),n=s;for(let r of t){if(n==null||typeof n!="object")return;n=n[r]}return n}function Fe(s,e,t){let n=e.split("."),r=s;for(let o=0;o<n.length-1;o++)(r[n[o]]==null||typeof r[n[o]]!="object")&&(r[n[o]]={}),r=r[n[o]];r[n[n.length-1]]=t}function _(s,e){if(U){console.warn("[Lyt DevTools] \u5DF2\u7ECF\u8FDE\u63A5\u5230\u5E94\u7528\uFF0C\u4E0D\u80FD\u91CD\u590D\u8FDE\u63A5\u3002");return}e&&Object.assign(C,e),U=!0,Ue(s),s._instance&&(O(s._instance,null),ue()),console.log("[Lyt DevTools] \u5DF2\u8FDE\u63A5\u5230\u5E94\u7528\u5B9E\u4F8B\u3002")}function Ue(s){let e=s.mount.bind(s);s.mount=function(t){let n=e(t);return s._instance&&(O(s._instance,null),ue()),n}}function O(s,e){var o,i,l,d,p,a,c,u;if(!s)return;let t=be(s),n=!t;if(n){let h=ze();t={id:h,name:ye(s),parentId:e,childIds:[],props:{},state:{},computed:{},isMounted:(o=s.isMounted)!=null?o:!1,isUnmounted:(i=s.isUnmounted)!=null?i:!1,el:(l=s.el)!=null?l:null,renderTime:0,lastUpdateTime:Date.now(),instance:s},E.set(h,t)}else t.parentId=e,t.name=ye(s),t.isMounted=(d=s.isMounted)!=null?d:!1,t.isUnmounted=(p=s.isUnmounted)!=null?p:!1,t.el=(a=s.el)!=null?a:null,t.lastUpdateTime=Date.now();s.props&&(t.props=S(s.props)),s.state&&(t.state=S(s.state)),s.computedCache&&(t.computed=S(s.computedCache)),n&&s.state&&typeof s.state=="object"&&_e(t.id,s),n&&s.emit&&typeof s.emit=="function"&&Oe(t.id,s),n?(c=C.onComponentCreated)==null||c.call(C,t):(u=C.onComponentUpdated)==null||u.call(C,t);let r=s.subTree;r&&ve(r,t.id)}function ve(s,e){if(s){if(s.component){O(s.component,e);let t=E.get(e);if(t&&!t.childIds.includes(s.component.id||s.component._id)){let n=qe(s.component);n&&!t.childIds.includes(n)&&t.childIds.push(n)}return}if(s.children&&Array.isArray(s.children))for(let t of s.children)t&&typeof t=="object"&&ve(t,e)}}function _e(s,e){if(!e.state||typeof e.state!="object")return;let t=e.state,n=E.get(s);if(n&&!t.__devtools_intercepted__)try{Object.defineProperty(t,"__devtools_intercepted__",{value:!0,enumerable:!1,configurable:!1});let r=new Proxy(t,{set(o,i,l){var a;let d=o[i],p=Reflect.set(o,i,l);if(Be(d,l)){let c=String(i),u={componentId:s,componentName:n.name,path:c,oldValue:S(d),newValue:S(l),timestamp:Date.now()};w.push(u),w.length>1e3&&w.splice(0,w.length-1e3),n.state=S(o),n.lastUpdateTime=Date.now(),(a=C.onStateChanged)==null||a.call(C,u)}return p}});Object.defineProperty(e,"__devtools_state_proxy__",{value:r,enumerable:!1,configurable:!0})}catch(r){console.warn("[Lyt DevTools] \u72B6\u6001\u62E6\u622A\u5931\u8D25:",r)}}function Oe(s,e){if(!e.emit||typeof e.emit!="function")return;let t=e.emit,n=E.get(s);n&&(e.emit=function(r,...o){var l;let i={id:$e(),name:r,timestamp:Date.now(),args:S(o),componentId:s,componentName:n.name};return M.push(i),M.length>500&&M.splice(0,M.length-500),(l=C.onEventEmitted)==null||l.call(C,i),t.call(this,r,...o)})}function ue(){typeof window!="undefined"&&window.dispatchEvent(new CustomEvent("lyt-devtools-update"))}function be(s){for(let e of E.values())if(e.instance===s)return e;return null}function qe(s){let e=be(s);return e?e.id:null}function k(){return Array.from(E.values())}function q(){for(let s of E.values())if(s.parentId===null)return s;return null}function H(s){var e;return(e=E.get(s))!=null?e:null}function j(s){let e=E.get(s);return e?e.childIds.map(t=>E.get(t)).filter(Boolean):[]}function J(){return[...M]}function Te(){return[...w]}function V(s){return w.filter(e=>e.componentId===s)}function Ce(s){return M.filter(e=>e.componentId===s)}function W(s){F=s}function Y(){var s;return F&&(s=E.get(F))!=null?s:null}function L(){return F}function K(s,e,t){var l;let n=E.get(s);if(!n||!n.instance)return!1;let r=n.instance.state;if(!r||typeof r!="object")return!1;let o=Ae(r,e);Fe(r,e,t);let i={componentId:s,componentName:n.name,path:e,oldValue:S(o),newValue:S(t),timestamp:Date.now()};return w.push(i),n.state=S(r),n.lastUpdateTime=Date.now(),(l=C.onStateChanged)==null||l.call(C,i),!0}function X(s){E.clear(),s._instance&&(O(s._instance,null),ue())}function G(){M.length=0,w.length=0}function Q(){E.clear(),M.length=0,w.length=0,F=null,U=!1,console.log("[Lyt DevTools] \u5DF2\u65AD\u5F00\u4E0E\u5E94\u7528\u7684\u8FDE\u63A5\u3002")}function Ee(){return U}function Se(){return E.size}var I=class{constructor(e,t){this.searchKeyword="";this.expandedNodes=new Set;this.container=null;this.updateTimer=null;this.onUpdate=()=>{this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>{this.renderTree()},100)};this.panel=e,this.onSelect=t||(()=>{});let n=q();n&&this.expandedNodes.add(n.id),typeof window!="undefined"&&window.addEventListener("lyt-devtools-update",this.onUpdate)}render(e){this.container=e,this.renderTree()}renderTree(){if(!this.container)return;this.container.innerHTML="";let e=document.createElement("input");e.type="text",e.className="lyt-devtools-search",e.placeholder="\u641C\u7D22\u7EC4\u4EF6...",e.value=this.searchKeyword,e.addEventListener("input",r=>{this.searchKeyword=r.target.value,this.renderTree()}),this.container.appendChild(e);let t=k();if(t.length===0){let r=document.createElement("div");r.className="lyt-devtools-empty",r.textContent="\u6682\u65E0\u7EC4\u4EF6\uFF0C\u8BF7\u786E\u4FDD\u5E94\u7528\u5DF2\u6302\u8F7D\u3002",this.container.appendChild(r);return}let n=this.buildTree();for(let r of n){let o=this.renderTreeNode(r);o&&this.container.appendChild(o)}this.panel.setStatusLeft(`<span class="lyt-devtools-status-dot"></span><span>${t.length} \u4E2A\u7EC4\u4EF6</span>`)}buildTree(){let e=k(),t=new Map,n=[];for(let r of e){if(this.searchKeyword){let i=this.searchKeyword.toLowerCase(),l=r.name.toLowerCase().includes(i),d=r.id.toLowerCase().includes(i);if(!l&&!d)continue}let o={info:r,children:[],depth:0,expanded:this.expandedNodes.has(r.id)};t.set(r.id,o)}for(let r of t.values()){let o=r.info.parentId;if(o&&t.has(o)){let i=t.get(o);i.children.push(r),r.depth=i.depth+1}else n.push(r)}return n}renderTreeNode(e){let{info:t,depth:n,expanded:r}=e,o=L(),i=t.id===o,l=document.createElement("div");l.className="lyt-tree-node",l.style.cssText=`
293
+ `;let t=e.getBoundingClientRect();this.highlightOverlay.style.left=`${t.left}px`,this.highlightOverlay.style.top=`${t.top}px`,this.highlightOverlay.style.width=`${t.width}px`,this.highlightOverlay.style.height=`${t.height}px`,document.body.appendChild(this.highlightOverlay)}clearHighlight(){this.highlightOverlay&&(this.highlightOverlay.remove(),this.highlightOverlay=null)}destroy(){this.styleEl.remove(),this.panelEl.remove(),this.clearHighlight(),window.removeEventListener("resize",this.onWindowResize),this.tabRenderers.clear()}};var E=new Map,M=[],w=[],xe=0,F=null,C={},U=!1;function ze(){return`comp_${++xe}`}function $e(){return`evt_${++xe}`}function ye(s){var t;if(!s)return"Unknown";let e=s.type||s.options;return e?e.name?e.name:e.render&&e.render.name?e.render.name:e.setup&&e.setup.name?e.setup.name:e._isComponentDefine&&((t=e.options)!=null&&t.name)?e.options.name:"Anonymous":"Anonymous"}function S(s){if(s===null||typeof s!="object")return s;if(Array.isArray(s))return s.map(t=>S(t));let e={};for(let t of Object.keys(s))e[t]=S(s[t]);return e}function Be(s,e){return s===e?!1:typeof s!=typeof e?!0:s===null||e===null?s!==e:typeof s=="object"?JSON.stringify(s)!==JSON.stringify(e):s!==e}function Ae(s,e){let t=e.split("."),n=s;for(let r of t){if(n==null||typeof n!="object")return;n=n[r]}return n}function Fe(s,e,t){let n=e.split("."),r=s;for(let o=0;o<n.length-1;o++)(r[n[o]]==null||typeof r[n[o]]!="object")&&(r[n[o]]={}),r=r[n[o]];r[n[n.length-1]]=t}function _(s,e){U||(e&&Object.assign(C,e),U=!0,Ue(s),s._instance&&(O(s._instance,null),ue()))}function Ue(s){let e=s.mount.bind(s);s.mount=function(t){let n=e(t);return s._instance&&(O(s._instance,null),ue()),n}}function O(s,e){var o,i,l,d,p,a,c,u;if(!s)return;let t=be(s),n=!t;if(n){let h=ze();t={id:h,name:ye(s),parentId:e,childIds:[],props:{},state:{},computed:{},isMounted:(o=s.isMounted)!=null?o:!1,isUnmounted:(i=s.isUnmounted)!=null?i:!1,el:(l=s.el)!=null?l:null,renderTime:0,lastUpdateTime:Date.now(),instance:s},E.set(h,t)}else t.parentId=e,t.name=ye(s),t.isMounted=(d=s.isMounted)!=null?d:!1,t.isUnmounted=(p=s.isUnmounted)!=null?p:!1,t.el=(a=s.el)!=null?a:null,t.lastUpdateTime=Date.now();s.props&&(t.props=S(s.props)),s.state&&(t.state=S(s.state)),s.computedCache&&(t.computed=S(s.computedCache)),n&&s.state&&typeof s.state=="object"&&_e(t.id,s),n&&s.emit&&typeof s.emit=="function"&&Oe(t.id,s),n?(c=C.onComponentCreated)==null||c.call(C,t):(u=C.onComponentUpdated)==null||u.call(C,t);let r=s.subTree;r&&ve(r,t.id)}function ve(s,e){if(s){if(s.component){O(s.component,e);let t=E.get(e);if(t&&!t.childIds.includes(s.component.id||s.component._id)){let n=qe(s.component);n&&!t.childIds.includes(n)&&t.childIds.push(n)}return}if(s.children&&Array.isArray(s.children))for(let t of s.children)t&&typeof t=="object"&&ve(t,e)}}function _e(s,e){if(!e.state||typeof e.state!="object")return;let t=e.state,n=E.get(s);if(n&&!t.__devtools_intercepted__)try{Object.defineProperty(t,"__devtools_intercepted__",{value:!0,enumerable:!1,configurable:!1});let r=new Proxy(t,{set(o,i,l){var a;let d=o[i],p=Reflect.set(o,i,l);if(Be(d,l)){let c=String(i),u={componentId:s,componentName:n.name,path:c,oldValue:S(d),newValue:S(l),timestamp:Date.now()};w.push(u),w.length>1e3&&w.splice(0,w.length-1e3),n.state=S(o),n.lastUpdateTime=Date.now(),(a=C.onStateChanged)==null||a.call(C,u)}return p}});Object.defineProperty(e,"__devtools_state_proxy__",{value:r,enumerable:!1,configurable:!0})}catch(r){}}function Oe(s,e){if(!e.emit||typeof e.emit!="function")return;let t=e.emit,n=E.get(s);n&&(e.emit=function(r,...o){var l;let i={id:$e(),name:r,timestamp:Date.now(),args:S(o),componentId:s,componentName:n.name};return M.push(i),M.length>500&&M.splice(0,M.length-500),(l=C.onEventEmitted)==null||l.call(C,i),t.call(this,r,...o)})}function ue(){typeof window!="undefined"&&window.dispatchEvent(new CustomEvent("lyt-devtools-update"))}function be(s){for(let e of E.values())if(e.instance===s)return e;return null}function qe(s){let e=be(s);return e?e.id:null}function k(){return Array.from(E.values())}function q(){for(let s of E.values())if(s.parentId===null)return s;return null}function H(s){var e;return(e=E.get(s))!=null?e:null}function j(s){let e=E.get(s);return e?e.childIds.map(t=>E.get(t)).filter(Boolean):[]}function J(){return[...M]}function Te(){return[...w]}function V(s){return w.filter(e=>e.componentId===s)}function Ce(s){return M.filter(e=>e.componentId===s)}function W(s){F=s}function Y(){var s;return F&&(s=E.get(F))!=null?s:null}function L(){return F}function K(s,e,t){var l;let n=E.get(s);if(!n||!n.instance)return!1;let r=n.instance.state;if(!r||typeof r!="object")return!1;let o=Ae(r,e);Fe(r,e,t);let i={componentId:s,componentName:n.name,path:e,oldValue:S(o),newValue:S(t),timestamp:Date.now()};return w.push(i),n.state=S(r),n.lastUpdateTime=Date.now(),(l=C.onStateChanged)==null||l.call(C,i),!0}function X(s){E.clear(),s._instance&&(O(s._instance,null),ue())}function G(){M.length=0,w.length=0}function Q(){E.clear(),M.length=0,w.length=0,F=null,U=!1}function Ee(){return U}function Se(){return E.size}var I=class{constructor(e,t){this.searchKeyword="";this.expandedNodes=new Set;this.container=null;this.updateTimer=null;this.onUpdate=()=>{this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>{this.renderTree()},100)};this.panel=e,this.onSelect=t||(()=>{});let n=q();n&&this.expandedNodes.add(n.id),typeof window!="undefined"&&window.addEventListener("lyt-devtools-update",this.onUpdate)}render(e){this.container=e,this.renderTree()}renderTree(){if(!this.container)return;this.container.innerHTML="";let e=document.createElement("input");e.type="text",e.className="lyt-devtools-search",e.placeholder="\u641C\u7D22\u7EC4\u4EF6...",e.value=this.searchKeyword,e.addEventListener("input",r=>{this.searchKeyword=r.target.value,this.renderTree()}),this.container.appendChild(e);let t=k();if(t.length===0){let r=document.createElement("div");r.className="lyt-devtools-empty",r.textContent="\u6682\u65E0\u7EC4\u4EF6\uFF0C\u8BF7\u786E\u4FDD\u5E94\u7528\u5DF2\u6302\u8F7D\u3002",this.container.appendChild(r);return}let n=this.buildTree();for(let r of n){let o=this.renderTreeNode(r);o&&this.container.appendChild(o)}this.panel.setStatusLeft(`<span class="lyt-devtools-status-dot"></span><span>${t.length} \u4E2A\u7EC4\u4EF6</span>`)}buildTree(){let e=k(),t=new Map,n=[];for(let r of e){if(this.searchKeyword){let i=this.searchKeyword.toLowerCase(),l=r.name.toLowerCase().includes(i),d=r.id.toLowerCase().includes(i);if(!l&&!d)continue}let o={info:r,children:[],depth:0,expanded:this.expandedNodes.has(r.id)};t.set(r.id,o)}for(let r of t.values()){let o=r.info.parentId;if(o&&t.has(o)){let i=t.get(o);i.children.push(r),r.depth=i.depth+1}else n.push(r)}return n}renderTreeNode(e){let{info:t,depth:n,expanded:r}=e,o=L(),i=t.id===o,l=document.createElement("div");l.className="lyt-tree-node",l.style.cssText=`
294
294
  display: flex;
295
295
  align-items: center;
296
296
  padding: 3px 8px;
@@ -506,7 +506,7 @@
506
506
  <span style="color: #6c7086;">[${d}]</span>
507
507
  <span style="color: #585b70; margin: 0 4px;">${c}:</span>
508
508
  <span style="color: #a6e3a1; white-space: pre-wrap; word-break: break-all;">${this.escapeHtml(u)}</span>
509
- `,t.appendChild(p)}}else{let l=document.createElement("div");l.style.cssText="color: #585b70; font-size: 11px; font-style: italic;",l.textContent="\u6B64\u4E8B\u4EF6\u65E0\u53C2\u6570\u3002",t.appendChild(l)}this.container.appendChild(t)}escapeHtml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}clearEvents(){this.selectedEventId=null,this.renderEvents()}setPaused(e){this.paused=e}isPaused(){return this.paused}refresh(){this.renderEvents()}destroy(){this.updateTimer&&clearTimeout(this.updateTimer),this.autoScrollTimer&&clearInterval(this.autoScrollTimer),typeof window!="undefined"&&window.removeEventListener("lyt-devtools-update",this.onUpdate),this.container=null}};function P(s){if(s===null||typeof s!="object")return s;if(s instanceof Map){let t=new Map;for(let[n,r]of s)t.set(n,P(r));return t}if(Array.isArray(s))return s.map(t=>P(t));let e={};for(let t of Object.keys(s))e[t]=P(s[t]);return e}function We(s){let e=new Date(s);return e.toLocaleTimeString("zh-CN",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})+`.${String(e.getMilliseconds()).padStart(3,"0")}`}var $=class{constructor(e){this.container=null;this.snapshots=[];this.snapshotCounter=0;this.maxSnapshots=100;this.currentIndex=-1;this.playState="stopped";this.playSpeed=500;this.playTimer=null;this.autoSnapshot=!0;this.updateTimer=null;this.onUpdate=()=>{this.autoSnapshot&&(this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>{this.takeSnapshot("\u81EA\u52A8\u5FEB\u7167")},300))};this.panel=e,typeof window!="undefined"&&window.addEventListener("lyt-devtools-update",this.onUpdate)}takeSnapshot(e,t){let n=k(),r=new Map;for(let i of n)r.set(i.id,{id:i.id,name:i.name,state:P(i.state),props:P(i.props),computed:P(i.computed),isMounted:i.isMounted});let o={id:++this.snapshotCounter,timestamp:Date.now(),description:e||`\u5FEB\u7167 #${this.snapshotCounter}`,components:r,trigger:t};return this.snapshots.push(o),this.snapshots.length>this.maxSnapshots&&this.snapshots.splice(0,this.snapshots.length-this.maxSnapshots),(this.currentIndex===-1||this.currentIndex===this.snapshots.length-2)&&(this.currentIndex=this.snapshots.length-1),o}getSnapshots(){return[...this.snapshots]}getSnapshot(e){var t;return(t=this.snapshots[e])!=null?t:null}getCurrentIndex(){return this.currentIndex}clearSnapshots(){this.snapshots=[],this.snapshotCounter=0,this.currentIndex=-1,this.stopPlayback(),this.renderTimeTravel()}setAutoSnapshot(e){this.autoSnapshot=e}travelTo(e){e<0||e>=this.snapshots.length||(this.currentIndex=e,this.renderTimeTravel())}stepBack(){this.currentIndex>0&&this.travelTo(this.currentIndex-1)}stepForward(){this.currentIndex<this.snapshots.length-1&&this.travelTo(this.currentIndex+1)}goToLatest(){this.currentIndex=-1,this.stopPlayback(),this.renderTimeTravel()}restoreSnapshot(e){let t=this.snapshots[e];if(!t)return!1;for(let[n,r]of t.components){let o=H(n);if(!(!o||!o.instance)&&o.instance.state&&typeof o.instance.state=="object"){let i=Object.keys(r.state);for(let l of i)try{o.instance.state[l]=P(r.state[l])}catch(d){console.warn(`[Lyt DevTools] \u6062\u590D\u72B6\u6001\u5931\u8D25: ${o.name}.${l}`,d)}}}return!0}startPlayback(){this.playState!=="playing"&&((this.currentIndex===-1||this.currentIndex>=this.snapshots.length-1)&&(this.currentIndex=0),this.playState="playing",this.renderTimeTravel(),this.playTimer=setInterval(()=>{this.currentIndex<this.snapshots.length-1?(this.currentIndex++,this.renderTimeTravel()):this.stopPlayback()},this.playSpeed))}pausePlayback(){this.playState==="playing"&&(this.playState="paused",this.playTimer&&(clearInterval(this.playTimer),this.playTimer=null),this.renderTimeTravel())}stopPlayback(){this.playState="stopped",this.playTimer&&(clearInterval(this.playTimer),this.playTimer=null),this.renderTimeTravel()}setPlaySpeed(e){this.playSpeed=e,this.playState==="playing"&&(this.pausePlayback(),this.startPlayback())}getPlayState(){return this.playState}render(e){this.container=e,this.renderTimeTravel()}renderTimeTravel(){if(!this.container)return;this.container.innerHTML="";let e=document.createElement("div");e.style.cssText="display: flex; gap: 4px; margin-bottom: 8px; align-items: center; flex-wrap: wrap;";let t=document.createElement("button");t.style.cssText=this.createButtonStyle("#a6e3a1","#1e1e2e"),t.textContent="\u{1F4F8} \u5FEB\u7167",t.title="\u624B\u52A8\u521B\u5EFA\u5FEB\u7167",t.addEventListener("click",()=>{this.takeSnapshot("\u624B\u52A8\u5FEB\u7167"),this.renderTimeTravel()}),e.appendChild(t);let n=document.createElement("button");n.style.cssText=this.createButtonStyle("#89b4fa","#1e1e2e"),n.textContent="\u{1F504} \u6700\u65B0",n.title="\u56DE\u5230\u6700\u65B0\u72B6\u6001",n.addEventListener("click",()=>{this.goToLatest()}),e.appendChild(n);let r=document.createElement("button");r.style.cssText=this.createButtonStyle("#f38ba8","#1e1e2e"),r.textContent="\u{1F5D1} \u6E05\u7A7A",r.title="\u6E05\u7A7A\u6240\u6709\u5FEB\u7167",r.addEventListener("click",()=>{this.clearSnapshots()}),e.appendChild(r);let o=document.createElement("label");o.style.cssText="display: flex; align-items: center; gap: 4px; font-size: 11px; color: #a6adc8; margin-left: 8px; cursor: pointer;";let i=document.createElement("input");i.type="checkbox",i.checked=this.autoSnapshot,i.style.cssText="cursor: pointer;",i.addEventListener("change",()=>{this.autoSnapshot=i.checked}),o.appendChild(i),o.appendChild(document.createTextNode("\u81EA\u52A8\u5FEB\u7167")),e.appendChild(o),this.container.appendChild(e),this.snapshots.length>0&&this.renderPlaybackControls(this.container),this.renderSnapshotList(this.container);let l=this.currentIndex===-1;this.panel.setStatusLeft(`<span class="lyt-devtools-status-dot"></span><span>${this.snapshots.length} \u4E2A\u5FEB\u7167</span><span style="color: #585b70;">|</span><span>${l?"\u5B9E\u65F6":`\u5386\u53F2 #${this.currentIndex+1}`}</span>`)}renderPlaybackControls(e){let t=document.createElement("div");t.style.cssText=`
509
+ `,t.appendChild(p)}}else{let l=document.createElement("div");l.style.cssText="color: #585b70; font-size: 11px; font-style: italic;",l.textContent="\u6B64\u4E8B\u4EF6\u65E0\u53C2\u6570\u3002",t.appendChild(l)}this.container.appendChild(t)}escapeHtml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}clearEvents(){this.selectedEventId=null,this.renderEvents()}setPaused(e){this.paused=e}isPaused(){return this.paused}refresh(){this.renderEvents()}destroy(){this.updateTimer&&clearTimeout(this.updateTimer),this.autoScrollTimer&&clearInterval(this.autoScrollTimer),typeof window!="undefined"&&window.removeEventListener("lyt-devtools-update",this.onUpdate),this.container=null}};function P(s){if(s===null||typeof s!="object")return s;if(s instanceof Map){let t=new Map;for(let[n,r]of s)t.set(n,P(r));return t}if(Array.isArray(s))return s.map(t=>P(t));let e={};for(let t of Object.keys(s))e[t]=P(s[t]);return e}function We(s){let e=new Date(s);return e.toLocaleTimeString("zh-CN",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})+`.${String(e.getMilliseconds()).padStart(3,"0")}`}var $=class{constructor(e){this.container=null;this.snapshots=[];this.snapshotCounter=0;this.maxSnapshots=100;this.currentIndex=-1;this.playState="stopped";this.playSpeed=500;this.playTimer=null;this.autoSnapshot=!0;this.updateTimer=null;this.onUpdate=()=>{this.autoSnapshot&&(this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>{this.takeSnapshot("\u81EA\u52A8\u5FEB\u7167")},300))};this.panel=e,typeof window!="undefined"&&window.addEventListener("lyt-devtools-update",this.onUpdate)}takeSnapshot(e,t){let n=k(),r=new Map;for(let i of n)r.set(i.id,{id:i.id,name:i.name,state:P(i.state),props:P(i.props),computed:P(i.computed),isMounted:i.isMounted});let o={id:++this.snapshotCounter,timestamp:Date.now(),description:e||`\u5FEB\u7167 #${this.snapshotCounter}`,components:r,trigger:t};return this.snapshots.push(o),this.snapshots.length>this.maxSnapshots&&this.snapshots.splice(0,this.snapshots.length-this.maxSnapshots),(this.currentIndex===-1||this.currentIndex===this.snapshots.length-2)&&(this.currentIndex=this.snapshots.length-1),o}getSnapshots(){return[...this.snapshots]}getSnapshot(e){var t;return(t=this.snapshots[e])!=null?t:null}getCurrentIndex(){return this.currentIndex}clearSnapshots(){this.snapshots=[],this.snapshotCounter=0,this.currentIndex=-1,this.stopPlayback(),this.renderTimeTravel()}setAutoSnapshot(e){this.autoSnapshot=e}travelTo(e){e<0||e>=this.snapshots.length||(this.currentIndex=e,this.renderTimeTravel())}stepBack(){this.currentIndex>0&&this.travelTo(this.currentIndex-1)}stepForward(){this.currentIndex<this.snapshots.length-1&&this.travelTo(this.currentIndex+1)}goToLatest(){this.currentIndex=-1,this.stopPlayback(),this.renderTimeTravel()}restoreSnapshot(e){let t=this.snapshots[e];if(!t)return!1;for(let[n,r]of t.components){let o=H(n);if(!(!o||!o.instance)&&o.instance.state&&typeof o.instance.state=="object"){let i=Object.keys(r.state);for(let l of i)try{o.instance.state[l]=P(r.state[l])}catch(d){}}}return!0}startPlayback(){this.playState!=="playing"&&((this.currentIndex===-1||this.currentIndex>=this.snapshots.length-1)&&(this.currentIndex=0),this.playState="playing",this.renderTimeTravel(),this.playTimer=setInterval(()=>{this.currentIndex<this.snapshots.length-1?(this.currentIndex++,this.renderTimeTravel()):this.stopPlayback()},this.playSpeed))}pausePlayback(){this.playState==="playing"&&(this.playState="paused",this.playTimer&&(clearInterval(this.playTimer),this.playTimer=null),this.renderTimeTravel())}stopPlayback(){this.playState="stopped",this.playTimer&&(clearInterval(this.playTimer),this.playTimer=null),this.renderTimeTravel()}setPlaySpeed(e){this.playSpeed=e,this.playState==="playing"&&(this.pausePlayback(),this.startPlayback())}getPlayState(){return this.playState}render(e){this.container=e,this.renderTimeTravel()}renderTimeTravel(){if(!this.container)return;this.container.innerHTML="";let e=document.createElement("div");e.style.cssText="display: flex; gap: 4px; margin-bottom: 8px; align-items: center; flex-wrap: wrap;";let t=document.createElement("button");t.style.cssText=this.createButtonStyle("#a6e3a1","#1e1e2e"),t.textContent="\u{1F4F8} \u5FEB\u7167",t.title="\u624B\u52A8\u521B\u5EFA\u5FEB\u7167",t.addEventListener("click",()=>{this.takeSnapshot("\u624B\u52A8\u5FEB\u7167"),this.renderTimeTravel()}),e.appendChild(t);let n=document.createElement("button");n.style.cssText=this.createButtonStyle("#89b4fa","#1e1e2e"),n.textContent="\u{1F504} \u6700\u65B0",n.title="\u56DE\u5230\u6700\u65B0\u72B6\u6001",n.addEventListener("click",()=>{this.goToLatest()}),e.appendChild(n);let r=document.createElement("button");r.style.cssText=this.createButtonStyle("#f38ba8","#1e1e2e"),r.textContent="\u{1F5D1} \u6E05\u7A7A",r.title="\u6E05\u7A7A\u6240\u6709\u5FEB\u7167",r.addEventListener("click",()=>{this.clearSnapshots()}),e.appendChild(r);let o=document.createElement("label");o.style.cssText="display: flex; align-items: center; gap: 4px; font-size: 11px; color: #a6adc8; margin-left: 8px; cursor: pointer;";let i=document.createElement("input");i.type="checkbox",i.checked=this.autoSnapshot,i.style.cssText="cursor: pointer;",i.addEventListener("change",()=>{this.autoSnapshot=i.checked}),o.appendChild(i),o.appendChild(document.createTextNode("\u81EA\u52A8\u5FEB\u7167")),e.appendChild(o),this.container.appendChild(e),this.snapshots.length>0&&this.renderPlaybackControls(this.container),this.renderSnapshotList(this.container);let l=this.currentIndex===-1;this.panel.setStatusLeft(`<span class="lyt-devtools-status-dot"></span><span>${this.snapshots.length} \u4E2A\u5FEB\u7167</span><span style="color: #585b70;">|</span><span>${l?"\u5B9E\u65F6":`\u5386\u53F2 #${this.currentIndex+1}`}</span>`)}renderPlaybackControls(e){let t=document.createElement("div");t.style.cssText=`
510
510
  display: flex;
511
511
  align-items: center;
512
512
  gap: 6px;
@@ -608,7 +608,7 @@
608
608
  background: ${r?"#313244":"transparent"};
609
609
  color: ${o?"#89b4fa":"#cdd6f4"};
610
610
  border-bottom: 1px solid #1e1e2e;
611
- `;let l=document.createElement("span");l.style.cssText="display: inline-block; width: 14px; text-align: center; margin-right: 4px; font-size: 10px; color: #585b70;",i?l.textContent=e.expanded?"\u25BC":"\u25B6":l.textContent="\xB7",n.appendChild(l);let d=document.createElement("span");if(d.textContent=e.node.name,d.style.cssText="font-weight: bold;",n.appendChild(d),e.node.stateSummary){let c=document.createElement("span");c.textContent=` ${e.node.stateSummary}`,c.style.cssText="color: #a6adc8; font-size: 10px; margin-left: 6px;",n.appendChild(c)}if(e.node.propsCount!==void 0&&e.node.propsCount>0){let c=document.createElement("span");c.textContent=` [${e.node.propsCount} props]`,c.style.cssText="color: #585b70; font-size: 10px; margin-left: 4px;",n.appendChild(c)}let p=e.node,a=p.id;return n.addEventListener("click",()=>{var c;if(i){let u=(c=this.expandedMap.get(a))!=null?c:!1;this.expandedMap.set(a,!u),this.flatten(),this.renderNodes()}this.selectedId=a,this.onNodeClick&&this.onNodeClick(p)}),n}handleScroll(e){if(this.destroyed)return;let t=e.target;this.scrollTop=t.scrollTop,this.renderNodes()}getFlatNodes(){return[...this.flatNodes]}getVisibleNodeCount(){return this.getVisibleNodes().length}getTotalNodeCount(){return this.flatNodes.length}};var me=class{constructor(e){this.head=0;this.count=0;this.capacity=e,this.buffer=new Array(e).fill(void 0)}push(e){let t=(this.head+this.count)%this.capacity;this.buffer[t]=e,this.count<this.capacity?this.count++:this.head=(this.head+1)%this.capacity}getAll(){let e=[];for(let t=0;t<this.count;t++){let n=this.buffer[(this.head+t)%this.capacity];n!==void 0&&e.push(n)}return e}get size(){return this.count}get isEmpty(){return this.count===0}clear(){this.buffer.fill(void 0),this.head=0,this.count=0}},Xe=100,Ge=1024,Qe=.7,Ze=5,oe=class{constructor(e){this.counter=0;var t,n,r,o;this.config={bufferSize:(t=e==null?void 0:e.bufferSize)!=null?t:Xe,leakGrowthThreshold:(n=e==null?void 0:e.leakGrowthThreshold)!=null?n:Ge,leakRSquaredThreshold:(r=e==null?void 0:e.leakRSquaredThreshold)!=null?r:Qe,leakMinSnapshots:(o=e==null?void 0:e.leakMinSnapshots)!=null?o:Ze},this.snapshots=new me(this.config.bufferSize)}trackMemoryUsage(e,t,n,r){if(e===void 0){let i=performance.memory;i&&(e=i.usedJSHeapSize,t=i.totalJSHeapSize,n=i.jsHeapSizeLimit)}if(e===void 0)return null;let o={timestamp:r!=null?r:Date.now(),usedJSHeapSize:e,totalJSHeapSize:t!=null?t:0,jsHeapSizeLimit:n!=null?n:0,index:this.counter++};return this.snapshots.push(o),o}getMemoryTrend(){let e=this.snapshots.getAll();return e.length===0?[]:e.map((t,n)=>{let r=n>0?e[n-1]:null,o=r?t.usedJSHeapSize-r.usedJSHeapSize:0,i=t.jsHeapSizeLimit>0?t.usedJSHeapSize/t.jsHeapSizeLimit*100:0;return{timestamp:t.timestamp,usedJSHeapSize:t.usedJSHeapSize,delta:o,usagePercent:i}})}detectMemoryLeak(){let e=this.snapshots.getAll();if(e.length<this.config.leakMinSnapshots)return{hasLeak:!1,severity:"none",description:`\u5FEB\u7167\u6570\u91CF\u4E0D\u8DB3\uFF08\u9700\u8981\u81F3\u5C11 ${this.config.leakMinSnapshots} \u4E2A\uFF0C\u5F53\u524D ${e.length} \u4E2A\uFF09`,snapshotCount:e.length,growthRate:0,rSquared:0};let t=e.length,n=0,r=0,o=0,i=0,l=0;for(let g=0;g<t;g++){let b=g,T=e[g].usedJSHeapSize;n+=b,r+=T,o+=b*T,i+=b*b,l+=T*T}let d=t*i-n*n,p=d!==0?(t*o-n*r)/d:0,a=r/t,c=0,u=0;for(let g=0;g<t;g++){let b=e[g].usedJSHeapSize,T=p*g+(r-p*n)/t;c+=(b-a)*(b-a),u+=(b-T)*(b-T)}let h=c!==0?1-u/c:0,f=(e[t-1].timestamp-e[0].timestamp)/1e3,m=f>0?p/f:0,x=h>=this.config.leakRSquaredThreshold&&m>=this.config.leakGrowthThreshold,v="none",y="\u672A\u68C0\u6D4B\u5230\u5185\u5B58\u6CC4\u6F0F";return x&&(m>=this.config.leakGrowthThreshold*10?(v="high",y=`\u68C0\u6D4B\u5230\u4E25\u91CD\u5185\u5B58\u6CC4\u6F0F\uFF0C\u589E\u957F\u901F\u7387 ${Math.round(m)} bytes/s\uFF0CR\xB2=${h.toFixed(3)}`):m>=this.config.leakGrowthThreshold*3?(v="medium",y=`\u68C0\u6D4B\u5230\u4E2D\u7B49\u5185\u5B58\u6CC4\u6F0F\uFF0C\u589E\u957F\u901F\u7387 ${Math.round(m)} bytes/s\uFF0CR\xB2=${h.toFixed(3)}`):(v="low",y=`\u68C0\u6D4B\u5230\u8F7B\u5FAE\u5185\u5B58\u6CC4\u6F0F\uFF0C\u589E\u957F\u901F\u7387 ${Math.round(m)} bytes/s\uFF0CR\xB2=${h.toFixed(3)}`)),{hasLeak:x,severity:v,description:y,snapshotCount:t,growthRate:m,rSquared:h}}getMemoryReport(){let e=this.snapshots.getAll(),t=this.getMemoryTrend(),n=this.detectMemoryLeak(),r=null,o=0,i=0,l=0,d=1/0;for(let c of e)(!r||c.timestamp>r.timestamp)&&(r=c),c.usedJSHeapSize>o&&(o=c.usedJSHeapSize,i=c.timestamp),l+=c.usedJSHeapSize,c.usedJSHeapSize<d&&(d=c.usedJSHeapSize);let p=e.length>0?l/e.length:0;d===1/0&&(d=0);let a=e.length>=2?e[e.length-1].usedJSHeapSize-e[0].usedJSHeapSize:0;return{generatedAt:Date.now(),current:r,peakUsage:o,peakTimestamp:i,averageUsage:p,minUsage:d,totalGrowth:a,trend:t,leakDetection:n,snapshotCount:e.length}}getSnapshots(){return this.snapshots.getAll()}getSnapshotCount(){return this.snapshots.size}clear(){this.snapshots.clear(),this.counter=0}destroy(){this.clear()}};var fe=class{constructor(e){this.head=0;this.count=0;this.capacity=e,this.buffer=new Array(e).fill(void 0)}push(e){let t=(this.head+this.count)%this.capacity;this.buffer[t]=e,this.count<this.capacity?this.count++:this.head=(this.head+1)%this.capacity}getAll(){let e=[];for(let t=0;t<this.count;t++){let n=this.buffer[(this.head+t)%this.capacity];n!==void 0&&e.push(n)}return e}get size(){return this.count}get isEmpty(){return this.count===0}clear(){this.buffer.fill(void 0),this.head=0,this.count=0}},et=200,tt=16,se=class{constructor(e){this.counter=0;var t,n;this.config={bufferSize:(t=e==null?void 0:e.bufferSize)!=null?t:et,slowThreshold:(n=e==null?void 0:e.slowThreshold)!=null?n:tt},this.records=new fe(this.config.bufferSize)}trackRender(e,t){this.records.push({componentName:e,duration:t,timestamp:Date.now(),index:this.counter++})}getSlowRenderers(e){let t=e!=null?e:this.config.slowThreshold;return this.records.getAll().filter(r=>r.duration>t).map(r=>({componentName:r.componentName,duration:r.duration,timestamp:r.timestamp,overThreshold:r.duration-t})).sort((r,o)=>o.duration-r.duration)}getRenderStats(){let e=this.records.getAll(),t=this.config.slowThreshold;if(e.length===0)return{totalRenders:0,totalDuration:0,avgDuration:0,maxDuration:0,minDuration:0,slowRenderCount:0,slowRenderRatio:0,byComponent:[]};let n=0,r=-1/0,o=1/0,i=0,l=new Map;for(let p of e){n+=p.duration,p.duration>r&&(r=p.duration),p.duration<o&&(o=p.duration),p.duration>t&&i++;let a=l.get(p.componentName);a||(a={renderCount:0,totalDuration:0,maxDuration:-1/0,minDuration:1/0,slowCount:0},l.set(p.componentName,a)),a.renderCount++,a.totalDuration+=p.duration,p.duration>a.maxDuration&&(a.maxDuration=p.duration),p.duration<a.minDuration&&(a.minDuration=p.duration),p.duration>t&&a.slowCount++}let d=Array.from(l.entries()).map(([p,a])=>({componentName:p,renderCount:a.renderCount,avgDuration:a.totalDuration/a.renderCount,maxDuration:a.maxDuration===-1/0?0:a.maxDuration,minDuration:a.minDuration===1/0?0:a.minDuration,totalDuration:a.totalDuration,slowCount:a.slowCount})).sort((p,a)=>a.avgDuration-p.avgDuration);return{totalRenders:e.length,totalDuration:n,avgDuration:n/e.length,maxDuration:r===-1/0?0:r,minDuration:o===1/0?0:o,slowRenderCount:i,slowRenderRatio:i/e.length,byComponent:d}}getRenderTimeline(){let e=this.records.getAll(),t=this.config.slowThreshold;return e.map((n,r)=>({componentName:n.componentName,duration:n.duration,timestamp:n.timestamp,isSlow:n.duration>t,gap:r>0?n.timestamp-e[r-1].timestamp:-1}))}getRecords(){return this.records.getAll()}getRecordCount(){return this.records.size}clear(){this.records.clear(),this.counter=0}destroy(){this.clear()}};var ge=class{constructor(e){this.head=0;this.count=0;this.capacity=e,this.buffer=new Array(e).fill(void 0)}push(e){let t=(this.head+this.count)%this.capacity;this.buffer[t]=e,this.count<this.capacity?this.count++:this.head=(this.head+1)%this.capacity}getAll(){let e=[];for(let t=0;t<this.count;t++){let n=this.buffer[(this.head+t)%this.capacity];n!==void 0&&e.push(n)}return e}get size(){return this.count}get isEmpty(){return this.count===0}clear(){this.buffer.fill(void 0),this.head=0,this.count=0}},nt=100,rt=1e3,ot=2,ie=class{constructor(e){this.pending=new Map;this.counter=0;var t,n,r;this.config={bufferSize:(t=e==null?void 0:e.bufferSize)!=null?t:nt,slowThreshold:(n=e==null?void 0:e.slowThreshold)!=null?n:rt,outlierSigmaThreshold:(r=e==null?void 0:e.outlierSigmaThreshold)!=null?r:ot},this.records=new ge(this.config.bufferSize)}startBatch(e){return this.pending.has(e)?!1:(this.pending.set(e,Date.now()),!0)}endBatch(e){let t=this.pending.get(e);if(t===void 0)return null;let n=Date.now(),r=n-t;this.pending.delete(e);let o={name:e,startTime:t,endTime:n,duration:r,index:this.counter++};return this.records.push(o),o}getBatchStats(){let e=this.records.getAll();if(e.length===0)return{totalBatches:0,totalDuration:0,avgDuration:0,maxDuration:0,minDuration:0,byName:[]};let t=0,n=-1/0,r=1/0,o=new Map;for(let l of e){t+=l.duration,l.duration>n&&(n=l.duration),l.duration<r&&(r=l.duration);let d=o.get(l.name);d||(d={count:0,totalDuration:0,maxDuration:-1/0,minDuration:1/0,durations:[]},o.set(l.name,d)),d.count++,d.totalDuration+=l.duration,l.duration>d.maxDuration&&(d.maxDuration=l.duration),l.duration<d.minDuration&&(d.minDuration=l.duration),d.durations.push(l.duration)}let i=Array.from(o.entries()).map(([l,d])=>{let p=d.totalDuration/d.count,a=0;for(let u of d.durations)a+=(u-p)*(u-p);a/=d.count;let c=Math.sqrt(a);return{name:l,count:d.count,avgDuration:p,maxDuration:d.maxDuration===-1/0?0:d.maxDuration,minDuration:d.minDuration===1/0?0:d.minDuration,totalDuration:d.totalDuration,stdDev:c}});return{totalBatches:e.length,totalDuration:t,avgDuration:t/e.length,maxDuration:n===-1/0?0:n,minDuration:r===1/0?0:r,byName:i}}detectAnomalousBatches(){let e=this.records.getAll();if(e.length===0)return[];let t=this.getBatchStats(),n=[],r=new Map;for(let o of t.byName)r.set(o.name,o);for(let o of e){let i=r.get(o.name);if(o.duration>this.config.slowThreshold){n.push({name:o.name,duration:o.duration,timestamp:o.endTime,anomalyType:"slow",description:`\u64CD\u4F5C "${o.name}" \u8017\u65F6 ${o.duration.toFixed(1)}ms\uFF0C\u8D85\u8FC7\u6162\u64CD\u4F5C\u9608\u503C ${this.config.slowThreshold}ms`,deviationSigma:i&&i.stdDev>0?(o.duration-i.avgDuration)/i.stdDev:0});continue}if(i&&i.count>=2&&i.stdDev>0){let l=(o.duration-i.avgDuration)/i.stdDev;if(Math.abs(l)>this.config.outlierSigmaThreshold){let d=l>0?"slow":"fast";n.push({name:o.name,duration:o.duration,timestamp:o.endTime,anomalyType:d,description:`\u64CD\u4F5C "${o.name}" \u8017\u65F6 ${o.duration.toFixed(1)}ms\uFF0C\u504F\u79BB\u5E73\u5747\u503C ${l.toFixed(1)} \u4E2A\u6807\u51C6\u5DEE`,deviationSigma:l})}}}return n.sort((o,i)=>o.timestamp-i.timestamp),n}getRecords(){return this.records.getAll()}getRecordCount(){return this.records.size}getPendingBatches(){return Array.from(this.pending.keys())}clear(){this.records.clear(),this.pending.clear(),this.counter=0}destroy(){this.clear()}};var ae=class{constructor(e){this._installed=!1;this.app=null;var t,n,r,o,i,l;this.config={width:(t=e==null?void 0:e.width)!=null?t:420,height:(n=e==null?void 0:e.height)!=null?n:560,x:(r=e==null?void 0:e.x)!=null?r:void 0,y:(o=e==null?void 0:e.y)!=null?o:void 0,autoShow:(i=e==null?void 0:e.autoShow)!=null?i:!0,title:(l=e==null?void 0:e.title)!=null?l:"Lyt DevTools"},this.panel=new D({width:this.config.width,height:this.config.height,x:this.config.x,y:this.config.y,title:this.config.title}),this.componentTree=new I(this.panel,d=>{this.panel.switchTab("state"),this.stateInspector.refresh()}),this.stateInspector=new N(this.panel),this.eventTracker=new z(this.panel),this.timeTravel=new $(this.panel),this.panel.registerTabRenderer("components",d=>{this.componentTree.render(d)}),this.panel.registerTabRenderer("state",d=>{this.stateInspector.render(d)}),this.panel.registerTabRenderer("events",d=>{this.eventTracker.render(d)}),this.panel.registerTabRenderer("router",d=>{this.renderRouterTab(d)}),this.panel.renderContent(),this.config.autoShow||this.panel.hide()}install(e){if(this._installed){console.warn("[Lyt DevTools] DevTools \u5DF2\u7ECF\u5B89\u88C5\uFF0C\u4E0D\u80FD\u91CD\u590D\u5B89\u88C5\u3002");return}this.app=e,this._installed=!0,_(e,{onComponentCreated:n=>{this.componentTree.refresh()},onComponentUpdated:n=>{this.componentTree.refresh(),this.stateInspector.refresh()},onComponentUnmounted:n=>{this.componentTree.refresh()},onStateChanged:n=>{this.stateInspector.markChanged(`state.${n.path}`),this.stateInspector.refresh()},onEventEmitted:n=>{this.eventTracker.refresh()}}),this.panel.setConnected(!0),console.log("[Lyt DevTools] \u5DF2\u5B89\u88C5\u5230\u5E94\u7528\u3002\u6309 Ctrl+Shift+D \u5207\u6362\u9762\u677F\u663E\u793A\u3002")}show(){this.panel.show()}hide(){this.panel.hide()}toggle(){this.panel.toggle()}isVisible(){return this.panel.isVisible()}renderRouterTab(e){e.innerHTML="";let t=document.createElement("div");t.className="lyt-devtools-empty",t.style.cssText="padding: 40px 24px;",t.innerHTML=`
611
+ `;let l=document.createElement("span");l.style.cssText="display: inline-block; width: 14px; text-align: center; margin-right: 4px; font-size: 10px; color: #585b70;",i?l.textContent=e.expanded?"\u25BC":"\u25B6":l.textContent="\xB7",n.appendChild(l);let d=document.createElement("span");if(d.textContent=e.node.name,d.style.cssText="font-weight: bold;",n.appendChild(d),e.node.stateSummary){let c=document.createElement("span");c.textContent=` ${e.node.stateSummary}`,c.style.cssText="color: #a6adc8; font-size: 10px; margin-left: 6px;",n.appendChild(c)}if(e.node.propsCount!==void 0&&e.node.propsCount>0){let c=document.createElement("span");c.textContent=` [${e.node.propsCount} props]`,c.style.cssText="color: #585b70; font-size: 10px; margin-left: 4px;",n.appendChild(c)}let p=e.node,a=p.id;return n.addEventListener("click",()=>{var c;if(i){let u=(c=this.expandedMap.get(a))!=null?c:!1;this.expandedMap.set(a,!u),this.flatten(),this.renderNodes()}this.selectedId=a,this.onNodeClick&&this.onNodeClick(p)}),n}handleScroll(e){if(this.destroyed)return;let t=e.target;this.scrollTop=t.scrollTop,this.renderNodes()}getFlatNodes(){return[...this.flatNodes]}getVisibleNodeCount(){return this.getVisibleNodes().length}getTotalNodeCount(){return this.flatNodes.length}};var me=class{constructor(e){this.head=0;this.count=0;this.capacity=e,this.buffer=new Array(e).fill(void 0)}push(e){let t=(this.head+this.count)%this.capacity;this.buffer[t]=e,this.count<this.capacity?this.count++:this.head=(this.head+1)%this.capacity}getAll(){let e=[];for(let t=0;t<this.count;t++){let n=this.buffer[(this.head+t)%this.capacity];n!==void 0&&e.push(n)}return e}get size(){return this.count}get isEmpty(){return this.count===0}clear(){this.buffer.fill(void 0),this.head=0,this.count=0}},Xe=100,Ge=1024,Qe=.7,Ze=5,oe=class{constructor(e){this.counter=0;var t,n,r,o;this.config={bufferSize:(t=e==null?void 0:e.bufferSize)!=null?t:Xe,leakGrowthThreshold:(n=e==null?void 0:e.leakGrowthThreshold)!=null?n:Ge,leakRSquaredThreshold:(r=e==null?void 0:e.leakRSquaredThreshold)!=null?r:Qe,leakMinSnapshots:(o=e==null?void 0:e.leakMinSnapshots)!=null?o:Ze},this.snapshots=new me(this.config.bufferSize)}trackMemoryUsage(e,t,n,r){if(e===void 0){let i=performance.memory;i&&(e=i.usedJSHeapSize,t=i.totalJSHeapSize,n=i.jsHeapSizeLimit)}if(e===void 0)return null;let o={timestamp:r!=null?r:Date.now(),usedJSHeapSize:e,totalJSHeapSize:t!=null?t:0,jsHeapSizeLimit:n!=null?n:0,index:this.counter++};return this.snapshots.push(o),o}getMemoryTrend(){let e=this.snapshots.getAll();return e.length===0?[]:e.map((t,n)=>{let r=n>0?e[n-1]:null,o=r?t.usedJSHeapSize-r.usedJSHeapSize:0,i=t.jsHeapSizeLimit>0?t.usedJSHeapSize/t.jsHeapSizeLimit*100:0;return{timestamp:t.timestamp,usedJSHeapSize:t.usedJSHeapSize,delta:o,usagePercent:i}})}detectMemoryLeak(){let e=this.snapshots.getAll();if(e.length<this.config.leakMinSnapshots)return{hasLeak:!1,severity:"none",description:`\u5FEB\u7167\u6570\u91CF\u4E0D\u8DB3\uFF08\u9700\u8981\u81F3\u5C11 ${this.config.leakMinSnapshots} \u4E2A\uFF0C\u5F53\u524D ${e.length} \u4E2A\uFF09`,snapshotCount:e.length,growthRate:0,rSquared:0};let t=e.length,n=0,r=0,o=0,i=0,l=0;for(let g=0;g<t;g++){let b=g,T=e[g].usedJSHeapSize;n+=b,r+=T,o+=b*T,i+=b*b,l+=T*T}let d=t*i-n*n,p=d!==0?(t*o-n*r)/d:0,a=r/t,c=0,u=0;for(let g=0;g<t;g++){let b=e[g].usedJSHeapSize,T=p*g+(r-p*n)/t;c+=(b-a)*(b-a),u+=(b-T)*(b-T)}let h=c!==0?1-u/c:0,f=(e[t-1].timestamp-e[0].timestamp)/1e3,m=f>0?p/f:0,x=h>=this.config.leakRSquaredThreshold&&m>=this.config.leakGrowthThreshold,v="none",y="\u672A\u68C0\u6D4B\u5230\u5185\u5B58\u6CC4\u6F0F";return x&&(m>=this.config.leakGrowthThreshold*10?(v="high",y=`\u68C0\u6D4B\u5230\u4E25\u91CD\u5185\u5B58\u6CC4\u6F0F\uFF0C\u589E\u957F\u901F\u7387 ${Math.round(m)} bytes/s\uFF0CR\xB2=${h.toFixed(3)}`):m>=this.config.leakGrowthThreshold*3?(v="medium",y=`\u68C0\u6D4B\u5230\u4E2D\u7B49\u5185\u5B58\u6CC4\u6F0F\uFF0C\u589E\u957F\u901F\u7387 ${Math.round(m)} bytes/s\uFF0CR\xB2=${h.toFixed(3)}`):(v="low",y=`\u68C0\u6D4B\u5230\u8F7B\u5FAE\u5185\u5B58\u6CC4\u6F0F\uFF0C\u589E\u957F\u901F\u7387 ${Math.round(m)} bytes/s\uFF0CR\xB2=${h.toFixed(3)}`)),{hasLeak:x,severity:v,description:y,snapshotCount:t,growthRate:m,rSquared:h}}getMemoryReport(){let e=this.snapshots.getAll(),t=this.getMemoryTrend(),n=this.detectMemoryLeak(),r=null,o=0,i=0,l=0,d=1/0;for(let c of e)(!r||c.timestamp>r.timestamp)&&(r=c),c.usedJSHeapSize>o&&(o=c.usedJSHeapSize,i=c.timestamp),l+=c.usedJSHeapSize,c.usedJSHeapSize<d&&(d=c.usedJSHeapSize);let p=e.length>0?l/e.length:0;d===1/0&&(d=0);let a=e.length>=2?e[e.length-1].usedJSHeapSize-e[0].usedJSHeapSize:0;return{generatedAt:Date.now(),current:r,peakUsage:o,peakTimestamp:i,averageUsage:p,minUsage:d,totalGrowth:a,trend:t,leakDetection:n,snapshotCount:e.length}}getSnapshots(){return this.snapshots.getAll()}getSnapshotCount(){return this.snapshots.size}clear(){this.snapshots.clear(),this.counter=0}destroy(){this.clear()}};var fe=class{constructor(e){this.head=0;this.count=0;this.capacity=e,this.buffer=new Array(e).fill(void 0)}push(e){let t=(this.head+this.count)%this.capacity;this.buffer[t]=e,this.count<this.capacity?this.count++:this.head=(this.head+1)%this.capacity}getAll(){let e=[];for(let t=0;t<this.count;t++){let n=this.buffer[(this.head+t)%this.capacity];n!==void 0&&e.push(n)}return e}get size(){return this.count}get isEmpty(){return this.count===0}clear(){this.buffer.fill(void 0),this.head=0,this.count=0}},et=200,tt=16,se=class{constructor(e){this.counter=0;var t,n;this.config={bufferSize:(t=e==null?void 0:e.bufferSize)!=null?t:et,slowThreshold:(n=e==null?void 0:e.slowThreshold)!=null?n:tt},this.records=new fe(this.config.bufferSize)}trackRender(e,t){this.records.push({componentName:e,duration:t,timestamp:Date.now(),index:this.counter++})}getSlowRenderers(e){let t=e!=null?e:this.config.slowThreshold;return this.records.getAll().filter(r=>r.duration>t).map(r=>({componentName:r.componentName,duration:r.duration,timestamp:r.timestamp,overThreshold:r.duration-t})).sort((r,o)=>o.duration-r.duration)}getRenderStats(){let e=this.records.getAll(),t=this.config.slowThreshold;if(e.length===0)return{totalRenders:0,totalDuration:0,avgDuration:0,maxDuration:0,minDuration:0,slowRenderCount:0,slowRenderRatio:0,byComponent:[]};let n=0,r=-1/0,o=1/0,i=0,l=new Map;for(let p of e){n+=p.duration,p.duration>r&&(r=p.duration),p.duration<o&&(o=p.duration),p.duration>t&&i++;let a=l.get(p.componentName);a||(a={renderCount:0,totalDuration:0,maxDuration:-1/0,minDuration:1/0,slowCount:0},l.set(p.componentName,a)),a.renderCount++,a.totalDuration+=p.duration,p.duration>a.maxDuration&&(a.maxDuration=p.duration),p.duration<a.minDuration&&(a.minDuration=p.duration),p.duration>t&&a.slowCount++}let d=Array.from(l.entries()).map(([p,a])=>({componentName:p,renderCount:a.renderCount,avgDuration:a.totalDuration/a.renderCount,maxDuration:a.maxDuration===-1/0?0:a.maxDuration,minDuration:a.minDuration===1/0?0:a.minDuration,totalDuration:a.totalDuration,slowCount:a.slowCount})).sort((p,a)=>a.avgDuration-p.avgDuration);return{totalRenders:e.length,totalDuration:n,avgDuration:n/e.length,maxDuration:r===-1/0?0:r,minDuration:o===1/0?0:o,slowRenderCount:i,slowRenderRatio:i/e.length,byComponent:d}}getRenderTimeline(){let e=this.records.getAll(),t=this.config.slowThreshold;return e.map((n,r)=>({componentName:n.componentName,duration:n.duration,timestamp:n.timestamp,isSlow:n.duration>t,gap:r>0?n.timestamp-e[r-1].timestamp:-1}))}getRecords(){return this.records.getAll()}getRecordCount(){return this.records.size}clear(){this.records.clear(),this.counter=0}destroy(){this.clear()}};var ge=class{constructor(e){this.head=0;this.count=0;this.capacity=e,this.buffer=new Array(e).fill(void 0)}push(e){let t=(this.head+this.count)%this.capacity;this.buffer[t]=e,this.count<this.capacity?this.count++:this.head=(this.head+1)%this.capacity}getAll(){let e=[];for(let t=0;t<this.count;t++){let n=this.buffer[(this.head+t)%this.capacity];n!==void 0&&e.push(n)}return e}get size(){return this.count}get isEmpty(){return this.count===0}clear(){this.buffer.fill(void 0),this.head=0,this.count=0}},nt=100,rt=1e3,ot=2,ie=class{constructor(e){this.pending=new Map;this.counter=0;var t,n,r;this.config={bufferSize:(t=e==null?void 0:e.bufferSize)!=null?t:nt,slowThreshold:(n=e==null?void 0:e.slowThreshold)!=null?n:rt,outlierSigmaThreshold:(r=e==null?void 0:e.outlierSigmaThreshold)!=null?r:ot},this.records=new ge(this.config.bufferSize)}startBatch(e){return this.pending.has(e)?!1:(this.pending.set(e,Date.now()),!0)}endBatch(e){let t=this.pending.get(e);if(t===void 0)return null;let n=Date.now(),r=n-t;this.pending.delete(e);let o={name:e,startTime:t,endTime:n,duration:r,index:this.counter++};return this.records.push(o),o}getBatchStats(){let e=this.records.getAll();if(e.length===0)return{totalBatches:0,totalDuration:0,avgDuration:0,maxDuration:0,minDuration:0,byName:[]};let t=0,n=-1/0,r=1/0,o=new Map;for(let l of e){t+=l.duration,l.duration>n&&(n=l.duration),l.duration<r&&(r=l.duration);let d=o.get(l.name);d||(d={count:0,totalDuration:0,maxDuration:-1/0,minDuration:1/0,durations:[]},o.set(l.name,d)),d.count++,d.totalDuration+=l.duration,l.duration>d.maxDuration&&(d.maxDuration=l.duration),l.duration<d.minDuration&&(d.minDuration=l.duration),d.durations.push(l.duration)}let i=Array.from(o.entries()).map(([l,d])=>{let p=d.totalDuration/d.count,a=0;for(let u of d.durations)a+=(u-p)*(u-p);a/=d.count;let c=Math.sqrt(a);return{name:l,count:d.count,avgDuration:p,maxDuration:d.maxDuration===-1/0?0:d.maxDuration,minDuration:d.minDuration===1/0?0:d.minDuration,totalDuration:d.totalDuration,stdDev:c}});return{totalBatches:e.length,totalDuration:t,avgDuration:t/e.length,maxDuration:n===-1/0?0:n,minDuration:r===1/0?0:r,byName:i}}detectAnomalousBatches(){let e=this.records.getAll();if(e.length===0)return[];let t=this.getBatchStats(),n=[],r=new Map;for(let o of t.byName)r.set(o.name,o);for(let o of e){let i=r.get(o.name);if(o.duration>this.config.slowThreshold){n.push({name:o.name,duration:o.duration,timestamp:o.endTime,anomalyType:"slow",description:`\u64CD\u4F5C "${o.name}" \u8017\u65F6 ${o.duration.toFixed(1)}ms\uFF0C\u8D85\u8FC7\u6162\u64CD\u4F5C\u9608\u503C ${this.config.slowThreshold}ms`,deviationSigma:i&&i.stdDev>0?(o.duration-i.avgDuration)/i.stdDev:0});continue}if(i&&i.count>=2&&i.stdDev>0){let l=(o.duration-i.avgDuration)/i.stdDev;if(Math.abs(l)>this.config.outlierSigmaThreshold){let d=l>0?"slow":"fast";n.push({name:o.name,duration:o.duration,timestamp:o.endTime,anomalyType:d,description:`\u64CD\u4F5C "${o.name}" \u8017\u65F6 ${o.duration.toFixed(1)}ms\uFF0C\u504F\u79BB\u5E73\u5747\u503C ${l.toFixed(1)} \u4E2A\u6807\u51C6\u5DEE`,deviationSigma:l})}}}return n.sort((o,i)=>o.timestamp-i.timestamp),n}getRecords(){return this.records.getAll()}getRecordCount(){return this.records.size}getPendingBatches(){return Array.from(this.pending.keys())}clear(){this.records.clear(),this.pending.clear(),this.counter=0}destroy(){this.clear()}};var ae=class{constructor(e){this._installed=!1;this.app=null;var t,n,r,o,i,l;this.config={width:(t=e==null?void 0:e.width)!=null?t:420,height:(n=e==null?void 0:e.height)!=null?n:560,x:(r=e==null?void 0:e.x)!=null?r:void 0,y:(o=e==null?void 0:e.y)!=null?o:void 0,autoShow:(i=e==null?void 0:e.autoShow)!=null?i:!0,title:(l=e==null?void 0:e.title)!=null?l:"Lyt DevTools"},this.panel=new D({width:this.config.width,height:this.config.height,x:this.config.x,y:this.config.y,title:this.config.title}),this.componentTree=new I(this.panel,d=>{this.panel.switchTab("state"),this.stateInspector.refresh()}),this.stateInspector=new N(this.panel),this.eventTracker=new z(this.panel),this.timeTravel=new $(this.panel),this.panel.registerTabRenderer("components",d=>{this.componentTree.render(d)}),this.panel.registerTabRenderer("state",d=>{this.stateInspector.render(d)}),this.panel.registerTabRenderer("events",d=>{this.eventTracker.render(d)}),this.panel.registerTabRenderer("router",d=>{this.renderRouterTab(d)}),this.panel.renderContent(),this.config.autoShow||this.panel.hide()}install(e){if(this._installed)return;this.app=e,this._installed=!0,_(e,{onComponentCreated:n=>{this.componentTree.refresh()},onComponentUpdated:n=>{this.componentTree.refresh(),this.stateInspector.refresh()},onComponentUnmounted:n=>{this.componentTree.refresh()},onStateChanged:n=>{this.stateInspector.markChanged(`state.${n.path}`),this.stateInspector.refresh()},onEventEmitted:n=>{this.eventTracker.refresh()}}),this.panel.setConnected(!0)}show(){this.panel.show()}hide(){this.panel.hide()}toggle(){this.panel.toggle()}isVisible(){return this.panel.isVisible()}renderRouterTab(e){e.innerHTML="";let t=document.createElement("div");t.className="lyt-devtools-empty",t.style.cssText="padding: 40px 24px;",t.innerHTML=`
612
612
  <div style="font-size: 32px; margin-bottom: 12px;">\u{1F517}</div>
613
613
  <div style="color: #cdd6f4; font-size: 14px; margin-bottom: 8px; font-style: normal;">\u8DEF\u7531\u68C0\u67E5\u5668</div>
614
614
  <div style="color: #585b70; font-size: 12px;">
@@ -616,4 +616,4 @@
616
616
  \u8DEF\u7531\u68C0\u67E5\u5668\u5C06\u663E\u793A\u5F53\u524D\u8DEF\u7531\u4FE1\u606F\u3001<br>
617
617
  \u8DEF\u7531\u5B88\u536B\u548C\u5BFC\u822A\u5386\u53F2\u3002
618
618
  </div>
619
- `,e.appendChild(t)}refreshTree(){this.app&&X(this.app),this.componentTree.refresh()}clearAllRecords(){G(),this.eventTracker.refresh(),this.stateInspector.refresh()}getPanel(){return this.panel}getComponentTree(){return this.componentTree}getStateInspector(){return this.stateInspector}getEventTracker(){return this.eventTracker}getTimeTravel(){return this.timeTravel}destroy(){this.componentTree.destroy(),this.stateInspector.destroy(),this.eventTracker.destroy(),this.timeTravel.destroy(),this.panel.destroy(),Q(),this._installed=!1,this.app=null,console.log("[Lyt DevTools] \u5DF2\u9500\u6BC1\u3002")}};function st(s){let e=null;return{install(t){if(e){console.warn("[Lyt DevTools] \u5DF2\u7ECF\u521B\u5EFA\uFF0C\u4E0D\u80FD\u91CD\u590D\u5B89\u88C5\u3002");return}e=new ae(s),t.globalProperties&&(t.globalProperties.__LYT_DEVTOOLS__=e);let n=t;(n._instance!==void 0||n.mount)&&e.install(n)}}}
619
+ `,e.appendChild(t)}refreshTree(){this.app&&X(this.app),this.componentTree.refresh()}clearAllRecords(){G(),this.eventTracker.refresh(),this.stateInspector.refresh()}getPanel(){return this.panel}getComponentTree(){return this.componentTree}getStateInspector(){return this.stateInspector}getEventTracker(){return this.eventTracker}getTimeTravel(){return this.timeTravel}destroy(){this.componentTree.destroy(),this.stateInspector.destroy(),this.eventTracker.destroy(),this.timeTravel.destroy(),this.panel.destroy(),Q(),this._installed=!1,this.app=null}};function st(s){let e=null;return{install(t){if(e)return;e=new ae(s),t.globalProperties&&(t.globalProperties.__LYT_DEVTOOLS__=e);let n=t;(n._instance!==void 0||n.mount)&&e.install(n)}}}
package/dist/index.mjs CHANGED
@@ -290,7 +290,7 @@ var Ce=`
290
290
  background: rgba(203, 166, 247, 0.1);
291
291
  border-radius: 2px;
292
292
  transition: all 0.15s ease;
293
- `;let t=e.getBoundingClientRect();this.highlightOverlay.style.left=`${t.left}px`,this.highlightOverlay.style.top=`${t.top}px`,this.highlightOverlay.style.width=`${t.width}px`,this.highlightOverlay.style.height=`${t.height}px`,document.body.appendChild(this.highlightOverlay)}clearHighlight(){this.highlightOverlay&&(this.highlightOverlay.remove(),this.highlightOverlay=null)}destroy(){this.styleEl.remove(),this.panelEl.remove(),this.clearHighlight(),window.removeEventListener("resize",this.onWindowResize),this.tabRenderers.clear()}};var E=new Map,M=[],w=[],ye=0,H=null,C={},U=!1;function Se(){return`comp_${++ye}`}function we(){return`evt_${++ye}`}function ge(i){var t;if(!i)return"Unknown";let e=i.type||i.options;return e?e.name?e.name:e.render&&e.render.name?e.render.name:e.setup&&e.setup.name?e.setup.name:e._isComponentDefine&&((t=e.options)!=null&&t.name)?e.options.name:"Anonymous":"Anonymous"}function S(i){if(i===null||typeof i!="object")return i;if(Array.isArray(i))return i.map(t=>S(t));let e={};for(let t of Object.keys(i))e[t]=S(i[t]);return e}function Re(i,e){return i===e?!1:typeof i!=typeof e?!0:i===null||e===null?i!==e:typeof i=="object"?JSON.stringify(i)!==JSON.stringify(e):i!==e}function Me(i,e){let t=e.split("."),n=i;for(let r of t){if(n==null||typeof n!="object")return;n=n[r]}return n}function ke(i,e,t){let n=e.split("."),r=i;for(let o=0;o<n.length-1;o++)(r[n[o]]==null||typeof r[n[o]]!="object")&&(r[n[o]]={}),r=r[n[o]];r[n[n.length-1]]=t}function J(i,e){if(U){console.warn("[Lyt DevTools] \u5DF2\u7ECF\u8FDE\u63A5\u5230\u5E94\u7528\uFF0C\u4E0D\u80FD\u91CD\u590D\u8FDE\u63A5\u3002");return}e&&Object.assign(C,e),U=!0,Le(i),i._instance&&(_(i._instance,null),V()),console.log("[Lyt DevTools] \u5DF2\u8FDE\u63A5\u5230\u5E94\u7528\u5B9E\u4F8B\u3002")}function Le(i){let e=i.mount.bind(i);i.mount=function(t){let n=e(t);return i._instance&&(_(i._instance,null),V()),n}}function _(i,e){var o,s,l,d,p,a,c,u;if(!i)return;let t=ve(i),n=!t;if(n){let h=Se();t={id:h,name:ge(i),parentId:e,childIds:[],props:{},state:{},computed:{},isMounted:(o=i.isMounted)!=null?o:!1,isUnmounted:(s=i.isUnmounted)!=null?s:!1,el:(l=i.el)!=null?l:null,renderTime:0,lastUpdateTime:Date.now(),instance:i},E.set(h,t)}else t.parentId=e,t.name=ge(i),t.isMounted=(d=i.isMounted)!=null?d:!1,t.isUnmounted=(p=i.isUnmounted)!=null?p:!1,t.el=(a=i.el)!=null?a:null,t.lastUpdateTime=Date.now();i.props&&(t.props=S(i.props)),i.state&&(t.state=S(i.state)),i.computedCache&&(t.computed=S(i.computedCache)),n&&i.state&&typeof i.state=="object"&&Pe(t.id,i),n&&i.emit&&typeof i.emit=="function"&&De(t.id,i),n?(c=C.onComponentCreated)==null||c.call(C,t):(u=C.onComponentUpdated)==null||u.call(C,t);let r=i.subTree;r&&xe(r,t.id)}function xe(i,e){if(i){if(i.component){_(i.component,e);let t=E.get(e);if(t&&!t.childIds.includes(i.component.id||i.component._id)){let n=He(i.component);n&&!t.childIds.includes(n)&&t.childIds.push(n)}return}if(i.children&&Array.isArray(i.children))for(let t of i.children)t&&typeof t=="object"&&xe(t,e)}}function Pe(i,e){if(!e.state||typeof e.state!="object")return;let t=e.state,n=E.get(i);if(n&&!t.__devtools_intercepted__)try{Object.defineProperty(t,"__devtools_intercepted__",{value:!0,enumerable:!1,configurable:!1});let r=new Proxy(t,{set(o,s,l){var a;let d=o[s],p=Reflect.set(o,s,l);if(Re(d,l)){let c=String(s),u={componentId:i,componentName:n.name,path:c,oldValue:S(d),newValue:S(l),timestamp:Date.now()};w.push(u),w.length>1e3&&w.splice(0,w.length-1e3),n.state=S(o),n.lastUpdateTime=Date.now(),(a=C.onStateChanged)==null||a.call(C,u)}return p}});Object.defineProperty(e,"__devtools_state_proxy__",{value:r,enumerable:!1,configurable:!0})}catch(r){console.warn("[Lyt DevTools] \u72B6\u6001\u62E6\u622A\u5931\u8D25:",r)}}function De(i,e){if(!e.emit||typeof e.emit!="function")return;let t=e.emit,n=E.get(i);n&&(e.emit=function(r,...o){var l;let s={id:we(),name:r,timestamp:Date.now(),args:S(o),componentId:i,componentName:n.name};return M.push(s),M.length>500&&M.splice(0,M.length-500),(l=C.onEventEmitted)==null||l.call(C,s),t.call(this,r,...o)})}function V(){typeof window!="undefined"&&window.dispatchEvent(new CustomEvent("lyt-devtools-update"))}function ve(i){for(let e of E.values())if(e.instance===i)return e;return null}function He(i){let e=ve(i);return e?e.id:null}function L(){return Array.from(E.values())}function W(){for(let i of E.values())if(i.parentId===null)return i;return null}function I(i){var e;return(e=E.get(i))!=null?e:null}function Y(i){let e=E.get(i);return e?e.childIds.map(t=>E.get(t)).filter(Boolean):[]}function K(){return[...M]}function Ie(){return[...w]}function X(i){return w.filter(e=>e.componentId===i)}function Ne(i){return M.filter(e=>e.componentId===i)}function G(i){H=i}function Q(){var i;return H&&(i=E.get(H))!=null?i:null}function P(){return H}function Z(i,e,t){var l;let n=E.get(i);if(!n||!n.instance)return!1;let r=n.instance.state;if(!r||typeof r!="object")return!1;let o=Me(r,e);ke(r,e,t);let s={componentId:i,componentName:n.name,path:e,oldValue:S(o),newValue:S(t),timestamp:Date.now()};return w.push(s),n.state=S(r),n.lastUpdateTime=Date.now(),(l=C.onStateChanged)==null||l.call(C,s),!0}function ee(i){E.clear(),i._instance&&(_(i._instance,null),V())}function te(){M.length=0,w.length=0}function ne(){E.clear(),M.length=0,w.length=0,H=null,U=!1,console.log("[Lyt DevTools] \u5DF2\u65AD\u5F00\u4E0E\u5E94\u7528\u7684\u8FDE\u63A5\u3002")}function ze(){return U}function $e(){return E.size}var N=class{constructor(e,t){this.searchKeyword="";this.expandedNodes=new Set;this.container=null;this.updateTimer=null;this.onUpdate=()=>{this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>{this.renderTree()},100)};this.panel=e,this.onSelect=t||(()=>{});let n=W();n&&this.expandedNodes.add(n.id),typeof window!="undefined"&&window.addEventListener("lyt-devtools-update",this.onUpdate)}render(e){this.container=e,this.renderTree()}renderTree(){if(!this.container)return;this.container.innerHTML="";let e=document.createElement("input");e.type="text",e.className="lyt-devtools-search",e.placeholder="\u641C\u7D22\u7EC4\u4EF6...",e.value=this.searchKeyword,e.addEventListener("input",r=>{this.searchKeyword=r.target.value,this.renderTree()}),this.container.appendChild(e);let t=L();if(t.length===0){let r=document.createElement("div");r.className="lyt-devtools-empty",r.textContent="\u6682\u65E0\u7EC4\u4EF6\uFF0C\u8BF7\u786E\u4FDD\u5E94\u7528\u5DF2\u6302\u8F7D\u3002",this.container.appendChild(r);return}let n=this.buildTree();for(let r of n){let o=this.renderTreeNode(r);o&&this.container.appendChild(o)}this.panel.setStatusLeft(`<span class="lyt-devtools-status-dot"></span><span>${t.length} \u4E2A\u7EC4\u4EF6</span>`)}buildTree(){let e=L(),t=new Map,n=[];for(let r of e){if(this.searchKeyword){let s=this.searchKeyword.toLowerCase(),l=r.name.toLowerCase().includes(s),d=r.id.toLowerCase().includes(s);if(!l&&!d)continue}let o={info:r,children:[],depth:0,expanded:this.expandedNodes.has(r.id)};t.set(r.id,o)}for(let r of t.values()){let o=r.info.parentId;if(o&&t.has(o)){let s=t.get(o);s.children.push(r),r.depth=s.depth+1}else n.push(r)}return n}renderTreeNode(e){let{info:t,depth:n,expanded:r}=e,o=P(),s=t.id===o,l=document.createElement("div");l.className="lyt-tree-node",l.style.cssText=`
293
+ `;let t=e.getBoundingClientRect();this.highlightOverlay.style.left=`${t.left}px`,this.highlightOverlay.style.top=`${t.top}px`,this.highlightOverlay.style.width=`${t.width}px`,this.highlightOverlay.style.height=`${t.height}px`,document.body.appendChild(this.highlightOverlay)}clearHighlight(){this.highlightOverlay&&(this.highlightOverlay.remove(),this.highlightOverlay=null)}destroy(){this.styleEl.remove(),this.panelEl.remove(),this.clearHighlight(),window.removeEventListener("resize",this.onWindowResize),this.tabRenderers.clear()}};var E=new Map,M=[],w=[],ye=0,H=null,C={},U=!1;function Se(){return`comp_${++ye}`}function we(){return`evt_${++ye}`}function ge(i){var t;if(!i)return"Unknown";let e=i.type||i.options;return e?e.name?e.name:e.render&&e.render.name?e.render.name:e.setup&&e.setup.name?e.setup.name:e._isComponentDefine&&((t=e.options)!=null&&t.name)?e.options.name:"Anonymous":"Anonymous"}function S(i){if(i===null||typeof i!="object")return i;if(Array.isArray(i))return i.map(t=>S(t));let e={};for(let t of Object.keys(i))e[t]=S(i[t]);return e}function Re(i,e){return i===e?!1:typeof i!=typeof e?!0:i===null||e===null?i!==e:typeof i=="object"?JSON.stringify(i)!==JSON.stringify(e):i!==e}function Me(i,e){let t=e.split("."),n=i;for(let r of t){if(n==null||typeof n!="object")return;n=n[r]}return n}function ke(i,e,t){let n=e.split("."),r=i;for(let o=0;o<n.length-1;o++)(r[n[o]]==null||typeof r[n[o]]!="object")&&(r[n[o]]={}),r=r[n[o]];r[n[n.length-1]]=t}function J(i,e){U||(e&&Object.assign(C,e),U=!0,Le(i),i._instance&&(_(i._instance,null),V()))}function Le(i){let e=i.mount.bind(i);i.mount=function(t){let n=e(t);return i._instance&&(_(i._instance,null),V()),n}}function _(i,e){var o,s,l,d,p,a,c,u;if(!i)return;let t=ve(i),n=!t;if(n){let h=Se();t={id:h,name:ge(i),parentId:e,childIds:[],props:{},state:{},computed:{},isMounted:(o=i.isMounted)!=null?o:!1,isUnmounted:(s=i.isUnmounted)!=null?s:!1,el:(l=i.el)!=null?l:null,renderTime:0,lastUpdateTime:Date.now(),instance:i},E.set(h,t)}else t.parentId=e,t.name=ge(i),t.isMounted=(d=i.isMounted)!=null?d:!1,t.isUnmounted=(p=i.isUnmounted)!=null?p:!1,t.el=(a=i.el)!=null?a:null,t.lastUpdateTime=Date.now();i.props&&(t.props=S(i.props)),i.state&&(t.state=S(i.state)),i.computedCache&&(t.computed=S(i.computedCache)),n&&i.state&&typeof i.state=="object"&&Pe(t.id,i),n&&i.emit&&typeof i.emit=="function"&&De(t.id,i),n?(c=C.onComponentCreated)==null||c.call(C,t):(u=C.onComponentUpdated)==null||u.call(C,t);let r=i.subTree;r&&xe(r,t.id)}function xe(i,e){if(i){if(i.component){_(i.component,e);let t=E.get(e);if(t&&!t.childIds.includes(i.component.id||i.component._id)){let n=He(i.component);n&&!t.childIds.includes(n)&&t.childIds.push(n)}return}if(i.children&&Array.isArray(i.children))for(let t of i.children)t&&typeof t=="object"&&xe(t,e)}}function Pe(i,e){if(!e.state||typeof e.state!="object")return;let t=e.state,n=E.get(i);if(n&&!t.__devtools_intercepted__)try{Object.defineProperty(t,"__devtools_intercepted__",{value:!0,enumerable:!1,configurable:!1});let r=new Proxy(t,{set(o,s,l){var a;let d=o[s],p=Reflect.set(o,s,l);if(Re(d,l)){let c=String(s),u={componentId:i,componentName:n.name,path:c,oldValue:S(d),newValue:S(l),timestamp:Date.now()};w.push(u),w.length>1e3&&w.splice(0,w.length-1e3),n.state=S(o),n.lastUpdateTime=Date.now(),(a=C.onStateChanged)==null||a.call(C,u)}return p}});Object.defineProperty(e,"__devtools_state_proxy__",{value:r,enumerable:!1,configurable:!0})}catch(r){}}function De(i,e){if(!e.emit||typeof e.emit!="function")return;let t=e.emit,n=E.get(i);n&&(e.emit=function(r,...o){var l;let s={id:we(),name:r,timestamp:Date.now(),args:S(o),componentId:i,componentName:n.name};return M.push(s),M.length>500&&M.splice(0,M.length-500),(l=C.onEventEmitted)==null||l.call(C,s),t.call(this,r,...o)})}function V(){typeof window!="undefined"&&window.dispatchEvent(new CustomEvent("lyt-devtools-update"))}function ve(i){for(let e of E.values())if(e.instance===i)return e;return null}function He(i){let e=ve(i);return e?e.id:null}function L(){return Array.from(E.values())}function W(){for(let i of E.values())if(i.parentId===null)return i;return null}function I(i){var e;return(e=E.get(i))!=null?e:null}function Y(i){let e=E.get(i);return e?e.childIds.map(t=>E.get(t)).filter(Boolean):[]}function K(){return[...M]}function Ie(){return[...w]}function X(i){return w.filter(e=>e.componentId===i)}function Ne(i){return M.filter(e=>e.componentId===i)}function G(i){H=i}function Q(){var i;return H&&(i=E.get(H))!=null?i:null}function P(){return H}function Z(i,e,t){var l;let n=E.get(i);if(!n||!n.instance)return!1;let r=n.instance.state;if(!r||typeof r!="object")return!1;let o=Me(r,e);ke(r,e,t);let s={componentId:i,componentName:n.name,path:e,oldValue:S(o),newValue:S(t),timestamp:Date.now()};return w.push(s),n.state=S(r),n.lastUpdateTime=Date.now(),(l=C.onStateChanged)==null||l.call(C,s),!0}function ee(i){E.clear(),i._instance&&(_(i._instance,null),V())}function te(){M.length=0,w.length=0}function ne(){E.clear(),M.length=0,w.length=0,H=null,U=!1}function ze(){return U}function $e(){return E.size}var N=class{constructor(e,t){this.searchKeyword="";this.expandedNodes=new Set;this.container=null;this.updateTimer=null;this.onUpdate=()=>{this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>{this.renderTree()},100)};this.panel=e,this.onSelect=t||(()=>{});let n=W();n&&this.expandedNodes.add(n.id),typeof window!="undefined"&&window.addEventListener("lyt-devtools-update",this.onUpdate)}render(e){this.container=e,this.renderTree()}renderTree(){if(!this.container)return;this.container.innerHTML="";let e=document.createElement("input");e.type="text",e.className="lyt-devtools-search",e.placeholder="\u641C\u7D22\u7EC4\u4EF6...",e.value=this.searchKeyword,e.addEventListener("input",r=>{this.searchKeyword=r.target.value,this.renderTree()}),this.container.appendChild(e);let t=L();if(t.length===0){let r=document.createElement("div");r.className="lyt-devtools-empty",r.textContent="\u6682\u65E0\u7EC4\u4EF6\uFF0C\u8BF7\u786E\u4FDD\u5E94\u7528\u5DF2\u6302\u8F7D\u3002",this.container.appendChild(r);return}let n=this.buildTree();for(let r of n){let o=this.renderTreeNode(r);o&&this.container.appendChild(o)}this.panel.setStatusLeft(`<span class="lyt-devtools-status-dot"></span><span>${t.length} \u4E2A\u7EC4\u4EF6</span>`)}buildTree(){let e=L(),t=new Map,n=[];for(let r of e){if(this.searchKeyword){let s=this.searchKeyword.toLowerCase(),l=r.name.toLowerCase().includes(s),d=r.id.toLowerCase().includes(s);if(!l&&!d)continue}let o={info:r,children:[],depth:0,expanded:this.expandedNodes.has(r.id)};t.set(r.id,o)}for(let r of t.values()){let o=r.info.parentId;if(o&&t.has(o)){let s=t.get(o);s.children.push(r),r.depth=s.depth+1}else n.push(r)}return n}renderTreeNode(e){let{info:t,depth:n,expanded:r}=e,o=P(),s=t.id===o,l=document.createElement("div");l.className="lyt-tree-node",l.style.cssText=`
294
294
  display: flex;
295
295
  align-items: center;
296
296
  padding: 3px 8px;
@@ -506,7 +506,7 @@ var Ce=`
506
506
  <span style="color: #6c7086;">[${d}]</span>
507
507
  <span style="color: #585b70; margin: 0 4px;">${c}:</span>
508
508
  <span style="color: #a6e3a1; white-space: pre-wrap; word-break: break-all;">${this.escapeHtml(u)}</span>
509
- `,t.appendChild(p)}}else{let l=document.createElement("div");l.style.cssText="color: #585b70; font-size: 11px; font-style: italic;",l.textContent="\u6B64\u4E8B\u4EF6\u65E0\u53C2\u6570\u3002",t.appendChild(l)}this.container.appendChild(t)}escapeHtml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}clearEvents(){this.selectedEventId=null,this.renderEvents()}setPaused(e){this.paused=e}isPaused(){return this.paused}refresh(){this.renderEvents()}destroy(){this.updateTimer&&clearTimeout(this.updateTimer),this.autoScrollTimer&&clearInterval(this.autoScrollTimer),typeof window!="undefined"&&window.removeEventListener("lyt-devtools-update",this.onUpdate),this.container=null}};function k(i){if(i===null||typeof i!="object")return i;if(i instanceof Map){let t=new Map;for(let[n,r]of i)t.set(n,k(r));return t}if(Array.isArray(i))return i.map(t=>k(t));let e={};for(let t of Object.keys(i))e[t]=k(i[t]);return e}function Ue(i){let e=new Date(i);return e.toLocaleTimeString("zh-CN",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})+`.${String(e.getMilliseconds()).padStart(3,"0")}`}var B=class{constructor(e){this.container=null;this.snapshots=[];this.snapshotCounter=0;this.maxSnapshots=100;this.currentIndex=-1;this.playState="stopped";this.playSpeed=500;this.playTimer=null;this.autoSnapshot=!0;this.updateTimer=null;this.onUpdate=()=>{this.autoSnapshot&&(this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>{this.takeSnapshot("\u81EA\u52A8\u5FEB\u7167")},300))};this.panel=e,typeof window!="undefined"&&window.addEventListener("lyt-devtools-update",this.onUpdate)}takeSnapshot(e,t){let n=L(),r=new Map;for(let s of n)r.set(s.id,{id:s.id,name:s.name,state:k(s.state),props:k(s.props),computed:k(s.computed),isMounted:s.isMounted});let o={id:++this.snapshotCounter,timestamp:Date.now(),description:e||`\u5FEB\u7167 #${this.snapshotCounter}`,components:r,trigger:t};return this.snapshots.push(o),this.snapshots.length>this.maxSnapshots&&this.snapshots.splice(0,this.snapshots.length-this.maxSnapshots),(this.currentIndex===-1||this.currentIndex===this.snapshots.length-2)&&(this.currentIndex=this.snapshots.length-1),o}getSnapshots(){return[...this.snapshots]}getSnapshot(e){var t;return(t=this.snapshots[e])!=null?t:null}getCurrentIndex(){return this.currentIndex}clearSnapshots(){this.snapshots=[],this.snapshotCounter=0,this.currentIndex=-1,this.stopPlayback(),this.renderTimeTravel()}setAutoSnapshot(e){this.autoSnapshot=e}travelTo(e){e<0||e>=this.snapshots.length||(this.currentIndex=e,this.renderTimeTravel())}stepBack(){this.currentIndex>0&&this.travelTo(this.currentIndex-1)}stepForward(){this.currentIndex<this.snapshots.length-1&&this.travelTo(this.currentIndex+1)}goToLatest(){this.currentIndex=-1,this.stopPlayback(),this.renderTimeTravel()}restoreSnapshot(e){let t=this.snapshots[e];if(!t)return!1;for(let[n,r]of t.components){let o=I(n);if(!(!o||!o.instance)&&o.instance.state&&typeof o.instance.state=="object"){let s=Object.keys(r.state);for(let l of s)try{o.instance.state[l]=k(r.state[l])}catch(d){console.warn(`[Lyt DevTools] \u6062\u590D\u72B6\u6001\u5931\u8D25: ${o.name}.${l}`,d)}}}return!0}startPlayback(){this.playState!=="playing"&&((this.currentIndex===-1||this.currentIndex>=this.snapshots.length-1)&&(this.currentIndex=0),this.playState="playing",this.renderTimeTravel(),this.playTimer=setInterval(()=>{this.currentIndex<this.snapshots.length-1?(this.currentIndex++,this.renderTimeTravel()):this.stopPlayback()},this.playSpeed))}pausePlayback(){this.playState==="playing"&&(this.playState="paused",this.playTimer&&(clearInterval(this.playTimer),this.playTimer=null),this.renderTimeTravel())}stopPlayback(){this.playState="stopped",this.playTimer&&(clearInterval(this.playTimer),this.playTimer=null),this.renderTimeTravel()}setPlaySpeed(e){this.playSpeed=e,this.playState==="playing"&&(this.pausePlayback(),this.startPlayback())}getPlayState(){return this.playState}render(e){this.container=e,this.renderTimeTravel()}renderTimeTravel(){if(!this.container)return;this.container.innerHTML="";let e=document.createElement("div");e.style.cssText="display: flex; gap: 4px; margin-bottom: 8px; align-items: center; flex-wrap: wrap;";let t=document.createElement("button");t.style.cssText=this.createButtonStyle("#a6e3a1","#1e1e2e"),t.textContent="\u{1F4F8} \u5FEB\u7167",t.title="\u624B\u52A8\u521B\u5EFA\u5FEB\u7167",t.addEventListener("click",()=>{this.takeSnapshot("\u624B\u52A8\u5FEB\u7167"),this.renderTimeTravel()}),e.appendChild(t);let n=document.createElement("button");n.style.cssText=this.createButtonStyle("#89b4fa","#1e1e2e"),n.textContent="\u{1F504} \u6700\u65B0",n.title="\u56DE\u5230\u6700\u65B0\u72B6\u6001",n.addEventListener("click",()=>{this.goToLatest()}),e.appendChild(n);let r=document.createElement("button");r.style.cssText=this.createButtonStyle("#f38ba8","#1e1e2e"),r.textContent="\u{1F5D1} \u6E05\u7A7A",r.title="\u6E05\u7A7A\u6240\u6709\u5FEB\u7167",r.addEventListener("click",()=>{this.clearSnapshots()}),e.appendChild(r);let o=document.createElement("label");o.style.cssText="display: flex; align-items: center; gap: 4px; font-size: 11px; color: #a6adc8; margin-left: 8px; cursor: pointer;";let s=document.createElement("input");s.type="checkbox",s.checked=this.autoSnapshot,s.style.cssText="cursor: pointer;",s.addEventListener("change",()=>{this.autoSnapshot=s.checked}),o.appendChild(s),o.appendChild(document.createTextNode("\u81EA\u52A8\u5FEB\u7167")),e.appendChild(o),this.container.appendChild(e),this.snapshots.length>0&&this.renderPlaybackControls(this.container),this.renderSnapshotList(this.container);let l=this.currentIndex===-1;this.panel.setStatusLeft(`<span class="lyt-devtools-status-dot"></span><span>${this.snapshots.length} \u4E2A\u5FEB\u7167</span><span style="color: #585b70;">|</span><span>${l?"\u5B9E\u65F6":`\u5386\u53F2 #${this.currentIndex+1}`}</span>`)}renderPlaybackControls(e){let t=document.createElement("div");t.style.cssText=`
509
+ `,t.appendChild(p)}}else{let l=document.createElement("div");l.style.cssText="color: #585b70; font-size: 11px; font-style: italic;",l.textContent="\u6B64\u4E8B\u4EF6\u65E0\u53C2\u6570\u3002",t.appendChild(l)}this.container.appendChild(t)}escapeHtml(e){return e.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")}clearEvents(){this.selectedEventId=null,this.renderEvents()}setPaused(e){this.paused=e}isPaused(){return this.paused}refresh(){this.renderEvents()}destroy(){this.updateTimer&&clearTimeout(this.updateTimer),this.autoScrollTimer&&clearInterval(this.autoScrollTimer),typeof window!="undefined"&&window.removeEventListener("lyt-devtools-update",this.onUpdate),this.container=null}};function k(i){if(i===null||typeof i!="object")return i;if(i instanceof Map){let t=new Map;for(let[n,r]of i)t.set(n,k(r));return t}if(Array.isArray(i))return i.map(t=>k(t));let e={};for(let t of Object.keys(i))e[t]=k(i[t]);return e}function Ue(i){let e=new Date(i);return e.toLocaleTimeString("zh-CN",{hour12:!1,hour:"2-digit",minute:"2-digit",second:"2-digit"})+`.${String(e.getMilliseconds()).padStart(3,"0")}`}var B=class{constructor(e){this.container=null;this.snapshots=[];this.snapshotCounter=0;this.maxSnapshots=100;this.currentIndex=-1;this.playState="stopped";this.playSpeed=500;this.playTimer=null;this.autoSnapshot=!0;this.updateTimer=null;this.onUpdate=()=>{this.autoSnapshot&&(this.updateTimer&&clearTimeout(this.updateTimer),this.updateTimer=setTimeout(()=>{this.takeSnapshot("\u81EA\u52A8\u5FEB\u7167")},300))};this.panel=e,typeof window!="undefined"&&window.addEventListener("lyt-devtools-update",this.onUpdate)}takeSnapshot(e,t){let n=L(),r=new Map;for(let s of n)r.set(s.id,{id:s.id,name:s.name,state:k(s.state),props:k(s.props),computed:k(s.computed),isMounted:s.isMounted});let o={id:++this.snapshotCounter,timestamp:Date.now(),description:e||`\u5FEB\u7167 #${this.snapshotCounter}`,components:r,trigger:t};return this.snapshots.push(o),this.snapshots.length>this.maxSnapshots&&this.snapshots.splice(0,this.snapshots.length-this.maxSnapshots),(this.currentIndex===-1||this.currentIndex===this.snapshots.length-2)&&(this.currentIndex=this.snapshots.length-1),o}getSnapshots(){return[...this.snapshots]}getSnapshot(e){var t;return(t=this.snapshots[e])!=null?t:null}getCurrentIndex(){return this.currentIndex}clearSnapshots(){this.snapshots=[],this.snapshotCounter=0,this.currentIndex=-1,this.stopPlayback(),this.renderTimeTravel()}setAutoSnapshot(e){this.autoSnapshot=e}travelTo(e){e<0||e>=this.snapshots.length||(this.currentIndex=e,this.renderTimeTravel())}stepBack(){this.currentIndex>0&&this.travelTo(this.currentIndex-1)}stepForward(){this.currentIndex<this.snapshots.length-1&&this.travelTo(this.currentIndex+1)}goToLatest(){this.currentIndex=-1,this.stopPlayback(),this.renderTimeTravel()}restoreSnapshot(e){let t=this.snapshots[e];if(!t)return!1;for(let[n,r]of t.components){let o=I(n);if(!(!o||!o.instance)&&o.instance.state&&typeof o.instance.state=="object"){let s=Object.keys(r.state);for(let l of s)try{o.instance.state[l]=k(r.state[l])}catch(d){}}}return!0}startPlayback(){this.playState!=="playing"&&((this.currentIndex===-1||this.currentIndex>=this.snapshots.length-1)&&(this.currentIndex=0),this.playState="playing",this.renderTimeTravel(),this.playTimer=setInterval(()=>{this.currentIndex<this.snapshots.length-1?(this.currentIndex++,this.renderTimeTravel()):this.stopPlayback()},this.playSpeed))}pausePlayback(){this.playState==="playing"&&(this.playState="paused",this.playTimer&&(clearInterval(this.playTimer),this.playTimer=null),this.renderTimeTravel())}stopPlayback(){this.playState="stopped",this.playTimer&&(clearInterval(this.playTimer),this.playTimer=null),this.renderTimeTravel()}setPlaySpeed(e){this.playSpeed=e,this.playState==="playing"&&(this.pausePlayback(),this.startPlayback())}getPlayState(){return this.playState}render(e){this.container=e,this.renderTimeTravel()}renderTimeTravel(){if(!this.container)return;this.container.innerHTML="";let e=document.createElement("div");e.style.cssText="display: flex; gap: 4px; margin-bottom: 8px; align-items: center; flex-wrap: wrap;";let t=document.createElement("button");t.style.cssText=this.createButtonStyle("#a6e3a1","#1e1e2e"),t.textContent="\u{1F4F8} \u5FEB\u7167",t.title="\u624B\u52A8\u521B\u5EFA\u5FEB\u7167",t.addEventListener("click",()=>{this.takeSnapshot("\u624B\u52A8\u5FEB\u7167"),this.renderTimeTravel()}),e.appendChild(t);let n=document.createElement("button");n.style.cssText=this.createButtonStyle("#89b4fa","#1e1e2e"),n.textContent="\u{1F504} \u6700\u65B0",n.title="\u56DE\u5230\u6700\u65B0\u72B6\u6001",n.addEventListener("click",()=>{this.goToLatest()}),e.appendChild(n);let r=document.createElement("button");r.style.cssText=this.createButtonStyle("#f38ba8","#1e1e2e"),r.textContent="\u{1F5D1} \u6E05\u7A7A",r.title="\u6E05\u7A7A\u6240\u6709\u5FEB\u7167",r.addEventListener("click",()=>{this.clearSnapshots()}),e.appendChild(r);let o=document.createElement("label");o.style.cssText="display: flex; align-items: center; gap: 4px; font-size: 11px; color: #a6adc8; margin-left: 8px; cursor: pointer;";let s=document.createElement("input");s.type="checkbox",s.checked=this.autoSnapshot,s.style.cssText="cursor: pointer;",s.addEventListener("change",()=>{this.autoSnapshot=s.checked}),o.appendChild(s),o.appendChild(document.createTextNode("\u81EA\u52A8\u5FEB\u7167")),e.appendChild(o),this.container.appendChild(e),this.snapshots.length>0&&this.renderPlaybackControls(this.container),this.renderSnapshotList(this.container);let l=this.currentIndex===-1;this.panel.setStatusLeft(`<span class="lyt-devtools-status-dot"></span><span>${this.snapshots.length} \u4E2A\u5FEB\u7167</span><span style="color: #585b70;">|</span><span>${l?"\u5B9E\u65F6":`\u5386\u53F2 #${this.currentIndex+1}`}</span>`)}renderPlaybackControls(e){let t=document.createElement("div");t.style.cssText=`
510
510
  display: flex;
511
511
  align-items: center;
512
512
  gap: 6px;
@@ -608,7 +608,7 @@ var Ce=`
608
608
  background: ${r?"#313244":"transparent"};
609
609
  color: ${o?"#89b4fa":"#cdd6f4"};
610
610
  border-bottom: 1px solid #1e1e2e;
611
- `;let l=document.createElement("span");l.style.cssText="display: inline-block; width: 14px; text-align: center; margin-right: 4px; font-size: 10px; color: #585b70;",s?l.textContent=e.expanded?"\u25BC":"\u25B6":l.textContent="\xB7",n.appendChild(l);let d=document.createElement("span");if(d.textContent=e.node.name,d.style.cssText="font-weight: bold;",n.appendChild(d),e.node.stateSummary){let c=document.createElement("span");c.textContent=` ${e.node.stateSummary}`,c.style.cssText="color: #a6adc8; font-size: 10px; margin-left: 6px;",n.appendChild(c)}if(e.node.propsCount!==void 0&&e.node.propsCount>0){let c=document.createElement("span");c.textContent=` [${e.node.propsCount} props]`,c.style.cssText="color: #585b70; font-size: 10px; margin-left: 4px;",n.appendChild(c)}let p=e.node,a=p.id;return n.addEventListener("click",()=>{var c;if(s){let u=(c=this.expandedMap.get(a))!=null?c:!1;this.expandedMap.set(a,!u),this.flatten(),this.renderNodes()}this.selectedId=a,this.onNodeClick&&this.onNodeClick(p)}),n}handleScroll(e){if(this.destroyed)return;let t=e.target;this.scrollTop=t.scrollTop,this.renderNodes()}getFlatNodes(){return[...this.flatNodes]}getVisibleNodeCount(){return this.getVisibleNodes().length}getTotalNodeCount(){return this.flatNodes.length}};var de=class{constructor(e){this.head=0;this.count=0;this.capacity=e,this.buffer=new Array(e).fill(void 0)}push(e){let t=(this.head+this.count)%this.capacity;this.buffer[t]=e,this.count<this.capacity?this.count++:this.head=(this.head+1)%this.capacity}getAll(){let e=[];for(let t=0;t<this.count;t++){let n=this.buffer[(this.head+t)%this.capacity];n!==void 0&&e.push(n)}return e}get size(){return this.count}get isEmpty(){return this.count===0}clear(){this.buffer.fill(void 0),this.head=0,this.count=0}},qe=100,je=1024,Je=.7,Ve=5,ce=class{constructor(e){this.counter=0;var t,n,r,o;this.config={bufferSize:(t=e==null?void 0:e.bufferSize)!=null?t:qe,leakGrowthThreshold:(n=e==null?void 0:e.leakGrowthThreshold)!=null?n:je,leakRSquaredThreshold:(r=e==null?void 0:e.leakRSquaredThreshold)!=null?r:Je,leakMinSnapshots:(o=e==null?void 0:e.leakMinSnapshots)!=null?o:Ve},this.snapshots=new de(this.config.bufferSize)}trackMemoryUsage(e,t,n,r){if(e===void 0){let s=performance.memory;s&&(e=s.usedJSHeapSize,t=s.totalJSHeapSize,n=s.jsHeapSizeLimit)}if(e===void 0)return null;let o={timestamp:r!=null?r:Date.now(),usedJSHeapSize:e,totalJSHeapSize:t!=null?t:0,jsHeapSizeLimit:n!=null?n:0,index:this.counter++};return this.snapshots.push(o),o}getMemoryTrend(){let e=this.snapshots.getAll();return e.length===0?[]:e.map((t,n)=>{let r=n>0?e[n-1]:null,o=r?t.usedJSHeapSize-r.usedJSHeapSize:0,s=t.jsHeapSizeLimit>0?t.usedJSHeapSize/t.jsHeapSizeLimit*100:0;return{timestamp:t.timestamp,usedJSHeapSize:t.usedJSHeapSize,delta:o,usagePercent:s}})}detectMemoryLeak(){let e=this.snapshots.getAll();if(e.length<this.config.leakMinSnapshots)return{hasLeak:!1,severity:"none",description:`\u5FEB\u7167\u6570\u91CF\u4E0D\u8DB3\uFF08\u9700\u8981\u81F3\u5C11 ${this.config.leakMinSnapshots} \u4E2A\uFF0C\u5F53\u524D ${e.length} \u4E2A\uFF09`,snapshotCount:e.length,growthRate:0,rSquared:0};let t=e.length,n=0,r=0,o=0,s=0,l=0;for(let g=0;g<t;g++){let b=g,T=e[g].usedJSHeapSize;n+=b,r+=T,o+=b*T,s+=b*b,l+=T*T}let d=t*s-n*n,p=d!==0?(t*o-n*r)/d:0,a=r/t,c=0,u=0;for(let g=0;g<t;g++){let b=e[g].usedJSHeapSize,T=p*g+(r-p*n)/t;c+=(b-a)*(b-a),u+=(b-T)*(b-T)}let h=c!==0?1-u/c:0,f=(e[t-1].timestamp-e[0].timestamp)/1e3,m=f>0?p/f:0,x=h>=this.config.leakRSquaredThreshold&&m>=this.config.leakGrowthThreshold,v="none",y="\u672A\u68C0\u6D4B\u5230\u5185\u5B58\u6CC4\u6F0F";return x&&(m>=this.config.leakGrowthThreshold*10?(v="high",y=`\u68C0\u6D4B\u5230\u4E25\u91CD\u5185\u5B58\u6CC4\u6F0F\uFF0C\u589E\u957F\u901F\u7387 ${Math.round(m)} bytes/s\uFF0CR\xB2=${h.toFixed(3)}`):m>=this.config.leakGrowthThreshold*3?(v="medium",y=`\u68C0\u6D4B\u5230\u4E2D\u7B49\u5185\u5B58\u6CC4\u6F0F\uFF0C\u589E\u957F\u901F\u7387 ${Math.round(m)} bytes/s\uFF0CR\xB2=${h.toFixed(3)}`):(v="low",y=`\u68C0\u6D4B\u5230\u8F7B\u5FAE\u5185\u5B58\u6CC4\u6F0F\uFF0C\u589E\u957F\u901F\u7387 ${Math.round(m)} bytes/s\uFF0CR\xB2=${h.toFixed(3)}`)),{hasLeak:x,severity:v,description:y,snapshotCount:t,growthRate:m,rSquared:h}}getMemoryReport(){let e=this.snapshots.getAll(),t=this.getMemoryTrend(),n=this.detectMemoryLeak(),r=null,o=0,s=0,l=0,d=1/0;for(let c of e)(!r||c.timestamp>r.timestamp)&&(r=c),c.usedJSHeapSize>o&&(o=c.usedJSHeapSize,s=c.timestamp),l+=c.usedJSHeapSize,c.usedJSHeapSize<d&&(d=c.usedJSHeapSize);let p=e.length>0?l/e.length:0;d===1/0&&(d=0);let a=e.length>=2?e[e.length-1].usedJSHeapSize-e[0].usedJSHeapSize:0;return{generatedAt:Date.now(),current:r,peakUsage:o,peakTimestamp:s,averageUsage:p,minUsage:d,totalGrowth:a,trend:t,leakDetection:n,snapshotCount:e.length}}getSnapshots(){return this.snapshots.getAll()}getSnapshotCount(){return this.snapshots.size}clear(){this.snapshots.clear(),this.counter=0}destroy(){this.clear()}};var pe=class{constructor(e){this.head=0;this.count=0;this.capacity=e,this.buffer=new Array(e).fill(void 0)}push(e){let t=(this.head+this.count)%this.capacity;this.buffer[t]=e,this.count<this.capacity?this.count++:this.head=(this.head+1)%this.capacity}getAll(){let e=[];for(let t=0;t<this.count;t++){let n=this.buffer[(this.head+t)%this.capacity];n!==void 0&&e.push(n)}return e}get size(){return this.count}get isEmpty(){return this.count===0}clear(){this.buffer.fill(void 0),this.head=0,this.count=0}},We=200,Ye=16,ue=class{constructor(e){this.counter=0;var t,n;this.config={bufferSize:(t=e==null?void 0:e.bufferSize)!=null?t:We,slowThreshold:(n=e==null?void 0:e.slowThreshold)!=null?n:Ye},this.records=new pe(this.config.bufferSize)}trackRender(e,t){this.records.push({componentName:e,duration:t,timestamp:Date.now(),index:this.counter++})}getSlowRenderers(e){let t=e!=null?e:this.config.slowThreshold;return this.records.getAll().filter(r=>r.duration>t).map(r=>({componentName:r.componentName,duration:r.duration,timestamp:r.timestamp,overThreshold:r.duration-t})).sort((r,o)=>o.duration-r.duration)}getRenderStats(){let e=this.records.getAll(),t=this.config.slowThreshold;if(e.length===0)return{totalRenders:0,totalDuration:0,avgDuration:0,maxDuration:0,minDuration:0,slowRenderCount:0,slowRenderRatio:0,byComponent:[]};let n=0,r=-1/0,o=1/0,s=0,l=new Map;for(let p of e){n+=p.duration,p.duration>r&&(r=p.duration),p.duration<o&&(o=p.duration),p.duration>t&&s++;let a=l.get(p.componentName);a||(a={renderCount:0,totalDuration:0,maxDuration:-1/0,minDuration:1/0,slowCount:0},l.set(p.componentName,a)),a.renderCount++,a.totalDuration+=p.duration,p.duration>a.maxDuration&&(a.maxDuration=p.duration),p.duration<a.minDuration&&(a.minDuration=p.duration),p.duration>t&&a.slowCount++}let d=Array.from(l.entries()).map(([p,a])=>({componentName:p,renderCount:a.renderCount,avgDuration:a.totalDuration/a.renderCount,maxDuration:a.maxDuration===-1/0?0:a.maxDuration,minDuration:a.minDuration===1/0?0:a.minDuration,totalDuration:a.totalDuration,slowCount:a.slowCount})).sort((p,a)=>a.avgDuration-p.avgDuration);return{totalRenders:e.length,totalDuration:n,avgDuration:n/e.length,maxDuration:r===-1/0?0:r,minDuration:o===1/0?0:o,slowRenderCount:s,slowRenderRatio:s/e.length,byComponent:d}}getRenderTimeline(){let e=this.records.getAll(),t=this.config.slowThreshold;return e.map((n,r)=>({componentName:n.componentName,duration:n.duration,timestamp:n.timestamp,isSlow:n.duration>t,gap:r>0?n.timestamp-e[r-1].timestamp:-1}))}getRecords(){return this.records.getAll()}getRecordCount(){return this.records.size}clear(){this.records.clear(),this.counter=0}destroy(){this.clear()}};var he=class{constructor(e){this.head=0;this.count=0;this.capacity=e,this.buffer=new Array(e).fill(void 0)}push(e){let t=(this.head+this.count)%this.capacity;this.buffer[t]=e,this.count<this.capacity?this.count++:this.head=(this.head+1)%this.capacity}getAll(){let e=[];for(let t=0;t<this.count;t++){let n=this.buffer[(this.head+t)%this.capacity];n!==void 0&&e.push(n)}return e}get size(){return this.count}get isEmpty(){return this.count===0}clear(){this.buffer.fill(void 0),this.head=0,this.count=0}},Ke=100,Xe=1e3,Ge=2,me=class{constructor(e){this.pending=new Map;this.counter=0;var t,n,r;this.config={bufferSize:(t=e==null?void 0:e.bufferSize)!=null?t:Ke,slowThreshold:(n=e==null?void 0:e.slowThreshold)!=null?n:Xe,outlierSigmaThreshold:(r=e==null?void 0:e.outlierSigmaThreshold)!=null?r:Ge},this.records=new he(this.config.bufferSize)}startBatch(e){return this.pending.has(e)?!1:(this.pending.set(e,Date.now()),!0)}endBatch(e){let t=this.pending.get(e);if(t===void 0)return null;let n=Date.now(),r=n-t;this.pending.delete(e);let o={name:e,startTime:t,endTime:n,duration:r,index:this.counter++};return this.records.push(o),o}getBatchStats(){let e=this.records.getAll();if(e.length===0)return{totalBatches:0,totalDuration:0,avgDuration:0,maxDuration:0,minDuration:0,byName:[]};let t=0,n=-1/0,r=1/0,o=new Map;for(let l of e){t+=l.duration,l.duration>n&&(n=l.duration),l.duration<r&&(r=l.duration);let d=o.get(l.name);d||(d={count:0,totalDuration:0,maxDuration:-1/0,minDuration:1/0,durations:[]},o.set(l.name,d)),d.count++,d.totalDuration+=l.duration,l.duration>d.maxDuration&&(d.maxDuration=l.duration),l.duration<d.minDuration&&(d.minDuration=l.duration),d.durations.push(l.duration)}let s=Array.from(o.entries()).map(([l,d])=>{let p=d.totalDuration/d.count,a=0;for(let u of d.durations)a+=(u-p)*(u-p);a/=d.count;let c=Math.sqrt(a);return{name:l,count:d.count,avgDuration:p,maxDuration:d.maxDuration===-1/0?0:d.maxDuration,minDuration:d.minDuration===1/0?0:d.minDuration,totalDuration:d.totalDuration,stdDev:c}});return{totalBatches:e.length,totalDuration:t,avgDuration:t/e.length,maxDuration:n===-1/0?0:n,minDuration:r===1/0?0:r,byName:s}}detectAnomalousBatches(){let e=this.records.getAll();if(e.length===0)return[];let t=this.getBatchStats(),n=[],r=new Map;for(let o of t.byName)r.set(o.name,o);for(let o of e){let s=r.get(o.name);if(o.duration>this.config.slowThreshold){n.push({name:o.name,duration:o.duration,timestamp:o.endTime,anomalyType:"slow",description:`\u64CD\u4F5C "${o.name}" \u8017\u65F6 ${o.duration.toFixed(1)}ms\uFF0C\u8D85\u8FC7\u6162\u64CD\u4F5C\u9608\u503C ${this.config.slowThreshold}ms`,deviationSigma:s&&s.stdDev>0?(o.duration-s.avgDuration)/s.stdDev:0});continue}if(s&&s.count>=2&&s.stdDev>0){let l=(o.duration-s.avgDuration)/s.stdDev;if(Math.abs(l)>this.config.outlierSigmaThreshold){let d=l>0?"slow":"fast";n.push({name:o.name,duration:o.duration,timestamp:o.endTime,anomalyType:d,description:`\u64CD\u4F5C "${o.name}" \u8017\u65F6 ${o.duration.toFixed(1)}ms\uFF0C\u504F\u79BB\u5E73\u5747\u503C ${l.toFixed(1)} \u4E2A\u6807\u51C6\u5DEE`,deviationSigma:l})}}}return n.sort((o,s)=>o.timestamp-s.timestamp),n}getRecords(){return this.records.getAll()}getRecordCount(){return this.records.size}getPendingBatches(){return Array.from(this.pending.keys())}clear(){this.records.clear(),this.pending.clear(),this.counter=0}destroy(){this.clear()}};var fe=class{constructor(e){this._installed=!1;this.app=null;var t,n,r,o,s,l;this.config={width:(t=e==null?void 0:e.width)!=null?t:420,height:(n=e==null?void 0:e.height)!=null?n:560,x:(r=e==null?void 0:e.x)!=null?r:void 0,y:(o=e==null?void 0:e.y)!=null?o:void 0,autoShow:(s=e==null?void 0:e.autoShow)!=null?s:!0,title:(l=e==null?void 0:e.title)!=null?l:"Lyt DevTools"},this.panel=new D({width:this.config.width,height:this.config.height,x:this.config.x,y:this.config.y,title:this.config.title}),this.componentTree=new N(this.panel,d=>{this.panel.switchTab("state"),this.stateInspector.refresh()}),this.stateInspector=new z(this.panel),this.eventTracker=new $(this.panel),this.timeTravel=new B(this.panel),this.panel.registerTabRenderer("components",d=>{this.componentTree.render(d)}),this.panel.registerTabRenderer("state",d=>{this.stateInspector.render(d)}),this.panel.registerTabRenderer("events",d=>{this.eventTracker.render(d)}),this.panel.registerTabRenderer("router",d=>{this.renderRouterTab(d)}),this.panel.renderContent(),this.config.autoShow||this.panel.hide()}install(e){if(this._installed){console.warn("[Lyt DevTools] DevTools \u5DF2\u7ECF\u5B89\u88C5\uFF0C\u4E0D\u80FD\u91CD\u590D\u5B89\u88C5\u3002");return}this.app=e,this._installed=!0,J(e,{onComponentCreated:n=>{this.componentTree.refresh()},onComponentUpdated:n=>{this.componentTree.refresh(),this.stateInspector.refresh()},onComponentUnmounted:n=>{this.componentTree.refresh()},onStateChanged:n=>{this.stateInspector.markChanged(`state.${n.path}`),this.stateInspector.refresh()},onEventEmitted:n=>{this.eventTracker.refresh()}}),this.panel.setConnected(!0),console.log("[Lyt DevTools] \u5DF2\u5B89\u88C5\u5230\u5E94\u7528\u3002\u6309 Ctrl+Shift+D \u5207\u6362\u9762\u677F\u663E\u793A\u3002")}show(){this.panel.show()}hide(){this.panel.hide()}toggle(){this.panel.toggle()}isVisible(){return this.panel.isVisible()}renderRouterTab(e){e.innerHTML="";let t=document.createElement("div");t.className="lyt-devtools-empty",t.style.cssText="padding: 40px 24px;",t.innerHTML=`
611
+ `;let l=document.createElement("span");l.style.cssText="display: inline-block; width: 14px; text-align: center; margin-right: 4px; font-size: 10px; color: #585b70;",s?l.textContent=e.expanded?"\u25BC":"\u25B6":l.textContent="\xB7",n.appendChild(l);let d=document.createElement("span");if(d.textContent=e.node.name,d.style.cssText="font-weight: bold;",n.appendChild(d),e.node.stateSummary){let c=document.createElement("span");c.textContent=` ${e.node.stateSummary}`,c.style.cssText="color: #a6adc8; font-size: 10px; margin-left: 6px;",n.appendChild(c)}if(e.node.propsCount!==void 0&&e.node.propsCount>0){let c=document.createElement("span");c.textContent=` [${e.node.propsCount} props]`,c.style.cssText="color: #585b70; font-size: 10px; margin-left: 4px;",n.appendChild(c)}let p=e.node,a=p.id;return n.addEventListener("click",()=>{var c;if(s){let u=(c=this.expandedMap.get(a))!=null?c:!1;this.expandedMap.set(a,!u),this.flatten(),this.renderNodes()}this.selectedId=a,this.onNodeClick&&this.onNodeClick(p)}),n}handleScroll(e){if(this.destroyed)return;let t=e.target;this.scrollTop=t.scrollTop,this.renderNodes()}getFlatNodes(){return[...this.flatNodes]}getVisibleNodeCount(){return this.getVisibleNodes().length}getTotalNodeCount(){return this.flatNodes.length}};var de=class{constructor(e){this.head=0;this.count=0;this.capacity=e,this.buffer=new Array(e).fill(void 0)}push(e){let t=(this.head+this.count)%this.capacity;this.buffer[t]=e,this.count<this.capacity?this.count++:this.head=(this.head+1)%this.capacity}getAll(){let e=[];for(let t=0;t<this.count;t++){let n=this.buffer[(this.head+t)%this.capacity];n!==void 0&&e.push(n)}return e}get size(){return this.count}get isEmpty(){return this.count===0}clear(){this.buffer.fill(void 0),this.head=0,this.count=0}},qe=100,je=1024,Je=.7,Ve=5,ce=class{constructor(e){this.counter=0;var t,n,r,o;this.config={bufferSize:(t=e==null?void 0:e.bufferSize)!=null?t:qe,leakGrowthThreshold:(n=e==null?void 0:e.leakGrowthThreshold)!=null?n:je,leakRSquaredThreshold:(r=e==null?void 0:e.leakRSquaredThreshold)!=null?r:Je,leakMinSnapshots:(o=e==null?void 0:e.leakMinSnapshots)!=null?o:Ve},this.snapshots=new de(this.config.bufferSize)}trackMemoryUsage(e,t,n,r){if(e===void 0){let s=performance.memory;s&&(e=s.usedJSHeapSize,t=s.totalJSHeapSize,n=s.jsHeapSizeLimit)}if(e===void 0)return null;let o={timestamp:r!=null?r:Date.now(),usedJSHeapSize:e,totalJSHeapSize:t!=null?t:0,jsHeapSizeLimit:n!=null?n:0,index:this.counter++};return this.snapshots.push(o),o}getMemoryTrend(){let e=this.snapshots.getAll();return e.length===0?[]:e.map((t,n)=>{let r=n>0?e[n-1]:null,o=r?t.usedJSHeapSize-r.usedJSHeapSize:0,s=t.jsHeapSizeLimit>0?t.usedJSHeapSize/t.jsHeapSizeLimit*100:0;return{timestamp:t.timestamp,usedJSHeapSize:t.usedJSHeapSize,delta:o,usagePercent:s}})}detectMemoryLeak(){let e=this.snapshots.getAll();if(e.length<this.config.leakMinSnapshots)return{hasLeak:!1,severity:"none",description:`\u5FEB\u7167\u6570\u91CF\u4E0D\u8DB3\uFF08\u9700\u8981\u81F3\u5C11 ${this.config.leakMinSnapshots} \u4E2A\uFF0C\u5F53\u524D ${e.length} \u4E2A\uFF09`,snapshotCount:e.length,growthRate:0,rSquared:0};let t=e.length,n=0,r=0,o=0,s=0,l=0;for(let g=0;g<t;g++){let b=g,T=e[g].usedJSHeapSize;n+=b,r+=T,o+=b*T,s+=b*b,l+=T*T}let d=t*s-n*n,p=d!==0?(t*o-n*r)/d:0,a=r/t,c=0,u=0;for(let g=0;g<t;g++){let b=e[g].usedJSHeapSize,T=p*g+(r-p*n)/t;c+=(b-a)*(b-a),u+=(b-T)*(b-T)}let h=c!==0?1-u/c:0,f=(e[t-1].timestamp-e[0].timestamp)/1e3,m=f>0?p/f:0,x=h>=this.config.leakRSquaredThreshold&&m>=this.config.leakGrowthThreshold,v="none",y="\u672A\u68C0\u6D4B\u5230\u5185\u5B58\u6CC4\u6F0F";return x&&(m>=this.config.leakGrowthThreshold*10?(v="high",y=`\u68C0\u6D4B\u5230\u4E25\u91CD\u5185\u5B58\u6CC4\u6F0F\uFF0C\u589E\u957F\u901F\u7387 ${Math.round(m)} bytes/s\uFF0CR\xB2=${h.toFixed(3)}`):m>=this.config.leakGrowthThreshold*3?(v="medium",y=`\u68C0\u6D4B\u5230\u4E2D\u7B49\u5185\u5B58\u6CC4\u6F0F\uFF0C\u589E\u957F\u901F\u7387 ${Math.round(m)} bytes/s\uFF0CR\xB2=${h.toFixed(3)}`):(v="low",y=`\u68C0\u6D4B\u5230\u8F7B\u5FAE\u5185\u5B58\u6CC4\u6F0F\uFF0C\u589E\u957F\u901F\u7387 ${Math.round(m)} bytes/s\uFF0CR\xB2=${h.toFixed(3)}`)),{hasLeak:x,severity:v,description:y,snapshotCount:t,growthRate:m,rSquared:h}}getMemoryReport(){let e=this.snapshots.getAll(),t=this.getMemoryTrend(),n=this.detectMemoryLeak(),r=null,o=0,s=0,l=0,d=1/0;for(let c of e)(!r||c.timestamp>r.timestamp)&&(r=c),c.usedJSHeapSize>o&&(o=c.usedJSHeapSize,s=c.timestamp),l+=c.usedJSHeapSize,c.usedJSHeapSize<d&&(d=c.usedJSHeapSize);let p=e.length>0?l/e.length:0;d===1/0&&(d=0);let a=e.length>=2?e[e.length-1].usedJSHeapSize-e[0].usedJSHeapSize:0;return{generatedAt:Date.now(),current:r,peakUsage:o,peakTimestamp:s,averageUsage:p,minUsage:d,totalGrowth:a,trend:t,leakDetection:n,snapshotCount:e.length}}getSnapshots(){return this.snapshots.getAll()}getSnapshotCount(){return this.snapshots.size}clear(){this.snapshots.clear(),this.counter=0}destroy(){this.clear()}};var pe=class{constructor(e){this.head=0;this.count=0;this.capacity=e,this.buffer=new Array(e).fill(void 0)}push(e){let t=(this.head+this.count)%this.capacity;this.buffer[t]=e,this.count<this.capacity?this.count++:this.head=(this.head+1)%this.capacity}getAll(){let e=[];for(let t=0;t<this.count;t++){let n=this.buffer[(this.head+t)%this.capacity];n!==void 0&&e.push(n)}return e}get size(){return this.count}get isEmpty(){return this.count===0}clear(){this.buffer.fill(void 0),this.head=0,this.count=0}},We=200,Ye=16,ue=class{constructor(e){this.counter=0;var t,n;this.config={bufferSize:(t=e==null?void 0:e.bufferSize)!=null?t:We,slowThreshold:(n=e==null?void 0:e.slowThreshold)!=null?n:Ye},this.records=new pe(this.config.bufferSize)}trackRender(e,t){this.records.push({componentName:e,duration:t,timestamp:Date.now(),index:this.counter++})}getSlowRenderers(e){let t=e!=null?e:this.config.slowThreshold;return this.records.getAll().filter(r=>r.duration>t).map(r=>({componentName:r.componentName,duration:r.duration,timestamp:r.timestamp,overThreshold:r.duration-t})).sort((r,o)=>o.duration-r.duration)}getRenderStats(){let e=this.records.getAll(),t=this.config.slowThreshold;if(e.length===0)return{totalRenders:0,totalDuration:0,avgDuration:0,maxDuration:0,minDuration:0,slowRenderCount:0,slowRenderRatio:0,byComponent:[]};let n=0,r=-1/0,o=1/0,s=0,l=new Map;for(let p of e){n+=p.duration,p.duration>r&&(r=p.duration),p.duration<o&&(o=p.duration),p.duration>t&&s++;let a=l.get(p.componentName);a||(a={renderCount:0,totalDuration:0,maxDuration:-1/0,minDuration:1/0,slowCount:0},l.set(p.componentName,a)),a.renderCount++,a.totalDuration+=p.duration,p.duration>a.maxDuration&&(a.maxDuration=p.duration),p.duration<a.minDuration&&(a.minDuration=p.duration),p.duration>t&&a.slowCount++}let d=Array.from(l.entries()).map(([p,a])=>({componentName:p,renderCount:a.renderCount,avgDuration:a.totalDuration/a.renderCount,maxDuration:a.maxDuration===-1/0?0:a.maxDuration,minDuration:a.minDuration===1/0?0:a.minDuration,totalDuration:a.totalDuration,slowCount:a.slowCount})).sort((p,a)=>a.avgDuration-p.avgDuration);return{totalRenders:e.length,totalDuration:n,avgDuration:n/e.length,maxDuration:r===-1/0?0:r,minDuration:o===1/0?0:o,slowRenderCount:s,slowRenderRatio:s/e.length,byComponent:d}}getRenderTimeline(){let e=this.records.getAll(),t=this.config.slowThreshold;return e.map((n,r)=>({componentName:n.componentName,duration:n.duration,timestamp:n.timestamp,isSlow:n.duration>t,gap:r>0?n.timestamp-e[r-1].timestamp:-1}))}getRecords(){return this.records.getAll()}getRecordCount(){return this.records.size}clear(){this.records.clear(),this.counter=0}destroy(){this.clear()}};var he=class{constructor(e){this.head=0;this.count=0;this.capacity=e,this.buffer=new Array(e).fill(void 0)}push(e){let t=(this.head+this.count)%this.capacity;this.buffer[t]=e,this.count<this.capacity?this.count++:this.head=(this.head+1)%this.capacity}getAll(){let e=[];for(let t=0;t<this.count;t++){let n=this.buffer[(this.head+t)%this.capacity];n!==void 0&&e.push(n)}return e}get size(){return this.count}get isEmpty(){return this.count===0}clear(){this.buffer.fill(void 0),this.head=0,this.count=0}},Ke=100,Xe=1e3,Ge=2,me=class{constructor(e){this.pending=new Map;this.counter=0;var t,n,r;this.config={bufferSize:(t=e==null?void 0:e.bufferSize)!=null?t:Ke,slowThreshold:(n=e==null?void 0:e.slowThreshold)!=null?n:Xe,outlierSigmaThreshold:(r=e==null?void 0:e.outlierSigmaThreshold)!=null?r:Ge},this.records=new he(this.config.bufferSize)}startBatch(e){return this.pending.has(e)?!1:(this.pending.set(e,Date.now()),!0)}endBatch(e){let t=this.pending.get(e);if(t===void 0)return null;let n=Date.now(),r=n-t;this.pending.delete(e);let o={name:e,startTime:t,endTime:n,duration:r,index:this.counter++};return this.records.push(o),o}getBatchStats(){let e=this.records.getAll();if(e.length===0)return{totalBatches:0,totalDuration:0,avgDuration:0,maxDuration:0,minDuration:0,byName:[]};let t=0,n=-1/0,r=1/0,o=new Map;for(let l of e){t+=l.duration,l.duration>n&&(n=l.duration),l.duration<r&&(r=l.duration);let d=o.get(l.name);d||(d={count:0,totalDuration:0,maxDuration:-1/0,minDuration:1/0,durations:[]},o.set(l.name,d)),d.count++,d.totalDuration+=l.duration,l.duration>d.maxDuration&&(d.maxDuration=l.duration),l.duration<d.minDuration&&(d.minDuration=l.duration),d.durations.push(l.duration)}let s=Array.from(o.entries()).map(([l,d])=>{let p=d.totalDuration/d.count,a=0;for(let u of d.durations)a+=(u-p)*(u-p);a/=d.count;let c=Math.sqrt(a);return{name:l,count:d.count,avgDuration:p,maxDuration:d.maxDuration===-1/0?0:d.maxDuration,minDuration:d.minDuration===1/0?0:d.minDuration,totalDuration:d.totalDuration,stdDev:c}});return{totalBatches:e.length,totalDuration:t,avgDuration:t/e.length,maxDuration:n===-1/0?0:n,minDuration:r===1/0?0:r,byName:s}}detectAnomalousBatches(){let e=this.records.getAll();if(e.length===0)return[];let t=this.getBatchStats(),n=[],r=new Map;for(let o of t.byName)r.set(o.name,o);for(let o of e){let s=r.get(o.name);if(o.duration>this.config.slowThreshold){n.push({name:o.name,duration:o.duration,timestamp:o.endTime,anomalyType:"slow",description:`\u64CD\u4F5C "${o.name}" \u8017\u65F6 ${o.duration.toFixed(1)}ms\uFF0C\u8D85\u8FC7\u6162\u64CD\u4F5C\u9608\u503C ${this.config.slowThreshold}ms`,deviationSigma:s&&s.stdDev>0?(o.duration-s.avgDuration)/s.stdDev:0});continue}if(s&&s.count>=2&&s.stdDev>0){let l=(o.duration-s.avgDuration)/s.stdDev;if(Math.abs(l)>this.config.outlierSigmaThreshold){let d=l>0?"slow":"fast";n.push({name:o.name,duration:o.duration,timestamp:o.endTime,anomalyType:d,description:`\u64CD\u4F5C "${o.name}" \u8017\u65F6 ${o.duration.toFixed(1)}ms\uFF0C\u504F\u79BB\u5E73\u5747\u503C ${l.toFixed(1)} \u4E2A\u6807\u51C6\u5DEE`,deviationSigma:l})}}}return n.sort((o,s)=>o.timestamp-s.timestamp),n}getRecords(){return this.records.getAll()}getRecordCount(){return this.records.size}getPendingBatches(){return Array.from(this.pending.keys())}clear(){this.records.clear(),this.pending.clear(),this.counter=0}destroy(){this.clear()}};var fe=class{constructor(e){this._installed=!1;this.app=null;var t,n,r,o,s,l;this.config={width:(t=e==null?void 0:e.width)!=null?t:420,height:(n=e==null?void 0:e.height)!=null?n:560,x:(r=e==null?void 0:e.x)!=null?r:void 0,y:(o=e==null?void 0:e.y)!=null?o:void 0,autoShow:(s=e==null?void 0:e.autoShow)!=null?s:!0,title:(l=e==null?void 0:e.title)!=null?l:"Lyt DevTools"},this.panel=new D({width:this.config.width,height:this.config.height,x:this.config.x,y:this.config.y,title:this.config.title}),this.componentTree=new N(this.panel,d=>{this.panel.switchTab("state"),this.stateInspector.refresh()}),this.stateInspector=new z(this.panel),this.eventTracker=new $(this.panel),this.timeTravel=new B(this.panel),this.panel.registerTabRenderer("components",d=>{this.componentTree.render(d)}),this.panel.registerTabRenderer("state",d=>{this.stateInspector.render(d)}),this.panel.registerTabRenderer("events",d=>{this.eventTracker.render(d)}),this.panel.registerTabRenderer("router",d=>{this.renderRouterTab(d)}),this.panel.renderContent(),this.config.autoShow||this.panel.hide()}install(e){if(this._installed)return;this.app=e,this._installed=!0,J(e,{onComponentCreated:n=>{this.componentTree.refresh()},onComponentUpdated:n=>{this.componentTree.refresh(),this.stateInspector.refresh()},onComponentUnmounted:n=>{this.componentTree.refresh()},onStateChanged:n=>{this.stateInspector.markChanged(`state.${n.path}`),this.stateInspector.refresh()},onEventEmitted:n=>{this.eventTracker.refresh()}}),this.panel.setConnected(!0)}show(){this.panel.show()}hide(){this.panel.hide()}toggle(){this.panel.toggle()}isVisible(){return this.panel.isVisible()}renderRouterTab(e){e.innerHTML="";let t=document.createElement("div");t.className="lyt-devtools-empty",t.style.cssText="padding: 40px 24px;",t.innerHTML=`
612
612
  <div style="font-size: 32px; margin-bottom: 12px;">\u{1F517}</div>
613
613
  <div style="color: #cdd6f4; font-size: 14px; margin-bottom: 8px; font-style: normal;">\u8DEF\u7531\u68C0\u67E5\u5668</div>
614
614
  <div style="color: #585b70; font-size: 12px;">
@@ -616,4 +616,4 @@ var Ce=`
616
616
  \u8DEF\u7531\u68C0\u67E5\u5668\u5C06\u663E\u793A\u5F53\u524D\u8DEF\u7531\u4FE1\u606F\u3001<br>
617
617
  \u8DEF\u7531\u5B88\u536B\u548C\u5BFC\u822A\u5386\u53F2\u3002
618
618
  </div>
619
- `,e.appendChild(t)}refreshTree(){this.app&&ee(this.app),this.componentTree.refresh()}clearAllRecords(){te(),this.eventTracker.refresh(),this.stateInspector.refresh()}getPanel(){return this.panel}getComponentTree(){return this.componentTree}getStateInspector(){return this.stateInspector}getEventTracker(){return this.eventTracker}getTimeTravel(){return this.timeTravel}destroy(){this.componentTree.destroy(),this.stateInspector.destroy(),this.eventTracker.destroy(),this.timeTravel.destroy(),this.panel.destroy(),ne(),this._installed=!1,this.app=null,console.log("[Lyt DevTools] \u5DF2\u9500\u6BC1\u3002")}};function Dt(i){let e=null;return{install(t){if(e){console.warn("[Lyt DevTools] \u5DF2\u7ECF\u521B\u5EFA\uFF0C\u4E0D\u80FD\u91CD\u590D\u5B89\u88C5\u3002");return}e=new fe(i),t.globalProperties&&(t.globalProperties.__LYT_DEVTOOLS__=e);let n=t;(n._instance!==void 0||n.mount)&&e.install(n)}}}export{me as BatchAnalyzer,F as ComponentProfiler,N as ComponentTreeInspector,fe as DevTools,D as DevToolsPanel,ie as EventPanel,$ as EventTracker,ce as MemoryTracker,se as PerfPanel,A as PerformanceCollector,ue as RenderTracker,oe as RoutePanel,ae as RouterPanel,z as StateInspector,B as TimeTravelDebugger,le as VirtualComponentTree,te as clearRecords,J as connectToApp,Dt as createDevTools,ne as disconnect,L as getAllComponents,Y as getChildComponents,I as getComponentById,$e as getComponentCount,Ne as getComponentEvents,X as getComponentStateChanges,K as getEventRecords,W as getRootComponent,Q as getSelectedComponent,P as getSelectedComponentId,Ie as getStateChangeRecords,ze as isAppConnected,ee as refreshComponentTree,G as selectComponent,Z as setComponentState};
619
+ `,e.appendChild(t)}refreshTree(){this.app&&ee(this.app),this.componentTree.refresh()}clearAllRecords(){te(),this.eventTracker.refresh(),this.stateInspector.refresh()}getPanel(){return this.panel}getComponentTree(){return this.componentTree}getStateInspector(){return this.stateInspector}getEventTracker(){return this.eventTracker}getTimeTravel(){return this.timeTravel}destroy(){this.componentTree.destroy(),this.stateInspector.destroy(),this.eventTracker.destroy(),this.timeTravel.destroy(),this.panel.destroy(),ne(),this._installed=!1,this.app=null}};function Dt(i){let e=null;return{install(t){if(e)return;e=new fe(i),t.globalProperties&&(t.globalProperties.__LYT_DEVTOOLS__=e);let n=t;(n._instance!==void 0||n.mount)&&e.install(n)}}}export{me as BatchAnalyzer,F as ComponentProfiler,N as ComponentTreeInspector,fe as DevTools,D as DevToolsPanel,ie as EventPanel,$ as EventTracker,ce as MemoryTracker,se as PerfPanel,A as PerformanceCollector,ue as RenderTracker,oe as RoutePanel,ae as RouterPanel,z as StateInspector,B as TimeTravelDebugger,le as VirtualComponentTree,te as clearRecords,J as connectToApp,Dt as createDevTools,ne as disconnect,L as getAllComponents,Y as getChildComponents,I as getComponentById,$e as getComponentCount,Ne as getComponentEvents,X as getComponentStateChanges,K as getEventRecords,W as getRootComponent,Q as getSelectedComponent,P as getSelectedComponentId,Ie as getStateChangeRecords,ze as isAppConnected,ee as refreshComponentTree,G as selectComponent,Z as setComponentState};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lytjs/devtools",
3
- "version": "3.1.0",
3
+ "version": "4.0.0",
4
4
  "description": "Lyt.js 浏览器开发者工具 - 提供组件树检查、状态查看、性能分析和时间旅行调试",
5
5
  "main": "./dist/index.mjs",
6
6
  "module": "./dist/index.mjs",
@@ -17,9 +17,9 @@
17
17
  "author": "lytjs",
18
18
  "repository": {
19
19
  "type": "git",
20
- "url": "https://gitee.com/@lytjs/lytjs"
20
+ "url": "https://gitee.com/lytjs/lytjs"
21
21
  },
22
- "homepage": "https://gitee.com/@lytjs/lytjs",
22
+ "homepage": "https://gitee.com/lytjs/lytjs",
23
23
  "keywords": [
24
24
  "lyt",
25
25
  "lytjs",