import {
Parser,
htmlEscape,
wordWrap
} from "../../chunk-MLPO7RBW.js";
// formatters/html/themes.ts
var themes = {
nightOwl: {
pre: "background-color: #061626; color: #c792ea;",
toggle: "color: #4f5357; background: none; border: none;",
braces: "color: #ffd700;",
brackets: "color: #ffd700;",
number: "color: #f78c6c;",
bigInt: "color: #f78c6c; font-weight: bold;",
boolean: "color: #ff5874; font-style: italic;",
string: "color: #ecc48d;",
null: "color: #637777;",
undefined: "color: #637777;",
prototypeLabel: "color: #637777;",
symbol: "color: #82aaff;",
regex: "color: #ff5874;",
date: "color: #7fdbca;",
buffer: "color: #7fdbca;",
functionLabel: "color: #89b4fa;",
arrayLabel: "color: #82aaff;",
objectLabel: "color: #82aaff;",
mapLabel: "color: #82aaff;",
setLabel: "color: #82aaff;",
objectKey: "color: #c792ea;",
objectKeyPrefix: "color: #637777; font-style: italic; font-weight: bold",
classLabel: "color: #82aaff;",
collapseLabel: "color: #7fdbca; font-style: italic;",
getterLabel: "color: #7fdbca;",
circularLabel: "color: #7fdbca;",
weakSetLabel: "color: #7fdbca;",
weakRefLabel: "color: #7fdbca;",
weakMapLabel: "color: #7fdbca;",
observableLabel: "color: #7fdbca;",
promiseLabel: "color: #7fdbca;",
generatorLabel: "color: #7fdbca;",
blobLabel: "color: #7fdbca;",
unknownLabel: "color: #7fdbca;"
},
minLight: {
pre: "background-color: #fff; color: #212121;",
toggle: "color: #989999; background: none; border: none;",
braces: "color: #0431fa;",
brackets: "color: #0431fa;",
number: "color: #1976d2;",
bigInt: "color: #1976d2; font-weight: bold;",
boolean: "color: #1976d2; font-style: italic;",
string: "color: #22863a;",
null: "color: #9c9c9d;",
undefined: "color: #9c9c9d;",
prototypeLabel: "color: #9c9c9d;",
symbol: "color: #d32f2f;",
regex: "color: #1976d2;",
date: "color: #7b3814;",
buffer: "color: #7b3814;",
functionLabel: "color: #6f42c1;",
arrayLabel: "color: #d32f2f;",
objectLabel: "color: #d32f2f;",
mapLabel: "color: #d32f2f;",
setLabel: "color: #d32f2f;",
objectKey: "color: #212121;",
objectKeyPrefix: "color: #9c9c9d; font-style: italic; font-weight: bold",
classLabel: "color: #6f42c1;",
collapseLabel: "color: #9c9c9d; font-style: italic;",
getterLabel: "color: #7b3814;",
circularLabel: "color: #7b3814;",
weakSetLabel: "color: #7b3814;",
weakRefLabel: "color: #7b3814;",
weakMapLabel: "color: #7b3814;",
observableLabel: "color: #7b3814;",
promiseLabel: "color: #7b3814;",
generatorLabel: "color: #7b3814;",
blobLabel: "color: #7b3814;",
unknownLabel: "color: #7b3814;"
},
catppuccin: {
pre: "background-color: #1e1e2e; color: #94e2d5;",
toggle: "color: #7c7c8c; background: none; border: none;",
braces: "color: #f38ba8;",
brackets: "color: #f38ba8;",
number: "color: #fab387;",
bigInt: "color: #fab387; font-weight: bold;",
boolean: "color: #cba6f7; font-style: italic;",
string: "color: #a6e3a1;",
null: "color: #6c7086;",
undefined: "color: #6c7086;",
prototypeLabel: "color: #6c7086;",
symbol: "color: #f9e2af;",
regex: "color: #cba6f7;",
date: "color: #94e2d5;",
buffer: "color: #94e2d5;",
functionLabel: "color: #cba6f7;",
arrayLabel: "color: #f9e2af;",
objectLabel: "color: #f9e2af;",
mapLabel: "color: #f9e2af;",
setLabel: "color: #f9e2af;",
objectKey: "color: #89b4fa;",
objectKeyPrefix: "color: #6c7086; font-style: italic; font-weight: bold",
classLabel: "color: #cba6f7;",
collapseLabel: "color: #6c7086; font-style: italic;",
getterLabel: "color: #94e2d5;",
circularLabel: "color: #94e2d5;",
weakSetLabel: "color: #94e2d5;",
weakRefLabel: "color: #94e2d5;",
weakMapLabel: "color: #94e2d5;",
observableLabel: "color: #94e2d5;",
promiseLabel: "color: #94e2d5;",
generatorLabel: "color: #94e2d5;",
blobLabel: "color: #94e2d5;",
unknownLabel: "color: #94e2d5;"
},
/**
* Following is the list of defined variables
--pre-bg-color
--pre-fg-color
--toggle-fg-color
--braces-fg-color
--brackets-fg-color
--dt-number-fg-color
--dt-bigint-fg-color
--dt-boolean-fg-color
--dt-string-fg-color
--dt-null-fg-color
--dt-undefined-fg-color
--prototype-label-fg-color
--dt-symbol-fg-color
--dt-regex-fg-color
--dt-date-fg-color
--dt-buffer-fg-color
--function-label-fg-color
--array-label-fg-color
--object-label-fg-color
--map-label-fg-color
--set-label-fg-color
--object-key-fg-color
--object-key-prefix-fg-color
--class-label-fg-color
--collpase-label-fg-color
--getter-label-fg-color
--circular-label-fg-color
--weakset-label-fg-color
--weakref-label-fg-color
--weakmap-label-fg-color
--observable-label-fg-color
--promise-label-fg-color
--generator-label-fg-color
--blob-label-fg-color
--unknown-label-fg-color
*/
cssVariables: {
pre: "background-color: var(--pre-bg-color); color: var(--pre-fg-color);",
toggle: "color: var(--toggle-fg-color); background: none; border: none;",
braces: "color: var(--braces-fg-color);",
brackets: "color: var(--brackets-fg-color);",
number: "color: var(--dt-number-fg-color);",
bigInt: "color: var(--dt-bigint-fg-color); font-weight: bold;",
boolean: "color: var(--dt-boolean-fg-color); font-style: italic;",
string: "color: var(--dt-string-fg-color);",
null: "color: var(--dt-null-fg-color);",
undefined: "color: var(--dt-undefined-fg-color);",
prototypeLabel: "color: var(--prototype-label-fg-color);",
symbol: "color: var(--dt-symbol-fg-color);",
regex: "color: var(--dt-regex-fg-color);",
date: "color: var(--dt-date-fg-color);",
buffer: "color: var(--dt-buffer-fg-color);",
functionLabel: "color: var(--function-label-fg-color);",
arrayLabel: "color: var(--array-label-fg-color);",
objectLabel: "color: var(--object-label-fg-color);",
mapLabel: "color: var(--map-label-fg-color);",
setLabel: "color: var(--set-label-fg-color);",
objectKey: "color: var(--object-key-fg-color);",
objectKeyPrefix: "color: var(--object-key-prefix-fg-color); font-style: italic; font-weight: bold",
classLabel: "color: var(--class-label-fg-color);",
collapseLabel: "color: var(--collpase-label-fg-color); font-style: italic;",
getterLabel: "color: var(--getter-label-fg-color);",
circularLabel: "color: var(--circular-label-fg-color);",
weakSetLabel: "color: var(--weakset-label-fg-color);",
weakRefLabel: "color: var(--weakref-label-fg-color);",
weakMapLabel: "color: var(--weakmap-label-fg-color);",
observableLabel: "color: var(--observable-label-fg-color);",
promiseLabel: "color: var(--promise-label-fg-color);",
generatorLabel: "color: var(--generator-label-fg-color);",
blobLabel: "color: var(--blob-label-fg-color);",
unknownLabel: "color: var(--unknown-label-fg-color);"
}
};
// formatters/html/printers/main.ts
var dropdownIcon = "▼";
function openingBrace(formatter) {
return `{`;
}
function closingBrace(formatter) {
return `}`;
}
function openingBrackets(formatter) {
return `[`;
}
function closingBrackets(formatter) {
return `]`;
}
var HTMLPrinters = {
"collapse": (token, formatter) => {
const styles = token.token.type === "object-start" ? formatter.styles.objectLabel : formatter.styles.arrayLabel;
const collpaseStyles = formatter.styles.collapseLabel;
return `${token.name} ` + (token.token.type === "object-start" ? openingBrace(formatter) : openingBrackets(formatter)) + ` collapsed ` + (token.token.type === "object-start" ? closingBrace(formatter) : closingBrackets(formatter));
},
"object-start": (token, formatter) => {
formatter.indentation.increment();
const styles = formatter.styles.objectLabel;
const toggleStyles = formatter.styles.toggle;
const label = formatter.context.isStaticMember && formatter.context.staticDepth === 0 ? " " : `${token.constructorName || "Object [null]"} `;
return `${label}` + openingBrace(formatter) + ``;
},
"object-end": (_, formatter) => {
formatter.indentation.decrement();
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
return indent + "" + closingBrace(formatter) + "";
},
"object-key": (token, formatter) => {
formatter.context.isStack = token.value === "stack";
const styles = formatter.styles.objectKey;
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
let value = token.value;
if (token.isSymbol) {
value = `[${value}]`;
} else if (!/^[a-z$_][$\w]*$/i.test(value)) {
value = `"${htmlEscape(value.replace(/"/g, '\\"'))}"`;
}
let prefix = "";
if (formatter.context.isStaticMember) {
formatter.context.staticDepth++;
if (formatter.context.staticDepth === 1) {
const prefixStyles = formatter.styles.objectKeyPrefix;
prefix = `static `;
}
}
return indent + prefix + `${value}: `;
},
"object-circular-ref": (_, formatter) => {
const styles = formatter.styles.circularLabel;
return `[*Circular]`;
},
"object-max-depth-ref": (_, formatter) => {
const styles = formatter.styles.objectLabel;
return `[Object]`;
},
"object-value-getter": (_, formatter) => {
const styles = formatter.styles.getterLabel;
return `[Getter]`;
},
"object-value-start": () => {
return "";
},
"object-value-end": (_, formatter) => {
if (formatter.context.isStaticMember) {
formatter.context.staticDepth--;
}
return `,`;
},
"array-start": (token, formatter) => {
formatter.indentation.increment();
const toggleStyles = formatter.styles.toggle;
const styles = formatter.styles.arrayLabel;
const label = `${token.name}:${token.size} `;
return `${label}` + openingBrackets(formatter) + ``;
},
"array-end": (_, formatter) => {
formatter.indentation.decrement();
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
return indent + "" + closingBrackets(formatter) + "";
},
"array-value-start": (_, formatter) => {
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
return indent;
},
"array-value-hole": (_, formatter) => {
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
const styles = formatter.styles.undefined;
return indent + `${htmlEscape("")},`;
},
"array-value-end": () => {
return `,`;
},
"array-circular-ref": (_, formatter) => {
const styles = formatter.styles.circularLabel;
return `[*Circular]`;
},
"array-max-depth-ref": (_, formatter) => {
const styles = formatter.styles.arrayLabel;
return `[Array]`;
},
"array-max-length-ref": (token, formatter) => {
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
const styles = formatter.styles.arrayLabel;
const itemsLeft = token.size - token.limit;
if (itemsLeft <= 0) {
return "";
}
const label = itemsLeft === 1 ? `1 more item` : `${itemsLeft} more items`;
return `${indent}[...${label}]`;
},
"prototype-start": (_, formatter) => {
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
formatter.indentation.increment();
const styles = formatter.styles.prototypeLabel;
const toggleStyles = formatter.styles.toggle;
const label = "[[Prototype]] ";
return indent + `${label}` + openingBrace(formatter) + ``;
},
"prototype-end": (_, formatter) => {
formatter.indentation.decrement();
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
return indent + "" + closingBrace(formatter) + "";
},
"map-start": (token, formatter) => {
formatter.indentation.increment();
const toggleStyles = formatter.styles.toggle;
const styles = formatter.styles.mapLabel;
const label = `Map:${token.size} `;
return `${label}` + openingBrace(formatter) + ``;
},
"map-end": (_, formatter) => {
formatter.indentation.decrement();
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
return indent + "" + closingBrace(formatter) + "";
},
"map-row-start": (_, formatter) => {
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
formatter.indentation.increment();
return indent + openingBrackets(formatter);
},
"map-row-end": (_, formatter) => {
formatter.indentation.decrement();
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
return indent + closingBrackets(formatter) + `,`;
},
"map-key-start": (_, formatter) => {
const styles = formatter.styles.objectKey;
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
return indent + `key: `;
},
"map-key-end": function() {
return "";
},
"map-value-start": (_, formatter) => {
const styles = formatter.styles.objectKey;
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
return indent + `value: `;
},
"map-value-end": function() {
return "";
},
"map-circular-ref": (_, formatter) => {
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
const styles = formatter.styles.circularLabel;
return `${indent}[*Circular]`;
},
"map-max-depth-ref": (_, formatter) => {
const styles = formatter.styles.mapLabel;
return `[Map]`;
},
"map-max-length-ref": (token, formatter) => {
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
const styles = formatter.styles.mapLabel;
const itemsLeft = token.size - token.limit;
if (itemsLeft <= 0) {
return "";
}
const label = itemsLeft === 1 ? `1 more item` : `${itemsLeft} more items`;
return `${indent}[...${label}]`;
},
"set-start": (token, formatter) => {
formatter.indentation.increment();
const toggleStyles = formatter.styles.toggle;
const styles = formatter.styles.setLabel;
const label = `Set:${token.size} `;
return `${label}` + openingBrackets(formatter) + ``;
},
"set-end": (_, formatter) => {
formatter.indentation.decrement();
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
return indent + "" + closingBrackets(formatter) + "";
},
"set-value-start": (_, formatter) => {
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
return indent;
},
"set-value-end": () => {
return `,`;
},
"set-circular-ref": (_, formatter) => {
const styles = formatter.styles.circularLabel;
return `[*Circular]`;
},
"set-max-depth-ref": (_, formatter) => {
const styles = formatter.styles.setLabel;
return `[Set]`;
},
"set-max-length-ref": (token, formatter) => {
const indent = `${formatter.newLine}${formatter.indentation.getSpaces()}`;
const styles = formatter.styles.setLabel;
const itemsLeft = token.size - token.limit;
if (itemsLeft <= 0) {
return "";
}
const label = itemsLeft === 1 ? `1 more item` : `${itemsLeft} more items`;
return `${indent}[...${label}]`;
},
"string": (token, formatter) => {
let value = token.value;
const indent = formatter.indentation.getSpaces();
if (formatter.context.isStack) {
value = token.value.split("\n").map((row, index) => {
let rowValue = `${htmlEscape(row.trim())}`;
if (index > 0) {
rowValue = `${indent}${rowValue}`;
}
return rowValue;
}).join("\n");
} else {
value = wordWrap(token.value, {
newLine: formatter.newLine,
indent: formatter.indentation.getSpaces(),
width: 70
});
}
const styles = formatter.styles.string;
return `${value}`;
},
"boolean": (token, formatter) => {
const styles = formatter.styles.boolean;
return `` + token.value + "";
},
"number": (token, formatter) => {
const styles = formatter.styles.number;
return `` + token.value + "";
},
"bigInt": (token, formatter) => {
const styles = formatter.styles.bigInt;
return `` + token.value + "";
},
"undefined": (_, formatter) => {
const styles = formatter.styles.undefined;
return `undefined`;
},
"null": (_, formatter) => {
const styles = formatter.styles.null;
return `null`;
},
"symbol": (token, formatter) => {
const styles = formatter.styles.symbol;
return `` + token.value + "";
},
"function": (token, formatter) => {
const className = token.isClass ? "dumper-class" : "dumper-function";
const styles = token.isClass ? formatter.styles.classLabel : formatter.styles.functionLabel;
const async = token.isAsync ? `async ` : "";
const generator = token.isGenerator ? `*` : "";
const label = token.isClass ? `[class ${token.name}]` : `[${async}${generator}function ${token.name}]`;
return `` + label + "";
},
"date": function(token, formatter) {
const styles = formatter.styles.date;
return `` + token.value + "";
},
"buffer": function(token, formatter) {
const styles = formatter.styles.buffer;
return `` + htmlEscape(token.value) + "";
},
"regexp": function(token, formatter) {
const styles = formatter.styles.regex;
return `` + token.value + "";
},
"unknown": function(token, formatter) {
const styles = formatter.styles.unknownLabel;
return `` + String(token.value) + "";
},
"weak-set": function(_, formatter) {
const styles = formatter.styles.weakSetLabel;
return `[WeakSet]`;
},
"weak-ref": function(_, formatter) {
const styles = formatter.styles.weakRefLabel;
return `[WeakRef]`;
},
"weak-map": function(_, formatter) {
const styles = formatter.styles.weakMapLabel;
return `[WeakMap]`;
},
"observable": function(_, formatter) {
const styles = formatter.styles.observableLabel;
return `[Observable]`;
},
"blob": function(token, formatter) {
const styles = formatter.styles.objectLabel;
const propertiesStart = `{ `;
const propertiesEnd = ` }`;
const sizeProp = `size: `;
const sizeValue = `${token.size},`;
const typeProp = `type: `;
const typeValue = `${token.contentType}`;
return `[Blob]` + propertiesStart + `${sizeProp}${sizeValue} ${typeProp}${typeValue}` + propertiesEnd + "";
},
"promise": function(token, formatter) {
const styles = formatter.styles.promiseLabel;
const label = token.isFulfilled ? "resolved" : "pending";
return `[Promise${htmlEscape(`<${label}>`)}]`;
},
"generator": function(token, formatter) {
const styles = formatter.styles.generatorLabel;
const label = token.isAsync ? "[AsyncGenerator] {}" : "[Generator] {}";
return `` + label + "";
},
"static-members-start": function(_, formatter) {
formatter.context.isStaticMember = true;
formatter.context.staticDepth = 0;
return "";
},
"static-members-end": function(_, formatter) {
formatter.context.isStaticMember = false;
formatter.context.staticDepth = 0;
return "";
}
};
// formatters/html/formatter.ts
var seed = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
var nanoid = (length = 15) => {
let output = "";
let random = new Uint8Array(length);
if (globalThis.crypto) {
crypto.getRandomValues(random);
} else {
for (let i = 0; i < length; i++) {
random[i] = Math.floor(Math.random() * 256);
}
}
for (let n = 0; n < length; n++) {
output += seed[63 & random[n]];
}
return output;
};
var HTMLFormatter = class {
#config;
/**
* Styles for output elements
*/
styles;
/**
* Context maintained through out the printing
* phase. Each instance has its own context
* that gets mutated internally.
*/
context;
/**
* Value for the newline character
*/
newLine = "\n";
/**
* Utility to manage indentation
*/
indentation = {
counter: 0,
/**
* Increment the identation by 1 step
*/
increment() {
this.counter++;
},
/**
* Decrement the identation by 1 step
*/
decrement() {
this.counter--;
},
/**
* Get the identation spaces as per the current
* identation level
*/
getSpaces() {
return new Array(this.counter * 2 + 1).join(" ");
}
};
constructor(config, context) {
this.context = context || {};
this.#config = config || {};
this.styles = Object.freeze({ ...themes.nightOwl, ...config?.styles });
}
/**
* Wraps the final output inside pre tags and add the script
* to activate the frontend iteractions.
*/
#wrapOutput(code) {
const id = `dump-${nanoid()}`;
const expand = this.#config.expand === "all" ? `'all'` : this.#config.expand;
const nonce = this.#config.cspNonce ? ` nonce="${this.#config.cspNonce}"` : "";
return `
`;
}
/**
* Format a collection of tokens to HTML output wrapped
* inside the `pre` tag.
*/
format(tokens) {
return this.#wrapOutput(
tokens.map((token) => {
const formatter = HTMLPrinters[token.type];
return formatter(token, this) || "";
}).join("")
);
}
};
// formatters/html/head.ts
function createStyleSheet() {
return `.dumper-dump, .dumper-dump pre, .dumper-dump code, .dumper-dump samp {
font-family: JetBrains Mono, monaspace argon, Menlo, Monaco, Consolas, monospace;
}
.dumper-dump pre {
line-height: 24px;
font-size: 15px;
overflow-x: scroll;
position:relative;
z-index:99999;
padding: 10px 15px;
margin: 0;
}
.dumper-dump pre samp {
position: relative;
}
.dumper-dump pre samp[hidden="true"] {
display: none;
}
.dumper-dump .dumper-prototype-group {
opacity: 0.5;
}
.dumper-dump .dumper-toggle {
transform: rotate(270deg);
}
.dumper-dump .dumper-toggle span {
display: inline-block;
position: relative;
top: 1px;
margin: 0 5px;
font-size: 14px;
}
.dumper-dump .dumper-toggle[aria-expanded="true"] {
transform: none;
}`;
}
function createScript() {
return `function expandGroup(group) {
const trigger = group.querySelector('button')
trigger.setAttribute('aria-expanded', 'true')
const samp = group.querySelector('samp')
samp.removeAttribute('hidden')
}
function collapseGroup(group) {
const trigger = group.querySelector('button')
trigger.removeAttribute('aria-expanded', 'true')
const samp = group.querySelector('samp')
samp.setAttribute('hidden', 'true')
}
function dumperActivate(dumpId, expand) {
if (expand === true) {
expandGroup(document.querySelector(\`#\${dumpId} .dumper-group\`))
} else if (expand === 'all') {
document.querySelectorAll(\`#\${dumpId} .dumper-group\`).forEach((c) => expandGroup(c))
}
document.querySelectorAll(\`#\${dumpId} .dumper-toggle\`).forEach((trigger) => {
trigger.addEventListener('click', function (event) {
const target = event.currentTarget
const parent = target.parentElement
const isExpanded = !!target.getAttribute('aria-expanded')
if (isExpanded) {
collapseGroup(parent)
if (event.metaKey) {
parent.querySelectorAll('.dumper-group').forEach((c) => collapseGroup(c))
}
} else {
expandGroup(parent)
if (event.metaKey) {
parent.querySelectorAll('.dumper-group').forEach((c) => expandGroup(c))
}
}
})
})
}`;
}
// formatters/html/main.ts
function dump(value, config) {
const parser = new Parser(config);
parser.parse(value);
return new HTMLFormatter(config).format(parser.flush());
}
export {
HTMLFormatter,
HTMLPrinters,
createScript,
createStyleSheet,
dump,
themes
};