taro-bluetooth-print 2.5.0 → 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.
@@ -26,7 +26,7 @@ export class ImageProcessing {
26
26
  for (let i = 0; i < 8; i++) {
27
27
  m8[i] = [];
28
28
  for (let j = 0; j < 8; j++) {
29
- const v = (m4[i >> 1]?.[j >> 1] ?? 0) + ((i % 2) * 32) + ((j % 2) * 64);
29
+ const v = (m4[i >> 1]?.[j >> 1] ?? 0) + (i % 2) * 32 + (j % 2) * 64;
30
30
  m8[i]![j] = v;
31
31
  }
32
32
  }
@@ -63,7 +63,13 @@ export class ImageProcessing {
63
63
  targetHeight?: number;
64
64
  useDithering?: boolean;
65
65
  /** 'floyd-steinberg' | 'atkinson' | 'ordered' | 'halftone' | 'sierra' | 'stucki' (default: 'floyd-steinberg') */
66
- ditheringAlgorithm?: 'floyd-steinberg' | 'atkinson' | 'ordered' | 'halftone' | 'sierra' | 'stucki';
66
+ ditheringAlgorithm?:
67
+ | 'floyd-steinberg'
68
+ | 'atkinson'
69
+ | 'ordered'
70
+ | 'halftone'
71
+ | 'sierra'
72
+ | 'stucki';
67
73
  scalingAlgorithm?: 'nearest' | 'bilinear';
68
74
  contrast?: number;
69
75
  brightness?: number;
@@ -78,7 +84,9 @@ export class ImageProcessing {
78
84
  }
79
85
 
80
86
  if (data.length !== width * height * 4) {
81
- throw new Error(`Invalid image data length: expected ${width * height * 4}, got ${data.length}`);
87
+ throw new Error(
88
+ `Invalid image data length: expected ${width * height * 4}, got ${data.length}`
89
+ );
82
90
  }
83
91
 
84
92
  let opts = options || {};
@@ -105,7 +113,14 @@ export class ImageProcessing {
105
113
  let processedHeight = height;
106
114
 
107
115
  if (targetWidth || targetHeight) {
108
- const scaled = this.scaleImage(data, width, height, targetWidth || width, targetHeight || height, { algorithm: scalingAlgorithm });
116
+ const scaled = this.scaleImage(
117
+ data,
118
+ width,
119
+ height,
120
+ targetWidth || width,
121
+ targetHeight || height,
122
+ { algorithm: scalingAlgorithm }
123
+ );
109
124
  processedData = scaled.newData;
110
125
  processedWidth = scaled.newWidth;
111
126
  processedHeight = scaled.newHeight;
@@ -125,7 +140,14 @@ export class ImageProcessing {
125
140
  halftoneDotType,
126
141
  });
127
142
  } else {
128
- this.applyThreshold(grayscale, processedWidth, processedHeight, bitmap, bytesPerLine, threshold);
143
+ this.applyThreshold(
144
+ grayscale,
145
+ processedWidth,
146
+ processedHeight,
147
+ bitmap,
148
+ bytesPerLine,
149
+ threshold
150
+ );
129
151
  }
130
152
 
131
153
  return bitmap;
@@ -214,10 +236,26 @@ export class ImageProcessing {
214
236
  ): void {
215
237
  switch (opts.algorithm) {
216
238
  case 'ordered':
217
- this.applyOrderedDithering(grayscale, width, height, bitmap, bytesPerLine, opts.threshold, opts.orderedMatrixSize);
239
+ this.applyOrderedDithering(
240
+ grayscale,
241
+ width,
242
+ height,
243
+ bitmap,
244
+ bytesPerLine,
245
+ opts.threshold,
246
+ opts.orderedMatrixSize
247
+ );
218
248
  break;
219
249
  case 'halftone':
220
- this.applyHalftone(grayscale, width, height, bitmap, bytesPerLine, opts.threshold, opts.halftoneDotType);
250
+ this.applyHalftone(
251
+ grayscale,
252
+ width,
253
+ height,
254
+ bitmap,
255
+ bytesPerLine,
256
+ opts.threshold,
257
+ opts.halftoneDotType
258
+ );
221
259
  break;
222
260
  case 'sierra':
223
261
  this.applySierraDithering(grayscale, width, height, bitmap, bytesPerLine, opts.threshold);
@@ -229,7 +267,14 @@ export class ImageProcessing {
229
267
  this.applyAtkinsonDithering(grayscale, width, height, bitmap, bytesPerLine, opts.threshold);
230
268
  break;
231
269
  default:
232
- this.applyFloydSteinbergDithering(grayscale, width, height, bitmap, bytesPerLine, opts.threshold);
270
+ this.applyFloydSteinbergDithering(
271
+ grayscale,
272
+ width,
273
+ height,
274
+ bitmap,
275
+ bytesPerLine,
276
+ opts.threshold
277
+ );
233
278
  }
234
279
  }
235
280
 
@@ -254,10 +299,10 @@ export class ImageProcessing {
254
299
  bitmap[byteIdx] = (bitmap[byteIdx] ?? 0) | (1 << bitIdx);
255
300
  }
256
301
  const err = oldPixel - newPixel;
257
- this.distributeErr(grayscale, width, height, x + 1, y, err * 7 / 16);
258
- this.distributeErr(grayscale, width, height, x - 1, y + 1, err * 3 / 16);
259
- this.distributeErr(grayscale, width, height, x, y + 1, err * 5 / 16);
260
- this.distributeErr(grayscale, width, height, x + 1, y + 1, err * 1 / 16);
302
+ this.distributeErr(grayscale, width, height, x + 1, y, (err * 7) / 16);
303
+ this.distributeErr(grayscale, width, height, x - 1, y + 1, (err * 3) / 16);
304
+ this.distributeErr(grayscale, width, height, x, y + 1, (err * 5) / 16);
305
+ this.distributeErr(grayscale, width, height, x + 1, y + 1, (err * 1) / 16);
261
306
  }
262
307
  }
263
308
  }
