🎉 initiate project *astro_rewrite*

This commit is contained in:
sindrekjelsrud 2023-07-19 21:31:30 +02:00
parent ffd4d5e86c
commit 2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions

13
node_modules/ansi-sequence-parser/CHANGELOG.md generated vendored Normal file
View file

@ -0,0 +1,13 @@
# ansi-sequence-parser
## 1.1.0
### Minor Changes
- 57cbaa6: Add default named colors map
## 1.0.0
### Major Changes
- 86719a2: Initial release

133
node_modules/ansi-sequence-parser/README.md generated vendored Normal file
View file

@ -0,0 +1,133 @@
# `ansi-sequence-parser`
Parse ANSI escape sequences into a readable format for things like generating pretty HTML.
Install with your favourite package manager:
```sh
pnpm install ansi-sequence-parser
yarn add ansi-sequence-parser
npm install ansi-sequence-parser
```
## Parsing
Token format:
```ts
interface ParseToken {
// The text content of the token
value: string;
// The foreground color
foreground: Color | null;
// The background color
background: Color | null;
// A Set of the applied decorations
decorations: Set<DecorationType>;
}
```
Parse full input at once:
```ts
import { parseAnsiSequences } from 'ansi-sequence-parser';
const tokens = parseAnsiSequences(input);
```
If you want to parse your input in multiple chunks, make sure to create a parser so that you can maintain
state between chunks:
```ts
import { createAnsiSequenceParser } from 'ansi-sequence-parser';
const parser = createAnsiSequenceParser();
const tokensByLine = input.split(/\r?\n/).map((line) => parser.parse(line));
```
## Colors
Colors format:
```ts
// A named ANSI color, e.g. `magenta` or `brightBlue`
export interface NamedColor {
type: 'named';
name: ColorName;
}
// A color-table lookup
export interface TableColor {
type: 'table';
index: number;
}
// An RGB color
export interface RgbColor {
type: 'rgb';
rgb: [number, number, number];
}
export type Color = NamedColor | TableColor | RgbColor;
```
In order to interpret all of the above color types as a hex code, you can create a color palette:
```ts
import { parseAnsiSequences, createColorPalette } from 'ansi-sequence-parser';
const tokens = parseAnsiSequences(input);
const colorPalette = createColorPalette();
for (const token of tokens) {
if (token.foreground) {
const foregroundValue = colorPalette.value(token.foreground);
}
if (token.background) {
const backgroundValue = colorPalette.value(token.background);
}
}
```
You can also specify a custom named colors map:
```ts
import { parseAnsiSequences, createColorPalette } from 'ansi-sequence-parser';
const tokens = parseAnsiSequences(input);
const colorPalette = createColorPalette({
black: '#000000',
red: '#bb0000',
green: '#00bb00',
yellow: '#bbbb00',
blue: '#0000bb',
magenta: '#ff00ff',
cyan: '#00bbbb',
white: '#eeeeee',
brightBlack: '#555555',
brightRed: '#ff5555',
brightGreen: '#00ff00',
brightYellow: '#ffff55',
brightBlue: '#5555ff',
brightMagenta: '#ff55ff',
brightCyan: '#55ffff',
brightWhite: '#ffffff',
});
```
If you want to modify the default named colors map, you can import the `defaultNamedColorsMap`:
```ts
import {
parseAnsiSequences,
createColorPalette,
defaultNamedColorsMap,
} from 'ansi-sequence-parser';
const tokens = parseAnsiSequences(input);
const colorPalette = createColorPalette({
...defaultNamedColorsMap,
blue: '#0000cc',
});
```

298
node_modules/ansi-sequence-parser/dist/index.cjs generated vendored Normal file
View file

