UNPKG

micro-app

Version:

(<5kb) [📱iOS] Create Progressive Web App Dynamically.

7 lines • 4.76 kB
/*! * @ProjectName micro-app * @Version 1.0.2 * @Author lixinliang(https://github.com/lixinliang) * @Update 2016-12-07 9:12:02 am */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.microApp=e():t.microApp=e()}(this,function(){return function(t){function e(n){if(i[n])return i[n].exports;var r=i[n]={exports:{},id:n,loaded:!1};return t[n].call(r.exports,r,r.exports,e),r.loaded=!0,r.exports}var i={};return e.m=t,e.c=i,e.p="",e(0)}([function(t,e,i){"use strict";function n(t,e){if("string"!=typeof t||"function"!=typeof e)throw new TypeError("[micro-app] microApp.filter( name : String, method : Function );");var i=t.match(/\|/);if(i)throw new TypeError('[micro-app] "'+i[0]+'" is not allowed.');return n[t]=e,this}function r(t,e){var i=void 0,n=void 0;"string"==typeof t?i=n=t:(i=t[0],n=t[1]);var o=A.getAttribute(n);null!==o&&e(n,o,null);var a={get:function(){return o},set:function(t){return t!==o&&e(n,t,o),o=t},enumerable:!1};c(A,i,a),r[i]=!0,i!=n&&(c(A,n,a),r[n]=!0)}var o=document,a=o.head,c=Object.defineProperty.bind(Object),u=navigator.userAgent,p=/\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(u),l=!/iPad/i.test(u),s=/\bversion\/([0-9.]+(?: beta)?)(?: mobile(?:\/[a-z0-9]+)?)? safari\//i.test(u),f=parseInt((u.match(/\bcpu(?: iphone)? os /i.test(u)?/\bcpu(?: iphone)? os ([0-9._]+)/i:/\biph os ([0-9_]+)/i)||[,0])[1]),h=function(t){return a.appendChild(t),t},v=function(t){a.removeChild(t)},d=[[["72x72","144x144"],["76x76","152x152"]],[["57x57","114x114"],["60x60","120x120"]]],m={},b="device-width",g="device-height";l?(m[b]=320,m[g]=480,[{width:320,height:568},{width:375,height:667},{width:414,height:736}].forEach(function(t){matchMedia("("+b+":"+t.width+"px)and("+g+":"+t.height+"px)").matches&&(m[b]=t.width,m[g]=t.height)}),m[b]+="px",m[g]+="px"):(m[b]="768px",m[g]="1024px"),m["-webkit-device-pixel-ratio"]=devicePixelRatio;var x=function(t){if("icon"==t){var e=d[+l][+(f>6)][+(devicePixelRatio>1)];return{sizes:e}}if("splash"==t){var i=[];for(var n in m)i.push("("+n+":"+m[n]+")");if(!l||3==devicePixelRatio){var r="(orientation:landscape)";matchMedia(r).matches?i.push(r):i.push("(orientation:portrait)")}var o=i.join("and");return{media:o}}},y=o.createElement("div"),w=function(t){return y.innerHTML=t,y.firstElementChild},A=o.querySelector("script[micro-app]")||h(w("<script micro-app>")),P=function(t,e,i){return c(t,e,{value:i,writable:!1,enumerable:!1,configurable:!1})},j=Object.getOwnPropertyDescriptor(function(){},"name").configurable,E=function(t,e){var i=A[t];P(A,t,P(function(){var n=function(){var t=!0,n=e.call(this,{stopPropagation:function(){t=!1}},arguments);return t?i.apply(this,arguments):n};return j?P(n,"name",t):n}(),"toString",function(){return"function "+t+"() { [native code] }"}))},O=Element.prototype,S=O.setAttribute,C=O.removeAttribute,M=function(t,e,i){null===i?C.call(t,e):S.call(t,e,i)},k={}.toString.call([]),z="[object Base64]",R=function(t,e){var i=[];return function(r,o,a){var c=o instanceof Array?o.slice(0):null===o?[]:[o];i.forEach(function(t){v(t)}),i=[];for(var u=c.length,p=0;p<u;p++){var l=c[p];null!==l&&!function(){var r=w(t);if(l instanceof Object){M(r,e,void 0);for(var o in l)M(r,o,l[o])}else M(r,e,l);var a=r.getAttribute(e);a.indexOf("#")>-1&&!function(){var t=a.split("#");M(r,e,t[0]),M(r,"filter",t[1]);var i=!1;t[1].split("|").forEach(function(t){if(!i){var e=n[t];e&&(i=e.call(r)===!1)}})}(),i.push(h(r))}()}M(A,r,o instanceof Array?k:/^data:image/.test(o)?z:o)}};P(A,"version","1.0.2"),P(A,"filter",n),p&&s&&!function(){A.filter("precomposed",function(){this.rel="apple-touch-icon-precomposed"}).filter("autosize",function(){var t="apple-touch-startup-image"==this.getAttribute("rel")?"splash":"icon",e=x(t);if(e)for(var i in e)this.setAttribute(i,e[i])});var t=w('<meta name="apple-mobile-web-app-capable" content="yes">');r("capable",function(e,i,n){M(A,e,i),null===i&&v(t),null===n&&h(t)});var e=w('<meta name="apple-mobile-web-app-status-bar-style">');r(["statusBarStyle","status-bar-style"],function(t,i,n){M(A,t,i),M(e,"content",i),null===i&&v(e),null===n&&h(e)});var i=w('<meta name="apple-mobile-web-app-title">');r("title",function(t,e,n){M(A,t,e),M(i,"content",e),null===e&&v(i),null===n&&h(i)}),r("icon",R('<link rel="apple-touch-icon">',"href")),r("splash",R('<link rel="apple-touch-startup-image">',"href")),E("getAttribute",function(t,e){var i=e[0];if(A===this&&i in r)return t.stopPropagation(),A[i]}),E("setAttribute",function(t,e){var i=e[0],n=e[1];if(A===this&&i in r)return t.stopPropagation(),A[i]=n}),E("removeAttribute",function(t,e){var i=e[0];if(A===this&&i in r)return t.stopPropagation(),A[i]=null})}(),t.exports=window.microApp=A}])});