UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

3 lines (2 loc) 3.41 kB
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */ const e=5;function n(e){for(const n of e.rootOutputNodes())e.shouldPruneOutputNode(n)||(n.variableName=r(e,n.node))}function t(e,n){let t="";return"boolean"!=typeof n&&"number"!=typeof n&&n.debugInfo.name&&(t=`${n.debugInfo.name}_`),`${t}v${e.varCount++}`}function r(e,n,t=!1){if("number"==typeof n)return n.toString();if("boolean"==typeof n)return n.toString();let r=e.getEmit(n);if(r)return r;switch(n.shaderType){case"scope-node":r=i(e,n);break;case"primitive-node":r=s(e,n,t);break;case"function-node":r=p(e,n);break;case"property-access-node":r=u(e,n);break;case"property-access-2d-node":r=a(e,n);break;case"text-node":r=n.text;break;case"block-node":r=d(e,n);break;case"condition-node":r=c(e,n)}return e.setEmit(n,r),r}function o(e,n,t){const r=n.split("\n");for(const o of r)if(o.trim().length){{let n="";null!=t&&(n+=`/*id:${t??"000"}*/ `),e.body+=n.padEnd(14)}e.body+=" ".repeat(e.indent)+o+"\n"}}function i(e,n){const t=new n.child.constructor;t.setDebugName(n.debugInfo.name);const i=r(e,t,!0);o(e,`{ /*ScopeStart: ${n.uid} ${n.debugInfo.name}*/`),e.indent+=2;return o(e,`${i} = ${r(e,n.child)};`),e.indent-=2,o(e,`} /*ScopeEnd: ${n.uid} ${n.debugInfo.name}*/`),i}function c(e,n){const t=r(e,new n.ifTrue.constructor,!0);o(e,`if (${r(e,n.condition)}) {`),e.indent+=2;const i=e.createSubgraphContext(),c=r(i,n.ifTrue);if(e.body+=i.body,c&&o(e,`${t} = ${c};`),e.indent-=2,o(e,"}"),n.ifFalse){o(e,"else {"),e.indent+=2;const i=e.createSubgraphContext(),c=r(i,n.ifFalse);e.body+=i.body,c&&o(e,`${t} = ${c};`),e.indent-=2,o(e,"}")}return t}function d(e,n){const{captureList:t,generator:i,returnType:c}=n,d={};for(const o in t){if(!t[o])continue;const n=r(e,t[o]);d[o]=n}const u=r(e,new c,!0);if(d.out=u,n.subgraph){const t=e.createSubgraphContext(),o=r(t,n.subgraph.child),i=t.body;d.subgraph={varName:o,body:i}}const a=i(d);return o(e,"{\n"),e.indent+=2,o(e,a),e.indent-=2,o(e,"}\n"),u}function u(e,n){const t=r(e,n.target);if("string"==typeof n.property&&n.property.includes("["))return`${t}${n.property}`;if("string"!=typeof n.property){return`${t}[${r(e,n.property)}]`}return`${t}.${n.property}`}function a(e,n){return`${r(e,n.target)}[${r(e,n.x)}][${r(e,n.y)}]`}function p(n,i){const c=i.returnType.type;if(i.isInfix){const[d,u]=i.children.map(e=>r(n,e)),a=t(n,i);return o(n,`${c.padEnd(e)} ${a} = ${d} ${i.token} ${u};`,i.uid),a}const d=i.children.map(e=>r(n,e)).join(", "),u=t(n,i);return o(n,`${c.padEnd(e)} ${u} = ${i.token}(${d});`,i.uid),u}function s(n,i,c=!1){const d=n.getInput(i);if(d)return d.isUsed=!0,d.variableName;const u=1===i.children.length&&i.children[0]?.type===i.type;if(!i.isMutable&&(i.isImplicit||u))return r(n,i.children[0]);const a=t(n,i);if(c)return o(n,`${i.type.padEnd(e)} ${a};`,i.uid),a;const p=!i.debugInfo.name&&!i.isMutable;if(p){if("float"===i.type&&"number"==typeof i.children[0])return Number.isInteger(i.children[0])?i.children[0].toFixed(1):i.children[0].toString();if("int"===i.type&&"number"==typeof i.children[0]&&Number.isInteger(i.children[0]))return i.children[0].toString();if("bool"===i.type&&"boolean"==typeof i.children[0])return i.children[0].toString()}const s=i.children.map(e=>r(n,e)).join(", ");return"array"===i.type?(o(n,`${i.type.padEnd(e)} ${a} = [${s}];`,i.uid),a):p?`${i.type}(${s})`:(o(n,`${i.type.padEnd(e)} ${a} = ${i.type}(${s});`,i.uid),a)}export{n as generateGLSL};