@tidal-music/player-web-components 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-music/player-web-components",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -13,23 +13,24 @@
13
13
  },
14
14
  "license": "Apache-2.0",
15
15
  "exports": {
16
- "default": "./dist/index.js",
17
- "import": "./dist/index.js"
16
+ "import": "./dist/index.js",
17
+ "default": "./dist/index.js"
18
18
  },
19
19
  "keywords": [
20
20
  "tidal-music",
21
21
  "web-components"
22
22
  ],
23
23
  "devDependencies": {
24
- "@vitest/coverage-v8": "1.6.0",
25
- "@vitest/ui": "1.6.0",
26
- "typescript": "5.4.5",
27
- "vite": "5.2.11",
28
- "vite-plugin-dts": "3.9.1",
29
- "vitest": "1.6.0",
30
- "@tidal-music/common": "^0.1.5",
31
- "@tidal-music/auth": "^1.3.0",
32
- "@tidal-music/player": "^0.2.0"
24
+ "@vitest/coverage-v8": "3.2.4",
25
+ "@vitest/ui": "3.2.4",
26
+ "typescript": "5.9.2",
27
+ "vite": "7.1.1",
28
+ "vite-plugin-dts": "4.5.4",
29
+ "vitest": "3.2.4",
30
+ "@tidal-music/auth": "^1.4.0",
31
+ "@tidal-music/player": "^0.10.2",
32
+ "@tidal-music/common": "^0.2.0",
33
+ "@tidal-music/event-producer": "^2.4.0"
33
34
  },