@ -0,0 +1,298 @@
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
createAnsiSequenceParser: () => createAnsiSequenceParser,
createColorPalette: () => createColorPalette,
decorations: () => decorations,
defaultNamedColorsMap: () => defaultNamedColorsMap,
namedColors: () => namedColors,
parseAnsiSequences: () => parseAnsiSequences
});
module.exports = __toCommonJS(src_exports);
// src/colors.ts
var namedColors = [
"black",
"red",
"green",
"yellow",
"blue",
"magenta",
"cyan",
"white",
"brightBlack",
"brightRed",
"brightGreen",
"brightYellow",
"brightBlue",
"brightMagenta",
"brightCyan",
"brightWhite"
];
// src/decorations.ts
var decorations = {
1: "bold",
2: "dim",
3: "italic",
4: "underline",
7: "reverse",
9: "strikethrough"
};
// src/parser.ts
function findSequence(value, position) {
const nextEscape = value.indexOf("\x1B", position);
if (nextEscape !== -1) {
if (value[nextEscape + 1] === "[") {
const nextClose = value.indexOf("m", nextEscape);
return {
sequence: value.substring(nextEscape + 2, nextClose).split(";"),
startPosition: nextEscape,
position: nextClose + 1
};
}
}
return {
position: value.length
};
}
function parseColor(sequence) {
const colorMode = sequence.shift();
if (colorMode === "2") {
const rgb = sequence.splice(0, 3).map((x) => Number.parseInt(x));
if (rgb.length !== 3 || rgb.some((x) => Number.isNaN(x)))
return;
return {
type: "rgb",
rgb
};
} else if (colorMode === "5") {
const index = sequence.shift();
if (index) {
return { type: "table", index: Number(index) };
}
}
}
function parseSequence(sequence) {
const commands = [];
while (sequence.length > 0) {
const code = sequence.shift();
if (!code)
continue;
const codeInt = Number.parseInt(code);
if (Number.isNaN(codeInt))
continue;
if (codeInt === 0) {
commands.push({ type: "resetAll" });
} else if (codeInt <= 9) {
const decoration = decorations[codeInt];
if (decoration) {
commands.push({
type: "setDecoration",
value: decorations[codeInt]
});
}
} else if (codeInt <= 29) {
const decoration = decorations[codeInt - 20];
if (decoration) {
commands.push({
type: "resetDecoration",
value: decoration
});
}
} else if (codeInt <= 37) {
commands.push({
type: "setForegroundColor",
value: { type: "named", name: namedColors[codeInt - 30] }
});
} else if (codeInt === 38) {
const color = parseColor(sequence);
if (color) {
commands.push({
type: "setForegroundColor",
value: color
});
}
} else if (codeInt === 39) {
commands.push({
type: "resetForegroundColor"
});
} else if (codeInt <= 47) {
commands.push({
type: "setBackgroundColor",
value: { type: "named", name: namedColors[codeInt - 40] }
});
} else if (codeInt === 48) {
const color = parseColor(sequence);
if (color) {
commands.push({
type: "setBackgroundColor",
value: color
});
}
} else if (codeInt === 49) {
commands.push({
type: "resetBackgroundColor"
});
} else if (codeInt >= 90 && codeInt <= 97) {
commands.push({
type: "setForegroundColor",
value: { type: "named", name: namedColors[codeInt - 90 + 8] }
});
} else if (codeInt >= 100 && codeInt <= 107) {
commands.push({
type: "setBackgroundColor",
value: { type: "named", name: namedColors[codeInt - 100 + 8] }
});
}
}
return commands;
}
function createAnsiSequenceParser() {
let foreground = null;
let background = null;
let decorations2 = /* @__PURE__ */ new Set();
return {
parse(value) {
const tokens = [];
let position = 0;
do {
const findResult = findSequence(value, position);
const text = findResult.sequence ? value.substring(position, findResult.startPosition) : value.substring(position);
if (text.length > 0) {
tokens.push({
value: text,
foreground,
background,
decorations: new Set(decorations2)
});
}
if (findResult.sequence) {
const commands = parseSequence(findResult.sequence);
for (const styleToken of commands) {
if (styleToken.type === "resetAll") {
foreground = null;
background = null;
decorations2.clear();
} else if (styleToken.type === "resetForegroundColor") {
foreground = null;
} else if (styleToken.type === "resetBackgroundColor") {
background = null;
} else if (styleToken.type === "resetDecoration") {
decorations2.delete(styleToken.value);
}
}
for (const styleToken of commands) {
if (styleToken.type === "setForegroundColor") {
foreground = styleToken.value;
} else if (styleToken.type === "setBackgroundColor") {
background = styleToken.value;
} else if (styleToken.type === "setDecoration") {
decorations2.add(styleToken.value);
}
}
}
position = findResult.position;
} while (position < value.length);
return tokens;
}
};
}
function parseAnsiSequences(value) {
return createAnsiSequenceParser().parse(value);
}
// src/palette.ts
var defaultNamedColorsMap = {
black: "#000000",
red: "#bb0000",
green: "#00bb00",
yellow: "#bbbb00",
blue: "#0000bb",
magenta: "#ff00ff",
cyan: "#00bbbb",
white: "#eeeeee",
brightBlack: "#555555",
brightRed: "#ff5555",
brightGreen: "#00ff00",
brightYellow: "#ffff55",
brightBlue: "#5555ff",
brightMagenta: "#ff55ff",
brightCyan: "#55ffff",
brightWhite: "#ffffff"
};
function createColorPalette(namedColorsMap = defaultNamedColorsMap) {
function namedColor(name) {
return namedColorsMap[name];
}
function rgbColor(rgb) {
return `#${rgb.map((x) => Math.max(0, Math.min(x, 255)).toString(16).padStart(2, "0")).join("")}`;
}
let colorTable;
function getColorTable() {
if (colorTable) {
return colorTable;
}
colorTable = [];
for (let i = 0; i < namedColors.length; i++) {
colorTable.push(namedColor(namedColors[i]));
}
let levels = [0, 95, 135, 175, 215, 255];
for (let r = 0; r < 6; r++) {
for (let g = 0; g < 6; g++) {
for (let b = 0; b < 6; b++) {
colorTable.push(rgbColor([levels[r], levels[g], levels[b]]));
}
}
}
let level = 8;
for (let i = 0; i < 24; i++, level += 10) {
colorTable.push(rgbColor([level, level, level]));
}
return colorTable;
}
function tableColor(index) {
return getColorTable()[index];
}
function value(color) {
switch (color.type) {
case "named":
return namedColor(color.name);
case "rgb":
return rgbColor(color.rgb);
case "table":
return tableColor(color.index);
}
}
return {
value
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
createAnsiSequenceParser,
createColorPalette,
decorations,
defaultNamedColorsMap,
namedColors,
parseAnsiSequences
});

