taro-bluetooth-print 2.7.0 → 2.8.3
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 +32 -0
- package/README.md +104 -133
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/types/device/DeviceManager.d.ts +1 -1
- package/dist/types/device/DiscoveryService.d.ts +3 -2
- package/dist/types/drivers/SprtDriver.d.ts +87 -0
- package/dist/types/drivers/XprinterDriver.d.ts +84 -0
- package/dist/types/drivers/index.d.ts +2 -0
- package/dist/types/services/CloudPrintManager.d.ts +123 -0
- package/dist/types/services/PrintScheduler.d.ts +3 -3
- package/dist/types/services/QRCodeDiscoveryService.d.ts +120 -0
- package/dist/types/services/QRCodeParser.d.ts +60 -0
- package/dist/types/services/index.d.ts +3 -0
- package/dist/types/types.d.ts +1 -1
- package/package.json +1 -1
- package/src/device/DeviceManager.ts +2 -2
- package/src/device/DiscoveryService.ts +39 -26
- package/src/drivers/SprtDriver.ts +163 -0
- package/src/drivers/XprinterDriver.ts +155 -0
- package/src/drivers/index.ts +4 -0
- package/src/services/CloudPrintManager.ts +372 -0
- package/src/services/PrintScheduler.ts +18 -8
- package/src/services/QRCodeDiscoveryService.ts +429 -0
- package/src/services/QRCodeParser.ts +185 -0
- package/src/services/index.ts +29 -0
- package/src/template/TemplateEngine.ts +2 -2
- package/src/types.ts +1 -1
- package/src/utils/image.ts +37 -38
package/src/utils/image.ts
CHANGED
|
@@ -199,9 +199,9 @@ export class ImageProcessing {
|
|
|
199
199
|
const grayscale = new Float32Array(width * height);
|
|
200
200
|
for (let i = 0; i < data.length; i += 4) {
|
|
201
201
|
const idx = i >> 2;
|
|
202
|
-
const r = data[i]
|
|
203
|
-
const g = data[i + 1]
|
|
204
|
-
const b = data[i + 2]
|
|
202
|
+
const r = data[i];
|
|
203
|
+
const g = data[i + 1];
|
|
204
|
+
const b = data[i + 2];
|
|
205
205
|
grayscale[idx] = (r * 299 + g * 587 + b * 114) / 1000;
|
|
206
206
|
}
|
|
207
207
|
return grayscale;
|
|
@@ -215,7 +215,7 @@ export class ImageProcessing {
|
|
|
215
215
|
if (contrast === 1.0 && brightness === 0.0) return grayscale;
|
|
216
216
|
const adjusted = new Float32Array(grayscale);
|
|
217
217
|
for (let i = 0; i < adjusted.length; i++) {
|
|
218
|
-
const value = adjusted[i]
|
|
218
|
+
const value = adjusted[i];
|
|
219
219
|
adjusted[i] = Math.max(0, Math.min(255, (value - 128) * contrast + 128 + brightness * 255));
|
|
220
220
|
}
|
|
221
221
|
return adjusted;
|
|
@@ -291,12 +291,12 @@ export class ImageProcessing {
|
|
|
291
291
|
for (let y = 0; y < height; y++) {
|
|
292
292
|
for (let x = 0; x < width; x++) {
|
|
293
293
|
const idx = y * width + x;
|
|
294
|
-
const oldPixel = grayscale[idx]
|
|
294
|
+
const oldPixel = grayscale[idx];
|
|
295
295
|
const newPixel = oldPixel < threshold ? 0 : 255;
|
|
296
296
|
if (newPixel === 0) {
|
|
297
297
|
const byteIdx = y * bytesPerLine + Math.floor(x / 8);
|
|
298
298
|
const bitIdx = 7 - (x % 8);
|
|
299
|
-
bitmap[byteIdx] =
|
|
299
|
+
bitmap[byteIdx] = bitmap[byteIdx] | (1 << bitIdx);
|
|
300
300
|
}
|
|
301
301
|
const err = oldPixel - newPixel;
|
|
302
302
|
this.distributeErr(grayscale, width, height, x + 1, y, (err * 7) / 16);
|
|
@@ -320,12 +320,12 @@ export class ImageProcessing {
|
|
|
320
320
|
for (let y = 0; y < height; y++) {
|
|
321
321
|
for (let x = 0; x < width; x++) {
|
|
322
322
|
const idx = y * width + x;
|
|
323
|
-
const oldPixel = grayscale[idx]
|
|
323
|
+
const oldPixel = grayscale[idx];
|
|
324
324
|
const newPixel = oldPixel < threshold ? 0 : 255;
|
|
325
325
|
if (newPixel === 0) {
|
|
326
326
|
const byteIdx = y * bytesPerLine + Math.floor(x / 8);
|
|
327
327
|
const bitIdx = 7 - (x % 8);
|
|
328
|
-
bitmap[byteIdx] =
|
|
328
|
+
bitmap[byteIdx] = bitmap[byteIdx] | (1 << bitIdx);
|
|
329
329
|
}
|
|
330
330
|
const err = (oldPixel - newPixel) / 8;
|
|
331
331
|
this.distributeErr(grayscale, width, height, x + 1, y, err);
|
|
@@ -360,14 +360,14 @@ export class ImageProcessing {
|
|
|
360
360
|
for (let y = 0; y < height; y++) {
|
|
361
361
|
for (let x = 0; x < width; x++) {
|
|
362
362
|
const idx = y * width + x;
|
|
363
|
-
const pixel = grayscale[idx]
|
|
363
|
+
const pixel = grayscale[idx];
|
|
364
364
|
const bayerRow = matrix[y % matrixSize] ?? [];
|
|
365
365
|
const bayerVal = bayerRow[x % matrixSize] ?? 0;
|
|
366
366
|
const adjustedThreshold = thresholdOffset + (bayerVal / matrixMax) * 48;
|
|
367
367
|
if (pixel < adjustedThreshold) {
|
|
368
368
|
const byteIdx = y * bytesPerLine + Math.floor(x / 8);
|
|
369
369
|
const bitIdx = 7 - (x % 8);
|
|
370
|
-
bitmap[byteIdx] =
|
|
370
|
+
bitmap[byteIdx] = bitmap[byteIdx] | (1 << bitIdx);
|
|
371
371
|
}
|
|
372
372
|
}
|
|
373
373
|
}
|
|
@@ -389,7 +389,7 @@ export class ImageProcessing {
|
|
|
389
389
|
for (let y = 0; y < height; y++) {
|
|
390
390
|
for (let x = 0; x < width; x++) {
|
|
391
391
|
const idx = y * width + x;
|
|
392
|
-
const pixel = grayscale[idx]
|
|
392
|
+
const pixel = grayscale[idx];
|
|
393
393
|
const localY = y % cellSize;
|
|
394
394
|
const localX = x % cellSize;
|
|
395
395
|
const row = thresholds[localY] ?? [];
|
|
@@ -398,7 +398,7 @@ export class ImageProcessing {
|
|
|
398
398
|
if (pixel < adjusted) {
|
|
399
399
|
const byteIdx = y * bytesPerLine + Math.floor(x / 8);
|
|
400
400
|
const bitIdx = 7 - (x % 8);
|
|
401
|
-
bitmap[byteIdx] =
|
|
401
|
+
bitmap[byteIdx] = bitmap[byteIdx] | (1 << bitIdx);
|
|
402
402
|
}
|
|
403
403
|
}
|
|
404
404
|
}
|
|
@@ -440,12 +440,12 @@ export class ImageProcessing {
|
|
|
440
440
|
for (let y = 0; y < height; y++) {
|
|
441
441
|
for (let x = 0; x < width; x++) {
|
|
442
442
|
const idx = y * width + x;
|
|
443
|
-
const oldPixel = grayscale[idx]
|
|
443
|
+
const oldPixel = grayscale[idx];
|
|
444
444
|
const newPixel = oldPixel < threshold ? 0 : 255;
|
|
445
445
|
if (newPixel === 0) {
|
|
446
446
|
const byteIdx = y * bytesPerLine + Math.floor(x / 8);
|
|
447
447
|
const bitIdx = 7 - (x % 8);
|
|
448
|
-
bitmap[byteIdx] =
|
|
448
|
+
bitmap[byteIdx] = bitmap[byteIdx] | (1 << bitIdx);
|
|
449
449
|
}
|
|
450
450
|
const err = oldPixel - newPixel;
|
|
451
451
|
this.distributeErr(grayscale, width, height, x + 1, y, (err * 5) / 32);
|
|
@@ -474,12 +474,12 @@ export class ImageProcessing {
|
|
|
474
474
|
for (let y = 0; y < height; y++) {
|
|
475
475
|
for (let x = 0; x < width; x++) {
|
|
476
476
|
const idx = y * width + x;
|
|
477
|
-
const oldPixel = grayscale[idx]
|
|
477
|
+
const oldPixel = grayscale[idx];
|
|
478
478
|
const newPixel = oldPixel < threshold ? 0 : 255;
|
|
479
479
|
if (newPixel === 0) {
|
|
480
480
|
const byteIdx = y * bytesPerLine + Math.floor(x / 8);
|
|
481
481
|
const bitIdx = 7 - (x % 8);
|
|
482
|
-
bitmap[byteIdx] =
|
|
482
|
+
bitmap[byteIdx] = bitmap[byteIdx] | (1 << bitIdx);
|
|
483
483
|
}
|
|
484
484
|
const err = oldPixel - newPixel;
|
|
485
485
|
this.distributeErr(grayscale, width, height, x + 1, y, (err * 8) / 42);
|
|
@@ -511,11 +511,11 @@ export class ImageProcessing {
|
|
|
511
511
|
for (let y = 0; y < height; y++) {
|
|
512
512
|
for (let x = 0; x < width; x++) {
|
|
513
513
|
const idx = y * width + x;
|
|
514
|
-
const pixel = grayscale[idx]
|
|
514
|
+
const pixel = grayscale[idx];
|
|
515
515
|
if (pixel < threshold) {
|
|
516
516
|
const byteIdx = y * bytesPerLine + Math.floor(x / 8);
|
|
517
517
|
const bitIdx = 7 - (x % 8);
|
|
518
|
-
bitmap[byteIdx] =
|
|
518
|
+
bitmap[byteIdx] = bitmap[byteIdx] | (1 << bitIdx);
|
|
519
519
|
}
|
|
520
520
|
}
|
|
521
521
|
}
|
|
@@ -533,7 +533,7 @@ export class ImageProcessing {
|
|
|
533
533
|
): void {
|
|
534
534
|
if (nx >= 0 && nx < width && ny >= 0 && ny < height) {
|
|
535
535
|
const idx = ny * width + nx;
|
|
536
|
-
const current = grayscale[idx]
|
|
536
|
+
const current = grayscale[idx];
|
|
537
537
|
grayscale[idx] = Math.max(0, Math.min(255, current + error));
|
|
538
538
|
}
|
|
539
539
|
}
|
|
@@ -581,10 +581,10 @@ export class ImageProcessing {
|
|
|
581
581
|
const sjy = Math.min(srcHeight - 1, Math.round(y * sy));
|
|
582
582
|
const si = (sjy * srcWidth + sjx) * 4;
|
|
583
583
|
const di = (y * destWidth + x) * 4;
|
|
584
|
-
destData[di] = srcData[si]
|
|
585
|
-
destData[di + 1] = srcData[si + 1]
|
|
586
|
-
destData[di + 2] = srcData[si + 2]
|
|
587
|
-
destData[di + 3] = srcData[si + 3]
|
|
584
|
+
destData[di] = srcData[si];
|
|
585
|
+
destData[di + 1] = srcData[si + 1];
|
|
586
|
+
destData[di + 2] = srcData[si + 2];
|
|
587
|
+
destData[di + 3] = srcData[si + 3];
|
|
588
588
|
}
|
|
589
589
|
}
|
|
590
590
|
}
|
|
@@ -618,11 +618,7 @@ export class ImageProcessing {
|
|
|
618
618
|
const ii2 = (y1 * srcWidth + x2) * 4 + c;
|
|
619
619
|
const ii3 = (y2 * srcWidth + x1) * 4 + c;
|
|
620
620
|
const ii4 = (y2 * srcWidth + x2) * 4 + c;
|
|
621
|
-
const v =
|
|
622
|
-
(srcData[ii1] ?? 0) * w1 +
|
|
623
|
-
(srcData[ii2] ?? 0) * w2 +
|
|
624
|
-
(srcData[ii3] ?? 0) * w3 +
|
|
625
|
-
(srcData[ii4] ?? 0) * w4;
|
|
621
|
+
const v = srcData[ii1] * w1 + srcData[ii2] * w2 + srcData[ii3] * w3 + srcData[ii4] * w4;
|
|
626
622
|
destData[(y * destWidth + x) * 4 + c] = Math.round(v);
|
|
627
623
|
}
|
|
628
624
|
}
|
|
@@ -639,10 +635,13 @@ export class ImageProcessing {
|
|
|
639
635
|
}
|
|
640
636
|
const result = new Uint8Array(data.length);
|
|
641
637
|
for (let i = 0; i < data.length; i += 4) {
|
|
642
|
-
|
|
643
|
-
result[i
|
|
644
|
-
|
|
645
|
-
result[i +
|
|
638
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- lut has 256 entries, data[i] is 0-255
|
|
639
|
+
result[i] = lut[data[i]]!;
|
|
640
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
641
|
+
result[i + 1] = lut[data[i + 1]]!;
|
|
642
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
643
|
+
result[i + 2] = lut[data[i + 2]]!;
|
|
644
|
+
result[i + 3] = data[i + 3];
|
|
646
645
|
}
|
|
647
646
|
return result;
|
|
648
647
|
}
|
|
@@ -659,7 +658,7 @@ export class ImageProcessing {
|
|
|
659
658
|
const ny2 = Math.max(0, Math.min(height - 1, y + dy));
|
|
660
659
|
const si = (ny2 * width + nx) * 4;
|
|
661
660
|
for (let c = 0; c < 4; c++) {
|
|
662
|
-
window.push(data[si + c]
|
|
661
|
+
window.push(data[si + c]);
|
|
663
662
|
}
|
|
664
663
|
}
|
|
665
664
|
}
|
|
@@ -692,7 +691,7 @@ export class ImageProcessing {
|
|
|
692
691
|
const ny2 = Math.max(0, Math.min(height - 1, y + ky - kHalf));
|
|
693
692
|
const si = (ny2 * width + nx) * 4 + c;
|
|
694
693
|
const kv = kernel[ky]?.[kx] ?? 0;
|
|
695
|
-
sum +=
|
|
694
|
+
sum += data[si] * kv;
|
|
696
695
|
}
|
|
697
696
|
}
|
|
698
697
|
result[di + c] = Math.max(0, Math.min(255, Math.round(sum)));
|
|
@@ -707,10 +706,10 @@ export class ImageProcessing {
|
|
|
707
706
|
const step = 255 / (Math.pow(2, lv) - 1);
|
|
708
707
|
const result = new Uint8Array(data.length);
|
|
709
708
|
for (let i = 0; i < data.length; i += 4) {
|
|
710
|
-
result[i] = Math.round(Math.round(
|
|
711
|
-
result[i + 1] = Math.round(Math.round(
|
|
712
|
-
result[i + 2] = Math.round(Math.round(
|
|
713
|
-
result[i + 3] = data[i + 3]
|
|
709
|
+
result[i] = Math.round(Math.round(data[i] / step) * step);
|
|
710
|
+
result[i + 1] = Math.round(Math.round(data[i + 1] / step) * step);
|
|
711
|
+
result[i + 2] = Math.round(Math.round(data[i + 2] / step) * step);
|
|
712
|
+
result[i + 3] = data[i + 3];
|
|
714
713
|
}
|
|
715
714
|
return result;
|
|
716
715
|
}
|