web-audio-recorder-ts 1.0.3 → 1.0.4

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/dist/index.cjs.js CHANGED
@@ -549,33 +549,47 @@ function configureEncoderPaths(baseUrl) {
549
549
  * Useful when auto-detection fails
550
550
  */
551
551
  async function findEncoderPath(filename) {
552
+ // Obter base URL atual para construir caminhos relativos
553
+ const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
554
+ const currentPath = typeof window !== 'undefined' ? window.location.pathname : '';
552
555
  // Priorizar caminhos do node_modules primeiro
553
556
  const possiblePaths = [
554
- // Primeiro: tentar node_modules (prioridade máxima)
557
+ // Primeiro: tentar node_modules com caminhos absolutos (prioridade máxima)
555
558
  `/node_modules/web-audio-recorder-ts/lib/${filename}`,
559
+ `${currentOrigin}/node_modules/web-audio-recorder-ts/lib/${filename}`,
560
+ // Caminhos relativos do node_modules
556
561
  `./node_modules/web-audio-recorder-ts/lib/${filename}`,
557
562
  `../node_modules/web-audio-recorder-ts/lib/${filename}`,
558
563
  `../../node_modules/web-audio-recorder-ts/lib/${filename}`,
564
+ `../../../node_modules/web-audio-recorder-ts/lib/${filename}`,
565
+ // Com base no caminho atual
566
+ `${currentPath.replace(/\/[^/]*$/, '')}/node_modules/web-audio-recorder-ts/lib/${filename}`,
559
567
  // From dist (se os arquivos foram copiados para dist/lib)
560
568
  `/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
569
+ `${currentOrigin}/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
561
570
  `./node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
562
571
  // Auto-detected path (pode apontar para node_modules)
563
572
  getEncoderScriptUrl(filename),
564
573
  // Para desenvolvimento/demo: try public folder (Vite serves public/ at root)
565
574
  `/${filename}`,
575
+ `${currentOrigin}/${filename}`,
566
576
  // Direct lib paths (for development or custom setups)
567
577
  `/lib/${filename}`,
578
+ `${currentOrigin}/lib/${filename}`,
568
579
  `./lib/${filename}`,
569
580
  `../lib/${filename}`,
570
581
  // CDN or absolute paths (if configured)
571
582
  filename.startsWith('http') ? filename : null
572
583
  ].filter((path) => path !== null);
584
+ console.log(`[web-audio-recorder-ts] Searching for ${filename} in ${possiblePaths.length} possible paths...`);
573
585
  // Try each path
574
- for (const path of possiblePaths) {
586
+ for (let i = 0; i < possiblePaths.length; i++) {
587
+ const path = possiblePaths[i];
575
588
  try {
576
589
  const testUrl = path.startsWith('http')
577
590
  ? path
578
591
  : new URL(path, typeof window !== 'undefined' ? window.location.href : 'file://').href;
592
+ console.log(`[web-audio-recorder-ts] Trying path ${i + 1}/${possiblePaths.length}: ${path} -> ${testUrl}`);
579
593
  // Usar GET para verificar se é JavaScript válido (não HTML)
580
594
  const response = await fetch(testUrl, { method: 'GET', cache: 'no-cache' });
581
595
  if (response.ok) {
@@ -584,21 +598,30 @@ async function findEncoderPath(filename) {
584
598
  const trimmedText = text.trim();
585
599
  // Se começar com '<', é HTML (404, etc) - pular este caminho
586
600
  if (trimmedText.startsWith('<')) {
587
- console.warn(`Path ${path} returned HTML instead of JavaScript, skipping...`);
601
+ console.warn(`[web-audio-recorder-ts] ❌ Path ${path} returned HTML instead of JavaScript (likely 404), skipping...`);
588
602
  continue;
589
603
  }
590
604
  // Se parece JavaScript, retornar este caminho
591
605
  if (trimmedText.includes('function') || trimmedText.includes('var') || trimmedText.includes('const') || trimmedText.includes('let') || trimmedText.length > 100) {
592
- console.log(`✅ Found encoder file at: ${path}`);
606
+ console.log(`[web-audio-recorder-ts] Found encoder file at: ${path}`);
593
607
  return path;
594
608
  }
609
+ else {
610
+ console.warn(`[web-audio-recorder-ts] ⚠️ Path ${path} returned content but doesn't look like JavaScript`);
611
+ }
612
+ }
613
+ else {
614
+ console.warn(`[web-audio-recorder-ts] ❌ Path ${path} returned status ${response.status} ${response.statusText}`);
595
615
  }
596
616
  }
