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.
Files changed (48) hide show
  1. package/CHANGELOG.md +23 -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/logo.svg +17 -0
  7. package/dist/manifest.webmanifest +17 -0
  8. package/dist/types/adapters/QQAdapter.d.ts +22 -0
  9. package/dist/types/adapters/ReactNativeAdapter.d.ts +111 -0
  10. package/dist/types/adapters/WebBluetoothAdapter.d.ts +87 -1
  11. package/dist/types/adapters/index.d.ts +13 -0
  12. package/dist/types/barcode/BarcodeGenerator.d.ts +61 -4
  13. package/dist/types/barcode/index.d.ts +1 -1
  14. package/dist/types/drivers/StarPrinter.d.ts +243 -0
  15. package/dist/types/drivers/index.d.ts +1 -0
  16. package/dist/types/encoding/EncodingService.d.ts +41 -2
  17. package/dist/types/encoding/index.d.ts +2 -1
  18. package/dist/types/encoding/korean-japanese.d.ts +127 -0
  19. package/dist/types/services/BatchPrintManager.d.ts +98 -5
  20. package/dist/types/services/PrintStatistics.d.ts +189 -0
  21. package/dist/types/services/ScheduledRetryManager.d.ts +213 -0
  22. package/dist/types/services/index.d.ts +2 -0
  23. package/dist/types/template/TemplateEngine.d.ts +140 -1
  24. package/dist/types/utils/image.d.ts +40 -119
  25. package/dist/types/utils/platform.d.ts +2 -0
  26. package/dist/types/utils/uuid.d.ts +191 -0
  27. package/package.json +1 -1
  28. package/src/adapters/AdapterFactory.ts +5 -0
  29. package/src/adapters/QQAdapter.ts +36 -0
  30. package/src/adapters/ReactNativeAdapter.ts +506 -0
  31. package/src/adapters/WebBluetoothAdapter.ts +275 -14
  32. package/src/adapters/index.ts +19 -0
  33. package/src/barcode/BarcodeGenerator.ts +312 -6
  34. package/src/barcode/index.ts +1 -1
  35. package/src/drivers/StarPrinter.ts +556 -0
  36. package/src/drivers/index.ts +10 -0
  37. package/src/encoding/EncodingService.ts +268 -4
  38. package/src/encoding/index.ts +17 -1
  39. package/src/encoding/korean-japanese.ts +325 -0
  40. package/src/services/BatchPrintManager.ts +291 -16
  41. package/src/services/PrintStatistics.ts +504 -0
  42. package/src/services/ScheduledRetryManager.ts +560 -0
  43. package/src/services/index.ts +16 -0
  44. package/src/template/TemplateEngine.ts +543 -4
  45. package/src/utils/image.ts +507 -324
  46. package/src/utils/platform.ts +10 -10
  47. package/src/utils/uuid.ts +522 -0
  48. package/src/utils/validation.ts +1155 -0
