code-yeongyu/oh-my-openagent / packages/shared-skills/skills/frontend
frontend
FlaggedBuilds, styles, and polishes anything drawn with HTML, CSS, or SVG: web UI, pages, components, HTML reports rendered to PDF or print, figures, PNG/SVG diagrams, slides, and images for Notion or Slack. Use for any styling, layout, animation, or visual-quality task, or when asked to make something look or feel a certain way.
scripts/detect/rules/layout/support/geometry.ts
View on GitHubimport { ancestors, childrenOf, descendants, fontSizePx, isRendered, px, styleOf } from "../../../core/page"
import { parseColor } from "../../../core/color"
import type { ElementSnapshot, PageSnapshot, Rect } from "../../../types"
export const right = (r: Rect): number => r.x + r.width
export const bottom = (r: Rect): number => r.y + r.height
export const length = (el: ElementSnapshot, prop: string): number => px(styleOf(el, prop)) ?? 0
export const chain = (s: PageSnapshot, el: ElementSnapshot): readonly ElementSnapshot[] => [el, ...ancestors(s, el)]
export const scrollsX = (el: ElementSnapshot): boolean => /^(auto|scroll)$/.test(styleOf(el, "overflow-x"))
export const clipsX = (el: ElementSnapshot): boolean => /^(hidden|clip|auto|scroll)$/.test(styleOf(el, "overflow-x"))
export const clipsY = (el: ElementSnapshot): boolean => /^(hidden|clip|auto|scroll)$/.test(styleOf(el, "overflow-y"))
export function clipRect(el: ElementSnapshot): Rect {
const margin = Math.max(
0,
styleOf(el, "overflow-clip-margin").split(/\s+/).map(Number.parseFloat).find(Number.isFinite) ?? 0,
)
const layoutWidth = el.scroll.clientWidth + length(el, "border-left-width") + length(el, "border-right-width")
const layoutHeight = el.scroll.clientHeight + length(el, "border-top-width") + length(el, "border-bottom-width")
const scaleX = layoutWidth > 0 && Math.abs(el.rect.width - layoutWidth) > 1 ? el.rect.width / layoutWidth : 1
const scaleY = layoutHeight > 0 && Math.abs(el.rect.height - layoutHeight) > 1 ? el.rect.height / layoutHeight : 1
const x = styleOf(el, "overflow-x") === "clip" ? margin * scaleX : 0
const y = styleOf(el, "overflow-y") === "clip" ? margin * scaleY : 0
return { x: el.rect.x - x, y: el.rect.y - y, width: el.rect.width + 2 * x, height: el.rect.height + 2 * y }
}
export const outOfFlow = (el: ElementSnapshot): boolean => /^(absolute|fixed)$/.test(styleOf(el, "position"))
export const hasRole = (el: ElementSnapshot, roles: readonly string[]): boolean =>
(el.attributes["role"] ?? "")
.toLowerCase()
.split(/\s+/)
.some((r) => roles.includes(r))
export const ident = (el: ElementSnapshot): string =>
`${el.attributes["class"] ?? ""} ${el.attributes["id"] ?? ""}`.toLowerCase()
export const alpha = (el: ElementSnapshot, prop: string): number => parseColor(styleOf(el, prop))?.a ?? 0
export const borders = (el: ElementSnapshot): readonly boolean[] =>
["top", "right", "bottom", "left"].map(
(side) =>
length(el, `border-${side}-width`) >= 0.5 &&
!/^(none|hidden)$/.test(styleOf(el, `border-${side}-style`)) &&
alpha(el, `border-${side}-color`) >= 0.05,
)
const screenReaderOnly = (el: ElementSnapshot): boolean =>
styleOf(el, "clip-path") === "inset(50%)" || (el.rect.width <= 1 && el.rect.height <= 1 && (clipsX(el) || clipsY(el)))
export function painted(s: PageSnapshot, el: ElementSnapshot): boolean {
if (!isRendered(s, el) || screenReaderOnly(el)) return false
for (const a of chain(s, el)) {
if (styleOf(a, "display") === "none" || Number.parseFloat(styleOf(a, "opacity")) <= 0.01) return false
if (a.tag === "details" && a.attributes["open"] === undefined) {
const summary = childrenOf(s, a).find((c) => c.tag === "summary")
if (!summary || !chain(s, el).includes(summary)) return false
}
const clip = clipRect(a)
if (
a !== el &&
((clipsX(a) && (right(el.rect) <= clip.x || el.rect.x >= right(clip))) ||
(clipsY(a) && (bottom(el.rect) <= clip.y || el.rect.y >= bottom(clip))))
)
return false
}
return true
}
export function textLines(s: PageSnapshot, el: ElementSnapshot): readonly Rect[] {
const nodes = [el, ...descendants(s, el)].filter((n) => n === el || styleOf(n, "display") === "inline")
const rects = nodes
.flatMap((n) => n.lineRects)
.filter((r) => r.width > 0 && r.height > 0)
.sort((a, b) => a.y - b.y || a.x - b.x)
const lines: Rect[] = []
for (const r of rects) {
const i = lines.findIndex(
(l) => Math.min(bottom(l), bottom(r)) - Math.max(l.y, r.y) > Math.min(l.height, r.height) / 2,
)
const l = lines[i]
if (l)
lines[i] = {
x: Math.min(l.x, r.x),
y: Math.min(l.y, r.y),
width: Math.max(right(l), right(r)) - Math.min(l.x, r.x),
height: Math.max(bottom(l), bottom(r)) - Math.min(l.y, r.y),
}
else lines.push(r)
}
return lines
}
export function bounds(rects: readonly Rect[]): Rect | null {
if (rects.length === 0) return null
const x = Math.min(...rects.map((r) => r.x))
const y = Math.min(...rects.map((r) => r.y))
return { x, y, width: Math.max(...rects.map(right)) - x, height: Math.max(...rects.map(bottom)) - y }
}
export const lineHeight = (el: ElementSnapshot): number => px(styleOf(el, "line-height")) ?? fontSizePx(el) * 1.2
export const intersects = (a: Rect, b: Rect): boolean =>
Math.min(right(a), right(b)) > Math.max(a.x, b.x) && Math.min(bottom(a), bottom(b)) > Math.max(a.y, b.y)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |