@anov/core
Version:
ANOV Visualization Platform Kernel encapsulates all basic services, such as face recognition, gesture recognition, speech recognition, theme skin changing, internationalization, animation engine, basic components
26 lines • 394 kB
JavaScript
import{moment,gpu,qs,annyang,checkVideo,isPlainObject,isArray,Browser,checkAudio,cloneDeep}from"dtc";import CryptoJS__default,{MD5 as MD5$1,HmacSHA1,enc}from"crypto-js";import axios from"axios";import{merge,compact,throttle,isPlainObject as isPlainObject$1,isArray as isArray$1,isFunction,isString,startsWith,mapKeys,has,isBoolean,mergeWith,reverse,unionBy,concat}from"lodash-es";import hotkeys from"hotkeys-js";import{Howler,Howl}from"howler";import UPNG from"upng-js";import Vue from"vue";function mitt(e){return e=e||Object.create(null),{$on(t,n){(e[t]||(e[t]=[])).push(n)},$once(e,t){let n=this;this.$on(e,function r(){n.$off(e,r),t.apply(n,arguments)})},$off(t,n){e[t]&&e[t].splice(e[t].indexOf(n)>>>0,1)},$emit(t,n){(e[t]||[]).slice().map(e=>{e(n)}),(e["*"]||[]).slice().map(e=>{e(t,n)})}}}const __sys_bus_emitter=mitt();class EventBusServer{}Object.assign(EventBusServer.prototype,{getEventBus:()=>__sys_bus_emitter});class VuexServer{}Object.assign(VuexServer.prototype,{getState(){return this.getAppStore().state[this._type]},mapState(e){return mapState(this._type,e)},mapGetters(e){return mapGetters(this._type,e)},mapMutations(e){return mapMutations(this._type,e)},callState(e){return this.getAppStore().state[this._type][e]},callGetter(e,t){return this.getAppStore().getters[this._type+"/"+e](t)},callMutation(e,t){this.getAppStore().commit(this._type+"/"+e,t)}});const mapState=normalizeNamespace((e,t)=>{const n={};return normalizeMap(t).forEach(({key:t,val:r})=>{n[t]=function(){let t=this.$store.state,n=this.$store.getters;if(e){const r=getModuleByNamespace(this.$store,"mapState",e);if(!r)return;t=r.context.state,n=r.context.getters}return"function"==typeof r?r.call(this,t,n):t[r]},n[t].vuex=!0}),n}),mapMutations=normalizeNamespace((e,t)=>{const n={};return normalizeMap(t).forEach(({key:t,val:r})=>{n[t]=function(...t){let n=this.$store.commit;if(e){const t=getModuleByNamespace(this.$store,"mapMutations",e);if(!t)return;n=t.context.commit}return"function"==typeof r?r.apply(this,[n].concat(t)):n.apply(this.$store,[r].concat(t))}}),n}),mapGetters=normalizeNamespace((e,t)=>{const n={};return normalizeMap(t).forEach(({key:t,val:r})=>{r=e+r,n[t]=function(){if(!e||getModuleByNamespace(this.$store,"mapGetters",e)){if("production"===process.env.NODE_ENV||r in this.$store.getters)return this.$store.getters[r];console.error(`[vuex] unknown getter: ${r}`)}},n[t].vuex=!0}),n});function normalizeMap(e){return Array.isArray(e)?e.map(e=>({key:e,val:e})):Object.keys(e).map(t=>({key:t,val:e[t]}))}function normalizeNamespace(e){return(t,n)=>("string"!=typeof t?(n=t,t=""):"/"!==t.charAt(t.length-1)&&(t+="/"),e(t,n))}function getModuleByNamespace(e,t,n){const r=e._modulesNamespaceMap[n];return"production"===process.env.NODE_ENV||r||console.error(`[vuex] module namespace not found in ${t}(): ${n}`),r}class EventDispatcher{}Object.assign(EventDispatcher.prototype,{addEventListener(e,t){void 0===this._listeners&&(this._listeners={});var n=this._listeners;void 0===n[e]&&(n[e]=[]),-1===n[e].indexOf(t)&&n[e].push(t)},hasEventListener(e,t){if(void 0===this._listeners)return!1;var n=this._listeners;return void 0!==n[e]&&-1!==n[e].indexOf(t)},removeEventListener(e,t){if(void 0!==this._listeners){var n=this._listeners[e];if(void 0!==n){var r=n.indexOf(t);-1!==r&&n.splice(r,1)}}},dispatchEvent(e){if(void 0!==this._listeners){var t=this._listeners[e.type];if(void 0!==t){e.target=this;for(var n=t.slice(0),r=0,i=n.length;r<i;r++)n[r].call(this,e)}}}});const __sys_error=[],_maxCount=50;class MonitorServer{constructor(){this.initNormalError(),this.initConsoleError(),this.initPromiseError()}initNormalError(){window.onerror=((e,t,n,r,i)=>{let o=i?i.stack:e+"\n"+t+":"+n+":"+r;this._write(o)})}initConsoleError(){var e=console.error;console.error=(t=>{let n=t+"\n"+window.location.href+":0:0[console]";return this._write(n),e(t)})}initPromiseError(){window.onunhandledrejection=(e=>{let t="",n=(t="object"==typeof e.reason?JSON.stringify(e.reason):e.reason)+"\n"+window.location.href+":0:0[promise]";this._write(n)})}_write(e){try{app&&app.runtimeServer?__sys_error.length>0?(__sys_error.map(e=>{app.runtimeServer.addError(e)}),__sys_error.splice(0)):app.runtimeServer.addError(e):(__sys_error.length>=_maxCount&&__sys_error.shift(),__sys_error.push(e))}catch(e){}}}const monitorServer=new MonitorServer,__sys_log=[],_maxCount$1=200;class LogServer{}Object.assign(LogServer.prototype,{addError(e){this._addLog({type:"error",msg:e})},addWarn(e){this._addLog({type:"warn",msg:e})},addInfo(e){this._addLog({type:"info",msg:e})},_addLog(e){e=Object.assign({module:this._type,date:moment().format("HH:mm:ss")},e),__sys_log.length>=_maxCount$1&&__sys_log.shift(),__sys_log.push(e),this.getEventBus().$emit("logging",e)},getLog:()=>__sys_log,delLog(){__sys_log.splice(0)}});let __sys_current_context=null,__appStore=null,__http=null;class BaseServer{constructor(e){if(!e)throw new Error("Anov:server type is not null");this._type=e,this._http=__http,this._addLog({type:"info",module:"system",msg:this._type+"Server initialization"})}_extractConfig(e){return e[this._type]}getAppStore(){return __appStore}getCurrentContext(){return __sys_current_context}static _setCurrentContext(e){__sys_current_context=e}static _setAppStore(e){__appStore=e}}Object.assign(BaseServer.prototype,LogServer.prototype),Object.assign(BaseServer.prototype,EventDispatcher.prototype),Object.assign(BaseServer.prototype,EventBusServer.prototype),Object.assign(BaseServer.prototype,VuexServer.prototype);const T_KEY="anov@2019:helloX",T_IV="anov@2020:helloX",expire=30,token={ct:(e,t)=>getAesString(e+"|"+t,T_KEY,T_IV),vt(e){let t=getDAesString(e,T_KEY,T_IV);if(t&&t.split("|")[1]){let e=+t.split("|")[1],n=1e3*expire;return(new Date).getTime()-e<n}return!1}};function getAesString(e,t,n){t=CryptoJS__default.enc.Utf8.parse(t),n=CryptoJS__default.enc.Utf8.parse(n);return CryptoJS__default.AES.encrypt(e,t,{iv:n,mode:CryptoJS__default.mode.CBC,padding:CryptoJS__default.pad.Pkcs7}).toString()}function getDAesString(e,t,n){t=CryptoJS__default.enc.Utf8.parse(t),n=CryptoJS__default.enc.Utf8.parse(n);return CryptoJS__default.AES.decrypt(e,t,{iv:n,mode:CryptoJS__default.mode.CBC,padding:CryptoJS__default.pad.Pkcs7}).toString(CryptoJS__default.enc.Utf8)}const ga={info:{},getInfo(){var e={};document&&(e.domain=document.domain||"",e.url=document.URL||"",e.title=document.title||"",e.referrer=document.referrer||""),window&&window.screen&&(e.sh=window.screen.height||0,e.sw=window.screen.width||0,e.cd=window.screen.colorDepth||0),navigator&&(e.lang=navigator.language||""),e.GPUmodel=this.info.GPUmodel||gpu()&&gpu().name,e.GPUmanufacturer=this.info.GPUmanufacturer||"",e.memoryTotalJsHeapSize=this.info.memoryTotalJsHeapSize||0,e.memoryUsedJsHeapSize=this.info.memoryUsedJsHeapSize||0,e.fps=this.info.fps||0;var t="";for(var n in e)""!=t&&(t+="&"),t+=n+"="+encodeURIComponent(e[n]);return t}};var httpInterceptors={init(e){e.http&&(this.http=e.http,e.request&&this.openRequestInterceptors(e.http),e.response&&this.openResponseInterceptors(e.http))},openRequestInterceptors(e){e.interceptors.request.use(e=>{if(!__ANOV__ENV)return void console.warn("__ANOV__ENV全局对象未配置。");let t=(new Date).getTime(),n=token.ct(__ANOV__ENV.projectId,t);return n&&(e.headers["X-Anov-Token"]=n,e.headers.GA=ga.getInfo(),e.headers["X-Anov-Client-Type"]=getClientType()),e},e=>Promise.error(e))},openResponseInterceptors(e){e.interceptors.response.use(e=>200===e.status?Promise.resolve(e.data):Promise.reject(e.data),e=>(__ANOV__ENV.debug&&console.error(e),e.response&&e.response.status&&e.response.status,Promise.reject(e.response)))}};function getClientType(){let e="anov-null";if(__ANOV__ENV&&__ANOV__ENV.platformName)switch(__ANOV__ENV.platformName.toLowerCase()){case"anov":case"anov-dev":e="screen";break;case"anov-go":e="go";break;case"anov-remote":e="remote";break;case"anov-admin":e="server"}return e}const sender=Symbol("sender"),sendAck=Symbol("ack"),ACK="ACK",SEQ="SEQ",STATE="STATE",CONTROLL="CONTROLL",ACTION="ACTION",INFO="INFO",SYS="SYS",RTS="RTS",LOG="LOG",GET="GET";function isSupportWS(){return!!WebSocket}function interceptors(e={}){const{type:t,data:n,target:{readyState:r}}=e;let i,o;try{i=JSON.parse(n)}catch(e){o=n}return{type:t,data:i,message:o,readyState:r}}class Eventer{addEventListener(e,t){void 0===this._listeners&&(this._listeners={});let n=this._listeners;void 0===n[e]&&(n[e]=[]),-1===n[e].indexOf(t)&&n[e].push(t)}hasEventListener(e,t){if(void 0===this._listeners)return!1;let n=this._listeners;return void 0!==n[e]&&-1!==n[e].indexOf(t)}removeEventListener(e,t){if(void 0===this._listeners)return;let n=this._listeners[e];if(void 0!==n){let e=n.indexOf(t);-1!==e&&n.splice(e,1)}}dispatchEvent(e,t,n){if(void 0===this._listeners)return;let r=this._listeners[e];if(void 0!==r){let e=r.slice(0);for(let r=0,i=e.length;r<i;r++)e[r](t,n)}}}class Remote extends Eventer{constructor(e,t,n=!1){if(super(),this.sendReslove={},this.sendReject={},this.sendTimer={},this.sentMsgIds=[],this.url=e,this.closed=!0,this.readyState=3,this._gap=0,this._breakpoint=[],this.status=new Proxy({up:0,down:0},{get:function(e,t){return e[t]},set:(e,t,n)=>{let r=e.up+e.down;e[t]=n;let i=e.up+e.down;return i!==r&&this.dispatchEvent("wsStatus",i),!0}}),this.confirm="boolean"==typeof t?t:n,this.remoteId="string"==typeof t?t:"",!isSupportWS())return console.error("Your browser does not support WebSocket connections!"),Object.create(null);/^ws/.test(e)&&this.connect(this.url,this.remoteId,this.confirm)}[sendAck](e,t=ACK,n,r){const i={ack:e,timestamp:r,type:t,data:n,confirm:!0,screenCode:this.screenCode};this.ws.send(JSON.stringify(i))}[sender](e,t=!1,n=SEQ){let r={seq:CryptoJS__default.MD5(JSON.stringify(e)+(new Date).getTime()).toString(),timestamp:(new Date).getTime(),type:n,data:e,confirm:t,screenCode:this.screenCode};return this.status.up=1,new Promise((e,t)=>{this.ws&&1===this.ws.readyState?(this.ws.send(JSON.stringify(r)),this.sentMsgIds.push(r.seq),this.sendReslove[`seq_${r.seq}`]=e,this.sendReject[`seq_${r.seq}`]=t,this.sendTimer[`seq_${r.seq}`]=setTimeout(()=>{"function"==typeof this.sendReslove[`seq_${r.seq}`]&&(delete this.sendReslove[`seq_${r.seq}`],delete this.sendReject[`seq_${r.seq}`]),this.status.down=0,t({message:"timeout",id:r.seq})},3100)):(this.status.up=0,this.status.down=0,t({message:"state error",code:this.ws&&this.ws.readyState}))})}connect(e,t,n=!1){if(!/^ws(s)?:\/\//.test(e))return console.warn("Ensure the correct websocket address!"),Promise.reject();if(3!==this.readyState)return console.warn("You already have One WebSocket instance!"),Promise.reject();this.url=e;const r=e.split("/"),i=r.length;return this.appCode=r[i-2],this.screenCode=r[i-1],this.confirm="boolean"==typeof t?t:n,this.remoteId="string"==typeof t?t:"",this.ws=new WebSocket(e),this.ws.addEventListener("message",e=>{const t=interceptors(e),n=t&&t.data&&t.data.type,r=t&&t.data&&t.data.confirm,i=t&&t.data&&t.data.timestamp||(new Date).getTime(),o=e=>{const n=t&&t.data&&t.data.seq;let r={success:!0};"boolean"==typeof e?r.success=e:"object"==typeof e&&(r=e),this[sendAck](n,ACK,r,i)};if("PING"===n){clearTimeout(this.serverTimeoutTimer),clearTimeout(this.hartbeatTimer);let e=t&&t.data&&t.data.seq;"function"==typeof this.sendReslove[`seq_${e}`]&&this.sendReslove[`seq_${e}`](t);const n=this.sendTimer[`seq_${e}`];return n&&clearTimeout(n),delete this.sendReslove[`seq_${e}`],delete this.sendReject[`seq_${e}`],void(!this.closed&&this.hartbeat())}if(n===SYS)return void this.dispatchEvent("sys",t);if(!t.data)return void this.dispatchEvent("error",t);if(t.data.toCodeId!==(this.appCode||this.screenCode))return;const s=t&&t.data&&t.data.seq;let a=this.sentMsgIds.findIndex(e=>e===s);if(a>=0)return this.sentMsgIds.splice(a,1),r||(this.dispatchEvent("serverDelay",(new Date).getTime()-t.data.timestamp),clearTimeout(this.sendTimer[`seq_${s}`]),"function"==typeof this.sendReslove[`seq_${s}`]&&(this.sendReslove[`seq_${s}`](!0),delete this.sendReslove[`seq_${s}`],delete this.sendReject[`seq_${s}`])),void(this.status.down=2);if(n===ACK){const e=t&&t.data&&t.data.ack,n=t&&t.data&&t.data.data&&t.data.data.success;"function"==typeof this.sendReslove[`seq_${e}`]&&(!1===n?this.sendReject[`seq_${e}`](t):this.sendReslove[`seq_${e}`](t)),this.dispatchEvent("clientDelay",(new Date).getTime()-t.data.timestamp);const r=this.sendTimer[`seq_${e}`];r&&clearTimeout(r),delete this.sendReslove[`seq_${e}`],delete this.sendReject[`seq_${e}`]}else this.dispatchEvent("message",t,o)}),this.readyState=this.ws.readyState,new Promise((e,t)=>{const n=["open","close","error"];for(let r=0;r<n.length;r++)this.ws.addEventListener(n[r],i=>{const{type:o}=i;this.readyState=this.ws.readyState,clearTimeout(this.reconnectTimer),"open"===o?(this.closed=!1,this.hartbeat(),e(i)):(!this.closed&&1!==this.readyState&&this._autoReconnect(),this.dispatchEvent("serverDelay",NaN),this.dispatchEvent("clientDelay",NaN),this.status.up=0,this.status.down=0,t(i)),this.dispatchEvent(n[r],i)})})}send(e,t=!1){return this[sender](e,t,SEQ)}ping(){return this[sender](null,!1,"PING")}sendState(e,t=!1){return this[sender](e,t,STATE)}sendControll(e,t=!1){return this[sender](e,t,CONTROLL)}sendAction(e,t=!0){return this[sender](e,t,ACTION)}sendRTS(e,t=!0){return this[sender](e,t,RTS)}sendInfo(e,t=!1){return this[sender](e,t,INFO)}sendLog(e){return this[sender](e,!1,LOG)}sendCustomize(e,t,n=!1){if("string"==typeof t)return this[sender](e,!!n,t)}getState(e,t=!0){return this[sender](e,t,GET)}reconnect(){1!==this.readyState?this.connect(this.url,this.remoteId,this.confirm).then(()=>{this.dispatchEvent("reconnect","network")}):this.dispatchEvent("reconnect",!0)}_autoReconnect(){this.closed||(this.reconnectTimer=setTimeout(()=>{this.dispatchEvent("reconnecting",!0),this.connect(this.url,this.remoteId,this.confirm).then(()=>{this.dispatchEvent("reconnect",!0)}).catch(()=>{})},1e3*this._updateGap()))}_updateGap(){if(!this._breakpoint.length){for(let e=1;e<=5;e++){let t=10*(10+5*(e-1))*100+(this._breakpoint[e-2]||0);this._breakpoint.push(t)}return 1}let e=this._breakpoint.findIndex(e=>e>this._gap);return this._gap=this._gap+100*(10+5*e),~e?2+1*e:60}hartbeat(){this.hartbeatTimer=setTimeout(()=>{this.ping().catch(e=>console.log(e)),this.serverTimeoutTimer=setTimeout(()=>{this.ws.close(4003,"ping timeout")},3e3)},3e4)}close(e,t){this.closed=!0,this.ws&&this.ws.close(e,t),clearTimeout(this.serverTimeoutTimer),clearTimeout(this.hartbeatTimer),Object.values(this.sendTimer).forEach(e=>{clearTimeout(e)})}}const WS=function(){let e;return function(t,n,r=!1){return e||(e=new Remote(t,n,r))}}();class RemoteServer{constructor(e){return this.ws=new WS,e&&e.test(/^ws(s)?:\/\//.test(e))&&this.ws.connect(e),this.ws}}function createInstance(e){var t=new WS;return e&&e.test(/^ws(s)?:\/\//.test(e))&&t.connect(e),t}let remote=function(){let e;return function(t,n){return e?(e.config=t,e):((e=new RemoteServer(n)).config=t,e)}}();remote.create=function(e){return createInstance(e)};const TIMEOUT=6e3,eventType={connected:"adminServer__connected",logined:"logined"},setGlobal=e=>{Object.assign(window,e),document.title=__ANOV__ENV.projectName,document.querySelector("#projectName").innerText=__ANOV__ENV.projectName,document.querySelector("#copyright").innerText=__ANOV__ENV.copyright};class AdminServer extends BaseServer{constructor(){super("admin"),this.addEventListener("connected"),this.getEventBus().$on("logging",this._addLogToServer.bind(this))}get serverPath(){return this.callState("serverPath")}get connected(){return this.callState("connected")}get isActive(){return this.callState("isActive")}setConnected(e){this.callMutation("setConnected",e)}setServerPath(e){this.callMutation("setServerPath",e)}setIsActive(e){this.callMutation("setIsActive",e)}init(e){let t=this._extractConfig(e);if(!t.serverPath)return void this.addWarn("Server address not configured,[serverPath] is null.");this.setServerPath(t.serverPath);let n=t.timeout||TIMEOUT;this._http=axios.create({baseURL:this.serverPath,timeout:n,headers:{"Content-Type":"application/json;charset=UTF-8"},withCredentials:!0}),httpInterceptors.init({http:this._http,request:!0,response:!0}),this._httpScreenshot=axios.create({timeout:n,headers:{"Content-Type":"application/json;charset=UTF-8"},withCredentials:!0}),httpInterceptors.init({http:this._httpScreenshot,request:!0,response:!0}),this.ws=remote(e.remote)}getVerifyCodeImg(e){this._http&&this._http.get("/auth/code").then(t=>{e&&e(t)}).catch(t=>{e&&e(!1),this.addError(t.message)})}login(e,t){this._http&&this._http.post("/auth/login",{name:e.name,code:e.code,imgCode:e.imgCode,uuid:e.uuid}).then(e=>{t&&t(e),this.dispatchEvent({type:eventType.logined,result:e})}).catch(e=>{t&&t(e),this.addError(e.message)}).finally(()=>{})}getConfig(e,t){return e.key?__ANOV__ENV?this._http({url:`/api/devs/v1/${e.key}/verify?rnd=`+Math.random(),headers:{"X-Anov-Version":__ANOV__ENV.platformVersion,"X-Anov-Core-Version":__ANOV__ENV.platformCoreVersion,"X-Anov-Level":__ANOV__ENV.level||"","X-Anov-Debug":__ANOV__ENV.debug,"X-Anov-Dir":encodeURIComponent(__ANOV__ENV.projectLocalDir),"X-Anov-Client-Code":e.code||__ANOV__ENV.pkgid},method:"post",data:{pkginfo:token.ct(__ANOV__ENV.pkginfo,(new Date).getTime())}}).then(e=>(t&&t(e),this.code=e.data?e.data.clientCode:"",e)).catch(e=>(this.addError(e&&e.msg),t&&t(!1),Promise.reject(e))):(console.warn("__ANOV__ENV全局对象未配置。"),t&&t(!1),Promise.reject(1)):(this.addError("ProjectId is null"),t&&t(!1),Promise.reject(0))}vaildateToken(e){return token.vt(e)}_init_screenshot_params(e){this._httpScreenshot&&this._httpScreenshot.post("/take",{origin:this.serverPath,...e}).catch(()=>void 0)}_screenshot_upload(){if("development"===process.env.NODE_ENV&&this._httpScreenshot)return this._httpScreenshot.post("/upload").catch(()=>void 0)}_addLogToServer(e){if(!this.ws||!__ANOV__ENV.projectId)return;if(1!==this.ws.readyState)return;const{module:t,msg:n,type:r}=e;this.ws.sendLog({logType:r.toUpperCase(),logModule:t.toUpperCase(),logDesc:n}).catch(e=>{console.log(e)})}screenshotUpload(e,t){let n=new FormData;n.append("file",e),this._http.post("/api/localStorage/screenFileUpLoad",n).then(e=>{t&&t(e)}).catch(e=>{})}saveScreenImg(e,t){let n={screenImg:e.id,screenKey:e.key};this._http.post("/api/devBigScreen/saveScreenImg",n).then(e=>{t&&t(e)}).catch(e=>{})}getTerminalInfo(e,t){this._http&&this._http.get(`/api/devScreenOnline/findOnlineApp?key=${e.key}&code=${e.code}`).then(e=>{t&&t(e)}).catch(e=>{this.addError(e.message),t&&t(!1)})}shareCodeVerify(e,t){this._http&&this._http.get(`/api/v1/go/v1/${e.key}/check/${e.code}`).then(e=>{t&&t(e)}).catch(e=>{this.addError(e.message),t&&t(!1)})}}const adminServer=new AdminServer;Object.defineProperty(adminServer,"setGlobal",{value:setGlobal,writable:!1,configurable:!1});class RuntimeServer extends BaseServer{constructor(){super("runtime")}init(e){this._sysConfigInit(e)}setAppStore(e){e&&BaseServer._setAppStore(e)}setCurrentContext(e){e&&BaseServer._setCurrentContext(e)}exec(code){try{eval(code)}catch(e){this.addError("代码注入异常:"+error.stack)}}_sysConfigInit(e){let t=window.location.href.split("?")[1]||"";t=t.split("#")[0];let n=qs.parse(t,{allowDots:!0,decoder:function(e,t){return"true"===e||"false"!==e&&t(e=e.replace(/\%20|\+/g,"%2B"))}});merge(e,n)}}const runtimeServer=new RuntimeServer,eventType$1={execAction:"execAction"};class ActionServer extends BaseServer{constructor(){super("action"),this._items=[]}init(e){}addActions(e){Array.isArray(e)?e.map(e=>{this._add(e)}):this._add(e)}removeActions(e){Array.isArray(e)?e.map(e=>{this._remove(e)}):this._remove(e)}getActionById(e){return this._items.find(t=>t.id===e)}getActionByName(e){return this._items.find(t=>t.name===e)}getActions(){return this._items}exec(e,t,n=!0){let r=this.getActionById(e)||this.getActionByName(e);r&&r.exec(this.getCurrentContext(),t),n&&this.addInfo("执行动作 "+r.id+":"+r.name),this.dispatchEvent({type:eventType$1.execAction,result:r})}_add(e){this._items.find(t=>t.id===e.id)?this.addError("Anov.ActionServer._add(action):Unable to add, because "+e.id+" action is exists"):this._items.push(e)}_remove(e){this._items.splice(this._items.findIndex(t=>t.id===e),1)}}class Action{constructor(e){this.id=e.id,this.name=e.name,this.exec=e.exec}exec(e){this.exec&&this.exec(...e)}}const actionServer=new ActionServer;class DataSourceServer extends BaseServer{constructor(){super("dataSource"),this._ds={}}init(e){let t=this._extractConfig(e);this.type=t.type,this.dataPlan=e.dataPlan}addDataSources(e){this._ds=e}get type(){return this.callState("type")}set type(e){this.type!=e&&this.callMutation("setType",e)}get dataPlan(){return this.callState("dataPlan")}set dataPlan(e){this.callMutation("setDataPlan",e)}get currentPlan(){return this.callState("currentPlan")}set currentPlan(e){let t="";this.dataPlan&&this.pagePlan.option&&(t=this.pagePlan.option.find(t=>t.plan==e)),t?this.callMutation("setCurrentPlan",e):this.addError(`${e} no exits!`)}get pagePlan(){return this.callState("pagePlan")}set pagePlan(e){this.callMutation("setPagePlan",e)}create(){return this._ds[this.type.toUpperCase()]}setOption(e){Array.isArray(e)&&this.callMutation("SET_OPTION",e)}setDataPlan(e){Array.isArray(e)&&this.callMutation("setDataPlan",e)}initPagePlan(e){let t=e||this.getCurrentContext().$router.currentRoute.path;this.dataPlan&&this.dataPlan.forEach(e=>{e.path==t&&(this.pagePlan=e,this.currentPlan=e.plan)})}}const dataSourceServer=new DataSourceServer,codeString="self.onmessage = function (e) {\n switch (e.data.command) {\n case \"transform\":\n transform.transaction(e.data.buffer);\n break;\n }\n}\n\nvar transform = {\n transaction(buffer) {\n let bufTo16kHz = transform.to16kHz(buffer)\n let bufTo16BitPCM = transform.to16BitPCM(bufTo16kHz)\n // let bufToBase64 = transform.toBase64(bufTo16BitPCM)\n self.postMessage({ 'buffer': bufTo16BitPCM })\n },\n to16kHz(buffer) {\n var data = new Float32Array(buffer)\n var fitCount = Math.round(data.length * (16000 / 44100))\n var newData = new Float32Array(fitCount)\n var springFactor = (data.length - 1) / (fitCount - 1)\n newData[0] = data[0]\n for (let i = 1; i < fitCount - 1; i++) {\n var tmp = i * springFactor\n var before = Math.floor(tmp).toFixed()\n var after = Math.ceil(tmp).toFixed()\n var atPoint = tmp - before\n newData[i] = data[before] + (data[after] - data[before]) * atPoint\n }\n newData[fitCount - 1] = data[data.length - 1]\n return newData\n },\n\n to16BitPCM(input) {\n var dataLength = input.length * (16 / 8)\n var dataBuffer = new ArrayBuffer(dataLength)\n var dataView = new DataView(dataBuffer)\n var offset = 0\n for (var i = 0; i < input.length; i++, offset += 2) {\n var s = Math.max(-1, Math.min(1, input[i]))\n dataView.setInt16(offset, s < 0 ? s * 0x8000 : s * 0x7FFF, true)\n }\n return Array.from(new Int8Array(dataView.buffer))\n },\n toBase64(buffer) {\n var binary = ''\n var bytes = new Uint8Array(buffer)\n var len = bytes.byteLength\n for (var i = 0; i < len; i++) {\n binary += String.fromCharCode(bytes[i])\n }\n return window.btoa(binary)\n }\n}";var blob=new Blob([codeString]),url=window.URL.createObjectURL(blob);let recorderWorker=new Worker(url),buffer$1=[],AudioContext=window.AudioContext||window.webkitAudioContext;navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia,recorderWorker.onmessage=function(e){buffer$1.push(...e.data.buffer)};class IatRecorder{constructor(e={}){this.config=e,this.state="ing",this.xfid=this.config.configInfo.ID,this.whisper=this.config.configInfo.WHISPER}isSupport(){return!!(navigator.getUserMedia&&AudioContext&&recorderWorker)}start(){if(this.isSupport()&&!this.ws){this.abort(),this.state="ing";var e=new AudioContext;this.context=e,this.recorder=e.createScriptProcessor(0,1,1);var t=t=>{if("running"===e.state){var n=this.context.createMediaStreamSource(t);this.mediaStream=n,this.recorder.onaudioprocess=(e=>{this.sendData(e.inputBuffer.getChannelData(0))}),this.connectWebsocket()}else this.config.onError&&this.config.onError({error:"getMediaFail"})},n=e=>{this.recorder=null,this.mediaStream=null,this.context=null,this.config.onError&&this.config.onError({error:"getMediaFail"})};navigator.mediaDevices&&navigator.mediaDevices.getUserMedia?navigator.mediaDevices.getUserMedia({audio:!0,video:!1}).then(e=>{t(e)}).catch(e=>{n()}):navigator.getUserMedia({audio:!0,video:!1},e=>{t(e)},function(e){n()})}else this.isSupport()||this.config.onError&&this.config.onError({error:"getMediaFail"})}abort(){this.state="end";try{this.mediaStream.disconnect(this.recorder),this.recorder.disconnect()}catch(e){}}pause(){"running"===this.context.state&&this.context.suspend()}resume(){"suspended"===this.context.state&&this.context.resume()}sendData(e){recorderWorker.postMessage({command:"transform",buffer:e})}getHandShakeParams(){var e=Math.floor((new Date).getTime()/1e3),t=MD5$1(this.xfid+e).toString(),n=HmacSHA1(t,this.whisper),r=enc.Base64.stringify(n);return r=encodeURIComponent(r),"?appid="+this.xfid+"&ts="+e+"&signa="+r}connectWebsocket(){var e="wss://rtasr.xfyun.cn/v1/ws";if(e=`${e}${this.getHandShakeParams()}`,"WebSocket"in window)this.ws=new WebSocket(e);else{if(!("MozWebSocket"in window))return this.config.onError&&this.config.onError({error:"not-websocket"}),null;this.ws=new MozWebSocket(e)}this.ws.onopen=(e=>{this.mediaStream.connect(this.recorder),this.recorder.connect(this.context.destination),setTimeout(()=>{this.wsOpened(e)},500)}),this.ws.onmessage=(e=>{this.wsOnMessage(e)}),this.ws.onerror=(e=>{this.abort(),this.config.onError&&this.config.onError({error:"network"})}),this.ws.onclose=(e=>{this.abort(),this.ws=null})}wsOpened(){if(this.ws&&1===this.ws.readyState){var e=buffer$1.splice(0,2560);this.ws.send(new Int8Array(e)),this.clearBuffer=setInterval(()=>{buffer$1.length>3e3&&(buffer$1=[])},1e3),this.handlerInterval=setInterval(()=>{if(this.ws&&1!==this.ws.readyState)return clearInterval(this.clearBuffer),void clearInterval(this.handlerInterval);if(0===buffer$1.length)return"end"===this.state&&this.ws&&(this.ws.close(),this.ws=null,clearInterval(this.handlerInterval),clearInterval(this.clearBuffer)),!1;var e=buffer$1.splice(0,2560);e.length>0&&this.ws&&this.ws.send(new Int8Array(e))},40)}}wsOnMessage(e){let t=JSON.parse(e.data);"started"==t.action?this.config.onStart&&this.config.onStart(e):"result"==t.action?("end"!==this.state&&this.config.onSoundStart&&this.config.onSoundStart(),this.setResult(JSON.parse(t.data))):"error"==t.action&&(console.log("实时语音转写API错误码"+t.code),"10110"===t.code?this.config.onError&&this.config.onError({error:"no-license"}):this.config.onError&&this.config.onError({error:"websocket"}))}setResult(e){if(0!=e.cn.st.type)return;let t="";e.cn.st.rt[0].ws.forEach((e,n)=>{0!=n||","!=e.cw[0].w&&"。"!=e.cw[0].w&&"、"!=e.cw[0].w&&"?"!=e.cw[0].w||(e.cw[0].w=""),"啊"!=e.cw[0].w&&"嗯"!=e.cw[0].w&&"呃"!=e.cw[0].w&&"唉"!=e.cw[0].w&&"噢"!=e.cw[0].w||(e.cw[0].w=""),t+=e.cw[0].w}),t.length>=2&&this.config.onMessage&&this.config.onMessage([t],e.cn.st.type)}}const eventType$2={onStart:"onStart",onStop:"onStop",onSoundStart:"onSoundStart",onResult:"onResult",onResultMatch:"onResultMatch",onError:"onError",readyStart:"readyStart"};class VoiceRecognizeServer extends BaseServer{constructor(){super("voiceRecognize"),this._cmds=[],this.config={},this.iatRecorder=annyang,this.iatRecorder&&(this.iatRecorder.setLanguage("zh-CN ?"),this.iatRecorder.addCallback("start",this._onStart.bind(this)),this.iatRecorder.addCallback("soundstart",this._onSoundStart.bind(this)),this.iatRecorder.addCallback("result",this._onResult.bind(this)),this.iatRecorder.addCallback("errorPermissionBlocked",this._onError.bind(this)),this.iatRecorder.addCallback("errorPermissionDenied",this._onError.bind(this)),this.iatRecorder.addCallback("errorNetwork",this._onError.bind(this)))}init(e){let t=this._extractConfig(e);this.config={ID:t.ID,WHISPER:t.WHISPER},this.isStart=t.isStart,this.iatType=t.iatType,this.ID=t.ID,this.WHISPER=t.WHISPER}changeType(e){switch(e){case"default":this.iatRecorder=annyang;break;case"xf":this.iatRecorder=new IatRecorder({configInfo:this.config,onError:this._onError.bind(this),onMessage:this._onResult.bind(this),onStart:this._onStart.bind(this),onSoundStart:this._onSoundStart.bind(this)});break;default:this.iatRecorder=annyang}}changeServer(e){e!==this.iatType&&(this.iatRecorder&&this.iatRecorder.abort(),this.iatType=e,this.isStart&&this.iatRecorder&&this.iatRecorder.start({continuous:!1}))}get isStart(){return this.callState("isStart")}set isStart(e){this.callMutation("setIsStart",e)}get iatType(){return this.callState("iatType")}set iatType(e){this.changeType(e),this.callMutation("changeIatType",e)}get ID(){return this.callState("ID")}set ID(e){this.callMutation("setID",e)}get WHISPER(){return this.callState("WHISPER")}set WHISPER(e){this.callMutation("setWhisper",e)}readyStart(){this.dispatchEvent({type:eventType$2.readyStart})}start(){this.iatRecorder&&this.iatRecorder.start({continuous:!1})}stop(){this.iatRecorder&&this.iatRecorder.abort(),this.isStart=!1,this.dispatchEvent({type:eventType$2.onStop})}pause(){this.iatRecorder&&this.iatRecorder.pause()}resume(){this.iatRecorder&&this.iatRecorder.resume()}toggle(){this.isStart?this.stop():this.start()}addCommands(e){Array.isArray(e)?this._cmds=this._cmds.concat(e):this._cmds.push(e)}removeCommands(e){Array.isArray(e)?e.map(e=>{this._remove(e)}):this._remove(e)}getCommands(){return this._cmds}_onStart(){this.isStart=!0,this.dispatchEvent({type:eventType$2.onStart})}_onSoundStart(){this.dispatchEvent({type:eventType$2.onSoundStart})}_onResult(e){this.addInfo("识别结果:["+e.join(",")+"]"),this._match(e)||this.dispatchEvent({type:eventType$2.onResult,result:e})}_onError(e){let t="";t="not-allowed"===e.error?"请在设置中允许浏览器访问麦克风。":"network"===e.error?"网络错误,请确保连接到远程服务器。":"getMediaFail"===e.error?"麦克风受限,请重新开启语音识别服务。":"websocket"===e.error?"websocket连接失败。":"not-websocket"===e.error?"浏览器不支持websocket。":"no-license"===e.error?"接口没有授权许可。":e.error,this.addError(t),this.dispatchEvent({type:eventType$2.onError,result:t}),this.isStart?this.stop():this.iatRecorder&&this.iatRecorder.abort()}_match(e){for(let t=0;t<e.length;t++)for(let n=0;n<this._cmds.length;n++){let r=this._cmds[n],i=r.tag.test(e[t]);if(r.tag.lastIndex=0,i)return r.params=[RegExp.$1,RegExp.$2,RegExp.$3,RegExp.$4,RegExp.$5,RegExp.$6],r.result=e,this.addInfo("指令命中: "+r.tag+" 提取参数:"+r.params.join(",")),this.dispatchEvent({type:eventType$2.onResultMatch,result:r}),!0}}_remove(e){for(let t=0;t<this._cmds.length;t++)String(this._cmds[t].tag)===String(e)&&(this._cmds.splice(t,1),t--)}}const voiceRecognizeServer=new VoiceRecognizeServer;function isSupport(){try{return new window.SpeechSynthesisUtterance,!0}catch(e){return!1}}function Synthesis(e={}){if(Synthesis.single_instance||(Synthesis.single_instance=this),e=Object.assign({lang:"zh-CN",volume:1,rate:1,pitch:.5},e),!isSupport())return console.log("your browser do net support the API, visit https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesisUtterance get more infomation"),null;const t=window.speechSynthesis,n=new SpeechSynthesisUtterance;return Object.keys(e).forEach(t=>{n[t]=e[t]}),this.speak=function(e){e&&(n.text=e,t.speak(n))},this.cancel=function(){t.cancel()},this.setOption=function(t={}){Object.assign(e,t),Object.keys(e).forEach(t=>{n[t]=e[t]})},this.addEventListener=function(e,t){n.addEventListener(e,t)},this.getOption=function(){const{lang:e,volume:t,rate:r,pitch:i}=n;return{lang:e,volume:t,rate:r,pitch:i}},this.getStatus=function(){const{paused:e,pending:n,speaking:r}=t;return{paused:e,pending:n,speaking:r}},this.removeEventListener=function(e,t){n.removeEventListener(e,t)},Synthesis.single_instance}const codeString$1=" self.onmessage = function(e) {\n transcode.transToAudioData(e.data)\n}\nvar transcode = {\ntransToAudioData: function(audioDataStr, fromRate = 16000, toRate = 22505) {\n let outputS16 = transcode.base64ToS16(audioDataStr)\n let output = transcode.transS16ToF32(outputS16)\n output = transcode.transSamplingRate(output, fromRate, toRate)\n output = Array.from(output)\n self.postMessage({\n data: output, \n rawAudioData: Array.from(outputS16)\n })\n},\ntransSamplingRate: function(data, fromRate = 44100, toRate = 16000) {\n var fitCount = Math.round(data.length * (toRate / fromRate))\n var newData = new Float32Array(fitCount)\n var springFactor = (data.length - 1) / (fitCount - 1)\n newData[0] = data[0]\n for (let i = 1; i < fitCount - 1; i++) {\n var tmp = i * springFactor\n var before = Math.floor(tmp).toFixed()\n var after = Math.ceil(tmp).toFixed()\n var atPoint = tmp - before\n newData[i] = data[before] + (data[after] - data[before]) * atPoint\n }\n newData[fitCount - 1] = data[data.length - 1]\n return newData\n},\ntransS16ToF32: function(input) {\n var tmpData = []\n for (let i = 0; i < input.length; i++) {\n var d = input[i] < 0 ? input[i] / 0x8000 : input[i] / 0x7fff\n tmpData.push(d)\n }\n return new Float32Array(tmpData)\n},\nbase64ToS16: function(base64AudioData) {\n base64AudioData = atob(base64AudioData)\n const outputArray = new Uint8Array(base64AudioData.length)\n for (let i = 0; i < base64AudioData.length; ++i) {\n outputArray[i] = base64AudioData.charCodeAt(i)\n }\n return new Int16Array(new DataView(outputArray.buffer).buffer)\n},\n}\n";var Base64=require("js-base64").Base64,blob$1=new Blob([codeString$1]),url$1=window.URL.createObjectURL(blob$1);let transWorker=new Worker(url$1);function getWebsocketUrl(e){return new Promise((t,n)=>{var r=e.k,i=e.c,o="wss://tts-api.xfyun.cn/v2/tts",s=location.host,a=(new Date).toGMTString(),u=`host: ${s}\ndate: ${a}\nGET /v2/tts HTTP/1.1`,l=CryptoJS__default.HmacSHA256(u,i),c=CryptoJS__default.enc.Base64.stringify(l);t(o=`${o}?authorization=${btoa(`api_key="${r}", algorithm="hmac-sha256", headers="host date request-line", signature="${c}"`)}&date=${a}&host=${s}`)})}class TTSRecorder extends EventDispatcher{constructor(e){super(),this.speed=50*e.rate,this.voice=100*e.volume,this.pitch=100*e.pitch,this.voiceName=e.voiceName,this.text=e.text,this.tte=e.tte,this.defaultText=e.defaultText,this.xfid=e.ID,this.k=e.WHISPER,this.c=e.BEACON,this.audioData=[],this.audioDataOffset=0,this.status="init",transWorker.onmessage=(e=>{this.audioData.push(...e.data.data)})}setStatus(e){this.status=e}setParams({rate:e,volume:t,pitch:n,text:r,voiceName:i,tte:o}){void 0!==e&&(this.speed=(50*e).toFixed()-0),void 0!==t&&(this.voice=(100*t).toFixed()-0),void 0!==n&&(this.pitch=(100*n).toFixed()-0),r&&(this.text=r),o&&(this.tte=o),i&&(this.voiceName=i),this.resetAudio()}connectWebSocket(e){this.setStatus("ttsing");return getWebsocketUrl({k:this.k,c:this.c}).then(t=>{let n;if("WebSocket"in window)n=new WebSocket(t);else{if(!("MozWebSocket"in window))return void console.log("浏览器不支持WebSocket");n=new MozWebSocket(t)}this.ttsWS=n,n.onopen=(t=>{this.webSocketSend(),this.playTimeout=setTimeout(()=>{this.audioPlay(e)},1e3)}),n.onmessage=(t=>{this.result(t.data,e)}),n.onerror=(t=>{e&&"test"==e?this.dispatchEvent({type:"testError"}):this.dispatchEvent({type:"error"}),clearTimeout(this.playTimeout),this.setStatus("errorTTS")}),n.onclose=(e=>{})})}webSocketSend(){var e={common:{app_id:this.xfid},business:{aue:"raw",auf:"audio/L16;rate=16000",vcn:this.voiceName,speed:this.speed,volume:this.voice,pitch:this.pitch,bgs:0,tte:this.tte},data:{status:2,text:this.encodeText(this.text||this.defaultText,"unicode"===this.tte?"base64&utf16le":"")}};this.ttsWS.send(JSON.stringify(e))}encodeText(e,t){switch(t){case"utf16le":{let t=new ArrayBuffer(4*e.length),n=new Uint16Array(t);for(let t=0,r=e.length;t<r;t++)n[t]=e.charCodeAt(t);return t}case"buffer2Base64":{let t="",n=new Uint8Array(e),r=n.byteLength;for(let e=0;e<r;e++)t+=String.fromCharCode(n[e]);return window.btoa(t)}case"base64&utf16le":return this.encodeText(this.encodeText(e,"utf16le"),"buffer2Base64");default:return Base64.encode(e)}}result(e,t){let n=JSON.parse(e);if(0!==n.code)return t&&"test"==t?this.dispatchEvent({type:"testError"}):this.dispatchEvent({type:"error"}),console.error(`合成失败: ${n.code}:${n.message}`),void this.resetAudio();transWorker.postMessage(n.data.audio),0===n.code&&2===n.data.status&&this.ttsWS.close()}resetAudio(){this.audioStop(),this.setStatus("init"),this.audioDataOffset=0,this.audioData=[],this.ttsWS&&this.ttsWS.close(),clearTimeout(this.playTimeout)}audioInit(){let e=window.AudioContext||window.webkitAudioContext;e&&(this.audioContext=new e,this.audioContext.resume(),this.audioDataOffset=0)}audioPlay(e){this.setStatus("play");let t=this.audioData.slice(this.audioDataOffset);this.audioDataOffset+=t.length;let n=this.audioContext.createBuffer(1,t.length,22050),r=n.getChannelData(0);if(n.copyToChannel)n.copyToChannel(new Float32Array(t),0,0);else for(let e=0;e<t.length;e++)r[e]=t[e];let i=this.bufferSource=this.audioContext.createBufferSource();i.buffer=n,i.connect(this.audioContext.destination),i.start(),e&&"test"==e?this.dispatchEvent({type:"testStart"}):this.dispatchEvent({type:"start"}),i.onended=(t=>{e&&"test"==e?this.dispatchEvent({type:"testEnd"}):this.audioDataOffset>=this.audioData.length?(this.dispatchEvent({type:"end"}),this.audioStop()):this.audioPlay(),this.status})}audioStop(){if(this.setStatus("endPlay"),clearTimeout(this.playTimeout),this.audioDataOffset=0,this.audioData=[],this.bufferSource)try{this.bufferSource.stop()}catch(e){console.log(e)}}start(e){if(this.audioData.length)this.audioPlay(e);else{if(this.audioContext||this.audioInit(),!this.audioContext)return void console.log("该浏览器不支持webAudioApi相关接口");this.connectWebSocket(e)}}stop(){this.audioStop()}}function SynthesisXF(e={}){e=Object.assign({rate:1,volume:1,pitch:.5,voiceName:"",text:"",tte:"UTF8",ID:"",BEACON:"",WHISPER:""},e);let t=new TTSRecorder(e);this.speak=function(e){t.setParams({text:e}),t.start()},this.cancel=function(){t.stop()},this.test=function(e){t.setParams({text:e}),t.start("test")},this.getOption=function(){const{speed:e,voice:n,pitch:r,voiceName:i}=t;return{rate:e/50,volume:n/100,pitch:r/100,voiceName:i}},this.setOption=function(n={}){Object.assign(e,n),Object.keys(e).forEach(n=>{switch(n){case"rate":t.speed=(50*e[n]).toFixed()-0;break;case"volume":t.voice=(100*e[n]).toFixed()-0;break;case"pitch":t.pitch=(100*e[n]).toFixed()-0}})},this.getStatus=function(){const{status:e}=t;return{status:e}},this.addEventListener=function(e,n){t.addEventListener(e,n)}}class VoiceFeedbackServer extends BaseServer{constructor(){super("voiceFeedback"),this.option={},this.state=!1,this.ready=!1,this.queue=[],this.thirdConfig={},this.synthesis=new Synthesis,this.synthesis.addEventListener&&this.synthesis.addEventListener("start",this._onStart.bind(this)),this.synthesis.addEventListener&&this.synthesis.addEventListener("end",this._onEnd.bind(this)),this.synthesis.addEventListener&&this.synthesis.addEventListener("error",this._onError.bind(this))}get isReady(){return this.ready}get isStart(){return this.callState("isStart")&&(this.state=!0),this.callState("isStart")}set isStart(e){this.state=e,this.callMutation("toggleOpen",e)}get synthesisType(){return this.callState("synthesisType")}set synthesisType(e){switch(e){case"default":this.synthesis=new Synthesis;break;case"xf":this.synthesis=new SynthesisXF(this.getThirdConfig()),this.synthesis.addEventListener("start",this._onStart.bind(this)),this.synthesis.addEventListener("end",this._onEnd.bind(this)),this.synthesis.addEventListener("error",this._onError.bind(this)),this.synthesis.addEventListener("testStart",this._onTestStart.bind(this)),this.synthesis.addEventListener("testEnd",this._onTestEnd.bind(this)),this.synthesis.addEventListener("testError",this._onTestError.bind(this));break;default:this.synthesis=new Synthesis}this.callMutation("changeSynthesisType",e)}init(e){if(this.synthesis?this.ready=!0:this.addError("your browser dont support"),this.callState("isStart")&&(this.state=!0),!this.ready)return;let t=this._extractConfig(e);this.setThirdConfig(t.thirdConfig,!0),this.toggleOpen(t.isStart),this.changeSynthesisType(t.synthesisType)}toggleOpen(e){e?this.start():this.stop(),this.addInfo("语音合成"+(e?"启动":"停止"))}setThirdConfig(e,t){if(this.callMutation("setThirdConfig",e),t)return;let n=this.synthesis.getOption();this.synthesis=new SynthesisXF(this.getThirdConfig()),this.synthesis.addEventListener("start",this._onStart.bind(this)),this.synthesis.addEventListener("end",this._onEnd.bind(this)),this.synthesis.addEventListener("error",this._onError.bind(this)),this.synthesis.setOption(n)}getThirdConfig(){return this.callState("thirdConfig")}speak(e,t,n){this.ready&&this.state?(t&&"object"==typeof t&&this.setOption(t),"boolean"==typeof t&&(n=t),n&&(this.synthesis.cancel(),this.queue=[]),0===this.queue.length&&this.synthesis.speak(e),this.queue.push(e)):this.isStart&&this.addWarn("voiceFeedbackServer unusable")}test(e,t){this.ready&&this.state?(t&&"object"==typeof t&&this.setOption(t),this.synthesis.test(e)):this.addWarn("voiceFeedbackServer unusable")}start(){this.state=!0,this.callMutation("toggleOpen",!0)}stop(){this.state=!1,this.callMutation("toggleOpen",!1),this.queue=[],this.synthesis.cancel&&this.synthesis.cancel()}getOption(){return this.synthesis.getOption()}setOption(e={}){Object.assign(this.option,e),this.synthesis.setOption(this.option)}changeSynthesisType(e){if(this.synthesis.synthesisType===e)return;this.synthesisType=e;let t=this.synthesis.getOption&&this.synthesis.getOption();this.synthesis.setOption&&this.synthesis.setOption(t)}_onStart(){this.dispatchEvent({type:"start"})}_onEnd(){this.queue.shift(),this.dispatchEvent({type:"end"}),this.queue.length&&this.synthesis.speak(this.queue[0])}_onError(e){this.dispatchEvent({type:"error",result:e.error})}_onTestStart(){this.dispatchEvent({type:"testStart"})}_onTestEnd(){this.queue=[],this.dispatchEvent({type:"testEnd"})}_onTestError(e){this.dispatchEvent({type:"testError",result:e})}}const voiceFeedbackServer=new VoiceFeedbackServer;
/*
* @name: gest.js
* @description: gest.js is a webcam based gesture recognition library that helps developers make webpages more immersive
* @version: 0.5.0
* @author: Hadi Michael (http://hadi.io)
* @acknowledgements: gest.js is an extension of work started by William Wu (https://github.com/wvvvw)
* @license: MIT License
The MIT License (MIT)
Copyright (c) 2013-2014 Hadi Michael (http://hadi.io)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/window.gest=function(e){navigator.getUserMedia=navigator.getUserMedia||navigator.webkitGetUserMedia||navigator.mozGetUserMedia||navigator.msGetUserMedia;var t,n,r,i,o={framerate:25,videoCompressionRate:4,sensitivity:80,skinFilter:!1,debug:{state:!1,canvas:null,context:null},timer:null},s=!1,a=!1,u=function(){if(u.prototype._singletonInstance)return u.prototype._singletonInstance;function t(){return f.removeEventListener("DOMContentLoaded",document,t),f.removeEventListener("load",e,t),c()&&(s=!0),!(!a||!s)&&e.gest.start()}return u.prototype._singletonInstance=this,"complete"===document.readyState?t.call():(f.addEventListener("DOMContentLoaded",document,t),f.addEventListener("load",e,t)),!0},l=function(e){var t=f.createCustomEvent("gest",document);t.direction=e.direction||null,t.up=e.up||!1,t.down=e.down||!1,t.left=e.left||!1,t.right=e.right||!1,t.error=e.error||null,f.fireEvent(t)},c=function(){return n=document.createElement("video"),r=document.createElement("canvas"),n.canPlayType&&r.getContext&&r.getContext("2d")&&navigator.getUserMedia?(n.width=300,n.height=225,n.setAttribute("style","visibility: hidden;"),document.body.appendChild(n),r.setAttribute("style","width: 300px; display: none;"),document.body.appendChild(r),i=r.getContext("2d"),!0):(h(0),!1)},h=function(e,t){var n;switch(e){case 0:n={code:e,message:"gest.js can't run in your browser :("};break;case 1:n={code:e,message:"gest.js could not start."};break;case 2:n={code:e,message:"gest.js has already started."};break;case 10:n={code:e,message:"DEEENIED! gest.js needs webcam access.",obj:t};break;case 11:n={code:e,message:"A constraint specified is not supported by the web-browser.",obj:t};break;case 12:n={code:e,message:"No media tracks of the type specified in the constraints are found.",obj:t};break;case 13:n={code:e,message:"Couldn't get access to webcam.",obj:t};break;default:n=null}o.debug.state&&console.error(n.message),l({error:n})},d={huemin:0,huemax:.1,satmin:.3,satmax:1,valmin:.4,valmax:1,rgb2hsv:function(e,t,n){e/=255,t/=255,n/=255;var r,i,o=Math.max(e,t,n),s=Math.min(e,t,n),a=o,u=o-s;if(i=0===o?0:u/o,o==s)r=0;else{switch(o){case e:r=(t-n)/u+(t<n?6:0);break;case t:r=(n-e)/u+2;break;case n:r=(e-t)/u+4}r/=6}return[r,i,a]},apply:function(e){for(var t=4*(e.width*e.height),n=0,r=0;r<e.height;r++)for(var i=0;i<e.width;i++){t=i+r*e.width;var o=e.data[n],s=e.data[n+1],a=e.data[n+2],u=e.data[n+3],l=this.rgb2hsv(o,s,a);(l[0]>this.huemin&&l[0]<this.huemax||l[0]>.59&&l[0]<1)&&l[1]>this.satmin&&l[1]<this.satmax&&l[2]>this.valmin&&l[2]<this.valmax?(e[n]=o,e[n+1]=s,e[n+2]=a,e[n+3]=u):(e.data[n]=255,e.data[n+1]=255,e.data[n+2]=255,e.data[n+3]=0),n=4*t}return e}},p={priorFrame:!1,get:function(e,t,n,r){var s=i.createImageData(n,r),a=0,u=0,l=0;if(!1!==this.priorFrame)for(var c=4*(s.width*s.height);(c-=4)>=0;){Math.abs(e.data[c]-this.priorFrame.data[c])+Math.abs(e.data[c+1]-this.priorFrame.data[c+1])+Math.abs(e.data[c+2]-this.priorFrame.data[c+2])>768*Math.abs((t-100)/100)?(s.data[c]=255,s.data[c+1]=0,s.data[c+2]=0,s.data[c+3]=255,l+=1,a+=c/4%s.width,u+=Math.floor(c/4/s.height)):(s.data[c]=e.data[c],s.data[c+1]=e.data[c+1],s.data[c+2]=e.data[c+2],s.data[c+3]=e.data[c+3])}l>0&&(g.search({x:a,y:u,d:l}),o.debug.state&&o.debug.context.putImageData&&(o.debug.canvas.width=n,o.debug.canvas.height=r,o.debug.context.putImageData(s,0,0))),this.priorFrame=e}},g={prior:!1,filteringFactor:.9,filteredTotal:0,minTotalChange:300,minDirChange:2,longDirChange:7,state:0,search:function(e){var t={x:e.x/e.d,y:e.y/e.d,d:e.d};this.filteredTotal=this.filteringFactor*this.filteredTotal+(1-this.filteringFactor)*t.d;var n=t.d-this.filteredTotal>this.minTotalChange;switch(this.state){case 0:n&&(this.state=1,g.prior=t);break;case 1:this.state=2;var r=t.x-g.prior.x,i=t.y-g.prior.y,o=Math.abs(i)<Math.abs(r);r<-this.minDirChange&&o?l({direction:"Right",right:!0}):r>this.minDirChange&&o&&l({direction:"Left",left:!0}),i>this.minDirChange&&!o?Math.abs(i)>this.longDirChange?l({direction:"Long down",down:!0}):l({direction:"Down",down:!0}):i<-this.minDirChange&&!o&&(Math.abs(i)>this.longDirChange?l({direction:"Long up",up:!0}):l({direction:"Up",up:!0}));break;case 2:n||(this.state=0)}}},f={htmlEvents:{onload:1,onunload:1,onblur:1,onchange:1,onfocus:1,onreset:1,onselect:1,onsubmit:1,onabort:1,onkeydown:1,onkeypress:1,onkeyup:1,onclick:1,ondblclick:1,onmousedown:1,onmousemove:1,onmouseout:1,onmouseover:1,onmouseup:1},addEventListener:function(e,t,n){t.addEventListener?t.addEventListener(e,n,!1):t.attachEvent&&this.htmlEvents["on"+e]?t.attachEvent("on"+e,n):t["on"+e]=n},removeEventListener:function(e,t,n){t.removeEventListener?t.removeEventListener(e,n,!1):t.detachEvent&&this.htmlEvents["on"+e]?t.detachEvent("on"+e,n):t["on"+e]=null},createCustomEvent:function(e,t){try{var n;return t.createEvent?(n=t.createEvent("Event")).initEvent(e,!0,!0):t.createEventObject&&((n=t.createEventObject()).eventType=e),n.evntName=e,n.evntElement=t,n}catch(e){return console.error(e),!1}},fireEvent:function(e){try{e.evntElement.dispatchEvent?e.evntElement.dispatchEvent(e):e.evntElement.fireEvent&&this.htmlEvents["on"+e.evntName]?e.evntElement.fireEvent("on"+e.eventType,e):e.evntElement[e.evntName]?e.evntElement[e.evntName]():e.evntElement["on"+e.evntName]&&e.evntElement["on"+e.evntName]()}catch(e){console.error(e)}}};return u.prototype.videoUsable=function(e){t=e,n.srcObject=t,f.addEventListener("canplaythrough",n,function(){n.play(),f.addEventListener("playing",n,function(){var e=Math.floor(n.getBoundingClientRect().width/o.videoCompressionRate),t=Math.floor(n.getBoundingClientRect().height/o.videoCompressionRate);r.width=e,r.height=t,o.timer=setInterval(function(){!function(e,t){try{i.drawImage(n,0,0,e,t);var r=i.getImageData(0,0,e,t);o.skinFilter?p.get(d.apply(r),o.sensitivity,e,t):p.get(r,o.sensitivity,e,t)}catch(e){if("NS_ERROR_NOT_AVAILABLE"===e.name)return!1;throw e}}(e,t)},1e3/o.framerate)})})},u.prototype.start=function(){return a=!0,!!s&&!!n},u.prototype.stop=function(){return o.timer&&clearInterval(o.timer),!(!s||!a)&&(n&&(n.src=""),!!t&&!!t.getTracks()[0].stop())},u.prototype.options={subscribeWithCallback:function(e){e&&f.addEventListener("gest",document,function(t){e(t)})},sensitivity:function(e){o.sensitivity=e>=100?100:e<=0?0:e},debug:function(e){return o.debug.state=e,e?(o.debug.canvas=document.createElement("canvas"),o.debug.canvas.setAttribute("style","width: 100%; height: 100%; display: block; position: absolute; top: 0; left: 0;"),document.body.appendChild(o.debug.canvas),