Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .agents/skills/simple-words-design/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ The options page is fully opaque.

### Layout rules

- **Floating button** is `position: fixed`, `z-index: 2147483647` (max), starts near the active editable field's lower-right edge, and can move to avoid button-like page controls.
This is non-negotiable — it must clear every host page, including ones with their own floating UI.
- **Floating button** is `position: fixed`, `z-index: 2147483647` (max), starts near the active editable field's lower-right edge, and can move when a candidate button center would sit over a button-like page control.
Keep this placement check lightweight so typing, selection, scroll, and caret movement stay responsive on heavy host pages.
Use a compact 24px `sw` glyph button for normal editors and a 20px version for short inputs.
The injected button and panel are visible only while the current domain is enabled and the active editor is connected, focused, and visible, including empty editors.
Hide them when the editor or any ancestor is `hidden`, `aria-hidden="true"`, or `display: none`, when the editor itself is `visibility: hidden` or `visibility: collapse`, inside a closed `dialog`, or inside closed `details` content.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Check the production extension files before treating this kit as pixel-faithful.
## Surfaces

1. **Floating button** (`FloatingButton.jsx`) - a prototype pill button with the older sparkles icon and label.
Production now uses a compact `sw` glyph button that starts near the lower-right edge of focused editable fields and can move to avoid button-like page controls, so check the extension files before treating this component as pixel-faithful.
Production now uses a compact `sw` glyph button that starts near the lower-right edge of focused editable fields and can move when a candidate button center would sit over a button-like page control, so check the extension files before treating this component as pixel-faithful.
2. **Refine panel** (`RefinePanel.jsx`) - the floating panel that shows loading, setup or provider error guidance, rewritten draft states, and Open settings/Replace/Dismiss actions.
3. **Options page** (`OptionsPage.jsx`) - the settings page prototype with provider config, enabled domains, name field, and advanced system prompt.
4. **Host page** (`HostPage.jsx`) - a faked Gmail-like compose window, just so the floating button has something to attach to in `index.html`.
Expand All @@ -33,7 +33,7 @@ Preserve that visibility contract in production-facing work.
## Demo

`index.html` boots a fake Gmail compose window with a draft typed in.
The prototype still positions its legacy pill below the textarea; production starts the compact `sw` button near the editor's lower-right edge and can move it to avoid button-like page controls.
The prototype still positions its legacy pill below the textarea; production starts the compact `sw` button near the editor's lower-right edge and can move it when the candidate center would sit over a button-like page control.
Clicking the button opens the refine panel with a 1-second simulated "Refining..." state, then a rewritten draft.
Click "Replace draft" to swap the textarea content; click "Dismiss" to close.
There's also a tab switch at the top to jump to the **Options page** view.
Expand Down
140 changes: 22 additions & 118 deletions src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ const CLICKABLE_AVOID_SELECTOR = [
'input[type="reset"]',
'summary'
].join(',')
const CLICKABLE_AVOID_PROXIMITY = 80
const CLICKABLE_AVOID_INTERIOR_SAMPLE_STEP = 4

const BRAND_GLYPH_SVG = `<svg viewBox="0 0 64 64" fill="currentColor" aria-hidden="true"><text x="32" y="47" text-anchor="middle" font-family="Georgia, serif" font-style="italic" font-weight="700" font-size="48">sw</text></svg>`

