livecode-static/livecodes/lang-sql-script.0fda13b68543df41c3693dcb15145df0.js
2025-06-11 22:23:49 +08:00

2 lines
6.2 KiB
JavaScript

"use strict";(()=>{var g=["esm.sh","skypack","esm.run","jsdelivr.esm","fastly.jsdelivr.esm","gcore.jsdelivr.esm","testingcf.jsdelivr.esm","jsdelivr.b-cdn.esm","jspm"],j=["jsdelivr","fastly.jsdelivr","unpkg","gcore.jsdelivr","testingcf.jsdelivr","jsdelivr.b-cdn","npmcdn"],U=["jsdelivr.gh","fastly.jsdelivr.gh","statically","gcore.jsdelivr.gh","testingcf.jsdelivr.gh","jsdelivr.b-cdn.gh"],i={getModuleUrl:(s,{isModule:t=!0,defaultCDN:o="esm.sh",external:e}={})=>{s=s.replace(/#nobundle/g,"");let n=r=>!e||!r.includes("https://esm.sh")?r:r.includes("?")?`${r}&external=${e}`:`${r}?external=${e}`,c=u(s,t,o);return c?n(c):t?n("https://esm.sh/"+s):"https://cdn.jsdelivr.net/npm/"+s},getUrl:(s,t)=>s.startsWith("http")||s.startsWith("data:")?s:u(s,!1,t||$())||s,cdnLists:{npm:j,module:g,gh:U},checkCDNs:async(s,t)=>{let o=[t,...i.cdnLists.npm].filter(Boolean);for(let e of o)try{if((await fetch(i.getUrl(s,e),{method:"HEAD"})).ok)return e}catch{}return i.cdnLists.npm[0]}},$=()=>{if(globalThis.appCDN)return globalThis.appCDN;try{return new URL(location.href).searchParams.get("appCDN")||i.cdnLists.npm[0]}catch{return i.cdnLists.npm[0]}},u=(s,t,o)=>{let e=t&&s.startsWith("unpkg:")?"?module":"";s.startsWith("gh:")?s=s.replace("gh",U[0]):s.includes(":")||(s=(o||(t?g[0]:j[0]))+":"+s);for(let n of k){let[c,r]=n;if(c.test(s))return s.replace(c,r)+e}return null},k=[[/^(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{getUrl:b,getModuleUrl:q}=i;var v=b("sql-formatter@12.2.1/dist/sql-formatter.min.js"),y=b("sql.js@1.10.3/dist/");var h="application/json",M={name:"sql",title:"SQL",formatter:{factory:()=>(importScripts(v),async s=>({formatted:await self.sqlFormatter.format(s,{linesBetweenQueries:2}),cursorOffset:0}))},compiler:{url:y+"sql-wasm.js",factory:(s,t)=>(self.importScripts(t+"lang-sql-compiler.be3194e4332711421f17ac09851f498d.js"),self.createSqlCompiler()),scripts:({baseUrl:s})=>[s+"waiting"],scriptType:h,compiledCodeLanguage:"json"},extensions:["sql","sqlite","sqlite3"],editor:"script"};window.livecodes={...window.livecodes,sql:{getResult:()=>new Promise((s,t)=>{window.addEventListener("load",()=>{let o=document.querySelector(`script[type="${h}"]`);if(o)try{let e=JSON.parse(o.innerHTML);e.data&&s(e),t(e.error||"Error compiling SQL")}catch{t("Error compiling SQL")}else t("Error compiling SQL")})}),getResultAsObjects:()=>new Promise(async(s,t)=>{try{let e=(await livecodes.sql.getResult()).data.map(n=>{let c=n.columns;return n.values.reduce((r,d)=>[...r,d.reduce((l,p,x)=>({...l,[c[x]]:p}),{})],[])});s(e)}catch(o){t(o)}}),render:s=>new Promise((t,o)=>{livecodes.sql.getResult().then(e=>{e.data.forEach(c=>{let r=c.columns,d=c.values,l=document.createElement("table"),p=document.createElement("tr");l.append(p),r.forEach(m=>{let a=document.createElement("th");a.innerHTML=m,p.append(a)}),d.forEach(m=>{let a=document.createElement("tr");l.append(a),m.forEach(w=>{let f=document.createElement("td");f.innerHTML=w,a.append(f)})}),(typeof s=="string"?document.querySelector(s):s instanceof Element||s instanceof HTMLDocument?s:document.body).append(l),t()})}).catch(o)})}};})();