UNPKG

mincu-debug-tools

Version:

[Mincu - 南大家园 WEB JS API](https://github.com/ncuhome/mincu)

2 lines (1 loc) 5.95 kB
var R=Object.defineProperty,P=Object.defineProperties;var V=Object.getOwnPropertyDescriptors;var u=Object.getOwnPropertySymbols;var D=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable;var f=(o,e,t)=>e in o?R(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t,b=(o,e)=>{for(var t in e||(e={}))D.call(e,t)&&f(o,t,e[t]);if(u)for(var t of u(e))E.call(e,t)&&f(o,t,e[t]);return o},x=(o,e)=>P(o,V(e));var T=(o,e)=>{var t={};for(var r in o)D.call(o,r)&&e.indexOf(r)<0&&(t[r]=o[r]);if(o!=null&&u)for(var r of u(o))e.indexOf(r)<0&&E.call(o,r)&&(t[r]=o[r]);return t};var d=(o,e,t)=>(f(o,typeof e!="symbol"?e+"":e,t),t);import{j as k,a as M,u as m,b as O,l as H,c as S,y as C,d as K,S as N}from"./vendor.85cbdb11.js";const G=function(){const e=document.createElement("link").relList;if(e&&e.supports&&e.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))r(n);new MutationObserver(n=>{for(const i of n)if(i.type==="childList")for(const a of i.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&r(a)}).observe(document,{childList:!0,subtree:!0});function t(n){const i={};return n.integrity&&(i.integrity=n.integrity),n.referrerpolicy&&(i.referrerPolicy=n.referrerpolicy),n.crossorigin==="use-credentials"?i.credentials="include":n.crossorigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function r(n){if(n.ep)return;n.ep=!0;const i=t(n);fetch(n.href,i)}};G();const l=k,g=M,L=n=>{var i=n,{children:o,disabled:e,onClick:t}=i,r=T(i,["children","disabled","onClick"]);return l("button",x(b({class:"mt-2 text-gray-700 bg-gray-100 border-0 py-2 px-6 focus:outline-none hover:bg-gray-200 rounded text-lg active:bg-gray-400 disabled:opacity-50",disabled:e,onClick:t},r),{children:o}))},Y="\u8BF7\u6253\u5F00 \u300C\u5357\u5927\u5BB6\u56ED\u300D - \u300C\u751F\u6D3B\u677F\u5757\u300D - \u53F3\u4E0A\u89D2\u300C\u626B\u4E00\u626B\u300D\uFF0C\u626B\u63CF\u4EE5\u4E0A\u4E8C\u7EF4\u7801\uFF0C\u5F00\u59CB\u8C03\u8BD5",q="/api",_="$DEBUG_URL",J=()=>{const o=m("url"),e=localStorage.getItem(_);return o?decodeURIComponent(o):e},z=o=>o.includes("http://localhost")?o:`${q}/fetch?target=${encodeURIComponent(o)}`,Q=async o=>{const t=await(await fetch(z(o))).text();return t.includes("<html")?t:!1},W=o=>new DOMParser().parseFromString(o,"text/html").title,s=typeof window=="undefined"?global:window;var p;const X="CMD_RELOAD",Z="CMD_DEV_TOOL",B=2333,F=((p=s.location)===null||p===void 0?void 0:p.hostname)||"localhost",ee=["trace","info","warn","error","log","group","groupCollapsed","groupEnd","debug"],j=o=>JSON.stringify(o),h=class{constructor(){d(this,"opened",!1);d(this,"bindServerCommand",e=>{var t;const{data:r}=e;switch(r.toString()){case X:(t=s.location)===null||t===void 0||t.reload();break;case Z:this.toggleDevTool();break}})}init(){if(this.client||this.opened)return!0;try{this.client=new O(`ws://${F}:${B}`),this.client&&(this.client.onerror=e=>{console.error(e),this.opened=!1},this.client.onopen=()=>{var e;this.opened=!0,this.log("info",`${(e=s.location)===null||e===void 0?void 0:e.origin} has connected`)},this.client.onmessage=this.bindServerCommand,this.devToolActive()&&this.injectDevTool())}catch(e){return console.error(e),!1}return!0}initByDebugTools(){if(this.client||this.opened)return!0;try{this.client=new O(`ws://${F}:${B}`),this.client.onopen=()=>{var e;this.opened=!0,this.log("info",`DebugTools at ${(e=s.location)===null||e===void 0?void 0:e.origin} has connected`)},this.client.onerror=()=>{this.opened=!1}}catch{return!1}return!0}devToolActive(){return localStorage.getItem(h.KEY_DEV_TOOL)==="true"}toggleDevTool(){const e=this.devToolActive();if(!e)this.injectDevTool();else{var t;(t=s.eruda)===null||t===void 0||t.destroy()}localStorage.setItem(h.KEY_DEV_TOOL,String(!e))}injectDevTool(){const e=document.createElement("script");e.src="//cdn.jsdelivr.net/npm/eruda",document.body.appendChild(e),e.onload=()=>{var t;(t=s.eruda)===null||t===void 0||t.init()}}log(e,...t){if(this.client||this.init(),!!this.opened)try{this.client.send(j({type:"log",level:e,data:H.Encode(t)}))}catch(r){console.error(r)}}command(e,t){return this.opened?(this.client.send(j({type:"command",data:[e,...t]})),!0):!1}};let v=h;d(v,"KEY_DEV_TOOL","DEV_TOOL");class y{static Instance(){return new y}constructor(){this.client=new v}applyConsole(e=!0){this.client.init()&&(ee.forEach(t=>{const r=s.console[t];r&&(s.console[t]=(...n)=>{r(...n),this.client.log(t,...n)})}),e&&(s.addEventListener("error",t=>{this.client.log("error",t)}),s.addEventListener("unhandledrejection",t=>{this.client.log("error",t.reason)})))}applyByDebugTools(){return this.client.initByDebugTools()}command(e,t){return this.client.command(e,t)}}var te=y.Instance();function oe(){const[o,e]=S(""),[t,r]=S(""),n=J(),i=m("origin"),a=m("hint")||Y;C(()=>{n&&localStorage.setItem(_,n)},[]),C(()=>{I(),$()},[n]);const I=async()=>{if(!n)return;const c=await K.toDataURL(n,{width:300,margin:1});e(c)},$=async()=>{if(!n)return;const c=await Q(n);if(c){const U=W(c);r(U)}else r(n.split("/?")[0])},w=c=>{te.command("openUrl",[n,c])},A=t==i?t:[t,i].filter(c=>c&&c.length>0).join(" | ");return l("div",{class:"text-light-600 body-font overflow-hidden bg-dark-900 w-screen h-screen",children:g("div",{class:"container mx-auto flex px-5 py-24 items-center justify-center flex-col",children:[l("h1",{class:"title-font sm:text-2xl text-2xl mb-8 font-medium subpixel-antialiased",children:A}),l("img",{src:o,alt:i||n||"",class:"lg:w-1/4 md:w-3/6 w-4/6 mb-8 object-cover object-center rounded-2xl"}),g("div",{class:"text-center lg:w-2/3 w-full",children:[l("p",{class:"sm:text-1xl text-2xl mb-8 text-gray-300",children:a}),g("div",{class:"flex flex-col items-center",children:[l(L,{onClick:()=>w("android"),children:"\u5728 Android \u4E0A\u6253\u5F00\u9875\u9762"}),l(L,{onClick:()=>w("ios"),children:"\u5728 iOS \u4E0A\u6253\u5F00\u9875\u9762"})]})]})]})})}N(l(oe,{}),document.getElementById("app"));