/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/node-hid@3.3.0/nodehid.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
const EventEmitter=require("events").EventEmitter,util=require("util");let driverType=null;function setDriverType(e){driverType=e}let binding=null;function loadBinding(){if(!binding){const e=require("./binding-options");"linux"!==process.platform||driverType&&"hidraw"!==driverType||(e.name="HID_hidraw"),binding=require("pkg-prebuilds/bindings")(__dirname,e)}}function HID(){if(!new.target)throw new Error("HID() must be called with 'new' operator");EventEmitter.call(this),loadBinding();var e=new Array(arguments.length+1);e[0]=null;for(var i=0;i<arguments.length;i++)e[i+1]=arguments[i];for(var i in this._raw=new(Function.prototype.bind.apply(binding.HID,e)),binding.HID.prototype)this[i]=binding.HID.prototype[i].bind(this._raw);this._paused=!0;var t=this;t.on("newListener",(function(e,i){"data"==e&&process.nextTick(t.resume.bind(t))}))}util.inherits(HID,EventEmitter),HID.prototype.close=function(){this._closing=!0,this.removeAllListeners(),this._paused?(this._raw.close(),this._closed=!0):this._raw.readInterrupt()},HID.prototype.pause=function(){this._paused=!0,this._raw.readInterrupt()},HID.prototype.read=function(e){if(this._closed)throw new Error("Unable to read from a closed HID device");return this._raw.read(e)},HID.prototype.resume=function(){var e=this;e._paused&&e.listeners("data").length>0&&(e._paused=!1,e.read((function i(t,n){try{if(e._closing)return e._paused=!0,e._raw.close(),void(e._closed=!0);t?(e._paused=!0,e._closing||e.emit("error",t)):(e.listeners("data").length<=0&&(e._paused=!0),e._paused||e.read(i),e.emit("data",n))}catch(i){setImmediate((()=>{e._closing||e.emit("error",i)}))}})))};class HIDAsync extends EventEmitter{constructor(e){if(super(),!(e instanceof binding.HIDAsync))throw new Error("HIDAsync cannot be constructed directly. Use HIDAsync.open() instead");this._raw=e;for(let e in this._raw)this[e]=async(...i)=>this._raw[e](...i);this.on("newListener",((e,i)=>{"data"==e&&process.nextTick(this.resume.bind(this))})),this.on("removeListener",((e,i)=>{"data"==e&&0==this.listenerCount("data")&&process.nextTick(this.pause.bind(this))}))}static async open(...e){loadBinding();const i=await binding.openAsyncHIDDevice(...e);return new HIDAsync(i)}async close(){this._closing=!0,await this._raw.close(),this.removeAllListeners(),this._closed=!0}pause(){this._raw.readStop()}resume(){this.listenerCount("data")>0&&this._raw.readStart(((e,i)=>{try{e?this._closing||this.emit("error",e):this.emit("data",i)}catch(e){setImmediate((()=>{this._closing||this.emit("error",e)}))}}))}}function showdevices(){return loadBinding(),binding.devices.apply(HID,arguments)}function showdevicesAsync(...e){return loadBinding(),binding.devicesAsync(...e)}function getHidapiVersion(){return loadBinding(),binding.hidapiVersion}exports.HID=HID,exports.HIDAsync=HIDAsync,exports.devices=showdevices,exports.devicesAsync=showdevicesAsync,exports.setDriverType=setDriverType,exports.getHidapiVersion=getHidapiVersion;
//# sourceMappingURL=/sm/fa806c81fa1e197171071dcc1b476b137bc4ad99b7dba8d6cf412f7044951f28.map