UNPKG

@auraxy/cef-bridge

Version:

cefCore, boundAsync, cefEnviroment, cefPopupEnvironment, cefJsWebBridge

10 lines (8 loc) 13.6 kB
/** * Bundle of @auraxy/cef-bridge * Generated: 2021-06-25 * Version: 3.0.2 * License: MIT * Author: 2631541504@qq.com */ !function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e=e||self).CefBridge={})}(this,function(e){"use strict";function n(n,e){var t,r=Object.keys(n);return Object.getOwnPropertySymbols&&(t=Object.getOwnPropertySymbols(n),e&&(t=t.filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable})),r.push.apply(r,t)),r}function i(r){for(var e=1;e<arguments.length;e++){var o=null!=arguments[e]?arguments[e]:{};e%2?n(Object(o),!0).forEach(function(e){var n,t;n=r,e=o[t=e],t in n?Object.defineProperty(n,t,{value:e,enumerable:!0,configurable:!0,writable:!0}):n[t]=e}):Object.getOwnPropertyDescriptors?Object.defineProperties(r,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach(function(e){Object.defineProperty(r,e,Object.getOwnPropertyDescriptor(o,e))})}return r}function c(e,n,t,r,o,i,u){try{var a=e[i](u),c=a.value}catch(e){return void t(e)}a.done?n(c):Promise.resolve(c).then(r,o)}function t(a){return function(){var e=this,u=arguments;return new Promise(function(n,t){var r=a.apply(e,u);function o(e){c(r,n,t,o,i,"next",e)}function i(e){c(r,n,t,o,i,"throw",e)}o(void 0)})}}function o(e,n){for(var t,r=0;r<e.length;r++)if(n(e[r],r,e)){t=r;break}return t}function u(e){for(var n;e(n=Math.random().toFixed(6)););return n}function a(){var t=this,r=[];t.publish=function(){var n=arguments;r.forEach(function(e){e.callback.apply(t,n)})},t.subscribe=function(e){var n=u(function(n){return void 0!==o(r,function(e){return e.id===n})});return r.push({id:n,callback:e}),console.log("simple-observer: Start subscribe!"),n},t.unsubscribe=function(e){(e instanceof Array?e:[e]).forEach(function(n){var e=o(r,function(e){return e.id===n||e.callback===n});void 0!==e&&r.splice(e,1)}),console.log("simple-observer: Unsubscribe success!")},t.getSubscribersCount=function(){return r.length}}var r=new Map;function s(e,n){e="singleton-any-".concat(e||"default");return r.has(e)||r.set(e,n?n():{}),r.get(e)}function f(e){if("number"==typeof e){if(isNaN(e))return"NaN";if(!isFinite(e))return"Infinity"}return JSON.stringify(e)}function l(n){try{return"undefined"===n?void 0:"NaN"===n?NaN:"Infinity"===n?1/0:JSON.parse(n)}catch(e){return n}}function d(e){return 22===e.code||0<=e.name.toLowerCase().indexOf("quota")}function p(){try{var e=window.localStorage,n="storage-available";e.setItem(n,n);var t=e.getItem(n)===n;return e.removeItem(n),t}catch(e){return d(e)&&0<window.localStorage.length}}function y(){try{return document.cookie||!0}catch(e){return!1}}var h=Object.freeze({stringifyJSON:f,parseJSON:l,isStorageExceeded:d,storageAvailable:p,cookieAvailable:y}),v=function(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")},g=function(e,n,t){return n&&m(e.prototype,n),t&&m(e,t),e};function m(e,n){for(var t=0;t<n.length;t++){var r=n[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}var w=(g(b,null,[{key:"keys",value:function(){return document.cookie.match(/[^\s=;]+(?==)/g)}},{key:"values",value:function(){return b.keys().map(function(e){return b.get(e)})}},{key:"entries",value:function(){return b.keys().map(function(e){return[e,b.get(e)]})}},{key:"forEach",value:function(n){b.keys().forEach(function(e){return n(b.get(e),e,b)})}},{key:"set",value:function(e,n){var t=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},r=t.maxAgeMs,o=void 0===r?"Infinity":r,i=t.domain,r=t.secure,t=t.path,e=e+"="+f("string"==typeof n?encodeURIComponent(n):n);o&&(n=new Date,o=isFinite(o)?+o:31536e6,n.setTime(n.getTime()+o),e+=";expires="+n.toUTCString()),e+=";path="+(t||"/"),i&&(e+=";domain="+i),r&&(e+=";secure="+(r?"secure":"")),document.cookie=e}},{key:"get",value:function(e){e=new RegExp("(^| )"+e+"=([^;]*)(;|$)"),e=document.cookie.match(e);if(e){e=l(e[2]);return"string"==typeof e?decodeURIComponent(e):e}return null}},{key:"has",value:function(n){return b.keys().some(function(e){return e===n})}},{key:"delete",value:function(e){return!!b.has(e)&&(b.set(e,b.get(e),{maxAgeMs:-1}),!0)}},{key:"clear",value:function(){b.keys().forEach(function(e){b.delete(e)})}},{key:"size",get:function(){return b.keys().length}}]),b);function b(){v(this,b)}var k=(g(C,null,[{key:"keys",value:function(){return Object.keys(localStorage)}},{key:"values",value:function(){return C.keys().map(function(e){return C.get(e)})}},{key:"entries",value:function(){return C.keys().map(function(e){return[e,C.get(e)]})}},{key:"forEach",value:function(n){C.keys().forEach(function(e){return n(C.get(e),e,C)})}},{key:"set",value:function(e,n){n=f(n);localStorage.setItem(e,n)}},{key:"get",value:function(e){return l(localStorage.getItem(e))}},{key:"has",value:function(e){return null!==localStorage.getItem(e)}},{key:"delete",value:function(e){return!!C.has(e)&&(localStorage.removeItem(e),!0)}},{key:"clear",value:function(){localStorage.clear()}},{key:"addHandler",value:function(n){if(window.addEventListener){if(n instanceof Function){var e=function(e){n({key:e.key,oldValue:l(e.oldValue),newValue:l(e.newValue),event:e})};return window.addEventListener("storage",e),e}console.warn("(LocalStorage) Handler add failed: Parameter `storageHandler` should be a function")}return null}},{key:"removeHandler",value:function(e){var n;window.removeEventListener&&(n=function(e){return e instanceof Function?window.removeEventListener("storage",e):""},e instanceof Array?e.forEach(n):n(e))}},{key:"size",get:function(){return C.keys().length}}]),C);function C(){v(this,C)}g(P,[{key:"keys",value:function(){return this.storage.keys()}},{key:"values",value:function(){return this.storage.values()}},{key:"entries",value:function(){return this.storage.entries()}},{key:"forEach",value:function(e){this.storage.forEach(e)}},{key:"set",value:function(n,t){try{this.storage.set(n,t)}catch(e){if(!d(e)||!this.exceededCallback)throw e;this.exceededCallback(e,[n,t],this)}}},{key:"get",value:function(e){return this.storage.get(e)}},{key:"has",value:function(e){return this.storage.has(e)}},{key:"delete",value:function(e){return this.storage.delete(e)}},{key:"clear",value:function(){this.storage.clear()}},{key:"addHandler",value:function(e){return this.storage.addHandler?this.storage.addHandler(e):null}},{key:"removeHandler",value:function(e){this.storage.removeHandler&&this.storage.removeHandler(e)}},{key:"size",get:function(){return this.storage.size}}]);function P(e,n){v(this,P);this.storage=function(){if(p())return k;if(("undefined"!=typeof window&&console.warn("(Storage) The Object localStorage isn't supported in your client, methods `addHandler` and `removeHandler` will do nothing when you call it"),e)&&y())return w;return new Map}(),n instanceof Function&&(this.exceededCallback=n)}var S="undefined"!=typeof cefCore,x=S&&"undefined"!=typeof cefPopupEnvironment,O=new Promise(function(e){"undefined"!=typeof cefJsWebBridge?e():S?window.addEventListener("cefJsWebBridgeReady",e):window.addEventListener("load",e)});function E(){console.warn("该功能只在客户端主窗口可用!")}function I(){return Promise.reject(new Error("该功能只在客户端可用"))}function A(){return S?cefCore.GetDpi().then(function(e){return+e||1}):Promise.resolve(1)}function N(){return(S?cefCore.GetNowTaxInfo().then(function(e){return h.parseJSON(e)}):Promise.resolve({returnCode:"-1",returnMsg:"只能在客户端获取税盘信息!"})).then(function(e){return i(i({},e),{},{status:"0000"===e.returnCode?1:0,companyName:e.companyName||"",taxNo:e.companyTax||"",deviceNo:e.machineCode||"",message:e.returnMsg||"",type:+e.diskType||0})})}var T="undefined"!=typeof boundAsync;function W(){return s("clientInfo",function(){return T&&boundAsync.getIce?boundAsync.getIce().then(function(e){return Promise.resolve(JSON.parse(e))}):Promise.resolve(null)})}function j(){return(j=t(regeneratorRuntime.mark(function e(){var n;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,W();case 2:if(n=e.sent)return e.abrupt("return",n.AppVer);e.next=5;break;case 5:return e.abrupt("return",null);case 6:case"end":return e.stop()}},e)}))).apply(this,arguments)}function J(){return B.apply(this,arguments)}function B(){return(B=t(regeneratorRuntime.mark(function e(){var n;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,W();case 2:if(n=e.sent)return e.abrupt("return",n.AppName);e.next=5;break;case 5:return e.abrupt("return",null);case 6:case"end":return e.stop()}},e)}))).apply(this,arguments)}function M(){return(M=t(regeneratorRuntime.mark(function e(){var n;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,J();case 2:if(n=e.sent)return e.abrupt("return",n.endsWith("V2"));e.next=5;break;case 5:return e.abrupt("return",!1);case 6:case"end":return e.stop()}},e)}))).apply(this,arguments)}function H(){return(H=t(regeneratorRuntime.mark(function e(){var n;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,J();case 2:if(n=e.sent)return e.abrupt("return",n.endsWith("V3"));e.next=5;break;case 5:return e.abrupt("return",!1);case 6:case"end":return e.stop()}},e)}))).apply(this,arguments)}(g=e.TaxSoftWares||(e.TaxSoftWares={})).HX="hx",g.BW="bw",(g=e.InvoiceType||(e.InvoiceType={})).Common="c",g.Special="s",g.Electronic="ce",g.BlockChain="bc";g=T||S;e.CefAddEventListener=function(e,n){S&&!x?cefJsWebBridge.addEventListener(e,n):x&&E()},e.CefCall=function(e){var n=cefCore[e]||cefJsWebBridge[e];if(!n)throw new Error("接口 ".concat(e," 在当前版本的客户端不存在!"));for(var t=arguments.length,r=new Array(1<t?t-1:0),o=1;o<t;o++)r[o-1]=arguments[o];return n.apply(void 0,r)},e.CefExitApp=function(){S?cefCore.ExitApp?cefCore.ExitApp():cefCore.CloseWindow():window.close()},e.CefGetDPI=A,e.CefGetTaxDeviceInfo=N,e.CefHasOFD=function(){try{return Promise.resolve(cefCore.HasOfd())}catch(e){return Promise.resolve(!1)}},e.CefIsFullBridgeClient=S,e.CefIsPopupClient=x,e.CefIsTaxSoftWareOpen=function(e){return S?cefCore.IsTaxProcessOpen(e):I()},e.CefJsWebBridgeReady=O,e.CefMakePdf=function(e){return S?cefCore.MakePdf(h.stringifyJSON(e)).then(function(e){if(!e)return e;throw new Error(e)}):I()},e.CefOpenTaxSoftware=function(e){return S?Promise.resolve(cefCore.OpenTaxExe(e)).then(function(e){return"boolean"==typeof e?e:h.parseJSON(e)}):I()},e.CefOpenUrlInBrowser=function(e){S?cefCore.OpenUrlOnSystem(e):window.open(e)},e.CefPlayAudio=function(e){S?cefCore.PlaySound(e):console.warn("请在客户端调用音频接口!")},e.CefPopupCallback=function(e){x&&cefPopupEnvironment.callback(h.stringifyJSON(e))},e.CefRemoveEventListener=function(e,n){S&&!x?cefJsWebBridge.addEventListener(e,n):x&&E()},e.CefSendDataForCE=function(e){return S?cefCore.MakeoutFromPreview(h.stringifyJSON(e)).then(function(e){if(!e)return e;throw new Error(e)}):I()},e.CefSendTitleToTaxSoftware=function(e){return S?cefCore.DoSendTitle(h.stringifyJSON(e)).then(function(e){if(!e)return e;throw new Error(e)}):I()},e.CefSetCertPassword=function(e){return S?cefCore.SetCertPassword(e).then(function(e){if(!e)return e;throw new Error(e)}):I()},e.CefShowMainWindow=function(){S&&cefCore.ShowMainWindow()},e.CefSubscribeTaxDeviceInfo=function(e){var n,t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:5e3,r=s("taxDevicePubSub",function(){return new a}),o=r.subscribe(e);return setTimeout(function(){N().then(r.publish),n=setInterval(function(){N().then(r.publish)},t)}),function(){r.unsubscribe(o),n&&clearInterval(n)}},e.CefVersion=function(){return O.then(function(){return new Promise(function(e){return cefJsWebBridge.getVersion(e)})})},e.CefWindowClose=function(){S?cefCore.CloseWindow():window.close()},e.CefWindowMinimize=function(){S&&cefCore.SetWindowMinimized()},e.CefWindowPopup=function(e,n){var t=(e.content||"").replace(/\s\s+/g," "),r=i(i({},e),{},{content:t,title:e.title||""}),o=i(i({width:320,height:180,position:"centerScreen"},n),r);return S?O.then(function(){return A().then(function(n){return new Promise(function(e){return cefJsWebBridge.invoke("showPopup",i(i({},o),{},{width:Math.ceil(o.width*n),height:Math.ceil(o.height*n)}),e)})})}):new Promise(function(e){window.open("https://lite.yipiaoyun.cn/custom-dialog#data=".concat(encodeURIComponent(JSON.stringify(r))),"custom-dialog"),alert(t),e()})},e.GetKaiPiaoClientAppName=J,e.GetKaiPiaoClientInfo=W,e.GetKaiPiaoClientVersion=function(){return j.apply(this,arguments)},e.InvoiceFix=function(){return T?(boundAsync.callInvoiceFix(),Promise.resolve(!0)):Promise.reject(new Error("浏览器不支持修复功能,请在客户端修复!"))},e.IsClient=g,e.IsKaiPiaoClient=T,e.IsKaiPiaoClientV2ByIce=function(){return M.apply(this,arguments)},e.IsKaiPiaoClientV2ByTaxDisk=function(e){if(e){e=e.AppName;return!!e&&e.endsWith("V2")}return!1},e.IsKaiPiaoClientV3ByIce=function(){return H.apply(this,arguments)},e.IsKaiPiaoClientV3ByTaxDisk=function(e){if(e){e=e.AppName;return!!e&&e.endsWith("V3")}return!1},e.JumpAction=function(e){if(boundAsync.jumpAction)return boundAsync.jumpAction(e.type,e.url)},e.LoginKaiPiao=function(e,n){return T?boundAsync.login(e,n):Promise.reject(new Error("不在客户端!"))},e.LogoutKaiPiao=function(){T&&boundAsync.logout()},e.PageReload=function(){T?boundAsync.refushHome():window.location.reload()},e.SignOutClient=function(e){if(cefCore.mutualSwitch)return cefCore.mutualSwitch(e)},Object.defineProperty(e,"__esModule",{value:!0})});