web-ui-pack
Version:
Web package with UI elements
95 lines (94 loc) • 3.8 kB
TypeScript
declare global {
namespace WUP.Popup.Place {
interface XResult {
attr: "left" | "right" | "top" | "bottom";
left: number;
/** Size restriction that must be applied to element; calculated in .adjust() and based on userDefined minSize */
maxW?: number | null;
/** Available space including alignment start/left/middle */
freeW: number;
arrowLeft: number;
arrowAngle: number;
}
interface YResult {
attr: "left" | "right" | "top" | "bottom";
top: number;
/** Size restriction that must be applied to element; calculated in .adjust() and based on userDefined minSize */
maxH?: number | null;
/** Available space including alignment start/left/middle */
freeH: number;
arrowTop: number;
arrowAngle: number;
}
interface Result extends XResult, YResult {
}
interface PositionRect {
top: number;
right: number;
bottom: number;
left: number;
}
interface Rect extends PositionRect {
el: Element;
width: number;
height: number;
}
interface MeRect {
w: number;
h: number;
el: HTMLElement;
/** target offset; attention: it's already applied before call of placements */
offset: PositionRect;
minW: number;
minH: number;
arrow: {
h: number;
w: number;
offset: PositionRect;
};
}
/** Ordinary placement rule */
interface PlaceFunc {
(target: Rect, me: MeRect, fit: Rect): Result;
}
/** Ordinary placement rule with nested $resize rule */
interface AdjustFunc extends PlaceFunc {
/** Allow changing maxHeight to fit layout; setup style minHeight to avoid extra-squeezing */
$resizeHeight: PlaceFunc;
/** Allow changing maxWidth; setup style minWidth to avoid extra-squeezing */
$resizeWidth: PlaceFunc;
}
/** Ordinary placement rule with nested $adjust rule */
interface AlignFunc extends PlaceFunc {
/** Allow to break align-rules (start,middle,end) and adjust position to fit layout */
$adjust: AdjustFunc;
/** Allow changing maxHeight to fit layout; setup style minHeight to avoid extra-squeezing */
$resizeHeight: PlaceFunc;
/** Allow changing maxWidth to fit layout; setup style minWidth to avoid extra-squeezing */
$resizeWidth: PlaceFunc;
}
/** Set of rules related to specific edge of targetElement; use bottom.start to place bottomStart */
interface EdgeFunc {
(target: Rect, me: MeRect, fit: Rect): XResult | YResult;
/** align by start of edge of target */
$start: AlignFunc;
/** align by middle of target */
$middle: AlignFunc;
/** align by end of edge of target */
$end: AlignFunc;
}
}
}
export declare const xAdjust: WUP.Popup.Place.AdjustFunc;
export declare const PopupPlacements: {
/** place above of target */
$top: WUP.Popup.Place.EdgeFunc;
/** place bellow of target */
$bottom: WUP.Popup.Place.EdgeFunc;
/** place at left side of target */
$left: WUP.Popup.Place.EdgeFunc;
/** place at right side of target */
$right: WUP.Popup.Place.EdgeFunc;
};
/** Returns normalized offset */
export declare function getOffset(offset: [number, number, number, number] | [number, number] | undefined): WUP.Popup.Place.PositionRect;