@bddh/starling-realtime-client 1.0.0-beta.2 → 1.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/cjs/BrtcClient.js +1 -1
- package/cjs/Client.js +1 -1
- package/cjs/Cutout.js +1 -1
- package/cjs/Server.js +1 -1
- package/es/BrtcClient.js +1 -1
- package/es/Client.js +1 -1
- package/es/Cutout.js +1 -1
- package/es/Server.js +1 -1
- package/package.json +14 -10
- package/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -1
- package/cjs/_virtual/seriously.js +0 -1
- package/cjs/packages/cut-out/src/Seriously.js +0 -1
- package/cjs/packages/cut-out/src/libs/seriously.chroma.js +0 -1
- package/cjs/packages/cut-out/src/libs/seriously.chroma_obs.js +0 -1
- package/cjs/packages/cut-out/src/libs/seriously.chroma_post.js +0 -1
- package/cjs/packages/cut-out/src/libs/seriously.js +0 -1
- package/cjs/packages/json/es/index.js +0 -1
- package/cjs/packages/wait-for-loading/es/index.js +0 -1
- package/cjs/packages/web-socket/src/create-web-socket.js +0 -1
- package/cjs/packages/web-socket/src/interface.js +0 -1
- package/cjs/packages/web-socket/src/utils.js +0 -1
- package/es/_virtual/_rollupPluginBabelHelpers.js +0 -1
- package/es/_virtual/seriously.js +0 -1
- package/es/packages/cut-out/src/Seriously.js +0 -1
- package/es/packages/cut-out/src/libs/seriously.chroma.js +0 -1
- package/es/packages/cut-out/src/libs/seriously.chroma_obs.js +0 -1
- package/es/packages/cut-out/src/libs/seriously.chroma_post.js +0 -1
- package/es/packages/cut-out/src/libs/seriously.js +0 -1
- package/es/packages/json/es/index.js +0 -1
- package/es/packages/wait-for-loading/es/index.js +0 -1
- package/es/packages/web-socket/src/create-web-socket.js +0 -1
- package/es/packages/web-socket/src/interface.js +0 -1
- package/es/packages/web-socket/src/utils.js +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) zhangyibo02@baidu.com
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/cjs/BrtcClient.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@bddh/starling-brtc"),e=require("@bddh/starling-timeout-controller"),o=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@bddh/starling-brtc"),e=require("@bddh/starling-timeout-controller"),o=require("@bddh/starling-json"),i=require("lodash/isEmpty"),n=require("lodash/isFunction"),s=require("./interface.js");exports.default=class{client;isRtcVideoOn=!1;brtcParams;rtcConnection;rtcConfig;bizConfig;rtcCallback;restarting=!1;timeoutEvent;reopenTimer;restartCount=0;closeLog=!0;haveVideoOn=!1;rtcStateCallback=null;constructor(t){const{brtcParams:o,rtcConnection:i,rtcConfig:n,closeLog:s=!0,rtcCallback:c}=t;this.brtcParams=o,this.rtcConnection=i,this.rtcConfig=n,this.rtcCallback=c,this.closeLog=s,this.timeoutEvent=new e.TimeoutController(6e4,(()=>{if(!this.rtcConnection)return!this.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");this.timeoutEvent.clear(),this.restartRtc?.(this.rtcConnection)}))}openRtc=e=>{if(this.restarting)!this.closeLog&&console.warn("rtc restarting");else if(e&&(this.rtcConnection=e),this.rtcConnection&&!i(this.rtcConnection)){const{server:i,appId:c,token:r,roomName:a,userId:l}=this.rtcConnection,{onRemotedata:d,onLocalStream:h,onRemoteVideoComing:m,onLocalVideoPublished:u,onLocalVideoPublishing:C,onRemoteVideoOn:b,onRemoteVideoOff:g,onRemoteVideoLoading:L,onSuccess:R,onError:f,onLocalVideoConnected:y,onRemoteVideoConnected:v,onRemoteMediaState:E,onPlayingError:S,onDigitalHumanCallback:V}=this.rtcCallback||{};this.timeoutEvent.start(),this.rtcStateCallback=t=>{const{body:e,action:o}=t;V&&V({status:s.statusEnum.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:o,body:e}})},this.client=new t({roomName:a,token:r,userId:l,appId:c,server:i,rtcConfig:this.rtcConfig,callback:{onRemoteVideoConnected:(t,o)=>{if(!o&&!this.haveVideoOn){let t=setTimeout((()=>{this.restartCount<3?(this.restartCount=++this.restartCount,this.restartRtc?.(e)):(this.restartCount=0,this.closeRtc()),clearTimeout(t)}),500)}if(o){const t=document.getElementById("remotevideo500");t.muted=!1;let e=t.play();void 0!==e&&(console.log("promise",e),e.catch((()=>{t.muted=!0,t.play().catch((e=>{!this.closeLog&&console.info("videoElement play error",e),S?.(t),V&&V({status:s.statusEnum.DH_LIB_ERROR,content:{type:s.errorTypeEnum.LOCAL_VIDEO_ERROR}})})),V&&V({status:s.statusEnum.DH_LIB_STATUS,content:{type:s.errorTypeEnum.LOCAL_VIDEO_MUTED}})})))}!this.closeLog&&console.info("remoteVideoConnected",t,o,this.restartCount),this.rtcStateCallback?.({action:"remoteVideoConnected",body:{id:t,connected:o,restartCount:this.restartCount}}),n(v)&&v(t,o)},onRemoteVideoOn:t=>{this.haveVideoOn=!0,!this.closeLog&&console.info("remotevideoon by id: ",t),this.timeoutEvent.clear();const e=document.querySelector("#starlingRtcContainer")?.lastChild;e&&(e.style.display="none"),this.rtcStateCallback?.({action:"remotevideoon",body:t}),V&&V({status:s.statusEnum.DH_LIB_OPEN}),n(b)&&b(t)},onRemoteMediaState:(t,e,o)=>{!this.closeLog&&console.info("remoteMediaState",t,e,o),this.rtcStateCallback?.({action:"remoteMediaState",body:{id:t,medium:e,connected:o}}),n(E)&&E(t,e,o)},onLocalVideoConnected:t=>{!this.closeLog&&console.info("localVideoConnected",t),this.rtcStateCallback?.({action:"localVideoConnected",body:{connected:t}}),n(y)&&y(t)},onRemotedata:t=>{if(this.rtcConfig?.usingdatachannel){const e=o.parse(t);!this.closeLog&&console.info("RTC - receive:",e),n(d)&&d(e)}},onLocalStream:(t,e)=>{!this.closeLog&&console.info("rtc - onlocalstream by name: "+e),this.rtcStateCallback?.({action:"onlocalstream",body:{stream:t,name:e}}),n(h)&&h(t,e)},onLocalVideoPublished:()=>{!this.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),this.rtcStateCallback?.({action:"localvideopublished_ok",body:!0}),n(u)&&u()},onLocalVideoPublishing:()=>{!this.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),this.rtcStateCallback?.({action:"localvideopublishing",body:!0}),n(C)&&C()},onRemoteVideoComing:t=>{!this.closeLog&&console.info("remotevideocoming",t),this.rtcStateCallback?.({action:"remotevideocoming",body:t}),n(m)&&m(t)},onRemoteVideoLoading:t=>{!this.closeLog&&console.info("remotevideoloading by id: ",t),this.rtcStateCallback?.({action:"remotevideoloading",body:t}),n(L)&&L(t)},onRemoteVideoOff:t=>{!this.closeLog&&console.info("remotevideooff: ",t),this.isRtcVideoOn=!1,this.rtcStateCallback?.({action:"remotevideooff",body:t}),V&&V({status:s.statusEnum.DH_LIB_CLOSE}),n(g)&&g(t),this.timeoutEvent.start()},onSuccess:()=>{!this.closeLog&&console.info("rtc - success"),this.rtcStateCallback?.({action:"success",body:!0}),n(R)&&R()},onError:t=>{this.isRtcVideoOn=!1,!this.closeLog&&console.error("rtc - error:",t),this.rtcStateCallback?.({action:"error",body:t}),V&&V({status:s.statusEnum.DH_LIB_ERROR,content:{type:s.errorTypeEnum.RTC_ERROR}}),n(f)&&f(t),(t.includes("Lost connection to the server")||t.includes("Is the server down"))&&this.restartRtc?.(e)}}})}};closeRtc=()=>{this.timeoutEvent.clear(),clearTimeout(this.reopenTimer),this.client?.destroy(),this.restarting=!1};restartRtc=t=>{!this.restarting&&this.bizConfig?.autoReConnect&&(this.rtcStateCallback?.({action:"restartRtc",body:t}),this.restarting=!0,this.closeRtc?.(),this.reopenTimer=setTimeout((()=>{!this.closeLog&&console.error("拉流失败,开始重启"),this.restarting=!1,this.openRtc(t)}),2e3))}};
|
package/cjs/Client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@bddh/starling-json"),t=require("lodash/isEmpty"),a=require("uuid"),n=require("./interface.js"),s=require("./Server.js"),r=require("./BrtcClient.js"),o=require("./DomControl.js"),i=require("./Cutout.js");exports.default=class{token;appKey;appId;connectParams;renderParams;onDigitalHumanCallback;dhServer;rtcServer;rtcConnectParams;cutoutInstance;isHuawei=o.checkIsHuawei();constructor(e){const{wrapperId:a,token:c,appKey:d,appId:u,connectParams:m,renderParams:l,rtcConnectParams:h,onDigitalHumanCallback:p}=e;this.token=c,this.appKey=d,this.appId=u,this.connectParams=m,this.renderParams=l;const{fullStatus:I,closeLog:g}=l;this.onDigitalHumanCallback=e=>{const{status:t}=e;t!==n.statusEnum.DH_LIB_FULL_STATUS?p&&p(e):I&&p&&p(e)},this.dhServer=new s.default("wss://persona.baidu.com:8850/cloud/digital-human-demonstration");const{playerWrapper:C}=o.createHumanDom({autoChromaKey:!!l.autoChromaKey})||{},v=document.getElementById(a);v||console.error("dom with wrapperId is not find"),C&&v?.appendChild(C),this.rtcServer=new r.default({closeLog:g,brtcParams:{},videoWrapperId:o.RTC_VIDEO_ID,rtcConfig:{remotevideoviewid:a,showvideobps:!1,usingvideo:!1,usingaudio:!1,aspublisher:!1,usingdatachannel:!0,autoplaymuted:!1},bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new i.default({sourceId:o.RTC_VIDEO_ID}),t(h)||(this.rtcConnectParams=h,this.rtcServer.openRtc(h))}onRemoteVideoComing=e=>{this.rtcConnectParams&&this.rtcConnectParams.feedId&&e===+this.rtcConnectParams.feedId&&this.rtcServer?.client?.subscribeStreaming("remotevideo500",+this.rtcConnectParams.feedId)};onRemoteVideoOn=()=>{setTimeout((async()=>{const e=document.getElementById(o.RTC_VIDEO_ID);if(await(this.cutoutInstance?.updateSource?.(o.RTC_VIDEO_ID)),e){e.setAttribute?.("data-playing","true");const{videoWidth:t,videoHeight:a}=e,n=document.getElementById(o.DEFAULT_CANVAS_ID),s=n.getContext("2d");n&&s&&(n.width=t,n.height=a,s.drawImage(e,0,0,t,a))}}),100)};connectListener=t=>{const{code:a,body:n}=t;if(0===a){const t=e.parse(n),{rtcServerUrl:a,appId:s,clientToken:r,roomName:o,clientId:i,feedId:c,chargeId:d}=t;this.rtcConnectParams={server:a,appId:s,token:r,roomName:o,userId:i,feedId:c,chargeId:d},s&&o&&this.rtcServer?.openRtc(this.rtcConnectParams)}};createServer=e=>{this.dhServer?.createSocket({token:this.token,appKey:this.appKey,appId:this.appId,...e?{sessionId:e}:{},parameters:this.connectParams,onConnect:this.connectListener,onDigitalHumanCallback:this.onDigitalHumanCallback})};checkHumanInstansce=()=>{this.dhServer||console.warn("请先初始化数字人示例")};sendMessage=(e,t)=>this.dhServer?.sendMessage(e,t);textRender=e=>{const{requestId:t,body:n,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:t||a.v4(),action:"TEXT_RENDER",body:n,clientTs:(new Date).getTime()},s)};textStreamRender=t=>{const{requestId:n,body:s,onCallbackMsg:r}=t,{first:o}=e.parse(s);this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:n||a.v4(),action:"TEXT_STREAM_RENDER",body:s,clientTs:(new Date).getTime()},o?r:null)};audioRender=e=>{const{body:t,onCallbackMsg:n}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:a.v4(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},n)};audioStreamRender=e=>{const{body:t,onCallbackMsg:n}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:a.v4(),action:"AUDIO_STREAM_RENDER",body:t,clientTs:(new Date).getTime()},n)};destory=async()=>{await(this.dhServer?.closeSocket()),this.rtcServer?.closeRtc(),o.removeHumanDom(),this.dhServer=null,this.rtcServer=null};pauseHuman=()=>o.playHumanVideo(!1);playHuman=()=>o.playHumanVideo(!0);muteHuman=()=>o.muteHumanVideo(!0);unMuteHuman=()=>{const e=o.muteHumanVideo(!1);if(!this.isHuawei)return e.paused&&e.play();e.pause(),e.play()}};
|
package/cjs/Cutout.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@bddh/starling-cutout/src/Seriously");const e={version:2,chromaKey:{screen:[53,186,123],similarity:90,edgeShrink:3,smoothness:80,spill:100,opacity:1,contrast:0,brightness:0,gamma:0}};exports.DEFAULT_EFFECTS=e,exports.default=class{cutoutInstance;constructor(s){const{effects:o,sourceId:r}=s;this.cutoutInstance=new t("starling-cutout-canvas",r||"starling-cutout-video",o?.chromaKey||e.chromaKey,o?.version||e.version)}setOptions(t){t&&this.cutoutInstance?.setOptions(t)}destroy(){return this.cutoutInstance.destroy()}updateSource(t){return this.cutoutInstance.updateSource(t)}};
|
package/cjs/Server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("uuid"),t=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("uuid"),t=require("@bddh/starling-web-socket/src/create-web-socket"),s=require("./interface.js");exports.default=class{dhServerSocket=null;socketClosingPromise=null;url;firstConnect=!0;connectParams=null;constructor(e){this.url=e}createSocket=async n=>{this.connectParams=n;const{token:o,sessionId:r,onConnect:c,onDigitalHumanCallback:i}=n;return this.socketClosingPromise&&await this.socketClosingPromise,this.dhServerSocket&&await this.closeSocket(),new Promise(((n,a)=>{const u=t.createWebSocket(this.url,{reopen:!0,keepAlive:"heartbeat",combine:(e,t)=>e?.requestId===t?.requestId,onOpen:()=>{if(this.dhServerSocket=u,r&&this.firstConnect)return u.request({action:"RE_CONNECT",requestId:e.v4(),body:JSON.stringify({token:o,sessionId:r})}).on(((e,t)=>{c(e),0!==e.code&&(t(),this.handleConnect()),n(u)})),void(this.firstConnect=!1);this.handleConnect()},onClose:()=>{this.dhServerSocket=null,this.socketClosingPromise=null},onError:e=>{a(e)}});u.onReadyStateChange((e=>{-1===e&&i&&i({status:s.statusEnum.DH_LIB_INIT}),i&&i({status:s.statusEnum.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:s.WS_STATUS_MAP[e]}})})),u.onMessage((e=>{const{action:t}=e;[s.errorTypeEnum.TIMEOUT_EXIT,s.errorTypeEnum.DISCONNECT_ALERT].includes(t)&&i&&i({status:s.statusEnum.DH_LIB_STATUS,content:{type:t}})})),u.open()}))};closeSocket=async()=>{this.dhServerSocket&&(this.socketClosingPromise=this.dhServerSocket.close(),await this.socketClosingPromise,this.dhServerSocket=null)};handleConnect=async()=>{if(!this.connectParams)return;const{appId:t,appKey:s,token:n,parameters:o,onConnect:r}=this.connectParams;(t||s||n)&&this.dhServerSocket?.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:e.v4(),body:JSON.stringify({token:n,appId:t,appKey:s,parameters:o})}).on(((e,t)=>{r(e),0!==e.code&&t()}))};async sendMessage(e,t){try{this.dhServerSocket&&this.dhServerSocket?.request(e).on((e=>{t&&t(e)}))}catch(s){t&&t({code:-11,body:null,action:"RENDER_ERROR",requestId:e.requestId,message:JSON.stringify(s)})}}};
|
package/es/BrtcClient.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"@bddh/starling-brtc";import{TimeoutController as o}from"@bddh/starling-timeout-controller";import e from"
|
|
1
|
+
import t from"@bddh/starling-brtc";import{TimeoutController as o}from"@bddh/starling-timeout-controller";import e from"@bddh/starling-json";import i from"lodash/isEmpty";import n from"lodash/isFunction";import{statusEnum as c,errorTypeEnum as s}from"./interface.js";class r{client;isRtcVideoOn=!1;brtcParams;rtcConnection;rtcConfig;bizConfig;rtcCallback;restarting=!1;timeoutEvent;reopenTimer;restartCount=0;closeLog=!0;haveVideoOn=!1;rtcStateCallback=null;constructor(t){const{brtcParams:e,rtcConnection:i,rtcConfig:n,closeLog:c=!0,rtcCallback:s}=t;this.brtcParams=e,this.rtcConnection=i,this.rtcConfig=n,this.rtcCallback=s,this.closeLog=c,this.timeoutEvent=new o(6e4,(()=>{if(!this.rtcConnection)return!this.closeLog&&console.warn("remotevideoon事件超时, rtcConnectionRef is null");this.timeoutEvent.clear(),this.restartRtc?.(this.rtcConnection)}))}openRtc=o=>{if(this.restarting)!this.closeLog&&console.warn("rtc restarting");else if(o&&(this.rtcConnection=o),this.rtcConnection&&!i(this.rtcConnection)){const{server:i,appId:r,token:a,roomName:l,userId:d}=this.rtcConnection,{onRemotedata:h,onLocalStream:m,onRemoteVideoComing:C,onLocalVideoPublished:u,onLocalVideoPublishing:b,onRemoteVideoOn:g,onRemoteVideoOff:L,onRemoteVideoLoading:f,onSuccess:R,onError:y,onLocalVideoConnected:S,onRemoteVideoConnected:V,onRemoteMediaState:p,onPlayingError:v,onDigitalHumanCallback:k}=this.rtcCallback||{};this.timeoutEvent.start(),this.rtcStateCallback=t=>{const{body:o,action:e}=t;k&&k({status:c.DH_LIB_FULL_STATUS,content:{type:"rtcState",action:e,body:o}})},this.client=new t({roomName:l,token:a,userId:d,appId:r,server:i,rtcConfig:this.rtcConfig,callback:{onRemoteVideoConnected:(t,e)=>{if(!e&&!this.haveVideoOn){let t=setTimeout((()=>{this.restartCount<3?(this.restartCount=++this.restartCount,this.restartRtc?.(o)):(this.restartCount=0,this.closeRtc()),clearTimeout(t)}),500)}if(e){const t=document.getElementById("remotevideo500");t.muted=!1;let o=t.play();void 0!==o&&(console.log("promise",o),o.catch((()=>{t.muted=!0,t.play().catch((o=>{!this.closeLog&&console.info("videoElement play error",o),v?.(t),k&&k({status:c.DH_LIB_ERROR,content:{type:s.LOCAL_VIDEO_ERROR}})})),k&&k({status:c.DH_LIB_STATUS,content:{type:s.LOCAL_VIDEO_MUTED}})})))}!this.closeLog&&console.info("remoteVideoConnected",t,e,this.restartCount),this.rtcStateCallback?.({action:"remoteVideoConnected",body:{id:t,connected:e,restartCount:this.restartCount}}),n(V)&&V(t,e)},onRemoteVideoOn:t=>{this.haveVideoOn=!0,!this.closeLog&&console.info("remotevideoon by id: ",t),this.timeoutEvent.clear();const o=document.querySelector("#starlingRtcContainer")?.lastChild;o&&(o.style.display="none"),this.rtcStateCallback?.({action:"remotevideoon",body:t}),k&&k({status:c.DH_LIB_OPEN}),n(g)&&g(t)},onRemoteMediaState:(t,o,e)=>{!this.closeLog&&console.info("remoteMediaState",t,o,e),this.rtcStateCallback?.({action:"remoteMediaState",body:{id:t,medium:o,connected:e}}),n(p)&&p(t,o,e)},onLocalVideoConnected:t=>{!this.closeLog&&console.info("localVideoConnected",t),this.rtcStateCallback?.({action:"localVideoConnected",body:{connected:t}}),n(S)&&S(t)},onRemotedata:t=>{if(this.rtcConfig?.usingdatachannel){const o=e.parse(t);!this.closeLog&&console.info("RTC - receive:",o),n(h)&&h(o)}},onLocalStream:(t,o)=>{!this.closeLog&&console.info("rtc - onlocalstream by name: "+o),this.rtcStateCallback?.({action:"onlocalstream",body:{stream:t,name:o}}),n(m)&&m(t,o)},onLocalVideoPublished:()=>{!this.closeLog&&console.info("LocalVideoPublished 本地视频发布成功"),this.rtcStateCallback?.({action:"localvideopublished_ok",body:!0}),n(u)&&u()},onLocalVideoPublishing:()=>{!this.closeLog&&console.info("LocalVideoPublishing 本地视频发布成功"),this.rtcStateCallback?.({action:"localvideopublishing",body:!0}),n(b)&&b()},onRemoteVideoComing:t=>{!this.closeLog&&console.info("remotevideocoming",t),this.rtcStateCallback?.({action:"remotevideocoming",body:t}),n(C)&&C(t)},onRemoteVideoLoading:t=>{!this.closeLog&&console.info("remotevideoloading by id: ",t),this.rtcStateCallback?.({action:"remotevideoloading",body:t}),n(f)&&f(t)},onRemoteVideoOff:t=>{!this.closeLog&&console.info("remotevideooff: ",t),this.isRtcVideoOn=!1,this.rtcStateCallback?.({action:"remotevideooff",body:t}),k&&k({status:c.DH_LIB_CLOSE}),n(L)&&L(t),this.timeoutEvent.start()},onSuccess:()=>{!this.closeLog&&console.info("rtc - success"),this.rtcStateCallback?.({action:"success",body:!0}),n(R)&&R()},onError:t=>{this.isRtcVideoOn=!1,!this.closeLog&&console.error("rtc - error:",t),this.rtcStateCallback?.({action:"error",body:t}),k&&k({status:c.DH_LIB_ERROR,content:{type:s.RTC_ERROR}}),n(y)&&y(t),(t.includes("Lost connection to the server")||t.includes("Is the server down"))&&this.restartRtc?.(o)}}})}};closeRtc=()=>{this.timeoutEvent.clear(),clearTimeout(this.reopenTimer),this.client?.destroy(),this.restarting=!1};restartRtc=t=>{!this.restarting&&this.bizConfig?.autoReConnect&&(this.rtcStateCallback?.({action:"restartRtc",body:t}),this.restarting=!0,this.closeRtc?.(),this.reopenTimer=setTimeout((()=>{!this.closeLog&&console.error("拉流失败,开始重启"),this.restarting=!1,this.openRtc(t)}),2e3))}}export{r as default};
|
package/es/Client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"
|
|
1
|
+
import e from"@bddh/starling-json";import t from"lodash/isEmpty";import{v4 as a}from"uuid";import{statusEnum as n}from"./interface.js";import s from"./Server.js";import r from"./BrtcClient.js";import{checkIsHuawei as o,createHumanDom as i,RTC_VIDEO_ID as c,DEFAULT_CANVAS_ID as d,removeHumanDom as m,playHumanVideo as h,muteHumanVideo as u}from"./DomControl.js";import l from"./Cutout.js";class p{token;appKey;appId;connectParams;renderParams;onDigitalHumanCallback;dhServer;rtcServer;rtcConnectParams;cutoutInstance;isHuawei=o();constructor(e){const{wrapperId:a,token:o,appKey:d,appId:m,connectParams:h,renderParams:u,rtcConnectParams:p,onDigitalHumanCallback:g}=e;this.token=o,this.appKey=d,this.appId=m,this.connectParams=h,this.renderParams=u;const{fullStatus:I,closeLog:C}=u;this.onDigitalHumanCallback=e=>{const{status:t}=e;t!==n.DH_LIB_FULL_STATUS?g&&g(e):I&&g&&g(e)},this.dhServer=new s("wss://persona.baidu.com:8850/cloud/digital-human-demonstration");const{playerWrapper:S}=i({autoChromaKey:!!u.autoChromaKey})||{},b=document.getElementById(a);b||console.error("dom with wrapperId is not find"),S&&b?.appendChild(S),this.rtcServer=new r({closeLog:C,brtcParams:{},videoWrapperId:c,rtcConfig:{remotevideoviewid:a,showvideobps:!1,usingvideo:!1,usingaudio:!1,aspublisher:!1,usingdatachannel:!0,autoplaymuted:!1},bizConfig:{},rtcCallback:{onRemoteVideoComing:this.onRemoteVideoComing,onDigitalHumanCallback:this.onDigitalHumanCallback}}),this.cutoutInstance=new l({sourceId:c}),t(p)||(this.rtcConnectParams=p,this.rtcServer.openRtc(p))}onRemoteVideoComing=e=>{this.rtcConnectParams&&this.rtcConnectParams.feedId&&e===+this.rtcConnectParams.feedId&&this.rtcServer?.client?.subscribeStreaming("remotevideo500",+this.rtcConnectParams.feedId)};onRemoteVideoOn=()=>{setTimeout((async()=>{const e=document.getElementById(c);if(await(this.cutoutInstance?.updateSource?.(c)),e){e.setAttribute?.("data-playing","true");const{videoWidth:t,videoHeight:a}=e,n=document.getElementById(d),s=n.getContext("2d");n&&s&&(n.width=t,n.height=a,s.drawImage(e,0,0,t,a))}}),100)};connectListener=t=>{const{code:a,body:n}=t;if(0===a){const t=e.parse(n),{rtcServerUrl:a,appId:s,clientToken:r,roomName:o,clientId:i,feedId:c,chargeId:d}=t;this.rtcConnectParams={server:a,appId:s,token:r,roomName:o,userId:i,feedId:c,chargeId:d},s&&o&&this.rtcServer?.openRtc(this.rtcConnectParams)}};createServer=e=>{this.dhServer?.createSocket({token:this.token,appKey:this.appKey,appId:this.appId,...e?{sessionId:e}:{},parameters:this.connectParams,onConnect:this.connectListener,onDigitalHumanCallback:this.onDigitalHumanCallback})};checkHumanInstansce=()=>{this.dhServer||console.warn("请先初始化数字人示例")};sendMessage=(e,t)=>this.dhServer?.sendMessage(e,t);textRender=e=>{const{requestId:t,body:n,onCallbackMsg:s}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:t||a(),action:"TEXT_RENDER",body:n,clientTs:(new Date).getTime()},s)};textStreamRender=t=>{const{requestId:n,body:s,onCallbackMsg:r}=t,{first:o}=e.parse(s);this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:n||a(),action:"TEXT_STREAM_RENDER",body:s,clientTs:(new Date).getTime()},o?r:null)};audioRender=e=>{const{body:t,onCallbackMsg:n}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:a(),action:"AUDIO_RENDER",body:t,clientTs:(new Date).getTime()},n)};audioStreamRender=e=>{const{body:t,onCallbackMsg:n}=e;this.checkHumanInstansce(),this.dhServer?.sendMessage({requestId:a(),action:"AUDIO_STREAM_RENDER",body:t,clientTs:(new Date).getTime()},n)};destory=async()=>{await(this.dhServer?.closeSocket()),this.rtcServer?.closeRtc(),m(),this.dhServer=null,this.rtcServer=null};pauseHuman=()=>h(!1);playHuman=()=>h(!0);muteHuman=()=>u(!0);unMuteHuman=()=>{const e=u(!1);if(!this.isHuawei)return e.paused&&e.play();e.pause(),e.play()}}export{p as default};
|
package/es/Cutout.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"
|
|
1
|
+
import t from"@bddh/starling-cutout/src/Seriously";const s={version:2,chromaKey:{screen:[53,186,123],similarity:90,edgeShrink:3,smoothness:80,spill:100,opacity:1,contrast:0,brightness:0,gamma:0}};class e{cutoutInstance;constructor(e){const{effects:o,sourceId:c}=e;this.cutoutInstance=new t("starling-cutout-canvas",c||"starling-cutout-video",o?.chromaKey||s.chromaKey,o?.version||s.version)}setOptions(t){t&&this.cutoutInstance?.setOptions(t)}destroy(){return this.cutoutInstance.destroy()}updateSource(t){return this.cutoutInstance.updateSource(t)}}export{s as DEFAULT_EFFECTS,e as default};
|
package/es/Server.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{v4 as e}from"uuid";import{createWebSocket as t}from"
|
|
1
|
+
import{v4 as e}from"uuid";import{createWebSocket as t}from"@bddh/starling-web-socket/src/create-web-socket";import{statusEnum as s,WS_STATUS_MAP as o,errorTypeEnum as n}from"./interface.js";class r{dhServerSocket=null;socketClosingPromise=null;url;firstConnect=!0;connectParams=null;constructor(e){this.url=e}createSocket=async r=>{this.connectParams=r;const{token:i,sessionId:c,onConnect:a,onDigitalHumanCallback:h}=r;return this.socketClosingPromise&&await this.socketClosingPromise,this.dhServerSocket&&await this.closeSocket(),new Promise(((r,d)=>{const l=t(this.url,{reopen:!0,keepAlive:"heartbeat",combine:(e,t)=>e?.requestId===t?.requestId,onOpen:()=>{if(this.dhServerSocket=l,c&&this.firstConnect)return l.request({action:"RE_CONNECT",requestId:e(),body:JSON.stringify({token:i,sessionId:c})}).on(((e,t)=>{a(e),0!==e.code&&(t(),this.handleConnect()),r(l)})),void(this.firstConnect=!1);this.handleConnect()},onClose:()=>{this.dhServerSocket=null,this.socketClosingPromise=null},onError:e=>{d(e)}});l.onReadyStateChange((e=>{-1===e&&h&&h({status:s.DH_LIB_INIT}),h&&h({status:s.DH_LIB_FULL_STATUS,content:{type:"wsState",readyState:e,body:o[e]}})})),l.onMessage((e=>{const{action:t}=e;[n.TIMEOUT_EXIT,n.DISCONNECT_ALERT].includes(t)&&h&&h({status:s.DH_LIB_STATUS,content:{type:t}})})),l.open()}))};closeSocket=async()=>{this.dhServerSocket&&(this.socketClosingPromise=this.dhServerSocket.close(),await this.socketClosingPromise,this.dhServerSocket=null)};handleConnect=async()=>{if(!this.connectParams)return;const{appId:t,appKey:s,token:o,parameters:n,onConnect:r}=this.connectParams;(t||s||o)&&this.dhServerSocket?.request({action:"CONNECT",clientTs:(new Date).getTime(),requestId:e(),body:JSON.stringify({token:o,appId:t,appKey:s,parameters:n})}).on(((e,t)=>{r(e),0!==e.code&&t()}))};async sendMessage(e,t){try{this.dhServerSocket&&this.dhServerSocket?.request(e).on((e=>{t&&t(e)}))}catch(s){t&&t({code:-11,body:null,action:"RENDER_ERROR",requestId:e.requestId,message:JSON.stringify(s)})}}}export{r as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bddh/starling-realtime-client",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.4",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"react",
|
|
6
6
|
"indexDB"
|
|
@@ -27,18 +27,22 @@
|
|
|
27
27
|
"deploy": "npm publish --registry=https://registry.npmjs.org --access public"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
|
-
"lodash": "^4.17.21",
|
|
31
|
-
"uuid": "^9.0.0",
|
|
32
30
|
"@bddh/starling-brtc": "^1.0.2",
|
|
33
|
-
"@bddh/starling-
|
|
31
|
+
"@bddh/starling-cutout": "^1.2.1",
|
|
32
|
+
"@bddh/starling-json": "^1.0.1",
|
|
33
|
+
"@bddh/starling-timeout-controller": "^1.0.3",
|
|
34
|
+
"@bddh/starling-web-socket": "^1.0.10",
|
|
35
|
+
"lodash": "^4.17.21",
|
|
36
|
+
"uuid": "^9.0.0"
|
|
34
37
|
},
|
|
35
38
|
"dependencies": {
|
|
39
|
+
"@bddh/starling-brtc": "^1.0.2",
|
|
40
|
+
"@bddh/starling-cutout": "^1.2.1",
|
|
41
|
+
"@bddh/starling-json": "^1.0.1",
|
|
42
|
+
"@bddh/starling-timeout-controller": "^1.0.3",
|
|
36
43
|
"@bddh/starling-web-socket": "^1.0.10",
|
|
37
44
|
"lodash": "^4.17.21",
|
|
38
|
-
"uuid": "^9.0.0"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"@bddh/starling-timeout-controller": "^1.0.2",
|
|
42
|
-
"@bddh/starling-cutout": "^1.2.1"
|
|
43
|
-
}
|
|
45
|
+
"uuid": "^9.0.0"
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "4a9c2c781bae8b4f245659b41ea29d7f0f014ce3"
|
|
44
48
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},r(t)}function t(r,t){for(var e=0;e<t.length;e++){var o=t[e];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(r,l(o.key),o)}}function e(r){if(Array.isArray(r))return i(r)}function o(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function n(r,t){if(r){if("string"==typeof r)return i(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?i(r,t):void 0}}function i(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,o=new Array(t);e<t;e++)o[e]=r[e];return o}function a(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function u(r,t){if("object"!=typeof r||null===r)return r;var e=r[Symbol.toPrimitive];if(void 0!==e){var o=e.call(r,t||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(r)}function l(r){var t=u(r,"string");return"symbol"==typeof t?t:String(t)}exports.arrayLikeToArray=i,exports.arrayWithoutHoles=e,exports.classCallCheck=function(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")},exports.createClass=function(r,e,o){return e&&t(r.prototype,e),o&&t(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r},exports.iterableToArray=o,exports.nonIterableSpread=a,exports.toConsumableArray=function(r){return e(r)||o(r)||n(r)||a()},exports.toPrimitive=u,exports.toPropertyKey=l,exports.typeof=r,exports.unsupportedIterableToArray=n;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";exports.__module={exports:{}};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("lodash/isEmpty"),t=require("lodash/isNumber"),s=require("../../wait-for-loading/es/index.js");require("./libs/seriously.js"),require("./libs/seriously.chroma.js"),require("./libs/seriously.chroma_obs.js"),require("./libs/seriously.chroma_post.js");exports.default=class{seriously;version;defaultOptions={screen:[0,255,0,0]};targetElement;sourceElement;source=null;target=null;effect=null;backEffect=null;constructor(e,t,s,i=0){this.seriously=new window.Seriously,this.version=i,this.targetElement="string"==typeof e?document.getElementById(e):e,this.sourceElement="string"==typeof t?document.getElementById(t):t,this.init(s)}async loadEffect(e){return 1===e?"chroma":"chroma_obs"}async init(e){console.info("serious version:",this.version);const t=await this.loadEffect(this.version);await s.waitForLoading((()=>!(this.sourceElement?.videoWidth>0&&this.sourceElement?.videoHeight>0))),this.targetElement.width=this.sourceElement.videoWidth,this.targetElement.height=this.sourceElement.videoHeight,this.source=this.seriously.source(this.sourceElement),this.target=this.seriously.target(this.targetElement),this.effect=this.seriously.effect(t),this.backEffect=this.seriously.effect("chroma_post"),this.effect.source=this.source,this.backEffect.source=this.effect,this.target.source=this.backEffect,this.seriously.go(),this.setOptions(this.defaultOptions),e&&this.setOptions(e)}destroy(){this.seriously.destroy()}async updateSource(e){e&&this.effect&&this.backEffect?(this.sourceElement="string"==typeof e?document.getElementById(e):e,await s.waitForLoading((()=>!(this.sourceElement?.videoWidth>0&&this.sourceElement?.videoHeight>0))),this.source?.destroy(),console.info("update source: ",this.source?.isDestroyed()),this.source=this.seriously.source(this.sourceElement),this.effect.source=this.source,this.backEffect.source=this.effect,this.target.source=this.backEffect):console.warn("update source error: source or effect is null",e,this.effect)}async setOptions(s){if(this.defaultOptions={...this.defaultOptions,...s},!this.effect||!this.backEffect||e(s))return;console.info("set options: ",s);const{screen:i,edgeShrink:o}=s;if(i&&i.length>=3){const[e,s,o,r]=i;this.effect.screen=[e/255,s/255,o/255,t(r)?r:1]}o&&(this.backEffect.edgeShrink=o);for(const[e,t]of Object.entries(s))"number"==typeof t&&"screen"!==e&&"edgeShrink"!==e&&(this.effect[e]=t)}};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("./seriously.js");window,console.info("seriously version: chroma"),e.seriouslyExports.plugin("chroma",{shader:function(e,r){return r.vertex=["precision mediump float;","attribute vec4 position;","attribute vec2 texCoord;","uniform vec2 resolution;","uniform mat4 transform;","varying vec2 vTexCoord;","uniform vec4 screen;","uniform float balance;","varying float screenSat;","varying vec3 screenPrimary;","void main(void) {","\tfloat fmin = min(min(screen.r, screen.g), screen.b);","\tfloat fmax = max(max(screen.r, screen.g), screen.b);","\tfloat secondaryComponents;","\tscreenPrimary = step(fmax, screen.rgb);","\tsecondaryComponents = dot(1.0 - screenPrimary, screen.rgb);","\tscreenSat = fmax - mix(secondaryComponents - fmin, secondaryComponents / 2.0, balance);","\tvec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);","\tscreenPosition = transform * screenPosition;","\tgl_Position = screenPosition;","\tgl_Position.xy = screenPosition.xy * 2.0 / resolution;","\tgl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);","\tvTexCoord = texCoord;","}"].join("\n"),r.fragment=[this.inputs.mask?"#define MASK":"","precision mediump float;","varying vec2 vTexCoord;","uniform sampler2D source;","uniform vec4 screen;","uniform float screenWeight;","uniform float balance;","uniform float clipBlack;","uniform float clipWhite;","uniform bool mask;","varying float screenSat;","varying vec3 screenPrimary;","void main(void) {","\tfloat pixelSat, secondaryComponents;","\tvec4 sourcePixel = texture2D(source, vTexCoord);","\n\t\t\t\t\tif (screen.a == 0.0) {\n\t\t\t\t\t\tgl_FragColor = sourcePixel;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t","\tfloat fmin = min(min(sourcePixel.r, sourcePixel.g), sourcePixel.b);","\tfloat fmax = max(max(sourcePixel.r, sourcePixel.g), sourcePixel.b);","\tvec3 pixelPrimary = step(fmax, sourcePixel.rgb);","\tsecondaryComponents = dot(1.0 - pixelPrimary, sourcePixel.rgb);","\tpixelSat = fmax - mix(secondaryComponents - fmin, secondaryComponents / 2.0, balance);","\tfloat diffPrimary = dot(abs(pixelPrimary - screenPrimary), vec3(1.0));","\tfloat solid = step(1.0, step(pixelSat, 0.1) + step(fmax, 0.1) + diffPrimary);","\tfloat alpha = max(0.0, 1.0 - pixelSat / screenSat);","\talpha = smoothstep(clipBlack, clipWhite, alpha);","\tvec4 semiTransparentPixel = vec4((sourcePixel.rgb - (1.0 - alpha) * screen.rgb * screenWeight) / max(0.00001, alpha), alpha);","\tvec4 pixel = mix(semiTransparentPixel, sourcePixel, solid);","#ifdef MASK","\tgl_FragColor = vec4(vec3(pixel.a), 1.0);","#else","\tgl_FragColor = pixel;","#endif","}"].join("\n"),r},inPlace:!0,inputs:{source:{type:"image",uniform:"source"},screen:{type:"color",uniform:"screen",defaultValue:[66/255,195/255,31/255,1]},weight:{type:"number",uniform:"screenWeight",defaultValue:1,min:0},balance:{type:"number",uniform:"balance",defaultValue:1,min:0,max:1},clipBlack:{type:"number",uniform:"clipBlack",defaultValue:0,min:0,max:1},clipWhite:{type:"number",uniform:"clipWhite",defaultValue:1,min:0,max:1},mask:{type:"boolean",defaultValue:!1,uniform:"mask",shaderDirty:!0}},title:"Chroma Key",description:""});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("./seriously.js");window,console.info("seriously version: chroma_obs"),e.seriouslyExports.plugin("chroma_obs",{shader:function(e,t){return t.vertex=["precision mediump float;","attribute vec4 position;","attribute vec2 texCoord;","uniform vec2 resolution;","uniform mat4 transform;","varying vec2 vTexCoord;","const vec4 cb_v4 = vec4(-0.100644, -0.338572, 0.439216, 0.501961);","const vec4 cr_v4 = vec4(0.439216, -0.398942, -0.040274, 0.501961);","uniform vec4 screen;","uniform float similarity;","uniform float smoothness;","uniform float spill;","uniform float contrast;","uniform float gamma;","varying vec2 chroma_key;","varying vec2 pixel_size;","varying float similarity_v;","varying float smoothness_v;","varying float spill_v;","varying float contrast_v;","varying float gamma_v;","void main(void) {","\tfloat cb = dot(screen.rgb, cb_v4.xyz) + cb_v4.w;","\tfloat cr = dot(screen.rgb, cr_v4.xyz) + cr_v4.w;","\tchroma_key.x = cb;","\tchroma_key.y = cr;","\tpixel_size.x = 1.0 / resolution.x;","\tpixel_size.y = 1.0 / resolution.y;","\tsimilarity_v = similarity * 1.0 / 1000.0;","\tsmoothness_v = smoothness * 1.0 / 1000.0;","\tspill_v = spill * 1.0 / 1000.0;","\tcontrast_v = (contrast < 0.0) ? (1.0 / (-contrast + 1.0)) : (contrast + 1.0);","\tgamma_v = (gamma < 0.0) ? (-gamma + 1.0) : (1.0 / (gamma + 1.0));","\tvec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);","\tscreenPosition = transform * screenPosition;","\tgl_Position = screenPosition;","\tgl_Position.xy = screenPosition.xy * 2.0 / resolution;","\tgl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);","\tvTexCoord = texCoord;","}"].join("\n"),t.fragment=[this.inputs.mask?"#define MASK":"","precision mediump float;","varying vec2 vTexCoord;","uniform bool mask;","uniform vec4 screen;","uniform sampler2D source;","const vec4 cb_v4 = vec4(-0.100644, -0.338572, 0.439216, 0.501961);","const vec4 cr_v4 = vec4(0.439216, -0.398942, -0.040274, 0.501961);","uniform float opacity;","uniform float brightness;","varying vec2 chroma_key;","varying vec2 pixel_size;","varying float similarity_v;","varying float smoothness_v;","varying float spill_v;","varying float contrast_v;","varying float gamma_v;","vec4 CalcColor(vec4 rgba) {","\treturn vec4(pow(rgba.rgb, vec3(gamma_v, gamma_v, gamma_v)) * contrast_v + brightness, rgba.a);","}","float GetChromaDist(vec3 rgb) {","\tfloat cb = dot(rgb.rgb, cb_v4.xyz) + cb_v4.w;","\tfloat cr = dot(rgb.rgb, cr_v4.xyz) + cr_v4.w;","\treturn distance(chroma_key, vec2(cb, cr));","}","float GetNonlinearChannel(float u) {","\treturn u;","}","vec3 GetNonlinearColor(vec3 rgb)","{","\treturn vec3(GetNonlinearChannel(rgb.r), GetNonlinearChannel(rgb.g), GetNonlinearChannel(rgb.b));","}","vec3 SampleTexture(vec2 uv)","{","\tvec3 rgb = texture2D(source, uv).rgb;","\treturn GetNonlinearColor(rgb);","}","float GetBoxFilteredChromaDist(vec3 rgb, vec2 texCoord) {","\tvec2 h_pixel_size = pixel_size / 2.0;","\tvec2 point_0 = vec2(pixel_size.x, h_pixel_size.y);","\tvec2 point_1 = vec2(h_pixel_size.x, -pixel_size.y);","\tfloat distVal = GetChromaDist(SampleTexture(texCoord-point_0));","\tdistVal += GetChromaDist(SampleTexture(texCoord+point_0));","\tdistVal += GetChromaDist(SampleTexture(texCoord-point_1));","\tdistVal += GetChromaDist(SampleTexture(texCoord+point_1));","\tdistVal *= 2.0;","\tdistVal += GetChromaDist(GetNonlinearColor(rgb));","\treturn distVal / 9.0;","}","vec4 ProcessChromaKey(vec4 rgba, vec2 uv)","{","\tfloat chromaDist = GetBoxFilteredChromaDist(rgba.rgb, uv);","\tfloat baseMask = chromaDist - similarity_v;","\tfloat fullMask = pow(clamp(baseMask / smoothness_v, 0.0, 1.0), 1.5);","\tfloat spillVal = pow(clamp(baseMask / spill_v, 0.0, 1.0), 1.5);","\trgba.a *= opacity;","\trgba.a *= fullMask;","\tfloat desat = dot(rgba.rgb, vec3(0.2126, 0.7152, 0.0722));","\trgba.rgb = mix(vec3(desat, desat, desat), rgba.rgb, spillVal);","\treturn CalcColor(rgba);","}","void main(void) {","\tvec4 rgba = texture2D(source, vTexCoord);","\n \tif (screen.w == 0.0) {\n \t\tgl_FragColor = rgba;\n \t\treturn;\n \t}\n ","\trgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;","\trgba = ProcessChromaKey(rgba, vTexCoord);","\trgba.rgb *= rgba.a;","#ifdef MASK","\tgl_FragColor = vec4(vec3(rgba.a), 1.0);","#else","\tgl_FragColor = rgba;","#endif","}"].join("\n"),t},inPlace:!0,inputs:{source:{type:"image",uniform:"source"},screen:{type:"color",uniform:"screen",defaultValue:[0,1,0,1]},similarity:{type:"number",uniform:"similarity",defaultValue:400,min:1,max:1e3},smoothness:{type:"number",uniform:"smoothness",defaultValue:80,min:1,max:1e3},opacity:{type:"number",uniform:"opacity",defaultValue:1,min:0,max:1},contrast:{type:"number",uniform:"contrast",defaultValue:0,min:-4,max:4},brightness:{type:"number",uniform:"brightness",defaultValue:0,min:-1,max:1},gamma:{type:"number",uniform:"gamma",defaultValue:0,min:-1,max:1},spill:{type:"number",uniform:"spill",defaultValue:100,min:1,max:1e3},mask:{type:"boolean",defaultValue:!1,uniform:"mask",shaderDirty:!0}},title:"Chroma Key OBS",description:""});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("./seriously.js");window,console.info("seriously version: chroma_post"),e.seriouslyExports.plugin("chroma_post",{shader:function(e,o){return o.vertex=["precision mediump float;","attribute vec4 position;","attribute vec2 texCoord;","uniform vec2 resolution;","uniform mat4 transform;","varying vec2 vTexCoord;","varying vec2 pixel_size;","void main(void) {","\tpixel_size.x = 1.0 / resolution.x;","\tpixel_size.y = 1.0 / resolution.y;","\tvec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);","\tscreenPosition = transform * screenPosition;","\tgl_Position = screenPosition;","\tgl_Position.xy = screenPosition.xy * 2.0 / resolution;","\tgl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);","\tvTexCoord = texCoord;","}"].join("\n"),o.fragment=[this.inputs.mask?"#define MASK":"","precision mediump float;","varying vec2 vTexCoord;","uniform bool mask;","uniform sampler2D source;","uniform float edgeShrink;","varying vec2 pixel_size;","const int filter_size = 3;","float edgeSmoothSuppKernelV2(vec4 rgba, vec2 coord) {"," float alpha = rgba.a;"," if (edgeShrink > 1.0) {"," float sum = 0.0;"," float weightSum = 0.0;"," // float sigma = 1.0f;"," for (int j = - filter_size / 2; j <= filter_size / 2; j++) {"," \t for (int i = - filter_size / 2; i <= filter_size / 2; i++) {"," \t\t // float weight = exp(-(i*i + j*j) / (2 * sigma * sigma)) / (2 * 3.1415926f * sigma * sigma);"," \t\t float weight = 1.0;"," vec4 neighborColor = texture2D(source, coord + vec2(i, j) * pixel_size);"," \t\t // speedup: move the powf to chroma_key"," \t\t float alpha_ker = pow(neighborColor.w, edgeShrink);"," \t\t sum += (alpha_ker * weight);"," \t\t weightSum += weight;"," \t }"," }"," alpha = sum * 1.0 / weightSum;"," }"," return alpha;","}","void main(void) {","\tvec4 rgba = texture2D(source, vTexCoord);","\trgba.a = edgeSmoothSuppKernelV2(rgba, vTexCoord);","\trgba.a = pow(rgba.a, edgeShrink);","#ifdef MASK","\tgl_FragColor = vec4(vec3(rgba.a), 1.0);","#else","\tgl_FragColor = rgba;","#endif","}"].join("\n"),o},inPlace:!0,inputs:{source:{type:"image",uniform:"source"},edgeShrink:{type:"number",uniform:"edgeShrink",defaultValue:3,min:1,max:10},mask:{type:"boolean",defaultValue:!1,uniform:"mask",shaderDirty:!0}},title:"Chroma Key Post",description:""});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var t,e,i,r=require("../../../../_virtual/_rollupPluginBabelHelpers.js"),n=require("../../../../_virtual/seriously.js");t=n.__module,e=window,i=function(t){var e,i,n,s,o,a,u,h,f=t.document,c=t.console,l={},d={},p={},m={},y=[],g={},v={},x={canvas:[],image:[],video:[]},E={},b=t.WeakMap&&new WeakMap,T=0,w=function(){},R={transparent:[0,0,0,0],black:[0,0,0,1],red:[1,0,0,1],green:[0,128/255,0,1],blue:[0,0,1,1],white:[1,1,1,1],silver:[192/255,192/255,192/255,1],gray:[128/255,128/255,128/255,1],maroon:[128/255,0,0,1],purple:[128/255,0,128/255,1],fuchsia:[1,0,1,1],lime:[0,1,0,1],olive:[128/255,128/255,0,1],yellow:[1,1,0,1],navy:[0,0,128/255,1],teal:[0,128/255,128/255,1],aqua:[0,1,1,1],orange:[1,165/255,0,1]},D=/^(rgb|hsl)a?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*(\d+(\.\d*)?)\s*)?\)/i,A=/^#(([0-9a-fA-F]{3,8}))/,_=["x","y","z","w"],N=["r","g","b","a"],P={srcRGB:770,dstRGB:771,srcAlpha:1,dstAlpha:771},F=["MAX_COMBINED_TEXTURE_IMAGE_UNITS","MAX_FRAGMENT_UNIFORM_VECTORS","MAX_TEXTURE_IMAGE_UNITS","MAX_VARYING_VECTORS","MAX_VERTEX_ATTRIBS","MAX_VERTEX_TEXTURE_IMAGE_UNITS","MAX_VERTEX_UNIFORM_VECTORS"],O=/^[\t ]*#define[\t ]+SHADER_NAME\s+([^$\n\r]+)/i,U={frustum:function(t,e,i,r,n,s,o){o||(o=U.create());var a=e-t,u=r-i,h=s-n;return o[0]=2*n/a,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2*n/u,o[6]=0,o[7]=0,o[8]=(e+t)/a,o[9]=(r+i)/u,o[10]=-(s+n)/h,o[11]=-1,o[12]=0,o[13]=0,o[14]=-s*n*2/h,o[15]=0,o},perspective:function(t,e,i,r,n){var s=i*Math.tan(t*Math.PI/360),o=s*e;return U.frustum(-o,o,-s,s,i,r,n)},multiply:function(t,e,i){var r=e[0],n=e[1],s=e[2],o=e[3],a=e[4],u=e[5],h=e[6],f=e[7],c=e[8],l=e[9],d=e[10],p=e[11],m=e[12],y=e[13],g=e[14],v=e[15],x=i[0],E=i[1],b=i[2],T=i[3];return t[0]=x*r+E*a+b*c+T*m,t[1]=x*n+E*u+b*l+T*y,t[2]=x*s+E*h+b*d+T*g,t[3]=x*o+E*f+b*p+T*v,x=i[4],E=i[5],b=i[6],T=i[7],t[4]=x*r+E*a+b*c+T*m,t[5]=x*n+E*u+b*l+T*y,t[6]=x*s+E*h+b*d+T*g,t[7]=x*o+E*f+b*p+T*v,x=i[8],E=i[9],b=i[10],T=i[11],t[8]=x*r+E*a+b*c+T*m,t[9]=x*n+E*u+b*l+T*y,t[10]=x*s+E*h+b*d+T*g,t[11]=x*o+E*f+b*p+T*v,x=i[12],E=i[13],b=i[14],T=i[15],t[12]=x*r+E*a+b*c+T*m,t[13]=x*n+E*u+b*l+T*y,t[14]=x*s+E*h+b*d+T*g,t[15]=x*o+E*f+b*p+T*v,t},identity:function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},copy:function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}},B=(h=0,t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||function(e){var i,r,n;function s(){e(i+r)}return i=(new Date).getTime(),r=Math.max(0,16-(i-h)),n=t.setTimeout(s,r),h=i+r,n}),L=t.cancelAnimationFrame||t.webkitCancelAnimationFrame||t.mozCancelAnimationFrame||t.oCancelAnimationFrame||t.msCancelAnimationFrame||function(e){t.cancelTimeout(e)},S=["alias","destroy","effect","id","initialize","inputs","isDestroyed","isReady","matte","off","on","readPixels","render","title","update"],I=["alias","destroy","id","inputs","isDestroyed","isReady","off","on","source","title","update"],C=["aliases","defaults","destroy","effect","go","id","incompatible","isDestroyed","isEffect","isNode","isSource","isTarget","isTransform","removeAlias","render","source","stop","target","transform"];function M(t,e){var i,r;if("string"==typeof t)i=f.querySelector(t);else if(!t)return!1;return t.tagName&&(i=t),i?(r=i.tagName.toLowerCase(),e&&e.indexOf(r)<0?t:i):t}function z(t,e){var i,r;for(i in t.prototype&&e.prototype&&t.prototype!==e.prototype&&z(t.prototype,e.prototype),e)e.hasOwnProperty(i)&&((r=Object.getOwnPropertyDescriptor(e,i)).get||r.set?Object.defineProperty(t,i,{configurable:!0,enumerable:!0,get:r.get,set:r.set}):t[i]=e[i]);return t}function G(t){var e;if(!c)return w;if("function"==typeof c[t])e=c[t];else{if("function"!=typeof c.log)return w;e=c.log}return e.bind?e.bind(c):function(){e.apply(c,arguments)}}function k(e,i){if(i||(i="HTMLElement"),!t[i])return c.error("window[proto] is undefined, proto:",i),!1;if(e instanceof t[i])return!0;if(!e||"object"!==r.typeof(e))return!1;for(;e;)if((e=Object.getPrototypeOf(e))&&e.constructor.name===i)return!0;return!1}function X(t,e,i,r,n){function s(t,e,i){return(i%=1)<0&&(i+=1),i<1/6?t+(e-t)*i*6:i<.5?e:i<2/3?t+(e-t)*(2/3-i)*6:t}var o,a;return o=2*i-(a=i<.5?i*(e+1):i+e-i*e),n||(n=[]),n[0]=s(o,a,t+1/3),n[1]=s(o,a,t),n[2]=s(o,a,t-1/3),n[3]=r,n}function j(t){var e,i,r,n="#",s=t[3]<1?4:3;for(e=0;e<s;e++)r=(i=Math.min(255,Math.round(255*t[e]||0))).toString(16),i<16&&(r="0"+r),n+=r;return n}function W(t){return Array.isArray(t)||t&&t.BYTES_PER_ELEMENT&&"length"in t}function V(e){function i(){y.length&&y.shift()()}if("function"!=typeof e)throw new Error("setTimeoutZero argument is not a function");y.push(e),"file:"!==t.location.protocol?t.postMessage("seriously-timeout-message",t.location):setTimeout(i,0)}function H(e,i){var r;try{r=t.WebGLDebugUtils&&i&&i.debugContext?t.WebGLDebugUtils.makeDebugContext(e.getContext("webgl",i)):e.getContext("webgl",i)}catch(t){}if(!r)try{r=e.getContext("experimental-webgl",i)}catch(t){}return r}function Y(){var i;return e&&e.getError()===e.CONTEXT_LOST_WEBGL&&(e=void 0),e||!t.WebGLRenderingContext||n||(i=f.createElement("canvas"),(e=H(i))?i.addEventListener("webglcontextlost",(function t(r){r.preventDefault(),e&&e.canvas===this&&(e=void 0,i.removeEventListener("webglcontextlost",t,!1))}),!1):J.logger.warn("Unable to access WebGL.")),e}function q(e){var i,r,n,s;if(!(i=M(e,["img","canvas","video"])))return!1;if(!(r=f.createElement("canvas")))return J.logger.warn("Browser does not support canvas or Seriously.js"),!1;if(0===i.naturalWidth&&"IMG"===i.tagName)return J.logger.warn("Image not loaded"),!1;if(0===i.readyState&&0===i.videoWidth&&"VIDEO"===i.tagName)return J.logger.warn("Video not loaded"),!1;if(n=Y()){(s=n.createTexture())||J.logger.error("Test WebGL context has been lost"),n.bindTexture(n.TEXTURE_2D,s);try{n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i)}catch(e){return e.code===t.DOMException.SECURITY_ERR?J.logger.log("Unable to access cross-domain image"):J.logger.error("Error storing image to texture: "+e.message),n.deleteTexture(s),!1}n.deleteTexture(s)}else{n=r.getContext("2d");try{n.drawImage(i,0,0),n.getImageData(0,0,1,1)}catch(e){return e.code===t.DOMException.SECURITY_ERR?J.logger.log("Unable to access cross-domain image"):J.logger.error("Error drawing image to canvas: "+e.message),!1}}return!0}function Z(t){var e,i,r;function n(t,r){var n,s;W(t)?(n=t[0],s=t[1]||n):n=t,"string"==typeof n?n=n.toLowerCase():"number"==typeof n?n=String(n):n||(n=""),i[n]=s,r||(e.firstValue=n)}function s(t){return t}for(r in t.inputs)if(t.inputs.hasOwnProperty(r)){if(t.reserved.indexOf(r)>=0||Object.prototype[r])throw new Error("Reserved input name: "+r);(e=t.inputs[r]).name=r,isNaN(e.min)&&(e.min=-1/0),isNaN(e.max)&&(e.max=1/0),isNaN(e.minCount)&&(e.minCount=-1/0),isNaN(e.maxCount)&&(e.maxCount=1/0),isNaN(e.step)&&(e.step=0),isNaN(e.mod)&&(e.mod=0),"enum"===e.type&&e.options&&W(e.options)&&e.options.length&&(i={},e.options.forEach(n),e.options=i),"vector"===e.type?e.dimensions<2?e.dimensions=2:e.dimensions>4||!e.dimensions||isNaN(e.dimensions)?e.dimensions=4:e.dimensions=Math.round(e.dimensions):e.dimensions=1,e.shaderDirty=!!e.shaderDirty,"function"!=typeof e.validate&&(e.validate=J.inputValidators[e.type]||s),t.defaultImageInput||"image"!==e.type||(t.defaultImageInput=r)}}function K(t,e,i,r){var n,s,o,a,u=!0===r?r:r&&r.useFloat;u=!1,this.type=u?t.FLOAT:t.UNSIGNED_BYTE,n=t.createFramebuffer(),t.bindFramebuffer(t.FRAMEBUFFER,n),r&&r.texture?(this.texture=r.texture,t.bindTexture(t.TEXTURE_2D,this.texture),this.ownTexture=!1):(this.texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.texture),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),this.ownTexture=!0);try{this.type===t.FLOAT?(o=new Float32Array(e*i*4),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.FLOAT,o)):(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.UNSIGNED_BYTE,null),this.type=t.UNSIGNED_BYTE)}catch(r){this.type=t.UNSIGNED_BYTE,o=new Uint8Array(e*i*4),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.UNSIGNED_BYTE,o)}if(s=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,s),t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_COMPONENT16,e,i),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,s),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.texture,0),(a=t.checkFramebufferStatus(t.FRAMEBUFFER))===t.FRAMEBUFFER_INCOMPLETE_ATTACHMENT)throw new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");if(a===t.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)throw new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");if(a===t.FRAMEBUFFER_INCOMPLETE_DIMENSIONS)throw new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");if(a===t.FRAMEBUFFER_UNSUPPORTED)throw new Error("Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED");if(a!==t.FRAMEBUFFER_COMPLETE)throw new Error("Incomplete framebuffer: "+a);t.bindTexture(t.TEXTURE_2D,null),t.bindRenderbuffer(t.RENDERBUFFER,null),t.bindFramebuffer(t.FRAMEBUFFER,null),this.gl=t,this.frameBuffer=n,this.renderBuffer=s,this.width=e,this.height=i}function $(t,e,i){var r,n,s,o,a,u,h,f,c="";function l(e,i){var r,n;if(r=i?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER),t.shaderSource(r,e),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS)){for(e=e.split(/[\n\r]/),n=0;n<e.length;n++)e[n]=n+1+":\t"+e[n];throw e.unshift("Error compiling "+(i?"fragment":"vertex")+" shader:"),J.logger.error(e.join("\n")),new Error("Shader error: "+t.getShaderInfoLog(r))}return r}function d(e,i){if(e.type===t.SAMPLER_2D)return function(r){e.glTexture=t["TEXTURE"+r],t.uniform1i(i,r)};if(e.type===t.BOOL||e.type===t.INT)return e.size>1?function(e){t.uniform1iv(i,e)}:function(e){t.uniform1i(i,e)};if(e.type===t.FLOAT)return e.size>1?function(e){t.uniform1fv(i,e)}:function(e){t.uniform1f(i,e)};if(e.type===t.FLOAT_VEC2)return function(e){t.uniform2f(i,e[0],e[1])};if(e.type===t.FLOAT_VEC3)return function(e){t.uniform3f(i,e[0],e[1],e[2])};if(e.type===t.FLOAT_VEC4)return function(e){t.uniform4f(i,e[0],e[1],e[2],e[3])};if(e.type===t.FLOAT_MAT3)return function(e){t.uniformMatrix3fv(i,!1,e)};if(e.type===t.FLOAT_MAT4)return function(e){t.uniformMatrix4fv(i,!1,e)};throw new Error("Unknown shader uniform type: "+e.type)}function p(e){return function(){return t.getUniform(r,e)}}if(n=l(e),s=l(i,!0),r=t.createProgram(),t.attachShader(r,n),(o=t.getShaderInfoLog(n))&&(c+="Vertex shader error: "+o+"\n"),t.attachShader(r,s),(o=t.getShaderInfoLog(s))&&(c+="Fragment shader error: "+o+"\n"),t.linkProgram(r),!t.getProgramParameter(r,t.LINK_STATUS))throw c+=t.getProgramInfoLog(r),t.deleteProgram(r),t.deleteShader(n),t.deleteShader(s),(h=O.exec(e)||O.exec(i))&&(c="Shader = "+h[1]+"\n"+c),F.forEach((function(e){c+="\n"+e+": "+t.getParameter(t[e])})),new Error("Could not initialize shader:\n"+c);for(t.useProgram(r),this.uniforms={},u=t.getProgramParameter(r,t.ACTIVE_UNIFORMS),a=0;a<u;++a)(f={info:t.getActiveUniform(r,a)}).name=f.info.name.replace(/\[0\]$/,""),f.loc=t.getUniformLocation(r,f.name),f.set=d(f.info,f.loc),f.get=p(f.loc),this.uniforms[f.name]=f,this[f.name]||(this[f.name]=f);for(this.attributes={},this.location={},u=t.getProgramParameter(r,t.ACTIVE_ATTRIBUTES),a=0;a<u;++a)(f={info:t.getActiveAttrib(r,a)}).name=f.info.name,f.location=t.getAttribLocation(r,f.name),this.attributes[f.name]=f,this.location[f.name]=f.location;this.gl=t,this.program=r,this.destroy=function(){var e;for(e in t&&(t.deleteProgram(r),t.deleteShader(n),t.deleteShader(s)),this)this.hasOwnProperty(e)&&delete this[e];r=null,n=null,s=null}}function J(e){if(t===this||!(this instanceof J)||void 0!==this.id)return new J(e);var i,n,o,h,c,y,E,R,D,A,_,N,F,S,I,G=++T,X=this,W=[],Y={},q=0,Q=[],tt=[],et=[],it=[],rt={},nt=[],st=[],ot={},at={},ut=!1,ht=!1,ft=null;function ct(t,e){var i,r,n;return!!e&&(i=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,i),e.bufferData(e.ARRAY_BUFFER,t.vertices,e.STATIC_DRAW),i.size=3,r=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,r),e.bufferData(e.ELEMENT_ARRAY_BUFFER,t.indices,e.STATIC_DRAW),n=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,n),e.bufferData(e.ARRAY_BUFFER,t.coords,e.STATIC_DRAW),n.size=2,{vertex:i,index:r,texCoord:n,length:t.indices.length,mode:t.mode||e.TRIANGLES})}function lt(t){var e={};return e.vertices=new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,1,0]),e.indices=new Uint16Array([0,1,2,0,2,3]),e.coords=new Float32Array([0,0,1,0,1,1,0,1]),ct(e,t)}function dt(){J.logger.warn("WebGL context lost. 5 seconds to restore context."),ft&&clearTimeout(ft),ft=setTimeout(mt,5e3)}function pt(t){var e,r;if(!n)if(t.canvas.addEventListener("webglcontextlost",yt,!1),t.canvas.addEventListener("webglcontextrestored",mt,!1),t.isContextLost())J.logger.warn("Unable to attach lost WebGL context. Will try again when context is restored.");else{for(n=t,i=t.canvas,h=lt(n),c=new $(n,"#define SHADER_NAME seriously.base\n"+a,"#define SHADER_NAME seriously.base\n"+u),e=0;e<it.length;e++)(r=it[e]).gl=n,r.initialize(),r.buildShader();for(e=0;e<Q.length;e++)(r=Q[e]).initialize();for(e=0;e<tt.length;e++)(r=tt[e]).model||(r.model=h,r.shader=c)}}function mt(){var t,e,i,r;if(ft&&clearTimeout(ft),ft=null,o&&!n){if(k(e=o.target,"WebGLFramebuffer"))return void J.logger.error("Unable to restore target built on WebGLFramebuffer");if(t=H(e,{alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!0,stencil:!0,debugContext:o.debugContext})){if(t.isContextLost())return ft?void J.logger.error("restore WebGL Context ing, wait...."):(dt(),void J.logger.error("Unable to restore WebGL Context"));for(pt(t),o.renderToTexture?o.frameBuffer=new K(n,o.width,o.height,!1):o.frameBuffer={frameBuffer:null},i=0;i<W.length;i++)(r=W[i]).setDirty(),r.emit("webglcontextrestored");J.logger.log("WebGL context restored")}}}function yt(t){var e,r;for(t?(t.preventDefault(),dt()):ft&&clearTimeout(ft),I&&(L(I),I=0),i&&i.removeEventListener("webglcontextlost",yt,!1),e=0;e<it.length;e++)(r=it[e]).gl=null,r.initialized=!1,r.baseShader=null,r.model=null,r.frameBuffer=null,r.texture=null,r.shader&&r.shader.destroy&&(r.shader.destroy(),r.effect.commonShader&&delete at[r.hook]),r.shaderDirty=!0,r.shader=null,r.effect.lostContext&&r.effect.lostContext.call(r),t&&r.emit("webglcontextlost");for(e=0;e<Q.length;e++)(r=Q[e]).texture=null,r.initialized=!1,r.allowRefresh=!1,t&&r.emit("webglcontextlost");for(e=0;e<et.length;e++)(r=et[e]).frameBuffer=null,r.texture=null,t&&r.emit("webglcontextlost");for(e=0;e<tt.length;e++)(r=tt[e]).model=!1,r.frameBuffer=null,t&&r.emit("webglcontextlost");c&&c.destroy&&c.destroy(),n&&(n.deleteBuffer(h.vertex),n.deleteBuffer(h.texCoord),n.deleteBuffer(h.index)),h&&(delete h.vertex,delete h.texCoord,delete h.index),h=null,c=null,n=null,i=null}function gt(t){var e,i,r=!1;if(I=0,nt.length)for(r=!0,e=0;e<nt.length;e++)nt[e].call(X,t);if(Q&&Q.length)for(r=!0,e=0;e<Q.length;e++){var n=(i=Q[e]).source&&i.source.dataset&&i.source.dataset.playing;if("string"==typeof n&&"true"!==n)return void(I=B(gt));(i.dirty||i.checkDirty&&i.checkDirty())&&(i.dirty=!1,i.setDirty())}for(e=0;e<tt.length;e++)(i=tt[e]).auto&&i.dirty&&i.render();if(st.length)for(r=!0,e=0;e<st.length;e++)st[e].call(X);r&&!I&&(I=B(gt))}function vt(t,e,i,r,s,o){var a,u,h,f,c,l,d,p,m,y=0,g=s&&s.gl||n;if(g){for(a in s?(f=o&&o.width||s.width||g.canvas.width,c=o&&o.height||s.height||g.canvas.height):(f=o&&o.width||g.canvas.width,c=o&&o.height||g.canvas.height),t.use(),g.viewport(0,0,f,c),g.bindFramebuffer(g.FRAMEBUFFER,r),g.enableVertexAttribArray(t.location.position),g.enableVertexAttribArray(t.location.texCoord),e.texCoord&&(g.bindBuffer(g.ARRAY_BUFFER,e.texCoord),g.vertexAttribPointer(t.location.texCoord,e.texCoord.size,g.FLOAT,!1,0,0)),g.bindBuffer(g.ARRAY_BUFFER,e.vertex),g.vertexAttribPointer(t.location.position,e.vertex.size,g.FLOAT,!1,0,0),g.bindBuffer(g.ELEMENT_ARRAY_BUFFER,e.index),o&&o.depth?n.enable(n.DEPTH_TEST):n.disable(n.DEPTH_TEST),o?void 0===o.blend||o.blend?(n.enable(n.BLEND),l=void 0===o.srcRGB?n.ONE:o.srcRGB,p=o.dstRGB||n.ZERO,d=void 0===o.srcAlpha?l:o.srcAlpha,m=void 0===o.dstAlpha?p:o.dstAlpha,n.blendFuncSeparate(l,p,d,m),n.blendEquation(o.blendEquation||n.FUNC_ADD)):n.disable(n.BLEND):(n.enable(n.BLEND),n.blendFunc(n.ONE,n.ZERO),n.blendEquation(n.FUNC_ADD)),i)i.hasOwnProperty(a)&&(u=i[a],(h=t.uniforms[a])&&(k(u,"WebGLTexture")?(g.activeTexture(g.TEXTURE0+y),g.bindTexture(g.TEXTURE_2D,u),h.set(y),y++):u instanceof E||u instanceof R||u instanceof D?u.texture&&(g.activeTexture(g.TEXTURE0+y),g.bindTexture(g.TEXTURE_2D,u.texture),h.set(y),y++):null!=u&&h.set(u)));o&&void 0!==o.clear&&!o.clear||(g.clearColor(0,0,0,0),g.clear(g.COLOR_BUFFER_BIT|g.DEPTH_BUFFER_BIT)),g.drawElements(e.mode,e.length,g.UNSIGNED_SHORT,0),n.enable(n.DEPTH_TEST)}}function xt(t,e,i){var n,s;if(("string"!=typeof t||!e&&0!==e)&&(i&&"object"===r.typeof(i)||(i=e),e=t),"string"==typeof t&&p[t]||(t=null),e instanceof E||e instanceof R||e instanceof D)n=e;else if(e instanceof _||e instanceof N||e instanceof F){if(!(n=Y[e.id]))throw new Error("Cannot connect a foreign node")}else{for("string"==typeof e&&isNaN(e)&&(e=M(e,["canvas","img","video"])),s=0;s<Q.length;s++)if(n=Q[s],(!t||t===n.hook)&&n.compare&&n.compare(e,i))return n;n=new E(t,e,i)}return n}function Et(t,e){var i,r,n;if(!(t instanceof R||t instanceof D))return!1;if(t===e)return!0;for(i in n=t.sources)if(n.hasOwnProperty(i)&&((r=n[i])===e||Et(r,e)))return!0;return!1}(y=function(){this.ready=!1,this.width=1,this.height=1,this.gl=n,this.uniforms={resolution:[this.width,this.height],transform:null},this.dirty=!0,this.isDestroyed=!1,this.seriously=X,this.listeners={},this.id=q,q++}).prototype.setReady=function(){var t;if(!this.ready&&(this.ready=!0,this.emit("ready"),this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setReady()},y.prototype.setUnready=function(){var t;if(this.ready&&(this.ready=!1,this.emit("unready"),this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setUnready()},y.prototype.setDirty=function(){var t;if(!this.dirty&&(this.emit("dirty"),this.dirty=!0,this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setDirty()},y.prototype.initFrameBuffer=function(t){n&&(this.frameBuffer=new K(n,this.width,this.height,t))},y.prototype.readPixels=function(t,e,i,r,s){var o=this.gl||n;if(!n)throw new Error("Cannot read pixels until a canvas is connected");if(this.frameBuffer||(this.initFrameBuffer(),this.setDirty()),this.render(),void 0===s)s=new Uint8Array(i*r*4);else if(!k(s,"Uint8Array"))throw new Error("Incompatible array type");return o.bindFramebuffer(n.FRAMEBUFFER,this.frameBuffer.frameBuffer),o.readPixels(t,e,i,r,n.RGBA,n.UNSIGNED_BYTE,s),s},y.prototype.resize=function(){var t,e;this.source?(t=this.source.width,e=this.source.height):this.sources&&this.sources.source?(t=this.sources.source.width,e=this.sources.source.height):this.inputs&&this.inputs.width?(t=this.inputs.width,e=this.inputs.height||t):this.inputs&&this.inputs.height?t=e=this.inputs.height:(t=1,e=1),t=Math.floor(t),e=Math.floor(e),this.width===t&&this.height===e||(this.width=t,this.height=e,this.emit("resize"),this.setDirty()),this.uniforms&&this.uniforms.resolution&&(this.uniforms.resolution[0]=t,this.uniforms.resolution[1]=e),this.frameBuffer&&this.frameBuffer.resize&&this.frameBuffer.resize(t,e)},y.prototype.on=function(t,e){var i,r=-1;t&&"function"==typeof e&&((i=this.listeners[t])?r=i.indexOf(e):i=this.listeners[t]=[],r<0&&i.push(e))},y.prototype.off=function(t,e){var i,r=-1;t&&"function"==typeof e&&(i=this.listeners[t])&&(r=i.indexOf(e))>=0&&i.splice(r,1)},y.prototype.emit=function(t){var e,i=this.listeners[t];if(i&&i.length)for(e=0;e<i.length;e++)V(i[e])},y.prototype.destroy=function(){var t,e;for(e in delete this.gl,delete this.seriously,this.listeners)this.listeners.hasOwnProperty(e)&&delete this.listeners[e];for(t in this.uniforms)this.uniforms.hasOwnProperty(t)&&delete this.uniforms[t];this.targets&&delete this.targets,this.frameBuffer&&this.frameBuffer.destroy&&(this.frameBuffer.destroy(),delete this.frameBuffer),(t=W.indexOf(this))>=0&&W.splice(t,1),delete Y[this.id],this.isDestroyed=!0},_=function(t){var e,i=t;function r(t,e){var r,n,s;return s=i.effect.inputs[t],r=i.inputElements[t],"string"==typeof e&&isNaN(e)&&("enum"===s.type?s.options.hasOwnProperty(e)||(e=M(e,["select"])):"number"===s.type||"boolean"===s.type?e=M(e,["input","select"]):"image"===s.type&&(e=M(e,["canvas","img","video"]))),k(e,"HTMLInputElement")||k(e,"HTMLSelectElement")?(n=e.value,r&&r.element!==e&&(r.element.removeEventListener("change",r.listener,!0),r.element.removeEventListener("input",r.listener,!0),delete i.inputElements[t],r=null),r||(r={element:e,listener:function(t,r){return function(){var n,o;n="checkbox"===e.type?e.checked:r.value,o=i.setInput(t,n),"color"===s.type&&(o=j(o).substr(0,7)),o!==n&&(r.value=o)}}(t,e)},i.inputElements[t]=r,"range"===e.type?(e.addEventListener("input",r.listener,!0),e.addEventListener("change",r.listener,!0)):e.addEventListener("change",r.listener,!0)),r&&"checkbox"===e.type&&(n=e.checked)):(r&&(r.element.removeEventListener("change",r.listener,!0),r.element.removeEventListener("input",r.listener,!0),delete i.inputElements[t]),n=e),i.setInput(t,n),i.inputs[t]}function n(t){return function(e){var i=r(t,e);return i&&i.pub}}function s(t){return function(){var e=i.inputs[t];return e&&e.pub}}function o(t){return function(e){return r(t,e)}}function a(t){return function(){return i.inputs[t]}}for(e in i.effect.inputs)if(i.effect.inputs.hasOwnProperty(e)){if(void 0!==this[e])throw new Error("Cannot overwrite Seriously."+e);"image"===i.effect.inputs[e].type?Object.defineProperty(this,e,{configurable:!0,enumerable:!0,get:s(e),set:n(e)}):Object.defineProperty(this,e,{configurable:!0,enumerable:!0,get:a(e),set:o(e)})}Object.defineProperties(this,{effect:{enumerable:!0,configurable:!0,get:function(){return i.hook}},title:{enumerable:!0,configurable:!0,get:function(){return i.effect.title||i.hook}},width:{enumerable:!0,configurable:!0,get:function(){return i.width}},height:{enumerable:!0,configurable:!0,get:function(){return i.height}},id:{enumerable:!0,configurable:!0,get:function(){return i.id}}}),this.render=function(){return i.render(),this},this.readPixels=function(t,e,r,n,s){return i.readPixels(t,e,r,n,s)},this.on=function(t,e){i.on(t,e)},this.off=function(t,e){i.off(t,e)},this.inputs=function(t){var e,r,n,s;if(n=i.effect.inputs,t)return(r=n[t])?(e={type:r.type,defaultValue:r.defaultValue,title:r.title||t},"number"===r.type?(e.min=r.min,e.max=r.max,e.step=r.step,e.mod=r.mod):"enum"===r.type?e.options=z({},r.options):"vector"===r.type&&(e.dimensions=r.dimensions),r.description&&(e.description=r.description),e):null;for(s in e={},n)n.hasOwnProperty(s)&&(e[s]=this.inputs(s));return e},this.alias=function(t,e){return i.alias(t,e),this},this.matte=function(t){i.matte(t)},this.destroy=function(){var t,e;for(t in i.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((e=Object.getOwnPropertyDescriptor(this,t)).get||e.set||"function"!=typeof this[t]?delete this[t]:this[t]=w)},this.isDestroyed=function(){return i.isDestroyed},this.isReady=function(){return i.ready}},R=function(t,e){var i,r,o,a,u={};for(i in y.call(this,e),this.gl=n,this.effectRef=l[t],this.sources={},this.targets=[],this.inputElements={},this.dirty=!0,this.shaderDirty=!0,this.hook=t,this.options=e,this.transform=null,this.effect=z({},this.effectRef),this.effectRef.definition&&z(this.effect,this.effectRef.definition.call(this,e)),Z(this.effect),this.uniforms.transform=s,this.inputs={},a=ot[t],this.effect.inputs)this.effect.inputs.hasOwnProperty(i)&&(void 0!==(r=this.effect.inputs[i]).defaultValue&&null!==r.defaultValue||("number"===r.type?r.defaultValue=Math.min(Math.max(0,r.min),r.max):"color"===r.type?r.defaultValue=[0,0,0,0]:"boolean"===r.type?r.defaultValue=!1:"string"===r.type?r.defaultValue="":"enum"===r.type&&(r.defaultValue=r.firstValue)),o=r.validate.call(this,r.defaultValue,r),a&&void 0!==a[i]&&(o=r.validate.call(this,a[i],r,r.defaultValue,o),a[i]=o,"image"===r.type&&(u[i]=o)),this.inputs[i]=o,r.uniform&&(this.uniforms[r.uniform]=r.defaultValue));for(i in n&&(this.initialize(),this.effect.commonShader&&this.buildShader()),this.updateReady(),this.inPlace=this.effect.inPlace,this.pub=new _(this),W.push(this),Y[this.id]=this,it.push(this),g[t].push(this),u)u.hasOwnProperty(i)&&this.setInput(i,u[i])},R.prototype=Object.create(y.prototype),R.prototype.constructor=R,R.prototype.initialize=function(){if(!this.initialized){var t=this;this.baseShader=c,this.shape?this.model=ct(this.shape,this.gl):this.model=h,"function"==typeof this.effect.initialize?this.effect.initialize.call(this,(function(){t.initFrameBuffer(!0)}),n):this.initFrameBuffer(!0),this.frameBuffer&&(this.texture=this.frameBuffer.texture),this.initialized=!0}},R.prototype.resize=function(){var t;for(y.prototype.resize.call(this),this.effect.resize&&this.effect.resize.call(this),t=0;t<this.targets.length;t++)this.targets[t].resize()},R.prototype.updateReady=function(){var t,e,i,r,n=!0;for(e in(i=this.effect).inputs)if(i.inputs.hasOwnProperty(e)&&"image"===this.effect.inputs[e].type&&(!this.sources[e]||!this.sources[e].ready)&&(!i.requires||i.requires.call(this,e,this.inputs))){n=!1;break}if(this.ready!==n&&(this.ready=n,this.emit(n?"ready":"unready"),r=n?"setReady":"setUnready",this.targets))for(t=0;t<this.targets.length;t++)this.targets[t][r]()},R.prototype.setReady=R.prototype.updateReady,R.prototype.setUnready=R.prototype.updateReady,R.prototype.addTarget=function(t){var e;for(e=0;e<this.targets.length;e++)if(this.targets[e]===t)return;this.targets.push(t)},R.prototype.removeTarget=function(t){var e=this.targets&&this.targets.indexOf(t);e>=0&&this.targets.splice(e,1)},R.prototype.removeSource=function(t){var e,i=t&&t.pub;for(e in this.inputs)!this.inputs.hasOwnProperty(e)||this.inputs[e]!==t&&this.inputs[e]!==i||(this.inputs[e]=null);for(e in this.sources)!this.sources.hasOwnProperty(e)||this.sources[e]!==t&&this.sources[e]!==i||(this.sources[e]=null)},R.prototype.buildShader=function(){var t,e=this.effect,i=this;function r(t){return O.test(t)?t:"#define SHADER_NAME seriously."+i.hook+"\n"+t}this.shaderDirty&&(e.commonShader&&at[this.hook]?(this.shader||at[this.hook].count++,this.shader=at[this.hook].shader):e.shader?(this.shader&&!e.commonShader&&this.shader.destroy(),(t=e.shader.call(this,this.inputs,{vertex:a,fragment:u},J.util))instanceof $?this.shader=t:t&&t.vertex&&t.fragment?this.shader=new $(n,r(t.vertex),r(t.fragment)):this.shader=c,e.commonShader&&(at[this.hook]={count:1,shader:this.shader})):this.shader=c,this.shaderDirty=!1)},R.prototype.render=function(){var t,e,i,r=this.effect,s=this;function o(t,e,i,r,n,o){vt(t,e,i,r,n||s,o)}if(n){if(this.initialized||this.initialize(),this.shaderDirty&&this.buildShader(),this.dirty&&this.ready){for(t in this.sources)!this.sources.hasOwnProperty(t)||r.requires&&!r.requires.call(this,t,this.inputs)||(i="function"==typeof this.inPlace?this.inPlace(t):this.inPlace,this.sources[t].render(!i));this.frameBuffer&&(e=this.frameBuffer.frameBuffer),"function"==typeof r.draw?(r.draw.call(this,this.shader,this.model,this.uniforms,e,o),this.emit("render")):e&&(vt(this.shader,this.model,this.uniforms,e,this),this.emit("render")),this.dirty=!1}return this.texture}},R.prototype.setInput=function(t,e){var i,r,n,o,a,u=this;function h(){var e,i=u.sources[t];if(i){for(e in u.sources)if(e!==t&&u.sources.hasOwnProperty(e)&&u.sources[e]===i)return;i.removeTarget(u)}}if(this.effect.inputs.hasOwnProperty(t)){if("image"===(i=this.effect.inputs[t]).type){if(e){if((e=xt(e))!==this.sources[t]){if(h(),Et(e,this))throw new Error("Attempt to make cyclical connection.");this.sources[t]=e,e.addTarget(this)}}else delete this.sources[t],e=!1;r=this.sources[t],n=Object.keys(this.sources),!0===this.inPlace&&1===n.length?(o=this.sources[n[0]],this.uniforms.transform=o&&o.cumulativeMatrix||s):this.uniforms.transform=s}else a=ot[this.hook]&&void 0!==ot[this.hook][t]?ot[this.hook][t]:i.defaultValue,r=e=i.validate.call(this,e,i,a,this.inputs[t]);return this.inputs[t]===e&&"color"!==i.type&&"vector"!==i.type||(this.inputs[t]=e,i.uniform&&(this.uniforms[i.uniform]=r),"image"===i.type?(this.resize(),this.updateReady()):i.updateSources&&this.updateReady(),i.shaderDirty&&(this.shaderDirty=!0),this.setDirty(),i.update&&i.update.call(this,e)),e}},R.prototype.alias=function(t,e){var i=this;if(C.indexOf(e)>=0)throw new Error("'"+e+"' is a reserved name and cannot be used as an alias.");return this.effect.inputs.hasOwnProperty(t)&&(e||(e=t),X.removeAlias(e),rt[e]={node:this,input:t},Object.defineProperty(X,e,{configurable:!0,enumerable:!0,get:function(){return i.inputs[t]},set:function(e){return i.setInput(t,e)}})),this},R.prototype.matte=function(t){var e,i,n,s,o,a,u,h=[],f=[],c={};function l(t){return t&&t.length&&Array.isArray(t)?Array.isArray(t[0])?Array.isArray(t[0])&&!isNaN(t[0][0])?[t]:t:[t]:[]}function d(t,e,i,r){var n,s,o,a,u;return n=(r.x-i.x)*(t.y-i.y)-(r.y-i.y)*(t.x-i.x),s=(e.x-t.x)*(t.y-i.y)-(e.y-t.y)*(t.x-i.x),!!((o=(r.y-i.y)*(e.x-t.x)-(r.x-i.x)*(e.y-t.y))&&(u=s/o,(a=n/o)>0&&a<=1&&u>0&&u<=1))&&{x:t.x+a*(e.x-t.x),y:t.y+a*(e.y-t.y)}}function p(t){var e,i,r,n,s,o,a,u,c,l,p,m=[];if(!t.simple){for(e=0;e<t.edges.length;e++)for(r=t.edges[e],i=e+1;i<t.edges.length;i++)n=t.edges[i],(s=d(r[0],r[1],n[0],n[1]))&&(s.edge1=r,s.edge2=n,m.push(s));if(m.length){for(c=[],e=0;e<m.length;e++)r=(s=m[e]).edge1,n=s.edge2,l={x:s.x,y:s.y,prev:r[0],next:n[1],id:f.length},t.vertices.push(l),f.push(l),p={x:s.x,y:s.y,prev:n[0],next:r[1],id:f.length},t.vertices.push(p),f.push(l),l.prev.next=l,l.next.prev=l,p.prev.next=p,p.next.prev=p;do{o={edges:[],vertices:[],simple:!0},c.push(o),a=u=t.vertices[0];do{e=t.vertices.indexOf(u),t.vertices.splice(e,1),o.edges.push([u,u.next]),o.vertices.push(u),u=u.next}while(u!==a)}while(t.vertices.length);for(e=h.indexOf(t),h.splice(e,1),e=0;e<c.length;e++)h.push(c[e])}else t.simple=!0}}function m(t){var e,i,r,n,s=t.vertices.length,o=0;for(e=s-1,i=0;i<s;e=i,i++)r=t.vertices[e],n=t.vertices[i],o+=r.x*n.y-n.x*r.y;return o>0}function y(t){var e,r,n,s,o,a,u,h,f,c,l,d=t.vertices,p=[],m=[];function y(t,e,i,r){var n,s,o,a,u,h,f,c,l,d,p,m;return n=i.x-e.x,s=i.y-e.y,o=t.x-i.x,a=t.y-i.y,u=e.x-t.x,h=e.y-t.y,f=r.x-t.x,c=r.y-t.y,l=r.x-e.x,d=r.y-e.y,p=r.x-i.x,m=r.y-i.y,n*d-s*l>=0&&o*m-a*p>=0&&u*c-h*f>=0}function g(t,e,i,r,n){var s,o,a,u;if(o=d[n[t]],a=d[n[e]],u=d[n[i]],0>(a.x-o.x)*(u.y-o.y)-(a.y-o.y)*(u.x-o.x))return!1;for(s=0;s<r;s++)if(s!==t&&s!==e&&s!==i&&y(o,a,u,d[n[s]]))return!1;return!0}if(r=d.length,t.clockWise)for(e=0;e<r;e++)p[e]=e;else for(e=0;e<r;e++)p[e]=r-1-e;for(s=2*(n=r),e=n-1;n>2;){if(s--<=0)return m;if(n<=(o=e)&&(o=0),n<=(e=o+1)&&(e=0),n<(a=e+1)&&(a=0),g(o,e,a,n,p)){for(u=p[o],h=p[e],f=p[a],t.clockWise?(m.push(d[u]),m.push(d[h]),m.push(d[f])):(m.push(d[f]),m.push(d[h]),m.push(d[u])),c=e,l=e+1;l<n;c++,l++)p[c]=p[l];s=2*--n}}i.indices=m}for(e=l(t),n=0;n<e.length;n++){for(t=e[n],u=null,i={vertices:[],edges:[]},s=0;s<t.length;s++)o=t[s],"object"!==r.typeof(o)||isNaN(o.x)||isNaN(o.y)?o.length>=2&&!isNaN(o[0])&&!isNaN(o[1])&&(a={x:o[0],y:o[1],id:f.length}):a={x:o.x,y:o.y,id:f.length},a&&(u?(u.next=a,a.prev=u,a.next=i.vertices[0],i.vertices[0].prev=a):(i.head=a,a.next=a,a.prev=a),f.push(a),i.vertices.push(a),u=a);if(i.vertices.length>2)for(3===i.vertices.length&&(i.simple=!0),h.push(i),s=0;s<i.vertices.length;s++)a=i.vertices[s],i.edges.push([a,a.next])}for(n=h.length-1;n>=0;n--)p(i=h[n]);for(n=0;n<h.length;n++)(i=h[n]).clockWise=m(i),y(i);for(c.vertices=[],c.coords=[],n=0;n<f.length;n++)o=f[n],c.vertices.push(2*o.x-1),c.vertices.push(-2*o.y+1),c.vertices.push(-1),c.coords.push(o.x),c.coords.push(-1*o.y+1);for(c.vertices=new Float32Array(c.vertices),c.coords=new Float32Array(c.coords),c.indices=[],n=0;n<h.length;n++)for(i=h[n],s=0;s<i.indices.length;s++)o=i.indices[s],c.indices.push(o.id);c.indices=new Uint16Array(c.indices),this.shape=c,this.gl&&ct(c,this.gl)},R.prototype.destroy=function(){var t,e,i,r=this.hook;for(e in this.effect.destroy&&"function"==typeof this.effect.destroy&&this.effect.destroy.call(this),delete this.effect,at[r]&&(at[r].count--,at[r].count||delete at[r]),this.shader&&this.shader.destroy&&this.shader!==c&&!at[r]&&this.shader.destroy(),delete this.shader,this.inputElements)this.inputElements.hasOwnProperty(e)&&((i=this.inputElements[e]).element.removeEventListener("change",i.listener,!0),i.element.removeEventListener("input",i.listener,!0));for(e in this.sources)this.sources.hasOwnProperty(e)&&((i=this.sources[e])&&i.removeTarget&&i.removeTarget(this),delete this.sources[e]);for(;this.targets.length;)(i=this.targets.pop())&&i.removeSource&&i.removeSource(this);for(e in this)this.hasOwnProperty(e)&&"id"!==e&&delete this[e];for(e in rt)rt.hasOwnProperty(e)&&(i=rt[e]).node===this&&X.removeAlias(e);(t=it.indexOf(this))>=0&&it.splice(t,1),(t=g[r].indexOf(this))>=0&&g[r].splice(t,1),y.prototype.destroy.call(this)},N=function(t){var e=t;Object.defineProperties(this,{original:{enumerable:!0,configurable:!0,get:function(){return e.source}},id:{enumerable:!0,configurable:!0,get:function(){return e.id}},width:{enumerable:!0,configurable:!0,get:function(){return e.width}},height:{enumerable:!0,configurable:!0,get:function(){return e.height}}}),this.render=function(){e.render()},this.update=function(){e.setDirty()},this.readPixels=function(t,i,r,n,s){return e.readPixels(t,i,r,n,s)},this.on=function(t,i){e.on(t,i)},this.off=function(t,i){e.off(t,i)},this.destroy=function(){var t,i;for(t in e.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((i=Object.getOwnPropertyDescriptor(this,t)).get||i.set||"function"!=typeof this[t]?delete this[t]:this[t]=w)},this.isDestroyed=function(){return e.isDestroyed},this.isReady=function(){return e.ready}},E=function(t,e,i){var s,o,a=i||{},u=void 0===a.flip||a.flip,h=a.width,f=a.height,c=!1,l=this,d=!1;function m(t,e,i,r){var n=p[t];if(n.definition){if(!(n=n.definition.call(l,e,i,r)))return null;n=z(z({},p[t]),n)}return n}function g(t){return l.source===t}if(y.call(this),(t&&"string"!=typeof t||!e&&0!==e)&&(i&&"object"===r.typeof(i)||(i=e),e=t),"string"==typeof e&&isNaN(e)&&(e=M(e,["canvas","img","video"])),"string"==typeof t&&p[t]&&(o=m(t,e,i,!0))&&(this.hook=t,d=!0,c=o.deferTexture,this.plugin=o,this.compare=o.compare,this.checkDirty=o.checkDirty,o.source&&(e=o.source)),!o&&k(e))"CANVAS"===e.tagName?(this.width=e.width,this.height=e.height,this.render=this.renderImageCanvas,d=!0,this.hook="canvas",this.compare=g):"IMG"===e.tagName&&(this.width=e.naturalWidth||1,this.height=e.naturalHeight||1,e.complete&&e.naturalWidth||(c=!0),e.addEventListener("load",(function(){l.isDestroyed||(l.width===e.naturalWidth&&l.height===e.naturalHeight||(l.width=e.naturalWidth,l.height=e.naturalHeight,l.resize()),l.setDirty(),l.setReady())}),!0),this.render=this.renderImageCanvas,d=!0,this.hook="image",this.compare=g);else if(!o&&k(e,"WebGLTexture")){if(n&&!n.isTexture(e))throw new Error("Not a valid WebGL texture.");isNaN(h)?isNaN(f)||(h=f):isNaN(f)&&(f=h),this.width=h,this.height=f,void 0===a.flip&&(u=!1),d=!0,this.texture=e,this.initialized=!0,this.hook="texture",this.compare=g,this.render=function(){}}if(!d&&!o)for(s in p)if(p.hasOwnProperty(s)&&p[s]&&(o=m(s,e,i,!1))){this.hook=s,d=!0,c=o.deferTexture,this.plugin=o,this.compare=o.compare,this.checkDirty=o.checkDirty,o.source&&(e=o.source);break}if(!d)throw new Error("Unknown source type");this.source=e,void 0===this.flip&&(this.flip=u),this.targets=[],c||l.setReady(),this.pub=new N(this),W.push(this),Y[this.id]=this,Q.push(this),x[this.hook].push(this),Q.length&&!I&>()},E.prototype=Object.create(y.prototype),E.prototype.constructor=E,E.prototype.initialize=function(){var t;n&&!this.texture&&this.ready&&(t=n.createTexture(),n.bindTexture(n.TEXTURE_2D,t),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),this.texture=t,this.initialized=!0,this.allowRefresh=!0,this.setDirty())},E.prototype.initFrameBuffer=function(t){n&&(this.frameBuffer=new K(n,this.width,this.height,{texture:this.texture,useFloat:t}))},E.prototype.addTarget=function(t){var e;for(e=0;e<this.targets.length;e++)if(this.targets[e]===t)return;this.targets.push(t)},E.prototype.removeTarget=function(t){var e=this.targets&&this.targets.indexOf(t);e>=0&&this.targets.splice(e,1)},E.prototype.resize=function(){var t,e;if(this.uniforms.resolution[0]=this.width,this.uniforms.resolution[1]=this.height,this.framebuffer&&this.framebuffer.resize(this.width,this.height),this.emit("resize"),this.setDirty(),this.targets)for(t=0;t<this.targets.length;t++)(e=this.targets[t]).resize(),e.setTransformDirty&&e.setTransformDirty()},E.prototype.setReady=function(){var t;if(!this.ready&&(this.ready=!0,this.resize(),this.initialize(),this.emit("ready"),this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setReady()},E.prototype.render=function(){var t=this.source;n&&(t||0===t)&&this.ready&&(this.initialized||this.initialize(),this.allowRefresh&&this.plugin&&this.plugin.render&&(this.dirty||this.checkDirty&&this.checkDirty())&&this.plugin.render.call(this,n,vt,h,c)&&(this.dirty=!1,this.emit("render")))},E.prototype.renderImageCanvas=function(){var e=this.source;if(n&&e&&this.ready&&(this.initialized||this.initialize(),this.allowRefresh&&this.dirty)){n.bindTexture(n.TEXTURE_2D,this.texture),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,this.flip),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);try{return n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),this.dirty=!1,this.emit("render"),!0}catch(e){e.code===t.DOMException.SECURITY_ERR&&(this.allowRefresh=!1,J.logger.error("Unable to access cross-domain image"))}return!1}},E.prototype.destroy=function(){var t,e,i;for(this.plugin&&this.plugin.destroy&&this.plugin.destroy.call(this),n&&this.texture&&n.deleteTexture(this.texture);this.targets.length;)(i=this.targets.pop())&&i.removeSource&&i.removeSource(this);for(e in(t=Q.indexOf(this))>=0&&Q.splice(t,1),(t=x[this.hook].indexOf(this))>=0&&x[this.hook].splice(t,1),this)this.hasOwnProperty(e)&&"id"!==e&&delete this[e];y.prototype.destroy.call(this)},S=function(t){var e=t;Object.defineProperties(this,{source:{enumerable:!0,configurable:!0,get:function(){if(e.source)return e.source.pub},set:function(t){e.setSource(t)}},original:{enumerable:!0,configurable:!0,get:function(){return e.target}},width:{enumerable:!0,configurable:!0,get:function(){return e.width},set:function(t){!isNaN(t)&&t>0&&e.width!==t&&(e.width=t,e.resize(),e.setTransformDirty())}},height:{enumerable:!0,configurable:!0,get:function(){return e.height},set:function(t){!isNaN(t)&&t>0&&e.height!==t&&(e.height=t,e.resize(),e.setTransformDirty())}},id:{enumerable:!0,configurable:!0,get:function(){return e.id}}}),this.render=function(){e.render()},this.readPixels=function(t,i,r,n,s){return e.readPixels(t,i,r,n,s)},this.on=function(t,i){e.on(t,i)},this.off=function(t,i){e.off(t,i)},this.go=function(t){e.go(t)},this.stop=function(){e.stop()},this.getTexture=function(){return e.frameBuffer.texture},this.destroy=function(){var t,i;for(t in e.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((i=Object.getOwnPropertyDescriptor(this,t)).get||i.set||"function"!=typeof this[t]?delete this[t]:this[t]=w)},this.inputs=function(t){return{source:{type:"image"}}},this.isDestroyed=function(){return e.isDestroyed},this.isReady=function(){return e.ready}},A=function(t,e,i){var s,f,l,d,p,g,v,x,E,T=this,R=!1;function D(t,e,i,r){var s=m[t];if(s.definition){if(!(s=s.definition.call(T,e,i,r)))return null;s=z(z({},m[t]),s),T.hook=E,R=!0,T.plugin=s,T.compare=s.compare,s.target&&(e=s.target),s.gl&&!T.gl&&(T.gl=s.gl,n||pt(s.gl)),T.gl===n&&(T.model=h,T.shader=c)}return s}if(y.call(this),(t&&"string"!=typeof t||!e&&0!==e)&&(i&&"object"===r.typeof(i)||(i=e),e=t),f=void 0===(s=i||{}).flip||s.flip,l=parseInt(s.width,10),d=parseInt(s.height,10),g=s.debugContext,"string"==typeof t&&m[t]&&D(t,e,s,!0),this.renderToTexture=s.renderToTexture,k(e,"WebGLFramebuffer"))if(v=e,k(s,"HTMLCanvasElement"))e=s;else if(k(s,"WebGLRenderingContext"))e=s.canvas;else if(k(s.canvas,"HTMLCanvasElement"))e=s.canvas;else{if(!k(s.context,"WebGLRenderingContext"))throw new Error("Must provide a canvas with WebGLFramebuffer target");e=s.context.canvas}if(k(e,"HTMLCanvasElement")){if(l=e.width,d=e.height,(!n||n.canvas!==e&&s.allowSecondaryWebGL)&&(p=H(e,{alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!0,stencil:!0,debugContext:g})),p)n&&n!==p?(this.gl=p,this.frameBuffer={frameBuffer:v||null},this.shader=new $(this.gl,a,u),this.model=lt.call(this,this.gl),this.pixels=null,this.texture=this.gl.createTexture(),this.gl.bindTexture(n.TEXTURE_2D,this.texture),this.gl.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),this.gl.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),this.gl.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),this.gl.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),this.render=this.renderSecondaryWebGL):(o||(o=this),n||pt(p),this.render=this.renderWebGL,s.renderToTexture?n&&(this.frameBuffer=new K(n,l,d,!1)):this.frameBuffer={frameBuffer:v||null});else{if(!s.allowSecondaryWebGL&&n&&n.canvas!==e)throw new Error("Only one WebGL target canvas allowed. Set allowSecondaryWebGL option to create secondary context.");this.render=w,J.logger.log("Unable to create WebGL context.")}R=!0}if(!R)for(E in m)if(m.hasOwnProperty(E)&&m[E]&&D(E,e,s,!1))break;if(!R)throw new Error("Unknown target type");b&&((x=b.get(e))?J.logger.warn("Target already in use by another instance",e,Object.keys(x).map((function(t){return x[t]}))):(x={},b.set(e,x)),x[X.id]=X),this.target=e,this.transform=null,this.transformDirty=!0,this.flip=f,l&&(this.width=l),d&&(this.height=d),this.uniforms.resolution[0]=this.width,this.uniforms.resolution[1]=this.height,void 0!==s.auto?this.auto=s.auto:this.auto=ut,this.frames=0,this.pub=new S(this),W.push(this),Y[this.id]=this,tt.push(this)},A.prototype=Object.create(y.prototype),A.prototype.constructor=A,A.prototype.setSource=function(t){var e;(e=xt(t))!==this.source&&(this.source&&this.source.removeTarget(this),this.source=e,e.addTarget(this),e&&(this.resize(),e.ready?this.setReady():this.setUnready()),this.setDirty())},A.prototype.setDirty=function(){this.dirty=!0,this.auto&&!I&&(I=B(gt))},A.prototype.resize=function(){k(this.target,"HTMLCanvasElement")?this.width===this.target.width&&this.height===this.target.height||(this.target.width=this.width,this.target.height=this.height,this.uniforms.resolution[0]=this.width,this.uniforms.resolution[1]=this.height,this.emit("resize"),this.setTransformDirty()):this.plugin&&this.plugin.resize&&this.plugin.resize.call(this),!this.source||this.source.width===this.width&&this.source.height===this.height||this.transform||(this.transform=new Float32Array(16))},A.prototype.setTransformDirty=function(){this.transformDirty=!0,this.setDirty()},A.prototype.go=function(){this.auto=!0,this.setDirty()},A.prototype.stop=function(){this.auto=!1},A.prototype.render=function(){n&&this.plugin&&this.plugin.render&&this.plugin.render.call(this,vt,c,h)},A.prototype.renderWebGL=function(){var t,e,i;if(this.resize(),n&&this.dirty&&this.ready){if(!this.source)return;this.source.render(),this.uniforms.source=this.source.texture,this.source.width===this.width&&this.source.height===this.height?this.uniforms.transform=this.source.cumulativeMatrix||s:this.transformDirty&&(t=this.transform,U.copy(t,this.source.cumulativeMatrix||s),e=this.source.width/this.width,i=this.source.height/this.height,t[0]*=e,t[1]*=e,t[2]*=e,t[3]*=e,t[4]*=i,t[5]*=i,t[6]*=i,t[7]*=i,this.uniforms.transform=t,this.transformDirty=!1),vt(c,h,this.uniforms,this.frameBuffer.frameBuffer,this,P),this.emit("render"),this.dirty=!1}},A.prototype.renderSecondaryWebGL=function(){var t,e,i,r,n;this.dirty&&this.ready&&this.source&&(this.emit("render"),this.source.render(!0),t=this.source.width,e=this.source.height,this.pixels&&this.pixels.length===t*e*4||(this.pixels=new Uint8Array(t*e*4)),this.source.readPixels(0,0,t,e,this.pixels),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,t,e,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,this.pixels),t===this.width&&e===this.height?this.uniforms.transform=s:this.transformDirty&&(i=this.transform,U.copy(i,s),r=this.source.width/this.width,n=this.source.height/this.height,i[0]*=r,i[1]*=r,i[2]*=r,i[3]*=r,i[4]*=n,i[5]*=n,i[6]*=n,i[7]*=n,this.uniforms.transform=i,this.transformDirty=!1),this.uniforms.source=this.texture,vt(this.shader,this.model,this.uniforms,null,this,P),this.dirty=!1)},A.prototype.removeSource=function(t){this.source!==t&&this.source!==t.pub||(this.source=null)},A.prototype.destroy=function(){var t,e;this.source&&this.source.removeTarget&&this.source.removeTarget(this),b&&(delete(e=b.get(this.target))[X.id],Object.keys(e).length||b.delete(this.target)),this.plugin&&this.plugin.destroy&&this.plugin.destroy.call(this),delete this.source,delete this.target,delete this.pub,delete this.uniforms,delete this.pixels,delete this.auto,(t=tt.indexOf(this))>=0&&tt.splice(t,1),y.prototype.destroy.call(this),this===o&&(i.removeEventListener("webglcontextrestored",mt,!1),yt(),o=null)},F=function(t){var e,i=t,r=this;function n(t,e,r){var n,s,o;n=i.inputElements[t],"string"==typeof r&&isNaN(r)&&("enum"===e.type?e.options.hasOwnProperty(r)||(r=M(r,["select"])):"number"===e.type||"boolean"===e.type?r=M(r,["input","select"]):"image"===e.type&&(r=M(r,["canvas","img","video"]))),k(r,"HTMLInputElement")||k(r,"HTMLSelectElement")?(s=r.value,n&&n.element!==r&&(n.element.removeEventListener("change",n.listener,!0),n.element.removeEventListener("input",n.listener,!0),delete i.inputElements[t],n=null),n||(n={element:r,listener:(o=r,function(){var e,n;e="checkbox"===r.type?r.checked:o.value,n=i.setInput(t,e),"color"===r.type&&(n=j(n)),n!==e&&(o.value=n)})},i.inputElements[t]=n,"range"===r.type?(r.addEventListener("input",n.listener,!0),r.addEventListener("change",n.listener,!0)):r.addEventListener("change",n.listener,!0)),n&&"checkbox"===r.type&&(s=r.checked)):(n&&(n.element.removeEventListener("change",n.listener,!0),n.element.removeEventListener("input",n.listener,!0),delete i.inputElements[t]),s=r),i.setInput(t,s)}function s(t,e){Object.defineProperty(r,t,{configurable:!0,enumerable:!0,get:function(){return e.get.call(i)},set:function(i){n(t,e,i)}})}function o(t){return function(){t.apply(i,arguments)&&i.setTransformDirty()}}for(e in Object.defineProperties(this,{transform:{enumerable:!0,configurable:!0,get:function(){return i.hook}},title:{enumerable:!0,configurable:!0,get:function(){return i.plugin.title||i.hook}},width:{enumerable:!0,configurable:!0,get:function(){return i.width}},height:{enumerable:!0,configurable:!0,get:function(){return i.height}},id:{enumerable:!0,configurable:!0,get:function(){return i.id}},source:{enumerable:!0,configurable:!0,get:function(){return i.source&&i.source.pub},set:function(t){i.setSource(t)}}}),i.methods)i.methods.hasOwnProperty(e)&&(this[e]=o(i.methods[e]));for(e in i.inputs)i.inputs.hasOwnProperty(e)&&s(e,i.inputs[e]);this.update=function(){i.setDirty()},this.inputs=function(t){var e,r,n,s;if(n=i.plugin.inputs,t)return!(r=n[t])||r.method?null:(e={type:r.type,defaultValue:r.defaultValue,title:r.title||t},"number"===r.type?(e.min=r.min,e.max=r.max,e.step=r.step,e.mod=r.mod):"enum"===r.type?e.options=z({},r.options):"vector"===r.type&&(e.dimensions=r.dimensions),r.description&&(e.description=r.description),e);for(s in e={},n)n.hasOwnProperty(s)&&!n[s].method&&(e[s]=this.inputs(s));return e},this.alias=function(t,e){return i.alias(t,e),this},this.on=function(t,e){i.on(t,e)},this.off=function(t,e){i.off(t,e)},this.destroy=function(){var t,e;for(t in i.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((e=Object.getOwnPropertyDescriptor(this,t)).get||e.set||"function"!=typeof this[t]?delete this[t]:this[t]=w)},this.isDestroyed=function(){return i.isDestroyed},this.isReady=function(){return i.ready}},D=function(t,e){var i,r,n,s,o;for(i in this.matrix=new Float32Array(16),this.cumulativeMatrix=new Float32Array(16),this.ready=!1,this.width=1,this.height=1,this.seriously=X,this.transformRef=d[t],this.hook=t,this.id=q,q++,this.options=e,this.sources=null,this.targets=[],this.inputElements={},this.inputs={},this.methods={},this.listeners={},this.texture=null,this.frameBuffer=null,this.uniforms=null,this.dirty=!0,this.transformDirty=!0,this.renderDirty=!1,this.isDestroyed=!1,this.transformed=!1,this.plugin=z({},this.transformRef),this.transformRef.definition&&z(this.plugin,this.transformRef.definition.call(this,e)),this.plugin.inputs)this.plugin.inputs.hasOwnProperty(i)&&((r=this.plugin.inputs[i]).method&&"function"==typeof r.method?this.methods[i]=r.method:"function"==typeof r.set&&"function"==typeof r.get&&(this.inputs[i]=r));for(i in Z(this.plugin),o=ot[t],this.plugin.inputs)this.plugin.inputs.hasOwnProperty(i)&&"function"==typeof(r=this.plugin.inputs[i]).set&&"function"==typeof r.get&&"function"!=typeof r.method&&(n=r.get.call(this),s=void 0===r.defaultValue?n:r.defaultValue,s=r.validate.call(this,s,r,n),o&&void 0!==o[i]&&(s=r.validate.call(this,o[i],r,r.defaultValue,s),o[i]=s),s!==n&&r.set.call(this,s));W.push(this),Y[this.id]=this,this.pub=new F(this),et.push(this),v[t].push(this)},D.prototype=Object.create(y.prototype),D.prototype.constructor=D,D.prototype.setDirty=function(){this.renderDirty=!0,y.prototype.setDirty.call(this)},D.prototype.setTransformDirty=function(){var t,e;for(this.transformDirty=!0,this.dirty=!0,this.renderDirty=!0,t=0;t<this.targets.length;t++)(e=this.targets[t]).setTransformDirty?e.setTransformDirty():e.setDirty()},D.prototype.resize=function(){var t;for(y.prototype.resize.call(this),this.plugin.resize&&this.plugin.resize.call(this),t=0;t<this.targets.length;t++)this.targets[t].resize();this.setTransformDirty()},D.prototype.setSource=function(t){var e;if((e=xt(t))!==this.source){if(Et(e,this))throw new Error("Attempt to make cyclical connection.");this.source&&this.source.removeTarget(this),this.source=e,e.addTarget(this),e&&e.ready?this.setReady():this.setUnready(),this.resize()}},D.prototype.addTarget=function(t){var e;for(e=0;e<this.targets.length;e++)if(this.targets[e]===t)return;this.targets.push(t)},D.prototype.removeTarget=function(t){var e=this.targets&&this.targets.indexOf(t);e>=0&&this.targets.splice(e,1),this.targets&&this.targets.length&&this.resize()},D.prototype.setInput=function(t,e){var i,r,n;if(this.plugin.inputs.hasOwnProperty(t))return i=this.plugin.inputs[t],r=ot[this.hook]&&void 0!==ot[this.hook][t]?ot[this.hook][t]:i.defaultValue,n=i.get.call(this),void 0===r&&(r=n),e=i.validate.call(this,e,i,r,n),i.set.call(this,e)&&this.setTransformDirty(),i.get.call(this)},D.prototype.alias=function(t,e){var i,r,n=this;if(C.indexOf(e)>=0)throw new Error("'"+e+"' is a reserved name and cannot be used as an alias.");return this.plugin.inputs.hasOwnProperty(t)&&(e||(e=t),X.removeAlias(e),(i=this.inputs[t])?(r=n.inputs[t],Object.defineProperty(X,e,{configurable:!0,enumerable:!0,get:function(){return r.get.call(n)},set:function(t){r.set.call(n,t)&&n.setTransformDirty()}})):(i=this.methods[t])&&(r=i,X[e]=function(){r.apply(n,arguments)&&n.setTransformDirty()}),i&&(rt[e]={node:this,input:t})),this},D.prototype.render=function(t){return this.source?(this.source.render(),this.transformDirty&&(this.transformed?this.source.cumulativeMatrix?U.multiply(this.cumulativeMatrix,this.matrix,this.source.cumulativeMatrix):U.copy(this.cumulativeMatrix,this.matrix):U.copy(this.cumulativeMatrix,this.source.cumulativeMatrix||s),this.transformDirty=!1),t&&n?(this.renderDirty&&(this.frameBuffer||(this.uniforms={resolution:[this.width,this.height]},this.frameBuffer=new K(n,this.width,this.height)),this.uniforms.source=this.source.texture,this.uniforms.transform=this.cumulativeMatrix||s,vt(c,h,this.uniforms,this.frameBuffer.frameBuffer,this),this.renderDirty=!1),this.texture=this.frameBuffer.texture):this.source?this.texture=this.source.texture:this.texture=null,this.dirty=!1,this.texture):(this.transformDirty&&(U.copy(this.cumulativeMatrix,this.matrix),this.transformDirty=!1),this.texture=null,void(this.dirty=!1))},D.prototype.readPixels=function(t,e,i,r,s){var o=this.gl||n;if(!n)throw new Error("Cannot read pixels until a canvas is connected");if(this.render(!0),void 0===s)s=new Uint8Array(i*r*4);else if(!k(s,"Uint8Array"))throw new Error("Incompatible array type");return o.bindFramebuffer(n.FRAMEBUFFER,this.frameBuffer.frameBuffer),o.readPixels(t,e,i,r,n.RGBA,n.UNSIGNED_BYTE,s),s},D.prototype.destroy=function(){var t,e,i,r=this.hook;for(t in this.plugin.destroy&&"function"==typeof this.plugin.destroy&&this.plugin.destroy.call(this),delete this.effect,this.frameBuffer&&(this.frameBuffer.destroy(),delete this.frameBuffer,delete this.texture),this.inputElements)this.inputElements.hasOwnProperty(t)&&((i=this.inputElements[t]).element.removeEventListener("change",i.listener,!0),i.element.removeEventListener("input",i.listener,!0));for(this.source&&this.source.removeTarget(this);this.targets.length;)(i=this.targets.pop())&&i.removeSource&&i.removeSource(this);for(e in this)this.hasOwnProperty(e)&&"id"!==e&&delete this[e];for(e in rt)rt.hasOwnProperty(e)&&(i=rt[e]).node===this&&X.removeAlias(e);(t=et.indexOf(this))>=0&&et.splice(t,1),(t=v[r].indexOf(this))>=0&&v[r].splice(t,1),y.prototype.destroy.call(this)},D.prototype.setReady=y.prototype.setReady,D.prototype.setUnready=y.prototype.setUnready,D.prototype.on=y.prototype.on,D.prototype.off=y.prototype.off,D.prototype.emit=y.prototype.emit,(e=k(e,"HTMLCanvasElement")?{canvas:e}:e||{}).canvas,this.effect=function(t,e){if(!l[t])throw new Error("Unknown effect: "+t);return new R(t,e).pub},this.source=function(t,e,i){return xt(t,e,i).pub},this.transform=function(t,i){if("string"!=typeof t&&(i=t,t=!1),t){if(!d[t])throw new Error("Unknown transform: "+t)}else if(t=e&&e.defaultTransform||"2d",!d[t])throw new Error("No transform specified");return new D(t,i).pub},this.target=function(t,e,i){var n,s,o;for(t&&"string"==typeof t&&!m[t]&&(s=f.querySelector(t)),("string"!=typeof t||!e&&0!==e||s)&&(i&&"object"===r.typeof(i)||(i=e),e=s||t,t=null),"string"==typeof e&&isNaN(e)&&(e=f.querySelector(e)),o=0;o<tt.length;o++)if(n=tt[o],(!t||t===n.hook)&&(n.target===e||n.compare&&n.compare(e,i)))return n.pub;return(n=new A(t,e,i)).pub},this.aliases=function(){return Object.keys(rt)},this.removeAlias=function(t){rt[t]&&(delete this[t],delete rt[t])},this.defaults=function(t,e){var i;if(t)if("object"!==r.typeof(t))null===e?delete ot[t]:"object"===r.typeof(e)&&(ot[t]=z({},e));else for(i in t)t.hasOwnProperty(i)&&this.defaults(i,t[i]);else if(null===t)for(i in ot)ot.hasOwnProperty(i)&&delete ot[i]},this.go=function(t,e){var i;for("function"==typeof t&&nt.indexOf(t)<0&&nt.push(t),"function"==typeof e&&st.indexOf(e)<0&&st.push(e),ut=!0,i=0;i<tt.length;i++)tt[i].go();I||!nt.length&&!st.length||gt()},this.stop=function(){nt.length=0,st.length=0,L(I),I=0},this.render=function(){var t;for(t=0;t<tt.length;t++)tt[t].render(e)},this.destroy=function(){for(var t,e;W.length;)W[0].pub.destroy();for(t in this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((e=Object.getOwnPropertyDescriptor(this,t)).get||e.set||"function"!=typeof this[t]?delete this[t]:this[t]=w);X=null,Q=[],tt=[],it=[],W=[],nt.length=0,st.length=0,L(I),I=0,ht=!0},this.isDestroyed=function(){return ht},this.incompatible=function(t){var e,i,r=!1;if(r=J.incompatible(t))return r;if(!t){for(e in g)if(g.hasOwnProperty(e)&&g[e].length&&(i=l[e])&&"function"==typeof i.compatible&&!i.compatible.call(this))return"plugin-"+e;for(e in x)if(x.hasOwnProperty(e)&&x[e].length&&(i=p[e])&&"function"==typeof i.compatible&&!i.compatible.call(this))return"source-"+e}return!1},this.isNode=function(t){var e;return!(!t||!(e=Y[t.id])||e.isDestroyed)},this.isSource=function(t){return this.isNode(t)&&t instanceof N},this.isEffect=function(t){return this.isNode(t)&&t instanceof _},this.isTransform=function(t){return this.isNode(t)&&t instanceof F},this.isTarget=function(t){return this.isNode(t)&&t instanceof S},Object.defineProperties(this,{id:{enumerable:!0,configurable:!0,get:function(){return G}}}),this.defaults(e.defaults)}return t.addEventListener("message",(function(e){e.source===t&&"seriously-timeout-message"===e.data&&(e.stopPropagation(),y.length>0&&y.shift()())}),!0),K.prototype.resize=function(t,e){var i=this.gl;this.width===t&&this.height===e||(this.width=t,this.height=e,i&&(i.bindTexture(i.TEXTURE_2D,this.texture),i.bindFramebuffer(i.FRAMEBUFFER,this.frameBuffer),i.bindRenderbuffer(i.RENDERBUFFER,this.renderBuffer),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,t,e,0,i.RGBA,i.UNSIGNED_BYTE,null),i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_COMPONENT16,t,e),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,this.texture,0),i.bindTexture(i.TEXTURE_2D,null),i.bindRenderbuffer(i.RENDERBUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,null)))},K.prototype.destroy=function(){var t=this.gl;t&&(t.deleteFramebuffer(this.frameBuffer),t.deleteRenderbuffer(this.renderBuffer),this.ownTexture&&t.deleteTexture(this.texture)),delete this.frameBuffer,delete this.renderBuffer,delete this.texture,delete this.gl},$.prototype.use=function(){this.gl.useProgram(this.program)},J.incompatible=function(e){var i,r,s;if(void 0===n&&((i=f.createElement("canvas"))&&i.getContext?t.WebGLRenderingContext?(r=Y())||(n="context"):n="webgl":n="canvas"),n)return n;if(e){if((s=l[e])&&"function"==typeof s.compatible&&!s.compatible(r))return"plugin-"+e;if((s=p[e])&&"function"==typeof s.compatible&&!s.compatible(r))return"source-"+e}return!1},J.plugin=function(t,e,i){var n;if(l[t])J.logger.warn("Effect ["+t+"] already loaded");else if(void 0===i&&"object"===r.typeof(e)&&(i=e),i)return n=z({},i),"function"==typeof e&&(n.definition=e),n.reserved=S,n.inputs&&Z(n),n.title||(n.title=t),l[t]=n,g[t]=[],n},J.removePlugin=function(t){var e;if(!t)return this;if(!l[t])return this;if(e=g[t]){for(;e.length;)e.shift().destroy();delete g[t]}return delete l[t],this},J.source=function(t,e,i){var n;if(p[t])J.logger.warn("Source ["+t+"] already loaded");else if(void 0===i&&"object"===r.typeof(e)&&(i=e),i||e)return n=z({},i),"function"==typeof e&&(n.definition=e),n.title||(n.title=t),p[t]=n,x[t]=[],n},J.removeSource=function(t){var e;if(!t)return this;if(!p[t])return this;if(e=x[t]){for(;e.length;)e.shift().destroy();delete x[t]}return delete p[t],this},J.transform=function(t,e,i){var n;if(d[t])J.logger.warn("Transform ["+t+"] already loaded");else if(void 0===i&&"object"===r.typeof(e)&&(i=e),i||e)return n=z({},i),"function"==typeof e&&(n.definition=e),n.reserved=I,n.inputs&&Z(n),n.title||(n.title=t),d[t]=n,v[t]=[],n},J.removeTransform=function(t){var e;if(!t)return this;if(!d[t])return this;if(e=v[t]){for(;e.length;)e.shift().destroy();delete v[t]}return delete d[t],this},J.target=function(t,e,i){var n;if(m[t])J.logger.warn("Target ["+t+"] already loaded");else if(void 0===i&&"object"===r.typeof(e)&&(i=e),i||e)return n=z({},i),"function"==typeof e&&(n.definition=e),n.title||(n.title=t),m[t]=n,E[t]=[],n},J.removeTarget=function(t){var e;if(!t)return this;if(!m[t])return this;if(e=E[t]){for(;e.length;)e.shift().destroy();delete E[t]}return delete m[t],this},J.inputValidators={color:function(t,e,n,s){var o,a,u,h;if(a=s||[],"string"==typeof t){if((u=D.exec(t))&&u.length){if(u.length<3)return a[0]=a[1]=a[2]=a[3]=0,a;for(a[3]=1,h=0;h<3;h++)a[h]=parseFloat(u[h+2])/255;return isNaN(u[6])||(a[3]=parseFloat(u[6])),"hsl"===u[1].toLowerCase()?X(a[0],a[1],a[2],a[3],a):a}if((u=A.exec(t))&&u.length)return 3===(o=u[1]).length?(a[0]=parseInt(o[0],16)/15,a[1]=parseInt(o[1],16)/15,a[2]=parseInt(o[2],16)/15,a[3]=1):4===o.length?(a[0]=parseInt(o[0],16)/15,a[1]=parseInt(o[1],16)/15,a[2]=parseInt(o[2],16)/15,a[3]=parseInt(o[3],16)/15):6===o.length?(a[0]=parseInt(o.substr(0,2),16)/255,a[1]=parseInt(o.substr(2,2),16)/255,a[2]=parseInt(o.substr(4,2),16)/255,a[3]=1):8===o.length?(a[0]=parseInt(o.substr(0,2),16)/255,a[1]=parseInt(o.substr(2,2),16)/255,a[2]=parseInt(o.substr(4,2),16)/255,a[3]=parseInt(o.substr(6,2),16)/255):a[0]=a[1]=a[2]=a[3]=0,a;if(u=R[t.toLowerCase()]){for(h=0;h<4;h++)a[h]=u[h];return a}return i||(i=f.createElement("canvas").getContext("2d")),i.fillStyle=t,(o=i.fillStyle)&&"#000000"!==o?J.inputValidators.color(o,e,n,s):(a[0]=a[1]=a[2]=a[3]=0,a)}if(W(t)){if((a=t).length<3)return a[0]=a[1]=a[2]=a[3]=0,a;for(h=0;h<3;h++)if(isNaN(a[h]))return a[0]=a[1]=a[2]=a[3]=0,a;return a.length<4&&a.push(1),a}if("number"==typeof t)return a[0]=a[1]=a[2]=t,a[3]=1,a;if("object"===r.typeof(t)){for(h=0;h<4;h++)null===t[o=N[h]]||isNaN(t[o])?a[h]=3===h?1:0:a[h]=t[o];return a}return a[0]=a[1]=a[2]=a[3]=0,a},number:function(t,e,i){return t=parseFloat(t),isNaN(t)?i||0:(e.mod&&(t-=e.mod*Math.floor(t/e.mod)),t<e.min?e.min:t>e.max?e.max:e.step?Math.round(t/e.step)*e.step:t)},enum:function(t,e,i){var r=e.options||[];return"string"==typeof t?t=t.toLowerCase():"number"==typeof t?t=t.toString():t||(t=""),r.hasOwnProperty(t)?t:i||""},vector:function(t,e,i,n){var s,o,a,u=e.dimensions||4;if(s=n||[],W(t)){for(o=0;o<u;o++)s[o]=t[o]||0;return s}if("object"===r.typeof(t)){for(o=0;o<u;o++)void 0===t[a=_[o]]&&(a=N[o]),s[o]=t[a]||0;return s}for(t=parseFloat(t)||0,o=0;o<u;o++)s[o]=t;return s},boolean:function(t){return!(!t||t&&t.toLowerCase&&"false"===t.toLowerCase())},string:function(t){return"string"==typeof t?t:0===t||t?t.toString?t.toString():String(t):""}},J.prototype.effects=J.effects=function(){var t,e,i,r,n,s={};for(t in l)if(l.hasOwnProperty(t)){for(n in i={title:(e=l[t]).title||t,description:e.description||"",inputs:{}},e.inputs)e.inputs.hasOwnProperty(n)&&(r=e.inputs[n],i.inputs[n]={type:r.type,defaultValue:r.defaultValue,step:r.step,min:r.min,max:r.max,mod:r.mod,minCount:r.minCount,maxCount:r.maxCount,dimensions:r.dimensions,title:r.title||n,description:r.description||"",options:r.options||[]});s[t]=i}return s},t.Float32Array&&(s=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])),t.Seriously&&"object"===r.typeof(t.Seriously)&&function(){var e;for(e in t.Seriously)t.Seriously.hasOwnProperty(e)&&"plugin"!==e&&"object"===r.typeof(t.Seriously[e])&&J.plugin(e,t.Seriously[e])}(),J.logger={log:G("log"),info:G("info"),warn:G("warn"),error:G("error")},J.util={mat4:U,checkSource:q,hslToRgb:X,colors:R,setTimeoutZero:V,ShaderProgram:$,FrameBuffer:K,requestAnimationFrame:B,shader:{makeNoise:"float makeNoise(float u, float v, float timer) {\n\tfloat x = u * v * mod(timer * 1000.0, 100.0);\n\tx = mod(x, 13.0) * mod(x, 127.0);\n\tfloat dx = mod(x, 0.01);\n\treturn clamp(0.1 + dx * 100.0, 0.0, 1.0);\n}\n",random:"#ifndef RANDOM\n#define RANDOM\nfloat random(vec2 n) {\n\treturn 0.5 + 0.5 * fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453);\n}\n#endif\n"}},J.source("video",(function(e,i,r){var n,s,a=this,u=!1,h=!1,c=!1,l=0;function d(){e.removeEventListener("loadedmetadata",d,!0),u||(e.videoWidth?(a.width===e.videoWidth&&a.height===e.videoHeight||(a.width=e.videoWidth,a.height=e.videoHeight,a.resize()),h&&a.setReady()):(h=!0,setTimeout(d,50)))}function p(){c=!0}function m(){c=!1,a.setDirty()}if(k(e,"HTMLVideoElement"))return e.readyState?d():(h=!0,e.addEventListener("loadedmetadata",d,!0)),e.addEventListener("seeking",p,!1),e.addEventListener("seeked",m,!1),{deferTexture:h,source:e,render:function i(r){var u;if(l=e.currentTime,!e.videoHeight||!e.videoWidth)return!1;o?(s||(s=f.createElement("canvas").getContext("2d"),(n=s.canvas).width=a.width,n.height=a.height),u=n,s.drawImage(e,0,0,a.width,a.height)):u=e,r.bindTexture(r.TEXTURE_2D,a.texture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,a.flip),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);try{if(r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,u),void 0===o){if(r.getError()===r.INVALID_VALUE)return o=!0,i(r);o=!1}return!0}catch(e){e.code===t.DOMException.SECURITY_ERR?(a.allowRefresh=!1,J.logger.error("Unable to access cross-domain image")):J.logger.error("Error rendering video source",e)}return!1},checkDirty:function(){return!c&&e.currentTime!==l},compare:function(t){return a.source===t},destroy:function(){u=!0,e.removeEventListener("seeking",p,!1),e.removeEventListener("seeked",m,!1),e.removeEventListener("loadedmetadata",d,!0)}}}),{title:"Video"}),J.transform("2d",(function(t){var e=this,i=!(t&&t.radians),r=0,n=0,s=1,o=1,a=0,u=0,h=0,f=0,c=0;function l(){var t,l,d,p,m,y,g,v,x,E,b,T=e.matrix;function w(t,e){T[12]=T[0]*t+T[4]*e+T[12],T[13]=T[1]*t+T[5]*e+T[13],T[14]=T[2]*t+T[6]*e+T[14],T[15]=T[3]*t+T[7]*e+T[15]}a||u||h||f||c||1!==s||1!==o?(U.identity(T),w(a+r,u+n),f&&(T[4]=f/e.width),c&&(T[1]=c/e.height),h&&(p=T[0],m=T[1],y=T[2],g=T[3],v=T[4],x=T[5],E=T[6],b=T[7],t=-(i?h*Math.PI/180:h),l=Math.sin(t),d=Math.cos(t),T[0]=p*d+v*l,T[1]=m*d+x*l,T[2]=y*d+E*l,T[3]=g*d+b*l,T[4]=v*d-p*l,T[5]=x*d-m*l,T[6]=E*d-y*l,T[7]=b*d-g*l),1!==s&&(T[0]*=s,T[1]*=s,T[2]*=s,T[3]*=s),1!==o&&(T[4]*=o,T[5]*=o,T[6]*=o,T[7]*=o),w(-r,-n),e.transformed=!0):e.transformed=!1}return{inputs:{reset:{method:function(){return r=0,n=0,s=1,o=1,a=0,u=0,h=0,f=0,c=0,!!e.transformed&&(e.transformed=!1,!0)}},translate:{method:function(t,e){return isNaN(t)&&(t=a),isNaN(e)&&(e=u),(t!==a||e!==u)&&(a=t,u=e,l(),!0)},type:["number","number"]},translateX:{get:function(){return a},set:function(t){return t!==a&&(a=t,l(),!0)},type:"number"},translateY:{get:function(){return u},set:function(t){return t!==u&&(u=t,l(),!0)},type:"number"},rotation:{get:function(){return h},set:function(t){return t!==h&&(h=parseFloat(t),l(),!0)},type:"number"},center:{method:function(t,e){return isNaN(t)&&(t=r),isNaN(e)&&(e=n),(t!==r||e!==n)&&(r=t,n=e,l(),!0)},type:["number","number"]},centerX:{get:function(){return r},set:function(t){return t!==r&&(r=t,l(),!0)},type:"number"},centerY:{get:function(){return n},set:function(t){return t!==n&&(n=t,l(),!0)},type:"number"},skew:{method:function(t,e){return isNaN(t)&&(t=f),isNaN(e)&&(e=c),(t!==f||e!==c)&&(f=t,c=e,l(),!0)},type:["number","number"]},skewX:{get:function(){return f},set:function(t){return t!==f&&(f=t,l(),!0)},type:"number"},skewY:{get:function(){return c},set:function(t){return t!==c&&(c=t,l(),!0)},type:"number"},scale:{method:function(t,e){var i,r;if(i=isNaN(t)?s:t,isNaN(e)){if(isNaN(t))return!1;r=i}else r=e;return(i!==s||r!==o)&&(s=i,o=r,l(),!0)},type:["number","number"]},scaleX:{get:function(){return s},set:function(t){return t!==s&&(s=t,l(),!0)},type:"number"},scaleY:{get:function(){return o},set:function(t){return t!==o&&(o=t,l(),!0)},type:"number"}}}}),{title:"2D Transform",description:"Translate, Rotate, Scale, Skew"}),J.transform("flip",(function(){var t=this,e=!0;function i(){var i=t.matrix;e?(i[0]=-1,i[5]=1):(i[0]=1,i[5]=-1)}return U.identity(t.matrix),i(),t.transformDirty=!0,t.transformed=!0,{inputs:{direction:{get:function(){return e?"horizontal":"vertical"},set:function(t){var r;return(r="vertical"!==t)!==e&&(e=r,i(),!0)},type:"string"}}}}),{title:"Flip",description:"Flip Horizontal/Vertical"}),J.transform("reformat",(function(){var t,e,i=this,r="contain";function n(){var n,s,o,a,u=i.matrix,h=t||i.width,f=e||i.height,c=i.source,l=c&&c.width||1,d=c&&c.height||1;"distort"===r||h===l&&f===d?i.transformed=!1:(o=l/d,a=h/f,"none"===r?(n=l/h,s=d/f):"width"===r||"contain"===r&&a<=o?(n=1,s=a/o):"height"===r||"contain"===r&&a>o?(n=o/a,s=1):a>o?(n=1,s=a/o):(n=o/a,s=1),1!==n||1!==s?(U.identity(u),1!==n&&(u[0]*=n,u[1]*=n,u[2]*=n,u[3]*=n),1!==s&&(u[4]*=s,u[5]*=s,u[6]*=s,u[7]*=s),i.transformed=!0):i.transformed=!1)}function s(){return t||i.source&&i.source.width||1}function o(){return e||i.source&&i.source.height||1}return this.resize=function(){var t,e=s(),i=o();if(this.width!==e||this.height!==i)for(this.width=e,this.height=i,this.uniforms&&this.uniforms.resolution&&(this.uniforms.resolution[0]=e,this.uniforms.resolution[1]=i),this.frameBuffer&&this.frameBuffer.resize&&this.frameBuffer.resize(e,i),t=0;t<this.targets.length;t++)this.targets[t].resize();this.setTransformDirty(),n()},{inputs:{width:{get:s,set:function(e){return(e=Math.floor(e))===t||(t=e,this.resize()),!1},type:"number"},height:{get:o,set:function(t){return(t=Math.floor(t))===e||(e=t,this.resize()),!1},type:"number"},mode:{get:function(){return r},set:function(t){return t!==r&&(r=t,n(),!0)},type:"enum",options:["cover","contain","distort","width","height","none"]}}}}),{title:"Reformat",description:"Change output dimensions"}),a=["precision mediump float;","attribute vec4 position;","attribute vec2 texCoord;","uniform vec2 resolution;","uniform mat4 transform;","varying vec2 vTexCoord;","void main(void) {","\tvec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);","\tscreenPosition = transform * screenPosition;","\tgl_Position.xy = screenPosition.xy * 2.0 / resolution;","\tgl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);","\tgl_Position.w = screenPosition.w;","\tvTexCoord = texCoord;","}\n"].join("\n"),u=["precision mediump float;","varying vec2 vTexCoord;","uniform sampler2D source;","void main(void) {","\t\tgl_FragColor = texture2D(source, vTexCoord);","}"].join("\n"),J.util.shader.noiseHelpers="#ifndef NOISE_HELPERS\n#define NOISE_HELPERS\nvec2 mod289(vec2 x) {\n\treturn x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec3 mod289(vec3 x) {\n\treturn x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 mod289(vec4 x) {\n\treturn x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec3 permute(vec3 x) {\n\treturn mod289(((x*34.0)+1.0)*x);\n}\nvec4 permute(vec4 x) {\n\treturn mod289(((x*34.0)+1.0)*x);\n}\nvec4 taylorInvSqrt(vec4 r) {\n\treturn 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat taylorInvSqrt(float r) {\n\treturn 1.79284291400159 - 0.85373472095314 * r;\n}\n#endif\n",J.util.shader.snoise2d="#ifndef NOISE2D\n#define NOISE2D\nfloat snoise(vec2 v) {\n\tconst vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0\n\t\t0.366025403784439, // 0.5*(sqrt(3.0)-1.0)\n\t\t-0.577350269189626, // -1.0 + 2.0 * C.x\n\t\t0.024390243902439); // 1.0 / 41.0\n\tvec2 i = floor(v + dot(v, C.yy));\n\tvec2 x0 = v - i + dot(i, C.xx);\n\tvec2 i1;\n\t//i1.x = step(x0.y, x0.x); // x0.x > x0.y ? 1.0 : 0.0\n\t//i1.y = 1.0 - i1.x;\n\ti1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n\t// x0 = x0 - 0.0 + 0.0 * C.xx ;\n\t// x1 = x0 - i1 + 1.0 * C.xx ;\n\t// x2 = x0 - 1.0 + 2.0 * C.xx ;\n\tvec4 x12 = x0.xyxy + C.xxzz;\n\tx12.xy -= i1;\n\ti = mod289(i); // Avoid truncation effects in permutation\n\tvec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));\n\tvec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);\n\tm = m*m ;\n\tm = m*m ;\n\tvec3 x = 2.0 * fract(p * C.www) - 1.0;\n\tvec3 h = abs(x) - 0.5;\n\tvec3 ox = floor(x + 0.5);\n\tvec3 a0 = x - ox;\n\tm *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);\n\tvec3 g;\n\tg.x = a0.x * x0.x + h.x * x0.y;\n\tg.yz = a0.yz * x12.xz + h.yz * x12.yw;\n\treturn 130.0 * dot(m, g);\n}\n#endif\n",J.util.shader.snoise3d="#ifndef NOISE3D\n#define NOISE3D\nfloat snoise(vec3 v) {\n\tconst vec2 C = vec2(1.0/6.0, 1.0/3.0) ;\n\tconst vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n\tvec3 i = floor(v + dot(v, C.yyy));\n\tvec3 x0 = v - i + dot(i, C.xxx) ;\n\tvec3 g = step(x0.yzx, x0.xyz);\n\tvec3 l = 1.0 - g;\n\tvec3 i1 = min(g.xyz, l.zxy);\n\tvec3 i2 = max(g.xyz, l.zxy);\n\t// x0 = x0 - 0.0 + 0.0 * C.xxx;\n\t// x1 = x0 - i1 + 1.0 * C.xxx;\n\t// x2 = x0 - i2 + 2.0 * C.xxx;\n\t// x3 = x0 - 1.0 + 3.0 * C.xxx;\n\tvec3 x1 = x0 - i1 + C.xxx;\n\tvec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y\n\tvec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y\n\ti = mod289(i);\n\tvec4 p = permute(permute(permute(\n\t\t\t\t\t\ti.z + vec4(0.0, i1.z, i2.z, 1.0))\n\t\t\t\t\t\t+ i.y + vec4(0.0, i1.y, i2.y, 1.0))\n\t\t\t\t\t\t+ i.x + vec4(0.0, i1.x, i2.x, 1.0));\n\tfloat n_ = 0.142857142857; // 1.0/7.0\n\tvec3 ns = n_ * D.wyz - D.xzx;\n\tvec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p, 7 * 7)\n\tvec4 x_ = floor(j * ns.z);\n\tvec4 y_ = floor(j - 7.0 * x_); // mod(j, N)\n\tvec4 x = x_ * ns.x + ns.yyyy;\n\tvec4 y = y_ * ns.x + ns.yyyy;\n\tvec4 h = 1.0 - abs(x) - abs(y);\n\tvec4 b0 = vec4(x.xy, y.xy);\n\tvec4 b1 = vec4(x.zw, y.zw);\n\t//vec4 s0 = vec4(lessThan(b0, 0.0)) * 2.0 - 1.0;\n\t//vec4 s1 = vec4(lessThan(b1, 0.0)) * 2.0 - 1.0;\n\tvec4 s0 = floor(b0) * 2.0 + 1.0;\n\tvec4 s1 = floor(b1) * 2.0 + 1.0;\n\tvec4 sh = -step(h, vec4(0.0));\n\tvec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy ;\n\tvec4 a1 = b1.xzyw + s1.xzyw * sh.zzww ;\n\tvec3 p0 = vec3(a0.xy, h.x);\n\tvec3 p1 = vec3(a0.zw, h.y);\n\tvec3 p2 = vec3(a1.xy, h.z);\n\tvec3 p3 = vec3(a1.zw, h.w);\n\tvec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n\tp0 *= norm.x;\n\tp1 *= norm.y;\n\tp2 *= norm.z;\n\tp3 *= norm.w;\n\tvec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n\tm = m * m;\n\treturn 42.0 * dot(m*m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\n#endif\n",J.util.shader.snoise4d="#ifndef NOISE4D\n#define NOISE4D\nvec4 grad4(float j, vec4 ip)\n\t{\n\tconst vec4 ones = vec4(1.0, 1.0, 1.0, -1.0);\n\tvec4 p, s;\n\n\tp.xyz = floor(fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0;\n\tp.w = 1.5 - dot(abs(p.xyz), ones.xyz);\n\ts = vec4(lessThan(p, vec4(0.0)));\n\tp.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www;\n\n\treturn p;\n\t}\n\n#define F4 0.309016994374947451\n\nfloat snoise(vec4 v)\n\t{\n\tconst vec4 C = vec4(0.138196601125011, // (5 - sqrt(5))/20 G4\n\t\t\t\t\t\t0.276393202250021, // 2 * G4\n\t\t\t\t\t\t0.414589803375032, // 3 * G4\n\t\t\t\t\t\t-0.447213595499958); // -1 + 4 * G4\n\n\tvec4 i = floor(v + dot(v, vec4(F4)));\n\tvec4 x0 = v - i + dot(i, C.xxxx);\n\n\n\tvec4 i0;\n\tvec3 isX = step(x0.yzw, x0.xxx);\n\tvec3 isYZ = step(x0.zww, x0.yyz);\n\ti0.x = isX.x + isX.y + isX.z;\n\ti0.yzw = 1.0 - isX;\n\ti0.y += isYZ.x + isYZ.y;\n\ti0.zw += 1.0 - isYZ.xy;\n\ti0.z += isYZ.z;\n\ti0.w += 1.0 - isYZ.z;\n\n\tvec4 i3 = clamp(i0, 0.0, 1.0);\n\tvec4 i2 = clamp(i0 - 1.0, 0.0, 1.0);\n\tvec4 i1 = clamp(i0 - 2.0, 0.0, 1.0);\n\n\tvec4 x1 = x0 - i1 + C.xxxx;\n\tvec4 x2 = x0 - i2 + C.yyyy;\n\tvec4 x3 = x0 - i3 + C.zzzz;\n\tvec4 x4 = x0 + C.wwww;\n\n\ti = mod289(i);\n\tfloat j0 = permute(permute(permute(permute(i.w) + i.z) + i.y) + i.x);\n\tvec4 j1 = permute(permute(permute(permute (\n\t\t\t\t\ti.w + vec4(i1.w, i2.w, i3.w, 1.0))\n\t\t\t\t\t+ i.z + vec4(i1.z, i2.z, i3.z, 1.0))\n\t\t\t\t\t+ i.y + vec4(i1.y, i2.y, i3.y, 1.0))\n\t\t\t\t\t+ i.x + vec4(i1.x, i2.x, i3.x, 1.0));\n\n\tvec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ;\n\n\tvec4 p0 = grad4(j0, ip);\n\tvec4 p1 = grad4(j1.x, ip);\n\tvec4 p2 = grad4(j1.y, ip);\n\tvec4 p3 = grad4(j1.z, ip);\n\tvec4 p4 = grad4(j1.w, ip);\n\n\tvec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n\tp0 *= norm.x;\n\tp1 *= norm.y;\n\tp2 *= norm.z;\n\tp3 *= norm.w;\n\tp4 *= taylorInvSqrt(dot(p4, p4));\n\n\tvec3 m0 = max(0.6 - vec3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0);\n\tvec2 m1 = max(0.6 - vec2(dot(x3, x3), dot(x4, x4)), 0.0);\n\tm0 = m0 * m0;\n\tm1 = m1 * m1;\n\treturn 49.0 * (dot(m0*m0, vec3(dot(p0, x0), dot(p1, x1), dot(p2, x2)))\n\t\t\t\t\t\t\t+ dot(m1*m1, vec2(dot(p3, x3), dot(p4, x4)))) ;\n}\n#endif\n",J}(e),e.Seriously||(e.Seriously=i),t.exports=i;var s=n.__module.exports;exports.seriouslyExports=s;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("../../../_virtual/_rollupPluginBabelHelpers.js"),e=require("lodash/isString"),t=require("lodash/isObject"),n=require("lodash/cloneDeep"),a=function(){function a(){r.classCallCheck(this,a)}return r.createClass(a,null,[{key:"isJsonStr",value:function(r){if(e(r))try{var n=JSON.parse(r);return!!t(n)}catch(r){return!1}return!1}},{key:"parse",value:function(r){var e={};try{e=JSON.parse(r||"{}")}catch(e){console.error("JSON.parse Error:",r)}return e||{}}},{key:"stringify",value:function(r){var e="";try{e=JSON.stringify(r||{})}catch(e){console.error("JSON.stringify error:",r)}return e||"{}"}},{key:"getParseValue",value:function(r){try{return r&&e(r)?a.parse(r):r}catch(e){return console.info("JSON parse error",r),r}}},{key:"parseObj",value:function(r,e){var t=n(r);return e.forEach((function(e){if(Object.keys(r).includes(e))try{t[e]=a.parse(r[e]),console.log(e,t[e])}catch(r){console.error('Failed to parse JSON for key "'.concat(e,'":'),r)}})),t}},{key:"stringifyObj",value:function(r,e){var t=n(r);return e.forEach((function(e){Object.keys(r).includes(e)&&(t[e]=a.stringify(r[e]))})),t}}]),a}();exports.default=a;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("../../../_virtual/_rollupPluginBabelHelpers.js");exports.waitForLoading=function(r,n,t){return Promise.race([new Promise((function(e){if(r())var n=setInterval((function(){r()||(clearInterval(n),e())}),t||100);else e()}))].concat(e.toConsumableArray(n?[new Promise((function(e,r){setTimeout((function(){r(new Error("overtime"))}),n)}))]:[])))};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("../../../node_modules/worker-timers/build/es2019/module.js"),t=require("./interface.js"),s=require("./utils.js");const n=10,o=5e3;exports.DEFAULT_RECONNECT_ATTEMPTS=n,exports.DEFAULT_RECONNECT_DELAY=o,exports.createWebSocket=function(r,i={}){let a=r,c=0,h=0,d=0,l=!1,u=i?.reopenDelay??o,p=!0,E=!1,v=0;const y=new Set,S=new Set,g=new Set;function f(){l=!1,c=0,p=!0,u=i?.reopenDelay??o}function R(t){const{reopen:s=!0,reopenAttempts:o=n,reopenDelayIncrease:r,onReopenAttemptEnd:a}=i;if(c>=o||!s)return f(),p&&h&&e.clearTimeout(h),void("function"==typeof a&&a(p));u="function"==typeof r?r({reopenCount:c,preDelay:u,isServerClosed:p}):u,d=e.setTimeout((()=>{l=!0,t.open(),c++}),u)}const m={socket:null,messages:[],get readyState(){return this.socket?this.socket.readyState:t.ReadyState.UNINSTANTIATED},get isOpened(){return t.ReadyState.OPEN===this.readyState},get isActive(){return t.ReadyState.CONNECTING===this.readyState||t.ReadyState.OPEN===this.readyState},open(){if(this.isActive)return this;d&&!l&&e.clearTimeout(d);const t=this.socket=new WebSocket(a,i?.protocols);return this._dispchReadyStateChangeEvent(),t.addEventListener("open",this._dispchReadyStateChangeEvent),t.addEventListener("close",this._dispchReadyStateChangeEvent),t.addEventListener("error",this._dispchReadyStateChangeEvent),t.onopen=s=>{const{onOpen:n,onMessage:r,combine:a,reopenDelay:c=o}=i;l&&(p?(h&&e.clearTimeout(h),h=e.setTimeout(f,c>1e3?c+100:1e3)):f()),n&&n(s),t.onmessage=e=>{r&&r(e);const t=this.deserialization(e.data);a&&y.forEach((e=>{a(e.requestData,t)&&(e.then?(e.then(t),y.delete(e)):e.on?e.on(t):e.responseData=t)})),S.forEach((e=>e(t)))},this.messages.flush(),this._ping()},t.onerror=e=>{i.onError&&i.onError(e),p=!1,R(this)},t.onclose=s=>{s.isInterruptWithNewUrl=E,E=!1,v&&e.clearTimeout(v);const{reopenWhenServerClosed:n=!0,onClose:o,onServerClose:r}=i;p&&r&&r(s),o&&o(s),this._dispose(t),p&&n&&R(this)},this},openWithNewUrl(e){return e&&this.isActive&&e===a?this:(a=e||a,t.ReadyState.CONNECTING===this.readyState?(this._dispose(),this.socket?.close()):this.isActive&&this.close(t.CloseEventCode.CLOSE_INTERRUPT_WITH_NEW_URL,"interrupt by new url"),this.open())},close(e=1e3,s){return this.socket?new Promise((n=>{p=!1,t.CloseEventCode.CLOSE_INTERRUPT_WITH_NEW_URL===e&&(E=!0);const o=()=>{this.socket?.removeEventListener("close",o),this._dispose(this.socket),n()};this.socket?.addEventListener("close",o),this.socket?.close(e,s),this._dispchReadyStateChangeEvent()})):Promise.resolve()},connect(){return this.open()},disconnect(e,t){return this.close(e,t)},send(e){const{socket:n}=this;if(!n)return this;if(t.ReadyState.CONNECTING===n.readyState)return this.messages.push(e),this;e instanceof Function&&(e=e(s.createRequestId()));const o=this.serialization(e);return n.send(o),this},request(e){if(!i?.combine)throw new Error("Request failed! unconfigured combine, this configuration is required to use the request api.");e instanceof Function&&(e=e(s.createRequestId())),this.send(e);const t={requestData:e,responseData:null};return y.add(t),{then(e){if(t.on&&console.warn('You have already registered for the "on" callback.'),t.responseData){const s=e(t.responseData);return s instanceof Promise?s:Promise.resolve(s)}return new Promise((e=>{t.then=t=>e(t)})).then((t=>e(t)))},on(e,s=!0){t.then&&console.warn('You have already registered for the "then" callback.'),t.on=s=>{e(s,(()=>{y.delete(t)}))},t.responseData&&s&&t.on(t.responseData)}}},receive(){return new Promise((e=>{const t=this.onReceive((s=>{t(),e(s)}))}))},onReceive:e=>(S.add(e),()=>{S.delete(e)}),onMessage(e){return this.onReceive(e)},_dispchReadyStateChangeEvent(){g.forEach((e=>e(this.readyState)))},_dispose(e){(e=e??this.socket)&&(e.removeEventListener("open",this._dispchReadyStateChangeEvent),e.removeEventListener("close",this._dispchReadyStateChangeEvent),e.removeEventListener("error",this._dispchReadyStateChangeEvent),e.onopen=null,e.onclose=null,e.onerror=null)},_ping(){const{keepAlive:t="none"}=i;v&&e.clearTimeout(v),"none"!==t&&this.isOpened&&(v=e.setTimeout((()=>{if(!this.isOpened)return;const e=i?.getKeepAliveMessage?i?.getKeepAliveMessage(s.createRequestId()):{requestId:s.createRequestId(),action:"heartbeat"===t?"HEART_BEAT":"PING"};"heartbeat"===i.keepAlive?(this.send(e),this._ping()):this.request(e).then((()=>{this._ping()})).catch((e=>{console.error(e)}))}),i?.keepAliveDelay||3e3))},onReadyStateChange:e=>(g.add(e),()=>{g.delete(e)}),serialization:e=>"[object Object]"===Object.prototype.toString.call(e)||Array.isArray(e)||"number"==typeof e?JSON.stringify(e):e,deserialization(e){if("string"==typeof e){let t=e;try{t=JSON.parse(e)}catch(s){t=e}return t}return e}};return m.messages.flush=function(){const e=[...this];if(this.length=0,e.length)for(const t of e)m.send(t)},m};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e,N;exports.ReadyState=void 0,(e=exports.ReadyState||(exports.ReadyState={}))[e.UNINSTANTIATED=-1]="UNINSTANTIATED",e[e.CONNECTING=0]="CONNECTING",e[e.OPEN=1]="OPEN",e[e.CLOSING=2]="CLOSING",e[e.CLOSED=3]="CLOSED",exports.CloseEventCode=void 0,(N=exports.CloseEventCode||(exports.CloseEventCode={}))[N.CLOSE_INTERRUPT_WITH_NEW_URL=4e3]="CLOSE_INTERRUPT_WITH_NEW_URL";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("uuid");exports.createRequestId=function(){return e.v4()};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function r(t){return r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(r){return typeof r}:function(r){return r&&"function"==typeof Symbol&&r.constructor===Symbol&&r!==Symbol.prototype?"symbol":typeof r},r(t)}function t(r,t){if(!(r instanceof t))throw new TypeError("Cannot call a class as a function")}function e(r,t){for(var e=0;e<t.length;e++){var o=t[e];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(r,c(o.key),o)}}function o(r,t,o){return t&&e(r.prototype,t),o&&e(r,o),Object.defineProperty(r,"prototype",{writable:!1}),r}function n(r){return a(r)||i(r)||u(r)||y()}function a(r){if(Array.isArray(r))return l(r)}function i(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r)}function u(r,t){if(r){if("string"==typeof r)return l(r,t);var e=Object.prototype.toString.call(r).slice(8,-1);return"Object"===e&&r.constructor&&(e=r.constructor.name),"Map"===e||"Set"===e?Array.from(r):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?l(r,t):void 0}}function l(r,t){(null==t||t>r.length)&&(t=r.length);for(var e=0,o=new Array(t);e<t;e++)o[e]=r[e];return o}function y(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function f(r,t){if("object"!=typeof r||null===r)return r;var e=r[Symbol.toPrimitive];if(void 0!==e){var o=e.call(r,t||"default");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(r)}function c(r){var t=f(r,"string");return"symbol"==typeof t?t:String(t)}export{l as arrayLikeToArray,a as arrayWithoutHoles,t as classCallCheck,o as createClass,i as iterableToArray,y as nonIterableSpread,n as toConsumableArray,f as toPrimitive,c as toPropertyKey,r as typeof,u as unsupportedIterableToArray};
|
package/es/_virtual/seriously.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var e={exports:{}};export{e as __module};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e from"lodash/isEmpty";import t from"lodash/isNumber";import{waitForLoading as s}from"../../wait-for-loading/es/index.js";import"./libs/seriously.js";import"./libs/seriously.chroma.js";import"./libs/seriously.chroma_obs.js";import"./libs/seriously.chroma_post.js";class i{seriously;version;defaultOptions={screen:[0,255,0,0]};targetElement;sourceElement;source=null;target=null;effect=null;backEffect=null;constructor(e,t,s,i=0){this.seriously=new window.Seriously,this.version=i,this.targetElement="string"==typeof e?document.getElementById(e):e,this.sourceElement="string"==typeof t?document.getElementById(t):t,this.init(s)}async loadEffect(e){return 1===e?"chroma":"chroma_obs"}async init(e){console.info("serious version:",this.version);const t=await this.loadEffect(this.version);await s((()=>!(this.sourceElement?.videoWidth>0&&this.sourceElement?.videoHeight>0))),this.targetElement.width=this.sourceElement.videoWidth,this.targetElement.height=this.sourceElement.videoHeight,this.source=this.seriously.source(this.sourceElement),this.target=this.seriously.target(this.targetElement),this.effect=this.seriously.effect(t),this.backEffect=this.seriously.effect("chroma_post"),this.effect.source=this.source,this.backEffect.source=this.effect,this.target.source=this.backEffect,this.seriously.go(),this.setOptions(this.defaultOptions),e&&this.setOptions(e)}destroy(){this.seriously.destroy()}async updateSource(e){e&&this.effect&&this.backEffect?(this.sourceElement="string"==typeof e?document.getElementById(e):e,await s((()=>!(this.sourceElement?.videoWidth>0&&this.sourceElement?.videoHeight>0))),this.source?.destroy(),console.info("update source: ",this.source?.isDestroyed()),this.source=this.seriously.source(this.sourceElement),this.effect.source=this.source,this.backEffect.source=this.effect,this.target.source=this.backEffect):console.warn("update source error: source or effect is null",e,this.effect)}async setOptions(s){if(this.defaultOptions={...this.defaultOptions,...s},!this.effect||!this.backEffect||e(s))return;console.info("set options: ",s);const{screen:i,edgeShrink:o}=s;if(i&&i.length>=3){const[e,s,o,r]=i;this.effect.screen=[e/255,s/255,o/255,t(r)?r:1]}o&&(this.backEffect.edgeShrink=o);for(const[e,t]of Object.entries(s))"number"==typeof t&&"screen"!==e&&"edgeShrink"!==e&&(this.effect[e]=t)}}export{i as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as e}from"./seriously.js";window,console.info("seriously version: chroma"),e.plugin("chroma",{shader:function(e,o){return o.vertex=["precision mediump float;","attribute vec4 position;","attribute vec2 texCoord;","uniform vec2 resolution;","uniform mat4 transform;","varying vec2 vTexCoord;","uniform vec4 screen;","uniform float balance;","varying float screenSat;","varying vec3 screenPrimary;","void main(void) {","\tfloat fmin = min(min(screen.r, screen.g), screen.b);","\tfloat fmax = max(max(screen.r, screen.g), screen.b);","\tfloat secondaryComponents;","\tscreenPrimary = step(fmax, screen.rgb);","\tsecondaryComponents = dot(1.0 - screenPrimary, screen.rgb);","\tscreenSat = fmax - mix(secondaryComponents - fmin, secondaryComponents / 2.0, balance);","\tvec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);","\tscreenPosition = transform * screenPosition;","\tgl_Position = screenPosition;","\tgl_Position.xy = screenPosition.xy * 2.0 / resolution;","\tgl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);","\tvTexCoord = texCoord;","}"].join("\n"),o.fragment=[this.inputs.mask?"#define MASK":"","precision mediump float;","varying vec2 vTexCoord;","uniform sampler2D source;","uniform vec4 screen;","uniform float screenWeight;","uniform float balance;","uniform float clipBlack;","uniform float clipWhite;","uniform bool mask;","varying float screenSat;","varying vec3 screenPrimary;","void main(void) {","\tfloat pixelSat, secondaryComponents;","\tvec4 sourcePixel = texture2D(source, vTexCoord);","\n\t\t\t\t\tif (screen.a == 0.0) {\n\t\t\t\t\t\tgl_FragColor = sourcePixel;\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t","\tfloat fmin = min(min(sourcePixel.r, sourcePixel.g), sourcePixel.b);","\tfloat fmax = max(max(sourcePixel.r, sourcePixel.g), sourcePixel.b);","\tvec3 pixelPrimary = step(fmax, sourcePixel.rgb);","\tsecondaryComponents = dot(1.0 - pixelPrimary, sourcePixel.rgb);","\tpixelSat = fmax - mix(secondaryComponents - fmin, secondaryComponents / 2.0, balance);","\tfloat diffPrimary = dot(abs(pixelPrimary - screenPrimary), vec3(1.0));","\tfloat solid = step(1.0, step(pixelSat, 0.1) + step(fmax, 0.1) + diffPrimary);","\tfloat alpha = max(0.0, 1.0 - pixelSat / screenSat);","\talpha = smoothstep(clipBlack, clipWhite, alpha);","\tvec4 semiTransparentPixel = vec4((sourcePixel.rgb - (1.0 - alpha) * screen.rgb * screenWeight) / max(0.00001, alpha), alpha);","\tvec4 pixel = mix(semiTransparentPixel, sourcePixel, solid);","#ifdef MASK","\tgl_FragColor = vec4(vec3(pixel.a), 1.0);","#else","\tgl_FragColor = pixel;","#endif","}"].join("\n"),o},inPlace:!0,inputs:{source:{type:"image",uniform:"source"},screen:{type:"color",uniform:"screen",defaultValue:[66/255,195/255,31/255,1]},weight:{type:"number",uniform:"screenWeight",defaultValue:1,min:0},balance:{type:"number",uniform:"balance",defaultValue:1,min:0,max:1},clipBlack:{type:"number",uniform:"clipBlack",defaultValue:0,min:0,max:1},clipWhite:{type:"number",uniform:"clipWhite",defaultValue:1,min:0,max:1},mask:{type:"boolean",defaultValue:!1,uniform:"mask",shaderDirty:!0}},title:"Chroma Key",description:""});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as e}from"./seriously.js";window,console.info("seriously version: chroma_obs"),e.plugin("chroma_obs",{shader:function(e,t){return t.vertex=["precision mediump float;","attribute vec4 position;","attribute vec2 texCoord;","uniform vec2 resolution;","uniform mat4 transform;","varying vec2 vTexCoord;","const vec4 cb_v4 = vec4(-0.100644, -0.338572, 0.439216, 0.501961);","const vec4 cr_v4 = vec4(0.439216, -0.398942, -0.040274, 0.501961);","uniform vec4 screen;","uniform float similarity;","uniform float smoothness;","uniform float spill;","uniform float contrast;","uniform float gamma;","varying vec2 chroma_key;","varying vec2 pixel_size;","varying float similarity_v;","varying float smoothness_v;","varying float spill_v;","varying float contrast_v;","varying float gamma_v;","void main(void) {","\tfloat cb = dot(screen.rgb, cb_v4.xyz) + cb_v4.w;","\tfloat cr = dot(screen.rgb, cr_v4.xyz) + cr_v4.w;","\tchroma_key.x = cb;","\tchroma_key.y = cr;","\tpixel_size.x = 1.0 / resolution.x;","\tpixel_size.y = 1.0 / resolution.y;","\tsimilarity_v = similarity * 1.0 / 1000.0;","\tsmoothness_v = smoothness * 1.0 / 1000.0;","\tspill_v = spill * 1.0 / 1000.0;","\tcontrast_v = (contrast < 0.0) ? (1.0 / (-contrast + 1.0)) : (contrast + 1.0);","\tgamma_v = (gamma < 0.0) ? (-gamma + 1.0) : (1.0 / (gamma + 1.0));","\tvec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);","\tscreenPosition = transform * screenPosition;","\tgl_Position = screenPosition;","\tgl_Position.xy = screenPosition.xy * 2.0 / resolution;","\tgl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);","\tvTexCoord = texCoord;","}"].join("\n"),t.fragment=[this.inputs.mask?"#define MASK":"","precision mediump float;","varying vec2 vTexCoord;","uniform bool mask;","uniform vec4 screen;","uniform sampler2D source;","const vec4 cb_v4 = vec4(-0.100644, -0.338572, 0.439216, 0.501961);","const vec4 cr_v4 = vec4(0.439216, -0.398942, -0.040274, 0.501961);","uniform float opacity;","uniform float brightness;","varying vec2 chroma_key;","varying vec2 pixel_size;","varying float similarity_v;","varying float smoothness_v;","varying float spill_v;","varying float contrast_v;","varying float gamma_v;","vec4 CalcColor(vec4 rgba) {","\treturn vec4(pow(rgba.rgb, vec3(gamma_v, gamma_v, gamma_v)) * contrast_v + brightness, rgba.a);","}","float GetChromaDist(vec3 rgb) {","\tfloat cb = dot(rgb.rgb, cb_v4.xyz) + cb_v4.w;","\tfloat cr = dot(rgb.rgb, cr_v4.xyz) + cr_v4.w;","\treturn distance(chroma_key, vec2(cb, cr));","}","float GetNonlinearChannel(float u) {","\treturn u;","}","vec3 GetNonlinearColor(vec3 rgb)","{","\treturn vec3(GetNonlinearChannel(rgb.r), GetNonlinearChannel(rgb.g), GetNonlinearChannel(rgb.b));","}","vec3 SampleTexture(vec2 uv)","{","\tvec3 rgb = texture2D(source, uv).rgb;","\treturn GetNonlinearColor(rgb);","}","float GetBoxFilteredChromaDist(vec3 rgb, vec2 texCoord) {","\tvec2 h_pixel_size = pixel_size / 2.0;","\tvec2 point_0 = vec2(pixel_size.x, h_pixel_size.y);","\tvec2 point_1 = vec2(h_pixel_size.x, -pixel_size.y);","\tfloat distVal = GetChromaDist(SampleTexture(texCoord-point_0));","\tdistVal += GetChromaDist(SampleTexture(texCoord+point_0));","\tdistVal += GetChromaDist(SampleTexture(texCoord-point_1));","\tdistVal += GetChromaDist(SampleTexture(texCoord+point_1));","\tdistVal *= 2.0;","\tdistVal += GetChromaDist(GetNonlinearColor(rgb));","\treturn distVal / 9.0;","}","vec4 ProcessChromaKey(vec4 rgba, vec2 uv)","{","\tfloat chromaDist = GetBoxFilteredChromaDist(rgba.rgb, uv);","\tfloat baseMask = chromaDist - similarity_v;","\tfloat fullMask = pow(clamp(baseMask / smoothness_v, 0.0, 1.0), 1.5);","\tfloat spillVal = pow(clamp(baseMask / spill_v, 0.0, 1.0), 1.5);","\trgba.a *= opacity;","\trgba.a *= fullMask;","\tfloat desat = dot(rgba.rgb, vec3(0.2126, 0.7152, 0.0722));","\trgba.rgb = mix(vec3(desat, desat, desat), rgba.rgb, spillVal);","\treturn CalcColor(rgba);","}","void main(void) {","\tvec4 rgba = texture2D(source, vTexCoord);","\n \tif (screen.w == 0.0) {\n \t\tgl_FragColor = rgba;\n \t\treturn;\n \t}\n ","\trgba.rgb *= (rgba.a > 0.) ? (1. / rgba.a) : 0.;","\trgba = ProcessChromaKey(rgba, vTexCoord);","\trgba.rgb *= rgba.a;","#ifdef MASK","\tgl_FragColor = vec4(vec3(rgba.a), 1.0);","#else","\tgl_FragColor = rgba;","#endif","}"].join("\n"),t},inPlace:!0,inputs:{source:{type:"image",uniform:"source"},screen:{type:"color",uniform:"screen",defaultValue:[0,1,0,1]},similarity:{type:"number",uniform:"similarity",defaultValue:400,min:1,max:1e3},smoothness:{type:"number",uniform:"smoothness",defaultValue:80,min:1,max:1e3},opacity:{type:"number",uniform:"opacity",defaultValue:1,min:0,max:1},contrast:{type:"number",uniform:"contrast",defaultValue:0,min:-4,max:4},brightness:{type:"number",uniform:"brightness",defaultValue:0,min:-1,max:1},gamma:{type:"number",uniform:"gamma",defaultValue:0,min:-1,max:1},spill:{type:"number",uniform:"spill",defaultValue:100,min:1,max:1e3},mask:{type:"boolean",defaultValue:!1,uniform:"mask",shaderDirty:!0}},title:"Chroma Key OBS",description:""});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{s as e}from"./seriously.js";window,console.info("seriously version: chroma_post"),e.plugin("chroma_post",{shader:function(e,o){return o.vertex=["precision mediump float;","attribute vec4 position;","attribute vec2 texCoord;","uniform vec2 resolution;","uniform mat4 transform;","varying vec2 vTexCoord;","varying vec2 pixel_size;","void main(void) {","\tpixel_size.x = 1.0 / resolution.x;","\tpixel_size.y = 1.0 / resolution.y;","\tvec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);","\tscreenPosition = transform * screenPosition;","\tgl_Position = screenPosition;","\tgl_Position.xy = screenPosition.xy * 2.0 / resolution;","\tgl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);","\tvTexCoord = texCoord;","}"].join("\n"),o.fragment=[this.inputs.mask?"#define MASK":"","precision mediump float;","varying vec2 vTexCoord;","uniform bool mask;","uniform sampler2D source;","uniform float edgeShrink;","varying vec2 pixel_size;","const int filter_size = 3;","float edgeSmoothSuppKernelV2(vec4 rgba, vec2 coord) {"," float alpha = rgba.a;"," if (edgeShrink > 1.0) {"," float sum = 0.0;"," float weightSum = 0.0;"," // float sigma = 1.0f;"," for (int j = - filter_size / 2; j <= filter_size / 2; j++) {"," \t for (int i = - filter_size / 2; i <= filter_size / 2; i++) {"," \t\t // float weight = exp(-(i*i + j*j) / (2 * sigma * sigma)) / (2 * 3.1415926f * sigma * sigma);"," \t\t float weight = 1.0;"," vec4 neighborColor = texture2D(source, coord + vec2(i, j) * pixel_size);"," \t\t // speedup: move the powf to chroma_key"," \t\t float alpha_ker = pow(neighborColor.w, edgeShrink);"," \t\t sum += (alpha_ker * weight);"," \t\t weightSum += weight;"," \t }"," }"," alpha = sum * 1.0 / weightSum;"," }"," return alpha;","}","void main(void) {","\tvec4 rgba = texture2D(source, vTexCoord);","\trgba.a = edgeSmoothSuppKernelV2(rgba, vTexCoord);","\trgba.a = pow(rgba.a, edgeShrink);","#ifdef MASK","\tgl_FragColor = vec4(vec3(rgba.a), 1.0);","#else","\tgl_FragColor = rgba;","#endif","}"].join("\n"),o},inPlace:!0,inputs:{source:{type:"image",uniform:"source"},edgeShrink:{type:"number",uniform:"edgeShrink",defaultValue:3,min:1,max:10},mask:{type:"boolean",defaultValue:!1,uniform:"mask",shaderDirty:!0}},title:"Chroma Key Post",description:""});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{typeof as t}from"../../../../_virtual/_rollupPluginBabelHelpers.js";import{__module as e}from"../../../../_virtual/seriously.js";var i,r,n;i=e,r=window,n=function(e){var i,r,n,s,o,a,u,h,f=e.document,c=e.console,l={},d={},p={},m={},y=[],g={},v={},x={canvas:[],image:[],video:[]},E={},b=e.WeakMap&&new WeakMap,T=0,w=function(){},R={transparent:[0,0,0,0],black:[0,0,0,1],red:[1,0,0,1],green:[0,128/255,0,1],blue:[0,0,1,1],white:[1,1,1,1],silver:[192/255,192/255,192/255,1],gray:[128/255,128/255,128/255,1],maroon:[128/255,0,0,1],purple:[128/255,0,128/255,1],fuchsia:[1,0,1,1],lime:[0,1,0,1],olive:[128/255,128/255,0,1],yellow:[1,1,0,1],navy:[0,0,128/255,1],teal:[0,128/255,128/255,1],aqua:[0,1,1,1],orange:[1,165/255,0,1]},D=/^(rgb|hsl)a?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*(\d+(\.\d*)?)\s*)?\)/i,A=/^#(([0-9a-fA-F]{3,8}))/,_=["x","y","z","w"],N=["r","g","b","a"],P={srcRGB:770,dstRGB:771,srcAlpha:1,dstAlpha:771},F=["MAX_COMBINED_TEXTURE_IMAGE_UNITS","MAX_FRAGMENT_UNIFORM_VECTORS","MAX_TEXTURE_IMAGE_UNITS","MAX_VARYING_VECTORS","MAX_VERTEX_ATTRIBS","MAX_VERTEX_TEXTURE_IMAGE_UNITS","MAX_VERTEX_UNIFORM_VECTORS"],O=/^[\t ]*#define[\t ]+SHADER_NAME\s+([^$\n\r]+)/i,U={frustum:function(t,e,i,r,n,s,o){o||(o=U.create());var a=e-t,u=r-i,h=s-n;return o[0]=2*n/a,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2*n/u,o[6]=0,o[7]=0,o[8]=(e+t)/a,o[9]=(r+i)/u,o[10]=-(s+n)/h,o[11]=-1,o[12]=0,o[13]=0,o[14]=-s*n*2/h,o[15]=0,o},perspective:function(t,e,i,r,n){var s=i*Math.tan(t*Math.PI/360),o=s*e;return U.frustum(-o,o,-s,s,i,r,n)},multiply:function(t,e,i){var r=e[0],n=e[1],s=e[2],o=e[3],a=e[4],u=e[5],h=e[6],f=e[7],c=e[8],l=e[9],d=e[10],p=e[11],m=e[12],y=e[13],g=e[14],v=e[15],x=i[0],E=i[1],b=i[2],T=i[3];return t[0]=x*r+E*a+b*c+T*m,t[1]=x*n+E*u+b*l+T*y,t[2]=x*s+E*h+b*d+T*g,t[3]=x*o+E*f+b*p+T*v,x=i[4],E=i[5],b=i[6],T=i[7],t[4]=x*r+E*a+b*c+T*m,t[5]=x*n+E*u+b*l+T*y,t[6]=x*s+E*h+b*d+T*g,t[7]=x*o+E*f+b*p+T*v,x=i[8],E=i[9],b=i[10],T=i[11],t[8]=x*r+E*a+b*c+T*m,t[9]=x*n+E*u+b*l+T*y,t[10]=x*s+E*h+b*d+T*g,t[11]=x*o+E*f+b*p+T*v,x=i[12],E=i[13],b=i[14],T=i[15],t[12]=x*r+E*a+b*c+T*m,t[13]=x*n+E*u+b*l+T*y,t[14]=x*s+E*h+b*d+T*g,t[15]=x*o+E*f+b*p+T*v,t},identity:function(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t},copy:function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}},B=(h=0,e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame||function(t){var i,r,n;function s(){t(i+r)}return i=(new Date).getTime(),r=Math.max(0,16-(i-h)),n=e.setTimeout(s,r),h=i+r,n}),L=e.cancelAnimationFrame||e.webkitCancelAnimationFrame||e.mozCancelAnimationFrame||e.oCancelAnimationFrame||e.msCancelAnimationFrame||function(t){e.cancelTimeout(t)},S=["alias","destroy","effect","id","initialize","inputs","isDestroyed","isReady","matte","off","on","readPixels","render","title","update"],I=["alias","destroy","id","inputs","isDestroyed","isReady","off","on","source","title","update"],C=["aliases","defaults","destroy","effect","go","id","incompatible","isDestroyed","isEffect","isNode","isSource","isTarget","isTransform","removeAlias","render","source","stop","target","transform"];function M(t,e){var i,r;if("string"==typeof t)i=f.querySelector(t);else if(!t)return!1;return t.tagName&&(i=t),i?(r=i.tagName.toLowerCase(),e&&e.indexOf(r)<0?t:i):t}function z(t,e){var i,r;for(i in t.prototype&&e.prototype&&t.prototype!==e.prototype&&z(t.prototype,e.prototype),e)e.hasOwnProperty(i)&&((r=Object.getOwnPropertyDescriptor(e,i)).get||r.set?Object.defineProperty(t,i,{configurable:!0,enumerable:!0,get:r.get,set:r.set}):t[i]=e[i]);return t}function G(t){var e;if(!c)return w;if("function"==typeof c[t])e=c[t];else{if("function"!=typeof c.log)return w;e=c.log}return e.bind?e.bind(c):function(){e.apply(c,arguments)}}function k(i,r){if(r||(r="HTMLElement"),!e[r])return c.error("window[proto] is undefined, proto:",r),!1;if(i instanceof e[r])return!0;if(!i||"object"!==t(i))return!1;for(;i;)if((i=Object.getPrototypeOf(i))&&i.constructor.name===r)return!0;return!1}function X(t,e,i,r,n){function s(t,e,i){return(i%=1)<0&&(i+=1),i<1/6?t+(e-t)*i*6:i<.5?e:i<2/3?t+(e-t)*(2/3-i)*6:t}var o,a;return o=2*i-(a=i<.5?i*(e+1):i+e-i*e),n||(n=[]),n[0]=s(o,a,t+1/3),n[1]=s(o,a,t),n[2]=s(o,a,t-1/3),n[3]=r,n}function j(t){var e,i,r,n="#",s=t[3]<1?4:3;for(e=0;e<s;e++)r=(i=Math.min(255,Math.round(255*t[e]||0))).toString(16),i<16&&(r="0"+r),n+=r;return n}function W(t){return Array.isArray(t)||t&&t.BYTES_PER_ELEMENT&&"length"in t}function V(t){function i(){y.length&&y.shift()()}if("function"!=typeof t)throw new Error("setTimeoutZero argument is not a function");y.push(t),"file:"!==e.location.protocol?e.postMessage("seriously-timeout-message",e.location):setTimeout(i,0)}function H(t,i){var r;try{r=e.WebGLDebugUtils&&i&&i.debugContext?e.WebGLDebugUtils.makeDebugContext(t.getContext("webgl",i)):t.getContext("webgl",i)}catch(t){}if(!r)try{r=t.getContext("experimental-webgl",i)}catch(t){}return r}function Y(){var t;return i&&i.getError()===i.CONTEXT_LOST_WEBGL&&(i=void 0),i||!e.WebGLRenderingContext||n||(t=f.createElement("canvas"),(i=H(t))?t.addEventListener("webglcontextlost",(function e(r){r.preventDefault(),i&&i.canvas===this&&(i=void 0,t.removeEventListener("webglcontextlost",e,!1))}),!1):J.logger.warn("Unable to access WebGL.")),i}function q(t){var i,r,n,s;if(!(i=M(t,["img","canvas","video"])))return!1;if(!(r=f.createElement("canvas")))return J.logger.warn("Browser does not support canvas or Seriously.js"),!1;if(0===i.naturalWidth&&"IMG"===i.tagName)return J.logger.warn("Image not loaded"),!1;if(0===i.readyState&&0===i.videoWidth&&"VIDEO"===i.tagName)return J.logger.warn("Video not loaded"),!1;if(n=Y()){(s=n.createTexture())||J.logger.error("Test WebGL context has been lost"),n.bindTexture(n.TEXTURE_2D,s);try{n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i)}catch(t){return t.code===e.DOMException.SECURITY_ERR?J.logger.log("Unable to access cross-domain image"):J.logger.error("Error storing image to texture: "+t.message),n.deleteTexture(s),!1}n.deleteTexture(s)}else{n=r.getContext("2d");try{n.drawImage(i,0,0),n.getImageData(0,0,1,1)}catch(t){return t.code===e.DOMException.SECURITY_ERR?J.logger.log("Unable to access cross-domain image"):J.logger.error("Error drawing image to canvas: "+t.message),!1}}return!0}function Z(t){var e,i,r;function n(t,r){var n,s;W(t)?(n=t[0],s=t[1]||n):n=t,"string"==typeof n?n=n.toLowerCase():"number"==typeof n?n=String(n):n||(n=""),i[n]=s,r||(e.firstValue=n)}function s(t){return t}for(r in t.inputs)if(t.inputs.hasOwnProperty(r)){if(t.reserved.indexOf(r)>=0||Object.prototype[r])throw new Error("Reserved input name: "+r);(e=t.inputs[r]).name=r,isNaN(e.min)&&(e.min=-1/0),isNaN(e.max)&&(e.max=1/0),isNaN(e.minCount)&&(e.minCount=-1/0),isNaN(e.maxCount)&&(e.maxCount=1/0),isNaN(e.step)&&(e.step=0),isNaN(e.mod)&&(e.mod=0),"enum"===e.type&&e.options&&W(e.options)&&e.options.length&&(i={},e.options.forEach(n),e.options=i),"vector"===e.type?e.dimensions<2?e.dimensions=2:e.dimensions>4||!e.dimensions||isNaN(e.dimensions)?e.dimensions=4:e.dimensions=Math.round(e.dimensions):e.dimensions=1,e.shaderDirty=!!e.shaderDirty,"function"!=typeof e.validate&&(e.validate=J.inputValidators[e.type]||s),t.defaultImageInput||"image"!==e.type||(t.defaultImageInput=r)}}function K(t,e,i,r){var n,s,o,a,u=!0===r?r:r&&r.useFloat;u=!1,this.type=u?t.FLOAT:t.UNSIGNED_BYTE,n=t.createFramebuffer(),t.bindFramebuffer(t.FRAMEBUFFER,n),r&&r.texture?(this.texture=r.texture,t.bindTexture(t.TEXTURE_2D,this.texture),this.ownTexture=!1):(this.texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.texture),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),this.ownTexture=!0);try{this.type===t.FLOAT?(o=new Float32Array(e*i*4),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.FLOAT,o)):(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.UNSIGNED_BYTE,null),this.type=t.UNSIGNED_BYTE)}catch(r){this.type=t.UNSIGNED_BYTE,o=new Uint8Array(e*i*4),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.UNSIGNED_BYTE,o)}if(s=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,s),t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_COMPONENT16,e,i),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,s),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.texture,0),(a=t.checkFramebufferStatus(t.FRAMEBUFFER))===t.FRAMEBUFFER_INCOMPLETE_ATTACHMENT)throw new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");if(a===t.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)throw new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");if(a===t.FRAMEBUFFER_INCOMPLETE_DIMENSIONS)throw new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");if(a===t.FRAMEBUFFER_UNSUPPORTED)throw new Error("Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED");if(a!==t.FRAMEBUFFER_COMPLETE)throw new Error("Incomplete framebuffer: "+a);t.bindTexture(t.TEXTURE_2D,null),t.bindRenderbuffer(t.RENDERBUFFER,null),t.bindFramebuffer(t.FRAMEBUFFER,null),this.gl=t,this.frameBuffer=n,this.renderBuffer=s,this.width=e,this.height=i}function $(t,e,i){var r,n,s,o,a,u,h,f,c="";function l(e,i){var r,n;if(r=i?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER),t.shaderSource(r,e),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS)){for(e=e.split(/[\n\r]/),n=0;n<e.length;n++)e[n]=n+1+":\t"+e[n];throw e.unshift("Error compiling "+(i?"fragment":"vertex")+" shader:"),J.logger.error(e.join("\n")),new Error("Shader error: "+t.getShaderInfoLog(r))}return r}function d(e,i){if(e.type===t.SAMPLER_2D)return function(r){e.glTexture=t["TEXTURE"+r],t.uniform1i(i,r)};if(e.type===t.BOOL||e.type===t.INT)return e.size>1?function(e){t.uniform1iv(i,e)}:function(e){t.uniform1i(i,e)};if(e.type===t.FLOAT)return e.size>1?function(e){t.uniform1fv(i,e)}:function(e){t.uniform1f(i,e)};if(e.type===t.FLOAT_VEC2)return function(e){t.uniform2f(i,e[0],e[1])};if(e.type===t.FLOAT_VEC3)return function(e){t.uniform3f(i,e[0],e[1],e[2])};if(e.type===t.FLOAT_VEC4)return function(e){t.uniform4f(i,e[0],e[1],e[2],e[3])};if(e.type===t.FLOAT_MAT3)return function(e){t.uniformMatrix3fv(i,!1,e)};if(e.type===t.FLOAT_MAT4)return function(e){t.uniformMatrix4fv(i,!1,e)};throw new Error("Unknown shader uniform type: "+e.type)}function p(e){return function(){return t.getUniform(r,e)}}if(n=l(e),s=l(i,!0),r=t.createProgram(),t.attachShader(r,n),(o=t.getShaderInfoLog(n))&&(c+="Vertex shader error: "+o+"\n"),t.attachShader(r,s),(o=t.getShaderInfoLog(s))&&(c+="Fragment shader error: "+o+"\n"),t.linkProgram(r),!t.getProgramParameter(r,t.LINK_STATUS))throw c+=t.getProgramInfoLog(r),t.deleteProgram(r),t.deleteShader(n),t.deleteShader(s),(h=O.exec(e)||O.exec(i))&&(c="Shader = "+h[1]+"\n"+c),F.forEach((function(e){c+="\n"+e+": "+t.getParameter(t[e])})),new Error("Could not initialize shader:\n"+c);for(t.useProgram(r),this.uniforms={},u=t.getProgramParameter(r,t.ACTIVE_UNIFORMS),a=0;a<u;++a)(f={info:t.getActiveUniform(r,a)}).name=f.info.name.replace(/\[0\]$/,""),f.loc=t.getUniformLocation(r,f.name),f.set=d(f.info,f.loc),f.get=p(f.loc),this.uniforms[f.name]=f,this[f.name]||(this[f.name]=f);for(this.attributes={},this.location={},u=t.getProgramParameter(r,t.ACTIVE_ATTRIBUTES),a=0;a<u;++a)(f={info:t.getActiveAttrib(r,a)}).name=f.info.name,f.location=t.getAttribLocation(r,f.name),this.attributes[f.name]=f,this.location[f.name]=f.location;this.gl=t,this.program=r,this.destroy=function(){var e;for(e in t&&(t.deleteProgram(r),t.deleteShader(n),t.deleteShader(s)),this)this.hasOwnProperty(e)&&delete this[e];r=null,n=null,s=null}}function J(i){if(e===this||!(this instanceof J)||void 0!==this.id)return new J(i);var r,n,o,h,c,y,E,R,D,A,_,N,F,S,I,G=++T,X=this,W=[],Y={},q=0,Q=[],tt=[],et=[],it=[],rt={},nt=[],st=[],ot={},at={},ut=!1,ht=!1,ft=null;function ct(t,e){var i,r,n;return!!e&&(i=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,i),e.bufferData(e.ARRAY_BUFFER,t.vertices,e.STATIC_DRAW),i.size=3,r=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,r),e.bufferData(e.ELEMENT_ARRAY_BUFFER,t.indices,e.STATIC_DRAW),n=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,n),e.bufferData(e.ARRAY_BUFFER,t.coords,e.STATIC_DRAW),n.size=2,{vertex:i,index:r,texCoord:n,length:t.indices.length,mode:t.mode||e.TRIANGLES})}function lt(t){var e={};return e.vertices=new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,1,0]),e.indices=new Uint16Array([0,1,2,0,2,3]),e.coords=new Float32Array([0,0,1,0,1,1,0,1]),ct(e,t)}function dt(){J.logger.warn("WebGL context lost. 5 seconds to restore context."),ft&&clearTimeout(ft),ft=setTimeout(mt,5e3)}function pt(t){var e,i;if(!n)if(t.canvas.addEventListener("webglcontextlost",yt,!1),t.canvas.addEventListener("webglcontextrestored",mt,!1),t.isContextLost())J.logger.warn("Unable to attach lost WebGL context. Will try again when context is restored.");else{for(n=t,r=t.canvas,h=lt(n),c=new $(n,"#define SHADER_NAME seriously.base\n"+a,"#define SHADER_NAME seriously.base\n"+u),e=0;e<it.length;e++)(i=it[e]).gl=n,i.initialize(),i.buildShader();for(e=0;e<Q.length;e++)(i=Q[e]).initialize();for(e=0;e<tt.length;e++)(i=tt[e]).model||(i.model=h,i.shader=c)}}function mt(){var t,e,i,r;if(ft&&clearTimeout(ft),ft=null,o&&!n){if(k(e=o.target,"WebGLFramebuffer"))return void J.logger.error("Unable to restore target built on WebGLFramebuffer");if(t=H(e,{alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!0,stencil:!0,debugContext:o.debugContext})){if(t.isContextLost())return ft?void J.logger.error("restore WebGL Context ing, wait...."):(dt(),void J.logger.error("Unable to restore WebGL Context"));for(pt(t),o.renderToTexture?o.frameBuffer=new K(n,o.width,o.height,!1):o.frameBuffer={frameBuffer:null},i=0;i<W.length;i++)(r=W[i]).setDirty(),r.emit("webglcontextrestored");J.logger.log("WebGL context restored")}}}function yt(t){var e,i;for(t?(t.preventDefault(),dt()):ft&&clearTimeout(ft),I&&(L(I),I=0),r&&r.removeEventListener("webglcontextlost",yt,!1),e=0;e<it.length;e++)(i=it[e]).gl=null,i.initialized=!1,i.baseShader=null,i.model=null,i.frameBuffer=null,i.texture=null,i.shader&&i.shader.destroy&&(i.shader.destroy(),i.effect.commonShader&&delete at[i.hook]),i.shaderDirty=!0,i.shader=null,i.effect.lostContext&&i.effect.lostContext.call(i),t&&i.emit("webglcontextlost");for(e=0;e<Q.length;e++)(i=Q[e]).texture=null,i.initialized=!1,i.allowRefresh=!1,t&&i.emit("webglcontextlost");for(e=0;e<et.length;e++)(i=et[e]).frameBuffer=null,i.texture=null,t&&i.emit("webglcontextlost");for(e=0;e<tt.length;e++)(i=tt[e]).model=!1,i.frameBuffer=null,t&&i.emit("webglcontextlost");c&&c.destroy&&c.destroy(),n&&(n.deleteBuffer(h.vertex),n.deleteBuffer(h.texCoord),n.deleteBuffer(h.index)),h&&(delete h.vertex,delete h.texCoord,delete h.index),h=null,c=null,n=null,r=null}function gt(t){var e,i,r=!1;if(I=0,nt.length)for(r=!0,e=0;e<nt.length;e++)nt[e].call(X,t);if(Q&&Q.length)for(r=!0,e=0;e<Q.length;e++){var n=(i=Q[e]).source&&i.source.dataset&&i.source.dataset.playing;if("string"==typeof n&&"true"!==n)return void(I=B(gt));(i.dirty||i.checkDirty&&i.checkDirty())&&(i.dirty=!1,i.setDirty())}for(e=0;e<tt.length;e++)(i=tt[e]).auto&&i.dirty&&i.render();if(st.length)for(r=!0,e=0;e<st.length;e++)st[e].call(X);r&&!I&&(I=B(gt))}function vt(t,e,i,r,s,o){var a,u,h,f,c,l,d,p,m,y=0,g=s&&s.gl||n;if(g){for(a in s?(f=o&&o.width||s.width||g.canvas.width,c=o&&o.height||s.height||g.canvas.height):(f=o&&o.width||g.canvas.width,c=o&&o.height||g.canvas.height),t.use(),g.viewport(0,0,f,c),g.bindFramebuffer(g.FRAMEBUFFER,r),g.enableVertexAttribArray(t.location.position),g.enableVertexAttribArray(t.location.texCoord),e.texCoord&&(g.bindBuffer(g.ARRAY_BUFFER,e.texCoord),g.vertexAttribPointer(t.location.texCoord,e.texCoord.size,g.FLOAT,!1,0,0)),g.bindBuffer(g.ARRAY_BUFFER,e.vertex),g.vertexAttribPointer(t.location.position,e.vertex.size,g.FLOAT,!1,0,0),g.bindBuffer(g.ELEMENT_ARRAY_BUFFER,e.index),o&&o.depth?n.enable(n.DEPTH_TEST):n.disable(n.DEPTH_TEST),o?void 0===o.blend||o.blend?(n.enable(n.BLEND),l=void 0===o.srcRGB?n.ONE:o.srcRGB,p=o.dstRGB||n.ZERO,d=void 0===o.srcAlpha?l:o.srcAlpha,m=void 0===o.dstAlpha?p:o.dstAlpha,n.blendFuncSeparate(l,p,d,m),n.blendEquation(o.blendEquation||n.FUNC_ADD)):n.disable(n.BLEND):(n.enable(n.BLEND),n.blendFunc(n.ONE,n.ZERO),n.blendEquation(n.FUNC_ADD)),i)i.hasOwnProperty(a)&&(u=i[a],(h=t.uniforms[a])&&(k(u,"WebGLTexture")?(g.activeTexture(g.TEXTURE0+y),g.bindTexture(g.TEXTURE_2D,u),h.set(y),y++):u instanceof E||u instanceof R||u instanceof D?u.texture&&(g.activeTexture(g.TEXTURE0+y),g.bindTexture(g.TEXTURE_2D,u.texture),h.set(y),y++):null!=u&&h.set(u)));o&&void 0!==o.clear&&!o.clear||(g.clearColor(0,0,0,0),g.clear(g.COLOR_BUFFER_BIT|g.DEPTH_BUFFER_BIT)),g.drawElements(e.mode,e.length,g.UNSIGNED_SHORT,0),n.enable(n.DEPTH_TEST)}}function xt(e,i,r){var n,s;if(("string"!=typeof e||!i&&0!==i)&&(r&&"object"===t(r)||(r=i),i=e),"string"==typeof e&&p[e]||(e=null),i instanceof E||i instanceof R||i instanceof D)n=i;else if(i instanceof _||i instanceof N||i instanceof F){if(!(n=Y[i.id]))throw new Error("Cannot connect a foreign node")}else{for("string"==typeof i&&isNaN(i)&&(i=M(i,["canvas","img","video"])),s=0;s<Q.length;s++)if(n=Q[s],(!e||e===n.hook)&&n.compare&&n.compare(i,r))return n;n=new E(e,i,r)}return n}function Et(t,e){var i,r,n;if(!(t instanceof R||t instanceof D))return!1;if(t===e)return!0;for(i in n=t.sources)if(n.hasOwnProperty(i)&&((r=n[i])===e||Et(r,e)))return!0;return!1}(y=function(){this.ready=!1,this.width=1,this.height=1,this.gl=n,this.uniforms={resolution:[this.width,this.height],transform:null},this.dirty=!0,this.isDestroyed=!1,this.seriously=X,this.listeners={},this.id=q,q++}).prototype.setReady=function(){var t;if(!this.ready&&(this.ready=!0,this.emit("ready"),this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setReady()},y.prototype.setUnready=function(){var t;if(this.ready&&(this.ready=!1,this.emit("unready"),this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setUnready()},y.prototype.setDirty=function(){var t;if(!this.dirty&&(this.emit("dirty"),this.dirty=!0,this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setDirty()},y.prototype.initFrameBuffer=function(t){n&&(this.frameBuffer=new K(n,this.width,this.height,t))},y.prototype.readPixels=function(t,e,i,r,s){var o=this.gl||n;if(!n)throw new Error("Cannot read pixels until a canvas is connected");if(this.frameBuffer||(this.initFrameBuffer(),this.setDirty()),this.render(),void 0===s)s=new Uint8Array(i*r*4);else if(!k(s,"Uint8Array"))throw new Error("Incompatible array type");return o.bindFramebuffer(n.FRAMEBUFFER,this.frameBuffer.frameBuffer),o.readPixels(t,e,i,r,n.RGBA,n.UNSIGNED_BYTE,s),s},y.prototype.resize=function(){var t,e;this.source?(t=this.source.width,e=this.source.height):this.sources&&this.sources.source?(t=this.sources.source.width,e=this.sources.source.height):this.inputs&&this.inputs.width?(t=this.inputs.width,e=this.inputs.height||t):this.inputs&&this.inputs.height?t=e=this.inputs.height:(t=1,e=1),t=Math.floor(t),e=Math.floor(e),this.width===t&&this.height===e||(this.width=t,this.height=e,this.emit("resize"),this.setDirty()),this.uniforms&&this.uniforms.resolution&&(this.uniforms.resolution[0]=t,this.uniforms.resolution[1]=e),this.frameBuffer&&this.frameBuffer.resize&&this.frameBuffer.resize(t,e)},y.prototype.on=function(t,e){var i,r=-1;t&&"function"==typeof e&&((i=this.listeners[t])?r=i.indexOf(e):i=this.listeners[t]=[],r<0&&i.push(e))},y.prototype.off=function(t,e){var i,r=-1;t&&"function"==typeof e&&(i=this.listeners[t])&&(r=i.indexOf(e))>=0&&i.splice(r,1)},y.prototype.emit=function(t){var e,i=this.listeners[t];if(i&&i.length)for(e=0;e<i.length;e++)V(i[e])},y.prototype.destroy=function(){var t,e;for(e in delete this.gl,delete this.seriously,this.listeners)this.listeners.hasOwnProperty(e)&&delete this.listeners[e];for(t in this.uniforms)this.uniforms.hasOwnProperty(t)&&delete this.uniforms[t];this.targets&&delete this.targets,this.frameBuffer&&this.frameBuffer.destroy&&(this.frameBuffer.destroy(),delete this.frameBuffer),(t=W.indexOf(this))>=0&&W.splice(t,1),delete Y[this.id],this.isDestroyed=!0},_=function(t){var e,i=t;function r(t,e){var r,n,s;return s=i.effect.inputs[t],r=i.inputElements[t],"string"==typeof e&&isNaN(e)&&("enum"===s.type?s.options.hasOwnProperty(e)||(e=M(e,["select"])):"number"===s.type||"boolean"===s.type?e=M(e,["input","select"]):"image"===s.type&&(e=M(e,["canvas","img","video"]))),k(e,"HTMLInputElement")||k(e,"HTMLSelectElement")?(n=e.value,r&&r.element!==e&&(r.element.removeEventListener("change",r.listener,!0),r.element.removeEventListener("input",r.listener,!0),delete i.inputElements[t],r=null),r||(r={element:e,listener:function(t,r){return function(){var n,o;n="checkbox"===e.type?e.checked:r.value,o=i.setInput(t,n),"color"===s.type&&(o=j(o).substr(0,7)),o!==n&&(r.value=o)}}(t,e)},i.inputElements[t]=r,"range"===e.type?(e.addEventListener("input",r.listener,!0),e.addEventListener("change",r.listener,!0)):e.addEventListener("change",r.listener,!0)),r&&"checkbox"===e.type&&(n=e.checked)):(r&&(r.element.removeEventListener("change",r.listener,!0),r.element.removeEventListener("input",r.listener,!0),delete i.inputElements[t]),n=e),i.setInput(t,n),i.inputs[t]}function n(t){return function(e){var i=r(t,e);return i&&i.pub}}function s(t){return function(){var e=i.inputs[t];return e&&e.pub}}function o(t){return function(e){return r(t,e)}}function a(t){return function(){return i.inputs[t]}}for(e in i.effect.inputs)if(i.effect.inputs.hasOwnProperty(e)){if(void 0!==this[e])throw new Error("Cannot overwrite Seriously."+e);"image"===i.effect.inputs[e].type?Object.defineProperty(this,e,{configurable:!0,enumerable:!0,get:s(e),set:n(e)}):Object.defineProperty(this,e,{configurable:!0,enumerable:!0,get:a(e),set:o(e)})}Object.defineProperties(this,{effect:{enumerable:!0,configurable:!0,get:function(){return i.hook}},title:{enumerable:!0,configurable:!0,get:function(){return i.effect.title||i.hook}},width:{enumerable:!0,configurable:!0,get:function(){return i.width}},height:{enumerable:!0,configurable:!0,get:function(){return i.height}},id:{enumerable:!0,configurable:!0,get:function(){return i.id}}}),this.render=function(){return i.render(),this},this.readPixels=function(t,e,r,n,s){return i.readPixels(t,e,r,n,s)},this.on=function(t,e){i.on(t,e)},this.off=function(t,e){i.off(t,e)},this.inputs=function(t){var e,r,n,s;if(n=i.effect.inputs,t)return(r=n[t])?(e={type:r.type,defaultValue:r.defaultValue,title:r.title||t},"number"===r.type?(e.min=r.min,e.max=r.max,e.step=r.step,e.mod=r.mod):"enum"===r.type?e.options=z({},r.options):"vector"===r.type&&(e.dimensions=r.dimensions),r.description&&(e.description=r.description),e):null;for(s in e={},n)n.hasOwnProperty(s)&&(e[s]=this.inputs(s));return e},this.alias=function(t,e){return i.alias(t,e),this},this.matte=function(t){i.matte(t)},this.destroy=function(){var t,e;for(t in i.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((e=Object.getOwnPropertyDescriptor(this,t)).get||e.set||"function"!=typeof this[t]?delete this[t]:this[t]=w)},this.isDestroyed=function(){return i.isDestroyed},this.isReady=function(){return i.ready}},R=function(t,e){var i,r,o,a,u={};for(i in y.call(this,e),this.gl=n,this.effectRef=l[t],this.sources={},this.targets=[],this.inputElements={},this.dirty=!0,this.shaderDirty=!0,this.hook=t,this.options=e,this.transform=null,this.effect=z({},this.effectRef),this.effectRef.definition&&z(this.effect,this.effectRef.definition.call(this,e)),Z(this.effect),this.uniforms.transform=s,this.inputs={},a=ot[t],this.effect.inputs)this.effect.inputs.hasOwnProperty(i)&&(void 0!==(r=this.effect.inputs[i]).defaultValue&&null!==r.defaultValue||("number"===r.type?r.defaultValue=Math.min(Math.max(0,r.min),r.max):"color"===r.type?r.defaultValue=[0,0,0,0]:"boolean"===r.type?r.defaultValue=!1:"string"===r.type?r.defaultValue="":"enum"===r.type&&(r.defaultValue=r.firstValue)),o=r.validate.call(this,r.defaultValue,r),a&&void 0!==a[i]&&(o=r.validate.call(this,a[i],r,r.defaultValue,o),a[i]=o,"image"===r.type&&(u[i]=o)),this.inputs[i]=o,r.uniform&&(this.uniforms[r.uniform]=r.defaultValue));for(i in n&&(this.initialize(),this.effect.commonShader&&this.buildShader()),this.updateReady(),this.inPlace=this.effect.inPlace,this.pub=new _(this),W.push(this),Y[this.id]=this,it.push(this),g[t].push(this),u)u.hasOwnProperty(i)&&this.setInput(i,u[i])},R.prototype=Object.create(y.prototype),R.prototype.constructor=R,R.prototype.initialize=function(){if(!this.initialized){var t=this;this.baseShader=c,this.shape?this.model=ct(this.shape,this.gl):this.model=h,"function"==typeof this.effect.initialize?this.effect.initialize.call(this,(function(){t.initFrameBuffer(!0)}),n):this.initFrameBuffer(!0),this.frameBuffer&&(this.texture=this.frameBuffer.texture),this.initialized=!0}},R.prototype.resize=function(){var t;for(y.prototype.resize.call(this),this.effect.resize&&this.effect.resize.call(this),t=0;t<this.targets.length;t++)this.targets[t].resize()},R.prototype.updateReady=function(){var t,e,i,r,n=!0;for(e in(i=this.effect).inputs)if(i.inputs.hasOwnProperty(e)&&"image"===this.effect.inputs[e].type&&(!this.sources[e]||!this.sources[e].ready)&&(!i.requires||i.requires.call(this,e,this.inputs))){n=!1;break}if(this.ready!==n&&(this.ready=n,this.emit(n?"ready":"unready"),r=n?"setReady":"setUnready",this.targets))for(t=0;t<this.targets.length;t++)this.targets[t][r]()},R.prototype.setReady=R.prototype.updateReady,R.prototype.setUnready=R.prototype.updateReady,R.prototype.addTarget=function(t){var e;for(e=0;e<this.targets.length;e++)if(this.targets[e]===t)return;this.targets.push(t)},R.prototype.removeTarget=function(t){var e=this.targets&&this.targets.indexOf(t);e>=0&&this.targets.splice(e,1)},R.prototype.removeSource=function(t){var e,i=t&&t.pub;for(e in this.inputs)!this.inputs.hasOwnProperty(e)||this.inputs[e]!==t&&this.inputs[e]!==i||(this.inputs[e]=null);for(e in this.sources)!this.sources.hasOwnProperty(e)||this.sources[e]!==t&&this.sources[e]!==i||(this.sources[e]=null)},R.prototype.buildShader=function(){var t,e=this.effect,i=this;function r(t){return O.test(t)?t:"#define SHADER_NAME seriously."+i.hook+"\n"+t}this.shaderDirty&&(e.commonShader&&at[this.hook]?(this.shader||at[this.hook].count++,this.shader=at[this.hook].shader):e.shader?(this.shader&&!e.commonShader&&this.shader.destroy(),(t=e.shader.call(this,this.inputs,{vertex:a,fragment:u},J.util))instanceof $?this.shader=t:t&&t.vertex&&t.fragment?this.shader=new $(n,r(t.vertex),r(t.fragment)):this.shader=c,e.commonShader&&(at[this.hook]={count:1,shader:this.shader})):this.shader=c,this.shaderDirty=!1)},R.prototype.render=function(){var t,e,i,r=this.effect,s=this;function o(t,e,i,r,n,o){vt(t,e,i,r,n||s,o)}if(n){if(this.initialized||this.initialize(),this.shaderDirty&&this.buildShader(),this.dirty&&this.ready){for(t in this.sources)!this.sources.hasOwnProperty(t)||r.requires&&!r.requires.call(this,t,this.inputs)||(i="function"==typeof this.inPlace?this.inPlace(t):this.inPlace,this.sources[t].render(!i));this.frameBuffer&&(e=this.frameBuffer.frameBuffer),"function"==typeof r.draw?(r.draw.call(this,this.shader,this.model,this.uniforms,e,o),this.emit("render")):e&&(vt(this.shader,this.model,this.uniforms,e,this),this.emit("render")),this.dirty=!1}return this.texture}},R.prototype.setInput=function(t,e){var i,r,n,o,a,u=this;function h(){var e,i=u.sources[t];if(i){for(e in u.sources)if(e!==t&&u.sources.hasOwnProperty(e)&&u.sources[e]===i)return;i.removeTarget(u)}}if(this.effect.inputs.hasOwnProperty(t)){if("image"===(i=this.effect.inputs[t]).type){if(e){if((e=xt(e))!==this.sources[t]){if(h(),Et(e,this))throw new Error("Attempt to make cyclical connection.");this.sources[t]=e,e.addTarget(this)}}else delete this.sources[t],e=!1;r=this.sources[t],n=Object.keys(this.sources),!0===this.inPlace&&1===n.length?(o=this.sources[n[0]],this.uniforms.transform=o&&o.cumulativeMatrix||s):this.uniforms.transform=s}else a=ot[this.hook]&&void 0!==ot[this.hook][t]?ot[this.hook][t]:i.defaultValue,r=e=i.validate.call(this,e,i,a,this.inputs[t]);return this.inputs[t]===e&&"color"!==i.type&&"vector"!==i.type||(this.inputs[t]=e,i.uniform&&(this.uniforms[i.uniform]=r),"image"===i.type?(this.resize(),this.updateReady()):i.updateSources&&this.updateReady(),i.shaderDirty&&(this.shaderDirty=!0),this.setDirty(),i.update&&i.update.call(this,e)),e}},R.prototype.alias=function(t,e){var i=this;if(C.indexOf(e)>=0)throw new Error("'"+e+"' is a reserved name and cannot be used as an alias.");return this.effect.inputs.hasOwnProperty(t)&&(e||(e=t),X.removeAlias(e),rt[e]={node:this,input:t},Object.defineProperty(X,e,{configurable:!0,enumerable:!0,get:function(){return i.inputs[t]},set:function(e){return i.setInput(t,e)}})),this},R.prototype.matte=function(e){var i,r,n,s,o,a,u,h=[],f=[],c={};function l(t){return t&&t.length&&Array.isArray(t)?Array.isArray(t[0])?Array.isArray(t[0])&&!isNaN(t[0][0])?[t]:t:[t]:[]}function d(t,e,i,r){var n,s,o,a,u;return n=(r.x-i.x)*(t.y-i.y)-(r.y-i.y)*(t.x-i.x),s=(e.x-t.x)*(t.y-i.y)-(e.y-t.y)*(t.x-i.x),!!((o=(r.y-i.y)*(e.x-t.x)-(r.x-i.x)*(e.y-t.y))&&(u=s/o,(a=n/o)>0&&a<=1&&u>0&&u<=1))&&{x:t.x+a*(e.x-t.x),y:t.y+a*(e.y-t.y)}}function p(t){var e,i,r,n,s,o,a,u,c,l,p,m=[];if(!t.simple){for(e=0;e<t.edges.length;e++)for(r=t.edges[e],i=e+1;i<t.edges.length;i++)n=t.edges[i],(s=d(r[0],r[1],n[0],n[1]))&&(s.edge1=r,s.edge2=n,m.push(s));if(m.length){for(c=[],e=0;e<m.length;e++)r=(s=m[e]).edge1,n=s.edge2,l={x:s.x,y:s.y,prev:r[0],next:n[1],id:f.length},t.vertices.push(l),f.push(l),p={x:s.x,y:s.y,prev:n[0],next:r[1],id:f.length},t.vertices.push(p),f.push(l),l.prev.next=l,l.next.prev=l,p.prev.next=p,p.next.prev=p;do{o={edges:[],vertices:[],simple:!0},c.push(o),a=u=t.vertices[0];do{e=t.vertices.indexOf(u),t.vertices.splice(e,1),o.edges.push([u,u.next]),o.vertices.push(u),u=u.next}while(u!==a)}while(t.vertices.length);for(e=h.indexOf(t),h.splice(e,1),e=0;e<c.length;e++)h.push(c[e])}else t.simple=!0}}function m(t){var e,i,r,n,s=t.vertices.length,o=0;for(e=s-1,i=0;i<s;e=i,i++)r=t.vertices[e],n=t.vertices[i],o+=r.x*n.y-n.x*r.y;return o>0}function y(t){var e,i,n,s,o,a,u,h,f,c,l,d=t.vertices,p=[],m=[];function y(t,e,i,r){var n,s,o,a,u,h,f,c,l,d,p,m;return n=i.x-e.x,s=i.y-e.y,o=t.x-i.x,a=t.y-i.y,u=e.x-t.x,h=e.y-t.y,f=r.x-t.x,c=r.y-t.y,l=r.x-e.x,d=r.y-e.y,p=r.x-i.x,m=r.y-i.y,n*d-s*l>=0&&o*m-a*p>=0&&u*c-h*f>=0}function g(t,e,i,r,n){var s,o,a,u;if(o=d[n[t]],a=d[n[e]],u=d[n[i]],0>(a.x-o.x)*(u.y-o.y)-(a.y-o.y)*(u.x-o.x))return!1;for(s=0;s<r;s++)if(s!==t&&s!==e&&s!==i&&y(o,a,u,d[n[s]]))return!1;return!0}if(i=d.length,t.clockWise)for(e=0;e<i;e++)p[e]=e;else for(e=0;e<i;e++)p[e]=i-1-e;for(s=2*(n=i),e=n-1;n>2;){if(s--<=0)return m;if(n<=(o=e)&&(o=0),n<=(e=o+1)&&(e=0),n<(a=e+1)&&(a=0),g(o,e,a,n,p)){for(u=p[o],h=p[e],f=p[a],t.clockWise?(m.push(d[u]),m.push(d[h]),m.push(d[f])):(m.push(d[f]),m.push(d[h]),m.push(d[u])),c=e,l=e+1;l<n;c++,l++)p[c]=p[l];s=2*--n}}r.indices=m}for(i=l(e),n=0;n<i.length;n++){for(e=i[n],u=null,r={vertices:[],edges:[]},s=0;s<e.length;s++)o=e[s],"object"!==t(o)||isNaN(o.x)||isNaN(o.y)?o.length>=2&&!isNaN(o[0])&&!isNaN(o[1])&&(a={x:o[0],y:o[1],id:f.length}):a={x:o.x,y:o.y,id:f.length},a&&(u?(u.next=a,a.prev=u,a.next=r.vertices[0],r.vertices[0].prev=a):(r.head=a,a.next=a,a.prev=a),f.push(a),r.vertices.push(a),u=a);if(r.vertices.length>2)for(3===r.vertices.length&&(r.simple=!0),h.push(r),s=0;s<r.vertices.length;s++)a=r.vertices[s],r.edges.push([a,a.next])}for(n=h.length-1;n>=0;n--)p(r=h[n]);for(n=0;n<h.length;n++)(r=h[n]).clockWise=m(r),y(r);for(c.vertices=[],c.coords=[],n=0;n<f.length;n++)o=f[n],c.vertices.push(2*o.x-1),c.vertices.push(-2*o.y+1),c.vertices.push(-1),c.coords.push(o.x),c.coords.push(-1*o.y+1);for(c.vertices=new Float32Array(c.vertices),c.coords=new Float32Array(c.coords),c.indices=[],n=0;n<h.length;n++)for(r=h[n],s=0;s<r.indices.length;s++)o=r.indices[s],c.indices.push(o.id);c.indices=new Uint16Array(c.indices),this.shape=c,this.gl&&ct(c,this.gl)},R.prototype.destroy=function(){var t,e,i,r=this.hook;for(e in this.effect.destroy&&"function"==typeof this.effect.destroy&&this.effect.destroy.call(this),delete this.effect,at[r]&&(at[r].count--,at[r].count||delete at[r]),this.shader&&this.shader.destroy&&this.shader!==c&&!at[r]&&this.shader.destroy(),delete this.shader,this.inputElements)this.inputElements.hasOwnProperty(e)&&((i=this.inputElements[e]).element.removeEventListener("change",i.listener,!0),i.element.removeEventListener("input",i.listener,!0));for(e in this.sources)this.sources.hasOwnProperty(e)&&((i=this.sources[e])&&i.removeTarget&&i.removeTarget(this),delete this.sources[e]);for(;this.targets.length;)(i=this.targets.pop())&&i.removeSource&&i.removeSource(this);for(e in this)this.hasOwnProperty(e)&&"id"!==e&&delete this[e];for(e in rt)rt.hasOwnProperty(e)&&(i=rt[e]).node===this&&X.removeAlias(e);(t=it.indexOf(this))>=0&&it.splice(t,1),(t=g[r].indexOf(this))>=0&&g[r].splice(t,1),y.prototype.destroy.call(this)},N=function(t){var e=t;Object.defineProperties(this,{original:{enumerable:!0,configurable:!0,get:function(){return e.source}},id:{enumerable:!0,configurable:!0,get:function(){return e.id}},width:{enumerable:!0,configurable:!0,get:function(){return e.width}},height:{enumerable:!0,configurable:!0,get:function(){return e.height}}}),this.render=function(){e.render()},this.update=function(){e.setDirty()},this.readPixels=function(t,i,r,n,s){return e.readPixels(t,i,r,n,s)},this.on=function(t,i){e.on(t,i)},this.off=function(t,i){e.off(t,i)},this.destroy=function(){var t,i;for(t in e.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((i=Object.getOwnPropertyDescriptor(this,t)).get||i.set||"function"!=typeof this[t]?delete this[t]:this[t]=w)},this.isDestroyed=function(){return e.isDestroyed},this.isReady=function(){return e.ready}},E=function(e,i,r){var s,o,a=r||{},u=void 0===a.flip||a.flip,h=a.width,f=a.height,c=!1,l=this,d=!1;function m(t,e,i,r){var n=p[t];if(n.definition){if(!(n=n.definition.call(l,e,i,r)))return null;n=z(z({},p[t]),n)}return n}function g(t){return l.source===t}if(y.call(this),(e&&"string"!=typeof e||!i&&0!==i)&&(r&&"object"===t(r)||(r=i),i=e),"string"==typeof i&&isNaN(i)&&(i=M(i,["canvas","img","video"])),"string"==typeof e&&p[e]&&(o=m(e,i,r,!0))&&(this.hook=e,d=!0,c=o.deferTexture,this.plugin=o,this.compare=o.compare,this.checkDirty=o.checkDirty,o.source&&(i=o.source)),!o&&k(i))"CANVAS"===i.tagName?(this.width=i.width,this.height=i.height,this.render=this.renderImageCanvas,d=!0,this.hook="canvas",this.compare=g):"IMG"===i.tagName&&(this.width=i.naturalWidth||1,this.height=i.naturalHeight||1,i.complete&&i.naturalWidth||(c=!0),i.addEventListener("load",(function(){l.isDestroyed||(l.width===i.naturalWidth&&l.height===i.naturalHeight||(l.width=i.naturalWidth,l.height=i.naturalHeight,l.resize()),l.setDirty(),l.setReady())}),!0),this.render=this.renderImageCanvas,d=!0,this.hook="image",this.compare=g);else if(!o&&k(i,"WebGLTexture")){if(n&&!n.isTexture(i))throw new Error("Not a valid WebGL texture.");isNaN(h)?isNaN(f)||(h=f):isNaN(f)&&(f=h),this.width=h,this.height=f,void 0===a.flip&&(u=!1),d=!0,this.texture=i,this.initialized=!0,this.hook="texture",this.compare=g,this.render=function(){}}if(!d&&!o)for(s in p)if(p.hasOwnProperty(s)&&p[s]&&(o=m(s,i,r,!1))){this.hook=s,d=!0,c=o.deferTexture,this.plugin=o,this.compare=o.compare,this.checkDirty=o.checkDirty,o.source&&(i=o.source);break}if(!d)throw new Error("Unknown source type");this.source=i,void 0===this.flip&&(this.flip=u),this.targets=[],c||l.setReady(),this.pub=new N(this),W.push(this),Y[this.id]=this,Q.push(this),x[this.hook].push(this),Q.length&&!I&>()},E.prototype=Object.create(y.prototype),E.prototype.constructor=E,E.prototype.initialize=function(){var t;n&&!this.texture&&this.ready&&(t=n.createTexture(),n.bindTexture(n.TEXTURE_2D,t),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),this.texture=t,this.initialized=!0,this.allowRefresh=!0,this.setDirty())},E.prototype.initFrameBuffer=function(t){n&&(this.frameBuffer=new K(n,this.width,this.height,{texture:this.texture,useFloat:t}))},E.prototype.addTarget=function(t){var e;for(e=0;e<this.targets.length;e++)if(this.targets[e]===t)return;this.targets.push(t)},E.prototype.removeTarget=function(t){var e=this.targets&&this.targets.indexOf(t);e>=0&&this.targets.splice(e,1)},E.prototype.resize=function(){var t,e;if(this.uniforms.resolution[0]=this.width,this.uniforms.resolution[1]=this.height,this.framebuffer&&this.framebuffer.resize(this.width,this.height),this.emit("resize"),this.setDirty(),this.targets)for(t=0;t<this.targets.length;t++)(e=this.targets[t]).resize(),e.setTransformDirty&&e.setTransformDirty()},E.prototype.setReady=function(){var t;if(!this.ready&&(this.ready=!0,this.resize(),this.initialize(),this.emit("ready"),this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setReady()},E.prototype.render=function(){var t=this.source;n&&(t||0===t)&&this.ready&&(this.initialized||this.initialize(),this.allowRefresh&&this.plugin&&this.plugin.render&&(this.dirty||this.checkDirty&&this.checkDirty())&&this.plugin.render.call(this,n,vt,h,c)&&(this.dirty=!1,this.emit("render")))},E.prototype.renderImageCanvas=function(){var t=this.source;if(n&&t&&this.ready&&(this.initialized||this.initialize(),this.allowRefresh&&this.dirty)){n.bindTexture(n.TEXTURE_2D,this.texture),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,this.flip),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);try{return n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,t),this.dirty=!1,this.emit("render"),!0}catch(t){t.code===e.DOMException.SECURITY_ERR&&(this.allowRefresh=!1,J.logger.error("Unable to access cross-domain image"))}return!1}},E.prototype.destroy=function(){var t,e,i;for(this.plugin&&this.plugin.destroy&&this.plugin.destroy.call(this),n&&this.texture&&n.deleteTexture(this.texture);this.targets.length;)(i=this.targets.pop())&&i.removeSource&&i.removeSource(this);for(e in(t=Q.indexOf(this))>=0&&Q.splice(t,1),(t=x[this.hook].indexOf(this))>=0&&x[this.hook].splice(t,1),this)this.hasOwnProperty(e)&&"id"!==e&&delete this[e];y.prototype.destroy.call(this)},S=function(t){var e=t;Object.defineProperties(this,{source:{enumerable:!0,configurable:!0,get:function(){if(e.source)return e.source.pub},set:function(t){e.setSource(t)}},original:{enumerable:!0,configurable:!0,get:function(){return e.target}},width:{enumerable:!0,configurable:!0,get:function(){return e.width},set:function(t){!isNaN(t)&&t>0&&e.width!==t&&(e.width=t,e.resize(),e.setTransformDirty())}},height:{enumerable:!0,configurable:!0,get:function(){return e.height},set:function(t){!isNaN(t)&&t>0&&e.height!==t&&(e.height=t,e.resize(),e.setTransformDirty())}},id:{enumerable:!0,configurable:!0,get:function(){return e.id}}}),this.render=function(){e.render()},this.readPixels=function(t,i,r,n,s){return e.readPixels(t,i,r,n,s)},this.on=function(t,i){e.on(t,i)},this.off=function(t,i){e.off(t,i)},this.go=function(t){e.go(t)},this.stop=function(){e.stop()},this.getTexture=function(){return e.frameBuffer.texture},this.destroy=function(){var t,i;for(t in e.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((i=Object.getOwnPropertyDescriptor(this,t)).get||i.set||"function"!=typeof this[t]?delete this[t]:this[t]=w)},this.inputs=function(t){return{source:{type:"image"}}},this.isDestroyed=function(){return e.isDestroyed},this.isReady=function(){return e.ready}},A=function(e,i,r){var s,f,l,d,p,g,v,x,E,T=this,R=!1;function D(t,e,i,r){var s=m[t];if(s.definition){if(!(s=s.definition.call(T,e,i,r)))return null;s=z(z({},m[t]),s),T.hook=E,R=!0,T.plugin=s,T.compare=s.compare,s.target&&(e=s.target),s.gl&&!T.gl&&(T.gl=s.gl,n||pt(s.gl)),T.gl===n&&(T.model=h,T.shader=c)}return s}if(y.call(this),(e&&"string"!=typeof e||!i&&0!==i)&&(r&&"object"===t(r)||(r=i),i=e),f=void 0===(s=r||{}).flip||s.flip,l=parseInt(s.width,10),d=parseInt(s.height,10),g=s.debugContext,"string"==typeof e&&m[e]&&D(e,i,s,!0),this.renderToTexture=s.renderToTexture,k(i,"WebGLFramebuffer"))if(v=i,k(s,"HTMLCanvasElement"))i=s;else if(k(s,"WebGLRenderingContext"))i=s.canvas;else if(k(s.canvas,"HTMLCanvasElement"))i=s.canvas;else{if(!k(s.context,"WebGLRenderingContext"))throw new Error("Must provide a canvas with WebGLFramebuffer target");i=s.context.canvas}if(k(i,"HTMLCanvasElement")){if(l=i.width,d=i.height,(!n||n.canvas!==i&&s.allowSecondaryWebGL)&&(p=H(i,{alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!0,stencil:!0,debugContext:g})),p)n&&n!==p?(this.gl=p,this.frameBuffer={frameBuffer:v||null},this.shader=new $(this.gl,a,u),this.model=lt.call(this,this.gl),this.pixels=null,this.texture=this.gl.createTexture(),this.gl.bindTexture(n.TEXTURE_2D,this.texture),this.gl.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),this.gl.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),this.gl.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),this.gl.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),this.render=this.renderSecondaryWebGL):(o||(o=this),n||pt(p),this.render=this.renderWebGL,s.renderToTexture?n&&(this.frameBuffer=new K(n,l,d,!1)):this.frameBuffer={frameBuffer:v||null});else{if(!s.allowSecondaryWebGL&&n&&n.canvas!==i)throw new Error("Only one WebGL target canvas allowed. Set allowSecondaryWebGL option to create secondary context.");this.render=w,J.logger.log("Unable to create WebGL context.")}R=!0}if(!R)for(E in m)if(m.hasOwnProperty(E)&&m[E]&&D(E,i,s,!1))break;if(!R)throw new Error("Unknown target type");b&&((x=b.get(i))?J.logger.warn("Target already in use by another instance",i,Object.keys(x).map((function(t){return x[t]}))):(x={},b.set(i,x)),x[X.id]=X),this.target=i,this.transform=null,this.transformDirty=!0,this.flip=f,l&&(this.width=l),d&&(this.height=d),this.uniforms.resolution[0]=this.width,this.uniforms.resolution[1]=this.height,void 0!==s.auto?this.auto=s.auto:this.auto=ut,this.frames=0,this.pub=new S(this),W.push(this),Y[this.id]=this,tt.push(this)},A.prototype=Object.create(y.prototype),A.prototype.constructor=A,A.prototype.setSource=function(t){var e;(e=xt(t))!==this.source&&(this.source&&this.source.removeTarget(this),this.source=e,e.addTarget(this),e&&(this.resize(),e.ready?this.setReady():this.setUnready()),this.setDirty())},A.prototype.setDirty=function(){this.dirty=!0,this.auto&&!I&&(I=B(gt))},A.prototype.resize=function(){k(this.target,"HTMLCanvasElement")?this.width===this.target.width&&this.height===this.target.height||(this.target.width=this.width,this.target.height=this.height,this.uniforms.resolution[0]=this.width,this.uniforms.resolution[1]=this.height,this.emit("resize"),this.setTransformDirty()):this.plugin&&this.plugin.resize&&this.plugin.resize.call(this),!this.source||this.source.width===this.width&&this.source.height===this.height||this.transform||(this.transform=new Float32Array(16))},A.prototype.setTransformDirty=function(){this.transformDirty=!0,this.setDirty()},A.prototype.go=function(){this.auto=!0,this.setDirty()},A.prototype.stop=function(){this.auto=!1},A.prototype.render=function(){n&&this.plugin&&this.plugin.render&&this.plugin.render.call(this,vt,c,h)},A.prototype.renderWebGL=function(){var t,e,i;if(this.resize(),n&&this.dirty&&this.ready){if(!this.source)return;this.source.render(),this.uniforms.source=this.source.texture,this.source.width===this.width&&this.source.height===this.height?this.uniforms.transform=this.source.cumulativeMatrix||s:this.transformDirty&&(t=this.transform,U.copy(t,this.source.cumulativeMatrix||s),e=this.source.width/this.width,i=this.source.height/this.height,t[0]*=e,t[1]*=e,t[2]*=e,t[3]*=e,t[4]*=i,t[5]*=i,t[6]*=i,t[7]*=i,this.uniforms.transform=t,this.transformDirty=!1),vt(c,h,this.uniforms,this.frameBuffer.frameBuffer,this,P),this.emit("render"),this.dirty=!1}},A.prototype.renderSecondaryWebGL=function(){var t,e,i,r,n;this.dirty&&this.ready&&this.source&&(this.emit("render"),this.source.render(!0),t=this.source.width,e=this.source.height,this.pixels&&this.pixels.length===t*e*4||(this.pixels=new Uint8Array(t*e*4)),this.source.readPixels(0,0,t,e,this.pixels),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,t,e,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,this.pixels),t===this.width&&e===this.height?this.uniforms.transform=s:this.transformDirty&&(i=this.transform,U.copy(i,s),r=this.source.width/this.width,n=this.source.height/this.height,i[0]*=r,i[1]*=r,i[2]*=r,i[3]*=r,i[4]*=n,i[5]*=n,i[6]*=n,i[7]*=n,this.uniforms.transform=i,this.transformDirty=!1),this.uniforms.source=this.texture,vt(this.shader,this.model,this.uniforms,null,this,P),this.dirty=!1)},A.prototype.removeSource=function(t){this.source!==t&&this.source!==t.pub||(this.source=null)},A.prototype.destroy=function(){var t,e;this.source&&this.source.removeTarget&&this.source.removeTarget(this),b&&(delete(e=b.get(this.target))[X.id],Object.keys(e).length||b.delete(this.target)),this.plugin&&this.plugin.destroy&&this.plugin.destroy.call(this),delete this.source,delete this.target,delete this.pub,delete this.uniforms,delete this.pixels,delete this.auto,(t=tt.indexOf(this))>=0&&tt.splice(t,1),y.prototype.destroy.call(this),this===o&&(r.removeEventListener("webglcontextrestored",mt,!1),yt(),o=null)},F=function(t){var e,i=t,r=this;function n(t,e,r){var n,s,o;n=i.inputElements[t],"string"==typeof r&&isNaN(r)&&("enum"===e.type?e.options.hasOwnProperty(r)||(r=M(r,["select"])):"number"===e.type||"boolean"===e.type?r=M(r,["input","select"]):"image"===e.type&&(r=M(r,["canvas","img","video"]))),k(r,"HTMLInputElement")||k(r,"HTMLSelectElement")?(s=r.value,n&&n.element!==r&&(n.element.removeEventListener("change",n.listener,!0),n.element.removeEventListener("input",n.listener,!0),delete i.inputElements[t],n=null),n||(n={element:r,listener:(o=r,function(){var e,n;e="checkbox"===r.type?r.checked:o.value,n=i.setInput(t,e),"color"===r.type&&(n=j(n)),n!==e&&(o.value=n)})},i.inputElements[t]=n,"range"===r.type?(r.addEventListener("input",n.listener,!0),r.addEventListener("change",n.listener,!0)):r.addEventListener("change",n.listener,!0)),n&&"checkbox"===r.type&&(s=r.checked)):(n&&(n.element.removeEventListener("change",n.listener,!0),n.element.removeEventListener("input",n.listener,!0),delete i.inputElements[t]),s=r),i.setInput(t,s)}function s(t,e){Object.defineProperty(r,t,{configurable:!0,enumerable:!0,get:function(){return e.get.call(i)},set:function(i){n(t,e,i)}})}function o(t){return function(){t.apply(i,arguments)&&i.setTransformDirty()}}for(e in Object.defineProperties(this,{transform:{enumerable:!0,configurable:!0,get:function(){return i.hook}},title:{enumerable:!0,configurable:!0,get:function(){return i.plugin.title||i.hook}},width:{enumerable:!0,configurable:!0,get:function(){return i.width}},height:{enumerable:!0,configurable:!0,get:function(){return i.height}},id:{enumerable:!0,configurable:!0,get:function(){return i.id}},source:{enumerable:!0,configurable:!0,get:function(){return i.source&&i.source.pub},set:function(t){i.setSource(t)}}}),i.methods)i.methods.hasOwnProperty(e)&&(this[e]=o(i.methods[e]));for(e in i.inputs)i.inputs.hasOwnProperty(e)&&s(e,i.inputs[e]);this.update=function(){i.setDirty()},this.inputs=function(t){var e,r,n,s;if(n=i.plugin.inputs,t)return!(r=n[t])||r.method?null:(e={type:r.type,defaultValue:r.defaultValue,title:r.title||t},"number"===r.type?(e.min=r.min,e.max=r.max,e.step=r.step,e.mod=r.mod):"enum"===r.type?e.options=z({},r.options):"vector"===r.type&&(e.dimensions=r.dimensions),r.description&&(e.description=r.description),e);for(s in e={},n)n.hasOwnProperty(s)&&!n[s].method&&(e[s]=this.inputs(s));return e},this.alias=function(t,e){return i.alias(t,e),this},this.on=function(t,e){i.on(t,e)},this.off=function(t,e){i.off(t,e)},this.destroy=function(){var t,e;for(t in i.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((e=Object.getOwnPropertyDescriptor(this,t)).get||e.set||"function"!=typeof this[t]?delete this[t]:this[t]=w)},this.isDestroyed=function(){return i.isDestroyed},this.isReady=function(){return i.ready}},D=function(t,e){var i,r,n,s,o;for(i in this.matrix=new Float32Array(16),this.cumulativeMatrix=new Float32Array(16),this.ready=!1,this.width=1,this.height=1,this.seriously=X,this.transformRef=d[t],this.hook=t,this.id=q,q++,this.options=e,this.sources=null,this.targets=[],this.inputElements={},this.inputs={},this.methods={},this.listeners={},this.texture=null,this.frameBuffer=null,this.uniforms=null,this.dirty=!0,this.transformDirty=!0,this.renderDirty=!1,this.isDestroyed=!1,this.transformed=!1,this.plugin=z({},this.transformRef),this.transformRef.definition&&z(this.plugin,this.transformRef.definition.call(this,e)),this.plugin.inputs)this.plugin.inputs.hasOwnProperty(i)&&((r=this.plugin.inputs[i]).method&&"function"==typeof r.method?this.methods[i]=r.method:"function"==typeof r.set&&"function"==typeof r.get&&(this.inputs[i]=r));for(i in Z(this.plugin),o=ot[t],this.plugin.inputs)this.plugin.inputs.hasOwnProperty(i)&&"function"==typeof(r=this.plugin.inputs[i]).set&&"function"==typeof r.get&&"function"!=typeof r.method&&(n=r.get.call(this),s=void 0===r.defaultValue?n:r.defaultValue,s=r.validate.call(this,s,r,n),o&&void 0!==o[i]&&(s=r.validate.call(this,o[i],r,r.defaultValue,s),o[i]=s),s!==n&&r.set.call(this,s));W.push(this),Y[this.id]=this,this.pub=new F(this),et.push(this),v[t].push(this)},D.prototype=Object.create(y.prototype),D.prototype.constructor=D,D.prototype.setDirty=function(){this.renderDirty=!0,y.prototype.setDirty.call(this)},D.prototype.setTransformDirty=function(){var t,e;for(this.transformDirty=!0,this.dirty=!0,this.renderDirty=!0,t=0;t<this.targets.length;t++)(e=this.targets[t]).setTransformDirty?e.setTransformDirty():e.setDirty()},D.prototype.resize=function(){var t;for(y.prototype.resize.call(this),this.plugin.resize&&this.plugin.resize.call(this),t=0;t<this.targets.length;t++)this.targets[t].resize();this.setTransformDirty()},D.prototype.setSource=function(t){var e;if((e=xt(t))!==this.source){if(Et(e,this))throw new Error("Attempt to make cyclical connection.");this.source&&this.source.removeTarget(this),this.source=e,e.addTarget(this),e&&e.ready?this.setReady():this.setUnready(),this.resize()}},D.prototype.addTarget=function(t){var e;for(e=0;e<this.targets.length;e++)if(this.targets[e]===t)return;this.targets.push(t)},D.prototype.removeTarget=function(t){var e=this.targets&&this.targets.indexOf(t);e>=0&&this.targets.splice(e,1),this.targets&&this.targets.length&&this.resize()},D.prototype.setInput=function(t,e){var i,r,n;if(this.plugin.inputs.hasOwnProperty(t))return i=this.plugin.inputs[t],r=ot[this.hook]&&void 0!==ot[this.hook][t]?ot[this.hook][t]:i.defaultValue,n=i.get.call(this),void 0===r&&(r=n),e=i.validate.call(this,e,i,r,n),i.set.call(this,e)&&this.setTransformDirty(),i.get.call(this)},D.prototype.alias=function(t,e){var i,r,n=this;if(C.indexOf(e)>=0)throw new Error("'"+e+"' is a reserved name and cannot be used as an alias.");return this.plugin.inputs.hasOwnProperty(t)&&(e||(e=t),X.removeAlias(e),(i=this.inputs[t])?(r=n.inputs[t],Object.defineProperty(X,e,{configurable:!0,enumerable:!0,get:function(){return r.get.call(n)},set:function(t){r.set.call(n,t)&&n.setTransformDirty()}})):(i=this.methods[t])&&(r=i,X[e]=function(){r.apply(n,arguments)&&n.setTransformDirty()}),i&&(rt[e]={node:this,input:t})),this},D.prototype.render=function(t){return this.source?(this.source.render(),this.transformDirty&&(this.transformed?this.source.cumulativeMatrix?U.multiply(this.cumulativeMatrix,this.matrix,this.source.cumulativeMatrix):U.copy(this.cumulativeMatrix,this.matrix):U.copy(this.cumulativeMatrix,this.source.cumulativeMatrix||s),this.transformDirty=!1),t&&n?(this.renderDirty&&(this.frameBuffer||(this.uniforms={resolution:[this.width,this.height]},this.frameBuffer=new K(n,this.width,this.height)),this.uniforms.source=this.source.texture,this.uniforms.transform=this.cumulativeMatrix||s,vt(c,h,this.uniforms,this.frameBuffer.frameBuffer,this),this.renderDirty=!1),this.texture=this.frameBuffer.texture):this.source?this.texture=this.source.texture:this.texture=null,this.dirty=!1,this.texture):(this.transformDirty&&(U.copy(this.cumulativeMatrix,this.matrix),this.transformDirty=!1),this.texture=null,void(this.dirty=!1))},D.prototype.readPixels=function(t,e,i,r,s){var o=this.gl||n;if(!n)throw new Error("Cannot read pixels until a canvas is connected");if(this.render(!0),void 0===s)s=new Uint8Array(i*r*4);else if(!k(s,"Uint8Array"))throw new Error("Incompatible array type");return o.bindFramebuffer(n.FRAMEBUFFER,this.frameBuffer.frameBuffer),o.readPixels(t,e,i,r,n.RGBA,n.UNSIGNED_BYTE,s),s},D.prototype.destroy=function(){var t,e,i,r=this.hook;for(t in this.plugin.destroy&&"function"==typeof this.plugin.destroy&&this.plugin.destroy.call(this),delete this.effect,this.frameBuffer&&(this.frameBuffer.destroy(),delete this.frameBuffer,delete this.texture),this.inputElements)this.inputElements.hasOwnProperty(t)&&((i=this.inputElements[t]).element.removeEventListener("change",i.listener,!0),i.element.removeEventListener("input",i.listener,!0));for(this.source&&this.source.removeTarget(this);this.targets.length;)(i=this.targets.pop())&&i.removeSource&&i.removeSource(this);for(e in this)this.hasOwnProperty(e)&&"id"!==e&&delete this[e];for(e in rt)rt.hasOwnProperty(e)&&(i=rt[e]).node===this&&X.removeAlias(e);(t=et.indexOf(this))>=0&&et.splice(t,1),(t=v[r].indexOf(this))>=0&&v[r].splice(t,1),y.prototype.destroy.call(this)},D.prototype.setReady=y.prototype.setReady,D.prototype.setUnready=y.prototype.setUnready,D.prototype.on=y.prototype.on,D.prototype.off=y.prototype.off,D.prototype.emit=y.prototype.emit,(i=k(i,"HTMLCanvasElement")?{canvas:i}:i||{}).canvas,this.effect=function(t,e){if(!l[t])throw new Error("Unknown effect: "+t);return new R(t,e).pub},this.source=function(t,e,i){return xt(t,e,i).pub},this.transform=function(t,e){if("string"!=typeof t&&(e=t,t=!1),t){if(!d[t])throw new Error("Unknown transform: "+t)}else if(t=i&&i.defaultTransform||"2d",!d[t])throw new Error("No transform specified");return new D(t,e).pub},this.target=function(e,i,r){var n,s,o;for(e&&"string"==typeof e&&!m[e]&&(s=f.querySelector(e)),("string"!=typeof e||!i&&0!==i||s)&&(r&&"object"===t(r)||(r=i),i=s||e,e=null),"string"==typeof i&&isNaN(i)&&(i=f.querySelector(i)),o=0;o<tt.length;o++)if(n=tt[o],(!e||e===n.hook)&&(n.target===i||n.compare&&n.compare(i,r)))return n.pub;return(n=new A(e,i,r)).pub},this.aliases=function(){return Object.keys(rt)},this.removeAlias=function(t){rt[t]&&(delete this[t],delete rt[t])},this.defaults=function(e,i){var r;if(e)if("object"!==t(e))null===i?delete ot[e]:"object"===t(i)&&(ot[e]=z({},i));else for(r in e)e.hasOwnProperty(r)&&this.defaults(r,e[r]);else if(null===e)for(r in ot)ot.hasOwnProperty(r)&&delete ot[r]},this.go=function(t,e){var i;for("function"==typeof t&&nt.indexOf(t)<0&&nt.push(t),"function"==typeof e&&st.indexOf(e)<0&&st.push(e),ut=!0,i=0;i<tt.length;i++)tt[i].go();I||!nt.length&&!st.length||gt()},this.stop=function(){nt.length=0,st.length=0,L(I),I=0},this.render=function(){var t;for(t=0;t<tt.length;t++)tt[t].render(i)},this.destroy=function(){for(var t,e;W.length;)W[0].pub.destroy();for(t in this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((e=Object.getOwnPropertyDescriptor(this,t)).get||e.set||"function"!=typeof this[t]?delete this[t]:this[t]=w);X=null,Q=[],tt=[],it=[],W=[],nt.length=0,st.length=0,L(I),I=0,ht=!0},this.isDestroyed=function(){return ht},this.incompatible=function(t){var e,i,r=!1;if(r=J.incompatible(t))return r;if(!t){for(e in g)if(g.hasOwnProperty(e)&&g[e].length&&(i=l[e])&&"function"==typeof i.compatible&&!i.compatible.call(this))return"plugin-"+e;for(e in x)if(x.hasOwnProperty(e)&&x[e].length&&(i=p[e])&&"function"==typeof i.compatible&&!i.compatible.call(this))return"source-"+e}return!1},this.isNode=function(t){var e;return!(!t||!(e=Y[t.id])||e.isDestroyed)},this.isSource=function(t){return this.isNode(t)&&t instanceof N},this.isEffect=function(t){return this.isNode(t)&&t instanceof _},this.isTransform=function(t){return this.isNode(t)&&t instanceof F},this.isTarget=function(t){return this.isNode(t)&&t instanceof S},Object.defineProperties(this,{id:{enumerable:!0,configurable:!0,get:function(){return G}}}),this.defaults(i.defaults)}return e.addEventListener("message",(function(t){t.source===e&&"seriously-timeout-message"===t.data&&(t.stopPropagation(),y.length>0&&y.shift()())}),!0),K.prototype.resize=function(t,e){var i=this.gl;this.width===t&&this.height===e||(this.width=t,this.height=e,i&&(i.bindTexture(i.TEXTURE_2D,this.texture),i.bindFramebuffer(i.FRAMEBUFFER,this.frameBuffer),i.bindRenderbuffer(i.RENDERBUFFER,this.renderBuffer),i.texImage2D(i.TEXTURE_2D,0,i.RGBA,t,e,0,i.RGBA,i.UNSIGNED_BYTE,null),i.renderbufferStorage(i.RENDERBUFFER,i.DEPTH_COMPONENT16,t,e),i.framebufferTexture2D(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0,i.TEXTURE_2D,this.texture,0),i.bindTexture(i.TEXTURE_2D,null),i.bindRenderbuffer(i.RENDERBUFFER,null),i.bindFramebuffer(i.FRAMEBUFFER,null)))},K.prototype.destroy=function(){var t=this.gl;t&&(t.deleteFramebuffer(this.frameBuffer),t.deleteRenderbuffer(this.renderBuffer),this.ownTexture&&t.deleteTexture(this.texture)),delete this.frameBuffer,delete this.renderBuffer,delete this.texture,delete this.gl},$.prototype.use=function(){this.gl.useProgram(this.program)},J.incompatible=function(t){var i,r,s;if(void 0===n&&((i=f.createElement("canvas"))&&i.getContext?e.WebGLRenderingContext?(r=Y())||(n="context"):n="webgl":n="canvas"),n)return n;if(t){if((s=l[t])&&"function"==typeof s.compatible&&!s.compatible(r))return"plugin-"+t;if((s=p[t])&&"function"==typeof s.compatible&&!s.compatible(r))return"source-"+t}return!1},J.plugin=function(e,i,r){var n;if(l[e])J.logger.warn("Effect ["+e+"] already loaded");else if(void 0===r&&"object"===t(i)&&(r=i),r)return n=z({},r),"function"==typeof i&&(n.definition=i),n.reserved=S,n.inputs&&Z(n),n.title||(n.title=e),l[e]=n,g[e]=[],n},J.removePlugin=function(t){var e;if(!t)return this;if(!l[t])return this;if(e=g[t]){for(;e.length;)e.shift().destroy();delete g[t]}return delete l[t],this},J.source=function(e,i,r){var n;if(p[e])J.logger.warn("Source ["+e+"] already loaded");else if(void 0===r&&"object"===t(i)&&(r=i),r||i)return n=z({},r),"function"==typeof i&&(n.definition=i),n.title||(n.title=e),p[e]=n,x[e]=[],n},J.removeSource=function(t){var e;if(!t)return this;if(!p[t])return this;if(e=x[t]){for(;e.length;)e.shift().destroy();delete x[t]}return delete p[t],this},J.transform=function(e,i,r){var n;if(d[e])J.logger.warn("Transform ["+e+"] already loaded");else if(void 0===r&&"object"===t(i)&&(r=i),r||i)return n=z({},r),"function"==typeof i&&(n.definition=i),n.reserved=I,n.inputs&&Z(n),n.title||(n.title=e),d[e]=n,v[e]=[],n},J.removeTransform=function(t){var e;if(!t)return this;if(!d[t])return this;if(e=v[t]){for(;e.length;)e.shift().destroy();delete v[t]}return delete d[t],this},J.target=function(e,i,r){var n;if(m[e])J.logger.warn("Target ["+e+"] already loaded");else if(void 0===r&&"object"===t(i)&&(r=i),r||i)return n=z({},r),"function"==typeof i&&(n.definition=i),n.title||(n.title=e),m[e]=n,E[e]=[],n},J.removeTarget=function(t){var e;if(!t)return this;if(!m[t])return this;if(e=E[t]){for(;e.length;)e.shift().destroy();delete E[t]}return delete m[t],this},J.inputValidators={color:function(e,i,n,s){var o,a,u,h;if(a=s||[],"string"==typeof e){if((u=D.exec(e))&&u.length){if(u.length<3)return a[0]=a[1]=a[2]=a[3]=0,a;for(a[3]=1,h=0;h<3;h++)a[h]=parseFloat(u[h+2])/255;return isNaN(u[6])||(a[3]=parseFloat(u[6])),"hsl"===u[1].toLowerCase()?X(a[0],a[1],a[2],a[3],a):a}if((u=A.exec(e))&&u.length)return 3===(o=u[1]).length?(a[0]=parseInt(o[0],16)/15,a[1]=parseInt(o[1],16)/15,a[2]=parseInt(o[2],16)/15,a[3]=1):4===o.length?(a[0]=parseInt(o[0],16)/15,a[1]=parseInt(o[1],16)/15,a[2]=parseInt(o[2],16)/15,a[3]=parseInt(o[3],16)/15):6===o.length?(a[0]=parseInt(o.substr(0,2),16)/255,a[1]=parseInt(o.substr(2,2),16)/255,a[2]=parseInt(o.substr(4,2),16)/255,a[3]=1):8===o.length?(a[0]=parseInt(o.substr(0,2),16)/255,a[1]=parseInt(o.substr(2,2),16)/255,a[2]=parseInt(o.substr(4,2),16)/255,a[3]=parseInt(o.substr(6,2),16)/255):a[0]=a[1]=a[2]=a[3]=0,a;if(u=R[e.toLowerCase()]){for(h=0;h<4;h++)a[h]=u[h];return a}return r||(r=f.createElement("canvas").getContext("2d")),r.fillStyle=e,(o=r.fillStyle)&&"#000000"!==o?J.inputValidators.color(o,i,n,s):(a[0]=a[1]=a[2]=a[3]=0,a)}if(W(e)){if((a=e).length<3)return a[0]=a[1]=a[2]=a[3]=0,a;for(h=0;h<3;h++)if(isNaN(a[h]))return a[0]=a[1]=a[2]=a[3]=0,a;return a.length<4&&a.push(1),a}if("number"==typeof e)return a[0]=a[1]=a[2]=e,a[3]=1,a;if("object"===t(e)){for(h=0;h<4;h++)null===e[o=N[h]]||isNaN(e[o])?a[h]=3===h?1:0:a[h]=e[o];return a}return a[0]=a[1]=a[2]=a[3]=0,a},number:function(t,e,i){return t=parseFloat(t),isNaN(t)?i||0:(e.mod&&(t-=e.mod*Math.floor(t/e.mod)),t<e.min?e.min:t>e.max?e.max:e.step?Math.round(t/e.step)*e.step:t)},enum:function(t,e,i){var r=e.options||[];return"string"==typeof t?t=t.toLowerCase():"number"==typeof t?t=t.toString():t||(t=""),r.hasOwnProperty(t)?t:i||""},vector:function(e,i,r,n){var s,o,a,u=i.dimensions||4;if(s=n||[],W(e)){for(o=0;o<u;o++)s[o]=e[o]||0;return s}if("object"===t(e)){for(o=0;o<u;o++)void 0===e[a=_[o]]&&(a=N[o]),s[o]=e[a]||0;return s}for(e=parseFloat(e)||0,o=0;o<u;o++)s[o]=e;return s},boolean:function(t){return!(!t||t&&t.toLowerCase&&"false"===t.toLowerCase())},string:function(t){return"string"==typeof t?t:0===t||t?t.toString?t.toString():String(t):""}},J.prototype.effects=J.effects=function(){var t,e,i,r,n,s={};for(t in l)if(l.hasOwnProperty(t)){for(n in i={title:(e=l[t]).title||t,description:e.description||"",inputs:{}},e.inputs)e.inputs.hasOwnProperty(n)&&(r=e.inputs[n],i.inputs[n]={type:r.type,defaultValue:r.defaultValue,step:r.step,min:r.min,max:r.max,mod:r.mod,minCount:r.minCount,maxCount:r.maxCount,dimensions:r.dimensions,title:r.title||n,description:r.description||"",options:r.options||[]});s[t]=i}return s},e.Float32Array&&(s=new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])),e.Seriously&&"object"===t(e.Seriously)&&function(){var i;for(i in e.Seriously)e.Seriously.hasOwnProperty(i)&&"plugin"!==i&&"object"===t(e.Seriously[i])&&J.plugin(i,e.Seriously[i])}(),J.logger={log:G("log"),info:G("info"),warn:G("warn"),error:G("error")},J.util={mat4:U,checkSource:q,hslToRgb:X,colors:R,setTimeoutZero:V,ShaderProgram:$,FrameBuffer:K,requestAnimationFrame:B,shader:{makeNoise:"float makeNoise(float u, float v, float timer) {\n\tfloat x = u * v * mod(timer * 1000.0, 100.0);\n\tx = mod(x, 13.0) * mod(x, 127.0);\n\tfloat dx = mod(x, 0.01);\n\treturn clamp(0.1 + dx * 100.0, 0.0, 1.0);\n}\n",random:"#ifndef RANDOM\n#define RANDOM\nfloat random(vec2 n) {\n\treturn 0.5 + 0.5 * fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453);\n}\n#endif\n"}},J.source("video",(function(t,i,r){var n,s,a=this,u=!1,h=!1,c=!1,l=0;function d(){t.removeEventListener("loadedmetadata",d,!0),u||(t.videoWidth?(a.width===t.videoWidth&&a.height===t.videoHeight||(a.width=t.videoWidth,a.height=t.videoHeight,a.resize()),h&&a.setReady()):(h=!0,setTimeout(d,50)))}function p(){c=!0}function m(){c=!1,a.setDirty()}if(k(t,"HTMLVideoElement"))return t.readyState?d():(h=!0,t.addEventListener("loadedmetadata",d,!0)),t.addEventListener("seeking",p,!1),t.addEventListener("seeked",m,!1),{deferTexture:h,source:t,render:function i(r){var u;if(l=t.currentTime,!t.videoHeight||!t.videoWidth)return!1;o?(s||(s=f.createElement("canvas").getContext("2d"),(n=s.canvas).width=a.width,n.height=a.height),u=n,s.drawImage(t,0,0,a.width,a.height)):u=t,r.bindTexture(r.TEXTURE_2D,a.texture),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,a.flip),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);try{if(r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,u),void 0===o){if(r.getError()===r.INVALID_VALUE)return o=!0,i(r);o=!1}return!0}catch(t){t.code===e.DOMException.SECURITY_ERR?(a.allowRefresh=!1,J.logger.error("Unable to access cross-domain image")):J.logger.error("Error rendering video source",t)}return!1},checkDirty:function(){return!c&&t.currentTime!==l},compare:function(t){return a.source===t},destroy:function(){u=!0,t.removeEventListener("seeking",p,!1),t.removeEventListener("seeked",m,!1),t.removeEventListener("loadedmetadata",d,!0)}}}),{title:"Video"}),J.transform("2d",(function(t){var e=this,i=!(t&&t.radians),r=0,n=0,s=1,o=1,a=0,u=0,h=0,f=0,c=0;function l(){var t,l,d,p,m,y,g,v,x,E,b,T=e.matrix;function w(t,e){T[12]=T[0]*t+T[4]*e+T[12],T[13]=T[1]*t+T[5]*e+T[13],T[14]=T[2]*t+T[6]*e+T[14],T[15]=T[3]*t+T[7]*e+T[15]}a||u||h||f||c||1!==s||1!==o?(U.identity(T),w(a+r,u+n),f&&(T[4]=f/e.width),c&&(T[1]=c/e.height),h&&(p=T[0],m=T[1],y=T[2],g=T[3],v=T[4],x=T[5],E=T[6],b=T[7],t=-(i?h*Math.PI/180:h),l=Math.sin(t),d=Math.cos(t),T[0]=p*d+v*l,T[1]=m*d+x*l,T[2]=y*d+E*l,T[3]=g*d+b*l,T[4]=v*d-p*l,T[5]=x*d-m*l,T[6]=E*d-y*l,T[7]=b*d-g*l),1!==s&&(T[0]*=s,T[1]*=s,T[2]*=s,T[3]*=s),1!==o&&(T[4]*=o,T[5]*=o,T[6]*=o,T[7]*=o),w(-r,-n),e.transformed=!0):e.transformed=!1}return{inputs:{reset:{method:function(){return r=0,n=0,s=1,o=1,a=0,u=0,h=0,f=0,c=0,!!e.transformed&&(e.transformed=!1,!0)}},translate:{method:function(t,e){return isNaN(t)&&(t=a),isNaN(e)&&(e=u),(t!==a||e!==u)&&(a=t,u=e,l(),!0)},type:["number","number"]},translateX:{get:function(){return a},set:function(t){return t!==a&&(a=t,l(),!0)},type:"number"},translateY:{get:function(){return u},set:function(t){return t!==u&&(u=t,l(),!0)},type:"number"},rotation:{get:function(){return h},set:function(t){return t!==h&&(h=parseFloat(t),l(),!0)},type:"number"},center:{method:function(t,e){return isNaN(t)&&(t=r),isNaN(e)&&(e=n),(t!==r||e!==n)&&(r=t,n=e,l(),!0)},type:["number","number"]},centerX:{get:function(){return r},set:function(t){return t!==r&&(r=t,l(),!0)},type:"number"},centerY:{get:function(){return n},set:function(t){return t!==n&&(n=t,l(),!0)},type:"number"},skew:{method:function(t,e){return isNaN(t)&&(t=f),isNaN(e)&&(e=c),(t!==f||e!==c)&&(f=t,c=e,l(),!0)},type:["number","number"]},skewX:{get:function(){return f},set:function(t){return t!==f&&(f=t,l(),!0)},type:"number"},skewY:{get:function(){return c},set:function(t){return t!==c&&(c=t,l(),!0)},type:"number"},scale:{method:function(t,e){var i,r;if(i=isNaN(t)?s:t,isNaN(e)){if(isNaN(t))return!1;r=i}else r=e;return(i!==s||r!==o)&&(s=i,o=r,l(),!0)},type:["number","number"]},scaleX:{get:function(){return s},set:function(t){return t!==s&&(s=t,l(),!0)},type:"number"},scaleY:{get:function(){return o},set:function(t){return t!==o&&(o=t,l(),!0)},type:"number"}}}}),{title:"2D Transform",description:"Translate, Rotate, Scale, Skew"}),J.transform("flip",(function(){var t=this,e=!0;function i(){var i=t.matrix;e?(i[0]=-1,i[5]=1):(i[0]=1,i[5]=-1)}return U.identity(t.matrix),i(),t.transformDirty=!0,t.transformed=!0,{inputs:{direction:{get:function(){return e?"horizontal":"vertical"},set:function(t){var r;return(r="vertical"!==t)!==e&&(e=r,i(),!0)},type:"string"}}}}),{title:"Flip",description:"Flip Horizontal/Vertical"}),J.transform("reformat",(function(){var t,e,i=this,r="contain";function n(){var n,s,o,a,u=i.matrix,h=t||i.width,f=e||i.height,c=i.source,l=c&&c.width||1,d=c&&c.height||1;"distort"===r||h===l&&f===d?i.transformed=!1:(o=l/d,a=h/f,"none"===r?(n=l/h,s=d/f):"width"===r||"contain"===r&&a<=o?(n=1,s=a/o):"height"===r||"contain"===r&&a>o?(n=o/a,s=1):a>o?(n=1,s=a/o):(n=o/a,s=1),1!==n||1!==s?(U.identity(u),1!==n&&(u[0]*=n,u[1]*=n,u[2]*=n,u[3]*=n),1!==s&&(u[4]*=s,u[5]*=s,u[6]*=s,u[7]*=s),i.transformed=!0):i.transformed=!1)}function s(){return t||i.source&&i.source.width||1}function o(){return e||i.source&&i.source.height||1}return this.resize=function(){var t,e=s(),i=o();if(this.width!==e||this.height!==i)for(this.width=e,this.height=i,this.uniforms&&this.uniforms.resolution&&(this.uniforms.resolution[0]=e,this.uniforms.resolution[1]=i),this.frameBuffer&&this.frameBuffer.resize&&this.frameBuffer.resize(e,i),t=0;t<this.targets.length;t++)this.targets[t].resize();this.setTransformDirty(),n()},{inputs:{width:{get:s,set:function(e){return(e=Math.floor(e))===t||(t=e,this.resize()),!1},type:"number"},height:{get:o,set:function(t){return(t=Math.floor(t))===e||(e=t,this.resize()),!1},type:"number"},mode:{get:function(){return r},set:function(t){return t!==r&&(r=t,n(),!0)},type:"enum",options:["cover","contain","distort","width","height","none"]}}}}),{title:"Reformat",description:"Change output dimensions"}),a=["precision mediump float;","attribute vec4 position;","attribute vec2 texCoord;","uniform vec2 resolution;","uniform mat4 transform;","varying vec2 vTexCoord;","void main(void) {","\tvec4 screenPosition = vec4(position.xy * resolution / 2.0, position.z, position.w);","\tscreenPosition = transform * screenPosition;","\tgl_Position.xy = screenPosition.xy * 2.0 / resolution;","\tgl_Position.z = screenPosition.z * 2.0 / (resolution.x / resolution.y);","\tgl_Position.w = screenPosition.w;","\tvTexCoord = texCoord;","}\n"].join("\n"),u=["precision mediump float;","varying vec2 vTexCoord;","uniform sampler2D source;","void main(void) {","\t\tgl_FragColor = texture2D(source, vTexCoord);","}"].join("\n"),J.util.shader.noiseHelpers="#ifndef NOISE_HELPERS\n#define NOISE_HELPERS\nvec2 mod289(vec2 x) {\n\treturn x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec3 mod289(vec3 x) {\n\treturn x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec4 mod289(vec4 x) {\n\treturn x - floor(x * (1.0 / 289.0)) * 289.0;\n}\nvec3 permute(vec3 x) {\n\treturn mod289(((x*34.0)+1.0)*x);\n}\nvec4 permute(vec4 x) {\n\treturn mod289(((x*34.0)+1.0)*x);\n}\nvec4 taylorInvSqrt(vec4 r) {\n\treturn 1.79284291400159 - 0.85373472095314 * r;\n}\nfloat taylorInvSqrt(float r) {\n\treturn 1.79284291400159 - 0.85373472095314 * r;\n}\n#endif\n",J.util.shader.snoise2d="#ifndef NOISE2D\n#define NOISE2D\nfloat snoise(vec2 v) {\n\tconst vec4 C = vec4(0.211324865405187, // (3.0-sqrt(3.0))/6.0\n\t\t0.366025403784439, // 0.5*(sqrt(3.0)-1.0)\n\t\t-0.577350269189626, // -1.0 + 2.0 * C.x\n\t\t0.024390243902439); // 1.0 / 41.0\n\tvec2 i = floor(v + dot(v, C.yy));\n\tvec2 x0 = v - i + dot(i, C.xx);\n\tvec2 i1;\n\t//i1.x = step(x0.y, x0.x); // x0.x > x0.y ? 1.0 : 0.0\n\t//i1.y = 1.0 - i1.x;\n\ti1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);\n\t// x0 = x0 - 0.0 + 0.0 * C.xx ;\n\t// x1 = x0 - i1 + 1.0 * C.xx ;\n\t// x2 = x0 - 1.0 + 2.0 * C.xx ;\n\tvec4 x12 = x0.xyxy + C.xxzz;\n\tx12.xy -= i1;\n\ti = mod289(i); // Avoid truncation effects in permutation\n\tvec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));\n\tvec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);\n\tm = m*m ;\n\tm = m*m ;\n\tvec3 x = 2.0 * fract(p * C.www) - 1.0;\n\tvec3 h = abs(x) - 0.5;\n\tvec3 ox = floor(x + 0.5);\n\tvec3 a0 = x - ox;\n\tm *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);\n\tvec3 g;\n\tg.x = a0.x * x0.x + h.x * x0.y;\n\tg.yz = a0.yz * x12.xz + h.yz * x12.yw;\n\treturn 130.0 * dot(m, g);\n}\n#endif\n",J.util.shader.snoise3d="#ifndef NOISE3D\n#define NOISE3D\nfloat snoise(vec3 v) {\n\tconst vec2 C = vec2(1.0/6.0, 1.0/3.0) ;\n\tconst vec4 D = vec4(0.0, 0.5, 1.0, 2.0);\n\tvec3 i = floor(v + dot(v, C.yyy));\n\tvec3 x0 = v - i + dot(i, C.xxx) ;\n\tvec3 g = step(x0.yzx, x0.xyz);\n\tvec3 l = 1.0 - g;\n\tvec3 i1 = min(g.xyz, l.zxy);\n\tvec3 i2 = max(g.xyz, l.zxy);\n\t// x0 = x0 - 0.0 + 0.0 * C.xxx;\n\t// x1 = x0 - i1 + 1.0 * C.xxx;\n\t// x2 = x0 - i2 + 2.0 * C.xxx;\n\t// x3 = x0 - 1.0 + 3.0 * C.xxx;\n\tvec3 x1 = x0 - i1 + C.xxx;\n\tvec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y\n\tvec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y\n\ti = mod289(i);\n\tvec4 p = permute(permute(permute(\n\t\t\t\t\t\ti.z + vec4(0.0, i1.z, i2.z, 1.0))\n\t\t\t\t\t\t+ i.y + vec4(0.0, i1.y, i2.y, 1.0))\n\t\t\t\t\t\t+ i.x + vec4(0.0, i1.x, i2.x, 1.0));\n\tfloat n_ = 0.142857142857; // 1.0/7.0\n\tvec3 ns = n_ * D.wyz - D.xzx;\n\tvec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p, 7 * 7)\n\tvec4 x_ = floor(j * ns.z);\n\tvec4 y_ = floor(j - 7.0 * x_); // mod(j, N)\n\tvec4 x = x_ * ns.x + ns.yyyy;\n\tvec4 y = y_ * ns.x + ns.yyyy;\n\tvec4 h = 1.0 - abs(x) - abs(y);\n\tvec4 b0 = vec4(x.xy, y.xy);\n\tvec4 b1 = vec4(x.zw, y.zw);\n\t//vec4 s0 = vec4(lessThan(b0, 0.0)) * 2.0 - 1.0;\n\t//vec4 s1 = vec4(lessThan(b1, 0.0)) * 2.0 - 1.0;\n\tvec4 s0 = floor(b0) * 2.0 + 1.0;\n\tvec4 s1 = floor(b1) * 2.0 + 1.0;\n\tvec4 sh = -step(h, vec4(0.0));\n\tvec4 a0 = b0.xzyw + s0.xzyw * sh.xxyy ;\n\tvec4 a1 = b1.xzyw + s1.xzyw * sh.zzww ;\n\tvec3 p0 = vec3(a0.xy, h.x);\n\tvec3 p1 = vec3(a0.zw, h.y);\n\tvec3 p2 = vec3(a1.xy, h.z);\n\tvec3 p3 = vec3(a1.zw, h.w);\n\tvec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n\tp0 *= norm.x;\n\tp1 *= norm.y;\n\tp2 *= norm.z;\n\tp3 *= norm.w;\n\tvec4 m = max(0.6 - vec4(dot(x0, x0), dot(x1, x1), dot(x2, x2), dot(x3, x3)), 0.0);\n\tm = m * m;\n\treturn 42.0 * dot(m*m, vec4(dot(p0, x0), dot(p1, x1), dot(p2, x2), dot(p3, x3)));\n}\n#endif\n",J.util.shader.snoise4d="#ifndef NOISE4D\n#define NOISE4D\nvec4 grad4(float j, vec4 ip)\n\t{\n\tconst vec4 ones = vec4(1.0, 1.0, 1.0, -1.0);\n\tvec4 p, s;\n\n\tp.xyz = floor(fract (vec3(j) * ip.xyz) * 7.0) * ip.z - 1.0;\n\tp.w = 1.5 - dot(abs(p.xyz), ones.xyz);\n\ts = vec4(lessThan(p, vec4(0.0)));\n\tp.xyz = p.xyz + (s.xyz*2.0 - 1.0) * s.www;\n\n\treturn p;\n\t}\n\n#define F4 0.309016994374947451\n\nfloat snoise(vec4 v)\n\t{\n\tconst vec4 C = vec4(0.138196601125011, // (5 - sqrt(5))/20 G4\n\t\t\t\t\t\t0.276393202250021, // 2 * G4\n\t\t\t\t\t\t0.414589803375032, // 3 * G4\n\t\t\t\t\t\t-0.447213595499958); // -1 + 4 * G4\n\n\tvec4 i = floor(v + dot(v, vec4(F4)));\n\tvec4 x0 = v - i + dot(i, C.xxxx);\n\n\n\tvec4 i0;\n\tvec3 isX = step(x0.yzw, x0.xxx);\n\tvec3 isYZ = step(x0.zww, x0.yyz);\n\ti0.x = isX.x + isX.y + isX.z;\n\ti0.yzw = 1.0 - isX;\n\ti0.y += isYZ.x + isYZ.y;\n\ti0.zw += 1.0 - isYZ.xy;\n\ti0.z += isYZ.z;\n\ti0.w += 1.0 - isYZ.z;\n\n\tvec4 i3 = clamp(i0, 0.0, 1.0);\n\tvec4 i2 = clamp(i0 - 1.0, 0.0, 1.0);\n\tvec4 i1 = clamp(i0 - 2.0, 0.0, 1.0);\n\n\tvec4 x1 = x0 - i1 + C.xxxx;\n\tvec4 x2 = x0 - i2 + C.yyyy;\n\tvec4 x3 = x0 - i3 + C.zzzz;\n\tvec4 x4 = x0 + C.wwww;\n\n\ti = mod289(i);\n\tfloat j0 = permute(permute(permute(permute(i.w) + i.z) + i.y) + i.x);\n\tvec4 j1 = permute(permute(permute(permute (\n\t\t\t\t\ti.w + vec4(i1.w, i2.w, i3.w, 1.0))\n\t\t\t\t\t+ i.z + vec4(i1.z, i2.z, i3.z, 1.0))\n\t\t\t\t\t+ i.y + vec4(i1.y, i2.y, i3.y, 1.0))\n\t\t\t\t\t+ i.x + vec4(i1.x, i2.x, i3.x, 1.0));\n\n\tvec4 ip = vec4(1.0/294.0, 1.0/49.0, 1.0/7.0, 0.0) ;\n\n\tvec4 p0 = grad4(j0, ip);\n\tvec4 p1 = grad4(j1.x, ip);\n\tvec4 p2 = grad4(j1.y, ip);\n\tvec4 p3 = grad4(j1.z, ip);\n\tvec4 p4 = grad4(j1.w, ip);\n\n\tvec4 norm = taylorInvSqrt(vec4(dot(p0, p0), dot(p1, p1), dot(p2, p2), dot(p3, p3)));\n\tp0 *= norm.x;\n\tp1 *= norm.y;\n\tp2 *= norm.z;\n\tp3 *= norm.w;\n\tp4 *= taylorInvSqrt(dot(p4, p4));\n\n\tvec3 m0 = max(0.6 - vec3(dot(x0, x0), dot(x1, x1), dot(x2, x2)), 0.0);\n\tvec2 m1 = max(0.6 - vec2(dot(x3, x3), dot(x4, x4)), 0.0);\n\tm0 = m0 * m0;\n\tm1 = m1 * m1;\n\treturn 49.0 * (dot(m0*m0, vec3(dot(p0, x0), dot(p1, x1), dot(p2, x2)))\n\t\t\t\t\t\t\t+ dot(m1*m1, vec2(dot(p3, x3), dot(p4, x4)))) ;\n}\n#endif\n",J}(r),r.Seriously||(r.Seriously=n),i.exports=n;var s=e.exports;export{s};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createClass as r,classCallCheck as e}from"../../../_virtual/_rollupPluginBabelHelpers.js";import t from"lodash/isString";import n from"lodash/isObject";import o from"lodash/cloneDeep";var a=function(){function a(){e(this,a)}return r(a,null,[{key:"isJsonStr",value:function(r){if(t(r))try{var e=JSON.parse(r);return!!n(e)}catch(r){return!1}return!1}},{key:"parse",value:function(r){var e={};try{e=JSON.parse(r||"{}")}catch(e){console.error("JSON.parse Error:",r)}return e||{}}},{key:"stringify",value:function(r){var e="";try{e=JSON.stringify(r||{})}catch(e){console.error("JSON.stringify error:",r)}return e||"{}"}},{key:"getParseValue",value:function(r){try{return r&&t(r)?a.parse(r):r}catch(e){return console.info("JSON parse error",r),r}}},{key:"parseObj",value:function(r,e){var t=o(r);return e.forEach((function(e){if(Object.keys(r).includes(e))try{t[e]=a.parse(r[e]),console.log(e,t[e])}catch(r){console.error('Failed to parse JSON for key "'.concat(e,'":'),r)}})),t}},{key:"stringifyObj",value:function(r,e){var t=o(r);return e.forEach((function(e){Object.keys(r).includes(e)&&(t[e]=a.stringify(r[e]))})),t}}]),a}();export{a as default};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{toConsumableArray as r}from"../../../_virtual/_rollupPluginBabelHelpers.js";var e=function(e,n,o){return Promise.race([new Promise((function(r){if(e())var n=setInterval((function(){e()||(clearInterval(n),r())}),o||100);else r()}))].concat(r(n?[new Promise((function(r,e){setTimeout((function(){e(new Error("overtime"))}),n)}))]:[])))};export{e as waitForLoading};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{setTimeout as e,clearTimeout as t}from"../../../node_modules/worker-timers/build/es2019/module.js";import{ReadyState as s,CloseEventCode as n}from"./interface.js";import{createRequestId as o}from"./utils.js";const r=10,i=5e3;function a(a,h={}){let c=a,d=0,l=0,p=0,u=!1,v=h?.reopenDelay??i,f=!0,E=!1,g=0;const y=new Set,S=new Set,m=new Set;function _(){u=!1,d=0,f=!0,v=h?.reopenDelay??i}function C(s){const{reopen:n=!0,reopenAttempts:o=r,reopenDelayIncrease:i,onReopenAttemptEnd:a}=h;if(d>=o||!n)return _(),f&&l&&t(l),void("function"==typeof a&&a(f));v="function"==typeof i?i({reopenCount:d,preDelay:v,isServerClosed:f}):v,p=e((()=>{u=!0,s.open(),d++}),v)}const N={socket:null,messages:[],get readyState(){return this.socket?this.socket.readyState:s.UNINSTANTIATED},get isOpened(){return s.OPEN===this.readyState},get isActive(){return s.CONNECTING===this.readyState||s.OPEN===this.readyState},open(){if(this.isActive)return this;p&&!u&&t(p);const s=this.socket=new WebSocket(c,h?.protocols);return this._dispchReadyStateChangeEvent(),s.addEventListener("open",this._dispchReadyStateChangeEvent),s.addEventListener("close",this._dispchReadyStateChangeEvent),s.addEventListener("error",this._dispchReadyStateChangeEvent),s.onopen=n=>{const{onOpen:o,onMessage:r,combine:a,reopenDelay:c=i}=h;u&&(f?(l&&t(l),l=e(_,c>1e3?c+100:1e3)):_()),o&&o(n),s.onmessage=e=>{r&&r(e);const t=this.deserialization(e.data);a&&y.forEach((e=>{a(e.requestData,t)&&(e.then?(e.then(t),y.delete(e)):e.on?e.on(t):e.responseData=t)})),S.forEach((e=>e(t)))},this.messages.flush(),this._ping()},s.onerror=e=>{h.onError&&h.onError(e),f=!1,C(this)},s.onclose=e=>{e.isInterruptWithNewUrl=E,E=!1,g&&t(g);const{reopenWhenServerClosed:n=!0,onClose:o,onServerClose:r}=h;f&&r&&r(e),o&&o(e),this._dispose(s),f&&n&&C(this)},this},openWithNewUrl(e){return e&&this.isActive&&e===c?this:(c=e||c,s.CONNECTING===this.readyState?(this._dispose(),this.socket?.close()):this.isActive&&this.close(n.CLOSE_INTERRUPT_WITH_NEW_URL,"interrupt by new url"),this.open())},close(e=1e3,t){return this.socket?new Promise((s=>{f=!1,n.CLOSE_INTERRUPT_WITH_NEW_URL===e&&(E=!0);const o=()=>{this.socket?.removeEventListener("close",o),this._dispose(this.socket),s()};this.socket?.addEventListener("close",o),this.socket?.close(e,t),this._dispchReadyStateChangeEvent()})):Promise.resolve()},connect(){return this.open()},disconnect(e,t){return this.close(e,t)},send(e){const{socket:t}=this;if(!t)return this;if(s.CONNECTING===t.readyState)return this.messages.push(e),this;e instanceof Function&&(e=e(o()));const n=this.serialization(e);return t.send(n),this},request(e){if(!h?.combine)throw new Error("Request failed! unconfigured combine, this configuration is required to use the request api.");e instanceof Function&&(e=e(o())),this.send(e);const t={requestData:e,responseData:null};return y.add(t),{then(e){if(t.on&&console.warn('You have already registered for the "on" callback.'),t.responseData){const s=e(t.responseData);return s instanceof Promise?s:Promise.resolve(s)}return new Promise((e=>{t.then=t=>e(t)})).then((t=>e(t)))},on(e,s=!0){t.then&&console.warn('You have already registered for the "then" callback.'),t.on=s=>{e(s,(()=>{y.delete(t)}))},t.responseData&&s&&t.on(t.responseData)}}},receive(){return new Promise((e=>{const t=this.onReceive((s=>{t(),e(s)}))}))},onReceive:e=>(S.add(e),()=>{S.delete(e)}),onMessage(e){return this.onReceive(e)},_dispchReadyStateChangeEvent(){m.forEach((e=>e(this.readyState)))},_dispose(e){(e=e??this.socket)&&(e.removeEventListener("open",this._dispchReadyStateChangeEvent),e.removeEventListener("close",this._dispchReadyStateChangeEvent),e.removeEventListener("error",this._dispchReadyStateChangeEvent),e.onopen=null,e.onclose=null,e.onerror=null)},_ping(){const{keepAlive:s="none"}=h;g&&t(g),"none"!==s&&this.isOpened&&(g=e((()=>{if(!this.isOpened)return;const e=h?.getKeepAliveMessage?h?.getKeepAliveMessage(o()):{requestId:o(),action:"heartbeat"===s?"HEART_BEAT":"PING"};"heartbeat"===h.keepAlive?(this.send(e),this._ping()):this.request(e).then((()=>{this._ping()})).catch((e=>{console.error(e)}))}),h?.keepAliveDelay||3e3))},onReadyStateChange:e=>(m.add(e),()=>{m.delete(e)}),serialization:e=>"[object Object]"===Object.prototype.toString.call(e)||Array.isArray(e)||"number"==typeof e?JSON.stringify(e):e,deserialization(e){if("string"==typeof e){let t=e;try{t=JSON.parse(e)}catch(s){t=e}return t}return e}};return N.messages.flush=function(){const e=[...this];if(this.length=0,e.length)for(const t of e)N.send(t)},N}export{r as DEFAULT_RECONNECT_ATTEMPTS,i as DEFAULT_RECONNECT_DELAY,a as createWebSocket};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var N,E;!function(N){N[N.UNINSTANTIATED=-1]="UNINSTANTIATED",N[N.CONNECTING=0]="CONNECTING",N[N.OPEN=1]="OPEN",N[N.CLOSING=2]="CLOSING",N[N.CLOSED=3]="CLOSED"}(N||(N={})),function(N){N[N.CLOSE_INTERRUPT_WITH_NEW_URL=4e3]="CLOSE_INTERRUPT_WITH_NEW_URL"}(E||(E={}));export{E as CloseEventCode,N as ReadyState};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{v4 as r}from"uuid";function o(){return r()}export{o as createRequestId};
|