load-source
Version:
A simple function for load js/image/css/style
8 lines (7 loc) • 2.39 kB
JavaScript
/*!
* load-source v1.2.0
* A simple function for load js/image/css/style
* (c) 2021-2023 saqqdy<https://github.com/saqqdy>
* Released under the MIT License.
*/
import t from"mount-css";import e from"mount-image";import r from"mount-script";import n from"mount-style";function o(t,e,r,n){return new(r||(r=Promise))((function(o,i){function u(t){try{l(n.next(t))}catch(t){i(t)}}function c(t){try{l(n.throw(t))}catch(t){i(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof r?e:new r((function(t){t(e)}))).then(u,c)}l((n=n.apply(t,e||[])).next())}))}function i(t,e){var r,n,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:c(0),throw:c(1),return:c(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function c(c){return function(l){return function(c){if(r)throw new TypeError("Generator is already executing.");for(;i&&(i=0,c[0]&&(u=0)),u;)try{if(r=1,n&&(o=2&c[0]?n.return:c[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,c[1])).done)return o;switch(n=0,o&&(c=[2&c[0],o.value]),c[0]){case 0:case 1:o=c;break;case 4:return u.label++,{value:c[1],done:!1};case 5:u.label++,n=c[1],c=[0];continue;case 7:c=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==c[0]&&2!==c[0])){u=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]<o[3])){u.label=c[1];break}if(6===c[0]&&u.label<o[1]){u.label=o[1],o=c;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(c);break}o[2]&&u.ops.pop(),u.trys.pop();continue}c=e.call(t,u)}catch(t){c=[6,t],n=0}finally{r=o=0}if(5&c[0])throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}([c,l])}}}function u(u,c){var l,a;return o(this,void 0,void 0,(function(){var o,s;return i(this,(function(i){switch(i.label){case 0:if(!u)throw new Error("url is required");if(c||(c={}),"string"==typeof c)c={type:c};else if(!c.type){if(!(o=/\.(\w+)$/.exec(u))||!o[1])throw new Error("The url is not support");c.type=o[1]}if(null!==(l=c.force)&&void 0!==l||(c.force=!1),c.type&&(c.type=c.type.toLowerCase()),!["js","img","css","style"].includes(c.type))throw new Error("Not support type: ".concat(c.type));return[4,null===(a=(s={js:function(t){return r(t,c)},img:function(t){return e(t,c)},css:function(e){return t(e,c)},style:function(t){return n(t,c)}})[c.type])||void 0===a?void 0:a.call(s,u)];case 1:return[2,i.sent()]}}))}))}export{u as default};