Skip to content

Commit ec1a626

Browse files
committed
Placeholder content
1 parent 5998c0a commit ec1a626

4 files changed

Lines changed: 184 additions & 1 deletion

File tree

-44.7 KB
Loading
-6.9 KB
Loading
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { describe, expect, it } from 'bun:test'
2+
import {
3+
type Annotation,
4+
buildSvgOverlay,
5+
} from './capture-screenshots'
6+
7+
describe('buildSvgOverlay', () => {
8+
it('should render badge annotations', () => {
9+
const annotations: Annotation[] = [
10+
{ type: 'badge', x: 100, y: 50, text: '1' },
11+
{ type: 'badge', x: 200, y: 150, text: '12' },
12+
]
13+
14+
const svg = buildSvgOverlay(annotations, 800, 450).toString()
15+
expect(svg).toContain('<svg width="800" height="450"')
16+
expect(svg).toContain('fill="#ffffff" stroke="#1a1a1a"')
17+
expect(svg).toContain('>1<')
18+
expect(svg).toContain('>12<')
19+
})
20+
21+
it('should render selection/highlight box annotations', () => {
22+
const annotations: Annotation[] = [
23+
{
24+
type: 'box',
25+
x: 24,
26+
y: 84,
27+
width: 104,
28+
height: 64,
29+
rx: 4,
30+
},
31+
{
32+
type: 'highlight',
33+
x: 50,
34+
y: 100,
35+
width: 200,
36+
height: 80,
37+
stroke: '#ff0000',
38+
strokeWidth: 2,
39+
},
40+
]
41+
42+
const svg = buildSvgOverlay(annotations, 800, 450).toString()
43+
expect(svg).toContain('x="24"')
44+
expect(svg).toContain('y="84"')
45+
expect(svg).toContain('width="104"')
46+
expect(svg).toContain('height="64"')
47+
expect(svg).toContain('rx="4"')
48+
expect(svg).toContain('fill="none"')
49+
expect(svg).toContain('stroke="#ffffff"')
50+
51+
// Scaled to 3200x1800
52+
const svgLarge = buildSvgOverlay(annotations, 3200, 1800).toString()
53+
expect(svgLarge).toContain('x="96"')
54+
expect(svgLarge).toContain('y="336"')
55+
expect(svgLarge).toContain('width="416"')
56+
expect(svgLarge).toContain('height="256"')
57+
expect(svgLarge).toContain('stroke="#ff0000"')
58+
expect(svgLarge).toContain('stroke-width="8"')
59+
})
60+
61+
it('should render text on white background annotations', () => {
62+
const annotations: Annotation[] = [
63+
{
64+
type: 'text',
65+
x: 24,
66+
y: 152,
67+
width: 188,
68+
height: 20,
69+
text: 'Placeholder content for the slot',
70+
},
71+
]
72+
73+
const svg = buildSvgOverlay(annotations, 800, 450).toString()
74+
expect(svg).toContain('x="24"')
75+
expect(svg).toContain('y="152"')
76+
expect(svg).toContain('width="188"')
77+
expect(svg).toContain('height="20"')
78+
expect(svg).toContain('fill="#ffffff"')
79+
expect(svg).toContain('Placeholder content for the slot')
80+
expect(svg).toContain('text-anchor="middle"')
81+
82+
// Scaled to 3200x1800
83+
const svgLarge = buildSvgOverlay(annotations, 3200, 1800).toString()
84+
expect(svgLarge).toContain('x="96"')
85+
expect(svgLarge).toContain('y="608"')
86+
expect(svgLarge).toContain('width="752"')
87+
expect(svgLarge).toContain('height="80"')
88+
expect(svgLarge).toContain('font-size="46"')
89+
})
90+
})

‎scripts/capture-screenshots.ts‎

Lines changed: 94 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,33 @@ export interface AnnotationBadge {
1414
text: string
1515
}
1616

