Skip to content

Commit

Permalink
Update JoyPixels (#2619)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge authored Dec 12, 2024
1 parent 60e3500 commit bb208ab
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 35 deletions.
27 changes: 27 additions & 0 deletions packages/gitbook/src/components/RootLayout/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,30 @@ html {
html.dark {
color-scheme: dark light;
}

/* Emojis */

[class*='emoji'] {
font-family: var(--font-emojis-sbix);
}

/* Safari Only CSS here */
_::-webkit-full-page-media,
_:future,
:root [class*='emoji'] {
font-family: var(--font-emojis-sbix);
}

/* Chrome Only CSS here */
@media screen and (-webkit-min-device-pixel-ratio: 0) {
.emoji {
font-family: var(--font-emojis-colrv1);
}
}

/* Firefox Only CSS here */
@-moz-document url-prefix() {
.emoji {
font-family: var(--font-emojis-colrv1);
}
}
36 changes: 25 additions & 11 deletions packages/gitbook/src/components/primitives/Emoji/Emoji.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,46 @@ import localFont from 'next/font/local';
import { getEmojiForCode } from '@/lib/emojis';
import { ClassValue, tcls } from '@/lib/tailwind';

import './emoji.css';

/* Load the 3 variants of the font as CSS variables and let the emoji.css decide on the best one to use */

const svgFont = localFont({
src: './svg.woff2',
/**
COLRv1 font.
- lightweight, top quality
- widely supported by modern browsers
- currently not by Safari (or iOS)
*/
const colrv1Font = localFont({
src: './joypixels-colrv1.woff2',
preload: false,
variable: '--font-emojis-svg',
variable: '--font-emojis-colrv1',
});

/**
SBIX font.
- narrowly supported
- currently required for Safari (or iOS)
- provide alternative font-family name (see below)
*/
const sbixFont = localFont({
src: './sbix.woff2',
src: './joypixels-sbix.woff2',
preload: false,
variable: '--font-emojis-sbix',
});

/**
CBDT font.
- widely supported
- currently not by Safari (or iOS)
- retain for legacy browser support
*/
const cbdtFont = localFont({
src: './cbdt.woff2',
src: './joypixels-cbdt.woff2',
preload: false,
variable: '--font-emojis-cbdt',
});

/**
* Class name to set on the <html> tag to use the emoji font.
*/
export const emojiFontClassName = [svgFont.variable, sbixFont.variable, cbdtFont.variable].join(
export const emojiFontClassName = [colrv1Font.variable, sbixFont.variable, cbdtFont.variable].join(
' ',
);

Expand All @@ -40,5 +54,5 @@ export async function Emoji(props: { code: string; style?: ClassValue }) {
const { code, style } = props;

const fallback = getEmojiForCode(code);
return <span className={'emoji ' + tcls(style)}>{fallback}</span>;
return <span className={tcls('emoji', style)}>{fallback}</span>;
}
24 changes: 0 additions & 24 deletions packages/gitbook/src/components/primitives/Emoji/emoji.css

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit bb208ab

Please sign in to comment.