mqtt 5.15.1 → 5.16.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.
Files changed (40) hide show
  1. package/README.md +73 -0
  2. package/build/lib/KeepaliveManager.js +1 -1
  3. package/build/lib/KeepaliveManager.js.map +1 -1
  4. package/build/lib/client.d.ts +16 -1
  5. package/build/lib/client.js +129 -23
  6. package/build/lib/client.js.map +1 -1
  7. package/build/lib/connect/index.js +15 -2
  8. package/build/lib/connect/index.js.map +1 -1
  9. package/build/lib/connect/tls.js +1 -1
  10. package/build/lib/connect/tls.js.map +1 -1
  11. package/build/lib/handlers/ack.d.ts +1 -0
  12. package/build/lib/handlers/ack.js +13 -1
  13. package/build/lib/handlers/ack.js.map +1 -1
  14. package/build/lib/handlers/auth.d.ts +6 -2
  15. package/build/lib/handlers/auth.js +31 -9
  16. package/build/lib/handlers/auth.js.map +1 -1
  17. package/build/lib/handlers/connack.d.ts +4 -2
  18. package/build/lib/handlers/connack.js +24 -14
  19. package/build/lib/handlers/connack.js.map +1 -1
  20. package/build/lib/handlers/index.js +40 -16
  21. package/build/lib/handlers/index.js.map +1 -1
  22. package/build/lib/handlers/publish.js +35 -11
  23. package/build/lib/handlers/publish.js.map +1 -1
  24. package/build/lib/handlers/pubrel.js +1 -0
  25. package/build/lib/handlers/pubrel.js.map +1 -1
  26. package/build/lib/number-allocator.d.ts +12 -0
  27. package/build/lib/number-allocator.js +61 -0
  28. package/build/lib/number-allocator.js.map +1 -0
  29. package/build/lib/shared.d.ts +5 -1
  30. package/build/lib/shared.js.map +1 -1
  31. package/build/lib/topic-alias-send.js +1 -1
  32. package/build/lib/topic-alias-send.js.map +1 -1
  33. package/build/lib/unique-message-id-provider.js +1 -1
  34. package/build/lib/unique-message-id-provider.js.map +1 -1
  35. package/build/mqtt.d.ts +1 -0
  36. package/build/tsconfig.build.tsbuildinfo +1 -1
  37. package/dist/mqtt.esm.js +8 -8
  38. package/dist/mqtt.js +455 -2996
  39. package/dist/mqtt.min.js +8 -8
  40. package/package.json +5 -5
package/dist/mqtt.js CHANGED
@@ -11856,6 +11856,69 @@ var mqtt = (() => {
11856
11856
  }
11857
11857
  });
11858
11858
 
11859
+ // package-json:../../package.json
11860
+ var require_package = __commonJS({
11861
+ "package-json:../../package.json"(exports8, module) {
11862
+ module.exports = { version: "5.16.0" };
11863
+ }
11864
+ });
11865
+
11866
+ // build/lib/shared.js
11867
+ var require_shared = __commonJS({
11868
+ "build/lib/shared.js"(exports8) {
11869
+ "use strict";
11870
+ init_dirname();
11871
+ init_buffer2();
11872
+ init_process2();
11873
+ Object.defineProperty(exports8, "__esModule", { value: true });
11874
+ exports8.MQTTJS_VERSION = exports8.nextTick = exports8.ErrorWithSubackPacket = exports8.ErrorWithReasonCode = void 0;
11875
+ exports8.applyMixin = applyMixin;
11876
+ var ErrorWithReasonCode = class _ErrorWithReasonCode extends Error {
11877
+ code;
11878
+ constructor(message, code) {
11879
+ super(message);
11880
+ this.code = code;
11881
+ Object.setPrototypeOf(this, _ErrorWithReasonCode.prototype);
11882
+ Object.getPrototypeOf(this).name = "ErrorWithReasonCode";
11883
+ }
11884
+ };
11885
+ exports8.ErrorWithReasonCode = ErrorWithReasonCode;
11886
+ var ErrorWithSubackPacket = class _ErrorWithSubackPacket extends Error {
11887
+ packet;
11888
+ constructor(message, packet) {
11889
+ super(message);
11890
+ this.packet = packet;
11891
+ Object.setPrototypeOf(this, _ErrorWithSubackPacket.prototype);
11892
+ Object.getPrototypeOf(this).name = "ErrorWithSubackPacket";
11893
+ }
11894
+ };
11895
+ exports8.ErrorWithSubackPacket = ErrorWithSubackPacket;
11896
+ function applyMixin(target, mixin, includeConstructor = false) {
11897
+ const inheritanceChain = [mixin];
11898
+ while (true) {
11899
+ const current = inheritanceChain[0];
11900
+ const base = Object.getPrototypeOf(current);
11901
+ if (base?.prototype) {
11902
+ inheritanceChain.unshift(base);
11903
+ } else {
11904
+ break;
11905
+ }
11906
+ }
11907
+ for (const ctor of inheritanceChain) {
11908
+ for (const prop of Object.getOwnPropertyNames(ctor.prototype)) {
11909
+ if (includeConstructor || prop !== "constructor") {
11910
+ Object.defineProperty(target.prototype, prop, Object.getOwnPropertyDescriptor(ctor.prototype, prop) ?? /* @__PURE__ */ Object.create(null));
11911
+ }
11912
+ }
11913
+ }
11914
+ }
11915
+ exports8.nextTick = typeof process_exports?.nextTick === "function" ? process_exports.nextTick : (callback) => {
11916
+ setTimeout(callback, 0);
11917
+ };
11918
+ exports8.MQTTJS_VERSION = require_package().version;
11919
+ }
11920
+ });
11921
+
11859
11922
  // build/lib/handlers/publish.js