const SPARKLES_SVG = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"/><path d="M20 3v4"/><path d="M22 5h-4"/><path d="M4 17v2"/><path d="M5 18H3"/></svg>`
Expand Down Expand Up @@ -577,136 +574,43 @@ function collisionAwareButtonPositionNearEditor(options: {
const candidateRects = buttonCandidateRectsNearEditor(positionOptions)

for (const candidateRect of candidateRects) {
const avoidRects = clickableAvoidRectsForCandidate(editor, candidateRect)
if (!avoidRects.some((rect) => rectsOverlap(rect, candidateRect))) {
if (!candidateCenterCoversClickable(editor, candidateRect)) {
return candidateRect
}
}

return candidateRects[0]
}

function clickableAvoidRectsForCandidate(
// Cheap collision check: hit-test a single point at the candidate's center.
// This avoids the topmost clickable control sitting directly under the button
// without the cost of scanning every pixel of the candidate rect, which made
// repositioning sluggish on heavy pages (it runs on scroll, input, and caret
// moves). The browser's hit-testing already skips hidden/non-painted elements.
function candidateCenterCoversClickable(
editor: HTMLElement,
candidateRect: RectLike
): DOMRect[] {
const elementsFromPoint = document.elementsFromPoint?.bind(document)

if (elementsFromPoint) {
const seenElements = new Set<HTMLElement>()

for (const element of elementsFromCandidateRect(
candidateRect,
elementsFromPoint
)) {
const clickableElement = element.closest<HTMLElement>(
CLICKABLE_AVOID_SELECTOR
)

if (!clickableElement || seenElements.has(clickableElement)) {
continue
}

seenElements.add(clickableElement)

if (clickableElement === editor) {
continue
}

if (clickableElement.contains(editor)) {
continue
}

if (isInjectedUITarget(clickableElement)) {
continue
}

const visibility = getComputedStyle(clickableElement).visibility
if (visibility === 'hidden' || visibility === 'collapse') {
continue
}

const rect = clickableElement.getBoundingClientRect()
if (
rect.width > 0 &&
rect.height > 0 &&
rectsOverlap(rect, candidateRect)
) {
return [rect]
}
}

return []
}

const proximityRect = expandedRect(candidateRect, CLICKABLE_AVOID_PROXIMITY)

return Array.from(
document.querySelectorAll<HTMLElement>(CLICKABLE_AVOID_SELECTOR)
)
.filter((element) => element !== editor)
.filter((element) => !element.contains(editor))
.filter((element) => !isInjectedUITarget(element))
.filter((element) => {
const visibility = getComputedStyle(element).visibility
return visibility !== 'hidden' && visibility !== 'collapse'
})
.map((element) => element.getBoundingClientRect())
.filter((rect) => rect.width > 0 && rect.height > 0)
.filter((rect) => rectsOverlap(rect, proximityRect))
}

function* elementsFromCandidateRect(
rect: RectLike,
elementsFromPoint: (x: number, y: number) => Element[]
): Iterable<Element> {
const right = rect.right - 1
const bottom = rect.bottom - 1
const centerX = Math.floor(rect.left + rect.width / 2)

for (let x = rect.left; x < rect.right; x += 1) {
yield* elementsFromPoint(x, rect.top)
yield* elementsFromPoint(x, bottom)
}

for (let y = rect.top + 1; y < bottom; y += 1) {
yield* elementsFromPoint(rect.left, y)
yield* elementsFromPoint(right, y)
yield* elementsFromPoint(centerX, y)
}

for (
let x = rect.left + CLICKABLE_AVOID_INTERIOR_SAMPLE_STEP;
x < right;
x += CLICKABLE_AVOID_INTERIOR_SAMPLE_STEP
) {
if (x === centerX) {
): boolean {
const centerX = candidateRect.left + candidateRect.width / 2
const centerY = candidateRect.top + candidateRect.height / 2
const elements = document.elementsFromPoint?.(centerX, centerY) ?? [
document.elementFromPoint?.(centerX, centerY)
]

for (const element of elements) {
if (!(element instanceof Element) || isInjectedUITarget(element)) {
continue
}

for (
let y = rect.top + CLICKABLE_AVOID_INTERIOR_SAMPLE_STEP;
y < bottom;
y += CLICKABLE_AVOID_INTERIOR_SAMPLE_STEP
) {
yield* elementsFromPoint(x, y)
const clickable = element.closest<HTMLElement>(CLICKABLE_AVOID_SELECTOR)
if (!clickable || clickable === editor || clickable.contains(editor)) {
return false
}
}
}

function expandedRect(rect: RectLike, amount: number): DOMRect {
return new DOMRect(
rect.left - amount,
rect.top - amount,
rect.width + amount * 2,
rect.height + amount * 2
)
}
return !isInjectedUITarget(clickable)
}

function rectsOverlap(a: RectLike, b: RectLike): boolean {
return (
a.left < b.right && a.right > b.left && a.top < b.bottom && a.bottom > b.top
)
return false
}

function buttonSizeForEditor(rect: DOMRect): number {
Expand Down
Loading
Loading