/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var it=Object.create;var Ce=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var at=Object.getOwnPropertyNames;var ot=Object.getPrototypeOf,lt=Object.prototype.hasOwnProperty;var ct=(p,e)=>()=>(e||p((e={exports:{}}).exports,e),e.exports),ht=(p,e)=>{for(var t in e)Ce(p,t,{get:e[t],enumerable:!0})},je=(p,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of at(e))!lt.call(p,n)&&n!==t&&Ce(p,n,{get:()=>e[n],enumerable:!(r=nt(e,n))||r.enumerable});return p};var ut=(p,e,t)=>(t=p!=null?it(ot(p)):{},je(e||!p||!p.__esModule?Ce(t,"default",{value:p,enumerable:!0}):t,p)),dt=p=>je(Ce({},"__esModule",{value:!0}),p);var Ke=ct((He,Oe)=>{((p,e)=>{typeof define=="function"&&define.amd?define([],e):typeof Oe=="object"&&typeof He!="undefined"?Oe.exports=e():p.Papa=e()})(He,function p(){var e=typeof self!="undefined"?self:typeof window!="undefined"?window:e!==void 0?e:{},t,r=!e.document&&!!e.postMessage,n=e.IS_PAPA_WORKER||!1,o={},u=0,s={};function c(i){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},function(a){var l=oe(a);l.chunkSize=parseInt(l.chunkSize),a.step||a.chunk||(l.chunkSize=null),this._handle=new y(l),(this._handle.streamer=this)._config=l}.call(this,i),this.parseChunk=function(a,l){var m=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0=this._config.preview),n)e.postMessage({results:g,workerId:s.WORKER_ID,finished:m});else if(N(this._config.chunk)&&!l){if(this._config.chunk(g,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=g=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(g.data),this._completeResults.errors=this._completeResults.errors.concat(g.errors),this._completeResults.meta=g.meta),this._completed||!m||!N(this._config.complete)||g&&g.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),m||g&&g.meta.paused||this._nextChunk(),g}this._halted=!0},this._sendError=function(a){N(this._config.error)?this._config.error(a):n&&this._config.error&&e.postMessage({workerId:s.WORKER_ID,error:a,finished:!1})}}function h(i){var a;(i=i||{}).chunkSize||(i.chunkSize=s.RemoteChunkSize),c.call(this,i),this._nextChunk=r?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(l){this._input=l,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(a=new XMLHttpRequest,this._config.withCredentials&&(a.withCredentials=this._config.withCredentials),r||(a.onload=j(this._chunkLoaded,this),a.onerror=j(this._chunkError,this)),a.open(this._config.downloadRequestBody?"POST":"GET",this._input,!r),this._config.downloadRequestHeaders){var l,m=this._config.downloadRequestHeaders;for(l in m)a.setRequestHeader(l,m[l])}var g;this._config.chunkSize&&(g=this._start+this._config.chunkSize-1,a.setRequestHeader("Range","bytes="+this._start+"-"+g));try{a.send(this._config.downloadRequestBody)}catch(L){this._chunkError(L.message)}r&&a.status===0&&this._chunkError()}},this._chunkLoaded=function(){a.readyState===4&&(a.status<200||400<=a.status?this._chunkError():(this._start+=this._config.chunkSize||a.responseText.length,this._finished=!this._config.chunkSize||this._start>=(l=>(l=l.getResponseHeader("Content-Range"))!==null?parseInt(l.substring(l.lastIndexOf("/")+1)):-1)(a),this.parseChunk(a.responseText)))},this._chunkError=function(l){l=a.statusText||l,this._sendError(new Error(l))}}function E(i){(i=i||{}).chunkSize||(i.chunkSize=s.LocalChunkSize),c.call(this,i);var a,l,m=typeof FileReader!="undefined";this.stream=function(g){this._input=g,l=g.slice||g.webkitSlice||g.mozSlice,m?((a=new FileReader).onload=j(this._chunkLoaded,this),a.onerror=j(this._chunkError,this)):a=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount=this._input.size,this.parseChunk(g.target.result)},this._chunkError=function(){this._sendError(a.error)}}function x(i){var a;c.call(this,i=i||{}),this.stream=function(l){return a=l,this._nextChunk()},this._nextChunk=function(){var l,m;if(!this._finished)return l=this._config.chunkSize,a=l?(m=a.substring(0,l),a.substring(l)):(m=a,""),this._finished=!a,this.parseChunk(m)}}function $(i){c.call(this,i=i||{});var a=[],l=!0,m=!1;this.pause=function(){c.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){c.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(g){this._input=g,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){m&&a.length===1&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),a.length?this.parseChunk(a.shift()):l=!0},this._streamData=j(function(g){try{a.push(typeof g=="string"?g:g.toString(this._config.encoding)),l&&(l=!1,this._checkIsFinished(),this.parseChunk(a.shift()))}catch(L){this._streamError(L)}},this),this._streamError=j(function(g){this._streamCleanUp(),this._sendError(g)},this),this._streamEnd=j(function(){this._streamCleanUp(),m=!0,this._streamData("")},this),this._streamCleanUp=j(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function y(i){var a,l,m,g,L=Math.pow(2,53),Q=-L,V=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,Y=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,M=this,K=0,R=0,X=!1,f=!1,w=[],d={data:[],errors:[],meta:{}};function _(b){return i.skipEmptyLines==="greedy"?b.join("").trim()==="":b.length===1&&b[0].length===0}function v(){if(d&&m&&(A("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+s.DefaultDelimiter+"'"),m=!1),i.skipEmptyLines&&(d.data=d.data.filter(function(S){return!_(S)})),C()){let S=function(U,H){N(i.transformHeader)&&(U=i.transformHeader(U,H)),w.push(U)};var I=S;if(d)if(Array.isArray(d.data[0])){for(var b=0;C()&&b(J=>(i.dynamicTypingFunction&&i.dynamicTyping[J]===void 0&&(i.dynamicTyping[J]=i.dynamicTypingFunction(J)),(i.dynamicTyping[J]||i.dynamicTyping)===!0))(F)?W==="true"||W==="TRUE"||W!=="false"&&W!=="FALSE"&&((J=>{if(V.test(J)&&(J=parseFloat(J),Q=w.length?"__parsed_extra":w[q]:T,Z=i.transform?i.transform(Z,T):Z);T==="__parsed_extra"?(H[T]=H[T]||[],H[T].push(Z)):H[T]=Z}return i.header&&(q>w.length?A("FieldMismatch","TooManyFields","Too many fields: expected "+w.length+" fields but parsed "+q,R+U):qi.preview?l.abort():(d.data=d.data[0],g(d,M))))}),this.parse=function(b,O,B){var I=i.quoteChar||'"',I=(i.newline||(i.newline=this.guessLineEndings(b,I)),m=!1,i.delimiter?N(i.delimiter)&&(i.delimiter=i.delimiter(b),d.meta.delimiter=i.delimiter):((I=((S,U,H,q,T)=>{var Z,F,W,J;T=T||[","," ","|",";",s.RECORD_SEP,s.UNIT_SEP];for(var fe=0;fe=B.length/2?`\r `:"\r"}}function D(i){return i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function z(i){var a=(i=i||{}).delimiter,l=i.newline,m=i.comments,g=i.step,L=i.preview,Q=i.fastMode,V=null,Y=!1,M=i.quoteChar==null?'"':i.quoteChar,K=M;if(i.escapeChar!==void 0&&(K=i.escapeChar),(typeof a!="string"||-1=L)return te(!0);break}B.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:O.length,index:R}),F++}}else if(m&&I.length===0&&f.substring(R,R+A)===m){if(T===-1)return te();R=T+C,T=f.indexOf(l,R),q=f.indexOf(a,R)}else if(q!==-1&&(q=L)return te(!0)}return le();function J(G){O.push(G),S=R}function fe(G){var re=0;return re=G!==-1&&(G=f.substring(F+1,G))&&G.trim()===""?G.length:re}function le(G){return d||(G===void 0&&(G=f.substring(R)),I.push(G),R=_,J(I),b&&ce()),te()}function be(G){R=G,J(I),I=[],T=f.indexOf(l,R)}function te(G){if(i.header&&!w&&O.length&&!Y){var re=O[0],de={},Ae=new Set(re);let We=!1;for(let ge=0;gem.charCodeAt(0)!==65279?m:m.slice(1))(i),l=new(a.download?h:x)(a)):i.readable===!0&&N(i.read)&&N(i.on)?l=new $(a):(e.File&&i instanceof File||i instanceof Object)&&(l=new E(a)),l.stream(i);(l=(()=>{var m;return!!s.WORKERS_SUPPORTED&&(m=(()=>{var g=e.URL||e.webkitURL||null,L=p.toString();return s.BLOB_URL||(s.BLOB_URL=g.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ","(",L,")();"],{type:"text/javascript"})))})(),(m=new e.Worker(m)).onmessage=ee,m.id=u++,o[m.id]=m)})()).userStep=a.step,l.userChunk=a.chunk,l.userComplete=a.complete,l.userError=a.error,a.step=N(a.step),a.chunk=N(a.chunk),a.complete=N(a.complete),a.error=N(a.error),delete a.worker,l.postMessage({input:i,config:a,workerId:l.id})},s.unparse=function(i,a){var l=!1,m=!0,g=",",L=`\r `,Q='"',V=Q+Q,Y=!1,M=null,K=!1,R=((()=>{if(typeof a=="object"){if(typeof a.delimiter!="string"||s.BAD_DELIMITERS.filter(function(w){return a.delimiter.indexOf(w)!==-1}).length||(g=a.delimiter),typeof a.quotes!="boolean"&&typeof a.quotes!="function"&&!Array.isArray(a.quotes)||(l=a.quotes),typeof a.skipEmptyLines!="boolean"&&typeof a.skipEmptyLines!="string"||(Y=a.skipEmptyLines),typeof a.newline=="string"&&(L=a.newline),typeof a.quoteChar=="string"&&(Q=a.quoteChar),typeof a.header=="boolean"&&(m=a.header),Array.isArray(a.columns)){if(a.columns.length===0)throw new Error("Option columns is empty");M=a.columns}a.escapeChar!==void 0&&(V=a.escapeChar+Q),a.escapeFormulae instanceof RegExp?K=a.escapeFormulae:typeof a.escapeFormulae=="boolean"&&a.escapeFormulae&&(K=/^[=+\-@\t\r].*$/)}})(),new RegExp(D(Q),"g"));if(typeof i=="string"&&(i=JSON.parse(i)),Array.isArray(i)){if(!i.length||Array.isArray(i[0]))return X(null,i,Y);if(typeof i[0]=="object")return X(M||Object.keys(i[0]),i,Y)}else if(typeof i=="object")return typeof i.data=="string"&&(i.data=JSON.parse(i.data)),Array.isArray(i.data)&&(i.fields||(i.fields=i.meta&&i.meta.fields||M),i.fields||(i.fields=Array.isArray(i.data[0])?i.fields:typeof i.data[0]=="object"?Object.keys(i.data[0]):[]),Array.isArray(i.data[0])||typeof i.data[0]=="object"||(i.data=[i.data])),X(i.fields||[],i.data||[],Y);throw new Error("Unable to serialize unrecognized input");function X(w,d,_){var v="",C=(typeof w=="string"&&(w=JSON.parse(w)),typeof d=="string"&&(d=JSON.parse(d)),Array.isArray(w)&&0{for(var b=0;bIe});module.exports=dt(mt);var pe=require("obsidian");var ne=require("obsidian");var Se=ut(Ke()),Fe=require("obsidian");var Qe={buttons:{undo:"\u64A4\u9500",redo:"\u91CD\u505A",addRow:"\u6DFB\u52A0\u884C",deleteRow:"\u5220\u9664\u884C",addColumn:"\u6DFB\u52A0\u5217",deleteColumn:"\u5220\u9664\u5217",resetColumnWidth:"\u91CD\u7F6E\u5217\u5BBD",sourceMode:"\u6E90\u7801\u6A21\u5F0F",tableMode:"\u8868\u683C\u6A21\u5F0F",insertRowBefore:"\u4E0A\u65B9\u63D2\u5165\u884C",insertRowAfter:"\u4E0B\u65B9\u63D2\u5165\u884C"},editBar:{placeholder:"\u7F16\u8F91\u9009\u4E2D\u5355\u5143\u683C..."},csv:{error:"\u9519\u8BEF",parsingFailed:"CSV\u89E3\u6790\u5931\u8D25\uFF0C\u8BF7\u68C0\u67E5\u6587\u4EF6\u683C\u5F0F",parseWarning:"CSV\u89E3\u6790\u63D0\u793A:"},settings:{fieldSeparator:"\u5B57\u6BB5\u5206\u9694\u7B26",fieldSeparatorDesc:"\u7528\u4E8E\u5206\u9694\u5B57\u6BB5\u7684\u5B57\u7B26\uFF08\u4F8B\u5982\uFF1A\u9017\u53F7\u3001\u5206\u53F7\u3001\u5236\u8868\u7B26\uFF09",quoteChar:"\u5F15\u53F7\u5B57\u7B26",quoteCharDesc:"\u7528\u4E8E\u5305\u56F4\u542B\u6709\u7279\u6B8A\u5B57\u7B26\u7684\u5B57\u6BB5"},search:{placeholder:"\u641C\u7D22\u8868\u683C\u5185\u5BB9...",noResults:"\u672A\u627E\u5230\u5339\u914D\u7ED3\u679C",moreResults:"\u8FD8\u6709 {count} \u4E2A\u7ED3\u679C...",rowColumn:"\u7B2C{row}\u884C\uFF0C\u7B2C{col}\u5217"},table:{headerRow:"\u8868\u5934\u884C",dataRow:"\u6570\u636E\u884C"},contextMenu:{insertRowAbove:"\u4E0A\u65B9\u63D2\u5165\u884C",insertRowBelow:"\u4E0B\u65B9\u63D2\u5165\u884C",deleteRow:"\u5220\u9664\u672C\u884C",moveRowUp:"\u5411\u4E0A\u79FB\u52A8\u4E00\u884C",moveRowDown:"\u5411\u4E0B\u79FB\u52A8\u4E00\u884C",insertColLeft:"\u5DE6\u4FA7\u63D2\u5165\u5217",insertColRight:"\u53F3\u4FA7\u63D2\u5165\u5217",deleteCol:"\u5220\u9664\u672C\u5217",moveColLeft:"\u5411\u5DE6\u79FB\u52A8\u4E00\u5217",moveColRight:"\u5411\u53F3\u79FB\u52A8\u4E00\u5217",createNewCsv:"\u521B\u5EFA\u65B0 CSV \u6587\u4EF6"},commands:{createNewCsv:"\u521B\u5EFA\u65B0 CSV \u6587\u4EF6",fileExists:"\u6587\u4EF6\u5DF2\u5B58\u5728"},tableMessages:{atLeastOneRow:"\u81F3\u5C11\u9700\u8981\u4FDD\u7559\u4E00\u884C",atLeastOneColumn:"\u81F3\u5C11\u9700\u8981\u4FDD\u7559\u4E00\u5217"},notifications:{undo:"\u5DF2\u64A4\u9500\u4E0A\u4E00\u6B65\u64CD\u4F5C",noMoreUndo:"\u6CA1\u6709\u66F4\u591A\u53EF\u64A4\u9500\u7684\u64CD\u4F5C",redo:"\u5DF2\u91CD\u505A\u64CD\u4F5C",noMoreRedo:"\u6CA1\u6709\u66F4\u591A\u53EF\u91CD\u505A\u7684\u64CD\u4F5C"}};var Ye={buttons:{undo:"Undo",redo:"Redo",addRow:"Add row",deleteRow:"Delete row",addColumn:"Add column",deleteColumn:"Delete column",resetColumnWidth:"Reset column width",sourceMode:"Source Mode",tableMode:"Table Mode"},editBar:{placeholder:"Edit selected cell..."},csv:{error:"Error",parsingFailed:"Failed to parse CSV. Please check file format.",parseWarning:"CSV parse warning:"},settings:{fieldSeparator:"Field Separator",fieldSeparatorDesc:"The character used to separate fields (e.g., comma, semicolon, tab)",quoteChar:"Quote Character",quoteCharDesc:"Character used to enclose fields containing special characters"},search:{placeholder:"Search table content...",noResults:"No matching results found",moreResults:"{count} more results...",rowColumn:"Row {row}, Column {col}"},table:{headerRow:"Header Row",dataRow:"Data Row"},contextMenu:{insertRowAbove:"Insert row above",insertRowBelow:"Insert row below",deleteRow:"Delete this row",moveRowUp:"Move row up",moveRowDown:"Move row down",insertColLeft:"Insert column left",insertColRight:"Insert column right",deleteCol:"Delete this column",moveColLeft:"Move column left",moveColRight:"Move column right",createNewCsv:"Create new CSV file"},commands:{createNewCsv:"Create new CSV file",fileExists:"File already exists"},tableMessages:{atLeastOneRow:"At least one row must remain",atLeastOneColumn:"At least one column must remain"},notifications:{undo:"Undid last action",noMoreUndo:"There is nothing more to undo",redo:"Redid action",noMoreRedo:"There is nothing more to redo"}};var Je={"zh-cn":Qe,en:Ye},qe=class{constructor(e){this.locale="en";this.setLocale(e||"en")}setLocale(e){console.log(`I18n: Attempting to set locale to '${e}'`);let t=e.toLowerCase(),r="en";t.startsWith("zh")?r="zh-cn":t.startsWith("en")&&(r="en"),r in Je?(this.locale=r,console.log(`I18n: Successfully set locale to '${this.locale}'`)):(this.locale="en",console.warn(`I18n: Locale '${r}' is not fully supported, falling back to 'en'`))}t(e,t){let r=this.getTranslation(e,this.locale);r===null&&this.locale!=="en"&&(console.warn(`I18n: Key '${e}' not found in '${this.locale}', falling back to 'en'.`),r=this.getTranslation(e,"en"));let n=r!=null?r:e;return t&&Object.keys(t).forEach(o=>{let u=`{${o}}`;n=n.replace(new RegExp(u,"g"),String(t[o]))}),n}getTranslation(e,t){let r=Je[t],n=e.split("."),o=r;for(let u of n)if(o&&typeof o=="object"&&u in o)o=o[u];else return null;return typeof o=="string"?o:null}getCurrentLocale(){return this.locale}},k=new qe;var ue=class{static detectDelimiter(e,t='"'){if(!e||e.length===0)return",";let r=[",",";"," ","|"],n=[],o="",u=!1;for(let E=0;E0&&n.push(o);let s=n.map(E=>E).filter(E=>E.trim().length>0).slice(0,20);if(s.length===0)return",";function c(E,x){let $=!1,y=0;for(let D=0;Dc(z,E)),$=x.reduce((z,ee)=>z+ee,0)/x.length,y=x.reduce((z,ee)=>z+Math.pow(ee-$,2),0)/x.length,D=($>1?$:0)-y*.1;(!h||D>h.score)&&(h={delim:E,score:D,avgFields:$,consistency:y})}return h&&h.avgFields>=1.5?h.delim:","}static parseCSV(e,t){try{let r={...this.defaultConfig,...t};if(!r.delimiter||r.delimiter==="auto"){let o=this.detectDelimiter(e,r.quoteChar);r.delimiter=o}let n=Se.parse(e,r);return n.errors&&n.errors.length>0&&(console.warn("CSV parse warnings:",n.errors),new Fe.Notice(`${k.t("csv.parseWarning")} ${n.errors[0].message}`)),n.data}catch(r){return console.error("CSV parse error:",r),new Fe.Notice(k.t("csv.parsingFailed")),[[""]]}}static unparseCSV(e,t){return Se.unparse(e,{...{header:!1,newline:` `},...t})}static normalizeTableData(e){if(!e||e.length===0)return[[""]];let t=0;for(let n of e)n&&(t=Math.max(t,n.length));return e.map(n=>{let o=n?[...n]:[];for(;o.lengththis.maxSize?this.history.shift():this.currentIndex++}undo(){return this.canUndo()?(this.currentIndex--,new ye.Notice(k.t("notifications.undo")),this.getCurrentState()):(new ye.Notice(k.t("notifications.noMoreUndo")),null)}redo(){return this.canRedo()?(this.currentIndex++,new ye.Notice(k.t("notifications.redo")),this.getCurrentState()):(new ye.Notice(k.t("notifications.noMoreRedo")),null)}getCurrentState(){return this.currentIndex>=0&&this.currentIndex0}canRedo(){return this.currentIndex0&&Array.isArray(e[0])?e.map(t=>[...t]):[...e]:typeof e=="object"&&e!==null?JSON.parse(JSON.stringify(e)):e}},Ee=class extends Pe{cloneState(e){return e.map(t=>[...t])}};var ze=require("obsidian");var ae=class{static calculateColumnWidths(e){if(!e||e.length===0||!e[0])return[];let t=e[0].map(()=>100);return e.forEach(r=>{r.forEach((n,o)=>{let u=Math.max(50,Math.min(300,n.length*10));t[o]=Math.max(t[o],u)})}),t}static addRow(e){let t=e.length>0?e[0].length:1,r=Array(t).fill("");return[...e,r]}static deleteRow(e){return e.length<=1?(new ze.Notice(k.t("tableMessages.atLeastOneRow")),e):e.slice(0,-1)}static addColumn(e){return e.map(t=>[...t,""])}static deleteColumn(e){return!e[0]||e[0].length<=1?(new ze.Notice(k.t("tableMessages.atLeastOneColumn")),e):e.map(t=>t.slice(0,-1))}static addColumnToLeft(e,t){return!e||e.length===0?[]:e.map(r=>{let n=[...r];return n.splice(t,0,""),n})}static addColumnToRight(e,t){return!e||e.length===0?[]:e.map(r=>{let n=[...r];return n.splice(t+1,0,""),n})}static getColumnLabel(e){let t="",r=e;for(;r>=0;)t=String.fromCharCode(65+r%26)+t,r=Math.floor(r/26)-1;return t}static getCellAddress(e,t){let r=this.getColumnLabel(t),n=e+1;return`${r}${n}`}static getTableData(e){return Array.from(e.querySelectorAll("tr")).map(r=>Array.from(r.querySelectorAll("td, th")).map(o=>o.textContent||""))}};var Xe=require("obsidian"),me=class{static async withRetry(e,t=3,r=500){let n=new Error("Unknown error occurred");for(let o=0;o<=t;o++)try{return await e()}catch(u){if(n=u,!(u instanceof Error&&(u.message.includes("EBUSY")||u.message.includes("busy")||u.message.includes("locked")))||o===t)break;o===0&&new Xe.Notice(`File is busy. Retrying... (${o+1}/${t})`),await new Promise(c=>setTimeout(c,r))}throw n}};function Re(p){let{editBarEl:e,editInput:t,activeCellEl:r,activeRowIndex:n,activeColIndex:o,tableData:u,onEdit:s}=p;if(r){t.value=r.value;let c=ae.getCellAddress(n,o);e.setAttribute("data-cell-address",c),r.value?t.placeholder="":t.placeholder=c}else t.value="",t.placeholder=k.t("editBar.placeholder"),e.removeAttribute("data-cell-address");t.oninput=null,t.oninput=()=>{r&&n>=0&&o>=0&&(r.value=t.value,u[n][o]!==t.value&&s(n,o,t.value))}}var xe=class{constructor(e,t){this.searchMatches=[];this.currentSearchIndex=-1;this.options=t,this.searchContainer=e.createEl("div",{cls:"csv-search-container"}),this.searchInput=this.searchContainer.createEl("input",{cls:"csv-search-input",attr:{type:"text",placeholder:k.t("search.placeholder")}}),this.searchResults=this.searchContainer.createEl("div",{cls:"csv-search-results"}),this.setupSearchEvents()}setupSearchEvents(){let e;this.searchInput.addEventListener("input",()=>{clearTimeout(e),e=setTimeout(()=>{this.performSearch(this.searchInput.value)},300)}),this.searchInput.addEventListener("focus",()=>{this.searchMatches.length>0&&this.searchResults.classList.add("show")}),this.searchInput.addEventListener("keydown",t=>{t.key==="ArrowDown"?(t.preventDefault(),this.navigateSearchResults(1)):t.key==="ArrowUp"?(t.preventDefault(),this.navigateSearchResults(-1)):t.key==="Enter"?(t.preventDefault(),this.selectCurrentSearchResult()):t.key==="Escape"&&(this.searchInput.value="",this.performSearch(""),this.hideSearchResults())}),document.addEventListener("click",t=>{this.searchContainer.contains(t.target)||this.hideSearchResults()})}performSearch(e){if(this.searchMatches=[],this.currentSearchIndex=-1,!e.trim()){this.hideSearchResults(),this.options.clearSearchHighlights();return}let t=e.toLowerCase().trim(),r=this.options.getTableData();for(let n=0;n{let o=this.searchResults.createEl("div",{cls:"csv-search-result-item"}),u=o.createEl("div");u.createEl("span",{cls:"csv-search-result-cell",text:this.options.getCellAddress(r.row,r.col)}),u.createEl("span",{cls:"csv-search-result-address",text:k.t("search.rowColumn",{row:(r.row+1).toString(),col:(r.col+1).toString()})});let s=o.createEl("div",{cls:"csv-search-result-preview"});s.innerHTML=this.highlightSearchTerm(r.value,e),o.addEventListener("click",()=>{this.options.jumpToCell(r.row,r.col),this.hideSearchResults()}),o.setAttribute("data-index",n.toString())}),this.searchMatches.length>10){let r=this.searchResults.createEl("div",{cls:"csv-search-result-item",text:k.t("search.moreResults",{count:(this.searchMatches.length-10).toString()})});r.style.color="var(--text-muted)",r.style.fontStyle="italic"}this.searchResults.classList.add("show")}highlightSearchTerm(e,t){if(!t.trim())return e;let r=new RegExp(`(${t.replace(/[.*+?^${}()|[\\]\\]/g,"\\$&")})`,"gi");return e.replace(r,'$1')}navigateSearchResults(e){let t=this.searchResults.querySelectorAll(".csv-search-result-item[data-index]");if(t.length===0)return;t.forEach(n=>n.classList.remove("csv-search-result-hover")),this.currentSearchIndex=Math.max(0,Math.min(t.length-1,this.currentSearchIndex+e));let r=t[this.currentSearchIndex];r&&(r.classList.add("csv-search-result-hover"),r.scrollIntoView({block:"nearest"}))}selectCurrentSearchResult(){if(this.currentSearchIndex>=0&&this.currentSearchIndexu.index>=h.index&&u.indexc.index-h.index);let s=0;for(let c of t)c.index>s&&e.push({text:p.substring(s,c.index),isUrl:!1}),e.push({text:c.displayText,isUrl:!0,url:c.url,displayText:c.displayText}),s=c.index+c.length;return s{u.stopPropagation()},t.appendChild(o)}else{let o=document.createElement("span");o.textContent=n.text,t.appendChild(o)}if(e){let n=document.createElement("span");n.className="csv-cell-edit-btn",n.textContent="\u270E",n.title="Click to edit",n.onclick=o=>{o.stopPropagation(),e()},t.appendChild(n),t.onclick=o=>{o.target.tagName!=="A"&&e()}}return t}function et(p){let{tableData:e,columnWidths:t,autoResize:r,tableEl:n,editInput:o,activeCellEl:u,activeRowIndex:s,activeColIndex:c,setActiveCell:h,saveSnapshot:E,requestSave:x,setupAutoResize:$,adjustInputHeight:y,selectRow:D,selectColumn:z,getColumnLabel:ee,setupColumnResize:P,insertRowAt:ie,deleteRowAt:oe,insertColAt:j,deleteColAt:N,renderEditBar:i,onColumnReorder:a,onRowReorder:l,stickyRows:m,stickyColumns:g,toggleRowSticky:L,toggleColumnSticky:Q}=p;n.empty(),window._csvLiteDragState||(window._csvLiteDragState={type:null,index:null});let V=window._csvLiteDragState;function Y(f,w){V.type=f,V.index=w,n.classList.remove("csv-dragging-row","csv-dragging-col"),f==="row"&&n.classList.add("csv-dragging-row"),f==="col"&&n.classList.add("csv-dragging-col")}if(t.length===0&&e[0]){let f=ae.calculateColumnWidths(e);t.splice(0,t.length,...f)}let M=n.createEl("thead").createEl("tr"),K=M.createEl("th",{cls:"csv-corner-cell"});e[0]&&e[0].forEach((f,w)=>{let d=M.createEl("th",{cls:"csv-col-number",attr:{style:`width: ${t[w]||100}px`,draggable:"true"}});if(d.textContent=ee(w),d.onclick=v=>{v.stopPropagation(),z(w)},Q){let v=(g==null?void 0:g.has(w))||!1,C=d.createEl("button",{cls:`csv-pin-btn csv-pin-col ${v?"pinned":""}`,attr:{title:v?"Unpin column":"Pin column"}});(0,Be.setIcon)(C,v?"pin-off":"pin"),C.onclick=A=>{A.stopPropagation(),Q(w)}}if(d.ondragstart=v=>{var C;(C=v.dataTransfer)==null||C.setData("text/col-index",String(w)),d.classList.add("dragging"),Y("col",w),typeof x=="function"&&x()},d.ondragend=()=>{d.classList.remove("dragging"),Y(null,null),typeof x=="function"&&x()},d.ondragover=v=>{v.preventDefault(),d.classList.add("drag-over")},d.ondragleave=()=>{d.classList.remove("drag-over")},d.ondrop=v=>{var b;v.preventDefault(),d.classList.remove("drag-over"),Y(null,null);let C=Number((b=v.dataTransfer)==null?void 0:b.getData("text/col-index")),A=w;a&&C!==A&&a(C,A)},V.type!=="col"){let v=d.createEl("button",{cls:"csv-insert-col-btn left"});v.innerText="+",v.title=k.t("buttons.insertColBefore")||"Insert column before",v.onclick=b=>{b.stopPropagation(),p.insertColAt(w,!1)};let C=d.createEl("button",{cls:"csv-insert-col-btn right"});C.innerText="+",C.title=k.t("buttons.insertColAfter")||"Insert column after",C.onclick=b=>{b.stopPropagation(),p.insertColAt(w,!0)};let A=d.createEl("button",{cls:"csv-del-col-btn"});A.innerText="-",A.title=k.t("buttons.deleteColumn")||"Delete column",A.onclick=b=>{b.stopPropagation(),p.deleteColAt(w)}}if(V.type==="col"&&V.index!==null){let v=Math.max(0,V.index-2),C=Math.min(e[0].length-1,V.index+2);w>=v&&w<=C&&d.classList.add("csv-dragging-highlight")}let _=d.createEl("div",{cls:"resize-handle"});P(_,w)});let R=n.createEl("tbody");for(let f=0;f{v.stopPropagation(),D(f)},L){let v=(m==null?void 0:m.has(f))||!1,C=_.createEl("button",{cls:`csv-pin-btn csv-pin-row ${v?"pinned":""}`,attr:{title:v?"Unpin row":"Pin row"}});(0,Be.setIcon)(C,v?"pin-off":"pin"),C.onclick=A=>{A.stopPropagation(),L(f)}}if(_.ondragstart=v=>{var C;(C=v.dataTransfer)==null||C.setData("text/row-index",String(f)),_.classList.add("dragging"),Y("row",f),typeof x=="function"&&x()},_.ondragend=()=>{_.classList.remove("dragging"),Y(null,null),typeof x=="function"&&x()},_.ondragover=v=>{v.preventDefault(),_.classList.add("drag-over")},_.ondragleave=()=>{_.classList.remove("drag-over")},_.ondrop=v=>{var b;v.preventDefault(),_.classList.remove("drag-over"),Y(null,null);let C=Number((b=v.dataTransfer)==null?void 0:b.getData("text/row-index")),A=f;l&&C!==A&&l(C,A)},V.type!=="row"){let v=_.createEl("button",{cls:"csv-insert-row-btn above"});v.innerText="+",v.title=k.t("buttons.insertRowBefore")||"Insert row before",v.onclick=b=>{b.stopPropagation(),p.insertRowAt(f,!1)};let C=_.createEl("button",{cls:"csv-insert-row-btn below"});C.innerText="+",C.title=k.t("buttons.insertRowAfter")||"Insert row after",C.onclick=b=>{b.stopPropagation(),p.insertRowAt(f,!0)};let A=_.createEl("button",{cls:"csv-del-row-btn"});A.innerText="-",A.title=k.t("buttons.deleteRow")||"Delete row",A.onclick=b=>{b.stopPropagation(),p.deleteRowAt(f)}}if(V.type==="row"&&V.index!==null){let v=Math.max(0,V.index-2),C=Math.min(e.length-1,V.index+2);f>=v&&f<=C&&(_.classList.add("csv-dragging-highlight"),Array.from(d.children).forEach(A=>{A.classList.add("csv-dragging-highlight")}))}w.forEach((v,C)=>{let A=d.createEl("td",{attr:{style:`width: ${t[C]||100}px`}}),b=A.createEl("input",{cls:"csv-cell-input",attr:{value:v}}),O=ke(v),B=null;O&&(B=Ne(v,()=>{let S=A.querySelector(".csv-cell-display");S&&(S.style.display="none"),b.style.display="block",b.focus()}),A.insertBefore(B,b)),$(b),O&&B&&(b.style.display="none",B.style.display="block"),b.oninput=S=>{if(S.currentTarget instanceof HTMLInputElement){E(),e[f][C]=S.currentTarget.value,u===S.currentTarget&&o&&(o.value=S.currentTarget.value),i&&i(f,C,S.currentTarget),x(),r&&y(S.currentTarget);let U=ke(S.currentTarget.value),H=S.currentTarget.parentElement;if(H){let q=H.querySelector(".csv-cell-display");if(U){q&&q.remove();let T=S.currentTarget,Z=Ne(S.currentTarget.value,()=>{let F=H.querySelector(".csv-cell-display");F&&(F.style.display="none"),T.style.display="block",T.focus()});H.insertBefore(Z,S.currentTarget)}else q&&q.remove()}}},b.onfocus=S=>{if(S.currentTarget instanceof HTMLInputElement){h(f,C,S.currentTarget);let U=S.currentTarget.parentElement;if(U){let H=U.querySelector(".csv-cell-display");H&&(H.style.display="none",S.currentTarget.style.display="block")}}},b.onblur=S=>{if(S.currentTarget instanceof HTMLInputElement){let U=S.currentTarget.parentElement;if(U){let H=U.querySelector(".csv-cell-display");H&&ke(S.currentTarget.value)&&(H.style.display="block",S.currentTarget.style.display="none")}}}})}let X=()=>{n.querySelectorAll(".csv-col-number.active, .csv-row-number.active").forEach(w=>w.classList.remove("active"))};document.addEventListener("click",f=>{let w=f.target;w!=null&&w.closest(".csv-col-number, .csv-row-number")||X()})}var Le=class{constructor(e){this.selectedRow=-1;this.selectedCol=-1;this.tableEl=e}selectRow(e){if(console.log("[HighlightManager] selectRow called with index:",e),this.selectedRow===e){this.clearSelection();return}this.clearSelection(),this.selectedRow=e,this.highlightRow(e)}selectColumn(e){if(console.log("[HighlightManager] selectColumn called with index:",e),this.selectedCol===e){this.clearSelection();return}this.clearSelection(),this.selectedCol=e,this.highlightColumn(e)}clearSelection(){console.log("[HighlightManager] clearSelection called"),this.selectedRow=-1,this.selectedCol=-1,this.clearHighlight()}getSelectedRow(){return this.selectedRow}getSelectedCol(){return this.selectedCol}setTableEl(e){this.tableEl=e}highlightRow(e){var n;console.log("[HighlightManager] highlightRow called with index:",e);let t=(n=this.tableEl)==null?void 0:n.querySelectorAll("tbody tr");console.log("[HighlightManager] \u627E\u5230\u7684tbody\u884C\u6570:",t==null?void 0:t.length);let r=e;t&&t[r]?(console.log("[HighlightManager] \u9AD8\u4EAE\u76EE\u6807\u884C:",t[r]),t[r].classList.add("csv-row-selected")):console.log("[HighlightManager] \u672A\u627E\u5230\u76EE\u6807\u884C\uFF0CrowIndex:",e,"targetRowIndex:",r)}highlightColumn(e){var r;console.log("[HighlightManager] highlightColumn called with index:",e);let t=(r=this.tableEl)==null?void 0:r.querySelectorAll(`th:nth-child(${e+2}), td:nth-child(${e+2})`);console.log("[HighlightManager] \u627E\u5230\u7684\u5217\u5355\u5143\u683C\u6570:",t==null?void 0:t.length),t&&console.log("[HighlightManager] \u5217\u5355\u5143\u683C:",t),t==null||t.forEach(n=>{n instanceof HTMLElement&&n.classList.add("csv-col-selected")})}clearHighlight(){var t;console.log("[HighlightManager] clearHighlight called");let e=(t=this.tableEl)==null?void 0:t.querySelectorAll(".csv-row-selected, .csv-col-selected");console.log("[HighlightManager] \u6E05\u9664\u9AD8\u4EAE\u5143\u7D20\u6570:",e==null?void 0:e.length),e==null||e.forEach(r=>{r instanceof HTMLElement&&(r.classList.remove("csv-row-selected"),r.classList.remove("csv-col-selected"))})}};var Ue=class{constructor(){this.menuEl=null;this.outsideHandler=null;this.keyHandler=null}showMenu(e,t,r,n){this.closeMenu(),this.menuEl=document.createElement("div"),this.menuEl.className="csv-header-context-menu menu",Object.assign(this.menuEl.style,{position:"absolute",left:`${t}px`,top:`${r}px`,zIndex:"9999",minWidth:"160px"}),e.forEach(o=>{let u=document.createElement("div");u.className="menu-item csv-header-context-menu-item",u.textContent=k.t(o.label)||o.label,Object.assign(u.style,{padding:"6px 18px",cursor:"pointer"}),u.onclick=s=>{s.stopPropagation(),s.preventDefault(),this.closeMenu(),o.onClick()},u.onmouseenter=()=>u.classList.add("is-hovered"),u.onmouseleave=()=>u.classList.remove("is-hovered"),this.menuEl.appendChild(u)}),document.body.appendChild(this.menuEl),this.outsideHandler=o=>{this.menuEl&&!this.menuEl.contains(o.target)&&this.closeMenu(n)},this.keyHandler=o=>{o.key==="Escape"&&this.closeMenu(n)},setTimeout(()=>{document.addEventListener("mousedown",this.outsideHandler),document.addEventListener("keydown",this.keyHandler)},0)}closeMenu(e){this.menuEl&&(this.menuEl.remove(),this.menuEl=null),document.removeEventListener("mousedown",this.outsideHandler),document.removeEventListener("keydown",this.keyHandler),e&&e()}};function tt(p,e){let t=new Ue,r=n=>{let o=n.target;if(o.classList.contains("csv-row-number")){n.preventDefault();let u=o.closest("tr");if(!u)return;let c=Array.from(u.parentElement.children).indexOf(u);e.selectRow&&e.selectRow(c);let h=[{label:"contextMenu.insertRowAbove",onClick:()=>e.onInsertRowAbove(c)},{label:"contextMenu.insertRowBelow",onClick:()=>e.onInsertRowBelow(c)},{label:"contextMenu.deleteRow",onClick:()=>e.onDeleteRow(c)},{label:"contextMenu.moveRowUp",onClick:()=>e.onMoveRowUp(c)},{label:"contextMenu.moveRowDown",onClick:()=>e.onMoveRowDown(c)}];t.showMenu(h,n.pageX,n.pageY,()=>{e.clearSelection&&e.clearSelection(),e.onMenuClose&&e.onMenuClose()})}else if(o.classList.contains("csv-col-number")){n.preventDefault();let s=Array.from(p.querySelectorAll(".csv-col-number")).indexOf(o);e.selectColumn&&e.selectColumn(s);let c=[{label:"contextMenu.insertColLeft",onClick:()=>e.onInsertColLeft(s)},{label:"contextMenu.insertColRight",onClick:()=>e.onInsertColRight(s)},{label:"contextMenu.deleteCol",onClick:()=>e.onDeleteCol(s)},{label:"contextMenu.moveColLeft",onClick:()=>e.onMoveColLeft(s)},{label:"contextMenu.moveColRight",onClick:()=>e.onMoveColRight(s)}];t.showMenu(c,n.pageX,n.pageY,()=>{e.clearSelection&&e.clearSelection(),e.onMenuClose&&e.onMenuClose()})}};return p.addEventListener("contextmenu",r),()=>{p.removeEventListener("contextmenu",r),t.closeMenu()}}var Me="csv-lite-view",Te=class extends ne.TextFileView{constructor(t){super(t);this.tableData=[[""]];this.maxHistorySize=50;this.columnWidths=[];this.autoResize=!0;this.delimiter="auto";this.quoteChar='"';this.originalFileDelimiter=null;this.activeCellEl=null;this.activeRowIndex=-1;this.activeColIndex=-1;this.searchMatches=[];this.currentSearchIndex=-1;this.isSourceMode=!1;this.sourceTextarea=null;this.sourceCursorPos={start:0,end:0};this.headerContextMenuCleanup=null;this.stickyRows=new Set;this.stickyColumns=new Set;this.stickyHeaders=!0;this.stickyRowNumbers=!0;this.historyManager=new Ee(void 0,this.maxHistorySize),this.file=this.file,this.headerEl=this.headerEl,this.setupSafeSave()}getIcon(){return"table"}getViewData(){let t=this.originalFileDelimiter||(this.delimiter==="auto"?void 0:this.delimiter);return ue.unparseCSV(this.tableData,t?{delimiter:t}:void 0)}setupSafeSave(){this.originalRequestSave=this.requestSave,this.requestSave=async()=>{try{await me.withRetry(async()=>(this.originalRequestSave(),Promise.resolve()))}catch(t){console.error("Failed to save CSV file after retries:",t),new ne.Notice(`Failed to save file: ${t.message}. The file might be open in another program.`)}}}setViewData(t,r){try{if(this.tableData=ue.parseCSV(t,{delimiter:this.delimiter,quoteChar:this.quoteChar}),!this.originalFileDelimiter)try{this.originalFileDelimiter=ue.detectDelimiter(t,this.quoteChar)}catch(n){console.warn("Failed to detect original delimiter:",n)}(!this.tableData||this.tableData.length===0)&&(this.tableData=[[""]]),this.tableData=ue.normalizeTableData(this.tableData),r&&this.historyManager.reset(this.tableData),this.refresh()}catch(n){console.error("CSV\u5904\u7406\u9519\u8BEF:",n),this.tableData=[[""]],r&&this.historyManager.reset(this.tableData),this.refresh()}}reparseAndRefresh(){let t=this.data;this.setViewData(t,!1)}refresh(){var o,u;if(!this.contentEl)return;this.contentEl.querySelectorAll(".csv-source-mode").forEach(s=>s.remove()),(!this.tableData||!Array.isArray(this.tableData)||this.tableData.length===0)&&(console.warn("Table data not properly initialized, setting default"),this.tableData=[[""]]);let t=(s,c,h)=>{Re({editBarEl:this.editBarEl,editInput:this.editInput,activeCellEl:h,activeRowIndex:s,activeColIndex:c,tableData:this.tableData,onEdit:(E,x,$)=>{this.saveSnapshot(),this.tableData[E][x]=$,this.requestSave()}})};et({tableData:this.tableData,columnWidths:this.columnWidths,autoResize:this.autoResize,tableEl:this.tableEl,editInput:this.editInput,activeCellEl:this.activeCellEl,activeRowIndex:this.activeRowIndex,activeColIndex:this.activeColIndex,setActiveCell:(s,c,h)=>{this.setActiveCell(s,c,h),t(s,c,h)},saveSnapshot:()=>this.saveSnapshot(),requestSave:()=>this.requestSave(),setupAutoResize:s=>this.setupAutoResize(s),adjustInputHeight:s=>this.adjustInputHeight(s),selectRow:s=>this.highlightManager.selectRow(s),selectColumn:s=>this.highlightManager.selectColumn(s),getColumnLabel:s=>this.getColumnLabel(s),setupColumnResize:(s,c)=>this.setupColumnResize(s,c),insertRowAt:(s,c=!1)=>{this.saveSnapshot();let h=c?s+1:s;this.tableData.splice(h,0,Array(this.tableData[0].length).fill("")),this.refresh(),this.requestSave()},deleteRowAt:s=>{this.tableData.length<=1||(this.saveSnapshot(),this.tableData.splice(s,1),this.refresh(),this.requestSave())},insertColAt:(s,c=!1)=>{this.saveSnapshot();let h=c?s+1:s;this.tableData.forEach(E=>E.splice(h,0,"")),this.refresh(),this.requestSave()},deleteColAt:s=>{this.tableData[0].length<=1||(this.saveSnapshot(),this.tableData.forEach(c=>c.splice(s,1)),this.refresh(),this.requestSave())},renderEditBar:t,onColumnReorder:(s,c)=>{if(s!==c){this.saveSnapshot();for(let h of this.tableData){let[E]=h.splice(s,1);h.splice(c,0,E)}if(this.columnWidths&&this.columnWidths.length>0){let[h]=this.columnWidths.splice(s,1);this.columnWidths.splice(c,0,h)}this.refresh(),this.requestSave()}},onRowReorder:(s,c)=>{if(s===c)return;this.saveSnapshot();let[h]=this.tableData.splice(s,1);this.tableData.splice(c,0,h),this.refresh(),this.requestSave()},stickyRows:this.stickyRows,stickyColumns:this.stickyColumns,toggleRowSticky:s=>this.toggleRowSticky(s),toggleColumnSticky:s=>this.toggleColumnSticky(s)}),requestAnimationFrame(()=>{this.applyStickyStyles()});let r=(u=(o=this.operationEl)==null?void 0:o.querySelector)==null?void 0:u.call(o,".top-scroll");if(r&&this.tableEl){let s=this.tableEl.offsetWidth,c=()=>{let h=document.createElement("div");return h.style.width=s+"px",h.style.height="1px",h};r.empty(),r.appendChild(c())}let n=this.tableEl.parentElement;if(n){this._csvTableClickHandler&&n.removeEventListener("click",this._csvTableClickHandler);let s=c=>{let h=c.target;h.tagName==="TH"&&h.classList.contains("csv-col-number")||h.tagName==="TD"&&h.classList.contains("csv-row-number")||this.highlightManager.clearSelection()};this._csvTableClickHandler=s,n.addEventListener("click",s)}this.headerContextMenuCleanup&&(this.headerContextMenuCleanup(),this.headerContextMenuCleanup=null),this.headerContextMenuCleanup=tt(this.tableEl,{selectRow:s=>this.highlightManager.selectRow(s),selectColumn:s=>this.highlightManager.selectColumn(s),clearSelection:()=>this.highlightManager.clearSelection(),onMenuClose:()=>{console.log("[DEBUG] Header context menu closed")},onInsertRowAbove:s=>this.refreshInsertRow(s,!1),onInsertRowBelow:s=>this.refreshInsertRow(s,!0),onDeleteRow:s=>this.refreshDeleteRow(s),onMoveRowUp:s=>this.moveRow(s,s-1),onMoveRowDown:s=>this.moveRow(s,s+1),onInsertColLeft:s=>this.refreshInsertCol(s,!1),onInsertColRight:s=>this.refreshInsertCol(s,!0),onDeleteCol:s=>this.refreshDeleteCol(s),onMoveColLeft:s=>this.moveCol(s,s-1),onMoveColRight:s=>this.moveCol(s,s+1)}),this.tableData[0].forEach((s,c)=>{let h=this.tableEl.querySelector(`.resize-handle[data-index='${c}']`);h&&this.setupColumnResize(h,c)}),this.tableData.forEach((s,c)=>{let h=this.tableEl.querySelector(`.resize-handle-row[data-row-index='${c}']`);h&&this.setupColumnResize(h,c)})}getColumnLabel(t){let r="",n=t;do r=String.fromCharCode(65+n%26)+r,n=Math.floor(n/26)-1;while(n>=0);return r}setActiveCell(t,r,n){this.activeCellEl&&this.activeCellEl.parentElement&&this.activeCellEl.parentElement.classList.remove("csv-active-cell"),this.activeRowIndex=t,this.activeColIndex=r,this.activeCellEl=n,n.parentElement&&n.parentElement.classList.add("csv-active-cell"),this.editInput&&this.editBarEl&&Re({editBarEl:this.editBarEl,editInput:this.editInput,activeCellEl:n,activeRowIndex:t,activeColIndex:r,tableData:this.tableData,onEdit:(o,u,s)=>{this.saveSnapshot(),this.tableData[o][u]=s,this.requestSave()}})}setupColumnResize(t,r){let n,o,u=h=>{n=h.clientX,o=this.columnWidths[r]||100,document.addEventListener("mousemove",s),document.addEventListener("mouseup",c),h.preventDefault()},s=h=>{let E=o+(h.clientX-n);E>=50&&(this.columnWidths[r]=E,this.refresh())},c=()=>{document.removeEventListener("mousemove",s),document.removeEventListener("mouseup",c)};t.addEventListener("mousedown",u)}setupAutoResize(t){this.adjustInputHeight(t),t.addEventListener("input",()=>{this.autoResize&&this.adjustInputHeight(t)})}adjustInputHeight(t){let r=(t.value.match(/\n/g)||[]).length+1,u=Math.max(24,r*20);t.style.height=`${u}px`}saveSnapshot(){this.historyManager.push(this.tableData)}undo(){let t=this.historyManager.undo();t&&(this.tableData=t,this.refresh(),this.requestSave())}redo(){let t=this.historyManager.redo();t&&(this.tableData=t,this.refresh(),this.requestSave())}clear(){this.tableData=[[""]],this.historyManager.reset(this.tableData),this.refresh()}getViewType(){return Me}async onOpen(){var t,r;try{let n=(r=(t=this.headerEl)==null?void 0:t.querySelector)==null?void 0:r.call(t,".view-actions");if(n&&!n.querySelector(".csv-switch-source")){let y=document.createElement("button");y.className="clickable-icon csv-switch-source",y.setAttribute("aria-label","\u5207\u6362\u5230\u6E90\u7801\u6A21\u5F0F"),y.innerHTML='',y.onclick=async()=>{let D=this.file;if(!D)return;let z=this.app.workspace.getLeavesOfType("csv-lite-source-view"),ee=!1;for(let P of z)if(P.view&&P.view.file&&P.view.file.path===D.path){this.app.workspace.setActiveLeaf(P,!0,!0),ee=!0;break}if(!ee){let P=this.app.workspace.getLeaf(!0);await P.openFile(D,{active:!0,state:{mode:"source"}}),await P.setViewState({type:"csv-lite-source-view",active:!0,state:{file:D.path}}),this.app.workspace.setActiveLeaf(P,!0,!0)}},n.appendChild(y)}this.contentEl.empty(),this.operationEl=this.contentEl.createEl("div",{cls:"csv-operations"});let o=this.operationEl.createEl("div",{cls:"csv-parser-settings"});new ne.Setting(o).setName(k.t("settings.fieldSeparator")).setDesc(k.t("settings.fieldSeparatorDesc")).addDropdown(y=>{var z,ee;try{let P=(ee=(z=this.app.plugins)==null?void 0:z.getPlugin)==null?void 0:ee.call(z,"csv-lite");P&&P.settings&&P.settings.preferredDelimiter&&(this.delimiter=P.settings.preferredDelimiter)}catch(P){}let D=ue.detectDelimiter(this.data||"",this.quoteChar);y.addOption("auto",`Auto (detected: ${D})`),y.addOption(",",","),y.addOption(";",";"),y.setValue(this.delimiter||"auto"),y.onChange(async P=>{var ie,oe;this.delimiter=P==="\\t"?" ":P;try{let j=(oe=(ie=this.app.plugins)==null?void 0:ie.getPlugin)==null?void 0:oe.call(ie,"csv-lite");j&&typeof j.saveSettings=="function"&&(j.settings={...j.settings||{},preferredDelimiter:this.delimiter},await j.saveSettings())}catch(j){}this.reparseAndRefresh()})}),new ne.Setting(o).setName(k.t("settings.quoteChar")).setDesc(k.t("settings.quoteCharDesc")).addText(y=>{y.setValue(this.quoteChar).setPlaceholder('\u9ED8\u8BA4\u4E3A\u53CC\u5F15\u53F7 "').onChange(async D=>{this.quoteChar=D||'"',this.reparseAndRefresh()})});let u=this.operationEl.createEl("div",{cls:"csv-operation-buttons"}),s=u.createEl("div",{cls:"csv-buttons-group"}),c=u.createEl("div",{cls:"csv-search-bar-container"});this.searchBar=new xe(c,{getTableData:()=>this.tableData,tableEl:this.tableEl,getColumnLabel:y=>this.getColumnLabel(y),getCellAddress:(y,D)=>this.getCellAddress(y,D),jumpToCell:(y,D)=>this.jumpToCell(y,D),clearSearchHighlights:()=>this.clearSearchHighlights()}),new ne.ButtonComponent(s).setButtonText(k.t("buttons.undo")).setIcon("undo").onClick(()=>this.undo()),new ne.ButtonComponent(s).setButtonText(k.t("buttons.redo")).setIcon("redo").onClick(()=>this.redo()),new ne.ButtonComponent(s).setButtonText(k.t("buttons.resetColumnWidth")).onClick(()=>{this.columnWidths=[],this.calculateColumnWidths(),this.refresh()});let h=s.createEl("div",{cls:"csv-delimiter-compact"});new ne.Setting(h).addDropdown(y=>{var z,ee;try{let P=(ee=(z=this.app.plugins)==null?void 0:z.getPlugin)==null?void 0:ee.call(z,"csv-lite");P&&P.settings&&P.settings.preferredDelimiter&&(this.delimiter=P.settings.preferredDelimiter)}catch(P){}let D=ue.detectDelimiter(this.data||"",this.quoteChar);y.addOption("auto",`Auto (${D})`),y.addOption(",",","),y.addOption(";",";"),y.setValue(this.delimiter||"auto"),y.onChange(async P=>{var ie,oe;this.delimiter=P==="\\t"?" ":P;try{let j=(oe=(ie=this.app.plugins)==null?void 0:ie.getPlugin)==null?void 0:oe.call(ie,"csv-lite");j&&typeof j.saveSettings=="function"&&(j.settings={...j.settings||{},preferredDelimiter:this.delimiter},await j.saveSettings())}catch(j){}this.reparseAndRefresh()})}),this.editBarEl=this.operationEl.createEl("div",{cls:"csv-edit-bar"}),this.editInput=this.editBarEl.createEl("input",{cls:"csv-edit-input",attr:{placeholder:k.t("editBar.placeholder")}}),Re({editBarEl:this.editBarEl,editInput:this.editInput,activeCellEl:this.activeCellEl,activeRowIndex:this.activeRowIndex,activeColIndex:this.activeColIndex,tableData:this.tableData,onEdit:(y,D,z)=>{this.saveSnapshot(),this.tableData[y][D]=z,this.requestSave()}});let E=this.operationEl.createEl("div",{cls:"scroll-container top-scroll"}),$=this.contentEl.createEl("div",{cls:"table-wrapper"}).createEl("div",{cls:"table-container main-scroll"});this.tableEl=$.createEl("table",{cls:"csv-lite-table"}),this.highlightManager=new Le(this.tableEl),this.setupScrollSync(E,$),this.historyManager||(this.historyManager=new Ee(this.tableData,this.maxHistorySize)),this.registerDomEvent(document,"keydown",y=>{this.app.workspace.activeLeaf===this.leaf&&(y.ctrlKey||y.metaKey)&&y.key==="z"&&(y.shiftKey?(y.preventDefault(),this.redo()):(y.preventDefault(),this.undo()))}),(!this.tableData||!Array.isArray(this.tableData)||this.tableData.length===0)&&(this.tableData=[[""]]),this.refresh(),this.tableEl&&this.tableEl.addEventListener("click",y=>{let D=y.target;D.tagName==="TH"&&(D.classList.contains("csv-row-header")||D.classList.contains("csv-col-header"))||this.highlightManager.clearSelection()}),this.operationEl.classList.add("csv-toolbar-sticky")}catch(n){console.error("Error in onOpen:",n),new ne.Notice(`Failed to open CSV view: ${n.message}`),this.contentEl.empty();let o=this.contentEl.createEl("div",{cls:"csv-error"});o.createEl("h3",{text:"Error opening CSV file"}),o.createEl("p",{text:n.message}),this.tableData=[[""]],this.tableEl=this.contentEl.createEl("table"),this.refresh()}}setTableContent(t){this.tableData=t,this.refresh()}getTableContent(){return this.tableData}calculateColumnWidths(){this.columnWidths=ae.calculateColumnWidths(this.tableData)}setupScrollSync(t,r){r.addEventListener("scroll",()=>{t.scrollLeft=r.scrollLeft}),t.addEventListener("scroll",()=>{r.scrollLeft=t.scrollLeft})}async onClose(){let t=document.head.querySelector("#csv-edit-bar-styles");t&&t.remove(),this.headerContextMenuCleanup&&(this.headerContextMenuCleanup(),this.headerContextMenuCleanup=null),this.contentEl.empty()}addRow(){this.saveSnapshot(),this.tableData=ae.addRow(this.tableData),this.refresh(),this.requestSave()}deleteRow(){this.saveSnapshot(),this.tableData=ae.deleteRow(this.tableData),this.refresh(),this.requestSave()}addColumn(){this.saveSnapshot(),this.tableData=ae.addColumn(this.tableData),this.refresh(),this.requestSave()}deleteColumn(){this.saveSnapshot(),this.tableData=ae.deleteColumn(this.tableData),this.refresh(),this.requestSave()}getCellAddress(t,r){return`${this.getColumnLabel(r)}${t+1}`}jumpToCell(t,r){var u;this.clearSearchHighlights();let n=(u=this.tableEl)==null?void 0:u.querySelectorAll("tr"),o=t===0?1:t+1;if(n&&o{x.focus(),x.select(),x.parentElement&&(x.parentElement.classList.add("csv-search-current"),setTimeout(()=>{x.parentElement&&x.parentElement.classList.remove("csv-search-current")},3e3))},100))}}}clearSearchHighlights(){var t;(t=this.tableEl)==null||t.querySelectorAll(".csv-search-current").forEach(r=>{r instanceof HTMLElement&&r.classList.remove("csv-search-current")})}async openSourceMode(){let t=this.file;if(!t)return;let r=this.app.workspace.getLeaf(!0);await r.openFile(t,{active:!0,state:{mode:"source"}}),await r.setViewState({type:"csv-lite-source-view",active:!0,state:{file:t.path}}),this.leaf.detach()}moveRow(t,r){if(t<0||r<0||t>=this.tableData.length||r>=this.tableData.length)return;this.saveSnapshot();let n=this.tableData.splice(t,1)[0];this.tableData.splice(r,0,n),this.refresh(),this.requestSave()}toggleRowSticky(t){this.stickyRows.has(t)?this.stickyRows.delete(t):this.stickyRows.add(t),this.applyStickyStyles()}toggleColumnSticky(t){this.stickyColumns.has(t)?this.stickyColumns.delete(t):this.stickyColumns.add(t),this.applyStickyStyles()}applyStickyStyles(){if(!this.tableEl)return;this.tableEl.querySelectorAll(".csv-sticky-row, .csv-sticky-col, .csv-sticky-header, .csv-sticky-row-number").forEach(s=>{s.classList.remove("csv-sticky-row","csv-sticky-col","csv-sticky-header","csv-sticky-row-number"),s.style.removeProperty("left"),s.style.removeProperty("top")});let t=()=>{let s=this.tableEl.querySelector("tbody tr td:first-child");return s?s.offsetWidth:40},r=()=>{let s=this.tableEl.querySelector("thead tr");return s?s.offsetHeight:30},n=s=>{let c=t();for(let h=0;h{let c=r();for(let h=0;h{c.classList.add("csv-sticky-header"),c.style.top="0px"}),this.stickyRowNumbers){let s=t(),c=this.tableEl.querySelector("thead tr th:first-child");c&&(c.classList.add("csv-sticky-row-number"),c.style.left="0px",c.style.top="0px"),this.tableEl.querySelectorAll("tbody tr td:first-child").forEach(E=>{E.classList.add("csv-sticky-row-number"),E.style.left="0px"})}let u=r();this.stickyRows.forEach(s=>{let c=o(s);this.tableEl.querySelectorAll(`tbody tr:nth-child(${s+1}) td`).forEach(E=>{E.classList.add("csv-sticky-row"),E.style.top=`${c}px`})}),this.stickyColumns.forEach(s=>{let c=n(s),h=this.tableEl.querySelector(`thead tr th:nth-child(${s+2})`);h&&(h.classList.add("csv-sticky-col"),h.style.left=`${c}px`,h.style.top="0px"),this.tableEl.querySelectorAll(`tbody tr td:nth-child(${s+2})`).forEach(x=>{x.classList.add("csv-sticky-col"),x.style.left=`${c}px`})}),console.log("Applied sticky styles:",{stickyHeaders:this.stickyHeaders,stickyRowNumbers:this.stickyRowNumbers,stickyRows:Array.from(this.stickyRows),stickyColumns:Array.from(this.stickyColumns),rowNumberWidth:t(),headerHeight:r()})}moveCol(t,r){t<0||r<0||t>=this.tableData[0].length||r>=this.tableData[0].length||(this.saveSnapshot(),this.tableData.forEach(n=>{let o=n.splice(t,1)[0];n.splice(r,0,o)}),this.refresh(),this.requestSave())}refreshInsertRow(t,r){this.saveSnapshot();let n=r?t+1:t;this.tableData.splice(n,0,Array(this.tableData[0].length).fill("")),this.refresh(),this.requestSave()}refreshDeleteRow(t){this.tableData.length<=1||(this.saveSnapshot(),this.tableData.splice(t,1),this.refresh(),this.requestSave())}refreshInsertCol(t,r){this.saveSnapshot();let n=r?t+1:t;this.tableData.forEach(o=>o.splice(n,0,"")),this.refresh(),this.requestSave()}refreshDeleteCol(t){this.tableData[0].length<=1||(this.saveSnapshot(),this.tableData.forEach(r=>r.splice(t,1)),this.refresh(),this.requestSave())}};var rt=require("obsidian"),De=require("@codemirror/state"),se=require("@codemirror/view"),ve=require("@codemirror/commands"),Ve="csv-lite-source-view",ft=se.ViewPlugin.fromClass(class{constructor(p){this.decorations=st(p)}update(p){(p.docChanged||p.viewportChanged)&&(this.decorations=st(p.view))}},{decorations:p=>p.decorations});function st(p){let e=new De.RangeSetBuilder,t=/[;, ]/g;for(let{from:r,to:n}of p.visibleRanges){let o=p.state.doc.sliceString(r,n),u;for(;(u=t.exec(o))!==null;){let s=r+u.index;e.add(s,s+1,se.Decoration.mark({class:"csv-separator-highlight"}))}}return e.finish()}var _e=class extends rt.TextFileView{constructor(e){super(e),this.file=this.file,this.headerEl=this.headerEl}getViewType(){return Ve}getDisplayText(){return this.file?`CSV source: ${this.file.basename}`:"CSV source"}getIcon(){return"file-code"}async onOpen(){var s,c;let e=(c=(s=this.headerEl)==null?void 0:s.querySelector)==null?void 0:c.call(s,".view-actions");if(e&&!e.querySelector(".csv-switch-table")){let h=document.createElement("button");h.className="clickable-icon csv-switch-table",h.setAttribute("aria-label","\u5207\u6362\u5230\u8868\u683C\u6A21\u5F0F"),h.innerHTML='',h.onclick=async()=>{let E=this.file;if(!E)return;let x=this.app.workspace.getLeavesOfType("csv-lite-view"),$=!1;for(let y of x)if(y.view&&y.view.file&&y.view.file.path===E.path){this.app.workspace.setActiveLeaf(y,!0,!0),$=!0;break}if(!$){let y=this.app.workspace.getLeaf(!0);await y.openFile(E,{active:!0}),await y.setViewState({type:"csv-lite-view",active:!0,state:{file:E.path}}),this.app.workspace.setActiveLeaf(y,!0,!0)}},e.appendChild(h)}let t=this.containerEl.children[1];t.empty();let n=t.createDiv({cls:"csv-source-editor-container"}).createDiv({cls:"csv-source-cm-container"}),o=[(0,se.lineNumbers)(),(0,se.drawSelection)(),(0,ve.history)(),se.keymap.of([...ve.defaultKeymap,...ve.historyKeymap]),ft,(0,se.placeholder)("\u8F93\u5165 CSV \u6E90\u7801..."),se.EditorView.lineWrapping,se.EditorView.updateListener.of(h=>{h.docChanged&&this.save()})],u=De.EditorState.create({doc:this.data||"",extensions:o});this.editor=new se.EditorView({state:u,parent:n}),this.addEditorStyles(),setTimeout(()=>this.editor.focus(),10)}addToolbarButton(e,t,r,n,o){e.createEl("button",{text:t,cls:"csv-source-button",attr:{"aria-label":n}}).addEventListener("click",o)}addEditorStyles(){let e=document.createElement("style");e.textContent=` .csv-source-editor-container { height: 100%; display: flex; flex-direction: column; } .csv-source-toolbar { padding: 8px 12px; border-bottom: 1px solid var(--background-modifier-border); background: var(--background-secondary); font-weight: 500; display: flex; justify-content: space-between; align-items: center; } .csv-source-title { font-size: 14px; font-weight: 600; color: var(--text-normal); } .csv-source-button-group { display: flex; gap: 4px; } .csv-source-button { background: var(--interactive-normal); color: var(--text-normal); border: 1px solid var(--background-modifier-border); border-radius: 4px; padding: 4px 8px; font-size: 12px; cursor: pointer; transition: all 0.1s ease; } .csv-source-button:hover { background: var(--interactive-hover); } .csv-source-cm-container { flex: 1; overflow: auto; height: 100%; } .csv-source-cm-container .cm-editor { height: 100%; } .csv-source-cm-container .cm-scroller { font-family: var(--font-monospace); font-size: 14px; line-height: 1.5; } .csv-source-cm-container .cm-content { padding: 12px; } .cm-line .csv-separator-highlight { color: var(--color-accent); font-weight: bold; background: var(--background-modifier-active-hover); border-radius: 2px; } .csv-source-cm-container .cm-cursor { border-left: 2px solid var(--color-accent); /* \u517C\u5BB9\u660E\u6697\u4E3B\u9898\uFF0C\u4F7F\u7528\u4E3B\u9898\u4E3B\u8272 */ background: none; opacity: 1; z-index: 10; } .csv-source-cm-container .cm-gutters { background: var(--background-secondary); color: var(--text-faint); border-right: 1px solid var(--background-modifier-border); } .csv-source-cm-container .cm-lineNumbers .cm-gutterElement { color: var(--text-faint); } `,document.head.appendChild(e),this.register(()=>{document.head.removeChild(e)})}async onClose(){await this.save()}getViewData(){return this.editor?this.editor.state.doc.toString():this.data||""}setViewData(e,t){if(t&&this.clear(),this.data=e,this.editor){let r=this.editor.state.update({changes:{from:0,to:this.editor.state.doc.length,insert:e}});this.editor.dispatch(r)}}clear(){if(this.data="",this.editor){let e=this.editor.state.update({changes:{from:0,to:this.editor.state.doc.length,insert:""}});this.editor.dispatch(e)}}};var gt={csvSettings:"default",preferredDelimiter:"auto"},Ie=class extends pe.Plugin{async onload(){await this.loadSettings();let e=pe.moment.locale();k.setLocale(e),console.log(`CSV Plugin: Setting locale to '${e}'`),console.log(`CSV Plugin: Test translation - buttons.undo: '${k.t("buttons.undo")}'`),this.registerView(Me,t=>new Te(t)),this.registerView(Ve,t=>new _e(t)),this.registerExtensions(["csv"],Me),this.addCommand({id:"csv-lite-create-new-csv-file",name:k.t("commands.createNewCsv"),callback:()=>{this.createCsvInFolder("")}}),this.registerEvent(this.app.workspace.on("file-menu",(t,r)=>{t.addItem(n=>{n.setTitle(k.t("contextMenu.createNewCsv")||k.t("commands.createNewCsv")).setIcon("file-plus").onClick(()=>{let o="";if(r.path){let u=r.path,s=u.lastIndexOf("/");s>0&&(o=u.substring(0,s))}this.createCsvInFolder(o)})})}))}async createCsvInFolder(e){let r="new.csv",n=0;for(;this.app.vault.getAbstractFileByPath(e?`${e}/${r}`:r);)if(n++,r=`new-${n}.csv`,n>1e3)return new pe.Notice(k.t("modal.errors.createFailed")||"Failed to create file"),null;let o=e?`${e}/${r}`:r;try{await me.withRetry(()=>this.app.vault.create(o,""));let u=this.app.vault.getAbstractFileByPath(o);return u&&await this.app.workspace.getLeaf(!0).openFile(u),u}catch(u){return console.error("CreateCsv: failed to create file",u),new pe.Notice(k.t("modal.errors.createFailed")||"Failed to create file"),null}}onunload(){}async loadSettings(){this.settings=Object.assign({},gt,await this.loadData())}async saveSettings(){await this.saveData(this.settings)}}; /*! Bundled license information: papaparse/papaparse.min.js: (* @license Papa Parse v5.5.2 https://github.com/mholt/PapaParse License: MIT *) */ /* nosourcemap */