11860
11923
  var require_publish = __commonJS({
11861
11924
  "build/lib/handlers/publish.js"(exports8) {
@@ -11864,8 +11927,23 @@ var mqtt = (() => {
11864
11927
  init_buffer2();
11865
11928
  init_process2();
11866
11929
  Object.defineProperty(exports8, "__esModule", { value: true });
11930
+ var shared_1 = require_shared();
11867
11931
  var validReasonCodes = [0, 16, 128, 131, 135, 144, 145, 151, 153];
11868
- var handlePublish = (client, packet, done) => {
11932
+ var TOPIC_ALIAS_INVALID = 148;
11933
+ var PROTOCOL_ERROR = 130;
11934
+ var rejectTopicAlias = (client, message, done, pump, reasonCode = TOPIC_ALIAS_INVALID) => {
11935
+ pump?.discardParsedPackets();
11936
+ if (!pump || pump.isCurrent()) {
11937
+ client["_cleanUp"](true);
11938
+ }
11939
+ done();
11940
+ client.emit("error", new shared_1.ErrorWithReasonCode(message, reasonCode));
11941
+ };
11942
+ var failCustomAck = (client, error, done) => {
11943
+ done();
11944
+ client.emit("error", error);
11945
+ };
11946
+ var handlePublish = (client, packet, done, pump) => {
11869
11947
  client.log("handlePublish: packet %o", packet);
11870
11948
  done = typeof done !== "undefined" ? done : client.noop;
11871
11949
  let topic = packet.topic.toString();
@@ -11879,27 +11957,33 @@ var mqtt = (() => {
11879
11957
  alias = packet.properties.topicAlias;
11880
11958
  }
11881
11959
  if (typeof alias !== "undefined") {
11960
+ const topicAliasRecv = client["topicAliasRecv"];
11961
+ if (!topicAliasRecv) {
11962
+ client.log("handlePublish :: received unexpected topic alias. alias: %d", alias);
11963
+ rejectTopicAlias(client, "Received a PUBLISH Topic Alias but no Topic Alias Maximum was advertised", done, pump);
11964
+ return;
11965
+ }
11882
11966
  if (topic.length === 0) {
11883
11967
  if (alias > 0 && alias <= 65535) {
11884
- const gotTopic = client["topicAliasRecv"].getTopicByAlias(alias);
11968
+ const gotTopic = topicAliasRecv.getTopicByAlias(alias);
11885
11969
  if (gotTopic) {
11886
11970
  topic = gotTopic;
11887
11971
  client.log("handlePublish :: topic complemented by alias. topic: %s - alias: %d", topic, alias);
11888
11972
  } else {
11889
11973
  client.log("handlePublish :: unregistered topic alias. alias: %d", alias);
11890
- client.emit("error", new Error("Received unregistered Topic Alias"));
11974
+ rejectTopicAlias(client, "Received unregistered Topic Alias", done, pump, PROTOCOL_ERROR);
11891
11975
  return;
11892
11976
  }
11893
11977
  } else {
11894
11978
  client.log("handlePublish :: topic alias out of range. alias: %d", alias);
11895
- client.emit("error", new Error("Received Topic Alias is out of range"));
11979
+ rejectTopicAlias(client, `Received Topic Alias ${alias} is outside the valid range 1-65535`, done, pump);
11896
11980
  return;
11897
11981
  }
11898
- } else if (client["topicAliasRecv"].put(topic, alias)) {
11982
+ } else if (topicAliasRecv.put(topic, alias)) {
11899
11983
  client.log("handlePublish :: registered topic: %s - alias: %d", topic, alias);
11900
11984
  } else {
11901
- client.log("handlePublish :: topic alias out of range. alias: %d", alias);
11902
- client.emit("error", new Error("Received Topic Alias is out of range"));
11985
+ client.log("handlePublish :: topic alias outside the advertised maximum. alias: %d - max: %d", alias, topicAliasRecv.max);
11986
+ rejectTopicAlias(client, `Received Topic Alias ${alias} is outside the advertised Topic Alias Maximum range 1-${topicAliasRecv.max}`, done, pump);
11903
11987
  return;
11904
11988
  }
11905
11989
  }
@@ -11913,14 +11997,17 @@ var mqtt = (() => {
11913
11997
  error = null;
11914
11998
  }
11915
11999
  if (error) {
11916
- return client.emit("error", error);
12000
+ return failCustomAck(client, error, done);
11917
12001
  }
11918
12002
  if (validReasonCodes.indexOf(code) === -1) {
11919
- return client.emit("error", new Error("Wrong reason code for pubrec"));
12003
+ return failCustomAck(client, new Error("Wrong reason code for pubrec"), done);
11920
12004
  }
11921
12005
  if (code) {
11922
12006
  client["_sendPacket"]({ cmd: "pubrec", messageId, reasonCode: code }, done);
11923
12007
  } else {
12008
+ if (!client["_trackIncomingQoS2Publish"](messageId, done, pump)) {
12009
+ return;
12010
+ }
11924
12011
  client.incomingStore.put(packet, () => {
11925
12012
  client["_sendPacket"]({ cmd: "pubrec", messageId }, done);
11926
12013
  });
@@ -11935,10 +12022,10 @@ var mqtt = (() => {
11935
12022
  error = null;
11936
12023
  }
11937
12024
  if (error) {
11938
- return client.emit("error", error);
12025
+ return failCustomAck(client, error, done);
11939
12026
  }
11940
12027
  if (validReasonCodes.indexOf(code) === -1) {
11941
- return client.emit("error", new Error("Wrong reason code for puback"));
12028
+ return failCustomAck(client, new Error("Wrong reason code for puback"), done);
11942
12029
  }
11943
12030
  if (!code) {
11944
12031
  client.emit("message", topic, message, packet);
@@ -11965,66 +12052,63 @@ var mqtt = (() => {
11965
12052
  }
11966
12053
  });
11967
12054
 
11968
- // package-json:../../package.json
11969
- var require_package = __commonJS({
11970
- "package-json:../../package.json"(exports8, module) {
11971
- module.exports = { version: "5.15.1" };
11972
- }
11973
- });
11974
-
11975
- // build/lib/shared.js
11976
- var require_shared = __commonJS({
11977
- "build/lib/shared.js"(exports8) {
12055
+ // build/lib/handlers/auth.js
12056
+ var require_auth = __commonJS({
12057
+ "build/lib/handlers/auth.js"(exports8) {
11978
12058
  "use strict";
11979
12059
  init_dirname();
11980
12060
  init_buffer2();
11981
12061
  init_process2();
11982
12062
  Object.defineProperty(exports8, "__esModule", { value: true });
11983
- exports8.MQTTJS_VERSION = exports8.nextTick = exports8.ErrorWithSubackPacket = exports8.ErrorWithReasonCode = void 0;
11984
- exports8.applyMixin = applyMixin;
11985
- var ErrorWithReasonCode = class _ErrorWithReasonCode extends Error {
11986
- code;
11987
- constructor(message, code) {
11988
- super(message);
11989
- this.code = code;
11990
- Object.setPrototypeOf(this, _ErrorWithReasonCode.prototype);
11991
- Object.getPrototypeOf(this).name = "ErrorWithReasonCode";
12063
+ var shared_1 = require_shared();
12064
+ var PROTOCOL_ERROR = 130;
12065
+ var rejectAuth = (client, error, pump) => {
12066
+ client.log("handleAuth :: %s", error.message);
12067
+ pump?.discardParsedPackets();
12068
+ if (!pump || pump.isCurrent()) {
12069
+ client["_cleanUp"](true);
11992
12070
  }
12071
+ client.emit("error", error);
11993
12072
  };
11994
- exports8.ErrorWithReasonCode = ErrorWithReasonCode;
11995
- var ErrorWithSubackPacket = class _ErrorWithSubackPacket extends Error {
11996
- packet;
11997
- constructor(message, packet) {
11998
- super(message);
11999
- this.packet = packet;
12000
- Object.setPrototypeOf(this, _ErrorWithSubackPacket.prototype);
12001
- Object.getPrototypeOf(this).name = "ErrorWithSubackPacket";
12073
+ var handleAuth = (client, packet, pump) => {
12074
+ const { options } = client;
12075
+ const version4 = options.protocolVersion;
12076
+ const rc = version4 === 5 ? packet.reasonCode : packet.returnCode;
12077
+ if (version4 !== 5) {
12078
+ rejectAuth(client, new shared_1.ErrorWithReasonCode(`Protocol error: Auth packets are only supported in MQTT 5. Your version:${version4}`, PROTOCOL_ERROR), pump);
12079
+ return;
12002
12080
  }
12003
- };
12004
- exports8.ErrorWithSubackPacket = ErrorWithSubackPacket;
12005
- function applyMixin(target, mixin, includeConstructor = false) {
12006
- const inheritanceChain = [mixin];
12007
- while (true) {
12008
- const current = inheritanceChain[0];
12009
- const base = Object.getPrototypeOf(current);
12010
- if (base?.prototype) {
12011
- inheritanceChain.unshift(base);
12012
- } else {
12013
- break;
12014
- }
12081
+ const authenticationMethod = client["_authenticationMethod"];
12082
+ if (!authenticationMethod) {
12083
+ rejectAuth(client, new shared_1.ErrorWithReasonCode("Protocol error: Auth packet received but enhanced authentication was not requested", PROTOCOL_ERROR), pump);
12084
+ return;
12015
12085
  }
12016
- for (const ctor of inheritanceChain) {
12017
- for (const prop of Object.getOwnPropertyNames(ctor.prototype)) {
12018
- if (includeConstructor || prop !== "constructor") {
12019
- Object.defineProperty(target.prototype, prop, Object.getOwnPropertyDescriptor(ctor.prototype, prop) ?? /* @__PURE__ */ Object.create(null));
12086
+ if (packet.properties?.authenticationMethod !== authenticationMethod) {
12087
+ rejectAuth(client, new shared_1.ErrorWithReasonCode(`Protocol error: Auth packet Authentication Method does not match the "${authenticationMethod}" sent in CONNECT`, PROTOCOL_ERROR), pump);
12088
+ return;
12089
+ }
12090
+ client.handleAuth(packet, (err, packet2) => {
12091
+ if (err) {
12092
+ rejectAuth(client, err, pump);
12093
+ return;
12094
+ }
12095
+ if (rc === 0) {
12096
+ client.log("handleAuth :: authentication exchange completed successfully");
12097
+ return;
12098
+ }
12099
+ if (rc === 24) {
12100
+ if (!packet2) {
12101
+ rejectAuth(client, new shared_1.ErrorWithReasonCode("Protocol error: No auth packet to continue the authentication exchange", PROTOCOL_ERROR), pump);
12102
+ return;
12020
12103
  }
12104
+ client.reconnecting = false;
12105
+ client["_sendPacket"](packet2);
12106
+ return;
12021
12107
  }
12022
- }
12023
- }
12024
- exports8.nextTick = typeof process_exports?.nextTick === "function" ? process_exports.nextTick : (callback) => {
12025
- setTimeout(callback, 0);
12108
+ rejectAuth(client, new shared_1.ErrorWithReasonCode(`Protocol error: Auth packet reason code ${rc} is not one a broker may send`, PROTOCOL_ERROR), pump);
12109
+ });
12026
12110
  };
12027
- exports8.MQTTJS_VERSION = require_package().version;
12111
+ exports8.default = handleAuth;
12028
12112
  }
12029
12113
  });
12030
12114
 
@@ -12083,16 +12167,28 @@ var mqtt = (() => {
12083
12167
  161: "Subscription Identifiers not supported",
12084
12168
  162: "Wildcard Subscriptions not supported"
12085
12169
  };
12170
+ var acksForPendingCmd = {
12171
+ publish: ["puback", "pubrec", "pubcomp"],
12172
+ pubrel: ["pubcomp"],
12173
+ subscribe: ["suback"],
12174
+ unsubscribe: ["unsuback"]
12175
+ };
12086
12176
  var handleAck = (client, packet) => {
12087
12177
  const { messageId } = packet;
12088
12178
  const type = packet.cmd;
12089
12179
  let response = null;
12090
- const cb = client.outgoing[messageId] ? client.outgoing[messageId].cb : null;
12180
+ const pending = client.outgoing[messageId];
12181
+ const cb = pending ? pending.cb : null;
12091
12182
  let err = null;
12092
12183
  if (!cb) {
12093
12184
  client.log("_handleAck :: Server sent an ack in error. Ignoring.");
12094
12185
  return;
12095
12186
  }
12187
+ if (!acksForPendingCmd[pending.cmd]?.includes(type)) {
12188
+ client.log("_handleAck :: %s does not answer the pending %s on message id %d. Ignoring.", type, pending.cmd, messageId);
12189
+ client.emit("error", new Error(`Protocol error: ${type} does not answer the ${pending.cmd} pending on message id ${messageId}`));
12190
+ return;
12191
+ }
12096
12192
  client.log("_handleAck :: packet type", type);
12097
12193
  switch (type) {
12098
12194
  case "pubcomp":
@@ -12165,43 +12261,6 @@ var mqtt = (() => {
12165
12261
  }
12166
12262
  });
12167
12263
 
12168
- // build/lib/handlers/auth.js
12169
- var require_auth = __commonJS({
12170
- "build/lib/handlers/auth.js"(exports8) {
12171
- "use strict";
12172
- init_dirname();
12173
- init_buffer2();
12174
- init_process2();
12175
- Object.defineProperty(exports8, "__esModule", { value: true });
12176
- var shared_1 = require_shared();
12177
- var ack_1 = require_ack();
12178
- var handleAuth = (client, packet) => {
12179
- const { options } = client;
12180
- const version4 = options.protocolVersion;
12181
- const rc = version4 === 5 ? packet.reasonCode : packet.returnCode;
12182
- if (version4 !== 5) {
12183
- const err = new shared_1.ErrorWithReasonCode(`Protocol error: Auth packets are only supported in MQTT 5. Your version:${version4}`, rc);
12184
- client.emit("error", err);
12185
- return;
12186
- }
12187
- client.handleAuth(packet, (err, packet2) => {
12188
- if (err) {
12189
- client.emit("error", err);
12190
- return;
12191
- }
12192
- if (rc === 24) {
12193
- client.reconnecting = false;
12194
- client["_sendPacket"](packet2);
12195
- } else {
12196
- const error = new shared_1.ErrorWithReasonCode(`Connection refused: ${ack_1.ReasonCodes[rc]}`, rc);
12197
- client.emit("error", error);
12198
- }
12199
- });
12200
- };
12201
- exports8.default = handleAuth;
12202
- }
12203
- });
12204
-
12205
12264
  // node_modules/lru-cache/dist/commonjs/index.js
12206
12265
  var require_commonjs = __commonJS({
12207
12266
  "node_modules/lru-cache/dist/commonjs/index.js"(exports8) {
@@ -13508,2883 +13567,146 @@ var mqtt = (() => {
13508
13567
  }
13509
13568
  this.#keyMap.delete(k);
13510
13569
  this.#keyList[index] = void 0;
13511
- this.#valList[index] = void 0;
13512
- if (index === this.#tail) {
13513
- this.#tail = this.#prev[index];
13514
- } else if (index === this.#head) {
13515
- this.#head = this.#next[index];
13516
- } else {
13517
- const pi = this.#prev[index];
13518
- this.#next[pi] = this.#next[index];
13519
- const ni = this.#next[index];
13520
- this.#prev[ni] = this.#prev[index];
13521
- }
13522
- this.#size--;
13523
- this.#free.push(index);
13524
- }
13525
- }
13526
- }
13527
- if (this.#hasDisposeAfter && this.#disposed?.length) {
13528
- const dt = this.#disposed;
13529
- let task;
13530
- while (task = dt?.shift()) {
13531
- this.#disposeAfter?.(...task);
13532
- }
13533
- }
13534
- return deleted;
13535
- }
13536
- /**
13537
- * Clear the cache entirely, throwing away all values.
13538
- */
13539
- clear() {
13540
- return this.#clear("delete");
13541
- }
13542
- #clear(reason) {
13543
- for (const index of this.#rindexes({ allowStale: true })) {
13544
- const v = this.#valList[index];
13545
- if (this.#isBackgroundFetch(v)) {
13546
- v.__abortController.abort(new Error("deleted"));
13547
- } else {
13548
- const k = this.#keyList[index];
13549
- if (this.#hasDispose) {
13550
- this.#dispose?.(v, k, reason);
13551
- }
13552
- if (this.#hasDisposeAfter) {
13553
- this.#disposed?.push([v, k, reason]);
13554
- }
13555
- }
13556
- }
13557
- this.#keyMap.clear();
13558
- this.#valList.fill(void 0);
13559
- this.#keyList.fill(void 0);
13560
- if (this.#ttls && this.#starts) {
13561
- this.#ttls.fill(0);
13562
- this.#starts.fill(0);
13563
- }
13564
- if (this.#sizes) {
13565
- this.#sizes.fill(0);
13566
- }
13567
- this.#head = 0;
13568
- this.#tail = 0;
13569
- this.#free.length = 0;
13570
- this.#calculatedSize = 0;
13571
- this.#size = 0;
13572
- if (this.#hasDisposeAfter && this.#disposed) {
13573
- const dt = this.#disposed;
13574
- let task;
13575
- while (task = dt?.shift()) {
13576
- this.#disposeAfter?.(...task);
13577
- }
13578
- }
13579
- }
13580
- };
13581
- exports8.LRUCache = LRUCache;
13582
- }
13583
- });
13584
-
13585
- // node_modules/js-sdsl/dist/cjs/container/ContainerBase/index.js
13586
- var require_ContainerBase = __commonJS({
13587
- "node_modules/js-sdsl/dist/cjs/container/ContainerBase/index.js"(exports8) {
13588
- "use strict";
13589
- init_dirname();
13590
- init_buffer2();
13591
- init_process2();
13592
- Object.defineProperty(exports8, "t", {
13593
- value: true
13594
- });
13595
- exports8.ContainerIterator = exports8.Container = exports8.Base = void 0;
13596
- var ContainerIterator = class {
13597
- constructor(t = 0) {
13598
- this.iteratorType = t;
13599
- }
13600
- equals(t) {
13601
- return this.o === t.o;
13602
- }
13603
- };
13604
- exports8.ContainerIterator = ContainerIterator;
13605
- var Base = class {
13606
- constructor() {
13607
- this.i = 0;
13608
- }
13609
- get length() {
13610
- return this.i;
13611
- }
13612
- size() {
13613
- return this.i;
13614
- }
13615
- empty() {
13616
- return this.i === 0;
13617
- }
13618
- };
13619
- exports8.Base = Base;
13620
- var Container = class extends Base {
13621
- };
13622
- exports8.Container = Container;
13623
- }
13624
- });
13625
-
13626
- // node_modules/js-sdsl/dist/cjs/container/OtherContainer/Stack.js
13627
- var require_Stack = __commonJS({
13628
- "node_modules/js-sdsl/dist/cjs/container/OtherContainer/Stack.js"(exports8) {
13629
- "use strict";
13630
- init_dirname();
13631
- init_buffer2();
13632
- init_process2();
13633
- Object.defineProperty(exports8, "t", {
13634
- value: true
13635
- });
13636
- exports8.default = void 0;
13637
- var _ContainerBase = require_ContainerBase();
13638
- var Stack = class extends _ContainerBase.Base {
13639
- constructor(t = []) {
13640
- super();
13641
- this.S = [];
13642
- const s = this;
13643
- t.forEach((function(t2) {
13644
- s.push(t2);
13645
- }));
13646
- }
13647
- clear() {
13648
- this.i = 0;
13649
- this.S = [];
13650
- }
13651
- push(t) {
13652
- this.S.push(t);
13653
- this.i += 1;
13654
- return this.i;
13655
- }
13656
- pop() {
13657
- if (this.i === 0) return;
13658
- this.i -= 1;
13659
- return this.S.pop();
13660
- }
13661
- top() {
13662
- return this.S[this.i - 1];
13663
- }
13664
- };
13665
- var _default = Stack;
13666
- exports8.default = _default;
13667
- }
13668
- });
13669
-
13670
- // node_modules/js-sdsl/dist/cjs/container/OtherContainer/Queue.js
13671
- var require_Queue = __commonJS({
13672
- "node_modules/js-sdsl/dist/cjs/container/OtherContainer/Queue.js"(exports8) {
13673
- "use strict";
13674
- init_dirname();
13675
- init_buffer2();
13676
- init_process2();
13677
- Object.defineProperty(exports8, "t", {
13678
- value: true
13679
- });
13680
- exports8.default = void 0;
13681
- var _ContainerBase = require_ContainerBase();
13682
- var Queue = class extends _ContainerBase.Base {
13683
- constructor(t = []) {
13684
- super();
13685
- this.j = 0;
13686
- this.q = [];
13687
- const s = this;
13688
- t.forEach((function(t2) {
13689
- s.push(t2);
13690
- }));
13691
- }
13692
- clear() {
13693
- this.q = [];
13694
- this.i = this.j = 0;
13695
- }
13696
- push(t) {
13697
- const s = this.q.length;
13698
- if (this.j / s > 0.5 && this.j + this.i >= s && s > 4096) {
13699
- const s2 = this.i;
13700
- for (let t2 = 0; t2 < s2; ++t2) {
13701
- this.q[t2] = this.q[this.j + t2];
13702
- }
13703
- this.j = 0;
13704
- this.q[this.i] = t;
13705
- } else this.q[this.j + this.i] = t;
13706
- return ++this.i;
13707
- }
13708
- pop() {
13709
- if (this.i === 0) return;
13710
- const t = this.q[this.j++];
13711
- this.i -= 1;
13712
- return t;
13713
- }
13714
- front() {
13715
- if (this.i === 0) return;
13716
- return this.q[this.j];
13717
- }
13718
- };
13719
- var _default = Queue;
13720
- exports8.default = _default;
13721
- }
13722
- });
13723
-
13724
- // node_modules/js-sdsl/dist/cjs/container/OtherContainer/PriorityQueue.js
13725
- var require_PriorityQueue = __commonJS({
13726
- "node_modules/js-sdsl/dist/cjs/container/OtherContainer/PriorityQueue.js"(exports8) {
13727
- "use strict";
13728
- init_dirname();
13729
- init_buffer2();
13730
- init_process2();
13731
- Object.defineProperty(exports8, "t", {
13732
- value: true
13733
- });
13734
- exports8.default = void 0;
13735
- var _ContainerBase = require_ContainerBase();
13736
- var PriorityQueue = class extends _ContainerBase.Base {
13737
- constructor(t = [], s = function(t2, s2) {
13738
- if (t2 > s2) return -1;
13739
- if (t2 < s2) return 1;
13740
- return 0;
13741
- }, i = true) {
13742
- super();
13743
- this.v = s;
13744
- if (Array.isArray(t)) {
13745
- this.C = i ? [...t] : t;
13746
- } else {
13747
- this.C = [];
13748
- const s2 = this;
13749
- t.forEach((function(t2) {
13750
- s2.C.push(t2);
13751
- }));
13752
- }
13753
- this.i = this.C.length;
13754
- const e = this.i >> 1;
13755
- for (let t2 = this.i - 1 >> 1; t2 >= 0; --t2) {
13756
- this.k(t2, e);
13757
- }
13758
- }
13759
- m(t) {
13760
- const s = this.C[t];
13761
- while (t > 0) {
13762
- const i = t - 1 >> 1;
13763
- const e = this.C[i];
13764
- if (this.v(e, s) <= 0) break;
13765
- this.C[t] = e;
13766
- t = i;
13767
- }
13768
- this.C[t] = s;
13769
- }
13770
- k(t, s) {
13771
- const i = this.C[t];
13772
- while (t < s) {
13773
- let s2 = t << 1 | 1;
13774
- const e = s2 + 1;
13775
- let h = this.C[s2];
13776
- if (e < this.i && this.v(h, this.C[e]) > 0) {
13777
- s2 = e;
13778
- h = this.C[e];
13779
- }
13780
- if (this.v(h, i) >= 0) break;
13781
- this.C[t] = h;
13782
- t = s2;
13783
- }
13784
- this.C[t] = i;
13785
- }
13786
- clear() {
13787
- this.i = 0;
13788
- this.C.length = 0;
13789
- }
13790
- push(t) {
13791
- this.C.push(t);
13792
- this.m(this.i);
13793
- this.i += 1;
13794
- }
13795
- pop() {
13796
- if (this.i === 0) return;
13797
- const t = this.C[0];
13798
- const s = this.C.pop();
13799
- this.i -= 1;
13800
- if (this.i) {
13801
- this.C[0] = s;
13802
- this.k(0, this.i >> 1);
13803
- }
13804
- return t;
13805
- }
13806
- top() {
13807
- return this.C[0];
13808
- }
13809
- find(t) {
13810
- return this.C.indexOf(t) >= 0;
13811
- }
13812
- remove(t) {
13813
- const s = this.C.indexOf(t);
13814
- if (s < 0) return false;
13815
- if (s === 0) {
13816
- this.pop();
13817
- } else if (s === this.i - 1) {
13818
- this.C.pop();
13819
- this.i -= 1;
13820
- } else {
13821
- this.C.splice(s, 1, this.C.pop());
13822
- this.i -= 1;
13823
- this.m(s);
13824
- this.k(s, this.i >> 1);
13825
- }
13826
- return true;
13827
- }
13828
- updateItem(t) {
13829
- const s = this.C.indexOf(t);
13830
- if (s < 0) return false;
13831
- this.m(s);
13832
- this.k(s, this.i >> 1);
13833
- return true;
13834
- }
13835
- toArray() {
13836
- return [...this.C];
13837
- }
13838
- };
13839
- var _default = PriorityQueue;
13840
- exports8.default = _default;
13841
- }
13842
- });
13843
-
13844
- // node_modules/js-sdsl/dist/cjs/container/SequentialContainer/Base/index.js
13845
- var require_Base = __commonJS({
13846
- "node_modules/js-sdsl/dist/cjs/container/SequentialContainer/Base/index.js"(exports8) {
13847
- "use strict";
13848
- init_dirname();
13849
- init_buffer2();
13850
- init_process2();
13851
- Object.defineProperty(exports8, "t", {
13852
- value: true
13853
- });
13854
- exports8.default = void 0;
13855
- var _ContainerBase = require_ContainerBase();
13856
- var SequentialContainer = class extends _ContainerBase.Container {
13857
- };
13858
- var _default = SequentialContainer;
13859
- exports8.default = _default;
13860
- }
13861
- });
13862
-
13863
- // node_modules/js-sdsl/dist/cjs/utils/throwError.js
13864
- var require_throwError = __commonJS({
13865
- "node_modules/js-sdsl/dist/cjs/utils/throwError.js"(exports8) {
13866
- "use strict";
13867
- init_dirname();
13868
- init_buffer2();
13869
- init_process2();
13870
- Object.defineProperty(exports8, "t", {
13871
- value: true
13872
- });
13873
- exports8.throwIteratorAccessError = throwIteratorAccessError;
13874
- function throwIteratorAccessError() {
13875
- throw new RangeError("Iterator access denied!");
13876
- }
13877
- }
13878
- });
13879
-
13880
- // node_modules/js-sdsl/dist/cjs/container/SequentialContainer/Base/RandomIterator.js
13881
- var require_RandomIterator = __commonJS({
13882
- "node_modules/js-sdsl/dist/cjs/container/SequentialContainer/Base/RandomIterator.js"(exports8) {
13883
- "use strict";
13884
- init_dirname();
13885
- init_buffer2();
13886
- init_process2();
13887
- Object.defineProperty(exports8, "t", {
13888
- value: true
13889
- });
13890
- exports8.RandomIterator = void 0;
13891
- var _ContainerBase = require_ContainerBase();
13892
- var _throwError = require_throwError();
13893
- var RandomIterator = class extends _ContainerBase.ContainerIterator {
13894
- constructor(t, r) {
13895
- super(r);
13896
- this.o = t;
13897
- if (this.iteratorType === 0) {
13898
- this.pre = function() {
13899
- if (this.o === 0) {
13900
- (0, _throwError.throwIteratorAccessError)();
13901
- }
13902
- this.o -= 1;
13903
- return this;
13904
- };
13905
- this.next = function() {
13906
- if (this.o === this.container.size()) {
13907
- (0, _throwError.throwIteratorAccessError)();
13908
- }
13909
- this.o += 1;
13910
- return this;
13911
- };
13912
- } else {
13913
- this.pre = function() {
13914
- if (this.o === this.container.size() - 1) {
13915
- (0, _throwError.throwIteratorAccessError)();
13916
- }
13917
- this.o += 1;
13918
- return this;
13919
- };
13920
- this.next = function() {
13921
- if (this.o === -1) {
13922
- (0, _throwError.throwIteratorAccessError)();
13923
- }
13924
- this.o -= 1;
13925
- return this;
13926
- };
13927
- }
13928
- }
13929
- get pointer() {
13930
- return this.container.getElementByPos(this.o);
13931
- }
13932
- set pointer(t) {
13933
- this.container.setElementByPos(this.o, t);
13934
- }
13935
- };
13936
- exports8.RandomIterator = RandomIterator;
13937
- }
13938
- });
13939
-
13940
- // node_modules/js-sdsl/dist/cjs/container/SequentialContainer/Vector.js
13941
- var require_Vector = __commonJS({
13942
- "node_modules/js-sdsl/dist/cjs/container/SequentialContainer/Vector.js"(exports8) {
13943
- "use strict";
13944
- init_dirname();
13945
- init_buffer2();
13946
- init_process2();
13947
- Object.defineProperty(exports8, "t", {
13948
- value: true
13949
- });
13950
- exports8.default = void 0;
13951
- var _Base = _interopRequireDefault(require_Base());
13952
- var _RandomIterator = require_RandomIterator();
13953
- function _interopRequireDefault(t) {
13954
- return t && t.t ? t : {
13955
- default: t
13956
- };
13957
- }
13958
- var VectorIterator = class _VectorIterator extends _RandomIterator.RandomIterator {
13959
- constructor(t, r, e) {
13960
- super(t, e);
13961
- this.container = r;
13962
- }
13963
- copy() {
13964
- return new _VectorIterator(this.o, this.container, this.iteratorType);
13965
- }
13966
- };
13967
- var Vector = class extends _Base.default {
13968
- constructor(t = [], r = true) {
13969
- super();
13970
- if (Array.isArray(t)) {
13971
- this.J = r ? [...t] : t;
13972
- this.i = t.length;
13973
- } else {
13974
- this.J = [];
13975
- const r2 = this;
13976
- t.forEach((function(t2) {
13977
- r2.pushBack(t2);
13978
- }));
13979
- }
13980
- }
13981
- clear() {
13982
- this.i = 0;
13983
- this.J.length = 0;
13984
- }
13985
- begin() {
13986
- return new VectorIterator(0, this);
13987
- }
13988
- end() {
13989
- return new VectorIterator(this.i, this);
13990
- }
13991
- rBegin() {
13992
- return new VectorIterator(this.i - 1, this, 1);
13993
- }
13994
- rEnd() {
13995
- return new VectorIterator(-1, this, 1);
13996
- }
13997
- front() {
13998
- return this.J[0];
13999
- }
14000
- back() {
14001
- return this.J[this.i - 1];
14002
- }
14003
- getElementByPos(t) {
14004
- if (t < 0 || t > this.i - 1) {
14005
- throw new RangeError();
14006
- }
14007
- return this.J[t];
14008
- }
14009
- eraseElementByPos(t) {
14010
- if (t < 0 || t > this.i - 1) {
14011
- throw new RangeError();
14012
- }
14013
- this.J.splice(t, 1);
14014
- this.i -= 1;
14015
- return this.i;
14016
- }
14017
- eraseElementByValue(t) {
14018
- let r = 0;
14019
- for (let e = 0; e < this.i; ++e) {
14020
- if (this.J[e] !== t) {
14021
- this.J[r++] = this.J[e];
14022
- }
14023
- }
14024
- this.i = this.J.length = r;
14025
- return this.i;
14026
- }
14027
- eraseElementByIterator(t) {
14028
- const r = t.o;
14029
- t = t.next();
14030
- this.eraseElementByPos(r);
14031
- return t;
14032
- }
14033
- pushBack(t) {
14034
- this.J.push(t);
14035
- this.i += 1;
14036
- return this.i;
14037
- }
14038
- popBack() {
14039
- if (this.i === 0) return;
14040
- this.i -= 1;
14041
- return this.J.pop();
14042
- }
14043
- setElementByPos(t, r) {
14044
- if (t < 0 || t > this.i - 1) {
14045
- throw new RangeError();
14046
- }
14047
- this.J[t] = r;
14048
- }
14049
- insert(t, r, e = 1) {
14050
- if (t < 0 || t > this.i) {
14051
- throw new RangeError();
14052
- }
14053
- this.J.splice(t, 0, ...new Array(e).fill(r));
14054
- this.i += e;
14055
- return this.i;
14056
- }
14057
- find(t) {
14058
- for (let r = 0; r < this.i; ++r) {
14059
- if (this.J[r] === t) {
14060
- return new VectorIterator(r, this);
14061
- }
14062
- }
14063
- return this.end();
14064
- }
14065
- reverse() {
14066
- this.J.reverse();
14067
- }
14068
- unique() {
14069
- let t = 1;
14070
- for (let r = 1; r < this.i; ++r) {
14071
- if (this.J[r] !== this.J[r - 1]) {
14072
- this.J[t++] = this.J[r];
14073
- }
14074
- }
14075
- this.i = this.J.length = t;
14076
- return this.i;
14077
- }
14078
- sort(t) {
14079
- this.J.sort(t);
14080
- }
14081
- forEach(t) {
14082
- for (let r = 0; r < this.i; ++r) {
14083
- t(this.J[r], r, this);
14084
- }
14085
- }
14086
- [Symbol.iterator]() {
14087
- return function* () {
14088
- yield* this.J;
14089
- }.bind(this)();
14090
- }
14091
- };
14092
- var _default = Vector;
14093
- exports8.default = _default;
14094
- }
14095
- });
14096
-
14097
- // node_modules/js-sdsl/dist/cjs/container/SequentialContainer/LinkList.js
14098
- var require_LinkList = __commonJS({
14099
- "node_modules/js-sdsl/dist/cjs/container/SequentialContainer/LinkList.js"(exports8) {
14100
- "use strict";
14101
- init_dirname();
14102
- init_buffer2();
14103
- init_process2();
14104
- Object.defineProperty(exports8, "t", {
14105
- value: true
14106
- });
14107
- exports8.default = void 0;
14108
- var _Base = _interopRequireDefault(require_Base());
14109
- var _ContainerBase = require_ContainerBase();
14110
- var _throwError = require_throwError();
14111
- function _interopRequireDefault(t) {
14112
- return t && t.t ? t : {
14113
- default: t
14114
- };
14115
- }
14116
- var LinkListIterator = class _LinkListIterator extends _ContainerBase.ContainerIterator {
14117
- constructor(t, i, s, r) {
14118
- super(r);
14119
- this.o = t;
14120
- this.h = i;
14121
- this.container = s;
14122
- if (this.iteratorType === 0) {
14123
- this.pre = function() {
14124
- if (this.o.L === this.h) {
14125
- (0, _throwError.throwIteratorAccessError)();
14126
- }
14127
- this.o = this.o.L;
14128
- return this;
14129
- };
14130
- this.next = function() {
14131
- if (this.o === this.h) {
14132
- (0, _throwError.throwIteratorAccessError)();
14133
- }
14134
- this.o = this.o.B;
14135
- return this;
14136
- };
14137
- } else {
14138
- this.pre = function() {
14139
- if (this.o.B === this.h) {
14140
- (0, _throwError.throwIteratorAccessError)();
14141
- }
14142
- this.o = this.o.B;
14143
- return this;
14144
- };
14145
- this.next = function() {
14146
- if (this.o === this.h) {
14147
- (0, _throwError.throwIteratorAccessError)();
14148
- }
14149
- this.o = this.o.L;
14150
- return this;
14151
- };
14152
- }
14153
- }
14154
- get pointer() {
14155
- if (this.o === this.h) {
14156
- (0, _throwError.throwIteratorAccessError)();
14157
- }
14158
- return this.o.l;
14159
- }
14160
- set pointer(t) {
14161
- if (this.o === this.h) {
14162
- (0, _throwError.throwIteratorAccessError)();
14163
- }
14164
- this.o.l = t;
14165
- }
14166
- copy() {
14167
- return new _LinkListIterator(this.o, this.h, this.container, this.iteratorType);
14168
- }
14169
- };
14170
- var LinkList = class extends _Base.default {
14171
- constructor(t = []) {
14172
- super();
14173
- this.h = {};
14174
- this.p = this._ = this.h.L = this.h.B = this.h;
14175
- const i = this;
14176
- t.forEach((function(t2) {
14177
- i.pushBack(t2);
14178
- }));
14179
- }
14180
- V(t) {
14181
- const { L: i, B: s } = t;
14182
- i.B = s;
14183
- s.L = i;
14184
- if (t === this.p) {
14185
- this.p = s;
14186
- }
14187
- if (t === this._) {
14188
- this._ = i;
14189
- }
14190
- this.i -= 1;
14191
- }
14192
- G(t, i) {
14193
- const s = i.B;
14194
- const r = {
14195
- l: t,
14196
- L: i,
14197
- B: s
14198
- };
14199
- i.B = r;
14200
- s.L = r;
14201
- if (i === this.h) {
14202
- this.p = r;
14203
- }
14204
- if (s === this.h) {
14205
- this._ = r;
14206
- }
14207
- this.i += 1;
14208
- }
14209
- clear() {
14210
- this.i = 0;
14211
- this.p = this._ = this.h.L = this.h.B = this.h;
14212
- }
14213
- begin() {
14214
- return new LinkListIterator(this.p, this.h, this);
14215
- }
14216
- end() {
14217
- return new LinkListIterator(this.h, this.h, this);
14218
- }
14219
- rBegin() {
14220
- return new LinkListIterator(this._, this.h, this, 1);
14221
- }
14222
- rEnd() {
14223
- return new LinkListIterator(this.h, this.h, this, 1);
14224
- }
14225
- front() {
14226
- return this.p.l;
14227
- }
14228
- back() {
14229
- return this._.l;
14230
- }
14231
- getElementByPos(t) {
14232
- if (t < 0 || t > this.i - 1) {
14233
- throw new RangeError();
14234
- }
14235
- let i = this.p;
14236
- while (t--) {
14237
- i = i.B;
14238
- }
14239
- return i.l;
14240
- }
14241
- eraseElementByPos(t) {
14242
- if (t < 0 || t > this.i - 1) {
14243
- throw new RangeError();
14244
- }
14245
- let i = this.p;
14246
- while (t--) {
14247
- i = i.B;
14248
- }
14249
- this.V(i);
14250
- return this.i;
14251
- }
14252
- eraseElementByValue(t) {
14253
- let i = this.p;
14254
- while (i !== this.h) {
14255
- if (i.l === t) {
14256
- this.V(i);
14257
- }
14258
- i = i.B;
14259
- }
14260
- return this.i;
14261
- }
14262
- eraseElementByIterator(t) {
14263
- const i = t.o;
14264
- if (i === this.h) {
14265
- (0, _throwError.throwIteratorAccessError)();
14266
- }
14267
- t = t.next();
14268
- this.V(i);
14269
- return t;
14270
- }
14271
- pushBack(t) {
14272
- this.G(t, this._);
14273
- return this.i;
14274
- }
14275
- popBack() {
14276
- if (this.i === 0) return;
14277
- const t = this._.l;
14278
- this.V(this._);
14279
- return t;
14280
- }
14281
- pushFront(t) {
14282
- this.G(t, this.h);
14283
- return this.i;
14284
- }
14285
- popFront() {
14286
- if (this.i === 0) return;
14287
- const t = this.p.l;
14288
- this.V(this.p);
14289
- return t;
14290
- }
14291
- setElementByPos(t, i) {
14292
- if (t < 0 || t > this.i - 1) {
14293
- throw new RangeError();
14294
- }
14295
- let s = this.p;
14296
- while (t--) {
14297
- s = s.B;
14298
- }
14299
- s.l = i;
14300
- }
14301
- insert(t, i, s = 1) {
14302
- if (t < 0 || t > this.i) {
14303
- throw new RangeError();
14304
- }
14305
- if (s <= 0) return this.i;
14306
- if (t === 0) {
14307
- while (s--) this.pushFront(i);
14308
- } else if (t === this.i) {
14309
- while (s--) this.pushBack(i);
14310
- } else {
14311
- let r = this.p;
14312
- for (let i2 = 1; i2 < t; ++i2) {
14313
- r = r.B;
14314
- }
14315
- const e = r.B;
14316
- this.i += s;
14317
- while (s--) {
14318
- r.B = {
14319
- l: i,
14320
- L: r
14321
- };
14322
- r.B.L = r;
14323
- r = r.B;
14324
- }
14325
- r.B = e;
14326
- e.L = r;
14327
- }
14328
- return this.i;
14329
- }
14330
- find(t) {
14331
- let i = this.p;
14332
- while (i !== this.h) {
14333
- if (i.l === t) {
14334
- return new LinkListIterator(i, this.h, this);
14335
- }
14336
- i = i.B;
14337
- }
14338
- return this.end();
14339
- }
14340
- reverse() {
14341
- if (this.i <= 1) return;
14342
- let t = this.p;
14343
- let i = this._;
14344
- let s = 0;
14345
- while (s << 1 < this.i) {
14346
- const r = t.l;
14347
- t.l = i.l;
14348
- i.l = r;
14349
- t = t.B;
14350
- i = i.L;
14351
- s += 1;
14352
- }
14353
- }
14354
- unique() {
14355
- if (this.i <= 1) {
14356
- return this.i;
14357
- }
14358
- let t = this.p;
14359
- while (t !== this.h) {
14360
- let i = t;
14361
- while (i.B !== this.h && i.l === i.B.l) {
14362
- i = i.B;
14363
- this.i -= 1;
14364
- }
14365
- t.B = i.B;
14366
- t.B.L = t;
14367
- t = t.B;
14368
- }
14369
- return this.i;
14370
- }
14371
- sort(t) {
14372
- if (this.i <= 1) return;
14373
- const i = [];
14374
- this.forEach((function(t2) {
14375
- i.push(t2);
14376
- }));
14377
- i.sort(t);
14378
- let s = this.p;
14379
- i.forEach((function(t2) {
14380
- s.l = t2;
14381
- s = s.B;
14382
- }));
14383
- }
14384
- merge(t) {
14385
- const i = this;
14386
- if (this.i === 0) {
14387
- t.forEach((function(t2) {
14388
- i.pushBack(t2);
14389
- }));
14390
- } else {
14391
- let s = this.p;
14392
- t.forEach((function(t2) {
14393
- while (s !== i.h && s.l <= t2) {
14394
- s = s.B;
14395
- }
14396
- i.G(t2, s.L);
14397
- }));
14398
- }
14399
- return this.i;
14400
- }
14401
- forEach(t) {
14402
- let i = this.p;
14403
- let s = 0;
14404
- while (i !== this.h) {
14405
- t(i.l, s++, this);
14406
- i = i.B;
14407
- }
14408
- }
14409
- [Symbol.iterator]() {
14410
- return function* () {
14411
- if (this.i === 0) return;
14412
- let t = this.p;
14413
- while (t !== this.h) {
14414
- yield t.l;
14415
- t = t.B;
14416
- }
14417
- }.bind(this)();
14418
- }
14419
- };
14420
- var _default = LinkList;
14421
- exports8.default = _default;
14422
- }
14423
- });
14424
-
14425
- // node_modules/js-sdsl/dist/cjs/container/SequentialContainer/Deque.js
14426
- var require_Deque = __commonJS({
14427
- "node_modules/js-sdsl/dist/cjs/container/SequentialContainer/Deque.js"(exports8) {
14428
- "use strict";
14429
- init_dirname();
14430
- init_buffer2();
14431
- init_process2();
14432
- Object.defineProperty(exports8, "t", {
14433
- value: true
14434
- });
14435
- exports8.default = void 0;
14436
- var _Base = _interopRequireDefault(require_Base());
14437
- var _RandomIterator = require_RandomIterator();
14438
- function _interopRequireDefault(t) {
14439
- return t && t.t ? t : {
14440
- default: t
14441
- };
14442
- }
14443
- var DequeIterator = class _DequeIterator extends _RandomIterator.RandomIterator {
14444
- constructor(t, i, s) {
14445
- super(t, s);
14446
- this.container = i;
14447
- }
14448
- copy() {
14449
- return new _DequeIterator(this.o, this.container, this.iteratorType);
14450
- }
14451
- };
14452
- var Deque = class extends _Base.default {
14453
- constructor(t = [], i = 1 << 12) {
14454
- super();
14455
- this.j = 0;
14456
- this.D = 0;
14457
- this.R = 0;
14458
- this.N = 0;
14459
- this.P = 0;
14460
- this.A = [];
14461
- const s = (() => {
14462
- if (typeof t.length === "number") return t.length;
14463
- if (typeof t.size === "number") return t.size;
14464
- if (typeof t.size === "function") return t.size();
14465
- throw new TypeError("Cannot get the length or size of the container");
14466
- })();
14467
- this.F = i;
14468
- this.P = Math.max(Math.ceil(s / this.F), 1);
14469
- for (let t2 = 0; t2 < this.P; ++t2) {
14470
- this.A.push(new Array(this.F));
14471
- }
14472
- const h = Math.ceil(s / this.F);
14473
- this.j = this.R = (this.P >> 1) - (h >> 1);
14474
- this.D = this.N = this.F - s % this.F >> 1;
14475
- const e = this;
14476
- t.forEach((function(t2) {
14477
- e.pushBack(t2);
14478
- }));
14479
- }
14480
- T() {
14481
- const t = [];
14482
- const i = Math.max(this.P >> 1, 1);
14483
- for (let s = 0; s < i; ++s) {
14484
- t[s] = new Array(this.F);
14485
- }
14486
- for (let i2 = this.j; i2 < this.P; ++i2) {
14487
- t[t.length] = this.A[i2];
14488
- }
14489
- for (let i2 = 0; i2 < this.R; ++i2) {
14490
- t[t.length] = this.A[i2];
14491
- }
14492
- t[t.length] = [...this.A[this.R]];
14493
- this.j = i;
14494
- this.R = t.length - 1;
14495
- for (let s = 0; s < i; ++s) {
14496
- t[t.length] = new Array(this.F);
14497
- }
14498
- this.A = t;
14499
- this.P = t.length;
14500
- }
14501
- O(t) {
14502
- const i = this.D + t + 1;
14503
- const s = i % this.F;
14504
- let h = s - 1;
14505
- let e = this.j + (i - s) / this.F;
14506
- if (s === 0) e -= 1;
14507
- e %= this.P;
14508
- if (h < 0) h += this.F;
14509
- return {
14510
- curNodeBucketIndex: e,
14511
- curNodePointerIndex: h
14512
- };
14513
- }
14514
- clear() {
14515
- this.A = [new Array(this.F)];
14516
- this.P = 1;
14517
- this.j = this.R = this.i = 0;
14518
- this.D = this.N = this.F >> 1;
14519
- }
14520
- begin() {
14521
- return new DequeIterator(0, this);
14522
- }
14523
- end() {
14524
- return new DequeIterator(this.i, this);
14525
- }
14526
- rBegin() {
14527
- return new DequeIterator(this.i - 1, this, 1);
14528
- }
14529
- rEnd() {
14530
- return new DequeIterator(-1, this, 1);
14531
- }
14532
- front() {
14533
- if (this.i === 0) return;
14534
- return this.A[this.j][this.D];
14535
- }
14536
- back() {
14537
- if (this.i === 0) return;
14538
- return this.A[this.R][this.N];
14539
- }
14540
- pushBack(t) {
14541
- if (this.i) {
14542
- if (this.N < this.F - 1) {
14543
- this.N += 1;
14544
- } else if (this.R < this.P - 1) {
14545
- this.R += 1;
14546
- this.N = 0;
14547
- } else {
14548
- this.R = 0;
14549
- this.N = 0;
14550
- }
14551
- if (this.R === this.j && this.N === this.D) this.T();
14552
- }
14553
- this.i += 1;
14554
- this.A[this.R][this.N] = t;
14555
- return this.i;
14556
- }
14557
- popBack() {
14558
- if (this.i === 0) return;
14559
- const t = this.A[this.R][this.N];
14560
- if (this.i !== 1) {
14561
- if (this.N > 0) {
14562
- this.N -= 1;
14563
- } else if (this.R > 0) {
14564
- this.R -= 1;
14565
- this.N = this.F - 1;
14566
- } else {
14567
- this.R = this.P - 1;
14568
- this.N = this.F - 1;
14569
- }
14570
- }
14571
- this.i -= 1;
14572
- return t;
14573
- }
14574
- pushFront(t) {
14575
- if (this.i) {
14576
- if (this.D > 0) {
14577
- this.D -= 1;
14578
- } else if (this.j > 0) {
14579
- this.j -= 1;
14580
- this.D = this.F - 1;
14581
- } else {
14582
- this.j = this.P - 1;
14583
- this.D = this.F - 1;
14584
- }
14585
- if (this.j === this.R && this.D === this.N) this.T();
14586
- }
14587
- this.i += 1;
14588
- this.A[this.j][this.D] = t;
14589
- return this.i;
14590
- }
14591
- popFront() {
14592
- if (this.i === 0) return;
14593
- const t = this.A[this.j][this.D];
14594
- if (this.i !== 1) {
14595
- if (this.D < this.F - 1) {
14596
- this.D += 1;
14597
- } else if (this.j < this.P - 1) {
14598
- this.j += 1;
14599
- this.D = 0;
14600
- } else {
14601
- this.j = 0;
14602
- this.D = 0;
14603
- }
14604
- }
14605
- this.i -= 1;
14606
- return t;
14607
- }
14608
- getElementByPos(t) {
14609
- if (t < 0 || t > this.i - 1) {
14610
- throw new RangeError();
14611
- }
14612
- const { curNodeBucketIndex: i, curNodePointerIndex: s } = this.O(t);
14613
- return this.A[i][s];
14614
- }
14615
- setElementByPos(t, i) {
14616
- if (t < 0 || t > this.i - 1) {
14617
- throw new RangeError();
14618
- }
14619
- const { curNodeBucketIndex: s, curNodePointerIndex: h } = this.O(t);
14620
- this.A[s][h] = i;
14621
- }
14622
- insert(t, i, s = 1) {
14623
- if (t < 0 || t > this.i) {
14624
- throw new RangeError();
14625
- }
14626
- if (t === 0) {
14627
- while (s--) this.pushFront(i);
14628
- } else if (t === this.i) {
14629
- while (s--) this.pushBack(i);
14630
- } else {
14631
- const h = [];
14632
- for (let i2 = t; i2 < this.i; ++i2) {
14633
- h.push(this.getElementByPos(i2));
14634
- }
14635
- this.cut(t - 1);
14636
- for (let t2 = 0; t2 < s; ++t2) this.pushBack(i);
14637
- for (let t2 = 0; t2 < h.length; ++t2) this.pushBack(h[t2]);
14638
- }
14639
- return this.i;
14640
- }
14641
- cut(t) {
14642
- if (t < 0) {
14643
- this.clear();
14644
- return 0;
14645
- }
14646
- const { curNodeBucketIndex: i, curNodePointerIndex: s } = this.O(t);
14647
- this.R = i;
14648
- this.N = s;
14649
- this.i = t + 1;
14650
- return this.i;
14651
- }
14652
- eraseElementByPos(t) {
14653
- if (t < 0 || t > this.i - 1) {
14654
- throw new RangeError();
14655
- }
14656
- if (t === 0) this.popFront();
14657
- else if (t === this.i - 1) this.popBack();
14658
- else {
14659
- const i = [];
14660
- for (let s2 = t + 1; s2 < this.i; ++s2) {
14661
- i.push(this.getElementByPos(s2));
14662
- }
14663
- this.cut(t);
14664
- this.popBack();
14665
- const s = this;
14666
- i.forEach((function(t2) {
14667
- s.pushBack(t2);
14668
- }));
14669
- }
14670
- return this.i;
14671
- }
14672
- eraseElementByValue(t) {
14673
- if (this.i === 0) return 0;
14674
- const i = [];
14675
- for (let s2 = 0; s2 < this.i; ++s2) {
14676
- const h = this.getElementByPos(s2);
14677
- if (h !== t) i.push(h);
14678
- }
14679
- const s = i.length;
14680
- for (let t2 = 0; t2 < s; ++t2) this.setElementByPos(t2, i[t2]);
14681
- return this.cut(s - 1);
14682
- }
14683
- eraseElementByIterator(t) {
14684
- const i = t.o;
14685
- this.eraseElementByPos(i);
14686
- t = t.next();
14687
- return t;
14688
- }
14689
- find(t) {
14690
- for (let i = 0; i < this.i; ++i) {
14691
- if (this.getElementByPos(i) === t) {
14692
- return new DequeIterator(i, this);
14693
- }
14694
- }
14695
- return this.end();
14696
- }
14697
- reverse() {
14698
- let t = 0;
14699
- let i = this.i - 1;
14700
- while (t < i) {
14701
- const s = this.getElementByPos(t);
14702
- this.setElementByPos(t, this.getElementByPos(i));
14703
- this.setElementByPos(i, s);
14704
- t += 1;
14705
- i -= 1;
14706
- }
14707
- }
14708
- unique() {
14709
- if (this.i <= 1) {
14710
- return this.i;
14711
- }
14712
- let t = 1;
14713
- let i = this.getElementByPos(0);
14714
- for (let s = 1; s < this.i; ++s) {
14715
- const h = this.getElementByPos(s);
14716
- if (h !== i) {
14717
- i = h;
14718
- this.setElementByPos(t++, h);
14719
- }
14720
- }
14721
- while (this.i > t) this.popBack();
14722
- return this.i;
14723
- }
14724
- sort(t) {
14725
- const i = [];
14726
- for (let t2 = 0; t2 < this.i; ++t2) {
14727
- i.push(this.getElementByPos(t2));
14728
- }
14729
- i.sort(t);
14730
- for (let t2 = 0; t2 < this.i; ++t2) this.setElementByPos(t2, i[t2]);
14731
- }
14732
- shrinkToFit() {
14733
- if (this.i === 0) return;
14734
- const t = [];
14735
- this.forEach((function(i) {
14736
- t.push(i);
14737
- }));
14738
- this.P = Math.max(Math.ceil(this.i / this.F), 1);
14739
- this.i = this.j = this.R = this.D = this.N = 0;
14740
- this.A = [];
14741
- for (let t2 = 0; t2 < this.P; ++t2) {
14742
- this.A.push(new Array(this.F));
14743
- }
14744
- for (let i = 0; i < t.length; ++i) this.pushBack(t[i]);
14745
- }
14746
- forEach(t) {
14747
- for (let i = 0; i < this.i; ++i) {
14748
- t(this.getElementByPos(i), i, this);
14749
- }
14750
- }
14751
- [Symbol.iterator]() {
14752
- return function* () {
14753
- for (let t = 0; t < this.i; ++t) {
14754
- yield this.getElementByPos(t);
14755
- }
14756
- }.bind(this)();
14757
- }
14758
- };
14759
- var _default = Deque;
14760
- exports8.default = _default;
14761
- }
14762
- });
14763
-
14764
- // node_modules/js-sdsl/dist/cjs/container/TreeContainer/Base/TreeNode.js
14765
- var require_TreeNode = __commonJS({
14766
- "node_modules/js-sdsl/dist/cjs/container/TreeContainer/Base/TreeNode.js"(exports8) {
14767
- "use strict";
14768
- init_dirname();
14769
- init_buffer2();
14770
- init_process2();
14771
- Object.defineProperty(exports8, "t", {
14772
- value: true
14773
- });
14774
- exports8.TreeNodeEnableIndex = exports8.TreeNode = void 0;
14775
- var TreeNode = class {
14776
- constructor(e, t) {
14777
- this.ee = 1;
14778
- this.u = void 0;
14779
- this.l = void 0;
14780
- this.U = void 0;
14781
- this.W = void 0;
14782
- this.tt = void 0;
14783
- this.u = e;
14784
- this.l = t;
14785
- }
14786
- L() {
14787
- let e = this;
14788
- if (e.ee === 1 && e.tt.tt === e) {
14789
- e = e.W;
14790
- } else if (e.U) {
14791
- e = e.U;
14792
- while (e.W) {
14793
- e = e.W;
14794
- }
14795
- } else {
14796
- let t = e.tt;
14797
- while (t.U === e) {
14798
- e = t;
14799
- t = e.tt;
14800
- }
14801
- e = t;
14802
- }
14803
- return e;
14804
- }
14805
- B() {
14806
- let e = this;
14807
- if (e.W) {
14808
- e = e.W;
14809
- while (e.U) {
14810
- e = e.U;
14811
- }
14812
- return e;
14813
- } else {
14814
- let t = e.tt;
14815
- while (t.W === e) {
14816
- e = t;
14817
- t = e.tt;
14818
- }
14819
- if (e.W !== t) {
14820
- return t;
14821
- } else return e;
14822
- }
14823
- }
14824
- te() {
14825
- const e = this.tt;
14826
- const t = this.W;
14827
- const s = t.U;
14828
- if (e.tt === this) e.tt = t;
14829
- else if (e.U === this) e.U = t;
14830
- else e.W = t;
14831
- t.tt = e;
14832
- t.U = this;
14833
- this.tt = t;
14834
- this.W = s;
14835
- if (s) s.tt = this;
14836
- return t;
14837
- }
14838
- se() {
14839
- const e = this.tt;
14840
- const t = this.U;
14841
- const s = t.W;
14842
- if (e.tt === this) e.tt = t;
14843
- else if (e.U === this) e.U = t;
14844
- else e.W = t;
14845
- t.tt = e;
14846
- t.W = this;
14847
- this.tt = t;
14848
- this.U = s;
14849
- if (s) s.tt = this;
14850
- return t;
14851
- }
14852
- };
14853
- exports8.TreeNode = TreeNode;
14854
- var TreeNodeEnableIndex = class extends TreeNode {
14855
- constructor() {
14856
- super(...arguments);
14857
- this.rt = 1;
14858
- }
14859
- te() {
14860
- const e = super.te();
14861
- this.ie();
14862
- e.ie();
14863
- return e;
14864
- }
14865
- se() {
14866
- const e = super.se();
14867
- this.ie();
14868
- e.ie();
14869
- return e;
14870
- }
14871
- ie() {
14872
- this.rt = 1;
14873
- if (this.U) {
14874
- this.rt += this.U.rt;
14875
- }
14876
- if (this.W) {
14877
- this.rt += this.W.rt;
14878
- }
14879
- }
14880
- };
14881
- exports8.TreeNodeEnableIndex = TreeNodeEnableIndex;
14882
- }
14883
- });
14884
-
14885
- // node_modules/js-sdsl/dist/cjs/container/TreeContainer/Base/index.js
14886
- var require_Base2 = __commonJS({
14887
- "node_modules/js-sdsl/dist/cjs/container/TreeContainer/Base/index.js"(exports8) {
14888
- "use strict";
14889
- init_dirname();
14890
- init_buffer2();
14891
- init_process2();
14892
- Object.defineProperty(exports8, "t", {
14893
- value: true
14894
- });
14895
- exports8.default = void 0;
14896
- var _TreeNode = require_TreeNode();
14897
- var _ContainerBase = require_ContainerBase();
14898
- var _throwError = require_throwError();
14899
- var TreeContainer = class extends _ContainerBase.Container {
14900
- constructor(e = function(e2, t2) {
14901
- if (e2 < t2) return -1;
14902
- if (e2 > t2) return 1;
14903
- return 0;
14904
- }, t = false) {
14905
- super();
14906
- this.Y = void 0;
14907
- this.v = e;
14908
- if (t) {
14909
- this.re = _TreeNode.TreeNodeEnableIndex;
14910
- this.M = function(e2, t2, i) {
14911
- const s = this.ne(e2, t2, i);
14912
- if (s) {
14913
- let e3 = s.tt;
14914
- while (e3 !== this.h) {
14915
- e3.rt += 1;
14916
- e3 = e3.tt;
14917
- }
14918
- const t3 = this.he(s);
14919
- if (t3) {
14920
- const { parentNode: e4, grandParent: i2, curNode: s2 } = t3;
14921
- e4.ie();
14922
- i2.ie();
14923
- s2.ie();
14924
- }
14925
- }
14926
- return this.i;
14927
- };
14928
- this.V = function(e2) {
14929
- let t2 = this.fe(e2);
14930
- while (t2 !== this.h) {
14931
- t2.rt -= 1;
14932
- t2 = t2.tt;
14933
- }
14934
- };
14935
- } else {
14936
- this.re = _TreeNode.TreeNode;
14937
- this.M = function(e2, t2, i) {
14938
- const s = this.ne(e2, t2, i);
14939
- if (s) this.he(s);
14940
- return this.i;
14941
- };
14942
- this.V = this.fe;
14943
- }
14944
- this.h = new this.re();
14945
- }
14946
- X(e, t) {
14947
- let i = this.h;
14948
- while (e) {
14949
- const s = this.v(e.u, t);
14950
- if (s < 0) {
14951
- e = e.W;
14952
- } else if (s > 0) {
14953
- i = e;
14954
- e = e.U;
14955
- } else return e;
14956
- }
14957
- return i;
14958
- }
14959
- Z(e, t) {
14960
- let i = this.h;
14961
- while (e) {
14962
- const s = this.v(e.u, t);
14963
- if (s <= 0) {
14964
- e = e.W;
14965
- } else {
14966
- i = e;
14967
- e = e.U;
14968
- }
14969
- }
14970
- return i;
14971
- }
14972
- $(e, t) {
14973
- let i = this.h;
14974
- while (e) {
14975
- const s = this.v(e.u, t);
14976
- if (s < 0) {
14977
- i = e;
14978
- e = e.W;
14979
- } else if (s > 0) {
14980
- e = e.U;
14981
- } else return e;
14982
- }
14983
- return i;
14984
- }
14985
- rr(e, t) {
14986
- let i = this.h;
14987
- while (e) {
14988
- const s = this.v(e.u, t);
14989
- if (s < 0) {
14990
- i = e;
14991
- e = e.W;
14992
- } else {
14993
- e = e.U;
14994
- }
14995
- }
14996
- return i;
14997
- }
14998
- ue(e) {
14999
- while (true) {
15000
- const t = e.tt;
15001
- if (t === this.h) return;
15002
- if (e.ee === 1) {
15003
- e.ee = 0;
15004
- return;
15005
- }
15006
- if (e === t.U) {
15007
- const i = t.W;
15008
- if (i.ee === 1) {
15009
- i.ee = 0;
15010
- t.ee = 1;
15011
- if (t === this.Y) {
15012
- this.Y = t.te();
15013
- } else t.te();
15014
- } else {
15015
- if (i.W && i.W.ee === 1) {
15016
- i.ee = t.ee;
15017
- t.ee = 0;
15018
- i.W.ee = 0;
15019
- if (t === this.Y) {
15020
- this.Y = t.te();
15021
- } else t.te();
15022
- return;
15023
- } else if (i.U && i.U.ee === 1) {
15024
- i.ee = 1;
15025
- i.U.ee = 0;
15026
- i.se();
15027
- } else {
15028
- i.ee = 1;
15029
- e = t;
15030
- }
15031
- }
15032
- } else {
15033
- const i = t.U;
15034
- if (i.ee === 1) {
15035
- i.ee = 0;
15036
- t.ee = 1;
15037
- if (t === this.Y) {
15038
- this.Y = t.se();
15039
- } else t.se();
15040
- } else {
15041
- if (i.U && i.U.ee === 1) {
15042
- i.ee = t.ee;
15043
- t.ee = 0;
15044
- i.U.ee = 0;
15045
- if (t === this.Y) {
15046
- this.Y = t.se();
15047
- } else t.se();
15048
- return;
15049
- } else if (i.W && i.W.ee === 1) {
15050
- i.ee = 1;
15051
- i.W.ee = 0;
15052
- i.te();
15053
- } else {
15054
- i.ee = 1;
15055
- e = t;
15056
- }
15057
- }
15058
- }
15059
- }
15060
- }
15061
- fe(e) {
15062
- if (this.i === 1) {
15063
- this.clear();
15064
- return this.h;
15065
- }
15066
- let t = e;
15067
- while (t.U || t.W) {
15068
- if (t.W) {
15069
- t = t.W;
15070
- while (t.U) t = t.U;
15071
- } else {
15072
- t = t.U;
15073
- }
15074
- [e.u, t.u] = [t.u, e.u];
15075
- [e.l, t.l] = [t.l, e.l];
15076
- e = t;
15077
- }
15078
- if (this.h.U === t) {
15079
- this.h.U = t.tt;
15080
- } else if (this.h.W === t) {
15081
- this.h.W = t.tt;
15082
- }
15083
- this.ue(t);
15084
- const i = t.tt;
15085
- if (t === i.U) {
15086
- i.U = void 0;
15087
- } else i.W = void 0;
15088
- this.i -= 1;
15089
- this.Y.ee = 0;
15090
- return i;
15091
- }
15092
- oe(e, t) {
15093
- if (e === void 0) return false;
15094
- const i = this.oe(e.U, t);
15095
- if (i) return true;
15096
- if (t(e)) return true;
15097
- return this.oe(e.W, t);
15098
- }
15099
- he(e) {
15100
- while (true) {
15101
- const t = e.tt;
15102
- if (t.ee === 0) return;
15103
- const i = t.tt;
15104
- if (t === i.U) {
15105
- const s = i.W;
15106
- if (s && s.ee === 1) {
15107
- s.ee = t.ee = 0;
15108
- if (i === this.Y) return;
15109
- i.ee = 1;
15110
- e = i;
15111
- continue;
15112
- } else if (e === t.W) {
15113
- e.ee = 0;
15114
- if (e.U) e.U.tt = t;
15115
- if (e.W) e.W.tt = i;
15116
- t.W = e.U;
15117
- i.U = e.W;
15118
- e.U = t;
15119
- e.W = i;
15120
- if (i === this.Y) {
15121
- this.Y = e;
15122
- this.h.tt = e;
15123
- } else {
15124
- const t2 = i.tt;
15125
- if (t2.U === i) {
15126
- t2.U = e;
15127
- } else t2.W = e;
15128
- }
15129
- e.tt = i.tt;
15130
- t.tt = e;
15131
- i.tt = e;
15132
- i.ee = 1;
15133
- return {
15134
- parentNode: t,
15135
- grandParent: i,
15136
- curNode: e
15137
- };
15138
- } else {
15139
- t.ee = 0;
15140
- if (i === this.Y) {
15141
- this.Y = i.se();
15142
- } else i.se();
15143
- i.ee = 1;
15144
- }
15145
- } else {
15146
- const s = i.U;
15147
- if (s && s.ee === 1) {
15148
- s.ee = t.ee = 0;
15149
- if (i === this.Y) return;
15150
- i.ee = 1;
15151
- e = i;
15152
- continue;
15153
- } else if (e === t.U) {
15154
- e.ee = 0;
15155
- if (e.U) e.U.tt = i;
15156
- if (e.W) e.W.tt = t;
15157
- i.W = e.U;
15158
- t.U = e.W;
15159
- e.U = i;
15160
- e.W = t;
15161
- if (i === this.Y) {
15162
- this.Y = e;
15163
- this.h.tt = e;
15164
- } else {
15165
- const t2 = i.tt;
15166
- if (t2.U === i) {
15167
- t2.U = e;
15168
- } else t2.W = e;
15169
- }
15170
- e.tt = i.tt;
15171
- t.tt = e;
15172
- i.tt = e;
15173
- i.ee = 1;
15174
- return {
15175
- parentNode: t,
15176
- grandParent: i,
15177
- curNode: e
15178
- };
15179
- } else {
15180
- t.ee = 0;
15181
- if (i === this.Y) {
15182
- this.Y = i.te();
15183
- } else i.te();
15184
- i.ee = 1;
15185
- }
15186
- }
15187
- return;
15188
- }
15189
- }
15190
- ne(e, t, i) {
15191
- if (this.Y === void 0) {
15192
- this.i += 1;
15193
- this.Y = new this.re(e, t);
15194
- this.Y.ee = 0;
15195
- this.Y.tt = this.h;
15196
- this.h.tt = this.Y;
15197
- this.h.U = this.Y;
15198
- this.h.W = this.Y;
15199
- return;
15200
- }
15201
- let s;
15202
- const r = this.h.U;
15203
- const n = this.v(r.u, e);
15204
- if (n === 0) {
15205
- r.l = t;
15206
- return;
15207
- } else if (n > 0) {
15208
- r.U = new this.re(e, t);
15209
- r.U.tt = r;
15210
- s = r.U;
15211
- this.h.U = s;
15212
- } else {
15213
- const r2 = this.h.W;
15214
- const n2 = this.v(r2.u, e);
15215
- if (n2 === 0) {
15216
- r2.l = t;
15217
- return;
15218
- } else if (n2 < 0) {
15219
- r2.W = new this.re(e, t);
15220
- r2.W.tt = r2;
15221
- s = r2.W;
15222
- this.h.W = s;
15223
- } else {
15224
- if (i !== void 0) {
15225
- const r3 = i.o;
15226
- if (r3 !== this.h) {
15227
- const i2 = this.v(r3.u, e);
15228
- if (i2 === 0) {
15229
- r3.l = t;
15230
- return;
15231
- } else if (i2 > 0) {
15232
- const i3 = r3.L();
15233
- const n3 = this.v(i3.u, e);
15234
- if (n3 === 0) {
15235
- i3.l = t;
15236
- return;
15237
- } else if (n3 < 0) {
15238
- s = new this.re(e, t);
15239
- if (i3.W === void 0) {
15240
- i3.W = s;
15241
- s.tt = i3;
15242
- } else {
15243
- r3.U = s;
15244
- s.tt = r3;
15245
- }
15246
- }
15247
- }
15248
- }
15249
- }
15250
- if (s === void 0) {
15251
- s = this.Y;
15252
- while (true) {
15253
- const i2 = this.v(s.u, e);
15254
- if (i2 > 0) {
15255
- if (s.U === void 0) {
15256
- s.U = new this.re(e, t);
15257
- s.U.tt = s;
15258
- s = s.U;
15259
- break;
15260
- }
15261
- s = s.U;
15262
- } else if (i2 < 0) {
15263
- if (s.W === void 0) {
15264
- s.W = new this.re(e, t);
15265
- s.W.tt = s;
15266
- s = s.W;
15267
- break;
15268
- }
15269
- s = s.W;
15270
- } else {
15271
- s.l = t;
15272
- return;
15273
- }
15274
- }
15275
- }
15276
- }
15277
- }
15278
- this.i += 1;
15279
- return s;
15280
- }
15281
- I(e, t) {
15282
- while (e) {
15283
- const i = this.v(e.u, t);
15284
- if (i < 0) {
15285
- e = e.W;
15286
- } else if (i > 0) {
15287
- e = e.U;
15288
- } else return e;
15289
- }
15290
- return e || this.h;
15291
- }
15292
- clear() {
15293
- this.i = 0;
15294
- this.Y = void 0;
15295
- this.h.tt = void 0;
15296
- this.h.U = this.h.W = void 0;
15297
- }
15298
- updateKeyByIterator(e, t) {
15299
- const i = e.o;
15300
- if (i === this.h) {
15301
- (0, _throwError.throwIteratorAccessError)();
15302
- }
15303
- if (this.i === 1) {
15304
- i.u = t;
15305
- return true;
15306
- }
15307
- if (i === this.h.U) {
15308
- if (this.v(i.B().u, t) > 0) {
15309
- i.u = t;
15310
- return true;
15311
- }
15312
- return false;
15313
- }
15314
- if (i === this.h.W) {
15315
- if (this.v(i.L().u, t) < 0) {
15316
- i.u = t;
15317
- return true;
15318
- }
15319
- return false;
15320
- }
15321
- const s = i.L().u;
15322
- if (this.v(s, t) >= 0) return false;
15323
- const r = i.B().u;
15324
- if (this.v(r, t) <= 0) return false;
15325
- i.u = t;
15326
- return true;
15327
- }
15328
- eraseElementByPos(e) {
15329
- if (e < 0 || e > this.i - 1) {
15330
- throw new RangeError();
15331
- }
15332
- let t = 0;
15333
- const i = this;
15334
- this.oe(this.Y, (function(s) {
15335
- if (e === t) {
15336
- i.V(s);
15337
- return true;
15338
- }
15339
- t += 1;
15340
- return false;
15341
- }));
15342
- return this.i;
15343
- }
15344
- eraseElementByKey(e) {
15345
- if (this.i === 0) return false;
15346
- const t = this.I(this.Y, e);
15347
- if (t === this.h) return false;
15348
- this.V(t);
15349
- return true;
15350
- }
15351
- eraseElementByIterator(e) {
15352
- const t = e.o;
15353
- if (t === this.h) {
15354
- (0, _throwError.throwIteratorAccessError)();
15355
- }
15356
- const i = t.W === void 0;
15357
- const s = e.iteratorType === 0;
15358
- if (s) {
15359
- if (i) e.next();
15360
- } else {
15361
- if (!i || t.U === void 0) e.next();
15362
- }
15363
- this.V(t);
15364
- return e;
15365
- }
15366
- forEach(e) {
15367
- let t = 0;
15368
- for (const i of this) e(i, t++, this);
15369
- }
15370
- getElementByPos(e) {
15371
- if (e < 0 || e > this.i - 1) {
15372
- throw new RangeError();
15373
- }
15374
- let t;
15375
- let i = 0;
15376
- for (const s of this) {
15377
- if (i === e) {
15378
- t = s;
15379
- break;
15380
- }
15381
- i += 1;
15382
- }
15383
- return t;
15384
- }
15385
- getHeight() {
15386
- if (this.i === 0) return 0;
15387
- const traversal = function(e) {
15388
- if (!e) return 0;
15389
- return Math.max(traversal(e.U), traversal(e.W)) + 1;
15390
- };
15391
- return traversal(this.Y);
15392
- }
15393
- };
15394
- var _default = TreeContainer;
15395
- exports8.default = _default;
15396
- }
15397
- });
15398
-
15399
- // node_modules/js-sdsl/dist/cjs/container/TreeContainer/Base/TreeIterator.js
15400
- var require_TreeIterator = __commonJS({
15401
- "node_modules/js-sdsl/dist/cjs/container/TreeContainer/Base/TreeIterator.js"(exports8) {
15402
- "use strict";
15403
- init_dirname();
15404
- init_buffer2();
15405
- init_process2();
15406
- Object.defineProperty(exports8, "t", {
15407
- value: true
15408
- });
15409
- exports8.default = void 0;
15410
- var _ContainerBase = require_ContainerBase();
15411
- var _throwError = require_throwError();
15412
- var TreeIterator = class extends _ContainerBase.ContainerIterator {
15413
- constructor(t, r, i) {
15414
- super(i);
15415
- this.o = t;
15416
- this.h = r;
15417
- if (this.iteratorType === 0) {
15418
- this.pre = function() {
15419
- if (this.o === this.h.U) {
15420
- (0, _throwError.throwIteratorAccessError)();
15421
- }
15422
- this.o = this.o.L();
15423
- return this;
15424
- };
15425
- this.next = function() {
15426
- if (this.o === this.h) {
15427
- (0, _throwError.throwIteratorAccessError)();
15428
- }
15429
- this.o = this.o.B();
15430
- return this;
15431
- };
15432
- } else {
15433
- this.pre = function() {
15434
- if (this.o === this.h.W) {
15435
- (0, _throwError.throwIteratorAccessError)();
15436
- }
15437
- this.o = this.o.B();
15438
- return this;
15439
- };
15440
- this.next = function() {
15441
- if (this.o === this.h) {
15442
- (0, _throwError.throwIteratorAccessError)();
15443
- }
15444
- this.o = this.o.L();
15445
- return this;
15446
- };
15447
- }
15448
- }
15449
- get index() {
15450
- let t = this.o;
15451
- const r = this.h.tt;
15452
- if (t === this.h) {
15453
- if (r) {
15454
- return r.rt - 1;
15455
- }
15456
- return 0;
15457
- }
15458
- let i = 0;
15459
- if (t.U) {
15460
- i += t.U.rt;
15461
- }
15462
- while (t !== r) {
15463
- const r2 = t.tt;
15464
- if (t === r2.W) {
15465
- i += 1;
15466
- if (r2.U) {
15467
- i += r2.U.rt;
15468
- }
15469
- }
15470
- t = r2;
15471
- }
15472
- return i;
15473
- }
15474
- };
15475
- var _default = TreeIterator;
15476
- exports8.default = _default;
15477
- }
15478
- });
15479
-
15480
- // node_modules/js-sdsl/dist/cjs/container/TreeContainer/OrderedSet.js
15481
- var require_OrderedSet = __commonJS({
15482
- "node_modules/js-sdsl/dist/cjs/container/TreeContainer/OrderedSet.js"(exports8) {
15483
- "use strict";
15484
- init_dirname();
15485
- init_buffer2();
15486
- init_process2();
15487
- Object.defineProperty(exports8, "t", {
15488
- value: true
15489
- });
15490
- exports8.default = void 0;
15491
- var _Base = _interopRequireDefault(require_Base2());
15492
- var _TreeIterator = _interopRequireDefault(require_TreeIterator());
15493
- var _throwError = require_throwError();
15494
- function _interopRequireDefault(e) {
15495
- return e && e.t ? e : {
15496
- default: e
15497
- };
15498
- }
15499
- var OrderedSetIterator = class _OrderedSetIterator extends _TreeIterator.default {
15500
- constructor(e, t, r, i) {
15501
- super(e, t, i);
15502
- this.container = r;
15503
- }
15504
- get pointer() {
15505
- if (this.o === this.h) {
15506
- (0, _throwError.throwIteratorAccessError)();
15507
- }
15508
- return this.o.u;
15509
- }
15510
- copy() {
15511
- return new _OrderedSetIterator(this.o, this.h, this.container, this.iteratorType);
15512
- }
15513
- };
15514
- var OrderedSet = class extends _Base.default {
15515
- constructor(e = [], t, r) {
15516
- super(t, r);
15517
- const i = this;
15518
- e.forEach((function(e2) {
15519
- i.insert(e2);
15520
- }));
15521
- }
15522
- *K(e) {
15523
- if (e === void 0) return;
15524
- yield* this.K(e.U);
15525
- yield e.u;
15526
- yield* this.K(e.W);
15527
- }
15528
- begin() {
15529
- return new OrderedSetIterator(this.h.U || this.h, this.h, this);
15530
- }
15531
- end() {
15532
- return new OrderedSetIterator(this.h, this.h, this);
15533
- }
15534
- rBegin() {
15535
- return new OrderedSetIterator(this.h.W || this.h, this.h, this, 1);
15536
- }
15537
- rEnd() {
15538
- return new OrderedSetIterator(this.h, this.h, this, 1);
15539
- }
15540
- front() {
15541
- return this.h.U ? this.h.U.u : void 0;
15542
- }
15543
- back() {
15544
- return this.h.W ? this.h.W.u : void 0;
15545
- }
15546
- insert(e, t) {
15547
- return this.M(e, void 0, t);
15548
- }
15549
- find(e) {
15550
- const t = this.I(this.Y, e);
15551
- return new OrderedSetIterator(t, this.h, this);
15552
- }
15553
- lowerBound(e) {
15554
- const t = this.X(this.Y, e);
15555
- return new OrderedSetIterator(t, this.h, this);
15556
- }
15557
- upperBound(e) {
15558
- const t = this.Z(this.Y, e);
15559
- return new OrderedSetIterator(t, this.h, this);
15560
- }
15561
- reverseLowerBound(e) {
15562
- const t = this.$(this.Y, e);
15563
- return new OrderedSetIterator(t, this.h, this);
15564
- }
15565
- reverseUpperBound(e) {
15566
- const t = this.rr(this.Y, e);
15567
- return new OrderedSetIterator(t, this.h, this);
15568
- }
15569
- union(e) {
15570
- const t = this;
15571
- e.forEach((function(e2) {
15572
- t.insert(e2);
15573
- }));
15574
- return this.i;
15575
- }
15576
- [Symbol.iterator]() {
15577
- return this.K(this.Y);
15578
- }
15579
- };
15580
- var _default = OrderedSet;
15581
- exports8.default = _default;
15582
- }
15583
- });
15584
-
15585
- // node_modules/js-sdsl/dist/cjs/container/TreeContainer/OrderedMap.js
15586
- var require_OrderedMap = __commonJS({
15587
- "node_modules/js-sdsl/dist/cjs/container/TreeContainer/OrderedMap.js"(exports8) {
15588
- "use strict";
15589
- init_dirname();
15590
- init_buffer2();
15591
- init_process2();
15592
- Object.defineProperty(exports8, "t", {
15593
- value: true
15594
- });
15595
- exports8.default = void 0;
15596
- var _Base = _interopRequireDefault(require_Base2());
15597
- var _TreeIterator = _interopRequireDefault(require_TreeIterator());
15598
- var _throwError = require_throwError();
15599
- function _interopRequireDefault(r) {
15600
- return r && r.t ? r : {
15601
- default: r
15602
- };
15603
- }
15604
- var OrderedMapIterator = class _OrderedMapIterator extends _TreeIterator.default {
15605
- constructor(r, t, e, s) {
15606
- super(r, t, s);
15607
- this.container = e;
15608
- }
15609
- get pointer() {
15610
- if (this.o === this.h) {
15611
- (0, _throwError.throwIteratorAccessError)();
15612
- }
15613
- const r = this;
15614
- return new Proxy([], {
15615
- get(t, e) {
15616
- if (e === "0") return r.o.u;
15617
- else if (e === "1") return r.o.l;
15618
- },
15619
- set(t, e, s) {
15620
- if (e !== "1") {
15621
- throw new TypeError("props must be 1");
15622
- }
15623
- r.o.l = s;
15624
- return true;
15625
- }
15626
- });
15627
- }
15628
- copy() {
15629
- return new _OrderedMapIterator(this.o, this.h, this.container, this.iteratorType);
15630
- }
15631
- };
15632
- var OrderedMap = class extends _Base.default {
15633
- constructor(r = [], t, e) {
15634
- super(t, e);
15635
- const s = this;
15636
- r.forEach((function(r2) {
15637
- s.setElement(r2[0], r2[1]);
15638
- }));
15639
- }
15640
- *K(r) {
15641
- if (r === void 0) return;
15642
- yield* this.K(r.U);
15643
- yield [r.u, r.l];
15644
- yield* this.K(r.W);
15645
- }
15646
- begin() {
15647
- return new OrderedMapIterator(this.h.U || this.h, this.h, this);
15648
- }
15649
- end() {
15650
- return new OrderedMapIterator(this.h, this.h, this);
15651
- }
15652
- rBegin() {
15653
- return new OrderedMapIterator(this.h.W || this.h, this.h, this, 1);
15654
- }
15655
- rEnd() {
15656
- return new OrderedMapIterator(this.h, this.h, this, 1);
15657
- }
15658
- front() {
15659
- if (this.i === 0) return;
15660
- const r = this.h.U;
15661
- return [r.u, r.l];
15662
- }
15663
- back() {
15664
- if (this.i === 0) return;
15665
- const r = this.h.W;
15666
- return [r.u, r.l];
15667
- }
15668
- lowerBound(r) {
15669
- const t = this.X(this.Y, r);
15670
- return new OrderedMapIterator(t, this.h, this);
15671
- }
15672
- upperBound(r) {
15673
- const t = this.Z(this.Y, r);
15674
- return new OrderedMapIterator(t, this.h, this);
15675
- }
15676
- reverseLowerBound(r) {
15677
- const t = this.$(this.Y, r);
15678
- return new OrderedMapIterator(t, this.h, this);
15679
- }
15680
- reverseUpperBound(r) {
15681
- const t = this.rr(this.Y, r);
15682
- return new OrderedMapIterator(t, this.h, this);
15683
- }
15684
- setElement(r, t, e) {
15685
- return this.M(r, t, e);
15686
- }
15687
- find(r) {
15688
- const t = this.I(this.Y, r);
15689
- return new OrderedMapIterator(t, this.h, this);
15690
- }
15691
- getElementByKey(r) {
15692
- const t = this.I(this.Y, r);
15693
- return t.l;
15694
- }
15695
- union(r) {
15696
- const t = this;
15697
- r.forEach((function(r2) {
15698
- t.setElement(r2[0], r2[1]);
15699
- }));
15700
- return this.i;
15701
- }
15702
- [Symbol.iterator]() {
15703
- return this.K(this.Y);
15704
- }
15705
- };
15706
- var _default = OrderedMap;
15707
- exports8.default = _default;
15708
- }
15709
- });
15710
-
15711
- // node_modules/js-sdsl/dist/cjs/utils/checkObject.js
15712
- var require_checkObject = __commonJS({
15713
- "node_modules/js-sdsl/dist/cjs/utils/checkObject.js"(exports8) {
15714
- "use strict";
15715
- init_dirname();
15716
- init_buffer2();
15717
- init_process2();
15718
- Object.defineProperty(exports8, "t", {
15719
- value: true
15720
- });
15721
- exports8.default = checkObject;
15722
- function checkObject(e) {
15723
- const t = typeof e;
15724
- return t === "object" && e !== null || t === "function";
15725
- }
15726
- }
15727
- });
15728
-
15729
- // node_modules/js-sdsl/dist/cjs/container/HashContainer/Base/index.js
15730
- var require_Base3 = __commonJS({
15731
- "node_modules/js-sdsl/dist/cjs/container/HashContainer/Base/index.js"(exports8) {
15732
- "use strict";
15733
- init_dirname();
15734
- init_buffer2();
15735
- init_process2();
15736
- Object.defineProperty(exports8, "t", {
15737
- value: true
15738
- });
15739
- exports8.HashContainerIterator = exports8.HashContainer = void 0;
15740
- var _ContainerBase = require_ContainerBase();
15741
- var _checkObject = _interopRequireDefault(require_checkObject());
15742
- var _throwError = require_throwError();
15743
- function _interopRequireDefault(t) {
15744
- return t && t.t ? t : {
15745
- default: t
15746
- };
15747
- }
15748
- var HashContainerIterator = class extends _ContainerBase.ContainerIterator {
15749
- constructor(t, e, i) {
15750
- super(i);
15751
- this.o = t;
15752
- this.h = e;
15753
- if (this.iteratorType === 0) {
15754
- this.pre = function() {
15755
- if (this.o.L === this.h) {
15756
- (0, _throwError.throwIteratorAccessError)();
15757
- }
15758
- this.o = this.o.L;
15759
- return this;
15760
- };
15761
- this.next = function() {
15762
- if (this.o === this.h) {
15763
- (0, _throwError.throwIteratorAccessError)();
15764
- }
15765
- this.o = this.o.B;
15766
- return this;
15767
- };
15768
- } else {
15769
- this.pre = function() {
15770
- if (this.o.B === this.h) {
15771
- (0, _throwError.throwIteratorAccessError)();
15772
- }
15773
- this.o = this.o.B;
15774
- return this;
15775
- };
15776
- this.next = function() {
15777
- if (this.o === this.h) {
15778
- (0, _throwError.throwIteratorAccessError)();
15779
- }
15780
- this.o = this.o.L;
15781
- return this;
15782
- };
15783
- }
15784
- }
15785
- };
15786
- exports8.HashContainerIterator = HashContainerIterator;
15787
- var HashContainer = class extends _ContainerBase.Container {
15788
- constructor() {
15789
- super();
15790
- this.H = [];
15791
- this.g = {};
15792
- this.HASH_TAG = Symbol("@@HASH_TAG");
15793
- Object.setPrototypeOf(this.g, null);
15794
- this.h = {};
15795
- this.h.L = this.h.B = this.p = this._ = this.h;
15796
- }
15797
- V(t) {
15798
- const { L: e, B: i } = t;
15799
- e.B = i;
15800
- i.L = e;
15801
- if (t === this.p) {
15802
- this.p = i;
15803
- }
15804
- if (t === this._) {
15805
- this._ = e;
15806
- }
15807
- this.i -= 1;
15808
- }
15809
- M(t, e, i) {
15810
- if (i === void 0) i = (0, _checkObject.default)(t);
15811
- let s;
15812
- if (i) {
15813
- const i2 = t[this.HASH_TAG];
15814
- if (i2 !== void 0) {
15815
- this.H[i2].l = e;
15816
- return this.i;
15817
- }
15818
- Object.defineProperty(t, this.HASH_TAG, {
15819
- value: this.H.length,
15820
- configurable: true
15821
- });
15822
- s = {
15823
- u: t,
15824
- l: e,
15825
- L: this._,
15826
- B: this.h
15827
- };
15828
- this.H.push(s);
15829
- } else {
15830
- const i2 = this.g[t];
15831
- if (i2) {
15832
- i2.l = e;
15833
- return this.i;
15834
- }
15835
- s = {
15836
- u: t,
15837
- l: e,
15838
- L: this._,
15839
- B: this.h
15840
- };
15841
- this.g[t] = s;
15842
- }
15843
- if (this.i === 0) {
15844
- this.p = s;
15845
- this.h.B = s;
15846
- } else {
15847
- this._.B = s;
15848
- }
15849
- this._ = s;
15850
- this.h.L = s;
15851
- return ++this.i;
15852
- }
15853
- I(t, e) {
15854
- if (e === void 0) e = (0, _checkObject.default)(t);
15855
- if (e) {
15856
- const e2 = t[this.HASH_TAG];
15857
- if (e2 === void 0) return this.h;
15858
- return this.H[e2];
15859
- } else {
15860
- return this.g[t] || this.h;
15861
- }
15862
- }
15863
- clear() {
15864
- const t = this.HASH_TAG;
15865
- this.H.forEach((function(e) {
15866
- delete e.u[t];
15867
- }));
15868
- this.H = [];
15869
- this.g = {};
15870
- Object.setPrototypeOf(this.g, null);
15871
- this.i = 0;
15872
- this.p = this._ = this.h.L = this.h.B = this.h;
15873
- }
15874
- eraseElementByKey(t, e) {
15875
- let i;
15876
- if (e === void 0) e = (0, _checkObject.default)(t);
15877
- if (e) {
15878
- const e2 = t[this.HASH_TAG];
15879
- if (e2 === void 0) return false;
15880
- delete t[this.HASH_TAG];
15881
- i = this.H[e2];
15882
- delete this.H[e2];
15883
- } else {
15884
- i = this.g[t];
15885
- if (i === void 0) return false;
15886
- delete this.g[t];
15887
- }
15888
- this.V(i);
15889
- return true;
15890
- }
15891
- eraseElementByIterator(t) {
15892
- const e = t.o;
15893
- if (e === this.h) {
15894
- (0, _throwError.throwIteratorAccessError)();
15895
- }
15896
- this.V(e);
15897
- return t.next();
15898
- }
15899
- eraseElementByPos(t) {
15900
- if (t < 0 || t > this.i - 1) {
15901
- throw new RangeError();
15902
- }
15903
- let e = this.p;
15904
- while (t--) {
15905
- e = e.B;
15906
- }
15907
- this.V(e);
15908
- return this.i;
15909
- }
15910
- };
15911
- exports8.HashContainer = HashContainer;
15912
- }
15913
- });
15914
-
15915
- // node_modules/js-sdsl/dist/cjs/container/HashContainer/HashSet.js
15916
- var require_HashSet = __commonJS({
15917
- "node_modules/js-sdsl/dist/cjs/container/HashContainer/HashSet.js"(exports8) {
15918
- "use strict";
15919
- init_dirname();
15920
- init_buffer2();
15921
- init_process2();
15922
- Object.defineProperty(exports8, "t", {
15923
- value: true
15924
- });
15925
- exports8.default = void 0;
15926
- var _Base = require_Base3();
15927
- var _throwError = require_throwError();
15928
- var HashSetIterator = class _HashSetIterator extends _Base.HashContainerIterator {
15929
- constructor(t, e, r, s) {
15930
- super(t, e, s);
15931
- this.container = r;
15932
- }
15933
- get pointer() {
15934
- if (this.o === this.h) {
15935
- (0, _throwError.throwIteratorAccessError)();
15936
- }
15937
- return this.o.u;
15938
- }
15939
- copy() {
15940
- return new _HashSetIterator(this.o, this.h, this.container, this.iteratorType);
15941
- }
15942
- };
15943
- var HashSet = class extends _Base.HashContainer {
15944
- constructor(t = []) {
15945
- super();
15946
- const e = this;
15947
- t.forEach((function(t2) {
15948
- e.insert(t2);
15949
- }));
15950
- }
15951
- begin() {
15952
- return new HashSetIterator(this.p, this.h, this);
15953
- }
15954
- end() {
15955
- return new HashSetIterator(this.h, this.h, this);
15956
- }
15957
- rBegin() {
15958
- return new HashSetIterator(this._, this.h, this, 1);
15959
- }
15960
- rEnd() {
15961
- return new HashSetIterator(this.h, this.h, this, 1);
15962
- }
15963
- front() {
15964
- return this.p.u;
15965
- }
15966
- back() {
15967
- return this._.u;
15968
- }
15969
- insert(t, e) {
15970
- return this.M(t, void 0, e);
15971
- }
15972
- getElementByPos(t) {
15973
- if (t < 0 || t > this.i - 1) {
15974
- throw new RangeError();
15975
- }
15976
- let e = this.p;
15977
- while (t--) {
15978
- e = e.B;
15979
- }
15980
- return e.u;
15981
- }
15982
- find(t, e) {
15983
- const r = this.I(t, e);
15984
- return new HashSetIterator(r, this.h, this);
15985
- }
15986
- forEach(t) {
15987
- let e = 0;
15988
- let r = this.p;
15989
- while (r !== this.h) {
15990
- t(r.u, e++, this);
15991
- r = r.B;
13570
+ this.#valList[index] = void 0;
13571
+ if (index === this.#tail) {
13572
+ this.#tail = this.#prev[index];
13573
+ } else if (index === this.#head) {
13574
+ this.#head = this.#next[index];
13575
+ } else {
13576
+ const pi = this.#prev[index];
13577
+ this.#next[pi] = this.#next[index];
13578
+ const ni = this.#next[index];
13579
+ this.#prev[ni] = this.#prev[index];
13580
+ }
13581
+ this.#size--;
13582
+ this.#free.push(index);
13583
+ }
13584
+ }
15992
13585
  }
15993
- }
15994
- [Symbol.iterator]() {
15995
- return function* () {
15996
- let t = this.p;
15997
- while (t !== this.h) {
15998
- yield t.u;
15999
- t = t.B;
13586
+ if (this.#hasDisposeAfter && this.#disposed?.length) {
13587
+ const dt = this.#disposed;
13588
+ let task;
13589
+ while (task = dt?.shift()) {
13590
+ this.#disposeAfter?.(...task);
16000
13591
  }
16001
- }.bind(this)();
13592
+ }
13593
+ return deleted;
16002
13594
  }
16003
- };
16004
- var _default = HashSet;
16005
- exports8.default = _default;
16006
- }
16007
- });
16008
-
16009
- // node_modules/js-sdsl/dist/cjs/container/HashContainer/HashMap.js
16010
- var require_HashMap = __commonJS({
16011
- "node_modules/js-sdsl/dist/cjs/container/HashContainer/HashMap.js"(exports8) {
16012
- "use strict";
16013
- init_dirname();
16014
- init_buffer2();
16015
- init_process2();
16016
- Object.defineProperty(exports8, "t", {
16017
- value: true
16018
- });
16019
- exports8.default = void 0;
16020
- var _Base = require_Base3();
16021
- var _checkObject = _interopRequireDefault(require_checkObject());
16022
- var _throwError = require_throwError();
16023
- function _interopRequireDefault(t) {
16024
- return t && t.t ? t : {
16025
- default: t
16026
- };
16027
- }
16028
- var HashMapIterator = class _HashMapIterator extends _Base.HashContainerIterator {
16029
- constructor(t, e, r, s) {
16030
- super(t, e, s);
16031
- this.container = r;
13595
+ /**
13596
+ * Clear the cache entirely, throwing away all values.
13597
+ */
13598
+ clear() {
13599
+ return this.#clear("delete");
16032
13600
  }
16033
- get pointer() {
16034
- if (this.o === this.h) {
16035
- (0, _throwError.throwIteratorAccessError)();
16036
- }
16037
- const t = this;
16038
- return new Proxy([], {
16039
- get(e, r) {
16040
- if (r === "0") return t.o.u;
16041
- else if (r === "1") return t.o.l;
16042
- },
16043
- set(e, r, s) {
16044
- if (r !== "1") {
16045
- throw new TypeError("props must be 1");
13601
+ #clear(reason) {
13602
+ for (const index of this.#rindexes({ allowStale: true })) {
13603
+ const v = this.#valList[index];
13604
+ if (this.#isBackgroundFetch(v)) {
13605
+ v.__abortController.abort(new Error("deleted"));
13606
+ } else {
13607
+ const k = this.#keyList[index];
13608
+ if (this.#hasDispose) {
13609
+ this.#dispose?.(v, k, reason);
13610
+ }
13611
+ if (this.#hasDisposeAfter) {
13612
+ this.#disposed?.push([v, k, reason]);
16046
13613
  }
16047
- t.o.l = s;
16048
- return true;
16049
13614
  }
16050
- });
16051
- }
16052
- copy() {
16053
- return new _HashMapIterator(this.o, this.h, this.container, this.iteratorType);
16054
- }
16055
- };
16056
- var HashMap = class extends _Base.HashContainer {
16057
- constructor(t = []) {
16058
- super();
16059
- const e = this;
16060
- t.forEach((function(t2) {
16061
- e.setElement(t2[0], t2[1]);
16062
- }));
16063
- }
16064
- begin() {
16065
- return new HashMapIterator(this.p, this.h, this);
16066
- }
16067
- end() {
16068
- return new HashMapIterator(this.h, this.h, this);
16069
- }
16070
- rBegin() {
16071
- return new HashMapIterator(this._, this.h, this, 1);
16072
- }
16073
- rEnd() {
16074
- return new HashMapIterator(this.h, this.h, this, 1);
16075
- }
16076
- front() {
16077
- if (this.i === 0) return;
16078
- return [this.p.u, this.p.l];
16079
- }
16080
- back() {
16081
- if (this.i === 0) return;
16082
- return [this._.u, this._.l];
16083
- }
16084
- setElement(t, e, r) {
16085
- return this.M(t, e, r);
16086
- }
16087
- getElementByKey(t, e) {
16088
- if (e === void 0) e = (0, _checkObject.default)(t);
16089
- if (e) {
16090
- const e2 = t[this.HASH_TAG];
16091
- return e2 !== void 0 ? this.H[e2].l : void 0;
16092
13615
  }
16093
- const r = this.g[t];
16094
- return r ? r.l : void 0;
16095
- }
16096
- getElementByPos(t) {
16097
- if (t < 0 || t > this.i - 1) {
16098
- throw new RangeError();
16099
- }
16100
- let e = this.p;
16101
- while (t--) {
16102
- e = e.B;
13616
+ this.#keyMap.clear();
13617
+ this.#valList.fill(void 0);
13618
+ this.#keyList.fill(void 0);
13619
+ if (this.#ttls && this.#starts) {
13620
+ this.#ttls.fill(0);
13621
+ this.#starts.fill(0);
16103
13622
  }
16104
- return [e.u, e.l];
16105
- }
16106
- find(t, e) {
16107
- const r = this.I(t, e);
16108
- return new HashMapIterator(r, this.h, this);
16109
- }
16110
- forEach(t) {
16111
- let e = 0;
16112
- let r = this.p;
16113
- while (r !== this.h) {
16114
- t([r.u, r.l], e++, this);
16115
- r = r.B;
13623
+ if (this.#sizes) {
13624
+ this.#sizes.fill(0);
16116
13625
  }
16117
- }
16118
- [Symbol.iterator]() {
16119
- return function* () {
16120
- let t = this.p;
16121
- while (t !== this.h) {
16122
- yield [t.u, t.l];
16123
- t = t.B;
13626
+ this.#head = 0;
13627
+ this.#tail = 0;
13628
+ this.#free.length = 0;
13629
+ this.#calculatedSize = 0;
13630
+ this.#size = 0;
13631
+ if (this.#hasDisposeAfter && this.#disposed) {
13632
+ const dt = this.#disposed;
13633
+ let task;
13634
+ while (task = dt?.shift()) {
13635
+ this.#disposeAfter?.(...task);
16124
13636
  }
16125
- }.bind(this)();
13637
+ }
16126
13638
  }
16127
13639
  };
16128
- var _default = HashMap;
16129
- exports8.default = _default;
16130
- }
16131
- });
16132
-
16133
- // node_modules/js-sdsl/dist/cjs/index.js
16134
- var require_cjs = __commonJS({
16135
- "node_modules/js-sdsl/dist/cjs/index.js"(exports8) {
16136
- "use strict";
16137
- init_dirname();
16138
- init_buffer2();
16139
- init_process2();
16140
- Object.defineProperty(exports8, "t", {
16141
- value: true
16142
- });
16143
- Object.defineProperty(exports8, "Deque", {
16144
- enumerable: true,
16145
- get: function() {
16146
- return _Deque.default;
16147
- }
16148
- });
16149
- Object.defineProperty(exports8, "HashMap", {
16150
- enumerable: true,
16151
- get: function() {
16152
- return _HashMap.default;
16153
- }
16154
- });
16155
- Object.defineProperty(exports8, "HashSet", {
16156
- enumerable: true,
16157
- get: function() {
16158
- return _HashSet.default;
16159
- }
16160
- });
16161
- Object.defineProperty(exports8, "LinkList", {
16162
- enumerable: true,
16163
- get: function() {
16164
- return _LinkList.default;
16165
- }
16166
- });
16167
- Object.defineProperty(exports8, "OrderedMap", {
16168
- enumerable: true,
16169
- get: function() {
16170
- return _OrderedMap.default;
16171
- }
16172
- });
16173
- Object.defineProperty(exports8, "OrderedSet", {
16174
- enumerable: true,
16175
- get: function() {
16176
- return _OrderedSet.default;
16177
- }
16178
- });
16179
- Object.defineProperty(exports8, "PriorityQueue", {
16180
- enumerable: true,
16181
- get: function() {
16182
- return _PriorityQueue.default;
16183
- }
16184
- });
16185
- Object.defineProperty(exports8, "Queue", {
16186
- enumerable: true,
16187
- get: function() {
16188
- return _Queue.default;
16189
- }
16190
- });
16191
- Object.defineProperty(exports8, "Stack", {
16192
- enumerable: true,
16193
- get: function() {
16194
- return _Stack.default;
16195
- }
16196
- });
16197
- Object.defineProperty(exports8, "Vector", {
16198
- enumerable: true,
16199
- get: function() {
16200
- return _Vector.default;
16201
- }
16202
- });
16203
- var _Stack = _interopRequireDefault(require_Stack());
16204
- var _Queue = _interopRequireDefault(require_Queue());
16205
- var _PriorityQueue = _interopRequireDefault(require_PriorityQueue());
16206
- var _Vector = _interopRequireDefault(require_Vector());
16207
- var _LinkList = _interopRequireDefault(require_LinkList());
16208
- var _Deque = _interopRequireDefault(require_Deque());
16209
- var _OrderedSet = _interopRequireDefault(require_OrderedSet());
16210
- var _OrderedMap = _interopRequireDefault(require_OrderedMap());
16211
- var _HashSet = _interopRequireDefault(require_HashSet());
16212
- var _HashMap = _interopRequireDefault(require_HashMap());
16213
- function _interopRequireDefault(e) {
16214
- return e && e.t ? e : {
16215
- default: e
16216
- };
16217
- }
13640
+ exports8.LRUCache = LRUCache;
16218
13641
  }
16219
13642
  });
16220
13643
 
16221
- // node_modules/number-allocator/lib/number-allocator.js
13644
+ // build/lib/number-allocator.js
16222
13645
  var require_number_allocator = __commonJS({
16223
- "node_modules/number-allocator/lib/number-allocator.js"(exports8, module) {
13646
+ "build/lib/number-allocator.js"(exports8) {
16224
13647
  "use strict";
16225
13648
  init_dirname();
16226
13649
  init_buffer2();
16227
13650
  init_process2();
16228
- var SortedSet = require_cjs().OrderedSet;
16229
- var debugTrace = require_browser4()("number-allocator:trace");
16230
- var debugError = require_browser4()("number-allocator:error");
16231
- function Interval(low, high) {
16232
- this.low = low;
16233
- this.high = high;
16234
- }
16235
- Interval.prototype.equals = function(other) {
16236
- return this.low === other.low && this.high === other.high;
16237
- };
16238
- Interval.prototype.compare = function(other) {
16239
- if (this.low < other.low && this.high < other.low) return -1;
16240
- if (other.low < this.low && other.high < this.low) return 1;
16241
- return 0;
16242
- };
16243
- function NumberAllocator(min, max) {
16244
- if (!(this instanceof NumberAllocator)) {
16245
- return new NumberAllocator(min, max);
13651
+ Object.defineProperty(exports8, "__esModule", { value: true });
13652
+ exports8.NumberAllocator = void 0;
13653
+ var NumberAllocator = class {
13654
+ used;
13655
+ min;
13656
+ max;
13657
+ lowWaterMark;
13658
+ constructor(min, max) {
13659
+ this.min = min;
13660
+ this.max = max;
13661
+ this.used = /* @__PURE__ */ new Set();
13662
+ this.lowWaterMark = min;
16246
13663
  }
16247
- this.min = min;
16248
- this.max = max;
16249
- this.ss = new SortedSet(
16250
- [],
16251
- (lhs, rhs) => {
16252
- return lhs.compare(rhs);
13664
+ firstVacant() {
13665
+ if (this.used.size === this.max - this.min + 1) {
13666
+ return null;
13667
+ }
13668
+ for (let i = this.lowWaterMark; i <= this.max; i++) {
13669
+ if (!this.used.has(i)) {
13670
+ return i;
13671
+ }
16253
13672
  }
16254
- );
16255
- debugTrace("Create");
16256
- this.clear();
16257
- }
16258
- NumberAllocator.prototype.firstVacant = function() {
16259
- if (this.ss.size() === 0) return null;
16260
- return this.ss.front().low;
16261
- };
16262
- NumberAllocator.prototype.alloc = function() {
16263
- if (this.ss.size() === 0) {
16264
- debugTrace("alloc():empty");
16265
13673
  return null;
16266
13674
  }
16267
- const it = this.ss.begin();
16268
- const low = it.pointer.low;
16269
- const high = it.pointer.high;
16270
- const num = low;
16271
- if (num + 1 <= high) {
16272
- this.ss.updateKeyByIterator(it, new Interval(low + 1, high));
16273
- } else {
16274
- this.ss.eraseElementByPos(0);
16275
- }
16276
- debugTrace("alloc():" + num);
16277
- return num;
16278
- };
16279
- NumberAllocator.prototype.use = function(num) {
16280
- const key = new Interval(num, num);
16281
- const it = this.ss.lowerBound(key);
16282
- if (!it.equals(this.ss.end())) {
16283
- const low = it.pointer.low;
16284
- const high = it.pointer.high;
16285
- if (it.pointer.equals(key)) {
16286
- this.ss.eraseElementByIterator(it);
16287
- debugTrace("use():" + num);
16288
- return true;
13675
+ alloc() {
13676
+ if (this.used.size === this.max - this.min + 1) {
13677
+ return null;
16289
13678
  }
16290
- if (low > num) return false;
16291
- if (low === num) {
16292
- this.ss.updateKeyByIterator(it, new Interval(low + 1, high));
16293
- debugTrace("use():" + num);
16294
- return true;
13679
+ for (let i = this.lowWaterMark; i <= this.max; i++) {
13680
+ if (!this.used.has(i)) {
13681
+ this.used.add(i);
13682
+ this.lowWaterMark = i + 1;
13683
+ return i;
13684
+ }
16295
13685
  }
16296
- if (high === num) {
16297
- this.ss.updateKeyByIterator(it, new Interval(low, high - 1));
16298
- debugTrace("use():" + num);
16299
- return true;
13686
+ return null;
13687
+ }
13688
+ use(num) {
13689
+ if (num < this.min || num > this.max || this.used.has(num)) {
13690
+ return false;
16300
13691
  }
16301
- this.ss.updateKeyByIterator(it, new Interval(num + 1, high));
16302
- this.ss.insert(new Interval(low, num - 1));
16303
- debugTrace("use():" + num);
13692
+ this.used.add(num);
16304
13693
  return true;
16305
13694
  }
16306
- debugTrace("use():failed");
16307
- return false;
16308
- };
16309
- NumberAllocator.prototype.free = function(num) {
16310
- if (num < this.min || num > this.max) {
16311
- debugError("free():" + num + " is out of range");
16312
- return;
16313
- }
16314
- const key = new Interval(num, num);
16315
- const it = this.ss.upperBound(key);
16316
- if (it.equals(this.ss.end())) {
16317
- if (it.equals(this.ss.begin())) {
16318
- this.ss.insert(key);
13695
+ free(num) {
13696
+ if (num < this.min || num > this.max) {
16319
13697
  return;
16320
13698
  }
16321
- it.pre();
16322
- const low = it.pointer.high;
16323
- const high = it.pointer.high;
16324
- if (high + 1 === num) {
16325
- this.ss.updateKeyByIterator(it, new Interval(low, num));
16326
- } else {
16327
- this.ss.insert(key);
16328
- }
16329
- } else {
16330
- if (it.equals(this.ss.begin())) {
16331
- if (num + 1 === it.pointer.low) {
16332
- const high = it.pointer.high;
16333
- this.ss.updateKeyByIterator(it, new Interval(num, high));
16334
- } else {
16335
- this.ss.insert(key);
16336
- }
16337
- } else {
16338
- const rLow = it.pointer.low;
16339
- const rHigh = it.pointer.high;
16340
- it.pre();
16341
- const lLow = it.pointer.low;
16342
- const lHigh = it.pointer.high;
16343
- if (lHigh + 1 === num) {
16344
- if (num + 1 === rLow) {
16345
- this.ss.eraseElementByIterator(it);
16346
- this.ss.updateKeyByIterator(it, new Interval(lLow, rHigh));
16347
- } else {
16348
- this.ss.updateKeyByIterator(it, new Interval(lLow, num));
16349
- }
16350
- } else {
16351
- if (num + 1 === rLow) {
16352
- this.ss.eraseElementByIterator(it.next());
16353
- this.ss.insert(new Interval(num, rHigh));
16354
- } else {
16355
- this.ss.insert(key);
16356
- }
16357
- }
13699
+ this.used.delete(num);
13700
+ if (num < this.lowWaterMark) {
13701
+ this.lowWaterMark = num;
16358
13702
  }
16359
13703
  }
16360
- debugTrace("free():" + num);
16361
- };
16362
- NumberAllocator.prototype.clear = function() {
16363
- debugTrace("clear()");
16364
- this.ss.clear();
16365
- this.ss.insert(new Interval(this.min, this.max));
16366
- };
16367
- NumberAllocator.prototype.intervalCount = function() {
16368
- return this.ss.size();
16369
- };
16370
- NumberAllocator.prototype.dump = function() {
16371
- console.log("length:" + this.ss.size());
16372
- for (const element of this.ss) {
16373
- console.log(element);
13704
+ clear() {
13705
+ this.used.clear();
13706
+ this.lowWaterMark = this.min;
16374
13707
  }
16375
13708
  };
16376
- module.exports = NumberAllocator;
16377
- }
16378
- });
16379
-
16380
- // node_modules/number-allocator/index.js
16381
- var require_number_allocator2 = __commonJS({
16382
- "node_modules/number-allocator/index.js"(exports8, module) {
16383
- init_dirname();
16384
- init_buffer2();
16385
- init_process2();
16386
- var NumberAllocator = require_number_allocator();
16387
- module.exports.NumberAllocator = NumberAllocator;
13709
+ exports8.NumberAllocator = NumberAllocator;
16388
13710
  }
16389
13711
  });
16390
13712
 
@@ -16397,7 +13719,7 @@ var mqtt = (() => {
16397
13719
  init_process2();
16398
13720
  Object.defineProperty(exports8, "__esModule", { value: true });
16399
13721
  var lru_cache_1 = require_commonjs();
16400
- var number_allocator_1 = require_number_allocator2();
13722
+ var number_allocator_1 = require_number_allocator();
16401
13723
  var TopicAliasSend = class {
16402
13724
  aliasToTopic;
16403
13725
  topicToAlias;
@@ -16468,16 +13790,27 @@ var mqtt = (() => {
16468
13790
  var ack_1 = require_ack();
16469
13791
  var topic_alias_send_1 = __importDefault(require_topic_alias_send());
16470
13792
  var shared_1 = require_shared();
16471
- var handleConnack = (client, packet) => {
13793
+ var handleConnack = (client, packet, pump) => {
16472
13794
  client.log("_handleConnack");
16473
13795
  const { options } = client;
16474
13796
  const version4 = options.protocolVersion;
16475
13797
  const rc = version4 === 5 ? packet.reasonCode : packet.returnCode;
13798
+ if (client["connackReceived"]) {
13799
+ const err = new shared_1.ErrorWithReasonCode("Protocol error: duplicate CONNACK on the same network connection", 130);
13800
+ pump?.discardParsedPackets();
13801
+ client["_cleanUp"](true);
13802
+ client.emit("error", err);
13803
+ return;
13804
+ }
13805
+ client["connackReceived"] = true;
16476
13806
  clearTimeout(client["connackTimer"]);
16477
13807
  delete client["topicAliasSend"];
13808
+ client["_serverProperties"] = packet.properties;
16478
13809
  if (packet.properties) {
16479
13810
  if (packet.properties.topicAliasMaximum) {
16480
13811
  if (packet.properties.topicAliasMaximum > 65535) {
13812
+ pump?.discardParsedPackets();
13813
+ client["_cleanUp"](true);
16481
13814
  client.emit("error", new Error("topicAliasMaximum from broker is out of range"));
16482
13815
  return;
16483
13816
  }
@@ -16485,24 +13818,23 @@ var mqtt = (() => {
16485
13818
  client["topicAliasSend"] = new topic_alias_send_1.default(packet.properties.topicAliasMaximum);
16486
13819
  }
16487
13820
  }
16488
- if (packet.properties.serverKeepAlive && options.keepalive) {
16489
- options.keepalive = packet.properties.serverKeepAlive;
16490
- }
16491
- if (packet.properties.maximumPacketSize) {
16492
- if (!options.properties) {
16493
- options.properties = {};
16494
- }
16495
- options.properties.maximumPacketSize = packet.properties.maximumPacketSize;
16496
- }
16497
13821
  }
16498
13822
  if (rc === 0) {
16499
13823
  client.reconnecting = false;
16500
13824
  client["_onConnect"](packet);
16501
13825
  } else if (rc > 0) {
13826
+ client.log("_handleConnack :: connection refused with reason code %d", rc);
16502
13827
  const err = new shared_1.ErrorWithReasonCode(`Connection refused: ${ack_1.ReasonCodes[rc]}`, rc);
16503
- client.emit("error", err);
16504
- if (client.options.reconnectOnConnackError) {
16505
- client["_cleanUp"](true);
13828
+ pump?.discardParsedPackets();
13829
+ client["reconnectSuppressed"] = true;
13830
+ client["_cleanUp"](true);
13831
+ try {
13832
+ client.emit("error", err);
13833
+ } finally {
13834
+ if (options.reconnectOnConnackError) {
13835
+ client["reconnectSuppressed"] = false;
13836
+ client["_setupReconnect"]();
13837
+ }
16506
13838
  }
16507
13839
  }
16508
13840
  };
@@ -16531,6 +13863,7 @@ var mqtt = (() => {
16531
13863
  return callback(err2);
16532
13864
  }
16533
13865
  client.incomingStore.del(pub, client.noop);
13866
+ client["_releaseIncomingQoS2Publish"](messageId);
16534
13867
  client["_sendPacket"](comp, callback);
16535
13868
  });
16536
13869
  } else {
@@ -16558,21 +13891,34 @@ var mqtt = (() => {
16558
13891
  var connack_1 = __importDefault(require_connack());
16559
13892
  var ack_1 = __importDefault(require_ack());
16560
13893
  var pubrel_1 = __importDefault(require_pubrel());
16561
- var handle = (client, packet, done) => {
13894
+ var shared_1 = require_shared();
13895
+ var remainingLengthBytes = (remainingLength) => {
13896
+ if (remainingLength < 128)
13897
+ return 1;
13898
+ if (remainingLength < 16384)
13899
+ return 2;
13900
+ if (remainingLength < 2097152)
13901
+ return 3;
13902
+ return 4;
13903
+ };
13904
+ var totalPacketSize = (remainingLength) => 1 + remainingLengthBytes(remainingLength) + remainingLength;
13905
+ var handle = (client, packet, done, pump) => {
16562
13906
  const { options } = client;
16563
- if (options.protocolVersion === 5 && options.properties && options.properties.maximumPacketSize && options.properties.maximumPacketSize < packet.length) {
16564
- client.emit("error", new Error(`exceeding packets size ${packet.cmd}`));
16565
- client.end({
16566
- reasonCode: 149,
16567
- properties: { reasonString: "Maximum packet size was exceeded" }
16568
- });
13907
+ const maximumPacketSize = options.properties?.maximumPacketSize;
13908
+ const packetSize = totalPacketSize(packet.length);
13909
+ if (options.protocolVersion === 5 && maximumPacketSize && maximumPacketSize < packetSize) {
13910
+ client.log("_handlePacket :: %s packet of %d bytes exceeds the advertised maximumPacketSize %d", packet.cmd, packetSize, maximumPacketSize);
13911
+ pump?.discardParsedPackets();
13912
+ client["_cleanUp"](true);
13913
+ done();
13914
+ client.emit("error", new shared_1.ErrorWithReasonCode(`exceeding packets size ${packet.cmd}: ${packetSize} bytes, maximumPacketSize is ${maximumPacketSize}`, 149));
16569
13915
  return client;
16570
13916
  }
16571
13917
  client.log("_handlePacket :: emitting packetreceive");
16572
13918
  client.emit("packetreceive", packet);
16573
13919
  switch (packet.cmd) {
16574
13920
  case "publish":
16575
- (0, publish_1.default)(client, packet, done);
13921
+ (0, publish_1.default)(client, packet, done, pump);
16576
13922
  break;
16577
13923
  case "puback":
16578
13924
  case "pubrec":
@@ -16580,21 +13926,30 @@ var mqtt = (() => {
16580
13926
  case "suback":
16581
13927
  case "unsuback":
16582
13928
  client.reschedulePing();
16583
- (0, ack_1.default)(client, packet);
16584
- done();
13929
+ try {
13930
+ (0, ack_1.default)(client, packet);
13931
+ } finally {
13932
+ done();
13933
+ }
16585
13934
  break;
16586
13935
  case "pubrel":
16587
13936
  client.reschedulePing();
16588
13937
  (0, pubrel_1.default)(client, packet, done);
16589
13938
  break;
16590
13939
  case "connack":
16591
- (0, connack_1.default)(client, packet);
16592
- done();
13940
+ try {
13941
+ (0, connack_1.default)(client, packet, pump);
13942
+ } finally {
13943
+ done();
13944
+ }
16593
13945
  break;
16594
13946
  case "auth":
16595
13947
  client.reschedulePing();
16596
- (0, auth_1.default)(client, packet);
16597
- done();
13948
+ try {
13949
+ (0, auth_1.default)(client, packet, pump);
13950
+ } finally {
13951
+ done();
13952
+ }
16598
13953
  break;
16599
13954
  case "pingresp":
16600
13955
  client.log("_handlePacket :: received pingresp");
@@ -17859,7 +15214,7 @@ var mqtt = (() => {
17859
15214
  constructor(client, variant) {
17860
15215
  this.client = client;
17861
15216
  this.timer = typeof variant === "object" && "set" in variant && "clear" in variant ? variant : (0, get_timer_1.default)(variant);
17862
- this.setKeepalive(client.options.keepalive);
15217
+ this.setKeepalive(client.keepalive);
17863
15218
  }
17864
15219
  clear() {
17865
15220
  if (this.timerId) {
@@ -17961,6 +15316,7 @@ var mqtt = (() => {
17961
15316
  var validations = __importStar(require_validations());
17962
15317
  var store_1 = __importDefault(require_store());
17963
15318
  var handlers_1 = __importDefault(require_handlers());
15319
+ var ack_1 = require_ack();
17964
15320
  var default_message_id_provider_1 = __importDefault(require_default_message_id_provider());
17965
15321
  var topic_alias_recv_1 = __importDefault(require_topic_alias_recv());
17966
15322
  var shared_1 = require_shared();
@@ -17973,6 +15329,8 @@ var mqtt = (() => {
17973
15329
  callback(...args);
17974
15330
  });
17975
15331
  });
15332
+ var MAX_RECEIVE_MAXIMUM = 65535;
15333
+ var RECEIVE_MAXIMUM_EXCEEDED = 147;
17976
15334
  var defaultConnectOptions = {
17977
15335
  keepalive: 60,
17978
15336
  reschedulePings: true,
@@ -18015,8 +15373,15 @@ var mqtt = (() => {
18015
15373
  _firstConnection;
18016
15374
  topicAliasRecv;
18017
15375
  topicAliasSend;
15376
+ _incomingQoS2Ids;
15377
+ _receiveMaximum;
18018
15378
  _deferredReconnect;
15379
+ _currentPump;
15380
+ connackReceived;
15381
+ reconnectSuppressed;
15382
+ _authenticationMethod;
18019
15383
  connackPacket;
15384
+ _serverProperties;
18020
15385
  static defaultId() {
18021
15386
  return `mqttjs_${Math.random().toString(16).substr(2, 8)}`;
18022
15387
  }
@@ -18057,6 +15422,16 @@ var mqtt = (() => {
18057
15422
  this.messageIdProvider = typeof this.options.messageIdProvider === "undefined" ? new default_message_id_provider_1.default() : this.options.messageIdProvider;
18058
15423
  this.outgoingStore = options.outgoingStore || new store_1.default();
18059
15424
  this.incomingStore = options.incomingStore || new store_1.default();
15425
+ this._incomingQoS2Ids = /* @__PURE__ */ new Set();
15426
+ this._receiveMaximum = MAX_RECEIVE_MAXIMUM;
15427
+ const receiveMaximum = options.properties?.receiveMaximum;
15428
+ if (receiveMaximum !== void 0) {
15429
+ if (Number.isInteger(receiveMaximum) && receiveMaximum >= 1 && receiveMaximum <= MAX_RECEIVE_MAXIMUM) {
15430
+ this._receiveMaximum = receiveMaximum;
15431
+ } else {
15432
+ this.log("MqttClient :: options.properties.receiveMaximum %o is not an integer between 1 and %d, enforcing and advertising %d instead", receiveMaximum, MAX_RECEIVE_MAXIMUM, MAX_RECEIVE_MAXIMUM);
15433
+ }
15434
+ }
18060
15435
  this.queueQoSZero = options.queueQoSZero === void 0 ? true : options.queueQoSZero;
18061
15436
  this._resubscribeTopics = {};
18062
15437
  this.messageIdToTopic = {};
@@ -18066,6 +15441,8 @@ var mqtt = (() => {
18066
15441
  this.reconnecting = false;
18067
15442
  this.queue = [];
18068
15443
  this.connackTimer = null;
15444
+ this.connackReceived = false;
15445
+ this.reconnectSuppressed = false;
18069
15446
  this.reconnectTimer = null;
18070
15447
  this._storeProcessing = false;
18071
15448
  this._packetIdsDuringStoreProcessing = {};
@@ -18118,6 +15495,7 @@ var mqtt = (() => {
18118
15495
  this.log("close :: clearing connackTimer");
18119
15496
  clearTimeout(this.connackTimer);
18120
15497
  this._destroyKeepaliveManager();
15498
+ this._serverProperties = void 0;
18121
15499
  if (this.topicAliasRecv) {
18122
15500
  this.topicAliasRecv.clear();
18123
15501
  }
@@ -18141,16 +15519,57 @@ var mqtt = (() => {
18141
15519
  getLastMessageId() {
18142
15520
  return this.messageIdProvider.getLastAllocated();
18143
15521
  }
15522
+ _trackIncomingQoS2Publish(messageId, done, pump) {
15523
+ if (this._incomingQoS2Ids.has(messageId)) {
15524
+ return true;
15525
+ }
15526
+ if (this.options.protocolVersion === 5 && this._incomingQoS2Ids.size >= this._receiveMaximum) {
15527
+ this.log("_trackIncomingQoS2Publish :: inbound QoS 2 messages exceeded receiveMaximum %d", this._receiveMaximum);
15528
+ pump?.discardParsedPackets();
15529
+ if (!pump || pump.isCurrent()) {
15530
+ this._cleanUp(true);
15531
+ }
15532
+ done();
15533
+ this.emit("error", new shared_1.ErrorWithReasonCode(`${ack_1.ReasonCodes[RECEIVE_MAXIMUM_EXCEEDED]}: ${this._incomingQoS2Ids.size + 1} inbound QoS 2 messages in flight, receiveMaximum is ${this._receiveMaximum}`, RECEIVE_MAXIMUM_EXCEEDED));
15534
+ return false;
15535
+ }
15536
+ this._incomingQoS2Ids.add(messageId);
15537
+ return true;
15538
+ }
15539
+ _releaseIncomingQoS2Publish(messageId) {
15540
+ this._incomingQoS2Ids.delete(messageId);
15541
+ }
15542
+ _discardIncomingQoS2State() {
15543
+ if (this._incomingQoS2Ids.size === 0) {
15544
+ return;
15545
+ }
15546
+ this.log("_discardIncomingQoS2State :: session not resumed, dropping %d inbound QoS 2 message(s)", this._incomingQoS2Ids.size);
15547
+ for (const messageId of this._incomingQoS2Ids) {
15548
+ this.incomingStore.del({ messageId }, this.noop);
15549
+ }
15550
+ this._incomingQoS2Ids.clear();
15551
+ }
18144
15552
  connect() {
18145
15553
  const writable = new readable_stream_1.Writable();
18146
15554
  const parser = mqtt_packet_1.default.parser(this.options);
18147
15555
  let completeParse = null;
18148
15556
  const packets = [];
15557
+ const pump = {
15558
+ discardParsedPackets: () => {
15559
+ packets.length = 0;
15560
+ },
15561
+ isCurrent: () => this._currentPump === pump
15562
+ };
15563
+ this._currentPump = pump;
15564
+ this.connackReceived = false;
15565
+ this.reconnectSuppressed = false;
18149
15566
  this.log("connect :: calling method to clear reconnect");
18150
15567
  this._clearReconnect();
15568
+ this._serverProperties = void 0;
18151
15569
  if (this.disconnected && !this.reconnecting) {
18152
15570
  this.incomingStore = this.options.incomingStore || new store_1.default();
18153
15571
  this.outgoingStore = this.options.outgoingStore || new store_1.default();
15572
+ this._incomingQoS2Ids.clear();
18154
15573
  this.disconnecting = false;
18155
15574
  this.disconnected = false;
18156
15575
  }
@@ -18162,10 +15581,14 @@ var mqtt = (() => {
18162
15581
  });
18163
15582
  const work = () => {
18164
15583
  this.log("work :: getting next packet in queue");
15584
+ if (this._currentPump !== pump) {
15585
+ this.log("work :: pump superseded, dropping %d queued packets", packets.length);
15586
+ packets.length = 0;
15587
+ }
18165
15588
  const packet = packets.shift();
18166
15589
  if (packet) {
18167
15590
  this.log("work :: packet pulled from queue");
18168
- (0, handlers_1.default)(this, packet, nextTickWork);
15591
+ (0, handlers_1.default)(this, packet, nextTickWork, pump);
18169
15592
  } else {
18170
15593
  this.log("work :: no packets in queue");
18171
15594
  const done = completeParse;
@@ -18181,7 +15604,8 @@ var mqtt = (() => {
18181
15604
  } else {
18182
15605
  const done = completeParse;
18183
15606
  completeParse = null;
18184
- done();
15607
+ if (done)
15608
+ done();
18185
15609
  }
18186
15610
  };
18187
15611
  writable._write = (buf, enc, done) => {
@@ -18218,8 +15642,11 @@ var mqtt = (() => {
18218
15642
  keepalive: this.options.keepalive,
18219
15643
  username: this.options.username,
18220
15644
  password: this.options.password,
18221
- properties: this.options.properties
15645
+ properties: this.options.properties ? { ...this.options.properties } : void 0
18222
15646
  };
15647
+ if (connectPacket.properties?.receiveMaximum !== void 0) {
15648
+ connectPacket.properties.receiveMaximum = this._receiveMaximum;
15649
+ }
18223
15650
  if (this.options.will) {
18224
15651
  connectPacket.will = {
18225
15652
  ...this.options.will,
@@ -18234,6 +15661,7 @@ var mqtt = (() => {
18234
15661
  connectPacket.properties.topicAliasMaximum = this.topicAliasRecv.max;
18235
15662
  }
18236
15663
  }
15664
+ this._authenticationMethod = connectPacket.properties?.authenticationMethod;
18237
15665
  this._writePacket(connectPacket);
18238
15666
  parser.on("error", this.emit.bind(this, "error"));
18239
15667
  if (this.options.properties) {
@@ -18252,13 +15680,14 @@ var mqtt = (() => {
18252
15680
  }
18253
15681
  this.stream.setMaxListeners(1e3);
18254
15682
  clearTimeout(this.connackTimer);
18255
- this.connackTimer = setTimeout(() => {
18256
- this.log("!!connectTimeout hit!! Calling _cleanUp with force `true`");
18257
- this.emit("error", new Error("connack timeout"));
18258
- this._cleanUp(true);
18259
- }, this.options.connectTimeout);
15683
+ this.connackTimer = setTimeout(() => this._onConnackTimeout(), this.options.connectTimeout);
18260
15684
  return this;
18261
15685
  }
15686
+ _onConnackTimeout() {
15687
+ this.log("!!connectTimeout hit!! Calling _cleanUp with force `true`");
15688
+ this._cleanUp(true);
15689
+ this.emit("error", new Error("connack timeout"));
15690
+ }
18262
15691
  publish(topic, message, opts, callback) {
18263
15692
  this.log("publish :: message `%s` to topic `%s`", message, topic);
18264
15693
  const { options } = this;
@@ -18304,6 +15733,7 @@ var mqtt = (() => {
18304
15733
  case 2:
18305
15734
  this.outgoing[packet.messageId] = {
18306
15735
  volatile: false,
15736
+ cmd: "publish",
18307
15737
  cb: callback || this.noop
18308
15738
  };
18309
15739
  this.log("MqttClient:publish: packet cmd: %s", packet.cmd);
@@ -18436,18 +15866,22 @@ var mqtt = (() => {
18436
15866
  const promise = new Promise((resolve2, reject) => {
18437
15867
  this.outgoing[packet.messageId] = {
18438
15868
  volatile: true,
18439
- cb(err, packet2) {
18440
- if (!err) {
18441
- const { granted } = packet2;
18442
- for (let grantedI = 0; grantedI < granted.length; grantedI += 1) {
18443
- chunkedSubs[grantedI].qos = granted[grantedI];
18444
- }
18445
- }
18446
- if (!err) {
18447
- resolve2(packet2);
18448
- } else {
15869
+ cmd: "subscribe",
15870
+ cb: (err, packet2) => {
15871
+ if (err) {
18449
15872
  reject(new shared_1.ErrorWithSubackPacket(err.message, packet2));
15873
+ return;
15874
+ }
15875
+ const { granted } = packet2;
15876
+ if (granted.length !== chunkedSubs.length) {
15877
+ reject(new shared_1.ErrorWithSubackPacket(`Protocol error: suback granted ${granted.length} reason code(s) for ${chunkedSubs.length} subscription(s)`, packet2));
15878
+ this._cleanUp(true);
15879
+ return;
15880
+ }
15881
+ for (let grantedI = 0; grantedI < granted.length; grantedI += 1) {
15882
+ chunkedSubs[grantedI].qos = granted[grantedI];
18450
15883
  }
15884
+ resolve2(packet2);
18451
15885
  }
18452
15886
  };
18453
15887
  });
@@ -18535,6 +15969,7 @@ var mqtt = (() => {
18535
15969
  }
18536
15970
  this.outgoing[packet.messageId] = {
18537
15971
  volatile: true,
15972
+ cmd: "unsubscribe",
18538
15973
  cb: callback
18539
15974
  };
18540
15975
  this.log("unsubscribe: call _sendPacket");
@@ -18578,6 +16013,7 @@ var mqtt = (() => {
18578
16013
  const closeStores = () => {
18579
16014
  this.log("end :: closeStores: closing incoming and outgoing stores");
18580
16015
  this.disconnected = true;
16016
+ this._incomingQoS2Ids.clear();
18581
16017
  this.incomingStore.close((e1) => {
18582
16018
  this.outgoingStore.close((e2) => {
18583
16019
  this.log("end :: closeStores: emitting end");
@@ -18649,6 +16085,7 @@ var mqtt = (() => {
18649
16085
  }
18650
16086
  this.incomingStore = this.options.incomingStore || new store_1.default();
18651
16087
  this.outgoingStore = this.options.outgoingStore || new store_1.default();
16088
+ this._incomingQoS2Ids.clear();
18652
16089
  this.disconnecting = false;
18653
16090
  this.disconnected = false;
18654
16091
  this._deferredReconnect = null;
@@ -18728,7 +16165,7 @@ var mqtt = (() => {
18728
16165
  }
18729
16166
  }
18730
16167
  _setupReconnect() {
18731
- if (!this.disconnecting && !this.reconnectTimer && this.options.reconnectPeriod > 0) {
16168
+ if (!this.disconnecting && !this.reconnectSuppressed && !this.reconnectTimer && this.options.reconnectPeriod > 0) {
18732
16169
  if (!this.reconnecting) {
18733
16170
  this.log("_setupReconnect :: emit `offline` state");
18734
16171
  this.emit("offline");
@@ -18950,9 +16387,16 @@ var mqtt = (() => {
18950
16387
  cb(new Error("No connection to broker"));
18951
16388
  }
18952
16389
  }
16390
+ get serverProperties() {
16391
+ return this._serverProperties;
16392
+ }
16393
+ get keepalive() {
16394
+ const serverKeepAlive = this.connected ? this._serverProperties?.serverKeepAlive : void 0;
16395
+ return serverKeepAlive && this.options.keepalive ? serverKeepAlive : this.options.keepalive;
16396
+ }
18953
16397
  _setupKeepaliveManager() {
18954
- this.log("_setupKeepaliveManager :: keepalive %d (seconds)", this.options.keepalive);
18955
- if (!this.keepaliveManager && this.options.keepalive) {
16398
+ this.log("_setupKeepaliveManager :: keepalive %d (seconds)", this.keepalive);
16399
+ if (!this.keepaliveManager && this.keepalive) {
18956
16400
  this.keepaliveManager = new KeepaliveManager_1.default(this, this.options.timerVariant);
18957
16401
  }
18958
16402
  }
@@ -18964,7 +16408,7 @@ var mqtt = (() => {
18964
16408
  }
18965
16409
  }
18966
16410
  reschedulePing(force = false) {
18967
- if (this.keepaliveManager && this.options.keepalive && (force || this.options.reschedulePings)) {
16411
+ if (this.keepaliveManager && this.keepalive && (force || this.options.reschedulePings)) {
18968
16412
  this._reschedulePing();
18969
16413
  }
18970
16414
  }
@@ -18977,9 +16421,9 @@ var mqtt = (() => {
18977
16421
  this._sendPacket({ cmd: "pingreq" });
18978
16422
  }
18979
16423
  onKeepaliveTimeout() {
18980
- this.emit("error", new Error("Keepalive timeout"));
18981
16424
  this.log("onKeepaliveTimeout :: calling _cleanUp with force true");
18982
16425
  this._cleanUp(true);
16426
+ this.emit("error", new Error("Keepalive timeout"));
18983
16427
  }
18984
16428
  _resubscribe() {
18985
16429
  this.log("_resubscribe");
@@ -19012,9 +16456,13 @@ var mqtt = (() => {
19012
16456
  return;
19013
16457
  }
19014
16458
  this.connackPacket = packet;
16459
+ const sessionResumed = !this.options.clean && (this.options.protocolVersion < 4 || packet.sessionPresent === true);
16460
+ if (!sessionResumed) {
16461
+ this._discardIncomingQoS2State();
16462
+ }
19015
16463
  this.messageIdProvider.clear();
19016
- this._setupKeepaliveManager();
19017
16464
  this.connected = true;
16465
+ this._setupKeepaliveManager();
19018
16466
  const startStreamProcess = () => {
19019
16467
  let outStore = this.outgoingStore.createStream();
19020
16468
  const remove = () => {
@@ -19053,6 +16501,7 @@ var mqtt = (() => {
19053
16501
  cb = this.outgoing[packet2.messageId] ? this.outgoing[packet2.messageId].cb : null;
19054
16502
  this.outgoing[packet2.messageId] = {
19055
16503
  volatile: false,
16504
+ cmd: packet2.cmd,
19056
16505
  cb(err, status) {
19057
16506
  if (cb) {
19058
16507
  cb(err, status);
@@ -19135,7 +16584,7 @@ var mqtt = (() => {
19135
16584
  init_buffer2();
19136
16585
  init_process2();
19137
16586
  Object.defineProperty(exports8, "__esModule", { value: true });
19138
- var number_allocator_1 = require_number_allocator2();
16587
+ var number_allocator_1 = require_number_allocator();
19139
16588
  var UniqueMessageIdProvider = class {
19140
16589
  numberAllocator;
19141
16590
  lastId;
@@ -23332,7 +20781,7 @@ var mqtt = (() => {
23332
20781
  var buildStream = (client, opts) => {
23333
20782
  opts.port = opts.port || 8883;
23334
20783
  opts.host = opts.hostname || opts.host || "localhost";
23335
- if (net_1.default.isIP(opts.host) === 0) {
20784
+ if (net_1.default.isIP(opts.host) === 0 && !opts.servername) {
23336
20785
  opts.servername = opts.host;
23337
20786
  }
23338
20787
  opts.rejectUnauthorized = opts.rejectUnauthorized !== false;
@@ -23613,6 +21062,15 @@ var mqtt = (() => {
23613
21062
  }
23614
21063
  var debug = (0, debug_1.default)("mqttjs");
23615
21064
  var protocols = null;
21065
+ function getDefaultWebSocketProtocol() {
21066
+ if (typeof location !== "undefined") {
21067
+ return location.protocol === "https:" ? "wss" : "ws";
21068
+ }
21069
+ if (typeof document !== "undefined") {
21070
+ return new URL(document.URL).protocol === "https:" ? "wss" : "ws";
21071
+ }
21072
+ return "ws";
21073
+ }
23616
21074
  function parseAuthOptions(opts) {
23617
21075
  let matches;
23618
21076
  if (opts.auth) {
@@ -23636,6 +21094,7 @@ var mqtt = (() => {
23636
21094
  if (brokerUrl && typeof brokerUrl === "string") {
23637
21095
  const parsedUrl = url_1.default.parse(brokerUrl, true);
23638
21096
  const parsedOptions = {};
21097
+ const isRelativeWebSocketUrl = !parsedUrl.protocol && !parsedUrl.hostname && parsedUrl.path?.startsWith("/") && (is_browser_1.default || opts.forceNativeWebSocket);
23639
21098
  if (parsedUrl.port != null) {
23640
21099
  parsedOptions.port = Number(parsedUrl.port);
23641
21100
  }
@@ -23645,10 +21104,10 @@ var mqtt = (() => {
23645
21104
  parsedOptions.protocol = parsedUrl.protocol;
23646
21105
  parsedOptions.path = parsedUrl.path;
23647
21106
  opts = { ...parsedOptions, ...opts };
23648
- if (!opts.protocol) {
21107
+ if (!opts.protocol && !isRelativeWebSocketUrl) {
23649
21108
  throw new Error("Missing protocol");
23650
21109
  }
23651
- opts.protocol = opts.protocol.replace(/:$/, "");
21110
+ opts.protocol = (opts.protocol || getDefaultWebSocketProtocol()).replace(/:$/, "");
23652
21111
  }
23653
21112
  opts.unixSocket = opts.unixSocket || opts.protocol?.includes("+unix");
23654
21113
  if (opts.unixSocket) {