@univerjs/sheets-conditional-formatting 0.20.1 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/cjs/facade.js CHANGED
@@ -1 +1,2147 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/sheets-conditional-formatting`),n=require(`@univerjs/sheets/facade`),r=require(`@univerjs/core/facade`);function i(e){"@babel/helpers - typeof";return i=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},i(e)}function a(e,t){if(i(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(i(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function o(e){var t=a(e,`string`);return i(t)==`symbol`?t:t+``}function s(e,t,n){return(t=o(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var c=class n{get _ruleConfig(){return this._rule.rule||null}_getDefaultConfig(n=t.CFRuleType.highlightCell){switch(n){case t.CFRuleType.colorScale:return{type:n,config:[{index:0,color:new e.ColorKit(``).toRgbString(),value:{type:t.CFValueType.min}},{index:0,color:new e.ColorKit(`green`).toRgbString(),value:{type:t.CFValueType.max}}]};case t.CFRuleType.dataBar:return{type:n,isShowValue:!0,config:{min:{type:t.CFValueType.min},max:{type:t.CFValueType.max},positiveColor:new e.ColorKit(`green`).toRgbString(),nativeColor:new e.ColorKit(``).toRgbString(),isGradient:!1}};case t.CFRuleType.highlightCell:return{type:n,subType:t.CFSubRuleType.text,operator:t.CFTextOperator.containsText,value:`abc`,style:{}};case t.CFRuleType.iconSet:return{type:n,isShowValue:!0,config:[{operator:t.CFNumberOperator.greaterThanOrEqual,value:{type:t.CFValueType.min},iconType:t.EMPTY_ICON_TYPE,iconId:``},{operator:t.CFNumberOperator.greaterThanOrEqual,value:{type:t.CFValueType.percentile,value:.5},iconType:t.EMPTY_ICON_TYPE,iconId:``},{operator:t.CFNumberOperator.lessThanOrEqual,value:{type:t.CFValueType.max},iconType:t.EMPTY_ICON_TYPE,iconId:``}]}}}constructor(e={}){s(this,`_rule`,{}),this._rule=e,this._ensureAttr(this._rule,[`rule`])}_ensureAttr(e,t){return t.reduce((e,t)=>(e[t]||(e[t]={}),e[t]),e),e}build(){var e;this._rule.cfId||(this._rule.cfId=(0,t.createCfId)()),this._rule.ranges||(this._rule.ranges=[]),this._rule.stopIfTrue===void 0&&(this._rule.stopIfTrue=!1),(e=this._rule.rule)!=null&&e.type||(this._rule.rule.type=t.CFRuleType.highlightCell,this._ensureAttr(this._rule,[`rule`,`style`]));let n=this._getDefaultConfig(this._rule.rule.type);return{...this._rule,rule:{...n,...this._rule.rule}}}copy(){let r=e.Tools.deepClone(this._rule);return r.cfId&&(r.cfId=(0,t.createCfId)()),new n(r)}getRanges(){return this._rule.ranges||[]}getIconMap(){return t.iconMap}createCfId(){return(0,t.createCfId)()}setRanges(e){return this._rule.ranges=e,this}},l=class n extends c{constructor(e={}){super(e),this._ensureAttr(this._rule,[`rule`,`style`])}copy(){let r=e.Tools.deepClone(this._rule);return r.cfId&&(r.cfId=(0,t.createCfId)()),new n(r)}setAverage(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.average,n.operator=e,this}setUniqueValues(){let e=this._ruleConfig;return e.type=t.CFRuleType.highlightCell,e.subType=t.CFSubRuleType.uniqueValues,this}setDuplicateValues(){let e=this._ruleConfig;return e.type=t.CFRuleType.highlightCell,e.subType=t.CFSubRuleType.duplicateValues,this}setRank(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.rank,n.isBottom=e.isBottom,n.isPercent=e.isPercent,n.value=e.value,this}setBackground(n){var r;if(((r=this._ruleConfig)==null?void 0:r.type)===t.CFRuleType.highlightCell)if(n){this._ensureAttr(this._ruleConfig,[`style`,`bg`]);let t=new e.ColorKit(n);this._ruleConfig.style.bg.rgb=t.toRgbString()}else delete this._ruleConfig.style.bg;return this}setBold(n){var r;return((r=this._ruleConfig)==null?void 0:r.type)===t.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,[`style`]),this._ruleConfig.style.bl=n?e.BooleanNumber.TRUE:e.BooleanNumber.FALSE),this}setFontColor(n){var r;if(((r=this._ruleConfig)==null?void 0:r.type)===t.CFRuleType.highlightCell)if(n){let t=new e.ColorKit(n);this._ensureAttr(this._ruleConfig,[`style`,`cl`]),this._ruleConfig.style.cl.rgb=t.toRgbString()}else delete this._ruleConfig.style.cl;return this}setItalic(n){var r;return((r=this._ruleConfig)==null?void 0:r.type)===t.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,[`style`]),this._ruleConfig.style.it=n?e.BooleanNumber.TRUE:e.BooleanNumber.FALSE),this}setStrikethrough(n){var r;return((r=this._ruleConfig)==null?void 0:r.type)===t.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,[`style`,`st`]),this._ruleConfig.style.st.s=n?e.BooleanNumber.TRUE:e.BooleanNumber.FALSE),this}setUnderline(n){var r;return((r=this._ruleConfig)==null?void 0:r.type)===t.CFRuleType.highlightCell&&(this._ensureAttr(this._ruleConfig,[`style`,`ul`]),this._ruleConfig.style.ul.s=n?e.BooleanNumber.TRUE:e.BooleanNumber.FALSE),this}whenCellEmpty(){let e=this._ruleConfig;return e.type=t.CFRuleType.highlightCell,e.subType=t.CFSubRuleType.text,e.value=``,e.operator=t.CFTextOperator.equal,this}whenCellNotEmpty(){let e=this._ruleConfig;return e.type=t.CFRuleType.highlightCell,e.subType=t.CFSubRuleType.text,e.value=``,e.operator=t.CFTextOperator.notEqual,this}whenDate(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.timePeriod,n.operator=e,this}whenFormulaSatisfied(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.formula,n.value=e,this}whenNumberBetween(e,n){let r=Math.min(e,n),i=Math.max(e,n),a=this._ruleConfig;return a.type=t.CFRuleType.highlightCell,a.subType=t.CFSubRuleType.number,a.value=[r,i],a.operator=t.CFNumberOperator.between,this}whenNumberEqualTo(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.number,n.value=e,n.operator=t.CFNumberOperator.equal,this}whenNumberGreaterThan(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.number,n.value=e,n.operator=t.CFNumberOperator.greaterThan,this}whenNumberGreaterThanOrEqualTo(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.number,n.value=e,n.operator=t.CFNumberOperator.greaterThanOrEqual,this}whenNumberLessThan(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.number,n.value=e,n.operator=t.CFNumberOperator.lessThan,this}whenNumberLessThanOrEqualTo(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.number,n.value=e,n.operator=t.CFNumberOperator.lessThanOrEqual,this}whenNumberNotBetween(e,n){let r=Math.min(e,n),i=Math.max(e,n),a=this._ruleConfig;return a.type=t.CFRuleType.highlightCell,a.subType=t.CFSubRuleType.number,a.value=[r,i],a.operator=t.CFNumberOperator.notBetween,this}whenNumberNotEqualTo(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.number,n.value=e,n.operator=t.CFNumberOperator.notEqual,this}whenTextContains(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.text,n.value=e,n.operator=t.CFTextOperator.containsText,this}whenTextDoesNotContain(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.text,n.value=e,n.operator=t.CFTextOperator.notContainsText,this}whenTextEndsWith(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.text,n.value=e,n.operator=t.CFTextOperator.endsWith,this}whenTextEqualTo(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.text,n.value=e,n.operator=t.CFTextOperator.equal,this}whenTextStartsWith(e){let n=this._ruleConfig;return n.type=t.CFRuleType.highlightCell,n.subType=t.CFSubRuleType.text,n.value=e,n.operator=t.CFTextOperator.beginsWith,this}},u=class n extends c{copy(){let r=e.Tools.deepClone(this._rule);return r.cfId&&(r.cfId=(0,t.createCfId)()),new n(r)}setDataBar(e){let n=this._ruleConfig;return n.type=t.CFRuleType.dataBar,n.isShowValue=!!e.isShowValue,n.config={min:e.min,max:e.max,positiveColor:e.positiveColor,nativeColor:e.nativeColor,isGradient:!!e.isGradient},this}},d=class n extends c{copy(){let r=e.Tools.deepClone(this._rule);return r.cfId&&(r.cfId=(0,t.createCfId)()),new n(r)}setColorScale(e){let n=this._ruleConfig;return n.type=t.CFRuleType.colorScale,n.config=e,this}},f=class n extends c{copy(){let r=e.Tools.deepClone(this._rule);return r.cfId&&(r.cfId=(0,t.createCfId)()),new n(r)}setIconSet(e){let n=this._ruleConfig;return n.type=t.CFRuleType.iconSet,n.config=e.iconConfigs,n.isShowValue=e.isShowValue,this}},p=class{constructor(e={}){this._initConfig=e}build(){return new c(this._initConfig).build()}setAverage(e){return new l(this._initConfig).setAverage(e)}setUniqueValues(){return new l(this._initConfig).setUniqueValues()}setDuplicateValues(){return new l(this._initConfig).setDuplicateValues()}setRank(e){return new l(this._initConfig).setRank(e)}getIconMap(){return t.iconMap}setIconSet(e){return new f(this._initConfig).setIconSet(e)}setColorScale(e){return new d(this._initConfig).setColorScale(e)}setDataBar(e){return new u(this._initConfig).setDataBar(e)}setBackground(e){return new l(this._initConfig).setBackground(e)}setBold(e){return new l(this._initConfig).setBold(e)}setFontColor(e){return new l(this._initConfig).setFontColor(e)}setItalic(e){return new l(this._initConfig).setItalic(e)}setStrikethrough(e){return new l(this._initConfig).setStrikethrough(e)}setUnderline(e){return new l(this._initConfig).setUnderline(e)}whenCellEmpty(){return new l(this._initConfig).whenCellEmpty()}whenCellNotEmpty(){return new l(this._initConfig).whenCellNotEmpty()}whenDate(e){return new l(this._initConfig).whenDate(e)}whenFormulaSatisfied(e){return new l(this._initConfig).whenFormulaSatisfied(e)}whenNumberBetween(e,t){return new l(this._initConfig).whenNumberBetween(e,t)}whenNumberEqualTo(e){return new l(this._initConfig).whenNumberEqualTo(e)}whenNumberGreaterThan(e){return new l(this._initConfig).whenNumberGreaterThan(e)}whenNumberGreaterThanOrEqualTo(e){return new l(this._initConfig).whenNumberGreaterThanOrEqualTo(e)}whenNumberLessThan(e){return new l(this._initConfig).whenNumberLessThan(e)}whenNumberLessThanOrEqualTo(e){return new l(this._initConfig).whenNumberLessThanOrEqualTo(e)}whenNumberNotBetween(e,t){return new l(this._initConfig).whenNumberNotBetween(e,t)}whenNumberNotEqualTo(e){return new l(this._initConfig).whenNumberNotEqualTo(e)}whenTextContains(e){return new l(this._initConfig).whenTextContains(e)}whenTextDoesNotContain(e){return new l(this._initConfig).whenTextDoesNotContain(e)}whenTextEndsWith(e){return new l(this._initConfig).whenTextEndsWith(e)}whenTextEqualTo(e){return new l(this._initConfig).whenTextEqualTo(e)}whenTextStartsWith(e){return new l(this._initConfig).whenTextStartsWith(e)}},m=class extends n.FRange{_getConditionalFormattingRuleModel(){return this._injector.get(t.ConditionalFormattingRuleModel)}getConditionalFormattingRules(){return[...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(),this._worksheet.getSheetId())||[]].filter(t=>t.ranges.some(t=>e.Rectangle.intersects(t,this._range)))}createConditionalFormattingRule(){return new p({ranges:[this._range]})}addConditionalFormattingRule(e){let n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:e};return this._commandService.syncExecuteCommand(t.AddCfCommand.id,n),this}deleteConditionalFormattingRule(e){let n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cfId:e};return this._commandService.syncExecuteCommand(t.DeleteCfCommand.id,n),this}moveConditionalFormattingRule(e,n,r=`after`){let i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),start:{id:e,type:`self`},end:{id:n,type:r}};return this._commandService.syncExecuteCommand(t.MoveCfCommand.id,i),this}setConditionalFormattingRule(e,n){let r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:n,cfId:e};return this._commandService.syncExecuteCommand(t.SetCfCommand.id,r),this}clearConditionalFormatRules(){let e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),ranges:[this._range]};return this._commandService.syncExecuteCommand(t.ClearRangeCfCommand.id,e),this}};n.FRange.extend(m);var h=class extends n.FWorksheet{_getConditionalFormattingRuleModel(){return this._injector.get(t.ConditionalFormattingRuleModel)}getConditionalFormattingRules(){return[...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(),this._worksheet.getSheetId())||[]]}createConditionalFormattingRule(){return new p}newConditionalFormattingRule(){return new p}addConditionalFormattingRule(e){let n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),rule:e};return this._commandService.syncExecuteCommand(t.AddCfCommand.id,n),this}deleteConditionalFormattingRule(e){let n={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cfId:e};return this._commandService.syncExecuteCommand(t.DeleteCfCommand.id,n),this}moveConditionalFormattingRule(e,n,r=`after`){let i={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),start:{id:e,type:`self`},end:{id:n,type:r}};return this._commandService.syncExecuteCommand(t.MoveCfCommand.id,i),this}setConditionalFormattingRule(e,n){let r={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId(),cfId:e,rule:n};return this._commandService.syncExecuteCommand(t.SetCfCommand.id,r),this}clearConditionalFormatRules(){let e={unitId:this._workbook.getUnitId(),subUnitId:this._worksheet.getSheetId()};return this._commandService.syncExecuteCommand(t.ClearWorksheetCfCommand.id,e),this}};n.FWorksheet.extend(h);var g=class extends r.FEnum{get ConditionFormatNumberOperatorEnum(){return t.CFNumberOperator}get ConditionFormatTimePeriodOperatorEnum(){return t.CFTimePeriodOperator}};r.FEnum.extend(g),exports.FConditionalFormattingBuilder=p;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ let _univerjs_core = require("@univerjs/core");
3
+ let _univerjs_sheets_conditional_formatting = require("@univerjs/sheets-conditional-formatting");
4
+ let _univerjs_sheets_facade = require("@univerjs/sheets/facade");
5
+ let _univerjs_core_facade = require("@univerjs/core/facade");
6
+
7
+ //#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
8
+ function _typeof(o) {
9
+ "@babel/helpers - typeof";
10
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
11
+ return typeof o;
12
+ } : function(o) {
13
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
14
+ }, _typeof(o);
15
+ }
16
+
17
+ //#endregion
18
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
19
+ function toPrimitive(t, r) {
20
+ if ("object" != _typeof(t) || !t) return t;
21
+ var e = t[Symbol.toPrimitive];
22
+ if (void 0 !== e) {
23
+ var i = e.call(t, r || "default");
24
+ if ("object" != _typeof(i)) return i;
25
+ throw new TypeError("@@toPrimitive must return a primitive value.");
26
+ }
27
+ return ("string" === r ? String : Number)(t);
28
+ }
29
+
30
+ //#endregion
31
+ //#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
32
+ function toPropertyKey(t) {
33
+ var i = toPrimitive(t, "string");
34
+ return "symbol" == _typeof(i) ? i : i + "";
35
+ }
36
+
37
+ //#endregion
38
+ //#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
39
+ function _defineProperty(e, r, t) {
40
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
41
+ value: t,
42
+ enumerable: !0,
43
+ configurable: !0,
44
+ writable: !0
45
+ }) : e[r] = t, e;
46
+ }
47
+
48
+ //#endregion
49
+ //#region src/facade/f-conditional-formatting-builder.ts
50
+ /**
51
+ * @ignore
52
+ * @hideconstructor
53
+ */
54
+ var ConditionalFormatRuleBaseBuilder = class ConditionalFormatRuleBaseBuilder {
55
+ get _ruleConfig() {
56
+ return this._rule.rule || null;
57
+ }
58
+ _getDefaultConfig(type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell) {
59
+ switch (type) {
60
+ case _univerjs_sheets_conditional_formatting.CFRuleType.colorScale: return {
61
+ type,
62
+ config: [{
63
+ index: 0,
64
+ color: new _univerjs_core.ColorKit("").toRgbString(),
65
+ value: { type: _univerjs_sheets_conditional_formatting.CFValueType.min }
66
+ }, {
67
+ index: 0,
68
+ color: new _univerjs_core.ColorKit("green").toRgbString(),
69
+ value: { type: _univerjs_sheets_conditional_formatting.CFValueType.max }
70
+ }]
71
+ };
72
+ case _univerjs_sheets_conditional_formatting.CFRuleType.dataBar: return {
73
+ type,
74
+ isShowValue: true,
75
+ config: {
76
+ min: { type: _univerjs_sheets_conditional_formatting.CFValueType.min },
77
+ max: { type: _univerjs_sheets_conditional_formatting.CFValueType.max },
78
+ positiveColor: new _univerjs_core.ColorKit("green").toRgbString(),
79
+ nativeColor: new _univerjs_core.ColorKit("").toRgbString(),
80
+ isGradient: false
81
+ }
82
+ };
83
+ case _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell: return {
84
+ type,
85
+ subType: _univerjs_sheets_conditional_formatting.CFSubRuleType.text,
86
+ operator: _univerjs_sheets_conditional_formatting.CFTextOperator.containsText,
87
+ value: "abc",
88
+ style: {}
89
+ };
90
+ case _univerjs_sheets_conditional_formatting.CFRuleType.iconSet: return {
91
+ type,
92
+ isShowValue: true,
93
+ config: [
94
+ {
95
+ operator: _univerjs_sheets_conditional_formatting.CFNumberOperator.greaterThanOrEqual,
96
+ value: { type: _univerjs_sheets_conditional_formatting.CFValueType.min },
97
+ iconType: _univerjs_sheets_conditional_formatting.EMPTY_ICON_TYPE,
98
+ iconId: ""
99
+ },
100
+ {
101
+ operator: _univerjs_sheets_conditional_formatting.CFNumberOperator.greaterThanOrEqual,
102
+ value: {
103
+ type: _univerjs_sheets_conditional_formatting.CFValueType.percentile,
104
+ value: .5
105
+ },
106
+ iconType: _univerjs_sheets_conditional_formatting.EMPTY_ICON_TYPE,
107
+ iconId: ""
108
+ },
109
+ {
110
+ operator: _univerjs_sheets_conditional_formatting.CFNumberOperator.lessThanOrEqual,
111
+ value: { type: _univerjs_sheets_conditional_formatting.CFValueType.max },
112
+ iconType: _univerjs_sheets_conditional_formatting.EMPTY_ICON_TYPE,
113
+ iconId: ""
114
+ }
115
+ ]
116
+ };
117
+ }
118
+ }
119
+ constructor(initRule = {}) {
120
+ _defineProperty(this, "_rule", {});
121
+ this._rule = initRule;
122
+ this._ensureAttr(this._rule, ["rule"]);
123
+ }
124
+ _ensureAttr(obj, keys) {
125
+ keys.reduce((pre, cur) => {
126
+ if (!pre[cur]) pre[cur] = {};
127
+ return pre[cur];
128
+ }, obj);
129
+ return obj;
130
+ }
131
+ /**
132
+ * Constructs a conditional format rule from the settings applied to the builder.
133
+ * @returns {IConditionFormattingRule} The conditional format rule.
134
+ * @example
135
+ * ```typescript
136
+ * const fWorkbook = univerAPI.getActiveWorkbook();
137
+ * const fWorksheet = fWorkbook.getActiveSheet();
138
+ *
139
+ * // Create a conditional formatting rule that highlights cells with no content in red for the range A1:D10.
140
+ * const fRange = fWorksheet.getRange('A1:D10');
141
+ * const rule = fWorksheet.newConditionalFormattingRule()
142
+ * .whenCellEmpty()
143
+ * .setBackground('#FF0000')
144
+ * .setRanges([fRange.getRange()])
145
+ * .build();
146
+ * fWorksheet.addConditionalFormattingRule(rule);
147
+ * ```
148
+ */
149
+ build() {
150
+ var _this$_rule$rule;
151
+ if (!this._rule.cfId) this._rule.cfId = (0, _univerjs_sheets_conditional_formatting.createCfId)();
152
+ if (!this._rule.ranges) this._rule.ranges = [];
153
+ if (this._rule.stopIfTrue === void 0) this._rule.stopIfTrue = false;
154
+ if (!((_this$_rule$rule = this._rule.rule) === null || _this$_rule$rule === void 0 ? void 0 : _this$_rule$rule.type)) {
155
+ this._rule.rule.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
156
+ this._ensureAttr(this._rule, ["rule", "style"]);
157
+ }
158
+ const defaultConfig = this._getDefaultConfig(this._rule.rule.type);
159
+ return {
160
+ ...this._rule,
161
+ rule: {
162
+ ...defaultConfig,
163
+ ...this._rule.rule
164
+ }
165
+ };
166
+ }
167
+ /**
168
+ * Deep clone a current builder.
169
+ * @returns {ConditionalFormatRuleBaseBuilder} A new builder with the same settings as the original.
170
+ * @example
171
+ * ```typescript
172
+ * const fWorkbook = univerAPI.getActiveWorkbook();
173
+ * const fWorksheet = fWorkbook.getActiveSheet();
174
+ *
175
+ * // Create a conditional formatting rule that highlights cells with no content in red for the range A1:D10.
176
+ * const fRange = fWorksheet.getRange('A1:D10');
177
+ * const builder = fWorksheet.newConditionalFormattingRule()
178
+ * .whenCellEmpty()
179
+ * .setBackground('#FF0000')
180
+ * .setRanges([fRange.getRange()]);
181
+ * fWorksheet.addConditionalFormattingRule(builder.build());
182
+ *
183
+ * // Copy the rule and change the background color to green for the range A1:B2.
184
+ * const newRange = fWorksheet.getRange('A1:B2');
185
+ * const newBuilder = builder.copy()
186
+ * .setBackground('#00FF00')
187
+ * .setRanges([newRange.getRange()]);
188
+ * fWorksheet.addConditionalFormattingRule(newBuilder.build());
189
+ * ```
190
+ */
191
+ copy() {
192
+ const newRule = _univerjs_core.Tools.deepClone(this._rule);
193
+ if (newRule.cfId) newRule.cfId = (0, _univerjs_sheets_conditional_formatting.createCfId)();
194
+ return new ConditionalFormatRuleBaseBuilder(newRule);
195
+ }
196
+ /**
197
+ * Gets the scope of the current conditional format.
198
+ * @returns {IRange[]} The ranges to which the conditional format applies.
199
+ */
200
+ getRanges() {
201
+ return this._rule.ranges || [];
202
+ }
203
+ /**
204
+ * Get the icon set mapping dictionary.
205
+ * @returns {Record<string, string[]>} The icon set mapping dictionary.
206
+ */
207
+ getIconMap() {
208
+ return _univerjs_sheets_conditional_formatting.iconMap;
209
+ }
210
+ /**
211
+ * Create a conditional format ID.
212
+ * @returns {string} The conditional format ID.
213
+ */
214
+ createCfId() {
215
+ return (0, _univerjs_sheets_conditional_formatting.createCfId)();
216
+ }
217
+ /**
218
+ * Sets the scope for conditional formatting.
219
+ * @param {IRange[]} ranges - The ranges to which the conditional format applies.
220
+ * @returns {ConditionalFormatRuleBaseBuilder} This builder for chaining.
221
+ * @example
222
+ * ```typescript
223
+ * const fWorkbook = univerAPI.getActiveWorkbook();
224
+ * const fWorksheet = fWorkbook.getActiveSheet();
225
+ *
226
+ * // Create a conditional formatting rule that highlights cells with no content in red for the range A1:D10.
227
+ * const fRange = fWorksheet.getRange('A1:D10');
228
+ * const rule = fWorksheet.newConditionalFormattingRule()
229
+ * .whenCellEmpty()
230
+ * .setBackground('#FF0000')
231
+ * .setRanges([fRange.getRange()])
232
+ * .build();
233
+ * fWorksheet.addConditionalFormattingRule(rule);
234
+ * ```
235
+ */
236
+ setRanges(ranges) {
237
+ this._rule.ranges = ranges;
238
+ return this;
239
+ }
240
+ };
241
+ /**
242
+ * @hideconstructor
243
+ */
244
+ var ConditionalFormatHighlightRuleBuilder = class ConditionalFormatHighlightRuleBuilder extends ConditionalFormatRuleBaseBuilder {
245
+ constructor(initConfig = {}) {
246
+ super(initConfig);
247
+ this._ensureAttr(this._rule, ["rule", "style"]);
248
+ }
249
+ /**
250
+ * Deep clone a current builder.
251
+ * @returns {ConditionalFormatHighlightRuleBuilder} A new builder with the same settings as the original.
252
+ * @example
253
+ * ```typescript
254
+ * const fWorkbook = univerAPI.getActiveWorkbook();
255
+ * const fWorksheet = fWorkbook.getActiveSheet();
256
+ *
257
+ * // Create a conditional formatting rule that highlights cells with no content in red for the range A1:D10.
258
+ * const fRange = fWorksheet.getRange('A1:D10');
259
+ * const builder = fWorksheet.newConditionalFormattingRule()
260
+ * .whenCellEmpty()
261
+ * .setBackground('#FF0000')
262
+ * .setRanges([fRange.getRange()]);
263
+ * fWorksheet.addConditionalFormattingRule(builder.build());
264
+ *
265
+ * // Copy the rule and change the background color to green for the range A1:B2.
266
+ * const newRange = fWorksheet.getRange('A1:B2');
267
+ * const newBuilder = builder.copy()
268
+ * .setBackground('#00FF00')
269
+ * .setRanges([newRange.getRange()]);
270
+ * fWorksheet.addConditionalFormattingRule(newBuilder.build());
271
+ * ```
272
+ */
273
+ copy() {
274
+ const newRule = _univerjs_core.Tools.deepClone(this._rule);
275
+ if (newRule.cfId) newRule.cfId = (0, _univerjs_sheets_conditional_formatting.createCfId)();
276
+ return new ConditionalFormatHighlightRuleBuilder(newRule);
277
+ }
278
+ /**
279
+ * Set average rule.
280
+ * @param {IAverageHighlightCell['operator']} operator - The operator to use for the average rule.
281
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
282
+ * @example
283
+ * ```typescript
284
+ * const fWorkbook = univerAPI.getActiveWorkbook();
285
+ * const fWorksheet = fWorkbook.getActiveSheet();
286
+ *
287
+ * // Create a conditional formatting rule that highlights cells with greater than average values in red for the range A1:D10.
288
+ * const fRange = fWorksheet.getRange('A1:D10');
289
+ * const rule = fWorksheet.newConditionalFormattingRule()
290
+ * .setAverage(univerAPI.Enum.ConditionFormatNumberOperatorEnum.greaterThan)
291
+ * .setBackground('#FF0000')
292
+ * .setRanges([fRange.getRange()])
293
+ * .build();
294
+ * fWorksheet.addConditionalFormattingRule(rule);
295
+ * ```
296
+ */
297
+ setAverage(operator) {
298
+ const ruleConfig = this._ruleConfig;
299
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
300
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.average;
301
+ ruleConfig.operator = operator;
302
+ return this;
303
+ }
304
+ /**
305
+ * Set unique values rule.
306
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
307
+ * @example
308
+ * ```typescript
309
+ * const fWorkbook = univerAPI.getActiveWorkbook();
310
+ * const fWorksheet = fWorkbook.getActiveSheet();
311
+ *
312
+ * // Create a conditional formatting rule that highlights cells with unique values in red for the range A1:D10.
313
+ * const fRange = fWorksheet.getRange('A1:D10');
314
+ * const rule = fWorksheet.newConditionalFormattingRule()
315
+ * .setUniqueValues()
316
+ * .setBackground('#FF0000')
317
+ * .setRanges([fRange.getRange()])
318
+ * .build();
319
+ * fWorksheet.addConditionalFormattingRule(rule);
320
+ * ```
321
+ */
322
+ setUniqueValues() {
323
+ const ruleConfig = this._ruleConfig;
324
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
325
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.uniqueValues;
326
+ return this;
327
+ }
328
+ /**
329
+ * Set duplicate values rule.
330
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
331
+ * @example
332
+ * ```typescript
333
+ * const fWorkbook = univerAPI.getActiveWorkbook();
334
+ * const fWorksheet = fWorkbook.getActiveSheet();
335
+ *
336
+ * // Create a conditional formatting rule that highlights cells with duplicate values in red for the range A1:D10.
337
+ * const fRange = fWorksheet.getRange('A1:D10');
338
+ * const rule = fWorksheet.newConditionalFormattingRule()
339
+ * .setDuplicateValues()
340
+ * .setBackground('#FF0000')
341
+ * .setRanges([fRange.getRange()])
342
+ * .build();
343
+ * fWorksheet.addConditionalFormattingRule(rule);
344
+ * ```
345
+ */
346
+ setDuplicateValues() {
347
+ const ruleConfig = this._ruleConfig;
348
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
349
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.duplicateValues;
350
+ return this;
351
+ }
352
+ /**
353
+ * Set rank rule.
354
+ * @param {{ isBottom: boolean, isPercent: boolean, value: number }} config - The rank rule settings.
355
+ * @param {boolean} config.isBottom - Whether to highlight the bottom rank.
356
+ * @param {boolean} config.isPercent - Whether to use a percentage rank.
357
+ * @param {number} config.value - The rank value.
358
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
359
+ * @example
360
+ * ```typescript
361
+ * const fWorkbook = univerAPI.getActiveWorkbook();
362
+ * const fWorksheet = fWorkbook.getActiveSheet();
363
+ *
364
+ * // Create a conditional formatting rule that highlights the bottom 10% of values in red for the range A1:D10.
365
+ * const fRange = fWorksheet.getRange('A1:D10');
366
+ * const rule = fWorksheet.newConditionalFormattingRule()
367
+ * .setRank({ isBottom: true, isPercent: true, value: 10 })
368
+ * .setBackground('#FF0000')
369
+ * .setRanges([fRange.getRange()])
370
+ * .build();
371
+ * fWorksheet.addConditionalFormattingRule(rule);
372
+ * ```
373
+ */
374
+ setRank(config) {
375
+ const ruleConfig = this._ruleConfig;
376
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
377
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.rank;
378
+ ruleConfig.isBottom = config.isBottom;
379
+ ruleConfig.isPercent = config.isPercent;
380
+ ruleConfig.value = config.value;
381
+ return this;
382
+ }
383
+ /**
384
+ * Sets the background color for the conditional format rule's format.
385
+ * @param {string} [color] - The background color to set. If not provided, the background color is removed.
386
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
387
+ * @example
388
+ * ```typescript
389
+ * const fWorkbook = univerAPI.getActiveWorkbook();
390
+ * const fWorksheet = fWorkbook.getActiveSheet();
391
+ *
392
+ * // Create a conditional formatting rule that highlights cells with no content in red for the range A1:D10.
393
+ * const fRange = fWorksheet.getRange('A1:D10');
394
+ * const rule = fWorksheet.newConditionalFormattingRule()
395
+ * .whenCellEmpty()
396
+ * .setBackground('#FF0000')
397
+ * .setRanges([fRange.getRange()])
398
+ * .build();
399
+ * fWorksheet.addConditionalFormattingRule(rule);
400
+ * ```
401
+ */
402
+ setBackground(color) {
403
+ var _this$_ruleConfig;
404
+ if (((_this$_ruleConfig = this._ruleConfig) === null || _this$_ruleConfig === void 0 ? void 0 : _this$_ruleConfig.type) === _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell) if (color) {
405
+ this._ensureAttr(this._ruleConfig, ["style", "bg"]);
406
+ const colorKit = new _univerjs_core.ColorKit(color);
407
+ this._ruleConfig.style.bg.rgb = colorKit.toRgbString();
408
+ } else delete this._ruleConfig.style.bg;
409
+ return this;
410
+ }
411
+ /**
412
+ * Sets text bolding for the conditional format rule's format.
413
+ * @param {boolean} isBold - Whether to bold the text.
414
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
415
+ * @example
416
+ * ```typescript
417
+ * const fWorkbook = univerAPI.getActiveWorkbook();
418
+ * const fWorksheet = fWorkbook.getActiveSheet();
419
+ *
420
+ * // Create a conditional formatting rule that bolds the text for cells with not empty content in the range A1:D10.
421
+ * const fRange = fWorksheet.getRange('A1:D10');
422
+ * const rule = fWorksheet.newConditionalFormattingRule()
423
+ * .whenCellNotEmpty()
424
+ * .setBold(true)
425
+ * .setRanges([fRange.getRange()])
426
+ * .build();
427
+ * fWorksheet.addConditionalFormattingRule(rule);
428
+ * ```
429
+ */
430
+ setBold(isBold) {
431
+ var _this$_ruleConfig2;
432
+ if (((_this$_ruleConfig2 = this._ruleConfig) === null || _this$_ruleConfig2 === void 0 ? void 0 : _this$_ruleConfig2.type) === _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell) {
433
+ this._ensureAttr(this._ruleConfig, ["style"]);
434
+ this._ruleConfig.style.bl = isBold ? _univerjs_core.BooleanNumber.TRUE : _univerjs_core.BooleanNumber.FALSE;
435
+ }
436
+ return this;
437
+ }
438
+ /**
439
+ * Sets the font color for the conditional format rule's format.
440
+ * @param {string} [color] - The font color to set. If not provided, the font color is removed.
441
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
442
+ * @example
443
+ * ```typescript
444
+ * const fWorkbook = univerAPI.getActiveWorkbook();
445
+ * const fWorksheet = fWorkbook.getActiveSheet();
446
+ *
447
+ * // Create a conditional formatting rule that changes the font color to red for cells with not empty content in the range A1:D10.
448
+ * const fRange = fWorksheet.getRange('A1:D10');
449
+ * const rule = fWorksheet.newConditionalFormattingRule()
450
+ * .whenCellNotEmpty()
451
+ * .setFontColor('#FF0000')
452
+ * .setRanges([fRange.getRange()])
453
+ * .build();
454
+ * fWorksheet.addConditionalFormattingRule(rule);
455
+ * ```
456
+ */
457
+ setFontColor(color) {
458
+ var _this$_ruleConfig3;
459
+ if (((_this$_ruleConfig3 = this._ruleConfig) === null || _this$_ruleConfig3 === void 0 ? void 0 : _this$_ruleConfig3.type) === _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell) if (color) {
460
+ const colorKit = new _univerjs_core.ColorKit(color);
461
+ this._ensureAttr(this._ruleConfig, ["style", "cl"]);
462
+ this._ruleConfig.style.cl.rgb = colorKit.toRgbString();
463
+ } else delete this._ruleConfig.style.cl;
464
+ return this;
465
+ }
466
+ /**
467
+ * Sets text italics for the conditional format rule's format.
468
+ * @param {boolean} isItalic - Whether to italicize the text.
469
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
470
+ * @example
471
+ * ```typescript
472
+ * const fWorkbook = univerAPI.getActiveWorkbook();
473
+ * const fWorksheet = fWorkbook.getActiveSheet();
474
+ *
475
+ * // Create a conditional formatting rule that italicizes the text for cells with not empty content in the range A1:D10.
476
+ * const fRange = fWorksheet.getRange('A1:D10');
477
+ * const rule = fWorksheet.newConditionalFormattingRule()
478
+ * .whenCellNotEmpty()
479
+ * .setItalic(true)
480
+ * .setRanges([fRange.getRange()])
481
+ * .build();
482
+ * fWorksheet.addConditionalFormattingRule(rule);
483
+ * ```
484
+ */
485
+ setItalic(isItalic) {
486
+ var _this$_ruleConfig4;
487
+ if (((_this$_ruleConfig4 = this._ruleConfig) === null || _this$_ruleConfig4 === void 0 ? void 0 : _this$_ruleConfig4.type) === _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell) {
488
+ this._ensureAttr(this._ruleConfig, ["style"]);
489
+ this._ruleConfig.style.it = isItalic ? _univerjs_core.BooleanNumber.TRUE : _univerjs_core.BooleanNumber.FALSE;
490
+ }
491
+ return this;
492
+ }
493
+ /**
494
+ * Sets text strikethrough for the conditional format rule's format.
495
+ * @param {boolean} isStrikethrough - Whether is strikethrough the text.
496
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
497
+ * @example
498
+ * ```typescript
499
+ * const fWorkbook = univerAPI.getActiveWorkbook();
500
+ * const fWorksheet = fWorkbook.getActiveSheet();
501
+ *
502
+ * // Create a conditional formatting rule that set text strikethrough for cells with not empty content in the range A1:D10.
503
+ * const fRange = fWorksheet.getRange('A1:D10');
504
+ * const rule = fWorksheet.newConditionalFormattingRule()
505
+ * .whenCellNotEmpty()
506
+ * .setStrikethrough(true)
507
+ * .setRanges([fRange.getRange()])
508
+ * .build();
509
+ * fWorksheet.addConditionalFormattingRule(rule);
510
+ * ```
511
+ */
512
+ setStrikethrough(isStrikethrough) {
513
+ var _this$_ruleConfig5;
514
+ if (((_this$_ruleConfig5 = this._ruleConfig) === null || _this$_ruleConfig5 === void 0 ? void 0 : _this$_ruleConfig5.type) === _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell) {
515
+ this._ensureAttr(this._ruleConfig, ["style", "st"]);
516
+ this._ruleConfig.style.st.s = isStrikethrough ? _univerjs_core.BooleanNumber.TRUE : _univerjs_core.BooleanNumber.FALSE;
517
+ }
518
+ return this;
519
+ }
520
+ /**
521
+ * Sets text underlining for the conditional format rule's format.
522
+ * @param {boolean} isUnderline - Whether to underline the text.
523
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
524
+ * @example
525
+ * ```typescript
526
+ * const fWorkbook = univerAPI.getActiveWorkbook();
527
+ * const fWorksheet = fWorkbook.getActiveSheet();
528
+ *
529
+ * // Create a conditional formatting rule that underlines the text for cells with not empty content in the range A1:D10.
530
+ * const fRange = fWorksheet.getRange('A1:D10');
531
+ * const rule = fWorksheet.newConditionalFormattingRule()
532
+ * .whenCellNotEmpty()
533
+ * .setUnderline(true)
534
+ * .setRanges([fRange.getRange()])
535
+ * .build();
536
+ * fWorksheet.addConditionalFormattingRule(rule);
537
+ * ```
538
+ */
539
+ setUnderline(isUnderline) {
540
+ var _this$_ruleConfig6;
541
+ if (((_this$_ruleConfig6 = this._ruleConfig) === null || _this$_ruleConfig6 === void 0 ? void 0 : _this$_ruleConfig6.type) === _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell) {
542
+ this._ensureAttr(this._ruleConfig, ["style", "ul"]);
543
+ this._ruleConfig.style.ul.s = isUnderline ? _univerjs_core.BooleanNumber.TRUE : _univerjs_core.BooleanNumber.FALSE;
544
+ }
545
+ return this;
546
+ }
547
+ /**
548
+ * Sets the conditional format rule to trigger when the cell is empty.
549
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
550
+ * @example
551
+ * ```typescript
552
+ * const fWorkbook = univerAPI.getActiveWorkbook();
553
+ * const fWorksheet = fWorkbook.getActiveSheet();
554
+ *
555
+ * // Create a conditional formatting rule that highlights cells with no content in red for the range A1:D10.
556
+ * const fRange = fWorksheet.getRange('A1:D10');
557
+ * const rule = fWorksheet.newConditionalFormattingRule()
558
+ * .whenCellEmpty()
559
+ * .setBackground('#FF0000')
560
+ * .setRanges([fRange.getRange()])
561
+ * .build();
562
+ * fWorksheet.addConditionalFormattingRule(rule);
563
+ * ```
564
+ */
565
+ whenCellEmpty() {
566
+ const ruleConfig = this._ruleConfig;
567
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
568
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.text;
569
+ ruleConfig.value = "";
570
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFTextOperator.equal;
571
+ return this;
572
+ }
573
+ /**
574
+ * Sets the conditional format rule to trigger when the cell is not empty.
575
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
576
+ * @example
577
+ * ```typescript
578
+ * const fWorkbook = univerAPI.getActiveWorkbook();
579
+ * const fWorksheet = fWorkbook.getActiveSheet();
580
+ *
581
+ * // Create a conditional formatting rule that changes the font color to red for cells with not empty content in the range A1:D10.
582
+ * const fRange = fWorksheet.getRange('A1:D10');
583
+ * const rule = fWorksheet.newConditionalFormattingRule()
584
+ * .whenCellNotEmpty()
585
+ * .setFontColor('#FF0000')
586
+ * .setRanges([fRange.getRange()])
587
+ * .build();
588
+ * fWorksheet.addConditionalFormattingRule(rule);
589
+ * ```
590
+ */
591
+ whenCellNotEmpty() {
592
+ const ruleConfig = this._ruleConfig;
593
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
594
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.text;
595
+ ruleConfig.value = "";
596
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFTextOperator.notEqual;
597
+ return this;
598
+ }
599
+ /**
600
+ * Sets the conditional format rule to trigger when a time period is met.
601
+ * @param {CFTimePeriodOperator} date - The time period to check for.
602
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
603
+ * @example
604
+ * ```typescript
605
+ * const fWorkbook = univerAPI.getActiveWorkbook();
606
+ * const fWorksheet = fWorkbook.getActiveSheet();
607
+ *
608
+ * // Create a conditional formatting rule that highlights cells with dates in the last 7 days in red for the range A1:D10.
609
+ * const fRange = fWorksheet.getRange('A1:D10');
610
+ * const rule = fWorksheet.newConditionalFormattingRule()
611
+ * .whenDate(univerAPI.Enum.ConditionFormatTimePeriodOperatorEnum.last7Days)
612
+ * .setBackground('#FF0000')
613
+ * .setRanges([fRange.getRange()])
614
+ * .build();
615
+ * fWorksheet.addConditionalFormattingRule(rule);
616
+ * ```
617
+ */
618
+ whenDate(date) {
619
+ const ruleConfig = this._ruleConfig;
620
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
621
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.timePeriod;
622
+ ruleConfig.operator = date;
623
+ return this;
624
+ }
625
+ /**
626
+ * Sets the conditional format rule to trigger when that the given formula evaluates to `true`.
627
+ * @param {string} formulaString - A custom formula that evaluates to true if the input is valid. formulaString start with '='.
628
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
629
+ * @example
630
+ * ```typescript
631
+ * const fWorkbook = univerAPI.getActiveWorkbook();
632
+ * const fWorksheet = fWorkbook.getActiveSheet();
633
+ *
634
+ * // Create a conditional formatting rule that highlights cells with values greater than 10 in red for the range A1:D10.
635
+ * const fRange = fWorksheet.getRange('A1:D10');
636
+ * const rule = fWorksheet.newConditionalFormattingRule()
637
+ * .whenFormulaSatisfied('=A1>10')
638
+ * .setBackground('#FF0000')
639
+ * .setRanges([fRange.getRange()])
640
+ * .build();
641
+ * fWorksheet.addConditionalFormattingRule(rule);
642
+ * ```
643
+ */
644
+ whenFormulaSatisfied(formulaString) {
645
+ const ruleConfig = this._ruleConfig;
646
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
647
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.formula;
648
+ ruleConfig.value = formulaString;
649
+ return this;
650
+ }
651
+ /**
652
+ * Sets the conditional format rule to trigger when a number falls between, or is either of, two specified values.
653
+ * @param {number} start - The lowest acceptable value.
654
+ * @param {number} end - The highest acceptable value.
655
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
656
+ * @example
657
+ * ```typescript
658
+ * const fWorkbook = univerAPI.getActiveWorkbook();
659
+ * const fWorksheet = fWorkbook.getActiveSheet();
660
+ *
661
+ * // Create a conditional formatting rule that highlights cells with values between 10 and 20 in red for the range A1:D10.
662
+ * const fRange = fWorksheet.getRange('A1:D10');
663
+ * const rule = fWorksheet.newConditionalFormattingRule()
664
+ * .whenNumberBetween(10, 20)
665
+ * .setBackground('#FF0000')
666
+ * .setRanges([fRange.getRange()])
667
+ * .build();
668
+ * fWorksheet.addConditionalFormattingRule(rule);
669
+ * ```
670
+ */
671
+ whenNumberBetween(start, end) {
672
+ const min = Math.min(start, end);
673
+ const max = Math.max(start, end);
674
+ const ruleConfig = this._ruleConfig;
675
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
676
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.number;
677
+ ruleConfig.value = [min, max];
678
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFNumberOperator.between;
679
+ return this;
680
+ }
681
+ /**
682
+ * Sets the conditional format rule to trigger when a number is equal to the given value.
683
+ * @param {number} value - The sole acceptable value.
684
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
685
+ * @example
686
+ * ```typescript
687
+ * const fWorkbook = univerAPI.getActiveWorkbook();
688
+ * const fWorksheet = fWorkbook.getActiveSheet();
689
+ *
690
+ * // Create a conditional formatting rule that highlights cells with values equal to 10 in red for the range A1:D10.
691
+ * const fRange = fWorksheet.getRange('A1:D10');
692
+ * const rule = fWorksheet.newConditionalFormattingRule()
693
+ * .whenNumberEqualTo(10)
694
+ * .setBackground('#FF0000')
695
+ * .setRanges([fRange.getRange()])
696
+ * .build();
697
+ * fWorksheet.addConditionalFormattingRule(rule);
698
+ * ```
699
+ */
700
+ whenNumberEqualTo(value) {
701
+ const ruleConfig = this._ruleConfig;
702
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
703
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.number;
704
+ ruleConfig.value = value;
705
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFNumberOperator.equal;
706
+ return this;
707
+ }
708
+ /**
709
+ * Sets the conditional format rule to trigger when a number is greater than the given value.
710
+ * @param {number} value - The highest unacceptable value.
711
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
712
+ * @example
713
+ * ```typescript
714
+ * const fWorkbook = univerAPI.getActiveWorkbook();
715
+ * const fWorksheet = fWorkbook.getActiveSheet();
716
+ *
717
+ * // Create a conditional formatting rule that highlights cells with values greater than 10 in red for the range A1:D10.
718
+ * const fRange = fWorksheet.getRange('A1:D10');
719
+ * const rule = fWorksheet.newConditionalFormattingRule()
720
+ * .whenNumberGreaterThan(10)
721
+ * .setBackground('#FF0000')
722
+ * .setRanges([fRange.getRange()])
723
+ * .build();
724
+ * fWorksheet.addConditionalFormattingRule(rule);
725
+ * ```
726
+ */
727
+ whenNumberGreaterThan(value) {
728
+ const ruleConfig = this._ruleConfig;
729
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
730
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.number;
731
+ ruleConfig.value = value;
732
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFNumberOperator.greaterThan;
733
+ return this;
734
+ }
735
+ /**
736
+ * Sets the conditional format rule to trigger when a number is greater than or equal to the given value.
737
+ * @param {number} value - The lowest acceptable value.
738
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
739
+ * @example
740
+ * ```typescript
741
+ * const fWorkbook = univerAPI.getActiveWorkbook();
742
+ * const fWorksheet = fWorkbook.getActiveSheet();
743
+ *
744
+ * // Create a conditional formatting rule that highlights cells with values greater than or equal to 10 in red for the range A1:D10.
745
+ * const fRange = fWorksheet.getRange('A1:D10');
746
+ * const rule = fWorksheet.newConditionalFormattingRule()
747
+ * .whenNumberGreaterThanOrEqualTo(10)
748
+ * .setBackground('#FF0000')
749
+ * .setRanges([fRange.getRange()])
750
+ * .build();
751
+ * fWorksheet.addConditionalFormattingRule(rule);
752
+ * ```
753
+ */
754
+ whenNumberGreaterThanOrEqualTo(value) {
755
+ const ruleConfig = this._ruleConfig;
756
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
757
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.number;
758
+ ruleConfig.value = value;
759
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFNumberOperator.greaterThanOrEqual;
760
+ return this;
761
+ }
762
+ /**
763
+ * Sets the conditional conditional format rule to trigger when a number less than the given value.
764
+ * @param {number} value - The lowest unacceptable value.
765
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
766
+ * @example
767
+ * ```typescript
768
+ * const fWorkbook = univerAPI.getActiveWorkbook();
769
+ * const fWorksheet = fWorkbook.getActiveSheet();
770
+ *
771
+ * // Create a conditional formatting rule that highlights cells with values less than 10 in red for the range A1:D10.
772
+ * const fRange = fWorksheet.getRange('A1:D10');
773
+ * const rule = fWorksheet.newConditionalFormattingRule()
774
+ * .whenNumberLessThan(10)
775
+ * .setBackground('#FF0000')
776
+ * .setRanges([fRange.getRange()])
777
+ * .build();
778
+ * fWorksheet.addConditionalFormattingRule(rule);
779
+ * ```
780
+ */
781
+ whenNumberLessThan(value) {
782
+ const ruleConfig = this._ruleConfig;
783
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
784
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.number;
785
+ ruleConfig.value = value;
786
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFNumberOperator.lessThan;
787
+ return this;
788
+ }
789
+ /**
790
+ * Sets the conditional format rule to trigger when a number less than or equal to the given value.
791
+ * @param {number} value - The highest acceptable value.
792
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
793
+ * @example
794
+ * ```typescript
795
+ * const fWorkbook = univerAPI.getActiveWorkbook();
796
+ * const fWorksheet = fWorkbook.getActiveSheet();
797
+ *
798
+ * // Create a conditional formatting rule that highlights cells with values less than or equal to 10 in red for the range A1:D10.
799
+ * const fRange = fWorksheet.getRange('A1:D10');
800
+ * const rule = fWorksheet.newConditionalFormattingRule()
801
+ * .whenNumberLessThanOrEqualTo(10)
802
+ * .setBackground('#FF0000')
803
+ * .setRanges([fRange.getRange()])
804
+ * .build();
805
+ * fWorksheet.addConditionalFormattingRule(rule);
806
+ * ```
807
+ */
808
+ whenNumberLessThanOrEqualTo(value) {
809
+ const ruleConfig = this._ruleConfig;
810
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
811
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.number;
812
+ ruleConfig.value = value;
813
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFNumberOperator.lessThanOrEqual;
814
+ return this;
815
+ }
816
+ /**
817
+ * Sets the conditional format rule to trigger when a number does not fall between, and is neither of, two specified values.
818
+ * @param {number} start - The lowest unacceptable value.
819
+ * @param {number} end - The highest unacceptable value.
820
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
821
+ * @example
822
+ * ```typescript
823
+ * const fWorkbook = univerAPI.getActiveWorkbook();
824
+ * const fWorksheet = fWorkbook.getActiveSheet();
825
+ *
826
+ * // Create a conditional formatting rule that highlights cells with values not between 10 and 20 in red for the range A1:D10.
827
+ * const fRange = fWorksheet.getRange('A1:D10');
828
+ * const rule = fWorksheet.newConditionalFormattingRule()
829
+ * .whenNumberNotBetween(10, 20)
830
+ * .setBackground('#FF0000')
831
+ * .setRanges([fRange.getRange()])
832
+ * .build();
833
+ * fWorksheet.addConditionalFormattingRule(rule);
834
+ * ```
835
+ */
836
+ whenNumberNotBetween(start, end) {
837
+ const min = Math.min(start, end);
838
+ const max = Math.max(start, end);
839
+ const ruleConfig = this._ruleConfig;
840
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
841
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.number;
842
+ ruleConfig.value = [min, max];
843
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFNumberOperator.notBetween;
844
+ return this;
845
+ }
846
+ /**
847
+ * Sets the conditional format rule to trigger when a number is not equal to the given value.
848
+ * @param {number} value - The sole unacceptable value.
849
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
850
+ * @example
851
+ * ```typescript
852
+ * const fWorkbook = univerAPI.getActiveWorkbook();
853
+ * const fWorksheet = fWorkbook.getActiveSheet();
854
+ *
855
+ * // Create a conditional formatting rule that highlights cells with values not equal to 10 in red for the range A1:D10.
856
+ * const fRange = fWorksheet.getRange('A1:D10');
857
+ * const rule = fWorksheet.newConditionalFormattingRule()
858
+ * .whenNumberNotEqualTo(10)
859
+ * .setBackground('#FF0000')
860
+ * .setRanges([fRange.getRange()])
861
+ * .build();
862
+ * fWorksheet.addConditionalFormattingRule(rule);
863
+ * ```
864
+ */
865
+ whenNumberNotEqualTo(value) {
866
+ const ruleConfig = this._ruleConfig;
867
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
868
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.number;
869
+ ruleConfig.value = value;
870
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFNumberOperator.notEqual;
871
+ return this;
872
+ }
873
+ /**
874
+ * Sets the conditional format rule to trigger when that the input contains the given value.
875
+ * @param {string} text - The value that the input must contain.
876
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
877
+ * @example
878
+ * ```typescript
879
+ * const fWorkbook = univerAPI.getActiveWorkbook();
880
+ * const fWorksheet = fWorkbook.getActiveSheet();
881
+ *
882
+ * // Create a conditional formatting rule that highlights cells with text containing 'apple' in red for the range A1:D10.
883
+ * const fRange = fWorksheet.getRange('A1:D10');
884
+ * const rule = fWorksheet.newConditionalFormattingRule()
885
+ * .whenTextContains('apple')
886
+ * .setBackground('#FF0000')
887
+ * .setRanges([fRange.getRange()])
888
+ * .build();
889
+ * fWorksheet.addConditionalFormattingRule(rule);
890
+ * ```
891
+ */
892
+ whenTextContains(text) {
893
+ const ruleConfig = this._ruleConfig;
894
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
895
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.text;
896
+ ruleConfig.value = text;
897
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFTextOperator.containsText;
898
+ return this;
899
+ }
900
+ /**
901
+ * Sets the conditional format rule to trigger when that the input does not contain the given value.
902
+ * @param {string} text - The value that the input must not contain.
903
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
904
+ * @example
905
+ * ```typescript
906
+ * const fWorkbook = univerAPI.getActiveWorkbook();
907
+ * const fWorksheet = fWorkbook.getActiveSheet();
908
+ *
909
+ * // Create a conditional formatting rule that highlights cells with text not containing 'apple' in red for the range A1:D10.
910
+ * const fRange = fWorksheet.getRange('A1:D10');
911
+ * const rule = fWorksheet.newConditionalFormattingRule()
912
+ * .whenTextDoesNotContain('apple')
913
+ * .setBackground('#FF0000')
914
+ * .setRanges([fRange.getRange()])
915
+ * .build();
916
+ * fWorksheet.addConditionalFormattingRule(rule);
917
+ * ```
918
+ */
919
+ whenTextDoesNotContain(text) {
920
+ const ruleConfig = this._ruleConfig;
921
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
922
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.text;
923
+ ruleConfig.value = text;
924
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFTextOperator.notContainsText;
925
+ return this;
926
+ }
927
+ /**
928
+ * Sets the conditional format rule to trigger when that the input ends with the given value.
929
+ * @param {string} text - Text to compare against the end of the string.
930
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
931
+ * @example
932
+ * ```typescript
933
+ * const fWorkbook = univerAPI.getActiveWorkbook();
934
+ * const fWorksheet = fWorkbook.getActiveSheet();
935
+ *
936
+ * // Create a conditional formatting rule that highlights cells with text ending with '.ai' in red for the range A1:D10.
937
+ * const fRange = fWorksheet.getRange('A1:D10');
938
+ * const rule = fWorksheet.newConditionalFormattingRule()
939
+ * .whenTextEndsWith('.ai')
940
+ * .setBackground('#FF0000')
941
+ * .setRanges([fRange.getRange()])
942
+ * .build();
943
+ * fWorksheet.addConditionalFormattingRule(rule);
944
+ * ```
945
+ */
946
+ whenTextEndsWith(text) {
947
+ const ruleConfig = this._ruleConfig;
948
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
949
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.text;
950
+ ruleConfig.value = text;
951
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFTextOperator.endsWith;
952
+ return this;
953
+ }
954
+ /**
955
+ * Sets the conditional format rule to trigger when that the input is equal to the given value.
956
+ * @param {string} text - The sole acceptable value.
957
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
958
+ * @example
959
+ * ```typescript
960
+ * const fWorkbook = univerAPI.getActiveWorkbook();
961
+ * const fWorksheet = fWorkbook.getActiveSheet();
962
+ *
963
+ * // Create a conditional formatting rule that highlights cells with text equal to 'apple' in red for the range A1:D10.
964
+ * const fRange = fWorksheet.getRange('A1:D10');
965
+ * const rule = fWorksheet.newConditionalFormattingRule()
966
+ * .whenTextEqualTo('apple')
967
+ * .setBackground('#FF0000')
968
+ * .setRanges([fRange.getRange()])
969
+ * .build();
970
+ * fWorksheet.addConditionalFormattingRule(rule);
971
+ * ```
972
+ */
973
+ whenTextEqualTo(text) {
974
+ const ruleConfig = this._ruleConfig;
975
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
976
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.text;
977
+ ruleConfig.value = text;
978
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFTextOperator.equal;
979
+ return this;
980
+ }
981
+ /**
982
+ * Sets the conditional format rule to trigger when that the input starts with the given value.
983
+ * @param {string} text - Text to compare against the beginning of the string.
984
+ * @returns {ConditionalFormatHighlightRuleBuilder} This builder for chaining.
985
+ * @example
986
+ * ```typescript
987
+ * const fWorkbook = univerAPI.getActiveWorkbook();
988
+ * const fWorksheet = fWorkbook.getActiveSheet();
989
+ *
990
+ * // Create a conditional formatting rule that highlights cells with text starting with 'https://' in red for the range A1:D10.
991
+ * const fRange = fWorksheet.getRange('A1:D10');
992
+ * const rule = fWorksheet.newConditionalFormattingRule()
993
+ * .whenTextStartsWith('https://')
994
+ * .setBackground('#FF0000')
995
+ * .setRanges([fRange.getRange()])
996
+ * .build();
997
+ * fWorksheet.addConditionalFormattingRule(rule);
998
+ * ```
999
+ */
1000
+ whenTextStartsWith(text) {
1001
+ const ruleConfig = this._ruleConfig;
1002
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.highlightCell;
1003
+ ruleConfig.subType = _univerjs_sheets_conditional_formatting.CFSubRuleType.text;
1004
+ ruleConfig.value = text;
1005
+ ruleConfig.operator = _univerjs_sheets_conditional_formatting.CFTextOperator.beginsWith;
1006
+ return this;
1007
+ }
1008
+ };
1009
+ var ConditionalFormatDataBarRuleBuilder = class ConditionalFormatDataBarRuleBuilder extends ConditionalFormatRuleBaseBuilder {
1010
+ /**
1011
+ * Deep clone a current builder.
1012
+ * @returns {ConditionalFormatDataBarRuleBuilder} A new instance of the builder with the same settings as the original.
1013
+ * @example
1014
+ * ```typescript
1015
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1016
+ * const fWorksheet = fWorkbook.getActiveSheet();
1017
+ *
1018
+ * // Create a conditional formatting rule that adds a data bar to cells with values between -100 and 100 in the range A1:D10.
1019
+ * // positive values are green and negative values are red.
1020
+ * const fRange = fWorksheet.getRange('A1:D10');
1021
+ * const builder = fWorksheet.newConditionalFormattingRule()
1022
+ * .setDataBar({
1023
+ * min: { type: 'num', value: -100 },
1024
+ * max: { type: 'num', value: 100 },
1025
+ * positiveColor: '#00FF00',
1026
+ * nativeColor: '#FF0000',
1027
+ * isShowValue: true
1028
+ * })
1029
+ * .setRanges([fRange.getRange()]);
1030
+ * fWorksheet.addConditionalFormattingRule(builder.build());
1031
+ *
1032
+ * // Copy the rule and apply it to a new range.
1033
+ * const newRange = fWorksheet.getRange('F1:F10');
1034
+ * const newBuilder = builder.copy()
1035
+ * .setRanges([newRange.getRange()]);
1036
+ * fWorksheet.addConditionalFormattingRule(newBuilder.build());
1037
+ * ```
1038
+ */
1039
+ copy() {
1040
+ const newRule = _univerjs_core.Tools.deepClone(this._rule);
1041
+ if (newRule.cfId) newRule.cfId = (0, _univerjs_sheets_conditional_formatting.createCfId)();
1042
+ return new ConditionalFormatDataBarRuleBuilder(newRule);
1043
+ }
1044
+ /**
1045
+ * Set data bar rule.
1046
+ * @param {{
1047
+ * min: IValueConfig;
1048
+ * max: IValueConfig;
1049
+ * isGradient?: boolean;
1050
+ * positiveColor: string;
1051
+ * nativeColor: string;
1052
+ * isShowValue?: boolean;
1053
+ * }} config - The data bar rule settings.
1054
+ * @param {IValueConfig} config.min - The minimum value for the data bar.
1055
+ * @param {IValueConfig} config.max - The maximum value for the data bar.
1056
+ * @param {boolean} [config.isGradient] - Whether the data bar is gradient.
1057
+ * @param {string} config.positiveColor - The color for positive values.
1058
+ * @param {string} config.nativeColor - The color for negative values.
1059
+ * @param {boolean} [config.isShowValue] - Whether to show the value in the cell.
1060
+ * @returns {ConditionalFormatDataBarRuleBuilder} This builder for chaining.
1061
+ * @example
1062
+ * ```typescript
1063
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1064
+ * const fWorksheet = fWorkbook.getActiveSheet();
1065
+ *
1066
+ * // Create a conditional formatting rule that adds a data bar to cells with values between -100 and 100 in the range A1:D10.
1067
+ * // positive values are green and negative values are red.
1068
+ * const fRange = fWorksheet.getRange('A1:D10');
1069
+ * const rule = fWorksheet.newConditionalFormattingRule()
1070
+ * .setDataBar({
1071
+ * min: { type: 'num', value: -100 },
1072
+ * max: { type: 'num', value: 100 },
1073
+ * positiveColor: '#00FF00',
1074
+ * nativeColor: '#FF0000',
1075
+ * isShowValue: true
1076
+ * })
1077
+ * .setRanges([fRange.getRange()])
1078
+ * .build();
1079
+ * fWorksheet.addConditionalFormattingRule(rule);
1080
+ * ```
1081
+ */
1082
+ setDataBar(config) {
1083
+ const ruleConfig = this._ruleConfig;
1084
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.dataBar;
1085
+ ruleConfig.isShowValue = !!config.isShowValue;
1086
+ ruleConfig.config = {
1087
+ min: config.min,
1088
+ max: config.max,
1089
+ positiveColor: config.positiveColor,
1090
+ nativeColor: config.nativeColor,
1091
+ isGradient: !!config.isGradient
1092
+ };
1093
+ return this;
1094
+ }
1095
+ };
1096
+ var ConditionalFormatColorScaleRuleBuilder = class ConditionalFormatColorScaleRuleBuilder extends ConditionalFormatRuleBaseBuilder {
1097
+ /**
1098
+ * Deep clone a current builder.
1099
+ * @returns {ConditionalFormatColorScaleRuleBuilder} A new instance of the builder with the same settings as the original.
1100
+ * @example
1101
+ * ```typescript
1102
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1103
+ * const fWorksheet = fWorkbook.getActiveSheet();
1104
+ *
1105
+ * // Create a conditional formatting rule that adds a color scale to cells with values between 0 and 100 in the range A1:D10.
1106
+ * // The color scale is green for 0, yellow for 50, and red for 100.
1107
+ * const fRange = fWorksheet.getRange('A1:D10');
1108
+ * const builder = fWorksheet.newConditionalFormattingRule()
1109
+ * .setColorScale([
1110
+ * { index: 0, color: '#00FF00', value: { type: 'num', value: 0 } },
1111
+ * { index: 1, color: '#FFFF00', value: { type: 'num', value: 50 } },
1112
+ * { index: 2, color: '#FF0000', value: { type: 'num', value: 100 } }
1113
+ * ])
1114
+ * .setRanges([fRange.getRange()]);
1115
+ * fWorksheet.addConditionalFormattingRule(builder.build());
1116
+ *
1117
+ * // Copy the rule and apply it to a new range.
1118
+ * const newRange = fWorksheet.getRange('F1:F10');
1119
+ * const newBuilder = builder.copy()
1120
+ * .setRanges([newRange.getRange()]);
1121
+ * fWorksheet.addConditionalFormattingRule(newBuilder.build());
1122
+ * ```
1123
+ */
1124
+ copy() {
1125
+ const newRule = _univerjs_core.Tools.deepClone(this._rule);
1126
+ if (newRule.cfId) newRule.cfId = (0, _univerjs_sheets_conditional_formatting.createCfId)();
1127
+ return new ConditionalFormatColorScaleRuleBuilder(newRule);
1128
+ }
1129
+ /**
1130
+ * Set color scale rule.
1131
+ * @param {{ index: number; color: string; value: IValueConfig }[]} config - The color scale rule settings.
1132
+ * @param {number} config.index - The index of the color scale configuration.
1133
+ * @param {string} config.color - The color corresponding to the index of the color scale configuration.
1134
+ * @param {IValueConfig} config.value - The condition value corresponding to the index of the color scale configuration.
1135
+ * @returns {ConditionalFormatColorScaleRuleBuilder} This builder for chaining.
1136
+ * @example
1137
+ * ```typescript
1138
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1139
+ * const fWorksheet = fWorkbook.getActiveSheet();
1140
+ *
1141
+ * // Create a conditional formatting rule that adds a color scale to cells with values between 0 and 100 in the range A1:D10.
1142
+ * // The color scale is green for 0, yellow for 50, and red for 100.
1143
+ * const fRange = fWorksheet.getRange('A1:D10');
1144
+ * const rule = fWorksheet.newConditionalFormattingRule()
1145
+ * .setColorScale([
1146
+ * { index: 0, color: '#00FF00', value: { type: 'num', value: 0 } },
1147
+ * { index: 1, color: '#FFFF00', value: { type: 'num', value: 50 } },
1148
+ * { index: 2, color: '#FF0000', value: { type: 'num', value: 100 } }
1149
+ * ])
1150
+ * .setRanges([fRange.getRange()])
1151
+ * .build();
1152
+ * fWorksheet.addConditionalFormattingRule(rule);
1153
+ * ```
1154
+ */
1155
+ setColorScale(config) {
1156
+ const ruleConfig = this._ruleConfig;
1157
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.colorScale;
1158
+ ruleConfig.config = config;
1159
+ return this;
1160
+ }
1161
+ };
1162
+ var ConditionalFormatIconSetRuleBuilder = class ConditionalFormatIconSetRuleBuilder extends ConditionalFormatRuleBaseBuilder {
1163
+ /**
1164
+ * Deep clone a current builder.
1165
+ * @returns {ConditionalFormatIconSetRuleBuilder} A new instance of the builder with the same settings as the original.
1166
+ * @example
1167
+ * ```typescript
1168
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1169
+ * const fWorksheet = fWorkbook.getActiveSheet();
1170
+ *
1171
+ * // Create a 3-arrow icon set conditional formatting rule in the range A1:D10.
1172
+ * // The first arrow is green for values greater than 20.
1173
+ * // The second arrow is yellow for values greater than 10.
1174
+ * // The third arrow is red for values less than or equal to 10.
1175
+ * const fRange = fWorksheet.getRange('A1:D10');
1176
+ * const builder = fWorksheet.newConditionalFormattingRule()
1177
+ * .setIconSet({
1178
+ * iconConfigs: [
1179
+ * { iconType: '3Arrows', iconId: '0', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.greaterThan, value: { type: 'num', value: 20 } },
1180
+ * { iconType: '3Arrows', iconId: '1', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.greaterThan, value: { type: 'num', value: 10 } },
1181
+ * { iconType: '3Arrows', iconId: '2', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.lessThanOrEqual, value: { type: 'num', value: 10 } }
1182
+ * ],
1183
+ * isShowValue: true,
1184
+ * })
1185
+ * .setRanges([fRange.getRange()]);
1186
+ * fWorksheet.addConditionalFormattingRule(builder.build());
1187
+ *
1188
+ * // Copy the rule and apply it to a new range.
1189
+ * const newRange = fWorksheet.getRange('F1:F10');
1190
+ * const newBuilder = builder.copy()
1191
+ * .setRanges([newRange.getRange()]);
1192
+ * fWorksheet.addConditionalFormattingRule(newBuilder.build());
1193
+ * ```
1194
+ */
1195
+ copy() {
1196
+ const newRule = _univerjs_core.Tools.deepClone(this._rule);
1197
+ if (newRule.cfId) newRule.cfId = (0, _univerjs_sheets_conditional_formatting.createCfId)();
1198
+ return new ConditionalFormatIconSetRuleBuilder(newRule);
1199
+ }
1200
+ /**
1201
+ * Set up icon set conditional formatting rule.
1202
+ * @param {{ iconConfigs: IIconSet['config'], isShowValue: boolean }} config - The icon set conditional formatting rule settings.
1203
+ * @param {IIconSet['config']} config.iconConfigs - The icon configurations. iconId property is a string indexing of a group icons.
1204
+ * @param {boolean} config.isShowValue - Whether to show the value in the cell.
1205
+ * @returns {ConditionalFormatIconSetRuleBuilder} This builder for chaining.
1206
+ * @example
1207
+ * ```typescript
1208
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1209
+ * const fWorksheet = fWorkbook.getActiveSheet();
1210
+ *
1211
+ * // Create a 3-arrow icon set conditional formatting rule in the range A1:D10.
1212
+ * // The first arrow is green for values greater than 20.
1213
+ * // The second arrow is yellow for values greater than 10.
1214
+ * // The third arrow is red for values less than or equal to 10.
1215
+ * const fRange = fWorksheet.getRange('A1:D10');
1216
+ * const builder = fWorksheet.newConditionalFormattingRule();
1217
+ * console.log(builder.getIconMap()); // icons key-value map
1218
+ * const rule = builder.setIconSet({
1219
+ * iconConfigs: [
1220
+ * { iconType: '3Arrows', iconId: '0', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.greaterThan, value: { type: 'num', value: 20 } },
1221
+ * { iconType: '3Arrows', iconId: '1', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.greaterThan, value: { type: 'num', value: 10 } },
1222
+ * { iconType: '3Arrows', iconId: '2', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.lessThanOrEqual, value: { type: 'num', value: 10 } }
1223
+ * ],
1224
+ * isShowValue: true,
1225
+ * })
1226
+ * .setRanges([fRange.getRange()])
1227
+ * .build();
1228
+ * fWorksheet.addConditionalFormattingRule(rule);
1229
+ * ```
1230
+ */
1231
+ setIconSet(config) {
1232
+ const ruleConfig = this._ruleConfig;
1233
+ ruleConfig.type = _univerjs_sheets_conditional_formatting.CFRuleType.iconSet;
1234
+ ruleConfig.config = config.iconConfigs;
1235
+ ruleConfig.isShowValue = config.isShowValue;
1236
+ return this;
1237
+ }
1238
+ };
1239
+ /**
1240
+ * @hideconstructor
1241
+ */
1242
+ var FConditionalFormattingBuilder = class {
1243
+ constructor(_initConfig = {}) {
1244
+ this._initConfig = _initConfig;
1245
+ }
1246
+ /**
1247
+ * Constructs a conditional format rule from the settings applied to the builder.
1248
+ * @returns {IConditionFormattingRule} The conditional format rule.
1249
+ * @example
1250
+ * ```typescript
1251
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1252
+ * const fWorksheet = fWorkbook.getActiveSheet();
1253
+ *
1254
+ * // Create a conditional formatting rule that highlights cells with values greater than 10 in red for the range A1:D10.
1255
+ * const fRange = fWorksheet.getRange('A1:D10');
1256
+ * const rule = fWorksheet.newConditionalFormattingRule()
1257
+ * .whenNumberGreaterThan(10)
1258
+ * .setBackground('#FF0000')
1259
+ * .setRanges([fRange.getRange()])
1260
+ * .build();
1261
+ * fWorksheet.addConditionalFormattingRule(rule);
1262
+ * ```
1263
+ */
1264
+ build() {
1265
+ return new ConditionalFormatRuleBaseBuilder(this._initConfig).build();
1266
+ }
1267
+ /**
1268
+ * Set average rule.
1269
+ * @param {IAverageHighlightCell['operator']} operator - The operator to use for the average rule.
1270
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1271
+ * @example
1272
+ * ```typescript
1273
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1274
+ * const fWorksheet = fWorkbook.getActiveSheet();
1275
+ *
1276
+ * // Create a conditional formatting rule that highlights cells with greater than average values in red for the range A1:D10.
1277
+ * const fRange = fWorksheet.getRange('A1:D10');
1278
+ * const rule = fWorksheet.newConditionalFormattingRule()
1279
+ * .setAverage(univerAPI.Enum.ConditionFormatNumberOperatorEnum.greaterThan)
1280
+ * .setBackground('#FF0000')
1281
+ * .setRanges([fRange.getRange()])
1282
+ * .build();
1283
+ * fWorksheet.addConditionalFormattingRule(rule);
1284
+ * ```
1285
+ */
1286
+ setAverage(operator) {
1287
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).setAverage(operator);
1288
+ }
1289
+ /**
1290
+ * Set unique values rule.
1291
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1292
+ * @example
1293
+ * ```typescript
1294
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1295
+ * const fWorksheet = fWorkbook.getActiveSheet();
1296
+ *
1297
+ * // Create a conditional formatting rule that highlights cells with unique values in red for the range A1:D10.
1298
+ * const fRange = fWorksheet.getRange('A1:D10');
1299
+ * const rule = fWorksheet.newConditionalFormattingRule()
1300
+ * .setUniqueValues()
1301
+ * .setBackground('#FF0000')
1302
+ * .setRanges([fRange.getRange()])
1303
+ * .build();
1304
+ * fWorksheet.addConditionalFormattingRule(rule);
1305
+ * ```
1306
+ */
1307
+ setUniqueValues() {
1308
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).setUniqueValues();
1309
+ }
1310
+ /**
1311
+ * Set duplicate values rule.
1312
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1313
+ * @example
1314
+ * ```typescript
1315
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1316
+ * const fWorksheet = fWorkbook.getActiveSheet();
1317
+ *
1318
+ * // Create a conditional formatting rule that highlights cells with duplicate values in red for the range A1:D10.
1319
+ * const fRange = fWorksheet.getRange('A1:D10');
1320
+ * const rule = fWorksheet.newConditionalFormattingRule()
1321
+ * .setDuplicateValues()
1322
+ * .setBackground('#FF0000')
1323
+ * .setRanges([fRange.getRange()])
1324
+ * .build();
1325
+ * fWorksheet.addConditionalFormattingRule(rule);
1326
+ * ```
1327
+ */
1328
+ setDuplicateValues() {
1329
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).setDuplicateValues();
1330
+ }
1331
+ /**
1332
+ * Set rank rule.
1333
+ * @param {{ isBottom: boolean, isPercent: boolean, value: number }} config - The rank rule settings.
1334
+ * @param {boolean} config.isBottom - Whether to highlight the bottom rank.
1335
+ * @param {boolean} config.isPercent - Whether to use a percentage rank.
1336
+ * @param {number} config.value - The rank value.
1337
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1338
+ * @example
1339
+ * ```typescript
1340
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1341
+ * const fWorksheet = fWorkbook.getActiveSheet();
1342
+ *
1343
+ * // Create a conditional formatting rule that highlights the bottom 10% of values in red for the range A1:D10.
1344
+ * const fRange = fWorksheet.getRange('A1:D10');
1345
+ * const rule = fWorksheet.newConditionalFormattingRule()
1346
+ * .setRank({ isBottom: true, isPercent: true, value: 10 })
1347
+ * .setBackground('#FF0000')
1348
+ * .setRanges([fRange.getRange()])
1349
+ * .build();
1350
+ * fWorksheet.addConditionalFormattingRule(rule);
1351
+ * ```
1352
+ */
1353
+ setRank(config) {
1354
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).setRank(config);
1355
+ }
1356
+ /**
1357
+ * Get the icon set mapping dictionary.
1358
+ * @returns {Record<string, string[]>} The icon set mapping dictionary.
1359
+ * @example
1360
+ * ```typescript
1361
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1362
+ * const fWorksheet = fWorkbook.getActiveSheet();
1363
+ * console.log(fWorksheet.newConditionalFormattingRule().getIconMap()); // icons key-value map
1364
+ * ```
1365
+ */
1366
+ getIconMap() {
1367
+ return _univerjs_sheets_conditional_formatting.iconMap;
1368
+ }
1369
+ /**
1370
+ * Set up icon set conditional formatting rule.
1371
+ * @param {{ iconConfigs: IIconSet['config'], isShowValue: boolean }} config - The icon set conditional formatting rule settings.
1372
+ * @param {IIconSet['config']} config.iconConfigs - The icon configurations. iconId property is a string indexing of a group icons.
1373
+ * @param {boolean} config.isShowValue - Whether to show the value in the cell.
1374
+ * @returns {ConditionalFormatIconSetRuleBuilder} The conditional format icon set rule builder.
1375
+ * @example
1376
+ * ```typescript
1377
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1378
+ * const fWorksheet = fWorkbook.getActiveSheet();
1379
+ *
1380
+ * // Create a 3-arrow icon set conditional formatting rule in the range A1:D10.
1381
+ * // The first arrow is green for values greater than 20.
1382
+ * // The second arrow is yellow for values greater than 10.
1383
+ * // The third arrow is red for values less than or equal to 10.
1384
+ * const fRange = fWorksheet.getRange('A1:D10');
1385
+ * const builder = fWorksheet.newConditionalFormattingRule();
1386
+ * console.log(builder.getIconMap()); // icons key-value map
1387
+ * const rule = builder.setIconSet({
1388
+ * iconConfigs: [
1389
+ * { iconType: '3Arrows', iconId: '0', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.greaterThan, value: { type: 'num', value: 20 } },
1390
+ * { iconType: '3Arrows', iconId: '1', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.greaterThan, value: { type: 'num', value: 10 } },
1391
+ * { iconType: '3Arrows', iconId: '2', operator: univerAPI.Enum.ConditionFormatNumberOperatorEnum.lessThanOrEqual, value: { type: 'num', value: 10 } }
1392
+ * ],
1393
+ * isShowValue: true,
1394
+ * })
1395
+ * .setRanges([fRange.getRange()])
1396
+ * .build();
1397
+ * fWorksheet.addConditionalFormattingRule(rule);
1398
+ * ```
1399
+ */
1400
+ setIconSet(config) {
1401
+ return new ConditionalFormatIconSetRuleBuilder(this._initConfig).setIconSet(config);
1402
+ }
1403
+ /**
1404
+ * Set color scale rule.
1405
+ * @param {{ index: number; color: string; value: IValueConfig }[]} config - The color scale rule settings.
1406
+ * @param {number} config.index - The index of the color scale.
1407
+ * @param {string} config.color - The color for the color scale.
1408
+ * @param {IValueConfig} config.value - The value for the color scale.
1409
+ * @returns {ConditionalFormatColorScaleRuleBuilder} The conditional format color scale rule builder.
1410
+ * @example
1411
+ * ```typescript
1412
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1413
+ * const fWorksheet = fWorkbook.getActiveSheet();
1414
+ *
1415
+ * // Create a conditional formatting rule that adds a color scale to cells with values between 0 and 100 in the range A1:D10.
1416
+ * // The color scale is green for 0, yellow for 50, and red for 100.
1417
+ * const fRange = fWorksheet.getRange('A1:D10');
1418
+ * const rule = fWorksheet.newConditionalFormattingRule()
1419
+ * .setColorScale([
1420
+ * { index: 0, color: '#00FF00', value: { type: 'num', value: 0 } },
1421
+ * { index: 1, color: '#FFFF00', value: { type: 'num', value: 50 } },
1422
+ * { index: 2, color: '#FF0000', value: { type: 'num', value: 100 } }
1423
+ * ])
1424
+ * .setRanges([fRange.getRange()])
1425
+ * .build();
1426
+ * fWorksheet.addConditionalFormattingRule(rule);
1427
+ * ```
1428
+ */
1429
+ setColorScale(config) {
1430
+ return new ConditionalFormatColorScaleRuleBuilder(this._initConfig).setColorScale(config);
1431
+ }
1432
+ /**
1433
+ * Set data bar rule.
1434
+ * @param {{
1435
+ * min: IValueConfig;
1436
+ * max: IValueConfig;
1437
+ * isGradient?: boolean;
1438
+ * positiveColor: string;
1439
+ * nativeColor: string;
1440
+ * isShowValue?: boolean;
1441
+ * }} config - The data bar rule settings.
1442
+ * @param {IValueConfig} config.min - The minimum value for the data bar.
1443
+ * @param {IValueConfig} config.max - The maximum value for the data bar.
1444
+ * @param {boolean} [config.isGradient] - Whether the data bar is gradient.
1445
+ * @param {string} config.positiveColor - The color for positive values.
1446
+ * @param {string} config.nativeColor - The color for negative values.
1447
+ * @param {boolean} [config.isShowValue] - Whether to show the value in the cell.
1448
+ * @returns {ConditionalFormatDataBarRuleBuilder} The conditional format data bar rule builder.
1449
+ * @example
1450
+ * ```typescript
1451
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1452
+ * const fWorksheet = fWorkbook.getActiveSheet();
1453
+ *
1454
+ * // Create a conditional formatting rule that adds a data bar to cells with values between -100 and 100 in the range A1:D10.
1455
+ * // positive values are green and negative values are red.
1456
+ * const fRange = fWorksheet.getRange('A1:D10');
1457
+ * const rule = fWorksheet.newConditionalFormattingRule()
1458
+ * .setDataBar({
1459
+ * min: { type: 'num', value: -100 },
1460
+ * max: { type: 'num', value: 100 },
1461
+ * positiveColor: '#00FF00',
1462
+ * nativeColor: '#FF0000',
1463
+ * isShowValue: true
1464
+ * })
1465
+ * .setRanges([fRange.getRange()])
1466
+ * .build();
1467
+ * fWorksheet.addConditionalFormattingRule(rule);
1468
+ * ```
1469
+ */
1470
+ setDataBar(config) {
1471
+ return new ConditionalFormatDataBarRuleBuilder(this._initConfig).setDataBar(config);
1472
+ }
1473
+ /**
1474
+ * Sets the background color for the conditional format rule's format.
1475
+ * @param {string} [color] - The background color to set. If not provided, the background color is removed.
1476
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1477
+ * @example
1478
+ * ```typescript
1479
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1480
+ * const fWorksheet = fWorkbook.getActiveSheet();
1481
+ *
1482
+ * // Create a conditional formatting rule that highlights cells with no content in red for the range A1:D10.
1483
+ * const fRange = fWorksheet.getRange('A1:D10');
1484
+ * const rule = fWorksheet.newConditionalFormattingRule()
1485
+ * .whenCellEmpty()
1486
+ * .setBackground('#FF0000')
1487
+ * .setRanges([fRange.getRange()])
1488
+ * .build();
1489
+ * fWorksheet.addConditionalFormattingRule(rule);
1490
+ * ```
1491
+ */
1492
+ setBackground(color) {
1493
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).setBackground(color);
1494
+ }
1495
+ /**
1496
+ * Sets text bolding for the conditional format rule's format.
1497
+ * @param {boolean} isBold - Whether to bold the text.
1498
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1499
+ * @example
1500
+ * ```typescript
1501
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1502
+ * const fWorksheet = fWorkbook.getActiveSheet();
1503
+ *
1504
+ * // Create a conditional formatting rule that bolds the text for cells with not empty content in the range A1:D10.
1505
+ * const fRange = fWorksheet.getRange('A1:D10');
1506
+ * const rule = fWorksheet.newConditionalFormattingRule()
1507
+ * .whenCellNotEmpty()
1508
+ * .setBold(true)
1509
+ * .setRanges([fRange.getRange()])
1510
+ * .build();
1511
+ * fWorksheet.addConditionalFormattingRule(rule);
1512
+ * ```
1513
+ */
1514
+ setBold(isBold) {
1515
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).setBold(isBold);
1516
+ }
1517
+ /**
1518
+ * Sets the font color for the conditional format rule's format.
1519
+ * @param {string} [color] - The font color to set. If not provided, the font color is removed.
1520
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1521
+ * @example
1522
+ * ```typescript
1523
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1524
+ * const fWorksheet = fWorkbook.getActiveSheet();
1525
+ *
1526
+ * // Create a conditional formatting rule that changes the font color to red for cells with not empty content in the range A1:D10.
1527
+ * const fRange = fWorksheet.getRange('A1:D10');
1528
+ * const rule = fWorksheet.newConditionalFormattingRule()
1529
+ * .whenCellNotEmpty()
1530
+ * .setFontColor('#FF0000')
1531
+ * .setRanges([fRange.getRange()])
1532
+ * .build();
1533
+ * fWorksheet.addConditionalFormattingRule(rule);
1534
+ * ```
1535
+ */
1536
+ setFontColor(color) {
1537
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).setFontColor(color);
1538
+ }
1539
+ /**
1540
+ * Sets text italics for the conditional format rule's format.
1541
+ * @param {boolean} isItalic - Whether to italicize the text.
1542
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1543
+ * @example
1544
+ * ```typescript
1545
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1546
+ * const fWorksheet = fWorkbook.getActiveSheet();
1547
+ *
1548
+ * // Create a conditional formatting rule that italicizes the text for cells with not empty content in the range A1:D10.
1549
+ * const fRange = fWorksheet.getRange('A1:D10');
1550
+ * const rule = fWorksheet.newConditionalFormattingRule()
1551
+ * .whenCellNotEmpty()
1552
+ * .setItalic(true)
1553
+ * .setRanges([fRange.getRange()])
1554
+ * .build();
1555
+ * fWorksheet.addConditionalFormattingRule(rule);
1556
+ * ```
1557
+ */
1558
+ setItalic(isItalic) {
1559
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).setItalic(isItalic);
1560
+ }
1561
+ /**
1562
+ * Sets text strikethrough for the conditional format rule's format.
1563
+ * @param {boolean} isStrikethrough - Whether is strikethrough the text.
1564
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1565
+ * @example
1566
+ * ```typescript
1567
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1568
+ * const fWorksheet = fWorkbook.getActiveSheet();
1569
+ *
1570
+ * // Create a conditional formatting rule that set text strikethrough for cells with not empty content in the range A1:D10.
1571
+ * const fRange = fWorksheet.getRange('A1:D10');
1572
+ * const rule = fWorksheet.newConditionalFormattingRule()
1573
+ * .whenCellNotEmpty()
1574
+ * .setStrikethrough(true)
1575
+ * .setRanges([fRange.getRange()])
1576
+ * .build();
1577
+ * fWorksheet.addConditionalFormattingRule(rule);
1578
+ * ```
1579
+ */
1580
+ setStrikethrough(isStrikethrough) {
1581
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).setStrikethrough(isStrikethrough);
1582
+ }
1583
+ /**
1584
+ * Sets text underlining for the conditional format rule's format.
1585
+ * @param {boolean} isUnderline - Whether to underline the text.
1586
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1587
+ * @example
1588
+ * ```typescript
1589
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1590
+ * const fWorksheet = fWorkbook.getActiveSheet();
1591
+ *
1592
+ * // Create a conditional formatting rule that underlines the text for cells with not empty content in the range A1:D10.
1593
+ * const fRange = fWorksheet.getRange('A1:D10');
1594
+ * const rule = fWorksheet.newConditionalFormattingRule()
1595
+ * .whenCellNotEmpty()
1596
+ * .setUnderline(true)
1597
+ * .setRanges([fRange.getRange()])
1598
+ * .build();
1599
+ * fWorksheet.addConditionalFormattingRule(rule);
1600
+ * ```
1601
+ */
1602
+ setUnderline(isUnderline) {
1603
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).setUnderline(isUnderline);
1604
+ }
1605
+ /**
1606
+ * Sets the conditional format rule to trigger when the cell is empty.
1607
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1608
+ * @example
1609
+ * ```typescript
1610
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1611
+ * const fWorksheet = fWorkbook.getActiveSheet();
1612
+ *
1613
+ * // Create a conditional formatting rule that highlights cells with no content in red for the range A1:D10.
1614
+ * const fRange = fWorksheet.getRange('A1:D10');
1615
+ * const rule = fWorksheet.newConditionalFormattingRule()
1616
+ * .whenCellEmpty()
1617
+ * .setBackground('#FF0000')
1618
+ * .setRanges([fRange.getRange()])
1619
+ * .build();
1620
+ * fWorksheet.addConditionalFormattingRule(rule);
1621
+ * ```
1622
+ */
1623
+ whenCellEmpty() {
1624
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenCellEmpty();
1625
+ }
1626
+ /**
1627
+ * Sets the conditional format rule to trigger when the cell is not empty.
1628
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1629
+ * @example
1630
+ * ```typescript
1631
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1632
+ * const fWorksheet = fWorkbook.getActiveSheet();
1633
+ *
1634
+ * // Create a conditional formatting rule that changes the font color to red for cells with not empty content in the range A1:D10.
1635
+ * const fRange = fWorksheet.getRange('A1:D10');
1636
+ * const rule = fWorksheet.newConditionalFormattingRule()
1637
+ * .whenCellNotEmpty()
1638
+ * .setFontColor('#FF0000')
1639
+ * .setRanges([fRange.getRange()])
1640
+ * .build();
1641
+ * fWorksheet.addConditionalFormattingRule(rule);
1642
+ * ```
1643
+ */
1644
+ whenCellNotEmpty() {
1645
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenCellNotEmpty();
1646
+ }
1647
+ /**
1648
+ * Sets the conditional format rule to trigger when a time period is met.
1649
+ * @param {CFTimePeriodOperator} date - The time period to check for.
1650
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1651
+ * @example
1652
+ * ```typescript
1653
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1654
+ * const fWorksheet = fWorkbook.getActiveSheet();
1655
+ *
1656
+ * // Create a conditional formatting rule that highlights cells with dates in the last 7 days in red for the range A1:D10.
1657
+ * const fRange = fWorksheet.getRange('A1:D10');
1658
+ * const rule = fWorksheet.newConditionalFormattingRule()
1659
+ * .whenDate(univerAPI.Enum.ConditionFormatTimePeriodOperatorEnum.last7Days)
1660
+ * .setBackground('#FF0000')
1661
+ * .setRanges([fRange.getRange()])
1662
+ * .build();
1663
+ * fWorksheet.addConditionalFormattingRule(rule);
1664
+ * ```
1665
+ */
1666
+ whenDate(date) {
1667
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenDate(date);
1668
+ }
1669
+ /**
1670
+ * Sets the conditional format rule to trigger when that the given formula evaluates to `true`.
1671
+ * @param {string} formulaString - A custom formula that evaluates to true if the input is valid. formulaString start with '='.
1672
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1673
+ * @example
1674
+ * ```typescript
1675
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1676
+ * const fWorksheet = fWorkbook.getActiveSheet();
1677
+ *
1678
+ * // Create a conditional formatting rule that highlights cells with values greater than 10 in red for the range A1:D10.
1679
+ * const fRange = fWorksheet.getRange('A1:D10');
1680
+ * const rule = fWorksheet.newConditionalFormattingRule()
1681
+ * .whenFormulaSatisfied('=A1>10')
1682
+ * .setBackground('#FF0000')
1683
+ * .setRanges([fRange.getRange()])
1684
+ * .build();
1685
+ * fWorksheet.addConditionalFormattingRule(rule);
1686
+ * ```
1687
+ */
1688
+ whenFormulaSatisfied(formulaString) {
1689
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenFormulaSatisfied(formulaString);
1690
+ }
1691
+ /**
1692
+ * Sets the conditional format rule to trigger when a number falls between, or is either of, two specified values.
1693
+ * @param {number} start - The lowest acceptable value.
1694
+ * @param {number} end - The highest acceptable value.
1695
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1696
+ * @example
1697
+ * ```typescript
1698
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1699
+ * const fWorksheet = fWorkbook.getActiveSheet();
1700
+ *
1701
+ * // Create a conditional formatting rule that highlights cells with values between 10 and 20 in red for the range A1:D10.
1702
+ * const fRange = fWorksheet.getRange('A1:D10');
1703
+ * const rule = fWorksheet.newConditionalFormattingRule()
1704
+ * .whenNumberBetween(10, 20)
1705
+ * .setBackground('#FF0000')
1706
+ * .setRanges([fRange.getRange()])
1707
+ * .build();
1708
+ * fWorksheet.addConditionalFormattingRule(rule);
1709
+ * ```
1710
+ */
1711
+ whenNumberBetween(start, end) {
1712
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenNumberBetween(start, end);
1713
+ }
1714
+ /**
1715
+ * Sets the conditional format rule to trigger when a number is equal to the given value.
1716
+ * @param {number} value - The sole acceptable value.
1717
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1718
+ * @example
1719
+ * ```typescript
1720
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1721
+ * const fWorksheet = fWorkbook.getActiveSheet();
1722
+ *
1723
+ * // Create a conditional formatting rule that highlights cells with values equal to 10 in red for the range A1:D10.
1724
+ * const fRange = fWorksheet.getRange('A1:D10');
1725
+ * const rule = fWorksheet.newConditionalFormattingRule()
1726
+ * .whenNumberEqualTo(10)
1727
+ * .setBackground('#FF0000')
1728
+ * .setRanges([fRange.getRange()])
1729
+ * .build();
1730
+ * fWorksheet.addConditionalFormattingRule(rule);
1731
+ * ```
1732
+ */
1733
+ whenNumberEqualTo(value) {
1734
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenNumberEqualTo(value);
1735
+ }
1736
+ /**
1737
+ * Sets the conditional format rule to trigger when a number is greater than the given value.
1738
+ * @param {number} value - The highest unacceptable value.
1739
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1740
+ * @example
1741
+ * ```typescript
1742
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1743
+ * const fWorksheet = fWorkbook.getActiveSheet();
1744
+ *
1745
+ * // Create a conditional formatting rule that highlights cells with values greater than 10 in red for the range A1:D10.
1746
+ * const fRange = fWorksheet.getRange('A1:D10');
1747
+ * const rule = fWorksheet.newConditionalFormattingRule()
1748
+ * .whenNumberGreaterThan(10)
1749
+ * .setBackground('#FF0000')
1750
+ * .setRanges([fRange.getRange()])
1751
+ * .build();
1752
+ * fWorksheet.addConditionalFormattingRule(rule);
1753
+ * ```
1754
+ */
1755
+ whenNumberGreaterThan(value) {
1756
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenNumberGreaterThan(value);
1757
+ }
1758
+ /**
1759
+ * Sets the conditional format rule to trigger when a number is greater than or equal to the given value.
1760
+ * @param {number} value - The lowest acceptable value.
1761
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1762
+ * @example
1763
+ * ```typescript
1764
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1765
+ * const fWorksheet = fWorkbook.getActiveSheet();
1766
+ *
1767
+ * // Create a conditional formatting rule that highlights cells with values greater than or equal to 10 in red for the range A1:D10.
1768
+ * const fRange = fWorksheet.getRange('A1:D10');
1769
+ * const rule = fWorksheet.newConditionalFormattingRule()
1770
+ * .whenNumberGreaterThanOrEqualTo(10)
1771
+ * .setBackground('#FF0000')
1772
+ * .setRanges([fRange.getRange()])
1773
+ * .build();
1774
+ * fWorksheet.addConditionalFormattingRule(rule);
1775
+ * ```
1776
+ */
1777
+ whenNumberGreaterThanOrEqualTo(value) {
1778
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenNumberGreaterThanOrEqualTo(value);
1779
+ }
1780
+ /**
1781
+ * Sets the conditional conditional format rule to trigger when a number less than the given value.
1782
+ * @param {number} value - The lowest unacceptable value.
1783
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1784
+ * @example
1785
+ * ```typescript
1786
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1787
+ * const fWorksheet = fWorkbook.getActiveSheet();
1788
+ *
1789
+ * // Create a conditional formatting rule that highlights cells with values less than 10 in red for the range A1:D10.
1790
+ * const fRange = fWorksheet.getRange('A1:D10');
1791
+ * const rule = fWorksheet.newConditionalFormattingRule()
1792
+ * .whenNumberLessThan(10)
1793
+ * .setBackground('#FF0000')
1794
+ * .setRanges([fRange.getRange()])
1795
+ * .build();
1796
+ * fWorksheet.addConditionalFormattingRule(rule);
1797
+ * ```
1798
+ */
1799
+ whenNumberLessThan(value) {
1800
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenNumberLessThan(value);
1801
+ }
1802
+ /**
1803
+ * Sets the conditional format rule to trigger when a number less than or equal to the given value.
1804
+ * @param {number} value - The highest acceptable value.
1805
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1806
+ * @example
1807
+ * ```typescript
1808
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1809
+ * const fWorksheet = fWorkbook.getActiveSheet();
1810
+ *
1811
+ * // Create a conditional formatting rule that highlights cells with values less than or equal to 10 in red for the range A1:D10.
1812
+ * const fRange = fWorksheet.getRange('A1:D10');
1813
+ * const rule = fWorksheet.newConditionalFormattingRule()
1814
+ * .whenNumberLessThanOrEqualTo(10)
1815
+ * .setBackground('#FF0000')
1816
+ * .setRanges([fRange.getRange()])
1817
+ * .build();
1818
+ * fWorksheet.addConditionalFormattingRule(rule);
1819
+ * ```
1820
+ */
1821
+ whenNumberLessThanOrEqualTo(value) {
1822
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenNumberLessThanOrEqualTo(value);
1823
+ }
1824
+ /**
1825
+ * Sets the conditional format rule to trigger when a number does not fall between, and is neither of, two specified values.
1826
+ * @param {number} start - The lowest unacceptable value.
1827
+ * @param {number} end - The highest unacceptable value.
1828
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1829
+ * @example
1830
+ * ```typescript
1831
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1832
+ * const fWorksheet = fWorkbook.getActiveSheet();
1833
+ *
1834
+ * // Create a conditional formatting rule that highlights cells with values not between 10 and 20 in red for the range A1:D10.
1835
+ * const fRange = fWorksheet.getRange('A1:D10');
1836
+ * const rule = fWorksheet.newConditionalFormattingRule()
1837
+ * .whenNumberNotBetween(10, 20)
1838
+ * .setBackground('#FF0000')
1839
+ * .setRanges([fRange.getRange()])
1840
+ * .build();
1841
+ * fWorksheet.addConditionalFormattingRule(rule);
1842
+ * ```
1843
+ */
1844
+ whenNumberNotBetween(start, end) {
1845
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenNumberNotBetween(start, end);
1846
+ }
1847
+ /**
1848
+ * Sets the conditional format rule to trigger when a number is not equal to the given value.
1849
+ * @param {number} value - The sole unacceptable value.
1850
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1851
+ * @example
1852
+ * ```typescript
1853
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1854
+ * const fWorksheet = fWorkbook.getActiveSheet();
1855
+ *
1856
+ * // Create a conditional formatting rule that highlights cells with values not equal to 10 in red for the range A1:D10.
1857
+ * const fRange = fWorksheet.getRange('A1:D10');
1858
+ * const rule = fWorksheet.newConditionalFormattingRule()
1859
+ * .whenNumberNotEqualTo(10)
1860
+ * .setBackground('#FF0000')
1861
+ * .setRanges([fRange.getRange()])
1862
+ * .build();
1863
+ * fWorksheet.addConditionalFormattingRule(rule);
1864
+ * ```
1865
+ */
1866
+ whenNumberNotEqualTo(value) {
1867
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenNumberNotEqualTo(value);
1868
+ }
1869
+ /**
1870
+ * Sets the conditional format rule to trigger when that the input contains the given value.
1871
+ * @param {string} text - The value that the input must contain.
1872
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1873
+ * @example
1874
+ * ```typescript
1875
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1876
+ * const fWorksheet = fWorkbook.getActiveSheet();
1877
+ *
1878
+ * // Create a conditional formatting rule that highlights cells with text containing 'apple' in red for the range A1:D10.
1879
+ * const fRange = fWorksheet.getRange('A1:D10');
1880
+ * const rule = fWorksheet.newConditionalFormattingRule()
1881
+ * .whenTextContains('apple')
1882
+ * .setBackground('#FF0000')
1883
+ * .setRanges([fRange.getRange()])
1884
+ * .build();
1885
+ * fWorksheet.addConditionalFormattingRule(rule);
1886
+ * ```
1887
+ */
1888
+ whenTextContains(text) {
1889
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenTextContains(text);
1890
+ }
1891
+ /**
1892
+ * Sets the conditional format rule to trigger when that the input does not contain the given value.
1893
+ * @param {string} text - The value that the input must not contain.
1894
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1895
+ * @example
1896
+ * ```typescript
1897
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1898
+ * const fWorksheet = fWorkbook.getActiveSheet();
1899
+ *
1900
+ * // Create a conditional formatting rule that highlights cells with text not containing 'apple' in red for the range A1:D10.
1901
+ * const fRange = fWorksheet.getRange('A1:D10');
1902
+ * const rule = fWorksheet.newConditionalFormattingRule()
1903
+ * .whenTextDoesNotContain('apple')
1904
+ * .setBackground('#FF0000')
1905
+ * .setRanges([fRange.getRange()])
1906
+ * .build();
1907
+ * fWorksheet.addConditionalFormattingRule(rule);
1908
+ * ```
1909
+ */
1910
+ whenTextDoesNotContain(text) {
1911
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenTextDoesNotContain(text);
1912
+ }
1913
+ /**
1914
+ * Sets the conditional format rule to trigger when that the input ends with the given value.
1915
+ * @param {string} text - Text to compare against the end of the string.
1916
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1917
+ * @example
1918
+ * ```typescript
1919
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1920
+ * const fWorksheet = fWorkbook.getActiveSheet();
1921
+ *
1922
+ * // Create a conditional formatting rule that highlights cells with text ending with '.ai' in red for the range A1:D10.
1923
+ * const fRange = fWorksheet.getRange('A1:D10');
1924
+ * const rule = fWorksheet.newConditionalFormattingRule()
1925
+ * .whenTextEndsWith('.ai')
1926
+ * .setBackground('#FF0000')
1927
+ * .setRanges([fRange.getRange()])
1928
+ * .build();
1929
+ * fWorksheet.addConditionalFormattingRule(rule);
1930
+ * ```
1931
+ */
1932
+ whenTextEndsWith(text) {
1933
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenTextEndsWith(text);
1934
+ }
1935
+ /**
1936
+ * Sets the conditional format rule to trigger when that the input is equal to the given value.
1937
+ * @param {string} text - The sole acceptable value.
1938
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1939
+ * @example
1940
+ * ```typescript
1941
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1942
+ * const fWorksheet = fWorkbook.getActiveSheet();
1943
+ *
1944
+ * // Create a conditional formatting rule that highlights cells with text equal to 'apple' in red for the range A1:D10.
1945
+ * const fRange = fWorksheet.getRange('A1:D10');
1946
+ * const rule = fWorksheet.newConditionalFormattingRule()
1947
+ * .whenTextEqualTo('apple')
1948
+ * .setBackground('#FF0000')
1949
+ * .setRanges([fRange.getRange()])
1950
+ * .build();
1951
+ * fWorksheet.addConditionalFormattingRule(rule);
1952
+ * ```
1953
+ */
1954
+ whenTextEqualTo(text) {
1955
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenTextEqualTo(text);
1956
+ }
1957
+ /**
1958
+ * Sets the conditional format rule to trigger when that the input starts with the given value.
1959
+ * @param {string} text - Text to compare against the beginning of the string.
1960
+ * @returns {ConditionalFormatHighlightRuleBuilder} The conditional format highlight rule builder.
1961
+ * @example
1962
+ * ```typescript
1963
+ * const fWorkbook = univerAPI.getActiveWorkbook();
1964
+ * const fWorksheet = fWorkbook.getActiveSheet();
1965
+ *
1966
+ * // Create a conditional formatting rule that highlights cells with text starting with 'https://' in red for the range A1:D10.
1967
+ * const fRange = fWorksheet.getRange('A1:D10');
1968
+ * const rule = fWorksheet.newConditionalFormattingRule()
1969
+ * .whenTextStartsWith('https://')
1970
+ * .setBackground('#FF0000')
1971
+ * .setRanges([fRange.getRange()])
1972
+ * .build();
1973
+ * fWorksheet.addConditionalFormattingRule(rule);
1974
+ * ```
1975
+ */
1976
+ whenTextStartsWith(text) {
1977
+ return new ConditionalFormatHighlightRuleBuilder(this._initConfig).whenTextStartsWith(text);
1978
+ }
1979
+ };
1980
+
1981
+ //#endregion
1982
+ //#region src/facade/f-range.ts
1983
+ var FRangeSheetsConditionalFormattingMixin = class extends _univerjs_sheets_facade.FRange {
1984
+ _getConditionalFormattingRuleModel() {
1985
+ return this._injector.get(_univerjs_sheets_conditional_formatting.ConditionalFormattingRuleModel);
1986
+ }
1987
+ getConditionalFormattingRules() {
1988
+ return [...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(), this._worksheet.getSheetId()) || []].filter((rule) => rule.ranges.some((range) => _univerjs_core.Rectangle.intersects(range, this._range)));
1989
+ }
1990
+ createConditionalFormattingRule() {
1991
+ return new FConditionalFormattingBuilder({ ranges: [this._range] });
1992
+ }
1993
+ addConditionalFormattingRule(rule) {
1994
+ const params = {
1995
+ unitId: this._workbook.getUnitId(),
1996
+ subUnitId: this._worksheet.getSheetId(),
1997
+ rule
1998
+ };
1999
+ this._commandService.syncExecuteCommand(_univerjs_sheets_conditional_formatting.AddCfCommand.id, params);
2000
+ return this;
2001
+ }
2002
+ deleteConditionalFormattingRule(cfId) {
2003
+ const params = {
2004
+ unitId: this._workbook.getUnitId(),
2005
+ subUnitId: this._worksheet.getSheetId(),
2006
+ cfId
2007
+ };
2008
+ this._commandService.syncExecuteCommand(_univerjs_sheets_conditional_formatting.DeleteCfCommand.id, params);
2009
+ return this;
2010
+ }
2011
+ moveConditionalFormattingRule(cfId, toCfId, type = "after") {
2012
+ const params = {
2013
+ unitId: this._workbook.getUnitId(),
2014
+ subUnitId: this._worksheet.getSheetId(),
2015
+ start: {
2016
+ id: cfId,
2017
+ type: "self"
2018
+ },
2019
+ end: {
2020
+ id: toCfId,
2021
+ type
2022
+ }
2023
+ };
2024
+ this._commandService.syncExecuteCommand(_univerjs_sheets_conditional_formatting.MoveCfCommand.id, params);
2025
+ return this;
2026
+ }
2027
+ setConditionalFormattingRule(cfId, rule) {
2028
+ const params = {
2029
+ unitId: this._workbook.getUnitId(),
2030
+ subUnitId: this._worksheet.getSheetId(),
2031
+ rule,
2032
+ cfId
2033
+ };
2034
+ this._commandService.syncExecuteCommand(_univerjs_sheets_conditional_formatting.SetCfCommand.id, params);
2035
+ return this;
2036
+ }
2037
+ clearConditionalFormatRules() {
2038
+ const params = {
2039
+ unitId: this._workbook.getUnitId(),
2040
+ subUnitId: this._worksheet.getSheetId(),
2041
+ ranges: [this._range]
2042
+ };
2043
+ this._commandService.syncExecuteCommand(_univerjs_sheets_conditional_formatting.ClearRangeCfCommand.id, params);
2044
+ return this;
2045
+ }
2046
+ };
2047
+ _univerjs_sheets_facade.FRange.extend(FRangeSheetsConditionalFormattingMixin);
2048
+
2049
+ //#endregion
2050
+ //#region src/facade/f-worksheet.ts
2051
+ var FWorksheetConditionalFormattingMixin = class extends _univerjs_sheets_facade.FWorksheet {
2052
+ _getConditionalFormattingRuleModel() {
2053
+ return this._injector.get(_univerjs_sheets_conditional_formatting.ConditionalFormattingRuleModel);
2054
+ }
2055
+ getConditionalFormattingRules() {
2056
+ return [...this._getConditionalFormattingRuleModel().getSubunitRules(this._workbook.getUnitId(), this._worksheet.getSheetId()) || []];
2057
+ }
2058
+ createConditionalFormattingRule() {
2059
+ return new FConditionalFormattingBuilder();
2060
+ }
2061
+ newConditionalFormattingRule() {
2062
+ return new FConditionalFormattingBuilder();
2063
+ }
2064
+ addConditionalFormattingRule(rule) {
2065
+ const params = {
2066
+ unitId: this._workbook.getUnitId(),
2067
+ subUnitId: this._worksheet.getSheetId(),
2068
+ rule
2069
+ };
2070
+ this._commandService.syncExecuteCommand(_univerjs_sheets_conditional_formatting.AddCfCommand.id, params);
2071
+ return this;
2072
+ }
2073
+ deleteConditionalFormattingRule(cfId) {
2074
+ const params = {
2075
+ unitId: this._workbook.getUnitId(),
2076
+ subUnitId: this._worksheet.getSheetId(),
2077
+ cfId
2078
+ };
2079
+ this._commandService.syncExecuteCommand(_univerjs_sheets_conditional_formatting.DeleteCfCommand.id, params);
2080
+ return this;
2081
+ }
2082
+ moveConditionalFormattingRule(cfId, toCfId, type = "after") {
2083
+ const params = {
2084
+ unitId: this._workbook.getUnitId(),
2085
+ subUnitId: this._worksheet.getSheetId(),
2086
+ start: {
2087
+ id: cfId,
2088
+ type: "self"
2089
+ },
2090
+ end: {
2091
+ id: toCfId,
2092
+ type
2093
+ }
2094
+ };
2095
+ this._commandService.syncExecuteCommand(_univerjs_sheets_conditional_formatting.MoveCfCommand.id, params);
2096
+ return this;
2097
+ }
2098
+ setConditionalFormattingRule(cfId, rule) {
2099
+ const params = {
2100
+ unitId: this._workbook.getUnitId(),
2101
+ subUnitId: this._worksheet.getSheetId(),
2102
+ cfId,
2103
+ rule
2104
+ };
2105
+ this._commandService.syncExecuteCommand(_univerjs_sheets_conditional_formatting.SetCfCommand.id, params);
2106
+ return this;
2107
+ }
2108
+ clearConditionalFormatRules() {
2109
+ const params = {
2110
+ unitId: this._workbook.getUnitId(),
2111
+ subUnitId: this._worksheet.getSheetId()
2112
+ };
2113
+ this._commandService.syncExecuteCommand(_univerjs_sheets_conditional_formatting.ClearWorksheetCfCommand.id, params);
2114
+ return this;
2115
+ }
2116
+ };
2117
+ _univerjs_sheets_facade.FWorksheet.extend(FWorksheetConditionalFormattingMixin);
2118
+
2119
+ //#endregion
2120
+ //#region src/facade/f-enum.ts
2121
+ /**
2122
+ * Copyright 2023-present DreamNum Co., Ltd.
2123
+ *
2124
+ * Licensed under the Apache License, Version 2.0 (the "License");
2125
+ * you may not use this file except in compliance with the License.
2126
+ * You may obtain a copy of the License at
2127
+ *
2128
+ * http://www.apache.org/licenses/LICENSE-2.0
2129
+ *
2130
+ * Unless required by applicable law or agreed to in writing, software
2131
+ * distributed under the License is distributed on an "AS IS" BASIS,
2132
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2133
+ * See the License for the specific language governing permissions and
2134
+ * limitations under the License.
2135
+ */
2136
+ var FSheetsConditionalFormattingEnumMixin = class extends _univerjs_core_facade.FEnum {
2137
+ get ConditionFormatNumberOperatorEnum() {
2138
+ return _univerjs_sheets_conditional_formatting.CFNumberOperator;
2139
+ }
2140
+ get ConditionFormatTimePeriodOperatorEnum() {
2141
+ return _univerjs_sheets_conditional_formatting.CFTimePeriodOperator;
2142
+ }
2143
+ };
2144
+ _univerjs_core_facade.FEnum.extend(FSheetsConditionalFormattingEnumMixin);
2145
+
2146
+ //#endregion
2147
+ exports.FConditionalFormattingBuilder = FConditionalFormattingBuilder;