@ozdemirburak/morse-code-translator 6.0.0 → 7.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,616 @@
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
+ },
150
+ 6: {
151
+ Α: "01",
152
+ Β: "1000",
153
+ Γ: "110",
154
+ Δ: "100",
155
+ Ε: "0",
156
+ Ζ: "1100",
157
+ Η: "0000",
158
+ Θ: "1010",
159
+ Ι: "00",
160
+ Κ: "101",
161
+ Λ: "0100",
162
+ Μ: "11",
163
+ Ν: "10",
164
+ Ξ: "1001",
165
+ Ο: "111",
166
+ Π: "0110",
167
+ Ρ: "010",
168
+ Σ: "000",
169
+ Τ: "1",
170
+ Υ: "1011",
171
+ Φ: "0010",
172
+ Χ: "1111",
173
+ Ψ: "1101",
174
+ Ω: "011"
175
+ },
176
+ 7: {
177
+ א: "01",
178
+ ב: "1000",
179
+ ג: "110",
180
+ ד: "100",
181
+ ה: "111",
182
+ ו: "0",
183
+ ז: "1100",
184
+ ח: "0000",
185
+ ט: "001",
186
+ י: "00",
187
+ כ: "101",
188
+ ל: "0100",
189
+ מ: "11",
190
+ נ: "10",
191
+ ס: "1010",
192
+ ע: "0111",
193
+ פ: "0110",
194
+ צ: "011",
195
+ ק: "1101",
196
+ ר: "010",
197
+ ש: "000",
198
+ ת: "1"
199
+ },
200
+ 8: {
201
+ ا: "01",
202
+ ب: "1000",
203
+ ت: "1",
204
+ ث: "1010",
205
+ ج: "0111",
206
+ ح: "0000",
207
+ خ: "111",
208
+ د: "100",
209
+ ذ: "1100",
210
+ ر: "010",
211
+ ز: "1110",
212
+ س: "000",
213
+ ش: "1111",
214
+ ص: "1001",
215
+ ض: "0001",
216
+ ط: "001",
217
+ ظ: "1011",
218
+ ع: "0101",
219
+ غ: "110",
220
+ ف: "0010",
221
+ ق: "1101",
222
+ ك: "101",
223
+ ل: "0100",
224
+ م: "11",
225
+ ن: "10",
226
+ ه: "00100",
227
+ و: "011",
228
+ ي: "00",
229
+ ﺀ: "0"
230
+ },
231
+ 9: {
232
+ ا: "01",
233
+ ب: "1000",
234
+ پ: "0110",
235
+ ت: "1",
236
+ ث: "1010",
237
+ ج: "0111",
238
+ چ: "1110",
239
+ ح: "0000",
240
+ خ: "1001",
241
+ د: "100",
242
+ ذ: "0001",
243
+ ر: "010",
244
+ ز: "1100",
245
+ ژ: "110",
246
+ س: "000",
247
+ ش: "1111",
248
+ ص: "0101",
249
+ ض: "00100",
250
+ ط: "001",
251
+ ظ: "1011",
252
+ ع: "111",
253
+ غ: "0011",
254
+ ف: "0010",
255
+ ق: "111000",
256
+ ک: "101",
257
+ گ: "1101",
258
+ ل: "0100",
259
+ م: "11",
260
+ ن: "10",
261
+ و: "011",
262
+ ه: "0",
263
+ ی: "00"
264
+ },
265
+ 10: {
266
+ ア: "11011",
267
+ カ: "0100",
268
+ サ: "10101",
269
+ タ: "10",
270
+ ナ: "010",
271
+ ハ: "1000",
272
+ マ: "1001",
273
+ ヤ: "011",
274
+ ラ: "000",
275
+ ワ: "101",
276
+ イ: "01",
277
+ キ: "10100",
278
+ シ: "11010",
279
+ チ: "0010",
280
+ ニ: "1010",
281
+ ヒ: "11001",
282
+ ミ: "00101",
283
+ リ: "110",
284
+ ヰ: "01001",
285
+ ウ: "001",
286
+ ク: "0001",
287
+ ス: "11101",
288
+ ツ: "0110",
289
+ ヌ: "0000",
290
+ フ: "1100",
291
+ ム: "1",
292
+ ユ: "10011",
293
+ ル: "10110",
294
+ ン: "01010",
295
+ エ: "10111",
296
+ ケ: "1011",
297
+ セ: "01110",
298
+ テ: "01011",
299
+ ネ: "1101",
300
+ ヘ: "0",
301
+ メ: "10001",
302
+ レ: "111",
303
+ ヱ: "01100",
304
+ オ: "01000",
305
+ コ: "1111",
306
+ ソ: "1110",
307
+ ト: "00100",
308
+ ノ: "0011",
309
+ ホ: "100",
310
+ モ: "10010",
311
+ ヨ: "11",
312
+ ロ: "0101",
313
+ ヲ: "0111",
314
+ ゛: "00",
315
+ ゜: "00110",
316
+ "。": "010100",
317
+ ー: "01101",
318
+ "、": "010101",
319
+ "(": "101101",
320
+ ")": "010010"
321
+ },
322
+ 11: {
323
+ ㄱ: "0100",
324
+ ㄴ: "0010",
325
+ ㄷ: "1000",
326
+ ㄹ: "0001",
327
+ ㅁ: "11",
328
+ ㅂ: "011",
329
+ ㅅ: "110",
330
+ ㅇ: "101",
331
+ ㅈ: "0110",
332
+ ㅊ: "1010",
333
+ ㅋ: "1001",
334
+ ㅌ: "1100",
335
+ ㅍ: "111",
336
+ ㅎ: "0111",
337
+ ㅏ: "0",
338
+ ㅑ: "00",
339
+ ㅓ: "1",
340
+ ㅕ: "000",
341
+ ㅗ: "01",
342
+ ㅛ: "10",
343
+ ㅜ: "0000",
344
+ ㅠ: "010",
345
+ ㅡ: "100",
346
+ ㅣ: "001",
347
+ ㅐ: "1101",
348
+ ㅔ: "1011"
349
+ },
350
+ 12: {
351
+ ก: "110",
352
+ ข: "1010",
353
+ ค: "101",
354
+ ง: "10110",
355
+ จ: "10010",
356
+ ฉ: "1111",
357
+ ช: "1001",
358
+ ซ: "1100",
359
+ ญ: "0111",
360
+ ด: "100",
361
+ ต: "1",
362
+ ถ: "10100",
363
+ ท: "10011",
364
+ น: "10",
365
+ บ: "1000",
366
+ ป: "0110",
367
+ ผ: "1101",
368
+ ฝ: "10101",
369
+ พ: "01100",
370
+ ฟ: "0010",
371
+ ม: "11",
372
+ ย: "1011",
373
+ ร: "010",
374
+ ล: "0100",
375
+ ว: "011",
376
+ ส: "000",
377
+ ห: "0000",
378
+ อ: "10001",
379
+ ฮ: "11011",
380
+ ฤ: "01011",
381
+ ะ: "01000",
382
+ า: "01",
383
+ "ิ": "00100",
384
+ "ี": "00",
385
+ "ึ": "00110",
386
+ "ื": "0011",
387
+ "ุ": "00101",
388
+ "ู": "1110",
389
+ เ: "0",
390
+ แ: "0101",
391
+ ไ: "01001",
392
+ โ: "111",
393
+ ำ: "00010",
394
+ "่": "001",
395
+ "้": "0001",
396
+ "๊": "11000",
397
+ "๋": "01010",
398
+ "ั": "01101",
399
+ "็": "11100",
400
+ "์": "11001",
401
+ ๆ: "10111",
402
+ ฯ: "11010"
403
+ }
404
+ }, t = (t) => ({
405
+ ...e,
406
+ 0: e[t.priority],
407
+ 1: {
408
+ ...e[1],
409
+ [t.separator]: t.space
410
+ }
411
+ }), n = (e, n) => {
412
+ let r = {}, i = t(e);
413
+ for (let t in i) {
414
+ r[t] = {};
415
+ let n = i[t];
416
+ if (n) for (let i in n) r[t][i] = n[i].replace(/[01]/g, (t) => t === "0" ? e.dot : e.dash);
417
+ }
418
+ return n || delete r[0], r;
419
+ }, r = (e) => {
420
+ let t = Object.create(null), r = n(e, !0);
421
+ for (let e in r) for (let n in r[e]) {
422
+ let i = r[e][n];
423
+ t[i] === void 0 && (t[i] = n);
424
+ }
425
+ return (t[e.space] === void 0 || t[e.space] === e.separator) && (t[e.space] = " "), t;
426
+ }, i = (e) => typeof e == "number" && Number.isFinite(e) && e > 0, a = (t) => Object.values(e).some((e) => Object.prototype.hasOwnProperty.call(e, t)), o = (e, t, n) => {
427
+ if (e === "") return !1;
428
+ let r = 0;
429
+ for (; r < e.length;) if (e.startsWith(t, r)) r += t.length;
430
+ else if (e.startsWith(n, r)) r += n.length;
431
+ else return !1;
432
+ return !0;
433
+ }, s = (e) => {
434
+ if (e.dot === e.dash) throw Error("morse-code-translator: \"dot\" and \"dash\" symbols must be different.");
435
+ if (e.separator === e.space) throw Error("morse-code-translator: \"separator\" and \"space\" symbols must be different.");
436
+ for (let [t, n] of [["separator", e.separator], ["space", e.space]]) {
437
+ if ([...n].length !== 1) throw Error(`morse-code-translator: "${t}" must be a single character.`);
438
+ if (n === e.dot || n === e.dash) throw Error(`morse-code-translator: "${t}" must differ from the "dot" and "dash" symbols.`);
439
+ if (o(n, e.dot, e.dash)) throw Error(`morse-code-translator: "${t}" must not be composed solely of "dot"/"dash" symbols.`);
440
+ if (t === "space" && /\s/.test(n)) throw Error("morse-code-translator: \"space\" must not be a whitespace character.");
441
+ }
442
+ for (let [t, n] of [["dot", e.dot], ["dash", e.dash]]) if (n.includes(e.space) || n.includes(e.separator)) throw Error(`morse-code-translator: "${t}" must not contain the "space" or "separator" symbol.`);
443
+ if (a(e.separator)) throw Error("morse-code-translator: \"separator\" must not be an encodable character.");
444
+ if (e.invalid !== "" && o(e.invalid, e.dot, e.dash)) throw Error("morse-code-translator: \"invalid\" must not be composed solely of \"dot\"/\"dash\" symbols.");
445
+ for (let [t, n] of [["space", e.space], ["invalid", e.invalid]]) if (/[01]/.test(n)) throw Error(`morse-code-translator: "${t}" must not contain the reserved characters "0" or "1".`);
446
+ }, c = (e = {}) => {
447
+ let t = i(e.unit) ? e.unit : .08, n = i(e.fwUnit) ? e.fwUnit : t, r = i(e.wpm) ? e.wpm : void 0, a = i(e.oscillator?.frequency) ? e.oscillator.frequency : 500, o = typeof e.volume == "number" && Number.isFinite(e.volume) ? e.volume : 100, c = Number.isInteger(e.priority) && e.priority >= 1 && e.priority <= 12 ? e.priority : 1, l = e.oscillator?.type, u = l === "sine" || l === "square" || l === "sawtooth" || l === "triangle" ? l : "sine", d = {
448
+ ...e,
449
+ dash: e.dash || "-",
450
+ dot: e.dot || ".",
451
+ space: e.space || "/",
452
+ separator: e.separator || " ",
453
+ invalid: e.invalid ?? "#",
454
+ priority: c,
455
+ wpm: r,
456
+ unit: t,
457
+ fwUnit: n,
458
+ volume: o,
459
+ oscillator: {
460
+ ...e.oscillator,
461
+ type: u,
462
+ frequency: a,
463
+ onended: e.oscillator?.onended || null
464
+ },
465
+ events: e.events ? { ...e.events } : e.events
466
+ };
467
+ return s(d), d;
468
+ }, l = 44100, u = 1, d = 16, f = 1, p = 3, m = 1, h = 3, g = 7, _ = 50, v = 3600, y = (e, t, n = 0) => {
469
+ let r = [], { unit: i, fwUnit: a } = t, o = 0;
470
+ t.wpm && (i = a = 60 / (t.wpm * _)), r.push([0, o]);
471
+ let s = (e, t, s = !0) => {
472
+ r.push([e, n + o]), o += t * (s ? i : a);
473
+ }, c = (e) => s(t.volume / 100, e), l = (e) => s(0, e), u = (e) => s(0, e, !1), d = t.dot.length >= t.dash.length ? [[t.dot, f], [t.dash, p]] : [[t.dash, p], [t.dot, f]];
474
+ return e.split(t.space).map((e) => e.split(t.separator).filter((e) => e !== "")).filter((e) => e.length > 0).forEach((e, t) => {
475
+ t > 0 && u(g), e.forEach((e, t) => {
476
+ t > 0 && u(h);
477
+ let n = 0, r = !1;
478
+ for (; n < e.length;) {
479
+ let t = d.find(([t]) => t && e.startsWith(t, n));
480
+ t ? (r && l(m), c(t[1]), r = !0, n += t[0].length) : n += 1;
481
+ }
482
+ });
483
+ }), [r, Math.min(o, v)];
484
+ }, b = (e, t) => {
485
+ let n = d / 8, r = u * n, i = e * r, a = t.length * n, o = 44 + a, s = new ArrayBuffer(o), c = new DataView(s), l = (e, t) => {
486
+ for (let n = 0; n < t.length; n++) c.setUint8(e + n, t.charCodeAt(n));
487
+ };
488
+ return l(0, "RIFF"), c.setUint32(4, o - 8, !0), l(8, "WAVE"), l(12, "fmt "), c.setUint32(16, 16, !0), c.setUint16(20, 1, !0), c.setUint16(22, u, !0), c.setUint32(24, e, !0), c.setUint32(28, i, !0), c.setUint16(32, r, !0), c.setUint16(34, d, !0), l(36, "data"), c.setUint32(40, a, !0), ((e, t) => {
489
+ for (let r = 0; r < t.length; r++, e += n) {
490
+ let n = Math.max(-1, Math.min(1, t[r])), i = n < 0 ? n * 32768 : n * 32767;
491
+ c.setInt16(e, i, !0);
492
+ }
493
+ })(44, t), c;
494
+ }, x = (e, t) => {
495
+ let n = window.AudioContext || window.webkitAudioContext, r = window.OfflineAudioContext || window.webkitOfflineAudioContext;
496
+ if (!n || !r) throw Error("Web Audio API is not supported in this browser. Please use a modern browser with Web Audio API support.");
497
+ let [i, a] = y(e, t), o = new r(u, Math.max(1, Math.ceil(l * a)), l), s = o.createOscillator(), c = o.createGain();
498
+ s.type = t.oscillator.type, s.frequency.value = t.oscillator.frequency ?? 500, i.forEach(([e, t]) => {
499
+ c.gain.setValueAtTime(e, t);
500
+ }), s.connect(c), c.connect(o.destination);
501
+ let d = null, f = null, p = null, m = "ready", h = 0, g = 0, _ = null, v = !1, x = 0, S = () => (!d && m !== "disposed" && (d = new n()), d), C = t.events || {};
502
+ t.oscillator.onended && !C.onended && (C.onended = t.oscillator.onended);
503
+ let w = new Promise((e, t) => {
504
+ s.start(0), o.startRendering(), o.oncomplete = (n) => {
505
+ try {
506
+ m !== "disposed" && (p = n.renderedBuffer, C.onready?.()), e();
507
+ } catch (e) {
508
+ t(e);
509
+ }
510
+ }, o.addEventListener("error", (e) => {
511
+ t(e);
512
+ });
513
+ }), T = () => {
514
+ _ !== null && (clearTimeout(_), _ = null);
515
+ }, E = () => {
516
+ if (f) {
517
+ try {
518
+ f.stop(0);
519
+ } catch {}
520
+ f = null;
521
+ }
522
+ }, D = () => {
523
+ let e = S(), t = e.createBufferSource();
524
+ return t.buffer = p, t.connect(e.destination), t;
525
+ }, O = async () => {
526
+ if (m === "playing" || m === "disposed") return;
527
+ let e = ++x;
528
+ v = !0;
529
+ let t = () => x !== e || F() === "disposed";
530
+ try {
531
+ if (await w, t()) return;
532
+ let e = S();
533
+ if (e.state === "suspended" && await e.resume(), t()) return;
534
+ f ||= D(), f.start(e.currentTime, h), g = e.currentTime - h, m = "playing", C.onstarted?.(), T();
535
+ let n = (a - h) * 1e3;
536
+ _ = window.setTimeout(() => {
537
+ m === "playing" && (T(), E(), m = "stopped", h = 0, g = 0, C.onended?.());
538
+ }, n);
539
+ } finally {
540
+ x === e && (v = !1);
541
+ }
542
+ }, k = () => {
543
+ if (m !== "disposed") {
544
+ if (m === "playing") {
545
+ T(), h = Math.min(S().currentTime - g, a), E(), m = "paused", C.onpaused?.();
546
+ return;
547
+ }
548
+ v && (x++, v = !1, T(), E(), m = "paused", C.onpaused?.());
549
+ }
550
+ }, A = (e = !1) => {
551
+ if (m === "disposed") return;
552
+ x++, T(), E();
553
+ let t = m === "playing" || v;
554
+ v = !1, m = "stopped", h = 0, g = 0, t && C.onstopped?.(), e && (p = null);
555
+ }, j = async (e) => {
556
+ if (m === "disposed") return;
557
+ let t = m === "playing" || v, n = Math.max(0, Math.min(Number.isNaN(e) ? 0 : e, a));
558
+ x++, T(), E(), h = n, C.onseeked?.(n), t && (m = "paused", await O());
559
+ }, M = () => {
560
+ A(!0), m = "disposed", d && d.state !== "closed" && d.close();
561
+ }, N = () => m === "playing" ? Math.min(S().currentTime - g, a) : h, P = () => a, F = () => m, I = async () => {
562
+ if (await w, !p) throw Error("Audio buffer not available");
563
+ let e = b(o.sampleRate, p.getChannelData(0)), t = new Uint8Array(e.byteLength);
564
+ for (let n = 0; n < e.byteLength; n++) t[n] = e.getUint8(n);
565
+ return new Blob([t], { type: "audio/wav" });
566
+ }, L = async () => {
567
+ let e = await I();
568
+ return URL.createObjectURL(e);
569
+ }, R = {
570
+ play: O,
571
+ pause: k,
572
+ stop: A,
573
+ seek: j,
574
+ dispose: M,
575
+ getCurrentTime: N,
576
+ getTotalTime: P,
577
+ getState: F,
578
+ getWaveBlob: I,
579
+ getWaveUrl: L,
580
+ exportWave: async (e = "morse.wav") => {
581
+ let t = await L(), n = document.createElement("a");
582
+ n.href = t, n.target = "_blank", n.download = e, n.click(), setTimeout(() => URL.revokeObjectURL(t), 1e3);
583
+ },
584
+ oscillator: s,
585
+ gainNode: c
586
+ };
587
+ return Object.defineProperty(R, "context", {
588
+ get: S,
589
+ enumerable: !1,
590
+ configurable: !0
591
+ }), R;
592
+ }, S = /[゠-ヿ]/, C = /[ヽヾ]/, w = (e) => [...e.normalize("NFC")].map((e) => S.test(e) && !C.test(e) ? e.normalize("NFD").replace(/゙/g, "゛").replace(/゚/g, "゜") : e).join(""), T = (e, n) => {
593
+ let r = c(n), i = t(r), a = [...w(e.trim().replace(/\s+/g, r.separator).toUpperCase())].map((e) => {
594
+ for (let t in i) {
595
+ let n = i[t];
596
+ if (n && n[e]) return n[e];
597
+ }
598
+ return r.invalid;
599
+ }).map((e) => e.replace(/[01]/g, (e) => e === "0" ? r.dot : r.dash)).filter((e) => e !== "");
600
+ return r.invalid === "" && (a = a.filter((e, t) => e !== r.space || a[t - 1] !== void 0 && a[t - 1] !== r.space && a[t + 1] !== void 0 && a[t + 1] !== r.space)), a.join(r.separator);
601
+ }, E = (e, t) => {
602
+ let n = c(t), i = r(n), a = e.trim().replace(/\s+/g, n.separator);
603
+ return a === "" ? "" : a.split(n.separator).map((e) => Object.prototype.hasOwnProperty.call(i, e) ? i[e] : n.invalid).join("");
604
+ }, D = (e, t = !1) => n(c(e), t), O = (e, t, n) => {
605
+ let r = c(t);
606
+ return x(n || T(e, t), r);
607
+ }, k = {
608
+ encode: T,
609
+ decode: E,
610
+ characters: D,
611
+ audio: O
601
612
  };
602
- export {
603
- e0 as audio,
604
- Z as characters,
605
- Y as decode,
606
- n0 as default,
607
- B as encode
608
- };
609
- //# sourceMappingURL=morse-code-translator.es.js.map
613
+ //#endregion
614
+ export { O as audio, D as characters, E as decode, k as default, T as encode };
615
+
616
+ //# sourceMappingURL=morse-code-translator.es.js.map