All skills
garrytan avatar

/design-html

@01593aa official
by Garry Tangarrytan/gstack135k stars
20,051

Design finalization: generates production-quality Pretext-native HTML/CSS. (gstack)

Use this Skill: https://skilld.dev/gh/garrytan/gstack/design-html

This session only. Nothing lands on disk.

sectionspretext-patterns.md

≈1.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

<!-- AUTO-GENERATED from pretext-patterns.md.tmpl — do not edit directly --> <!-- Regenerate: bun run gen:skill-docs -->

Pretext Wiring Patterns

Use these patterns based on the tier selected in Step 2. These are the correct Pretext API usage patterns. Follow them exactly.

Pattern 1: Basic height computation (Simple layout, Card/grid)

import { prepare, layout } from './pretext-inline.js'
// Or if inlined: const { prepare, layout } = window.Pretext

// 1. PREPARE — one-time, after fonts load
await document.fonts.ready
const elements = document.querySelectorAll('[data-pretext]')
const prepared = new Map()

for (const el of elements) {
  const text = el.textContent
  const font = getComputedStyle(el).font
  prepared.set(el, prepare(text, font))
}

// 2. LAYOUT — cheap, call on every resize
function relayout() {
  for (const [el, handle] of prepared) {
    const { height } = layout(handle, el.clientWidth, parseFloat(getComputedStyle(el).lineHeight))
    el.style.height = `${height}px`
  }
}

// 3. RESIZE-AWARE
new ResizeObserver(() => relayout()).observe(document.body)
relayout()

// 4. CONTENT-EDITABLE — re-prepare when text changes
for (const el of elements) {
  if (el.contentEditable === 'true') {
    new MutationObserver(() => {
      const font = getComputedStyle(el).font
      prepared.set(el, prepare(el.textContent, font))
      relayout()
    }).observe(el, { characterData: true, subtree: true, childList: true })
  }
}

Pattern 2: Shrinkwrap / tight-fit containers (Chat bubbles)

import { prepareWithSegments, walkLineRanges } from './pretext-inline.js'

// Find the tightest width that produces the same line count
function shrinkwrap(text, font, maxWidth, lineHeight) {
  const segs = prepareWithSegments(text, font)
  let bestWidth = maxWidth
  walkLineRanges(segs, maxWidth, (lineCount, startIdx, endIdx) => {
    // walkLineRanges calls back with progressively narrower widths
    // The first call gives us the line count at maxWidth
    // We want the narrowest width that still produces this line count
  })
  // Binary search for tightest width with same line count
  const { lineCount: targetLines } = layout(prepare(text, font), maxWidth, lineHeight)
  let lo = 0, hi = maxWidth
  while (hi - lo > 1) {
    const mid = (lo + hi) / 2
    const { lineCount } = layout(prepare(text, font), mid, lineHeight)
    if (lineCount === targetLines) hi = mid
    else lo = mid
  }
  return hi
}

Pattern 3: Text around obstacles (Editorial layout)

import { prepareWithSegments, layoutNextLine } from './pretext-inline.js'

function layoutAroundObstacles(text, font, containerWidth, lineHeight, obstacles) {
  const segs = prepareWithSegments(text, font)
  let state = null
  let y = 0
  const lines = []

  while (true) {
    // Calculate available width at current y position, accounting for obstacles
    let availWidth = containerWidth
    for (const obs of obstacles) {
      if (y >= obs.top && y < obs.top + obs.height) {
        availWidth -= obs.width
      }
    }

    const result = layoutNextLine(segs, state, availWidth, lineHeight)
    if (!result) break

    lines.push({ text: result.text, width: result.width, x: 0, y })
    state = result.state
    y += lineHeight
  }

  return { lines, totalHeight: y }
}

Pattern 4: Full line-by-line rendering (Complex editorial)

import { prepareWithSegments, layoutWithLines } from './pretext-inline.js'

const segs = prepareWithSegments(text, font)
const { lines, height } = layoutWithLines(segs, containerWidth, lineHeight)

// lines = [{ text, width, x, y }, ...]
// Use for Canvas/SVG rendering or custom DOM positioning
for (const line of lines) {
  const span = document.createElement('span')
  span.textContent = line.text
  span.style.position = 'absolute'
  span.style.left = `${line.x}px`
  span.style.top = `${line.y}px`
  container.appendChild(span)
}

Pretext API Reference

PRETEXT API CHEATSHEET:

prepare(text, font) → handle
  One-time text measurement. Call after document.fonts.ready.
  Font: CSS shorthand like '16px Inter' or 'bold 24px Georgia'.

layout(prepared, maxWidth, lineHeight) → { height, lineCount }
  Fast layout computation. Call on every resize. Sub-millisecond.

prepareWithSegments(text, font) → handle
  Like prepare() but enables line-level APIs below.

layoutWithLines(segs, maxWidth, lineHeight) → { lines: [{text, width, x, y}...], height }
  Full line-by-line breakdown. For Canvas/SVG rendering.

walkLineRanges(segs, maxWidth, onLine) → void
  Calls onLine(lineCount, startIdx, endIdx) for each possible layout.
  Find minimum width for N lines. For tight-fit containers.

layoutNextLine(segs, state, maxWidth, lineHeight) → { text, width, state } | null
  Iterator. Different maxWidth per line = text around obstacles.
  Pass null as initial state. Returns null when text is exhausted.

clearCache() → void
  Clears internal measurement caches. Use when cycling many fonts.

setLocale(locale?) → void
  Retargets word segmenter for future prepare() calls.

Source: SKILL.md on GitHub

1 warning4d4 checks · Risk SAFE
  • Gen Agent Trust Hub4d

    The skill is a professional design tool for generating production-quality HTML/CSS. It uses a structured system for handling local state and design artifacts, and it offers an optional design engine download that is protected by user consent and checksum verification. No malicious patterns were identified.

  • Socket4d

    No alerts

  • Snyk4d

    Risk: LOW · No issues

  • ZeroLeaks5mo

    2 findings · Score: 71/100

Signed by skilld at 01593aa. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 15 hours ago.

Activeupdated 5 days ago
What it can do
Runs commands Reads files Edits files
preamble-tier
2
version
1.0.0
triggers
[
  "build the design",
  "code the mockup",
  "make design real"
]
All 8 allowed tools
BashReadWriteEditGlobGrepAgentAskUserQuestion

README badge

README badge for garrytan/gstack/design-html

Generates production-quality HTML and CSS for approved designs using Pretext patterns, with dynamic layout reflow and computed heights. Targets design-to-code handoff after mockup review or planning, with zero dependencies and smart pattern selection based on design type.

Generated from the current SKILL.md.

Does this skill generate Pretext-native HTML or framework-specific code?
It generates Pretext-native HTML/CSS. The skill automatically selects the right Pretext patterns based on your design type, handling text reflow and dynamic layouts without external dependencies.
What design sources can this skill work from?
It accepts approved mockups from /design-shotgun, CEO plans from /plan-ceo-review, design review context from /plan-design-review, or a plain text description from the user.
How much overhead does this skill add?
30KB overhead with zero dependencies.
When should I invoke this skill?
Use it after approving a design or finishing a plan, or when you want to turn a mockup into production HTML. Triggers include 'finalize this design', 'turn this into HTML', or 'build me a page'.

Generated from the current SKILL.md. These answers refresh after source changes.