flowmolio
Version:
[](https://github.com/vladvlasov256/flowmolio/actions/workflows/test.yml) [](htt
68 lines (67 loc) • 3.34 kB
TypeScript
import { FabricObject } from 'fabric';
import { SVGElementNode } from '../types';
/**
* Represents the bounding box of an SVG element
*/
export interface ElementBounds {
x: number;
y: number;
width: number;
height: number;
}
/**
* Loads all fabric.js objects from an SVG string and returns them indexed by ID
*/
export declare function loadAllFabricObjects(svgString: string): Promise<Record<string, FabricObject>>;
/**
* Context for height update operations
*/
export interface HeightUpdateContext {
element: SVGElementNode;
oldBounds: ElementBounds;
newBounds: ElementBounds;
deltaHeight: number;
}
/**
* Calculate element bounds using fabric.js (async)
* This version creates a root SVG if none provided
* Handles root <svg> elements specially by returning their width/height attributes
*/
export declare function calculateSingleElementBounds(element: SVGElementNode, svgRoot?: SVGElementNode): Promise<ElementBounds>;
/**
* Calculate bounds for an element within the context of the full SVG tree
* This is the primary bounds calculation function
* Throws errors for invalid combinations of SVG elements
*/
export declare function calculateElementBounds(element: SVGElementNode, svgRoot: SVGElementNode): Promise<ElementBounds>;
/**
* Synchronous fallback for text bounds using line extraction
* Used when we need immediate bounds for text layout calculations
*/
export declare function calculateTextBoundsSync(element: SVGElementNode): ElementBounds;
/**
* Checks if an element contains (overlaps with) the changed element
*
* An element "contains" the changed element if their bounds intersect
* for at least 90% of the changed element's height.
*/
export declare function containsChangedElement(element: SVGElementNode, changedElementBounds: ElementBounds, fabricObjectsById: Record<string, FabricObject>): boolean;
/**
* Updates heights of siblings that contain the changed element
* Falls back to full-height logic if no containing elements are found
*/
export declare function updateContainingSiblings(containerElement: SVGElementNode, changedElementBounds: ElementBounds, deltaHeight: number, svgRoot: SVGElementNode, fabricObjectsById: Record<string, FabricObject>, processedElements?: Set<SVGElementNode>, constrainedWidth?: number, changedElement?: SVGElementNode): Promise<void>;
/**
* Updates filter widths for constrained text elements
* This should be called whenever text has constrained width, regardless of height changes
*/
export declare function updateFilterWidthsForConstrainedText(svgTree: SVGElementNode, textElement: SVGElementNode, constrainedWidth: number): Promise<void>;
/**
* Recursively updates element heights from a changed element up to the SVG root
*/
export declare function updateElementAndAncestors(svgTree: SVGElementNode, changedElement: SVGElementNode, changedElementOriginalBounds: ElementBounds, deltaHeight: number, fabricObjectsById: Record<string, FabricObject>, constrainedWidth?: number): Promise<void>;
/**
* Main function to handle height updates from text expansion
* This replaces the global updateBackgroundElements approach
*/
export declare function handleTextHeightChange(svgTree: SVGElementNode, textElement: SVGElementNode, deltaHeight: number, originalBounds: ElementBounds, constrainedWidth?: number): Promise<void>;