import{isCustomProperty as t}from"../../utils/names.mjs";import{Ident as i,Colon as e,Delim as s,WhiteSpace as n,Semicolon as o,Hash as r}from"../../tokenizer/types.mjs";import"../../tokenizer/char-code-definitions.mjs";import"../../tokenizer/TokenStream.mjs";function a(){return this.Raw(this.consumeUntilExclamationMarkOrSemicolon,!0)}function h(){return this.Raw(this.consumeUntilExclamationMarkOrSemicolon,!1)}function c(){const t=this.tokenIndex,i=this.Value();return"Raw"!==i.type&&!1===this.eof&&this.tokenType!==o&&!1===this.isDelim(33)&&!1===this.isBalanceEdge(t)&&this.error(),i}const l="Declaration",p="declaration",k={important:[Boolean,String],property:String,value:["Value","Raw"]};function m(){const i=this.tokenStart,s=this.tokenIndex,r=f.call(this),l=t(r),p=l?this.parseCustomProperty:this.parseValue,k=l?h:a;let m,u=!1;this.skipSC(),this.eat(e);const y=this.tokenIndex;if(l||this.skipSC(),m=p?this.parseWithFallback(c,k):k.call(this,this.tokenIndex),l&&"Value"===m.type&&m.children.isEmpty)for(let t=y-this.tokenIndex;t<=0;t++)if(this.lookupType(t)===n){m.children.appendData({type:"WhiteSpace",loc:null,value:" "});break}return this.isDelim(33)&&(u=d.call(this),this.skipSC()),!1===this.eof&&this.tokenType!==o&&!1===this.isBalanceEdge(s)&&this.error(),{type:"Declaration",loc:this.getLocation(i,this.tokenStart),important:u,property:r,value:m}}function u(t){this.token(i,t.property),this.token(e,":"),this.node(t.value),t.important&&(this.token(s,"!"),this.token(i,!0===t.important?"important":t.important))}function f(){const t=this.tokenStart;if(this.tokenType===s)switch(this.charCodeAt(this.tokenStart)){case 42:case 36:case 43:case 35:case 38:this.next();break;case 47:this.next(),this.isDelim(47)&&this.next()}return this.tokenType===r?this.eat(r):this.eat(i),this.substrToCursor(t)}function d(){this.eat(s),this.skipSC();const t=this.consume(i);return"important"===t||t}export{u as generate,l as name,m as parse,k as structure,p as walkContext};