@ozdemirburak/morse-code-translator 5.0.3 → 6.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.
@@ -0,0 +1,609 @@
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
601
+ };
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