brilliant-msg 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +28 -0
- package/README.md +122 -0
- package/dist/async-queue.d.ts +48 -0
- package/dist/brilliant-msg.d.ts +175 -0
- package/dist/brilliant-msg.es.js +26473 -0
- package/dist/brilliant-msg.umd.js +204 -0
- package/dist/index.d.ts +36 -0
- package/dist/rx/audio.d.ts +129 -0
- package/dist/rx/auto-exp-result.d.ts +85 -0
- package/dist/rx/click.d.ts +50 -0
- package/dist/rx/imu.d.ts +77 -0
- package/dist/rx/metering-data.d.ts +56 -0
- package/dist/rx/photo.d.ts +81 -0
- package/dist/rx/tap.d.ts +62 -0
- package/dist/tx/auto-exp-settings.d.ts +62 -0
- package/dist/tx/capture-settings.d.ts +44 -0
- package/dist/tx/code.d.ts +24 -0
- package/dist/tx/image-sprite-block.d.ts +62 -0
- package/dist/tx/manual-exp-settings.d.ts +50 -0
- package/dist/tx/plain-text.d.ts +35 -0
- package/dist/tx/sprite-coords.d.ts +46 -0
- package/dist/tx/sprite.d.ts +92 -0
- package/dist/tx/text-page.d.ts +184 -0
- package/dist/tx/text-sprite-block.d.ts +50 -0
- package/package.json +56 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring camera capture settings.
|
|
3
|
+
*/
|
|
4
|
+
export interface TxCaptureSettingsOptions {
|
|
5
|
+
/** Optional image resolution (256-720, must be even). Defaults to 512. */
|
|
6
|
+
resolution?: number;
|
|
7
|
+
/** Optional index into JPEG quality array [VERY_LOW, LOW, MEDIUM, HIGH, VERY_HIGH] (0-4). Defaults to 4 (VERY_HIGH). */
|
|
8
|
+
qualityIndex?: number;
|
|
9
|
+
/** Optional image pan value (-140 to 140). Defaults to 0. */
|
|
10
|
+
pan?: number;
|
|
11
|
+
/** Optional flag whether to capture in RAW (headerless JPEG) format. Defaults to false. */
|
|
12
|
+
raw?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Message for camera capture settings.
|
|
16
|
+
*/
|
|
17
|
+
export declare class TxCaptureSettings {
|
|
18
|
+
/**
|
|
19
|
+
* Image resolution (256-720, must be even)
|
|
20
|
+
*/
|
|
21
|
+
resolution: number;
|
|
22
|
+
/**
|
|
23
|
+
* Index into [VERY_LOW, LOW, MEDIUM, HIGH, VERY_HIGH]
|
|
24
|
+
*/
|
|
25
|
+
qualityIndex: number;
|
|
26
|
+
/**
|
|
27
|
+
* Image pan value (-140 to 140)
|
|
28
|
+
*/
|
|
29
|
+
pan: number;
|
|
30
|
+
/**
|
|
31
|
+
* Whether to capture in RAW format
|
|
32
|
+
*/
|
|
33
|
+
raw: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Constructs an instance of TxCaptureSettings.
|
|
36
|
+
* @param options Configuration options for the capture settings.
|
|
37
|
+
*/
|
|
38
|
+
constructor(options?: TxCaptureSettingsOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Packs the settings into 6 bytes.
|
|
41
|
+
* @returns Uint8Array Binary representation of the message (6 bytes)
|
|
42
|
+
*/
|
|
43
|
+
pack(): Uint8Array;
|
|
44
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring a TxCode message.
|
|
3
|
+
*/
|
|
4
|
+
export interface TxCodeOptions {
|
|
5
|
+
/** Optional byte value to be transmitted (0-255). Defaults to 0. */
|
|
6
|
+
value?: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* A simple message containing only an optional byte value.
|
|
10
|
+
* Used for signaling the frameside app to take some action.
|
|
11
|
+
*/
|
|
12
|
+
export declare class TxCode {
|
|
13
|
+
value: number;
|
|
14
|
+
/**
|
|
15
|
+
* Constructs an instance of TxCode.
|
|
16
|
+
* @param options Configuration options for the code message.
|
|
17
|
+
*/
|
|
18
|
+
constructor(options?: TxCodeOptions);
|
|
19
|
+
/**
|
|
20
|
+
* Packs the message into a single byte.
|
|
21
|
+
* @returns Uint8Array Binary representation of the message (a single byte)
|
|
22
|
+
*/
|
|
23
|
+
pack(): Uint8Array;
|
|
24
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { TxSprite } from './sprite';
|
|
2
|
+
/**
|
|
3
|
+
* Options for configuring an image sprite block.
|
|
4
|
+
*/
|
|
5
|
+
export interface TxImageSpriteBlockOptions {
|
|
6
|
+
/** The source {@link TxSprite} to be split into strips. */
|
|
7
|
+
image: TxSprite;
|
|
8
|
+
/**
|
|
9
|
+
* Optional height of each sprite strip. Defaults to 16.
|
|
10
|
+
* If the source `image` is compressed (`image.compress` is true),
|
|
11
|
+
* this value is dynamically calculated to respect a 4kB packed size limit per strip
|
|
12
|
+
* and any provided value here is ignored.
|
|
13
|
+
*/
|
|
14
|
+
spriteLineHeight?: number;
|
|
15
|
+
/** Optional flag whether to render lines as they arrive. Defaults to true. */
|
|
16
|
+
progressiveRender?: boolean;
|
|
17
|
+
/** Optional flag whether lines can be updated after initial render. Defaults to true. */
|
|
18
|
+
updatable?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* An image split into horizontal sprite strips.
|
|
22
|
+
*/
|
|
23
|
+
export declare class TxImageSpriteBlock {
|
|
24
|
+
/**
|
|
25
|
+
* Source sprite to split.
|
|
26
|
+
*/
|
|
27
|
+
image: TxSprite;
|
|
28
|
+
/**
|
|
29
|
+
* Height of each sprite strip. If the TxSprite is compressed, the strip has a packed size limit of 4kB and this value is dynamically calculated.
|
|
30
|
+
*/
|
|
31
|
+
spriteLineHeight: number;
|
|
32
|
+
/**
|
|
33
|
+
* Whether to render lines as they arrive.
|
|
34
|
+
*/
|
|
35
|
+
progressiveRender: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Whether lines can be updated after initial render.
|
|
38
|
+
*/
|
|
39
|
+
updatable: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* List of sprite strips.
|
|
42
|
+
*/
|
|
43
|
+
spriteLines: TxSprite[];
|
|
44
|
+
/**
|
|
45
|
+
* Constructs an instance of TxImageSpriteBlock.
|
|
46
|
+
* @param options Configuration options for the image sprite block.
|
|
47
|
+
*/
|
|
48
|
+
constructor(options: TxImageSpriteBlockOptions);
|
|
49
|
+
/**
|
|
50
|
+
* Splits the source image into horizontal strips.
|
|
51
|
+
* This method needs careful implementation based on how pixelData is structured
|
|
52
|
+
* and how BPP affects its layout if it's not 1 byte per pixel index.
|
|
53
|
+
* The current TxSprite.pixelData is Uint8Array of palette indices.
|
|
54
|
+
*/
|
|
55
|
+
private _splitIntoLines;
|
|
56
|
+
/**
|
|
57
|
+
* Packs the image block header into a binary format.
|
|
58
|
+
* @returns Uint8Array Binary representation of the header
|
|
59
|
+
* @throws Error if there are no sprite lines to pack (though _splitIntoLines should always create at least one if height > 0 and spriteLineHeight > 0)
|
|
60
|
+
*/
|
|
61
|
+
pack(): Uint8Array;
|
|
62
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring manual exposure and gain settings.
|
|
3
|
+
*/
|
|
4
|
+
export interface TxManualExpSettingsOptions {
|
|
5
|
+
/** Optional shutter value (4-16383). Defaults to 3072. */
|
|
6
|
+
manualShutter?: number;
|
|
7
|
+
/** Optional analog gain value (1-248). Defaults to 16. */
|
|
8
|
+
manualAnalogGain?: number;
|
|
9
|
+
/** Optional red gain value (0-1023). Defaults to 121. */
|
|
10
|
+
manualRedGain?: number;
|
|
11
|
+
/** Optional green gain value (0-1023). Defaults to 64. */
|
|
12
|
+
manualGreenGain?: number;
|
|
13
|
+
/** Optional blue gain value (0-1023). Defaults to 140. */
|
|
14
|
+
manualBlueGain?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Message for manual exposure and gain settings.
|
|
18
|
+
*/
|
|
19
|
+
export declare class TxManualExpSettings {
|
|
20
|
+
/**
|
|
21
|
+
* Shutter value (4-16383)
|
|
22
|
+
*/
|
|
23
|
+
manualShutter: number;
|
|
24
|
+
/**
|
|
25
|
+
* Analog gain value (1-248)
|
|
26
|
+
*/
|
|
27
|
+
manualAnalogGain: number;
|
|
28
|
+
/**
|
|
29
|
+
* Red gain value (0-1023)
|
|
30
|
+
*/
|
|
31
|
+
manualRedGain: number;
|
|
32
|
+
/**
|
|
33
|
+
* Green gain value (0-1023)
|
|
34
|
+
*/
|
|
35
|
+
manualGreenGain: number;
|
|
36
|
+
/**
|
|
37
|
+
* Blue gain value (0-1023)
|
|
38
|
+
*/
|
|
39
|
+
manualBlueGain: number;
|
|
40
|
+
/**
|
|
41
|
+
* Constructs an instance of TxManualExpSettings.
|
|
42
|
+
* @param options Configuration options for manual exposure and gain settings.
|
|
43
|
+
*/
|
|
44
|
+
constructor(options?: TxManualExpSettingsOptions);
|
|
45
|
+
/**
|
|
46
|
+
* Packs the settings into 9 bytes.
|
|
47
|
+
* @returns Uint8Array Binary representation of the message (9 bytes)
|
|
48
|
+
*/
|
|
49
|
+
pack(): Uint8Array;
|
|
50
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring a plain text message.
|
|
3
|
+
*/
|
|
4
|
+
export interface TxPlainTextOptions {
|
|
5
|
+
/** The plain text content to be transmitted. */
|
|
6
|
+
text: string;
|
|
7
|
+
/** Optional X-coordinate for text position (1-640, Lua/1-based indexing). Defaults to 1. */
|
|
8
|
+
x?: number;
|
|
9
|
+
/** Optional Y-coordinate for text position (1-400, Lua/1-based indexing). Defaults to 1. */
|
|
10
|
+
y?: number;
|
|
11
|
+
/** Optional color palette offset (1-15, 0/'VOID' is invalid). Defaults to 1. */
|
|
12
|
+
paletteOffset?: number;
|
|
13
|
+
/** Optional character spacing value. Defaults to 4. */
|
|
14
|
+
spacing?: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A message containing plain text with positioning and formatting information.
|
|
18
|
+
*/
|
|
19
|
+
export declare class TxPlainText {
|
|
20
|
+
text: string;
|
|
21
|
+
x: number;
|
|
22
|
+
y: number;
|
|
23
|
+
paletteOffset: number;
|
|
24
|
+
spacing: number;
|
|
25
|
+
/**
|
|
26
|
+
* Constructs an instance of TxPlainText.
|
|
27
|
+
* @param options Configuration options for the plain text message.
|
|
28
|
+
*/
|
|
29
|
+
constructor(options: TxPlainTextOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Packs the message into a binary format.
|
|
32
|
+
* @returns Uint8Array Binary representation of the message
|
|
33
|
+
*/
|
|
34
|
+
pack(): Uint8Array;
|
|
35
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for configuring sprite coordinates.
|
|
3
|
+
*/
|
|
4
|
+
export interface TxSpriteCoordsOptions {
|
|
5
|
+
/** Unsigned byte identifying the sprite code. */
|
|
6
|
+
code: number;
|
|
7
|
+
/** X-coordinate for sprite position (1-640). */
|
|
8
|
+
x: number;
|
|
9
|
+
/** Y-coordinate for sprite position (1-400). */
|
|
10
|
+
y: number;
|
|
11
|
+
/** Optional palette offset value for the sprite (0-15). Defaults to 0. */
|
|
12
|
+
offset?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A message containing sprite coordinates information for display.
|
|
16
|
+
*/
|
|
17
|
+
export declare class TxSpriteCoords {
|
|
18
|
+
/**
|
|
19
|
+
* Unsigned byte identifying the sprite code
|
|
20
|
+
*/
|
|
21
|
+
code: number;
|
|
22
|
+
/**
|
|
23
|
+
* X-coordinate for sprite position (1..640)
|
|
24
|
+
*/
|
|
25
|
+
x: number;
|
|
26
|
+
/**
|
|
27
|
+
* Y-coordinate for sprite position (1..400)
|
|
28
|
+
*/
|
|
29
|
+
y: number;
|
|
30
|
+
/**
|
|
31
|
+
* Palette offset value for the sprite (0..15)
|
|
32
|
+
*/
|
|
33
|
+
offset: number;
|
|
34
|
+
/**
|
|
35
|
+
* Constructs an instance of TxSpriteCoords.
|
|
36
|
+
* @param options Configuration options for the sprite coordinates.
|
|
37
|
+
*/
|
|
38
|
+
constructor(options: TxSpriteCoordsOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Packs the message into a binary format.
|
|
41
|
+
* @returns Uint8Array Binary representation of the message in the format:
|
|
42
|
+
* [code, x_msb, x_lsb, y_msb, y_lsb, offset]
|
|
43
|
+
* (6 bytes)
|
|
44
|
+
*/
|
|
45
|
+
pack(): Uint8Array;
|
|
46
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating a TxSprite instance.
|
|
3
|
+
*/
|
|
4
|
+
export interface TxSpriteOptions {
|
|
5
|
+
/** The width of the sprite in pixels. */
|
|
6
|
+
width: number;
|
|
7
|
+
/** The height of the sprite in pixels. */
|
|
8
|
+
height: number;
|
|
9
|
+
/** The number of colors in the sprite's palette. */
|
|
10
|
+
numColors: number;
|
|
11
|
+
/** The palette data as a flat Uint8Array of RGB values. */
|
|
12
|
+
paletteData: Uint8Array;
|
|
13
|
+
/** The pixel data as a Uint8Array of palette indices. */
|
|
14
|
+
pixelData: Uint8Array;
|
|
15
|
+
/** Optional flag whether to compress the pixel data using LZ4. Defaults to false. */
|
|
16
|
+
compress?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A sprite message containing image data with a custom palette.
|
|
20
|
+
*/
|
|
21
|
+
export declare class TxSprite {
|
|
22
|
+
/** The width of the sprite in pixels. */
|
|
23
|
+
width: number;
|
|
24
|
+
/** The height of the sprite in pixels. */
|
|
25
|
+
height: number;
|
|
26
|
+
/** The number of colors in the sprite's palette. */
|
|
27
|
+
numColors: number;
|
|
28
|
+
/** The palette data as a flat Uint8Array of RGB values. */
|
|
29
|
+
paletteData: Uint8Array;
|
|
30
|
+
/** The pixel data as a Uint8Array of palette indices. */
|
|
31
|
+
pixelData: Uint8Array;
|
|
32
|
+
/** Whether the pixel data is compressed using LZ4. */
|
|
33
|
+
compress: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Creates an instance of TxSprite.
|
|
36
|
+
* @param options Configuration options for the sprite.
|
|
37
|
+
*/
|
|
38
|
+
constructor(options: TxSpriteOptions);
|
|
39
|
+
/**
|
|
40
|
+
* Creates a TxSprite from an indexed PNG image.
|
|
41
|
+
* @param imageBytes The ArrayBuffer containing the PNG image data.
|
|
42
|
+
* @param compress Whether to compress the pixel data using LZ4.
|
|
43
|
+
* @returns A TxSprite instance.
|
|
44
|
+
*/
|
|
45
|
+
static fromIndexedPngBytes(imageBytes: ArrayBuffer, compress?: boolean): Promise<TxSprite>;
|
|
46
|
+
/**
|
|
47
|
+
* Creates a TxSprite from an image file, resizing and quantizing it to a maximum of 16 colors.
|
|
48
|
+
* @param imageBytes The ArrayBuffer containing the image data.
|
|
49
|
+
* @param maxPixels The maximum number of pixels allowed in the sprite.
|
|
50
|
+
* @param compress Whether to compress the pixel data using LZ4.
|
|
51
|
+
* @returns A TxSprite instance.
|
|
52
|
+
*/
|
|
53
|
+
static fromImageBytes(imageBytes: ArrayBuffer, maxPixels?: number, compress?: boolean): Promise<TxSprite>;
|
|
54
|
+
/**
|
|
55
|
+
* The number of bits per pixel, derived from the number of colors.
|
|
56
|
+
*/
|
|
57
|
+
get bpp(): number;
|
|
58
|
+
/**
|
|
59
|
+
* Packs the sprite data into a compact binary format.
|
|
60
|
+
* The format includes a header, palette data, and packed pixel data.
|
|
61
|
+
* Pixel data can be optionally compressed using LZ4.
|
|
62
|
+
* @returns A Uint8Array containing the packed sprite data.
|
|
63
|
+
*/
|
|
64
|
+
pack(): Uint8Array;
|
|
65
|
+
/**
|
|
66
|
+
* Packs pixel data into 1-bit per pixel format.
|
|
67
|
+
*/
|
|
68
|
+
private static _pack_1bit;
|
|
69
|
+
/**
|
|
70
|
+
* Packs pixel data into 2-bits per pixel format.
|
|
71
|
+
*/
|
|
72
|
+
private static _pack_2bit;
|
|
73
|
+
/**
|
|
74
|
+
* Packs pixel data into 4-bits per pixel format.
|
|
75
|
+
*/
|
|
76
|
+
private static _pack_4bit;
|
|
77
|
+
/**
|
|
78
|
+
* Converts the TxSprite to a PNG image as an ArrayBuffer.
|
|
79
|
+
* Intended for debugging and visualization purposes.
|
|
80
|
+
* @returns The PNG image data as an ArrayBuffer.
|
|
81
|
+
*/
|
|
82
|
+
toPngBytes(): ArrayBuffer;
|
|
83
|
+
/**
|
|
84
|
+
* Create a true-color PNG from an indexed palette and pixel data.
|
|
85
|
+
* @param width Image width in pixels
|
|
86
|
+
* @param height Image height in pixels
|
|
87
|
+
* @param paletteRGB Flat RGB Uint8Array of colors: [r0,g0,b0, r1,g1,b1, ..., rN,gN,bN]
|
|
88
|
+
* @param pixelIndices Uint8Array of palette indices (length = width * height)
|
|
89
|
+
* @returns PNG as ArrayBuffer
|
|
90
|
+
*/
|
|
91
|
+
private static _makeRGBAPngFromIndexed;
|
|
92
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { TxSprite } from './sprite';
|
|
2
|
+
/**
|
|
3
|
+
* Abstract interface for defining the geometry of a text layout area.
|
|
4
|
+
* This allows for different shapes like rectangles and circles.
|
|
5
|
+
*/
|
|
6
|
+
export interface TextLayout {
|
|
7
|
+
/** The width of the layout in pixels. */
|
|
8
|
+
width: number;
|
|
9
|
+
/** The height of the layout in pixels. */
|
|
10
|
+
height: number;
|
|
11
|
+
/** The font size in pixels. */
|
|
12
|
+
fontSize: number;
|
|
13
|
+
/** Optional font family name. */
|
|
14
|
+
fontFamily?: string;
|
|
15
|
+
/** Text alignment within each line. */
|
|
16
|
+
textAlign: CanvasTextAlign;
|
|
17
|
+
/** The starting Y coordinate for laying out text. */
|
|
18
|
+
readonly startY: number;
|
|
19
|
+
/**
|
|
20
|
+
* Gets the layout parameters (width and x-offset) for a line at a specific Y position.
|
|
21
|
+
* Returns null if the line is outside the displayable area.
|
|
22
|
+
*/
|
|
23
|
+
getLineLayout(lineY: number, lineHeight: number): {
|
|
24
|
+
width: number;
|
|
25
|
+
xOffset: number;
|
|
26
|
+
} | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A standard rectangular text layout.
|
|
30
|
+
*/
|
|
31
|
+
export declare class RectangularTextLayout implements TextLayout {
|
|
32
|
+
width: number;
|
|
33
|
+
height: number;
|
|
34
|
+
fontSize: number;
|
|
35
|
+
fontFamily?: string;
|
|
36
|
+
textAlign: CanvasTextAlign;
|
|
37
|
+
/**
|
|
38
|
+
* Constructs a RectangularTextLayout.
|
|
39
|
+
* @param options Configuration options.
|
|
40
|
+
*/
|
|
41
|
+
constructor(options: {
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
fontSize: number;
|
|
45
|
+
fontFamily?: string;
|
|
46
|
+
textAlign?: CanvasTextAlign;
|
|
47
|
+
});
|
|
48
|
+
/** The starting Y coordinate for text layout (always 0 for rectangular). */
|
|
49
|
+
get startY(): number;
|
|
50
|
+
/**
|
|
51
|
+
* Returns the full width at xOffset 0 if the line fits vertically, null otherwise.
|
|
52
|
+
*/
|
|
53
|
+
getLineLayout(lineY: number, lineHeight: number): {
|
|
54
|
+
width: number;
|
|
55
|
+
xOffset: number;
|
|
56
|
+
} | null;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A circular text layout, ideal for the Halo device.
|
|
60
|
+
* Text is constrained within a circle inscribed in the defined width/height.
|
|
61
|
+
*/
|
|
62
|
+
export declare class CircularTextLayout implements TextLayout {
|
|
63
|
+
width: number;
|
|
64
|
+
height: number;
|
|
65
|
+
fontSize: number;
|
|
66
|
+
fontFamily?: string;
|
|
67
|
+
textAlign: CanvasTextAlign;
|
|
68
|
+
circleMargin: number;
|
|
69
|
+
readonly radius: number;
|
|
70
|
+
readonly centerX: number;
|
|
71
|
+
readonly centerY: number;
|
|
72
|
+
/**
|
|
73
|
+
* Constructs a CircularTextLayout.
|
|
74
|
+
* @param options Configuration options.
|
|
75
|
+
*/
|
|
76
|
+
constructor(options: {
|
|
77
|
+
width: number;
|
|
78
|
+
height: number;
|
|
79
|
+
fontSize: number;
|
|
80
|
+
circleMargin?: number;
|
|
81
|
+
fontFamily?: string;
|
|
82
|
+
textAlign?: CanvasTextAlign;
|
|
83
|
+
});
|
|
84
|
+
/** The starting Y coordinate for text layout (top of the inscribed circle). */
|
|
85
|
+
get startY(): number;
|
|
86
|
+
/**
|
|
87
|
+
* Returns the chord width and x-offset for a line at the given Y position within the circle.
|
|
88
|
+
* Returns null if the line is outside the circle or too narrow to render text.
|
|
89
|
+
*/
|
|
90
|
+
getLineLayout(lineY: number, lineHeight: number): {
|
|
91
|
+
width: number;
|
|
92
|
+
xOffset: number;
|
|
93
|
+
} | null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Options for TxTextPage constructor.
|
|
97
|
+
*/
|
|
98
|
+
export interface TxTextPageOptions {
|
|
99
|
+
/** The layout to use for text rendering. */
|
|
100
|
+
layout: TextLayout;
|
|
101
|
+
/** The text to render. */
|
|
102
|
+
text: string;
|
|
103
|
+
}
|
|
104
|
+
/** Internal data class for a measured line of text. */
|
|
105
|
+
interface LineData {
|
|
106
|
+
text: string;
|
|
107
|
+
width: number;
|
|
108
|
+
xOffset: number;
|
|
109
|
+
yOffset: number;
|
|
110
|
+
lineHeight: number;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Represents a single, measured page of text that is ready to be rasterized into sprites.
|
|
114
|
+
*/
|
|
115
|
+
export declare class PageData {
|
|
116
|
+
private _lines;
|
|
117
|
+
private _layout;
|
|
118
|
+
private _sprites;
|
|
119
|
+
private _isRasterizing;
|
|
120
|
+
/** @internal */
|
|
121
|
+
constructor(lines: LineData[], layout: TextLayout);
|
|
122
|
+
/** Returns true if the page contains no lines. */
|
|
123
|
+
get isEmpty(): boolean;
|
|
124
|
+
/** Returns true if the page has been rasterized into sprites. */
|
|
125
|
+
get isRasterized(): boolean;
|
|
126
|
+
/** The rasterized sprites, one per line. Only valid after rasterize() has been called. */
|
|
127
|
+
get rasterizedSprites(): TxSprite[];
|
|
128
|
+
/** The text for each measured line. */
|
|
129
|
+
get lineTexts(): string[];
|
|
130
|
+
/**
|
|
131
|
+
* Rasterizes the measured lines into TxSprite objects (one per line) using
|
|
132
|
+
* 1-bit monochrome rendering via the Canvas 2D API.
|
|
133
|
+
*/
|
|
134
|
+
rasterize(): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Composes all rasterized sprites into a single layout.width × layout.height canvas
|
|
137
|
+
* and returns a PNG as a Uint8Array.
|
|
138
|
+
* Calls rasterize() first if not already done.
|
|
139
|
+
*/
|
|
140
|
+
toPngBytes(): Promise<Uint8Array>;
|
|
141
|
+
/**
|
|
142
|
+
* Packs the page layout data for transmission to the device.
|
|
143
|
+
* Must be called after rasterize().
|
|
144
|
+
* Format:
|
|
145
|
+
* 0xFF (1 byte)
|
|
146
|
+
* layout.width (2 bytes, big-endian)
|
|
147
|
+
* layout.height (2 bytes, big-endian)
|
|
148
|
+
* numSprites (1 byte)
|
|
149
|
+
* [xOffset_h, xOffset_l, yOffset_h, yOffset_l] * numSprites
|
|
150
|
+
*/
|
|
151
|
+
pack(): Uint8Array;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Manages the process of laying out and rasterizing text into pages.
|
|
155
|
+
* It works with any TextLayout to support different display shapes.
|
|
156
|
+
*/
|
|
157
|
+
export declare class TxTextPage {
|
|
158
|
+
/** The layout used for text rendering. */
|
|
159
|
+
readonly layout: TextLayout;
|
|
160
|
+
/** The full original text. */
|
|
161
|
+
readonly text: string;
|
|
162
|
+
private _remainingText;
|
|
163
|
+
/**
|
|
164
|
+
* Constructs an instance of TxTextPage.
|
|
165
|
+
* @param options Configuration options.
|
|
166
|
+
*/
|
|
167
|
+
constructor(options: TxTextPageOptions);
|
|
168
|
+
/** The portion of the text that has not yet been processed into a page. */
|
|
169
|
+
get remainingText(): string;
|
|
170
|
+
/** Returns true if there is more text to be laid out. */
|
|
171
|
+
get hasMoreText(): boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Measures the next page of text using the Canvas 2D API and returns a PageData
|
|
174
|
+
* without rasterizing any sprites.
|
|
175
|
+
* Returns null if there is no remaining text or if no text fits on the page.
|
|
176
|
+
*/
|
|
177
|
+
measureNextPage(): Promise<PageData | null>;
|
|
178
|
+
/**
|
|
179
|
+
* Measures and rasterizes the next page in one call.
|
|
180
|
+
* Returns null if there is no remaining text or nothing fit on the page.
|
|
181
|
+
*/
|
|
182
|
+
rasterizeNextPage(): Promise<PageData | null>;
|
|
183
|
+
}
|
|
184
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { TxSprite } from './sprite';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for TxTextSpriteBlock constructor options.
|
|
4
|
+
*/
|
|
5
|
+
export interface TxTextSpriteBlockOptions {
|
|
6
|
+
/** Width constraint for text layout */
|
|
7
|
+
width: number;
|
|
8
|
+
/** Font size in pixels */
|
|
9
|
+
fontSize: number;
|
|
10
|
+
/** Line height in pixels (fixed height for each sprite) */
|
|
11
|
+
lineHeight: number;
|
|
12
|
+
/** Maximum number of lines to display */
|
|
13
|
+
maxDisplayLines: number;
|
|
14
|
+
/** Optional font family name. Defaults to 'sans-serif'. */
|
|
15
|
+
fontFamily?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* A block of text rendered as sprites, for use in a browser environment.
|
|
19
|
+
*/
|
|
20
|
+
export declare class TxTextSpriteBlock {
|
|
21
|
+
/** The width constraint for the text layout, in pixels. */
|
|
22
|
+
width: number;
|
|
23
|
+
/** The font size used for rendering the text, in pixels. */
|
|
24
|
+
fontSize: number;
|
|
25
|
+
/** The fixed line height for each sprite, in pixels. */
|
|
26
|
+
lineHeight: number;
|
|
27
|
+
/** The maximum number of lines of text to be displayed. */
|
|
28
|
+
maxDisplayLines: number;
|
|
29
|
+
/** The font family used for rendering the text. */
|
|
30
|
+
fontFamily: string;
|
|
31
|
+
/**
|
|
32
|
+
* @param options Configuration options for the text sprite block.
|
|
33
|
+
*/
|
|
34
|
+
constructor(options: TxTextSpriteBlockOptions);
|
|
35
|
+
/**
|
|
36
|
+
* Creates sprites from the rendered text using the browser's Canvas API.
|
|
37
|
+
* Returns an array of TxSprite instances, one per line of text.
|
|
38
|
+
* Each sprite has exactly lineHeight pixels in height and width pixels in width,
|
|
39
|
+
* except blank lines which are 1×lineHeight.
|
|
40
|
+
* @param text The text to render. Lines are split on '\n'.
|
|
41
|
+
* @returns Array of TxSprite instances.
|
|
42
|
+
*/
|
|
43
|
+
createTextSprites(text: string): TxSprite[];
|
|
44
|
+
/**
|
|
45
|
+
* Packs the text block header into a 6-byte binary format.
|
|
46
|
+
* Format: 0xFF (1 byte) | width (uint16 BE) | lineHeight (uint16 BE) | maxDisplayLines (uint8)
|
|
47
|
+
* @returns Uint8Array Binary representation of the text block header.
|
|
48
|
+
*/
|
|
49
|
+
pack(): Uint8Array;
|
|
50
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "brilliant-msg",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/brilliant-msg.umd.js",
|
|
6
|
+
"module": "dist/brilliant-msg.es.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/brilliant-msg.es.js",
|
|
12
|
+
"require": "./dist/brilliant-msg.umd.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"dev": "vite",
|
|
22
|
+
"build": "vite build",
|
|
23
|
+
"build:example": "vite build --config example/vite.config.ts",
|
|
24
|
+
"preview": "vite preview",
|
|
25
|
+
"dev:demo": "vite --config example/vite.config.ts",
|
|
26
|
+
"docs:api": "typedoc --out example/dist/api src",
|
|
27
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [],
|
|
30
|
+
"author": "luke-brilliant",
|
|
31
|
+
"license": "BSD-3-Clause",
|
|
32
|
+
"description": "A high-level library for interacting with Brilliant Labs Frame by passing structured messages between a Frameside app and a hostside app",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^22.15.17",
|
|
35
|
+
"typedoc": "^0.28.5",
|
|
36
|
+
"typescript": "^5.8.3",
|
|
37
|
+
"vite": "^6.3.5",
|
|
38
|
+
"vite-plugin-dts": "^4.5.4"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@pdf-lib/upng": "^1.0.1",
|
|
42
|
+
"@types/lz4js": "^0.2.1",
|
|
43
|
+
"brilliant-ble": "^1.0.0",
|
|
44
|
+
"image-js": "^0.37.0",
|
|
45
|
+
"image-q": "^4.0.0",
|
|
46
|
+
"lz4js": "^0.2.0"
|
|
47
|
+
},
|
|
48
|
+
"optionalDependencies": {
|
|
49
|
+
"@rollup/rollup-linux-x64-gnu": "4.41.1"
|
|
50
|
+
},
|
|
51
|
+
"overrides": {
|
|
52
|
+
"vite": {
|
|
53
|
+
"rollup": "npm:@rollup/wasm-node"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|