@ozdemirburak/morse-code-translator 6.0.0 → 8.0.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.
@@ -1,609 +1,883 @@
1
- const b = {
2
- 1: {
3
- // Latin => https://en.wikipedia.org/wiki/Morse_code
4
- A: "01",
5
- B: "1000",
6
- C: "1010",
7
- D: "100",
8
- E: "0",
9
- F: "0010",
10
- G: "110",
11
- H: "0000",
12
- I: "00",
13
- J: "0111",
14
- K: "101",
15
- L: "0100",
16
- M: "11",
17
- N: "10",
18
- O: "111",
19
- P: "0110",
20
- Q: "1101",
21
- R: "010",
22
- S: "000",
23
- T: "1",
24
- U: "001",
25
- V: "0001",
26
- W: "011",
27
- X: "1001",
28
- Y: "1011",
29
- Z: "1100"
30
- },
31
- 2: {
32
- // Numbers
33
- 0: "11111",
34
- 1: "01111",
35
- 2: "00111",
36
- 3: "00011",
37
- 4: "00001",
38
- 5: "00000",
39
- 6: "10000",
40
- 7: "11000",
41
- 8: "11100",
42
- 9: "11110"
43
- },
44
- 3: {
45
- // Punctuation
46
- ".": "010101",
47
- ",": "110011",
48
- "?": "001100",
49
- "'": "011110",
50
- "!": "101011",
51
- "/": "10010",
52
- "(": "10110",
53
- ")": "101101",
54
- "&": "01000",
55
- ":": "111000",
56
- ";": "101010",
57
- "=": "10001",
58
- "+": "01010",
59
- "-": "100001",
60
- _: "001101",
61
- '"': "010010",
62
- $: "0001001",
63
- "@": "011010",
64
- "¿": "00101",
65
- "¡": "110001"
66
- },
67
- 4: {
68
- // Latin Extended => https://ham.stackexchange.com/questions/1379/international-characters-in-morse-code
69
- Ã: "01101",
70
- Á: "01101",
71
- Å: "01101",
72
- À: "01101",
73
- Â: "01101",
74
- Ä: "0101",
75
- Ą: "0101",
76
- Æ: "0101",
77
- Ç: "10100",
78
- Ć: "10100",
79
- Ĉ: "10100",
80
- Č: "110",
81
- Ð: "00110",
82
- È: "01001",
83
- Ę: "00100",
84
- Ë: "00100",
85
- É: "00100",
86
- Ê: "10010",
87
- Ğ: "11010",
88
- Ĝ: "11010",
89
- Ĥ: "1111",
90
- İ: "01001",
91
- Ï: "10011",
92
- Ì: "01110",
93
- Ĵ: "01110",
94
- Ł: "01001",
95
- Ń: "11011",
96
- Ñ: "11011",
97
- Ó: "1110",
98
- Ò: "1110",
99
- Ö: "1110",
100
- Ô: "1110",
101
- Ø: "1110",
102
- Ś: "0001000",
103
- Ş: "01100",
104
- Ș: "1111",
105
- Š: "1111",
106
- Ŝ: "00010",
107
- ß: "000000",
108
- Þ: "01100",
109
- Ü: "0011",
110
- Ù: "0011",
111
- Ŭ: "0011",
112
- Ž: "11001",
113
- Ź: "110010",
114
- Ż: "11001"
115
- },
116
- 5: {
117
- // Cyrillic Alphabet => https://en.wikipedia.org/wiki/Russian_Morse_code
118
- А: "01",
119
- Б: "1000",
120
- В: "011",
121
- Г: "110",
122
- Д: "100",
123
- Е: "0",
124
- Ж: "0001",
125
- З: "1100",
126
- И: "00",
127
- Й: "0111",
128
- К: "101",
129
- Л: "0100",
130
- М: "11",
131
- Н: "10",
132
- О: "111",
133
- П: "0110",
134
- Р: "010",
135
- С: "000",
136
- Т: "1",
137
- У: "001",
138
- Ф: "0010",
139
- Х: "0000",
140
- Ц: "1010",
141
- Ч: "1110",
142
- Ш: "1111",
143
- Щ: "1101",
144
- Ъ: "11011",
145
- Ы: "1011",
146
- Ь: "1001",
147
- Э: "00100",
148
- Ю: "0011",
149
- Я: "0101",
150
- Ї: "01110",
151
- Є: "00100",
152
- І: "00",
153
- Ґ: "110"
154
- },
155
- 6: {
156
- // Greek Alphabet => https://en.wikipedia.org/wiki/Morse_code_for_non-Latin_alphabets
157
- Α: "01",
158
- Β: "1000",
159
- Γ: "110",
160
- Δ: "100",
161
- Ε: "0",
162
- Ζ: "1100",
163
- Η: "0000",
164
- Θ: "1010",
165
- Ι: "00",
166
- Κ: "101",
167
- Λ: "0100",
168
- Μ: "11",
169
- Ν: "10",
170
- Ξ: "1001",
171
- Ο: "111",
172
- Π: "0110",
173
- Ρ: "010",
174
- Σ: "000",
175
- Τ: "1",
176
- Υ: "1011",
177
- Φ: "0010",
178
- Χ: "1111",
179
- Ψ: "1101",
180
- Ω: "011"
181
- },
182
- 7: {
183
- // Hebrew Alphabet => https://en.wikipedia.org/wiki/Morse_code_for_non-Latin_alphabets
184
- א: "01",
185
- ב: "1000",
186
- ג: "110",
187
- ד: "100",
188
- ה: "111",
189
- ו: "0",
190
- ז: "1100",
191
- ח: "0000",
192
- ט: "001",
193
- י: "00",
194
- כ: "101",
195
- ל: "0100",
196
- מ: "11",
197
- נ: "10",
198
- ס: "1010",
199
- ע: "0111",
200
- פ: "0110",
201
- צ: "011",
202
- ק: "1101",
203
- ר: "010",
204
- ש: "000",
205
- ת: "1"
206
- },
207
- 8: {
208
- // Arabic Alphabet => https://en.wikipedia.org/wiki/Morse_code_for_non-Latin_alphabets
209
- ا: "01",
210
- ب: "1000",
211
- ت: "1",
212
- ث: "1010",
213
- ج: "0111",
214
- ح: "0000",
215
- خ: "111",
216
- د: "100",
217
- ذ: "1100",
218
- ر: "010",
219
- ز: "1110",
220
- س: "000",
221
- ش: "1111",
222
- ص: "1001",
223
- ض: "0001",
224
- ط: "001",
225
- ظ: "1011",
226
- ع: "0101",
227
- غ: "110",
228
- ف: "0010",
229
- ق: "1101",
230
- ك: "101",
231
- ل: "0100",
232
- م: "11",
233
- ن: "10",
234
- ه: "00100",
235
- و: "011",
236
- ي: "00",
237
- ﺀ: "0"
238
- },
239
- 9: {
240
- // Persian Alphabet => https://en.wikipedia.org/wiki/Morse_code_for_non-Latin_alphabets
241
- ا: "01",
242
- ب: "1000",
243
- پ: "0110",
244
- ت: "1",
245
- ث: "1010",
246
- ج: "0111",
247
- چ: "1110",
248
- ح: "0000",
249
- خ: "1001",
250
- د: "100",
251
- ذ: "0001",
252
- ر: "010",
253
- ز: "1100",
254
- ژ: "110",
255
- س: "000",
256
- ش: "1111",
257
- ص: "0101",
258
- ض: "00100",
259
- ط: "001",
260
- ظ: "1011",
261
- ع: "111",
262
- غ: "0011",
263
- ف: "0010",
264
- ق: "111000",
265
- ک: "101",
266
- گ: "1101",
267
- ل: "0100",
268
- م: "11",
269
- ن: "10",
270
- و: "011",
271
- ه: "0",
272
- ی: "00"
273
- },
274
- 10: {
275
- // Japanese Alphabet => https://ja.wikipedia.org/wiki/%E3%83%A2%E3%83%BC%E3%83%AB%E3%82%B9%E7%AC%A6%E5%8F%B7#%E5%92%8C%E6%96%87%E3%83%A2%E3%83%BC%E3%83%AB%E3%82%B9%E7%AC%A6%E5%8F%B7
276
- ア: "11011",
277
- カ: "0100",
278
- サ: "10101",
279
- タ: "10",
280
- ナ: "010",
281
- ハ: "1000",
282
- マ: "1001",
283
- ヤ: "011",
284
- ラ: "000",
285
- ワ: "101",
286
- イ: "01",
287
- キ: "10100",
288
- シ: "11010",
289
- チ: "0010",
290
- ニ: "1010",
291
- ヒ: "11001",
292
- ミ: "00101",
293
- リ: "110",
294
- ヰ: "01001",
295
- ウ: "001",
296
- ク: "0001",
297
- ス: "11101",
298
- ツ: "0110",
299
- ヌ: "0000",
300
- フ: "1100",
301
- ム: "1",
302
- ユ: "10011",
303
- ル: "10110",
304
- ン: "01010",
305
- エ: "10111",
306
- ケ: "1011",
307
- セ: "01110",
308
- テ: "01011",
309
- ネ: "1101",
310
- ヘ: "0",
311
- メ: "10001",
312
- レ: "111",
313
- ヱ: "01100",
314
- オ: "01000",
315
- コ: "1111",
316
- ソ: "1110",
317
- ト: "00100",
318
- ノ: "0011",
319
- ホ: "100",
320
- モ: "10010",
321
- ヨ: "11",
322
- ロ: "0101",
323
- ヲ: "0111",
324
- "゛": "00",
325
- "゜": "00110",
326
- "。": "010100",
327
- ー: "01101",
328
- "、": "010101",
329
- "(": "101101",
330
- ")": "010010"
331
- },
332
- 11: {
333
- // Korean Alphabet => https://ko.wikipedia.org/wiki/%EB%AA%A8%EC%8A%A4_%EB%B6%80%ED%98%B8
334
- ㄱ: "0100",
335
- ㄴ: "0010",
336
- ㄷ: "1000",
337
- ㄹ: "0001",
338
- ㅁ: "11",
339
- ㅂ: "011",
340
- ㅅ: "110",
341
- ㅇ: "101",
342
- ㅈ: "0110",
343
- ㅊ: "1010",
344
- ㅋ: "1001",
345
- ㅌ: "1100",
346
- ㅍ: "111",
347
- ㅎ: "0111",
348
- ㅏ: "0",
349
- ㅑ: "00",
350
- ㅓ: "1",
351
- ㅕ: "000",
352
- ㅗ: "01",
353
- ㅛ: "10",
354
- ㅜ: "0000",
355
- ㅠ: "010",
356
- ㅡ: "100",
357
- ㅣ: "001",
358
- ㅐ: "1101",
359
- ㅔ: "1011"
360
- },
361
- 12: {
362
- // Thai Alphabet => https://th.wikipedia.org/wiki/รหัสมอร์ส
363
- ก: "110",
364
- ข: "1010",
365
- ค: "101",
366
- ง: "10110",
367
- จ: "10010",
368
- ฉ: "1111",
369
- ช: "1001",
370
- ซ: "1100",
371
- ญ: "0111",
372
- ด: "100",
373
- ต: "1",
374
- ถ: "10100",
375
- ท: "10011",
376
- น: "10",
377
- บ: "1000",
378
- ป: "0110",
379
- ผ: "1101",
380
- ฝ: "10101",
381
- พ: "01100",
382
- ฟ: "0010",
383
- ม: "11",
384
- ย: "1011",
385
- ร: "010",
386
- ล: "0100",
387
- ว: "011",
388
- ส: "000",
389
- ห: "0000",
390
- อ: "10001",
391
- ฮ: "11011",
392
- ฤ: "01011",
393
- ะ: "01000",
394
- า: "01",
395
- "ิ": "00100",
396
- "ี": "00",
397
- "ึ": "00110",
398
- "ื": "0011",
399
- "ุ": "00101",
400
- "ู": "1110",
401
- เ: "0",
402
- แ: "0101",
403
- ไ: "01001",
404
- โ: "111",
405
- ำ: "00010",
406
- "่": "001",
407
- "้": "0001",
408
- "๊": "11000",
409
- "๋": "01010",
410
- "ั": "01101",
411
- "็": "11100",
412
- "์": "11001",
413
- ๆ: "10111",
414
- ฯ: "11010"
415
- }
416
- }, L = (e) => ({
417
- ...b,
418
- 0: b[e.priority],
419
- 1: {
420
- ...b[1],
421
- [e.separator]: e.space
422
- }
423
- }), W = (e, t) => {
424
- const n = {}, s = L(e);
425
- for (const r in s) {
426
- n[r] = {};
427
- const w = s[r];
428
- if (w)
429
- for (const c in w)
430
- n[r][c] = w[c].replace(/0/g, e.dot).replace(/1/g, e.dash);
431
- }
432
- return t || delete n[0], n;
433
- }, q = (e) => {
434
- const t = {}, n = W(e, !0);
435
- for (const s in n)
436
- for (const r in n[s])
437
- typeof t[n[s][r]] > "u" && (t[n[s][r]] = r);
438
- return t;
439
- }, C = (e = {}) => ({
440
- ...e,
441
- dash: e.dash || "-",
442
- dot: e.dot || ".",
443
- space: e.space || "/",
444
- separator: e.separator || " ",
445
- invalid: e.invalid || "#",
446
- priority: e.priority || 1,
447
- wpm: e.wpm,
448
- // words per minute - PARIS method used in favour of unit/fwUnit options
449
- unit: e.unit || 0.08,
450
- // period of one unit, in seconds, 1.2 / c where c is speed of transmission, in words per minute
451
- fwUnit: e.fwUnit || e.unit || 0.08,
452
- // Farnsworth unit to control intercharacter and interword gaps
453
- volume: e.volume || 100,
454
- oscillator: {
455
- ...e.oscillator,
456
- type: e.oscillator?.type || "sine",
457
- // sine, square, sawtooth, triangle
458
- frequency: e.oscillator?.frequency || 500,
459
- // value in hertz
460
- onended: e.oscillator?.onended || null
461
- // event that fires when the tone has stopped playing
462
- }
463
- }), I = 44100, U = 1, M = 16, F = 1, j = 3, O = 1, z = 3, $ = 7, J = 50, K = (e, t, n = 0) => {
464
- const s = [];
465
- let { unit: r, fwUnit: w } = t, c = 0;
466
- t.wpm && (r = w = 60 / (t.wpm * J)), s.push([0, c]);
467
- const T = (o, u, a = !0) => {
468
- s.push([o, n + c]), c += u * (a ? r : w);
469
- }, i = (o) => T(t.volume / 100, o), m = (o) => T(0, o), y = (o) => T(0, o, !1);
470
- for (let o = 0, u = !1; o <= e.length; o++) {
471
- const a = e[o], f = e[o + 1], h = e[o - 1];
472
- a === t.space ? (y($), u = !1) : a === t.dot ? (u && m(O), i(F), u = !0) : a === t.dash ? (u && m(O), i(j), u = !0) : f !== void 0 && f !== t.space && h !== void 0 && h !== t.space && (y(z), u = !1);
473
- }
474
- return [s, c];
475
- }, Q = (e, t) => {
476
- const n = M / 8, s = U * n, r = e * s, w = t.length * n, c = 44 + w, T = new ArrayBuffer(c), i = new DataView(T), m = (o, u) => {
477
- for (let a = 0; a < u.length; a++)
478
- i.setUint8(o + a, u.charCodeAt(a));
479
- }, y = (o, u) => {
480
- for (let a = 0; a < u.length; a++, o += n) {
481
- const f = Math.max(-1, Math.min(1, u[a])), h = f < 0 ? f * 32768 : f * 32767;
482
- i.setInt16(o, h, !0);
483
- }
484
- };
485
- return m(0, "RIFF"), i.setUint32(4, c - 8, !0), m(8, "WAVE"), m(12, "fmt "), i.setUint32(16, 16, !0), i.setUint16(20, 1, !0), i.setUint16(22, U, !0), i.setUint32(24, e, !0), i.setUint32(28, r, !0), i.setUint16(32, s, !0), i.setUint16(34, M, !0), m(36, "data"), i.setUint32(40, w, !0), y(44, t), i;
486
- }, X = (e, t) => {
487
- const n = window.AudioContext || window.webkitAudioContext, s = window.OfflineAudioContext || window.webkitOfflineAudioContext;
488
- if (!n || !s)
489
- throw new Error("Web Audio API is not supported in this browser. Please use a modern browser with Web Audio API support.");
490
- const r = new n(), [w, c] = K(e, t), T = Math.ceil(I * c), i = new s(U, T, I), m = i.createOscillator(), y = i.createGain();
491
- m.type = t.oscillator.type, m.frequency.value = t.oscillator.frequency ?? 500, w.forEach(([l, p]) => {
492
- y.gain.setValueAtTime(l, p);
493
- }), m.connect(y), y.connect(i.destination);
494
- let o = null, u = null, a = "ready", f = 0, h = 0, g = null;
495
- const A = t.events || {};
496
- t.oscillator.onended && !A.onended && (A.onended = t.oscillator.onended);
497
- const R = new Promise((l, p) => {
498
- m.start(0), i.startRendering(), i.oncomplete = (d) => {
499
- try {
500
- u = d.renderedBuffer, a = "ready", A.onready?.(), l();
501
- } catch (_) {
502
- p(_);
503
- }
504
- }, i.addEventListener("error", (d) => {
505
- p(d);
506
- });
507
- }), D = () => {
508
- const l = r.createBufferSource();
509
- return l.buffer = u, l.connect(r.destination), l.onended = () => {
510
- const p = P();
511
- a === "playing" && p >= c - 0.01 && (a = "stopped", f = 0, A.onended?.());
512
- }, l;
513
- }, S = async () => {
514
- if (await R, r.state === "suspended" && await r.resume(), a === "playing")
515
- return;
516
- (!o || o.buffer === null) && (o = D()), o.start(r.currentTime, f), h = r.currentTime - f, a = "playing", A.onstarted?.();
517
- const l = (c - f) * 1e3;
518
- g = window.setTimeout(() => {
519
- a === "playing" && v();
520
- }, l);
521
- }, k = () => {
522
- a === "playing" && (g !== null && (clearTimeout(g), g = null), f = Math.min(r.currentTime - h, c), o && (o.stop(0), o = null), a = "paused", A.onpaused?.());
523
- }, v = (l = !1) => {
524
- if (g !== null && (clearTimeout(g), g = null), o) {
525
- try {
526
- o.stop(0);
527
- } catch {
528
- }
529
- o = null;
530
- }
531
- const p = a === "playing";
532
- a = "stopped", f = 0, h = 0, p && A.onstopped?.(), l && (u = null);
533
- }, N = async (l) => {
534
- const p = a === "playing", d = Math.max(0, Math.min(l, c));
535
- if (o) {
536
- g !== null && (clearTimeout(g), g = null);
537
- try {
538
- o.stop(0);
539
- } catch {
540
- }
541
- o = null;
542
- }
543
- f = d, A.onseeked?.(d), p && (a = "paused", await S());
544
- }, V = () => {
545
- v(!0), r.state !== "closed" && r.close();
546
- }, P = () => a === "playing" ? Math.min(r.currentTime - h, c) : f, G = () => c, H = () => a, E = async () => {
547
- if (await R, !u)
548
- throw new Error("Audio buffer not available");
549
- const l = Q(i.sampleRate, u.getChannelData(0)), p = new Uint8Array(l.byteLength);
550
- for (let d = 0; d < l.byteLength; d++)
551
- p[d] = l.getUint8(d);
552
- return new Blob([p], { type: "audio/wav" });
553
- }, x = async () => {
554
- const l = await E();
555
- return URL.createObjectURL(l);
556
- };
557
- return {
558
- // Playback control
559
- play: S,
560
- pause: k,
561
- stop: v,
562
- seek: N,
563
- dispose: V,
564
- // Playback information
565
- getCurrentTime: P,
566
- getTotalTime: G,
567
- getState: H,
568
- // Export functionality
569
- getWaveBlob: E,
570
- getWaveUrl: x,
571
- exportWave: async (l = "morse.wav") => {
572
- const p = await x(), d = document.createElement("a");
573
- d.href = p, d.target = "_blank", d.download = l, d.click();
574
- },
575
- // Context access (for advanced users)
576
- context: r,
577
- oscillator: m,
578
- gainNode: y
579
- };
580
- }, B = (e, t) => {
581
- const n = C(t), s = L(n);
582
- return [...e.replace(/\s+/g, n.separator).trim().toLocaleUpperCase()].map((r) => {
583
- for (const w in s) {
584
- const c = s[w];
585
- if (c && c[r])
586
- return c[r];
587
- }
588
- return n.invalid;
589
- }).join(n.separator).replace(/0/g, n.dot).replace(/1/g, n.dash);
590
- }, Y = (e, t) => {
591
- const n = C(t), s = q(n);
592
- return e.replace(/\s+/g, n.separator).trim().split(n.separator).map((r) => typeof s[r] < "u" ? s[r] : n.invalid).join("");
593
- }, Z = (e, t = !1) => W(C(e), t), e0 = (e, t, n) => {
594
- const s = n || B(e, t), r = C(t);
595
- return X(s, r);
596
- }, n0 = {
597
- encode: B,
598
- decode: Y,
599
- characters: Z,
600
- audio: e0
1
+ //#region src/characters.ts
2
+ var e = {
3
+ 1: {
4
+ A: "01",
5
+ B: "1000",
6
+ C: "1010",
7
+ D: "100",
8
+ E: "0",
9
+ F: "0010",
10
+ G: "110",
11
+ H: "0000",
12
+ I: "00",
13
+ J: "0111",
14
+ K: "101",
15
+ L: "0100",
16
+ M: "11",
17
+ N: "10",
18
+ O: "111",
19
+ P: "0110",
20
+ Q: "1101",
21
+ R: "010",
22
+ S: "000",
23
+ T: "1",
24
+ U: "001",
25
+ V: "0001",
26
+ W: "011",
27
+ X: "1001",
28
+ Y: "1011",
29
+ Z: "1100"
30
+ },
31
+ 2: {
32
+ 0: "11111",
33
+ 1: "01111",
34
+ 2: "00111",
35
+ 3: "00011",
36
+ 4: "00001",
37
+ 5: "00000",
38
+ 6: "10000",
39
+ 7: "11000",
40
+ 8: "11100",
41
+ 9: "11110"
42
+ },
43
+ 3: {
44
+ ".": "010101",
45
+ ",": "110011",
46
+ "?": "001100",
47
+ "'": "011110",
48
+ "!": "101011",
49
+ "/": "10010",
50
+ "(": "10110",
51
+ ")": "101101",
52
+ "&": "01000",
53
+ ":": "111000",
54
+ ";": "101010",
55
+ "=": "10001",
56
+ "+": "01010",
57
+ "-": "100001",
58
+ _: "001101",
59
+ "\"": "010010",
60
+ $: "0001001",
61
+ "@": "011010",
62
+ "¿": "00101",
63
+ "¡": "110001"
64
+ },
65
+ 4: {
66
+ Ã: "01101",
67
+ Á: "01101",
68
+ Å: "01101",
69
+ À: "01101",
70
+ Â: "01101",
71
+ Ä: "0101",
72
+ Ą: "0101",
73
+ Æ: "0101",
74
+ Ç: "10100",
75
+ Ć: "10100",
76
+ Ĉ: "10100",
77
+ Č: "110",
78
+ Ð: "00110",
79
+ È: "01001",
80
+ É: "00100",
81
+ Ę: "00100",
82
+ Ë: "00100",
83
+ Ê: "10010",
84
+ Ğ: "11010",
85
+ Ĝ: "11010",
86
+ Ĥ: "1111",
87
+ İ: "01001",
88
+ Ï: "10011",
89
+ Ì: "01110",
90
+ Ĵ: "01110",
91
+ Ł: "01001",
92
+ Ń: "11011",
93
+ Ñ: "11011",
94
+ Ó: "1110",
95
+ Ò: "1110",
96
+ Ö: "1110",
97
+ Ô: "1110",
98
+ Ø: "1110",
99
+ Ś: "0001000",
100
+ Ş: "01100",
101
+ Ș: "1111",
102
+ Š: "1111",
103
+ Ŝ: "00010",
104
+ Þ: "01100",
105
+ Ü: "0011",
106
+ Ù: "0011",
107
+ Ŭ: "0011",
108
+ Ž: "11001",
109
+ Ź: "110010",
110
+ Ż: "11001"
111
+ },
112
+ 5: {
113
+ А: "01",
114
+ Б: "1000",
115
+ В: "011",
116
+ Г: "110",
117
+ Д: "100",
118
+ Е: "0",
119
+ Ж: "0001",
120
+ З: "1100",
121
+ И: "00",
122
+ Й: "0111",
123
+ К: "101",
124
+ Л: "0100",
125
+ М: "11",
126
+ Н: "10",
127
+ О: "111",
128
+ П: "0110",
129
+ Р: "010",
130
+ С: "000",
131
+ Т: "1",
132
+ У: "001",
133
+ Ф: "0010",
134
+ Х: "0000",
135
+ Ц: "1010",
136
+ Ч: "1110",
137
+ Ш: "1111",
138
+ Щ: "1101",
139
+ Ъ: "11011",
140
+ Ы: "1011",
141
+ Ь: "1001",
142
+ Э: "00100",
143
+ Ю: "0011",
144
+ Я: "0101",
145
+ Ї: "01110",
146
+ Є: "00100",
147
+ І: "00",
148
+ Ґ: "110",
149
+ Ё: "0"
150
+ },
151
+ 6: {
152
+ Α: "01",
153
+ Β: "1000",
154
+ Γ: "110",
155
+ Δ: "100",
156
+ Ε: "0",
157
+ Ζ: "1100",
158
+ Η: "0000",
159
+ Θ: "1010",
160
+ Ι: "00",
161
+ Κ: "101",
162
+ Λ: "0100",
163
+ Μ: "11",
164
+ Ν: "10",
165
+ Ξ: "1001",
166
+ Ο: "111",
167
+ Π: "0110",
168
+ Ρ: "010",
169
+ Σ: "000",
170
+ Τ: "1",
171
+ Υ: "1011",
172
+ Φ: "0010",
173
+ Χ: "1111",
174
+ Ψ: "1101",
175
+ Ω: "011"
176
+ },
177
+ 7: {
178
+ א: "01",
179
+ ב: "1000",
180
+ ג: "110",
181
+ ד: "100",
182
+ ה: "111",
183
+ ו: "0",
184
+ ז: "1100",
185
+ ח: "0000",
186
+ ט: "001",
187
+ י: "00",
188
+ כ: "101",
189
+ ל: "0100",
190
+ מ: "11",
191
+ נ: "10",
192
+ ס: "1010",
193
+ ע: "0111",
194
+ פ: "0110",
195
+ צ: "011",
196
+ ק: "1101",
197
+ ר: "010",
198
+ ש: "000",
199
+ ת: "1",
200
+ ך: "101",
201
+ ם: "11",
202
+ ן: "10",
203
+ ף: "0110",
204
+ ץ: "011"
205
+ },
206
+ 8: {
207
+ ا: "01",
208
+ ب: "1000",
209
+ ت: "1",
210
+ ث: "1010",
211
+ ج: "0111",
212
+ ح: "0000",
213
+ خ: "111",
214
+ د: "100",
215
+ ذ: "1100",
216
+ ر: "010",
217
+ ز: "1110",
218
+ س: "000",
219
+ ش: "1111",
220
+ ص: "1001",
221
+ ض: "0001",
222
+ ط: "001",
223
+ ظ: "1011",
224
+ ع: "0101",
225
+ غ: "110",
226
+ ف: "0010",
227
+ ق: "1101",
228
+ ك: "101",
229
+ ل: "0100",
230
+ م: "11",
231
+ ن: "10",
232
+ ه: "00100",
233
+ و: "011",
234
+ ي: "00",
235
+ ء: "0",
236
+ ﺀ: "0"
237
+ },
238
+ 9: {
239
+ ا: "01",
240
+ ب: "1000",
241
+ پ: "0110",
242
+ ت: "1",
243
+ ث: "1010",
244
+ ج: "0111",
245
+ چ: "1110",
246
+ ح: "0000",
247
+ خ: "1001",
248
+ د: "100",
249
+ ذ: "0001",
250
+ ر: "010",
251
+ ز: "1100",
252
+ ژ: "110",
253
+ س: "000",
254
+ ش: "1111",
255
+ ص: "0101",
256
+ ض: "00100",
257
+ ط: "001",
258
+ ظ: "1011",
259
+ ع: "111",
260
+ غ: "0011",
261
+ ف: "0010",
262
+ ق: "111000",
263
+ ک: "101",
264
+ گ: "1101",
265
+ ل: "0100",
266
+ م: "11",
267
+ ن: "10",
268
+ و: "011",
269
+ ه: "0",
270
+ ی: "00"
271
+ },
272
+ 10: {
273
+ ア: "11011",
274
+ カ: "0100",
275
+ サ: "10101",
276
+ タ: "10",
277
+ ナ: "010",
278
+ ハ: "1000",
279
+ マ: "1001",
280
+ ヤ: "011",
281
+ ラ: "000",
282
+ ワ: "101",
283
+ イ: "01",
284
+ キ: "10100",
285
+ シ: "11010",
286
+ チ: "0010",
287
+ ニ: "1010",
288
+ ヒ: "11001",
289
+ ミ: "00101",
290
+ リ: "110",
291
+ ヰ: "01001",
292
+ ウ: "001",
293
+ ク: "0001",
294
+ ス: "11101",
295
+ ツ: "0110",
296
+ ヌ: "0000",
297
+ フ: "1100",
298
+ ム: "1",
299
+ ユ: "10011",
300
+ ル: "10110",
301
+ ン: "01010",
302
+ エ: "10111",
303
+ ケ: "1011",
304
+ セ: "01110",
305
+ テ: "01011",
306
+ ネ: "1101",
307
+ ヘ: "0",
308
+ メ: "10001",
309
+ レ: "111",
310
+ ヱ: "01100",
311
+ オ: "01000",
312
+ コ: "1111",
313
+ ソ: "1110",
314
+ ト: "00100",
315
+ ノ: "0011",
316
+ ホ: "100",
317
+ モ: "10010",
318
+ ヨ: "11",
319
+ ロ: "0101",
320
+ ヲ: "0111",
321
+ ゛: "00",
322
+ ゜: "00110",
323
+ "。": "010100",
324
+ ー: "01101",
325
+ "、": "010101",
326
+ "(": "101101",
327
+ ")": "010010"
328
+ },
329
+ 11: {
330
+ ㄱ: "0100",
331
+ ㄴ: "0010",
332
+ ㄷ: "1000",
333
+ ㄹ: "0001",
334
+ ㅁ: "11",
335
+ ㅂ: "011",
336
+ ㅅ: "110",
337
+ ㅇ: "101",
338
+ ㅈ: "0110",
339
+ ㅊ: "1010",
340
+ ㅋ: "1001",
341
+ ㅌ: "1100",
342
+ ㅍ: "111",
343
+ ㅎ: "0111",
344
+ ㅏ: "0",
345
+ ㅑ: "00",
346
+ ㅓ: "1",
347
+ ㅕ: "000",
348
+ ㅗ: "01",
349
+ ㅛ: "10",
350
+ ㅜ: "0000",
351
+ ㅠ: "010",
352
+ ㅡ: "100",
353
+ ㅣ: "001",
354
+ ㅐ: "1101",
355
+ ㅔ: "1011"
356
+ },
357
+ 12: {
358
+ ก: "110",
359
+ ข: "1010",
360
+ ค: "101",
361
+ ง: "10110",
362
+ จ: "10010",
363
+ ฉ: "1111",
364
+ ช: "1001",
365
+ ซ: "1100",
366
+ ญ: "0111",
367
+ ด: "100",
368
+ ต: "1",
369
+ ถ: "10100",
370
+ ท: "10011",
371
+ น: "10",
372
+ บ: "1000",
373
+ ป: "0110",
374
+ ผ: "1101",
375
+ ฝ: "10101",
376
+ พ: "01100",
377
+ ฟ: "0010",
378
+ ม: "11",
379
+ ย: "1011",
380
+ ร: "010",
381
+ ล: "0100",
382
+ ว: "011",
383
+ ส: "000",
384
+ ห: "0000",
385
+ อ: "10001",
386
+ ฮ: "11011",
387
+ ฤ: "01011",
388
+ ะ: "01000",
389
+ า: "01",
390
+ "ิ": "00100",
391
+ "ี": "00",
392
+ "ึ": "00110",
393
+ "ื": "0011",
394
+ "ุ": "00101",
395
+ "ู": "1110",
396
+ เ: "0",
397
+ แ: "0101",
398
+ ไ: "01001",
399
+ โ: "111",
400
+ ำ: "00010",
401
+ "่": "001",
402
+ "้": "0001",
403
+ "๊": "11000",
404
+ "๋": "01010",
405
+ "ั": "01101",
406
+ "็": "11100",
407
+ "์": "11001",
408
+ ๆ: "10111",
409
+ ฯ: "11010",
410
+ ฃ: "1010",
411
+ ฅ: "101",
412
+ ฆ: "101",
413
+ ศ: "000",
414
+ ษ: "000",
415
+ ฌ: "1001",
416
+ ฎ: "100",
417
+ ฏ: "1",
418
+ ฐ: "10100",
419
+ ฑ: "10011",
420
+ ฒ: "10011",
421
+ ธ: "10011",
422
+ ณ: "10",
423
+ ภ: "01100",
424
+ ฬ: "0100",
425
+ ใ: "01001"
426
+ }
427
+ }, t = 16, n = /* @__PURE__ */ new Map(), r = (r) => {
428
+ let i = JSON.stringify([
429
+ r.dot,
430
+ r.dash,
431
+ r.space,
432
+ r.priority
433
+ ]), a = n.get(i);
434
+ if (a) return a;
435
+ let o = {}, s = {
436
+ ...e,
437
+ 0: e[r.priority]
438
+ };
439
+ for (let e in s) {
440
+ o[e] = {};
441
+ for (let t in s[e]) o[e][t] = s[e][t].replace(/[01]/g, (e) => e === "0" ? r.dot : r.dash);
442
+ }
443
+ let c = Object.create(null);
444
+ for (let e in o) for (let t in o[e]) c[o[e][t]] ??= t;
445
+ c[r.space] = " ", n.size >= t && n.delete(n.keys().next().value);
446
+ let l = {
447
+ mapped: o,
448
+ swapped: c
449
+ };
450
+ return n.set(i, l), l;
451
+ }, i = (e) => r(e).mapped, a = (e) => r(e).swapped, o = (e, t) => {
452
+ let n = {}, { mapped: i } = r(e);
453
+ for (let e in i) (e !== "0" || t) && (n[e] = { ...i[e] });
454
+ return n;
455
+ }, s = (e, t) => {
456
+ let n = [];
457
+ for (let r of e.trim().replace(/\s+/g, t.separator).split(t.separator)) r.split(t.space).forEach((e, r) => {
458
+ r > 0 && n.push(t.space), e !== "" && n.push(e);
459
+ });
460
+ return n;
461
+ }, c = 22050, l = {
462
+ dash: "-",
463
+ dot: ".",
464
+ space: "/",
465
+ separator: " ",
466
+ invalid: "#"
467
+ }, u = (e) => typeof e == "number" && Number.isFinite(e) && e > 0, d = (t) => Object.values(e).some((e) => Object.prototype.hasOwnProperty.call(e, t)), f = (e, t, n) => {
468
+ if (e === "") return !1;
469
+ let r = 0;
470
+ for (; r < e.length;) if (e.startsWith(t, r)) r += t.length;
471
+ else if (e.startsWith(n, r)) r += n.length;
472
+ else return !1;
473
+ return !0;
601
474
  };
602
- export {
603
- e0 as audio,
604
- Z as characters,
605
- Y as decode,
606
- n0 as default,
607
- B as encode
475
+ function p(e, t) {
476
+ if (typeof e != "string") throw TypeError(`morse-code-translator: ${t} must be a string.`);
477
+ }
478
+ var m = (e, t) => {
479
+ let n = e[t];
480
+ return n == null ? l[t] : (p(n, `"${t}"`), n === "" && t !== "invalid" ? l[t] : n);
481
+ }, h = (e) => {
482
+ let t = typeof e == "string" && /^\d+$/.test(e) ? Number(e) : e;
483
+ return Number.isInteger(t) && t >= 1 && t <= 12 ? t : 1;
484
+ }, g = (e) => {
485
+ if (e.dot === e.dash) throw Error("morse-code-translator: \"dot\" and \"dash\" symbols must be different.");
486
+ if (e.dot.startsWith(e.dash) || e.dash.startsWith(e.dot)) throw Error("morse-code-translator: \"dot\" and \"dash\" must not be a prefix of each other.");
487
+ if (e.separator === e.space) throw Error("morse-code-translator: \"separator\" and \"space\" symbols must be different.");
488
+ for (let [t, n] of [["separator", e.separator], ["space", e.space]]) {
489
+ if ([...n].length !== 1) throw Error(`morse-code-translator: "${t}" must be a single character.`);
490
+ if (n === e.dot || n === e.dash) throw Error(`morse-code-translator: "${t}" must differ from the "dot" and "dash" symbols.`);
491
+ if (f(n, e.dot, e.dash)) throw Error(`morse-code-translator: "${t}" must not be composed solely of "dot"/"dash" symbols.`);
492
+ if (t === "space" && /\s/.test(n)) throw Error("morse-code-translator: \"space\" must not be a whitespace character.");
493
+ }
494
+ for (let [t, n] of [["dot", e.dot], ["dash", e.dash]]) if (n.includes(e.space) || n.includes(e.separator) || /\s/.test(n)) throw Error(`morse-code-translator: "${t}" must not contain whitespace or the "space"/"separator" symbol.`);
495
+ if (d(e.separator)) throw Error("morse-code-translator: \"separator\" must not be an encodable character.");
496
+ if (e.invalid !== "") {
497
+ if (f(e.invalid, e.dot, e.dash)) throw Error("morse-code-translator: \"invalid\" must not be composed solely of \"dot\"/\"dash\" symbols.");
498
+ if (e.invalid.includes(e.space) || e.invalid.includes(e.separator) || /\s/.test(e.invalid)) throw Error("morse-code-translator: \"invalid\" must not contain whitespace or the \"space\"/\"separator\" symbol.");
499
+ }
500
+ }, _ = (e) => {
501
+ let t = e ?? {}, n = u(t.unit) ? t.unit : .08, r = u(t.fwUnit) ? t.fwUnit : n, i = u(t.wpm) ? t.wpm : void 0, a = t.oscillator?.frequency, o = u(a) && a <= c ? a : 500, s = typeof t.volume == "number" && Number.isFinite(t.volume) ? Math.min(100, Math.max(0, t.volume)) : 100, l = h(t.priority), d = t.oscillator?.type, f = d === "sine" || d === "square" || d === "sawtooth" || d === "triangle" ? d : "sine", p = {
502
+ ...t,
503
+ dash: m(t, "dash"),
504
+ dot: m(t, "dot"),
505
+ space: m(t, "space"),
506
+ separator: m(t, "separator"),
507
+ invalid: m(t, "invalid"),
508
+ priority: l,
509
+ wpm: i,
510
+ unit: n,
511
+ fwUnit: r,
512
+ volume: s,
513
+ oscillator: {
514
+ type: f,
515
+ frequency: o
516
+ },
517
+ events: t.events ? { ...t.events } : t.events
518
+ };
519
+ return g(p), p;
520
+ }, v = 44100, y = 1, ee = 16, b = 44, te = 4294967259, x = 1, S = 3, C = 1, w = 3, T = 7, E = 50, D = .005, ne = 3, O = .005, re = 2, ie = 2, k = /* @__PURE__ */ Error("morse-code-translator: render cancelled."), A = (e) => {
521
+ if (e.wpm) {
522
+ let t = 60 / (e.wpm * E);
523
+ return [t, t];
524
+ }
525
+ return [e.unit, e.fwUnit];
526
+ }, ae = (e, t) => {
527
+ let [n, r] = A(t), i = t.dot.length >= t.dash.length ? [[t.dot, x], [t.dash, S]] : [[t.dash, S], [t.dot, x]], a = [], o = 0, c = !1;
528
+ for (let l of s(e, t)) {
529
+ if (l === t.space) {
530
+ c = a.length > 0;
531
+ continue;
532
+ }
533
+ if (l === t.invalid) continue;
534
+ let e = [];
535
+ for (let t = 0; t < l.length;) {
536
+ let n = i.find(([e]) => l.startsWith(e, t));
537
+ n ? (e.push(n[1]), t += n[0].length) : t += 1;
538
+ }
539
+ e.length !== 0 && (a.length > 0 && (o += (c ? T : w) * r), c = !1, e.forEach((e, t) => {
540
+ t > 0 && (o += C * n), a.push(o, e * n), o += e * n;
541
+ }));
542
+ }
543
+ if (!Number.isFinite(o)) throw RangeError("morse-code-translator: audio duration is not finite; use a smaller unit/fwUnit.");
544
+ return {
545
+ tones: Float64Array.from(a),
546
+ totalTime: o
547
+ };
548
+ }, j = (e, t, n) => {
549
+ let r = .5 * t / n + 1e-6;
550
+ return Math.max(0, Math.ceil(e * t - r) / t - e);
551
+ }, oe = (e, t, n, r, i = 30 * n) => {
552
+ let a = e.length / 2, o = (t) => Math.floor(e[t * 2] * n), s = (t) => Math.ceil((e[t * 2] + e[t * 2 + 1]) * n), c = Math.ceil(n / r) + 1, l = (e) => {
553
+ let t = 0, n = a;
554
+ for (; t < n;) {
555
+ let r = t + n >> 1;
556
+ s(r) <= e ? t = r + 1 : n = r;
557
+ }
558
+ return t;
559
+ }, u = (e) => {
560
+ let u = e * i;
561
+ if (e === 0 || u >= t) return Math.min(u, t);
562
+ let d = u + i;
563
+ for (let e = l(u); e <= a; e++) {
564
+ let n = e === 0 ? u : Math.max(u, s(e - 1));
565
+ if (n >= d || n >= t) break;
566
+ if (e === a || o(e) - n >= c) return n;
567
+ }
568
+ return t <= d ? t : Math.min(Math.round(Math.ceil(u / n * r) / r * n), t);
569
+ };
570
+ return {
571
+ startFor: (e) => {
572
+ let t = Math.floor(e / i), n = u(t);
573
+ return n <= e ? n : u(t - 1);
574
+ },
575
+ next: (e) => u(Math.floor(e / i) + 1)
576
+ };
577
+ }, se = (e, t, n, r, i) => {
578
+ let a = Math.max(1, i - r), o = new e(y, a, v), s = o.createOscillator(), c = o.createGain(), l = n.oscillator.frequency ?? 500, u = n.volume / 100;
579
+ s.type = n.oscillator.type ?? "sine", s.frequency.value = l;
580
+ let d = r / v, f = d + a / v, p = (e) => {
581
+ let n = t[e * 2], r = t[e * 2 + 1], i = Math.min(D, r / 4);
582
+ return [
583
+ [
584
+ n,
585
+ 0,
586
+ !1
587
+ ],
588
+ [
589
+ n + i,
590
+ u,
591
+ !0
592
+ ],
593
+ [
594
+ n + r - i,
595
+ u,
596
+ !1
597
+ ],
598
+ [
599
+ n + r,
600
+ 0,
601
+ !0
602
+ ]
603
+ ];
604
+ }, m = 0;
605
+ for (let e = 0, n = t.length / 2; e < n;) {
606
+ let r = e + n >> 1;
607
+ t[r * 2] + t[r * 2 + 1] <= d ? e = r + 1 : n = r, m = e;
608
+ }
609
+ let h = c.gain, g = 0;
610
+ if (m * 2 < t.length && t[m * 2] < d) {
611
+ let e = p(m);
612
+ for (let t = 1; t < e.length; t++) {
613
+ let [n, r, i] = e[t];
614
+ if (n > d) {
615
+ let [a, o] = e[t - 1];
616
+ g = i ? o + (r - o) * (d - a) / (n - a) : o;
617
+ break;
618
+ }
619
+ }
620
+ }
621
+ h.setValueAtTime(g, 0);
622
+ for (let e = m; e * 2 < t.length && t[e * 2] < f; e++) for (let [t, n, r] of p(e)) t > d && (r ? h.linearRampToValueAtTime(n, t - d) : h.setValueAtTime(n, t - d));
623
+ return s.connect(c), c.connect(o.destination), s.start(j(d, l, v)), o.startRendering();
624
+ }, M = (e, t, n) => {
625
+ for (let r = 0; r < n.length; r++) e.setUint8(t + r, n.charCodeAt(r));
626
+ }, ce = (e, t) => {
627
+ let n = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(b));
628
+ return M(n, 0, "RIFF"), n.setUint32(4, 36 + t, !0), M(n, 8, "WAVE"), M(n, 12, "fmt "), n.setUint32(16, 16, !0), n.setUint16(20, 1, !0), n.setUint16(22, y, !0), n.setUint32(24, e, !0), n.setUint32(28, e * 2, !0), n.setUint16(32, 2, !0), n.setUint16(34, ee, !0), M(n, 36, "data"), n.setUint32(40, t, !0), n.buffer;
629
+ }, le = (e) => {
630
+ let t = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(e.length * 2));
631
+ for (let n = 0; n < e.length; n++) {
632
+ let r = Math.max(-1, Math.min(1, e[n]));
633
+ t.setInt16(n * 2, r < 0 ? r * 32768 : r * 32767, !0);
634
+ }
635
+ return t.buffer;
636
+ }, N = (e, ...t) => {
637
+ try {
638
+ e?.(...t);
639
+ } catch (e) {
640
+ console.error(e);
641
+ }
642
+ }, ue = (e, t) => {
643
+ let n = typeof window < "u" && window ? window : globalThis, r = n.AudioContext, i = n.OfflineAudioContext;
644
+ if (!r || !i) throw Error("Web Audio API is not supported in this browser. Please use a modern browser with Web Audio API support.");
645
+ let { tones: a, totalTime: o } = ae(e, t), s = Math.max(1, Math.ceil(v * o)), c = oe(a, s, v, t.oscillator.frequency ?? 500), l = (e) => se(i, a, t, e, Math.min(c.next(e), s)), u = null, d = /* @__PURE__ */ new Set(), f = null, p = 0, m = 0, h = 0, g = !1, _ = "ready", b = 0, x = 0, S = !1, C = null, w = 0, T = () => (!u && _ !== "disposed" && (u = new r()), u), E = t.events || {}, D = /* @__PURE__ */ new Map(), A = [], j = /* @__PURE__ */ new Map(), M = 0, ue = (e) => {
646
+ try {
647
+ return l(e);
648
+ } catch (e) {
649
+ return Promise.reject(e);
650
+ }
651
+ }, de = (e) => {
652
+ j.get(e.start) === e && j.delete(e.start), D.get(e.start) === e.promise && D.delete(e.start);
653
+ }, P = () => {
654
+ for (; M < re && A.length > 0;) {
655
+ let e = A.shift();
656
+ e.wanted.some((e) => e()) ? (M++, ue(e.start).then(e.resolve, e.reject).finally(() => {
657
+ j.get(e.start) === e && j.delete(e.start), M--, P();
658
+ })) : (de(e), e.reject(k));
659
+ }
660
+ }, F = (e, t) => {
661
+ let n = {
662
+ start: e,
663
+ wanted: [t]
664
+ };
665
+ return n.promise = new Promise((e, t) => {
666
+ n.resolve = e, n.reject = t;
667
+ }), A.push(n), n;
668
+ }, I = (e, t = () => !0) => {
669
+ let n = D.get(e);
670
+ if (n) j.get(e)?.wanted.push(t), D.delete(e);
671
+ else {
672
+ let r = F(e, t);
673
+ j.set(e, r), n = r.promise;
674
+ let i = n;
675
+ i.catch(() => {
676
+ D.get(e) === i && D.delete(e);
677
+ });
678
+ }
679
+ for (D.set(e, n); D.size > ne;) D.delete(D.keys().next().value);
680
+ return P(), n;
681
+ }, L = null, R = () => (L ??= I(0).then(() => {
682
+ _ !== "disposed" && N(E.onready);
683
+ }, (e) => {
684
+ throw L = null, e;
685
+ }), L);
686
+ R().catch(() => {});
687
+ let z = () => {
688
+ let e = u, t = e !== null && f !== null, n = t ? e.currentTime + O : 0;
689
+ if (t) {
690
+ let { gain: t } = f, r = e.currentTime, i = Math.min(1, Math.max(0, (r - p) / O));
691
+ t.cancelScheduledValues(r), t.setValueAtTime(i, r), t.linearRampToValueAtTime(0, n), m = n;
692
+ }
693
+ for (let e of d) try {
694
+ e.stop(n);
695
+ } catch {}
696
+ return d.clear(), f = null, g = !1, t;
697
+ }, fe = () => {
698
+ d.clear(), f = null, _ = "stopped", b = 0, x = 0, N(E.onended);
699
+ }, B = (e, t, n) => {
700
+ let r = u, i = x + e / v, a = r.currentTime, o = r.createBufferSource();
701
+ if (o.buffer = t, a > i + 1 / v) {
702
+ let e = r.createGain();
703
+ e.gain.setValueAtTime(0, a), e.gain.linearRampToValueAtTime(1, a + O), e.connect(f), o.connect(e);
704
+ } else o.connect(f);
705
+ o.onended = () => {
706
+ d.delete(o), w === n && _ === "playing" && (d.size === 0 && h >= s ? fe() : H(n));
707
+ }, o.start(Math.max(i, a), Math.max(0, a - i)), d.add(o), h = c.next(e);
708
+ }, V = -1, H = (e) => {
709
+ if (g || d.size >= 2 || h >= s) return;
710
+ let t = h, n = () => w === e && _ === "playing";
711
+ g = !0, I(t, n).then((r) => {
712
+ n() && (g = !1, B(t, r, e), H(e));
713
+ }, (r) => {
714
+ n() && (g = !1, r === k ? H(e) : (console.error(r), V === t ? d.size === 0 && W() : (V = t, d.size === 0 && H(e))));
715
+ });
716
+ }, U = async () => {
717
+ if (_ === "playing" || _ === "disposed") return;
718
+ let e = T(), t = () => e.state === "suspended" || e.state === "interrupted", n = t() ? e.resume() : null;
719
+ n?.catch(() => {});
720
+ let r = ++w;
721
+ S = !0;
722
+ let i = () => w === r && _ !== "disposed", a = (e) => I(e, i).catch(() => i() ? I(e, i) : Promise.reject(k));
723
+ try {
724
+ let o = b, l = c.startFor(Math.floor(o * v)), u = c.next(l), d = a(l), m = u < s && u / v - o < ie ? I(u, i).catch(() => null) : null, h = Promise.all([d, m]);
725
+ h.catch(() => {});
726
+ let y;
727
+ try {
728
+ if (y = await h, !i() || (await R().catch(() => {}), !i())) return;
729
+ n && await n, t() && await e.resume();
730
+ } catch (e) {
731
+ if (!i()) return;
732
+ throw C === "playing" ? W() : C !== null && (_ = C, C = null), e;
733
+ }
734
+ if (!i()) return;
735
+ x = e.currentTime - o, _ = "playing", S = !1, C = null, V = -1, p = e.currentTime, f = e.createGain(), f.gain.setValueAtTime(0, e.currentTime), f.gain.linearRampToValueAtTime(1, e.currentTime + O), f.connect(e.destination), g = !1, B(l, y[0], r), y[1] && B(u, y[1], r), H(r), N(E.onstarted);
736
+ } finally {
737
+ w === r && (S = !1);
738
+ }
739
+ }, pe = () => {
740
+ _ !== "disposed" && (_ === "playing" ? (w++, S = !1, C = null, b = Math.min(T().currentTime - x, o), z(), _ = "paused", N(E.onpaused)) : S && (w++, S = !1, C = null, z(), _ = "paused", N(E.onpaused)));
741
+ }, W = (e = !1) => {
742
+ if (_ === "disposed") return;
743
+ w++, z();
744
+ let t = _ === "playing" || _ === "paused" || S;
745
+ S = !1, C = null, _ = "stopped", b = 0, x = 0, t && N(E.onstopped), e && D.clear();
746
+ }, me = async (e) => {
747
+ if (_ === "disposed") return;
748
+ let t = _ === "playing" || S, n = Number(e), r = Number.isNaN(n) ? 0 : Math.max(0, Math.min(n, o)), i = ++w;
749
+ z(), b = r, t && (C ??= K(), _ = "paused", S = !0), N(E.onseeked, r), t && w === i && await U();
750
+ }, G = () => {
751
+ if (_ === "disposed") return;
752
+ W(!0), _ = "disposed";
753
+ let e = u;
754
+ if (e && e.state !== "closed") {
755
+ let t = () => e.close().catch(() => {}), n = m - e.currentTime;
756
+ n > 0 ? setTimeout(t, n * 1e3 + 45) : t();
757
+ }
758
+ }, he = () => _ === "playing" ? Math.min(T().currentTime - x, o) : b, ge = () => o, K = () => C ?? _, q = null, J = () => _ === "disposed" ? Promise.reject(/* @__PURE__ */ Error("Audio buffer not available")) : (q ??= Y().finally(() => {
759
+ q = null;
760
+ }), q), Y = async () => {
761
+ if (await R(), _ === "disposed") throw Error("Audio buffer not available");
762
+ let e = ee / 8 * s * y;
763
+ if (e > te) throw RangeError("morse-code-translator: audio is too long for a WAV file (about 13.5 hours at most).");
764
+ let t = [ce(v, e)];
765
+ for (let e = 0; e < s; e = c.next(e)) {
766
+ let n = () => {
767
+ let t = F(e, () => _ !== "disposed");
768
+ return P(), t.promise;
769
+ }, r = D.get(e), i = await (r ? r.catch((e) => e === k ? n() : Promise.reject(e)) : n());
770
+ t.push(le(i.getChannelData(0)));
771
+ }
772
+ return new Blob(t, { type: "audio/wav" });
773
+ }, X = async () => {
774
+ let e = await J();
775
+ return URL.createObjectURL(e);
776
+ }, Z = {
777
+ play: U,
778
+ pause: pe,
779
+ stop: W,
780
+ seek: me,
781
+ dispose: G,
782
+ getCurrentTime: he,
783
+ getTotalTime: ge,
784
+ getState: K,
785
+ getWaveBlob: J,
786
+ getWaveUrl: X,
787
+ exportWave: async (e = "morse.wav") => {
788
+ let t = await X(), n = document.createElement("a");
789
+ n.href = t, n.target = "_blank", n.download = e, n.click(), setTimeout(() => URL.revokeObjectURL(t), 1e3);
790
+ }
791
+ };
792
+ return Object.defineProperty(Z, "context", {
793
+ get: T,
794
+ enumerable: !1,
795
+ configurable: !0
796
+ }), Z;
797
+ }, de = 44032, P = 55203, F = "ㄱㄲㄴㄷㄸㄹㅁㅂㅃㅅㅆㅇㅈㅉㅊㅋㅌㅍㅎ", I = "ㅏㅐㅑㅒㅓㅔㅕㅖㅗㅘㅙㅚㅛㅜㅝㅞㅟㅠㅡㅢㅣ", L = ["", ..."ㄱㄲㄳㄴㄵㄶㄷㄹㄺㄻㄼㄽㄾㄿㅀㅁㅂㅄㅅㅆㅇㅈㅊㅋㅌㅍㅎ"], R = {
798
+ ㄲ: "ㄱㄱ",
799
+ ㄸ: "ㄷㄷ",
800
+ ㅃ: "ㅂㅂ",
801
+ ㅆ: "ㅅㅅ",
802
+ ㅉ: "ㅈㅈ",
803
+ ㄳ: "ㄱㅅ",
804
+ ㄵ: "ㄴㅈ",
805
+ ㄶ: "ㄴㅎ",
806
+ ㄺ: "ㄹㄱ",
807
+ ㄻ: "ㄹㅁ",
808
+ ㄼ: "ㄹㅂ",
809
+ ㄽ: "ㄹㅅ",
810
+ ㄾ: "ㄹㅌ",
811
+ ㄿ: "ㄹㅍ",
812
+ ㅀ: "ㄹㅎ",
813
+ ㅄ: "ㅂㅅ",
814
+ ㅒ: "ㅑㅣ",
815
+ ㅖ: "ㅕㅣ",
816
+ ㅘ: "ㅗㅏ",
817
+ ㅙ: "ㅗㅐ",
818
+ ㅚ: "ㅗㅣ",
819
+ ㅝ: "ㅜㅓ",
820
+ ㅞ: "ㅜㅔ",
821
+ ㅟ: "ㅜㅣ",
822
+ ㅢ: "ㅡㅣ"
823
+ }, z = (e) => R[e] ?? e, fe = (e) => {
824
+ let t = e - de;
825
+ return z(F[Math.floor(t / 588)]) + z(I[Math.floor(t % 588 / 28)]) + z(L[t % 28]);
826
+ }, B = {
827
+ ァ: "ア",
828
+ ィ: "イ",
829
+ ゥ: "ウ",
830
+ ェ: "エ",
831
+ ォ: "オ",
832
+ ッ: "ツ",
833
+ ャ: "ヤ",
834
+ ュ: "ユ",
835
+ ョ: "ヨ",
836
+ ヮ: "ワ",
837
+ ヵ: "カ",
838
+ ヶ: "ケ"
839
+ }, V = /[ぁ-ゖ]/, H = /[゠-ヿ]/, U = /[ヽヾ]/, pe = /[\uFF01-\uFF07\uFF0A-\uFF5E\uFF61-\uFF9F]+/g, W = /[\u3099\u309A]/g, me = /(?<=[\u3041-\u3096\u30A1-\u30FA\u30FC])[\u3099\u309A]/g, G = (e) => e === "゙" ? "゛" : "゜", he = /[\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7]/g, ge = /[\u0640\u064B-\u065F\u0670]/g, K = /[\u0660-\u0669\u06F0-\u06F9\u0E50-\u0E59]/g, q = (e) => String(e.codePointAt(0) & 15), J = /\u0E4D\u0E32/g, Y = {
840
+ "؟": "?",
841
+ "،": ",",
842
+ "؛": ";",
843
+ "־": "-"
844
+ }, X = /[Ͱ-Ͽἀ-῿][̀-ͯ]*/g, Z = /[̀-ͯ]/g, _e = (e) => U.test(e) ? e : [...e.normalize("NFD").replace(/゙/g, "゛").replace(/゚/g, "゜")].map((e) => B[e] ?? e).join(""), ve = (e) => {
845
+ let t = e.codePointAt(0);
846
+ return t >= de && t <= P ? fe(t) : V.test(e) ? _e(String.fromCodePoint(t + 96)) : H.test(e) ? _e(e) : e === "ẞ" ? "SS" : Y[e] ? Y[e] : z(e);
847
+ }, ye = (e) => [...e.toUpperCase().replace(pe, (e) => e.normalize("NFKC").replace(W, G)).normalize("NFC").replace(me, G).replace(he, "").replace(ge, "").replace(K, q).replace(J, "ำ").replace(X, (e) => e.normalize("NFD").replace(Z, ""))].map(ve).join(""), Q;
848
+ function* be(e) {
849
+ if (Q === void 0 && (Q = typeof Intl < "u" && typeof Intl.Segmenter == "function" ? new Intl.Segmenter(void 0, { granularity: "grapheme" }) : null), Q) for (let { segment: t } of Q.segment(e)) yield t;
850
+ else yield* e;
851
+ }
852
+ var xe = /^\p{Default_Ignorable_Code_Point}$/u, Se = /[^\S\uFEFF]+/g, $ = (e, t) => {
853
+ p(e, "text");
854
+ let n = _(t), r = i(n), a = (e) => {
855
+ for (let t in r) if (Object.prototype.hasOwnProperty.call(r[t], e)) return r[t][e];
856
+ }, o = [], s = (e) => {
857
+ e !== "" && (e !== n.space || o.length !== 0 && o[o.length - 1] !== n.space) && o.push(e);
858
+ };
859
+ for (let t of be(ye(e.trim()).replace(Se, n.separator))) {
860
+ let e = !1;
861
+ for (let r of t) {
862
+ let t = r === n.separator ? n.space : a(r);
863
+ t === void 0 ? xe.test(r) || (e || s(n.invalid), e = !0) : (s(t), e = !1);
864
+ }
865
+ }
866
+ return o[o.length - 1] === n.space && o.pop(), o.join(n.separator);
867
+ }, Ce = (e, t) => {
868
+ p(e, "morse");
869
+ let n = _(t), r = a(n);
870
+ return s(e, n).map((e) => r[e] ?? n.invalid).join("");
871
+ }, we = (e, t = !1) => o(_(e), t), Te = (e, t, n) => {
872
+ let r = _(t);
873
+ return n !== void 0 && p(n, "morseString"), ue(n ?? $(e, t), r);
874
+ }, Ee = {
875
+ encode: $,
876
+ decode: Ce,
877
+ characters: we,
878
+ audio: Te
608
879
  };
609
- //# sourceMappingURL=morse-code-translator.es.js.map
880
+ //#endregion
881
+ export { Te as audio, we as characters, Ce as decode, Ee as default, $ as encode };
882
+
883
+ //# sourceMappingURL=morse-code-translator.es.js.map