taro-bluetooth-print 2.4.0 → 2.5.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.
Files changed (43) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/README.md +10 -2
  3. package/dist/index.cjs.js +1 -1
  4. package/dist/index.es.js +1 -1
  5. package/dist/index.umd.js +1 -1
  6. package/dist/types/adapters/QQAdapter.d.ts +22 -0
  7. package/dist/types/adapters/ReactNativeAdapter.d.ts +111 -0
  8. package/dist/types/adapters/index.d.ts +13 -0
  9. package/dist/types/device/MultiPrinterManager.d.ts +1 -1
  10. package/dist/types/drivers/StarPrinter.d.ts +243 -0
  11. package/dist/types/drivers/index.d.ts +1 -0
  12. package/dist/types/encoding/EncodingService.d.ts +41 -2
  13. package/dist/types/encoding/index.d.ts +2 -1
  14. package/dist/types/encoding/korean-japanese.d.ts +127 -0
  15. package/dist/types/index.d.ts +1 -1
  16. package/dist/types/services/BatchPrintManager.d.ts +98 -5
  17. package/dist/types/services/PrintStatistics.d.ts +189 -0
  18. package/dist/types/services/ScheduledRetryManager.d.ts +213 -0
  19. package/dist/types/services/index.d.ts +5 -3
  20. package/dist/types/utils/image.d.ts +40 -119
  21. package/dist/types/utils/platform.d.ts +2 -0
  22. package/package.json +1 -1
  23. package/src/adapters/AdapterFactory.ts +5 -0
  24. package/src/adapters/QQAdapter.ts +36 -0
  25. package/src/adapters/ReactNativeAdapter.ts +517 -0
  26. package/src/adapters/index.ts +14 -0
  27. package/src/config/PrinterConfigManager.ts +10 -6
  28. package/src/device/MultiPrinterManager.ts +10 -10
  29. package/src/drivers/StarPrinter.ts +555 -0
  30. package/src/drivers/index.ts +10 -0
  31. package/src/encoding/EncodingService.ts +261 -4
  32. package/src/encoding/index.ts +17 -1
  33. package/src/encoding/korean-japanese.ts +289 -0
  34. package/src/index.ts +1 -5
  35. package/src/services/BatchPrintManager.ts +312 -42
  36. package/src/services/PrintHistory.ts +13 -11
  37. package/src/services/PrintJobManager.ts +3 -3
  38. package/src/services/PrintStatistics.ts +504 -0
  39. package/src/services/PrinterStatus.ts +4 -10
  40. package/src/services/ScheduledRetryManager.ts +564 -0
  41. package/src/services/index.ts +38 -3
  42. package/src/utils/image.ts +476 -342
  43. package/src/utils/platform.ts +20 -34
@@ -2,155 +2,76 @@
2
2
  * Image Processing Utilities
3
3
  *
4
4
  * Provides methods for converting images to printer-compatible formats.
5
- * Currently supports converting RGBA images to monochrome bitmaps using various dithering algorithms.
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 imageData = new Uint8Array(width * height * 4); // RGBA
22
- * const bitmap = ImageProcessing.toBitmap(imageData, width, height, {
18
+ * const bitmap = ImageProcessing.toBitmap(rgbaData, width, height, {
23
19
  * targetWidth: 384,
24
- * ditheringAlgorithm: 'atkinson',
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
- /** Dithering algorithm to use: 'floyd-steinberg' | 'atkinson' (default: 'floyd-steinberg') */
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
- * Convert RGBA data to grayscale using optimized formula
50
- *
51
- * @param data - RGBA pixel data as Uint8Array
52
- * @param width - Image width in pixels
53
- * @param height - Image height in pixels
54
- * @returns Grayscale image data as Float32Array
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
- * Apply simple thresholding to grayscale image with adjustable threshold
80
- *
81
- * @param grayscale - Grayscale image data
82
- * @param width - Image width
83
- * @param height - Image height
84
- * @param bitmap - Output bitmap buffer
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
- * Distribute quantization error to neighboring pixels using Floyd-Steinberg algorithm
125
- *
126
- * @param grayscale - Grayscale image data
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
  }
@@ -15,6 +15,8 @@ export declare enum PlatformType {
15
15
  BAIDU = "baidu",
16
16
  /** ByteDance Mini Program (Douyin, Toutiao) */
17
17
  BYTEDANCE = "bytedance",
18
+ /** QQ Mini Program */
19
+ QQ = "qq",
18
20
  /** Web platform */
19
21
  WEB = "web",
20
22
  /** Unknown platform */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taro-bluetooth-print",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Taro 蓝牙打印库 v2.4 - 轻量级、高性能、跨平台支持微信、支付宝、百度、字节跳动小程序及H5 Web Bluetooth",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
@@ -9,6 +9,7 @@ import { TaroAdapter } from './TaroAdapter';
9
9
  import { AlipayAdapter } from './AlipayAdapter';
10
10
  import { BaiduAdapter } from './BaiduAdapter';
11
11
  import { ByteDanceAdapter } from './ByteDanceAdapter';
12
+ import { QQAdapter } from './QQAdapter';
12
13
  import { WebBluetoothAdapter } from './WebBluetoothAdapter';
13
14
  import { PlatformType, detectPlatform } from '@/utils/platform';
14
15
  import { BluetoothPrintError, ErrorCode } from '@/errors/BluetoothError';
@@ -35,6 +36,8 @@ export class AdapterFactory {
35
36
  return new BaiduAdapter();
36
37
  case PlatformType.BYTEDANCE:
37
38
  return new ByteDanceAdapter();
39
+ case PlatformType.QQ:
40
+ return new QQAdapter();
38
41
  case PlatformType.WEB:
39
42
  if (WebBluetoothAdapter.isSupported()) {
40
43
  return new WebBluetoothAdapter();
@@ -68,6 +71,8 @@ export class AdapterFactory {
68
71
  return new BaiduAdapter();
69
72
  case PlatformType.BYTEDANCE:
70
73
  return new ByteDanceAdapter();
74
+ case PlatformType.QQ:
75
+ return new QQAdapter();
71
76
  case PlatformType.WEB:
72
77
  if (WebBluetoothAdapter.isSupported()) {
73
78
  return new WebBluetoothAdapter();
@@ -0,0 +1,36 @@
1
+ /**
2
+ * QQ Mini Program Bluetooth Adapter
3
+ * Implements the IPrinterAdapter interface for QQ Mini Program
4
+ */
5
+
6
+ import { MiniProgramAdapter, MiniProgramBLEApi } from './BaseAdapter';
7
+
8
+ // Declare QQ global for TypeScript
9
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type
10
+ interface QQGlobal extends MiniProgramBLEApi {}
11
+
12
+ declare const qq: QQGlobal;
13
+
14
+ /**
15
+ * QQ Mini Program Bluetooth Low Energy adapter
16
+ *
17
+ * Uses the QQ mini-program's BLE APIs (qq.xxx).
18
+ * All connection, write, and service discovery logic is inherited from MiniProgramAdapter.
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const adapter = new QQAdapter();
23
+ * await adapter.connect('device-id-123');
24
+ * await adapter.write('device-id-123', buffer);
25
+ * await adapter.disconnect('device-id-123');
26
+ * ```
27
+ */
28
+ export class QQAdapter extends MiniProgramAdapter {
29
+ /**
30
+ * Returns the QQ mini-program BLE API object
31
+ * @returns The qq global object providing BLE capabilities
32
+ */
33
+ protected getApi(): MiniProgramBLEApi {
34
+ return qq;
35
+ }
36
+ }