vue-blox-expressions
Version:
Adds scripting support to vue-blox.
2 lines (1 loc) • 2.45 kB
JavaScript
(function(t,r){typeof exports=="object"&&typeof module<"u"?r(exports):typeof define=="function"&&define.amd?define(["exports"],r):(t=typeof globalThis<"u"?globalThis:t||self,r(t["vue-blox-expressions"]={}))})(this,function(t){"use strict";var y=Object.defineProperty;var E=(t,r,u)=>r in t?y(t,r,{enumerable:!0,configurable:!0,writable:!0,value:u}):t[r]=u;var g=(t,r,u)=>(E(t,typeof r!="symbol"?r+"":r,u),u);class r{constructor(e){g(this,"parser");this.parser=e}run({context:e,key:s,value:n,variables:o,buildContext:c}){const i="compute:";if(!s.startsWith(i))return;const a=s.substring(i.length,s.length);if(a.length===0)throw new Error("The value for the prop name for compute must be a string with length > 0.");const l=JSON.parse(JSON.stringify(o??{})),h=this.evaluate(n,l);e.setProp({propName:a,value:h})}evaluate(e,s){if(typeof e=="string"){const n=e;if(/^__proto__|prototype|constructor$/.test(n))throw new Error(`The call to parser.evaluate() for value ${e} was aborted because prototype access was detected.`);try{return this.parser.evaluate(n,s)}catch(o){throw new Error(`The call to parser.evaluate() for value ${e} threw the error: ${o}`)}}else if(typeof e=="object"&&Array.isArray(e)){const n=[];for(let o=0;o<e.length;o+=1){const c=e[o],i=this.evaluate(c,s);n.push(i)}return n}else if(typeof e=="object"){const n={},o=Object.keys(e);for(let c=0;c<o.length;c+=1){const i=o[c],a=e[i],l=this.evaluate(a,s);n[i]=l}return n}}}function u({parser:p}){return new r(p)}class w{constructor(e){g(this,"parser");this.parser=e}run({context:e,key:s,value:n,variables:o,buildContext:c}){const i="event:";if(!s.startsWith(i))return;const a=s.substring(i.length,s.length);if(a.length===0)throw new Error("The value for the prop name for event must be a string with length > 0.");const l=n,h=`on${a.charAt(0).toUpperCase()}${a.slice(1)}`,d=JSON.parse(JSON.stringify(o??{}));e.setProp({propName:h,value:(...b)=>{if(/^__proto__|prototype|constructor$/.test(l))throw new Error(`The call to parser.evaluate() for value ${n} was aborted because prototype access was detected.`);Object.assign(d,b);try{this.parser.functions.setVariable=(f,v)=>{o[f]=v},this.parser.evaluate(l,d)}catch(f){throw new Error(`The call to parser.evaluate() for value ${n} threw the error: ${f}`)}}})}}function m({parser:p}){return new w(p)}t.BloxPluginCompute=r,t.BloxPluginEvent=w,t.getPluginCompute=u,t.getPluginEvent=m,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});