UNPKG

@gistproduct/web

Version:

Build beautiful in-app flows with no code and deliver them instantly to your app.

1 lines 34.7 kB
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Gist=t():e.Gist=t()}(this,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var s=t[r]={i:r,l:!1,exports:{}};return e[r].call(s.exports,s,s.exports,n),s.l=!0,s.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var s in e)n.d(r,s,function(t){return e[t]}.bind(null,s));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=11)}([function(e,t,n){"use strict";var r=n(2),s=Object.prototype.toString;function i(e){return"[object Array]"===s.call(e)}function o(e){return void 0===e}function a(e){return null!==e&&"object"==typeof e}function u(e){if("[object Object]"!==s.call(e))return!1;var t=Object.getPrototypeOf(e);return null===t||t===Object.prototype}function c(e){return"[object Function]"===s.call(e)}function l(e,t){if(null!=e)if("object"!=typeof e&&(e=[e]),i(e))for(var n=0,r=e.length;n<r;n++)t.call(null,e[n],n,e);else for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.call(null,e[s],s,e)}e.exports={isArray:i,isArrayBuffer:function(e){return"[object ArrayBuffer]"===s.call(e)},isBuffer:function(e){return null!==e&&!o(e)&&null!==e.constructor&&!o(e.constructor)&&"function"==typeof e.constructor.isBuffer&&e.constructor.isBuffer(e)},isFormData:function(e){return"undefined"!=typeof FormData&&e instanceof FormData},isArrayBufferView:function(e){return"undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&e.buffer instanceof ArrayBuffer},isString:function(e){return"string"==typeof e},isNumber:function(e){return"number"==typeof e},isObject:a,isPlainObject:u,isUndefined:o,isDate:function(e){return"[object Date]"===s.call(e)},isFile:function(e){return"[object File]"===s.call(e)},isBlob:function(e){return"[object Blob]"===s.call(e)},isFunction:c,isStream:function(e){return a(e)&&c(e.pipe)},isURLSearchParams:function(e){return"undefined"!=typeof URLSearchParams&&e instanceof URLSearchParams},isStandardBrowserEnv:function(){return("undefined"==typeof navigator||"ReactNative"!==navigator.product&&"NativeScript"!==navigator.product&&"NS"!==navigator.product)&&("undefined"!=typeof window&&"undefined"!=typeof document)},forEach:l,merge:function e(){var t={};function n(n,r){u(t[r])&&u(n)?t[r]=e(t[r],n):u(n)?t[r]=e({},n):i(n)?t[r]=n.slice():t[r]=n}for(var r=0,s=arguments.length;r<s;r++)l(arguments[r],n);return t},extend:function(e,t,n){return l(t,(function(t,s){e[s]=n&&"function"==typeof t?r(t,n):t})),e},trim:function(e){return e.replace(/^\s*/,"").replace(/\s*$/,"")},stripBOM:function(e){return 65279===e.charCodeAt(0)&&(e=e.slice(1)),e}}},function(e,t,n){e.exports=n(12)},function(e,t,n){"use strict";e.exports=function(e,t){return function(){for(var n=new Array(arguments.length),r=0;r<n.length;r++)n[r]=arguments[r];return e.apply(t,n)}}},function(e,t,n){"use strict";var r=n(0);function s(e){return encodeURIComponent(e).replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}e.exports=function(e,t,n){if(!t)return e;var i;if(n)i=n(t);else if(r.isURLSearchParams(t))i=t.toString();else{var o=[];r.forEach(t,(function(e,t){null!=e&&(r.isArray(e)?t+="[]":e=[e],r.forEach(e,(function(e){r.isDate(e)?e=e.toISOString():r.isObject(e)&&(e=JSON.stringify(e)),o.push(s(t)+"="+s(e))})))})),i=o.join("&")}if(i){var a=e.indexOf("#");-1!==a&&(e=e.slice(0,a)),e+=(-1===e.indexOf("?")?"?":"&")+i}return e}},function(e,t,n){"use strict";e.exports=function(e){return!(!e||!e.__CANCEL__)}},function(e,t,n){"use strict";(function(t){var r=n(0),s=n(18),i={"Content-Type":"application/x-www-form-urlencoded"};function o(e,t){!r.isUndefined(e)&&r.isUndefined(e["Content-Type"])&&(e["Content-Type"]=t)}var a,u={adapter:(("undefined"!=typeof XMLHttpRequest||void 0!==t&&"[object process]"===Object.prototype.toString.call(t))&&(a=n(6)),a),transformRequest:[function(e,t){return s(t,"Accept"),s(t,"Content-Type"),r.isFormData(e)||r.isArrayBuffer(e)||r.isBuffer(e)||r.isStream(e)||r.isFile(e)||r.isBlob(e)?e:r.isArrayBufferView(e)?e.buffer:r.isURLSearchParams(e)?(o(t,"application/x-www-form-urlencoded;charset=utf-8"),e.toString()):r.isObject(e)?(o(t,"application/json;charset=utf-8"),JSON.stringify(e)):e}],transformResponse:[function(e){if("string"==typeof e)try{e=JSON.parse(e)}catch(e){}return e}],timeout:0,xsrfCookieName:"XSRF-TOKEN",xsrfHeaderName:"X-XSRF-TOKEN",maxContentLength:-1,maxBodyLength:-1,validateStatus:function(e){return e>=200&&e<300}};u.headers={common:{Accept:"application/json, text/plain, */*"}},r.forEach(["delete","get","head"],(function(e){u.headers[e]={}})),r.forEach(["post","put","patch"],(function(e){u.headers[e]=r.merge(i)})),e.exports=u}).call(this,n(17))},function(e,t,n){"use strict";var r=n(0),s=n(19),i=n(21),o=n(3),a=n(22),u=n(25),c=n(26),l=n(7);e.exports=function(e){return new Promise((function(t,n){var d=e.data,f=e.headers;r.isFormData(d)&&delete f["Content-Type"];var p=new XMLHttpRequest;if(e.auth){var h=e.auth.username||"",g=e.auth.password?unescape(encodeURIComponent(e.auth.password)):"";f.Authorization="Basic "+btoa(h+":"+g)}var m=a(e.baseURL,e.url);if(p.open(e.method.toUpperCase(),o(m,e.params,e.paramsSerializer),!0),p.timeout=e.timeout,p.onreadystatechange=function(){if(p&&4===p.readyState&&(0!==p.status||p.responseURL&&0===p.responseURL.indexOf("file:"))){var r="getAllResponseHeaders"in p?u(p.getAllResponseHeaders()):null,i={data:e.responseType&&"text"!==e.responseType?p.response:p.responseText,status:p.status,statusText:p.statusText,headers:r,config:e,request:p};s(t,n,i),p=null}},p.onabort=function(){p&&(n(l("Request aborted",e,"ECONNABORTED",p)),p=null)},p.onerror=function(){n(l("Network Error",e,null,p)),p=null},p.ontimeout=function(){var t="timeout of "+e.timeout+"ms exceeded";e.timeoutErrorMessage&&(t=e.timeoutErrorMessage),n(l(t,e,"ECONNABORTED",p)),p=null},r.isStandardBrowserEnv()){var v=(e.withCredentials||c(m))&&e.xsrfCookieName?i.read(e.xsrfCookieName):void 0;v&&(f[e.xsrfHeaderName]=v)}if("setRequestHeader"in p&&r.forEach(f,(function(e,t){void 0===d&&"content-type"===t.toLowerCase()?delete f[t]:p.setRequestHeader(t,e)})),r.isUndefined(e.withCredentials)||(p.withCredentials=!!e.withCredentials),e.responseType)try{p.responseType=e.responseType}catch(t){if("json"!==e.responseType)throw t}"function"==typeof e.onDownloadProgress&&p.addEventListener("progress",e.onDownloadProgress),"function"==typeof e.onUploadProgress&&p.upload&&p.upload.addEventListener("progress",e.onUploadProgress),e.cancelToken&&e.cancelToken.promise.then((function(e){p&&(p.abort(),n(e),p=null)})),d||(d=null),p.send(d)}))}},function(e,t,n){"use strict";var r=n(20);e.exports=function(e,t,n,s,i){var o=new Error(e);return r(o,t,n,s,i)}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t){t=t||{};var n={},s=["url","method","data"],i=["headers","auth","proxy","params"],o=["baseURL","transformRequest","transformResponse","paramsSerializer","timeout","timeoutMessage","withCredentials","adapter","responseType","xsrfCookieName","xsrfHeaderName","onUploadProgress","onDownloadProgress","decompress","maxContentLength","maxBodyLength","maxRedirects","transport","httpAgent","httpsAgent","cancelToken","socketPath","responseEncoding"],a=["validateStatus"];function u(e,t){return r.isPlainObject(e)&&r.isPlainObject(t)?r.merge(e,t):r.isPlainObject(t)?r.merge({},t):r.isArray(t)?t.slice():t}function c(s){r.isUndefined(t[s])?r.isUndefined(e[s])||(n[s]=u(void 0,e[s])):n[s]=u(e[s],t[s])}r.forEach(s,(function(e){r.isUndefined(t[e])||(n[e]=u(void 0,t[e]))})),r.forEach(i,c),r.forEach(o,(function(s){r.isUndefined(t[s])?r.isUndefined(e[s])||(n[s]=u(void 0,e[s])):n[s]=u(void 0,t[s])})),r.forEach(a,(function(r){r in t?n[r]=u(e[r],t[r]):r in e&&(n[r]=u(void 0,e[r]))}));var l=s.concat(i).concat(o).concat(a),d=Object.keys(e).concat(Object.keys(t)).filter((function(e){return-1===l.indexOf(e)}));return r.forEach(d,c),n}},function(e,t,n){"use strict";function r(e){this.message=e}r.prototype.toString=function(){return"Cancel"+(this.message?": "+this.message:"")},r.prototype.__CANCEL__=!0,e.exports=r},,function(e,t,n){const r=n(32).default;e.exports=r},function(e,t,n){"use strict";var r=n(0),s=n(2),i=n(13),o=n(8);function a(e){var t=new i(e),n=s(i.prototype.request,t);return r.extend(n,i.prototype,t),r.extend(n,t),n}var u=a(n(5));u.Axios=i,u.create=function(e){return a(o(u.defaults,e))},u.Cancel=n(9),u.CancelToken=n(27),u.isCancel=n(4),u.all=function(e){return Promise.all(e)},u.spread=n(28),u.isAxiosError=n(29),e.exports=u,e.exports.default=u},function(e,t,n){"use strict";var r=n(0),s=n(3),i=n(14),o=n(15),a=n(8);function u(e){this.defaults=e,this.interceptors={request:new i,response:new i}}u.prototype.request=function(e){"string"==typeof e?(e=arguments[1]||{}).url=arguments[0]:e=e||{},(e=a(this.defaults,e)).method?e.method=e.method.toLowerCase():this.defaults.method?e.method=this.defaults.method.toLowerCase():e.method="get";var t=[o,void 0],n=Promise.resolve(e);for(this.interceptors.request.forEach((function(e){t.unshift(e.fulfilled,e.rejected)})),this.interceptors.response.forEach((function(e){t.push(e.fulfilled,e.rejected)}));t.length;)n=n.then(t.shift(),t.shift());return n},u.prototype.getUri=function(e){return e=a(this.defaults,e),s(e.url,e.params,e.paramsSerializer).replace(/^\?/,"")},r.forEach(["delete","get","head","options"],(function(e){u.prototype[e]=function(t,n){return this.request(a(n||{},{method:e,url:t,data:(n||{}).data}))}})),r.forEach(["post","put","patch"],(function(e){u.prototype[e]=function(t,n,r){return this.request(a(r||{},{method:e,url:t,data:n}))}})),e.exports=u},function(e,t,n){"use strict";var r=n(0);function s(){this.handlers=[]}s.prototype.use=function(e,t){return this.handlers.push({fulfilled:e,rejected:t}),this.handlers.length-1},s.prototype.eject=function(e){this.handlers[e]&&(this.handlers[e]=null)},s.prototype.forEach=function(e){r.forEach(this.handlers,(function(t){null!==t&&e(t)}))},e.exports=s},function(e,t,n){"use strict";var r=n(0),s=n(16),i=n(4),o=n(5);function a(e){e.cancelToken&&e.cancelToken.throwIfRequested()}e.exports=function(e){return a(e),e.headers=e.headers||{},e.data=s(e.data,e.headers,e.transformRequest),e.headers=r.merge(e.headers.common||{},e.headers[e.method]||{},e.headers),r.forEach(["delete","get","head","post","put","patch","common"],(function(t){delete e.headers[t]})),(e.adapter||o.adapter)(e).then((function(t){return a(e),t.data=s(t.data,t.headers,e.transformResponse),t}),(function(t){return i(t)||(a(e),t&&t.response&&(t.response.data=s(t.response.data,t.response.headers,e.transformResponse))),Promise.reject(t)}))}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t,n){return r.forEach(n,(function(n){e=n(e,t)})),e}},function(e,t){var n,r,s=e.exports={};function i(){throw new Error("setTimeout has not been defined")}function o(){throw new Error("clearTimeout has not been defined")}function a(e){if(n===setTimeout)return setTimeout(e,0);if((n===i||!n)&&setTimeout)return n=setTimeout,setTimeout(e,0);try{return n(e,0)}catch(t){try{return n.call(null,e,0)}catch(t){return n.call(this,e,0)}}}!function(){try{n="function"==typeof setTimeout?setTimeout:i}catch(e){n=i}try{r="function"==typeof clearTimeout?clearTimeout:o}catch(e){r=o}}();var u,c=[],l=!1,d=-1;function f(){l&&u&&(l=!1,u.length?c=u.concat(c):d=-1,c.length&&p())}function p(){if(!l){var e=a(f);l=!0;for(var t=c.length;t;){for(u=c,c=[];++d<t;)u&&u[d].run();d=-1,t=c.length}u=null,l=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===o||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function h(e,t){this.fun=e,this.array=t}function g(){}s.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];c.push(new h(e,t)),1!==c.length||l||a(p)},h.prototype.run=function(){this.fun.apply(null,this.array)},s.title="browser",s.browser=!0,s.env={},s.argv=[],s.version="",s.versions={},s.on=g,s.addListener=g,s.once=g,s.off=g,s.removeListener=g,s.removeAllListeners=g,s.emit=g,s.prependListener=g,s.prependOnceListener=g,s.listeners=function(e){return[]},s.binding=function(e){throw new Error("process.binding is not supported")},s.cwd=function(){return"/"},s.chdir=function(e){throw new Error("process.chdir is not supported")},s.umask=function(){return 0}},function(e,t,n){"use strict";var r=n(0);e.exports=function(e,t){r.forEach(e,(function(n,r){r!==t&&r.toUpperCase()===t.toUpperCase()&&(e[t]=n,delete e[r])}))}},function(e,t,n){"use strict";var r=n(7);e.exports=function(e,t,n){var s=n.config.validateStatus;n.status&&s&&!s(n.status)?t(r("Request failed with status code "+n.status,n.config,null,n.request,n)):e(n)}},function(e,t,n){"use strict";e.exports=function(e,t,n,r,s){return e.config=t,n&&(e.code=n),e.request=r,e.response=s,e.isAxiosError=!0,e.toJSON=function(){return{message:this.message,name:this.name,description:this.description,number:this.number,fileName:this.fileName,lineNumber:this.lineNumber,columnNumber:this.columnNumber,stack:this.stack,config:this.config,code:this.code}},e}},function(e,t,n){"use strict";var r=n(0);e.exports=r.isStandardBrowserEnv()?{write:function(e,t,n,s,i,o){var a=[];a.push(e+"="+encodeURIComponent(t)),r.isNumber(n)&&a.push("expires="+new Date(n).toGMTString()),r.isString(s)&&a.push("path="+s),r.isString(i)&&a.push("domain="+i),!0===o&&a.push("secure"),document.cookie=a.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}:{write:function(){},read:function(){return null},remove:function(){}}},function(e,t,n){"use strict";var r=n(23),s=n(24);e.exports=function(e,t){return e&&!r(t)?s(e,t):t}},function(e,t,n){"use strict";e.exports=function(e){return/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(e)}},function(e,t,n){"use strict";e.exports=function(e,t){return t?e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""):e}},function(e,t,n){"use strict";var r=n(0),s=["age","authorization","content-length","content-type","etag","expires","from","host","if-modified-since","if-unmodified-since","last-modified","location","max-forwards","proxy-authorization","referer","retry-after","user-agent"];e.exports=function(e){var t,n,i,o={};return e?(r.forEach(e.split("\n"),(function(e){if(i=e.indexOf(":"),t=r.trim(e.substr(0,i)).toLowerCase(),n=r.trim(e.substr(i+1)),t){if(o[t]&&s.indexOf(t)>=0)return;o[t]="set-cookie"===t?(o[t]?o[t]:[]).concat([n]):o[t]?o[t]+", "+n:n}})),o):o}},function(e,t,n){"use strict";var r=n(0);e.exports=r.isStandardBrowserEnv()?function(){var e,t=/(msie|trident)/i.test(navigator.userAgent),n=document.createElement("a");function s(e){var r=e;return t&&(n.setAttribute("href",r),r=n.href),n.setAttribute("href",r),{href:n.href,protocol:n.protocol?n.protocol.replace(/:$/,""):"",host:n.host,search:n.search?n.search.replace(/^\?/,""):"",hash:n.hash?n.hash.replace(/^#/,""):"",hostname:n.hostname,port:n.port,pathname:"/"===n.pathname.charAt(0)?n.pathname:"/"+n.pathname}}return e=s(window.location.href),function(t){var n=r.isString(t)?s(t):t;return n.protocol===e.protocol&&n.host===e.host}}():function(){return!0}},function(e,t,n){"use strict";var r=n(9);function s(e){if("function"!=typeof e)throw new TypeError("executor must be a function.");var t;this.promise=new Promise((function(e){t=e}));var n=this;e((function(e){n.reason||(n.reason=new r(e),t(n.reason))}))}s.prototype.throwIfRequested=function(){if(this.reason)throw this.reason},s.source=function(){var e;return{token:new s((function(t){e=t})),cancel:e}},e.exports=s},function(e,t,n){"use strict";e.exports=function(e){return function(t){return e.apply(null,t)}}},function(e,t,n){"use strict";e.exports=function(e){return"object"==typeof e&&!0===e.isAxiosError}},function(e,t){e.exports='<div id="gist-embed"> <style>#x-gist-floating-top,#x-gist-floating-top-left,#x-gist-floating-top-right{position:fixed;top:0;z-index:1000000}#x-gist-floating-bottom,#x-gist-floating-bottom-left,#x-gist-floating-bottom-right{position:fixed;bottom:0;z-index:1000000}#x-gist-bottom,#x-gist-floating-bottom,#x-gist-floating-top{width:100%}#x-gist-floating-bottom-left,#x-gist-floating-bottom-right,#x-gist-floating-top-left,#x-gist-floating-top-right{width:40%;max-width:414px}#x-gist-floating-bottom-right,#x-gist-floating-top-right{right:0}#gist-embed{position:relative;height:100%;width:100%}#gist-embed-container{position:relative;height:100%;width:100%}#gist-embed-container .gist-frame{height:100%;width:100%;border:none}@media (max-width:800px){#x-gist-floating-bottom-left,#x-gist-floating-bottom-right,#x-gist-floating-top-left,#x-gist-floating-top-right{width:100%}}</style> <div id="gist-embed-container"> <iframe class="gist-frame" src="${url}"></iframe> </div> </div>'},function(e,t){e.exports='<div id="gist-embed-message"> <style>#gist-overlay.background{position:fixed;z-index:9999999998;left:0;top:0;width:100%;height:100%;background-color:rgba(0,0,0,.2);visibility:hidden}#gist-overlay.background.visible{visibility:visible}#gist-overlay.background.is-blacked-out{display:block}#gist-message{width:414px;position:absolute;border:none;opacity:0;transition:opacity .3s ease-in-out;z-index:9999999999;left:50%;transform:translateX(-50%)}#gist-message.visible{opacity:1}#gist-message.center{transform:translate(-50%,-50%);top:50%}#gist-message.bottom{bottom:0}#gist-message.top{top:0}@media (max-width:600px){#gist-message{width:100%}}</style> <div id="gist-overlay" class="background"> <iframe id="gist-message" class="message" src="${url}"></iframe> </div> </div>'},function(e,t,n){"use strict";n.r(t);class r{on(e,t){var n=this[e];n?n.push(t):this[e]=[t]}dispatch(e,t){var n=this[e];n&&n.forEach(e=>e(t))}}function s(e){re.config.logging&&console.log("Gist: "+e)}class i extends Error{constructor(){super("EventSource not available.\nConsider loading an EventSource polyfill and making it available globally as EventSource, or passing one in as eventSourceClass to the ReconnectingEventSource constructor.")}}class o{constructor(e,t){if(this._configuration=null!=t?Object.assign({},t):null,this._eventSource=null,this._lastEventId=null,this._timer=null,this._listeners={},this.url=e,this.readyState=0,this.max_retry_time=3e3,this.eventSourceClass=globalThis.EventSource,null!=this._configuration&&(this._configuration.lastEventId&&(this._lastEventId=this._configuration.lastEventId,delete this._configuration.lastEventId),this._configuration.max_retry_time&&(this.max_retry_time=this._configuration.max_retry_time,delete this._configuration.max_retry_time),this._configuration.eventSourceClass&&(this.eventSourceClass=this._configuration.eventSourceClass,delete this._configuration.eventSourceClass)),null==this.eventSourceClass||"function"!=typeof this.eventSourceClass)throw new i;this._onevent_wrapped=e=>{this._onevent(e)},this._start()}_start(){let e=this.url;this._lastEventId&&(-1===e.indexOf("?")?e+="?":e+="&",e+="lastEventId="+encodeURIComponent(this._lastEventId)),this._eventSource=new this.eventSourceClass(e,this._configuration),this._eventSource.onopen=e=>{this._onopen(e)},this._eventSource.onerror=e=>{this._onerror(e)},this._eventSource.onmessage=e=>{this.onmessage(e)};for(const e of Object.keys(this._listeners))this._eventSource.addEventListener(e,this._onevent_wrapped)}_onopen(e){0===this.readyState&&(this.readyState=1,this.onopen(e))}_onerror(e){if(1===this.readyState&&(this.readyState=0,this.onerror(e)),this._eventSource&&2===this._eventSource.readyState){this._eventSource.close(),this._eventSource=null;const e=Math.round(this.max_retry_time*Math.random());this._timer=setTimeout(()=>this._start(),e)}}_onevent(e){e.lastEventId&&(this._lastEventId=e.lastEventId);const t=this._listeners[e.type];if(null!=t)for(const n of[...t])n(e);"message"===e.type&&this.onmessage(e)}onopen(e){}onerror(e){}onmessage(e){}close(){this._timer&&(clearTimeout(this._timer),this._timer=null),this._eventSource&&(this._eventSource.close(),this._eventSource=null),this.readyState=2}addEventListener(e,t){const n=e.toString();n in this._listeners||(this._listeners[n]=[],this._eventSource&&this._eventSource.addEventListener(n,this._onevent_wrapped));const r=this._listeners[n];r.includes(t)||(this._listeners[n]=[...r,t])}removeEventListener(e,t){const n=e.toString();if(n in this._listeners){const e=this._listeners[n].filter(e=>e!==t);e.length>0?this._listeners[n]=e:(delete this._listeners[n],this._eventSource&&this._eventSource.removeEventListener(n,this._onevent_wrapped))}}}function a(e,t,n){const r={value:t,expiry:n};localStorage.setItem(e,JSON.stringify(r))}function u(e){const t=localStorage.getItem(e);if(!t)return null;const n=JSON.parse(t),r=new Date,s=new Date(n.expiry);return r.getTime()>s.getTime()?(localStorage.removeItem(e),null):n.value}function c(e){localStorage.removeItem(e)}var l,d=new Uint8Array(16);function f(){if(!l&&!(l="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return l(d)}var p=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var h=function(e){return"string"==typeof e&&p.test(e)},g=[],m=0;m<256;++m)g.push((m+256).toString(16).substr(1));var v=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(g[e[t+0]]+g[e[t+1]]+g[e[t+2]]+g[e[t+3]]+"-"+g[e[t+4]]+g[e[t+5]]+"-"+g[e[t+6]]+g[e[t+7]]+"-"+g[e[t+8]]+g[e[t+9]]+"-"+g[e[t+10]]+g[e[t+11]]+g[e[t+12]]+g[e[t+13]]+g[e[t+14]]+g[e[t+15]]).toLowerCase();if(!h(n))throw TypeError("Stringified UUID is invalid");return n};var y=function(e,t,n){var r=(e=e||{}).random||(e.rng||f)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var s=0;s<16;++s)t[n+s]=r[s];return t}return v(r)};function b(){return u("gist.web.userToken")}function w(){var e=new Date;if(e.setDate(e.getDate()+365),null===b()){var t=u("gist.web.guestUserToken");null==t&&(a("gist.web.guestUserToken",t=y(),e),s(`Set guest user token "${t}" with expiry date set to 1 year from today`)),a("gist.web.userToken",t,e),a("gist.web.usingGuestUserToken",!0,e)}}var x=n(1),S=n.n(x);const I={GIST_API_ENDPOINT:{prod:"https://api.gist.build",dev:"https://api.dev.gist.build",local:"http://api.local.gist.build:83"},GIST_QUEUE_API_ENDPOINT:{prod:"https://queue.api.gist.build",dev:"https://queue.api.dev.gist.build",local:"http://api.local.gist.build:86"},GIST_ANALYTICS_API_ENDPOINT:{prod:"https://analytics.api.gist.build",dev:"https://analytics.api.dev.gist.build",local:"http://api.local.gist.build:88"},GIST_VIEW_ENDPOINT:{prod:"https://renderer.gist.build/1.0",dev:"https://renderer.gist.build/1.0",local:"http://app.local.gist.build:8080/web"}};function _(){var e={"X-Bourbon-Organization-Id":""+re.config.organizationId},t=b();return void 0===t&&null===t||(e["X-Gist-User-Token"]=t),S.a.create({baseURL:I.GIST_QUEUE_API_ENDPOINT[re.config.env],timeout:2e4,headers:e})}const E=S.a.CancelToken;let T;async function R(e,t,n,r,s){try{return await(i={"X-Bourbon-Organization-Id":""+re.config.organizationId},S.a.create({baseURL:I.GIST_ANALYTICS_API_ENDPOINT[re.config.env],timeout:2e4,headers:i})).post("/api/v1/organization/events",{name:e,route:t,instanceId:n,queueId:r,campaignId:s,platform:"web"})}catch(e){return e.response}var i}function C(e){var t="",n="",r="",s=!1,i=!1,o=!1,a=!1,u=null;return e.properties&&e.properties.gist&&(e.properties.gist.campaignId&&(u=e.properties.gist.campaignId),e.properties.gist.elementId&&(t=e.properties.gist.elementId,s=!0),e.properties.gist.routeRuleWeb&&(n=e.properties.gist.routeRuleWeb,i=!0),e.properties.gist.position&&(r=e.properties.gist.position,o=!0),e.properties.gist.scale&&(a=e.properties.gist.scale)),{isEmbedded:s,elementId:t,hasRouteRule:i,routeRule:n,position:r,hasPosition:o,shouldScale:a,campaignId:u}}async function O(e,t){s(`Logging analytics event ${e} for route: ${t.currentRoute}, instance id: ${t.instanceId}, queue id: ${t.queueId}`),await R(e,t.currentRoute,t.instanceId,t.queueId,C(t).campaignId)}function k(e,t){var r=document.querySelector(q(e));r?(L(e)||(r.style.height="0px"),r.innerHTML=function(e){var t=n(30);return t=t.replace("${url}",e)}(t)):s(`Message could not be embedded, elementId ${e} not found.`)}function L(e){var t=document.querySelector(q(e));if(t)return t.style&&t.style.height&&"0px"!=t.style.height}function N(e,t,n){var r=document.querySelector(q(e));if(r){var s=r.style;if(t.height>0)if(t.height>window.innerHeight){var i=1-(t.height/window.innerHeight-1);n&&i>=.4?(s.height=t.height+"px",s.transform=`translateX(-50%) translateY(-50%) scale(${i})`):s.height=window.innerHeight+"px"}else s.height=t.height+"px"}}function A(e,t){document.body.insertAdjacentHTML("beforeend",function(e,t){var r=n(31);return r=(r=r.replace("${url}",e)).replace("${instanceId}",t)}(e,t))}function P(){var e=document.querySelector("#gist-embed-message");e&&e.parentNode.removeChild(e)}function q(e){return"#"+e}function U(){var e=document.querySelector("#gist-message");e&&e.classList.add("visible")}var j=["x-gist-top","x-gist-floating-top","x-gist-bottom","x-gist-floating-bottom","x-gist-floating-bottom-left","x-gist-floating-bottom-right","x-gist-floating-top-left","x-gist-floating-top-right"];function D(e){if(re.isDocumentVisible){if(re.overlayInstanceId)return s(`Message ${re.overlayInstanceId} already showing.`),null;var t=C(e);return e.instanceId=y(),e.overlay=!0,e.firstLoad=!0,e.shouldResizeHeight=!0,e.shouldScale=t.shouldScale,re.overlayInstanceId=e.instanceId,re.currentMessages.push(e),G(e)}return s("Document hidden, not showing message now."),null}function M(e,t){return re.isDocumentVisible?(e.instanceId=y(),e.overlay=!1,e.firstLoad=!0,e.shouldScale=!1,e.elementId=t,e.shouldResizeHeight=!L(t),re.currentMessages.push(e),G(e,t)):(s("Document hidden, not showing message now."),null)}function $(e){var t=V(e);t?(O("gist_dismissed",t),re.messageDismissed(t),t.overlay?z(!0,t):B(t)):s(`Message with instance id: ${e} not found`)}function B(e){var t,n;F(e.instanceId),t=e.elementId,(n=document.querySelector(q(t)))&&(n.classList.remove("gist-visible"),n.style.removeProperty("height"),n.innerHTML="")}function z(e,t){F(t.instanceId),re.overlayInstanceId=null,e?function(){var e=document.querySelector("#gist-message");e?(e.classList.remove("visible"),setTimeout(P,300)):P()}():P(),0==re.currentMessages.length&&(window.removeEventListener("message",X),window.removeEventListener("touchstart",{}))}function G(e,t=null){if(t&&function(e){var t=document.querySelector(q(e));return!(!t||!t.classList.contains("gist-visible"))}(t))return s(`Message ${e.messageId} already showing in element ${t}.`),null;var n,r,i={organizationId:re.config.organizationId,messageId:e.messageId,instanceId:e.instanceId,endpoint:I.GIST_API_ENDPOINT[re.config.env],livePreview:!1,properties:e.properties},o=`${I.GIST_VIEW_ENDPOINT[re.config.env]}/index.html?options=${n=JSON.stringify(i),r=btoa(encodeURIComponent(n).replace(/%([0-9A-F]{2})/g,(function(e,t){return String.fromCharCode("0x"+t)}))),encodeURIComponent(r)}`;return window.addEventListener("message",X),window.addEventListener("touchstart",{}),t?(j.includes(t)&&function(e){const t=document.createElement("div");switch(t.id=e,e){case"x-gist-top":document.body.insertBefore(t,document.body.firstChild);break;default:document.body.insertAdjacentElement("beforeend",t)}s("Top & bottom elements injected into page")}(t),k(t,o)):A(o,e.instanceId),e}async function H(e){re.messageShown(e),s("Message shown, logging view for: "+e.messageId);var t={};200===(t=null!=e.queueId?await async function(e){try{return await _().post("/api/v1/logs/queue/"+e)}catch(e){return e.response}}(e.queueId):await async function(e){try{return await _().post("/api/v1/logs/message/"+e)}catch(e){return e.response}}(e.messageId)).status?s("Message view logged"):s("Problem logging message: "+t.status)}function V(e){return re.currentMessages.find(t=>t.instanceId===e)}function F(e){re.currentMessages=re.currentMessages.filter(t=>t.instanceId!==e)}function J(e,t){F(e),re.currentMessages.push(t)}function X(e){if(e.data.gist){var t=e.data.gist.instanceId,n=V(t);switch(e.data.gist.method){case"routeLoaded":n.currentRoute=e.data.gist.parameters.route,O("gist_loaded",n),n.firstLoad&&(n.overlay?function(e){var t=document.querySelector("#gist-overlay");if(t){t.classList.add("visible");var n=document.querySelector("#gist-message");e.position?n.classList.add(e.position):n.classList.add("center"),setTimeout(U,100)}else P()}(n):(l=n.elementId,(d=document.querySelector(q(l)))&&d.classList.add("gist-visible")),H(n),n.firstLoad=!1),J(t,n);break;case"tap":var r=e.data.gist.parameters.action,i=e.data.gist.parameters.name;if(re.messageAction(n,r,i),1==e.data.gist.parameters.system){O("gist_system_action",n),$(t);break}var o=!0;try{if((c=new URL(r))&&"gist:"===c.protocol)switch(c.href.replace("gist://","").split("?")[0]){case"close":$(t),o=!1,ee();break;case"showMessage":var a=c.searchParams.get("messageId"),u=c.searchParams.get("properties");a&&(u&&(u=JSON.parse(atob(u))),re.showMessage({messageId:a,properties:u}));break;case"loadPage":var c;(c=c.searchParams.get("url"))&&(c.startsWith("https://")||c.startsWith("http://")||c.startsWith("/")?window.location.href=c:window.location.href=window.location+c)}}catch(e){}o&&O("gist_action",n);break;case"routeChanged":n.currentRoute=e.data.gist.parameters.route,J(t,n),s("Route changed to: "+n.currentRoute);break;case"sizeChanged":s(`Size Changed Width: ${e.data.gist.parameters.width} - Height: ${e.data.gist.parameters.height}`),n.elementId&&n.shouldResizeHeight?N(n.elementId,e.data.gist.parameters,n.shouldScale):N("gist-message",e.data.gist.parameters,n.shouldScale);break;case"error":case"routeError":re.messageError(n),re.overlayInstanceId?z(!1,n):B(n)}}var l,d}var W=(e,t)=>e().then((e=>new Promise(t=>setTimeout(t,e)))(t).then(()=>W(e,t))),Q=!1,Y=null,K=[];async function Z(){var e;Q?ee():((e=document.createElement("iframe")).setAttribute("src",I.GIST_VIEW_ENDPOINT[re.config.env]+"/index.html"),e.style.display="none",document.body.appendChild(e),b()?(s("Queue watcher started"),Q=!0,W(()=>new Promise(()=>ne()),6e4)):s("User token not setup, queue not started.")),null!==u("gist.web.usingGuestUserToken")?te():await async function(){if(te(),b()){var e=await async function(){try{return await _().get("/api/v1/settings",{cancelToken:new E((function(e){T=e}))})}catch(e){return e.response}}();null!=e&&200===e.status&&(s("Listening to SSE on endpoint: "+e.data.sseEndpoint),(Y=new o(e.data.sseEndpoint)).onmessage=function(e){var t=JSON.parse(e.data);if("queue"===t.name){var n=JSON.parse(t.data);K.push(n),ee()}})}else Y=null}()}function ee(){s("Messages in local queue: "+K.length);var e=[];K.forEach(t=>{if(!function(e){var t=C(e);if(t.hasRouteRule){var n=re.currentRoute;null==n&&(n=new URL(window.location.href).pathname);var r=t.routeRule;if(s("Verifying route against rule: "+r),!new RegExp(r).test(n))return s(`Route ${n} does not match rule.`),!1}t.hasPosition&&(e.position=t.position);return t.isEmbedded?M(e,t.elementId):D(e)}(t)){var n=e.find(e=>e.queueId===t.queueId),r=re.currentMessages.find(e=>e.queueId===t.queueId);n||r?s(`Message with queueId: ${t.queueId} already in queue, discarding.`):e.push(t)}}),K=e}function te(){void 0!==T&&T(),null!=Y&&(s("Closing EventSource connection"),Y.close())}async function ne(){if(b()){var e=await async function(e=[]){try{return await _().post("/api/v1/users",{topics:e})}catch(e){return e.response}}(re.topics);200===e.status||204===e.status?(s(`Message queue checked for user ${b()}, ${e.data.length} messages found.`),e.data.length>0?(K=e.data,ee()):s("No messages for user token.")):s("There was an error while checking message queue: "+e.status)}else s("User token reset, skipping queue check.")}var re=t.default=class{static async setup(e){this.events=new r,this.config={useGuestSession:void 0!==e.useGuestSession&&e.useGuestSession,organizationId:e.organizationId,env:void 0===e.env?"prod":e.env,logging:void 0!==e.logging&&e.logging,experiments:void 0!==e.experiments&&e.experiments},this.currentMessages=[],this.overlayInstanceId=null,this.currentRoute=null,this.topics=[],this.isDocumentVisible=!0,s(`Setup complete on ${this.config.env} environment.`),this.config.useGuestSession&&w(),await Z(),document.addEventListener("visibilitychange",()=>{"hidden"===document.visibilityState?this.isDocumentVisible=!1:(this.isDocumentVisible=!0,ee())},!1)}static async setCurrentRoute(e){this.currentRoute=e,s("Current route set to: "+e),ee()}static async setUserToken(e,t){!function(e,t){void 0===t&&(t=new Date).setDate(t.getDate()+30),a("gist.web.userToken",e,t),c("gist.web.usingGuestUserToken"),s(`Set user token "${e}" with expiry date set to ${t}`)}(e,t),await Z()}static async clearUserToken(){c("gist.web.userToken"),s("Cleared user token"),this.config.useGuestSession&&w(),await Z()}static dismissMessage(e){$(e),ee()}static embedMessage(e,t){return(e=M(e,t)).instanceId}static showMessage(e){return(e=D(e))?e.instanceId:null}static async subscribeToTopic(e){-1==this.topics.indexOf(e)&&(this.topics.push(e),await ne())}static unsubscribeFromTopic(e){this.topics=this.topics.filter(t=>t!==e)}static clearTopics(){this.topics=[]}static getTopics(){return this.topics}static messageShown(e){s("Message shown: "+e.messageId),this.events.dispatch("messageShown",e)}static messageDismissed(e){null!==e&&(s("Message dismissed: "+e.messageId),this.events.dispatch("messageDismissed",e))}static messageError(e){s("Message error: "+e.messageId),this.events.dispatch("messageError",e)}static messageAction(e,t,n){s(`Message action: ${e.currentRoute}, ${t} with name ${n} on ${e.instanceId}`),this.events.dispatch("messageAction",{message:e,action:t,name:n})}}}])}));