597
617
  catch (e) {
618
+ console.warn(`[web-audio-recorder-ts] ❌ Error testing path ${path}:`, e);
598
619
  // Continue to next path
599
620
  continue;
600
621
  }
601
622
  }
623
+ console.error(`[web-audio-recorder-ts] ❌ Could not find ${filename} in any of the ${possiblePaths.length} paths tried`);
624
+ console.error(`[web-audio-recorder-ts] Tried paths:`, possiblePaths);
602
625
  return null;
603
626
  }
604
627
 
@@ -680,8 +703,14 @@ async function loadOggVorbisEncoder(scriptUrl) {
680
703
  // Tentar encontrar o arquivo automaticamente
681
704
  const foundPath = await findEncoderPath('OggVorbisEncoder.min.js');
682
705
  if (!foundPath) {
683
- throw new Error('Could not find OggVorbisEncoder.min.js. ' +
684
- 'Please provide the path manually or ensure the package is installed correctly.');
706
+ const errorMsg = 'Could not find OggVorbisEncoder.min.js automatically.\n\n' +
707
+ 'Please try one of the following:\n' +
708
+ '1. Provide the path manually: await loadOggVorbisEncoder("/path/to/OggVorbisEncoder.min.js")\n' +
709
+ '2. Copy files to public/: cp node_modules/web-audio-recorder-ts/lib/*.js public/\n' +
710
+ '3. Configure server to serve node_modules (see NUXT_USAGE.md)\n' +
711
+ '4. Check browser console for detailed path information';
712
+ console.error(errorMsg);
713
+ throw new Error(errorMsg);
685
714
  }
686
715
  scriptUrl = foundPath;
687
716
  }
@@ -872,8 +901,14 @@ async function loadMp3LameEncoder(scriptUrl) {
872
901
  // Tentar encontrar o arquivo automaticamente
873
902
  const foundPath = await findEncoderPath('Mp3LameEncoder.min.js');
874
903
  if (!foundPath) {
875
- throw new Error('Could not find Mp3LameEncoder.min.js. ' +
876
- 'Please provide the path manually or ensure the package is installed correctly.');
904
+ const errorMsg = 'Could not find Mp3LameEncoder.min.js automatically.\n\n' +
905
+ 'Please try one of the following:\n' +
906
+ '1. Provide the path manually: await loadMp3LameEncoder("/path/to/Mp3LameEncoder.min.js")\n' +
907
+ '2. Copy files to public/: cp node_modules/web-audio-recorder-ts/lib/*.js public/\n' +
908
+ '3. Configure server to serve node_modules (see NUXT_USAGE.md)\n' +
909
+ '4. Check browser console for detailed path information';
910
+ console.error(errorMsg);
911
+ throw new Error(errorMsg);
877
912
  }
878
913
  scriptUrl = foundPath;
879
914
  }