@@ -304,11 +349,12 @@ export class ImageProcessing {
304
349
  thresholdOffset: number,
305
350
  matrixSize: 2 | 4 | 8
306
351
  ): void {
307
- const matrix = matrixSize === 2
308
- ? ImageProcessing.BAYER_MATRIX_2
309
- : matrixSize === 8
310
- ? ImageProcessing.BAYER_MATRIX_8
311
- : ImageProcessing.BAYER_MATRIX_4;
352
+ const matrix =
353
+ matrixSize === 2
354
+ ? ImageProcessing.BAYER_MATRIX_2
355
+ : matrixSize === 8
356
+ ? ImageProcessing.BAYER_MATRIX_8
357
+ : ImageProcessing.BAYER_MATRIX_4;
312
358
  const matrixMax = matrixSize === 4 ? 16 : matrixSize === 8 ? 64 : 4;
313
359
 
314
360
  for (let y = 0; y < height; y++) {
@@ -317,7 +363,7 @@ export class ImageProcessing {
317
363
  const pixel = grayscale[idx] ?? 0;
318
364
  const bayerRow = matrix[y % matrixSize] ?? [];
319
365
  const bayerVal = bayerRow[x % matrixSize] ?? 0;
320
- const adjustedThreshold = thresholdOffset + ((bayerVal / matrixMax) * 48);
366
+ const adjustedThreshold = thresholdOffset + (bayerVal / matrixMax) * 48;
321
367
  if (pixel < adjustedThreshold) {
322
368
  const byteIdx = y * bytesPerLine + Math.floor(x / 8);
323
369
  const bitIdx = 7 - (x % 8);
@@ -402,15 +448,15 @@ export class ImageProcessing {
402
448
  bitmap[byteIdx] = (bitmap[byteIdx] ?? 0) | (1 << bitIdx);
403
449
  }
404
450
  const err = oldPixel - newPixel;
405
- this.distributeErr(grayscale, width, height, x + 1, y, err * 5 / 32);
406
- this.distributeErr(grayscale, width, height, x - 1, y + 1, err * 3 / 32);
407
- this.distributeErr(grayscale, width, height, x, y + 1, err * 5 / 32);
408
- this.distributeErr(grayscale, width, height, x + 1, y + 1, err * 2 / 32);
409
- this.distributeErr(grayscale, width, height, x - 2, y + 1, err * 2 / 32);
410
- this.distributeErr(grayscale, width, height, x - 1, y + 2, err * 2 / 32);
411
- this.distributeErr(grayscale, width, height, x, y + 2, err * 3 / 32);
412
- this.distributeErr(grayscale, width, height, x + 1, y + 2, err * 2 / 32);
413
- this.distributeErr(grayscale, width, height, x + 2, y + 2, err * 1 / 32);
451
+ this.distributeErr(grayscale, width, height, x + 1, y, (err * 5) / 32);
452
+ this.distributeErr(grayscale, width, height, x - 1, y + 1, (err * 3) / 32);
453
+ this.distributeErr(grayscale, width, height, x, y + 1, (err * 5) / 32);
454
+ this.distributeErr(grayscale, width, height, x + 1, y + 1, (err * 2) / 32);
455
+ this.distributeErr(grayscale, width, height, x - 2, y + 1, (err * 2) / 32);
456
+ this.distributeErr(grayscale, width, height, x - 1, y + 2, (err * 2) / 32);
457
+ this.distributeErr(grayscale, width, height, x, y + 2, (err * 3) / 32);
458
+ this.distributeErr(grayscale, width, height, x + 1, y + 2, (err * 2) / 32);
459
+ this.distributeErr(grayscale, width, height, x + 2, y + 2, (err * 1) / 32);
414
460
  }
415
461
  }
416
462
  }
@@ -436,18 +482,18 @@ export class ImageProcessing {
436
482
  bitmap[byteIdx] = (bitmap[byteIdx] ?? 0) | (1 << bitIdx);
437
483
  }
438
484
  const err = oldPixel - newPixel;
439
- this.distributeErr(grayscale, width, height, x + 1, y, err * 8 / 42);
440
- this.distributeErr(grayscale, width, height, x + 2, y, err * 4 / 42);
441
- this.distributeErr(grayscale, width, height, x - 2, y + 1, err * 2 / 42);
442
- this.distributeErr(grayscale, width, height, x - 1, y + 1, err * 4 / 42);
443
- this.distributeErr(grayscale, width, height, x, y + 1, err * 8 / 42);
444
- this.distributeErr(grayscale, width, height, x + 1, y + 1, err * 4 / 42);
445
- this.distributeErr(grayscale, width, height, x + 2, y + 1, err * 2 / 42);
446
- this.distributeErr(grayscale, width, height, x - 2, y + 2, err * 1 / 42);
447
- this.distributeErr(grayscale, width, height, x - 1, y + 2, err * 2 / 42);
448
- this.distributeErr(grayscale, width, height, x, y + 2, err * 4 / 42);
449
- this.distributeErr(grayscale, width, height, x + 1, y + 2, err * 2 / 42);
450
- this.distributeErr(grayscale, width, height, x + 2, y + 2, err * 1 / 42);
485
+ this.distributeErr(grayscale, width, height, x + 1, y, (err * 8) / 42);
486
+ this.distributeErr(grayscale, width, height, x + 2, y, (err * 4) / 42);
487
+ this.distributeErr(grayscale, width, height, x - 2, y + 1, (err * 2) / 42);
488
+ this.distributeErr(grayscale, width, height, x - 1, y + 1, (err * 4) / 42);
489
+ this.distributeErr(grayscale, width, height, x, y + 1, (err * 8) / 42);
490
+ this.distributeErr(grayscale, width, height, x + 1, y + 1, (err * 4) / 42);
491
+ this.distributeErr(grayscale, width, height, x + 2, y + 1, (err * 2) / 42);
492
+ this.distributeErr(grayscale, width, height, x - 2, y + 2, (err * 1) / 42);
493
+ this.distributeErr(grayscale, width, height, x - 1, y + 2, (err * 2) / 42);
494
+ this.distributeErr(grayscale, width, height, x, y + 2, (err * 4) / 42);
495
+ this.distributeErr(grayscale, width, height, x + 1, y + 2, (err * 2) / 42);
496
+ this.distributeErr(grayscale, width, height, x + 2, y + 2, (err * 1) / 42);
451
497
  }