17-
export type Annotation = AnnotationBadge
17+
export interface AnnotationBox {
18+
type: 'box' | 'highlight' | 'selection'
19+
x: number // reference 800x450 coordinate
20+
y: number // reference 800x450 coordinate
21+
width: number
22+
height: number
23+
rx?: number
24+
stroke?: string
25+
strokeWidth?: number
26+
}
27+
28+
export interface AnnotationText {
29+
type: 'text' | 'label'
30+
x: number // reference 800x450 coordinate
31+
y: number // reference 800x450 coordinate
32+
text: string
33+
width?: number
34+
height?: number
35+
rx?: number
36+
fontSize?: number
37+
fontWeight?: string
38+
color?: string
39+
backgroundColor?: string
40+
paddingX?: number
41+
}
42+
43+
export type Annotation = AnnotationBadge | AnnotationBox | AnnotationText
1844

1945
export interface ScreenshotTarget {
2046
id: string
@@ -48,6 +74,43 @@ export function buildSvgOverlay(
4874
<text x="${tx}" y="${ty}" font-family="-apple-system, BlinkMacSystemFont, Inter, Helvetica, Arial, sans-serif" font-size="${fontSize}" font-weight="bold" fill="#000000" text-anchor="middle" dominant-baseline="central">${ann.text}</text>
4975
`
5076
}
77+
if (
78+
ann.type === 'box' ||
79+
ann.type === 'highlight' ||
80+
ann.type === 'selection'
81+
) {
82+
const bx = ann.x * scale
83+
const by = ann.y * scale
84+
const bw = ann.width * scale
85+
const bh = ann.height * scale
86+
const rx = (ann.rx ?? 4) * scale
87+
const stroke = ann.stroke ?? '#ffffff'
88+
const strokeWidth = (ann.strokeWidth ?? 1) * scale
89+
return `
90+
<rect x="${bx}" y="${by}" width="${bw}" height="${bh}" rx="${rx}" ry="${rx}" fill="none" stroke="${stroke}" stroke-width="${strokeWidth}" />
91+
`
92+
}
93+
if (ann.type === 'text' || ann.type === 'label') {
94+
const bx = ann.x * scale
95+
const by = ann.y * scale
96+
const fontSize = (ann.fontSize ?? 11.5) * scale
97+
const paddingX = (ann.paddingX ?? 4) * scale
98+
const bw =
99+
ann.width !== undefined
100+
? ann.width * scale
101+
: (ann.text.length * (fontSize / scale) * 0.58 + paddingX * 2) * scale
102+
const bh = (ann.height ?? 20) * scale
103+
const rx = (ann.rx ?? 2) * scale
104+
const tx = bx + bw / 2
105+
const ty = by + bh / 2 + 0.5 * scale
106+
const fill = ann.backgroundColor ?? '#ffffff'
107+
const color = ann.color ?? '#000000'
108+
const fontWeight = ann.fontWeight ?? 'bold'
109+
return `
110+
<rect x="${bx}" y="${by}" width="${bw}" height="${bh}" rx="${rx}" ry="${rx}" fill="${fill}" />
111+
<text x="${tx}" y="${ty}" font-family="-apple-system, BlinkMacSystemFont, Inter, Helvetica, Arial, sans-serif" font-size="${fontSize}" font-weight="${fontWeight}" fill="${color}" text-anchor="middle" dominant-baseline="central">${ann.text}</text>
112+
`
113+
}
51114
return ''
52115
})
53116
.join('\n')
@@ -546,6 +609,36 @@ export const TARGETS: ScreenshotTarget[] = [
546609
],
547610
},
548611

612+
// Placeholder content
613+
{
614+
id: 'placeholder-content',
615+
name: 'placeholder-content',
616+
outputDir: 'docs/components/compositions',
617+
path: '/projects/docs_examples/branches/screenshots/components/screenshot-card-container?mode=design&canvas-tool=select&selection=nodes.Iry7BeAO7AjcLcJEL-sPT&rightpanel=attributes',
618+
description: 'Placeholder content in slot',
619+
setup: async (page: Page) => {
620+
await page.waitForTimeout(500)
621+
},
622+
annotations: [
623+
{
624+
type: 'box',
625+
x: 24,
626+
y: 84,
627+
width: 104,
628+
height: 64,
629+
rx: 4,
630+
},
631+
{
632+
type: 'text',
633+
x: 24,
634+
y: 152,
635+
width: 188,
636+
height: 20,
637+
text: 'Placeholder content for the slot',
638+
},
639+
],
640+
},
641+
549642
// Export a component
550643
{
551644
id: 'export-a-component',

0 commit comments

Comments
 (0)