import * as kiwi from '@lume/kiwi' ; import Attribute from './Attribute.js' ; namespace class SubView { declare _name ; declare _type ; declare _solver ; declare _attr ; declare _intrinsicWidth : number ; declare _intrinsicHeight : number ; constructor ( options ) { this . _name = options . name ; this . _type = options . type ; this . _solver = options . solver ; this . _attr = { } ; if ( ! options . name ) { this . _attr [ Attribute . LEFT ] = new kiwi . Variable ( ) ; this . _solver . addConstraint ( new kiwi . Constraint ( this . _attr [ Attribute . LEFT ] , kiwi . Operator . Eq , 0 ) ) ; this . _attr [ Attribute . TOP ] = new kiwi . Variable ( ) ; this . _solver . addConstraint ( new kiwi . Constraint ( this . _attr [ Attribute . TOP ] , kiwi . Operator . Eq , 0 ) ) ; this . _attr [ Attribute . ZINDEX ] = new kiwi . Variable ( ) ; this . _solver . addConstraint ( new kiwi . Constraint ( this . _attr [ Attribute . ZINDEX ] , kiwi . Operator . Eq , 0 ) ) ; } } toJSON ( ) { return { name : this . name , left : this . left , top : this . top , width : this . width , height : this . height , } ; } toString ( ) { JSON . stringify ( this . toJSON ( ) , undefined , 2 ) ; } readonly type { String } get name ( ) { return this . _name ; } readonly type { Number } get left ( ) { return this . _getAttrValue ( Attribute . LEFT ) ; } readonly type { Number } get right ( ) { return this . _getAttrValue ( Attribute . RIGHT ) ; } type { Number } get width ( ) { return this . _getAttrValue ( Attribute . WIDTH ) ; } readonly type { Number } get height ( ) { return this . _getAttrValue ( Attribute . HEIGHT ) ; } type { Number } get intrinsicWidth ( ) : number { return this . _intrinsicWidth ; } set intrinsicWidth ( value ) { if ( value !== undefined && value !== this . _intrinsicWidth ) { const attr = this . _getAttr ( Attribute . WIDTH ) ; if ( this . _intrinsicWidth === undefined ) { this . _solver . addEditVariable ( attr , kiwi . Strength . create ( this . _name ? 998 : 999 , 1000 , 1000 ) ) ; } this . _intrinsicWidth = value ; this . _solver . suggestValue ( attr , value ) ; this . _solver . updateVariables ( ) ; } } type { Number } get intrinsicHeight ( ) : number { return this . _intrinsicHeight ; } set intrinsicHeight ( value ) { if ( value !== undefined && value !== this . _intrinsicHeight ) { const attr = this . _getAttr ( Attribute . HEIGHT ) ; if ( this . _intrinsicHeight === undefined ) { this . _solver . addEditVariable ( attr , kiwi . Strength . create ( this . _name ? 998 : 999 , 1000 , 1000 ) ) ; } this . _intrinsicHeight = value ; this . _solver . suggestValue ( attr , value ) ; this . _solver . updateVariables ( ) ; } } readonly type { Number } get top ( ) { return this . _getAttrValue ( Attribute . TOP ) ; } readonly type { Number } get bottom ( ) { return this . _getAttrValue ( Attribute . BOTTOM ) ; } readonly type { Number } get centerX ( ) { return this . _getAttrValue ( Attribute . CENTERX ) ; } readonly type { Number } get centerY ( ) { return this . _getAttrValue ( Attribute . CENTERY ) ; } readonly type { Number } get zIndex ( ) { return this . _getAttrValue ( Attribute . ZINDEX ) ; } readonly type { String } get type ( ) { return this . _type ; } param { String | Attribute } attr return { Number } getValue ( attr ) { return this . _attr [ attr ] ? this . _attr [ attr ] . value ( ) : undefined ; } private _getAttr ( attr ) { if ( this . _attr [ attr ] ) { return this . _attr [ attr ] ; } this . _attr [ attr ] = new kiwi . Variable ( ) ; switch ( attr ) { case Attribute . RIGHT : this . _getAttr ( Attribute . LEFT ) ; this . _getAttr ( Attribute . WIDTH ) ; this . _solver . addConstraint ( new kiwi . Constraint ( this . _attr [ attr ] , kiwi . Operator . Eq , this . _attr [ Attribute . LEFT ] . plus ( this . _attr [ Attribute . WIDTH ] ) ) ) ; break ; case Attribute . BOTTOM : this . _getAttr ( Attribute . TOP ) ; this . _getAttr ( Attribute . HEIGHT ) ; this . _solver . addConstraint ( new kiwi . Constraint ( this . _attr [ attr ] , kiwi . Operator . Eq , this . _attr [ Attribute . TOP ] . plus ( this . _attr [ Attribute . HEIGHT ] ) ) ) ; break ; case Attribute . CENTERX : this . _getAttr ( Attribute . LEFT ) ; this . _getAttr ( Attribute . WIDTH ) ; this . _solver . addConstraint ( new kiwi . Constraint ( this . _attr [ attr ] , kiwi . Operator . Eq , this . _attr [ Attribute . LEFT ] . plus ( this . _attr [ Attribute . WIDTH ] . divide ( 2 ) ) ) ) ; break ; case Attribute . CENTERY : this . _getAttr ( Attribute . TOP ) ; this . _getAttr ( Attribute . HEIGHT ) ; this . _solver . addConstraint ( new kiwi . Constraint ( this . _attr [ attr ] , kiwi . Operator . Eq , this . _attr [ Attribute . TOP ] . plus ( this . _attr [ Attribute . HEIGHT ] . divide ( 2 ) ) ) ) ; break ; } this . _solver . updateVariables ( ) ; return this . _attr [ attr ] ; } private _getAttrValue ( attr ) { return this . _getAttr ( attr ) . value ( ) ; } } export default SubView ;