Skip to content

Commit

Permalink
feat: begin adding line number support but stopped because of strange…
Browse files Browse the repository at this point in the history
… line wrapping issues
  • Loading branch information
cmgriffing committed Nov 26, 2024
1 parent d8fcf7f commit 166a9ca
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
61 changes: 57 additions & 4 deletions playgrounds/app/src/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export default function Editor(props: EditorProps) {
backgroundGradientColorStart: props.snippetSettings.bgGradientColorStart,
backgroundGradientColorEnd: props.snippetSettings.bgGradientColorEnd,
backgroundGradientDirection: props.snippetSettings.bgGradientDirection,
lineNumberColor: props.snippetSettings.lineNumberColor,
},
},
)
Expand Down Expand Up @@ -352,6 +353,50 @@ export default function Editor(props: EditorProps) {
collapsible
defaultValue={['background', 'layout', 'shadow', 'font']}
>
<AccordionItem value="background">
<AccordionTrigger>Line Numbers</AccordionTrigger>
<AccordionContent>
<div class="flex flex-col gap-4">
<div class="flex flex-row items-center justify-between">
<Label
for="line-numbers-checkbox"
onClick={() =>
props.setSnippetSettings(
'lineNumbersEnabled',
!props.snippetSettings.lineNumbersEnabled,
)
}
>
Show Line Numbers
</Label>
<Checkbox
id="line-numbers-checkbox"
checked={props.snippetSettings.lineNumbersEnabled}
onChange={() => {
props.setSnippetSettings(
'lineNumbersEnabled',
!props.snippetSettings.lineNumbersEnabled,
)
}}
/>
</div>
<div class="flex flex-row items-center justify-between">
<Label for="line-number-color" class="font-normal">
Color
</Label>
<input
id="line-number-color"
class="h-6 w-6 rounded"
type="color"
value={props.snippetSettings.lineNumberColor}
onInput={e => {
props.setSnippetSettings('lineNumberColor', e.target.value)
}}
/>
</div>
</div>
</AccordionContent>
</AccordionItem>
<AccordionItem value="background">
<AccordionTrigger>Background</AccordionTrigger>
<AccordionContent>
Expand Down Expand Up @@ -563,7 +608,7 @@ export default function Editor(props: EditorProps) {
}}
/>
</div>

//
<div class="flex flex-row items-center justify-between">
<Label for="shadow-color-input" class="font-normal">
Color
Expand Down Expand Up @@ -839,7 +884,7 @@ export default function Editor(props: EditorProps) {
options={{
duration: 800,
stagger: 0,
lineNumbers: false,
lineNumbers: props.snippetSettings.lineNumbersEnabled,
}}
/>
{/* The hidden shiki that we use to generate the magic move elements */}
Expand All @@ -859,7 +904,7 @@ export default function Editor(props: EditorProps) {
options={{
duration: 800,
stagger: 0,
lineNumbers: false,
lineNumbers: props.snippetSettings.lineNumbersEnabled,
onAnimationStart: async (elements, maxContainerDimensions) => {
if (elements.length === 0) {
return
Expand Down Expand Up @@ -1178,6 +1223,7 @@ async function createAnimationFrame(
height: number = 100,
config: AnimationFrameConfig,
) {
console.log({ elements })
const { yPadding, xPadding } = config.layout
const { shadowEnabled, shadowOffsetY, shadowBlur, shadowColor, shadowOpacity } = config.shadow
const {
Expand All @@ -1189,6 +1235,7 @@ async function createAnimationFrame(
backgroundGradientColorStart,
backgroundGradientColorEnd,
backgroundGradientDirection,
lineNumberColor,
} = config.styling

const canvas = document.createElement('canvas')
Expand Down Expand Up @@ -1260,10 +1307,16 @@ async function createAnimationFrame(
const opacity = interpolate(frame, [0, animationFrames], [el.opacity.start, el.opacity.end], {
easing: Easing.inOut(Easing.quad),
})

let fallbackColor = 'rgba(0,0,0,0)'
if (el.el.classList.contains('shiki-magic-move-line-number')) {
fallbackColor = lineNumberColor || '#aaaaaa'
}

const color = interpolateColors(
frame,
[0, animationFrames],
[el.color.start || 'rgba(0,0,0,0)', el.color.end || 'rgba(0,0,0,0)'],
[el.color.start || fallbackColor, el.color.end || fallbackColor],
)

ctx.font = `${fontSize} ${fontFamily}`
Expand Down
2 changes: 2 additions & 0 deletions playgrounds/app/src/routes/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export default function Home() {
theme: 'nord',
fontSize: 16,
fontFamily: 'Fira Code',
lineNumbersEnabled: true,
lineNumberColor: '#aaaaaa',
}),
{ name: 'snippetSettings' },
)
Expand Down
3 changes: 3 additions & 0 deletions playgrounds/app/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export interface SnippetSettings {
theme: string
fontSize: number
fontFamily: string
lineNumbersEnabled: boolean
lineNumberColor: string
}

export interface Snippet extends SnippetSettings {
Expand Down Expand Up @@ -58,6 +60,7 @@ export interface AnimationFrameStyling {
backgroundGradientColorStart: string
backgroundGradientColorEnd: string
backgroundGradientDirection: number
lineNumberColor: string
}

export interface AnimationFrameConfig {
Expand Down

0 comments on commit 166a9ca

Please sign in to comment.