@@ -0,0 +1,191 @@
1
+ /**
2
+ * UUID Utility Module
3
+ *
4
+ * Provides UUID generation and parsing utilities for device identification,
5
+ * job tracking, and unique identifier generation.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { generateUUID, parseUUID, isValidUUID } from '@/utils/uuid';
10
+ *
11
+ * const id = generateUUID(); // v4 UUID
12
+ * const parsed = parseUUID(id);
13
+ * const valid = isValidUUID(id);
14
+ * ```
15
+ */
16
+ /**
17
+ * UUID version numbers
18
+ */
19
+ export declare enum UUIDVersion {
20
+ /** Version 1: Timestamp-based */
21
+ V1 = 1,
22
+ /** Version 4: Random */
23
+ V4 = 4,
24
+ /** Version 7: Unix Epoch time-based (recommended) */
25
+ V7 = 7
26
+ }
27
+ /**
28
+ * Parsed UUID structure
29
+ */
30
+ export interface ParsedUUID {
31
+ /** Raw UUID string */
32
+ raw: string;
33
+ /** UUID version */
34
+ version: UUIDVersion;
35
+ /** Variant bits */
36
+ variant: number;
37
+ /** Time component (for V1, V7) in milliseconds since epoch */
38
+ timestamp?: number;
39
+ /** Node identifier bytes (for V1) */
40
+ node?: string;
41
+ /** Random bytes (for V4) */
42
+ random?: string;
43
+ /** Whether the UUID is valid */
44
+ valid: boolean;
45
+ }
46
+ /**
47
+ * UUID format options
48
+ */
49
+ export interface UUIDOptions {
50
+ /** Uppercase hex output */
51
+ uppercase?: boolean;
52
+ /** Include hyphens (default: true) */
53
+ hyphenated?: boolean;
54
+ /** UUID version to generate (default: V4) */
55
+ version?: UUIDVersion;
56
+ }
57
+ /**
58
+ * UUID validation result
59
+ */
60
+ export interface UUIDValidationResult {
61
+ /** Whether the UUID is valid */
62
+ valid: boolean;
63
+ /** Version of the UUID if valid */
64
+ version?: UUIDVersion;
65
+ /** Error message if invalid */
66
+ error?: string;
67
+ }
68
+ /**
69
+ * UUID namespace for generating namespaced UUIDs (V5)
70
+ */
71
+ export interface UUIDNamespace {
72
+ /** Namespace UUID */
73
+ uuid: string;
74
+ /** Namespace name */
75
+ name: string;
76
+ }
77
+ /**
78
+ * Predefined namespaces for namespaced UUIDs (RFC 4122)
79
+ */
80
+ export declare const UUID_NAMESPACES: Record<string, UUIDNamespace>;
81
+ /**
82
+ * Generate a random UUID
83
+ *
84
+ * @param version - UUID version to generate (default: V4)
85
+ * @param options - Generation options
86
+ * @returns Generated UUID string
87
+ *
88
+ * @example
89
+ * ```typescript
90
+ * const uuid = generateUUID();
91
+ * const uuidV7 = generateUUID(UUIDVersion.V7, { uppercase: true });
92
+ * ```
93
+ */
94
+ export declare function generateUUID(version?: UUIDVersion, options?: UUIDOptions): string;
95
+ /**
96
+ * Parse a UUID string into its components
97
+ *
98
+ * @param uuid - UUID string to parse
99
+ * @returns Parsed UUID structure
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const parsed = parseUUID('550e8400-e29b-41d4-a716-446655440000');
104
+ * console.log(parsed.version); // 4
105
+ * console.log(parsed.valid); // true
106
+ * ```
107
+ */
108
+ export declare function parseUUID(uuid: string): ParsedUUID;
109
+ /**
110
+ * Validate a UUID string
111
+ *
112
+ * @param uuid - UUID string to validate
113
+ * @returns Validation result
114
+ *
115
+ * @example
116
+ * ```typescript
117
+ * const result = isValidUUID('550e8400-e29b-41d4-a716-446655440000');
118
+ * if (result.valid) {
119
+ * console.log(`Valid UUID v${result.version}`);
120
+ * }
121
+ * ```
122
+ */
123
+ export declare function isValidUUID(uuid: string): UUIDValidationResult;
124
+ /**
125
+ * Extract timestamp from a time-based UUID (v1 or v7)
126
+ *
127
+ * @param uuid - UUID string
128
+ * @returns Timestamp in milliseconds, or null if not a time-based UUID
129
+ *
130
+ * @example
131
+ * ```typescript
132
+ * const timestamp = getUUIDTimestamp('07c450b0-7d4a-11ed-a1eb-0242ac120002');
133
+ * console.log(new Date(timestamp ?? 0));
134
+ * ```
135
+ */
136
+ export declare function getUUIDTimestamp(uuid: string): number | null;
137
+ /**
138
+ * Compare two UUIDs chronologically (for time-based UUIDs)
139
+ *
140
+ * @param uuidA - First UUID
141
+ * @param uuidB - Second UUID
142
+ * @returns -1 if A < B, 0 if equal, 1 if A > B
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * const order = compareUUIDs(uuid1, uuid2);
147
+ * ```
148
+ */
149
+ export declare function compareUUIDs(uuidA: string, uuidB: string): number;
150
+ /**
151
+ * Convert UUID to bytes (Uint8Array)
152
+ *
153
+ * @param uuid - UUID string
154
+ * @returns UUID as 16-byte array
155
+ */
156
+ export declare function uuidToBytes(uuid: string): Uint8Array;
157
+ /**
158
+ * Convert bytes to UUID string
159
+ *
160
+ * @param bytes - 16-byte array
161
+ * @param hyphenated - Include hyphens (default: true)
162
+ * @returns UUID string
163
+ */
164
+ export declare function bytesToUUID(bytes: Uint8Array, hyphenated?: boolean): string;
165
+ /**
166
+ * Generate a short ID (8-12 character hex string)
167
+ * Useful for display purposes like job IDs
168
+ *
169
+ * @param length - Length of ID (default: 8)
170
+ * @returns Short hex ID
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * const shortId = generateShortId(8); // e.g., 'a3f2b1c9'
175
+ * ```
176
+ */
177
+ export declare function generateShortId(length?: number): string;
178
+ /**
179
+ * Generate a namespaced UUID (v5)
180
+ *
181
+ * @param namespace - Namespace UUID
182
+ * @param name - Name within namespace
183
+ * @param options - Generation options
184
+ * @returns Namespaced UUID
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const uuid = generateNamespacedUUID(UUID_NAMESPACES.NAMESPACE_DNS, 'example.com');
189
+ * ```
190
+ */
191
+ export declare function generateNamespacedUUID(namespace: string, name: string, options?: UUIDOptions): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taro-bluetooth-print",
3
- "version": "2.4.1",
3
+ "version": "2.6.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
+ }