@univerjs/sheets-ui 0.5.4-nightly.202501131606 → 0.5.4-nightly.202501141606

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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var ld=Object.defineProperty;var cd=(n,r,e)=>r in n?ld(n,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[r]=e;var T=(n,r,e)=>cd(n,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("@univerjs/docs-ui"),a=require("@univerjs/core"),y=require("@univerjs/engine-render"),R=require("@univerjs/ui"),H=require("react"),O=require("rxjs"),m=require("@univerjs/sheets"),Ie=require("@univerjs/docs"),G=require("@univerjs/engine-formula"),dd=require("@univerjs/engine-numfmt"),K=require("@univerjs/design"),ud=require("@univerjs/telemetry"),La=require("rxjs/operators");function _r(n,r){if(n==null)return;const e=r.getRenderById(n);if(e==null)return;const{mainComponent:t,scene:i,engine:o,components:s}=e,l=t,c=s.get(J.DOCS_VIEW_KEY.BACKGROUND);return{document:l,docBackground:c,scene:i,engine:o}}function vn(n,r){const{startRow:e,startColumn:t,endRow:i,endColumn:o,rangeType:s}=r,l=i<e?i:e,c=i<e?e:i,d=o<t?o:t,u=o<t?t:o,h=n.getNoMergeCellPositionByIndex(l,d),g=n.getNoMergeCellPositionByIndex(c,u);return{startRow:e,startColumn:t,endRow:i,endColumn:o,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}function ye(n,r){const{range:e,primary:t,style:i}=n,o=vn(r,e),s=t&&qn(r,t);return{rangeWithCoord:o,primaryWithCoord:s,style:i}}function qn(n,r){const{actualRow:e,actualColumn:t,isMerged:i,isMergedMainCell:o,startRow:s,startColumn:l,endRow:c,endColumn:d}=r,u=n.getNoMergeCellPositionByIndex(e,t),h=n.getNoMergeCellPositionByIndex(s,l),g=n.getNoMergeCellPositionByIndex(c,d);return{actualRow:e,actualColumn:t,isMerged:i,isMergedMainCell:o,startX:u.startX,startY:u.startY,endX:u.endX,endY:u.endY,mergeInfo:{startRow:s,startColumn:l,endRow:c,endColumn:d,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}}var hd=Object.defineProperty,md=Object.getOwnPropertyDescriptor,gd=(n,r,e,t)=>{for(var i=t>1?void 0:t?md(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&hd(r,e,i),i},Sd=(n,r)=>(e,t)=>r(e,t,n);exports.SheetSkeletonManagerService=class extends a.Disposable{constructor(e,t){super();T(this,"_currentSkeletonSearchParam",{sheetId:""});T(this,"_sheetSkeletonParam",[]);T(this,"_currentSkeleton$",new O.BehaviorSubject(null));T(this,"currentSkeleton$",this._currentSkeleton$.asObservable());T(this,"_currentSkeletonBefore$",new O.BehaviorSubject(null));T(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._context=e,this._injector=t,this.disposeWithMe(()=>{this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParam=[]}),this._initRemoveSheet()}_initRemoveSheet(){this.disposeWithMe(this._context.unit.sheetDisposed$.subscribe(e=>{this.disposeSkeleton({sheetId:e.getSheetId()})}))}getCurrentSkeleton(){var e;return(e=this.getCurrent())==null?void 0:e.skeleton}getCurrent(){return this._getSkeleton(this._currentSkeletonSearchParam)}getWorksheetSkeleton(e){return this._getSkeleton({sheetId:e})}getUnitSkeleton(e,t){const i=this._getSkeleton({sheetId:t});return i!=null&&(i.unitId=e),i}setCurrent(e){this._setCurrent(e)}_setCurrent(e){const t=this._getSkeleton(e),i=this._context.unitId;if(t!=null)this._reCalculate(t);else{const{sheetId:l}=e,d=this._context.unit.getSheetBySheetId(e.sheetId);if(d==null)return;const u=this._buildSkeleton(d);this._sheetSkeletonParam.push({unitId:i,sheetId:l,skeleton:u,dirty:!1})}this._currentSkeletonSearchParam=e;const o=this._currentSkeletonSearchParam.sheetId,s=this.getUnitSkeleton(i,o);this._currentSkeletonBefore$.next(s),this._currentSkeleton$.next(s)}reCalculate(){const e=this.getCurrent();e!=null&&this._reCalculate(e)}_reCalculate(e){e.dirty&&(e.skeleton.makeDirty(!0),e.dirty=!1),e.skeleton.calculate()}makeDirty(e,t=!0){const i=this._getSkeleton(e);i!=null&&(i.dirty=t)}getOrCreateSkeleton(e){const t=this._getSkeleton(e);if(t)return t.skeleton;const o=this._context.unit.getSheetBySheetId(e.sheetId);if(!o)return;const s=this._buildSkeleton(o);return this._sheetSkeletonParam.push({unitId:this._context.unitId,sheetId:e.sheetId,skeleton:s,dirty:!1}),s}disposeSkeleton(e){const t=this._sheetSkeletonParam.findIndex(i=>i.sheetId===e.sheetId);t>-1&&(this._sheetSkeletonParam[t].skeleton.dispose(),this._sheetSkeletonParam.splice(t,1))}attachRangeWithCoord(e){const t=this.getCurrentSkeleton();return t?vn(t,e):null}_getSkeleton(e){const t=this._sheetSkeletonParam.find(i=>i.sheetId===e.sheetId);return t!=null&&(t.commandId=e.commandId),t}_buildSkeleton(e){return this._injector.createInstance(y.SpreadsheetSkeleton,e,this._context.unit.getStyles())}};exports.SheetSkeletonManagerService=gd([Sd(1,a.Inject(a.Injector))],exports.SheetSkeletonManagerService);function Je(){const n=a.useDependency(a.IUniverInstanceService),r=R.useObservable(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]);return r!=null?r:null}function fd(n){return R.useObservable(()=>{var e;return(e=n==null?void 0:n.activeSheet$)!=null?e:O.of(null)},void 0,void 0,[n])}function pd(){const n=a.useDependency(a.IUniverInstanceService);return R.useObservable(()=>O.merge([n.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET),n.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET)]).pipe(O.map(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET)),O.startWith(n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET))),[],void 0,[n])}function vd(){const n=a.useDependency(y.IRenderManagerService),r=Je(),{sheetSkeletonManagerService:e}=H.useMemo(()=>{if(r){const t=n.getRenderById(r.getUnitId());return{sheetSkeletonManagerService:t==null?void 0:t.with(exports.SheetSkeletonManagerService)}}return{sheetSkeletonManagerService:null}},[r,n]);return e}const Cd="SheetUI";var is=(n=>(n.FILTER_PANEL_EMBED_POINT="filter-panel-embed-point",n.SHEETS_FOOTER="sheets-footer",n.FORMULA_AUX="formula-aux",n))(is||{}),Id=Object.defineProperty,_d=Object.getOwnPropertyDescriptor,bd=(n,r,e,t)=>{for(var i=t>1?void 0:t?_d(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&Id(r,e,i),i},Ai=(n,r)=>(e,t)=>r(e,t,n);const rs=["ff","fs","tr","tb"];exports.AutoHeightController=class extends a.Disposable{constructor(r,e,t,i){super(),this._renderManagerService=r,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=i,this._initialize()}getUndoRedoParamsOfAutoHeight(r){const{_univerInstanceService:e}=this,t=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),i=t.getActiveSheet(),o=t.getUnitId(),s=i.getSheetId(),l=this._renderManagerService.getRenderById(o).with(exports.SheetSkeletonManagerService);if(!s||!l.getCurrent())return{redos:[],undos:[]};const{skeleton:c}=l.getCurrent(),d=c.calculateAutoHeightInRange(r),u={subUnitId:s,unitId:o,rowsAutoHeightInfo:d},h=m.SetWorksheetRowAutoHeightMutationFactory(u,i);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:h}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}]}}_initialize(){const{_sheetInterceptorService:r,_selectionManagerService:e}=this;this.disposeWithMe(r.interceptCommand({getMutations:t=>{if(t.id===m.SetRangeValuesCommand.id){const i=t.params;return this.getUndoRedoParamsOfAutoHeight(i.range)}return{redos:[],undos:[]}}})),this.disposeWithMe(r.interceptCommand({getMutations:t=>t.id!==m.SetWorksheetRowIsAutoHeightCommand.id?{redos:[],undos:[]}:this.getUndoRedoParamsOfAutoHeight(t.params.ranges)})),this.disposeWithMe(r.interceptCommand({getMutations:t=>{var o,s;if(t.id!==m.SetStyleCommand.id)return{redos:[],undos:[]};if(!rs.includes((o=t.params)==null?void 0:o.style.type))return{redos:[],undos:[]};const i=(s=e.getCurrentSelections())==null?void 0:s.map(l=>l.range);return i!=null&&i.length?this.getUndoRedoParamsOfAutoHeight(i):{redos:[],undos:[]}}})),this.disposeWithMe(r.interceptAfterCommand({getMutations:t=>{if(t.id===m.MoveRangeCommand.id){const i=t.params;return this.getUndoRedoParamsOfAutoHeight([i.fromRange,i.toRange])}if(t.id===m.ReorderRangeCommand.id){const i=t.params;return this.getUndoRedoParamsOfAutoHeight([i.range])}return{redos:[],undos:[]}}}))}};exports.AutoHeightController=bd([Ai(0,y.IRenderManagerService),Ai(1,a.Inject(m.SheetInterceptorService)),Ai(2,a.Inject(m.SheetsSelectionsService)),Ai(3,a.Inject(a.IUniverInstanceService))],exports.AutoHeightController);function un(n,r,e,t){const i=r.get(a.IUniverInstanceService),o=e?i.getUnit(e,a.UniverInstanceType.UNIVER_SHEET):i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=t?o==null?void 0:o.getSheetBySheetId(t):o==null?void 0:o.getActiveSheet();if(!s)return null;const{startRow:l,endRow:c,startColumn:d,endColumn:u}=n,h=[],g=[];for(let S=l;S<=c;S++)s.getRowFiltered(S)||h.push(S);for(let S=d;S<=u;S++)g.push(S);return{rows:h,cols:g}}function _t(n){const{rows:r,cols:e}=n;return{startRow:r[0],endRow:r[r.length-1],startColumn:e[0],endColumn:e[e.length-1]}}function Et(n){let r=[],e=[];const t=[];return n.forEach(i=>{r=r.concat(i.rows),e=e.concat(i.cols)}),r=Array.from(new Set(r)).sort((i,o)=>i-o),e=Array.from(new Set(e)).sort((i,o)=>i-o),n.forEach(i=>{t.push({startRow:r.findIndex(o=>o===i.rows[0]),endRow:r.findIndex(o=>o===i.rows[i.rows.length-1]),startColumn:e.findIndex(o=>o===i.cols[0]),endColumn:e.findIndex(o=>o===i.cols[i.cols.length-1])})}),{ranges:t,mapFunc:(i,o)=>({row:r[i],col:e[o]})}}function Rd(n){const r=new a.ObjectMatrix;return n.forEach(e=>{const{rows:t,cols:i}=e;t.forEach(o=>{i.forEach(s=>{r.setValue(o,s,{v:null,p:null,f:null,si:null,custom:null})})})}),r.getData()}const Po={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},Zi=["零","一","二","三","四","五","六","七","八","九"],Hs=["","万","亿","万亿","亿亿"],Ed=["","十","百","千"],Ba={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function dt(n){if(!n)return 0;let r=0,e=0,t=0,i=!1;const o=n.split("");for(let s=0;s<o.length;s++){const l=Po[o[s]];if(typeof l<"u")t=l,s===o.length-1&&(e+=t);else{const c=Ba[o[s]],d=c.value;i=c.secUnit,i?(e=(e+t)*d,r+=e,e=0):e+=t*d,t=0}}return r+e}function Td(n){let r="",e="",t=0,i=!0;for(;n>0;){const o=n%10;o===0?i||(i=!0,e=Zi[o]+e):(i=!1,r=Zi[o],r+=Ed[t],e=r+e),t++,n=Math.floor(n/10)}return e}function wd(n){let r=0,e="",t="",i=!1;if(n===0)return Zi[0];for(;n>0;){const o=n%1e4;i&&(t=Zi[0]+t),e=Td(o),e+=o!==0?Hs[r]:Hs[0],t=e+t,i=o<1e3&&o>0,n=Math.floor(n/1e4),r++}return t}function yd(n){if(!n)return!1;let r=!0;if(n)if(n.length===1)n==="日"||n in Po?r=!0:r=!1;else{const e=n.split("");for(let t=0;t<e.length;t++)if(!(e[t]in Po||e[t]in Ba)){r=!1;break}}return r}function Ni(n){if(!n)return{isExtendNumber:!1};const r=/0|([1-9]+[0-9]*)/g,e=r.test(n);if(e){const t=n.match(r);if(t&&t.length>0){const i=t[t.length-1],o=n.lastIndexOf(i),s=n.substr(0,o),l=n.substr(o+i.length);return{isExtendNumber:!0,matchTxt:Number(i),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:e}}function Md(n){let r;return n.length===2&&(n==="周一"||n==="周二"||n==="周三"||n==="周四"||n==="周五"||n==="周六"||n==="周日")?r=!0:r=!1,r}function Pd(n){let r;return n.length===3&&(n==="星期一"||n==="星期二"||n==="星期三"||n==="星期四"||n==="星期五"||n==="星期六"||n==="星期日")?r=!0:r=!1,r}function Od(n,r){let e=0;for(let t=0;t<n.length&&n[t]<r;t++)e++;return e}function ai(n){let r=!0;const e=n[1]-n[0];for(let t=1;t<n.length;t++)if(n[t]-n[t-1]!==e){r=!1;break}return r}function xd(n,r,e){const t=[],i=Math.floor(r/n),o=r%n;let s=0;if(i>0){for(let l=0;l<i;l++)for(let c=0;c<e.length;c++)t[e[c]+l*n]=s,s++;for(let l=0;l<e.length&&e[l]<o;l++)t[e[l]+n*i]=s,s++}else for(let l=0;l<e.length&&e[l]<o;l++)t[e[l]]=s,s++;return t}function Bt(n,r){const e=[];for(let t=1;t<=r;t++){const i=(t-1)%n.length,o=a.Tools.deepClone(n[i]);e.push({v:null,s:null,p:null,f:null,si:null,t:null,...o})}return e}function Ad(n,r){var t;const e=[];for(let i=1;i<=r;i++){const o=(i-1)%n.length,s={s:(t=n[o])==null?void 0:t.s};e.push(s)}return e}function Nd(n){let r=!0;const e=n[1]/n[0];for(let t=1;t<n.length;t++)if(n[t]/n[t-1]!==e){r=!1;break}return r}function Dd(n){const r=[];for(let e=1;e<=n;e++)r.push(e);return r}function Ki(n,r,e){var o,s,l,c;const t=[],i=[];for(let d=0;d<n.length;d++)i.push(Number((o=n[d])==null?void 0:o.v));if(n.length>2&&Nd(i))for(let d=1;d<=r;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]),g=Number((s=n[n.length-1])==null?void 0:s.v)*(Number((l=n[1])==null?void 0:l.v)/Number((c=n[0])==null?void 0:c.v))**d;h&&(Bs(h)&&(h.v=g),t.push(h))}else{const d=Dd(n.length);for(let u=1;u<=r;u++){const h=(u-1)%n.length,g=a.Tools.deepClone(n[h]),S=e===a.Direction.DOWN||e===a.Direction.RIGHT,f=kd(n.length+u,i,d,S);g&&(Bs(g)&&(g.v=f),t.push(g))}}return t}function kd(n,r,e,t=!0){function i(h){let g=0;for(let S=0;S<h.length;S++)g+=h[S];return g/h.length}const o=i(e),s=i(r);let l=0,c=0;for(let h=0;h<e.length;h++)l+=(e[h]-o)*(r[h]-s),c+=(e[h]-o)*(e[h]-o);let d;c===0?d=t?1:-1:d=l/c;const u=s-d*o;return Math.round((u+d*n)*1e5)/1e5}function Ws(n,r,e){var o;const t=[],i=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=r;s++){const l=(s-1)%n.length,c=a.Tools.deepClone(n[l]),d=`${(o=n[n.length-1])==null?void 0:o.v}`,u=d==null?void 0:d.match(i),h=u==null?void 0:u[u.length-1],g=Math.abs(Number(h)+e*s);if(!d||!h)continue;const S=d.lastIndexOf(h),f=d.substr(0,S)+g.toString()+d.substr(S+h.length);c&&(c.v=f,t.push(c))}return t}function Cn(n,r,e,t=0){var l,c;const i=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=i.length)return[];const o=i[t],s=[];for(let d=1;d<=r;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);let g=0;if(((l=n[n.length-1])==null?void 0:l.v)===o[0])g=7+e*d;else{const f=`${(c=n[n.length-1])==null?void 0:c.v}`;if(f){const p=f.substr(f.length-1,1);g=dt(p)+e*d}}g<0&&(g=Math.ceil(Math.abs(g)/7)*7+g);const S=g%7;h&&(h.v=o[S],s.push(h))}return s}function Us(n,r,e){var i;const t=[];for(let o=1;o<=r;o++){const s=(o-1)%n.length,l=a.Tools.deepClone(n[s]),c=`${(i=n[n.length-1])==null?void 0:i.v}`,d=dt(c)+e*o;let u;d<=0?u="零":u=wd(d),l&&(l.v=u,t.push(l))}return t}const Gn={enWeek1:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],enWeek2:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],enMonth1:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],enMonth2:["January","February","March","April","May","June","July","August","September","October","November","December"],chnMonth1:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],chnMonth2:["正月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","腊月"],chHour1:["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"],chHour2:["子时","丑时","寅时","卯时","辰时","巳时","午时","未时","申时","酉时","戌时","亥时"],chYear1:["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"],chSeason1:["春","夏","秋","冬"],chSeason2:["春季","夏季","秋季","冬季"]};function Vd(n){let r=!1;return Object.keys(Gn).forEach(e=>{Gn[e].includes(n)&&(r=!0)}),r}function Wr(n){let r="";const e=[];return Object.keys(Gn).forEach(t=>{Gn[t].includes(n)&&(r=t,e.push(...Gn[t]))}),{name:r,series:e}}function Ls(n,r,e,t){var s;const i=t.length,o=[];for(let l=1;l<=r;l++){const c=(l-1)%n.length,d=a.Tools.deepClone(n[c]),u=`${(s=n[n.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+e*l;h<0&&(h+=Math.abs(e)*i);const g=h%i;d&&(d.v=t[g],o.push(d))}return o}function Hd(n,r){const e=[];let t;if(r.startRow<n.startRow)t=a.Direction.UP;else if(r.endRow>n.endRow)t=a.Direction.DOWN;else if(r.startColumn<n.startColumn)t=a.Direction.LEFT;else if(r.endColumn>n.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const i=n.endRow-n.startRow+1,o=r.endRow-r.startRow+1,s=Math.floor(o/i),l=o%i,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.DOWN){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow+(d+1)*i,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow+(s+1)*i,col:n.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:n.endColumn-n.startColumn}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow-(d+1)*i,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow-(s+1)*i,col:n.startColumn},relativeRange:{startRow:i-l,endRow:i-1,startColumn:0,endColumn:n.endColumn-n.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const i=n.endColumn-n.startColumn+1,o=r.endColumn-r.startColumn+1,s=Math.floor(o/i),l=o%i,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.RIGHT){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(d+1)*i},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(s+1)*i},relativeRange:{startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:l-1}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(d+1)*i},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(s+1)*i},relativeRange:{startRow:0,startColumn:i-l,endRow:n.endRow-n.startRow,endColumn:i-1}})}}return e}function Bs(n){return!(a.isFormulaString(n.f)||a.isFormulaId(n.si)||n.t===a.CellValueType.BOOLEAN)}var cn=(n=>(n.Append="APPEND",n.Default="DEFAULT",n.Only="ONLY",n))(cn||{}),ve=(n=>(n.NUMBER="number",n.DATE="date",n.EXTEND_NUMBER="extendNumber",n.CHN_NUMBER="chnNumber",n.CHN_WEEK2="chnWeek2",n.CHN_WEEK3="chnWeek3",n.LOOP_SERIES="loopSeries",n.FORMULA="formula",n.OTHER="other",n))(ve||{}),se=(n=>(n.COPY="COPY",n.SERIES="SERIES",n.ONLY_FORMAT="ONLY_FORMAT",n.NO_FORMAT="NO_FORMAT",n))(se||{});const Wd={type:ve.DATE,priority:1100,match:(n,r)=>{var e;if(n!=null&&n.f||n!=null&&n.si)return!1;if((typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER)&&n.s){if(typeof n.s=="string"){const i=r.get(a.IUniverInstanceService).getFocusedUnit().getStyles().get(n.s),o=(e=i==null?void 0:i.n)==null?void 0:e.pattern;if(o)return a.numfmt.getInfo(o).isDate}else if(n.s.n&&a.numfmt.getInfo(n.s.n.pattern).isDate)return!0}return!1},isContinue:(n,r)=>n.type===ve.DATE,applyFunctions:{[se.SERIES]:(n,r,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),Ki(t,r,e).reverse()):Ki(t,r,e)}}},Ud={type:ve.NUMBER,priority:1e3,match:n=>typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER,isContinue:(n,r)=>n.type===ve.NUMBER,applyFunctions:{[se.SERIES]:(n,r,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),Ki(t,r,e).reverse()):Ki(t,r,e)}}},Fa={type:ve.OTHER,priority:0,match:()=>!0,isContinue:(n,r)=>n.type===ve.OTHER},Ld={type:ve.EXTEND_NUMBER,priority:900,match:n=>Ni(`${n==null?void 0:n.v}`||"").isExtendNumber,isContinue:(n,r)=>{var e;if(n.type===ve.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:i}=Ni(`${(e=n.cellData)==null?void 0:e.v}`||""),{beforeTxt:o,afterTxt:s}=Ni(`${r==null?void 0:r.v}`||"");if(t===o&&i===s)return!0}return!1},applyFunctions:{[se.SERIES]:(n,r,e)=>{var l;const{data:t}=n,i=e===a.Direction.UP||e===a.Direction.LEFT;let o;if(t.length===1)return o=i?-1:1,Ue(Ws(t,r,o),i);const s=[];for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;d&&s.push(Number(Ni(d).matchTxt))}return i&&(t.reverse(),s.reverse()),ai(s)?(o=s[1]-s[0],Ue(Ws(t,r,o),i)):Bt(t,r)}}},Bd={type:ve.CHN_NUMBER,priority:830,match:n=>!!yd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>n.type===ve.CHN_NUMBER,applyFunctions:{[se.SERIES]:(n,r,e)=>{var c,d,u;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){const h=`${(c=t[0])==null?void 0:c.v}`;let g;return i?g=-1:g=1,h&&(h==="日"||dt(h)<7)?Ue(Cn(t,r,g),i):Ue(Us(t,r,g),i)}let o=!1;for(let h=0;h<t.length;h++)if(((d=t[h])==null?void 0:d.v)==="日"){o=!0;break}const s=[];let l=0;for(let h=0;h<t.length;h++){const g=`${(u=t[h])==null?void 0:u.v}`;g==="日"?h===0?s.push(0):(l++,s.push(l*7)):o&&dt(g)>0&&dt(g)<7?s.push(dt(g)+l*7):s.push(dt(g))}if(i&&(t.reverse(),s.reverse()),ai(s)){if(o||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const g=s[1]-s[0];return Ue(Cn(t,r,g),i)}const h=s[1]-s[0];return Ue(Us(t,r,h),i)}return Bt(t,r)}}},Fd={type:ve.CHN_WEEK2,priority:820,match:n=>!!Md(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>n.type===ve.CHN_WEEK2,applyFunctions:{[se.SERIES]:(n,r,e)=>{var l;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return i?c=-1:c=1,Ue(Cn(t,r,c,1),i)}const o=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`,u=d==null?void 0:d.substr(d.length-1,1);d==="周日"?c===0?o.push(0):(s++,o.push(s*7)):o.push(dt(u)+s*7)}if(i&&(t.reverse(),o.reverse()),ai(o)){const c=o[1]-o[0];return Ue(Cn(t,r,c,1),i)}return Bt(t,r)}}},jd={type:ve.CHN_WEEK3,priority:810,match:n=>Pd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>n.type===ve.CHN_WEEK3,applyFunctions:{[se.SERIES]:(n,r,e)=>{var l;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return i?c=-1:c=1,Ue(Cn(t,r,c,2),i)}const o=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;if(d){const u=d.substr(d.length-1,1);d==="星期日"?c===0?o.push(0):(s++,o.push(s*7)):o.push(dt(u)+s*7)}}if(i&&(t.reverse(),o.reverse()),ai(o)){const c=o[1]-o[0];return Ue(Cn(t,r,c,2),i)}return Bt(t,r)}}},zd={type:ve.LOOP_SERIES,priority:800,match:n=>Vd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>{var e;return n.type===ve.LOOP_SERIES?Wr(`${(e=n.cellData)==null?void 0:e.v}`||"").name===Wr(`${r==null?void 0:r.v}`||"").name:!1},applyFunctions:{[se.SERIES]:(n,r,e)=>{var c,d;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP,{series:o}=Wr(`${(c=t[0])==null?void 0:c.v}`||"");if(t.length===1){let u;return i?u=-1:u=1,Ue(Ls(t,r,u,o),i)}const s=[];let l=0;for(let u=0;u<t.length;u++){const h=`${(d=t[u])==null?void 0:d.v}`;h&&(h===o[0]?u===0?s.push(0):(l++,s.push(l*o.length)):s.push(o.indexOf(h)+l*7))}if(i&&(t.reverse(),s.reverse()),ai(s)){const u=s[1]-s[0];return Ue(Ls(t,r,u,o),i)}return Bt(t,r)}}};function Ue(n,r){return r?n.reverse():n}var Xd=Object.defineProperty,Yd=Object.getOwnPropertyDescriptor,Gd=(n,r,e,t)=>{for(var i=t>1?void 0:t?Yd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&Xd(r,e,i),i},$t=(n,r)=>(e,t)=>r(e,t,n);exports.AutoFillService=class extends a.Disposable{constructor(e,t,i,o,s,l){super();T(this,"_rules",[]);T(this,"_hooks",[]);T(this,"_applyType$",new O.BehaviorSubject(se.SERIES));T(this,"_isFillingStyle",!0);T(this,"_prevUndos",[]);T(this,"_autoFillLocation$",new O.BehaviorSubject(null));T(this,"autoFillLocation$",this._autoFillLocation$.asObservable());T(this,"_showMenu$",new O.BehaviorSubject(!1));T(this,"showMenu$",this._showMenu$.asObservable());T(this,"_direction",a.Direction.DOWN);T(this,"applyType$",this._applyType$.asObservable());T(this,"_menu$",new O.BehaviorSubject([{label:"autoFill.copy",value:se.COPY,disable:!1},{label:"autoFill.series",value:se.SERIES,disable:!1},{label:"autoFill.formatOnly",value:se.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:se.NO_FORMAT,disable:!1}]));T(this,"menu$",this._menu$.asObservable());this._commandService=e,this._undoRedoService=t,this._renderManagerService=i,this._univerInstanceService=o,this._selectionManagerService=s,this._injector=l,this._init()}_init(){this._rules=[Wd,Ud,Ld,Bd,Fd,jd,zd,Fa].sort((e,t)=>t.priority-e.priority),this._isFillingStyle=!0}_getOneByPriority(e){return e.length<=0?[]:[e.reduce((i,o)=>(o.priority||0)>(i.priority||0)?o:i,e[0])]}_initPrevUndo(){this._prevUndos=[]}async triggerAutoFill(e,t,i,o){var S;if(i.startColumn===o.startColumn&&i.startRow===o.startRow&&i.endColumn===o.endColumn&&i.endRow===o.endRow)return!1;if(o.endColumn<i.endColumn&&o.endColumn>i.startColumn)return this._commandService.executeCommand(In.id,{clearRange:{startRow:o.startRow,endRow:o.endRow,startColumn:o.endColumn+1,endColumn:i.endColumn},selectionRange:o});if(o.endRow<i.endRow&&o.endRow>i.startRow)return this._commandService.executeCommand(In.id,{clearRange:{startRow:o.endRow+1,endRow:i.endRow,startColumn:o.startColumn,endColumn:o.endColumn},selectionRange:o});const s={startRow:o.startRow,endRow:o.endRow,startColumn:o.startColumn,endColumn:o.endColumn};let l=null;if(o.startRow<i.startRow)l=a.Direction.UP,s.endRow=i.startRow-1;else if(o.endRow>i.endRow)l=a.Direction.DOWN,s.startRow=i.endRow+1;else if(o.startColumn<i.startColumn)l=a.Direction.LEFT,s.endColumn=i.startColumn-1;else if(o.endColumn>i.endColumn)l=a.Direction.RIGHT,s.startColumn=i.endColumn+1;else return!1;this.direction=l;const c=this._injector.invoke(f=>un(i,f)),d=this._injector.invoke(f=>un(s,f));if(!c||!d)return!1;this.autoFillLocation={source:c,target:d,unitId:e,subUnitId:t};const u=[];this.getActiveHooks().forEach(f=>{var v;const p=(v=f==null?void 0:f.onBeforeFillData)==null?void 0:v.call(f,{source:c,target:d,unitId:e,subUnitId:t},l);p&&u.unshift(p)}),this._initPrevUndo();for(let f=0;f<u.length;f++){const p=this.menu.find(v=>v.value===u[f]);if(p&&!p.disable)return this.fillData(u[f])}const g=(S=this.menu.find(f=>f.disable===!1))==null?void 0:S.value;return g?this.fillData(g):!1}addHook(e){if(this._hooks.find(t=>t.id===e.id))throw new Error(`Add hook failed, hook id '${e.id}' already exist!`);return e.priority===void 0&&(e.priority=0),e.type===void 0&&(e.type=cn.Append),this._hooks.push(e),a.toDisposable(()=>{const t=this._hooks.findIndex(i=>i===e);t>-1&&this._hooks.splice(t,1)})}registerRule(e){if(this._rules.find(i=>i.type===e.type))throw new Error(`Registry rule failed, type '${e.type}' already exist!`);const t=this._rules.findIndex(i=>i.priority<e.priority);this._rules.splice(t===-1?this._rules.length:t,0,e)}getRules(){return this._rules}getAllHooks(){return this._hooks}getActiveHooks(){const{source:e,target:t,unitId:i,subUnitId:o}=this.autoFillLocation||{};if(!e||!t||!i||!o)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:e,target:t,unitId:i,subUnitId:o},this._direction,this.applyType))}),l=s.filter(u=>u.type===cn.Only);if(l.length>0)return this._getOneByPriority(l);const c=this._getOneByPriority(s.filter(u=>u.type===cn.Default)),d=s.filter(u=>u.type===cn.Append)||[];return[...c,...d]}get applyType(){return this._applyType$.getValue()}set applyType(e){this._applyType$.next(e)}get menu(){return this._menu$.getValue()}get direction(){return this._direction}set direction(e){this._direction=e}isFillingStyle(){return this._isFillingStyle}setFillingStyle(e){this._isFillingStyle=e}get autoFillLocation(){return this._autoFillLocation$.getValue()}set autoFillLocation(e){this._autoFillLocation$.next(e)}setDisableApplyType(e,t){this._menu$.next(this._menu$.getValue().map(i=>i.value===e?{...i,disable:t}:i))}setShowMenu(e){this._showMenu$.next(e)}fillData(e){var C,_,b;this.applyType=e;const{source:t,target:i,unitId:o=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),subUnitId:s=(C=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:C.getSheetId()}=this.autoFillLocation||{};if(!t||!i||!o||!s)return!1;const l=this.direction;this._prevUndos.length>0&&this._prevUndos.forEach(E=>{this._commandService.syncExecuteCommand(E.id,E.params)}),this._prevUndos=[];const c=a.Rectangle.union(_t(t),_t(i)),d=this.getActiveHooks(),u=this._univerInstanceService.getUnit(o,a.UniverInstanceType.UNIVER_SHEET);this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{selections:[{primary:{...(b=(_=this._selectionManagerService.getCurrentLastSelection())==null?void 0:_.primary)!=null?b:c},range:{...c,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:o,subUnitId:s});const h=[],g=[];d.forEach(E=>{var P;const{undos:M,redos:w}=((P=E.onFillData)==null?void 0:P.call(E,{source:t,target:i,unitId:o,subUnitId:s},l,e))||{};M&&h.push(...M),w&&g.push(...w)});const S=g.every(E=>this._commandService.syncExecuteCommand(E.id,E.params)),f=[];e!==se.NO_FORMAT&&g.forEach(E=>{if(E.id===m.SetRangeValuesMutation.id){const{cellValue:M}=E.params;new a.ObjectMatrix(M).forValue((P,x,A)=>{const N=Object.keys(u.getStyles().get(A==null?void 0:A.s)||{});(A!=null&&A.p||N.length&&rs.some(D=>N.includes(D)))&&f.push({startRow:P,endRow:P,startColumn:x,endColumn:x})})}});const p=this._getAutoHeightUndoRedos(o,s,f);return p.redos.every(E=>this._commandService.syncExecuteCommand(E.id,E.params))&&(h.push(...p.undos),g.push(...p.redos)),S&&(this._prevUndos=h,this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:h,redoMutations:g})),d.forEach(E=>{var M;(M=E.onAfterFillData)==null||M.call(E,{source:t,target:i,unitId:o,subUnitId:s},l,e)}),this.setShowMenu(!0),!0}_getAutoHeightUndoRedos(e,t,i){var h,g;const o=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(exports.SheetSkeletonManagerService),s=(g=o==null?void 0:o.getCurrent())==null?void 0:g.skeleton;if(!s)return{redos:[],undos:[]};const l=s.calculateAutoHeightInRange(i),c={subUnitId:t,unitId:e,rowsAutoHeightInfo:l},d=s.worksheet,u=m.SetWorksheetRowAutoHeightMutationFactory(c,d);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:c}]}}};exports.AutoFillService=Gd([$t(0,a.ICommandService),$t(1,a.IUndoRedoService),$t(2,y.IRenderManagerService),$t(3,a.Inject(a.IUniverInstanceService)),$t(4,a.Inject(m.SheetsSelectionsService)),$t(5,a.Inject(a.Injector))],exports.AutoFillService);const Tt=a.createIdentifier("univer.auto-fill-service"),Ct={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(n,r)=>{const e=n.get(Tt),t=n.get(a.IUniverInstanceService),{sourceRange:i,targetRange:o}=r,s=m.getSheetCommandTarget(t);if(!s)return!1;const{subUnitId:l,unitId:c}=s;return e.triggerAutoFill(c,l,i,o)}},In={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(n,r)=>{const e=n.get(a.IUniverInstanceService),t=n.get(a.ICommandService),i=n.get(a.IUndoRedoService),o=n.get(m.SheetInterceptorService),s=m.getSheetCommandTarget(e);if(!s)return!1;const{unitId:l,subUnitId:c}=s,{clearRange:d,selectionRange:u}=r,h={subUnitId:c,unitId:l,cellValue:m.generateNullCellValue([d])},g=m.SetRangeValuesUndoMutationFactory(n,h),{startColumn:S,startRow:f}=u,p={selections:[{primary:{startColumn:S,startRow:f,endColumn:S,endRow:f,actualRow:f,actualColumn:S,isMerged:!1,isMergedMainCell:!1},range:{...u}}],unitId:l,subUnitId:c};if(t.executeCommand(m.SetSelectionsOperation.id,p),t.syncExecuteCommand(m.SetRangeValuesMutation.id,h)){const C=o.afterCommandExecute({id:m.SetRangeValuesMutation.id,params:h});return a.sequenceExecute(C.redos,t),i.pushUndoRedo({unitID:l,undoMutations:[{id:m.SetRangeValuesMutation.id,params:g},...C.undos],redoMutations:[{id:m.SetRangeValuesMutation.id,params:h},...C.redos]}),!0}return!1}},li={id:"sheet.command.refill",type:a.CommandType.COMMAND,handler:async(n,r)=>n.get(Tt).fillData(r.type)},Oo=[10,400],os="RANGE_SELECTOR_COMPONENT_KEY",br="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var me=(n=>(n.MAIN="__SpreadsheetRender__",n.ROW="__SpreadsheetRowHeader__",n.COLUMN="__SpreadsheetColumnHeader__",n.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",n))(me||{});const Fs=0,qi=1,bt=10,Zd=11,js=12,xo=a.createInterceptorKey("rangeMovePermissionCheck"),Ao=a.createInterceptorKey("rangeFillPermissionCheck");var ss=(n=>(n[n.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",n[n.MARK_SELECTION=1e4]="MARK_SELECTION",n))(ss||{});function Rt(n){const r=n.getCurrentTheme(),e=new a.ColorKit(r.primaryColor).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:r.primaryColor,fill:e,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:r.colorWhite,autofillSize:6,autofillStrokeWidth:1,autofillStroke:r.colorWhite,rowHeaderFill:e,rowHeaderStroke:r.primaryColor,rowHeaderStrokeWidth:1,columnHeaderFill:e,columnHeaderStroke:r.primaryColor,columnHeaderStrokeWidth:1,expandCornerSize:40}}class Kd{constructor(){T(this,"_startColumn",-1);T(this,"_startRow",-1);T(this,"_endColumn",-1);T(this,"_endRow",-1);T(this,"_startX",0);T(this,"_startY",0);T(this,"_endX",0);T(this,"_endY",0);T(this,"_primary");T(this,"_rangeType",a.RANGE_TYPE.NORMAL)}get startColumn(){return this._startColumn}get startRow(){return this._startRow}get endColumn(){return this._endColumn}get endRow(){return this._endRow}get startX(){return this._startX}get startY(){return this._startY}get endX(){return this._endX}get endY(){return this._endY}get currentCell(){return this._primary}get rangeType(){return this._rangeType}isEqual(r){const{startColumn:e,startRow:t,endColumn:i,endRow:o}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=r;return e===s&&t===l&&i===c&&o===d}isInclude(r){const{startColumn:e,startRow:t,endColumn:i,endRow:o}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=r;return!(c<e||s>i||l>o||d<t)}highlightToSelection(){if(this._primary)return a.convertCellToRange(this._primary)}getRange(){return{startColumn:this._startColumn,startRow:this._startRow,endColumn:this._endColumn,endRow:this._endRow,startX:this._startX,startY:this._startY,endX:this._endX,endY:this._endY,rangeType:this.rangeType}}getCell(){return this._primary}getRangeType(){return this._rangeType}setRangeType(r){this._rangeType=r}getValue(){return{rangeWithCoord:this.getRange(),primaryWithCoord:this._primary}}setValue(r,e){const{startColumn:t,startRow:i,endColumn:o,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=r;this._startColumn=t,this._startRow=i,this._endColumn=o,this._endRow=s,this._startX=l,this._startY=c,this._endX=d,this._endY=u,h!==void 0&&(this._rangeType=h),e!==void 0&&this.setCurrentCell(e)}setCurrentCell(r){this._primary=r}clearCurrentCell(){this._primary=null}}const zs="__SpreadsheetHelperSelectionTempRect",qd=35;class ja{constructor(r,e){T(this,"_startOffsetX",0);T(this,"_startOffsetY",0);T(this,"_relativeSelectionPositionRow",0);T(this,"_relativeSelectionPositionColumn",0);T(this,"_relativeSelectionRowLength",0);T(this,"_relativeSelectionColumnLength",0);T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_helperSelection");T(this,"_scrollTimer");T(this,"_activeViewport");T(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});T(this,"_isInMergeState",!1);T(this,"_fillControlColors",[]);T(this,"_skeleton");T(this,"_scene");T(this,"_themeService");T(this,"_injector");T(this,"_selectionHooks");this._control=r,this._skeleton=e.skeleton,this._scene=e.scene,this._themeService=e.themeService,this._injector=e.injector,this._selectionHooks=e.selectionHooks,this._initialControl(),this._initialWidget(),this._initialAutoFill(),this._control.dispose$.subscribe(()=>{this.dispose()})}get isHelperSelection(){return this._control.isHelperSelection}dispose(){var r,e;(r=this._scrollTimer)==null||r.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(e=this._helperSelection)==null||e.dispose()}_getFreeze(){var t,i;return(i=(t=this._injector.get(y.IRenderManagerService).withCurrentTypeOfUnit(a.UniverInstanceType.UNIVER_SHEET,exports.SheetSkeletonManagerService))==null?void 0:t.getCurrent())==null?void 0:i.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(r,e){const t=this._getFreeze()||{startRow:-1,startColumn:-1,xSplit:0,ySplit:0};switch(e.viewportKey){case y.SHEET_VIEWPORT_KEY.VIEW_MAIN:return r.endRow>=t.startRow&&r.endColumn>=t.startColumn;case y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return r.endColumn>=t.startColumn&&r.startRow<t.startRow;case y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case y.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return r.endRow>=t.startRow&&r.startColumn<t.startColumn;case y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP:case y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT:case y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP:case y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP:return r.startRow<t.startRow&&r.startColumn<t.startColumn}}_clearObserverEvent(){var r,e;(r=this._scenePointerMoveSub)==null||r.unsubscribe(),(e=this._scenePointerUpSub)==null||e.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}_initialControl(){const{leftControl:r,rightControl:e,topControl:t,bottomControl:i}=this._control;[r,e,t,i].forEach(o=>{o.onPointerEnter$.subscribeEvent(()=>{var l;((l=this._injector.get(_e,a.Quantity.OPTIONAL))==null?void 0:l.interceptor.fetchThroughInterceptors(xo)(!1,null))!==!1&&o.setCursor(y.CURSOR_TYPE.MOVE)}),o.onPointerLeave$.subscribeEvent(()=>{o.resetCursor()}),o.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(r,e){var A;const t=this._scene,i=t.getScrollXYInfoByViewport(y.Vector2.FromArray([r,e])),{scaleX:o,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(r,e,o,s,i),{row:c,column:d}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let g=Math.max(0,c+this._relativeSelectionPositionRow),S=g+this._relativeSelectionRowLength;S>u&&(S=u,S-g<this._relativeSelectionRowLength&&(g=S-this._relativeSelectionRowLength));let f=Math.max(0,d+this._relativeSelectionPositionColumn),p=f+this._relativeSelectionColumnLength;p>h&&(p=h,p-f<this._relativeSelectionColumnLength&&(f=p-this._relativeSelectionColumnLength));const v=this._skeleton.worksheet.getCellInfoInMergeData(g,f),_=ye({range:{startRow:g,endRow:S,startColumn:f,endColumn:p},primary:v,style:null},this._skeleton),b=this._skeleton.getNoMergeCellPositionByIndex(g,f),E=this._skeleton.getNoMergeCellPositionByIndex(S,p),M=(b==null?void 0:b.startY)||0,w=(E==null?void 0:E.endY)||0,P=(b==null?void 0:b.startX)||0,x=(E==null?void 0:E.endX)||0;(A=this._helperSelection)==null||A.transformByState({left:P,top:M,width:x-P,height:w-M}),this._targetSelection={..._.rangeWithCoord},this._control.selectionMoving$.next(_.rangeWithCoord)}_controlPointerDownHandler(r){const{offsetX:e,offsetY:t}=r,i=this._scene,o=i.getCoordRelativeToViewport(y.Vector2.FromArray([e,t])),{x:s,y:l}=o,c=i.getScrollXYInfoByViewport(o),{scaleX:d,scaleY:u}=i.getAncestorScale(),h=this._skeleton.getCellIndexByOffset(s,l,d,u,c);this._startOffsetX=s,this._startOffsetY=l;const{row:g,column:S}=h,{startRow:f,startColumn:p,endRow:v,endColumn:C}=this._control.model;let _=0,b=0;g<f?_-=1:g>v&&(_+=1),S<p?b-=1:S>C&&(b+=1),this._relativeSelectionPositionRow=f-g+_,this._relativeSelectionPositionColumn=p-S+b,this._relativeSelectionRowLength=v-f,this._relativeSelectionColumnLength=C-p;const E=this._control.currentStyle,M=this._getScale();this.isHelperSelection&&(this._helperSelection=new y.Rect(zs,{stroke:E.stroke,strokeWidth:E.strokeWidth/M}),i.addObject(this._helperSelection));const w=i.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),P=y.ScrollTimer.create(i);this._scrollTimer=P,P.startScroll(s,l,w),i.disableObjectsEvent(),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(x=>{var V;const{offsetX:A,offsetY:N}=x;if(((V=this._injector.get(_e,a.Quantity.OPTIONAL))==null?void 0:V.interceptor.fetchThroughInterceptors(xo)(!1,null))===!1)return;const{x:k,y:B}=i.getCoordRelativeToViewport(y.Vector2.FromArray([A,N]));this._controlMoving(k,B),i.setCursor(y.CURSOR_TYPE.MOVE),P.scrolling(k,B,()=>{this._controlMoving(k,B)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var A,N,D,k;(A=this._helperSelection)==null||A.dispose();const x=this._scene;x.resetCursor(),this._clearObserverEvent(),x.enableObjectsEvent(),(N=this._scrollTimer)==null||N.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(k=(D=this._selectionHooks).selectionMoveEnd)==null||k.call(D)})}_initialWidget(){const{topLeftWidget:r,topCenterWidget:e,topRightWidget:t,middleLeftWidget:i,middleRightWidget:o,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:c}=this._control,d=[y.CURSOR_TYPE.NORTH_WEST_RESIZE,y.CURSOR_TYPE.NORTH_RESIZE,y.CURSOR_TYPE.NORTH_EAST_RESIZE,y.CURSOR_TYPE.WEST_RESIZE,y.CURSOR_TYPE.EAST_RESIZE,y.CURSOR_TYPE.SOUTH_WEST_RESIZE,y.CURSOR_TYPE.SOUTH_RESIZE,y.CURSOR_TYPE.SOUTH_EAST_RESIZE];[r,e,t,i,o,s,l,c].forEach((u,h)=>{u.onPointerEnter$.subscribeEvent(()=>{u.setCursor(d[h])}),u.onPointerLeave$.subscribeEvent(()=>{u.resetCursor()}),u.onPointerDown$.subscribeEvent(g=>{this._widgetPointerDownEvent(g,d[h])})})}_widgetPointerDownEvent(r,e){const t=this._scene,{offsetX:i,offsetY:o}=r,s=t.getCoordRelativeToViewport(y.Vector2.FromArray([i,o])),{x:l,y:c}=s;this._startOffsetX=i,this._startOffsetY=o;const{startRow:d,startColumn:u,endRow:h,endColumn:g}=this._control.model,S=Math.min(d,h),f=Math.min(u,g),p=Math.max(d,h),v=Math.max(u,g);this._relativeSelectionPositionRow=S,this._relativeSelectionPositionColumn=f,this._relativeSelectionRowLength=p-S,this._relativeSelectionColumnLength=v-f,e===y.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=p,this._relativeSelectionPositionColumn=v):e===y.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=p:e===y.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=p:e===y.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===y.CURSOR_TYPE.SOUTH_WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===y.CURSOR_TYPE.SOUTH_RESIZE&&(this._relativeSelectionPositionRow=S);const C=y.ScrollTimer.create(t),_=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);C.startScroll(l,c,_),this._scrollTimer=C,t.disableObjectsEvent(),this._scenePointerMoveSub=t.onPointerMove$.subscribeEvent(b=>{const{offsetX:E,offsetY:M}=b,{x:w,y:P}=t.getCoordRelativeToViewport(y.Vector2.FromArray([E,M]));this._widgetMoving(w,P,e),t.setCursor(e),C.scrolling(w,P,()=>{this._widgetMoving(w,P,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var E,M,w;const b=this._scene;b.resetCursor(),this._clearObserverEvent(),b.enableObjectsEvent(),(E=this._scrollTimer)==null||E.dispose(),this._control.selectionScaled$.next(this._targetSelection),(w=(M=this._selectionHooks).selectionMoveEnd)==null||w.call(M)})}_widgetMoving(r,e,t){const i=this._scene,o=i.getScrollXYInfoByViewport(y.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=i.getAncestorScale(),c=this._skeleton.getCellIndexByOffset(r,e,s,l,o),{row:d,column:u}=c;let h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,f=u;t===y.CURSOR_TYPE.NORTH_WEST_RESIZE?(h=d,g=u,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn):t===y.CURSOR_TYPE.NORTH_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===y.CURSOR_TYPE.NORTH_EAST_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=u):t===y.CURSOR_TYPE.WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,f=this._relativeSelectionPositionColumn):t===y.CURSOR_TYPE.EAST_RESIZE?S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===y.CURSOR_TYPE.SOUTH_WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=d,f=this._relativeSelectionPositionColumn):t===y.CURSOR_TYPE.SOUTH_RESIZE&&(h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const p=this._swapPositions(h,g,S,f),v=this._skeleton.getCellWithMergeInfoByIndex(h,g),_=ye({range:p,primary:v,style:null},this._skeleton);this._targetSelection={..._.rangeWithCoord},this._control.updateRangeBySelectionWithCoord(_),this._control.selectionScaling$.next(this._targetSelection)}_initialAutoFill(){const{fillControl:r}=this._control;r.onPointerEnter$.subscribeEvent(e=>{this._injector.get(_e).interceptor.fetchThroughInterceptors(Ao)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&r.setCursor(y.CURSOR_TYPE.CROSSHAIR)}),r.onPointerLeave$.subscribeEvent(()=>{r.resetCursor()}),r.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(r,e){var N,D,k;const t=this._scene,i=t.getViewportScrollXY(this._activeViewport),{scaleX:o,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(r,e,o,s,i),{row:c,column:d}=l,u=t.getCoordRelativeToViewport(y.Vector2.FromArray([r,e])),h=this._skeleton.getRowCount()-1,g=this._skeleton.getColumnCount()-1;let S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn,p=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,C=!1,_=!0;if((d<f||d>v)&&c>=S&&c<=p){const B=this._fillRuler(d,f,v,this._relativeSelectionColumnLength,g);f=B.startRowOrColumn,v=B.endRowOrColumn,C=B.isLighten,_=!1}else if((c<S||c>p)&&d>=f&&d<=v){const B=this._fillRuler(c,S,p,this._relativeSelectionRowLength,h);S=B.startRowOrColumn,p=B.endRowOrColumn,C=B.isLighten}else if(Math.abs(this._startOffsetX-u.x-i.x)/2>Math.abs(this._startOffsetY-u.y-i.y)){const B=this._fillRuler(d,f,v,this._relativeSelectionColumnLength,g);f=B.startRowOrColumn,v=B.endRowOrColumn,C=B.isLighten,_=!1}else{const B=this._fillRuler(c,S,p,this._relativeSelectionRowLength,h);S=B.startRowOrColumn,p=B.endRowOrColumn,C=B.isLighten}const b=this._skeleton.getNoMergeCellPositionByIndex(S,f),E=this._skeleton.getNoMergeCellPositionByIndex(p,v),M=(b==null?void 0:b.startY)||0,w=(E==null?void 0:E.endY)||0,P=(b==null?void 0:b.startX)||0,x=(E==null?void 0:E.endX)||0;C?this._controlHandler((B,V)=>{const U=new a.ColorKit(this._fillControlColors[V]).lighten(qd).toRgbString();B.setProps({fill:U})}):this._controlHandler((B,V)=>{B.setProps({fill:this._fillControlColors[V]})});const A=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===p&&_===!0||f===v&&_===!1?(N=this._helperSelection)==null||N.hide():((D=this._helperSelection)==null||D.transformByState({left:P-A/2,top:M-A/2,width:x-P,height:w-M}),(k=this._helperSelection)==null||k.show()),this._targetSelection={startY:M,endY:w,startX:P,endX:x,startRow:S,endRow:p,startColumn:f,endColumn:v},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(r){const{offsetX:e,offsetY:t}=r,i=this._scene,o=i.getCoordRelativeToViewport(y.Vector2.FromArray([e,t])),{x:s,y:l}=o;this._startOffsetX=s,this._startOffsetY=l;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=this._control.model;this._isInMergeState=this._hasMergeInRange(c,d,u,h),this._relativeSelectionPositionRow=c,this._relativeSelectionPositionColumn=d,this._relativeSelectionRowLength=u-c,this._relativeSelectionColumnLength=h-d;const g=this._control.currentStyle;let S=g==null?void 0:g.stroke,f=g==null?void 0:g.strokeWidth;const p=Rt(this._themeService);S==null&&(S=p.stroke),f==null&&(f=p.strokeWidth);const v=this._getScale();f/=v;const C=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/v,_=new a.ColorKit(S).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new y.Rect(zs,{stroke:_,strokeWidth:f+C/2}),i.addObject(this._helperSelection)),this._activeViewport=i.getActiveViewportByCoord(y.Vector2.FromArray([e,t]));const b=i.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),E=y.ScrollTimer.create(i,this._activeViewport.viewportKey===y.SHEET_VIEWPORT_KEY.VIEW_MAIN?y.ScrollTimerType.ALL:y.ScrollTimerType.NONE);E.startScroll(s,l,b),this._scrollTimer=E,i.disableObjectsEvent(),this._controlHandler(M=>{this._fillControlColors.push(M.fill)}),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(M=>{var B;const{offsetX:w,offsetY:P}=M,x=i.getActiveViewportByCoord(y.Vector2.FromArray([w,P]));if(!this._injector.get(_e).interceptor.fetchThroughInterceptors(Ao)(!1,{x:r.offsetX,y:r.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:N,y:D}=i.getCoordRelativeToViewport(y.Vector2.FromArray([w,P]));this._autoFillMoving(N,D),i.setCursor(y.CURSOR_TYPE.CROSSHAIR);const k=this._targetSelection;if(b&&x&&((B=this._activeViewport)==null?void 0:B.viewportKey)!==(x==null?void 0:x.viewportKey)){let V;k.startRow!==c?(E.scrollTimerType=y.ScrollTimerType.Y,V={...k,endRow:k.startRow}):k.endRow!==u?(E.scrollTimerType=y.ScrollTimerType.Y,V={...k,startRow:k.endRow}):k.startColumn!==d?(E.scrollTimerType=y.ScrollTimerType.X,V={...k,endColumn:k.startColumn}):(E.scrollTimerType=y.ScrollTimerType.X,V={...k,startColumn:k.endColumn}),this._isSelectionInViewport(V,x)&&(b.scrollToBarPos({x:E.scrollTimerType===y.ScrollTimerType.X?0:void 0,y:E.scrollTimerType===y.ScrollTimerType.Y?0:void 0}),this._activeViewport=x)}E.scrolling(N,D,()=>{this._autoFillMoving(N,D)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var w,P;(w=this._helperSelection)==null||w.dispose();const M=this._scene;M.resetCursor(),this._clearObserverEvent(),M.enableObjectsEvent(),(P=this._scrollTimer)==null||P.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((x,A)=>{x.setProps({fill:this._fillControlColors[A]})}),this._fillControlColors=[]})}_hasMergeInRange(r,e,t,i){return this._skeleton.worksheet.getMergedCellRange(r,e,t,i).length>0}_swapPositions(r,e,t,i){const o=Math.min(r,t),s=Math.min(e,i),l=Math.max(r,t),c=Math.max(e,i);return{startRow:o,startColumn:s,endRow:l,endColumn:c}}_controlHandler(r){const{leftControl:e,rightControl:t,topControl:i,bottomControl:o,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[e,t,i,o,s,l,c,d,u];for(let g=0,S=h.length;g<S;g++){const f=h[g];r(f,g)}}_fillRuler(r,e,t,i,o){let s=!1;if(r<e)if(this._isInMergeState&&r<e){const l=e-r,c=i+1,d=Math.ceil(l/c);let u=e-d*c;u<0&&(u=e-(d-1)*c),e=u}else e=r;else if(r>=e&&r<=t)s=!0,this._isInMergeState||(t=r);else if(this._isInMergeState&&r>t){const l=r-t,c=i+1,d=Math.ceil(l/c);let u=t+d*c;u>o&&(u=t+(d-1)*c),t=u}else t=r;return{rowOrColumn:r,startRowOrColumn:e,endRowOrColumn:t,isLighten:s}}_getScale(){const{scaleX:r,scaleY:e}=this._scene.getAncestorScale();return Math.max(r,e)}}var No=(n=>(n.Selection="__SpreadsheetSelectionShape__",n.top="__SpreadsheetSelectionTopControl__",n.bottom="__SpreadsheetSelectionBottomControl__",n.left="__SpreadsheetSelectionShapeLeftControl__",n.right="__SpreadsheetSelectionShapeRightControl__",n.backgroundTop="__SpreadsheetSelectionBackgroundControlTop__",n.backgroundMiddleLeft="__SpreadsheetSelectionBackgroundControlMiddleLeft__",n.backgroundMiddleRight="__SpreadsheetSelectionBackgroundControlMiddleRight__",n.backgroundBottom="__SpreadsheetSelectionBackgroundControlBottom__",n.fill="__SpreadsheetSelectionFillControl__",n.fillTopLeft="__SpreadsheetSelectionFillControlTopLeft__",n.fillBottomRight="__SpreadsheetSelectionFillControlBottomRight__",n.fillTopLeftInner="__SpreadsheetSelectionFillControlTopLeftInner__",n.fillBottomRightInner="__SpreadsheetSelectionFillControlBottomRightInner__",n.lineMain="__SpreadsheetDragLineMainControl__",n.lineContent="__SpreadsheetDragLineContentControl__",n.line="__SpreadsheetDragLineControl__",n.dash="__SpreadsheetDragDashControl__",n.rowHeaderBackground="__SpreadSheetSelectionRowHeaderBackground__",n.rowHeaderBorder="__SpreadSheetSelectionRowHeaderBorder__",n.rowHeaderGroup="__SpreadSheetSelectionRowHeaderGroup__",n.columnHeaderBackground="__SpreadSheetSelectionColumnHeaderBackground__",n.columnHeaderBorder="__SpreadSheetSelectionColumnHeaderBorder__",n.columnHeaderGroup="__SpreadSheetSelectionColumnHeaderGroup__",n.topLeftWidget="__SpreadSheetSelectionTopLeftWidget__",n.topCenterWidget="__SpreadSheetSelectionTopCenterWidget__",n.topRightWidget="__SpreadSheetSelectionTopRightWidget__",n.middleLeftWidget="__SpreadSheetSelectionMiddleLeftWidget__",n.middleRightWidget="__SpreadSheetSelectionMiddleRightWidget__",n.bottomLeftWidget="__SpreadSheetSelectionBottomLeftWidget__",n.bottomCenterWidget="__SpreadSheetSelectionBottomCenterWidget__",n.bottomRightWidget="__SpreadSheetSelectionBottomRightWidget__",n))(No||{});const Xs=.3;class ci extends a.Disposable{constructor(e,t,i,o){var s,l,c,d;super();T(this,"_isHelperSelection",!0);T(this,"_enableAutoFill",!0);T(this,"_showAutoFill",!1);T(this,"_highlightHeader",!0);T(this,"_selectionRenderModel");T(this,"_leftBorder");T(this,"_rightBorder");T(this,"_topBorder");T(this,"_bottomBorder");T(this,"_backgroundControlTop");T(this,"_backgroundControlBottom");T(this,"_backgroundControlMiddleLeft");T(this,"_backgroundControlMiddleRight");T(this,"_autoFillControl");T(this,"_selectionShapeGroup");T(this,"_rowHeaderBackground");T(this,"_rowHeaderBorder");T(this,"_rowHeaderGroup");T(this,"_columnHeaderBackground");T(this,"_columnHeaderBorder");T(this,"_columnHeaderGroup");T(this,"_dashedRect");T(this,"_topLeftWidget");T(this,"_topCenterWidget");T(this,"_topRightWidget");T(this,"_middleLeftWidget");T(this,"_middleRightWidget");T(this,"_bottomLeftWidget");T(this,"_bottomCenterWidget");T(this,"_bottomRightWidget");T(this,"_defaultStyle");T(this,"_currentStyle");T(this,"_rowHeaderWidth",0);T(this,"_columnHeaderHeight",0);T(this,"_widgetRects",[]);T(this,"_controlExtension");T(this,"_dispose$",new O.BehaviorSubject(this));T(this,"dispose$",this._dispose$.asObservable());T(this,"selectionMoving$",new O.Subject);T(this,"selectionMoveEnd$",new O.Subject);T(this,"selectionScaling$",new O.Subject);T(this,"selectionScaled$",new O.Subject);T(this,"selectionFilling$",new O.Subject);T(this,"_selectionFilled$",new O.Subject);T(this,"selectionFilled$",this._selectionFilled$.asObservable());T(this,"_antLineOffset",0);T(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=t,this._themeService=i,this._enableAutoFill=(s=o==null?void 0:o.enableAutoFill)!=null?s:!0,this._highlightHeader=(l=o==null?void 0:o.highlightHeader)!=null?l:!0,this._rowHeaderWidth=(c=o==null?void 0:o.rowHeaderWidth)!=null?c:0,this._columnHeaderHeight=(d=o==null?void 0:o.columnHeaderHeight)!=null?d:0,this._initializeSheetBody(),this._initialHeader()}_initializeSheetBody(){this._defaultStyle=Rt(this._themeService),this._currentStyle=Rt(this._themeService),this._selectionRenderModel=new Kd;const e=this._zIndex;this._leftBorder=new y.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightBorder=new y.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topBorder=new y.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomBorder=new y.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new y.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new y.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new y.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new y.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._autoFillControl=new y.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._autoFillControl.hide(),this._dashedRect=new y.DashedRect("__SpreadsheetDragDashControl__"+e,{zIndex:e+2,evented:!1,stroke:"#fff"});const t=[this._autoFillControl,this._leftBorder,this._rightBorder,this._topBorder,this._bottomBorder,this._backgroundControlTop,this._backgroundControlMiddleLeft,this._backgroundControlMiddleRight,this._backgroundControlBottom,this._dashedRect];this._widgetRects=this._initialWidget(),this._selectionShapeGroup=new y.Group("__SpreadsheetSelectionShape__"+e,...t,...this._widgetRects),this._selectionShapeGroup.hide(),this._selectionShapeGroup.evented=!1,this._selectionShapeGroup.zIndex=e;const i=this.getScene();i.addObject(this._selectionShapeGroup,qi),this.disposeWithMe(a.toDisposable(i.onTransformChange$.subscribeEvent(o=>{o.type===y.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&(this._updateLayoutOfSelectionControl(this._currentStyle),this._updateControlCoord())})))}_initialHeader(){const e=this._zIndex;this._rowHeaderBackground=new y.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new y.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new y.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new y.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new y.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new y.Group("__SpreadSheetSelectionColumnHeaderGroup__"+e,this._columnHeaderBackground,this._columnHeaderBorder),this._columnHeaderGroup.hide(),this._columnHeaderGroup.evented=!1,this._columnHeaderGroup.zIndex=e,this.getScene().addObjects([this._rowHeaderGroup,this._columnHeaderGroup],Zd)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new y.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new y.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new y.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new y.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new y.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new y.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new y.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new y.Rect("__SpreadSheetSelectionBottomRightWidget__"+e,{zIndex:e+1}),[this._topLeftWidget,this._topCenterWidget,this._topRightWidget,this._middleLeftWidget,this._middleRightWidget,this._bottomLeftWidget,this._bottomCenterWidget,this._bottomRightWidget]}get zIndex(){return this._zIndex}get leftControl(){return this._leftBorder}get rightControl(){return this._rightBorder}get topControl(){return this._topBorder}get bottomControl(){return this._bottomBorder}get fillControl(){return this._autoFillControl}get backgroundControlTop(){return this._backgroundControlTop}get backgroundControlBottom(){return this._backgroundControlBottom}get backgroundControlMiddleLeft(){return this._backgroundControlMiddleLeft}get backgroundControlMiddleRight(){return this._backgroundControlMiddleRight}get selectionShape(){return this._selectionShapeGroup}get columnHeaderGroup(){return this._columnHeaderGroup}get rowHeaderGroup(){return this._rowHeaderGroup}get selectionShapeGroup(){return this._selectionShapeGroup}get model(){return this._selectionRenderModel}get topLeftWidget(){return this._topLeftWidget}get topCenterWidget(){return this._topCenterWidget}get topRightWidget(){return this._topRightWidget}get middleLeftWidget(){return this._middleLeftWidget}get middleRightWidget(){return this._middleRightWidget}get bottomLeftWidget(){return this._bottomLeftWidget}get bottomCenterWidget(){return this._bottomCenterWidget}get bottomRightWidget(){return this._bottomRightWidget}get themeService(){return this._themeService}get selectionModel(){return this._selectionRenderModel}set selectionModel(e){this._selectionRenderModel=e}get currentStyle(){return this._currentStyle}set currentStyle(e){this._currentStyle=e}get dashedRect(){return this._dashedRect}get isHelperSelection(){return this._isHelperSelection}get rowHeaderWidth(){return this._rowHeaderWidth}set rowHeaderWidth(e){this._rowHeaderWidth=e}get columnHeaderHeight(){return this._columnHeaderHeight}set columnHeaderHeight(e){this._columnHeaderHeight=e}setControlExtension(e){this._controlExtension=new ja(this,e)}setEvent(e){this.leftControl.evented=e,this.rightControl.evented=e,this.topControl.evented=e,this.bottomControl.evented=e}refreshSelectionFilled(e){this._selectionFilled$.next(e)}_updateLayoutOfSelectionControl(e){e&&(this.currentStyle=Object.assign({},this._defaultStyle,e));const t=this.currentStyle,{stroke:i,widgets:o,autofillStroke:s,strokeDash:l,isAnimationDash:c}=t;let d=t.autofillSize,u=t.strokeWidth,h=t.autofillStrokeWidth;const g=this._getScale(),S=(u+m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/g;u/=g,d/=g,h/=g<1?1:g;const f=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/g,p=y.FIX_ONE_PIXEL_BLUR_OFFSET/g,{startX:v,startY:C,endX:_,endY:b}=this._selectionRenderModel;if(this.leftControl.transformByState({height:b-C,left:-S+p,width:u,strokeWidth:f,top:-f/2+p}),this.leftControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:b-C,left:_-v-S+p,width:u,strokeWidth:f,top:-f/2+p}),this.rightControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:_-v+u,top:-S+p,left:-S+p,height:u,strokeWidth:f}),this.topControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:_-v+u,top:b-C-S+p,height:u,left:-S+p,strokeWidth:f}),this.bottomControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),l==null)this.dashedRect.hide(),this._stopAntLineAnimation();else{const E=t.strokeWidth*2/g;this.dashedRect.transformByState({height:b-C,width:_-v,strokeWidth:E,left:-E/2+p,top:-E/2+p}),this.dashedRect.setProps({strokeDashArray:[0,l/g]}),this._stopAntLineAnimation(),c!==!1&&this._startAntLineAnimation(),this.dashedRect.show()}if(this._showAutoFill=this._showAutoFill&&this._enableAutoFill,this._showAutoFill&&!this._hasWidgets(o)){const E={fill:i,stroke:s,strokeScaleEnabled:!1},M={width:d-h,height:d-h,left:_-v-d/2+h/2-p,top:b-C-d/2+h/2-p,strokeWidth:h};this._autoFillControl.setProps(E),this._autoFillControl.transformByState(M),this._autoFillControl.show()}else this._autoFillControl.hide();this._updateBackgroundControl(t),this._updateHeaderBackground(t),this._updateWidgets(t)}_updateControlCoord(){const{startX:e,startY:t}=this._selectionRenderModel;this.selectionShapeGroup.show(),this.selectionShapeGroup.translate(e,t),this.selectionShapeGroup.makeDirtyNoDebounce(!0)}updateStyle(e){this._updateLayoutOfSelectionControl(e),this._updateControlCoord()}updateRange(e,t){this._selectionRenderModel.setValue(e,t),this._showAutoFill=t!==null,this._updateLayoutOfSelectionControl(),this._updateControlCoord()}updateRangeBySelectionWithCoord(e){this._selectionRenderModel.setValue(e.rangeWithCoord,e.primaryWithCoord),this._showAutoFill=e.primaryWithCoord!==null,this._updateLayoutOfSelectionControl(e.style),this._updateControlCoord()}update(e,t=0,i=0,o,s){this._rowHeaderWidth=t,this._columnHeaderHeight=i,this.updateRangeBySelectionWithCoord({rangeWithCoord:e,primaryWithCoord:s,style:o}),o&&this.updateStyle(o)}updateCurrCell(e){this._showAutoFill=e!==null,this._selectionRenderModel.setCurrentCell(e)}clearHighlight(){this._showAutoFill=!1,this._selectionRenderModel.clearCurrentCell(),this._updateLayoutOfSelectionControl(this._currentStyle)}getScene(){return this._scene}dispose(){var e,t,i,o,s,l,c,d,u,h,g,S,f,p,v,C,_,b,E,M,w,P,x,A,N;(e=this._leftBorder)==null||e.dispose(),(t=this._rightBorder)==null||t.dispose(),(i=this._topBorder)==null||i.dispose(),(o=this._bottomBorder)==null||o.dispose(),(s=this._backgroundControlTop)==null||s.dispose(),(l=this._backgroundControlMiddleLeft)==null||l.dispose(),(c=this._backgroundControlMiddleRight)==null||c.dispose(),(d=this._backgroundControlBottom)==null||d.dispose(),this._autoFillControl.dispose(),(u=this._selectionShapeGroup)==null||u.dispose(),(h=this._rowHeaderBackground)==null||h.dispose(),(g=this._rowHeaderBorder)==null||g.dispose(),(S=this._rowHeaderGroup)==null||S.dispose(),(f=this._rowHeaderBackground)==null||f.dispose(),(p=this._columnHeaderBackground)==null||p.dispose(),(v=this._columnHeaderBorder)==null||v.dispose(),(C=this._columnHeaderGroup)==null||C.dispose(),(_=this._topLeftWidget)==null||_.dispose(),(b=this._topCenterWidget)==null||b.dispose(),(E=this._topRightWidget)==null||E.dispose(),(M=this._middleLeftWidget)==null||M.dispose(),(w=this._middleRightWidget)==null||w.dispose(),(P=this._bottomLeftWidget)==null||P.dispose(),(x=this._bottomCenterWidget)==null||x.dispose(),(A=this._bottomRightWidget)==null||A.dispose(),(N=this._controlExtension)==null||N.dispose(),super.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const i=e.mergeInfo;t={startRow:i.startRow,endRow:i.endRow,startColumn:i.startColumn,endColumn:i.endColumn,startX:i.startX,endX:i.endX,startY:i.startY,endY:i.endY}}else{const{actualRow:i,actualColumn:o,startX:s,endX:l,startY:c,endY:d}=e;t={startRow:i,endRow:i,startColumn:o,endColumn:o,startX:s,endX:l,startY:c,endY:d}}return t}}getValue(){return{...this._selectionRenderModel.getValue(),style:this._currentStyle}}getRange(){return this._selectionRenderModel.getValue().rangeWithCoord}enableHelperSelection(){this._isHelperSelection=!0}disableHelperSelection(){this._isHelperSelection=!1}_updateHeaderBackground(e){const{startX:t,startY:i,endX:o,endY:s,rangeType:l}=this._selectionRenderModel,c=this._currentStyle,d=this._getScale(),{stroke:u,rowHeaderFill:h=c.rowHeaderFill,rowHeaderStroke:g=c.rowHeaderStroke,columnHeaderFill:S=c.columnHeaderFill,columnHeaderStroke:f=c.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:p=c.rowHeaderStrokeWidth,columnHeaderStrokeWidth:v=c.columnHeaderStrokeWidth}=e;p/=d,v/=d;const C=this._rowHeaderWidth,_=this._columnHeaderHeight;if(this._highlightHeader&&_>0){let b=S;l===a.RANGE_TYPE.COLUMN&&(b=new a.ColorKit(u).setAlpha(Xs).toString()),this._columnHeaderBackground.setProps({fill:b}),this._columnHeaderBackground.resize(o-t,_),this._columnHeaderBorder.setProps({fill:f}),this._columnHeaderBorder.transformByState({width:o-t,height:v,top:_-v+1/d}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(t,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),this._highlightHeader&&C>0){let b=h;l===a.RANGE_TYPE.ROW&&(b=new a.ColorKit(u).setAlpha(Xs).toString()),this._rowHeaderBackground.setProps({fill:b}),this._rowHeaderBackground.resize(C,s-i),this._rowHeaderBorder.setProps({fill:g}),this._rowHeaderBorder.transformByState({width:p,height:s-i,left:C-p+1/d}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,i)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:t,startY:i,endX:o,endY:s}=this._selectionRenderModel,l=this._getScale(),{fill:c=e.fill}=e;let{strokeWidth:d}=e;d/=l;const u=this._selectionRenderModel.highlightToSelection();if(!u){this._backgroundControlTop.resize(o-t,s-i),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlBottom.resize(0,0),this._backgroundControlMiddleLeft.resize(0,0),this._backgroundControlMiddleRight.resize(0,0);return}const{startX:h,startY:g,endX:S,endY:f}=u,p=d/2,v={left:-p,top:-p,width:o-t+p*2,height:g-i+p};v.height<0&&(v.width=0,v.height=0),this._backgroundControlTop.transformByState(v);const C={left:-p,top:g-i,width:h-t+p,height:f-g};C.width<0&&(C.width=0,C.height=0),this._backgroundControlMiddleLeft.transformByState(C);const _={left:S-t-p,top:g-i,width:o-S+p*2,height:f-g};_.width<0&&(_.width=0,_.height=0),this._backgroundControlMiddleRight.transformByState(_);const b={left:-p,top:f-i,width:o-t+p*2,height:s-f+p};b.height<0&&(b.width=0,b.height=0),this._backgroundControlBottom.transformByState(b),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlMiddleLeft.setProps({fill:c}),this._backgroundControlMiddleRight.setProps({fill:c}),this._backgroundControlBottom.setProps({fill:c})}_updateWidgets(e){const{startX:t,startY:i,endX:o,endY:s}=this._selectionRenderModel,{stroke:l=e.stroke,widgets:c=e.widgets,widgetStroke:d=e.widgetStroke}=e,u=this._getScale();let{widgetSize:h,widgetStrokeWidth:g}=e;h/=u,g/=u;const S={left:-h/2+g/2,center:(o-t)/2-h/2+g/2,right:o-t-h/2+g/2,top:-h/2,middle:(s-i)/2-h/2,bottom:s-i-h/2+g/2},f=h-g;this._widgetRects.forEach(p=>{p.setProps({fill:l,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.top,strokeWidth:g}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:f,width:f,left:S.center,top:S.top,strokeWidth:g}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:f,width:f,left:S.right,top:S.top,strokeWidth:g}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.middle,strokeWidth:g}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:f,width:f,left:S.right,top:S.middle,strokeWidth:g}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.bottom,strokeWidth:g}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:f,width:f,left:S.center,top:S.bottom,strokeWidth:g}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:f,width:f,left:S.right,top:S.bottom,strokeWidth:g}),this._bottomRightWidget.show()):this._bottomRightWidget.hide()}_hasWidgets(e){if(e==null)return!1;const t=Object.keys(e);if(t.length===0)return!1;for(const i of t)if(e[i]===!0)return!0;return!1}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}_stopAntLineAnimation(){this._antLineOffset=0,y.cancelRequestFrame(this._antRequestNewFrame)}_startAntLineAnimation(){const e=this._getScale();this._antLineOffset+=.6/e,this._antLineOffset>160/e&&(this._antLineOffset=0),this.dashedRect.setProps({strokeDashOffset:-this._antLineOffset}),this._antRequestNewFrame=y.requestNewFrame(()=>{this._startAntLineAnimation()})}}class Qd extends y.Layer{render(r,e=!1){const t=a.Tools.now();return super.render(r,e),this._afterRender(t),this}_afterRender(r){this.scene.getEngine().renderFrameTimeMetric$.next(["selectionLayer",a.Tools.now()-r])}}const _e=a.createIdentifier("univer.sheet.selection-render-service");class as extends a.Disposable{constructor(e,t,i,o,s){super();T(this,"_downObserver");T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_controlFillConfig$",new O.BehaviorSubject(null));T(this,"controlFillConfig$",this._controlFillConfig$.asObservable());T(this,"_selectionControls",[]);T(this,"_startRangeWhenPointerDown",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});T(this,"_activeControlIndex",-1);T(this,"_startViewportPosX",0);T(this,"_startViewportPosY",0);T(this,"_scrollTimer");T(this,"_cancelDownSubscription");T(this,"_cancelUpSubscription");T(this,"_skeleton");T(this,"_scene");T(this,"_highlightHeader",!0);T(this,"_rangeType",a.RANGE_TYPE.NORMAL);T(this,"_selectionStyle");T(this,"_remainLastEnabled",!1);T(this,"_skipLastEnabled",!1);T(this,"_singleSelectionEnabled",!1);T(this,"_selectionMoveEnd$",new O.BehaviorSubject([]));T(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());T(this,"_selectionMoving$",new O.Subject);T(this,"selectionMoving$",this._selectionMoving$.asObservable());T(this,"_selectionMoveStart$",new O.Subject);T(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());T(this,"_selectionMoving",!1);T(this,"_selectionTheme");T(this,"_activeViewport");T(this,"interceptor",new a.InterceptorManager({RANGE_MOVE_PERMISSION_CHECK:xo,RANGE_FILL_PERMISSION_CHECK:Ao}));T(this,"_escapeShortcutDisposable",null);this._injector=e,this._themeService=t,this._shortcutService=i,this._sheetSkeletonManagerService=o,this.contextService=s,this._initSelectionThemeFromThemeService(),this._initMoving()}get selectionMoving(){return this._selectionMoving}get _shouldDetectMergedCells(){return this._rangeType===a.RANGE_TYPE.NORMAL}_initMoving(){this.disposeWithMe(this._selectionMoving$.subscribe(()=>{this._selectionMoving=!0})),this.disposeWithMe(this._selectionMoveEnd$.subscribe(()=>{this._selectionMoving=!1}))}_setSelectionStyle(e){this._selectionStyle=e}getViewPort(){return this._activeViewport}setSingleSelectionEnabled(e=!1){this._singleSelectionEnabled=e}newSelectionControl(e,t,i){const o=this.getSelectionControls().length,{rowHeaderWidth:s,columnHeaderHeight:l}=t,c=new ci(e,o,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(c);const d=ye(i,t);return c.updateRangeBySelectionWithCoord(d),c.setControlExtension({skeleton:t,scene:e,themeService:this._selectionTheme,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),c}resetSelectionsByModelData(e){const t=this.getSelectionControls(),i=this._skeleton;if(!(!t||!i)){for(let o=0,s=e.length;o<s;o++){const l=e[o],c=ye(l,this._skeleton),d=t[o];d?d.updateRangeBySelectionWithCoord(c):this.isSelectionEnabled()&&this.newSelectionControl(this._scene,i,l)}e.length<t.length&&t.splice(e.length).forEach(s=>s.dispose())}}refreshSelectionMoveStart(){this._selectionMoveStart$.next(this.getSelectionDataWithStyle())}refreshSelectionMoveEnd(){this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}_initSelectionThemeFromThemeService(){const e=this._themeService.getCurrentTheme();this._selectionTheme=new a.ThemeService,this._selectionTheme.setTheme(e)}setSelectionTheme(e){this._selectionTheme.setTheme(e)}_changeRuntime(e,t,i){this._skeleton=e,this._scene=t,this._activeViewport=i||(t==null?void 0:t.getViewports()[0]),t.findLayerByZIndex(qi)||t.addLayer(new Qd(t,[],qi))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls,[t,i]=this._skeleton.getLocation();return e.map(o=>{const s=o.getValue();return s.rangeWithCoord.sheetId=i,s.rangeWithCoord.unitId=t,s})}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,i=(l=e.style)!=null?l:Rt(this._selectionTheme),o=this._scene;return e.style=i,this.newSelectionControl(o,t,e)}_clearAllSelectionControls(){const e=this._selectionControls;for(const t of e)t.dispose();this._selectionControls.length=0}_getFreeze(){var t;return(t=this._sheetSkeletonManagerService.getCurrent())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_getViewportByCell(e,t){if(e===void 0||t===void 0)return null;const i=this._getFreeze();if(!i||i.startRow<=0&&i.startColumn<=0)return this._scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e>i.startRow&&t>i.startColumn)return this._scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e<=i.startRow&&t<=i.startColumn)return this._scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(e<=i.startRow&&t>i.startColumn)return this._scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(e>i.startRow&&t<=i.startColumn)return this._scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}getActiveRange(){const e=this.getSelectionControls(),t=e&&e[e.length-1].model;return t&&{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn}}setActiveSelectionIndex(e){this._activeControlIndex=e}resetActiveSelectionIndex(){this._activeControlIndex=-1}getActiveSelectionControl(){const e=this.getSelectionControls();if(e)return this._activeControlIndex<0?e[e.length-1]:e[this._activeControlIndex]}endSelection(){var e;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(e=this._escapeShortcutDisposable)==null||e.dispose(),this._escapeShortcutDisposable=null}_reset(){var e;this._clearAllSelectionControls(),(e=this._downObserver)==null||e.unsubscribe(),this._downObserver=null}_setupPointerMoveListener(e,t,i,o=y.ScrollTimerType.ALL,s,l){var f,p;let c=0,d=0,u=s,h=l;this._scrollTimer=y.ScrollTimer.create(this._scene,o),this._scrollTimer.startScroll((f=e==null?void 0:e.left)!=null?f:0,(p=e==null?void 0:e.top)!=null?p:0,e);const g=this._scene,S=g.getActiveViewportByCoord(y.Vector2.FromArray([s,l]));this._scenePointerMoveSub=g.onPointerMove$.subscribeEvent(v=>{var k,B,V,U,F,L,W,j,z;const{offsetX:C,offsetY:_}=v,{x:b,y:E}=g.getCoordRelativeToViewport(y.Vector2.FromArray([C,_]));this._movingHandler(b,E,t,i);let M=b,w=E;const P=this.getActiveSelectionControl(),x=this._getFreeze(),A=P==null?void 0:P.model,N=(k=g.getActiveViewportByCoord(y.Vector2.FromArray([C,_])))!=null?k:this._getViewportByCell(A==null?void 0:A.endRow,A==null?void 0:A.endColumn);if((()=>{if(!S||!N||!e)return!1;const Z=[y.SHEET_VIEWPORT_KEY.VIEW_MAIN,y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT];return Z.includes(S.viewportKey)&&Z.includes(N.viewportKey)})()){if(!S||!N||!e)return!1;const Z=u<e.left&&b>e.left||u>e.left&&b<e.left,te=h<e.top&&E>e.top||h>e.top&&E<e.top;Z&&(c+=1),te&&(d+=1);const q=S.viewportKey,ie=N.viewportKey;if(q===y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)_<e.top&&((B=A==null?void 0:A.endRow)!=null?B:0)<((V=x==null?void 0:x.startRow)!=null?V:0)?w=e.top:te&&d%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if(q===y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)C<e.left&&((U=A==null?void 0:A.endColumn)!=null?U:0)<((F=x==null?void 0:x.startColumn)!=null?F:0)?M=e.left:Z&&c%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if(q===ie){let oe=!1,X=!1;q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?(oe=!0,X=!0):q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?X=!0:q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&(oe=!0),((L=A==null?void 0:A.endRow)!=null?L:0)>((W=x==null?void 0:x.startRow)!=null?W:0)&&(X=!1),((j=A==null?void 0:A.endColumn)!=null?j:0)>((z=x==null?void 0:x.startColumn)!=null?z:0)&&(oe=!1),oe&&(M=e.left),X&&(w=e.top)}else{const oe={x:S.scrollX,y:S.scrollY},X={x:N.scrollX,y:N.scrollY},Y=oe.x!==X.x&&Z&&c%2===1,Q=oe.y!==X.y&&te&&d%2===1;(Y||Q)&&(e.scrollToBarPos({x:Y?oe.x:void 0,y:Q?oe.y:void 0}),Y||(M=e.left),Q||(w=e.top)),(q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&ie===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||ie===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)&&(M=e.left),(q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&ie===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||ie===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)&&(w=e.top)}u=b,h=E}this._scrollTimer.scrolling(M,w,()=>{this._movingHandler(b,E,t,i)})})}attachSelectionWithCoord(e){return ye(e,this._skeleton)}attachPrimaryWithCoord(e){return qn(this._skeleton,e)}getSelectionCellByPosition(e,t){return this.getCellWithCoordByOffset(e,t)}getCellWithCoordByOffset(e,t,i){const o=this._scene,s=i!=null?i:this._skeleton,l=o.getViewportScrollXY(o.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:c,scaleY:d}=o.getAncestorScale();return s.getCellWithCoordByOffset(e,t,c,d,l)}_movingHandler(e,t,i,o){var M,w,P,x,A;const s=this._skeleton,l=this._scene,[c,d]=s.getLocation(),u={startRow:(M=i==null?void 0:i.model.startRow)!=null?M:-1,endRow:(w=i==null?void 0:i.model.endRow)!=null?w:-1,startColumn:(P=i==null?void 0:i.model.startColumn)!=null?P:-1,endColumn:(x=i==null?void 0:i.model.endColumn)!=null?x:-1,unitId:c,sheetId:d},h=l.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(A=this._getViewportByCell(u.endRow,u.endColumn))!=null?A:h,S=l.getScrollXYInfoByViewport(y.Vector2.FromArray([this._startViewportPosX,this._startViewportPosY]),g),{scaleX:f,scaleY:p}=l.getAncestorScale();o===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:o===a.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const v=this._skeleton.getCellByOffset(e,t,f,p,S);if(!v)return;let C={startRow:Math.min(v.startRow,this._startRangeWhenPointerDown.startRow),startColumn:Math.min(v.startColumn,this._startRangeWhenPointerDown.startColumn),endRow:Math.max(v.endRow,this._startRangeWhenPointerDown.endRow),endColumn:Math.max(v.endColumn,this._startRangeWhenPointerDown.endColumn)};this._shouldDetectMergedCells&&(C=s.expandRangeByMerge(C));const b=ye({range:C,primary:void 0,style:null},s);b.rangeWithCoord.unitId=c,b.rangeWithCoord.sheetId=d,b.rangeWithCoord.rangeType=o;const E=u.startRow!==C.startRow||u.startColumn!==C.startColumn||u.endRow!==C.endRow||u.endColumn!==C.endColumn;i!=null&&E&&(i.updateRangeBySelectionWithCoord(b),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_clearUpdatingListeners(){var t,i,o,s,l;this._scene.enableObjectsEvent(),(t=this._scenePointerMoveSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,(i=this._scenePointerUpSub)==null||i.unsubscribe(),this._scenePointerUpSub=null,(o=this._cancelDownSubscription)==null||o.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,(l=this._scrollTimer)==null||l.dispose()}_addEndingListeners(){var i,o,s;const e=this._scene,t=(i=e.getEngine())==null?void 0:i.activeScene;!t||t===e||((o=this._cancelDownSubscription)==null||o.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,this._cancelDownSubscription=t.onPointerDown$.subscribeEvent(()=>this._clearUpdatingListeners()),this._cancelUpSubscription=t.onPointerUp$.subscribeEvent(()=>this._clearUpdatingListeners()))}_getSelectionWithCoordByOffset(e,t,i,o,s){const l=this._skeleton;if(l==null)return null;if(this._shouldDetectMergedCells){const C=l==null?void 0:l.getCellWithCoordByOffset(e,t,i,o,s,{firstMatch:!0});if(!C)return;const _=a.convertCellToRange(C);return{primaryWithCoord:C,rangeWithCoord:_}}const{row:c,column:d}=l.getCellIndexByOffset(e,t,i,o,s),u=l.getNoMergeCellPositionByIndex(c,d),{startX:h,startY:g,endX:S,endY:f}=u,p={startY:g,endY:f,startX:h,endX:S,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{mergeInfo:p,actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:g,endY:f,startX:h,endX:S},rangeWithCoord:p}}_checkClearPreviousControls(e){this.getSelectionControls().length!==0&&(!e.ctrlKey&&!e.shiftKey&&!this._remainLastEnabled||this._singleSelectionEnabled&&!e.shiftKey)&&this._clearAllSelectionControls()}_makeSelectionByTwoCells(e,t,i,o,s){const{actualRow:l,actualColumn:c,mergeInfo:d}=e;this._startRangeWhenPointerDown={...e.mergeInfo};const u=Math.min(l,t.startRow,d.startRow),h=Math.max(l,t.endRow,d.endRow),g=Math.min(c,t.startColumn,d.startColumn),S=Math.max(c,t.endColumn,d.endColumn),p={range:i.expandRangeByMerge({startRow:u,startColumn:g,endRow:h,endColumn:S}),primary:null,style:null},v=ye(p,i);s.updateRangeBySelectionWithCoord(v)}isSelectionEnabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)}isSelectionDisabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)===!1}inRefSelectionMode(){return this.contextService.getContextValue(m.REF_SELECTIONS_ENABLED)}}function ls(n){return{range:{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:Rr(n).primary,style:null}}function Rr(n){return za(n,{startRow:0,startColumn:0,endRow:0,endColumn:0})}function za(n,r){const e=n.worksheet.getCellInfoInMergeData(r.startRow,r.startColumn),t=n.worksheet.getCellInfoInMergeData(r.endRow,r.endColumn);return{range:{startRow:e.startRow,startColumn:e.startColumn,endRow:t.endRow,endColumn:t.endColumn,rangeType:a.RANGE_TYPE.NORMAL},primary:{actualRow:e.startRow,actualColumn:e.startColumn,startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn,isMerged:e.isMerged,isMergedMainCell:e.isMergedMainCell},style:null}}var Jd=Object.defineProperty,$d=Object.getOwnPropertyDescriptor,eu=(n,r,e,t)=>{for(var i=t>1?void 0:t?$d(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&Jd(r,e,i),i},Mt=(n,r)=>(e,t)=>r(e,t,n);exports.EditorBridgeService=class extends a.Disposable{constructor(e,t,i,o,s,l,c){super();T(this,"_editorUnitId",a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);T(this,"_editorIsDirty",!1);T(this,"_isDisabled",!1);T(this,"_visible",{visible:!1,eventType:y.DeviceInputEventType.Dblclick,unitId:""});T(this,"_currentEditCell",null);T(this,"_currentEditCellState",null);T(this,"_currentEditCellLayout",null);T(this,"_currentEditCellState$",new O.BehaviorSubject(null));T(this,"currentEditCellState$",this._currentEditCellState$.asObservable());T(this,"_currentEditCellLayout$",new O.BehaviorSubject(null));T(this,"currentEditCellLayout$",this._currentEditCellLayout$.asObservable());T(this,"currentEditCell$",this._currentEditCellState$.pipe(O.switchMap(e=>this._currentEditCellLayout$.pipe(O.map(t=>e&&t?{...e,...t}:null)))));T(this,"_visible$",new O.BehaviorSubject(this._visible));T(this,"visible$",this._visible$.asObservable());T(this,"_afterVisible$",new O.BehaviorSubject(this._visible));T(this,"afterVisible$",this._afterVisible$.asObservable());T(this,"_forceKeepVisible$",new O.BehaviorSubject(!1));T(this,"forceKeepVisible$",this._forceKeepVisible$.asObservable());this._sheetInterceptorService=e,this._renderManagerService=t,this._themeService=i,this._univerInstanceService=o,this._editorService=s,this._refSelectionsService=l,this._contextService=c,this.disposeWithMe(a.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).subscribe(d=>{var u;d.getUnitId()===((u=this._currentEditCellState)==null?void 0:u.unitId)&&this._clearCurrentEditCellState()})}refreshEditCellState(){const e=this.getLatestEditCellState();if(!e){this._currentEditCellState=null,this._currentEditCellLayout=null,this._currentEditCellState$.next(null),this._currentEditCellLayout$.next(null);return}const{position:t,scaleX:i,scaleY:o,canvasOffset:s,...l}=e;this._currentEditCellState=l,this._currentEditCellLayout={position:t,scaleX:i,scaleY:o,canvasOffset:s},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}refreshEditCellPosition(e){var w;const t=this._currentEditCell;if(t==null)return;const i=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!i)return;const o=(w=i.with(exports.SheetSkeletonManagerService).getWorksheetSkeleton(t.sheetId))==null?void 0:w.skeleton,s=i.with(_e);if(!o||!this._currentEditCellState)return;const{primary:l,unitId:c,sheetId:d,scene:u,engine:h}=t,g=qn(o,l);if(g==null)return;const S=a.convertCellToRange(g),f=J.getCanvasOffsetByEngine(h);let{startX:p,startY:v,endX:C,endY:_}=S;const{scaleX:b,scaleY:E}=u.getAncestorScale(),M=u.getViewportScrollXY(s.getViewPort());p=o.convertTransformToOffsetX(p,b,M),v=o.convertTransformToOffsetY(v,E,M),C=o.convertTransformToOffsetX(C,b,M),_=o.convertTransformToOffsetY(_,E,M),e&&this._currentEditCellLayout&&(C=C-p+this._currentEditCellLayout.position.startX,_=_-v+this._currentEditCellLayout.position.startY,p=this._currentEditCellLayout.position.startX,v=this._currentEditCellLayout.position.startY),this._currentEditCellLayout={position:{startX:p,startY:v,endX:C,endY:_},canvasOffset:f,scaleX:b,scaleY:E},this._currentEditCellLayout$.next(this._currentEditCellLayout)}setEditCell(e){this._currentEditCell=e,this._editorService.getFocusEditor()||(this._editorService.focus(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_STANDALONE,!1));const t=this.getLatestEditCellState();if(!t){this._currentEditCellState=t,this._currentEditCellLayout=t,this._currentEditCellState$.next(t),this._currentEditCellLayout$.next(t);return}const{position:i,canvasOffset:o,scaleX:s,scaleY:l,...c}=t;this._currentEditCellState=c,this._currentEditCellLayout={position:i,canvasOffset:o,scaleX:s,scaleY:l},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}_clearCurrentEditCellState(){this._currentEditCellState=null,this._currentEditCellState$.next(null),this._currentEditCellLayout=null,this._currentEditCellLayout$.next(null)}getEditCellState(){return this._currentEditCellState==null||this._currentEditCellLayout==null?null:{...this._currentEditCellState,...this._currentEditCellLayout}}getEditCellLayout(){return this._currentEditCellLayout}getEditLocation(){return this._currentEditCellState}getLatestEditCellState(){var B,V,U;const e=this._currentEditCell;if(e==null)return;const t=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!t)return;const i=t.with(exports.SheetSkeletonManagerService).getCurrentSkeleton(),o=t.with(_e);if(!i)return;const{primary:s,unitId:l,sheetId:c,scene:d,engine:u}=e,{startRow:h,startColumn:g}=s,S=qn(i,s);if(S==null)return;const f=a.convertCellToRange(S),p=J.getCanvasOffsetByEngine(u);let{startX:v,startY:C,endX:_,endY:b}=f;const{scaleX:E,scaleY:M}=d.getAncestorScale(),w=d.getViewportScrollXY(o.getViewPort());v=i.convertTransformToOffsetX(v,E,w),C=i.convertTransformToOffsetY(C,M,w),_=i.convertTransformToOffsetX(_,E,w),b=i.convertTransformToOffsetY(b,M,w);const P=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),x=P.getActiveSheet();if(!x)return;const A={workbook:P,worksheet:x,unitId:P.getUnitId(),subUnitId:x.getSheetId(),row:h,col:g,origin:x.getCellRaw(h,g)};let N;const D=this._sheetInterceptorService.writeCellInterceptor.fetchThroughInterceptors(m.BEFORE_CELL_EDIT)(x.getCell(h,g),A);N=D&&i.getCellDocumentModelWithFormula(D);const k=(B=N==null?void 0:N.documentModel)==null?void 0:B.documentStyle.renderConfig;if(k!=null&&(k.cellValueType=a.CellValueType.STRING),!N||N.documentModel==null){const F=i.getBlankCellDocumentModel(D);if(N!=null){const{verticalAlign:L,horizontalAlign:W,wrapStrategy:j,textRotation:z,fill:Z}=N,{centerAngle:te,vertexAngle:q}=y.convertTextRotation(z);F.documentModel.documentStyle.renderConfig={...k,verticalAlign:L,horizontalAlign:W,wrapStrategy:j,background:{rgb:Z},centerAngle:te,vertexAngle:q}}N=F}if(N.fill=N.fill||"#fff",(V=N.documentModel)==null||V.setZoomRatio(Math.max(E,M)),(D==null?void 0:D.isInArrayFormulaRange)===!0){const F=(U=N.documentModel)==null?void 0:U.getBody();F&&(F.textRuns=[{st:0,ed:F.dataStream.length-2,ts:{cl:{rgb:this._themeService.getCurrentTheme().textColorSecondary}}}])}return{position:{startX:v,startY:C,endX:_,endY:b},scaleX:E,scaleY:M,canvasOffset:p,row:h,column:g,unitId:l,sheetId:c,documentLayoutObject:N,editorUnitId:this._editorUnitId,isInArrayFormulaRange:D==null?void 0:D.isInArrayFormulaRange}}getCurrentEditorId(){return this._editorUnitId}changeVisible(e){this._visible=e,e.visible&&(this._editorIsDirty=!1),this._visible$.next(this._visible),this._afterVisible$.next(this._visible)}isVisible(){return this._visible}enableForceKeepVisible(){this._forceKeepVisible$.next(!0)}disableForceKeepVisible(){this._forceKeepVisible$.next(!1)}isForceKeepVisible(){return this._forceKeepVisible$.getValue()}changeEditorDirty(e){this._editorIsDirty=e}getEditorDirty(){return this._editorIsDirty}};exports.EditorBridgeService=eu([Mt(0,a.Inject(m.SheetInterceptorService)),Mt(1,y.IRenderManagerService),Mt(2,a.Inject(a.ThemeService)),Mt(3,a.IUniverInstanceService),Mt(4,J.IEditorService),Mt(5,m.IRefSelectionsService),Mt(6,a.IContextService)],exports.EditorBridgeService);const he=a.createIdentifier("univer.sheet-editor-bridge.service"),Me={id:"sheet.operation.set-cell-edit-visible",type:a.CommandType.OPERATION,handler:(n,r)=>r?(n.get(he).changeVisible(r),!0):!1},di={id:"sheet.operation.set-cell-edit-visible-f2",type:a.CommandType.OPERATION,handler:(n,r)=>{const e=n.get(a.ICommandService),i=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return i?(e.syncExecuteCommand(Me.id,{...r,unitId:i.getUnitId()}),!0):!1}},Ft={id:"sheet.operation.set-cell-edit-visible-arrow",type:a.CommandType.OPERATION,handler:()=>!0},Pn={id:"sheet.command.change-zoom-ratio",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=n.get(a.IUniverInstanceService),t=m.getSheetCommandTarget(e);if(!t)return!1;const{worksheet:i,subUnitId:o,unitId:s}=t,{delta:l,reset:c}=r;let d=c?100:Math.round((i.getConfig().zoomRatio+l)*100);d=Math.max(Oo[0],d),d=Math.min(Oo[1],d);const u=d/100,g=n.get(he).isVisible();return(g.unitId===s||g.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&g.visible?!1:n.get(a.ICommandService).executeCommand(ze.id,{unitId:s,subUnitId:o,zoomRatio:u})}},On={id:"sheet.command.set-zoom-ratio",type:a.CommandType.COMMAND,handler:async(n,r)=>{if(!r)return!1;const{unitId:e,subUnitId:t,zoomRatio:i}=r,s=n.get(he).isVisible();return(s.unitId===e||s.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&s.visible?!1:n.get(a.ICommandService).executeCommand(ze.id,{unitId:e,subUnitId:t,zoomRatio:i})}};function tu(n){return typeof n.isMainScene>"u"}function Xe(n,r){const e=n instanceof a.Workbook?n:n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getUnitId();let i,o,s,l;if(tu(r)){const g=r.getRenderById(t);if(g==null)return null;i=g.components,i=g.components,o=g.mainComponent,s=g.scene,l=g.engine}else i=r.components,o=r.mainComponent,s=r.scene,l=r.engine;if(!i||!o)return null;const c=o,d=i.get(me.ROW),u=i.get(me.COLUMN),h=i.get(me.LEFT_TOP);return{spreadsheet:c,spreadsheetRowHeader:d,spreadsheetColumnHeader:u,spreadsheetLeftTopPlaceholder:h,scene:s,engine:l}}function Do(n,r,e,t){const{startX:i,startY:o,endX:s,endY:l}=t.getCellWithCoordByIndex(n,r);return{startX:i,startY:o,endX:s,endY:l}}function Ke(n,r,e,t,i,o){const s=e.getCoordRelativeToViewport(y.Vector2.FromArray([n,r])),{x:l,y:c}=s,d=e.getScrollXYInfoByViewport(s,i),{scaleX:u,scaleY:h}=e.getAncestorScale(),g=t.getCellIndexByOffset(l,c,u,h,d,{closeFirst:o}),{row:S,column:f}=g,p=t.getNoMergeCellPositionByIndex(S,f),{startX:v,startY:C,endX:_,endY:b}=p;return{startX:v,startY:C,endX:_,endY:b,row:S,column:f}}function Zn(n,r,e,t){const i=e.getCoordRelativeToViewport(y.Vector2.FromArray([n,r])),o=e.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=e.getScrollXYInfoByViewport(i,o),{scaleX:l,scaleY:c}=e.getAncestorScale(),{x:d,y:u}=s,h=n/l+d,g=r/c+u;return{x:h,y:g}}var nu=Object.defineProperty,iu=Object.getOwnPropertyDescriptor,ru=(n,r,e,t)=>{for(var i=t>1?void 0:t?iu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&nu(r,e,i),i},Di=(n,r)=>(e,t)=>r(e,t,n);let Qn=class extends a.Disposable{constructor(n,r,e,t,i){super(),this._context=n,this._sheetSkeletonManagerService=r,this._commandService=e,this._contextService=t,this._editorBridgeService=i,this._initSkeletonListener(),this._initZoomEventListener()}updateZoom(n,r){const e=this._context.unit.getSheetBySheetId(n);return e?(e.getConfig().zoomRatio=r,e===this._context.unit.getActiveSheet()&&this._updateViewZoom(r),!0):!1}_initZoomEventListener(){const n=this._getSheetObject().scene;this.disposeWithMe(n.onMouseWheel$.subscribeEvent(r=>{if(!r.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;if(this._editorBridgeService){const c=this._editorBridgeService.isVisible();if((c.unitId===this._context.unitId||c.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&c.visible)return}const e=Math.abs(r.deltaX);let t=e<40?.2:e<80?.4:.2;t*=r.deltaY>0?-1:1,n.scaleX<1&&(t/=2);const i=this._context.unit,o=i.getActiveSheet();if(!o)return;const s=o.getZoomRatio();let l=+Number.parseFloat(`${s+t}`).toFixed(1);l=l>=4?4:l<=.1?.1:l,this._commandService.executeCommand(On.id,{zoomRatio:Math.round(l*10)/10,unitId:i.getUnitId(),subUnitId:o.getSheetId()}),r.preventDefault()}))}_initSkeletonListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(n=>{if(n==null)return;const e=this._context.unit.getActiveSheet();if(!e)return;const t=e.getZoomRatio()||1;this._updateViewZoom(t)}))}_updateViewZoom(n){const r=this._getSheetObject();r==null||r.scene.scale(n,n),r==null||r.spreadsheet.makeForceDirty()}_getSheetObject(){return Xe(this._context.unit,this._context)}};Qn=ru([Di(1,a.Inject(exports.SheetSkeletonManagerService)),Di(2,a.ICommandService),Di(3,a.IContextService),Di(4,a.Optional(he))],Qn);const ze={id:"sheet.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(n,r)=>{const t=n.get(y.IRenderManagerService).getRenderById(r.unitId);return t?t.with(Qn).updateZoom(r.subUnitId,r.zoomRatio):!1}};var ou=Object.defineProperty,su=Object.getOwnPropertyDescriptor,au=(n,r,e,t)=>{for(var i=t>1?void 0:t?su(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&ou(r,e,i),i},Ur=(n,r)=>(e,t)=>r(e,t,n);const Ys="univer-sheet-main-canvas";exports.SheetsRenderService=class extends a.RxDisposable{constructor(e,t,i){super();T(this,"_skeletonChangeMutations",new Set);this._contextService=e,this._instanceSrv=t,this._renderManagerService=i,Promise.resolve().then(()=>this._init())}registerSkeletonChangingMutations(e){return this._skeletonChangeMutations.has(e)?a.toDisposable(()=>{}):(this._skeletonChangeMutations.add(e),a.toDisposable(()=>this._skeletonChangeMutations.delete(e)))}checkMutationShouldTriggerRerender(e){return this._skeletonChangeMutations.has(e)}_init(){this._initWorkbookListener(),this._initContextListener()}_initWorkbookListener(){this._instanceSrv.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.takeUntil(this.dispose$)).subscribe(e=>this._createRenderer(e)),this._instanceSrv.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._createRenderer(e)),this._instanceSrv.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.takeUntil(this.dispose$)).subscribe(e=>this._disposeRenderer(e))}_createRenderer(e){const t=e.getUnitId();this._renderManagerService.created$.subscribe(i=>{i.unitId===t&&(i.engine.getCanvas().setId(`${Ys}_${t}`),i.engine.getCanvas().getContext().setId(`${Ys}_${t}`))}),this._renderManagerService.createRender(t),this._renderManagerService.setCurrent(t)}_disposeRenderer(e){const t=e.getUnitId();this._renderManagerService.removeRender(t)}_initContextListener(){this.disposeWithMe(this._contextService.subscribeContextValue$(y.RENDER_RAW_FORMULA_KEY).pipe(O.distinctUntilChanged()).subscribe(()=>{this._renderManagerService.getRenderAll().forEach(e=>{e.mainComponent instanceof y.Spreadsheet&&e.mainComponent.makeForceDirty(!0)})}))}};exports.SheetsRenderService=au([Ur(0,a.IContextService),Ur(1,a.IUniverInstanceService),Ur(2,y.IRenderManagerService)],exports.SheetsRenderService);var lu=Object.defineProperty,cu=Object.getOwnPropertyDescriptor,du=(n,r,e,t)=>{for(var i=t>1?void 0:t?cu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&lu(r,e,i),i},Pt=(n,r)=>(e,t)=>r(e,t,n);exports.AutoFillController=class extends a.Disposable{constructor(e,t,i,o,s,l,c){super();T(this,"_beforeApplyData",[]);T(this,"_currentLocation",null);T(this,"_copyData",[]);T(this,"_defaultHook");this._univerInstanceService=e,this._commandService=t,this._autoFillService=i,this._editorBridgeService=o,this._renderManagerService=s,this._injector=l,this._sheetsRenderService=c,this._defaultHook={id:"default",type:cn.Default,priority:0,onBeforeFillData:(d,u)=>this._presetAndCacheData(d,u),onFillData:(d,u,h)=>this._fillData(d,u,h)},this._init()}_init(){this._initDefaultHook(),this._onSelectionControlFillChanged(),this._initQuitListener(),this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(Ct.id))}_initDefaultHook(){this.disposeWithMe(this._autoFillService.addHook(this._defaultHook))}_initQuitListener(){const e=[Me.id,In.id,m.SetRangeValuesCommand.id,ze.id,m.SetWorksheetActiveOperation.id,m.MoveRangeMutation.id,m.RemoveRowMutation.id,m.RemoveColMutation.id,m.InsertRowMutation.id,m.InsertColMutation.id,m.MoveRowsMutation.id,m.MoveColsMutation.id,m.SetWorksheetColWidthMutation.id,m.SetWorksheetRowHeightMutation.id,m.SetRangeValuesMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted((t,i)=>{var c,d;const o=i==null?void 0:i.fromCollab,s=i==null?void 0:i.fromSync,l=i==null?void 0:i.fromFormula;e.includes(t.id)&&!o&&!s&&!l&&t.params.trigger!==Ct.id&&t.params.trigger!==li.id&&this._quit(),t.id===m.RemoveSheetMutation.id&&t.params.unitId===((c=this._currentLocation)==null?void 0:c.unitId)&&t.params.subUnitId===((d=this._currentLocation)==null?void 0:d.subUnitId)&&this._quit()})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{var i;t.getUnitId()===((i=this._currentLocation)==null?void 0:i.unitId)&&this._quit()}))}_quit(){this._currentLocation=null,this._beforeApplyData=[],this._copyData=[],this._autoFillService.setShowMenu(!1)}_onSelectionControlFillChanged(){const e=new a.DisposableCollection,t=i=>{i.dispose();const o=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!o)return;o.with(_e).getSelectionControls().forEach(c=>{i.add(a.toDisposable(c.selectionFilled$.subscribe(d=>{if(d==null||d.startColumn===-1||d.startRow===-1||d.endColumn===-1||d.endRow===-1)return;const u={startColumn:c.model.startColumn,endColumn:c.model.endColumn,startRow:c.model.startRow,endRow:c.model.endRow},h={startColumn:d.startColumn,endColumn:d.endColumn,startRow:d.startRow,endRow:d.endRow};this._commandService.executeCommand(Ct.id,{sourceRange:u,targetRange:h})}))),i.add(a.toDisposable(c.fillControl.onDblclick$.subscribeEvent(()=>{const d={startColumn:c.model.startColumn,endColumn:c.model.endColumn,startRow:c.model.startRow,endRow:c.model.endRow};this._handleDbClickFill(d)}))),i.add(a.toDisposable(c.fillControl.onPointerDown$.subscribeEvent(()=>{this._editorBridgeService.isVisible().visible&&this._editorBridgeService.changeVisible({visible:!1,eventType:y.DeviceInputEventType.PointerDown,unitId:o.unitId})})))})};t(e),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===m.SetSelectionsOperation.id&&t(e)}))}_handleDbClickFill(e){const t=this._detectFillRange(e);t.endRow<=e.endRow||this._commandService.executeCommand(Ct.id,{sourceRange:e,targetRange:t})}_detectFillRange(e){var g,S,f,p,v,C;const{startRow:t,endRow:i,startColumn:o,endColumn:s}=e,l=(g=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:g.getActiveSheet();if(!l)return e;const c=l.getCellMatrix(),d=l.getMaxRows()-1,u=l.getMaxColumns()-1;let h=i;if(o>0&&((S=c.getValue(t,o-1))==null?void 0:S.v)!=null){let _=t;for(;((f=c.getValue(_,o-1))==null?void 0:f.v)!=null&&_<d;)_+=1;h=_-1}else if(s<u&&((p=c.getValue(i,s+1))==null?void 0:p.v)!=null){let _=t;for(;((v=c.getValue(_,s+1))==null?void 0:v.v)!=null&&_<d;)_+=1;h=_-1}for(let _=i+1;_<=h;_++)for(let b=o;b<=s;b++)if(((C=c.getValue(_,b))==null?void 0:C.v)!=null){h=_-1;break}return{startColumn:o,endColumn:s,startRow:t,endRow:h}}_getApplyData(e,t,i,o,s,l=!0){const c=[],d=Math.floor(i/t),u=i%t,h=this._autoFillService.getRules();if(!l&&s===se.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const g={};h.forEach(S=>{g[S.type]=[]}),h.forEach(S=>{const{type:f,applyFunctions:p={}}=S,v=e[f];v&&v.forEach(C=>{const _=Od(C.index,u),b=C.index.length*d+_,E=this._applyFunctions(C,b,o,s,p,e),M=xd(t,i,C.index);g[f].push({data:E,index:M})})});for(let S=0;S<i;S++)h.forEach(f=>{const{type:p}=f,v=g[p];for(let C=0;C<v.length;C++)S in v[C].index&&c.push(v[C].data[v[C].index[S]])});return c}_applyFunctions(e,t,i,o,s,l){const{data:c}=e,d=i===a.Direction.UP||i===a.Direction.LEFT;if(o===se.COPY){const u=s==null?void 0:s[se.COPY];return u?u(e,t,i,l):(d&&c.reverse(),Bt(c,t))}if(o===se.SERIES){const u=s==null?void 0:s[se.SERIES];return u?u(e,t,i,l):(d&&c.reverse(),s!=null&&s[se.COPY]?s[se.COPY](e,t,i,l):Bt(c,t))}if(o===se.ONLY_FORMAT){const u=s==null?void 0:s[se.ONLY_FORMAT];return u?u(e,t,i,l):Ad(c,t)}}_getCopyData(e,t){const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!i)throw new Error("No active sheet found");const o=i.getCellMatrix(),s=this._autoFillService.getRules(),l=[],c=t===a.Direction.DOWN||t===a.Direction.UP;let d,u;return c?(d=e.cols,u=e.rows):(d=e.rows,u=e.cols),d.forEach(h=>{const g=this._getEmptyCopyDataPiece(),S={type:void 0,cellData:void 0};u.forEach(f=>{let p;c?p=o.getValue(f,h):p=o.getValue(h,f);const{type:v,isContinue:C}=s.find(_=>_.match(p,this._injector))||Fa;if(C(S,p)){const _=g[v],b=_[_.length-1];b.data.push(p),b.index.push(f-u[0])}else{const _=g[v];_?_.push({data:[p],index:[f-u[0]]}):g[v]=[{data:[p],index:[f-u[0]]}]}S.type=v,S.cellData=p}),l.push(g)}),l}_getEmptyCopyDataPiece(){const e={};return this._autoFillService.getRules().forEach(t=>{e[t.type]=[]}),e}_getMergeApplyData(e,t,i,o){const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=[];for(let c=e.startRow;c<=e.endRow;c++)for(let d=e.startColumn;d<=e.endColumn;d++){const{isMergedMainCell:u,startRow:h,startColumn:g,endRow:S,endColumn:f}=s.getCellInfoInMergeData(c,d);if(u){if(i===a.Direction.DOWN){let p=h+o,v=S+o;for(;v<=t.endRow;)l.push({startRow:p,startColumn:g,endRow:v,endColumn:f}),p+=o,v+=o}else if(i===a.Direction.UP){let p=h-o,v=S-o;for(;p>=t.startRow;)l.push({startRow:p,startColumn:g,endRow:v,endColumn:f}),p-=o,v-=o}else if(i===a.Direction.RIGHT){let p=g+o,v=f+o;for(;v<=t.endColumn;)l.push({startRow:h,startColumn:p,endRow:S,endColumn:v}),p+=o,v+=o}else if(i===a.Direction.LEFT){let p=g-o,v=f-o;for(;p>=t.startColumn;)l.push({startRow:h,startColumn:p,endRow:S,endColumn:v}),p-=o,v-=o}}}return l}_presetAndCacheData(e,t){const{source:i,target:o}=e,s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=s.getCellMatrix(),c=[];return o.rows.forEach(d=>{const u=[];o.cols.forEach(h=>{u.push(a.Tools.deepClone(l.getValue(d,h)))}),c.push(u)}),this._beforeApplyData=c,this._copyData=this._getCopyData(i,t),this._currentLocation=e,this._shouldDisableSeries(this._copyData)?(this._autoFillService.setDisableApplyType(se.SERIES,!0),se.COPY):(this._autoFillService.setDisableApplyType(se.SERIES,!1),this._getPreferredApplyType(this._copyData))}_fillData(e,t,i){var B,V;const o=[],s=[];let l=!0;i===se.NO_FORMAT&&(l=!1,i=se.SERIES);const{source:c,target:d,unitId:u,subUnitId:h}=e;if(!c||!d||t==null)return{undos:o,redos:s};const g=_t(c),S=_t(d),{cols:f,rows:p}=d,{cols:v,rows:C}=c,_=this._copyData;let b;t===a.Direction.DOWN||t===a.Direction.UP?b=C.length:b=v.length;const E=[];if(t===a.Direction.DOWN||t===a.Direction.UP){const U=p.length,F=[];f.forEach((L,W)=>{const j=_[W],z=this._getApplyData(j,b,U,t,i,l);F.push(z)});for(let L=0;L<F[0].length;L++){const W=[];for(let j=0;j<F.length;j++)W.push({s:null,...F[j][L]});E.push(W)}}else{const U=f.length;p.forEach((F,L)=>{const W=_[L],j=this._getApplyData(W,b,U,t,i,l),z=[];for(let Z=0;Z<j.length;Z++)z.push({s:null,...j[Z]});E.push(z)})}let M=[];const w=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getStyles();if(l?(M=this._getMergeApplyData(g,S,t,b),E.forEach(U=>{U.forEach(F=>{F&&w&&w&&(F.s=w.getStyleByCell(F))})})):E.forEach((U,F)=>{U.forEach((L,W)=>{L&&w&&(L.s=w.getStyleByCell(this._beforeApplyData[F][W])||null)})}),i===se.ONLY_FORMAT&&E.forEach((U,F)=>{U.forEach((L,W)=>{if(L){const j=this._beforeApplyData[F][W]||{};L.f=j.f,L.si=j.si,L.t=j.t,L.v=j.v}})}),l){const U=[],F=(V=(B=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:B.getSheetBySheetId(h))==null?void 0:V.getMergeData();F&&F.forEach(j=>{a.Rectangle.intersects(j,S)&&U.push(j)});const L={unitId:u,subUnitId:h,ranges:U},W=this._injector.invoke(m.RemoveMergeUndoMutationFactory,L);U.length&&(s.push({id:m.RemoveWorksheetMergeMutation.id,params:L}),o.unshift({id:m.AddWorksheetMergeMutation.id,params:W}))}const P={subUnitId:h,unitId:u,cellValue:Rd([d])},x=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,P);s.push({id:m.SetRangeValuesMutation.id,params:P}),o.unshift({id:m.SetRangeValuesMutation.id,params:x});const A=new a.ObjectMatrix;p.forEach((U,F)=>{f.forEach((L,W)=>{E[F][W]&&A.setValue(U,L,E[F][W])})});const N=A.getMatrix(),D={subUnitId:h,unitId:u,cellValue:N},k=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,D);if(this._autoFillService.getActiveHooks().forEach(U=>{var F;(F=U.onBeforeSubmit)==null||F.call(U,e,t,i,N)}),o.unshift({id:m.SetRangeValuesMutation.id,params:k}),s.push({id:m.SetRangeValuesMutation.id,params:D}),M!=null&&M.length){const U=m.getAddMergeMutationRangeByType(M),F={unitId:u,subUnitId:h,ranges:U},L=this._injector.invoke(m.AddMergeUndoMutationFactory,F);o.unshift({id:m.RemoveWorksheetMergeMutation.id,params:L}),s.push({id:m.AddWorksheetMergeMutation.id,params:F})}return{undos:o,redos:s}}_shouldDisableSeries(e){return e.every(t=>Object.keys(t).every(i=>{var o;return((o=t[i])==null?void 0:o.length)===0||[ve.OTHER,ve.FORMULA].includes(i)}))}_getPreferredApplyType(e){return e.every(i=>Object.keys(i).every(o=>{var s,l;return((s=i[o])==null?void 0:s.length)===0||((l=i[o])==null?void 0:l.length)===1&&i[o][0].data.length===1&&ve.NUMBER===o}))?se.COPY:se.SERIES}};exports.AutoFillController=du([Pt(0,a.IUniverInstanceService),Pt(1,a.ICommandService),Pt(2,Tt),Pt(3,he),Pt(4,y.IRenderManagerService),Pt(5,a.Inject(a.Injector)),Pt(6,a.Inject(exports.SheetsRenderService))],exports.AutoFillController);var uu=Object.defineProperty,hu=Object.getOwnPropertyDescriptor,mu=(n,r,e,t)=>{for(var i=t>1?void 0:t?hu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&uu(r,e,i),i},Lr=(n,r)=>(e,t)=>r(e,t,n);exports.CellCustomRenderController=class extends a.Disposable{constructor(e,t,i,o){super();T(this,"_enterActiveRender");this._context=e,this._sheetSkeletonManagerService=t,this._renderManagerService=i,this._permissionService=o,this._initEventBinding()}_initEventBinding(){const e=new a.DisposableCollection,t=this._context.unit,i=o=>{if(e.dispose(),!o)return;const s=this._context.unitId,{skeleton:l}=o,c=this._renderManagerService.getRenderById(s);if(c&&c.mainComponent){const d=c.mainComponent,u=S=>{const{offsetX:f,offsetY:p}=S,v=c.scene,C=t.getActiveSheet();if(!C)return;const _=v.getActiveViewportByCoord(y.Vector2.FromArray([f,p]));if(!_)return;const{scaleX:b,scaleY:E}=v.getAncestorScale(),M={x:_.viewportScrollX,y:_.viewportScrollY},w=l.getCellIndexByOffset(f,p,b,E,M),P=l.worksheet.getMergedCell(w.row,w.column),x={actualRow:P?P.startRow:w.row,actualCol:P?P.startColumn:w.column,mergeCell:P,row:w.row,col:w.column};if(!x||!l)return;const A=C.getCell(x.actualRow,x.actualCol);if(!A)return;const N=A.customRender;if(!(N!=null&&N.length))return;const D=x.actualRow,k=x.actualCol,B=N.sort(a.sortRules),V=C.getSheetId(),U={data:A,style:l.getsStyles().getStyleByCell(A),primaryWithCoord:l.getCellWithCoordByIndex(x.actualRow,x.actualCol),unitId:s,subUnitId:V,row:D,col:k,workbook:t,worksheet:C},F={x:M.x+f/b,y:M.y+p/E},L=B.find(W=>{var j;return(j=W.isHit)==null?void 0:j.call(W,F,U)});if(L)return[L,U]},h=d.onPointerDown$.subscribeEvent(S=>{var p,v,C,_;const f=u(S);if(f){const[b,E]=f,{row:M,col:w,worksheet:P,unitId:x,subUnitId:A}=E;if(!((p=this._permissionService.composePermission([new m.WorkbookEditablePermission(x).id,new m.WorksheetEditPermission(x,A).id]))==null?void 0:p.every(k=>k.value)))return!1;const D=(C=(v=P.getCell(M,w))==null?void 0:v.selectionProtection)==null?void 0:C[0];if((D==null?void 0:D[m.UnitAction.Edit])===!1)return!1;(_=b.onPointerDown)==null||_.call(b,E,S)}}),g=a.fromEventSubject(d.onPointerMove$).pipe(O.throttleTime(30)).subscribe(S=>{var p,v,C,_,b,E;const f=u(S);if(f){const[M,w]=f;this._enterActiveRender?this._enterActiveRender.render!==M&&((v=(p=this._enterActiveRender.render).onPointerLeave)==null||v.call(p,this._enterActiveRender.cellContext,S),this._enterActiveRender={render:M,cellContext:w},(C=M.onPointerEnter)==null||C.call(M,w,S)):(this._enterActiveRender={render:M,cellContext:w},(_=M.onPointerEnter)==null||_.call(M,w,S))}else this._enterActiveRender&&((E=(b=this._enterActiveRender.render).onPointerLeave)==null||E.call(b,this._enterActiveRender.cellContext,S),this._enterActiveRender=null)});h&&e.add(h),g&&e.add(g)}};this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i)),i(this._sheetSkeletonManagerService.getCurrent()),this.disposeWithMe(e)}};exports.CellCustomRenderController=mu([Lr(1,a.Inject(exports.SheetSkeletonManagerService)),Lr(2,y.IRenderManagerService),Lr(3,a.IPermissionService)],exports.CellCustomRenderController);class cs extends a.Disposable{constructor(){super(...arguments);T(this,"rangesStack",[]);T(this,"selectedRangeWorksheet","")}}var gu=Object.defineProperty,Su=Object.getOwnPropertyDescriptor,fu=(n,r,e,t)=>{for(var i=t>1?void 0:t?Su(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&gu(r,e,i),i},Gs=(n,r)=>(e,t)=>r(e,t,n);let _n=class{constructor(n,r){T(this,"_current",null);T(this,"_shortcutParam",[]);this._univerInstanceService=n,this._localeService=r}dispose(){this._shortcutParam=[]}getCurrentBySearch(n){return this._getCurrentBySearch(n)}getCurrent(){return this._getCurrentBySearch(this._current)}addOrUpdate(n){const r=this._getCurrentBySearch({unitId:n.unitId,sheetId:n.sheetId,keycode:n.keycode});if(r!=null){const e=this._shortcutParam.indexOf(r);this._shortcutParam.splice(e,1)}return this._shortcutParam.push(n),r}remove(n){if(n==null)return;const r=this._getCurrentBySearch(n);if(r==null)return;const e=this._shortcutParam.indexOf(r);return this._shortcutParam.splice(e,1)[0]}_getCurrentBySearch(n){return n==null?void 0:this._shortcutParam.find(e=>e.unitId===n.unitId&&e.sheetId===n.sheetId&&e.keycode===n.keycode)}};_n=fu([Gs(0,a.IUniverInstanceService),Gs(1,a.Inject(a.LocaleService))],_n);var Er=(n=>(n.MergeAll="mergeAll",n.MergeVertical="mergeVertical",n.MergeHorizontal="mergeHorizontal",n))(Er||{});function It(n,r,e,t,i=!0,o=1,s=!0){let l={...n};t==null&&(t={startRow:0,endRow:e.getRowCount()-1,startColumn:0,endColumn:e.getColumnCount()-1});let c;switch(r){case a.Direction.UP:for(c=n.startRow-o;c>-1&&!e.getRowVisible(c);)c-=1;c>=t.startRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.endRow,l.endRow=t.endRow,i&&(l=It(l,a.Direction.LEFT,e,t,!1)));break;case a.Direction.DOWN:for(c=n.endRow+o;c<e.getRowCount()&&!e.getRowVisible(c);)c+=1;c<=t.endRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.startRow,l.endRow=t.startRow,i&&(l=It(l,a.Direction.RIGHT,e,t,!1)));break;case a.Direction.LEFT:for(c=n.startColumn-o;c>-1&&!e.getColVisible(c);)c-=1;c>=t.startColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.endColumn,l.endColumn=t.endColumn,i&&(l=It(l,a.Direction.UP,e,t,!1)));break;case a.Direction.RIGHT:for(c=n.endColumn+o;c<e.getColumnCount()&&!e.getColVisible(c);)c+=1;c<=t.endColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.startColumn,l.endColumn=t.startColumn,i&&(l=It(l,a.Direction.DOWN,e,t,!1)));break}return l}function ds(n,r,e){const t={...n},{startRow:i,startColumn:o,endRow:s,endColumn:l}=Jn(n,r,e);let c=Hn(e,i,o,s,l).hasValue,d=!0,u=!0;for(;u;){if(a.Direction.UP===r){let h=t.startRow-1;for(;h>-1&&!e.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=Hn(e,h,t.startColumn,h,t.endColumn);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue(p=>{f=Math.min(p,f)}),t.startRow=f}else t.startRow=h;if(t.endRow=t.startRow,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.DOWN===r){let h=t.endRow+1;for(;h<e.getRowCount()&&!e.getRowVisible(h);)h+=1;if(h===e.getRowCount()){u=!1;break}const{hasValue:g,matrix:S}=Hn(e,h,t.startColumn,h,t.endColumn);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v,C)=>{f=Math.max(p+(C.rowSpan||1)-1,f)}),t.endRow=f}else t.endRow=h;if(t.startRow=t.endRow,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.LEFT===r){let h=t.startColumn-1;for(;h>-1&&!e.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=Hn(e,t.startRow,h,t.endRow,h);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v)=>{f=Math.min(v,f)}),t.startColumn=f}else t.startColumn=h;if(t.endColumn=t.startColumn,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.RIGHT===r){let h=t.endColumn+1;for(;h<e.getColumnCount()&&!e.getColVisible(h);)h+=1;if(h===e.getColumnCount()){u=!1;break}const{hasValue:g,matrix:S}=Hn(e,t.startRow,h,t.endRow,h);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v,C)=>{f=Math.max(v+(C.colSpan||1)-1,f)}),t.endColumn=f}else t.endColumn=h;if(t.startColumn=t.endColumn,!c&&g){u=!1;break}c=g,d=!1}}}return m.alignToMergedCellsBorders(t,e,!0)}function Xa(n,r,e){return It(n,r,e,void 0,!1,1,!1)}function pu(n,r,e){const t=ds(n,r,e);return m.alignToMergedCellsBorders(a.Rectangle.union(t,n),e,!0)}function vu(n,r,e){const t=Xa(n,r,e),i={startRow:Math.min(n.startRow,t.startRow),startColumn:Math.min(n.startColumn,t.startColumn),endRow:Math.max(n.endRow,t.endRow),endColumn:Math.max(n.endColumn,t.endColumn)};return m.alignToMergedCellsBorders(a.Rectangle.union(n,i),e)}function Cu(n,r,e,t){const i=a.getReverseDirection(e),o=ds(Jn(n,i,t),e,t);return e===a.Direction.UP&&o.startRow<=n.startRow?m.alignToMergedCellsBorders({...r,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.DOWN&&o.endRow>=n.endRow?m.alignToMergedCellsBorders({...r,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.LEFT&&o.startColumn<=n.startColumn?m.alignToMergedCellsBorders({...r,startRow:n.startRow,endRow:n.endRow},t,!0):e===a.Direction.RIGHT&&o.endColumn>=n.endColumn?m.alignToMergedCellsBorders({...r,startRow:n.startRow,endRow:n.endRow},t,!0):a.Rectangle.union(a.Rectangle.clone(r),o)}function Iu(n,r,e){const t=a.getReverseDirection(r),i=Jn(n,t,e),o=Jn(n,r,e),s=Xa(i,r,e);return m.alignToMergedCellsBorders(a.Rectangle.union(o,s),e,!1)}function Zs(n){return{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL}}function Jn(n,r,e){let t;switch(r){case a.Direction.UP:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.startRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.DOWN:t={startRow:n.endRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.LEFT:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.startColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.RIGHT:t={startRow:n.startRow,startColumn:n.endColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return m.alignToMergedCellsBorders(t,e,!1)}function Hn(n,r,e,t,i){let o=!1;const s=n.getMatrixWithMergedCells(r,e,t,i).forValue((l,c,d)=>{if(bu(d))return o=!0,!1});return{hasValue:o,matrix:s}}function ko(n,r,e){const t=a.Rectangle.clone(n);if(r==null)return t;switch(e){case a.Direction.UP:case a.Direction.DOWN:t.startColumn=t.endColumn=r.actualColumn;break;case a.Direction.LEFT:case a.Direction.RIGHT:t.startRow=t.endRow=r.actualRow;break}return t}function _u(n,r,e){var l,c,d,u;const{primary:t,range:i}=n,o=a.Rectangle.clone(i);switch(r){case a.Direction.UP:case a.Direction.DOWN:o.startRow=(l=t==null?void 0:t.startRow)!=null?l:i.startRow,o.endRow=(c=t==null?void 0:t.endRow)!=null?c:i.startRow;break;case a.Direction.LEFT:case a.Direction.RIGHT:o.startColumn=(d=t==null?void 0:t.startColumn)!=null?d:i.startColumn,o.endColumn=(u=t==null?void 0:t.endColumn)!=null?u:i.startColumn;break}const s=Jn(o,r,e);switch(r){case a.Direction.DOWN:return i.startRow<s.startRow;case a.Direction.UP:return i.endRow>s.endRow;case a.Direction.LEFT:return s.endColumn<i.endColumn;case a.Direction.RIGHT:return s.startColumn>i.startColumn}}function Ya(n,r){let e=n[0].startRow,t=n[0].endRow;n.forEach(o=>{const{startRow:s,endRow:l}=o;e=Math.min(e,s),t=Math.max(t,l)});const i=new Array(t-e+1).fill(!1);return r.forEach(o=>{const{startRow:s,endRow:l}=o;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)i[c-e]=!0}),n.every(o=>{const{startRow:s,endRow:l}=o;for(let c=s;c<=l;c++)if(!i[c-e])return!1;return!0})}function Ga(n,r){let e=n[0].startColumn,t=n[0].endColumn;n.forEach(o=>{const{startColumn:s,endColumn:l}=o;e=Math.min(e,s),t=Math.max(t,l)});const i=new Array(t-e+1).fill(!1);return r.forEach(o=>{const{startColumn:s,endColumn:l}=o;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)i[c-e]=!0}),n.every(o=>{const{startColumn:s,endColumn:l}=o;for(let c=s;c<=l;c++)if(!i[c-e])return!1;return!0})}function us(n,r){return r?n==="mergeAll"?r.filter(e=>!(e.startRow===e.endRow&&e.startColumn===e.endColumn)):n==="mergeVertical"?r.filter(e=>e.startRow!==e.endRow):n==="mergeHorizontal"?r.filter(e=>e.startColumn!==e.endColumn):r:null}function bu(n){return n.v!==void 0&&n.v!==null&&n.v!==""||n.p!==void 0}var $e=(n=>(n[n.moveStopeOne=0]="moveStopeOne",n[n.moveGap=1]="moveGap",n[n.moveStepPage=2]="moveStepPage",n[n.moveStepEnd=3]="moveStepEnd",n))($e||{});const xe={id:"sheet.command.move-selection",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:i}=e,o=m.getSelectionsService(n,r.fromCurrentSelection).getCurrentLastSelection();if(!o)return!1;const{direction:s,jumpOver:l,extra:c}=r,{range:d,primary:u}=o,h=ko(d,u,s),g=l===1?ds(h,s,i):It(h,s,i),S=m.getCellAtRowCol(g.startRow,g.startColumn,i);if(a.Rectangle.equals(S,h))return!1;const f=t.getUnitId();n.get(_n).remove({unitId:f,sheetId:i.getSheetId(),keycode:R.KeyCode.TAB});const p=[{range:a.Rectangle.clone(S),primary:{startRow:S.startRow,startColumn:S.startColumn,endRow:S.endRow,endColumn:S.endColumn,actualRow:g.startRow,actualColumn:g.startColumn,isMerged:S.isMerged,isMergedMainCell:S.startRow===g.startRow&&S.startColumn===g.startColumn}}];return n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:i.getSheetId(),selections:p,type:m.SelectionMoveType.MOVE_END,extra:c})}},et={id:"sheet.command.move-selection-enter-tab",type:a.CommandType.COMMAND,handler:(n,r)=>{var U;if(!r)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:i}=e,o=m.getSelectionsService(n),{direction:s,keycode:l}=r,c=s===a.Direction.LEFT||s===a.Direction.UP,d=o.getCurrentSelections().concat(),u=d.findIndex(F=>F.primary),h=d[u];if(!h)return!1;const g=c?-1:1,S=u+g!==d.length?d[u+g]:d[0],f=d.findIndex(F=>F===S),p=t.getUnitId(),v=i.getSheetId();if(!h)return!1;const{range:C}=h,_=h.primary;let b=ko(C,_,s);const E=n.get(_n),M=E.getCurrentBySearch({unitId:p,sheetId:v,keycode:R.KeyCode.TAB});let w;const{startRow:P,endRow:x,startColumn:A,endColumn:N}=C,D=c?_.startRow===P&&_.startColumn===A:_.endRow===x&&_.endColumn===N;if(a.Rectangle.equals(C,_)){if(l===R.KeyCode.TAB)M==null&&E.addOrUpdate({unitId:p,sheetId:v,keycode:R.KeyCode.TAB,selection:h});else{const W=M==null?void 0:M.selection;if(W!=null){const{range:j,primary:z}=W;b=ko(j,z,s)}E.remove({unitId:p,sheetId:v,keycode:R.KeyCode.TAB})}const F=It(b,s,i),L=m.getCellAtRowCol(F.startRow,F.startColumn,i);if(a.Rectangle.equals(L,b))return!1;w={range:a.Rectangle.clone(L),primary:{startRow:L.startRow,startColumn:L.startColumn,endRow:L.endRow,endColumn:L.endColumn,actualRow:F.startRow,actualColumn:F.startColumn,isMerged:L.isMerged,isMergedMainCell:L.startRow===F.startRow&&L.startColumn===F.startColumn}}}else{E.remove({unitId:p,sheetId:v,keycode:R.KeyCode.TAB});const F=a.Tools.deepClone(_),L=D?S.range:It({startRow:F.startRow,startColumn:F.startColumn,endRow:F.endRow,endColumn:F.endColumn},s,i,{startRow:P,endRow:x,startColumn:A,endColumn:N}),W=D&&c,j=W?m.getCellAtRowCol(L.endRow,L.endColumn,i):m.getCellAtRowCol(L.startRow,L.startColumn,i);w={range:D?S.range:a.Rectangle.clone(C),primary:{startRow:j.startRow,startColumn:j.startColumn,endRow:j.endRow,endColumn:j.endColumn,actualRow:W?j.startRow:L.startRow,actualColumn:W?j.startColumn:L.startColumn,isMerged:j.isMerged,isMergedMainCell:j.startRow===L.startRow&&j.startColumn===L.startColumn},style:D?S.style:h.style}}D?(d[u].primary=null,d[f]=w,o.setSelections(p,v,[],m.SelectionMoveType.MOVE_END)):d[u]=w;const k=n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:p,subUnitId:v,type:m.SelectionMoveType.MOVE_END,selections:d,extra:r.extra}),V=(U=n.get(y.IRenderManagerService).getRenderById(p))==null?void 0:U.with(_e);return V==null||V.refreshSelectionMoveEnd(),k}},ke={id:"sheet.command.expand-selection",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{worksheet:t,unitId:i,subUnitId:o}=e,s=m.getSelectionsService(n).getCurrentLastSelection();if(!s)return!1;const{range:l,primary:c}=s,{jumpOver:d,direction:u,extra:h}=r,S=_u(s,u,t)?d===1?Cu(l,{...a.Rectangle.clone(c),rangeType:a.RANGE_TYPE.NORMAL},u,t):Iu(l,u,t):d===1?pu(l,u,t):vu(l,u,t);return S.rangeType=s.range.rangeType,a.Rectangle.equals(S,l)?!1:n.get(a.ICommandService).syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:i,subUnitId:o,type:m.SelectionMoveType.ONLY_SET,selections:[{range:S,primary:c}],extra:h})}},Tr={id:"sheet.command.select-all",type:a.CommandType.COMMAND,handler:async(n,r={expandToGapFirst:!0,loop:!1})=>{const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const t=m.getSelectionsService(n).getCurrentLastSelection();if(!t)return!1;const i=n.get(cs),{worksheet:o,unitId:s,subUnitId:l}=e,c=`${s}|${l}`;c!==i.selectedRangeWorksheet&&(i.rangesStack=[],i.selectedRangeWorksheet=c);const d=o.getMaxRows(),u=o.getMaxColumns(),{expandToGapFirst:h,loop:g}=r,{range:S,primary:f}=t,p=S.endColumn===u-1&&S.endRow===d-1&&S.startRow===0&&S.startColumn===0;i.rangesStack.some(C=>a.Rectangle.equals(C,S))||(i.rangesStack=[],i.rangesStack.push(S));let v;if(p)if(g){if(i.rangesStack.findIndex(_=>a.Rectangle.equals(_,S))!==i.rangesStack.length-1)return!1;v=i.rangesStack[0]}else return!1;else h?(v=m.expandToContinuousRange(S,{left:!0,right:!0,up:!0,down:!0},o),a.Rectangle.equals(v,S)&&(v=Zs(o))):v=Zs(o);return i.rangesStack.some(C=>a.Rectangle.equals(C,v))||i.rangesStack.push(v),n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:s,subUnitId:l,selections:[{range:v,primary:f}]})}};var Ru=Object.defineProperty,Eu=Object.getOwnPropertyDescriptor,Tu=(n,r,e,t)=>{for(var i=t>1?void 0:t?Eu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&Ru(r,e,i),i},wu=(n,r)=>(e,t)=>r(e,t,n);exports.SheetScrollManagerService=class{constructor(r,e){T(this,"_scrollStateMap",new Map);T(this,"_rawScrollInfo$",new O.BehaviorSubject(null));T(this,"rawScrollInfo$",this._rawScrollInfo$.asObservable());T(this,"validViewportScrollInfo$",new O.BehaviorSubject(null));T(this,"_searchParamForScroll",null);this._context=r,this._sheetSkeletonManagerService=e}dispose(){this._rawScrollInfo$.complete()}setSearchParam(r){this._searchParamForScroll=r}setSearchParamAndRefresh(r){this._searchParamForScroll=r,this._scrollStateNext(r)}getScrollStateByParam(r){return this._getCurrentScroll(r)}getCurrentScrollState(){return this._getCurrentScroll(this._searchParamForScroll)}setScrollInfoAndEmitEvent(r){this._setScrollState(r),this._scrollStateNext(r)}setScrollStateToCurrSheet(r){this._searchParamForScroll!=null&&this._setScrollState({...this._searchParamForScroll,...r})}clear(){this._searchParamForScroll!=null&&this._clearByParamAndNotify(this._searchParamForScroll)}calcViewportScrollFromRowColOffset(r){if(!r)return{viewportScrollX:0,viewportScrollY:0};let{sheetViewStartColumn:e,sheetViewStartRow:t,offsetX:i,offsetY:o}=r;t=t||0,o=o||0;const s=this._sheetSkeletonManagerService.getCurrentSkeleton(),l=(s==null?void 0:s.rowHeightAccumulation[t-1])||0,d=((s==null?void 0:s.columnWidthAccumulation[e-1])||0)+i,u=l+o;return{viewportScrollX:d,viewportScrollY:u}}_setScrollState(r){const{unitId:e,sheetId:t,sheetViewStartColumn:i,sheetViewStartRow:o,offsetX:s,offsetY:l}=r;this._scrollStateMap.has(e)||this._scrollStateMap.set(e,new Map);const c=this._scrollStateMap.get(e),d={sheetViewStartRow:o,sheetViewStartColumn:i,offsetX:s,offsetY:l};c.set(t,d)}_clearByParamAndNotify(r){this._setScrollState({...r,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._scrollStateNext(r)}_getCurrentScroll(r){var s;const e={sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0};if(r==null)return e;const{unitId:t,sheetId:i}=r;return((s=this._scrollStateMap.get(t))==null?void 0:s.get(i))||e}_scrollStateNext(r){const e=this._getCurrentScroll(r);this._rawScrollInfo$.next(e)}};exports.SheetScrollManagerService=Tu([wu(1,a.Inject(exports.SheetSkeletonManagerService))],exports.SheetScrollManagerService);const qe={id:"sheet.operation.set-scroll",type:a.CommandType.OPERATION,handler:(n,r)=>{if(!r)return!1;const{unitId:e,sheetId:t,offsetX:i,offsetY:o,sheetViewStartColumn:s,sheetViewStartRow:l}=r;return n.get(y.IRenderManagerService).getRenderById(e).with(exports.SheetScrollManagerService).setScrollInfoAndEmitEvent({unitId:e,sheetId:t,offsetX:i,offsetY:o,sheetViewStartRow:l,sheetViewStartColumn:s}),!0}},bn={id:"sheet.command.set-scroll-relative",type:a.CommandType.COMMAND,handler:async(n,r)=>{const e=n.get(a.ICommandService),t=n.get(a.IUniverInstanceService),i=n.get(y.IRenderManagerService),o=m.getSheetCommandTarget(t);if(!o)return!1;const{unitId:s,subUnitId:l}=o,d=i.getRenderById(s).with(exports.SheetScrollManagerService).getCurrentScrollState(),{offsetX:u=0,offsetY:h=0}=r||{},{sheetViewStartRow:g=0,sheetViewStartColumn:S=0,offsetX:f=0,offsetY:p=0}=d||{};return e.executeCommand(qe.id,{unitId:s,sheetId:l,sheetViewStartRow:g,sheetViewStartColumn:S,offsetX:f+u,offsetY:p+h})}},Be={id:"sheet.command.scroll-view",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=n.get(a.IUniverInstanceService),t=n.get(y.IRenderManagerService),i=m.getSheetCommandTarget(e);if(!i)return!1;const{workbook:o,worksheet:s,unitId:l}=i,d=t.getRenderById(l).with(exports.SheetScrollManagerService).getCurrentScrollState();if(!s)return!1;const{sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:g,offsetY:S}=r,{sheetViewStartColumn:f,sheetViewStartRow:p,offsetX:v,offsetY:C}=d||{},{xSplit:_,ySplit:b}=i.worksheet.getConfig().freeze;return n.get(a.ICommandService).syncExecuteCommand(qe.id,{unitId:o.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:u!=null?u:p!=null?p:0+b,sheetViewStartColumn:h!=null?h:f!=null?f:0+_,offsetX:g!=null?g:v,offsetY:S!=null?S:C})}},hs={id:"sheet.command.scroll-to-cell",type:a.CommandType.COMMAND,handler:(n,r)=>{const e=n.get(a.IUniverInstanceService);return n.get(y.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(exports.SheetsScrollRenderController).scrollToRange(r.range,r.forceTop,r.forceLeft)}},yu={id:"sheet.command.scroll-view-reset",type:a.CommandType.COMMAND,handler:async n=>{const r=n.get(a.IUniverInstanceService),e=m.getSheetCommandTarget(r);if(!e)return!1;const{subUnitId:t,unitId:i}=e;return n.get(a.ICommandService).executeCommand(qe.id,{unitId:i,sheetId:t,sheetViewStartRow:0,sheetViewStartColumn:0})}};var Mu=Object.defineProperty,Pu=Object.getOwnPropertyDescriptor,Ou=(n,r,e,t)=>{for(var i=t>1?void 0:t?Pu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&Mu(r,e,i),i},en=(n,r)=>(e,t)=>r(e,t,n);const xu=[xe.id,et.id],Au=3;exports.SheetsScrollRenderController=class extends a.Disposable{constructor(r,e,t,i,o,s,l){super(),this._context=r,this._injector=e,this._sheetSkeletonManagerService=t,this._contextService=i,this._commandService=o,this._renderManagerService=s,this._scrollManagerService=l,this._initCommandListener(),this._wheelEventListener(),this._scrollBarEventListener(),this._initSkeletonListener()}_wheelEventListener(){const{scene:r}=this._context;if(!r)return;const e=r.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&this.disposeWithMe(r.onMouseWheel$.subscribeEvent((t,i)=>{if(t.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;let o=0,s=0;const l=e.limitedScroll();o=t.deltaX,t.shiftKey?o=(t.deltaY||t.deltaX)*Au:s=t.deltaY,this._commandService.executeCommand(bn.id,{offsetX:o,offsetY:s}),this._context.scene.makeDirty(!0),l&&!l.isLimitedX&&!l.isLimitedY&&(t.preventDefault(),r.getParent().classType===y.RENDER_CLASS_TYPE.SCENE_VIEWER&&i.stopPropagation()),e.isWheelPreventDefaultX&&e.isWheelPreventDefaultY&&t.preventDefault()}))}_scrollBarEventListener(){const{scene:r}=this._context;if(r==null)return;const e=r.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&(this.disposeWithMe(a.toDisposable(this._scrollManagerService.rawScrollInfo$.subscribe(t=>{var S;const i=(S=this._sheetSkeletonManagerService.getCurrent())==null?void 0:S.skeleton;if(!i)return;if(t==null){e.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});return}const{sheetViewStartRow:o,sheetViewStartColumn:s,offsetX:l,offsetY:c}=t,{startX:d,startY:u}=i.getCellWithCoordByIndex(o,s,!1),h=d+l,g=u+c;e.scrollToViewportPos({viewportScrollX:h,viewportScrollY:g})}))),this.disposeWithMe(e.onScrollAfter$.subscribeEvent(t=>{var p;const i=(p=this._sheetSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(i==null||t.isTrigger===!1)return;const o=this._getSheetObject();if(i==null||o==null)return;const{viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d}=t,{row:u,column:h,rowOffset:g,columnOffset:S}=i.getDecomposedOffset(s,l),f={sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:S,offsetY:g};this._scrollManagerService.setScrollStateToCurrSheet(f),this._scrollManagerService.validViewportScrollInfo$.next({...f,viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d})})),this.disposeWithMe(e.onScrollByBar$.subscribeEvent(t=>{var g;const i=(g=this._sheetSkeletonManagerService.getCurrent())==null?void 0:g.skeleton;if(i==null||t.isTrigger===!1)return;const o=this._getSheetObject();if(i==null||o==null)return;const{viewportScrollX:s=0,viewportScrollY:l=0}=t,{row:c,column:d,rowOffset:u,columnOffset:h}=i.getDecomposedOffset(s,l);this._commandService.executeCommand(Be.id,{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})})))}_initSkeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(r=>{if(r==null)return;const e={unitId:r.unitId,sheetId:r.sheetId};this._scrollManagerService.setSearchParam(e);const t=this._getSheetObject();if(!t)return;const o=t.scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=this._scrollManagerService.getScrollStateByParam(e),{viewportScrollX:l,viewportScrollY:c}=this._scrollManagerService.calcViewportScrollFromRowColOffset(s);o&&(s?(o.viewportScrollX=l,o.viewportScrollY=c):(o.viewportScrollX=0,o.viewportScrollY=0),this._updateSceneSize(r))})))}scrollToRange(r,e,t){let{endRow:i,endColumn:o,startColumn:s,startRow:l}=r;const c=this._getViewportBounding();if(r.rangeType===a.RANGE_TYPE.ROW?(s=0,o=0):r.rangeType===a.RANGE_TYPE.COLUMN&&(l=0,i=0),c&&!e&&!t){const d=c.startRow>i?l:i,u=c.startColumn>o?s:o;return this._scrollToCell(d,u)}else return this._scrollToCell(l,s,e,t)}scrollToCell(r,e){const t=this._context.unit.getActiveSheet(),{ySplit:i,xSplit:o}=t.getFreeze();return this._commandService.syncExecuteCommand(Be.id,{sheetViewStartRow:r-i,sheetViewStartColumn:e-o,offsetX:0,offsetY:0})}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(xu.includes(r.id))this._scrollToSelection();else if(r.id===m.ScrollToCellOperation.id){const e=r.params;this.scrollToRange(e)}else if(r.id===ke.id){const e=r.params;this._scrollToSelectionForExpand(e)}else r.id===m.SetSelectionsOperation.id&&r.params.reveal&&this._scrollToSelection()}))}_scrollToSelectionForExpand(r){setTimeout(()=>{const e=this._getSelectionsService().getCurrentLastSelection();if(e==null)return;const{startRow:t,startColumn:i,endRow:o,endColumn:s}=e.range,l=this._getViewportBounding();if(l==null)return;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=l;let g=0,S=0;t>c?g=o:o<u?g=t:g=c,i>d?S=s:s<h?S=i:S=d,r.direction===a.Direction.DOWN?g=o:r.direction===a.Direction.UP?g=t:r.direction===a.Direction.RIGHT?S=s:r.direction===a.Direction.LEFT&&(S=i),this._scrollToCell(g,S)},0)}_getFreeze(){var e;const r=(e=this._sheetSkeletonManagerService.getCurrent())==null?void 0:e.skeleton.getWorksheetConfig();if(r!=null)return r.freeze}_updateSceneSize(r){var g;if(r==null)return;const{unitId:e}=this._context,{skeleton:t}=r,i=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.scene;if(t==null||i==null)return;const{rowTotalHeight:o,columnTotalWidth:s,rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=t,u=this._context.unit.getActiveSheet();if(!u)return;const h=u.getZoomRatio()||1;i==null||i.setScaleValue(h,h),i==null||i.transformByState({width:l+s,height:c+o})}_getSheetObject(){return Xe(this._context.unit,this._context)}_scrollToSelectionByDirection(r){const e=this._getViewportBounding();if(e==null)return!1;const{startRow:t,startColumn:i,endRow:o,endColumn:s}=e;let l=0,c=0;const{startRow:d,startColumn:u,endRow:h,endColumn:g}=r;d>=t&&(l=h),h<=o&&(l=d),u>=i&&(c=g),g<=s&&(c=u),this._scrollToCell(l,c)}_scrollToSelection(r=!0){var d;const e=this._getSelectionsService().getCurrentLastSelection();if(!e)return;const{startRow:t,startColumn:i,actualRow:o,actualColumn:s}=(d=e.primary)!=null?d:e.range,l=r&&o!=null?o:t,c=r&&s!=null?s:i;this._scrollToCell(l,c)}_getSelectionsService(){return m.getSelectionsService(this._injector)}_getViewportBounding(){var o,s;const r=(o=this._getSheetObject())==null?void 0:o.scene;if(r==null)return;const e=r.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e==null)return;const t=(s=this._sheetSkeletonManagerService.getCurrent())==null?void 0:s.skeleton;if(t==null)return;const i=e.calcViewportInfo();return t.getRangeByViewBound(i.viewBound)}_scrollToCell(r,e,t=!1,i=!1){var N,D,k,B;const{rowHeightAccumulation:o,columnWidthAccumulation:s}=(D=(N=this._sheetSkeletonManagerService.getCurrent())==null?void 0:N.skeleton)!=null?D:{};if(o==null||s==null)return!1;const l=(k=this._getSheetObject())==null?void 0:k.scene;if(l==null)return!1;const c=l.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(c==null)return!1;const d=(B=this._sheetSkeletonManagerService.getCurrent())==null?void 0:B.skeleton;if(d==null)return!1;const u=this._context.unit.getActiveSheet();if(!u)return!1;r=a.Tools.clamp(r,0,o.length-1),e=a.Tools.clamp(e,0,s.length-1);const{startColumn:h,startRow:g,ySplit:S,xSplit:f}=u.getFreeze(),p=this._getViewportBounding();if(p==null)return!1;const{startRow:v,startColumn:C,endRow:_,endColumn:b}=p;d.getVisibleRangeByViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);let E,M;if(r>=g&&e>=h-S&&(r<=v&&(E=r,t=!0),r>=_)){const V=o[r]-c.height;for(let U=v;U<=r&&(E=U+1,!(o[U]>=V));U++);}if(e>=h&&r>=g-S&&(e<=C&&(M=e,i=!0),e>=b)){const V=s[e]-c.width;for(let U=C;U<=e&&(M=U+1,!(s[U]>=V));U++);}if(E===void 0&&M===void 0)return!1;let{offsetX:w,offsetY:P,sheetViewStartRow:x,sheetViewStartColumn:A}=this._scrollManagerService.getCurrentScrollState()||{};if(E=E?Math.min(E,r):x+S,M=M?Math.min(M,e):A+f,i){w=0,M=e;const V=d.getHiddenColumnsInRange({startColumn:M-f,endColumn:M});M=M-V.length}if(t){P=0,E=r;const V=d.getHiddenRowsInRange({startRow:E-S,endRow:E});E=E-V.length}return this._commandService.syncExecuteCommand(Be.id,{sheetViewStartRow:Math.max(0,E-S),sheetViewStartColumn:Math.max(0,M-f),offsetX:w,offsetY:P})}};exports.SheetsScrollRenderController=Ou([en(1,a.Inject(a.Injector)),en(2,a.Inject(exports.SheetSkeletonManagerService)),en(3,a.IContextService),en(4,a.ICommandService),en(5,y.IRenderManagerService),en(6,a.Inject(exports.SheetScrollManagerService))],exports.SheetsScrollRenderController);const ms={id:"sheet.operation.scroll-to-range",type:a.CommandType.OPERATION,handler:(n,r)=>{if(!r)return!1;const e=n.get(a.IUniverInstanceService);return n.get(y.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(exports.SheetsScrollRenderController).scrollToRange(r.range,r.forceTop,r.forceLeft)}};class Za{constructor(){T(this,"_state",null);T(this,"_rect",null);T(this,"_state$",new O.BehaviorSubject(null));T(this,"state$",this._state$.asObservable());T(this,"_rect$",new O.BehaviorSubject(null));T(this,"rect$",this._rect$.asObservable());T(this,"_focus",!1);T(this,"_focus$",new O.BehaviorSubject(this._focus));T(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(r){this._state=r,this._refresh(r)}getRect(){return this._rect}setRect(r){this._rect=r,this._rect$.next(r)}getState(){return this._state}setFocus(r=!1){this._focus=r,this._focus$.next(r)}_refresh(r){this._state$.next(r)}}const ui=a.createIdentifier("univer.sheet-cell-editor-manager.service"),Nu="36",Du="univer-sheet-container",Ka={sheetFooterBarHeight:Nu,sheetContainer:Du};var ku=Object.defineProperty,Vu=Object.getOwnPropertyDescriptor,Hu=(n,r,e,t)=>{for(var i=t>1?void 0:t?Vu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&ku(r,e,i),i},tn=(n,r)=>(e,t)=>r(e,t,n);const Ks=5,qs=2;exports.SheetCellEditorResizeService=class extends a.Disposable{constructor(r,e,t,i,o,s,l){super(),this._context=r,this._layoutService=e,this._cellEditorManagerService=t,this._editorBridgeService=i,this._renderManagerService=o,this._sheetSkeletonManagerService=s,this._univerInstanceService=l}fitTextSize(r){var A,N,D,k;const e=this._editorBridgeService.getEditCellState();if(!e)return;const{position:t,documentLayoutObject:i,canvasOffset:o,scaleX:s,scaleY:l}=e,{startX:c,startY:d,endX:u,endY:h}=t,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);if(g==null)return;const S=this._getEditorSkeleton();if(!S)return;const f=this._predictingSize(t,o,S,i,s,l);if(!f)return;let{actualWidth:p,actualHeight:v}=f;const{verticalAlign:C,horizontalAlign:_,paddingData:b,fill:E}=i;p=p+((A=b.l)!=null?A:0)+((N=b.r)!=null?N:0),v=v+((D=b.t)!=null?D:0)+((k=b.b)!=null?k:0);let M=u-c,w=h-d;M<p&&(M=Math.ceil(p)),w<v&&(w=Math.ceil(v));let P=0;C===a.VerticalAlign.MIDDLE?P=(w-v)/2/l:C===a.VerticalAlign.TOP?P=b.t||0:P=(w-v)/l;let x=0;_===a.HorizontalAlign.CENTER?x=(M-p)/2/s:_===a.HorizontalAlign.RIGHT?x=(M-p)/s:x=b.l||0,P=P<(b.t||0)?b.t||0:P,x=x<(b.l||0)?b.l||0:x,g.updateDocumentDataMargin({t:P,l:x}),S.calculate(),this._editAreaProcessing(M,w,t,o,E,s,l,_,r)}_predictingSize(r,e,t,i,o=1,s=1){const{startX:l,endX:c}=r,{textRotation:d,wrapStrategy:u,paddingData:h}=i,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC),{vertexAngle:S}=y.convertTextRotation(d);if(u===a.WrapStrategy.WRAP&&S===0){g==null||g.updateDocumentDataPageSize(c-l),g==null||g.updateDocumentDataMargin({l:h.l,t:h.t}),t.calculate();const{actualWidth:C,actualHeight:_}=t.getActualSize();return{actualWidth:C*o,actualHeight:_*s}}const f=this._getEditorMaxSize(r,e,i.horizontalAlign);if(!f)return;g==null||g.updateDocumentDataPageSize(f.width/o),t.calculate();const p=t.getActualSize();let v=c-l;return v<p.actualWidth*o+Ks*o&&(v=p.actualWidth*o+Ks*o),g==null||g.updateDocumentDataPageSize(v/o),g==null||g.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED,cellValueType:void 0}),{actualWidth:p.actualWidth*o,actualHeight:p.actualHeight*s}}_getEditorMaxSize(r,e,t){if(this._getEditorObject()==null)return;function o(_){return Number.parseInt(_.replace("px",""))}const l=this._context.engine.getCanvasElement(),c=l.getBoundingClientRect(),d=o(l.style.width),{width:u}=c,h=u/d,{startX:g,startY:S,endX:f}=r,p=this._context.engine.width,v=document.body.clientHeight-S-Number.parseFloat(Ka.sheetFooterBarHeight)-e.top-qs*2;let C=u-g;if(t===a.HorizontalAlign.CENTER){const _=p-f,b=g;C=f-g+Math.min(b,_)*2}else t===a.HorizontalAlign.RIGHT&&(C=f);return{height:v,width:C-qs,scaleAdjust:h}}_editAreaProcessing(r,e,t,i,o,s=1,l=1,c,d){var V;const u=this._getEditorObject();if(u==null)return;const g=this._context.engine.getCanvasElement();let{startX:S,startY:f}=t;const{document:p,scene:v,engine:C}=u,_=v.getViewport(J.VIEWPORT_KEY.VIEW_MAIN),b=this._getEditorMaxSize(t,i,c),{height:E,width:M,scaleAdjust:w}=b;let P=e,x=_==null?void 0:_.getScrollBar();P>E?(x==null?_&&new y.ScrollBar(_,{enableHorizontal:!1,barSize:8}):_==null||_.resetCanvasSizeAndUpdateScroll(),_==null||_.scrollToViewportPos({viewportScrollY:P-E}),P=E):(x=null,(V=_==null?void 0:_.getScrollBar())==null||V.dispose()),r+=(x==null?void 0:x.barSize)||0,r>M&&(r=M),this._addBackground(v,r/s,e/l,o);const{scaleX:A,scaleY:N}=v.getPrecisionScale();v.transformByState({width:r*w/s,height:e*w/l,scaleX:s*w,scaleY:l*w}),p.resize(r*w/s,e*w/l),setTimeout(()=>{C.resizeBySize(y.fixLineWidthByScale(r,A),y.fixLineWidthByScale(P,N)),d==null||d()},0);const D=this._layoutService.getContentElement().getBoundingClientRect(),k=g.getBoundingClientRect();S=S*w+(k.left-D.left),f=f*w+(k.top-D.top);const B=t.endX-t.startX;c===a.HorizontalAlign.RIGHT?S+=(B-r)*w:c===a.HorizontalAlign.CENTER&&(S+=(B-r*w)/2),this._cellEditorManagerService.setState({startX:S,startY:f,endX:r*w+S,endY:P*w+f,show:!0})}_addBackground(r,e,t,i){const o="_backgroundRectHelperColor_",s=r.getObject(o);s==null&&i==null||(s==null?r.addObjects([new y.Rect(o,{width:e,height:t,fill:i,evented:!1})],J.DOCS_COMPONENT_MAIN_LAYER_INDEX):i==null?s.dispose():(s.setProps({fill:i}),s.transformByState({width:e,height:t})))}resizeCellEditor(r){var w;const e=this._cellEditorManagerService.getState();if(!e||!this._editorBridgeService.isVisible().visible)return;this._editorBridgeService.refreshEditCellPosition(!0);const t=this._editorBridgeService.getEditCellState();if(!t)return;const i=(w=this._sheetSkeletonManagerService.getWorksheetSkeleton(t.sheetId))==null?void 0:w.skeleton;if(!i)return;const{row:o,column:s,scaleX:l,scaleY:c,position:d,canvasOffset:u,documentLayoutObject:h}=t,{horizontalAlign:g}=h,S=this._getEditorMaxSize(d,u,g);if(!S)return;const{height:f,width:p,scaleAdjust:v}=S,C=i.getCellWithCoordByIndex(o,s),_=Math.min((C.mergeInfo.endY-C.mergeInfo.startY)*c,f)*v,b=Math.min((C.mergeInfo.endX-C.mergeInfo.startX)*l,p)*v,E=e.endY-e.startY,M=e.endX-e.startX;if(E!==_||M!==b){if(this._editorBridgeService.refreshEditCellPosition(!0),!this._getEditorSkeleton())return;this.fitTextSize(r)}}_getEditorObject(){return _r(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_getEditorSkeleton(){var r;return(r=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:r.with(Ie.DocSkeletonManagerService).getSkeleton()}};exports.SheetCellEditorResizeService=Hu([tn(1,R.ILayoutService),tn(2,ui),tn(3,he),tn(4,y.IRenderManagerService),tn(5,a.Inject(exports.SheetSkeletonManagerService)),tn(6,a.IUniverInstanceService)],exports.SheetCellEditorResizeService);function gs(n){return n.getContextValue(a.FOCUSING_SHEET)}function ae(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function qa(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function Wu(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function Uu(n){return n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function Qa(n){return n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Lu(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.EDITOR_ACTIVATED)&&n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function $n(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!n.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}const Ja=[R.KeyCode.ARROW_DOWN,R.KeyCode.ARROW_UP,R.KeyCode.ARROW_LEFT,R.KeyCode.ARROW_RIGHT],Bu=[R.KeyCode.ENTER,R.KeyCode.TAB,...Ja];function $a(){const n=[];for(const r of Ja)n.push({id:Ft.id,binding:r,preconditions:e=>$n(e),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:r,isShift:!1}}),n.push({id:Ft.id,binding:r|R.MetaKeys.SHIFT,preconditions:e=>$n(e),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:r,isShift:!0}});return n}const el={id:di.id,binding:R.KeyCode.F2,description:"shortcut.sheet.start-editing",group:"4_sheet-edit",preconditions:ae,staticParameters:{visible:!0,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.F2}},tl={id:Me.id,binding:R.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:n=>$n(n),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.ENTER}},nl={id:Me.id,binding:R.KeyCode.TAB,preconditions:n=>$n(n),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.TAB}},il={id:Me.id,binding:R.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:n=>$n(n),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.ESC}},rl={id:J.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:n=>Wu(n),binding:R.KeyCode.ENTER|R.MetaKeys.ALT},ol={id:J.DeleteLeftCommand.id,preconditions:n=>Uu(n)||Qa(n),binding:R.KeyCode.BACKSPACE},sl={id:Me.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:n=>ae(n)&&!Qa(n),binding:R.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.BACKSPACE}};function Fu(n){return n.startsWith("'")}function ju(n){return n.slice(1)}const zu={"0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9",A:"A",B:"B",C:"C",D:"D",E:"E",F:"F",G:"G",H:"H",I:"I",J:"J",K:"K",L:"L",M:"M",N:"N",O:"O",P:"P",Q:"Q",R:"R",S:"S",T:"T",U:"U",V:"V",W:"W",X:"X",Y:"Y",Z:"Z",a:"a",b:"b",c:"c",d:"d",e:"e",f:"f",g:"g",h:"h",i:"i",j:"j",k:"k",l:"l",m:"m",n:"n",o:"o",p:"p",q:"q",r:"r",s:"s",t:"t",u:"u",v:"v",w:"w",x:"x",y:"y",z:"z","%":"%","-":"-",".":".",":":":","/":"/","+":"+","@":"@","&":"&","*":"*","#":"#","=":"=",">":">","<":"<","$":"$",""":'"',"'":"'","(":"(",")":")"," ":" ",",":",","!":"!","?":"?",";":";","[":"[","]":"]","{":"{","}":"}"},Vo={true:"TRUE",false:"FALSE"};function Xu(n){return[a.LocaleType.ZH_CN,a.LocaleType.ZH_TW].includes(n)}function Yu(n,r,e,t){let i=n;if(Xu(e)){if(n.startsWith("'")||n.startsWith("'"))return`'${n.slice(1)}`;i=Gu(i)}if(i.startsWith("="))return Zu(n,i,r,t);const o=i.toLowerCase();return Vo[o]?Vo[o]:a.numfmt.parseValue(i)==null?n:i}function Gu(n){const r=/['"].*?['"]/g,e=[],t=n.split(r);n.replace(r,o=>(e.push(o),""));let i=t.join("").split("").map(Qu).join("");return e.forEach((o,s)=>{i=i.slice(0,s*2)+o+i.slice((s+1)*2)}),i}function Zu(n,r,e,t){const i=e.sequenceNodesBuilder(r);if(!i)return n;let o=r,s=0;return i.forEach((l,c)=>{if(typeof l=="object"){const d=l.token;if(Vo[d.toLowerCase()]){const u=l.startIndex+s+1,h=l.endIndex+s+2;o=nn(d.toLocaleUpperCase(),o,u,h)}else if(l.nodeType===G.sequenceNodeType.FUNCTION&&Ku(d,t,i,c)||l.nodeType===G.sequenceNodeType.REFERENCE){const u=d.indexOf("!");if(u>-1){const h=d.substring(u+1),g=l.startIndex+s+(u+1)+1,S=l.endIndex+s+2;o=nn(h.toLocaleUpperCase(),o,g,S)}else{const h=l.startIndex+s+1,g=l.endIndex+s+2;o=nn(d.toLocaleUpperCase(),o,h,g)}}else if(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'")){const u=l.startIndex+s+2,h=l.endIndex+s+1;o=nn(n.slice(u,h),o,u,h)}else if(l.nodeType!==G.sequenceNodeType.ARRAY){const u=a.numfmt.parseValue(d);if(u==null){const h=l.startIndex+s+1,g=l.endIndex+s+2;o=nn(n.slice(h,g),o,h,g)}else if(typeof u.v=="number"&&(u.z===void 0||!a.numfmt.isDate(u.z))){const h=`${u.v}`,g=l.startIndex+s+1,S=l.endIndex+s+2,{processedString:f,offset:p}=Ju(d,h);o=nn(f,o,g,S),s+=p}}}}),o}function Ku(n,r,e,t){const i=r.getDescriptions();return e[t+1]!==G.matchToken.OPEN_BRACKET?!1:i.get(qu(n).toLocaleUpperCase())!==void 0}function qu(n){const r=/^@+/;return n.replace(r,"")}function Qu(n){return zu[n]||n}function nn(n,r,e,t){return r.substring(0,e)+n+r.substring(t)}function Ju(n,r){var s,l;const e=((s=n.match(/^\s*/))==null?void 0:s[0])||"",t=((l=n.match(/\s*$/))==null?void 0:l[0])||"",i=e+r+t,o=i.length-n.length;return{processedString:i,offset:o}}const al="range_selector",ll=n=>n.includes(al);var $u=Object.defineProperty,eh=Object.getOwnPropertyDescriptor,th=(n,r,e,t)=>{for(var i=t>1?void 0:t?eh(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&$u(r,e,i),i},we=(n,r)=>(e,t)=>r(e,t,n);const Qs=-1e3;exports.EditingRenderController=class extends a.Disposable{constructor(e,t,i,o,s,l,c,d,u,h,g,S,f,p,v,C){super();T(this,"_cursorChange",0);T(this,"_isUnitEditing",!1);T(this,"_workbookSelections");T(this,"_d");T(this,"_cursorTimeout");this._context=e,this._undoRedoService=i,this._contextService=o,this._renderManagerService=s,this._editorBridgeService=l,this._cellEditorManagerService=c,this._lexerTreeBuilder=d,this._functionService=u,this._textSelectionManagerService=h,this._commandService=g,this._localService=S,this._editorService=f,this._sheetCellEditorResizeService=p,this._univerInstanceService=v,this._sheetInterceptorService=C,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(_=>{(_==null?void 0:_.getUnitId())===this._context.unitId?this._d=this._init():(this._disposeCurrent(),this._isUnitEditing&&(this._handleEditorInvisible({visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.ESC,unitId:this._context.unitId}),this._isUnitEditing=!1))})),this._initEditorVisibilityListener()}dispose(){super.dispose(),this._disposeCurrent()}_disposeCurrent(){var e;(e=this._d)==null||e.dispose(),this._d=null}_init(){const e=new a.DisposableCollection;return this._subscribeToCurrentCell(e),this._initialCursorSync(e),this._listenEditorFocus(e),this._commandExecutedListener(e),this._initSkeletonListener(e),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{clearTimeout(this._cursorTimeout)})),this._cursorTimeout=setTimeout(()=>{this._cursorStateListener(e)},1e3),e}_initEditorVisibilityListener(){this.disposeWithMe(this._editorBridgeService.visible$.pipe(O.distinctUntilChanged((e,t)=>e.visible===t.visible)).subscribe(e=>{(e.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY||e.unitId===this._context.unitId)&&e.visible?(this._isUnitEditing=!0,this._handleEditorVisible(e)):this._isUnitEditing&&(this._handleEditorInvisible(e),this._isUnitEditing=!1)}))}_listenEditorFocus(e){const t=this._getEditorObject();t&&e.add(t.document.onPointerDown$.subscribeEvent(()=>{if(this._isUnitEditing&&this._editorBridgeService.isVisible()){const i=this._editorBridgeService.getEditCellState(),o=this._editorBridgeService.getCurrentEditorId();if(!i||!o)return;this._sheetCellEditorResizeService.fitTextSize()}}))}_initialCursorSync(e){e.add(this._cellEditorManagerService.focus$.pipe(O.filter(t=>!!t)).subscribe(()=>{var i;const t=(i=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_DOC))==null?void 0:i.with(J.DocSelectionRenderService);t&&t.sync()}))}_initSkeletonListener(e){const t=new Set(m.COMMAND_LISTENER_SKELETON_CHANGE);t.delete(m.SetWorksheetActiveOperation.id),e.add(this._commandService.onCommandExecuted(i=>{t.has(i.id)&&this._sheetCellEditorResizeService.resizeCellEditor(()=>{this._textSelectionManagerService.refreshSelection({unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})})}))}_subscribeToCurrentCell(e){e.add(this._editorBridgeService.currentEditCellState$.subscribe(t=>{var _,b;if(t==null||this._editorBridgeService.isForceKeepVisible())return;const i=this._editorBridgeService.getEditCellState();if(i==null)return;const{position:o,documentLayoutObject:s,scaleX:l,editorUnitId:c}=i;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE))return;const d=this._getDocumentDataModel();if(d==null)return;const{startX:u,endX:h}=o,{textRotation:g,wrapStrategy:S,documentModel:f}=s,{vertexAngle:p}=y.convertTextRotation(g);S===a.WrapStrategy.WRAP&&p===0&&d.updateDocumentDataPageSize((h-u)/l),this._commandService.syncExecuteCommand(J.ReplaceSnapshotCommand.id,{unitId:c,snapshot:f.getSnapshot()}),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const v=(_=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:_.with(J.DocSelectionRenderService),C=(b=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:b.with(J.DocSelectionRenderService);(v!=null&&v.canFocusing||C!=null&&C.canFocusing)&&(this._univerInstanceService.setCurrentUnitForType(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),v==null||v.activate(Qs,Qs,!0))}))}_commandExecutedListener(e){e.add(this._commandService.onCommandExecuted(i=>{if(i.id===Ie.RichTextEditingMutation.id){const o=i.params,{unitId:s}=o;if(!this._isCurrentSheetFocused()||ll(s)||(this._editorBridgeService.changeEditorDirty(!0),!this._editorBridgeService.isVisible().visible))return;s===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetCellEditorResizeService.fitTextSize()}}));const t=[Ft.id];e.add(this._commandService.onCommandExecuted(i=>{if(t.includes(i.id)){const o=i.params,{keycode:s,isShift:l}=o;if(s!=null&&(this._cursorChange===2||this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR))){this._moveInEditor(s,l);return}this._editorBridgeService.changeVisible(o)}i.id===di.id&&(this._cursorChange=2)}))}_handleEditorVisible(e){var S,f,p;const{eventType:t,keycode:i}=e;this._cursorChange=t===y.DeviceInputEventType.PointerDown||t===y.DeviceInputEventType.Dblclick?2:1;const o=this._editorBridgeService.getEditLocation();if(o==null)return;this._commandService.syncExecuteCommand(ms.id,{range:{startRow:o.row,startColumn:o.column,endRow:o.row,endColumn:o.column}}),this._editorBridgeService.refreshEditCellPosition(!1);const{unitId:s,isInArrayFormulaRange:l=!1}=o,c=this._getEditorObject();if(c==null)return;const{document:d,scene:u}=c;this._contextService.setContextValue(a.EDITOR_ACTIVATED,!0);const h=this._getDocumentDataModel(),g=this._getEditorSkeleton(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!(!g||!h)){if(this._sheetCellEditorResizeService.fitTextSize(()=>{const v=u.getViewport(J.VIEWPORT_KEY.VIEW_MAIN);v==null||v.scrollToViewportPos({viewportScrollX:Number.POSITIVE_INFINITY,viewportScrollY:Number.POSITIVE_INFINITY})}),t===y.DeviceInputEventType.Keyboard&&i===R.KeyCode.F2){d.makeDirty(),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}]);const v=((f=(S=h.getBody())==null?void 0:S.dataStream.length)!=null?f:2)-2;this._textSelectionManagerService.replaceDocRanges([{startOffset:v,endOffset:v}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})}else if(t===y.DeviceInputEventType.Keyboard||t===y.DeviceInputEventType.Dblclick&&l)this._emptyDocumentDataModel(h.getSnapshot().documentStyle,!!l),d.makeDirty(),(i===R.KeyCode.BACKSPACE||t===y.DeviceInputEventType.Dblclick)&&(g.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});else if(t===y.DeviceInputEventType.Dblclick){if(this._contextService.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA))return;const v=h.getBody().dataStream.length-2||0;this._textSelectionManagerService.replaceDocRanges([{startOffset:v,endOffset:v}])}(p=this._renderManagerService.getRenderById(s))==null||p.scene.resetCursor()}}async _handleEditorInvisible(e){const t=this._editorBridgeService.getEditCellState(),i=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),o=a.Tools.deepClone(i==null?void 0:i.getSnapshot());let{keycode:s}=e;if(this._cursorChange=0,this._exitInput(e),t==null)return;this._editorBridgeService.getEditorDirty()===!1&&(s=R.KeyCode.ESC);const d=this._context.unit.getActiveSheet(),u=this._context.unitId,h=d.getSheetId(),{unitId:g,sheetId:S}=t;if(u===g&&S!==h&&await this._commandService.executeCommand(m.SetWorksheetActivateCommand.id,{subUnitId:S,unitId:g}),s===R.KeyCode.ESC){this._editorBridgeService.isForceKeepVisible()&&this._editorBridgeService.disableForceKeepVisible();const f=this._workbookSelections.getCurrentSelections();f&&(this._contextService.setContextValue(m.REF_SELECTIONS_ENABLED,!1),this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:this._context.unit.getUnitId(),subUnitId:S,selections:f}));return}o&&await this._submitCellData(o),this._moveCursor(s)}_getEditorObject(){return _r(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}submitCellData(e){return this._submitCellData(e.getSnapshot())}async _submitCellData(e){const t=this._editorBridgeService.getEditCellState();if(t==null)return;const{unitId:i,sheetId:o,row:s,column:l}=t,c=this._context.unit;let d=c.getActiveSheet();if(!c.getSheetBySheetId(o))return;d=c.getActiveSheet();const h=nh({...d.getCellRaw(s,l)||{}},e,this._lexerTreeBuilder,this._localService,this._functionService,c.getStyles());if(!h)return;const g=await this._sheetInterceptorService.onWriteCell(c,d,s,l,h);this._commandService.executeCommand(m.SetRangeValuesCommand.id,{subUnitId:o,unitId:i,range:{startRow:s,startColumn:l,endRow:s,endColumn:l},value:g})}_exitInput(e){var o;this._contextService.setContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!1),this._cellEditorManagerService.setState({show:e.visible});const t=this._getEditorObject();(o=t==null?void 0:t.scene.getViewport(J.VIEWPORT_KEY.VIEW_MAIN))==null||o.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});const i=this._editorBridgeService.getCurrentEditorId();i==null||!this._editorService.isSheetEditor(i)||(this._undoRedoService.clearUndoRedo(i),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveCursor(e){if(e==null||!Bu.includes(e))return;let t=a.Direction.LEFT;switch(e){case R.KeyCode.ENTER:t=a.Direction.DOWN;break;case R.KeyCode.TAB:t=a.Direction.RIGHT;break;case R.KeyCode.ARROW_DOWN:t=a.Direction.DOWN;break;case R.KeyCode.ARROW_UP:t=a.Direction.UP;break;case R.KeyCode.ARROW_LEFT:t=a.Direction.LEFT;break;case R.KeyCode.ARROW_RIGHT:t=a.Direction.RIGHT;break}e===R.KeyCode.ENTER||e===R.KeyCode.TAB?this._commandService.executeCommand(et.id,{keycode:e,direction:t}):this._commandService.executeCommand(xe.id,{direction:t})}_cursorStateListener(e){const t=this._getEditorObject();if(!(t!=null&&t.document))return;const{document:i}=t;e.add(a.toDisposable(i.onPointerDown$.subscribeEvent(()=>{this._cursorChange===1&&(this._cursorChange=2)})))}_moveInEditor(e,t){let i=a.Direction.LEFT;e===R.KeyCode.ARROW_DOWN?i=a.Direction.DOWN:e===R.KeyCode.ARROW_UP?i=a.Direction.UP:e===R.KeyCode.ARROW_RIGHT&&(i=a.Direction.RIGHT),t?this._commandService.executeCommand(J.MoveSelectionOperation.id,{direction:i}):this._commandService.executeCommand(J.MoveCursorOperation.id,{direction:i})}_getDocumentDataModel(){return this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC)}_isCurrentSheetFocused(){var e;return((e=this._univerInstanceService.getFocusedUnit())==null?void 0:e.getUnitId())===this._context.unitId}_getEditorSkeleton(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(Ie.DocSkeletonManagerService).getSkeleton()}_getEditorViewModel(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(Ie.DocSkeletonManagerService).getViewModel()}_emptyDocumentDataModel(e,t){const i=(l,c)=>{const d=a.Tools.deepClone(l.getSnapshot()),u=this._getEditorViewModel(l.getUnitId());u!=null&&(ih(d.body,t),c&&(d.documentStyle=e),d.drawings={},d.drawingsOrder=[],l.reset(d),u.reset(l))},o=this._getDocumentDataModel();o&&i(o,!0);const s=this._univerInstanceService.getUnit(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);s&&i(s)}};exports.EditingRenderController=th([we(1,a.Inject(m.SheetsSelectionsService)),we(2,a.IUndoRedoService),we(3,a.IContextService),we(4,y.IRenderManagerService),we(5,he),we(6,ui),we(7,a.Inject(G.LexerTreeBuilder)),we(8,G.IFunctionService),we(9,a.Inject(Ie.DocSelectionManagerService)),we(10,a.ICommandService),we(11,a.Inject(a.LocaleService)),we(12,J.IEditorService),we(13,a.Inject(exports.SheetCellEditorResizeService)),we(14,a.IUniverInstanceService),we(15,a.Inject(m.SheetInterceptorService))],exports.EditingRenderController);function nh(n,r,e,t,i,o){var h,g,S;if((r==null?void 0:r.body)==null)return null;const{body:s}=r;n.t=void 0;const l=s.dataStream;let d=l.substring(l.length-2,l.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?l.substring(0,l.length-2):l;const u=t.getCurrentLocale();if(d=Yu(d,e,u,i),(h=r.drawingsOrder)!=null&&h.length)n.v="",n.f=null,n.si=null,n.p=r,n.t=a.CellValueType.STRING;else if(n.s&&((S=(g=o==null?void 0:o.get(n.s))==null?void 0:g.n)==null?void 0:S.pattern)===dd.DEFAULT_TEXT_FORMAT){n.v=d,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.STRING,Ho(s)&&s.dataStream!==`\r
1
+ "use strict";var ld=Object.defineProperty;var cd=(n,r,e)=>r in n?ld(n,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[r]=e;var T=(n,r,e)=>cd(n,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("@univerjs/docs-ui"),a=require("@univerjs/core"),y=require("@univerjs/engine-render"),R=require("@univerjs/ui"),H=require("react"),O=require("rxjs"),m=require("@univerjs/sheets"),Ie=require("@univerjs/docs"),G=require("@univerjs/engine-formula"),dd=require("@univerjs/engine-numfmt"),K=require("@univerjs/design"),ud=require("@univerjs/telemetry"),La=require("rxjs/operators");function _r(n,r){if(n==null)return;const e=r.getRenderById(n);if(e==null)return;const{mainComponent:t,scene:i,engine:o,components:s}=e,l=t,c=s.get(J.DOCS_VIEW_KEY.BACKGROUND);return{document:l,docBackground:c,scene:i,engine:o}}function vn(n,r){const{startRow:e,startColumn:t,endRow:i,endColumn:o,rangeType:s}=r,l=i<e?i:e,c=i<e?e:i,d=o<t?o:t,u=o<t?t:o,h=n.getNoMergeCellPositionByIndex(l,d),g=n.getNoMergeCellPositionByIndex(c,u);return{startRow:e,startColumn:t,endRow:i,endColumn:o,rangeType:s,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}function ye(n,r){const{range:e,primary:t,style:i}=n,o=vn(r,e),s=t&&qn(r,t);return{rangeWithCoord:o,primaryWithCoord:s,style:i}}function qn(n,r){const{actualRow:e,actualColumn:t,isMerged:i,isMergedMainCell:o,startRow:s,startColumn:l,endRow:c,endColumn:d}=r,u=n.getNoMergeCellPositionByIndex(e,t),h=n.getNoMergeCellPositionByIndex(s,l),g=n.getNoMergeCellPositionByIndex(c,d);return{actualRow:e,actualColumn:t,isMerged:i,isMergedMainCell:o,startX:u.startX,startY:u.startY,endX:u.endX,endY:u.endY,mergeInfo:{startRow:s,startColumn:l,endRow:c,endColumn:d,startY:(h==null?void 0:h.startY)||0,endY:(g==null?void 0:g.endY)||0,startX:(h==null?void 0:h.startX)||0,endX:(g==null?void 0:g.endX)||0}}}var hd=Object.defineProperty,md=Object.getOwnPropertyDescriptor,gd=(n,r,e,t)=>{for(var i=t>1?void 0:t?md(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&hd(r,e,i),i},Sd=(n,r)=>(e,t)=>r(e,t,n);exports.SheetSkeletonManagerService=class extends a.Disposable{constructor(e,t){super();T(this,"_currentSkeletonSearchParam",{sheetId:""});T(this,"_sheetSkeletonParam",[]);T(this,"_currentSkeleton$",new O.BehaviorSubject(null));T(this,"currentSkeleton$",this._currentSkeleton$.asObservable());T(this,"_currentSkeletonBefore$",new O.BehaviorSubject(null));T(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._context=e,this._injector=t,this.disposeWithMe(()=>{this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._sheetSkeletonParam=[]}),this._initRemoveSheet()}_initRemoveSheet(){this.disposeWithMe(this._context.unit.sheetDisposed$.subscribe(e=>{this.disposeSkeleton({sheetId:e.getSheetId()})}))}getCurrentSkeleton(){var e;return(e=this.getCurrent())==null?void 0:e.skeleton}getCurrent(){return this._getSkeleton(this._currentSkeletonSearchParam)}getWorksheetSkeleton(e){return this._getSkeleton({sheetId:e})}getUnitSkeleton(e,t){const i=this._getSkeleton({sheetId:t});return i!=null&&(i.unitId=e),i}setCurrent(e){this._setCurrent(e)}_setCurrent(e){const t=this._getSkeleton(e),i=this._context.unitId;if(t!=null)this._reCalculate(t);else{const{sheetId:l}=e,d=this._context.unit.getSheetBySheetId(e.sheetId);if(d==null)return;const u=this._buildSkeleton(d);this._sheetSkeletonParam.push({unitId:i,sheetId:l,skeleton:u,dirty:!1})}this._currentSkeletonSearchParam=e;const o=this._currentSkeletonSearchParam.sheetId,s=this.getUnitSkeleton(i,o);this._currentSkeletonBefore$.next(s),this._currentSkeleton$.next(s)}reCalculate(){const e=this.getCurrent();e!=null&&this._reCalculate(e)}_reCalculate(e){e.dirty&&(e.skeleton.makeDirty(!0),e.dirty=!1),e.skeleton.calculate()}makeDirty(e,t=!0){const i=this._getSkeleton(e);i!=null&&(i.dirty=t)}getOrCreateSkeleton(e){const t=this._getSkeleton(e);if(t)return t.skeleton;const o=this._context.unit.getSheetBySheetId(e.sheetId);if(!o)return;const s=this._buildSkeleton(o);return this._sheetSkeletonParam.push({unitId:this._context.unitId,sheetId:e.sheetId,skeleton:s,dirty:!1}),s}disposeSkeleton(e){const t=this._sheetSkeletonParam.findIndex(i=>i.sheetId===e.sheetId);t>-1&&(this._sheetSkeletonParam[t].skeleton.dispose(),this._sheetSkeletonParam.splice(t,1))}attachRangeWithCoord(e){const t=this.getCurrentSkeleton();return t?vn(t,e):null}_getSkeleton(e){const t=this._sheetSkeletonParam.find(i=>i.sheetId===e.sheetId);return t!=null&&(t.commandId=e.commandId),t}_buildSkeleton(e){return this._injector.createInstance(y.SpreadsheetSkeleton,e,this._context.unit.getStyles())}};exports.SheetSkeletonManagerService=gd([Sd(1,a.Inject(a.Injector))],exports.SheetSkeletonManagerService);function Je(){const n=a.useDependency(a.IUniverInstanceService),r=R.useObservable(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]);return r!=null?r:null}function fd(n){return R.useObservable(()=>{var e;return(e=n==null?void 0:n.activeSheet$)!=null?e:O.of(null)},void 0,void 0,[n])}function pd(){const n=a.useDependency(a.IUniverInstanceService);return R.useObservable(()=>O.merge([n.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET),n.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET)]).pipe(O.map(()=>n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET)),O.startWith(n.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET))),[],void 0,[n])}function vd(){const n=a.useDependency(y.IRenderManagerService),r=Je(),{sheetSkeletonManagerService:e}=H.useMemo(()=>{if(r){const t=n.getRenderById(r.getUnitId());return{sheetSkeletonManagerService:t==null?void 0:t.with(exports.SheetSkeletonManagerService)}}return{sheetSkeletonManagerService:null}},[r,n]);return e}const Cd="SheetUI";var is=(n=>(n.FILTER_PANEL_EMBED_POINT="filter-panel-embed-point",n.SHEETS_FOOTER="sheets-footer",n.FORMULA_AUX="formula-aux",n))(is||{}),Id=Object.defineProperty,_d=Object.getOwnPropertyDescriptor,bd=(n,r,e,t)=>{for(var i=t>1?void 0:t?_d(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&Id(r,e,i),i},Ai=(n,r)=>(e,t)=>r(e,t,n);const rs=["ff","fs","tr","tb"];exports.AutoHeightController=class extends a.Disposable{constructor(r,e,t,i){super(),this._renderManagerService=r,this._sheetInterceptorService=e,this._selectionManagerService=t,this._univerInstanceService=i,this._initialize()}getUndoRedoParamsOfAutoHeight(r){const{_univerInstanceService:e}=this,t=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),i=t.getActiveSheet(),o=t.getUnitId(),s=i.getSheetId(),l=this._renderManagerService.getRenderById(o).with(exports.SheetSkeletonManagerService);if(!s||!l.getCurrent())return{redos:[],undos:[]};const{skeleton:c}=l.getCurrent(),d=c.calculateAutoHeightInRange(r),u={subUnitId:s,unitId:o,rowsAutoHeightInfo:d},h=m.SetWorksheetRowAutoHeightMutationFactory(u,i);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:h}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}]}}_initialize(){const{_sheetInterceptorService:r,_selectionManagerService:e}=this;this.disposeWithMe(r.interceptCommand({getMutations:t=>{if(t.id===m.SetRangeValuesCommand.id){const i=t.params;return this.getUndoRedoParamsOfAutoHeight(i.range)}return{redos:[],undos:[]}}})),this.disposeWithMe(r.interceptCommand({getMutations:t=>t.id!==m.SetWorksheetRowIsAutoHeightCommand.id?{redos:[],undos:[]}:this.getUndoRedoParamsOfAutoHeight(t.params.ranges)})),this.disposeWithMe(r.interceptCommand({getMutations:t=>{var o,s;if(t.id!==m.SetStyleCommand.id)return{redos:[],undos:[]};if(!rs.includes((o=t.params)==null?void 0:o.style.type))return{redos:[],undos:[]};const i=(s=e.getCurrentSelections())==null?void 0:s.map(l=>l.range);return i!=null&&i.length?this.getUndoRedoParamsOfAutoHeight(i):{redos:[],undos:[]}}})),this.disposeWithMe(r.interceptAfterCommand({getMutations:t=>{if(t.id===m.MoveRangeCommand.id){const i=t.params;return this.getUndoRedoParamsOfAutoHeight([i.fromRange,i.toRange])}if(t.id===m.ReorderRangeCommand.id){const i=t.params;return this.getUndoRedoParamsOfAutoHeight([i.range])}return{redos:[],undos:[]}}}))}};exports.AutoHeightController=bd([Ai(0,y.IRenderManagerService),Ai(1,a.Inject(m.SheetInterceptorService)),Ai(2,a.Inject(m.SheetsSelectionsService)),Ai(3,a.Inject(a.IUniverInstanceService))],exports.AutoHeightController);function un(n,r,e,t){const i=r.get(a.IUniverInstanceService),o=e?i.getUnit(e,a.UniverInstanceType.UNIVER_SHEET):i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=t?o==null?void 0:o.getSheetBySheetId(t):o==null?void 0:o.getActiveSheet();if(!s)return null;const{startRow:l,endRow:c,startColumn:d,endColumn:u}=n,h=[],g=[];for(let S=l;S<=c;S++)s.getRowFiltered(S)||h.push(S);for(let S=d;S<=u;S++)g.push(S);return{rows:h,cols:g}}function _t(n){const{rows:r,cols:e}=n;return{startRow:r[0],endRow:r[r.length-1],startColumn:e[0],endColumn:e[e.length-1]}}function Et(n){let r=[],e=[];const t=[];return n.forEach(i=>{r=r.concat(i.rows),e=e.concat(i.cols)}),r=Array.from(new Set(r)).sort((i,o)=>i-o),e=Array.from(new Set(e)).sort((i,o)=>i-o),n.forEach(i=>{t.push({startRow:r.findIndex(o=>o===i.rows[0]),endRow:r.findIndex(o=>o===i.rows[i.rows.length-1]),startColumn:e.findIndex(o=>o===i.cols[0]),endColumn:e.findIndex(o=>o===i.cols[i.cols.length-1])})}),{ranges:t,mapFunc:(i,o)=>({row:r[i],col:e[o]})}}function Rd(n){const r=new a.ObjectMatrix;return n.forEach(e=>{const{rows:t,cols:i}=e;t.forEach(o=>{i.forEach(s=>{r.setValue(o,s,{v:null,p:null,f:null,si:null,custom:null})})})}),r.getData()}const Po={零:0,一:1,二:2,三:3,四:4,五:5,六:6,七:7,八:8,九:9},Zi=["零","一","二","三","四","五","六","七","八","九"],Hs=["","万","亿","万亿","亿亿"],Ed=["","十","百","千"],Ba={十:{value:10,secUnit:!1},百:{value:100,secUnit:!1},千:{value:1e3,secUnit:!1},万:{value:1e4,secUnit:!0},亿:{value:1e8,secUnit:!0}};function dt(n){if(!n)return 0;let r=0,e=0,t=0,i=!1;const o=n.split("");for(let s=0;s<o.length;s++){const l=Po[o[s]];if(typeof l<"u")t=l,s===o.length-1&&(e+=t);else{const c=Ba[o[s]],d=c.value;i=c.secUnit,i?(e=(e+t)*d,r+=e,e=0):e+=t*d,t=0}}return r+e}function Td(n){let r="",e="",t=0,i=!0;for(;n>0;){const o=n%10;o===0?i||(i=!0,e=Zi[o]+e):(i=!1,r=Zi[o],r+=Ed[t],e=r+e),t++,n=Math.floor(n/10)}return e}function wd(n){let r=0,e="",t="",i=!1;if(n===0)return Zi[0];for(;n>0;){const o=n%1e4;i&&(t=Zi[0]+t),e=Td(o),e+=o!==0?Hs[r]:Hs[0],t=e+t,i=o<1e3&&o>0,n=Math.floor(n/1e4),r++}return t}function yd(n){if(!n)return!1;let r=!0;if(n)if(n.length===1)n==="日"||n in Po?r=!0:r=!1;else{const e=n.split("");for(let t=0;t<e.length;t++)if(!(e[t]in Po||e[t]in Ba)){r=!1;break}}return r}function Ni(n){if(!n)return{isExtendNumber:!1};const r=/0|([1-9]+[0-9]*)/g,e=r.test(n);if(e){const t=n.match(r);if(t&&t.length>0){const i=t[t.length-1],o=n.lastIndexOf(i),s=n.substr(0,o),l=n.substr(o+i.length);return{isExtendNumber:!0,matchTxt:Number(i),beforeTxt:s,afterTxt:l}}return{isExtendNumber:!1}}return{isExtendNumber:e}}function Md(n){let r;return n.length===2&&(n==="周一"||n==="周二"||n==="周三"||n==="周四"||n==="周五"||n==="周六"||n==="周日")?r=!0:r=!1,r}function Pd(n){let r;return n.length===3&&(n==="星期一"||n==="星期二"||n==="星期三"||n==="星期四"||n==="星期五"||n==="星期六"||n==="星期日")?r=!0:r=!1,r}function Od(n,r){let e=0;for(let t=0;t<n.length&&n[t]<r;t++)e++;return e}function ai(n){let r=!0;const e=n[1]-n[0];for(let t=1;t<n.length;t++)if(n[t]-n[t-1]!==e){r=!1;break}return r}function xd(n,r,e){const t=[],i=Math.floor(r/n),o=r%n;let s=0;if(i>0){for(let l=0;l<i;l++)for(let c=0;c<e.length;c++)t[e[c]+l*n]=s,s++;for(let l=0;l<e.length&&e[l]<o;l++)t[e[l]+n*i]=s,s++}else for(let l=0;l<e.length&&e[l]<o;l++)t[e[l]]=s,s++;return t}function Bt(n,r){const e=[];for(let t=1;t<=r;t++){const i=(t-1)%n.length,o=a.Tools.deepClone(n[i]);e.push({v:null,s:null,p:null,f:null,si:null,t:null,...o})}return e}function Ad(n,r){var t;const e=[];for(let i=1;i<=r;i++){const o=(i-1)%n.length,s={s:(t=n[o])==null?void 0:t.s};e.push(s)}return e}function Nd(n){let r=!0;const e=n[1]/n[0];for(let t=1;t<n.length;t++)if(n[t]/n[t-1]!==e){r=!1;break}return r}function Dd(n){const r=[];for(let e=1;e<=n;e++)r.push(e);return r}function Ki(n,r,e){var o,s,l,c;const t=[],i=[];for(let d=0;d<n.length;d++)i.push(Number((o=n[d])==null?void 0:o.v));if(n.length>2&&Nd(i))for(let d=1;d<=r;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]),g=Number((s=n[n.length-1])==null?void 0:s.v)*(Number((l=n[1])==null?void 0:l.v)/Number((c=n[0])==null?void 0:c.v))**d;h&&(Bs(h)&&(h.v=g),t.push(h))}else{const d=Dd(n.length);for(let u=1;u<=r;u++){const h=(u-1)%n.length,g=a.Tools.deepClone(n[h]),S=e===a.Direction.DOWN||e===a.Direction.RIGHT,f=kd(n.length+u,i,d,S);g&&(Bs(g)&&(g.v=f),t.push(g))}}return t}function kd(n,r,e,t=!0){function i(h){let g=0;for(let S=0;S<h.length;S++)g+=h[S];return g/h.length}const o=i(e),s=i(r);let l=0,c=0;for(let h=0;h<e.length;h++)l+=(e[h]-o)*(r[h]-s),c+=(e[h]-o)*(e[h]-o);let d;c===0?d=t?1:-1:d=l/c;const u=s-d*o;return Math.round((u+d*n)*1e5)/1e5}function Ws(n,r,e){var o;const t=[],i=/0|([1-9]+[0-9]*)/g;for(let s=1;s<=r;s++){const l=(s-1)%n.length,c=a.Tools.deepClone(n[l]),d=`${(o=n[n.length-1])==null?void 0:o.v}`,u=d==null?void 0:d.match(i),h=u==null?void 0:u[u.length-1],g=Math.abs(Number(h)+e*s);if(!d||!h)continue;const S=d.lastIndexOf(h),f=d.substr(0,S)+g.toString()+d.substr(S+h.length);c&&(c.v=f,t.push(c))}return t}function Cn(n,r,e,t=0){var l,c;const i=[["日","一","二","三","四","五","六"],["周日","周一","周二","周三","周四","周五","周六"],["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]];if(t>=i.length)return[];const o=i[t],s=[];for(let d=1;d<=r;d++){const u=(d-1)%n.length,h=a.Tools.deepClone(n[u]);let g=0;if(((l=n[n.length-1])==null?void 0:l.v)===o[0])g=7+e*d;else{const f=`${(c=n[n.length-1])==null?void 0:c.v}`;if(f){const p=f.substr(f.length-1,1);g=dt(p)+e*d}}g<0&&(g=Math.ceil(Math.abs(g)/7)*7+g);const S=g%7;h&&(h.v=o[S],s.push(h))}return s}function Us(n,r,e){var i;const t=[];for(let o=1;o<=r;o++){const s=(o-1)%n.length,l=a.Tools.deepClone(n[s]),c=`${(i=n[n.length-1])==null?void 0:i.v}`,d=dt(c)+e*o;let u;d<=0?u="零":u=wd(d),l&&(l.v=u,t.push(l))}return t}const Gn={enWeek1:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],enWeek2:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],enMonth1:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],enMonth2:["January","February","March","April","May","June","July","August","September","October","November","December"],chnMonth1:["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"],chnMonth2:["正月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","腊月"],chHour1:["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"],chHour2:["子时","丑时","寅时","卯时","辰时","巳时","午时","未时","申时","酉时","戌时","亥时"],chYear1:["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"],chSeason1:["春","夏","秋","冬"],chSeason2:["春季","夏季","秋季","冬季"]};function Vd(n){let r=!1;return Object.keys(Gn).forEach(e=>{Gn[e].includes(n)&&(r=!0)}),r}function Wr(n){let r="";const e=[];return Object.keys(Gn).forEach(t=>{Gn[t].includes(n)&&(r=t,e.push(...Gn[t]))}),{name:r,series:e}}function Ls(n,r,e,t){var s;const i=t.length,o=[];for(let l=1;l<=r;l++){const c=(l-1)%n.length,d=a.Tools.deepClone(n[c]),u=`${(s=n[n.length-1])==null?void 0:s.v}`;let h=t.indexOf(u)+e*l;h<0&&(h+=Math.abs(e)*i);const g=h%i;d&&(d.v=t[g],o.push(d))}return o}function Hd(n,r){const e=[];let t;if(r.startRow<n.startRow)t=a.Direction.UP;else if(r.endRow>n.endRow)t=a.Direction.DOWN;else if(r.startColumn<n.startColumn)t=a.Direction.LEFT;else if(r.endColumn>n.endColumn)t=a.Direction.RIGHT;else return[];if(t===a.Direction.DOWN||t===a.Direction.UP){const i=n.endRow-n.startRow+1,o=r.endRow-r.startRow+1,s=Math.floor(o/i),l=o%i,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.DOWN){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow+(d+1)*i,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow+(s+1)*i,col:n.startColumn},relativeRange:{startRow:0,startColumn:0,endRow:l-1,endColumn:n.endColumn-n.startColumn}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow-(d+1)*i,col:n.startColumn},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow-(s+1)*i,col:n.startColumn},relativeRange:{startRow:i-l,endRow:i-1,startColumn:0,endColumn:n.endColumn-n.startColumn}})}}if(t===a.Direction.RIGHT||t===a.Direction.LEFT){const i=n.endColumn-n.startColumn+1,o=r.endColumn-r.startColumn+1,s=Math.floor(o/i),l=o%i,c={startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:n.endColumn-n.startColumn};if(t===a.Direction.RIGHT){for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(d+1)*i},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn+(s+1)*i},relativeRange:{startRow:0,startColumn:0,endRow:n.endRow-n.startRow,endColumn:l-1}})}else{for(let d=0;d<s;d++)e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(d+1)*i},relativeRange:c});l>0&&e.push({repeatStartCell:{row:n.startRow,col:n.startColumn-(s+1)*i},relativeRange:{startRow:0,startColumn:i-l,endRow:n.endRow-n.startRow,endColumn:i-1}})}}return e}function Bs(n){return!(a.isFormulaString(n.f)||a.isFormulaId(n.si)||n.t===a.CellValueType.BOOLEAN)}var cn=(n=>(n.Append="APPEND",n.Default="DEFAULT",n.Only="ONLY",n))(cn||{}),ve=(n=>(n.NUMBER="number",n.DATE="date",n.EXTEND_NUMBER="extendNumber",n.CHN_NUMBER="chnNumber",n.CHN_WEEK2="chnWeek2",n.CHN_WEEK3="chnWeek3",n.LOOP_SERIES="loopSeries",n.FORMULA="formula",n.OTHER="other",n))(ve||{}),se=(n=>(n.COPY="COPY",n.SERIES="SERIES",n.ONLY_FORMAT="ONLY_FORMAT",n.NO_FORMAT="NO_FORMAT",n))(se||{});const Wd={type:ve.DATE,priority:1100,match:(n,r)=>{var e;if(n!=null&&n.f||n!=null&&n.si)return!1;if((typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER)&&n.s){if(typeof n.s=="string"){const i=r.get(a.IUniverInstanceService).getFocusedUnit().getStyles().get(n.s),o=(e=i==null?void 0:i.n)==null?void 0:e.pattern;if(o)return a.numfmt.getInfo(o).isDate}else if(n.s.n&&a.numfmt.getInfo(n.s.n.pattern).isDate)return!0}return!1},isContinue:(n,r)=>n.type===ve.DATE,applyFunctions:{[se.SERIES]:(n,r,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),Ki(t,r,e).reverse()):Ki(t,r,e)}}},Ud={type:ve.NUMBER,priority:1e3,match:n=>typeof(n==null?void 0:n.v)=="number"||(n==null?void 0:n.t)===a.CellValueType.NUMBER,isContinue:(n,r)=>n.type===ve.NUMBER,applyFunctions:{[se.SERIES]:(n,r,e)=>{const{data:t}=n;return e===a.Direction.LEFT||e===a.Direction.UP?(t.reverse(),Ki(t,r,e).reverse()):Ki(t,r,e)}}},Fa={type:ve.OTHER,priority:0,match:()=>!0,isContinue:(n,r)=>n.type===ve.OTHER},Ld={type:ve.EXTEND_NUMBER,priority:900,match:n=>Ni(`${n==null?void 0:n.v}`||"").isExtendNumber,isContinue:(n,r)=>{var e;if(n.type===ve.EXTEND_NUMBER){const{beforeTxt:t,afterTxt:i}=Ni(`${(e=n.cellData)==null?void 0:e.v}`||""),{beforeTxt:o,afterTxt:s}=Ni(`${r==null?void 0:r.v}`||"");if(t===o&&i===s)return!0}return!1},applyFunctions:{[se.SERIES]:(n,r,e)=>{var l;const{data:t}=n,i=e===a.Direction.UP||e===a.Direction.LEFT;let o;if(t.length===1)return o=i?-1:1,Ue(Ws(t,r,o),i);const s=[];for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;d&&s.push(Number(Ni(d).matchTxt))}return i&&(t.reverse(),s.reverse()),ai(s)?(o=s[1]-s[0],Ue(Ws(t,r,o),i)):Bt(t,r)}}},Bd={type:ve.CHN_NUMBER,priority:830,match:n=>!!yd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>n.type===ve.CHN_NUMBER,applyFunctions:{[se.SERIES]:(n,r,e)=>{var c,d,u;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){const h=`${(c=t[0])==null?void 0:c.v}`;let g;return i?g=-1:g=1,h&&(h==="日"||dt(h)<7)?Ue(Cn(t,r,g),i):Ue(Us(t,r,g),i)}let o=!1;for(let h=0;h<t.length;h++)if(((d=t[h])==null?void 0:d.v)==="日"){o=!0;break}const s=[];let l=0;for(let h=0;h<t.length;h++){const g=`${(u=t[h])==null?void 0:u.v}`;g==="日"?h===0?s.push(0):(l++,s.push(l*7)):o&&dt(g)>0&&dt(g)<7?s.push(dt(g)+l*7):s.push(dt(g))}if(i&&(t.reverse(),s.reverse()),ai(s)){if(o||s[s.length-1]<6&&s[0]>0||s[0]<6&&s[s.length-1]>0){const g=s[1]-s[0];return Ue(Cn(t,r,g),i)}const h=s[1]-s[0];return Ue(Us(t,r,h),i)}return Bt(t,r)}}},Fd={type:ve.CHN_WEEK2,priority:820,match:n=>!!Md(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>n.type===ve.CHN_WEEK2,applyFunctions:{[se.SERIES]:(n,r,e)=>{var l;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return i?c=-1:c=1,Ue(Cn(t,r,c,1),i)}const o=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`,u=d==null?void 0:d.substr(d.length-1,1);d==="周日"?c===0?o.push(0):(s++,o.push(s*7)):o.push(dt(u)+s*7)}if(i&&(t.reverse(),o.reverse()),ai(o)){const c=o[1]-o[0];return Ue(Cn(t,r,c,1),i)}return Bt(t,r)}}},jd={type:ve.CHN_WEEK3,priority:810,match:n=>Pd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>n.type===ve.CHN_WEEK3,applyFunctions:{[se.SERIES]:(n,r,e)=>{var l;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP;if(t.length===1){let c;return i?c=-1:c=1,Ue(Cn(t,r,c,2),i)}const o=[];let s=0;for(let c=0;c<t.length;c++){const d=`${(l=t[c])==null?void 0:l.v}`;if(d){const u=d.substr(d.length-1,1);d==="星期日"?c===0?o.push(0):(s++,o.push(s*7)):o.push(dt(u)+s*7)}}if(i&&(t.reverse(),o.reverse()),ai(o)){const c=o[1]-o[0];return Ue(Cn(t,r,c,2),i)}return Bt(t,r)}}},zd={type:ve.LOOP_SERIES,priority:800,match:n=>Vd(`${n==null?void 0:n.v}`||""),isContinue:(n,r)=>{var e;return n.type===ve.LOOP_SERIES?Wr(`${(e=n.cellData)==null?void 0:e.v}`||"").name===Wr(`${r==null?void 0:r.v}`||"").name:!1},applyFunctions:{[se.SERIES]:(n,r,e)=>{var c,d;const{data:t}=n,i=e===a.Direction.LEFT||e===a.Direction.UP,{series:o}=Wr(`${(c=t[0])==null?void 0:c.v}`||"");if(t.length===1){let u;return i?u=-1:u=1,Ue(Ls(t,r,u,o),i)}const s=[];let l=0;for(let u=0;u<t.length;u++){const h=`${(d=t[u])==null?void 0:d.v}`;h&&(h===o[0]?u===0?s.push(0):(l++,s.push(l*o.length)):s.push(o.indexOf(h)+l*7))}if(i&&(t.reverse(),s.reverse()),ai(s)){const u=s[1]-s[0];return Ue(Ls(t,r,u,o),i)}return Bt(t,r)}}};function Ue(n,r){return r?n.reverse():n}var Xd=Object.defineProperty,Yd=Object.getOwnPropertyDescriptor,Gd=(n,r,e,t)=>{for(var i=t>1?void 0:t?Yd(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&Xd(r,e,i),i},$t=(n,r)=>(e,t)=>r(e,t,n);exports.AutoFillService=class extends a.Disposable{constructor(e,t,i,o,s,l){super();T(this,"_rules",[]);T(this,"_hooks",[]);T(this,"_applyType$",new O.BehaviorSubject(se.SERIES));T(this,"_isFillingStyle",!0);T(this,"_prevUndos",[]);T(this,"_autoFillLocation$",new O.BehaviorSubject(null));T(this,"autoFillLocation$",this._autoFillLocation$.asObservable());T(this,"_showMenu$",new O.BehaviorSubject(!1));T(this,"showMenu$",this._showMenu$.asObservable());T(this,"_direction",a.Direction.DOWN);T(this,"applyType$",this._applyType$.asObservable());T(this,"_menu$",new O.BehaviorSubject([{label:"autoFill.copy",value:se.COPY,disable:!1},{label:"autoFill.series",value:se.SERIES,disable:!1},{label:"autoFill.formatOnly",value:se.ONLY_FORMAT,disable:!1},{label:"autoFill.noFormat",value:se.NO_FORMAT,disable:!1}]));T(this,"menu$",this._menu$.asObservable());this._commandService=e,this._undoRedoService=t,this._renderManagerService=i,this._univerInstanceService=o,this._selectionManagerService=s,this._injector=l,this._init()}_init(){this._rules=[Wd,Ud,Ld,Bd,Fd,jd,zd,Fa].sort((e,t)=>t.priority-e.priority),this._isFillingStyle=!0}_getOneByPriority(e){return e.length<=0?[]:[e.reduce((i,o)=>(o.priority||0)>(i.priority||0)?o:i,e[0])]}_initPrevUndo(){this._prevUndos=[]}async triggerAutoFill(e,t,i,o){var S;if(i.startColumn===o.startColumn&&i.startRow===o.startRow&&i.endColumn===o.endColumn&&i.endRow===o.endRow)return!1;if(o.endColumn<i.endColumn&&o.endColumn>i.startColumn)return this._commandService.executeCommand(In.id,{clearRange:{startRow:o.startRow,endRow:o.endRow,startColumn:o.endColumn+1,endColumn:i.endColumn},selectionRange:o});if(o.endRow<i.endRow&&o.endRow>i.startRow)return this._commandService.executeCommand(In.id,{clearRange:{startRow:o.endRow+1,endRow:i.endRow,startColumn:o.startColumn,endColumn:o.endColumn},selectionRange:o});const s={startRow:o.startRow,endRow:o.endRow,startColumn:o.startColumn,endColumn:o.endColumn};let l=null;if(o.startRow<i.startRow)l=a.Direction.UP,s.endRow=i.startRow-1;else if(o.endRow>i.endRow)l=a.Direction.DOWN,s.startRow=i.endRow+1;else if(o.startColumn<i.startColumn)l=a.Direction.LEFT,s.endColumn=i.startColumn-1;else if(o.endColumn>i.endColumn)l=a.Direction.RIGHT,s.startColumn=i.endColumn+1;else return!1;this.direction=l;const c=this._injector.invoke(f=>un(i,f)),d=this._injector.invoke(f=>un(s,f));if(!c||!d)return!1;this.autoFillLocation={source:c,target:d,unitId:e,subUnitId:t};const u=[];this.getActiveHooks().forEach(f=>{var v;const p=(v=f==null?void 0:f.onBeforeFillData)==null?void 0:v.call(f,{source:c,target:d,unitId:e,subUnitId:t},l);p&&u.unshift(p)}),this._initPrevUndo();for(let f=0;f<u.length;f++){const p=this.menu.find(v=>v.value===u[f]);if(p&&!p.disable)return this.fillData(u[f])}const g=(S=this.menu.find(f=>f.disable===!1))==null?void 0:S.value;return g?this.fillData(g):!1}addHook(e){if(this._hooks.find(t=>t.id===e.id))throw new Error(`Add hook failed, hook id '${e.id}' already exist!`);return e.priority===void 0&&(e.priority=0),e.type===void 0&&(e.type=cn.Append),this._hooks.push(e),a.toDisposable(()=>{const t=this._hooks.findIndex(i=>i===e);t>-1&&this._hooks.splice(t,1)})}registerRule(e){if(this._rules.find(i=>i.type===e.type))throw new Error(`Registry rule failed, type '${e.type}' already exist!`);const t=this._rules.findIndex(i=>i.priority<e.priority);this._rules.splice(t===-1?this._rules.length:t,0,e)}getRules(){return this._rules}getAllHooks(){return this._hooks}getActiveHooks(){const{source:e,target:t,unitId:i,subUnitId:o}=this.autoFillLocation||{};if(!e||!t||!i||!o)return[];const s=this._hooks.filter(u=>{var h;return!((h=u.disable)!=null&&h.call(u,{source:e,target:t,unitId:i,subUnitId:o},this._direction,this.applyType))}),l=s.filter(u=>u.type===cn.Only);if(l.length>0)return this._getOneByPriority(l);const c=this._getOneByPriority(s.filter(u=>u.type===cn.Default)),d=s.filter(u=>u.type===cn.Append)||[];return[...c,...d]}get applyType(){return this._applyType$.getValue()}set applyType(e){this._applyType$.next(e)}get menu(){return this._menu$.getValue()}get direction(){return this._direction}set direction(e){this._direction=e}isFillingStyle(){return this._isFillingStyle}setFillingStyle(e){this._isFillingStyle=e}get autoFillLocation(){return this._autoFillLocation$.getValue()}set autoFillLocation(e){this._autoFillLocation$.next(e)}setDisableApplyType(e,t){this._menu$.next(this._menu$.getValue().map(i=>i.value===e?{...i,disable:t}:i))}setShowMenu(e){this._showMenu$.next(e)}fillData(e){var C,_,b;this.applyType=e;const{source:t,target:i,unitId:o=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),subUnitId:s=(C=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet())==null?void 0:C.getSheetId()}=this.autoFillLocation||{};if(!t||!i||!o||!s)return!1;const l=this.direction;this._prevUndos.length>0&&this._prevUndos.forEach(E=>{this._commandService.syncExecuteCommand(E.id,E.params)}),this._prevUndos=[];const c=a.Rectangle.union(_t(t),_t(i)),d=this.getActiveHooks(),u=this._univerInstanceService.getUnit(o,a.UniverInstanceType.UNIVER_SHEET);this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{selections:[{primary:{...(b=(_=this._selectionManagerService.getCurrentLastSelection())==null?void 0:_.primary)!=null?b:c},range:{...c,rangeType:a.RANGE_TYPE.NORMAL}}],unitId:o,subUnitId:s});const h=[],g=[];d.forEach(E=>{var P;const{undos:M,redos:w}=((P=E.onFillData)==null?void 0:P.call(E,{source:t,target:i,unitId:o,subUnitId:s},l,e))||{};M&&h.push(...M),w&&g.push(...w)});const S=g.every(E=>this._commandService.syncExecuteCommand(E.id,E.params)),f=[];e!==se.NO_FORMAT&&g.forEach(E=>{if(E.id===m.SetRangeValuesMutation.id){const{cellValue:M}=E.params;new a.ObjectMatrix(M).forValue((P,x,A)=>{const N=Object.keys(u.getStyles().get(A==null?void 0:A.s)||{});(A!=null&&A.p||N.length&&rs.some(D=>N.includes(D)))&&f.push({startRow:P,endRow:P,startColumn:x,endColumn:x})})}});const p=this._getAutoHeightUndoRedos(o,s,f);return p.redos.every(E=>this._commandService.syncExecuteCommand(E.id,E.params))&&(h.push(...p.undos),g.push(...p.redos)),S&&(this._prevUndos=h,this._undoRedoService.pushUndoRedo({unitID:o,undoMutations:h,redoMutations:g})),d.forEach(E=>{var M;(M=E.onAfterFillData)==null||M.call(E,{source:t,target:i,unitId:o,subUnitId:s},l,e)}),this.setShowMenu(!0),!0}_getAutoHeightUndoRedos(e,t,i){var h,g;const o=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(exports.SheetSkeletonManagerService),s=(g=o==null?void 0:o.getCurrent())==null?void 0:g.skeleton;if(!s)return{redos:[],undos:[]};const l=s.calculateAutoHeightInRange(i),c={subUnitId:t,unitId:e,rowsAutoHeightInfo:l},d=s.worksheet,u=m.SetWorksheetRowAutoHeightMutationFactory(c,d);return{undos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:u}],redos:[{id:m.SetWorksheetRowAutoHeightMutation.id,params:c}]}}};exports.AutoFillService=Gd([$t(0,a.ICommandService),$t(1,a.IUndoRedoService),$t(2,y.IRenderManagerService),$t(3,a.Inject(a.IUniverInstanceService)),$t(4,a.Inject(m.SheetsSelectionsService)),$t(5,a.Inject(a.Injector))],exports.AutoFillService);const Tt=a.createIdentifier("univer.auto-fill-service"),Ct={type:a.CommandType.COMMAND,id:"sheet.command.auto-fill",handler:async(n,r)=>{const e=n.get(Tt),t=n.get(a.IUniverInstanceService),{sourceRange:i,targetRange:o}=r,s=m.getSheetCommandTarget(t);if(!s)return!1;const{subUnitId:l,unitId:c}=s;return e.triggerAutoFill(c,l,i,o)}},In={id:"sheet.command.auto-clear-content",type:a.CommandType.COMMAND,handler:async(n,r)=>{const e=n.get(a.IUniverInstanceService),t=n.get(a.ICommandService),i=n.get(a.IUndoRedoService),o=n.get(m.SheetInterceptorService),s=m.getSheetCommandTarget(e);if(!s)return!1;const{unitId:l,subUnitId:c}=s,{clearRange:d,selectionRange:u}=r,h={subUnitId:c,unitId:l,cellValue:m.generateNullCellValue([d])},g=m.SetRangeValuesUndoMutationFactory(n,h),{startColumn:S,startRow:f}=u,p={selections:[{primary:{startColumn:S,startRow:f,endColumn:S,endRow:f,actualRow:f,actualColumn:S,isMerged:!1,isMergedMainCell:!1},range:{...u}}],unitId:l,subUnitId:c};if(t.executeCommand(m.SetSelectionsOperation.id,p),t.syncExecuteCommand(m.SetRangeValuesMutation.id,h)){const C=o.afterCommandExecute({id:m.SetRangeValuesMutation.id,params:h});return a.sequenceExecute(C.redos,t),i.pushUndoRedo({unitID:l,undoMutations:[{id:m.SetRangeValuesMutation.id,params:g},...C.undos],redoMutations:[{id:m.SetRangeValuesMutation.id,params:h},...C.redos]}),!0}return!1}},li={id:"sheet.command.refill",type:a.CommandType.COMMAND,handler:async(n,r)=>n.get(Tt).fillData(r.type)},Oo=[10,400],os="RANGE_SELECTOR_COMPONENT_KEY",br="EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY";var me=(n=>(n.MAIN="__SpreadsheetRender__",n.ROW="__SpreadsheetRowHeader__",n.COLUMN="__SpreadsheetColumnHeader__",n.LEFT_TOP="__SpreadsheetLeftTopPlaceholder__",n))(me||{});const Fs=0,qi=1,bt=10,Zd=11,js=12,xo=a.createInterceptorKey("rangeMovePermissionCheck"),Ao=a.createInterceptorKey("rangeFillPermissionCheck");var ss=(n=>(n[n.FORMULA_EDITOR_SHOW=100]="FORMULA_EDITOR_SHOW",n[n.MARK_SELECTION=1e4]="MARK_SELECTION",n))(ss||{});function Rt(n){const r=n.getCurrentTheme(),e=new a.ColorKit(r.primaryColor).setAlpha(.07).toRgbString();return{strokeWidth:1,stroke:r.primaryColor,fill:e,widgets:{},widgetSize:6,widgetStrokeWidth:1,widgetStroke:r.colorWhite,autofillSize:6,autofillStrokeWidth:1,autofillStroke:r.colorWhite,rowHeaderFill:e,rowHeaderStroke:r.primaryColor,rowHeaderStrokeWidth:1,columnHeaderFill:e,columnHeaderStroke:r.primaryColor,columnHeaderStrokeWidth:1,expandCornerSize:40}}class Kd{constructor(){T(this,"_startColumn",-1);T(this,"_startRow",-1);T(this,"_endColumn",-1);T(this,"_endRow",-1);T(this,"_startX",0);T(this,"_startY",0);T(this,"_endX",0);T(this,"_endY",0);T(this,"_primary");T(this,"_rangeType",a.RANGE_TYPE.NORMAL)}get startColumn(){return this._startColumn}get startRow(){return this._startRow}get endColumn(){return this._endColumn}get endRow(){return this._endRow}get startX(){return this._startX}get startY(){return this._startY}get endX(){return this._endX}get endY(){return this._endY}get currentCell(){return this._primary}get rangeType(){return this._rangeType}isEqual(r){const{startColumn:e,startRow:t,endColumn:i,endRow:o}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=r;return e===s&&t===l&&i===c&&o===d}isInclude(r){const{startColumn:e,startRow:t,endColumn:i,endRow:o}=this,{startColumn:s,startRow:l,endColumn:c,endRow:d}=r;return!(c<e||s>i||l>o||d<t)}highlightToSelection(){if(this._primary)return a.convertCellToRange(this._primary)}getRange(){return{startColumn:this._startColumn,startRow:this._startRow,endColumn:this._endColumn,endRow:this._endRow,startX:this._startX,startY:this._startY,endX:this._endX,endY:this._endY,rangeType:this.rangeType}}getCell(){return this._primary}getRangeType(){return this._rangeType}setRangeType(r){this._rangeType=r}getValue(){return{rangeWithCoord:this.getRange(),primaryWithCoord:this._primary}}setValue(r,e){const{startColumn:t,startRow:i,endColumn:o,endRow:s,startX:l,startY:c,endX:d,endY:u,rangeType:h}=r;this._startColumn=t,this._startRow=i,this._endColumn=o,this._endRow=s,this._startX=l,this._startY=c,this._endX=d,this._endY=u,h!==void 0&&(this._rangeType=h),e!==void 0&&this.setCurrentCell(e)}setCurrentCell(r){this._primary=r}clearCurrentCell(){this._primary=null}}const zs="__SpreadsheetHelperSelectionTempRect",qd=35;class ja{constructor(r,e){T(this,"_startOffsetX",0);T(this,"_startOffsetY",0);T(this,"_relativeSelectionPositionRow",0);T(this,"_relativeSelectionPositionColumn",0);T(this,"_relativeSelectionRowLength",0);T(this,"_relativeSelectionColumnLength",0);T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_helperSelection");T(this,"_scrollTimer");T(this,"_activeViewport");T(this,"_targetSelection",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});T(this,"_isInMergeState",!1);T(this,"_fillControlColors",[]);T(this,"_skeleton");T(this,"_scene");T(this,"_themeService");T(this,"_injector");T(this,"_selectionHooks");this._control=r,this._skeleton=e.skeleton,this._scene=e.scene,this._themeService=e.themeService,this._injector=e.injector,this._selectionHooks=e.selectionHooks,this._initialControl(),this._initialWidget(),this._initialAutoFill(),this._control.dispose$.subscribe(()=>{this.dispose()})}get isHelperSelection(){return this._control.isHelperSelection}dispose(){var r,e;(r=this._scrollTimer)==null||r.dispose(),this._fillControlColors=[],this._clearObserverEvent(),(e=this._helperSelection)==null||e.dispose()}_getFreeze(){var t,i;return(i=(t=this._injector.get(y.IRenderManagerService).withCurrentTypeOfUnit(a.UniverInstanceType.UNIVER_SHEET,exports.SheetSkeletonManagerService))==null?void 0:t.getCurrent())==null?void 0:i.skeleton.getWorksheetConfig().freeze}_isSelectionInViewport(r,e){const t=this._getFreeze()||{startRow:-1,startColumn:-1,xSplit:0,ySplit:0};switch(e.viewportKey){case y.SHEET_VIEWPORT_KEY.VIEW_MAIN:return r.endRow>=t.startRow&&r.endColumn>=t.startColumn;case y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP:case y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT:return r.endColumn>=t.startColumn&&r.startRow<t.startRow;case y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT:case y.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM:return r.endRow>=t.startRow&&r.startColumn<t.startColumn;case y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP:case y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT:case y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP:case y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP:return r.startRow<t.startRow&&r.startColumn<t.startColumn}}_clearObserverEvent(){var r,e;(r=this._scenePointerMoveSub)==null||r.unsubscribe(),(e=this._scenePointerUpSub)==null||e.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}_initialControl(){const{leftControl:r,rightControl:e,topControl:t,bottomControl:i}=this._control;[r,e,t,i].forEach(o=>{o.onPointerEnter$.subscribeEvent(()=>{var l;((l=this._injector.get(_e,a.Quantity.OPTIONAL))==null?void 0:l.interceptor.fetchThroughInterceptors(xo)(!1,null))!==!1&&o.setCursor(y.CURSOR_TYPE.MOVE)}),o.onPointerLeave$.subscribeEvent(()=>{o.resetCursor()}),o.onPointerDown$.subscribeEvent(this._controlPointerDownHandler.bind(this))})}_controlMoving(r,e){var A;const t=this._scene,i=t.getScrollXYInfoByViewport(y.Vector2.FromArray([r,e])),{scaleX:o,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(r,e,o,s,i),{row:c,column:d}=l,u=this._skeleton.getRowCount()-1,h=this._skeleton.getColumnCount()-1;let g=Math.max(0,c+this._relativeSelectionPositionRow),S=g+this._relativeSelectionRowLength;S>u&&(S=u,S-g<this._relativeSelectionRowLength&&(g=S-this._relativeSelectionRowLength));let f=Math.max(0,d+this._relativeSelectionPositionColumn),p=f+this._relativeSelectionColumnLength;p>h&&(p=h,p-f<this._relativeSelectionColumnLength&&(f=p-this._relativeSelectionColumnLength));const v=this._skeleton.worksheet.getCellInfoInMergeData(g,f),_=ye({range:{startRow:g,endRow:S,startColumn:f,endColumn:p},primary:v,style:null},this._skeleton),b=this._skeleton.getNoMergeCellPositionByIndex(g,f),E=this._skeleton.getNoMergeCellPositionByIndex(S,p),M=(b==null?void 0:b.startY)||0,w=(E==null?void 0:E.endY)||0,P=(b==null?void 0:b.startX)||0,x=(E==null?void 0:E.endX)||0;(A=this._helperSelection)==null||A.transformByState({left:P,top:M,width:x-P,height:w-M}),this._targetSelection={..._.rangeWithCoord},this._control.selectionMoving$.next(_.rangeWithCoord)}_controlPointerDownHandler(r){const{offsetX:e,offsetY:t}=r,i=this._scene,o=i.getCoordRelativeToViewport(y.Vector2.FromArray([e,t])),{x:s,y:l}=o,c=i.getScrollXYInfoByViewport(o),{scaleX:d,scaleY:u}=i.getAncestorScale(),h=this._skeleton.getCellIndexByOffset(s,l,d,u,c);this._startOffsetX=s,this._startOffsetY=l;const{row:g,column:S}=h,{startRow:f,startColumn:p,endRow:v,endColumn:C}=this._control.model;let _=0,b=0;g<f?_-=1:g>v&&(_+=1),S<p?b-=1:S>C&&(b+=1),this._relativeSelectionPositionRow=f-g+_,this._relativeSelectionPositionColumn=p-S+b,this._relativeSelectionRowLength=v-f,this._relativeSelectionColumnLength=C-p;const E=this._control.currentStyle,M=this._getScale();this.isHelperSelection&&(this._helperSelection=new y.Rect(zs,{stroke:E.stroke,strokeWidth:E.strokeWidth/M}),i.addObject(this._helperSelection));const w=i.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),P=y.ScrollTimer.create(i);this._scrollTimer=P,P.startScroll(s,l,w),i.disableObjectsEvent(),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(x=>{var V;const{offsetX:A,offsetY:N}=x;if(((V=this._injector.get(_e,a.Quantity.OPTIONAL))==null?void 0:V.interceptor.fetchThroughInterceptors(xo)(!1,null))===!1)return;const{x:k,y:B}=i.getCoordRelativeToViewport(y.Vector2.FromArray([A,N]));this._controlMoving(k,B),i.setCursor(y.CURSOR_TYPE.MOVE),P.scrolling(k,B,()=>{this._controlMoving(k,B)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var A,N,D,k;(A=this._helperSelection)==null||A.dispose();const x=this._scene;x.resetCursor(),this._clearObserverEvent(),x.enableObjectsEvent(),(N=this._scrollTimer)==null||N.dispose(),this._control.selectionMoveEnd$.next(this._targetSelection),(k=(D=this._selectionHooks).selectionMoveEnd)==null||k.call(D)})}_initialWidget(){const{topLeftWidget:r,topCenterWidget:e,topRightWidget:t,middleLeftWidget:i,middleRightWidget:o,bottomLeftWidget:s,bottomCenterWidget:l,bottomRightWidget:c}=this._control,d=[y.CURSOR_TYPE.NORTH_WEST_RESIZE,y.CURSOR_TYPE.NORTH_RESIZE,y.CURSOR_TYPE.NORTH_EAST_RESIZE,y.CURSOR_TYPE.WEST_RESIZE,y.CURSOR_TYPE.EAST_RESIZE,y.CURSOR_TYPE.SOUTH_WEST_RESIZE,y.CURSOR_TYPE.SOUTH_RESIZE,y.CURSOR_TYPE.SOUTH_EAST_RESIZE];[r,e,t,i,o,s,l,c].forEach((u,h)=>{u.onPointerEnter$.subscribeEvent(()=>{u.setCursor(d[h])}),u.onPointerLeave$.subscribeEvent(()=>{u.resetCursor()}),u.onPointerDown$.subscribeEvent(g=>{this._widgetPointerDownEvent(g,d[h])})})}_widgetPointerDownEvent(r,e){const t=this._scene,{offsetX:i,offsetY:o}=r,s=t.getCoordRelativeToViewport(y.Vector2.FromArray([i,o])),{x:l,y:c}=s;this._startOffsetX=i,this._startOffsetY=o;const{startRow:d,startColumn:u,endRow:h,endColumn:g}=this._control.model,S=Math.min(d,h),f=Math.min(u,g),p=Math.max(d,h),v=Math.max(u,g);this._relativeSelectionPositionRow=S,this._relativeSelectionPositionColumn=f,this._relativeSelectionRowLength=p-S,this._relativeSelectionColumnLength=v-f,e===y.CURSOR_TYPE.NORTH_WEST_RESIZE?(this._relativeSelectionPositionRow=p,this._relativeSelectionPositionColumn=v):e===y.CURSOR_TYPE.NORTH_RESIZE?this._relativeSelectionPositionRow=p:e===y.CURSOR_TYPE.NORTH_EAST_RESIZE?this._relativeSelectionPositionRow=p:e===y.CURSOR_TYPE.WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===y.CURSOR_TYPE.SOUTH_WEST_RESIZE?this._relativeSelectionPositionColumn=v:e===y.CURSOR_TYPE.SOUTH_RESIZE&&(this._relativeSelectionPositionRow=S);const C=y.ScrollTimer.create(t),_=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);C.startScroll(l,c,_),this._scrollTimer=C,t.disableObjectsEvent(),this._scenePointerMoveSub=t.onPointerMove$.subscribeEvent(b=>{const{offsetX:E,offsetY:M}=b,{x:w,y:P}=t.getCoordRelativeToViewport(y.Vector2.FromArray([E,M]));this._widgetMoving(w,P,e),t.setCursor(e),C.scrolling(w,P,()=>{this._widgetMoving(w,P,e)})}),this._scenePointerUpSub=t.onPointerUp$.subscribeEvent(()=>{var E,M,w;const b=this._scene;b.resetCursor(),this._clearObserverEvent(),b.enableObjectsEvent(),(E=this._scrollTimer)==null||E.dispose(),this._control.selectionScaled$.next(this._targetSelection),(w=(M=this._selectionHooks).selectionMoveEnd)==null||w.call(M)})}_widgetMoving(r,e,t){const i=this._scene,o=i.getScrollXYInfoByViewport(y.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),{scaleX:s,scaleY:l}=i.getAncestorScale(),c=this._skeleton.getCellIndexByOffset(r,e,s,l,o),{row:d,column:u}=c;let h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,f=u;t===y.CURSOR_TYPE.NORTH_WEST_RESIZE?(h=d,g=u,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn):t===y.CURSOR_TYPE.NORTH_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength):t===y.CURSOR_TYPE.NORTH_EAST_RESIZE?(h=d,g=this._relativeSelectionPositionColumn,S=this._relativeSelectionPositionRow,f=u):t===y.CURSOR_TYPE.WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,f=this._relativeSelectionPositionColumn):t===y.CURSOR_TYPE.EAST_RESIZE?S=this._relativeSelectionPositionRow+this._relativeSelectionRowLength:t===y.CURSOR_TYPE.SOUTH_WEST_RESIZE?(h=this._relativeSelectionPositionRow,g=u,S=d,f=this._relativeSelectionPositionColumn):t===y.CURSOR_TYPE.SOUTH_RESIZE&&(h=this._relativeSelectionPositionRow,g=this._relativeSelectionPositionColumn,S=d,f=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength);const p=this._swapPositions(h,g,S,f),v=this._skeleton.getCellWithMergeInfoByIndex(h,g),_=ye({range:p,primary:v,style:null},this._skeleton);this._targetSelection={..._.rangeWithCoord},this._control.updateRangeBySelectionWithCoord(_),this._control.selectionScaling$.next(this._targetSelection)}_initialAutoFill(){const{fillControl:r}=this._control;r.onPointerEnter$.subscribeEvent(e=>{this._injector.get(_e).interceptor.fetchThroughInterceptors(Ao)(!1,{x:e.offsetX,y:e.offsetY,skeleton:this._skeleton,scene:this._scene})&&r.setCursor(y.CURSOR_TYPE.CROSSHAIR)}),r.onPointerLeave$.subscribeEvent(()=>{r.resetCursor()}),r.onPointerDown$.subscribeEvent(this._autoFillForPointerdown.bind(this))}_autoFillMoving(r,e){var N,D,k;const t=this._scene,i=t.getViewportScrollXY(this._activeViewport),{scaleX:o,scaleY:s}=t.getAncestorScale(),l=this._skeleton.getCellIndexByOffset(r,e,o,s,i),{row:c,column:d}=l,u=t.getCoordRelativeToViewport(y.Vector2.FromArray([r,e])),h=this._skeleton.getRowCount()-1,g=this._skeleton.getColumnCount()-1;let S=this._relativeSelectionPositionRow,f=this._relativeSelectionPositionColumn,p=this._relativeSelectionPositionRow+this._relativeSelectionRowLength,v=this._relativeSelectionPositionColumn+this._relativeSelectionColumnLength,C=!1,_=!0;if((d<f||d>v)&&c>=S&&c<=p){const B=this._fillRuler(d,f,v,this._relativeSelectionColumnLength,g);f=B.startRowOrColumn,v=B.endRowOrColumn,C=B.isLighten,_=!1}else if((c<S||c>p)&&d>=f&&d<=v){const B=this._fillRuler(c,S,p,this._relativeSelectionRowLength,h);S=B.startRowOrColumn,p=B.endRowOrColumn,C=B.isLighten}else if(Math.abs(this._startOffsetX-u.x-i.x)/2>Math.abs(this._startOffsetY-u.y-i.y)){const B=this._fillRuler(d,f,v,this._relativeSelectionColumnLength,g);f=B.startRowOrColumn,v=B.endRowOrColumn,C=B.isLighten,_=!1}else{const B=this._fillRuler(c,S,p,this._relativeSelectionRowLength,h);S=B.startRowOrColumn,p=B.endRowOrColumn,C=B.isLighten}const b=this._skeleton.getNoMergeCellPositionByIndex(S,f),E=this._skeleton.getNoMergeCellPositionByIndex(p,v),M=(b==null?void 0:b.startY)||0,w=(E==null?void 0:E.endY)||0,P=(b==null?void 0:b.startX)||0,x=(E==null?void 0:E.endX)||0;C?this._controlHandler((B,V)=>{const U=new a.ColorKit(this._fillControlColors[V]).lighten(qd).toRgbString();B.setProps({fill:U})}):this._controlHandler((B,V)=>{B.setProps({fill:this._fillControlColors[V]})});const A=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/this._getScale();S===p&&_===!0||f===v&&_===!1?(N=this._helperSelection)==null||N.hide():((D=this._helperSelection)==null||D.transformByState({left:P-A/2,top:M-A/2,width:x-P,height:w-M}),(k=this._helperSelection)==null||k.show()),this._targetSelection={startY:M,endY:w,startX:P,endX:x,startRow:S,endRow:p,startColumn:f,endColumn:v},this._control.selectionFilling$.next(this._targetSelection)}_autoFillForPointerdown(r){const{offsetX:e,offsetY:t}=r,i=this._scene,o=i.getCoordRelativeToViewport(y.Vector2.FromArray([e,t])),{x:s,y:l}=o;this._startOffsetX=s,this._startOffsetY=l;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=this._control.model;this._isInMergeState=this._hasMergeInRange(c,d,u,h),this._relativeSelectionPositionRow=c,this._relativeSelectionPositionColumn=d,this._relativeSelectionRowLength=u-c,this._relativeSelectionColumnLength=h-d;const g=this._control.currentStyle;let S=g==null?void 0:g.stroke,f=g==null?void 0:g.strokeWidth;const p=Rt(this._themeService);S==null&&(S=p.stroke),f==null&&(f=p.strokeWidth);const v=this._getScale();f/=v;const C=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/v,_=new a.ColorKit(S).darken(2).toRgbString();this.isHelperSelection&&(this._helperSelection=new y.Rect(zs,{stroke:_,strokeWidth:f+C/2}),i.addObject(this._helperSelection)),this._activeViewport=i.getActiveViewportByCoord(y.Vector2.FromArray([e,t]));const b=i.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),E=y.ScrollTimer.create(i,this._activeViewport.viewportKey===y.SHEET_VIEWPORT_KEY.VIEW_MAIN?y.ScrollTimerType.ALL:y.ScrollTimerType.NONE);E.startScroll(s,l,b),this._scrollTimer=E,i.disableObjectsEvent(),this._controlHandler(M=>{this._fillControlColors.push(M.fill)}),this._scenePointerMoveSub=i.onPointerMove$.subscribeEvent(M=>{var B;const{offsetX:w,offsetY:P}=M,x=i.getActiveViewportByCoord(y.Vector2.FromArray([w,P]));if(!this._injector.get(_e).interceptor.fetchThroughInterceptors(Ao)(!1,{x:r.offsetX,y:r.offsetY,skeleton:this._skeleton,scene:this._scene}))return;const{x:N,y:D}=i.getCoordRelativeToViewport(y.Vector2.FromArray([w,P]));this._autoFillMoving(N,D),i.setCursor(y.CURSOR_TYPE.CROSSHAIR);const k=this._targetSelection;if(b&&x&&((B=this._activeViewport)==null?void 0:B.viewportKey)!==(x==null?void 0:x.viewportKey)){let V;k.startRow!==c?(E.scrollTimerType=y.ScrollTimerType.Y,V={...k,endRow:k.startRow}):k.endRow!==u?(E.scrollTimerType=y.ScrollTimerType.Y,V={...k,startRow:k.endRow}):k.startColumn!==d?(E.scrollTimerType=y.ScrollTimerType.X,V={...k,endColumn:k.startColumn}):(E.scrollTimerType=y.ScrollTimerType.X,V={...k,startColumn:k.endColumn}),this._isSelectionInViewport(V,x)&&(b.scrollToBarPos({x:E.scrollTimerType===y.ScrollTimerType.X?0:void 0,y:E.scrollTimerType===y.ScrollTimerType.Y?0:void 0}),this._activeViewport=x)}E.scrolling(N,D,()=>{this._autoFillMoving(N,D)})}),this._scenePointerUpSub=i.onPointerUp$.subscribeEvent(()=>{var w,P;(w=this._helperSelection)==null||w.dispose();const M=this._scene;M.resetCursor(),this._clearObserverEvent(),M.enableObjectsEvent(),(P=this._scrollTimer)==null||P.dispose(),this._control.refreshSelectionFilled(this._targetSelection),this._isInMergeState=!1,this._controlHandler((x,A)=>{x.setProps({fill:this._fillControlColors[A]})}),this._fillControlColors=[]})}_hasMergeInRange(r,e,t,i){return this._skeleton.worksheet.getMergedCellRange(r,e,t,i).length>0}_swapPositions(r,e,t,i){const o=Math.min(r,t),s=Math.min(e,i),l=Math.max(r,t),c=Math.max(e,i);return{startRow:o,startColumn:s,endRow:l,endColumn:c}}_controlHandler(r){const{leftControl:e,rightControl:t,topControl:i,bottomControl:o,backgroundControlTop:s,backgroundControlMiddleLeft:l,backgroundControlMiddleRight:c,backgroundControlBottom:d,fillControl:u}=this._control,h=[e,t,i,o,s,l,c,d,u];for(let g=0,S=h.length;g<S;g++){const f=h[g];r(f,g)}}_fillRuler(r,e,t,i,o){let s=!1;if(r<e)if(this._isInMergeState&&r<e){const l=e-r,c=i+1,d=Math.ceil(l/c);let u=e-d*c;u<0&&(u=e-(d-1)*c),e=u}else e=r;else if(r>=e&&r<=t)s=!0,this._isInMergeState||(t=r);else if(this._isInMergeState&&r>t){const l=r-t,c=i+1,d=Math.ceil(l/c);let u=t+d*c;u>o&&(u=t+(d-1)*c),t=u}else t=r;return{rowOrColumn:r,startRowOrColumn:e,endRowOrColumn:t,isLighten:s}}_getScale(){const{scaleX:r,scaleY:e}=this._scene.getAncestorScale();return Math.max(r,e)}}var No=(n=>(n.Selection="__SpreadsheetSelectionShape__",n.top="__SpreadsheetSelectionTopControl__",n.bottom="__SpreadsheetSelectionBottomControl__",n.left="__SpreadsheetSelectionShapeLeftControl__",n.right="__SpreadsheetSelectionShapeRightControl__",n.backgroundTop="__SpreadsheetSelectionBackgroundControlTop__",n.backgroundMiddleLeft="__SpreadsheetSelectionBackgroundControlMiddleLeft__",n.backgroundMiddleRight="__SpreadsheetSelectionBackgroundControlMiddleRight__",n.backgroundBottom="__SpreadsheetSelectionBackgroundControlBottom__",n.fill="__SpreadsheetSelectionFillControl__",n.fillTopLeft="__SpreadsheetSelectionFillControlTopLeft__",n.fillBottomRight="__SpreadsheetSelectionFillControlBottomRight__",n.fillTopLeftInner="__SpreadsheetSelectionFillControlTopLeftInner__",n.fillBottomRightInner="__SpreadsheetSelectionFillControlBottomRightInner__",n.lineMain="__SpreadsheetDragLineMainControl__",n.lineContent="__SpreadsheetDragLineContentControl__",n.line="__SpreadsheetDragLineControl__",n.dash="__SpreadsheetDragDashControl__",n.rowHeaderBackground="__SpreadSheetSelectionRowHeaderBackground__",n.rowHeaderBorder="__SpreadSheetSelectionRowHeaderBorder__",n.rowHeaderGroup="__SpreadSheetSelectionRowHeaderGroup__",n.columnHeaderBackground="__SpreadSheetSelectionColumnHeaderBackground__",n.columnHeaderBorder="__SpreadSheetSelectionColumnHeaderBorder__",n.columnHeaderGroup="__SpreadSheetSelectionColumnHeaderGroup__",n.topLeftWidget="__SpreadSheetSelectionTopLeftWidget__",n.topCenterWidget="__SpreadSheetSelectionTopCenterWidget__",n.topRightWidget="__SpreadSheetSelectionTopRightWidget__",n.middleLeftWidget="__SpreadSheetSelectionMiddleLeftWidget__",n.middleRightWidget="__SpreadSheetSelectionMiddleRightWidget__",n.bottomLeftWidget="__SpreadSheetSelectionBottomLeftWidget__",n.bottomCenterWidget="__SpreadSheetSelectionBottomCenterWidget__",n.bottomRightWidget="__SpreadSheetSelectionBottomRightWidget__",n))(No||{});const Xs=.3;class ci extends a.Disposable{constructor(e,t,i,o){var s,l,c,d;super();T(this,"_isHelperSelection",!0);T(this,"_enableAutoFill",!0);T(this,"_showAutoFill",!1);T(this,"_highlightHeader",!0);T(this,"_selectionRenderModel");T(this,"_leftBorder");T(this,"_rightBorder");T(this,"_topBorder");T(this,"_bottomBorder");T(this,"_backgroundControlTop");T(this,"_backgroundControlBottom");T(this,"_backgroundControlMiddleLeft");T(this,"_backgroundControlMiddleRight");T(this,"_autoFillControl");T(this,"_selectionShapeGroup");T(this,"_rowHeaderBackground");T(this,"_rowHeaderBorder");T(this,"_rowHeaderGroup");T(this,"_columnHeaderBackground");T(this,"_columnHeaderBorder");T(this,"_columnHeaderGroup");T(this,"_dashedRect");T(this,"_topLeftWidget");T(this,"_topCenterWidget");T(this,"_topRightWidget");T(this,"_middleLeftWidget");T(this,"_middleRightWidget");T(this,"_bottomLeftWidget");T(this,"_bottomCenterWidget");T(this,"_bottomRightWidget");T(this,"_defaultStyle");T(this,"_currentStyle");T(this,"_rowHeaderWidth",0);T(this,"_columnHeaderHeight",0);T(this,"_widgetRects",[]);T(this,"_controlExtension");T(this,"_dispose$",new O.BehaviorSubject(this));T(this,"dispose$",this._dispose$.asObservable());T(this,"selectionMoving$",new O.Subject);T(this,"selectionMoveEnd$",new O.Subject);T(this,"selectionScaling$",new O.Subject);T(this,"selectionScaled$",new O.Subject);T(this,"selectionFilling$",new O.Subject);T(this,"_selectionFilled$",new O.Subject);T(this,"selectionFilled$",this._selectionFilled$.asObservable());T(this,"_antLineOffset",0);T(this,"_antRequestNewFrame",-1);this._scene=e,this._zIndex=t,this._themeService=i,this._enableAutoFill=(s=o==null?void 0:o.enableAutoFill)!=null?s:!0,this._highlightHeader=(l=o==null?void 0:o.highlightHeader)!=null?l:!0,this._rowHeaderWidth=(c=o==null?void 0:o.rowHeaderWidth)!=null?c:0,this._columnHeaderHeight=(d=o==null?void 0:o.columnHeaderHeight)!=null?d:0,this._initializeSheetBody(),this._initialHeader()}_initializeSheetBody(){this._defaultStyle=Rt(this._themeService),this._currentStyle=Rt(this._themeService),this._selectionRenderModel=new Kd;const e=this._zIndex;this._leftBorder=new y.Rect("__SpreadsheetSelectionShapeLeftControl__"+e,{zIndex:e}),this._rightBorder=new y.Rect("__SpreadsheetSelectionShapeRightControl__"+e,{zIndex:e}),this._topBorder=new y.Rect("__SpreadsheetSelectionTopControl__"+e,{zIndex:e}),this._bottomBorder=new y.Rect("__SpreadsheetSelectionBottomControl__"+e,{zIndex:e}),this._backgroundControlTop=new y.Rect("__SpreadsheetSelectionBackgroundControlTop__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlBottom=new y.Rect("__SpreadsheetSelectionBackgroundControlBottom__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleLeft=new y.Rect("__SpreadsheetSelectionBackgroundControlMiddleLeft__"+e,{zIndex:e-1,evented:!1}),this._backgroundControlMiddleRight=new y.Rect("__SpreadsheetSelectionBackgroundControlMiddleRight__"+e,{zIndex:e-1,evented:!1}),this._autoFillControl=new y.Rect("__SpreadsheetSelectionFillControl__"+e,{zIndex:e+1}),this._autoFillControl.hide(),this._dashedRect=new y.DashedRect("__SpreadsheetDragDashControl__"+e,{zIndex:e+2,evented:!1,stroke:"#fff"});const t=[this._autoFillControl,this._leftBorder,this._rightBorder,this._topBorder,this._bottomBorder,this._backgroundControlTop,this._backgroundControlMiddleLeft,this._backgroundControlMiddleRight,this._backgroundControlBottom,this._dashedRect];this._widgetRects=this._initialWidget(),this._selectionShapeGroup=new y.Group("__SpreadsheetSelectionShape__"+e,...t,...this._widgetRects),this._selectionShapeGroup.hide(),this._selectionShapeGroup.evented=!1,this._selectionShapeGroup.zIndex=e;const i=this.getScene();i.addObject(this._selectionShapeGroup,qi),this.disposeWithMe(a.toDisposable(i.onTransformChange$.subscribeEvent(o=>{o.type===y.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&(this._updateLayoutOfSelectionControl(this._currentStyle),this._updateControlCoord())})))}_initialHeader(){const e=this._zIndex;this._rowHeaderBackground=new y.Rect("__SpreadSheetSelectionRowHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderBorder=new y.Rect("__SpreadSheetSelectionRowHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._rowHeaderGroup=new y.Group("__SpreadSheetSelectionRowHeaderGroup__"+e,this._rowHeaderBackground,this._rowHeaderBorder),this._rowHeaderGroup.hide(),this._rowHeaderGroup.evented=!1,this._rowHeaderGroup.zIndex=e,this._columnHeaderBackground=new y.Rect("__SpreadSheetSelectionColumnHeaderBackground__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderBorder=new y.Rect("__SpreadSheetSelectionColumnHeaderBorder__"+e,{zIndex:e-1,evented:!1}),this._columnHeaderGroup=new y.Group("__SpreadSheetSelectionColumnHeaderGroup__"+e,this._columnHeaderBackground,this._columnHeaderBorder),this._columnHeaderGroup.hide(),this._columnHeaderGroup.evented=!1,this._columnHeaderGroup.zIndex=e,this.getScene().addObjects([this._rowHeaderGroup,this._columnHeaderGroup],Zd)}_initialWidget(){const e=this._zIndex;return this._topLeftWidget=new y.Rect("__SpreadSheetSelectionTopLeftWidget__"+e,{zIndex:e+1}),this._topCenterWidget=new y.Rect("__SpreadSheetSelectionTopCenterWidget__"+e,{zIndex:e+1}),this._topRightWidget=new y.Rect("__SpreadSheetSelectionTopRightWidget__"+e,{zIndex:e+1}),this._middleLeftWidget=new y.Rect("__SpreadSheetSelectionMiddleLeftWidget__"+e,{zIndex:e+1}),this._middleRightWidget=new y.Rect("__SpreadSheetSelectionMiddleRightWidget__"+e,{zIndex:e+1}),this._bottomLeftWidget=new y.Rect("__SpreadSheetSelectionBottomLeftWidget__"+e,{zIndex:e+1}),this._bottomCenterWidget=new y.Rect("__SpreadSheetSelectionBottomCenterWidget__"+e,{zIndex:e+1}),this._bottomRightWidget=new y.Rect("__SpreadSheetSelectionBottomRightWidget__"+e,{zIndex:e+1}),[this._topLeftWidget,this._topCenterWidget,this._topRightWidget,this._middleLeftWidget,this._middleRightWidget,this._bottomLeftWidget,this._bottomCenterWidget,this._bottomRightWidget]}get zIndex(){return this._zIndex}get leftControl(){return this._leftBorder}get rightControl(){return this._rightBorder}get topControl(){return this._topBorder}get bottomControl(){return this._bottomBorder}get fillControl(){return this._autoFillControl}get backgroundControlTop(){return this._backgroundControlTop}get backgroundControlBottom(){return this._backgroundControlBottom}get backgroundControlMiddleLeft(){return this._backgroundControlMiddleLeft}get backgroundControlMiddleRight(){return this._backgroundControlMiddleRight}get selectionShape(){return this._selectionShapeGroup}get columnHeaderGroup(){return this._columnHeaderGroup}get rowHeaderGroup(){return this._rowHeaderGroup}get selectionShapeGroup(){return this._selectionShapeGroup}get model(){return this._selectionRenderModel}get topLeftWidget(){return this._topLeftWidget}get topCenterWidget(){return this._topCenterWidget}get topRightWidget(){return this._topRightWidget}get middleLeftWidget(){return this._middleLeftWidget}get middleRightWidget(){return this._middleRightWidget}get bottomLeftWidget(){return this._bottomLeftWidget}get bottomCenterWidget(){return this._bottomCenterWidget}get bottomRightWidget(){return this._bottomRightWidget}get themeService(){return this._themeService}get selectionModel(){return this._selectionRenderModel}set selectionModel(e){this._selectionRenderModel=e}get currentStyle(){return this._currentStyle}set currentStyle(e){this._currentStyle=e}get dashedRect(){return this._dashedRect}get isHelperSelection(){return this._isHelperSelection}get rowHeaderWidth(){return this._rowHeaderWidth}set rowHeaderWidth(e){this._rowHeaderWidth=e}get columnHeaderHeight(){return this._columnHeaderHeight}set columnHeaderHeight(e){this._columnHeaderHeight=e}setControlExtension(e){this._controlExtension=new ja(this,e)}setEvent(e){this.leftControl.evented=e,this.rightControl.evented=e,this.topControl.evented=e,this.bottomControl.evented=e}refreshSelectionFilled(e){this._selectionFilled$.next(e)}_updateLayoutOfSelectionControl(e){e&&(this.currentStyle=Object.assign({},this._defaultStyle,e));const t=this.currentStyle,{stroke:i,widgets:o,autofillStroke:s,strokeDash:l,isAnimationDash:c}=t;let d=t.autofillSize,u=t.strokeWidth,h=t.autofillStrokeWidth;const g=this._getScale(),S=(u+m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH)/2/g;u/=g,d/=g,h/=g<1?1:g;const f=m.SELECTION_CONTROL_BORDER_BUFFER_WIDTH/g,p=y.FIX_ONE_PIXEL_BLUR_OFFSET/g,{startX:v,startY:C,endX:_,endY:b}=this._selectionRenderModel;if(this.leftControl.transformByState({height:b-C,left:-S+p,width:u,strokeWidth:f,top:-f/2+p}),this.leftControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.rightControl.transformByState({height:b-C,left:_-v-S+p,width:u,strokeWidth:f,top:-f/2+p}),this.rightControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.topControl.transformByState({width:_-v+u,top:-S+p,left:-S+p,height:u,strokeWidth:f}),this.topControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),this.bottomControl.transformByState({width:_-v+u,top:b-C-S+p,height:u,left:-S+p,strokeWidth:f}),this.bottomControl.setProps({fill:i,stroke:m.SELECTION_CONTROL_BORDER_BUFFER_COLOR}),l==null)this.dashedRect.hide(),this._stopAntLineAnimation();else{const E=t.strokeWidth*2/g;this.dashedRect.transformByState({height:b-C,width:_-v,strokeWidth:E,left:-E/2+p,top:-E/2+p}),this.dashedRect.setProps({strokeDashArray:[0,l/g]}),this._stopAntLineAnimation(),c!==!1&&this._startAntLineAnimation(),this.dashedRect.show()}if(this._showAutoFill=this._showAutoFill&&this._enableAutoFill,this._showAutoFill&&!this._hasWidgets(o)){const E={fill:i,stroke:s,strokeScaleEnabled:!1},M={width:d-h,height:d-h,left:_-v-d/2+h/2-p,top:b-C-d/2+h/2-p,strokeWidth:h};this._autoFillControl.setProps(E),this._autoFillControl.transformByState(M),this._autoFillControl.show()}else this._autoFillControl.hide();this._updateBackgroundControl(t),this._updateHeaderBackground(t),this._updateWidgets(t)}_updateControlCoord(){const{startX:e,startY:t}=this._selectionRenderModel;this.selectionShapeGroup.show(),this.selectionShapeGroup.translate(e,t),this.selectionShapeGroup.makeDirtyNoDebounce(!0)}updateStyle(e){this._updateLayoutOfSelectionControl(e),this._updateControlCoord()}updateRange(e,t){this._selectionRenderModel.setValue(e,t),this._showAutoFill=t!==null,this._updateLayoutOfSelectionControl(),this._updateControlCoord()}updateRangeBySelectionWithCoord(e){this._selectionRenderModel.setValue(e.rangeWithCoord,e.primaryWithCoord),this._showAutoFill=e.primaryWithCoord!==null,this._updateLayoutOfSelectionControl(e.style),this._updateControlCoord()}update(e,t=0,i=0,o,s){this._rowHeaderWidth=t,this._columnHeaderHeight=i,this.updateRangeBySelectionWithCoord({rangeWithCoord:e,primaryWithCoord:s,style:o}),o&&this.updateStyle(o)}updateCurrCell(e){this._showAutoFill=e!==null,this._selectionRenderModel.setCurrentCell(e)}clearHighlight(){this._showAutoFill=!1,this._selectionRenderModel.clearCurrentCell(),this._updateLayoutOfSelectionControl(this._currentStyle)}getScene(){return this._scene}dispose(){var e,t,i,o,s,l,c,d,u,h,g,S,f,p,v,C,_,b,E,M,w,P,x,A,N;(e=this._leftBorder)==null||e.dispose(),(t=this._rightBorder)==null||t.dispose(),(i=this._topBorder)==null||i.dispose(),(o=this._bottomBorder)==null||o.dispose(),(s=this._backgroundControlTop)==null||s.dispose(),(l=this._backgroundControlMiddleLeft)==null||l.dispose(),(c=this._backgroundControlMiddleRight)==null||c.dispose(),(d=this._backgroundControlBottom)==null||d.dispose(),this._autoFillControl.dispose(),(u=this._selectionShapeGroup)==null||u.dispose(),(h=this._rowHeaderBackground)==null||h.dispose(),(g=this._rowHeaderBorder)==null||g.dispose(),(S=this._rowHeaderGroup)==null||S.dispose(),(f=this._rowHeaderBackground)==null||f.dispose(),(p=this._columnHeaderBackground)==null||p.dispose(),(v=this._columnHeaderBorder)==null||v.dispose(),(C=this._columnHeaderGroup)==null||C.dispose(),(_=this._topLeftWidget)==null||_.dispose(),(b=this._topCenterWidget)==null||b.dispose(),(E=this._topRightWidget)==null||E.dispose(),(M=this._middleLeftWidget)==null||M.dispose(),(w=this._middleRightWidget)==null||w.dispose(),(P=this._bottomLeftWidget)==null||P.dispose(),(x=this._bottomCenterWidget)==null||x.dispose(),(A=this._bottomRightWidget)==null||A.dispose(),(N=this._controlExtension)==null||N.dispose(),super.dispose(),this._dispose$.next(this),this._dispose$.complete()}getCurrentCellInfo(){const e=this.model.currentCell;if(e){let t;if(e.isMerged){const i=e.mergeInfo;t={startRow:i.startRow,endRow:i.endRow,startColumn:i.startColumn,endColumn:i.endColumn,startX:i.startX,endX:i.endX,startY:i.startY,endY:i.endY}}else{const{actualRow:i,actualColumn:o,startX:s,endX:l,startY:c,endY:d}=e;t={startRow:i,endRow:i,startColumn:o,endColumn:o,startX:s,endX:l,startY:c,endY:d}}return t}}getValue(){return{...this._selectionRenderModel.getValue(),style:this._currentStyle}}getRange(){return this._selectionRenderModel.getValue().rangeWithCoord}enableHelperSelection(){this._isHelperSelection=!0}disableHelperSelection(){this._isHelperSelection=!1}_updateHeaderBackground(e){const{startX:t,startY:i,endX:o,endY:s,rangeType:l}=this._selectionRenderModel,c=this._currentStyle,d=this._getScale(),{stroke:u,rowHeaderFill:h=c.rowHeaderFill,rowHeaderStroke:g=c.rowHeaderStroke,columnHeaderFill:S=c.columnHeaderFill,columnHeaderStroke:f=c.columnHeaderStroke}=e;let{rowHeaderStrokeWidth:p=c.rowHeaderStrokeWidth,columnHeaderStrokeWidth:v=c.columnHeaderStrokeWidth}=e;p/=d,v/=d;const C=this._rowHeaderWidth,_=this._columnHeaderHeight;if(this._highlightHeader&&_>0){let b=S;l===a.RANGE_TYPE.COLUMN&&(b=new a.ColorKit(u).setAlpha(Xs).toString()),this._columnHeaderBackground.setProps({fill:b}),this._columnHeaderBackground.resize(o-t,_),this._columnHeaderBorder.setProps({fill:f}),this._columnHeaderBorder.transformByState({width:o-t,height:v,top:_-v+1/d}),this._columnHeaderGroup.show(),this._columnHeaderGroup.translate(t,0)}else this._columnHeaderGroup.hide();if(this._columnHeaderGroup.makeDirty(!0),this._highlightHeader&&C>0){let b=h;l===a.RANGE_TYPE.ROW&&(b=new a.ColorKit(u).setAlpha(Xs).toString()),this._rowHeaderBackground.setProps({fill:b}),this._rowHeaderBackground.resize(C,s-i),this._rowHeaderBorder.setProps({fill:g}),this._rowHeaderBorder.transformByState({width:p,height:s-i,left:C-p+1/d}),this._rowHeaderGroup.show(),this._rowHeaderGroup.translate(0,i)}else this._rowHeaderGroup.hide();this._rowHeaderGroup.makeDirty(!0)}_updateBackgroundControl(e){const{startX:t,startY:i,endX:o,endY:s}=this._selectionRenderModel,l=this._getScale(),{fill:c=e.fill}=e;let{strokeWidth:d}=e;d/=l;const u=this._selectionRenderModel.highlightToSelection();if(!u){this._backgroundControlTop.resize(o-t,s-i),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlBottom.resize(0,0),this._backgroundControlMiddleLeft.resize(0,0),this._backgroundControlMiddleRight.resize(0,0);return}const{startX:h,startY:g,endX:S,endY:f}=u,p=d/2,v={left:-p,top:-p,width:o-t+p*2,height:g-i+p};v.height<0&&(v.width=0,v.height=0),this._backgroundControlTop.transformByState(v);const C={left:-p,top:g-i,width:h-t+p,height:f-g};C.width<0&&(C.width=0,C.height=0),this._backgroundControlMiddleLeft.transformByState(C);const _={left:S-t-p,top:g-i,width:o-S+p*2,height:f-g};_.width<0&&(_.width=0,_.height=0),this._backgroundControlMiddleRight.transformByState(_);const b={left:-p,top:f-i,width:o-t+p*2,height:s-f+p};b.height<0&&(b.width=0,b.height=0),this._backgroundControlBottom.transformByState(b),this._backgroundControlTop.setProps({fill:c}),this._backgroundControlMiddleLeft.setProps({fill:c}),this._backgroundControlMiddleRight.setProps({fill:c}),this._backgroundControlBottom.setProps({fill:c})}_updateWidgets(e){const{startX:t,startY:i,endX:o,endY:s}=this._selectionRenderModel,{stroke:l=e.stroke,widgets:c=e.widgets,widgetStroke:d=e.widgetStroke}=e,u=this._getScale();let{widgetSize:h,widgetStrokeWidth:g}=e;h/=u,g/=u;const S={left:-h/2+g/2,center:(o-t)/2-h/2+g/2,right:o-t-h/2+g/2,top:-h/2,middle:(s-i)/2-h/2,bottom:s-i-h/2+g/2},f=h-g;this._widgetRects.forEach(p=>{p.setProps({fill:l,stroke:d})}),c.tl===!0?(this._topLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.top,strokeWidth:g}),this._topLeftWidget.show()):this._topLeftWidget.hide(),c.tc===!0?(this._topCenterWidget.transformByState({height:f,width:f,left:S.center,top:S.top,strokeWidth:g}),this._topCenterWidget.show()):this._topCenterWidget.hide(),c.tr===!0?(this._topRightWidget.transformByState({height:f,width:f,left:S.right,top:S.top,strokeWidth:g}),this._topRightWidget.show()):this._topRightWidget.hide(),c.ml===!0?(this._middleLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.middle,strokeWidth:g}),this._middleLeftWidget.show()):this._middleLeftWidget.hide(),c.mr===!0?(this._middleRightWidget.transformByState({height:f,width:f,left:S.right,top:S.middle,strokeWidth:g}),this._middleRightWidget.show()):this._middleRightWidget.hide(),c.bl===!0?(this._bottomLeftWidget.transformByState({height:f,width:f,left:S.left,top:S.bottom,strokeWidth:g}),this._bottomLeftWidget.show()):this._bottomLeftWidget.hide(),c.bc===!0?(this._bottomCenterWidget.transformByState({height:f,width:f,left:S.center,top:S.bottom,strokeWidth:g}),this._bottomCenterWidget.show()):this._bottomCenterWidget.hide(),c.br===!0?(this._bottomRightWidget.transformByState({height:f,width:f,left:S.right,top:S.bottom,strokeWidth:g}),this._bottomRightWidget.show()):this._bottomRightWidget.hide()}_hasWidgets(e){if(e==null)return!1;const t=Object.keys(e);if(t.length===0)return!1;for(const i of t)if(e[i]===!0)return!0;return!1}_getScale(){const{scaleX:e,scaleY:t}=this._scene.getAncestorScale();return Math.max(e,t)}_stopAntLineAnimation(){this._antLineOffset=0,y.cancelRequestFrame(this._antRequestNewFrame)}_startAntLineAnimation(){const e=this._getScale();this._antLineOffset+=.6/e,this._antLineOffset>160/e&&(this._antLineOffset=0),this.dashedRect.setProps({strokeDashOffset:-this._antLineOffset}),this._antRequestNewFrame=y.requestNewFrame(()=>{this._startAntLineAnimation()})}}class Qd extends y.Layer{render(r,e=!1){const t=a.Tools.now();return super.render(r,e),this._afterRender(t),this}_afterRender(r){this.scene.getEngine().renderFrameTimeMetric$.next(["selectionLayer",a.Tools.now()-r])}}const _e=a.createIdentifier("univer.sheet.selection-render-service");class as extends a.Disposable{constructor(e,t,i,o,s){super();T(this,"_downObserver");T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_controlFillConfig$",new O.BehaviorSubject(null));T(this,"controlFillConfig$",this._controlFillConfig$.asObservable());T(this,"_selectionControls",[]);T(this,"_startRangeWhenPointerDown",{startY:0,endY:0,startX:0,endX:0,startRow:-1,endRow:-1,startColumn:-1,endColumn:-1});T(this,"_activeControlIndex",-1);T(this,"_startViewportPosX",0);T(this,"_startViewportPosY",0);T(this,"_scrollTimer");T(this,"_cancelDownSubscription");T(this,"_cancelUpSubscription");T(this,"_skeleton");T(this,"_scene");T(this,"_highlightHeader",!0);T(this,"_rangeType",a.RANGE_TYPE.NORMAL);T(this,"_selectionStyle");T(this,"_remainLastEnabled",!1);T(this,"_skipLastEnabled",!1);T(this,"_singleSelectionEnabled",!1);T(this,"_selectionMoveEnd$",new O.BehaviorSubject([]));T(this,"selectionMoveEnd$",this._selectionMoveEnd$.asObservable());T(this,"_selectionMoving$",new O.Subject);T(this,"selectionMoving$",this._selectionMoving$.asObservable());T(this,"_selectionMoveStart$",new O.Subject);T(this,"selectionMoveStart$",this._selectionMoveStart$.asObservable());T(this,"_selectionMoving",!1);T(this,"_selectionTheme");T(this,"_activeViewport");T(this,"interceptor",new a.InterceptorManager({RANGE_MOVE_PERMISSION_CHECK:xo,RANGE_FILL_PERMISSION_CHECK:Ao}));T(this,"_escapeShortcutDisposable",null);this._injector=e,this._themeService=t,this._shortcutService=i,this._sheetSkeletonManagerService=o,this.contextService=s,this._initSelectionThemeFromThemeService(),this._initMoving()}get selectionMoving(){return this._selectionMoving}get _shouldDetectMergedCells(){return this._rangeType===a.RANGE_TYPE.NORMAL}_initMoving(){this.disposeWithMe(this._selectionMoving$.subscribe(()=>{this._selectionMoving=!0})),this.disposeWithMe(this._selectionMoveEnd$.subscribe(()=>{this._selectionMoving=!1}))}_setSelectionStyle(e){this._selectionStyle=e}getViewPort(){return this._activeViewport}setSingleSelectionEnabled(e=!1){this._singleSelectionEnabled=e}newSelectionControl(e,t,i){const o=this.getSelectionControls().length,{rowHeaderWidth:s,columnHeaderHeight:l}=t,c=new ci(e,o,this._selectionTheme,{highlightHeader:this._highlightHeader,rowHeaderWidth:s,columnHeaderHeight:l});this._selectionControls.push(c);const d=ye(i,t);return c.updateRangeBySelectionWithCoord(d),c.setControlExtension({skeleton:t,scene:e,themeService:this._selectionTheme,injector:this._injector,selectionHooks:{selectionMoveEnd:()=>{this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}}}),c}resetSelectionsByModelData(e){const t=this.getSelectionControls(),i=this._skeleton;if(!(!t||!i)){for(let o=0,s=e.length;o<s;o++){const l=e[o],c=ye(l,this._skeleton),d=t[o];d?d.updateRangeBySelectionWithCoord(c):this.isSelectionEnabled()&&this.newSelectionControl(this._scene,i,l)}e.length<t.length&&t.splice(e.length).forEach(s=>s.dispose())}}refreshSelectionMoveStart(){this._selectionMoveStart$.next(this.getSelectionDataWithStyle())}refreshSelectionMoveEnd(){this._selectionMoveEnd$.next(this.getSelectionDataWithStyle())}_initSelectionThemeFromThemeService(){const e=this._themeService.getCurrentTheme();this._selectionTheme=new a.ThemeService,this._selectionTheme.setTheme(e)}setSelectionTheme(e){this._selectionTheme.setTheme(e)}_changeRuntime(e,t,i){this._skeleton=e,this._scene=t,this._activeViewport=i||(t==null?void 0:t.getViewports()[0]),t.findLayerByZIndex(qi)||t.addLayer(new Qd(t,[],qi))}getSkeleton(){return this._skeleton}getSelectionDataWithStyle(){const e=this._selectionControls,[t,i]=this._skeleton.getLocation();return e.map(o=>{const s=o.getValue();return s.rangeWithCoord.sheetId=i,s.rangeWithCoord.unitId=t,s})}getSelectionControls(){return this._selectionControls}_addSelectionControlByModelData(e){var l;const t=this._skeleton,i=(l=e.style)!=null?l:Rt(this._selectionTheme),o=this._scene;return e.style=i,this.newSelectionControl(o,t,e)}_clearAllSelectionControls(){const e=this._selectionControls;for(const t of e)t.dispose();this._selectionControls.length=0}_getFreeze(){var t;return(t=this._sheetSkeletonManagerService.getCurrent())==null?void 0:t.skeleton.getWorksheetConfig().freeze}_getViewportByCell(e,t){if(e===void 0||t===void 0)return null;const i=this._getFreeze();if(!i||i.startRow<=0&&i.startColumn<=0)return this._scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e>i.startRow&&t>i.startColumn)return this._scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e<=i.startRow&&t<=i.startColumn)return this._scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(e<=i.startRow&&t>i.startColumn)return this._scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(e>i.startRow&&t<=i.startColumn)return this._scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}getActiveRange(){const e=this.getSelectionControls(),t=e&&e[e.length-1].model;return t&&{startRow:t.startRow,startColumn:t.startColumn,endRow:t.endRow,endColumn:t.endColumn}}setActiveSelectionIndex(e){this._activeControlIndex=e}resetActiveSelectionIndex(){this._activeControlIndex=-1}getActiveSelectionControl(){const e=this.getSelectionControls();if(e)return this._activeControlIndex<0?e[e.length-1]:e[this._activeControlIndex]}endSelection(){var e;this._clearUpdatingListeners(),this._selectionMoveEnd$.next(this.getSelectionDataWithStyle()),(e=this._escapeShortcutDisposable)==null||e.dispose(),this._escapeShortcutDisposable=null}_reset(){var e;this._clearAllSelectionControls(),(e=this._downObserver)==null||e.unsubscribe(),this._downObserver=null}_setupPointerMoveListener(e,t,i,o=y.ScrollTimerType.ALL,s,l){var f,p;let c=0,d=0,u=s,h=l;this._scrollTimer=y.ScrollTimer.create(this._scene,o),this._scrollTimer.startScroll((f=e==null?void 0:e.left)!=null?f:0,(p=e==null?void 0:e.top)!=null?p:0,e);const g=this._scene,S=g.getActiveViewportByCoord(y.Vector2.FromArray([s,l]));this._scenePointerMoveSub=g.onPointerMove$.subscribeEvent(v=>{var k,B,V,U,F,L,W,j,z;const{offsetX:C,offsetY:_}=v,{x:b,y:E}=g.getCoordRelativeToViewport(y.Vector2.FromArray([C,_]));this._movingHandler(b,E,t,i);let M=b,w=E;const P=this.getActiveSelectionControl(),x=this._getFreeze(),A=P==null?void 0:P.model,N=(k=g.getActiveViewportByCoord(y.Vector2.FromArray([C,_])))!=null?k:this._getViewportByCell(A==null?void 0:A.endRow,A==null?void 0:A.endColumn);if((()=>{if(!S||!N||!e)return!1;const Z=[y.SHEET_VIEWPORT_KEY.VIEW_MAIN,y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT];return Z.includes(S.viewportKey)&&Z.includes(N.viewportKey)})()){if(!S||!N||!e)return!1;const Z=u<e.left&&b>e.left||u>e.left&&b<e.left,te=h<e.top&&E>e.top||h>e.top&&E<e.top;Z&&(c+=1),te&&(d+=1);const q=S.viewportKey,ie=N.viewportKey;if(q===y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP)_<e.top&&((B=A==null?void 0:A.endRow)!=null?B:0)<((V=x==null?void 0:x.startRow)!=null?V:0)?w=e.top:te&&d%2===1&&e.scrollToViewportPos({viewportScrollY:0});else if(q===y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT)C<e.left&&((U=A==null?void 0:A.endColumn)!=null?U:0)<((F=x==null?void 0:x.startColumn)!=null?F:0)?M=e.left:Z&&c%2===1&&e.scrollToViewportPos({viewportScrollX:0});else if(q===ie){let oe=!1,X=!1;q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP?(oe=!0,X=!0):q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP?X=!0:q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT&&(oe=!0),((L=A==null?void 0:A.endRow)!=null?L:0)>((W=x==null?void 0:x.startRow)!=null?W:0)&&(X=!1),((j=A==null?void 0:A.endColumn)!=null?j:0)>((z=x==null?void 0:x.startColumn)!=null?z:0)&&(oe=!1),oe&&(M=e.left),X&&(w=e.top)}else{const oe={x:S.scrollX,y:S.scrollY},X={x:N.scrollX,y:N.scrollY},Y=oe.x!==X.x&&Z&&c%2===1,Q=oe.y!==X.y&&te&&d%2===1;(Y||Q)&&(e.scrollToBarPos({x:Y?oe.x:void 0,y:Q?oe.y:void 0}),Y||(M=e.left),Q||(w=e.top)),(q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&ie===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||ie===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)&&(M=e.left),(q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&ie===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||ie===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP&&q===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP)&&(w=e.top)}u=b,h=E}this._scrollTimer.scrolling(M,w,()=>{this._movingHandler(b,E,t,i)})})}attachSelectionWithCoord(e){return ye(e,this._skeleton)}attachPrimaryWithCoord(e){return qn(this._skeleton,e)}getSelectionCellByPosition(e,t){return this.getCellWithCoordByOffset(e,t)}getCellWithCoordByOffset(e,t,i){const o=this._scene,s=i!=null?i:this._skeleton,l=o.getViewportScrollXY(o.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:c,scaleY:d}=o.getAncestorScale();return s.getCellWithCoordByOffset(e,t,c,d,l)}_movingHandler(e,t,i,o){var M,w,P,x,A;const s=this._skeleton,l=this._scene,[c,d]=s.getLocation(),u={startRow:(M=i==null?void 0:i.model.startRow)!=null?M:-1,endRow:(w=i==null?void 0:i.model.endRow)!=null?w:-1,startColumn:(P=i==null?void 0:i.model.startColumn)!=null?P:-1,endColumn:(x=i==null?void 0:i.model.endColumn)!=null?x:-1,unitId:c,sheetId:d},h=l.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(A=this._getViewportByCell(u.endRow,u.endColumn))!=null?A:h,S=l.getScrollXYInfoByViewport(y.Vector2.FromArray([this._startViewportPosX,this._startViewportPosY]),g),{scaleX:f,scaleY:p}=l.getAncestorScale();o===a.RANGE_TYPE.ROW?e=Number.POSITIVE_INFINITY:o===a.RANGE_TYPE.COLUMN&&(t=Number.POSITIVE_INFINITY);const v=this._skeleton.getCellByOffset(e,t,f,p,S);if(!v)return;let C={startRow:Math.min(v.startRow,this._startRangeWhenPointerDown.startRow),startColumn:Math.min(v.startColumn,this._startRangeWhenPointerDown.startColumn),endRow:Math.max(v.endRow,this._startRangeWhenPointerDown.endRow),endColumn:Math.max(v.endColumn,this._startRangeWhenPointerDown.endColumn)};this._shouldDetectMergedCells&&(C=s.expandRangeByMerge(C));const b=ye({range:C,primary:void 0,style:null},s);b.rangeWithCoord.unitId=c,b.rangeWithCoord.sheetId=d,b.rangeWithCoord.rangeType=o;const E=u.startRow!==C.startRow||u.startColumn!==C.startColumn||u.endRow!==C.endRow||u.endColumn!==C.endColumn;i!=null&&E&&(i.updateRangeBySelectionWithCoord(b),this._selectionMoving$.next(this.getSelectionDataWithStyle()))}_clearUpdatingListeners(){var t,i,o,s,l;this._scene.enableObjectsEvent(),(t=this._scenePointerMoveSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,(i=this._scenePointerUpSub)==null||i.unsubscribe(),this._scenePointerUpSub=null,(o=this._cancelDownSubscription)==null||o.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,(l=this._scrollTimer)==null||l.dispose()}_addEndingListeners(){var i,o,s;const e=this._scene,t=(i=e.getEngine())==null?void 0:i.activeScene;!t||t===e||((o=this._cancelDownSubscription)==null||o.unsubscribe(),this._cancelDownSubscription=null,(s=this._cancelUpSubscription)==null||s.unsubscribe(),this._cancelUpSubscription=null,this._cancelDownSubscription=t.onPointerDown$.subscribeEvent(()=>this._clearUpdatingListeners()),this._cancelUpSubscription=t.onPointerUp$.subscribeEvent(()=>this._clearUpdatingListeners()))}_getSelectionWithCoordByOffset(e,t,i,o,s){const l=this._skeleton;if(l==null)return null;if(this._shouldDetectMergedCells){const C=l==null?void 0:l.getCellWithCoordByOffset(e,t,i,o,s,{firstMatch:!0});if(!C)return;const _=a.convertCellToRange(C);return{primaryWithCoord:C,rangeWithCoord:_}}const{row:c,column:d}=l.getCellIndexByOffset(e,t,i,o,s),u=l.getNoMergeCellPositionByIndex(c,d),{startX:h,startY:g,endX:S,endY:f}=u,p={startY:g,endY:f,startX:h,endX:S,startRow:c,endRow:c,startColumn:d,endColumn:d};return{primaryWithCoord:{mergeInfo:p,actualRow:c,actualColumn:d,isMerged:!1,isMergedMainCell:!1,startY:g,endY:f,startX:h,endX:S},rangeWithCoord:p}}_checkClearPreviousControls(e){this.getSelectionControls().length!==0&&(!e.ctrlKey&&!e.shiftKey&&!this._remainLastEnabled||this._singleSelectionEnabled&&!e.shiftKey)&&this._clearAllSelectionControls()}_makeSelectionByTwoCells(e,t,i,o,s){const{actualRow:l,actualColumn:c,mergeInfo:d}=e;this._startRangeWhenPointerDown={...e.mergeInfo};const u=Math.min(l,t.startRow,d.startRow),h=Math.max(l,t.endRow,d.endRow),g=Math.min(c,t.startColumn,d.startColumn),S=Math.max(c,t.endColumn,d.endColumn),p={range:i.expandRangeByMerge({startRow:u,startColumn:g,endRow:h,endColumn:S}),primary:null,style:null},v=ye(p,i);s.updateRangeBySelectionWithCoord(v)}isSelectionEnabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)}isSelectionDisabled(){return this.contextService.getContextValue(m.SELECTIONS_ENABLED)===!1}inRefSelectionMode(){return this.contextService.getContextValue(m.REF_SELECTIONS_ENABLED)}}function ls(n){return{range:{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL},primary:Rr(n).primary,style:null}}function Rr(n){return za(n,{startRow:0,startColumn:0,endRow:0,endColumn:0})}function za(n,r){const e=n.worksheet.getCellInfoInMergeData(r.startRow,r.startColumn),t=n.worksheet.getCellInfoInMergeData(r.endRow,r.endColumn);return{range:{startRow:e.startRow,startColumn:e.startColumn,endRow:t.endRow,endColumn:t.endColumn,rangeType:a.RANGE_TYPE.NORMAL},primary:{actualRow:e.startRow,actualColumn:e.startColumn,startRow:e.startRow,startColumn:e.startColumn,endRow:e.endRow,endColumn:e.endColumn,isMerged:e.isMerged,isMergedMainCell:e.isMergedMainCell},style:null}}var Jd=Object.defineProperty,$d=Object.getOwnPropertyDescriptor,eu=(n,r,e,t)=>{for(var i=t>1?void 0:t?$d(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&Jd(r,e,i),i},Mt=(n,r)=>(e,t)=>r(e,t,n);exports.EditorBridgeService=class extends a.Disposable{constructor(e,t,i,o,s,l,c){super();T(this,"_editorUnitId",a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);T(this,"_editorIsDirty",!1);T(this,"_isDisabled",!1);T(this,"_visible",{visible:!1,eventType:y.DeviceInputEventType.Dblclick,unitId:""});T(this,"_currentEditCell",null);T(this,"_currentEditCellState",null);T(this,"_currentEditCellLayout",null);T(this,"_currentEditCellState$",new O.BehaviorSubject(null));T(this,"currentEditCellState$",this._currentEditCellState$.asObservable());T(this,"_currentEditCellLayout$",new O.BehaviorSubject(null));T(this,"currentEditCellLayout$",this._currentEditCellLayout$.asObservable());T(this,"currentEditCell$",this._currentEditCellState$.pipe(O.switchMap(e=>this._currentEditCellLayout$.pipe(O.map(t=>e&&t?{...e,...t}:null)))));T(this,"_visible$",new O.BehaviorSubject(this._visible));T(this,"visible$",this._visible$.asObservable());T(this,"_afterVisible$",new O.BehaviorSubject(this._visible));T(this,"afterVisible$",this._afterVisible$.asObservable());T(this,"_forceKeepVisible$",new O.BehaviorSubject(!1));T(this,"forceKeepVisible$",this._forceKeepVisible$.asObservable());this._sheetInterceptorService=e,this._renderManagerService=t,this._themeService=i,this._univerInstanceService=o,this._editorService=s,this._refSelectionsService=l,this._contextService=c,this.disposeWithMe(a.toDisposable(()=>{this._currentEditCellState$.complete(),this._currentEditCell=null})),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).subscribe(d=>{var u;d.getUnitId()===((u=this._currentEditCellState)==null?void 0:u.unitId)&&this._clearCurrentEditCellState()})}refreshEditCellState(){const e=this.getLatestEditCellState();if(!e){this._currentEditCellState=null,this._currentEditCellLayout=null,this._currentEditCellState$.next(null),this._currentEditCellLayout$.next(null);return}const{position:t,scaleX:i,scaleY:o,canvasOffset:s,...l}=e;this._currentEditCellState=l,this._currentEditCellLayout={position:t,scaleX:i,scaleY:o,canvasOffset:s},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}refreshEditCellPosition(e){var w;const t=this._currentEditCell;if(t==null)return;const i=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!i)return;const o=(w=i.with(exports.SheetSkeletonManagerService).getWorksheetSkeleton(t.sheetId))==null?void 0:w.skeleton,s=i.with(_e);if(!o||!this._currentEditCellState)return;const{primary:l,unitId:c,sheetId:d,scene:u,engine:h}=t,g=qn(o,l);if(g==null)return;const S=a.convertCellToRange(g),f=J.getCanvasOffsetByEngine(h);let{startX:p,startY:v,endX:C,endY:_}=S;const{scaleX:b,scaleY:E}=u.getAncestorScale(),M=u.getViewportScrollXY(s.getViewPort());p=o.convertTransformToOffsetX(p,b,M),v=o.convertTransformToOffsetY(v,E,M),C=o.convertTransformToOffsetX(C,b,M),_=o.convertTransformToOffsetY(_,E,M),e&&this._currentEditCellLayout&&(C=C-p+this._currentEditCellLayout.position.startX,_=_-v+this._currentEditCellLayout.position.startY,p=this._currentEditCellLayout.position.startX,v=this._currentEditCellLayout.position.startY),this._currentEditCellLayout={position:{startX:p,startY:v,endX:C,endY:_},canvasOffset:f,scaleX:b,scaleY:E},this._currentEditCellLayout$.next(this._currentEditCellLayout)}setEditCell(e){this._currentEditCell=e,this._editorService.getFocusEditor()||(this._editorService.focus(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_STANDALONE,!1));const t=this.getLatestEditCellState();if(!t){this._currentEditCellState=t,this._currentEditCellLayout=t,this._currentEditCellState$.next(t),this._currentEditCellLayout$.next(t);return}const{position:i,canvasOffset:o,scaleX:s,scaleY:l,...c}=t;this._currentEditCellState=c,this._currentEditCellLayout={position:i,canvasOffset:o,scaleX:s,scaleY:l},this._currentEditCellState$.next(this._currentEditCellState),this._currentEditCellLayout$.next(this._currentEditCellLayout)}_clearCurrentEditCellState(){this._currentEditCellState=null,this._currentEditCellState$.next(null),this._currentEditCellLayout=null,this._currentEditCellLayout$.next(null)}getEditCellState(){return this._currentEditCellState==null||this._currentEditCellLayout==null?null:{...this._currentEditCellState,...this._currentEditCellLayout}}getEditCellLayout(){return this._currentEditCellLayout}getEditLocation(){return this._currentEditCellState}getLatestEditCellState(){var B,V,U;const e=this._currentEditCell;if(e==null)return;const t=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!t)return;const i=t.with(exports.SheetSkeletonManagerService).getCurrentSkeleton(),o=t.with(_e);if(!i)return;const{primary:s,unitId:l,sheetId:c,scene:d,engine:u}=e,{startRow:h,startColumn:g}=s,S=qn(i,s);if(S==null)return;const f=a.convertCellToRange(S),p=J.getCanvasOffsetByEngine(u);let{startX:v,startY:C,endX:_,endY:b}=f;const{scaleX:E,scaleY:M}=d.getAncestorScale(),w=d.getViewportScrollXY(o.getViewPort());v=i.convertTransformToOffsetX(v,E,w),C=i.convertTransformToOffsetY(C,M,w),_=i.convertTransformToOffsetX(_,E,w),b=i.convertTransformToOffsetY(b,M,w);const P=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),x=P.getActiveSheet();if(!x)return;const A={workbook:P,worksheet:x,unitId:P.getUnitId(),subUnitId:x.getSheetId(),row:h,col:g,origin:x.getCellRaw(h,g)};let N;const D=this._sheetInterceptorService.writeCellInterceptor.fetchThroughInterceptors(m.BEFORE_CELL_EDIT)(x.getCell(h,g),A);N=D&&i.getCellDocumentModelWithFormula(D);const k=(B=N==null?void 0:N.documentModel)==null?void 0:B.documentStyle.renderConfig;if(k!=null&&(k.cellValueType=a.CellValueType.STRING),!N||N.documentModel==null){const F=i.getBlankCellDocumentModel(D);if(N!=null){const{verticalAlign:L,horizontalAlign:W,wrapStrategy:j,textRotation:z,fill:Z}=N,{centerAngle:te,vertexAngle:q}=y.convertTextRotation(z);F.documentModel.documentStyle.renderConfig={...k,verticalAlign:L,horizontalAlign:W,wrapStrategy:j,background:{rgb:Z},centerAngle:te,vertexAngle:q}}N=F}if(N.fill=N.fill||"#fff",(V=N.documentModel)==null||V.setZoomRatio(Math.max(E,M)),(D==null?void 0:D.isInArrayFormulaRange)===!0){const F=(U=N.documentModel)==null?void 0:U.getBody();F&&(F.textRuns=[{st:0,ed:F.dataStream.length-2,ts:{cl:{rgb:this._themeService.getCurrentTheme().textColorSecondary}}}])}return{position:{startX:v,startY:C,endX:_,endY:b},scaleX:E,scaleY:M,canvasOffset:p,row:h,column:g,unitId:l,sheetId:c,documentLayoutObject:N,editorUnitId:this._editorUnitId,isInArrayFormulaRange:D==null?void 0:D.isInArrayFormulaRange}}getCurrentEditorId(){return this._editorUnitId}changeVisible(e){this._visible=e,e.visible&&(this._editorIsDirty=!1),this._visible$.next(this._visible),this._afterVisible$.next(this._visible)}isVisible(){return this._visible}enableForceKeepVisible(){this._forceKeepVisible$.next(!0)}disableForceKeepVisible(){this._forceKeepVisible$.next(!1)}isForceKeepVisible(){return this._forceKeepVisible$.getValue()}changeEditorDirty(e){this._editorIsDirty=e}getEditorDirty(){return this._editorIsDirty}};exports.EditorBridgeService=eu([Mt(0,a.Inject(m.SheetInterceptorService)),Mt(1,y.IRenderManagerService),Mt(2,a.Inject(a.ThemeService)),Mt(3,a.IUniverInstanceService),Mt(4,J.IEditorService),Mt(5,m.IRefSelectionsService),Mt(6,a.IContextService)],exports.EditorBridgeService);const he=a.createIdentifier("univer.sheet-editor-bridge.service"),Me={id:"sheet.operation.set-cell-edit-visible",type:a.CommandType.OPERATION,handler:(n,r)=>r?(n.get(he).changeVisible(r),!0):!1},di={id:"sheet.operation.set-cell-edit-visible-f2",type:a.CommandType.OPERATION,handler:(n,r)=>{const e=n.get(a.ICommandService),i=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);return i?(e.syncExecuteCommand(Me.id,{...r,unitId:i.getUnitId()}),!0):!1}},Ft={id:"sheet.operation.set-cell-edit-visible-arrow",type:a.CommandType.OPERATION,handler:()=>!0},Pn={id:"sheet.command.change-zoom-ratio",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=n.get(a.IUniverInstanceService),t=m.getSheetCommandTarget(e);if(!t)return!1;const{worksheet:i,subUnitId:o,unitId:s}=t,{delta:l,reset:c}=r;let d=c?100:Math.round((i.getConfig().zoomRatio+l)*100);d=Math.max(Oo[0],d),d=Math.min(Oo[1],d);const u=d/100,g=n.get(he).isVisible();return(g.unitId===s||g.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&g.visible?!1:n.get(a.ICommandService).executeCommand(ze.id,{unitId:s,subUnitId:o,zoomRatio:u})}},On={id:"sheet.command.set-zoom-ratio",type:a.CommandType.COMMAND,handler:async(n,r)=>{if(!r)return!1;const{unitId:e,subUnitId:t,zoomRatio:i}=r,s=n.get(he).isVisible();return(s.unitId===e||s.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&s.visible?!1:n.get(a.ICommandService).executeCommand(ze.id,{unitId:e,subUnitId:t,zoomRatio:i})}};function tu(n){return typeof n.isMainScene>"u"}function Xe(n,r){const e=n instanceof a.Workbook?n:n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return null;const t=e.getUnitId();let i,o,s,l;if(tu(r)){const g=r.getRenderById(t);if(g==null)return null;i=g.components,i=g.components,o=g.mainComponent,s=g.scene,l=g.engine}else i=r.components,o=r.mainComponent,s=r.scene,l=r.engine;if(!i||!o)return null;const c=o,d=i.get(me.ROW),u=i.get(me.COLUMN),h=i.get(me.LEFT_TOP);return{spreadsheet:c,spreadsheetRowHeader:d,spreadsheetColumnHeader:u,spreadsheetLeftTopPlaceholder:h,scene:s,engine:l}}function Do(n,r,e,t){const{startX:i,startY:o,endX:s,endY:l}=t.getCellWithCoordByIndex(n,r);return{startX:i,startY:o,endX:s,endY:l}}function Ke(n,r,e,t,i,o){const s=e.getCoordRelativeToViewport(y.Vector2.FromArray([n,r])),{x:l,y:c}=s,d=e.getScrollXYInfoByViewport(s,i),{scaleX:u,scaleY:h}=e.getAncestorScale(),g=t.getCellIndexByOffset(l,c,u,h,d,{closeFirst:o}),{row:S,column:f}=g,p=t.getNoMergeCellPositionByIndex(S,f),{startX:v,startY:C,endX:_,endY:b}=p;return{startX:v,startY:C,endX:_,endY:b,row:S,column:f}}function Zn(n,r,e,t){const i=e.getCoordRelativeToViewport(y.Vector2.FromArray([n,r])),o=e.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=e.getScrollXYInfoByViewport(i,o),{scaleX:l,scaleY:c}=e.getAncestorScale(),{x:d,y:u}=s,h=n/l+d,g=r/c+u;return{x:h,y:g}}var nu=Object.defineProperty,iu=Object.getOwnPropertyDescriptor,ru=(n,r,e,t)=>{for(var i=t>1?void 0:t?iu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&nu(r,e,i),i},Di=(n,r)=>(e,t)=>r(e,t,n);let Qn=class extends a.Disposable{constructor(n,r,e,t,i){super(),this._context=n,this._sheetSkeletonManagerService=r,this._commandService=e,this._contextService=t,this._editorBridgeService=i,this._initSkeletonListener(),this._initZoomEventListener()}updateZoom(n,r){const e=this._context.unit.getSheetBySheetId(n);return e?(e.getConfig().zoomRatio=r,e===this._context.unit.getActiveSheet()&&this._updateViewZoom(r),!0):!1}_initZoomEventListener(){const n=this._getSheetObject().scene;this.disposeWithMe(n.onMouseWheel$.subscribeEvent(r=>{if(!r.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;if(this._editorBridgeService){const c=this._editorBridgeService.isVisible();if((c.unitId===this._context.unitId||c.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY)&&c.visible)return}const e=Math.abs(r.deltaX);let t=e<40?.2:e<80?.4:.2;t*=r.deltaY>0?-1:1,n.scaleX<1&&(t/=2);const i=this._context.unit,o=i.getActiveSheet();if(!o)return;const s=o.getZoomRatio();let l=+Number.parseFloat(`${s+t}`).toFixed(1);l=l>=4?4:l<=.1?.1:l,this._commandService.executeCommand(On.id,{zoomRatio:Math.round(l*10)/10,unitId:i.getUnitId(),subUnitId:o.getSheetId()}),r.preventDefault()}))}_initSkeletonListener(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(n=>{if(n==null)return;const e=this._context.unit.getActiveSheet();if(!e)return;const t=e.getZoomRatio()||1;this._updateViewZoom(t)}))}_updateViewZoom(n){const r=this._getSheetObject();r==null||r.scene.scale(n,n),r==null||r.spreadsheet.makeForceDirty()}_getSheetObject(){return Xe(this._context.unit,this._context)}};Qn=ru([Di(1,a.Inject(exports.SheetSkeletonManagerService)),Di(2,a.ICommandService),Di(3,a.IContextService),Di(4,a.Optional(he))],Qn);const ze={id:"sheet.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(n,r)=>{const t=n.get(y.IRenderManagerService).getRenderById(r.unitId);return t?t.with(Qn).updateZoom(r.subUnitId,r.zoomRatio):!1}};var ou=Object.defineProperty,su=Object.getOwnPropertyDescriptor,au=(n,r,e,t)=>{for(var i=t>1?void 0:t?su(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&ou(r,e,i),i},Ur=(n,r)=>(e,t)=>r(e,t,n);const Ys="univer-sheet-main-canvas";exports.SheetsRenderService=class extends a.RxDisposable{constructor(e,t,i){super();T(this,"_skeletonChangeMutations",new Set);this._contextService=e,this._instanceSrv=t,this._renderManagerService=i,Promise.resolve().then(()=>this._init())}registerSkeletonChangingMutations(e){return this._skeletonChangeMutations.has(e)?a.toDisposable(()=>{}):(this._skeletonChangeMutations.add(e),a.toDisposable(()=>this._skeletonChangeMutations.delete(e)))}checkMutationShouldTriggerRerender(e){return this._skeletonChangeMutations.has(e)}_init(){this._initWorkbookListener(),this._initContextListener()}_initWorkbookListener(){this._instanceSrv.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.takeUntil(this.dispose$)).subscribe(e=>this._createRenderer(e)),this._instanceSrv.getAllUnitsForType(a.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._createRenderer(e)),this._instanceSrv.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.takeUntil(this.dispose$)).subscribe(e=>this._disposeRenderer(e))}_createRenderer(e){const t=e.getUnitId();this._renderManagerService.created$.subscribe(i=>{i.unitId===t&&(i.engine.getCanvas().setId(`${Ys}_${t}`),i.engine.getCanvas().getContext().setId(`${Ys}_${t}`))}),this._renderManagerService.createRender(t),this._renderManagerService.setCurrent(t)}_disposeRenderer(e){const t=e.getUnitId();this._renderManagerService.removeRender(t)}_initContextListener(){this.disposeWithMe(this._contextService.subscribeContextValue$(y.RENDER_RAW_FORMULA_KEY).pipe(O.distinctUntilChanged()).subscribe(()=>{this._renderManagerService.getRenderAll().forEach(e=>{e.mainComponent instanceof y.Spreadsheet&&e.mainComponent.makeForceDirty(!0)})}))}};exports.SheetsRenderService=au([Ur(0,a.IContextService),Ur(1,a.IUniverInstanceService),Ur(2,y.IRenderManagerService)],exports.SheetsRenderService);var lu=Object.defineProperty,cu=Object.getOwnPropertyDescriptor,du=(n,r,e,t)=>{for(var i=t>1?void 0:t?cu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&lu(r,e,i),i},Pt=(n,r)=>(e,t)=>r(e,t,n);exports.AutoFillController=class extends a.Disposable{constructor(e,t,i,o,s,l,c){super();T(this,"_beforeApplyData",[]);T(this,"_currentLocation",null);T(this,"_copyData",[]);T(this,"_defaultHook");this._univerInstanceService=e,this._commandService=t,this._autoFillService=i,this._editorBridgeService=o,this._renderManagerService=s,this._injector=l,this._sheetsRenderService=c,this._defaultHook={id:"default",type:cn.Default,priority:0,onBeforeFillData:(d,u)=>this._presetAndCacheData(d,u),onFillData:(d,u,h)=>this._fillData(d,u,h)},this._init()}_init(){this._initDefaultHook(),this._onSelectionControlFillChanged(),this._initQuitListener(),this._initSkeletonChange()}_initSkeletonChange(){this.disposeWithMe(this._sheetsRenderService.registerSkeletonChangingMutations(Ct.id))}_initDefaultHook(){this.disposeWithMe(this._autoFillService.addHook(this._defaultHook))}_initQuitListener(){const e=[Me.id,In.id,m.SetRangeValuesCommand.id,ze.id,m.SetWorksheetActiveOperation.id,m.MoveRangeMutation.id,m.RemoveRowMutation.id,m.RemoveColMutation.id,m.InsertRowMutation.id,m.InsertColMutation.id,m.MoveRowsMutation.id,m.MoveColsMutation.id,m.SetWorksheetColWidthMutation.id,m.SetWorksheetRowHeightMutation.id,m.SetRangeValuesMutation.id];this.disposeWithMe(this._commandService.onCommandExecuted((t,i)=>{var c,d;const o=i==null?void 0:i.fromCollab,s=i==null?void 0:i.fromSync,l=i==null?void 0:i.fromFormula;e.includes(t.id)&&!o&&!s&&!l&&t.params.trigger!==Ct.id&&t.params.trigger!==li.id&&this._quit(),t.id===m.RemoveSheetMutation.id&&t.params.unitId===((c=this._currentLocation)==null?void 0:c.unitId)&&t.params.subUnitId===((d=this._currentLocation)==null?void 0:d.subUnitId)&&this._quit()})),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{var i;t.getUnitId()===((i=this._currentLocation)==null?void 0:i.unitId)&&this._quit()}))}_quit(){this._currentLocation=null,this._beforeApplyData=[],this._copyData=[],this._autoFillService.setShowMenu(!1)}_onSelectionControlFillChanged(){const e=new a.DisposableCollection,t=i=>{i.dispose();const o=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_SHEET);if(!o)return;o.with(_e).getSelectionControls().forEach(c=>{i.add(a.toDisposable(c.selectionFilled$.subscribe(d=>{if(d==null||d.startColumn===-1||d.startRow===-1||d.endColumn===-1||d.endRow===-1)return;const u={startColumn:c.model.startColumn,endColumn:c.model.endColumn,startRow:c.model.startRow,endRow:c.model.endRow},h={startColumn:d.startColumn,endColumn:d.endColumn,startRow:d.startRow,endRow:d.endRow};this._commandService.executeCommand(Ct.id,{sourceRange:u,targetRange:h})}))),i.add(a.toDisposable(c.fillControl.onDblclick$.subscribeEvent(()=>{const d={startColumn:c.model.startColumn,endColumn:c.model.endColumn,startRow:c.model.startRow,endRow:c.model.endRow};this._handleDbClickFill(d)}))),i.add(a.toDisposable(c.fillControl.onPointerDown$.subscribeEvent(()=>{this._editorBridgeService.isVisible().visible&&this._editorBridgeService.changeVisible({visible:!1,eventType:y.DeviceInputEventType.PointerDown,unitId:o.unitId})})))})};t(e),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===m.SetSelectionsOperation.id&&t(e)}))}_handleDbClickFill(e){const t=this._detectFillRange(e);t.endRow<=e.endRow||this._commandService.executeCommand(Ct.id,{sourceRange:e,targetRange:t})}_detectFillRange(e){var g,S,f,p,v,C;const{startRow:t,endRow:i,startColumn:o,endColumn:s}=e,l=(g=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET))==null?void 0:g.getActiveSheet();if(!l)return e;const c=l.getCellMatrix(),d=l.getMaxRows()-1,u=l.getMaxColumns()-1;let h=i;if(o>0&&((S=c.getValue(t,o-1))==null?void 0:S.v)!=null){let _=t;for(;((f=c.getValue(_,o-1))==null?void 0:f.v)!=null&&_<d;)_+=1;h=_-1}else if(s<u&&((p=c.getValue(i,s+1))==null?void 0:p.v)!=null){let _=t;for(;((v=c.getValue(_,s+1))==null?void 0:v.v)!=null&&_<d;)_+=1;h=_-1}for(let _=i+1;_<=h;_++)for(let b=o;b<=s;b++)if(((C=c.getValue(_,b))==null?void 0:C.v)!=null){h=_-1;break}return{startColumn:o,endColumn:s,startRow:t,endRow:h}}_getApplyData(e,t,i,o,s,l=!0){const c=[],d=Math.floor(i/t),u=i%t,h=this._autoFillService.getRules();if(!l&&s===se.ONLY_FORMAT)return console.error("ERROR: only format can not be applied when hasStyle is false"),[];const g={};h.forEach(S=>{g[S.type]=[]}),h.forEach(S=>{const{type:f,applyFunctions:p={}}=S,v=e[f];v&&v.forEach(C=>{const _=Od(C.index,u),b=C.index.length*d+_,E=this._applyFunctions(C,b,o,s,p,e),M=xd(t,i,C.index);g[f].push({data:E,index:M})})});for(let S=0;S<i;S++)h.forEach(f=>{const{type:p}=f,v=g[p];for(let C=0;C<v.length;C++)S in v[C].index&&c.push(v[C].data[v[C].index[S]])});return c}_applyFunctions(e,t,i,o,s,l){const{data:c}=e,d=i===a.Direction.UP||i===a.Direction.LEFT;if(o===se.COPY){const u=s==null?void 0:s[se.COPY];return u?u(e,t,i,l):(d&&c.reverse(),Bt(c,t))}if(o===se.SERIES){const u=s==null?void 0:s[se.SERIES];return u?u(e,t,i,l):(d&&c.reverse(),s!=null&&s[se.COPY]?s[se.COPY](e,t,i,l):Bt(c,t))}if(o===se.ONLY_FORMAT){const u=s==null?void 0:s[se.ONLY_FORMAT];return u?u(e,t,i,l):Ad(c,t)}}_getCopyData(e,t){const i=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!i)throw new Error("No active sheet found");const o=i.getCellMatrix(),s=this._autoFillService.getRules(),l=[],c=t===a.Direction.DOWN||t===a.Direction.UP;let d,u;return c?(d=e.cols,u=e.rows):(d=e.rows,u=e.cols),d.forEach(h=>{const g=this._getEmptyCopyDataPiece(),S={type:void 0,cellData:void 0};u.forEach(f=>{let p;c?p=o.getValue(f,h):p=o.getValue(h,f);const{type:v,isContinue:C}=s.find(_=>_.match(p,this._injector))||Fa;if(C(S,p)){const _=g[v],b=_[_.length-1];b.data.push(p),b.index.push(f-u[0])}else{const _=g[v];_?_.push({data:[p],index:[f-u[0]]}):g[v]=[{data:[p],index:[f-u[0]]}]}S.type=v,S.cellData=p}),l.push(g)}),l}_getEmptyCopyDataPiece(){const e={};return this._autoFillService.getRules().forEach(t=>{e[t.type]=[]}),e}_getMergeApplyData(e,t,i,o){const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=[];for(let c=e.startRow;c<=e.endRow;c++)for(let d=e.startColumn;d<=e.endColumn;d++){const{isMergedMainCell:u,startRow:h,startColumn:g,endRow:S,endColumn:f}=s.getCellInfoInMergeData(c,d);if(u){if(i===a.Direction.DOWN){let p=h+o,v=S+o;for(;v<=t.endRow;)l.push({startRow:p,startColumn:g,endRow:v,endColumn:f}),p+=o,v+=o}else if(i===a.Direction.UP){let p=h-o,v=S-o;for(;p>=t.startRow;)l.push({startRow:p,startColumn:g,endRow:v,endColumn:f}),p-=o,v-=o}else if(i===a.Direction.RIGHT){let p=g+o,v=f+o;for(;v<=t.endColumn;)l.push({startRow:h,startColumn:p,endRow:S,endColumn:v}),p+=o,v+=o}else if(i===a.Direction.LEFT){let p=g-o,v=f-o;for(;p>=t.startColumn;)l.push({startRow:h,startColumn:p,endRow:S,endColumn:v}),p-=o,v-=o}}}return l}_presetAndCacheData(e,t){const{source:i,target:o}=e,s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet();if(!s)throw new Error("No active sheet found");const l=s.getCellMatrix(),c=[];return o.rows.forEach(d=>{const u=[];o.cols.forEach(h=>{u.push(a.Tools.deepClone(l.getValue(d,h)))}),c.push(u)}),this._beforeApplyData=c,this._copyData=this._getCopyData(i,t),this._currentLocation=e,this._shouldDisableSeries(this._copyData)?(this._autoFillService.setDisableApplyType(se.SERIES,!0),se.COPY):(this._autoFillService.setDisableApplyType(se.SERIES,!1),this._getPreferredApplyType(this._copyData))}_fillData(e,t,i){var B,V;const o=[],s=[];let l=!0;i===se.NO_FORMAT&&(l=!1,i=se.SERIES);const{source:c,target:d,unitId:u,subUnitId:h}=e;if(!c||!d||t==null)return{undos:o,redos:s};const g=_t(c),S=_t(d),{cols:f,rows:p}=d,{cols:v,rows:C}=c,_=this._copyData;let b;t===a.Direction.DOWN||t===a.Direction.UP?b=C.length:b=v.length;const E=[];if(t===a.Direction.DOWN||t===a.Direction.UP){const U=p.length,F=[];f.forEach((L,W)=>{const j=_[W],z=this._getApplyData(j,b,U,t,i,l);F.push(z)});for(let L=0;L<F[0].length;L++){const W=[];for(let j=0;j<F.length;j++)W.push({s:null,...F[j][L]});E.push(W)}}else{const U=f.length;p.forEach((F,L)=>{const W=_[L],j=this._getApplyData(W,b,U,t,i,l),z=[];for(let Z=0;Z<j.length;Z++)z.push({s:null,...j[Z]});E.push(z)})}let M=[];const w=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getStyles();if(l?(M=this._getMergeApplyData(g,S,t,b),E.forEach(U=>{U.forEach(F=>{F&&w&&w&&(F.s=w.getStyleByCell(F))})})):E.forEach((U,F)=>{U.forEach((L,W)=>{L&&w&&(L.s=w.getStyleByCell(this._beforeApplyData[F][W])||null)})}),i===se.ONLY_FORMAT&&E.forEach((U,F)=>{U.forEach((L,W)=>{if(L){const j=this._beforeApplyData[F][W]||{};L.f=j.f,L.si=j.si,L.t=j.t,L.v=j.v}})}),l){const U=[],F=(V=(B=this._univerInstanceService.getUniverSheetInstance(u))==null?void 0:B.getSheetBySheetId(h))==null?void 0:V.getMergeData();F&&F.forEach(j=>{a.Rectangle.intersects(j,S)&&U.push(j)});const L={unitId:u,subUnitId:h,ranges:U},W=this._injector.invoke(m.RemoveMergeUndoMutationFactory,L);U.length&&(s.push({id:m.RemoveWorksheetMergeMutation.id,params:L}),o.unshift({id:m.AddWorksheetMergeMutation.id,params:W}))}const P={subUnitId:h,unitId:u,cellValue:Rd([d])},x=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,P);s.push({id:m.SetRangeValuesMutation.id,params:P}),o.unshift({id:m.SetRangeValuesMutation.id,params:x});const A=new a.ObjectMatrix;p.forEach((U,F)=>{f.forEach((L,W)=>{E[F][W]&&A.setValue(U,L,E[F][W])})});const N=A.getMatrix(),D={subUnitId:h,unitId:u,cellValue:N},k=this._injector.invoke(m.SetRangeValuesUndoMutationFactory,D);if(this._autoFillService.getActiveHooks().forEach(U=>{var F;(F=U.onBeforeSubmit)==null||F.call(U,e,t,i,N)}),o.unshift({id:m.SetRangeValuesMutation.id,params:k}),s.push({id:m.SetRangeValuesMutation.id,params:D}),M!=null&&M.length){const U=m.getAddMergeMutationRangeByType(M),F={unitId:u,subUnitId:h,ranges:U},L=this._injector.invoke(m.AddMergeUndoMutationFactory,F);o.unshift({id:m.RemoveWorksheetMergeMutation.id,params:L}),s.push({id:m.AddWorksheetMergeMutation.id,params:F})}return{undos:o,redos:s}}_shouldDisableSeries(e){return e.every(t=>Object.keys(t).every(i=>{var o;return((o=t[i])==null?void 0:o.length)===0||[ve.OTHER,ve.FORMULA].includes(i)}))}_getPreferredApplyType(e){return e.every(i=>Object.keys(i).every(o=>{var s,l;return((s=i[o])==null?void 0:s.length)===0||((l=i[o])==null?void 0:l.length)===1&&i[o][0].data.length===1&&ve.NUMBER===o}))?se.COPY:se.SERIES}};exports.AutoFillController=du([Pt(0,a.IUniverInstanceService),Pt(1,a.ICommandService),Pt(2,Tt),Pt(3,he),Pt(4,y.IRenderManagerService),Pt(5,a.Inject(a.Injector)),Pt(6,a.Inject(exports.SheetsRenderService))],exports.AutoFillController);var uu=Object.defineProperty,hu=Object.getOwnPropertyDescriptor,mu=(n,r,e,t)=>{for(var i=t>1?void 0:t?hu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&uu(r,e,i),i},Lr=(n,r)=>(e,t)=>r(e,t,n);exports.CellCustomRenderController=class extends a.Disposable{constructor(e,t,i,o){super();T(this,"_enterActiveRender");this._context=e,this._sheetSkeletonManagerService=t,this._renderManagerService=i,this._permissionService=o,this._initEventBinding()}_initEventBinding(){const e=new a.DisposableCollection,t=this._context.unit,i=o=>{if(e.dispose(),!o)return;const s=this._context.unitId,{skeleton:l}=o,c=this._renderManagerService.getRenderById(s);if(c&&c.mainComponent){const d=c.mainComponent,u=S=>{const{offsetX:f,offsetY:p}=S,v=c.scene,C=t.getActiveSheet();if(!C)return;const _=v.getActiveViewportByCoord(y.Vector2.FromArray([f,p]));if(!_)return;const{scaleX:b,scaleY:E}=v.getAncestorScale(),M={x:_.viewportScrollX,y:_.viewportScrollY},w=l.getCellIndexByOffset(f,p,b,E,M),P=l.worksheet.getMergedCell(w.row,w.column),x={actualRow:P?P.startRow:w.row,actualCol:P?P.startColumn:w.column,mergeCell:P,row:w.row,col:w.column};if(!x||!l)return;const A=C.getCell(x.actualRow,x.actualCol);if(!A)return;const N=A.customRender;if(!(N!=null&&N.length))return;const D=x.actualRow,k=x.actualCol,B=N.sort(a.sortRules),V=C.getSheetId(),U={data:A,style:l.getsStyles().getStyleByCell(A),primaryWithCoord:l.getCellWithCoordByIndex(x.actualRow,x.actualCol),unitId:s,subUnitId:V,row:D,col:k,workbook:t,worksheet:C},F={x:M.x+f/b,y:M.y+p/E},L=B.find(W=>{var j;return(j=W.isHit)==null?void 0:j.call(W,F,U)});if(L)return[L,U]},h=d.onPointerDown$.subscribeEvent(S=>{var p,v,C,_;const f=u(S);if(f){const[b,E]=f,{row:M,col:w,worksheet:P,unitId:x,subUnitId:A}=E;if(!((p=this._permissionService.composePermission([new m.WorkbookEditablePermission(x).id,new m.WorksheetEditPermission(x,A).id]))==null?void 0:p.every(k=>k.value)))return!1;const D=(C=(v=P.getCell(M,w))==null?void 0:v.selectionProtection)==null?void 0:C[0];if((D==null?void 0:D[m.UnitAction.Edit])===!1)return!1;(_=b.onPointerDown)==null||_.call(b,E,S)}}),g=a.fromEventSubject(d.onPointerMove$).pipe(O.throttleTime(30)).subscribe(S=>{var p,v,C,_,b,E;const f=u(S);if(f){const[M,w]=f;this._enterActiveRender?this._enterActiveRender.render!==M&&((v=(p=this._enterActiveRender.render).onPointerLeave)==null||v.call(p,this._enterActiveRender.cellContext,S),this._enterActiveRender={render:M,cellContext:w},(C=M.onPointerEnter)==null||C.call(M,w,S)):(this._enterActiveRender={render:M,cellContext:w},(_=M.onPointerEnter)==null||_.call(M,w,S))}else this._enterActiveRender&&((E=(b=this._enterActiveRender.render).onPointerLeave)==null||E.call(b,this._enterActiveRender.cellContext,S),this._enterActiveRender=null)});h&&e.add(h),g&&e.add(g)}};this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(i)),i(this._sheetSkeletonManagerService.getCurrent()),this.disposeWithMe(e)}};exports.CellCustomRenderController=mu([Lr(1,a.Inject(exports.SheetSkeletonManagerService)),Lr(2,y.IRenderManagerService),Lr(3,a.IPermissionService)],exports.CellCustomRenderController);class cs extends a.Disposable{constructor(){super(...arguments);T(this,"rangesStack",[]);T(this,"selectedRangeWorksheet","")}}var gu=Object.defineProperty,Su=Object.getOwnPropertyDescriptor,fu=(n,r,e,t)=>{for(var i=t>1?void 0:t?Su(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&gu(r,e,i),i},Gs=(n,r)=>(e,t)=>r(e,t,n);let _n=class{constructor(n,r){T(this,"_current",null);T(this,"_shortcutParam",[]);this._univerInstanceService=n,this._localeService=r}dispose(){this._shortcutParam=[]}getCurrentBySearch(n){return this._getCurrentBySearch(n)}getCurrent(){return this._getCurrentBySearch(this._current)}addOrUpdate(n){const r=this._getCurrentBySearch({unitId:n.unitId,sheetId:n.sheetId,keycode:n.keycode});if(r!=null){const e=this._shortcutParam.indexOf(r);this._shortcutParam.splice(e,1)}return this._shortcutParam.push(n),r}remove(n){if(n==null)return;const r=this._getCurrentBySearch(n);if(r==null)return;const e=this._shortcutParam.indexOf(r);return this._shortcutParam.splice(e,1)[0]}_getCurrentBySearch(n){return n==null?void 0:this._shortcutParam.find(e=>e.unitId===n.unitId&&e.sheetId===n.sheetId&&e.keycode===n.keycode)}};_n=fu([Gs(0,a.IUniverInstanceService),Gs(1,a.Inject(a.LocaleService))],_n);var Er=(n=>(n.MergeAll="mergeAll",n.MergeVertical="mergeVertical",n.MergeHorizontal="mergeHorizontal",n))(Er||{});function It(n,r,e,t,i=!0,o=1,s=!0){let l={...n};t==null&&(t={startRow:0,endRow:e.getRowCount()-1,startColumn:0,endColumn:e.getColumnCount()-1});let c;switch(r){case a.Direction.UP:for(c=n.startRow-o;c>-1&&!e.getRowVisible(c);)c-=1;c>=t.startRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.endRow,l.endRow=t.endRow,i&&(l=It(l,a.Direction.LEFT,e,t,!1)));break;case a.Direction.DOWN:for(c=n.endRow+o;c<e.getRowCount()&&!e.getRowVisible(c);)c+=1;c<=t.endRow?(l.startRow=c,l.endRow=c):s&&(l.startRow=t.startRow,l.endRow=t.startRow,i&&(l=It(l,a.Direction.RIGHT,e,t,!1)));break;case a.Direction.LEFT:for(c=n.startColumn-o;c>-1&&!e.getColVisible(c);)c-=1;c>=t.startColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.endColumn,l.endColumn=t.endColumn,i&&(l=It(l,a.Direction.UP,e,t,!1)));break;case a.Direction.RIGHT:for(c=n.endColumn+o;c<e.getColumnCount()&&!e.getColVisible(c);)c+=1;c<=t.endColumn?(l.startColumn=c,l.endColumn=c):s&&(l.startColumn=t.startColumn,l.endColumn=t.startColumn,i&&(l=It(l,a.Direction.DOWN,e,t,!1)));break}return l}function ds(n,r,e){const t={...n},{startRow:i,startColumn:o,endRow:s,endColumn:l}=Jn(n,r,e);let c=Hn(e,i,o,s,l).hasValue,d=!0,u=!0;for(;u;){if(a.Direction.UP===r){let h=t.startRow-1;for(;h>-1&&!e.getRowVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=Hn(e,h,t.startColumn,h,t.endColumn);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue(p=>{f=Math.min(p,f)}),t.startRow=f}else t.startRow=h;if(t.endRow=t.startRow,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.DOWN===r){let h=t.endRow+1;for(;h<e.getRowCount()&&!e.getRowVisible(h);)h+=1;if(h===e.getRowCount()){u=!1;break}const{hasValue:g,matrix:S}=Hn(e,h,t.startColumn,h,t.endColumn);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v,C)=>{f=Math.max(p+(C.rowSpan||1)-1,f)}),t.endRow=f}else t.endRow=h;if(t.startRow=t.endRow,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.LEFT===r){let h=t.startColumn-1;for(;h>-1&&!e.getColVisible(h);)h-=1;if(h===-1){u=!1;break}const{hasValue:g,matrix:S}=Hn(e,t.startRow,h,t.endRow,h);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v)=>{f=Math.min(v,f)}),t.startColumn=f}else t.startColumn=h;if(t.endColumn=t.startColumn,!c&&g){u=!1;break}c=g,d=!1}}if(a.Direction.RIGHT===r){let h=t.endColumn+1;for(;h<e.getColumnCount()&&!e.getColVisible(h);)h+=1;if(h===e.getColumnCount()){u=!1;break}const{hasValue:g,matrix:S}=Hn(e,t.startRow,h,t.endRow,h);if(c&&!g&&!d){u=!1;break}else{if(S.getLength()!==0){let f=h;S.forValue((p,v,C)=>{f=Math.max(v+(C.colSpan||1)-1,f)}),t.endColumn=f}else t.endColumn=h;if(t.startColumn=t.endColumn,!c&&g){u=!1;break}c=g,d=!1}}}return m.alignToMergedCellsBorders(t,e,!0)}function Xa(n,r,e){return It(n,r,e,void 0,!1,1,!1)}function pu(n,r,e){const t=ds(n,r,e);return m.alignToMergedCellsBorders(a.Rectangle.union(t,n),e,!0)}function vu(n,r,e){const t=Xa(n,r,e),i={startRow:Math.min(n.startRow,t.startRow),startColumn:Math.min(n.startColumn,t.startColumn),endRow:Math.max(n.endRow,t.endRow),endColumn:Math.max(n.endColumn,t.endColumn)};return m.alignToMergedCellsBorders(a.Rectangle.union(n,i),e)}function Cu(n,r,e,t){const i=a.getReverseDirection(e),o=ds(Jn(n,i,t),e,t);return e===a.Direction.UP&&o.startRow<=n.startRow?m.alignToMergedCellsBorders({...r,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.DOWN&&o.endRow>=n.endRow?m.alignToMergedCellsBorders({...r,startColumn:n.startColumn,endColumn:n.endColumn},t,!0):e===a.Direction.LEFT&&o.startColumn<=n.startColumn?m.alignToMergedCellsBorders({...r,startRow:n.startRow,endRow:n.endRow},t,!0):e===a.Direction.RIGHT&&o.endColumn>=n.endColumn?m.alignToMergedCellsBorders({...r,startRow:n.startRow,endRow:n.endRow},t,!0):a.Rectangle.union(a.Rectangle.clone(r),o)}function Iu(n,r,e){const t=a.getReverseDirection(r),i=Jn(n,t,e),o=Jn(n,r,e),s=Xa(i,r,e);return m.alignToMergedCellsBorders(a.Rectangle.union(o,s),e,!1)}function Zs(n){return{startRow:0,startColumn:0,endRow:n.getRowCount()-1,endColumn:n.getColumnCount()-1,rangeType:a.RANGE_TYPE.ALL}}function Jn(n,r,e){let t;switch(r){case a.Direction.UP:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.startRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.DOWN:t={startRow:n.endRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.LEFT:t={startRow:n.startRow,startColumn:n.startColumn,endRow:n.endRow,endColumn:n.startColumn,rangeType:a.RANGE_TYPE.NORMAL};break;case a.Direction.RIGHT:t={startRow:n.startRow,startColumn:n.endColumn,endRow:n.endRow,endColumn:n.endColumn,rangeType:a.RANGE_TYPE.NORMAL};break;default:throw new Error("Invalid direction")}return m.alignToMergedCellsBorders(t,e,!1)}function Hn(n,r,e,t,i){let o=!1;const s=n.getMatrixWithMergedCells(r,e,t,i).forValue((l,c,d)=>{if(bu(d))return o=!0,!1});return{hasValue:o,matrix:s}}function ko(n,r,e){const t=a.Rectangle.clone(n);if(r==null)return t;switch(e){case a.Direction.UP:case a.Direction.DOWN:t.startColumn=t.endColumn=r.actualColumn;break;case a.Direction.LEFT:case a.Direction.RIGHT:t.startRow=t.endRow=r.actualRow;break}return t}function _u(n,r,e){var l,c,d,u;const{primary:t,range:i}=n,o=a.Rectangle.clone(i);switch(r){case a.Direction.UP:case a.Direction.DOWN:o.startRow=(l=t==null?void 0:t.startRow)!=null?l:i.startRow,o.endRow=(c=t==null?void 0:t.endRow)!=null?c:i.startRow;break;case a.Direction.LEFT:case a.Direction.RIGHT:o.startColumn=(d=t==null?void 0:t.startColumn)!=null?d:i.startColumn,o.endColumn=(u=t==null?void 0:t.endColumn)!=null?u:i.startColumn;break}const s=Jn(o,r,e);switch(r){case a.Direction.DOWN:return i.startRow<s.startRow;case a.Direction.UP:return i.endRow>s.endRow;case a.Direction.LEFT:return s.endColumn<i.endColumn;case a.Direction.RIGHT:return s.startColumn>i.startColumn}}function Ya(n,r){let e=n[0].startRow,t=n[0].endRow;n.forEach(o=>{const{startRow:s,endRow:l}=o;e=Math.min(e,s),t=Math.max(t,l)});const i=new Array(t-e+1).fill(!1);return r.forEach(o=>{const{startRow:s,endRow:l}=o;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)i[c-e]=!0}),n.every(o=>{const{startRow:s,endRow:l}=o;for(let c=s;c<=l;c++)if(!i[c-e])return!1;return!0})}function Ga(n,r){let e=n[0].startColumn,t=n[0].endColumn;n.forEach(o=>{const{startColumn:s,endColumn:l}=o;e=Math.min(e,s),t=Math.max(t,l)});const i=new Array(t-e+1).fill(!1);return r.forEach(o=>{const{startColumn:s,endColumn:l}=o;for(let c=Math.max(s,e);c<=Math.min(l,t);c++)i[c-e]=!0}),n.every(o=>{const{startColumn:s,endColumn:l}=o;for(let c=s;c<=l;c++)if(!i[c-e])return!1;return!0})}function us(n,r){return r?n==="mergeAll"?r.filter(e=>!(e.startRow===e.endRow&&e.startColumn===e.endColumn)):n==="mergeVertical"?r.filter(e=>e.startRow!==e.endRow):n==="mergeHorizontal"?r.filter(e=>e.startColumn!==e.endColumn):r:null}function bu(n){return n.v!==void 0&&n.v!==null&&n.v!==""||n.p!==void 0}var $e=(n=>(n[n.moveStopeOne=0]="moveStopeOne",n[n.moveGap=1]="moveGap",n[n.moveStepPage=2]="moveStepPage",n[n.moveStepEnd=3]="moveStepEnd",n))($e||{});const xe={id:"sheet.command.move-selection",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:i}=e,o=m.getSelectionsService(n,r.fromCurrentSelection).getCurrentLastSelection();if(!o)return!1;const{direction:s,jumpOver:l,extra:c}=r,{range:d,primary:u}=o,h=ko(d,u,s),g=l===1?ds(h,s,i):It(h,s,i),S=m.getCellAtRowCol(g.startRow,g.startColumn,i);if(a.Rectangle.equals(S,h))return!1;const f=t.getUnitId();n.get(_n).remove({unitId:f,sheetId:i.getSheetId(),keycode:R.KeyCode.TAB});const p=[{range:a.Rectangle.clone(S),primary:{startRow:S.startRow,startColumn:S.startColumn,endRow:S.endRow,endColumn:S.endColumn,actualRow:g.startRow,actualColumn:g.startColumn,isMerged:S.isMerged,isMergedMainCell:S.startRow===g.startRow&&S.startColumn===g.startColumn}}];return n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:t.getUnitId(),subUnitId:i.getSheetId(),selections:p,type:m.SelectionMoveType.MOVE_END,extra:c})}},et={id:"sheet.command.move-selection-enter-tab",type:a.CommandType.COMMAND,handler:(n,r)=>{var U;if(!r)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{workbook:t,worksheet:i}=e,o=m.getSelectionsService(n),{direction:s,keycode:l}=r,c=s===a.Direction.LEFT||s===a.Direction.UP,d=o.getCurrentSelections().concat(),u=d.findIndex(F=>F.primary),h=d[u];if(!h)return!1;const g=c?-1:1,S=u+g!==d.length?d[u+g]:d[0],f=d.findIndex(F=>F===S),p=t.getUnitId(),v=i.getSheetId();if(!h)return!1;const{range:C}=h,_=h.primary;let b=ko(C,_,s);const E=n.get(_n),M=E.getCurrentBySearch({unitId:p,sheetId:v,keycode:R.KeyCode.TAB});let w;const{startRow:P,endRow:x,startColumn:A,endColumn:N}=C,D=c?_.startRow===P&&_.startColumn===A:_.endRow===x&&_.endColumn===N;if(a.Rectangle.equals(C,_)){if(l===R.KeyCode.TAB)M==null&&E.addOrUpdate({unitId:p,sheetId:v,keycode:R.KeyCode.TAB,selection:h});else{const W=M==null?void 0:M.selection;if(W!=null){const{range:j,primary:z}=W;b=ko(j,z,s)}E.remove({unitId:p,sheetId:v,keycode:R.KeyCode.TAB})}const F=It(b,s,i),L=m.getCellAtRowCol(F.startRow,F.startColumn,i);if(a.Rectangle.equals(L,b))return!1;w={range:a.Rectangle.clone(L),primary:{startRow:L.startRow,startColumn:L.startColumn,endRow:L.endRow,endColumn:L.endColumn,actualRow:F.startRow,actualColumn:F.startColumn,isMerged:L.isMerged,isMergedMainCell:L.startRow===F.startRow&&L.startColumn===F.startColumn}}}else{E.remove({unitId:p,sheetId:v,keycode:R.KeyCode.TAB});const F=a.Tools.deepClone(_),L=D?S.range:It({startRow:F.startRow,startColumn:F.startColumn,endRow:F.endRow,endColumn:F.endColumn},s,i,{startRow:P,endRow:x,startColumn:A,endColumn:N}),W=D&&c,j=W?m.getCellAtRowCol(L.endRow,L.endColumn,i):m.getCellAtRowCol(L.startRow,L.startColumn,i);w={range:D?S.range:a.Rectangle.clone(C),primary:{startRow:j.startRow,startColumn:j.startColumn,endRow:j.endRow,endColumn:j.endColumn,actualRow:W?j.startRow:L.startRow,actualColumn:W?j.startColumn:L.startColumn,isMerged:j.isMerged,isMergedMainCell:j.startRow===L.startRow&&j.startColumn===L.startColumn},style:D?S.style:h.style}}D?(d[u].primary=null,d[f]=w,o.setSelections(p,v,[],m.SelectionMoveType.MOVE_END)):d[u]=w;const k=n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:p,subUnitId:v,type:m.SelectionMoveType.MOVE_END,selections:d,extra:r.extra}),V=(U=n.get(y.IRenderManagerService).getRenderById(p))==null?void 0:U.with(_e);return V==null||V.refreshSelectionMoveEnd(),k}},ke={id:"sheet.command.expand-selection",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const{worksheet:t,unitId:i,subUnitId:o}=e,s=m.getSelectionsService(n).getCurrentLastSelection();if(!s)return!1;const{range:l,primary:c}=s,{jumpOver:d,direction:u,extra:h}=r,S=_u(s,u,t)?d===1?Cu(l,{...a.Rectangle.clone(c),rangeType:a.RANGE_TYPE.NORMAL},u,t):Iu(l,u,t):d===1?pu(l,u,t):vu(l,u,t);return S.rangeType=s.range.rangeType,a.Rectangle.equals(S,l)?!1:n.get(a.ICommandService).syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:i,subUnitId:o,type:m.SelectionMoveType.ONLY_SET,selections:[{range:S,primary:c}],extra:h})}},Tr={id:"sheet.command.select-all",type:a.CommandType.COMMAND,handler:async(n,r={expandToGapFirst:!0,loop:!1})=>{const e=m.getSheetCommandTarget(n.get(a.IUniverInstanceService));if(!e)return!1;const t=m.getSelectionsService(n).getCurrentLastSelection();if(!t)return!1;const i=n.get(cs),{worksheet:o,unitId:s,subUnitId:l}=e,c=`${s}|${l}`;c!==i.selectedRangeWorksheet&&(i.rangesStack=[],i.selectedRangeWorksheet=c);const d=o.getMaxRows(),u=o.getMaxColumns(),{expandToGapFirst:h,loop:g}=r,{range:S,primary:f}=t,p=S.endColumn===u-1&&S.endRow===d-1&&S.startRow===0&&S.startColumn===0;i.rangesStack.some(C=>a.Rectangle.equals(C,S))||(i.rangesStack=[],i.rangesStack.push(S));let v;if(p)if(g){if(i.rangesStack.findIndex(_=>a.Rectangle.equals(_,S))!==i.rangesStack.length-1)return!1;v=i.rangesStack[0]}else return!1;else h?(v=m.expandToContinuousRange(S,{left:!0,right:!0,up:!0,down:!0},o),a.Rectangle.equals(v,S)&&(v=Zs(o))):v=Zs(o);return i.rangesStack.some(C=>a.Rectangle.equals(C,v))||i.rangesStack.push(v),n.get(a.ICommandService).executeCommand(m.SetSelectionsOperation.id,{unitId:s,subUnitId:l,selections:[{range:v,primary:f}]})}};var Ru=Object.defineProperty,Eu=Object.getOwnPropertyDescriptor,Tu=(n,r,e,t)=>{for(var i=t>1?void 0:t?Eu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&Ru(r,e,i),i},wu=(n,r)=>(e,t)=>r(e,t,n);exports.SheetScrollManagerService=class{constructor(r,e){T(this,"_scrollStateMap",new Map);T(this,"_rawScrollInfo$",new O.BehaviorSubject(null));T(this,"rawScrollInfo$",this._rawScrollInfo$.asObservable());T(this,"validViewportScrollInfo$",new O.BehaviorSubject(null));T(this,"_searchParamForScroll",null);this._context=r,this._sheetSkeletonManagerService=e}dispose(){this._rawScrollInfo$.complete()}setSearchParam(r){this._searchParamForScroll=r}setSearchParamAndRefresh(r){this._searchParamForScroll=r,this._scrollStateNext(r)}getScrollStateByParam(r){return this._getCurrentScroll(r)}getCurrentScrollState(){return this._getCurrentScroll(this._searchParamForScroll)}setScrollInfoAndEmitEvent(r){this._setScrollState(r),this._scrollStateNext(r)}setScrollStateToCurrSheet(r){this._searchParamForScroll!=null&&this._setScrollState({...this._searchParamForScroll,...r})}clear(){this._searchParamForScroll!=null&&this._clearByParamAndNotify(this._searchParamForScroll)}calcViewportScrollFromRowColOffset(r){if(!r)return{viewportScrollX:0,viewportScrollY:0};let{sheetViewStartColumn:e,sheetViewStartRow:t,offsetX:i,offsetY:o}=r;t=t||0,o=o||0;const s=this._sheetSkeletonManagerService.getCurrentSkeleton(),l=(s==null?void 0:s.rowHeightAccumulation[t-1])||0,d=((s==null?void 0:s.columnWidthAccumulation[e-1])||0)+i,u=l+o;return{viewportScrollX:d,viewportScrollY:u}}_setScrollState(r){const{unitId:e,sheetId:t,sheetViewStartColumn:i,sheetViewStartRow:o,offsetX:s,offsetY:l}=r;this._scrollStateMap.has(e)||this._scrollStateMap.set(e,new Map);const c=this._scrollStateMap.get(e),d={sheetViewStartRow:o,sheetViewStartColumn:i,offsetX:s,offsetY:l};c.set(t,d)}_clearByParamAndNotify(r){this._setScrollState({...r,sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0}),this._scrollStateNext(r)}_getCurrentScroll(r){var s;const e={sheetViewStartRow:0,sheetViewStartColumn:0,offsetX:0,offsetY:0};if(r==null)return e;const{unitId:t,sheetId:i}=r;return((s=this._scrollStateMap.get(t))==null?void 0:s.get(i))||e}_scrollStateNext(r){const e=this._getCurrentScroll(r);this._rawScrollInfo$.next(e)}};exports.SheetScrollManagerService=Tu([wu(1,a.Inject(exports.SheetSkeletonManagerService))],exports.SheetScrollManagerService);const qe={id:"sheet.operation.set-scroll",type:a.CommandType.OPERATION,handler:(n,r)=>{if(!r)return!1;const{unitId:e,sheetId:t,offsetX:i,offsetY:o,sheetViewStartColumn:s,sheetViewStartRow:l}=r;return n.get(y.IRenderManagerService).getRenderById(e).with(exports.SheetScrollManagerService).setScrollInfoAndEmitEvent({unitId:e,sheetId:t,offsetX:i,offsetY:o,sheetViewStartRow:l,sheetViewStartColumn:s}),!0}},bn={id:"sheet.command.set-scroll-relative",type:a.CommandType.COMMAND,handler:async(n,r)=>{const e=n.get(a.ICommandService),t=n.get(a.IUniverInstanceService),i=n.get(y.IRenderManagerService),o=m.getSheetCommandTarget(t);if(!o)return!1;const{unitId:s,subUnitId:l}=o,d=i.getRenderById(s).with(exports.SheetScrollManagerService).getCurrentScrollState(),{offsetX:u=0,offsetY:h=0}=r||{},{sheetViewStartRow:g=0,sheetViewStartColumn:S=0,offsetX:f=0,offsetY:p=0}=d||{};return e.executeCommand(qe.id,{unitId:s,sheetId:l,sheetViewStartRow:g,sheetViewStartColumn:S,offsetX:f+u,offsetY:p+h})}},Be={id:"sheet.command.scroll-view",type:a.CommandType.COMMAND,handler:(n,r)=>{if(!r)return!1;const e=n.get(a.IUniverInstanceService),t=n.get(y.IRenderManagerService),i=m.getSheetCommandTarget(e);if(!i)return!1;const{workbook:o,worksheet:s,unitId:l}=i,d=t.getRenderById(l).with(exports.SheetScrollManagerService).getCurrentScrollState();if(!s)return!1;const{sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:g,offsetY:S}=r,{sheetViewStartColumn:f,sheetViewStartRow:p,offsetX:v,offsetY:C}=d||{},{xSplit:_,ySplit:b}=i.worksheet.getConfig().freeze;return n.get(a.ICommandService).syncExecuteCommand(qe.id,{unitId:o.getUnitId(),sheetId:s.getSheetId(),sheetViewStartRow:u!=null?u:p!=null?p:0+b,sheetViewStartColumn:h!=null?h:f!=null?f:0+_,offsetX:g!=null?g:v,offsetY:S!=null?S:C})}},hs={id:"sheet.command.scroll-to-cell",type:a.CommandType.COMMAND,handler:(n,r)=>{const e=n.get(a.IUniverInstanceService);return n.get(y.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(exports.SheetsScrollRenderController).scrollToRange(r.range,r.forceTop,r.forceLeft)}},yu={id:"sheet.command.scroll-view-reset",type:a.CommandType.COMMAND,handler:async n=>{const r=n.get(a.IUniverInstanceService),e=m.getSheetCommandTarget(r);if(!e)return!1;const{subUnitId:t,unitId:i}=e;return n.get(a.ICommandService).executeCommand(qe.id,{unitId:i,sheetId:t,sheetViewStartRow:0,sheetViewStartColumn:0})}};var Mu=Object.defineProperty,Pu=Object.getOwnPropertyDescriptor,Ou=(n,r,e,t)=>{for(var i=t>1?void 0:t?Pu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&Mu(r,e,i),i},en=(n,r)=>(e,t)=>r(e,t,n);const xu=[xe.id,et.id],Au=3;exports.SheetsScrollRenderController=class extends a.Disposable{constructor(r,e,t,i,o,s,l){super(),this._context=r,this._injector=e,this._sheetSkeletonManagerService=t,this._contextService=i,this._commandService=o,this._renderManagerService=s,this._scrollManagerService=l,this._initCommandListener(),this._wheelEventListener(),this._scrollBarEventListener(),this._initSkeletonListener()}_wheelEventListener(){const{scene:r}=this._context;if(!r)return;const e=r.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&this.disposeWithMe(r.onMouseWheel$.subscribeEvent((t,i)=>{if(t.ctrlKey||!this._contextService.getContextValue(a.FOCUSING_SHEET))return;let o=0,s=0;const l=e.limitedScroll();o=t.deltaX,t.shiftKey?o=(t.deltaY||t.deltaX)*Au:s=t.deltaY,this._commandService.executeCommand(bn.id,{offsetX:o,offsetY:s}),this._context.scene.makeDirty(!0),l&&!l.isLimitedX&&!l.isLimitedY&&(t.preventDefault(),r.getParent().classType===y.RENDER_CLASS_TYPE.SCENE_VIEWER&&i.stopPropagation()),e.isWheelPreventDefaultX&&e.isWheelPreventDefaultY&&t.preventDefault()}))}_scrollBarEventListener(){const{scene:r}=this._context;if(r==null)return;const e=r.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);e&&(this.disposeWithMe(a.toDisposable(this._scrollManagerService.rawScrollInfo$.subscribe(t=>{var S;const i=(S=this._sheetSkeletonManagerService.getCurrent())==null?void 0:S.skeleton;if(!i)return;if(t==null){e.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});return}const{sheetViewStartRow:o,sheetViewStartColumn:s,offsetX:l,offsetY:c}=t,{startX:d,startY:u}=i.getCellWithCoordByIndex(o,s,!1),h=d+l,g=u+c;e.scrollToViewportPos({viewportScrollX:h,viewportScrollY:g})}))),this.disposeWithMe(e.onScrollAfter$.subscribeEvent(t=>{var p;const i=(p=this._sheetSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(i==null||t.isTrigger===!1)return;const o=this._getSheetObject();if(i==null||o==null)return;const{viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d}=t,{row:u,column:h,rowOffset:g,columnOffset:S}=i.getDecomposedOffset(s,l),f={sheetViewStartRow:u,sheetViewStartColumn:h,offsetX:S,offsetY:g};this._scrollManagerService.setScrollStateToCurrSheet(f),this._scrollManagerService.validViewportScrollInfo$.next({...f,viewportScrollX:s,viewportScrollY:l,scrollX:c,scrollY:d})})),this.disposeWithMe(e.onScrollByBar$.subscribeEvent(t=>{var g;const i=(g=this._sheetSkeletonManagerService.getCurrent())==null?void 0:g.skeleton;if(i==null||t.isTrigger===!1)return;const o=this._getSheetObject();if(i==null||o==null)return;const{viewportScrollX:s=0,viewportScrollY:l=0}=t,{row:c,column:d,rowOffset:u,columnOffset:h}=i.getDecomposedOffset(s,l);this._commandService.executeCommand(Be.id,{sheetViewStartRow:c,sheetViewStartColumn:d,offsetX:h,offsetY:u})})))}_initSkeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeletonBefore$.subscribe(r=>{if(r==null)return;const e={unitId:r.unitId,sheetId:r.sheetId};this._scrollManagerService.setSearchParam(e);const t=this._getSheetObject();if(!t)return;const o=t.scene.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),s=this._scrollManagerService.getScrollStateByParam(e),{viewportScrollX:l,viewportScrollY:c}=this._scrollManagerService.calcViewportScrollFromRowColOffset(s);o&&(s?(o.viewportScrollX=l,o.viewportScrollY=c):(o.viewportScrollX=0,o.viewportScrollY=0),this._updateSceneSize(r))})))}scrollToRange(r,e,t){let{endRow:i,endColumn:o,startColumn:s,startRow:l}=r;const c=this._getViewportBounding();if(r.rangeType===a.RANGE_TYPE.ROW?(s=0,o=0):r.rangeType===a.RANGE_TYPE.COLUMN&&(l=0,i=0),c&&!e&&!t){const d=c.startRow>i?l:i,u=c.startColumn>o?s:o;return this._scrollToCell(d,u)}else return this._scrollToCell(l,s,e,t)}scrollToCell(r,e){const t=this._context.unit.getActiveSheet(),{ySplit:i,xSplit:o}=t.getFreeze();return this._commandService.syncExecuteCommand(Be.id,{sheetViewStartRow:r-i,sheetViewStartColumn:e-o,offsetX:0,offsetY:0})}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{if(xu.includes(r.id))this._scrollToSelection();else if(r.id===m.ScrollToCellOperation.id){const e=r.params;this.scrollToRange(e)}else if(r.id===ke.id){const e=r.params;this._scrollToSelectionForExpand(e)}else r.id===m.SetSelectionsOperation.id&&r.params.reveal&&this._scrollToSelection()}))}_scrollToSelectionForExpand(r){setTimeout(()=>{const e=this._getSelectionsService().getCurrentLastSelection();if(e==null)return;const{startRow:t,startColumn:i,endRow:o,endColumn:s}=e.range,l=this._getViewportBounding();if(l==null)return;const{startRow:c,startColumn:d,endRow:u,endColumn:h}=l;let g=0,S=0;t>c?g=o:o<u?g=t:g=c,i>d?S=s:s<h?S=i:S=d,r.direction===a.Direction.DOWN?g=o:r.direction===a.Direction.UP?g=t:r.direction===a.Direction.RIGHT?S=s:r.direction===a.Direction.LEFT&&(S=i),this._scrollToCell(g,S)},0)}_getFreeze(){var e;const r=(e=this._sheetSkeletonManagerService.getCurrent())==null?void 0:e.skeleton.getWorksheetConfig();if(r!=null)return r.freeze}_updateSceneSize(r){var g;if(r==null)return;const{unitId:e}=this._context,{skeleton:t}=r,i=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.scene;if(t==null||i==null)return;const{rowTotalHeight:o,columnTotalWidth:s,rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=t,u=this._context.unit.getActiveSheet();if(!u)return;const h=u.getZoomRatio()||1;i==null||i.setScaleValue(h,h),i==null||i.transformByState({width:l+s,height:c+o})}_getSheetObject(){return Xe(this._context.unit,this._context)}_scrollToSelectionByDirection(r){const e=this._getViewportBounding();if(e==null)return!1;const{startRow:t,startColumn:i,endRow:o,endColumn:s}=e;let l=0,c=0;const{startRow:d,startColumn:u,endRow:h,endColumn:g}=r;d>=t&&(l=h),h<=o&&(l=d),u>=i&&(c=g),g<=s&&(c=u),this._scrollToCell(l,c)}_scrollToSelection(r=!0){var d;const e=this._getSelectionsService().getCurrentLastSelection();if(!e)return;const{startRow:t,startColumn:i,actualRow:o,actualColumn:s}=(d=e.primary)!=null?d:e.range,l=r&&o!=null?o:t,c=r&&s!=null?s:i;this._scrollToCell(l,c)}_getSelectionsService(){return m.getSelectionsService(this._injector)}_getViewportBounding(){var o,s;const r=(o=this._getSheetObject())==null?void 0:o.scene;if(r==null)return;const e=r.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(e==null)return;const t=(s=this._sheetSkeletonManagerService.getCurrent())==null?void 0:s.skeleton;if(t==null)return;const i=e.calcViewportInfo();return t.getRangeByViewBound(i.viewBound)}_scrollToCell(r,e,t=!1,i=!1){var N,D,k,B;const{rowHeightAccumulation:o,columnWidthAccumulation:s}=(D=(N=this._sheetSkeletonManagerService.getCurrent())==null?void 0:N.skeleton)!=null?D:{};if(o==null||s==null)return!1;const l=(k=this._getSheetObject())==null?void 0:k.scene;if(l==null)return!1;const c=l.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(c==null)return!1;const d=(B=this._sheetSkeletonManagerService.getCurrent())==null?void 0:B.skeleton;if(d==null)return!1;const u=this._context.unit.getActiveSheet();if(!u)return!1;r=a.Tools.clamp(r,0,o.length-1),e=a.Tools.clamp(e,0,s.length-1);const{startColumn:h,startRow:g,ySplit:S,xSplit:f}=u.getFreeze(),p=this._getViewportBounding();if(p==null)return!1;const{startRow:v,startColumn:C,endRow:_,endColumn:b}=p;d.getVisibleRangeByViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);let E,M;if(r>=g&&e>=h-S&&(r<=v&&(E=r,t=!0),r>=_)){const V=o[r]-c.height;for(let U=v;U<=r&&(E=U+1,!(o[U]>=V));U++);}if(e>=h&&r>=g-S&&(e<=C&&(M=e,i=!0),e>=b)){const V=s[e]-c.width;for(let U=C;U<=e&&(M=U+1,!(s[U]>=V));U++);}if(E===void 0&&M===void 0)return!1;let{offsetX:w,offsetY:P,sheetViewStartRow:x,sheetViewStartColumn:A}=this._scrollManagerService.getCurrentScrollState()||{};if(E=E?Math.min(E,r):x+S,M=M?Math.min(M,e):A+f,i){w=0,M=e;const V=d.getHiddenColumnsInRange({startColumn:M-f,endColumn:M});M=M-V.length}if(t){P=0,E=r;const V=d.getHiddenRowsInRange({startRow:E-S,endRow:E});E=E-V.length}return this._commandService.syncExecuteCommand(Be.id,{sheetViewStartRow:Math.max(0,E-S),sheetViewStartColumn:Math.max(0,M-f),offsetX:w,offsetY:P})}};exports.SheetsScrollRenderController=Ou([en(1,a.Inject(a.Injector)),en(2,a.Inject(exports.SheetSkeletonManagerService)),en(3,a.IContextService),en(4,a.ICommandService),en(5,y.IRenderManagerService),en(6,a.Inject(exports.SheetScrollManagerService))],exports.SheetsScrollRenderController);const ms={id:"sheet.operation.scroll-to-range",type:a.CommandType.OPERATION,handler:(n,r)=>{if(!r)return!1;const e=n.get(a.IUniverInstanceService);return n.get(y.IRenderManagerService).getRenderById(e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId()).with(exports.SheetsScrollRenderController).scrollToRange(r.range,r.forceTop,r.forceLeft)}};class Za{constructor(){T(this,"_state",null);T(this,"_rect",null);T(this,"_state$",new O.BehaviorSubject(null));T(this,"state$",this._state$.asObservable());T(this,"_rect$",new O.BehaviorSubject(null));T(this,"rect$",this._rect$.asObservable());T(this,"_focus",!1);T(this,"_focus$",new O.BehaviorSubject(this._focus));T(this,"focus$",this._focus$.asObservable())}dispose(){this._state$.complete(),this._state=null,this._rect$.complete(),this._rect=null}setState(r){this._state=r,this._refresh(r)}getRect(){return this._rect}setRect(r){this._rect=r,this._rect$.next(r)}getState(){return this._state}setFocus(r=!1){this._focus=r,this._focus$.next(r)}_refresh(r){this._state$.next(r)}}const ui=a.createIdentifier("univer.sheet-cell-editor-manager.service"),Nu="36",Du="univer-sheet-container",Ka={sheetFooterBarHeight:Nu,sheetContainer:Du};var ku=Object.defineProperty,Vu=Object.getOwnPropertyDescriptor,Hu=(n,r,e,t)=>{for(var i=t>1?void 0:t?Vu(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&ku(r,e,i),i},tn=(n,r)=>(e,t)=>r(e,t,n);const Ks=5,qs=2;exports.SheetCellEditorResizeService=class extends a.Disposable{constructor(r,e,t,i,o,s,l){super(),this._context=r,this._layoutService=e,this._cellEditorManagerService=t,this._editorBridgeService=i,this._renderManagerService=o,this._sheetSkeletonManagerService=s,this._univerInstanceService=l}fitTextSize(r){var A,N,D,k;const e=this._editorBridgeService.getEditCellState();if(!e)return;const{position:t,documentLayoutObject:i,canvasOffset:o,scaleX:s,scaleY:l}=e,{startX:c,startY:d,endX:u,endY:h}=t,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);if(g==null)return;const S=this._getEditorSkeleton();if(!S)return;const f=this._predictingSize(t,o,S,i,s,l);if(!f)return;let{actualWidth:p,actualHeight:v}=f;const{verticalAlign:C,horizontalAlign:_,paddingData:b,fill:E}=i;p=p+((A=b.l)!=null?A:0)+((N=b.r)!=null?N:0),v=v+((D=b.t)!=null?D:0)+((k=b.b)!=null?k:0);let M=u-c,w=h-d;M<p&&(M=Math.ceil(p)),w<v&&(w=Math.ceil(v));let P=0;C===a.VerticalAlign.MIDDLE?P=(w-v)/2/l:C===a.VerticalAlign.TOP?P=b.t||0:P=(w-v)/l;let x=0;_===a.HorizontalAlign.CENTER?x=(M-p)/2/s:_===a.HorizontalAlign.RIGHT?x=(M-p)/s:x=b.l||0,P=P<(b.t||0)?b.t||0:P,x=x<(b.l||0)?b.l||0:x,g.updateDocumentDataMargin({t:P,l:x}),S.calculate(),this._editAreaProcessing(M,w,t,o,E,s,l,_,r)}_predictingSize(r,e,t,i,o=1,s=1){const{startX:l,endX:c}=r,{textRotation:d,wrapStrategy:u,paddingData:h}=i,g=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC),{vertexAngle:S}=y.convertTextRotation(d);if(u===a.WrapStrategy.WRAP&&S===0){g==null||g.updateDocumentDataPageSize(c-l),g==null||g.updateDocumentDataMargin({l:h.l,t:h.t}),t.calculate();const{actualWidth:C,actualHeight:_}=t.getActualSize();return{actualWidth:C*o,actualHeight:_*s}}const f=this._getEditorMaxSize(r,e,i.horizontalAlign);if(!f)return;g==null||g.updateDocumentDataPageSize(f.width/o),t.calculate();const p=t.getActualSize();let v=c-l;return v<p.actualWidth*o+Ks*o&&(v=p.actualWidth*o+Ks*o),g==null||g.updateDocumentDataPageSize(v/o),g==null||g.updateDocumentRenderConfig({horizontalAlign:a.HorizontalAlign.UNSPECIFIED,cellValueType:void 0}),{actualWidth:p.actualWidth*o,actualHeight:p.actualHeight*s}}_getEditorMaxSize(r,e,t){if(this._getEditorObject()==null)return;function o(_){return Number.parseInt(_.replace("px",""))}const l=this._context.engine.getCanvasElement(),c=l.getBoundingClientRect(),d=o(l.style.width),{width:u}=c,h=u/d,{startX:g,startY:S,endX:f}=r,p=this._context.engine.width,v=document.body.clientHeight-S-Number.parseFloat(Ka.sheetFooterBarHeight)-e.top-qs*2;let C=u-g;if(t===a.HorizontalAlign.CENTER){const _=p-f,b=g;C=f-g+Math.min(b,_)*2}else t===a.HorizontalAlign.RIGHT&&(C=f);return{height:v,width:C-qs,scaleAdjust:h}}_editAreaProcessing(r,e,t,i,o,s=1,l=1,c,d){var V;const u=this._getEditorObject();if(u==null)return;const g=this._context.engine.getCanvasElement();let{startX:S,startY:f}=t;const{document:p,scene:v,engine:C}=u,_=v.getViewport(J.VIEWPORT_KEY.VIEW_MAIN),b=this._getEditorMaxSize(t,i,c),{height:E,width:M,scaleAdjust:w}=b;let P=e,x=_==null?void 0:_.getScrollBar();P>E?(x==null?_&&new y.ScrollBar(_,{enableHorizontal:!1,barSize:8}):_==null||_.resetCanvasSizeAndUpdateScroll(),_==null||_.scrollToViewportPos({viewportScrollY:P-E}),P=E):(x=null,(V=_==null?void 0:_.getScrollBar())==null||V.dispose()),r+=(x==null?void 0:x.barSize)||0,r>M&&(r=M),this._addBackground(v,r/s,e/l,o);const{scaleX:A,scaleY:N}=v.getPrecisionScale();v.transformByState({width:r*w/s,height:e*w/l,scaleX:s*w,scaleY:l*w}),p.resize(r*w/s,e*w/l),setTimeout(()=>{C.resizeBySize(y.fixLineWidthByScale(r,A),y.fixLineWidthByScale(P,N)),d==null||d()},0);const D=this._layoutService.getContentElement().getBoundingClientRect(),k=g.getBoundingClientRect();S=S*w+(k.left-D.left),f=f*w+(k.top-D.top);const B=t.endX-t.startX;c===a.HorizontalAlign.RIGHT?S+=(B-r)*w:c===a.HorizontalAlign.CENTER&&(S+=(B-r*w)/2),this._cellEditorManagerService.setState({startX:S,startY:f,endX:r*w+S,endY:P*w+f,show:!0})}_addBackground(r,e,t,i){const o="_backgroundRectHelperColor_",s=r.getObject(o);s==null&&i==null||(s==null?r.addObjects([new y.Rect(o,{width:e,height:t,fill:i,evented:!1})],J.DOCS_COMPONENT_MAIN_LAYER_INDEX):i==null?s.dispose():(s.setProps({fill:i}),s.transformByState({width:e,height:t})))}resizeCellEditor(r){var w;const e=this._cellEditorManagerService.getState();if(!e||!this._editorBridgeService.isVisible().visible)return;this._editorBridgeService.refreshEditCellPosition(!0);const t=this._editorBridgeService.getEditCellState();if(!t)return;const i=(w=this._sheetSkeletonManagerService.getWorksheetSkeleton(t.sheetId))==null?void 0:w.skeleton;if(!i)return;const{row:o,column:s,scaleX:l,scaleY:c,position:d,canvasOffset:u,documentLayoutObject:h}=t,{horizontalAlign:g}=h,S=this._getEditorMaxSize(d,u,g);if(!S)return;const{height:f,width:p,scaleAdjust:v}=S,C=i.getCellWithCoordByIndex(o,s),_=Math.min((C.mergeInfo.endY-C.mergeInfo.startY)*c,f)*v,b=Math.min((C.mergeInfo.endX-C.mergeInfo.startX)*l,p)*v,E=e.endY-e.startY,M=e.endX-e.startX;if(E!==_||M!==b){if(this._editorBridgeService.refreshEditCellPosition(!0),!this._getEditorSkeleton())return;this.fitTextSize(r)}}_getEditorObject(){return _r(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}_getEditorSkeleton(){var r;return(r=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:r.with(Ie.DocSkeletonManagerService).getSkeleton()}};exports.SheetCellEditorResizeService=Hu([tn(1,R.ILayoutService),tn(2,ui),tn(3,he),tn(4,y.IRenderManagerService),tn(5,a.Inject(exports.SheetSkeletonManagerService)),tn(6,a.IUniverInstanceService)],exports.SheetCellEditorResizeService);function gs(n){return n.getContextValue(a.FOCUSING_SHEET)}function ae(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function qa(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&!n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&!n.getContextValue(a.FOCUSING_COMMON_DRAWINGS)}function Wu(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function Uu(n){return n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)}function Qa(n){return n.getContextValue(a.FOCUSING_FX_BAR_EDITOR)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function Lu(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.EDITOR_ACTIVATED)&&n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)}function $n(n){return n.getContextValue(a.FOCUSING_SHEET)&&n.getContextValue(a.FOCUSING_UNIVER_EDITOR)&&n.getContextValue(a.EDITOR_ACTIVATED)&&!n.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA)&&!n.getContextValue(a.FOCUSING_EDITOR_STANDALONE)}const Ja=[R.KeyCode.ARROW_DOWN,R.KeyCode.ARROW_UP,R.KeyCode.ARROW_LEFT,R.KeyCode.ARROW_RIGHT],Bu=[R.KeyCode.ENTER,R.KeyCode.TAB,...Ja];function $a(){const n=[];for(const r of Ja)n.push({id:Ft.id,binding:r,preconditions:e=>$n(e),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:r,isShift:!1}}),n.push({id:Ft.id,binding:r|R.MetaKeys.SHIFT,preconditions:e=>$n(e),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:r,isShift:!0}});return n}const el={id:di.id,binding:R.KeyCode.F2,description:"shortcut.sheet.start-editing",group:"4_sheet-edit",preconditions:ae,staticParameters:{visible:!0,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.F2}},tl={id:Me.id,binding:R.KeyCode.ENTER,description:"shortcut.sheet.toggle-editing",group:"4_sheet-edit",preconditions:n=>$n(n),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.ENTER}},nl={id:Me.id,binding:R.KeyCode.TAB,preconditions:n=>$n(n),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.TAB}},il={id:Me.id,binding:R.KeyCode.ESC,description:"shortcut.sheet.abort-editing",group:"4_sheet-edit",preconditions:n=>$n(n),staticParameters:{visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.ESC}},rl={id:J.BreakLineCommand.id,description:"shortcut.sheet.break-line",group:"4_sheet-edit",preconditions:n=>Wu(n),binding:R.KeyCode.ENTER|R.MetaKeys.ALT},ol={id:J.DeleteLeftCommand.id,preconditions:n=>Uu(n)||Qa(n),binding:R.KeyCode.BACKSPACE},sl={id:Me.id,description:"shortcut.sheet.delete-and-start-editing",group:"4_sheet-edit",preconditions:n=>ae(n)&&!Qa(n),binding:R.KeyCode.BACKSPACE,staticParameters:{visible:!0,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.BACKSPACE}};function Fu(n){return n.startsWith("'")}function ju(n){return n.slice(1)}const zu={"0":"0","1":"1","2":"2","3":"3","4":"4","5":"5","6":"6","7":"7","8":"8","9":"9",A:"A",B:"B",C:"C",D:"D",E:"E",F:"F",G:"G",H:"H",I:"I",J:"J",K:"K",L:"L",M:"M",N:"N",O:"O",P:"P",Q:"Q",R:"R",S:"S",T:"T",U:"U",V:"V",W:"W",X:"X",Y:"Y",Z:"Z",a:"a",b:"b",c:"c",d:"d",e:"e",f:"f",g:"g",h:"h",i:"i",j:"j",k:"k",l:"l",m:"m",n:"n",o:"o",p:"p",q:"q",r:"r",s:"s",t:"t",u:"u",v:"v",w:"w",x:"x",y:"y",z:"z","%":"%","-":"-",".":".",":":":","/":"/","+":"+","@":"@","&":"&","*":"*","#":"#","=":"=",">":">","<":"<","$":"$",""":'"',"'":"'","(":"(",")":")"," ":" ",",":",","!":"!","?":"?",";":";","[":"[","]":"]","{":"{","}":"}"},Vo={true:"TRUE",false:"FALSE"};function Xu(n){return[a.LocaleType.ZH_CN,a.LocaleType.ZH_TW].includes(n)}function Yu(n,r,e,t){let i=n;if(Xu(e)){if(n.startsWith("'")||n.startsWith("'"))return`'${n.slice(1)}`;i=Gu(i)}if(i.startsWith("="))return Zu(n,i,r,t);const o=i.toLowerCase();return Vo[o]?Vo[o]:a.numfmt.parseValue(i)==null?n:i}function Gu(n){const r=/['"].*?['"]/g,e=[],t=n.split(r);n.replace(r,o=>(e.push(o),""));let i=t.join("").split("").map(Qu).join("");return e.forEach((o,s)=>{i=i.slice(0,s*2)+o+i.slice((s+1)*2)}),i}function Zu(n,r,e,t){const i=e.sequenceNodesBuilder(r);if(!i)return n;let o=r,s=0;return i.forEach((l,c)=>{if(typeof l=="object"){const d=l.token;if(Vo[d.toLowerCase()]){const u=l.startIndex+s+1,h=l.endIndex+s+2;o=nn(d.toLocaleUpperCase(),o,u,h)}else if(l.nodeType===G.sequenceNodeType.FUNCTION&&Ku(d,t,i,c)||l.nodeType===G.sequenceNodeType.REFERENCE){const u=d.indexOf("!");if(u>-1){const h=d.substring(u+1),g=l.startIndex+s+(u+1)+1,S=l.endIndex+s+2;o=nn(h.toLocaleUpperCase(),o,g,S)}else{const h=l.startIndex+s+1,g=l.endIndex+s+2;o=nn(d.toLocaleUpperCase(),o,h,g)}}else if(d.startsWith('"')&&d.endsWith('"')||d.startsWith("'")&&d.endsWith("'")){const u=l.startIndex+s+2,h=l.endIndex+s+1;o=nn(n.slice(u,h),o,u,h)}else if(l.nodeType!==G.sequenceNodeType.ARRAY){const u=a.numfmt.parseValue(d);if(u==null){const h=l.startIndex+s+1,g=l.endIndex+s+2;o=nn(n.slice(h,g),o,h,g)}else if(typeof u.v=="number"&&(u.z===void 0||!a.numfmt.isDate(u.z))){const h=`${u.v}`,g=l.startIndex+s+1,S=l.endIndex+s+2,{processedString:f,offset:p}=Ju(d,h);o=nn(f,o,g,S),s+=p}}}}),o}function Ku(n,r,e,t){const i=r.getDescriptions();return e[t+1]!==G.matchToken.OPEN_BRACKET?!1:i.get(qu(n).toLocaleUpperCase())!==void 0}function qu(n){const r=/^@+/;return n.replace(r,"")}function Qu(n){return zu[n]||n}function nn(n,r,e,t){return r.substring(0,e)+n+r.substring(t)}function Ju(n,r){var s,l;const e=((s=n.match(/^\s*/))==null?void 0:s[0])||"",t=((l=n.match(/\s*$/))==null?void 0:l[0])||"",i=e+r+t,o=i.length-n.length;return{processedString:i,offset:o}}const al="range_selector",ll=n=>n.includes(al);var $u=Object.defineProperty,eh=Object.getOwnPropertyDescriptor,th=(n,r,e,t)=>{for(var i=t>1?void 0:t?eh(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&$u(r,e,i),i},we=(n,r)=>(e,t)=>r(e,t,n);const Qs=-1e3;exports.EditingRenderController=class extends a.Disposable{constructor(e,t,i,o,s,l,c,d,u,h,g,S,f,p,v,C){super();T(this,"_cursorChange",0);T(this,"_isUnitEditing",!1);T(this,"_workbookSelections");T(this,"_d");T(this,"_cursorTimeout");this._context=e,this._undoRedoService=i,this._contextService=o,this._renderManagerService=s,this._editorBridgeService=l,this._cellEditorManagerService=c,this._lexerTreeBuilder=d,this._functionService=u,this._textSelectionManagerService=h,this._commandService=g,this._localService=S,this._editorService=f,this._sheetCellEditorResizeService=p,this._univerInstanceService=v,this._sheetInterceptorService=C,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(_=>{(_==null?void 0:_.getUnitId())===this._context.unitId?this._d=this._init():(this._disposeCurrent(),this._isUnitEditing&&(this._handleEditorInvisible({visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.ESC,unitId:this._context.unitId}),this._isUnitEditing=!1))})),this._initEditorVisibilityListener()}dispose(){super.dispose(),this._disposeCurrent()}_disposeCurrent(){var e;(e=this._d)==null||e.dispose(),this._d=null}_init(){const e=new a.DisposableCollection;return this._subscribeToCurrentCell(e),this._initialCursorSync(e),this._listenEditorFocus(e),this._commandExecutedListener(e),this._initSkeletonListener(e),this.disposeWithMe(this._univerInstanceService.unitDisposed$.subscribe(t=>{clearTimeout(this._cursorTimeout)})),this._cursorTimeout=setTimeout(()=>{this._cursorStateListener(e)},1e3),e}_initEditorVisibilityListener(){this.disposeWithMe(this._editorBridgeService.visible$.pipe(O.distinctUntilChanged((e,t)=>e.visible===t.visible)).subscribe(e=>{(e.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY||e.unitId===this._context.unitId)&&e.visible?(this._isUnitEditing=!0,this._handleEditorVisible(e)):this._isUnitEditing&&(this._handleEditorInvisible(e),this._isUnitEditing=!1)}))}_listenEditorFocus(e){const t=this._getEditorObject();t&&e.add(t.document.onPointerDown$.subscribeEvent(()=>{if(this._isUnitEditing&&this._editorBridgeService.isVisible()){const i=this._editorBridgeService.getEditCellState(),o=this._editorBridgeService.getCurrentEditorId();if(!i||!o)return;this._sheetCellEditorResizeService.fitTextSize()}}))}_initialCursorSync(e){e.add(this._cellEditorManagerService.focus$.pipe(O.filter(t=>!!t)).subscribe(()=>{var i;const t=(i=this._renderManagerService.getCurrentTypeOfRenderer(a.UniverInstanceType.UNIVER_DOC))==null?void 0:i.with(J.DocSelectionRenderService);t&&t.sync()}))}_initSkeletonListener(e){const t=new Set(m.COMMAND_LISTENER_SKELETON_CHANGE);t.delete(m.SetWorksheetActiveOperation.id),e.add(this._commandService.onCommandExecuted(i=>{t.has(i.id)&&this._sheetCellEditorResizeService.resizeCellEditor(()=>{this._textSelectionManagerService.refreshSelection({unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})})}))}_subscribeToCurrentCell(e){e.add(this._editorBridgeService.currentEditCellState$.subscribe(t=>{var _,b;if(t==null||this._editorBridgeService.isForceKeepVisible())return;const i=this._editorBridgeService.getEditCellState();if(i==null)return;const{position:o,documentLayoutObject:s,scaleX:l,editorUnitId:c}=i;if(this._contextService.getContextValue(a.FOCUSING_EDITOR_STANDALONE))return;const d=this._getDocumentDataModel();if(d==null)return;const{startX:u,endX:h}=o,{textRotation:g,wrapStrategy:S,documentModel:f}=s,{vertexAngle:p}=y.convertTextRotation(g);S===a.WrapStrategy.WRAP&&p===0&&d.updateDocumentDataPageSize((h-u)/l),this._commandService.syncExecuteCommand(J.ReplaceSnapshotCommand.id,{unitId:c,snapshot:f.getSnapshot()}),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!0),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});const v=(_=this._renderManagerService.getRenderById(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY))==null?void 0:_.with(J.DocSelectionRenderService),C=(b=this._renderManagerService.getRenderById(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))==null?void 0:b.with(J.DocSelectionRenderService);(v!=null&&v.canFocusing||C!=null&&C.canFocusing)&&(this._univerInstanceService.setCurrentUnitForType(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),v==null||v.activate(Qs,Qs,!0))}))}_commandExecutedListener(e){e.add(this._commandService.onCommandExecuted(i=>{if(i.id===Ie.RichTextEditingMutation.id){const o=i.params,{unitId:s}=o;if(!this._isCurrentSheetFocused()||ll(s)||(this._editorBridgeService.changeEditorDirty(!0),!this._editorBridgeService.isVisible().visible))return;s===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY&&this._sheetCellEditorResizeService.fitTextSize()}}));const t=[Ft.id];e.add(this._commandService.onCommandExecuted(i=>{if(t.includes(i.id)){const o=i.params,{keycode:s,isShift:l}=o;if(s!=null&&(this._cursorChange===2||this._contextService.getContextValue(a.FOCUSING_FX_BAR_EDITOR))){this._moveInEditor(s,l);return}this._editorBridgeService.changeVisible(o)}i.id===di.id&&(this._cursorChange=2)}))}_handleEditorVisible(e){var S,f,p;const{eventType:t,keycode:i}=e;this._cursorChange=t===y.DeviceInputEventType.PointerDown||t===y.DeviceInputEventType.Dblclick?2:1;const o=this._editorBridgeService.getEditLocation();if(o==null)return;this._commandService.syncExecuteCommand(ms.id,{range:{startRow:o.row,startColumn:o.column,endRow:o.row,endColumn:o.column}}),this._editorBridgeService.refreshEditCellPosition(!1);const{unitId:s,isInArrayFormulaRange:l=!1}=o,c=this._getEditorObject();if(c==null)return;const{document:d,scene:u}=c;this._contextService.setContextValue(a.EDITOR_ACTIVATED,!0);const h=this._getDocumentDataModel(),g=this._getEditorSkeleton(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(!(!g||!h)){if(this._sheetCellEditorResizeService.fitTextSize(()=>{const v=u.getViewport(J.VIEWPORT_KEY.VIEW_MAIN);v==null||v.scrollToViewportPos({viewportScrollX:Number.POSITIVE_INFINITY,viewportScrollY:Number.POSITIVE_INFINITY})}),t===y.DeviceInputEventType.Keyboard&&i===R.KeyCode.F2){d.makeDirty(),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}]);const v=((f=(S=h.getBody())==null?void 0:S.dataStream.length)!=null?f:2)-2;this._textSelectionManagerService.replaceDocRanges([{startOffset:v,endOffset:v}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY})}else if(t===y.DeviceInputEventType.Keyboard||t===y.DeviceInputEventType.Dblclick&&l)this._emptyDocumentDataModel(h.getSnapshot().documentStyle,!!l),d.makeDirty(),(i===R.KeyCode.BACKSPACE||t===y.DeviceInputEventType.Dblclick)&&(g.calculate(),this._editorBridgeService.changeEditorDirty(!0)),this._textSelectionManagerService.replaceDocRanges([{startOffset:0,endOffset:0}],{unitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,subUnitId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY});else if(t===y.DeviceInputEventType.Dblclick){if(this._contextService.getContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA))return;const v=h.getBody().dataStream.length-2||0;this._textSelectionManagerService.replaceDocRanges([{startOffset:v,endOffset:v}])}(p=this._renderManagerService.getRenderById(s))==null||p.scene.resetCursor()}}async _handleEditorInvisible(e){const t=this._editorBridgeService.getEditCellState(),i=this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),o=a.Tools.deepClone(i==null?void 0:i.getSnapshot());let{keycode:s}=e;if(this._cursorChange=0,this._exitInput(e),t==null)return;this._editorBridgeService.getEditorDirty()===!1&&(s=R.KeyCode.ESC);const d=this._context.unit.getActiveSheet(),u=this._context.unitId,h=d.getSheetId(),{unitId:g,sheetId:S}=t;if(u===g&&S!==h&&await this._commandService.executeCommand(m.SetWorksheetActivateCommand.id,{subUnitId:S,unitId:g}),s===R.KeyCode.ESC){this._editorBridgeService.isForceKeepVisible()&&this._editorBridgeService.disableForceKeepVisible();const f=this._workbookSelections.getCurrentSelections();f&&(this._contextService.setContextValue(m.REF_SELECTIONS_ENABLED,!1),this._commandService.syncExecuteCommand(m.SetSelectionsOperation.id,{unitId:this._context.unit.getUnitId(),subUnitId:S,selections:f}));return}o&&await this._submitCellData(o),this._moveCursor(s)}_getEditorObject(){return _r(this._editorBridgeService.getCurrentEditorId(),this._renderManagerService)}submitCellData(e){return this._submitCellData(e.getSnapshot())}async _submitCellData(e){const t=this._editorBridgeService.getEditCellState();if(t==null)return;const{unitId:i,sheetId:o,row:s,column:l}=t,c=this._context.unit;let d=c.getActiveSheet();if(!c.getSheetBySheetId(o))return;d=c.getActiveSheet();const h=nh({...d.getCellRaw(s,l)||{}},e,this._lexerTreeBuilder,this._localService,this._functionService,c.getStyles());if(!h)return;const g=await this._sheetInterceptorService.onWriteCell(c,d,s,l,h);g!==d.getCellRaw(s,l)&&this._commandService.executeCommand(m.SetRangeValuesCommand.id,{subUnitId:o,unitId:i,range:{startRow:s,startColumn:l,endRow:s,endColumn:l},value:g})}_exitInput(e){var o;this._contextService.setContextValue(a.FOCUSING_EDITOR_INPUT_FORMULA,!1),this._contextService.setContextValue(a.EDITOR_ACTIVATED,!1),this._contextService.setContextValue(a.FOCUSING_EDITOR_BUT_HIDDEN,!1),this._contextService.setContextValue(a.FOCUSING_FX_BAR_EDITOR,!1),this._cellEditorManagerService.setState({show:e.visible});const t=this._getEditorObject();(o=t==null?void 0:t.scene.getViewport(J.VIEWPORT_KEY.VIEW_MAIN))==null||o.scrollToViewportPos({viewportScrollX:0,viewportScrollY:0});const i=this._editorBridgeService.getCurrentEditorId();i==null||!this._editorService.isSheetEditor(i)||(this._undoRedoService.clearUndoRedo(i),this._undoRedoService.clearUndoRedo(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY))}_moveCursor(e){if(e==null||!Bu.includes(e))return;let t=a.Direction.LEFT;switch(e){case R.KeyCode.ENTER:t=a.Direction.DOWN;break;case R.KeyCode.TAB:t=a.Direction.RIGHT;break;case R.KeyCode.ARROW_DOWN:t=a.Direction.DOWN;break;case R.KeyCode.ARROW_UP:t=a.Direction.UP;break;case R.KeyCode.ARROW_LEFT:t=a.Direction.LEFT;break;case R.KeyCode.ARROW_RIGHT:t=a.Direction.RIGHT;break}e===R.KeyCode.ENTER||e===R.KeyCode.TAB?this._commandService.executeCommand(et.id,{keycode:e,direction:t}):this._commandService.executeCommand(xe.id,{direction:t})}_cursorStateListener(e){const t=this._getEditorObject();if(!(t!=null&&t.document))return;const{document:i}=t;e.add(a.toDisposable(i.onPointerDown$.subscribeEvent(()=>{this._cursorChange===1&&(this._cursorChange=2)})))}_moveInEditor(e,t){let i=a.Direction.LEFT;e===R.KeyCode.ARROW_DOWN?i=a.Direction.DOWN:e===R.KeyCode.ARROW_UP?i=a.Direction.UP:e===R.KeyCode.ARROW_RIGHT&&(i=a.Direction.RIGHT),t?this._commandService.executeCommand(J.MoveSelectionOperation.id,{direction:i}):this._commandService.executeCommand(J.MoveCursorOperation.id,{direction:i})}_getDocumentDataModel(){return this._univerInstanceService.getUnit(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC)}_isCurrentSheetFocused(){var e;return((e=this._univerInstanceService.getFocusedUnit())==null?void 0:e.getUnitId())===this._context.unitId}_getEditorSkeleton(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(Ie.DocSkeletonManagerService).getSkeleton()}_getEditorViewModel(e){var t;return(t=this._renderManagerService.getRenderById(e))==null?void 0:t.with(Ie.DocSkeletonManagerService).getViewModel()}_emptyDocumentDataModel(e,t){const i=(l,c)=>{const d=a.Tools.deepClone(l.getSnapshot()),u=this._getEditorViewModel(l.getUnitId());u!=null&&(ih(d.body,t),c&&(d.documentStyle=e),d.drawings={},d.drawingsOrder=[],l.reset(d),u.reset(l))},o=this._getDocumentDataModel();o&&i(o,!0);const s=this._univerInstanceService.getUnit(a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,a.UniverInstanceType.UNIVER_DOC);s&&i(s)}};exports.EditingRenderController=th([we(1,a.Inject(m.SheetsSelectionsService)),we(2,a.IUndoRedoService),we(3,a.IContextService),we(4,y.IRenderManagerService),we(5,he),we(6,ui),we(7,a.Inject(G.LexerTreeBuilder)),we(8,G.IFunctionService),we(9,a.Inject(Ie.DocSelectionManagerService)),we(10,a.ICommandService),we(11,a.Inject(a.LocaleService)),we(12,J.IEditorService),we(13,a.Inject(exports.SheetCellEditorResizeService)),we(14,a.IUniverInstanceService),we(15,a.Inject(m.SheetInterceptorService))],exports.EditingRenderController);function nh(n,r,e,t,i,o){var h,g,S;if((r==null?void 0:r.body)==null)return null;const{body:s}=r;n.t=void 0;const l=s.dataStream;let d=l.substring(l.length-2,l.length)===a.DEFAULT_EMPTY_DOCUMENT_VALUE?l.substring(0,l.length-2):l;const u=t.getCurrentLocale();if(d=Yu(d,e,u,i),(h=r.drawingsOrder)!=null&&h.length)n.v="",n.f=null,n.si=null,n.p=r,n.t=a.CellValueType.STRING;else if(n.s&&((S=(g=o==null?void 0:o.get(n.s))==null?void 0:g.n)==null?void 0:S.pattern)===dd.DEFAULT_TEXT_FORMAT){n.v=d,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.STRING,Ho(s)&&s.dataStream!==`\r
2
2
  `&&(n.p=r);const f=Js(r);f&&(n.s=f)}else if(a.isFormulaString(d)){if(n.f===d)return null;const f=e.checkIfAddBracket(d);for(let p=0;p<f;p++)d+=G.matchToken.CLOSE_BRACKET;n.f=d,n.si=null,n.v=null,n.p=null}else if(Fu(d)){const f=ju(d);n.v=f,n.f=null,n.si=null,n.p=null,n.t=a.CellValueType.FORCE_STRING}else if(Ho(s))s.dataStream===`\r
3
3
  `?(n.v="",n.f=null,n.si=null,n.p=null):(n.p=r,n.v=null,n.f=null,n.si=null);else{if(d===""&&n.v==null&&n.p==null)return null;n.v=d,n.f=null,n.si=null,n.p=null;const f=Js(r);f&&(n.s=f)}return n}function Ho(n){const{textRuns:r=[],paragraphs:e=[],customRanges:t,customBlocks:i=[]}=n,o=n.dataStream.replace(/(\r\n)+$/,""),s=["va"];return r.filter(l=>l.st<o.length).some(l=>{var d;return!!(l.ts&&Object.keys(l.ts).some(u=>s.includes(u)))||Object.keys((d=l.ts)!=null?d:{}).length&&l.ed-l.st<o.length})||e.some(l=>l.bullet)||e.length>=2||!!(t!=null&&t.length)||i.length>0}function Js(n){const{body:r}=n;if(!r)return null;const{textRuns:e=[]}=r;let t={};const i=r.dataStream.replace(`\r
4
4
  `,"");return e.forEach(o=>{const{st:s,ed:l,ts:c}=o;l-s>=i.length&&(t={...t,...c})}),Object.keys(t).length?t:null}function ih(n,r=!1){n.dataStream=a.DEFAULT_EMPTY_DOCUMENT_VALUE,n.textRuns!=null&&(n.textRuns.length===1&&!r?(n.textRuns[0].st=0,n.textRuns[0].ed=1):n.textRuns=void 0),n.paragraphs!=null&&(n.paragraphs=[{startIndex:0}]),n.sectionBreaks!=null&&(n.sectionBreaks=void 0),n.tables!=null&&(n.tables=void 0),n.customRanges!=null&&(n.customRanges=void 0),n.customBlocks!=null&&(n.customBlocks=void 0)}var rh=Object.defineProperty,oh=Object.getOwnPropertyDescriptor,sh=(n,r,e,t)=>{for(var i=t>1?void 0:t?oh(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&rh(r,e,i),i},Br=(n,r)=>(e,t)=>r(e,t,n);const $s=ss.MARK_SELECTION,Yt=a.createIdentifier("univer.mark-selection-service");exports.MarkSelectionService=class extends a.Disposable{constructor(e,t,i){super();T(this,"_shapeMap",new Map);this._currentService=e,this._renderManagerService=t,this._themeService=i}addShape(e,t=[],i=$s){var d;const o=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(d=o.getActiveSheet())==null?void 0:d.getSheetId();if(!s)return null;const l=a.Tools.generateRandomId(),c={selection:e,subUnitId:s,unitId:o.getUnitId(),zIndex:i,control:null,exits:t};return this._shapeMap.set(l,c),this.refreshShapes(),l}addShapeWithNoFresh(e,t=[],i=$s){var c;const o=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=(c=o.getActiveSheet())==null?void 0:c.getSheetId();if(!s)return null;const l=a.Tools.generateRandomId();return this._shapeMap.set(l,{selection:e,subUnitId:s,unitId:o.getUnitId(),zIndex:i,control:null,exits:t}),l}refreshShapes(){var o;const e=this._currentService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),i=(o=e.getActiveSheet())==null?void 0:o.getSheetId();this._shapeMap.forEach(s=>{var b;const{unitId:l,subUnitId:c,selection:d,control:u,zIndex:h}=s;if(u==null||u.dispose(),l!==t||c!==i)return;const g=this._renderManagerService.getRenderById(l);if(!g)return;const S=(b=this._renderManagerService.withCurrentTypeOfUnit(a.UniverInstanceType.UNIVER_SHEET,exports.SheetSkeletonManagerService))==null?void 0:b.getCurrentSkeleton();if(!S)return;const{scene:f}=g,{rowHeaderWidth:p,columnHeaderHeight:v}=S,C=new ci(f,h,this._themeService,{enableAutoFill:!1,highlightHeader:!1,rowHeaderWidth:p,columnHeaderHeight:v}),_=ye(d,S);C.updateRangeBySelectionWithCoord(_),s.control=C})}getShapeMap(){return this._shapeMap}removeShape(e){const t=this._shapeMap.get(e);if(!t)return;const{control:i}=t;i==null||i.dispose(),this._shapeMap.delete(e)}removeAllShapes(){for(const e of this._shapeMap.values()){const{control:t}=e;t==null||t.dispose()}this._shapeMap.clear()}};exports.MarkSelectionService=sh([Br(0,a.IUniverInstanceService),Br(1,y.IRenderManagerService),Br(2,a.Inject(a.ThemeService))],exports.MarkSelectionService);function cl(n){return{strokeWidth:1.5,stroke:n.getCurrentTheme().primaryColor,fill:"rgba(178, 178, 178, 0.10)",widgets:{},strokeDash:8}}const ah=10,lh=6;function ch(){return a.Tools.generateRandomId(lh)}function dh(n){const r=n.match(/data-copy-id="([^\s]+)"/);return r&&r[1]?r[1]:null}class uh{constructor(){T(this,"_cache",new a.LRUMap(ah))}set(r,e){this._cache.set(r,e)}get(r){return this._cache.get(r)}del(r){this._cache.delete(r)}clear(){this._cache.clear()}clearWithUnitId(r){this._cache.forEach((e,t)=>{e.unitId===r&&this._cache.delete(t)})}}function Qi(n,r){const e=r!=null?r:n.style,t={},i=n.tagName.toLowerCase();switch(i){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=i==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}return hh(e,t),t}function hh(n,r){if(n instanceof CSSStyleDeclaration)for(let e=0;e<n.length;e++){const t=n[e],i=n.getPropertyValue(t);ea(t,i,r)}else for(const e in n){const t=n[e];ea(e,t,r)}}function ea(n,r,e){switch(n){case"font-family":e.ff=r;break;case"font-size":{const t=Number.parseInt(r);Number.isNaN(t)||(r.endsWith("pt")?e.fs=t:r.endsWith("px")&&(e.fs=t*.75));break}case"font-style":r==="italic"&&(e.it=a.BooleanNumber.TRUE);break;case"font-weight":{(Number(r)>400||r==="bold")&&(e.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(r)?e.ul={s:a.BooleanNumber.TRUE}:/overline/.test(r)?e.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(r)&&(e.st={s:a.BooleanNumber.TRUE});break}case"color":{try{const t=new a.ColorKit(r);t.isValid&&(e.cl={rgb:t.toRgbString()})}catch{}break}case"background-color":{const t=new a.ColorKit(r),i=t.isValid?t.toRgbString():"";i!==R.DEFAULT_BACKGROUND_COLOR_RGB&&i!==R.DEFAULT_BACKGROUND_COLOR_RGBA&&(e.bg={rgb:i});break}}}function mh(n){const r=document.createElement("body");return r.innerHTML=n,r}function dl(n){const r=n.style,e={};for(let t=0;t<r.length;t++){const i=r[t],o=r.getPropertyValue(i);switch(i){case"margin-top":{const s=Number.parseInt(o);e.spaceAbove={v:/pt/.test(o)?y.ptToPixel(s):s};break}case"margin-bottom":{const s=Number.parseInt(o);e.spaceBelow={v:/pt/.test(o)?y.ptToPixel(s):s};break}case"line-height":{const s=Number.parseFloat(o);e.lineSpacing=s;break}}}return Object.getOwnPropertyNames(e).length?e:null}function Fr(n,r){const e=[];for(let t=0,i=n.length;t<i;t++)n[t]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});return e}function ta(n,r,e){var s,l,c;const t=r.length,o=((s=e==null?void 0:e.length)!=null?s:0)===1&&e[0].st===0&&e[0].ed===t;return n.p?o&&((c=(l=n.p.body)==null?void 0:l.textRuns)!=null&&c.length)?(n.p.body.textRuns=[],{...n,s:e[0].ts}):n:o?{...n,s:e[0].ts}:n}const na=["color","background","font-size","text-align","vertical-align","font-weight","font-style","font-family","text-decoration","white-space","word-wrap","border-left","border-right","border-top","border-bottom","--data-rotate"];function ia(n,r){const e=n.tagName.toLowerCase();return typeof r=="string"?e===r:Array.isArray(r)?r.some(t=>t===e):r(n)}const Ir=class Ir{constructor(r){T(this,"_styleMap",new Map);T(this,"_styleCache",new Map);T(this,"_styleRules",[]);T(this,"_afterProcessRules",[]);T(this,"_dom",null);T(this,"_getCurrentSkeleton");this._getCurrentSkeleton=r.getCurrentSkeleton}static use(r){if(this._pluginList.includes(r))throw new Error(`Univer paste plugin ${r.name} already added`);this._pluginList.push(r)}convert(r){const e=Ir._pluginList.find(p=>p.checkPasteType(r));e&&(this._styleRules=[...e.stylesRules],this._afterProcessRules=[...e.afterProcessRules]);const t=new a.ObjectMatrix;this._dom=mh(r);const i=this._dom.querySelector("style");if(i){const p=document.createElement("div"),v=p.attachShadow({mode:"open"});document.body.appendChild(p),v.appendChild(i);for(const C of i.sheet.cssRules){const _=C,b=_.selectorText,E=_.style;this._styleMap.set(b,E)}i.remove(),p.remove()}const o={dataStream:"",textRuns:[]},s=[],l=[],c=r.match(/<table\b[^>]*>([\s\S]*?)<\/table>/gi),d=[];this.process(null,this._dom.childNodes,o,d);const{paragraphs:u,dataStream:h,textRuns:g,payloads:S,customRanges:f}=o;if(u){const p=u.map(v=>v.startIndex+1);p.unshift(0);for(let v=0;v<p.length;v++){let C;if(v===p.length-1){if(C=`${h.substring(p[v])}\r
@@ -20,7 +20,7 @@
20
20
  */var la;function zh(){if(la)return Un;la=1;var n=H,r=Symbol.for("react.element"),e=Symbol.for("react.fragment"),t=Object.prototype.hasOwnProperty,i=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function s(l,c,d){var u,h={},g=null,S=null;d!==void 0&&(g=""+d),c.key!==void 0&&(g=""+c.key),c.ref!==void 0&&(S=c.ref);for(u in c)t.call(c,u)&&!o.hasOwnProperty(u)&&(h[u]=c[u]);if(l&&l.defaultProps)for(u in c=l.defaultProps,c)h[u]===void 0&&(h[u]=c[u]);return{$$typeof:r,type:l,key:g,ref:S,props:h,_owner:i.current}}return Un.Fragment=e,Un.jsx=s,Un.jsxs=s,Un}var ca;function Xh(){return ca||(ca=1,zr.exports=zh()),zr.exports}var I=Xh();const Yh="univer-sheets-ui-context-menu-input",Gh="univer-sheets-ui-context-menu-input-container",Zh="univer-sheets-ui-context-menu-input-number",Xr={sheetsUiContextMenuInput:Yh,sheetsUiContextMenuInputContainer:Gh,sheetsUiContextMenuInputNumber:Zh},gl=n=>{const{prefix:r,suffix:e,value:t,onChange:i,min:o=Number.MIN_SAFE_INTEGER,max:s=Number.MAX_SAFE_INTEGER}=n,l=a.useDependency(a.LocaleService),c=a.useDependency(R.IContextMenuService),[d,u]=H.useState(),h=S=>{var f;u(S==null?void 0:S.toString()),i((f=S==null?void 0:S.toString())!=null?f:"")};H.useEffect(()=>{c.visible||u(t)},[c.visible]),H.useEffect(()=>{u(t)},[t]);function g(S){S.key==="Backspace"&&S.stopPropagation()}return I.jsxs("div",{className:Xr.sheetsUiContextMenuInput,children:[l.t(r),I.jsx("span",{className:Xr.sheetsUiContextMenuInputContainer,onClick:S=>S.stopPropagation(),children:I.jsx(K.InputNumber,{className:Xr.sheetsUiContextMenuInputNumber,value:Number(d),precision:0,onKeyDown:g,onChange:h,min:o,max:s})}),l.t(e)]})};function Kh(n){return n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.switchMap(r=>r?r.activeSheet$.pipe(O.map(e=>e?{workbook:r,worksheet:e}:null)):O.of(null)))}function Pe(n,r,e){return Kh(n).pipe(O.switchMap(t=>t?e(t):O.of(r)))}function Sl(n,r){const e=n.get(a.IUniverInstanceService),t=n.get(m.IExclusiveRangeService),i=n.get(m.SheetsSelectionsService);return e.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).pipe(O.switchMap(s=>s?O.combineLatest([i.selectionMoveEnd$,s.activeSheet$]).pipe(O.switchMap(([l,c])=>{if(!c||l.length===0)return O.of(!1);const d=t.getInterestGroupId(l);if(r){const u=d.filter(h=>r.has(h));return O.of(u.length>0)}else return O.of(d.length>0)})):O.of(!1)))}function Qt(n,r,e){return O.combineLatest([r,Sl(n,e)]).pipe(O.map(([t,i])=>t||i))}function $(n,r={},e=!1){var u;const i=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),o=n.get(a.UserManagerService),s=n.has(he)?n.get(he):null,c=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR),d=(u=s==null?void 0:s.visible$)!=null?u:O.of(null);return O.combineLatest([o.currentUser$,i,d,c]).pipe(O.switchMap(([h,g,S,f])=>!g||S!=null&&S.visible&&S.unitId===g.getUnitId()&&!e||f&&!e?O.of(!0):g.activeSheet$.pipe(O.switchMap(p=>{if(!p)return O.of(!0);const v=n.get(m.SheetsSelectionsService),C=n.get(m.RangeProtectionRuleModel),_=n.get(m.WorksheetProtectionRuleModel),E=n.get(a.IContextService).subscribeContextValue$(a.FOCUSING_COMMON_DRAWINGS).pipe(O.startWith(!1));return O.combineLatest([v.selectionMoveEnd$,E]).pipe(O.switchMap(([M,w])=>{if(w)return O.of(!0);const P=g.getUnitId(),x=p.getSheetId(),A=n.get(a.IPermissionService),{workbookTypes:N=[m.WorkbookEditablePermission],worksheetTypes:D,rangeTypes:k}=r,B=[];if(N==null||N.forEach(L=>{B.push(new L(P).id)}),D==null||D.forEach(L=>{B.push(new L(P,x).id)}),_.getRule(P,x))return A.composePermission$(B).pipe(O.map(L=>L.some(W=>W.value===!1)));const U=M==null?void 0:M.map(L=>L.range),F=C.getSubunitRuleList(P,x).filter(L=>U==null?void 0:U.some(W=>L.ranges.some(j=>a.Rectangle.intersects(W,j))));return k==null||k.forEach(L=>{F.forEach(W=>{B.push(new L(P,x,W.permissionId).id)})}),A.composePermission$(B).pipe(O.map(L=>L.some(W=>W.value===!1)))}))}))))}function Ar(n){const r=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(m.RangeProtectionRuleModel),i=n.get(a.IPermissionService);return O.merge(e.selectionMoveEnd$,i.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var h;const o=(h=e.getCurrentLastSelection())==null?void 0:h.range;if(!o)return!0;const s=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s==null?void 0:s.getActiveSheet();if(!s||!l)return!0;const c=s.getUnitId(),d=l.getSheetId(),u=[new m.WorkbookEditablePermission(c).id,new m.WorksheetEditPermission(c,d).id];return t.getSubunitRuleList(c,d).filter(g=>g.ranges.some(S=>a.Rectangle.intersects(o,S))).forEach(g=>{u.push(new m.RangeProtectionPermissionEditPoint(c,d,g.permissionId).id)}),i.composePermission(u).some(g=>g.value===!1)}))}function fl(n,r){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var g;const s=(g=t.getCurrentLastSelection())==null?void 0:g.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),c=l==null?void 0:l.getActiveSheet();if(!l||!c)return!0;const d=l.getUnitId(),u=c.getSheetId(),h=[new m.WorkbookEditablePermission(d).id,new m.WorksheetEditPermission(d,u).id];return i.getSubunitRuleList(d,u).filter(S=>r==="row"?S.ranges.some(f=>s.endRow>f.startRow&&s.endRow<=f.endRow):S.ranges.some(f=>s.endColumn>f.startColumn&&s.endColumn<=f.endColumn)).forEach(S=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,S.permissionId).id)}),o.composePermission(h).some(S=>S.value===!1)}))}function pl(n,r){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var g;const s=(g=t.getCurrentLastSelection())==null?void 0:g.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),c=l==null?void 0:l.getActiveSheet();if(!l||!c)return!0;const d=l.getUnitId(),u=c.getSheetId(),h=[new m.WorkbookEditablePermission(d).id,new m.WorksheetEditPermission(d,u).id];return i.getSubunitRuleList(d,u).filter(S=>r==="row"?S.ranges.some(f=>s.startRow>f.startRow&&s.startRow<=f.endRow):S.ranges.some(f=>s.startColumn>f.startColumn&&s.startColumn<=f.endColumn)).forEach(S=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,S.permissionId).id)}),o.composePermission(h).some(S=>S.value===!1)}))}function vl(n,r){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var S;const s=(S=t.getCurrentLastSelection())==null?void 0:S.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),c=l==null?void 0:l.getActiveSheet();if(!l||!c)return!0;const d=l.getUnitId(),u=c.getSheetId(),h=[new m.WorkbookEditablePermission(d).id,new m.WorksheetEditPermission(d,u).id],g=a.Tools.deepClone(s);return r==="row"?(g.startColumn=0,g.endColumn=c.getColumnCount()-1):(g.startRow=0,g.endRow=c.getRowCount()-1),i.getSubunitRuleList(d,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),o.composePermission(h).some(f=>f.value===!1)}))}function Nr(n,r){const e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(m.RangeProtectionRuleModel),o=n.get(a.IPermissionService);return O.merge(t.selectionMoveEnd$,o.permissionPointUpdate$.pipe(O.debounceTime(100))).pipe(O.map(()=>{var S;const s=(S=t.getCurrentLastSelection())==null?void 0:S.range;if(!s)return!0;const l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),c=l==null?void 0:l.getActiveSheet();if(!l||!c)return!0;const d=l.getUnitId(),u=c.getSheetId(),h=[new m.WorkbookEditablePermission(d).id,new m.WorksheetEditPermission(d,u).id],g=a.Tools.deepClone(s);return r==="row"?g.endRow=c.getRowCount()-1:g.endColumn=c.getColumnCount()-1,i.getSubunitRuleList(d,u).filter(f=>f.ranges.some(p=>a.Rectangle.intersects(g,p))).forEach(f=>{h.push(new m.RangeProtectionPermissionEditPoint(d,u,f.permissionId).id)}),o.composePermission(h).some(f=>f.value===!1)}))}function Nn(n,r){const t=n.get(a.IUniverInstanceService).getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),i=n.get(m.WorksheetProtectionRuleModel),o=n.get(m.RangeProtectionRuleModel),s=n.get(a.IPermissionService),l=n.get(a.UserManagerService);return O.combineLatest([l.currentUser$,t]).pipe(O.switchMap(([c,d])=>d?d.activeSheet$.pipe(O.switchMap(u=>{if(!u)return O.of(!0);const h=d.getUnitId(),g=[];return r.forEach(f=>g.push(new f(h).id)),s.composePermission$(g).pipe(O.map(f=>f.every(p=>p.value===!0))).pipe(O.map(f=>{if(!f)return!0;const p=u.getSheetId(),v=i.getRule(h,p),C=o.getSubunitRuleList(h,p);return!!(v||C.length)}))})):O.of(!0)))}var Cl=(n=>(n.ROW_HEADER_CONTEXT_MENU="ROW_HEADER_CONTEXT_MENU",n.COL_HEADER_CONTEXT_MENU="COL_HEADER_CONTEXT_MENU",n.SHEET_BAR="SHEET_BAR",n.SHEET_FOOTER="SHEET_FOOTER",n))(Cl||{});function qh(n){const r=n.get(tt);return{id:xn.id,subId:wr.id,type:R.MenuItemType.BUTTON,icon:"BrushSingle",title:"Format Painter",tooltip:"toolbar.formatPainter",activated$:new O.Observable(e=>{let t=!1;const i=r.status$.subscribe(o=>{t=o!==De.OFF,e.next(t)});return e.next(t),()=>{i.unsubscribe()}}),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetCopyPermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function Qh(n){const r=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IContextService),i=n.get(m.SheetsSelectionsService);return{id:Gt.id,type:R.MenuItemType.BUTTON,icon:"BoldSingle",title:"Set bold",tooltip:"toolbar.bold",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:Pe(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=r.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=i.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontWeight.NORMAL;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontWeight()}s.next(v===a.FontWeight.BOLD)}if((g===Ie.SetTextSelectionsOperation.id||g===J.SetInlineFormatCommand.id)&&t.getContextValue(a.EDITOR_ACTIVATED)&&t.getContextValue(a.FOCUSING_SHEET)){const p=bi(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.bl;s.next(v===a.BooleanNumber.TRUE)}}),c=(u=i.getCurrentLastSelection())==null?void 0:u.primary;if(!o){s.next(!1);return}let d=a.FontWeight.NORMAL;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getFontWeight()}return s.next(d===a.FontWeight.BOLD),l.dispose})),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Jh(n){const r=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(a.IContextService);return{id:Zt.id,type:R.MenuItemType.BUTTON,icon:"ItalicSingle",title:"Set italic",tooltip:"toolbar.italic",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:Pe(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=r.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v=a.FontItalic.NORMAL;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getFontStyle()}s.next(v===a.FontItalic.ITALIC)}if((g===Ie.SetTextSelectionsOperation.id||g===J.SetInlineFormatCommand.id)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_SHEET)){const p=bi(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.it;s.next(v===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d=a.FontItalic.NORMAL;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getFontStyle()}return s.next(d===a.FontItalic.ITALIC),l.dispose})),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function $h(n){const r=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(a.IContextService);return{id:Kt.id,type:R.MenuItemType.BUTTON,icon:"UnderlineSingle",title:"Set underline",tooltip:"toolbar.underline",activated$:Pe(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=r.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getUnderline()}s.next(!!(v&&v.s))}if((g===Ie.SetTextSelectionsOperation.id||g===J.SetInlineFormatCommand.id)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_SHEET)){const p=bi(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.ul;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getUnderline()}return s.next(!!(d&&d.s)),l.dispose})),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function em(n){const r=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(a.IContextService);return{id:qt.id,type:R.MenuItemType.BUTTON,icon:"StrikethroughSingle",title:"Set strike through",tooltip:"toolbar.strikethrough",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),activated$:Pe(e,!1,({worksheet:o})=>new O.Observable(s=>{var u;const l=r.onCommandExecuted(h=>{var S,f;const g=h.id;if(g===m.SetRangeValuesMutation.id||g===m.SetSelectionsOperation.id||g===m.SetWorksheetActiveOperation.id){const p=(S=t.getCurrentLastSelection())==null?void 0:S.primary;let v;if(p!=null){const C=o.getRange(p.startRow,p.startColumn);v=C==null?void 0:C.getStrikeThrough()}s.next(!!(v&&v.s))}if((g===Ie.SetTextSelectionsOperation.id||g===J.SetInlineFormatCommand.id)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_SHEET)){const p=bi(n);if(p==null)return;const v=(f=p.ts)==null?void 0:f.st;s.next((v==null?void 0:v.s)===a.BooleanNumber.TRUE)}}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getStrikeThrough()}return s.next(!!(d&&d.s)),l.dispose})),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function tm(n){const r=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=a.DEFAULT_STYLES.ff;return{id:Si.id,tooltip:"toolbar.font",type:R.MenuItemType.SELECTOR,label:Mr,selections:R.FONT_FAMILY_LIST.map(o=>({label:{name:Pr,hoverable:!0},value:o.value})),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),value$:Pe(e,i,({worksheet:o})=>new O.Observable(s=>{var u;const l=r.onCommandExecuted(h=>{var p;const g=h.id;if(g!==m.SetRangeValuesMutation.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(p=t.getCurrentLastSelection())==null?void 0:p.primary;let f;if(S!=null){const v=o.getRange(S.startRow,S.startColumn);f=v==null?void 0:v.getFontFamily()}s.next(f!=null?f:i)}),c=(u=t.getCurrentLastSelection())==null?void 0:u.primary;let d;if(c!=null){const h=o.getRange(c.startRow,c.startColumn);d=h==null?void 0:h.getFontFamily()}return s.next(d!=null?d:i),l.dispose})),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function nm(n){const r=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(a.IContextService),o=a.DEFAULT_STYLES.fs,s=$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0);return{id:gi.id,type:R.MenuItemType.SELECTOR,tooltip:"toolbar.fontSize",label:{name:Or,props:{min:1,max:400,disabled$:s}},selections:R.FONT_SIZE_LIST,disabled$:s,value$:Pe(e,o,({worksheet:l})=>new O.Observable(c=>{var g;const d=r.onCommandExecuted(S=>{var p,v;const f=S.id;if(f===m.SetRangeValuesMutation.id||f===m.SetSelectionsOperation.id||f===m.SetWorksheetActiveOperation.id){const C=(p=t.getCurrentLastSelection())==null?void 0:p.primary;let _;if(C!=null){const b=l.getRange(C.startRow,C.startColumn);_=b==null?void 0:b.getFontSize()}c.next(_!=null?_:o)}if((f===Ie.SetTextSelectionsOperation.id||f===J.SetInlineFormatCommand.id)&&i.getContextValue(a.EDITOR_ACTIVATED)&&i.getContextValue(a.FOCUSING_SHEET)){const C=bi(n);if(C==null)return;const _=(v=C.ts)==null?void 0:v.fs;c.next(_!=null?_:o)}}),u=(g=t.getCurrentLastSelection())==null?void 0:g.primary;let h;if(u!=null){const S=l.getRange(u.startRow,u.startColumn);h=S==null?void 0:S.getFontSize()}return c.next(h!=null?h:o),d.dispose})),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function im(n){return{id:_s.id,type:R.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function rm(n){const r=n.get(a.ICommandService),e=n.get(a.ThemeService);return{id:En.id,icon:"FontColor",tooltip:"toolbar.textColor.main",type:R.MenuItemType.BUTTON_SELECTOR,selections:[{label:{name:Ii,hoverable:!1}}],value$:new O.Observable(t=>{const i=e.getCurrentTheme().textColor,o=r.onCommandExecuted(s=>{if(s.id===En.id){const l=s.params.value;t.next(l!=null?l:i)}});return t.next(i),o.dispose}),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]},!0)}}function om(n){return{id:m.ResetBackgroundColorCommand.id,type:R.MenuItemType.BUTTON,title:"toolbar.resetColor",icon:"NoColor",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function sm(n){const r=n.get(a.ICommandService),e=n.get(a.ThemeService);return{id:m.SetBackgroundColorCommand.id,tooltip:"toolbar.fillColor.main",type:R.MenuItemType.BUTTON_SELECTOR,icon:"PaintBucket",selections:[{label:{name:Ii,hoverable:!1}}],value$:new O.Observable(t=>{const i=e.getCurrentTheme().primaryColor,o=r.onCommandExecuted(s=>{if(s.id===m.SetBackgroundColorCommand.id){const l=s.params.value;t.next(l!=null?l:i)}});return t.next(i),o.dispose}),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const da=[{label:"align.left",icon:"LeftJustifyingSingle",value:a.HorizontalAlign.LEFT},{label:"align.center",icon:"HorizontallySingle",value:a.HorizontalAlign.CENTER},{label:"align.right",icon:"RightJustifyingSingle",value:a.HorizontalAlign.RIGHT}];function am(n){const r=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=a.HorizontalAlign.LEFT;return{id:m.SetHorizontalTextAlignCommand.id,icon:da[0].icon,tooltip:"toolbar.horizontalAlignMode.main",type:R.MenuItemType.SELECTOR,selections:da,value$:Pe(r,t,({worksheet:i})=>new O.Observable(o=>{var d;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetHorizontalTextAlignCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=e.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=i.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getHorizontalAlignment()}o.next(S!=null?S:t)}),l=(d=e.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const u=i.getRange(l.startRow,l.startColumn);c=u==null?void 0:u.getHorizontalAlignment()}return o.next(c!=null?c:t),s.dispose})),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const ua=[{label:"align.top",icon:"AlignTopSingle",value:a.VerticalAlign.TOP},{label:"align.middle",icon:"VerticalCenterSingle",value:a.VerticalAlign.MIDDLE},{label:"align.bottom",icon:"AlignBottomSingle",value:a.VerticalAlign.BOTTOM}];function lm(n){const r=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=a.VerticalAlign.BOTTOM;return{id:m.SetVerticalTextAlignCommand.id,icon:ua[2].icon,tooltip:"toolbar.verticalAlignMode.main",type:R.MenuItemType.SELECTOR,selections:ua,value$:Pe(r,t,({worksheet:i})=>new O.Observable(o=>{var d;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetVerticalTextAlignCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=e.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=i.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getVerticalAlignment()}o.next(S!=null?S:t)}),l=(d=e.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const u=i.getRange(l.startRow,l.startColumn);c=u==null?void 0:u.getVerticalAlignment()}return o.next(c!=null?c:t),s.dispose})),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const ha=[{label:"textWrap.overflow",icon:"OverflowSingle",value:a.WrapStrategy.OVERFLOW},{label:"textWrap.wrap",icon:"AutowrapSingle",value:a.WrapStrategy.WRAP},{label:"textWrap.clip",icon:"TruncationSingle",value:a.WrapStrategy.CLIP}];function cm(n){const r=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=a.WrapStrategy.OVERFLOW;return{id:m.SetTextWrapCommand.id,tooltip:"toolbar.textWrapMode.main",icon:ha[0].icon,type:R.MenuItemType.SELECTOR,selections:ha,value$:Pe(e,t,({worksheet:i})=>new O.Observable(o=>{var d;const s=n.get(a.ICommandService).onCommandExecuted(u=>{var f;const h=u.id;if(h!==m.SetTextWrapCommand.id&&h!==m.SetSelectionsOperation.id&&h!==m.SetWorksheetActiveOperation.id)return;const g=(f=r.getCurrentLastSelection())==null?void 0:f.primary;let S;if(g!=null){const p=i.getRange(g.startRow,g.startColumn);S=p==null?void 0:p.getWrapStrategy()}o.next(S!=null?S:t)}),l=(d=r.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const u=i.getRange(l.startRow,l.startColumn);c=u==null?void 0:u.getWrapStrategy()}return o.next(c!=null?c:t),s.dispose})),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}const ma=[{label:"textRotate.none",icon:"NoRotationSingle",value:0},{label:"textRotate.angleUp",icon:"LeftRotationFortyFiveDegreesSingle",value:-45},{label:"textRotate.angleDown",icon:"RightRotationFortyFiveDegreesSingle",value:45},{label:"textRotate.vertical",icon:"VerticalTextSingle",value:"v"},{label:"textRotate.rotationUp",icon:"LeftRotationNinetyDegreesSingle",value:-90},{label:"textRotate.rotationDown",icon:"RightRotationNinetyDegreesSingle",value:90}];function dm(n){const r=n.get(m.SheetsSelectionsService),e=n.get(a.IUniverInstanceService),t=0;return{id:m.SetTextRotationCommand.id,tooltip:"toolbar.textRotateMode.main",icon:ma[0].icon,type:R.MenuItemType.SELECTOR,selections:ma,value$:Pe(e,t,({worksheet:i})=>new O.Observable(o=>{var d,u;const s=n.get(a.ICommandService).onCommandExecuted(h=>{var p,v;const g=h.id;if(g!==m.SetTextRotationCommand.id&&g!==m.SetSelectionsOperation.id&&g!==m.SetWorksheetActiveOperation.id)return;const S=(p=r.getCurrentLastSelection())==null?void 0:p.primary;let f;if(S!=null){const C=i.getRange(S.startRow,S.startColumn);f=C==null?void 0:C.getTextRotation()}(f==null?void 0:f.v)===a.BooleanNumber.TRUE?o.next("v"):o.next((v=f&&f.a)!=null?v:t)}),l=(d=r.getCurrentLastSelection())==null?void 0:d.primary;let c;if(l!=null){const h=i.getRange(l.startRow,l.startColumn);c=h==null?void 0:h.getTextRotation()}return(c==null?void 0:c.v)===a.BooleanNumber.TRUE?o.next("v"):o.next((u=c&&c.a)!=null?u:t),s.dispose})),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function _i(n){return new O.Observable(e=>e.next(!n.get(R.IClipboardInterfaceService).supportClipboard))}function Sn(n){return{id:Fe.name,commandId:Fe.id,type:R.MenuItemType.BUTTON,title:"rightClick.copy",icon:"Copy",disabled$:$(n,{workbookTypes:[m.WorkbookCopyPermission],worksheetTypes:[m.WorksheetCopyPermission],rangeTypes:[m.RangeProtectionPermissionViewPoint]}),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Yr(n){return{id:je.name,commandId:je.id,type:R.MenuItemType.BUTTON,title:"rightClick.paste",icon:"PasteSpecial",disabled$:_i(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([r,e])=>r||e)),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Kn="sheet.menu.paste-special";function Gr(n){return{id:Kn,type:R.MenuItemType.SUBITEMS,icon:"PasteSpecial",title:"rightClick.pasteSpecial",hidden$:Qt(n,R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET))}}function Zr(n){return{id:hn.id,type:R.MenuItemType.BUTTON,title:"rightClick.pasteValue",disabled$:_i(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellValuePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([r,e])=>r||e)),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Kr(n){return{id:mn.id,type:R.MenuItemType.BUTTON,title:"rightClick.pasteFormat",disabled$:_i(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetCellStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([r,e])=>r||e)),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function qr(n){return{id:kt.id,type:R.MenuItemType.BUTTON,title:"rightClick.pasteColWidth",disabled$:_i(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([r,e])=>r||e))}}function Qr(n){return{id:gn.id,type:R.MenuItemType.BUTTON,title:"rightClick.pasteBesidesBorder",disabled$:_i(n).pipe(O.combineLatestWith($(n,{rangeTypes:[m.RangeProtectionPermissionEditPoint],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetCellStylePermission,m.WorksheetSetCellValuePermission,m.WorksheetSetRowStylePermission,m.WorksheetSetColumnStylePermission],workbookTypes:[m.WorkbookEditablePermission]})),O.map(([r,e])=>r||e)),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function um(n){return{id:m.SetWorksheetRowIsAutoHeightCommand.id,type:R.MenuItemType.BUTTON,icon:"AutoHeight",title:"rightClick.fitContent",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function hm(n){return{id:yr.id,type:R.MenuItemType.BUTTON,icon:"AutoWidth",title:"rightClick.fitContent",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Il="sheet.menu.sheet-frozen";function mm(n){return{id:Il,type:R.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}const Uo="sheet.header-menu.sheet-frozen";function ga(n){return{id:Uo,type:R.MenuItemType.SUBITEMS,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Jr(n){return{id:ut.id,type:R.MenuItemType.BUTTON,title:"rightClick.freeze",icon:"FreezeToSelectedSingle",hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function gm(n){return{id:vi.id,type:R.MenuItemType.BUTTON,title:"rightClick.freezeRow",icon:"FreezeRowSingle",hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function Sm(n){return{id:Ci.id,type:R.MenuItemType.BUTTON,title:"rightClick.freezeCol",icon:"FreezeColumnSingle",hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function $r(n){return{id:m.CancelFrozenCommand.id,type:R.MenuItemType.BUTTON,title:"rightClick.cancelFreeze",icon:"CancelFreezeSingle",hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function fm(n){return{id:hi.id,type:R.MenuItemType.BUTTON,icon:"Hide",title:"rightClick.hideSelectedRow",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetRowStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function pm(n){return{id:mi.id,type:R.MenuItemType.BUTTON,icon:"Hide",title:"rightClick.hideSelectedColumn",disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]}),hidden$:R.getMenuHiddenObservable(n,a.UniverInstanceType.UNIVER_SHEET)}}function vm(n){const r=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=[m.SetSelectionsOperation,m.SetRowHiddenMutation,m.SetRowVisibleMutation].map(o=>o.id);return{id:m.SetSelectedRowsVisibleCommand.id,type:R.MenuItemType.BUTTON,title:"rightClick.showHideRow",hidden$:Pe(r,!0,({worksheet:o})=>new O.Observable(s=>{function l(){var u;const d=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.ROW);return!!(d!=null&&d.some(h=>{for(let g=h.startRow;g<=h.endRow;g++)if(!o.getRowRawVisible(g))return!0;return!1}))}const c=t.onCommandExecuted(d=>{i.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Cm(n){const r=n.get(a.IUniverInstanceService),e=n.get(m.SheetsSelectionsService),t=n.get(a.ICommandService),i=[m.SetSelectionsOperation,m.SetColHiddenMutation,m.SetColVisibleMutation].map(o=>o.id);return{id:m.SetSelectedColsVisibleCommand.id,type:R.MenuItemType.BUTTON,title:"rightClick.showHideColumn",hidden$:Pe(r,!0,({worksheet:o})=>new O.Observable(s=>{function l(){var u;const d=(u=e.getCurrentSelections())==null?void 0:u.map(h=>h.range).filter(h=>h.rangeType===a.RANGE_TYPE.COLUMN);return!d||d.length===0?!1:!!d.some(h=>{for(let g=h.startColumn;g<=h.endColumn;g++)if(!o.getColVisible(g))return!0;return!1})}const c=t.onCommandExecuted(d=>{i.findIndex(u=>u===d.id)!==-1&&s.next(!l())});return s.next(!l()),()=>c.dispose()})),disabled$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetSetColumnStylePermission,m.WorksheetEditPermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function Im(n){const r=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=0;return{id:m.SetRowHeightCommand.id,type:R.MenuItemType.BUTTON,icon:"AdjustHeight",label:{name:xr,props:{prefix:"rightClick.rowHeight",suffix:"px",min:2,max:1e3}},value$:Pe(e,i,({worksheet:o})=>new O.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary,u=d?o.getRowHeight(d.startRow):i;s.next(u)}const c=r.onCommandExecuted(d=>{const u=d.id;if(u===m.SetRangeValuesMutation.id||u===m.SetSelectionsOperation.id||u===m.SetWorksheetRowIsAutoHeightMutation.id)return l()});return l(),c.dispose})),hidden$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetRowStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function _m(n){const r=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=0;return{id:m.SetColWidthCommand.id,type:R.MenuItemType.BUTTON,icon:"AdjustWidth",label:{name:xr,props:{prefix:"rightClick.columnWidth",suffix:"px",min:2,max:1e3}},value$:Pe(e,i,({worksheet:o})=>new O.Observable(s=>{function l(){var h;const d=(h=t.getCurrentLastSelection())==null?void 0:h.primary;let u=i;d!=null&&(u=o.getColumnWidth(d.startColumn)),s.next(u)}const c=r.onCommandExecuted(d=>{const u=d.id;if(u===m.SetRangeValuesMutation.id||u===m.SetSelectionsOperation.id||u===m.SetWorksheetColWidthMutation.id)return l()});return l(),c.dispose})),hidden$:$(n,{workbookTypes:[m.WorkbookEditablePermission],worksheetTypes:[m.WorksheetEditPermission,m.WorksheetSetColumnStylePermission],rangeTypes:[m.RangeProtectionPermissionEditPoint]})}}function bi(n){var c;const r=n.get(a.IUniverInstanceService),e=n.get(Ie.DocSelectionManagerService),t=r.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),i=e.getActiveTextRange();if(t==null||i==null)return null;const o=(c=t.getBody())==null?void 0:c.textRuns;if(o==null)return;const{startOffset:s}=i;return o.find(({st:d,ed:u})=>s>=d&&s<=u)}var bm=Object.defineProperty,Rm=Object.getOwnPropertyDescriptor,Em=(n,r,e,t)=>{for(var i=t>1?void 0:t?Rm(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&bm(r,e,i),i},Ot=(n,r)=>(e,t)=>r(e,t,n);const Tm="__SpreadsheetFreezeRowMainName__",wm="__SpreadsheetFreezeRowHeaderName__",ym="__SpreadsheetFreezeColumnMainName__",Mm="__SpreadsheetFreezeColumnHeaderName__",eo=2,Pm=.01,Ln=a.createInterceptorKey("freezePermissionCheck");exports.HeaderFreezeRenderController=class extends a.Disposable{constructor(e,t,i,o,s,l,c,d){super();T(this,"_rowFreezeHeaderRect");T(this,"_rowFreezeMainRect");T(this,"_columnFreezeHeaderRect");T(this,"_columnFreezeMainRect");T(this,"_freezeDownSubs");T(this,"_freezePointerEnterSubs");T(this,"_freezePointerLeaveSubs");T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_changeToRow",-1);T(this,"_changeToColumn",-1);T(this,"_changeToOffsetX",0);T(this,"_changeToOffsetY",0);T(this,"_activeViewport",null);T(this,"_freezeNormalHeaderColor","");T(this,"_freezeNormalMainColor","");T(this,"_freezeActiveColor","");T(this,"_freezeHoverColor","");T(this,"_lastFreeze");T(this,"interceptor",new a.InterceptorManager({FREEZE_PERMISSION_CHECK:Ln}));this._context=e,this._sheetSkeletonManagerService=t,this._commandService=i,this._selectionManagerService=o,this._scrollManagerService=s,this._themeService=l,this._sheetInterceptorService=c,this._injector=d,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._themeChangeListener(),this._interceptorCommands(),this._bindViewportScroll(),this._zoomRefresh()}_createFreeze(e=0,t){var x;const i=t!=null?t:this._getFreeze();if(i==null)return null;const o=(x=this._sheetSkeletonManagerService.getCurrent())==null?void 0:x.skeleton,{startRow:s,startColumn:l}=i,c=this._getPositionByIndex(s,l);if(c==null||o==null)return null;const d=this._getSheetObject(),u=d.engine,h=(u==null?void 0:u.width)||0,g=(u==null?void 0:u.height)||0,S=d.scene,{startX:f,startY:p}=c,{rowTotalHeight:v,columnTotalWidth:C,rowHeaderWidthAndMarginLeft:_,columnHeaderHeightAndMarginTop:b}=o,E=h>C+_?h:C+b,M=g>v+b?g:v+b;this._changeToRow=s,this._changeToColumn=l,this._changeToOffsetX=f,this._changeToOffsetY=p;const w=Math.max(S.scaleX,S.scaleY);let P=eo/(w<1?1:w);if(e===0){(s===-1||s===0)&&(P=P*2);const A=P;this._rowFreezeHeaderRect=new y.Rect(wm,{fill:this._freezeNormalHeaderColor,width:_,height:P,left:0,top:p-A,zIndex:3});let N=this._freezeNormalHeaderColor;(s===-1||s===0)&&(N=this._freezeNormalMainColor),this._rowFreezeMainRect=new y.Rect(Tm,{fill:N,width:E*2/w,height:P,left:_,top:p-A,zIndex:3}),S.addObjects([this._rowFreezeHeaderRect,this._rowFreezeMainRect],bt)}else{(l===-1||l===0)&&(P=P*2);const A=P;this._columnFreezeHeaderRect=new y.Rect(Mm,{fill:this._freezeNormalHeaderColor,width:P,height:b,left:f-A,top:0,zIndex:3});let N=this._freezeNormalHeaderColor;(l===-1||l===0)&&(N=this._freezeNormalMainColor),this._columnFreezeMainRect=new y.Rect(ym,{fill:N,width:P,height:M*2/w,left:f-A,top:b,zIndex:3}),S.addObjects([this._columnFreezeHeaderRect,this._columnFreezeMainRect],bt)}this._eventBinding(e)}_eventBinding(e=0){let t=this._rowFreezeHeaderRect,i=this._rowFreezeMainRect;e===1&&(t=this._columnFreezeHeaderRect,i=this._columnFreezeMainRect);const o=this._getSheetObject();if(o==null)return;const{scene:s}=o;if(this._freezePointerEnterSubs=new O.Subscription,this._freezePointerLeaveSubs=new O.Subscription,this._freezeDownSubs=new O.Subscription,i){const d=i.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Ln)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(y.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(d);const u=i.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}if(t){const d=t.onPointerEnter$.subscribeEvent(()=>{if(!this.interceptor.fetchThroughInterceptors(Ln)(!0,null))return!1;t==null||t.setProps({fill:this._freezeHoverColor,zIndex:4}),s.setCursor(y.CURSOR_TYPE.GRAB)});this._freezePointerEnterSubs.add(d);const u=t.onPointerLeave$.subscribeEvent(()=>{t==null||t.setProps({fill:this._freezeNormalHeaderColor,zIndex:3}),s.resetCursor()});this._freezePointerLeaveSubs.add(u)}const l=t==null?void 0:t.onPointerDown$.subscribeEvent(d=>{this._freezeDown(d,t,i,e)});l&&this._freezeDownSubs.add(l);const c=i==null?void 0:i.onPointerDown$.subscribeEvent(d=>{this._freezeDown(d,t,i,e)});c&&this._freezeDownSubs.add(c)}_getCurrentLastVisible(){var C,_,b,E,M,w,P;const e=this._getSheetObject();if(e==null)return;const t=(C=this._sheetSkeletonManagerService.getCurrent())==null?void 0:C.skeleton;if(t==null)return;const i=e.scene,o=Math.max(i.scaleX,i.scaleY),s=this._scrollManagerService.getCurrentScrollState(),l=(e.engine.height-t.columnHeaderHeight)/o,c=(e.engine.width-t.rowHeaderWidth)/o,d=(_=s==null?void 0:s.sheetViewStartRow)!=null?_:0,u=d===0?-((b=s==null?void 0:s.offsetY)!=null?b:0):t.rowHeightAccumulation[d-1]-((E=s==null?void 0:s.offsetY)!=null?E:0);let h=0,g=!1;for(let x=d,A=t.rowHeightAccumulation.length;x<A;x++)if(t.rowHeightAccumulation[x]-u>l){h=x,g=!0;break}g||(h=t.rowHeightAccumulation.length-1);const S=(M=s==null?void 0:s.sheetViewStartColumn)!=null?M:0,f=S===0?-((w=s==null?void 0:s.offsetX)!=null?w:0):t.columnWidthAccumulation[S-1]-((P=s==null?void 0:s.offsetX)!=null?P:0);let p=0,v=!1;for(let x=S,A=t.columnWidthAccumulation.length;x<A;x++)if(t.columnWidthAccumulation[x]-f>c){p=x,v=!0;break}return v||(p=t.columnWidthAccumulation.length-1),{lastRow:h,lastColumn:p}}_getActiveViewport(e){var i;const t=(i=this._getSheetObject())==null?void 0:i.scene.getViewports();return t&&t.find(o=>o.isHit(new y.Vector2(e.offsetX,e.offsetY)))||null}_freezeDown(e,t,i,o=0){var f;const s=(f=this._sheetSkeletonManagerService.getCurrent())==null?void 0:f.skeleton;if(s==null)return;const l=this._getSheetObject();if(l==null)return;if(!this.interceptor.fetchThroughInterceptors(Ln)(!0,null))return!1;const{scene:d}=l;d.setCursor(y.CURSOR_TYPE.GRABBING),d.disableObjectsEvent();const u=this._getCurrentLastVisible(),h=u===void 0?Number.POSITIVE_INFINITY:s.rowHeightAccumulation[u.lastRow],g=u===void 0?Number.POSITIVE_INFINITY:s.columnWidthAccumulation[u.lastColumn-1]+s.rowHeaderWidth;this._activeViewport=null;const S=this._getFreeze();S&&(this._changeToColumn=S.startColumn,this._changeToRow=S.startRow),this._scenePointerMoveSub=d.onPointerMove$.subscribeEvent(p=>{var P,x,A,N;const v=this._getActiveViewport(p),{startX:C,startY:_,row:b,column:E}=Ke(p.offsetX,p.offsetY,d,s,v||void 0,!0);if(!this.interceptor.fetchThroughInterceptors(Ln)(!0,null))return!1;d.setCursor(y.CURSOR_TYPE.GRABBING);const w=eo/Math.max(d.scaleX,d.scaleY);o===0?((P=t.transformByState({top:Math.min(_,h)-w/2}))==null||P.setProps({fill:this._freezeActiveColor}),(x=i.transformByState({top:Math.min(_,h)-w/2}))==null||x.setProps({fill:this._freezeNormalHeaderColor}),this._changeToRow=u===void 0?b:Math.min(b,u.lastRow),this._changeToOffsetY=Math.min(_,h),this._activeViewport=v):((A=t.transformByState({left:Math.min(C,g)-w/2}))==null||A.setProps({fill:this._freezeActiveColor}),(N=i.transformByState({left:Math.min(C,g)-w/2}))==null||N.setProps({fill:this._freezeNormalHeaderColor}),this._changeToColumn=u===void 0?E:Math.min(E,u.lastColumn),this._changeToOffsetX=C,this._activeViewport=v)}),this._scenePointerUpSub=d.onPointerUp$.subscribeEvent(()=>{var D,k;d.resetCursor(),d.enableObjectsEvent(),this._clearObserverEvent();const{rowHeaderWidthAndMarginLeft:p,columnHeaderHeightAndMarginTop:v}=s;o===0&&(this._changeToRow===0||this._changeToRow===-1)||o===1&&(this._changeToColumn===0||this._changeToColumn===-1)?(t.setProps({fill:this._freezeNormalHeaderColor}),i.setProps({fill:this._freezeNormalMainColor})):(t==null||t.setProps({fill:this._freezeNormalHeaderColor}),i==null||i.setProps({fill:this._freezeNormalHeaderColor}));const C=eo/Math.max(d.scaleX,d.scaleY);o===0?(this._changeToRow===0||this._changeToRow===-1)&&(t.transformByState({top:v-C}),i.transformByState({top:v-C})):(this._changeToColumn===0||this._changeToColumn===-1)&&(t.transformByState({left:p-C}),i.transformByState({left:p-C}));const _=this._scrollManagerService.getCurrentScrollState()||{sheetViewStartRow:0,sheetViewStartColumn:0},{sheetViewStartRow:b,sheetViewStartColumn:E}=_;if(E==null||b==null)return;const M=this._context.unit,w=M.getActiveSheet();if(!w)return;const P=(D=w.getConfig())==null?void 0:D.freeze;let x=(P==null?void 0:P.xSplit)||0,A=(P==null?void 0:P.ySplit)||0;const N=(k=this._activeViewport)==null?void 0:k.viewportKey;o===0&&(!N||N===y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||N===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||N===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP||N===y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP?A=this._changeToRow-(P.startRow-P.ySplit):A=this._changeToRow-b,A=A<0?0:A),o===1&&(!N||N===y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP||N===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP||N===y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT||N===y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT?x=this._changeToColumn-(P.startColumn-P.xSplit):x=this._changeToColumn-E,x=x<0?0:x),this._commandService.executeCommand(m.SetFrozenCommand.id,{startRow:A===0?-1:this._changeToRow,startColumn:x===0?-1:this._changeToColumn,ySplit:A,xSplit:x,unitId:M.getUnitId(),subUnitId:w.getSheetId()})})}_getViewports(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e,i=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT),o=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT),s=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP),l=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM),c=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP),d=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),u=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP),h=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT),g=t.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(!(i==null||o==null||s==null||l==null||c==null||d==null||u==null||h==null||g==null))return{viewMain:d,viewMainLeftTop:u,viewMainLeft:h,viewMainTop:g,viewColumnLeft:i,viewColumnRight:o,viewRowTop:s,viewRowBottom:l,viewLeftTop:c}}_bindViewportScroll(){const e=this._getViewports();if(!e)return;const{viewRowBottom:t,viewColumnRight:i,viewMainLeft:o,viewMainTop:s}=e;this.disposeWithMe(this._scrollManagerService.validViewportScrollInfo$.subscribe(l=>{if(!l)return;const{scrollX:c,scrollY:d,viewportScrollX:u,viewportScrollY:h}=l;t.isActive&&t.updateScrollVal({scrollY:d,viewportScrollY:h}),i.isActive&&i.updateScrollVal({scrollX:c,viewportScrollX:u}),o.isActive&&o.updateScrollVal({scrollY:d,viewportScrollY:h}),s.isActive&&s.updateScrollVal({scrollX:c,viewportScrollX:u})}))}_updateViewport(e=-1,t=-1,i=0,o=0,s=3){var x;const l=(x=this._sheetSkeletonManagerService.getCurrent())==null?void 0:x.skeleton;if(l==null)return;const{rowHeaderWidthAndMarginLeft:c,columnHeaderHeightAndMarginTop:d}=l,u=this._getViewports();if(!u)return;const{viewMain:h,viewMainLeftTop:g,viewMainLeft:S,viewMainTop:f,viewColumnLeft:p,viewColumnRight:v,viewRowTop:C,viewRowBottom:_,viewLeftTop:b}=u;v.resizeWhenFreezeChange({left:c,top:0,height:d,right:0}),_.resizeWhenFreezeChange({left:0,top:d,bottom:0,width:c}),b.resizeWhenFreezeChange({left:0,top:0,width:c,height:d});let E=!0,M=!0;g.enable(),(e===-1||e===0)&&(E=!1),(t===-1||t===0)&&(M=!1);const w=l.getNoMergeCellPositionByIndexWithNoHeader(e-i,t-o),P=l.getNoMergeCellPositionByIndexWithNoHeader(e,t);if(g.disable(),f.disable(),S.disable(),C.disable(),p.disable(),g.resetPadding(),f.resetPadding(),S.resetPadding(),C.resetPadding(),p.resetPadding(),E===!1&&M===!1)h.resizeWhenFreezeChange({left:c,top:d,bottom:0,right:0}),h.resetPadding();else if(E===!0&&M===!1){const A=P.startY-w.startY;h.resizeWhenFreezeChange({left:c,top:d+A,bottom:0,right:0}),h.setPadding({startY:w.startY,endY:P.startY,startX:0,endX:0}),s&2&&this._commandService.executeCommand(Be.id,{sheetViewStartRow:0,offsetY:0}),f.resizeWhenFreezeChange({left:c,top:d,height:A,right:0}),f.updateScrollVal({viewportScrollY:w.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),C.resizeWhenFreezeChange({left:0,top:d,width:c,height:A}),C.updateScrollVal({viewportScrollY:w.startY}),_.resizeWhenFreezeChange({left:0,top:d+A,bottom:0,width:c}),f.enable(),C.enable()}else if(E===!1&&M===!0){const A=P.startX-w.startX;h.resizeWhenFreezeChange({left:c+A,top:d,bottom:0,right:0}),h.setPadding({startX:w.startX,endX:P.startX,startY:0,endY:0}),s&1&&this._commandService.executeCommand(Be.id,{sheetViewStartColumn:0,offsetX:0}),S.resizeWhenFreezeChange({left:c,top:d,width:A,bottom:0,right:0}),S.updateScrollVal({viewportScrollX:w.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),p.resizeWhenFreezeChange({left:c,top:0,width:A,height:d}),p.updateScrollVal({viewportScrollX:w.startX}),v.resizeWhenFreezeChange({left:c+A,top:0,height:d,right:0}),S.enable(),p.enable()}else{const A=P.startX-w.startX,N=P.startY-w.startY;h.resizeWhenFreezeChange({left:c+A,top:d+N,bottom:0,right:0}),h.setPadding({startY:w.startY,endY:P.startY,startX:w.startX,endX:P.startX}),s&&this._commandService.executeCommand(Be.id,{...s&1?{sheetViewStartColumn:0,offsetX:0}:null,...s&2?{sheetViewStartRow:0,offsetY:0}:null}),S.resizeWhenFreezeChange({left:c,top:d+N,width:A,bottom:0}),S.updateScrollVal({viewportScrollX:w.startX,rawScrollY:h.scrollY,viewportScrollY:h.viewportScrollY}),f.resizeWhenFreezeChange({left:c+A,top:d,height:N,right:0}),f.updateScrollVal({viewportScrollY:w.startY,rawScrollX:h.scrollX,viewportScrollX:h.viewportScrollX}),g.resizeWhenFreezeChange({left:c,top:d,width:A,height:N}),g.updateScrollVal({viewportScrollX:w.startX,viewportScrollY:w.startY}),C.resizeWhenFreezeChange({left:0,top:d,width:c,height:N}),C.updateScrollVal({viewportScrollY:w.startY}),_.resizeWhenFreezeChange({left:0,top:d+N,bottom:0,width:c}),p.resizeWhenFreezeChange({left:c,top:0,width:A,height:d}),p.updateScrollVal({viewportScrollX:w.startX}),v.resizeWhenFreezeChange({left:c+A,top:0,height:d,right:0}),g.enable(),f.enable(),S.enable(),C.enable(),p.enable()}}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{[m.SetWorksheetActiveOperation.id,m.InsertRangeMoveDownCommand.id,m.InsertRangeMoveRightCommand.id].includes((e==null?void 0:e.commandId)||"")&&this._refreshCurrent()})))}_refreshCurrent(){const t=this._context.unit.getActiveSheet();if(!t)return;const i=t.getConfig().freeze,{startRow:o=-1,startColumn:s=-1,ySplit:l=0,xSplit:c=0}=i;this._refreshFreeze(o,s,l,c,0)}_themeChangeListener(){this._themeChange(this._themeService.getCurrentTheme()),this.disposeWithMe(this._themeService.currentTheme$.subscribe(e=>{this._clearFreeze(),this._themeChange(e),this._refreshCurrent()}))}_themeChange(e){this._freezeNormalHeaderColor=e.grey400,this._freezeNormalMainColor=new a.ColorKit(e.grey400).setAlpha(Pm).toRgbString(),this._freezeActiveColor=e.primaryColor,this._freezeHoverColor=e.grey500}_interceptorCommands(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:e=>{const t={redos:[],undos:[]},i=this._getFreeze();if(!i)return t;const o=s=>{const l=this._context.unit,c=l.getUnitId(),d=l.getActiveSheet();if(!d)return t;const u=d.getSheetId();this._refreshFreeze(s.startRow,s.startColumn,s.ySplit,s.xSplit,0);const h={...s,unitId:c,subUnitId:u,resetScroll:!1},g=m.SetFrozenMutationFactory(this._injector,h);return{undos:[{id:m.SetFrozenMutation.id,params:g}],redos:[{id:m.SetFrozenMutation.id,params:h}]}};if(e.id===m.InsertRowCommand.id){const s=e.params,{range:l,direction:c}=s,d=l.endRow-l.startRow+1;if(l.startRow+1<i.startRow||l.startRow+1===i.startRow&&c===a.Direction.UP){const u={...i,startRow:Math.max(1,i.startRow+d),ySplit:Math.max(1,i.ySplit+d)};return o(u)}}if(e.id===m.InsertColCommand.id){const s=e.params,{range:l,direction:c}=s,d=l.endColumn-l.startColumn+1;if(l.startColumn+1<i.startColumn||l.startColumn+1===i.startColumn&&c===a.Direction.LEFT){const u={...i,startColumn:Math.max(1,i.startColumn+d),xSplit:Math.max(1,i.xSplit+d)};return o(u)}}if(e.id===m.MoveColsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startColumn:l},toRange:{startColumn:c}}=e.params,d=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.COLUMN&&C.range.startColumn<=l&&l<=C.range.endColumn);if(!(d!=null&&d.length))return t;const u=d[0].range,h={...u,startColumn:c,endColumn:c+u.endColumn-u.startColumn};if(!i||i.startColumn<=0||u.startColumn>=i.startColumn&&h.startColumn>=i.startColumn||u.startColumn===h.startColumn||u.endColumn<i.startColumn&&h.startColumn<i.startColumn)return t;const g=u.endColumn-u.startColumn+1,S=Math.max(Math.min(i.startColumn,u.endColumn+1)-u.startColumn,0);let f,p;h.startColumn>=i.startColumn?(f=Math.max(i.startColumn-S,1),p=Math.max(i.xSplit-S,1)):(f=i.startColumn+g-S,p=i.xSplit+g-S);const v={...i,startColumn:f,xSplit:p};return o(v)}if(e.id===m.MoveRowsCommand.id){const s=this._selectionManagerService.getCurrentSelections(),{fromRange:{startRow:l},toRange:{startRow:c}}=e.params,d=s==null?void 0:s.filter(C=>C.range.rangeType===a.RANGE_TYPE.ROW&&C.range.startRow<=l&&l<=C.range.endRow);if(!(d!=null&&d.length))return t;const u=d[0].range,h={...u,startRow:c,endRow:c+u.endRow-u.startRow};if(!i||i.startRow<=0||u.startRow>=i.startRow&&h.startRow>=i.startRow||u.startRow===h.startRow||u.endRow<i.startRow&&h.startRow<i.startRow)return t;const g=u.endRow-u.startRow+1,S=Math.max(Math.min(i.startRow,u.endRow+1)-u.startRow,0);let f,p;h.startRow>=i.startRow?(f=Math.max(i.startRow-S,1),p=Math.max(i.ySplit-S,1)):(f=i.startRow+g-S,p=i.ySplit+g-S);const v={...i,startRow:f,ySplit:p};return o(v)}if(e.id===m.RemoveColCommand.id||e.id===m.RemoveRowCommand.id){const s=e.params,l=s.range;if(l.rangeType===a.RANGE_TYPE.COLUMN&&l.startColumn<i.startColumn){const c=Math.min(i.startColumn,l.endColumn+1)-l.startColumn,d={...i,startColumn:Math.max(1,i.startColumn-c),xSplit:Math.max(1,i.xSplit-c)};return o(d)}if(s.range.rangeType===a.RANGE_TYPE.ROW&&l.startRow<i.startRow){const c=Math.min(i.startRow,l.endRow+1)-l.startRow,d={...i,startRow:Math.max(1,i.startRow-c),ySplit:Math.max(1,i.ySplit-c)};return o(d)}}return t}}))}_commandExecutedListener(){const e=[m.SetFrozenMutation.id,ze.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const i=this._lastFreeze,o=this._context.unit,s=o.getActiveSheet(),l=t.params,{unitId:c,subUnitId:d}=l;if(!(c===o.getUnitId()&&d===(s==null?void 0:s.getSheetId())))return;const u=s.getConfig().freeze;if(this._lastFreeze=u,u==null)return;let h=0;const{startRow:g=-1,startColumn:S=-1,ySplit:f=0,xSplit:p=0}=u;(!i||i.startRow!==g||i.ySplit!==f)&&(h|=2),(!i||i.startColumn!==S||i.xSplit!==p)&&(h|=1),l.resetScroll===!1&&(h=0),this._refreshFreeze(g,S,f,p,h)}else if(t.id===m.SetWorksheetRowHeightMutation.id){const i=this._getFreeze(),o=i&&t.params.ranges.some(s=>s.startRow<i.startRow);t.params&&o&&this._refreshCurrent()}else if(t.id===m.SetWorksheetColWidthMutation.id){const i=this._getFreeze();t.params&&i&&t.params.ranges.some(o=>o.startColumn<i.startColumn)&&this._refreshCurrent()}else if(t.id===m.SetWorksheetRowAutoHeightMutation.id){const i=t.params,o=this._getFreeze();if(o&&o.startRow>-1&&i.rowsAutoHeightInfo.some(s=>s.row<o.startRow)){const s=this._sheetSkeletonManagerService.currentSkeleton$.subscribe(()=>{this._refreshCurrent(),setTimeout(()=>{s.unsubscribe()})})}}else if(t.id===m.SetColHiddenMutation.id||t.id===m.SetColVisibleMutation.id){const i=t.params,o=this._getFreeze(),s=i.ranges;o&&o.startColumn>-1&&s.some(l=>l.startColumn<o.startColumn)&&this._refreshCurrent()}else if(t.id===m.SetRowHiddenMutation.id||t.id===m.SetRowVisibleMutation.id){const i=t.params,o=this._getFreeze(),s=i.ranges;o&&o.startRow>-1&&s.some(l=>l.startRow<o.startRow)&&this._refreshCurrent()}}))}_zoomRefresh(){const e=this._getSheetObject();if(e==null)return;const{scene:t}=e;t.onTransformChange$.subscribeEvent(i=>{i.type===y.TRANSFORM_CHANGE_OBSERVABLE_TYPE.scale&&this._refreshCurrent()})}_clearObserverEvent(){var t,i;this._getSheetObject()!=null&&((t=this._scenePointerMoveSub)==null||t.unsubscribe(),(i=this._scenePointerUpSub)==null||i.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_clearFreeze(){var t,i,o,s,l,c;(t=this._rowFreezeHeaderRect)==null||t.dispose(),(i=this._rowFreezeMainRect)==null||i.dispose(),(o=this._columnFreezeHeaderRect)==null||o.dispose(),(s=this._columnFreezeMainRect)==null||s.dispose(),this._getSheetObject()!=null&&([this._freezeDownSubs,this._freezePointerEnterSubs,this._freezePointerLeaveSubs].forEach(d=>{d==null||d.unsubscribe()}),this._freezeDownSubs=null,this._freezePointerEnterSubs=null,this._freezePointerLeaveSubs=null,(l=this._scenePointerMoveSub)==null||l.unsubscribe(),(c=this._scenePointerUpSub)==null||c.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null)}_getPositionByIndex(e,t){var d;if(this._getSheetObject()==null)return;const o=(d=this._sheetSkeletonManagerService.getCurrent())==null?void 0:d.skeleton,s=o==null?void 0:o.getNoMergeCellPositionByIndex(e,t);if(o==null)return;if(s!=null&&(!isNaN(s.endX)||!isNaN(s.endY)))return s;const{rowHeaderWidthAndMarginLeft:l,columnHeaderHeightAndMarginTop:c}=o;return{startX:l,endX:l,startY:c,endY:c}}_getFreeze(){var t;const e=(t=this._sheetSkeletonManagerService.getCurrent())==null?void 0:t.skeleton.getWorksheetConfig();if(e!=null)return e.freeze}_getSheetObject(){return Xe(this._context.unit,this._context)}_refreshFreeze(e,t,i,o,s){var c;const l={startRow:e,startColumn:t,ySplit:i,xSplit:o};this._clearFreeze(),this._createFreeze(0,l),this._createFreeze(1,l),this._updateViewport(e,t,i,o,s),(c=this._getSheetObject())==null||c.spreadsheet.makeForceDirty()}};exports.HeaderFreezeRenderController=Em([Ot(1,a.Inject(exports.SheetSkeletonManagerService)),Ot(2,a.ICommandService),Ot(3,a.Inject(m.SheetsSelectionsService)),Ot(4,a.Inject(exports.SheetScrollManagerService)),Ot(5,a.Inject(a.ThemeService)),Ot(6,a.Inject(m.SheetInterceptorService)),Ot(7,a.Inject(a.Injector))],exports.HeaderFreezeRenderController);function Om(n){const r=n.get(m.SheetsSelectionsService),e=n.get(m.RangeProtectionRuleModel),t=n.get(a.IUniverInstanceService),i=n.get(m.MergeCellController),o=t.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET);return O.combineLatest([r.selectionMoveEnd$,o.pipe(O.map(s=>{var l;return(l=s==null?void 0:s.getUnitId())!=null?l:""})),o.pipe(O.switchMap(s=>{var l;return(l=s==null?void 0:s.activeSheet$)!=null?l:O.of(null)}))]).pipe(O.map(([s,l,c])=>{if(!c||!s||s.length===0)return!1;const d=c.getSheetId(),u=s.map(S=>S.range);if(i.interceptor.fetchThroughInterceptors(m.MERGE_CELL_INTERCEPTOR_CHECK)(!1,u))return!0;const g=e.getSubunitRuleList(l,d).map(S=>S.ranges).flat();if(s.length<2){const S=s[0].range;return g.some(p=>a.Rectangle.intersects(p,S)&&!a.Rectangle.contains(p,S))}for(let S=0;S<s.length;S++)for(let f=S+1;f<s.length;f++)if(a.Rectangle.intersects(s[S].range,s[f].range))return!0;return!1}))}function _l(n,r){return!!ei(n,r,a.RANGE_TYPE.ROW)}function bl(n,r){return!!ei(n,r,a.RANGE_TYPE.COLUMN)}function ei(n,r,e){return n.find(i=>{const o=i.range,{startRow:s,endRow:l,startColumn:c,endColumn:d,rangeType:u}=o;return u===a.RANGE_TYPE.ALL||u===a.RANGE_TYPE.NORMAL?!1:u===e&&(e===a.RANGE_TYPE.COLUMN&&c<=r&&r<=d||e===a.RANGE_TYPE.ROW&&s<=r&&r<=l)})}var xm=Object.defineProperty,Am=Object.getOwnPropertyDescriptor,Nm=(n,r,e,t)=>{for(var i=t>1?void 0:t?Am(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&xm(r,e,i),i},to=(n,r)=>(e,t)=>r(e,t,n);const Dm="__SpreadsheetHeaderMoveControllerBackground__",km="__SpreadsheetHeaderMoveControllerShapeLine__",Vm="rgba(0, 0, 0, 0.1)",Hm="rgb(119, 119, 119)",Wm=4,no=a.createInterceptorKey("headerMovePermissionCheck");exports.HeaderMoveRenderController=class extends a.Disposable{constructor(e,t,i,o){super();T(this,"_startOffsetX",Number.NEGATIVE_INFINITY);T(this,"_startOffsetY",Number.NEGATIVE_INFINITY);T(this,"_moveHelperBackgroundShape");T(this,"_moveHelperLineShape");T(this,"_headerPointerDownSubs");T(this,"_headerPointerMoveSubs");T(this,"_headerPointerLeaveSubs");T(this,"_dragHeaderMoveSub");T(this,"_scenePointerUpSub");T(this,"_scrollTimer");T(this,"_changeFromColumn",-1);T(this,"_changeFromRow",-1);T(this,"_changeToColumn",-1);T(this,"_changeToRow",-1);T(this,"interceptor",new a.InterceptorManager({HEADER_MOVE_PERMISSION_CHECK:no}));T(this,"_workbookSelections");this._context=e,this._sheetSkeletonManagerService=i,this._commandService=o,this._workbookSelections=t.getWorkbookSelections(this._context.unitId),this._init()}dispose(){var e,t,i,o,s,l,c,d;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose(),(i=this._headerPointerMoveSubs)==null||i.unsubscribe(),(o=this._headerPointerLeaveSubs)==null||o.unsubscribe(),(s=this._headerPointerDownSubs)==null||s.unsubscribe(),this._headerPointerMoveSubs=null,this._headerPointerLeaveSubs=null,this._headerPointerDownSubs=null,(l=this._dragHeaderMoveSub)==null||l.unsubscribe(),(c=this._scenePointerUpSub)==null||c.unsubscribe(),this._dragHeaderMoveSub=null,this._scenePointerUpSub=null,(d=this._scrollTimer)==null||d.dispose()}_init(){this._initialRowOrColumn(a.RANGE_TYPE.ROW),this._initialRowOrColumn(a.RANGE_TYPE.COLUMN)}_initialRowOrColumn(e=a.RANGE_TYPE.ROW){const t=this._context.components.get(me.COLUMN),i=this._context.components.get(me.ROW),o=this._context.scene,s=e===a.RANGE_TYPE.ROW?i:t,l=u=>{var _,b;const h=(_=this._sheetSkeletonManagerService.getCurrent())==null?void 0:_.skeleton;if(h==null)return;const g=(b=this._workbookSelections.getCurrentLastSelection())==null?void 0:b.range;if(!g||!this.interceptor.fetchThroughInterceptors(no)(!1,g))return;const f=this._workbookSelections.getCurrentSelections(),{row:p,column:v}=Ke(u.offsetX,u.offsetY,o,h);if(!ei(f,e===a.RANGE_TYPE.ROW?p:v,e)){o.resetCursor();return}o.setCursor(y.CURSOR_TYPE.GRAB)},c=()=>{var u,h;(u=this._moveHelperBackgroundShape)==null||u.hide(),(h=this._moveHelperLineShape)==null||h.hide(),o.resetCursor()},d=(u,h)=>{var B,V;if(h.isStopPropagation)return;const g=(B=this._sheetSkeletonManagerService.getCurrent())==null?void 0:B.skeleton;if(g==null)return;const S=(V=this._workbookSelections.getCurrentLastSelection())==null?void 0:V.range;if(!S||!this.interceptor.fetchThroughInterceptors(no)(!1,S))return;const{offsetX:p,offsetY:v}=u,C=o.getCoordRelativeToViewport(y.Vector2.FromArray([p,v])),{x:_,y:b}=C;this._startOffsetX=_,this._startOffsetY=b;const{row:E,column:M}=Ke(u.offsetX,u.offsetY,o,g);let w;e===a.RANGE_TYPE.ROW?(this._changeFromRow=E,w=y.ScrollTimerType.Y):(this._changeFromColumn=M,w=y.ScrollTimerType.X);const P=this._workbookSelections.getCurrentSelections(),x=ei(P,e===a.RANGE_TYPE.ROW?E:M,e);if(!x)return;const A=o.getScrollXYInfoByViewport(y.Vector2.FromArray([this._startOffsetX,this._startOffsetY]));this._newBackgroundAndLine(),o.setCursor(y.CURSOR_TYPE.GRABBING),o.disableObjectsEvent();let N=!1,D;const k=()=>{if(N)return;D=y.ScrollTimer.create(o,w),this._scrollTimer=D;const U=o.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);D.startScroll(_,b,U),N=!0};this._dragHeaderMoveSub=o.onPointerMove$.subscribeEvent(U=>{k();const{offsetX:F,offsetY:L}=U,{x:W,y:j}=o.getCoordRelativeToViewport(y.Vector2.FromArray([F,L]));this._rowColumnMoving(W,j,x,A,e),D.scrolling(W,j,()=>{this._rowColumnMoving(W,j,x,A,e)})}),this._scenePointerUpSub=o.onPointerUp$.subscribeEvent(()=>{var F,L,W;this._disposeBackgroundAndLine(),o.resetCursor(),o.enableObjectsEvent(),this._clearObserverEvent(),(F=this._scrollTimer)==null||F.dispose();const U=this._workbookSelections.getCurrentSelections();if(e===a.RANGE_TYPE.ROW){if(this._changeFromRow!==this._changeToRow&&this._changeToRow!==-1){const z=(L=((U==null?void 0:U.filter(Z=>Z.range.rangeType===a.RANGE_TYPE.ROW&&Z.range.startRow<=this._changeFromRow&&this._changeFromRow<=Z.range.endRow))||[])[0])==null?void 0:L.range;z&&this._commandService.executeCommand(m.MoveRowsCommand.id,{fromRange:z,toRange:{...z,startRow:this._changeToRow,endRow:this._changeToRow+z.endRow-z.startRow}})}this._changeToRow=this._changeFromRow=-1}else{if(this._changeFromColumn!==this._changeToColumn&&this._changeToColumn!==-1){const z=(W=((U==null?void 0:U.filter(Z=>Z.range.rangeType===a.RANGE_TYPE.COLUMN&&Z.range.startColumn<=this._changeFromColumn&&this._changeFromColumn<=Z.range.endColumn))||[])[0])==null?void 0:W.range;z&&this._commandService.executeCommand(m.MoveColsCommand.id,{fromRange:z,toRange:{...z,startColumn:this._changeToColumn,endColumn:this._changeToColumn+z.endColumn-z.startColumn}})}this._changeToColumn=this._changeFromColumn=-1}})};this._headerPointerMoveSubs=new O.Subscription,this._headerPointerMoveSubs.add(s.onPointerMove$.subscribeEvent(l)),this._headerPointerLeaveSubs=new O.Subscription,this._headerPointerLeaveSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(c)),this._headerPointerDownSubs=new O.Subscription,this._headerPointerDownSubs.add(s==null?void 0:s.onPointerDown$.subscribeEvent(d))}_rowColumnMoving(e,t,i,o,s){var j,z,Z,te,q,ie,oe;const l=this._context.scene,c=(j=this._sheetSkeletonManagerService.getCurrent())==null?void 0:j.skeleton;if(c==null)return;const{rowHeaderWidth:d,columnHeaderHeight:u,rowTotalHeight:h,columnTotalWidth:g}=c,S=l.getViewportScrollXY(l.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN)),{scaleX:f,scaleY:p}=l.getAncestorScale(),v=c.getCellIndexByOffset(e,t,f,p,S),{row:C,column:_}=v,b=c.getNoMergeCellPositionByIndex(C,_),{startX:E,startY:M,endX:w,endY:P}=b,x=this._sheetSkeletonManagerService.attachRangeWithCoord(i.range);if(x==null)return;const A=Math.max(f,f),{startX:N,endX:D,startY:k,endY:B,startRow:V,startColumn:U,endRow:F,endColumn:L}=x;s===a.RANGE_TYPE.ROW?(z=this._moveHelperBackgroundShape)==null||z.transformByState({height:B-k,width:g+d,left:0,top:k+(t-this._startOffsetY)/A+S.y-o.y}):(Z=this._moveHelperBackgroundShape)==null||Z.transformByState({height:h+u,width:D-N,left:N+(e-this._startOffsetX)/A+S.x-o.x,top:0}),(te=this._moveHelperBackgroundShape)==null||te.show();const W=Wm/A;if(s===a.RANGE_TYPE.ROW){let X=0;if(C<=V)X=M-W/2,this._changeToRow=C;else if(C>F)X=P-W/2,this._changeToRow=C+1;else return;(q=this._moveHelperLineShape)==null||q.transformByState({height:W,width:g,left:d,top:X})}else{let X=0;if(_<=U)X=E-W/2,this._changeToColumn=_;else if(_>L)X=w-W/2,this._changeToColumn=_+1;else return;(ie=this._moveHelperLineShape)==null||ie.transformByState({height:h,width:W,left:X,top:u})}(oe=this._moveHelperLineShape)==null||oe.show()}_clearObserverEvent(){var e,t;(e=this._dragHeaderMoveSub)==null||e.unsubscribe(),(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._dragHeaderMoveSub=null,this._scenePointerUpSub=null}_newBackgroundAndLine(){const e=this._context.scene;this._moveHelperBackgroundShape=new y.Rect(Dm,{fill:Vm,evented:!1,zIndex:100}),this._moveHelperLineShape=new y.Rect(km,{fill:Hm,evented:!1,zIndex:100}),e.addObjects([this._moveHelperBackgroundShape,this._moveHelperLineShape],bt)}_disposeBackgroundAndLine(){var e,t;(e=this._moveHelperBackgroundShape)==null||e.dispose(),(t=this._moveHelperLineShape)==null||t.dispose()}};exports.HeaderMoveRenderController=Nm([to(1,a.Inject(m.SheetsSelectionsService)),to(2,a.Inject(exports.SheetSkeletonManagerService)),to(3,a.ICommandService)],exports.HeaderMoveRenderController);var Lo=(n=>(n[n.VERTICAL=0]="VERTICAL",n[n.HORIZONTAL=1]="HORIZONTAL",n))(Lo||{});const Um="rgba(120, 120, 120, 0.01)",io="rgb(68, 71, 70)",Xn=12,Lm=44,Bo=4;class Sa extends y.Shape{constructor(e,t){super(e,t);T(this,"_size",Xn);T(this,"_color",io);T(this,"_mode",0);this.setShapeProps(t)}get size(){return this._size}get mode(){return this._mode}get color(){return this._color}_draw(e){const t=this.getScene();if(!t)return;const{scaleX:i,scaleY:o}=t.getAncestorScale(),s=Math.max(i,o),l=Xn/s,c=Bo/s;let{width:d,height:u}=this,h=0,g=0;this.mode===0?(d=c,h=l-c):(u=c,g=l-c),y.Rect.drawWith(e,{width:this.width,height:this.height,left:0,top:0,fill:Um}),y.Rect.drawWith(e,{width:d,height:u,fill:io,radius:c}),e.save(),e.transform(1,0,0,1,h,g),y.Rect.drawWith(e,{width:d,height:u,fill:io,radius:c}),e.restore()}setShapeProps(e){return e!=null&&e.size&&(this._size=e.size),e!=null&&e.mode&&(this._mode=e.mode),e!=null&&e.color&&(this._color=e.color),this.mode===0?this.transformByState({width:Xn,height:this.size}):this.transformByState({width:this.size,height:Xn}),this}}var Bm=Object.defineProperty,Fm=Object.getOwnPropertyDescriptor,jm=(n,r,e,t)=>{for(var i=t>1?void 0:t?Fm(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&Bm(r,e,i),i},ro=(n,r)=>(e,t)=>r(e,t,n);const zm="__SpreadsheetHeaderResizeControllerShapeRow__",Xm="__SpreadsheetHeaderResizeControllerShapeColumn__",fa="__SpreadsheetHeaderResizeControllerShapeHelper__",pa="rgb(199, 199, 199)",Ym=2,oo=a.createInterceptorKey("headerResizePermissionCheck");exports.HeaderResizeRenderController=class extends a.Disposable{constructor(e,t,i,o){super();T(this,"_currentRow",0);T(this,"_currentColumn",0);T(this,"_rowResizeRect");T(this,"_columnResizeRect");T(this,"_headerPointerSubs");T(this,"_scenePointerMoveSub");T(this,"_scenePointerUpSub");T(this,"_resizeHelperShape");T(this,"_startOffsetX",Number.POSITIVE_INFINITY);T(this,"_startOffsetY",Number.POSITIVE_INFINITY);T(this,"interceptor",new a.InterceptorManager({HEADER_RESIZE_PERMISSION_CHECK:oo}));this._context=e,this._sheetSkeletonManagerService=t,this._selectionManagerService=i,this._commandService=o,this._init()}dispose(){var e,t,i;(e=this._rowResizeRect)==null||e.dispose(),this._rowResizeRect=null,(t=this._columnResizeRect)==null||t.dispose(),this._columnResizeRect=null,(i=this._headerPointerSubs)==null||i.unsubscribe(),this._headerPointerSubs=null}_init(){const e=this._context.scene;this._rowResizeRect=new Sa(zm,{visible:!1,mode:Lo.HORIZONTAL,zIndex:100}),this._columnResizeRect=new Sa(Xm,{visible:!1,mode:Lo.VERTICAL,zIndex:100}),e.addObjects([this._rowResizeRect,this._columnResizeRect],bt),this._initialHover(0),this._initialHover(1),this._initialHoverResize(0),this._initialHoverResize(1)}_initialHover(e=0){const t=this._context.components.get(me.COLUMN),i=this._context.components.get(me.ROW),o=this._context.scene,s=e===0?i:t,l=(d,u)=>{var h,g;(h=this._rowResizeRect)==null||h.hide(),(g=this._columnResizeRect)==null||g.hide()},c=(d,u)=>{var A;const h=(A=this._sheetSkeletonManagerService.getCurrent())==null?void 0:A.skeleton;if(h==null||this._rowResizeRect==null||this._columnResizeRect==null)return;const{rowHeaderWidth:g,columnHeaderHeight:S}=h,{startX:f,startY:p,endX:v,endY:C,row:_,column:b}=Ke(d.offsetX,d.offsetY,o,h),E=Zn(d.offsetX,d.offsetY,o),{scaleX:M,scaleY:w}=o.getAncestorScale(),P=Math.max(M,w),x=Xn/P;if(e===0){let N=p-x/2;if(E.y<=p+x/2&&E.y>=p)this._currentRow=_-1;else if(E.y>=C-x/2&&E.y<=C)this._currentRow=_,N=C-x/2;else{this._rowResizeRect.hide();return}if(this._currentRow===-1)return;if(!this.interceptor.fetchThroughInterceptors(oo)(null,{row:this._currentRow}))return!1;const k=Math.min(Lm,g/3);this._rowResizeRect.transformByState({left:g/2-k/2,top:N}),this._rowResizeRect.setShapeProps({size:k}),this._rowResizeRect.show()}else{let N=f-x/2;if(E.x<=f+x/2&&E.x>=f)this._currentColumn=b-1;else if(E.x>=v-x/2&&E.x<=v)this._currentColumn=b,N=v-x/2;else{this._columnResizeRect.hide();return}if(this._currentColumn===-1)return;if(!this.interceptor.fetchThroughInterceptors(oo)(null,{col:this._currentColumn}))return!1;const k=S*.7;this._columnResizeRect.transformByState({left:N,top:S/2-k/2}),this._columnResizeRect.setShapeProps({size:k}),this._columnResizeRect.show()}};this._headerPointerSubs=new O.Subscription,this._headerPointerSubs.add(s==null?void 0:s.onPointerMove$.subscribeEvent(c)),this._headerPointerSubs.add(s==null?void 0:s.onPointerLeave$.subscribeEvent(l))}_initialHoverResize(e=0){const t=this._context.scene,i=e===0?this._rowResizeRect:this._columnResizeRect;i!=null&&(this.disposeWithMe(i.onPointerEnter$.subscribeEvent(()=>{i!=null&&(i.show(),t.setCursor(e===0?y.CURSOR_TYPE.ROW_RESIZE:y.CURSOR_TYPE.COLUMN_RESIZE))})),this.disposeWithMe(i.onPointerLeave$.subscribeEvent(()=>{i!=null&&(i.hide(),t.resetCursor())})),this.disposeWithMe(i.onPointerDown$.subscribeEvent(o=>{var L,W,j,z,Z,te,q;const s=(L=this._sheetSkeletonManagerService.getCurrent())==null?void 0:L.skeleton;if(s==null)return;const l=this._context.scene,c=l.getEngine(),d=(c==null?void 0:c.height)||0,u=(c==null?void 0:c.width)||0,h=l.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=(((j=(W=h==null?void 0:h.getScrollBar())==null?void 0:W.horizonScrollTrack)==null?void 0:j.height)||0)+10,S=(((Z=(z=h==null?void 0:h.getScrollBar())==null?void 0:z.verticalScrollTrack)==null?void 0:Z.width)||0)+10,f=Zn(o.offsetX,o.offsetY,l),{scaleX:p,scaleY:v}=l.getAncestorScale();this._startOffsetX=f.x,this._startOffsetY=f.y;const C=s.getOffsetByPositionX(this._currentColumn),_=s.getOffsetByPositionY(this._currentRow),b=s.getNoMergeCellPositionByIndex(this._currentRow,this._currentColumn);let E=!1,M=0,w=0;const{columnTotalWidth:P,rowHeaderWidth:x,rowTotalHeight:A,columnHeaderHeight:N}=s,D=u>P+x?u:P+x,k=d>A+N?d:A+N,B=Math.max(p,v),V=Bo/B;e===0?this._resizeHelperShape=new y.Rect(fa,{width:D,height:V,fill:pa,left:0,top:_-V/2}):this._resizeHelperShape=new y.Rect(fa,{width:V,height:k,fill:pa,left:C-V/2,top:0});const U=((te=this._columnResizeRect)==null?void 0:te.left)||0,F=((q=this._rowResizeRect)==null?void 0:q.top)||0;l.addObject(this._resizeHelperShape,bt),l.disableObjectsEvent(),this._scenePointerMoveSub=l.onPointerMove$.subscribeEvent(ie=>{var le,Re,Ee,Vn,ks,Vs;const oe=l.getCoordRelativeToViewport(y.Vector2.FromArray([this._startOffsetX,this._startOffsetY])),X=l.getScrollXYInfoByViewport(oe,h),Y=Zn(ie.offsetX,ie.offsetY,l),{x:Q,y:ne}=Y,{scaleX:ue,scaleY:pe}=l.getAncestorScale(),de=Math.max(ue,pe),re=Bo/de;M=Q-this._startOffsetX-re/2,w=ne-this._startOffsetY-re/2,Math.abs(e===0?w:M)>=Ym&&(E=!0),e===0?(w>d-g+X.y-b.startY&&(w=d-g+X.y-b.startY),w<-(b.endY-b.startY)+2&&(w=-(b.endY-b.startY)+2),E&&((le=this._resizeHelperShape)==null||le.transformByState({top:_+w}),(Re=this._rowResizeRect)==null||Re.transformByState({top:F+w+re/2}),(Ee=this._rowResizeRect)==null||Ee.show(),l.setCursor(y.CURSOR_TYPE.ROW_RESIZE))):(M>u-S+X.x-b.startX&&(M=u-S+X.x-b.startX),M<-(b.endX-b.startX)+2&&(M=-(b.endX-b.startX)+2),E&&((Vn=this._resizeHelperShape)==null||Vn.transformByState({left:C+M}),(ks=this._columnResizeRect)==null||ks.transformByState({left:U+M+re/2}),(Vs=this._columnResizeRect)==null||Vs.show(),l.setCursor(y.CURSOR_TYPE.COLUMN_RESIZE)))}),this._scenePointerUpSub=l.onPointerUp$.subscribeEvent(ie=>{var X,Y,Q;const oe=this._context.scene;this._clearObserverEvent(),(X=this._resizeHelperShape)==null||X.dispose(),this._resizeHelperShape=null,oe.enableObjectsEvent(),E&&(oe.resetCursor(),(Y=this._rowResizeRect)==null||Y.hide(),(Q=this._columnResizeRect)==null||Q.hide(),e===0?this._commandService.executeCommand(m.DeltaRowHeightCommand.id,{deltaY:w,anchorRow:this._currentRow}):this._commandService.executeCommand(m.DeltaColumnWidthCommand.id,{deltaX:M,anchorCol:this._currentColumn}))})})),this.disposeWithMe(i.onDblclick$.subscribeEvent(()=>{var h,g,S;this._context.scene.resetCursor();const s=(h=this._sheetSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(!s)return;const l=0,c=0,d=s.worksheet.getRowCount()-1||0,u=s.worksheet.getColumnCount()-1||0;switch(e){case 1:{const f=this._selectionManagerService.getCurrentSelections(),p=[];for(let v=0;v<f.length;v++){const C=f[v];C.range.rangeType===a.RANGE_TYPE.COLUMN&&this._currentColumn<=C.range.endColumn&&this._currentColumn>=C.range.startColumn&&p.push({startColumn:C.range.startColumn,endColumn:C.range.endColumn,startRow:l,endRow:d})}p.length===0&&p.push({startColumn:this._currentColumn,endColumn:this._currentColumn,startRow:l,endRow:d}),this._commandService.executeCommand(yr.id,{ranges:p}),(g=this._columnResizeRect)==null||g.hide();break}case 0:this._commandService.executeCommand(m.SetWorksheetRowIsAutoHeightCommand.id,{ranges:[{startRow:this._currentRow,endRow:this._currentRow,startColumn:c,endColumn:u}]}),(S=this._rowResizeRect)==null||S.hide();break}})))}_clearObserverEvent(){var e,t;(e=this._scenePointerMoveSub)==null||e.unsubscribe(),(t=this._scenePointerUpSub)==null||t.unsubscribe(),this._scenePointerMoveSub=null,this._scenePointerUpSub=null}};exports.HeaderResizeRenderController=jm([ro(1,a.Inject(exports.SheetSkeletonManagerService)),ro(2,a.Inject(m.SheetsSelectionsService)),ro(3,a.ICommandService)],exports.HeaderResizeRenderController);var Gm=Object.defineProperty,Zm=Object.getOwnPropertyDescriptor,Km=(n,r,e,t)=>{for(var i=t>1?void 0:t?Zm(r,e):r,o=n.length-1,s;o>=0;o--)(s=n[o])&&(i=(t?s(r,e,i):s(i))||i);return t&&i&&Gm(r,e,i),i},ki=(n,r)=>(e,t)=>r(e,t,n);const qm=60;exports.SheetRenderController=class extends a.RxDisposable{constructor(e,t,i,o,s){super();T(this,"_renderFrameTimeMetric",null);T(this,"_renderFrameTags",{});T(this,"_afterRenderMetric$",new O.Subject);this._context=e,this._sheetSkeletonManagerService=t,this._sheetRenderService=i,this._commandService=o,this._telemetryService=s,this._addNewRender(),this._initRenderMetricSubscriber()}_addNewRender(){const{scene:e,engine:t,unit:i}=this._context;this._addComponent(i),this._initRerenderScheduler(),this._initCommandListener();const o=this._context.unit.getActiveSheet();if(!o)throw new Error("No active sheet found");const s=o.getSheetId();this._sheetSkeletonManagerService.setCurrent({sheetId:s}),t.runRenderLoop(()=>e.render())}_initRenderMetricSubscriber(){if(!this._telemetryService)return;const{engine:e}=this._context;e.beginFrame$.subscribe(()=>{this._renderFrameTimeMetric=null,this._renderFrameTags={}}),e.endFrame$.subscribe(()=>{this._renderFrameTimeMetric&&Object.keys(this._renderFrameTimeMetric).filter(o=>o.startsWith(y.SHEET_EXTENSION_PREFIX)).length>0&&this._afterRenderMetric$.next({frameTimeMetric:this._renderFrameTimeMetric,tags:this._renderFrameTags})}),e.renderFrameTimeMetric$.subscribe(([i,o])=>{this._renderFrameTimeMetric||(this._renderFrameTimeMetric={}),this._renderFrameTimeMetric[i]||(this._renderFrameTimeMetric[i]=[]),this._renderFrameTimeMetric[i].push(Math.round(o*100)/100)}),e.renderFrameTags$.subscribe(([i,o])=>{this._renderFrameTags[i]=o});const t=[];this._afterRenderMetric$.pipe(O.withLatestFrom(e.endFrame$)).subscribe(([i,o])=>{t.push({FPS:o.FPS,elapsedTime:o.elapsedTime,frameTime:Math.round(o.frameTime*100)/100,...i.frameTimeMetric,...i.tags}),t.length>qm&&(this._renderMetricCapture(t),t.length=0)})}_renderMetricCapture(e){const t=e;if(t.length===0)return;const i=g=>{let S=0;const p=Object.entries(g).filter(([C,_])=>Array.isArray(_)).map(([C])=>C).reduce((C,_)=>{const b=g[_].reduce((E,M)=>E+M,0);return C[_]=b,C},{});return Object.keys(g).filter(C=>C.startsWith(y.SHEET_EXTENSION_PREFIX)).forEach(C=>{S+=p[C]}),{...p,extensionTotal:S}},o=e.map(g=>({...g,...i(g)})),l=(g=>Object.entries(g[0]).filter(([p,v])=>!["elapsedTime"].includes(p)).filter(([p,v])=>typeof v=="number").map(([p])=>p).reduce((p,v)=>{const C=g.map(M=>M[v]),_=Math.max(...C),b=Math.min(...C),E=C.reduce((M,w)=>M+w,0)/C.length;return p[v]={max:Math.round(_*100)/100,min:Math.round(b*100)/100,avg:Math.round(E*100)/100},p},{}))(o),c=t[t.length-1].elapsedTime,d=this._context.unit.getActiveSheet().getSheetId(),u=this._context.unit.getUnitId(),h={sheetId:d,unitId:u,elapsedTimeToStart:c,...l};this._telemetryService.capture("sheet_render_cost",h)}_addComponent(e){const{scene:t,components:i}=this._context,o=e.getActiveSheet(),s=new y.Spreadsheet(me.MAIN);this._addViewport(o);const l=new y.SpreadsheetRowHeader(me.ROW),c=new y.SpreadsheetColumnHeader(me.COLUMN),d=new y.Rect(me.LEFT_TOP,{zIndex:2,left:-1,top:-1,fill:"rgb(248, 249, 250)",stroke:"rgb(217, 217, 217)",strokeWidth:1});this._context.mainComponent=s,i.set(me.MAIN,s),i.set(me.ROW,l),i.set(me.COLUMN,c),i.set(me.LEFT_TOP,d),t.addObjects([s],Fs),t.addObjects([l,c,d],bt),t.enableLayerCache(Fs,bt)}_initViewports(e,t,i){const l=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN,e,{left:t.width,top:i.height,bottom:0,right:0,isWheelPreventDefaultX:!0,allowCache:!0,bufferEdgeX:100,bufferEdgeY:100}),c=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:0}),d=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:0,bufferEdgeY:100}),u=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP,e,{isWheelPreventDefaultX:!0,active:!1,allowCache:!0,bufferEdgeX:100,bufferEdgeY:0}),h=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_ROW_TOP,e,{active:!1,isWheelPreventDefaultX:!0}),g=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_ROW_BOTTOM,e,{left:0,top:i.height,bottom:0,width:t.width,isWheelPreventDefaultX:!0}),S=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_LEFT,e,{active:!1,isWheelPreventDefaultX:!0}),f=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_COLUMN_RIGHT,e,{left:t.width,top:0,height:i.height,right:0,isWheelPreventDefaultX:!0}),p=new y.Viewport(y.SHEET_VIEWPORT_KEY.VIEW_LEFT_TOP,e,{left:0,top:0,width:t.width,height:i.height,isWheelPreventDefaultX:!0});return{viewMain:l,viewLeftTop:p,viewMainLeftTop:c,viewMainLeft:d,viewMainTop:u,viewColumnLeft:S,viewRowTop:h,viewRowBottom:g,viewColumnRight:f}}_addViewport(e){const t=this._context.scene,{rowHeader:i,columnHeader:o}=e.getConfig(),{viewMain:s}=this._initViewports(t,i,o);return new y.ScrollBar(s),t.attachControl(),s}_initRerenderScheduler(){this.disposeWithMe(this._sheetSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(!e)return null;const{skeleton:t,sheetId:i}=e,o=this._context.unit,s=o==null?void 0:o.getSheetBySheetId(i);if(o==null||s==null)return;const{mainComponent:l,components:c}=this._context,d=l,u=c.get(me.ROW),h=c.get(me.COLUMN),g=c.get(me.LEFT_TOP),{rowHeaderWidth:S,columnHeaderHeight:f}=t;d==null||d.updateSkeleton(t),u==null||u.updateSkeleton(t),h==null||h.updateSkeleton(t),g==null||g.transformByState({width:S,height:f})}))}_initCommandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{const{unit:t}=this._context,{id:i}=e;if(m.COMMAND_LISTENER_SKELETON_CHANGE.includes(i)||this._sheetRenderService.checkMutationShouldTriggerRerender(i)){const o=e.params,{unitId:s,subUnitId:l}=o,c=t.getActiveSheet();if(!c)return;const d=this._context.unitId,u=c.getSheetId();if(s!==d||l!==u)return;this._sheetSkeletonManagerService.makeDirty({sheetId:u,commandId:i},!0),this._sheetSkeletonManagerService.setCurrent({sheetId:u,commandId:i})}else m.COMMAND_LISTENER_VALUE_CHANGE.includes(i)&&this._sheetSkeletonManagerService.reCalculate();e.type===a.CommandType.MUTATION&&this._markUnitDirty(e)}))}_markUnitDirty(e){const{mainComponent:t,scene:i}=this._context;if(e.id===G.SetFormulaCalculationNotificationMutation.id&&e.params.stageInfo!=null||(t&&t.makeDirty(),i.makeDirty(),!e.params))return;const o=e.params,s=this._spreadsheetViewports(i);if(e.id===m.SetRangeValuesMutation.id&&o.cellValue){const l=this._cellValueToRange(o.cellValue),c=this._rangeToBounds([l]);this._markViewportDirty(s,c),t.setDirtyArea(c)}if(e.id===m.MoveRangeMutation.id&&o.from&&o.to){const l=o.fromRange||this._cellValueToRange(o.from.value),c=o.toRange||this._cellValueToRange(o.to.value),d=this._rangeToBounds([l,c]);this._markViewportDirty(s,d),t.setDirtyArea(d)}}_cellValueToRange(e){let t=0,i=0,o=0,s=0;for(const[h,g]of Object.entries(e)){for(const S in g)t>Number(S)&&(t=Number(S)),i<Number(S)&&(i=Number(S));o>Number(h)&&(o=Number(h)),s<Number(h)&&(s=Number(h))}return{startRow:o,endRow:s,startColumn:t,endColumn:i}}_rangeToBounds(e){const t=this._sheetSkeletonManagerService.getCurrent().skeleton,{rowHeightAccumulation:i,columnWidthAccumulation:o,rowHeaderWidth:s,columnHeaderHeight:l}=t,c=[];for(const d of e){const{startRow:u,endRow:h,startColumn:g,endColumn:S}=d,f=u===0?0:i[u-1]+l,p=i[h]+l,v=g===0?0:o[g-1]+s,C=o[S]+s;c.push({top:f,left:v,bottom:p,right:C,width:C-v,height:p-f})}return c}_markViewportDirty(e,t){const i=e.filter(o=>o.isActive&&o.cacheBound);for(const o of i)for(const s of t)a.Rectangle.hasIntersectionBetweenTwoRect(o.cacheBound,s)&&o.markDirty(!0)}_spreadsheetViewports(e){return e.getViewports().filter(t=>["viewMain","viewMainLeftTop","viewMainTop","viewMainLeft"].includes(t.viewportKey))}};exports.SheetRenderController=Km([ki(1,a.Inject(exports.SheetSkeletonManagerService)),ki(2,a.Inject(exports.SheetsRenderService)),ki(3,a.ICommandService),ki(4,a.Optional(ud.ITelemetryService))],exports.SheetRenderController);var He=function(){return He=Object.assign||function(n){for(var r,e=1,t=arguments.length;e<t;e++){r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(n[i]=r[i])}return n},He.apply(this,arguments)},Qm=function(n,r){var e={};for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&r.indexOf(t)<0&&(e[t]=n[t]);if(n!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,t=Object.getOwnPropertySymbols(n);i<t.length;i++)r.indexOf(t[i])<0&&Object.prototype.propertyIsEnumerable.call(n,t[i])&&(e[t[i]]=n[t[i]]);return e},be=H.forwardRef(function(n,r){var e=n.icon,t=n.id,i=n.className,o=n.extend,s=Qm(n,["icon","id","className","extend"]),l="univerjs-icon univerjs-icon-".concat(t," ").concat(i||"").trim(),c=H.useRef("_".concat(eg()));return Rl(e,"".concat(t),{defIds:e.defIds,idSuffix:c.current},He({ref:r,className:l},s),o)});function Rl(n,r,e,t,i){return H.createElement(n.tag,He(He({key:r},Jm(n,e,i)),t),($m(n,e).children||[]).map(function(o,s){return Rl(o,"".concat(r,"-").concat(n.tag,"-").concat(s),e,void 0,i)}))}function Jm(n,r,e){var t=He({},n.attrs);e!=null&&e.colorChannel1&&t.fill==="colorChannel1"&&(t.fill=e.colorChannel1);var i=r.defIds;return!i||i.length===0||(n.tag==="use"&&t["xlink:href"]&&(t["xlink:href"]=t["xlink:href"]+r.idSuffix),Object.entries(t).forEach(function(o){var s=o[0],l=o[1];typeof l=="string"&&(t[s]=l.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),t}function $m(n,r){var e,t=r.defIds;return!t||t.length===0?n:n.tag==="defs"&&(!((e=n.children)===null||e===void 0)&&e.length)?He(He({},n),{children:n.children.map(function(i){return typeof i.attrs.id=="string"&&t&&t.indexOf(i.attrs.id)>-1?He(He({},i),{attrs:He(He({},i.attrs),{id:i.attrs.id+r.idSuffix})}):i})}):n}function eg(){return Math.random().toString(36).substring(2,8)}be.displayName="UniverIcon";var tg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M11.0363 12.2367V14.0367C11.0363 14.3681 11.3049 14.6367 11.6363 14.6367C11.9676 14.6367 12.2363 14.3681 12.2363 14.0367V12.2367H14.0364C14.3677 12.2367 14.6364 11.9681 14.6364 11.6367C14.6364 11.3054 14.3677 11.0367 14.0364 11.0367H12.2363V9.23672C12.2363 8.90535 11.9676 8.63672 11.6363 8.63672C11.3049 8.63672 11.0363 8.90535 11.0363 9.23672V11.0367H9.23635C8.90498 11.0367 8.63635 11.3054 8.63635 11.6367C8.63635 11.9681 8.90498 12.2367 9.23635 12.2367H11.0363Z"}},{tag:"path",attrs:{fill:"currentColor",d:"M2.56365 1.36377C1.90091 1.36377 1.36365 1.90103 1.36365 2.56377V6.16377C1.36365 6.82651 1.90091 7.36377 2.56365 7.36377H6.16365C6.82639 7.36377 7.36365 6.82651 7.36365 6.16377V2.56377C7.36365 1.90103 6.82639 1.36377 6.16365 1.36377H2.56365zM6.16365 2.56377H2.56365L2.56365 6.16377H6.16365V2.56377zM2.56365 8.63647C1.90091 8.63647 1.36365 9.17373 1.36365 9.83647V13.4365C1.36365 14.0992 1.90091 14.6365 2.56365 14.6365H6.16365C6.82639 14.6365 7.36365 14.0992 7.36365 13.4365V9.83647C7.36365 9.17373 6.82639 8.63647 6.16365 8.63647H2.56365zM6.16365 9.83647H2.56365L2.56365 13.4365H6.16365V9.83647zM9.83635 7.36377C9.17361 7.36377 8.63635 6.82651 8.63635 6.16377V2.56377C8.63635 1.90103 9.17361 1.36377 9.83635 1.36377H13.4364C14.0991 1.36377 14.6364 1.90103 14.6364 2.56377V6.16377C14.6364 6.82651 14.0991 7.36377 13.4364 7.36377H9.83635zM9.83635 6.16377V2.56377L13.4364 2.56377V6.16377H9.83635z",fillRule:"evenodd",clipRule:"evenodd"}}]},El=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"autofill",ref:r,icon:tg}))});El.displayName="Autofill";var ng={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M14.1544 3.75557C14.3887 3.98988 14.3887 4.36978 14.1544 4.6041L6.51409 12.2444C6.40157 12.3569 6.24896 12.4201 6.08983 12.4201C5.9307 12.4201 5.77808 12.3569 5.66556 12.2444L1.84541 8.42425C1.6111 8.18993 1.6111 7.81003 1.84541 7.57572C2.07973 7.34141 2.45963 7.34141 2.69394 7.57572L6.08983 10.9716L13.3059 3.75557C13.5402 3.52126 13.9201 3.52126 14.1544 3.75557Z",fillRule:"evenodd",clipRule:"evenodd"}}]},ht=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"check-mark-single",ref:r,icon:ng}))});ht.displayName="CheckMarkSingle";var ig={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M3.71274 2.86421C3.47843 2.6299 3.09853 2.6299 2.86421 2.86421C2.6299 3.09853 2.6299 3.47843 2.86421 3.71274L7.15154 8.00007L2.86421 12.2874C2.6299 12.5217 2.6299 12.9016 2.86421 13.1359C3.09853 13.3702 3.47843 13.3702 3.71274 13.1359L8.00007 8.84859L12.2874 13.1359C12.5217 13.3702 12.9016 13.3702 13.1359 13.1359C13.3702 12.9016 13.3702 12.5217 13.1359 12.2874L8.84859 8.00007L13.1359 3.71274C13.3702 3.47843 13.3702 3.09853 13.1359 2.86421C12.9016 2.6299 12.5217 2.6299 12.2874 2.86421L8.00007 7.15154L3.71274 2.86421Z"}}]},Tl=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"close-single",ref:r,icon:ig}))});Tl.displayName="CloseSingle";var rg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"g",attrs:{fill:"currentColor",clipPath:"url(#convert-single_clip0_911_593)"},children:[{tag:"path",attrs:{d:"M2.44766.848145C1.564.848145.847656 1.56449.847656 2.44814V6.44814C.847656 7.3318 1.564 8.04814 2.44766 8.04814H6.44766C7.33131 8.04814 8.04766 7.3318 8.04766 6.44814V2.44814C8.04766 1.56449 7.33131.848145 6.44766.848145H2.44766zM2.04766 6.44814V5.04824H3.84775V6.84814H2.44766C2.22674 6.84814 2.04766 6.66906 2.04766 6.44814zM2.04766 3.84824H3.84775V2.04814H2.44766C2.22674 2.04814 2.04766 2.22723 2.04766 2.44814V3.84824zM5.04775 6.84814V5.04824H6.84766V6.44814C6.84766 6.66906 6.66857 6.84814 6.44766 6.84814H5.04775zM5.04775 3.84824H6.84766V2.44814C6.84766 2.22723 6.66857 2.04814 6.44766 2.04814H5.04775V3.84824zM9.55215 7.95166C8.66849 7.95166 7.95215 8.668 7.95215 9.55166V13.5517C7.95215 14.4353 8.66849 15.1517 9.55215 15.1517L11.5522 15.1517 13.5521 15.1517C14.4358 15.1517 15.1521 14.4353 15.1521 13.5517L15.1521 11.5518 15.1521 9.55166C15.1521 8.668 14.4358 7.95166 13.5521 7.95166H9.55215zM13.9521 10.9518V9.55166C13.9521 9.33075 13.7731 9.15166 13.5521 9.15166H12.1522V10.9518H13.9521zM10.9522 10.9518V9.15166H9.55215C9.33123 9.15166 9.15215 9.33075 9.15215 9.55166V10.9518H10.9522zM9.15215 12.1518H10.9522V13.9517H9.55215C9.33123 13.9517 9.15215 13.7726 9.15215 13.5517V12.1518zM12.1522 12.1518H13.9521V13.5517C13.9521 13.7726 13.7731 13.9517 13.5521 13.9517H12.1522V12.1518z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{d:"M9.62158 2.44912C9.62158 2.11775 9.89021 1.84912 10.2216 1.84912H12.7516C13.6352 1.84912 14.3516 2.56547 14.3516 3.44912V5.9791C14.3516 6.31047 14.0829 6.5791 13.7516 6.5791 13.4202 6.5791 13.1516 6.31047 13.1516 5.9791V3.44912C13.1516 3.22821 12.9725 3.04912 12.7516 3.04912H10.2216C9.89021 3.04912 9.62158 2.78049 9.62158 2.44912zM5.77871 14.1507C6.11008 14.1507 6.37871 13.8821 6.37871 13.5507 6.37871 13.2193 6.11008 12.9507 5.77871 12.9507L3.24873 12.9507C3.02782 12.9507 2.84873 12.7716 2.84873 12.5507L2.84873 10.0207C2.84873 9.68933 2.5801 9.4207 2.24873 9.4207 1.91736 9.4207 1.64873 9.68933 1.64873 10.0207L1.64873 12.5507C1.64873 13.4343 2.36507 14.1507 3.24873 14.1507H5.77871z"}}]},{tag:"defs",attrs:{},children:[{tag:"clipPath",attrs:{id:"convert-single_clip0_911_593"},children:[{tag:"path",attrs:{fill:"#fff",d:"M0 0H16V16H0z"}}]}]}],defIds:["convert-single_clip0_911_593"]},wl=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"convert-single",ref:r,icon:rg}))});wl.displayName="ConvertSingle";var og={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.3313 1.4667C5.3313 1.13533 5.59993.866699 5.9313.866699H10.069C10.4004.866699 10.669 1.13533 10.669 1.4667 10.669 1.79807 10.4004 2.0667 10.069 2.0667H5.9313C5.59993 2.0667 5.3313 1.79807 5.3313 1.4667zM1.09985 3.64443C1.09985 3.31306 1.36848 3.04443 1.69985 3.04443H14.2999C14.6312 3.04443 14.8999 3.31306 14.8999 3.64443 14.8999 3.9758 14.6312 4.24443 14.2999 4.24443H1.69985C1.36848 4.24443 1.09985 3.9758 1.09985 3.64443zM6.12398 8.30171C6.35829 8.0674 6.73819 8.0674 6.97251 8.30171L8.00007 9.32928 9.02764 8.30171C9.26195 8.0674 9.64185 8.0674 9.87617 8.30171 10.1105 8.53603 10.1105 8.91593 9.87617 9.15024L8.8486 10.1778 9.87617 11.2054C10.1105 11.4397 10.1105 11.8196 9.87617 12.0539 9.64185 12.2882 9.26195 12.2882 9.02764 12.0539L8.00007 11.0263 6.97251 12.0539C6.73819 12.2882 6.35829 12.2882 6.12398 12.0539 5.88966 11.8196 5.88966 11.4397 6.12398 11.2054L7.15154 10.1778 6.12398 9.15024C5.88966 8.91593 5.88966 8.53603 6.12398 8.30171z"}},{tag:"path",attrs:{fill:"currentColor",d:"M4.75332 5.22217C3.86966 5.22217 3.15332 5.93851 3.15332 6.82217V12.5331C3.15332 13.9691 4.31738 15.1332 5.75332 15.1332H10.2465C11.6825 15.1332 12.8465 13.9691 12.8465 12.5331V6.82217C12.8465 5.93851 12.1302 5.22217 11.2465 5.22217H4.75332ZM4.35332 6.82217C4.35332 6.60125 4.53241 6.42217 4.75332 6.42217H11.2465C11.4674 6.42217 11.6465 6.60125 11.6465 6.82217V12.5331C11.6465 13.3063 11.0197 13.9332 10.2465 13.9332H5.75332C4.98012 13.9332 4.35332 13.3063 4.35332 12.5331V6.82217Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Dr=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"delete-single",ref:r,icon:og}))});Dr.displayName="DeleteSingle";var sg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_371_77",style:{maskType:"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_371_77)"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.85869 12.9216C8.38445 13.4708 7.61555 13.4708 7.14131 12.9216L0.358114 5.06726C-0.406895 4.18144 0.134916 2.66683 1.2168 2.66683L14.7832 2.66683C15.8651 2.66683 16.4069 4.18144 15.6419 5.06726L8.85869 12.9216Z"}}]}]},Fo=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"dropdown-single",ref:r,icon:sg}))});Fo.displayName="DropdownSingle";var ag={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8ZM10.3097 5.69014C10.544 5.92445 10.544 6.30435 10.3097 6.53867L8.84843 7.9999L10.3099 9.46137C10.5442 9.69569 10.5442 10.0756 10.3099 10.3099C10.0756 10.5442 9.69569 10.5442 9.46137 10.3099L7.9999 8.84843L6.53842 10.3099C6.30411 10.5442 5.92421 10.5442 5.6899 10.3099C5.45558 10.0756 5.45558 9.69569 5.6899 9.46137L7.15137 7.9999L5.69014 6.53867C5.45583 6.30435 5.45583 5.92445 5.69014 5.69014C5.92445 5.45583 6.30435 5.45583 6.53867 5.69014L7.9999 7.15137L9.46113 5.69014C9.69544 5.45583 10.0753 5.45583 10.3097 5.69014Z",fillRule:"evenodd",clipRule:"evenodd"}}]},bs=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"error-single",ref:r,icon:ag}))});bs.displayName="ErrorSingle";var lg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M1.28096 4.6541C1.57489 4.50109 1.93721 4.61533 2.09022 4.90926C2.27315 5.26067 2.55999 5.60455 2.94829 5.92278C4.04628 6.82266 5.87505 7.44865 7.99828 7.44865C10.1215 7.44865 11.9503 6.82267 13.0482 5.92279C13.4366 5.60455 13.7234 5.26067 13.9063 4.90927C14.0594 4.61533 14.4217 4.50109 14.7156 4.65409C15.0095 4.8071 15.1238 5.16941 14.9708 5.46334C14.6995 5.98445 14.2981 6.44997 13.8089 6.8509C13.7298 6.91575 13.6481 6.97914 13.564 7.041L15.2245 8.70153C15.4588 8.93585 15.4588 9.31575 15.2245 9.55006C14.9902 9.78438 14.6103 9.78438 14.376 9.55006L12.5041 7.67822C11.8977 7.97568 11.2181 8.21208 10.4884 8.37706L11.0996 10.6581C11.1853 10.9782 10.9954 11.3072 10.6753 11.393C10.3552 11.4787 10.0262 11.2888 9.94045 10.9687L9.29949 8.57652C8.8758 8.62404 8.44081 8.64865 7.99828 8.64865C7.55276 8.64865 7.11487 8.62371 6.68846 8.57555L6.04723 10.9687C5.96147 11.2888 5.63247 11.4788 5.31239 11.393C4.99231 11.3073 4.80236 10.9783 4.88812 10.6582L5.49983 8.37516C4.7743 8.2105 4.09843 7.9752 3.49498 7.67947L1.62436 9.55009C1.39005 9.78441 1.01015 9.78441 0.775835 9.5501C0.54152 9.31578 0.541518 8.93588 0.775832 8.70157L2.43478 7.04261C2.34987 6.98024 2.26746 6.91632 2.18764 6.8509C1.69842 6.44997 1.29706 5.98445 1.0258 5.46335C0.872791 5.16942 0.987031 4.80711 1.28096 4.6541Z"}}]},yl=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"eyelash-single",ref:r,icon:lg}))});yl.displayName="EyelashSingle";var cg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 17",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M6.06409 5.53454C5.93592 5.53454 5.84083 5.41567 5.86897 5.29063L5.95442 4.9109C6.05444 4.48178 6.23806 4.11547 6.51182 3.81952 6.81082 3.49628 7.25398 3.35405 7.79738 3.35405 7.99847 3.35405 8.21359 3.37775 8.44188 3.42245 8.46089 3.42617 8.47974 3.43006 8.49846 3.4341 8.7099 3.4798 8.93698 3.38478 9.02031 3.18514L9.24767 2.6404C9.33457 2.43219 9.23178 2.19404 9.01582 2.12874 8.98358 2.11899 8.95028 2.10912 8.91591 2.09914 8.62745 2.01631 8.28392 1.97217 7.88074 1.97217 6.82015 1.97217 6.02714 2.23936 5.4746 2.7444 4.90987 3.26069 4.50889 3.99917 4.28413 4.9762L2.83703 11.1909C2.76126 11.5286 2.666 11.8917 2.54844 12.2812 2.42975 12.6734 2.2873 13.0595 2.12221 13.4373 1.95577 13.8159 1.76813 14.1762 1.55955 14.5171 1.49345 14.6251 1.42515 14.7282 1.35467 14.8263 1.26508 14.9509 1.3347 15.133 1.48655 15.1554 2.13635 15.2509 2.8179 15.0763 3.18197 14.5296 3.32661 14.3124 3.46779 14.0646 3.60509 13.7851 3.96635 13.0497 4.30522 12.0103 4.61867 10.6574L5.469 7.01534C5.49013 6.92483 5.57082 6.86081 5.66376 6.86081H7.62478C7.8097 6.86081 7.97051 6.73405 8.01371 6.55425L8.14014 6.02798C8.20057 5.77642 8.00992 5.53454 7.75121 5.53454H6.06409zM14.3211 5.72037L12.5124 7.96963 11.4089 5.77754C11.3422 5.63012 11.1954 5.5354 11.0336 5.5354H10.3129C10.0085 5.5354 9.80921 5.85428 9.9427 6.1279L11.4089 9.05502 8.79783 12.1493C8.56587 12.4158 8.75519 12.8315 9.10855 12.8315H9.68607C9.80672 12.8315 9.9605 12.7822 10.0388 12.6904L12.1108 10.2648 13.1176 12.561C13.1786 12.7231 13.333 12.8315 13.5061 12.8315H14.3C14.5831 12.8315 14.7417 12.6175 14.6426 12.3524L13.1728 9.28628C13.1728 9.28628 15.4009 6.45542 15.6013 6.17892 15.7966 5.90929 15.6023 5.5354 15.2693 5.5354H14.6661C14.5275 5.5354 14.4333 5.58887 14.3211 5.72037z"}}]},Ml=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"fx-single",ref:r,icon:cg}))});Ml.displayName="FxSingle";var dg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M6.4833 1.65005C6.4833 1.31868 6.21467 1.05005 5.8833 1.05005C5.55193 1.05005 5.2833 1.31868 5.2833 1.65005V5.28345H1.65029C1.31892 5.28345 1.05029 5.55208 1.05029 5.88345C1.05029 6.21482 1.31892 6.48345 1.65029 6.48345H5.2833V9.51684H1.65029C1.31892 9.51684 1.05029 9.78547 1.05029 10.1168C1.05029 10.4482 1.31892 10.7168 1.65029 10.7168H5.2833V14.35C5.2833 14.6814 5.55193 14.95 5.8833 14.95C6.21467 14.95 6.4833 14.6814 6.4833 14.35V10.7168H9.5167V14.35C9.5167 14.6814 9.78533 14.95 10.1167 14.95C10.4481 14.95 10.7167 14.6814 10.7167 14.35V10.7168H14.3503C14.6817 10.7168 14.9503 10.4482 14.9503 10.1168C14.9503 9.78547 14.6817 9.51685 14.3503 9.51685H10.7167V6.48345H14.3503C14.6817 6.48345 14.9503 6.21482 14.9503 5.88345C14.9503 5.55208 14.6817 5.28345 14.3503 5.28345H10.7167V1.65005C10.7167 1.31868 10.4481 1.05005 10.1167 1.05005C9.78533 1.05005 9.5167 1.31868 9.5167 1.65005V5.28345L6.4833 5.28345V1.65005ZM6.4833 6.48345V9.51684L9.5167 9.51685V6.48345L6.4833 6.48345Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.0498 3.65005C1.0498 2.21411 2.21386 1.05005 3.6498 1.05005H12.3498C13.7857 1.05005 14.9498 2.21411 14.9498 3.65005V12.3501C14.9498 13.786 13.7857 14.95 12.3498 14.95H3.6498C2.21386 14.95 1.0498 13.786 1.0498 12.35V3.65005ZM3.6498 2.25005C2.87661 2.25005 2.2498 2.87685 2.2498 3.65005V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V3.65005C13.7498 2.87685 13.123 2.25005 12.3498 2.25005H3.6498Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Pl=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"hide-gridlines",ref:r,icon:dg}))});Pl.displayName="HideGridlines";var ug={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M8.6 1.99991C8.60001 1.66854 8.33138 1.39991 8.00001 1.3999C7.66864 1.3999 7.40001 1.66853 7.4 1.9999L7.39996 7.3999H1.9999C1.66853 7.3999 1.3999 7.66853 1.3999 7.9999C1.3999 8.33127 1.66853 8.5999 1.9999 8.5999H7.39995L7.3999 13.9999C7.3999 14.3313 7.66853 14.5999 7.9999 14.5999C8.33127 14.5999 8.5999 14.3313 8.5999 13.9999L8.59995 8.5999H13.9999C14.3313 8.5999 14.5999 8.33127 14.5999 7.9999C14.5999 7.66853 14.3313 7.3999 13.9999 7.3999H8.59996L8.6 1.99991Z"}}]},Rs=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"increase-single",ref:r,icon:ug}))});Rs.displayName="IncreaseSingle";var hg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.62402 7.72905C2.58427 7.72905 2.55205 7.76127 2.55205 7.80102V13.6782C2.55205 13.7179 2.58427 13.7502 2.62402 13.7502H13.3755C13.4152 13.7502 13.4474 13.7179 13.4474 13.6782V7.80102C13.4474 7.76127 13.4152 7.72905 13.3755 7.72905H2.62402ZM1.35205 7.80102C1.35205 7.09853 1.92153 6.52905 2.62402 6.52905H13.3755C14.0779 6.52905 14.6474 7.09853 14.6474 7.80102V13.6782C14.6474 14.3807 14.0779 14.9502 13.3755 14.9502H2.62402C1.92153 14.9502 1.35205 14.3807 1.35205 13.6782V7.80102Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M8 2.25005C6.69847 2.25003 5.64336 3.30513 5.64336 4.60666V7.12895C5.64336 7.46032 5.37473 7.72895 5.04336 7.72895 4.71199 7.72895 4.44336 7.46032 4.44336 7.12895V4.60666C4.44336 2.64239 6.04451 1.05565 8.00879 1.05566M8 2.25005L8.00879 1.05566 8 2.25005zM8.00879 1.05566L8 2.25005C9.30154 2.25003 10.3567 3.30513 10.3567 4.60666V7.12895C10.3567 7.46032 10.6253 7.72895 10.9567 7.72895 11.288 7.72895 11.5567 7.46032 11.5567 7.12895V4.60666C11.5567 2.64239 9.97306 1.05565 8.00879 1.05566zM8.00039 9.4668C8.33176 9.4668 8.60039 9.73543 8.60039 10.0668V12.0827C8.60039 12.4141 8.33176 12.6827 8.00039 12.6827 7.66902 12.6827 7.40039 12.4141 7.40039 12.0827V10.0668C7.40039 9.73543 7.66902 9.4668 8.00039 9.4668z",fillRule:"evenodd",clipRule:"evenodd"}}]},Es=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"lock-single",ref:r,icon:hg}))});Es.displayName="LockSingle";var mg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Tn=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"more-down-single",ref:r,icon:mg}))});Tn.displayName="MoreDownSingle";var gg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.90913 3.57564C6.14345 3.34132 6.52335 3.34132 6.75766 3.57564L10.7577 7.57564C10.992 7.80995 10.992 8.18985 10.7577 8.42417L6.75766 12.4242C6.52335 12.6585 6.14345 12.6585 5.90913 12.4242C5.67482 12.1899 5.67482 11.81 5.90913 11.5756L9.48487 7.9999L5.90913 4.42417C5.67482 4.18985 5.67482 3.80995 5.90913 3.57564Z",fillRule:"evenodd",clipRule:"evenodd"}}]},jo=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"more-single",ref:r,icon:gg}))});jo.displayName="MoreSingle";var Sg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1204",style:{maskType:"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_1204)"},children:[{tag:"rect",attrs:{width:12.62,height:2.79,x:1.69,y:12.25,fill:"colorChannel1",rx:1.4}},{tag:"path",attrs:{fill:"currentColor",d:"M7.74646 2.1642C7.34284 1.65121 6.85947 1.28205 6.38447 1.09593C5.86863 0.893787 5.15166 0.852126 4.70047 1.42917C4.29842 1.94344 4.33082 2.70249 4.57691 3.50395C4.68808 3.8661 4.86846 4.22254 5.12522 4.56617C5.13695 4.58185 5.14927 4.5968 5.16211 4.61102C5.17152 4.6214 5.18122 4.63139 5.19115 4.64096C5.20459 4.65393 5.21855 4.66618 5.23296 4.6777L3.5064 6.40422C3.26756 6.64306 3.26756 7.03033 3.5064 7.26919L7.23756 11.0004C7.47648 11.2392 7.86375 11.2392 8.1026 11.0004L12.8329 6.27001C13.0717 6.03117 13.0717 5.6439 12.8329 5.40505L9.10172 1.67387C8.86288 1.43503 8.47561 1.43503 8.23676 1.67387L7.74646 2.1642ZM7.46162 4.50638C7.47252 4.57574 7.48163 4.64652 7.4888 4.71868C7.52232 5.05481 7.82194 5.30013 8.15807 5.26661C8.4942 5.23311 8.73954 4.93345 8.70601 4.59732C8.65786 4.11463 8.54251 3.6666 8.37892 3.26169L8.66928 2.97135L11.5354 5.83753L10.6106 6.76237H4.87824L7.40802 4.2326C7.42885 4.32128 7.44684 4.41255 7.46162 4.50638ZM6.87284 3.03784C6.57441 2.62008 6.22261 2.34634 5.93815 2.23487C5.80233 2.18165 5.71528 2.17827 5.67638 2.18335C5.6725 2.18387 5.66929 2.18443 5.6666 2.18497L5.6619 2.18607C5.64166 2.21954 5.53594 2.45979 5.74626 3.1449C5.81241 3.36036 5.92262 3.58602 6.09307 3.81761L6.87284 3.03784Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M12.1932 11.5463C12.6454 11.5463 13.012 11.1797 13.012 10.7275C13.012 10.4475 12.6981 9.92821 12.459 9.5733C12.3299 9.38173 12.0564 9.38174 11.9274 9.57331C11.6883 9.92822 11.3744 10.4475 11.3744 10.7275C11.3744 11.1797 11.741 11.5463 12.1932 11.5463Z"}}]}]},Ol=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"paint-bucket",ref:r,icon:Sg}))});Ol.displayName="PaintBucket";var fg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_1138",style:{maskType:"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#DCDCDC",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{mask:"url(#mask0_102_1138)"},children:[{tag:"path",attrs:{fill:"colorChannel1",d:"M7.74692 9.12463C7.74692 9.46018 8.01893 9.73219 8.35448 9.73219H11.4933C11.8288 9.73219 12.1009 9.46018 12.1009 9.12463 12.1009 8.78909 11.8288 8.51707 11.4933 8.51707H8.35448C8.01893 8.51707 7.74692 8.78909 7.74692 9.12463zM10.8636 10.8523C10.8636 11.1879 10.5915 11.4599 10.256 11.4599H8.35448C8.01893 11.4599 7.74692 11.1879 7.74692 10.8523 7.74692 10.5168 8.01893 10.2447 8.35448 10.2447H10.256C10.5915 10.2447 10.8636 10.5168 10.8636 10.8523z"}},{tag:"path",attrs:{fill:"currentColor",d:"M5.4791 1.98268C5.47913 1.71529 5.87912 1.49854 6.37252 1.49854C6.86593 1.49854 7.26592 1.71529 7.26595 1.98268H7.62187C8.22277 1.98268 8.72459 2.39534 8.84412 2.9452H9.39563C10.0856 2.9452 10.6449 3.48923 10.6449 4.16032V6.00569H12.1261C13.161 6.00569 14 6.82174 14 7.82838V11.334C14 11.8174 13.8025 12.281 13.4511 12.6228L12.0693 13.9647C11.7179 14.3065 11.2412 14.4985 10.7442 14.4985H7.91116C7.05024 14.4985 6.32492 14.0431 6.10535 13.2737H3.34925C2.6593 13.2737 2.09998 12.7297 2.09998 12.0586V4.16032C2.09998 3.48923 2.6593 2.9452 3.34925 2.9452H3.90107C4.0206 2.39534 4.52241 1.98268 5.12332 1.98268H5.4791ZM3.97249 4.16032H3.24925L3.24925 12.0586H6.03725V7.82838C6.03725 6.82174 6.87623 6.00569 7.91116 6.00569H9.49563V4.16032H8.7727C8.58289 4.59611 8.13909 4.90183 7.62187 4.90183H5.12332C4.6061 4.90183 4.1623 4.59611 3.97249 4.16032ZM5.12332 2.89403H7.62187C7.79436 2.89403 7.93419 3.03003 7.93419 3.19781V3.68671C7.93419 3.85448 7.79436 3.99049 7.62187 3.99049H5.12332C4.95083 3.99049 4.811 3.85448 4.811 3.68671V3.19781C4.811 3.03003 4.95083 2.89403 5.12332 2.89403ZM7.91116 7.11157C7.56618 7.11157 7.28652 7.38359 7.28652 7.71913V12.7851C7.28652 13.1206 7.56618 13.3927 7.91116 13.3927H10.7442C10.8401 13.3927 10.9337 13.3712 11.0182 13.3311C11.1373 13.2746 11.1859 13.1423 11.1859 13.0134V12.0066C11.1859 11.8724 11.2978 11.7636 11.4358 11.7636H12.4709C12.6034 11.7636 12.7394 11.7163 12.7975 11.6004C12.8388 11.5182 12.8608 11.4272 12.8608 11.334V7.71913C12.8608 7.38359 12.5811 7.11157 12.2362 7.11157H7.91116Z",fillRule:"evenodd",clipRule:"evenodd"}}]}]},xl=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"paste-special",ref:r,icon:fg}))});xl.displayName="PasteSpecial";var pg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M5.785 6.77762C5.78908 6.7777 5.79316 6.77774 5.79725 6.77774C5.80134 6.77774 5.80543 6.7777 5.8095 6.77762H10.0184C10.0225 6.7777 10.0266 6.77774 10.0307 6.77774C10.0347 6.77774 10.0388 6.7777 10.0429 6.77762H13.6638V7.63727C13.6638 7.96864 13.9324 8.23727 14.2638 8.23727C14.5951 8.23727 14.8638 7.96864 14.8638 7.63727V3.9999C14.8638 2.56395 13.6997 1.39989 12.2637 1.3999L3.56389 1.39999C2.12797 1.40001 0.96393 2.56405 0.96392 3.99998L0.963867 11.6666C0.963857 13.1025 2.12792 14.2666 3.56387 14.2666H8.0542C8.38557 14.2666 8.6542 13.9979 8.6542 13.6666C8.6542 13.3352 8.38557 13.0666 8.0542 13.0666H3.56387C2.79067 13.0666 2.16386 12.4398 2.16387 11.6666L2.1639 6.77762H5.785ZM6.39725 2.59996L9.43065 2.59993V5.57762H6.39725V2.59996ZM5.19725 5.57762V2.59998L3.56391 2.59999C2.79072 2.6 2.16393 3.22679 2.16392 3.99998L2.16391 5.57762H5.19725ZM13.6638 5.57762V3.9999C13.6638 3.2267 13.037 2.59989 12.2638 2.5999L10.6307 2.59992V5.57762H13.6638Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M14.1223 10.2333V10.7496C14.7087 10.9869 15.1223 11.5618 15.1223 12.2333V12.8999C15.1223 13.7836 14.406 14.4999 13.5223 14.4999H11.5223C10.6387 14.4999 9.92235 13.7836 9.92235 12.8999V12.2333C9.92235 11.5618 10.336 10.9869 10.9223 10.7496V10.2333C10.9223 9.34961 11.6387 8.63328 12.5223 8.63328C13.406 8.63328 14.1223 9.34961 14.1223 10.2333ZM11.1223 12.2333C11.1223 12.0124 11.3014 11.8333 11.5223 11.8333H13.5223C13.7433 11.8333 13.9223 12.0124 13.9223 12.2333V12.8999C13.9223 13.1209 13.7433 13.2999 13.5223 13.2999H11.5223C11.3014 13.2999 11.1223 13.1209 11.1223 12.8999V12.2333ZM12.9223 10.2333V10.6333H12.1223V10.2333C12.1223 10.0124 12.3014 9.83328 12.5223 9.83328C12.7433 9.83328 12.9223 10.0124 12.9223 10.2333Z",fillRule:"evenodd",clipRule:"evenodd"}}]},Al=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"protect-single",ref:r,icon:pg}))});Al.displayName="ProtectSingle";var vg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1C11.866 1 15 4.13401 15 8ZM8.00008 12.3671C8.46031 12.3671 8.83342 11.994 8.83342 11.5338C8.83342 11.0735 8.46031 10.7004 8.00008 10.7004C7.53985 10.7004 7.16675 11.0735 7.16675 11.5338C7.16675 11.994 7.53985 12.3671 8.00008 12.3671ZM8.5999 4.4335C8.5999 4.10213 8.33127 3.8335 7.9999 3.8335C7.66853 3.8335 7.3999 4.10213 7.3999 4.4335V9.36683C7.3999 9.6982 7.66853 9.96683 7.9999 9.96683C8.33127 9.96683 8.5999 9.6982 8.5999 9.36683V4.4335Z",fillRule:"evenodd",clipRule:"evenodd"}}]},zo=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"warning-single",ref:r,icon:vg}))});zo.displayName="WarningSingle";var Cg={tag:"svg",attrs:{fill:"none",viewBox:"0 0 17 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M12.6551 1.98906C11.7476 1.08113 10.2757 1.08149 9.3686 1.98987L4.82542 6.53955C4.75087 6.61421 4.69336 6.70411 4.65682 6.80309L3.2461 10.625C3.16506 10.8446 3.21909 11.0912 3.3845 11.2568C3.54991 11.4224 3.79651 11.4767 4.01616 11.3959L7.85031 9.98517C7.94979 9.94856 8.04014 9.89077 8.11508 9.81579L12.6552 5.27327C13.5618 4.36621 13.5618 2.89607 12.6551 1.98906ZM10.2177 2.83779C10.6562 2.39869 11.3677 2.39851 11.8064 2.8374C12.2447 3.27584 12.2447 3.9865 11.8065 4.42497L7.3392 8.89457L4.82213 9.82068L5.74706 7.31487L10.2177 2.83779Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M1.79238 13.2999C1.46101 13.2999 1.19238 13.5685 1.19238 13.8999C1.19238 14.2313 1.46101 14.4999 1.79238 14.4999H14.4924C14.8238 14.4999 15.0924 14.2313 15.0924 13.8999C15.0924 13.5685 14.8238 13.2999 14.4924 13.2999H1.79238Z"}}]},Ts=H.forwardRef(function(n,r){return H.createElement(be,Object.assign({},n,{id:"write-single",ref:r,icon:Cg}))});Ts.displayName="WriteSingle";function Ig(n,r){if(n.length!==r.length)return!1;const e=n.sort((i,o)=>i.id.localeCompare(o.id)),t=r.sort((i,o)=>i.id.localeCompare(o.id));return e.every((i,o)=>{var s,l;return((s=i.subject)==null?void 0:s.userID)===((l=t[o].subject)==null?void 0:l.userID)&&i.role===t[o].role})}function Nl(n,r){return r.some(e=>_g(n,e))}function _g(n,r){const{startRow:e,startColumn:t,endColumn:i,endRow:o}=r,s=n.getMatrixWithMergedCells(e,t,o,i);let l=!1;return s.forValue((c,d,u)=>{if(u&&(c!==e||d!==t)&&n.cellHasValue(u))return l=!0,!1}),l}function Dl(n,r,e,t){const i=[],o=[],s=e.getSheetId();return t.forEach(l=>{const c=bg(e,l),d={unitId:r,subUnitId:s,cellValue:c.getData()},u=m.SetRangeValuesUndoMutationFactory(n,d);i.push({id:m.SetRangeValuesMutation.id,params:u}),o.push({id:m.SetRangeValuesMutation.id,params:d})}),{undos:i,redos:o}}function bg(n,r){const{startRow:e,startColumn:t,endColumn:i,endRow:o}=r,s=n.getMatrixWithMergedCells(e,t,o,i,a.CellModeEnum.Intercepted),l=new a.ObjectMatrix;let c=null;return s.forValue((d,u,h)=>{var g,S,f,p;h&&d>=e&&u>=t&&(!c&&n.cellHasValue(h)&&(h.v!==""||((p=(f=(S=(g=h.p)==null?void 0:g.body)==null?void 0:S.dataStream)==null?void 0:f.length)!=null?p:0)>2)&&(c=h),l.setValue(d,u,null))}),l.setValue(e,t,c),l}function Rg(n,r,e,t){const i=e.getActiveViewportByCoord(y.Vector2.FromArray([n,r]));if(!i)return;const{scaleX:o,scaleY:s}=e.getAncestorScale(),l={x:i.viewportScrollX,y:i.viewportScrollY},c=t.getCellIndexByOffset(n,r,o,s,l),d=t.worksheet.getMergedCell(c.row,c.column);return{actualRow:d?d.startRow:c.row,actualCol:d?d.startColumn:c.column,mergeCell:d,row:c.row,col:c.column}}function Eg(n,r,e,t){const i=t.getFreeze();if(!i||i.startRow<=0&&i.startColumn<=0||n>=i.startRow&&r>=i.startColumn)return e.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(n<i.startRow&&r<i.startColumn)return e.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT_TOP);if(n<i.startRow&&r>=i.startColumn)return e.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_TOP);if(n>=i.startRow&&r<i.startColumn)return e.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN_LEFT)}function Tg(n,r,e,t){const i=va(n.left,n.top,r,e,t),o=va(n.right,n.bottom,r,e,t);return{left:i.x,top:i.y,right:o.x,bottom:o.y}}function va(n,r,e,t,i){const{scaleX:o,scaleY:s}=e.getAncestorScale(),l=e.getViewport(y.SHEET_VIEWPORT_KEY.VIEW_MAIN);if(!l)return{x:n,y:r};const c=i.getFreeze(),{startColumn:d,startRow:u,xSplit:h,ySplit:g}=c,S=t.getNoMergeCellPositionByIndexWithNoHeader(u-g,d-h),f=t.getNoMergeCellPositionByIndexWithNoHeader(u,d),{rowHeaderWidth:p,columnHeaderHeight:v}=t,C=f.startX-S.startX,_=f.startY-S.startY,{top:b,left:E,viewportScrollX:M,viewportScrollY:w}=l;let P;n>E?P=(n-M)*o:P=(C+p-(E-n))*o;let x;return r>b?x=(r-w)*s:x=(_+v-(b-r))*o,{x:P,y:x}}function kl(n,r,e,t,i){let o=t,s=i;e.overflowCache.forValue((d,u,h)=>{h.startRow<=o&&h.endRow>=o&&h.startColumn<=s&&h.endColumn>=s&&(s=u,o=d)});const l=e.getCellWithCoordByIndex(o,s);return{unitId:n.getUnitId(),subUnitId:r.getSheetId(),workbook:n,worksheet:r,row:l.actualRow,col:l.actualColumn}}function Vl(n,r,e,t,i,o){const{scene:s}=n,l=r.getUnitId(),{skeleton:c,sheetId:d}=t,u=Rg(i,o,s,c);if(!u)return null;let{actualCol:h,actualRow:g}=u;const S={unitId:l,subUnitId:d,workbook:r,worksheet:e,row:g,col:h};c.overflowCache.forValue((w,P,x)=>{x.startRow<=g&&x.endRow>=g&&x.startColumn<=h&&x.endColumn>=h&&(h=P,g=w)});const f=c.getCellWithCoordByIndex(g,h),p=kl(r,e,c,g,h);let v;f.mergeInfo?v=f.mergeInfo:v={startRow:p.row,endRow:p.row,startColumn:p.col,endColumn:p.col};const C=s.getActiveViewportByCoord(y.Vector2.FromArray([i,o]));if(!C)return;const{scaleX:_,scaleY:b}=s.getAncestorScale(),E={x:C.viewportScrollX,y:C.viewportScrollY};return{position:{startX:(c.getOffsetByPositionX(v.startColumn-1)-E.x)*_,endX:(c.getOffsetByPositionX(v.endColumn)-E.x)*_,startY:(c.getOffsetByPositionY(v.startRow-1)-E.y)*b,endY:(c.getOffsetByPositionY(v.endRow)-E.y)*b},location:S,overflowLocation:p}}const wt={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge",handler:async(n,r)=>{const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),i=n.get(a.IUniverInstanceService),o=n.get(R.IConfirmService),s=n.get(a.LocaleService),l=r.unitId,c=r.subUnitId,d=r.selections,u=m.getAddMergeMutationRangeByType(d,r.value),h=i.getUniverSheetInstance(l).getSheetBySheetId(c),g=[],S=[],f=Nl(h,u);if(f&&!r.defaultMerge&&!await o.confirm({id:"merge.confirm.add-worksheet-merge",title:{title:"merge.confirm.title"},cancelText:s.t("merge.confirm.cancel"),confirmText:s.t("merge.confirm.confirm")}))return!1;const p={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},v={unitId:l,subUnitId:c,ranges:a.Tools.deepClone(u)},C=m.RemoveMergeUndoMutationFactory(n,p),_=m.AddMergeUndoMutationFactory(n,v);if(C.ranges.length>0&&g.push({id:m.RemoveWorksheetMergeMutation.id,params:C}),g.push({id:m.AddWorksheetMergeMutation.id,params:v}),S.push({id:m.RemoveWorksheetMergeMutation.id,params:_}),C.ranges.length>0&&S.push({id:m.AddWorksheetMergeMutation.id,params:C}),f){const x=Dl(n,l,h,u);g.unshift(...x.redos),S.push(...x.undos)}const b=m.AddMergeRedoSelectionsOperationFactory(n,r,u);b&&g.push(b);const E=m.AddMergeUndoSelectionsOperationFactory(n,r);E&&S.push(E);const w=n.get(m.SheetInterceptorService).onCommandExecute({id:wt.id,params:{unitId:l,subUnitId:c,ranges:u}});return g.push(...w.redos),S.push(...w.undos),a.sequenceExecute(g,e).result?(t.pushUndoRedo({unitID:l,undoMutations:S,redoMutations:g}),!0):!1}},ws={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-all",handler:async n=>{var u;const r=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),i=us(Er.MergeAll,t);if(!(i!=null&&i.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return r.executeCommand(wt.id,{selections:i,unitId:c,subUnitId:d})}},ys={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-vertical",handler:async n=>{var u;const r=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),i=us(Er.MergeVertical,t);if(!(i!=null&&i.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return r.executeCommand(wt.id,{value:a.Dimension.COLUMNS,selections:i,unitId:c,subUnitId:d})}},Ms={type:a.CommandType.COMMAND,id:"sheet.command.add-worksheet-merge-horizontal",handler:async n=>{var u;const r=n.get(a.ICommandService),t=(u=n.get(m.SheetsSelectionsService).getCurrentSelections())==null?void 0:u.map(h=>h.range),i=us(Er.MergeHorizontal,t);if(!(i!=null&&i.length))return!1;const s=n.get(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET);if(!s)return!1;const l=s.getActiveSheet();if(!l)return!1;const c=s.getUnitId(),d=l.getSheetId();return r.executeCommand(wt.id,{value:a.Dimension.ROWS,selections:i,unitId:c,subUnitId:d})}},Dn={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-left-confirm",handler:async n=>{const r=n.get(R.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),i=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=i.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:c}=l;let d=s[0].range;if(!d)return!1;d={...d,endColumn:c.getColumnCount()-1};const u=S=>S.endRow-S.startRow;return!c.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,d);return f?u(S)>u(f):!1})||await r.confirm({id:Dn.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.DeleteRangeMoveLeftCommand.id):!0}},jt={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-move-up-confirm",handler:async n=>{const r=n.get(R.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),i=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=i.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:c}=l;let d=s[0].range;if(!d)return!1;d={...d,endRow:c.getRowCount()-1};for(let S=d.startRow;S<=d.endRow;S++)if(c.getRowFiltered(S)&&await r.confirm({id:jt.id,title:{title:t.t("filter.confirm.error")},children:{title:t.t("filter.confirm.notAllowedToInsertRange")},confirmText:t.t("button.confirm")}))return!1;const u=S=>S.endColumn-S.startColumn;return!c.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,d);return f?u(S)>u(f):!1})||await r.confirm({id:jt.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.DeleteRangeMoveUpCommand.id):!0}},zt={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-down-confirm",handler:async n=>{const r=n.get(R.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),i=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=i.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:c}=l;let d=s[0].range;if(!d)return!1;d={...d,endRow:c.getRowCount()-1};for(let S=d.startRow;S<=d.endRow;S++)if(c.getRowFiltered(S)&&await r.confirm({id:zt.id,title:{title:t.t("filter.confirm.error")},children:{title:t.t("filter.confirm.notAllowedToInsertRange")},confirmText:t.t("button.confirm")}))return!1;const u=S=>S.endColumn-S.startColumn;return!c.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,d);return f?u(S)>u(f):!1})||await r.confirm({id:zt.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.InsertRangeMoveDownCommand.id):!0}},kn={type:a.CommandType.COMMAND,id:"sheet.command.insert-range-move-right-confirm",handler:async n=>{const r=n.get(R.IConfirmService),e=n.get(a.ICommandService),t=n.get(a.LocaleService),i=n.get(m.SheetsSelectionsService),o=n.get(a.IUniverInstanceService),s=i.getCurrentSelections();if(!s)return!1;const l=m.getSheetCommandTarget(o);if(!l)return!1;const{worksheet:c}=l;let d=s[0].range;if(!d)return!1;d={...d,endColumn:c.getColumnCount()-1};const u=S=>S.endRow-S.startRow;return!c.getMergeData().find(S=>{const f=a.Rectangle.getIntersects(S,d);return f?u(S)>u(f):!1})||await r.confirm({id:kn.id,title:{title:t.t("merge.confirm.waring")},children:{title:t.t("merge.confirm.dismantleMergeCellWaring")},cancelText:t.t("button.cancel"),confirmText:t.t("button.confirm")})?e.executeCommand(m.InsertRangeMoveRightCommand.id):!0}};var Hl=(n=>(n[n.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",n[n.UNIVER_DOC=1]="UNIVER_DOC",n[n.UNIVER_SHEET=2]="UNIVER_SHEET",n[n.UNIVER_SLIDE=3]="UNIVER_SLIDE",n[n.UNIVER_PROJECT=4]="UNIVER_PROJECT",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Hl||{}),ee=(n=>(n[n.View=0]="View",n[n.Edit=1]="Edit",n[n.ManageCollaborator=2]="ManageCollaborator",n[n.Print=3]="Print",n[n.Duplicate=4]="Duplicate",n[n.Comment=5]="Comment",n[n.Copy=6]="Copy",n[n.Share=7]="Share",n[n.Export=8]="Export",n[n.MoveWorksheet=9]="MoveWorksheet",n[n.DeleteWorksheet=10]="DeleteWorksheet",n[n.HideWorksheet=11]="HideWorksheet",n[n.RenameWorksheet=12]="RenameWorksheet",n[n.CreateWorksheet=13]="CreateWorksheet",n[n.SetWorksheetStyle=14]="SetWorksheetStyle",n[n.EditWorksheetCell=15]="EditWorksheetCell",n[n.InsertHyperlink=16]="InsertHyperlink",n[n.Sort=17]="Sort",n[n.Filter=18]="Filter",n[n.PivotTable=19]="PivotTable",n[n.FloatImg=20]="FloatImg",n[n.History=21]="History",n[n.RwHgtClWdt=22]="RwHgtClWdt",n[n.ViemRwHgtClWdt=23]="ViemRwHgtClWdt",n[n.ViewFilter=24]="ViewFilter",n[n.MoveSheet=25]="MoveSheet",n[n.DeleteSheet=26]="DeleteSheet",n[n.HideSheet=27]="HideSheet",n[n.CopySheet=28]="CopySheet",n[n.RenameSheet=29]="RenameSheet",n[n.CreateSheet=30]="CreateSheet",n[n.SelectProtectedCells=31]="SelectProtectedCells",n[n.SelectUnProtectedCells=32]="SelectUnProtectedCells",n[n.SetCellStyle=33]="SetCellStyle",n[n.SetCellValue=34]="SetCellValue",n[n.SetRowStyle=35]="SetRowStyle",n[n.SetColumnStyle=36]="SetColumnStyle",n[n.InsertRow=37]="InsertRow",n[n.InsertColumn=38]="InsertColumn",n[n.DeleteRow=39]="DeleteRow",n[n.DeleteColumn=40]="DeleteColumn",n[n.EditExtraObject=41]="EditExtraObject",n[n.Delete=42]="Delete",n[n.RecoverHistory=43]="RecoverHistory",n[n.ViewHistory=44]="ViewHistory",n[n.CreatePermissionObject=45]="CreatePermissionObject",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(ee||{}),Ne=(n=>(n[n.Reader=0]="Reader",n[n.Editor=1]="Editor",n[n.Owner=2]="Owner",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Ne||{}),ct=(n=>(n[n.Unkonwn=0]="Unkonwn",n[n.Workbook=1]="Workbook",n[n.Worksheet=2]="Worksheet",n[n.SelectRange=3]="SelectRange",n[n.Document=4]="Document",n[n.Slide=5]="Slide",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(ct||{}),Ze=(n=>(n[n.SomeCollaborator=0]="SomeCollaborator",n[n.AllCollaborator=1]="AllCollaborator",n[n.OneSelf=2]="OneSelf",n[n.UNRECOGNIZED=-1]="UNRECOGNIZED",n))(Ze||{});const ti="UNIVER_SHEET_PERMISSION_PANEL",er="UNIVER_SHEET_PERMISSION_USER_PART",Ps="UNIVER_SHEET_PERMISSION_BACKGROUND",Wl="UNIVER_SHEET_PERMISSION_USER_DIALOG",Ul="UNIVER_SHEET_PERMISSION_DIALOG",tr="UNIVER_SHEET_PERMISSION_USER_DIALOG_ID",nr="UNIVER_SHEET_PERMISSION_DIALOG_ID",Vi={[ee.Copy]:"Copy",[ee.SetCellStyle]:"SetCellStyle",[ee.SetCellValue]:"SetCellValue",[ee.SetRowStyle]:"SetRowStyle",[ee.SetColumnStyle]:"SetColumnStyle",[ee.InsertRow]:"InsertRow",[ee.InsertColumn]:"InsertColumn",[ee.InsertHyperlink]:"InsertHyperlink",[ee.DeleteRow]:"DeleteRow",[ee.DeleteColumn]:"DeleteColumn",[ee.Sort]:"Sort",[ee.Filter]:"Filter",[ee.PivotTable]:"PivotTable",[ee.EditExtraObject]:"EditExtraObject"},wg=[ee.Copy,ee.SetCellStyle,ee.SetCellValue,ee.SetRowStyle,ee.SetColumnStyle,ee.InsertRow,ee.InsertColumn,ee.InsertHyperlink,ee.DeleteRow,ee.DeleteColumn,ee.Sort,ee.Filter,ee.PivotTable,ee.EditExtraObject,ee.View],Ll="sheet-permission-menu-icon",yg="sheet-permission-delete-icon",Mg="sheet-permission-edit-icon",Pg="sheet-permission-check-icon",Bl="sheet-permission-lock-icon",Og={unitId:"",subUnitId:"",permissionId:"",unitType:m.UnitObject.SelectRange,id:"",ranges:[],viewState:m.ViewStateEnum.OthersCanView,editState:m.EditStateEnum.OnlyMe};class wn{constructor(){T(this,"_rule",Og);T(this,"_visible",!1)}setVisible(r){this._visible=r}getVisible(){return this._visible}reset(){this.setVisible(!1)}}class yt{constructor(){T(this,"_userList",[]);T(this,"_oldCollaboratorList",[]);T(this,"_selectUserList",[]);T(this,"_selectUserList$",new O.BehaviorSubject(this._selectUserList));T(this,"selectUserList$",this._selectUserList$.asObservable())}get userList(){return this._userList}setCanEditUserList(r){this._userList=r}reset(){this._userList=[],this._oldCollaboratorList=[],this._selectUserList=[],this._selectUserList$.next([])}get oldCollaboratorList(){return this._oldCollaboratorList}setOldCollaboratorList(r){this._oldCollaboratorList=r}get selectUserList(){return this._selectUserList}setSelectUserList(r){this._selectUserList=r,this._selectUserList$.next(r)}}const Qe={type:a.CommandType.OPERATION,id:"sheet-permission.operation.openPanel",async handler(n,r={}){const e=n.get(R.ISidebarService),t=n.get(wn),i=n.get(yt),{showDetail:o=!0,fromSheetBar:s=!1,rule:l,oldRule:c}=r,d={header:{title:"permission.panel.title"},children:{label:ti,showDetail:o,fromSheetBar:s,rule:l,oldRule:c},width:330,onClose:()=>{t.reset(),i.reset()}};return t.setVisible(!0),e.open(d),!0}},Ri={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-toolbar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!0}),!0}},Vt={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!0}),!0}},Ht={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-context-menu",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!1}),!0}},Ei={type:a.CommandType.COMMAND,id:"sheet.command.add-range-protection-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{fromSheetBar:!0,showDetail:!0}),!0}},Ti={type:a.CommandType.COMMAND,id:"sheet.command.view-sheet-permission-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand(Qe.id,{showDetail:!1}),!0}},Wt={type:a.CommandType.COMMAND,id:"sheet.command.delete-range-protection-from-context-menu",async handler(n){var h;const r=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(a.IUndoRedoService),i=n.get(m.SheetsSelectionsService),o=n.get(m.WorksheetProtectionRuleModel),s=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),l=s.getActiveSheet(),c=s.getUnitId(),d=l.getSheetId(),u=o.getRule(c,d);if(u!=null&&u.permissionId)return r.executeCommand(m.DeleteWorksheetProtectionCommand.id,{unitId:c,subUnitId:d,rule:u});{const g=(h=i.getCurrentLastSelection())==null?void 0:h.range;if(!g)return!1;const p=n.get(m.RangeProtectionRuleModel).getSubunitRuleList(c,d).find(v=>v.ranges.some(C=>a.Rectangle.intersects(C,g)));if(p){const v={unitId:c,subUnitId:d,ruleIds:[p.id]};return await r.executeCommand(m.DeleteRangeProtectionMutation.id,v)&&t.pushUndoRedo({unitID:c,redoMutations:[{id:m.DeleteRangeProtectionMutation.id,params:v}],undoMutations:[{id:m.AddRangeProtectionMutation.id,params:{unitId:c,subUnitId:d,rules:[p]}}]}),!0}else return!1}}},Ut={type:a.CommandType.COMMAND,id:"sheet.command.set-range-protection-from-context-menu",async handler(n){var u;const r=n.get(a.ICommandService),e=n.get(a.IUniverInstanceService),t=n.get(m.SheetsSelectionsService),i=n.get(m.WorksheetProtectionRuleModel),o=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),s=o.getActiveSheet(),l=o.getUnitId(),c=s.getSheetId(),d=i.getRule(l,c);if(d!=null&&d.permissionId){const h={...d,unitId:l,subUnitId:c,ranges:[]};return await r.executeCommand(Qe.id,{showDetail:!0,rule:a.Tools.deepClone(h),oldRule:a.Tools.deepClone(h)}),!0}else{const h=(u=t.getCurrentLastSelection())==null?void 0:u.range;if(!h)return!1;const f=n.get(m.RangeProtectionRuleModel).getSubunitRuleList(l,c).find(p=>{var v;return(v=p==null?void 0:p.ranges)==null?void 0:v.some(C=>a.Rectangle.intersects(C,h))});if(f){const p={...f,unitId:l,subUnitId:c};return await r.executeCommand(Qe.id,{showDetail:!0,rule:a.Tools.deepClone(p),oldRule:a.Tools.deepClone(p)}),!0}else return!1}}},yn={id:"sheet.command.remove-row-confirm",type:a.CommandType.COMMAND,handler:async(n,r)=>{var d;const e=n.get(m.SheetsSelectionsService);let t=r==null?void 0:r.range;if(t||(t=(d=e.getCurrentLastSelection())==null?void 0:d.range),!t)return!1;const i=n.get(a.ICommandService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o);if(!s)return!1;const{worksheet:l}=s,c=l.getVisibleRows();if(Ya(c,[t])){const u=n.get(R.IConfirmService),h=n.get(a.LocaleService);return await u.confirm({id:"sheet.confirm.remove-row",title:{title:h.t("info.problem")},children:{title:h.t("rightClick.deleteAllRowsAlert")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm")}),!1}return await i.executeCommand(m.RemoveRowCommand.id,{range:t}),!0}},Mn={id:"sheet.command.remove-col-confirm",type:a.CommandType.COMMAND,handler:async(n,r)=>{var d;const e=n.get(m.SheetsSelectionsService);let t=r==null?void 0:r.range;if(t||(t=(d=e.getCurrentLastSelection())==null?void 0:d.range),!t)return!1;const i=n.get(a.ICommandService),o=n.get(a.IUniverInstanceService),s=m.getSheetCommandTarget(o);if(!s)return!1;const{worksheet:l}=s,c=l.getVisibleCols();if(Ga(c,[t])){const u=n.get(R.IConfirmService),h=n.get(a.LocaleService);return await u.confirm({id:"sheet.confirm.remove-col",title:{title:h.t("info.problem")},children:{title:h.t("rightClick.deleteAllColumnsAlert")},cancelText:h.t("button.cancel"),confirmText:h.t("button.confirm")}),!1}return await i.executeCommand(m.RemoveColCommand.id,{range:t}),!0}},wi={id:"sheet.command.remove-sheet-confirm",type:a.CommandType.COMMAND,handler:async(n,r)=>{const{subUnitId:e}=r,t=n.get(R.IConfirmService),i=n.get(a.ICommandService),o=n.get(a.LocaleService);return await t.confirm({id:"sheet.confirm.remove-sheet",title:{title:o.t("sheetConfig.deleteSheet")},children:{title:o.t("sheetConfig.deleteSheetContent")},cancelText:o.t("button.cancel"),confirmText:o.t("button.confirm")})?(await i.executeCommand(m.RemoveSheetCommand.id,{subUnitId:e}),!0):!1}},Jt=a.createIdentifier("univer.sheetbar-service");class Fl extends a.Disposable{constructor(){super();T(this,"renameId$");T(this,"removeId$");T(this,"scroll$");T(this,"scrollX$");T(this,"addSheet$");T(this,"_renameId$");T(this,"_removeId$");T(this,"_scroll$");T(this,"_scrollX$");T(this,"_addSheet$");T(this,"_currentHandler",null);this._renameId$=new O.Subject,this.renameId$=this._renameId$.asObservable(),this._removeId$=new O.Subject,this.removeId$=this._removeId$.asObservable(),this._scroll$=new O.Subject,this.scroll$=this._scroll$.asObservable(),this._scrollX$=new O.Subject,this.scrollX$=this._scrollX$.asObservable(),this._addSheet$=new O.Subject,this.addSheet$=this._addSheet$.asObservable()}setRenameId(e){this._renameId$.next(e)}setRemoveId(e){this._removeId$.next(e)}setScroll(e){this._scroll$.next(e)}setScrollX(e){this._scrollX$.next(e)}setAddSheet(e){this._addSheet$.next(e)}triggerSheetBarMenu(){var e;(e=this._currentHandler)==null||e.handleSheetBarMenu()}registerSheetBarMenuHandler(e){if(this._currentHandler)throw new Error("There is already a context menu handler!");return this._currentHandler=e,a.toDisposable(()=>{this._currentHandler=null})}}const yi={id:"ui-sheet.command.show-menu-list",type:a.CommandType.OPERATION,handler:async n=>(n.get(Jt).triggerSheetBarMenu(),!0)},Mi={type:a.CommandType.COMMAND,id:"sheet.command.delete-worksheet-protection-from-sheet-bar",async handler(n,r){if(!r)return!1;const e=n.get(a.ICommandService),t=n.get(a.IUndoRedoService),i=n.get(m.WorksheetProtectionRuleModel),s=n.get(a.IUniverInstanceService).getCurrentUnitForType(Hl.UNIVER_SHEET),l=s==null?void 0:s.getActiveSheet(),c=s.getUnitId();if(!l)return!1;const d=l.getSheetId(),u=i.getRule(c,d);if(await e.executeCommand(m.DeleteWorksheetProtectionCommand.id,{unitId:c,subUnitId:d})){const g=[{id:m.DeleteWorksheetProtectionCommand.id,params:{unitId:c,subUnitId:d}}],S=[{id:m.AddWorksheetProtectionCommand.id,params:{unitId:c,rule:u}}];t.pushUndoRedo({unitID:c,redoMutations:g,undoMutations:S})}return!0}},Pi={type:a.CommandType.COMMAND,id:"sheet.command.change-sheet-protection-from-sheet-bar",async handler(n){return await n.get(a.ICommandService).executeCommand("sheet-permission.operation.openDialog"),!0}},kr={id:"sheet.operation.set-activate-cell-edit",type:a.CommandType.OPERATION,handler:(n,r)=>(n.get(he).setEditCell(r),!0)},Oi={id:"sheet.operation.rename-sheet",type:a.CommandType.OPERATION,handler:async(n,r)=>{const e=n.get(Jt);return r&&e.setRenameId(r.subUnitId),!0}},Os={type:a.CommandType.OPERATION,id:"sheet-permission.operation.openDialog",async handler(n,r){const e=n.get(R.IDialogService);return e.close("DESKTOP_FIND_REPLACE_DIALOG"),e.open({id:nr,title:{title:"permission.dialog.allowedPermissionType"},children:{label:Ul},width:393,destroyOnClose:!0,onClose:()=>e.close(nr)}),!0}},ni="DefinedNameContainer",Vr={id:"sidebar.operation.defined-name",type:a.CommandType.COMMAND,handler:async(n,r)=>{const e=n.get(R.ISidebarService);n.get(J.IEditorService);const t=n.get(a.LocaleService),i=n.get(a.IUniverInstanceService);if(!m.getSheetCommandTarget(i))return!1;switch(r.value){case"open":e.open({id:ni,header:{title:t.t("definedName.featureTitle")},children:{label:ni},onClose:()=>{},width:333});break;case"close":default:e.close();break}return!0}},xg=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M0.98999 1.08218H-0.0100098V0.0821838H0.98999V1.08218Z",fill:"black"}),I.jsx("path",{d:"M5.78992 1.08218H2.78992V0.0821838H5.78992V1.08218Z",fill:"black"}),I.jsx("path",{d:"M7.58984 1.08218H8.58984V0.0821838H7.58984V1.08218Z",fill:"black"}),I.jsx("path",{d:"M14.9152 1.08218H13.9152V0.0821838H14.9152V1.08218Z",fill:"black"}),I.jsx("path",{d:"M16.7151 1.08218H19.7151V0.0821838H16.7151V1.08218Z",fill:"black"}),I.jsx("path",{d:"M22.515 1.08218H21.515V0.0821838H22.515V1.08218Z",fill:"black"}),I.jsx("path",{d:"M27.8405 1.08218H28.8405V0.0821838H27.8405V1.08218Z",fill:"black"}),I.jsx("path",{d:"M33.6404 1.08218H30.6404V0.0821838H33.6404V1.08218Z",fill:"black"}),I.jsx("path",{d:"M35.4403 1.08218H36.4403V0.0821838H35.4403V1.08218Z",fill:"black"}),I.jsx("path",{d:"M42.7657 1.08218H41.7657V0.0821838H42.7657V1.08218Z",fill:"black"}),I.jsx("path",{d:"M44.5657 1.08218H47.5657V0.0821838H44.5657V1.08218Z",fill:"black"}),I.jsx("path",{d:"M50.3656 1.08218H49.3656V0.0821838H50.3656V1.08218Z",fill:"black"}),I.jsx("path",{d:"M55.691 1.08218H56.691V0.0821838H55.691V1.08218Z",fill:"black"}),I.jsx("path",{d:"M61.491 1.08218H58.491V0.0821838H61.491V1.08218Z",fill:"black"}),I.jsx("path",{d:"M63.2909 1.08218H64.2909V0.0821838H63.2909V1.08218Z",fill:"black"}),I.jsx("path",{d:"M70.6163 1.08218H69.6163V0.0821838H70.6163V1.08218Z",fill:"black"}),I.jsx("path",{d:"M72.4163 1.08218H75.4163V0.0821838H72.4163V1.08218Z",fill:"black"}),I.jsx("path",{d:"M78.2162 1.08218H77.2162V0.0821838H78.2162V1.08218Z",fill:"black"}),I.jsx("path",{d:"M83.5416 1.08218H84.5416V0.0821838H83.5416V1.08218Z",fill:"black"}),I.jsx("path",{d:"M89.3416 1.08218H86.3416V0.0821838H89.3416V1.08218Z",fill:"black"}),I.jsx("path",{d:"M91.1415 1.08218H92.1415V0.0821838H91.1415V1.08218Z",fill:"black"}),I.jsx("path",{d:"M98.4669 1.08218H97.4669V0.0821838H98.4669V1.08218Z",fill:"black"}),I.jsx("path",{d:"M100.267 1.08218H103.267V0.0821838H100.267V1.08218Z",fill:"black"}),I.jsx("path",{d:"M106.067 1.08218H105.067V0.0821838H106.067V1.08218Z",fill:"black"}),I.jsx("path",{d:"M111.392 1.08218H112.392V0.0821838H111.392V1.08218Z",fill:"black"}),I.jsx("path",{d:"M117.192 1.08218H114.192V0.0821838H117.192V1.08218Z",fill:"black"}),I.jsx("path",{d:"M118.992 1.08218H119.992V0.0821838H118.992V1.08218Z",fill:"black"})]}),Ag=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.0100098 1.15771H0.98999V0.157715H-0.0100098V1.15771Z",fill:"black"}),I.jsx("path",{d:"M2.78992 1.15771H5.78992V0.157715H2.78992V1.15771Z",fill:"black"}),I.jsx("path",{d:"M8.58984 1.15771H7.58984V0.157715H8.58984V1.15771Z",fill:"black"}),I.jsx("path",{d:"M10.3899 1.15771H11.3899V0.157715H10.3899V1.15771Z",fill:"black"}),I.jsx("path",{d:"M19.0903 1.15771H18.0903V0.157715H19.0903V1.15771Z",fill:"black"}),I.jsx("path",{d:"M20.8903 1.15771H23.8903V0.157715H20.8903V1.15771Z",fill:"black"}),I.jsx("path",{d:"M26.6902 1.15771H25.6902V0.157715H26.6902V1.15771Z",fill:"black"}),I.jsx("path",{d:"M28.4902 1.15771H29.4902V0.157715H28.4902V1.15771Z",fill:"black"}),I.jsx("path",{d:"M37.1907 1.15771H36.1907V0.157715H37.1907V1.15771Z",fill:"black"}),I.jsx("path",{d:"M38.9906 1.15771H41.9906V0.157715H38.9906V1.15771Z",fill:"black"}),I.jsx("path",{d:"M44.7905 1.15771H43.7905V0.157715H44.7905V1.15771Z",fill:"black"}),I.jsx("path",{d:"M46.5906 1.15771H47.5906V0.157715H46.5906V1.15771Z",fill:"black"}),I.jsx("path",{d:"M55.291 1.15771H54.291V0.157715H55.291V1.15771Z",fill:"black"}),I.jsx("path",{d:"M57.0909 1.15771H60.0909V0.157715H57.0909V1.15771Z",fill:"black"}),I.jsx("path",{d:"M62.8909 1.15771H61.8909V0.157715H62.8909V1.15771Z",fill:"black"}),I.jsx("path",{d:"M64.6909 1.15771H65.6909V0.157715H64.6909V1.15771Z",fill:"black"}),I.jsx("path",{d:"M73.3914 1.15771H72.3914V0.157715H73.3914V1.15771Z",fill:"black"}),I.jsx("path",{d:"M75.1913 1.15771H78.1913V0.157715H75.1913V1.15771Z",fill:"black"}),I.jsx("path",{d:"M80.9912 1.15771H79.9912V0.157715H80.9912V1.15771Z",fill:"black"}),I.jsx("path",{d:"M82.7913 1.15771H83.7913V0.157715H82.7913V1.15771Z",fill:"black"}),I.jsx("path",{d:"M91.4917 1.15771H90.4917V0.157715H91.4917V1.15771Z",fill:"black"}),I.jsx("path",{d:"M93.2916 1.15771H96.2916V0.157715H93.2916V1.15771Z",fill:"black"}),I.jsx("path",{d:"M99.0916 1.15771H98.0916V0.157715H99.0916V1.15771Z",fill:"black"}),I.jsx("path",{d:"M100.892 1.15771H101.892V0.157715H100.892V1.15771Z",fill:"black"}),I.jsx("path",{d:"M109.592 1.15771H108.592V0.157715H109.592V1.15771Z",fill:"black"}),I.jsx("path",{d:"M111.392 1.15771H114.392V0.157715H111.392V1.15771Z",fill:"black"}),I.jsx("path",{d:"M117.192 1.15771H116.192V0.157715H117.192V1.15771Z",fill:"black"}),I.jsx("path",{d:"M118.992 1.15771H119.992V0.157715H118.992V1.15771Z",fill:"black"})]}),Ng=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.00842285 1.22449H2.99158V0.224487H-0.00842285V1.22449Z",fill:"black"}),I.jsx("path",{d:"M6.14941 1.22449H9.14941V0.224487H6.14941V1.22449Z",fill:"black"}),I.jsx("path",{d:"M15.3073 1.22449H12.3073V0.224487H15.3073V1.22449Z",fill:"black"}),I.jsx("path",{d:"M18.4651 1.22449H21.4651V0.224487H18.4651V1.22449Z",fill:"black"}),I.jsx("path",{d:"M27.6229 1.22449H24.6229V0.224487H27.6229V1.22449Z",fill:"black"}),I.jsx("path",{d:"M30.7808 1.22449H33.7808V0.224487H30.7808V1.22449Z",fill:"black"}),I.jsx("path",{d:"M39.9386 1.22449H36.9386V0.224487H39.9386V1.22449Z",fill:"black"}),I.jsx("path",{d:"M43.0964 1.22449H46.0964V0.224487H43.0964V1.22449Z",fill:"black"}),I.jsx("path",{d:"M52.2543 1.22449H49.2543V0.224487H52.2543V1.22449Z",fill:"black"}),I.jsx("path",{d:"M55.4121 1.22449H58.4121V0.224487H55.4121V1.22449Z",fill:"black"}),I.jsx("path",{d:"M64.5699 1.22449H61.5699V0.224487H64.5699V1.22449Z",fill:"black"}),I.jsx("path",{d:"M67.7278 1.22449H70.7278V0.224487H67.7278V1.22449Z",fill:"black"}),I.jsx("path",{d:"M76.8856 1.22449H73.8856V0.224487H76.8856V1.22449Z",fill:"black"}),I.jsx("path",{d:"M80.0435 1.22449H83.0435V0.224487H80.0435V1.22449Z",fill:"black"}),I.jsx("path",{d:"M89.2013 1.22449H86.2013V0.224487H89.2013V1.22449Z",fill:"black"}),I.jsx("path",{d:"M92.3591 1.22449H95.3591V0.224487H92.3591V1.22449Z",fill:"black"}),I.jsx("path",{d:"M101.517 1.22449H98.517V0.224487H101.517V1.22449Z",fill:"black"}),I.jsx("path",{d:"M104.675 1.22449H107.675V0.224487H104.675V1.22449Z",fill:"black"}),I.jsx("path",{d:"M113.833 1.22449H110.833V0.224487H113.833V1.22449Z",fill:"black"}),I.jsx("path",{d:"M116.99 1.22449H119.99V0.224487H116.99V1.22449Z",fill:"black"})]}),Dg=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.00976562 1.65707H0.990234V0.657074H-0.00976562V1.65707Z",fill:"black"}),I.jsx("path",{d:"M2.32361 1.65707H3.32361V0.657074H2.32361V1.65707Z",fill:"black"}),I.jsx("path",{d:"M5.65698 1.65707H4.65698V0.657074H5.65698V1.65707Z",fill:"black"}),I.jsx("path",{d:"M6.99036 1.65707H7.99036V0.657074H6.99036V1.65707Z",fill:"black"}),I.jsx("path",{d:"M10.3237 1.65707H9.32373V0.657074H10.3237V1.65707Z",fill:"black"}),I.jsx("path",{d:"M11.6571 1.65707H12.6571V0.657074H11.6571V1.65707Z",fill:"black"}),I.jsx("path",{d:"M14.9905 1.65707H13.9905V0.657074H14.9905V1.65707Z",fill:"black"}),I.jsx("path",{d:"M16.3239 1.65707H17.3239V0.657074H16.3239V1.65707Z",fill:"black"}),I.jsx("path",{d:"M19.6572 1.65707H18.6572V0.657074H19.6572V1.65707Z",fill:"black"}),I.jsx("path",{d:"M20.9906 1.65707H21.9906V0.657074H20.9906V1.65707Z",fill:"black"}),I.jsx("path",{d:"M24.324 1.65707H23.324V0.657074H24.324V1.65707Z",fill:"black"}),I.jsx("path",{d:"M25.6573 1.65707H26.6573V0.657074H25.6573V1.65707Z",fill:"black"}),I.jsx("path",{d:"M28.9907 1.65707H27.9907V0.657074H28.9907V1.65707Z",fill:"black"}),I.jsx("path",{d:"M30.3241 1.65707H31.3241V0.657074H30.3241V1.65707Z",fill:"black"}),I.jsx("path",{d:"M33.6575 1.65707H32.6575V0.657074H33.6575V1.65707Z",fill:"black"}),I.jsx("path",{d:"M34.9908 1.65707H35.9908V0.657074H34.9908V1.65707Z",fill:"black"}),I.jsx("path",{d:"M38.3242 1.65707H37.3242V0.657074H38.3242V1.65707Z",fill:"black"}),I.jsx("path",{d:"M39.6576 1.65707H40.6576V0.657074H39.6576V1.65707Z",fill:"black"}),I.jsx("path",{d:"M42.991 1.65707H41.991V0.657074H42.991V1.65707Z",fill:"black"}),I.jsx("path",{d:"M44.3243 1.65707H45.3243V0.657074H44.3243V1.65707Z",fill:"black"}),I.jsx("path",{d:"M47.6577 1.65707H46.6577V0.657074H47.6577V1.65707Z",fill:"black"}),I.jsx("path",{d:"M48.9911 1.65707H49.9911V0.657074H48.9911V1.65707Z",fill:"black"}),I.jsx("path",{d:"M52.3245 1.65707H51.3245V0.657074H52.3245V1.65707Z",fill:"black"}),I.jsx("path",{d:"M53.6578 1.65707H54.6578V0.657074H53.6578V1.65707Z",fill:"black"}),I.jsx("path",{d:"M56.9912 1.65707H55.9912V0.657074H56.9912V1.65707Z",fill:"black"}),I.jsx("path",{d:"M58.3246 1.65707H59.3246V0.657074H58.3246V1.65707Z",fill:"black"}),I.jsx("path",{d:"M61.658 1.65707H60.658V0.657074H61.658V1.65707Z",fill:"black"}),I.jsx("path",{d:"M62.9913 1.65707H63.9913V0.657074H62.9913V1.65707Z",fill:"black"}),I.jsx("path",{d:"M66.3247 1.65707H65.3247V0.657074H66.3247V1.65707Z",fill:"black"}),I.jsx("path",{d:"M67.6581 1.65707H68.6581V0.657074H67.6581V1.65707Z",fill:"black"}),I.jsx("path",{d:"M70.9915 1.65707H69.9915V0.657074H70.9915V1.65707Z",fill:"black"}),I.jsx("path",{d:"M72.3248 1.65707H73.3248V0.657074H72.3248V1.65707Z",fill:"black"}),I.jsx("path",{d:"M75.6582 1.65707H74.6582V0.657074H75.6582V1.65707Z",fill:"black"}),I.jsx("path",{d:"M76.9916 1.65707H77.9916V0.657074H76.9916V1.65707Z",fill:"black"}),I.jsx("path",{d:"M80.325 1.65707H79.325V0.657074H80.325V1.65707Z",fill:"black"}),I.jsx("path",{d:"M81.6583 1.65707H82.6583V0.657074H81.6583V1.65707Z",fill:"black"}),I.jsx("path",{d:"M84.9917 1.65707H83.9917V0.657074H84.9917V1.65707Z",fill:"black"}),I.jsx("path",{d:"M86.3251 1.65707H87.3251V0.657074H86.3251V1.65707Z",fill:"black"}),I.jsx("path",{d:"M89.6584 1.65707H88.6584V0.657074H89.6584V1.65707Z",fill:"black"}),I.jsx("path",{d:"M90.9918 1.65707H91.9918V0.657074H90.9918V1.65707Z",fill:"black"}),I.jsx("path",{d:"M94.3252 1.65707H93.3252V0.657074H94.3252V1.65707Z",fill:"black"}),I.jsx("path",{d:"M95.6586 1.65707H96.6586V0.657074H95.6586V1.65707Z",fill:"black"}),I.jsx("path",{d:"M98.9919 1.65707H97.9919V0.657074H98.9919V1.65707Z",fill:"black"}),I.jsx("path",{d:"M100.325 1.65707H101.325V0.657074H100.325V1.65707Z",fill:"black"}),I.jsx("path",{d:"M103.659 1.65707H102.659V0.657074H103.659V1.65707Z",fill:"black"}),I.jsx("path",{d:"M104.992 1.65707H105.992V0.657074H104.992V1.65707Z",fill:"black"}),I.jsx("path",{d:"M108.325 1.65707H107.325V0.657074H108.325V1.65707Z",fill:"black"}),I.jsx("path",{d:"M109.659 1.65707H110.659V0.657074H109.659V1.65707Z",fill:"black"}),I.jsx("path",{d:"M112.992 1.65707H111.992V0.657074H112.992V1.65707Z",fill:"black"}),I.jsx("path",{d:"M114.325 1.65707H115.325V0.657074H114.325V1.65707Z",fill:"black"}),I.jsx("path",{d:"M117.659 1.65707H116.659V0.657074H117.659V1.65707Z",fill:"black"}),I.jsx("path",{d:"M118.992 1.65707H119.992V0.657074H118.992V1.65707Z",fill:"black"})]}),kg=()=>I.jsx("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:I.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 2.42035H-0.0090332V0.420349H119.991V2.42035Z",fill:"black"})}),Vg=()=>I.jsxs("svg",{width:"120",height:"3",viewBox:"0 0 120 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.0100098 2.47614H1.98999V0.476135H-0.0100098V2.47614Z",fill:"black"}),I.jsx("path",{d:"M3.99014 2.47614H9.99014V0.476135H3.99014V2.47614Z",fill:"black"}),I.jsx("path",{d:"M13.9901 2.47614H11.9901V0.476135H13.9901V2.47614Z",fill:"black"}),I.jsx("path",{d:"M21.1904 2.47614H23.1904V0.476135H21.1904V2.47614Z",fill:"black"}),I.jsx("path",{d:"M31.1906 2.47614H25.1906V0.476135H31.1906V2.47614Z",fill:"black"}),I.jsx("path",{d:"M33.1906 2.47614H35.1906V0.476135H33.1906V2.47614Z",fill:"black"}),I.jsx("path",{d:"M44.3909 2.47614H42.3909V0.476135H44.3909V2.47614Z",fill:"black"}),I.jsx("path",{d:"M46.391 2.47614H52.391V0.476135H46.391V2.47614Z",fill:"black"}),I.jsx("path",{d:"M56.391 2.47614H54.391V0.476135H56.391V2.47614Z",fill:"black"}),I.jsx("path",{d:"M63.5913 2.47614H65.5913V0.476135H63.5913V2.47614Z",fill:"black"}),I.jsx("path",{d:"M73.5915 2.47614H67.5915V0.476135H73.5915V2.47614Z",fill:"black"}),I.jsx("path",{d:"M75.5915 2.47614H77.5915V0.476135H75.5915V2.47614Z",fill:"black"}),I.jsx("path",{d:"M86.7917 2.47614H84.7917V0.476135H86.7917V2.47614Z",fill:"black"}),I.jsx("path",{d:"M88.7919 2.47614H94.7919V0.476135H88.7919V2.47614Z",fill:"black"}),I.jsx("path",{d:"M98.7919 2.47614H96.7919V0.476135H98.7919V2.47614Z",fill:"black"}),I.jsx("path",{d:"M105.992 2.47614H107.992V0.476135H105.992V2.47614Z",fill:"black"}),I.jsx("path",{d:"M115.992 2.47614H109.992V0.476135H115.992V2.47614Z",fill:"black"}),I.jsx("path",{d:"M117.992 2.47614H119.992V0.476135H117.992V2.47614Z",fill:"black"})]}),Hg=()=>I.jsxs("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.0100098 2.00415H1.98999V0.00415039H-0.0100098V2.00415Z",fill:"black"}),I.jsx("path",{d:"M3.99014 2.00415H9.99014V0.00415039H3.99014V2.00415Z",fill:"black"}),I.jsx("path",{d:"M13.9901 2.00415H11.9901V0.00415039H13.9901V2.00415Z",fill:"black"}),I.jsx("path",{d:"M15.9901 2.00415H17.9901V0.00415039H15.9901V2.00415Z",fill:"black"}),I.jsx("path",{d:"M27.4905 2.00415H25.4905V0.00415039H27.4905V2.00415Z",fill:"black"}),I.jsx("path",{d:"M29.4906 2.00415H35.4906V0.00415039H29.4906V2.00415Z",fill:"black"}),I.jsx("path",{d:"M39.4906 2.00415H37.4906V0.00415039H39.4906V2.00415Z",fill:"black"}),I.jsx("path",{d:"M41.4906 2.00415H43.4906V0.00415039H41.4906V2.00415Z",fill:"black"}),I.jsx("path",{d:"M52.991 2.00415H50.991V0.00415039H52.991V2.00415Z",fill:"black"}),I.jsx("path",{d:"M54.9911 2.00415H60.9911V0.00415039H54.9911V2.00415Z",fill:"black"}),I.jsx("path",{d:"M64.9911 2.00415H62.9911V0.00415039H64.9911V2.00415Z",fill:"black"}),I.jsx("path",{d:"M66.9911 2.00415H68.9911V0.00415039H66.9911V2.00415Z",fill:"black"}),I.jsx("path",{d:"M78.4915 2.00415H76.4915V0.00415039H78.4915V2.00415Z",fill:"black"}),I.jsx("path",{d:"M80.4916 2.00415H86.4916V0.00415039H80.4916V2.00415Z",fill:"black"}),I.jsx("path",{d:"M90.4916 2.00415H88.4916V0.00415039H90.4916V2.00415Z",fill:"black"}),I.jsx("path",{d:"M92.4916 2.00415H94.4916V0.00415039H92.4916V2.00415Z",fill:"black"}),I.jsx("path",{d:"M103.992 2.00415H101.992V0.00415039H103.992V2.00415Z",fill:"black"}),I.jsx("path",{d:"M105.992 2.00415H111.992V0.00415039H105.992V2.00415Z",fill:"black"}),I.jsx("path",{d:"M115.992 2.00415H113.992V0.00415039H115.992V2.00415Z",fill:"black"}),I.jsx("path",{d:"M117.992 2.00415H119.992V0.00415039H117.992V2.00415Z",fill:"black"})]}),Wg=()=>I.jsxs("svg",{width:"118",height:"3",viewBox:"0 0 118 3",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[I.jsx("path",{d:"M-0.00854492 2.94815H1.99146V0.948151H-0.00854492V2.94815Z",fill:"black"}),I.jsx("path",{d:"M6.09668 2.94815H8.09668V0.948151H6.09668V2.94815Z",fill:"black"}),I.jsx("path",{d:"M14.2019 2.94815H12.2019V0.948151H14.2019V2.94815Z",fill:"black"}),I.jsx("path",{d:"M18.3071 2.94815H20.3071V0.948151H18.3071V2.94815Z",fill:"black"}),I.jsx("path",{d:"M26.4124 2.94815H24.4124V0.948151H26.4124V2.94815Z",fill:"black"}),I.jsx("path",{d:"M30.5176 2.94815H32.5176V0.948151H30.5176V2.94815Z",fill:"black"}),I.jsx("path",{d:"M38.6228 2.94815H36.6228V0.948151H38.6228V2.94815Z",fill:"black"}),I.jsx("path",{d:"M42.728 2.94815H44.728V0.948151H42.728V2.94815Z",fill:"black"}),I.jsx("path",{d:"M50.8333 2.94815H48.8333V0.948151H50.8333V2.94815Z",fill:"black"}),I.jsx("path",{d:"M54.9385 2.94815H56.9385V0.948151H54.9385V2.94815Z",fill:"black"}),I.jsx("path",{d:"M63.0437 2.94815H61.0437V0.948151H63.0437V2.94815Z",fill:"black"}),I.jsx("path",{d:"M67.1489 2.94815H69.1489V0.948151H67.1489V2.94815Z",fill:"black"}),I.jsx("path",{d:"M75.2542 2.94815H73.2542V0.948151H75.2542V2.94815Z",fill:"black"}),I.jsx("path",{d:"M79.3594 2.94815H81.3594V0.948151H79.3594V2.94815Z",fill:"black"}),I.jsx("path",{d:"M87.4645 2.94815H85.4645V0.948151H87.4645V2.94815Z",fill:"black"}),I.jsx("path",{d:"M91.5697 2.94815H93.5697V0.948151H91.5697V2.94815Z",fill:"black"}),I.jsx("path",{d:"M99.6749 2.94815H97.6749V0.948151H99.6749V2.94815Z",fill:"black"}),I.jsx("path",{d:"M103.78 2.94815H105.78V0.948151H103.78V2.94815Z",fill:"black"}),I.jsx("path",{d:"M111.885 2.94815H109.885V0.948151H111.885V2.94815Z",fill:"black"}),I.jsx("path",{d:"M115.991 2.94815H117.991V0.948151H115.991V2.94815Z",fill:"black"})]}),Ug=()=>I.jsx("svg",{width:"120",height:"4",viewBox:"0 0 120 4",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:I.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 3.86215H-0.0090332V0.862152H119.991V3.86215Z",fill:"black"})}),Ca=()=>I.jsx("svg",{width:"120",height:"2",viewBox:"0 0 120 2",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:I.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M119.991 1.15668H-0.0090332V0.156677H119.991V1.15668Z",fill:"black"})});function Ia(n){const{type:r=a.BorderStyleTypes.THIN}=n;switch(r){case a.BorderStyleTypes.DASH_DOT:return I.jsx(xg,{});case a.BorderStyleTypes.DASH_DOT_DOT:return I.jsx(Ag,{});case a.BorderStyleTypes.DASHED:return I.jsx(Ng,{});case a.BorderStyleTypes.HAIR:return I.jsx(Dg,{});case a.BorderStyleTypes.MEDIUM:return I.jsx(kg,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT:return I.jsx(Vg,{});case a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT:return I.jsx(Hg,{});case a.BorderStyleTypes.MEDIUM_DASHED:return I.jsx(Wg,{});case a.BorderStyleTypes.THICK:return I.jsx(Ug,{});case a.BorderStyleTypes.THIN:return I.jsx(Ca,{});default:return I.jsx(Ca,{})}}const Lg="univer-ui-plugin-sheets-border-panel",Bg="univer-ui-plugin-sheets-border-panel-position",Fg="univer-ui-plugin-sheets-border-panel-position-item",jg="univer-ui-plugin-sheets-border-panel-position-item-active",zg="univer-ui-plugin-sheets-border-panel-styles",Xg="univer-ui-plugin-sheets-border-panel-board",Yg="univer-ui-plugin-sheets-border-panel-button",Gg="univer-ui-plugin-sheets-border-panel-more-icon",Le={uiPluginSheetsBorderPanel:Lg,uiPluginSheetsBorderPanelPosition:Bg,uiPluginSheetsBorderPanelPositionItem:Fg,uiPluginSheetsBorderPanelPositionItemActive:jg,uiPluginSheetsBorderPanelStyles:zg,uiPluginSheetsBorderPanelBoard:Xg,uiPluginSheetsBorderPanelButton:Yg,uiPluginSheetsBorderPanelMoreIcon:Gg},xs=`${An}_BORDER_PANEL_COMPONENT`,jl=[{label:"borderLine.borderTop",icon:"UpBorder",value:"top"},{label:"borderLine.borderBottom",icon:"DownBorder",value:"bottom"},{label:"borderLine.borderLeft",icon:"LeftBorder",value:"left"},{label:"borderLine.borderRight",icon:"RightBorder",value:"right"},{label:"borderLine.borderNone",icon:"NoBorderSingle",value:"none"},{label:"borderLine.borderAll",icon:"AllBorderSingle",value:"all"},{label:"borderLine.borderOutside",icon:"OuterBorder",value:"outside"},{label:"borderLine.borderInside",icon:"InnerBorder",value:"inside"},{label:"borderLine.borderHorizontal",icon:"HorizontalBorder",value:"horizontal"},{label:"borderLine.borderVertical",icon:"VerticalBorder",value:"vertical"},{label:"borderLine.borderTlbr",icon:"BackSlashSingle",value:"tlbr"},{label:"borderLine.borderTlbcTlmr",icon:"LeftDoubleDiagonalSingle",value:"tlbc_tlmr"},{label:"borderLine.borderTlbrTlbcTlmr",icon:"LeftTridiagonalSingle",value:"tlbr_tlbc_tlmr"},{label:"borderLine.borderBlTr",icon:"SlashSingle",value:"bltr"},{label:"borderLine.borderMltrBctr",icon:"RightDoubleDiagonalSingle",value:"mltr_bctr"}],Zg=[{label:a.BorderStyleTypes.THIN,value:a.BorderStyleTypes.THIN},{label:a.BorderStyleTypes.HAIR,value:a.BorderStyleTypes.HAIR},{label:a.BorderStyleTypes.DOTTED,value:a.BorderStyleTypes.DOTTED},{label:a.BorderStyleTypes.DASHED,value:a.BorderStyleTypes.DASHED},{label:a.BorderStyleTypes.DASH_DOT,value:a.BorderStyleTypes.DASH_DOT},{label:a.BorderStyleTypes.DASH_DOT_DOT,value:a.BorderStyleTypes.DASH_DOT_DOT},{label:a.BorderStyleTypes.MEDIUM,value:a.BorderStyleTypes.MEDIUM},{label:a.BorderStyleTypes.MEDIUM_DASHED,value:a.BorderStyleTypes.MEDIUM_DASHED},{label:a.BorderStyleTypes.MEDIUM_DASH_DOT,value:a.BorderStyleTypes.MEDIUM_DASH_DOT},{label:a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT,value:a.BorderStyleTypes.MEDIUM_DASH_DOT_DOT},{label:a.BorderStyleTypes.THICK,value:a.BorderStyleTypes.THICK}];function zl(n){var c;const r=a.useDependency(R.ComponentManager),e=a.useDependency(m.BorderStyleManagerService),{onChange:t,value:i}=n;function o(d,u){t==null||t({...i,[u]:d})}function s(d){const u=r.get(d);return u&&I.jsx(u,{extend:{colorChannel1:"rgb(var(--primary-color))"}})}function l(d){d.stopPropagation()}return I.jsxs("section",{className:Le.uiPluginSheetsBorderPanel,children:[I.jsx("div",{className:Le.uiPluginSheetsBorderPanelPosition,children:jl.map(d=>I.jsx("div",{className:e.getBorderInfo().type===d.value?`
21
21
  ${Le.uiPluginSheetsBorderPanelPositionItemActive}
22
22
  ${Le.uiPluginSheetsBorderPanelPositionItem}
23
- `:Le.uiPluginSheetsBorderPanelPositionItem,onClick:u=>{u.stopPropagation(),o(d.value,"type")},children:s(d.icon)},d.value))}),I.jsxs("div",{className:Le.uiPluginSheetsBorderPanelStyles,children:[I.jsx("div",{children:I.jsx(K.DropdownLegacy,{align:{offset:[0,18]},overlay:I.jsx("section",{className:Le.uiPluginSheetsBorderPanelBoard,onClick:l,children:I.jsx(K.ColorPicker,{onChange:d=>o(d,"color")})}),children:I.jsxs("a",{className:Le.uiPluginSheetsBorderPanelButton,onClick:l,children:[I.jsx(Ol,{extend:{colorChannel1:(c=i==null?void 0:i.color)!=null?c:"rgb(var(--primary-color))"}}),I.jsx("span",{className:Le.uiPluginSheetsBorderPanelMoreIcon,children:I.jsx(Tn,{})})]})})}),I.jsx("div",{children:I.jsx(K.DropdownLegacy,{align:{offset:[0,18]},overlay:I.jsx("section",{onClick:l,children:I.jsx(K.Menu,{children:Zg.map(d=>I.jsx(K.MenuItem,{eventKey:d.value.toString(),onClick:()=>o(d.value,"style"),children:I.jsx(Ia,{type:d.value})},d.value))})}),children:I.jsxs("a",{className:Le.uiPluginSheetsBorderPanelButton,onClick:l,children:[I.jsx(Ia,{type:a.BorderStyleTypes.THIN}),I.jsx("span",{className:Le.uiPluginSheetsBorderPanelMoreIcon,children:I.jsx(Tn,{})})]})})})]})]})}function Xl(n){var r,e,t="";if(typeof n=="string"||typeof n=="number")t+=n;else if(typeof n=="object")if(Array.isArray(n)){var i=n.length;for(r=0;r<i;r++)n[r]&&(e=Xl(n[r]))&&(t&&(t+=" "),t+=e)}else for(e in n)n[e]&&(t&&(t+=" "),t+=e);return t}function fe(){for(var n,r,e=0,t="",i=arguments.length;e<i;e++)(n=arguments[e])&&(r=Xl(n))&&(t&&(t+=" "),t+=r);return t}const Kg="univer-defined-name",qg="univer-defined-name-overlay",Qg="univer-defined-name-overlay-container",Jg="univer-defined-name-overlay-item",$g="univer-defined-name-overlay-item-name",eS="univer-defined-name-overlay-item-name-for-sheet",tS="univer-defined-name-overlay-item-formula",nS="univer-defined-name-overlay-manager",iS="univer-defined-name-overlay-manager-title",rS="univer-defined-name-overlay-manager-content",oS="univer-defined-name-container",sS="univer-defined-name-container-scroll",aS="univer-defined-name-container-addButton",lS="univer-defined-name-container-addButton-text",cS="univer-defined-name-container-item",dS="univer-defined-name-container-item-name",uS="univer-defined-name-container-item-name-for-sheet",hS="univer-defined-name-container-item-formula-or-refString",mS="univer-defined-name-container-item-update",gS="univer-defined-name-container-item-delete",SS="univer-defined-name-container-item-show",fS="univer-defined-name-input",pS="univer-defined-name-input-formula-selector-text-wrap",vS="univer-defined-name-input-text-editor-container",CS="univer-defined-name-input-validation",IS="univer-defined-name-input-disable",Te={definedName:Kg,definedNameOverlay:qg,definedNameOverlayContainer:Qg,definedNameOverlayItem:Jg,definedNameOverlayItemName:$g,definedNameOverlayItemNameForSheet:eS,definedNameOverlayItemFormula:tS,definedNameOverlayManager:nS,definedNameOverlayManagerTitle:iS,definedNameOverlayManagerContent:rS,definedNameContainer:oS,definedNameContainerScroll:sS,definedNameContainerAddButton:aS,definedNameContainerAddButtonText:lS,definedNameContainerItem:cS,definedNameContainerItemName:dS,definedNameContainerItemNameForSheet:uS,definedNameContainerItemFormulaOrRefString:hS,definedNameContainerItemUpdate:mS,definedNameContainerItemDelete:gS,definedNameContainerItemShow:SS,definedNameInput:fS,definedNameInputFormulaSelectorTextWrap:pS,definedNameInputTextEditorContainer:vS,definedNameInputValidation:CS,definedNameInputDisable:IS},so={width:"100%"},_a=n=>{const{inputId:r,state:e=!1,type:t="range",confirm:i,cancel:o,name:s,formulaOrRefString:l,comment:c="",localSheetId:d=m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,hidden:u=!1,id:h}=n,S=a.useDependency(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),f=a.useDependency(a.LocaleService),p=a.useDependency(G.IDefinedNamesService),v=a.useDependency(G.IFunctionService),C=a.useDependency(G.LexerTreeBuilder),_=a.useDependency(R.ComponentManager),b=H.useMemo(()=>_.get(os),[]),E=H.useMemo(()=>_.get(br),[]);if(S==null)return;const M=H.useMemo(()=>S.getUnitId(),[]),w=H.useMemo(()=>S.getActiveSheet().getSheetId(),[]),[P,x]=H.useState(s),[A,N]=H.useState(l),[D,k]=H.useState(c),[B,V]=H.useState(d),[U,F]=H.useState(""),[L,W]=H.useState(t),[j,z]=H.useState(!0),Z=H.useRef({}),[te,q]=H.useState(!1),ie=[{label:f.t("definedName.scopeWorkbook"),value:m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}],oe=re=>!G.isReferenceStrings(re);H.useEffect(()=>{q(!1)},[w]),H.useEffect(()=>{z(!0),x(s),k(c),V(d);let re=l;l.substring(0,1)===G.operatorToken.EQUALS?W("formula"):oe(l)?(W("formula"),re=G.operatorToken.EQUALS+l):W("range"),N(re),F("")},[e]),S.getSheetOrders().forEach(re=>{const le=S.getSheetBySheetId(re);ie.push({label:(le==null?void 0:le.getName())||"",value:re})});const X=re=>{N(re)},Y=re=>{N(re||"")},Q=()=>{if(P.length===0){F(f.t("definedName.nameEmpty"));return}if(p.getValueByName(M,P)!=null&&(h==null||h.length===0)){F(f.t("definedName.nameDuplicate"));return}if(!a.Tools.isValidParameter(P)||G.isReferenceStringWithEffectiveColumn(P)||!a.Tools.isStartValidPosition(P)&&!y.hasCJKText(P.substring(0,1))){F(f.t("definedName.nameInvalid"));return}if(S.getSheetOrders().map(Re=>{var Ee;return((Ee=S.getSheetBySheetId(Re))==null?void 0:Ee.getName())||""}).includes(P)){F(f.t("definedName.nameSheetConflict"));return}if(A.length===0){F(f.t("definedName.formulaOrRefStringEmpty"));return}if(!j){F(f.t("definedName.formulaOrRefStringInvalid"));return}if(v.hasExecutor(P.toUpperCase())){F(f.t("definedName.nameConflict"));return}const le=S.getActiveSheet().getName();i&&i({id:h||"",name:P,formulaOrRefString:C.convertRefersToAbsolute(A,a.AbsoluteRefType.ALL,a.AbsoluteRefType.ALL,le),comment:D,localSheetId:B})},ne=re=>{const le=re;le==="formula"?l[0]===G.operatorToken.EQUALS?N(l):N(`${G.operatorToken.EQUALS}`):l[0]===G.operatorToken.EQUALS?N(""):N(l),W(le)},ue=H.useRef({}),[pe,de]=H.useState(!1);return R.useSidebarClick(re=>{var Re;const le=(Re=Z.current)==null?void 0:Re.handleOutClick;le&&le(re,()=>q(!1))}),R.useSidebarClick(re=>{var Re;const le=(Re=ue.current)==null?void 0:Re.handleOutClick;le&&le(re,()=>de(!1))}),I.jsxs("div",{className:Te.definedNameInput,style:{display:e?"block":"none"},children:[I.jsx("div",{children:I.jsx(K.Input,{placeholder:f.t("definedName.inputNamePlaceholder"),value:P,allowClear:!0,onChange:x,affixWrapperStyle:so})}),I.jsx("div",{children:I.jsxs(K.RadioGroup,{value:L,onChange:ne,children:[I.jsx(K.Radio,{value:"range",children:f.t("definedName.ratioRange")}),I.jsx(K.Radio,{value:"formula",children:f.t("definedName.ratioFormula")})]})}),L==="range"?b&&I.jsx(b,{unitId:M,subUnitId:w,initValue:A,onChange:X,isFocus:te,onFocus:()=>q(!0),actions:Z.current,isSupportAcrossSheet:!0}):E&&I.jsx(E,{initValue:A,unitId:M,subUnitId:w,isFocus:pe,isSupportAcrossSheet:!0,onChange:(re="")=>{Y(re||"")},onVerify:re=>{z(re)},onFocus:()=>de(!0),actions:ue.current}),I.jsx("div",{children:I.jsx(K.Select,{style:so,value:B,options:ie,onChange:V})}),I.jsx("div",{children:I.jsx(K.Input,{affixWrapperStyle:so,placeholder:f.t("definedName.inputCommentPlaceholder"),value:D,onChange:k})}),I.jsxs("div",{style:{display:U.length===0?"none":"flex"},className:Te.definedNameInputValidation,children:[I.jsx("span",{children:U}),I.jsx(bs,{})]}),I.jsxs("div",{children:[I.jsx(K.Button,{onClick:()=>{o&&o()},children:f.t("definedName.cancel")}),I.jsx(K.Button,{style:{marginLeft:15},type:"primary",onClick:Q,children:f.t("definedName.confirm")})]})]})},Yl=()=>{const n=a.useDependency(a.ICommandService),e=a.useDependency(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),t=a.useDependency(a.LocaleService),i=a.useDependency(G.IDefinedNamesService),o=a.useDependency(m.SheetsSelectionsService);if(e==null)return;const s=e.getUnitId(),l=()=>{const D=i.getDefinedNameMap(s);return D?Array.from(Object.values(D)):[]},[c,d]=H.useState(!1),[u,h]=H.useState(l()),[g,S]=H.useState(null),[f,p]=H.useState();H.useEffect(()=>{const D=i.update$.subscribe(()=>{h(l())});return()=>{D.unsubscribe()}},[]);const v=D=>{const{name:k,formulaOrRefString:B,comment:V,localSheetId:U,hidden:F}=D;let L=D.id;if(L==null||L.length===0)L=a.Tools.generateRandomId(10),n.executeCommand(m.InsertDefinedNameCommand.id,{id:L,unitId:s,name:k,formulaOrRefString:B,comment:V,localSheetId:U,hidden:F});else{const W={id:L,unitId:s,name:k,formulaOrRefString:B,comment:V,localSheetId:U,hidden:F};n.executeCommand(m.SetDefinedNameCommand.id,W)}d(!1),S(null)},C=D=>{p(D)};function _(){p(null)}function b(D){const k=i.getValueById(s,D);n.executeCommand(m.RemoveDefinedNameCommand.id,{...k,unitId:s}),p(null)}const E=async D=>{const{formulaOrRefString:k,id:B}=D,V=i.getWorksheetByRef(s,k);if(!V)return;V.isSheetHidden()&&await n.executeCommand(m.SetWorksheetShowCommand.id,{unitId:s,subUnitId:V.getSheetId()}),i.focusRange(s,B)},M=()=>{const D=u.length+1,k=t.t("definedName.defaultName")+D;if(i.getValueByName(s,k)==null)return k;let B=D+1;for(;;){const V=t.t("definedName.defaultName")+B;if(i.getValueByName(s,V)==null)return V;B++}},w=()=>{var V;const D=(V=e.getActiveSheet())==null?void 0:V.getName();if(!D)return"";const k=o.getCurrentSelections();return k==null?"":k.map(U=>G.serializeRangeWithSheet(D,U.range)).join(",")},P=()=>{d(!1),S(null)},x=()=>{d(!0),S(null)},A=D=>{d(!1),S(D)},N=D=>{const k=e.getSheetBySheetId(D);return k==null?"":k.getName()};return I.jsx("div",{className:Te.definedNameContainer,children:I.jsxs("div",{className:Te.definedNameContainerScroll,children:[I.jsxs("div",{children:[I.jsxs("div",{onClick:x,className:Te.definedNameContainerAddButton,style:{display:c?"none":"flex"},children:[I.jsx(Rs,{}),I.jsx("span",{className:Te.definedNameContainerAddButtonText,children:t.t("definedName.addButton")})]}),c&&I.jsx(_a,{confirm:v,cancel:P,state:c,inputId:"insertDefinedName",name:M(),formulaOrRefString:w()})]},"insertDefinedName"),u.map((D,k)=>I.jsxs("div",{children:[I.jsxs("div",{onClick:()=>{E(D)},className:Te.definedNameContainerItem,style:{display:D.id===g?"none":"flex"},children:[I.jsxs("div",{title:D.comment,children:[I.jsxs("div",{className:Te.definedNameContainerItemName,children:[D.name,I.jsx("span",{className:Te.definedNameContainerItemNameForSheet,children:D.localSheetId===m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME||D.localSheetId==null?"":N(D.localSheetId)})]}),I.jsx("div",{className:Te.definedNameContainerItemFormulaOrRefString,children:D.formulaOrRefString})]}),I.jsx(K.Tooltip,{title:t.t("definedName.updateButton"),placement:"top",children:I.jsx("div",{className:fe(Te.definedNameContainerItemUpdate,Te.definedNameContainerItemShow),onClick:()=>{A(D.id)},children:I.jsx(ht,{})})}),I.jsx(K.Tooltip,{title:t.t("definedName.deleteButton"),placement:"top",children:I.jsx("div",{className:fe(Te.definedNameContainerItemDelete,Te.definedNameContainerItemShow),onClick:()=>{C(D.id)},children:I.jsx(Dr,{})})})]}),I.jsx(K.Confirm,{visible:f===D.id,onClose:_,onConfirm:()=>{b(D.id)},children:t.t("definedName.deleteConfirmText")}),D.id===g&&I.jsx(_a,{confirm:v,cancel:P,state:D.id===g,id:D.id,inputId:D.id+k,name:D.name,formulaOrRefString:D.formulaOrRefString,comment:D.comment,localSheetId:D.localSheetId})]},k))]})})},_S="univer-count-bar",bS={countBar:_S},RS=[50,75,100,125,150,175,200,400];function ES(){const n=a.useDependency(a.ICommandService),r=a.useDependency(a.IUniverInstanceService),e=Je(),t=a.useDependency(he),i=a.useObservable(t.visible$),o=H.useCallback(()=>{if(!e)return 100;const u=e.getActiveSheet(),h=u&&u.getZoomRatio()*100||100;return Math.round(h)},[e]),[s,l]=H.useState(()=>o());H.useEffect(()=>(l(o()),n.onCommandExecuted(h=>{if(h.id===ze.id||h.id===m.SetWorksheetActiveOperation.id){const g=o();l(g)}}).dispose),[n,o]);function c(u){l(u);const h=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),g=h==null?void 0:h.getActiveSheet();if(g==null)return;const S=u/100;n.executeCommand(On.id,{unitId:h.getUnitId(),subUnitId:g.getSheetId(),zoomRatio:S})}const d=(i==null?void 0:i.visible)&&(i.unitId===(e==null?void 0:e.getUnitId())||i.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);return I.jsx(K.Slider,{disabled:d,min:Oo[0],value:s,shortcuts:RS,onChange:c})}function TS(n){return I.jsx("section",{className:bS.countBar,children:I.jsx(ES,{})})}function Gl(n,r){const e=a.useDependency(he);return H.useMemo(()=>({keyCodes:[{keyCode:R.KeyCode.ENTER},{keyCode:R.KeyCode.ESC},{keyCode:R.KeyCode.TAB}],handler:i=>{(i===R.KeyCode.ENTER||i===R.KeyCode.ESC||i===R.KeyCode.TAB)&&(e.disableForceKeepVisible(),e.changeVisible({visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:i,unitId:r}))}}),[e,r])}const wS="univer-editor-container",yS="univer-editor-input",MS="univer-sheet-embedding-formula-editor-wrap",ba={editorContainer:wS,editorInput:yS,sheetEmbeddingFormulaEditorWrap:MS},ir=-1e3,Ra={width:0,height:0,top:ir,left:ir},PS=()=>{const[n,r]=H.useState({...Ra}),e=a.useDependency(ui),t=a.useDependency(J.IEditorService),i=a.useDependency(a.IContextService),o=a.useDependency(R.ComponentManager),s=a.useDependency(he),l=R.useObservable(s.visible$),c=a.useDependency(a.ICommandService),d=H.useRef(0),u=R.useObservable(()=>i.subscribeContextValue$(R.DISABLE_AUTO_FOCUS_KEY),!1,void 0,[i,R.DISABLE_AUTO_FOCUS_KEY]),h=o.get(br),g=s.getEditLocation();H.useEffect(()=>{const v=e.state$.subscribe(C=>{if(C==null)return;const{startX:_=ir,startY:b=ir,endX:E=0,endY:M=0,show:w=!1}=C;if(!w)r({...Ra});else{r({width:E-_,height:M-b,left:_,top:b});const P=t.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(P==null)return;const{left:x,top:A,width:N,height:D}=P.getBoundingClientRect();e.setRect({left:x,top:A,width:N,height:D})}});return()=>{v.unsubscribe()}},[]),H.useEffect(()=>{u||e.setFocus(!0)},[u,n]);const S=R.useEvent(()=>{s.isVisible().visible&&s.changeVisible({visible:!1,eventType:y.DeviceInputEventType.PointerUp,unitId:g.unitId})});R.useSidebarClick(S);const f=Gl(d,g==null?void 0:g.unitId),p=R.useEvent((v,C)=>{c.executeCommand(Ft.id,{keycode:v,visible:!1,eventType:y.DeviceInputEventType.Keyboard,isShift:C===R.MetaKeys.SHIFT||C===(R.MetaKeys.CTRL_COMMAND|R.MetaKeys.SHIFT),unitId:g==null?void 0:g.unitId})});return I.jsx("div",{className:ba.editorContainer,style:{left:n.left,top:n.top,width:n.width,height:n.height},children:h&&I.jsx(h,{editorId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,className:ba.editorInput,initValue:"",onChange:()=>{},isFocus:l==null?void 0:l.visible,unitId:g==null?void 0:g.unitId,subUnitId:g==null?void 0:g.sheetId,keyboradEventConfig:f,onMoveInEditor:p,isSupportAcrossSheet:!0,resetSelectionOnBlur:!1,isSingle:!1,autoScrollbar:!1,onFormulaSelectingChange:v=>{d.current=v,v?s.enableForceKeepVisible():s.disableForceKeepVisible()},disableSelectionOnClick:!0})})};class OS{constructor(){T(this,"_position",null);T(this,"_position$",new O.BehaviorSubject(null));T(this,"position$",this._position$.asObservable());T(this,"_focus",!1);T(this,"_focus$",new O.BehaviorSubject(this._focus));T(this,"focus$",this._focus$.asObservable());T(this,"_fxBtnClick$",new O.Subject);T(this,"fxBtnClick$",this._fxBtnClick$.asObservable());T(this,"_foldBtnStatus$",new O.Subject);T(this,"foldBtnStatus$",this._foldBtnStatus$.asObservable())}dispose(){this._position$.complete(),this._focus$.complete(),this._position=null,this._focus=!1}setPosition(r){this._position=r,this._refresh(r)}getPosition(){return this._position}setFocus(r=!1){this._focus=r,this._focus$.next(r)}handleFxBtnClick(r){this._fxBtnClick$.next(r)}handleFoldBtnClick(r){this._foldBtnStatus$.next(r)}_refresh(r){this._position$.next(r)}}const xi=a.createIdentifier("univer.sheet-formula-editor-manager.service");function xS(n){const r=a.useDependency(a.ICommandService),e=a.useDependency(a.LocaleService),t=a.useDependency(G.IDefinedNamesService),i=a.useDependency(a.IUniverInstanceService),o=a.useDependency(R.ISidebarService),l=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),c=()=>{const S=t.getDefinedNameMap(l);return S?Array.from(Object.values(S)):[]},[d,u]=H.useState(c());H.useEffect(()=>{const S=t.update$.subscribe(()=>{u(c())});return()=>{S.unsubscribe()}},[]),H.useEffect(()=>{const S=o.sidebarOptions$.subscribe(f=>{f.id===ni&&(f.visible||setTimeout(()=>{o.sidebarOptions$.next({visible:!1})}))});return()=>{S.unsubscribe()}},[]);const h=()=>{r.executeCommand(Vr.id,{value:"open"})},g=async S=>{const{formulaOrRefString:f,id:p}=S,v=t.getWorksheetByRef(l,f);if(!v)return;v.isSheetHidden()&&await r.executeCommand(m.SetWorksheetShowCommand.id,{unitId:l,subUnitId:v.getSheetId()}),t.focusRange(l,p)};return I.jsxs("div",{className:"univer-w-[300px]",children:[I.jsx("ul",{className:`
23
+ `:Le.uiPluginSheetsBorderPanelPositionItem,onClick:u=>{u.stopPropagation(),o(d.value,"type")},children:s(d.icon)},d.value))}),I.jsxs("div",{className:Le.uiPluginSheetsBorderPanelStyles,children:[I.jsx("div",{children:I.jsx(K.DropdownLegacy,{align:{offset:[0,18]},overlay:I.jsx("section",{className:Le.uiPluginSheetsBorderPanelBoard,onClick:l,children:I.jsx(K.ColorPicker,{onChange:d=>o(d,"color")})}),children:I.jsxs("a",{className:Le.uiPluginSheetsBorderPanelButton,onClick:l,children:[I.jsx(Ol,{extend:{colorChannel1:(c=i==null?void 0:i.color)!=null?c:"rgb(var(--primary-color))"}}),I.jsx("span",{className:Le.uiPluginSheetsBorderPanelMoreIcon,children:I.jsx(Tn,{})})]})})}),I.jsx("div",{children:I.jsx(K.DropdownLegacy,{align:{offset:[0,18]},overlay:I.jsx("section",{onClick:l,children:I.jsx(K.Menu,{children:Zg.map(d=>I.jsx(K.MenuItem,{eventKey:d.value.toString(),onClick:()=>o(d.value,"style"),children:I.jsx(Ia,{type:d.value})},d.value))})}),children:I.jsxs("a",{className:Le.uiPluginSheetsBorderPanelButton,onClick:l,children:[I.jsx(Ia,{type:a.BorderStyleTypes.THIN}),I.jsx("span",{className:Le.uiPluginSheetsBorderPanelMoreIcon,children:I.jsx(Tn,{})})]})})})]})]})}function Xl(n){var r,e,t="";if(typeof n=="string"||typeof n=="number")t+=n;else if(typeof n=="object")if(Array.isArray(n)){var i=n.length;for(r=0;r<i;r++)n[r]&&(e=Xl(n[r]))&&(t&&(t+=" "),t+=e)}else for(e in n)n[e]&&(t&&(t+=" "),t+=e);return t}function fe(){for(var n,r,e=0,t="",i=arguments.length;e<i;e++)(n=arguments[e])&&(r=Xl(n))&&(t&&(t+=" "),t+=r);return t}const Kg="univer-defined-name",qg="univer-defined-name-overlay",Qg="univer-defined-name-overlay-container",Jg="univer-defined-name-overlay-item",$g="univer-defined-name-overlay-item-name",eS="univer-defined-name-overlay-item-name-for-sheet",tS="univer-defined-name-overlay-item-formula",nS="univer-defined-name-overlay-manager",iS="univer-defined-name-overlay-manager-title",rS="univer-defined-name-overlay-manager-content",oS="univer-defined-name-container",sS="univer-defined-name-container-scroll",aS="univer-defined-name-container-addButton",lS="univer-defined-name-container-addButton-text",cS="univer-defined-name-container-item",dS="univer-defined-name-container-item-name",uS="univer-defined-name-container-item-name-for-sheet",hS="univer-defined-name-container-item-formula-or-refString",mS="univer-defined-name-container-item-update",gS="univer-defined-name-container-item-delete",SS="univer-defined-name-container-item-show",fS="univer-defined-name-input",pS="univer-defined-name-input-formula-selector-text-wrap",vS="univer-defined-name-input-text-editor-container",CS="univer-defined-name-input-validation",IS="univer-defined-name-input-disable",Te={definedName:Kg,definedNameOverlay:qg,definedNameOverlayContainer:Qg,definedNameOverlayItem:Jg,definedNameOverlayItemName:$g,definedNameOverlayItemNameForSheet:eS,definedNameOverlayItemFormula:tS,definedNameOverlayManager:nS,definedNameOverlayManagerTitle:iS,definedNameOverlayManagerContent:rS,definedNameContainer:oS,definedNameContainerScroll:sS,definedNameContainerAddButton:aS,definedNameContainerAddButtonText:lS,definedNameContainerItem:cS,definedNameContainerItemName:dS,definedNameContainerItemNameForSheet:uS,definedNameContainerItemFormulaOrRefString:hS,definedNameContainerItemUpdate:mS,definedNameContainerItemDelete:gS,definedNameContainerItemShow:SS,definedNameInput:fS,definedNameInputFormulaSelectorTextWrap:pS,definedNameInputTextEditorContainer:vS,definedNameInputValidation:CS,definedNameInputDisable:IS},so={width:"100%"},_a=n=>{const{inputId:r,state:e=!1,type:t="range",confirm:i,cancel:o,name:s,formulaOrRefString:l,comment:c="",localSheetId:d=m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME,hidden:u=!1,id:h}=n,S=a.useDependency(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),f=a.useDependency(a.LocaleService),p=a.useDependency(G.IDefinedNamesService),v=a.useDependency(G.IFunctionService),C=a.useDependency(G.LexerTreeBuilder),_=a.useDependency(R.ComponentManager),b=H.useMemo(()=>_.get(os),[]),E=H.useMemo(()=>_.get(br),[]);if(S==null)return;const M=H.useMemo(()=>S.getUnitId(),[]),w=H.useMemo(()=>S.getActiveSheet().getSheetId(),[]),[P,x]=H.useState(s),[A,N]=H.useState(l),[D,k]=H.useState(c),[B,V]=H.useState(d),[U,F]=H.useState(""),[L,W]=H.useState(t),[j,z]=H.useState(!0),Z=H.useRef({}),[te,q]=H.useState(!1),ie=[{label:f.t("definedName.scopeWorkbook"),value:m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME}],oe=re=>!G.isReferenceStrings(re);H.useEffect(()=>{q(!1)},[w]),H.useEffect(()=>{z(!0),x(s),k(c),V(d);let re=l;l.substring(0,1)===G.operatorToken.EQUALS?W("formula"):oe(l)?(W("formula"),re=G.operatorToken.EQUALS+l):W("range"),N(re),F("")},[e]),S.getSheetOrders().forEach(re=>{const le=S.getSheetBySheetId(re);ie.push({label:(le==null?void 0:le.getName())||"",value:re})});const X=re=>{N(re)},Y=re=>{N(re||"")},Q=()=>{if(P.length===0){F(f.t("definedName.nameEmpty"));return}if(p.getValueByName(M,P)!=null&&(h==null||h.length===0)){F(f.t("definedName.nameDuplicate"));return}if(!a.Tools.isValidParameter(P)||G.isReferenceStringWithEffectiveColumn(P)||!a.Tools.isStartValidPosition(P)&&!y.hasCJKText(P.substring(0,1))){F(f.t("definedName.nameInvalid"));return}if(S.getSheetOrders().map(Re=>{var Ee;return((Ee=S.getSheetBySheetId(Re))==null?void 0:Ee.getName())||""}).includes(P)){F(f.t("definedName.nameSheetConflict"));return}if(A.length===0){F(f.t("definedName.formulaOrRefStringEmpty"));return}if(!j){F(f.t("definedName.formulaOrRefStringInvalid"));return}if(v.hasExecutor(P.toUpperCase())){F(f.t("definedName.nameConflict"));return}const le=S.getActiveSheet().getName();i&&i({id:h||"",name:P,formulaOrRefString:C.convertRefersToAbsolute(A,a.AbsoluteRefType.ALL,a.AbsoluteRefType.ALL,le),comment:D,localSheetId:B})},ne=re=>{const le=re;le==="formula"?l[0]===G.operatorToken.EQUALS?N(l):N(`${G.operatorToken.EQUALS}`):l[0]===G.operatorToken.EQUALS?N(""):N(l),W(le)},ue=H.useRef({}),[pe,de]=H.useState(!1);return R.useSidebarClick(re=>{var Re;const le=(Re=Z.current)==null?void 0:Re.handleOutClick;le&&le(re,()=>q(!1))}),R.useSidebarClick(re=>{var Re;const le=(Re=ue.current)==null?void 0:Re.handleOutClick;le&&le(re,()=>de(!1))}),I.jsxs("div",{className:Te.definedNameInput,style:{display:e?"block":"none"},children:[I.jsx("div",{children:I.jsx(K.Input,{placeholder:f.t("definedName.inputNamePlaceholder"),value:P,allowClear:!0,onChange:x,affixWrapperStyle:so})}),I.jsx("div",{children:I.jsxs(K.RadioGroup,{value:L,onChange:ne,children:[I.jsx(K.Radio,{value:"range",children:f.t("definedName.ratioRange")}),I.jsx(K.Radio,{value:"formula",children:f.t("definedName.ratioFormula")})]})}),L==="range"?b&&I.jsx(b,{unitId:M,subUnitId:w,initValue:A,onChange:X,isFocus:te,onFocus:()=>q(!0),actions:Z.current,isSupportAcrossSheet:!0}):E&&I.jsx(E,{initValue:A,unitId:M,subUnitId:w,isFocus:pe,isSupportAcrossSheet:!0,onChange:(re="")=>{Y(re||"")},onVerify:re=>{z(re)},onFocus:()=>de(!0),actions:ue.current}),I.jsx("div",{children:I.jsx(K.Select,{style:so,value:B,options:ie,onChange:V})}),I.jsx("div",{children:I.jsx(K.Input,{affixWrapperStyle:so,placeholder:f.t("definedName.inputCommentPlaceholder"),value:D,onChange:k})}),I.jsxs("div",{style:{display:U.length===0?"none":"flex"},className:Te.definedNameInputValidation,children:[I.jsx("span",{children:U}),I.jsx(bs,{})]}),I.jsxs("div",{children:[I.jsx(K.Button,{onClick:()=>{o&&o()},children:f.t("definedName.cancel")}),I.jsx(K.Button,{style:{marginLeft:15},type:"primary",onClick:Q,children:f.t("definedName.confirm")})]})]})},Yl=()=>{const n=a.useDependency(a.ICommandService),e=a.useDependency(a.IUniverInstanceService).getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),t=a.useDependency(a.LocaleService),i=a.useDependency(G.IDefinedNamesService),o=a.useDependency(m.SheetsSelectionsService);if(e==null)return;const s=e.getUnitId(),l=()=>{const D=i.getDefinedNameMap(s);return D?Array.from(Object.values(D)):[]},[c,d]=H.useState(!1),[u,h]=H.useState(l()),[g,S]=H.useState(null),[f,p]=H.useState();H.useEffect(()=>{const D=i.update$.subscribe(()=>{h(l())});return()=>{D.unsubscribe()}},[]);const v=D=>{const{name:k,formulaOrRefString:B,comment:V,localSheetId:U,hidden:F}=D;let L=D.id;if(L==null||L.length===0)L=a.Tools.generateRandomId(10),n.executeCommand(m.InsertDefinedNameCommand.id,{id:L,unitId:s,name:k,formulaOrRefString:B,comment:V,localSheetId:U,hidden:F});else{const W={id:L,unitId:s,name:k,formulaOrRefString:B,comment:V,localSheetId:U,hidden:F};n.executeCommand(m.SetDefinedNameCommand.id,W)}d(!1),S(null)},C=D=>{p(D)};function _(){p(null)}function b(D){const k=i.getValueById(s,D);n.executeCommand(m.RemoveDefinedNameCommand.id,{...k,unitId:s}),p(null)}const E=async D=>{const{formulaOrRefString:k,id:B}=D,V=i.getWorksheetByRef(s,k);if(!V)return;V.isSheetHidden()&&await n.executeCommand(m.SetWorksheetShowCommand.id,{unitId:s,subUnitId:V.getSheetId()}),i.focusRange(s,B)},M=()=>{const D=u.length+1,k=t.t("definedName.defaultName")+D;if(i.getValueByName(s,k)==null)return k;let B=D+1;for(;;){const V=t.t("definedName.defaultName")+B;if(i.getValueByName(s,V)==null)return V;B++}},w=()=>{var V;const D=(V=e.getActiveSheet())==null?void 0:V.getName();if(!D)return"";const k=o.getCurrentSelections();return k==null?"":k.map(U=>G.serializeRangeWithSheet(D,U.range)).join(",")},P=()=>{d(!1),S(null)},x=()=>{d(!0),S(null)},A=D=>{d(!1),S(D)},N=D=>{const k=e.getSheetBySheetId(D);return k==null?"":k.getName()};return I.jsx("div",{className:Te.definedNameContainer,children:I.jsxs("div",{className:Te.definedNameContainerScroll,children:[I.jsxs("div",{children:[I.jsxs("div",{onClick:x,className:Te.definedNameContainerAddButton,style:{display:c?"none":"flex"},children:[I.jsx(Rs,{}),I.jsx("span",{className:Te.definedNameContainerAddButtonText,children:t.t("definedName.addButton")})]}),c&&I.jsx(_a,{confirm:v,cancel:P,state:c,inputId:"insertDefinedName",name:M(),formulaOrRefString:w()})]},"insertDefinedName"),u.map((D,k)=>I.jsxs("div",{children:[I.jsxs("div",{onClick:()=>{E(D)},className:Te.definedNameContainerItem,style:{display:D.id===g?"none":"flex"},children:[I.jsxs("div",{title:D.comment,children:[I.jsxs("div",{className:Te.definedNameContainerItemName,children:[D.name,I.jsx("span",{className:Te.definedNameContainerItemNameForSheet,children:D.localSheetId===m.SCOPE_WORKBOOK_VALUE_DEFINED_NAME||D.localSheetId==null?"":N(D.localSheetId)})]}),I.jsx("div",{className:Te.definedNameContainerItemFormulaOrRefString,children:D.formulaOrRefString})]}),I.jsx(K.Tooltip,{title:t.t("definedName.updateButton"),placement:"top",children:I.jsx("div",{className:fe(Te.definedNameContainerItemUpdate,Te.definedNameContainerItemShow),onClick:()=>{A(D.id)},children:I.jsx(ht,{})})}),I.jsx(K.Tooltip,{title:t.t("definedName.deleteButton"),placement:"top",children:I.jsx("div",{className:fe(Te.definedNameContainerItemDelete,Te.definedNameContainerItemShow),onClick:()=>{C(D.id)},children:I.jsx(Dr,{})})})]}),I.jsx(K.Confirm,{visible:f===D.id,onClose:_,onConfirm:()=>{b(D.id)},children:t.t("definedName.deleteConfirmText")}),D.id===g&&I.jsx(_a,{confirm:v,cancel:P,state:D.id===g,id:D.id,inputId:D.id+k,name:D.name,formulaOrRefString:D.formulaOrRefString,comment:D.comment,localSheetId:D.localSheetId})]},k))]})})},_S="univer-count-bar",bS={countBar:_S},RS=[50,75,100,125,150,175,200,400];function ES(){const n=a.useDependency(a.ICommandService),r=a.useDependency(a.IUniverInstanceService),e=Je(),t=a.useDependency(he),i=a.useObservable(t.visible$),o=H.useCallback(()=>{if(!e)return 100;const u=e.getActiveSheet(),h=u&&u.getZoomRatio()*100||100;return Math.round(h)},[e]),[s,l]=H.useState(()=>o());H.useEffect(()=>(l(o()),n.onCommandExecuted(h=>{if(h.id===ze.id||h.id===m.SetWorksheetActiveOperation.id){const g=o();l(g)}}).dispose),[n,o]);function c(u){l(u);const h=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),g=h==null?void 0:h.getActiveSheet();if(g==null)return;const S=u/100;n.executeCommand(On.id,{unitId:h.getUnitId(),subUnitId:g.getSheetId(),zoomRatio:S})}const d=(i==null?void 0:i.visible)&&(i.unitId===(e==null?void 0:e.getUnitId())||i.unitId===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY);return I.jsx(K.Slider,{disabled:d,min:Oo[0],value:s,shortcuts:RS,onChange:c})}function TS(n){return I.jsx("section",{className:bS.countBar,children:I.jsx(ES,{})})}function Gl(n,r){const e=a.useDependency(he);return H.useMemo(()=>({keyCodes:[{keyCode:R.KeyCode.ENTER},{keyCode:R.KeyCode.ESC},{keyCode:R.KeyCode.TAB}],handler:i=>{(i===R.KeyCode.ENTER||i===R.KeyCode.ESC||i===R.KeyCode.TAB)&&(e.disableForceKeepVisible(),e.changeVisible({visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:i,unitId:r}))}}),[e,r])}const wS="univer-editor-container",yS="univer-editor-input",MS="univer-sheet-embedding-formula-editor-wrap",ba={editorContainer:wS,editorInput:yS,sheetEmbeddingFormulaEditorWrap:MS},ir=-1e3,Ra={width:0,height:0,top:ir,left:ir},PS=()=>{const[n,r]=H.useState({...Ra}),e=a.useDependency(ui),t=a.useDependency(J.IEditorService),i=a.useDependency(a.IContextService),o=a.useDependency(R.ComponentManager),s=a.useDependency(he),l=R.useObservable(s.visible$),c=a.useDependency(a.ICommandService),d=H.useRef(0),u=R.useObservable(()=>i.subscribeContextValue$(R.DISABLE_AUTO_FOCUS_KEY),!1,void 0,[i,R.DISABLE_AUTO_FOCUS_KEY]),h=o.get(br),g=s.getEditLocation();H.useEffect(()=>{const v=e.state$.subscribe(C=>{if(C==null)return;const{startX:_=ir,startY:b=ir,endX:E=0,endY:M=0,show:w=!1}=C;if(!w)r({...Ra});else{r({width:E-_,height:M-b,left:_,top:b});const P=t.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);if(P==null)return;const{left:x,top:A,width:N,height:D}=P.getBoundingClientRect();e.setRect({left:x,top:A,width:N,height:D})}});return()=>{v.unsubscribe()}},[]),H.useEffect(()=>{u||e.setFocus(!0)},[u,n]);const S=R.useEvent(()=>{s.isVisible().visible&&s.changeVisible({visible:!1,eventType:y.DeviceInputEventType.PointerUp,unitId:g.unitId})});R.useSidebarClick(S);const f=Gl(d,g==null?void 0:g.unitId),p=R.useEvent((v,C)=>{c.executeCommand(Ft.id,{keycode:v,visible:!1,eventType:y.DeviceInputEventType.Keyboard,isShift:C===R.MetaKeys.SHIFT||C===(R.MetaKeys.CTRL_COMMAND|R.MetaKeys.SHIFT),unitId:g==null?void 0:g.unitId})});return I.jsx("div",{className:ba.editorContainer,style:{left:n.left,top:n.top,width:n.width,height:n.height},children:h&&I.jsx(h,{editorId:a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,className:ba.editorInput,initValue:"",onChange:()=>{},isFocus:l==null?void 0:l.visible,unitId:g==null?void 0:g.unitId,subUnitId:g==null?void 0:g.sheetId,keyboradEventConfig:f,onMoveInEditor:p,isSupportAcrossSheet:!0,resetSelectionOnBlur:!1,isSingle:!1,autoScrollbar:!1,onFormulaSelectingChange:v=>{d.current=v,v?s.enableForceKeepVisible():s.disableForceKeepVisible()},disableSelectionOnClick:!0,disableContextMenu:!1})})};class OS{constructor(){T(this,"_position",null);T(this,"_position$",new O.BehaviorSubject(null));T(this,"position$",this._position$.asObservable());T(this,"_focus",!1);T(this,"_focus$",new O.BehaviorSubject(this._focus));T(this,"focus$",this._focus$.asObservable());T(this,"_fxBtnClick$",new O.Subject);T(this,"fxBtnClick$",this._fxBtnClick$.asObservable());T(this,"_foldBtnStatus$",new O.Subject);T(this,"foldBtnStatus$",this._foldBtnStatus$.asObservable())}dispose(){this._position$.complete(),this._focus$.complete(),this._position=null,this._focus=!1}setPosition(r){this._position=r,this._refresh(r)}getPosition(){return this._position}setFocus(r=!1){this._focus=r,this._focus$.next(r)}handleFxBtnClick(r){this._fxBtnClick$.next(r)}handleFoldBtnClick(r){this._foldBtnStatus$.next(r)}_refresh(r){this._position$.next(r)}}const xi=a.createIdentifier("univer.sheet-formula-editor-manager.service");function xS(n){const r=a.useDependency(a.ICommandService),e=a.useDependency(a.LocaleService),t=a.useDependency(G.IDefinedNamesService),i=a.useDependency(a.IUniverInstanceService),o=a.useDependency(R.ISidebarService),l=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getUnitId(),c=()=>{const S=t.getDefinedNameMap(l);return S?Array.from(Object.values(S)):[]},[d,u]=H.useState(c());H.useEffect(()=>{const S=t.update$.subscribe(()=>{u(c())});return()=>{S.unsubscribe()}},[]),H.useEffect(()=>{const S=o.sidebarOptions$.subscribe(f=>{f.id===ni&&(f.visible||setTimeout(()=>{o.sidebarOptions$.next({visible:!1})}))});return()=>{S.unsubscribe()}},[]);const h=()=>{r.executeCommand(Vr.id,{value:"open"})},g=async S=>{const{formulaOrRefString:f,id:p}=S,v=t.getWorksheetByRef(l,f);if(!v)return;v.isSheetHidden()&&await r.executeCommand(m.SetWorksheetShowCommand.id,{unitId:l,subUnitId:v.getSheetId()}),t.focusRange(l,p)};return I.jsxs("div",{className:"univer-w-[300px]",children:[I.jsx("ul",{className:`
24
24
  univer-max-h-[360px] univer-overflow-y-auto univer-scrollbar-thin univer-scrollbar-thumb-gray-300
25
25
  univer-scrollbar-track-transparent univer-scrollbar-w-[4px] univer-m-0 univer-list-none univer-p-0
26
26
  `,children:d.map((S,f)=>I.jsx("li",{className:`
@@ -44,7 +44,7 @@
44
44
  univer-flex univer-items-center univer-justify-center univer-px-1 univer-cursor-pointer
45
45
  univer-absolute univer-right-0 univer-h-full univer-transition-colors univer-duration-200
46
46
  hover:univer-bg-gray-100
47
- `,{"univer-text-gray-300 univer-cursor-not-allowed hover:univer-bg-transparent":n}),children:I.jsx(Tn,{})})}),I.jsx(K.DropdownOverlay,{className:"univer-z-[1001]",offset:{x:-75,y:2},children:I.jsx(xS,{})})]})]})}const NS="univer-formula-box",DS="univer-name-ranges",kS="univer-formula-bar",VS="univer-formula-icon",HS="univer-formula-icon-disable",WS="univer-formula-icon-wrapper",US="univer-icon-container",LS="univer-icon-container-success",BS="univer-formula-active",FS="univer-icon-container-error",jS="univer-icon-container-fx",zS="univer-formula-input",XS="univer-formula-container",YS="univer-sheet-embedding-formula-editor-wrap",GS="univer-formula-content",ZS="univer-arrow-container",KS="univer-arrow-container-disable",Ce={formulaBox:NS,nameRanges:DS,formulaBar:kS,formulaIcon:VS,formulaIconDisable:HS,formulaIconWrapper:WS,iconContainer:US,iconContainerSuccess:LS,formulaActive:BS,iconContainerError:FS,iconContainerFx:jS,formulaInput:zS,formulaContainer:XS,sheetEmbeddingFormulaEditorWrap:YS,formulaContent:GS,arrowContainer:ZS,arrowContainerDisable:KS};function qS(){var F;const[n,r]=H.useState(Ce.formulaGrey),[e,t]=H.useState(0),i=a.useDependency(xi),o=a.useDependency(he),s=a.useDependency(m.WorksheetProtectionRuleModel),l=a.useDependency(m.RangeProtectionRuleModel),c=a.useDependency(a.IUniverInstanceService),d=a.useDependency(m.SheetsSelectionsService),u=a.useDependency(a.IPermissionService),[h,g]=H.useState(!1),[S,f]=H.useState(!1),p=Je(),v=a.useDependency(R.ComponentManager),C=a.useObservable(()=>c.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),_=H.useRef(0),b=o.getEditLocation(),E=Gl(_,(F=b==null?void 0:b.unitId)!=null?F:""),M=v.get(br),w=R.useComponentsOfPart(is.FORMULA_AUX),P=a.useDependency(a.IContextService);a.useObservable(H.useMemo(()=>P.subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR),[P]));const x=P.getContextValue(a.FOCUSING_FX_BAR_EDITOR),A=H.useRef(null);function N(L,W){return[new m.WorkbookEditablePermission(L).id,new m.WorksheetSetCellValuePermission(L,W).id,new m.WorksheetEditPermission(L,W).id]}H.useLayoutEffect(()=>{const L=C.activeSheet$.pipe(O.switchMap(W=>W?O.merge(s.ruleChange$,l.ruleChange$,d.selectionMoveEnd$,d.selectionSet$).pipe(O.switchMap(()=>{var oe,X;const j=C.getUnitId(),z=W.getSheetId();if(!((oe=d.getCurrentLastSelection())==null?void 0:oe.range))return O.EMPTY;const te=N(j,z),q=(X=d.getCurrentSelections())==null?void 0:X.map(Y=>Y.range);return l.getSubunitRuleList(j,z).filter(Y=>Y.ranges.some(Q=>q==null?void 0:q.some(ne=>a.Rectangle.intersects(Q,ne)))).forEach(Y=>{te.push(new m.RangeProtectionPermissionEditPoint(j,z,Y.permissionId).id)}),u.composePermission$(te)})):O.EMPTY)).subscribe(W=>{W&&g(!W.every(j=>j.value))});return()=>{L.unsubscribe()}},[C]),H.useEffect(()=>{const L=o.visible$.subscribe(W=>{r(W.visible?Ce.formulaActive:Ce.formulaGrey)});return()=>L.unsubscribe()},[o.visible$]),H.useEffect(()=>{const L=o.currentEditCellState$.subscribe(W=>{var j,z,Z;(Z=(z=(j=W==null?void 0:W.documentLayoutObject.documentModel)==null?void 0:j.getBody())==null?void 0:z.customBlocks)!=null&&Z.length?f(!0):f(!1)});return()=>L.unsubscribe()},[o.currentEditCellState$]),H.useEffect(()=>{if(A.current){const L=()=>{const j=A.current.getBoundingClientRect();i.setPosition(j)};L();const W=new ResizeObserver(L);return W.observe(A.current),()=>W.disconnect()}},[i]);function D(){t(e===0?1:0),setTimeout(()=>{i.handleFoldBtnClick(e===1)},150)}function k(){var W;o.isVisible().visible&&o.changeVisible({visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.ESC,unitId:(W=p==null?void 0:p.getUnitId())!=null?W:""})}function B(){var W;o.isVisible().visible&&o.changeVisible({visible:!1,eventType:y.DeviceInputEventType.PointerDown,unitId:(W=p==null?void 0:p.getUnitId())!=null?W:""})}function V(){i.handleFxBtnClick(!0)}const U=h||S;return I.jsxs("div",{className:Ce.formulaBox,style:{height:e===0?"28px":"82px",pointerEvents:h?"none":"auto"},children:[I.jsx("div",{className:Ce.nameRanges,children:I.jsx(AS,{disable:h})}),I.jsxs("div",{className:Ce.formulaBar,children:[I.jsx("div",{className:fe(Ce.formulaIcon,{[Ce.formulaIconDisable]:U}),children:I.jsxs("div",{className:Ce.formulaIconWrapper,children:[I.jsx("span",{className:fe(Ce.iconContainer,Ce.iconContainerError,n),onClick:k,children:I.jsx(Tl,{})}),I.jsx("span",{className:fe(Ce.iconContainer,Ce.iconContainerSuccess,n),onClick:B,children:I.jsx(ht,{})}),I.jsx("span",{className:fe(Ce.iconContainer,Ce.iconContainerFx),onClick:V,children:I.jsx(Ml,{})})]})}),I.jsxs("div",{className:Ce.formulaContainer,children:[I.jsx("div",{className:Ce.formulaInput,ref:A,children:M&&I.jsx(M,{disableSelectionOnClick:!0,editorId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,initValue:"",onChange:()=>{},isFocus:x,className:Ce.formulaContent,unitId:b==null?void 0:b.unitId,subUnitId:b==null?void 0:b.sheetId,isSupportAcrossSheet:!0,resetSelectionOnBlur:!1,isSingle:!1,keyboradEventConfig:E,onFormulaSelectingChange:L=>{_.current=L,L?o.enableForceKeepVisible():o.disableForceKeepVisible()},autoScrollbar:!1})}),I.jsx("div",{className:fe(Ce.arrowContainer,{[Ce.arrowContainerDisable]:h}),onClick:D,children:e===0?I.jsx(Fo,{}):I.jsx(Fo,{style:{transform:"rotateZ(180deg)"}})})]})]}),I.jsx(R.ComponentContainer,{components:w},"formula-aux")]})}const QS="univer-operate-container",JS="univer-auto-fill-popup-menu",$S="univer-auto-fill-popup-menu-item",ef="univer-auto-fill-popup-menu-item-icon",tf="univer-auto-fill-popup-menu-item-title",nf="univer-auto-fill-popup-menu-item-hide",rf="univer-btn-container",of="univer-btn-container-expand",Dt={operateContainer:QS,autoFillPopupMenu:JS,autoFillPopupMenuItem:$S,autoFillPopupMenuItemIcon:ef,autoFillPopupMenuItemTitle:tf,autoFillPopupMenuItemHide:nf,btnContainer:rf,btnContainerExpand:of},sf=()=>{const[,n]=H.useState({});return H.useCallback(()=>n(r=>!r),[])},af=()=>{const n=a.useDependency(a.ICommandService),r=a.useDependency(a.IUniverInstanceService),e=a.useDependency(y.IRenderManagerService),t=a.useDependency(Tt),i=a.useDependency(a.LocaleService),[o,s]=H.useState([]),[l,c]=H.useState(!1),[d,u]=H.useState({row:-1,col:-1}),[h,g]=H.useState(se.SERIES),[S,f]=H.useState(!1),p=Je(),{sheetSkeletonManagerService:v,selectionRenderService:C}=H.useMemo(()=>{if(p){const z=e.getRenderById(p.getUnitId());return{sheetSkeletonManagerService:z==null?void 0:z.with(exports.SheetSkeletonManagerService),selectionRenderService:z==null?void 0:z.with(_e)}}return{sheetSkeletonManagerService:null,selectionRenderService:null}},[p,e]),_=()=>{f(!0)},b=()=>{f(!1)},E=sf();if(H.useEffect(()=>n.onCommandExecuted((Z,te)=>{Z.id===qe.id&&E()}).dispose,[E,n]),H.useEffect(()=>{const z=v&&a.toDisposable(v.currentSkeleton$.subscribe(Z=>{Z&&E()}));return z==null?void 0:z.dispose},[v,E]),H.useEffect(()=>a.toDisposable(t.menu$.subscribe(Z=>{s(Z.map(te=>({...te,index:Z.indexOf(te)})))})).dispose,[t]),H.useEffect(()=>a.toDisposable(t.showMenu$.subscribe(Z=>{const{source:te,target:q}=t.autoFillLocation||{source:null,target:null};if(Z&&te&&q){const ie=Math.max(te.rows[te.rows.length-1],q.rows[q.rows.length-1]),oe=Math.max(te.cols[te.cols.length-1],q.cols[q.cols.length-1]);u({row:ie,col:oe})}else u({row:-1,col:-1})})).dispose,[t]),H.useEffect(()=>a.toDisposable(t.applyType$.subscribe(Z=>{g(Z)})).dispose,[t]),H.useEffect(()=>{function z(){c(!1)}return document.addEventListener("wheel",z),()=>{document.removeEventListener("wheel",z)}},[l]),d.col<0||d.row<0)return null;const M=Xe(r,e);if(!M||!C)return null;const{scene:w}=M,P=v==null?void 0:v.getCurrentSkeleton(),x=C.getViewPort(),A=w==null?void 0:w.scaleX,N=w==null?void 0:w.scaleY,D=w==null?void 0:w.getViewportScrollXY(x);if(!A||!w||!A||!N||!D)return null;const k=(P==null?void 0:P.getNoMergeCellPositionByIndex(d.row,d.col).endX)||0,B=(P==null?void 0:P.getNoMergeCellPositionByIndex(d.row,d.col).endY)||0,V=P==null?void 0:P.convertTransformToOffsetX(k,A,D),U=P==null?void 0:P.convertTransformToOffsetY(B,N,D);if(V==null||U==null)return null;const F=z=>{c(z)},L=z=>{n.executeCommand(li.id,{type:z.value}),c(!1)},W=l||S,j=o.filter(z=>!z.disable);return I.jsx("div",{onMouseEnter:_,onMouseLeave:b,style:{left:`${V+2}px`,top:`${U+2}px`,position:"absolute"},children:I.jsx(K.DropdownLegacy,{placement:"bottomLeft",trigger:["click"],overlay:I.jsx("ul",{className:Dt.autoFillPopupMenu,children:j.map(z=>I.jsxs("li",{onClick:()=>L(z),className:Dt.autoFillPopupMenuItem,children:[I.jsx("span",{className:Dt.autoFillPopupMenuItemIcon,children:z.value===h&&I.jsx(ht,{style:{color:"rgb(var(--green-700, #409f11))"}})}),I.jsx("span",{className:Dt.autoFillPopupMenuItemTitle,children:i.t(z.label)})]},z.index))}),visible:l,onVisibleChange:F,children:I.jsxs("div",{className:fe(Dt.btnContainer,{[Dt.btnContainerExpand]:l}),children:[I.jsx(El,{style:{color:"#35322B"},extend:{colorChannel1:"rgb(var(--green-700, #409f11))"}}),W&&I.jsx(Tn,{style:{color:"#CCCCCC",fontSize:"8px",marginLeft:"8px"}})]})})})},lf=()=>I.jsx("div",{className:Dt.operateContainer,children:I.jsx(af,{})}),cf="univer-sheet-bar",df="univer-sheet-bar-options",uf="univer-sheet-bar-options-divider",Hi={sheetBar:cf,sheetBarOptions:df,sheetBarOptionsDivider:uf},hf="univer-sheet-bar-btn",mf={sheetBarBtn:hf};function Xi(n){const{children:r,className:e,style:t,disabled:i=!1,onClick:o,...s}=n,l=c=>{if(i){c.preventDefault();return}o&&o(c)};return I.jsx("button",{className:mf.sheetBarBtn,style:t,disabled:i,onClick:l,...s,children:r})}const gf="36",Sf="univer-sheet-container",ff="univer-sheet-bar-menu",pf="univer-sheet-bar-menu-item",vf="univer-sheet-bar-menu-item-icon",Cf="univer-sheet-bar-menu-item-hide",If="univer-sheet-bar-menu-item-select",_f="univer-sheet-bar-menu-item-label",mt={sheetFooterBarHeight:gf,sheetContainer:Sf,sheetBarMenu:ff,sheetBarMenuItem:pf,sheetBarMenuItemIcon:vf,sheetBarMenuItemHide:Cf,sheetBarMenuItemSelect:If,sheetBarMenuItemLabel:_f};function bf(n){const{style:r}=n,[e,t]=H.useState([]),[i,o]=H.useState(!1),s=a.useDependency(a.IUniverInstanceService),l=a.useDependency(a.ICommandService),c=a.useDependency(Jt),d=a.useDependency(m.WorksheetProtectionRuleModel),u=R.useObservable(()=>s.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),null,!1,[]),h=v=>{const{sheetId:C}=v;!C||!u||(v.hidden?l.executeCommand(m.SetWorksheetShowCommand.id,{unitId:u.getUnitId(),subUnitId:C,value:C}):v.selected||l.executeCommand(m.SetWorksheetActivateCommand.id,{unitId:u.getUnitId(),subUnitId:C}),o(!1))},g=H.useCallback(()=>{if(!u)return;const v=u.getSheets(),C=u.getActiveSheet(),_=v.map((b,E)=>({label:b.getName(),index:`${E}`,sheetId:b.getSheetId(),hidden:b.isSheetHidden()===a.BooleanNumber.TRUE,selected:C===b}));t(_)},[u,d]),S=H.useCallback(()=>l.onCommandExecuted(v=>{switch(v.id){case m.SetWorksheetHideMutation.id:case m.RemoveSheetMutation.id:case m.SetWorksheetNameMutation.id:case m.InsertSheetMutation.id:case m.SetWorksheetOrderMutation.id:case m.SetWorksheetActiveOperation.id:g();break}}),[l,g]);function f(){o(!0)}const p=v=>{o(v)};return H.useEffect(()=>{g();const v=new a.DisposableCollection;return v.add(S()),v.add(c.registerSheetBarMenuHandler({handleSheetBarMenu:f})),()=>v.dispose()},[S,c,g,u]),I.jsx(K.DropdownLegacy,{placement:"topLeft",trigger:["click"],overlay:I.jsx("ul",{className:mt.sheetBarMenu,style:{...r},children:e.map(v=>I.jsxs("li",{onClick:()=>h(v),className:v.selected?`
47
+ `,{"univer-text-gray-300 univer-cursor-not-allowed hover:univer-bg-transparent":n}),children:I.jsx(Tn,{})})}),I.jsx(K.DropdownOverlay,{className:"univer-z-[1001]",offset:{x:-75,y:2},children:I.jsx(xS,{})})]})]})}const NS="univer-formula-box",DS="univer-name-ranges",kS="univer-formula-bar",VS="univer-formula-icon",HS="univer-formula-icon-disable",WS="univer-formula-icon-wrapper",US="univer-icon-container",LS="univer-icon-container-success",BS="univer-formula-active",FS="univer-icon-container-error",jS="univer-icon-container-fx",zS="univer-formula-input",XS="univer-formula-container",YS="univer-sheet-embedding-formula-editor-wrap",GS="univer-formula-content",ZS="univer-arrow-container",KS="univer-arrow-container-disable",Ce={formulaBox:NS,nameRanges:DS,formulaBar:kS,formulaIcon:VS,formulaIconDisable:HS,formulaIconWrapper:WS,iconContainer:US,iconContainerSuccess:LS,formulaActive:BS,iconContainerError:FS,iconContainerFx:jS,formulaInput:zS,formulaContainer:XS,sheetEmbeddingFormulaEditorWrap:YS,formulaContent:GS,arrowContainer:ZS,arrowContainerDisable:KS};function qS(){var F;const[n,r]=H.useState(Ce.formulaGrey),[e,t]=H.useState(0),i=a.useDependency(xi),o=a.useDependency(he),s=a.useDependency(m.WorksheetProtectionRuleModel),l=a.useDependency(m.RangeProtectionRuleModel),c=a.useDependency(a.IUniverInstanceService),d=a.useDependency(m.SheetsSelectionsService),u=a.useDependency(a.IPermissionService),[h,g]=H.useState(!1),[S,f]=H.useState(!1),p=Je(),v=a.useDependency(R.ComponentManager),C=a.useObservable(()=>c.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),void 0,void 0,[]),_=H.useRef(0),b=o.getEditLocation(),E=Gl(_,(F=b==null?void 0:b.unitId)!=null?F:""),M=v.get(br),w=R.useComponentsOfPart(is.FORMULA_AUX),P=a.useDependency(a.IContextService);a.useObservable(H.useMemo(()=>P.subscribeContextValue$(a.FOCUSING_FX_BAR_EDITOR),[P]));const x=P.getContextValue(a.FOCUSING_FX_BAR_EDITOR),A=H.useRef(null);function N(L,W){return[new m.WorkbookEditablePermission(L).id,new m.WorksheetSetCellValuePermission(L,W).id,new m.WorksheetEditPermission(L,W).id]}H.useLayoutEffect(()=>{const L=C.activeSheet$.pipe(O.switchMap(W=>W?O.merge(s.ruleChange$,l.ruleChange$,d.selectionMoveEnd$,d.selectionSet$).pipe(O.switchMap(()=>{var oe,X;const j=C.getUnitId(),z=W.getSheetId();if(!((oe=d.getCurrentLastSelection())==null?void 0:oe.range))return O.EMPTY;const te=N(j,z),q=(X=d.getCurrentSelections())==null?void 0:X.map(Y=>Y.range);return l.getSubunitRuleList(j,z).filter(Y=>Y.ranges.some(Q=>q==null?void 0:q.some(ne=>a.Rectangle.intersects(Q,ne)))).forEach(Y=>{te.push(new m.RangeProtectionPermissionEditPoint(j,z,Y.permissionId).id)}),u.composePermission$(te)})):O.EMPTY)).subscribe(W=>{W&&g(!W.every(j=>j.value))});return()=>{L.unsubscribe()}},[C]),H.useEffect(()=>{const L=o.visible$.subscribe(W=>{r(W.visible?Ce.formulaActive:Ce.formulaGrey)});return()=>L.unsubscribe()},[o.visible$]),H.useEffect(()=>{const L=o.currentEditCellState$.subscribe(W=>{var j,z,Z;(Z=(z=(j=W==null?void 0:W.documentLayoutObject.documentModel)==null?void 0:j.getBody())==null?void 0:z.customBlocks)!=null&&Z.length?f(!0):f(!1)});return()=>L.unsubscribe()},[o.currentEditCellState$]),H.useEffect(()=>{if(A.current){const L=()=>{const j=A.current.getBoundingClientRect();i.setPosition(j)};L();const W=new ResizeObserver(L);return W.observe(A.current),()=>W.disconnect()}},[i]);function D(){t(e===0?1:0),setTimeout(()=>{i.handleFoldBtnClick(e===1)},150)}function k(){var W;o.isVisible().visible&&o.changeVisible({visible:!1,eventType:y.DeviceInputEventType.Keyboard,keycode:R.KeyCode.ESC,unitId:(W=p==null?void 0:p.getUnitId())!=null?W:""})}function B(){var W;o.isVisible().visible&&o.changeVisible({visible:!1,eventType:y.DeviceInputEventType.PointerDown,unitId:(W=p==null?void 0:p.getUnitId())!=null?W:""})}function V(){i.handleFxBtnClick(!0)}const U=h||S;return I.jsxs("div",{className:Ce.formulaBox,style:{height:e===0?"28px":"82px",pointerEvents:h?"none":"auto"},children:[I.jsx("div",{className:Ce.nameRanges,children:I.jsx(AS,{disable:h})}),I.jsxs("div",{className:Ce.formulaBar,children:[I.jsx("div",{className:fe(Ce.formulaIcon,{[Ce.formulaIconDisable]:U}),children:I.jsxs("div",{className:Ce.formulaIconWrapper,children:[I.jsx("span",{className:fe(Ce.iconContainer,Ce.iconContainerError,n),onClick:k,children:I.jsx(Tl,{})}),I.jsx("span",{className:fe(Ce.iconContainer,Ce.iconContainerSuccess,n),onClick:B,children:I.jsx(ht,{})}),I.jsx("span",{className:fe(Ce.iconContainer,Ce.iconContainerFx),onClick:V,children:I.jsx(Ml,{})})]})}),I.jsxs("div",{className:Ce.formulaContainer,children:[I.jsx("div",{className:Ce.formulaInput,ref:A,children:M&&I.jsx(M,{disableSelectionOnClick:!0,editorId:a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,initValue:"",onChange:()=>{},isFocus:x,className:Ce.formulaContent,unitId:b==null?void 0:b.unitId,subUnitId:b==null?void 0:b.sheetId,isSupportAcrossSheet:!0,resetSelectionOnBlur:!1,isSingle:!1,keyboradEventConfig:E,onFormulaSelectingChange:L=>{_.current=L,L?o.enableForceKeepVisible():o.disableForceKeepVisible()},autoScrollbar:!1,disableContextMenu:!1})}),I.jsx("div",{className:fe(Ce.arrowContainer,{[Ce.arrowContainerDisable]:h}),onClick:D,children:e===0?I.jsx(Fo,{}):I.jsx(Fo,{style:{transform:"rotateZ(180deg)"}})})]})]}),I.jsx(R.ComponentContainer,{components:w},"formula-aux")]})}const QS="univer-operate-container",JS="univer-auto-fill-popup-menu",$S="univer-auto-fill-popup-menu-item",ef="univer-auto-fill-popup-menu-item-icon",tf="univer-auto-fill-popup-menu-item-title",nf="univer-auto-fill-popup-menu-item-hide",rf="univer-btn-container",of="univer-btn-container-expand",Dt={operateContainer:QS,autoFillPopupMenu:JS,autoFillPopupMenuItem:$S,autoFillPopupMenuItemIcon:ef,autoFillPopupMenuItemTitle:tf,autoFillPopupMenuItemHide:nf,btnContainer:rf,btnContainerExpand:of},sf=()=>{const[,n]=H.useState({});return H.useCallback(()=>n(r=>!r),[])},af=()=>{const n=a.useDependency(a.ICommandService),r=a.useDependency(a.IUniverInstanceService),e=a.useDependency(y.IRenderManagerService),t=a.useDependency(Tt),i=a.useDependency(a.LocaleService),[o,s]=H.useState([]),[l,c]=H.useState(!1),[d,u]=H.useState({row:-1,col:-1}),[h,g]=H.useState(se.SERIES),[S,f]=H.useState(!1),p=Je(),{sheetSkeletonManagerService:v,selectionRenderService:C}=H.useMemo(()=>{if(p){const z=e.getRenderById(p.getUnitId());return{sheetSkeletonManagerService:z==null?void 0:z.with(exports.SheetSkeletonManagerService),selectionRenderService:z==null?void 0:z.with(_e)}}return{sheetSkeletonManagerService:null,selectionRenderService:null}},[p,e]),_=()=>{f(!0)},b=()=>{f(!1)},E=sf();if(H.useEffect(()=>n.onCommandExecuted((Z,te)=>{Z.id===qe.id&&E()}).dispose,[E,n]),H.useEffect(()=>{const z=v&&a.toDisposable(v.currentSkeleton$.subscribe(Z=>{Z&&E()}));return z==null?void 0:z.dispose},[v,E]),H.useEffect(()=>a.toDisposable(t.menu$.subscribe(Z=>{s(Z.map(te=>({...te,index:Z.indexOf(te)})))})).dispose,[t]),H.useEffect(()=>a.toDisposable(t.showMenu$.subscribe(Z=>{const{source:te,target:q}=t.autoFillLocation||{source:null,target:null};if(Z&&te&&q){const ie=Math.max(te.rows[te.rows.length-1],q.rows[q.rows.length-1]),oe=Math.max(te.cols[te.cols.length-1],q.cols[q.cols.length-1]);u({row:ie,col:oe})}else u({row:-1,col:-1})})).dispose,[t]),H.useEffect(()=>a.toDisposable(t.applyType$.subscribe(Z=>{g(Z)})).dispose,[t]),H.useEffect(()=>{function z(){c(!1)}return document.addEventListener("wheel",z),()=>{document.removeEventListener("wheel",z)}},[l]),d.col<0||d.row<0)return null;const M=Xe(r,e);if(!M||!C)return null;const{scene:w}=M,P=v==null?void 0:v.getCurrentSkeleton(),x=C.getViewPort(),A=w==null?void 0:w.scaleX,N=w==null?void 0:w.scaleY,D=w==null?void 0:w.getViewportScrollXY(x);if(!A||!w||!A||!N||!D)return null;const k=(P==null?void 0:P.getNoMergeCellPositionByIndex(d.row,d.col).endX)||0,B=(P==null?void 0:P.getNoMergeCellPositionByIndex(d.row,d.col).endY)||0,V=P==null?void 0:P.convertTransformToOffsetX(k,A,D),U=P==null?void 0:P.convertTransformToOffsetY(B,N,D);if(V==null||U==null)return null;const F=z=>{c(z)},L=z=>{n.executeCommand(li.id,{type:z.value}),c(!1)},W=l||S,j=o.filter(z=>!z.disable);return I.jsx("div",{onMouseEnter:_,onMouseLeave:b,style:{left:`${V+2}px`,top:`${U+2}px`,position:"absolute"},children:I.jsx(K.DropdownLegacy,{placement:"bottomLeft",trigger:["click"],overlay:I.jsx("ul",{className:Dt.autoFillPopupMenu,children:j.map(z=>I.jsxs("li",{onClick:()=>L(z),className:Dt.autoFillPopupMenuItem,children:[I.jsx("span",{className:Dt.autoFillPopupMenuItemIcon,children:z.value===h&&I.jsx(ht,{style:{color:"rgb(var(--green-700, #409f11))"}})}),I.jsx("span",{className:Dt.autoFillPopupMenuItemTitle,children:i.t(z.label)})]},z.index))}),visible:l,onVisibleChange:F,children:I.jsxs("div",{className:fe(Dt.btnContainer,{[Dt.btnContainerExpand]:l}),children:[I.jsx(El,{style:{color:"#35322B"},extend:{colorChannel1:"rgb(var(--green-700, #409f11))"}}),W&&I.jsx(Tn,{style:{color:"#CCCCCC",fontSize:"8px",marginLeft:"8px"}})]})})})},lf=()=>I.jsx("div",{className:Dt.operateContainer,children:I.jsx(af,{})}),cf="univer-sheet-bar",df="univer-sheet-bar-options",uf="univer-sheet-bar-options-divider",Hi={sheetBar:cf,sheetBarOptions:df,sheetBarOptionsDivider:uf},hf="univer-sheet-bar-btn",mf={sheetBarBtn:hf};function Xi(n){const{children:r,className:e,style:t,disabled:i=!1,onClick:o,...s}=n,l=c=>{if(i){c.preventDefault();return}o&&o(c)};return I.jsx("button",{className:mf.sheetBarBtn,style:t,disabled:i,onClick:l,...s,children:r})}const gf="36",Sf="univer-sheet-container",ff="univer-sheet-bar-menu",pf="univer-sheet-bar-menu-item",vf="univer-sheet-bar-menu-item-icon",Cf="univer-sheet-bar-menu-item-hide",If="univer-sheet-bar-menu-item-select",_f="univer-sheet-bar-menu-item-label",mt={sheetFooterBarHeight:gf,sheetContainer:Sf,sheetBarMenu:ff,sheetBarMenuItem:pf,sheetBarMenuItemIcon:vf,sheetBarMenuItemHide:Cf,sheetBarMenuItemSelect:If,sheetBarMenuItemLabel:_f};function bf(n){const{style:r}=n,[e,t]=H.useState([]),[i,o]=H.useState(!1),s=a.useDependency(a.IUniverInstanceService),l=a.useDependency(a.ICommandService),c=a.useDependency(Jt),d=a.useDependency(m.WorksheetProtectionRuleModel),u=R.useObservable(()=>s.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),null,!1,[]),h=v=>{const{sheetId:C}=v;!C||!u||(v.hidden?l.executeCommand(m.SetWorksheetShowCommand.id,{unitId:u.getUnitId(),subUnitId:C,value:C}):v.selected||l.executeCommand(m.SetWorksheetActivateCommand.id,{unitId:u.getUnitId(),subUnitId:C}),o(!1))},g=H.useCallback(()=>{if(!u)return;const v=u.getSheets(),C=u.getActiveSheet(),_=v.map((b,E)=>({label:b.getName(),index:`${E}`,sheetId:b.getSheetId(),hidden:b.isSheetHidden()===a.BooleanNumber.TRUE,selected:C===b}));t(_)},[u,d]),S=H.useCallback(()=>l.onCommandExecuted(v=>{switch(v.id){case m.SetWorksheetHideMutation.id:case m.RemoveSheetMutation.id:case m.SetWorksheetNameMutation.id:case m.InsertSheetMutation.id:case m.SetWorksheetOrderMutation.id:case m.SetWorksheetActiveOperation.id:g();break}}),[l,g]);function f(){o(!0)}const p=v=>{o(v)};return H.useEffect(()=>{g();const v=new a.DisposableCollection;return v.add(S()),v.add(c.registerSheetBarMenuHandler({handleSheetBarMenu:f})),()=>v.dispose()},[S,c,g,u]),I.jsx(K.DropdownLegacy,{placement:"topLeft",trigger:["click"],overlay:I.jsx("ul",{className:mt.sheetBarMenu,style:{...r},children:e.map(v=>I.jsxs("li",{onClick:()=>h(v),className:v.selected?`
48
48
  ${mt.sheetBarMenuItem}
49
49
  ${mt.sheetBarMenuItemSelect}
50
50
  `:v.hidden?`