Skip to content

UI Element

The base element (root class of all elements), exposing all common properties and methods shared by every UI component.

In addition to the API list, we also provide a simple categorization system to help you quickly understand the structure of the API.

📃 API

All Properties

NameDescription
Identity
idUnique element id
tagElement tag name (class name of the element)
nameElement name
classNameCategory name, currently supports only one value
innerIdRuntime-generated temporary id (incremental), not for persistent storage
innerNameRuntime-generated temporary name for quick element identification
Layout
xX-axis position
yY-axis position
widthWidth
heightHeight
isAutoWidthWhether width is auto-calculated
isAutoHeightWhether height is auto-calculated
lockRatioLock aspect ratio (requires resize plugin)
scaleXX-axis scale (negative = mirror X)
scaleYY-axis scale (negative = mirror Y)
scaleFixedFixed global scale (not affected by zoom)
scaleGet/set scaleX and scaleY together
rotationRotation angle (see Math rotation)
skewXX-axis skew angle
skewYY-axis skew angle
offsetXX-axis offset
offsetYY-axis offset
originTransform origin (same as CSS transform-origin)
aroundAnchor-based positioning (similar to game engine anchors)
Bounds
boxBoundsBasic bounds in inner coordinate system (OBB)
renderBoundsRender bounds in inner coordinate system (AABB)
worldBoxBoundsBasic bounds in world coordinates (AABB)
worldRenderBoundsRender bounds in world coordinates (AABB)
renderSpreadExpands render bounds to prevent rendering artifacts (e.g. text glitches)
Transform
worldTransformWorld transformation matrix (includes scale)
localTransformLocal transformation matrix relative to parent
Appearance
zIndexStacking order within parent
opacityOpacity
worldOpacityGlobal opacity (affected by parent)
visibleVisibility toggle
fillFill color/style (supports solid, gradient, image, etc.)
strokeStroke style (supports multiple types and stacking)
strokeAlignStroke alignment
strokeWidthStroke width
strokeScaleFixedFix stroke width during zoom
strokeCapStroke line cap style
strokeJoinStroke join style
dashPatternDashed line pattern
dashOffsetDash offset
shadowOuter shadow (supports multiple shadows)
innerShadowInner shadow (supports multiple shadows)
dimDim effect (requires bright plugin)
dimskipSkip dimming (highlight element)
brightHighlight and bring element to front
maskSet element as mask
eraserSet element as eraser
blendModeBlend mode
Interaction
hittableWhether element responds to pointer events
hitChildrenControl child hit behavior
hitSelfControl self hit behavior
hitFillHit detection for fill (supports pixel-level detection)
hitStrokeHit detection for stroke
editableEnable editing (requires editor plugin)
draggableEnable dragging
dragBoundsDrag constraint area
dragBoundsTypeDrag constraint type
cursorCursor style on hover (CSS cursor supported)
State
statesPredefined states (requires state plugin)
stateCurrent state
buttonEnable button behavior (auto sync states)
hoverStyleHover style
pressStylePress style
focusStyleFocus style
selectedSelected state
selectedStyleSelected style
disabledDisabled state
disabledStyleDisabled style
Animation
animationAnimation system (timeline, keyframes, etc.)
transitionEnter transition
transitionOutExit transition
motionPathMotion path
motionPrecisionMotion sampling precision
motionPosition on motion path
motionRotationRotation offset along motion path
Relation
parentParent element
leaferLeafer engine instance
appApp instance (root)
isLeaferWhether element is Leafer root
leaferIsCreatedEngine creation completed
leaferIsReadyEngine ready (first layout done)
zoomLayerZoom/pan layer
Data
dataUser-defined data object
__Internal data instance
proxyDataReactive proxy for frameworks
pathPath data (SVG/Canvas commands supported)

All Methods

