import*as Common from"../common/common.js";export class ContrastInfo extends Common.ObjectWrapper.ObjectWrapper{constructor(o){if(super(),this._isNull=!0,this._contrastRatio=null,this._contrastRatioAPCA=null,this._contrastRatioThresholds=null,this._contrastRationAPCAThreshold=0,this._fgColor=null,this._bgColor=null,!o)return;if(!o.computedFontSize||!o.computedFontWeight||!o.backgroundColors||1!==o.backgroundColors.length)return;this._isNull=!1,this._contrastRatioThresholds=Common.ColorUtils.getContrastThreshold(o.computedFontSize,o.computedFontWeight),this._contrastRationAPCAThreshold=Common.ColorUtils.getAPCAThreshold(o.computedFontSize,o.computedFontWeight);const t=o.backgroundColors[0],r=Common.Color.Color.parse(t);r&&this._setBgColorInternal(r)}isNull(){return this._isNull}setColor(o,t){this._fgColor=o,this._colorFormat=t,this._updateContrastRatio(),this.dispatchEventToListeners("ContrastInfoUpdated")}colorFormat(){return this._colorFormat}color(){return this._fgColor}contrastRatio(){return this._contrastRatio}contrastRatioAPCA(){return this._contrastRatioAPCA}contrastRatioAPCAThreshold(){return this._contrastRationAPCAThreshold}setBgColor(o){this._setBgColorInternal(o),this.dispatchEventToListeners("ContrastInfoUpdated")}_setBgColorInternal(o){if(this._bgColor=o,!this._fgColor)return;const t=this._fgColor.rgba();if(o.hasAlpha()){const r=Common.ColorUtils.blendColors(o.rgba(),t);this._bgColor=new Common.Color.Color(r,Common.Color.Format.RGBA)}this._contrastRatio=Common.ColorUtils.contrastRatio(t,this._bgColor.rgba()),this._contrastRatioAPCA=Common.ColorUtils.contrastRatioAPCA(this._fgColor.rgba(),this._bgColor.rgba())}bgColor(){return this._bgColor}_updateContrastRatio(){this._bgColor&&this._fgColor&&(this._contrastRatio=Common.ColorUtils.contrastRatio(this._fgColor.rgba(),this._bgColor.rgba()),this._contrastRatioAPCA=Common.ColorUtils.contrastRatioAPCA(this._fgColor.rgba(),this._bgColor.rgba()))}contrastRatioThreshold(o){return this._contrastRatioThresholds?this._contrastRatioThresholds[o]:null}}