@@ -30,6 +30,7 @@ type TokenSegment = {
3030type WrappedLine = {
3131 lineNumber : number | null ;
3232 segments : TokenSegment [ ] ;
33+ height : number ;
3334} ;
3435
3536export type OgTokenClass = TokenClass ;
@@ -47,13 +48,13 @@ type SkillCardInput = {
4748 shareUrl : string ;
4849} ;
4950
50- const FONT_SIZE = 15 ;
51- const LINE_HEIGHT = 22 ;
51+ const FONT_SIZE = 24 ;
52+ const LINE_HEIGHT = 34 ;
5253const BODY_X = 34 ;
53- const BODY_Y = 116 ;
54- const BODY_WIDTH = 1084 ;
55- const BODY_HEIGHT = 454 ;
56- const CHAR_WIDTH = 8.9 ;
54+ const BODY_Y = 126 ;
55+ const BODY_WIDTH = 1110 ;
56+ const BODY_HEIGHT = 410 ;
57+ const CHAR_WIDTH = 12.2 ;
5758const OG_SANS_FONT = "DejaVu Sans, Liberation Sans, Arial, sans-serif" ;
5859const OG_MONO_FONT = "DejaVu Sans Mono, Liberation Mono, Courier New, monospace" ;
5960const MAX_LINES = Math . floor ( BODY_HEIGHT / LINE_HEIGHT ) ;
@@ -242,6 +243,17 @@ function buildWrappedLines(text: string, shareUrl: string): WrappedLine[] {
242243 let truncated = false ;
243244
244245 for ( const [ index , htmlLine ] of htmlLines . entries ( ) ) {
246+ if ( ! ( rawLines [ index ] ?? "" ) . trim ( ) ) {
247+ if ( wrapped . length && wrapped [ wrapped . length - 1 ] ?. segments . length ) {
248+ wrapped . push ( {
249+ lineNumber : null ,
250+ segments : [ ] ,
251+ height : 14 ,
252+ } ) ;
253+ }
254+ continue ;
255+ }
256+
245257 const quotedCodeSegments = detectQuotedCodeSegments ( rawLines [ index ] ?? "" ) ;
246258 const parsed = quotedCodeSegments
247259 ? quotedCodeSegments
@@ -255,6 +267,7 @@ function buildWrappedLines(text: string, shareUrl: string): WrappedLine[] {
255267 wrapped . push ( {
256268 lineNumber : wrapped . length + 1 ,
257269 segments : lineGroup ,
270+ height : LINE_HEIGHT ,
258271 } ) ;
259272 }
260273 if ( truncated ) break ;
@@ -264,11 +277,13 @@ function buildWrappedLines(text: string, shareUrl: string): WrappedLine[] {
264277 wrapped . push ( {
265278 lineNumber : null ,
266279 segments : [ ] ,
280+ height : 18 ,
267281 } ) ;
268282 for ( const continuationLine of continuationLines ) {
269283 wrapped . push ( {
270284 lineNumber : null ,
271285 segments : continuationLine ,
286+ height : LINE_HEIGHT ,
272287 } ) ;
273288 }
274289 }
@@ -288,7 +303,7 @@ function classStyle(className: TokenClass): { fill: string; weight?: string; sty
288303 case "hl-frontmatter" :
289304 return { fill : "#94a3b8" } ;
290305 case "hl-key" :
291- return { fill : "#475569 " } ;
306+ return { fill : "#be123c " } ;
292307 case "hl-url" :
293308 return { fill : "#2563eb" } ;
294309 case "hl-string" :
@@ -300,15 +315,15 @@ function classStyle(className: TokenClass): { fill: string; weight?: string; sty
300315 case "hl-number" :
301316 return { fill : "#f97316" } ;
302317 case "hl-keyword" :
303- return { fill : "#be123c " } ;
318+ return { fill : "#7c3aed" , weight : "600 " } ;
304319 case "hl-comment" :
305320 return { fill : "#94a3b8" , style : "italic" } ;
306321 case "hl-heading" :
307322 return { fill : "#0f172a" , weight : "700" } ;
308323 case "hl-field" :
309324 return { fill : "#be123c" } ;
310325 case "hl-inline-code" :
311- return { fill : "#7c3aed " } ;
326+ return { fill : "#0891b2 " } ;
312327 case "hl-bold" :
313328 return { fill : "#0f172a" , weight : "700" } ;
314329 case "hl-type" :
@@ -328,16 +343,17 @@ function classStyle(className: TokenClass): { fill: string; weight?: string; sty
328343
329344function renderLine ( line : WrappedLine , y : number ) : string {
330345 let x = BODY_X ;
331- const gutter = line . lineNumber == null ? "" : `<text x="${ BODY_X } " y="${ y } " fill="#cbd5e1" font-family="${ OG_MONO_FONT } " font-size="13" font-weight="600">${ String ( line . lineNumber ) . padStart ( 2 , "0" ) } </text>` ;
332- x += 44 ;
346+ const gutter = "" ;
333347
334348 return `${ gutter } ${ line . segments
335349 . map ( ( segment , index ) => {
336350 const style = classStyle ( segment . className ) ;
337351 const width = segmentWidth ( segment . text ) ;
338352 const pill =
339353 segment . className === "hl-codeblock"
340- ? `<rect x="${ x - 1 } " y="${ y - 14 } " width="${ width + 8 } " height="22" rx="5" fill="#f8fafc" stroke="#cbd5e1" />`
354+ ? `<rect x="${ x - 1 } " y="${ y - 18 } " width="${ width + 10 } " height="28" rx="6" fill="#f8fafc" stroke="#cbd5e1" />`
355+ : segment . className === "hl-inline-code"
356+ ? `<rect x="${ x - 2 } " y="${ y - 18 } " width="${ width + 6 } " height="28" rx="5" fill="rgba(8,145,178,0.08)" />`
341357 : "" ;
342358 const node = `<text x="${ x } " y="${ y } " fill="${ style . fill } " font-family="${ OG_MONO_FONT } " font-size="${ FONT_SIZE } "${ style . weight ? ` font-weight="${ style . weight } "` : "" } ${ style . style ? ` font-style="${ style . style } "` : "" } ${ segment . className === "hl-cta-url" ? ` text-decoration="underline"` : "" } >${ escapeSvgText ( segment . text ) } </text>` ;
343359 x += width ;
@@ -348,15 +364,22 @@ function renderLine(line: WrappedLine, y: number): string {
348364
349365function renderPreviewSurface ( input : { title : string ; filename : string ; text : string ; shareUrl : string } ) : string {
350366 const model = buildSkillCardModel ( input ) ;
367+ let currentY = BODY_Y ;
351368
352369 return `
353370 <g transform="translate(18 12)">
354371 <rect width="1164" height="606" rx="38" fill="rgba(255,255,255,0.96)" stroke="rgba(148,163,184,0.16)" />
355- <path d="M0 66H1164" stroke="rgba(226,232,240,0.92)" />
356- <text x="34" y="42" fill="#0f172a" font-family="${ OG_SANS_FONT } " font-size="28" font-weight="800" letter-spacing="-1.2">SKILL.md</text>
357- <circle cx="930" cy="33" r="7" fill="url(#skillGradient)" />
358- <text x="950" y="40" fill="#94a3b8" font-family="${ OG_MONO_FONT } " font-size="16">${ escapeSvgText ( input . filename ) } </text>
359- ${ model . lines . map ( ( line , index ) => renderLine ( line , BODY_Y + index * LINE_HEIGHT ) ) . join ( "" ) }
372+ <path d="M0 78H1164" stroke="rgba(226,232,240,0.92)" />
373+ <text x="34" y="52" fill="#0f172a" font-family="${ OG_SANS_FONT } " font-size="40" font-weight="900" letter-spacing="-1.2">SKILL.md</text>
374+ <circle cx="888" cy="39" r="9" fill="url(#skillGradient)" />
375+ <text x="912" y="48" fill="#94a3b8" font-family="${ OG_MONO_FONT } " font-size="30" font-weight="700">${ escapeSvgText ( input . filename ) } </text>
376+ ${ model . lines
377+ . map ( ( line ) => {
378+ const y = currentY ;
379+ currentY += line . height ;
380+ return renderLine ( line , y ) ;
381+ } )
382+ . join ( "" ) }
360383 </g>` ;
361384}
362385
0 commit comments