livecode-static/livecodes/compiler-utils.f13ac14f45040b76eb5fb14fed8360f9.js
2025-06-12 09:37:26 +08:00

2 lines
9.7 KiB
JavaScript

"use strict";(()=>{var p=e=>{function t(s){return typeof HTMLElement=="object"?s instanceof HTMLElement:s&&typeof s=="object"&&s!==null&&s.nodeType===1&&typeof s.nodeName=="string"}function o(s){return typeof Node=="object"?s instanceof Node:s&&typeof s=="object"&&typeof s.nodeType=="number"&&typeof s.nodeName=="string"}function n(s){return s instanceof NodeList}function i(s){return s instanceof HTMLCollection}function a(s){return Object.prototype.toString.call(s)==="[object HTMLDocument]"}function r(s){return Object.prototype.toString.call(s)==="[object Window]"}let c=Object.prototype.toString.call(e);if(e===void 0)return"undefined";if(e===null)return"null";if(r(e))return"window";if(a(e))return"document";if(t(e))return"element";if(o(e))return"node";if(n(e))return"nodelist";if(i(e))return"htmlcollection";if(e.constructor&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e))return"buffer";if(typeof window=="object"&&e===window)return"window";if(typeof global=="object"&&e===global)return"global";if(typeof e=="number"&&isNaN(e)||typeof e=="object"&&c==="[object Number]"&&isNaN(e))return"nan";if(typeof e=="object"&&c.substr(-6)==="Event]")return"event";if(c.substr(0,12)==="[object HTML")return"element";if(c.substr(0,12)==="[object Node")return"node";let y=c.match(/\[object\s*([^\]]+)\]/);return y?y[1].toLowerCase():"object"};function d(e){return e.map(t=>{switch(p(t)){case"window":case"function":case"date":case"symbol":return{type:p(t),content:t.toString()};case"document":return{type:p(t),content:t.documentElement.outerHTML};case"element":return{type:p(t),content:t.outerHTML};case"node":return{type:p(t),content:t.textContent};case"nodelist":case"htmlcollection":return{type:p(t),content:[...t].map(n=>d([n])[0].content)};case"array":return{type:p(t),content:t.map(n=>d([n])[0].content)};case"object":case"event":let o={};for(let n in t)o[n]=t[n];return{type:p(t),content:Object.keys(o).reduce((n,i)=>({...n,[i]:d([o[i]])[0].content}),{})};case"error":return{type:p(t),content:t.constructor.name+": "+t.message}}try{return{type:"other",content:structuredClone(t)}}catch{return{type:"other",content:String(t)}}})}var h=()=>{window.console=new Proxy(console,{get(e,t){return function(...o){if(!(t in e)){let n=`Uncaught TypeError: console.${String(t)} is not a function`;e.error(n),parent.postMessage({type:"console",method:"error",args:d([n])},"*");return}e[t](...o),parent.postMessage({type:"console",method:t,args:d(o)},"*")}}}),window.addEventListener("error",e=>{parent.postMessage({type:"console",method:"error",args:d([e.message])},"*")})};var x=["esm.sh","skypack","esm.run","jsdelivr.esm","fastly.jsdelivr.esm","gcore.jsdelivr.esm","testingcf.jsdelivr.esm","jsdelivr.b-cdn.esm","jspm"],w=["jsdelivr","fastly.jsdelivr","unpkg","gcore.jsdelivr","testingcf.jsdelivr","jsdelivr.b-cdn","npmcdn"],v=["jsdelivr.gh","fastly.jsdelivr.gh","statically","gcore.jsdelivr.gh","testingcf.jsdelivr.gh","jsdelivr.b-cdn.gh"],u={getModuleUrl:(e,{isModule:t=!0,defaultCDN:o="esm.sh",external:n}={})=>{e=e.replace(/#nobundle/g,"");let i=r=>!n||!r.includes("https://esm.sh")?r:r.includes("?")?`${r}&external=${n}`:`${r}?external=${n}`,a=b(e,t,o);return a?i(a):t?i("https://esm.sh/"+e):"https://cdn.jsdelivr.net/npm/"+e},getUrl:(e,t)=>e.startsWith("http")||e.startsWith("data:")?e:b(e,!1,t||g())||e,cdnLists:{npm:w,module:x,gh:v},checkCDNs:async(e,t)=>{let o=[t,...u.cdnLists.npm].filter(Boolean);for(let n of o)try{if((await fetch(u.getUrl(e,n),{method:"HEAD"})).ok)return n}catch{}return u.cdnLists.npm[0]}},g=()=>{if(globalThis.appCDN)return globalThis.appCDN;try{return new URL(location.href).searchParams.get("appCDN")||u.cdnLists.npm[0]}catch{return u.cdnLists.npm[0]}},b=(e,t,o)=>{let n=t&&e.startsWith("unpkg:")?"?module":"";e.startsWith("gh:")?e=e.replace("gh",v[0]):e.includes(":")||(e=(o||(t?x[0]:w[0]))+":"+e);for(let i of j){let[a,r]=i;if(a.test(e))return e.replace(a,r)+n}return null},j=[[/^(esm\.sh:)(.+)/i,"https://esm.sh/$2"],[/^(npm:)(.+)/i,"https://esm.sh/$2"],[/^(node:)(.+)/i,"https://esm.sh/$2"],[/^(jsr:)(.+)/i,"https://esm.sh/jsr/$2"],[/^(skypack:)(.+)/i,"https://cdn.skypack.dev/$2"],[/^(jsdelivr:)(.+)/i,"https://cdn.jsdelivr.net/npm/$2"],[/^(fastly\.jsdelivr:)(.+)/i,"https://fastly.jsdelivr.net/npm/$2"],[/^(gcore\.jsdelivr:)(.+)/i,"https://gcore.jsdelivr.net/npm/$2"],[/^(testingcf\.jsdelivr:)(.+)/i,"https://testingcf.jsdelivr.net/npm/$2"],[/^(jsdelivr\.b-cdn:)(.+)/i,"https://jsdelivr.b-cdn.net/npm/$2"],[/^(jsdelivr\.gh:)(.+)/i,"https://cdn.jsdelivr.net/gh/$2"],[/^(fastly\.jsdelivr\.gh:)(.+)/i,"https://fastly.jsdelivr.net/gh/$2"],[/^(gcore\.jsdelivr\.gh:)(.+)/i,"https://gcore.jsdelivr.net/gh/$2"],[/^(testingcf\.jsdelivr\.gh:)(.+)/i,"https://testingcf.jsdelivr.net/gh/$2"],[/^(jsdelivr\.b-cdn\.gh:)(.+)/i,"https://jsdelivr.b-cdn.net/gh/$2"],[/^(statically:)(.+)/i,"https://cdn.statically.io/gh/$2"],[/^(esm\.run:)(.+)/i,"https://esm.run/$2"],[/^(jsdelivr\.esm:)(.+)/i,"https://cdn.jsdelivr.net/npm/$2/+esm"],[/^(fastly\.jsdelivr\.esm:)(.+)/i,"https://fastly.jsdelivr.net/npm/$2/+esm"],[/^(gcore\.jsdelivr\.esm:)(.+)/i,"https://gcore.jsdelivr.net/npm/$2/+esm"],[/^(testingcf\.jsdelivr\.esm:)(.+)/i,"https://testingcf.jsdelivr.net/npm/$2/+esm"],[/^(jsdelivr\.b-cdn\.esm:)(.+)/i,"https://jsdelivr.b-cdn.net/npm/$2/+esm"],[/^(jspm:)(.+)/i,"https://jspm.dev/$2"],[/^(esbuild:)(.+)/i,"https://esbuild.vercel.app/$2"],[/^(bundle\.run:)(.+)/i,"https://bundle.run/$2"],[/^(unpkg:)(.+)/i,"https://unpkg.com/$2"],[/^(npmcdn:)(.+)/i,"https://npmcdn.com/$2"],[/^(bundlejs:)(.+)/i,"https://deno.bundlejs.com/?file&q=$2"],[/^(bundle:)(.+)/i,"https://deno.bundlejs.com/?file&q=$2"],[/^(deno:)(.+)/i,"https://deno.bundlejs.com/?file&q=https://deno.land/x/$2/mod.ts"],[/^(https:\/\/deno\.land\/.+)/i,"https://deno.bundlejs.com/?file&q=$1"],[/^(github:|https:\/\/github\.com\/)(.[^\/]+?)\/(.[^\/]+?)\/(?!releases\/)(?:(?:blob|raw)\/)?(.+?\/.+)/i,"https://deno.bundlejs.com/?file&q=https://cdn.jsdelivr.net/gh/$2/$3@$4"],[/^(gist\.github:)(.+?\/[0-9a-f]+\/raw\/(?:[0-9a-f]+\/)?.+)$/i,"https://gist.githack.com/$2"],[/^(gitlab:|https:\/\/gitlab\.com\/)([^\/]+.*\/[^\/]+)\/(?:raw|blob)\/(.+?)(?:\?.*)?$/i,"https://deno.bundlejs.com/?file&q=https://gl.githack.com/$2/raw/$3"],[/^(bitbucket:|https:\/\/bitbucket\.org\/)([^\/]+\/[^\/]+)\/(?:raw|src)\/(.+?)(?:\?.*)?$/i,"https://deno.bundlejs.com/?file&q=https://bb.githack.com/$2/raw/$3"],[/^(bitbucket:)snippets\/([^\/]+\/[^\/]+)\/revisions\/([^\/\#\?]+)(?:\?[^#]*)?(?:\#file-(.+?))$/i,"https://bb.githack.com/!api/2.0/snippets/$2/$3/files/$4"],[/^(bitbucket:)snippets\/([^\/]+\/[^\/\#\?]+)(?:\?[^#]*)?(?:\#file-(.+?))$/i,"https://bb.githack.com/!api/2.0/snippets/$2/HEAD/files/$3"],[/^(bitbucket:)\!api\/2.0\/snippets\/([^\/]+\/[^\/]+\/[^\/]+)\/files\/(.+?)(?:\?.*)?$/i,"https://bb.githack.com/!api/2.0/snippets/$2/files/$3"],[/^(api\.bitbucket:)2.0\/snippets\/([^\/]+\/[^\/]+\/[^\/]+)\/files\/(.+?)(?:\?.*)?$/i,"https://bb.githack.com/!api/2.0/snippets/$2/files/$3"],[/^(rawgit:)(.+?\/[0-9a-f]+\/raw\/(?:[0-9a-f]+\/)?.+)$/i,"https://gist.githack.com/$2"],[/^(rawgit:|https:\/\/raw\.githubusercontent\.com)(\/[^\/]+\/[^\/]+|[0-9A-Za-z-]+\/[0-9a-f]+\/raw)\/(.+)/i,"https://deno.bundlejs.com/?file&q=https://raw.githack.com/$2/$3"]];var $=typeof btoa=="function",m=typeof Buffer=="function",O=typeof TextDecoder=="function"?new TextDecoder:void 0,C=typeof TextEncoder=="function"?new TextEncoder:void 0,L="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",f=Array.prototype.slice.call(L),F=(e=>{let t={};return e.forEach((o,n)=>t[o]=n),t})(f);var l=String.fromCharCode.bind(String),P=typeof Uint8Array.from=="function"?Uint8Array.from.bind(Uint8Array):e=>new Uint8Array(Array.prototype.slice.call(e,0)),U=e=>e.replace(/=/g,"").replace(/[+\/]/g,t=>t=="+"?"-":"_");var S=e=>{let t,o,n,i,a="",r=e.length%3;for(let c=0;c<e.length;){if((o=e.charCodeAt(c++))>255||(n=e.charCodeAt(c++))>255||(i=e.charCodeAt(c++))>255)throw new TypeError("invalid character found");t=o<<16|n<<8|i,a+=f[t>>18&63]+f[t>>12&63]+f[t>>6&63]+f[t&63]}return r?a.slice(0,r-3)+"===".substring(r):a},A=$?e=>btoa(e):m?e=>Buffer.from(e,"binary").toString("base64"):S,D=m?e=>Buffer.from(e).toString("base64"):e=>{let o=[];for(let n=0,i=e.length;n<i;n+=4096)o.push(l.apply(null,e.subarray(n,n+4096)));return A(o.join(""))};var R=e=>{if(e.length<2){var t=e.charCodeAt(0);return t<128?e:t<2048?l(192|t>>>6)+l(128|t&63):l(224|t>>>12&15)+l(128|t>>>6&63)+l(128|t&63)}else{var t=65536+(e.charCodeAt(0)-55296)*1024+(e.charCodeAt(1)-56320);return l(240|t>>>18&7)+l(128|t>>>12&63)+l(128|t>>>6&63)+l(128|t&63)}},M=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g,N=e=>e.replace(M,R),T=m?e=>Buffer.from(e,"utf8").toString("base64"):C?e=>D(C.encode(e)):e=>A(N(e)),k=(e,t=!1)=>t?U(T(e)):T(e);var _=(e,t="text/javascript")=>`data:${t};charset=UTF-8;base64,`+k(e);var E=e=>{try{return new Worker(_(e))}catch{return new Worker(URL.createObjectURL(new Blob([e],{type:"application/javascript"})))}};h();window.initCompiler=async e=>{let t=e.baseUrl,o=t+"compile.worker.eb7da915b0ffc30bdfaee53f3460a761.js",n=new URL(t).origin,i=`self.appCDN='${g()}';importScripts('${o}');`,a=E(i);await new Promise(r=>{let c=document.createElement("script");c.src=t+"compile.page.57425c1e2248287cb72deac0fc962cd9.js",c.onload=()=>r(),document.head.appendChild(c)}),a.addEventListener("message",async function(r){if(r.data.type==="compileInCompiler"){a.postMessage(r.data);return}r.data.payload&&window.compilers&&window.compilers[r.data.payload.language]&&(r.data.payload.compiled=await window.compilers[r.data.payload.language](r.data.payload.compiled,{config:r.data.payload.config,language:r.data.payload.language,baseUrl:t,options:r.data.payload.options,worker:a})),r.data.trigger==="compileInCompiler"?a.postMessage({...r.data,from:"compiler"}):parent.postMessage({...r.data,from:"compiler"},n)}),window.addEventListener("message",async function(r){r.data.type!=="RELEASE"&&a.postMessage(r.data)}),a.postMessage(e)};})();