usb 2.4.1 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitmodules +2 -2
- package/CHANGELOG.md +15 -0
- package/README.md +34 -0
- package/binding.gyp +48 -24
- package/dist/usb/bindings.d.ts +1 -0
- package/dist/usb/endpoint.d.ts +1 -1
- package/dist/usb/endpoint.js +4 -2
- package/dist/usb/endpoint.js.map +1 -1
- package/dist/usb/index.d.ts +2 -0
- package/dist/usb/index.js +25 -13
- package/dist/usb/index.js.map +1 -1
- package/package.json +1 -1
- package/prebuilds/android-arm/node.napi.armv7.node +0 -0
- package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
- package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/linux-ia32/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/device.cc +309 -309
- package/src/helpers.h +36 -36
- package/src/hotplug/hotplug.h +22 -0
- package/src/hotplug/libusb.cc +91 -0
- package/src/hotplug/windows.cc +160 -0
- package/src/node_usb.cc +247 -281
- package/src/node_usb.h +64 -67
- package/src/thread_name.cc +79 -0
- package/src/thread_name.h +11 -0
- package/src/transfer.cc +114 -114
- package/test/usb.coffee +178 -178
- package/test/webusb.coffee +140 -140
- package/tsc/usb/bindings.ts +1 -0
- package/tsc/usb/endpoint.ts +4 -3
- package/tsc/usb/index.ts +30 -12
package/.gitmodules
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
[submodule "libusb"]
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
path = libusb
|
|
3
|
+
url = https://github.com/libusb/libusb.git
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2.5.0] - 2022-07-30
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Native USB device plug/unplug detection on Windows - [`524`](https://github.com/node-usb/node-usb/pull/524) ([Julian Waller](https://github.com/Julusian))
|
|
7
|
+
|
|
8
|
+
## [2.4.3] - 2022-06-21
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Fixed poll transfer tracking - [`522`](https://github.com/node-usb/node-usb/pull/522) ([Rob Moran](https://github.com/thegecko))
|
|
12
|
+
|
|
13
|
+
## [2.4.2] - 2022-05-27
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- Fixed multiple events with device detection on Windows - [`512`](https://github.com/node-usb/node-usb/pull/512) ([Alba Mendez](https://github.com/mildsunrise))
|
|
17
|
+
|
|
3
18
|
## [2.4.1] - 2022-05-07
|
|
4
19
|
|
|
5
20
|
### Fixed
|
package/README.md
CHANGED
|
@@ -547,6 +547,40 @@ Restore (re-reference) the hotplug events unreferenced by `unrefHotplugEvents()`
|
|
|
547
547
|
#### usb.unrefHotplugEvents();
|
|
548
548
|
Listening to events will prevent the process to exit. By calling this function, hotplug events will be unreferenced by the event loop, allowing the process to exit even when listening for the `attach` and `detach` events.
|
|
549
549
|
|
|
550
|
+
# Migrating from node-usb-detection
|
|
551
|
+
|
|
552
|
+
If you have been referred here by `node-usb-detection`, the following may be helpful for you to update your existing code.
|
|
553
|
+
|
|
554
|
+
## usbDetect.startMonitoring() & usbDetect.stopMonitoring()
|
|
555
|
+
|
|
556
|
+
There is no direct equivalent to these methods. This is handled automatically for you when you add and remove event listeners.
|
|
557
|
+
|
|
558
|
+
You may find `usb.unrefHotplugEvents()` useful as it is intended to help with exit conditions.
|
|
559
|
+
|
|
560
|
+
## usbDetect.find()
|
|
561
|
+
|
|
562
|
+
You can instead use `usb.getDeviceList()`. Be aware that this will do an enumeration to find all of the devices, and not look at a cache of the known devices. If you call it too often it may have a performance impact.
|
|
563
|
+
|
|
564
|
+
To find a specific device by vid and pid, call `usb.findByIds`. e.g. `usb.findByIds(0x12, 0x34)`.
|
|
565
|
+
|
|
566
|
+
## usbDetect.on('add', function(device) { ... })
|
|
567
|
+
|
|
568
|
+
These should be changed to `usb.on('attach', function(device) { ... })`.
|
|
569
|
+
|
|
570
|
+
There is no equivalent to filter based on the vid or pid, instead you should do a check inside the callback you provide.
|
|
571
|
+
The contents of the device object has also changed.
|
|
572
|
+
|
|
573
|
+
## usbDetect.on('remove', function(device) { ... })
|
|
574
|
+
|
|
575
|
+
These should be changed to `usb.on('detach', function(device) { ... })`.
|
|
576
|
+
|
|
577
|
+
There is no equivalent to filter based on the vid or pid, instead you should do a check inside the callback you provide.
|
|
578
|
+
The contents of the device object has also changed.
|
|
579
|
+
|
|
580
|
+
## usbDetect.on('change', function(device) { ... })
|
|
581
|
+
|
|
582
|
+
There is no direct equivalent to this. Instead you can listen to both `attach` and `detach` to get the same behaviour.
|
|
583
|
+
|
|
550
584
|
# Development
|
|
551
585
|
The library is based on native bindings wrapping the [libusb](https://github.com/libusb/libusb) library.
|
|
552
586
|
|
package/binding.gyp
CHANGED
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
'variables': {
|
|
3
3
|
'use_udev%': 1,
|
|
4
|
-
'use_system_libusb%': 'false'
|
|
4
|
+
'use_system_libusb%': 'false'
|
|
5
5
|
},
|
|
6
6
|
'targets': [
|
|
7
7
|
{
|
|
8
8
|
'target_name': 'usb_bindings',
|
|
9
|
-
'cflags!': [
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
'cflags!': [
|
|
10
|
+
'-fno-exceptions'
|
|
11
|
+
],
|
|
12
|
+
'cflags_cc!': [
|
|
13
|
+
'-fno-exceptions'
|
|
14
|
+
],
|
|
15
|
+
'xcode_settings': {
|
|
16
|
+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
|
|
12
17
|
'CLANG_CXX_LIBRARY': 'libc++',
|
|
13
|
-
'MACOSX_DEPLOYMENT_TARGET': '10.7'
|
|
18
|
+
'MACOSX_DEPLOYMENT_TARGET': '10.7'
|
|
14
19
|
},
|
|
15
20
|
'msvs_settings': {
|
|
16
|
-
'VCCLCompilerTool': {
|
|
21
|
+
'VCCLCompilerTool': {
|
|
22
|
+
'ExceptionHandling': 1
|
|
23
|
+
}
|
|
17
24
|
},
|
|
18
25
|
'sources': [
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
26
|
+
'src/node_usb.cc',
|
|
27
|
+
'src/device.cc',
|
|
28
|
+
'src/transfer.cc',
|
|
29
|
+
'src/thread_name.cc'
|
|
22
30
|
],
|
|
23
31
|
'cflags_cc': [
|
|
24
32
|
'-std=c++14'
|
|
@@ -26,7 +34,7 @@
|
|
|
26
34
|
'defines': [
|
|
27
35
|
'_FILE_OFFSET_BITS=64',
|
|
28
36
|
'_LARGEFILE_SOURCE',
|
|
29
|
-
'NAPI_VERSION=6'
|
|
37
|
+
'NAPI_VERSION=6'
|
|
30
38
|
],
|
|
31
39
|
'include_dirs+': [
|
|
32
40
|
'src/',
|
|
@@ -36,7 +44,7 @@
|
|
|
36
44
|
['use_system_libusb=="false" and OS!="freebsd"', {
|
|
37
45
|
'dependencies': [
|
|
38
46
|
'libusb.gypi:libusb',
|
|
39
|
-
]
|
|
47
|
+
]
|
|
40
48
|
}],
|
|
41
49
|
['use_system_libusb=="true" or OS=="freebsd"', {
|
|
42
50
|
'include_dirs+': [
|
|
@@ -44,7 +52,7 @@
|
|
|
44
52
|
],
|
|
45
53
|
'libraries': [
|
|
46
54
|
'<!@(pkg-config libusb-1.0 --libs)'
|
|
47
|
-
]
|
|
55
|
+
]
|
|
48
56
|
}],
|
|
49
57
|
['OS=="mac"', {
|
|
50
58
|
'xcode_settings': {
|
|
@@ -61,40 +69,56 @@
|
|
|
61
69
|
'-arch arm64'
|
|
62
70
|
],
|
|
63
71
|
'SDKROOT': 'macosx',
|
|
64
|
-
'MACOSX_DEPLOYMENT_TARGET': '10.7'
|
|
65
|
-
}
|
|
72
|
+
'MACOSX_DEPLOYMENT_TARGET': '10.7'
|
|
73
|
+
}
|
|
74
|
+
}],
|
|
75
|
+
['OS!="win"', {
|
|
76
|
+
'sources': [
|
|
77
|
+
'src/hotplug/libusb.cc'
|
|
78
|
+
],
|
|
66
79
|
}],
|
|
67
80
|
['OS=="win"', {
|
|
81
|
+
'sources': [
|
|
82
|
+
'src/hotplug/windows.cc'
|
|
83
|
+
],
|
|
68
84
|
'defines':[
|
|
69
85
|
'WIN32_LEAN_AND_MEAN'
|
|
70
86
|
],
|
|
87
|
+
'libraries': [
|
|
88
|
+
'cfgmgr32.lib'
|
|
89
|
+
],
|
|
71
90
|
'default_configuration': 'Debug',
|
|
72
91
|
'configurations': {
|
|
73
92
|
'Debug': {
|
|
74
|
-
'defines': [
|
|
93
|
+
'defines': [
|
|
94
|
+
'DEBUG',
|
|
95
|
+
'_DEBUG'
|
|
96
|
+
],
|
|
75
97
|
'msvs_settings': {
|
|
76
98
|
'VCCLCompilerTool': {
|
|
77
99
|
'RuntimeLibrary': 1, # static debug
|
|
78
|
-
}
|
|
79
|
-
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
80
102
|
},
|
|
81
103
|
'Release': {
|
|
82
|
-
'defines': [
|
|
104
|
+
'defines': [
|
|
105
|
+
'NDEBUG'
|
|
106
|
+
],
|
|
83
107
|
'msvs_settings': {
|
|
84
108
|
'VCCLCompilerTool': {
|
|
85
109
|
'RuntimeLibrary': 0, # static release
|
|
86
|
-
}
|
|
87
|
-
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
88
112
|
}
|
|
89
113
|
},
|
|
90
114
|
'msvs_settings': {
|
|
91
115
|
'VCCLCompilerTool': {
|
|
92
|
-
'AdditionalOptions': [ '/EHsc' ]
|
|
93
|
-
}
|
|
94
|
-
}
|
|
116
|
+
'AdditionalOptions': [ '/EHsc' ]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
95
119
|
}
|
|
96
120
|
]
|
|
97
121
|
]
|
|
98
|
-
}
|
|
122
|
+
}
|
|
99
123
|
]
|
|
100
124
|
}
|
package/dist/usb/bindings.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare function setDebugLevel(level: number): void;
|
|
|
17
17
|
* Use USBDK Backend (Windows only)
|
|
18
18
|
*/
|
|
19
19
|
export declare function useUsbDkBackend(): void;
|
|
20
|
+
export declare function _supportedHotplugEvents(): number;
|
|
20
21
|
export declare function _enableHotplugEvents(): void;
|
|
21
22
|
export declare function _disableHotplugEvents(): void;
|
|
22
23
|
export declare function _getLibusbCapability(capability: number): number;
|
package/dist/usb/endpoint.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare abstract class Endpoint extends EventEmitter {
|
|
|
32
32
|
export declare class InEndpoint extends Endpoint {
|
|
33
33
|
/** Endpoint direction. */
|
|
34
34
|
direction: 'in' | 'out';
|
|
35
|
-
protected pollTransfers: Transfer[]
|
|
35
|
+
protected pollTransfers: Transfer[];
|
|
36
36
|
protected pollTransferSize: number;
|
|
37
37
|
protected pollPending: number;
|
|
38
38
|
pollActive: boolean;
|
package/dist/usb/endpoint.js
CHANGED
|
@@ -58,6 +58,7 @@ var InEndpoint = /** @class */ (function (_super) {
|
|
|
58
58
|
var _this = _super.call(this, device, descriptor) || this;
|
|
59
59
|
/** Endpoint direction. */
|
|
60
60
|
_this.direction = 'in';
|
|
61
|
+
_this.pollTransfers = [];
|
|
61
62
|
_this.pollTransferSize = 0;
|
|
62
63
|
_this.pollPending = 0;
|
|
63
64
|
_this.pollActive = false;
|
|
@@ -115,6 +116,7 @@ var InEndpoint = /** @class */ (function (_super) {
|
|
|
115
116
|
_this.pollPending--;
|
|
116
117
|
if (_this.pollPending === 0) {
|
|
117
118
|
_this.pollTransfers = [];
|
|
119
|
+
_this.pollActive = false;
|
|
118
120
|
_this.emit('end');
|
|
119
121
|
}
|
|
120
122
|
}
|
|
@@ -140,7 +142,7 @@ var InEndpoint = /** @class */ (function (_super) {
|
|
|
140
142
|
InEndpoint.prototype.startPollTransfers = function (nTransfers, transferSize, callback) {
|
|
141
143
|
if (nTransfers === void 0) { nTransfers = 3; }
|
|
142
144
|
if (transferSize === void 0) { transferSize = this.descriptor.wMaxPacketSize; }
|
|
143
|
-
if (this.
|
|
145
|
+
if (this.pollActive) {
|
|
144
146
|
throw new Error('Polling already active');
|
|
145
147
|
}
|
|
146
148
|
this.pollTransferSize = transferSize;
|
|
@@ -162,7 +164,7 @@ var InEndpoint = /** @class */ (function (_super) {
|
|
|
162
164
|
* @param callback
|
|
163
165
|
*/
|
|
164
166
|
InEndpoint.prototype.stopPoll = function (callback) {
|
|
165
|
-
if (!this.
|
|
167
|
+
if (!this.pollActive) {
|
|
166
168
|
throw new Error('Polling is not active.');
|
|
167
169
|
}
|
|
168
170
|
for (var i = 0; i < this.pollTransfers.length; i++) {
|
package/dist/usb/endpoint.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"endpoint.js","sourceRoot":"","sources":["../../tsc/usb/endpoint.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,iCAAsC;AACtC,uCAA0F;AAG1F,IAAM,QAAQ,GAAG,UAAC,GAAyB,IAAwB,OAAA,GAAG,IAAI,GAAG,YAAY,UAAU,EAAhC,CAAgC,CAAC;AAEpG,kDAAkD;AAClD;IAAuC,4BAAY;IAe/C,kBAAsB,MAAc,EAAE,UAA8B;QAApE,YACI,iBAAO,SAIV;QALqB,YAAM,GAAN,MAAM,CAAQ;QANpC,8GAA8G;QACvG,aAAO,GAAG,CAAC,CAAC;QAOf,KAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,KAAI,CAAC,OAAO,GAAG,UAAU,CAAC,gBAAgB,CAAC;QAC3C,KAAI,CAAC,YAAY,GAAG,UAAU,CAAC,YAAY,G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AC;QAEF,IAAI;YACA,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;SACtD;QAAC,OAAO,CAAC,EAAE;YACR,OAAO,CAAC,QAAQ,CAAC,cAAM,OAAA,EAAE,CAAC,CAAC,CAAC,EAAL,CAAK,CAAC,CAAC;SACjC;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;IAEM,qCAAe,GAAtB,UAAuB,MAAc,EAAE,QAAsD;QACzF,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,cAAc,KAAK,CAAC,EAAE;YACtD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACtB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;SAC5C;aAAM;YACH,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;SACnC;IACL,CAAC;IACL,kBAAC;AAAD,CAAC,AA9CD,CAAiC,QAAQ,GA8CxC;AA9CY,kCAAW"}
|
package/dist/usb/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ declare module './bindings' {
|
|
|
10
10
|
interface DeviceEvents extends EventListeners<DeviceEvents> {
|
|
11
11
|
attach: Device;
|
|
12
12
|
detach: Device;
|
|
13
|
+
attachIds: undefined;
|
|
14
|
+
detachIds: undefined;
|
|
13
15
|
}
|
|
14
16
|
function addListener<K extends keyof DeviceEvents>(event: K, listener: (arg: DeviceEvents[K]) => void): void;
|
|
15
17
|
function removeListener<K extends keyof DeviceEvents>(event: K, listener: (arg: DeviceEvents[K]) => void): void;
|
package/dist/usb/index.js
CHANGED
|
@@ -21,21 +21,13 @@ Object.setPrototypeOf(usb, events_1.EventEmitter.prototype);
|
|
|
21
21
|
Object.getOwnPropertyNames(device_1.ExtendedDevice.prototype).forEach(function (name) {
|
|
22
22
|
Object.defineProperty(usb.Device.prototype, name, Object.getOwnPropertyDescriptor(device_1.ExtendedDevice.prototype, name) || Object.create(null));
|
|
23
23
|
});
|
|
24
|
-
// Polling mechanism for discovering device changes
|
|
25
|
-
// https://github.com/libusb/libusb/issues/86
|
|
24
|
+
// Polling mechanism for discovering device changes where hotplug detection is not available
|
|
26
25
|
var pollTimeout = 500;
|
|
27
|
-
var hotplugSupported = usb.
|
|
26
|
+
var hotplugSupported = usb._supportedHotplugEvents();
|
|
28
27
|
var pollingHotplug = false;
|
|
29
28
|
var pollDevices = new Set();
|
|
30
|
-
var
|
|
29
|
+
var pollHotplugOnce = function (start) {
|
|
31
30
|
var e_1, _a, e_2, _b;
|
|
32
|
-
if (start === void 0) { start = false; }
|
|
33
|
-
if (start) {
|
|
34
|
-
pollingHotplug = true;
|
|
35
|
-
}
|
|
36
|
-
else if (!pollingHotplug) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
31
|
// Collect current devices
|
|
40
32
|
var devices = new Set(usb.getDeviceList());
|
|
41
33
|
if (!start) {
|
|
@@ -71,10 +63,30 @@ var pollHotplug = function (start) {
|
|
|
71
63
|
}
|
|
72
64
|
}
|
|
73
65
|
pollDevices = devices;
|
|
66
|
+
};
|
|
67
|
+
var pollHotplugLoop = function (start) {
|
|
68
|
+
if (start === void 0) { start = false; }
|
|
69
|
+
if (start) {
|
|
70
|
+
pollingHotplug = true;
|
|
71
|
+
}
|
|
72
|
+
else if (!pollingHotplug) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
pollHotplugOnce(start);
|
|
74
76
|
setTimeout(function () {
|
|
75
|
-
|
|
77
|
+
pollHotplugLoop();
|
|
76
78
|
}, pollTimeout);
|
|
77
79
|
};
|
|
80
|
+
var hotplugModeIsIdsOnly = hotplugSupported === 2;
|
|
81
|
+
if (hotplugModeIsIdsOnly) {
|
|
82
|
+
// The hotplug backend doesnt emit 'attach' or 'detach', so we need to do some conversion
|
|
83
|
+
var hotplugEventConversion = function () {
|
|
84
|
+
// Future: This might want a debounce, to avoid doing multiple polls when attaching a usb hub or something
|
|
85
|
+
pollHotplugOnce(false);
|
|
86
|
+
};
|
|
87
|
+
usb.on('attachIds', hotplugEventConversion);
|
|
88
|
+
usb.on('detachIds', hotplugEventConversion);
|
|
89
|
+
}
|
|
78
90
|
usb.on('newListener', function (event) {
|
|
79
91
|
if (event !== 'attach' && event !== 'detach') {
|
|
80
92
|
return;
|
|
@@ -85,7 +97,7 @@ usb.on('newListener', function (event) {
|
|
|
85
97
|
usb._enableHotplugEvents();
|
|
86
98
|
}
|
|
87
99
|
else {
|
|
88
|
-
|
|
100
|
+
pollHotplugLoop(true);
|
|
89
101
|
}
|
|
90
102
|
}
|
|
91
103
|
});
|
package/dist/usb/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tsc/usb/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAsC;AACtC,mCAA0C;AAC1C,gCAAkC;AAElC,IAAI,GAAG,CAAC,UAAU,EAAE;IAChB,+BAA+B;IAC/B,OAAO,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;CAChD;AAED,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,qBAAY,CAAC,SAAS,CAAC,CAAC;AAEnD,MAAM,CAAC,mBAAmB,CAAC,uBAAc,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,UAAA,IAAI;IAC7D,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,wBAAwB,CAAC,uBAAc,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9I,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../tsc/usb/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iCAAsC;A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CAAC,EAAE,CAAC,gBAAgB,EAAE,UAAA,KAAK;IAC1B,IAAI,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,QAAQ,EAAE;QAC1C,OAAO;KACV;IACD,IAAM,aAAa,GAAG,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChF,IAAI,aAAa,KAAK,CAAC,EAAE;QACrB,IAAI,gBAAgB,EAAE;YAClB,GAAG,CAAC,qBAAqB,EAAE,CAAC;SAC/B;aAAM;YACH,cAAc,GAAG,KAAK,CAAC;SAC1B;KACJ;AACL,CAAC,CAAC,CAAC;AAEH,iBAAS,GAAG,CAAC"}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|