@tomorrowevening/hermes 0.0.32 → 0.0.34
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/hermes.umd.cjs +1 -1
- package/package.json +2 -4
- package/src/core/Application.ts +1 -1
- package/src/core/RemoteController.ts +1 -1
- package/src/core/remote/RemoteTheatre.ts +2 -3
- package/src/core/remote/RemoteTweakpane.ts +1 -2
- package/src/editor/components/DropdownItem.tsx +1 -1
- package/src/editor/sidePanel/ContainerObject.tsx +1 -1
- package/types/core/Application.d.ts +1 -1
- package/types/core/remote/RemoteTheatre.d.ts +2 -3
- package/types/core/remote/RemoteTweakpane.d.ts +1 -2
- package/types/editor/components/DropdownItem.d.ts +1 -1
- package/types/editor/sidePanel/ContainerObject.d.ts +1 -1
package/dist/hermes.umd.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
(function(w,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("three"),require("@theatre/core"),require("@theatre/studio"),require("tweakpane"),require("@tweakpane/plugin-essentials"),require("react"),require("framer-motion")):typeof define=="function"&&define.amd?define(["exports","three","@theatre/core","@theatre/studio","tweakpane","@tweakpane/plugin-essentials","react","framer-motion"],c):(w=typeof globalThis<"u"?globalThis:w||self,c(w.Hermes={},w.Three,w["Theatre Core"],w["Theatre Studio"],w.tweakpane,w["tweakpane-plugin-essentials"],w.React,w["framer-motion"]))})(this,function(w,c,Ce,Je,Rn,An,P,Xt){"use strict";var Na=Object.defineProperty;var La=(w,c,Ce)=>c in w?Na(w,c,{enumerable:!0,configurable:!0,writable:!0,value:Ce}):w[c]=Ce;var V=(w,c,Ce)=>(La(w,typeof c!="symbol"?c+"":c,Ce),Ce);function Pn(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const e=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,e.get?e:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const kn=Pn(An);function ze(t){return t.substring(0,1).toUpperCase()+t.substring(1)}function jn(t,n,a){return Math.min(n,Math.max(t,a))}function _n(t,n){const a=t-n;return Math.sqrt(a*a)}function Zt(){return Math.round(Math.random()*1e6).toString()}function Jt(t){return t.r!==void 0&&t.g!==void 0&&t.b!==void 0}function Qt(t){const n=Math.round(t.r*255),a=Math.round(t.g*255),e=Math.round(t.b*255),r=u=>{const f=u.toString(16);return f.length===1?"0"+f:f},s=r(n),p=r(a),l=r(e);return"#"+s+p+l}function ft(t,n=1){return Number(t.toFixed(n))}w.totalThreeObjects=0;const qt=()=>{w.totalThreeObjects=0},Pt=t=>{if(!t)return;let n=t.name.replace(" ","");n.length===0&&(n=`obj_${w.totalThreeObjects}`,w.totalThreeObjects++),t.parent!==null&&(n=`${t.parent.uuid}.${n}`),t.uuid=n,t.children.forEach(a=>{Pt(a)})},Dn=t=>{t==null||t.dispose()},$t=t=>{t&&(Array.isArray(t)?t.forEach(n=>n.dispose()):t.dispose())},kt=t=>{var n;if(t){for(;t.children.length>0;){const a=t.children[0];a instanceof c.PositionalAudio?(a.pause(),a.parent&&a.parent.remove(a)):kt(a)}if(t.parent&&t.parent.remove(t),t.isMesh){const a=t;(n=a.geometry)==null||n.dispose(),$t(a.material)}t.dispose!==void 0&&t.dispose()}};class In{constructor(n,a,e=!0,r="editor"){V(this,"components",new Map);V(this,"listen");V(this,"_debugEnabled");V(this,"broadcastChannel");V(this,"webSocket");V(this,"_mode","app");V(this,"_connected",!1);V(this,"useBC",!1);V(this,"messageHandler",n=>{this.listen!==void 0&&(this.useBC?this.listen(n.data):this.listen(JSON.parse(n.data)))});V(this,"openHandler",()=>{this._connected=!0});V(this,"closeHandler",()=>{this._connected=!1});this.editor=a&&document.location.hash.search(r)>-1,this._debugEnabled=a,a&&(this.useBC=e,e?(this.broadcastChannel=new BroadcastChannel(n),this.broadcastChannel.addEventListener("message",this.messageHandler)):(this.webSocket=new WebSocket(n),this.webSocket.addEventListener("open",this.openHandler),this.webSocket.addEventListener("close",this.closeHandler),this.webSocket.addEventListener("message",this.messageHandler)))}addComponent(n,a){this.components.set(n,a)}dispose(){this.broadcastChannel!==void 0&&this.broadcastChannel.removeEventListener("message",this.messageHandler),this.webSocket!==void 0&&(this.webSocket.removeEventListener("open",this.openHandler),this.webSocket.removeEventListener("close",this.closeHandler),this.webSocket.removeEventListener("message",this.messageHandler)),this.components.forEach(n=>{n.dispose()}),this.components.clear()}send(n){var a,e;this._mode!==n.target&&(this.useBC?(a=this.broadcastChannel)==null||a.postMessage(n):this._connected&&((e=this.webSocket)==null||e.send(JSON.stringify(n))))}get connected(){return this._connected}get debugEnabled(){return this._debugEnabled}get mode(){return this._mode}get isApp(){return this._mode==="app"}get editor(){return this._mode==="editor"}set editor(n){n&&(this._mode="editor",document.title+=" - Editor")}}const I=new c.EventDispatcher,N={CUSTOM:"ToolEvents::custom",SELECT_DROPDOWN:"ToolEvents::selectDropdown",DRAG_UPDATE:"ToolEvents::dragUpdate",SET_SCENE:"ToolEvents::setScene",GET_OBJECT:"ToolEvents::getObject",SET_OBJECT:"ToolEvents::setObject",UPDATE_OBJECT:"ToolEvents::updateObject",CREATE_TEXTURE:"ToolEvents::createTexture",REQUEST_METHOD:"ToolEvents::requestMethod",ADD_CAMERA:"ToolEvents::addCamera",REMOVE_CAMERA:"ToolEvents::removeCamera"};class Qe{constructor(n){V(this,"app");this.app=n}dispose(){}}class en extends Qe{selectDropdown(n,a){this.app.send({event:"selectComponent",target:"app",data:{dropdown:n,value:a}})}updateDropdown(n,a){this.app.send({event:"draggableListUpdate",target:"app",data:{dropdown:n,value:a}})}}function Nn(t,n){switch(n.event){case"selectComponent":I.dispatchEvent({type:N.SELECT_DROPDOWN,value:n.data});break;case"draggableListUpdate":I.dispatchEvent({type:N.DRAG_UPDATE,value:n.data});break}}const tn=()=>{},Ge=class Ge extends Qe{constructor(){super(...arguments);V(this,"project");V(this,"sheets",new Map);V(this,"sheetObjects",new Map);V(this,"sheetObjectCBs",new Map);V(this,"sheetObjectUnsubscribe",new Map)}init(a,e){return this.project=Ce.getProject(a,e),this.project.ready}dispose(){this.project=void 0,this.sheets=new Map,this.sheetObjects=new Map,this.sheetObjectCBs=new Map,this.sheetObjectUnsubscribe=new Map}sheet(a){var r;if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}let e=this.sheets.get(a);return e!==void 0||(e=(r=this.project)==null?void 0:r.sheet(a),this.sheets.set(a,e)),e}playSheet(a,e){var r;(r=this.sheet(a))==null||r.sequence.play(e),this.app.send({event:"playSheet",target:"editor",data:{sheet:a,value:e}})}pauseSheet(a){var e;(e=this.sheet(a))==null||e.sequence.pause(),this.app.send({event:"pauseSheet",target:"editor",data:{sheet:a}})}clearSheetObjects(a){this.sheetObjects.forEach((e,r)=>{r.search(`${a}_`)>-1&&this.unsubscribe(e)})}sheetObject(a,e,r,s){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const p=this.sheet(a);if(p===void 0)return;const l=`${a}_${e}`;let u=this.sheetObjects.get(l);u!==void 0?u=p.object(e,{...r,...u.value},{reconfigure:!0}):u=p.object(e,r),this.sheetObjects.set(l,u),this.sheetObjectCBs.set(l,s!==void 0?s:tn);const f=u.onValuesChange(y=>{if(this.app.editor){for(const C in y){const x=y[C];typeof x=="object"&&Jt(x)&&(y[C]={r:x.r,g:x.g,b:x.b,a:x.a})}this.app.send({event:"updateSheetObject",target:"app",data:{sheet:a,sheetObject:l,values:y}})}const v=this.sheetObjectCBs.get(l);v!==void 0&&v(y)});return this.sheetObjectUnsubscribe.set(l,f),u}unsubscribe(a){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const e=a.address.sheetId,r=a.address.objectKey,s=this.sheets.get(e);s==null||s.detachObject(r);const p=`${e}_${r}`,l=this.sheetObjectUnsubscribe.get(p);l!==void 0&&(this.sheetObjects.delete(p),this.sheetObjectCBs.delete(p),this.sheetObjectUnsubscribe.delete(p),l())}static getRafDriver(){return Ge.rafDriver||(Ge.rafDriver=Ce.createRafDriver()),Ge.rafDriver}};V(Ge,"rafDriver",null);let Me=Ge,Se;function Ln(t,n){t.components.forEach(a=>{if(a instanceof Me){let e;const r=a;switch(n.event){case"setSheet":e=r.sheets.get(n.data.sheet),e!==void 0&&(Se=e,Je.setSelection([e]));break;case"setSheetObject":e=r.sheetObjects.get(`${n.data.sheet}_${n.data.key}`),e!==void 0&&Je.setSelection([e]);break;case"updateSheetObject":e=r.sheets.get(n.data.sheet),e!==void 0&&e.sequence.pause(),e=r.sheetObjectCBs.get(n.data.sheetObject),e!==void 0&&e(n.data.values);break;case"updateTimeline":e=r.sheets.get(n.data.sheet),Se!==void 0&&(Se.sequence.position=n.data.position);break}}})}function Fn(t){if(t.editor){let n;t.components.forEach(s=>{s instanceof Me&&(n=s)}),Je.ui.restore(),Je.onSelectionChange(s=>{s.length<1||s.forEach(p=>{let l=p.address.sheetId,u="setSheet",f={};switch(p.type){case"Theatre_Sheet_PublicAPI":u="setSheet",f={sheet:p.address.sheetId},Se=n.sheets.get(p.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":u="setSheetObject",l+=`_${p.address.objectKey}`,f={id:l,sheet:p.address.sheetId,key:p.address.objectKey};break}t.send({event:u,target:"app",data:f})})});let a=0;const e=()=>{if(Se!==void 0&&a!==Se.sequence.position){a=Se.sequence.position;const s=Se;t.send({event:"updateTimeline",target:"app",data:{position:a,sheet:s.address.sheetId}})}},r=()=>{e(),requestAnimationFrame(r)};e(),r()}else Je.ui.hide()}function Un(t,n){t.editor&&t.components.forEach(a=>{var e,r;if(a instanceof Me){const s=a;switch(n.event){case"playSheet":(e=s.sheet(n.data.sheet))==null||e.sequence.play(n.data.value);break;case"pauseSheet":(r=s.sheet(n.data.sheet))==null||r.sequence.pause();break}return}})}function Bn(t){if(t.name==="cameras")return"camera";if(t.name==="interactive")return"interactive";if(t.name==="lights")return"light";if(t.name==="ui")return"ui";if(t.name==="utils")return"utils";const n=t.type;return n.search("Helper")>-1?"icon_utils":n.search("Camera")>-1?"camera":n.search("Light")>-1?"light":"obj3D"}function nn(t){const n={name:t.name,type:t.type,uuid:t.uuid,children:[]};return t.children.forEach(a=>{n.children.push(nn(a))}),n}function Vn(t){const n={};for(const a in t){const e=t[a].value;n[a]={value:e},e===null?n[a].value={src:""}:e.isTexture&&(n[a].value={src:e.image.src})}return n}function zn(t){switch(t){case"blendSrcAlpha":case"blendDstAlpha":case"blendEquationAlpha":case"clippingPlanes":case"shadowSide":case"precision":return!0}return!1}function He(t){const n={};for(const a in t){if(a.substring(0,1)==="_"||a.substring(0,2)==="is"||zn(a))continue;const e=typeof t[a],r=t[a];switch(e){case"boolean":case"number":case"string":n[a]=r;break;case"object":if(r!==null)if(n[a]=r,r.isTexture)if(r instanceof c.Texture){const s=r.source.toJSON();n[a]={src:s.url}}else r instanceof c.CubeTexture&&(console.log("env map"),console.log(r.source.data),console.log(r.source.toJSON()),n[a]={src:""});else a==="uniforms"&&(n[a]=Vn(n[a]));else n[a]={src:""};break}}return n}function jt(t){t.updateMatrix();const n={name:t.name,type:t.type,uuid:t.uuid,visible:t.visible,matrix:t.matrix.elements,animations:[],material:void 0,perspectiveCameraInfo:void 0,orthographicCameraInfo:void 0,lightInfo:void 0};t.animations.forEach(e=>{n.animations.push({name:e.name,duration:e.duration,blendMode:e.blendMode})});const a=t.type.toLowerCase();if(a.search("mesh")>-1){const e=t;if(Array.isArray(e.material)){const r=[];e.material.forEach(s=>{r.push(He(s))}),n.material=r}else n.material=He(e.material)}else if(a.search("points")>-1){const e=t;if(Array.isArray(e.material)){const r=[];e.material.forEach(s=>{r.push(He(s))}),n.material=r}else n.material=He(e.material)}else if(a.search("line")>-1){const e=t;if(Array.isArray(e.material)){const r=[];e.material.forEach(s=>{r.push(He(s))}),n.material=r}else n.material=He(e.material)}else a.search("camera")>-1?t.type==="PerspectiveCamera"?n.perspectiveCameraInfo={fov:t.fov,zoom:t.zoom,near:t.near,far:t.far,focus:t.focus,aspect:t.aspect,filmGauge:t.filmGauge,filmOffset:t.filmOffset}:t.type==="OrthographicCamera"&&(n.orthographicCameraInfo={zoom:t.zoom,near:t.near,far:t.far,left:t.left,right:t.right,top:t.top,bottom:t.bottom}):a.search("light")>-1&&(n.lightInfo={color:t.color,intensity:t.intensity,decay:t.decay,distance:t.distance,angle:t.angle,penumbra:t.penumbra,groundColor:t.groundColor});return n}function Hn(t,n){const a=n.split(".");switch(a.length){case 1:return t[a[0]];case 2:return t[a[0]][a[1]];case 3:return t[a[0]][a[1]][a[2]];case 4:return t[a[0]][a[1]][a[2]][a[3]];case 5:return t[a[0]][a[1]][a[2]][a[3]][a[4]];case 6:return t[a[0]][a[1]][a[2]][a[3]][a[4]][a[5]]}}function ae(t,n,a){const e=n.split(".");switch(e.length){case 1:t[e[0]]=a;break;case 2:t[e[0]][e[1]]=a;break;case 3:t[e[0]][e[1]][e[2]]=a;break;case 4:t[e[0]][e[1]][e[2]][e[3]]=a;break;case 5:t[e[0]][e[1]][e[2]][e[3]][e[4]]=a;break}}function _t(t){return new Promise((n,a)=>{const e=new Image;e.onload=()=>{const r=new c.Texture(e);r.wrapS=c.RepeatWrapping,r.wrapT=c.RepeatWrapping,r.needsUpdate=!0,n(r)},e.onerror=a,e.src=t})}class an extends Qe{constructor(){super(...arguments);V(this,"scene")}getObject(a){this.app.debugEnabled&&this.app.send({event:"getObject",target:"app",data:a})}setObject(a){const e=jt(a);this.app.send({event:"setObject",target:"editor",data:e})}requestMethod(a,e,r,s){this.app.send({event:"requestMethod",target:"app",data:{uuid:a,key:e,value:r,subitem:s}})}updateObject(a,e,r){this.app.send({event:"updateObject",target:"app",data:{uuid:a,key:e,value:r}})}createTexture(a,e,r){this.app.send({event:"createTexture",target:"app",data:{uuid:a,key:e,value:r}})}setScene(a){if(a===void 0||(this.scene=a,!this.app.debugEnabled))return;qt(),Pt(this.scene);const e=nn(this.scene);this.app.send({event:"setScene",target:"editor",data:e})}addCamera(a){if(!this.app.debugEnabled)return;const e=jt(a);this.app.send({event:"addCamera",target:"editor",data:e})}removeCamera(a){if(!this.app.debugEnabled)return;const e=jt(a);this.app.send({event:"removeCamera",target:"editor",data:e})}}function Yn(t,n){switch(n.event){case"getObject":I.dispatchEvent({type:N.GET_OBJECT,value:n.data});break;case"updateObject":I.dispatchEvent({type:N.UPDATE_OBJECT,value:n.data});break;case"createTexture":I.dispatchEvent({type:N.CREATE_TEXTURE,value:n.data});break;case"requestMethod":I.dispatchEvent({type:N.REQUEST_METHOD,value:n.data});break}}function Gn(t,n){switch(n.event){case"setObject":I.dispatchEvent({type:N.SET_OBJECT,value:n.data});break;case"setScene":I.dispatchEvent({type:N.SET_SCENE,value:n.data});break;case"addCamera":I.dispatchEvent({type:N.ADD_CAMERA,value:n.data});break;case"removeCamera":I.dispatchEvent({type:N.REMOVE_CAMERA,value:n.data});break}}class Dt extends Qe{constructor(a){super(a);V(this,"bindCBs");V(this,"buttonCBs");V(this,"pane");V(this,"appCallbacks",0);V(this,"editorCallbacks",0);V(this,"inspectorFolder");this.bindCBs=new Map,this.buttonCBs=new Map,a.editor&&this.createGUI()}createGUI(){this.pane=new Rn.Pane({title:"GUI"}),this.pane.registerPlugin(kn)}dispose(){var a;this.bindCBs.clear(),this.buttonCBs.clear(),this.appCallbacks=0,this.editorCallbacks=0,this.app.editor&&((a=this.pane)==null||a.dispose(),this.pane=void 0)}addFolder(a,e=void 0,r=void 0){if(this.app.editor)return this.pane===void 0&&this.createGUI(),(r!==void 0?r:this.pane).addFolder({title:a,...e});this.app.send({event:"addFolder",target:"app",data:{name:a,params:e,parent:r}})}get bindID(){return`debug_${Math.max(this.appCallbacks,this.editorCallbacks)}`}bind(a,e,r,s=void 0){const p=this.bindID,l=r.onChange!==void 0?r.onChange:tn;this.bindCBs.set(p,l),this.app.editor?(this.pane===void 0&&this.createGUI(),(s!==void 0?s:this.pane).addBinding(a,e,r).on("change",f=>{this.app.send({event:"updateBind",target:"app",data:{id:p,value:f.value}})}),this.editorCallbacks++):(this.app.send({event:"bindObject",target:"app",data:{id:p,name:e,params:r,parent:s}}),this.appCallbacks++)}triggerBind(a,e){const r=this.bindCBs.get(a);r!==void 0?r(e):console.warn(`No callback for: ${a}`,e)}button(a,e,r=void 0){const s=this.bindID;this.buttonCBs.set(s,e),this.app.editor?(this.pane===void 0&&this.createGUI(),(r!==void 0?r:this.pane).addButton({title:a}).on("click",()=>{this.app.send({event:"clickButton",target:"app",data:{id:s}})}),this.editorCallbacks++):(this.app.send({event:"addButton",target:"app",data:{id:s,name:a,callback:e,parent:r}}),this.appCallbacks++)}triggerButton(a){const e=this.buttonCBs.get(a);e!==void 0&&e()}createInspector(){this.inspectorFolder=this.addFolder("Inspector",this.pane)}clearInspector(){const a=this.inspectorFolder.children.length-1;for(let e=a;e>-1;--e)this.inspectorFolder.remove(this.inspectorFolder.children[e])}}function Wn(t,n){t.components.forEach(a=>{if(a instanceof Dt){const e=a;switch(n.event){case"addFolder":e.addFolder(n.data.name,n.data.params,n.data.parent);break;case"bindObject":e.bind(n.data.name,n.data.params,n.data.parent);break;case"updateBind":e.triggerBind(n.data.id,n.data.value);break;case"addButton":e.button(n.data.name,n.data.callback,n.data.parent);break;case"clickButton":e.triggerButton(n.data.id);break}return}})}var It={exports:{}},qe={};/**
|
1
|
+
(function(w,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("three"),require("@theatre/core"),require("@theatre/studio"),require("tweakpane"),require("@tweakpane/plugin-essentials"),require("react"),require("framer-motion")):typeof define=="function"&&define.amd?define(["exports","three","@theatre/core","@theatre/studio","tweakpane","@tweakpane/plugin-essentials","react","framer-motion"],c):(w=typeof globalThis<"u"?globalThis:w||self,c(w.Hermes={},w.three,w["@theatre/core"],w["@theatre/studio"],w.tweakpane,w["tweakpane-plugin-essentials"],w.react,w["framer-motion"]))})(this,function(w,c,Ce,Je,Rn,An,P,Xt){"use strict";var Na=Object.defineProperty;var La=(w,c,Ce)=>c in w?Na(w,c,{enumerable:!0,configurable:!0,writable:!0,value:Ce}):w[c]=Ce;var V=(w,c,Ce)=>(La(w,typeof c!="symbol"?c+"":c,Ce),Ce);function Pn(t){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const e=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(n,a,e.get?e:{enumerable:!0,get:()=>t[a]})}}return n.default=t,Object.freeze(n)}const kn=Pn(An);function ze(t){return t.substring(0,1).toUpperCase()+t.substring(1)}function jn(t,n,a){return Math.min(n,Math.max(t,a))}function _n(t,n){const a=t-n;return Math.sqrt(a*a)}function Zt(){return Math.round(Math.random()*1e6).toString()}function Jt(t){return t.r!==void 0&&t.g!==void 0&&t.b!==void 0}function Qt(t){const n=Math.round(t.r*255),a=Math.round(t.g*255),e=Math.round(t.b*255),r=u=>{const f=u.toString(16);return f.length===1?"0"+f:f},s=r(n),p=r(a),l=r(e);return"#"+s+p+l}function ft(t,n=1){return Number(t.toFixed(n))}w.totalThreeObjects=0;const qt=()=>{w.totalThreeObjects=0},Pt=t=>{if(!t)return;let n=t.name.replace(" ","");n.length===0&&(n=`obj_${w.totalThreeObjects}`,w.totalThreeObjects++),t.parent!==null&&(n=`${t.parent.uuid}.${n}`),t.uuid=n,t.children.forEach(a=>{Pt(a)})},Dn=t=>{t==null||t.dispose()},$t=t=>{t&&(Array.isArray(t)?t.forEach(n=>n.dispose()):t.dispose())},kt=t=>{var n;if(t){for(;t.children.length>0;){const a=t.children[0];a instanceof c.PositionalAudio?(a.pause(),a.parent&&a.parent.remove(a)):kt(a)}if(t.parent&&t.parent.remove(t),t.isMesh){const a=t;(n=a.geometry)==null||n.dispose(),$t(a.material)}t.dispose!==void 0&&t.dispose()}};class In{constructor(n,a,e=!0,r="editor"){V(this,"components",new Map);V(this,"listen");V(this,"_debugEnabled");V(this,"broadcastChannel");V(this,"webSocket");V(this,"_mode","app");V(this,"_connected",!1);V(this,"useBC",!1);V(this,"messageHandler",n=>{this.listen!==void 0&&(this.useBC?this.listen(n.data):this.listen(JSON.parse(n.data)))});V(this,"openHandler",()=>{this._connected=!0});V(this,"closeHandler",()=>{this._connected=!1});this.editor=a&&document.location.hash.search(r)>-1,this._debugEnabled=a,a&&(this.useBC=e,e?(this.broadcastChannel=new BroadcastChannel(n),this.broadcastChannel.addEventListener("message",this.messageHandler)):(this.webSocket=new WebSocket(n),this.webSocket.addEventListener("open",this.openHandler),this.webSocket.addEventListener("close",this.closeHandler),this.webSocket.addEventListener("message",this.messageHandler)))}addComponent(n,a){this.components.set(n,a)}dispose(){this.broadcastChannel!==void 0&&this.broadcastChannel.removeEventListener("message",this.messageHandler),this.webSocket!==void 0&&(this.webSocket.removeEventListener("open",this.openHandler),this.webSocket.removeEventListener("close",this.closeHandler),this.webSocket.removeEventListener("message",this.messageHandler)),this.components.forEach(n=>{n.dispose()}),this.components.clear()}send(n){var a,e;this._mode!==n.target&&(this.useBC?(a=this.broadcastChannel)==null||a.postMessage(n):this._connected&&((e=this.webSocket)==null||e.send(JSON.stringify(n))))}get connected(){return this._connected}get debugEnabled(){return this._debugEnabled}get mode(){return this._mode}get isApp(){return this._mode==="app"}get editor(){return this._mode==="editor"}set editor(n){n&&(this._mode="editor",document.title+=" - Editor")}}const I=new c.EventDispatcher,N={CUSTOM:"ToolEvents::custom",SELECT_DROPDOWN:"ToolEvents::selectDropdown",DRAG_UPDATE:"ToolEvents::dragUpdate",SET_SCENE:"ToolEvents::setScene",GET_OBJECT:"ToolEvents::getObject",SET_OBJECT:"ToolEvents::setObject",UPDATE_OBJECT:"ToolEvents::updateObject",CREATE_TEXTURE:"ToolEvents::createTexture",REQUEST_METHOD:"ToolEvents::requestMethod",ADD_CAMERA:"ToolEvents::addCamera",REMOVE_CAMERA:"ToolEvents::removeCamera"};class Qe{constructor(n){V(this,"app");this.app=n}dispose(){}}class en extends Qe{selectDropdown(n,a){this.app.send({event:"selectComponent",target:"app",data:{dropdown:n,value:a}})}updateDropdown(n,a){this.app.send({event:"draggableListUpdate",target:"app",data:{dropdown:n,value:a}})}}function Nn(t,n){switch(n.event){case"selectComponent":I.dispatchEvent({type:N.SELECT_DROPDOWN,value:n.data});break;case"draggableListUpdate":I.dispatchEvent({type:N.DRAG_UPDATE,value:n.data});break}}const tn=()=>{},Ge=class Ge extends Qe{constructor(){super(...arguments);V(this,"project");V(this,"sheets",new Map);V(this,"sheetObjects",new Map);V(this,"sheetObjectCBs",new Map);V(this,"sheetObjectUnsubscribe",new Map)}init(a,e){return this.project=Ce.getProject(a,e),this.project.ready}dispose(){this.project=void 0,this.sheets=new Map,this.sheetObjects=new Map,this.sheetObjectCBs=new Map,this.sheetObjectUnsubscribe=new Map}sheet(a){var r;if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}let e=this.sheets.get(a);return e!==void 0||(e=(r=this.project)==null?void 0:r.sheet(a),this.sheets.set(a,e)),e}playSheet(a,e){var r;(r=this.sheet(a))==null||r.sequence.play(e),this.app.send({event:"playSheet",target:"editor",data:{sheet:a,value:e}})}pauseSheet(a){var e;(e=this.sheet(a))==null||e.sequence.pause(),this.app.send({event:"pauseSheet",target:"editor",data:{sheet:a}})}clearSheetObjects(a){this.sheetObjects.forEach((e,r)=>{r.search(`${a}_`)>-1&&this.unsubscribe(e)})}sheetObject(a,e,r,s){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const p=this.sheet(a);if(p===void 0)return;const l=`${a}_${e}`;let u=this.sheetObjects.get(l);u!==void 0?u=p.object(e,{...r,...u.value},{reconfigure:!0}):u=p.object(e,r),this.sheetObjects.set(l,u),this.sheetObjectCBs.set(l,s!==void 0?s:tn);const f=u.onValuesChange(y=>{if(this.app.editor){for(const C in y){const x=y[C];typeof x=="object"&&Jt(x)&&(y[C]={r:x.r,g:x.g,b:x.b,a:x.a})}this.app.send({event:"updateSheetObject",target:"app",data:{sheet:a,sheetObject:l,values:y}})}const v=this.sheetObjectCBs.get(l);v!==void 0&&v(y)});return this.sheetObjectUnsubscribe.set(l,f),u}unsubscribe(a){if(this.project===void 0){console.error("Theatre Project hasn't been created yet.");return}const e=a.address.sheetId,r=a.address.objectKey,s=this.sheets.get(e);s==null||s.detachObject(r);const p=`${e}_${r}`,l=this.sheetObjectUnsubscribe.get(p);l!==void 0&&(this.sheetObjects.delete(p),this.sheetObjectCBs.delete(p),this.sheetObjectUnsubscribe.delete(p),l())}static getRafDriver(){return Ge.rafDriver||(Ge.rafDriver=Ce.createRafDriver()),Ge.rafDriver}};V(Ge,"rafDriver",null);let Me=Ge,Se;function Ln(t,n){t.components.forEach(a=>{if(a instanceof Me){let e;const r=a;switch(n.event){case"setSheet":e=r.sheets.get(n.data.sheet),e!==void 0&&(Se=e,Je.setSelection([e]));break;case"setSheetObject":e=r.sheetObjects.get(`${n.data.sheet}_${n.data.key}`),e!==void 0&&Je.setSelection([e]);break;case"updateSheetObject":e=r.sheets.get(n.data.sheet),e!==void 0&&e.sequence.pause(),e=r.sheetObjectCBs.get(n.data.sheetObject),e!==void 0&&e(n.data.values);break;case"updateTimeline":e=r.sheets.get(n.data.sheet),Se!==void 0&&(Se.sequence.position=n.data.position);break}}})}function Fn(t){if(t.editor){let n;t.components.forEach(s=>{s instanceof Me&&(n=s)}),Je.ui.restore(),Je.onSelectionChange(s=>{s.length<1||s.forEach(p=>{let l=p.address.sheetId,u="setSheet",f={};switch(p.type){case"Theatre_Sheet_PublicAPI":u="setSheet",f={sheet:p.address.sheetId},Se=n.sheets.get(p.address.sheetId);break;case"Theatre_SheetObject_PublicAPI":u="setSheetObject",l+=`_${p.address.objectKey}`,f={id:l,sheet:p.address.sheetId,key:p.address.objectKey};break}t.send({event:u,target:"app",data:f})})});let a=0;const e=()=>{if(Se!==void 0&&a!==Se.sequence.position){a=Se.sequence.position;const s=Se;t.send({event:"updateTimeline",target:"app",data:{position:a,sheet:s.address.sheetId}})}},r=()=>{e(),requestAnimationFrame(r)};e(),r()}else Je.ui.hide()}function Un(t,n){t.editor&&t.components.forEach(a=>{var e,r;if(a instanceof Me){const s=a;switch(n.event){case"playSheet":(e=s.sheet(n.data.sheet))==null||e.sequence.play(n.data.value);break;case"pauseSheet":(r=s.sheet(n.data.sheet))==null||r.sequence.pause();break}return}})}function Bn(t){if(t.name==="cameras")return"camera";if(t.name==="interactive")return"interactive";if(t.name==="lights")return"light";if(t.name==="ui")return"ui";if(t.name==="utils")return"utils";const n=t.type;return n.search("Helper")>-1?"icon_utils":n.search("Camera")>-1?"camera":n.search("Light")>-1?"light":"obj3D"}function nn(t){const n={name:t.name,type:t.type,uuid:t.uuid,children:[]};return t.children.forEach(a=>{n.children.push(nn(a))}),n}function Vn(t){const n={};for(const a in t){const e=t[a].value;n[a]={value:e},e===null?n[a].value={src:""}:e.isTexture&&(n[a].value={src:e.image.src})}return n}function zn(t){switch(t){case"blendSrcAlpha":case"blendDstAlpha":case"blendEquationAlpha":case"clippingPlanes":case"shadowSide":case"precision":return!0}return!1}function He(t){const n={};for(const a in t){if(a.substring(0,1)==="_"||a.substring(0,2)==="is"||zn(a))continue;const e=typeof t[a],r=t[a];switch(e){case"boolean":case"number":case"string":n[a]=r;break;case"object":if(r!==null)if(n[a]=r,r.isTexture)if(r instanceof c.Texture){const s=r.source.toJSON();n[a]={src:s.url}}else r instanceof c.CubeTexture&&(console.log("env map"),console.log(r.source.data),console.log(r.source.toJSON()),n[a]={src:""});else a==="uniforms"&&(n[a]=Vn(n[a]));else n[a]={src:""};break}}return n}function jt(t){t.updateMatrix();const n={name:t.name,type:t.type,uuid:t.uuid,visible:t.visible,matrix:t.matrix.elements,animations:[],material:void 0,perspectiveCameraInfo:void 0,orthographicCameraInfo:void 0,lightInfo:void 0};t.animations.forEach(e=>{n.animations.push({name:e.name,duration:e.duration,blendMode:e.blendMode})});const a=t.type.toLowerCase();if(a.search("mesh")>-1){const e=t;if(Array.isArray(e.material)){const r=[];e.material.forEach(s=>{r.push(He(s))}),n.material=r}else n.material=He(e.material)}else if(a.search("points")>-1){const e=t;if(Array.isArray(e.material)){const r=[];e.material.forEach(s=>{r.push(He(s))}),n.material=r}else n.material=He(e.material)}else if(a.search("line")>-1){const e=t;if(Array.isArray(e.material)){const r=[];e.material.forEach(s=>{r.push(He(s))}),n.material=r}else n.material=He(e.material)}else a.search("camera")>-1?t.type==="PerspectiveCamera"?n.perspectiveCameraInfo={fov:t.fov,zoom:t.zoom,near:t.near,far:t.far,focus:t.focus,aspect:t.aspect,filmGauge:t.filmGauge,filmOffset:t.filmOffset}:t.type==="OrthographicCamera"&&(n.orthographicCameraInfo={zoom:t.zoom,near:t.near,far:t.far,left:t.left,right:t.right,top:t.top,bottom:t.bottom}):a.search("light")>-1&&(n.lightInfo={color:t.color,intensity:t.intensity,decay:t.decay,distance:t.distance,angle:t.angle,penumbra:t.penumbra,groundColor:t.groundColor});return n}function Hn(t,n){const a=n.split(".");switch(a.length){case 1:return t[a[0]];case 2:return t[a[0]][a[1]];case 3:return t[a[0]][a[1]][a[2]];case 4:return t[a[0]][a[1]][a[2]][a[3]];case 5:return t[a[0]][a[1]][a[2]][a[3]][a[4]];case 6:return t[a[0]][a[1]][a[2]][a[3]][a[4]][a[5]]}}function ae(t,n,a){const e=n.split(".");switch(e.length){case 1:t[e[0]]=a;break;case 2:t[e[0]][e[1]]=a;break;case 3:t[e[0]][e[1]][e[2]]=a;break;case 4:t[e[0]][e[1]][e[2]][e[3]]=a;break;case 5:t[e[0]][e[1]][e[2]][e[3]][e[4]]=a;break}}function _t(t){return new Promise((n,a)=>{const e=new Image;e.onload=()=>{const r=new c.Texture(e);r.wrapS=c.RepeatWrapping,r.wrapT=c.RepeatWrapping,r.needsUpdate=!0,n(r)},e.onerror=a,e.src=t})}class an extends Qe{constructor(){super(...arguments);V(this,"scene")}getObject(a){this.app.debugEnabled&&this.app.send({event:"getObject",target:"app",data:a})}setObject(a){const e=jt(a);this.app.send({event:"setObject",target:"editor",data:e})}requestMethod(a,e,r,s){this.app.send({event:"requestMethod",target:"app",data:{uuid:a,key:e,value:r,subitem:s}})}updateObject(a,e,r){this.app.send({event:"updateObject",target:"app",data:{uuid:a,key:e,value:r}})}createTexture(a,e,r){this.app.send({event:"createTexture",target:"app",data:{uuid:a,key:e,value:r}})}setScene(a){if(a===void 0||(this.scene=a,!this.app.debugEnabled))return;qt(),Pt(this.scene);const e=nn(this.scene);this.app.send({event:"setScene",target:"editor",data:e})}addCamera(a){if(!this.app.debugEnabled)return;const e=jt(a);this.app.send({event:"addCamera",target:"editor",data:e})}removeCamera(a){if(!this.app.debugEnabled)return;const e=jt(a);this.app.send({event:"removeCamera",target:"editor",data:e})}}function Yn(t,n){switch(n.event){case"getObject":I.dispatchEvent({type:N.GET_OBJECT,value:n.data});break;case"updateObject":I.dispatchEvent({type:N.UPDATE_OBJECT,value:n.data});break;case"createTexture":I.dispatchEvent({type:N.CREATE_TEXTURE,value:n.data});break;case"requestMethod":I.dispatchEvent({type:N.REQUEST_METHOD,value:n.data});break}}function Gn(t,n){switch(n.event){case"setObject":I.dispatchEvent({type:N.SET_OBJECT,value:n.data});break;case"setScene":I.dispatchEvent({type:N.SET_SCENE,value:n.data});break;case"addCamera":I.dispatchEvent({type:N.ADD_CAMERA,value:n.data});break;case"removeCamera":I.dispatchEvent({type:N.REMOVE_CAMERA,value:n.data});break}}class Dt extends Qe{constructor(a){super(a);V(this,"bindCBs");V(this,"buttonCBs");V(this,"pane");V(this,"appCallbacks",0);V(this,"editorCallbacks",0);V(this,"inspectorFolder");this.bindCBs=new Map,this.buttonCBs=new Map,a.editor&&this.createGUI()}createGUI(){this.pane=new Rn.Pane({title:"GUI"}),this.pane.registerPlugin(kn)}dispose(){var a;this.bindCBs.clear(),this.buttonCBs.clear(),this.appCallbacks=0,this.editorCallbacks=0,this.app.editor&&((a=this.pane)==null||a.dispose(),this.pane=void 0)}addFolder(a,e=void 0,r=void 0){if(this.app.editor)return this.pane===void 0&&this.createGUI(),(r!==void 0?r:this.pane).addFolder({title:a,...e});this.app.send({event:"addFolder",target:"app",data:{name:a,params:e,parent:r}})}get bindID(){return`debug_${Math.max(this.appCallbacks,this.editorCallbacks)}`}bind(a,e,r,s=void 0){const p=this.bindID,l=r.onChange!==void 0?r.onChange:tn;this.bindCBs.set(p,l),this.app.editor?(this.pane===void 0&&this.createGUI(),(s!==void 0?s:this.pane).addBinding(a,e,r).on("change",f=>{this.app.send({event:"updateBind",target:"app",data:{id:p,value:f.value}})}),this.editorCallbacks++):(this.app.send({event:"bindObject",target:"app",data:{id:p,name:e,params:r,parent:s}}),this.appCallbacks++)}triggerBind(a,e){const r=this.bindCBs.get(a);r!==void 0?r(e):console.warn(`No callback for: ${a}`,e)}button(a,e,r=void 0){const s=this.bindID;this.buttonCBs.set(s,e),this.app.editor?(this.pane===void 0&&this.createGUI(),(r!==void 0?r:this.pane).addButton({title:a}).on("click",()=>{this.app.send({event:"clickButton",target:"app",data:{id:s}})}),this.editorCallbacks++):(this.app.send({event:"addButton",target:"app",data:{id:s,name:a,callback:e,parent:r}}),this.appCallbacks++)}triggerButton(a){const e=this.buttonCBs.get(a);e!==void 0&&e()}createInspector(){this.inspectorFolder=this.addFolder("Inspector",this.pane)}clearInspector(){const a=this.inspectorFolder.children.length-1;for(let e=a;e>-1;--e)this.inspectorFolder.remove(this.inspectorFolder.children[e])}}function Wn(t,n){t.components.forEach(a=>{if(a instanceof Dt){const e=a;switch(n.event){case"addFolder":e.addFolder(n.data.name,n.data.params,n.data.parent);break;case"bindObject":e.bind(n.data.name,n.data.params,n.data.parent);break;case"updateBind":e.triggerBind(n.data.id,n.data.value);break;case"addButton":e.button(n.data.name,n.data.callback,n.data.parent);break;case"clickButton":e.triggerButton(n.data.id);break}return}})}var It={exports:{}},qe={};/**
|
2
2
|
* @license React
|
3
3
|
* react-jsx-runtime.production.min.js
|
4
4
|
*
|
package/package.json
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
"module": "./dist/hermes.js",
|
8
8
|
"types": "./types/index.d.ts",
|
9
9
|
"type": "module",
|
10
|
-
"version": "0.0.
|
10
|
+
"version": "0.0.34",
|
11
11
|
"homepage": "https://github.com/tomorrowevening/hermes#readme",
|
12
12
|
"bugs": {
|
13
13
|
"url": "https://github.com/tomorrowevening/hermes/issues"
|
@@ -30,14 +30,12 @@
|
|
30
30
|
],
|
31
31
|
"exports": {
|
32
32
|
".": {
|
33
|
-
"default": "./dist/hermes.umd.cjs",
|
34
33
|
"import": "./dist/hermes.js",
|
35
34
|
"require": "./dist/hermes.umd.cjs",
|
36
35
|
"types": "./types/index.d.ts"
|
37
36
|
},
|
38
37
|
"./dist/style.css": "./dist/style.css",
|
39
|
-
"./server/index.mjs": "./server/index.mjs"
|
40
|
-
"./src/*": "./src/*"
|
38
|
+
"./server/index.mjs": "./server/index.mjs"
|
41
39
|
},
|
42
40
|
"repository": {
|
43
41
|
"type": "git",
|
package/src/core/Application.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import BaseRemote from './remote/BaseRemote';
|
2
|
-
import
|
2
|
+
import { ApplicationMode, BroadcastCallback, BroadcastData } from './types';
|
3
3
|
|
4
4
|
export default class Application {
|
5
5
|
components: Map<string, any> = new Map();
|
@@ -1,7 +1,7 @@
|
|
1
1
|
// Core
|
2
2
|
import Application from './Application';
|
3
3
|
import { ToolEvents, debugDispatcher } from '@/editor/global';
|
4
|
-
import
|
4
|
+
import { BroadcastData } from './types';
|
5
5
|
import BaseRemote from './remote/BaseRemote';
|
6
6
|
import RemoteComponents, { HandleAppRemoteComponents } from './remote/RemoteComponents';
|
7
7
|
import RemoteTheatre, { HandleAppRemoteTheatre, HandleEditorRemoteTheatre, UpdateRemoteTheatre } from './remote/RemoteTheatre';
|
@@ -1,13 +1,12 @@
|
|
1
1
|
// Libs
|
2
2
|
import { createRafDriver, getProject } from '@theatre/core';
|
3
|
-
import
|
3
|
+
import { IProject, IProjectConfig, IRafDriver, ISheet, ISheetObject } from '@theatre/core';
|
4
4
|
import studio from '@theatre/studio';
|
5
5
|
// Core
|
6
6
|
import Application from '../Application';
|
7
7
|
import BaseRemote from './BaseRemote';
|
8
8
|
import { isColor } from '@/editor/utils';
|
9
|
-
import { BroadcastData, EditorEvent, noop } from '../types';
|
10
|
-
import type { DataUpdateCallback, VoidCallback } from '../types';
|
9
|
+
import { BroadcastData, DataUpdateCallback, EditorEvent, VoidCallback, noop } from '../types';
|
11
10
|
|
12
11
|
export default class RemoteTheatre extends BaseRemote {
|
13
12
|
project: IProject | undefined;
|
@@ -4,8 +4,7 @@ import * as EssentialsPlugin from '@tweakpane/plugin-essentials';
|
|
4
4
|
// Core
|
5
5
|
import Application from '../Application';
|
6
6
|
import BaseRemote from './BaseRemote';
|
7
|
-
import { BroadcastData, noop } from '../types';
|
8
|
-
import type { DataUpdateCallback, VoidCallback } from '../types';
|
7
|
+
import { BroadcastData, DataUpdateCallback, VoidCallback, noop } from '../types';
|
9
8
|
|
10
9
|
export default class RemoteTweakpane extends BaseRemote {
|
11
10
|
bindCBs: Map<string, DataUpdateCallback>;
|
@@ -3,7 +3,7 @@ import { useState } from 'react';
|
|
3
3
|
// Components
|
4
4
|
import Draggable from './Draggable';
|
5
5
|
import Dropdown from './Dropdown';
|
6
|
-
import
|
6
|
+
import { DropdownItemProps, DropdownOption } from './types';
|
7
7
|
// Utils
|
8
8
|
import { randomID } from '../utils';
|
9
9
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { Object3D } from 'three';
|
2
2
|
import ChildObject from './ChildObject';
|
3
|
-
import
|
3
|
+
import { ChildObjectProps } from './types';
|
4
4
|
|
5
5
|
export default function ContainerObject(props: ChildObjectProps) {
|
6
6
|
const children: Array<any> = [];
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import BaseRemote from './remote/BaseRemote';
|
2
|
-
import
|
2
|
+
import { ApplicationMode, BroadcastCallback, BroadcastData } from './types';
|
3
3
|
export default class Application {
|
4
4
|
components: Map<string, any>;
|
5
5
|
listen?: BroadcastCallback;
|
@@ -1,8 +1,7 @@
|
|
1
|
-
import
|
1
|
+
import { IProject, IProjectConfig, IRafDriver, ISheet, ISheetObject } from '@theatre/core';
|
2
2
|
import Application from '../Application';
|
3
3
|
import BaseRemote from './BaseRemote';
|
4
|
-
import { BroadcastData } from '../types';
|
5
|
-
import type { DataUpdateCallback, VoidCallback } from '../types';
|
4
|
+
import { BroadcastData, DataUpdateCallback, VoidCallback } from '../types';
|
6
5
|
export default class RemoteTheatre extends BaseRemote {
|
7
6
|
project: IProject | undefined;
|
8
7
|
sheets: Map<string, ISheet>;
|
@@ -1,8 +1,7 @@
|
|
1
1
|
import { Pane } from 'tweakpane';
|
2
2
|
import Application from '../Application';
|
3
3
|
import BaseRemote from './BaseRemote';
|
4
|
-
import { BroadcastData } from '../types';
|
5
|
-
import type { DataUpdateCallback, VoidCallback } from '../types';
|
4
|
+
import { BroadcastData, DataUpdateCallback, VoidCallback } from '../types';
|
6
5
|
export default class RemoteTweakpane extends BaseRemote {
|
7
6
|
bindCBs: Map<string, DataUpdateCallback>;
|
8
7
|
buttonCBs: Map<string, VoidCallback>;
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import
|
1
|
+
import { DropdownItemProps } from './types';
|
2
2
|
export default function DropdownItem(props: DropdownItemProps): import("react/jsx-runtime").JSX.Element;
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import
|
1
|
+
import { ChildObjectProps } from './types';
|
2
2
|
export default function ContainerObject(props: ChildObjectProps): import("react/jsx-runtime").JSX.Element;
|