package/dist/index.esm.js CHANGED
@@ -546,33 +546,47 @@ function configureEncoderPaths(baseUrl) {
546
546
  * Useful when auto-detection fails
547
547
  */
548
548
  async function findEncoderPath(filename) {
549
+ // Obter base URL atual para construir caminhos relativos
550
+ const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
551
+ const currentPath = typeof window !== 'undefined' ? window.location.pathname : '';
549
552
  // Priorizar caminhos do node_modules primeiro
550
553
  const possiblePaths = [
551
- // Primeiro: tentar node_modules (prioridade máxima)
554
+ // Primeiro: tentar node_modules com caminhos absolutos (prioridade máxima)
552
555
  `/node_modules/web-audio-recorder-ts/lib/${filename}`,
556
+ `${currentOrigin}/node_modules/web-audio-recorder-ts/lib/${filename}`,
557
+ // Caminhos relativos do node_modules
553
558
  `./node_modules/web-audio-recorder-ts/lib/${filename}`,
554
559
  `../node_modules/web-audio-recorder-ts/lib/${filename}`,
555
560
  `../../node_modules/web-audio-recorder-ts/lib/${filename}`,
561
+ `../../../node_modules/web-audio-recorder-ts/lib/${filename}`,
562
+ // Com base no caminho atual
563
+ `${currentPath.replace(/\/[^/]*$/, '')}/node_modules/web-audio-recorder-ts/lib/${filename}`,
556
564
  // From dist (se os arquivos foram copiados para dist/lib)
557
565
  `/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
566
+ `${currentOrigin}/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
558
567
  `./node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
559
568
  // Auto-detected path (pode apontar para node_modules)
560
569
  getEncoderScriptUrl(filename),
561
570
  // Para desenvolvimento/demo: try public folder (Vite serves public/ at root)
562
571
  `/${filename}`,
572
+ `${currentOrigin}/${filename}`,
563
573
  // Direct lib paths (for development or custom setups)
564
574
  `/lib/${filename}`,
575
+ `${currentOrigin}/lib/${filename}`,
565
576
  `./lib/${filename}`,
566
577
  `../lib/${filename}`,
567
578
  // CDN or absolute paths (if configured)
568
579
  filename.startsWith('http') ? filename : null
569
580
  ].filter((path) => path !== null);
581
+ console.log(`[web-audio-recorder-ts] Searching for ${filename} in ${possiblePaths.length} possible paths...`);
570
582
  // Try each path
571
- for (const path of possiblePaths) {
583
+ for (let i = 0; i < possiblePaths.length; i++) {
584
+ const path = possiblePaths[i];
572
585
  try {
573
586
  const testUrl = path.startsWith('http')
574
587
  ? path
575
588
  : new URL(path, typeof window !== 'undefined' ? window.location.href : 'file://').href;
589
+ console.log(`[web-audio-recorder-ts] Trying path ${i + 1}/${possiblePaths.length}: ${path} -> ${testUrl}`);
576
590
  // Usar GET para verificar se é JavaScript válido (não HTML)
577
591
  const response = await fetch(testUrl, { method: 'GET', cache: 'no-cache' });
578
592
  if (response.ok) {
@@ -581,21 +595,30 @@ async function findEncoderPath(filename) {
581
595
  const trimmedText = text.trim();
582
596
  // Se começar com '<', é HTML (404, etc) - pular este caminho
583
597
  if (trimmedText.startsWith('<')) {
584
- console.warn(`Path ${path} returned HTML instead of JavaScript, skipping...`);
598
+ console.warn(`[web-audio-recorder-ts] ❌ Path ${path} returned HTML instead of JavaScript (likely 404), skipping...`);
585
599
  continue;
586
600
  }
587
601
  // Se parece JavaScript, retornar este caminho
588
602
  if (trimmedText.includes('function') || trimmedText.includes('var') || trimmedText.includes('const') || trimmedText.includes('let') || trimmedText.length > 100) {
589
- console.log(`✅ Found encoder file at: ${path}`);
603
+ console.log(`[web-audio-recorder-ts] Found encoder file at: ${path}`);
590
604
  return path;
591
605
  }
606
+ else {
607
+ console.warn(`[web-audio-recorder-ts] ⚠️ Path ${path} returned content but doesn't look like JavaScript`);
608
+ }
609
+ }
610
+ else {
611
+ console.warn(`[web-audio-recorder-ts] ❌ Path ${path} returned status ${response.status} ${response.statusText}`);
592
612
  }
593
613
  }
594
614
  catch (e) {
615
+ console.warn(`[web-audio-recorder-ts] ❌ Error testing path ${path}:`, e);
595
616
  // Continue to next path
596
617
  continue;
597
618
  }
598
619
  }
620
+ console.error(`[web-audio-recorder-ts] ❌ Could not find ${filename} in any of the ${possiblePaths.length} paths tried`);
621
+ console.error(`[web-audio-recorder-ts] Tried paths:`, possiblePaths);
599
622
  return null;
600
623
  }
601
624
 
@@ -677,8 +700,14 @@ async function loadOggVorbisEncoder(scriptUrl) {
677
700
  // Tentar encontrar o arquivo automaticamente
678
701
  const foundPath = await findEncoderPath('OggVorbisEncoder.min.js');
679
702
  if (!foundPath) {
680
- throw new Error('Could not find OggVorbisEncoder.min.js. ' +
681
- 'Please provide the path manually or ensure the package is installed correctly.');
703
+ const errorMsg = 'Could not find OggVorbisEncoder.min.js automatically.\n\n' +
704
+ 'Please try one of the following:\n' +
705
+ '1. Provide the path manually: await loadOggVorbisEncoder("/path/to/OggVorbisEncoder.min.js")\n' +
706
+ '2. Copy files to public/: cp node_modules/web-audio-recorder-ts/lib/*.js public/\n' +
707
+ '3. Configure server to serve node_modules (see NUXT_USAGE.md)\n' +
708
+ '4. Check browser console for detailed path information';
709
+ console.error(errorMsg);
710
+ throw new Error(errorMsg);
682
711
  }
683
712
  scriptUrl = foundPath;
684
713
  }
@@ -869,8 +898,14 @@ async function loadMp3LameEncoder(scriptUrl) {
869
898
  // Tentar encontrar o arquivo automaticamente
870
899
  const foundPath = await findEncoderPath('Mp3LameEncoder.min.js');
871
900
  if (!foundPath) {
872
- throw new Error('Could not find Mp3LameEncoder.min.js. ' +
873
- 'Please provide the path manually or ensure the package is installed correctly.');
901
+ const errorMsg = 'Could not find Mp3LameEncoder.min.js automatically.\n\n' +
902
+ 'Please try one of the following:\n' +
903
+ '1. Provide the path manually: await loadMp3LameEncoder("/path/to/Mp3LameEncoder.min.js")\n' +
904
+ '2. Copy files to public/: cp node_modules/web-audio-recorder-ts/lib/*.js public/\n' +
905
+ '3. Configure server to serve node_modules (see NUXT_USAGE.md)\n' +
906
+ '4. Check browser console for detailed path information';
907
+ console.error(errorMsg);
908
+ throw new Error(errorMsg);
874
909
  }
875
910
  scriptUrl = foundPath;
876
911
  }
package/dist/index.umd.js CHANGED
@@ -553,33 +553,47 @@
553
553
  * Useful when auto-detection fails
554
554
  */
555
555
  async function findEncoderPath(filename) {
556
+ // Obter base URL atual para construir caminhos relativos
557
+ const currentOrigin = typeof window !== 'undefined' ? window.location.origin : '';
558
+ const currentPath = typeof window !== 'undefined' ? window.location.pathname : '';
556
559
  // Priorizar caminhos do node_modules primeiro
557
560
  const possiblePaths = [
558
- // Primeiro: tentar node_modules (prioridade máxima)
561
+ // Primeiro: tentar node_modules com caminhos absolutos (prioridade máxima)
559
562
  `/node_modules/web-audio-recorder-ts/lib/${filename}`,
563
+ `${currentOrigin}/node_modules/web-audio-recorder-ts/lib/${filename}`,
564
+ // Caminhos relativos do node_modules
560
565
  `./node_modules/web-audio-recorder-ts/lib/${filename}`,
561
566
  `../node_modules/web-audio-recorder-ts/lib/${filename}`,
562
567
  `../../node_modules/web-audio-recorder-ts/lib/${filename}`,
568
+ `../../../node_modules/web-audio-recorder-ts/lib/${filename}`,
569
+ // Com base no caminho atual
570
+ `${currentPath.replace(/\/[^/]*$/, '')}/node_modules/web-audio-recorder-ts/lib/${filename}`,
563
571
  // From dist (se os arquivos foram copiados para dist/lib)
564
572
  `/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
573
+ `${currentOrigin}/node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
565
574
  `./node_modules/web-audio-recorder-ts/dist/lib/${filename}`,
566
575
  // Auto-detected path (pode apontar para node_modules)
567
576
  getEncoderScriptUrl(filename),
568
577
  // Para desenvolvimento/demo: try public folder (Vite serves public/ at root)
569
578
  `/${filename}`,
579
+ `${currentOrigin}/${filename}`,
570
580
  // Direct lib paths (for development or custom setups)
571
581
  `/lib/${filename}`,
582
+ `${currentOrigin}/lib/${filename}`,
572
583
  `./lib/${filename}`,
573
584
  `../lib/${filename}`,
574
585
  // CDN or absolute paths (if configured)
575
586
  filename.startsWith('http') ? filename : null
576
587
  ].filter((path) => path !== null);
588
+ console.log(`[web-audio-recorder-ts] Searching for ${filename} in ${possiblePaths.length} possible paths...`);
577
589
  // Try each path
578
- for (const path of possiblePaths) {
590
+ for (let i = 0; i < possiblePaths.length; i++) {
591
+ const path = possiblePaths[i];
579
592
  try {
580
593
  const testUrl = path.startsWith('http')
581
594
  ? path
582
595
  : new URL(path, typeof window !== 'undefined' ? window.location.href : 'file://').href;
596
+ console.log(`[web-audio-recorder-ts] Trying path ${i + 1}/${possiblePaths.length}: ${path} -> ${testUrl}`);
583
597
  // Usar GET para verificar se é JavaScript válido (não HTML)
584
598
  const response = await fetch(testUrl, { method: 'GET', cache: 'no-cache' });
585
599
  if (response.ok) {
@@ -588,21 +602,30 @@
588
602
  const trimmedText = text.trim();
589
603
  // Se começar com '<', é HTML (404, etc) - pular este caminho
590
604
  if (trimmedText.startsWith('<')) {
591
- console.warn(`Path ${path} returned HTML instead of JavaScript, skipping...`);
605
+ console.warn(`[web-audio-recorder-ts] ❌ Path ${path} returned HTML instead of JavaScript (likely 404), skipping...`);
592
606
  continue;
593
607
  }
594
608
  // Se parece JavaScript, retornar este caminho
595
609
  if (trimmedText.includes('function') || trimmedText.includes('var') || trimmedText.includes('const') || trimmedText.includes('let') || trimmedText.length > 100) {
596
- console.log(`✅ Found encoder file at: ${path}`);
610
+ console.log(`[web-audio-recorder-ts] Found encoder file at: ${path}`);
597
611
  return path;
598
612
  }
613
+ else {
614
+ console.warn(`[web-audio-recorder-ts] ⚠️ Path ${path} returned content but doesn't look like JavaScript`);
615
+ }
616
+ }
617
+ else {
618
+ console.warn(`[web-audio-recorder-ts] ❌ Path ${path} returned status ${response.status} ${response.statusText}`);
599
619
  }
600
620
  }
601
621
  catch (e) {
622
+ console.warn(`[web-audio-recorder-ts] ❌ Error testing path ${path}:`, e);
602
623
  // Continue to next path
603
624
  continue;
604
625
  }
605
626
  }
627
+ console.error(`[web-audio-recorder-ts] ❌ Could not find ${filename} in any of the ${possiblePaths.length} paths tried`);
628
+ console.error(`[web-audio-recorder-ts] Tried paths:`, possiblePaths);
606
629
  return null;
607
630
  }
608
631
 
@@ -684,8 +707,14 @@
684
707
  // Tentar encontrar o arquivo automaticamente
685
708
  const foundPath = await findEncoderPath('OggVorbisEncoder.min.js');
686
709
  if (!foundPath) {
687
- throw new Error('Could not find OggVorbisEncoder.min.js. ' +
688
- 'Please provide the path manually or ensure the package is installed correctly.');
710
+ const errorMsg = 'Could not find OggVorbisEncoder.min.js automatically.\n\n' +
711
+ 'Please try one of the following:\n' +
712
+ '1. Provide the path manually: await loadOggVorbisEncoder("/path/to/OggVorbisEncoder.min.js")\n' +
713
+ '2. Copy files to public/: cp node_modules/web-audio-recorder-ts/lib/*.js public/\n' +
714
+ '3. Configure server to serve node_modules (see NUXT_USAGE.md)\n' +
715
+ '4. Check browser console for detailed path information';
716
+ console.error(errorMsg);
717
+ throw new Error(errorMsg);
689
718
  }
690
719
  scriptUrl = foundPath;
691
720
  }
@@ -876,8 +905,14 @@
876
905
  // Tentar encontrar o arquivo automaticamente
877
906
  const foundPath = await findEncoderPath('Mp3LameEncoder.min.js');
878
907
  if (!foundPath) {
879
- throw new Error('Could not find Mp3LameEncoder.min.js. ' +
880
- 'Please provide the path manually or ensure the package is installed correctly.');
908
+ const errorMsg = 'Could not find Mp3LameEncoder.min.js automatically.\n\n' +
909
+ 'Please try one of the following:\n' +
910
+ '1. Provide the path manually: await loadMp3LameEncoder("/path/to/Mp3LameEncoder.min.js")\n' +
911
+ '2. Copy files to public/: cp node_modules/web-audio-recorder-ts/lib/*.js public/\n' +
912
+ '3. Configure server to serve node_modules (see NUXT_USAGE.md)\n' +
913
+ '4. Check browser console for detailed path information';
914
+ console.error(errorMsg);
915
+ throw new Error(errorMsg);
881
916
  }
882
917
  scriptUrl = foundPath;
883
918
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "web-audio-recorder-ts",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "type": "module",
5
5
  "description": "TypeScript port of web-audio-recorder-js with full type support for WAV, OGG Vorbis, and MP3 audio recording",
6
6
  "main": "dist/index.cjs.js",