Skip to content

Commit 6a4b708

Browse files
committed
feat: support importing mp4 in instruments
1 parent be0ffb4 commit 6a4b708

7 files changed

Lines changed: 21 additions & 6 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ export const Editor = () => {
150150
'image/webp': ['.webp'],
151151
'text/css': ['.css'],
152152
'text/html': ['.html'],
153-
'text/plain': ['.js', '.jsx', '.ts', '.tsx']
153+
'text/plain': ['.js', '.jsx', '.ts', '.tsx'],
154+
'video/mp4': ['.mp4']
154155
}}
155156
isOpen={isFileUploadDialogOpen}
156157
setIsOpen={setIsFileUploadDialogOpen}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ export const EditorFileIcon = ({ filename }: EditorFileIconProps) => {
9292
/>
9393
</svg>
9494
))
95+
.with('.mp4', () => (
96+
<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
97+
<path
98+
d="m24 6 2 6h-4l-2-6h-3l2 6h-4l-2-6h-3l2 6H8L6 6H5a3 3 0 0 0-3 3v14a3 3 0 0 0 3 3h22a3 3 0 0 0 3-3V6Z"
99+
fill="#ff9800"
100+
/>
101+
</svg>
102+
))
95103
.with('.html', () => (
96104
<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg">
97105
<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}', {
16+
const binaryFiles: { [key: string]: string } = import.meta.glob('./**/*.{jpg,jpeg,png,webp,mp4}', {
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'), () => 'asset' as const)
14+
.with(P.union('.jpeg', '.jpg', '.png', '.webp', '.mp4'), () => 'asset' as const)
1515
.with(P.union('.html', '.svg'), () => 'html' as const)
1616
.with(null, () => null)
1717
.exhaustive();
@@ -30,7 +30,7 @@ export function editorFileToInput(file: EditorFile): BundlerInput {
3030
}
3131

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

3636
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
@@ -5,6 +5,7 @@ export type BundlerInputFileExtension =
55
| '.jpg'
66
| '.js'
77
| '.jsx'
8+
| '.mp4'
89
| '.png'
910
| '.svg'
1011
| '.ts'

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|png|svg|ts|tsx|webp)$/i.exec(filename)?.[0];
9+
const ext = /\.(css|html|jpeg|jpg|js|jsx|mp4|png|svg|ts|tsx|webp)$/i.exec(filename)?.[0];
1010
return (ext ?? null) as BundlerInputFileExtension | null;
1111
}
1212

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

runtime/v1/env.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ declare module '*.webp' {
2828
export default src;
2929
}
3030

31+
declare module '*.mp4' {
32+
const src: string;
33+
export default src;
34+
}
35+
3136
declare module 'react/jsx-runtime' {
3237
export * from '/runtime/v1/react@18.x/jsx-runtime';
3338
}

0 commit comments

Comments
 (0)