aqualink 2.18.1 → 2.19.1

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.
@@ -1,11 +1,10 @@
1
-
2
- class Plugin {
3
- constructor(name) {
4
- this.name = name;
5
- }
6
-
7
- load(aqua) { }
8
- unload(aqua) { }
9
- }
10
-
11
- module.exports = Plugin
1
+ class Plugin {
2
+ constructor(name) {
3
+ this.name = name
4
+ }
5
+
6
+ load(aqua) {}
7
+ unload(aqua) {}
8
+ }
9
+
10
+ module.exports = Plugin
@@ -1,111 +1,129 @@
1
- 'use strict'
2
-
3
- class Queue {
4
- constructor() {
5
- this._items = []
6
- this._head = 0
7
- }
8
-
9
- get size() {
10
- return this._items.length - this._head
11
- }
12
-
13
- get first() {
14
- return this._items[this._head] || null
15
- }
16
-
17
- get last() {
18
- return this._items[this._items.length - 1] || null
19
- }
20
-
21
- add(...tracks) {
22
- this._items.push(...tracks)
23
- return this
24
- }
25
-
26
- remove(track) {
27
- const idx = this._items.indexOf(track, this._head)
28
- if (idx === -1) return false
29
- const removed = this._items[idx]
30
- this._items.splice(idx, 1)
31
- if (removed?.dispose) removed.dispose()
32
- return true
33
- }
34
-
35
- clear() {
36
- for (let i = this._head; i < this._items.length; i++) {
37
- if (this._items[i]?.dispose) this._items[i].dispose()
38
- }
39
- this._items.length = 0
40
- this._head = 0
41
- }
42
-
43
- shuffle() {
44
- // Compact first if needed
45
- if (this._head > 0) {
46
- this._items = this._items.slice(this._head)
47
- this._head = 0
48
- }
49
- for (let i = this._items.length - 1; i > 0; i--) {
50
- const j = Math.floor(Math.random() * (i + 1))
51
- const temp = this._items[i]
52
- this._items[i] = this._items[j]
53
- this._items[j] = temp
54
- }
55
- return this
56
- }
57
-
58
- move(from, to) {
59
- const actualFrom = from + this._head
60
- const actualTo = to + this._head
61
- if (from < 0 || actualFrom >= this._items.length || to < 0 || actualTo >= this._items.length) return this
62
- const [item] = this._items.splice(actualFrom, 1)
63
- this._items.splice(actualTo, 0, item)
64
- return this
65
- }
66
-
67
- swap(index1, index2) {
68
- const actual1 = index1 + this._head
69
- const actual2 = index2 + this._head
70
- if (index1 < 0 || actual1 >= this._items.length || index2 < 0 || actual2 >= this._items.length) return this
71
- const temp = this._items[actual1]
72
- this._items[actual1] = this._items[actual2]
73
- this._items[actual2] = temp
74
- return this
75
- }
76
-
77
- peek() {
78
- return this.first
79
- }
80
-
81
- toArray() {
82
- return this._items.slice(this._head)
83
- }
84
-
85
- at(index) {
86
- return this._items[this._head + index] || null
87
- }
88
-
89
- dequeue() {
90
- if (this._head >= this._items.length) return undefined
91
- const item = this._items[this._head]
92
- this._items[this._head] = undefined // Allow GC
93
- this._head++
94
- // Compact when head is > 50% of array to prevent unbounded growth
95
- if (this._head > 0 && this._head > this._items.length / 2) {
96
- this._items = this._items.slice(this._head)
97
- this._head = 0
98
- }
99
- return item
100
- }
101
-
102
- isEmpty() {
103
- return this.size === 0
104
- }
105
-
106
- enqueue(track) {
107
- return this.add(track)
108
- }
109
- }
110
-
111
- module.exports = Queue
1
+ class Queue {
2
+ constructor() {
3
+ this._items = []
4
+ this._head = 0
5
+ }
6
+
7
+ get size() {
8
+ return this._items.length - this._head
9
+ }
10
+
11
+ get first() {
12
+ return this._items[this._head] || null
13
+ }
14
+
15
+ get last() {
16
+ return this._items[this._items.length - 1] || null
17
+ }
18
+
19
+ add(...tracks) {
20
+ this._items.push(...tracks)
21
+ return this
22
+ }
23
+
24
+ remove(track) {
25
+ const idx = this._items.indexOf(track, this._head)
26
+ if (idx === -1) return false
27
+ const removed = this._items[idx]
28
+ this._items.splice(idx, 1)
29
+ if (removed?.dispose) removed.dispose()
30
+ return true
31
+ }
32
+
33
+ clear() {
34
+ for (let i = this._head; i < this._items.length; i++) {
35
+ if (this._items[i]?.dispose) this._items[i].dispose()
36
+ }
37
+ this._items.length = 0
38
+ this._head = 0
39
+ }
40
+
41
+ shuffle() {
42
+ if (this._head > 0) {
43
+ if (this._head > 0) {
44
+ const len = this._items.length - this._head
45
+ for (let i = 0; i < len; i++) {
46
+ this._items[i] = this._items[this._head + i]
47
+ }
48
+ this._items.length = len
49
+ this._head = 0
50
+ }
51
+ }
52
+ for (let i = this._items.length - 1; i > 0; i--) {
53
+ const j = Math.floor(Math.random() * (i + 1))
54
+ const temp = this._items[i]
55
+ this._items[i] = this._items[j]
56
+ this._items[j] = temp
57
+ }
58
+ return this
59
+ }
60
+
61
+ move(from, to) {
62
+ const actualFrom = from + this._head
63
+ const actualTo = to + this._head
64
+ if (
65
+ from < 0 ||
66
+ actualFrom >= this._items.length ||
67
+ to < 0 ||
68
+ actualTo >= this._items.length
69
+ )
70
+ return this
71
+ const [item] = this._items.splice(actualFrom, 1)
72
+ this._items.splice(actualTo, 0, item)
73
+ return this
74
+ }
75
+
76
+ swap(index1, index2) {
77
+ const actual1 = index1 + this._head
78
+ const actual2 = index2 + this._head
79
+ if (
80
+ index1 < 0 ||
81
+ actual1 >= this._items.length ||
82
+ index2 < 0 ||
83
+ actual2 >= this._items.length
84
+ )
85
+ return this
86
+ const temp = this._items[actual1]
87
+ this._items[actual1] = this._items[actual2]
88
+ this._items[actual2] = temp
89
+ return this
90
+ }
91
+
92
+ peek() {
93
+ return this.first
94
+ }
95
+
96
+ toArray() {
97
+ return this._items.slice(this._head)
98
+ }
99
+
100
+ at(index) {
101
+ return this._items[this._head + index] || null
102
+ }
103
+
104
+ dequeue() {
105
+ if (this._head >= this._items.length) return undefined
106
+ const item = this._items[this._head]
107
+ this._items[this._head] = undefined // Allow GC
108
+ this._head++
109
+ if (this._head > 0 && this._head > this._items.length / 2) {
110
+ const len = this._items.length - this._head
111
+ for (let i = 0; i < len; i++) {
112
+ this._items[i] = this._items[this._head + i]
113
+ }
114
+ this._items.length = len
115
+ this._head = 0
116
+ }
117
+ return item
118
+ }
119
+
120
+ isEmpty() {
121
+ return this.size === 0
122
+ }
123
+
124
+ enqueue(track) {
125
+ return this.add(track)
126
+ }
127
+ }
128
+
129
+ module.exports = Queue