lunchboxjs 0.2.1013 → 0.2.1015

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,8 +1,8 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('three'), require('lodash')) :
3
- typeof define === 'function' && define.amd ? define(['exports', 'vue', 'three', 'lodash'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Lunchbox = {}, global.vue, global.three, global.lodash));
5
- })(this, (function (exports, vue, THREE, lodash) { 'use strict';
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue'), require('three')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'vue', 'three'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.Lunchbox = {}, global.vue, global.three));
5
+ })(this, (function (exports, vue, THREE) { 'use strict';
6
6
 
7
7
  function _interopNamespace(e) {
8
8
  if (e && e.__esModule) return e;
@@ -44,6 +44,115 @@
44
44
  return null;
45
45
  }
46
46
 
47
+ const get = (obj, path, defValue) => {
48
+ // If path is not defined or it has false value
49
+ if (!path) return undefined; // Check if path is string or array. Regex : ensure that we do not have '.' and brackets.
50
+ // Regex explained: https://regexr.com/58j0k
51
+
52
+ const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g); // Find value
53
+
54
+ const result = pathArray?.reduce((prevObj, key) => prevObj && prevObj[key], obj); // If found value is undefined return default value; otherwise return the value
55
+
56
+ return result === undefined ? defValue : result;
57
+ };
58
+
59
+ const buildIsNumber = () => {
60
+ /**
61
+ * lodash (Custom Build) <https://lodash.com/>
62
+ * Build: `lodash modularize exports="npm" -o ./`
63
+ * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
64
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
65
+ * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
66
+ * Available under MIT license <https://lodash.com/license>
67
+ */
68
+
69
+ /** `Object#toString` result references. */
70
+ const numberTag = '[object Number]';
71
+ /** Used for built-in method references. */
72
+
73
+ const objectProto = Object.prototype;
74
+ /**
75
+ * Used to resolve the
76
+ * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
77
+ * of values.
78
+ */
79
+
80
+ const objectToString = objectProto.toString;
81
+ /**
82
+ * Checks if `value` is object-like. A value is object-like if it's not `null`
83
+ * and has a `typeof` result of "object".
84
+ *
85
+ * @static
86
+ * @memberOf _
87
+ * @since 4.0.0
88
+ * @category Lang
89
+ * @param {*} value The value to check.
90
+ * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
91
+ * @example
92
+ *
93
+ * _.isObjectLike({});
94
+ * // => true
95
+ *
96
+ * _.isObjectLike([1, 2, 3]);
97
+ * // => true
98
+ *
99
+ * _.isObjectLike(_.noop);
100
+ * // => false
101
+ *
102
+ * _.isObjectLike(null);
103
+ * // => false
104
+ */
105
+
106
+ function isObjectLike(value) {
107
+ return !!value && typeof value == 'object';
108
+ }
109
+ /**
110
+ * Checks if `value` is classified as a `Number` primitive or object.
111
+ *
112
+ * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
113
+ * classified as numbers, use the `_.isFinite` method.
114
+ *
115
+ * @static
116
+ * @memberOf _
117
+ * @since 0.1.0
118
+ * @category Lang
119
+ * @param {*} value The value to check.
120
+ * @returns {boolean} Returns `true` if `value` is a number, else `false`.
121
+ * @example
122
+ *
123
+ * _.isNumber(3);
124
+ * // => true
125
+ *
126
+ * _.isNumber(Number.MIN_VALUE);
127
+ * // => true
128
+ *
129
+ * _.isNumber(Infinity);
130
+ * // => true
131
+ *
132
+ * _.isNumber('3');
133
+ * // => false
134
+ */
135
+
136
+
137
+ const output = function isNumber(value) {
138
+ return typeof value == 'number' || isObjectLike(value) && objectToString.call(value) == numberTag;
139
+ };
140
+
141
+ return output;
142
+ };
143
+
144
+ const isNumber = buildIsNumber();
145
+
146
+ const set = (obj, path, value) => {
147
+ // Regex explained: https://regexr.com/58j0k
148
+ const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g);
149
+ pathArray?.reduce((acc, key, i) => {
150
+ if (acc[key] === undefined) acc[key] = {};
151
+ if (i === pathArray.length - 1) acc[key] = value;
152
+ return acc[key];
153
+ }, obj);
154
+ };
155
+
47
156
  /** Type check on whether target is a Lunchbox.EventKey */
48
157
 
49
158
  const isEventKey = target => {
@@ -1321,7 +1430,7 @@
1321
1430
 
1322
1431
  if (typeof value === 'string' && value.startsWith('$attached')) {
1323
1432
  const attachedName = value.replace('$attached.', '');
1324
- value = lodash.get(node.attached, attachedName, null);
1433
+ value = get(node.attached, attachedName, null);
1325
1434
  } // save instance
1326
1435
 
1327
1436
 
@@ -1334,12 +1443,12 @@
1334
1443
  for (let i = 0; i < nestedPropertiesToCheck.length && !liveProperty; i++) {
1335
1444
  const nestedProperty = nestedPropertiesToCheck[i];
1336
1445
  const fullPath = [nestedProperty, finalKey].filter(Boolean).join('.');
1337
- liveProperty = liveProperty = lodash.get(target, fullPath);
1446
+ liveProperty = liveProperty = get(target, fullPath);
1338
1447
  } // change property
1339
1448
  // first, save as array in case we need to spread it
1340
1449
 
1341
1450
 
1342
- if (liveProperty && lodash.isNumber(value) && liveProperty.setScalar) {
1451
+ if (liveProperty && isNumber(value) && liveProperty?.setScalar) {
1343
1452
  // if value is a number and the property has a `setScalar` method, use that
1344
1453
  liveProperty.setScalar(value);
1345
1454
  } else if (liveProperty && liveProperty.set) {
@@ -1365,11 +1474,11 @@
1365
1474
  // ; (parentAsLunchboxNode.instance as any)[finalKey] = result
1366
1475
  // }
1367
1476
 
1368
- } else if (lodash.get(target, finalKey, undefined) !== undefined) {
1477
+ } else if (get(target, finalKey, undefined) !== undefined) {
1369
1478
  // blank strings evaluate to `true`
1370
1479
  // <mesh castShadow receiveShadow /> will work the same as
1371
1480
  // <mesh :castShadow="true" :receiveShadow="true" />
1372
- lodash.set(target, finalKey, value === '' ? true : value);
1481
+ set(target, finalKey, value === '' ? true : value);
1373
1482
  } else {
1374
1483
  // if you see this error in production, you might need to add `finalKey`
1375
1484
  // to `internalLunchboxVueKeys` below
@@ -1798,7 +1907,14 @@
1798
1907
  };
1799
1908
  /** Obtain a list of interactable objects (registered via onClick, onHover, etc events). Usually used internally by Lunchbox. */
1800
1909
 
1801
- const useLunchboxInteractables = () => vue.inject(lunchboxInteractables); // CREATE APP
1910
+ const useLunchboxInteractables = () => vue.inject(lunchboxInteractables);
1911
+ /** Build a computed instance-getter from a specified ref. Defaults to a `toRaw`'d result. */
1912
+
1913
+ const getInstance = (target, raw = true) => vue.computed(() => {
1914
+ const output = target.value?.$el?.instance ?? target.value?.instance ?? null;
1915
+ if (output && raw) return vue.toRaw(output);
1916
+ return output;
1917
+ }); // CREATE APP
1802
1918
  // ====================
1803
1919
 
1804
1920
  const createApp = root => {
@@ -1979,6 +2095,7 @@
1979
2095
  exports.extend = extend;
1980
2096
  exports.find = find;
1981
2097
  exports.frameIdKey = frameIdKey;
2098
+ exports.getInstance = getInstance;
1982
2099
  exports.globalsInjectionKey = globalsInjectionKey;
1983
2100
  exports.instantiateThreeObject = instantiateThreeObject;
1984
2101
  exports.isMinidomNode = isMinidomNode;
@@ -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).Lunchbox={},e.vue,e.three,e.lodash)}(this,(function(e,t,r,n){"use strict";function o(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a=o(r);const i=e=>e?.$el&&e?.$el?.hasOwnProperty?.("instance"),s=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 u(t={}){const r={domElement:document.createElement(t.type??"")};return new e.MiniDom.RendererDomNode({...r,...t,metaType:"domMeta"})}function p(t={}){const r={text:t.text??""};return new e.MiniDom.RendererTextNode({...t,...r,metaType:"textMeta"})}function m(t={},r={}){const n={attached:t.attached??[],attachedArray:t.attachedArray??{},instance:t.instance??null},o=new e.MiniDom.RendererStandardNode({...t,...n,metaType:"standardMeta"});return!o.type||d(o)||o.instance||(o.instance=E({...o,props:{...o.props,...r}})),o}function h({node:e,key:t,interactables:r,value:n}){return e.eventListeners[t]||(e.eventListeners[t]=[]),e.eventListenerRemoveFunctions[t]||(e.eventListenerRemoveFunctions[t]=[]),e.eventListeners[t].push(n),f.includes(t)&&e.instance&&!r.value.includes(e)&&(r.value.push(e),e.eventListenerRemoveFunctions[t].push((()=>{const t=r.value.indexOf(e);-1!==t&&r.value.splice(t,1)}))),e}const f=["onClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove"],y=(e,r,n,o,a)=>{if(!r?.domElement||!n||!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,r=a/o;t.top=10*r,t.bottom=10*-r,t.right=10,t.left=-10,t.updateProjectionMatrix()}r.setSize(o,a),n&&e&&r.render(t.toRaw(n),t.toRaw(e))},b=(e,t,r,n,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);y(t,r,n,e.width,e.height)}else y(t,r,n)};i();let s=new ResizeObserver((()=>{i()}));return a&&s.observe(a),{dispose(){a&&s.unobserve(a)}}},v=t.defineComponent({name:"LunchboxScene",setup:(e,{slots:r})=>()=>t.createVNode(t.resolveComponent("scene"),null,{default:()=>[r.default?.()]})}),g=t.defineComponent({name:"LunchboxEventHandlers",setup(){const e=Le(),r=Pe(),n=t.ref({x:1/0,y:1/0}),o=t.ref(!1);let i=[];const s=new a.Raycaster(new a.Vector3,new a.Vector3(0,0,-1)),c=({element:e,eventKeys:t,intersection:r})=>{e&&t.forEach((t=>{e.eventListeners[t]&&e.eventListeners[t].forEach((e=>{e({intersection:r})}))}))};xe((e=>{if(!e?.domElement)return;const{domElement:t}=e;t.addEventListener("pointermove",(e=>{const o=(t.width??1)/r.dpr,a=(t.height??1)/r.dpr;n.value.x=e.offsetX/o*2-1,n.value.y=-e.offsetY/a*2+1})),t.addEventListener("pointerdown",(()=>o.value=!0)),t.addEventListener("pointerup",(()=>o.value=!1))}));const d=ve(),l=()=>{const t=d.value;if(!t)return;s.setFromCamera(n.value,t);const r=s.intersectObjects(e?.value.map((e=>e.instance))??[]);let o=[],a=[],l=[];o=i.map((e=>e.intersection)),r?.forEach((t=>{if(-1===i.findIndex((e=>e.intersection.object===t.object))){const r=e?.value.find((e=>e.instance?.uuid===t.object.uuid));r&&a.push({element:r,intersection:t})}else{const r=e?.value.find((e=>e.instance?.uuid===t.object.uuid));r&&l.push({element:r,intersection:t})}const r=o.findIndex((e=>e.object.uuid===t.object.uuid));-1!==r&&o.splice(r,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)};ne(l);t.onBeforeUnmount((()=>oe(l)));const u=["onClick","onPointerDown","onPointerUp"];return t.watch(o,(e=>{l();const t=[];i.forEach((r=>{u.forEach((n=>{const o=r.element.uuid+n;!e||"onClick"!==n&&"onPointerDown"!==n?e||"onPointerUp"!==n||t.includes(o)||(r.element.eventListeners[n]?.forEach((e=>e({intersection:r.intersection}))),t.push(o)):t.includes(o)||(r.element.eventListeners[n]?.forEach((e=>e({intersection:r.intersection}))),t.push(o))}))}))})),()=>t.createVNode(t.resolveComponent("object3D"),null,null)}}),x=e=>({position:e,top:0,right:0,bottom:0,left:0,width:"100%",height:"100%",display:"block"}),R=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 n=t.ref();let o=e.dpr??-1;const i=t.ref(),s=t.ref(),c=t.ref(),d=t.ref(),l=Pe(),u=Ce(),p=Ae(),m=t.reactive({}),h=Ee();e.r3f&&a?.ColorManagement&&(a.ColorManagement.legacyMode=!1);const f=Le();t.onMounted((async()=>{if(!n.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===o&&(o=window.devicePixelRatio),u?.({dpr:o});!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(!r.slots?.renderer?.()?.length){b(i,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(!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});te({app:p,camera:y,renderer:t,scene:f,updateSource:e.updateSource})})),t.onBeforeUnmount((()=>{ie(),ce()}));const y="container"===e.sizePolicy?"static":"absolute",R="container"===e.sizePolicy?"static":"fixed",w=t.computed((()=>{const e=r.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,[r.slots?.renderer?.()?.length?s.value=r.slots?.renderer?.()[0]:t.createVNode(t.Fragment,null,[t.createVNode("div",{class:"lunchbox-container",style:x(y),ref:i,"data-lunchbox":"true"},[t.createVNode("canvas",{ref:n,class:"lunchbox-canvas",style:x(R),"data-lunchbox":"true"},null)]),n.value?.domElement&&t.createVNode(t.resolveComponent("webGLRenderer"),t.mergeProps(e.rendererProperties??{},{ref:s,args:[{alpha:e.transparent,antialias:!0,canvas:n.value?.domElement,powerPreference:e.r3f?"high-performance":"default",...e.rendererArguments??{}}]}),null)]),r.slots?.scene?.()?.length?d.value=r.slots?.scene?.()[0]:t.createVNode(v,{ref:d},{default:()=>[r.slots?.default?.()]}),r.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(g,null,null)])}}),w={},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:(r,n)=>()=>t.h(e,n.attrs,n.slots?.default?.()||[])}))).reduce(((e,t)=>(e[t.name]=t,e)),{}),Lunchbox:R},C=e=>t.defineComponent({inheritAttrs:!1,name:e,render(){return t.h(e,this.$attrs,this.$slots?.default?.()||[])}}),A=({app:e,...t})=>{Object.keys(t).forEach((r=>{e.component(r,C(r)),w[r]=t[r]}))};function E(e){if(!e.type)return null;const t=e.type[0].toUpperCase()+e.type.slice(1),r=t.replace(/Lunchbox$/,""),n=w[e.type]||a[t]||w[r]||a[r];if(!n)throw`${t} is not part of the THREE namespace! Did you forget to extend? import {extend} from 'lunchbox'; extend({app, YourComponent, ...})`;const o=(e.props.args??[]).map((t=>function({node:e,prop:t}){const r="string"==typeof t&&t.startsWith("$attachedArray"),n=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(n)&&r?n:[n]}({node:e,prop:t})));let i=[];o.forEach((e=>{i=i.concat(e)}));return new n(...i)}var L,N=new Uint8Array(16);function M(){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(N)}var S=/^(?:[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 B(e){return"string"==typeof e&&S.test(e)}for(var j=[],G=0;G<256;++G)j.push((G+256).toString(16).substr(1));function T(e,t,r){var n=(e=e||{}).random||(e.rng||M)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){r=r||0;for(var o=0;o<16;++o)t[r+o]=n[o];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(j[e[t+0]]+j[e[t+1]]+j[e[t+2]]+j[e[t+3]]+"-"+j[e[t+4]]+j[e[t+5]]+"-"+j[e[t+6]]+j[e[t+7]]+"-"+j[e[t+8]]+j[e[t+9]]+"-"+j[e[t+10]]+j[e[t+11]]+j[e[t+12]]+j[e[t+13]]+j[e[t+14]]+j[e[t+15]]).toLowerCase();if(!B(r))throw TypeError("Stringified UUID is invalid");return r}(n)}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??T()}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 n=!0;for(;t.length&&n;){const o=t.shift();if(o){if(r.includes(o))continue;r.push(o),t.push(...o.children.filter((e=>!r.includes(e)))),n=e(o)}else n=!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 n extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.text=e.text??""}text}e.RendererCommentNode=n;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 k=Symbol(),O=Symbol(),$=Symbol(),D=Symbol(),F=Symbol(),K=Symbol(),V=Symbol(),I=Symbol(),U=Symbol(),z=Symbol(),H=Symbol(),W=Symbol(),q=Symbol(),_=Symbol(),X=Symbol(),Y=Symbol(),J=Symbol(),Q=Symbol(),Z=Symbol(),ee=e=>{"number"==typeof e.app.config.globalProperties.lunchbox.frameId&&cancelAnimationFrame(e.app.config.globalProperties.lunchbox.frameId),e.app.config.globalProperties.lunchbox.frameId=requestAnimationFrame((()=>te({app:e.app,renderer:e.renderer,scene:e.scene,camera:e.camera,updateSource:e.updateSource})))},te=e=>{e.updateSource?e.app.config.globalProperties.lunchbox.watchStopHandle||(e.app.config.globalProperties.lunchbox.watchStopHandle=t.watch(e.updateSource,(()=>{ee(e)}),{deep:!0})):ee(e);const{app:r,renderer:n,scene:o}=e;r.config.globalProperties.lunchbox.beforeRender.forEach((t=>{t?.(e)})),n&&o&&e.app.config.globalProperties.lunchbox.camera&&(r.customRender?r.customRender(e):n.render(t.toRaw(o),e.app.config.globalProperties.lunchbox.camera)),r.config.globalProperties.lunchbox.afterRender.forEach((t=>{t?.(e)}))},re=()=>({onBeforeRender:t.inject(K),offBeforeRender:t.inject(V)}),ne=(e,t=1/0)=>{re().onBeforeRender?.(e,t)},oe=e=>{re().offBeforeRender?.(e)},ae=()=>{const e=t.inject(H);return()=>{void 0!==e&&cancelAnimationFrame(e)}},ie=()=>{ae()?.()},se=()=>{const e=t.inject(W);return()=>e?.()},ce=()=>{se()?.()};function de({node:e,key:t,interactables:r,value:o}){if((e=>["onClick","onContextMenu","onDoubleClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove","onWheel"].includes(e))(t))return h({node:e,key:t,interactables:r,value:o});const a=t.replace(/-/g,"."),i=le[a]||a;if(pe.includes(t)||pe.includes(i))return e;if(!c(e))return e;if("string"==typeof o&&o.startsWith("$attached")){const t=o.replace("$attached.","");o=n.get(e.attached,t,null)}const s=e.instance;if(!s)return e;let d;for(let e=0;e<ue.length&&!d;e++){const t=[ue[e],i].filter(Boolean).join(".");d=d=n.get(s,t)}if(d&&n.isNumber(o)&&d.setScalar)d.setScalar(o);else if(d&&d.set){const e=Array.isArray(o)?o:[o];s[i].set(...e)}else if("function"==typeof d)if("onbeforerender"===i.toLowerCase()||"onafterrender"===i.toLowerCase())s[i]=o;else{if(!Array.isArray(o))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" />');d.bind(e.instance)(...o)}else void 0!==n.get(s,i,void 0)?n.set(s,i,""===o||o):console.log(`No property ${i} found on ${s}`);const l=s?.texture?.type||s?.type;if("string"==typeof l){const e=l.toLowerCase();switch(!0){case e.includes("material"):s.needsUpdate=!0;break;case e.includes("camera")&&s.updateProjectionMatrix:s.updateProjectionMatrix()}}return e}const le={x:"position.x",y:"position.y",z:"position.z"},ue=["","parameters"],pe=["args","attach","attachArray","is.default","isDefault","key","onAdded","ref","src"],me=["geometry","material"],he=(e,t,r,n)=>{const o={type:e,props:n};if(s(o)){return u(o)}const a=m(o);return me.forEach((t=>{e.toLowerCase().endsWith(t)&&(a.props.attach=t)})),a},fe=(e,t,r)=>{if(!t)throw new Error("missing parent");if(t.insertBefore(e,r),"commentMeta"!==e.metaType&&"textMeta"!==e.metaType&&(s(e)&&(s(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 n=r.load(e.props.src);ye(e,t,e.props.attach,n)}else r.load(e.props.src,(r=>{ye(e,t,e.props.attach,r)}),null,(e=>{throw new Error(e)}))}(e,t):ye(e,t,e.props.attach)}e.props?.onAdded&&e.props.onAdded({instance:e.instance})}};function ye(e,t,r,n){const o=n??e.instance,a=t.instance;e.props.attach===r&&(t.attached={[r]:o,...t.attached||{}},a[r]=n??e.instance),e.props.attachArray===r&&(t.attachedArray[e.props.attachArray]||(t.attachedArray[e.props.attachArray]=[]),t.attachedArray[e.props.attachArray].push(o),a[r]=[a[r]])}const be=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()}))},ve=()=>t.inject(J),ge=()=>t.inject(X),xe=e=>{const r=ge();if(r.value)return void e(r.value);let n=null;n=t.watch(ge(),(t=>{t&&(e(t),n?.())}),{immediate:!0})},Re=()=>t.inject(Y),we=()=>({setCustomRender:t.inject($),clearCustomRender:t.inject(D)}),Pe=()=>t.inject(k),Ce=()=>t.inject(O),Ae=()=>t.inject(_),Ee=()=>t.inject(Z),Le=()=>t.inject(Q);e.addEventListener=h,e.afterRenderKey=I,e.appCameraKey=J,e.appKey=_,e.appRenderersKey=X,e.appRootNodeKey=q,e.appSceneKey=Y,e.beforeRenderKey=F,e.cancelUpdate=ie,e.cancelUpdateSource=ce,e.clearCustomRender=()=>{we()?.clearCustomRender?.()},e.clearCustomRenderKey=D,e.createApp=r=>{const{nodeOps:n,interactables:o}=(()=>{const e=t.ref([]);return{nodeOps:{createElement:he,createText:e=>p({text:e}),createComment:e=>l({text:e}),insert:fe,nextSibling:e=>e.nextSibling||null,parentNode:e=>e.parentNode||null,patchProp(t,r,n,o){s(t)?"style"===r?Object.keys(o).forEach((e=>{t.domElement.style[e]=o[e]})):t.domElement.setAttribute(r,o):d(t)||r.startsWith("$")||de({node:t,key:r,interactables:e,value:o})},remove:be,setElementText(){},setText(){}},interactables:e}})(),a=t.createRenderer(n).createApp(r);a.provide(Q,o),Object.keys(P).forEach((e=>{a?.component(e,P[e])})),a.provide($,(e=>{a.setCustomRender(e)})),a.provide(D,(()=>{a.clearCustomRender()}));const i=[];a.provide(F,i),a.provide(K,((e,t=1/0)=>{t===1/0?i.push(e):i.splice(t,0,e)})),a.provide(V,(e=>{if(isFinite(e))i.splice(e,1);else{const t=i.findIndex((t=>t==e));-1!==t&&i.splice(t,1)}}));const c=[];a.provide(I,c),a.provide(U,((e,t=1/0)=>{t===1/0?c.push(e):c.splice(t,0,e)})),a.provide(z,(e=>{if(isFinite(e))c.splice(e,1);else{const t=c.findIndex((t=>t==e));-1!==t&&c.splice(t,1)}})),a.config.globalProperties.lunchbox=t.reactive({afterRender:c,beforeRender:i,camera:null,dpr:1,frameId:-1,renderer:null,scene:null,watchStopHandle:null}),a.provide(k,a.config.globalProperties.lunchbox),a.provide(O,(e=>{Object.keys(e).forEach((t=>{const r=t;a.config.globalProperties.lunchbox[r]=e[r]}))})),a.provide(H,a.config.globalProperties.lunchbox.frameId),a.provide(W,a.config.globalProperties.lunchbox.watchStopHandle);const{mount:u}=a;a.mount=(t,...r)=>{const n="string"==typeof t?document.querySelector(t):t,o=new e.MiniDom.RendererRootNode({domElement:n,isLunchboxRootNode:!0,name:"root",metaType:"rootMeta",type:"root",uuid:"LUNCHBOX_ROOT"});a.rootNode=o,a.provide(q,o);return u(o,...r)},a.extend=e=>(A({app:a,...e}),a);return a.provide(Z,[]),a.setCustomRender=e=>{a&&(a.customRender=e)},a.clearCustomRender=()=>{a&&(a.customRender=null)},a.provide(_,a),a.provide(X,t.computed((()=>a.config.globalProperties.lunchbox.renderer))),a.provide(Y,t.computed((()=>a.config.globalProperties.lunchbox.scene))),a.provide(J,t.computed((()=>a.config.globalProperties.lunchbox.camera))),a},e.createCommentNode=l,e.createDomNode=u,e.createNode=m,e.createTextNode=p,e.extend=A,e.find=function(e){return e=t.isRef(e)?e.value:e,c(e)?e?.instance:i(e)?e?.$el?.instance:t.isVNode(e)?e.el?.instance:null},e.frameIdKey=H,e.globalsInjectionKey=k,e.instantiateThreeObject=E,e.isMinidomNode=function(e){return"RendererNode"===e?.minidomType},e.lunchboxInteractables=Q,e.nestedPropertiesToCheck=ue,e.offAfterRender=e=>{re().offBeforeRender?.(e)},e.offAfterRenderKey=z,e.offBeforeRender=oe,e.offBeforeRenderKey=V,e.onAfterRender=(e,t=1/0)=>{re().onBeforeRender?.(e,t)},e.onAfterRenderKey=U,e.onBeforeRender=ne,e.onBeforeRenderKey=K,e.onCameraReady=e=>{const r=ve();if(r.value)return void e(r.value);let n=null;n=t.watch(ve(),(t=>{t&&(e(t),n?.())}))},e.onRendererReady=xe,e.onSceneReady=e=>{const r=Re();if(r.value)return void e(r.value);let n=null;n=t.watch(Re(),(t=>{t&&(e(t),n?.())}),{immediate:!0})},e.onStart=(e,t=1/0)=>{const r=Ee();t===1/0?r?.push(e):r?.splice(t,0,e)},e.setCustomRender=e=>{we()?.setCustomRender?.(e)},e.setCustomRenderKey=$,e.startCallbackKey=Z,e.update=te,e.updateGlobals=e=>{Ce()?.(e)},e.updateGlobalsInjectionKey=O,e.updateObjectProp=de,e.useAfterRender=()=>({onAfterRender:t.inject(K),offAfterRender:t.inject(V)}),e.useApp=Ae,e.useBeforeRender=re,e.useCamera=ve,e.useCancelUpdate=ae,e.useCancelUpdateSource=se,e.useCustomRender=we,e.useGlobals=Pe,e.useLunchboxInteractables=Le,e.useRenderer=ge,e.useScene=Re,e.useStartCallbacks=Ee,e.useUpdateGlobals=Ce,e.watchStopHandleKey=W,Object.defineProperty(e,"__esModule",{value:!0})}));
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,r){"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 n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var o=n(r);const a=(e,t,r)=>{if(!t)return;const n=(Array.isArray(t)?t:t.match(/([^[.\]])+/g))?.reduce(((e,t)=>e&&e[t]),e);return void 0===n?r:n},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 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 m(t={}){const r={text:t.text??""};return new e.MiniDom.RendererTextNode({...t,...r,metaType:"textMeta"})}function h(t={},r={}){const n={attached:t.attached??[],attachedArray:t.attachedArray??{},instance:t.instance??null},o=new e.MiniDom.RendererStandardNode({...t,...n,metaType:"standardMeta"});return!o.type||l(o)||o.instance||(o.instance=L({...o,props:{...o.props,...r}})),o}function f({node:e,key:t,interactables:r,value:n}){return e.eventListeners[t]||(e.eventListeners[t]=[]),e.eventListenerRemoveFunctions[t]||(e.eventListenerRemoveFunctions[t]=[]),e.eventListeners[t].push(n),y.includes(t)&&e.instance&&!r.value.includes(e)&&(r.value.push(e),e.eventListenerRemoveFunctions[t].push((()=>{const t=r.value.indexOf(e);-1!==t&&r.value.splice(t,1)}))),e}const y=["onClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove"],b=(e,r,n,o,a)=>{if(!r?.domElement||!n||!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,r=a/o;t.top=10*r,t.bottom=10*-r,t.right=10,t.left=-10,t.updateProjectionMatrix()}r.setSize(o,a),n&&e&&r.render(t.toRaw(n),t.toRaw(e))},v=(e,t,r,n,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,r,n,e.width,e.height)}else b(t,r,n)};i();let s=new ResizeObserver((()=>{i()}));return a&&s.observe(a),{dispose(){a&&s.unobserve(a)}}},g=t.defineComponent({name:"LunchboxScene",setup:(e,{slots:r})=>()=>t.createVNode(t.resolveComponent("scene"),null,{default:()=>[r.default?.()]})}),x=t.defineComponent({name:"LunchboxEventHandlers",setup(){const e=Ne(),r=Ce(),n=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:r})=>{e&&t.forEach((t=>{e.eventListeners[t]&&e.eventListeners[t].forEach((e=>{e({intersection:r})}))}))};Re((e=>{if(!e?.domElement)return;const{domElement:t}=e;t.addEventListener("pointermove",(e=>{const o=(t.width??1)/r.dpr,a=(t.height??1)/r.dpr;n.value.x=e.offsetX/o*2-1,n.value.y=-e.offsetY/a*2+1})),t.addEventListener("pointerdown",(()=>a.value=!0)),t.addEventListener("pointerup",(()=>a.value=!1))}));const d=ge(),l=()=>{const t=d.value;if(!t)return;s.setFromCamera(n.value,t);const r=s.intersectObjects(e?.value.map((e=>e.instance))??[]);let o=[],a=[],l=[];o=i.map((e=>e.intersection)),r?.forEach((t=>{if(-1===i.findIndex((e=>e.intersection.object===t.object))){const r=e?.value.find((e=>e.instance?.uuid===t.object.uuid));r&&a.push({element:r,intersection:t})}else{const r=e?.value.find((e=>e.instance?.uuid===t.object.uuid));r&&l.push({element:r,intersection:t})}const r=o.findIndex((e=>e.object.uuid===t.object.uuid));-1!==r&&o.splice(r,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((r=>{u.forEach((n=>{const o=r.element.uuid+n;!e||"onClick"!==n&&"onPointerDown"!==n?e||"onPointerUp"!==n||t.includes(o)||(r.element.eventListeners[n]?.forEach((e=>e({intersection:r.intersection}))),t.push(o)):t.includes(o)||(r.element.eventListeners[n]?.forEach((e=>e({intersection:r.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,r){const n=t.ref();let a=e.dpr??-1;const i=t.ref(),s=t.ref(),c=t.ref(),d=t.ref(),l=Ce(),u=Ae(),p=Ee(),m=t.reactive({}),h=Le();e.r3f&&o?.ColorManagement&&(o.ColorManagement.legacyMode=!1);const f=Ne();t.onMounted((async()=>{if(!n.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 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(!r.slots?.renderer?.()?.length){v(i,y,t,f,e.sizePolicy),e.r3f&&(t.outputEncoding=o.sRGBEncoding,t.toneMapping=o.ACESFilmicToneMapping);const r={shadow:e.shadow};r?.shadow&&(t.shadowMap.enabled=!0,"object"==typeof r.shadow&&(t.shadowMap.type=r.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});re({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=r.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,[r.slots?.renderer?.()?.length?s.value=r.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:n,class:"lunchbox-canvas",style:R(b),"data-lunchbox":"true"},null)]),n.value?.domElement&&t.createVNode(t.resolveComponent("webGLRenderer"),t.mergeProps(e.rendererProperties??{},{ref:s,args:[{alpha:e.transparent,antialias:!0,canvas:n.value?.domElement,powerPreference:e.r3f?"high-performance":"default",...e.rendererArguments??{}}]}),null)]),r.slots?.scene?.()?.length?d.value=r.slots?.scene?.()[0]:t.createVNode(g,{ref:d},{default:()=>[r.slots?.default?.()]}),r.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)])}}),P={},C={...["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:(r,n)=>()=>t.h(e,n.attrs,n.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((r=>{e.component(r,A(r)),P[r]=t[r]}))};function L(e){if(!e.type)return null;const t=e.type[0].toUpperCase()+e.type.slice(1),r=t.replace(/Lunchbox$/,""),n=P[e.type]||o[t]||P[r]||o[r];if(!n)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 r="string"==typeof t&&t.startsWith("$attachedArray"),n=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(n)&&r?n:[n]}({node:e,prop:t})));let i=[];a.forEach((e=>{i=i.concat(e)}));return new n(...i)}var N,M=new Uint8Array(16);function S(){if(!N&&!(N="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 N(M)}var j=/^(?:[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 B(e){return"string"==typeof e&&j.test(e)}for(var G=[],T=0;T<256;++T)G.push((T+256).toString(16).substr(1));function k(e,t,r){var n=(e=e||{}).random||(e.rng||S)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){r=r||0;for(var o=0;o<16;++o)t[r+o]=n[o];return t}return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(G[e[t+0]]+G[e[t+1]]+G[e[t+2]]+G[e[t+3]]+"-"+G[e[t+4]]+G[e[t+5]]+"-"+G[e[t+6]]+G[e[t+7]]+"-"+G[e[t+8]]+G[e[t+9]]+"-"+G[e[t+10]]+G[e[t+11]]+G[e[t+12]]+G[e[t+13]]+G[e[t+14]]+G[e[t+15]]).toLowerCase();if(!B(r))throw TypeError("Stringified UUID is invalid");return r}(n)}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 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 n=!0;for(;t.length&&n;){const o=t.shift();if(o){if(r.includes(o))continue;r.push(o),t.push(...o.children.filter((e=>!r.includes(e)))),n=e(o)}else n=!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 n extends e.RendererBaseNode{constructor(e={},t){super(e,t),this.text=e.text??""}text}e.RendererCommentNode=n;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=Symbol(),$=Symbol(),D=Symbol(),F=Symbol(),K=Symbol(),I=Symbol(),V=Symbol(),U=Symbol(),z=Symbol(),H=Symbol(),W=Symbol(),q=Symbol(),_=Symbol(),X=Symbol(),Y=Symbol(),J=Symbol(),Q=Symbol(),Z=Symbol(),ee=Symbol(),te=e=>{"number"==typeof e.app.config.globalProperties.lunchbox.frameId&&cancelAnimationFrame(e.app.config.globalProperties.lunchbox.frameId),e.app.config.globalProperties.lunchbox.frameId=requestAnimationFrame((()=>re({app:e.app,renderer:e.renderer,scene:e.scene,camera:e.camera,updateSource:e.updateSource})))},re=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:r,renderer:n,scene:o}=e;r.config.globalProperties.lunchbox.beforeRender.forEach((t=>{t?.(e)})),n&&o&&e.app.config.globalProperties.lunchbox.camera&&(r.customRender?r.customRender(e):n.render(t.toRaw(o),e.app.config.globalProperties.lunchbox.camera)),r.config.globalProperties.lunchbox.afterRender.forEach((t=>{t?.(e)}))},ne=()=>({onBeforeRender:t.inject(I),offBeforeRender:t.inject(V)}),oe=(e,t=1/0)=>{ne().onBeforeRender?.(e,t)},ae=e=>{ne().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:r,value:n}){if((e=>["onClick","onContextMenu","onDoubleClick","onPointerUp","onPointerDown","onPointerOver","onPointerOut","onPointerEnter","onPointerLeave","onPointerMove","onWheel"].includes(e))(t))return f({node:e,key:t,interactables:r,value:n});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 n&&n.startsWith("$attached")){const t=n.replace("$attached.","");n=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(n)&&l?.setScalar)l.setScalar(n);else if(l&&l.set){const e=Array.isArray(n)?n:[n];c[s].set(...e)}else if("function"==typeof l)if("onbeforerender"===s.toLowerCase()||"onafterrender"===s.toLowerCase())c[s]=n;else{if(!Array.isArray(n))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)(...n)}else void 0!==a(c,s,void 0)?((e,t,r)=>{const n=Array.isArray(t)?t:t.match(/([^[.\]])+/g);n?.reduce(((e,t,o)=>(void 0===e[t]&&(e[t]={}),o===n.length-1&&(e[t]=r),e[t])),e)})(c,s,""===n||n):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,r,n)=>{const o={type:e,props:n};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,r)=>{if(!t)throw new Error("missing parent");if(t.insertBefore(e,r),"commentMeta"!==e.metaType&&"textMeta"!==e.metaType&&(c(e)&&(c(t)||l(t))&&t.domElement.appendChild(e.domElement),d(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(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 r=e.instance;if(t.attached=t.attached||{},t.attachedArray=t.attachedArray||{},!e.props.attach)return;if("textureloader"===e.type?.toLowerCase()){const n=r.load(e.props.src);be(e,t,e.props.attach,n)}else r.load(e.props.src,(r=>{be(e,t,e.props.attach,r)}),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,r,n){const o=n??e.instance,a=t.instance;e.props.attach===r&&(t.attached={[r]:o,...t.attached||{}},a[r]=n??e.instance),e.props.attachArray===r&&(t.attachedArray[e.props.attachArray]||(t.attachedArray[e.props.attachArray]=[]),t.attachedArray[e.props.attachArray].push(o),a[r]=[a[r]])}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.inject(Q),xe=()=>t.inject(Y),Re=e=>{const r=xe();if(r.value)return void e(r.value);let n=null;n=t.watch(xe(),(t=>{t&&(e(t),n?.())}),{immediate:!0})},we=()=>t.inject(J),Pe=()=>({setCustomRender:t.inject(D),clearCustomRender:t.inject(F)}),Ce=()=>t.inject(O),Ae=()=>t.inject($),Ee=()=>t.inject(X),Le=()=>t.inject(ee),Ne=()=>t.inject(Z);e.addEventListener=f,e.afterRenderKey=U,e.appCameraKey=Q,e.appKey=X,e.appRenderersKey=Y,e.appRootNodeKey=_,e.appSceneKey=J,e.beforeRenderKey=K,e.cancelUpdate=se,e.cancelUpdateSource=de,e.clearCustomRender=()=>{Pe()?.clearCustomRender?.()},e.clearCustomRenderKey=F,e.createApp=r=>{const{nodeOps:n,interactables:o}=(()=>{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,r,n,o){c(t)?"style"===r?Object.keys(o).forEach((e=>{t.domElement.style[e]=o[e]})):t.domElement.setAttribute(r,o):l(t)||r.startsWith("$")||le({node:t,key:r,interactables:e,value:o})},remove:ve,setElementText(){},setText(){}},interactables:e}})(),a=t.createRenderer(n).createApp(r);a.provide(Z,o),Object.keys(C).forEach((e=>{a?.component(e,C[e])})),a.provide(D,(e=>{a.setCustomRender(e)})),a.provide(F,(()=>{a.clearCustomRender()}));const i=[];a.provide(K,i),a.provide(I,((e,t=1/0)=>{t===1/0?i.push(e):i.splice(t,0,e)})),a.provide(V,(e=>{if(isFinite(e))i.splice(e,1);else{const t=i.findIndex((t=>t==e));-1!==t&&i.splice(t,1)}}));const s=[];a.provide(U,s),a.provide(z,((e,t=1/0)=>{t===1/0?s.push(e):s.splice(t,0,e)})),a.provide(H,(e=>{if(isFinite(e))s.splice(e,1);else{const t=s.findIndex((t=>t==e));-1!==t&&s.splice(t,1)}})),a.config.globalProperties.lunchbox=t.reactive({afterRender:s,beforeRender:i,camera:null,dpr:1,frameId:-1,renderer:null,scene:null,watchStopHandle:null}),a.provide(O,a.config.globalProperties.lunchbox),a.provide($,(e=>{Object.keys(e).forEach((t=>{const r=t;a.config.globalProperties.lunchbox[r]=e[r]}))})),a.provide(W,a.config.globalProperties.lunchbox.frameId),a.provide(q,a.config.globalProperties.lunchbox.watchStopHandle);const{mount:d}=a;a.mount=(t,...r)=>{const n="string"==typeof t?document.querySelector(t):t,o=new e.MiniDom.RendererRootNode({domElement:n,isLunchboxRootNode:!0,name:"root",metaType:"rootMeta",type:"root",uuid:"LUNCHBOX_ROOT"});a.rootNode=o,a.provide(_,o);return d(o,...r)},a.extend=e=>(E({app:a,...e}),a);return a.provide(ee,[]),a.setCustomRender=e=>{a&&(a.customRender=e)},a.clearCustomRender=()=>{a&&(a.customRender=null)},a.provide(X,a),a.provide(Y,t.computed((()=>a.config.globalProperties.lunchbox.renderer))),a.provide(J,t.computed((()=>a.config.globalProperties.lunchbox.scene))),a.provide(Q,t.computed((()=>a.config.globalProperties.lunchbox.camera))),a},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,r=!0)=>t.computed((()=>{const n=e.value?.$el?.instance??e.value?.instance??null;return n&&r?t.toRaw(n):n})),e.globalsInjectionKey=O,e.instantiateThreeObject=L,e.isMinidomNode=function(e){return"RendererNode"===e?.minidomType},e.lunchboxInteractables=Z,e.nestedPropertiesToCheck=pe,e.offAfterRender=e=>{ne().offBeforeRender?.(e)},e.offAfterRenderKey=H,e.offBeforeRender=ae,e.offBeforeRenderKey=V,e.onAfterRender=(e,t=1/0)=>{ne().onBeforeRender?.(e,t)},e.onAfterRenderKey=z,e.onBeforeRender=oe,e.onBeforeRenderKey=I,e.onCameraReady=e=>{const r=ge();if(r.value)return void e(r.value);let n=null;n=t.watch(ge(),(t=>{t&&(e(t),n?.())}))},e.onRendererReady=Re,e.onSceneReady=e=>{const r=we();if(r.value)return void e(r.value);let n=null;n=t.watch(we(),(t=>{t&&(e(t),n?.())}),{immediate:!0})},e.onStart=(e,t=1/0)=>{const r=Le();t===1/0?r?.push(e):r?.splice(t,0,e)},e.setCustomRender=e=>{Pe()?.setCustomRender?.(e)},e.setCustomRenderKey=D,e.startCallbackKey=ee,e.update=re,e.updateGlobals=e=>{Ae()?.(e)},e.updateGlobalsInjectionKey=$,e.updateObjectProp=le,e.useAfterRender=()=>({onAfterRender:t.inject(I),offAfterRender:t.inject(V)}),e.useApp=Ee,e.useBeforeRender=ne,e.useCamera=ge,e.useCancelUpdate=ie,e.useCancelUpdateSource=ce,e.useCustomRender=Pe,e.useGlobals=Ce,e.useLunchboxInteractables=Ne,e.useRenderer=xe,e.useScene=we,e.useStartCallbacks=Le,e.useUpdateGlobals=Ae,e.watchStopHandleKey=q,Object.defineProperty(e,"__esModule",{value:!0})}));
@@ -1,6 +1,5 @@
1
1
  import { isRef, isVNode, toRaw, defineComponent, createVNode, resolveComponent, ref, onBeforeUnmount, watch, reactive, onMounted, computed, Fragment, mergeProps, h, inject, createRenderer } from 'vue';
2
2
  import * as THREE from 'three';
3
- import { get, isNumber, set } from 'lodash';
4
3
 
5
4
  function find(target) {
6
5
  target = isRef(target) ? target.value : target; // handle standard lunchbox node
@@ -22,6 +21,115 @@ function find(target) {
22
21
  return null;
23
22
  }
24
23
 
24
+ const get = (obj, path, defValue) => {
25
+ // If path is not defined or it has false value
26
+ if (!path) return undefined; // Check if path is string or array. Regex : ensure that we do not have '.' and brackets.
27
+ // Regex explained: https://regexr.com/58j0k
28
+
29
+ const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g); // Find value
30
+
31
+ const result = pathArray?.reduce((prevObj, key) => prevObj && prevObj[key], obj); // If found value is undefined return default value; otherwise return the value
32
+
33
+ return result === undefined ? defValue : result;
34
+ };
35
+
36
+ const buildIsNumber = () => {
37
+ /**
38
+ * lodash (Custom Build) <https://lodash.com/>
39
+ * Build: `lodash modularize exports="npm" -o ./`
40
+ * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
41
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
42
+ * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
43
+ * Available under MIT license <https://lodash.com/license>
44
+ */
45
+
46
+ /** `Object#toString` result references. */
47
+ const numberTag = '[object Number]';
48
+ /** Used for built-in method references. */
49
+
50
+ const objectProto = Object.prototype;
51
+ /**
52
+ * Used to resolve the
53
+ * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
54
+ * of values.
55
+ */
56
+
57
+ const objectToString = objectProto.toString;
58
+ /**
59
+ * Checks if `value` is object-like. A value is object-like if it's not `null`
60
+ * and has a `typeof` result of "object".
61
+ *
62
+ * @static
63
+ * @memberOf _
64
+ * @since 4.0.0
65
+ * @category Lang
66
+ * @param {*} value The value to check.
67
+ * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
68
+ * @example
69
+ *
70
+ * _.isObjectLike({});
71
+ * // => true
72
+ *
73
+ * _.isObjectLike([1, 2, 3]);
74
+ * // => true
75
+ *
76
+ * _.isObjectLike(_.noop);
77
+ * // => false
78
+ *
79
+ * _.isObjectLike(null);
80
+ * // => false
81
+ */
82
+
83
+ function isObjectLike(value) {
84
+ return !!value && typeof value == 'object';
85
+ }
86
+ /**
87
+ * Checks if `value` is classified as a `Number` primitive or object.
88
+ *
89
+ * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
90
+ * classified as numbers, use the `_.isFinite` method.
91
+ *
92
+ * @static
93
+ * @memberOf _
94
+ * @since 0.1.0
95
+ * @category Lang
96
+ * @param {*} value The value to check.
97
+ * @returns {boolean} Returns `true` if `value` is a number, else `false`.
98
+ * @example
99
+ *
100
+ * _.isNumber(3);
101
+ * // => true
102
+ *
103
+ * _.isNumber(Number.MIN_VALUE);
104
+ * // => true
105
+ *
106
+ * _.isNumber(Infinity);
107
+ * // => true
108
+ *
109
+ * _.isNumber('3');
110
+ * // => false
111
+ */
112
+
113
+
114
+ const output = function isNumber(value) {
115
+ return typeof value == 'number' || isObjectLike(value) && objectToString.call(value) == numberTag;
116
+ };
117
+
118
+ return output;
119
+ };
120
+
121
+ const isNumber = buildIsNumber();
122
+
123
+ const set = (obj, path, value) => {
124
+ // Regex explained: https://regexr.com/58j0k
125
+ const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g);
126
+ pathArray?.reduce((acc, key, i) => {
127
+ if (acc[key] === undefined) acc[key] = {};
128
+ if (i === pathArray.length - 1) acc[key] = value;
129
+ return acc[key];
130
+ }, obj);
131
+ };
132
+
25
133
  /** Type check on whether target is a Lunchbox.EventKey */
26
134
 
27
135
  const isEventKey = target => {
@@ -1317,7 +1425,7 @@ function updateObjectProp({
1317
1425
  // first, save as array in case we need to spread it
1318
1426
 
1319
1427
 
1320
- if (liveProperty && isNumber(value) && liveProperty.setScalar) {
1428
+ if (liveProperty && isNumber(value) && liveProperty?.setScalar) {
1321
1429
  // if value is a number and the property has a `setScalar` method, use that
1322
1430
  liveProperty.setScalar(value);
1323
1431
  } else if (liveProperty && liveProperty.set) {
@@ -1776,7 +1884,14 @@ const onStart = (cb, index = Infinity) => {
1776
1884
  };
1777
1885
  /** Obtain a list of interactable objects (registered via onClick, onHover, etc events). Usually used internally by Lunchbox. */
1778
1886
 
1779
- const useLunchboxInteractables = () => inject(lunchboxInteractables); // CREATE APP
1887
+ const useLunchboxInteractables = () => inject(lunchboxInteractables);
1888
+ /** Build a computed instance-getter from a specified ref. Defaults to a `toRaw`'d result. */
1889
+
1890
+ const getInstance = (target, raw = true) => computed(() => {
1891
+ const output = target.value?.$el?.instance ?? target.value?.instance ?? null;
1892
+ if (output && raw) return toRaw(output);
1893
+ return output;
1894
+ }); // CREATE APP
1780
1895
  // ====================
1781
1896
 
1782
1897
  const createApp = root => {
@@ -1937,4 +2052,4 @@ const createApp = root => {
1937
2052
  return app;
1938
2053
  };
1939
2054
 
1940
- export { MiniDom, addEventListener, afterRenderKey, appCameraKey, appKey, appRenderersKey, appRootNodeKey, appSceneKey, beforeRenderKey, cancelUpdate, cancelUpdateSource, clearCustomRender, clearCustomRenderKey, createApp, createCommentNode, createDomNode, createNode, createTextNode, extend, find, frameIdKey, globalsInjectionKey, instantiateThreeObject, isMinidomNode, lunchboxInteractables, nestedPropertiesToCheck, offAfterRender, offAfterRenderKey, offBeforeRender, offBeforeRenderKey, onAfterRender, onAfterRenderKey, onBeforeRender, onBeforeRenderKey, onCameraReady, onRendererReady, onSceneReady, onStart, setCustomRender, setCustomRenderKey, startCallbackKey, update, updateGlobals, updateGlobalsInjectionKey, updateObjectProp, useAfterRender, useApp, useBeforeRender, useCamera, useCancelUpdate, useCancelUpdateSource, useCustomRender, useGlobals, useLunchboxInteractables, useRenderer, useScene, useStartCallbacks, useUpdateGlobals, watchStopHandleKey };
2055
+ export { MiniDom, addEventListener, afterRenderKey, appCameraKey, appKey, appRenderersKey, appRootNodeKey, appSceneKey, beforeRenderKey, cancelUpdate, cancelUpdateSource, clearCustomRender, clearCustomRenderKey, createApp, createCommentNode, createDomNode, createNode, createTextNode, extend, find, frameIdKey, getInstance, globalsInjectionKey, instantiateThreeObject, isMinidomNode, lunchboxInteractables, nestedPropertiesToCheck, offAfterRender, offAfterRenderKey, offBeforeRender, offBeforeRenderKey, onAfterRender, onAfterRenderKey, onBeforeRender, onBeforeRenderKey, onCameraReady, onRendererReady, onSceneReady, onStart, setCustomRender, setCustomRenderKey, startCallbackKey, update, updateGlobals, updateGlobalsInjectionKey, updateObjectProp, useAfterRender, useApp, useBeforeRender, useCamera, useCancelUpdate, useCancelUpdateSource, useCustomRender, useGlobals, useLunchboxInteractables, useRenderer, useScene, useStartCallbacks, useUpdateGlobals, watchStopHandleKey };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lunchboxjs",
3
- "version": "0.2.1013",
3
+ "version": "0.2.1015",
4
4
  "scripts": {
5
5
  "dev": "vite -c utils/vite.config.ts",
6
6
  "build": "vue-tsc --noEmit && vite build -c utils/vite.config.ts",
@@ -26,7 +26,6 @@
26
26
  "@rollup/plugin-babel": "5.3.1",
27
27
  "@rollup/plugin-node-resolve": "13.0.5",
28
28
  "@rollup/plugin-typescript": "8.3.0",
29
- "@types/lodash": "4.14.175",
30
29
  "@types/node": "18.6.3",
31
30
  "@types/three": "0.141.0",
32
31
  "@types/uuid": "8.3.1",
@@ -50,8 +49,7 @@
50
49
  "vue-tsc": "^0.3.0"
51
50
  },
52
51
  "peerDependencies": {
53
- "lodash": "^4.17.21",
54
- "three": "^0.133.0"
52
+ "three": "*"
55
53
  },
56
54
  "files": [
57
55
  "dist",
@@ -1,6 +1,11 @@
1
- import { isEventKey, isLunchboxStandardNode } from '../utils'
1
+ import {
2
+ get,
3
+ isEventKey,
4
+ isLunchboxStandardNode,
5
+ isNumber,
6
+ set,
7
+ } from '../utils'
2
8
  import { addEventListener } from './interaction'
3
- import { get, isNumber, set } from 'lodash'
4
9
  import type { Lunch } from '..'
5
10
  import type { Ref } from 'vue'
6
11
 
@@ -50,7 +55,7 @@ export function updateObjectProp({
50
55
  if (!target) return node
51
56
 
52
57
  // burrow down until we get property to change
53
- let liveProperty
58
+ let liveProperty: any
54
59
  for (let i = 0; i < nestedPropertiesToCheck.length && !liveProperty; i++) {
55
60
  const nestedProperty = nestedPropertiesToCheck[i]
56
61
  const fullPath = [nestedProperty, finalKey].filter(Boolean).join('.')
@@ -59,7 +64,7 @@ export function updateObjectProp({
59
64
 
60
65
  // change property
61
66
  // first, save as array in case we need to spread it
62
- if (liveProperty && isNumber(value) && liveProperty.setScalar) {
67
+ if (liveProperty && isNumber(value) && liveProperty?.setScalar) {
63
68
  // if value is a number and the property has a `setScalar` method, use that
64
69
  liveProperty.setScalar(value)
65
70
  } else if (liveProperty && liveProperty.set) {
package/src/index.ts CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  reactive,
9
9
  Ref,
10
10
  WatchStopHandle,
11
+ toRaw,
11
12
  } from 'vue'
12
13
  import { createNodeOps } from './nodeOps'
13
14
  import { extend, MiniDom } from './core'
@@ -181,6 +182,20 @@ export const onStart = (cb: Lunch.UpdateCallback, index = Infinity) => {
181
182
  export const useLunchboxInteractables = () =>
182
183
  inject<Ref<Lunch.Node[]>>(Keys.lunchboxInteractables)
183
184
 
185
+ /** Build a computed instance-getter from a specified ref. Defaults to a `toRaw`'d result. */
186
+ export const getInstance = <T = unknown>(
187
+ target: Ref<Lunch.LunchboxComponent<T> | Lunch.Node<T> | null>,
188
+ raw = true
189
+ ) =>
190
+ computed(() => {
191
+ const output =
192
+ (target.value as Lunch.LunchboxComponent<T>)?.$el?.instance ??
193
+ (target.value as Lunch.Node<T>)?.instance ??
194
+ null
195
+ if (output && raw) return toRaw(output)
196
+ return output
197
+ })
198
+
184
199
  // CREATE APP
185
200
  // ====================
186
201
  export const createApp = (root: Component) => {
@@ -0,0 +1,18 @@
1
+ export const get = <T = unknown>(
2
+ obj: Record<string, any>,
3
+ path: string | string[],
4
+ defValue?: T
5
+ ) => {
6
+ // If path is not defined or it has false value
7
+ if (!path) return undefined
8
+ // Check if path is string or array. Regex : ensure that we do not have '.' and brackets.
9
+ // Regex explained: https://regexr.com/58j0k
10
+ const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g)
11
+ // Find value
12
+ const result = pathArray?.reduce(
13
+ (prevObj: Record<string, any>, key: string) => prevObj && prevObj[key],
14
+ obj
15
+ )
16
+ // If found value is undefined return default value; otherwise return the value
17
+ return result === undefined ? defValue : result
18
+ }
@@ -2,6 +2,11 @@ import { Lunch } from '..'
2
2
 
3
3
  export * from './find'
4
4
 
5
+ // replacement functions from https://youmightnotneed.com/lodash
6
+ export * from './get'
7
+ export * from './isNumber'
8
+ export * from './set'
9
+
5
10
  // MAKE SURE THESE MATCH VALUES IN types.EventKey
6
11
  /** Type check on whether target is a Lunchbox.EventKey */
7
12
  export const isEventKey = (target: any): target is Lunch.EventKey => {
@@ -0,0 +1,87 @@
1
+ const buildIsNumber = () => {
2
+ /**
3
+ * lodash (Custom Build) <https://lodash.com/>
4
+ * Build: `lodash modularize exports="npm" -o ./`
5
+ * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
6
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
7
+ * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
8
+ * Available under MIT license <https://lodash.com/license>
9
+ */
10
+
11
+ /** `Object#toString` result references. */
12
+ const numberTag = '[object Number]'
13
+
14
+ /** Used for built-in method references. */
15
+ const objectProto = Object.prototype
16
+
17
+ /**
18
+ * Used to resolve the
19
+ * [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
20
+ * of values.
21
+ */
22
+ const objectToString = objectProto.toString
23
+
24
+ /**
25
+ * Checks if `value` is object-like. A value is object-like if it's not `null`
26
+ * and has a `typeof` result of "object".
27
+ *
28
+ * @static
29
+ * @memberOf _
30
+ * @since 4.0.0
31
+ * @category Lang
32
+ * @param {*} value The value to check.
33
+ * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
34
+ * @example
35
+ *
36
+ * _.isObjectLike({});
37
+ * // => true
38
+ *
39
+ * _.isObjectLike([1, 2, 3]);
40
+ * // => true
41
+ *
42
+ * _.isObjectLike(_.noop);
43
+ * // => false
44
+ *
45
+ * _.isObjectLike(null);
46
+ * // => false
47
+ */
48
+ function isObjectLike(value: any) {
49
+ return !!value && typeof value == 'object'
50
+ }
51
+
52
+ /**
53
+ * Checks if `value` is classified as a `Number` primitive or object.
54
+ *
55
+ * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
56
+ * classified as numbers, use the `_.isFinite` method.
57
+ *
58
+ * @static
59
+ * @memberOf _
60
+ * @since 0.1.0
61
+ * @category Lang
62
+ * @param {*} value The value to check.
63
+ * @returns {boolean} Returns `true` if `value` is a number, else `false`.
64
+ * @example
65
+ *
66
+ * _.isNumber(3);
67
+ * // => true
68
+ *
69
+ * _.isNumber(Number.MIN_VALUE);
70
+ * // => true
71
+ *
72
+ * _.isNumber(Infinity);
73
+ * // => true
74
+ *
75
+ * _.isNumber('3');
76
+ * // => false
77
+ */
78
+ const output = function isNumber(value: any) {
79
+ return (
80
+ typeof value == 'number' ||
81
+ (isObjectLike(value) && objectToString.call(value) == numberTag)
82
+ )
83
+ }
84
+ return output
85
+ }
86
+
87
+ export const isNumber = buildIsNumber()
@@ -0,0 +1,14 @@
1
+ export const set = (
2
+ obj: Record<string, any>,
3
+ path: string | string[],
4
+ value: any
5
+ ) => {
6
+ // Regex explained: https://regexr.com/58j0k
7
+ const pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g)
8
+
9
+ pathArray?.reduce((acc: Record<string, any>, key: string, i: number) => {
10
+ if (acc[key] === undefined) acc[key] = {}
11
+ if (i === pathArray.length - 1) acc[key] = value
12
+ return acc[key]
13
+ }, obj)
14
+ }