/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.25/esri/copyright.txt for details. */ import"../../core/has.js";import{isSome as t}from"../../core/maybe.js";import{ShaderType as e}from"./enums.js";import a from"./reservedWordsGLSL3.js";import{shaderTranspiler as r}from"./testUtils.js";import{o as n,l as o,b as i}from"../../chunks/builtins.js";var s=999,c=9999,p=0,u=1,d=2,f=3,l=4,h=5,y=6,w=7,g=8,m=9,b=10,k=11,E=["block-comment","line-comment","preprocessor","operator","integer","float","ident","builtin","keyword","whitespace","eof","integer"];function _(){var t,e,a,r=0,_=0,v=s,j=[],x=[],D=1,R=0,T=0,A=!1,G=!1,S="";return function(t){return x=[],null!==t?F(t.replace?t.replace(/\r\n/g,"\n"):t):L()};function X(t){t.length&&x.push({type:E[v],data:t,position:T,line:D,column:R})}function F(e){var n;for(r=0,a=(S+=e).length;t=S[r],r0)continue;a=t.slice(0,1).join("")}return X(a),T+=a.length,(j=j.slice(a.length)).length}}function $(){return/[^a-fA-F0-9]/.test(t)?(X(j.join("")),v=s,r):(j.push(t),e=t,r+1)}function z(){return"."===t||/[eE]/.test(t)?(j.push(t),v=h,e=t,r+1):"x"===t&&1===j.length&&"0"===j[0]?(v=k,j.push(t),e=t,r+1):/[^\d]/.test(t)?(X(j.join("")),v=s,r):(j.push(t),e=t,r+1)}function I(){return"f"===t&&(j.push(t),e=t,r+=1),/[eE]/.test(t)||"-"===t&&/[eE]/.test(e)?(j.push(t),e=t,r+1):/[^\d]/.test(t)?(X(j.join("")),v=s,r):(j.push(t),e=t,r+1)}function U(){if(/[^\d\w_]/.test(t)){var a=j.join("");return v=o.indexOf(a)>-1?g:i.indexOf(a)>-1?w:y,X(j.join("")),v=s,r}return j.push(t),e=t,r+1}}function v(t){var e=_(),a=[];return a=(a=a.concat(e(t))).concat(e(null))}function j(t){return v(t)}function x(t){return t.map((t=>"eof"!==t.type?t.data:"")).join("")}const D=["GL_OES_standard_derivatives","GL_EXT_frag_depth","GL_EXT_draw_buffers","GL_EXT_shader_texture_lod"];function R(t,e="100",a="300 es"){const r=/^\s*\#version\s+([0-9]+(\s+[a-zA-Z]+)?)\s*/;for(const n of t)if("preprocessor"===n.type){const t=r.exec(n.data);if(t){const r=t[1].replace(/\s\s+/g," ");if(r===a)return r;if(r===e)return n.data="#version "+a,e;throw new Error("unknown glsl version: "+r)}}return t.splice(0,0,{type:"preprocessor",data:"#version "+a},{type:"whitespace",data:"\n"}),null}function T(t,e){for(let a=e-1;a>=0;a--){const e=t[a];if("whitespace"!==e.type&&"block-comment"!==e.type){if("keyword"!==e.type)break;if("attribute"===e.data||"in"===e.data)return!0}}return!1}function A(t,e,a,r){r=r||a;for(const n of t)if("ident"===n.type&&n.data===a){r in e?e[r]++:e[r]=0;return A(t,e,r+"_"+e[r],r)}return a}function G(t,e,a="afterVersion"){function r(t,e){for(let a=e;ae=0;--t){const e=i[t];if("preprocessor"===e.type){const a=e.data.match(/\#extension\s+(.*)\:/);if(a&&a[1]&&D.includes(a[1].trim())){const e=i[t+1];i.splice(t,e&&"whitespace"===e.type?2:1)}const r=e.data.match(/\#ifdef\s+(.*)/);r&&r[1]&&D.includes(r[1].trim())&&(e.data="#if 1");const n=e.data.match(/\#ifndef\s+(.*)/);n&&n[1]&&D.includes(n[1].trim())&&(e.data="#if 0")}}return M(r,x(i))}const C=new Map;function H(t){return r.enableCache?C.get(t):null}function M(t,e){return r.enableCache&&C.set(t,e),e}export{L as transpileShader};