4 lines
39 KiB
JavaScript

var ce=Object.defineProperty;var Ae=Object.getOwnPropertyDescriptor;var Ie=Object.getOwnPropertyNames;var Fe=Object.prototype.hasOwnProperty;var Ve=(i,r)=>{for(var e in r)ce(i,e,{get:r[e],enumerable:!0})},De=(i,r,e,t)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Ie(r))!Fe.call(i,o)&&o!==e&&ce(i,o,{get:()=>r[o],enumerable:!(t=Ae(r,o))||t.enumerable});return i};var Ne=i=>De(ce({},"__esModule",{value:!0}),i);var je={};Ve(je,{default:()=>se,leafName:()=>v,splitName:()=>ne});module.exports=Ne(je);var E=require("obsidian");var L=typeof queueMicrotask=="function"?queueMicrotask:(i=>r=>i.then(r))(Promise.resolve());function pe(i){return i&&typeof i=="object"?JSON.parse(JSON.stringify(i)):i}function T(i,r,e){let t=i.classList.contains(r);return e=e!=null?e:!t,e!==t&&(e?i.classList.add(r):i.classList.remove(r)),e}var h;(i=>Object.assign(i,require("obsidian")))(h||(h={}));var le="use.me",ue="use.factory",z,j,fe=function(){return Object.defineProperties(i(),{this:{get(){if(z)return z;throw new TypeError("No current context")}},me:{value:le},factory:{value:ue}});function i(o){let a=new Map;a.prev=o;let n=Object.assign(o?c=>{let p=a.get(c);if(!p){for(let y=a.prev;y;y=y.prev)if(p=y.get(c)){p=Object.assign(Object.assign({},p),{s:p.s||1});break}p=p||{s:2,v:e},a.set(c,p)}let f,m,g;for(;;)switch(p.s){case 0:return z===n&&j&&j.push(c),p.v;case 1:if(f=p.d,!f||s(()=>f.k.every(y=>n(y)===f.c(y)))){p.s=0;break}p.v=f.f;case 2:p.s=4;try{r(a,c,0,s(m=p.v,c,g=[])),g.length&&(p.d={c:n,f:m,k:g});break}catch(y){p.s=3,p.v=y,p.d=null}case 3:throw p.v;case 4:throw new Error(`Factory ${String(p.v)} didn't resolve ${String(c)}`)}}:c=>fe.this(c),{def(c,p){return r(a,c,2,p),n},set(c,p){return r(a,c,1,p),n},fork(c){let p=i(a);return c!=null?p(c):p}});return o?n.use=n:n;function s(c,p,f){let m=z,g=j;try{return z=n,j=f,c(p)}finally{z=m,j=g}}}function r(o,a,n,s){if(o.has(a)){let c=o.get(a);if(!c.s)throw new Error(`Already read: ${String(a)}`);c.s=n,c.v=s,c.d=null}else o.set(a,{s:n,v:s})}function e(o){if(typeof o[le]=="function")return o[le](o);if(t(o))return typeof o.prototype[ue]=="function"?o.prototype[ue]():new o;throw new ReferenceError(`No config for ${String(o)}`)}function t(o){return typeof o=="function"&&o.prototype!==void 0&&(Object.getPrototypeOf(o.prototype)!==Object.prototype||Object.getOwnPropertyNames(o.prototype).length>1||o.toString().startsWith("class"))}}();var Oe,V=(i=>(i.service=function(r){return i(G).addChild(r),i.this},i.plugin=function(r){if(!F)Oe=r.app,F=i.fork(),F.set(h.Plugin,r),F.set(r.constructor,r),r.addChild(F.use(G));else if(r!==F.use(h.Plugin))throw new TypeError("use.plugin() called on multiple plugins");return F},i.def(h.Plugin,()=>{throw new Error("Plugin not created yet")}),i.def(h.App,()=>i(h.Plugin).app),i))(fe),F;var k=class extends h.Component{constructor(){super(...arguments);this.use=V.service(this)}},G=class extends h.Component{constructor(){super(...arguments);this.children=new Set([this])}onload(){this.loaded=!0}onunload(){this.loaded=!1,this.children.clear()}addChild(e){return this.children.has(e)||(this.children.add(e),this.loaded?L(()=>super.addChild(e)):super.addChild(e)),e}};function Q(i,r){L(()=>i.removeChild(r))}function ve(i,r){let e=new h.Component;e.onload=()=>{Q(i,e),i=null,r()},i.addChild(e)}function u(i,r){let e=Object.keys(r).map(t=>ze(i,t,r[t]));return e.length===1?e[0]:function(){e.forEach(t=>t())}}function ze(i,r,e){let t=i[r],o=i.hasOwnProperty(r),a=e(t);return t&&Object.setPrototypeOf(a,t),Object.setPrototypeOf(n,a),i[r]=n,s;function n(...c){return a===t&&i[r]===n&&s(),a.apply(this,c)}function s(){i[r]===n&&(o?i[r]=t:delete i[r]),a!==t&&(a=t,Object.setPrototypeOf(n,t||Function))}}function _(i,r,e){return t[i]=i,t;function t(...o){return(r[i]===i?r:e).apply(this,o)}}function X(i){let r=app.workspace;switch(i==null?void 0:i.getRoot()){case r.rootSplit:case r.floatingSplit:case r.leftSplit:case r.rightSplit:return!0;default:return!1}}function D(i,r){if(!i)return!1;if(typeof i=="function"&&(r=i,i=app.workspace),r(i))return!0;if(i instanceof h.Workspace)return D(i.rootSplit,r)||D(i.floatingSplit,r)||D(i.leftSplit,r)||D(i.rightSplit,r);if(i instanceof h.WorkspaceParent){for(let e of i.children)if(D(e,r))return!0}return!1}var M=class{constructor(r,e,t,o){this.key=e;this.defaultValue=t;this.owner=o;this.store=r.use(J)}of(r){return new M(this.store,this.key,this.defaultValue,r)}get(r=this.owner){return this.store.get(this.requires(r),this.key,this.defaultValue)}set(r,e=this.owner){this.store.set(this.requires(e),this.key,r)}unset(r=this.owner){this.store.unset(this.requires(r),this.key)}requires(r){if(r&&(r instanceof h.Workspace||r instanceof h.WorkspaceItem))return r;throw new TypeError("Setting method requires a workspace or workspace item")}onSet(r,e){return this.owner?this.store.onSet(this.key,(t,o,a)=>{t===this.owner&&r.call(e,o,a)}):this.store.onSet(this.key,r,e)}onLoadWorkspace(r,e){return this.store.onLoadWorkspace(r,e)}offref(r){this.store.offref(r)}},J=class extends k{constructor(){super(...arguments);this.loading=!1}get(e,t,o){var a,n;return(n=(a=e==null?void 0:e[C])==null?void 0:a[t])!=null?n:o}set(e,t,o){let a=e[C]||(e[C]={}),n=a[t];a[t]=o,!this.loading&&n!==o&&(app.workspace.trigger(be+t,e,o,n),app.workspace.requestSaveLayout())}unset(e,t){let o=e[C];o!=null&&o.hasOwnProperty(t)&&(delete o[t],this.loading||app.workspace.requestSaveLayout())}onSet(e,t,o){return app.workspace.on(be+e,t,o)}onLoadItem(e,t){return!this.loading&&app.workspace.layoutReady&&L(()=>{D(o=>{try{e.call(t,o)}catch(a){console.error(a)}})}),app.workspace.on(N,e,t)}onSaveItem(e,t){return app.workspace.on(Ee,e,t)}onLoadWorkspace(e,t){return!this.loading&&app.workspace.layoutReady&&L(()=>{try{e.call(t)}catch(o){console.error(o)}}),app.workspace.on(N+":workspace",e,t)}offref(e){app.workspace.offref(e)}onload(){let e=app.workspace;this.registerEvent(e.on(N+":start",()=>this.loading=!0)),this.registerEvent(e.on(N+":workspace",()=>this.loading=!1)),this.register(u(h.WorkspaceItem.prototype,{serialize:Se})),this.register(u(app.workspace,{getLayout:Se,setLayout(t){return _(de,t,async function(a,...n){e.trigger(N+":start");try{return Le(this,a),await t.call(this,a,...n)}finally{e.trigger(N+":workspace")}})},deserializeLayout(t){return _(de,t,async function(a,...n){let s=await t.call(this,a,...n);return Le(s,a),s})}}))}},he=2,de=Symbol.for(`v${he}.layout-storage-events.ophidian.peak-dev.org`),C="ophidian:layout-settings",N=`ophidian-layout-storage:v${he}:item-load`,Ee=`ophidian-layout-storage:v${he}:item-save`,be="ophidian-layout-storage:set:";function Se(i){return _(de,i,function(){let e=i.call(this);return app.workspace.trigger(Ee,this,e),this[C]&&(e[C]=pe(this[C])),e})}function Le(i,r){if(!i)return;let e=r==null?void 0:r[C];e&&(i[C]=pe(e)),app.workspace.trigger(N,i,r)}var B=class extends h.Component{constructor(e,t){super();this.use=e;this.container=t;this.win=this.container.win}[V.factory](){return new Y(this.constructor)}static onload(e){}static onunload(e){}},Y=class extends k{constructor(e){super();this.factory=e;this.instances=new Map;this.watching=!1;this.layoutReadyCallbacks=[]}onload(){var e,t;this.registerEvent(app.workspace.on("layout-change",()=>{app.workspace.layoutReady&&this.layoutReadyCallbacks.length&&(this.layoutReadyCallbacks.forEach(L),this.layoutReadyCallbacks=[])})),(t=(e=this.factory).onload)==null||t.call(e,this.use)}onLeafChange(e,t){return this.onLayoutReady(()=>e.call(t,app.workspace.activeLeaf)),app.workspace.on("active-leaf-change",o=>{app.workspace.layoutReady&&e.call(t,o)})}onLayoutReady(e){app.workspace.layoutReady?L(e):this.layoutReadyCallbacks.push(e)}onunload(){var e,t;(t=(e=this.factory).onunload)==null||t.call(e,this.use)}watch(){if(!this._loaded)ve(this,()=>this.watch());else if(!this.watching){let{workspace:e}=app,t=this;this.watching=!0,this.registerEvent(e.on("window-open",o=>{this.onLayoutReady(()=>this.forContainer(o))})),this.register(u(e,{clearLayout(o){return async function(){try{return await o.call(this)}finally{t.onLayoutReady(()=>t.forAll())}}}})),this.onLayoutReady(()=>this.forAll())}return this}forWindow(e=(o=>(o=window.activeWindow)!=null?o:window)(),t=!0){let a=qe(e);if(a)return this.forContainer(a,t)}forContainer(e,t=!0){e=e.getContainer();let o=this.instances.get(e);return!o&&t&&(o=new this.factory(this.use,e),o&&(this.instances.set(e,o),this.addChild(o),e.component.addChild(o),o.register(()=>{Q(this,o),Q(e.component,o),this.instances.delete(e)}))),o}forDom(e,t=!0){return this.forWindow(Be(e),t)}forLeaf(e=app.workspace.activeLeaf,t=!0){if(X(e))return this.forContainer(e.getContainer(),t)}forView(e,t=!0){return this.forLeaf(e.leaf,t)}forAll(e=!0){return Ce().map(t=>this.forContainer(t,e)).filter(t=>t)}};function Ce(){return[app.workspace.rootSplit].concat(app.workspace.floatingSplit.children)}function ge(){return Ce().map(i=>i.win)}function b(){var i,r;return 1+((r=(i=app.workspace.floatingSplit)==null?void 0:i.children.length)!=null?r:0)}function xe(i){for(let r of ge())if(r.event&&i(r,r.event))return r.event}function Be(i){return i.win||(i.ownerDocument||i).defaultView||window}function qe(i){if(i===window)return app.workspace.rootSplit;let{floatingSplit:r}=app.workspace;if(r){for(let e of r.children)if(i===e.win)return e}}var Z=class extends k{onload(){let r=this,e=this.use(h.Plugin);this.register(u(e,{loadCSS(t){return async function(){await t.call(this),r.triggerReparse(),this.register(()=>r.triggerReparse())}}}))}triggerReparse(){app.workspace.layoutReady&&app.workspace.trigger("parse-style-settings")}};var Pe={};function Te(i,r,e=[],t={}){typeof e=="string"&&(e=[e]),typeof e=="object"&&e.key&&(e=[e]);let o=e.map(function(n){if(typeof n=="object")return n;let s=n.split("+");return{modifiers:s,key:s.pop()||"+"}});Object.assign(t,{id:i,name:r,hotkeys:o});let a=Symbol("cmd:"+i);return Pe[a]=t,a}function Me(i,r=i.constructor.prototype){Object.getOwnPropertySymbols(r).forEach(e=>{let t=Pe[e],o=r[e];t&&i.addCommand(Object.assign({},t,{checkCallback(a){let n=o.call(i);return a||typeof n!="function"?!!n:(n(),!0)}}))})}var We={};function l(i,r,e=[],t={}){typeof e=="string"&&(e=[e]),typeof e=="object"&&e.key&&(e=[e]);let o=e.map(function(n){if(typeof n=="object")return n;let s=n.split("+");return{modifiers:s,key:s.pop()||"+"}});Object.assign(t,{id:i,name:r,hotkeys:o});let a=Symbol("cmd:"+i);return We[a]=t,a}function ee(i,r=i.constructor.prototype){Object.getOwnPropertySymbols(r).forEach(e=>{let t=We[e],o=r[e];t&&i.addCommand(Object.assign({},t,{checkCallback(a){let n=o.call(i);return a||typeof n!="function"?!!n:(n(),!0)}}))})}var A=require("obsidian");var w=require("obsidian");var S=require("obsidian");var te="pane-relief:history-v1",me="pane-relief:history-v1",W=(0,S.requireApiVersion)("0.16.3"),we=new WeakMap,q=class{constructor(r){this.setState(r)}static fromNative(r){return new this({...r,state:JSON.stringify(r.state),eState:JSON.stringify(r.eState)})}get asNative(){let r={...this.raw,state:this.viewState,eState:this.eState};if(!r.title||!r.icon){let e=re(this);r.title||(r.title=e.title||""),r.icon||(r.icon=e.icon||"")}return r}get viewState(){return JSON.parse(this.raw.state||"{}")}setState(r){var e;this.raw=r,this.eState=JSON.parse(r.eState||"null"),this.path=(e=this.viewState.state)==null?void 0:e.file}onRename(r,e){if(this.path===e){let t=this.viewState;this.path=t.state.file=r.path,this.raw.state=JSON.stringify(t)}}go(r){let{viewState:e,path:t,eState:o}=this,a=t&&(app==null?void 0:app.vault.getAbstractFileByPath(t));t&&!a&&(new S.Notice("Missing file: "+t),e={type:"empty",state:{}},o=void 0),r.setViewState({...e,active:!0,popstate:!0},o)}isEmpty(){return JSON.parse(this.raw.state||"{}").type==="empty"}replaceState(r){var e;if(r.state!==this.raw.state){let t=JSON.parse(r.state||"{}");if(t.type==="empty")return!0;if(this.path&&this.path!==((e=t==null?void 0:t.state)==null?void 0:e.file))return!1;if(t.type==="media-view"){let o=JSON.stringify(this.viewState.state.info),a=JSON.stringify(t.state.info);if(o!==a)return!1}}return this.setState(r),!0}},d=class{constructor(r,{pos:e,stack:t}={pos:0,stack:[]}){this.leaf=r;this.hadTabs=W;r&&(r[te]=this),this.leaf=r,this.pos=e,this.stack=t.map(o=>new q(o))}static current(){return this.forLeaf(app.workspace.activeLeaf)||new this}static forLeaf(r){if(r&&we.set(r.containerEl,r),r){let e=r[te];if(e instanceof this)return e;if(e&&!e.hadTabs){let t=(e==null?void 0:e.serialize())||void 0;return new this(r,t).saveToNative()}return new this(r).loadFromNative()}}saveToNative(){var t;let r=(t=this.leaf)==null?void 0:t.history;if(!r||!W)return this;let e=this.stack.map(o=>o.asNative);return r.deserialize({backHistory:e.slice(this.pos+1).reverse(),forwardHistory:e.slice(0,this.pos)}),this}loadFromNative(){var t;let r=(t=this.leaf)==null?void 0:t.history;if(!r||!W)return this;let e=[].concat(r.forwardHistory.slice().filter(o=>o),{state:{},eState:{}},r.backHistory.slice().filter(o=>o).reverse());return this.stack=e.map(o=>q.fromNative(o)),this.pos=r.forwardHistory.length,this}cloneTo(r){return new d(r,this.serialize()).saveToNative()}onRename(r,e){for(let t of this.stack)t.onRename(r,e)}serialize(){return{pos:this.pos,stack:this.stack.map(r=>r.raw)}}get state(){var r;return((r=this.stack[this.pos])==null?void 0:r.raw)||null}get length(){return this.stack.length}back(){this.go(-1)}forward(){this.go(1)}lookAhead(){return this.stack.slice(0,this.pos).reverse()}lookBehind(){return this.stack.slice(this.pos+1)}announce(){var r;(r=app==null?void 0:app.workspace)==null||r.trigger("pane-relief:update-history",this.leaf,this)}goto(r){var e;if(this.leaf){if(this.leaf.pinned)return new S.Notice(`Pinned ${v}: unpin before going forward or back`),void 0;if(this.leaf.working)return new S.Notice("Pane is busy: please wait before navigating further"),void 0;r=this.pos=Math.max(0,Math.min(r,this.stack.length-1)),(e=this.stack[r])==null||e.go(this.leaf),this.announce()}}go(r,e){if(!this.leaf||!r)return;let t=Math.max(0,Math.min(this.pos-r,this.stack.length-1));e||t!==this.pos?this.leaf.history&&W?(this.pos=t,this.leaf.history.go(r)):this.goto(t):new S.Notice(`No more ${r<0?"back":"forward"} history for ${v}`)}replaceState(r,e,t){let o=this.stack[this.pos];o?o.replaceState(r)||this.pushState(r,e,t):this.stack[this.pos]=new q(r)}pushState(r,e,t){let o=this.stack[this.pos];if(o&&o.isEmpty())return this.replaceState(r,e,t);for(this.stack.splice(0,this.pos,new q(r)),this.pos=0;this.stack.length>20;)this.stack.pop();this.announce()}},oe=class extends k{onload(){let r=this.use(J);if(this.registerEvent(r.onSaveItem((o,a)=>{o instanceof S.WorkspaceLeaf&&o[te]&&(a[me]=o[te].serialize())})),this.registerEvent(r.onLoadItem((o,a)=>{o instanceof S.WorkspaceLeaf&&a&&a[me]&&new d(o,a[me]).saveToNative()})),W){this.register(u(S.WorkspaceLeaf.prototype,{trigger(o){return function(n,...s){if(n==="history-change"){let c=d.forLeaf(this);c.loadFromNative(),app.workspace.trigger("pane-relief:update-history",this,c)}return o.call(this,n,...s)}}})),app.workspace.layoutReady&&app.workspace.iterateAllLeaves(o=>{d.forLeaf(o)});return}this.register(u(S.WorkspaceLeaf.prototype,{setViewState(o){return function(n,s){var c;return n.popstate&&((c=window.event)==null?void 0:c.type)==="popstate"?Promise.resolve():o.call(this,n,s)}}})),this.register(u(app.workspace,{setActiveLeaf(o){return function(n,...s){let c=u(this,{recordHistory(p){return function(f,m,...g){return p.call(this,f,!1,...g)}}});try{return o.call(this,n,...s)}finally{c()}}}}));function e(o){return!!xe((a,n)=>{if(n.type==="mousedown"&&n.button===o)return n.preventDefault(),n.stopImmediatePropagation(),!0})}let t=window.history;this.register(()=>window.history=t),Object.defineProperty(window,"history",{enumerable:!0,configurable:!0,writable:!0,value:{get state(){return d.current().state},get length(){return d.current().length},back(){e(3)||this.go(-1)},forward(){e(4)||this.go(1)},go(o){d.current().go(o)},replaceState(o,a,n){d.current().replaceState(o,a,n)},pushState(o,a,n){d.current().pushState(o,a,n)},get scrollRestoration(){return t.scrollRestoration},set scrollRestoration(o){t.scrollRestoration=o}}})}};var $e=(0,w.debounce)(()=>{app.vault.getConfig("theme")==="system"&&app.adaptToSystemTheme()},200,!0),Ke={markdown:"document",image:"image-file",audio:"audio-file",video:"audio-file",pdf:"pdf-file",localgraph:"dot-network",outline:"bullet-list",backlink:"link",kanban:"blocks",excalidraw:"excalidraw-icon","media-view":"audio-file"},He={graph:["dot-network","Graph View"],"file-explorer":["folder","File Explorer"],starred:["star","Starred Files"],tag:["tag","Tags View"],"recent-files":["clock","Recent Files"],calendar:["calendar-with-checkmark","Calendar"],empty:["cross","No file"]},$=class extends B{constructor(){super(...arguments);this.historyIsOpen=!1}display(e=this.latestLeaf()){if(!this.historyIsOpen){if(!this._loaded){this.load();return}this.win.requestAnimationFrame(()=>{let t=e?d.forLeaf(e):new d;this.back.setHistory(t),this.forward.setHistory(t),e&&this.updateLeaf(e,t)})}}leaves(){var a;let e=new Set,t=n=>{e.add(n)};app.workspace.iterateLeaves(t,this.container);let o=(a=app.plugins.plugins["obsidian-hover-editor"])==null?void 0:a.activePopovers;if(o)for(let n of o)n.hoverEl.ownerDocument.defaultView===this.win&&(n.rootSplit?app.workspace.iterateLeaves(t,n.rootSplit):n.leaf&&t(n.leaf));return[...e.values()]}latestLeaf(){let e=app.workspace.activeLeaf;return e&&this.use($).forLeaf(e)===this?e:this.leaves().reduce((t,o)=>!t||t.activeTime<o.activeTime?o:t,null)}onload(){let{document:e}=this.win;(0,w.requireApiVersion)("0.16.0")&&e.body.addClass("obsidian-themepocalypse"),this.win.addEventListener("pointerup",o,!0),this.win.addEventListener("pointerdown",o,!0),this.register(()=>{this.win.removeEventListener("pointerup",o,!0),this.win.removeEventListener("pointerdown",o,!0)});let t=this;function o(a){if(a.button!==3&&a.button!==4)return;a.preventDefault(),a.stopImmediatePropagation();let n=a.target.matchParent(".workspace-leaf, .workspace-tab-header");if(n&&a.type==="pointerup"){let s=we.get(n);if(s||app.workspace.iterateLeaves(c=>s=c.containerEl===n||c.tabHeaderEl===n?c:s,t.container),!s)return!1;a.button==3&&d.forLeaf(s).back(),a.button==4&&d.forLeaf(s).forward()}return!1}this.registerDomEvent(this.win.matchMedia("(prefers-color-scheme: dark)"),"change",$e),app.workspace.onLayoutReady(()=>{this.addChild(this.back=new H(this,"back",-1)),this.addChild(this.forward=new H(this,"forward",1)),this.display(),this.numberPanes(),this.registerEvent(app.workspace.on("layout-change",this.numberPanes,this))})}onunload(){this.unNumberPanes(),this.win.document.body.findAll(".workspace-leaf").forEach(e=>{let t=e.find(".view-header > .view-actions"),o=t==null?void 0:t.find('.view-action[class*=" app:go-forward"]'),a=t==null?void 0:t.find('.view-action[class*=" app:go-back"]');o&&K(o,this.forward.oldLabel),a&&K(o,this.back.oldLabel)})}unNumberPanes(e=".workspace-leaf"){this.win.document.body.findAll(e).forEach(t=>{t.style.removeProperty("--pane-relief-label"),t.toggleClass("has-pane-relief-label",!1),t.style.removeProperty("--pane-relief-forward-count"),t.style.removeProperty("--pane-relief-backward-count")})}updateLeaf(e,t=d.forLeaf(e)){e.containerEl.style.setProperty("--pane-relief-forward-count",'"'+(t.lookAhead().length||"")+'"'),e.containerEl.style.setProperty("--pane-relief-backward-count",'"'+(t.lookBehind().length||"")+'"');let o=e.containerEl.find(".view-header > .view-actions"),a=o==null?void 0:o.find('.view-action[class*=" app:go-forward"]'),n=o==null?void 0:o.find('.view-action[class*=" app:go-back"]');if(a&&this.forward.updateDisplay(t,a),n&&this.back.updateDisplay(t,n),W){let s=e.containerEl.find(".view-header > .view-header-nav-buttons"),c=s==null?void 0:s.find("button:last-child"),p=s==null?void 0:s.find("button:first-child");c&&this.forward.updateDisplay(t,c),p&&this.back.updateDisplay(t,p)}}numberPanes(){this.win.requestAnimationFrame(()=>{let e=new Map;this.win===window&&this.unNumberPanes(".workspace > .workspace-split:not(.mod-root) .workspace-tabs > .workspace-leaf");let t=0,o=null;this.leaves().forEach(a=>{a.containerEl.style.setProperty("--pane-relief-label",++t<9?""+t:""),a.containerEl.toggleClass("has-pane-relief-label",t<9),o=a,this.updateLeaf(a),a.parentSplit instanceof w.WorkspaceTabs&&e.set(a.parentSplit,1+(e.get(a.parentSplit)||0))}),t>8&&(o==null||o.containerEl.style.setProperty("--pane-relief-label","9"),o==null||o.containerEl.toggleClass("has-pane-relief-label",!0));for(let[a,n]of e.entries())a.containerEl.style.setProperty("--pane-relief-tab-count",""+n)})}onUpdateHistory(e,t){this.win.requestAnimationFrame(()=>{this.updateLeaf(e),t===this.forward.history&&this.forward.setHistory(t),t===this.back.history&&this.back.setHistory(t)})}},ye=class extends w.Component{constructor(e,t,o){super();this.owner=e;this.kind=t;this.dir=o;this.history=null}onload(){this.containerEl=this.owner.win.document.body.find(`.titlebar .titlebar-button-container.mod-left .titlebar-button.mod-${this.kind}`)||this.owner.win.createDiv(),this.count=this.containerEl.createSpan({prepend:this.kind==="back",cls:"history-counter"}),this.history=null,this.oldLabel=this.containerEl.getAttribute("aria-label")||i18next.t(this.dir<0?"commands.navigate-back":"commands.navigate-forward"),this.registerDomEvent(this.containerEl,"contextmenu",this.openMenu.bind(this));let e=t=>{var o;t.preventDefault(),t.stopImmediatePropagation(),(o=this.history)==null||o[this.kind]()};this.register(()=>this.containerEl.removeEventListener("click",e,!0)),this.containerEl.addEventListener("click",e,!0),this.register(Ue(this.owner.win.document.body,"contextmenu",`.view-header > .view-actions > .view-action[class*="app:go-${this.kind}"],
.view-header > .view-header-nav-buttons > button:${this.dir<0?"first":"last"}-child`,(t,o)=>{let a=o.matchParent(".workspace-leaf"),n=this.owner.leaves().filter(s=>s.containerEl===a).pop();n&&(t.preventDefault(),t.stopImmediatePropagation(),this.openMenu(t,d.forLeaf(n)))},{capture:!0}))}onunload(){K(this.containerEl,this.oldLabel),this.count.detach(),this.containerEl.toggleClass("mod-active",!1)}setCount(e){this.count.textContent=""+(e||"")}setHistory(e=d.current()){this.updateDisplay(this.history=e)}updateDisplay(e,t=this.containerEl){let o=e[this.dir<0?"lookBehind":"lookAhead"]();t===this.containerEl&&this.setCount(o.length),K(t,o.length?this.oldLabel+`
`+re(o[0]).title:`No ${this.kind} history`),t.toggleClass("mod-active",o.length>0)}openMenu(e,t=this.history){var n;let o=t[this.dir<0?"lookBehind":"lookAhead"]();if(!o.length)return;let a=new w.Menu;(n=a.setUseNativeMenu)==null||n.call(a,!1),a.dom.addClass("pane-relief-history-menu"),a.dom.on("mousedown",".menu-item",s=>{s.stopPropagation()},!0),o.map(re).forEach((s,c)=>this.menuItem(s,c,a,t)),a.showAtPosition({x:e.clientX,y:e.clientY+20}),a.register(u(app.workspace,{setActiveLeaf(s){return function(c,...p){if(!c.containerEl.matchParent(".hover-editor"))return s.call(this,c,...p)}}})),this.owner.historyIsOpen=!0,a.onHide(()=>{this.owner.historyIsOpen=!1,this.owner.display()})}menuItem(e,t,o,a){let{dir:n,kind:s}=this;o.addItem(f=>{c(f),e.file&&p(f.dom)});return;function c(f,m=""){f.setIcon(e.icon).setTitle(m+e.title).onClick(g=>{if(w.Keymap.isModEvent(g))if(W&&a.leaf){app.workspace.duplicateLeaf(a.leaf,w.Keymap.isModEvent(g)).then(y=>{d.forLeaf(y).go((t+1)*n,!0)});return}else a=a.cloneTo(app.workspace.getLeaf(w.Keymap.isModEvent(g)));a.go((t+1)*n,!0)})}function p(f){f.addEventListener("mouseover",m=>{app.workspace.trigger("hover-link",{event:m,source:ye.hoverSource,hoverParent:o.dom,targetEl:f,linktext:e.file.path})}),f.setAttr("draggable","true"),f.addEventListener("dragstart",m=>{let g=app.dragManager,y=g.dragFile(m,e.file);g.onDragStart(m,y)}),f.addEventListener("dragend",m=>o.hide()),f.addEventListener("contextmenu",m=>{let g=new w.Menu;g.addItem(y=>c(y,`Go ${s} to `)).addSeparator(),app.workspace.trigger("file-menu",g,e.file,"link-context-menu"),g.showAtPosition({x:m.clientX,y:m.clientY}),m.stopPropagation()},!0)}}},H=ye;H.hoverSource="pane-relief:history-menu";function re(i){var c,p,f,m,g;let{viewState:{type:r,state:e},eState:t,path:o,raw:a}=i,n=o&&app.vault.getAbstractFileByPath(o),s={icon:(c=a==null?void 0:a.icon)!=null?c:"",title:(p=a==null?void 0:a.title)!=null?p:"",file:n,type:r,state:e,eState:t};return He[r]?[s.icon,s.title]=He[r]:o&&!n?[s.icon,s.title]=["trash","Missing file "+o]:n instanceof w.TFile&&(s.icon=(f=Ke[r])!=null?f:"document",r==="markdown"&&e.mode==="preview"&&(s.icon="lines-of-text"),s.title=n?n.basename+(n.extension!=="md"?"."+n.extension:""):"No file",r==="media-view"&&!n&&(s.title=(g=(m=e.info)==null?void 0:m.filename)!=null?g:s.title)),app.workspace.trigger("pane-relief:format-history-item",s),s}function Ue(i,r,e,t,o){return i.on(r,e,t,o),()=>i.off(r,e,t,o)}function K(i,r){r?i.setAttribute("aria-label",r||void 0):i.removeAttribute("aria-label")}var ae=class extends k{constructor(){super(...arguments);this.setting=new M(this,"pane-relief:focus-lock").of(app.workspace);this.plugin=this.use(A.Plugin);this.statusEl=this.plugin.addStatusBarItem();this.iconEl=this.statusEl.createSpan("pane-relief-focus-lock icon",e=>{e.setAttribute("aria-label-position","top"),e.setAttribute("aria-label-delay","0"),e.setAttribute("data-tooltip-position","top")});this.isLocked=null;this.installed=!1}onload(){this.registerDomEvent(this.iconEl,"click",()=>this.toggle()),ee(this.plugin,{[l("focus-lock","Toggle focus lock (Enable/disable sidebar focusing)")]:()=>()=>this.toggle()}),this.registerEvent(this.setting.onLoadWorkspace(this.onChange,this))}install(){this.installed=!0;let e=this;this.register(u(app.workspace,{setActiveLeaf(t){return function(o,...a){if(!e.isLocked||R(o))return t.call(this,o,...a);if(app.workspace.revealLeaf(o),!this.activeLeaf||!X(this.activeLeaf))return t.call(this,this.getLeaf(),...a)}},revealLeaf(t){return function(o){let a=o.getContainer();if(!e.isLocked||R(o)||!a)return t.call(this,o);let n=u(a,{focus(){return function(){}}});try{return t.call(this,o)}finally{n()}}}})),this.register(u(A.WorkspaceLeaf.prototype,{canNavigate(t){return function(){return t.call(this)&&(!e.isLocked||R(this))}}})),this.register(u(app.internalPlugins.plugins["file-explorer"].instance,{init(t){return function(...a){try{return t.apply(this,a)}finally{e.blockFileExplorerReveal()}}}})),this.blockFileExplorerReveal()}blockFileExplorerReveal(){let e=this,t=app.commands.commands["file-explorer:reveal-active-file"];t&&this.register(u(t,{checkCallback(o){return function(...a){var n;if(e.isLocked){for(let s of app.workspace.getLeavesOfType("file-explorer"))if(!R(s)){let c=(n=s.view.dom)==null?void 0:n.navFileContainerEl;c&&L(u(c,{focus(p){return function(){}}}))}}return o==null?void 0:o.apply(this,a)}}}))}toggle(){this.setting.set(!this.setting.get()),this.onChange()}onChange(){let e=this.setting.get();e&&!this.installed&&this.install(),this.isLocked!==e&&(this.isLocked!=null&&document.body.appendChild(new A.Notice(e?"Sidebar focusing disabled":"Sidebar focusing enabled").noticeEl.parentElement),this.isLocked=e,(0,A.setIcon)(this.iconEl,e?"lucide-lock":"lucide-unlock"),K(this.iconEl,e?"Sidebar focus disabled: click to enable":"Sidebar focus enabled: click to disable"),e&&!R(app.workspace.activeLeaf)&&app.workspace.layoutReady&&app.workspace.setActiveLeaf(app.workspace.getUnpinnedLeaf(),!1,!0))}};function R(i){let r=i==null?void 0:i.getRoot();return!!(r&&r!==app.workspace.leftSplit&&r!==app.workspace.rightSplit)}var O=require("obsidian");var ie=class extends k{constructor(){super(...arguments);this.changing=!1;this.fixSlidingPanes=(0,O.debounce)(()=>{let e=app.workspace.activeLeaf.parentSplit;(0,O.requireApiVersion)("0.16.2")&&e instanceof O.WorkspaceTabs&&e.isStacked?e.containerEl.win.requestAnimationFrame(()=>{let t=u(e.tabsContainerEl,{scrollTo(o){return function(a,n){return typeof a=="object"?(delete a.behavior,o.call(this,a)):o.call(this,a,n)}}});try{e.scrollIntoView(e.currentTab)}finally{t(),this.changing=!1}}):(app.workspace.requestActiveLeafEvents(),this.changing=!1)},1,!0)}onload(){this.registerEvent(app.workspace.on("layout-change",()=>{for(let t of this.parents())this.refresh(t)}));let e=this;this.register(u(app.workspace,{setActiveLeaf(t){return function(a,n,s){let c=e.parentForLeaf(a),p=e.parentForLeaf(app.workspace.activeLeaf);return c&&p&&c!==p&&p.matchParent(".hover-popover.is-active.snap-to-viewport")&&c.ownerDocument===p.ownerDocument&&!c.matchParent(".hover-popover")&&app.commands.executeCommandById("obsidian-hover-editor:restore-active-popover"),R(a)&&c&&e.refresh(c,c.hasClass("should-maximize")?a.containerEl:null),t.call(this,a,n,s)}}})),this.register(u(O.WorkspaceTabs.prototype,{onContainerScroll(t){return function(){if(!e.changing&&this.containerEl.isShown())return t.call(this)}}})),app.workspace.onLayoutReady(()=>{let t=app.workspace.rightSidebarToggleButtonEl.cloneNode(!0);t.id="pr-maximize-sb-toggle",t.addEventListener("click",()=>app.workspace.rightSplit.toggle()),t.ariaLabel=i18next.t(app.workspace.rightSplit.collapsed?"interface.sidebar-expand":"interface.sidebar-collapse"),app.workspace.containerEl.parentElement.appendChild(t),this.register(()=>t.detach()),this.register(u(app.workspace.rightSplit.constructor.prototype,{expand(o){return function(){return t.ariaLabel=i18next.t("interface.sidebar-collapse"),o.call(this)}},collapse(o){return function(){return t.ariaLabel=i18next.t("interface.sidebar-expand"),o.call(this)}}}))})}onunload(){for(let e of this.parents())this.refresh(e,null)}toggleMaximize(e=app.workspace.activeLeaf){(!e||!R(e))&&(e=app.workspace.getMostRecentLeaf(app.workspace.rootSplit));let t=this.parentForLeaf(e);if(!t)return;let o=t.matchParent(".hover-popover");if(o&&app.plugins.plugins["obsidian-hover-editor"]&&o.findAll(".workspace-leaf").length===1){app.commands.executeCommandById("obsidian-hover-editor:"+(o.hasClass("snap-to-viewport")?"restore-active-popover":"snap-active-popover-to-viewport"));return}t&&this.refresh(t,T(t,"should-maximize")?e.containerEl:null)}lastMaximized(e){return e.find(".workspace-leaf.is-maximized")||app.workspace.getMostRecentLeaf().containerEl}refresh(e,t=e.hasClass("should-maximize")?this.lastMaximized(e):null){this.changing=!0;let o=e.hasClass("has-maximized");if(e.findAllSelf(".workspace-split, .workspace-tabs").forEach(a=>{(a===e||this.parentFor(a)===e)&&T(a,"has-maximized",t?a.contains(t):!1)}),e.findAll(".workspace-leaf").forEach(a=>{this.parentFor(a)===e&&T(a,"is-maximized",a===t)}),(!t||!e.contains(t))&&(T(e,"should-maximize",!1),o))return this.fixSlidingPanes();this.changing=!1}parents(){var o,a,n;let e=[app.workspace.rootSplit.containerEl];e.concat(((a=(o=app.workspace.floatingSplit)==null?void 0:o.children)!=null?a:[]).map(s=>s.containerEl));let t=(n=app.plugins.plugins["obsidian-hover-editor"])==null?void 0:n.activePopovers;if(t)for(let s of t)s.rootSplit&&e.push(s.rootSplit.containerEl);return e.map(s=>this.parentFor(s))}parentForLeaf(e){return this.parentFor(e==null?void 0:e.containerEl)}parentFor(e){return e==null?void 0:e.matchParent(".workspace, .hover-popover > .popover-content > .workspace-split")}};var I=require("obsidian"),U=class extends B{constructor(){super(...arguments);this.manager=this.use(U)}[V.factory](){return new ke(this.constructor)}onload(){this.onSet()}onunload(){this.update(!1)}get options(){return this.manager.options.get(this.container)}set options(e){this.manager.options.set(e,this.container)}onSet(e=this.options){this.update(e.active)}update(e){T(this.container.containerEl,"is-sliding",e);let t=this.container.containerEl.matchParent(".workspace");t?T(t,"is-sliding",e):this.register(this.container.containerEl.onNodeInserted(()=>this.update(this.options.active),!0))}activate(e){var o;let{options:t}=this;!this.win.document.hasFocus()&&ge().some(a=>a.document.hasFocus())&&this.container.focus(),t.active&&((o=e.containerEl.matchParent(".workspace-tabs"))!=null?o:e.containerEl).scrollIntoView({behavior:"smooth"}),this.manager.options.defaultValue=t}toggleSliding(){let{options:e}=this;this.options={...e,active:!e.active}}},ke=class extends Y{constructor(){super(...arguments);this.options=new M(this,"pane-relief:sliding-panes",{active:!1});this.overlay=app.workspace.containerEl.parentElement.createDiv("prsp-tb-overlay");this.requestOverlayUpdate=(0,I.debounce)(()=>{var e,t;if(app.workspace.layoutReady&&!((e=app.workspace.leftSplit)!=null&&e.collapsed)){let o=(t=app.workspace.leftSplit.containerEl.find(".workspace-tabs.mod-top-left-space .workspace-tab-header-spacer"))==null?void 0:t.getBoundingClientRect();o&&this.overlay.style.setProperty("--pr-overlay-width",`${o.width}px`),o&&this.overlay.style.setProperty("--pr-overlay-left",`${o.left}px`)}},100,!0)}onunload(){super.onunload(),this.overlay.detach()}onload(){super.onload(),window.CodeMirror.getMode({},"XXX");let e=this;Me(this.use(I.Plugin),{[Te("toggle-sliding","Toggle sliding panes (for current window)")](){return()=>e.forLeaf(app.workspace.activeLeaf).toggleSliding()}}),this.registerEvent(this.options.onSet(this.onChange,this)),this.registerEvent(this.options.store.onLoadItem(this.onChange,this)),this.registerEvent(this.onLeafChange(t=>this.forLeaf(t).activate(t))),app.workspace.onLayoutReady(()=>{this.registerEvent(app.workspace.on("layout-change",this.requestOverlayUpdate)),this.registerEvent(app.workspace.on("resize",this.requestOverlayUpdate));let t=this;this.register(u(app.workspace.leftSplit.constructor.prototype,{expand(o){return function(){return t.requestOverlayUpdate(),o.call(this)}}})),this.requestOverlayUpdate()})}onChange(e){(e instanceof I.WorkspaceRoot||e instanceof I.WorkspaceWindow)&&this.forContainer(e).onSet(this.options.get(e))}};var v=(0,E.requireApiVersion)("0.16")?"tab":"pane",ne=(0,E.requireApiVersion)("0.16")?"group":"split";function x(i){return`Jump to ${i} ${v} in window`}function P(i){return`Place as ${i} ${v} in ${ne}`}var se=class extends E.Plugin{constructor(){super(...arguments);this.use=V.plugin(this);this.nav=this.use($).watch();this.max=this.use(ie);this.sliding=this.use(U).watch()}onload(){this.use(oe).load(),this.register(u(E.Workspace.prototype,{getFocusedContainer(e){return function(){let o=e.call(this);return o===this.rootSplit&&window!==activeWindow?null:o}}})),this.app.workspace.registerHoverLinkSource(H.hoverSource,{display:"History dropdowns",defaultMod:!0}),this.app.workspace.onLayoutReady(()=>{this.registerEvent(this.app.vault.on("rename",(e,t)=>{e instanceof E.TFile&&this.app.workspace.iterateAllLeaves(o=>d.forLeaf(o).onRename(e,t))})),this.registerEvent(app.workspace.on("active-leaf-change",e=>{var t;return(t=this.nav.forLeaf(e))==null?void 0:t.display(e)})),this.registerEvent(app.workspace.on("pane-relief:update-history",(e,t)=>{var o;return(o=this.nav.forLeaf(e))==null?void 0:o.onUpdateHistory(e,t)}))}),ee(this),(0,E.requireApiVersion)("0.15.6")&&this.use(ae),this.use(Z)}[l("swap-prev",`Swap ${v} with previous in ${ne}`,"Mod+Shift+PageUp")](){return this.leafPlacer(-1)}[l("swap-next",`Swap ${v} with next in ${ne}`,"Mod+Shift+PageDown")](){return this.leafPlacer(1)}[l("go-prev",`Cycle to previous ${v} in this window`,"Mod+PageUp")](){return()=>this.gotoNthLeaf(-1,!0)}[l("go-next",`Cycle to next ${v} in this window`,"Mod+PageDown")](){return()=>this.gotoNthLeaf(1,!0)}[l("win-prev","Cycle to previous window",[])](){if(b()>1)return()=>this.gotoNthWindow(-1,!0)}[l("win-next","Cycle to next window",[])](){if(b()>1)return()=>this.gotoNthWindow(1,!0)}[l("go-1st",x("1st"),"Alt+1")](){return()=>this.gotoNthLeaf(0)}[l("go-2nd",x("2nd"),"Alt+2")](){return()=>this.gotoNthLeaf(1)}[l("go-3rd",x("3rd"),"Alt+3")](){return()=>this.gotoNthLeaf(2)}[l("go-4th",x("4th"),"Alt+4")](){return()=>this.gotoNthLeaf(3)}[l("go-5th",x("5th"),"Alt+5")](){return()=>this.gotoNthLeaf(4)}[l("go-6th",x("6th"),"Alt+6")](){return()=>this.gotoNthLeaf(5)}[l("go-7th",x("7th"),"Alt+7")](){return()=>this.gotoNthLeaf(6)}[l("go-8th",x("8th"),"Alt+8")](){return()=>this.gotoNthLeaf(7)}[l("go-last",x("last"),"Alt+9")](){return()=>this.gotoNthLeaf(99999999)}[l("win-1st","Switch to 1st window",[])](){if(b()>1)return()=>this.gotoNthWindow(0)}[l("win-2nd","Switch to 2nd window",[])](){if(b()>1)return()=>this.gotoNthWindow(1)}[l("win-3rd","Switch to 3rd window",[])](){if(b()>2)return()=>this.gotoNthWindow(2)}[l("win-4th","Switch to 4th window",[])](){if(b()>3)return()=>this.gotoNthWindow(3)}[l("win-5th","Switch to 5th window",[])](){if(b()>4)return()=>this.gotoNthWindow(4)}[l("win-6th","Switch to 6th window",[])](){if(b()>5)return()=>this.gotoNthWindow(5)}[l("win-7th","Switch to 7th window",[])](){if(b()>6)return()=>this.gotoNthWindow(6)}[l("win-8th","Switch to 8th window",[])](){if(b()>7)return()=>this.gotoNthWindow(7)}[l("win-last","Switch to last window",[])](){if(b()>1)return()=>this.gotoNthWindow(99999999)}[l("put-1st",P("1st"),"Mod+Alt+1")](){return()=>this.placeLeaf(0,!1)}[l("put-2nd",P("2nd"),"Mod+Alt+2")](){return()=>this.placeLeaf(1,!1)}[l("put-3rd",P("3rd"),"Mod+Alt+3")](){return()=>this.placeLeaf(2,!1)}[l("put-4th",P("4th"),"Mod+Alt+4")](){return()=>this.placeLeaf(3,!1)}[l("put-5th",P("5th"),"Mod+Alt+5")](){return()=>this.placeLeaf(4,!1)}[l("put-6th",P("6th"),"Mod+Alt+6")](){return()=>this.placeLeaf(5,!1)}[l("put-7th",P("7th"),"Mod+Alt+7")](){return()=>this.placeLeaf(6,!1)}[l("put-8th",P("8th"),"Mod+Alt+8")](){return()=>this.placeLeaf(7,!1)}[l("put-last",P("last"),"Mod+Alt+9")](){return()=>this.placeLeaf(99999999,!1)}[l("maximize",`Maximize active ${v} (Toggle)`,[])](){if(this.max.parentForLeaf(app.workspace.activeLeaf))return()=>this.max.toggleMaximize()}[l("ordered-close",`Close ${v} and go to adjacent ${v}`)](){return()=>{let e=app.workspace.activeLeaf,t=this.nav.forLeaf(e).leaves(),o=t.indexOf(e),a;o>-1&&(t.length>o+1?a=t[o+1]:o>0&&(a=t[o-1])),a&&app.workspace.setActiveLeaf(a,!1,!0),e.detach()}}[l("open-new-window","Open new window")](){return()=>app.workspace.openPopoutLeaf()}onunload(){this.app.workspace.unregisterHoverLinkSource(H.hoverSource)}gotoNthLeaf(e,t){let o=app.workspace.activeLeaf,a=o.getRoot();(a===app.workspace.leftSplit||a===app.workspace.rightSplit)&&(o=app.workspace.getMostRecentLeaf(app.workspace.rootSplit));let n=this.nav.forLeaf(o);o=Re(n.leaves(),o,e,t),!o||this.app.workspace.setActiveLeaf(o,!0,!0)}gotoNthWindow(e,t){var n,s,c,p,f;let o=Re(this.nav.forAll(),this.nav.forLeaf(app.workspace.activeLeaf),e,t),a=o==null?void 0:o.latestLeaf();a&&app.workspace.setActiveLeaf(a,!0,!0),(f=(p=(c=(s=(n=o==null?void 0:o.win).require)==null?void 0:s.call(n,"electron"))==null?void 0:c.remote)==null?void 0:p.getCurrentWindow())==null||f.focus()}placeLeaf(e,t=!0){let o=this.leafPlacer(e,t);o&&o()}leafPlacer(e,t=!0){let o=this.app.workspace.activeLeaf;if(!o)return!1;let a=o.parentSplit,n=a.children,s=n.indexOf(o);if(s==-1)return!1;if(n.length===1){let c=o.containerEl.matchParent(".hover-popover");if(c&&t&&Math.abs(e)===1){let p=c;for(;p&&(p===c||!p.matches(".hover-popover"));)p=e<0?p.previousElementSibling:p.nextElementSibling;if(p)return()=>{e<0?p.parentElement.insertBefore(c,p):p.parentElement.insertBefore(p,c),app.workspace.onLayoutChange()}}}if(t){if(e+=s,e<0||e>=n.length)return!1}else e>=n.length&&(e=n.length-1),e<0&&(e=0);return s==e?!1:()=>{let c=n[e];n.splice(s,1),n.splice(e,0,o),a.selectTab?a.selectTab(o):(c.containerEl.insertAdjacentElement(s>e?"beforebegin":"afterend",o.containerEl),a.recomputeChildrenDimensions(),o.onResize(),this.app.workspace.onLayoutChange(),this.app.workspace.activeLeaf=null,this.app.workspace.setActiveLeaf(o,!1,!0))}}};function Re(i,r,e,t){return t&&(e+=i.indexOf(r),e=(e+i.length)%i.length),i[e>=i.length?i.length-1:e]}