@psdk/device-webusb 0.5.4 → 0.5.5

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/dist/index.js CHANGED
@@ -1,2288 +1,2 @@
1
- require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
2
- /******/ "use strict";
3
- /******/ var __webpack_modules__ = ({
4
-
5
- /***/ 245:
6
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
7
-
8
-
9
- Object.defineProperty(exports, "__esModule", ({ value: true }));
10
- exports.FakeConnectedDevice = void 0;
11
- /**
12
- * Connected device
13
- */
14
- const types_1 = __nccwpck_require__(569);
15
- const father_1 = __nccwpck_require__(932);
16
- /**
17
- * Fake connected device
18
- */
19
- class FakeConnectedDevice {
20
- origin() {
21
- return "FAKE-DEVICE";
22
- }
23
- connectionState() {
24
- return types_1.ConnectionState.CONNECTED;
25
- }
26
- deviceName() {
27
- return "FAKE-DEVICE";
28
- }
29
- async disconnect() {
30
- }
31
- canRead() {
32
- return true;
33
- }
34
- async read(options) {
35
- return father_1.PsdkConst.EMPTY_BYTES;
36
- }
37
- async write(data) {
38
- console.log('WRITE: ', data);
39
- }
40
- flush() {
41
- }
42
- }
43
- exports.FakeConnectedDevice = FakeConnectedDevice;
44
-
45
-
46
- /***/ }),
47
-
48
- /***/ 324:
49
- /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
50
-
51
-
52
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
53
- if (k2 === undefined) k2 = k;
54
- var desc = Object.getOwnPropertyDescriptor(m, k);
55
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
56
- desc = { enumerable: true, get: function() { return m[k]; } };
57
- }
58
- Object.defineProperty(o, k2, desc);
59
- }) : (function(o, m, k, k2) {
60
- if (k2 === undefined) k2 = k;
61
- o[k2] = m[k];
62
- }));
63
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
64
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
65
- };
66
- Object.defineProperty(exports, "__esModule", ({ value: true }));
67
- __exportStar(__nccwpck_require__(245), exports);
68
- __exportStar(__nccwpck_require__(569), exports);
69
-
70
-
71
- /***/ }),
72
-
73
- /***/ 569:
74
- /***/ ((__unused_webpack_module, exports) => {
75
-
76
-
77
- Object.defineProperty(exports, "__esModule", ({ value: true }));
78
- exports.ReadOptions = exports.WroteReporter = exports.ConnectionState = void 0;
79
- /**
80
- * Connection state
81
- */
82
- var ConnectionState;
83
- (function (ConnectionState) {
84
- /**
85
- * connected
86
- */
87
- ConnectionState["CONNECTED"] = "CONNECTED";
88
- /**
89
- * disconnect
90
- */
91
- ConnectionState["DISCONNECTED"] = "DISCONNECTED";
92
- })(ConnectionState || (exports.ConnectionState = ConnectionState = {}));
93
- /**
94
- * Wrote reporter
95
- */
96
- class WroteReporter {
97
- ok;
98
- binary;
99
- controlExit;
100
- exception;
101
- constructor(
102
- /**
103
- * Wrote is ok
104
- */
105
- ok,
106
- /**
107
- * Wrote data
108
- */
109
- binary,
110
- /**
111
- * control exit
112
- */
113
- controlExit,
114
- /**
115
- * exception
116
- */
117
- exception) {
118
- this.ok = ok;
119
- this.binary = binary;
120
- this.controlExit = controlExit;
121
- this.exception = exception;
122
- }
123
- }
124
- exports.WroteReporter = WroteReporter;
125
- /**
126
- * Read options
127
- */
128
- class ReadOptions {
129
- timeout;
130
- constructor(options) {
131
- this.timeout = options?.timeout;
132
- }
133
- }
134
- exports.ReadOptions = ReadOptions;
135
-
136
-
137
- /***/ }),
138
-
139
- /***/ 555:
140
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
141
-
142
-
143
- Object.defineProperty(exports, "__esModule", ({ value: true }));
144
- exports.PSDK = void 0;
145
- const types_1 = __nccwpck_require__(482);
146
- const write_operation_1 = __nccwpck_require__(783);
147
- class PSDK {
148
- /**
149
- * sdk version
150
- */
151
- sversion() {
152
- return '0.2.67';
153
- }
154
- /**
155
- * authors
156
- */
157
- authors() {
158
- return types_1.PsdkConst.DEF_AUTHORS;
159
- }
160
- /**
161
- * Push raw command
162
- * @param raw raw
163
- */
164
- raw(raw) {
165
- this.commander().pushArg(raw);
166
- return this;
167
- }
168
- /**
169
- * Put variable
170
- * @param name name
171
- * @param value value
172
- */
173
- variable(name, value) {
174
- this.commander().variable(name, value);
175
- return this;
176
- }
177
- /**
178
- * get command
179
- */
180
- command() {
181
- return this.commander().command();
182
- }
183
- /**
184
- * Clear command
185
- */
186
- clear() {
187
- this.commander().clear();
188
- return this;
189
- }
190
- /**
191
- * Write data to device
192
- */
193
- async write(options) {
194
- const connectedDevice = this.connectedDevice();
195
- if (!connectedDevice)
196
- throw Error('It\'s seems you missing to set connectedDevice');
197
- options = options ?? types_1.WriteOptions.def();
198
- const command = this.command();
199
- const binary = command.binary();
200
- const operation = new write_operation_1.DataWriteOperation(options, binary, connectedDevice);
201
- const reporter = await operation.write();
202
- this.clear();
203
- return reporter;
204
- }
205
- /**
206
- * Newline command
207
- */
208
- newline() {
209
- this.commander().newline();
210
- return this;
211
- }
212
- /**
213
- * Push command
214
- * @param command
215
- */
216
- push(command) {
217
- this.commander().pushArg(command);
218
- return this;
219
- }
220
- }
221
- exports.PSDK = PSDK;
222
-
223
-
224
- /***/ }),
225
-
226
- /***/ 101:
227
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
228
-
229
-
230
- Object.defineProperty(exports, "__esModule", ({ value: true }));
231
- exports.BasicArg = void 0;
232
- const types_1 = __nccwpck_require__(482);
233
- class BasicArg {
234
- newline() {
235
- return types_1.PsdkConst.DEF_ENABLED_NEWLINE;
236
- }
237
- }
238
- exports.BasicArg = BasicArg;
239
-
240
-
241
- /***/ }),
242
-
243
- /***/ 12:
244
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
245
-
246
-
247
- Object.defineProperty(exports, "__esModule", ({ value: true }));
248
- exports.OnlyTextHeaderArg = exports.OnlyBinaryHeaderArg = exports.EasyArg = void 0;
249
- const arg_1 = __nccwpck_require__(101);
250
- const command_1 = __nccwpck_require__(623);
251
- /**
252
- * Easy argument abstract class
253
- */
254
- class EasyArg extends arg_1.BasicArg {
255
- prependClauses;
256
- appendClauses;
257
- constructor() {
258
- super();
259
- this.prependClauses = [];
260
- this.appendClauses = [];
261
- }
262
- /**
263
- * Append another argument for this clause
264
- * @param arg
265
- */
266
- append(arg) {
267
- this.appendClauses.push(...arg.clauses());
268
- return this;
269
- }
270
- /**
271
- * Prepend another argument for this clause
272
- * @param arg
273
- */
274
- prepend(arg) {
275
- this.prependClauses.push(...arg.clauses());
276
- return this;
277
- }
278
- /**
279
- * Get current command clauses
280
- */
281
- clauses() {
282
- const clause = this.clause();
283
- const currentClauses = [];
284
- if (clause.type !== command_1.ClauseType.NONE) {
285
- currentClauses.push(clause);
286
- if (this.newline()) {
287
- currentClauses.push(command_1.CommandClause.newline());
288
- }
289
- }
290
- return [
291
- ...this.prependClauses,
292
- ...currentClauses,
293
- ...this.appendClauses,
294
- ];
295
- }
296
- clear() {
297
- this.prependClauses.splice(0, this.prependClauses.length);
298
- this.appendClauses.splice(0, this.appendClauses.length);
299
- }
300
- }
301
- exports.EasyArg = EasyArg;
302
- class OnlyBinaryHeaderArg extends EasyArg {
303
- append(arg) {
304
- super.append(arg);
305
- return this;
306
- }
307
- prepend(arg) {
308
- super.prepend(arg);
309
- return this;
310
- }
311
- clause() {
312
- return command_1.CommandClause.binary(this.header());
313
- }
314
- newline() {
315
- return false;
316
- }
317
- }
318
- exports.OnlyBinaryHeaderArg = OnlyBinaryHeaderArg;
319
- class OnlyTextHeaderArg extends EasyArg {
320
- append(arg) {
321
- super.append(arg);
322
- return this;
323
- }
324
- prepend(arg) {
325
- super.prepend(arg);
326
- return this;
327
- }
328
- clause() {
329
- return command_1.CommandClause.text(this.header());
330
- }
331
- }
332
- exports.OnlyTextHeaderArg = OnlyTextHeaderArg;
333
-
334
-
335
- /***/ }),
336
-
337
- /***/ 666:
338
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
339
-
340
-
341
- Object.defineProperty(exports, "__esModule", ({ value: true }));
342
- exports.RawMode = exports.Raw = void 0;
343
- const easy_1 = __nccwpck_require__(12);
344
- const command_1 = __nccwpck_require__(623);
345
- const types_1 = __nccwpck_require__(482);
346
- class Raw extends easy_1.EasyArg {
347
- _mode;
348
- _text;
349
- _charset;
350
- _binary;
351
- _newline = types_1.PsdkConst.DEF_ENABLED_NEWLINE;
352
- constructor() {
353
- super();
354
- }
355
- static text(text, options) {
356
- const raw = new Raw();
357
- raw._mode = RawMode.TEXT;
358
- raw._text = text;
359
- raw._charset = options?.charset ?? types_1.PsdkConst.DEF_CHARSET;
360
- raw._newline = options?.newline ?? types_1.PsdkConst.DEF_ENABLED_NEWLINE;
361
- return raw;
362
- }
363
- static binary(binary, options) {
364
- const raw = new Raw();
365
- raw._mode = RawMode.BINARY;
366
- raw._binary = binary;
367
- raw._charset = options?.charset ?? types_1.PsdkConst.DEF_CHARSET;
368
- raw._newline = options?.newline ?? types_1.PsdkConst.DEF_ENABLED_NEWLINE;
369
- return raw;
370
- }
371
- append(arg) {
372
- super.append(arg);
373
- return this;
374
- }
375
- prepend(arg) {
376
- super.prepend(arg);
377
- return this;
378
- }
379
- clause() {
380
- let clause;
381
- switch (this._mode) {
382
- case RawMode.TEXT:
383
- clause = command_1.CommandClause.text(this._text, this._charset);
384
- break;
385
- case RawMode.BINARY:
386
- clause = command_1.CommandClause.binary(this._binary);
387
- break;
388
- default:
389
- clause = command_1.CommandClause.none();
390
- break;
391
- }
392
- return clause;
393
- }
394
- header() {
395
- return types_1.PsdkConst.EMPTY_BYTES;
396
- }
397
- newline() {
398
- return this._newline;
399
- }
400
- }
401
- exports.Raw = Raw;
402
- var RawMode;
403
- (function (RawMode) {
404
- RawMode["BINARY"] = "BINARY";
405
- RawMode["TEXT"] = "TEXT";
406
- })(RawMode || (exports.RawMode = RawMode = {}));
407
-
408
-
409
- /***/ }),
410
-
411
- /***/ 146:
412
- /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
413
-
414
-
415
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
416
- if (k2 === undefined) k2 = k;
417
- var desc = Object.getOwnPropertyDescriptor(m, k);
418
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
419
- desc = { enumerable: true, get: function() { return m[k]; } };
420
- }
421
- Object.defineProperty(o, k2, desc);
422
- }) : (function(o, m, k, k2) {
423
- if (k2 === undefined) k2 = k;
424
- o[k2] = m[k];
425
- }));
426
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
427
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
428
- };
429
- Object.defineProperty(exports, "__esModule", ({ value: true }));
430
- __exportStar(__nccwpck_require__(101), exports);
431
- __exportStar(__nccwpck_require__(12), exports);
432
- __exportStar(__nccwpck_require__(666), exports);
433
-
434
-
435
- /***/ }),
436
-
437
- /***/ 623:
438
- /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
439
-
440
-
441
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
442
- if (k2 === undefined) k2 = k;
443
- var desc = Object.getOwnPropertyDescriptor(m, k);
444
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
445
- desc = { enumerable: true, get: function() { return m[k]; } };
446
- }
447
- Object.defineProperty(o, k2, desc);
448
- }) : (function(o, m, k, k2) {
449
- if (k2 === undefined) k2 = k;
450
- o[k2] = m[k];
451
- }));
452
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
453
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
454
- };
455
- Object.defineProperty(exports, "__esModule", ({ value: true }));
456
- __exportStar(__nccwpck_require__(247), exports);
457
- __exportStar(__nccwpck_require__(392), exports);
458
- __exportStar(__nccwpck_require__(211), exports);
459
- __exportStar(__nccwpck_require__(718), exports);
460
- __exportStar(__nccwpck_require__(839), exports);
461
- __exportStar(__nccwpck_require__(410), exports);
462
-
463
-
464
- /***/ }),
465
-
466
- /***/ 247:
467
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
468
-
469
-
470
- Object.defineProperty(exports, "__esModule", ({ value: true }));
471
- exports.DefaultCommand = exports.BasicCommand = void 0;
472
- /**
473
- * All printer sdk command interface
474
- */
475
- const types_1 = __nccwpck_require__(482);
476
- const base64_1 = __nccwpck_require__(423);
477
- const command_clause_1 = __nccwpck_require__(211);
478
- const toolkit_1 = __nccwpck_require__(6);
479
- class BasicCommand {
480
- base64() {
481
- return base64_1.Base64.fromUint8Array(this.binary());
482
- }
483
- }
484
- exports.BasicCommand = BasicCommand;
485
- class DefaultCommand extends BasicCommand {
486
- bytes;
487
- constructor(clauses, variable) {
488
- super();
489
- let bytes = [];
490
- for (const clause of clauses) {
491
- switch (clause.type) {
492
- case command_clause_1.ClauseType.TEXT:
493
- const t = toolkit_1.PVariableKit.replace(clause.text, variable);
494
- //# use gbk encoding
495
- // const t_buffer = iconv.encode(t, clause.charset ?? PsdkConst.DEF_CHARSET);
496
- const t_buffer = toolkit_1.FastGBK.encode(t);
497
- const t_binary = Array.prototype.slice.call(t_buffer, 0);
498
- bytes = bytes.concat(t_binary);
499
- //# use utf8 encoding
500
- // const t_binary = ByteKit.textToU8A(t)
501
- // const array = Array.from(t_binary)
502
- // bytes.push(...array);
503
- break;
504
- case command_clause_1.ClauseType.NEWLINE:
505
- case command_clause_1.ClauseType.BINARY:
506
- const b = Array.from(clause.binary ?? types_1.PsdkConst.EMPTY_BYTES);
507
- bytes = bytes.concat(b);
508
- break;
509
- }
510
- }
511
- this.bytes = new Uint8Array(bytes);
512
- }
513
- binary() {
514
- return this.bytes;
515
- }
516
- hex(output) {
517
- return (output ?? types_1.HexOutput.def()).format(this.binary());
518
- }
519
- string(charset) {
520
- // const buffer = Array.from(this.binary());
521
- // @ts-ignore
522
- // return iconv.decode(buffer, charset ?? PsdkConst.DEF_CHARSET);
523
- // return gbkDecoder.decode(this.binary());
524
- return toolkit_1.FastGBK.decode(this.binary());
525
- }
526
- }
527
- exports.DefaultCommand = DefaultCommand;
528
-
529
-
530
- /***/ }),
531
-
532
- /***/ 211:
533
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
534
-
535
-
536
- Object.defineProperty(exports, "__esModule", ({ value: true }));
537
- exports.CommandClause = exports.ClauseType = void 0;
538
- const types_1 = __nccwpck_require__(482);
539
- var ClauseType;
540
- (function (ClauseType) {
541
- ClauseType["TEXT"] = "TEXT";
542
- ClauseType["BINARY"] = "BINARY";
543
- ClauseType["NEWLINE"] = "NEWLINE";
544
- ClauseType["NONE"] = "NONE";
545
- })(ClauseType || (exports.ClauseType = ClauseType = {}));
546
- class CommandClause {
547
- /**
548
- * Clause type
549
- * @private
550
- */
551
- _type;
552
- /**
553
- * Text command
554
- * @private
555
- */
556
- _text;
557
- /**
558
- * Charset
559
- * @private
560
- */
561
- _charset;
562
- /**
563
- * Binary command
564
- * @private
565
- */
566
- _binary;
567
- constructor(type, text, charset, binary) {
568
- this._type = type;
569
- this._text = text;
570
- this._charset = charset;
571
- this._binary = binary;
572
- }
573
- static text(command, charset = types_1.PsdkConst.DEF_CHARSET) {
574
- return new CommandClause(ClauseType.TEXT, command, charset, undefined);
575
- }
576
- static binary(binary) {
577
- return new CommandClause(ClauseType.BINARY, undefined, undefined, binary);
578
- }
579
- static newline() {
580
- return new CommandClause(ClauseType.NEWLINE, undefined, undefined, types_1.PsdkConst.DEF_NEWLINE_BINARY);
581
- }
582
- static none() {
583
- return new CommandClause(ClauseType.NONE, undefined, undefined, undefined);
584
- }
585
- get type() {
586
- return this._type;
587
- }
588
- get text() {
589
- return this._text;
590
- }
591
- get charset() {
592
- return this._charset;
593
- }
594
- get binary() {
595
- return this._binary;
596
- }
597
- }
598
- exports.CommandClause = CommandClause;
599
-
600
-
601
- /***/ }),
602
-
603
- /***/ 392:
604
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
605
-
606
-
607
- Object.defineProperty(exports, "__esModule", ({ value: true }));
608
- exports.Commander = void 0;
609
- const command_clause_1 = __nccwpck_require__(211);
610
- const types_1 = __nccwpck_require__(482);
611
- const command_1 = __nccwpck_require__(247);
612
- /**
613
- * Command builder
614
- */
615
- class Commander {
616
- /**
617
- * Command clauses
618
- * @private
619
- */
620
- clauses;
621
- _variable;
622
- constructor() {
623
- this.clauses = [];
624
- this._variable = new Map();
625
- }
626
- /**
627
- * Make a commander
628
- */
629
- static make() {
630
- return new Commander();
631
- }
632
- /**
633
- * Push a text command
634
- * @param command command
635
- * @param options Options: { newline: newline, charset: charset }
636
- */
637
- pushText(command, options) {
638
- if (command.startsWith(types_1.PsdkConst.CRLF)) {
639
- command = command.substring(2);
640
- }
641
- const clause = command_clause_1.CommandClause.text(command, options?.charset ?? types_1.PsdkConst.DEF_CHARSET);
642
- return this.pushClause(clause, options?.newline ?? types_1.PsdkConst.DEF_ENABLED_NEWLINE);
643
- }
644
- /**
645
- * Push binary command
646
- * @param command Command
647
- * @param newline Add new line for this command
648
- */
649
- pushBinary(command, newline) {
650
- const clause = command_clause_1.CommandClause.binary(command);
651
- return this.pushClause(clause, newline ?? types_1.PsdkConst.DEF_ENABLED_NEWLINE);
652
- }
653
- /**
654
- * Push clause
655
- * @param clause Command clause object
656
- * @param newline Add new line for this command
657
- */
658
- pushClause(clause, newline) {
659
- this.clauses.push(clause);
660
- if (newline ?? types_1.PsdkConst.DEF_ENABLED_NEWLINE) {
661
- this.clauses.push(command_clause_1.CommandClause.newline());
662
- }
663
- return this;
664
- }
665
- /**
666
- * Push multiple clause
667
- * @param clauses
668
- */
669
- pushClauses(clauses) {
670
- clauses.forEach(item => this.pushClause(item, false));
671
- return this;
672
- }
673
- /**
674
- * Push arg
675
- * @param arg arg
676
- */
677
- pushArg(arg) {
678
- this.pushClauses(arg.clauses());
679
- return this;
680
- }
681
- /**
682
- * Add newline
683
- */
684
- newline() {
685
- const clause = command_clause_1.CommandClause.newline();
686
- return this.pushClause(clause, false);
687
- }
688
- /**
689
- * Add a new variable
690
- * @param name name
691
- * @param value value
692
- */
693
- variable(name, value) {
694
- this._variable.set(name, value);
695
- return this;
696
- }
697
- /**
698
- * Clear all commands
699
- */
700
- clear() {
701
- this.clauses.splice(0, this.clauses.length);
702
- this._variable.clear();
703
- return this;
704
- }
705
- /**
706
- * Get command
707
- */
708
- command() {
709
- return new command_1.DefaultCommand(this.clauses, this._variable);
710
- }
711
- }
712
- exports.Commander = Commander;
713
-
714
-
715
- /***/ }),
716
-
717
- /***/ 718:
718
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
719
-
720
-
721
- Object.defineProperty(exports, "__esModule", ({ value: true }));
722
- exports.TextAppendat = exports.Appendat = void 0;
723
- const toolkit_1 = __nccwpck_require__(6);
724
- class Appendat {
725
- _argument;
726
- _condition;
727
- _callback;
728
- constructor(argument, condition, callback) {
729
- this._argument = argument;
730
- this._condition = condition;
731
- this._callback = callback;
732
- }
733
- get condition() {
734
- return this._condition;
735
- }
736
- callback(callback) {
737
- this._callback = callback;
738
- return this;
739
- }
740
- quote() {
741
- return this;
742
- }
743
- argument() {
744
- if (!toolkit_1.Checker.truthy(this._callback))
745
- return this._argument;
746
- if (!toolkit_1.Checker.truthy(this._argument))
747
- return undefined;
748
- return this._callback.callback(this._argument);
749
- }
750
- }
751
- exports.Appendat = Appendat;
752
- class TextAppendat extends Appendat {
753
- _quote;
754
- constructor(argument, condition, callback) {
755
- super(argument, condition ?? true, callback);
756
- this._quote = false;
757
- }
758
- /**
759
- * Create new text appendat
760
- * @param argument argument
761
- * @param options options: { condition: condition for this arg, callback: value callback }
762
- */
763
- static create(argument, options) {
764
- return new TextAppendat(argument, options?.condition ?? true, new class {
765
- callback(data) {
766
- const cb = options?.callback;
767
- if (cb) {
768
- return cb(data);
769
- }
770
- return data;
771
- }
772
- });
773
- }
774
- callback(callback) {
775
- super.callback(callback);
776
- return this;
777
- }
778
- quote() {
779
- this._quote = true;
780
- return this;
781
- }
782
- argument() {
783
- const arg = super.argument();
784
- if (!toolkit_1.Checker.truthy(arg))
785
- return this._quote ? '""' : '';
786
- if (this._quote) {
787
- return `"${arg}"`;
788
- }
789
- return arg;
790
- }
791
- }
792
- exports.TextAppendat = TextAppendat;
793
-
794
-
795
- /***/ }),
796
-
797
- /***/ 839:
798
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
799
-
800
-
801
- Object.defineProperty(exports, "__esModule", ({ value: true }));
802
- exports.BinaryCommand = void 0;
803
- const command_clause_1 = __nccwpck_require__(211);
804
- // import * as iconv from 'iconv-lite';
805
- const toolkit_1 = __nccwpck_require__(6);
806
- class BinaryCommand {
807
- binary;
808
- constructor(binary) {
809
- this.binary = binary ?? [];
810
- }
811
- static make() {
812
- return new BinaryCommand();
813
- }
814
- static with(u8a) {
815
- const b = Array.from(u8a);
816
- return new BinaryCommand(b);
817
- }
818
- appendNumber(num) {
819
- this.binary.push(num);
820
- return this;
821
- }
822
- appendText(text, charset) {
823
- // const encoding = (charset ?? PsdkConst.DEF_CHARSET).toLowerCase();
824
- // const binary = iconv.encode(text, encoding);
825
- const binary = toolkit_1.FastGBK.encode(text);
826
- this.binary.push(...binary);
827
- return this;
828
- }
829
- appendU8A(u8a) {
830
- const b = Array.from(u8a);
831
- this.binary = this.binary.concat(b);
832
- return this;
833
- }
834
- output() {
835
- return new Uint8Array(this.binary);
836
- }
837
- clause() {
838
- const output = this.output();
839
- return command_clause_1.CommandClause.binary(output);
840
- }
841
- }
842
- exports.BinaryCommand = BinaryCommand;
843
-
844
-
845
- /***/ }),
846
-
847
- /***/ 410:
848
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
849
-
850
-
851
- Object.defineProperty(exports, "__esModule", ({ value: true }));
852
- exports.TSPLCommand = exports.CPCLCommand = exports.SingleCommand = void 0;
853
- /**
854
- * Single Command
855
- */
856
- const appendat_1 = __nccwpck_require__(718);
857
- const command_clause_1 = __nccwpck_require__(211);
858
- const toolkit_1 = __nccwpck_require__(6);
859
- class SingleCommand {
860
- /**
861
- * arguments
862
- * @private
863
- */
864
- _arguments;
865
- _symbolAfterHeader;
866
- _symbolBetweenArguments;
867
- _header;
868
- _charset;
869
- constructor(symbolAfterHeader, symbolBetweenArguments, charset) {
870
- this._arguments = [];
871
- this._symbolAfterHeader = symbolAfterHeader;
872
- this._symbolBetweenArguments = symbolBetweenArguments;
873
- this._charset = charset;
874
- }
875
- get getHeader() {
876
- return this._header;
877
- }
878
- get symbolAfterHeader() {
879
- return this._symbolAfterHeader;
880
- }
881
- get symbolBetweenArguments() {
882
- return this._symbolBetweenArguments;
883
- }
884
- header(header) {
885
- this._header = header;
886
- return this;
887
- }
888
- get charset() {
889
- return this._charset;
890
- }
891
- append(appendat) {
892
- if (!appendat.condition)
893
- return this;
894
- const argument = appendat.argument();
895
- if (!toolkit_1.Checker.truthy(argument))
896
- return this;
897
- this._arguments.push(argument);
898
- return this;
899
- }
900
- arguments() {
901
- return this._arguments;
902
- }
903
- }
904
- exports.SingleCommand = SingleCommand;
905
- class BasicStringSingleCommand extends SingleCommand {
906
- constructor(symbolAfterHeader, symbolBetweenArguments, charset) {
907
- super(symbolAfterHeader, symbolBetweenArguments, charset);
908
- }
909
- append(appendat) {
910
- const argument = appendat.argument();
911
- if (!toolkit_1.Checker.truthy(argument))
912
- return this;
913
- super.append(appendat);
914
- return this;
915
- }
916
- appendText(text) {
917
- return this.append(appendat_1.TextAppendat.create(text ?? '', {}));
918
- }
919
- appendNumber(num) {
920
- if (isNaN(num))
921
- return this;
922
- return this.append(appendat_1.TextAppendat.create((num ?? '').toString(), {}));
923
- }
924
- output() {
925
- let ret = '';
926
- if (toolkit_1.Checker.truthy(super.getHeader)) {
927
- ret += super.getHeader;
928
- ret += super.symbolAfterHeader;
929
- }
930
- const args = super.arguments();
931
- const len = args.length;
932
- let seq = 0;
933
- for (const arg of args) {
934
- seq += 1;
935
- if (!toolkit_1.Checker.truthy(arg))
936
- continue;
937
- ret += arg;
938
- if (seq < len) {
939
- ret += super.symbolBetweenArguments;
940
- }
941
- }
942
- return ret;
943
- }
944
- clause() {
945
- const output = this.output();
946
- if (!toolkit_1.Checker.truthy(output)) {
947
- return command_clause_1.CommandClause.none();
948
- }
949
- return command_clause_1.CommandClause.text(output, super.charset);
950
- }
951
- }
952
- class CPCLCommand extends BasicStringSingleCommand {
953
- constructor(header, charset) {
954
- super(' ', ' ', charset);
955
- super.header(header);
956
- }
957
- static with(header, charset) {
958
- return new CPCLCommand(header, charset);
959
- }
960
- append(appendat) {
961
- super.append(appendat);
962
- return this;
963
- }
964
- appendText(text) {
965
- super.appendText(text);
966
- return this;
967
- }
968
- appendNumber(num) {
969
- super.appendNumber(num);
970
- return this;
971
- }
972
- }
973
- exports.CPCLCommand = CPCLCommand;
974
- class TSPLCommand extends BasicStringSingleCommand {
975
- constructor(header, charset) {
976
- super(' ', ',', charset);
977
- super.header(header);
978
- }
979
- static with(header, charset) {
980
- return new TSPLCommand(header, charset);
981
- }
982
- append(appendat) {
983
- super.append(appendat);
984
- return this;
985
- }
986
- appendText(text) {
987
- super.appendText(text);
988
- return this;
989
- }
990
- appendNumber(num) {
991
- super.appendNumber(num);
992
- return this;
993
- }
994
- }
995
- exports.TSPLCommand = TSPLCommand;
996
-
997
-
998
- /***/ }),
999
-
1000
- /***/ 783:
1001
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
1002
-
1003
-
1004
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1005
- exports.DataWriteOperation = void 0;
1006
- /**
1007
- * Data write operation
1008
- */
1009
- const types_1 = __nccwpck_require__(482);
1010
- const adapter_1 = __nccwpck_require__(324);
1011
- const toolkit_1 = __nccwpck_require__(6);
1012
- class DataWriteOperation {
1013
- options;
1014
- binary;
1015
- connectedDevice;
1016
- constructor(
1017
- /**
1018
- * Write options
1019
- * @private
1020
- */
1021
- options,
1022
- /**
1023
- * Write binary
1024
- * @private
1025
- */
1026
- binary,
1027
- /**
1028
- * Connected device
1029
- * @private
1030
- */
1031
- connectedDevice) {
1032
- this.options = options;
1033
- this.binary = binary;
1034
- this.connectedDevice = connectedDevice;
1035
- }
1036
- async write() {
1037
- if (!this.options.enableChunkWrite) {
1038
- const reporter = await this.writData(this.binary);
1039
- this.doCallback(reporter, this.binary, 1, 1);
1040
- return reporter;
1041
- }
1042
- const writeData = Array.from(this.binary);
1043
- const parts = toolkit_1.CollectionKit.split(writeData, this.options.chunkSize);
1044
- const totalTimes = parts.length;
1045
- let currentTimes = 0;
1046
- for (const part of parts) {
1047
- currentTimes += 1;
1048
- const partBinary = new Uint8Array(part);
1049
- const reporter = await this.writData(partBinary);
1050
- const control = this.doCallback(reporter, partBinary, currentTimes, totalTimes);
1051
- if (control == types_1.WriteControl.STOP) {
1052
- reporter.controlExit = true;
1053
- return reporter;
1054
- }
1055
- if (!reporter.ok) {
1056
- return reporter;
1057
- }
1058
- }
1059
- return new adapter_1.WroteReporter(true, this.binary, false);
1060
- }
1061
- doCallback(reporter, binary, currentTimes, totalTimes) {
1062
- const callback = this.options.callback;
1063
- if (!callback)
1064
- return types_1.WriteControl.CONTINUE;
1065
- const dataWrote = new types_1.DataWrote(binary, currentTimes, totalTimes);
1066
- if (reporter.ok) {
1067
- return callback.success(dataWrote);
1068
- }
1069
- if (callback.failed) {
1070
- callback.failed(dataWrote, reporter.exception);
1071
- }
1072
- else {
1073
- console.log('no custom failed callback, full exception: ', reporter.exception);
1074
- }
1075
- return types_1.WriteControl.STOP;
1076
- }
1077
- async writData(binary) {
1078
- try {
1079
- await this.connectedDevice.write(binary);
1080
- return new adapter_1.WroteReporter(true, binary, false);
1081
- }
1082
- catch (e) {
1083
- return new adapter_1.WroteReporter(false, binary, false, e);
1084
- }
1085
- }
1086
- }
1087
- exports.DataWriteOperation = DataWriteOperation;
1088
-
1089
-
1090
- /***/ }),
1091
-
1092
- /***/ 932:
1093
- /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
1094
-
1095
-
1096
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1097
- if (k2 === undefined) k2 = k;
1098
- var desc = Object.getOwnPropertyDescriptor(m, k);
1099
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1100
- desc = { enumerable: true, get: function() { return m[k]; } };
1101
- }
1102
- Object.defineProperty(o, k2, desc);
1103
- }) : (function(o, m, k, k2) {
1104
- if (k2 === undefined) k2 = k;
1105
- o[k2] = m[k];
1106
- }));
1107
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
1108
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1109
- };
1110
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1111
- __exportStar(__nccwpck_require__(146), exports);
1112
- __exportStar(__nccwpck_require__(482), exports);
1113
- __exportStar(__nccwpck_require__(623), exports);
1114
- __exportStar(__nccwpck_require__(555), exports);
1115
-
1116
-
1117
- /***/ }),
1118
-
1119
- /***/ 831:
1120
- /***/ ((__unused_webpack_module, exports) => {
1121
-
1122
-
1123
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1124
- exports.HexOutput = void 0;
1125
- const DEF_MAX_LENGTH_OF_LINE = 32;
1126
- /**
1127
- * hex output
1128
- */
1129
- class HexOutput {
1130
- enableFormat;
1131
- spacing;
1132
- maxLengthOfLine;
1133
- // private format: boolean;
1134
- //
1135
- // private spacing: boolean;
1136
- //
1137
- // private maxLengthOfLine: number = DEF_MAX_LENGTH_OF_LINE;
1138
- constructor(
1139
- /**
1140
- * Is format
1141
- */
1142
- enableFormat,
1143
- /**
1144
- * Enable spacing between byte
1145
- */
1146
- spacing,
1147
- /**
1148
- * Max length of line
1149
- */
1150
- maxLengthOfLine = DEF_MAX_LENGTH_OF_LINE) {
1151
- this.enableFormat = enableFormat;
1152
- this.spacing = spacing;
1153
- this.maxLengthOfLine = maxLengthOfLine;
1154
- }
1155
- static def() {
1156
- return new HexOutput(false, false, DEF_MAX_LENGTH_OF_LINE);
1157
- }
1158
- static simple(format = true) {
1159
- return new HexOutput(format, true, DEF_MAX_LENGTH_OF_LINE);
1160
- }
1161
- static formatWithMaxLength(maxLengthOfLine) {
1162
- return new HexOutput(true, true, maxLengthOfLine);
1163
- }
1164
- /**
1165
- * Format binary
1166
- */
1167
- format(binary) {
1168
- // const hex = toHex(binary);
1169
- const hex = Array.from(binary, function (byte) {
1170
- return ('0' + (byte & 0xFF).toString(16)).slice(-2);
1171
- }).join('');
1172
- if (!this.enableFormat) {
1173
- return hex;
1174
- }
1175
- let fmted = '';
1176
- const textLength = hex.length;
1177
- let lineIndex = 0;
1178
- for (let ix = 0; ix < textLength; ix++) {
1179
- const seq = ix + 1;
1180
- const v = hex[ix];
1181
- fmted += v;
1182
- if (seq % 2 == 0 && this.spacing) {
1183
- if (seq < textLength) {
1184
- if (lineIndex + 1 < this.maxLengthOfLine) {
1185
- fmted += ' ';
1186
- }
1187
- lineIndex += 1;
1188
- }
1189
- }
1190
- if (lineIndex >= this.maxLengthOfLine) {
1191
- fmted += '\n';
1192
- lineIndex = 0;
1193
- }
1194
- }
1195
- return fmted;
1196
- }
1197
- }
1198
- exports.HexOutput = HexOutput;
1199
-
1200
-
1201
- /***/ }),
1202
-
1203
- /***/ 482:
1204
- /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
1205
-
1206
-
1207
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1208
- if (k2 === undefined) k2 = k;
1209
- var desc = Object.getOwnPropertyDescriptor(m, k);
1210
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1211
- desc = { enumerable: true, get: function() { return m[k]; } };
1212
- }
1213
- Object.defineProperty(o, k2, desc);
1214
- }) : (function(o, m, k, k2) {
1215
- if (k2 === undefined) k2 = k;
1216
- o[k2] = m[k];
1217
- }));
1218
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
1219
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1220
- };
1221
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1222
- __exportStar(__nccwpck_require__(164), exports);
1223
- __exportStar(__nccwpck_require__(831), exports);
1224
- __exportStar(__nccwpck_require__(331), exports);
1225
- __exportStar(__nccwpck_require__(614), exports);
1226
-
1227
-
1228
- /***/ }),
1229
-
1230
- /***/ 614:
1231
- /***/ ((__unused_webpack_module, exports) => {
1232
-
1233
-
1234
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1235
- exports.Lifecycle = void 0;
1236
- class Lifecycle {
1237
- connectedDevice;
1238
- constructor(
1239
- /**
1240
- * Connected device
1241
- */
1242
- connectedDevice) {
1243
- this.connectedDevice = connectedDevice;
1244
- }
1245
- }
1246
- exports.Lifecycle = Lifecycle;
1247
-
1248
-
1249
- /***/ }),
1250
-
1251
- /***/ 164:
1252
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
1253
-
1254
-
1255
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1256
- exports.PsdkConst = void 0;
1257
- const toolkit_1 = __nccwpck_require__(6);
1258
- const CR = '\r';
1259
- const LF = '\n';
1260
- const CRLF = `${CR}${LF}`;
1261
- /**
1262
- * constants
1263
- */
1264
- exports.PsdkConst = {
1265
- DEF_CHARSET: 'gbk',
1266
- CR,
1267
- LF,
1268
- CRLF,
1269
- QUOTE: '"',
1270
- DEF_NEWLINE_BINARY: toolkit_1.ByteKit.textToU8A(CRLF),
1271
- DEF_AUTHORS: ['fewensa <osuni@protonmail.com>'],
1272
- DEF_ENABLED_NEWLINE: true,
1273
- DEF_WRITE_CHUNK_SIZE: 512,
1274
- EMPTY_BYTES: new Uint8Array([]),
1275
- };
1276
-
1277
-
1278
- /***/ }),
1279
-
1280
- /***/ 331:
1281
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
1282
-
1283
-
1284
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1285
- exports.WriteControl = exports.DataWrote = exports.DataWrite = exports.IDataWriteCallback = exports.WriteOptions = void 0;
1286
- const psdk_const_1 = __nccwpck_require__(164);
1287
- /**
1288
- * Write to device options
1289
- */
1290
- class WriteOptions {
1291
- enableChunkWrite;
1292
- chunkSize;
1293
- callback;
1294
- constructor(
1295
- /**
1296
- * Enable data splitting
1297
- */
1298
- enableChunkWrite = true,
1299
- /**
1300
- * Part size
1301
- */
1302
- chunkSize = psdk_const_1.PsdkConst.DEF_WRITE_CHUNK_SIZE,
1303
- /**
1304
- * Data write callback
1305
- */
1306
- callback) {
1307
- this.enableChunkWrite = enableChunkWrite;
1308
- this.chunkSize = chunkSize;
1309
- this.callback = callback;
1310
- }
1311
- static def() {
1312
- return new WriteOptions(true, psdk_const_1.PsdkConst.DEF_WRITE_CHUNK_SIZE, undefined);
1313
- }
1314
- }
1315
- exports.WriteOptions = WriteOptions;
1316
- /**
1317
- * Data write callback
1318
- */
1319
- class IDataWriteCallback {
1320
- failed(data, exception) {
1321
- console.error(`Write data failed: ${exception.message}`);
1322
- }
1323
- }
1324
- exports.IDataWriteCallback = IDataWriteCallback;
1325
- /**
1326
- * Data write
1327
- */
1328
- class DataWrite {
1329
- binary;
1330
- currentTimes;
1331
- totalTimes;
1332
- constructor(
1333
- /**
1334
- * Wrote binary
1335
- */
1336
- binary,
1337
- /**
1338
- * Write current times
1339
- */
1340
- currentTimes,
1341
- /**
1342
- * Write total times
1343
- */
1344
- totalTimes) {
1345
- this.binary = binary;
1346
- this.currentTimes = currentTimes;
1347
- this.totalTimes = totalTimes;
1348
- }
1349
- }
1350
- exports.DataWrite = DataWrite;
1351
- /**
1352
- * Data wrote
1353
- */
1354
- class DataWrote extends DataWrite {
1355
- }
1356
- exports.DataWrote = DataWrote;
1357
- /**
1358
- * Write control
1359
- */
1360
- var WriteControl;
1361
- (function (WriteControl) {
1362
- WriteControl["CONTINUE"] = "CONTINUE";
1363
- WriteControl["STOP"] = "STOP";
1364
- })(WriteControl || (exports.WriteControl = WriteControl = {}));
1365
-
1366
-
1367
- /***/ }),
1368
-
1369
- /***/ 833:
1370
- /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
1371
-
1372
-
1373
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1374
- if (k2 === undefined) k2 = k;
1375
- var desc = Object.getOwnPropertyDescriptor(m, k);
1376
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1377
- desc = { enumerable: true, get: function() { return m[k]; } };
1378
- }
1379
- Object.defineProperty(o, k2, desc);
1380
- }) : (function(o, m, k, k2) {
1381
- if (k2 === undefined) k2 = k;
1382
- o[k2] = m[k];
1383
- }));
1384
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
1385
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1386
- };
1387
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1388
- __exportStar(__nccwpck_require__(324), exports);
1389
- __exportStar(__nccwpck_require__(932), exports);
1390
- __exportStar(__nccwpck_require__(6), exports);
1391
-
1392
-
1393
- /***/ }),
1394
-
1395
- /***/ 423:
1396
- /***/ ((__unused_webpack_module, exports) => {
1397
-
1398
-
1399
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1400
- exports.Base64 = exports.extendBuiltins = exports.extendUint8Array = exports.extendString = exports.toUint8Array = exports.fromUint8Array = exports.isValid = exports.decode = exports.btou = exports.encodeURL = exports.encodeURI = exports.encode = exports.utob = exports.toBase64 = exports.fromBase64 = exports.btoaPolyfill = exports.btoa = exports.atobPolyfill = exports.atob = exports.VERSION = exports.version = void 0;
1401
- // https://github.com/dankogai/js-base64/blob/main/base64.ts
1402
- /**
1403
- * base64.ts
1404
- *
1405
- * Licensed under the BSD 3-Clause License.
1406
- * http://opensource.org/licenses/BSD-3-Clause
1407
- *
1408
- * References:
1409
- * http://en.wikipedia.org/wiki/Base64
1410
- *
1411
- * @author Dan Kogai (https://github.com/dankogai)
1412
- */
1413
- const version = '3.7.7';
1414
- exports.version = version;
1415
- /**
1416
- * @deprecated use lowercase `version`.
1417
- */
1418
- const VERSION = version;
1419
- exports.VERSION = VERSION;
1420
- const _hasBuffer = typeof Buffer === 'function';
1421
- const _TD = typeof TextDecoder === 'function' ? new TextDecoder() : undefined;
1422
- const _TE = typeof TextEncoder === 'function' ? new TextEncoder() : undefined;
1423
- const b64ch = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
1424
- const b64chs = Array.prototype.slice.call(b64ch);
1425
- const b64tab = ((a) => {
1426
- let tab = {};
1427
- a.forEach((c, i) => tab[c] = i);
1428
- return tab;
1429
- })(b64chs);
1430
- const b64re = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
1431
- const _fromCC = String.fromCharCode.bind(String);
1432
- const _U8Afrom = typeof Uint8Array.from === 'function'
1433
- ? Uint8Array.from.bind(Uint8Array)
1434
- : (it) => new Uint8Array(Array.prototype.slice.call(it, 0));
1435
- const _mkUriSafe = (src) => src
1436
- .replace(/=/g, '').replace(/[+\/]/g, (m0) => m0 == '+' ? '-' : '_');
1437
- const _tidyB64 = (s) => s.replace(/[^A-Za-z0-9\+\/]/g, '');
1438
- /**
1439
- * polyfill version of `btoa`
1440
- */
1441
- const btoaPolyfill = (bin) => {
1442
- // console.log('polyfilled');
1443
- let u32, c0, c1, c2, asc = '';
1444
- const pad = bin.length % 3;
1445
- for (let i = 0; i < bin.length;) {
1446
- if ((c0 = bin.charCodeAt(i++)) > 255 ||
1447
- (c1 = bin.charCodeAt(i++)) > 255 ||
1448
- (c2 = bin.charCodeAt(i++)) > 255)
1449
- throw new TypeError('invalid character found');
1450
- u32 = (c0 << 16) | (c1 << 8) | c2;
1451
- asc += b64chs[u32 >> 18 & 63]
1452
- + b64chs[u32 >> 12 & 63]
1453
- + b64chs[u32 >> 6 & 63]
1454
- + b64chs[u32 & 63];
1455
- }
1456
- return pad ? asc.slice(0, pad - 3) + "===".substring(pad) : asc;
1457
- };
1458
- exports.btoaPolyfill = btoaPolyfill;
1459
- /**
1460
- * does what `window.btoa` of web browsers do.
1461
- * @param {String} bin binary string
1462
- * @returns {string} Base64-encoded string
1463
- */
1464
- const _btoa = typeof btoa === 'function' ? (bin) => btoa(bin)
1465
- : _hasBuffer ? (bin) => Buffer.from(bin, 'binary').toString('base64')
1466
- : btoaPolyfill;
1467
- exports.btoa = _btoa;
1468
- const _fromUint8Array = _hasBuffer
1469
- ? (u8a) => Buffer.from(u8a).toString('base64')
1470
- : (u8a) => {
1471
- // cf. https://stackoverflow.com/questions/12710001/how-to-convert-uint8-array-to-base64-encoded-string/12713326#12713326
1472
- const maxargs = 0x1000;
1473
- let strs = [];
1474
- for (let i = 0, l = u8a.length; i < l; i += maxargs) {
1475
- strs.push(_fromCC.apply(null, u8a.subarray(i, i + maxargs)));
1476
- }
1477
- return _btoa(strs.join(''));
1478
- };
1479
- /**
1480
- * converts a Uint8Array to a Base64 string.
1481
- * @param {boolean} [urlsafe] URL-and-filename-safe a la RFC4648 §5
1482
- * @returns {string} Base64 string
1483
- */
1484
- const fromUint8Array = (u8a, urlsafe = false) => urlsafe ? _mkUriSafe(_fromUint8Array(u8a)) : _fromUint8Array(u8a);
1485
- exports.fromUint8Array = fromUint8Array;
1486
- // This trick is found broken https://github.com/dankogai/js-base64/issues/130
1487
- // const utob = (src: string) => unescape(encodeURIComponent(src));
1488
- // reverting good old fationed regexp
1489
- const cb_utob = (c) => {
1490
- if (c.length < 2) {
1491
- var cc = c.charCodeAt(0);
1492
- return cc < 0x80 ? c
1493
- : cc < 0x800 ? (_fromCC(0xc0 | (cc >>> 6))
1494
- + _fromCC(0x80 | (cc & 0x3f)))
1495
- : (_fromCC(0xe0 | ((cc >>> 12) & 0x0f))
1496
- + _fromCC(0x80 | ((cc >>> 6) & 0x3f))
1497
- + _fromCC(0x80 | (cc & 0x3f)));
1498
- }
1499
- else {
1500
- var cc = 0x10000
1501
- + (c.charCodeAt(0) - 0xD800) * 0x400
1502
- + (c.charCodeAt(1) - 0xDC00);
1503
- return (_fromCC(0xf0 | ((cc >>> 18) & 0x07))
1504
- + _fromCC(0x80 | ((cc >>> 12) & 0x3f))
1505
- + _fromCC(0x80 | ((cc >>> 6) & 0x3f))
1506
- + _fromCC(0x80 | (cc & 0x3f)));
1507
- }
1508
- };
1509
- const re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
1510
- /**
1511
- * @deprecated should have been internal use only.
1512
- * @param {string} src UTF-8 string
1513
- * @returns {string} UTF-16 string
1514
- */
1515
- const utob = (u) => u.replace(re_utob, cb_utob);
1516
- exports.utob = utob;
1517
- //
1518
- const _encode = _hasBuffer
1519
- ? (s) => Buffer.from(s, 'utf8').toString('base64')
1520
- : _TE
1521
- ? (s) => _fromUint8Array(_TE.encode(s))
1522
- : (s) => _btoa(utob(s));
1523
- /**
1524
- * converts a UTF-8-encoded string to a Base64 string.
1525
- * @param {boolean} [urlsafe] if `true` make the result URL-safe
1526
- * @returns {string} Base64 string
1527
- */
1528
- const encode = (src, urlsafe = false) => urlsafe
1529
- ? _mkUriSafe(_encode(src))
1530
- : _encode(src);
1531
- exports.toBase64 = encode;
1532
- exports.encode = encode;
1533
- /**
1534
- * converts a UTF-8-encoded string to URL-safe Base64 RFC4648 §5.
1535
- * @returns {string} Base64 string
1536
- */
1537
- const encodeURI = (src) => encode(src, true);
1538
- exports.encodeURI = encodeURI;
1539
- exports.encodeURL = encodeURI;
1540
- // This trick is found broken https://github.com/dankogai/js-base64/issues/130
1541
- // const btou = (src: string) => decodeURIComponent(escape(src));
1542
- // reverting good old fationed regexp
1543
- const re_btou = /[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;
1544
- const cb_btou = (cccc) => {
1545
- switch (cccc.length) {
1546
- case 4:
1547
- var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
1548
- | ((0x3f & cccc.charCodeAt(1)) << 12)
1549
- | ((0x3f & cccc.charCodeAt(2)) << 6)
1550
- | (0x3f & cccc.charCodeAt(3)), offset = cp - 0x10000;
1551
- return (_fromCC((offset >>> 10) + 0xD800)
1552
- + _fromCC((offset & 0x3FF) + 0xDC00));
1553
- case 3:
1554
- return _fromCC(((0x0f & cccc.charCodeAt(0)) << 12)
1555
- | ((0x3f & cccc.charCodeAt(1)) << 6)
1556
- | (0x3f & cccc.charCodeAt(2)));
1557
- default:
1558
- return _fromCC(((0x1f & cccc.charCodeAt(0)) << 6)
1559
- | (0x3f & cccc.charCodeAt(1)));
1560
- }
1561
- };
1562
- /**
1563
- * @deprecated should have been internal use only.
1564
- * @param {string} src UTF-16 string
1565
- * @returns {string} UTF-8 string
1566
- */
1567
- const btou = (b) => b.replace(re_btou, cb_btou);
1568
- exports.btou = btou;
1569
- /**
1570
- * polyfill version of `atob`
1571
- */
1572
- const atobPolyfill = (asc) => {
1573
- // console.log('polyfilled');
1574
- asc = asc.replace(/\s+/g, '');
1575
- if (!b64re.test(asc))
1576
- throw new TypeError('malformed base64.');
1577
- asc += '=='.slice(2 - (asc.length & 3));
1578
- let u24, bin = '', r1, r2;
1579
- for (let i = 0; i < asc.length;) {
1580
- u24 = b64tab[asc.charAt(i++)] << 18
1581
- | b64tab[asc.charAt(i++)] << 12
1582
- | (r1 = b64tab[asc.charAt(i++)]) << 6
1583
- | (r2 = b64tab[asc.charAt(i++)]);
1584
- bin += r1 === 64 ? _fromCC(u24 >> 16 & 255)
1585
- : r2 === 64 ? _fromCC(u24 >> 16 & 255, u24 >> 8 & 255)
1586
- : _fromCC(u24 >> 16 & 255, u24 >> 8 & 255, u24 & 255);
1587
- }
1588
- return bin;
1589
- };
1590
- exports.atobPolyfill = atobPolyfill;
1591
- /**
1592
- * does what `window.atob` of web browsers do.
1593
- * @param {String} asc Base64-encoded string
1594
- * @returns {string} binary string
1595
- */
1596
- const _atob = typeof atob === 'function' ? (asc) => atob(_tidyB64(asc))
1597
- : _hasBuffer ? (asc) => Buffer.from(asc, 'base64').toString('binary')
1598
- : atobPolyfill;
1599
- exports.atob = _atob;
1600
- //
1601
- const _toUint8Array = _hasBuffer
1602
- ? (a) => _U8Afrom(Buffer.from(a, 'base64'))
1603
- : (a) => _U8Afrom(_atob(a).split('').map(c => c.charCodeAt(0)));
1604
- /**
1605
- * converts a Base64 string to a Uint8Array.
1606
- */
1607
- const toUint8Array = (a) => _toUint8Array(_unURI(a));
1608
- exports.toUint8Array = toUint8Array;
1609
- //
1610
- const _decode = _hasBuffer
1611
- ? (a) => Buffer.from(a, 'base64').toString('utf8')
1612
- : _TD
1613
- ? (a) => _TD.decode(_toUint8Array(a))
1614
- : (a) => btou(_atob(a));
1615
- const _unURI = (a) => _tidyB64(a.replace(/[-_]/g, (m0) => m0 == '-' ? '+' : '/'));
1616
- /**
1617
- * converts a Base64 string to a UTF-8 string.
1618
- * @param {String} src Base64 string. Both normal and URL-safe are supported
1619
- * @returns {string} UTF-8 string
1620
- */
1621
- const decode = (src) => _decode(_unURI(src));
1622
- exports.fromBase64 = decode;
1623
- exports.decode = decode;
1624
- /**
1625
- * check if a value is a valid Base64 string
1626
- * @param {String} src a value to check
1627
- */
1628
- const isValid = (src) => {
1629
- if (typeof src !== 'string')
1630
- return false;
1631
- const s = src.replace(/\s+/g, '').replace(/={0,2}$/, '');
1632
- return !/[^\s0-9a-zA-Z\+/]/.test(s) || !/[^\s0-9a-zA-Z\-_]/.test(s);
1633
- };
1634
- exports.isValid = isValid;
1635
- //
1636
- const _noEnum = (v) => {
1637
- return {
1638
- value: v, enumerable: false, writable: true, configurable: true
1639
- };
1640
- };
1641
- /**
1642
- * extend String.prototype with relevant methods
1643
- */
1644
- const extendString = function () {
1645
- const _add = (name, body) => Object.defineProperty(String.prototype, name, _noEnum(body));
1646
- _add('fromBase64', function () { return decode(this); });
1647
- _add('toBase64', function (urlsafe) { return encode(this, urlsafe); });
1648
- _add('toBase64URI', function () { return encode(this, true); });
1649
- _add('toBase64URL', function () { return encode(this, true); });
1650
- _add('toUint8Array', function () { return toUint8Array(this); });
1651
- };
1652
- exports.extendString = extendString;
1653
- /**
1654
- * extend Uint8Array.prototype with relevant methods
1655
- */
1656
- const extendUint8Array = function () {
1657
- const _add = (name, body) => Object.defineProperty(Uint8Array.prototype, name, _noEnum(body));
1658
- _add('toBase64', function (urlsafe) { return fromUint8Array(this, urlsafe); });
1659
- _add('toBase64URI', function () { return fromUint8Array(this, true); });
1660
- _add('toBase64URL', function () { return fromUint8Array(this, true); });
1661
- };
1662
- exports.extendUint8Array = extendUint8Array;
1663
- /**
1664
- * extend Builtin prototypes with relevant methods
1665
- */
1666
- const extendBuiltins = () => {
1667
- extendString();
1668
- extendUint8Array();
1669
- };
1670
- exports.extendBuiltins = extendBuiltins;
1671
- const gBase64 = {
1672
- version: version,
1673
- VERSION: VERSION,
1674
- atob: _atob,
1675
- atobPolyfill: atobPolyfill,
1676
- btoa: _btoa,
1677
- btoaPolyfill: btoaPolyfill,
1678
- fromBase64: decode,
1679
- toBase64: encode,
1680
- encode: encode,
1681
- encodeURI: encodeURI,
1682
- encodeURL: encodeURI,
1683
- utob: utob,
1684
- btou: btou,
1685
- decode: decode,
1686
- isValid: isValid,
1687
- fromUint8Array: fromUint8Array,
1688
- toUint8Array: toUint8Array,
1689
- extendString: extendString,
1690
- extendUint8Array: extendUint8Array,
1691
- extendBuiltins: extendBuiltins
1692
- };
1693
- exports.Base64 = gBase64;
1694
-
1695
-
1696
- /***/ }),
1697
-
1698
- /***/ 659:
1699
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
1700
-
1701
-
1702
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1703
- exports.ByteKit = void 0;
1704
- const checker_1 = __nccwpck_require__(192);
1705
- /**
1706
- * Byte kit
1707
- */
1708
- class ByteKit {
1709
- /**
1710
- * Text to byte
1711
- * @param text text
1712
- */
1713
- static textToU8A(text) {
1714
- if (!checker_1.Checker.truthy(text))
1715
- return new Uint8Array([]);
1716
- let bytes = [];
1717
- let len, c;
1718
- len = text.length;
1719
- for (let i = 0; i < len; i++) {
1720
- c = text.charCodeAt(i);
1721
- if (c >= 0x010000 && c <= 0x10FFFF) {
1722
- bytes.push(((c >> 18) & 0x07) | 0xF0);
1723
- bytes.push(((c >> 12) & 0x3F) | 0x80);
1724
- bytes.push(((c >> 6) & 0x3F) | 0x80);
1725
- bytes.push((c & 0x3F) | 0x80);
1726
- }
1727
- else if (c >= 0x000800 && c <= 0x00FFFF) {
1728
- bytes.push(((c >> 12) & 0x0F) | 0xE0);
1729
- bytes.push(((c >> 6) & 0x3F) | 0x80);
1730
- bytes.push((c & 0x3F) | 0x80);
1731
- }
1732
- else if (c >= 0x000080 && c <= 0x0007FF) {
1733
- bytes.push(((c >> 6) & 0x1F) | 0xC0);
1734
- bytes.push((c & 0x3F) | 0x80);
1735
- }
1736
- else {
1737
- bytes.push(c & 0xFF);
1738
- }
1739
- }
1740
- return new Uint8Array(bytes);
1741
- }
1742
- }
1743
- exports.ByteKit = ByteKit;
1744
-
1745
-
1746
- /***/ }),
1747
-
1748
- /***/ 192:
1749
- /***/ ((__unused_webpack_module, exports) => {
1750
-
1751
-
1752
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1753
- exports.Checker = void 0;
1754
- class Checker {
1755
- static truthy(value) {
1756
- if (value === undefined)
1757
- return false;
1758
- if (value === null)
1759
- return false;
1760
- if (value === '')
1761
- return false;
1762
- const t = typeof value;
1763
- switch (t) {
1764
- case 'number':
1765
- if (isNaN(value))
1766
- return false;
1767
- break;
1768
- case 'bigint':
1769
- default:
1770
- return true;
1771
- }
1772
- }
1773
- static empty(value) {
1774
- if (!Checker.truthy(value))
1775
- return true;
1776
- return value.length === 0;
1777
- }
1778
- }
1779
- exports.Checker = Checker;
1780
-
1781
-
1782
- /***/ }),
1783
-
1784
- /***/ 961:
1785
- /***/ ((__unused_webpack_module, exports) => {
1786
-
1787
-
1788
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1789
- exports.FastGBK = void 0;
1790
- // https://github.com/EtherDream/str2gbk/blob/main/index.js
1791
- let table;
1792
- function initGbkTable() {
1793
- // https://en.wikipedia.org/wiki/GBK_(character_encoding)#Encoding
1794
- const ranges = [
1795
- [0xA1, 0xA9, 0xA1, 0xFE],
1796
- [0xB0, 0xF7, 0xA1, 0xFE],
1797
- [0x81, 0xA0, 0x40, 0xFE],
1798
- [0xAA, 0xFE, 0x40, 0xA0],
1799
- [0xA8, 0xA9, 0x40, 0xA0],
1800
- [0xAA, 0xAF, 0xA1, 0xFE],
1801
- [0xF8, 0xFE, 0xA1, 0xFE],
1802
- [0xA1, 0xA7, 0x40, 0xA0],
1803
- ];
1804
- const codes = new Uint16Array(23940);
1805
- let i = 0;
1806
- for (const [b1Begin, b1End, b2Begin, b2End] of ranges) {
1807
- for (let b2 = b2Begin; b2 <= b2End; b2++) {
1808
- if (b2 !== 0x7F) {
1809
- for (let b1 = b1Begin; b1 <= b1End; b1++) {
1810
- codes[i++] = b2 << 8 | b1;
1811
- }
1812
- }
1813
- }
1814
- }
1815
- table = new Uint16Array(65536);
1816
- table.fill(0xFFFF);
1817
- const str = new TextDecoder('gbk').decode(codes);
1818
- for (let i = 0; i < str.length; i++) {
1819
- table[str.charCodeAt(i)] = codes[i];
1820
- }
1821
- }
1822
- // const NodeJsBufAlloc = typeof Buffer === 'function' && Buffer.allocUnsafe
1823
- //
1824
- // const defaultOnAlloc = NodeJsBufAlloc
1825
- // ? (len) => NodeJsBufAlloc(len)
1826
- // : (len) => new Uint8Array(len)
1827
- const defaultOnAlloc = (len) => new Uint8Array(len);
1828
- const defaultOnError = () => 63; // '?'
1829
- const gbkDecoder = new TextDecoder('gbk');
1830
- class FastGBK {
1831
- static decode(buffer) {
1832
- return gbkDecoder.decode(buffer);
1833
- }
1834
- static encode(text, options) {
1835
- if (!table) {
1836
- initGbkTable();
1837
- }
1838
- const onAlloc = options?.onAlloc ?? defaultOnAlloc;
1839
- const onError = options?.onError ?? defaultOnError;
1840
- const buf = onAlloc(text.length * 2);
1841
- let n = 0;
1842
- for (let i = 0; i < text.length; i++) {
1843
- const code = text.charCodeAt(i);
1844
- if (code < 0x80) {
1845
- buf[n++] = code;
1846
- continue;
1847
- }
1848
- const gbk = table[code];
1849
- if (gbk !== 0xFFFF) {
1850
- buf[n++] = gbk;
1851
- buf[n++] = gbk >> 8;
1852
- }
1853
- else if (code === 8364) {
1854
- // 8364 == '€'.charCodeAt(0)
1855
- // Code Page 936 has a single-byte euro sign at 0x80
1856
- buf[n++] = 0x80;
1857
- }
1858
- else {
1859
- const ret = onError(i, text);
1860
- if (ret === -1) {
1861
- break;
1862
- }
1863
- if (ret > 0xFF) {
1864
- buf[n++] = ret;
1865
- buf[n++] = ret >> 8;
1866
- }
1867
- else {
1868
- buf[n++] = ret;
1869
- }
1870
- }
1871
- }
1872
- return buf.subarray(0, n);
1873
- }
1874
- }
1875
- exports.FastGBK = FastGBK;
1876
-
1877
-
1878
- /***/ }),
1879
-
1880
- /***/ 6:
1881
- /***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
1882
-
1883
-
1884
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
1885
- if (k2 === undefined) k2 = k;
1886
- var desc = Object.getOwnPropertyDescriptor(m, k);
1887
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
1888
- desc = { enumerable: true, get: function() { return m[k]; } };
1889
- }
1890
- Object.defineProperty(o, k2, desc);
1891
- }) : (function(o, m, k, k2) {
1892
- if (k2 === undefined) k2 = k;
1893
- o[k2] = m[k];
1894
- }));
1895
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
1896
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
1897
- };
1898
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1899
- __exportStar(__nccwpck_require__(659), exports);
1900
- __exportStar(__nccwpck_require__(925), exports);
1901
- __exportStar(__nccwpck_require__(329), exports);
1902
- __exportStar(__nccwpck_require__(973), exports);
1903
- __exportStar(__nccwpck_require__(192), exports);
1904
- __exportStar(__nccwpck_require__(961), exports);
1905
-
1906
-
1907
- /***/ }),
1908
-
1909
- /***/ 329:
1910
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
1911
-
1912
-
1913
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1914
- exports.CollectionKit = void 0;
1915
- const checker_1 = __nccwpck_require__(192);
1916
- /**
1917
- * Collection kit
1918
- */
1919
- class CollectionKit {
1920
- /**
1921
- * Split array
1922
- *
1923
- * @param colls collections
1924
- * @param size The size of result array
1925
- * @return List
1926
- */
1927
- static split(colls, size) {
1928
- if (checker_1.Checker.empty(colls))
1929
- return [];
1930
- if (size <= 0)
1931
- throw new Error('The size must > 0');
1932
- const rets = [];
1933
- let items = [];
1934
- for (const coll of colls) {
1935
- items.push(coll);
1936
- if (size == items.length) {
1937
- rets.push(items);
1938
- items = [];
1939
- }
1940
- }
1941
- if (0 != items.length)
1942
- rets.push(items);
1943
- return rets;
1944
- }
1945
- /**
1946
- * Part array
1947
- *
1948
- * @param colls collections
1949
- * @param parts Part length
1950
- * @return List
1951
- */
1952
- static parts(colls, parts) {
1953
- if (checker_1.Checker.empty(colls)) {
1954
- return [];
1955
- }
1956
- if (parts <= 0)
1957
- throw new Error('The parts length must > 0');
1958
- if (colls.length <= parts) {
1959
- return [colls];
1960
- }
1961
- const rets = [];
1962
- let items = [];
1963
- const pnum = Math.floor(colls.length / parts);
1964
- for (const coll of colls) {
1965
- items.push(coll);
1966
- if (items.length == pnum) {
1967
- rets.push(items);
1968
- if (rets.length < parts)
1969
- items = [];
1970
- }
1971
- }
1972
- return rets;
1973
- }
1974
- }
1975
- exports.CollectionKit = CollectionKit;
1976
-
1977
-
1978
- /***/ }),
1979
-
1980
- /***/ 973:
1981
- /***/ ((__unused_webpack_module, exports) => {
1982
-
1983
-
1984
- Object.defineProperty(exports, "__esModule", ({ value: true }));
1985
- exports.ImageKit = void 0;
1986
- /**
1987
- * Image kit
1988
- */
1989
- class ImageKit {
1990
- /**
1991
- * process image
1992
- * @param canvas canvas
1993
- * @param width width
1994
- * @param height height
1995
- */
1996
- static processImage(canvas, width, height) {
1997
- const ctx = canvas.getContext('2d');
1998
- let eWidth = Math.floor((width % 8 === 0) ? (width / 8) : (width / 8 + 1));
1999
- let currentHeight = 0;
2000
- let index = 0;
2001
- const area = height * eWidth;
2002
- const bytes = []; // the bytes length is equals `area`
2003
- for (let b1 = 0; b1 < area; b1++) {
2004
- bytes[b1] = 0;
2005
- }
2006
- const imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
2007
- while (currentHeight < height) {
2008
- // let rowData = []; // the row data length is image height
2009
- let eightBitIndex = 0;
2010
- for (let x = 0; x < width; x++) {
2011
- eightBitIndex++;
2012
- if (eightBitIndex > 8) {
2013
- eightBitIndex = 1;
2014
- index++;
2015
- }
2016
- const n = 1 << 8 - eightBitIndex;
2017
- // const pixel = ctx.getImageData(x, currentHeight, 1, 1);
2018
- const pixels = ImageKit.fastExtractPixel(imgData, x, currentHeight, 1, 1);
2019
- const pixel = pixels[0];
2020
- // const rgba = pixel.data;
2021
- const red = pixel[0];
2022
- const green = pixel[1];
2023
- const blue = pixel[2];
2024
- if ((red + green + blue) / 3 < 128) {
2025
- bytes[index] = (bytes[index] | n);
2026
- }
2027
- }
2028
- index = eWidth * (currentHeight + 1);
2029
- currentHeight += 1;
2030
- }
2031
- return new Uint8Array(bytes);
2032
- }
2033
- static fastExtractPixel(imageData, x, y, w, h) {
2034
- let i, j;
2035
- let result = [];
2036
- let r, g, b, a;
2037
- const data = imageData.data;
2038
- for (j = 0; j < h; j++) {
2039
- let idx = (x + (y + j) * imageData.width) * 4; // get left most byte index for row at y + j
2040
- for (i = 0; i < w; i++) {
2041
- r = data[idx++];
2042
- g = data[idx++];
2043
- b = data[idx++];
2044
- a = data[idx++];
2045
- // do the processing
2046
- result.push([r, g, b, a]);
2047
- }
2048
- }
2049
- return result;
2050
- }
2051
- }
2052
- exports.ImageKit = ImageKit;
2053
-
2054
-
2055
- /***/ }),
2056
-
2057
- /***/ 925:
2058
- /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
2059
-
2060
-
2061
- Object.defineProperty(exports, "__esModule", ({ value: true }));
2062
- exports.PVariableKit = void 0;
2063
- const checker_1 = __nccwpck_require__(192);
2064
- class PVariableKit {
2065
- /**
2066
- * Replace variable
2067
- * @param text text
2068
- * @param variable variable
2069
- */
2070
- static replace(text, variable) {
2071
- if (!checker_1.Checker.truthy(text))
2072
- return text;
2073
- if (!checker_1.Checker.truthy(variable))
2074
- return text;
2075
- if (text.indexOf('{{') < 0 && text.indexOf('}}') < 0)
2076
- return text;
2077
- const regx = /[\\]?\{\{(?<varx>.*?)}}/gm;
2078
- const tmpMark = '__THIS_IS_MAGIC_MARK_FOR_HACK_REGEX_MATCH__';
2079
- while (true) {
2080
- const match = regx.exec(text);
2081
- if (match == null)
2082
- break;
2083
- const originDefined = match[0];
2084
- const originVarx = originDefined.replace('{{', '')
2085
- .replace('}}', '');
2086
- const varName = originVarx.trim();
2087
- const varValue = variable.get(varName) ?? '';
2088
- if (originDefined.startsWith('\\')) {
2089
- const tmpDefined = originDefined.replace('\\{{', tmpMark);
2090
- text = text.replace(originDefined, tmpDefined);
2091
- continue;
2092
- }
2093
- text = text.replace(originDefined, varValue);
2094
- }
2095
- text = text.replace(new RegExp(tmpMark, 'g'), '{{');
2096
- return text;
2097
- }
2098
- }
2099
- exports.PVariableKit = PVariableKit;
2100
-
2101
-
2102
- /***/ })
2103
-
2104
- /******/ });
2105
- /************************************************************************/
2106
- /******/ // The module cache
2107
- /******/ var __webpack_module_cache__ = {};
2108
- /******/
2109
- /******/ // The require function
2110
- /******/ function __nccwpck_require__(moduleId) {
2111
- /******/ // Check if module is in cache
2112
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
2113
- /******/ if (cachedModule !== undefined) {
2114
- /******/ return cachedModule.exports;
2115
- /******/ }
2116
- /******/ // Create a new module (and put it into the cache)
2117
- /******/ var module = __webpack_module_cache__[moduleId] = {
2118
- /******/ // no module.id needed
2119
- /******/ // no module.loaded needed
2120
- /******/ exports: {}
2121
- /******/ };
2122
- /******/
2123
- /******/ // Execute the module function
2124
- /******/ var threw = true;
2125
- /******/ try {
2126
- /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __nccwpck_require__);
2127
- /******/ threw = false;
2128
- /******/ } finally {
2129
- /******/ if(threw) delete __webpack_module_cache__[moduleId];
2130
- /******/ }
2131
- /******/
2132
- /******/ // Return the exports of the module
2133
- /******/ return module.exports;
2134
- /******/ }
2135
- /******/
2136
- /************************************************************************/
2137
- /******/ /* webpack/runtime/compat */
2138
- /******/
2139
- /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
2140
- /******/
2141
- /************************************************************************/
2142
- var __webpack_exports__ = {};
2143
- // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
2144
- (() => {
2145
- var exports = __webpack_exports__;
2146
-
2147
- Object.defineProperty(exports, "__esModule", ({ value: true }));
2148
- exports.DeviceFilter = exports.WebusbReadOptions = exports.Webusb = void 0;
2149
- const frame_father_1 = __nccwpck_require__(833);
2150
- class Webusb {
2151
- filters;
2152
- configuration;
2153
- interface;
2154
- readEndpoint;
2155
- writeEndpoint;
2156
- inputReadEndpoint;
2157
- inputWriteEndpoint;
2158
- state;
2159
- device;
2160
- constructor(options) {
2161
- if (options.filters.length == 0) {
2162
- throw new Error('Missing filters');
2163
- }
2164
- this.filters = options.filters;
2165
- this.configuration = options.configuration ?? 1;
2166
- this.interface = options.interface ?? 0;
2167
- this.state = frame_father_1.ConnectionState.DISCONNECTED;
2168
- this.inputReadEndpoint = options.readEndpoint ?? 2;
2169
- this.inputWriteEndpoint = options.writeEndpoint ?? 2;
2170
- }
2171
- static withFilter(filter) {
2172
- return this.withFilters([filter]);
2173
- }
2174
- static withFilters(filters) {
2175
- return new Webusb({ filters });
2176
- }
2177
- async connect() {
2178
- // @ts-ignore
2179
- if (!navigator.usb) {
2180
- throw new Error('Your browser not support webusb');
2181
- }
2182
- // @ts-ignore
2183
- const device = await navigator.usb.requestDevice({
2184
- filters: this.filters,
2185
- });
2186
- if (!device)
2187
- throw new Error('Failed to get device');
2188
- await device.open();
2189
- await device.selectConfiguration(this.configuration);
2190
- await device.claimInterface(device.configuration.interfaces[this.interface].interfaceNumber);
2191
- const alternates = device.configuration.interfaces[0].alternates[0];
2192
- const inEndpoints = alternates.endpoints.filter(endpoint => endpoint.direction === 'in');
2193
- const outEndpoints = alternates.endpoints.filter(endpoint => endpoint.direction === 'out');
2194
- this.readEndpoint = inEndpoints && inEndpoints.length ? inEndpoints[0].endpointNumber : this.inputReadEndpoint;
2195
- this.writeEndpoint = outEndpoints && outEndpoints.length ? outEndpoints[0].endpointNumber : this.inputWriteEndpoint;
2196
- this.state = frame_father_1.ConnectionState.CONNECTED;
2197
- // @ts-ignore
2198
- navigator.usb.addEventListener('connect', e => {
2199
- this.state = frame_father_1.ConnectionState.CONNECTED;
2200
- });
2201
- // @ts-ignore
2202
- navigator.usb.addEventListener('disconnect', e => {
2203
- this.state = frame_father_1.ConnectionState.DISCONNECTED;
2204
- });
2205
- this.device = device;
2206
- return await this.connectedDevice();
2207
- }
2208
- async connectedDevice() {
2209
- const _device = () => this.device;
2210
- const _connectionState = () => this.state;
2211
- const _readEndpoint = () => this.readEndpoint;
2212
- const _writeEndpoint = () => this.writeEndpoint;
2213
- return new class {
2214
- origin() {
2215
- return _device();
2216
- }
2217
- connectionState() {
2218
- const device = _device();
2219
- if (!device.opened) {
2220
- return frame_father_1.ConnectionState.DISCONNECTED;
2221
- }
2222
- return _connectionState();
2223
- }
2224
- deviceName() {
2225
- const device = _device();
2226
- return device.productName;
2227
- }
2228
- async disconnect() {
2229
- // todo: disconnect webusb
2230
- }
2231
- canRead() {
2232
- return true;
2233
- }
2234
- async read(options) {
2235
- const device = _device();
2236
- const _options = options ?? WebusbReadOptions.def();
2237
- const result = await device.transferIn(_readEndpoint(), _options.readLength);
2238
- const { status, data } = result;
2239
- if (status != 'ok') {
2240
- throw new Error(`[${status}]: Failed to read data. about status code you can read this https://developer.mozilla.org/en-US/docs/Web/API/USBInTransferResult`);
2241
- }
2242
- const arrs = [];
2243
- const len = data.byteLength;
2244
- for (let i = 0; i < len; i++) {
2245
- arrs.push(data.getUint8(i));
2246
- }
2247
- return new Uint8Array(arrs);
2248
- }
2249
- async write(data) {
2250
- const device = _device();
2251
- await device.transferOut(_writeEndpoint(), data);
2252
- }
2253
- flush() {
2254
- }
2255
- };
2256
- }
2257
- }
2258
- exports.Webusb = Webusb;
2259
- class WebusbReadOptions extends frame_father_1.ReadOptions {
2260
- _length;
2261
- constructor(options) {
2262
- super(options);
2263
- this._length = options?.length ?? 1024;
2264
- }
2265
- static def() {
2266
- return new WebusbReadOptions();
2267
- }
2268
- get readLength() {
2269
- return this._length;
2270
- }
2271
- }
2272
- exports.WebusbReadOptions = WebusbReadOptions;
2273
- class DeviceFilter {
2274
- vendorId;
2275
- productId;
2276
- constructor(options) {
2277
- this.vendorId = options.vendorId;
2278
- this.productId = options.productId;
2279
- }
2280
- }
2281
- exports.DeviceFilter = DeviceFilter;
2282
-
2283
- })();
2284
-
2285
- module.exports = __webpack_exports__;
2286
- /******/ })()
2287
- ;
1
+ require('./sourcemap-register.js');(()=>{"use strict";var e={245:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.FakeConnectedDevice=void 0;const n=r(569);const s=r(932);class FakeConnectedDevice{origin(){return"FAKE-DEVICE"}connectionState(){return n.ConnectionState.CONNECTED}deviceName(){return"FAKE-DEVICE"}async disconnect(){}canRead(){return true}async read(e){return s.PsdkConst.EMPTY_BYTES}async write(e){console.log("WRITE: ",e)}flush(){}}t.FakeConnectedDevice=FakeConnectedDevice},324:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;var s=Object.getOwnPropertyDescriptor(t,r);if(!s||("get"in s?!t.__esModule:s.writable||s.configurable)){s={enumerable:true,get:function(){return t[r]}}}Object.defineProperty(e,n,s)}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var s=this&&this.__exportStar||function(e,t){for(var r in e)if(r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r))n(t,e,r)};Object.defineProperty(t,"__esModule",{value:true});s(r(245),t);s(r(569),t)},569:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});t.ReadOptions=t.WroteReporter=t.ConnectionState=void 0;var r;(function(e){e["CONNECTED"]="CONNECTED";e["DISCONNECTED"]="DISCONNECTED"})(r||(t.ConnectionState=r={}));class WroteReporter{ok;binary;controlExit;exception;constructor(e,t,r,n){this.ok=e;this.binary=t;this.controlExit=r;this.exception=n}}t.WroteReporter=WroteReporter;class ReadOptions{timeout;constructor(e){this.timeout=e?.timeout}}t.ReadOptions=ReadOptions},555:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.PSDK=void 0;const n=r(482);const s=r(783);class PSDK{sversion(){return"0.2.67"}authors(){return n.PsdkConst.DEF_AUTHORS}raw(e){this.commander().pushArg(e);return this}variable(e,t){this.commander().variable(e,t);return this}command(){return this.commander().command()}clear(){this.commander().clear();return this}async write(e){const t=this.connectedDevice();if(!t)throw Error("It's seems you missing to set connectedDevice");e=e??n.WriteOptions.def();const r=this.command();const i=r.binary();const a=new s.DataWriteOperation(e,i,t);const o=await a.write();this.clear();return o}newline(){this.commander().newline();return this}push(e){this.commander().pushArg(e);return this}}t.PSDK=PSDK},101:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.BasicArg=void 0;const n=r(482);class BasicArg{newline(){return n.PsdkConst.DEF_ENABLED_NEWLINE}}t.BasicArg=BasicArg},12:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.OnlyTextHeaderArg=t.OnlyBinaryHeaderArg=t.EasyArg=void 0;const n=r(101);const s=r(623);class EasyArg extends n.BasicArg{prependClauses;appendClauses;constructor(){super();this.prependClauses=[];this.appendClauses=[]}append(e){this.appendClauses.push(...e.clauses());return this}prepend(e){this.prependClauses.push(...e.clauses());return this}clauses(){const e=this.clause();const t=[];if(e.type!==s.ClauseType.NONE){t.push(e);if(this.newline()){t.push(s.CommandClause.newline())}}return[...this.prependClauses,...t,...this.appendClauses]}clear(){this.prependClauses.splice(0,this.prependClauses.length);this.appendClauses.splice(0,this.appendClauses.length)}}t.EasyArg=EasyArg;class OnlyBinaryHeaderArg extends EasyArg{append(e){super.append(e);return this}prepend(e){super.prepend(e);return this}clause(){return s.CommandClause.binary(this.header())}newline(){return false}}t.OnlyBinaryHeaderArg=OnlyBinaryHeaderArg;class OnlyTextHeaderArg extends EasyArg{append(e){super.append(e);return this}prepend(e){super.prepend(e);return this}clause(){return s.CommandClause.text(this.header())}}t.OnlyTextHeaderArg=OnlyTextHeaderArg},666:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.RawMode=t.Raw=void 0;const n=r(12);const s=r(623);const i=r(482);class Raw extends n.EasyArg{_mode;_text;_charset;_binary;_newline=i.PsdkConst.DEF_ENABLED_NEWLINE;constructor(){super()}static text(e,t){const r=new Raw;r._mode=a.TEXT;r._text=e;r._charset=t?.charset??i.PsdkConst.DEF_CHARSET;r._newline=t?.newline??i.PsdkConst.DEF_ENABLED_NEWLINE;return r}static binary(e,t){const r=new Raw;r._mode=a.BINARY;r._binary=e;r._charset=t?.charset??i.PsdkConst.DEF_CHARSET;r._newline=t?.newline??i.PsdkConst.DEF_ENABLED_NEWLINE;return r}append(e){super.append(e);return this}prepend(e){super.prepend(e);return this}clause(){let e;switch(this._mode){case a.TEXT:e=s.CommandClause.text(this._text,this._charset);break;case a.BINARY:e=s.CommandClause.binary(this._binary);break;default:e=s.CommandClause.none();break}return e}header(){return i.PsdkConst.EMPTY_BYTES}newline(){return this._newline}}t.Raw=Raw;var a;(function(e){e["BINARY"]="BINARY";e["TEXT"]="TEXT"})(a||(t.RawMode=a={}))},146:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;var s=Object.getOwnPropertyDescriptor(t,r);if(!s||("get"in s?!t.__esModule:s.writable||s.configurable)){s={enumerable:true,get:function(){return t[r]}}}Object.defineProperty(e,n,s)}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var s=this&&this.__exportStar||function(e,t){for(var r in e)if(r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r))n(t,e,r)};Object.defineProperty(t,"__esModule",{value:true});s(r(101),t);s(r(12),t);s(r(666),t)},623:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;var s=Object.getOwnPropertyDescriptor(t,r);if(!s||("get"in s?!t.__esModule:s.writable||s.configurable)){s={enumerable:true,get:function(){return t[r]}}}Object.defineProperty(e,n,s)}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var s=this&&this.__exportStar||function(e,t){for(var r in e)if(r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r))n(t,e,r)};Object.defineProperty(t,"__esModule",{value:true});s(r(247),t);s(r(392),t);s(r(211),t);s(r(718),t);s(r(839),t);s(r(410),t)},247:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.DefaultCommand=t.BasicCommand=void 0;const n=r(482);const s=r(423);const i=r(211);const a=r(6);class BasicCommand{base64(){return s.Base64.fromUint8Array(this.binary())}}t.BasicCommand=BasicCommand;class DefaultCommand extends BasicCommand{bytes;constructor(e,t){super();let r=[];for(const s of e){switch(s.type){case i.ClauseType.TEXT:const e=a.PVariableKit.replace(s.text,t);const o=a.FastGBK.encode(e);const c=Array.prototype.slice.call(o,0);r=r.concat(c);break;case i.ClauseType.NEWLINE:case i.ClauseType.BINARY:const u=Array.from(s.binary??n.PsdkConst.EMPTY_BYTES);r=r.concat(u);break}}this.bytes=new Uint8Array(r)}binary(){return this.bytes}hex(e){return(e??n.HexOutput.def()).format(this.binary())}string(e){return a.FastGBK.decode(this.binary())}}t.DefaultCommand=DefaultCommand},211:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.CommandClause=t.ClauseType=void 0;const n=r(482);var s;(function(e){e["TEXT"]="TEXT";e["BINARY"]="BINARY";e["NEWLINE"]="NEWLINE";e["NONE"]="NONE"})(s||(t.ClauseType=s={}));class CommandClause{_type;_text;_charset;_binary;constructor(e,t,r,n){this._type=e;this._text=t;this._charset=r;this._binary=n}static text(e,t=n.PsdkConst.DEF_CHARSET){return new CommandClause(s.TEXT,e,t,undefined)}static binary(e){return new CommandClause(s.BINARY,undefined,undefined,e)}static newline(){return new CommandClause(s.NEWLINE,undefined,undefined,n.PsdkConst.DEF_NEWLINE_BINARY)}static none(){return new CommandClause(s.NONE,undefined,undefined,undefined)}get type(){return this._type}get text(){return this._text}get charset(){return this._charset}get binary(){return this._binary}}t.CommandClause=CommandClause},392:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.Commander=void 0;const n=r(211);const s=r(482);const i=r(247);class Commander{clauses;_variable;constructor(){this.clauses=[];this._variable=new Map}static make(){return new Commander}pushText(e,t){if(e.startsWith(s.PsdkConst.CRLF)){e=e.substring(2)}const r=n.CommandClause.text(e,t?.charset??s.PsdkConst.DEF_CHARSET);return this.pushClause(r,t?.newline??s.PsdkConst.DEF_ENABLED_NEWLINE)}pushBinary(e,t){const r=n.CommandClause.binary(e);return this.pushClause(r,t??s.PsdkConst.DEF_ENABLED_NEWLINE)}pushClause(e,t){this.clauses.push(e);if(t??s.PsdkConst.DEF_ENABLED_NEWLINE){this.clauses.push(n.CommandClause.newline())}return this}pushClauses(e){e.forEach((e=>this.pushClause(e,false)));return this}pushArg(e){this.pushClauses(e.clauses());return this}newline(){const e=n.CommandClause.newline();return this.pushClause(e,false)}variable(e,t){this._variable.set(e,t);return this}clear(){this.clauses.splice(0,this.clauses.length);this._variable.clear();return this}command(){return new i.DefaultCommand(this.clauses,this._variable)}}t.Commander=Commander},718:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.TextAppendat=t.Appendat=void 0;const n=r(6);class Appendat{_argument;_condition;_callback;constructor(e,t,r){this._argument=e;this._condition=t;this._callback=r}get condition(){return this._condition}callback(e){this._callback=e;return this}quote(){return this}argument(){if(!n.Checker.truthy(this._callback))return this._argument;if(!n.Checker.truthy(this._argument))return undefined;return this._callback.callback(this._argument)}}t.Appendat=Appendat;class TextAppendat extends Appendat{_quote;constructor(e,t,r){super(e,t??true,r);this._quote=false}static create(e,t){return new TextAppendat(e,t?.condition??true,new class{callback(e){const r=t?.callback;if(r){return r(e)}return e}})}callback(e){super.callback(e);return this}quote(){this._quote=true;return this}argument(){const e=super.argument();if(!n.Checker.truthy(e))return this._quote?'""':"";if(this._quote){return`"${e}"`}return e}}t.TextAppendat=TextAppendat},839:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.BinaryCommand=void 0;const n=r(211);const s=r(6);class BinaryCommand{binary;constructor(e){this.binary=e??[]}static make(){return new BinaryCommand}static with(e){const t=Array.from(e);return new BinaryCommand(t)}appendNumber(e){this.binary.push(e);return this}appendText(e,t){const r=s.FastGBK.encode(e);this.binary.push(...r);return this}appendU8A(e){const t=Array.from(e);this.binary=this.binary.concat(t);return this}output(){return new Uint8Array(this.binary)}clause(){const e=this.output();return n.CommandClause.binary(e)}}t.BinaryCommand=BinaryCommand},410:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.TSPLCommand=t.CPCLCommand=t.SingleCommand=void 0;const n=r(718);const s=r(211);const i=r(6);class SingleCommand{_arguments;_symbolAfterHeader;_symbolBetweenArguments;_header;_charset;constructor(e,t,r){this._arguments=[];this._symbolAfterHeader=e;this._symbolBetweenArguments=t;this._charset=r}get getHeader(){return this._header}get symbolAfterHeader(){return this._symbolAfterHeader}get symbolBetweenArguments(){return this._symbolBetweenArguments}header(e){this._header=e;return this}get charset(){return this._charset}append(e){if(!e.condition)return this;const t=e.argument();if(!i.Checker.truthy(t))return this;this._arguments.push(t);return this}arguments(){return this._arguments}}t.SingleCommand=SingleCommand;class BasicStringSingleCommand extends SingleCommand{constructor(e,t,r){super(e,t,r)}append(e){const t=e.argument();if(!i.Checker.truthy(t))return this;super.append(e);return this}appendText(e){return this.append(n.TextAppendat.create(e??"",{}))}appendNumber(e){if(isNaN(e))return this;return this.append(n.TextAppendat.create((e??"").toString(),{}))}output(){let e="";if(i.Checker.truthy(super.getHeader)){e+=super.getHeader;e+=super.symbolAfterHeader}const t=super.arguments();const r=t.length;let n=0;for(const s of t){n+=1;if(!i.Checker.truthy(s))continue;e+=s;if(n<r){e+=super.symbolBetweenArguments}}return e}clause(){const e=this.output();if(!i.Checker.truthy(e)){return s.CommandClause.none()}return s.CommandClause.text(e,super.charset)}}class CPCLCommand extends BasicStringSingleCommand{constructor(e,t){super(" "," ",t);super.header(e)}static with(e,t){return new CPCLCommand(e,t)}append(e){super.append(e);return this}appendText(e){super.appendText(e);return this}appendNumber(e){super.appendNumber(e);return this}}t.CPCLCommand=CPCLCommand;class TSPLCommand extends BasicStringSingleCommand{constructor(e,t){super(" ",",",t);super.header(e)}static with(e,t){return new TSPLCommand(e,t)}append(e){super.append(e);return this}appendText(e){super.appendText(e);return this}appendNumber(e){super.appendNumber(e);return this}}t.TSPLCommand=TSPLCommand},783:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.DataWriteOperation=void 0;const n=r(482);const s=r(324);const i=r(6);class DataWriteOperation{options;binary;connectedDevice;constructor(e,t,r){this.options=e;this.binary=t;this.connectedDevice=r}async write(){if(!this.options.enableChunkWrite){const e=await this.writData(this.binary);this.doCallback(e,this.binary,1,1);return e}const e=Array.from(this.binary);const t=i.CollectionKit.split(e,this.options.chunkSize);const r=t.length;let a=0;for(const e of t){a+=1;const t=new Uint8Array(e);const s=await this.writData(t);const i=this.doCallback(s,t,a,r);if(i==n.WriteControl.STOP){s.controlExit=true;return s}if(!s.ok){return s}}return new s.WroteReporter(true,this.binary,false)}doCallback(e,t,r,s){const i=this.options.callback;if(!i)return n.WriteControl.CONTINUE;const a=new n.DataWrote(t,r,s);if(e.ok){return i.success(a)}if(i.failed){i.failed(a,e.exception)}else{console.log("no custom failed callback, full exception: ",e.exception)}return n.WriteControl.STOP}async writData(e){try{await this.connectedDevice.write(e);return new s.WroteReporter(true,e,false)}catch(t){return new s.WroteReporter(false,e,false,t)}}}t.DataWriteOperation=DataWriteOperation},932:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;var s=Object.getOwnPropertyDescriptor(t,r);if(!s||("get"in s?!t.__esModule:s.writable||s.configurable)){s={enumerable:true,get:function(){return t[r]}}}Object.defineProperty(e,n,s)}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var s=this&&this.__exportStar||function(e,t){for(var r in e)if(r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r))n(t,e,r)};Object.defineProperty(t,"__esModule",{value:true});s(r(146),t);s(r(482),t);s(r(623),t);s(r(555),t)},831:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});t.HexOutput=void 0;const r=32;class HexOutput{enableFormat;spacing;maxLengthOfLine;constructor(e,t,n=r){this.enableFormat=e;this.spacing=t;this.maxLengthOfLine=n}static def(){return new HexOutput(false,false,r)}static simple(e=true){return new HexOutput(e,true,r)}static formatWithMaxLength(e){return new HexOutput(true,true,e)}format(e){const t=Array.from(e,(function(e){return("0"+(e&255).toString(16)).slice(-2)})).join("");if(!this.enableFormat){return t}let r="";const n=t.length;let s=0;for(let e=0;e<n;e++){const i=e+1;const a=t[e];r+=a;if(i%2==0&&this.spacing){if(i<n){if(s+1<this.maxLengthOfLine){r+=" "}s+=1}}if(s>=this.maxLengthOfLine){r+="\n";s=0}}return r}}t.HexOutput=HexOutput},482:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;var s=Object.getOwnPropertyDescriptor(t,r);if(!s||("get"in s?!t.__esModule:s.writable||s.configurable)){s={enumerable:true,get:function(){return t[r]}}}Object.defineProperty(e,n,s)}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var s=this&&this.__exportStar||function(e,t){for(var r in e)if(r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r))n(t,e,r)};Object.defineProperty(t,"__esModule",{value:true});s(r(164),t);s(r(831),t);s(r(331),t);s(r(614),t)},614:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});t.Lifecycle=void 0;class Lifecycle{connectedDevice;constructor(e){this.connectedDevice=e}}t.Lifecycle=Lifecycle},164:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.PsdkConst=void 0;const n=r(6);const s="\r";const i="\n";const a=`${s}${i}`;t.PsdkConst={DEF_CHARSET:"gbk",CR:s,LF:i,CRLF:a,QUOTE:'"',DEF_NEWLINE_BINARY:n.ByteKit.textToU8A(a),DEF_AUTHORS:["fewensa <osuni@protonmail.com>"],DEF_ENABLED_NEWLINE:true,DEF_WRITE_CHUNK_SIZE:512,EMPTY_BYTES:new Uint8Array([])}},331:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.WriteControl=t.DataWrote=t.DataWrite=t.IDataWriteCallback=t.WriteOptions=void 0;const n=r(164);class WriteOptions{enableChunkWrite;chunkSize;callback;constructor(e=true,t=n.PsdkConst.DEF_WRITE_CHUNK_SIZE,r){this.enableChunkWrite=e;this.chunkSize=t;this.callback=r}static def(){return new WriteOptions(true,n.PsdkConst.DEF_WRITE_CHUNK_SIZE,undefined)}}t.WriteOptions=WriteOptions;class IDataWriteCallback{failed(e,t){console.error(`Write data failed: ${t.message}`)}}t.IDataWriteCallback=IDataWriteCallback;class DataWrite{binary;currentTimes;totalTimes;constructor(e,t,r){this.binary=e;this.currentTimes=t;this.totalTimes=r}}t.DataWrite=DataWrite;class DataWrote extends DataWrite{}t.DataWrote=DataWrote;var s;(function(e){e["CONTINUE"]="CONTINUE";e["STOP"]="STOP"})(s||(t.WriteControl=s={}))},833:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;var s=Object.getOwnPropertyDescriptor(t,r);if(!s||("get"in s?!t.__esModule:s.writable||s.configurable)){s={enumerable:true,get:function(){return t[r]}}}Object.defineProperty(e,n,s)}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var s=this&&this.__exportStar||function(e,t){for(var r in e)if(r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r))n(t,e,r)};Object.defineProperty(t,"__esModule",{value:true});s(r(324),t);s(r(932),t);s(r(6),t)},423:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});t.Base64=t.extendBuiltins=t.extendUint8Array=t.extendString=t.toUint8Array=t.fromUint8Array=t.isValid=t.decode=t.btou=t.encodeURL=t.encodeURI=t.encode=t.utob=t.toBase64=t.fromBase64=t.btoaPolyfill=t.btoa=t.atobPolyfill=t.atob=t.VERSION=t.version=void 0;const r="3.7.7";t.version=r;const n=r;t.VERSION=n;const s=typeof Buffer==="function";const i=typeof TextDecoder==="function"?new TextDecoder:undefined;const a=typeof TextEncoder==="function"?new TextEncoder:undefined;const o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";const c=Array.prototype.slice.call(o);const u=(e=>{let t={};e.forEach(((e,r)=>t[e]=r));return t})(c);const l=/^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;const d=String.fromCharCode.bind(String);const p=typeof Uint8Array.from==="function"?Uint8Array.from.bind(Uint8Array):e=>new Uint8Array(Array.prototype.slice.call(e,0));const _mkUriSafe=e=>e.replace(/=/g,"").replace(/[+\/]/g,(e=>e=="+"?"-":"_"));const _tidyB64=e=>e.replace(/[^A-Za-z0-9\+\/]/g,"");const btoaPolyfill=e=>{let t,r,n,s,i="";const a=e.length%3;for(let a=0;a<e.length;){if((r=e.charCodeAt(a++))>255||(n=e.charCodeAt(a++))>255||(s=e.charCodeAt(a++))>255)throw new TypeError("invalid character found");t=r<<16|n<<8|s;i+=c[t>>18&63]+c[t>>12&63]+c[t>>6&63]+c[t&63]}return a?i.slice(0,a-3)+"===".substring(a):i};t.btoaPolyfill=btoaPolyfill;const h=typeof btoa==="function"?e=>btoa(e):s?e=>Buffer.from(e,"binary").toString("base64"):btoaPolyfill;t.btoa=h;const f=s?e=>Buffer.from(e).toString("base64"):e=>{const t=4096;let r=[];for(let n=0,s=e.length;n<s;n+=t){r.push(d.apply(null,e.subarray(n,n+t)))}return h(r.join(""))};const fromUint8Array=(e,t=false)=>t?_mkUriSafe(f(e)):f(e);t.fromUint8Array=fromUint8Array;const cb_utob=e=>{if(e.length<2){var t=e.charCodeAt(0);return t<128?e:t<2048?d(192|t>>>6)+d(128|t&63):d(224|t>>>12&15)+d(128|t>>>6&63)+d(128|t&63)}else{var t=65536+(e.charCodeAt(0)-55296)*1024+(e.charCodeAt(1)-56320);return d(240|t>>>18&7)+d(128|t>>>12&63)+d(128|t>>>6&63)+d(128|t&63)}};const b=/[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;const utob=e=>e.replace(b,cb_utob);t.utob=utob;const m=s?e=>Buffer.from(e,"utf8").toString("base64"):a?e=>f(a.encode(e)):e=>h(utob(e));const encode=(e,t=false)=>t?_mkUriSafe(m(e)):m(e);t.toBase64=encode;t.encode=encode;const encodeURI=e=>encode(e,true);t.encodeURI=encodeURI;t.encodeURL=encodeURI;const _=/[\xC0-\xDF][\x80-\xBF]|[\xE0-\xEF][\x80-\xBF]{2}|[\xF0-\xF7][\x80-\xBF]{3}/g;const cb_btou=e=>{switch(e.length){case 4:var t=(7&e.charCodeAt(0))<<18|(63&e.charCodeAt(1))<<12|(63&e.charCodeAt(2))<<6|63&e.charCodeAt(3),r=t-65536;return d((r>>>10)+55296)+d((r&1023)+56320);case 3:return d((15&e.charCodeAt(0))<<12|(63&e.charCodeAt(1))<<6|63&e.charCodeAt(2));default:return d((31&e.charCodeAt(0))<<6|63&e.charCodeAt(1))}};const btou=e=>e.replace(_,cb_btou);t.btou=btou;const atobPolyfill=e=>{e=e.replace(/\s+/g,"");if(!l.test(e))throw new TypeError("malformed base64.");e+="==".slice(2-(e.length&3));let t,r="",n,s;for(let i=0;i<e.length;){t=u[e.charAt(i++)]<<18|u[e.charAt(i++)]<<12|(n=u[e.charAt(i++)])<<6|(s=u[e.charAt(i++)]);r+=n===64?d(t>>16&255):s===64?d(t>>16&255,t>>8&255):d(t>>16&255,t>>8&255,t&255)}return r};t.atobPolyfill=atobPolyfill;const y=typeof atob==="function"?e=>atob(_tidyB64(e)):s?e=>Buffer.from(e,"base64").toString("binary"):atobPolyfill;t.atob=y;const C=s?e=>p(Buffer.from(e,"base64")):e=>p(y(e).split("").map((e=>e.charCodeAt(0))));const toUint8Array=e=>C(_unURI(e));t.toUint8Array=toUint8Array;const g=s?e=>Buffer.from(e,"base64").toString("utf8"):i?e=>i.decode(C(e)):e=>btou(y(e));const _unURI=e=>_tidyB64(e.replace(/[-_]/g,(e=>e=="-"?"+":"/")));const decode=e=>g(_unURI(e));t.fromBase64=decode;t.decode=decode;const isValid=e=>{if(typeof e!=="string")return false;const t=e.replace(/\s+/g,"").replace(/={0,2}$/,"");return!/[^\s0-9a-zA-Z\+/]/.test(t)||!/[^\s0-9a-zA-Z\-_]/.test(t)};t.isValid=isValid;const _noEnum=e=>({value:e,enumerable:false,writable:true,configurable:true});const extendString=function(){const _add=(e,t)=>Object.defineProperty(String.prototype,e,_noEnum(t));_add("fromBase64",(function(){return decode(this)}));_add("toBase64",(function(e){return encode(this,e)}));_add("toBase64URI",(function(){return encode(this,true)}));_add("toBase64URL",(function(){return encode(this,true)}));_add("toUint8Array",(function(){return toUint8Array(this)}))};t.extendString=extendString;const extendUint8Array=function(){const _add=(e,t)=>Object.defineProperty(Uint8Array.prototype,e,_noEnum(t));_add("toBase64",(function(e){return fromUint8Array(this,e)}));_add("toBase64URI",(function(){return fromUint8Array(this,true)}));_add("toBase64URL",(function(){return fromUint8Array(this,true)}))};t.extendUint8Array=extendUint8Array;const extendBuiltins=()=>{extendString();extendUint8Array()};t.extendBuiltins=extendBuiltins;const E={version:r,VERSION:n,atob:y,atobPolyfill:atobPolyfill,btoa:h,btoaPolyfill:btoaPolyfill,fromBase64:decode,toBase64:encode,encode:encode,encodeURI:encodeURI,encodeURL:encodeURI,utob:utob,btou:btou,decode:decode,isValid:isValid,fromUint8Array:fromUint8Array,toUint8Array:toUint8Array,extendString:extendString,extendUint8Array:extendUint8Array,extendBuiltins:extendBuiltins};t.Base64=E},659:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.ByteKit=void 0;const n=r(192);class ByteKit{static textToU8A(e){if(!n.Checker.truthy(e))return new Uint8Array([]);let t=[];let r,s;r=e.length;for(let n=0;n<r;n++){s=e.charCodeAt(n);if(s>=65536&&s<=1114111){t.push(s>>18&7|240);t.push(s>>12&63|128);t.push(s>>6&63|128);t.push(s&63|128)}else if(s>=2048&&s<=65535){t.push(s>>12&15|224);t.push(s>>6&63|128);t.push(s&63|128)}else if(s>=128&&s<=2047){t.push(s>>6&31|192);t.push(s&63|128)}else{t.push(s&255)}}return new Uint8Array(t)}}t.ByteKit=ByteKit},192:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});t.Checker=void 0;class Checker{static truthy(e){if(e===undefined)return false;if(e===null)return false;if(e==="")return false;const t=typeof e;switch(t){case"number":if(isNaN(e))return false;break;case"bigint":default:return true}}static empty(e){if(!Checker.truthy(e))return true;return e.length===0}}t.Checker=Checker},961:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});t.FastGBK=void 0;let r;function initGbkTable(){const e=[[161,169,161,254],[176,247,161,254],[129,160,64,254],[170,254,64,160],[168,169,64,160],[170,175,161,254],[248,254,161,254],[161,167,64,160]];const t=new Uint16Array(23940);let n=0;for(const[r,s,i,a]of e){for(let e=i;e<=a;e++){if(e!==127){for(let i=r;i<=s;i++){t[n++]=e<<8|i}}}}r=new Uint16Array(65536);r.fill(65535);const s=new TextDecoder("gbk").decode(t);for(let e=0;e<s.length;e++){r[s.charCodeAt(e)]=t[e]}}const defaultOnAlloc=e=>new Uint8Array(e);const defaultOnError=()=>63;const n=new TextDecoder("gbk");class FastGBK{static decode(e){return n.decode(e)}static encode(e,t){if(!r){initGbkTable()}const n=t?.onAlloc??defaultOnAlloc;const s=t?.onError??defaultOnError;const i=n(e.length*2);let a=0;for(let t=0;t<e.length;t++){const n=e.charCodeAt(t);if(n<128){i[a++]=n;continue}const o=r[n];if(o!==65535){i[a++]=o;i[a++]=o>>8}else if(n===8364){i[a++]=128}else{const r=s(t,e);if(r===-1){break}if(r>255){i[a++]=r;i[a++]=r>>8}else{i[a++]=r}}}return i.subarray(0,a)}}t.FastGBK=FastGBK},6:function(e,t,r){var n=this&&this.__createBinding||(Object.create?function(e,t,r,n){if(n===undefined)n=r;var s=Object.getOwnPropertyDescriptor(t,r);if(!s||("get"in s?!t.__esModule:s.writable||s.configurable)){s={enumerable:true,get:function(){return t[r]}}}Object.defineProperty(e,n,s)}:function(e,t,r,n){if(n===undefined)n=r;e[n]=t[r]});var s=this&&this.__exportStar||function(e,t){for(var r in e)if(r!=="default"&&!Object.prototype.hasOwnProperty.call(t,r))n(t,e,r)};Object.defineProperty(t,"__esModule",{value:true});s(r(659),t);s(r(925),t);s(r(329),t);s(r(973),t);s(r(192),t);s(r(961),t)},329:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.CollectionKit=void 0;const n=r(192);class CollectionKit{static split(e,t){if(n.Checker.empty(e))return[];if(t<=0)throw new Error("The size must > 0");const r=[];let s=[];for(const n of e){s.push(n);if(t==s.length){r.push(s);s=[]}}if(0!=s.length)r.push(s);return r}static parts(e,t){if(n.Checker.empty(e)){return[]}if(t<=0)throw new Error("The parts length must > 0");if(e.length<=t){return[e]}const r=[];let s=[];const i=Math.floor(e.length/t);for(const n of e){s.push(n);if(s.length==i){r.push(s);if(r.length<t)s=[]}}return r}}t.CollectionKit=CollectionKit},973:(e,t)=>{Object.defineProperty(t,"__esModule",{value:true});t.ImageKit=void 0;class ImageKit{static processImage(e,t,r){const n=e.getContext("2d");let s=Math.floor(t%8===0?t/8:t/8+1);let i=0;let a=0;const o=r*s;const c=[];for(let e=0;e<o;e++){c[e]=0}const u=n.getImageData(0,0,e.width,e.height);while(i<r){let e=0;for(let r=0;r<t;r++){e++;if(e>8){e=1;a++}const t=1<<8-e;const n=ImageKit.fastExtractPixel(u,r,i,1,1);const s=n[0];const o=s[0];const l=s[1];const d=s[2];if((o+l+d)/3<128){c[a]=c[a]|t}}a=s*(i+1);i+=1}return new Uint8Array(c)}static fastExtractPixel(e,t,r,n,s){let i,a;let o=[];let c,u,l,d;const p=e.data;for(a=0;a<s;a++){let s=(t+(r+a)*e.width)*4;for(i=0;i<n;i++){c=p[s++];u=p[s++];l=p[s++];d=p[s++];o.push([c,u,l,d])}}return o}}t.ImageKit=ImageKit},925:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:true});t.PVariableKit=void 0;const n=r(192);class PVariableKit{static replace(e,t){if(!n.Checker.truthy(e))return e;if(!n.Checker.truthy(t))return e;if(e.indexOf("{{")<0&&e.indexOf("}}")<0)return e;const r=/[\\]?\{\{(?<varx>.*?)}}/gm;const s="__THIS_IS_MAGIC_MARK_FOR_HACK_REGEX_MATCH__";while(true){const n=r.exec(e);if(n==null)break;const i=n[0];const a=i.replace("{{","").replace("}}","");const o=a.trim();const c=t.get(o)??"";if(i.startsWith("\\")){const t=i.replace("\\{{",s);e=e.replace(i,t);continue}e=e.replace(i,c)}e=e.replace(new RegExp(s,"g"),"{{");return e}}t.PVariableKit=PVariableKit}};var t={};function __nccwpck_require__(r){var n=t[r];if(n!==undefined){return n.exports}var s=t[r]={exports:{}};var i=true;try{e[r].call(s.exports,s,s.exports,__nccwpck_require__);i=false}finally{if(i)delete t[r]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var r={};(()=>{var e=r;Object.defineProperty(e,"__esModule",{value:true});e.DeviceFilter=e.WebusbReadOptions=e.Webusb=void 0;const t=__nccwpck_require__(833);class Webusb{filters;configuration;interface;readEndpoint;writeEndpoint;inputReadEndpoint;inputWriteEndpoint;state;device;constructor(e){if(e.filters.length==0){throw new Error("Missing filters")}this.filters=e.filters;this.configuration=e.configuration??1;this.interface=e.interface??0;this.state=t.ConnectionState.DISCONNECTED;this.inputReadEndpoint=e.readEndpoint??2;this.inputWriteEndpoint=e.writeEndpoint??2}static withFilter(e){return this.withFilters([e])}static withFilters(e){return new Webusb({filters:e})}async connect(){if(!navigator.usb){throw new Error("Your browser not support webusb")}const e=await navigator.usb.requestDevice({filters:this.filters});if(!e)throw new Error("Failed to get device");await e.open();await e.selectConfiguration(this.configuration);await e.claimInterface(e.configuration.interfaces[this.interface].interfaceNumber);const r=e.configuration.interfaces[0].alternates[0];const n=r.endpoints.filter((e=>e.direction==="in"));const s=r.endpoints.filter((e=>e.direction==="out"));this.readEndpoint=n&&n.length?n[0].endpointNumber:this.inputReadEndpoint;this.writeEndpoint=s&&s.length?s[0].endpointNumber:this.inputWriteEndpoint;this.state=t.ConnectionState.CONNECTED;navigator.usb.addEventListener("connect",(e=>{this.state=t.ConnectionState.CONNECTED}));navigator.usb.addEventListener("disconnect",(e=>{this.state=t.ConnectionState.DISCONNECTED}));this.device=e;return await this.connectedDevice()}async connectedDevice(){const _device=()=>this.device;const _connectionState=()=>this.state;const _readEndpoint=()=>this.readEndpoint;const _writeEndpoint=()=>this.writeEndpoint;return new class{origin(){return _device()}connectionState(){const e=_device();if(!e.opened){return t.ConnectionState.DISCONNECTED}return _connectionState()}deviceName(){const e=_device();return e.productName}async disconnect(){}canRead(){return true}async read(e){const t=_device();const r=e??WebusbReadOptions.def();const n=await t.transferIn(_readEndpoint(),r.readLength);const{status:s,data:i}=n;if(s!="ok"){throw new Error(`[${s}]: Failed to read data. about status code you can read this https://developer.mozilla.org/en-US/docs/Web/API/USBInTransferResult`)}const a=[];const o=i.byteLength;for(let e=0;e<o;e++){a.push(i.getUint8(e))}return new Uint8Array(a)}async write(e){const t=_device();await t.transferOut(_writeEndpoint(),e)}flush(){}}}}e.Webusb=Webusb;class WebusbReadOptions extends t.ReadOptions{_length;constructor(e){super(e);this._length=e?.length??1024}static def(){return new WebusbReadOptions}get readLength(){return this._length}}e.WebusbReadOptions=WebusbReadOptions;class DeviceFilter{vendorId;productId;constructor(e){this.vendorId=e.vendorId;this.productId=e.productId}}e.DeviceFilter=DeviceFilter})();module.exports=r})();
2288
2
  //# sourceMappingURL=index.js.map