/**
 * Minified by jsDelivr using Terser v5.39.0.
 * Original file: /npm/@univerjs/sheets-find-replace@0.21.0/lib/es/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import{ColorKit,CommandType,DependentOn,Disposable,EDITOR_ACTIVATED,ICommandService,IConfigService,IContextService,IUndoRedoService,IUniverInstanceService,Inject,Injector,ObjectMatrix,Plugin,Rectangle,ThemeService,Tools,UniverInstanceType,fromCallback,groupBy,merge,replaceInDocumentBody,rotate}from"@univerjs/core";import{SelectRangeCommand,SetRangeValuesCommand,SetSelectionsOperation,SetWorksheetActivateCommand,SetWorksheetActiveOperation,SheetsSelectionsService,UniverSheetsPlugin}from"@univerjs/sheets";import{IRenderManagerService,RENDER_RAW_FORMULA_KEY,Rect,Shape}from"@univerjs/engine-render";import{FindBy,FindDirection,FindModel,FindReplaceController,FindScope,IFindReplaceService,UniverFindReplacePlugin}from"@univerjs/find-replace";import{ScrollToCellCommand,SheetSkeletonManagerService,getCoordByCell,getSheetObject}from"@univerjs/sheets-ui";import{Subject,debounceTime,filter,merge as merge$1,skip,throttleTime}from"rxjs";const SheetReplaceCommand={id:"sheet.command.replace",type:CommandType.COMMAND,handler:async(e,t)=>{const i=e.get(IUndoRedoService),n=e.get(ICommandService),{unitId:r,replacements:o}=t,s=i.__tempBatchingUndoRedo(r),a=await Promise.all(o.map((e=>n.executeCommand(SetRangeValuesCommand.id,{unitId:r,subUnitId:e.subUnitId,value:e.value}))));return s.dispose(),getReplaceAllResult(a,o)}};function getReplaceAllResult(e,t){let i=0,n=0;return e.forEach(((e,r)=>{const o=t[r].count;e?i+=o:n+=o})),{success:i,failure:n}}function _typeof(e){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},_typeof(e)}function toPrimitive(e,t){if("object"!=_typeof(e)||!e)return e;var i=e[Symbol.toPrimitive];if(void 0!==i){var n=i.call(e,t||"default");if("object"!=_typeof(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function toPropertyKey(e){var t=toPrimitive(e,"string");return"symbol"==_typeof(t)?t:t+""}function _defineProperty(e,t,i){return(t=toPropertyKey(t))in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}var SheetFindReplaceHighlightShape=class extends Shape{constructor(e,t){super(e,t),_defineProperty(this,"_activated",!1),_defineProperty(this,"_inHiddenRange",!1),_defineProperty(this,"_color",void 0),t&&this.setShapeProps(t)}setShapeProps(e){this._activated=!!e.activated,void 0!==e.inHiddenRange&&(this._inHiddenRange=e.inHiddenRange),void 0!==e.color&&(this._color=e.color),this.transformByState({width:e.width,height:e.height})}_draw(e){const t=this._activated,i=`rgba(${this._color.r}, ${this._color.g}, ${this._color.b}, 0.35)`,n=`rgb(${this._color.r}, ${this._color.g}, ${this._color.b})`;Rect.drawWith(e,{width:this.width,height:this.height,fill:i,stroke:t?n:void 0,strokeWidth:t?2:0,evented:!1})}};function isSamePosition(e,t){return e.startRow===t.startRow&&e.startColumn===t.startColumn}function isBehindPositionWithRowPriority(e,t){return e.startRow<t.startRow||e.startRow===t.startRow&&e.startColumn<=t.startColumn}function isBehindPositionWithColumnPriority(e,t){return e.startColumn<t.startColumn||e.startColumn===t.startColumn&&e.startRow<=t.startRow}function isBeforePositionWithRowPriority(e,t){return e.startRow>t.startRow||e.startRow===t.startRow&&e.startColumn>=t.startColumn}function isBeforePositionWithColumnPriority(e,t){return e.startColumn>t.startColumn||e.startColumn===t.startColumn&&e.startRow>=t.startRow}function isSelectionSingleCell(e,t){const{range:i}=e,{startRow:n,startColumn:r}=i,o=t.getMergedCell(n,r);return o?Rectangle.equals(i,o):i.endRow===i.startRow&&i.endColumn===i.startColumn}function __decorateParam(e,t){return function(i,n){t(i,n,e)}}function __decorate(e,t,i,n){var r,o=arguments.length,s=o<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(r=e[a])&&(s=(o<3?r(s):o>3?r(t,i,s):r(t,i))||s);return o>3&&s&&Object.defineProperty(t,i,s),s}let SheetsFindReplaceController=class extends Disposable{constructor(e,t,i,n,r){super(),this._injector=e,this._findReplaceController=t,this._contextService=i,this._findReplaceService=n,this._commandService=r,_defineProperty(this,"_provider",void 0),this._init(),this._initCommands()}dispose(){super.dispose(),this._findReplaceController.closePanel(),this._provider.dispose()}_init(){const e=this._injector.createInstance(SheetsFindReplaceProvider);this._provider=e,this.disposeWithMe(this._findReplaceService.registerFindReplaceProvider(e)),this.disposeWithMe(this._contextService.subscribeContextValue$(EDITOR_ACTIVATED).pipe(filter((e=>!!e))).subscribe((()=>this._findReplaceController.closePanel())))}_initCommands(){[SheetReplaceCommand].forEach((e=>this.disposeWithMe(this._commandService.registerCommand(e))))}};SheetsFindReplaceController=__decorate([__decorateParam(0,Inject(Injector)),__decorateParam(1,Inject(FindReplaceController)),__decorateParam(2,IContextService),__decorateParam(3,IFindReplaceService),__decorateParam(4,ICommandService)],SheetsFindReplaceController);const SHEETS_FIND_REPLACE_PROVIDER_NAME="sheets-find-replace-provider",FIND_REPLACE_Z_INDEX=1e4;let SheetFindModel=class extends FindModel{get _matchesCount(){return this._matches.length}get unitId(){return this._workbook.getUnitId()}get matchesCount(){return this._matchesCount}get matchesPosition(){return this._matchesPosition}get currentMatch(){return this._matchesPosition>0?this._matches[this._matchesPosition-1]:null}constructor(e,t,i,n,r,o,s,a){super(),this._workbook=e,this._sheetSkeletonManagerService=t,this._univerInstanceService=i,this._renderManagerService=n,this._commandService=r,this._contextService=o,this._themeService=s,_defineProperty(this,"_matchesUpdate$",new Subject),_defineProperty(this,"matchesUpdate$",this._matchesUpdate$.asObservable()),_defineProperty(this,"_activelyChangingMatch$",new Subject),_defineProperty(this,"activelyChangingMatch$",this._activelyChangingMatch$.asObservable()),_defineProperty(this,"_matchesByWorksheet",new Map),_defineProperty(this,"_matches",[]),_defineProperty(this,"_matchesPosition",0),_defineProperty(this,"_activeHighlightIndex",-1),_defineProperty(this,"_highlightShapes",[]),_defineProperty(this,"_currentHighlightShape",null),_defineProperty(this,"_query",null),_defineProperty(this,"_workbookSelections",void 0),this._workbookSelections=a.getWorkbookSelections(this.unitId)}dispose(){super.dispose(),this._disposeHighlights(),this._toggleDisplayRawFormula(!1)}getMatches(){return this._matches}start(e){switch(this._query=e,e.findBy===FindBy.FORMULA?this._toggleDisplayRawFormula(!0):this._toggleDisplayRawFormula(!1),e.findScope){case FindScope.UNIT:this.findInWorkbook(e);break;case FindScope.SUBUNIT:default:this.findInActiveWorksheet(e)}}focusSelection(){const e=this.currentMatch;e&&this._commandService.executeCommand(SelectRangeCommand.id,{unitId:e.unitId,subUnit:e.range.subUnitId,range:e.range.range})}_toggleDisplayRawFormula(e){this._contextService.setContextValue(RENDER_RAW_FORMULA_KEY,e)}findInWorkbook(e){const t=this._workbook.getUnitId();let i,n=!0;const r=()=>{this._matches=this._workbook.getSheets().filter((e=>!e.isSheetHidden())).map((i=>{const n=this._findInWorksheet(i,e,t),r=i.getSheetId(),{results:o}=n;return o.length?this._matchesByWorksheet.set(r,n.results):this._matchesByWorksheet.delete(r),n})).map((e=>e.results)).flat(),this._updateFindHighlight(),n?(i={results:this._matches},n=!1):this._matchesUpdate$.next(this._matches)};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe((()=>{this._updateFindHighlight(),this._updateCurrentHighlightShape(this._activeHighlightIndex)}))),this.disposeWithMe(fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter((([e,t])=>e.id===SetWorksheetActiveOperation.id&&!(null==t?void 0:t.fromFindReplace)))).subscribe((()=>{const e=this._workbook.getActiveSheet();if(!e)return;const t=e.getSheetId();this._matchesByWorksheet.has(t)&&this._findNextMatchOnActiveSheetChange(e)}))),this.disposeWithMe(fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter((([e])=>e.type===CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId())),throttleTime(600,void 0,{leading:!1,trailing:!0})).subscribe((()=>r()))),r(),i}_findNextMatchOnActiveSheetChange(e){let t,i,n=0;const r=this._matchesByWorksheet.get(e.getSheetId()),o=this._workbookSelections.getCurrentSelections();(null==o?void 0:o.length)?([t,n]=this._findNextMatchByRange(r,o[0].range),i=r.findIndex((e=>e===t))):(t=r[0],i=0,n=this._matches.findIndex((e=>e===t))),this._matchesPosition=n+1,this._activelyChangingMatch$.next(t),this._activeHighlightIndex=i,this._updateFindHighlight(),this._updateCurrentHighlightShape(i)}findInActiveWorksheet(e){const t=this._workbook.getUnitId(),i=()=>{var e;const t=this._workbook.getActiveSheet();if(!t)return!1;const i=this._workbookSelections.getCurrentSelections();return null!==(e=null==i?void 0:i.some((e=>!isSelectionSingleCell(e,t))))&&void 0!==e&&e};let n,r=!0,o=!1;const s=()=>{const s=this._workbook.getActiveSheet();if(!s)return{results:[]};const a=this.currentMatch;o=i();const h=this._workbookSelections.getCurrentSelections(),c=o?this._findInSelections(s,h,e,t):this._findInWorksheet(s,e,t);return this._matches=c.results,this._matchesPosition=this._tryRestoreLastMatchesPosition(a,this._matches),r?(n=c,r=!1):this._matchesUpdate$.next(this._matches),this._updateFindHighlight(),c};return this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe((()=>this._updateFindHighlight()))),this.disposeWithMe(merge$1(fromCallback(this._commandService.onCommandExecuted.bind(this._commandService)).pipe(filter((([e])=>{if(e.type===CommandType.MUTATION&&e.params.unitId===this._workbook.getUnitId())return!0;if(e.id===SetSelectionsOperation.id&&e.params.unitId===t){const e=i();return(!1!==e||!1!==o)&&(o=e,!0)}return!1}))),this._workbook.activeSheet$.pipe(skip(1))).pipe(debounceTime(200)).subscribe((()=>s()))),s(),n}_findInRange(e,t,i,n,r){const o=[],s=e.getSheetId(),a=(t.findDirection===FindDirection.COLUMN?e.iterateByColumn:e.iterateByRow).bind(e)(i);for(const i of a){const{row:a,col:h,colSpan:c,rowSpan:l,value:d}=i;if((null==r?void 0:r(a,h))||!d)continue;if(e.getRowFiltered(a))continue;const{hit:u,replaceable:_,isFormula:g}=hitCell(e,a,h,t,d);if(u){const e={provider:"sheets-find-replace-provider",unitId:n,replaceable:_,isFormula:g,range:{subUnitId:s,range:{startRow:a,startColumn:h,endColumn:h+(null!=c?c:1)-1,endRow:a+(null!=l?l:1)-1}}};o.push(e)}}return{results:o}}_findInSelections(e,t,i,n){const{findDirection:r}=i,o=r===FindDirection.ROW?isBehindPositionWithRowPriority:isBehindPositionWithColumnPriority,s=new Set;return{results:t.map((t=>this._findInRange(e,i,t.range,n,((e,t)=>{const i=`${e}-${t}`;return!!s.has(i)||(s.add(i),!1)})).results)).flat().sort(((e,t)=>o(e.range.range,t.range.range)?-1:1))}}_findInWorksheet(e,t,i){const n={startRow:0,startColumn:0,endRow:e.getRowCount()-1,endColumn:e.getColumnCount()-1};return this._findInRange(e,t,n,i)}_disposeHighlights(){var e;this._highlightShapes.forEach((e=>{var t;null===(t=e.getScene())||void 0===t||t.makeDirty(),e.dispose()})),this._highlightShapes=[],null===(e=this._currentHighlightShape)||void 0===e||e.dispose(),this._currentHighlightShape=null}_updateFindHighlight(){this._disposeHighlights();const e=this._sheetSkeletonManagerService.getCurrentSkeleton();if(!e)return;const t=this._workbook.getUnitId(),i=this._renderManagerService.getRenderById(t);if(null==i)return;const{scene:n}=i,r=this._matches,o=new ColorKit(this._themeService.getColorFromTheme("yellow.400")).toRgb(),s=this._workbook.getActiveSheet();if(!s)return;const a=s.getSheetId(),h=r.filter((e=>e.range.subUnitId===a)).map(((t,i)=>{const{startColumn:r,startRow:a,endColumn:h,endRow:c}=t.range.range,l=getCoordByCell(a,r,n,e),d=getCoordByCell(c,h,n,e),{startX:u,startY:_}=l,{endX:g,endY:m}=d;let S=!0;for(let e=a;e<=c;e++)if(s.getRowRawVisible(e)){S=!1;break}let p=!0;for(let e=r;e<=h;e++)if(s.getColVisible(e)){p=!1;break}return new SheetFindReplaceHighlightShape(`find-highlight-${i}`,{left:u,top:_,color:o,width:p?2:g-u,height:S?2:m-_,evented:!1,inHiddenRange:S||p,zIndex:1e4})}));n.addObjects(h),this._highlightShapes=h,n.makeDirty()}_updateCurrentHighlightShape(e){var t;if(null===(t=this._currentHighlightShape)||void 0===t||t.setShapeProps({activated:!1}),this._currentHighlightShape=null,void 0!==e){const t=this._highlightShapes[e];if(!t)return;this._currentHighlightShape=t,t.setShapeProps({activated:!0})}}_getSheetObject(){return getSheetObject(this._univerInstanceService,this._renderManagerService)}_focusMatch(e){var t;const i=e.range.subUnitId;i!==(null===(t=this._workbook.getActiveSheet())||void 0===t?void 0:t.getSheetId())&&this._commandService.executeCommand(SetWorksheetActivateCommand.id,{unitId:this._workbook.getUnitId(),subUnitId:i},{fromFindReplace:!0}),this._commandService.executeCommand(ScrollToCellCommand.id,{range:e.range.range},{fromFindReplace:!0})}_tryRestoreLastMatchesPosition(e,t){if(!e)return 0;const{subUnitId:i}=e.range,{startColumn:n,startRow:r}=e.range.range,o=t.findIndex((e=>{if(i!==e.range.subUnitId)return!1;const{startColumn:t,startRow:o}=e.range.range;return t===n&&o===r}));return o>-1?o+1:0}moveToNextMatch(e){var t,i,n,r;if(!this._matches.length)return null;const o=null!==(t=null==e?void 0:e.loop)&&void 0!==t&&t,s=null!==(i=null==e?void 0:e.stayIfOnMatch)&&void 0!==i&&i,a=null!==(n=null==e?void 0:e.noFocus)&&void 0!==n&&n,h=null!==(r=null==e?void 0:e.ignoreSelection)&&void 0!==r&&r,c=this._findNextMatch(o,s,h);if(c){var l;const[e,t]=c;return this._matchesPosition=t+1,this._query.findScope===FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex((t=>t===e)):this._activeHighlightIndex=t,a||this._focusMatch(e),(null===(l=this._workbook.getActiveSheet())||void 0===l?void 0:l.getSheetId())===e.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}moveToPreviousMatch(e){var t,i,n,r;if(!this._matches.length)return null;const o=null!==(t=null==e?void 0:e.loop)&&void 0!==t&&t,s=null!==(i=null==e?void 0:e.stayIfOnMatch)&&void 0!==i&&i,a=null!==(n=null==e?void 0:e.noFocus)&&void 0!==n&&n,h=null!==(r=null==e?void 0:e.ignoreSelection)&&void 0!==r&&r,c=this._findPreviousMatch(o,s,h);if(c){var l;const[e,t]=c;return this._matchesPosition=t+1,this._query.findScope===FindScope.UNIT?this._activeHighlightIndex=this._matchesByWorksheet.get(e.range.subUnitId).findIndex((t=>t===e)):this._activeHighlightIndex=t,a||this._focusMatch(e),(null===(l=this._workbook.getActiveSheet())||void 0===l?void 0:l.getSheetId())===e.range.subUnitId&&this._updateCurrentHighlightShape(this._activeHighlightIndex),e}return this._matchesPosition=0,this._updateCurrentHighlightShape(),null}_findPreviousMatch(e=!1,t=!1,i=!1){var n;if(this.currentMatch){const i=this._matches.findIndex((e=>e===this.currentMatch));if(t)return[this.currentMatch,i];const n=i-1;if(!e&&n<0)return null;const r=this._matches.length,o=(n+r)%r;return[this._matches[o],o]}const r=this._workbookSelections.getCurrentLastSelection();if(i||!r){const e=this._matches.length-1;return[this._matches[e],e]}if(this._query.findScope!==FindScope.UNIT)return this._findPreviousMatchByRange(this._matches,r.range);const o=null===(n=this._workbook.getActiveSheet())||void 0===n?void 0:n.getSheetId();if(!o)return null;const s=this._findPreviousWorksheetThatHasAMatch(o,e);return s?this._findPreviousMatchByRange(this._matchesByWorksheet.get(s),r.range):null}_findNextMatch(e=!1,t=!1,i=!1){var n;if(this.currentMatch){const i=this._matches.findIndex((e=>e===this.currentMatch));if(t)return[this.currentMatch,i];const n=i+1,r=this._matches.length;if(!e&&n>=r)return null;const o=n%r;return[this._matches[o],o]}const r=this._workbookSelections.getCurrentLastSelection();if(i||!r)return[this._matches[0],0];if(this._query.findScope!==FindScope.UNIT)return this._findNextMatchByRange(this._matches,r.range,t);const o=null===(n=this._workbook.getActiveSheet())||void 0===n?void 0:n.getSheetId();if(!o)return null;const s=this._findNextWorksheetThatHasAMatch(o,e);return s?this._findNextMatchByRange(this._matchesByWorksheet.get(s),r.range):null}_findPreviousWorksheetThatHasAMatch(e,t=!1){const i=this._workbook.getSheetOrders(),n=i.findIndex((t=>t===e)),r=(t?rotate(i,n+1):i.slice(0,n+1)).findLast((e=>this._matchesByWorksheet.has(e)));return null!=r?r:null}_findNextWorksheetThatHasAMatch(e,t=!1){const i=this._workbook.getSheetOrders(),n=i.findIndex((t=>t===e)),r=(t?rotate(i,n):i.slice(n)).find((e=>this._matchesByWorksheet.has(e)));return null!=r?r:null}_findNextMatchByRange(e,t,i=!1){const n=this._query.findDirection===FindDirection.ROW;let r=e.findIndex((e=>{const r=e.range.range;if(!(n?isBehindPositionWithRowPriority(t,r):isBehindPositionWithColumnPriority(t,r)))return!1;const o=isSamePosition(t,r);return i?o:!o}));-1===r&&(r=e.length-1);const o=e[r];return[o,this._matches.findIndex((e=>e===o))]}_findPreviousMatchByRange(e,t,i=!1){const n=this._query.findDirection===FindDirection.ROW;let r=this._matches.findLastIndex((e=>{const r=e.range.range;if(!(n?isBeforePositionWithRowPriority(t,r):isBeforePositionWithColumnPriority(t,r)))return!1;const o=isSamePosition(t,r);return i?o:!o}));-1===r&&(r=0);const o=e[r];return[o,this._matches.findIndex((e=>e===o))]}async replace(e){if(0===this._matchesCount||!this.currentMatch||!this._query||!this.currentMatch.replaceable)return!1;const t=this.currentMatch.range,i=this._workbook.getSheetBySheetId(this.currentMatch.range.subUnitId),n=this._getReplacedCellData(this.currentMatch,i,this._query.findBy===FindBy.FORMULA,this._query.findString,e,this._query.caseSensitive?"g":"ig"),r={unitId:this.currentMatch.unitId,subUnitId:t.subUnitId,value:{[t.range.startRow]:{[t.range.startColumn]:n}}};return this._commandService.executeCommand(SetRangeValuesCommand.id,r)}async replaceAll(e){if(0===this._matchesCount||!this._query)return{success:0,failure:0};const t=this._workbook.getUnitId(),{findString:i,caseSensitive:n,findBy:r}=this._query,o=r===FindBy.FORMULA,s=n?"g":"ig",a=[];return groupBy(this._matches.filter((e=>e.replaceable)),(e=>e.range.subUnitId)).forEach(((t,n)=>{const r=new ObjectMatrix,h=this._workbook.getSheetBySheetId(n);t.forEach((t=>{const{startColumn:n,startRow:a}=t.range.range,c=this._getReplacedCellData(t,h,o,i,e,s);c&&r.setValue(a,n,c)})),a.push({count:t.length,subUnitId:n,value:r.getMatrix()})})),a?this._commandService.executeCommand(SheetReplaceCommand.id,{unitId:t,replacements:a}):{success:0,failure:0}}_getReplacedCellData(e,t,i,n,r,o){var s;const{startRow:a,startColumn:h}=e.range.range,c=t.getCellRaw(a,h);if(e.isFormula)return i?{f:c.f.replace(new RegExp(escapeRegExp(n),o),r),v:null}:null;if(null===(s=c.p)||void 0===s?void 0:s.body){const e=Tools.deepClone(c.p);return replaceInDocumentBody(e.body,n,r,this._query.caseSensitive),{p:e}}return{v:c.v.toString().replace(new RegExp(escapeRegExp(n),o),r)}}};function escapeRegExp(e){return e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}SheetFindModel=__decorate([__decorateParam(2,IUniverInstanceService),__decorateParam(3,IRenderManagerService),__decorateParam(4,ICommandService),__decorateParam(5,IContextService),__decorateParam(6,Inject(ThemeService)),__decorateParam(7,Inject(SheetsSelectionsService))],SheetFindModel);let SheetsFindReplaceProvider=class extends Disposable{constructor(e,t,i){super(),this._univerInstanceService=e,this._renderManagerService=t,this._injector=i,_defineProperty(this,"_findModelsByUnitId",new Map)}async find(e){this._terminate();const t=this._univerInstanceService.getCurrentUnitOfType(UniverInstanceType.UNIVER_SHEET);if(!t)return[];const i=this._preprocessQuery(e),n=this._renderManagerService.getRenderById(t.getUnitId()).with(SheetSkeletonManagerService),r=this._injector.createInstance(SheetFindModel,t,n);return this._findModelsByUnitId.set(t.getUnitId(),r),r.start(i),[r]}terminate(){this._terminate()}_terminate(){this._findModelsByUnitId.forEach((e=>e.dispose())),this._findModelsByUnitId.clear()}_preprocessQuery(e){let t=e.caseSensitive?e.findString:e.findString.toLowerCase();return t=t.trim(),{...e,findString:t}}};SheetsFindReplaceProvider=__decorate([__decorateParam(0,IUniverInstanceService),__decorateParam(1,IRenderManagerService),__decorateParam(2,Inject(Injector))],SheetsFindReplaceProvider);const VALUE_PASSING_OBJECT={hit:!1,replaceable:!1,isFormula:!1,rawData:null};function hitCell(e,t,i,n,r){const{findBy:o}=n,s=o===FindBy.FORMULA,a=e.getCellRaw(t,i);return VALUE_PASSING_OBJECT.rawData=a,(null==a?void 0:a.f)?(VALUE_PASSING_OBJECT.isFormula=!0,s?matchCellData({v:a.f},n)?(VALUE_PASSING_OBJECT.hit=!0,VALUE_PASSING_OBJECT.replaceable=!0,VALUE_PASSING_OBJECT):(VALUE_PASSING_OBJECT.hit=!1,VALUE_PASSING_OBJECT.replaceable=!1,VALUE_PASSING_OBJECT):(VALUE_PASSING_OBJECT.replaceable=!1,matchCellData(r,n)?VALUE_PASSING_OBJECT.hit=!0:VALUE_PASSING_OBJECT.hit=!1,VALUE_PASSING_OBJECT)):(VALUE_PASSING_OBJECT.isFormula=!1,matchCellData(r,n)?a?(VALUE_PASSING_OBJECT.hit=!0,VALUE_PASSING_OBJECT.replaceable=!0):(VALUE_PASSING_OBJECT.hit=!0,VALUE_PASSING_OBJECT.replaceable=!1):(VALUE_PASSING_OBJECT.hit=!1,VALUE_PASSING_OBJECT.replaceable=!1),VALUE_PASSING_OBJECT)}function matchCellData(e,t){let i=extractPureValue(e);return!!i&&(t.matchesTheWholeCell?(i=trimLeadingTrailingWhitespace(i),t.caseSensitive?i===t.findString:i.toLowerCase()===t.findString):t.caseSensitive?i.indexOf(t.findString)>-1:i.toLowerCase().indexOf(t.findString)>-1)}function extractPureValue(e){var t,i;const n=null!==(t=null==e||null===(i=e.p)||void 0===i||null===(i=i.body)||void 0===i?void 0:i.dataStream)&&void 0!==t?t:null==e?void 0:e.v;return"number"==typeof n?`${n}`:"boolean"==typeof n?n?"1":"0":n}function trimLeadingTrailingWhitespace(e){return e.replace(/^ +/g,"").replace(/ +$/g,"")}var name="@univerjs/sheets-find-replace",version="0.21.0";const SHEETS_FIND_REPLACE_PLUGIN_CONFIG_KEY="sheets-find-replace.config",configSymbol=Symbol("sheets-find-replace.config"),defaultPluginConfig={};let UniverSheetsFindReplacePlugin=class extends Plugin{constructor(e=defaultPluginConfig,t,i){super(),this._config=e,this._injector=t,this._configService=i;const{...n}=merge({},defaultPluginConfig,this._config);this._configService.setConfig("sheets-find-replace.config",n)}onStarting(){[[SheetsFindReplaceController]].forEach((e=>this._injector.add(e)))}onSteady(){this._injector.get(SheetsFindReplaceController)}};_defineProperty(UniverSheetsFindReplacePlugin,"pluginName","SHEET_FIND_REPLACE_PLUGIN"),_defineProperty(UniverSheetsFindReplacePlugin,"packageName",name),_defineProperty(UniverSheetsFindReplacePlugin,"version",version),_defineProperty(UniverSheetsFindReplacePlugin,"type",UniverInstanceType.UNIVER_SHEET),UniverSheetsFindReplacePlugin=__decorate([DependentOn(UniverSheetsPlugin,UniverSheetsPlugin,UniverFindReplacePlugin),__decorateParam(1,Inject(Injector)),__decorateParam(2,IConfigService)],UniverSheetsFindReplacePlugin);export{SheetReplaceCommand,SheetsFindReplaceController,UniverSheetsFindReplacePlugin};
//# sourceMappingURL=/sm/19dbb51999469d55697bd7064f536fc77947b9a2b3dec118c50c5aa5153ca6bd.map