Skip to content

Commit

Permalink
Upgrade lighter for edge support
Browse files Browse the repository at this point in the history
  • Loading branch information
pomber committed Jul 17, 2023
1 parent c8e1fce commit 4f7ce9f
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .changeset/wet-singers-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"bright": patch
---

Upgrade lighter for edge support
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"watch": "tsup src/index.tsx --format esm,cjs --watch --dts"
},
"dependencies": {
"@code-hike/lighter": "0.6.6",
"@code-hike/lighter": "0.8.1",
"server-only": "^0.0.1"
},
"devDependencies": {
Expand Down
34 changes: 18 additions & 16 deletions lib/src/code.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Theme, annotatedHighlight } from "@code-hike/lighter"
import {
Theme,
getThemeColorsSync,
highlight as light,
} from "@code-hike/lighter"
import { TitleBar } from "./title"
import { LinesComponent } from "./lines"
import { BrightProps, CodeProps } from "./types"
Expand All @@ -23,12 +27,9 @@ async function highlight(props: CodeProps): Promise<BrightProps> {
}

const { code, lang, theme, annotations } = props
const { lines, colors } = await annotatedHighlight(
code,
lang,
theme,
annotations
)

const { lines } = await light(code, lang, theme, { annotations })
const colors = getThemeColorsSync(theme)

const brightProps: BrightProps = {
...props,
Expand Down Expand Up @@ -56,15 +57,16 @@ export function Root(props: BrightProps) {
borderRadius: "4px",
overflow: "hidden",
margin: "1em 0",
["--selection-background" as any]: colors.selectionBackground,
["--line-number-color" as any]: colors.lineNumberForeground,
["--tab-border" as any]: colors.tabBorder,
["--tab-background" as any]: colors.activeTabBackground,
["--tab-color" as any]: colors.activeTabForeground,
["--inactive-tab-background" as any]: colors.inactiveTabBackground,
["--inactive-tab-color" as any]: colors.inactiveTabForeground,
["--tab-top-border" as any]: colors.activeTabTopBorder,
["--tab-bottom-border" as any]: colors.activeTabBorder,
["--selection-background" as any]: colors.editor.selectionBackground,
["--line-number-color" as any]: colors.editorLineNumber.foreground,

["--tab-border" as any]: colors.tab.border,
["--tab-background" as any]: colors.tab.activeBackground,
["--tab-color" as any]: colors.tab.activeForeground,
["--inactive-tab-background" as any]: colors.tab.inactiveBackground,
["--inactive-tab-color" as any]: colors.tab.inactiveForeground,
["--tab-top-border" as any]: colors.tab.activeBorderTop,
["--tab-bottom-border" as any]: colors.tab.activeBorder,
colorScheme: colors.colorScheme,
...style,
}}
Expand Down
9 changes: 4 additions & 5 deletions lib/src/title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import React from "react"
import { BrightProps } from "./types"

export function TitleBar(props: BrightProps) {
const { activeTabForeground, editorGroupHeaderBackground, tabsBorder } =
props.colors
const colors = props.colors
const { TitleBarContent } = props
const elementProps = {
className: props.titleClassName,
style: {
background: editorGroupHeaderBackground,
color: activeTabForeground,
background: colors.editorGroupHeader.tabsBackground,
color: colors.tab.activeForeground,
position: "relative" as const,
display: "flex",
},
Expand All @@ -24,7 +23,7 @@ export function TitleBar(props: BrightProps) {
left: 0,
width: "100%",
pointerEvents: "none",
background: tabsBorder,
background: colors.tab.border,
height: 1,
zIndex: 9,
}}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
Lines,
Tokens,
Annotation,
ThemeColors,
getThemeColorsSync,
} from "@code-hike/lighter"
import brightComponents from "./components"
import type { ReactNode } from "react"
Expand Down Expand Up @@ -105,7 +105,7 @@ export type CodeProps = Prettify<
// afterHighlight
export type BrightProps = Prettify<
Omit<CodeProps, "subProps"> & {
colors: Prettify<ThemeColors>
colors: Prettify<ReturnType<typeof getThemeColorsSync>>
lines: Lines
lineCount: number

Expand Down
2 changes: 2 additions & 0 deletions web/app/test/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ export default function Page() {
</main>
)
}

export const runtime = "edge"
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,10 @@
human-id "^1.0.2"
prettier "^2.7.1"

"@code-hike/lighter@0.6.6":
version "0.6.6"
resolved "https://registry.yarnpkg.com/@code-hike/lighter/-/lighter-0.6.6.tgz#72f1b93dceacc40022a0c2c0f154363e2595a4ba"
integrity sha512-dLkSpowP4NaWDUgay3Mebb8V+wYqVGRD+Tl8wSfWdtIH0z4OUU3UznSsmvvGpCgkdUIF5DhOPRGRowqkNWQsrg==
"@code-hike/lighter@0.8.1":
version "0.8.1"
resolved "https://registry.yarnpkg.com/@code-hike/lighter/-/lighter-0.8.1.tgz#3bde8e1eea3900132359e37c05bae5ac96ddd53c"
integrity sha512-St4rPmB7C2EWmAK1sAbvD3lZeM7UDInVDMjQDzEDsu4Q3B3AqF25vXedQK51U0UO0MCOASgBBdTiNwvJAfIqMQ==

"@esbuild/[email protected]":
version "0.15.18"
Expand Down

0 comments on commit 4f7ce9f

Please sign in to comment.