NameDescription
Layout
move()Translate the element incremental operation, supports optional animation transition
moveInner()Move the element in the inner coordinate system incremental operation, supports optional animation transition
moveWorld()Move the element in the world coordinate system incremental operation, supports optional animation transition
resizeWidth()Resize the width of an element/group bounding box, requires resize plugin
resizeHeight()Resize the height of an element/group bounding box, requires resize plugin
scaleResize()Convert scale operation into width/height changes incremental operation, requires resize plugin
scaleOf()Scale the element around the origin ( box coordinates ) incremental operation, supports optional animation transition
scaleOfWorld()Scale the element around the world origin ( world coordinates ) incremental operation, supports optional animation transition
flip()Flip/mirror the element in the world coordinate system, supports optional animation transition
rotateOf()Rotate the element around the origin ( box coordinates ) incremental operation, supports optional animation transition
rotateOfWorld()Rotate the element around the world origin ( world coordinates ) incremental operation, supports optional animation transition
skewOf()Skew the element around the origin ( box coordinates ) incremental operation, supports optional animation transition
skewOfWorld()Skew the element around the world origin ( world coordinates ) incremental operation, supports optional animation transition
Bounds
getBounds()Get the AABB bounding box
getLayoutBounds()Get the OBB bounding box, including scale/rotation/layout transforms
getLayoutPoints()Get the four corner points of the OBB bounding box
Transform
setTransform()Set local transform matrix, automatically decomposed into layout properties, supports optional animation transition
getTransform()Get transform matrix, supports relative matrices to any parent via relative
transform()Apply transform operation and decompose into layout properties incremental operation, supports optional animation transition
transformWorld()Same as transform(), but in world coordinate system, supports optional animation transition
Coordinate Conversion
getPagePoint()Convert world coordinates to page coordinates (supports delta movement)
getLocalPoint()Convert world coordinates to local coordinates (supports delta movement)
getInnerPoint()Convert world coordinates to inner coordinates (supports delta movement)
getBoxPoint()Convert world coordinates to box coordinates (supports delta movement)
getWorldPointByPage()Convert page coordinates to world coordinates (supports delta movement)
getWorldPointByLocal()Convert local coordinates to world coordinates (supports delta movement)
getInnerPointByLocal()Convert local coordinates to inner coordinates (supports delta movement)
getWorldPoint()Convert inner coordinates to world coordinates (supports delta movement)
getLocalPointByInner()Convert inner coordinates to local coordinates (supports delta movement)
getBoxPointByInner()Convert inner coordinates to box coordinates (supports delta movement)
getWorldPointByBox()Convert box coordinates to world coordinates (supports delta movement)
getInnerPointByBox()Convert box coordinates to inner coordinates (supports delta movement)
Actions
dropTo()Drag and drop the element into another parent container
focus()Focus the element. Only one element can be focused per App. Requires state plugin
Animation
animate()Run animation and return an animation instance, requires animation plugin
getMotionTotal()Get total length of motion path, requires motion path plugin
getMotionPoint()Get a point on the motion path (includes rotation), requires motion path plugin
Events
on()Listen to events
on_()Listen to events with bound this, returns event id (used with off_())
once()Listen to event once
off()Remove event listener
off_()Remove event listener (paired with on_())
emit()Manually dispatch event
emitEvent()Manually dispatch event (must be IEvent object)
Update
forceUpdate()Force update element (async), updates layout and rendering
updateLayout()Request layout update; ignored if no changes
forceRender()Force render only (async), does not update layout
nextRender()Execute callback on next render frame
removeNextRender()Remove next render callback
Search
find()Find elements by id/innerId/className/tag/function condition, returns array, requires find plugin
findTag()Find elements by tag
findOne()Find single element by id/innerId/className/tag/function, requires find plugin
findId()Find element by id
pick()Pick element by world coordinate point
Relation
waitParent()Wait until element has a parent
waitLeafer()Wait until element has a Leafer instance
Data
set()Set element style with optional animation transition
reset()Reset element style
get()Get stored attribute data
setAttr()Set attribute value
getAttr()Get attribute value
getComputedAttr()Get computed attribute value
clone()Clone element, optionally with new styles
Path
getPath()Get numeric path (Canvas drawing commands)
getPathString()Get string path (Canvas commands, including non-SVG commands)
Export
export()Async export element as image/json/canvas, supports screenshot/slicing, requires export plugin
syncExport()Sync export element
toJSON()Export JSON object
toString()Export JSON string
Remove
remove()Remove current element
destroy()Destroy current element

Static Methods

NameDescription
changeAttr()Modify default attribute values globally
addAttr()Add new attributes globally

Classification

We also provide a simple classification system to help you quickly understand the structure of the API, as shown below:

🎞️ Data

id / name

id     tag     name     className     innerId     innerName

parent / leafer

parent     leafer

Data / Clone

data     proxyData     clone()

Path data

getPath()     getPathString()     path

Import / Export

export()     toJSON()     toString

Remove / Destroy

remove()     destroy()

📐 Layout

Position / Scale / Rotation

position     size     scale     flip()     rotation     skew

Offset / resize

offset     resize

Pivot / Center

origin     around

Bounds / Transform

bounds     transform

Coordinate conversion

Coordinate conversion     Fast conversion

Layering / Placement

zIndex     dropTo()

🏼 Appearance

Opacity / Visibility

opacity     visible

Fill / Stroke

fill     stroke

Gradients / Images

linear     radial     angular     solid     image

Inner / Outer Shadow

shadow     innerShadow

Dim / Highlight

dim     bright

Clip / Erase

clip     mask     eraser

Blend mode

blendMode

🖱 Interaction

Interactivity

hittable     hitChildren     hitSelf     hitFill     hitStroke

Edit / Drag

editable     draggable

Cursor style

cursor

Interaction states

state     hover     press     focus     selected     disabled

Event handling

on() / once()     off()     emit()     Naming     Capture / Bubble     Simulated interaction

🐆 Animation

Animation

animation     animate()

Transition

transition

Motion path

motionPath     motion     getMotionTotal()     getMotionPoint()

🌴 Advanced

Drag constraints

dragBounds

Force rendering

forceUpdate()     updateLayout()     forceRender()     nextRender()

Search / Picking

find()     findOne()     pick()

Custom properties

changeAttr()     addAttr()

Released under the MIT License.