spline-vue
Version:
Vue2/Vue3 component for Spline scenes.
2 lines (1 loc) • 1.71 kB
JavaScript
(function(n,u){typeof exports=="object"&&typeof module<"u"?module.exports=u(require("vue-demi"),require("@splinetool/runtime"),require("vue")):typeof define=="function"&&define.amd?define(["vue-demi","@splinetool/runtime","vue"],u):(n=typeof globalThis<"u"?globalThis:n||self,n["spline-vue"]=u(n.VueDemi,n.runtime,n.Vue))})(this,function(n,u,l){"use strict";const v=n.defineComponent({name:"Spline",props:{scene:{type:String,required:!0},styles:{type:Object,default:()=>({})},autoRender:{type:Boolean,default:!1},onLoad:Function,onMouseDown:Function,onMouseUp:Function,onMouseHover:Function,onKeyDown:Function,onKeyUp:Function,onStart:Function,onLookAt:Function,onFollow:Function,onWheel:Function},setup(e,r){const t=n.ref(!0),s=c=>t.value=c,i=n.ref();return n.watchPostEffect(c=>{var m;s(!0);let o;const d=[{name:"mouseDown",cb:e.onMouseDown},{name:"mouseUp",cb:e.onMouseUp},{name:"mouseHover",cb:e.onMouseHover},{name:"keyDown",cb:e.onKeyDown},{name:"keyUp",cb:e.onKeyUp},{name:"start",cb:e.onStart},{name:"lookAt",cb:e.onLookAt},{name:"follow",cb:e.onFollow},{name:"scroll",cb:e.onWheel}];i.value&&(o=new u.Application(i.value,{autoRender:(m=e.autoRender)!=null?m:!1}),(async()=>{var y;await o.load(e.scene);for(let f of d)f.cb&&o.addEventListener(f.name,f.cb);s(!1),(y=e.onLoad)==null||y.call(e,o)})()),c==null||c(()=>{for(let a of d)a.cb&&o.removeEventListener(a.name,a.cb);o==null||o.dispose()})}),{isLoading:t,canvasRef:i}}}),b=(e,r)=>{const t=e.__vccOpts||e;for(const[s,i]of r)t[s]=i;return t};function w(e,r,t,s,i,c){return l.openBlock(),l.createElementBlock("canvas",{ref:"canvasRef",style:l.normalizeStyle({display:e.isLoading?"none":"block",...e.styles})},null,4)}return b(v,[["render",w]])});