const ansiPattern = [ `[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)`, `(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))`, ].join(`|`) const stripAnsi = (body: string) => body?.replace?.(new RegExp(ansiPattern, `g`), ``) ?? body /** * Overlay controller */ export class Controller { /** * Element */ public element: HTMLElement /** * HMR update */ public payload: Payload /** * Class constructor */ public constructor() { this.update = this.update.bind(this) this.element = document.createElement(`bud-error`) } /** * Append `bud-error` element to the DOM */ public createError() { !document.body.querySelector(`bud-error`) && document.body?.appendChild(this.element) } /** * Formatted error message */ public get message(): string { return this.payload.errors?.reduce((a, c) => { const msg = c?.message ?? c?.error ?? c if (!msg) return a return `${a}
${stripAnsi(msg)}