Skip to content

Commit

Permalink
fix: svg blur image aspect ratio (#259)
Browse files Browse the repository at this point in the history
* fix: svg blur image aspect ratio

* fix: video and poster expanding parent container

* example: add fullscreen background video
  • Loading branch information
luwes authored May 30, 2024
1 parent ef554c4 commit 1efddd1
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import * as fs from 'node:fs/promises';

import type { Metadata } from 'next';
import { DM_Sans, JetBrains_Mono } from 'next/font/google';
import Nav from './nav';
import SidebarNav from './sidebar-nav';
import './globals.css';
import Nav from '../nav';
import SidebarNav from '../sidebar-nav';
import '../globals.css';

const dmSans = DM_Sans({ subsets: ['latin'], variable: '--sans' });
const jetBrainsMono = JetBrains_Mono({ subsets: ['latin'], variable: '--mono' });
Expand All @@ -18,7 +18,7 @@ export const metadata: Metadata = {
};

const fileDir = dirname(fileURLToPath(import.meta.url));
const themeScript = await fs.readFile(`${fileDir}/theme-toggle.js`, 'utf-8');
const themeScript = await fs.readFile(`${fileDir}/../theme-toggle.js`, 'utf-8');

export default async function RootLayout({
children,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Metadata } from 'next';
import BackgroundVideo from 'next-video/background-video';
import countryClouds from '/videos/country-clouds.mp4?thumbnailTime=0';

export const metadata: Metadata = {
title: 'next-video - Background Video',
};

export default function Page() {
return (
<>
<BackgroundVideo
src={countryClouds}
disableTracking
maxResolution="720p"
style={{
aspectRatio: 'auto',
width: '100%',
height: '100%'
}}
>
<h1>next-video</h1>
<p>
A React component for adding video to your Next.js application. It extends both the
video element and your Next app with features for automatic video optimization.
</p>
</BackgroundVideo>
</>
);
}
25 changes: 25 additions & 0 deletions examples/default-provider/app/(fullscreen)/layout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type { Metadata } from 'next';
import { DM_Sans, JetBrains_Mono } from 'next/font/google';
import '../globals.css';

const dmSans = DM_Sans({ subsets: ['latin'], variable: '--sans' });
const jetBrainsMono = JetBrains_Mono({ subsets: ['latin'], variable: '--mono' });

export const metadata: Metadata = {
title: 'next-video',
description:
'Next Video solves the hard problems with embedding, storing, streaming, and customizing video in your Next.js app.',
};

export default function getLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en" suppressHydrationWarning className={`${dmSans.variable} ${jetBrainsMono.variable}`}>
<body style={{
display: 'block',
margin: 0,
height: '100vh',
overflow: 'hidden',
}}>{children}</body>
</html>
);
}
1 change: 1 addition & 0 deletions src/components/players/background-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const BackgroundPlayer = forwardRef((allProps: BackgroundPlayerProps, for
.next-video-bg-poster,
.next-video-bg-text {
grid-area: 1 / 1;
min-height: 0;
}
.next-video-bg-poster {
Expand Down
2 changes: 1 addition & 1 deletion src/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ function isExoticComponent(component: any) {
}

export function svgBlurImage(blurDataURL: string) {
const svg = /*html*/`<svg xmlns="http://www.w3.org/2000/svg"><filter id="b" color-interpolation-filters="sRGB"><feGaussianBlur stdDeviation="20"/><feComponentTransfer><feFuncA type="discrete" tableValues="1 1"/></feComponentTransfer></filter><g filter="url(#b)"><image width="100%" height="100%" href="${blurDataURL}"/></g></svg>`;
const svg = /*html*/`<svg xmlns="http://www.w3.org/2000/svg"><filter id="b" color-interpolation-filters="sRGB"><feGaussianBlur stdDeviation="20"/><feComponentTransfer><feFuncA type="discrete" tableValues="1 1"/></feComponentTransfer></filter><g filter="url(#b)"><image width="100%" height="100%" preserveAspectRatio="xMidYMid slice" href="${blurDataURL}"/></g></svg>`;
return svg.replace(/#/g, '%23');
}

0 comments on commit 1efddd1

Please sign in to comment.