@w6s/cordova-import
Advanced tools
Comparing version 1.2.0 to 1.3.0
'use strict'; | ||
const config = { | ||
SDK_HOST: '//workplus.io/', | ||
SDK_NAME: 'cordova-import.js', | ||
// 只有作为es模块初始化时,才需配置 | ||
SDK_HOST: null, | ||
@@ -6,0 +9,0 @@ // 不同平台的 CordovaJs |
12
lib.js
@@ -12,3 +12,2 @@ 'use strict'; | ||
getCordovaJsUriByPlatform, | ||
inWorkPlus, | ||
} from './utils'; | ||
@@ -29,6 +28,2 @@ | ||
openInWorkPlus() { | ||
return inWorkPlus(this.userAgent); | ||
} | ||
/** | ||
@@ -40,6 +35,7 @@ * 返回注入的地址 | ||
getImportUri() { | ||
const platform = this.getCurrentPlatformByUserAgent(); | ||
invariant(platform, 'Please open in the correct webview'); | ||
// 以 es模块 初始化的情况下,不传人 SDK_HOST,默认只需要支持 local | ||
if (this.mustUseHttpModel() && this.config.SDK_HOST) { | ||
const platform = this.getCurrentPlatformByUserAgent(); | ||
invariant(platform, 'Please open in the correct webview'); | ||
if (this.mustUseHttpModel()) { | ||
return getCordovaJsUriByPlatform(this.config, platform); | ||
@@ -46,0 +42,0 @@ } |
/*! | ||
* @w6s/cordova-import.js v1.2.0 | ||
* @w6s/cordova-import.js v1.3.0 | ||
* (c) 2019 WorkPlusFE | ||
@@ -39,3 +39,5 @@ */ | ||
var config = { | ||
SDK_HOST: '//workplus.io/', | ||
SDK_NAME: 'cordova-import.js', | ||
// 只有作为es模块初始化时,才需配置 | ||
SDK_HOST: null, | ||
// 不同平台的 CordovaJs | ||
@@ -67,4 +69,4 @@ cordovajs: { | ||
}; | ||
var inWorkPlus = function inWorkPlus(userAgent) { | ||
return userAgent.indexOf('workplus') > -1; | ||
var inWorkPlus = function inWorkPlus() { | ||
return navigator.userAgent.indexOf('workplus') > -1; | ||
}; | ||
@@ -103,6 +105,4 @@ var scriptGenerator = function scriptGenerator(uri) { | ||
_createClass(CordovaImportLib, [{ | ||
key: "openInWorkPlus", | ||
value: function openInWorkPlus() { | ||
return inWorkPlus(this.userAgent); | ||
} | ||
key: "getImportUri", | ||
/** | ||
@@ -113,10 +113,7 @@ * 返回注入的地址 | ||
*/ | ||
}, { | ||
key: "getImportUri", | ||
value: function getImportUri() { | ||
var platform = this.getCurrentPlatformByUserAgent(); | ||
invariant(platform, 'Please open in the correct webview'); | ||
if (this.mustUseHttpModel()) { | ||
// 以 es模块 初始化的情况下,不传人 SDK_HOST,默认只需要支持 local | ||
if (this.mustUseHttpModel() && this.config.SDK_HOST) { | ||
var platform = this.getCurrentPlatformByUserAgent(); | ||
invariant(platform, 'Please open in the correct webview'); | ||
return getCordovaJsUriByPlatform(this.config, platform); | ||
@@ -159,2 +156,4 @@ } | ||
try { | ||
if (!inWorkPlus()) return; | ||
if (host) { | ||
@@ -165,3 +164,2 @@ invariant(isValidHost(host), 'Please enter a valid host, such as //workplus.io/'); | ||
var lib = new CordovaImportLib(host); | ||
if (!lib.openInWorkPlus()) return; | ||
var importUri = lib.getImportUri(); | ||
@@ -168,0 +166,0 @@ scriptGenerator(importUri); |
/*! | ||
* @w6s/cordova-import.js v1.2.0 | ||
* @w6s/cordova-import.js v1.3.0 | ||
* (c) 2019 WorkPlusFE | ||
*/ | ||
!function(t){"function"==typeof define&&define.amd?define(t):t()}(function(){"use strict";var o=function(t,e,r,n,o,i,a,u){if(!t){var c;if(void 0===e)c=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var f=[r,n,o,i,a,u],s=0;(c=Error(e.replace(/%s/g,function(){return f[s++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}};function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var $t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function a(t){return!!~t.indexOf("android")}var t,u=(function(t,e){var n="__lodash_hash_undefined__",o=9007199254740991,r="[object Arguments]",i="[object AsyncFunction]",a="[object Function]",u="[object GeneratorFunction]",c="[object Null]",d="[object Object]",f="[object Proxy]",s="[object Undefined]",l=/^\[object .+?Constructor\]$/,p=/^(?:0|[1-9]\d*)$/,v={};v["[object Float32Array]"]=v["[object Float64Array]"]=v["[object Int8Array]"]=v["[object Int16Array]"]=v["[object Int32Array]"]=v["[object Uint8Array]"]=v["[object Uint8ClampedArray]"]=v["[object Uint16Array]"]=v["[object Uint32Array]"]=!0,v[r]=v["[object Array]"]=v["[object ArrayBuffer]"]=v["[object Boolean]"]=v["[object DataView]"]=v["[object Date]"]=v["[object Error]"]=v[a]=v["[object Map]"]=v["[object Number]"]=v[d]=v["[object RegExp]"]=v["[object Set]"]=v["[object String]"]=v["[object WeakMap]"]=!1;var h="object"==typeof $t&&$t&&$t.Object===Object&&$t,y="object"==typeof self&&self&&self.Object===Object&&self,_=h||y||Function("return this")(),b=e&&!e.nodeType&&e,g=b&&t&&!t.nodeType&&t,j=g&&g.exports===b,m=j&&h.process,w=function(){try{var t=g&&g.require&&g.require("util").types;return t||m&&m.binding&&m.binding("util")}catch(t){}}(),A=w&&w.isTypedArray;var O,z,S,x=Array.prototype,k=Object.prototype,U=_["__core-js_shared__"],E=Function.prototype.toString,P=k.hasOwnProperty,T=(O=/[^.]+$/.exec(U&&U.keys&&U.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"",I=k.toString,F=E.call(Object),M=RegExp("^"+E.call(P).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),B=j?_.Buffer:void 0,C=_.Symbol,D=_.Uint8Array,$=B?B.allocUnsafe:void 0,H=(z=Object.getPrototypeOf,function(t){return z(S(t))}),K=(S=Object).create,N=k.propertyIsEnumerable,R=x.splice,L=C?C.toStringTag:void 0,W=function(){try{var t=yt(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),q=B?B.isBuffer:void 0,V=Math.max,G=Date.now,J=yt(_,"Map"),Q=yt(Object,"create"),X=function(t){if(!Pt(t))return{};if(K)return K(t);Y.prototype=t;var e=new Y;return Y.prototype=void 0,e};function Y(){}function Z(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function tt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function et(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function rt(t){var e=this.__data__=new tt(t);this.size=e.size}function nt(t,e){var r=St(t),n=!r&&zt(t),o=!r&&!n&&kt(t),i=!r&&!n&&!o&&Ft(t),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],c=u.length;for(var f in t)!e&&!P.call(t,f)||a&&("length"==f||o&&("offset"==f||"parent"==f)||i&&("buffer"==f||"byteLength"==f||"byteOffset"==f)||_t(f,c))||u.push(f);return u}function ot(t,e,r){(void 0===r||Ot(t[e],r))&&(void 0!==r||e in t)||at(t,e,r)}function it(t,e){for(var r=t.length;r--;)if(Ot(t[r][0],e))return r;return-1}function at(t,e,r){"__proto__"==e&&W?W(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}Z.prototype.clear=function(){this.__data__=Q?Q(null):{},this.size=0},Z.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Z.prototype.get=function(t){var e=this.__data__;if(Q){var r=e[t];return r===n?void 0:r}return P.call(e,t)?e[t]:void 0},Z.prototype.has=function(t){var e=this.__data__;return Q?void 0!==e[t]:P.call(e,t)},Z.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Q&&void 0===e?n:e,this},tt.prototype.clear=function(){this.__data__=[],this.size=0},tt.prototype.delete=function(t){var e=this.__data__,r=it(e,t);return 0<=r&&(r==e.length-1?e.pop():R.call(e,r,1),--this.size,!0)},tt.prototype.get=function(t){var e=this.__data__,r=it(e,t);return r<0?void 0:e[r][1]},tt.prototype.has=function(t){return-1<it(this.__data__,t)},tt.prototype.set=function(t,e){var r=this.__data__,n=it(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this},et.prototype.clear=function(){this.size=0,this.__data__={hash:new Z,map:new(J||tt),string:new Z}},et.prototype.delete=function(t){var e=dt(this,t).delete(t);return this.size-=e?1:0,e},et.prototype.get=function(t){return dt(this,t).get(t)},et.prototype.has=function(t){return dt(this,t).has(t)},et.prototype.set=function(t,e){var r=dt(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this},rt.prototype.clear=function(){this.__data__=new tt,this.size=0},rt.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},rt.prototype.get=function(t){return this.__data__.get(t)},rt.prototype.has=function(t){return this.__data__.has(t)},rt.prototype.set=function(t,e){var r=this.__data__;if(r instanceof tt){var n=r.__data__;if(!J||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new et(n)}return r.set(t,e),this.size=r.size,this};var ut,ct=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),a=i.length;a--;){var u=i[ut?a:++n];if(!1===e(o[u],u,o))break}return t};function ft(t){return null==t?void 0===t?s:c:L&&L in Object(t)?function(t){var e=P.call(t,L),r=t[L];try{var n=!(t[L]=void 0)}catch(t){}var o=I.call(t);n&&(e?t[L]=r:delete t[L]);return o}(t):I.call(t)}function st(t){return Tt(t)&&ft(t)==r}function lt(t){return!(!Pt(t)||(e=t,T&&T in e))&&(Ut(t)?M:l).test(function(t){if(null!=t){try{return E.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t));var e}function pt(t){if(!Pt(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=bt(t),r=[];for(var n in t)("constructor"!=n||!e&&P.call(t,n))&&r.push(n);return r}function vt(n,o,i,a,u){n!==o&&ct(o,function(t,e){if(u=u||new rt,Pt(t))!function(t,e,r,n,o,i,a){var u=gt(t,r),c=gt(e,r),f=a.get(c);if(f)return ot(t,r,f);var s=i?i(u,c,r+"",t,e,a):void 0,l=void 0===s;if(l){var p=St(c),v=!p&&kt(c),h=!p&&!v&&Ft(c);s=c,p||v||h?s=St(u)?u:function(t){return Tt(t)&&xt(t)}(u)?function(t,e){var r=-1,n=t.length;e=e||Array(n);for(;++r<n;)e[r]=t[r];return e}(u):v?function(t,e){if(e)return t.slice();var r=t.length,n=$?$(r):new t.constructor(r);return t.copy(n),n}(c,!(l=!1)):h?function(t,e){var r=e?function(t){var e=new t.constructor(t.byteLength);return new D(e).set(new D(t)),e}(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(c,!(l=!1)):[]:function(t){if(!Tt(t)||ft(t)!=d)return!1;var e=H(t);if(null===e)return!0;var r=P.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&E.call(r)==F}(c)||zt(c)?zt(s=u)?s=function(t){return function(t,e,r,n){var o=!r;r=r||{};var i=-1,a=e.length;for(;++i<a;){var u=e[i],c=n?n(r[u],t[u],u,r,t):void 0;void 0===c&&(c=t[u]),o?at(r,u,c):(l=c,p=(f=r)[s=u],P.call(f,s)&&Ot(p,l)&&(void 0!==l||s in f)||at(f,s,l))}var f,s,l,p;return r}(t,Mt(t))}(u):Pt(u)&&!Ut(u)||(s=function(t){return"function"!=typeof t.constructor||bt(t)?{}:X(H(t))}(c)):l=!1}l&&(a.set(c,s),o(s,c,n,i,a),a.delete(c));ot(t,r,s)}(n,o,e,i,vt,a,u);else{var r=a?a(gt(n,e),t,e+"",n,o,u):void 0;void 0===r&&(r=t),ot(n,e,r)}},Mt)}function ht(t,e){return At((i=t,u=Dt,a=V(void 0===(a=e)?i.length-1:a,0),function(){for(var t=arguments,e=-1,r=V(t.length-a,0),n=Array(r);++e<r;)n[e]=t[a+e];e=-1;for(var o=Array(a+1);++e<a;)o[e]=t[e];return o[a]=u(n),function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}(i,this,o)}),t+"");var i,a,u}function dt(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function yt(t,e){var r,n,o=(n=e,null==(r=t)?void 0:r[n]);return lt(o)?o:void 0}function _t(t,e){var r=typeof t;return!!(e=null==e?o:e)&&("number"==r||"symbol"!=r&&p.test(t))&&-1<t&&t%1==0&&t<e}function bt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||k)}function gt(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}var jt,mt,wt,At=(jt=W?function(t,e){return W(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:Dt,wt=mt=0,function(){var t=G(),e=16-(t-wt);if(wt=t,0<e){if(800<=++mt)return arguments[0]}else mt=0;return jt.apply(void 0,arguments)});function Ot(t,e){return t===e||t!=t&&e!=e}var zt=st(function(){return arguments}())?st:function(t){return Tt(t)&&P.call(t,"callee")&&!N.call(t,"callee")},St=Array.isArray;function xt(t){return null!=t&&Et(t.length)&&!Ut(t)}var kt=q||function(){return!1};function Ut(t){if(!Pt(t))return!1;var e=ft(t);return e==a||e==u||e==i||e==f}function Et(t){return"number"==typeof t&&-1<t&&t%1==0&&t<=o}function Pt(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function Tt(t){return null!=t&&"object"==typeof t}var It,Ft=A?(It=A,function(t){return It(t)}):function(t){return Tt(t)&&Et(t.length)&&!!v[ft(t)]};function Mt(t){return xt(t)?nt(t,!0):pt(t)}var Bt,Ct=(Bt=function(t,e,r){vt(t,e,r)},ht(function(t,e){var r=-1,n=e.length,o=1<n?e[n-1]:void 0,i=2<n?e[2]:void 0;for(o=3<Bt.length&&"function"==typeof o?(n--,o):void 0,i&&function(t,e,r){if(!Pt(r))return!1;var n=typeof e;return!!("number"==n?xt(r)&&_t(e,r.length):"string"==n&&e in r)&&Ot(r[e],t)}(e[0],e[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++r<n;){var a=e[r];a&&Bt(t,a,r,o)}return t}));function Dt(t){return t}t.exports=Ct}(t={exports:{}},t.exports),t.exports),c={SDK_HOST:"//workplus.io/",cordovajs:{iOS:"ios.cordova.min.js",android:"android.cordova.min.js",local:"applocal://cordova.min.js"},pcSDKUri:""},f=function(){function e(t){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=t?u(c,{SDK_HOST:t}):c}var t,r,n;return t=e,(r=[{key:"openInWorkPlus",value:function(){return!!~this.userAgent.indexOf("workplus")}},{key:"getImportUri",value:function(){var t,e,r=this.getCurrentPlatformByUserAgent();return o(r,"Please open in the correct webview"),this.mustUseHttpModel()?(e=r,"".concat((t=this.config).SDK_HOST).concat(t.cordovajs[e])):this.config.cordovajs.local}},{key:"mustUseHttpModel",value:function(){return!(!self.frameElement||"IFRAME"!=self.frameElement.tagName)||!("https:"!==window.location.protocol||!a(this.userAgent))}},{key:"getCurrentPlatformByUserAgent",value:function(){return~this.userAgent.indexOf("iphone")?"iOS":!!a(this.userAgent)&&"android"}},{key:"userAgent",get:function(){return window.navigator.userAgent.toLowerCase()}}])&&i(t.prototype,r),n&&i(t,n),e}();!function(){try{var t=new f;if(!t.openInWorkPlus())return;var e=t.getImportUri();r=e,(n=document.createElement("script")).setAttribute("type","text/javascript"),n.setAttribute("src",r),document.getElementsByTagName("head")[0].appendChild(n)}catch(t){o(!1,t)}var r,n}()}); | ||
!function(t){"function"==typeof define&&define.amd?define(t):t()}(function(){"use strict";var o=function(t,e,r,n,o,i,a,u){if(!t){var c;if(void 0===e)c=Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var f=[r,n,o,i,a,u],s=0;(c=Error(e.replace(/%s/g,function(){return f[s++]}))).name="Invariant Violation"}throw c.framesToPop=1,c}};function i(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}var Nt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function a(t){return!!~t.indexOf("android")}function u(){var t=function(){for(var t=document.getElementsByTagName("script"),e="",r=0;r<t.length;r+=1){var n=t[r];if(n.src&&~n.src.indexOf("/".concat(f.SDK_NAME))){e=n.src;break}}return e}();if(t)return t.split(f.SDK_NAME)[0]}var t,c=(function(t,e){var n="__lodash_hash_undefined__",o=9007199254740991,r="[object Arguments]",i="[object AsyncFunction]",a="[object Function]",u="[object GeneratorFunction]",c="[object Null]",d="[object Object]",f="[object Proxy]",s="[object Undefined]",l=/^\[object .+?Constructor\]$/,p=/^(?:0|[1-9]\d*)$/,v={};v["[object Float32Array]"]=v["[object Float64Array]"]=v["[object Int8Array]"]=v["[object Int16Array]"]=v["[object Int32Array]"]=v["[object Uint8Array]"]=v["[object Uint8ClampedArray]"]=v["[object Uint16Array]"]=v["[object Uint32Array]"]=!0,v[r]=v["[object Array]"]=v["[object ArrayBuffer]"]=v["[object Boolean]"]=v["[object DataView]"]=v["[object Date]"]=v["[object Error]"]=v[a]=v["[object Map]"]=v["[object Number]"]=v[d]=v["[object RegExp]"]=v["[object Set]"]=v["[object String]"]=v["[object WeakMap]"]=!1;var h="object"==typeof Nt&&Nt&&Nt.Object===Object&&Nt,_="object"==typeof self&&self&&self.Object===Object&&self,y=h||_||Function("return this")(),b=e&&!e.nodeType&&e,g=b&&t&&!t.nodeType&&t,j=g&&g.exports===b,m=j&&h.process,w=function(){try{var t=g&&g.require&&g.require("util").types;return t||m&&m.binding&&m.binding("util")}catch(t){}}(),A=w&&w.isTypedArray;var O,S,z,E=Array.prototype,x=Object.prototype,T=y["__core-js_shared__"],U=Function.prototype.toString,k=x.hasOwnProperty,D=(O=/[^.]+$/.exec(T&&T.keys&&T.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"",M=x.toString,P=U.call(Object),I=RegExp("^"+U.call(k).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),B=j?y.Buffer:void 0,F=y.Symbol,K=y.Uint8Array,N=B?B.allocUnsafe:void 0,C=(S=Object.getPrototypeOf,function(t){return S(z(t))}),$=(z=Object).create,H=x.propertyIsEnumerable,R=E.splice,L=F?F.toStringTag:void 0,q=function(){try{var t=_t(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),V=B?B.isBuffer:void 0,G=Math.max,W=Date.now,J=_t(y,"Map"),Q=_t(Object,"create"),X=function(t){if(!kt(t))return{};if($)return $(t);Y.prototype=t;var e=new Y;return Y.prototype=void 0,e};function Y(){}function Z(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function tt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function et(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function rt(t){var e=this.__data__=new tt(t);this.size=e.size}function nt(t,e){var r=zt(t),n=!r&&St(t),o=!r&&!n&&xt(t),i=!r&&!n&&!o&&Pt(t),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],c=u.length;for(var f in t)!e&&!k.call(t,f)||a&&("length"==f||o&&("offset"==f||"parent"==f)||i&&("buffer"==f||"byteLength"==f||"byteOffset"==f)||yt(f,c))||u.push(f);return u}function ot(t,e,r){(void 0===r||Ot(t[e],r))&&(void 0!==r||e in t)||at(t,e,r)}function it(t,e){for(var r=t.length;r--;)if(Ot(t[r][0],e))return r;return-1}function at(t,e,r){"__proto__"==e&&q?q(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}Z.prototype.clear=function(){this.__data__=Q?Q(null):{},this.size=0},Z.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Z.prototype.get=function(t){var e=this.__data__;if(Q){var r=e[t];return r===n?void 0:r}return k.call(e,t)?e[t]:void 0},Z.prototype.has=function(t){var e=this.__data__;return Q?void 0!==e[t]:k.call(e,t)},Z.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Q&&void 0===e?n:e,this},tt.prototype.clear=function(){this.__data__=[],this.size=0},tt.prototype.delete=function(t){var e=this.__data__,r=it(e,t);return 0<=r&&(r==e.length-1?e.pop():R.call(e,r,1),--this.size,!0)},tt.prototype.get=function(t){var e=this.__data__,r=it(e,t);return r<0?void 0:e[r][1]},tt.prototype.has=function(t){return-1<it(this.__data__,t)},tt.prototype.set=function(t,e){var r=this.__data__,n=it(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this},et.prototype.clear=function(){this.size=0,this.__data__={hash:new Z,map:new(J||tt),string:new Z}},et.prototype.delete=function(t){var e=dt(this,t).delete(t);return this.size-=e?1:0,e},et.prototype.get=function(t){return dt(this,t).get(t)},et.prototype.has=function(t){return dt(this,t).has(t)},et.prototype.set=function(t,e){var r=dt(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this},rt.prototype.clear=function(){this.__data__=new tt,this.size=0},rt.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},rt.prototype.get=function(t){return this.__data__.get(t)},rt.prototype.has=function(t){return this.__data__.has(t)},rt.prototype.set=function(t,e){var r=this.__data__;if(r instanceof tt){var n=r.__data__;if(!J||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new et(n)}return r.set(t,e),this.size=r.size,this};var ut,ct=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),a=i.length;a--;){var u=i[ut?a:++n];if(!1===e(o[u],u,o))break}return t};function ft(t){return null==t?void 0===t?s:c:L&&L in Object(t)?function(t){var e=k.call(t,L),r=t[L];try{var n=!(t[L]=void 0)}catch(t){}var o=M.call(t);n&&(e?t[L]=r:delete t[L]);return o}(t):M.call(t)}function st(t){return Dt(t)&&ft(t)==r}function lt(t){return!(!kt(t)||(e=t,D&&D in e))&&(Tt(t)?I:l).test(function(t){if(null!=t){try{return U.call(t)}catch(t){}try{return t+""}catch(t){}}return""}(t));var e}function pt(t){if(!kt(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=bt(t),r=[];for(var n in t)("constructor"!=n||!e&&k.call(t,n))&&r.push(n);return r}function vt(n,o,i,a,u){n!==o&&ct(o,function(t,e){if(u=u||new rt,kt(t))!function(t,e,r,n,o,i,a){var u=gt(t,r),c=gt(e,r),f=a.get(c);if(f)return ot(t,r,f);var s=i?i(u,c,r+"",t,e,a):void 0,l=void 0===s;if(l){var p=zt(c),v=!p&&xt(c),h=!p&&!v&&Pt(c);s=c,p||v||h?s=zt(u)?u:function(t){return Dt(t)&&Et(t)}(u)?function(t,e){var r=-1,n=t.length;e=e||Array(n);for(;++r<n;)e[r]=t[r];return e}(u):v?function(t,e){if(e)return t.slice();var r=t.length,n=N?N(r):new t.constructor(r);return t.copy(n),n}(c,!(l=!1)):h?function(t,e){var r=e?function(t){var e=new t.constructor(t.byteLength);return new K(e).set(new K(t)),e}(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(c,!(l=!1)):[]:function(t){if(!Dt(t)||ft(t)!=d)return!1;var e=C(t);if(null===e)return!0;var r=k.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&U.call(r)==P}(c)||St(c)?St(s=u)?s=function(t){return function(t,e,r,n){var o=!r;r=r||{};var i=-1,a=e.length;for(;++i<a;){var u=e[i],c=n?n(r[u],t[u],u,r,t):void 0;void 0===c&&(c=t[u]),o?at(r,u,c):(l=c,p=(f=r)[s=u],k.call(f,s)&&Ot(p,l)&&(void 0!==l||s in f)||at(f,s,l))}var f,s,l,p;return r}(t,It(t))}(u):kt(u)&&!Tt(u)||(s=function(t){return"function"!=typeof t.constructor||bt(t)?{}:X(C(t))}(c)):l=!1}l&&(a.set(c,s),o(s,c,n,i,a),a.delete(c));ot(t,r,s)}(n,o,e,i,vt,a,u);else{var r=a?a(gt(n,e),t,e+"",n,o,u):void 0;void 0===r&&(r=t),ot(n,e,r)}},It)}function ht(t,e){return At((i=t,u=Kt,a=G(void 0===(a=e)?i.length-1:a,0),function(){for(var t=arguments,e=-1,r=G(t.length-a,0),n=Array(r);++e<r;)n[e]=t[a+e];e=-1;for(var o=Array(a+1);++e<a;)o[e]=t[e];return o[a]=u(n),function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}(i,this,o)}),t+"");var i,a,u}function dt(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function _t(t,e){var r,n,o=(n=e,null==(r=t)?void 0:r[n]);return lt(o)?o:void 0}function yt(t,e){var r=typeof t;return!!(e=null==e?o:e)&&("number"==r||"symbol"!=r&&p.test(t))&&-1<t&&t%1==0&&t<e}function bt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||x)}function gt(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}var jt,mt,wt,At=(jt=q?function(t,e){return q(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:Kt,wt=mt=0,function(){var t=W(),e=16-(t-wt);if(wt=t,0<e){if(800<=++mt)return arguments[0]}else mt=0;return jt.apply(void 0,arguments)});function Ot(t,e){return t===e||t!=t&&e!=e}var St=st(function(){return arguments}())?st:function(t){return Dt(t)&&k.call(t,"callee")&&!H.call(t,"callee")},zt=Array.isArray;function Et(t){return null!=t&&Ut(t.length)&&!Tt(t)}var xt=V||function(){return!1};function Tt(t){if(!kt(t))return!1;var e=ft(t);return e==a||e==u||e==i||e==f}function Ut(t){return"number"==typeof t&&-1<t&&t%1==0&&t<=o}function kt(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function Dt(t){return null!=t&&"object"==typeof t}var Mt,Pt=A?(Mt=A,function(t){return Mt(t)}):function(t){return Dt(t)&&Ut(t.length)&&!!v[ft(t)]};function It(t){return Et(t)?nt(t,!0):pt(t)}var Bt,Ft=(Bt=function(t,e,r){vt(t,e,r)},ht(function(t,e){var r=-1,n=e.length,o=1<n?e[n-1]:void 0,i=2<n?e[2]:void 0;for(o=3<Bt.length&&"function"==typeof o?(n--,o):void 0,i&&function(t,e,r){if(!kt(r))return!1;var n=typeof e;return!!("number"==n?Et(r)&&yt(e,r.length):"string"==n&&e in r)&&Ot(r[e],t)}(e[0],e[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++r<n;){var a=e[r];a&&Bt(t,a,r,o)}return t}));function Kt(t){return t}t.exports=Ft}(t={exports:{}},t.exports),t.exports),f={SDK_NAME:"cordova-import.js",SDK_HOST:null,cordovajs:{iOS:"ios.cordova.min.js",android:"android.cordova.min.js",local:"applocal://cordova.min.js"},pcSDKUri:""},s=function(){function e(t){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),this.config=t?c(f,{SDK_HOST:t}):f}var t,r,n;return t=e,(r=[{key:"getImportUri",value:function(){if(this.mustUseHttpModel()&&this.config.SDK_HOST){var t=this.getCurrentPlatformByUserAgent();return o(t,"Please open in the correct webview"),r=t,"".concat((e=this.config).SDK_HOST).concat(e.cordovajs[r])}var e,r;return this.config.cordovajs.local}},{key:"mustUseHttpModel",value:function(){return!(!self.frameElement||"IFRAME"!=self.frameElement.tagName)||!("https:"!==window.location.protocol||!a(this.userAgent))}},{key:"getCurrentPlatformByUserAgent",value:function(){return~this.userAgent.indexOf("iphone")?"iOS":!!a(this.userAgent)&&"android"}},{key:"userAgent",get:function(){return window.navigator.userAgent.toLowerCase()}}])&&i(t.prototype,r),n&&i(t,n),e}();!function(){try{if(!~navigator.userAgent.indexOf("workplus"))return;var t=u(),e=new s(t).getImportUri();r=e,(n=document.createElement("script")).setAttribute("type","text/javascript"),n.setAttribute("src",r),document.getElementsByTagName("head")[0].appendChild(n)}catch(t){o(!1,t)}var r,n}()}); |
@@ -5,6 +5,12 @@ 'use strict'; | ||
import CordovaImportLib from './lib'; | ||
import { scriptGenerator, isValidHost } from './utils'; | ||
import { | ||
scriptGenerator, | ||
isValidHost, | ||
inWorkPlus, | ||
} from './utils'; | ||
function cordovaImportInit(host) { | ||
try { | ||
if (!inWorkPlus()) return; | ||
if (host) { | ||
@@ -15,5 +21,2 @@ invariant(isValidHost(host), 'Please enter a valid host, such as //workplus.io/'); | ||
const lib = new CordovaImportLib(host); | ||
if (!lib.openInWorkPlus()) return; | ||
const importUri = lib.getImportUri(); | ||
@@ -20,0 +23,0 @@ scriptGenerator(importUri); |
{ | ||
"name": "@w6s/cordova-import", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Automatic CordovaJs import util.", | ||
@@ -5,0 +5,0 @@ "main": "lib/@w6s/cordova-import-es.js", |
@@ -1,2 +0,2 @@ | ||
# cordova-import [![Build Status](https://travis-ci.org/WorkPlusFE/cordova-import.svg?branch=master)](https://travis-ci.org/WorkPlusFE/cordova-import) | ||
# cordova-import [![Build Status](https://travis-ci.org/WorkPlusFE/cordova-import.svg?branch=master)](https://travis-ci.org/WorkPlusFE/cordova-import) [![npm version](https://badge.fury.io/js/%40w6s%2Fcordova-import.svg)](https://badge.fury.io/js/%40w6s%2Fcordova-import) | ||
@@ -7,6 +7,8 @@ > `cordova-import.js`提供在 WorkPlus WebView 中注入 cordova 的能力,默认以`local`的方式注入,但同时会根据不同的环境,例如轻应用的访问协议(http、https),是否在 iframe 内打开等,自动选择最佳的注入方式,开发者无需关注过多的注入细节,开箱即用,一步到位! | ||
**重要** 请确保脚本`cordova-import.js`与`ios.cordova.min.js`及`android.cordova.min.js`放置到同一个资源目录,以确保脚本的正确加载。并且,为了提高资源的下载速度,请配置相关服务端的资源压缩策略,例如开启`gzip`。 | ||
相关脚本可在[Release页面](https://github.com/WorkPlusFE/cordova-import/releases/tag/v1.1)进行下载。 | ||
#### 一、通过 script 标签直接引入 | ||
当前该脚本的发布地址为`//workplus.io/cordova-import.js`,可在[Release页面](https://github.com/WorkPlusFE/cordova-import/releases/tag/v1.1)进行下载。 | ||
> 单页面应用(SPA)引入一次即可,多页面应用还需在每个页面都单独引入 | ||
@@ -13,0 +15,0 @@ |
@@ -5,11 +5,14 @@ 'use strict'; | ||
import CordovaImportLib from './lib'; | ||
import { scriptGenerator } from './utils'; | ||
import { | ||
scriptGenerator, | ||
getAssetDomainUrl, | ||
inWorkPlus, | ||
} from './utils'; | ||
function cordovaImportInit() { | ||
try { | ||
const lib = new CordovaImportLib(); | ||
if (!inWorkPlus()) return; | ||
// 非 WorkPlus webview 不进行任何处理 | ||
if (!lib.openInWorkPlus()) return; | ||
const sdkUri = getAssetDomainUrl(); // 自动获取资源路径 | ||
const lib = new CordovaImportLib(sdkUri); | ||
const importUri = lib.getImportUri(); | ||
@@ -16,0 +19,0 @@ scriptGenerator(importUri); |
26
utils.js
'use strict'; | ||
import isString from 'lodash.isstring'; | ||
import config from './config'; | ||
@@ -16,3 +17,3 @@ // 是否为 https 模式 | ||
export const inWorkPlus = userAgent => userAgent.indexOf('workplus') > -1; | ||
export const inWorkPlus = () => navigator.userAgent.indexOf('workplus') > -1; | ||
@@ -34,2 +35,23 @@ export const scriptGenerator = (uri) => { | ||
return true; | ||
}; | ||
}; | ||
const getSDKScriptTagSrc = () => { | ||
const scripts = document.getElementsByTagName("script"); | ||
let matchScriptSrc = ''; | ||
for (let i = 0; i < scripts.length; i += 1) { | ||
const script = scripts[i]; | ||
if (script.src && script.src.indexOf(`/${config.SDK_NAME}`) > -1) { | ||
matchScriptSrc = script.src; | ||
break; | ||
} | ||
} | ||
return matchScriptSrc; | ||
}; | ||
export const getAssetDomainUrl = () => { | ||
const currentScriptSrc = getSDKScriptTagSrc(); | ||
if (currentScriptSrc) { | ||
return currentScriptSrc.split(config.SDK_NAME)[0]; | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
34938
562
73
0