import{i as A,F,R as c}from"./declarationMapper-Lanf6XPr.js";import{C as w,b9 as y,V as j,ai as I,R as _}from"./index-CDrXokXW.js";import{F as N}from"./flowGraphCachedOperationBlock-CAD6CbqU.js";import"./index-DWyDLubb.js";import"./KHR_interactivity-BtMudStn.js";import"./objectModelMapping-CGWnurZP.js";const g=new RegExp(/\/\{(\w+)\}(?=\/|$)/g);class V{constructor(r,s){this.path=r,this.ownerBlock=s,this.templatedInputs=[];let n=g.exec(r);const o=new Set;for(;n;){const[,e]=n;if(o.has(e))throw new Error("Duplicate template variable detected.");o.add(e),this.templatedInputs.push(s.registerDataInput(e,A,new F(0))),n=g.exec(r)}}getAccessor(r,s){let n=this.path;for(const o of this.templatedInputs){const e=o.getValue(s).value;if(typeof e!="number"||e<0)throw new Error("Invalid value for templated input.");n=n.replace(`{${o.name}}`,e.toString())}return r.convert(n)}}class D extends N{constructor(r){super(c,r),this.config=r,this.object=this.registerDataOutput("object",c),this.propertyName=this.registerDataOutput("propertyName",c),this.setterFunction=this.registerDataOutput("setFunction",c,this._setPropertyValue.bind(this)),this.getterFunction=this.registerDataOutput("getFunction",c,this._getPropertyValue.bind(this)),this.generateAnimationsFunction=this.registerDataOutput("generateAnimationsFunction",c,this._getInterpolationAnimationPropertyInfo.bind(this)),this.templateComponent=new V(r.jsonPointer,this)}_doOperation(r){const s=this.templateComponent.getAccessor(this.config.pathConverter,r),n=s.info.get(s.object),o=s.info.getTarget?.(s.object),e=s.info.getPropertyName?.[0](s.object);if(o)this.object.setValue(o,r),e&&this.propertyName.setValue(e,r);else throw new Error("Object is undefined");return n}_setPropertyValue(r,s,n,o){const e=this.templateComponent.getAccessor(this.config.pathConverter,o),a=e.info.type;a.startsWith("Color")&&(n=C(n,a)),e.info.set?.(n,e.object)}_getPropertyValue(r,s,n){const o=this.templateComponent.getAccessor(this.config.pathConverter,n),e=o.info.type,a=o.info.get(o.object);return e.startsWith("Color")?G(a):a}_getInterpolationAnimationPropertyInfo(r,s,n){const o=this.templateComponent.getAccessor(this.config.pathConverter,n);return(e,a,b,h)=>{const m=[],l=o.info.type;return l.startsWith("Color")&&(e=e.map(p=>({frame:p.frame,value:C(p.value,l)}))),o.info.interpolation?.forEach((p,f)=>{const d=o.info.getPropertyName?.[f](o.object)||"Animation-interpolation-"+f;let u=e;b!==p.type&&(u=e.map(i=>({frame:i.frame,value:p.getValue(void 0,i.value.asArray?i.value.asArray():[i.value],0,1)})));const P=p.buildAnimations(o.object,d,60,u);for(const i of P)h&&i.babylonAnimation.setEasingFunction(h),m.push(i.babylonAnimation)}),m}}getClassName(){return"FlowGraphJsonPointerParserBlock"}}function C(t,r){return t.getClassName().startsWith("Color")?t:r==="Color3"?new w(t.x,t.y,t.z):r==="Color4"?new y(t.x,t.y,t.z,t.w):t}function G(t){if(t instanceof w)return new j(t.r,t.g,t.b);if(t instanceof y)return new I(t.r,t.g,t.b,t.a);throw new Error("Invalid color type")}_("FlowGraphJsonPointerParserBlock",D);export{D as FlowGraphJsonPointerParserBlock};
