🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

@maptalks/video-layer

Package Overview
Dependencies
Maintainers
1
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@maptalks/video-layer - npm Package Compare versions

Comparing version
0.2.2
to
0.2.3
+2
-2
dist/maptalks.video.js
/*!
* @maptalks/video-layer v0.2.2
* @maptalks/video-layer v0.2.3
* LICENSE : UNLICENSED
* (c) 2016-2022 maptalks.org
*/
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("maptalks"),require("@maptalks/gl")):"function"==typeof define&&define.amd?define(["exports","maptalks","@maptalks/gl"],n):n((t=t||self).maptalks=t.maptalks||{},t.maptalks,t.maptalksgl)}(this,function(t,u,c){"use strict";function o(t,n){t.prototype=Object.create(n.prototype),(t.prototype.constructor=t).__proto__=n}for(var O=[],n=0;n<6;n++)O[n]=[];var T=[];function l(t,n,i){var r,e,o,u,a,f,s,h,c,l,v,d,p,m,x,g,w,y,b;e=(r=t)[0],o=r[1],u=r[2],a=r[3],f=r[4],s=r[5],h=r[6],c=r[7],l=r[8],v=r[9],d=r[10],p=r[11],m=r[12],x=r[13],g=r[14],w=r[15],P(O[0],a-e,c-f,p-l,w-m),P(O[1],a+e,c+f,p+l,w+m),P(O[2],a+o,c+s,p+v,w+x),P(O[3],a-o,c-s,p-v,w-x),P(O[4],a-u,c-h,p-d,w-g),P(O[5],a+u,c+h,p+d,w+g);for(var _=0;_<6;_++)if(!i||"0"!==i.charAt(_)){var M=O[_];if(T[0]=0<M[0]?n[1][0]:n[0][0],T[1]=0<M[1]?n[1][1]:n[0][1],T[2]=0<M[2]?n[1][2]:n[0][2],b=T,(y=M)[0]*b[0]+y[1]*b[1]+y[2]*b[2]+y[3]<0)return!1}return!0}var a=1/6;function P(t,n,i,r,e){return t[0]=n*a,t[1]=i*a,t[2]=r*a,t[3]=e*a,t}var e=r,i=r;function r(t,n,i){i=i||2;var r,e,o,u,a,f,s,h=n&&n.length,c=h?n[0]*i:t.length,l=p(t,0,c,i,!0),v=[];if(!l||l.next===l.prev)return v;if(h&&(l=function(t,n,i,r){var e,o,u,a,f,s=[];for(e=0,o=n.length;e<o;e++)u=n[e]*r,a=e<o-1?n[e+1]*r:t.length,(f=p(t,u,a,r,!1))===f.next&&(f.steiner=!0),s.push(_(f));for(s.sort(w),e=0;e<s.length;e++)y(s[e],i),i=m(i,i.next);return i}(t,n,l,i)),t.length>80*i){r=o=t[0],e=u=t[1];for(var d=i;d<c;d+=i)(a=t[d])<r&&(r=a),(f=t[d+1])<e&&(e=f),o<a&&(o=a),u<f&&(u=f);s=0!==(s=Math.max(o-r,u-e))?1/s:0}return x(l,v,i,r,e,s),v}function p(t,n,i,r,e){var o,u;if(e===0<I(t,n,i,r))for(o=n;o<i;o+=r)u=A(o,t[o],t[o+1],u);else for(o=i-r;n<=o;o-=r)u=A(o,t[o],t[o+1],u);return u&&E(u,u.next)&&(R(u),u=u.next),u}function m(t,n){if(!t)return t;n||(n=t);var i,r=t;do{if(i=!1,r.steiner||!E(r,r.next)&&0!==k(r.prev,r,r.next))r=r.next;else{if(R(r),(r=n=r.prev)===r.next)break;i=!0}}while(i||r!==n);return n}function x(t,n,i,r,e,o,u){if(t){!u&&o&&function(t,n,i,r){var e=t;for(;null===e.z&&(e.z=b(e.x,e.y,n,i,r)),e.prevZ=e.prev,e.nextZ=e.next,e=e.next,e!==t;);e.prevZ.nextZ=null,e.prevZ=null,function(t){var n,i,r,e,o,u,a,f,s=1;do{for(i=t,o=t=null,u=0;i;){for(u++,r=i,n=a=0;n<s&&(a++,r=r.nextZ);n++);for(f=s;0<a||0<f&&r;)0!==a&&(0===f||!r||i.z<=r.z)?(i=(e=i).nextZ,a--):(r=(e=r).nextZ,f--),o?o.nextZ=e:t=e,e.prevZ=o,o=e;i=r}o.nextZ=null,s*=2}while(1<u)}(e)}(t,r,e,o);for(var a,f,s=t;t.prev!==t.next;)if(a=t.prev,f=t.next,o?v(t,r,e,o):h(t))n.push(a.i/i),n.push(t.i/i),n.push(f.i/i),R(t),t=f.next,s=f.next;else if((t=f)===s){u?1===u?x(t=d(m(t),n,i),n,i,r,e,o,2):2===u&&g(t,n,i,r,e,o):x(m(t),n,i,r,e,o,1);break}}}function h(t){var n=t.prev,i=t,r=t.next;if(0<=k(n,i,r))return!1;for(var e=t.next.next;e!==t.prev;){if(M(n.x,n.y,i.x,i.y,r.x,r.y,e.x,e.y)&&0<=k(e.prev,e,e.next))return!1;e=e.next}return!0}function v(t,n,i,r){var e=t.prev,o=t,u=t.next;if(0<=k(e,o,u))return!1;for(var a=e.x<o.x?e.x<u.x?e.x:u.x:o.x<u.x?o.x:u.x,f=e.y<o.y?e.y<u.y?e.y:u.y:o.y<u.y?o.y:u.y,s=e.x>o.x?e.x>u.x?e.x:u.x:o.x>u.x?o.x:u.x,h=e.y>o.y?e.y>u.y?e.y:u.y:o.y>u.y?o.y:u.y,c=b(a,f,n,i,r),l=b(s,h,n,i,r),v=t.prevZ,d=t.nextZ;v&&v.z>=c&&d&&d.z<=l;){if(v!==t.prev&&v!==t.next&&M(e.x,e.y,o.x,o.y,u.x,u.y,v.x,v.y)&&0<=k(v.prev,v,v.next))return!1;if(v=v.prevZ,d!==t.prev&&d!==t.next&&M(e.x,e.y,o.x,o.y,u.x,u.y,d.x,d.y)&&0<=k(d.prev,d,d.next))return!1;d=d.nextZ}for(;v&&v.z>=c;){if(v!==t.prev&&v!==t.next&&M(e.x,e.y,o.x,o.y,u.x,u.y,v.x,v.y)&&0<=k(v.prev,v,v.next))return!1;v=v.prevZ}for(;d&&d.z<=l;){if(d!==t.prev&&d!==t.next&&M(e.x,e.y,o.x,o.y,u.x,u.y,d.x,d.y)&&0<=k(d.prev,d,d.next))return!1;d=d.nextZ}return!0}function d(t,n,i){var r=t;do{var e=r.prev,o=r.next.next;!E(e,o)&&S(e,r,r.next,o)&&C(e,o)&&C(o,e)&&(n.push(e.i/i),n.push(r.i/i),n.push(o.i/i),R(r),R(r.next),r=t=o),r=r.next}while(r!==t);return m(r)}function g(t,n,i,r,e,o){var u,a,f=t;do{for(var s=f.next.next;s!==f.prev;){if(f.i!==s.i&&(a=s,(u=f).next.i!==a.i&&u.prev.i!==a.i&&!function(t,n){var i=t;do{if(i.i!==t.i&&i.next.i!==t.i&&i.i!==n.i&&i.next.i!==n.i&&S(i,i.next,t,n))return!0;i=i.next}while(i!==t);return!1}(u,a)&&(C(u,a)&&C(a,u)&&function(t,n){var i=t,r=!1,e=(t.x+n.x)/2,o=(t.y+n.y)/2;for(;i.y>o!=i.next.y>o&&i.next.y!==i.y&&e<(i.next.x-i.x)*(o-i.y)/(i.next.y-i.y)+i.x&&(r=!r),i=i.next,i!==t;);return r}(u,a)&&(k(u.prev,u,a.prev)||k(u,a.prev,a))||E(u,a)&&0<k(u.prev,u,u.next)&&0<k(a.prev,a,a.next)))){var h=j(f,s);return f=m(f,f.next),h=m(h,h.next),x(f,n,i,r,e,o),void x(h,n,i,r,e,o)}s=s.next}f=f.next}while(f!==t)}function w(t,n){return t.x-n.x}function y(t,n){if(n=function(t,n){var i,r=n,e=t.x,o=t.y,u=-1/0;do{if(o<=r.y&&o>=r.next.y&&r.next.y!==r.y){var a=r.x+(o-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(a<=e&&u<a){if((u=a)===e){if(o===r.y)return r;if(o===r.next.y)return r.next}i=r.x<r.next.x?r:r.next}}r=r.next}while(r!==n);if(!i)return null;if(e===u)return i;var f,s=i,h=i.x,c=i.y,l=1/0;r=i;for(;e>=r.x&&r.x>=h&&e!==r.x&&M(o<c?e:u,o,h,c,o<c?u:e,o,r.x,r.y)&&(f=Math.abs(o-r.y)/(e-r.x),C(r,t)&&(f<l||f===l&&(r.x>i.x||r.x===i.x&&(d=r,k((v=i).prev,v,d.prev)<0&&k(d.next,v,v.next)<0)))&&(i=r,l=f)),r=r.next,r!==s;);var v,d;return i}(t,n)){var i=j(n,t);m(n,n.next),m(i,i.next)}}function b(t,n,i,r,e){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-i)*e)|t<<8))|t<<4))|t<<2))|t<<1))|(n=1431655765&((n=858993459&((n=252645135&((n=16711935&((n=32767*(n-r)*e)|n<<8))|n<<4))|n<<2))|n<<1))<<1}function _(t){for(var n=t,i=t;(n.x<i.x||n.x===i.x&&n.y<i.y)&&(i=n),(n=n.next)!==t;);return i}function M(t,n,i,r,e,o,u,a){return 0<=(e-u)*(n-a)-(t-u)*(o-a)&&0<=(t-u)*(r-a)-(i-u)*(n-a)&&0<=(i-u)*(o-a)-(e-u)*(r-a)}function k(t,n,i){return(n.y-t.y)*(i.x-n.x)-(n.x-t.x)*(i.y-n.y)}function E(t,n){return t.x===n.x&&t.y===n.y}function S(t,n,i,r){var e=s(k(t,n,i)),o=s(k(t,n,r)),u=s(k(i,r,t)),a=s(k(i,r,n));return e!==o&&u!==a||(!(0!==e||!f(t,i,n))||(!(0!==o||!f(t,r,n))||(!(0!==u||!f(i,t,r))||!(0!==a||!f(i,n,r)))))}function f(t,n,i){return n.x<=Math.max(t.x,i.x)&&n.x>=Math.min(t.x,i.x)&&n.y<=Math.max(t.y,i.y)&&n.y>=Math.min(t.y,i.y)}function s(t){return 0<t?1:t<0?-1:0}function C(t,n){return k(t.prev,t,t.next)<0?0<=k(t,n,t.next)&&0<=k(t,t.prev,n):k(t,n,t.prev)<0||k(t,t.next,n)<0}function j(t,n){var i=new V(t.i,t.x,t.y),r=new V(n.i,n.x,n.y),e=t.next,o=n.prev;return(t.next=n).prev=t,(i.next=e).prev=i,(r.next=i).prev=r,(o.next=r).prev=o,r}function A(t,n,i,r){var e=new V(t,n,i);return r?(e.next=r.next,(e.prev=r).next.prev=e,r.next=e):(e.prev=e).next=e,e}function R(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function V(t,n,i){this.i=t,this.x=n,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function I(t,n,i,r){for(var e=0,o=n,u=i-r;o<i;o+=r)e+=(t[u]-t[o])*(t[o+1]+t[u+1]),u=o;return e}r.deviation=function(t,n,i,r){var e=n&&n.length,o=e?n[0]*i:t.length,u=Math.abs(I(t,0,o,i));if(e)for(var a=0,f=n.length;a<f;a++){var s=n[a]*i,h=a<f-1?n[a+1]*i:t.length;u-=Math.abs(I(t,s,h,i))}var c=0;for(a=0;a<r.length;a+=3){var l=r[a]*i,v=r[a+1]*i,d=r[a+2]*i;c+=Math.abs((t[l]-t[d])*(t[v+1]-t[l+1])-(t[l]-t[v])*(t[d+1]-t[l+1]))}return 0===u&&0===c?0:Math.abs((c-u)/u)},r.flatten=function(t){for(var n=t[0][0].length,i={vertices:[],holes:[],dimensions:n},r=0,e=0;e<t.length;e++){for(var o=0;o<t[e].length;o++)for(var u=0;u<n;u++)i.vertices.push(t[e][o][u]);0<e&&(r+=t[e-1].length,i.holes.push(r))}return i},e.default=i;var N={vert:"\n attribute vec3 aPosition;\n attribute vec2 aTexCoord;\n uniform mat4 projViewModelMatrix;\n uniform mat4 positionMatrix;\n uniform mat4 modelMatrix;\n varying vec2 vTexCoords;\n #include <get_output>\n void main()\n {\n mat4 localPositionMatrix = getPositionMatrix();\n vec4 localPosition = getPosition(aPosition);\n gl_Position = projViewModelMatrix * localPositionMatrix * localPosition;\n vTexCoords = aTexCoord;\n }\n",frag:"\n precision mediump float;\n uniform sampler2D videoTexture;\n uniform float opacity;\n\n varying vec2 vTexCoords;\n void main() {\n vec4 color = texture2D(videoTexture, vTexCoords);\n gl_FragColor = color * opacity;\n }\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:function(t,n){return c.mat4.multiply([],n.projViewMatrix,n.modelMatrix)}},"texture","opacity"],positionAttribute:"POSITION",extraCommandProps:{depth:{enable:!0,func:"always",mask:!1,range:[0,0]},cull:{enable:!1,face:"back"},frontFace:"cw",blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"}}},D=function(i){function t(t){var n;return(n=i.call(this,t)||this).t(),n.n={},n}o(t,i);var n=t.prototype;return n.draw=function(t,n){this.prepareCanvas(),this.r(n)},n.drawOnInteracting=function(t,n,i){this.r(i)},n.needToRedraw=function(){return!0},n.hitDetect=function(){return!1},n.createContext=function(){if(this.canvas.gl&&this.canvas.gl.wrap)this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl;else{var t=this.layer.options.glOptions||{alpha:!0,depth:!0,stencil:!0};this.glOptions=t,this.gl=this.gl||this.e(this.canvas,t),this.regl=c.createREGL({gl:this.gl,extensions:["ANGLE_instanced_arrays","OES_texture_float","OES_texture_half_float","OES_texture_float_linear","OES_texture_half_float_linear","EXT_shader_texture_lod","OES_element_index_uint","OES_standard_derivatives","WEBGL_depth_texture"],optionalExtensions:this.layer.options.glExtensions||[]})}this.o();for(var n=this.layer.getVideoSurfaces(),i=0;i<n.length;i++)this.u(n[i])},n.e=function(t,n){for(var i=["webgl","experimental-webgl"],r=null,e=0;e<i.length;++e){try{r=t.getContext(i[e],n)}catch(t){}if(r)break}return r},n.o=function(){var t=this.layer.getMap(),n=new c.reshader.Renderer(this.regl);this.renderer=n,this.a={projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,viewMatrix:t.viewMatrix,halton:[.2107,-.0202],uHalton:[.2107,-.0202],uCameraPosition:t.cameraPosition,cameraPosition:t.cameraPosition,globalTexSize:[t.width,t.height]}},n.f=function(){return this.regl},n.t=function(){var t=this;this.viewport={x:0,y:0,width:function(){return t.canvas?t.canvas.width:1},height:function(){return t.canvas?t.canvas.height:1}},this.s=new c.reshader.MeshShader(N)},n.u=function(t){var n=this.regl.texture(),i=new c.reshader.Material({videoTexture:n,opacity:1}),r=t.getCoordinates(),e=this.h(r),o=new c.reshader.Mesh(e,i);this.c(o);var u=new c.reshader.Scene(o),a=t.l();this.n[a]=u},n.v=function(t){var n=t.l(),i=this.n[n].getMeshes()[0],r=t.getCoordinates();i.geometry.dispose();var e=this.h(r);i.geometry=e},n.r=function(t){var n=this.layer.getVideoSurfaces().filter(function(t){return t.isVisible()});if(n.length){var i=this.d(n);if(i){var r=null;t&&(r=t.renderTarget&&t.renderTarget.fbo),this.renderer.render(this.s,this.a,i,r)}}},n.h=function(t){var n=new u.Polygon(t).getCenter(),i=this.p(n,t),r=e(i,null,3);return new c.reshader.Geometry({POSITION:i,TEXCOORD:[0,0,1,0,1,1,0,1]},r,0,{primitive:"triangles",positionAttribute:"POSITION",uv0Attribute:"TEXCOORD",normalAttribute:"NORMAL",positionSize:3})},n.p=function(t,n){var r=[],e=this.getMap(),o=F(e,t,0);return this.m=o,e&&n.forEach(function(t){var n=new u.Coordinate(t[0],t[1]),i=F(e,n,t[2]);i[0]=i[0]-o[0],i[1]=i[1]-o[1],r=r.concat(i)}),r},n.d=function(t){for(var n=[],i=this.layer.getMap(),r=0;r<t.length;r++){var e=t[r],o=this.n[e.l()];if(o)for(var u=o.getMeshes(),a=0;a<u.length;a++){var f=u[a],s=f.getMaterial(),h=s.get("videoTexture");h&&e.g()&&(h(e.video),s.set("opacity",e.getOpacity())),this.c(f),l(i.projViewMatrix,f.getBoundingBox())&&n.push(f)}}return n.length?new c.reshader.Scene(n):null},n.c=function(t){c.mat4.fromRotationTranslationScale(t.localTransform,c.quat.fromEuler([],0,0,0),this.m,[1,1,1])},n.clearCanvas=function(){this.canvas&&(this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),i.prototype.clearCanvas.call(this))},n.w=function(t){var n=this.n[t];n&&n.getMeshes().forEach(function(t){t.geometry.dispose(),t.material&&t.material.dispose(),t.dispose()})},t}(u.renderer.CanvasRenderer);function F(t,n,i){if(!t)return null;var r=t.coordinateToPointAtRes(n,t.getGLRes());return[r.x,r.y,i]}var L=function(e){function t(t,n,i){var r;return(r=e.call(this,t,i)||this).b={},r.videoId=0,r.addSurfaces(n),r}o(t,e);var n=t.prototype;return n.addSurfaces=function(n){var i=this;if(n)if(Array.isArray(n))n.forEach(function(t){i.addMarker(t)});else{((n.M=this).b[this.videoId]=n)._(this.videoId);var t=this.getRenderer();t?t.f()&&t.u(n):this.on("renderercreate",function(t){t.renderer.f()&&t.renderer.u(n)}),this.videoId++}},n.getVideoSurfaces=function(){var t=[];for(var n in this.b)t.push(this.b[n]);return t},n.removeVideoSurfaces=function(t){var n=this;if(Array.isArray(t))t.forEach(function(t){n.removeVideoSurfaces(t)});else{var i=t.l(),r=this.getRenderer();r&&r.w(i),delete this.b[i]}},n.clear=function(){for(var t=this.getVideoSurfaces(),n=0;n<t.length;n++)this.removeVideoSurfaces(t[n])},t}(u.Layer);L.mergeOptions({renderer:"gl",doubleBuffer:!1,glOptions:null,markerEvents:!0,forceRenderOnZooming:!0,forceRenderOnMoving:!0,forceRenderOnRotating:!0}),L.registerJSONType("VideoLayer"),L.registerRenderer("gl",D);var q=function(r){function t(t,n){var i;return(i=r.call(this,n)||this).setCoordinates(t),i.setVideo(i.options.url),i}o(t,r);var n=t.prototype;return n.setCoordinates=function(t){this.O=t},n.getCoordinates=function(){return this.O},n.setVideo=function(t){var n=this;this.options.url=t;var i=document.createElement("video");i.src=t,i.autoplay=!0,i.loop=!0,i.muted=!0,i.play(),i.addEventListener("playing",function(){n.T="playing"}),i.addEventListener("pause",function(){n.T="pause"}),this.video=i},n.getVideo=function(){return this.video},n._=function(t){this.P=t},n.l=function(){return this.P},n.addTo=function(t){if(this.M)throw new Error("VideoSurface cannot be added to two or more layers at the same time.");return t.addSurfaces(this),this},n.show=function(){return this.options.visible=!0,this},n.hide=function(){return this.options.visible=!1,this},n.isVisible=function(){return this.options.visible},n.play=function(){this.video&&this.video.play()},n.pause=function(){this.video&&this.video.pause()},n.setAudio=function(t){this.video.muted=t},n.setOpacity=function(t){this.options.opacity=t},n.getOpacity=function(){return this.options.opacity},n.remove=function(){var t=this.getLayer();t&&t.removeVideoSurfaces(this)},n.getLayer=function(){return this.M},n.g=function(){return"playing"===this.T||"pause"===this.T},n.startEdit=function(){var i=this,r=this.getLayer();if(r){var t=r.getMap();if(t){if(!this.k){var n=r.getId();this.k=new u.VectorLayer("internal_"+n+"_edit").addTo(t)}var e=this.getCoordinates();this.S=new u.Polygon(e,{symbol:{lineColor:"#34495e",lineWidth:2,polygonFill:"rgb(135,196,240)",polygonOpacity:.1}}).addTo(this.k),this.S.startEdit({newVertexHandleSymbol:{polygonFill:"rgba(0, 0, 0, 0)",polygonOpacity:0,markerType:"ellipse",markerWidth:1,markerHeight:1}}),this.S.on("shapechange",function(t){var n=t.target.getCoordinates()[0].slice(0,4).map(function(t){return[t.x,t.y,0]});i.setCoordinates(n),r.getRenderer().v(i)},this)}else console.warn("videosurface should be added to a map before edit")}else console.warn("videosurface should be added to a map before edit")},n.endEdit=function(){this.k&&(this.S.endEdit(),this.S.remove(),this.k.remove()),delete this.k,delete this.S},t}(u.Eventable(u.Handlerable(u.Class)));q.mergeOptions({opacity:1,visible:!0}),t.VideoLayer=L,t.VideoSurface=q,Object.defineProperty(t,"C",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/video-layer v0.2.2")});
!function(t,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("maptalks"),require("@maptalks/gl")):"function"==typeof define&&define.amd?define(["exports","maptalks","@maptalks/gl"],n):n((t=t||self).maptalks=t.maptalks||{},t.maptalks,t.maptalksgl)}(this,function(t,u,c){"use strict";function o(t,n){t.prototype=Object.create(n.prototype),(t.prototype.constructor=t).__proto__=n}for(var O=[],n=0;n<6;n++)O[n]=[];var T=[];function l(t,n,i){var r,e,o,u,a,f,s,h,c,l,v,d,p,m,x,g,w,y,b;e=(r=t)[0],o=r[1],u=r[2],a=r[3],f=r[4],s=r[5],h=r[6],c=r[7],l=r[8],v=r[9],d=r[10],p=r[11],m=r[12],x=r[13],g=r[14],w=r[15],P(O[0],a-e,c-f,p-l,w-m),P(O[1],a+e,c+f,p+l,w+m),P(O[2],a+o,c+s,p+v,w+x),P(O[3],a-o,c-s,p-v,w-x),P(O[4],a-u,c-h,p-d,w-g),P(O[5],a+u,c+h,p+d,w+g);for(var _=0;_<6;_++)if(!i||"0"!==i.charAt(_)){var M=O[_];if(T[0]=0<M[0]?n[1][0]:n[0][0],T[1]=0<M[1]?n[1][1]:n[0][1],T[2]=0<M[2]?n[1][2]:n[0][2],b=T,(y=M)[0]*b[0]+y[1]*b[1]+y[2]*b[2]+y[3]<0)return!1}return!0}var a=1/6;function P(t,n,i,r,e){return t[0]=n*a,t[1]=i*a,t[2]=r*a,t[3]=e*a,t}var e=r,i=r;function r(t,n,i){i=i||2;var r,e,o,u,a,f,s,h=n&&n.length,c=h?n[0]*i:t.length,l=p(t,0,c,i,!0),v=[];if(!l||l.next===l.prev)return v;if(h&&(l=function(t,n,i,r){var e,o,u,a,f,s=[];for(e=0,o=n.length;e<o;e++)u=n[e]*r,a=e<o-1?n[e+1]*r:t.length,(f=p(t,u,a,r,!1))===f.next&&(f.steiner=!0),s.push(_(f));for(s.sort(w),e=0;e<s.length;e++)y(s[e],i),i=m(i,i.next);return i}(t,n,l,i)),t.length>80*i){r=o=t[0],e=u=t[1];for(var d=i;d<c;d+=i)(a=t[d])<r&&(r=a),(f=t[d+1])<e&&(e=f),o<a&&(o=a),u<f&&(u=f);s=0!==(s=Math.max(o-r,u-e))?1/s:0}return x(l,v,i,r,e,s),v}function p(t,n,i,r,e){var o,u;if(e===0<I(t,n,i,r))for(o=n;o<i;o+=r)u=A(o,t[o],t[o+1],u);else for(o=i-r;n<=o;o-=r)u=A(o,t[o],t[o+1],u);return u&&E(u,u.next)&&(R(u),u=u.next),u}function m(t,n){if(!t)return t;n||(n=t);var i,r=t;do{if(i=!1,r.steiner||!E(r,r.next)&&0!==k(r.prev,r,r.next))r=r.next;else{if(R(r),(r=n=r.prev)===r.next)break;i=!0}}while(i||r!==n);return n}function x(t,n,i,r,e,o,u){if(t){!u&&o&&function(t,n,i,r){var e=t;for(;null===e.z&&(e.z=b(e.x,e.y,n,i,r)),e.prevZ=e.prev,e.nextZ=e.next,e=e.next,e!==t;);e.prevZ.nextZ=null,e.prevZ=null,function(t){var n,i,r,e,o,u,a,f,s=1;do{for(i=t,o=t=null,u=0;i;){for(u++,r=i,n=a=0;n<s&&(a++,r=r.nextZ);n++);for(f=s;0<a||0<f&&r;)0!==a&&(0===f||!r||i.z<=r.z)?(i=(e=i).nextZ,a--):(r=(e=r).nextZ,f--),o?o.nextZ=e:t=e,e.prevZ=o,o=e;i=r}o.nextZ=null,s*=2}while(1<u)}(e)}(t,r,e,o);for(var a,f,s=t;t.prev!==t.next;)if(a=t.prev,f=t.next,o?v(t,r,e,o):h(t))n.push(a.i/i),n.push(t.i/i),n.push(f.i/i),R(t),t=f.next,s=f.next;else if((t=f)===s){u?1===u?x(t=d(m(t),n,i),n,i,r,e,o,2):2===u&&g(t,n,i,r,e,o):x(m(t),n,i,r,e,o,1);break}}}function h(t){var n=t.prev,i=t,r=t.next;if(0<=k(n,i,r))return!1;for(var e=t.next.next;e!==t.prev;){if(M(n.x,n.y,i.x,i.y,r.x,r.y,e.x,e.y)&&0<=k(e.prev,e,e.next))return!1;e=e.next}return!0}function v(t,n,i,r){var e=t.prev,o=t,u=t.next;if(0<=k(e,o,u))return!1;for(var a=e.x<o.x?e.x<u.x?e.x:u.x:o.x<u.x?o.x:u.x,f=e.y<o.y?e.y<u.y?e.y:u.y:o.y<u.y?o.y:u.y,s=e.x>o.x?e.x>u.x?e.x:u.x:o.x>u.x?o.x:u.x,h=e.y>o.y?e.y>u.y?e.y:u.y:o.y>u.y?o.y:u.y,c=b(a,f,n,i,r),l=b(s,h,n,i,r),v=t.prevZ,d=t.nextZ;v&&v.z>=c&&d&&d.z<=l;){if(v!==t.prev&&v!==t.next&&M(e.x,e.y,o.x,o.y,u.x,u.y,v.x,v.y)&&0<=k(v.prev,v,v.next))return!1;if(v=v.prevZ,d!==t.prev&&d!==t.next&&M(e.x,e.y,o.x,o.y,u.x,u.y,d.x,d.y)&&0<=k(d.prev,d,d.next))return!1;d=d.nextZ}for(;v&&v.z>=c;){if(v!==t.prev&&v!==t.next&&M(e.x,e.y,o.x,o.y,u.x,u.y,v.x,v.y)&&0<=k(v.prev,v,v.next))return!1;v=v.prevZ}for(;d&&d.z<=l;){if(d!==t.prev&&d!==t.next&&M(e.x,e.y,o.x,o.y,u.x,u.y,d.x,d.y)&&0<=k(d.prev,d,d.next))return!1;d=d.nextZ}return!0}function d(t,n,i){var r=t;do{var e=r.prev,o=r.next.next;!E(e,o)&&S(e,r,r.next,o)&&C(e,o)&&C(o,e)&&(n.push(e.i/i),n.push(r.i/i),n.push(o.i/i),R(r),R(r.next),r=t=o),r=r.next}while(r!==t);return m(r)}function g(t,n,i,r,e,o){var u,a,f=t;do{for(var s=f.next.next;s!==f.prev;){if(f.i!==s.i&&(a=s,(u=f).next.i!==a.i&&u.prev.i!==a.i&&!function(t,n){var i=t;do{if(i.i!==t.i&&i.next.i!==t.i&&i.i!==n.i&&i.next.i!==n.i&&S(i,i.next,t,n))return!0;i=i.next}while(i!==t);return!1}(u,a)&&(C(u,a)&&C(a,u)&&function(t,n){var i=t,r=!1,e=(t.x+n.x)/2,o=(t.y+n.y)/2;for(;i.y>o!=i.next.y>o&&i.next.y!==i.y&&e<(i.next.x-i.x)*(o-i.y)/(i.next.y-i.y)+i.x&&(r=!r),i=i.next,i!==t;);return r}(u,a)&&(k(u.prev,u,a.prev)||k(u,a.prev,a))||E(u,a)&&0<k(u.prev,u,u.next)&&0<k(a.prev,a,a.next)))){var h=j(f,s);return f=m(f,f.next),h=m(h,h.next),x(f,n,i,r,e,o),void x(h,n,i,r,e,o)}s=s.next}f=f.next}while(f!==t)}function w(t,n){return t.x-n.x}function y(t,n){if(n=function(t,n){var i,r=n,e=t.x,o=t.y,u=-1/0;do{if(o<=r.y&&o>=r.next.y&&r.next.y!==r.y){var a=r.x+(o-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(a<=e&&u<a){if((u=a)===e){if(o===r.y)return r;if(o===r.next.y)return r.next}i=r.x<r.next.x?r:r.next}}r=r.next}while(r!==n);if(!i)return null;if(e===u)return i;var f,s=i,h=i.x,c=i.y,l=1/0;r=i;for(;e>=r.x&&r.x>=h&&e!==r.x&&M(o<c?e:u,o,h,c,o<c?u:e,o,r.x,r.y)&&(f=Math.abs(o-r.y)/(e-r.x),C(r,t)&&(f<l||f===l&&(r.x>i.x||r.x===i.x&&(d=r,k((v=i).prev,v,d.prev)<0&&k(d.next,v,v.next)<0)))&&(i=r,l=f)),r=r.next,r!==s;);var v,d;return i}(t,n)){var i=j(n,t);m(n,n.next),m(i,i.next)}}function b(t,n,i,r,e){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-i)*e)|t<<8))|t<<4))|t<<2))|t<<1))|(n=1431655765&((n=858993459&((n=252645135&((n=16711935&((n=32767*(n-r)*e)|n<<8))|n<<4))|n<<2))|n<<1))<<1}function _(t){for(var n=t,i=t;(n.x<i.x||n.x===i.x&&n.y<i.y)&&(i=n),(n=n.next)!==t;);return i}function M(t,n,i,r,e,o,u,a){return 0<=(e-u)*(n-a)-(t-u)*(o-a)&&0<=(t-u)*(r-a)-(i-u)*(n-a)&&0<=(i-u)*(o-a)-(e-u)*(r-a)}function k(t,n,i){return(n.y-t.y)*(i.x-n.x)-(n.x-t.x)*(i.y-n.y)}function E(t,n){return t.x===n.x&&t.y===n.y}function S(t,n,i,r){var e=s(k(t,n,i)),o=s(k(t,n,r)),u=s(k(i,r,t)),a=s(k(i,r,n));return e!==o&&u!==a||(!(0!==e||!f(t,i,n))||(!(0!==o||!f(t,r,n))||(!(0!==u||!f(i,t,r))||!(0!==a||!f(i,n,r)))))}function f(t,n,i){return n.x<=Math.max(t.x,i.x)&&n.x>=Math.min(t.x,i.x)&&n.y<=Math.max(t.y,i.y)&&n.y>=Math.min(t.y,i.y)}function s(t){return 0<t?1:t<0?-1:0}function C(t,n){return k(t.prev,t,t.next)<0?0<=k(t,n,t.next)&&0<=k(t,t.prev,n):k(t,n,t.prev)<0||k(t,t.next,n)<0}function j(t,n){var i=new V(t.i,t.x,t.y),r=new V(n.i,n.x,n.y),e=t.next,o=n.prev;return(t.next=n).prev=t,(i.next=e).prev=i,(r.next=i).prev=r,(o.next=r).prev=o,r}function A(t,n,i,r){var e=new V(t,n,i);return r?(e.next=r.next,(e.prev=r).next.prev=e,r.next=e):(e.prev=e).next=e,e}function R(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function V(t,n,i){this.i=t,this.x=n,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function I(t,n,i,r){for(var e=0,o=n,u=i-r;o<i;o+=r)e+=(t[u]-t[o])*(t[o+1]+t[u+1]),u=o;return e}r.deviation=function(t,n,i,r){var e=n&&n.length,o=e?n[0]*i:t.length,u=Math.abs(I(t,0,o,i));if(e)for(var a=0,f=n.length;a<f;a++){var s=n[a]*i,h=a<f-1?n[a+1]*i:t.length;u-=Math.abs(I(t,s,h,i))}var c=0;for(a=0;a<r.length;a+=3){var l=r[a]*i,v=r[a+1]*i,d=r[a+2]*i;c+=Math.abs((t[l]-t[d])*(t[v+1]-t[l+1])-(t[l]-t[v])*(t[d+1]-t[l+1]))}return 0===u&&0===c?0:Math.abs((c-u)/u)},r.flatten=function(t){for(var n=t[0][0].length,i={vertices:[],holes:[],dimensions:n},r=0,e=0;e<t.length;e++){for(var o=0;o<t[e].length;o++)for(var u=0;u<n;u++)i.vertices.push(t[e][o][u]);0<e&&(r+=t[e-1].length,i.holes.push(r))}return i},e.default=i;var N={vert:"\n attribute vec3 aPosition;\n attribute vec2 aTexCoord;\n uniform mat4 projViewModelMatrix;\n uniform mat4 positionMatrix;\n uniform mat4 modelMatrix;\n varying vec2 vTexCoords;\n #include <get_output>\n void main()\n {\n mat4 localPositionMatrix = getPositionMatrix();\n vec4 localPosition = getPosition(aPosition);\n gl_Position = projViewModelMatrix * localPositionMatrix * localPosition;\n vTexCoords = aTexCoord;\n }\n",frag:"\n precision mediump float;\n uniform sampler2D videoTexture;\n uniform float opacity;\n\n varying vec2 vTexCoords;\n void main() {\n vec4 color = texture2D(videoTexture, vTexCoords);\n gl_FragColor = color * opacity;\n }\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:function(t,n){return c.mat4.multiply([],n.projViewMatrix,n.modelMatrix)}},"texture","opacity"],positionAttribute:"POSITION",extraCommandProps:{depth:{enable:!0,func:"always",mask:!1,range:[0,0]},cull:{enable:!1,face:"back"},frontFace:"cw",blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"}}},D=function(i){function t(t){var n;return(n=i.call(this,t)||this).t(),n.n={},n}o(t,i);var n=t.prototype;return n.draw=function(t,n){this.prepareCanvas(),this.r(n)},n.drawOnInteracting=function(t,n,i){this.r(i)},n.needToRedraw=function(){return!0},n.hitDetect=function(){return!1},n.createContext=function(){if(this.canvas.gl&&this.canvas.gl.wrap)this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl;else{var t=this.layer.options.glOptions||{alpha:!0,depth:!0,stencil:!0};this.glOptions=t,this.gl=this.gl||this.e(this.canvas,t),this.regl=c.createREGL({gl:this.gl,extensions:["ANGLE_instanced_arrays","OES_texture_float","OES_texture_half_float","OES_texture_float_linear","OES_texture_half_float_linear","EXT_shader_texture_lod","OES_element_index_uint","OES_standard_derivatives","WEBGL_depth_texture"],optionalExtensions:this.layer.options.glExtensions||[]})}this.o();for(var n=this.layer.getVideoSurfaces(),i=0;i<n.length;i++)this.u(n[i])},n.e=function(t,n){for(var i=["webgl","experimental-webgl"],r=null,e=0;e<i.length;++e){try{r=t.getContext(i[e],n)}catch(t){}if(r)break}return r},n.o=function(){var t=this.layer.getMap(),n=new c.reshader.Renderer(this.regl);this.renderer=n,this.a={projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,viewMatrix:t.viewMatrix,halton:[.2107,-.0202],uHalton:[.2107,-.0202],uCameraPosition:t.cameraPosition,cameraPosition:t.cameraPosition,globalTexSize:[t.width,t.height]}},n.f=function(){return this.regl},n.t=function(){var t=this;this.viewport={x:0,y:0,width:function(){return t.canvas?t.canvas.width:1},height:function(){return t.canvas?t.canvas.height:1}},this.s=new c.reshader.MeshShader(N)},n.u=function(t){var n=this.regl.texture(),i=new c.reshader.Material({videoTexture:n,opacity:1}),r=t.getCoordinates(),e=this.h(r),o=new c.reshader.Mesh(e,i);this.c(o);var u=new c.reshader.Scene(o),a=t.l();this.n[a]=u},n.v=function(t){var n=t.l(),i=this.n[n].getMeshes()[0],r=t.getCoordinates();i.geometry.dispose();var e=this.h(r);i.geometry=e},n.r=function(t){var n=this.layer.getVideoSurfaces().filter(function(t){return t.isVisible()});if(n.length){var i=this.d(n);if(i){var r=null;t&&(r=t.renderTarget&&t.renderTarget.fbo),this.renderer.render(this.s,this.a,i,r)}}},n.h=function(t){var n=new u.Polygon(t).getCenter(),i=this.p(n,t),r=e(i,null,3);return new c.reshader.Geometry({POSITION:i,TEXCOORD:[0,0,1,0,1,1,0,1]},r,0,{primitive:"triangles",positionAttribute:"POSITION",uv0Attribute:"TEXCOORD",normalAttribute:"NORMAL",positionSize:3})},n.p=function(t,n){var r=[],e=this.getMap(),o=F(e,t,0);return this.m=o,e&&n.forEach(function(t){var n=new u.Coordinate(t[0],t[1]),i=F(e,n,t[2]);i[0]=i[0]-o[0],i[1]=i[1]-o[1],r=r.concat(i)}),r},n.d=function(t){for(var n=[],i=this.layer.getMap(),r=0;r<t.length;r++){var e=t[r],o=this.n[e.l()];if(o)for(var u=o.getMeshes(),a=0;a<u.length;a++){var f=u[a],s=f.getMaterial(),h=s.get("videoTexture");h&&e.g()&&(h(e.video),s.set("opacity",e.getOpacity())),this.c(f),l(i.projViewMatrix,f.getBoundingBox())&&n.push(f)}}return n.length?new c.reshader.Scene(n):null},n.c=function(t){c.mat4.fromRotationTranslationScale(t.localTransform,c.quat.fromEuler([],0,0,0),this.m,[1,1,1])},n.clearCanvas=function(){this.canvas&&(this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),i.prototype.clearCanvas.call(this))},n.w=function(t){var n=this.n[t];n&&n.getMeshes().forEach(function(t){t.geometry.dispose(),t.material&&t.material.dispose(),t.dispose()})},t}(u.renderer.CanvasRenderer);function F(t,n,i){if(!t)return null;var r=t.coordinateToPointAtRes(n,t.getGLRes());return[r.x,r.y,i]}var L=function(e){function t(t,n,i){var r;return(r=e.call(this,t,i)||this).b={},r.videoId=0,r.addSurfaces(n),r}o(t,e);var n=t.prototype;return n.addSurfaces=function(n){var i=this;if(n)if(Array.isArray(n))n.forEach(function(t){i.addMarker(t)});else{((n.M=this).b[this.videoId]=n)._(this.videoId);var t=this.getRenderer();t?t.f()&&t.u(n):this.on("renderercreate",function(t){t.renderer.f()&&t.renderer.u(n)}),this.videoId++}},n.getVideoSurfaces=function(){var t=[];for(var n in this.b)t.push(this.b[n]);return t},n.removeVideoSurfaces=function(t){var n=this;if(Array.isArray(t))t.forEach(function(t){n.removeVideoSurfaces(t)});else{var i=t.l(),r=this.getRenderer();r&&r.w(i),delete this.b[i]}},n.clear=function(){for(var t=this.getVideoSurfaces(),n=0;n<t.length;n++)this.removeVideoSurfaces(t[n])},t}(u.Layer);L.mergeOptions({renderer:"gl",doubleBuffer:!1,glOptions:null,markerEvents:!0,forceRenderOnZooming:!0,forceRenderOnMoving:!0,forceRenderOnRotating:!0}),L.registerJSONType("VideoLayer"),L.registerRenderer("gl",D);var q=function(r){function t(t,n){var i;return(i=r.call(this,n)||this).setCoordinates(t),i.setVideo(i.options.url),i}o(t,r);var n=t.prototype;return n.setCoordinates=function(t){this.O=t},n.getCoordinates=function(){return this.O},n.setVideo=function(t){var n=this;this.options.url=t;var i=document.createElement("video");i.src=t,i.autoplay=!0,i.loop=!0,i.muted=!0,i.play(),i.addEventListener("playing",function(){n.T="playing"}),i.addEventListener("pause",function(){n.T="pause"}),this.video=i},n.getVideo=function(){return this.video},n._=function(t){this.P=t},n.l=function(){return this.P},n.addTo=function(t){if(this.M)throw new Error("VideoSurface cannot be added to two or more layers at the same time.");return t.addSurfaces(this),this},n.show=function(){return this.options.visible=!0,this},n.hide=function(){return this.options.visible=!1,this},n.isVisible=function(){return this.options.visible},n.play=function(){this.video&&this.video.play()},n.pause=function(){this.video&&this.video.pause()},n.setAudio=function(t){this.video.muted=t},n.setOpacity=function(t){this.options.opacity=t},n.getOpacity=function(){return this.options.opacity},n.remove=function(){var t=this.getLayer();t&&t.removeVideoSurfaces(this)},n.getLayer=function(){return this.M},n.g=function(){return"playing"===this.T||"pause"===this.T},n.startEdit=function(){var i=this,r=this.getLayer();if(r){var t=r.getMap();if(t){if(this.k(),!this.S){var n=r.getId();this.S=new u.VectorLayer("internal_"+n+"_edit").addTo(t)}var e=this.getCoordinates();this.C=new u.Polygon(e,{symbol:{lineColor:"#34495e",lineWidth:2,polygonFill:"rgb(135,196,240)",polygonOpacity:.1}}).addTo(this.S),this.C.startEdit({newVertexHandleSymbol:{polygonFill:"rgba(0, 0, 0, 0)",polygonOpacity:0,markerType:"ellipse",markerWidth:1,markerHeight:1}}),this.C.on("shapechange",function(t){var n=t.target.getCoordinates()[0].slice(0,4).map(function(t){return[t.x,t.y,0]});i.setCoordinates(n),r.getRenderer().v(i)},this)}else console.warn("videosurface should be added to a map before edit")}else console.warn("videosurface should be added to a map before edit")},n.endEdit=function(){this.S&&(this.C.endEdit(),this.C.remove(),this.S.remove()),delete this.S,delete this.C},n.k=function(){this.S&&this.S.clear(),delete this.C},t}(u.Eventable(u.Handlerable(u.Class)));q.mergeOptions({opacity:1,visible:!0}),t.VideoLayer=L,t.VideoSurface=q,Object.defineProperty(t,"j",{value:!0}),"undefined"!=typeof console&&console.log("@maptalks/video-layer v0.2.3")});
/*!
* @maptalks/video-layer v0.2.2
* @maptalks/video-layer v0.2.3
* LICENSE : UNLICENSED

@@ -11,2 +11,2 @@ * (c) 2016-2022 maptalks.org

* https://github.com/mrdoob/three.js
*/for(var f=[],d=0;d<6;d++)f[d]=[];var v=[];function p(t,e,i){var r,n,o,s,a,u,h,l,c,d,p,m,_,w,y,b,M;n=(r=t)[0],o=r[1],s=r[2],a=r[3],u=r[4],h=r[5],l=r[6],c=r[7],d=r[8],p=r[9],m=r[10],_=r[11],w=r[12],y=r[13],b=r[14],M=r[15],g(f[0],a-n,c-u,_-d,M-w),g(f[1],a+n,c+u,_+d,M+w),g(f[2],a+o,c+h,_+p,M+y),g(f[3],a-o,c-h,_-p,M-y),g(f[4],a-s,c-l,_-m,M-b),g(f[5],a+s,c+l,_+m,M+b);for(var O=0;O<6;O++)if(!i||"0"!==i.charAt(O)){var S=f[O];if(v[0]=S[0]>0?e[1][0]:e[0][0],v[1]=S[1]>0?e[1][1]:e[0][1],v[2]=S[2]>0?e[1][2]:e[0][2],x(S,v)<0)return!1}return!0}var m=1/6;function g(t,e,i,r,n){return t[0]=e*m,t[1]=i*m,t[2]=r*m,t[3]=n*m,t}function x(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]}var _=y,w=y;function y(t,e,i){i=i||2;var r,n,o,s,a,u,h,l=e&&e.length,c=l?e[0]*i:t.length,f=b(t,0,c,i,!0),d=[];if(!f||f.next===f.prev)return d;if(l&&(f=function(t,e,i,r){var n,o,s,a,u,h=[];for(n=0,o=e.length;n<o;n++)s=e[n]*r,a=n<o-1?e[n+1]*r:t.length,(u=b(t,s,a,r,!1))===u.next&&(u.steiner=!0),h.push(R(u));for(h.sort(P),n=0;n<h.length;n++)V(h[n],i),i=M(i,i.next);return i}(t,e,f,i)),t.length>80*i){r=o=t[0],n=s=t[1];for(var v=i;v<c;v+=i)(a=t[v])<r&&(r=a),(u=t[v+1])<n&&(n=u),a>o&&(o=a),u>s&&(s=u);h=0!==(h=Math.max(o-r,s-n))?1/h:0}return O(f,d,i,r,n,h),d}function b(t,e,i,r,n){var o,s;if(n===q(t,e,i,r)>0)for(o=e;o<i;o+=r)s=X(o,t[o],t[o+1],s);else for(o=i-r;o>=e;o-=r)s=X(o,t[o],t[o+1],s);return s&&j(s,s.next)&&(z(s),s=s.next),s}function M(t,e){if(!t)return t;e||(e=t);var i,r=t;do{if(i=!1,r.steiner||!j(r,r.next)&&0!==L(r.prev,r,r.next))r=r.next;else{if(z(r),(r=e=r.prev)===r.next)break;i=!0}}while(i||r!==e);return e}function O(t,e,i,r,n,o,s){if(t){!s&&o&&function(t,e,i,r){var n=t;do{null===n.z&&(n.z=I(n.x,n.y,e,i,r)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next}while(n!==t);n.prevZ.nextZ=null,n.prevZ=null,function(t){var e,i,r,n,o,s,a,u,h=1;do{for(i=t,t=null,o=null,s=0;i;){for(s++,r=i,a=0,e=0;e<h&&(a++,r=r.nextZ);e++);for(u=h;a>0||u>0&&r;)0!==a&&(0===u||!r||i.z<=r.z)?(n=i,i=i.nextZ,a--):(n=r,r=r.nextZ,u--),o?o.nextZ=n:t=n,n.prevZ=o,o=n;i=r}o.nextZ=null,h*=2}while(s>1)}(n)}(t,r,n,o);for(var a,u,h=t;t.prev!==t.next;)if(a=t.prev,u=t.next,o?T(t,r,n,o):S(t))e.push(a.i/i),e.push(t.i/i),e.push(u.i/i),z(t),t=u.next,h=u.next;else if((t=u)===h){s?1===s?O(t=C(M(t),e,i),e,i,r,n,o,2):2===s&&E(t,e,i,r,n,o):O(M(t),e,i,r,n,o,1);break}}}function S(t){var e=t.prev,i=t,r=t.next;if(L(e,i,r)>=0)return!1;for(var n=t.next.next;n!==t.prev;){if(A(e.x,e.y,i.x,i.y,r.x,r.y,n.x,n.y)&&L(n.prev,n,n.next)>=0)return!1;n=n.next}return!0}function T(t,e,i,r){var n=t.prev,o=t,s=t.next;if(L(n,o,s)>=0)return!1;for(var a=n.x<o.x?n.x<s.x?n.x:s.x:o.x<s.x?o.x:s.x,u=n.y<o.y?n.y<s.y?n.y:s.y:o.y<s.y?o.y:s.y,h=n.x>o.x?n.x>s.x?n.x:s.x:o.x>s.x?o.x:s.x,l=n.y>o.y?n.y>s.y?n.y:s.y:o.y>s.y?o.y:s.y,c=I(a,u,e,i,r),f=I(h,l,e,i,r),d=t.prevZ,v=t.nextZ;d&&d.z>=c&&v&&v.z<=f;){if(d!==t.prev&&d!==t.next&&A(n.x,n.y,o.x,o.y,s.x,s.y,d.x,d.y)&&L(d.prev,d,d.next)>=0)return!1;if(d=d.prevZ,v!==t.prev&&v!==t.next&&A(n.x,n.y,o.x,o.y,s.x,s.y,v.x,v.y)&&L(v.prev,v,v.next)>=0)return!1;v=v.nextZ}for(;d&&d.z>=c;){if(d!==t.prev&&d!==t.next&&A(n.x,n.y,o.x,o.y,s.x,s.y,d.x,d.y)&&L(d.prev,d,d.next)>=0)return!1;d=d.prevZ}for(;v&&v.z<=f;){if(v!==t.prev&&v!==t.next&&A(n.x,n.y,o.x,o.y,s.x,s.y,v.x,v.y)&&L(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function C(t,e,i){var r=t;do{var n=r.prev,o=r.next.next;!j(n,o)&&F(n,r,r.next,o)&&W(n,o)&&W(o,n)&&(e.push(n.i/i),e.push(r.i/i),e.push(o.i/i),z(r),z(r.next),r=t=o),r=r.next}while(r!==t);return M(r)}function E(t,e,i,r,n,o){var s=t;do{for(var a=s.next.next;a!==s.prev;){if(s.i!==a.i&&D(s,a)){var u=H(s,a);return s=M(s,s.next),u=M(u,u.next),O(s,e,i,r,n,o),void O(u,e,i,r,n,o)}a=a.next}s=s.next}while(s!==t)}function P(t,e){return t.x-e.x}function V(t,e){if(e=function(t,e){var i,r=e,n=t.x,o=t.y,s=-1/0;do{if(o<=r.y&&o>=r.next.y&&r.next.y!==r.y){var a=r.x+(o-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(a<=n&&a>s){if(s=a,a===n){if(o===r.y)return r;if(o===r.next.y)return r.next}i=r.x<r.next.x?r:r.next}}r=r.next}while(r!==e);if(!i)return null;if(n===s)return i;var u,h=i,l=i.x,c=i.y,f=1/0;r=i;do{n>=r.x&&r.x>=l&&n!==r.x&&A(o<c?n:s,o,l,c,o<c?s:n,o,r.x,r.y)&&(u=Math.abs(o-r.y)/(n-r.x),W(r,t)&&(u<f||u===f&&(r.x>i.x||r.x===i.x&&k(i,r)))&&(i=r,f=u)),r=r.next}while(r!==h);return i}(t,e)){var i=H(e,t);M(e,e.next),M(i,i.next)}}function k(t,e){return L(t.prev,t,e.prev)<0&&L(e.next,t,t.next)<0}function I(t,e,i,r,n){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-i)*n)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-r)*n)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function R(t){var e=t,i=t;do{(e.x<i.x||e.x===i.x&&e.y<i.y)&&(i=e),e=e.next}while(e!==t);return i}function A(t,e,i,r,n,o,s,a){return(n-s)*(e-a)-(t-s)*(o-a)>=0&&(t-s)*(r-a)-(i-s)*(e-a)>=0&&(i-s)*(o-a)-(n-s)*(r-a)>=0}function D(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){var i=t;do{if(i.i!==t.i&&i.next.i!==t.i&&i.i!==e.i&&i.next.i!==e.i&&F(i,i.next,t,e))return!0;i=i.next}while(i!==t);return!1}(t,e)&&(W(t,e)&&W(e,t)&&function(t,e){var i=t,r=!1,n=(t.x+e.x)/2,o=(t.y+e.y)/2;do{i.y>o!=i.next.y>o&&i.next.y!==i.y&&n<(i.next.x-i.x)*(o-i.y)/(i.next.y-i.y)+i.x&&(r=!r),i=i.next}while(i!==t);return r}(t,e)&&(L(t.prev,t,e.prev)||L(t,e.prev,e))||j(t,e)&&L(t.prev,t,t.next)>0&&L(e.prev,e,e.next)>0)}function L(t,e,i){return(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y)}function j(t,e){return t.x===e.x&&t.y===e.y}function F(t,e,i,r){var n=G(L(t,e,i)),o=G(L(t,e,r)),s=G(L(i,r,t)),a=G(L(i,r,e));return n!==o&&s!==a||(!(0!==n||!N(t,i,e))||(!(0!==o||!N(t,r,e))||(!(0!==s||!N(i,t,r))||!(0!==a||!N(i,e,r)))))}function N(t,e,i){return e.x<=Math.max(t.x,i.x)&&e.x>=Math.min(t.x,i.x)&&e.y<=Math.max(t.y,i.y)&&e.y>=Math.min(t.y,i.y)}function G(t){return t>0?1:t<0?-1:0}function W(t,e){return L(t.prev,t,t.next)<0?L(t,e,t.next)>=0&&L(t,t.prev,e)>=0:L(t,e,t.prev)<0||L(t,t.next,e)<0}function H(t,e){var i=new B(t.i,t.x,t.y),r=new B(e.i,e.x,e.y),n=t.next,o=e.prev;return t.next=e,e.prev=t,i.next=n,n.prev=i,r.next=i,i.prev=r,o.next=r,r.prev=o,r}function X(t,e,i,r){var n=new B(t,e,i);return r?(n.next=r.next,n.prev=r,r.next.prev=n,r.next=n):(n.prev=n,n.next=n),n}function z(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function B(t,e,i){this.i=t,this.x=e,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function q(t,e,i,r){for(var n=0,o=e,s=i-r;o<i;o+=r)n+=(t[s]-t[o])*(t[o+1]+t[s+1]),s=o;return n}y.deviation=function(t,e,i,r){var n=e&&e.length,o=n?e[0]*i:t.length,s=Math.abs(q(t,0,o,i));if(n)for(var a=0,u=e.length;a<u;a++){var h=e[a]*i,l=a<u-1?e[a+1]*i:t.length;s-=Math.abs(q(t,h,l,i))}var c=0;for(a=0;a<r.length;a+=3){var f=r[a]*i,d=r[a+1]*i,v=r[a+2]*i;c+=Math.abs((t[f]-t[v])*(t[d+1]-t[f+1])-(t[f]-t[d])*(t[v+1]-t[f+1]))}return 0===s&&0===c?0:Math.abs((c-s)/s)},y.flatten=function(t){for(var e=t[0][0].length,i={vertices:[],holes:[],dimensions:e},r=0,n=0;n<t.length;n++){for(var o=0;o<t[n].length;o++)for(var s=0;s<e;s++)i.vertices.push(t[n][o][s]);n>0&&(r+=t[n-1].length,i.holes.push(r))}return i},_.default=w;const Z={vert:"\n attribute vec3 aPosition;\n attribute vec2 aTexCoord;\n uniform mat4 projViewModelMatrix;\n uniform mat4 positionMatrix;\n uniform mat4 modelMatrix;\n varying vec2 vTexCoords;\n #include <get_output>\n void main()\n {\n mat4 localPositionMatrix = getPositionMatrix();\n vec4 localPosition = getPosition(aPosition);\n gl_Position = projViewModelMatrix * localPositionMatrix * localPosition;\n vTexCoords = aTexCoord;\n }\n",frag:"\n precision mediump float;\n uniform sampler2D videoTexture;\n uniform float opacity;\n\n varying vec2 vTexCoords;\n void main() {\n vec4 color = texture2D(videoTexture, vTexCoords);\n gl_FragColor = color * opacity;\n }\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>l.multiply([],e.projViewMatrix,e.modelMatrix)},"texture","opacity"],positionAttribute:"POSITION",extraCommandProps:{depth:{enable:!0,func:"always",mask:!1,range:[0,0]},cull:{enable:!1,face:"back"},frontFace:"cw",blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"}}};function $(t,e,i){if(!t)return null;const r=t.coordinateToPointAtRes(e,t.getGLRes());return[r.x,r.y,i]}class J extends r{constructor(t,e,i){super(t,i),this.t={},this.videoId=0,this.addSurfaces(e)}addSurfaces(t){if(t)if(Array.isArray(t))t.forEach(t=>{this.addMarker(t)});else{t.o=this,this.t[this.videoId]=t,t.s(this.videoId);const e=this.getRenderer();e?e.u()&&e.h(t):this.on("renderercreate",e=>{e.renderer.u()&&e.renderer.h(t)}),this.videoId++}}getVideoSurfaces(){const t=[];for(const e in this.t)t.push(this.t[e]);return t}removeVideoSurfaces(t){if(Array.isArray(t))t.forEach(t=>{this.removeVideoSurfaces(t)});else{const e=t.l(),i=this.getRenderer();i&&i.v(e),delete this.t[e]}}clear(){const t=this.getVideoSurfaces();for(let e=0;e<t.length;e++)this.removeVideoSurfaces(t[e])}}J.mergeOptions({renderer:"gl",doubleBuffer:!1,glOptions:null,markerEvents:!0,forceRenderOnZooming:!0,forceRenderOnMoving:!0,forceRenderOnRotating:!0}),J.registerJSONType("VideoLayer"),J.registerRenderer("gl",class extends t.CanvasRenderer{constructor(t){super(t),this.p(),this.m={}}draw(t,e){this.prepareCanvas(),this.g(e)}drawOnInteracting(t,e,i){this.g(i)}needToRedraw(){return!0}hitDetect(){return!1}createContext(){if(this.canvas.gl&&this.canvas.gl.wrap)this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl;else{const t=this.layer.options.glOptions||{alpha:!0,depth:!0,stencil:!0};this.glOptions=t,this.gl=this.gl||this._(this.canvas,t),this.regl=u({gl:this.gl,extensions:["ANGLE_instanced_arrays","OES_texture_float","OES_texture_half_float","OES_texture_float_linear","OES_texture_half_float_linear","EXT_shader_texture_lod","OES_element_index_uint","OES_standard_derivatives","WEBGL_depth_texture"],optionalExtensions:this.layer.options.glExtensions||[]})}this.M();const t=this.layer.getVideoSurfaces();for(let e=0;e<t.length;e++)this.h(t[e])}_(t,e){const i=["webgl","experimental-webgl"];let r=null;for(let n=0;n<i.length;++n){try{r=t.getContext(i[n],e)}catch(t){}if(r)break}return r}M(){const t=this.layer.getMap(),e=new h.Renderer(this.regl);this.renderer=e,this.O={projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,viewMatrix:t.viewMatrix,halton:[.2107,-.0202],uHalton:[.2107,-.0202],uCameraPosition:t.cameraPosition,cameraPosition:t.cameraPosition,globalTexSize:[t.width,t.height]}}u(){return this.regl}p(){this.viewport={x:0,y:0,width:()=>this.canvas?this.canvas.width:1,height:()=>this.canvas?this.canvas.height:1},this.S=new h.MeshShader(Z)}h(t){const e=this.regl.texture(),i=new h.Material({videoTexture:e,opacity:1}),r=t.getCoordinates(),n=this.T(r),o=new h.Mesh(n,i);this.C(o);const s=new h.Scene(o),a=t.l();this.m[a]=s}P(t){const e=t.l(),i=this.m[e].getMeshes()[0],r=t.getCoordinates();i.geometry.dispose();const n=this.T(r);i.geometry=n}g(t){const e=this.layer.getVideoSurfaces().filter(t=>t.isVisible());if(!e.length)return;const i=this.V(e);if(!i)return;let r=null;t&&(r=t.renderTarget&&t.renderTarget.fbo),this.renderer.render(this.S,this.O,i,r)}T(t){const i=new e(t).getCenter(),r=this.k(i,t),n=_(r,null,3);return new h.Geometry({POSITION:r,TEXCOORD:[0,0,1,0,1,1,0,1]},n,0,{primitive:"triangles",positionAttribute:"POSITION",uv0Attribute:"TEXCOORD",normalAttribute:"NORMAL",positionSize:3})}k(t,e){let r=[];const n=this.getMap(),o=$(n,t,0);return this.I=o,n&&e.forEach(t=>{const e=new i(t[0],t[1]),s=$(n,e,t[2]);s[0]=s[0]-o[0],s[1]=s[1]-o[1],r=r.concat(s)}),r}V(t){const e=[],i=this.layer.getMap();for(let r=0;r<t.length;r++){const n=t[r],o=this.m[n.l()];if(!o)continue;const s=o.getMeshes();for(let t=0;t<s.length;t++){const r=s[t],o=r.getMaterial(),a=o.get("videoTexture");a&&n.R()&&(a(n.video),o.set("opacity",n.getOpacity())),this.C(r),p(i.projViewMatrix,r.getBoundingBox())&&e.push(r)}}return e.length?new h.Scene(e):null}C(t){l.fromRotationTranslationScale(t.localTransform,c.fromEuler([],0,0,0),this.I,[1,1,1])}clearCanvas(){this.canvas&&(this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas())}v(t){const e=this.m[t];e&&e.getMeshes().forEach(t=>{t.geometry.dispose(),t.material&&t.material.dispose(),t.dispose()})}});class K extends(n(o(s))){constructor(t,e){super(e),this.setCoordinates(t),this.setVideo(this.options.url)}setCoordinates(t){this.A=t}getCoordinates(){return this.A}setVideo(t){this.options.url=t;const e=document.createElement("video");e.src=t,e.autoplay=!0,e.loop=!0,e.muted=!0,e.play(),e.addEventListener("playing",()=>{this.D="playing"}),e.addEventListener("pause",()=>{this.D="pause"}),this.video=e}getVideo(){return this.video}s(t){this.L=t}l(){return this.L}addTo(t){if(this.o)throw new Error("VideoSurface cannot be added to two or more layers at the same time.");return t.addSurfaces(this),this}show(){return this.options.visible=!0,this}hide(){return this.options.visible=!1,this}isVisible(){return this.options.visible}play(){this.video&&this.video.play()}pause(){this.video&&this.video.pause()}setAudio(t){this.video.muted=t}setOpacity(t){this.options.opacity=t}getOpacity(){return this.options.opacity}remove(){const t=this.getLayer();t&&t.removeVideoSurfaces(this)}getLayer(){return this.o}R(){return"playing"===this.D||"pause"===this.D}startEdit(){const t=this.getLayer();if(!t)return void console.warn("videosurface should be added to a map before edit");const i=t.getMap();if(!i)return void console.warn("videosurface should be added to a map before edit");if(!this.j){const e=t.getId();this.j=new a(`internal_${e}_edit`).addTo(i)}const r=this.getCoordinates();this.F=new e(r,{symbol:{lineColor:"#34495e",lineWidth:2,polygonFill:"rgb(135,196,240)",polygonOpacity:.1}}).addTo(this.j),this.F.startEdit({newVertexHandleSymbol:{polygonFill:"rgba(0, 0, 0, 0)",polygonOpacity:0,markerType:"ellipse",markerWidth:1,markerHeight:1}}),this.F.on("shapechange",e=>{const i=e.target.getCoordinates()[0].slice(0,4).map(t=>[t.x,t.y,0]);this.setCoordinates(i),t.getRenderer().P(this)},this)}endEdit(){this.j&&(this.F.endEdit(),this.F.remove(),this.j.remove()),delete this.j,delete this.F}}K.mergeOptions({opacity:1,visible:!0});export{J as VideoLayer,K as VideoSurface};"undefined"!=typeof console&&console.log("@maptalks/video-layer v0.2.2");
*/for(var f=[],d=0;d<6;d++)f[d]=[];var v=[];function p(t,e,i){var r,n,o,s,a,u,h,l,c,d,p,m,x,w,y,b,M;n=(r=t)[0],o=r[1],s=r[2],a=r[3],u=r[4],h=r[5],l=r[6],c=r[7],d=r[8],p=r[9],m=r[10],x=r[11],w=r[12],y=r[13],b=r[14],M=r[15],_(f[0],a-n,c-u,x-d,M-w),_(f[1],a+n,c+u,x+d,M+w),_(f[2],a+o,c+h,x+p,M+y),_(f[3],a-o,c-h,x-p,M-y),_(f[4],a-s,c-l,x-m,M-b),_(f[5],a+s,c+l,x+m,M+b);for(var O=0;O<6;O++)if(!i||"0"!==i.charAt(O)){var S=f[O];if(v[0]=S[0]>0?e[1][0]:e[0][0],v[1]=S[1]>0?e[1][1]:e[0][1],v[2]=S[2]>0?e[1][2]:e[0][2],g(S,v)<0)return!1}return!0}var m=1/6;function _(t,e,i,r,n){return t[0]=e*m,t[1]=i*m,t[2]=r*m,t[3]=n*m,t}function g(t,e){return t[0]*e[0]+t[1]*e[1]+t[2]*e[2]+t[3]}var x=y,w=y;function y(t,e,i){i=i||2;var r,n,o,s,a,u,h,l=e&&e.length,c=l?e[0]*i:t.length,f=b(t,0,c,i,!0),d=[];if(!f||f.next===f.prev)return d;if(l&&(f=function(t,e,i,r){var n,o,s,a,u,h=[];for(n=0,o=e.length;n<o;n++)s=e[n]*r,a=n<o-1?e[n+1]*r:t.length,(u=b(t,s,a,r,!1))===u.next&&(u.steiner=!0),h.push(R(u));for(h.sort(P),n=0;n<h.length;n++)V(h[n],i),i=M(i,i.next);return i}(t,e,f,i)),t.length>80*i){r=o=t[0],n=s=t[1];for(var v=i;v<c;v+=i)(a=t[v])<r&&(r=a),(u=t[v+1])<n&&(n=u),a>o&&(o=a),u>s&&(s=u);h=0!==(h=Math.max(o-r,s-n))?1/h:0}return O(f,d,i,r,n,h),d}function b(t,e,i,r,n){var o,s;if(n===q(t,e,i,r)>0)for(o=e;o<i;o+=r)s=X(o,t[o],t[o+1],s);else for(o=i-r;o>=e;o-=r)s=X(o,t[o],t[o+1],s);return s&&j(s,s.next)&&(z(s),s=s.next),s}function M(t,e){if(!t)return t;e||(e=t);var i,r=t;do{if(i=!1,r.steiner||!j(r,r.next)&&0!==L(r.prev,r,r.next))r=r.next;else{if(z(r),(r=e=r.prev)===r.next)break;i=!0}}while(i||r!==e);return e}function O(t,e,i,r,n,o,s){if(t){!s&&o&&function(t,e,i,r){var n=t;do{null===n.z&&(n.z=I(n.x,n.y,e,i,r)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next}while(n!==t);n.prevZ.nextZ=null,n.prevZ=null,function(t){var e,i,r,n,o,s,a,u,h=1;do{for(i=t,t=null,o=null,s=0;i;){for(s++,r=i,a=0,e=0;e<h&&(a++,r=r.nextZ);e++);for(u=h;a>0||u>0&&r;)0!==a&&(0===u||!r||i.z<=r.z)?(n=i,i=i.nextZ,a--):(n=r,r=r.nextZ,u--),o?o.nextZ=n:t=n,n.prevZ=o,o=n;i=r}o.nextZ=null,h*=2}while(s>1)}(n)}(t,r,n,o);for(var a,u,h=t;t.prev!==t.next;)if(a=t.prev,u=t.next,o?T(t,r,n,o):S(t))e.push(a.i/i),e.push(t.i/i),e.push(u.i/i),z(t),t=u.next,h=u.next;else if((t=u)===h){s?1===s?O(t=C(M(t),e,i),e,i,r,n,o,2):2===s&&E(t,e,i,r,n,o):O(M(t),e,i,r,n,o,1);break}}}function S(t){var e=t.prev,i=t,r=t.next;if(L(e,i,r)>=0)return!1;for(var n=t.next.next;n!==t.prev;){if(A(e.x,e.y,i.x,i.y,r.x,r.y,n.x,n.y)&&L(n.prev,n,n.next)>=0)return!1;n=n.next}return!0}function T(t,e,i,r){var n=t.prev,o=t,s=t.next;if(L(n,o,s)>=0)return!1;for(var a=n.x<o.x?n.x<s.x?n.x:s.x:o.x<s.x?o.x:s.x,u=n.y<o.y?n.y<s.y?n.y:s.y:o.y<s.y?o.y:s.y,h=n.x>o.x?n.x>s.x?n.x:s.x:o.x>s.x?o.x:s.x,l=n.y>o.y?n.y>s.y?n.y:s.y:o.y>s.y?o.y:s.y,c=I(a,u,e,i,r),f=I(h,l,e,i,r),d=t.prevZ,v=t.nextZ;d&&d.z>=c&&v&&v.z<=f;){if(d!==t.prev&&d!==t.next&&A(n.x,n.y,o.x,o.y,s.x,s.y,d.x,d.y)&&L(d.prev,d,d.next)>=0)return!1;if(d=d.prevZ,v!==t.prev&&v!==t.next&&A(n.x,n.y,o.x,o.y,s.x,s.y,v.x,v.y)&&L(v.prev,v,v.next)>=0)return!1;v=v.nextZ}for(;d&&d.z>=c;){if(d!==t.prev&&d!==t.next&&A(n.x,n.y,o.x,o.y,s.x,s.y,d.x,d.y)&&L(d.prev,d,d.next)>=0)return!1;d=d.prevZ}for(;v&&v.z<=f;){if(v!==t.prev&&v!==t.next&&A(n.x,n.y,o.x,o.y,s.x,s.y,v.x,v.y)&&L(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function C(t,e,i){var r=t;do{var n=r.prev,o=r.next.next;!j(n,o)&&F(n,r,r.next,o)&&H(n,o)&&H(o,n)&&(e.push(n.i/i),e.push(r.i/i),e.push(o.i/i),z(r),z(r.next),r=t=o),r=r.next}while(r!==t);return M(r)}function E(t,e,i,r,n,o){var s=t;do{for(var a=s.next.next;a!==s.prev;){if(s.i!==a.i&&D(s,a)){var u=W(s,a);return s=M(s,s.next),u=M(u,u.next),O(s,e,i,r,n,o),void O(u,e,i,r,n,o)}a=a.next}s=s.next}while(s!==t)}function P(t,e){return t.x-e.x}function V(t,e){if(e=function(t,e){var i,r=e,n=t.x,o=t.y,s=-1/0;do{if(o<=r.y&&o>=r.next.y&&r.next.y!==r.y){var a=r.x+(o-r.y)*(r.next.x-r.x)/(r.next.y-r.y);if(a<=n&&a>s){if(s=a,a===n){if(o===r.y)return r;if(o===r.next.y)return r.next}i=r.x<r.next.x?r:r.next}}r=r.next}while(r!==e);if(!i)return null;if(n===s)return i;var u,h=i,l=i.x,c=i.y,f=1/0;r=i;do{n>=r.x&&r.x>=l&&n!==r.x&&A(o<c?n:s,o,l,c,o<c?s:n,o,r.x,r.y)&&(u=Math.abs(o-r.y)/(n-r.x),H(r,t)&&(u<f||u===f&&(r.x>i.x||r.x===i.x&&k(i,r)))&&(i=r,f=u)),r=r.next}while(r!==h);return i}(t,e)){var i=W(e,t);M(e,e.next),M(i,i.next)}}function k(t,e){return L(t.prev,t,e.prev)<0&&L(e.next,t,t.next)<0}function I(t,e,i,r,n){return(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-i)*n)|t<<8))|t<<4))|t<<2))|t<<1))|(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-r)*n)|e<<8))|e<<4))|e<<2))|e<<1))<<1}function R(t){var e=t,i=t;do{(e.x<i.x||e.x===i.x&&e.y<i.y)&&(i=e),e=e.next}while(e!==t);return i}function A(t,e,i,r,n,o,s,a){return(n-s)*(e-a)-(t-s)*(o-a)>=0&&(t-s)*(r-a)-(i-s)*(e-a)>=0&&(i-s)*(o-a)-(n-s)*(r-a)>=0}function D(t,e){return t.next.i!==e.i&&t.prev.i!==e.i&&!function(t,e){var i=t;do{if(i.i!==t.i&&i.next.i!==t.i&&i.i!==e.i&&i.next.i!==e.i&&F(i,i.next,t,e))return!0;i=i.next}while(i!==t);return!1}(t,e)&&(H(t,e)&&H(e,t)&&function(t,e){var i=t,r=!1,n=(t.x+e.x)/2,o=(t.y+e.y)/2;do{i.y>o!=i.next.y>o&&i.next.y!==i.y&&n<(i.next.x-i.x)*(o-i.y)/(i.next.y-i.y)+i.x&&(r=!r),i=i.next}while(i!==t);return r}(t,e)&&(L(t.prev,t,e.prev)||L(t,e.prev,e))||j(t,e)&&L(t.prev,t,t.next)>0&&L(e.prev,e,e.next)>0)}function L(t,e,i){return(e.y-t.y)*(i.x-e.x)-(e.x-t.x)*(i.y-e.y)}function j(t,e){return t.x===e.x&&t.y===e.y}function F(t,e,i,r){var n=G(L(t,e,i)),o=G(L(t,e,r)),s=G(L(i,r,t)),a=G(L(i,r,e));return n!==o&&s!==a||(!(0!==n||!N(t,i,e))||(!(0!==o||!N(t,r,e))||(!(0!==s||!N(i,t,r))||!(0!==a||!N(i,e,r)))))}function N(t,e,i){return e.x<=Math.max(t.x,i.x)&&e.x>=Math.min(t.x,i.x)&&e.y<=Math.max(t.y,i.y)&&e.y>=Math.min(t.y,i.y)}function G(t){return t>0?1:t<0?-1:0}function H(t,e){return L(t.prev,t,t.next)<0?L(t,e,t.next)>=0&&L(t,t.prev,e)>=0:L(t,e,t.prev)<0||L(t,t.next,e)<0}function W(t,e){var i=new B(t.i,t.x,t.y),r=new B(e.i,e.x,e.y),n=t.next,o=e.prev;return t.next=e,e.prev=t,i.next=n,n.prev=i,r.next=i,i.prev=r,o.next=r,r.prev=o,r}function X(t,e,i,r){var n=new B(t,e,i);return r?(n.next=r.next,n.prev=r,r.next.prev=n,r.next=n):(n.prev=n,n.next=n),n}function z(t){t.next.prev=t.prev,t.prev.next=t.next,t.prevZ&&(t.prevZ.nextZ=t.nextZ),t.nextZ&&(t.nextZ.prevZ=t.prevZ)}function B(t,e,i){this.i=t,this.x=e,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function q(t,e,i,r){for(var n=0,o=e,s=i-r;o<i;o+=r)n+=(t[s]-t[o])*(t[o+1]+t[s+1]),s=o;return n}y.deviation=function(t,e,i,r){var n=e&&e.length,o=n?e[0]*i:t.length,s=Math.abs(q(t,0,o,i));if(n)for(var a=0,u=e.length;a<u;a++){var h=e[a]*i,l=a<u-1?e[a+1]*i:t.length;s-=Math.abs(q(t,h,l,i))}var c=0;for(a=0;a<r.length;a+=3){var f=r[a]*i,d=r[a+1]*i,v=r[a+2]*i;c+=Math.abs((t[f]-t[v])*(t[d+1]-t[f+1])-(t[f]-t[d])*(t[v+1]-t[f+1]))}return 0===s&&0===c?0:Math.abs((c-s)/s)},y.flatten=function(t){for(var e=t[0][0].length,i={vertices:[],holes:[],dimensions:e},r=0,n=0;n<t.length;n++){for(var o=0;o<t[n].length;o++)for(var s=0;s<e;s++)i.vertices.push(t[n][o][s]);n>0&&(r+=t[n-1].length,i.holes.push(r))}return i},x.default=w;const Z={vert:"\n attribute vec3 aPosition;\n attribute vec2 aTexCoord;\n uniform mat4 projViewModelMatrix;\n uniform mat4 positionMatrix;\n uniform mat4 modelMatrix;\n varying vec2 vTexCoords;\n #include <get_output>\n void main()\n {\n mat4 localPositionMatrix = getPositionMatrix();\n vec4 localPosition = getPosition(aPosition);\n gl_Position = projViewModelMatrix * localPositionMatrix * localPosition;\n vTexCoords = aTexCoord;\n }\n",frag:"\n precision mediump float;\n uniform sampler2D videoTexture;\n uniform float opacity;\n\n varying vec2 vTexCoords;\n void main() {\n vec4 color = texture2D(videoTexture, vTexCoords);\n gl_FragColor = color * opacity;\n }\n",uniforms:[{name:"projViewModelMatrix",type:"function",fn:(t,e)=>l.multiply([],e.projViewMatrix,e.modelMatrix)},"texture","opacity"],positionAttribute:"POSITION",extraCommandProps:{depth:{enable:!0,func:"always",mask:!1,range:[0,0]},cull:{enable:!1,face:"back"},frontFace:"cw",blend:{enable:!0,func:{src:"src alpha",dst:"one minus src alpha"},equation:"add"}}};function $(t,e,i){if(!t)return null;const r=t.coordinateToPointAtRes(e,t.getGLRes());return[r.x,r.y,i]}class J extends r{constructor(t,e,i){super(t,i),this.t={},this.videoId=0,this.addSurfaces(e)}addSurfaces(t){if(t)if(Array.isArray(t))t.forEach(t=>{this.addMarker(t)});else{t.o=this,this.t[this.videoId]=t,t.s(this.videoId);const e=this.getRenderer();e?e.u()&&e.h(t):this.on("renderercreate",e=>{e.renderer.u()&&e.renderer.h(t)}),this.videoId++}}getVideoSurfaces(){const t=[];for(const e in this.t)t.push(this.t[e]);return t}removeVideoSurfaces(t){if(Array.isArray(t))t.forEach(t=>{this.removeVideoSurfaces(t)});else{const e=t.l(),i=this.getRenderer();i&&i.v(e),delete this.t[e]}}clear(){const t=this.getVideoSurfaces();for(let e=0;e<t.length;e++)this.removeVideoSurfaces(t[e])}}J.mergeOptions({renderer:"gl",doubleBuffer:!1,glOptions:null,markerEvents:!0,forceRenderOnZooming:!0,forceRenderOnMoving:!0,forceRenderOnRotating:!0}),J.registerJSONType("VideoLayer"),J.registerRenderer("gl",class extends t.CanvasRenderer{constructor(t){super(t),this.p(),this.m={}}draw(t,e){this.prepareCanvas(),this._(e)}drawOnInteracting(t,e,i){this._(i)}needToRedraw(){return!0}hitDetect(){return!1}createContext(){if(this.canvas.gl&&this.canvas.gl.wrap)this.gl=this.canvas.gl.wrap(),this.regl=this.canvas.gl.regl;else{const t=this.layer.options.glOptions||{alpha:!0,depth:!0,stencil:!0};this.glOptions=t,this.gl=this.gl||this.g(this.canvas,t),this.regl=u({gl:this.gl,extensions:["ANGLE_instanced_arrays","OES_texture_float","OES_texture_half_float","OES_texture_float_linear","OES_texture_half_float_linear","EXT_shader_texture_lod","OES_element_index_uint","OES_standard_derivatives","WEBGL_depth_texture"],optionalExtensions:this.layer.options.glExtensions||[]})}this.M();const t=this.layer.getVideoSurfaces();for(let e=0;e<t.length;e++)this.h(t[e])}g(t,e){const i=["webgl","experimental-webgl"];let r=null;for(let n=0;n<i.length;++n){try{r=t.getContext(i[n],e)}catch(t){}if(r)break}return r}M(){const t=this.layer.getMap(),e=new h.Renderer(this.regl);this.renderer=e,this.O={projMatrix:t.projMatrix,projViewMatrix:t.projViewMatrix,viewMatrix:t.viewMatrix,halton:[.2107,-.0202],uHalton:[.2107,-.0202],uCameraPosition:t.cameraPosition,cameraPosition:t.cameraPosition,globalTexSize:[t.width,t.height]}}u(){return this.regl}p(){this.viewport={x:0,y:0,width:()=>this.canvas?this.canvas.width:1,height:()=>this.canvas?this.canvas.height:1},this.S=new h.MeshShader(Z)}h(t){const e=this.regl.texture(),i=new h.Material({videoTexture:e,opacity:1}),r=t.getCoordinates(),n=this.T(r),o=new h.Mesh(n,i);this.C(o);const s=new h.Scene(o),a=t.l();this.m[a]=s}P(t){const e=t.l(),i=this.m[e].getMeshes()[0],r=t.getCoordinates();i.geometry.dispose();const n=this.T(r);i.geometry=n}_(t){const e=this.layer.getVideoSurfaces().filter(t=>t.isVisible());if(!e.length)return;const i=this.V(e);if(!i)return;let r=null;t&&(r=t.renderTarget&&t.renderTarget.fbo),this.renderer.render(this.S,this.O,i,r)}T(t){const i=new e(t).getCenter(),r=this.k(i,t),n=x(r,null,3);return new h.Geometry({POSITION:r,TEXCOORD:[0,0,1,0,1,1,0,1]},n,0,{primitive:"triangles",positionAttribute:"POSITION",uv0Attribute:"TEXCOORD",normalAttribute:"NORMAL",positionSize:3})}k(t,e){let r=[];const n=this.getMap(),o=$(n,t,0);return this.I=o,n&&e.forEach(t=>{const e=new i(t[0],t[1]),s=$(n,e,t[2]);s[0]=s[0]-o[0],s[1]=s[1]-o[1],r=r.concat(s)}),r}V(t){const e=[],i=this.layer.getMap();for(let r=0;r<t.length;r++){const n=t[r],o=this.m[n.l()];if(!o)continue;const s=o.getMeshes();for(let t=0;t<s.length;t++){const r=s[t],o=r.getMaterial(),a=o.get("videoTexture");a&&n.R()&&(a(n.video),o.set("opacity",n.getOpacity())),this.C(r),p(i.projViewMatrix,r.getBoundingBox())&&e.push(r)}}return e.length?new h.Scene(e):null}C(t){l.fromRotationTranslationScale(t.localTransform,c.fromEuler([],0,0,0),this.I,[1,1,1])}clearCanvas(){this.canvas&&(this.regl.clear({color:[0,0,0,0],depth:1,stencil:0}),super.clearCanvas())}v(t){const e=this.m[t];e&&e.getMeshes().forEach(t=>{t.geometry.dispose(),t.material&&t.material.dispose(),t.dispose()})}});class K extends(n(o(s))){constructor(t,e){super(e),this.setCoordinates(t),this.setVideo(this.options.url)}setCoordinates(t){this.A=t}getCoordinates(){return this.A}setVideo(t){this.options.url=t;const e=document.createElement("video");e.src=t,e.autoplay=!0,e.loop=!0,e.muted=!0,e.play(),e.addEventListener("playing",()=>{this.D="playing"}),e.addEventListener("pause",()=>{this.D="pause"}),this.video=e}getVideo(){return this.video}s(t){this.L=t}l(){return this.L}addTo(t){if(this.o)throw new Error("VideoSurface cannot be added to two or more layers at the same time.");return t.addSurfaces(this),this}show(){return this.options.visible=!0,this}hide(){return this.options.visible=!1,this}isVisible(){return this.options.visible}play(){this.video&&this.video.play()}pause(){this.video&&this.video.pause()}setAudio(t){this.video.muted=t}setOpacity(t){this.options.opacity=t}getOpacity(){return this.options.opacity}remove(){const t=this.getLayer();t&&t.removeVideoSurfaces(this)}getLayer(){return this.o}R(){return"playing"===this.D||"pause"===this.D}startEdit(){const t=this.getLayer();if(!t)return void console.warn("videosurface should be added to a map before edit");const i=t.getMap();if(!i)return void console.warn("videosurface should be added to a map before edit");if(this.j(),!this.F){const e=t.getId();this.F=new a(`internal_${e}_edit`).addTo(i)}const r=this.getCoordinates();this.N=new e(r,{symbol:{lineColor:"#34495e",lineWidth:2,polygonFill:"rgb(135,196,240)",polygonOpacity:.1}}).addTo(this.F),this.N.startEdit({newVertexHandleSymbol:{polygonFill:"rgba(0, 0, 0, 0)",polygonOpacity:0,markerType:"ellipse",markerWidth:1,markerHeight:1}}),this.N.on("shapechange",e=>{const i=e.target.getCoordinates()[0].slice(0,4).map(t=>[t.x,t.y,0]);this.setCoordinates(i),t.getRenderer().P(this)},this)}endEdit(){this.F&&(this.N.endEdit(),this.N.remove(),this.F.remove()),delete this.F,delete this.N}j(){this.F&&this.F.clear(),delete this.N}}K.mergeOptions({opacity:1,visible:!0});export{J as VideoLayer,K as VideoSurface};"undefined"!=typeof console&&console.log("@maptalks/video-layer v0.2.3");
{
"name": "@maptalks/video-layer",
"version": "0.2.2",
"version": "0.2.3",
"description": "A maptalks Layer to render video",

@@ -28,3 +28,3 @@ "license": "UNLICENSED",

"lint": "eslint src/**/*.js test/**/*.js",
"prepublish": "npm run lint && npm run build"
"prepare": "npm run lint && npm run build"
},

@@ -34,3 +34,3 @@ "devDependencies": {

"@babel/preset-env": "^7.2.3",
"@maptalks/gl": "^0.71.0",
"@maptalks/gl": "^0.74.3",
"babel-eslint": "^10.0.1",

@@ -47,3 +47,3 @@ "eslint": "^5.11.1",

"karma-mocha-reporter": "^2.2.5",
"maptalks": "1.0.0-rc.6",
"maptalks": "1.0.0-rc.10",
"mocha": "^5.2.0",

@@ -50,0 +50,0 @@ "rollup": "^1.0.1",