!function(t){function e(i){if(s[i])return s[i].exports;var o=s[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var s={};e.m=t,e.c=s,e.d=function(t,s,i){e.o(t,s)||Object.defineProperty(t,s,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var s=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(s,"a",s),s},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,s){"use strict";function i(t){let e=t.split(/(\w)\s*:\s*/).filter(t=>0!==t.length),s=[];for(var i=0;i<e.length;i+=2)s.push([e[i],e[i+1]]);return s}var o,r,n,a,l;if(Object.defineProperty(e,"__esModule",{value:!0}),o=s(1),r=s(2),n=s.n(r),a=s(4),s.n(a),l=function(){return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return function(t,e){var s,i,o=[],r=!0,n=!1,a=void 0;try{for(s=t[Symbol.iterator]();!(r=(i=s.next()).done)&&(o.push(i.value),!e||o.length!==e);r=!0);}catch(t){n=!0,a=t}finally{try{!r&&s.return&&s.return()}finally{if(n)throw a}}return o}(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),"undefined"==typeof AFRAME)throw Error("Component attempted to register before AFRAME was available.");AFRAME.registerComponent("lsystem",{schema:{axiom:{type:"string",default:"F"},productions:{default:"F:FF",parse:t=>i(t).map(t=>{var e=l(t,2);return[e[0],e[1].replace(/\s/g,"")]})},segmentMixins:{type:"string",parse:function(t){var e,s,o,r,n,a;let c=new Map,h=i(t);e=!0,s=!1,o=void 0;try{for(r=h[Symbol.iterator]();!(e=(n=r.next()).done);e=!0){let t=n.value,e=(a=l(t,2))[0],s=a[1];s=s.replace(/[\[\]]/g,"").split(","),c.set(e,s)}}catch(t){s=!0,o=t}finally{try{!e&&r.return&&r.return()}finally{if(s)throw o}}return c}},iterations:{type:"int",default:1},angle:{default:90},translateAxis:{type:"string",default:"y",parse:function(t){if("x"===(t=t.toLowerCase()))return new THREE.Vector3(1,0,0);if("y"===t)return new THREE.Vector3(0,1,0);if("z"===t)return new THREE.Vector3(0,0,1);throw Error('translateAxis has to be a string: "x", "y" or "z"')}},scaleFactor:{default:1},dynamicSegmentLength:{default:!0},mergeGeometries:{type:"boolean",default:!0},functionsInProductions:{type:"boolean",default:!0}},init:function(){this.sceneEl=document.querySelector("a-scene");let t=this;this.initWorker(),this.X=new THREE.Vector3(1,0,0),this.Y=new THREE.Vector3(0,1,0),this.Z=new THREE.Vector3(0,0,1),this.xPosRotation=new THREE.Quaternion,this.xNegRotation=new THREE.Quaternion,this.yPosRotation=new THREE.Quaternion,this.yNegRotation=new THREE.Quaternion,this.zPosRotation=new THREE.Quaternion,this.zNegRotation=new THREE.Quaternion,this.yReverseRotation=new THREE.Quaternion,this.xPosRotation=new THREE.Quaternion,this.xNegRotation=new THREE.Quaternion,this.yPosRotation=new THREE.Quaternion,this.yNegRotation=new THREE.Quaternion,this.zPosRotation=new THREE.Quaternion,this.zNegRotation=new THREE.Quaternion,this.yReverseRotation=new THREE.Quaternion,this.segmentLengthFactor=1,this.transformationSegment=new THREE.Object3D,this.transformationSegmentTemplate=this.transformationSegment.clone();let e=t.data.scaleFactor;this.colorIndex=0,this.lineWidth=5e-4,this.lineLength=.125,this.LSystem=new o.a({axiom:"F",productions:{F:"F"},finals:{"+":()=>{t.transformationSegment.quaternion.multiply(t.yPosRotation)},"-":()=>{t.transformationSegment.quaternion.multiply(t.yNegRotation)},"&":()=>{t.transformationSegment.quaternion.multiply(t.zNegRotation)},"^":()=>{t.transformationSegment.quaternion.multiply(t.zPosRotation)},"\\":()=>{t.transformationSegment.quaternion.multiply(t.xNegRotation)},"<":()=>{t.transformationSegment.quaternion.multiply(t.xNegRotation)},"/":()=>{t.transformationSegment.quaternion.multiply(t.xPosRotation)},">":()=>{t.transformationSegment.quaternion.multiply(t.xPosRotation)},"|":()=>{t.transformationSegment.quaternion.multiply(t.yReverseRotation)},"!":()=>{t.segmentLengthFactor*=e,t.transformationSegment.scale.set(t.transformationSegment.scale.x*=e,t.transformationSegment.scale.y*=e,t.transformationSegment.scale.z*=e),t.colorIndex++},"'":()=>{t.segmentLengthFactor*=1/e,t.transformationSegment.scale.set(t.transformationSegment.scale.x*=1/e,t.transformationSegment.scale.y*=1/e,t.transformationSegment.scale.z*=1/e),t.colorIndex=Math.max(0,t.colorIndex-1)},"[":()=>{t.stack.push(t.transformationSegment.clone())},"]":()=>{t.transformationSegment=t.stack.pop()}}})},update:function(t){var e,s,i,o,r;if(!1===this.data.mergeGeometries&&void 0!==this.segmentElementGroupsMap){e=!0,s=!1,i=void 0;try{for(o=this.segmentElementGroupsMap.values()[Symbol.iterator]();!(e=(r=o.next()).done);e=!0){let t=r.value;t.removeObject3D("mesh"),t.innerHTML=""}}catch(t){s=!0,i=t}finally{try{!e&&o.return&&o.return()}finally{if(s)throw i}}}if(0===Object.keys(t).length)this.updateLSystem(),this.updateSegmentMixins(),this.updateTurtleGraphics();else{let e=!1;(t.axiom&&t.axiom!==this.data.axiom||t.iterations&&t.iterations!==this.data.iterations||t.productions&&JSON.stringify(t.productions)!==JSON.stringify(this.data.productions))&&(this.updateLSystem(),e=!0),void 0!==t.segmentMixins&&JSON.stringify(Array.from(t.segmentMixins.entries()))!==JSON.stringify(Array.from(this.data.segmentMixins.entries()))&&(this.updateSegmentMixins(),e=!0),(e||t.angle&&t.angle!==this.data.angle)&&this.updateTurtleGraphics()}},calculateSegmentLength:function(t,e){if(this.segmentLengthMap.has(t))return this.segmentLengthMap.get(t);let s;return e.computeBoundingBox(),this.data.translateAxis.equals(this.X)?s=Math.abs(e.boundingBox.min.x-e.boundingBox.max.x):this.data.translateAxis.equals(this.Y)?s=Math.abs(e.boundingBox.min.y-e.boundingBox.max.y):this.data.translateAxis.equals(this.Z)&&(s=Math.abs(e.boundingBox.min.z-e.boundingBox.max.z)),this.segmentLengthMap.set(t,s),s},initWorker:function(){this.worker=new n.a},pushSegment:function(t){let e=this,s=e.transformationSegment.quaternion,i=e.transformationSegment.position,o=e.transformationSegment.scale,r=Math.min(this.colorIndex,this.data.segmentMixins.get(t).length-1),n=this.mixinMap.get(t+r);if(!1===this.data.mergeGeometries){let a=document.createElement("a-entity");a.setAttribute("mixin",n),a.addEventListener("loaded",()=>{let t=e.segmentLengthMap.get(n);a.object3D.children[0].translateOnAxis(e.data.translateAxis,t*e.segmentLengthFactor/2),a.object3D.quaternion.copy(s),a.object3D.position.copy(i),a.object3D.scale.copy(o)},{once:!0}),this.segmentElementGroupsMap.get(t+r).appendChild(a)}else{let e=this.segmentObjects3DMap.get(t+r).clone();e.matrixAutoUpdate=!1,e.quaternion.copy(s),e.position.copy(i),e.scale.copy(o),e.updateMatrix(),this.mergeGroups.get(t+r).geometry.merge(e.geometry,e.matrix)}let a=this.segmentLengthMap.get(n);this.transformationSegment.translateOnAxis(this.data.translateAxis,a*this.segmentLengthFactor)},updateLSystem:function(){let t=this,e={axiom:this.data.axiom,productions:this.data.productions,iterations:this.data.iterations};return Date.now()-this.worker.startTime>1e3&&(this.worker.terminate(),this.initWorker()),this.worker.startTime=Date.now(),this.workerPromise=new Promise(e=>{this.worker.onmessage=(s=>{t.LSystem.setAxiom(s.data.result),e()})}),this.worker.postMessage(e),this.workerPromise},updateSegmentMixins:function(){var t,e,s,i,o,r,n,a,c,h,u,m;let f=this;this.el.innerHTML="",this.segmentElementGroupsMap=new Map,this.mixinMap=new Map,t=!0,e=!1,s=void 0;try{for(i=this.data.segmentMixins[Symbol.iterator]();!(t=(o=i.next()).done);t=!0){let t=o.value,e=(r=l(t,2))[0],s=r[1];for(let t=0;t<s.length;t++)this.mixinMap.set(e+t,s[t])}}catch(t){e=!0,s=t}finally{try{!t&&i.return&&i.return()}finally{if(e)throw s}}if(this.segmentObjects3DMap=new Map,this.segmentLengthMap=new Map,this.mergeGroups=new Map,this.mixinPromises=[],this.data.segmentMixins&&0!==this.data.segmentMixins.length){n=!0,a=!1,c=void 0;try{for(h=this.data.segmentMixins[Symbol.iterator]();!(n=(u=h.next()).done);n=!0){let t=u.value,e=(m=l(t,2))[0],s=m[1];this.LSystem.setFinal(e,()=>{f.pushSegment.bind(f,e)()});for(let t=0;t<s.length;t++){let i=t,o=s[i];f.mixinPromises.push(new Promise(t=>{let s=document.createElement("a-entity");if(s.setAttribute("id",o+"-group-"+i+Math.floor(1e4*Math.random())),s.setAttribute("geometry","buffer",!1),s.setAttribute("mixin",o),s.addEventListener("loaded",function(){let r=s.getObject3D("mesh").clone();s.getObject3D("mesh").geometry.dispose(),r.geometry=r.geometry.clone();let n=f.calculateSegmentLength(o,r.geometry);if(!0===f.data.mergeGeometries){let t=f.data.translateAxis.clone().multiplyScalar(n*f.segmentLengthFactor/2);r.geometry.translate(t.x,t.y,t.z),f.segmentObjects3DMap.set(e+i,r)}s.removeObject3D("mesh"),t()},{once:!0}),this.segmentElementGroupsMap.has(e+i)){let t=this.segmentElementGroupsMap.get(e+i);this.segmentElementGroupsMap.delete(e+i),this.el.removeChild(t)}this.segmentElementGroupsMap.set(e+i,s),this.el.appendChild(s)}))}}}catch(t){a=!0,c=t}finally{try{!n&&h.return&&h.return()}finally{if(a)throw c}}}},updateTurtleGraphics:async function(){var t,e,s,i,o,r,n,a,c,h,u,m;if(await Promise.all([...this.mixinPromises,this.workerPromise]),this.transformationSegment.copy(this.transformationSegmentTemplate),!0===this.data.mergeGeometries){t=!0,e=!1,s=void 0;try{for(i=this.segmentObjects3DMap[Symbol.iterator]();!(t=(o=i.next()).done);t=!0){let t=o.value,e=(r=l(t,2))[0],s=r[1];this.mergeGroups.set(e,new THREE.Mesh(new THREE.Geometry,s.material))}}catch(t){e=!0,s=t}finally{try{!t&&i.return&&i.return()}finally{if(e)throw s}}}this.stack=[];let f=this.data.angle;if(this.xPosRotation.setFromAxisAngle(this.X,Math.PI/180*f),this.xNegRotation.setFromAxisAngle(this.X,Math.PI/180*-f),this.yPosRotation.setFromAxisAngle(this.Y,Math.PI/180*f),this.yNegRotation.setFromAxisAngle(this.Y,Math.PI/180*-f),this.yReverseRotation.setFromAxisAngle(this.Y,Math.PI/180*180),this.zPosRotation.setFromAxisAngle(this.Z,Math.PI/180*f),this.zNegRotation.setFromAxisAngle(this.Z,Math.PI/180*-f),this.LSystem.final(),!0===this.data.mergeGeometries){n=!0,a=!1,c=void 0;try{for(h=this.segmentElementGroupsMap[Symbol.iterator]();!(n=(u=h.next()).done);n=!0){let t=u.value,e=(m=l(t,2))[0],s=m[1];0===this.mergeGroups.get(e).geometry.vertices.length?this.el.removeChild(s):(s.setObject3D("mesh",this.mergeGroups.get(e)),s.setAttribute("mixin",this.mixinMap.get(e)))}}catch(t){a=!0,c=t}finally{try{!n&&h.return&&h.return()}finally{if(a)throw c}}}},remove:function(){},tick:function(){},pause:function(){},play:function(){}})},function(t,e){"use strict";function s(t){let e,s=t[0].match(/(.+)<(.)/),i=t[0].match(/(.)>(.+)/);if(null===s&&null===i)return t;let o=t[1].successor||t[1].successors?t[1]:{successor:t[1]};return null!==s&&(e=s[2],o.leftCtx=s[1]),null!==i&&(e=i[1],o.rightCtx=i[2]),[e,o]}function i(t){if("string"!=typeof t&&t instanceof String==!1)return t;let e=[];for(let s of t)e.push({symbol:s});return e}function o(t,e){return t[1]=function t(e,s){if(e.hasOwnProperty("successors"))for(var o=0;o<e.successors.length;o++)e.successors[o]=t(e.successors[o],s);else!1===e.hasOwnProperty("successor")&&(e={successor:e});return s&&e.hasOwnProperty("successor")&&(e.successor=i(e.successor)),e}(t[1],e),t}class LSystem{constructor({axiom:t="",productions:e,finals:s,branchSymbols:i="[]",ignoredSymbols:o="+-&^/|\\",allowClassicSyntax:r=!0,classicParametricSyntax:n=!1,forceObjects:a=!1,debug:l=!1}){this.ignoredSymbols=o,this.debug=l,this.branchSymbols=i,this.allowClassicSyntax=r,this.classicParametricSyntax=n,this.forceObjects=a,this.setAxiom(t),this.clearProductions(),e&&this.setProductions(e),s&&this.setFinals(s)}setAxiom(t){this.axiom=this.forceObjects?i(t):t}getRaw(){return this.axiom}getString(t=!0){return"string"==typeof this.axiom?this.axiom:!0===t?this.axiom.reduce((t,e)=>{if(void 0===e.symbol)throw console.log("found:",e),Error("L-Systems that use only objects as symbols (eg: {symbol: 'F', params: []}), cant use string symbols (eg. 'F')! Check if you always return objects in your productions and no strings.");return t+e.symbol},""):JSON.stringify(this.axiom)}setProduction(t,e,i=!1){let r=[t,e];if(void 0===r)throw Error("no production specified.");if(e.successor&&e.successors)throw Error('You can not have both a "successor" and a "successors" field in your production!');if(!0===this.allowClassicSyntax&&(r=s(r)),(r=o(r,this.forceObjects))[1].isStochastic=void 0!==r[1].successors&&r[1].successors.every(t=>void 0!==t.weight),r[1].isStochastic)for(let t of(r[1].weightSum=0,r[1].successors))r[1].weightSum+=t.weight;let n=r[0];if(!0===i&&this.productions.has(n)){let t=this.productions.get(n),e=t.successor,s=t.successors;e&&!s&&(t={successors:[t]}),t.successors.push(r[1]),this.productions.set(n,t)}else this.productions.set(n,r[1])}setProductions(t){if(void 0===t)throw Error("no production specified.");for(let e of(this.clearProductions(),Object.entries(t))){let t=e[0],s=e[1];this.setProduction(t,s,!0)}}clearProductions(){this.productions=new Map}setFinal(t,e){let s=[t,e];if(void 0===s)throw Error("no final specified.");this.finals.set(s[0],s[1])}setFinals(t){if(void 0===t)throw Error("no finals specified.");for(let e in this.finals=new Map,t)t.hasOwnProperty(e)&&this.setFinal(e,t[e])}getProductionResult(t,e,s,i,o=!1){let r=void 0!==t.leftCtx||void 0!==t.rightCtx,n=!1,a=!0;if(void 0!==t.condition&&!1===t.condition({index:e,currentAxiom:this.axiom,part:s,params:i})?a=!1:r&&(void 0!==t.leftCtx&&void 0!==t.rightCtx?a=this.match({direction:"left",match:t.leftCtx,index:e,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result&&this.match({direction:"right",match:t.rightCtx,index:e,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result:void 0!==t.leftCtx?a=this.match({direction:"left",match:t.leftCtx,index:e,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result:void 0!==t.rightCtx&&(a=this.match({direction:"right",match:t.rightCtx,index:e,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result)),!1===a)n=!1;else if(t.successors){let o,r;for(let a of(t.isStochastic&&(r=Math.random()*t.weightSum,o=0),t.successors)){if(t.isStochastic&&r>(o+=a.weight))continue;let l=this.getProductionResult(a,e,s,i,!0);if(void 0!==l&&!1!==l){n=l;break}}}else n="function"==typeof t.successor?t.successor({index:e,currentAxiom:this.axiom,part:s,params:i}):t.successor;return n||(o?n:s)}applyProductions(){let t="string"==typeof this.axiom?"":[],e=0;for(let s of this.axiom){let i=s.symbol||s,o=s.params||[],r=s;if(this.productions.has(i)){let t=this.productions.get(i);r=this.getProductionResult(t,e,s,o)}"string"==typeof t?t+=r:r instanceof Array?t.push(...r):t.push(r),e++}return this.axiom=t,t}iterate(t=1){let e;this.iterations=t;for(let s=0;t>s;s++)e=this.applyProductions();return e}final(t){let e=0;for(let s of this.axiom){let i=s;if("object"==typeof s&&s.symbol&&(i=s.symbol),this.finals.has(i)){let o=this.finals.get(i),r=typeof o;if("function"!==r)throw Error("'"+i+"' has an object for a final function. But it is __not a function__ but a "+r+"!");o({index:e,part:s},t)}e++}}match({axiom_:t,match:e,ignoredSymbols:s,branchSymbols:i,index:o,direction:r}){var n,a;let l=0,c=0;t=t||this.axiom,void 0===i&&(i=void 0!==this.branchSymbols?this.branchSymbols:[]),void 0===s&&(s=void 0!==this.ignoredSymbols?this.ignoredSymbols:[]);let h,u,m,f,d,g,y,p=[];if("right"===r)f=g=1,m=o+1,d=0,y=e.length,i.length>0&&(h=(n=i)[0],u=n[1]);else{if("left"!==r)throw Error(r,"is not a valid direction for matching.");f=g=-1,m=o-1,d=e.length-1,y=-1,i.length>0&&(u=(a=i)[0],h=a[1])}for(;m<t.length&&m>=0;m+=f){let i=t[m].symbol||t[m],o=e[d];if(i===o){if((0===l||c>0)&&(i===h?(c++,l++,d+=g):i===u?(c=Math.max(0,c-1),l=Math.max(0,l-1),0===c&&(d+=g)):(p.push(m),d+=g)),d===y)return{result:!0,matchIndices:p}}else if(i===h)l++,c>0&&c++;else if(i===u)l=Math.max(0,l-1),c>0&&(c=Math.max(0,c-1));else if((0===l||c>0&&o!==u)&&!1===s.includes(i))return{result:!1,matchIndices:p}}return{result:!1,matchIndices:p}}}LSystem.getStringResult=LSystem.getString,LSystem.transformClassicStochasticProductions=function(t){return function(){let e=t,s=e.length,i=Math.random();for(let t=0;s>t;t++)if((t+1)/s>=i)return e[t];console.error("Should have returned a result of the list, something is wrong here with the random numbers?.")}},LSystem.transformClassicCSProduction=s,LSystem.transformClassicParametricAxiom=function(t){let e=t.replace(/\s+/g,"").split(/[\(\)]/),s=[];for(let t=0;t<e.length-1;t+=2){let i=e[t+1].split(",").map(Number);s.push({symbol:e[t],params:i})}},LSystem.testClassicParametricSyntax=function(t){return/\(.+\)/.test(t)},e.a=LSystem},function(t,e,s){t.exports=function(){return s(3)('!function(t){function s(i){if(o[i])return o[i].exports;var e=o[i]={i:i,l:!1,exports:{}};return t[i].call(e.exports,e,e.exports,s),e.l=!0,e.exports}var o={};s.m=t,s.c=o,s.d=function(t,o,i){s.o(t,o)||Object.defineProperty(t,o,{configurable:!1,enumerable:!0,get:i})},s.n=function(t){var o=t&&t.__esModule?function(){return t.default}:function(){return t};return s.d(o,"a",o),o},s.o=function(t,s){return Object.prototype.hasOwnProperty.call(t,s)},s.p="",s(s.s=0)}([function(t,s,o){"use strict";Object.defineProperty(s,"__esModule",{value:!0});let i=new(o(1).a)({}),e={};onmessage=function(t){clearTimeout(e),e=setTimeout(function(){var s,o,e,r,n;i.setAxiom(t.data.axiom),i.clearProductions(),s=!0,o=!1,e=void 0;try{for(r=t.data.productions[Symbol.iterator]();!(s=(n=r.next()).done);s=!0){let t=n.value;i.setProduction(t[0],t[1])}}catch(t){o=!0,e=t}finally{try{!s&&r.return&&r.return()}finally{if(o)throw e}}i.iterate(t.data.iterations),postMessage({result:i.getString(),initial:t.data})},20)}},function(t,s){"use strict";function o(t){let s,o=t[0].match(/(.+)<(.)/),i=t[0].match(/(.)>(.+)/);if(null===o&&null===i)return t;let e=t[1].successor||t[1].successors?t[1]:{successor:t[1]};return null!==o&&(s=o[2],e.leftCtx=o[1]),null!==i&&(s=i[1],e.rightCtx=i[2]),[s,e]}function i(t){if("string"!=typeof t&&t instanceof String==!1)return t;let s=[];for(let o of t)s.push({symbol:o});return s}function e(t,s){return t[1]=function t(s,o){if(s.hasOwnProperty("successors"))for(var e=0;e<s.successors.length;e++)s.successors[e]=t(s.successors[e],o);else!1===s.hasOwnProperty("successor")&&(s={successor:s});return o&&s.hasOwnProperty("successor")&&(s.successor=i(s.successor)),s}(t[1],s),t}class LSystem{constructor({axiom:t="",productions:s,finals:o,branchSymbols:i="[]",ignoredSymbols:e="+-&^/|\\\\",allowClassicSyntax:r=!0,classicParametricSyntax:n=!1,forceObjects:c=!1,debug:a=!1}){this.ignoredSymbols=e,this.debug=a,this.branchSymbols=i,this.allowClassicSyntax=r,this.classicParametricSyntax=n,this.forceObjects=c,this.setAxiom(t),this.clearProductions(),s&&this.setProductions(s),o&&this.setFinals(o)}setAxiom(t){this.axiom=this.forceObjects?i(t):t}getRaw(){return this.axiom}getString(t=!0){return"string"==typeof this.axiom?this.axiom:!0===t?this.axiom.reduce((t,s)=>{if(void 0===s.symbol)throw console.log("found:",s),Error("L-Systems that use only objects as symbols (eg: {symbol: \'F\', params: []}), cant use string symbols (eg. \'F\')! Check if you always return objects in your productions and no strings.");return t+s.symbol},""):JSON.stringify(this.axiom)}setProduction(t,s,i=!1){let r=[t,s];if(void 0===r)throw Error("no production specified.");if(s.successor&&s.successors)throw Error(\'You can not have both a "successor" and a "successors" field in your production!\');if(!0===this.allowClassicSyntax&&(r=o(r)),(r=e(r,this.forceObjects))[1].isStochastic=void 0!==r[1].successors&&r[1].successors.every(t=>void 0!==t.weight),r[1].isStochastic)for(let t of(r[1].weightSum=0,r[1].successors))r[1].weightSum+=t.weight;let n=r[0];if(!0===i&&this.productions.has(n)){let t=this.productions.get(n),s=t.successor,o=t.successors;s&&!o&&(t={successors:[t]}),t.successors.push(r[1]),this.productions.set(n,t)}else this.productions.set(n,r[1])}setProductions(t){if(void 0===t)throw Error("no production specified.");for(let s of(this.clearProductions(),Object.entries(t))){let t=s[0],o=s[1];this.setProduction(t,o,!0)}}clearProductions(){this.productions=new Map}setFinal(t,s){let o=[t,s];if(void 0===o)throw Error("no final specified.");this.finals.set(o[0],o[1])}setFinals(t){if(void 0===t)throw Error("no finals specified.");for(let s in this.finals=new Map,t)t.hasOwnProperty(s)&&this.setFinal(s,t[s])}getProductionResult(t,s,o,i,e=!1){let r=void 0!==t.leftCtx||void 0!==t.rightCtx,n=!1,c=!0;if(void 0!==t.condition&&!1===t.condition({index:s,currentAxiom:this.axiom,part:o,params:i})?c=!1:r&&(void 0!==t.leftCtx&&void 0!==t.rightCtx?c=this.match({direction:"left",match:t.leftCtx,index:s,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result&&this.match({direction:"right",match:t.rightCtx,index:s,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result:void 0!==t.leftCtx?c=this.match({direction:"left",match:t.leftCtx,index:s,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result:void 0!==t.rightCtx&&(c=this.match({direction:"right",match:t.rightCtx,index:s,branchSymbols:this.branchSymbols,ignoredSymbols:this.ignoredSymbols}).result)),!1===c)n=!1;else if(t.successors){let e,r;for(let c of(t.isStochastic&&(r=Math.random()*t.weightSum,e=0),t.successors)){if(t.isStochastic&&r>(e+=c.weight))continue;let a=this.getProductionResult(c,s,o,i,!0);if(void 0!==a&&!1!==a){n=a;break}}}else n="function"==typeof t.successor?t.successor({index:s,currentAxiom:this.axiom,part:o,params:i}):t.successor;return n||(e?n:o)}applyProductions(){let t="string"==typeof this.axiom?"":[],s=0;for(let o of this.axiom){let i=o.symbol||o,e=o.params||[],r=o;if(this.productions.has(i)){let t=this.productions.get(i);r=this.getProductionResult(t,s,o,e)}"string"==typeof t?t+=r:r instanceof Array?t.push(...r):t.push(r),s++}return this.axiom=t,t}iterate(t=1){let s;this.iterations=t;for(let o=0;t>o;o++)s=this.applyProductions();return s}final(t){let s=0;for(let o of this.axiom){let i=o;if("object"==typeof o&&o.symbol&&(i=o.symbol),this.finals.has(i)){let e=this.finals.get(i),r=typeof e;if("function"!==r)throw Error("\'"+i+"\' has an object for a final function. But it is __not a function__ but a "+r+"!");e({index:s,part:o},t)}s++}}match({axiom_:t,match:s,ignoredSymbols:o,branchSymbols:i,index:e,direction:r}){var n,c;let a=0,l=0;t=t||this.axiom,void 0===i&&(i=void 0!==this.branchSymbols?this.branchSymbols:[]),void 0===o&&(o=void 0!==this.ignoredSymbols?this.ignoredSymbols:[]);let u,h,f,d,m,y,b,g=[];if("right"===r)d=y=1,f=e+1,m=0,b=s.length,i.length>0&&(u=(n=i)[0],h=n[1]);else{if("left"!==r)throw Error(r,"is not a valid direction for matching.");d=y=-1,f=e-1,m=s.length-1,b=-1,i.length>0&&(h=(c=i)[0],u=c[1])}for(;f<t.length&&f>=0;f+=d){let i=t[f].symbol||t[f],e=s[m];if(i===e){if((0===a||l>0)&&(i===u?(l++,a++,m+=y):i===h?(l=Math.max(0,l-1),a=Math.max(0,a-1),0===l&&(m+=y)):(g.push(f),m+=y)),m===b)return{result:!0,matchIndices:g}}else if(i===u)a++,l>0&&l++;else if(i===h)a=Math.max(0,a-1),l>0&&(l=Math.max(0,l-1));else if((0===a||l>0&&e!==h)&&!1===o.includes(i))return{result:!1,matchIndices:g}}return{result:!1,matchIndices:g}}}LSystem.getStringResult=LSystem.getString,LSystem.transformClassicStochasticProductions=function(t){return function(){let s=t,o=s.length,i=Math.random();for(let t=0;o>t;t++)if((t+1)/o>=i)return s[t];console.error("Should have returned a result of the list, something is wrong here with the random numbers?.")}},LSystem.transformClassicCSProduction=o,LSystem.transformClassicParametricAxiom=function(t){let s=t.replace(/\\s+/g,"").split(/[\\(\\)]/),o=[];for(let t=0;t<s.length-1;t+=2){let i=s[t+1].split(",").map(Number);o.push({symbol:s[t],params:i})}},LSystem.testClassicParametricSyntax=function(t){return/\\(.+\\)/.test(t)},s.a=LSystem}]);',null)}},function(t){var e=window.URL||window.webkitURL;t.exports=function(t,s){var i;try{try{try{(i=new(window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder||window.MSBlobBuilder)).append(t),i=i.getBlob()}catch(e){i=new Blob([t])}return new Worker(e.createObjectURL(i))}catch(e){return new Worker("data:application/javascript,"+encodeURIComponent(t))}}catch(t){if(!s)throw Error("Inline worker is not supported");return new Worker(s)}}},function(){AFRAME.registerPrimitive("a-lsystem",{defaultComponents:{lsystem:{axiom:"F",productions:"F:F++F++F++F",iterations:3,angle:60}},mappings:{axiom:"lsystem.axiom",productions:"lsystem.productions",segmentMixins:"lsystem.segmentMixins",iterations:"lsystem.iterations",angle:"lsystem.angle"}})}]);