60
node_modules/ansi-sequence-parser/dist/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,60 @@
declare const namedColors: readonly ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "brightBlack", "brightRed", "brightGreen", "brightYellow", "brightBlue", "brightMagenta", "brightCyan", "brightWhite"];
type ColorName = typeof namedColors[number];
interface NamedColor {
type: 'named';
name: ColorName;
}
interface TableColor {
type: 'table';
index: number;
}
interface RgbColor {
type: 'rgb';
rgb: [number, number, number];
}
type Color = NamedColor | TableColor | RgbColor;
declare const decorations: {
readonly 1: "bold";
readonly 2: "dim";
readonly 3: "italic";
readonly 4: "underline";
readonly 7: "reverse";
readonly 9: "strikethrough";
};
type DecorationType = typeof decorations[keyof typeof decorations];
interface ParseToken {
value: string;
foreground: Color | null;
background: Color | null;
decorations: Set<DecorationType>;
}
declare function createAnsiSequenceParser(): {
parse(value: string): ParseToken[];
};
declare function parseAnsiSequences(value: string): ParseToken[];
declare const defaultNamedColorsMap: {
readonly black: "#000000";
readonly red: "#bb0000";
readonly green: "#00bb00";
readonly yellow: "#bbbb00";
readonly blue: "#0000bb";
readonly magenta: "#ff00ff";
readonly cyan: "#00bbbb";
readonly white: "#eeeeee";
readonly brightBlack: "#555555";
readonly brightRed: "#ff5555";
readonly brightGreen: "#00ff00";
readonly brightYellow: "#ffff55";
readonly brightBlue: "#5555ff";
readonly brightMagenta: "#ff55ff";
readonly brightCyan: "#55ffff";
readonly brightWhite: "#ffffff";
};
declare function createColorPalette(namedColorsMap?: Record<ColorName, string>): {
value: (color: Color) => string;
};
export { Color, ColorName, DecorationType, NamedColor, ParseToken, RgbColor, TableColor, createAnsiSequenceParser, createColorPalette, decorations, defaultNamedColorsMap, namedColors, parseAnsiSequences };

