textmode.js 0.3.2-beta.3 → 0.4.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.
@@ -1,34 +0,0 @@
1
- import type { GLFramebuffer } from '../../rendering';
2
- import type { FramebufferData } from '../svg/types';
3
- /**
4
- * Base class for data extraction from textmode framebuffers.
5
- * Provides common functionality shared between different export formats.
6
- */
7
- export declare abstract class DataExtractor {
8
- /**
9
- * Extracts pixel data from all framebuffers needed for export
10
- * @param framebuffer The conversion pipeline containing framebuffers
11
- * @returns Object containing all pixel data arrays
12
- */
13
- $extractFramebufferData(framebuffer: GLFramebuffer): FramebufferData;
14
- /**
15
- * Gets character index from character framebuffer pixels
16
- * @param characterPixels Character framebuffer pixel data
17
- * @param pixelIndex Index in the pixel array (already multiplied by 4 for RGBA)
18
- * @param charactersLength Total number of available characters
19
- * @returns Character index
20
- */
21
- protected _getCharacterIndex(characterPixels: Uint8Array, pixelIndex: number): number;
22
- /**
23
- * Converts raw pixel data to RGBA color object
24
- * @param pixels Pixel data array
25
- * @param index Pixel index (already multiplied by 4 for RGBA)
26
- * @returns RGBA color object with r, g, b, a properties
27
- */
28
- protected _pixelsToRGBA(pixels: Uint8Array, index: number): {
29
- r: number;
30
- g: number;
31
- b: number;
32
- a: number;
33
- };
34
- }
@@ -1,46 +0,0 @@
1
- /**
2
- * Base class for file handling operations.
3
- * Provides common functionality for downloading files in the browser.
4
- */
5
- export declare abstract class FileHandler {
6
- /**
7
- * Creates a downloadable blob from content
8
- * @param content The content to include in the blob
9
- * @param mimeType The MIME type for the blob
10
- * @returns Blob object containing the content
11
- */
12
- protected _createBlob(content: string, mimeType: string): Blob;
13
- /**
14
- * Downloads content as a file
15
- * @param content The content to download
16
- * @param filename The filename (with extension)
17
- * @param mimeType The MIME type for the content
18
- */
19
- protected _downloadFile(content: string, filename: string, mimeType: string): void;
20
- /**
21
- * Generates a timestamp string for filenames
22
- * @returns Formatted timestamp string
23
- */
24
- protected _generateTimestamp(): string;
25
- /**
26
- * Generates a date-time string for filenames (alternative format)
27
- * @returns Formatted date and time string
28
- */
29
- protected _generateDateTimeString(): {
30
- date: string;
31
- time: string;
32
- };
33
- /**
34
- * Validates and sanitizes filename for safety and compatibility
35
- * @param filename The filename to validate
36
- * @returns Sanitized filename
37
- */
38
- protected _sanitizeFilename(filename: string): string;
39
- /**
40
- * Generates a default filename with prefix and timestamp
41
- * @param prefix The prefix for the filename
42
- * @param extension The file extension (with dot)
43
- * @returns Generated filename
44
- */
45
- $generateDefaultFilename(): string;
46
- }
@@ -1,2 +0,0 @@
1
- export { DataExtractor } from './DataExtractor';
2
- export { FileHandler } from './FileHandler';
@@ -1 +0,0 @@
1
- export type { SVGExportOptions } from './svg';
@@ -1,76 +0,0 @@
1
- import type { SVGCellData, SVGGenerationOptions } from './types';
2
- import type { TextmodeFont, TextmodeGrid } from '../../index';
3
- /**
4
- * Generates SVG content and markup from processed cell data.
5
- * This class handles the creation of SVG elements, groups, and styling.
6
- */
7
- export declare class SVGContentGenerator {
8
- private _pathGenerator;
9
- constructor();
10
- /**
11
- * Generates the SVG header with metadata
12
- * @param gridInfo Grid dimensions
13
- * @returns SVG header string
14
- */
15
- $generateSVGHeader(gridInfo: TextmodeGrid): string;
16
- /**
17
- * Generates the SVG footer
18
- * @returns SVG footer string
19
- */
20
- $generateSVGFooter(): string;
21
- /**
22
- * Generates background rectangle if needed
23
- * @param gridInfo Grid information
24
- * @param options SVG generation options
25
- * @returns Background rectangle SVG string or empty string
26
- */
27
- $generateBackground(gridInfo: TextmodeGrid, options: SVGGenerationOptions): string;
28
- /**
29
- * Generates SVG transform attribute string
30
- * @param cellData Cell data with transform information
31
- * @param gridInfo Grid information for center calculations
32
- * @returns Transform attribute string or empty string
33
- */
34
- private _generateTransformAttribute;
35
- /**
36
- * Generates background rectangle for a cell
37
- * @param cellData Cell data
38
- * @param gridInfo Grid information
39
- * @param options SVG generation options
40
- * @returns Background rectangle SVG string or empty string
41
- */
42
- private _generateCellBackground;
43
- /**
44
- * Generates character path element for a cell
45
- * @param cellData Cell data
46
- * @param gridInfo Grid information
47
- * @param fontInfo Font information
48
- * @param options SVG generation options
49
- * @returns Character path SVG string
50
- */
51
- private _generateCharacterPath;
52
- /**
53
- * Generates complete SVG content for a single cell
54
- * @param cellData Cell data
55
- * @param gridInfo Grid information
56
- * @param fontInfo Font information
57
- * @param options SVG generation options
58
- * @returns Complete cell SVG content
59
- */
60
- $generateCellContent(cellData: SVGCellData, gridInfo: TextmodeGrid, fontInfo: TextmodeFont, options: SVGGenerationOptions): string;
61
- /**
62
- * Generates the complete SVG content from cell data
63
- * @param cellDataArray Array of cell data
64
- * @param grid Grid information
65
- * @param fontInfo Font information
66
- * @param options SVG generation options
67
- * @returns Complete SVG string
68
- */
69
- $generateSVGContent(cellDataArray: SVGCellData[], grid: TextmodeGrid, fontInfo: TextmodeFont, options: SVGGenerationOptions): string;
70
- /**
71
- * Optimizes SVG content by removing empty elements and unnecessary whitespace
72
- * @param svgContent Raw SVG content
73
- * @returns Optimized SVG content
74
- */
75
- $optimizeSVGContent(svgContent: string): string;
76
- }
@@ -1,33 +0,0 @@
1
- import type { FramebufferData, SVGCellData } from './types';
2
- import { DataExtractor } from '../base';
3
- import type { TextmodeGrid } from '../../index';
4
- /**
5
- * Extracts and processes data from framebuffers for SVG generation.
6
- * This class handles the conversion of raw pixel data into structured data objects.
7
- */
8
- export declare class SVGDataExtractor extends DataExtractor {
9
- /**
10
- * Extracts transform data from transform pixels
11
- * @param transformPixels Transform framebuffer pixels
12
- * @param rotationPixels Rotation framebuffer pixels
13
- * @param pixelIndex Pixel index in the array
14
- * @returns Transform data object
15
- */
16
- private _extractTransformData;
17
- /**
18
- * Calculates cell position information
19
- * @param x Grid X coordinate
20
- * @param y Grid Y coordinate
21
- * @param gridInfo Grid information
22
- * @returns Position data object
23
- */
24
- private _calculateCellPosition;
25
- /**
26
- * Processes all grid cells and extracts SVG cell data
27
- * @param framebufferData Raw pixel data from framebuffers
28
- * @param grid Grid information
29
- * @param font Font information
30
- * @returns Array of SVG cell data objects
31
- */
32
- $extractSVGCellData(framebufferData: FramebufferData, grid: TextmodeGrid): SVGCellData[];
33
- }
@@ -1,31 +0,0 @@
1
- import type { SVGExportOptions, TextmodeRenderingData } from './types';
2
- /**
3
- * Main SVG exporter for the textmode.js library.
4
- * Orchestrates the SVG export process by coordinating data extraction,
5
- * content generation, and file handling.
6
- */
7
- export declare class SVGExporter {
8
- private _dataExtractor;
9
- private _contentGenerator;
10
- private _fileHandler;
11
- constructor();
12
- /**
13
- * Applies default values to SVG export options
14
- * @param options User-provided options
15
- * @returns Complete options with defaults applied
16
- */
17
- private _applyDefaultOptions;
18
- /**
19
- * Generates SVG content from textmode rendering data without saving to file
20
- * @param renderingData The textmode rendering data containing pipeline, grid, and font
21
- * @param options Export options (excluding filename)
22
- * @returns SVG content as string
23
- */
24
- $generateSVG(renderingData: TextmodeRenderingData, options?: SVGExportOptions): string;
25
- /**
26
- * Exports SVG content to a downloadable file
27
- * @param renderingData The textmode rendering data containing pipeline, grid, and font
28
- * @param options Export options including filename
29
- */
30
- $saveSVG(renderingData: TextmodeRenderingData, options?: SVGExportOptions): void;
31
- }
@@ -1,25 +0,0 @@
1
- import { FileHandler } from '../base/FileHandler.js';
2
- /**
3
- * Handles SVG file operations including download and save functionality.
4
- * This class manages the creation of downloadable SVG files and blob handling.
5
- */
6
- export declare class SVGFileHandler extends FileHandler {
7
- /**
8
- * Creates a downloadable blob from SVG content
9
- * @param svgContent The SVG content string
10
- * @returns Blob object containing the SVG data
11
- */
12
- $createSVGBlob(svgContent: string): Blob;
13
- /**
14
- * Downloads SVG content as a file
15
- * @param svgContent The SVG content to download
16
- * @param filename The filename (without extension)
17
- */
18
- private _downloadSVG;
19
- /**
20
- * Saves SVG content with automatic filename generation if not provided
21
- * @param svgContent The SVG content to save
22
- * @param filename Optional filename (will generate if not provided)
23
- */
24
- $saveSVG(svgContent: string, filename?: string): void;
25
- }
@@ -1,49 +0,0 @@
1
- import type { TextmodeFont } from '../../textmode/font/TextmodeFont';
2
- /**
3
- * Handles SVG path generation for character glyphs.
4
- * This class is responsible for converting font glyph data into SVG path strings.
5
- */
6
- export declare class SVGPathGenerator {
7
- /**
8
- * Creates a path object for a glyph
9
- * @param fontData Font data object
10
- * @param glyphData Glyph data from font
11
- * @param x X position
12
- * @param y Y position
13
- * @param fontSize Font size
14
- * @returns Path object with bounding box and SVG methods
15
- */
16
- private _createGlyphPath;
17
- /**
18
- * Converts glyph data to SVG path string
19
- * @param glyphData Glyph data from font
20
- * @param x X position
21
- * @param y Y position
22
- * @param scale Scale factor
23
- * @returns SVG path data string
24
- */
25
- private _glyphToSVGPath;
26
- /**
27
- * Generates an SVG path for a character glyph
28
- * @param character The character to generate a path for
29
- * @param fontData The font data object
30
- * @param x X position
31
- * @param y Y position
32
- * @param fontSize Font size
33
- * @returns Path object with SVG generation methods
34
- */
35
- private _generateCharacterPath;
36
- /**
37
- * Generates SVG path data for a character with positioning calculations
38
- * @param character The character to render
39
- * @param fontData The font data
40
- * @param cellX Cell X position
41
- * @param cellY Cell Y position
42
- * @param cellWidth Cell width
43
- * @param cellHeight Cell height
44
- * @param fontSize Font size
45
- * @param advanceWidth Character advance width
46
- * @returns SVG path data string or null if generation fails
47
- */
48
- $generatePositionedCharacterPath(character: string, font: TextmodeFont, cellX: number, cellY: number, cellWidth: number, cellHeight: number, fontSize: number, advanceWidth: number): string | null;
49
- }
@@ -1,6 +0,0 @@
1
- export { SVGExporter } from './SVGExporter';
2
- export { SVGDataExtractor } from './SVGDataExtractor';
3
- export { SVGContentGenerator } from './SVGContentGenerator';
4
- export { SVGPathGenerator } from './SVGPathGenerator';
5
- export { SVGFileHandler } from './SVGFileHandler';
6
- export type { SVGExportOptions, SVGGenerationOptions, SVGCellData, FramebufferData, RGBA, Position, CellPosition, CellTransform, GlyphPath } from './types';
@@ -1,129 +0,0 @@
1
- /**
2
- * SVG-specific type definitions for the textmode.js library.
3
- */
4
- import type { TextmodeFont, TextmodeGrid } from '../..';
5
- /**
6
- * RGBA color representation.
7
- */
8
- export interface RGBA {
9
- r: number;
10
- g: number;
11
- b: number;
12
- a: number;
13
- }
14
- /**
15
- * 2D position coordinates.
16
- */
17
- export interface Position {
18
- x: number;
19
- y: number;
20
- }
21
- /**
22
- * Cell position in grid coordinates.
23
- */
24
- export interface CellPosition {
25
- x: number;
26
- y: number;
27
- cellX: number;
28
- cellY: number;
29
- }
30
- /**
31
- * Cell transformation data.
32
- */
33
- export interface CellTransform {
34
- isInverted: boolean;
35
- flipHorizontal: boolean;
36
- flipVertical: boolean;
37
- rotation: number;
38
- }
39
- /**
40
- * Complete data for a single SVG cell.
41
- */
42
- export interface SVGCellData {
43
- charIndex: number;
44
- primaryColor: RGBA;
45
- secondaryColor: RGBA;
46
- transform: CellTransform;
47
- position: CellPosition;
48
- }
49
- /**
50
- * Framebuffer data extracted for SVG generation.
51
- */
52
- export interface FramebufferData {
53
- characterPixels: Uint8Array;
54
- primaryColorPixels: Uint8Array;
55
- secondaryColorPixels: Uint8Array;
56
- transformPixels: Uint8Array;
57
- rotationPixels: Uint8Array;
58
- }
59
- /**
60
- * Options for exporting the textmode content to SVG format.
61
- */
62
- export type SVGExportOptions = {
63
- /**
64
- * The filename to save the SVG file as.
65
- *
66
- * If not provided, a default filename is used.
67
- */
68
- filename?: string;
69
- /**
70
- * Whether to include cell background rectangles in the SVG output.
71
- *
72
- * When `false`, only the character paths are included, creating a more compact SVG.
73
- *
74
- * Default is `true`.
75
- */
76
- includeBackgroundRectangles?: boolean;
77
- /**
78
- * The drawing mode for ASCII characters.
79
- *
80
- * When set to `'fill'`, characters are rendered as filled shapes.
81
- *
82
- * When set to `'stroke'`, characters are rendered as outlines.
83
- *
84
- * Default is `'fill'`.
85
- */
86
- drawMode?: 'fill' | 'stroke';
87
- /**
88
- * The stroke width to use when drawMode is set to `'stroke'`.
89
- *
90
- * Default is `1.0`.
91
- */
92
- strokeWidth?: number;
93
- /**
94
- * Background color for the SVG as RGBA array `[r, g, b, a]`.
95
- *
96
- * Default is transparent black `[0, 0, 0, 0]`.
97
- */
98
- backgroundColor?: [number, number, number, number];
99
- };
100
- /**
101
- * Path object interface for character glyphs.
102
- */
103
- export interface GlyphPath {
104
- getBoundingBox(): {
105
- x1: number;
106
- y1: number;
107
- x2: number;
108
- y2: number;
109
- };
110
- toSVG(): string;
111
- }
112
- /**
113
- * Internal options used by SVG generation (with all defaults applied).
114
- */
115
- export interface SVGGenerationOptions {
116
- includeBackgroundRectangles: boolean;
117
- drawMode: 'fill' | 'stroke';
118
- strokeWidth: number;
119
- backgroundColor: [number, number, number, number];
120
- filename: string;
121
- }
122
- /**
123
- * Data required for textmode rendering export (shared shape with TXT exporter)
124
- */
125
- export interface TextmodeRenderingData {
126
- pipeline: any;
127
- grid: TextmodeGrid;
128
- font: TextmodeFont;
129
- }