Agent Skillsarturmarc/overflow-guard › overflow-guard-html

overflow-guard-html

GitHub

提供非React环境下检测内容溢出的Web组件,通过隐藏副本测量并在溢出时切换CSS类,实现工具栏等UI的自适应紧凑布局。

packages/overflow-guard-html/skills/overflow-guard-html/SKILL.md arturmarc/overflow-guard

Trigger Scenarios

需要构建或重构基于HTML/CSS/自定义元素的UI 内容超出容器空间需自动切换紧凑状态 固定高度区域需响应垂直溢出

Install

npx skills add arturmarc/overflow-guard --skill overflow-guard-html -g -y
More Options

Non-standard path

npx skills add https://github.com/arturmarc/overflow-guard/tree/main/packages/overflow-guard-html/skills/overflow-guard-html -g -y

Use without installing

npx skills use arturmarc/overflow-guard@overflow-guard-html

指定 Agent (Claude Code)

npx skills add arturmarc/overflow-guard --skill overflow-guard-html -a claude-code -g -y

安装 repo 全部 skill

npx skills add arturmarc/overflow-guard --all -g -y

预览 repo 内 skill

npx skills add arturmarc/overflow-guard --list

SKILL.md

Frontmatter
{
    "name": "overflow-guard-html",
    "description": "Use when building or refactoring plain HTML, CSS, or custom-element based UI whose layout should adapt when rendered content stops fitting available space. Helps apply fallbackClass-driven compact states, listen for overflowchange, use check-only for axis-specific behavior, and refresh the measurement copy after programmatic DOM changes."
}

OverflowGuard HTML

Use this skill when a non-React UI should respond to actual content overflow instead of viewport breakpoints or guessed container widths.

Reach for it when

  • a toolbar, nav, or action row should switch to a compact state only when content stops fitting
  • labels, translations, optional actions, or data-driven items make the rendered markup overflow
  • you want to keep one visible DOM tree and toggle a CSS class when overflow activates
  • a fixed-height area should react to vertical overflow

Do not reach for it first when:

  • plain CSS wrapping solves the problem cleanly
  • the UI should change at a fixed product breakpoint regardless of content
  • the consumer is already working in React and can use overflow-guard-react

Public API

overflow-guard-html can be used in two installation styles:

  • install the package in an app with a bundler: bun add overflow-guard-html
  • load it directly on a plain HTML page with <script src="https://cdn.jsdelivr.net/npm/overflow-guard-html@0"></script>

Importing or loading overflow-guard-html registers the custom element automatically.

Bundled app usage:

<script type="module">
  import 'overflow-guard-html'
</script>

Raw HTML usage:

<script src="https://cdn.jsdelivr.net/npm/overflow-guard-html@0"></script>

Wrap exactly one primary child element:

<overflow-guard fallbackClass="toolbar--compact">
  <nav class="toolbar">
    ...
  </nav>
</overflow-guard>

Primary behavior

  • the default child is the visible primary tree
  • the element clones that tree into a hidden measurement copy
  • overflow detection happens against the hidden copy
  • when overflow activates, fallbackClass is added to the visible primary child element
  • those fallback mutations are reversed automatically when the content fits again

Runtime state

The host element reflects state with:

  • overflowing
  • overflow-axis
  • data-overflow-axis

Listen for overflowchange when script logic needs the state:

guard.addEventListener('overflowchange', (event) => {
  console.log(event.detail.isOverflowing)
  console.log(event.detail.overflowAxis)
})

Call refresh() after programmatic DOM changes that should rebuild the measurement copy:

guard.refresh()

Preferred patterns

Prefer fallbackClass when:

  • the same markup should adapt in place with CSS
  • compact mode can be expressed with class-driven style changes
  • you want the visible DOM tree to remain stable

Prefer check-only="horizontal" or check-only="vertical" when:

  • only one axis should activate the compact state
  • you are targeting width overflow separately from height overflow

Constraints and gotchas

  • the element expects exactly one primary child element
  • named slots are not supported
  • fallbackClass is applied to the primary child, not the <overflow-guard> host
  • if you mutate source markup programmatically, call refresh()
  • preserve accessible names when hiding text labels in a compact state

Workflow

  1. Identify where rendered content may outgrow its available space.
  2. Decide whether a class-driven compact state is enough.
  3. Wrap the visible element in <overflow-guard>.
  4. Add fallback CSS keyed off fallbackClass or reflected overflow state.
  5. Use overflowchange for behavior that needs JavaScript.
  6. Use check-only when the fallback should react to a single axis.
  7. Verify with narrow widths, long labels, translated strings, dynamic item counts, and fixed-height cases.

Version History

  • 079936f Current 2026-08-04 18:46

Same Skill Collection

packages/overflow-guard-react/skills/overflow-guard-react/SKILL.md

Metadata

Files
0
Version
079936f
Hash
f7cbc4ab
Indexed
2026-08-04 18:46

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-06 07:16
浙ICP备14020137号-1 $bản đồ khách truy cập$