diff --git a/.changeset/hot-views-judge.md b/.changeset/hot-views-judge.md new file mode 100644 index 0000000000..3840961001 --- /dev/null +++ b/.changeset/hot-views-judge.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Add cover image background mode and masks diff --git a/packages/gitbook/src/components/DocumentView/Heading.tsx b/packages/gitbook/src/components/DocumentView/Heading.tsx index 68013e9ea0..0d41ea192a 100644 --- a/packages/gitbook/src/components/DocumentView/Heading.tsx +++ b/packages/gitbook/src/components/DocumentView/Heading.tsx @@ -53,6 +53,7 @@ export function Heading(props: BlockProps) { 'justify-self-start', 'max-w-full', 'break-words', + 'page-cover-background:text-contrast-cover', getTextAlignment(block.data.align), textStyle.lineHeight )} diff --git a/packages/gitbook/src/components/DocumentView/Paragraph.tsx b/packages/gitbook/src/components/DocumentView/Paragraph.tsx index 9ba46fa59f..bb575893ea 100644 --- a/packages/gitbook/src/components/DocumentView/Paragraph.tsx +++ b/packages/gitbook/src/components/DocumentView/Paragraph.tsx @@ -14,7 +14,14 @@ export function Paragraph(props: BlockProps) { 'has-[.button,input]:flex has-[.button,input]:flex-wrap has-[.button,input]:gap-2 has-[.button,input]:items-center'; return ( -

+

); diff --git a/packages/gitbook/src/components/PageAside/PageAside.tsx b/packages/gitbook/src/components/PageAside/PageAside.tsx index 2c12d3ba3b..e25258a640 100644 --- a/packages/gitbook/src/components/PageAside/PageAside.tsx +++ b/packages/gitbook/src/components/PageAside/PageAside.tsx @@ -95,9 +95,11 @@ export function PageAside(props: { 'page-api-block:page-has-outline:min-[96rem]:border-l-0', 'page-api-block:page-has-outline:min-[96rem]:pl-8', - 'hydrated:site-background', // Only add a background once the element is positioned correctly to prevent overlapping the page cover + 'layout-default:max-xl:site-background', + 'layout-wide:max-3xl:site-background', 'text-tint', - 'contrast-more:text-tint-strong' + 'contrast-more:text-tint-strong', + 'xl:page-cover-background:text-contrast-cover' )} >
diff --git a/packages/gitbook/src/components/PageAside/ScrollSectionsList.tsx b/packages/gitbook/src/components/PageAside/ScrollSectionsList.tsx index eee74203bf..b61714cf9e 100644 --- a/packages/gitbook/src/components/PageAside/ScrollSectionsList.tsx +++ b/packages/gitbook/src/components/PageAside/ScrollSectionsList.tsx @@ -91,6 +91,7 @@ export function ScrollSectionsList({ sections }: { sections: DocumentSection[] } 'sidebar-list-line:border-l-2', 'border-transparent', 'sidebar-list-line:-left-px', + 'xl:page-cover-background:text-contrast-cover', section.depth > 1 && [ 'subitem', diff --git a/packages/gitbook/src/components/PageBody/PageBody.tsx b/packages/gitbook/src/components/PageBody/PageBody.tsx index dd2056435f..ef402ef6cd 100644 --- a/packages/gitbook/src/components/PageBody/PageBody.tsx +++ b/packages/gitbook/src/components/PageBody/PageBody.tsx @@ -82,6 +82,7 @@ export function PageBody(props: { 'py-8', 'layout-wide:no-sidebar:lg:max-xl:pb-20', // Add padding to prevent overlap of minimised trademark '@container', + 'flex flex-col', CONTENT_STYLE, pageHasToc ? 'page-has-toc' : 'page-no-toc', wideLayout ? 'layout-wide' : 'layout-default' @@ -106,7 +107,7 @@ export function PageBody(props: { { + if (!height) { + return DEFAULT_RESPONSIVE_COVER_CUTOFF; + } + + let total = height; + if (context.customization.announcement?.enabled) { + total += 68; + } + if (context.customization.header.preset !== CustomizationHeaderPreset.None) { + total += 64; + } + if (context.visibleSections && context.visibleSections.list.length > 1) { + total += 45; + } + return `${total}px`; + }; + + as = 'background'; + const [resolved, resolvedDark] = await Promise.all([ cover.ref ? resolveContentRef(cover.ref, context) : null, cover.refDark ? resolveContentRef(cover.refDark, context) : null, @@ -79,56 +104,71 @@ export async function PageCover(props: { assert(light, 'Light image should be defined'); return ( -
- -
+ <> + +
+ +
+ ); } diff --git a/packages/gitbook/src/components/PageBody/PageCoverImage.tsx b/packages/gitbook/src/components/PageBody/PageCoverImage.tsx index eb2190b744..ae2d18c4bf 100644 --- a/packages/gitbook/src/components/PageBody/PageCoverImage.tsx +++ b/packages/gitbook/src/components/PageBody/PageCoverImage.tsx @@ -24,10 +24,11 @@ interface PageCoverImageProps { y: number; // Only if the `height` was customized by the user (and thus defined), we use it to set the cover's height and skip the default behaviour of fixed aspect-ratio. height: number | undefined; + mask?: 'none' | 'radial'; } export function PageCoverImage(props: PageCoverImageProps) { - const { imgs, y, height } = props; + const { imgs, y, height, mask } = props; const { containerRef, objectPositionY, isLoading } = useCoverPosition(imgs, y); if (isLoading) { @@ -53,6 +54,11 @@ export function PageCoverImage(props: PageCoverImageProps) { : `${PAGE_COVER_SIZE.width}/${PAGE_COVER_SIZE.height}`, objectPosition: `50% ${objectPositionY}%`, height, // if no height is passed, no height will be set. + maskComposite: 'intersect', + maskImage: + mask === 'radial' + ? 'radial-gradient(200% 200% at 50% -100%, black 70%, rgba(0,0,0,0.85) 77.5%, rgba(0,0,0,0.6) 85%, rgba(0,0,0,0.1) 96.25%, transparent 100%), linear-gradient(to left, black 60%, rgba(0,0,0,0.8) 75%, rgba(0,0,0,0.1) 95%, transparent 100%), linear-gradient(to right, black 60%, rgba(0,0,0,0.8) 75%, rgba(0,0,0,0.1) 95%, transparent 100%)' + : undefined, }} /> {imgs.dark && ( @@ -69,6 +75,11 @@ export function PageCoverImage(props: PageCoverImageProps) { : `${PAGE_COVER_SIZE.width}/${PAGE_COVER_SIZE.height}`, objectPosition: `50% ${objectPositionY}%`, height, // if no height is passed, no height will be set. + maskComposite: 'intersect', + maskImage: + mask === 'radial' + ? 'radial-gradient(200% 200% at 50% -100%, black 70%, rgba(0,0,0,0.85) 77.5%, rgba(0,0,0,0.6) 85%, rgba(0,0,0,0.1) 96.25%, transparent 100%), linear-gradient(to left, black 60%, rgba(0,0,0,0.8) 75%, rgba(0,0,0,0.1) 95%, transparent 100%), linear-gradient(to right, black 60%, rgba(0,0,0,0.8) 75%, rgba(0,0,0,0.1) 95%, transparent 100%)' + : undefined, }} /> )} diff --git a/packages/gitbook/src/components/PageBody/PageHeader.tsx b/packages/gitbook/src/components/PageBody/PageHeader.tsx index 8c2cdfde6c..351d3c8a2e 100644 --- a/packages/gitbook/src/components/PageBody/PageHeader.tsx +++ b/packages/gitbook/src/components/PageBody/PageHeader.tsx @@ -58,7 +58,10 @@ export async function PageHeader(props: {
{hasAncestors && ( -