uicore-ts
Version:
UICore is a library to build native-like user interfaces using pure Typescript. No HTML is needed at all. Components are described as TS classes and all user interactions are handled explicitly. This library is strongly inspired by the UIKit framework tha
396 lines (395 loc) • 16.7 kB
TypeScript
import { UIColor } from "./UIColor";
import { UICore } from "./UICore";
import "./UICoreExtensions";
import type { UIDialogView } from "./UIDialogView";
import { UILocalizedTextObject } from "./UIInterfaces";
import { UIObject } from "./UIObject";
import { UIPoint } from "./UIPoint";
import { UIRectangle } from "./UIRectangle";
import { UIViewController } from "./UIViewController";
declare module AutoLayout {
class Constraint {
[key: string]: any;
}
class View {
[key: string]: any;
}
class VisualFormat {
static parse(arg0: any, arg1: any): any;
[key: string]: any;
}
const enum Attribute {
LEFT = 0,
RIGHT = 1,
BOTTOM = 2,
TOP = 3,
CENTERX = 4,
CENTERY = 5,
WIDTH = 6,
HEIGHT = 7,
ZINDEX = 8,
VARIABLE = 9,
NOTANATTRIBUTE = 10
}
const enum Relation {
EQU = 0,
LEQ = 1,
GEQ = 2
}
}
declare global {
interface HTMLElement {
UIViewObject?: UIView;
}
}
export interface LooseObject {
[key: string]: any;
}
export interface ControlEventTargetsObject {
[key: string]: Function[];
}
export interface UIViewBroadcastEvent {
name: string;
parameters?: {
[key: string]: string | string[];
};
}
type Mutable<T> = {
-readonly [P in keyof T]: T[P];
};
export type UIViewAddControlEventTargetObject<T extends {
controlEvent: Record<string, any>;
}> = Mutable<{
[K in keyof T["controlEvent"]]: ((sender: UIView, event: Event) => void) & Partial<UIViewAddControlEventTargetObject<T>>;
}>;
interface Constraint {
constant: number;
multiplier: number;
view1: any;
attr2: any;
priority: number;
attr1: any;
view2: any;
relation: any;
}
export declare function UIComponentView(target: Function, context: ClassDecoratorContext): void;
export declare class UIView extends UIObject {
_nativeSelectionEnabled: boolean;
_shouldLayout?: boolean;
_UITableViewRowIndex?: number;
_UITableViewReusabilityIdentifier: any;
_UIViewIntrinsicTemporaryWidth?: string;
_UIViewIntrinsicTemporaryHeight?: string;
_enabled: boolean;
_frame?: UIRectangle & {
zIndex?: number;
};
_backgroundColor: UIColor;
_viewHTMLElement: HTMLElement & LooseObject;
_innerHTMLKey?: string;
_defaultInnerHTML?: string;
_parameters?: {
[x: string]: (string | UILocalizedTextObject);
};
_localizedTextObject?: UILocalizedTextObject;
_controlEventTargets: ControlEventTargetsObject;
_frameTransform: string;
viewController?: UIViewController;
_updateLayoutFunction?: Function;
_constraints: any[];
superview?: UIView;
subviews: UIView[];
_styleClasses: any[];
_isHidden: boolean;
pausesPointerEvents: boolean;
stopsPointerEventPropagation: boolean;
pointerDraggingPoint: UIPoint;
_previousClientPoint: UIPoint;
_isPointerInside?: boolean;
_isPointerValid?: boolean;
_isPointerValidForMovement?: boolean;
_isPointerDown: boolean;
_initialPointerPosition?: UIPoint;
_hasPointerDragged?: boolean;
_pointerDragThreshold: number;
ignoresTouches: boolean;
ignoresMouse: boolean;
core: UICore;
static _UIViewIndex: number;
_UIViewIndex: number;
static _viewsToLayout: UIView[];
forceIntrinsicSizeZero: boolean;
_touchEventTime?: number;
static _pageScale: number;
_scale: number;
isInternalScaling: boolean;
static resizeObserver: ResizeObserver;
private _isMovable;
makeNotMovable?: () => void;
private _isResizable;
makeNotResizable?: () => void;
resizingHandles: UIView[];
private _isMoving;
_isCBEditorTemporaryResizable: boolean;
_isCBEditorTemporaryMovable: boolean;
static _onWindowTouchMove: (event: TouchEvent) => void;
static _onWindowMouseMove: (event: MouseEvent) => void;
static _onWindowMouseup: (event: MouseEvent) => void;
private _resizeObserverEntry?;
private _intrinsicSizesCache;
constructor(elementID?: string, viewHTMLElement?: HTMLElement & LooseObject | null, elementType?: string | null, initViewData?: any);
static get nextIndex(): number;
static get pageHeight(): number;
static get pageWidth(): number;
centerInContainer(): void;
centerXInContainer(): void;
centerYInContainer(): void;
_initViewHTMLElement(elementID: string, viewHTMLElement: (HTMLElement & LooseObject) | null, elementType?: string | null): void;
set nativeSelectionEnabled(selectable: boolean);
get nativeSelectionEnabled(): boolean;
get styleClassName(): string;
protected _initViewCSSSelectorsIfNeeded(): void;
initViewStyleSelectors(): void;
initStyleSelector(selector: string, style: string): void;
createElement(elementID: string, elementType: string): HTMLElement;
get viewHTMLElement(): HTMLElement & LooseObject;
get elementID(): string;
setInnerHTML(key: string, defaultString: string, parameters?: {
[x: string]: string | UILocalizedTextObject;
}): void;
protected _setInnerHTMLFromKeyIfPossible(): void;
protected _setInnerHTMLFromLocalizedTextObjectIfPossible(): void;
get localizedTextObject(): UILocalizedTextObject | undefined;
set localizedTextObject(localizedTextObject: UILocalizedTextObject | undefined);
get innerHTML(): string;
set innerHTML(innerHTML: string);
set hoverText(hoverText: string);
get hoverText(): string;
get scrollSize(): UIRectangle;
get dialogView(): UIDialogView | undefined;
get rootView(): UIView;
set enabled(enabled: boolean);
get enabled(): boolean;
updateContentForCurrentEnabledState(): void;
get tabIndex(): number;
set tabIndex(index: number);
get propertyDescriptors(): {
object: UIObject;
name: string;
}[];
get styleClasses(): any[];
set styleClasses(styleClasses: any[]);
hasStyleClass(styleClass: string): boolean;
addStyleClass(styleClass: string): void;
removeStyleClass(styleClass: string): void;
static findViewWithElementID(elementID: string): UIView | undefined;
static createStyleSelector(selector: string, style: string): void;
static getStyleRules(selector: string): CSSRule[];
get style(): CSSStyleDeclaration;
get computedStyle(): CSSStyleDeclaration;
get hidden(): boolean;
set hidden(v: boolean);
static set pageScale(scale: number);
static get pageScale(): number;
set scale(scale: number);
get scale(): number;
calculateAndSetViewFrame(): void;
get frame(): UIRectangle & {
zIndex?: number;
};
set frame(rectangle: UIRectangle & {
zIndex?: number;
});
setFrame(rectangle: UIRectangle & {
zIndex?: number;
}, zIndex?: number, performUncheckedLayout?: boolean): void;
get bounds(): UIRectangle;
set bounds(rectangle: UIRectangle);
boundsDidChange(bounds: UIRectangle): void;
didResize(entry: ResizeObserverEntry): void;
get frameTransform(): string;
set frameTransform(value: string);
setPosition(left?: number | string, right?: number | string, bottom?: number | string, top?: number | string, height?: number | string, width?: number | string): void;
setSizes(height?: number | string, width?: number | string): void;
setMinSizes(height?: number | string, width?: number | string): void;
setMaxSizes(height?: number | string, width?: number | string): void;
setMargin(margin?: number | string): void;
setMargins(left?: number | string, right?: number | string, bottom?: number | string, top?: number | string): void;
setPadding(padding?: number | string): void;
setPaddings(left?: number | string, right?: number | string, bottom?: number | string, top?: number | string): void;
setBorder(radius?: number | string, width?: number | string, color?: UIColor, style?: string): void;
setStyleProperty(propertyName: string, value?: number | string): void;
get userInteractionEnabled(): boolean;
set userInteractionEnabled(userInteractionEnabled: boolean);
get backgroundColor(): UIColor;
set backgroundColor(backgroundColor: UIColor);
get alpha(): number;
set alpha(alpha: number);
static animateViewOrViewsWithDurationDelayAndFunction(viewOrViews: UIView | HTMLElement | UIView[] | HTMLElement[], duration: number, delay: number, timingStyle: string | undefined, transformFunction: Function, transitioncompletionFunction: Function): {
finishImmediately: () => void;
didFinish: () => void;
views: HTMLElement | UIView | UIView[] | HTMLElement[];
registrationTime: number;
};
animationDidFinish(): void;
static _transformAttribute: string;
static _setAbsoluteSizeAndPosition(element: HTMLElement & LooseObject, left: number, top: number, width: string | number, height: string | number, zIndex?: number, frameTransform?: string): void;
static performAutoLayout(parentElement: HTMLElement & LooseObject, visualFormatArray: string | any[] | null, constraintsArray: string | any[]): () => void;
static runFunctionBeforeNextFrame(step: () => void): void;
static scheduleLayoutViewsIfNeeded(): void;
static layoutViewsIfNeeded(): void;
setNeedsLayout(): void;
get needsLayout(): boolean | undefined;
layoutIfNeeded(): void;
layoutSubviews(): void;
applyClassesAndStyles(): void;
willLayoutSubviews(): void;
didLayoutSubviews(): void;
get constraints(): any[];
set constraints(constraints: any[]);
addConstraint(constraint: any): void;
addConstraintsWithVisualFormat(visualFormatArray: string[]): void;
static constraintWithView(view: {
isKindOfClass: (arg0: typeof UIView) => any;
viewHTMLElement: any;
id: any;
}, attribute: any, relation: any, toView: {
isKindOfClass: any;
viewHTMLElement: any;
id: any;
}, toAttribute: any, multiplier: number, constant: number, priority: number): Constraint;
static constraintAttribute: {
readonly left: AutoLayout.Attribute.LEFT;
readonly right: AutoLayout.Attribute.RIGHT;
readonly bottom: AutoLayout.Attribute.BOTTOM;
readonly top: AutoLayout.Attribute.TOP;
readonly centerX: AutoLayout.Attribute.CENTERX;
readonly centerY: AutoLayout.Attribute.CENTERY;
readonly height: AutoLayout.Attribute.HEIGHT;
readonly width: AutoLayout.Attribute.WIDTH;
readonly zIndex: AutoLayout.Attribute.ZINDEX;
readonly constant: AutoLayout.Attribute.NOTANATTRIBUTE;
readonly variable: AutoLayout.Attribute.VARIABLE;
};
static constraintRelation: {
readonly equal: AutoLayout.Relation.EQU;
readonly lessThanOrEqual: AutoLayout.Relation.LEQ;
readonly greaterThanOrEqual: AutoLayout.Relation.GEQ;
};
subviewWithID(viewID: string): UIView | undefined;
rectangleContainingSubviews(): UIRectangle;
hasSubview(view: UIView): boolean;
get viewBelowThisView(): UIView;
get viewAboveThisView(): UIView;
addSubview(view: UIView, aboveView?: UIView): void;
addSubviews(views: UIView[]): void;
addedAsSubviewToView(view: UIView | undefined, aboveView?: UIView): this;
moveToBottomOfSuperview(): void;
moveToTopOfSuperview(): void;
removeFromSuperview(): void;
willAppear(): void;
willMoveToSuperview(superview: UIView): void;
didMoveToSuperview(superview: UIView): void;
wasAddedToViewTree(): void;
wasRemovedFromViewTree(): void;
get isMemberOfViewTree(): boolean;
get withAllSuperviews(): UIView[];
get elementWithAllSuperviewElements(): HTMLElement[];
setNeedsLayoutOnAllSuperviews(): void;
setNeedsLayoutUpToRootView(): void;
focus(): void;
blur(): void;
get isMovable(): boolean;
set isMovable(isMovable: boolean);
makeMovable(optionalParameters?: {
shouldMoveWithMouseEvent?: (sender: UIView, event: MouseEvent) => boolean;
viewDidMoveToPosition?: (view: UIView, isMovementCompleted: boolean) => void;
}): void;
get isResizable(): boolean;
set isResizable(isResizable: boolean);
makeResizable(optionalParameters?: {
overlayElement?: HTMLElement;
borderWidth?: number;
borderColor?: UIColor;
cornerSize?: string;
maxCornerSize?: string;
viewDidChangeToSize?: (view: UIView, isMovementCompleted: boolean) => void;
}): void;
static shouldCallPointerUpInsideOnView(view: UIView, event: MouseEvent | TouchEvent): Promise<boolean>;
static shouldCallPointerHoverOnView(view: UIView, event: MouseEvent | TouchEvent): Promise<boolean>;
static shouldCallPointerLeaveOnView(view: UIView, event: MouseEvent | TouchEvent): Promise<boolean>;
static shouldCallPointerCancelOnView(view: UIView, event: MouseEvent | TouchEvent): Promise<boolean>;
shouldCallPointerUpInside(event: MouseEvent | TouchEvent): Promise<boolean>;
shouldCallPointerCancel(event: MouseEvent | TouchEvent): Promise<boolean>;
shouldCallPointerHover(event: MouseEvent | TouchEvent): Promise<boolean>;
shouldCallPointerLeave(event: MouseEvent | TouchEvent): Promise<boolean>;
protected _loadUIEvents(): void;
static controlEvent: {
readonly PointerDown: "PointerDown";
readonly PointerMove: "PointerMove";
readonly PointerDrag: "PointerDrag";
readonly PointerLeave: "PointerLeave";
readonly PointerEnter: "PointerEnter";
readonly PointerUpInside: "PointerUpInside";
readonly PointerTap: "PointerTap";
readonly PointerUp: "PointerUp";
readonly MultipleTouches: "PointerZoom";
readonly PointerCancel: "PointerCancel";
readonly PointerHover: "PointerHover";
readonly EnterDown: "EnterDown";
readonly EnterUp: "EnterUp";
readonly EscDown: "EscDown";
readonly TabDown: "TabDown";
readonly LeftArrowDown: "LeftArrowDown";
readonly RightArrowDown: "RightArrowDown";
readonly DownArrowDown: "DownArrowDown";
readonly UpArrowDown: "UpArrowDown";
readonly Focus: "Focus";
readonly Blur: "Blur";
};
controlEvent: {
readonly PointerDown: "PointerDown";
readonly PointerMove: "PointerMove";
readonly PointerDrag: "PointerDrag";
readonly PointerLeave: "PointerLeave";
readonly PointerEnter: "PointerEnter";
readonly PointerUpInside: "PointerUpInside";
readonly PointerTap: "PointerTap";
readonly PointerUp: "PointerUp";
readonly MultipleTouches: "PointerZoom";
readonly PointerCancel: "PointerCancel";
readonly PointerHover: "PointerHover";
readonly EnterDown: "EnterDown";
readonly EnterUp: "EnterUp";
readonly EscDown: "EscDown";
readonly TabDown: "TabDown";
readonly LeftArrowDown: "LeftArrowDown";
readonly RightArrowDown: "RightArrowDown";
readonly DownArrowDown: "DownArrowDown";
readonly UpArrowDown: "UpArrowDown";
readonly Focus: "Focus";
readonly Blur: "Blur";
};
get controlEventTargetAccumulator(): UIViewAddControlEventTargetObject<UIView>;
addTargetForControlEvents(eventKeys: string[], targetFunction: (sender: UIView, event: Event) => void): void;
addTargetForControlEvent(eventKey: string, targetFunction: (sender: UIView, event: Event) => void): void;
removeTargetForControlEvent(eventKey: string, targetFunction: (sender: UIView, event: Event) => void): void;
removeTargetForControlEvents(eventKeys: string[], targetFunction: (sender: UIView, event: Event) => void): void;
sendControlEventForKey(eventKey: string, nativeEvent?: Event): void;
static broadcastEventName: {
readonly LanguageChanged: "LanguageChanged";
readonly RemovedFromViewTree: "RemovedFromViewTree";
readonly AddedToViewTree: "AddedToViewTree";
readonly PageDidScroll: "PageDidScroll";
};
broadcastEventInSubtree(event: UIViewBroadcastEvent): void;
didReceiveBroadcastEvent(event: UIViewBroadcastEvent): void;
forEachViewInSubtree(functionToCall: (view: UIView) => void): void;
rectangleInView(rectangle: UIRectangle, view: UIView): any;
rectangleFromView(rectangle: UIRectangle, view: UIView): any;
intrinsicContentSizeWithConstraints(constrainingHeight?: number, constrainingWidth?: number): UIRectangle;
intrinsicContentWidth(constrainingHeight?: number): number;
intrinsicContentHeight(constrainingWidth?: number): number;
intrinsicContentSize(): UIRectangle;
}
export {};