import{isHexDigit as t,isWhiteSpace as r,isValidEscape as e}from"../tokenizer/char-code-definitions.mjs";import{consumeEscaped as o,decodeEscaped as n}from"../tokenizer/utils.mjs";import"../tokenizer/TokenStream.mjs";function i(t){const i=t.length;let c=4,s=41===t.charCodeAt(i-1)?i-2:i-1,a="";for(;c<s&&r(t.charCodeAt(c));)c++;for(;c<s&&r(t.charCodeAt(s));)s--;for(let r=c;r<=s;r++){let c=t.charCodeAt(r);if(92===c){if(r===s){r!==i-1&&(a=t.substr(r+1));break}if(c=t.charCodeAt(++r),e(92,c)){const e=r-1,i=o(t,e);r=i-1,a+=n(t.substring(e+1,i))}else 13===c&&10===t.charCodeAt(r+1)&&r++}else a+=t[r]}return a}function c(r){let e="",o=!1;for(let n=0;n<r.length;n++){const i=r.charCodeAt(n);0!==i?i<=31||127===i?(e+="\\"+i.toString(16),o=!0):32===i||92===i||34===i||39===i||40===i||41===i?(e+="\\"+r.charAt(n),o=!1):(o&&t(i)&&(e+=" "),e+=r.charAt(n),o=!1):e+="�"}return"url("+e+")"}export{i as decode,c as encode};