@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.
- package/LICENSE +1 -1
- package/README.md +111 -8
- package/dist/index.d.ts +10 -11
- package/dist/morse-code-translator.es.js +881 -607
- package/dist/morse-code-translator.es.js.map +1 -1
- package/dist/morse-code-translator.umd.js +2 -2
- package/dist/morse-code-translator.umd.js.map +1 -1
- package/dist/types.d.ts +25 -22
- package/package.json +42 -28
- package/dist/audio.d.ts +0 -4
- package/dist/audio.d.ts.map +0 -1
- package/dist/characters.d.ts +0 -11
- 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
|
@@ -1,609 +1,883 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
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
|
-
//#
|
|
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
|