lunchboxjs 0.2.1019 → 2.0.0-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.
- package/dist/lunchboxjs.es.d.ts +1 -1
- package/dist/lunchboxjs.js +6 -5
- package/dist/lunchboxjs.min.js +1 -1
- package/dist/lunchboxjs.module.js +6 -5
- package/dist/lunchboxjs.umd.d.ts +1 -1
- package/package.json +37 -82
- package/LICENSE.md +0 -7
- package/README.md +0 -17
- package/src/components/LunchboxEventHandlers.tsx +0 -237
- package/src/components/LunchboxWrapper/LunchboxScene.tsx +0 -8
- package/src/components/LunchboxWrapper/LunchboxWrapper.tsx +0 -341
- package/src/components/LunchboxWrapper/prepCanvas.ts +0 -55
- package/src/components/LunchboxWrapper/resizeCanvas.ts +0 -41
- package/src/components/autoGeneratedComponents.ts +0 -175
- package/src/components/index.ts +0 -31
- package/src/core/createNode.ts +0 -71
- package/src/core/extend.ts +0 -25
- package/src/core/index.ts +0 -7
- package/src/core/instantiateThreeObject/index.ts +0 -37
- package/src/core/instantiateThreeObject/processProps.ts +0 -40
- package/src/core/interaction.ts +0 -55
- package/src/core/minidom.ts +0 -256
- package/src/core/update.ts +0 -149
- package/src/core/updateObjectProp.ts +0 -153
- package/src/index.ts +0 -400
- package/src/keys.ts +0 -31
- package/src/nodeOps/createElement.ts +0 -34
- package/src/nodeOps/index.ts +0 -83
- package/src/nodeOps/insert.ts +0 -165
- package/src/nodeOps/remove.ts +0 -32
- package/src/plugins/bridge/BridgeComponent.tsx +0 -60
- package/src/plugins/bridge/bridge.ts +0 -9
- package/src/types.ts +0 -186
- package/src/utils/find.ts +0 -24
- package/src/utils/get.ts +0 -18
- package/src/utils/index.ts +0 -60
- package/src/utils/isNumber.ts +0 -87
- package/src/utils/set.ts +0 -14
package/dist/lunchboxjs.es.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "../src/index"
|
|
1
|
+
export * from "../src/index";
|
package/dist/lunchboxjs.js
CHANGED
|
@@ -1792,6 +1792,7 @@
|
|
|
1792
1792
|
// CREATE APP
|
|
1793
1793
|
// ====================
|
|
1794
1794
|
const createApp = (root, rootProps = {}) => {
|
|
1795
|
+
console.log("HERE");
|
|
1795
1796
|
const {
|
|
1796
1797
|
nodeOps,
|
|
1797
1798
|
interactables
|
|
@@ -1891,15 +1892,15 @@
|
|
|
1891
1892
|
} = app;
|
|
1892
1893
|
app.mount = (root, ...args) => {
|
|
1893
1894
|
// find DOM element to use as app root
|
|
1894
|
-
const domElement = typeof root ===
|
|
1895
|
+
const domElement = typeof root === "string" ? document.querySelector(root) : root;
|
|
1895
1896
|
// create or find root node
|
|
1896
1897
|
const rootNode = new exports.MiniDom.RendererRootNode({
|
|
1897
1898
|
domElement,
|
|
1898
1899
|
isLunchboxRootNode: true,
|
|
1899
|
-
name:
|
|
1900
|
-
metaType:
|
|
1901
|
-
type:
|
|
1902
|
-
uuid:
|
|
1900
|
+
name: "root",
|
|
1901
|
+
metaType: "rootMeta",
|
|
1902
|
+
type: "root",
|
|
1903
|
+
uuid: "LUNCHBOX_ROOT"
|
|
1903
1904
|
});
|
|
1904
1905
|
app.rootNode = rootNode;
|
|
1905
1906
|
app.provide(appRootNodeKey, rootNode);
|
package/dist/lunchboxjs.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("three")):"function"==typeof define&&define.amd?define(["exports","vue","three"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Lunchbox={},e.vue,e.three)}(this,(function(e,t,n){"use strict";function r(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 o=r(n);const a=(e,t,n)=>{if(!t)return;const r=(Array.isArray(t)?t:t.match(/([^[.\]])+/g))?.reduce(((e,t)=>e&&e[t]),e);return void 0===r?n:r},i=(()=>{const e=Object.prototype.toString;return function(t){return"number"==typeof t||function(e){return!!e&&"object"==typeof e}(t)&&"[object Number]"==e.call(t)}})(),s=e=>e?.$el&&e?.$el?.hasOwnProperty?.("instance"),c=e=>"domMeta"===e?.metaType||e?.props?.["data-lunchbox"],d=e=>"standardMeta"===e?.metaType,l=e=>e.isLunchboxRootNode;function u(t={}){const n={text:t.text??""};return new e.MiniDom.RendererCommentNode({...n,...t,metaType:"commentMeta"})}function p(t={}){const n={domElement:document.createElement(t.type??"")};return new e.MiniDom.RendererDomNode({...n,...t,metaType:"domMeta"})}function m(t={}){const n={text:t.text??""};return new e.MiniDom.RendererTextNode({...t,...n,metaType:"textMeta"})}function h(t={},n={}){const r={attached:t.attached??[],attachedArray:t.attachedArray??{},instance:t.instance??null},o=new e.MiniDom.RendererStandardNode({...t,...r,metaType:"standardMeta"});return!o.type||l(o)||o.instance||(o.instance=N({...o,props:{...o.props,...n}})),o}function f({node:e,key:t,interactables:n,value:r}){return e.eventListeners[t]||(e.eventListeners[t]=[]),e.eventListenerRemoveFunctions[t]||(e.eventListenerRemoveFunctions[t]=[]),e.eventListeners[t].push(r),y.includes(t)&&e.instance&&!n.value.includes(e)&&(n.value.push(e),e.eventListenerRemoveFunctions[t].push((()=>{const t=n.value.indexOf(e);-1!==t&&n.value.splice(t,1)}))),e}const y=["onClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove"],b=(e,n,r,o,a)=>{if(!n?.domElement||!r||!e)return;const i=(o=o??window.innerWidth)/(a=a??window.innerHeight);if("perspectivecamera"===e.type?.toLowerCase()){const t=e;t.aspect=i,t.updateProjectionMatrix()}else if("orthographiccamera"===e.type?.toLowerCase()){const t=e,n=a/o;t.top=10*n,t.bottom=10*-n,t.right=10,t.left=-10,t.updateProjectionMatrix()}n.setSize(o,a),r&&e&&n.render(t.toRaw(r),t.toRaw(e))},v=(e,t,n,r,o)=>{const a=e.value?.domElement;if(!a)throw new Error("missing container");const i=()=>{if("container"===o){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);b(t,n,r,e.width,e.height)}else b(t,n,r)};i();let s=new ResizeObserver((()=>{i()}));return a&&s.observe(a),{dispose(){a&&s.unobserve(a)}}},g=t.defineComponent({name:"LunchboxScene",setup:(e,{slots:n})=>()=>t.createVNode(t.resolveComponent("scene"),null,{default:()=>[n.default?.()]})}),x=t.defineComponent({name:"LunchboxEventHandlers",setup(){const e=Be(),n=Ee(),r=t.ref({x:1/0,y:1/0}),a=t.ref(!1);let i=[];const s=new o.Raycaster(new o.Vector3,new o.Vector3(0,0,-1)),c=({element:e,eventKeys:t,intersection:n})=>{e&&t.forEach((t=>{e.eventListeners[t]&&e.eventListeners[t].forEach((e=>{e({intersection:n})}))}))};Ce((e=>{if(!e?.domElement)return;const{domElement:t}=e;t.addEventListener("pointermove",(e=>{const o=(t.width??1)/n.dpr,a=(t.height??1)/n.dpr;r.value.x=e.offsetX/o*2-1,r.value.y=-e.offsetY/a*2+1})),t.addEventListener("pointerdown",(()=>a.value=!0)),t.addEventListener("pointerup",(()=>a.value=!1))}));const d=Re(),l=()=>{const t=d.value;if(!t)return;s.setFromCamera(r.value,t);const n=s.intersectObjects(e?.value.map((e=>e.instance))??[]);let o=[],a=[],l=[];o=i.map((e=>e.intersection)),n?.forEach((t=>{if(-1===i.findIndex((e=>e.intersection.object===t.object))){const n=e?.value.find((e=>e.instance?.uuid===t.object.uuid));n&&a.push({element:n,intersection:t})}else{const n=e?.value.find((e=>e.instance?.uuid===t.object.uuid));n&&l.push({element:n,intersection:t})}const n=o.findIndex((e=>e.object.uuid===t.object.uuid));-1!==n&&o.splice(n,1)}));const u=o.map((t=>({element:e?.value.find((e=>e.instance?.uuid===t.object.uuid)),intersection:t})));a.forEach((({element:e,intersection:t})=>{c({element:e,eventKeys:["onPointerEnter"],intersection:t})})),l.forEach((({element:e,intersection:t})=>{c({element:e,eventKeys:["onPointerOver","onPointerMove"],intersection:t})})),u.forEach((({element:e,intersection:t})=>{c({element:e,eventKeys:["onPointerLeave","onPointerOut"],intersection:t})})),i=[].concat(a,l)};oe(l);t.onBeforeUnmount((()=>ae(l)));const u=["onClick","onPointerDown","onPointerUp"];return t.watch(a,(e=>{l();const t=[];i.forEach((n=>{u.forEach((r=>{const o=n.element.uuid+r;!e||"onClick"!==r&&"onPointerDown"!==r?e||"onPointerUp"!==r||t.includes(o)||(n.element.eventListeners[r]?.forEach((e=>e({intersection:n.intersection}))),t.push(o)):t.includes(o)||(n.element.eventListeners[r]?.forEach((e=>e({intersection:n.intersection}))),t.push(o))}))}))})),()=>t.createVNode(t.resolveComponent("object3D"),null,null)}}),R=e=>({position:e,top:0,right:0,bottom:0,left:0,width:"100%",height:"100%",display:"block"}),w=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,n){const r=t.ref();let a=e.dpr??-1;const i=t.ref(),s=t.ref(),c=t.ref(),d=t.ref(),l=Ee(),u=Ne(),p=Le(),m=t.reactive({}),h=je();e.r3f&&o?.ColorManagement&&(o.ColorManagement.legacyMode=!1);const f=Be();t.onMounted((async()=>{if(!r.value&&!n.slots?.renderer?.()?.length)throw new Error("missing canvas");for(n.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 o.Color(e.background)),-1===a&&(a=window.devicePixelRatio),u?.({dpr:a});!s.value?.$el?.instance&&!s.value?.component?.ctx.$el?.instance;)await new Promise((e=>requestAnimationFrame(e)));for(;!d.value?.$el?.instance&&!d.value?.component?.ctx.$el?.instance;)await new Promise((e=>requestAnimationFrame(e)));const t=s.value?.$el?.instance??s.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(!n.slots?.renderer?.()?.length){v(i,y,t,f,e.sizePolicy),e.r3f&&(t.outputEncoding=o.sRGBEncoding,t.toneMapping=o.ACESFilmicToneMapping);const n={shadow:e.shadow};n?.shadow&&(t.shadowMap.enabled=!0,"object"==typeof n.shadow&&(t.shadowMap.type=n.shadow.type))}if(!p)throw new Error("error creating app");p.config.globalProperties.lunchbox.camera=y,p.config.globalProperties.lunchbox.renderer=t,p.config.globalProperties.lunchbox.scene=f;for(let e of h??[])e({app:p,camera:y,renderer:t,scene:f});ne({app:p,camera:y,renderer:t,scene:f,updateSource:e.updateSource})})),t.onBeforeUnmount((()=>{se(),de()}));const y="container"===e.sizePolicy?"static":"absolute",b="container"===e.sizePolicy?"static":"fixed",w=t.computed((()=>{const e=n.slots?.camera?.().find((e=>e.type?.name));return e||e}));return t.watch(w,(async(e,t)=>{e&&e?.props?.key!==t?.props?.key&&(c.value=e)}),{immediate:!0}),()=>t.createVNode(t.Fragment,null,[n.slots?.renderer?.()?.length?s.value=n.slots?.renderer?.()[0]:t.createVNode(t.Fragment,null,[t.createVNode("div",{class:"lunchbox-container",style:R(y),ref:i,"data-lunchbox":"true"},[t.createVNode("canvas",{ref:r,class:"lunchbox-canvas",style:R(b),"data-lunchbox":"true"},null)]),r.value?.domElement&&t.createVNode(t.resolveComponent("webGLRenderer"),t.mergeProps(e.rendererProperties??{},{ref:s,args:[{alpha:e.transparent,antialias:!0,canvas:r.value?.domElement,powerPreference:e.r3f?"high-performance":"default",...e.rendererArguments??{}}]}),null)]),n.slots?.scene?.()?.length?d.value=n.slots?.scene?.()[0]:t.createVNode(g,{ref:d},{default:()=>[n.slots?.default?.()]}),n.slots?.camera?.()?.length?c.value: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),f?.value.length&&t.createVNode(x,null,null)])}}),C={},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","raycaster","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:w},A=e=>t.defineComponent({inheritAttrs:!1,name:e,render(){return t.h(e,this.$attrs,this.$slots?.default?.()||[])}}),E=({app:e,...t})=>{Object.keys(t).forEach((n=>{e.component(n,A(n)),C[n]=t[n]}))};function N(e){if(!e.type)return null;const t=e.type[0].toUpperCase()+e.type.slice(1),n=t.replace(/Lunchbox$/,""),r=C[e.type]||o[t]||C[n]||o[n];if(!r)throw`${t} is not part of the THREE namespace! Did you forget to extend? import {extend} from 'lunchbox'; extend({app, YourComponent, ...})`;const a=(e.props.args??[]).map((t=>function({node:e,prop:t}){const n="string"==typeof t&&t.startsWith("$attachedArray"),r=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(r)&&n?r:[r]}({node:e,prop:t})));let i=[];a.forEach((e=>{i=i.concat(e)}));return new r(...i)}var L,j=new Uint8Array(16);function B(){if(!L&&!(L="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 L(j)}var M=/^(?:[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 G(e){return"string"==typeof e&&M.test(e)}for(var S=[],T=0;T<256;++T)S.push((T+256).toString(16).substr(1));function k(e,t,n){var r=(e=e||{}).random||(e.rng||B)();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=(S[e[t+0]]+S[e[t+1]]+S[e[t+2]]+S[e[t+3]]+"-"+S[e[t+4]]+S[e[t+5]]+"-"+S[e[t+6]]+S[e[t+7]]+"-"+S[e[t+8]]+S[e[t+9]]+"-"+S[e[t+10]]+S[e[t+11]]+S[e[t+12]]+S[e[t+13]]+S[e[t+14]]+S[e[t+15]]).toLowerCase();if(!G(n))throw TypeError("Stringified UUID is invalid");return n}(r)}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??k()}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.removeAsChildFromAnyParents(),this.parentNode=null}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(){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 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}(e.MiniDom||(e.MiniDom={}));const O="lunchbox-globals",$="lunchbox-updateGlobals",D="lunchbox-setCustomRender",F="lunchbox-clearCustomRender",K="lunchbox-beforeRender",I="lunchbox-onBeforeRender",V="lunchbox-offBeforeRender",U="lunchbox-afterRender",z="lunchbox-onAfterRender",H="lunchbox-offAfterRender",W="lunchbox-frameId",q="lunchbox-watchStopHandle",X="lunchbox-appRootNode",Y="lunchbox-appKey",_="lunchbox-renderer",J="lunchbox-scene",Q="lunchbox-camera",Z="lunchbox-interactables",ee="lunchbox-startCallback",te=e=>{"number"==typeof e.app.config.globalProperties.lunchbox.frameId&&cancelAnimationFrame(e.app.config.globalProperties.lunchbox.frameId),e.app.config.globalProperties.lunchbox.frameId=requestAnimationFrame((()=>ne({app:e.app,renderer:e.renderer,scene:e.scene,camera:e.camera,updateSource:e.updateSource})))},ne=e=>{e.updateSource?e.app.config.globalProperties.lunchbox.watchStopHandle||(e.app.config.globalProperties.lunchbox.watchStopHandle=t.watch(e.updateSource,(()=>{te(e)}),{deep:!0})):te(e);const{app:n,renderer:r,scene:o}=e;n.config.globalProperties.lunchbox.beforeRender.forEach((t=>{t?.(e)})),r&&o&&e.app.config.globalProperties.lunchbox.camera&&(n.customRender?n.customRender(e):r.render(t.toRaw(o),e.app.config.globalProperties.lunchbox.camera)),n.config.globalProperties.lunchbox.afterRender.forEach((t=>{t?.(e)}))},re=()=>({onBeforeRender:t.inject(I),offBeforeRender:t.inject(V)}),oe=(e,t=1/0)=>{re().onBeforeRender?.(e,t)},ae=e=>{re().offBeforeRender?.(e)},ie=()=>{const e=t.inject(W);return()=>{void 0!==e&&cancelAnimationFrame(e)}},se=()=>{ie()?.()},ce=()=>{const e=t.inject(q);return()=>e?.()},de=()=>{ce()?.()};function le({node:e,key:t,interactables:n,value:r}){if((e=>["onClick","onContextMenu","onDoubleClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove","onWheel"].includes(e))(t))return f({node:e,key:t,interactables:n,value:r});const o=t.replace(/-/g,"."),s=ue[o]||o;if(me.includes(t)||me.includes(s))return e;if(!d(e))return e;if("string"==typeof r&&r.startsWith("$attached")){const t=r.replace("$attached.","");r=a(e.attached,t,null)}const c=e.instance;if(!c)return e;let l;for(let e=0;e<pe.length&&!l;e++){const t=[pe[e],s].filter(Boolean).join(".");l=l=a(c,t)}if(l&&i(r)&&l?.setScalar)l.setScalar(r);else if(l&&l.set){const e=Array.isArray(r)?r:[r];c[s].set(...e)}else if("function"==typeof l)if("onbeforerender"===s.toLowerCase()||"onafterrender"===s.toLowerCase())c[s]=r;else{if(!Array.isArray(r))throw new Error('Arguments on a declarative method must be wrapped in an array.\nWorks:\n<example :methodCall="[256]" />\nDoesn\'t work:\n<example :methodCall="256" />');l.bind(e.instance)(...r)}else void 0!==a(c,s,void 0)?((e,t,n)=>{const r=Array.isArray(t)?t:t.match(/([^[.\]])+/g);r?.reduce(((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===r.length-1&&(e[t]=n),e[t])),e)})(c,s,""===r||r):console.log(`No property ${s} found on ${c}`);const u=c?.texture?.type||c?.type;if("string"==typeof u){const e=u.toLowerCase();switch(!0){case e.includes("material"):c.needsUpdate=!0;break;case e.includes("camera")&&c.updateProjectionMatrix:c.updateProjectionMatrix()}}return e}const ue={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"],fe=(e,t,n,r)=>{const o={type:e,props:r};if(c(o)){return p(o)}const a=h(o);return he.forEach((t=>{e.toLowerCase().endsWith(t)&&(a.props.attach=t)})),a},ye=(e,t,n)=>{if(!t)throw new Error("missing parent");if(t.insertBefore(e,n),"commentMeta"!==e.metaType&&"textMeta"!==e.metaType&&(c(e)&&(c(t)||l(t))&&t.domElement.appendChild(e.domElement),d(e))){let n=t.metaType;if("textMeta"===n||"commentMeta"===n){const e=t.getPath();for(let n=e.length-1;n>=0;n--)if("textMeta"!==e[n].metaType&&"commentMeta"!==e[n].metaType){t=e[n];break}}if(d(e)&&e.instance?.isObject3D&&d(t)&&t.instance?.isObject3D&&t.instance?.add?.(e.instance),e?.props?.attach&&d(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);be(e,t,e.props.attach,r)}else n.load(e.props.src,(n=>{be(e,t,e.props.attach,n)}),null,(e=>{throw new Error(e)}))}(e,t):be(e,t,e.props.attach)}e.props?.onAdded&&e.props.onAdded({instance:e.instance})}};function be(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 ve=e=>{if(!e)return;const t=[];e.walk((e=>(t.push(e),!0))),t.forEach((e=>{if(d(e)){e.instance?.removeFromParent?.();const t="scene"!==e.type&&e.instance?.dispose;t&&t.bind(e.instance)(),e.instance=null}e.drop()}))},ge=t.defineComponent({name:"BridgeComponent",props:{app:{type:Object},root:{type:Object},appSetup:{type:Function,default:e=>e}},setup(e,n){if(!e.app&&!e.root)throw new Error("app or root required as <bridge> prop");const r=t.ref();let o=e.appSetup(e.app??Me(e.root,n.attrs));const a=t.getCurrentInstance()?.provides??{};return Object.keys(a).forEach((e=>{o?.provide(e,t.inject(e))})),t.onMounted((()=>{o?.mount(r.value)})),t.onUnmounted((()=>{o?.unmount(),o=null})),()=>t.createVNode("div",{ref:r},null)}}),xe={install(e){e.component("lunchbox",ge)}},Re=()=>t.inject(Q),we=()=>t.inject(_),Ce=e=>{const n=we();if(n.value)return void e(n.value);let r=null;r=t.watch(we(),(t=>{t&&(e(t),r?.())}),{immediate:!0})},Pe=()=>t.inject(J),Ae=()=>({setCustomRender:t.inject(D),clearCustomRender:t.inject(F)}),Ee=()=>t.inject(O),Ne=()=>t.inject($),Le=()=>t.inject(Y),je=()=>t.inject(ee),Be=()=>t.inject(Z),Me=(n,r={})=>{const{nodeOps:o,interactables:a}=(()=>{const e=t.ref([]);return{nodeOps:{createElement:fe,createText:e=>m({text:e}),createComment:e=>u({text:e}),insert:ye,nextSibling:e=>e.nextSibling||null,parentNode:e=>e.parentNode||null,patchProp(t,n,r,o){c(t)?"style"===n?Object.keys(o).forEach((e=>{t.domElement.style[e]=o[e]})):t.domElement.setAttribute(n,o):l(t)||n.startsWith("$")||le({node:t,key:n,interactables:e,value:o})},remove:ve,setElementText(){},setText(){}},interactables:e}})(),i=t.createRenderer(o).createApp(n,r);i.provide(Z,a),Object.keys(P).forEach((e=>{i?.component(e,P[e])})),i.provide(D,(e=>{i.setCustomRender(e)})),i.provide(F,(()=>{i.clearCustomRender()}));const s=[];i.provide(K,s),i.provide(I,((e,t=1/0)=>{t===1/0?s.push(e):s.splice(t,0,e)})),i.provide(V,(e=>{if(isFinite(e))s.splice(e,1);else{const t=s.findIndex((t=>t==e));-1!==t&&s.splice(t,1)}}));const d=[];i.provide(U,d),i.provide(z,((e,t=1/0)=>{t===1/0?d.push(e):d.splice(t,0,e)})),i.provide(H,(e=>{if(isFinite(e))d.splice(e,1);else{const t=d.findIndex((t=>t==e));-1!==t&&d.splice(t,1)}})),i.config.globalProperties.lunchbox=t.reactive({afterRender:d,beforeRender:s,camera:null,dpr:1,frameId:-1,renderer:null,scene:null,watchStopHandle:null}),i.provide(O,i.config.globalProperties.lunchbox),i.provide($,(e=>{Object.keys(e).forEach((t=>{const n=t;i.config.globalProperties.lunchbox[n]=e[n]}))})),i.provide(W,i.config.globalProperties.lunchbox.frameId),i.provide(q,i.config.globalProperties.lunchbox.watchStopHandle);const{mount:p}=i;i.mount=(t,...n)=>{const r="string"==typeof t?document.querySelector(t):t,o=new e.MiniDom.RendererRootNode({domElement:r,isLunchboxRootNode:!0,name:"root",metaType:"rootMeta",type:"root",uuid:"LUNCHBOX_ROOT"});i.rootNode=o,i.provide(X,o);return p(o,...n)},i.extend=e=>(E({app:i,...e}),i);return i.provide(ee,[]),i.setCustomRender=e=>{i&&(i.customRender=e)},i.clearCustomRender=()=>{i&&(i.customRender=null)},i.provide(Y,i),i.provide(_,t.computed((()=>i.config.globalProperties.lunchbox.renderer))),i.provide(J,t.computed((()=>i.config.globalProperties.lunchbox.scene))),i.provide(Q,t.computed((()=>i.config.globalProperties.lunchbox.camera))),i._props,i};e.addEventListener=f,e.afterRenderKey=U,e.appCameraKey=Q,e.appKey=Y,e.appRenderersKey=_,e.appRootNodeKey=X,e.appSceneKey=J,e.beforeRenderKey=K,e.cancelUpdate=se,e.cancelUpdateSource=de,e.clearCustomRender=()=>{Ae()?.clearCustomRender?.()},e.clearCustomRenderKey=F,e.createApp=Me,e.createCommentNode=u,e.createDomNode=p,e.createNode=h,e.createTextNode=m,e.extend=E,e.find=function(e){return e=t.isRef(e)?e.value:e,d(e)?e?.instance:s(e)?e?.$el?.instance:t.isVNode(e)?e.el?.instance:null},e.frameIdKey=W,e.getInstance=(e,n=!0)=>t.computed((()=>{const r=e.value?.$el?.instance??e.value?.instance??null;return r&&n?t.toRaw(r):r})),e.globalsInjectionKey=O,e.instantiateThreeObject=N,e.isMinidomNode=function(e){return"RendererNode"===e?.minidomType},e.lunchbox=xe,e.lunchboxInteractables=Z,e.nestedPropertiesToCheck=pe,e.offAfterRender=e=>{re().offBeforeRender?.(e)},e.offAfterRenderKey=H,e.offBeforeRender=ae,e.offBeforeRenderKey=V,e.onAfterRender=(e,t=1/0)=>{re().onBeforeRender?.(e,t)},e.onAfterRenderKey=z,e.onBeforeRender=oe,e.onBeforeRenderKey=I,e.onCameraReady=e=>{const n=Re();if(n.value)return void e(n.value);let r=null;r=t.watch(Re(),(t=>{t&&(e(t),r?.())}))},e.onRendererReady=Ce,e.onSceneReady=e=>{const n=Pe();if(n.value)return void e(n.value);let r=null;r=t.watch(Pe(),(t=>{t&&(e(t),r?.())}),{immediate:!0})},e.onStart=(e,t=1/0)=>{const n=je();t===1/0?n?.push(e):n?.splice(t,0,e)},e.setCustomRender=e=>{Ae()?.setCustomRender?.(e)},e.setCustomRenderKey=D,e.startCallbackKey=ee,e.update=ne,e.updateGlobals=e=>{Ne()?.(e)},e.updateGlobalsInjectionKey=$,e.updateObjectProp=le,e.useAfterRender=()=>({onAfterRender:t.inject(I),offAfterRender:t.inject(V)}),e.useApp=Le,e.useBeforeRender=re,e.useCamera=Re,e.useCancelUpdate=ie,e.useCancelUpdateSource=ce,e.useCustomRender=Ae,e.useGlobals=Ee,e.useLunchboxInteractables=Be,e.useRenderer=we,e.useScene=Pe,e.useStartCallbacks=je,e.useUpdateGlobals=Ne,e.watchStopHandleKey=q}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("vue"),require("three")):"function"==typeof define&&define.amd?define(["exports","vue","three"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Lunchbox={},e.vue,e.three)}(this,(function(e,t,n){"use strict";function r(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 o=r(n);const a=(e,t,n)=>{if(!t)return;const r=(Array.isArray(t)?t:t.match(/([^[.\]])+/g))?.reduce(((e,t)=>e&&e[t]),e);return void 0===r?n:r},i=(()=>{const e=Object.prototype.toString;return function(t){return"number"==typeof t||function(e){return!!e&&"object"==typeof e}(t)&&"[object Number]"==e.call(t)}})(),s=e=>e?.$el&&e?.$el?.hasOwnProperty?.("instance"),c=e=>"domMeta"===e?.metaType||e?.props?.["data-lunchbox"],d=e=>"standardMeta"===e?.metaType,l=e=>e.isLunchboxRootNode;function u(t={}){const n={text:t.text??""};return new e.MiniDom.RendererCommentNode({...n,...t,metaType:"commentMeta"})}function p(t={}){const n={domElement:document.createElement(t.type??"")};return new e.MiniDom.RendererDomNode({...n,...t,metaType:"domMeta"})}function m(t={}){const n={text:t.text??""};return new e.MiniDom.RendererTextNode({...t,...n,metaType:"textMeta"})}function h(t={},n={}){const r={attached:t.attached??[],attachedArray:t.attachedArray??{},instance:t.instance??null},o=new e.MiniDom.RendererStandardNode({...t,...r,metaType:"standardMeta"});return!o.type||l(o)||o.instance||(o.instance=N({...o,props:{...o.props,...n}})),o}function f({node:e,key:t,interactables:n,value:r}){return e.eventListeners[t]||(e.eventListeners[t]=[]),e.eventListenerRemoveFunctions[t]||(e.eventListenerRemoveFunctions[t]=[]),e.eventListeners[t].push(r),y.includes(t)&&e.instance&&!n.value.includes(e)&&(n.value.push(e),e.eventListenerRemoveFunctions[t].push((()=>{const t=n.value.indexOf(e);-1!==t&&n.value.splice(t,1)}))),e}const y=["onClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove"],b=(e,n,r,o,a)=>{if(!n?.domElement||!r||!e)return;const i=(o=o??window.innerWidth)/(a=a??window.innerHeight);if("perspectivecamera"===e.type?.toLowerCase()){const t=e;t.aspect=i,t.updateProjectionMatrix()}else if("orthographiccamera"===e.type?.toLowerCase()){const t=e,n=a/o;t.top=10*n,t.bottom=10*-n,t.right=10,t.left=-10,t.updateProjectionMatrix()}n.setSize(o,a),r&&e&&n.render(t.toRaw(r),t.toRaw(e))},v=(e,t,n,r,o)=>{const a=e.value?.domElement;if(!a)throw new Error("missing container");const i=()=>{if("container"===o){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);b(t,n,r,e.width,e.height)}else b(t,n,r)};i();let s=new ResizeObserver((()=>{i()}));return a&&s.observe(a),{dispose(){a&&s.unobserve(a)}}},g=t.defineComponent({name:"LunchboxScene",setup:(e,{slots:n})=>()=>t.createVNode(t.resolveComponent("scene"),null,{default:()=>[n.default?.()]})}),x=t.defineComponent({name:"LunchboxEventHandlers",setup(){const e=Be(),n=Ee(),r=t.ref({x:1/0,y:1/0}),a=t.ref(!1);let i=[];const s=new o.Raycaster(new o.Vector3,new o.Vector3(0,0,-1)),c=({element:e,eventKeys:t,intersection:n})=>{e&&t.forEach((t=>{e.eventListeners[t]&&e.eventListeners[t].forEach((e=>{e({intersection:n})}))}))};Ce((e=>{if(!e?.domElement)return;const{domElement:t}=e;t.addEventListener("pointermove",(e=>{const o=(t.width??1)/n.dpr,a=(t.height??1)/n.dpr;r.value.x=e.offsetX/o*2-1,r.value.y=-e.offsetY/a*2+1})),t.addEventListener("pointerdown",(()=>a.value=!0)),t.addEventListener("pointerup",(()=>a.value=!1))}));const d=Re(),l=()=>{const t=d.value;if(!t)return;s.setFromCamera(r.value,t);const n=s.intersectObjects(e?.value.map((e=>e.instance))??[]);let o=[],a=[],l=[];o=i.map((e=>e.intersection)),n?.forEach((t=>{if(-1===i.findIndex((e=>e.intersection.object===t.object))){const n=e?.value.find((e=>e.instance?.uuid===t.object.uuid));n&&a.push({element:n,intersection:t})}else{const n=e?.value.find((e=>e.instance?.uuid===t.object.uuid));n&&l.push({element:n,intersection:t})}const n=o.findIndex((e=>e.object.uuid===t.object.uuid));-1!==n&&o.splice(n,1)}));const u=o.map((t=>({element:e?.value.find((e=>e.instance?.uuid===t.object.uuid)),intersection:t})));a.forEach((({element:e,intersection:t})=>{c({element:e,eventKeys:["onPointerEnter"],intersection:t})})),l.forEach((({element:e,intersection:t})=>{c({element:e,eventKeys:["onPointerOver","onPointerMove"],intersection:t})})),u.forEach((({element:e,intersection:t})=>{c({element:e,eventKeys:["onPointerLeave","onPointerOut"],intersection:t})})),i=[].concat(a,l)};oe(l);t.onBeforeUnmount((()=>ae(l)));const u=["onClick","onPointerDown","onPointerUp"];return t.watch(a,(e=>{l();const t=[];i.forEach((n=>{u.forEach((r=>{const o=n.element.uuid+r;!e||"onClick"!==r&&"onPointerDown"!==r?e||"onPointerUp"!==r||t.includes(o)||(n.element.eventListeners[r]?.forEach((e=>e({intersection:n.intersection}))),t.push(o)):t.includes(o)||(n.element.eventListeners[r]?.forEach((e=>e({intersection:n.intersection}))),t.push(o))}))}))})),()=>t.createVNode(t.resolveComponent("object3D"),null,null)}}),R=e=>({position:e,top:0,right:0,bottom:0,left:0,width:"100%",height:"100%",display:"block"}),w=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,n){const r=t.ref();let a=e.dpr??-1;const i=t.ref(),s=t.ref(),c=t.ref(),d=t.ref(),l=Ee(),u=Ne(),p=Le(),m=t.reactive({}),h=je();e.r3f&&o?.ColorManagement&&(o.ColorManagement.legacyMode=!1);const f=Be();t.onMounted((async()=>{if(!r.value&&!n.slots?.renderer?.()?.length)throw new Error("missing canvas");for(n.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 o.Color(e.background)),-1===a&&(a=window.devicePixelRatio),u?.({dpr:a});!s.value?.$el?.instance&&!s.value?.component?.ctx.$el?.instance;)await new Promise((e=>requestAnimationFrame(e)));for(;!d.value?.$el?.instance&&!d.value?.component?.ctx.$el?.instance;)await new Promise((e=>requestAnimationFrame(e)));const t=s.value?.$el?.instance??s.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(!n.slots?.renderer?.()?.length){v(i,y,t,f,e.sizePolicy),e.r3f&&(t.outputEncoding=o.sRGBEncoding,t.toneMapping=o.ACESFilmicToneMapping);const n={shadow:e.shadow};n?.shadow&&(t.shadowMap.enabled=!0,"object"==typeof n.shadow&&(t.shadowMap.type=n.shadow.type))}if(!p)throw new Error("error creating app");p.config.globalProperties.lunchbox.camera=y,p.config.globalProperties.lunchbox.renderer=t,p.config.globalProperties.lunchbox.scene=f;for(let e of h??[])e({app:p,camera:y,renderer:t,scene:f});ne({app:p,camera:y,renderer:t,scene:f,updateSource:e.updateSource})})),t.onBeforeUnmount((()=>{se(),de()}));const y="container"===e.sizePolicy?"static":"absolute",b="container"===e.sizePolicy?"static":"fixed",w=t.computed((()=>{const e=n.slots?.camera?.().find((e=>e.type?.name));return e||e}));return t.watch(w,(async(e,t)=>{e&&e?.props?.key!==t?.props?.key&&(c.value=e)}),{immediate:!0}),()=>t.createVNode(t.Fragment,null,[n.slots?.renderer?.()?.length?s.value=n.slots?.renderer?.()[0]:t.createVNode(t.Fragment,null,[t.createVNode("div",{class:"lunchbox-container",style:R(y),ref:i,"data-lunchbox":"true"},[t.createVNode("canvas",{ref:r,class:"lunchbox-canvas",style:R(b),"data-lunchbox":"true"},null)]),r.value?.domElement&&t.createVNode(t.resolveComponent("webGLRenderer"),t.mergeProps(e.rendererProperties??{},{ref:s,args:[{alpha:e.transparent,antialias:!0,canvas:r.value?.domElement,powerPreference:e.r3f?"high-performance":"default",...e.rendererArguments??{}}]}),null)]),n.slots?.scene?.()?.length?d.value=n.slots?.scene?.()[0]:t.createVNode(g,{ref:d},{default:()=>[n.slots?.default?.()]}),n.slots?.camera?.()?.length?c.value: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),f?.value.length&&t.createVNode(x,null,null)])}}),C={},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","raycaster","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:w},A=e=>t.defineComponent({inheritAttrs:!1,name:e,render(){return t.h(e,this.$attrs,this.$slots?.default?.()||[])}}),E=({app:e,...t})=>{Object.keys(t).forEach((n=>{e.component(n,A(n)),C[n]=t[n]}))};function N(e){if(!e.type)return null;const t=e.type[0].toUpperCase()+e.type.slice(1),n=t.replace(/Lunchbox$/,""),r=C[e.type]||o[t]||C[n]||o[n];if(!r)throw`${t} is not part of the THREE namespace! Did you forget to extend? import {extend} from 'lunchbox'; extend({app, YourComponent, ...})`;const a=(e.props.args??[]).map((t=>function({node:e,prop:t}){const n="string"==typeof t&&t.startsWith("$attachedArray"),r=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(r)&&n?r:[r]}({node:e,prop:t})));let i=[];a.forEach((e=>{i=i.concat(e)}));return new r(...i)}var L,j=new Uint8Array(16);function B(){if(!L&&!(L="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 L(j)}var M=/^(?:[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 G(e){return"string"==typeof e&&M.test(e)}for(var S=[],T=0;T<256;++T)S.push((T+256).toString(16).substr(1));function k(e,t,n){var r=(e=e||{}).random||(e.rng||B)();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=(S[e[t+0]]+S[e[t+1]]+S[e[t+2]]+S[e[t+3]]+"-"+S[e[t+4]]+S[e[t+5]]+"-"+S[e[t+6]]+S[e[t+7]]+"-"+S[e[t+8]]+S[e[t+9]]+"-"+S[e[t+10]]+S[e[t+11]]+S[e[t+12]]+S[e[t+13]]+S[e[t+14]]+S[e[t+15]]).toLowerCase();if(!G(n))throw TypeError("Stringified UUID is invalid");return n}(r)}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??k()}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.removeAsChildFromAnyParents(),this.parentNode=null}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(){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 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}(e.MiniDom||(e.MiniDom={}));const O="lunchbox-globals",$="lunchbox-updateGlobals",D="lunchbox-setCustomRender",F="lunchbox-clearCustomRender",K="lunchbox-beforeRender",I="lunchbox-onBeforeRender",V="lunchbox-offBeforeRender",U="lunchbox-afterRender",z="lunchbox-onAfterRender",H="lunchbox-offAfterRender",W="lunchbox-frameId",q="lunchbox-watchStopHandle",X="lunchbox-appRootNode",Y="lunchbox-appKey",_="lunchbox-renderer",J="lunchbox-scene",Q="lunchbox-camera",Z="lunchbox-interactables",ee="lunchbox-startCallback",te=e=>{"number"==typeof e.app.config.globalProperties.lunchbox.frameId&&cancelAnimationFrame(e.app.config.globalProperties.lunchbox.frameId),e.app.config.globalProperties.lunchbox.frameId=requestAnimationFrame((()=>ne({app:e.app,renderer:e.renderer,scene:e.scene,camera:e.camera,updateSource:e.updateSource})))},ne=e=>{e.updateSource?e.app.config.globalProperties.lunchbox.watchStopHandle||(e.app.config.globalProperties.lunchbox.watchStopHandle=t.watch(e.updateSource,(()=>{te(e)}),{deep:!0})):te(e);const{app:n,renderer:r,scene:o}=e;n.config.globalProperties.lunchbox.beforeRender.forEach((t=>{t?.(e)})),r&&o&&e.app.config.globalProperties.lunchbox.camera&&(n.customRender?n.customRender(e):r.render(t.toRaw(o),e.app.config.globalProperties.lunchbox.camera)),n.config.globalProperties.lunchbox.afterRender.forEach((t=>{t?.(e)}))},re=()=>({onBeforeRender:t.inject(I),offBeforeRender:t.inject(V)}),oe=(e,t=1/0)=>{re().onBeforeRender?.(e,t)},ae=e=>{re().offBeforeRender?.(e)},ie=()=>{const e=t.inject(W);return()=>{void 0!==e&&cancelAnimationFrame(e)}},se=()=>{ie()?.()},ce=()=>{const e=t.inject(q);return()=>e?.()},de=()=>{ce()?.()};function le({node:e,key:t,interactables:n,value:r}){if((e=>["onClick","onContextMenu","onDoubleClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove","onWheel"].includes(e))(t))return f({node:e,key:t,interactables:n,value:r});const o=t.replace(/-/g,"."),s=ue[o]||o;if(me.includes(t)||me.includes(s))return e;if(!d(e))return e;if("string"==typeof r&&r.startsWith("$attached")){const t=r.replace("$attached.","");r=a(e.attached,t,null)}const c=e.instance;if(!c)return e;let l;for(let e=0;e<pe.length&&!l;e++){const t=[pe[e],s].filter(Boolean).join(".");l=l=a(c,t)}if(l&&i(r)&&l?.setScalar)l.setScalar(r);else if(l&&l.set){const e=Array.isArray(r)?r:[r];c[s].set(...e)}else if("function"==typeof l)if("onbeforerender"===s.toLowerCase()||"onafterrender"===s.toLowerCase())c[s]=r;else{if(!Array.isArray(r))throw new Error('Arguments on a declarative method must be wrapped in an array.\nWorks:\n<example :methodCall="[256]" />\nDoesn\'t work:\n<example :methodCall="256" />');l.bind(e.instance)(...r)}else void 0!==a(c,s,void 0)?((e,t,n)=>{const r=Array.isArray(t)?t:t.match(/([^[.\]])+/g);r?.reduce(((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===r.length-1&&(e[t]=n),e[t])),e)})(c,s,""===r||r):console.log(`No property ${s} found on ${c}`);const u=c?.texture?.type||c?.type;if("string"==typeof u){const e=u.toLowerCase();switch(!0){case e.includes("material"):c.needsUpdate=!0;break;case e.includes("camera")&&c.updateProjectionMatrix:c.updateProjectionMatrix()}}return e}const ue={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"],fe=(e,t,n,r)=>{const o={type:e,props:r};if(c(o)){return p(o)}const a=h(o);return he.forEach((t=>{e.toLowerCase().endsWith(t)&&(a.props.attach=t)})),a},ye=(e,t,n)=>{if(!t)throw new Error("missing parent");if(t.insertBefore(e,n),"commentMeta"!==e.metaType&&"textMeta"!==e.metaType&&(c(e)&&(c(t)||l(t))&&t.domElement.appendChild(e.domElement),d(e))){let n=t.metaType;if("textMeta"===n||"commentMeta"===n){const e=t.getPath();for(let n=e.length-1;n>=0;n--)if("textMeta"!==e[n].metaType&&"commentMeta"!==e[n].metaType){t=e[n];break}}if(d(e)&&e.instance?.isObject3D&&d(t)&&t.instance?.isObject3D&&t.instance?.add?.(e.instance),e?.props?.attach&&d(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);be(e,t,e.props.attach,r)}else n.load(e.props.src,(n=>{be(e,t,e.props.attach,n)}),null,(e=>{throw new Error(e)}))}(e,t):be(e,t,e.props.attach)}e.props?.onAdded&&e.props.onAdded({instance:e.instance})}};function be(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 ve=e=>{if(!e)return;const t=[];e.walk((e=>(t.push(e),!0))),t.forEach((e=>{if(d(e)){e.instance?.removeFromParent?.();const t="scene"!==e.type&&e.instance?.dispose;t&&t.bind(e.instance)(),e.instance=null}e.drop()}))},ge=t.defineComponent({name:"BridgeComponent",props:{app:{type:Object},root:{type:Object},appSetup:{type:Function,default:e=>e}},setup(e,n){if(!e.app&&!e.root)throw new Error("app or root required as <bridge> prop");const r=t.ref();let o=e.appSetup(e.app??Me(e.root,n.attrs));const a=t.getCurrentInstance()?.provides??{};return Object.keys(a).forEach((e=>{o?.provide(e,t.inject(e))})),t.onMounted((()=>{o?.mount(r.value)})),t.onUnmounted((()=>{o?.unmount(),o=null})),()=>t.createVNode("div",{ref:r},null)}}),xe={install(e){e.component("lunchbox",ge)}},Re=()=>t.inject(Q),we=()=>t.inject(_),Ce=e=>{const n=we();if(n.value)return void e(n.value);let r=null;r=t.watch(we(),(t=>{t&&(e(t),r?.())}),{immediate:!0})},Pe=()=>t.inject(J),Ae=()=>({setCustomRender:t.inject(D),clearCustomRender:t.inject(F)}),Ee=()=>t.inject(O),Ne=()=>t.inject($),Le=()=>t.inject(Y),je=()=>t.inject(ee),Be=()=>t.inject(Z),Me=(n,r={})=>{console.log("HERE");const{nodeOps:o,interactables:a}=(()=>{const e=t.ref([]);return{nodeOps:{createElement:fe,createText:e=>m({text:e}),createComment:e=>u({text:e}),insert:ye,nextSibling:e=>e.nextSibling||null,parentNode:e=>e.parentNode||null,patchProp(t,n,r,o){c(t)?"style"===n?Object.keys(o).forEach((e=>{t.domElement.style[e]=o[e]})):t.domElement.setAttribute(n,o):l(t)||n.startsWith("$")||le({node:t,key:n,interactables:e,value:o})},remove:ve,setElementText(){},setText(){}},interactables:e}})(),i=t.createRenderer(o).createApp(n,r);i.provide(Z,a),Object.keys(P).forEach((e=>{i?.component(e,P[e])})),i.provide(D,(e=>{i.setCustomRender(e)})),i.provide(F,(()=>{i.clearCustomRender()}));const s=[];i.provide(K,s),i.provide(I,((e,t=1/0)=>{t===1/0?s.push(e):s.splice(t,0,e)})),i.provide(V,(e=>{if(isFinite(e))s.splice(e,1);else{const t=s.findIndex((t=>t==e));-1!==t&&s.splice(t,1)}}));const d=[];i.provide(U,d),i.provide(z,((e,t=1/0)=>{t===1/0?d.push(e):d.splice(t,0,e)})),i.provide(H,(e=>{if(isFinite(e))d.splice(e,1);else{const t=d.findIndex((t=>t==e));-1!==t&&d.splice(t,1)}})),i.config.globalProperties.lunchbox=t.reactive({afterRender:d,beforeRender:s,camera:null,dpr:1,frameId:-1,renderer:null,scene:null,watchStopHandle:null}),i.provide(O,i.config.globalProperties.lunchbox),i.provide($,(e=>{Object.keys(e).forEach((t=>{const n=t;i.config.globalProperties.lunchbox[n]=e[n]}))})),i.provide(W,i.config.globalProperties.lunchbox.frameId),i.provide(q,i.config.globalProperties.lunchbox.watchStopHandle);const{mount:p}=i;i.mount=(t,...n)=>{const r="string"==typeof t?document.querySelector(t):t,o=new e.MiniDom.RendererRootNode({domElement:r,isLunchboxRootNode:!0,name:"root",metaType:"rootMeta",type:"root",uuid:"LUNCHBOX_ROOT"});i.rootNode=o,i.provide(X,o);return p(o,...n)},i.extend=e=>(E({app:i,...e}),i);return i.provide(ee,[]),i.setCustomRender=e=>{i&&(i.customRender=e)},i.clearCustomRender=()=>{i&&(i.customRender=null)},i.provide(Y,i),i.provide(_,t.computed((()=>i.config.globalProperties.lunchbox.renderer))),i.provide(J,t.computed((()=>i.config.globalProperties.lunchbox.scene))),i.provide(Q,t.computed((()=>i.config.globalProperties.lunchbox.camera))),i._props,i};e.addEventListener=f,e.afterRenderKey=U,e.appCameraKey=Q,e.appKey=Y,e.appRenderersKey=_,e.appRootNodeKey=X,e.appSceneKey=J,e.beforeRenderKey=K,e.cancelUpdate=se,e.cancelUpdateSource=de,e.clearCustomRender=()=>{Ae()?.clearCustomRender?.()},e.clearCustomRenderKey=F,e.createApp=Me,e.createCommentNode=u,e.createDomNode=p,e.createNode=h,e.createTextNode=m,e.extend=E,e.find=function(e){return e=t.isRef(e)?e.value:e,d(e)?e?.instance:s(e)?e?.$el?.instance:t.isVNode(e)?e.el?.instance:null},e.frameIdKey=W,e.getInstance=(e,n=!0)=>t.computed((()=>{const r=e.value?.$el?.instance??e.value?.instance??null;return r&&n?t.toRaw(r):r})),e.globalsInjectionKey=O,e.instantiateThreeObject=N,e.isMinidomNode=function(e){return"RendererNode"===e?.minidomType},e.lunchbox=xe,e.lunchboxInteractables=Z,e.nestedPropertiesToCheck=pe,e.offAfterRender=e=>{re().offBeforeRender?.(e)},e.offAfterRenderKey=H,e.offBeforeRender=ae,e.offBeforeRenderKey=V,e.onAfterRender=(e,t=1/0)=>{re().onBeforeRender?.(e,t)},e.onAfterRenderKey=z,e.onBeforeRender=oe,e.onBeforeRenderKey=I,e.onCameraReady=e=>{const n=Re();if(n.value)return void e(n.value);let r=null;r=t.watch(Re(),(t=>{t&&(e(t),r?.())}))},e.onRendererReady=Ce,e.onSceneReady=e=>{const n=Pe();if(n.value)return void e(n.value);let r=null;r=t.watch(Pe(),(t=>{t&&(e(t),r?.())}),{immediate:!0})},e.onStart=(e,t=1/0)=>{const n=je();t===1/0?n?.push(e):n?.splice(t,0,e)},e.setCustomRender=e=>{Ae()?.setCustomRender?.(e)},e.setCustomRenderKey=D,e.startCallbackKey=ee,e.update=ne,e.updateGlobals=e=>{Ne()?.(e)},e.updateGlobalsInjectionKey=$,e.updateObjectProp=le,e.useAfterRender=()=>({onAfterRender:t.inject(I),offAfterRender:t.inject(V)}),e.useApp=Le,e.useBeforeRender=re,e.useCamera=Re,e.useCancelUpdate=ie,e.useCancelUpdateSource=ce,e.useCustomRender=Ae,e.useGlobals=Ee,e.useLunchboxInteractables=Be,e.useRenderer=we,e.useScene=Pe,e.useStartCallbacks=je,e.useUpdateGlobals=Ne,e.watchStopHandleKey=q}));
|
|
@@ -1770,6 +1770,7 @@ const getInstance = (target, raw = true) => computed(() => {
|
|
|
1770
1770
|
// CREATE APP
|
|
1771
1771
|
// ====================
|
|
1772
1772
|
const createApp = (root, rootProps = {}) => {
|
|
1773
|
+
console.log("HERE");
|
|
1773
1774
|
const {
|
|
1774
1775
|
nodeOps,
|
|
1775
1776
|
interactables
|
|
@@ -1869,15 +1870,15 @@ const createApp = (root, rootProps = {}) => {
|
|
|
1869
1870
|
} = app;
|
|
1870
1871
|
app.mount = (root, ...args) => {
|
|
1871
1872
|
// find DOM element to use as app root
|
|
1872
|
-
const domElement = typeof root ===
|
|
1873
|
+
const domElement = typeof root === "string" ? document.querySelector(root) : root;
|
|
1873
1874
|
// create or find root node
|
|
1874
1875
|
const rootNode = new MiniDom.RendererRootNode({
|
|
1875
1876
|
domElement,
|
|
1876
1877
|
isLunchboxRootNode: true,
|
|
1877
|
-
name:
|
|
1878
|
-
metaType:
|
|
1879
|
-
type:
|
|
1880
|
-
uuid:
|
|
1878
|
+
name: "root",
|
|
1879
|
+
metaType: "rootMeta",
|
|
1880
|
+
type: "root",
|
|
1881
|
+
uuid: "LUNCHBOX_ROOT"
|
|
1881
1882
|
});
|
|
1882
1883
|
app.rootNode = rootNode;
|
|
1883
1884
|
app.provide(appRootNodeKey, rootNode);
|
package/dist/lunchboxjs.umd.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "../src/index"
|
|
1
|
+
export * from "../src/index";
|
package/package.json
CHANGED
|
@@ -1,83 +1,38 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"lunchboxjs-plugins": "workspace:*",
|
|
40
|
-
"nice-color-palettes": "3.0.0",
|
|
41
|
-
"prompt": "1.3.0",
|
|
42
|
-
"prompts": "2.4.2",
|
|
43
|
-
"rollup": "3.2.5",
|
|
44
|
-
"rollup-plugin-delete": "2.0.0",
|
|
45
|
-
"rollup-plugin-jsx": "1.0.3",
|
|
46
|
-
"rollup-plugin-terser": "7.0.2",
|
|
47
|
-
"three": "0.141.0",
|
|
48
|
-
"typescript": "^4.4.3",
|
|
49
|
-
"vite": "3.0.4",
|
|
50
|
-
"vite-plugin-glsl": "0.0.5",
|
|
51
|
-
"vue-jsx-factory": "0.3.0",
|
|
52
|
-
"vue-tsc": "^0.3.0"
|
|
53
|
-
},
|
|
54
|
-
"peerDependencies": {
|
|
55
|
-
"three": "*"
|
|
56
|
-
},
|
|
57
|
-
"files": [
|
|
58
|
-
"dist",
|
|
59
|
-
"extras",
|
|
60
|
-
"package.json",
|
|
61
|
-
"README.md",
|
|
62
|
-
"src",
|
|
63
|
-
"types.d.ts"
|
|
64
|
-
],
|
|
65
|
-
"main": "./dist/lunchboxjs.js",
|
|
66
|
-
"module": "./dist/lunchboxjs.module.js",
|
|
67
|
-
"types": "dist/lunchboxjs.es.d.ts",
|
|
68
|
-
"directories": {
|
|
69
|
-
"doc": "docs"
|
|
70
|
-
},
|
|
71
|
-
"repository": {
|
|
72
|
-
"type": "git",
|
|
73
|
-
"url": "git+https://github.com/breakfast-studio/lunchboxjs.git"
|
|
74
|
-
},
|
|
75
|
-
"keywords": [],
|
|
76
|
-
"author": "",
|
|
77
|
-
"license": "ISC",
|
|
78
|
-
"bugs": {
|
|
79
|
-
"url": "https://github.com/breakfast-studio/lunchboxjs/issues"
|
|
80
|
-
},
|
|
81
|
-
"homepage": "https://github.com/breakfast-studio/lunchboxjs#readme",
|
|
82
|
-
"description": ""
|
|
83
|
-
}
|
|
2
|
+
"name": "lunchboxjs",
|
|
3
|
+
"files": [
|
|
4
|
+
"dist"
|
|
5
|
+
],
|
|
6
|
+
"main": "./dist/lunchboxjs.umd.cjs",
|
|
7
|
+
"module": "./dist/lunchboxjs.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/lunchboxjs.js",
|
|
11
|
+
"require": "./dist/lunchboxjs.umd.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"version": "2.0.0-beta.0",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"types": "./types.ts",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"dev": "vite",
|
|
19
|
+
"build": "tsc && vite build && npm run dts",
|
|
20
|
+
"dts": "echo \"export * from '../src/';\" > ./dist/lunchboxjs.d.ts",
|
|
21
|
+
"preview": "vite preview",
|
|
22
|
+
"cy:open": "cypress open",
|
|
23
|
+
"test": "cypress run"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"json5": "^2.2.3",
|
|
27
|
+
"lit": "^3.1.2",
|
|
28
|
+
"three": "^0.164.1"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/mocha": "^10.0.6",
|
|
32
|
+
"@types/node": "^20.12.7",
|
|
33
|
+
"@types/three": "^0.164.0",
|
|
34
|
+
"cypress": "^13.9.0",
|
|
35
|
+
"typescript": "^5.2.2",
|
|
36
|
+
"vite": "^5.2.0"
|
|
37
|
+
}
|
|
38
|
+
}
|
package/LICENSE.md
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
Copyright 2022 Breakfast Studio, LLC
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
-
|
|
5
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
-
|
|
7
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
Custom Vue 3 renderer for ThreeJS.
|
|
2
|
-
|
|
3
|
-
## Full Docs
|
|
4
|
-
|
|
5
|
-
[Docs](//docs.lunchboxjs.com)
|
|
6
|
-
|
|
7
|
-
## Local Dev
|
|
8
|
-
|
|
9
|
-
`npm run dev` to run dev server. From there, edit source code in `/src/...` and examples in `/demo/...` to build and test features.
|
|
10
|
-
|
|
11
|
-
### Creating Examples
|
|
12
|
-
|
|
13
|
-
Run `npm run demo:create` to create a new demo.
|
|
14
|
-
|
|
15
|
-
## Docs Dev
|
|
16
|
-
|
|
17
|
-
`npm run docs:dev` to run docs dev. Docs exist as a Vitepress site in the `/docs` folder.
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { defineComponent, onBeforeUnmount, ref, watch } from 'vue'
|
|
2
|
-
import {
|
|
3
|
-
useCamera,
|
|
4
|
-
Lunch,
|
|
5
|
-
useGlobals,
|
|
6
|
-
useLunchboxInteractables,
|
|
7
|
-
onRendererReady,
|
|
8
|
-
} from '..'
|
|
9
|
-
import * as THREE from 'three'
|
|
10
|
-
import { offBeforeRender, onBeforeRender } from '../core'
|
|
11
|
-
|
|
12
|
-
export const LunchboxEventHandlers = defineComponent({
|
|
13
|
-
name: 'LunchboxEventHandlers',
|
|
14
|
-
setup() {
|
|
15
|
-
const interactables = useLunchboxInteractables()
|
|
16
|
-
const globals = useGlobals()
|
|
17
|
-
const mousePos = ref({ x: Infinity, y: Infinity })
|
|
18
|
-
const inputActive = ref(false)
|
|
19
|
-
|
|
20
|
-
let currentIntersections: Array<{
|
|
21
|
-
element: Lunch.Node
|
|
22
|
-
intersection: THREE.Intersection<THREE.Object3D>
|
|
23
|
-
}> = []
|
|
24
|
-
|
|
25
|
-
const raycaster = new THREE.Raycaster(
|
|
26
|
-
new THREE.Vector3(),
|
|
27
|
-
new THREE.Vector3(0, 0, -1)
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
const fireEventsFromIntersections = ({
|
|
31
|
-
element,
|
|
32
|
-
eventKeys,
|
|
33
|
-
intersection,
|
|
34
|
-
}: {
|
|
35
|
-
element: Lunch.Node
|
|
36
|
-
eventKeys: Array<Lunch.EventKey>
|
|
37
|
-
intersection: THREE.Intersection<THREE.Object3D>
|
|
38
|
-
}) => {
|
|
39
|
-
if (!element) return
|
|
40
|
-
eventKeys.forEach((eventKey) => {
|
|
41
|
-
if (element.eventListeners[eventKey]) {
|
|
42
|
-
element.eventListeners[eventKey].forEach((cb) => {
|
|
43
|
-
cb({ intersection })
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// add mouse listener to renderer DOM element when the element is ready
|
|
50
|
-
onRendererReady((v) => {
|
|
51
|
-
if (!v?.domElement) return
|
|
52
|
-
|
|
53
|
-
// we have a DOM element, so let's add mouse listeners
|
|
54
|
-
const { domElement } = v
|
|
55
|
-
|
|
56
|
-
const mouseMoveListener = (evt: PointerEvent) => {
|
|
57
|
-
const screenWidth = (domElement.width ?? 1) / globals.dpr
|
|
58
|
-
const screenHeight = (domElement.height ?? 1) / globals.dpr
|
|
59
|
-
mousePos.value.x = (evt.offsetX / screenWidth) * 2 - 1
|
|
60
|
-
mousePos.value.y = -(evt.offsetY / screenHeight) * 2 + 1
|
|
61
|
-
}
|
|
62
|
-
const mouseDownListener = () => (inputActive.value = true)
|
|
63
|
-
const mouseUpListener = () => (inputActive.value = false)
|
|
64
|
-
|
|
65
|
-
// add mouse events
|
|
66
|
-
domElement.addEventListener('pointermove', mouseMoveListener)
|
|
67
|
-
domElement.addEventListener('pointerdown', mouseDownListener)
|
|
68
|
-
domElement.addEventListener('pointerup', mouseUpListener)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
const camera = useCamera()
|
|
72
|
-
const update = () => {
|
|
73
|
-
const c = camera.value
|
|
74
|
-
if (!c) return
|
|
75
|
-
|
|
76
|
-
// console.log(camera.value)
|
|
77
|
-
|
|
78
|
-
raycaster.setFromCamera(mousePos.value, c)
|
|
79
|
-
const intersections = raycaster.intersectObjects(
|
|
80
|
-
interactables?.value.map(
|
|
81
|
-
(v) => v.instance as any as THREE.Object3D
|
|
82
|
-
) ?? []
|
|
83
|
-
)
|
|
84
|
-
|
|
85
|
-
let enterValues: Array<THREE.Intersection<THREE.Object3D>> = [],
|
|
86
|
-
sameValues: Array<THREE.Intersection<THREE.Object3D>> = [],
|
|
87
|
-
leaveValues: Array<THREE.Intersection<THREE.Object3D>> = [],
|
|
88
|
-
entering: Array<{
|
|
89
|
-
element: Lunch.Node
|
|
90
|
-
intersection: THREE.Intersection<THREE.Object3D>
|
|
91
|
-
}> = [],
|
|
92
|
-
staying: Array<{
|
|
93
|
-
element: Lunch.Node
|
|
94
|
-
intersection: THREE.Intersection<THREE.Object3D>
|
|
95
|
-
}> = []
|
|
96
|
-
|
|
97
|
-
// intersection arrays
|
|
98
|
-
leaveValues = currentIntersections.map((v) => v.intersection)
|
|
99
|
-
|
|
100
|
-
// element arrays
|
|
101
|
-
intersections?.forEach((intersection) => {
|
|
102
|
-
const currentIdx = currentIntersections.findIndex(
|
|
103
|
-
(v) => v.intersection.object === intersection.object
|
|
104
|
-
)
|
|
105
|
-
if (currentIdx === -1) {
|
|
106
|
-
// new intersection
|
|
107
|
-
enterValues.push(intersection)
|
|
108
|
-
|
|
109
|
-
const found = interactables?.value.find(
|
|
110
|
-
(v) => v.instance?.uuid === intersection.object.uuid
|
|
111
|
-
)
|
|
112
|
-
if (found) {
|
|
113
|
-
entering.push({ element: found, intersection })
|
|
114
|
-
}
|
|
115
|
-
} else {
|
|
116
|
-
// existing intersection
|
|
117
|
-
sameValues.push(intersection)
|
|
118
|
-
|
|
119
|
-
const found = interactables?.value.find(
|
|
120
|
-
(v) => v.instance?.uuid === intersection.object.uuid
|
|
121
|
-
)
|
|
122
|
-
if (found) {
|
|
123
|
-
staying.push({ element: found, intersection })
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
// this is a current intersection, so it won't be in our `leave` array
|
|
127
|
-
const leaveIdx = leaveValues.findIndex(
|
|
128
|
-
(v) => v.object.uuid === intersection.object.uuid
|
|
129
|
-
)
|
|
130
|
-
if (leaveIdx !== -1) {
|
|
131
|
-
leaveValues.splice(leaveIdx, 1)
|
|
132
|
-
}
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
const leaving: Array<{
|
|
136
|
-
element: Lunch.Node
|
|
137
|
-
intersection: THREE.Intersection<THREE.Object3D>
|
|
138
|
-
}> = leaveValues.map((intersection) => {
|
|
139
|
-
return {
|
|
140
|
-
element: interactables?.value.find(
|
|
141
|
-
(interactable) =>
|
|
142
|
-
interactable.instance?.uuid ===
|
|
143
|
-
intersection.object.uuid
|
|
144
|
-
) as any as Lunch.Node,
|
|
145
|
-
intersection,
|
|
146
|
-
}
|
|
147
|
-
})
|
|
148
|
-
|
|
149
|
-
// new interactions
|
|
150
|
-
entering.forEach(({ element, intersection }) => {
|
|
151
|
-
fireEventsFromIntersections({
|
|
152
|
-
element,
|
|
153
|
-
eventKeys: ['onPointerEnter'],
|
|
154
|
-
intersection,
|
|
155
|
-
})
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
// unchanged interactions
|
|
159
|
-
staying.forEach(({ element, intersection }) => {
|
|
160
|
-
const eventKeys: Array<Lunch.EventKey> = [
|
|
161
|
-
'onPointerOver',
|
|
162
|
-
'onPointerMove',
|
|
163
|
-
]
|
|
164
|
-
fireEventsFromIntersections({
|
|
165
|
-
element,
|
|
166
|
-
eventKeys,
|
|
167
|
-
intersection,
|
|
168
|
-
})
|
|
169
|
-
})
|
|
170
|
-
|
|
171
|
-
// exited interactions
|
|
172
|
-
leaving.forEach(({ element, intersection }) => {
|
|
173
|
-
const eventKeys: Array<Lunch.EventKey> = [
|
|
174
|
-
'onPointerLeave',
|
|
175
|
-
'onPointerOut',
|
|
176
|
-
]
|
|
177
|
-
fireEventsFromIntersections({
|
|
178
|
-
element,
|
|
179
|
-
eventKeys,
|
|
180
|
-
intersection,
|
|
181
|
-
})
|
|
182
|
-
})
|
|
183
|
-
|
|
184
|
-
currentIntersections = ([] as any).concat(entering, staying)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// update function
|
|
188
|
-
onBeforeRender(update)
|
|
189
|
-
|
|
190
|
-
const teardown = () => offBeforeRender(update)
|
|
191
|
-
onBeforeUnmount(teardown)
|
|
192
|
-
|
|
193
|
-
const clickEventKeys: Lunch.EventKey[] = [
|
|
194
|
-
'onClick',
|
|
195
|
-
'onPointerDown',
|
|
196
|
-
'onPointerUp',
|
|
197
|
-
]
|
|
198
|
-
watch(inputActive, (isDown) => {
|
|
199
|
-
// run raycaster on click (necessary when `update` is not automatically called,
|
|
200
|
-
// for example in `updateSource` functions)
|
|
201
|
-
update()
|
|
202
|
-
|
|
203
|
-
// meshes with multiple intersections receive multiple callbacks by default -
|
|
204
|
-
// let's make it so they only receive one callback of each type per frame.
|
|
205
|
-
// (ie usually when you click on a mesh, you expect only one click event to fire, even
|
|
206
|
-
// if there are technically multiple intersections with that mesh)
|
|
207
|
-
const uuidsInteractedWithThisFrame: string[] = []
|
|
208
|
-
currentIntersections.forEach((v) => {
|
|
209
|
-
clickEventKeys.forEach((key) => {
|
|
210
|
-
const id = v.element.uuid + key
|
|
211
|
-
if (
|
|
212
|
-
isDown &&
|
|
213
|
-
(key === 'onClick' || key === 'onPointerDown')
|
|
214
|
-
) {
|
|
215
|
-
if (!uuidsInteractedWithThisFrame.includes(id)) {
|
|
216
|
-
v.element.eventListeners[key]?.forEach((cb) =>
|
|
217
|
-
cb({ intersection: v.intersection })
|
|
218
|
-
)
|
|
219
|
-
uuidsInteractedWithThisFrame.push(id)
|
|
220
|
-
}
|
|
221
|
-
} else if (!isDown && key === 'onPointerUp') {
|
|
222
|
-
if (!uuidsInteractedWithThisFrame.includes(id)) {
|
|
223
|
-
v.element.eventListeners[key]?.forEach((cb) =>
|
|
224
|
-
cb({ intersection: v.intersection })
|
|
225
|
-
)
|
|
226
|
-
uuidsInteractedWithThisFrame.push(id)
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
})
|
|
230
|
-
})
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
// return arbitrary object to ensure instantiation
|
|
234
|
-
// TODO: why can't we return a <raycaster/> here?
|
|
235
|
-
return () => <object3D />
|
|
236
|
-
},
|
|
237
|
-
})
|