267
node_modules/ansi-sequence-parser/dist/index.js generated vendored Normal file
View file

@ -0,0 +1,267 @@
// src/colors.ts
var namedColors = [
"black",
"red",
"green",
"yellow",
"blue",
"magenta",
"cyan",
"white",
"brightBlack",
"brightRed",
"brightGreen",
"brightYellow",
"brightBlue",
"brightMagenta",
"brightCyan",
"brightWhite"
];
// src/decorations.ts
var decorations = {
1: "bold",
2: "dim",
3: "italic",
4: "underline",
7: "reverse",
9: "strikethrough"
};
// src/parser.ts
function findSequence(value, position) {
const nextEscape = value.indexOf("\x1B", position);
if (nextEscape !== -1) {
if (value[nextEscape + 1] === "[") {
const nextClose = value.indexOf("m", nextEscape);
return {
sequence: value.substring(nextEscape + 2, nextClose).split(";"),
startPosition: nextEscape,
position: nextClose + 1
};
}
}
return {
position: value.length
};
}
function parseColor(sequence) {
const colorMode = sequence.shift();
if (colorMode === "2") {
const rgb = sequence.splice(0, 3).map((x) => Number.parseInt(x));
if (rgb.length !== 3 || rgb.some((x) => Number.isNaN(x)))
return;
return {
type: "rgb",
rgb
};
} else if (colorMode === "5") {
const index = sequence.shift();
if (index) {
return { type: "table", index: Number(index) };
}
}
}
function parseSequence(sequence) {
const commands = [];
while (sequence.length > 0) {
const code = sequence.shift();
if (!code)
continue;
const codeInt = Number.parseInt(code);
if (Number.isNaN(codeInt))
continue;
if (codeInt === 0) {
commands.push({ type: "resetAll" });
} else if (codeInt <= 9) {
const decoration = decorations[codeInt];
if (decoration) {
commands.push({
type: "setDecoration",
value: decorations[codeInt]
});
}
} else if (codeInt <= 29) {
const decoration = decorations[codeInt - 20];
if (decoration) {
commands.push({
type: "resetDecoration",
value: decoration
});
}
} else if (codeInt <= 37) {
commands.push({
type: "setForegroundColor",
value: { type: "named", name: namedColors[codeInt - 30] }
});
} else if (codeInt === 38) {
const color = parseColor(sequence);
if (color) {
commands.push({
type: "setForegroundColor",
value: color
});
}
} else if (codeInt === 39) {
commands.push({
type: "resetForegroundColor"
});
} else if (codeInt <= 47) {
commands.push({
type: "setBackgroundColor",
value: { type: "named", name: namedColors[codeInt - 40] }
});
} else if (codeInt === 48) {
const color = parseColor(sequence);
if (color) {
commands.push({
type: "setBackgroundColor",
value: color
});
}
} else if (codeInt === 49) {
commands.push({
type: "resetBackgroundColor"
});
} else if (codeInt >= 90 && codeInt <= 97) {
commands.push({
type: "setForegroundColor",
value: { type: "named", name: namedColors[codeInt - 90 + 8] }
});
} else if (codeInt >= 100 && codeInt <= 107) {
commands.push({
type: "setBackgroundColor",
value: { type: "named", name: namedColors[codeInt - 100 + 8] }
});
}
}
return commands;
}
function createAnsiSequenceParser() {
let foreground = null;
let background = null;
let decorations2 = /* @__PURE__ */ new Set();
return {
parse(value) {
const tokens = [];
let position = 0;
do {
const findResult = findSequence(value, position);
const text = findResult.sequence ? value.substring(position, findResult.startPosition) : value.substring(position);
if (text.length > 0) {
tokens.push({
value: text,
foreground,
background,
decorations: new Set(decorations2)
});
}
if (findResult.sequence) {
const commands = parseSequence(findResult.sequence);
for (const styleToken of commands) {
if (styleToken.type === "resetAll") {
foreground = null;
background = null;
decorations2.clear();
} else if (styleToken.type === "resetForegroundColor") {
foreground = null;
} else if (styleToken.type === "resetBackgroundColor") {
background = null;
} else if (styleToken.type === "resetDecoration") {
decorations2.delete(styleToken.value);
}
}
for (const styleToken of commands) {
if (styleToken.type === "setForegroundColor") {
foreground = styleToken.value;
} else if (styleToken.type === "setBackgroundColor") {
background = styleToken.value;
} else if (styleToken.type === "setDecoration") {
decorations2.add(styleToken.value);
}
}
}
position = findResult.position;
} while (position < value.length);
return tokens;
}
};
}
function parseAnsiSequences(value) {
return createAnsiSequenceParser().parse(value);
}
// src/palette.ts
var defaultNamedColorsMap = {
black: "#000000",
red: "#bb0000",
green: "#00bb00",
yellow: "#bbbb00",
blue: "#0000bb",
magenta: "#ff00ff",
cyan: "#00bbbb",
white: "#eeeeee",
brightBlack: "#555555",
brightRed: "#ff5555",
brightGreen: "#00ff00",
brightYellow: "#ffff55",
brightBlue: "#5555ff",
brightMagenta: "#ff55ff",
brightCyan: "#55ffff",
brightWhite: "#ffffff"
};
function createColorPalette(namedColorsMap = defaultNamedColorsMap) {
function namedColor(name) {
return namedColorsMap[name];
}
function rgbColor(rgb) {
return `#${rgb.map((x) => Math.max(0, Math.min(x, 255)).toString(16).padStart(2, "0")).join("")}`;
}
let colorTable;
function getColorTable() {
if (colorTable) {
return colorTable;
}
colorTable = [];
for (let i = 0; i < namedColors.length; i++) {
colorTable.push(namedColor(namedColors[i]));
}
let levels = [0, 95, 135, 175, 215, 255];
for (let r = 0; r < 6; r++) {
for (let g = 0; g < 6; g++) {
for (let b = 0; b < 6; b++) {
colorTable.push(rgbColor([levels[r], levels[g], levels[b]]));
}
}
}
let level = 8;
for (let i = 0; i < 24; i++, level += 10) {
colorTable.push(rgbColor([level, level, level]));
}
return colorTable;
}
function tableColor(index) {
return getColorTable()[index];
}
function value(color) {
switch (color.type) {
case "named":
return namedColor(color.name);
case "rgb":
return rgbColor(color.rgb);
case "table":
return tableColor(color.index);
}
}
return {
value
};
}
export {
createAnsiSequenceParser,
createColorPalette,
decorations,
defaultNamedColorsMap,
namedColors,
parseAnsiSequences
};

42
node_modules/ansi-sequence-parser/package.json generated vendored Normal file
View file

@ -0,0 +1,42 @@
{
"name": "ansi-sequence-parser",
"description": "A parser for ANSI escape sequences",
"repository": {
"type": "git",
"url": "https://github.com/blake-mealey/ansi-sequence-parser.git"
},
"homepage": "https://github.com/blake-mealey/ansi-sequence-parser#readme",
"version": "1.1.0",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"require": "./dist/index.cjs",
"import": "./dist/index.js"
}
},
"files": [
"dist",
"CHANGELOG.md",
"README.md"
],
"keywords": [
"ansi",
"sequences",
"parser"
],
"author": "blake-mealey",
"license": "MIT",
"devDependencies": {
"@changesets/cli": "^2.26.0",
"tsup": "^6.5.0",
"typescript": "^4.9.4",
"vitest": "^0.28.3"
},
"scripts": {
"build": "tsup src/index.ts --format cjs,esm --dts --clean",
"test": "vitest",
"changeset": "changeset"
}
}