mirror of
https://github.com/NanmiCoder/cc-haha
synced 2026-07-16 13:03:31 +08:00
feat(desktop): add computeWebviewBounds helper
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
78565a7478
commit
53724a6652
14
desktop/src/components/browser/computeWebviewBounds.test.ts
Normal file
14
desktop/src/components/browser/computeWebviewBounds.test.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { computeWebviewBounds } from './computeWebviewBounds'
|
||||
|
||||
describe('computeWebviewBounds', () => {
|
||||
it('maps a DOMRect to logical bounds (rounded)', () => {
|
||||
const rect = { left: 100.4, top: 50.6, width: 800.2, height: 600.9 } as DOMRect
|
||||
expect(computeWebviewBounds(rect)).toEqual({ x: 100, y: 51, width: 800, height: 601 })
|
||||
})
|
||||
|
||||
it('clamps negative/zero sizes to 0', () => {
|
||||
const rect = { left: -5, top: -5, width: -10, height: 0 } as DOMRect
|
||||
expect(computeWebviewBounds(rect)).toEqual({ x: -5, y: -5, width: 0, height: 0 })
|
||||
})
|
||||
})
|
||||
10
desktop/src/components/browser/computeWebviewBounds.ts
Normal file
10
desktop/src/components/browser/computeWebviewBounds.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export type WebviewBounds = { x: number; y: number; width: number; height: number }
|
||||
|
||||
export function computeWebviewBounds(rect: Pick<DOMRect, 'left' | 'top' | 'width' | 'height'>): WebviewBounds {
|
||||
return {
|
||||
x: Math.round(rect.left),
|
||||
y: Math.round(rect.top),
|
||||
width: Math.max(0, Math.round(rect.width)),
|
||||
height: Math.max(0, Math.round(rect.height)),
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user