34
35
  "scripts": {
35
36
  "build": "vite build",
@@ -40,7 +41,7 @@
40
41
  "lint:ci": "eslint . --quiet",
41
42
  "lint:fix": "pnpm run lint --fix",
42
43
  "preview": "vite preview",
43
- "test": "vitest --sequence.concurrent",
44
+ "test": "vitest",
44
45
  "test:coverage": "pnpm run test --coverage",
45
46
  "test:ui": "pnpm run test:coverage --ui",
46
47
  "typecheck": "tsc"
@@ -1,236 +0,0 @@
1
- import { i as V, b as S, l as y, m as T } from "./index-DbGwqQeZ.js";
2
- import { l as W } from "./_commonjsHelpers-DaMA6jEr-DtILRGNx.js";
3
- var q = /* @__PURE__ */ function() {
4
- function s(e, t, n, i, a) {
5
- return e < t || n < t ? e > n ? n + 1 : e + 1 : i === a ? t : t + 1;
6
- }
7
- return function(e, t) {
8
- if (e === t)
9
- return 0;
10
- if (e.length > t.length) {
11
- var n = e;
12
- e = t, t = n;
13
- }
14
- for (var i = e.length, a = t.length; i > 0 && e.charCodeAt(i - 1) === t.charCodeAt(a - 1); )
15
- i--, a--;
16
- for (var c = 0; c < i && e.charCodeAt(c) === t.charCodeAt(c); )
17
- c++;
18
- if (i -= c, a -= c, i === 0 || a < 3)
19
- return a;
20
- var o = 0, r, d, l, h, f, v, m, p, D, C, E, A, u = [];
21
- for (r = 0; r < i; r++)
22
- u.push(r + 1), u.push(e.charCodeAt(c + r));
23
- for (var P = u.length - 1; o < a - 3; )
24
- for (D = t.charCodeAt(c + (d = o)), C = t.charCodeAt(c + (l = o + 1)), E = t.charCodeAt(c + (h = o + 2)), A = t.charCodeAt(c + (f = o + 3)), v = o += 4, r = 0; r < P; r += 2)
25
- m = u[r], p = u[r + 1], d = s(m, d, l, D, p), l = s(d, l, h, C, p), h = s(l, h, f, E, p), v = s(h, f, v, A, p), u[r] = v, f = h, h = l, l = d, d = m;
26
- for (; o < a; )
27
- for (D = t.charCodeAt(c + (d = o)), v = ++o, r = 0; r < P; r += 2)
28
- m = u[r], u[r] = v = s(m, d, v, D, u[r + 1]), d = m;
29
- return v;
30
- };
31
- }();
32
- const O = /* @__PURE__ */ W(q);
33
- function M(s) {
34
- return new CustomEvent("device-change", {
35
- detail: {
36
- devices: s
37
- }
38
- });
39
- }
40
- const g = V.parse(navigator.userAgent);
41
- class w {
42
- controllableVolume;
43
- id;
44
- name;
45
- nativeDeviceId;
46
- type;
47
- webDeviceId;
48
- constructor({
49
- controllableVolume: e,
50
- name: t,
51
- nativeDeviceId: n,
52
- type: i,
53
- webDeviceId: a
54
- }) {
55
- this.name = t, this.id = n === "default" && a === "default" ? "default" : T(), this.nativeDeviceId = n, this.webDeviceId = a, this.type = i, this.controllableVolume = e !== !1;
56
- }
57
- }
58
- function b(s) {
59
- if (B(s))
60
- return "windowsCommunication";
61
- if ("id" in s && s.id === "BuiltInSpeakerDevice")
62
- return "builtIn";
63
- if ("type" in s) {
64
- if (s.type === "airplay")
65
- return "airplay";
66
- if (s.type === "mqa")
67
- return "mqa";
68
- }
69
- if ("label" in s) {
70
- const e = s.label.toLowerCase();
71
- if (e.includes("bluetooth"))
72
- return "bluetooth";
73
- if (e.includes("displayport"))
74
- return "displayPort";
75
- if (e.includes("hdmi"))
76
- return "hdmi";
77
- if (e.includes("usb"))
78
- return "usb";
79
- if (e.includes("built-in"))
80
- return "builtIn";
81
- if (e.includes("airplay"))
82
- return "airplay";
83
- }
84
- }
85
- function I(s, e) {
86
- const t = e.toLowerCase();
87
- let n = s;
88
- return t.includes("mac") && (n = (s.split("(")[0] ?? "").trim()), n;
89
- }
90
- function B(s) {
91
- let e;
92
- return "label" in s && (e = s.label), "name" in s && (e = s.name), e !== void 0 && e.startsWith("Communications");
93
- }
94
- function L(s, e) {
95
- if (e = I(e, g.os.name || ""), [...s].length === 0 || e === "")
96
- return;
97
- const t = [...s].filter((i) => i.name === e)[0];
98
- if (t)
99
- return t;
100
- const n = [...s].filter((i) => e.includes(i.name) || i.name.includes(e)).map((i) => ({
101
- device: i,
102
- // eslint-disable-next-line @typescript-eslint/no-unsafe-call
103
- distance: O(i.name, e)
104
- })).sort((i, a) => i.distance - a.distance).reverse();
105
- if (n.length > 0) {
106
- const i = n.pop();
107
- if (i && i.distance <= 16)
108
- return i.device;
109
- }
110
- }
111
- class N {
112
- #i;
113
- #s;
114
- #n = "shared";
115
- #e;
116
- #t;
117
- #a = void 0;
118
- #r;
119
- outputDevices;
120
- constructor() {
121
- this.#t = /* @__PURE__ */ new Set(), this.#r = /* @__PURE__ */ new Set(), this.#e = new EventTarget(), this.#s = new w({
122
- name: "System Default",
123
- nativeDeviceId: "default",
124
- type: "systemDefault",
125
- webDeviceId: "default"
126
- }), this.#i = this.#s, this.outputDevices = /* @__PURE__ */ new Set([this.#s]), this.hydrateWebDevices().then().catch(console.error), navigator.mediaDevices.addEventListener("devicechange", () => {
127
- this.hydrateWebDevices().then().catch(console.error);
128
- }), this.#e.addEventListener("native-devices", (e) => {
129
- this.#t = new Set(e.detail), this.queueUpdate().then().catch(console.error);
130
- }), this.#e.addEventListener("web-devices", (e) => {
131
- this.#r = new Set(e.detail), this.queueUpdate().then().catch(console.error);
132
- });
133
- }
134
- addNativeDevices(e) {
135
- this.#e.dispatchEvent(
136
- new CustomEvent("native-devices", {
137
- detail: e
138
- })
139
- );
140
- }
141
- addWebDevices(e) {
142
- e = e.filter((t) => t.deviceId !== "default"), this.#e.dispatchEvent(
143
- new CustomEvent("web-devices", {
144
- detail: e
145
- })
146
- );
147
- }
148
- emitDeviceChange() {
149
- S.dispatchEvent(M([...this.outputDevices]));
150
- }
151
- getNativeDevice(e) {
152
- return [...this.#t].find((t) => t.id === e);
153
- }
154
- async hydrateWebDevices() {
155
- const e = (await navigator.mediaDevices.enumerateDevices()).filter((t) => t.kind === "audiooutput");
156
- this.addWebDevices(e);
157
- }
158
- mergeDevices() {
159
- [...this.outputDevices].filter((e) => e.id !== "default").forEach((e) => {
160
- e.nativeDeviceId = void 0, e.webDeviceId = void 0;
161
- }), this.#t.forEach((e) => {
162
- const t = L(this.outputDevices, e.name);
163
- t ? (t.nativeDeviceId = e.id, t.controllableVolume = e.controllableVolume, t.type = b(e) || t.type) : this.outputDevices.add(
164
- new w({
165
- controllableVolume: e.controllableVolume,
166
- name: I(e.name, g.os.name || ""),
167
- nativeDeviceId: e.id,
168
- type: b(e)
169
- })
170
- );
171
- }), this.#r.forEach((e) => {
172
- const t = L(this.outputDevices, e.label);
173
- t ? (t.webDeviceId = e.deviceId, t.type = b(e) || t.type) : this.outputDevices.add(
174
- new w({
175
- name: I(e.label, g.os.name || ""),
176
- type: b(e),
177
- webDeviceId: e.deviceId
178
- })
179
- );
180
- }), [...this.outputDevices].filter(
181
- (e) => e.webDeviceId === void 0 && e.nativeDeviceId === void 0 || e.type === "airplay" || e.type === "windowsCommunication"
182
- ).forEach((e) => this.outputDevices.delete(e));
183
- }
184
- async queueUpdate() {
185
- const e = new Promise(
186
- (i) => this.#e.addEventListener(
187
- "native-devices",
188
- (a) => i(a.detail),
189
- { once: !0 }
190
- )
191
- ), t = new Promise(
192
- (i) => this.#e.addEventListener(
193
- "web-devices",
194
- (a) => i(a.detail),
195
- { once: !0 }
196
- )
197
- ), n = (i) => new Promise((a) => setTimeout(() => a(), i));
198
- await Promise.any([e, t, n(1e3)]), this.mergeDevices(), this.emitDeviceChange();
199
- }
200
- set activeDevice(e) {
201
- this.#i = e, this.#a = !1, this.#n = "shared", y.activePlayer?.updateOutputDevice()?.catch(console.error);
202
- }
203
- get activeDevice() {
204
- return this.#i;
205
- }
206
- /**
207
- * Set the current device mode for the output device.
208
- */
209
- set deviceMode(e) {
210
- const { activeDevice: t } = this, { activePlayer: n } = y;
211
- t && n && n.name === "nativePlayer" && this.deviceMode !== e && (this.#n = e, n.updateDeviceMode());
212
- }
213
- get deviceMode() {
214
- return this.#n;
215
- }
216
- /**
217
- * Set to true to disable software MQA decoder.
218
- */
219
- set passThrough(e) {
220
- const { activeDevice: t } = this, { activePlayer: n } = y;
221
- t && n && n.name === "nativePlayer" && this.passThrough !== e && (this.#a = e, n.updatePassThrough());
222
- }
223
- get passThrough() {
224
- return !!this.#a;
225
- }
226
- }
227
- const $ = new N();
228
- export {
229
- w as OutputDevice,
230
- N as OutputDevices,
231
- b as findOutputType,
232
- L as getOutputDeviceByName,
233
- B as isWindowsCommunicationsDevice,
234
- I as marshalLabel,
235
- $ as outputDevices
236
- };