New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

blipgloss

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

blipgloss - npm Package Compare versions

Comparing version

to
0.3.0

dist/index.js.map

33

dist/index.d.ts

@@ -12,3 +12,7 @@ // Generated by dts-bundle-generator v8.0.1

};
export type BlipglossColor = string | AdaptiveColor | CompleteColor;
export type CompleteAdaptiveColor = {
Light: CompleteColor;
Dark: CompleteColor;
};
export type BlipglossColor = string | AdaptiveColor | CompleteColor | CompleteAdaptiveColor;
export declare enum Position {

@@ -31,3 +35,10 @@ Top = 0,

};
export type BorderStyle = "rounded" | "double" | "normal" | "hidden" | "thick" | CustomBorder;
export declare enum Border {
Rounded = "rounded",
Double = "double",
Normal = "normal",
Hidden = "hidden",
Thick = "thick"
}
export type BorderStyle = Border | CustomBorder;
export declare class Style {

@@ -38,5 +49,6 @@ #private;

private SetColorValue;
private SetStringValue;
private SetBooleanValue;
private SetIntValue;
SetString(text: string): this;
String(): string;
Bold(val: boolean): this;

@@ -69,2 +81,3 @@ Strikethrough(val: boolean): this;

BorderRightForeground(color: BlipglossColor): this;
Border(style: BorderStyle, ...args: boolean[]): this;
BorderStyle(style: BorderStyle): this;

@@ -96,8 +109,4 @@ BorderTop(val: boolean): this;

MaxHeight(val: number): this;
WithWhitespaceBackground(color: BlipglossColor): this;
WithWhitespaceForeground(color: BlipglossColor): this;
/**
* Sets the characters to be rendered in the whitespace.
*/
WithWhitespaceChars(char: string): this;
Inherit(style: Style): this;
Underline(value: boolean): this;
}

@@ -113,3 +122,9 @@ export declare function NewStyle(): Style;

export declare function Height(text: string): number;
export declare function WithWhitespaceBackground(value: BlipglossColor): string;
export declare function WithWhitespaceForeground(value: BlipglossColor): string;
export declare function WithWhitespaceChars(char: string): string;
export declare function Place(width: number, height: number, hPos: number, vPos: number, str: string, ...whitespaceOptions: string[]): string;
export declare function PlaceHorizontal(width: number, pos: number, str: string, ...whitespaceOptions: string[]): string;
export declare function PlaceVertical(height: number, pos: number, str: string, ...whitespaceOptions: string[]): string;
export {};

@@ -1,6 +0,3 @@

// src/lib.ts
import {CString as CString2, ptr} from "bun:ffi";
// src/ffi.ts
import {dlopen, FFIType, suffix} from "bun:ffi";
import {FFIType, dlopen, suffix} from "bun:ffi";
var { platform, arch } = process;

@@ -23,2 +20,6 @@ var filename;

},
String: {
args: [FFIType.ptr],
returns: FFIType.ptr
},
Copy: {

@@ -36,6 +37,2 @@ args: [FFIType.ptr],

},
SetStringValue: {
args: [FFIType.ptr, FFIType.ptr, FFIType.ptr],
returns: FFIType.void
},
SetBooleanValue: {

@@ -89,2 +86,13 @@ args: [FFIType.ptr, FFIType.ptr, FFIType.bool],

},
Border: {
args: [
FFIType.ptr,
FFIType.ptr,
FFIType.bool,
FFIType.bool,
FFIType.bool,
FFIType.bool
],
returns: FFIType.void
},
BorderStyle: {

@@ -101,2 +109,41 @@ args: [FFIType.ptr, FFIType.ptr],

returns: FFIType.void
},
Inherit: {
args: [FFIType.ptr, FFIType.ptr],
returns: FFIType.void
},
WithWhitespaceChars: {
args: [FFIType.ptr],
returns: FFIType.ptr
},
WithWhitespaceBackground: {
args: [FFIType.ptr, FFIType.int],
returns: FFIType.ptr
},
WithWhitespaceForeground: {
args: [FFIType.ptr, FFIType.int],
returns: FFIType.ptr
},
Place: {
args: [
FFIType.int,
FFIType.int,
FFIType.f64,
FFIType.f64,
FFIType.ptr,
FFIType.ptr
],
returns: FFIType.ptr
},
PlaceVertical: {
args: [FFIType.int, FFIType.f64, FFIType.ptr, FFIType.ptr],
returns: FFIType.ptr
},
PlaceHorizontal: {
args: [FFIType.int, FFIType.f64, FFIType.ptr, FFIType.ptr],
returns: FFIType.ptr
},
SetString: {
args: [FFIType.ptr, FFIType.ptr],
returns: FFIType.void
}

