/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/express-error-renderer@1.8.5/build/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var __rest=this&&this.__rest||function(n,e){var r={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&e.indexOf(t)<0&&(r[t]=n[t]);if(null!=n&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(t=Object.getOwnPropertySymbols(n);s<t.length;s++)e.indexOf(t[s])<0&&(r[t[s]]=n[t[s]])}return r};Object.defineProperty(exports,"__esModule",{value:!0});const fs=require("fs"),HttpStatus=require("http-status-codes"),path=require("path"),stackman=require("stackman");function expressErrorRenderer(n={}){const e=Object.assign({basePath:path.join(__dirname,"..",".."),debug:!0,showMessage:!0},n);return(n,r,t,s)=>{if(t.headersSent)return void s(n);if(r.xhr){const r=e.formatXhrError?e.formatXhrError(n,e):formatXhrError(n,e);return void t.status(HttpStatus.INTERNAL_SERVER_ERROR).send(r)}if(!e.debug)return void t.status(HttpStatus.INTERNAL_SERVER_ERROR).send(e.showMessage?n.message:"Internal error occurred");const a=stackman();a.callsites(n,{sourcemap:!0},((r,s)=>{if(r)return void t.status(HttpStatus.INTERNAL_SERVER_ERROR).send(e.showMessage?n.message:"Internal error occurred");const o=s.filter((n=>{const r=n.getFileName();return!!r&&isProjectTrace(e.basePath,r)}));a.sourceContexts(o,{lines:20},((r,s)=>{if(r)return void t.status(HttpStatus.INTERNAL_SERVER_ERROR).send(e.showMessage?n.message:"Internal error occurred");const a=o.map(((n,r)=>renderStackFrame(r,n,e.basePath,s[r])));t.status(HttpStatus.INTERNAL_SERVER_ERROR).send(renderErrorPage(n,a,e.basePath))}))}))}}function formatXhrError(n,e){if(e.debug){const{name:e,message:r,stack:t}=n,s=__rest(n,["name","message","stack"]);return Object.assign({error:n.message,stack:"string"==typeof t?t.split("\n").map((n=>n.trim())):[]},s)}return{error:"Internal error occurred"}}function isProjectTrace(n,e){return-1!==e.indexOf(n)&&-1===e.indexOf("node_modules")}function renderErrorPage(n,e,r){const{name:t,message:s,stack:a}=n,o=__rest(n,["name","message","stack"]);return`\n    <html>\n    <head>\n      <meta charset="utf-8"/>\n      <title>Error</title>\n\n      <style>${fs.readFileSync(path.join(__dirname,"..","static","prism.css"),"utf8")}</style>\n      <script>${fs.readFileSync(path.join(__dirname,"..","static","prism.js"),"utf8")}<\/script>\n\n      <style>\n        body {\n          background-color: #252526;\n          color: #FFF;\n          margin: 0;\n          padding: 20px;\n        }\n        .error-message {\n          font-family: Consolas, fixed;\n          font-size: 120%;\n          margin-bottom: 20px;\n          border-radius: 5px 5px 0 0;\n          display: flex;\n          overflow: hidden;\n        }\n        .error-message__name {\n          padding: 20px;\n          background-color: #600;\n        }\n        .error-message__message {\n          padding: 20px;\n          background-color: #900;\n          flex-grow: 1;\n        }\n        .error-info {\n          background-color: #1E1E1E;\n          border-radius: 0 0 5px 5px;\n          margin-bottom: 20px;\n        }\n        .error-details {\n          white-space: pre;\n          font-family: Consolas, fixed;\n          font-size: 80%;\n          padding: 20px;\n          background-color: #111;\n        }\n        .stack-trace {\n          font-family: Consolas, fixed;\n          padding: 20px;\n        }\n        .stack-line {\n\n        }\n        .stack-line__match,\n        .stack-line__column {\n          display: none;\n        }\n        .stack-frame {\n          background-color: #1E1E1E;\n          padding: 0;\n          margin-bottom: 20px;\n          border-radius: 5px;\n          overflow: hidden;\n        }\n        .source-file {\n          font-weight: bold;\n          font-family: Consolas, fixed;\n          padding: 8px 10px;\n          background-color: #000;\n        }\n        .source-file__filename {\n          text-decoration: underline;\n        }\n        .source-lines {\n          font-family: Consolas, fixed;\n          padding: 0;\n          margin: 0;\n          color: #5A5A5A;\n        }\n        .source-lines__line {\n          padding: 5px 10px;\n          margin: 0;\n          white-space: pre;\n          list-style: decimal inside none;\n        }\n        .source-lines__line span {\n          color: #FFF;\n        }\n        .source-lines__line--main {\n          background-color: #111;\n        }\n        .no-context {\n          padding: 20px;\n        }\n        .source-code {\n          padding-left: 0 !important;\n          margin: 0 !important;\n          background-color: transparent !important;\n        }\n        .source-code code {\n          display: inline-block;\n        }\n      </style>\n    </head>\n    <body>\n      <div class="error-info">\n        <div class="error-message">\n          <div class="error-message__name">${t}</div>\n          <div class="error-message__message">${s}</div>\n        </div>\n        ${renderStackTrace(a,r)}\n        ${Object.keys(o).length>0?renderErrorDetails(o):""}\n      </div>\n      ${e.join("\n")}\n    </body>\n    </html>\n  `}function renderStackFrame(n,e,r,t){const s=formatFilename(r,e.getFileName()),a=e.getLineNumber();return`\n    <div class="stack-frame">\n      <div class="source-file">\n        <span class="source-file__index">#${n+1}</span>\n        <span class="source-file__filename">${s}</span>:<span class="source-file__line">${a}</span>\n      </div>\n      ${renderContext(a,t)}\n    </div>\n  `}function formatFilename(n,e){return path.relative(n,e).replace(/\\/g,"/")}function renderContext(n,e){if(!e)return'<div class="no-context">no context info available</div>';const r=n-e.pre.length;return`\n    <pre class="source-code line-numbers" data-start="${r}" data-line="${n-r+1}">\n      <code class="language-typescript">${`${e.pre.join("\n")}\n${e.line}\n${e.post.join("\n")}`}</code></pre>\n  `}function renderStackTrace(n,e){if("string"!=typeof n||0===n.length)return'<div class="no-stack-trace">no stack trace available</div>';return`\n    <ol class="stack-trace">\n      ${n.split("\n").filter((n=>isProjectTrace(e,n))).map((n=>renderStackLine(n,e))).join("\n")}\n    </ol>\n  `}function renderErrorDetails(n){try{return`<div class="error-details">${JSON.stringify(n,void 0,"  ")}</div>`}catch(n){return'<div class="error-details"><em>error details contained circular reference</em></div>'}}function renderStackLine(n,e){const r=/^\s*at (?:((?:\[object object\])?\S+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*$/i.exec(n);if(null===r||5!==r.length)return n;const t=r[1],s=r[2],a=r[3];return`\n    <li>\n      <span class="stack-line__source">${formatFilename(e,s)}:${a}</span>\n      ${"string"==typeof t?`<span class="stack-line__method">(${t})</span>`:""}\n    </li>\n  `}exports.default=expressErrorRenderer,exports.formatXhrError=formatXhrError;
//# sourceMappingURL=/sm/c84619675839aeb4fbfb2635e31cacd4a6ff993b70979934d628f489b0a37fa9.map