import{cssWideKeywords as e}from"./generic-const.mjs";import n from"./generic-an-plus-b.mjs";import t from"./generic-urange.mjs";import{LeftCurlyBracket as r,LeftSquareBracket as u,LeftParenthesis as o,Function as i,RightSquareBracket as a,RightParenthesis as l,RightCurlyBracket as c,BadUrl as s,BadString as f,Delim as p,Semicolon as m,Hash as k,Ident as g,Number as v,Dimension as h,Comma as y,Colon as b,CDC as d,CDO as w,WhiteSpace as x,Percentage as j,Url as z,String as C,AtKeyword as N}from"../tokenizer/types.mjs";import{isIdentifierStart as q,isHexDigit as D,isDigit as L}from"../tokenizer/char-code-definitions.mjs";import{cmpStr as O,consumeNumber as S}from"../tokenizer/utils.mjs";import"../tokenizer/TokenStream.mjs";const A=["calc(","-moz-calc(","-webkit-calc("],M=new Map([[i,l],[o,l],[u,a],[r,c]]);function R(e,n){return n<e.length?e.charCodeAt(n):0}function T(e,n){return O(e,0,e.length,n)}function B(e,n){for(let t=0;t<n.length;t++)if(T(e,n[t]))return!0;return!1}function E(e,n){return n===e.length-2&&(92===R(e,n)&&L(R(e,n+1)))}function F(e,n,t){if(e&&"Range"===e.type){const r=Number(void 0!==t&&t!==n.length?n.substr(0,t):n);if(isNaN(r))return!0;if(null!==e.min&&r<e.min&&"string"!=typeof e.min)return!0;if(null!==e.max&&r>e.max&&"string"!=typeof e.max)return!0}return!1}function G(e){return function(n,t,s){return null===n?0:n.type===i&&B(n.value,A)?function(e,n){let t=0,s=[],f=0;e:do{switch(e.type){case c:case l:case a:if(e.type!==t)break e;if(t=s.pop(),0===s.length){f++;break e}break;case i:case o:case u:case r:s.push(t),t=M.get(e.type)}f++}while(e=n(f));return f}(n,t):e(n,t,s)}}function H(e){return function(n){return null===n||n.type!==e?0:1}}function I(e){return null===e||e.type!==g||45!==R(e.value,0)||45!==R(e.value,1)?0:1}function J(e){return e&&(e=new Set(e)),function(n,t,r){if(null===n||n.type!==h)return 0;const u=S(n.value,0);if(null!==e){const t=n.value.indexOf("\\",u),r=-1!==t&&E(n.value,t)?n.value.substring(u,t):n.value.substr(u);if(!1===e.has(r.toLowerCase()))return 0}return F(r,n.value,u)?0:1}}function K(e){return"function"!=typeof e&&(e=function(){return 0}),function(n,t,r){return null!==n&&n.type===v&&0===Number(n.value)?1:e(n,t,r)}}const P={"ident-token":H(g),"function-token":H(i),"at-keyword-token":H(N),"hash-token":H(k),"string-token":H(C),"bad-string-token":H(f),"url-token":H(z),"bad-url-token":H(s),"delim-token":H(p),"number-token":H(v),"percentage-token":H(j),"dimension-token":H(h),"whitespace-token":H(x),"CDO-token":H(w),"CDC-token":H(d),"colon-token":H(b),"semicolon-token":H(m),"comma-token":H(y),"[-token":H(u),"]-token":H(a),"(-token":H(o),")-token":H(l),"{-token":H(r),"}-token":H(c)},Q={string:H(C),ident:H(g),percentage:G(function(e,n,t){return null===e||e.type!==j||F(t,e.value,e.value.length-1)?0:1}),zero:K(),number:G(function(e,n,t){if(null===e)return 0;const r=S(e.value,0);return r===e.value.length||E(e.value,r)?F(t,e.value,r)?0:1:0}),integer:G(function(e,n,t){if(null===e||e.type!==v)return 0;let r=43===R(e.value,0)||45===R(e.value,0)?1:0;for(;r<e.value.length;r++)if(!L(R(e.value,r)))return 0;return F(t,e.value,r)?0:1}),"custom-ident":function(n){if(null===n||n.type!==g)return 0;const t=n.value.toLowerCase();return B(t,e)||T(t,"default")?0:1},"dashed-ident":I,"custom-property-name":function(e){return I(e)?"--"===e.value?0:1:0},"hex-color":function(e){if(null===e||e.type!==k)return 0;const n=e.value.length;if(4!==n&&5!==n&&7!==n&&9!==n)return 0;for(let t=1;t<n;t++)if(!D(R(e.value,t)))return 0;return 1},"id-selector":function(e){return null===e||e.type!==k?0:q(R(e.value,1),R(e.value,2),R(e.value,3))?1:0},"an-plus-b":n,urange:t,"declaration-value":function(e,n){if(!e)return 0;let t=0,k=[],g=0;e:do{switch(e.type){case f:case s:break e;case c:case l:case a:if(e.type!==t)break e;t=k.pop();break;case m:if(0===t)break e;break;case p:if(0===t&&"!"===e.value)break e;break;case i:case o:case u:case r:k.push(t),t=M.get(e.type)}g++}while(e=n(g));return g},"any-value":function(e,n){if(!e)return 0;let t=0,p=[],m=0;e:do{switch(e.type){case f:case s:break e;case c:case l:case a:if(e.type!==t)break e;t=p.pop();break;case i:case o:case u:case r:p.push(t),t=M.get(e.type)}m++}while(e=n(m));return m}};function U(e){const{angle:n,decibel:t,frequency:r,flex:u,length:o,resolution:i,semitones:a,time:l}=e||{};return{dimension:G(J(null)),angle:G(J(n)),decibel:G(J(t)),frequency:G(J(r)),flex:G(J(u)),length:G(K(J(o))),resolution:G(J(i)),semitones:G(J(a)),time:G(J(l))}}function V(e){return{...P,...Q,...U(e)}}export{U as createDemensionTypes,V as createGenericTypes,Q as productionTypes,P as tokenTypes};