"))return b;if(rc(b))return b=mb(b),`${b}
-${pn(a)}`;if(z==="l"){const{div:M}=await Mc(c);mh(M,a),at(M),b=this.lute.BlockDOM2Md(M.outerHTML),b=mb(b);const i=b.trim().split(`
+`),a)}async fastCopyBlock(e,t,c,b,a,z,r){if(r&&(z["custom-in-book-index"]=`${e}#${r.i}`,z["custom-paragraph-index"]=String(r.i),t.addIndex2paragraph&&(b.startsWith("#")||b.startsWith("!")||b.startsWith("[")||b.startsWith("*")||zc(b)||(b=`[${r.i}]`+b)),r.i++),z["custom-progref"]=c,b.startsWith("
"))return b;if(zc(b))return b=gb(b),`${b}
+${on(z)}`;if(a==="l"){const{div:o}=await ea(c);Rh(o,z),at(o),b=this.lute.BlockDOM2Md(o.outerHTML),b=gb(b);const i=b.trim().split(`
`);return i.pop(),b=i.join(`
`),b=`${b}
-${pn(a)}`,b}else return b=mb(b),`${b}${re(c," * ",this.settings.pieceNoBacktraceLink)}
-${pn(a)}`}async copyBlock(e,t,c,b,z=[],a){if(!b||b.getAttribute(g1))return"";const r=Ot(b);if(r){if(!this.settings.pieceNoBacktraceLink){const O=r.appendChild(document.createElement("span"));_n(O,c," * ")}if(a&&b.getAttribute(a1)!=q1.NODE_HEADING&&(b.setAttribute(n2,String(a.i)),b.setAttribute(t2,`${e}#${a.i}`),t.addIndex2paragraph)){const O=r.insertBefore(document.createElement("span"),r.firstChild);O&&(O.setAttribute(a1,"text"),O.textContent=`[${a.i}]`)}a&&a.i++}const M=this.lute.BlockDOM2StdMd(b.outerHTML).replace(/\u200B/g,"").trim();return!M||M=="*"?"":(at(b),b.setAttribute(ee,c),z.forEach(O=>b.setAttribute(O,"1")),this.lute.BlockDOM2Md(b.outerHTML).trim())}async getBook2Learn(e){if(e)return this.storage.booksInfo(e);const t=this.storage.booksInfos();let c=Number.MAX_SAFE_INTEGER,b="";for(const z in t){const{time:a,ignored:r}=t[z];r||a
`,width:L0.isMobile?"90vw":"700px",height:L0.isMobile?"180vw":"800px",destroyCallback:()=>{t==null||t.$destroy(),t=void 0}});t=new If({target:c.element.querySelector("#"+e),props:{dialog:c}})}}const o0=new Wh;function mh(n,e){n.querySelectorAll(`div[${J1}]`).forEach(t=>{const c=t.parentElement;if(c){const b=c.getAttribute(c1);if(e)for(const z in e)c.setAttribute(z,e[z]);b&&(o0.settings.pieceNoBacktraceLink||QA(t,b,"*"),c.setAttribute(fe,"1"),c.setAttribute(ee,b))}})}function Rh(n){for(let e=0;e<1e3&&n;e++,n=n.previousElementSibling){const t=n.getAttribute(ee),c=n.getAttribute(n2)??"",b=n.getAttribute(t2)??"";if(t)return{ref:t,idx:c,bIdx:b}}return{}}function _h(n){for(let e=0;e<1e3&&n;e++,n=n.nextElementSibling){const t=n.getAttribute(ee),c=n.getAttribute(n2)??"",b=n.getAttribute(t2)??"";if(t)return{ref:t,idx:c,bIdx:b}}return{}}function Ge(n="",...e){const t=document.createElement("div");t.setAttribute(c1,P1()),t.setAttribute(a1,q1.NODE_PARAGRAPH),t.classList.add("p");const c=t.appendChild(document.createElement("div"));return c.setAttribute(J1,"true"),c.setAttribute("spellcheck","false"),c.textContent=n,e&&e.forEach(b=>{c.append(b),c.append(document.createTextNode(" "))}),t.appendChild(ca()),t}function yh(){const n=document.createElement("div");return n.classList.add("protyle-action"),n.setAttribute("draggable","true"),n.appendChild(document.createElement("svg")).appendChild(document.createElement("use")).setAttribute("xlink:href","#iconDot"),n}function ca(){const n=document.createElement("div");return n.classList.add("protyle-attr"),n.setAttribute(J1,"false"),n.textContent=Pi,n}class gp{constructor(){U(this,"_container",document.createElement("div"));U(this,"_id",P1());this.container.setAttribute(c1,this.id)}append(...e){return e.forEach(t=>this.container.appendChild(t)),this}build(){return this.container.appendChild(ca()),this.container}setAttrs(e){return Object.entries(e).forEach(([t,c])=>this.setAttr(t,c)),this}setAttr(e,t){return this.container.setAttribute(e,t),this}get container(){return this._container}get id(){return this._id}setID(e){return this._id=e,this.container.setAttribute(c1,e),this}}class ba extends gp{constructor(){super(),this.container.classList.add("list"),this.container.setAttribute(a1,q1.NODE_LIST),this.container.setAttribute(dn,"u")}append2FirstItem(e){const t=this.container.firstElementChild;return t?(e.removeAttribute(Qt),t.lastElementChild.insertAdjacentElement("beforebegin",e)):this.append(e),this}newList(e){const t=new ba;return this.append(e,t.container),t}append(...e){e.forEach(c=>c.removeAttribute(Qt));const t=document.createElement("div");return t.setAttribute("data-marker","*"),t.setAttribute(dn,"u"),t.setAttribute(c1,P1()),t.setAttribute(a1,q1.NODE_LIST_ITEM),t.classList.add("li"),t.appendChild(yh()),e.forEach(c=>t.appendChild(c)),t.appendChild(ca()),this.container.append(t),this}}async function Lh(n,e=!0){const t=n.map(b=>[...b.querySelectorAll('span[data-type="virtual-block-ref"]')].map(z=>z.textContent)).flat(),c=n.map(b=>[...b.querySelectorAll('span[data-type="block-ref"]')].map(z=>{const a=z.textContent.trim();if(a=="*"||a=="@"||a=="+"||a=="&")return;const r=z.cloneNode(!0);if(e){z.setAttribute(a1,"a"),z.removeAttribute(dn);const M=z.getAttribute(zn);z.removeAttribute(zn),z.setAttribute("data-href",`siyuan://blocks/${M}`)}return r})).flat();if((t==null?void 0:t.length)>0){const b=t.map(a=>`"${a}"`).join(","),z=await A.sql(`select id,content from blocks where type='d' and content in (${b})`).then(a=>a.map(r=>{const M=document.createElement("span");return M.textContent=r.content,M.setAttribute(a1,to),M.setAttribute(dn,"d"),M.setAttribute(zn,r.id),M}));c.push(...z)}return c}class Nh extends ba{constructor(t,c=!1){super();U(this,"supBuilder");const b=()=>(t==null?void 0:t.length)>0?Ge("",...t):Ge("refs:");this.supBuilder=new wh,c?this.newList(b()).append(this.supBuilder.container):(this.append2FirstItem(b()),this.append2FirstItem(this.supBuilder.container))}appendSup(...t){return this.supBuilder.append(...t),this}addBottomLine(){this.supBuilder.setAttr("custom-super-list","1")}}class wh extends gp{constructor(e="row"){super(),this.container.classList.add("sb"),this.container.setAttribute(a1,q1.NODE_SUPER_BLOCK),this.container.setAttribute("data-sb-layout",e)}}function $2(){const n=ne.dateFormat(new Date).split(" ")[0],[e,t]=n.split("-");return`/daily card/c${e}/c${e}-${t}/c${n}`}function Bh(){const n=ne.dateFormat(new Date).split(" ")[0],[e,t,c]=n.split("-");return e+t+c}function Wp(n){var t;if(!n)return{};if(((t=n==null?void 0:n.tagName)==null?void 0:t.toLocaleLowerCase())=="body")return{};const e=n.getAttribute(c1)??"";return e?{dom:n,blockID:e}:Wp(n.parentElement)}class vh{constructor(){U(this,"plugin");U(this,"settings")}blockIconEvent(e){this.plugin&&(e.menu.addItem({iconHTML:"+🗃️",accelerator:"⌥E",label:this.plugin.i18n.insertBlankSpaceCard,click:()=>{this.makeCard(e.protyle,"None")}}),e.menu.addItem({iconHTML:"+🗃️⬇️",accelerator:"⌥`",label:this.plugin.i18n.insertBlankSpaceCardHere,click:()=>{this.makeCard(e.protyle,"Here")}}),e.menu.addItem({iconHTML:"🗓️🗃️⭐",accelerator:"⌘`",label:this.plugin.i18n.send2dailyCard,click:()=>{this.makeCard(e.protyle,"None",$2())}}),e.menu.addItem({iconHTML:"🗓️🗃️",accelerator:"⌥S",label:this.plugin.i18n.send2dailyCardNoRef,click:()=>{this.makeCard(e.protyle,"None",$2(),!0)}}))}async onload(e,t){this.plugin=e,this.settings=t,this.plugin.addCommand({langKey:"insertBlankSpaceCard",hotkey:"⌥E",callback:()=>{var c;this.makeCard((c=L0.protyle)==null?void 0:c.protyle,"None")}}),this.plugin.addCommand({langKey:"insertBlankSpaceCardHere",hotkey:"⌥`",callback:()=>{var c;this.makeCard((c=L0.protyle)==null?void 0:c.protyle,"Here")}}),this.plugin.addCommand({langKey:"send2dailyCard",hotkey:"⌘`",callback:()=>{var c;this.makeCard((c=L0.protyle)==null?void 0:c.protyle,"None",$2())}}),this.plugin.addCommand({langKey:"send2dailyCardNoRef",hotkey:"⌥S",callback:()=>{var c;this.makeCard((c=L0.protyle)==null?void 0:c.protyle,"None",$2(),!0)}}),this.plugin.addCommand({langKey:"cardMark",hotkey:"⌥D",editorCallback:async c=>{const{selected:b,rangeText:z}=await L0.selectedDivs(c);if(z)c.toolbar.setInlineMark(c,"mark","range");else if(b.length>0){const a=b.map(r=>(r.querySelectorAll("span").forEach(i=>{const O=i.getAttribute(a1);O?O.includes("mark")||i.setAttribute(a1,O+" mark"):i.setAttribute(a1,"mark")}),mM(r).forEach(i=>{i.childNodes.forEach(O=>{if(O.nodeType===3){const u=document.createElement("span");u.setAttribute(a1,"mark"),u.textContent=O.textContent,O.parentElement.replaceChild(u,O)}})}),{id:r.getAttribute(c1),domStr:r.outerHTML})).filter(r=>!!r.id);(a==null?void 0:a.length)>0&&c.getInstance().transaction(A.transUpdateBlocks(a))}}}),this.plugin.eventBus.on("open-menu-content",({detail:c})=>{const b=c.menu;b.addItem({label:this.plugin.i18n.insertBlankSpaceCard,iconHTML:"+🗃️",accelerator:"⌥E",click:()=>{var r,M,i;const z=((r=c==null?void 0:c.element)==null?void 0:r.getAttribute("data-node-id"))??"",a=((i=(M=c==null?void 0:c.range)==null?void 0:M.cloneContents())==null?void 0:i.textContent)??"";z&&this.blankSpaceCard(z,a,c==null?void 0:c.range,c==null?void 0:c.protyle,"None")}}),b.addItem({label:T.原地制卡,iconHTML:"+🗃️⬇️",accelerator:"⌥`",click:()=>{var r,M,i;const z=((r=c==null?void 0:c.element)==null?void 0:r.getAttribute("data-node-id"))??"",a=((i=(M=c==null?void 0:c.range)==null?void 0:M.cloneContents())==null?void 0:i.textContent)??"";z&&this.blankSpaceCard(z,a,c==null?void 0:c.range,c==null?void 0:c.protyle,"Here")}}),b.addItem({label:this.plugin.i18n.send2dailyCard,iconHTML:"🗓️🗃️⭐",accelerator:"⌘`",click:()=>{var r,M,i;const z=((r=c==null?void 0:c.element)==null?void 0:r.getAttribute("data-node-id"))??"",a=((i=(M=c==null?void 0:c.range)==null?void 0:M.cloneContents())==null?void 0:i.textContent)??"";z&&this.blankSpaceCard(z,a,c==null?void 0:c.range,c==null?void 0:c.protyle,"None",$2())}}),b.addItem({label:this.plugin.i18n.send2dailyCardNoRef,iconHTML:"🗓️🗃️",accelerator:"⌥S",click:()=>{var r,M,i;const z=((r=c==null?void 0:c.element)==null?void 0:r.getAttribute("data-node-id"))??"",a=((i=(M=c==null?void 0:c.range)==null?void 0:M.cloneContents())==null?void 0:i.textContent)??"";z&&this.blankSpaceCard(z,a,c==null?void 0:c.range,c==null?void 0:c.protyle,"None",$2(),!0)}})})}async makeCard(e,t,c,b){var r,M;if(!e)return;const{ids:z,divs:a}=await this.cloneSelectedLineMarkdowns(e,b);if(z.length>0)await this.insertCard(e,a,t,z[z.length-1],c);else{const i=L0.lastBlockID,O=(r=document.getSelection())==null?void 0:r.getRangeAt(0),u=((M=O==null?void 0:O.cloneContents())==null?void 0:M.textContent)??"";i&&this.blankSpaceCard(i,u,O,e,t,c,b)}}async insertCard(e,t,c,b,z){return navigator.locks.request("prog-FlashBox-insertCard",{mode:"exclusive"},async a=>this.doInsertCard(e,t,c,b,z))}async doInsertCard(e,t,c,b,z){var y;const a=e.notebookId,r=(y=e.block)==null?void 0:y.rootID;if(!r)return;let{bookID:M}=await Hc(r);const i=await A.getBlockAttrs(r),O=i["custom-card-priority"],{cardID:u,domStr:l,text:R}=await this.createList(t,O),_=[];if(z){const w=await xh(a,z);_.push(...A.transInsertBlocksAfter([l,Ge().outerHTML],await A.getDocLastID(w)))}else if(c=="Here")_.push(...A.transInsertBlocksAfter([l,Ge().outerHTML],b));else{let w="";if(M&&!this.settings.cardUnderPiece?w=await ae(M,"cards"):(w=await ae(r,"cards"),M=r),!w)return;const k=await TM(M,a,w);_.push(...A.transInsertBlocksAfter([l,Ge().outerHTML],await A.getDocLastID(k)))}if(this.settings.markOriginText&&!await L0.isDocReadonly(e,i)){const{div:w}=await Mc(b);this.settings.markOriginTextBG&&(w.style.backgroundColor="var(--b3-font-background7)");const k=Ot(w);if(k){const S=k.appendChild(document.createElement("span"));_n(S,u," & "),_.push(...A.transUpdateBlocks([{id:b,domStr:w.outerHTML}]))}}_.push(A.transAddRiffCards([u])),_.push(A.transDoUpdateUpdated(u)),await A.transactions(_).then(()=>{c!=="Here"&&$1(this.plugin,u,ve.get(),null,null,b),A.addRiffCards([u]),A.pushMsg("⚡🗃"+R,2e3)})}async createList(e,t){let c="",b="",z="";const a=await Lh(e);for(const i of e)c||(c=i.getAttribute(Et)),b||(b=i.getAttribute(Pt)),z||(z=i.getAttribute(t2)),i.removeAttribute(ee),i.removeAttribute(t2),i.removeAttribute(n2),i.removeAttribute(fe),i.removeAttribute(Yi),i.removeAttribute(Zn),i.removeAttribute("custom-prog-words");const r=new Nh(a);if(e.forEach(i=>{i.removeAttribute(Et),i.removeAttribute(Pt),i.style.background="",i.querySelectorAll(`span[${a1}="a"]`).forEach(O=>{var l;const u=(l=O.textContent)==null?void 0:l.trim();(u=="&"||u=="+")&&O.parentElement.removeChild(O)}),r.appendSup(i)}),this.settings.cardAppendTime){c?r.appendSup(Ge(`【${c}】`)):b&&r.appendSup(Ge(`【${b}】`));const i=ne.dateFormat(ne.now());r.appendSup(Ge(`【${i}】`))}MM.get()&&r.addBottomLine();const M=r.build();return t&&M.setAttribute(Ji,t),c&&M.setAttribute(Et,c),b&&M.setAttribute(Pt,b),{cardID:r.id,div:M,domStr:M.outerHTML,text:M.textContent}}async cloneSelectedLineMarkdowns(e,t){var i;const c=(i=e==null?void 0:e.element)==null?void 0:i.querySelectorAll(`.${co}`),b=[];let z=!t,a=!0;const r=[],M=await L0.isDocReadonly(e);for(const O of c){const{id:u,div:l,setTheRef:R,setPath:_}=await this.cloneDiv(O,z,a);this.settings.markOriginText&&!M&&this.settings.markOriginTextBG&&(O.style.backgroundColor="var(--b3-font-background7)"),R&&(z=!1),_&&(a=!1),r.push(u),b.push(l)}return this.settings.markOriginText&&!M&&this.settings.markOriginTextBG&&Br(r),{divs:b,ids:r}}async cloneDiv(e,t,c=!0){return e=e.cloneNode(!0),gM(e,t,t,this.settings.flashcardMultipleLnks,c,this.settings.flashcardUseLink)}async blankSpaceCard(e,t,c,b,z,a,r){let M;const{dom:i}=Wp(c.endContainer.parentElement);if(!i)return;const O=await L0.isDocReadonly(b);if(t){O&&i.querySelectorAll(`div[${J1}="false"]`).forEach(l=>l.setAttribute(J1,"true")),b.toolbar.setInlineMark(b,"mark","range");const{div:u}=await this.cloneDiv(i,!r);b.toolbar.setInlineMark(b,"mark","range"),O&&i.querySelectorAll(`div[${J1}="true"]`).forEach(l=>l.setAttribute(J1,"false")),this.settings.markOriginTextBG&&!O&&(b.toolbar.setInlineMark(b,"text","range",{type:"backgroundColor",color:"var(--b3-font-background9)"}),u.querySelectorAll('[data-type~="text"]').forEach(l=>{l.style.backgroundColor=="var(--b3-font-background9)"&&(l.style.backgroundColor="")}),u.querySelectorAll('[data-type~="prog-marked"]').forEach(l=>{const R=l.getAttribute("data-type").replace("prog-marked","");l.setAttribute("data-type",R),l.style.backgroundColor=""})),M=u}else{const{id:u,div:l}=await this.cloneDiv(i,!r);M=l,this.settings.markOriginText&&!O&&this.settings.markOriginTextBG&&Br([u])}await this.insertCard(b,[M],z,e,a)}}const wr=new vh;async function xh(n,e){const t=Bh(),c={};return c[`custom-dailycard-${t}`]=t,await p2.createDocWithMdIfNotExists(5e3,n,e,"",c)}async function Br(n){const e={style:"background-color: var(--b3-font-background7);"};return A.batchSetBlockAttrs(n.map(t=>({id:t,attrs:e})))}class Sh{constructor(){U(this,"plugin");U(this,"settings")}blockIconEvent(e){if(!this.plugin)return;const t=e.protyle,{isPiece:c}=B2(t);c&&(e.menu.addItem({iconHTML:"🚚⬆️",label:T.移动到上一分片内,click:()=>{this.move(t,-1)}}),e.menu.addItem({iconHTML:"🚚⬇️",label:T.移动到下一分片内,click:()=>{this.move(t,1)}}))}async onload(e,t){this.plugin=e,this.settings=t,this.plugin.eventBus.on("open-menu-content",({detail:c})=>{const b=c.protyle,{isPiece:z}=B2(b);if(z){const a=c.menu;a.addItem({label:T.移动到上一分片内,iconHTML:"🚚⬆️",click:()=>{this.move(b,-1)}}),a.addItem({label:T.移动到下一分片内,iconHTML:"🚚⬇️",click:()=>{this.move(b,1)}})}})}async move(e,t){if(t==0)return;const{ids:c}=await L0.selectedDivs(e);if(!c||c.length==0)return;const{bookID:b,pieceNum:z}=await qp(c[0]);if(g2(z)&&b){const a=z+t;if(a>=0){const r=await A.sqlOne(`select id from blocks where type='d' and ial like "%${Sc(b,a)}%"`);if(r!=null&&r.id)if(t<0){const M=await A.getTailChildBlocks(r.id,1);await A.moveBlocksAfter(c,M[0].id)}else await A.moveBlocksAsChild(c,r.id)}}}}const vr=new Sh;class Th{constructor(){U(this,"plugin");U(this,"settings");U(this,"lute")}async onload(e,t){this.plugin=e,this.settings=t,this.lute=Jz(),this.plugin.addCommand({langKey:"collect",hotkey:"⌥⇧Z",callback:()=>{var c;this.copyBlocks((c=L0.protyle)==null?void 0:c.protyle)}}),this.plugin.eventBus.on("open-menu-content",({detail:c})=>{c.menu.addItem({iconHTML:"💼",label:this.plugin.i18n.collect,accelerator:"",click:async()=>{var z;this.copyBlocks((z=L0.protyle)==null?void 0:z.protyle)}})})}async copyBlocks(e){const{selected:t}=await L0.selectedDivs(e);if(!((t==null?void 0:t.length)>0))return;let c;if(!this.settings.summary2dailynote){const{bookID:b}=await qp(WM(t[0]));if(b&&(c=await kM(b),!c)){const z=await ae(b,"summary");z&&(c=await rf(b,L0.boxID,z))}}if(c||(c=(await A.createDailyNote(L0.boxID)).id),c){const b=t.map(a=>qM(a)),z=b[b.length-1].newID;await A.appendBlocks(b.map(a=>a.div.outerHTML),c),await $1(this.plugin,z,ve.get())}}}const Xh=new Th;function xr(n){return{ial:zt(n.ial),id:n.id,markdown:n.markdown,content:n.content}}class kh{constructor(){U(this,"plugin");U(this,"settings")}async onload(e,t){this.plugin=e,this.settings=t,this.plugin.addCommand({langKey:"extractAllNotes",hotkey:"⌘F4",editorCallback:async c=>{const{isPiece:b,markKey:z}=B2(c);b&&await this.extractAllNotes(c.notebookId,z)}}),this.plugin.addCommand({langKey:"extractNotes",hotkey:"⌘F5",editorCallback:async c=>{var a;const{isPiece:b,markKey:z}=B2(c);b&&await this.extractNotes((a=c.block)==null?void 0:a.rootID,c.notebookId,z)}}),this.plugin.addCommand({langKey:"2024-08-09 15:10:45 extract book",langText:T.合并所有分片到新文件,hotkey:"",editorCallback:async c=>{var a;const{isPiece:b,markKey:z}=B2(c);b&&await this.extractAsBook(c.notebookId,(a=c.block)==null?void 0:a.rootID,c.notebookId,z)}}),this.plugin.addCommand({langKey:"compareNotes",hotkey:"⌘F6",editorCallback:async c=>{var a;const{isKeyDoc:b,keyDocAttr:z}=ir(c);b&&await this.compareNotes((a=c.block)==null?void 0:a.rootID,c.notebookId,z)}}),this.plugin.eventBus.on("open-menu-content",({detail:c})=>{const b=c.protyle,{isPiece:z,markKey:a}=B2(b);if(z){const r=c.menu;r.addItem({label:this.plugin.i18n.extractAllNotes,icon:"iconCopy",accelerator:"⌘F4",click:async()=>{await this.extractAllNotes(b.notebookId,a)}}),r.addItem({label:this.plugin.i18n.extractNotes,icon:"iconCopy",accelerator:"⌘F5",click:async()=>{var M;await this.extractNotes((M=b.block)==null?void 0:M.rootID,b.notebookId,a)}}),r.addItem({label:T.合并所有分片到新文件,icon:"iconCopy",accelerator:"",click:async()=>{var M;await this.extractAsBook(b.notebookId,(M=b.block)==null?void 0:M.rootID,b.notebookId,a)}})}else{const{isKeyDoc:r,keyDocAttr:M}=ir(b);r&&c.menu.addItem({label:this.plugin.i18n.compareNotes,icon:"iconEye",accelerator:"⌘F6",click:async()=>{var O;await this.compareNotes((O=b.block)==null?void 0:O.rootID,b.notebookId,M)}})}})}async extractAllNotes(e,t){A.pushMsg("extract all notes");const c=t.split(",")[0],b=await Sr(c),a=(await A.getRows(b,"markdown",!0,[`ial not like "%${fe}%"`])).map(i=>{var O;if((O=i.markdown)!=null&&O.trim())return`${i.markdown} ${re(i.id,"*")}
-{: id="${P1()}"}`}).filter(i=>!!i),r=c.split("#")[1];let M=await CM(r);if(!M){const i=await ae(r,"collection");i&&(M=await Mf(r,e,i))}M&&(await A.clearAll(M),await A.insertBlockAsChildOf(`{{{row
-${a.join(`
+${on(z)}`,b}else return b=gb(b),`${b}${ze(c," * ",this.settings.pieceNoBacktraceLink)}
+${on(z)}`}async copyBlock(e,t,c,b,a=[],z){if(!b||b.getAttribute(g1))return"";const r=st(b);if(r){if(!this.settings.pieceNoBacktraceLink){const O=r.appendChild(document.createElement("span"));Rn(O,c," * ")}if(z&&b.getAttribute(z1)!=q1.NODE_HEADING&&(b.setAttribute(Ze,String(z.i)),b.setAttribute(e2,`${e}#${z.i}`),t.addIndex2paragraph)){const O=r.insertBefore(document.createElement("span"),r.firstChild);O&&(O.setAttribute(z1,"text"),O.textContent=`[${z.i}]`)}z&&z.i++}const o=this.lute.BlockDOM2StdMd(b.outerHTML).replace(/\u200B/g,"").trim();return!o||o=="*"?"":(at(b),b.setAttribute(Z1,c),a.forEach(O=>b.setAttribute(O,"1")),this.lute.BlockDOM2Md(b.outerHTML).trim())}async getBook2Learn(e){if(e)return this.storage.booksInfo(e);const t=this.storage.booksInfos();let c=Number.MAX_SAFE_INTEGER,b="";for(const a in t){const{time:z,ignored:r}=t[a];r||z
`,width:L0.isMobile?"90vw":"700px",height:L0.isMobile?"180vw":"800px",destroyCallback:()=>{t==null||t.$destroy(),t=void 0}});t=new Ef({target:c.element.querySelector("#"+e),props:{dialog:c}})}}const M0=new mh;function Rh(n,e){n.querySelectorAll(`div[${$1}]`).forEach(t=>{const c=t.parentElement;if(c){const b=c.getAttribute(c1);if(e)for(const a in e)c.setAttribute(a,e[a]);b&&(M0.settings.pieceNoBacktraceLink||ZA(t,b,"*"),c.setAttribute(Ae,"1"),c.setAttribute(Z1,b))}})}function _h(n){for(let e=0;e<1e3&&n;e++,n=n.previousElementSibling){const t=n.getAttribute(Z1),c=n.getAttribute(Ze)??"",b=n.getAttribute(e2)??"";if(t)return{ref:t,idx:c,bIdx:b}}return{}}function yh(n){for(let e=0;e<1e3&&n;e++,n=n.nextElementSibling){const t=n.getAttribute(Z1),c=n.getAttribute(Ze)??"",b=n.getAttribute(e2)??"";if(t)return{ref:t,idx:c,bIdx:b}}return{}}function O2(n="",...e){const t=document.createElement("div");t.setAttribute(c1,E1()),t.setAttribute(z1,q1.NODE_PARAGRAPH),t.classList.add("p");const c=t.appendChild(document.createElement("div"));return c.setAttribute($1,"true"),c.setAttribute("spellcheck","false"),e||(e=[]),e.splice(0,0,document.createTextNode(n)),FA(e,()=>document.createTextNode(" ")).forEach(b=>c.append(b)),t.appendChild(tz()),t}function Lh(){const n=document.createElement("div");return n.classList.add("protyle-action"),n.setAttribute("draggable","true"),n.appendChild(document.createElement("svg")).appendChild(document.createElement("use")).setAttribute("xlink:href","#iconDot"),n}function tz(){const n=document.createElement("div");return n.classList.add("protyle-attr"),n.setAttribute($1,"false"),n.textContent=Pi,n}class gp{constructor(){U(this,"_container",document.createElement("div"));U(this,"_id",E1());this.container.setAttribute(c1,this.id)}append(...e){return e.forEach(t=>this.container.appendChild(t)),this}build(){return this.container.appendChild(tz()),this.container}setAttrs(e){return Object.entries(e).forEach(([t,c])=>this.setAttr(t,c)),this}setAttr(e,t){return this.container.setAttribute(e,t),this}get container(){return this._container}get id(){return this._id}setID(e){return this._id=e,this.container.setAttribute(c1,e),this}}class cz extends gp{constructor(){super(),this.container.classList.add("list"),this.container.setAttribute(z1,q1.NODE_LIST),this.container.setAttribute(un,"u")}append2FirstItem(e){const t=this.container.firstElementChild;return t?(e.removeAttribute(Vt),t.lastElementChild.insertAdjacentElement("beforebegin",e)):this.append(e),this}newList(e){const t=new cz;return this.append(e,t.container),t}append(...e){e.forEach(c=>c.removeAttribute(Vt));const t=document.createElement("div");return t.setAttribute("data-marker","*"),t.setAttribute(un,"u"),t.setAttribute(c1,E1()),t.setAttribute(z1,q1.NODE_LIST_ITEM),t.classList.add("li"),t.appendChild(Lh()),e.forEach(c=>t.appendChild(c)),t.appendChild(tz()),this.container.append(t),this}}async function Nh(n,e=!0){const t=n.map(b=>[...b.querySelectorAll('span[data-type="virtual-block-ref"]')].map(a=>a.textContent)).flat(),c=n.map(b=>[...b.querySelectorAll('span[data-type="block-ref"]')].map(a=>{const z=a.textContent.trim();if(z=="*"||z=="@"||z=="+"||z=="&")return;const r=a.cloneNode(!0);if(e){a.setAttribute(z1,"a"),a.removeAttribute(un);const o=a.getAttribute(bn);a.removeAttribute(bn),a.setAttribute("data-href",`siyuan://blocks/${o}`)}return r})).flat();if((t==null?void 0:t.length)>0){const b=t.map(z=>`"${z}"`).join(","),a=await f.sql(`select id,content from blocks where type='d' and content in (${b})`).then(z=>z.map(r=>{const o=document.createElement("span");return o.textContent=r.content,o.setAttribute(z1,tM),o.setAttribute(un,"d"),o.setAttribute(bn,r.id),o}));c.push(...a)}return c}class wh extends cz{constructor(t){super();U(this,"supBuilder");this.supBuilder=new Bh,this.append2FirstItem(O2("refs:",...t)),this.append2FirstItem(this.supBuilder.container)}appendSup(...t){var c;return(c=this.supBuilder)==null||c.append(...t),this}addBottomLine(){this.setAttr("custom-super-list","1")}}class Bh extends gp{constructor(e="row"){super(),this.container.classList.add("sb"),this.container.setAttribute(z1,q1.NODE_SUPER_BLOCK),this.container.setAttribute("data-sb-layout",e)}}function H2(){const n=ee.dateFormat(new Date).split(" ")[0],[e,t]=n.split("-");return`/daily card/c${e}/c${e}-${t}/c${n}`}function vh(){const n=ee.dateFormat(new Date).split(" ")[0],[e,t,c]=n.split("-");return e+t+c}function Wp(n){var t;if(!n)return{};if(((t=n==null?void 0:n.tagName)==null?void 0:t.toLocaleLowerCase())=="body")return{};const e=n.getAttribute(c1)??"";return e?{dom:n,blockID:e}:Wp(n.parentElement)}class xh{constructor(){U(this,"plugin");U(this,"settings")}blockIconEvent(e){this.plugin&&(e.menu.addItem({iconHTML:"+🗃️",accelerator:"⌥E",label:this.plugin.i18n.insertBlankSpaceCard,click:()=>{this.makeCard(e.protyle,"None")}}),e.menu.addItem({iconHTML:"+🗃️⬇️",accelerator:"⌥`",label:this.plugin.i18n.insertBlankSpaceCardHere,click:()=>{this.makeCard(e.protyle,"Here")}}),e.menu.addItem({iconHTML:"🗓️🗃️⭐",accelerator:"⌘`",label:this.plugin.i18n.send2dailyCard,click:()=>{this.makeCard(e.protyle,"None",H2())}}),e.menu.addItem({iconHTML:"🗓️🗃️",accelerator:"⌥S",label:this.plugin.i18n.send2dailyCardNoRef,click:()=>{this.makeCard(e.protyle,"None",H2(),!0)}}))}async onload(e,t){this.plugin=e,this.settings=t,this.plugin.addCommand({langKey:"insertBlankSpaceCard",hotkey:"⌥E",callback:()=>{var c;this.makeCard((c=L0.protyle)==null?void 0:c.protyle,"None")}}),this.plugin.addCommand({langKey:"insertBlankSpaceCardHere",hotkey:"⌥`",callback:()=>{var c;this.makeCard((c=L0.protyle)==null?void 0:c.protyle,"Here")}}),this.plugin.addCommand({langKey:"send2dailyCard",hotkey:"⌘`",callback:()=>{var c;this.makeCard((c=L0.protyle)==null?void 0:c.protyle,"None",H2())}}),this.plugin.addCommand({langKey:"send2dailyCardNoRef",hotkey:"⌥S",callback:()=>{var c;this.makeCard((c=L0.protyle)==null?void 0:c.protyle,"None",H2(),!0)}}),this.plugin.addCommand({langKey:"cardMark",hotkey:"⌥D",editorCallback:async c=>{const{selected:b,rangeText:a}=await L0.selectedDivs(c);if(a)c.toolbar.setInlineMark(c,"mark","range");else if(b.length>0){const z=b.map(r=>(r.querySelectorAll("span").forEach(i=>{const O=i.getAttribute(z1);O?O.includes("mark")||i.setAttribute(z1,O+" mark"):i.setAttribute(z1,"mark")}),mo(r).forEach(i=>{i.childNodes.forEach(O=>{if(O.nodeType===3){const u=document.createElement("span");u.setAttribute(z1,"mark"),u.textContent=O.textContent,O.parentElement.replaceChild(u,O)}})}),{id:r.getAttribute(c1),domStr:r.outerHTML})).filter(r=>!!r.id);(z==null?void 0:z.length)>0&&c.getInstance().transaction(f.transUpdateBlocks(z))}}}),this.plugin.eventBus.on("open-menu-content",({detail:c})=>{const b=c.menu;b.addItem({label:this.plugin.i18n.insertBlankSpaceCard,iconHTML:"+🗃️",accelerator:"⌥E",click:()=>{var r,o,i;const a=((r=c==null?void 0:c.element)==null?void 0:r.getAttribute("data-node-id"))??"",z=((i=(o=c==null?void 0:c.range)==null?void 0:o.cloneContents())==null?void 0:i.textContent)??"";a&&this.blankSpaceCard(a,z,c==null?void 0:c.range,c==null?void 0:c.protyle,"None")}}),b.addItem({label:T.原地制卡,iconHTML:"+🗃️⬇️",accelerator:"⌥`",click:()=>{var r,o,i;const a=((r=c==null?void 0:c.element)==null?void 0:r.getAttribute("data-node-id"))??"",z=((i=(o=c==null?void 0:c.range)==null?void 0:o.cloneContents())==null?void 0:i.textContent)??"";a&&this.blankSpaceCard(a,z,c==null?void 0:c.range,c==null?void 0:c.protyle,"Here")}}),b.addItem({label:this.plugin.i18n.send2dailyCard,iconHTML:"🗓️🗃️⭐",accelerator:"⌘`",click:()=>{var r,o,i;const a=((r=c==null?void 0:c.element)==null?void 0:r.getAttribute("data-node-id"))??"",z=((i=(o=c==null?void 0:c.range)==null?void 0:o.cloneContents())==null?void 0:i.textContent)??"";a&&this.blankSpaceCard(a,z,c==null?void 0:c.range,c==null?void 0:c.protyle,"None",H2())}}),b.addItem({label:this.plugin.i18n.send2dailyCardNoRef,iconHTML:"🗓️🗃️",accelerator:"⌥S",click:()=>{var r,o,i;const a=((r=c==null?void 0:c.element)==null?void 0:r.getAttribute("data-node-id"))??"",z=((i=(o=c==null?void 0:c.range)==null?void 0:o.cloneContents())==null?void 0:i.textContent)??"";a&&this.blankSpaceCard(a,z,c==null?void 0:c.range,c==null?void 0:c.protyle,"None",H2(),!0)}})})}async makeCard(e,t,c,b){var r,o;if(!e)return;const{ids:a,divs:z}=await this.cloneSelectedLineMarkdowns(e,b);if(a.length>0)await this.insertCard(e,z,t,a[a.length-1],c);else{const i=L0.lastBlockID,O=(r=document.getSelection())==null?void 0:r.getRangeAt(0),u=((o=O==null?void 0:O.cloneContents())==null?void 0:o.textContent)??"";i&&this.blankSpaceCard(i,u,O,e,t,c,b)}}async insertCard(e,t,c,b,a){return navigator.locks.request("prog-FlashBox-insertCard",{mode:"exclusive"},async z=>this.doInsertCard(e,t,c,b,a))}async doInsertCard(e,t,c,b,a){var y;const z=e.notebookId,r=(y=e.block)==null?void 0:y.rootID;if(!r)return;let{bookID:o}=await Fc(r);const i=await f.getBlockAttrs(r),O=i["custom-card-priority"],{cardID:u,domStr:l,text:R}=await this.createList(t,O),_=[];if(a){const w=await Sh(z,a);_.push(...f.transInsertBlocksAfter([l,O2().outerHTML],await f.getDocLastID(w)))}else if(c=="Here")_.push(...f.transInsertBlocksAfter([l,O2().outerHTML],b));else{let w="";if(o&&!this.settings.cardUnderPiece?w=await ae(o,"cards"):(w=await ae(r,"cards"),o=r),!w)return;const k=await To(o,z,w);_.push(...f.transInsertBlocksAfter([l,O2().outerHTML],await f.getDocLastID(k)))}if(this.settings.markOriginText&&!await L0.isDocReadonly(e,i)){const{div:w}=await ea(b);this.settings.markOriginTextBG&&(w.style.backgroundColor="var(--b3-font-background7)");const k=st(w);if(k){const S=k.appendChild(document.createElement("span"));Rn(S,u," & "),_.push(...f.transUpdateBlocks([{id:b,domStr:w.outerHTML}]))}}_.push(f.transAddRiffCards([u])),_.push(f.transDoUpdateUpdated(u)),await f.transactions(_).then(()=>{c!=="Here"&&H1(this.plugin,u,Be.get(),null,null,b),f.addRiffCards([u]),f.pushMsg("⚡🗃"+R,2e3)})}async createList(e,t){let c="",b="",a="";const z=await Nh(e);for(const i of e)c||(c=i.getAttribute(It)),b||(b=i.getAttribute(Et)),a||(a=i.getAttribute(e2)),i.removeAttribute(Z1),i.removeAttribute(e2),i.removeAttribute(Ze),i.removeAttribute(Ae),i.removeAttribute(Yi),i.removeAttribute(Qn),i.removeAttribute("custom-prog-words");const r=new wh(z);if(e.forEach(i=>{i.removeAttribute(It),i.removeAttribute(Et),i.style.background="",i.querySelectorAll(`span[${z1}="a"]`).forEach(O=>{var l;const u=(l=O.textContent)==null?void 0:l.trim();(u=="&"||u=="+")&&O.parentElement.removeChild(O)}),r.appendSup(i)}),this.settings.cardAppendTime){c?r.appendSup(O2(`【${c}】`)):b&&r.appendSup(O2(`【${b}】`));const i=ee.dateFormat(ee.now());r.appendSup(O2(`【${i}】`))}Mo.get()&&r.addBottomLine();const o=r.build();return t&&o.setAttribute(Ji,t),c&&o.setAttribute(It,c),b&&o.setAttribute(Et,b),{cardID:r.id,div:o,domStr:o.outerHTML,text:o.textContent}}async cloneSelectedLineMarkdowns(e,t){var i;const c=(i=e==null?void 0:e.element)==null?void 0:i.querySelectorAll(`.${cM}`),b=[];let a=!t,z=!0;const r=[],o=await L0.isDocReadonly(e);for(const O of c){const{id:u,div:l,setTheRef:R,setPath:_}=await this.cloneDiv(O,a,z);this.settings.markOriginText&&!o&&this.settings.markOriginTextBG&&(O.style.backgroundColor="var(--b3-font-background7)"),R&&(a=!1),_&&(z=!1),r.push(u),b.push(l)}return this.settings.markOriginText&&!o&&this.settings.markOriginTextBG&&Br(r),{divs:b,ids:r}}async cloneDiv(e,t,c=!0){return e=e.cloneNode(!0),go(e,t,t,this.settings.flashcardMultipleLnks,c,this.settings.flashcardUseLink)}async blankSpaceCard(e,t,c,b,a,z,r){let o;const{dom:i}=Wp(c.endContainer.parentElement);if(!i)return;const O=await L0.isDocReadonly(b);if(t){O&&i.querySelectorAll(`div[${$1}="false"]`).forEach(l=>l.setAttribute($1,"true")),b.toolbar.setInlineMark(b,"mark","range");const{div:u}=await this.cloneDiv(i,!r);b.toolbar.setInlineMark(b,"mark","range"),O&&i.querySelectorAll(`div[${$1}="true"]`).forEach(l=>l.setAttribute($1,"false")),this.settings.markOriginTextBG&&!O&&(b.toolbar.setInlineMark(b,"text","range",{type:"backgroundColor",color:"var(--b3-font-background9)"}),u.querySelectorAll('[data-type~="text"]').forEach(l=>{l.style.backgroundColor=="var(--b3-font-background9)"&&(l.style.backgroundColor="")}),u.querySelectorAll('[data-type~="prog-marked"]').forEach(l=>{const R=l.getAttribute("data-type").replace("prog-marked","");l.setAttribute("data-type",R),l.style.backgroundColor=""})),o=u}else{const{id:u,div:l}=await this.cloneDiv(i,!r);o=l,this.settings.markOriginText&&!O&&this.settings.markOriginTextBG&&Br([u])}await this.insertCard(b,[o],a,e,z)}}const wr=new xh;async function Sh(n,e){const t=vh(),c={};return c[`custom-dailycard-${t}`]=t,await M2.createDocWithMdIfNotExists(5e3,n,e,"",c)}async function Br(n){const e={style:"background-color: var(--b3-font-background7);"};return f.batchSetBlockAttrs(n.map(t=>({id:t,attrs:e})))}class Th{constructor(){U(this,"plugin");U(this,"settings")}blockIconEvent(e){if(!this.plugin)return;const t=e.protyle,{isPiece:c}=w2(t);c&&(e.menu.addItem({iconHTML:"🚚⬆️",label:T.移动到上一分片内,click:()=>{this.move(t,-1)}}),e.menu.addItem({iconHTML:"🚚⬇️",label:T.移动到下一分片内,click:()=>{this.move(t,1)}}))}async onload(e,t){this.plugin=e,this.settings=t,this.plugin.eventBus.on("open-menu-content",({detail:c})=>{const b=c.protyle,{isPiece:a}=w2(b);if(a){const z=c.menu;z.addItem({label:T.移动到上一分片内,iconHTML:"🚚⬆️",click:()=>{this.move(b,-1)}}),z.addItem({label:T.移动到下一分片内,iconHTML:"🚚⬇️",click:()=>{this.move(b,1)}})}})}async move(e,t){if(t==0)return;const{ids:c}=await L0.selectedDivs(e);if(!c||c.length==0)return;const{bookID:b,pieceNum:a}=await qp(c[0]);if(q2(a)&&b){const z=a+t;if(z>=0){const r=await f.sqlOne(`select id from blocks where type='d' and ial like "%${vc(b,z)}%"`);if(r!=null&&r.id)if(t<0){const o=await f.getTailChildBlocks(r.id,1);await f.moveBlocksAfter(c,o[0].id)}else await f.moveBlocksAsChild(c,r.id)}}}}const vr=new Th;class Xh{constructor(){U(this,"plugin");U(this,"settings");U(this,"lute")}async onload(e,t){this.plugin=e,this.settings=t,this.lute=$a(),this.plugin.addCommand({langKey:"collect",hotkey:"⌥⇧Z",callback:()=>{var c;this.copyBlocks((c=L0.protyle)==null?void 0:c.protyle)}}),this.plugin.eventBus.on("open-menu-content",({detail:c})=>{c.menu.addItem({iconHTML:"💼",label:this.plugin.i18n.collect,accelerator:"",click:async()=>{var a;this.copyBlocks((a=L0.protyle)==null?void 0:a.protyle)}})})}async copyBlocks(e){const{selected:t}=await L0.selectedDivs(e);if(!((t==null?void 0:t.length)>0))return;let c;if(!this.settings.summary2dailynote){const{bookID:b}=await qp(Wo(t[0]));if(b&&(c=await ko(b),!c)){const a=await ae(b,"summary");a&&(c=await Mf(b,L0.boxID,a))}}if(c||(c=(await f.createDailyNote(L0.boxID)).id),c){const b=t.map(z=>qo(z)),a=b[b.length-1].newID;await f.appendBlocks(b.map(z=>z.div.outerHTML),c),await H1(this.plugin,a,Be.get())}}}const kh=new Xh;function xr(n){return{ial:bt(n.ial),id:n.id,markdown:n.markdown,content:n.content}}class Ch{constructor(){U(this,"plugin");U(this,"settings")}async onload(e,t){this.plugin=e,this.settings=t,this.plugin.addCommand({langKey:"extractAllNotes",hotkey:"⌘F4",editorCallback:async c=>{const{isPiece:b,markKey:a}=w2(c);b&&await this.extractAllNotes(c.notebookId,a)}}),this.plugin.addCommand({langKey:"extractNotes",hotkey:"⌘F5",editorCallback:async c=>{var z;const{isPiece:b,markKey:a}=w2(c);b&&await this.extractNotes((z=c.block)==null?void 0:z.rootID,c.notebookId,a)}}),this.plugin.addCommand({langKey:"2024-08-09 15:10:45 extract book",langText:T.合并所有分片到新文件,hotkey:"",editorCallback:async c=>{var z;const{isPiece:b,markKey:a}=w2(c);b&&await this.extractAsBook(c.notebookId,(z=c.block)==null?void 0:z.rootID,c.notebookId,a)}}),this.plugin.addCommand({langKey:"compareNotes",hotkey:"⌘F6",editorCallback:async c=>{var z;const{isKeyDoc:b,keyDocAttr:a}=ir(c);b&&await this.compareNotes((z=c.block)==null?void 0:z.rootID,c.notebookId,a)}}),this.plugin.eventBus.on("open-menu-content",({detail:c})=>{const b=c.protyle,{isPiece:a,markKey:z}=w2(b);if(a){const r=c.menu;r.addItem({label:this.plugin.i18n.extractAllNotes,icon:"iconCopy",accelerator:"⌘F4",click:async()=>{await this.extractAllNotes(b.notebookId,z)}}),r.addItem({label:this.plugin.i18n.extractNotes,icon:"iconCopy",accelerator:"⌘F5",click:async()=>{var o;await this.extractNotes((o=b.block)==null?void 0:o.rootID,b.notebookId,z)}}),r.addItem({label:T.合并所有分片到新文件,icon:"iconCopy",accelerator:"",click:async()=>{var o;await this.extractAsBook(b.notebookId,(o=b.block)==null?void 0:o.rootID,b.notebookId,z)}})}else{const{isKeyDoc:r,keyDocAttr:o}=ir(b);r&&c.menu.addItem({label:this.plugin.i18n.compareNotes,icon:"iconEye",accelerator:"⌘F6",click:async()=>{var O;await this.compareNotes((O=b.block)==null?void 0:O.rootID,b.notebookId,o)}})}})}async extractAllNotes(e,t){f.pushMsg("extract all notes");const c=t.split(",")[0],b=await Sr(c),z=(await f.getRows(b,"markdown",!0,[`ial not like "%${Ae}%"`])).map(i=>{var O;if((O=i.markdown)!=null&&O.trim())return`${i.markdown} ${ze(i.id,"*")}
+{: id="${E1()}"}`}).filter(i=>!!i),r=c.split("#")[1];let o=await Co(r);if(!o){const i=await ae(r,"collection");i&&(o=await pf(r,e,i))}o&&(await f.clearAll(o),await f.insertBlockAsChildOf(`{{{row
+${z.join(`
`)}
-}}}`,M),$1(this.plugin,M,ve.get()))}async compareNotes(e,t,c){var z;if(!e||!t||!c)return;A.pushMsg("compare notes");const b=(z=c.split("#").pop())==null?void 0:z.split(",");if(b.length==2){const a=Number(b[1]);if(!g2(a))return;const r=await XM(b[0],a);if(!r)return;let M=await EM(b[0],a);if(!M){const _=await ae(r,"compare");_&&(M=await Of(b[0],a,t,_))}if(!M)return;const i=A.clearAll(M),O=[],u=A.getChildBlocks(e).then(_=>A.getRows(_.map(y=>y.id),"ial,markdown,content",!0,["content is not null",'content != ""'])).then(_=>_.map(y=>({ial:zt(y.ial),id:y.id,markdown:y.markdown,content:y.content})).reduce(({lastRef:y,all:w},k)=>{w.push(k);const S=k.ial["custom-progref"];return S?y=S:y&&(k.ial["custom-progref"]=y),{lastRef:y,all:w}},{lastRef:"",all:[]}).all.filter(y=>!y.ial["custom-prog-key-note"]).reduce((y,w)=>{const k=w.ial["custom-progref"];return y.has(k)||y.set(k,[]),y.get(k).push(w),y},new Map)),{ids:l,m:R}=await A.getChildBlocks(r).then(_=>A.getRows(_.map(y=>y.id),"ial,markdown",!0,[`ial like "%${fe}%"`])).then(_=>_.map(y=>({ial:zt(y.ial),id:y.id,markdown:y.markdown})).reduce((y,w)=>{const k=w.ial["custom-progref"];return y.ids.push(k),y.m.has(k)||y.m.set(k,[]),y.m.get(k).push(w),y},{ids:[],m:new Map}));for(const _ of[...new Set(l)]){for(const w of R.get(_)??[])delete w.ial.id,delete w.ial.updated,w.ial["custom-prog-key-note"]="1",O.push(`${w.markdown}
-${pn(w.ial)}`);let y=!1;for(const w of(await u).get(_)??[])delete w.ial.id,delete w.ial.updated,y=!0,O.push(`((${w.id} '${w.content}'))
-${pn(w.ial)}`);y&&O.push("---")}await i,await A.insertBlockAsChildOf(O.join(`
-`),M),A.pushMsg("compare notes finished"),$1(this.plugin,M,ve.get())}}async extractAsBook(e,t,c,b){var u;if(!t||!c||!b)return;A.pushMsg("extract pieces as a new book");const z=(u=b.split("#").pop())==null?void 0:u.split(",");if(z.length!==2)return;const a=z[0];if(!a)return;let r=await jM(a);if(!r){const l=await ae(a,"merged");l&&(r=await of(a,e,l))}if(!r)return;const M=b.split(",")[0],i=await Sr(M),O=await A.getRows(i,"markdown,ial",!0,[`ial not like "%${Zn}%"`]).then(l=>l.filter(R=>!R.ial.includes(`${fe}="2"`)));await A.clearAll(r),await A.insertBlockAsChildOf(`{{{row
+}}}`,o),H1(this.plugin,o,Be.get()))}async compareNotes(e,t,c){var a;if(!e||!t||!c)return;f.pushMsg("compare notes");const b=(a=c.split("#").pop())==null?void 0:a.split(",");if(b.length==2){const z=Number(b[1]);if(!q2(z))return;const r=await Xo(b[0],z);if(!r)return;let o=await Eo(b[0],z);if(!o){const _=await ae(r,"compare");_&&(o=await uf(b[0],z,t,_))}if(!o)return;const i=f.clearAll(o),O=[],u=f.getChildBlocks(e).then(_=>f.getRows(_.map(y=>y.id),"ial,markdown,content",!0,["content is not null",'content != ""'])).then(_=>_.map(y=>({ial:bt(y.ial),id:y.id,markdown:y.markdown,content:y.content})).reduce(({lastRef:y,all:w},k)=>{w.push(k);const S=k.ial["custom-progref"];return S?y=S:y&&(k.ial["custom-progref"]=y),{lastRef:y,all:w}},{lastRef:"",all:[]}).all.filter(y=>!y.ial["custom-prog-key-note"]).reduce((y,w)=>{const k=w.ial["custom-progref"];return y.has(k)||y.set(k,[]),y.get(k).push(w),y},new Map)),{ids:l,m:R}=await f.getChildBlocks(r).then(_=>f.getRows(_.map(y=>y.id),"ial,markdown",!0,[`ial like "%${Ae}%"`])).then(_=>_.map(y=>({ial:bt(y.ial),id:y.id,markdown:y.markdown})).reduce((y,w)=>{const k=w.ial["custom-progref"];return y.ids.push(k),y.m.has(k)||y.m.set(k,[]),y.m.get(k).push(w),y},{ids:[],m:new Map}));for(const _ of[...new Set(l)]){for(const w of R.get(_)??[])delete w.ial.id,delete w.ial.updated,w.ial["custom-prog-key-note"]="1",O.push(`${w.markdown}
+${on(w.ial)}`);let y=!1;for(const w of(await u).get(_)??[])delete w.ial.id,delete w.ial.updated,y=!0,O.push(`((${w.id} '${w.content}'))
+${on(w.ial)}`);y&&O.push("---")}await i,await f.insertBlockAsChildOf(O.join(`
+`),o),f.pushMsg("compare notes finished"),H1(this.plugin,o,Be.get())}}async extractAsBook(e,t,c,b){var u;if(!t||!c||!b)return;f.pushMsg("extract pieces as a new book");const a=(u=b.split("#").pop())==null?void 0:u.split(",");if(a.length!==2)return;const z=a[0];if(!z)return;let r=await jo(z);if(!r){const l=await ae(z,"merged");l&&(r=await of(z,e,l))}if(!r)return;const o=b.split(",")[0],i=await Sr(o),O=await f.getRows(i,"markdown,ial",!0,[`ial not like "%${Qn}%"`]).then(l=>l.filter(R=>!R.ial.includes(`${Ae}="2"`)));await f.clearAll(r),await f.insertBlockAsChildOf(`{{{row
${O.map(l=>l.markdown).join(`
`)}
-}}}`,r),$1(this.plugin,r,ve.get())}async extractNotes(e,t,c){var l,R;if(!e||!t||!c)return;A.pushMsg("extract notes");const b=(l=c.split("#").pop())==null?void 0:l.split(",");if(b.length!==2)return;const z=Number(b[1]);if(!g2(z))return;let a=await IM(b[0],z);if(!a){const _=await ae(e,"keys");_&&(a=await sf(b[0],z,t,_))}if(!a)return;const r=A.getChildBlocks(a).then(_=>_.map(y=>y.id)).then(_=>A.getRows(_,"content,ial",!0)).then(_=>_.map(xr)).then(_=>{let y;const w=new Map;for(const k of _){const S=k.ial["custom-paragraph-index"];if(S&&(y=S),y&&!S){const C=w.get(y)??[];C.push(k),w.set(y,C)}}return w}),{contents:M,noteMap:i}=await(async()=>{const y=(await A.getChildBlocks(e)).map(S=>S.id);return{contents:(await A.getRows(y,"content,ial",!0,[`ial not like "%${fe}%"`,`ial not like "%${g1}%"`,"content IS NOT NULL","LENGTH(content) > 0"])).map(xr),noteMap:await r}})(),O=[];let u;for(const{id:_,ial:y,content:w}of M){if(!w)continue;delete y.id,delete y.updated;const k=y["custom-paragraph-index"];k!=u&&(u!=null&&O.push(Pn()),u=k),y["custom-prog-key-note"]="1",O.push(`((${_} '${w}'))
-${pn(y)}`),(R=i.get(k))==null||R.forEach(S=>{O.push(S.content)})}await A.clearAll(a),await A.insertBlockAsChildOf(O.join(`
-`),a),$1(this.plugin,a,ve.get())}}const Ch=new kh;async function Sr(n){const t=(await A.sqlAttr(`select root_id,value from attributes where name="${g1}" and value like "${n}%" limit 100000000`)).map(b=>{const z=b.value.split(",").pop();if(z)return{docID:b.root_id,idx:Number(z)}}).filter(b=>b!=null).sort((b,z)=>b.idx-z.idx).map(b=>b.docID);return(await Promise.all(t.map(b=>A.getChildBlocks(b)))).flat().filter(b=>b.type!="s"&&b.type!="tb").map(b=>b.id)}async function jh(n,e,t){const c=n[n.length-1],b=Ot(c);if(b){const z=b.appendChild(document.createElement("span"));return _n(z,e,"+"),A.safeUpdateBlock(c.getAttribute(c1),t.BlockDOM2Md(c.outerHTML))}}async function Ih(n){n.style.backgroundColor="var(--b3-font-background11)";const e={style:"background-color: var(--b3-font-background11);"};return A.setBlockAttrs(n.getAttribute(c1),e)}function Tr(n,e,t,c){return`select root_id from attributes
+}}}`,r),H1(this.plugin,r,Be.get())}async extractNotes(e,t,c){var l,R;if(!e||!t||!c)return;f.pushMsg("extract notes");const b=(l=c.split("#").pop())==null?void 0:l.split(",");if(b.length!==2)return;const a=Number(b[1]);if(!q2(a))return;let z=await Io(b[0],a);if(!z){const _=await ae(e,"keys");_&&(z=await Of(b[0],a,t,_))}if(!z)return;const r=f.getChildBlocks(z).then(_=>_.map(y=>y.id)).then(_=>f.getRows(_,"content,ial",!0)).then(_=>_.map(xr)).then(_=>{let y;const w=new Map;for(const k of _){const S=k.ial["custom-paragraph-index"];if(S&&(y=S),y&&!S){const j=w.get(y)??[];j.push(k),w.set(y,j)}}return w}),{contents:o,noteMap:i}=await(async()=>{const y=(await f.getChildBlocks(e)).map(S=>S.id);return{contents:(await f.getRows(y,"content,ial",!0,[`ial not like "%${Ae}%"`,`ial not like "%${g1}%"`,"content IS NOT NULL","LENGTH(content) > 0"])).map(xr),noteMap:await r}})(),O=[];let u;for(const{id:_,ial:y,content:w}of o){if(!w)continue;delete y.id,delete y.updated;const k=y["custom-paragraph-index"];k!=u&&(u!=null&&O.push(En()),u=k),y["custom-prog-key-note"]="1",O.push(`((${_} '${w}'))
+${on(y)}`),(R=i.get(k))==null||R.forEach(S=>{O.push(S.content)})}await f.clearAll(z),await f.insertBlockAsChildOf(O.join(`
+`),z),H1(this.plugin,z,Be.get())}}const jh=new Ch;async function Sr(n){const t=(await f.sqlAttr(`select root_id,value from attributes where name="${g1}" and value like "${n}%" limit 100000000`)).map(b=>{const a=b.value.split(",").pop();if(a)return{docID:b.root_id,idx:Number(a)}}).filter(b=>b!=null).sort((b,a)=>b.idx-a.idx).map(b=>b.docID);return(await Promise.all(t.map(b=>f.getChildBlocks(b)))).flat().filter(b=>b.type!="s"&&b.type!="tb").map(b=>b.id)}async function Ih(n,e,t){const c=n[n.length-1],b=st(c);if(b){const a=b.appendChild(document.createElement("span"));return Rn(a,e,"+"),f.safeUpdateBlock(c.getAttribute(c1),t.BlockDOM2Md(c.outerHTML))}}async function Eh(n){n.style.backgroundColor="var(--b3-font-background11)";const e={style:"background-color: var(--b3-font-background11);"};return f.setBlockAttrs(n.getAttribute(c1),e)}function Tr(n,e,t,c){return`select root_id from attributes
where name="${e}"
and value like "${n}#%"
- and ${t} order by value ${c} limit 1`}class Eh{constructor(){U(this,"protyle");U(this,"element");U(this,"selected",[]);U(this,"docID");U(this,"docName");U(this,"boxID");U(this,"anchorID");U(this,"plugin");U(this,"ctime");U(this,"singleCard");U(this,"bookID");U(this,"allText");U(this,"otab");U(this,"attrs");U(this,"settings")}async init(){this.allText=dM(this.selected),this.ctime=this.element.getAttribute(R2);const e=this.element.getAttribute(Hi);e&&(this.anchorID=e);let{bookID:t}=await Hc(this.docID);t||(t=this.docID),this.bookID=t,this.attrs=await A.getBlockAttrs(this.bookID),this.singleCard=this.attrs["custom-book-single-card"]==="1"}async getDigest(e,t,c,b){var a,r,M;if(e){const i=await A.sqlAttr(Tr(this.bookID,$i,`value ${c} "${e}"`,b));if(i.length>0)return(a=i[0])==null?void 0:a.root_id}if(t){const i=await A.sqlAttr(Tr(this.bookID,R2,`value ${c} "${t}"`,b));if(i.length>0)return(r=i[0])==null?void 0:r.root_id}const z=await A.sqlAttr(`select root_id from attributes where name="${R2}"
- and value like "${this.bookID}#%" order by value desc limit 1`);if(z.length>0)return(M=z[0])==null?void 0:M.root_id}async toggleMultiCardMode(){const e={};this.singleCard?(e["custom-book-single-card"]="2",A.pushMsg(T.每个摘抄都加入闪卡)):(e["custom-book-single-card"]="1",A.pushMsg(T.只有一个摘抄加入闪卡)),await A.setBlockAttrs(this.bookID,e)}async setDigestCard(e){if(this.singleCard){const t=await A.sqlOne(`SELECT a.id FROM blocks a
+ and ${t} order by value ${c} limit 1`}class Ph{constructor(){U(this,"protyle");U(this,"element");U(this,"selected",[]);U(this,"docID");U(this,"docName");U(this,"boxID");U(this,"anchorID");U(this,"plugin");U(this,"ctime");U(this,"singleCard");U(this,"bookID");U(this,"allText");U(this,"otab");U(this,"attrs");U(this,"settings")}async init(){this.allText=uo(this.selected),this.ctime=this.element.getAttribute(m2);const e=this.element.getAttribute(Hi);e&&(this.anchorID=e);let{bookID:t}=await Fc(this.docID);t||(t=this.docID),this.bookID=t,this.attrs=await f.getBlockAttrs(this.bookID),this.singleCard=this.attrs["custom-book-single-card"]==="1"}async getDigest(e,t,c,b){var z,r,o;if(e){const i=await f.sqlAttr(Tr(this.bookID,$i,`value ${c} "${e}"`,b));if(i.length>0)return(z=i[0])==null?void 0:z.root_id}if(t){const i=await f.sqlAttr(Tr(this.bookID,m2,`value ${c} "${t}"`,b));if(i.length>0)return(r=i[0])==null?void 0:r.root_id}const a=await f.sqlAttr(`select root_id from attributes where name="${m2}"
+ and value like "${this.bookID}#%" order by value desc limit 1`);if(a.length>0)return(o=a[0])==null?void 0:o.root_id}async toggleMultiCardMode(){const e={};this.singleCard?(e["custom-book-single-card"]="2",f.pushMsg(T.每个摘抄都加入闪卡)):(e["custom-book-single-card"]="1",f.pushMsg(T.只有一个摘抄加入闪卡)),await f.setBlockAttrs(this.bookID,e)}async setDigestCard(e){if(this.singleCard){const t=await f.sqlOne(`SELECT a.id FROM blocks a
INNER JOIN (
SELECT hpath,content
FROM blocks
WHERE type='d'
AND id ='${this.bookID}'
) b ON a.hpath = b.hpath || '/digest-' || b.content
- WHERE a.type='d' limit 1`);if(t!=null&&t.id){const c=await A.getTreeRiffCardsAll(t.id);await A.removeRiffCards(c.map(b=>b.id))}}fM(e)}async finishDigest(){const e=this.docID;await A.removeRiffCards([e]),await A.setBlockAttrs(e,{"custom-pdigest-ctime":"🔨#"+this.ctime}),await A.renameDocByID(e,"🔨"+this.docName);const t=await A.sqlAttr(`select block_id from attributes where
- name="${R2}"
+ WHERE a.type='d' limit 1`);if(t!=null&&t.id){const c=await f.getTreeRiffCardsAll(t.id);await f.removeRiffCards(c.map(b=>b.id))}}fo(e)}async finishDigest(){const e=this.docID;await f.removeRiffCards([e]),await f.setBlockAttrs(e,{"custom-pdigest-ctime":"🔨#"+this.ctime}),await f.renameDocByID(e,"🔨"+this.docName);const t=await f.sqlAttr(`select block_id from attributes where
+ name="${m2}"
and value like "${this.bookID}#%"
and value<"${this.ctime}"
and block_id!="${e}"
- order by value desc limit 1`);if(await this.tryOpen(t))return;const c=await A.sqlAttr(`select block_id from attributes where
- name="${R2}"
+ order by value desc limit 1`);if(await this.tryOpen(t))return;const c=await f.sqlAttr(`select block_id from attributes where
+ name="${m2}"
and value like "${this.bookID}#%"
and block_id!="${e}"
- order by value desc limit 1`);await this.tryOpen(c)||await this.otab.open(this.anchorID)}async cleanDigest(){const e=await A.sqlAttr(`select block_id from attributes where name="${R2}" and value like "🔨#${this.bookID}#%" limit 1000000`);for(const t of e)await A.removeDocByID(t.block_id)}async gotoDigest(e,t){const c=await A.getBlockAttrs(this.docID),b=c["custom-pdigest-index"],z=c["custom-pdigest-ctime"],a=await this.getDigest(b,z,e,t);await this.otab.open(a)}async getDigestLnk(e=!0){const t=A.getChildBlocks(this.bookID).then(async l=>{const R=await A.getRows(l.filter(y=>y.type=="h").map(y=>y.id),"markdown",!0),_=new Map(R.map(y=>[y.id,y.markdown]));return l.map(y=>({id:y.id,type:y.type,content:_.get(y.id)}))}),c=ae(this.bookID,"trace").then(l=>pf(this.bookID,this.boxID,l)).then(async l=>(await A.clearAll(l),l)),b=await A.sql(`select ial,content,id from blocks where id = "${this.bookID}" or id in
- (select block_id from attributes where name="${R2}" and value like "${this.bookID}#%" limit 1000000)`);if(b.length<=1)return;const[z,a]=b.map(l=>{const R=zt(l.ial);return R.title=l.content,R.id=l.id,R}).reduce(([l,R],_)=>(l.set(_.id,_),R.add(_["custom-pdigest-parent-id"]),[l,R]),[new Map,new Set]),r=z.get(this.bookID).title,i=[...z.keys()].reduce((l,R)=>(!a.has(R)&&R!=this.bookID&&l.push(z.get(R)),l),[]).sort((l,R)=>-l["custom-pdigest-ctime"].localeCompare(R["custom-pdigest-ctime"])).map(l=>{const R=[];R.push(l);do{if(l["custom-pdigest-parent-id"]==this.bookID)break;l=z.get(l["custom-pdigest-parent-id"]),l&&R.push(l)}while(l);return R}).map(l=>{const R=[];for(const y of l)R.push(re(y.id,y.title));return R.push(re(this.bookID,r)),{lnk:`${R.join(" -> ")}
-{: id="${P1()}"}
-{: id="${P1()}"}`,id:l[0]["custom-pdigest-last-id"]}}),O=(await t).map(l=>{const R=[];return l.type=="h"&&R.push(`${l.content}${re(l.id," . ")}`),R.push(...i.filter(_=>_.id==l.id).map(_=>_.lnk)),R}).flat(),u=await c;await A.insertBlockAsChildOf(`{{{row
+ order by value desc limit 1`);await this.tryOpen(c)||await this.otab.open(this.anchorID)}async cleanDigest(){const e=await f.sqlAttr(`select block_id from attributes where name="${m2}" and value like "🔨#${this.bookID}#%" limit 1000000`);for(const t of e)await f.removeDocByID(t.block_id)}async gotoDigest(e,t){const c=await f.getBlockAttrs(this.docID),b=c["custom-pdigest-index"],a=c["custom-pdigest-ctime"],z=await this.getDigest(b,a,e,t);await this.otab.open(z)}async getDigestLnk(e=!0){const t=f.getChildBlocks(this.bookID).then(async l=>{const R=await f.getRows(l.filter(y=>y.type=="h").map(y=>y.id),"markdown",!0),_=new Map(R.map(y=>[y.id,y.markdown]));return l.map(y=>({id:y.id,type:y.type,content:_.get(y.id)}))}),c=ae(this.bookID,"trace").then(l=>sf(this.bookID,this.boxID,l)).then(async l=>(await f.clearAll(l),l)),b=await f.sql(`select ial,content,id from blocks where id = "${this.bookID}" or id in
+ (select block_id from attributes where name="${m2}" and value like "${this.bookID}#%" limit 1000000)`);if(b.length<=1)return;const[a,z]=b.map(l=>{const R=bt(l.ial);return R.title=l.content,R.id=l.id,R}).reduce(([l,R],_)=>(l.set(_.id,_),R.add(_["custom-pdigest-parent-id"]),[l,R]),[new Map,new Set]),r=a.get(this.bookID).title,i=[...a.keys()].reduce((l,R)=>(!z.has(R)&&R!=this.bookID&&l.push(a.get(R)),l),[]).sort((l,R)=>-l["custom-pdigest-ctime"].localeCompare(R["custom-pdigest-ctime"])).map(l=>{const R=[];R.push(l);do{if(l["custom-pdigest-parent-id"]==this.bookID)break;l=a.get(l["custom-pdigest-parent-id"]),l&&R.push(l)}while(l);return R}).map(l=>{const R=[];for(const y of l)R.push(ze(y.id,y.title));return R.push(ze(this.bookID,r)),{lnk:`${R.join(" -> ")}
+{: id="${E1()}"}
+{: id="${E1()}"}`,id:l[0]["custom-pdigest-last-id"]}}),O=(await t).map(l=>{const R=[];return l.type=="h"&&R.push(`${l.content}${ze(l.id," . ")}`),R.push(...i.filter(_=>_.id==l.id).map(_=>_.lnk)),R}).flat(),u=await c;await f.insertBlockAsChildOf(`{{{row
${O.join(`
`)}
-}}}`,u),e&&await this.otab.open(u)}async newDigestDoc(e,t){const c=await ae(this.bookID,"digest"),b={},z=new Date().getTime();return b["custom-pdigest-index"]=`${this.bookID}#${e.padStart(10,"0")}`,b["custom-pdigest-parent-id"]=this.docID,b["custom-pdigest-last-id"]=this.anchorID,b["custom-pdigest-ctime"]=`${this.bookID}#${z}`,b["custom-card-priority"]="60",b["custom-off-tomatobacklink"]="1",b["custom-progmark"]=`${k1}#${this.bookID},${z}`,await A.createDocWithMd(this.boxID,`${c}/[${e}]${this.allText.slice(0,10)}`,t,"",b)}async digest(e=!1){const{idx:t,md:c}=await az(this.settings,this.selected,this.protyle,e,!0,!1,this.attrs);if(c.length==0)return;const b=await this.newDigestDoc(t,c.join(`
-`));await this.otab.open(b,ve.get()),await this.setDigestCard(b),D1.settings.markOriginText&&!await L0.isDocReadonly(this.protyle,this.attrs)&&jh(this.selected,b,D1.lute),setTimeout(()=>{this.getDigestLnk(!1)},4e3)}async tryOpen(e){return e.length>0?(await A.addRiffCards([e[0].block_id]),await this.otab.open(e[0].block_id),!0):!1}}async function az(n,e,t,c,b=!0,z=!1,a){const r=[];if(e==null||e.length==0)return{idx:"0",md:r};let M,i=0;for(const O of e){let u=O.getAttribute(t2);u||(u=O.getAttribute(Qt));let l=O.getAttribute(ee);l||(l=O.getAttribute(c1)),M||(M=u);const R=O.cloneNode(!0);D1.settings.markOriginTextBG&&!await L0.isDocReadonly(t,a)&&Ih(O),await gM(R,!D1.settings.digestNoBacktraceLink,!D1.settings.digestNoBacktraceLink,n.flashcardMultipleLnks,!0,n.flashcardUseLink),R.setAttribute(ee,l),R.setAttribute(t2,u),R.setAttribute(n2,String(i)),R.setAttribute(fe,"1"),R.style.backgroundColor="";const _=D1.lute.BlockDOM2Md(R.outerHTML).trim();if(!c||R.getAttribute(a1)===q1.NODE_LIST||rc(_))r.push(_);else{const w=_.trim().split(`
-`).pop();let S=[RM(R,`
-`)];for(const C of`
-。!?;:`)S=Be(S,C);S=Be(S,"……"),S=Be(S,"! "),S=Be(S,"? "),S=Be(S,"; "),S.map(C=>JA(C,"","").trim()).filter(C=>!!C).filter(C=>C!="@").filter(C=>C!="*").filter(C=>C!="@*").filter(C=>C!="*@").forEach(C=>{b?r.push(`${C}${re(l," * ",D1.settings.digestNoBacktraceLink)}
-${w}`):z?r.push(`* [ ] ${C}
-${w}`):r.push(`${C}
-${w}`)})}i++}return M||(M="0"),{idx:M,md:r}}const rz="RFC3986",oz={RFC1738:n=>String(n).replace(/%20/g,"+"),RFC3986:n=>String(n)},Ph="RFC1738",Dh=Array.isArray,_e=(()=>{const n=[];for(let e=0;e<256;++e)n.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return n})(),Sb=1024,Fh=(n,e,t,c,b)=>{if(n.length===0)return n;let z=n;if(typeof n=="symbol"?z=Symbol.prototype.toString.call(n):typeof n!="string"&&(z=String(n)),t==="iso-8859-1")return escape(z).replace(/%u[0-9a-f]{4}/gi,function(r){return"%26%23"+parseInt(r.slice(2),16)+"%3B"});let a="";for(let r=0;r