452
498
  }
453
499
  }
@@ -572,8 +618,11 @@ export class ImageProcessing {
572
618
  const ii2 = (y1 * srcWidth + x2) * 4 + c;
573
619
  const ii3 = (y2 * srcWidth + x1) * 4 + c;
574
620
  const ii4 = (y2 * srcWidth + x2) * 4 + c;
575
- const v = (srcData[ii1] ?? 0) * w1 + (srcData[ii2] ?? 0) * w2
576
- + (srcData[ii3] ?? 0) * w3 + (srcData[ii4] ?? 0) * w4;
621
+ const v =
622
+ (srcData[ii1] ?? 0) * w1 +
623
+ (srcData[ii2] ?? 0) * w2 +
624
+ (srcData[ii3] ?? 0) * w3 +
625
+ (srcData[ii4] ?? 0) * w4;
577
626
  destData[(y * destWidth + x) * 4 + c] = Math.round(v);
578
627
  }
579
628
  }
@@ -627,7 +676,7 @@ export class ImageProcessing {
627
676
  // Center=3, edges=-0.5
628
677
  const kernel: number[][] = [
629
678
  [-0.5, -1.0, -0.5],
630
- [-1.0, 3.0, -1.0],
679
+ [-1.0, 3.0, -1.0],
631
680
  [-0.5, -1.0, -0.5],
632
681
  ];
633
682
  const kHalf = 1;
@@ -658,7 +707,7 @@ export class ImageProcessing {
658
707
  const step = 255 / (Math.pow(2, lv) - 1);
659
708
  const result = new Uint8Array(data.length);
660
709
  for (let i = 0; i < data.length; i += 4) {
661
- result[i] = Math.round(Math.round((data[i] ?? 0) / step) * step);
710
+ result[i] = Math.round(Math.round((data[i] ?? 0) / step) * step);
662
711
  result[i + 1] = Math.round(Math.round((data[i + 1] ?? 0) / step) * step);
663
712
  result[i + 2] = Math.round(Math.round((data[i + 2] ?? 0) / step) * step);
664
713
  result[i + 3] = data[i + 3] ?? 255;
@@ -80,13 +80,20 @@ export function detectPlatform(): PlatformType {
80
80
  */
81
81
  export function getPlatformGlobal(): unknown {
82
82
  switch (detectPlatform()) {
83
- case PlatformType.WECHAT: return wx;
84
- case PlatformType.ALIPAY: return my;
85
- case PlatformType.BAIDU: return swan;
86
- case PlatformType.BYTEDANCE: return tt;
87
- case PlatformType.QQ: return qq;
88
- case PlatformType.WEB: return window;
89
- default: return null;
83
+ case PlatformType.WECHAT:
84
+ return wx;
85
+ case PlatformType.ALIPAY:
86
+ return my;
87
+ case PlatformType.BAIDU:
88
+ return swan;
89
+ case PlatformType.BYTEDANCE:
90
+ return tt;
91
+ case PlatformType.QQ:
92
+ return qq;
93
+ case PlatformType.WEB:
94
+ return window;
95
+ default:
96
+ return null;
90
97
  }
91
98
  }
92
99
 
@@ -107,12 +114,19 @@ export function isPlatformSupported(): boolean {
107
114
  */
108
115
  export function getPlatformName(): string {
109
116
  switch (detectPlatform()) {
110
- case PlatformType.WECHAT: return '微信小程序';
111
- case PlatformType.ALIPAY: return '支付宝小程序';
112
- case PlatformType.BAIDU: return '百度小程序';
113
- case PlatformType.BYTEDANCE: return '字节跳动小程序';
114
- case PlatformType.QQ: return 'QQ小程序';
115
- case PlatformType.WEB: return 'Web平台';
116
- default: return '未知平台';
117
+ case PlatformType.WECHAT:
118
+ return '微信小程序';
119
+ case PlatformType.ALIPAY:
120
+ return '支付宝小程序';
121
+ case PlatformType.BAIDU:
122
+ return '百度小程序';
123
+ case PlatformType.BYTEDANCE:
124
+ return '字节跳动小程序';
125
+ case PlatformType.QQ:
126
+ return 'QQ小程序';
127
+ case PlatformType.WEB:
128
+ return 'Web平台';
129
+ default:
130
+ return '未知平台';
117
131
  }
118
132
  }