@prolibu-suite/cobalt-core 0.11.3 → 0.11.5
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/custom-elements.json +31 -31
- package/dist/cjs/co-audio-player.cjs.entry.js +198 -46
- package/dist/cjs/co-number-field.cjs.entry.js +12 -4
- package/dist/cjs/index-bHoidDwv.js +4 -4
- package/dist/cobalt/cobalt.esm.js +1 -1
- package/dist/cobalt/p-4a7fd0b4.entry.js +1 -0
- package/dist/cobalt/p-7c20207b.entry.js +1 -0
- package/dist/collection/components/co-audio-player/co-audio-player.js +40 -47
- package/dist/collection/components/co-audio-player/co-audio-player.peaks-cache.js +104 -0
- package/dist/collection/components/co-audio-player/co-audio-player.utils.js +61 -0
- package/dist/collection/components/co-autocomplete/co-autocomplete.js +1 -1
- package/dist/collection/components/co-avatar-group/co-avatar-group.js +1 -1
- package/dist/collection/components/co-checkbox-group/co-checkbox-group.js +1 -1
- package/dist/collection/components/co-color-area/co-color-area.js +2 -2
- package/dist/collection/components/co-color-slider/co-color-slider.js +1 -1
- package/dist/collection/components/co-combobox/co-combobox.js +1 -1
- package/dist/collection/components/co-command-search/co-command-search.js +1 -1
- package/dist/collection/components/co-data-table/co-data-table.js +1 -1
- package/dist/collection/components/co-date-range-picker/co-date-range-picker.js +2 -2
- package/dist/collection/components/co-document-editor/co-document-editor.js +5 -5
- package/dist/collection/components/co-number-field/co-number-field.js +12 -4
- package/dist/collection/components/co-popover/co-popover.js +1 -1
- package/dist/collection/components/co-radio-group/co-radio-group.js +1 -1
- package/dist/collection/components/co-ref-field/co-ref-field.js +4 -4
- package/dist/collection/components/co-segmented-bar/co-segmented-bar.js +1 -1
- package/dist/collection/components/co-select/co-select.js +1 -1
- package/dist/collection/components/co-sidebar-nav/co-sidebar-nav.js +1 -1
- package/dist/collection/components/co-toast/co-toast.js +2 -2
- package/dist/collection/components/co-transfer-list/co-transfer-list.js +1 -1
- package/dist/collection/components/co-tree-item/co-tree-item.js +2 -2
- package/dist/components/co-audio-player.js +1 -1
- package/dist/components/co-number-field.js +1 -1
- package/dist/esm/co-audio-player.entry.js +198 -46
- package/dist/esm/co-number-field.entry.js +12 -4
- package/dist/esm/index-DJkaRtbb.js +4 -4
- package/dist/types/components/co-audio-player/co-audio-player.d.ts +8 -1
- package/dist/types/components/co-audio-player/co-audio-player.peaks-cache.d.ts +58 -0
- package/dist/types/components/co-audio-player/co-audio-player.utils.d.ts +33 -0
- package/package.json +4 -4
- package/dist/cobalt/p-358a6c2a.entry.js +0 -1
- package/dist/cobalt/p-ae999b94.entry.js +0 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { buildPeakEnvelope, resamplePeaks } from "./co-audio-player.utils";
|
|
2
|
+
/** Tope de entradas. Cada una pesa ≤ 256 KB (`PEAK_ENVELOPE_BINS` Float32) más unas
|
|
3
|
+
* pocas listas de barras exactas, así que el caché lleno queda en ~4 MB. Una
|
|
4
|
+
* instancia montada conserva SU envolvente aunque la entrada se desaloje (es la
|
|
5
|
+
* misma referencia, no una copia). */
|
|
6
|
+
export const PEAKS_CACHE_MAX = 16;
|
|
7
|
+
// Map conserva el orden de inserción: la primera clave es la menos usada (LRU).
|
|
8
|
+
const cache = new Map();
|
|
9
|
+
const inflight = new Map();
|
|
10
|
+
function remember(url, value) {
|
|
11
|
+
cache.delete(url);
|
|
12
|
+
cache.set(url, value);
|
|
13
|
+
while (cache.size > PEAKS_CACHE_MAX)
|
|
14
|
+
cache.delete(cache.keys().next().value);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Picos + duración de `url`: del caché si están, uniéndose a la carga en vuelo si
|
|
18
|
+
* otra instancia ya la pidió, o cargándolos. Solo se cachea un resultado real: un
|
|
19
|
+
* error (CORS, red, códec) o un `null` se devuelven tal cual y el próximo pedido
|
|
20
|
+
* reintenta.
|
|
21
|
+
*/
|
|
22
|
+
export function loadAudioPeaks(url, wantBars, loader = decodeAudioPeaks) {
|
|
23
|
+
const hit = cache.get(url);
|
|
24
|
+
if (hit) {
|
|
25
|
+
remember(url, hit); // refresca su posición LRU
|
|
26
|
+
return Promise.resolve(hit);
|
|
27
|
+
}
|
|
28
|
+
const pending = inflight.get(url);
|
|
29
|
+
if (pending) {
|
|
30
|
+
if (wantBars)
|
|
31
|
+
pending.wanted.add(wantBars);
|
|
32
|
+
return pending.promise;
|
|
33
|
+
}
|
|
34
|
+
const wanted = new Set(wantBars ? [wantBars] : []);
|
|
35
|
+
const p = loader(url, wanted).then((res) => {
|
|
36
|
+
inflight.delete(url);
|
|
37
|
+
if (res)
|
|
38
|
+
remember(url, res);
|
|
39
|
+
return res;
|
|
40
|
+
}, (err) => {
|
|
41
|
+
inflight.delete(url);
|
|
42
|
+
throw err;
|
|
43
|
+
});
|
|
44
|
+
inflight.set(url, { promise: p, wanted });
|
|
45
|
+
return p;
|
|
46
|
+
}
|
|
47
|
+
/** Vacía el caché (tests; y un host que necesite liberar memoria a mano). */
|
|
48
|
+
export function clearAudioPeaksCache() {
|
|
49
|
+
cache.clear();
|
|
50
|
+
inflight.clear();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Descarga + decode con Web Audio, reducido a la envolvente. El `AudioBuffer`
|
|
54
|
+
* (y con él el PCM completo) no sale de esta función: queda sin referencias
|
|
55
|
+
* apenas se calcula la envolvente.
|
|
56
|
+
*/
|
|
57
|
+
export async function decodeAudioPeaks(url, wanted = new Set()) {
|
|
58
|
+
var _a;
|
|
59
|
+
let ctx;
|
|
60
|
+
try {
|
|
61
|
+
/**
|
|
62
|
+
* `OfflineAudioContext` FIRST, and a live `AudioContext` only as the
|
|
63
|
+
* fallback: decoding a waveform needs no audio OUTPUT, and a live context
|
|
64
|
+
* created before the user has interacted trips the browser's autoplay
|
|
65
|
+
* policy — "The AudioContext was not allowed to start. It must be resumed
|
|
66
|
+
* (or created) after a user gesture on the page", once per player. A page
|
|
67
|
+
* with 15 recordings logged it 15 times. The offline one has no output
|
|
68
|
+
* device, so the policy does not apply to it.
|
|
69
|
+
*
|
|
70
|
+
* Its arguments are placeholders: nothing is ever rendered through this
|
|
71
|
+
* context, it is only the host for `decodeAudioData`.
|
|
72
|
+
*/
|
|
73
|
+
const OfflineCtx = window.OfflineAudioContext || window.webkitOfflineAudioContext;
|
|
74
|
+
const Ctx = window.AudioContext || window.webkitAudioContext;
|
|
75
|
+
if ((!OfflineCtx && !Ctx) || typeof fetch === 'undefined')
|
|
76
|
+
return null;
|
|
77
|
+
ctx = OfflineCtx ? new OfflineCtx(1, 1, 44100) : new Ctx();
|
|
78
|
+
const buf = await (await fetch(url)).arrayBuffer();
|
|
79
|
+
const audioBuf = await ctx.decodeAudioData(buf);
|
|
80
|
+
const pcm = audioBuf.getChannelData(0);
|
|
81
|
+
return { envelope: buildPeakEnvelope(pcm), exact: exactBarsFor(pcm, wanted), duration: audioBuf.duration };
|
|
82
|
+
}
|
|
83
|
+
finally {
|
|
84
|
+
// Always release the context. Chrome caps concurrent AudioContexts per
|
|
85
|
+
// document, so leaking one per failed decode would eventually stop every
|
|
86
|
+
// later player on the page from decoding at all. `close()` lives on
|
|
87
|
+
// AudioContext, not on every BaseAudioContext (an OfflineAudioContext
|
|
88
|
+
// needs no closing and may not implement it): optional call, not a cast.
|
|
89
|
+
try {
|
|
90
|
+
await ((_a = ctx === null || ctx === void 0 ? void 0 : ctx.close) === null || _a === void 0 ? void 0 : _a.call(ctx));
|
|
91
|
+
}
|
|
92
|
+
catch ( /* already closed */_b) { /* already closed */ }
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
/** Barras exactas para cada ancho que las instancias en espera quieren ahora mismo. */
|
|
96
|
+
export function exactBarsFor(pcm, wanted) {
|
|
97
|
+
const exact = new Map();
|
|
98
|
+
for (const want of wanted) {
|
|
99
|
+
const bars = want();
|
|
100
|
+
if (bars > 0 && !exact.has(bars))
|
|
101
|
+
exact.set(bars, resamplePeaks(pcm, bars));
|
|
102
|
+
}
|
|
103
|
+
return exact;
|
|
104
|
+
}
|
|
@@ -49,6 +49,67 @@ export function resamplePeaks(channelData, bars) {
|
|
|
49
49
|
}
|
|
50
50
|
return peaks;
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolución de la envolvente que se retiene por grabación, en bloques.
|
|
54
|
+
*
|
|
55
|
+
* Las barras EXACTAS del ancho vigente se calculan del PCM antes de soltarlo (ver
|
|
56
|
+
* `co-audio-player.peaks-cache`); la envolvente solo sirve los anchos que aparecen
|
|
57
|
+
* DESPUÉS (resize, o una segunda instancia que llega con el caché ya caliente). El
|
|
58
|
+
* reproductor deriva las barras del ancho (`floor(ancho / barDensity)`, ~853 a
|
|
59
|
+
* 2560 px), así que la envolvente tiene que ir muy por encima de eso: 65 536 bloques
|
|
60
|
+
* = ≥ 76 bloques por barra hasta 2560 px, y pesan 256 KB (Float32) frente a ~32 MB
|
|
61
|
+
* del PCM de 3 min a 44,1 kHz. Medido contra el exacto con PCM sintético de 3 min:
|
|
62
|
+
* desvío máx. ≈ 1 px de 40 en las barras que difieren (≈ 0,8 px con ruido blanco).
|
|
63
|
+
*/
|
|
64
|
+
export const PEAK_ENVELOPE_BINS = 65536;
|
|
65
|
+
/** PCM → envolvente de a lo sumo `maxBins` bloques. Con `length ≤ maxBins` el bloque
|
|
66
|
+
* es de 1 muestra y la envolvente ES |PCM| (sin pérdida). */
|
|
67
|
+
export function buildPeakEnvelope(channelData, maxBins = PEAK_ENVELOPE_BINS) {
|
|
68
|
+
const length = channelData.length;
|
|
69
|
+
const blockSize = Math.max(1, Math.ceil(length / Math.max(1, maxBins)));
|
|
70
|
+
const bins = Math.ceil(length / blockSize);
|
|
71
|
+
const peaks = new Float32Array(bins);
|
|
72
|
+
for (let b = 0; b < bins; b++) {
|
|
73
|
+
let max = 0;
|
|
74
|
+
const end = Math.min(length, (b + 1) * blockSize);
|
|
75
|
+
for (let j = b * blockSize; j < end; j++) {
|
|
76
|
+
const abs = Math.abs(channelData[j]);
|
|
77
|
+
if (abs > max)
|
|
78
|
+
max = abs;
|
|
79
|
+
}
|
|
80
|
+
peaks[b] = max;
|
|
81
|
+
}
|
|
82
|
+
return { peaks, blockSize, length };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Las mismas barras que `resamplePeaks(pcm, bars)`, calculadas desde la envolvente:
|
|
86
|
+
* mismo paso (`floor(length / bars)` muestras), mismo recorte de la cola y misma
|
|
87
|
+
* fórmula de altura. Cada barra toma el máximo de los bloques que TOCA su rango de
|
|
88
|
+
* muestras, así que el resultado es IDÉNTICO cuando `blockSize` es 1 o divide el
|
|
89
|
+
* paso, y en el caso general solo puede sumar el pico de un bloque parcial en cada
|
|
90
|
+
* borde (nunca queda por debajo del exacto).
|
|
91
|
+
*/
|
|
92
|
+
export function resampleEnvelope(env, bars) {
|
|
93
|
+
const { peaks: blocks, blockSize, length: len } = env;
|
|
94
|
+
if (!len || bars <= 0)
|
|
95
|
+
return [];
|
|
96
|
+
const step = Math.max(1, Math.floor(len / bars));
|
|
97
|
+
const peaks = [];
|
|
98
|
+
for (let i = 0; i < bars; i++) {
|
|
99
|
+
const start = i * step;
|
|
100
|
+
const end = Math.min(start + step, len); // exclusivo, como el bucle de resamplePeaks
|
|
101
|
+
let max = 0;
|
|
102
|
+
if (start < end) {
|
|
103
|
+
const last = Math.floor((end - 1) / blockSize);
|
|
104
|
+
for (let b = Math.floor(start / blockSize); b <= last; b++) {
|
|
105
|
+
if (blocks[b] > max)
|
|
106
|
+
max = blocks[b];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
peaks.push(0.12 + max * 0.88);
|
|
110
|
+
}
|
|
111
|
+
return peaks;
|
|
112
|
+
}
|
|
52
113
|
/** Deterministic pseudo-waveform (stable render + testable — no Math.random). */
|
|
53
114
|
export function fallbackPeaks(bars) {
|
|
54
115
|
if (bars <= 0)
|
|
@@ -431,7 +431,7 @@ export class CoAutocomplete {
|
|
|
431
431
|
"references": {
|
|
432
432
|
"AutocompleteOption": {
|
|
433
433
|
"location": "local",
|
|
434
|
-
"path": "/Users/agox/
|
|
434
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-autocomplete/co-autocomplete.tsx",
|
|
435
435
|
"id": "src/components/co-autocomplete/co-autocomplete.tsx::AutocompleteOption"
|
|
436
436
|
}
|
|
437
437
|
}
|
|
@@ -92,7 +92,7 @@ export class CoAvatarGroup {
|
|
|
92
92
|
"references": {
|
|
93
93
|
"CoAvatarGroupItem": {
|
|
94
94
|
"location": "local",
|
|
95
|
-
"path": "/Users/agox/
|
|
95
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-avatar-group/co-avatar-group.tsx",
|
|
96
96
|
"id": "src/components/co-avatar-group/co-avatar-group.tsx::CoAvatarGroupItem"
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -236,7 +236,7 @@ export class CoCheckboxGroup {
|
|
|
236
236
|
"references": {
|
|
237
237
|
"CheckboxOption": {
|
|
238
238
|
"location": "local",
|
|
239
|
-
"path": "/Users/agox/
|
|
239
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-checkbox-group/co-checkbox-group.tsx",
|
|
240
240
|
"id": "src/components/co-checkbox-group/co-checkbox-group.tsx::CheckboxOption"
|
|
241
241
|
}
|
|
242
242
|
}
|
|
@@ -310,7 +310,7 @@ export class CoColorArea {
|
|
|
310
310
|
"references": {
|
|
311
311
|
"ColorAreaDetail": {
|
|
312
312
|
"location": "local",
|
|
313
|
-
"path": "/Users/agox/
|
|
313
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-color-area/co-color-area.tsx",
|
|
314
314
|
"id": "src/components/co-color-area/co-color-area.tsx::ColorAreaDetail"
|
|
315
315
|
}
|
|
316
316
|
}
|
|
@@ -331,7 +331,7 @@ export class CoColorArea {
|
|
|
331
331
|
"references": {
|
|
332
332
|
"ColorAreaDetail": {
|
|
333
333
|
"location": "local",
|
|
334
|
-
"path": "/Users/agox/
|
|
334
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-color-area/co-color-area.tsx",
|
|
335
335
|
"id": "src/components/co-color-area/co-color-area.tsx::ColorAreaDetail"
|
|
336
336
|
}
|
|
337
337
|
}
|
|
@@ -215,7 +215,7 @@ export class CoColorSlider {
|
|
|
215
215
|
"references": {
|
|
216
216
|
"ColorSliderChannel": {
|
|
217
217
|
"location": "local",
|
|
218
|
-
"path": "/Users/agox/
|
|
218
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-color-slider/co-color-slider.tsx",
|
|
219
219
|
"id": "src/components/co-color-slider/co-color-slider.tsx::ColorSliderChannel"
|
|
220
220
|
}
|
|
221
221
|
}
|
|
@@ -545,7 +545,7 @@ export class CoCombobox {
|
|
|
545
545
|
"references": {
|
|
546
546
|
"ComboboxOption": {
|
|
547
547
|
"location": "local",
|
|
548
|
-
"path": "/Users/agox/
|
|
548
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-combobox/co-combobox.tsx",
|
|
549
549
|
"id": "src/components/co-combobox/co-combobox.tsx::ComboboxOption"
|
|
550
550
|
}
|
|
551
551
|
}
|
|
@@ -257,7 +257,7 @@ export class CoCommandSearch {
|
|
|
257
257
|
"references": {
|
|
258
258
|
"CommandItem": {
|
|
259
259
|
"location": "local",
|
|
260
|
-
"path": "/Users/agox/
|
|
260
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-command-search/co-command-search.tsx",
|
|
261
261
|
"id": "src/components/co-command-search/co-command-search.tsx::CommandItem"
|
|
262
262
|
}
|
|
263
263
|
}
|
|
@@ -509,7 +509,7 @@ export class CoDataTable {
|
|
|
509
509
|
"references": {
|
|
510
510
|
"CoDataTableColumn": {
|
|
511
511
|
"location": "local",
|
|
512
|
-
"path": "/Users/agox/
|
|
512
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-data-table/co-data-table.tsx",
|
|
513
513
|
"id": "src/components/co-data-table/co-data-table.tsx::CoDataTableColumn"
|
|
514
514
|
}
|
|
515
515
|
}
|
|
@@ -1055,7 +1055,7 @@ export class CoDateRangePicker {
|
|
|
1055
1055
|
"references": {
|
|
1056
1056
|
"DateRangeValue": {
|
|
1057
1057
|
"location": "local",
|
|
1058
|
-
"path": "/Users/agox/
|
|
1058
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-date-range-picker/co-date-range-picker.tsx",
|
|
1059
1059
|
"id": "src/components/co-date-range-picker/co-date-range-picker.tsx::DateRangeValue"
|
|
1060
1060
|
}
|
|
1061
1061
|
}
|
|
@@ -1076,7 +1076,7 @@ export class CoDateRangePicker {
|
|
|
1076
1076
|
"references": {
|
|
1077
1077
|
"DateRangeValue": {
|
|
1078
1078
|
"location": "local",
|
|
1079
|
-
"path": "/Users/agox/
|
|
1079
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-date-range-picker/co-date-range-picker.tsx",
|
|
1080
1080
|
"id": "src/components/co-date-range-picker/co-date-range-picker.tsx::DateRangeValue"
|
|
1081
1081
|
}
|
|
1082
1082
|
}
|
|
@@ -936,7 +936,7 @@ export class CoDocumentEditor {
|
|
|
936
936
|
"references": {
|
|
937
937
|
"DocumentPageSize": {
|
|
938
938
|
"location": "local",
|
|
939
|
-
"path": "/Users/agox/
|
|
939
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-document-editor/co-document-editor.tsx",
|
|
940
940
|
"id": "src/components/co-document-editor/co-document-editor.tsx::DocumentPageSize"
|
|
941
941
|
}
|
|
942
942
|
}
|
|
@@ -962,7 +962,7 @@ export class CoDocumentEditor {
|
|
|
962
962
|
"references": {
|
|
963
963
|
"DocumentMargins": {
|
|
964
964
|
"location": "local",
|
|
965
|
-
"path": "/Users/agox/
|
|
965
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-document-editor/co-document-editor.tsx",
|
|
966
966
|
"id": "src/components/co-document-editor/co-document-editor.tsx::DocumentMargins"
|
|
967
967
|
}
|
|
968
968
|
}
|
|
@@ -1027,7 +1027,7 @@ export class CoDocumentEditor {
|
|
|
1027
1027
|
"references": {
|
|
1028
1028
|
"DocumentFeatures": {
|
|
1029
1029
|
"location": "local",
|
|
1030
|
-
"path": "/Users/agox/
|
|
1030
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-document-editor/co-document-editor.tsx",
|
|
1031
1031
|
"id": "src/components/co-document-editor/co-document-editor.tsx::DocumentFeatures"
|
|
1032
1032
|
}
|
|
1033
1033
|
}
|
|
@@ -1220,7 +1220,7 @@ export class CoDocumentEditor {
|
|
|
1220
1220
|
"references": {
|
|
1221
1221
|
"DocumentHeaderDetail": {
|
|
1222
1222
|
"location": "local",
|
|
1223
|
-
"path": "/Users/agox/
|
|
1223
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-document-editor/co-document-editor.tsx",
|
|
1224
1224
|
"id": "src/components/co-document-editor/co-document-editor.tsx::DocumentHeaderDetail"
|
|
1225
1225
|
}
|
|
1226
1226
|
}
|
|
@@ -1256,7 +1256,7 @@ export class CoDocumentEditor {
|
|
|
1256
1256
|
"references": {
|
|
1257
1257
|
"DocumentActionDetail": {
|
|
1258
1258
|
"location": "local",
|
|
1259
|
-
"path": "/Users/agox/
|
|
1259
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-document-editor/co-document-editor.tsx",
|
|
1260
1260
|
"id": "src/components/co-document-editor/co-document-editor.tsx::DocumentActionDetail"
|
|
1261
1261
|
}
|
|
1262
1262
|
}
|
|
@@ -10,6 +10,11 @@ import { formatAmountText, parseNumericText, stripAmountText } from "../../utils
|
|
|
10
10
|
* blur—, solo impide que el campo muestre algo que no es un número.
|
|
11
11
|
*/
|
|
12
12
|
const NON_NUMERIC = /[^0-9.,-]/g;
|
|
13
|
+
/** «12,5» → «12.5»; con dos comas o con punto no se adivina (queda igual). */
|
|
14
|
+
function decimalCommaToDot(raw) {
|
|
15
|
+
const commas = raw.split(',').length - 1;
|
|
16
|
+
return commas === 1 && !raw.includes('.') ? raw.replace(',', '.') : raw;
|
|
17
|
+
}
|
|
13
18
|
/** Caracteres que CUENTAN para el caret en modo amount (la coma es decorado). */
|
|
14
19
|
const SIGNIFICANT = /[0-9.-]/;
|
|
15
20
|
const countSignificant = (text) => {
|
|
@@ -122,7 +127,10 @@ export class CoNumberField {
|
|
|
122
127
|
}
|
|
123
128
|
if (raw === '-')
|
|
124
129
|
return;
|
|
125
|
-
|
|
130
|
+
// Una coma sola y sin punto es el separador decimal (es/pt: «12,5»): parseFloat
|
|
131
|
+
// cortaría en ella y commitearía 12. Solo se normaliza lo que se parsea — el
|
|
132
|
+
// texto del campo queda como lo tipeó el usuario (y el caret en su lugar).
|
|
133
|
+
const num = parseFloat(decimalCommaToDot(raw));
|
|
126
134
|
if (!isNaN(num)) {
|
|
127
135
|
this.emitValue(this.fromDisplay(num));
|
|
128
136
|
}
|
|
@@ -337,18 +345,18 @@ export class CoNumberField {
|
|
|
337
345
|
return this.scaled && !this.isEmpty ? '%' : null;
|
|
338
346
|
}
|
|
339
347
|
render() {
|
|
340
|
-
return (h("div", { key: '
|
|
348
|
+
return (h("div", { key: '87d77047c35e2f0b3b9a978839e5b3c99541dc2e', class: {
|
|
341
349
|
'co-number-field': true,
|
|
342
350
|
'co-number-field--disabled': this.disabled,
|
|
343
351
|
'co-number-field--focused': this.focused,
|
|
344
352
|
[`co-number-field--${this.size}`]: true,
|
|
345
353
|
[`co-number-field--${this.status}`]: this.status !== 'default',
|
|
346
|
-
} }, (this.label || this.secondaryLabel) && (h("div", { key: '
|
|
354
|
+
} }, (this.label || this.secondaryLabel) && (h("div", { key: '22f0674035a68861fae6ce37aba4e51b10c03226', class: "co-number-field__labels" }, this.label && h("label", { key: '442ee74bed62bf7c800f231ad4992b791b85a30c', class: "co-number-field__label" }, this.label, h(RequiredMark, { key: 'ff7517b83b8e942512dcb8c1f504eafab55cea90', required: this.required })), this.secondaryLabel && h("span", { key: '736889aae85065fb28a56131e2f7a3da9fc86a48', class: "co-number-field__secondary-label" }, this.secondaryLabel))), h("div", { key: 'fd6163c7cb83073db2c19c3477447076372abb44', class: "co-number-field__row", part: "row" }, !this.hideControls && (h("button", { key: 'e1a52831b83c3255ce63c4ed48a228fe4fdb1629', class: "co-number-field__btn co-number-field__btn--minus", type: "button", tabIndex: -1, disabled: !this.canDecrement, onClick: this.handleDecrement, "aria-label": "Decrease" }, h("co-icon", { key: '86e0ce9b9801e50d9bda6b18a8e1f6f96581b178', name: "minus", size: 16 }))), h("input", { key: '4bdf89e9a4958841a948b3bd6e9886898917f464', ref: el => (this.inputEl = el), class: "co-number-field__input", type: "text", inputMode: "decimal",
|
|
347
355
|
// Mismo guard `focused` que el @Watch: mientras el usuario edita, su
|
|
348
356
|
// texto manda. Sin esto, el re-render que dispara emitValue repinta
|
|
349
357
|
// el input desde el NÚMERO y se come el texto en construcción
|
|
350
358
|
// ("34,640.00" pegado quedaba "34,640"; un "12." perdería el punto).
|
|
351
|
-
value: this.focused && this.inputEl ? this.inputEl.value : this.displayValue, placeholder: this.placeholder, disabled: this.disabled, onInput: this.handleInput, onPaste: this.handlePaste, onFocus: this.handleFocus, onBlur: this.handleBlur, onKeyDown: this.handleKeyDown, part: "input" }), this.affixText && (h("span", { key: '
|
|
359
|
+
value: this.focused && this.inputEl ? this.inputEl.value : this.displayValue, placeholder: this.placeholder, disabled: this.disabled, onInput: this.handleInput, onPaste: this.handlePaste, onFocus: this.handleFocus, onBlur: this.handleBlur, onKeyDown: this.handleKeyDown, part: "input" }), this.affixText && (h("span", { key: '7bc7c12c6fe2708691d9a2972f9ed3037e82a1a8', class: "co-number-field__affix", "aria-hidden": "true" }, this.affixText)), this.clearable && !this.isEmpty && !this.disabled && (h("button", { key: '2ef7c424a34a8a6cbfe8ac4cd0a5d8f0ed74e6d4', class: "co-number-field__clear", type: "button", tabIndex: -1, onClick: this.handleClear, "aria-label": "Clear" }, h("co-icon", { key: 'c428ca841c0de013cd151bd356686be43992de04', name: "x-circle", size: 16, weight: "fill" }))), h("slot", { key: 'fb127a663d3839bbb10b8232b250eaf67faab898', name: "suffix" }), !this.hideControls && (h("button", { key: '684329d2f32a58f6be2a124f0cd20986a7fc49af', class: "co-number-field__btn co-number-field__btn--plus", type: "button", tabIndex: -1, disabled: !this.canIncrement, onClick: this.handleIncrement, "aria-label": "Increase" }, h("co-icon", { key: '7ef48466e060efb314466d62216a8e00168ddbcd', name: "plus", size: 16 })))), this.helperText && (h("div", { key: '2cf6df2556160fef3c1dfd1b525991eb822cb285', class: `co-number-field__helper co-number-field__helper--${this.status}` }, this.statusIcon && h("co-icon", { key: '905ad795d9714fa9ae8fc2b9d4b9f6a7bba2d2ce', name: this.statusIcon, size: 14, weight: "fill", class: "co-number-field__helper-icon" }), h("span", { key: '0c4825c4145298700de006eb3170e9ec3b52d3b7', class: "co-number-field__helper-text" }, this.helperText)))));
|
|
352
360
|
}
|
|
353
361
|
static get is() { return "co-number-field"; }
|
|
354
362
|
static get encapsulation() { return "shadow"; }
|
|
@@ -446,7 +446,7 @@ export class CoPopover {
|
|
|
446
446
|
"references": {
|
|
447
447
|
"PopoverPlacement": {
|
|
448
448
|
"location": "local",
|
|
449
|
-
"path": "/Users/agox/
|
|
449
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-popover/co-popover.tsx",
|
|
450
450
|
"id": "src/components/co-popover/co-popover.tsx::PopoverPlacement"
|
|
451
451
|
}
|
|
452
452
|
}
|
|
@@ -224,7 +224,7 @@ export class CoRadioGroup {
|
|
|
224
224
|
"references": {
|
|
225
225
|
"RadioOption": {
|
|
226
226
|
"location": "local",
|
|
227
|
-
"path": "/Users/agox/
|
|
227
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-radio-group/co-radio-group.tsx",
|
|
228
228
|
"id": "src/components/co-radio-group/co-radio-group.tsx::RadioOption"
|
|
229
229
|
}
|
|
230
230
|
}
|
|
@@ -1349,7 +1349,7 @@ export class CoRefField {
|
|
|
1349
1349
|
"references": {
|
|
1350
1350
|
"RefFieldOption": {
|
|
1351
1351
|
"location": "local",
|
|
1352
|
-
"path": "/Users/agox/
|
|
1352
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-ref-field/co-ref-field.tsx",
|
|
1353
1353
|
"id": "src/components/co-ref-field/co-ref-field.tsx::RefFieldOption"
|
|
1354
1354
|
}
|
|
1355
1355
|
}
|
|
@@ -1490,7 +1490,7 @@ export class CoRefField {
|
|
|
1490
1490
|
"references": {
|
|
1491
1491
|
"RefFieldOption": {
|
|
1492
1492
|
"location": "local",
|
|
1493
|
-
"path": "/Users/agox/
|
|
1493
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-ref-field/co-ref-field.tsx",
|
|
1494
1494
|
"id": "src/components/co-ref-field/co-ref-field.tsx::RefFieldOption"
|
|
1495
1495
|
}
|
|
1496
1496
|
}
|
|
@@ -1511,7 +1511,7 @@ export class CoRefField {
|
|
|
1511
1511
|
"references": {
|
|
1512
1512
|
"RefFieldOption": {
|
|
1513
1513
|
"location": "local",
|
|
1514
|
-
"path": "/Users/agox/
|
|
1514
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-ref-field/co-ref-field.tsx",
|
|
1515
1515
|
"id": "src/components/co-ref-field/co-ref-field.tsx::RefFieldOption"
|
|
1516
1516
|
}
|
|
1517
1517
|
}
|
|
@@ -1550,7 +1550,7 @@ export class CoRefField {
|
|
|
1550
1550
|
},
|
|
1551
1551
|
"RefFieldOption": {
|
|
1552
1552
|
"location": "local",
|
|
1553
|
-
"path": "/Users/agox/
|
|
1553
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-ref-field/co-ref-field.tsx",
|
|
1554
1554
|
"id": "src/components/co-ref-field/co-ref-field.tsx::RefFieldOption"
|
|
1555
1555
|
}
|
|
1556
1556
|
},
|
|
@@ -160,7 +160,7 @@ export class CoSegmentedBar {
|
|
|
160
160
|
"references": {
|
|
161
161
|
"CoSegment": {
|
|
162
162
|
"location": "local",
|
|
163
|
-
"path": "/Users/agox/
|
|
163
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-segmented-bar/co-segmented-bar.tsx",
|
|
164
164
|
"id": "src/components/co-segmented-bar/co-segmented-bar.tsx::CoSegment"
|
|
165
165
|
}
|
|
166
166
|
}
|
|
@@ -846,7 +846,7 @@ export class CoSelect {
|
|
|
846
846
|
"references": {
|
|
847
847
|
"SelectOption": {
|
|
848
848
|
"location": "local",
|
|
849
|
-
"path": "/Users/agox/
|
|
849
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-select/co-select.tsx",
|
|
850
850
|
"id": "src/components/co-select/co-select.tsx::SelectOption"
|
|
851
851
|
}
|
|
852
852
|
}
|
|
@@ -718,7 +718,7 @@ export class CoSidebarNav {
|
|
|
718
718
|
"references": {
|
|
719
719
|
"NavigateDetail": {
|
|
720
720
|
"location": "local",
|
|
721
|
-
"path": "/Users/agox/
|
|
721
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-sidebar-nav/co-sidebar-nav.tsx",
|
|
722
722
|
"id": "src/components/co-sidebar-nav/co-sidebar-nav.tsx::NavigateDetail"
|
|
723
723
|
}
|
|
724
724
|
}
|
|
@@ -189,7 +189,7 @@ export class CoToast {
|
|
|
189
189
|
"references": {
|
|
190
190
|
"CoToastActionsLayout": {
|
|
191
191
|
"location": "local",
|
|
192
|
-
"path": "/Users/agox/
|
|
192
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-toast/co-toast.tsx",
|
|
193
193
|
"id": "src/components/co-toast/co-toast.tsx::CoToastActionsLayout"
|
|
194
194
|
}
|
|
195
195
|
}
|
|
@@ -215,7 +215,7 @@ export class CoToast {
|
|
|
215
215
|
"references": {
|
|
216
216
|
"CoToastVariant": {
|
|
217
217
|
"location": "local",
|
|
218
|
-
"path": "/Users/agox/
|
|
218
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-toast/co-toast.tsx",
|
|
219
219
|
"id": "src/components/co-toast/co-toast.tsx::CoToastVariant"
|
|
220
220
|
}
|
|
221
221
|
}
|
|
@@ -214,7 +214,7 @@ export class CoTransferList {
|
|
|
214
214
|
"references": {
|
|
215
215
|
"TransferOption": {
|
|
216
216
|
"location": "local",
|
|
217
|
-
"path": "/Users/agox/
|
|
217
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-transfer-list/co-transfer-list.tsx",
|
|
218
218
|
"id": "src/components/co-transfer-list/co-transfer-list.tsx::TransferOption"
|
|
219
219
|
}
|
|
220
220
|
}
|
|
@@ -243,7 +243,7 @@ export class CoTreeItem {
|
|
|
243
243
|
"references": {
|
|
244
244
|
"TreeItemSelection": {
|
|
245
245
|
"location": "local",
|
|
246
|
-
"path": "/Users/agox/
|
|
246
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-tree-item/co-tree-item.tsx",
|
|
247
247
|
"id": "src/components/co-tree-item/co-tree-item.tsx::TreeItemSelection"
|
|
248
248
|
}
|
|
249
249
|
}
|
|
@@ -269,7 +269,7 @@ export class CoTreeItem {
|
|
|
269
269
|
"references": {
|
|
270
270
|
"TreeItemSize": {
|
|
271
271
|
"location": "local",
|
|
272
|
-
"path": "/Users/agox/
|
|
272
|
+
"path": "/Users/agox/worktrees/cobalt-audio-peaks/packages/core/src/components/co-tree-item/co-tree-item.tsx",
|
|
273
273
|
"id": "src/components/co-tree-item/co-tree-item.tsx::TreeItemSize"
|
|
274
274
|
}
|
|
275
275
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{t,p as i,H as a,c as s,h as e}from"./index.js";import{d as o}from"./p-KK2vAKs-.js";function r(t){if(!Number.isFinite(t)||t<0)return"--:--";const i=Math.floor(t);return`${Math.floor(i/60)}:${(""+i%60).padStart(2,"0")}`}function c(t,i){const a=t.length;if(!a||i<=0)return[];const s=Math.max(1,Math.floor(a/i)),e=[];for(let o=0;o<i;o++){let i=0;const r=o*s;for(let e=r;e<r+s&&e<a;e++){const a=Math.abs(t[e]);a>i&&(i=a)}e.push(.12+.88*i)}return e}function h(t){if(t<=0)return[];const i=[];for(let a=0;a<t;a++)i.push(.12+(.6*Math.sin(a/Math.max(1,t)*Math.PI)+.3)*(.75+.25*Math.abs(Math.sin(1.7*a)))*.88);return i}const n=i(class extends a{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.coPlay=s(this,"coPlay",7),this.coPause=s(this,"coPause",7),this.coEnded=s(this,"coEnded",7),this.coError=s(this,"coError",7),this.coTimeUpdate=s(this,"coTimeUpdate",3),this.compact=!1,this.bars=64,this.barDensity=3,this.preload="metadata",this.downloadFilename="audio",this.noDownload=!1,this.isPlaying=!1,this.isLoading=!1,this.hasError=!1,this.currentTime=0,this.duration=NaN,this.peaks=[],this.containerWidth=0,this.playbackRate=1,this.rawChannelData=null,this.decodedDuration=NaN,this.loadToken=0,this.onMeta=()=>{this.syncDuration(),this.applyPendingSeek()},this.pendingSeek=null,this.onCanPlay=()=>{this.isLoading=!1,this.applyPendingSeek()},this.onWaiting=()=>{this.isLoading=!0},this.onTime=()=>{var t;this.currentTime=(null===(t=this.audio)||void 0===t?void 0:t.currentTime)||0,this.coTimeUpdate.emit({currentTime:this.currentTime,duration:this.knownDuration})},this.onEnded=()=>{this.isPlaying=!1,this.currentTime=0,this.coEnded.emit()},this.onErr=t=>{this.isLoading=!1,this.hasError=!0,this.coError.emit(t)},this.toggle=()=>{this.audio&&!this.hasError&&(this.isPlaying?(this.audio.pause(),this.isPlaying=!1,this.coPause.emit()):this.audio.play().then((()=>{this.isPlaying=!0,this.coPlay.emit()})).catch((()=>{})))},this.SPEEDS=[1,1.5,2,.5],this.cycleSpeed=()=>{const t=this.SPEEDS.indexOf(this.playbackRate);this.playbackRate=this.SPEEDS[(t+1)%this.SPEEDS.length],this.audio&&(this.audio.playbackRate=this.playbackRate)},this.seekAt=t=>{const i=this.knownDuration;if(!this.audio||!this.waveEl||!i)return;const a=function(t,i){return i.width?Math.max(0,Math.min(1,(t-i.left)/i.width)):0}(t,this.waveEl.getBoundingClientRect());this.audio.currentTime=a*i,this.currentTime=this.audio.currentTime},this.onWaveKey=t=>{if(" "===t.key||"Enter"===t.key)return t.preventDefault(),void this.toggle();if(!this.audio)return;const i=this.knownDuration,a=this.audio.currentTime;if("ArrowRight"===t.key)this.audio.currentTime=i?Math.min(i,a+5):a+5;else{if("ArrowLeft"!==t.key)return;this.audio.currentTime=Math.max(0,a-5)}this.currentTime=this.audio.currentTime}}get knownDuration(){return Number.isFinite(this.duration)&&this.duration>0?this.duration:0}get effectiveBars(){return this.containerWidth>0?Math.max(24,Math.floor(this.containerWidth/this.barDensity)):this.bars}componentWillLoad(){this.init()}componentDidLoad(){if("undefined"==typeof ResizeObserver||!this.waveEl)return;this.resizeObserver=new ResizeObserver((t=>{var i;for(const a of t){const t=(null===(i=a.contentRect)||void 0===i?void 0:i.width)||a.target.clientWidth||0;t>2&&Math.abs(t-this.containerWidth)>2&&(this.containerWidth=t,this.rebuildBars())}})),this.resizeObserver.observe(this.waveEl);const t=this.waveEl.clientWidth||0;t>2&&(this.containerWidth=t,this.rebuildBars())}disconnectedCallback(){var t;this.loadToken++,this.teardown(),null===(t=this.resizeObserver)||void 0===t||t.disconnect(),this.resizeObserver=void 0}onSrcChange(){this.init()}rebuildBars(){this.peaks=this.rawChannelData?c(this.rawChannelData,this.effectiveBars):h(this.effectiveBars)}init(){this.teardown();const t=++this.loadToken;if(this.rawChannelData=null,this.decodedDuration=NaN,this.peaks=h(this.effectiveBars),this.currentTime=0,this.duration=NaN,this.playbackRate=1,this.hasError=!1,!this.src)return;if(this.isLoading=!0,this.extractPeaks(this.src,t),"undefined"==typeof Audio)return;const i=new Audio;i.preload=this.preload,i.crossOrigin="anonymous",i.src=this.src,i.addEventListener("loadedmetadata",this.onMeta),i.addEventListener("timeupdate",this.onTime),i.addEventListener("ended",this.onEnded),i.addEventListener("error",this.onErr),i.addEventListener("canplay",this.onCanPlay),i.addEventListener("waiting",this.onWaiting),this.audio=i}teardown(){this.audio&&(this.audio.pause(),this.audio.removeEventListener("loadedmetadata",this.onMeta),this.audio.removeEventListener("timeupdate",this.onTime),this.audio.removeEventListener("ended",this.onEnded),this.audio.removeEventListener("error",this.onErr),this.audio.removeEventListener("canplay",this.onCanPlay),this.audio.removeEventListener("waiting",this.onWaiting),this.audio.src="",this.audio=void 0),this.isPlaying=!1}async extractPeaks(t,i){var a;let s;try{const a=window.OfflineAudioContext||window.webkitOfflineAudioContext,e=window.AudioContext||window.webkitAudioContext;if(!a&&!e||"undefined"==typeof fetch)return;s=a?new a(1,1,44100):new e;const o=await(await fetch(t)).arrayBuffer(),r=await s.decodeAudioData(o);if(i!==this.loadToken)return;this.rawChannelData=r.getChannelData(0),this.decodedDuration=r.duration,this.peaks=c(this.rawChannelData,this.effectiveBars)}catch(t){if(i!==this.loadToken)return;this.rawChannelData=null,this.decodedDuration=NaN,this.peaks=h(this.effectiveBars)}finally{try{await(null===(a=null==s?void 0:s.close)||void 0===a?void 0:a.call(s))}catch(t){}}i===this.loadToken&&this.syncDuration()}syncDuration(){var t,i;const a=function(t,i){return Number.isFinite(t)&&t>0?t:Number.isFinite(i)&&i>0?i:NaN}(null!==(i=null===(t=this.audio)||void 0===t?void 0:t.duration)&&void 0!==i?i:NaN,this.decodedDuration);Object.is(a,this.duration)||(this.duration=a)}applyPendingSeek(){if(null==this.pendingSeek||!this.audio)return;const t=this.pendingSeek;this.pendingSeek=null,this.audio.currentTime=t,this.currentTime=this.audio.currentTime,this.coTimeUpdate.emit({currentTime:this.currentTime,duration:this.knownDuration})}async seek(t){var i;if(!this.audio||!Number.isFinite(t))return;const a=this.knownDuration,s=Math.max(0,a?Math.min(a,t):t);this.audio.currentTime=s,Math.abs((null!==(i=this.audio.currentTime)&&void 0!==i?i:0)-s)>.05&&(this.pendingSeek=s),this.currentTime=s,this.coTimeUpdate.emit({currentTime:this.currentTime,duration:a})}async play(){if(this.audio&&!this.isPlaying&&!this.hasError)try{await this.audio.play(),this.isPlaying=!0,this.coPlay.emit()}catch(t){}}async download(){if(this.src&&"undefined"!=typeof fetch)try{const t=await(await fetch(this.src)).blob(),i=URL.createObjectURL(t),a=document.createElement("a");a.href=i,a.download=this.downloadFilename,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}catch(t){}}render(){const t=Math.max(1,3*this.peaks.length),i=this.knownDuration,a=i?this.currentTime/i*100:0,s=i?Math.floor(i):void 0,o=(t,i,a=!1)=>e("rect",{key:"4b294190b3be5e7cf15282d43e7e51164a3dda4c",x:3*i,y:20-40*t/2,width:1.8,height:Math.max(40*t,2),rx:.6,class:{"co-audio-player__bar":!0,"co-audio-player__bar--played":a}});return e("div",{key:"0758a438c4a71e822de94f8b41219945f62ae62d",class:{"co-audio-player":!0,"co-audio-player--compact":this.compact,"co-audio-player--error":this.hasError,"co-audio-player--playing":this.isPlaying},part:"player"},e("button",{key:"4c4161e7ba7344a9c6a32dcc8fd92c300b750d95",type:"button",class:"co-audio-player__play",part:"play","aria-label":this.hasError?"Audio no disponible":this.isPlaying?"Pausar":"Reproducir","aria-busy":this.isLoading?"true":"false",disabled:this.hasError||!this.src,onClick:this.toggle},e("co-icon",{key:"ea749ee1cf627a49e3859029ca274170c8d69c63",name:this.hasError?"warning-circle":this.isPlaying?"pause":"play",weight:"fill",size:this.compact?12:14})),e("div",{key:"f39bf8bf114860a672979fa53287672dccea1b7f",class:"co-audio-player__wave",part:"wave",role:"slider",tabindex:"0","aria-label":"Progreso de reproducción","aria-valuemin":0,"aria-valuemax":s,"aria-valuenow":Math.floor(this.currentTime),ref:t=>this.waveEl=t,onClick:t=>this.seekAt(t.clientX),onKeyDown:this.onWaveKey},e("svg",{key:"2145f303271ca676988999b5ea7d76ab384c5e2d",class:"co-audio-player__svg",viewBox:`0 0 ${t} 40`,preserveAspectRatio:"none","aria-hidden":"true"},this.peaks.map(((t,i)=>o(t,i))),e("clipPath",{key:"6014c9f96f5df60086265a5e01344be80ebff741",id:"co-ap-clip"},e("rect",{key:"5857fa3098fc0eb9df58b643c2b44316cf819ae8",x:"0",y:"0",width:a/100*t,height:40})),e("g",{key:"241608ddfdb863ba5b18444ed2bffb39e72abeb5","clip-path":"url(#co-ap-clip)"},this.peaks.map(((t,i)=>o(t,i,!0)))))),e("span",{key:"18f190b8b23f8939da5dd2c230214d42a5b330c1",class:"co-audio-player__time",part:"time"},r(this.currentTime)," / ",r(this.duration)),!this.compact&&e("button",{key:"4a29cae938ab347997bc76e0cfe5621b402730f7",type:"button",class:"co-audio-player__speed",part:"speed","aria-label":`Velocidad de reproducción ${this.playbackRate}x`,onClick:this.cycleSpeed},this.playbackRate,"x"),!this.compact&&!this.noDownload&&e("button",{key:"c451449e629584bc3937b27b31b1124e510af91e",type:"button",class:"co-audio-player__dl",part:"download","aria-label":"Descargar",onClick:()=>this.download()},e("co-icon",{key:"f4d014129829ab57ddae0d3e32b1e0930f1bc288",name:"download-simple",size:14})))}static get watchers(){return{src:[{onSrcChange:0}]}}static get style(){return":host{display:block;font-family:var(--co-font-family-primary)}.co-audio-player{display:flex;align-items:center;gap:var(--co-spacing-md);padding:var(--co-spacing-sm) var(--co-spacing-md);border:1px solid var(--co-semantic-border-default);border-radius:var(--co-border-radius-xs);background:var(--co-semantic-surface-secondary);min-width:180px}.co-audio-player--compact{gap:var(--co-spacing-sm2);padding:var(--co-spacing-sm2) var(--co-spacing-sm);min-width:140px}.co-audio-player__play{flex:0 0 auto;width:28px;height:28px;border:none;border-radius:50%;cursor:pointer;background:var(--co-semantic-surface-primary);color:var(--co-semantic-text-inverse);display:inline-flex;align-items:center;justify-content:center}.co-audio-player--compact .co-audio-player__play{width:24px;height:24px}.co-audio-player__play:disabled{opacity:.5;cursor:not-allowed}.co-audio-player__play:focus-visible{outline:2px solid var(--co-semantic-border-focus);outline-offset:2px}.co-audio-player__wave{flex:1;height:40px;min-width:0;cursor:pointer;display:flex;align-items:center}.co-audio-player__wave:focus-visible{outline:2px solid var(--co-semantic-border-focus);outline-offset:2px;border-radius:var(--co-border-radius-xxs)}.co-audio-player__svg{width:100%;height:100%;display:block}.co-audio-player__bar{fill:var(--co-semantic-border-field);transition:fill var(--co-motion-duration-fast)}.co-audio-player__wave:hover .co-audio-player__bar{fill:var(--co-semantic-text-muted)}.co-audio-player__bar--played{fill:var(--co-semantic-surface-primary)}.co-audio-player__time{flex:0 0 auto;font-size:var(--co-font-size-12);color:var(--co-semantic-text-muted);font-variant-numeric:tabular-nums;min-width:62px;text-align:right}.co-audio-player__speed{flex:0 0 auto;border:none;background:transparent;cursor:pointer;padding:2px 4px;color:var(--co-semantic-text-muted);font-family:var(--co-font-family-primary);font-size:var(--co-font-size-12);font-variant-numeric:tabular-nums;min-width:34px;text-align:center}.co-audio-player__speed:hover{color:var(--co-semantic-text-default)}.co-audio-player__speed:focus-visible{outline:2px solid var(--co-semantic-border-focus);outline-offset:2px;border-radius:var(--co-border-radius-xxs)}.co-audio-player__dl{flex:0 0 auto;border:none;background:transparent;cursor:pointer;padding:2px;color:var(--co-semantic-text-muted);display:inline-flex}.co-audio-player__dl:hover{color:var(--co-semantic-text-default)}.co-audio-player__dl:focus-visible{outline:2px solid var(--co-semantic-border-focus);outline-offset:2px}.co-audio-player--error .co-audio-player__wave{opacity:.5}.co-audio-player--error .co-audio-player__play{background:var(--co-color-status-error);color:var(--co-semantic-text-inverse);opacity:1}"}},[1,"co-audio-player",{src:[1],compact:[4],bars:[2],barDensity:[2,"bar-density"],preload:[1],downloadFilename:[1,"download-filename"],noDownload:[4,"no-download"],isPlaying:[32],isLoading:[32],hasError:[32],currentTime:[32],duration:[32],peaks:[32],containerWidth:[32],playbackRate:[32],seek:[64],play:[64]},void 0,{src:[{onSrcChange:0}]}]);function d(){"undefined"!=typeof customElements&&["co-audio-player","co-icon"].forEach((i=>{switch(i){case"co-audio-player":customElements.get(t(i))||customElements.define(t(i),n);break;case"co-icon":customElements.get(t(i))||o()}}))}d();const l=n,u=d;export{l as CoAudioPlayer,u as defineCustomElement}
|
|
1
|
+
import{t,p as i,H as a,c as e,h as s}from"./index.js";import{d as o}from"./p-KK2vAKs-.js";function r(t){if(!Number.isFinite(t)||t<0)return"--:--";const i=Math.floor(t);return`${Math.floor(i/60)}:${(""+i%60).padStart(2,"0")}`}function n(t,i){const a=t.length;if(!a||i<=0)return[];const e=Math.max(1,Math.floor(a/i)),s=[];for(let o=0;o<i;o++){let i=0;const r=o*e;for(let s=r;s<r+e&&s<a;s++){const a=Math.abs(t[s]);a>i&&(i=a)}s.push(.12+.88*i)}return s}function h(t,i=65536){const a=t.length,e=Math.max(1,Math.ceil(a/Math.max(1,i))),s=Math.ceil(a/e),o=new Float32Array(s);for(let i=0;i<s;i++){let s=0;const r=Math.min(a,(i+1)*e);for(let a=i*e;a<r;a++){const i=Math.abs(t[a]);i>s&&(s=i)}o[i]=s}return{peaks:o,blockSize:e,length:a}}function c(t){if(t<=0)return[];const i=[];for(let a=0;a<t;a++)i.push(.12+(.6*Math.sin(a/Math.max(1,t)*Math.PI)+.3)*(.75+.25*Math.abs(Math.sin(1.7*a)))*.88);return i}const d=new Map,l=new Map;function u(t,i){for(d.delete(t),d.set(t,i);d.size>16;)d.delete(d.keys().next().value)}function p(t,i,a=f){const e=d.get(t);if(e)return u(t,e),Promise.resolve(e);const s=l.get(t);if(s)return i&&s.wanted.add(i),s.promise;const o=new Set(i?[i]:[]),r=a(t,o).then((i=>(l.delete(t),i&&u(t,i),i)),(i=>{throw l.delete(t),i}));return l.set(t,{promise:r,wanted:o}),r}async function f(t,i=new Set){var a;let e;try{const a=window.OfflineAudioContext||window.webkitOfflineAudioContext,s=window.AudioContext||window.webkitAudioContext;if(!a&&!s||"undefined"==typeof fetch)return null;e=a?new a(1,1,44100):new s;const o=await(await fetch(t)).arrayBuffer(),r=await e.decodeAudioData(o),n=r.getChannelData(0);return{envelope:h(n),exact:y(n,i),duration:r.duration}}finally{try{await(null===(a=null==e?void 0:e.close)||void 0===a?void 0:a.call(e))}catch(t){}}}function y(t,i){const a=new Map;for(const e of i){const i=e();i>0&&!a.has(i)&&a.set(i,n(t,i))}return a}const b=i(class extends a{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.coPlay=e(this,"coPlay",7),this.coPause=e(this,"coPause",7),this.coEnded=e(this,"coEnded",7),this.coError=e(this,"coError",7),this.coTimeUpdate=e(this,"coTimeUpdate",3),this.compact=!1,this.bars=64,this.barDensity=3,this.preload="metadata",this.downloadFilename="audio",this.noDownload=!1,this.isPlaying=!1,this.isLoading=!1,this.hasError=!1,this.currentTime=0,this.duration=NaN,this.peaks=[],this.containerWidth=0,this.playbackRate=1,this.peakEnvelope=null,this.exactPeaks=null,this.decodedDuration=NaN,this.loadToken=0,this.onMeta=()=>{this.syncDuration(),this.applyPendingSeek()},this.pendingSeek=null,this.onCanPlay=()=>{this.isLoading=!1,this.applyPendingSeek()},this.onWaiting=()=>{this.isLoading=!0},this.onTime=()=>{var t;this.currentTime=(null===(t=this.audio)||void 0===t?void 0:t.currentTime)||0,this.coTimeUpdate.emit({currentTime:this.currentTime,duration:this.knownDuration})},this.onEnded=()=>{this.isPlaying=!1,this.currentTime=0,this.coEnded.emit()},this.onErr=t=>{this.isLoading=!1,this.hasError=!0,this.coError.emit(t)},this.toggle=()=>{this.audio&&!this.hasError&&(this.isPlaying?(this.audio.pause(),this.isPlaying=!1,this.coPause.emit()):this.audio.play().then((()=>{this.isPlaying=!0,this.coPlay.emit()})).catch((()=>{})))},this.SPEEDS=[1,1.5,2,.5],this.cycleSpeed=()=>{const t=this.SPEEDS.indexOf(this.playbackRate);this.playbackRate=this.SPEEDS[(t+1)%this.SPEEDS.length],this.audio&&(this.audio.playbackRate=this.playbackRate)},this.seekAt=t=>{const i=this.knownDuration;if(!this.audio||!this.waveEl||!i)return;const a=function(t,i){return i.width?Math.max(0,Math.min(1,(t-i.left)/i.width)):0}(t,this.waveEl.getBoundingClientRect());this.audio.currentTime=a*i,this.currentTime=this.audio.currentTime},this.onWaveKey=t=>{if(" "===t.key||"Enter"===t.key)return t.preventDefault(),void this.toggle();if(!this.audio)return;const i=this.knownDuration,a=this.audio.currentTime;if("ArrowRight"===t.key)this.audio.currentTime=i?Math.min(i,a+5):a+5;else{if("ArrowLeft"!==t.key)return;this.audio.currentTime=Math.max(0,a-5)}this.currentTime=this.audio.currentTime}}get knownDuration(){return Number.isFinite(this.duration)&&this.duration>0?this.duration:0}get effectiveBars(){return this.containerWidth>0?Math.max(24,Math.floor(this.containerWidth/this.barDensity)):this.bars}componentWillLoad(){this.init()}componentDidLoad(){if("undefined"==typeof ResizeObserver||!this.waveEl)return;this.resizeObserver=new ResizeObserver((t=>{var i;for(const a of t){const t=(null===(i=a.contentRect)||void 0===i?void 0:i.width)||a.target.clientWidth||0;t>2&&Math.abs(t-this.containerWidth)>2&&(this.containerWidth=t,this.rebuildBars())}})),this.resizeObserver.observe(this.waveEl);const t=this.waveEl.clientWidth||0;t>2&&(this.containerWidth=t,this.rebuildBars())}disconnectedCallback(){var t;this.loadToken++,this.teardown(),null===(t=this.resizeObserver)||void 0===t||t.disconnect(),this.resizeObserver=void 0}onSrcChange(){this.init()}rebuildBars(){this.peaks=this.peakEnvelope?this.decodedBars(this.effectiveBars):c(this.effectiveBars)}decodedBars(t){var i,a;return null!==(a=null===(i=this.exactPeaks)||void 0===i?void 0:i.get(t))&&void 0!==a?a:function(t,i){const{peaks:a,blockSize:e,length:s}=t;if(!s||i<=0)return[];const o=Math.max(1,Math.floor(s/i)),r=[];for(let t=0;t<i;t++){const i=t*o,n=Math.min(i+o,s);let h=0;if(i<n){const t=Math.floor((n-1)/e);for(let s=Math.floor(i/e);s<=t;s++)a[s]>h&&(h=a[s])}r.push(.12+.88*h)}return r}(this.peakEnvelope,t)}init(){this.teardown();const t=++this.loadToken;if(this.peakEnvelope=null,this.exactPeaks=null,this.decodedDuration=NaN,this.peaks=c(this.effectiveBars),this.currentTime=0,this.duration=NaN,this.playbackRate=1,this.hasError=!1,!this.src)return;if(this.isLoading=!0,this.extractPeaks(this.src,t),"undefined"==typeof Audio)return;const i=new Audio;i.preload=this.preload,i.crossOrigin="anonymous",i.src=this.src,i.addEventListener("loadedmetadata",this.onMeta),i.addEventListener("timeupdate",this.onTime),i.addEventListener("ended",this.onEnded),i.addEventListener("error",this.onErr),i.addEventListener("canplay",this.onCanPlay),i.addEventListener("waiting",this.onWaiting),this.audio=i}teardown(){this.audio&&(this.audio.pause(),this.audio.removeEventListener("loadedmetadata",this.onMeta),this.audio.removeEventListener("timeupdate",this.onTime),this.audio.removeEventListener("ended",this.onEnded),this.audio.removeEventListener("error",this.onErr),this.audio.removeEventListener("canplay",this.onCanPlay),this.audio.removeEventListener("waiting",this.onWaiting),this.audio.src="",this.audio=void 0),this.isPlaying=!1}async extractPeaks(t,i){try{const a=await p(t,(()=>i===this.loadToken?this.effectiveBars:0));if(i!==this.loadToken)return;if(!a)return;this.peakEnvelope=a.envelope,this.exactPeaks=a.exact,this.decodedDuration=a.duration,this.peaks=this.decodedBars(this.effectiveBars)}catch(t){if(i!==this.loadToken)return;this.peakEnvelope=null,this.exactPeaks=null,this.decodedDuration=NaN,this.peaks=c(this.effectiveBars)}i===this.loadToken&&this.syncDuration()}syncDuration(){var t,i;const a=function(t,i){return Number.isFinite(t)&&t>0?t:Number.isFinite(i)&&i>0?i:NaN}(null!==(i=null===(t=this.audio)||void 0===t?void 0:t.duration)&&void 0!==i?i:NaN,this.decodedDuration);Object.is(a,this.duration)||(this.duration=a)}applyPendingSeek(){if(null==this.pendingSeek||!this.audio)return;const t=this.pendingSeek;this.pendingSeek=null,this.audio.currentTime=t,this.currentTime=this.audio.currentTime,this.coTimeUpdate.emit({currentTime:this.currentTime,duration:this.knownDuration})}async seek(t){var i;if(!this.audio||!Number.isFinite(t))return;const a=this.knownDuration,e=Math.max(0,a?Math.min(a,t):t);this.audio.currentTime=e,Math.abs((null!==(i=this.audio.currentTime)&&void 0!==i?i:0)-e)>.05&&(this.pendingSeek=e),this.currentTime=e,this.coTimeUpdate.emit({currentTime:this.currentTime,duration:a})}async play(){if(this.audio&&!this.isPlaying&&!this.hasError)try{await this.audio.play(),this.isPlaying=!0,this.coPlay.emit()}catch(t){}}async download(){if(this.src&&"undefined"!=typeof fetch)try{const t=await(await fetch(this.src)).blob(),i=URL.createObjectURL(t),a=document.createElement("a");a.href=i,a.download=this.downloadFilename,document.body.appendChild(a),a.click(),a.remove(),URL.revokeObjectURL(i)}catch(t){}}render(){const t=Math.max(1,3*this.peaks.length),i=this.knownDuration,a=i?this.currentTime/i*100:0,e=i?Math.floor(i):void 0,o=(t,i,a=!1)=>s("rect",{key:"a3d5a225a904e22ba9905ef8198fa7e1b14e0e2f",x:3*i,y:20-40*t/2,width:1.8,height:Math.max(40*t,2),rx:.6,class:{"co-audio-player__bar":!0,"co-audio-player__bar--played":a}});return s("div",{key:"afbbf524713a1146653e69928ee21e263202315f",class:{"co-audio-player":!0,"co-audio-player--compact":this.compact,"co-audio-player--error":this.hasError,"co-audio-player--playing":this.isPlaying},part:"player"},s("button",{key:"5918385fbd8fb6fad4795e1a75eed5d073e0654c",type:"button",class:"co-audio-player__play",part:"play","aria-label":this.hasError?"Audio no disponible":this.isPlaying?"Pausar":"Reproducir","aria-busy":this.isLoading?"true":"false",disabled:this.hasError||!this.src,onClick:this.toggle},s("co-icon",{key:"e7a566257df253914593712bd20029bb8f1bcdfd",name:this.hasError?"warning-circle":this.isPlaying?"pause":"play",weight:"fill",size:this.compact?12:14})),s("div",{key:"70488015726d0c966fa3e738d9f2893d71b99ebf",class:"co-audio-player__wave",part:"wave",role:"slider",tabindex:"0","aria-label":"Progreso de reproducción","aria-valuemin":0,"aria-valuemax":e,"aria-valuenow":Math.floor(this.currentTime),ref:t=>this.waveEl=t,onClick:t=>this.seekAt(t.clientX),onKeyDown:this.onWaveKey},s("svg",{key:"8c70e4f74537e5f8ab6f66bc0da464a72507e81c",class:"co-audio-player__svg",viewBox:`0 0 ${t} 40`,preserveAspectRatio:"none","aria-hidden":"true"},this.peaks.map(((t,i)=>o(t,i))),s("clipPath",{key:"f0d37d76b3d6ab09dbd09582c8657b3fe7cb8c4c",id:"co-ap-clip"},s("rect",{key:"436de0ce10f98c868760c76505d134f3db2dbb54",x:"0",y:"0",width:a/100*t,height:40})),s("g",{key:"939a1a8851d6e41b4d3c37d7201f87a6403830bb","clip-path":"url(#co-ap-clip)"},this.peaks.map(((t,i)=>o(t,i,!0)))))),s("span",{key:"bd57bdd97a780864aa633ec5174d4f733799a278",class:"co-audio-player__time",part:"time"},r(this.currentTime)," / ",r(this.duration)),!this.compact&&s("button",{key:"d1f559546da0b0f97009afca79fe922ce569e67f",type:"button",class:"co-audio-player__speed",part:"speed","aria-label":`Velocidad de reproducción ${this.playbackRate}x`,onClick:this.cycleSpeed},this.playbackRate,"x"),!this.compact&&!this.noDownload&&s("button",{key:"a1503b85bb2edf02566dcad9b8e83b1fea20b159",type:"button",class:"co-audio-player__dl",part:"download","aria-label":"Descargar",onClick:()=>this.download()},s("co-icon",{key:"dc96b8afdb8036e76a0c515d76c625460f4fc44d",name:"download-simple",size:14})))}static get watchers(){return{src:[{onSrcChange:0}]}}static get style(){return":host{display:block;font-family:var(--co-font-family-primary)}.co-audio-player{display:flex;align-items:center;gap:var(--co-spacing-md);padding:var(--co-spacing-sm) var(--co-spacing-md);border:1px solid var(--co-semantic-border-default);border-radius:var(--co-border-radius-xs);background:var(--co-semantic-surface-secondary);min-width:180px}.co-audio-player--compact{gap:var(--co-spacing-sm2);padding:var(--co-spacing-sm2) var(--co-spacing-sm);min-width:140px}.co-audio-player__play{flex:0 0 auto;width:28px;height:28px;border:none;border-radius:50%;cursor:pointer;background:var(--co-semantic-surface-primary);color:var(--co-semantic-text-inverse);display:inline-flex;align-items:center;justify-content:center}.co-audio-player--compact .co-audio-player__play{width:24px;height:24px}.co-audio-player__play:disabled{opacity:.5;cursor:not-allowed}.co-audio-player__play:focus-visible{outline:2px solid var(--co-semantic-border-focus);outline-offset:2px}.co-audio-player__wave{flex:1;height:40px;min-width:0;cursor:pointer;display:flex;align-items:center}.co-audio-player__wave:focus-visible{outline:2px solid var(--co-semantic-border-focus);outline-offset:2px;border-radius:var(--co-border-radius-xxs)}.co-audio-player__svg{width:100%;height:100%;display:block}.co-audio-player__bar{fill:var(--co-semantic-border-field);transition:fill var(--co-motion-duration-fast)}.co-audio-player__wave:hover .co-audio-player__bar{fill:var(--co-semantic-text-muted)}.co-audio-player__bar--played{fill:var(--co-semantic-surface-primary)}.co-audio-player__time{flex:0 0 auto;font-size:var(--co-font-size-12);color:var(--co-semantic-text-muted);font-variant-numeric:tabular-nums;min-width:62px;text-align:right}.co-audio-player__speed{flex:0 0 auto;border:none;background:transparent;cursor:pointer;padding:2px 4px;color:var(--co-semantic-text-muted);font-family:var(--co-font-family-primary);font-size:var(--co-font-size-12);font-variant-numeric:tabular-nums;min-width:34px;text-align:center}.co-audio-player__speed:hover{color:var(--co-semantic-text-default)}.co-audio-player__speed:focus-visible{outline:2px solid var(--co-semantic-border-focus);outline-offset:2px;border-radius:var(--co-border-radius-xxs)}.co-audio-player__dl{flex:0 0 auto;border:none;background:transparent;cursor:pointer;padding:2px;color:var(--co-semantic-text-muted);display:inline-flex}.co-audio-player__dl:hover{color:var(--co-semantic-text-default)}.co-audio-player__dl:focus-visible{outline:2px solid var(--co-semantic-border-focus);outline-offset:2px}.co-audio-player--error .co-audio-player__wave{opacity:.5}.co-audio-player--error .co-audio-player__play{background:var(--co-color-status-error);color:var(--co-semantic-text-inverse);opacity:1}"}},[1,"co-audio-player",{src:[1],compact:[4],bars:[2],barDensity:[2,"bar-density"],preload:[1],downloadFilename:[1,"download-filename"],noDownload:[4,"no-download"],isPlaying:[32],isLoading:[32],hasError:[32],currentTime:[32],duration:[32],peaks:[32],containerWidth:[32],playbackRate:[32],seek:[64],play:[64]},void 0,{src:[{onSrcChange:0}]}]);function m(){"undefined"!=typeof customElements&&["co-audio-player","co-icon"].forEach((i=>{switch(i){case"co-audio-player":customElements.get(t(i))||customElements.define(t(i),b);break;case"co-icon":customElements.get(t(i))||o()}}))}m();const v=b,w=m;export{v as CoAudioPlayer,w as defineCustomElement}
|