import{Number as e,Ident as t,Dimension as r,WhiteSpace as u,Comment as n,Delim as l}from"../tokenizer/types.mjs";import{isDigit as a}from"../tokenizer/char-code-definitions.mjs";import{cmpChar as o}from"../tokenizer/utils.mjs";import"../tokenizer/TokenStream.mjs";const i=45,f=!0;function c(e,t){return null!==e&&e.type===l&&e.value.charCodeAt(0)===t}function h(e,t,r){for(;null!==e&&(e.type===u||e.type===n);)e=r(++t);return t}function v(e,t,r,u){if(!e)return 0;const n=e.value.charCodeAt(t);if(43===n||n===i){if(r)return 0;t++}for(;t<e.value.length;t++)if(!a(e.value.charCodeAt(t)))return 0;return u+1}function s(t,r,u){let n=!1,l=h(t,r,u);if(null===(t=u(l)))return r;if(t.type!==e){if(!c(t,43)&&!c(t,i))return r;if(n=!0,l=h(u(++l),l,u),null===(t=u(l))||t.type!==e)return 0}if(!n){const e=t.value.charCodeAt(0);if(43!==e&&e!==i)return 0}return v(t,n?0:1,n,l)}function d(u,n){let l=0;if(!u)return 0;if(u.type===e)return v(u,0,false,l);if(u.type===t&&u.value.charCodeAt(0)===i){if(!o(u.value,1,110))return 0;switch(u.value.length){case 2:return s(n(++l),l,n);case 3:return u.value.charCodeAt(2)!==i?0:(l=h(n(++l),l,n),v(u=n(l),0,f,l));default:return u.value.charCodeAt(2)!==i?0:v(u,3,f,l)}}else if(u.type===t||c(u,43)&&n(l+1).type===t){if(u.type!==t&&(u=n(++l)),null===u||!o(u.value,0,110))return 0;switch(u.value.length){case 1:return s(n(++l),l,n);case 2:return u.value.charCodeAt(1)!==i?0:(l=h(n(++l),l,n),v(u=n(l),0,f,l));default:return u.value.charCodeAt(1)!==i?0:v(u,2,f,l)}}else if(u.type===r){let e=u.value.charCodeAt(0),t=43===e||e===i?1:0,r=t;for(;r<u.value.length&&a(u.value.charCodeAt(r));r++);return r===t?0:o(u.value,r,110)?r+1===u.value.length?s(n(++l),l,n):u.value.charCodeAt(r+1)!==i?0:r+2===u.value.length?(l=h(n(++l),l,n),v(u=n(l),0,f,l)):v(u,r+2,f,l):0}return 0}export{d as default};