diff --git a/dist/index.js b/dist/index.js
index 10db26f..cdbc18a 100644
--- a/dist/index.js
+++ b/dist/index.js
@@ -347,7 +347,7 @@ data-node-id="${e}" data-type="NodeBlockQueryEmbed" class="render-node" >
`){const n=t.map(Cy).flat().reduce((i,r)=>(i.push(r.textContent??""),i),[]).filter(i=>!!i).join(e);return mA(n)}function a2(t,e=`
`){return ai([t],e)}function oi(t){if(!t)return t;const e=t.getAttribute(Gr);if((e==="true"||e==="false")&&!t.classList.contains("protyle-wysiwyg"))return t;let n=t.querySelector(`[${Gr}="true"]`);return n||(n=t.querySelector(`[${Gr}="false"]`)),n}function zT(t,e){return``}function OT(t){const e=Ff(),n=Array.from(t.matchAll(e));for(const i of n){const r=i[1],o=i[2],A=Fa(r,o.slice(1,-1));t=t.replace(i[0],A)}return t}function Ry(t){const e=NO(),n=t.matchAll(e),i=new Set;for(const r of n)r[0]&&i.add(r[0]);return i}function Ff(){return new RegExp(/\(\(([0-9]{14}-[0-9a-z]{7}) (("[^"]*?")|('[^']*?'))\)\)/g)}function gT(t,e,n,i){const r=[];e?e.clear():e=new Set;for(const o of Ly(t,n,i))e.has(o.id)||(e.add(o.id),r.push(o));return r}function Ly(t,e,n){const i=Ff();return[...t.matchAll(i)].map(r=>({id:r[1],text:r[2].slice(1,-1).trim()})).filter(r=>{let o=!0;return e&&o&&(o=!e.includes(r.id)),o?(n&&o&&(o=!n.includes(r.text)),o):!1})}function mT(t){const e=Ff(),n=[],i=[],r=[],o=t.matchAll(e);for(const A of o){const a=A[1]??"";a&&(n.push(a),i.push(A[0]),r.push({id:a,txt:A[2].slice(1,-1)}))}return{ids:n,links:i,idLnks:r}}function si(t){return new Promise(e=>{setTimeout(e,t)})}function mA(t){return t?t.split("").join("").split("").join("").trim():""}function ky(t){return t.replaceAll(/siyuan:\/\/blocks\/.{22}(\?focus=1)?/g,"")}function qT(t){return t=t.replace(/\[(.*?)\]\(.*?\)/,"$1"),t=t.replace(/\(\((.*?) ('|")(.*?)('|")\)\)/,"$3"),t}function Fz(t,e=10,n=0,i=new Set){if(i.has(t))return"[Circular]";if(i.add(t),n>=e)return"[MaxDepthReached]";if(t===null||typeof t!="object")return t;if(Array.isArray(t))return t.map(o=>Fz(o,e,n+1,i));const r={};for(const o in t)Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=Fz(t[o],e,n+1,i));return r}const rt=globalThis.siyuan,L2=globalThis.Lute.New,C1=globalThis.Lute.NewNodeID,_T=globalThis.Lute.BlockDOM2Content;function wT(t,e){return e=Math.ceil(t.length/e),ka(t,e)}function Sy(t){const e=[...t];for(let n=e.length-1;n>0;n--){const i=Math.floor(Math.random()*(n+1));[e[n],e[i]]=[e[i],e[n]]}return e}function BT(t){return typeof t=="boolean"}function ka(t,e){const n=[];for(let i=0;i0&&n.push(r)}return n}function yT(t,e){return e.length===0?t:e.indexOf(t)===-1?e[0]:t}function ze(){return"ID"+nL().replace(/-/g,"")}function WT(t){const e=t.split("/"),n=e.pop();return[e.join("/"),n]}function Nn(t){return typeof t=="number"&&!isNaN(t)}const I1={nowYMD(t){const[e,n]=I1.nowStr(t).split(" "),[i,r,o]=e.split("-"),[A,a,s]=n.split(":");return{y:Number(i),M:Number(r),d:Number(o),h:Number(A),m:Number(a),s:Number(s)}},nowYMDStrPad(t){const[e,n]=I1.nowStr(t).split(" "),[i,r,o]=e.split("-"),[A,a,s]=n.split(":");return{y:i.padStart(2,"0"),M:r.padStart(2,"0"),d:o.padStart(2,"0"),h:A.padStart(2,"0"),m:a.padStart(2,"0"),s:s.padStart(2,"0")}},nowStr(t){return t||(t=new Date),I1.dateFormat(t)},nowts(t=0){return I1.now(t).getTime()/1e3},now(t=0){const e=new Date().getTime()+t*1e3;return new Date(e)},getYYYYMMDDHHmmssPlus0(t){return t==null&&(t=new Date().getTime()/1e3),eh.unix(t).utcOffset("+0000").format("YYYYMMDDHHmmss")},getYYYYMMDDHHmmssPlus8(t){return t==null&&(t=new Date().getTime()/1e3),eh.unix(t).utcOffset("+0800").format("YYYYMMDDHHmmss")},getYYYYMMDDHHmmss(t){return t==null&&(t=new Date().getTime()/1e3),eh.unix(t).format("YYYYMMDDHHmmss")},dateFormat(t){t==null&&(t=new Date);const e=t.getFullYear().toString(),n=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getDate().toString().padStart(2,"0"),r=t.getHours().toString().padStart(2,"0"),o=t.getMinutes().toString().padStart(2,"0"),A=t.getSeconds().toString().padStart(2,"0");return e+"-"+n+"-"+i+" "+r+":"+o+":"+A},dateFormatTime(t){const e=t.getHours().toString().padStart(2,"0"),n=t.getMinutes().toString().padStart(2,"0"),i=t.getSeconds().toString().padStart(2,"0");return e+":"+n+":"+i},dateFormatDay(t){const e=t.getFullYear().toString(),n=(t.getMonth()+1).toString().padStart(2,"0"),i=t.getDate().toString().padStart(2,"0");return e+"-"+n+"-"+i},dateFromYYYYMMDDHHmmss(t){return new Date(t)},dateFromYYYYMMDDHHmmssShort(t){const e=t.slice(0,4),n=t.slice(4,6),i=t.slice(6,8),r=t.slice(8,10),o=t.slice(10,12),A=t.slice(12),a=`${e}-${n}-${i} ${r}:${o}:${A}`;return new Date(a)},checkTimeFormat(t){return/^(\d{4})-(\d{1,2})-(\d{1,2}) ?(\d{1,2}):(\d{1,2}):(\d{1,2})$/.test(t)},makesureDateTimeFormat(t){const e=/^(\d{4})-(\d{1,2})-(\d{1,2}) ?(\d{1,2}):(\d{1,2}):(\d{1,2})$/,n=r=>{const o=(r==null?void 0:r.toString())??"";return vT(o,2,"0")},i=t.replace(e,(r,o,A,a,s,c,u)=>`${o}-${n(A)}-${n(a)} ${n(s)}:${n(c)}:${n(u)}`);return new Date(i).toDateString()==="Invalid Date"?"":i}},S={async pushMsg(t,e=7e3){const n="/api/notification/pushMsg";t+=`${new Date().getTime()}`;const i=await c1.fetchSyncPost(n,{msg:t,timeout:e});if(i.code!=0)throw Error(`${n}: code=${i.code}, msg=${i.msg}`);return i.data},async currentTime(t=0){return I1.dateFormat(new Date(await S.currentTimeMs(t)))},async currentTimeMs(t=0){return(await c1.fetchSyncPost("/api/system/currentTime",{})).data+t*1e3},async copyFile(t,e){return S.call("/api/file/copyFile",{src:t,dest:e})},async readDir(t){return S.call("/api/file/readDir",{path:t})},async performSync(t=!1,e=!1){return S.call("/api/sync/performSync",{upload:t,mobileSwitch:e})},async performBootSync(){return S.call("/api/sync/performBootSync",{})},async listCloudSyncDir(){return S.call("/api/sync/listCloudSyncDir",{})},async removeFile(t){return S.call("/api/file/removeFile",{path:t})},async copyFile2(t,e){const n=await S.getFileBinary(t);return S.putFile(e,n)},async putFile(t,e){let n;if(e instanceof ArrayBuffer){const a=new Uint8Array(e);n=new File([new Blob([a])],t.split("/").pop())}else typeof e=="object"?n=new File([new Blob([JSON.stringify(e)],{type:"application/json"})],t.split("/").pop()):n=new File([new Blob([e])],t.split("/").pop());const i=new FormData;i.append("path",t),i.append("file",n),i.append("isDir","false");const A=await(await fetch("/api/file/putFile",{method:"POST",body:i})).json();return A.code&&A.code!=0?(console.error("code=%s %s",A.code,A.msg),null):A.data},async getFileBinary(t){try{const i=await fetch("/api/file/getFile",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})});if(!i.ok)throw new Error(`HTTP error! Status: ${i.status}`);return(await i.blob()).arrayBuffer()}catch(e){throw console.error("Error fetching file binary:",e),e}},async getFile(t){return(await fetch("/api/file/getFile",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:t})})).text()},async getJson(t){const e=await S.getFile(t);try{return JSON.parse(e)}catch(n){console.error(n)}},async call(t,e){const n="POST",i={"Content-Type":"application/json"};try{const r=await fetch(t,{method:n,headers:i,body:JSON.stringify(e)}),o=await r.json();return o!=null&&o.code&&(o==null?void 0:o.code)!=0?(console.warn(`p5: ${o==null?void 0:o.code} ${o==null?void 0:o.msg} ${JSON.stringify(e)}`),null):(o==null?void 0:o.data)===void 0?r:o.data}catch(r){console.warn(r,t,e)}},transSetAttrViewColWrap(t,e,n,i=!0){const r={};return r.action="setAttrViewColWrap",r.avID=t,r.blockID=e,r.id=n,r.data=i,r},transSetAttrViewColHidden(t,e,n,i=!0){const r={};return r.action="setAttrViewColHidden",r.avID=t,r.blockID=e,r.id=n,r.data=i,r},transSetAttrViewSorts(t,e,n,i){const r={};return r.action="setAttrViewSorts",r.avID=t,r.blockID=e,r.data=[{column:n,order:i}],r},transSetAttrViewColCalc(t,e,n,i){const r={};return r.action="setAttrViewColCalc",r.avID=t,r.data={operator:i},r.blockID=e,r.id=n,r},transSetAttrViewFilters(t,e,n){const i={};return i.action="setAttrViewFilters",i.avID=t,i.data=n,i.blockID=e,i},transSetAttrViewViewName(t,e,n){const i={};return i.action="setAttrViewViewName",i.avID=t,i.id=e,i.data=n,i},transUpdateAttrViewCol(t,e,n,i){const r={};return r.action="updateAttrViewCol",r.id=e,r.avID=t,r.name=n,r.type=i,r},transSetAttrViewName(t,e){const n={};return n.action="setAttrViewName",n.id=t,n.data=e,n},transRemoveAttrViewCol(t,e){const n={};return n.action="removeAttrViewCol",n.avID=t,n.id=e,n},transAddAttrViewCol(t,e,n=C1(),i="text",r=""){const o={};return o.action="addAttrViewCol",o.avID=t,o.name=e,o.previousID=r,o.type=i,o.id=n,o},transUpdateAttrViewCellBatch(t){return t.map(e=>{const n={};return n.action="updateAttrViewCell",n.avID=e.avID,n.id=e.cellID,n.keyID=e.colID,n.rowID=e.rowID_BlockID,n.data=e.value,n})},transInsertAttrViewBlock(t,e,n,i="",r=!0){const o={};return o.action="insertAttrViewBlock",o.avID=t,o.blockID=e,o.previousID=i,o.ignoreFillFilter=r,o.srcs=n,o},transDoUpdateUpdated(t,e=I1.getYYYYMMDDHHmmss()){const n={};return n.action="doUpdateUpdated",n.id=t,n.data=e,n},async getAttributeView(t){return S.call("/api/av/getAttributeView",{id:t})},async renderAttributeView(t,e=50,n=1,i="",r=""){return S.call("/api/av/renderAttributeView",{id:t,pageSize:e,query:i,page:n,viewID:r})},async removeUnusedAsset(t){return S.call("/api/asset/removeUnusedAsset",{path:t})},async removeUnusedAssets(){return S.call("/api/asset/removeUnusedAssets",{})},async getMissingAssets(){return S.call("/api/asset/getMissingAssets",{})},async getUnusedAssets(){return S.call("/api/asset/getUnusedAssets",{})},async getDocCreateSavePath(t){const e=t;return S.call("/api/filetree/getDocCreateSavePath",{notebook:e})},async getRefCreateSavePath(t){const e=t;return S.call("/api/filetree/getRefCreateSavePath",{notebook:e})},async openNotebook(t){const e=t;return S.call("/api/notebook/openNotebook",{notebook:e})},async lsNotebooks(t){const e=await S.call("/api/notebook/lsNotebooks",{});if(t==null)return e.notebooks;const n=[];for(const i of e.notebooks)i.closed===t&&n.push(i);return n},async sqlAsset(t){return await S.call("/api/query/sql",{stmt:t})??[]},async sqlSpan(t){return await S.call("/api/query/sql",{stmt:t})??[]},async sqlRef(t){return await S.call("/api/query/sql",{stmt:t})??[]},async sqlAttr(t){return await S.call("/api/query/sql",{stmt:t})??[]},async sql(t){return await S.call("/api/query/sql",{stmt:t})??[]},async sqlOne(t){const e=await S.sql(t);return e.length>=1?e[0]:{}},async getDocRowsByName(t){return S.sql(`select * from blocks where content="${t}" and type="d" limit 10000000`)},async getDocAttrs(t,e){return S.sqlAttr(`select * from attributes where root_id="${t}" and name="${e}"`)},async getBlockIndex(t){return await S.call("/api/block/getBlockIndex",{id:t})},async getBlocksIndexes(t){return await S.call("/api/block/getBlocksIndexes",{ids:t})},async getBlockBreadcrumb(t,e=[]){return await S.call("/api/block/getBlockBreadcrumb",{id:t,excludeTypes:e})},async setUILayout(t){return S.call("/api/system/setUILayout",{layout:t})},async getConf(){return S.call("/api/system/getConf",{})},async flushTransaction(){return await S.call("/api/sqlite/flushTransaction",{})},async createDocWithMdIfNotExists(t,e,n,i){return navigator.locks.request("tomato.siyuan.createDocWithMdIfNotExists",{mode:"exclusive"},async r=>{const o=await S.sqlOne(`select id from blocks where box="${t}" and hpath="${e}" and type='d' limit 1`),A=(o==null?void 0:o.id)??"";return A||S.createDocWithMd(t,e,n,"",i)})},async createDocWithMd(t,e,n,i="",r){const o=t,A=e;let a;return i?a={notebook:o,path:A,markdown:n,id:i}:a={notebook:o,path:A,markdown:n},i=await S.call("/api/filetree/createDocWithMd",a),r&&await S.setBlockAttrs(i,r),i},async getDocRowByBlockID(t){return S.sqlOne(`select * from blocks where id in (select root_id from blocks where id="${t}") limit 1`)},async removeDoc(t,e){return S.call("/api/filetree/removeDoc",{notebook:t,path:e})},async renameDocByID(t,e){const n=await S.sqlOne(`select box,path from blocks where type='d' and id="${t}"`);if(n!=null&&n.box&&(n!=null&&n.path))return S.renameDoc(n.box,n.path,e)},async renameDoc(t,e,n){return S.call("/api/filetree/renameDoc",{notebook:t,title:n,path:e})},async moveDocs(t,e,n,i){return i?S.call("/api/filetree/moveDocs",{fromPaths:t,toPath:e,toNotebook:n,callback:i}):S.call("/api/filetree/moveDocs",{fromPaths:t,toPath:e,toNotebook:n})},async duplicateDoc(t){return S.call("/api/filetree/duplicateDoc",{id:t})},async removeDocByIDSiyuan(t){return S.call("/api/filetree/removeDocByID",{id:t})},async removeDocByID(t){let e=10;for(;e-- >0;){const n=await this.sqlOne(`select box, path from blocks where id="${t}" and type="d"`),i=(n==null?void 0:n.box)??"",r=(n==null?void 0:n.path)??"";if(i&&r)return S.removeDoc(i,r);await si(1e3)}return{}},async insertLocalAssets(t,e,n=!1){return S.call("/api/asset/insertLocalAssets",{id:t,assetPaths:e,isUpload:n})},async getDocOutline(t){return S.call("/api/outline/getDocOutline",{id:t})},async resolveAssetPath(t){return S.call("/api/asset/resolveAssetPath",{path:t})},async renameAsset(t,e){return S.call("/api/asset/renameAsset",{oldPath:t,newName:e})},async createSnapshot(t="created by sy-tomato-plugin"){const e=await S.call("/api/repo/createSnapshot",{memo:t});return S.pushMsg("snapshot created"),e},async purgeRepo(){return S.call("/api/repo/purgeRepo",{})},async purgeCloudRepo(){return S.call("/api/repo/purgeCloudRepo",{})},async getDocImageAssets(t){return S.call("/api/asset/getDocImageAssets",{id:t})},async transferBlockRef(t,e,n=!0){return S.call("/api/block/transferBlockRef",{fromID:t,toID:e,reloadUI:n})},async createDailyNote(t){return S.call("/api/filetree/createDailyNote",{notebook:t})},async checkBlockExist(t){return t?S.call("/api/block/checkBlockExist",{id:t}):!1},async getBlockDOM(t){return S.call("/api/block/getBlockDOM",{id:t})},async setBlockAttrs(t,e){return S.call("/api/attr/setBlockAttrs",{id:t,attrs:e})},transbatchSetBlockAttrs(t){return t.map(e=>{const n={};return n.action="setAttrs",n.id=e.id,n.data=JSON.stringify(e.attrs),n})},async batchSetBlockAttrsTrans(t){return S.transactions(S.transbatchSetBlockAttrs(t))},transBatchUpdateAttrs(t){return t.map(e=>{const n={};return n.action="updateAttrs",n.id=e.id,n.data=JSON.stringify({old:e.old,new:e.new}),n})},async batchUpdateAttrsTrans(t){return S.transactions(S.transBatchUpdateAttrs(t))},async batchSetBlockAttrs(t){if(t.length>0)return S.call("/api/attr/batchSetBlockAttrs",{blockAttrs:t})},async batchGetBlockAttrs(t){return S.call("/api/attr/batchGetBlockAttrs",{ids:t})},async getBlockAttrs(t){return S.call("/api/attr/getBlockAttrs",{id:t})},async getNotebookConf(t){return S.call("/api/notebook/getNotebookConf",{notebook:t})},async getDocIDByBlockID(t){return t?(await S.sqlOne(`select root_id from blocks where id='${t}'`)).root_id??"":""},async getRowByID(t){return await S.sqlOne(`select * from blocks where id='${t}'`)},async getRows(t,e="*",n=!0,i=[],r=!1){if(!t||t.length==0)return[];if(e=e.trim(),e!="*"){const s=new Set(e.split(","));s.add("id"),e=[...s.values()].join(",")}const o=t.map(s=>`"${s}"`).join(","),A=[];A.push(`SELECT ${e} FROM blocks WHERE id IN (${o})`),i.forEach(s=>A.push("AND "+s)),A.push("limit 100000000");const a=await S.sql(A.join(" "));if(n){const s=a.reduce((c,u)=>(c.set(u.id,u),c),new Map);return r?t.map(c=>s.get(c)):t.map(c=>s.get(c)).filter(c=>c!=null)}return a},async getChildBlocks(t){return t?S.call("/api/block/getChildBlocks",{id:t}):[]},async getIDsByHPath(t,e){return S.call("/api/filetree/getIDsByHPath",{path:t,notebook:e})},async getTag(t){return S.call("/api/tag/getTag",{sort:t})},async copyStdMarkdown(t){return S.call("/api/lute/copyStdMarkdown",{id:t})},async getContentWordCount(t){return S.call("/api/block/getContentWordCount",{content:t})},async getBlocksWordCount(t){return S.call("/api/block/getBlocksWordCount",{ids:t})},async clearAll(t){const e=await S.getChildBlocks(t);return S.deleteBlocks(e.map(n=>n.id))},transDeleteBlocks(t){return(t==null?void 0:t.map(e=>{const n={};return n.action="delete",n.id=e,n}))??[]},async deleteBlock(t){return S.call("/api/block/deleteBlock",{id:t})},async deleteBlocks(t){if((t==null?void 0:t.length)>0)return S.transactions(S.transDeleteBlocks(t))},transMoveBlocksAfter(t,e){return t.slice().reverse().map(n=>{const i={};return i.action="move",i.id=n,i.previousID=e,i})},async moveBlocksAfter(t,e){return S.transactions(S.transMoveBlocksAfter(t,e))},async moveBlockAfter(t,e){return S.call("/api/block/moveBlock",{id:t,previousID:e})},async moveBlockAsChild(t,e){return S.call("/api/block/moveBlock",{id:t,parentID:e})},transMoveBlocksAsChild(t,e){return t.slice().reverse().map(n=>{const i={};return i.action="move",i.id=n,i.parentID=e,i})},async moveBlocksAsChild(t,e){return S.transactions(S.transMoveBlocksAsChild(t,e))},async getDocLastID(t){return S.getTailChildBlocks(t,1).then(e=>{var n;return(n=e==null?void 0:e.at(0))==null?void 0:n.id})},async getTailChildBlocks(t,e){return S.call("/api/block/getTailChildBlocks",{id:t,n:e})},async getBlockKramdown(t){return S.call("/api/block/getBlockKramdown",{id:t})},async refreshVirtualBlockRef(){return S.call("/api/setting/refreshVirtualBlockRef",{})},async setAppearance(t){return S.call("/api/setting/setAppearance",t)},async updateBlock(t,e,n="markdown"){return S.call("/api/block/updateBlock",{id:t,data:e,dataType:n})},async safeUpdateBlock(t,e,n="markdown"){let i=20;do{if(await S.checkBlockExist(t))return S.call("/api/block/updateBlock",{id:t,data:e,dataType:n});await si(400)}while(--i>0)},transUpdateBlocks(t){return t=t.filter(e=>!!e.id),t.length>0?t.map(({id:e,domStr:n})=>{const i={};return i.action="update",i.id=e,i.data=n,i}):[]},async updateBlocks(t){return S.transactions(S.transUpdateBlocks(t))},async getBlockMarkdownAndContent(t){const e=await S.sqlOne(`select markdown, content from blocks where id="${t}"`);return{markdown:(e==null?void 0:e.markdown)??"",content:(e==null?void 0:e.content)??"",id:t}},async transactions(t,e=[]){if(!(t.length==0&&e.length==0))return S.call("/api/transactions",{session:c1.Constants.SIYUAN_APPID,app:c1.Constants.SIYUAN_APPID,transactions:[{doOperations:t,undoOperations:e}],reqId:new Date().getTime()})},async getHeadingDeleteTransaction(t){return S.call("/api/block/getHeadingDeleteTransaction",{id:t})},async getHeadingChildrenIDs(t){return S.call("/api/block/getHeadingChildrenIDs",{id:t})},async getHeadingChildrenDOM(t){return S.call("/api/block/getHeadingChildrenDOM",{id:t})},async listDocsByPath(t,e,n=15){return S.call("/api/filetree/listDocsByPath",{notebook:t,path:e,sort:n})},async listDocTree(t,e){return S.call("/api/filetree/listDocTree",{notebook:t,path:e})},async getRefIDs(t){return S.call("/api/block/getRefIDs",{id:t})},async getBackmentionDoc(t,e,n=""){const i=rt.config.editor.backlinkContainChildren,r={defID:t,refTreeID:e,keyword:n,containChildren:i};return S.call("/api/ref/getBackmentionDoc",r)},async getBacklinkDoc(t,e,n=""){const i=rt.config.editor.backlinkContainChildren,r={defID:t,refTreeID:e,keyword:n,containChildren:i};return S.call("/api/ref/getBacklinkDoc",r)},async getBacklink2(t,e="",n="",i="3",r="3"){const o=rt.config.editor.backlinkContainChildren,A={id:t,k:e,mk:n,sort:i,mSort:r,containChildren:o};return S.call("/api/ref/getBacklink2",A)},async appendDailyNoteBlock(t,e,n="markdown"){return S.call("/api/block/appendDailyNoteBlock",{notebook:t,data:e,dataType:n})},async prependDailyNoteBlock(t,e,n="markdown"){return S.call("/api/block/prependDailyNoteBlock",{notebook:t,data:e,dataType:n})},async insertBlockAfter(t,e,n="markdown"){return S.call("/api/block/insertBlock",{data:t,dataType:n,previousID:e})},async insertBlockBefore(t,e,n="markdown"){return S.call("/api/block/insertBlock",{data:t,dataType:n,nextID:e})},async insertBlockAsChildOf(t,e,n="markdown"){return S.call("/api/block/insertBlock",{data:t,dataType:n,parentID:e})},transInsertBlocksBefore(t,e){return t.slice().reverse().map(n=>{const i={};return i.action="insert",i.data=n,i.nextID=e,i})},transInsertBlocksAfter(t,e){return t.slice().reverse().map(n=>{const i={};return i.action="insert",i.data=n,i.previousID=e,i})},transInsertBlocksAsChildOf(t,e){return t.slice().reverse().map(n=>{const i={};return i.action="insert",i.data=n,i.parentID=e,i})},async insertBlocksAfter(t,e){if(e)return S.transactions(S.transInsertBlocksAfter(t,e))},async insertBlocksAsChildOf(t,e){return S.transactions(S.transInsertBlocksAsChildOf(t,e))},transAppendBlocks(t,e){return t.map(n=>{const i={};return i.action="append",i.id=n,i.parentID=e,i})},async appendBlocks(t,e){const n=await S.getTailChildBlocks(e,1).then(i=>{var r;if(i)return(r=i[0])==null?void 0:r.id});if(n)return S.transactions(S.transInsertBlocksAfter(t,n))},async appendBlock(t,e,n="markdown"){return S.call("/api/block/appendBlock",{data:t,dataType:n,parentID:e})},async getBlockInfo(t){return S.call("/api/block/getBlockInfo",{id:t})},async getDocInfo(t){return S.call("/api/block/getDocInfo",{id:t})},async removeBookmarks(t,e){const n="",i=await S.sql(`select id from blocks where root_id='${t}' and ial like '%bookmark=%' limit 1000`);for(const r of i){const o=r.id;e!==o&&await S.setBlockAttrs(o,{bookmark:n})}},async addBookmark(t,e){return S.setBlockAttrs(t,{bookmark:e})},async getTreeRiffCardsAll(t){const e=[];for(let n=1;;n++){const i=await S.getTreeRiffCards(t,n);if(!(i!=null&&i.blocks)||(e.push(...i.blocks),e.length>=i.total)||n>=i.pageCount+3)break}return e},async getTreeRiffCards(t,e,n=1e4){return S.call("/api/riff/getTreeRiffCards",{id:t,page:e,pageSize:n})},transAddRiffCards(t){const e={};return e.action="addFlashcards",e.deckID=c1.Constants.QUICK_DECK_ID,e.blockIDs=t,e},transRemoveRiffCards(t){const e={};return e.action="removeFlashcards",e.deckID=c1.Constants.QUICK_DECK_ID,e.blockIDs=t,e},async addRiffCards(t,e=c1.Constants.QUICK_DECK_ID){return S.call("/api/riff/addRiffCards",{blockIDs:t,deckID:e})},async skipReviewRiffCard(t,e=c1.Constants.QUICK_DECK_ID){return S.call("/api/riff/skipReviewRiffCard",{cardID:t,deckID:e})},async reviewRiffCard(t,e,n=c1.Constants.QUICK_DECK_ID){return S.call("/api/riff/reviewRiffCard",{cardID:t,rating:e,deckID:n})},async reviewRiffCardByBlockID(t,e,n=c1.Constants.QUICK_DECK_ID){const i=await S.getRiffCardsByBlockIDs([t]);if(i.has(t)){const r=i.get(t).slice().pop();if(r)return S.reviewRiffCard(r.riffCardID,e,n)}},async getRiffCards(t=1,e=1e3,n=""){return S.call("/api/riff/getRiffCards",{id:n,page:t,pageSize:e})},async getRiffCardsByBlockIDs(t){var n;const e=await S.call("/api/riff/getRiffCardsByBlockIDs",{blockIDs:t});return(n=e==null?void 0:e.blocks)==null?void 0:n.reduce((i,r)=>{const o=i.get(r.id)??[];return o.push(r),i.set(r.id,o),i},new Map)},async batchSetRiffCardsDueTimeByBlockID(t){const e=await S.getRiffCardsByBlockIDs(t.map(i=>i.id)),n=t.map(i=>{var r;return(r=e.get(i.id))==null?void 0:r.map(o=>({id:o.riffCardID,due:i.due}))}).filter(i=>!!i).flat();return S.batchSetRiffCardsDueTimeByCardID(n)},async batchSetRiffCardsDueTimeByCardID(t){return S.call("/api/riff/batchSetRiffCardsDueTime",{cardDues:t})},async getRiffCardsAll(t=1e3){const e=new Map;for(let n=1;;n++){const i=await S.getRiffCards(n,t);if(!(i!=null&&i.blocks)||(i.blocks.forEach(r=>{const o=e.get(r.id)??[];o.push(r),e.set(r.id,o)}),e.size>=i.total)||n>=i.pageCount+1)break}return e},async getRiffDueCards(t=""){return S.call("/api/riff/getRiffDueCards",{deckID:t})},async getRiffDecks(){return S.call("/api/riff/getRiffDecks",{})},async removeRiffCards(t,e=""){return!t||t.length==0?null:S.call("/api/riff/removeRiffCards",{deckID:e,blockIDs:t})},async updateEmbedBlock(t,e){return S.call("/api/search/updateEmbedBlock",{id:t,content:e})},async findListType(t){let e="",n="",i=500;for(;i>0;){i-=1;const r=await S.getRowByID(t);n||(n=r.content,n||(n=" "));const o=r.type;if(o==="l")e=t;else if(o==="d"||o===void 0)break;if(!t||(t=r.parent_id,!o))break}return[e,n]},async deleteBlocksUtil(){const{aacc1:t,aacc2:e}=await Bm();if(t!=null&&t.id)if(e!=null&&e.id){if(t.root_id!==e.root_id){S.pushMsg("aacc1 aacc2 must be in the same doc");return}}else{S.pushMsg("aacc2 not found");return}else{S.pushMsg("aacc1 not found");return}let n=!1;const{root:{children:i}}=await Sz(t.root_id,"",!1,!1,1),r=[];for(const o of i)if(o.id===t.id&&(n=!0),n&&r.push(o.id),o.id===e.id)break;if(r.length===0)return r;await S.deleteBlocks(r)},async moveBlocksUtil(t=!1){const e=[],{aacc1:n,aacc2:i,aacc3:r}=await Bm();if(n!=null&&n.id)if(i!=null&&i.id)if(r!=null&&r.id){if(n.root_id!==i.root_id)return S.pushMsg("aacc1 aacc2 must be in the same doc"),e}else return S.pushMsg("aacc3 not found"),e;else return S.pushMsg("aacc2 not found"),e;else return S.pushMsg("aacc1 not found"),e;{let A=!1;const{root:{children:a}}=await Sz(n.root_id,"",!1,!1,1);for(const s of a){if(s.id===n.id){A=!0;continue}if(s.id===i.id)break;A&&e.push(s)}}if(e.length===0)return e;const o=[];if(t){const A=e.map(a=>{const s=gA(a.div);return a.div=s.div,a.id=s.newID,a.div}).map(a=>a.outerHTML);o.push(...S.transInsertBlocksAfter(A,r.id))}else o.push(...S.transMoveBlocksAfter(e.map(A=>A.id),r.id));return o.push(...S.transDeleteBlocks([n.id,i.id,r.id])),await S.transactions(o),e},async getBlockKramdownWithoutID(t,e=[],n,i){const{kramdown:r}=await S.getBlockKramdown(t),o=r.split(`
`);let A=o.pop();o.length>0&&(n&&(o[0]=n+o[0]),i&&(o[o.length-1]+=i));const a=/id="[^"]+"/,s=/custom-riff-decks="[^"]+"/;if(A=A.replace(a,""),A=A.replace(s,""),e){A=A.trim(),A=A.slice(0,A.length-1);for(const c of e)A+=" "+c+" ";A+="}"}return A!="{: }"&&o.push(A),o.join(`
-`)},async removeBrokenCards(t){if(!O0.isDesktop){S.pushMsg("can only run in desktop env.");return}return navigator.locks.request("removeBrokenCardsLock",{ifAvailable:!0},async e=>{var o,A,a;if(!e)return;if(!((a=(A=(o=await S.getConf())==null?void 0:o.conf)==null?void 0:A.repo)!=null&&a.key)){await S.pushMsg(t.你还没秘钥插件无法为您创建本地快照,0);return}S.pushMsg(t.正在确认无效闪卡请耐心等待,1800);const n=await xO(),i=Ry(n),r=[];for(const s of[...(await S.getRiffCardsAll()).values()].flat())i.has(s.id)||r.push(s.id);if(r.length>0){const c=r.slice(0,10).map(l=>`${l}`).join("
");let u="";r.length>10&&(u="
……"),c1.confirm("⚠️"+t.准备删除失效闪卡(r.length),t.即将创建快照+"
"+c+u,async()=>{await S.createSnapshot(t.清理所有失效的闪卡),await S.removeRiffCards(r),await S.pushMsg(t.清理所有失效的闪卡+" : "+r.length)})}else c1.confirm("😄",t.没有失效闪卡);return{bigText:n,allIDs:i}})},async getDocNameByBlockID(t){let e=await S.sqlOne(`select root_id from blocks where id="${t}"`);return e!=null&&e.root_id&&(e=await S.sqlOne(`select content from blocks where id="${e.root_id}"`),e!=null&&e.content)?e.content:""}},Uf={createDocWithMdIfNotExists:Uz(S.createDocWithMdIfNotExists),getRiffCardsByBlockIDs:Uz(S.getRiffCardsByBlockIDs)};async function Bm(){return await S.sql(`select id,root_id,content from blocks where type='p' and content in ("aacc1","aacc2","aacc3")`).then(t=>{let e,n,i;return t.forEach(r=>{switch(r.content){case"aacc1":e=r;break;case"aacc2":n=r;break;case"aacc3":i=r;break}}),{aacc1:e,aacc2:n,aacc3:i}})}async function xO(){return await kO().then(async t=>{const e=[];for(const n of ka(t,50)){const i=await Promise.all(n.map(r=>S.getFile(r)));e.push(...i)}return e}).then(t=>t.join(""))}async function Ey(t){S.pushMsg("Start to delete invalid databases."),t||(await S.createSnapshot("delete invalid databases."),t=await xO());let e=await S.readDir("/data/storage/av").then(n=>n.map(i=>{const r=i.name.split(".");if(r.pop()==="json")return r.join(".")})).then(n=>n.filter(i=>!!i));e=e.filter(n=>!t.includes(`"AttributeViewID":"${n}"`));for(const n of e)await S.removeFile(`/data/storage/av/${n}.json`),S.pushMsg("delete database: "+n);S.pushMsg(`${e.length} invalid databases have been deleted.`)}function Uz(t){const e=new Map;return async function(i,...r){const o=Date.now();for(const[s,c]of e.entries())o-c.timestamp>i&&e.delete(s);const A=JSON.stringify(r);if(e.has(A)){const{value:s}=e.get(A);return s}const a=await t(...r);return e.set(A,{value:a,timestamp:Date.now()}),a}}function vT(t,e,n){const i=t.length;if(i>=e)return t;const r=e-i;return n.repeat(Math.ceil(r/n.length)).slice(0,r)+t}function Ty(t){const e=Math.floor(t.length/2),n=t.substring(0,e),i=t.substring(e);return[n,i]}function CT(t,e,n){let i=t.split(e);if(i.length==1)return t;{const r=[];r.push(i[0]);for(let o=1;o0?i[r]=".."+i[r].slice(A,o)+e:i[r]=i[r].slice(A,o)+e}else n{var o,A,a;if(!e)return;if(!((a=(A=(o=await S.getConf())==null?void 0:o.conf)==null?void 0:A.repo)!=null&&a.key)){await S.pushMsg(t.你还没秘钥插件无法为您创建本地快照,0);return}S.pushMsg(t.正在确认无效闪卡请耐心等待,1800);const n=await xO(),i=Ry(n),r=[];for(const s of[...(await S.getRiffCardsAll()).values()].flat())i.has(s.id)||r.push(s.id);if(r.length>0){const c=r.slice(0,10).map(l=>`${l}`).join("
");let u="";r.length>10&&(u="
……"),c1.confirm("⚠️"+t.准备删除失效闪卡(r.length),t.即将创建快照+"
"+c+u,async()=>{await S.createSnapshot(t.清理所有失效的闪卡),await S.removeRiffCards(r),await S.pushMsg(t.清理所有失效的闪卡+" : "+r.length)})}else c1.confirm("😄",t.没有失效闪卡);return{bigText:n,allIDs:i}})},async getDocNameByBlockID(t){let e=await S.sqlOne(`select root_id from blocks where id="${t}"`);return e!=null&&e.root_id&&(e=await S.sqlOne(`select content from blocks where id="${e.root_id}"`),e!=null&&e.content)?e.content:""}},Uf={createDocWithMdIfNotExists:Uz(S.createDocWithMdIfNotExists),getRiffCardsByBlockIDs:Uz(S.getRiffCardsByBlockIDs)};async function Bm(){return await S.sql(`select id,root_id,content from blocks where type='p' and content in ("aacc1","aacc2","aacc3")`).then(t=>{let e,n,i;return t.forEach(r=>{switch(r.content){case"aacc1":e=r;break;case"aacc2":n=r;break;case"aacc3":i=r;break}}),{aacc1:e,aacc2:n,aacc3:i}})}async function xO(){return await kO().then(async t=>{const e=[];for(const n of ka(t,50)){const i=await Promise.all(n.map(r=>S.getFile(r)));e.push(...i)}return e}).then(t=>t.join(""))}async function Ey(t){if(!O0.isDesktop){S.pushMsg("can only run in desktop env.");return}S.pushMsg("Start to delete invalid databases."),t||(await S.createSnapshot("delete invalid databases."),t=await xO());let e=await S.readDir("/data/storage/av").then(n=>n.map(i=>{const r=i.name.split(".");if(r.pop()==="json")return r.join(".")})).then(n=>n.filter(i=>!!i));e=e.filter(n=>!t.includes(`"AttributeViewID":"${n}"`));for(const n of e)await S.removeFile(`/data/storage/av/${n}.json`),S.pushMsg("delete database: "+n);S.pushMsg(`${e.length} invalid databases have been deleted.`)}function Uz(t){const e=new Map;return async function(i,...r){const o=Date.now();for(const[s,c]of e.entries())o-c.timestamp>i&&e.delete(s);const A=JSON.stringify(r);if(e.has(A)){const{value:s}=e.get(A);return s}const a=await t(...r);return e.set(A,{value:a,timestamp:Date.now()}),a}}function vT(t,e,n){const i=t.length;if(i>=e)return t;const r=e-i;return n.repeat(Math.ceil(r/n.length)).slice(0,r)+t}function Ty(t){const e=Math.floor(t.length/2),n=t.substring(0,e),i=t.substring(e);return[n,i]}function CT(t,e,n){let i=t.split(e);if(i.length==1)return t;{const r=[];r.push(i[0]);for(let o=1;o0?i[r]=".."+i[r].slice(A,o)+e:i[r]=i[r].slice(A,o)+e}else n