@univerjs/sheets-numfmt 0.10.4-nightly.202508220605 → 0.10.5-nightly.202508290716

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 +1 @@
1
- "use strict";var Y=Object.defineProperty;var X=(e,r,a)=>r in e?Y(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a;var U=(e,r,a)=>X(e,typeof r!="symbol"?r+"":r,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),m=require("@univerjs/sheets"),R=require("rxjs"),J=require("@univerjs/engine-formula"),L=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function D(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function V(e){return E.get(e)||"$"}function j(e,r=2){let a=r;r>127&&(a=127);let n="";return a>0&&(n=`.${"0".repeat(a)}`),`"${V(e)}"#,##0${n}_);[Red]("${V(e)}"#,##0${n})`}const A=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],G=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],H=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],P=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},x=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),$=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${x(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${x(Number(r||0))}$1`):n).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),I={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const a=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),s=e.get(t.IUndoRedoService),o=m.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:d,worksheet:f}=o,i=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),T=m.transformCellsToRange(l,d,i),S={unitId:l,subUnitId:d,ranges:_.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],C=[];if(i.length){const c=i.reduce((g,u)=>{t.isTextFormat(u.pattern)&&g.setValue(u.row,u.col,{t:t.CellValueType.STRING});const v=f.getCellRaw(u.row,u.col);if(v){const N=m.checkCellValueType(v.v);N!==v.t&&g.setValue(u.row,u.col,{t:N})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,u)=>{const v=f.getCellRaw(g,u);v?h.setValue(g,u,{t:v.t}):h.setValue(g,u,{t:void 0})}),Object.keys(T.values).forEach(g=>{const u=T.values[g];u.ranges=m.rangeMerge(u.ranges)}),M.push({id:m.SetNumfmtMutation.id,params:T});const y=m.factorySetNumfmtUndoMutation(e,T);C.push(...y)}if(_.length){S.ranges=m.rangeMerge(S.ranges);const c=_.reduce((g,u)=>{const v=f.getCellRaw(u.row,u.col);if(v){const N=m.checkCellValueType(v.v);N!==v.t&&g.setValue(u.row,u.col,{t:N})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,u)=>{const v=f.getCellRaw(g,u);v?h.setValue(g,u,{t:v.t}):h.setValue(g,u,{t:void 0})}),M.push({id:m.RemoveNumfmtMutation.id,params:S},{id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:c}});const y=m.factoryRemoveNumfmtUndoMutation(e,S);C.push({id:m.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:h.getMatrix()}},...y)}const p=t.sequenceExecute(M,a).result;return p&&s.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:M}),p}},B={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:f}=l;let i=0;o.forEach(M=>{t.Range.foreach(M.range,(C,p)=>{const c=n.getValue(d,f,C,p);if(!c){const y=l.worksheet.getCellRaw(C,p);if(!i&&y&&y.t===t.CellValueType.NUMBER&&y.v){const g=/\.(\d*)$/.exec(String(y.v));if(g){const u=g[1].length;if(!u)return;i=Math.max(i,u)}}return}const h=P(c.pattern);i=h>i?h:i})});const _=i+1,T=$(`0${_>0?".0":""}`,_),S=[];return o.forEach(M=>{t.Range.foreach(M.range,(C,p)=>{const c=n.getValue(d,f,C,p);if(!c)S.push({row:C,col:p,pattern:T});else{const h=P(c.pattern),y=$(c.pattern,h+1);y!==c.pattern&&S.push({row:C,col:p,pattern:y})}})}),S.length?await r.executeCommand(I.id,{values:S}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(m.SheetsSelectionsService),n=e.get(t.LocaleService),s=a.getCurrentSelections();if(!s||!s.length)return!1;const o=[],l=D(n.getCurrentLocale()),d=j(l.locale);return s.forEach(i=>{t.Range.foreach(i.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(I.id,{values:o})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(m.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const s=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(f,i)=>{s.push({row:f,col:i,pattern:o,type:"percent"})})}),await r.executeCommand(I.id,{values:s})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),a=e.get(m.SheetsSelectionsService),n=e.get(m.INumfmtService),s=e.get(t.IUniverInstanceService),o=a.getCurrentSelections();if(!o||!o.length)return!1;const l=m.getSheetCommandTarget(s);if(!l)return!1;const{unitId:d,subUnitId:f}=l;let i=0;o.forEach(C=>{t.Range.foreach(C.range,(p,c)=>{const h=n.getValue(d,f,p,c);if(!h){const g=l.worksheet.getCellRaw(p,c);if(!i&&g&&g.t===t.CellValueType.NUMBER&&g.v){const u=/\.(\d*)$/.exec(String(g.v));if(u){const v=u[1].length;if(!v)return;i=Math.max(i,v)}}return}const y=P(h.pattern);i=y>i?y:i})});const _=i-1,T=$(`0${_>0?".0":"."}`,_),S=[];return o.forEach(C=>{t.Range.foreach(C.range,(p,c)=>{const h=n.getValue(d,f,p,c);if(!h)S.push({row:p,col:c,pattern:T});else{const y=P(h.pattern);S.push({row:p,col:c,pattern:$(h.pattern,y-1)})}})}),await r.executeCommand(I.id,{values:S})}},F="sheets-numfmt.config",w={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,a="en")=>{const n=t.numfmt.formatColor(e,r),s=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:a,throws:!1});return r<0?{result:o,color:s}:{result:o}},k=(e,r,a)=>e==="General"?{result:String(J.stripErrorMargin(r))}:Z(e,r,a),te=new Set(["m d"]),ne=new Set(["h:mm AM/PM","hh:mm AM/PM"]),re=e=>{var n,s;const r=(s=(n=t.numfmt.parseDate(e))!=null?n:t.numfmt.parseTime(e))!=null?s:t.numfmt.parseNumber(e);if(!r)return null;const{z:a}=r;return a&&(te.has(a)||ne.has(a)&&!/\s(A|AM|P|PM)$/i.test(e))?null:r};var ae=Object.getOwnPropertyDescriptor,se=(e,r,a,n)=>{for(var s=n>1?void 0:n?ae(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},b=(e,r)=>(a,n)=>r(a,n,e);const oe={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(a,n,s,o,l,d,f){super();U(this,"_locale$",new R.BehaviorSubject("en"));U(this,"locale$",this._locale$.asObservable());this._instanceService=a,this._sheetInterceptorService=n,this._themeService=s,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=f,this._initInterceptorCellContent()}get locale(){const a=this._locale$.getValue();if(a)return a;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const a=new t.ObjectMatrix;this.disposeWithMe(R.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{a.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(m.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,s,o)=>{var C,p;const l=s.unitId,d=s.subUnitId;let f;const i=n;if(!i||i.v===void 0||i.v===null)return o(n);if(n!=null&&n.s){const c=s.workbook.getStyles().get(n.s);c!=null&&c.n&&(f=c.n)}if(f||(f=this._numfmtService.getValue(l,d,s.row,s.col)),!f||f.pattern==="General"||i.t!==t.CellValueType.NUMBER&&m.checkCellValueType(i.v)!==t.CellValueType.NUMBER)return o(n);if((!n||n===s.rawData)&&(n={...s.rawData}),t.isTextFormat(f.pattern))return(C=this._configService.getConfig(F))!=null&&C.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...oe},o(n));let _="";const T=a.getValue(s.row,s.col);if(T&&T.parameters===`${i.v}_${f.pattern}`)return o({...n,...T.result});const S=k(f.pattern,Number(i.v),this.locale);if(_=S.result,!_)return o(n);const M={v:_,t:t.CellValueType.NUMBER};if(S.color){const c=(p=this._themeService.getColorFromTheme(`${S.color}.500`))!=null?p:S.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return a.setValue(s.row,s.col,{result:M,parameters:`${i.v}_${f.pattern}`}),Object.assign(n,M),o(n)},priority:m.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===m.SetNumfmtMutation.id){const s=n.params;Object.keys(s.values).forEach(o=>{s.values[o].ranges.forEach(d=>{t.Range.foreach(d,(f,i)=>{a.realDeleteValue(f,i)})})})}else if(n.id===m.SetRangeValuesMutation.id){const s=n.params;new t.ObjectMatrix(s.cellValue).forValue((o,l)=>{a.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(R.switchMap(n=>{var s;return(s=n==null?void 0:n.activeSheet$)!=null?s:R.of(null)}),R.skip(1)).subscribe(()=>a.reset()))}setNumfmtLocal(a){this._locale$.next(a)}};exports.SheetsNumfmtCellContentController=se([b(0,t.IUniverInstanceService),b(1,t.Inject(m.SheetInterceptorService)),b(2,t.Inject(t.ThemeService)),b(3,t.Inject(t.ICommandService)),b(4,t.Inject(m.INumfmtService)),b(5,t.Inject(t.LocaleService)),b(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const ce="SHEET_NUMFMT_PLUGIN";var ie=Object.defineProperty,le=Object.getOwnPropertyDescriptor,ue=(e,r,a)=>r in e?ie(e,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[r]=a,me=(e,r,a,n)=>{for(var s=n>1?void 0:n?le(r,a):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(s=l(s)||s);return s},O=(e,r)=>(a,n)=>r(a,n,e),z=(e,r,a)=>ue(e,typeof r!="symbol"?r+"":r,a);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=w,a,n,s){super(),this._config=r,this._injector=a,this._configService=n,this._commandService=s;const{...o}=t.merge({},w,this._config);this._configService.setConfig(F,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){[B,q,W,K,I].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",ce);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=me([t.DependentOn(m.UniverSheetsPlugin),O(1,t.Inject(t.Injector)),O(2,t.IConfigService),O(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const fe=e=>L.find(a=>e.includes(a)),ge=()=>L.map(e=>({label:e,value:e})),de=e=>H.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),pe=()=>A.map(e=>({label:e.label,value:e.suffix})),Se=()=>G.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=B;exports.CURRENCYFORMAT=H;exports.DATEFMTLISG=A;exports.NUMBERFORMAT=G;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=F;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=I;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=q;exports.currencySymbols=L;exports.getCurrencyFormat=j;exports.getCurrencyFormatOptions=de;exports.getCurrencyOptions=ge;exports.getCurrencySymbolByLocale=V;exports.getCurrencySymbolIconByLocale=D;exports.getCurrencyType=fe;exports.getDateFormatOptions=pe;exports.getDecimalFromPattern=P;exports.getDecimalString=x;exports.getNumberFormatOptions=Se;exports.getNumfmtParseValueFilter=re;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=$;
1
+ "use strict";var Y=Object.defineProperty;var X=(e,r,s)=>r in e?Y(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s;var U=(e,r,s)=>X(e,typeof r!="symbol"?r+"":r,s);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("@univerjs/core"),f=require("@univerjs/sheets"),I=require("rxjs"),J=require("@univerjs/engine-formula"),L=["$","£","¥","¤","֏","؋","৳","฿","៛","₡","₦","₩","₪","₫","€","₭","₮","₱","₲","₴","₸","₹","₺","₼","₽","₾","₿","﷼"],E=new Map([[t.LocaleType.EN_US,"$"],[t.LocaleType.RU_RU,"₽"],[t.LocaleType.VI_VN,"₫"],[t.LocaleType.ZH_CN,"¥"],[t.LocaleType.ZH_TW,"NT$"],[t.LocaleType.FR_FR,"€"],[t.LocaleType.FA_IR,"﷼"],[t.LocaleType.KO_KR,"₩"],[t.LocaleType.ES_ES,"€"],[t.LocaleType.CA_ES,"€"]]);function V(e){switch(e){case t.LocaleType.CA_ES:case t.LocaleType.ES_ES:case t.LocaleType.FR_FR:return{icon:"EuroIcon",symbol:E.get(e)||"€",locale:e};case t.LocaleType.RU_RU:return{icon:"RoubleIcon",symbol:E.get(e)||"₽",locale:e};case t.LocaleType.ZH_CN:return{icon:"RmbIcon",symbol:E.get(e)||"¥",locale:e};case t.LocaleType.EN_US:default:return{icon:"DollarIcon",symbol:"$",locale:t.LocaleType.EN_US}}}function F(e){return E.get(e)||"$"}function A(e,r=2){let s=r;r>127&&(s=127);let n="";return s>0&&(n=`.${"0".repeat(s)}`),`"${F(e)}"#,##0${n}_);[Red]("${F(e)}"#,##0${n})`}const j=[{label:"1930-08-05",suffix:"yyyy-MM-dd"},{label:"1930/08/05",suffix:"yyyy/MM/dd"},{label:"1930年08月05日",suffix:'yyyy"年"MM"月"dd"日"'},{label:"08-05",suffix:"MM-dd"},{label:"8月5日",suffix:'M"月"d"日"'},{label:"13:30:30",suffix:"h:mm:ss"},{label:"13:30",suffix:"h:mm"},{label:"下午01:30",suffix:"A/P hh:mm"},{label:"下午1:30",suffix:"A/P h:mm"},{label:"下午1:30:30",suffix:"A/P h:mm:ss"},{label:"08-05 下午 01:30",suffix:"MM-dd A/P hh:mm"}],B=[{label:"(1,235)",suffix:"#,##0_);(#,##0)"},{label:"(1,235) ",suffix:"#,##0_);[Red](#,##0)",color:"red"},{label:"1,234.56",suffix:"#,##0.00_);#,##0.00"},{label:"1,234.56",suffix:"#,##0.00_);[Red]#,##0.00",color:"red"},{label:"-1,234.56",suffix:"#,##0.00_);-#,##0.00"},{label:"-1,234.56",suffix:"#,##0.00_);[Red]-#,##0.00",color:"red"}],G=[{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);"${e}"#,##0.00`},{label:e=>`${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]"${e}"#,##0.00`,color:"red"},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);("${e}"#,##0.00)`},{label:e=>`(${e}1,235)`,suffix:e=>`"${e}"#,##0.00_);[Red]("${e}"#,##0.00)`,color:"red"},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);-"${e}"#,##0.00`},{label:e=>`-${e}1,235`,suffix:e=>`"${e}"#,##0.00_);[Red]-"${e}"#,##0.00`,color:"red"}],P=(e,r=0)=>{var n;return e&&(n=t.numfmt.getFormatInfo(e).maxDecimals)!=null?n:r},x=e=>new Array(Math.min(Math.max(0,Number(e)),30)).fill(0).join(""),$=(e,r)=>e.split(";").map(n=>/\.0?/.test(n)?n.replace(/\.0*/g,`${r>0?".":""}${x(Number(r||0))}`):/0([^0]?)|0$/.test(n)?n.replace(/0([^0]+)|0$/,`0${r>0?".":""}${x(Number(r||0))}$1`):n).join(";"),Q=e=>/\.0?/.test(e)||/0([^0]?)|0$/.test(e),R={id:"sheet.command.numfmt.set.numfmt",type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;const s=e.get(t.ICommandService),n=e.get(t.IUniverInstanceService),a=e.get(t.IUndoRedoService),o=f.getSheetCommandTarget(n,r);if(!o)return!1;const{unitId:l,subUnitId:d,worksheet:i}=o,u=r.values.filter(c=>!!c.pattern),_=r.values.filter(c=>!c.pattern),T=f.transformCellsToRange(l,d,u),S={unitId:l,subUnitId:d,ranges:_.map(c=>({startColumn:c.col,startRow:c.row,endColumn:c.col,endRow:c.row}))},M=[],C=[];if(u.length){const c=u.reduce((g,m)=>{t.isTextFormat(m.pattern)&&g.setValue(m.row,m.col,{t:t.CellValueType.STRING});const v=i.getCellRaw(m.row,m.col);if(v){const N=f.checkCellValueType(v.v);N!==v.t&&g.setValue(m.row,m.col,{t:N})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?h.setValue(g,m,{t:v.t}):h.setValue(g,m,{t:void 0})}),Object.keys(T.values).forEach(g=>{const m=T.values[g];m.ranges=f.rangeMerge(m.ranges)}),M.push({id:f.SetNumfmtMutation.id,params:T});const y=f.factorySetNumfmtUndoMutation(e,T);C.push(...y)}if(_.length){S.ranges=f.rangeMerge(S.ranges);const c=_.reduce((g,m)=>{const v=i.getCellRaw(m.row,m.col);if(v){const N=f.checkCellValueType(v.v);N!==v.t&&g.setValue(m.row,m.col,{t:N})}return g},new t.ObjectMatrix).getMatrix(),h=new t.ObjectMatrix;new t.ObjectMatrix(c).forValue((g,m)=>{const v=i.getCellRaw(g,m);v?h.setValue(g,m,{t:v.t}):h.setValue(g,m,{t:void 0})}),M.push({id:f.RemoveNumfmtMutation.id,params:S},{id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:c}});const y=f.factoryRemoveNumfmtUndoMutation(e,S);C.push({id:f.SetRangeValuesMutation.id,params:{unitId:l,subUnitId:d,cellValue:h.getMatrix()}},...y)}const p=t.sequenceExecute(M,s).result;return p&&a.pushUndoRedo({unitID:l,undoMutations:C,redoMutations:M}),p}},H={id:"sheet.command.numfmt.add.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(M=>{t.Range.foreach(M.range,(C,p)=>{const c=n.getValue(d,i,C,p);if(!c){const y=l.worksheet.getCellRaw(C,p);if(!u&&y&&y.t===t.CellValueType.NUMBER&&y.v){const g=/\.(\d*)$/.exec(String(y.v));if(g){const m=g[1].length;if(!m)return;u=Math.max(u,m)}}return}const h=P(c.pattern);u=h>u?h:u})});const _=u+1,T=$(`0${_>0?".0":""}`,_),S=[];return o.forEach(M=>{t.Range.foreach(M.range,(C,p)=>{const c=n.getValue(d,i,C,p);if(!c)S.push({row:C,col:p,pattern:T});else{const h=P(c.pattern),y=$(c.pattern,h+1);y!==c.pattern&&S.push({row:C,col:p,pattern:y})}})}),S.length?await r.executeCommand(R.id,{values:S}):!1}},W={id:"sheet.command.numfmt.set.currency",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(t.LocaleService),a=s.getCurrentSelections();if(!a||!a.length)return!1;const o=[],l=V(n.getCurrentLocale()),d=A(l.locale);return a.forEach(u=>{t.Range.foreach(u.range,(_,T)=>{o.push({row:_,col:T,pattern:d,type:"currency"})})}),await r.executeCommand(R.id,{values:o})}},K={id:"sheet.command.numfmt.set.percent",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),n=e.get(f.SheetsSelectionsService).getCurrentSelections();if(!n||!n.length)return!1;const a=[],o="0%";return n.forEach(d=>{t.Range.foreach(d.range,(i,u)=>{a.push({row:i,col:u,pattern:o,type:"percent"})})}),await r.executeCommand(R.id,{values:a})}},q={id:"sheet.command.numfmt.subtract.decimal.command",type:t.CommandType.COMMAND,handler:async e=>{const r=e.get(t.ICommandService),s=e.get(f.SheetsSelectionsService),n=e.get(f.INumfmtService),a=e.get(t.IUniverInstanceService),o=s.getCurrentSelections();if(!o||!o.length)return!1;const l=f.getSheetCommandTarget(a);if(!l)return!1;const{unitId:d,subUnitId:i}=l;let u=0;o.forEach(C=>{t.Range.foreach(C.range,(p,c)=>{const h=n.getValue(d,i,p,c);if(!h){const g=l.worksheet.getCellRaw(p,c);if(!u&&g&&g.t===t.CellValueType.NUMBER&&g.v){const m=/\.(\d*)$/.exec(String(g.v));if(m){const v=m[1].length;if(!v)return;u=Math.max(u,v)}}return}const y=P(h.pattern);u=y>u?y:u})});const _=u-1,T=$(`0${_>0?".0":"."}`,_),S=[];return o.forEach(C=>{t.Range.foreach(C.range,(p,c)=>{const h=n.getValue(d,i,p,c);if(!h)S.push({row:p,col:c,pattern:T});else{const y=P(h.pattern);S.push({row:p,col:c,pattern:$(h.pattern,y-1)})}})}),await r.executeCommand(R.id,{values:S})}},D="sheets-numfmt.config",w={},ee=e=>t.numfmt.getFormatInfo(e).type||"unknown",Z=(e,r,s="en")=>{const n=t.numfmt.formatColor(e,r),a=n?String(n):void 0,o=t.numfmt.format(e,r,{locale:s,throws:!1});return r<0?{result:o,color:a}:{result:o}},k=(e,r,s)=>e===t.DEFAULT_NUMBER_FORMAT?{result:String(J.stripErrorMargin(r))}:Z(e,r,s),te=new Set(["m d"]),ne=new Set(["h:mm AM/PM","hh:mm AM/PM"]),re=e=>{var n,a;const r=(a=(n=t.numfmt.parseDate(e))!=null?n:t.numfmt.parseTime(e))!=null?a:t.numfmt.parseNumber(e);if(!r)return null;const{z:s}=r;return s&&(te.has(s)||ne.has(s)&&!/\s(A|AM|P|PM)$/i.test(e))?null:r};var se=Object.getOwnPropertyDescriptor,ae=(e,r,s,n)=>{for(var a=n>1?void 0:n?se(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},b=(e,r)=>(s,n)=>r(s,n,e);const oe={tl:{size:6,color:"#409f11"}};exports.SheetsNumfmtCellContentController=class extends t.Disposable{constructor(s,n,a,o,l,d,i){super();U(this,"_locale$",new I.BehaviorSubject("en"));U(this,"locale$",this._locale$.asObservable());this._instanceService=s,this._sheetInterceptorService=n,this._themeService=a,this._commandService=o,this._numfmtService=l,this._localeService=d,this._configService=i,this._initInterceptorCellContent()}get locale(){const s=this._locale$.getValue();if(s)return s;switch(this._localeService.getCurrentLocale()){case t.LocaleType.FR_FR:return"fr";case t.LocaleType.RU_RU:return"ru";case t.LocaleType.VI_VN:return"vi";case t.LocaleType.ZH_CN:return"zh-CN";case t.LocaleType.KO_KR:return"ko";case t.LocaleType.ZH_TW:return"zh-TW";case t.LocaleType.ES_ES:case t.LocaleType.CA_ES:return"es";case t.LocaleType.EN_US:case t.LocaleType.FA_IR:default:return"en"}}_initInterceptorCellContent(){const s=new t.ObjectMatrix;this.disposeWithMe(I.merge(this._locale$,this._localeService.currentLocale$).subscribe(()=>{s.reset()})),this.disposeWithMe(this._sheetInterceptorService.intercept(f.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Value|t.InterceptorEffectEnum.Style,handler:(n,a,o)=>{var C,p;if(!n||n.v===void 0||n.v===null)return o(n);const l=a.unitId,d=a.subUnitId;let i;if(n!=null&&n.s){const c=a.workbook.getStyles().get(n.s);c!=null&&c.n&&(i=c.n)}if(i||(i=this._numfmtService.getValue(l,d,a.row,a.col)),t.isDefaultFormat(i==null?void 0:i.pattern)||n.t!==t.CellValueType.NUMBER&&f.checkCellValueType(n.v)!==t.CellValueType.NUMBER)return o(n);const u=n;if((!n||n===a.rawData)&&(n={...a.rawData}),t.isTextFormat(i==null?void 0:i.pattern))return(C=this._configService.getConfig(D))!=null&&C.disableTextFormatMark?(n.t=t.CellValueType.STRING,o(n)):(n.t=t.CellValueType.STRING,n.markers={...n==null?void 0:n.markers,...oe},o(n));let _="";const T=s.getValue(a.row,a.col);if(T&&T.parameters===`${u.v}_${i==null?void 0:i.pattern}`)return o({...n,...T.result});const S=k(i==null?void 0:i.pattern,Number(u.v),this.locale);if(_=S.result,!_)return o(n);const M={v:_,t:t.CellValueType.NUMBER};if(S.color){const c=(p=this._themeService.getColorFromTheme(`${S.color}.500`))!=null?p:S.color;c&&(M.interceptorStyle={cl:{rgb:c}})}return s.setValue(a.row,a.col,{result:M,parameters:`${u.v}_${i==null?void 0:i.pattern}`}),Object.assign(n,M),o(n)},priority:f.InterceptCellContentPriority.NUMFMT})),this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id===f.SetNumfmtMutation.id){const a=n.params;Object.keys(a.values).forEach(o=>{a.values[o].ranges.forEach(d=>{t.Range.foreach(d,(i,u)=>{s.realDeleteValue(i,u)})})})}else if(n.id===f.SetRangeValuesMutation.id){const a=n.params;new t.ObjectMatrix(a.cellValue).forValue((o,l)=>{s.realDeleteValue(o,l)})}})),this.disposeWithMe(this._instanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe(I.switchMap(n=>{var a;return(a=n==null?void 0:n.activeSheet$)!=null?a:I.of(null)}),I.skip(1)).subscribe(()=>s.reset()))}setNumfmtLocal(s){this._locale$.next(s)}};exports.SheetsNumfmtCellContentController=ae([b(0,t.IUniverInstanceService),b(1,t.Inject(f.SheetInterceptorService)),b(2,t.Inject(t.ThemeService)),b(3,t.Inject(t.ICommandService)),b(4,t.Inject(f.INumfmtService)),b(5,t.Inject(t.LocaleService)),b(6,t.IConfigService)],exports.SheetsNumfmtCellContentController);const ce="SHEET_NUMFMT_PLUGIN";var ie=Object.defineProperty,le=Object.getOwnPropertyDescriptor,ue=(e,r,s)=>r in e?ie(e,r,{enumerable:!0,configurable:!0,writable:!0,value:s}):e[r]=s,me=(e,r,s,n)=>{for(var a=n>1?void 0:n?le(r,s):r,o=e.length-1,l;o>=0;o--)(l=e[o])&&(a=l(a)||a);return a},O=(e,r)=>(s,n)=>r(s,n,e),z=(e,r,s)=>ue(e,typeof r!="symbol"?r+"":r,s);exports.UniverSheetsNumfmtPlugin=class extends t.Plugin{constructor(r=w,s,n,a){super(),this._config=r,this._injector=s,this._configService=n,this._commandService=a;const{...o}=t.merge({},w,this._config);this._configService.setConfig(D,o)}onStarting(){t.registerDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]]),t.touchDependencies(this._injector,[[exports.SheetsNumfmtCellContentController]])}onRendered(){[H,q,W,K,R].forEach(r=>{this.disposeWithMe(this._commandService.registerCommand(r))})}};z(exports.UniverSheetsNumfmtPlugin,"pluginName",ce);z(exports.UniverSheetsNumfmtPlugin,"type",t.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsNumfmtPlugin=me([t.DependentOn(f.UniverSheetsPlugin),O(1,t.Inject(t.Injector)),O(2,t.IConfigService),O(3,t.ICommandService)],exports.UniverSheetsNumfmtPlugin);const fe=e=>L.find(s=>e.includes(s)),ge=()=>L.map(e=>({label:e,value:e})),de=e=>G.map(r=>({label:r.label(e),value:r.suffix(e),color:r.color})),pe=()=>j.map(e=>({label:e.label,value:e.suffix})),Se=()=>B.map(e=>({label:e.label,value:e.suffix,color:e.color}));exports.AddDecimalCommand=H;exports.CURRENCYFORMAT=G;exports.DATEFMTLISG=j;exports.NUMBERFORMAT=B;exports.SHEETS_NUMFMT_PLUGIN_CONFIG_KEY=D;exports.SetCurrencyCommand=W;exports.SetNumfmtCommand=R;exports.SetPercentCommand=K;exports.SubtractDecimalCommand=q;exports.currencySymbols=L;exports.getCurrencyFormat=A;exports.getCurrencyFormatOptions=de;exports.getCurrencyOptions=ge;exports.getCurrencySymbolByLocale=F;exports.getCurrencySymbolIconByLocale=V;exports.getCurrencyType=fe;exports.getDateFormatOptions=pe;exports.getDecimalFromPattern=P;exports.getDecimalString=x;exports.getNumberFormatOptions=Se;exports.getNumfmtParseValueFilter=re;exports.getPatternPreview=Z;exports.getPatternPreviewIgnoreGeneral=k;exports.getPatternType=ee;exports.isPatternHasDecimal=Q;exports.localeCurrencySymbolMap=E;exports.setPatternDecimal=$;