lunchboxjs 0.1.4016 → 0.2.1001-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("three"),require("lodash")):"function"==typeof define&&define.amd?define(["exports","vue","three","lodash"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).LunchboxRenderer={},e.vue,e.three,e.lodash)}(this,(function(e,t,n,r){"use strict";function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,r.get?r:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var a=o(n);const s=[],i=(e,n)=>{const r=I.value?.instance,o=z.value.instance,a=D.value;if(!r?.domElement||!o||!a)return;const s=(e=e??window.innerWidth)/(n=n??window.innerHeight);if("perspectivecamera"===a.type?.toLowerCase()){const e=a.instance;e.aspect=s,e.updateProjectionMatrix()}else if("orthographiccamera"===a.type?.toLowerCase()){const t=a.instance,r=n/e;t.top=10*r,t.bottom=10*-r,t.right=10,t.left=-10,t.updateProjectionMatrix()}else console.log("TODO: non-ortho or perspective camera");r.setSize(e,n),o&&a.instance&&r.render(t.toRaw(o),t.toRaw(a.instance))},c=e=>({position:e,top:0,right:0,bottom:0,left:0,width:"100%",height:"100%"}),u={name:"Lunchbox",props:{background:String,cameraArgs:Array,cameraLook:Array,cameraLookAt:Array,cameraPosition:Array,dpr:Number,ortho:Boolean,orthographic:Boolean,r3f:Boolean,rendererArguments:Object,rendererProperties:Object,shadow:[Boolean,Object],transparent:Boolean,zoom:Number,updateSource:Object},setup(e,n){const o=t.ref(),s=t.ref(!0),u=t.ref(e.dpr??-1),d=t.ref();let l,p,m;return e.r3f&&a?.ColorManagement&&(a.ColorManagement.legacyMode=!1),t.onMounted((()=>{if(!o.value)throw new Error("missing canvas");if(l=G(["WebGLRenderer"]),l)s.value=!1,W.value=!0;else{const t={alpha:e.transparent,antialias:!0,canvas:o.value.domElement,powerPreference:e.r3f?"high-performance":"default",...e.rendererArguments??{}};I.value=_({type:"WebGLRenderer",uuid:$,props:{args:[t]}}),W.value=!0;const n=I;e.r3f&&n.value.instance&&(n.value.instance.outputEncoding=a.sRGBEncoding,n.value.instance.toneMapping=a.ACESFilmicToneMapping);const s={shadow:e.shadow};n.value.instance&&s?.shadow&&(n.value.instance.shadowMap.enabled=!0,"object"==typeof s.shadow&&(n.value.instance.shadowMap.type=s.shadow.type)),e.rendererProperties&&Object.keys(e.rendererProperties).forEach((t=>{r.set(n.value,t,e.rendererProperties[t])})),l=n.value}if(p=G(["PerspectiveCamera","OrthographicCamera"]),p?F.value=!0:(e.ortho||e.orthographic?D.value=_({props:{args:e.cameraArgs??[]},type:"OrthographicCamera",uuid:k}):D.value=_({props:{args:e.cameraArgs??[e.r3f?75:45,.5625,1,1e3]},type:"PerspectiveCamera",uuid:k}),F.value=!0,p=D.value),!p.instance)throw new Error("Error creating camera.");if(p&&e.cameraPosition&&p.instance.position.set(...e.cameraPosition),p&&(e.cameraLookAt||e.cameraLook)){const t=e.cameraLookAt||e.cameraLook;p.instance.lookAt(...t)}if(p&&void 0!==e.zoom&&(p.instance.zoom=e.zoom),m=z.value,m&&m.instance&&e.background&&(m.instance.background=new a.Color(e.background)),-1===u.value&&(u.value=window.devicePixelRatio),!l?.instance)throw new Error("missing renderer");l.instance.setPixelRatio(u.value),ve.dpr.value=u.value,((e,t,n)=>{const r=e.value?.domElement;if(!r)throw new Error("missing container");i();const o=new ResizeObserver((([e])=>{i()}));r&&o.observe(r),n((()=>{t&&o.unobserve(t)}))})(d,l.instance.domElement,t.onBeforeUnmount);const n=t.getCurrentInstance().appContext.app;for(let e of ne)e({app:n,camera:p.instance,renderer:l.instance,scene:m.instance});ce({app:n,camera:p.instance,renderer:l.instance,scene:m.instance,updateSource:e.updateSource})})),t.onBeforeUnmount((()=>{ue(),de()})),()=>[n.slots.default?.()??null,t.h("div",{style:c("absolute"),ref:d},[s.value?t.h("canvas",{style:c("fixed"),class:"lunchbox-canvas",ref:o}):null])]}},d={},l=["canvas","div","LunchboxWrapper"],p={...["mesh","instancedMesh","scene","sprite","object3D","instancedBufferGeometry","bufferGeometry","boxBufferGeometry","circleBufferGeometry","coneBufferGeometry","cylinderBufferGeometry","dodecahedronBufferGeometry","extrudeBufferGeometry","icosahedronBufferGeometry","latheBufferGeometry","octahedronBufferGeometry","parametricBufferGeometry","planeBufferGeometry","polyhedronBufferGeometry","ringBufferGeometry","shapeBufferGeometry","sphereBufferGeometry","tetrahedronBufferGeometry","textBufferGeometry","torusBufferGeometry","torusKnotBufferGeometry","tubeBufferGeometry","wireframeGeometry","parametricGeometry","tetrahedronGeometry","octahedronGeometry","icosahedronGeometry","dodecahedronGeometry","polyhedronGeometry","tubeGeometry","torusKnotGeometry","torusGeometry","sphereGeometry","ringGeometry","planeGeometry","latheGeometry","shapeGeometry","extrudeGeometry","edgesGeometry","coneGeometry","cylinderGeometry","circleGeometry","boxGeometry","material","shadowMaterial","spriteMaterial","rawShaderMaterial","shaderMaterial","pointsMaterial","meshPhysicalMaterial","meshStandardMaterial","meshPhongMaterial","meshToonMaterial","meshNormalMaterial","meshLambertMaterial","meshDepthMaterial","meshDistanceMaterial","meshBasicMaterial","meshMatcapMaterial","lineDashedMaterial","lineBasicMaterial","light","spotLightShadow","spotLight","pointLight","rectAreaLight","hemisphereLight","directionalLightShadow","directionalLight","ambientLight","lightShadow","ambientLightProbe","hemisphereLightProbe","lightProbe","texture","videoTexture","dataTexture","dataTexture3D","compressedTexture","cubeTexture","canvasTexture","depthTexture","textureLoader","group","catmullRomCurve3","points","cameraHelper","camera","perspectiveCamera","orthographicCamera","cubeCamera","arrayCamera","webGLRenderer"].map((e=>t.defineComponent({inheritAttrs:!1,name:e,setup:(n,r)=>()=>t.h(e,r.attrs,r.slots?.default?.()||[])}))).reduce(((e,t)=>(e[t.name]=t,e)),{}),Lunchbox:u};const m=e=>e?.$el&&e?.$el?.hasOwnProperty?.("instance"),h=e=>{if("domMeta"===e?.metaType)return!0;const t="string"==typeof e?e:e?.type;return l.includes(t??"")},f=e=>"standardMeta"===e?.metaType,y=e=>e.isLunchboxRootNode,v=[],g=t.ref(!1);function b({node:e,key:n,value:r}){var o;if(e.eventListeners[n]||(e.eventListeners[n]=[]),e.eventListenerRemoveFunctions[n]||(e.eventListenerRemoveFunctions[n]=[]),e.eventListeners[n].push(r),x.includes(n)&&(K.value,e.instance&&!v.includes(e)&&(o=e,v.push(o),e.eventListenerRemoveFunctions[n].push((()=>(e=>{const t=v.indexOf(e);-1!==t&&v.splice(t,1)})(e))))),"onClick"===n||"onPointerDown"===n||"onPointerUp"===n){const r=t.watch((()=>g.value),(t=>{const r=P.map((e=>e.element)).findIndex((t=>t.instance&&t.instance.uuid===e.instance?.uuid));-1!==r&&((!t||"onClick"!==n&&"onPointerDown"!==n)&&(t||"onPointerUp"!==n)||e.eventListeners[n].forEach((e=>{e({intersection:P[r].intersection})})))}));e.eventListenerRemoveFunctions[n].push(r)}return e}const x=["onClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove"];let w,R,A;const C=t.ref({x:1/0,y:1/0});let E,L=!1;let P=[];const M=()=>{const e=K.value?.instance,t=D.value?.instance;if(!e||!t)return;e.setFromCamera(ve.mousePos.value,t);const n=e.intersectObjects(v.map((e=>e.instance)));let r=[],o=[],a=[];r=P.map((e=>e.intersection)),n?.forEach((e=>{if(-1===P.findIndex((t=>t.intersection.object===e.object))){const t=v.find((t=>t.instance?.uuid===e.object.uuid));t&&o.push({element:t,intersection:e})}else{const t=v.find((t=>t.instance?.uuid===e.object.uuid));t&&a.push({element:t,intersection:e})}const t=r.findIndex((t=>t.object.uuid===e.object.uuid));-1!==t&&r.splice(t,1)}));const s=r.map((e=>({element:v.find((t=>t.instance?.uuid===e.object.uuid)),intersection:e})));o.forEach((({element:e,intersection:t})=>{B({element:e,eventKeys:["onPointerEnter"],intersection:t})})),a.forEach((({element:e,intersection:t})=>{B({element:e,eventKeys:["onPointerOver","onPointerMove"],intersection:t})})),s.forEach((({element:e,intersection:t})=>{B({element:e,eventKeys:["onPointerLeave","onPointerOut"],intersection:t})})),P=[].concat(o,a)},B=({element:e,eventKeys:t,intersection:n})=>{e&&t.forEach((t=>{e.eventListeners[t]&&e.eventListeners[t].forEach((e=>{e({intersection:n})}))}))};function N(t={}){return e.lunchboxTree||(e.lunchboxTree=new Q.RendererRootNode(t)),e.lunchboxTree}function G(e){Array.isArray(e)||(e=[e]);for(let t of e)if(O[t])return O[t];for(let n of e){const e=T[n]||s.find((e=>e.type?.toLowerCase()===n.toLowerCase()));if(!(t=e,"RendererNode"!==t?.minidomType||!1!==e.props["is-default"]&&!1!=!e.props.isDefault))return null;if(e){const t=e;return T[n]=t,t}}var t;return null}e.lunchboxTree=void 0;const T=t.reactive({}),O=t.reactive({});function j(e,n,r={},o=null){Array.isArray(e)||(e=[e]);for(let t of e)T[t]||(T[t]=null),O[t]||(O[t]=null);return t.computed({get(){const t=G(e);if(t)return t;const a=N(),s=_({type:e[0],uuid:n,props:r});return a.addChild(s),T[e[0]]=s,o&&o(s),s},set(e){const t=e.type??"",n=t[0].toUpperCase()+t.slice(1);O[n]=e}})}const k="FALLBACK_CAMERA",S=j(["PerspectiveCamera","OrthographicCamera"],k,{args:[45,.5625,1,1e3]}),F=t.ref(!1),D=t.computed({get:()=>F.value?S.value:null,set(e){const t=e.type??"",n=t[0].toUpperCase()+t.slice(1);O[n]=e}}),$="FALLBACK_RENDERER",U=j(["WebGLRenderer"],$,{}),W=t.ref(!1),I=t.computed({get:()=>W.value?U.value:null,set(e){const t=e.type??"",n=t[0].toUpperCase()+t.slice(1);O[n]=e}}),z=j("Scene","FALLBACK_SCENE"),K=j("Raycaster","AUTO_RAYCASTER",{},(e=>(e=>{if(!e.instance)return;let n=null;n=t.watch((()=>I.value),(e=>{e?.instance&&(L||(w=t=>{const n=(e.instance.domElement.width??1)/ve.dpr.value,r=(e.instance.domElement.height??1)/ve.dpr.value;C.value.x=t.offsetX/n*2-1,C.value.y=-t.offsetY/r*2+1},R=()=>g.value=!0,A=()=>g.value=!1,e.instance.domElement.addEventListener("mousemove",w),e.instance.domElement.addEventListener("mousedown",R),e.instance.domElement.addEventListener("mouseup",A),t.watch((()=>[g.value,C.value.x,C.value.y]),(()=>{E&&cancelAnimationFrame(E),E=requestAnimationFrame((()=>{M()}))})),L=!0),n&&n())}),{immediate:!0})})(e)));function _(e={},t={}){const n={attached:e.attached??[],attachedArray:e.attachedArray??{},instance:e.instance??null},r=new Q.RendererStandardNode({...e,...n,metaType:"standardMeta"});return!r.type||y(r)||r.instance||(r.instance=function(e){if(!e.type)return null;const t=e.type[0].toUpperCase()+e.type.slice(1),n=d[e.type]||a[t];if(!n)throw`${t} is not part of the THREE namespace! Did you forget to extend? import {extend} from 'lunchbox'; extend({app, YourComponent, ...})`;const r=(e.props.args??[]).map((t=>function({node:e,prop:t}){const n="string"==typeof t&&t.startsWith("$attachedArray"),r=function({node:e,prop:t}){if("string"==typeof t&&t.startsWith("$attachedArray"))return e.attachedArray[t.replace("$attachedArray.","")];if("string"==typeof t&&t.startsWith("$attached"))return e.attached[t.replace("$attached.","")];return t}({node:e,prop:t});return Array.isArray(r)&&n?r:[r]}({node:e,prop:t})));let o=[];r.forEach((e=>{o=o.concat(e)}));return new n(...o)}({...r,props:{...r.props,...t}})),"scene"===r.type?.toLowerCase()?z.value=r:r.type?.toLowerCase().endsWith("camera")&&(D.value=r),r}const q=e=>t.defineComponent({inheritAttrs:!1,name:e,render(){return t.h(e,this.$attrs,this.$slots?.default?.()||[])}});var V,H=new Uint8Array(16);function Y(){if(!V&&!(V="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return V(H)}var X=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function J(e){return"string"==typeof e&&X.test(e)}for(var Q,Z=[],ee=0;ee<256;++ee)Z.push((ee+256).toString(16).substr(1));function te(e,t,n){var r=(e=e||{}).random||(e.rng||Y)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(var o=0;o<16;++o)t[n+o]=r[o];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(Z[e[t+0]]+Z[e[t+1]]+Z[e[t+2]]+Z[e[t+3]]+"-"+Z[e[t+4]]+Z[e[t+5]]+"-"+Z[e[t+6]]+Z[e[t+7]]+"-"+Z[e[t+8]]+Z[e[t+9]]+"-"+Z[e[t+10]]+Z[e[t+11]]+Z[e[t+12]]+Z[e[t+13]]+Z[e[t+14]]+Z[e[t+15]]).toLowerCase();if(!J(n))throw TypeError("Stringified UUID is invalid");return n}(r)}!function(e){e.BaseNode=class{constructor(e={},t){this.parentNode=e?.parentNode??t??null,this.minidomType="MinidomBaseNode",this.uuid=e?.uuid??te(),s.push(this)}uuid;parentNode;get nextSibling(){if(!this.parentNode)return null;const e=this.parentNode.children.findIndex((e=>e.uuid===this.uuid));return-1!==e&&e<this.parentNode.children.length-1?this.parentNode.children[e+1]:null}insertBefore(e,t){e.removeAsChildFromAnyParents(),e.parentNode=this;const n=this.children.findIndex((e=>e.uuid===t?.uuid));-1!==n?this.children.splice(n,0,e):this.children.push(e)}removeChild(e){const t=this.children.findIndex((t=>t?.uuid===e?.uuid));-1!==t&&this.children.splice(t,1)}children=[];addChild(e){return e&&(e.removeAsChildFromAnyParents(),e.parentNode=this,this.insertBefore(e,null)),this}getPath(){const e=[];let t=this;for(;t;)e.unshift(t),t=t.parentNode;return e}drop(){this.parentNode=null,this.removeAsChildFromAnyParents()}walk(e){const t=[this,...this.children],n=[];let r=!0;for(;t.length&&r;){const o=t.shift();if(o){if(n.includes(o))continue;n.push(o),t.push(...o.children.filter((e=>!n.includes(e)))),r=e(o)}else r=!1}}minidomType;removeAsChildFromAnyParents(){s.forEach((e=>e.removeChild(this)))}};class t extends e.BaseNode{constructor(e={},t){super(e,t),this.minidomType="RendererNode",this.eventListeners={},this.eventListenerRemoveFunctions={},this.name=e.name??"",this.metaType=e.metaType??"standardMeta",this.props=e.props??[],this.type=e.type??""}eventListeners;eventListenerRemoveFunctions;name;metaType;props;type;drop(){super.drop(),Object.keys(this.eventListenerRemoveFunctions).forEach((e=>{this.eventListenerRemoveFunctions[e].forEach((e=>e()))}))}}e.RendererBaseNode=t;class n extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.domElement=e.domElement??document.createElement("div")}domElement;isLunchboxRootNode=!0}e.RendererRootNode=n;class r extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.text=e.text??""}text}e.RendererCommentNode=r;class o extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.domElement=e.domElement??document.createElement("div")}domElement}e.RendererDomNode=o;class a extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.text=e.text??""}text}e.RendererTextNode=a;class i extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.attached=e.attached??[],this.attachedArray=e.attachedArray??{},this.instance=e.instance??null}attached;attachedArray;instance}e.RendererStandardNode=i}(Q||(Q={}));(new Q.RendererRootNode).minidomType="RootNode";const ne=[];let re,oe;const ae=[],se=[],ie=e=>{ue(),re=requestAnimationFrame((()=>ce({app:e.app,renderer:I.value?.instance,scene:z.value.instance,camera:D.value?.instance,updateSource:e.updateSource})))},ce=e=>{e.updateSource?oe||(oe=t.watch(e.updateSource,(()=>{ie(e)}),{deep:!0})):ie(e);const{app:n,renderer:r,scene:o,camera:a}=e;ae.forEach((t=>{t&&t(e)})),r&&o&&a&&(n.customRender?n.customRender(e):r.render(t.toRaw(o),t.toRaw(a))),se.forEach((t=>{t&&t(e)}))},ue=()=>{re&&cancelAnimationFrame(re)},de=()=>{oe&&oe()};const le={x:"position.x",y:"position.y",z:"position.z"},pe=["","parameters"],me=["args","attach","attachArray","is.default","isDefault","key","onAdded","ref","src"],he=["geometry","material"];function fe(e,t,n,r){const o=r??e.instance,a=t.instance;e.props.attach===n&&(t.attached={[n]:o,...t.attached||{}},a[n]=r??e.instance),e.props.attachArray===n&&(t.attachedArray[e.props.attachArray]||(t.attachedArray[e.props.attachArray]=[]),t.attachedArray[e.props.attachArray].push(o),a[n]=[a[n]])}const ye={createElement:(e,t,n,r)=>{const o={type:e};r&&(o.props=r);if(h(e)){const e=function(e={}){const t={domElement:document.createElement(e.type??"")};return new Q.RendererDomNode({...t,...e,metaType:"domMeta"})}(o);return e}const a=_(o);return he.forEach((t=>{e.toLowerCase().endsWith(t)&&(a.props.attach=t)})),a},createText:e=>function(e={}){const t={text:e.text??""};return new Q.RendererTextNode({...e,...t,metaType:"textMeta"})}({text:e}),createComment:e=>function(e={}){const t={text:e.text??""};return new Q.RendererCommentNode({...t,...e,metaType:"commentMeta"})}({text:e}),insert:(e,t,n)=>{let r=t??N();if(r.insertBefore(e,n),"commentMeta"!==e.metaType&&"textMeta"!==e.metaType&&(h(e)&&(h(t)||y(t))&&t.domElement.appendChild(e.domElement),f(e))){let n=r.metaType;if("textMeta"===n||"commentMeta"===n){const e=r.getPath();for(let t=e.length-1;t>=0;t--)if("textMeta"!==e[t].metaType&&"commentMeta"!==e[t].metaType){r=e[t];break}}if("standardMeta"===e.metaType&&"scene"!==e.type&&y(r)){const t=z.value;t.instance&&e&&t.addChild(e),e.instance&&e.instance.isObject3D&&t.instance&&t!==e&&t.instance.add(e.instance)}else f(e)&&e.instance?.isObject3D&&f(r)&&r.instance?.isObject3D&&r.instance?.add?.(e.instance);if(e?.props?.attach&&f(t)&&t?.instance){e.type?.toLowerCase().endsWith("loader")&&e.props.src&&(e.props.attach||e.props.attachArray)?function(e,t){const n=e.instance;if(t.attached=t.attached||{},t.attachedArray=t.attachedArray||{},!e.props.attach)return;if("textureloader"===e.type?.toLowerCase()){const r=n.load(e.props.src);fe(e,t,e.props.attach,r)}else n.load(e.props.src,(n=>{fe(e,t,e.props.attach,n)}),null,(e=>{throw new Error(e)}))}(e,t):fe(e,t,e.props.attach)}e.props?.onAdded&&e.props.onAdded({instance:e.instance})}},nextSibling(e){const t=e.nextSibling;return t||null},parentNode(e){const t=e.parentNode;return t||null},patchProp(e,t,n,o){h(e)?"style"===t?Object.keys(o).forEach((t=>{e.domElement.style[t]=o[t]})):e.domElement.setAttribute(t,o):y(e)||t.startsWith("$")||function({node:e,key:t,value:n}){if((e=>["onClick","onContextMenu","onDoubleClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove","onWheel"].includes(e))(t))return b({node:e,key:t,value:n});const o=t.replace(/-/g,"."),a=le[o]||o;if(me.includes(t)||me.includes(a))return e;if(!f(e))return e;if("string"==typeof n&&n.startsWith("$attached")){const t=n.replace("$attached.","");n=r.get(e.attached,t,null)}const s=e.instance;if(!s)return e;let i;for(let e=0;e<pe.length&&!i;e++){const t=[pe[e],a].filter(Boolean).join(".");i=i=r.get(s,t)}if(i&&r.isNumber(n)&&i.setScalar)i.setScalar(n);else if(i&&i.set){const e=Array.isArray(n)?n:[n];s[a].set(...e)}else"function"==typeof i?i.bind(e.instance)(...n):void 0!==r.get(s,a,void 0)?r.set(s,a,""===n||n):console.log(`No property ${a} found on ${s}`);const c=s?.texture?.type||s?.type;if("string"==typeof c){const e=c.toLowerCase();switch(!0){case e.includes("material"):s.needsUpdate=!0;break;case e.includes("camera")&&s.updateProjectionMatrix:s.updateProjectionMatrix()}}}({node:e,key:t,value:o})},remove:e=>{if(!e)return;const t=Object.keys(O),n=[];e.walk((e=>(n.push(e),!0))),n.forEach((e=>{const n=t.find((t=>O[t]?.uuid===e.uuid));if(n&&(O[n]=null),f(e)){e.instance?.removeFromParent?.();const t="scene"!==e.type&&e.instance?.dispose;t&&t.bind(e.instance)(),e.instance=null}e.drop();const r=s.findIndex((t=>t.uuid===e.uuid));-1!==r&&s.splice(r,1)}))},setElementText(){},setText(){}},ve={dpr:t.ref(1),inputActive:g,mousePos:C},ge=t.computed((()=>D.value?.instance??null));const be=t.computed((()=>I.value?.instance??null));const xe=t.computed((()=>z.value.instance));let we=null,Re=null;e.camera=ge,e.clearCustomRender=()=>{we?we.clearCustomRender():Re=null},e.createApp=e=>{we=t.createRenderer(ye).createApp(e),Object.keys(p).forEach((e=>{we?.component(e,p[e])}));const{mount:n}=we;return we.mount=(e,...t)=>{const r=N({domElement:"string"==typeof e?document.querySelector(e):e,isLunchboxRootNode:!0,name:"root",metaType:"rootMeta",type:"root",uuid:"LUNCHBOX_ROOT"});we.rootNode=r;return n(r,...t)},we.extend=e=>((({app:e,...t})=>{Object.keys(t).forEach((n=>{e.component(n,q(n)),d[n]=t[n]}))})({app:we,...e}),we),we.setCustomRender=e=>{we.customRender=e},Re&&(we.setCustomRender(Re),Re=null),we.clearCustomRender=()=>{we.customRender=null},we},e.find=function(e){return e=t.isRef(e)?e.value:e,f(e)?e?.instance:m(e)?e?.$el?.instance:t.isVNode(e)?e.el?.instance:null},e.globals=ve,e.offAfterRender=e=>{if(isFinite(e))se.splice(e,1);else{const t=se.findIndex((t=>t==e));se.splice(t,1)}},e.offBeforeRender=e=>{if(isFinite(e))ae.splice(e,1);else{const t=ae.findIndex((t=>t==e));ae.splice(t,1)}},e.onAfterRender=(e,t=1/0)=>{t===1/0?se.push(e):se.splice(t,0,e)},e.onBeforeRender=(e,t=1/0)=>{t===1/0?ae.push(e):ae.splice(t,0,e)},e.onStart=(e,t=1/0)=>{t===1/0?ne.push(e):ne.splice(t,0,e)},e.renderer=be,e.scene=xe,e.setCustomRender=e=>{we?we.setCustomRender(e):Re=e},e.useCamera=function(e){return t.watch(ge,(t=>{t&&e(t)}),{immediate:!0})},e.useRenderer=function(e){return t.watch(be,(t=>{t&&e(t)}),{immediate:!0})},e.useScene=function(e){return t.watch(xe,(t=>{t&&e(t)}),{immediate:!0})},Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("three"),require("lodash")):"function"==typeof define&&define.amd?define(["exports","vue","three","lodash"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Lunchbox={},e.vue,e.three,e.lodash)}(this,(function(e,t,r,o){"use strict";function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var o=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,o.get?o:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a=n(r);const s=e=>e?.$el&&e?.$el?.hasOwnProperty?.("instance"),i=e=>"domMeta"===e?.metaType||e?.props?.["data-lunchbox"],c=e=>"standardMeta"===e?.metaType,d=e=>e.isLunchboxRootNode;function l(t={}){const r={text:t.text??""};return new e.MiniDom.RendererCommentNode({...r,...t,metaType:"commentMeta"})}function p(t={}){const r={domElement:document.createElement(t.type??"")};return new e.MiniDom.RendererDomNode({...r,...t,metaType:"domMeta"})}function u(t={}){const r={text:t.text??""};return new e.MiniDom.RendererTextNode({...t,...r,metaType:"textMeta"})}function m(t={},r={}){const o={attached:t.attached??[],attachedArray:t.attachedArray??{},instance:t.instance??null},n=new e.MiniDom.RendererStandardNode({...t,...o,metaType:"standardMeta"});return!n.type||d(n)||n.instance||(n.instance=Q({...n,props:{...n.props,...r}})),n}const h=Symbol(),f=Symbol(),y=Symbol(),g=Symbol(),b=Symbol(),v=Symbol(),x=Symbol(),R=Symbol(),w=Symbol(),P=Symbol(),C=Symbol(),A=Symbol(),N=Symbol(),M=Symbol(),S=Symbol(),B=Symbol(),L=Symbol(),E=Symbol(),G=()=>t.inject(L),j=()=>t.inject(S),T=()=>t.inject(B),k=[],O=e=>{k.push(e)},$=e=>{const t=k.indexOf(e);-1!==t&&k.splice(t,1)},D=t.ref(!1),F=t.ref({x:1/0,y:1/0});let K=[];function I({node:e,key:r,value:o}){if(e.eventListeners[r]||(e.eventListeners[r]=[]),e.eventListenerRemoveFunctions[r]||(e.eventListenerRemoveFunctions[r]=[]),e.eventListeners[r].push(o),U.includes(r)&&e.instance&&!k.includes(e)&&(O(e),e.eventListenerRemoveFunctions[r].push((()=>$(e)))),"onClick"===r||"onPointerDown"===r||"onPointerUp"===r){const o=t.watch((()=>D.value),(t=>{const o=K.map((e=>e.element)).findIndex((t=>t.instance&&t.instance.uuid===e.instance?.uuid));-1!==o&&((!t||"onClick"!==r&&"onPointerDown"!==r)&&(t||"onPointerUp"!==r)||e.eventListeners[r].forEach((e=>{e({intersection:K[o].intersection})})))}));e.eventListenerRemoveFunctions[r].push(o)}return e}const U=["onClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove"],V=(e,r,o,n,a)=>{if(!r?.domElement||!o||!e)return;const s=(n=n??window.innerWidth)/(a=a??window.innerHeight);if("perspectivecamera"===e.type?.toLowerCase()){const t=e;t.aspect=s,t.updateProjectionMatrix()}else if("orthographiccamera"===e.type?.toLowerCase()){const t=e,r=a/n;t.top=10*r,t.bottom=10*-r,t.right=10,t.left=-10,t.updateProjectionMatrix()}r.setSize(n,a),o&&e&&r.render(t.toRaw(o),t.toRaw(e))},z=(e,t,r,o,n)=>{const a=e.value?.domElement;if(!a)throw new Error("missing container");const s=()=>{if("container"===n){const e=(e=>{const t=getComputedStyle(e);return{width:e.clientWidth-parseFloat(t.paddingLeft)-parseFloat(t.paddingRight),height:e.clientHeight-parseFloat(t.paddingTop)-parseFloat(t.paddingBottom)}})(a);V(t,r,o,e.width,e.height)}else V(t,r,o)};s();let i=new ResizeObserver((()=>{s()}));return a&&i.observe(a),{dispose(){a&&i.unobserve(a)}}},H=t.defineComponent({name:"LunchboxScene",setup:(e,{slots:r})=>()=>t.createVNode(t.resolveComponent("scene"),null,{default:()=>[r.default?.()]})}),W=e=>({position:e,top:0,right:0,bottom:0,left:0,width:"100%",height:"100%",display:"block"}),q=t.defineComponent({name:"Lunchbox",props:{background:String,cameraArgs:Array,cameraLook:Array,cameraLookAt:Array,cameraPosition:Array,dpr:Number,ortho:Boolean,orthographic:Boolean,r3f:Boolean,rendererArguments:Object,rendererProperties:Object,sizePolicy:String,shadow:[Boolean,Object],transparent:Boolean,zoom:Number,updateSource:Object},setup(e,r){const o=t.ref();let n=e.dpr??-1;const s=t.ref(),i=t.ref(),c=t.ref(),d=t.ref(),l=Ae(),p=Ne(),u=Me(),m=t.reactive({}),h=Se();e.r3f&&a?.ColorManagement&&(a.ColorManagement.legacyMode=!1),t.onMounted((async()=>{if(!o.value&&!r.slots?.renderer?.()?.length)throw new Error("missing canvas");for(r.slots?.camera?.()?.length||(e.cameraPosition&&(m.position=e.cameraPosition),(e.cameraLook||e.cameraLookAt)&&(m.lookAt=e.cameraLook||e.cameraLookAt),void 0!==e.zoom&&(m.zoom=e.zoom)),d.value?.$el?.instance&&e.background&&(d.value.$el.instance.background=new a.Color(e.background)),-1===n&&(n=window.devicePixelRatio),p?.({dpr:n}),console.log(1);!i.value?.$el?.instance&&!i.value?.component?.ctx.$el?.instance;)console.log(2),await new Promise((e=>requestAnimationFrame(e)));for(console.log(3);!d.value?.$el?.instance&&!d.value?.component?.ctx.$el?.instance;)console.log(4),await new Promise((e=>requestAnimationFrame(e)));console.log(5);const t=i.value?.$el?.instance??i.value?.component?.ctx.$el?.instance;t.setPixelRatio(l.dpr);const f=d.value?.$el?.instance??d.value?.component?.ctx.$el?.instance,y=c.value?.$el?.instance??c.value?.component?.ctx.$el?.instance;if(!r.slots?.renderer?.()?.length){z(s,y,t,f,e.sizePolicy),e.r3f&&(t.outputEncoding=a.sRGBEncoding,t.toneMapping=a.ACESFilmicToneMapping);const r={shadow:e.shadow};r?.shadow&&(t.shadowMap.enabled=!0,"object"==typeof r.shadow&&(t.shadowMap.type=r.shadow.type))}if(!u)throw new Error("error creating app");u.config.globalProperties.lunchbox.camera=y,u.config.globalProperties.lunchbox.renderer=t,u.config.globalProperties.lunchbox.scene=f;for(let e of h??[])e({app:u,camera:y,renderer:t,scene:f});ce({app:u,camera:y,renderer:t,scene:f,updateSource:e.updateSource})})),t.onBeforeUnmount((()=>{pe(),me()}));const f="container"===e.sizePolicy?"static":"absolute",y="container"===e.sizePolicy?"static":"fixed";return()=>t.createVNode(t.Fragment,null,[r.slots?.renderer?.()?.length?i.value=r.slots?.renderer?.()[0]:t.createVNode(t.Fragment,null,[t.createVNode("div",{class:"lunchbox-container",style:W(f),ref:s,"data-lunchbox":"true"},[t.createVNode("canvas",{ref:o,class:"lunchbox-canvas",style:W(y),"data-lunchbox":"true"},null)]),o.value?.domElement&&t.createVNode(t.resolveComponent("webGLRenderer"),t.mergeProps(e.rendererProperties??{},{ref:i,args:[{alpha:e.transparent,antialias:!0,canvas:o.value?.domElement,powerPreference:e.r3f?"high-performance":"default",...e.rendererArguments??{}}]}),null)]),r.slots?.scene?.()?.length?d.value=r.slots?.scene?.()[0]:t.createVNode(H,{ref:d},{default:()=>[r.slots?.default?.()]}),r.slots?.camera?.()?.length?c.value=r.slots?.camera?.()[0]:e.ortho||e.orthographic?t.createVNode(t.resolveComponent("orthographicCamera"),t.mergeProps({ref:c,args:e.cameraArgs??[]},m),null):t.createVNode(t.resolveComponent("perspectiveCamera"),t.mergeProps({ref:c,args:e.cameraArgs??[e.r3f?75:45,.5625,1,1e3]},m),null)])}}),_={},X={...["mesh","instancedMesh","scene","sprite","object3D","instancedBufferGeometry","bufferGeometry","boxBufferGeometry","circleBufferGeometry","coneBufferGeometry","cylinderBufferGeometry","dodecahedronBufferGeometry","extrudeBufferGeometry","icosahedronBufferGeometry","latheBufferGeometry","octahedronBufferGeometry","parametricBufferGeometry","planeBufferGeometry","polyhedronBufferGeometry","ringBufferGeometry","shapeBufferGeometry","sphereBufferGeometry","tetrahedronBufferGeometry","textBufferGeometry","torusBufferGeometry","torusKnotBufferGeometry","tubeBufferGeometry","wireframeGeometry","parametricGeometry","tetrahedronGeometry","octahedronGeometry","icosahedronGeometry","dodecahedronGeometry","polyhedronGeometry","tubeGeometry","torusKnotGeometry","torusGeometry","sphereGeometry","ringGeometry","planeGeometry","latheGeometry","shapeGeometry","extrudeGeometry","edgesGeometry","coneGeometry","cylinderGeometry","circleGeometry","boxGeometry","material","shadowMaterial","spriteMaterial","rawShaderMaterial","shaderMaterial","pointsMaterial","meshPhysicalMaterial","meshStandardMaterial","meshPhongMaterial","meshToonMaterial","meshNormalMaterial","meshLambertMaterial","meshDepthMaterial","meshDistanceMaterial","meshBasicMaterial","meshMatcapMaterial","lineDashedMaterial","lineBasicMaterial","light","spotLightShadow","spotLight","pointLight","rectAreaLight","hemisphereLight","directionalLightShadow","directionalLight","ambientLight","lightShadow","ambientLightProbe","hemisphereLightProbe","lightProbe","texture","videoTexture","dataTexture","dataTexture3D","compressedTexture","cubeTexture","canvasTexture","depthTexture","textureLoader","group","catmullRomCurve3","points","cameraHelper","camera","perspectiveCamera","orthographicCamera","cubeCamera","arrayCamera","webGLRenderer"].map((e=>t.defineComponent({inheritAttrs:!1,name:e,setup:(r,o)=>()=>t.h(e,o.attrs,o.slots?.default?.()||[])}))).reduce(((e,t)=>(e[t.name]=t,e)),{}),Lunchbox:q},Y=e=>t.defineComponent({inheritAttrs:!1,name:e,render(){return t.h(e,this.$attrs,this.$slots?.default?.()||[])}}),J=({app:e,...t})=>{Object.keys(t).forEach((r=>{e.component(r,Y(r)),_[r]=t[r]}))};function Q(e){if(!e.type)return null;const t=e.type[0].toUpperCase()+e.type.slice(1),r=t.replace(/Lunchbox$/,""),o=_[e.type]||a[t]||_[r]||a[r];if(!o)throw`${t} is not part of the THREE namespace! Did you forget to extend? import {extend} from 'lunchbox'; extend({app, YourComponent, ...})`;const n=(e.props.args??[]).map((t=>function({node:e,prop:t}){const r="string"==typeof t&&t.startsWith("$attachedArray"),o=function({node:e,prop:t}){return"string"==typeof t&&t.startsWith("$attachedArray")?e.attachedArray[t.replace("$attachedArray.","")]:"string"==typeof t&&t.startsWith("$attached")?e.attached[t.replace("$attached.","")]:t}({node:e,prop:t});return Array.isArray(o)&&r?o:[o]}({node:e,prop:t})));let s=[];n.forEach((e=>{s=s.concat(e)}));return new o(...s)}var Z,ee=new Uint8Array(16);function te(){if(!Z&&!(Z="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Z(ee)}var re=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function oe(e){return"string"==typeof e&&re.test(e)}for(var ne=[],ae=0;ae<256;++ae)ne.push((ae+256).toString(16).substr(1));function se(e,t,r){var o=(e=e||{}).random||(e.rng||te)();if(o[6]=15&o[6]|64,o[8]=63&o[8]|128,t){r=r||0;for(var n=0;n<16;++n)t[r+n]=o[n];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(ne[e[t+0]]+ne[e[t+1]]+ne[e[t+2]]+ne[e[t+3]]+"-"+ne[e[t+4]]+ne[e[t+5]]+"-"+ne[e[t+6]]+ne[e[t+7]]+"-"+ne[e[t+8]]+ne[e[t+9]]+"-"+ne[e[t+10]]+ne[e[t+11]]+ne[e[t+12]]+ne[e[t+13]]+ne[e[t+14]]+ne[e[t+15]]).toLowerCase();if(!oe(r))throw TypeError("Stringified UUID is invalid");return r}(o)}e.MiniDom=void 0,function(e){e.BaseNode=class{constructor(e={},t){this.parentNode=e?.parentNode??t??null,this.minidomType="MinidomBaseNode",this.uuid=e?.uuid??se()}uuid;parentNode;get nextSibling(){if(!this.parentNode)return null;const e=this.parentNode.children.findIndex((e=>e.uuid===this.uuid));return-1!==e&&e<this.parentNode.children.length-1?this.parentNode.children[e+1]:null}insertBefore(e,t){e.removeAsChildFromAnyParents(),e.parentNode=this;const r=this.children.findIndex((e=>e.uuid===t?.uuid));-1!==r?this.children.splice(r,0,e):this.children.push(e)}removeChild(e){const t=this.children.findIndex((t=>t?.uuid===e?.uuid));-1!==t&&this.children.splice(t,1)}children=[];addChild(e){return e&&(e.removeAsChildFromAnyParents(),e.parentNode=this,this.insertBefore(e,null)),this}getPath(){const e=[];let t=this;for(;t;)e.unshift(t),t=t.parentNode;return e}drop(){this.removeAsChildFromAnyParents(),this.parentNode=null}walk(e){const t=[this,...this.children],r=[];let o=!0;for(;t.length&&o;){const n=t.shift();if(n){if(r.includes(n))continue;r.push(n),t.push(...n.children.filter((e=>!r.includes(e)))),o=e(n)}else o=!1}}minidomType;removeAsChildFromAnyParents(){this.parentNode?.removeChild(this)}};class t extends e.BaseNode{constructor(e={},t){super(e,t),this.minidomType="RendererNode",this.eventListeners={},this.eventListenerRemoveFunctions={},this.name=e.name??"",this.metaType=e.metaType??"standardMeta",this.props=e.props??[],this.type=e.type??""}eventListeners;eventListenerRemoveFunctions;name;metaType;props;type;drop(){super.drop(),Object.keys(this.eventListenerRemoveFunctions).forEach((e=>{this.eventListenerRemoveFunctions[e].forEach((e=>e()))}))}}e.RendererBaseNode=t;class r extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.domElement=e.domElement??document.createElement("div")}domElement;isLunchboxRootNode=!0}e.RendererRootNode=r;class o extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.text=e.text??""}text}e.RendererCommentNode=o;class n extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.domElement=e.domElement??document.createElement("div")}domElement}e.RendererDomNode=n;class a extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.text=e.text??""}text}e.RendererTextNode=a;class s extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.attached=e.attached??[],this.attachedArray=e.attachedArray??{},this.instance=e.instance??null}attached;attachedArray;instance}e.RendererStandardNode=s}(e.MiniDom||(e.MiniDom={}));const ie=e=>{"number"==typeof e.app.config.globalProperties.lunchbox.frameId&&cancelAnimationFrame(e.app.config.globalProperties.lunchbox.frameId),e.app.config.globalProperties.lunchbox.frameId=requestAnimationFrame((()=>ce({app:e.app,renderer:e.renderer,scene:e.scene,camera:e.camera,updateSource:e.updateSource})))},ce=e=>{e.updateSource?e.app.config.globalProperties.lunchbox.watchStopHandle||(e.app.config.globalProperties.lunchbox.watchStopHandle=t.watch(e.updateSource,(()=>{ie(e)}),{deep:!0})):ie(e);const{app:r,renderer:o,scene:n,camera:a}=e;r.config.globalProperties.lunchbox.beforeRender.forEach((t=>{t?.(e)})),o&&n&&a&&(r.customRender?r.customRender(e):o.render(t.toRaw(n),t.toRaw(a))),r.config.globalProperties.lunchbox.afterRender.forEach((t=>{t?.(e)}))},de=()=>({onBeforeRender:t.inject(v),offBeforeRender:t.inject(x)}),le=()=>{const e=t.inject(C);return()=>{void 0!==e&&cancelAnimationFrame(e)}},pe=()=>{le()?.()},ue=()=>{const e=t.inject(A);return()=>e?.()},me=()=>{ue()?.()};function he({node:e,key:t,value:r}){if((e=>["onClick","onContextMenu","onDoubleClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove","onWheel"].includes(e))(t))return I({node:e,key:t,value:r});const n=t.replace(/-/g,"."),a=fe[n]||n;if(ge.includes(t)||ge.includes(a))return e;if(!c(e))return e;if("string"==typeof r&&r.startsWith("$attached")){const t=r.replace("$attached.","");r=o.get(e.attached,t,null)}const s=e.instance;if(!s)return e;let i;for(let e=0;e<ye.length&&!i;e++){const t=[ye[e],a].filter(Boolean).join(".");i=i=o.get(s,t)}if(i&&o.isNumber(r)&&i.setScalar)i.setScalar(r);else if(i&&i.set){const e=Array.isArray(r)?r:[r];s[a].set(...e)}else"function"==typeof i?i.bind(e.instance)(...r):void 0!==o.get(s,a,void 0)?o.set(s,a,""===r||r):console.log(`No property ${a} found on ${s}`);const d=s?.texture?.type||s?.type;if("string"==typeof d){const e=d.toLowerCase();switch(!0){case e.includes("material"):s.needsUpdate=!0;break;case e.includes("camera")&&s.updateProjectionMatrix:s.updateProjectionMatrix()}}return e}const fe={x:"position.x",y:"position.y",z:"position.z"},ye=["","parameters"],ge=["args","attach","attachArray","is.default","isDefault","key","onAdded","ref","src"],be=["geometry","material"];function ve(e,t,r,o){const n=o??e.instance,a=t.instance;e.props.attach===r&&(t.attached={[r]:n,...t.attached||{}},a[r]=o??e.instance),e.props.attachArray===r&&(t.attachedArray[e.props.attachArray]||(t.attachedArray[e.props.attachArray]=[]),t.attachedArray[e.props.attachArray].push(n),a[r]=[a[r]])}const xe={createElement:(e,t,r,o)=>{const n={type:e,props:o};if(i(n)){return p(n)}const a=m(n);return be.forEach((t=>{e.toLowerCase().endsWith(t)&&(a.props.attach=t)})),a},createText:e=>u({text:e}),createComment:e=>l({text:e}),insert:(e,t,r)=>{if(!t)throw new Error("missing parent");if(t.insertBefore(e,r),"commentMeta"!==e.metaType&&"textMeta"!==e.metaType&&(i(e)&&(i(t)||d(t))&&t.domElement.appendChild(e.domElement),c(e))){let r=t.metaType;if("textMeta"===r||"commentMeta"===r){const e=t.getPath();for(let r=e.length-1;r>=0;r--)if("textMeta"!==e[r].metaType&&"commentMeta"!==e[r].metaType){t=e[r];break}}if(c(e)&&e.instance?.isObject3D&&c(t)&&t.instance?.isObject3D&&t.instance?.add?.(e.instance),e?.props?.attach&&c(t)&&t?.instance){e.type?.toLowerCase().endsWith("loader")&&e.props.src&&(e.props.attach||e.props.attachArray)?function(e,t){const r=e.instance;if(t.attached=t.attached||{},t.attachedArray=t.attachedArray||{},!e.props.attach)return;if("textureloader"===e.type?.toLowerCase()){const o=r.load(e.props.src);ve(e,t,e.props.attach,o)}else r.load(e.props.src,(r=>{ve(e,t,e.props.attach,r)}),null,(e=>{throw new Error(e)}))}(e,t):ve(e,t,e.props.attach)}e.props?.onAdded&&e.props.onAdded({instance:e.instance})}},nextSibling(e){const t=e.nextSibling;return t||null},parentNode(e){const t=e.parentNode;return t||null},patchProp(e,t,r,o){i(e)?"style"===t?Object.keys(o).forEach((t=>{e.domElement.style[t]=o[t]})):e.domElement.setAttribute(t,o):d(e)||t.startsWith("$")||he({node:e,key:t,value:o})},remove:e=>{if(!e)return;const t=[];e.walk((e=>(t.push(e),!0))),t.forEach((e=>{if(c(e)){e.instance?.removeFromParent?.();const t="scene"!==e.type&&e.instance?.dispose;t&&t.bind(e.instance)(),e.instance=null}e.drop()}))},setElementText(){},setText(){}},Re=G,we=j,Pe=T;const Ce=()=>({setCustomRender:t.inject(y),clearCustomRender:t.inject(g)}),Ae=()=>t.inject(h),Ne=()=>t.inject(f),Me=()=>t.inject(M),Se=()=>t.inject(E);e.addEventListener=I,e.addInteractable=O,e.afterRenderKey=R,e.appCameraKey=L,e.appKey=M,e.appRenderersKey=S,e.appRootNodeKey=N,e.appSceneKey=B,e.beforeRenderKey=b,e.camera=Re,e.cancelUpdate=pe,e.cancelUpdateSource=me,e.clearCustomRender=()=>{Ce()?.clearCustomRender?.()},e.clearCustomRenderKey=g,e.createApp=r=>{const o=t.createRenderer(xe).createApp(r);Object.keys(X).forEach((e=>{o?.component(e,X[e])})),o.provide(y,(e=>{o.setCustomRender(e)})),o.provide(g,(()=>{o.clearCustomRender()}));const n=[];o.provide(b,n),o.provide(v,((e,t=1/0)=>{t===1/0?n.push(e):n.splice(t,0,e)})),o.provide(x,(e=>{if(isFinite(e))n.splice(e,1);else{const t=n.findIndex((t=>t==e));-1!==t&&n.splice(t,1)}}));const a=[];o.provide(R,a),o.provide(w,((e,t=1/0)=>{t===1/0?a.push(e):a.splice(t,0,e)})),o.provide(P,(e=>{if(isFinite(e))a.splice(e,1);else{const t=a.findIndex((t=>t==e));-1!==t&&a.splice(t,1)}})),o.config.globalProperties.lunchbox=t.reactive({afterRender:a,beforeRender:n,camera:null,dpr:1,frameId:-1,renderer:null,scene:null,watchStopHandle:null}),o.provide(h,o.config.globalProperties.lunchbox),o.provide(f,(e=>{Object.keys(e).forEach((t=>{const r=t;o.config.globalProperties.lunchbox[r]=e[r]}))})),o.provide(C,o.config.globalProperties.lunchbox.frameId),o.provide(A,o.config.globalProperties.lunchbox.watchStopHandle);const{mount:s}=o;o.mount=(t,...r)=>{const n="string"==typeof t?document.querySelector(t):t,a=new e.MiniDom.RendererRootNode({domElement:n,isLunchboxRootNode:!0,name:"root",metaType:"rootMeta",type:"root",uuid:"LUNCHBOX_ROOT"});o.rootNode=a,o.provide(N,a);return s(a,...r)},o.extend=e=>(J({app:o,...e}),o);return o.provide(E,[]),o.setCustomRender=e=>{o&&(o.customRender=e)},o.clearCustomRender=()=>{o&&(o.customRender=null)},o.provide(M,o),o.provide(S,t.computed((()=>o.config.globalProperties.lunchbox.renderer))),o.provide(B,t.computed((()=>o.config.globalProperties.lunchbox.scene))),o.provide(L,t.computed((()=>o.config.globalProperties.lunchbox.camera))),o},e.createCommentNode=l,e.createDomNode=p,e.createNode=m,e.createTextNode=u,e.currentIntersections=K,e.ensureRenderer=j,e.ensuredCamera=G,e.ensuredScene=T,e.extend=J,e.find=function(e){return e=t.isRef(e)?e.value:e,c(e)?e?.instance:s(e)?e?.$el?.instance:t.isVNode(e)?e.el?.instance:null},e.frameIdKey=C,e.globalsInjectionKey=h,e.inputActive=D,e.instantiateThreeObject=Q,e.interactables=k,e.isMinidomNode=function(e){return"RendererNode"===e?.minidomType},e.mousePos=F,e.nestedPropertiesToCheck=ye,e.offAfterRender=e=>{de().offBeforeRender?.(e)},e.offAfterRenderKey=P,e.offBeforeRender=e=>{de().offBeforeRender?.(e)},e.offBeforeRenderKey=x,e.onAfterRender=(e,t=1/0)=>{de().onBeforeRender?.(e,t)},e.onAfterRenderKey=w,e.onBeforeRender=(e,t=1/0)=>{de().onBeforeRender?.(e,t)},e.onBeforeRenderKey=v,e.onStart=(e,t=1/0)=>{const r=Se();t===1/0?r?.push(e):r?.splice(t,0,e)},e.removeInteractable=$,e.renderer=we,e.scene=Pe,e.setCustomRender=e=>{Ce()?.setCustomRender?.(e)},e.setCustomRenderKey=y,e.startCallbackKey=E,e.update=ce,e.updateAllObjectProps=function({node:e}){const t=e.props||{};let r=e;return Object.keys(t).forEach((o=>{r=he({node:e,key:o,value:t[o]})})),r},e.updateGlobals=e=>{Ne()?.(e)},e.updateGlobalsInjectionKey=f,e.updateObjectProp=he,e.useAfterRender=()=>({onAfterRender:t.inject(v),offAfterRender:t.inject(x)}),e.useApp=Me,e.useBeforeRender=de,e.useCamera=()=>G(),e.useCancelUpdate=le,e.useCancelUpdateSource=ue,e.useCustomRender=Ce,e.useGlobals=Ae,e.useRenderer=()=>j(),e.useRootNode=()=>t.inject(N),e.useScene=function(e){return t.watch(Pe,(t=>{t&&e(t.value)}),{immediate:!0})},e.useStartCallbacks=Se,e.useUpdateGlobals=Ne,e.watchStopHandleKey=A,Object.defineProperty(e,"__esModule",{value:!0})}));