YUI.add("widget-position-constrain",function(t,n){var l,e="constrain",i=t.Node,o="region";function s(t){}s.ATTRS={constrain:{value:null,setter:"_setConstrain"},preventOverlap:{value:!1}},l=s._PREVENT_OVERLAP={x:{tltr:1,blbr:1,brbl:1,trtl:1},y:{trbr:1,tlbl:1,bltl:1,brtr:1}},s.prototype={initializer:function(){this._posNode||t.error("WidgetPosition needs to be added to the Widget, before WidgetPositionConstrain is added"),t.after(this._bindUIPosConstrained,this,"bindUI")},getConstrainedXY:function(t,n){n=n||this.get(e);var n=this._getRegion(!0===n?null:n),i=this._posNode.get(o);return[this._constrain(t[0],"x",i,n),this._constrain(t[1],"y",i,n)]},constrain:function(t,n){var n=n||this.get(e);n&&(t=t||this.get("xy"),(n=this.getConstrainedXY(t,n))[0]===t[0]&&n[1]===t[1]||this.set("xy",n,{constrained:!0}))},_setConstrain:function(t){return!0===t?t:i.one(t)},_constrain:function(t,n,i,e){var o,s;return e&&(this.get("preventOverlap")&&(t=this._preventOverlap(t,n,i,e)),o=(n="x"==n)?e.width:e.height,i=n?i.width:i.height,s=n?e.left:e.top,n=n?e.right-i:e.bottom-i,(t<s||n<t)&&(!(i<o)||t<s?t=s:n<t&&(t=n))),t},_preventOverlap:function(t,n,i,e){var o,s,r,a,h,g=this.get("align"),d="x"===n;return g&&g.points&&l[n][g.points.join("")]&&((n=this._getRegion(g.node))&&(o=d?i.width:i.height,s=d?n.left:n.top,r=d?n.right:n.bottom,a=d?n.left-e.left:n.top-e.top,h=d?e.right-n.right:e.bottom-n.bottom),s<t?h<o&&o<a&&(t=s-o):a<o&&o<h&&(t=r)),t},_bindUIPosConstrained:function(){this.after("constrainChange",this._afterConstrainChange),this._enableConstraints(this.get(e))},_afterConstrainChange:function(t){this._enableConstraints(t.newVal)},_enableConstraints:function(t){t?(this.constrain(),this._cxyHandle=this._cxyHandle||this.on("constrain|xyChange",this._constrainOnXYChange)):this._cxyHandle&&(this._cxyHandle.detach(),this._cxyHandle=null)},_constrainOnXYChange:function(t){t.constrained||(t.newVal=this.getConstrainedXY(t.newVal))},_getRegion:function(t){var n;return t?(t=i.one(t))&&(n=t.get(o)):n=this._posNode.get("viewportRegion"),n}},t.WidgetPositionConstrain=s},"patched-v3.18.4",{requires:["widget-position"]});