taro-bluetooth-print 2.4.1 → 2.6.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/CHANGELOG.md +23 -0
- package/README.md +10 -2
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/logo.svg +17 -0
- package/dist/manifest.webmanifest +17 -0
- package/dist/types/adapters/QQAdapter.d.ts +22 -0
- package/dist/types/adapters/ReactNativeAdapter.d.ts +111 -0
- package/dist/types/adapters/WebBluetoothAdapter.d.ts +87 -1
- package/dist/types/adapters/index.d.ts +13 -0
- package/dist/types/barcode/BarcodeGenerator.d.ts +61 -4
- package/dist/types/barcode/index.d.ts +1 -1
- package/dist/types/drivers/StarPrinter.d.ts +243 -0
- package/dist/types/drivers/index.d.ts +1 -0
- package/dist/types/encoding/EncodingService.d.ts +41 -2
- package/dist/types/encoding/index.d.ts +2 -1
- package/dist/types/encoding/korean-japanese.d.ts +127 -0
- package/dist/types/services/BatchPrintManager.d.ts +98 -5
- package/dist/types/services/PrintStatistics.d.ts +189 -0
- package/dist/types/services/ScheduledRetryManager.d.ts +213 -0
- package/dist/types/services/index.d.ts +2 -0
- package/dist/types/template/TemplateEngine.d.ts +140 -1
- package/dist/types/utils/image.d.ts +40 -119
- package/dist/types/utils/platform.d.ts +2 -0
- package/dist/types/utils/uuid.d.ts +191 -0
- package/package.json +1 -1
- package/src/adapters/AdapterFactory.ts +5 -0
- package/src/adapters/QQAdapter.ts +36 -0
- package/src/adapters/ReactNativeAdapter.ts +506 -0
- package/src/adapters/WebBluetoothAdapter.ts +275 -14
- package/src/adapters/index.ts +19 -0
- package/src/barcode/BarcodeGenerator.ts +312 -6
- package/src/barcode/index.ts +1 -1
- package/src/drivers/StarPrinter.ts +556 -0
- package/src/drivers/index.ts +10 -0
- package/src/encoding/EncodingService.ts +268 -4
- package/src/encoding/index.ts +17 -1
- package/src/encoding/korean-japanese.ts +325 -0
- package/src/services/BatchPrintManager.ts +291 -16
- package/src/services/PrintStatistics.ts +504 -0
- package/src/services/ScheduledRetryManager.ts +560 -0
- package/src/services/index.ts +16 -0
- package/src/template/TemplateEngine.ts +543 -4
- package/src/utils/image.ts +507 -324
- package/src/utils/platform.ts +10 -10
- package/src/utils/uuid.ts +522 -0
- package/src/utils/validation.ts +1155 -0
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import { OfflineCache } from '../cache/OfflineCache';
|
|
2
|
+
import { PrintQueue } from '../queue/PrintQueue';
|
|
3
|
+
/**
|
|
4
|
+
* Scheduled retry entry
|
|
5
|
+
*/
|
|
6
|
+
export interface ScheduledRetry {
|
|
7
|
+
/** Job ID to retry */
|
|
8
|
+
jobId: string;
|
|
9
|
+
/** Scheduled execution time */
|
|
10
|
+
runAt: Date;
|
|
11
|
+
/** Current attempt count */
|
|
12
|
+
attemptCount: number;
|
|
13
|
+
/** Maximum retry attempts */
|
|
14
|
+
maxAttempts: number;
|
|
15
|
+
/** Base delay in ms for exponential backoff */
|
|
16
|
+
baseDelay: number;
|
|
17
|
+
/** Maximum delay in ms for exponential backoff */
|
|
18
|
+
maxDelay: number;
|
|
19
|
+
/** Last error message */
|
|
20
|
+
lastError?: string;
|
|
21
|
+
/** Scheduled timeout reference (internal, not serialized) */
|
|
22
|
+
timeout?: ReturnType<typeof setTimeout>;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Retry options
|
|
26
|
+
*/
|
|
27
|
+
export interface RetryOptions {
|
|
28
|
+
/** Base delay in ms (default: 1000) */
|
|
29
|
+
baseDelay?: number;
|
|
30
|
+
/** Maximum delay in ms (default: 60000) */
|
|
31
|
+
maxDelay?: number;
|
|
32
|
+
/** Maximum attempts (default: 5) */
|
|
33
|
+
maxAttempts?: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Scheduler events
|
|
37
|
+
*/
|
|
38
|
+
export interface ScheduledRetryEvents {
|
|
39
|
+
'retry-due': {
|
|
40
|
+
entry: ScheduledRetry;
|
|
41
|
+
};
|
|
42
|
+
'retry-executed': {
|
|
43
|
+
entry: ScheduledRetry;
|
|
44
|
+
success: boolean;
|
|
45
|
+
};
|
|
46
|
+
'retry-cancelled': {
|
|
47
|
+
jobId: string;
|
|
48
|
+
};
|
|
49
|
+
'retry-exhausted': {
|
|
50
|
+
jobId: string;
|
|
51
|
+
};
|
|
52
|
+
'schedule-restored': {
|
|
53
|
+
count: number;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Event handler type
|
|
58
|
+
*/
|
|
59
|
+
type EventHandler<T> = (data: T) => void;
|
|
60
|
+
/**
|
|
61
|
+
* Scheduled retry configuration
|
|
62
|
+
*/
|
|
63
|
+
export interface ScheduledRetryManagerConfig {
|
|
64
|
+
/** Default base delay in ms */
|
|
65
|
+
baseDelay: number;
|
|
66
|
+
/** Default max delay in ms */
|
|
67
|
+
maxDelay: number;
|
|
68
|
+
/** Default max attempts */
|
|
69
|
+
maxAttempts: number;
|
|
70
|
+
/** Persist scheduled retries to OfflineCache */
|
|
71
|
+
persistEnabled: boolean;
|
|
72
|
+
/** Restore pending retries on startup */
|
|
73
|
+
autoRestore: boolean;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Scheduled Retry Manager
|
|
77
|
+
*
|
|
78
|
+
* Manages time-based retries for failed print jobs with support for:
|
|
79
|
+
* - Scheduled execution at specific times
|
|
80
|
+
* - Exponential backoff between retries
|
|
81
|
+
* - Persistence across process restarts via OfflineCache
|
|
82
|
+
* - Event-driven callbacks for retry execution
|
|
83
|
+
*/
|
|
84
|
+
export declare class ScheduledRetryManager {
|
|
85
|
+
private readonly logger;
|
|
86
|
+
/** Scheduled retries map: jobId -> ScheduledRetry */
|
|
87
|
+
private readonly scheduledRetries;
|
|
88
|
+
/** Event listeners */
|
|
89
|
+
private readonly listeners;
|
|
90
|
+
/** Configuration */
|
|
91
|
+
private readonly config;
|
|
92
|
+
/** Offline cache instance for persistence */
|
|
93
|
+
private readonly offlineCache;
|
|
94
|
+
/** Print queue reference for requeueing jobs */
|
|
95
|
+
private printQueue;
|
|
96
|
+
/** Retry executor function */
|
|
97
|
+
private retryExecutor;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new ScheduledRetryManager instance
|
|
100
|
+
*
|
|
101
|
+
* @param config - Optional configuration overrides
|
|
102
|
+
* @param offlineCache - Optional OfflineCache instance (uses singleton if not provided)
|
|
103
|
+
*/
|
|
104
|
+
constructor(config?: Partial<ScheduledRetryManagerConfig>, offlineCache?: OfflineCache);
|
|
105
|
+
/**
|
|
106
|
+
* Set the print queue for job requeuing
|
|
107
|
+
*
|
|
108
|
+
* @param queue - PrintQueue instance
|
|
109
|
+
*/
|
|
110
|
+
setPrintQueue(queue: PrintQueue): void;
|
|
111
|
+
/**
|
|
112
|
+
* Set the retry executor function
|
|
113
|
+
*
|
|
114
|
+
* @param executor - Async function that executes the retry
|
|
115
|
+
*/
|
|
116
|
+
setRetryExecutor(executor: (jobId: string) => Promise<void>): void;
|
|
117
|
+
/**
|
|
118
|
+
* Schedule a retry for a specific job at a given time
|
|
119
|
+
*
|
|
120
|
+
* @param jobId - Job identifier to retry
|
|
121
|
+
* @param runAt - Date/time to execute the retry
|
|
122
|
+
* @param options - Optional retry configuration
|
|
123
|
+
*/
|
|
124
|
+
scheduleRetry(jobId: string, runAt: Date, options?: RetryOptions): void;
|
|
125
|
+
/**
|
|
126
|
+
* Schedule a retry with exponential backoff starting from now
|
|
127
|
+
*
|
|
128
|
+
* @param jobId - Job identifier to retry
|
|
129
|
+
* @param options - Retry options including baseDelay, maxDelay, maxAttempts
|
|
130
|
+
*/
|
|
131
|
+
scheduleRetryWithBackoff(jobId: string, options?: RetryOptions): void;
|
|
132
|
+
/**
|
|
133
|
+
* Cancel a scheduled retry
|
|
134
|
+
*
|
|
135
|
+
* @param jobId - Job identifier to cancel
|
|
136
|
+
* @returns true if a retry was cancelled, false if not found
|
|
137
|
+
*/
|
|
138
|
+
cancelRetry(jobId: string): boolean;
|
|
139
|
+
/**
|
|
140
|
+
* Get all scheduled retries
|
|
141
|
+
*
|
|
142
|
+
* @returns Array of scheduled retry entries (without timeout refs)
|
|
143
|
+
*/
|
|
144
|
+
getScheduledRetries(): Array<{
|
|
145
|
+
jobId: string;
|
|
146
|
+
runAt: Date;
|
|
147
|
+
}>;
|
|
148
|
+
/**
|
|
149
|
+
* Get a specific scheduled retry entry
|
|
150
|
+
*
|
|
151
|
+
* @param jobId - Job identifier
|
|
152
|
+
* @returns Scheduled retry entry or undefined
|
|
153
|
+
*/
|
|
154
|
+
getScheduledRetry(jobId: string): ScheduledRetry | undefined;
|
|
155
|
+
/**
|
|
156
|
+
* Check if a job has a scheduled retry
|
|
157
|
+
*
|
|
158
|
+
* @param jobId - Job identifier
|
|
159
|
+
* @returns true if retry is scheduled
|
|
160
|
+
*/
|
|
161
|
+
hasScheduledRetry(jobId: string): boolean;
|
|
162
|
+
/**
|
|
163
|
+
* Get count of scheduled retries
|
|
164
|
+
*
|
|
165
|
+
* @returns Number of pending scheduled retries
|
|
166
|
+
*/
|
|
167
|
+
get pendingCount(): number;
|
|
168
|
+
/**
|
|
169
|
+
* Register event listener
|
|
170
|
+
*
|
|
171
|
+
* @param event - Event name
|
|
172
|
+
* @param callback - Event handler
|
|
173
|
+
*/
|
|
174
|
+
on<K extends keyof ScheduledRetryEvents>(event: K, callback: EventHandler<ScheduledRetryEvents[K]>): void;
|
|
175
|
+
/**
|
|
176
|
+
* Remove event listener
|
|
177
|
+
*
|
|
178
|
+
* @param event - Event name
|
|
179
|
+
* @param callback - Event handler to remove
|
|
180
|
+
*/
|
|
181
|
+
off<K extends keyof ScheduledRetryEvents>(event: K, callback: EventHandler<ScheduledRetryEvents[K]>): void;
|
|
182
|
+
/**
|
|
183
|
+
* Clear all scheduled retries
|
|
184
|
+
*/
|
|
185
|
+
clearAll(): void;
|
|
186
|
+
/**
|
|
187
|
+
* Destroy the manager
|
|
188
|
+
*/
|
|
189
|
+
destroy(): void;
|
|
190
|
+
/**
|
|
191
|
+
* Execute a scheduled retry
|
|
192
|
+
*/
|
|
193
|
+
private executeRetry;
|
|
194
|
+
/**
|
|
195
|
+
* Persist a scheduled retry to OfflineCache
|
|
196
|
+
*/
|
|
197
|
+
private persistRetry;
|
|
198
|
+
/**
|
|
199
|
+
* Remove a persisted retry from OfflineCache
|
|
200
|
+
*/
|
|
201
|
+
private removePersistedRetry;
|
|
202
|
+
/**
|
|
203
|
+
* Restore scheduled retries from OfflineCache on startup
|
|
204
|
+
*/
|
|
205
|
+
private restoreScheduledRetries;
|
|
206
|
+
/**
|
|
207
|
+
* Emit an event
|
|
208
|
+
*/
|
|
209
|
+
private emit;
|
|
210
|
+
}
|
|
211
|
+
/** Singleton instance */
|
|
212
|
+
export declare const scheduledRetryManager: ScheduledRetryManager;
|
|
213
|
+
export {};
|
|
@@ -8,4 +8,6 @@ export { PrintJobManager } from './PrintJobManager';
|
|
|
8
8
|
export { PrintHistory, printHistory, type PrintHistoryEntry, type PrintHistoryStats, type HistoryQueryOptions, } from './PrintHistory';
|
|
9
9
|
export { PrinterStatus, printerStatus, type PrinterStatusInfo, type StatusQueryOptions, type PaperStatus, } from './PrinterStatus';
|
|
10
10
|
export { BatchPrintManager, batchPrintManager, type BatchJob, type BatchConfig, type BatchStats, type BatchEvents, } from './BatchPrintManager';
|
|
11
|
+
export { PrintStatistics, printStatistics, type PrintStatisticsData, type JobTrackingMeta, } from './PrintStatistics';
|
|
12
|
+
export { ScheduledRetryManager, scheduledRetryManager, type ScheduledRetry, type RetryOptions, type ScheduledRetryEvents, type ScheduledRetryManagerConfig, } from './ScheduledRetryManager';
|
|
11
13
|
export * from './interfaces';
|
|
@@ -69,6 +69,117 @@ export interface LabelData {
|
|
|
69
69
|
productionDate?: string;
|
|
70
70
|
expiryDate?: string;
|
|
71
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Loop element for iterating over arrays
|
|
74
|
+
*/
|
|
75
|
+
export interface LoopElement {
|
|
76
|
+
/** Element type identifier */
|
|
77
|
+
type: 'loop';
|
|
78
|
+
/** Variable name to iterate over (array) */
|
|
79
|
+
items: string;
|
|
80
|
+
/** Item variable name for each iteration */
|
|
81
|
+
itemVar: string;
|
|
82
|
+
/** Index variable name (optional) */
|
|
83
|
+
indexVar?: string;
|
|
84
|
+
/** Template elements to render for each item */
|
|
85
|
+
elements: TemplateElement[];
|
|
86
|
+
/** Separator between iterations (optional) */
|
|
87
|
+
separator?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Condition element for conditional rendering
|
|
91
|
+
*/
|
|
92
|
+
export interface ConditionElement {
|
|
93
|
+
/** Element type identifier */
|
|
94
|
+
type: 'condition';
|
|
95
|
+
/** Variable name to evaluate */
|
|
96
|
+
variable: string;
|
|
97
|
+
/** Operator for comparison */
|
|
98
|
+
operator: 'exists' | 'not_exists' | 'equals' | 'not_equals' | 'gt' | 'gte' | 'lt' | 'lte' | 'truthy' | 'falsy';
|
|
99
|
+
/** Value to compare against (for binary operators) */
|
|
100
|
+
value?: unknown;
|
|
101
|
+
/** Elements to render when condition is true */
|
|
102
|
+
then: TemplateElement[];
|
|
103
|
+
/** Elements to render when condition is false (optional) */
|
|
104
|
+
else?: TemplateElement[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Border style for box/table drawing
|
|
108
|
+
*/
|
|
109
|
+
export type BorderStyle = 'single' | 'double' | 'thick' | 'rounded' | 'dashed' | 'none';
|
|
110
|
+
/**
|
|
111
|
+
* Border element for drawing boxes/lines
|
|
112
|
+
*/
|
|
113
|
+
export interface BorderElement {
|
|
114
|
+
/** Element type identifier */
|
|
115
|
+
type: 'border';
|
|
116
|
+
/** Border style */
|
|
117
|
+
style?: BorderStyle;
|
|
118
|
+
/** Top-left corner character */
|
|
119
|
+
topLeft?: string;
|
|
120
|
+
/** Top-right corner character */
|
|
121
|
+
topRight?: string;
|
|
122
|
+
/** Bottom-left corner character */
|
|
123
|
+
bottomLeft?: string;
|
|
124
|
+
/** Bottom-right corner character */
|
|
125
|
+
bottomRight?: string;
|
|
126
|
+
/** Top border character */
|
|
127
|
+
top?: string;
|
|
128
|
+
/** Bottom border character */
|
|
129
|
+
bottom?: string;
|
|
130
|
+
/** Left border character */
|
|
131
|
+
left?: string;
|
|
132
|
+
/** Right border character */
|
|
133
|
+
right?: string;
|
|
134
|
+
/** Intersection character */
|
|
135
|
+
cross?: string;
|
|
136
|
+
/** Whether to draw top border */
|
|
137
|
+
drawTop?: boolean;
|
|
138
|
+
/** Whether to draw bottom border */
|
|
139
|
+
drawBottom?: boolean;
|
|
140
|
+
/** Whether to draw left border */
|
|
141
|
+
drawLeft?: boolean;
|
|
142
|
+
/** Whether to draw right border */
|
|
143
|
+
drawRight?: boolean;
|
|
144
|
+
/** Whether to fill inside with spaces */
|
|
145
|
+
filled?: boolean;
|
|
146
|
+
/** Inner padding (default: 0) */
|
|
147
|
+
padding?: number;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Table column definition
|
|
151
|
+
*/
|
|
152
|
+
export interface TableColumn {
|
|
153
|
+
/** Column header text */
|
|
154
|
+
header: string;
|
|
155
|
+
/** Width of column in characters */
|
|
156
|
+
width: number;
|
|
157
|
+
/** Text alignment for header */
|
|
158
|
+
headerAlign?: TextAlign;
|
|
159
|
+
/** Text alignment for cells */
|
|
160
|
+
cellAlign?: TextAlign;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Table row data
|
|
164
|
+
*/
|
|
165
|
+
export type TableRowData = Record<string, string | number>;
|
|
166
|
+
/**
|
|
167
|
+
* Table element for drawing table-like structures
|
|
168
|
+
*/
|
|
169
|
+
export interface TableElement {
|
|
170
|
+
/** Element type identifier */
|
|
171
|
+
type: 'table';
|
|
172
|
+
/** Table columns definition */
|
|
173
|
+
columns: TableColumn[];
|
|
174
|
+
/** Variable name of array to render as rows */
|
|
175
|
+
rowsVar: string;
|
|
176
|
+
/** Whether to draw header row */
|
|
177
|
+
showHeader?: boolean;
|
|
178
|
+
/** Border style for table */
|
|
179
|
+
borderStyle?: BorderStyle;
|
|
180
|
+
/** Whether to alternate row shading */
|
|
181
|
+
alternateRows?: boolean;
|
|
182
|
+
}
|
|
72
183
|
/**
|
|
73
184
|
* Template element types
|
|
74
185
|
*/
|
|
@@ -103,7 +214,7 @@ export type TemplateElement = {
|
|
|
103
214
|
type: 'variable';
|
|
104
215
|
name: string;
|
|
105
216
|
format?: string;
|
|
106
|
-
};
|
|
217
|
+
} | LoopElement | ConditionElement | BorderElement | TableElement;
|
|
107
218
|
/**
|
|
108
219
|
* Template definition
|
|
109
220
|
*/
|
|
@@ -177,6 +288,34 @@ export declare class TemplateEngine implements ITemplateEngine {
|
|
|
177
288
|
* Render a single template element
|
|
178
289
|
*/
|
|
179
290
|
private renderElement;
|
|
291
|
+
/**
|
|
292
|
+
* Render a loop element
|
|
293
|
+
*/
|
|
294
|
+
private renderLoop;
|
|
295
|
+
/**
|
|
296
|
+
* Render a condition element
|
|
297
|
+
*/
|
|
298
|
+
private renderCondition;
|
|
299
|
+
/**
|
|
300
|
+
* Evaluate a condition
|
|
301
|
+
*/
|
|
302
|
+
private evaluateCondition;
|
|
303
|
+
/**
|
|
304
|
+
* Render a border element
|
|
305
|
+
*/
|
|
306
|
+
private renderBorder;
|
|
307
|
+
/**
|
|
308
|
+
* Render a table element
|
|
309
|
+
*/
|
|
310
|
+
private renderTable;
|
|
311
|
+
/**
|
|
312
|
+
* Align text within a specified width
|
|
313
|
+
*/
|
|
314
|
+
private alignText;
|
|
315
|
+
/**
|
|
316
|
+
* Render standard elements (text, line, image, qrcode, barcode, feed, variable)
|
|
317
|
+
*/
|
|
318
|
+
private renderStandardElement;
|
|
180
319
|
/**
|
|
181
320
|
* Render a separator line
|
|
182
321
|
*/
|
|
@@ -2,155 +2,76 @@
|
|
|
2
2
|
* Image Processing Utilities
|
|
3
3
|
*
|
|
4
4
|
* Provides methods for converting images to printer-compatible formats.
|
|
5
|
-
*
|
|
5
|
+
* Supports multiple dithering algorithms and image preprocessing.
|
|
6
6
|
*/
|
|
7
7
|
export declare class ImageProcessing {
|
|
8
|
+
private static readonly BAYER_MATRIX_2;
|
|
9
|
+
private static readonly BAYER_MATRIX_4;
|
|
10
|
+
private static readonly BAYER_MATRIX_8;
|
|
11
|
+
private static readonly QUALITY_PRESETS;
|
|
8
12
|
/**
|
|
9
13
|
* Convert RGBA data to monochrome bitmap (1 bit per pixel)
|
|
10
14
|
* suitable for ESC/POS GS v 0 command.
|
|
11
|
-
* Uses Floyd-Steinberg dithering for better quality by default.
|
|
12
|
-
*
|
|
13
|
-
* @param data - RGBA pixel data as Uint8Array
|
|
14
|
-
* @param width - Image width in pixels
|
|
15
|
-
* @param height - Image height in pixels
|
|
16
|
-
* @param options - Additional options for image processing
|
|
17
|
-
* @returns Monochrome bitmap data as Uint8Array
|
|
18
15
|
*
|
|
19
16
|
* @example
|
|
20
17
|
* ```typescript
|
|
21
|
-
* const
|
|
22
|
-
* const bitmap = ImageProcessing.toBitmap(imageData, width, height, {
|
|
18
|
+
* const bitmap = ImageProcessing.toBitmap(rgbaData, width, height, {
|
|
23
19
|
* targetWidth: 384,
|
|
24
|
-
* ditheringAlgorithm: '
|
|
20
|
+
* ditheringAlgorithm: 'ordered',
|
|
25
21
|
* contrast: 1.2,
|
|
26
22
|
* brightness: 0.1
|
|
27
23
|
* });
|
|
28
24
|
* ```
|
|
29
25
|
*/
|
|
30
26
|
static toBitmap(data: Uint8Array, width: number, height: number, options?: {
|
|
31
|
-
/** Target width for scaling (optional) */
|
|
32
27
|
targetWidth?: number;
|
|
33
|
-
/** Target height for scaling (optional) */
|
|
34
28
|
targetHeight?: number;
|
|
35
|
-
/** Whether to use dithering (default: true) */
|
|
36
29
|
useDithering?: boolean;
|
|
37
|
-
/**
|
|
38
|
-
ditheringAlgorithm?: 'floyd-steinberg' | 'atkinson';
|
|
39
|
-
/** Scaling algorithm to use: 'nearest' for nearest neighbor, 'bilinear' for bilinear interpolation (default: 'nearest') */
|
|
30
|
+
/** 'floyd-steinberg' | 'atkinson' | 'ordered' | 'halftone' | 'sierra' | 'stucki' (default: 'floyd-steinberg') */
|
|
31
|
+
ditheringAlgorithm?: 'floyd-steinberg' | 'atkinson' | 'ordered' | 'halftone' | 'sierra' | 'stucki';
|
|
40
32
|
scalingAlgorithm?: 'nearest' | 'bilinear';
|
|
41
|
-
/** Contrast adjustment factor (1.0 = no adjustment) */
|
|
42
33
|
contrast?: number;
|
|
43
|
-
/** Brightness adjustment factor (0.0 = no adjustment, negative = darker, positive = brighter) */
|
|
44
34
|
brightness?: number;
|
|
45
|
-
/** Threshold value for binarization (0-255, default: 128) */
|
|
46
35
|
threshold?: number;
|
|
36
|
+
orderedMatrixSize?: 2 | 4 | 8;
|
|
37
|
+
halftoneDotType?: 'round' | 'diamond' | 'square';
|
|
38
|
+
qualityPreset?: 'draft' | 'normal' | 'high';
|
|
47
39
|
}): Uint8Array;
|
|
48
40
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
41
|
+
* Image preprocessing pipeline
|
|
42
|
+
* @example
|
|
43
|
+
* ```typescript
|
|
44
|
+
* const processed = ImageProcessing.preprocessImage(data, w, h, {
|
|
45
|
+
* denoise: true,
|
|
46
|
+
* sharpen: true,
|
|
47
|
+
* gamma: 1.2,
|
|
48
|
+
* posterize: 4
|
|
49
|
+
* });
|
|
50
|
+
* ```
|
|
55
51
|
*/
|
|
52
|
+
static preprocessImage(data: Uint8Array, width: number, height: number, options?: {
|
|
53
|
+
denoise?: boolean;
|
|
54
|
+
sharpen?: boolean;
|
|
55
|
+
gamma?: number;
|
|
56
|
+
posterize?: number;
|
|
57
|
+
}): Uint8Array;
|
|
56
58
|
private static toGrayscale;
|
|
57
|
-
/**
|
|
58
|
-
* Adjust contrast and brightness of grayscale image
|
|
59
|
-
*
|
|
60
|
-
* @param grayscale - Grayscale image data
|
|
61
|
-
* @param contrast - Contrast adjustment factor (1.0 = no adjustment)
|
|
62
|
-
* @param brightness - Brightness adjustment factor (0.0 = no adjustment)
|
|
63
|
-
* @returns Adjusted grayscale image data
|
|
64
|
-
*/
|
|
65
59
|
private static adjustContrastBrightness;
|
|
66
|
-
/**
|
|
67
|
-
* Apply dithering to grayscale image using specified algorithm
|
|
68
|
-
*
|
|
69
|
-
* @param grayscale - Grayscale image data
|
|
70
|
-
* @param width - Image width
|
|
71
|
-
* @param height - Image height
|
|
72
|
-
* @param bitmap - Output bitmap buffer
|
|
73
|
-
* @param bytesPerLine - Number of bytes per line in the bitmap
|
|
74
|
-
* @param algorithm - Dithering algorithm to use
|
|
75
|
-
* @param threshold - Threshold value for binarization
|
|
76
|
-
*/
|
|
77
60
|
private static applyDithering;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* @param bytesPerLine - Number of bytes per line in the bitmap
|
|
86
|
-
* @param threshold - Threshold value for binarization (0-255)
|
|
87
|
-
*/
|
|
61
|
+
private static applyFloydSteinbergDithering;
|
|
62
|
+
private static applyAtkinsonDithering;
|
|
63
|
+
private static applyOrderedDithering;
|
|
64
|
+
private static applyHalftone;
|
|
65
|
+
private static computeHalftoneThresholds;
|
|
66
|
+
private static applySierraDithering;
|
|
67
|
+
private static applyStuckiDithering;
|
|
88
68
|
private static applyThreshold;
|
|
89
|
-
|
|
90
|
-
* Scale an image to new dimensions
|
|
91
|
-
*
|
|
92
|
-
* @param data - RGBA pixel data as Uint8Array
|
|
93
|
-
* @param width - Original image width in pixels
|
|
94
|
-
* @param height - Original image height in pixels
|
|
95
|
-
* @param targetWidth - Target width in pixels
|
|
96
|
-
* @param targetHeight - Target height in pixels
|
|
97
|
-
* @param options - Additional scaling options
|
|
98
|
-
* @returns Scaled image data and dimensions
|
|
99
|
-
*/
|
|
69
|
+
private static distributeErr;
|
|
100
70
|
private static scaleImage;
|
|
101
|
-
/**
|
|
102
|
-
* Apply nearest neighbor scaling to an image
|
|
103
|
-
*
|
|
104
|
-
* @param srcData - Source RGBA pixel data
|
|
105
|
-
* @param srcWidth - Source image width
|
|
106
|
-
* @param srcHeight - Source image height
|
|
107
|
-
* @param destData - Destination RGBA pixel data
|
|
108
|
-
* @param destWidth - Destination image width
|
|
109
|
-
* @param destHeight - Destination image height
|
|
110
|
-
*/
|
|
111
71
|
private static applyNearestNeighbor;
|
|
112
|
-
/**
|
|
113
|
-
* Apply bilinear interpolation scaling to an image
|
|
114
|
-
*
|
|
115
|
-
* @param srcData - Source RGBA pixel data
|
|
116
|
-
* @param srcWidth - Source image width
|
|
117
|
-
* @param srcHeight - Source image height
|
|
118
|
-
* @param destData - Destination RGBA pixel data
|
|
119
|
-
* @param destWidth - Destination image width
|
|
120
|
-
* @param destHeight - Destination image height
|
|
121
|
-
*/
|
|
122
72
|
private static applyBilinearInterpolation;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
* @param width - Image width
|
|
128
|
-
* @param height - Image height
|
|
129
|
-
* @param x - Current x position
|
|
130
|
-
* @param y - Current y position
|
|
131
|
-
* @param error - Quantization error to distribute
|
|
132
|
-
*/
|
|
133
|
-
private static distributeErrorFloydSteinberg;
|
|
134
|
-
/**
|
|
135
|
-
* Distribute quantization error to neighboring pixels using Atkinson algorithm
|
|
136
|
-
*
|
|
137
|
-
* @param grayscale - Grayscale image data
|
|
138
|
-
* @param width - Image width
|
|
139
|
-
* @param height - Image height
|
|
140
|
-
* @param x - Current x position
|
|
141
|
-
* @param y - Current y position
|
|
142
|
-
* @param error - Quantization error to distribute
|
|
143
|
-
*/
|
|
144
|
-
private static distributeErrorAtkinson;
|
|
145
|
-
/**
|
|
146
|
-
* Distribute error to a single pixel with bounds checking
|
|
147
|
-
*
|
|
148
|
-
* @param grayscale - Grayscale image data
|
|
149
|
-
* @param width - Image width
|
|
150
|
-
* @param height - Image height
|
|
151
|
-
* @param nx - New x position
|
|
152
|
-
* @param ny - New y position
|
|
153
|
-
* @param error - Error value to distribute
|
|
154
|
-
*/
|
|
155
|
-
private static distributeErrorPixel;
|
|
73
|
+
private static applyGammaCorrection;
|
|
74
|
+
private static applyMedianFilter;
|
|
75
|
+
private static applyUnsharpMask;
|
|
76
|
+
private static applyPosterization;
|
|
156
77
|
}
|