@@ -106,9 +153,58 @@ });

// src/utils.ts
import {CString} from "bun:ffi";
function encode(data) {
return utf8e.encode(data + "\0");
return utf8e.encode(`${data}\0`);
}
function whichSidesBool(...args) {
let [top, right, bottom, left, ok] = [false, false, false, false, false];
switch (args.length) {
case 1:
top = args[0];
bottom = args[0];
left = args[0];
right = args[0];
ok = true;
break;
case 2:
top = args[0];
bottom = args[0];
left = args[1];
right = args[1];
ok = true;
break;
case 3:
top = args[0];
left = args[1];
right = args[1];
bottom = args[2];
ok = true;
break;
case 4:
top = args[0];
right = args[1];
bottom = args[2];
left = args[3];
ok = true;
break;
}
return [top, right, bottom, left, ok];
}
function getColorType(value) {
if (typeof value === "string") {
return 1;
}
if (("Light" in value) && ("Dark" in value)) {
if (typeof value.Light !== "string" && ("True" in value.Light) && ("ANSI256" in value.Light) && ("ANSI" in value.Light) && typeof value.Dark !== "string" && ("True" in value.Dark) && ("ANSI256" in value.Dark) && ("ANSI" in value.Dark)) {
return 4;
}
return 2;
}
if (("True" in value) && ("ANSI256" in value) && ("ANSI" in value)) {
return 3;
}
throw new Error("Incorrect color type: Must be of type string, AdaptiveColor, CompleteColor, or CompleteAdaptiveColor.");
}
var utf8e = new TextEncoder;
// src/lib.ts
import {CString, ptr} from "bun:ffi";
function NewStyle() {

@@ -120,16 +216,17 @@ return Style.NewStyle();

}
var combineArgs = function(args) {
return args.join(",");
var getStringAndFreePtr = function(textPtr) {
if (!textPtr) {
throw new Error("Pointer required");
}
const textStr = new CString(textPtr);
symbols.FreeString(textStr.ptr);
return textStr.toString();
};
function JoinHorizontal(position, ...paragraphs) {
const textPtr = symbols.JoinHorizontal(position, ptr(encode(combineArgs(paragraphs))));
const textStr = new CString2(textPtr);
symbols.FreeString(textStr.ptr);
return textStr.toString();
const textPtr = symbols.JoinHorizontal(position, ptr(encode(JSON.stringify(paragraphs))));
return getStringAndFreePtr(textPtr);
}
function JoinVertical(position, ...paragraphs) {
const textPtr = symbols.JoinVertical(position, ptr(encode(combineArgs(paragraphs))));
const textStr = new CString2(textPtr);
symbols.FreeString(textStr.ptr);
return textStr.toString();
const textPtr = symbols.JoinVertical(position, ptr(encode(JSON.stringify(paragraphs))));
return getStringAndFreePtr(textPtr);
}

@@ -142,2 +239,33 @@ function Width(text) {

}
function WithWhitespaceBackground(value) {
const colorType = getColorType(value);
const color = colorType !== 1 ? ptr(encode(JSON.stringify(value))) : ptr(encode(value));
const textPtr = symbols.WithWhitespaceBackground(color, colorType);
return getStringAndFreePtr(textPtr);
}
function WithWhitespaceForeground(value) {
const colorType = getColorType(value);
const color = colorType !== 1 ? ptr(encode(JSON.stringify(value))) : ptr(encode(value));
const textPtr = symbols.WithWhitespaceForeground(color, colorType);
return getStringAndFreePtr(textPtr);
}
function WithWhitespaceChars(char) {
const textPtr = symbols.WithWhitespaceChars(ptr(encode(char)));
return getStringAndFreePtr(textPtr);
}
function Place(width, height, hPos, vPos, str, ...whitespaceOptions) {
const combinedOptions = whitespaceOptions.join(",");
const textPtr = symbols.Place(width, height, hPos, vPos, ptr(encode(str)), ptr(encode(combinedOptions)));
return getStringAndFreePtr(textPtr);
}
function PlaceHorizontal(width, pos, str, ...whitespaceOptions) {
const combinedOptions = whitespaceOptions.join(",");
const textPtr = symbols.PlaceHorizontal(width, pos, ptr(encode(str)), ptr(encode(combinedOptions)));
return getStringAndFreePtr(textPtr);
}
function PlaceVertical(height, pos, str, ...whitespaceOptions) {
const combinedOptions = whitespaceOptions.join(",");
const textPtr = symbols.PlaceVertical(height, pos, ptr(encode(str)), ptr(encode(combinedOptions)));
return getStringAndFreePtr(textPtr);
}
var Position;

@@ -151,2 +279,10 @@ (function(Position2) {

})(Position || (Position = {}));
var Border;
(function(Border2) {
Border2["Rounded"] = "rounded";
Border2["Double"] = "double";
Border2["Normal"] = "normal";
Border2["Hidden"] = "hidden";
Border2["Thick"] = "thick";
})(Border || (Border = {}));

@@ -159,22 +295,14 @@ class Style {

static NewStyle() {
return new Style(symbols.NewStyle());
const style = symbols.NewStyle();
if (!style) {
throw new Error("Unable to create new style");
}
return new Style(style);
}
SetColorValue(key, value) {
const isObject = typeof value !== "string";
const color = isObject ? ptr(encode(JSON.stringify(value))) : ptr(encode(value));
if (isObject) {
if ("Light" in value) {
symbols.SetColorValue(this.#handle, ptr(encode(key)), color, 2);
} else {
symbols.SetColorValue(this.#handle, ptr(encode(key)), color, 3);
}
} else {
symbols.SetColorValue(this.#handle, ptr(encode(key)), color, 1);
}
const colorType = getColorType(value);
const color = colorType !== 1 ? ptr(encode(JSON.stringify(value))) : ptr(encode(value));
symbols.SetColorValue(this.#handle, ptr(encode(key)), color, colorType);
return this;
}
SetStringValue(key, value) {
symbols.SetStringValue(this.#handle, ptr(encode(key)), ptr(encode(value)));
return this;
}
SetBooleanValue(key, value) {

@@ -188,2 +316,10 @@ symbols.SetBooleanValue(this.#handle, ptr(encode(key)), value);

}
SetString(text) {
symbols.SetString(this.#handle, ptr(encode(text)));
return this;
}
String() {
const textPtr = symbols.String(this.#handle);
return getStringAndFreePtr(textPtr);
}
Bold(val) {

@@ -272,2 +408,17 @@ return this.SetBooleanValue("Bold", val);

}
Border(style, ...args) {
let [top, right, bottom, left, ok] = whichSidesBool(...args);
if (!ok) {
top = true;
right = true;
bottom = true;
left = true;
}
if (typeof style === "string") {
symbols.Border(this.#handle, ptr(encode(style)), top, right, bottom, left);
} else {
symbols.Border(this.#handle, ptr(encode(JSON.stringify(style))), top, right, bottom, left);
}
return this;
}
BorderStyle(style) {

@@ -311,3 +462,6 @@ if (typeof style === "string") {

const textPtr = symbols.Render(this.#handle, ptr(encode(text)));
const textStr = new CString2(textPtr);
if (!textPtr) {
throw new Error("Unable to render text");
}
const textStr = new CString(textPtr);
symbols.FreeString(textStr.ptr);

@@ -317,3 +471,7 @@ return textStr.toString();

Copy() {
return new Style(symbols.Copy(this.#handle));
const handlerPtr = symbols.Copy(this.#handle);
if (!handlerPtr) {
throw new Error("Unable to copy style");
}
return new Style(handlerPtr);
}

@@ -363,18 +521,20 @@ FreeHandle() {

}
WithWhitespaceBackground(color) {
this.SetColorValue("WithWhitespaceBackground", color);
Inherit(style) {
symbols.Inherit(this.#handle, style.#handle);
return this;
}
WithWhitespaceForeground(color) {
this.SetColorValue("WithWhitespaceForeground", color);
return this;
Underline(value) {
return this.SetBooleanValue("Underline", value);
}
WithWhitespaceChars(char) {
return this.SetStringValue("WithWhitespaceChars", char);
}
}
export {
WithWhitespaceForeground,
WithWhitespaceChars,
WithWhitespaceBackground,
Width,
Style,
Position,
PlaceVertical,
PlaceHorizontal,
Place,
NewStyle,

@@ -384,3 +544,4 @@ JoinVertical,

Height,
HasDarkBackground
HasDarkBackground,
Border
};
{
"name": "blipgloss",
"version": "0.2.2",
"version": "0.3.0",
"main": "dist/index.js",

@@ -12,2 +12,4 @@ "types": "dist/index.d.ts",

"prepublishOnly": "bun run build",
"lint": "biome check src",
"format": "biome format src --write",
"test": "bun wiptest"

@@ -31,6 +33,9 @@ },

"devDependencies": {
"bun-types": "^0.7.1",
"bun-plugin-dts": " ^0.1.0",
"typescript": "^5.1.6"
"@biomejs/biome": "1.2.2",
"@types/color": "^3.0.4",
"bun-plugin-dts": "^0.2.0",
"bun-types": "^1.0.2",
"color": "^4.2.3",
"typescript": "^5.2.2"
}
}

@@ -86,2 +86,13 @@ # blipgloss

### Complete Adaptive Colors
You can use CompleteColor with AdaptiveColor to specify the exact values for light and dark backgrounds without automatic color degradation.
```js
Background({
Light: {TrueColor: "#d7ffae", ANSI256: "193", ANSI: "11"},
Dark: {TrueColor: "#d75fee", ANSI256: "163", ANSI: "5"}
})
```
The terminal's background color will automatically be detected and the appropriate color will be chosen at runtime.

@@ -172,5 +183,7 @@

```js
import { NewStyle, Border } from 'blipgloss'
// Add a purple, rectangular border
const style = NewStyle()
.BorderStyle('normal')
.BorderStyle(Border.Normal)
.BorderForeground("63")

@@ -180,3 +193,3 @@

const anotherStyle = NewStyle()
.BorderStyle('rounded')
.BorderStyle(Border.Rounded)
.BorderForeground("228")

@@ -287,4 +300,23 @@ .BorderBackground("63")

### Placing Text in Whitespace
Sometimes you’ll simply want to place a block of text in whitespace.
```js
import { PlaceHorizontal, PlaceVertical, Place, Position } from 'blipgloss'
// Center a paragraph horizontally in a space 80 cells wide. The height of
// the block returned will be as tall as the input paragraph.
const block = PlaceHorizontal(80, Position.Center, fancyStyledParagraph)
// Place a paragraph at the bottom of a space 30 cells tall. The width of
// the text block returned will be as wide as the input paragraph.
const block = PlaceVertical(30, Position.Bottom, fancyStyledParagraph)
// Place a paragraph in the bottom right corner of a 30x80 cell space.
const block = Place(30, 80, Position.Right, Position.Bottom, fancyStyledParagraph)
```
## License
MIT

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet