From 9d751ea06d99fed093db483d1d7acba2c4f16d1e Mon Sep 17 00:00:00 2001 From: mysterion <49054698+mysterion@users.noreply.github.com> Date: Thu, 4 Apr 2024 23:32:11 +0530 Subject: [PATCH] 1.3.1 --- static/index-Bp6QC3UT.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 static/index-Bp6QC3UT.js diff --git a/static/index-Bp6QC3UT.js b/static/index-Bp6QC3UT.js new file mode 100644 index 0000000..e0fdd66 --- /dev/null +++ b/static/index-Bp6QC3UT.js @@ -0,0 +1,7 @@ +var J=Object.defineProperty;var Z=(e,t,i)=>t in e?J(e,t,{enumerable:!0,configurable:!0,writable:!0,value:i}):e[t]=i;var G=(e,t,i)=>(Z(e,typeof t!="symbol"?t+"":t,i),i);(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const n of document.querySelectorAll('link[rel="modulepreload"]'))s(n);new MutationObserver(n=>{for(const l of n)if(l.type==="childList")for(const h of l.addedNodes)h.tagName==="LINK"&&h.rel==="modulepreload"&&s(h)}).observe(document,{childList:!0,subtree:!0});function i(n){const l={};return n.integrity&&(l.integrity=n.integrity),n.referrerPolicy&&(l.referrerPolicy=n.referrerPolicy),n.crossOrigin==="use-credentials"?l.credentials="include":n.crossOrigin==="anonymous"?l.credentials="omit":l.credentials="same-origin",l}function s(n){if(n.ep)return;n.ep=!0;const l=i(n);fetch(n.href,l)}})();const B="controls-hidden",U="controls-shown",T="controls";AFRAME.registerComponent("controls",{init:function(){this.system.register(this.el)},remove:function(){this.system.unregister(this.el)}});AFRAME.registerSystem("controls",{init:function(){this.entities=[],this.clickables=[]},register:function(e){this.entities.push(e)},unregister:function(e){var t=this.entities.indexOf(e);this.entities.splice(t,1)},hideControls:function(){for(let e in this.entities){let t=this.entities[e];this.clickables.push(t.hasAttribute("clickable")),this.clickables.at(-1)&&t.removeAttribute("clickable"),t.object3D.visible=!1}o.events.emit(T,B,!1)},showControls:function(){for(let e in this.entities){let t=this.entities[e];this.clickables[e]&&t.setAttribute("clickable",""),t.object3D.visible=!0}this.clickables=[],o.events.emit(T,U,!1)}});const F={SETTINGS:"Settings",VIDSTATE:"VideoState",CONTROLS:"Controls",ENVIRONMENT:"Environment"};AFRAME.registerComponent("events",{init:function(){console.log("Events initialized...")}});AFRAME.registerComponent("stereo",{schema:{eye:{type:"string",default:"both"}},init:function(){this.setMask=AFRAME.utils.bind(this.setMask,this)},update:function(e){let t=0;this.data.eye==="left"?t=1:this.data.eye==="right"&&(t=2),this.setMask(t,this.el.object3D)},setMask:function(e,t){if(t.isMesh)t.layers.set(e);else for(let i in t.children)this.setMask(e,t.children[i])},remove:function(e){this.setMask(0,this.el.object3D)}});const v=function(){return{get:i=>JSON.parse(localStorage.getItem(i)),set:(i,s)=>{localStorage.setItem(i,JSON.stringify(s))}}}();function ee(e,t){return e||(e="#FFF"),e==="#FFF"&&(t*=-1),"#"+e.replace(/^#/,"").replace(/../g,i=>("0"+Math.min(255,Math.max(0,parseInt(i,16)+t)).toString(16)).substr(-2))}function $(e){isNaN(e)&&(e=0);var t=new Date(null);return t.setSeconds(e),t.toISOString().substr(11,8)}function H(e){return e.replace(/^.*[\\/]/,"")}function r(e="a-entity",t={},i=[],s=null){const n=document.createElement(e);for(let l in t)n.setAttribute(l,t[l]);return i.length>0&&n.append(...i),s!==null&&s.appendChild(n),n}function te(e,t){return e.getAttribute(t)}function c(e,t={}){for(let i in t)e.setAttribute(i,t[i])}function ie(e,t){return Object.fromEntries(Object.entries(t).filter(([i,s])=>i in e&&e[i]!==s))}function se(e){for(const t in e)return!1;return!0}function ne(e){return document.querySelector("#"+e)}const S="settings",u={RESUME_VIDEO:"resumeVideo",DEF_PRESET:"defaultPreset",SAVE_PRESET:"savePreset",DEF_EYE:"defaultEye",VIEW_ANG:"viewAngle",UI_ANG:"uiAngle"},L=e=>o.settings.getAttribute(S)[e];AFRAME.registerComponent(S,{schema:{[u.RESUME_VIDEO]:{type:"boolean",default:!0},[u.DEF_PRESET]:{type:"number",default:0},[u.SAVE_PRESET]:{type:"boolean",default:!0},[u.DEF_EYE]:{type:"string",default:"left"},[u.VIEW_ANG]:{type:"number",default:0},[u.UI_ANG]:{type:"number",default:0}},init:function(){let e=this.el,t=v.get("settings");if(!t)t=this.data,v.set("settings",t);else{for(let s in t)s in this.data||delete t[s];let i={};for(let s in this.data)s in t||(i[s]=this.data[s]);se(i)||v.set("settings",{...t,...i}),e.setAttribute(S,t)}},update:function(e){o.events.emit(F.SETTINGS,this.data,!1),v.set("settings",this.data)}});AFRAME.registerComponent("stereocam",{schema:{eye:{type:"string",default:"left"}},init:function(){this.onEyeChange=AFRAME.utils.bind(this.onEyeChange,this),this.eye_changed=!0,o.events.addEventListener(F.SETTINGS,this.onEyeChange)},onEyeChange:function(e){let t=e.detail[u.DEF_EYE];this.el.setAttribute("stereocam",`eye: ${t}`),this.eye_changed=!0},update:function(e){this.eye_changed=!0},tick:function(e){if(this.eye_changed){console.log("stereocam: ",this.data.eye);var t;this.el.object3D.children.forEach(function(i){i.type=="PerspectiveCamera"&&(t=i)}),t?this.data.eye==="left"?(t.layers.enable(1),t.layers.disable(2)):this.data.eye==="right"?(t.layers.enable(2),t.layers.disable(1)):(t.layers.enable(1),t.layers.enable(2)):console.error("stereocam: Camera not found"),this.eye_changed=!1}},remove:function(e){o.events.removeEventListener(F.SETTINGS,this.onEyeChange)}});AFRAME.registerComponent("timeline",{schema:{videoId:{type:"string",default:"video"}},init:function(){var e=this.el;this.video=document.getElementById(this.data.videoId);const{width:t,height:i}=e.getAttribute("geometry");this.seek=r("a-entity",{geometry:`primitive: box; width: ${t*.01}; height: ${i}; depth: 0.5;`,material:"color: #006cd8",position:`${-t/2} 0 0`},[],e),this.hoverEl=r("a-entity",{geometry:`primitive: box; width: ${t*.01}; height: ${i+1}; depth: 0.5; `,visible:!1,material:"color: #00FF00"},[],e),this.hoverTextEl=r("a-text",{position:"0 5 0",align:"center",value:"00:00:00",width:"40"},[r("a-entity",{geometry:"primitive: plane; width: 8; height: 2.5;",position:"0 0 -0.5",material:"color: #808080"})],this.hoverEl),this.bg=r("a-entity",{geometry:`primitive: plane; width: ${t+1.5}; height: ${i+1} `,material:"color: #006cd8",position:"0 0 -0.5"},[],e),this.videoText=r("a-entity",{position:"0 0 0.5",text:"value: 00:00:00/00:00:00; width: 40; align: center;",material:"color: #333; opacity: 0.5;"},[r("a-plane",{geometry:"primitive: plane; width: 15; height: 2.5;",position:"0 0 -0.1",material:"color: black; opacity: 0.5"})],e),this.updateElems=()=>{var s=this.video.currentTime/this.video.duration*t-t/2;this.seek.setAttribute("position",{x:s}),this.videoText.setAttribute("text",{value:`${$(this.video.currentTime)} /${$(this.video.duration)}`})},this.video.addEventListener("loadedmetadata",()=>{this.seek.setAttribute("position",{x:-t/2}),this.videoText.setAttribute("text",{value:`${$(this.video.currentTime)}/${$(this.video.duration)}`})}),this.video.addEventListener("timeupdate",this.updateElems),e.addEventListener("click",s=>{let n=this.video;if(n.readyState===0){console.log("no info available for video");return}var l=s.detail.intersection.uv.x;n.currentTime=(l*n.duration).toFixed(2)}),e.addEventListener("raycaster-intersected",s=>{this.raycaster=s.detail.el,this.hoverEl.setAttribute("visible",!0)}),e.addEventListener("raycaster-intersected-cleared",s=>{this.raycaster=null,this.hoverEl.setAttribute("visible",!1)})},tick:function(){var a,d,f;if(!this.raycaster)return;let e=this.raycaster.components.raycaster.getIntersection(this.el);if(!e||e.point.x===((a=this.previousIntersection)==null?void 0:a.x)&&e.point.y===((d=this.previousIntersection)==null?void 0:d.y)&&e.point.z===((f=this.previousIntersection)==null?void 0:f.z))return;let t=e.uv.x,i=timeline.getAttribute("geometry").width,s=t*i-i/2,n=Math.floor(t*video.duration),{y:l,z:h}=this.hoverEl.getAttribute("position");this.hoverEl.setAttribute("position",`${s} ${l} ${h}`),this.hoverTextEl.setAttribute("value",$(n)),this.previousIntersection=e.point},remove:function(){var e=this.el;e.removeAttribute("controls"),e.removeChild(this.seek),e.removeChild(this.hoverEl),e.removeChild(this.bg),e.removeChild(this.videoText)}});AFRAME.registerComponent("button-highlight",{init:function(){this.color=this.el.getAttribute("material").color,this.el.addEventListener("raycaster-intersected",e=>{this.el.setAttribute("material",{color:ee(this.color,40)})}),this.el.addEventListener("raycaster-intersected-cleared",e=>{this.el.setAttribute("material",{color:this.color})})}});AFRAME.registerComponent("recenter",{schema:{},init:function(){var e=this.el;this.camera=document.getElementById("camera"),this.recenterCamera=!1,this.controlsVisible=!0,e.sceneEl.addEventListener("enter-vr",()=>{this.recenterCamera=!0}),e.sceneEl.addEventListener("exit-vr",()=>{this.recenterCamera=!1}),o.events.addEventListener(T,t=>{t.detail===B?this.controlsVisible=!1:t.detail===U&&(this.controlsVisible=!0)}),e.addEventListener("click",t=>{if(t.detail.intersectedEl===e){if(!this.controlsVisible){e.sceneEl.systems.controls.showControls();return}this.recenterCamera&&e.setAttribute("rotation",{y:-this.camera.getAttribute("rotation").y})}})}});AFRAME.registerComponent("cursor-util",{schema:{},init:function(){let e=this.el;this.checkVR=AFRAME.utils.bind(this.checkVR,this),e.sceneEl.addEventListener("enter-vr",this.checkVR),e.sceneEl.addEventListener("exit-vr",this.checkVR),this.cursorChild=r("a-entity",{geometry:"primitive: circle; radius: 0.2;",material:"color: aquamarine; shader: flat"}),this.checkVR()},checkVR:function(){let e=this.el;AFRAME.utils.device.checkVRSupport()?(c(e,{geometry:"primitive: ring; radiusInner: 0.2; radiusOuter: 0.4",material:"color: black; shader: flat"}),e.appendChild(this.cursorChild)):(e.setAttribute("cursor","rayOrigin: mouse"),e.replaceChildren())}});AFRAME.registerComponent("adjust-camera",{init:function(){let e=this.el;e.sceneEl.addEventListener("enter-vr",function(){e.setAttribute("position",{y:-1.6})}),e.sceneEl.addEventListener("exit-vr",function(){e.setAttribute("position",{y:0})})}});const E={EQ:"equirectangular",FE:"fisheye",FLAT:"flat"},b={EQ_180_SBS:"EQ_180_SBS",FE_180_SBS:"FE_180_SBS",FE_190_SBS:"FE_190_SBS",FE_200_SBS:"FE_200_SBS",FLAT_2D:"FLAT_2D",FLAT_3D:"FLAT_3D"},M=[{text:"180 SBS EQR",fn:()=>{c(o.env,{"env-manager":`preset: ${b.EQ_180_SBS}`})}},{text:"FLAT 2D",fn:()=>{c(o.env,{"env-manager":`preset: ${b.FLAT_2D}`})}},{text:"180 SBS FISH",fn:()=>{c(o.env,{"env-manager":`preset: ${b.FE_180_SBS}`})}},{text:"190 SBS FISH",fn:()=>{c(o.env,{"env-manager":`preset: ${b.FE_190_SBS}`})}},{text:"200 SBS FISH",fn:()=>{c(o.env,{"env-manager":`preset: ${b.FE_200_SBS}`})}}];function D(e){e==null&&(e="");for(let t in E)if(e.startsWith(t))return E[t]}AFRAME.registerComponent("env-manager",{schema:{preset:{type:"string",default:b.EQ_180_SBS},uiHidden:{type:"boolean",default:!1},defaultEye:{type:"string",default:"left"}},init:function(){this.data,this.onEyeChange=AFRAME.utils.bind(this.onEyeChange,this),this.onUIHide=AFRAME.utils.bind(this.onUIHide,this),o.events.addEventListener(T,this.onUIHide),o.events.addEventListener(F.SETTINGS,this.onEyeChange)},onEyeChange:function(e){let t=e.detail[u.DEF_EYE];this.el.setAttribute("env-manager",`defaultEye: ${t}`)},update:function(e){let t=this.data,i=this.el;switch(D(e.preset)!==D(t.preset)&&i.removeAttribute(D(e.preset)),t.preset){case b.EQ_180_SBS:i.setAttribute(E.EQ,{uiHidden:t.uiHidden,defaultEye:t.defaultEye});break;case b.FE_180_SBS:i.setAttribute(E.FE,{uiHidden:t.uiHidden,defaultEye:t.defaultEye});break;case b.FE_190_SBS:i.setAttribute(E.FE,{uiHidden:t.uiHidden,defaultEye:t.defaultEye,fov:190});break;case b.FE_200_SBS:i.setAttribute(E.FE,{uiHidden:t.uiHidden,defaultEye:t.defaultEye,fov:200});break;case b.FLAT_2D:i.setAttribute(E.FLAT,"");break;default:console.error("preset not found")}Object.keys(ie(t,e)).every(n=>["uiHidden","defaultEye"].includes(n))||o.events.emit(F.ENVIRONMENT,t)},onUIHide:function(e){e.detail===B?this.el.setAttribute("env-manager","uiHidden: true"):e.detail===U&&this.el.setAttribute("env-manager","uiHidden: false")},remove:function(){o.events.removeEventListener(T,this.onUIHide),o.events.removeEventListener(F.SETTINGS,this.onEyeChange)}});const V=[90,60,45,30,0,-30,-45,-60,-90],O=[60,45,30,15,0,-15,-30,-45,-60];function w(e){e.removeAttribute("button-highlight"),e.removeAttribute("clickable"),e.setAttribute("visible",!1)}function _(e){e.setAttribute("button-highlight",""),e.setAttribute("clickable",""),e.setAttribute("visible",!0)}AFRAME.registerComponent("toggle-adjust-ui",{init:function(){this.viewAngleIdx=v.get("viewAngleIdx")??4,this.uiAngleIdx=v.get("uiAngleIdx")??4,this.viewUp=r("a-entity",{position:"0 4 0",geometry:"primitive: triangle; vertexA: 0 0.5 0; vertexB: -2 -1.5 0; vertexC: 2 -1.5 0;",material:"side: double; color: #808080; opacity: 1;",clickable:"","button-highlight":""},[r("a-entity",{position:"0 0 -0.25",geometry:"primitive: triangle; vertexA: 0 1 0; vertexB: -2.5 -1.5 0; vertexC: 2.5 -1.5 0;",material:"side: double; color: #006cd8; opacity: 1;","button-highlight":""})]),this.viewDown=r("a-entity",{position:"0 -4 0",geometry:"primitive: triangle; vertexA: 2 1.5 0; vertexB: 0 -0.5 0; vertexC: -2 1.5 0;",material:"side: double; color: #808080; opacity: 1;",clickable:"","button-highlight":""},[r("a-entity",{position:"0 0 -0.25",geometry:"primitive: triangle; vertexA: 2.5 1.5 0; vertexB: 0 -1 0; vertexC: -2.5 1.5 0;",material:"side: double; color: #006cd8; opacity: 1;","button-highlight":""})]),this.viewAngle=r("a-entity",{position:"-34 1.5 -59",material:"color: #808080; opacity: 1",rotation:"0 20 0",geometry:"primitive:plane; width:4.5; height: 4.5"},[r("a-text",{align:"center",value:`view +0`,width:"40",position:"0 0 0.2"}),r("a-entity",{position:"0 0 -0.2",material:"color: #006cd8; opacity: 1",geometry:"primitive:plane; width:5; height: 5"}),this.viewUp,this.viewDown],this.el),this.uiUp=r("a-entity",{position:"0 4 0",geometry:"primitive: triangle; vertexA: 0 0.5 0; vertexB: -2 -1.5 0; vertexC: 2 -1.5 0;",material:"side: double; color: #808080; opacity: 1;",clickable:"","button-highlight":""},[r("a-entity",{position:"0 0 -0.25",geometry:"primitive: triangle; vertexA: 0 1 0; vertexB: -2.5 -1.5 0; vertexC: 2.5 -1.5 0;",material:"side: double; color: #006cd8; opacity: 1;","button-highlight":""})]),this.uiDown=r("a-entity",{position:"0 -4 0",geometry:"primitive: triangle; vertexA: 2 1.5 0; vertexB: 0 -0.5 0; vertexC: -2 1.5 0;",material:"side: double; color: #808080; opacity: 1;",clickable:"","button-highlight":""},[r("a-entity",{position:"0 0 -0.25",geometry:"primitive: triangle; vertexA: 2.5 1.5 0; vertexB: 0 -1 0; vertexC: -2.5 1.5 0;",material:"side: double; color: #006cd8; opacity: 1;","button-highlight":""})]),this.uiAngle=r("a-entity",{position:"34 1.5 -59",rotation:"0 -20 0",material:"color: #808080; opacity: 1",geometry:"primitive:plane; width:4.5; height: 4.5"},[r("a-text",{align:"center",value:`ui +0`,width:"40",position:"0 0 0.2"}),r("a-entity",{position:"0 0 -0.2",material:"color: #006cd8; opacity: 1",geometry:"primitive:plane; width:5; height: 5"}),this.uiUp,this.uiDown],this.el),this.uiUp.addEventListener("click",()=>{this.uiAngleIdx-=1,this.update()}),this.uiDown.addEventListener("click",()=>{this.uiAngleIdx+=1,this.update()}),this.viewUp.addEventListener("click",()=>{this.viewAngleIdx-=1,this.update()}),this.viewDown.addEventListener("click",()=>{this.viewAngleIdx+=1,this.update()}),this.onEnvChange=AFRAME.utils.bind(this.onEnvChange,this),o.events.addEventListener(F.ENVIRONMENT,this.onEnvChange)},update:function(){this.uiAngleIdx===0?w(this.uiUp):_(this.uiUp),this.uiAngleIdx===O.length-1?w(this.uiDown):_(this.uiDown),this.viewAngleIdx===0?w(this.viewUp):_(this.viewUp),this.viewAngleIdx===V.length-1?w(this.viewDown):_(this.viewDown),this.curEnv===E.FLAT?(w(this.uiDown),w(this.uiUp),this.uiAngle.setAttribute("visible",!1)):this.uiAngle.setAttribute("visible",!0),o.cameraRig.setAttribute("rotation",`${-1*V[this.viewAngleIdx]} 0 0`),c(this.viewAngle.children[0],{value:`view +${V[this.viewAngleIdx]}`}),v.set("viewAngleIdx",this.viewAngleIdx),o.controls.setAttribute("rotation",`${O[this.uiAngleIdx]} 0 0`),c(this.uiAngle.children[0],{value:`ui +${O[this.uiAngleIdx]}`}),this.curEnv!==E.FLAT&&v.set("uiAngleIdx",this.uiAngleIdx)},onEnvChange:function(e){this.curEnv=D(e.detail.preset),this.update()},remove:function(){this.el.removeChild(this.viewAngle),this.el.removeChild(this.uiAngle)}});class le{constructor(){G(this,"seperator",",")}timestampToSeconds(t){const[i,s]=t.split(","),n=parseInt(s),[l,h,a]=i.split(":").map(f=>parseInt(f)),d=n*.001+a+60*h+3600*l;return Math.round(d*1e3)/1e3}correctFormat(t){let i=t.replace(".",",");var s=null,n=null,l=null,h=null,[a,d]=i.split(",");h=this.fixed_str_digit(3,d);var[f,k,x]=a.split(":");return s=this.fixed_str_digit(2,f,!1),n=this.fixed_str_digit(2,k,!1),l=this.fixed_str_digit(2,x,!1),`${s}:${n}:${l},${h}`}fixed_str_digit(t,i,s=!0){if(i.length==t)return i;if(i.length>t)return i.slice(0,t);if(i.length (\d{1,2}:\d{2}:\d{2},\d{1,3})/g;let s=t.split(i);return s.shift(),s}tryDot(t){t=t.replace(/\r/g,"");var i=/(\d+)\n(\d{1,2}:\d{2}:\d{2}\.\d{1,3}) --> (\d{1,2}:\d{2}:\d{2}\.\d{1,3})/g;let s=t.split(i);return s.shift(),this.seperator=".",s}fromSrt(t){var i=t,s=this.tryComma(i);s.length==0&&(s=this.tryDot(i));for(var n=[],l=0;l "+l.endTime+s,i+=l.text.replace(` +`,s)+s+s}return i}}const N=4;AFRAME.registerComponent("subtitles",{schema:{src:{type:"string",default:""},on:{type:"boolean",default:!1}},init:function(){this.parser=new le,this.updateSubtitle=AFRAME.utils.bind(this.updateSubtitle,this),this.subsOnHandler=AFRAME.utils.bind(this.subsOnHandler,this),this.getAndPopulateSubs=AFRAME.utils.bind(this.getAndPopulateSubs,this),this.onlySubsHandlers=AFRAME.utils.bind(this.onlySubsHandlers,this),this.onEyeChange=AFRAME.utils.bind(this.onEyeChange,this),this.bg=this.el.children[0],c(this.bg,{geometry:"primitive: plane",material:"color: black; opacity: 0.5;"}),this.onlySubsON=!1,this.onlySubsBtn=r("a-entity",{geometry:"primitive: plane; width: 10; height: 3",material:"color: #808080",position:"21 -12 -60",clickable:"",controls:""},[r("a-text",{value:"SUBS SEEK",width:"40",align:"center",position:"0 0 0.5"})]),this.subsOn=r("a-entity",{geometry:"primitive: plane; width: 10; height: 3",material:"color: #808080",position:"21 -18 -60",clickable:"",controls:"","button-highlight":""},[r("a-text",{value:this.data.on?"ON":"OFF",width:"40",align:"center",position:"0 0 0.5"})]),this.subsOn.addEventListener("click",this.subsOnHandler),this.onlySubsBtn.addEventListener("click",this.onlySubsHandlers),o.controls.append(this.onlySubsBtn,this.subsOn),o.video.addEventListener("timeupdate",this.updateSubtitle),o.events.addEventListener(F.SETTINGS,this.onEyeChange),this.subtitles=[]},update:function(e){this.subsOn.children[0].setAttribute("value",this.data.on?"ON":"OFF"),this.data.src!==e.src&&(this.getAndPopulateSubs(this.data.src),this.onEyeChange({detail:{[u.DEF_EYE]:L(u.DEF_EYE)}}))},subsOnHandler:function(){let e=!this.data.on;this.el.setAttribute("subtitles",{on:e}),e?(this.el.object3D.visible=!0,o.video.addEventListener("timeupdate",this.updateSubtitle)):(this.el.object3D.visible=!1,o.video.removeEventListener("timeupdate",this.updateSubtitle))},onEyeChange:function(e){let t=e.detail[u.DEF_EYE];this.el.setAttribute("stereo",`eye:${t}`)},getAndPopulateSubs:async function(e){this.subtitles=[];const i=await(await fetch(e)).text();this.subtitles=this.parser.fromSrt(i)},onlySubsHandlers:function(){this.onlySubsON=!this.onlySubsON,this.onlySubsON?c(this.onlySubsBtn,{material:"color: #00008b"}):c(this.onlySubsBtn,{material:"color: #808080"})},updateSubtitle:function(){if(o.video.seeking)return;const e=o.video.currentTime,t=this.subtitles.find(i=>e>=i.startSeconds&&e<=i.endSeconds);if(t){this.el.object3D.visible=!0,this.bg.object3D.visible=!0;let i=t.text.split(/\r?\n/),s=i.length,n=i[0].length;if(i.length>1)for(let l in i)n=Math.max(n,i[l].length);this.latestSub=t,this.el.setAttribute("value",t.text),this.bg.setAttribute("geometry",{height:.25*s,width:.1*(n+2)})}else this.el.object3D.visible=!1,this.bg.object3D.visible=!0;if(this.onlySubsON){let i=this.subtitles.find(s=>e<=s.startSeconds);(!this.latestSub||e-this.latestSub.endSeconds>N)&&i.startSeconds-e>=N&&(o.video.currentTime=i.startSeconds-N)}},remove:function(){o.controls.removeChild(this.onlySubsBtn),o.controls.removeChild(this.subsOn),o.video.removeEventListener("timeupdate",this.updateSubtitle),this.bg.object3D.visible=!1}});AFRAME.registerComponent("marq-text",{schema:{value:{type:"string",default:""},limit:{type:"number",default:30}},init:function(){this.timerId=null,this.st=0,this.marquee=AFRAME.utils.bind(this.marquee,this),this.txt=r("a-text",{align:"center",width:"35",position:"0 0 1"}),this.el.appendChild(this.txt),this.data.value.length>this.data.limit&&(this.el.addEventListener("raycaster-intersected",e=>{this.timerId=setInterval(this.marquee,200)}),this.el.addEventListener("raycaster-intersected-cleared",e=>{this.update()}))},update:function(){this.st=0,this.txt.setAttribute("value",this.data.value.substring(this.st,this.st+this.data.limit)),clearInterval(this.timerId)},remove:function(){clearInterval(this.timerId)},marquee:function(){this.st=(this.st+1)%this.data.value.length,this.data.value.length-this.st<20&&(this.st=0),this.txt.setAttribute("value",this.data.value.substring(this.st,this.st+this.data.limit))}});const R="video-state";AFRAME.registerComponent(R,{schema:{presetId:{type:"number",default:0},src:{type:"string",default:"static/sample.mp4"},fileName:{type:"string",default:"sample.mp4"},resumeVideo:{type:"boolean",default:!1}},init:function(){this.onVideoLoad=AFRAME.utils.bind(this.onVideoLoad,this),this.saveVidTime=AFRAME.utils.bind(this.saveVidTime,this),this.setupKeys=AFRAME.utils.bind(this.setupKeys,this),this.video=document.querySelector("#video"),this.toggleModeBtn=r("a-entity",{position:"0 -12 -60",clickable:"",controls:"",material:"color: #808080; opacity: 1",geometry:"primitive:plane; width:15; height: 3","button-highlight":""},[],o.controls),this.toggleModeBtnTxt=r("a-text",{value:M[this.data.presetId].text,width:40,align:"center",position:"0 0 0.5"},[],this.toggleModeBtn),this.toggleBtnHandler=AFRAME.utils.bind(this.toggleBtnHandler,this),this.toggleModeBtn.addEventListener("click",this.toggleBtnHandler),this.setupKeys(this.data.src),this.lastUpdate=Date.now(),this.video.readyState>=1&&this.onVideoLoad,this.video.addEventListener("loadedmetadata",this.onVideoLoad)},update:function(e){var t=this.data;e.src&&e.src!==t.src&&(this.setupKeys(t.src),this.video.src=t.src,this.video.play()),L(u.RESUME_VIDEO)?this.video.addEventListener("timeupdate",this.saveVidTime):this.video.removeEventListener("timeupdate",this.saveVidTime),M[t.presetId].fn(),this.toggleModeBtnTxt.setAttribute("value",M[t.presetId].text)},onVideoLoad:function(){if(this.lastUpdate=Date.now(),L(u.RESUME_VIDEO)){let e=v.get(this.timeKey);e&&(this.video.currentTime=e)}if(L(u.SAVE_PRESET)){let e=v.get(this.presetKey);e!=null&&c(this.el,{[R]:{presetId:e}})}},toggleBtnHandler:function(){if(this.video.readyState>=1){let e=(this.data.presetId+1)%M.length;c(this.el,{[R]:{presetId:e}}),L(u.SAVE_PRESET)&&v.set(this.presetKey,e)}},saveVidTime:function(){let e=Date.now();e-this.lastUpdate>5e3&&(this.lastUpdate=e,v.set(this.timeKey,this.video.currentTime))},setupKeys:function(e){this.fileName=H(e),this.presetKey=`VID_P_${this.fileName}`,this.timeKey=`VID_T_${this.fileName}`},remove:function(){o.controls.removeChild(this.toggleModeBtn),this.video.removeEventListener("timeupdate",this.saveVidTime),this.video.removeEventListener("loadedmetadata",this.onVideoLoad)}});AFRAME.registerComponent("dialog-utils",{schema:{screen:{type:"string",default:""}},init:function(){let e=this.el;o.events.addEventListener(T,t=>{if(t.detail!==B)return!1;e.object3D.visible=!1,e.removeAttribute("clickable"),e.replaceChildren()})}});const g=60,m=30,K=["3g2","3gp","aaf","asf","avchd","avi","drc","flv","m2v","m3u8","m4p","m4v","mkv","mng","mov","mp2","mp4","mpe","mpeg","mpg","mpv","mxf","nsv","ogg","ogv","qt","rm","rmvb","roq","svi","vob","webm","wmv","yuv"];function re(e){for(let t in K)if(e.endsWith(K[t]))return!0;return!1}const oe="https://192.168.1.50:5000/list",W="https://192.168.1.50:5000/file",C="dialog-files",y=5,Y=-m*.125,Q=m*.15;AFRAME.registerComponent(C,{schema:{url:{type:"string",default:""},reRender:{type:"string",default:""}},init:function(){let e=this.el;e.setAttribute("geometry",`primitive: plane; width: ${g}; height: ${m}`),e.setAttribute("material","color: teal"),e.setAttribute("dialog-utils",{screen:C}),e.object3D.visible=!0,this.offset={},this.fetchFiles=AFRAME.utils.bind(this.fetchFiles,this),this.insertFolderUI=AFRAME.utils.bind(this.insertFolderUI,this),this.renderFiles=AFRAME.utils.bind(this.renderFiles,this)},update:function(e){var t=this.data,i=this.el;if(t.reRender&&t.reRender.length>0){i.setAttribute("dialog-utils",{screen:C}),i.setAttribute(C,{reRender:""});return}t.url!==e.url?this.fetchFiles(this.el,t.url):this.renderFiles()},fetchFiles:async function(e,t){e.setAttribute("dialog-loading","");let i=await fetch(oe+"/"+t),{files:s,folders:n}=await i.json();this.files=s.filter(l=>re(l)),this.allFiles=s,this.folders=n,e.removeAttribute("dialog-loading"),this.renderFiles()},renderFiles:function(){var l,h;const e=this.el,t=this.data.url;e.replaceChildren(),e.setAttribute("clickable",""),e.object3D.visible=!0;let i=((l=this.offset[t])==null?void 0:l.files)??0,s=((h=this.offset[t])==null?void 0:h.folders)??0,n=Q;for(let a=i;a{let f=W+t+"/"+this.files[a];o.videoState.setAttribute(R,{src:f,fileName:this.files[a]});let k=this.files[a].substr(0,this.files[a].lastIndexOf("."))+".srt",x=this.allFiles.find(j=>j===k);x?o.subtitles.setAttribute("subtitles",`src: ${W+t+"/"+x}`):o.subtitles.removeAttribute("subtitles")},n+=Y}n=Q;for(let a=s;a{e.setAttribute(C,{url:t+"/"+this.folders[a]}),console.log("going : ",t+"/"+this.folders[a])},n+=Y}this.insertFolderUI()},insertFolderUI:function(){var a,d;const e=this.el,t=this.data.url;let i=((a=this.offset[t])==null?void 0:a.files)??0,s=((d=this.offset[t])==null?void 0:d.folders)??0,n=e.getAttribute("geometry");r("a-plane",{geometry:`primitive:plane; width:${n.width}; height: 3`,position:`0 ${n.height/2} 0.2`,material:"color: #808080"},[r("a-entity",{text:`value: folder:/${t}; align: center; width: 30;`,position:"0 0 0.2"})],e),r("a-image",{src:"#asset-movie-icon",position:`-${n.width/2} 0 0.1`,"background-color":"blue",scale:"4 4 1"},[],e),r("a-image",{src:"#asset-folder",position:`${n.width/2} 0 0.1`,"background-color":"blue",scale:"4 4 1"},[],e),r("a-image",{src:"#asset-refresh",scale:"4 4 1",position:`-${n.width*.1} ${n.height*.35} 0.3`,clickable:"","button-highlight":""},[],e).addEventListener("click",()=>{this.fetchFiles(e,t)}),r("a-image",{src:"#asset-back",scale:"4 4 1",position:`${n.width*.1} ${n.height*.35} 0.3`,clickable:"","button-highlight":""},[],e).addEventListener("click",()=>{e.setAttribute(C,{url:t.substr(0,t.lastIndexOf("/"))})}),this.files.length>y&&(i!=0&&r("a-image",{src:"#asset-up",scale:"3 3 1",position:`-${n.width*.25} ${n.height*.3} 0.2`,clickable:"","button-highlight":""},[],e).addEventListener("click",()=>{this.offset={...this.offset,[t]:{files:i-y,folders:s}},this.renderFiles()}),i+y{this.offset={...this.offset,[t]:{files:i+y,folders:s}},this.renderFiles()})),this.folders.length>y&&(s!=0&&r("a-image",{src:"#asset-up",scale:"3 3 1",position:`${n.width*.25} ${n.height*.3} 0.2`,clickable:"","button-highlight":""},[],e).addEventListener("click",()=>{this.offset={...this.offset,[t]:{files:i,folders:s-y}},this.renderFiles()}),s+y{this.offset={...this.offset,[t]:{files:i,folders:s+y}},this.renderFiles()}))},remove:function(){let e=this.el;e.replaceChildren(),e.removeAttribute("clickable"),e.setAttribute("dialog-utils",{screen:""})}});const A="dialog-settings",P=5,ae=-m*.125,he=m*.15;document.querySelector("a-scene");function de(e,t,i){var s=["left","right"],n=s.indexOf(i);let l=r("a-plane",{geometry:`width: ${g*.4}; height: ${m*.1}`,material:"color: #A15807;",position:`${g*.25} ${t} 0.2`,clickable:"","button-highlight":""},[r("a-entity",{text:`value: ${i}; align: center; width: 35;`,position:"0 0 0.2"})]),h=l.children[0];l.onclick=()=>{n=(n+1)%s.length,h.setAttribute("text",`value: ${s[n]}`),o.settings.setAttribute(S,{defaultEye:s[n]})},e.appendChild(l)}function ce(e,t,i){var s=[!1,!0],n=s.indexOf(i);let l=r("a-plane",{geometry:`width: ${g*.4}; height: ${m*.1}`,material:"color: #A15807;",position:`${g*.25} ${t} 0.2`,clickable:"","button-highlight":""},[r("a-entity",{text:`value: ${i?"ON":"OFF"}; align: center; width: 35;`,position:"0 0 0.2"})]),h=l.children[0];l.onclick=()=>{let a=s[++n%s.length];h.setAttribute("text",`value: ${a?"ON":"OFF"}`),o.settings.setAttribute(S,{savePreset:a})},e.appendChild(l)}function ue(e,t,i){var s=[!1,!0],n=s.indexOf(i);let l=r("a-plane",{geometry:`width: ${g*.4}; height: ${m*.1}`,material:"color: #A15807;",position:`${g*.25} ${t} 0.2`,clickable:"","button-highlight":""},[r("a-entity",{text:`value: ${i?"ON":"OFF"}; align: center; width: 35;`,position:"0 0 0.2"})]),h=l.children[0];l.addEventListener("click",()=>{let a=s[++n%s.length];h.setAttribute("text",`value: ${a?"ON":"OFF"}`),o.settings.setAttribute(S,{resumeVideo:a})}),e.appendChild(l)}const I=[{name:"save preset per video",render:ce,storeKey:u.SAVE_PRESET},{name:"resume video",render:ue,storeKey:u.RESUME_VIDEO},{name:"default eye",render:de,storeKey:u.DEF_EYE}];function ge(e,t){let i=e.getAttribute("geometry");if(e.appendChild(r("a-entity",{geometry:`primitive:plane; width:${i.width}; height: 3`,position:`0 ${i.height/2} 0.2`,material:"color: grey"},[r("a-entity",{text:"value: Settings; align: center; width: 30;",position:"0 0 0.2"})])),I.length>P){if(t!=0){let s=r("a-image",{src:"#asset-up",scale:"3 3 1",position:`0 ${i.height*.3} 0.2`,clickable:"","button-highlight":""});s.addEventListener("click",()=>{e.setAttribute(S,{offset:t-1})}),e.appendChild(s)}if(t+P{e.setAttribute(S,{offset:t+1})}),e.appendChild(s)}}}function fe(e,t){e.replaceChildren(),e.setAttribute("clickable",""),e.object3D.visible=!0,ge(e,t);let i=te(o.settings,S),s=he;for(let n=t;n0){i.setAttribute("dialog-utils",{screen:A}),i.setAttribute(A,{reRender:""});return}fe(i,t.offset)},remove:function(){let e=this.el;e.replaceChildren(),e.removeAttribute("clickable"),e.setAttribute("dialog-utils",{screen:""})}});AFRAME.registerComponent("dialog-loading",{schema:{},init:function(){let e=this.el,t=this.loader=r("a-entity",{geometry:`primitive: plane; width: ${g}; height: ${m}`,material:"color: teal; opacity: 0.2",position:"0 0 3",clickable:""});e.appendChild(t);let i=r("a-image",{src:"#asset-loading",position:"0 0 1",scale:"4 4 1"}),s=r("a-text",{value:"loading",width:2,align:"center",position:"0 -0.5 0.1"});t.append(i,s)},remove:function(){this.el.contains(this.loader)&&this.el.removeChild(this.loader)}});AFRAME.registerComponent("eq-sphere",{schema:{eye:{type:"string",default:"left"},fov:{type:"number",default:180},side:{type:"string",default:"left"}},init:function(){let e=this.el.object3D.children[0],t=this.data,i=this.el.getAttribute("geometry"),s=new THREE.SphereGeometry(i.radius||100,i.segmentsWidth||32,i.segmentsHeight||32,Math.PI,Math.PI,0,Math.PI),n={repeat:{x:-.5,y:1},offset:{x:.5,y:0}};t.side==="right"&&(n.offset.x+=.5);let l=s.attributes.uv;for(let h=0;h{o.file.click()});return}}});AFRAME.registerComponent("btn-pause-play",{init:function(){let e=this.el;this.video=document.getElementById("video"),this.pausePlay=()=>{this.video.paused?this.video.play():this.video.pause()},this.onPause=()=>e.setAttribute("src","#asset-vp-play"),this.onPlay=()=>e.setAttribute("src","#asset-vp-pause"),e.addEventListener("click",this.pausePlay),this.video.addEventListener("playing",this.onPlay),this.video.addEventListener("pause",this.onPause)},remove:function(){el.removeEventListener("click",this.pausePlay),this.video.removeEventListener("playing",this.onPlay),this.video.removeEventListener("pause",this.onPause)}});AFRAME.registerComponent("btn-seek-back",{init:function(){let e=this.el;this.video=document.getElementById("video"),e.addEventListener("click",()=>{this.video.currentTime-=15})}});AFRAME.registerComponent("btn-seek-forw",{init:function(){let e=this.el;this.video=document.getElementById("video"),e.addEventListener("click",()=>{this.video.currentTime+=15})}});AFRAME.registerComponent("btn-vol",{schema:{vol:{type:"number",default:1}},init:function(){let e=this.el;this.setVolume=AFRAME.utils.bind(this.setVolume,this);let t=this.width=10;c(e,{geometry:{primitive:"plane",width:t+1,height:5},material:"color: #808080"});let i=this.txt=r("a-text",{width:40,align:"center",value:"100",position:"0 0 0.3"});e.appendChild(i);let s=this.bar=r("a-entity",{material:"color: #005073",geometry:"primitive: plane;width: width;height: 4;"});e.appendChild(s),e.addEventListener("click",n=>{this.setVolume(n.detail.intersection.uv.x)}),this.setVolume(v.get("volume")??1)},setVolume:function(e){e>=.9&&(e=1),e<=.1&&(e=.1);let t=this.width*e,i=t/2;o.video.volume=e,v.set("volume",e),this.txt.setAttribute("value",`${Math.round(o.video.volume*100)}`),this.bar.setAttribute("position",`${i-this.width/2} 0 0.2`),this.bar.setAttribute("geometry",{width:t})}});AFRAME.registerComponent("btn-hide-controls",{init:function(){let e=this.el;e.addEventListener("click",()=>{e.sceneEl.systems.controls.hideControls()})}});AFRAME.registerComponent("btn-settings",{schema:{},init:function(){this.el.addEventListener("click",()=>{o.dialog.hasAttribute(A)?o.dialog.object3D.visible?o.dialog.getAttribute("dialog-utils").screen===A?(o.dialog.removeAttribute("clickable"),o.dialog.replaceChildren(),o.dialog.object3D.visible=!1):o.dialog.setAttribute(A,{reRender:"rerender"}):o.dialog.setAttribute(A,{reRender:"rerender"}):(o.dialog.setAttribute(A,""),o.dialog.object3D.visible=!0)})}});const o={ascene:document.querySelector("a-scene"),video:document.getElementById("video"),env:document.getElementById("env"),file:document.getElementById("fileInput"),cameraRig:document.getElementById("cameraRig"),controls:document.getElementById("controls"),events:document.getElementById("events"),settings:document.getElementById("settings"),videoState:document.getElementById("video-state"),dialog:document.getElementById("dialog"),subtitles:document.getElementById("subtitles")};