UNPKG

altair-static

Version:

Static package for altair graphql client

7 lines (6 loc) 11.4 kB
var S=Object.defineProperty;var P=(e,r,n)=>r in e?S(e,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[r]=n;var _=(e,r,n)=>P(e,typeof r!="symbol"?r+"":r,n);(function(){const r=document.createElement("link").relList;if(r&&r.supports&&r.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))s(i);new MutationObserver(i=>{for(const d of i)if(d.type==="childList")for(const f of d.addedNodes)f.tagName==="LINK"&&f.rel==="modulepreload"&&s(f)}).observe(document,{childList:!0,subtree:!0});function n(i){const d={};return i.integrity&&(d.integrity=i.integrity),i.referrerPolicy&&(d.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?d.credentials="include":i.crossOrigin==="anonymous"?d.credentials="omit":d.credentials="same-origin",d}function s(i){if(i.ep)return;i.ep=!0;const d=n(i);fetch(i.href,d)}})();let getRandomValues;const rnds8=new Uint8Array(16);function rng(){if(!getRandomValues&&(getRandomValues=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!getRandomValues))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return getRandomValues(rnds8)}const byteToHex=[];for(let e=0;e<256;++e)byteToHex.push((e+256).toString(16).slice(1));function unsafeStringify(e,r=0){return byteToHex[e[r+0]]+byteToHex[e[r+1]]+byteToHex[e[r+2]]+byteToHex[e[r+3]]+"-"+byteToHex[e[r+4]]+byteToHex[e[r+5]]+"-"+byteToHex[e[r+6]]+byteToHex[e[r+7]]+"-"+byteToHex[e[r+8]]+byteToHex[e[r+9]]+"-"+byteToHex[e[r+10]]+byteToHex[e[r+11]]+byteToHex[e[r+12]]+byteToHex[e[r+13]]+byteToHex[e[r+14]]+byteToHex[e[r+15]]}const randomUUID=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),native={randomUUID};function v4(e,r,n){if(native.randomUUID&&!r&&!e)return native.randomUUID();e=e||{};const s=e.random||(e.rng||rng)();if(s[6]=s[6]&15|64,s[8]=s[8]&63|128,r){n=n||0;for(let i=0;i<16;++i)r[n+i]=s[i];return r}return unsafeStringify(s)}const SCRIPT_INIT_EXECUTE="init_execute",scriptRel="modulepreload",assetsURL=function(e){return"/"+e},seen={},__vitePreload=function(r,n,s){let i=Promise.resolve();if(n&&n.length>0){const d=document.getElementsByTagName("link"),f=document.querySelector("meta[property=csp-nonce]"),E=(f==null?void 0:f.nonce)||(f==null?void 0:f.getAttribute("nonce"));i=Promise.all(n.map(p=>{if(p=assetsURL(p),p in seen)return;seen[p]=!0;const g=p.endsWith(".css"),w=g?'[rel="stylesheet"]':"";if(!!s)for(let m=d.length-1;m>=0;m--){const v=d[m];if(v.href===p&&(!g||v.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${p}"]${w}`))return;const u=document.createElement("link");if(u.rel=g?"stylesheet":scriptRel,g||(u.as="script",u.crossOrigin=""),u.href=p,E&&u.setAttribute("nonce",E),document.head.appendChild(u),g)return new Promise((m,v)=>{u.addEventListener("load",m),u.addEventListener("error",()=>v(new Error(`Unable to preload CSS for ${p}`)))})}))}return i.then(()=>r()).catch(d=>{const f=new Event("vite:preloadError",{cancelable:!0});if(f.payload=d,window.dispatchEvent(f),!f.defaultPrevented)throw d})};var RequestType;(function(e){e.INTROSPECTION="introspection",e.QUERY="query",e.SUBSCRIPTION="subscription"})(RequestType||(RequestType={}));class ScriptEvaluatorWorker{}var commonjsGlobal=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function getDefaultExportFromCjs(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var objectPath={exports:{}};(function(e){(function(r,n){e.exports=n()})(commonjsGlobal,function(){var r=Object.prototype.toString;function n(l,u){return l==null?!1:Object.prototype.hasOwnProperty.call(l,u)}function s(l){if(!l||f(l)&&l.length===0)return!0;if(typeof l!="string"){for(var u in l)if(n(l,u))return!1;return!0}return!1}function i(l){return r.call(l)}function d(l){return typeof l=="object"&&i(l)==="[object Object]"}var f=Array.isArray||function(l){return r.call(l)==="[object Array]"};function E(l){return typeof l=="boolean"||i(l)==="[object Boolean]"}function p(l){var u=parseInt(l);return u.toString()===l?u:l}function g(l){l=l||{};var u=function(c){return Object.keys(u).reduce(function(t,o){return o==="create"||typeof u[o]=="function"&&(t[o]=u[o].bind(u,c)),t},{})},m;l.includeInheritedProps?m=function(){return!0}:m=function(c,t){return typeof t=="number"&&Array.isArray(c)||n(c,t)};function v(c,t){if(m(c,t))return c[t]}function x(c,t,o,a){if(typeof t=="number"&&(t=[t]),!t||t.length===0)return c;if(typeof t=="string")return x(c,t.split(".").map(p),o,a);var y=t[0],h=v(c,y);if(l.includeInheritedProps&&(y==="__proto__"||y==="constructor"&&typeof h=="function"))throw new Error("For security reasons, object's magic properties cannot be set");return t.length===1?((h===void 0||!a)&&(c[y]=o),h):(h===void 0&&(typeof t[1]=="number"?c[y]=[]:c[y]={}),x(c[y],t.slice(1),o,a))}return u.has=function(c,t){if(typeof t=="number"?t=[t]:typeof t=="string"&&(t=t.split(".")),!t||t.length===0)return!!c;for(var o=0;o<t.length;o++){var a=p(t[o]);if(typeof a=="number"&&f(c)&&a<c.length||(l.includeInheritedProps?a in Object(c):n(c,a)))c=c[a];else return!1}return!0},u.ensureExists=function(c,t,o){return x(c,t,o,!0)},u.set=function(c,t,o,a){return x(c,t,o,a)},u.insert=function(c,t,o,a){var y=u.get(c,t);a=~~a,f(y)||(y=[],u.set(c,t,y)),y.splice(a,0,o)},u.empty=function(c,t){if(!s(t)&&c!=null){var o,a;if(o=u.get(c,t)){if(typeof o=="string")return u.set(c,t,"");if(E(o))return u.set(c,t,!1);if(typeof o=="number")return u.set(c,t,0);if(f(o))o.length=0;else if(d(o))for(a in o)m(o,a)&&delete o[a];else return u.set(c,t,null)}}},u.push=function(c,t){var o=u.get(c,t);f(o)||(o=[],u.set(c,t,o)),o.push.apply(o,Array.prototype.slice.call(arguments,2))},u.coalesce=function(c,t,o){for(var a,y=0,h=t.length;y<h;y++)if((a=u.get(c,t[y]))!==void 0)return a;return o},u.get=function(c,t,o){if(typeof t=="number"&&(t=[t]),!t||t.length===0)return c;if(c==null)return o;if(typeof t=="string")return u.get(c,t.split("."),o);var a=p(t[0]),y=v(c,a);return y===void 0?o:t.length===1?y:u.get(c[a],t.slice(1),o)},u.del=function(t,o){if(typeof o=="number"&&(o=[o]),t==null||s(o))return t;if(typeof o=="string")return u.del(t,o.split("."));var a=p(o[0]);if(!m(t,a))return t;if(o.length===1)f(t)?t.splice(a,1):delete t[a];else return u.del(t[a],o.slice(1));return t},u}var w=g();return w.create=g,w.withInheritedProps=g({includeInheritedProps:!0}),w})})(objectPath);var objectPathExports=objectPath.exports;const ModuleImports={atob:{async exec(){return(await __vitePreload(async()=>{const{atob:e}=await import("./index-CzXqqJF2.js").then(r=>r.i);return{atob:e}},[])).atob}},btoa:{async exec(){return(await __vitePreload(async()=>{const{btoa:e}=await import("./index-CzXqqJF2.js").then(r=>r.i);return{btoa:e}},[])).btoa}},"crypto-js":{async exec(){return(await __vitePreload(async()=>{const{default:e}=await import("./index-cZO7q35G.js").then(r=>r.i);return{default:e}},[])).default}}},buildContextResponse=e=>{if(e.response)return{body:e.response.body,requestType:e.requestType??RequestType.QUERY,responseTime:e.response.responseTime,statusCode:e.response.status,headers:e.response.headers}},importModuleHelper=async e=>{const r=ModuleImports[e];if(!r)throw new Error(`No request script module found matching "${e}"`);return r.exec()},getGlobalContext=(e,r)=>({data:e,helpers:{getEnvironment:n=>objectPathExports.get(e.environment,n),setEnvironment:(n,s,i=!1)=>{objectPathExports.set(e.environment,n,s),i&&(e.__toSetActiveEnvironment=e.__toSetActiveEnvironment??{},objectPathExports.set(e.__toSetActiveEnvironment,n,s))},getCookie:n=>{var s;return((s=e.__cookieJar)==null?void 0:s[n])??""},setCookie:(n,s,i)=>{r.setCookie(n,s,i)},request:async(n,s,i)=>r.request(n,s,i)},storage:{get:n=>r.getStorageItem(n),set:(n,s)=>r.setStorageItem(n,s)},importModule:n=>importModuleHelper(n),response:buildContextResponse(e),log:n=>{e.requestScriptLogs=e.requestScriptLogs??[],e.requestScriptLogs.push({time:Date.now(),text:JSON.stringify(n,null,2),source:"Request script"})}}),workerHandlerNames=["setCookie","request","getStorageItem","setStorageItem"];class ScriptEvaluatorWorkerEngine{constructor(e){this.worker=e}start(){this.worker.onMessage(async e=>{switch(e.type){case SCRIPT_INIT_EXECUTE:try{await this.initExecute(e.payload)}catch(r){await this.makeCall("scriptError",r)}break}})}async initExecute(payload){const[script,data]=payload,res=await new Promise((resolve,reject)=>{this.worker.onError(e=>{reject(e)});const clonedMutableData=JSON.parse(JSON.stringify(data)),handlers=workerHandlerNames.reduce((e,r)=>(e[r]=(...n)=>this.makeCall(r,...n),e),{}),context={altair:getGlobalContext(clonedMutableData,handlers),alert:e=>this.makeCall("alert",e)},contextEntries=Object.entries(context);try{const res=(function(){return eval(` (async(${contextEntries.map(e=>e[0]).join(",")}) => { ${script}; return altair.data; })(...this.__ctxE.map(e => e[1])); `)}).call({__ctxE:contextEntries});return resolve(res)}catch(e){return reject(e)}});res.__toSetActiveEnvironment&&this.makeCall("updateActiveEnvironment",res.__toSetActiveEnvironment),this.makeCall("executeComplete",res)}makeCall(e,...r){return new Promise((n,s)=>{const i=v4();this.worker.onMessage(d=>{switch(d.type){case`${e}_response`:return d.payload.id!==i?void 0:n(d.payload.response);case`${e}_error`:return d.payload.id!==i?void 0:s(d.payload.error)}}),this.worker.send(e,{id:i,args:r})})}}class EvaluatorFrameWorker extends ScriptEvaluatorWorker{constructor(){super();_(this,"origin");const s=new URLSearchParams(window.location.search).get("sc");if(!s)throw new Error("Invalid source provided!");this.origin=s}onMessage(n){window.addEventListener("message",s=>{s.origin===this.origin&&n(s.data)})}send(n,s){window.parent.postMessage({type:n,payload:s},this.origin)}onError(n){window.addEventListener("error",n),window.addEventListener("unhandledrejection",s=>{s.preventDefault(),n(s.reason)})}}const injectScript=e=>new Promise((r,n)=>{const s=document.getElementsByTagName("head")[0];if(!s)return n(new Error("No head found!"));const i=document.createElement("script");i.type="text/javascript",i.src=e,i.onload=()=>r(null),i.onerror=d=>n(d),s.appendChild(i)}),injectStylesheet=e=>new Promise((r,n)=>{const s=document.getElementsByTagName("head")[0];if(!s)return n(new Error("No head found!"));const i=document.createElement("link");i.type="text/css",i.rel="stylesheet",i.href=e,i.onload=()=>r(null),i.onerror=d=>n(d),s.appendChild(i)}),handlePluginSandbox=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(s=>s.remove()),n.styleUrls)for(const s of n.styleUrls)await injectStylesheet(s);if(n.scriptUrls)for(const s of n.scriptUrls)await injectScript(s)},searchParams=new URLSearchParams(window.location.search),sandboxType=searchParams.get("sandbox_type");switch(sandboxType){case"plugin":handlePluginSandbox();break;case"script":default:new ScriptEvaluatorWorkerEngine(new EvaluatorFrameWorker).start()}export{commonjsGlobal as c,getDefaultExportFromCjs as g};