Socket
Socket
Sign inDemoInstall

opentok-annotation

Package Overview
Dependencies
3
Maintainers
1
Versions
101
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.14 to 1.0.15

2

dist/opentok-annotation.min.js

@@ -1,1 +0,1 @@

window.OTSolution=window.OTSolution||{},OTSolution.Annotations=function(t){function e(t,e,n){for(var i=e.split(" "),o=0,a=i.length;o<a;o++)t.addEventListener(i[o],n,!0)}function n(t,e){0===a.width&&(a.width=o.parent.getBoundingClientRect().width),0===a.height&&(a.height=o.parent.getBoundingClientRect().height);var n,i=e?t.canvas.width:o.parent.clientWidth,s=e?t.canvas.height:o.parent.clientHeight,c=e?t.canvas.offsetLeft:a.offsetLeft,l=e?t.canvas.offsetTop:a.offsetTop,d=a.width/i,h=a.height/s,g=t.offsetX||t.pageX-c||t.changedTouches&&t.changedTouches[0].pageX-c,m=t.offsetY||t.pageY-l||t.changedTouches&&t.changedTouches[0].pageY-l,f=g*d,v=m*h,y=e?t.selectedItem:o.selectedItem;if(y)if("OT_pen"===y.id)switch(t.type){case"mousedown":case"touchstart":p.dragging=!0,p.lastX=f,p.lastY=v,o.isStartPoint=!0;break;case"mousemove":case"touchmove":p.dragging&&(n={id:o.videoFeed.stream.connection.connectionId,fromId:o.session.connection.connectionId,fromX:p.lastX,fromY:p.lastY,toX:f,toY:v,color:e?t.userColor:o.userColor,lineWidth:o.lineWidth,videoWidth:o.videoFeed.videoElement().clientWidth,videoHeight:o.videoFeed.videoElement().clientHeight,canvasWidth:a.width,canvasHeight:a.height,mirrored:r,startPoint:o.isStartPoint,endPoint:!1,selectedItem:y},x(n,!0),p.lastX=f,p.lastY=v,!e&&S(n),o.isStartPoint=!1);break;case"mouseup":case"touchend":p.dragging=!1,n={id:o.videoFeed.stream.connection.connectionId,fromId:o.session.connection.connectionId,fromX:p.lastX,fromY:p.lastY,toX:f,toY:v,color:e?t.userColor:o.userColor,lineWidth:o.lineWidth,videoWidth:o.videoFeed.videoElement().clientWidth,videoHeight:o.videoFeed.videoElement().clientHeight,canvasWidth:a.width,canvasHeight:a.height,mirrored:r,startPoint:o.isStartPoint,endPoint:!0,selectedItem:y},x(n,!0),p.lastX=f,p.lastY=v,!e&&S(n),o.isStartPoint=!1;break;case"mouseout":p.dragging=!1}else if("OT_text"===y.id)n={id:o.videoFeed.stream.connection.connectionId,fromId:o.session.connection.connectionId,fromX:f,fromY:v+t.inputHeight,color:t.userColor,font:t.font,text:t.text,videoWidth:o.videoFeed.videoElement().clientWidth,videoHeight:o.videoFeed.videoElement().clientHeight,canvasWidth:a.width,canvasHeight:a.height,mirrored:r,selectedItem:y},x(n),!e&&S(n);else if(y&&y.points)switch(p.mX=f,p.mY=v,t.type){case"mousedown":case"touchstart":p.isDrawing=!0,p.dragging=!0,p.startX=f,p.startY=v;break;case"mousemove":case"touchmove":p.dragging&&(n={color:e?t.userColor:o.userColor,lineWidth:e?t.lineWidth:o.lineWidth,selectedItem:y},x(n,!0));break;case"mouseup":case"touchend":p.isDrawing=!1;var b=y.points;if(2===b.length)n={id:o.videoFeed.stream.connection.connectionId,fromId:o.session.connection.connectionId,fromX:p.startX,fromY:p.startY,toX:p.mX,toY:p.mY,color:e?t.userColor:o.userColor,lineWidth:e?t.lineWidth:o.lineWidth,videoWidth:o.videoFeed.videoElement().clientWidth,videoHeight:o.videoFeed.videoElement().clientHeight,canvasWidth:a.width,canvasHeight:a.height,mirrored:r,smoothed:!1,startPoint:!0,endPoint:!0,selectedItem:y},u.push(n),!e&&S(n);else{for(var I=P(b),w=0;w<b.length;w++){var T=!1,W=!1,_=p.startX+I.x*b[w][0],M=p.startY+I.y*b[w][1];0===w?(p.lastX=_,p.lastY=M,T=!0):w===b.length-1&&(W=!0),n={id:o.videoFeed.stream.connection.connectionId,fromId:o.session.connection.connectionId,fromX:p.lastX,fromY:p.lastY,toX:_,toY:M,color:e?t.userColor:o.userColor,lineWidth:e?t.lineWidth:o.lineWidth,videoWidth:o.videoFeed.videoElement().clientWidth,videoHeight:o.videoFeed.videoElement().clientHeight,canvasWidth:a.width,canvasHeight:a.height,mirrored:r,smoothed:y.enableSmoothing,startPoint:T,endPoint:W},u.push(n),!e&&S(n),p.lastX=_,p.lastY=M}x(null)}p.dragging=!1}}t=t||{},this.widgetVersion="js-1.0.0-beta",this.parent=t.container,this.videoFeed=t.feed;var i=t.externalWindow?t.externalWindow.document:window.document,o=this;if(this.parent){var a=document.createElement("canvas");a.setAttribute("id","opentok_canvas"),a.style.position="absolute",this.parent.appendChild(a),a.setAttribute("width",this.parent.clientWidth+"px"),a.style.width=window.getComputedStyle(this.parent).width,a.setAttribute("height",this.parent.clientHeight+"px"),a.style.height=window.getComputedStyle(this.parent).height}var s,r,c,l,o=this,d=[],h=[],u=[],g=[],m=[],p={dragging:!1};r=(" "+o.videoFeed.element.className+" ").indexOf(" OT_mirrored ")>-1,c=(" "+o.videoFeed.element.className+" ").indexOf(" OT_fit-mode-cover ")>-1,this.canvas=function(){return a},this.link=function(t){this.session=t},this.changeColor=function(t){o.userColor=t,o.lineWidth||(o.lineWidth=2)},this.changeLineWidth=function(t){this.lineWidth=t},this.selectItem=function(t){o.overlay&&(o.overlay.style.display="none",o.overlay=null),"OT_capture"===t.id?(o.selectedItem=t,o.overlay?o.overlay.style="inline":(o.overlay=document.createElement("div"),o.overlay.style.position="absolute",o.overlay.style.width=o.parent.clientWidth+"px",o.overlay.style.height=o.parent.clientHeight+"px",o.overlay.style.background='rgba(0,0,0,0.4) url("../images/annotation/camera.png") no-repeat center',o.overlay.style.backgroundSize="50px 50px",o.overlay.style.cursor="pointer",o.overlay.style.opacity=0,o.parent.appendChild(o.overlay),o.parent.onmouseover=function(){o.overlay.style.opacity=1},o.parent.onmouseout=function(){o.overlay.style.opacity=0},o.overlay.onclick=function(){o.captureScreenshot()})):t.id.indexOf("OT_line_width")!==-1?t.size&&o.changeLineWidth(t.size):o.selectedItem=t},this.colors=function(t){this.colors=t,this.changeColor(t[0])},this.clear=function(){k(!1,o.session.connection.connectionId),o.session&&o.session.signal({type:"otAnnotation_clear"})},this.captureScreenshot=function(){var t=document.createElement("canvas");t.width=a.width,t.height=a.height;var e=o.videoFeed.videoWidth(),n=o.videoFeed.videoHeight(),i=1,s=0,l=0;c?(e<n?(i=a.width/e,e=a.width,n*=i):(i=a.height/n,n=a.height,e*=i),s=(e-a.width)/2,l=(n-a.height)/2):e>n?(i=a.width/e,e=a.width,n*=i):(i=a.height/n,n=a.height,e*=i);var h=new Image;h.onload=function(){var i=t.getContext("2d");r&&(i.translate(e,0),i.scale(-1,1)),i.drawImage(h,s,l,e,n),r&&(i.translate(e,0),i.scale(-1,1)),i.drawImage(a,0,0),d.forEach(function(e){e.call(o,t.toDataURL())}),t=null},h.src="data:image/png;base64,"+o.videoFeed.getImgData()},this.onScreenCapture=function(t){d.push(t)},this.onResize=function(){u=[],O(g,!0),m.forEach(function(t){n(t,!0)})},e(a,"mousedown mousemove mouseup mouseout touchstart touchmove touchend",function(t){var e=o.selectedItem&&"OT_text"===o.selectedItem.id,i="mousemove"===t.type&&!p.dragging;e||i||(t.preventDefault(),t.selectedItem=o.selectedItem,t.selectedItem&&(t.canvas={width:a.width,height:a.height,offsetLeft:a.offsetLeft,offsetTop:a.offsetTop},t.userColor=o.userColor,t.lineWidth=o.lineWidth,m.push(t)),n(t))});var f,v="textAnnotation",y=!1,b=function(t){t.preventDefault(),o.selectedItem&&"OT_text"===o.selectedItem.id&&!y&&(y=!0,t.selectedItem=o.selectedItem,_(t))},I=function(t){13===t.which&&W(),27===t.which&&(i.getElementById(v).remove(),f=null),y=!1},w=function(){i.addEventListener("keydown",I)},T=function(){i.removeEventListener("keydown",I)},W=function(){var t=i.getElementById(v);t.clientHeight;return t.value?(t.remove(),T(),f.text=t.value,f.font="16px Arial",f.userColor=o.userColor,f.canvas={width:a.width,height:a.height,offsetLeft:a.offsetLeft,offsetTop:a.offsetTop},m.push(f),void n(f)):void(f=null)},_=function(t){var e=i.createElement("input");e.setAttribute("type","text"),e.style.position="absolute",e.style.top=t.clientY+"px",e.style.left=t.clientX+"px",e.style.background="rgba(255,255,255, .5)",e.style.width="100px",e.style.maxWidth="200px",e.style.border="1px dashed red",e.style.fontSize="16px",e.style.color=o.userColor,e.style.fontFamily="Arial",e.style.zIndex="1001",e.setAttribute("data-canvas-origin",JSON.stringify({x:t.offsetX,y:t.offsetY})),e.id=v,i.body.appendChild(e),e.focus(),f=t,f.inputHeight=e.clientHeight,w()};e(a,"click",b);var x=function(t,e){s||(s=a.getContext("2d"),s.lineCap="round",s.lineJoin="round",s.fillStyle="solid"),s.clearRect(0,0,a.width,a.height),u.forEach(function(t){s.strokeStyle=t.color,s.lineWidth=t.lineWidth,t.smoothed=!!t.smoothed,t.startPoint=!!t.startPoint;var e=!1,n=!!t.selectedItem&&"Text"===t.selectedItem.title&&t.text;n?(s.font=t.font,s.fillStyle=t.color,s.fillText(t.text,t.fromX,t.fromY)):t.smoothed?(t.startPoint?o.isStartPoint=!0:o.isStartPoint&&(e=!0,o.isStartPoint=!1),t.startPoint?(s.closePath(),s.beginPath()):e?s.moveTo((t.fromX+t.toX)/2,(t.fromY+t.toY)/2):(s.quadraticCurveTo(t.fromX,t.fromY,(t.fromX+t.toX)/2,(t.fromY+t.toY)/2),s.stroke())):(s.beginPath(),s.moveTo(t.fromX,t.fromY),s.lineTo(t.toX,t.toY),s.stroke(),s.closePath())});var n=e?t.selectedItem:o.selectedItem;!n||"Pen"!==n.title&&"Text"!==n.title?p.isDrawing&&(t&&(s.strokeStyle=t.color,s.lineWidth=t.lineWidth),n&&n.points&&M(s,o.selectedItem.points)):t&&("Pen"===n.title&&(s.strokeStyle=t.color,s.lineWidth=t.lineWidth,s.beginPath(),s.moveTo(t.fromX,t.fromY),s.lineTo(t.toX,t.toY),s.stroke(),s.closePath()),"Text"===n.title&&(s.font=t.font,s.fillStyle=t.color,s.fillText(t.text,t.fromX,t.fromY)),u.push(t))},M=function(t,e){var n=P(e);if(t.beginPath(),2===e.length)t.moveTo(p.startX,p.startY),t.lineTo(p.mX,p.mY);else for(var i=0;i<e.length;i++){var a=p.startX+n.x*e[i][0],s=p.startY+n.y*e[i][1];o.selectedItem.enableSmoothing?0===i||(1===i?(t.moveTo((a+p.lastX)/2,(s+p.lastY)/2),p.lastX=(a+p.lastX)/2,p.lastX=(s+p.lastY)/2):(t.quadraticCurveTo(p.lastX,p.lastY,(a+p.lastX)/2,(s+p.lastY)/2),p.lastX=(a+p.lastX)/2,p.lastY=(s+p.lastY)/2)):0===i?t.moveTo(a,s):t.lineTo(a,s),p.lastX=a,p.lastY=s}t.stroke(),t.closePath()},P=function(t){for(var e=Number.MAX_VALUE,n=Number.MAX_VALUE,i=0,o=0,a=0;a<t.length;a++)t[a][0]<e?e=t[a][0]:t[a][0]>i&&(i=t[a][0]),t[a][1]<n?n=t[a][1]:t[a][1]>o&&(o=t[a][1]);var s=Math.abs(i-e),r=Math.abs(o-n),c=(p.mX-p.startX)/s,l=(p.mY-p.startY)/r;return{x:c,y:l}},C=function(t,e,n){var i={width:t.canvasWidth,height:t.canvasHeight},s={width:t.videoWidth,height:t.videoHeight},c={width:o.videoFeed.videoElement().clientWidth,height:o.videoFeed.videoElement().clientHeight},l=1,d=a.width/a.height;c.width/c.height,i.width/i.height,s.width/s.height;l=d<0?a.width/i.width:a.height/i.height;var h=a.width/2,m=a.height/2,p=i.width/2,f=i.height/2;t.fromX=h-l*(p-t.fromX),t.fromY=m-l*(f-t.fromY),t.toX=h-l*(p-t.toX),t.toY=m-l*(f-t.toY),t.mirrored=!!t.mirrored,t.mirrored&&(t.fromX=a.width-t.fromX,t.toX=a.width-t.toX),r&&(t.fromX=a.width-t.fromX,t.toX=a.width-t.toX);var v=JSON.parse(JSON.stringify(t));v.canvasWidth=a.width,v.canvasHeight=a.height,v.videoWidth=c.width,v.videoHeight=c.height,e?g[n]=v:g.push(v),u.push(t),x(null)},O=function(t,e){t.forEach(function(t,n){t.id===o.videoFeed.stream.connection.connectionId&&C(t,e,n)})},k=function(t,e){u=u.filter(function(t){return console.log(t.fromId),t.fromId!==e}),t?g=[]:(o.session&&o.session.signal({type:"otAnnotation_clear"}),m=[]),x()};o.videoFeed.session&&o.videoFeed.session.on({"signal:otAnnotation_pen":function(t){t.from.connectionId!==o.session.connection.connectionId&&O(JSON.parse(t.data))},"signal:otAnnotation_text":function(t){t.from.connectionId!==o.session.connection.connectionId&&O(JSON.parse(t.data))},"signal:otAnnotation_history":function(t){l&&l!==t.from.connectionId||(l=t.from.connectionId,O(JSON.parse(t.data)))},"signal:otAnnotation_clear":function(t){t.from.connectionId!==o.session.connection.connectionId&&k(!0,t.from.connectionId)},connectionCreated:function(t){u.length>0&&t.connection.connectionId!==o.session.connection.connectionId&&A("otWhiteboard_history",u,t.connection)}});var E,A=function(t,e){for(var n=t.slice(),i=function(t){t&&TB.error(t)},a="otAnnotation_pen",s=function(t){if(t&&t[0]&&t[0].selectedItem&&t[0].selectedItem.id){var e=t[0].selectedItem.id;a="OT_text"===e?"otAnnotation_text":"otAnnotation_pen"}};n.length;){var r=n.splice(0,Math.min(n.length,32));s(r);var c={type:a,data:JSON.stringify(r)};e&&(c.to=e),o.session.signal(c,i)}},S=function(t){o.session&&(h.push(t),E||(E=setTimeout(function(){A(h),h=[],E=null},100)))}},OTSolution.Annotations.Toolbar=function(t){var e=this,n=this;t||(t={}),this.session=t.session,this.parent=t.container,this.externalWindow=t.externalWindow,this.backgroundColor=t.backgroundColor||"rgba(0, 0, 0, 0.7)",this.buttonWidth=t.buttonWidth||"40px",this.buttonHeight=t.buttonHeight||"40px",this.iconWidth=t.iconWidth||"30px",this.iconHeight=t.iconHeight||"30px",this.items=t.items||[{id:"OT_pen",title:"Pen",icon:"../images/annotation/freehand.png",selectedIcon:"../images/annotation/freehand_selected.png"},{id:"OT_line",title:"Line",icon:"../images/annotation/line.png",selectedIcon:"../images/annotation/line_selected.png",points:[[0,0],[0,1]]},{id:"OT_shapes",title:"Shapes",icon:"../images/annotation/shapes.png",items:[{id:"OT_arrow",title:"Arrow",icon:"../images/annotation/arrow.png",points:[[0,1],[3,1],[3,0],[5,2],[3,4],[3,3],[0,3],[0,1]]},{id:"OT_rect",title:"Rectangle",icon:"../images/annotation/rectangle.png",points:[[0,0],[1,0],[1,1],[0,1],[0,0]]},{id:"OT_oval",title:"Oval",icon:"../images/annotation/oval.png",enableSmoothing:!0,points:[[0,.5],[.5+.5*Math.cos(5*Math.PI/4),.5+.5*Math.sin(5*Math.PI/4)],[.5,0],[.5+.5*Math.cos(7*Math.PI/4),.5+.5*Math.sin(7*Math.PI/4)],[1,.5],[.5+.5*Math.cos(Math.PI/4),.5+.5*Math.sin(Math.PI/4)],[.5,1],[.5+.5*Math.cos(3*Math.PI/4),.5+.5*Math.sin(3*Math.PI/4)],[0,.5],[.5+.5*Math.cos(5*Math.PI/4),.5+.5*Math.sin(5*Math.PI/4)]]}]},{id:"OT_text",title:"Text",icon:"../images/annotation/text.png",selectedIcon:"../images/annotation/text.png"},{id:"OT_colors",title:"Colors",icon:"",items:{}},{id:"OT_line_width",title:"Line Width",icon:"../images/annotation/line_width.png",items:{}},{id:"OT_clear",title:"Clear",icon:"../images/annotation/clear.png"},{id:"OT_capture",title:"Capture",icon:"../images/annotation/camera.png",selectedIcon:"../images/annotation/camera_selected.png"}],this.colors=t.colors||["#1abc9c","#2ecc71","#3498db","#9b59b6","#34495e","#16a085","#27ae60","#2980b9","#8e44ad","#2c3e50","#f1c40f","#e67e22","#e74c3c","#ecf0f1","#95a5a6","#f39c12","#d35400","#c0392b","#bdc3c7","#7f8c8d"],this.cbs=[];var i,o=[],a=function(t,e,i){var o=this,a=n.externalWindow?n.externalWindow.document:document;this.getElm=function(t){return"string"==typeof t?a.querySelector(t):t},this.render=function(){var t=this,e="";t.colors.forEach(function(n){e+=t.options.template.replace(/\{color\}/g,n)}),t.elm.innerHTML=e},this.close=function(){this.elm.style.display="none"},this.open=function(){this.elm.style.display=this.options.style.display},this.colorChosen=function(t){this.cbs.push(t)},this.set=function(t,e){var n=this;n.color=t,e!==!1&&n.cbs.forEach(function(e){e.call(n,t)})},i=i||{},i.openEvent=i.openEvent||"click",i.style=Object(i.style),i.style.display=i.style.display||"block",i.template=i.template||'<div class="color-choice" data-col="{color}" style="background-color: {color}"></div>',o.elm=o.getElm(t),o.cbs=[],o.colors=e,o.options=i,o.render(),o.elm.addEventListener("click",function(t){var e=t.target.getAttribute("data-col");e&&(o.set(e),o.close())}),i.autoclose!==!1&&o.close()};this.createPanel=function(t){if(n.parent){var r=t?t.document:document;i=r.createElement("div"),i.setAttribute("id","OT_toolbar"),i.setAttribute("class","OT_panel"),i.style.width="100%",i.style.height="100%",i.style.backgroundColor=this.backgroundColor,this.parent.appendChild(i),this.parent.style.position="relative",this.parent.zIndex=1e3;for(var c=[],l=r.createElement("div"),d=0,h=this.items.length;d<h;d++){var u=this.items[d],g=r.createElement("input");if(g.setAttribute("type","button"),g.setAttribute("id",u.id),g.style.position="relative",g.style.top="50%",g.style.transform="translateY(-50%)","OT_colors"===u.id){g.style.webkitTransform="translateY(-85%)";var m=r.createElement("div");m.setAttribute("class","color-picker"),m.style.backgroundColor=this.backgroundColor,this.parent.appendChild(m);var p=new a(".color-picker",this.colors,{externalWindow:n.externalWindow});p.colorChosen(function(t){var e=r.getElementById("OT_colors");e.style.backgroundColor=t,o.forEach(function(e){e.changeColor(t)})});for(var f=r.querySelectorAll(".color-choice"),v=0;v<f.length;v++)f[v].style.display="inline-block",f[v].style.width="30px",f[v].style.height="30px",f[v].style.margin="5px",f[v].style.cursor="pointer",f[v].style.borderRadius="100%",f[v].style.opacity=.7,f[v].onmouseover=function(){this.style.opacity=1},f[v].onmouseout=function(){this.style.opacity=.7};g.setAttribute("class","OT_color"),g.style.marginLeft="10px",g.style.marginRight="10px",g.style.borderRadius="50%",g.style.backgroundColor=this.colors[0],g.style.width=this.iconWidth,g.style.height=this.iconHeight,g.style.paddingTop=this.buttonHeight.replace("px","")-this.iconHeight.replace("px","")+"px"}else g.style.background='url("'+u.icon+'") no-repeat',g.style.backgroundSize=this.iconWidth+" "+this.iconHeight,g.style.backgroundPosition="center",g.style.width=this.buttonWidth,g.style.height=this.buttonHeight;"Line Width"!==u.title||Array.isArray(u.items)||(u.items=[{id:"OT_line_width_2",title:"Line Width 2",size:2},{id:"OT_line_width_4",title:"Line Width 4",size:4},{id:"OT_line_width_6",title:"Line Width 6",size:6},{id:"OT_line_width_8",title:"Line Width 8",size:8},{id:"OT_line_width_10",title:"Line Width 10",size:10},{id:"OT_line_width_12",title:"Line Width 12",size:12},{id:"OT_line_width_14",title:"Line Width 14",size:14}]),u.items&&g.setAttribute("data-type","group"),g.setAttribute("data-col",u.title),g.style.border="none",g.style.cursor="pointer",c.push(g.outerHTML)}i.innerHTML=c.join(""),i.onclick=function(t){var n="group"===t.target.getAttribute("data-type"),i=t.target.getAttribute("data-col"),a=t.target.getAttribute("id");n?e.items.forEach(function(t){if(t.title===i){if(e.selectedGroup=t,t.items&&(l.setAttribute("class","OT_subpanel"),l.style.backgroundColor=e.backgroundColor,l.style.width="100%",l.style.height="100%",l.style.paddingLeft="15px",l.style.display="none",e.parent.appendChild(l),Array.isArray(t.items))){var n=[];"OT_line_width"===t.id?t.items.forEach(function(t){var i=r.createElement("div");i.setAttribute("data-col",t.title),i.setAttribute("id",t.id),i.style.position="relative",i.style.top="50%",i.style.transform="translateY(-50%)",i.style["float"]="left",i.style.width=e.buttonWidth,i.style.height=e.buttonHeight,i.style.border="none",i.style.cursor="pointer";var o=r.createElement("div");o.style.backgroundColor="#FFFFFF",o.style.width="80%",o.style.height=t.size+"px",o.style.position="relative",o.style.left="50%",o.style.top="50%",o.style.transform="translateX(-50%) translateY(-50%)",o.style.pointerEvents="none",i.appendChild(o),n.push(i.outerHTML)}):t.items.forEach(function(t){var i=r.createElement("input");i.setAttribute("type","button"),i.setAttribute("data-col",t.title),i.setAttribute("id",t.id),i.style.background='url("'+t.icon+'") no-repeat',i.style.position="relative",i.style.top="50%",i.style.transform="translateY(-50%)",i.style.backgroundSize=e.iconWidth+" "+e.iconHeight,i.style.backgroundPosition="center",i.style.width=e.buttonWidth,i.style.height=e.buttonHeight,i.style.border="none",i.style.cursor="pointer",n.push(i.outerHTML)}),l.innerHTML=n.join("")}"OT_shapes"===a||"OT_line_width"===a?(l&&(l.style.display="block"),p.close()):"OT_colors"===a&&(l&&(l.style.display="none"),p.open())}}):(e.items.forEach(function(t){if("Clear"!==t.title&&t.title===i){if(e.selectedItem){var n=r.getElementById(e.selectedItem.id);n&&(n.style.background='url("'+e.selectedItem.icon+'") no-repeat',n.style.backgroundSize=e.iconWidth+" "+e.iconHeight,n.style.backgroundPosition="center")}if(t.selectedIcon){var a=r.getElementById(t.id);a&&(a.style.background='url("'+t.selectedIcon+'") no-repeat',a.style.backgroundSize=e.iconWidth+" "+e.iconHeight,a.style.backgroundPosition="center")}return e.selectedItem=t,s(t),o.forEach(function(t){t.selectItem(e.selectedItem)}),!1}}),l.style.display="none"),e.cbs.forEach(function(t){t.call(e,a)})},l.onclick=function(t){var n="group"===t.target.getAttribute("data-type"),i=(t.target.getAttribute("data-col"),t.target.getAttribute("id"));l.style.display="none",n||e.selectedGroup.items.forEach(function(t){if("OT_clear"!==t.id&&t.id===i){if(e.selectedItem){var n=document.getElementById(e.selectedItem.id);n&&(n.style.background='url("'+e.selectedItem.icon+'") no-repeat',n.style.backgroundSize=e.iconWidth+" "+e.iconHeight,n.style.backgroundPosition="center")}if(t.selectedIcon){var a=document.getElementById(t.id);n&&(a.style.background='url("'+t.selectedIcon+'") no-repeat',a.style.backgroundSize=e.iconWidth+" "+e.iconHeight,a.style.backgroundPosition="center")}return e.selectedItem=t,s(t),o.forEach(function(t){t.selectItem(e.selectedItem)}),!1}}),e.cbs.forEach(function(t){t.call(e,i)})},r.getElementById("OT_clear").onclick=function(){o.forEach(function(t){t.clear()})}}},!this.externalWindow&&this.createPanel();var s=function(t){t.points||("OT_line"===t.id?e.selectedItem.points=[[0,0],[0,1]]:"OT_arrow"===t.id?e.selectedItem.points=[[0,1],[3,1],[3,0],[5,2],[3,4],[3,3],[0,3],[0,1]]:"OT_rect"===t.id?e.selectedItem.points=[[0,0],[1,0],[1,1],[0,1],[0,0]]:"OT_oval"===t.id&&(e.selectedItem.enableSmoothing=!0,e.selectedItem.points=[[0,.5],[.5+.5*Math.cos(5*Math.PI/4),.5+.5*Math.sin(5*Math.PI/4)],[.5,0],[.5+.5*Math.cos(7*Math.PI/4),.5+.5*Math.sin(7*Math.PI/4)],[1,.5],[.5+.5*Math.cos(Math.PI/4),.5+.5*Math.sin(Math.PI/4)],[.5,1],[.5+.5*Math.cos(3*Math.PI/4),.5+.5*Math.sin(3*Math.PI/4)],[0,.5],[.5+.5*Math.cos(5*Math.PI/4),.5+.5*Math.sin(5*Math.PI/4)]]))};this.itemClicked=function(t){this.cbs.push(t)},this.addCanvas=function(t){var e=this;t.link(e.session),t.colors(e.colors),o.push(t)},this.removeCanvas=function(t){o.forEach(function(e){var n=e.canvas();e.videoFeed.stream.connection.connectionId===t&&n.parentNode&&n.parentNode.removeChild(n)}),o=o.filter(function(e){return e.videoFeed.stream.connection.connectionId!==t})},this.remove=function(){try{i.parentNode.removeChild(i)}catch(t){console.log(t)}o.forEach(function(t){var e=t.canvas();e.parentNode&&e.parentNode.removeChild(e)}),o=[]}},function(){var t,e,n,i,o,a=function(t){var e="object"==typeof exports&&void 0!==require;if(e)return require(t);throw new Error(["Please include",t,"in your project"].join(" "))},s=this._||a("underscore"),r=this.$||a("jquery"),c=this.OTKAnalytics||a("opentok-solutions-logging"),l={},d={clientVersion:"js-vsol-1.0.0",componentId:"annotationsKit",name:"guidAnnotationsKit",actionInitialize:"Init",actionStart:"Start",actionEnd:"Done",actionFreeHand:"FreeHand",actionPickerColor:"PickerColor",actionText:"Text",actionScreenCapture:"ScreenCapture",actionErase:"Erase",variationAttempt:"Attempt",variationError:"Failure",variationSuccess:"Success"},h=function(){var t=window.location.href,e={clientVersion:d.clientVersion,source:t,componentId:d.componentId,name:d.name};o=new c(e);var i={sessionId:n.id,connectionId:n.connection.connectionId,partnerId:n.apiKey};o.addSessionInfo(i)},u=function(t,e){var n={action:t,variation:e};o.logEvent(n)},g=function(t,n){e&&e.triggerEvent(t,n)},m=function(){var t=["startAnnotation","linkAnnotation","resizeCanvas","annotationWindowClosed","endAnnotation"];e.registerEvents(t)},p=function(){var t=['<div id="toolbar"></div>'].join("\n");r("body").append(t)},f=[{id:"OT_pen",title:"Pen",icon:"../images/annotation/freehand.png",selectedIcon:"../images/annotation/freehand_selected.png"},{id:"OT_line",title:"Line",icon:"../images/annotation/line.png",selectedIcon:"../images/annotation/line_selected.png"},{id:"OT_text",title:"Text",icon:"../images/annotation/text.png",selectedIcon:"../images/annotation/text.png"},{id:"OT_shapes",title:"Shapes",icon:"../images/annotation/shapes.png",items:[{id:"OT_arrow",title:"Arrow",icon:"../images/annotation/arrow.png"},{id:"OT_rect",title:"Rectangle",icon:"../images/annotation/rectangle.png"},{id:"OT_oval",title:"Oval",icon:"../images/annotation/oval.png"},{id:"OT_star",title:"Star",icon:"../images/annotation/star.png",points:[[.5+.5*Math.cos(90*(Math.PI/180)),.5+.5*Math.sin(90*(Math.PI/180))],[.5+.25*Math.cos(126*(Math.PI/180)),.5+.25*Math.sin(126*(Math.PI/180))],[.5+.5*Math.cos(162*(Math.PI/180)),.5+.5*Math.sin(162*(Math.PI/180))],[.5+.25*Math.cos(198*(Math.PI/180)),.5+.25*Math.sin(198*(Math.PI/180))],[.5+.5*Math.cos(234*(Math.PI/180)),.5+.5*Math.sin(234*(Math.PI/180))],[.5+.25*Math.cos(270*(Math.PI/180)),.5+.25*Math.sin(270*(Math.PI/180))],[.5+.5*Math.cos(306*(Math.PI/180)),.5+.5*Math.sin(306*(Math.PI/180))],[.5+.25*Math.cos(342*(Math.PI/180)),.5+.25*Math.sin(342*(Math.PI/180))],[.5+.5*Math.cos(18*(Math.PI/180)),.5+.5*Math.sin(18*(Math.PI/180))],[.5+.25*Math.cos(54*(Math.PI/180)),.5+.25*Math.sin(54*(Math.PI/180))],[.5+.5*Math.cos(90*(Math.PI/180)),.5+.5*Math.sin(90*(Math.PI/180))]]}]},{id:"OT_colors",title:"Colors",icon:"",items:{}},{id:"OT_line_width",title:"Line Width",icon:"../images/annotation/line_width.png",items:{}},{id:"OT_clear",title:"Clear",icon:"../images/annotation/clear.png"}],v=["#1abc9c","#2ecc71","#3498db","#9b59b6","#8e44ad","#f1c40f","#e67e22","#e74c3c","#ded5d5"],y=10/6,b=s.throttle(function(){i.onResize()},1e3),I=function(){var t,e;if(l.externalWindow){var n={width:l.externalWindow.innerWidth,height:l.externalWindow.innerHeight},i=n.width/y;i<=n.height?(t=n.width,e=i):(e=n.height,t=e*y)}else{var o=l.absoluteParent||l.canvasContainer;t=r(o).width(),e=r(o).height()}r(l.canvasContainer).css({width:t,height:e}),r(l.canvas).css({width:t,height:e}),r(l.canvas).attr({width:t,height:e}),b(),g("resizeCanvas")},w=function(){r(l.resizeSubject).on("resize",s.throttle(function(){I()},500))},T=function(t,e,n){var i=s.property("toolbarId")(e)||"toolbar",o=s.property("toolbarItems")(e)||f,a=s.property("colors")(e)||v,r=function(){var t=n?n:window;return t.document.getElementById(i)};toolbar=new OTSolution.Annotations.Toolbar({session:t,container:r(),colors:a,items:o,externalWindow:n||null}),toolbar.itemClicked(function(t){var e={OT_pen:d.actionFreeHand,OT_colors:d.actionPickerColor,OT_text:d.actionText,OT_clear:d.actionErase},n=e[t];n&&(u(n,d.variationAttempt),u(n,d.variationSuccess))})},W=function(){var t=r.Deferred(),e=.8*screen.width|0,n=e/y,i=["templates/screenshare.html?opentok-annotation"].join(""),o=["toolbar=no","location=no","directories=no","status=no","menubar=no","scrollbars=no","resizable=no","copyhistory=no",["width=",e].join(""),["height=",n].join(""),["left=",screen.width/2-e/2].join(""),["top=",screen.height/2-n/2].join("")].join(","),a=window.open(i,"",o);window.onbeforeunload=function(){a.close()},a.toolbar=toolbar,a.OT=OT,a.$=r,a.triggerCloseEvent=function(){g("annotationWindowClosed")};var s=function(){a.createContainerElements?r(a.document).ready(function(){t.resolve(a)}):setTimeout(s,100)};return s(),t.promise()},_=function(){r(l.resizeSubject).off("resize",I),toolbar.remove()},x=function(t,e){var n=r.Deferred();return u(d.actionStart,d.variationAttempt),s.property("screensharing")(e)?W().then(function(i){T(t,e,i),toolbar.createPanel(i),g("startAnnotation",i),u(d.actionStart,d.variationSuccess),n.resolve(i)}):(T(t,e),g("startAnnotation"),u(d.actionStart,d.variationSuccess),n.resolve()),n.promise()},M=function(t,e,n){l.resizeSubject=s.property("externalWindow")(n)||window,l.externalWindow=s.property("externalWindow")(n)||null,l.absoluteParent=s.property("absoluteParent")(n)||null,l.canvasContainer=e,i=new OTSolution.Annotations({feed:t,container:e,externalWindow:l.externalWindow}),toolbar.addCanvas(i),i.onScreenCapture(function(t){var e=window.open(t,"_blank");e.focus()});var o=l.externalWindow?l.externalWindow:window;l.canvas=r(s.first(o.document.getElementsByTagName("canvas"))),w(),I(),g("linkAnnotation")},P=function(){I()},C=function(t){u(d.actionEnd,d.variationAttempt),_(),l.canvas=null,t&&(l.externalWindow&&(l.externalWindow.close(),l.externalWindow=null,l.resizeSubject=null),g("endAnnotation")),u(d.actionEnd,d.variationSuccess)},O=function(i){if(t=this,t.options=s.omit(i,"accPack","session"),e=s.property("accPack")(i),n=s.property("session")(i),!n)throw new Error("OpenTok Annotation Accelerator Pack requires an OpenTok session");m(),p(),h(),u(d.actionInitialize,d.variationAttempt),u(d.actionInitialize,d.variationSuccess)};O.prototype={constructor:O,start:x,linkCanvas:M,resizeCanvas:P,end:C},"object"==typeof exports?module.exports=O:"function"==typeof define&&define.amd?define(function(){return O}):this.AnnotationAccPack=O}.call(this);
window.OTSolution=window.OTSolution||{},OTSolution.Annotations=function(t){function e(t,e,n){for(var i=e.split(" "),o=0,a=i.length;o<a;o++)t.addEventListener(i[o],n,!0)}function n(t,e){0===a.width&&(a.width=o.parent.getBoundingClientRect().width),0===a.height&&(a.height=o.parent.getBoundingClientRect().height);var n,i=e?t.canvas.width:o.parent.clientWidth,s=e?t.canvas.height:o.parent.clientHeight,c=e?t.canvas.offsetLeft:a.offsetLeft,l=e?t.canvas.offsetTop:a.offsetTop,d=a.width/i,h=a.height/s,g=t.offsetX||t.pageX-c||t.changedTouches&&t.changedTouches[0].pageX-c,m=t.offsetY||t.pageY-l||t.changedTouches&&t.changedTouches[0].pageY-l,f=g*d,v=m*h,y=e?t.selectedItem:o.selectedItem;if(y)if("OT_pen"===y.id)switch(t.type){case"mousedown":case"touchstart":p.dragging=!0,p.lastX=f,p.lastY=v,o.isStartPoint=!0;break;case"mousemove":case"touchmove":p.dragging&&(n={id:o.videoFeed.stream.connection.connectionId,fromId:o.session.connection.connectionId,fromX:p.lastX,fromY:p.lastY,toX:f,toY:v,color:e?t.userColor:o.userColor,lineWidth:o.lineWidth,videoWidth:o.videoFeed.videoElement().clientWidth,videoHeight:o.videoFeed.videoElement().clientHeight,canvasWidth:a.width,canvasHeight:a.height,mirrored:r,startPoint:o.isStartPoint,endPoint:!1,selectedItem:y},x(n,!0),p.lastX=f,p.lastY=v,!e&&S(n),o.isStartPoint=!1);break;case"mouseup":case"touchend":p.dragging=!1,n={id:o.videoFeed.stream.connection.connectionId,fromId:o.session.connection.connectionId,fromX:p.lastX,fromY:p.lastY,toX:f,toY:v,color:e?t.userColor:o.userColor,lineWidth:o.lineWidth,videoWidth:o.videoFeed.videoElement().clientWidth,videoHeight:o.videoFeed.videoElement().clientHeight,canvasWidth:a.width,canvasHeight:a.height,mirrored:r,startPoint:o.isStartPoint,endPoint:!0,selectedItem:y},x(n,!0),p.lastX=f,p.lastY=v,!e&&S(n),o.isStartPoint=!1;break;case"mouseout":p.dragging=!1}else if("OT_text"===y.id)n={id:o.videoFeed.stream.connection.connectionId,fromId:o.session.connection.connectionId,fromX:f,fromY:v+t.inputHeight,color:t.userColor,font:t.font,text:t.text,videoWidth:o.videoFeed.videoElement().clientWidth,videoHeight:o.videoFeed.videoElement().clientHeight,canvasWidth:a.width,canvasHeight:a.height,mirrored:r,selectedItem:y},x(n),!e&&S(n);else if(y&&y.points)switch(p.mX=f,p.mY=v,t.type){case"mousedown":case"touchstart":p.isDrawing=!0,p.dragging=!0,p.startX=f,p.startY=v;break;case"mousemove":case"touchmove":p.dragging&&(n={color:e?t.userColor:o.userColor,lineWidth:e?t.lineWidth:o.lineWidth,selectedItem:y},x(n,!0));break;case"mouseup":case"touchend":p.isDrawing=!1;var b=y.points;if(2===b.length)n={id:o.videoFeed.stream.connection.connectionId,fromId:o.session.connection.connectionId,fromX:p.startX,fromY:p.startY,toX:p.mX,toY:p.mY,color:e?t.userColor:o.userColor,lineWidth:e?t.lineWidth:o.lineWidth,videoWidth:o.videoFeed.videoElement().clientWidth,videoHeight:o.videoFeed.videoElement().clientHeight,canvasWidth:a.width,canvasHeight:a.height,mirrored:r,smoothed:!1,startPoint:!0,endPoint:!0,selectedItem:y},u.push(n),!e&&S(n);else{for(var I=P(b),w=0;w<b.length;w++){var T=!1,W=!1,_=p.startX+I.x*b[w][0],M=p.startY+I.y*b[w][1];0===w?(p.lastX=_,p.lastY=M,T=!0):w===b.length-1&&(W=!0),n={id:o.videoFeed.stream.connection.connectionId,fromId:o.session.connection.connectionId,fromX:p.lastX,fromY:p.lastY,toX:_,toY:M,color:e?t.userColor:o.userColor,lineWidth:e?t.lineWidth:o.lineWidth,videoWidth:o.videoFeed.videoElement().clientWidth,videoHeight:o.videoFeed.videoElement().clientHeight,canvasWidth:a.width,canvasHeight:a.height,mirrored:r,smoothed:y.enableSmoothing,startPoint:T,endPoint:W},u.push(n),!e&&S(n),p.lastX=_,p.lastY=M}x(null)}p.dragging=!1}}t=t||{},this.widgetVersion="js-1.0.0-beta",this.parent=t.container,this.videoFeed=t.feed;var i=t.externalWindow?t.externalWindow.document:window.document,o=this;if(this.parent){var a=document.createElement("canvas");a.setAttribute("id","opentok_canvas"),a.style.position="absolute",this.parent.appendChild(a),a.setAttribute("width",this.parent.clientWidth+"px"),a.style.width=window.getComputedStyle(this.parent).width,a.setAttribute("height",this.parent.clientHeight+"px"),a.style.height=window.getComputedStyle(this.parent).height}var s,r,c,l,o=this,d=[],h=[],u=[],g=[],m=[],p={dragging:!1};r=(" "+o.videoFeed.element.className+" ").indexOf(" OT_mirrored ")>-1,c=(" "+o.videoFeed.element.className+" ").indexOf(" OT_fit-mode-cover ")>-1,this.canvas=function(){return a},this.link=function(t){this.session=t},this.changeColor=function(t){o.userColor=t,o.lineWidth||(o.lineWidth=2)},this.changeLineWidth=function(t){this.lineWidth=t},this.selectItem=function(t){o.overlay&&(o.overlay.style.display="none",o.overlay=null),"OT_capture"===t.id?(o.selectedItem=t,o.overlay?o.overlay.style="inline":(o.overlay=document.createElement("div"),o.overlay.style.position="absolute",o.overlay.style.width=o.parent.clientWidth+"px",o.overlay.style.height=o.parent.clientHeight+"px",o.overlay.style.background='rgba(0,0,0,0.4) url("../images/annotation/camera.png") no-repeat center',o.overlay.style.backgroundSize="50px 50px",o.overlay.style.cursor="pointer",o.overlay.style.opacity=0,o.parent.appendChild(o.overlay),o.parent.onmouseover=function(){o.overlay.style.opacity=1},o.parent.onmouseout=function(){o.overlay.style.opacity=0},o.overlay.onclick=function(){o.captureScreenshot()})):t.id.indexOf("OT_line_width")!==-1?t.size&&o.changeLineWidth(t.size):o.selectedItem=t},this.colors=function(t){this.colors=t,this.changeColor(t[0])},this.clear=function(){k(!1,o.session.connection.connectionId),o.session&&o.session.signal({type:"otAnnotation_clear"})},this.captureScreenshot=function(){var t=document.createElement("canvas");t.width=a.width,t.height=a.height;var e=o.videoFeed.videoWidth(),n=o.videoFeed.videoHeight(),i=1,s=0,l=0;c?(e<n?(i=a.width/e,e=a.width,n*=i):(i=a.height/n,n=a.height,e*=i),s=(e-a.width)/2,l=(n-a.height)/2):e>n?(i=a.width/e,e=a.width,n*=i):(i=a.height/n,n=a.height,e*=i);var h=new Image;h.onload=function(){var i=t.getContext("2d");r&&(i.translate(e,0),i.scale(-1,1)),i.drawImage(h,s,l,e,n),r&&(i.translate(e,0),i.scale(-1,1)),i.drawImage(a,0,0),d.forEach(function(e){e.call(o,t.toDataURL())}),t=null},h.src="data:image/png;base64,"+o.videoFeed.getImgData()},this.onScreenCapture=function(t){d.push(t)},this.onResize=function(){u=[],O(g,!0),m.forEach(function(t){n(t,!0)})},e(a,"mousedown mousemove mouseup mouseout touchstart touchmove touchend",function(t){var e=o.selectedItem&&"OT_text"===o.selectedItem.id,i="mousemove"===t.type&&!p.dragging;e||i||(t.preventDefault(),t.selectedItem=o.selectedItem,t.selectedItem&&(t.canvas={width:a.width,height:a.height,offsetLeft:a.offsetLeft,offsetTop:a.offsetTop},t.userColor=o.userColor,t.lineWidth=o.lineWidth,m.push(t)),n(t))});var f,v="textAnnotation",y=!1,b=function(t){t.preventDefault(),o.selectedItem&&"OT_text"===o.selectedItem.id&&!y&&(y=!0,t.selectedItem=o.selectedItem,_(t))},I=function(t){13===t.which&&W(),27===t.which&&(i.getElementById(v).remove(),f=null),y=!1},w=function(){i.addEventListener("keydown",I)},T=function(){i.removeEventListener("keydown",I)},W=function(){var t=i.getElementById(v);t.clientHeight;return t.value?(t.remove(),T(),f.text=t.value,f.font="16px Arial",f.userColor=o.userColor,f.canvas={width:a.width,height:a.height,offsetLeft:a.offsetLeft,offsetTop:a.offsetTop},m.push(f),void n(f)):void(f=null)},_=function(t){var e=i.createElement("input");e.setAttribute("type","text"),e.style.position="absolute",e.style.top=t.clientY+"px",e.style.left=t.clientX+"px",e.style.background="rgba(255,255,255, .5)",e.style.width="100px",e.style.maxWidth="200px",e.style.border="1px dashed red",e.style.fontSize="16px",e.style.color=o.userColor,e.style.fontFamily="Arial",e.style.zIndex="1001",e.setAttribute("data-canvas-origin",JSON.stringify({x:t.offsetX,y:t.offsetY})),e.id=v,i.body.appendChild(e),e.focus(),f=t,f.inputHeight=e.clientHeight,w()};e(a,"click",b);var x=function(t,e){s||(s=a.getContext("2d"),s.lineCap="round",s.lineJoin="round",s.fillStyle="solid"),s.clearRect(0,0,a.width,a.height),u.forEach(function(t){s.strokeStyle=t.color,s.lineWidth=t.lineWidth,t.smoothed=!!t.smoothed,t.startPoint=!!t.startPoint;var e=!1,n=!!t.selectedItem&&"Text"===t.selectedItem.title&&t.text;n?(s.font=t.font,s.fillStyle=t.color,s.fillText(t.text,t.fromX,t.fromY)):t.smoothed?(t.startPoint?o.isStartPoint=!0:o.isStartPoint&&(e=!0,o.isStartPoint=!1),t.startPoint?(s.closePath(),s.beginPath()):e?s.moveTo((t.fromX+t.toX)/2,(t.fromY+t.toY)/2):(s.quadraticCurveTo(t.fromX,t.fromY,(t.fromX+t.toX)/2,(t.fromY+t.toY)/2),s.stroke())):(s.beginPath(),s.moveTo(t.fromX,t.fromY),s.lineTo(t.toX,t.toY),s.stroke(),s.closePath())});var n=e?t.selectedItem:o.selectedItem;!n||"Pen"!==n.title&&"Text"!==n.title?p.isDrawing&&(t&&(s.strokeStyle=t.color,s.lineWidth=t.lineWidth),n&&n.points&&M(s,o.selectedItem.points)):t&&("Pen"===n.title&&(s.strokeStyle=t.color,s.lineWidth=t.lineWidth,s.beginPath(),s.moveTo(t.fromX,t.fromY),s.lineTo(t.toX,t.toY),s.stroke(),s.closePath()),"Text"===n.title&&(s.font=t.font,s.fillStyle=t.color,s.fillText(t.text,t.fromX,t.fromY)),u.push(t))},M=function(t,e){var n=P(e);if(t.beginPath(),2===e.length)t.moveTo(p.startX,p.startY),t.lineTo(p.mX,p.mY);else for(var i=0;i<e.length;i++){var a=p.startX+n.x*e[i][0],s=p.startY+n.y*e[i][1];o.selectedItem.enableSmoothing?0===i||(1===i?(t.moveTo((a+p.lastX)/2,(s+p.lastY)/2),p.lastX=(a+p.lastX)/2,p.lastX=(s+p.lastY)/2):(t.quadraticCurveTo(p.lastX,p.lastY,(a+p.lastX)/2,(s+p.lastY)/2),p.lastX=(a+p.lastX)/2,p.lastY=(s+p.lastY)/2)):0===i?t.moveTo(a,s):t.lineTo(a,s),p.lastX=a,p.lastY=s}t.stroke(),t.closePath()},P=function(t){for(var e=Number.MAX_VALUE,n=Number.MAX_VALUE,i=0,o=0,a=0;a<t.length;a++)t[a][0]<e?e=t[a][0]:t[a][0]>i&&(i=t[a][0]),t[a][1]<n?n=t[a][1]:t[a][1]>o&&(o=t[a][1]);var s=Math.abs(i-e),r=Math.abs(o-n),c=(p.mX-p.startX)/s,l=(p.mY-p.startY)/r;return{x:c,y:l}},C=function(t,e,n){var i={width:t.canvasWidth,height:t.canvasHeight},s={width:t.videoWidth,height:t.videoHeight},c={width:o.videoFeed.videoElement().clientWidth,height:o.videoFeed.videoElement().clientHeight},l=1,d=a.width/a.height;c.width/c.height,i.width/i.height,s.width/s.height;l=d<0?a.width/i.width:a.height/i.height;var h=a.width/2,m=a.height/2,p=i.width/2,f=i.height/2;t.fromX=h-l*(p-t.fromX),t.fromY=m-l*(f-t.fromY),t.toX=h-l*(p-t.toX),t.toY=m-l*(f-t.toY),t.mirrored=!!t.mirrored,t.mirrored&&(t.fromX=a.width-t.fromX,t.toX=a.width-t.toX),r&&(t.fromX=a.width-t.fromX,t.toX=a.width-t.toX);var v=JSON.parse(JSON.stringify(t));v.canvasWidth=a.width,v.canvasHeight=a.height,v.videoWidth=c.width,v.videoHeight=c.height,e?g[n]=v:g.push(v),u.push(t),x(null)},O=function(t,e){t.forEach(function(t,n){t.id===o.videoFeed.stream.connection.connectionId&&C(t,e,n)})},k=function(t,e){u=u.filter(function(t){return console.log(t.fromId),t.fromId!==e}),t?g=[]:(o.session&&o.session.signal({type:"otAnnotation_clear"}),m=[]),x()};o.videoFeed.session&&o.videoFeed.session.on({"signal:otAnnotation_pen":function(t){t.from.connectionId!==o.session.connection.connectionId&&O(JSON.parse(t.data))},"signal:otAnnotation_text":function(t){t.from.connectionId!==o.session.connection.connectionId&&O(JSON.parse(t.data))},"signal:otAnnotation_history":function(t){l&&l!==t.from.connectionId||(l=t.from.connectionId,O(JSON.parse(t.data)))},"signal:otAnnotation_clear":function(t){t.from.connectionId!==o.session.connection.connectionId&&k(!0,t.from.connectionId)},connectionCreated:function(t){u.length>0&&t.connection.connectionId!==o.session.connection.connectionId&&A("otWhiteboard_history",u,t.connection)}});var E,A=function(t,e){for(var n=t.slice(),i=function(t){t&&TB.error(t)},a="otAnnotation_pen",s=function(t){if(t&&t[0]&&t[0].selectedItem&&t[0].selectedItem.id){var e=t[0].selectedItem.id;a="OT_text"===e?"otAnnotation_text":"otAnnotation_pen"}};n.length;){var r=n.splice(0,Math.min(n.length,32));s(r);var c={type:a,data:JSON.stringify(r)};e&&(c.to=e),o.session.signal(c,i)}},S=function(t){o.session&&(h.push(t),E||(E=setTimeout(function(){A(h),h=[],E=null},100)))}},OTSolution.Annotations.Toolbar=function(t){var e=this,n=this;t||(t={}),this.session=t.session,this.parent=t.container,this.externalWindow=t.externalWindow,this.backgroundColor=t.backgroundColor||"rgba(0, 0, 0, 0.7)",this.buttonWidth=t.buttonWidth||"40px",this.buttonHeight=t.buttonHeight||"40px",this.iconWidth=t.iconWidth||"30px",this.iconHeight=t.iconHeight||"30px",this.items=t.items||[{id:"OT_pen",title:"Pen",icon:"../images/annotation/freehand.png",selectedIcon:"../images/annotation/freehand_selected.png"},{id:"OT_line",title:"Line",icon:"../images/annotation/line.png",selectedIcon:"../images/annotation/line_selected.png",points:[[0,0],[0,1]]},{id:"OT_shapes",title:"Shapes",icon:"../images/annotation/shapes.png",items:[{id:"OT_arrow",title:"Arrow",icon:"../images/annotation/arrow.png",points:[[0,1],[3,1],[3,0],[5,2],[3,4],[3,3],[0,3],[0,1]]},{id:"OT_rect",title:"Rectangle",icon:"../images/annotation/rectangle.png",points:[[0,0],[1,0],[1,1],[0,1],[0,0]]},{id:"OT_oval",title:"Oval",icon:"../images/annotation/oval.png",enableSmoothing:!0,points:[[0,.5],[.5+.5*Math.cos(5*Math.PI/4),.5+.5*Math.sin(5*Math.PI/4)],[.5,0],[.5+.5*Math.cos(7*Math.PI/4),.5+.5*Math.sin(7*Math.PI/4)],[1,.5],[.5+.5*Math.cos(Math.PI/4),.5+.5*Math.sin(Math.PI/4)],[.5,1],[.5+.5*Math.cos(3*Math.PI/4),.5+.5*Math.sin(3*Math.PI/4)],[0,.5],[.5+.5*Math.cos(5*Math.PI/4),.5+.5*Math.sin(5*Math.PI/4)]]}]},{id:"OT_text",title:"Text",icon:"../images/annotation/text.png",selectedIcon:"../images/annotation/text.png"},{id:"OT_colors",title:"Colors",icon:"",items:{}},{id:"OT_line_width",title:"Line Width",icon:"../images/annotation/line_width.png",items:{}},{id:"OT_clear",title:"Clear",icon:"../images/annotation/clear.png"},{id:"OT_capture",title:"Capture",icon:"../images/annotation/camera.png",selectedIcon:"../images/annotation/camera_selected.png"}],this.colors=t.colors||["#1abc9c","#2ecc71","#3498db","#9b59b6","#34495e","#16a085","#27ae60","#2980b9","#8e44ad","#2c3e50","#f1c40f","#e67e22","#e74c3c","#ecf0f1","#95a5a6","#f39c12","#d35400","#c0392b","#bdc3c7","#7f8c8d"],this.cbs=[];var i,o=[],a=function(t,e,i){var o=this,a=n.externalWindow?n.externalWindow.document:document;this.getElm=function(t){return"string"==typeof t?a.querySelector(t):t},this.render=function(){var t=this,e="";t.colors.forEach(function(n){e+=t.options.template.replace(/\{color\}/g,n)}),t.elm.innerHTML=e},this.close=function(){this.elm.style.display="none"},this.open=function(){this.elm.style.display=this.options.style.display},this.colorChosen=function(t){this.cbs.push(t)},this.set=function(t,e){var n=this;n.color=t,e!==!1&&n.cbs.forEach(function(e){e.call(n,t)})},i=i||{},i.openEvent=i.openEvent||"click",i.style=Object(i.style),i.style.display=i.style.display||"block",i.template=i.template||'<div class="color-choice" data-col="{color}" style="background-color: {color}"></div>',o.elm=o.getElm(t),o.cbs=[],o.colors=e,o.options=i,o.render(),o.elm.addEventListener("click",function(t){var e=t.target.getAttribute("data-col");e&&(o.set(e),o.close())}),i.autoclose!==!1&&o.close()};this.createPanel=function(t){if(n.parent){var r=t?t.document:document;i=r.createElement("div"),i.setAttribute("id","OT_toolbar"),i.setAttribute("class","OT_panel"),i.style.width="100%",i.style.height="100%",i.style.backgroundColor=this.backgroundColor,this.parent.appendChild(i),this.parent.style.position="relative",this.parent.zIndex=1e3;for(var c=[],l=r.createElement("div"),d=0,h=this.items.length;d<h;d++){var u=this.items[d],g=r.createElement("input");if(g.setAttribute("type","button"),g.setAttribute("id",u.id),g.style.position="relative",g.style.top="50%",g.style.transform="translateY(-50%)","OT_colors"===u.id){g.style.webkitTransform="translateY(-85%)";var m=r.createElement("div");m.setAttribute("class","color-picker"),m.style.backgroundColor=this.backgroundColor,this.parent.appendChild(m);var p=new a(".color-picker",this.colors,{externalWindow:n.externalWindow});p.colorChosen(function(t){var e=r.getElementById("OT_colors");e.style.backgroundColor=t,o.forEach(function(e){e.changeColor(t)})});for(var f=r.querySelectorAll(".color-choice"),v=0;v<f.length;v++)f[v].style.display="inline-block",f[v].style.width="30px",f[v].style.height="30px",f[v].style.margin="5px",f[v].style.cursor="pointer",f[v].style.borderRadius="100%",f[v].style.opacity=.7,f[v].onmouseover=function(){this.style.opacity=1},f[v].onmouseout=function(){this.style.opacity=.7};g.setAttribute("class","OT_color"),g.style.marginLeft="10px",g.style.marginRight="10px",g.style.borderRadius="50%",g.style.backgroundColor=this.colors[0],g.style.width=this.iconWidth,g.style.height=this.iconHeight,g.style.paddingTop=this.buttonHeight.replace("px","")-this.iconHeight.replace("px","")+"px"}else g.style.background='url("'+u.icon+'") no-repeat',g.style.backgroundSize=this.iconWidth+" "+this.iconHeight,g.style.backgroundPosition="center",g.style.width=this.buttonWidth,g.style.height=this.buttonHeight;"Line Width"!==u.title||Array.isArray(u.items)||(u.items=[{id:"OT_line_width_2",title:"Line Width 2",size:2},{id:"OT_line_width_4",title:"Line Width 4",size:4},{id:"OT_line_width_6",title:"Line Width 6",size:6},{id:"OT_line_width_8",title:"Line Width 8",size:8},{id:"OT_line_width_10",title:"Line Width 10",size:10},{id:"OT_line_width_12",title:"Line Width 12",size:12},{id:"OT_line_width_14",title:"Line Width 14",size:14}]),u.items&&g.setAttribute("data-type","group"),g.setAttribute("data-col",u.title),g.style.border="none",g.style.cursor="pointer",c.push(g.outerHTML)}i.innerHTML=c.join(""),i.onclick=function(t){var n="group"===t.target.getAttribute("data-type"),i=t.target.getAttribute("data-col"),a=t.target.getAttribute("id");n?e.items.forEach(function(t){if(t.title===i){if(e.selectedGroup=t,t.items&&(l.setAttribute("class","OT_subpanel"),l.style.backgroundColor=e.backgroundColor,l.style.width="100%",l.style.height="100%",l.style.paddingLeft="15px",l.style.display="none",e.parent.appendChild(l),Array.isArray(t.items))){var n=[];"OT_line_width"===t.id?t.items.forEach(function(t){var i=r.createElement("div");i.setAttribute("data-col",t.title),i.setAttribute("id",t.id),i.style.position="relative",i.style.top="50%",i.style.transform="translateY(-50%)",i.style["float"]="left",i.style.width=e.buttonWidth,i.style.height=e.buttonHeight,i.style.border="none",i.style.cursor="pointer";var o=r.createElement("div");o.style.backgroundColor="#FFFFFF",o.style.width="80%",o.style.height=t.size+"px",o.style.position="relative",o.style.left="50%",o.style.top="50%",o.style.transform="translateX(-50%) translateY(-50%)",o.style.pointerEvents="none",i.appendChild(o),n.push(i.outerHTML)}):t.items.forEach(function(t){var i=r.createElement("input");i.setAttribute("type","button"),i.setAttribute("data-col",t.title),i.setAttribute("id",t.id),i.style.background='url("'+t.icon+'") no-repeat',i.style.position="relative",i.style.top="50%",i.style.transform="translateY(-50%)",i.style.backgroundSize=e.iconWidth+" "+e.iconHeight,i.style.backgroundPosition="center",i.style.width=e.buttonWidth,i.style.height=e.buttonHeight,i.style.border="none",i.style.cursor="pointer",n.push(i.outerHTML)}),l.innerHTML=n.join("")}"OT_shapes"===a||"OT_line_width"===a?(l&&(l.style.display="block"),p.close()):"OT_colors"===a&&(l&&(l.style.display="none"),p.open())}}):(e.items.forEach(function(t){if("Clear"!==t.title&&t.title===i){if(e.selectedItem){var n=r.getElementById(e.selectedItem.id);n&&(n.style.background='url("'+e.selectedItem.icon+'") no-repeat',n.style.backgroundSize=e.iconWidth+" "+e.iconHeight,n.style.backgroundPosition="center")}if(t.selectedIcon){var a=r.getElementById(t.id);a&&(a.style.background='url("'+t.selectedIcon+'") no-repeat',a.style.backgroundSize=e.iconWidth+" "+e.iconHeight,a.style.backgroundPosition="center")}return e.selectedItem=t,s(t),o.forEach(function(t){t.selectItem(e.selectedItem)}),!1}}),l.style.display="none"),e.cbs.forEach(function(t){t.call(e,a)})},l.onclick=function(t){var n="group"===t.target.getAttribute("data-type"),i=(t.target.getAttribute("data-col"),t.target.getAttribute("id"));l.style.display="none",n||e.selectedGroup.items.forEach(function(t){if("OT_clear"!==t.id&&t.id===i){if(e.selectedItem){var n=document.getElementById(e.selectedItem.id);n&&(n.style.background='url("'+e.selectedItem.icon+'") no-repeat',n.style.backgroundSize=e.iconWidth+" "+e.iconHeight,n.style.backgroundPosition="center")}if(t.selectedIcon){var a=document.getElementById(t.id);n&&(a.style.background='url("'+t.selectedIcon+'") no-repeat',a.style.backgroundSize=e.iconWidth+" "+e.iconHeight,a.style.backgroundPosition="center")}return e.selectedItem=t,s(t),o.forEach(function(t){t.selectItem(e.selectedItem)}),!1}}),e.cbs.forEach(function(t){t.call(e,i)})},r.getElementById("OT_clear").onclick=function(){o.forEach(function(t){t.clear()})}}},!this.externalWindow&&this.createPanel();var s=function(t){t.points||("OT_line"===t.id?e.selectedItem.points=[[0,0],[0,1]]:"OT_arrow"===t.id?e.selectedItem.points=[[0,1],[3,1],[3,0],[5,2],[3,4],[3,3],[0,3],[0,1]]:"OT_rect"===t.id?e.selectedItem.points=[[0,0],[1,0],[1,1],[0,1],[0,0]]:"OT_oval"===t.id&&(e.selectedItem.enableSmoothing=!0,e.selectedItem.points=[[0,.5],[.5+.5*Math.cos(5*Math.PI/4),.5+.5*Math.sin(5*Math.PI/4)],[.5,0],[.5+.5*Math.cos(7*Math.PI/4),.5+.5*Math.sin(7*Math.PI/4)],[1,.5],[.5+.5*Math.cos(Math.PI/4),.5+.5*Math.sin(Math.PI/4)],[.5,1],[.5+.5*Math.cos(3*Math.PI/4),.5+.5*Math.sin(3*Math.PI/4)],[0,.5],[.5+.5*Math.cos(5*Math.PI/4),.5+.5*Math.sin(5*Math.PI/4)]]))};this.itemClicked=function(t){this.cbs.push(t)},this.addCanvas=function(t){var e=this;t.link(e.session),t.colors(e.colors),o.push(t)},this.removeCanvas=function(t){o.forEach(function(e){var n=e.canvas();e.videoFeed.stream.connection.connectionId===t&&n.parentNode&&n.parentNode.removeChild(n)}),o=o.filter(function(e){return e.videoFeed.stream.connection.connectionId!==t})},this.remove=function(){try{i.parentNode.removeChild(i)}catch(t){console.log(t)}o.forEach(function(t){var e=t.canvas();e.parentNode&&e.parentNode.removeChild(e)}),o=[]}},function(){var t,e,n;"object"==typeof module&&"object"==typeof module.exports?(t=require("underscore"),e=require("jquery"),n="opentok-solutions-logging"):(t=this._,e=this.$,n=this.OTKAnalytics);var i,o,a,s,r,c={},l={clientVersion:"js-vsol-1.0.0",componentId:"annotationsKit",name:"guidAnnotationsKit",actionInitialize:"Init",actionStart:"Start",actionEnd:"Done",actionFreeHand:"FreeHand",actionPickerColor:"PickerColor",actionText:"Text",actionScreenCapture:"ScreenCapture",actionErase:"Erase",variationAttempt:"Attempt",variationError:"Failure",variationSuccess:"Success"},d=function(){var t=window.location.href,e={clientVersion:l.clientVersion,source:t,componentId:l.componentId,name:l.name};r=new n(e);var i={sessionId:a.id,connectionId:a.connection.connectionId,partnerId:a.apiKey};r.addSessionInfo(i)},h=function(t,e){var n={action:t,variation:e};r.logEvent(n)},u=function(t,e){o&&o.triggerEvent(t,e)},g=function(){var t=["startAnnotation","linkAnnotation","resizeCanvas","annotationWindowClosed","endAnnotation"];o.registerEvents(t)},m=function(){var t=['<div id="toolbar"></div>'].join("\n");e("body").append(t)},p=[{id:"OT_pen",title:"Pen",icon:"../images/annotation/freehand.png",selectedIcon:"../images/annotation/freehand_selected.png"},{id:"OT_line",title:"Line",icon:"../images/annotation/line.png",selectedIcon:"../images/annotation/line_selected.png"},{id:"OT_text",title:"Text",icon:"../images/annotation/text.png",selectedIcon:"../images/annotation/text.png"},{id:"OT_shapes",title:"Shapes",icon:"../images/annotation/shapes.png",items:[{id:"OT_arrow",title:"Arrow",icon:"../images/annotation/arrow.png"},{id:"OT_rect",title:"Rectangle",icon:"../images/annotation/rectangle.png"},{id:"OT_oval",title:"Oval",icon:"../images/annotation/oval.png"},{id:"OT_star",title:"Star",icon:"../images/annotation/star.png",points:[[.5+.5*Math.cos(90*(Math.PI/180)),.5+.5*Math.sin(90*(Math.PI/180))],[.5+.25*Math.cos(126*(Math.PI/180)),.5+.25*Math.sin(126*(Math.PI/180))],[.5+.5*Math.cos(162*(Math.PI/180)),.5+.5*Math.sin(162*(Math.PI/180))],[.5+.25*Math.cos(198*(Math.PI/180)),.5+.25*Math.sin(198*(Math.PI/180))],[.5+.5*Math.cos(234*(Math.PI/180)),.5+.5*Math.sin(234*(Math.PI/180))],[.5+.25*Math.cos(270*(Math.PI/180)),.5+.25*Math.sin(270*(Math.PI/180))],[.5+.5*Math.cos(306*(Math.PI/180)),.5+.5*Math.sin(306*(Math.PI/180))],[.5+.25*Math.cos(342*(Math.PI/180)),.5+.25*Math.sin(342*(Math.PI/180))],[.5+.5*Math.cos(18*(Math.PI/180)),.5+.5*Math.sin(18*(Math.PI/180))],[.5+.25*Math.cos(54*(Math.PI/180)),.5+.25*Math.sin(54*(Math.PI/180))],[.5+.5*Math.cos(90*(Math.PI/180)),.5+.5*Math.sin(90*(Math.PI/180))]]}]},{id:"OT_colors",title:"Colors",icon:"",items:{}},{id:"OT_line_width",title:"Line Width",icon:"../images/annotation/line_width.png",items:{}},{id:"OT_clear",title:"Clear",icon:"../images/annotation/clear.png"}],f=["#1abc9c","#2ecc71","#3498db","#9b59b6","#8e44ad","#f1c40f","#e67e22","#e74c3c","#ded5d5"],v=10/6,y=t.throttle(function(){s.onResize()},1e3),b=function(){var t,n;if(c.externalWindow){var i={width:c.externalWindow.innerWidth,height:c.externalWindow.innerHeight},o=i.width/v;o<=i.height?(t=i.width,n=o):(n=i.height,t=n*v)}else{var a=c.absoluteParent||c.canvasContainer;t=e(a).width(),n=e(a).height()}e(c.canvasContainer).css({width:t,height:n}),e(c.canvas).css({width:t,height:n}),e(c.canvas).attr({width:t,height:n}),y(),u("resizeCanvas")},I=function(){e(c.resizeSubject).on("resize",t.throttle(function(){b()},500))},w=function(e,n,i){var o=t.property("toolbarId")(n)||"toolbar",a=t.property("toolbarItems")(n)||p,s=t.property("colors")(n)||f,r=function(){var t=i?i:window;return t.document.getElementById(o)};toolbar=new OTSolution.Annotations.Toolbar({session:e,container:r(),colors:s,items:a,externalWindow:i||null}),toolbar.itemClicked(function(t){var e={OT_pen:l.actionFreeHand,OT_colors:l.actionPickerColor,OT_text:l.actionText,OT_clear:l.actionErase},n=e[t];n&&(h(n,l.variationAttempt),h(n,l.variationSuccess))})},T=function(){var t=e.Deferred(),n=.8*screen.width|0,i=n/v,o=["templates/screenshare.html?opentok-annotation"].join(""),a=["toolbar=no","location=no","directories=no","status=no","menubar=no","scrollbars=no","resizable=no","copyhistory=no",["width=",n].join(""),["height=",i].join(""),["left=",screen.width/2-n/2].join(""),["top=",screen.height/2-i/2].join("")].join(","),s=window.open(o,"",a);window.onbeforeunload=function(){s.close()},s.toolbar=toolbar,s.OT=OT,s.$=e,s.triggerCloseEvent=function(){u("annotationWindowClosed")};var r=function(){s.createContainerElements?e(s.document).ready(function(){t.resolve(s)}):setTimeout(r,100)};return r(),t.promise()},W=function(){e(c.resizeSubject).off("resize",b),toolbar.remove()},_=function(n,i){var o=e.Deferred();return h(l.actionStart,l.variationAttempt),t.property("screensharing")(i)?T().then(function(t){w(n,i,t),toolbar.createPanel(t),u("startAnnotation",t),h(l.actionStart,l.variationSuccess),o.resolve(t)}):(w(n,i),u("startAnnotation"),h(l.actionStart,l.variationSuccess),o.resolve()),o.promise()},x=function(n,i,o){c.resizeSubject=t.property("externalWindow")(o)||window,c.externalWindow=t.property("externalWindow")(o)||null,c.absoluteParent=t.property("absoluteParent")(o)||null,c.canvasContainer=i,s=new OTSolution.Annotations({feed:n,container:i,externalWindow:c.externalWindow}),toolbar.addCanvas(s),s.onScreenCapture(function(t){var e=window.open(t,"_blank");e.focus()});var a=c.externalWindow?c.externalWindow:window;c.canvas=e(t.first(a.document.getElementsByTagName("canvas"))),I(),b(),u("linkAnnotation")},M=function(){b()},P=function(t){h(l.actionEnd,l.variationAttempt),W(),c.canvas=null,t&&(c.externalWindow&&(c.externalWindow.close(),c.externalWindow=null,c.resizeSubject=null),u("endAnnotation")),h(l.actionEnd,l.variationSuccess)},C=function(e){if(i=this,i.options=t.omit(e,"accPack","session"),o=t.property("accPack")(e),a=t.property("session")(e),!a)throw new Error("OpenTok Annotation Accelerator Pack requires an OpenTok session");g(),m(),d(),h(l.actionInitialize,l.variationAttempt),h(l.actionInitialize,l.variationSuccess)};C.prototype={constructor:C,start:_,linkCanvas:x,resizeCanvas:M,end:P},"object"==typeof exports?module.exports=C:"function"==typeof define&&define.amd?define(function(){return C}):this.AnnotationAccPack=C}.call(this);
{
"name": "opentok-annotation",
"version": "1.0.14",
"version": "1.0.15",
"description": "OpenTok annotation accelerator pack",

@@ -5,0 +5,0 @@ "main": "dist/opentok-annotation.js",

@@ -12,3 +12,3 @@ /* global OT OTSolution OTKAnalytics ScreenSharingAccPack define */

$ = require('jquery');
OTKAnalytics = ('opentok-solutions-logging');
OTKAnalytics = require('opentok-solutions-logging');
/* eslint-enable import/no-unresolved */

@@ -15,0 +15,0 @@ } else {

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc