Skip to content

Commit 00c3f18

Browse files
committed
feat: add mp3 support
1 parent 04629b0 commit 00c3f18

7 files changed

Lines changed: 20 additions & 5 deletions

File tree

apps/playground/src/components/Editor/Editor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export const Editor = () => {
146146
<FileUploadDialog
147147
accept={{
148148
'application/json': ['.json'],
149+
'audio/mpeg': ['.mp3'],
149150
'image/jpeg': ['.jpg', '.jpeg'],
150151
'image/png': ['.png'],
151152
'image/webp': ['.webp'],

apps/playground/src/components/Editor/EditorFileIcon.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,14 @@ export const EditorFileIcon = ({ filename }: EditorFileIconProps) => {
100100
/>
101101
</svg>
102102
))
103+
.with('.mp3', () => (
104+
<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
105+
<path
106+
d="M16 2a14 14 0 1 0 14 14A14 14 0 0 0 16 2m6 10h-4v8a4 4 0 1 1-4-4 3.96 3.96 0 0 1 2 .555V8h6Z"
107+
fill="#ef5350"
108+
/>
109+
</svg>
110+
))
103111
.with('.html', () => (
104112
<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
105113
<path

apps/playground/src/instruments/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const textFiles: { [key: string]: string } = import.meta.glob('./**/*.{css,js,js
1313
query: '?raw'
1414
});
1515

16-
const binaryFiles: { [key: string]: string } = import.meta.glob('./**/*.{jpg,jpeg,png,webp,mp4}', {
16+
const binaryFiles: { [key: string]: string } = import.meta.glob('./**/*.{jpg,jpeg,png,webp,mp4,mp3}', {
1717
eager: true,
1818
import: 'default',
1919
query: '?url'

apps/playground/src/utils/file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function inferFileType(filename: string): FileType | null {
1111
.with('.css', () => 'css' as const)
1212
.with(P.union('.js', '.jsx'), () => 'javascript' as const)
1313
.with(P.union('.ts', '.tsx'), () => 'typescript' as const)
14-
.with(P.union('.jpeg', '.jpg', '.png', '.webp', '.mp4'), () => 'asset' as const)
14+
.with(P.union('.jpeg', '.jpg', '.png', '.webp', '.mp3', '.mp4'), () => 'asset' as const)
1515
.with(P.union('.html', '.svg'), () => 'html' as const)
1616
.with('.json', () => 'json' as const)
1717
.with(null, () => null)
@@ -31,7 +31,7 @@ export function editorFileToInput(file: EditorFile): BundlerInput {
3131
}
3232

3333
export function isBase64EncodedFileType(filename: string) {
34-
return ['.jpeg', '.jpg', '.mp4', '.png', '.webp'].includes(extractInputFileExtension(filename)!);
34+
return ['.jpeg', '.jpg', '.mp3', '.mp4', '.png', '.webp'].includes(extractInputFileExtension(filename)!);
3535
}
3636

3737
export function resolveIndexFile(files: EditorFile[]) {

packages/instrument-bundler/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type BundlerInputFileExtension =
66
| '.js'
77
| '.json'
88
| '.jsx'
9+
| '.mp3'
910
| '.mp4'
1011
| '.png'
1112
| '.svg'

packages/instrument-bundler/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type { BundlerInputFileExtension } from './types.js';
66
import type { Loader } from './vendor/esbuild.js';
77

88
export function extractInputFileExtension(filename: string) {
9-
const ext = /\.(css|html|jpeg|jpg|js|jsx|json|mp4|png|svg|ts|tsx|webp)$/i.exec(filename)?.[0];
9+
const ext = /\.(css|html|jpeg|jpg|js|jsx|json|mp3|mp4|png|svg|ts|tsx|webp)$/i.exec(filename)?.[0];
1010
return (ext ?? null) as BundlerInputFileExtension | null;
1111
}
1212

@@ -19,7 +19,7 @@ export function inferLoader(filename: string): Loader {
1919
.with('.json', () => 'json' as const)
2020
.with('.ts', () => 'ts' as const)
2121
.with('.tsx', () => 'tsx' as const)
22-
.with(P.union('.jpeg', '.jpg', '.png', '.svg', '.webp', '.mp4'), () => 'dataurl' as const)
22+
.with(P.union('.jpeg', '.jpg', '.png', '.svg', '.webp', '.mp3', '.mp4'), () => 'dataurl' as const)
2323
.with(null, () => {
2424
throw new InstrumentBundlerError(`Cannot infer loader due to unexpected extension for filename: ${filename}`);
2525
})

runtime/v1/env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ declare module '*.mp4' {
3333
export default src;
3434
}
3535

36+
declare module '*.mp3' {
37+
const src: string;
38+
export default src;
39+
}
40+
3641
declare module '*.json' {
3742
const src: any;
3843
export default src;

0 commit comments

Comments
 (0)