UNPKG

altair-static

Version:

Static package for altair graphql client

7 lines (6 loc) 9.57 kB
(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))u(s);new MutationObserver(s=>{for(const a of s)if(a.type==="childList")for(const m of a.addedNodes)m.tagName==="LINK"&&m.rel==="modulepreload"&&u(m)}).observe(document,{childList:!0,subtree:!0});function n(s){const a={};return s.integrity&&(a.integrity=s.integrity),s.referrerPolicy&&(a.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?a.credentials="include":s.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function u(s){if(s.ep)return;s.ep=!0;const a=n(s);fetch(s.href,a)}})();const y=[];for(let t=0;t<256;++t)y.push((t+256).toString(16).slice(1));function A(t,r=0){return(y[t[r+0]]+y[t[r+1]]+y[t[r+2]]+y[t[r+3]]+"-"+y[t[r+4]]+y[t[r+5]]+"-"+y[t[r+6]]+y[t[r+7]]+"-"+y[t[r+8]]+y[t[r+9]]+"-"+y[t[r+10]]+y[t[r+11]]+y[t[r+12]]+y[t[r+13]]+y[t[r+14]]+y[t[r+15]]).toLowerCase()}const L=new Uint8Array(16);function U(){return crypto.getRandomValues(L)}function k(t,r,n){return crypto.randomUUID?crypto.randomUUID():N(t)}function N(t,r,n){t=t||{};const u=t.random??t.rng?.()??U();if(u.length<16)throw new Error("Random bytes length must be >= 16");return u[6]=u[6]&15|64,u[8]=u[8]&63|128,A(u)}const T="init_execute",q="modulepreload",R=function(t){return"/"+t},C={},x=function(r,n,u){let s=Promise.resolve();if(n&&n.length>0){let w=function(d){return Promise.all(d.map(l=>Promise.resolve(l).then(c=>({status:"fulfilled",value:c}),c=>({status:"rejected",reason:c}))))};var m=w;document.getElementsByTagName("link");const h=document.querySelector("meta[property=csp-nonce]"),g=h?.nonce||h?.getAttribute("nonce");s=w(n.map(d=>{if(d=R(d),d in C)return;C[d]=!0;const l=d.endsWith(".css"),c=l?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${d}"]${c}`))return;const v=document.createElement("link");if(v.rel=l?"stylesheet":q,l||(v.as="script"),v.crossOrigin="",v.href=d,g&&v.setAttribute("nonce",g),document.head.appendChild(v),l)return new Promise((P,E)=>{v.addEventListener("load",P),v.addEventListener("error",()=>E(new Error(`Unable to preload CSS for ${d}`)))})}))}function a(h){const g=new Event("vite:preloadError",{cancelable:!0});if(g.payload=h,window.dispatchEvent(g),!g.defaultPrevented)throw h}return s.then(h=>{for(const g of h||[])g.status==="rejected"&&a(g.reason);return r().catch(a)})};var I;(function(t){t.INTROSPECTION="introspection",t.QUERY="query",t.SUBSCRIPTION="subscription"})(I||(I={}));class M{}var S={exports:{}},D=S.exports,b;function $(){return b||(b=1,(function(t){(function(r,n){t.exports=n()})(D,function(){var r=Object.prototype.toString;function n(l,c){return l==null?!1:Object.prototype.hasOwnProperty.call(l,c)}function u(l){if(!l||m(l)&&l.length===0)return!0;if(typeof l!="string"){for(var c in l)if(n(l,c))return!1;return!0}return!1}function s(l){return r.call(l)}function a(l){return typeof l=="object"&&s(l)==="[object Object]"}var m=Array.isArray||function(l){return r.call(l)==="[object Array]"};function h(l){return typeof l=="boolean"||s(l)==="[object Boolean]"}function g(l){var c=parseInt(l);return c.toString()===l?c:l}function w(l){l=l||{};var c=function(i){return Object.keys(c).reduce(function(e,o){return o==="create"||typeof c[o]=="function"&&(e[o]=c[o].bind(c,i)),e},{})},v;l.includeInheritedProps?v=function(){return!0}:v=function(i,e){return typeof e=="number"&&Array.isArray(i)||n(i,e)};function P(i,e){if(v(i,e))return i[e]}function E(i,e,o,f){if(typeof e=="number"&&(e=[e]),!e||e.length===0)return i;if(typeof e=="string")return E(i,e.split(".").map(g),o,f);var p=e[0],_=P(i,p);if(l.includeInheritedProps&&(p==="__proto__"||p==="constructor"&&typeof _=="function"))throw new Error("For security reasons, object's magic properties cannot be set");return e.length===1?((_===void 0||!f)&&(i[p]=o),_):(_===void 0&&(typeof e[1]=="number"?i[p]=[]:i[p]={}),E(i[p],e.slice(1),o,f))}return c.has=function(i,e){if(typeof e=="number"?e=[e]:typeof e=="string"&&(e=e.split(".")),!e||e.length===0)return!!i;for(var o=0;o<e.length;o++){var f=g(e[o]);if(typeof f=="number"&&m(i)&&f<i.length||(l.includeInheritedProps?f in Object(i):n(i,f)))i=i[f];else return!1}return!0},c.ensureExists=function(i,e,o){return E(i,e,o,!0)},c.set=function(i,e,o,f){return E(i,e,o,f)},c.insert=function(i,e,o,f){var p=c.get(i,e);f=~~f,m(p)||(p=[],c.set(i,e,p)),p.splice(f,0,o)},c.empty=function(i,e){if(!u(e)&&i!=null){var o,f;if(o=c.get(i,e)){if(typeof o=="string")return c.set(i,e,"");if(h(o))return c.set(i,e,!1);if(typeof o=="number")return c.set(i,e,0);if(m(o))o.length=0;else if(a(o))for(f in o)v(o,f)&&delete o[f];else return c.set(i,e,null)}}},c.push=function(i,e){var o=c.get(i,e);m(o)||(o=[],c.set(i,e,o)),o.push.apply(o,Array.prototype.slice.call(arguments,2))},c.coalesce=function(i,e,o){for(var f,p=0,_=e.length;p<_;p++)if((f=c.get(i,e[p]))!==void 0)return f;return o},c.get=function(i,e,o){if(typeof e=="number"&&(e=[e]),!e||e.length===0)return i;if(i==null)return o;if(typeof e=="string")return c.get(i,e.split("."),o);var f=g(e[0]),p=P(i,f);return p===void 0?o:e.length===1?p:c.get(i[f],e.slice(1),o)},c.del=function(e,o){if(typeof o=="number"&&(o=[o]),e==null||u(o))return e;if(typeof o=="string")return c.del(e,o.split("."));var f=g(o[0]);if(!v(e,f))return e;if(o.length===1)m(e)?e.splice(f,1):delete e[f];else return c.del(e[f],o.slice(1));return e},c}var d=w();return d.create=w,d.withInheritedProps=w({includeInheritedProps:!0}),d})})(S)),S.exports}var O=$();const B={atob:{async exec(){return(await x(async()=>{const{atob:t}=await import("./index-D_C6pEAs.js").then(r=>r.i);return{atob:t}},[])).atob}},btoa:{async exec(){return(await x(async()=>{const{btoa:t}=await import("./index-D_C6pEAs.js").then(r=>r.i);return{btoa:t}},[])).btoa}},"crypto-js":{async exec(){return(await x(async()=>{const{default:t}=await import("./index-CT51TZmB.js").then(r=>r.i);return{default:t}},[])).default}}},W=t=>{if(t.response)return{body:t.response.body,requestType:t.requestType??I.QUERY,responseTime:t.response.responseTime,statusCode:t.response.status,headers:t.response.headers}},J=async t=>{const r=B[t];if(!r)throw new Error(`No request script module found matching "${t}"`);return r.exec()},F=(t,r)=>({data:t,helpers:{getEnvironment:n=>O.get(t.environment,n),setEnvironment:(n,u,s=!1)=>{O.set(t.environment,n,u),s&&(t.__toSetActiveEnvironment=t.__toSetActiveEnvironment??{},O.set(t.__toSetActiveEnvironment,n,u))},getCookie:n=>t.__cookieJar?.[n]??"",setCookie:(n,u,s)=>{r.setCookie(n,u,s)},request:async(n,u,s)=>r.request(n,u,s)},storage:{get:n=>r.getStorageItem(n),set:(n,u)=>r.setStorageItem(n,u)},importModule:n=>J(n),response:W(t),log:n=>{t.requestScriptLogs=t.requestScriptLogs??[],t.requestScriptLogs.push({id:crypto.randomUUID(),time:Date.now(),text:JSON.stringify(n,null,2),source:"Request script"})}}),H=["setCookie","request","getStorageItem","setStorageItem"];class K{constructor(r){this.worker=r}start(){this.worker.onMessage(async r=>{switch(r.type){case T:try{await this.initExecute(r.payload)}catch(n){await this.makeCall("scriptError",n)}break}})}async initExecute(r){const[n,u]=r,s=await new Promise((a,m)=>{this.worker.onError(d=>{m(d)});const h=JSON.parse(JSON.stringify(u)),g=H.reduce((d,l)=>(d[l]=((...c)=>this.makeCall(l,...c)),d),{}),w={altair:F(h,g),alert:d=>this.makeCall("alert",d)};return this.evalWithContext(n,w).then(d=>a(d)).catch(d=>{m(d)})});s.__toSetActiveEnvironment&&this.makeCall("updateActiveEnvironment",s.__toSetActiveEnvironment),this.makeCall("executeComplete",s)}makeCall(r,...n){return new Promise((u,s)=>{const a=k();this.worker.onMessage(m=>{switch(m.type){case`${r}_response`:return m.payload.id!==a?void 0:u(m.payload.response);case`${r}_error`:return m.payload.id!==a?void 0:s(m.payload.error)}}),this.worker.send(r,{id:a,args:n})})}async evalWithContext(r,n){const u=Object.entries(n);return(0,eval)(` async (${u.map(a=>a[0]).join(",")}) => { ${r}; return altair.data; } `)(...u.map(a=>a[1]))}}class Q extends M{origin;constructor(){super();const n=new URLSearchParams(window.location.search).get("sc");if(!n)throw new Error("Invalid source provided!");this.origin=n}onMessage(r){window.addEventListener("message",n=>{n.origin===this.origin&&r(n.data)})}send(r,n){window.parent.postMessage({type:r,payload:n},this.origin)}onError(r){window.addEventListener("error",r),window.addEventListener("unhandledrejection",n=>{n.preventDefault(),r(n.reason)})}}const V=t=>new Promise((r,n)=>{const u=document.getElementsByTagName("head")[0];if(!u)return n(new Error("No head found!"));const s=document.createElement("script");s.type="text/javascript",s.src=t,s.onload=()=>r(null),s.onerror=a=>n(a),u.appendChild(s)}),Y=t=>new Promise((r,n)=>{const u=document.getElementsByTagName("head")[0];if(!u)return n(new Error("No head found!"));const s=document.createElement("link");s.type="text/css",s.rel="stylesheet",s.href=t,s.onload=()=>r(null),s.onerror=a=>n(a),u.appendChild(s)}),G=async()=>{const r=new URLSearchParams(window.location.search).get("plugin_sandbox_opts"),n=r?JSON.parse(r):void 0;if(!n)throw new Error("Invalid plugin options provided!");if(n.type!=="scripts")throw new Error("Invalid plugin option type provided!");if(document.querySelectorAll('style,link[rel="stylesheet"]').forEach(u=>u.remove()),n.styleUrls)for(const u of n.styleUrls)await Y(u);if(n.scriptUrls)for(const u of n.scriptUrls)await V(u)},X=new URLSearchParams(window.location.search),z=X.get("sandbox_type");z==="plugin"?G():new K(new Q).start();