class e extends Error{constructor(e,n){super(e),this.name="ParseError",this.type=n.type,this.field=n.field,this.value=n.value,this.line=n.line}}function n(e){}function t(t){if("function"==typeof t)throw new TypeError("`callbacks` must be an object, got a function instead. Did you mean `{onEvent: fn}`?");const{onEvent:r=n,onError:o=n,onRetry:i=n,onComment:s}=t;let a,c="",l=!0,f="",u="";function d(e){if(""===e)return f.length>0&&r({id:a,event:u||void 0, // If the data buffer's last character is a U+000A LINE FEED (LF) character, // then remove the last character from the data buffer. data:f.endsWith("\n")?f.slice(0,-1):f}),a=void 0,f="",void(u="");if(e.startsWith(":"))return void(s&&s(e.slice(e.startsWith(": ")?2:1)));const n=e.indexOf(":");if(-1===n)v(e,"",e);else{const t=e.slice(0,n),r=" "===e[n+1]?2:1;v(t,e.slice(n+r),e)}}function v(n,t,r){switch(n){case"event":u=t;break;case"data":f=`${f}${t}\n`;break;case"id":a=t.includes("\0")?void 0:t;break;case"retry":/^\d+$/.test(t)?i(parseInt(t,10)):o(new e(`Invalid \`retry\` value: "${t}"`,{type:"invalid-retry",value:t,line:r}));break;default:o(new e(`Unknown field "${n.length>20?`${n.slice(0,20)}…`:n}"`,{type:"unknown-field",field:n,value:t,line:r}))}}return{feed:function(e){const n=l?e.replace(/^\xEF\xBB\xBF/,""):e,[t,r]=function(e){const n=[];let t="",r=0;for(;r{i.enqueue(e)},onError(n){"terminate"===e?i.error(n):"function"==typeof e&&e(n)},onRetry:n,onComment:r})},transform(e){o.feed(e)}})}}export{r as E};