var N = Object.defineProperty; var q = (u, e, t) => e in u ? N(u, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : u[e] = t; var b = (u, e, t) => q(u, typeof e != "symbol" ? e + "" : e, t); import { ColorKit as c, Tools as _, BooleanNumber as a, Rectangle as U, ColorBuilder as B } from "@univerjs/core"; import { CFRuleType as n, CFNumberOperator as l, CFValueType as C, EMPTY_ICON_TYPE as f, CFSubRuleType as o, CFTextOperator as g, createCfId as T, iconMap as M, ConditionalFormattingRuleModel as x, AddConditionalRuleMutation as S, DeleteConditionalRuleMutation as I, MoveConditionalRuleMutation as E, SetConditionalRuleMutation as k } from "@univerjs/sheets-conditional-formatting"; import { FRange as v, FWorkbook as F, FWorksheet as R } from "@univerjs/sheets/facade"; class d { constructor(e = {}) { b(this, "_rule", {}); this._rule = e, this._ensureAttr(this._rule, ["rule"]); } get _ruleConfig() { return this._rule.rule || null; } _getDefaultConfig(e = n.highlightCell) { switch (e) { case n.colorScale: return { type: e, config: [ { index: 0, color: new c("").toRgbString(), value: { type: C.min } }, { index: 0, color: new c("green").toRgbString(), value: { type: C.max } } ] }; case n.dataBar: return { type: e, isShowValue: !0, config: { min: { type: C.min }, max: { type: C.max }, positiveColor: new c("green").toRgbString(), nativeColor: new c("").toRgbString(), isGradient: !1 } }; case n.highlightCell: return { type: e, subType: o.text, operator: g.containsText, value: "abc", style: {} }; case n.iconSet: return { type: e, isShowValue: !0, config: [ { operator: l.greaterThanOrEqual, value: { type: C.min }, iconType: f, iconId: "" }, { operator: l.greaterThanOrEqual, value: { type: C.percentile, value: 0.5 }, iconType: f, iconId: "" }, { operator: l.lessThanOrEqual, value: { type: C.max }, iconType: f, iconId: "" } ] }; } } // eslint-disable-next-line ts/no-explicit-any _ensureAttr(e, t) { return t.reduce((r, s) => (r[s] || (r[s] = {}), r[s]), e), e; } build() { var r; this._rule.cfId || (this._rule.cfId = T()), this._rule.ranges || (this._rule.ranges = []), this._rule.stopIfTrue === void 0 && (this._rule.stopIfTrue = !1), (r = this._rule.rule) != null && r.type || (this._rule.rule.type = n.highlightCell, this._ensureAttr(this._rule, ["rule", "style"])); const e = this._getDefaultConfig(this._rule.rule.type); return { ...this._rule, rule: { ...e, ...this._rule.rule } }; } /** * Deep clone a current builder. * @returns {*} * @memberof ConditionalFormatRuleBuilder */ copy() { return new d(_.deepClone(this._rule)); } /** * Gets the scope of the current conditional format * @returns {*} * @memberof ConditionalFormatRuleBuilder */ getRanges() { return this._rule.ranges || []; } /** * Get the icon set mapping dictionary */ getIconMap() { return M; } /** * Create a conditional format ID. * @returns {*} * @memberof ConditionalFormatRuleBuilder */ createCfId() { return T(); } /** * Sets the scope for conditional formatting * @param {IRange[]} ranges * @returns {*} * @memberof ConditionalFormatRuleBuilder */ setRanges(e) { return this._rule.ranges = e, this; } } class i extends d { constructor(e = {}) { super(e), this._ensureAttr(this._rule, ["rule", "style"]); } copy() { return new i(_.deepClone(this._rule)); } /** * Set average rule * @param {IAverageHighlightCell['operator']} operator * @memberof ConditionalFormatHighlightRuleBuilder */ setAverage(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.average, t.operator = e, this; } /** * Set uniqueValues rule * @memberof ConditionalFormatHighlightRuleBuilder */ setUniqueValues() { const e = this._ruleConfig; return e.type = n.highlightCell, e.subType = o.uniqueValues, this; } /** * Set duplicateValues rule * @memberof ConditionalFormatHighlightRuleBuilder */ setDuplicateValues() { const e = this._ruleConfig; return e.type = n.highlightCell, e.subType = o.duplicateValues, this; } /** * Set rank rule * @param {{ isBottom: boolean, isPercent: boolean, value: number }} config * @param config.isBottom * @param config.isPercent * @param config.value * @memberof ConditionalFormatHighlightRuleBuilder */ setRank(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.rank, t.isBottom = e.isBottom, t.isPercent = e.isPercent, t.value = e.value, this; } /** * Sets the background color * @param {string} [color] * @returns {*} * @memberof ConditionalFormatRuleBuilder */ setBackground(e) { var t; if (((t = this._ruleConfig) == null ? void 0 : t.type) === n.highlightCell) if (e) { this._ensureAttr(this._ruleConfig, ["style", "bg"]); const r = new c(e); this._ruleConfig.style.bg.rgb = r.toRgbString(); } else delete this._ruleConfig.style.bg; return this; } /** * Set Bold * @param {boolean} isBold * @returns {*} * @memberof ConditionalFormatRuleBuilder */ setBold(e) { var t; return ((t = this._ruleConfig) == null ? void 0 : t.type) === n.highlightCell && (this._ensureAttr(this._ruleConfig, ["style"]), this._ruleConfig.style.bl = e ? a.TRUE : a.FALSE), this; } /** * Sets the font color * @param {string} [color] * @returns {*} * @memberof ConditionalFormatRuleBuilder */ setFontColor(e) { var t; if (((t = this._ruleConfig) == null ? void 0 : t.type) === n.highlightCell) if (e) { const r = new c(e); this._ensureAttr(this._ruleConfig, ["style", "cl"]), this._ruleConfig.style.cl.rgb = r.toRgbString(); } else delete this._ruleConfig.style.cl; return this; } /** * Set the text to italic * @param {boolean} isItalic * @returns {*} * @memberof ConditionalFormatRuleBuilder */ setItalic(e) { var t; return ((t = this._ruleConfig) == null ? void 0 : t.type) === n.highlightCell && (this._ensureAttr(this._ruleConfig, ["style"]), this._ruleConfig.style.it = e ? a.TRUE : a.FALSE), this; } /** * Set the strikethrough * @param {boolean} isStrikethrough * @returns {*} * @memberof ConditionalFormatRuleBuilder */ setStrikethrough(e) { var t; return ((t = this._ruleConfig) == null ? void 0 : t.type) === n.highlightCell && (this._ensureAttr(this._ruleConfig, ["style", "st"]), this._ruleConfig.style.st.s = e ? a.TRUE : a.FALSE), this; } /** * Set the underscore * @param {boolean} isUnderline * @returns {*} * @memberof ConditionalFormatRuleBuilder */ setUnderline(e) { var t; return ((t = this._ruleConfig) == null ? void 0 : t.type) === n.highlightCell && (this._ensureAttr(this._ruleConfig, ["style", "ul"]), this._ruleConfig.style.ul.s = e ? a.TRUE : a.FALSE), this; } /** * Sets the conditional formatting rule to fire when the cell is empty. */ whenCellEmpty() { const e = this._ruleConfig; return e.type = n.highlightCell, e.subType = o.text, e.value = "", e.operator = g.equal, this; } /** * Sets the conditional formatting rule to fire when the cell is not empty * @returns {*} * @memberof ConditionalFormatRuleBuilder */ whenCellNotEmpty() { const e = this._ruleConfig; return e.type = n.highlightCell, e.subType = o.text, e.value = "", e.operator = g.notEqual, this; } /** * Highlight when the date is in a time period, custom time is not supported. * @param {CFTimePeriodOperator} date * @returns {*} * @memberof ConditionalFormatRuleBuilder */ whenDate(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.timePeriod, t.operator = e, this; } /** * Sets a conditional formatting rule to fire when a given formula evaluates to true. * @param {string} formulaString formulaString start with' = ' * @memberof ConditionalFormatRuleBuilder */ whenFormulaSatisfied(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.formula, t.value = e, this; } /** * Sets the conditional formatting rule to fire when a number is between two specified values or equal to one of them. * @param {number} start * @param {number} end * @memberof ConditionalFormatRuleBuilder */ whenNumberBetween(e, t) { const r = Math.min(e, t), s = Math.max(e, t), h = this._ruleConfig; return h.type = n.highlightCell, h.subType = o.number, h.value = [r, s], h.operator = l.between, this; } /** * Sets the conditional formatting rule to fire when the number equals the given value * @param {number} value * @memberof ConditionalFormatRuleBuilder */ whenNumberEqualTo(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.number, t.value = e, t.operator = l.equal, this; } /** * Sets the conditional formatting rule to fire when the number is greater than the given value * @param {number} value * @memberof ConditionalFormatRuleBuilder */ whenNumberGreaterThan(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.number, t.value = e, t.operator = l.greaterThan, this; } /** * Sets a conditional formatting rule to fire when a number is greater than or equal to a given value. * @param {number} value * @memberof ConditionalFormatRuleBuilder */ whenNumberGreaterThanOrEqualTo(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.number, t.value = e, t.operator = l.greaterThanOrEqual, this; } /** * Sets a conditional formatting rule to fire when the number is less than the given value. * @param {number} value * @memberof ConditionalFormatRuleBuilder */ whenNumberLessThan(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.number, t.value = e, t.operator = l.lessThan, this; } /** * Sets the conditional formatting rule to fire when the value is less than or equal to the given value. * @param {number} value * @memberof ConditionalFormatRuleBuilder */ whenNumberLessThanOrEqualTo(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.number, t.value = e, t.operator = l.lessThanOrEqual, this; } /** * Sets a conditional formatting rule to fire when a number is not between two specified values and is not equal to them. * @param {number} start * @param {number} end * @memberof ConditionalFormatRuleBuilder */ whenNumberNotBetween(e, t) { const r = Math.min(e, t), s = Math.max(e, t), h = this._ruleConfig; return h.type = n.highlightCell, h.subType = o.number, h.value = [r, s], h.operator = l.notBetween, this; } /** * Sets the conditional formatting rule to fire when a number does not equal a given value. * @param value * @memberof ConditionalFormatRuleBuilder */ whenNumberNotEqualTo(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.number, t.value = e, t.operator = l.notEqual, this; } /** * Sets the conditional formatting rule to fire when the input contains the given value. * @param {string} text * @memberof ConditionalFormatRuleBuilder */ whenTextContains(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.text, t.value = e, t.operator = g.containsText, this; } /** * Sets a conditional formatting rule to fire when the input does not contain the given value. * @param {string} text * @memberof ConditionalFormatRuleBuilder */ whenTextDoesNotContain(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.text, t.value = e, t.operator = g.notContainsText, this; } /** * Sets a conditional formatting rule to fire when input ends with a specified value. * @param {string} text * @memberof ConditionalFormatRuleBuilder */ whenTextEndsWith(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.text, t.value = e, t.operator = g.endsWith, this; } /** * Sets the conditional formatting rule to fire when the input equals the given value. * @param {string} text * @memberof ConditionalFormatRuleBuilder */ whenTextEqualTo(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.text, t.value = e, t.operator = g.equal, this; } /** * Sets the conditional formatting rule to fire when the input value begins with the given value. * @param {string} text * @memberof ConditionalFormatRuleBuilder */ whenTextStartsWith(e) { const t = this._ruleConfig; return t.type = n.highlightCell, t.subType = o.text, t.value = e, t.operator = g.beginsWith, this; } } class w extends d { copy() { return new w(_.deepClone(this._rule)); } /** * Data bar settings * @param {{ * min: IValueConfig; * max: IValueConfig; * isGradient?: boolean; * positiveColor: string; * nativeColor: string; * isShowValue?: boolean; * }} config * @param config.min * @param config.max * @param config.isGradient * @param config.positiveColor * @param config.nativeColor * @param config.isShowValue * @memberof ConditionalFormatRuleBuilder */ setDataBar(e) { const t = this._ruleConfig; return t.type = n.dataBar, t.isShowValue = !!e.isShowValue, t.config = { min: e.min, max: e.max, positiveColor: e.positiveColor, nativeColor: e.nativeColor, isGradient: !!e.isGradient }, this; } } class p extends d { copy() { return new p(_.deepClone(this._rule)); } /** * Color scale set * @param {{ index: number; color: string; value: IValueConfig }[]} config * @memberof ConditionalFormatRuleBuilder */ setColorScale(e) { const t = this._ruleConfig; return t.type = n.colorScale, t.config = e, this; } } class y extends d { copy() { return new y(_.deepClone(this._rule)); } /** * * Icon Set * @param {{ iconConfigs: IIconSet['config'], isShowValue: boolean }} config * @param config.iconConfigs * @param config.isShowValue * @memberof ConditionalFormatRuleBuilder */ setIconSet(e) { const t = this._ruleConfig; return t.type = n.iconSet, t.config = e.iconConfigs, t.isShowValue = e.isShowValue, this; } } class m { constructor(e = {}) { this._initConfig = e; } build() { return new d(this._initConfig).build(); } /** * Set average rule * @param {IAverageHighlightCell['operator']} operator * @memberof ConditionalFormatHighlightRuleBuilder */ setAverage(e) { return new i(this._initConfig).setAverage(e); } /** * Set uniqueValues rule * @memberof ConditionalFormatHighlightRuleBuilder */ setUniqueValues() { return new i(this._initConfig).setUniqueValues(); } /** * Set duplicateValues rule * @memberof ConditionalFormatHighlightRuleBuilder */ setDuplicateValues() { return new i(this._initConfig).setDuplicateValues(); } /** * Set rank rule * @param {{ isBottom: boolean, isPercent: boolean, value: number }} config * @param config.isBottom * @param config.isPercent * @param config.value * @memberof ConditionalFormatHighlightRuleBuilder */ setRank(e) { return new i(this._initConfig).setRank(e); } /** * * Set iconSet rule * @param {{ iconConfigs: IIconSet['config'], isShowValue: boolean }} config * @param config.iconConfigs * @param config.isShowValue * @memberof ConditionalFormatRuleBuilder */ setIconSet(e) { return new y(this._initConfig).setIconSet(e); } /** * Set colorScale rule * @param {{ index: number; color: string; value: IValueConfig }[]} config * @memberof ConditionalFormatRuleBuilder */ setColorScale(e) { return new p(this._initConfig).setColorScale(e); } /** * Set dataBar rule * @param {{ * min: IValueConfig; * max: IValueConfig; * isGradient?: boolean; * positiveColor: string; * nativeColor: string; * isShowValue?: boolean; * }} config * @param config.min * @param config.max * @param config.isGradient * @param config.positiveColor * @param config.nativeColor * @param config.isShowValue * @memberof ConditionalFormatRuleBuilder */ setDataBar(e) { return new w(this._initConfig).setDataBar(e); } /** * Sets the background color * @param {string} [color] * @returns {*} * @memberof ConditionalFormatRuleBuilder */ setBackground(e) { return new i(this._initConfig).setBackground(e); } /** * Set Bold * @param {boolean} isBold * @returns {*} * @memberof ConditionalFormatRuleBuilder */ setBold(e) { return new i(this._initConfig).setBold(e); } /** * Sets the font color * @param {string} [color] * @returns {*} * @memberof ConditionalFormatRuleBuilder */ setFontColor(e) { return new i(this._initConfig).setFontColor(e); } /** * Set the text to italic * @param {boolean} isItalic * @returns {*} * @memberof ConditionalFormatRuleBuilder */ setItalic(e) { return new i(this._initConfig).setItalic(e); } /** * Set the strikethrough * @param {boolean} isStrikethrough * @returns {*} * @memberof ConditionalFormatRuleBuilder */ setStrikethrough(e) { return new i(this._initConfig).setStrikethrough(e); } /** * Set the underscore * @param {boolean} isUnderline * @returns {*} * @memberof ConditionalFormatRuleBuilder */ setUnderline(e) { return new i(this._initConfig).setUnderline(e); } /** * Sets the conditional formatting rule to fire when the cell is empty. */ whenCellEmpty() { return new i(this._initConfig).whenCellEmpty(); } /** * Sets the conditional formatting rule to fire when the cell is not empty * @returns {*} * @memberof ConditionalFormatRuleBuilder */ whenCellNotEmpty() { return new i(this._initConfig).whenCellNotEmpty(); } /** * Highlight when the date is in a time period, custom time is not supported. * @param {CFTimePeriodOperator} date * @returns {*} * @memberof ConditionalFormatRuleBuilder */ whenDate(e) { return new i(this._initConfig).whenDate(e); } /** * Sets a conditional formatting rule to fire when a given formula evaluates to true. * @param {string} formulaString formulaString start with' = ' * @memberof ConditionalFormatRuleBuilder */ whenFormulaSatisfied(e) { return new i(this._initConfig).whenFormulaSatisfied(e); } /** * Sets the conditional formatting rule to fire when a number is between two specified values or equal to one of them. * @param {number} start * @param {number} end * @memberof ConditionalFormatRuleBuilder */ whenNumberBetween(e, t) { return new i(this._initConfig).whenNumberBetween(e, t); } /** * Sets the conditional formatting rule to fire when the number equals the given value * @param {number} value * @memberof ConditionalFormatRuleBuilder */ whenNumberEqualTo(e) { return new i(this._initConfig).whenNumberEqualTo(e); } /** * Sets the conditional formatting rule to fire when the number is greater than the given value * @param {number} value * @memberof ConditionalFormatRuleBuilder */ whenNumberGreaterThan(e) { return new i(this._initConfig).whenNumberGreaterThan(e); } /** * Sets a conditional formatting rule to fire when a number is greater than or equal to a given value. * @param {number} value * @memberof ConditionalFormatRuleBuilder */ whenNumberGreaterThanOrEqualTo(e) { return new i(this._initConfig).whenNumberGreaterThanOrEqualTo(e); } /** * Sets a conditional formatting rule to fire when the number is less than the given value. * @param {number} value * @memberof ConditionalFormatRuleBuilder */ whenNumberLessThan(e) { return new i(this._initConfig).whenNumberLessThan(e); } /** * Sets the conditional formatting rule to fire when the value is less than or equal to the given value. * @param {number} value * @memberof ConditionalFormatRuleBuilder */ whenNumberLessThanOrEqualTo(e) { return new i(this._initConfig).whenNumberLessThanOrEqualTo(e); } /** * Sets a conditional formatting rule to fire when a number is not between two specified values and is not equal to them. * @param {number} start * @param {number} end * @memberof ConditionalFormatRuleBuilder */ whenNumberNotBetween(e, t) { return new i(this._initConfig).whenNumberNotBetween(e, t); } /** * Sets the conditional formatting rule to fire when a number does not equal a given value. * @param value * @memberof ConditionalFormatRuleBuilder */ whenNumberNotEqualTo(e) { return new i(this._initConfig).whenNumberNotEqualTo(e); } /** * Sets the conditional formatting rule to fire when the input contains the given value. * @param {string} text * @memberof ConditionalFormatRuleBuilder */ whenTextContains(e) { return new i(this._initConfig).whenTextContains(e); } /** * Sets a conditional formatting rule to fire when the input does not contain the given value. * @param {string} text * @memberof ConditionalFormatRuleBuilder */ whenTextDoesNotContain(e) { return new i(this._initConfig).whenTextDoesNotContain(e); } /** * Sets a conditional formatting rule to fire when input ends with a specified value. * @param {string} text * @memberof ConditionalFormatRuleBuilder */ whenTextEndsWith(e) { return new i(this._initConfig).whenTextEndsWith(e); } /** * Sets the conditional formatting rule to fire when the input equals the given value. * @param {string} text * @memberof ConditionalFormatRuleBuilder */ whenTextEqualTo(e) { return new i(this._initConfig).whenTextEqualTo(e); } /** * Sets the conditional formatting rule to fire when the input value begins with the given value. * @param {string} text * @memberof ConditionalFormatRuleBuilder */ whenTextStartsWith(e) { return new i(this._initConfig).whenTextStartsWith(e); } } class A extends v { _getConditionalFormattingRuleModel() { return this._injector.get(x); } getConditionalFormattingRules() { return [...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(), this._worksheet.getSheetId()) || []].filter((t) => t.ranges.some((r) => U.intersects(r, this._range))); } createConditionalFormattingRule() { return new m({ ranges: [this._range] }); } addConditionalFormattingRule(e) { const t = { rule: e, unitId: this._workbook.getUnitId(), subUnitId: this._worksheet.getSheetId() }; return this._commandService.syncExecuteCommand(S.id, t), this; } deleteConditionalFormattingRule(e) { const t = { unitId: this._workbook.getUnitId(), subUnitId: this._worksheet.getSheetId(), cfId: e }; return this._commandService.syncExecuteCommand(I.id, t), this; } moveConditionalFormattingRule(e, t, r = "after") { const s = { unitId: this._workbook.getUnitId(), subUnitId: this._worksheet.getSheetId(), start: { id: e, type: "self" }, end: { id: t, type: r } }; return this._commandService.syncExecuteCommand(E.id, s), this; } setConditionalFormattingRule(e, t) { const r = { unitId: this._workbook.getUnitId(), subUnitId: this._worksheet.getSheetId(), rule: t, cfId: e }; return this._commandService.syncExecuteCommand(k.id, r), this; } } v.extend(A); class D extends F { newColor() { return new B(); } } F.extend(D); class V extends R { _getConditionalFormattingRuleModel() { return this._injector.get(x); } getConditionalFormattingRules() { return [...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(), this._worksheet.getSheetId()) || []]; } createConditionalFormattingRule() { return new m(); } newConditionalFormattingRule() { return new m(); } addConditionalFormattingRule(e) { const t = { rule: e, unitId: this._workbook.getUnitId(), subUnitId: this._worksheet.getSheetId() }; return this._commandService.syncExecuteCommand(S.id, t), this; } deleteConditionalFormattingRule(e) { const t = { unitId: this._workbook.getUnitId(), subUnitId: this._worksheet.getSheetId(), cfId: e }; return this._commandService.syncExecuteCommand(I.id, t), this; } moveConditionalFormattingRule(e, t, r = "after") { const s = { unitId: this._workbook.getUnitId(), subUnitId: this._worksheet.getSheetId(), start: { id: e, type: "self" }, end: { id: t, type: r } }; return this._commandService.syncExecuteCommand(E.id, s), this; } setConditionalFormattingRule(e, t) { const r = { unitId: this._workbook.getUnitId(), subUnitId: this._worksheet.getSheetId(), rule: t, cfId: e }; return this._commandService.syncExecuteCommand(k.id, r), this; } } R.extend(V); export { m as FConditionalFormattingBuilder };