mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-01-26 19:09:52 +00:00
* add dom element resize observer registry for vue node components * Update src/renderer/extensions/vueNodes/composables/useVueNodeResizeTracking.ts Co-authored-by: AustinMroz <austin@comfy.org> * refactor(vue-nodes): typed TransformState InjectionKey, safer ResizeObserver sizing, centralized slot tracking, and small readability updates * chore: make TransformState interface non-exported to satisfy knip pre-push * Revert "chore: make TransformState interface non-exported to satisfy knip pre-push" This reverts commit110ecf31da. * Revert "refactor(vue-nodes): typed TransformState InjectionKey, safer ResizeObserver sizing, centralized slot tracking, and small readability updates" This reverts commit428752619c. * [refactor] Improve resize tracking composable documentation and test utilities - Rename parameters in useVueElementTracking for clarity (appIdentifier, trackingType) - Add comprehensive docstring with examples to prevent DOM attribute confusion - Extract mountLGraphNode test utility to eliminate repetitive mock setup - Add technical implementation notes documenting optimization decisions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> * remove typo comment * convert to functional bounds collection * remove inline import * add interfaces for bounds mutations * remove change log * fix bounds collection when vue nodes turned off * fix title offset on y * move from resize observer to selection toolbox bounds --------- Co-authored-by: AustinMroz <austin@comfy.org> Co-authored-by: Benjamin Lu <benjaminlu1107@gmail.com> Co-authored-by: Claude <noreply@anthropic.com>
98 lines
2.8 KiB
TypeScript
98 lines
2.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import type { ReadOnlyRect } from '@/lib/litegraph/src/interfaces'
|
|
import { computeUnionBounds, gcd, lcm } from '@/utils/mathUtil'
|
|
|
|
describe('mathUtil', () => {
|
|
describe('gcd', () => {
|
|
it('should compute greatest common divisor correctly', () => {
|
|
expect(gcd(48, 18)).toBe(6)
|
|
expect(gcd(100, 25)).toBe(25)
|
|
expect(gcd(17, 13)).toBe(1)
|
|
expect(gcd(0, 5)).toBe(5)
|
|
expect(gcd(5, 0)).toBe(5)
|
|
})
|
|
})
|
|
|
|
describe('lcm', () => {
|
|
it('should compute least common multiple correctly', () => {
|
|
expect(lcm(4, 6)).toBe(12)
|
|
expect(lcm(15, 20)).toBe(60)
|
|
expect(lcm(7, 11)).toBe(77)
|
|
})
|
|
})
|
|
|
|
describe('computeUnionBounds', () => {
|
|
it('should return null for empty input', () => {
|
|
expect(computeUnionBounds([])).toBe(null)
|
|
})
|
|
|
|
// Tests for tuple format (ReadOnlyRect)
|
|
it('should work with ReadOnlyRect tuple format', () => {
|
|
const tuples: ReadOnlyRect[] = [
|
|
[10, 20, 30, 40] as const, // bounds: 10,20 to 40,60
|
|
[50, 10, 20, 30] as const // bounds: 50,10 to 70,40
|
|
]
|
|
|
|
const result = computeUnionBounds(tuples)
|
|
|
|
expect(result).toEqual({
|
|
x: 10, // min(10, 50)
|
|
y: 10, // min(20, 10)
|
|
width: 60, // max(40, 70) - min(10, 50) = 70 - 10
|
|
height: 50 // max(60, 40) - min(20, 10) = 60 - 10
|
|
})
|
|
})
|
|
|
|
it('should handle single ReadOnlyRect tuple', () => {
|
|
const tuple: ReadOnlyRect = [10, 20, 30, 40] as const
|
|
const result = computeUnionBounds([tuple])
|
|
|
|
expect(result).toEqual({
|
|
x: 10,
|
|
y: 20,
|
|
width: 30,
|
|
height: 40
|
|
})
|
|
})
|
|
|
|
it('should handle tuple format with negative dimensions', () => {
|
|
const tuples: ReadOnlyRect[] = [
|
|
[100, 50, -20, -10] as const, // x+width=80, y+height=40
|
|
[90, 45, 15, 20] as const // x+width=105, y+height=65
|
|
]
|
|
|
|
const result = computeUnionBounds(tuples)
|
|
|
|
expect(result).toEqual({
|
|
x: 90, // min(100, 90)
|
|
y: 45, // min(50, 45)
|
|
width: 15, // max(80, 105) - min(100, 90) = 105 - 90
|
|
height: 20 // max(40, 65) - min(50, 45) = 65 - 45
|
|
})
|
|
})
|
|
|
|
it('should maintain optimal performance with SoA tuples', () => {
|
|
// Test that array access is as expected for typical selection sizes
|
|
const tuples: ReadOnlyRect[] = Array.from(
|
|
{ length: 10 },
|
|
(_, i) =>
|
|
[
|
|
i * 20, // x
|
|
i * 15, // y
|
|
100 + i * 5, // width
|
|
80 + i * 3 // height
|
|
] as const
|
|
)
|
|
|
|
const result = computeUnionBounds(tuples)
|
|
|
|
expect(result).toBeTruthy()
|
|
expect(result!.x).toBe(0)
|
|
expect(result!.y).toBe(0)
|
|
expect(result!.width).toBe(325)
|
|
expect(result!.height).toBe(242)
|
|
})
|
|
})
|
|
})
|