@ozdemirburak/morse-code-translator 7.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.
- package/LICENSE +1 -1
- package/README.md +110 -7
- package/dist/index.d.ts +10 -11
- package/dist/morse-code-translator.es.js +448 -181
- package/dist/morse-code-translator.es.js.map +1 -1
- package/dist/morse-code-translator.umd.js +1 -1
- package/dist/morse-code-translator.umd.js.map +1 -1
- package/dist/types.d.ts +24 -22
- package/package.json +42 -29
- package/dist/audio.d.ts +0 -4
- package/dist/audio.d.ts.map +0 -1
- package/dist/characters.d.ts +0 -12
- package/dist/characters.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/options.d.ts +0 -4
- package/dist/options.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
|
@@ -77,9 +77,9 @@ var e = {
|
|
|
77
77
|
Č: "110",
|
|
78
78
|
Ð: "00110",
|
|
79
79
|
È: "01001",
|
|
80
|
+
É: "00100",
|
|
80
81
|
Ę: "00100",
|
|
81
82
|
Ë: "00100",
|
|
82
|
-
É: "00100",
|
|
83
83
|
Ê: "10010",
|
|
84
84
|
Ğ: "11010",
|
|
85
85
|
Ĝ: "11010",
|
|
@@ -145,7 +145,8 @@ var e = {
|
|
|
145
145
|
Ї: "01110",
|
|
146
146
|
Є: "00100",
|
|
147
147
|
І: "00",
|
|
148
|
-
Ґ: "110"
|
|
148
|
+
Ґ: "110",
|
|
149
|
+
Ё: "0"
|
|
149
150
|
},
|
|
150
151
|
6: {
|
|
151
152
|
Α: "01",
|
|
@@ -195,7 +196,12 @@ var e = {
|
|
|
195
196
|
ק: "1101",
|
|
196
197
|
ר: "010",
|
|
197
198
|
ש: "000",
|
|
198
|
-
ת: "1"
|
|
199
|
+
ת: "1",
|
|
200
|
+
ך: "101",
|
|
201
|
+
ם: "11",
|
|
202
|
+
ן: "10",
|
|
203
|
+
ף: "0110",
|
|
204
|
+
ץ: "011"
|
|
199
205
|
},
|
|
200
206
|
8: {
|
|
201
207
|
ا: "01",
|
|
@@ -226,6 +232,7 @@ var e = {
|
|
|
226
232
|
ه: "00100",
|
|
227
233
|
و: "011",
|
|
228
234
|
ي: "00",
|
|
235
|
+
ء: "0",
|
|
229
236
|
ﺀ: "0"
|
|
230
237
|
},
|
|
231
238
|
9: {
|
|
@@ -399,218 +406,478 @@ var e = {
|
|
|
399
406
|
"็": "11100",
|
|
400
407
|
"์": "11001",
|
|
401
408
|
ๆ: "10111",
|
|
402
|
-
ฯ: "11010"
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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"
|
|
417
426
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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);
|
|
424
442
|
}
|
|
425
|
-
|
|
426
|
-
|
|
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) => {
|
|
427
468
|
if (e === "") return !1;
|
|
428
469
|
let r = 0;
|
|
429
470
|
for (; r < e.length;) if (e.startsWith(t, r)) r += t.length;
|
|
430
471
|
else if (e.startsWith(n, r)) r += n.length;
|
|
431
472
|
else return !1;
|
|
432
473
|
return !0;
|
|
433
|
-
}
|
|
474
|
+
};
|
|
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) => {
|
|
434
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.");
|
|
435
487
|
if (e.separator === e.space) throw Error("morse-code-translator: \"separator\" and \"space\" symbols must be different.");
|
|
436
488
|
for (let [t, n] of [["separator", e.separator], ["space", e.space]]) {
|
|
437
489
|
if ([...n].length !== 1) throw Error(`morse-code-translator: "${t}" must be a single character.`);
|
|
438
490
|
if (n === e.dot || n === e.dash) throw Error(`morse-code-translator: "${t}" must differ from the "dot" and "dash" symbols.`);
|
|
439
|
-
if (
|
|
491
|
+
if (f(n, e.dot, e.dash)) throw Error(`morse-code-translator: "${t}" must not be composed solely of "dot"/"dash" symbols.`);
|
|
440
492
|
if (t === "space" && /\s/.test(n)) throw Error("morse-code-translator: \"space\" must not be a whitespace character.");
|
|
441
493
|
}
|
|
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"
|
|
443
|
-
if (
|
|
444
|
-
if (e.invalid !== ""
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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,
|
|
459
513
|
oscillator: {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
frequency: a,
|
|
463
|
-
onended: e.oscillator?.onended || null
|
|
514
|
+
type: f,
|
|
515
|
+
frequency: o
|
|
464
516
|
},
|
|
465
|
-
events:
|
|
517
|
+
events: t.events ? { ...t.events } : t.events
|
|
466
518
|
};
|
|
467
|
-
return
|
|
468
|
-
},
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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
|
|
487
547
|
};
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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;
|
|
492
557
|
}
|
|
493
|
-
|
|
494
|
-
},
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
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;
|
|
509
618
|
}
|
|
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
619
|
}
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
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) => {
|
|
530
646
|
try {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
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;
|
|
541
692
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
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;
|
|
547
733
|
}
|
|
548
|
-
|
|
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();
|
|
549
757
|
}
|
|
550
|
-
},
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
let
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
let e = await I();
|
|
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();
|
|
568
775
|
return URL.createObjectURL(e);
|
|
569
|
-
},
|
|
570
|
-
play:
|
|
571
|
-
pause:
|
|
572
|
-
stop:
|
|
573
|
-
seek:
|
|
574
|
-
dispose:
|
|
575
|
-
getCurrentTime:
|
|
576
|
-
getTotalTime:
|
|
577
|
-
getState:
|
|
578
|
-
getWaveBlob:
|
|
579
|
-
getWaveUrl:
|
|
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,
|
|
580
787
|
exportWave: async (e = "morse.wav") => {
|
|
581
|
-
let t = await
|
|
788
|
+
let t = await X(), n = document.createElement("a");
|
|
582
789
|
n.href = t, n.target = "_blank", n.download = e, n.click(), setTimeout(() => URL.revokeObjectURL(t), 1e3);
|
|
583
|
-
}
|
|
584
|
-
oscillator: s,
|
|
585
|
-
gainNode: c
|
|
790
|
+
}
|
|
586
791
|
};
|
|
587
|
-
return Object.defineProperty(
|
|
588
|
-
get:
|
|
792
|
+
return Object.defineProperty(Z, "context", {
|
|
793
|
+
get: T,
|
|
589
794
|
enumerable: !1,
|
|
590
795
|
configurable: !0
|
|
591
|
-
}),
|
|
592
|
-
},
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
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);
|
|
597
864
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
let n =
|
|
603
|
-
return
|
|
604
|
-
},
|
|
605
|
-
let r =
|
|
606
|
-
return
|
|
607
|
-
},
|
|
608
|
-
encode:
|
|
609
|
-
decode:
|
|
610
|
-
characters:
|
|
611
|
-
audio:
|
|
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
|
|
612
879
|
};
|
|
613
880
|
//#endregion
|
|
614
|
-
export {
|
|
881
|
+
export { Te as audio, we as characters, Ce as decode, Ee as default, $ as encode };
|
|
615
882
|
|
|
616
883
|
//# sourceMappingURL=morse-code-translator.es.js.map
|