/**
 * Minified by jsDelivr using Terser v5.37.0.
 * Original file: /npm/node-iframe@1.10.0/dist/iframe.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var __assign=this&&this.__assign||function(){return __assign=Object.assign||function(e){for(var r,t=1,n=arguments.length;t<n;t++)for(var o in r=arguments[t])Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o]);return e},__assign.apply(this,arguments)},__awaiter=this&&this.__awaiter||function(e,r,t,n){return new(t||(t=Promise))((function(o,a){function s(e){try{i(n.next(e))}catch(e){a(e)}}function c(e){try{i(n.throw(e))}catch(e){a(e)}}function i(e){var r;e.done?o(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(s,c)}i((n=n.apply(e,r||[])).next())}))},__generator=this&&this.__generator||function(e,r){var t,n,o,a,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return a={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function c(a){return function(c){return function(a){if(t)throw new TypeError("Generator is already executing.");for(;s;)try{if(t=1,n&&(o=2&a[0]?n.return:a[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,a[1])).done)return o;switch(n=0,o&&(a=[2&a[0],o.value]),a[0]){case 0:case 1:o=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!o||a[1]>o[0]&&a[1]<o[3])){s.label=a[1];break}if(6===a[0]&&s.label<o[1]){s.label=o[1],o=a;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(a);break}o[2]&&s.ops.pop(),s.trys.pop();continue}a=r.call(e,s)}catch(e){a=[6,e],n=0}finally{t=o=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}};exports.__esModule=!0,exports.fetchFrame=exports.configureTemplates=exports.configureResourceControl=exports.configureAgent=exports.appSourceConfig=void 0;var fetch_1=require("./fetch"),cheerio_1=require("cheerio"),templates_1=require("./templates");exports.configureTemplates=templates_1.configureTemplates;var httpAgent,httpsAgent,config_1=require("./config"),appSourceConfig=config_1.defaultConfig;exports.appSourceConfig=appSourceConfig;var agentConfigured=!1,agent=agentConfigured?function(e){return"http:"==e.protocol&&setAgent(!0)?httpAgent:setAgent(!1)?httpsAgent:void 0}:void 0;function setAgent(e){try{if(e&&!httpAgent){var r=require("http");httpAgent=new r.Agent({rejectUnauthorized:!1})}else if(!httpsAgent){r=require("https");httpsAgent=new r.Agent({rejectUnauthorized:!1})}return!0}catch(e){return console.error(e),!1}}function configureAgent(){agentConfigured||(agentConfigured=!0)}exports.configureAgent=configureAgent;var mutateSource=function(e,r,t,n){var o=e.src,a=void 0===o?"":o,s=e.key,c=e.safeMode;return __awaiter(void 0,void 0,void 0,(function(){var e,o,i,u;return __generator(this,(function(l){switch(l.label){case 0:if(!a||"/"!==a[0])return[3,8];l.label=1;case 1:return l.trys.push([1,7,,8]),[4,(0,fetch_1.fetcher)("".concat(r,"/").concat(a),{headers:n,agent:agent})];case 2:return(e=l.sent())?"undefined"==typeof process?[3,3]:(i=e,[3,5]):[3,6];case 3:return[4,e.text()];case 4:i=l.sent(),l.label=5;case 5:o=i,t(s).text(c?"try {".concat(o,"}catch(e){console.error(e)}"):o),l.label=6;case 6:return[3,8];case 7:return u=l.sent(),console.error(u),[3,8];case 8:return[2]}}))}))};function renderErrorHtml(e){var r=e.url,t=e.server,n=e.noPage,o=void 0!==n&&n;return Object.assign((0,cheerio_1.load)(r?templates_1.templateModel[templates_1.TemplateType.notFound]:templates_1.templateModel[templates_1.TemplateType.error]),t?{status:Number("".concat(40).concat(!r||o?4:0))}:{})}function renderHtml(e,r){var t=e.url,n=e.baseHref,o=e.config,a=e.head,s=void 0===a?{}:a,c=e.safeMode;return void 0===r&&(r=!1),__awaiter(this,void 0,void 0,(function(){var e,a,i,u,l,f,p,g,h,_,d,v,m,b,y,w,x,C,A,S,k,H,T;return __generator(this,(function(j){switch(j.label){case 0:if(!t)return[2,renderErrorHtml({url:t,server:r})];e={inline:__assign(__assign({},appSourceConfig.inline),null==o?void 0:o.inline),cors:__assign(__assign({},appSourceConfig.cors),null==o?void 0:o.cors)},a=e.inline,i=e.cors,u=__assign(__assign({},config_1.appHeaders),s),j.label=1;case 1:return j.trys.push([1,3,,4]),[4,(0,fetch_1.fetcher)(t,{headers:s,agent:agent})];case 2:return l=j.sent(),[3,4];case 3:return f=j.sent(),console.error(f),[3,4];case 4:if(!l)return[3,14];j.label=5;case 5:return j.trys.push([5,13,,14]),"undefined"==typeof process?[3,6]:(g=l,[3,8]);case 6:return[4,l.text()];case 7:g=j.sent(),j.label=8;case 8:if(!(p=g))return[2,renderErrorHtml({url:t,server:r,noPage:!0})];for(h=(0,cheerio_1.load)(p),n&&h("head").prepend('<base target="_self" href="'.concat("string"==typeof n?n:t,'">')),_=[],d=function(e){if(a[e]){h(e).attr("src",(function(r,t){return t&&_.push({key:e,attribute:"src",src:t+""}),t}))}},v=0,m=Object.keys(a);v<m.length;v++)H=m[v],d(H);b=0,y=_,j.label=9;case 9:return b<y.length?(w=y[b],H=w.key,x=w.attribute,C=w.src,A="".concat(H,"[").concat(x,'="').concat(C,'"]'),[4,mutateSource({key:A,src:C,safeMode:c},t,h,u)]):[3,12];case 10:j.sent(),h(A).removeAttr(x),j.label=11;case 11:return b++,[3,9];case 12:for(h('[src="undefined"]').removeAttr("src"),S=0,k=Object.keys(i);S<k.length;S++)H=k[S],i[H]&&h(H).attr("crossorigin",i[H]);return[2,h];case 13:return T=j.sent(),console.error(T),[3,14];case 14:return[2,renderErrorHtml({url:t,server:r,noPage:!0})]}}))}))}function fetchFrame(e){return __awaiter(this,void 0,void 0,(function(){var r,t;return __generator(this,(function(n){switch(n.label){case 0:return n.trys.push([0,2,,3]),[4,renderHtml(e,"undefined"!=typeof process)];case 1:return[2,null==(r=n.sent())?void 0:r.html()];case 2:return t=n.sent(),console.error(t),[3,3];case 3:return[2]}}))}))}function configureResourceControl(e){exports.appSourceConfig=appSourceConfig={cors:__assign(__assign({},config_1.defaultCorsConfig),null==e?void 0:e.cors),inline:__assign(__assign({},config_1.defaultInlineConfig),null==e?void 0:e.inline)}}function createIframe(e,r,t){var n=this;r.createIframe=function(e){return __awaiter(n,void 0,void 0,(function(){var t,n;return __generator(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,renderHtml(e,!0)];case 1:return(t=o.sent())&&r.status(200).send(t.html()),[3,3];case 2:return n=o.sent(),console.error(n),[3,3];case 3:return[2]}}))}))},t()}exports.fetchFrame=fetchFrame,exports.configureResourceControl=configureResourceControl,exports.default=createIframe;
//# sourceMappingURL=/sm/079f0f21768a5a36dd92b29a43a776c42c2b8485fc5fb991c89c150cc4176ef1.map