- Installation
- Usage
- Extend / Customize Viewer
- Schematics
- Development
- License
Install the package using npm:
npm install @yuuvis/media-viewer --save
This library provides multiple viewers for displaying various media types based on their MIME types.
This is a convenience wrapper for all types that selects the appropriate viewer based on the provided type.
{
type: string | unknown; // Required
id: string; // Required
metadata: T;
src: string | null;
}
import { YuvMediaViewerComponent } from '@yuuvis/media-viewer';
@Component({
...
imports: [YuvMediaViewerComponent],
template: `<yuv-media-viewer [id]="id()" [src]="src()" [type]="type()" [metadata]="metadata()"></yuv-media-viewer>`
})
...
id = signal(UUID);
src = signal('https://path.to.the.document.com');
type = signal('application/vnd.openxmlformats-officedocument.wordprocessingml.document');
metadata = signal({});
Audio playback is handled using the native HTMLAudioElement, enhanced with a visualizer.
{
"mimeType": ["audio/mp3", "audio/webm", "audio/ogg", "audio/mpeg"],
"type": "AUDIO"
}
ImageMetadata {
mode?: 'oscilloscope' | 'frequency';
} // Default: 'frequency'
{
type: string;
id: string; // Required
metadata: AudioMetadata;
src: string; // Required
}
import { AudioComponent } from '@yuuvis/media-viewer';
@Component({
...
imports: [AudioComponent],
template: `<yuv-audio [id]="id()" [src]="src()" [type]="type()"></yuv-audio>`
})
...
id = signal(UUID);
src = signal('source');
type = signal('audio/mp3');
The UI renders the parsed email and allows users to select and view attachments (beta).
{
"mimeType": ["message/rfc822", "application/vnd.ms-outlook"],
"type": "EMAIL"
}
EmailMetadata {
type: 'EMAIL';
header: Email;
attachments: string[];
theme: string;
}
{
type: string;
id: string; // Required
metadata: EmailMetadata;
src: string; // Required
}
import { MailComponent } from '@yuuvis/media-viewer';
@Component({
...
imports: [MailComponent],
template: `<yuv-mail [id]="id()" [src]="src()" [type]="type()" [metadata]="metadata()"></yuv-mail>`
})
...
id = signal(UUID);
src = signal('source');
type = signal('message/rfc822');
metadata = signal(this.emailMetadata);
The image leverages the native HTMLImageElement and extends it with zoom and rotate capabilities, while also incorporating accessibility features.
{
"mimeType": ["image/tiff", "image/jpeg", "image/png", "image/apng", "image/gif", "image/svg+xml", "image/webp"],
"type": "IMAGE"
}
{
type: string;
id: string; // Required
metadata: T;
src: string; // Required
}
import { ImageComponent } from '@yuuvis/media-viewer';
@Component({
...
imports: [ImageComponent],
template: `<yuv-image [id]="id()" [src]="src()" [type]="type()" [metadata]="metadata()"></yuv-image>`
})
...
id = signal(UUID);
src = signal('source');
type = signal('image/jpeg');
metadata = signal({ disableMenu: false })
To properly use the Office viewer, a backend integrated with an MS Office 365 solution is required.
{
"mimeType": [
"application/msword",
"application/vnd.ms-excel",
"application/vnd.ms-powerpoint",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"application/vnd.openxmlformats-officedocument.wordprocessingml.template",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
"application/vnd.openxmlformats-officedocument.spreadsheetml.template",
"application/vnd.openxmlformats-officedocument.presentationml.presentation",
"application/vnd.openxmlformats-officedocument.presentationml.template",
"application/vnd.openxmlformats-officedocument.presentationml.slideshow",
"application/vnd.ms-word.document.macroEnabled.12",
"application/vnd.ms-word.template.macroEnabled.12",
"application/vnd.ms-excel.sheet.macroEnabled.12",
"application/vnd.ms-excel.template.macroEnabled.12",
"application/vnd.ms-excel.addin.macroEnabled.12",
"application/vnd.ms-excel.sheet.binary.macroEnabled.12",
"application/vnd.ms-powerpoint.addin.macroEnabled.12",
"application/vnd.ms-powerpoint.presentation.macroEnabled.12",
"application/vnd.ms-powerpoint.template.macroEnabled.12",
"application/vnd.ms-powerpoint.slideshow.macroEnabled.12"
],
"type": "OFFICE"
}
OfficeMetadata {
type: 'office';
id: string;
dmsObject: Record<string, unknown>;
editable?: boolean;
user: MetadatUser;
}
{
type: string;
id: string(required);
metadata: OfficeMetadata;
src: string(required);
}
import { OfficeComponent } from '@yuuvis/media-viewer';
@Component({
...
imports: [OfficeComponent],
template: `<yuv-office [id]="id()" [src]="src()" [type]="type()" [metadata]="metadata()"></yuv-office>`
})
...
id = signal(UUID)
src = signal('source')
type = signal('application/vnd.openxmlformats-officedocument.wordprocessingml.document')
metadata = signal({id:UUID,dmsObject:dmsObject, user:currentUser})
The PDF viewer is powered by ngx-extended-pdf-viewer.
{
"mimeType": ["application/pdf"],
"type": "PDF"
}
{
type: string;
id: string(required);
metadata: PdfMetadata;
src: string(required);
}
import { PdfComponent } from '@yuuvis/media-viewer';
@Component({
...
imports: [PdfComponent],
template: `<yuv-pdf [id]="id()" [src]="src()" [type]="type()" [metadata]="metadata()"></yuv-pdf>`,
})
...
id = signal(UUID)
src = signal('source')
type = signal('application/pdf')
metadata = signal({theme:'dark'})
// You might need to add
{
"glob": "**/*",
"input": "node_modules/ngx-extended-pdf-viewer/bleeding-edge/",
"output": "/bleeding-edge/"
}
The Text viewer is powered by ngx-monaco-editor-v2
{
"mimeType": [
"application/json",
"text/plain",
"text/xml",
"text/java",
"text/javascript",
"application/javascript",
"text/html",
"text/markdown",
"text/x-web-markdown",
"text/x-markdown"
],
"type": "TEXT"
}
{
type: string;
id: string(required);
metadata: {
theme: 'light';
}
src: string(required);
}
import { TextComponent } from '@yuuvis/media-viewer';
@Component({
...
imports: [TextComponent],
template: `<yuv-text [id]="id()" [src]="src()" [type]="type()" [metadata]="metadata()"></yuv-text>`,
})
...
id = signal(UUID)
src = signal('source')
type = signal('text/xml')
metadata = signal({theme:'dark'})
Video utilizes the native HTMLVideoElement.
{
"mimeType": ["video/mp4", "video/webm", "video/ogg", "application/ogg"],
"type": "VIDEO"
}
{
id: string(required);
src: string(required);
type: string;
}
import { VideoComponent } from '@yuuvis/media-viewer';
@Component({
...
imports: [VideoComponent],
template: `<yuv-video [id]="id()" [src]="src()" [type]="type()"></yuv-video>`,
})
...
id = signal(UUID)
src = signal('source')
type = signal('video/mp4')
Array<{ mimeType: Array<sting>; text: string }>;
If you prefer to use your own viewer for a specific type, you can override the default configuration as shown below:
import { MediaViewerService } from '@yuuvis/media-viewer';
...
readonly #mediaViewerService = inject(MediaViewerService);
constructor() {
this.#mediaViewerService.setCustomViewer([{'AUDIO': MyCustomImageViewerComponent}]);
}
import { MediaViewerService } from '@yuuvis/media-viewer';
...
readonly #mediaViewerService = inject(MediaViewerService);
constructor() {
this.#mediaViewerService.resetViewers();
}
To customize the supported MIME types for a specific type, you can override the default configuration.
import { MediaViewerService } from '@yuuvis/media-viewer';
...
readonly #mediaViewerService = inject(MediaViewerService);
constructor() {
this.#mediaViewerService.setViewers({
mimeType: ['image/jpeg', 'image/png'],
type: 'IMAGE'
});
}
If you have a custom media type, you can easily add it to the configuration.
import { MediaViewerService } from '@yuuvis/media-viewer';
...
readonly #mediaViewerService = inject(MediaViewerService);
constructor() {
this.#mediaViewerService.setViewers({
mimeType: ['fancy/stuff'],
type: 'FANCY'
});
this.#mediaViewerService.setCustomViewer([{'FANCY': MyFancyViewerComponent}]);
}
or
import { MediaViewerService } from '@yuuvis/media-viewer';
...
readonly #mediaViewerService = inject(MediaViewerService);
constructor() {
this.#mediaViewerService.extendViewer<MyFancyViewerComponent>({ mimeType: ['fancy/stuff'], type: 'FANCY' }, MyFancyViewerComponent );
}
For development, you can set the configuration globally. For the Office viewer, you must specify the path to the Office 365 instance.
provideMediaViewer(environment, { office: { defaultHost: 'https://path.to.office-365.org' } });
MIT