13 lines
187 KiB
JavaScript
13 lines
187 KiB
JavaScript
/*
|
|||
|
|
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
|
||
|
|
if you want to view the source, please visit the github repository of this plugin
|
||
|
|
https://github.com/aisahpA/obsidian-position-restore
|
||
|
|
*/
|
||
|
|
|
||
|
|
"use strict";var rt=Object.defineProperty;var an=Object.getOwnPropertyDescriptor;var ln=Object.getOwnPropertyNames;var dn=Object.prototype.hasOwnProperty;var cn=(r,e)=>{for(var t in e)rt(r,t,{get:e[t],enumerable:!0})},pn=(r,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of ln(e))!dn.call(r,n)&&n!==t&&rt(r,n,{get:()=>e[n],enumerable:!(i=an(e,n))||i.enumerable});return r};var hn=r=>pn(rt({},"__esModule",{value:!0}),r);var os={};cn(os,{default:()=>tt});module.exports=hn(os);var it=require("obsidian");var Wt=require("obsidian");var ie=require("obsidian");var Dt=require("obsidian");var st={"lastPosition.heading":"Last position","lastPosition.intro":"Every note remembers where its cursor sat and how far it was scrolled, and opening it again lands on that spot, with no flash at the top first and no jump afterwards.","openAndRestore.heading":"Open & restore","openAndRestore.linkOpenPosition.name":"When opening from a link","openAndRestore.linkOpenPosition.desc":"When you click a wikilink with no # heading or ^ block target: open at the file start, or return to the saved position. A link that names a target is landed by Obsidian itself, on the spot you clicked, and is out of reach here; other ways of opening (file explorer, search results, bookmarks, quick switcher) are unaffected too and land on the saved position.","openAndRestore.linkOpenPosition.options.start":"File start","openAndRestore.linkOpenPosition.options.restore":"Saved position","openAndRestore.restoreBreadcrumb.name":"Name the restored section","openAndRestore.restoreBreadcrumb.desc":"After a position is restored, briefly show the heading path of where you landed, but only when no heading is visible on screen. Nothing is shown when a heading is already in view (you can see where you are), when the note has only one heading, or when the note has exactly one level-1 heading, which is usually just the note title and already on the tab.","openAndRestore.flashLandingLine.name":"Mark the landing line","openAndRestore.flashLandingLine.desc":"Mark where you land: after a restore or back/forward, editing view marks the cursor line. In reading view, only a jump to a section marks that section.","recordingRules.heading":"Recording rules","recordingRules.folders.name":"Excluded folders","recordingRules.folders.desc":"Don't record the cursor/scroll position for files in these folders and their subfolders.","recordingRules.folders.list.empty":"No folders excluded","recordingRules.folders.add":"Add folder","recordingRules.folders.search.placeholder":"Type to search folders...","recordingRules.folders.search.empty":"No folders found","recordingRules.minLinesToRecord.name":"Do not record files shorter than","recordingRules.minLinesToRecord.desc":`Don't record the cursor/scroll position for a note with fewer lines than this value; views other than a note are not measured by line count. Set to "0" to disable this filter.`,"recordingRules.frontmatterExclude.name":"Exclude by frontmatter property/value","recordingRules.frontmatterExclude.desc":"Exclude a whole class of notes by frontmatter: a file matching any entry in the list is not recorded.","recordingRules.frontmatterExclude.formName":"A property name on its own (`status`): any file carrying the property is skipped, whatever its value.","recordingRules.frontmatterExclude.formValue":"A name with a value (`status: archived`): only files whose value equals it are skipped. yes/no/on/off compare as booleans; an array matches when any one element does.","recordingRules.frontmatterExclude.list.empty":"No properties excluded","recordingRules.frontmatterExclude.add":"Add property","recordingRules.frontmatterExclude.search.placeholder":"Type to search properties...","recordingRules.frontmatterExclude.search.empty":"No properties found","recordingRules.frontmatterExclude.value.title":"Exclude when {0} equals","recordingRules.frontmatterExclude.value.name":"Value","recordingRules.frontmatterExclude.value.desc":"Leave empty to exclude any file that has this property, whatever its value.","recordingRules.frontmatterExclude.v
|
||
|
|
`)),s=_n(n,i);s.length!==0&&(this.hasVisibleHeading(e,n)||(this.removeChip(),this.showChip(e,s),this.shownAt=Date.now(),this.hideTimer=window.setTimeout(()=>this.hide(),In)))}flashLine(e,t){if(!this.settings.flashLandingLine)return;if(e.getMode()==="preview"){let s=this.previewLineElement(e,t);s&&this.flash(s);return}let i=e.editor.cm,n=i?this.sourceLineElement(i,t):null;n&&this.flash(n)}dismissOnMove(){this.chip&&(Date.now()-this.shownAt<Hn||this.hide())}hide(){this.clearHideTimer();let e=this.chip;e&&(this.chip=null,e.setCssStyles({opacity:"0"}),e.animate([{opacity:1},{opacity:0}],{duration:200,easing:"ease-in",fill:"forwards"}),window.setTimeout(()=>e.remove(),220))}hasVisibleHeading(e,t){if(t.length===0)return!1;if(e.getMode()==="preview"){let c=x(e);if(!c)return!1;let p=c.getBoundingClientRect();for(let h of Array.from(c.querySelectorAll("h1, h2, h3, h4, h5, h6"))){let f=h.getBoundingClientRect();if(f.top<p.bottom&&f.bottom>p.top)return!0}return!1}let i=e.editor.cm,n=x(e);if(!i||!n)return!1;let s=n.getBoundingClientRect();if(s.height<=0)return!1;let o=i.state.doc,a=o.lineAt(i.viewport.from).number,d=o.lineAt(i.viewport.to).number;for(let c of t){let p=c.line+1;if(p<a||p>d)continue;let h=this.sourceLineElement(i,c.line);if(!h)continue;let f=h.getBoundingClientRect();if(f.top<s.bottom&&f.bottom>s.top)return!0}return!1}previewLineElement(e,t){let n=e.previewMode?.renderer?.sections;if(!Array.isArray(n))return null;for(let s of n){let o=s?.start?.line,a=s?.lines;if(!(typeof o!="number"||typeof a!="number")&&t>=o&&t<=o+Math.max(0,a-1))return s.el??null}return null}sourceLineElement(e,t){try{let i=e.state.doc,n=Math.min(Math.max(0,t),i.lines-1)+1,s=e.domAtPos(i.line(n).from);return(s.node.instanceOf(Element)?s.node:s.node.parentElement)?.closest(".cm-line")??null}catch{return null}}flash(e){e.addClass("is-flashing"),window.setTimeout(()=>e.removeClass("is-flashing"),Vn)}showChip(e,t){let i=e.contentEl;getComputedStyle(i).position==="static"&&i.addClass("position-restore-cue-host");let n=i.createDiv({cls:"position-restore-cue"});for(let s=0;s<t.length;s++){s>0&&n.createSpan({text:" / ",cls:"position-restore-cue-sep"});let o=s===t.length-1;n.createSpan({text:t[s],cls:o?"position-restore-cue-seg is-deepest":"position-restore-cue-seg"})}n.setAttribute("title",t.join(" / ")),this.chip=n,n.animate([{opacity:0},{opacity:1}],{duration:150,easing:"ease-out"}),n.setCssStyles({opacity:"1"})}removeChip(){this.clearHideTimer(),this.chip&&(this.chip.remove(),this.chip=null)}clearHideTimer(){this.hideTimer&&(window.clearTimeout(this.hideTimer),this.hideTimer=0)}};var Le=3e3,Te=class{constructor(e){this.injectedOpenLeafIds=new Set;this.lastActiveFilePath=void 0;this.restoreRun=0;this.activeRestores=0;this.inFlightRestoreLeafRuns=new Map;this.noAnchorLeafIds=new Set;this.lastAnchorAt=0;this.lastTouchAt=0;this.lastUserInputAt=0;this.handledLeafIdMap=new Map;this.pendingOpenKind=new Map;this.pendingLinkKindTimeout=0;this.pendingHistoryNav=!1;this.pendingHistoryNavTimeout=0;this.injectedLeafStates=new Map;this.cueSuppressUntil=0;this.searchAnchorUntil=0;this.cover=new Se;this.cue=new Pe(e)}beginLeafRestore(e,t){let i=++this.restoreRun;return this.inFlightRestoreLeafRuns.set(e,{filePath:t,run:i}),i}isCurrentLeafRestore(e,t){let i=this.inFlightRestoreLeafRuns.get(e);return!!i&&i.run===t}isRestoringFile(){return this.activeRestores>0}restoreStarted(){this.activeRestores++}restoreEnded(){this.activeRestores--}isSearchAnchored(){return Date.now()<this.searchAnchorUntil}leafId(e){return Jt(e)}};var vt=require("obsidian");var mi=require("obsidian");var di=require("obsidian");var Bn=3e3,Wn=200,jn=700,gt=800,Un=200,Kn=200,$n=100,ci=1250,Gn=150,pi=1e3,qn=32,Jn=400,hi=1200,Y=class{constructor(e){this.state=e}async relandDriftedScroll(e,t,i){if(!t||!t.scroll||t.scroll<=0)return;let n=t.scroll,s=this.state.lastTouchAt,o=Date.now()+Bn;if(e.getMode()==="source"){await this.relandSourcePixels(e,n,i,s);return}let a=n,d=1/0,c=0,p=Wn;for(;i()&&Date.now()<o;){if(this.state.lastTouchAt>s||!mt(e))return;let h=M(e);if(!h||h.scroll===void 0||h.scroll===n)return;le
|
||
|
|
`))}catch{}this.reading.delete(e),this.heads.set(e,{mtime:i,headings:n}),this.opts.onLateRead?.()}otherNamesFor(e,t){if(!e)return{aliases:[]};let i=this.metaFor(e),n=t?i.aliases.filter(s=>s!==t):i.aliases;return{frontTitle:i.frontTitle===t?void 0:i.frontTitle,aliases:n}}};function ji(r,e){if(!e||!r)return;let t=s=>{let o=Array.isArray(s)?s[0]:s;return typeof o!="string"?void 0:o.trim()||void 0},i=t(r[e]);if(i)return i;let n=e.toLowerCase();for(let s of Object.keys(r))if(s.toLowerCase()===n)return t(r[s])}function yr(r,e,t){let i=e?r.vault.getAbstractFileByPath(e):null,n=i instanceof je.TFile?r.metadataCache?.getFileCache?.(i):null;if(!n)return null;let s=n.headings?.map(p=>({heading:p.heading,level:p.level,line:p.position.start.line})),o=n.frontmatter,a=[],d=new Set,c=p=>{if(typeof p=="string"){let h=p.trim();h&&!d.has(h)&&(d.add(h),a.push(h))}else if(Array.isArray(p))for(let h of p)c(h)};return c(o?.aliases),{headings:s,aliases:a,frontTitle:ji(o,"title"),title:ji(o,t)}}function br(){return{headings:void 0,aliases:[]}}var V=require("obsidian");var Er="";function Ui(r,e,t=()=>!0,i){let n=new Map,s=(a,d)=>{let c=y(a),p={path:a.kind==="view"?Er:a.path,key:c,rep:d,current:d===e};return n.set(c,p),p};for(let a=r.length-1;a>=0;a--){if(!t(a))continue;let d=r[a];n.has(y(d))||s(d,a)}let o=Array.from(n.values());if(i){let a=new Map(i.map((d,c)=>[d,c]));o.sort((d,c)=>(a.get(d.key)??-1)-(a.get(c.key)??-1))}return o}function Ki(r){return r.toLowerCase().split(/\s+/).filter(Boolean)}function Sr(r,e,t,i){let n=Ki(e);if(n.length===0)return!0;let s=`${Pr(r)} ${t??""} ${i??""}`.toLowerCase();return n.every(o=>s.includes(o))}function kr(r,e){let t=r.entries[e];return t.kind==="view"||r.noteExists(t.path)}function Fr(r,e){let t=r.entries[e],i=r.describe(e),n=t.kind==="view"?void 0:r.otherNames(t.path,i.name),s=n?[n.frontTitle??"",...n.aliases]:[];return`${i.name??""} ${s.join(" ")}`}function xr(r,e){if(!r.outlineSearch())return;let t=r.entries[e];if(t.kind==="view")return;let i=r.headingsFor(t.path);return i?.length?i.map(n=>n.heading).join(`
|
||
|
|
`):void 0}function $i(r,e,t){return kr(r,e)?t?Sr(r.entries[e],t,Fr(r,e),xr(r,e)):!0:!1}function Gi(r,e,t){let i=Ki(e);if(!r?.length||!i.length||t!==void 0&&t<=0)return[];let n=[],s=[];for(let a of r){let d=a.heading.toLowerCase();d&&(i.every(c=>d.includes(c))?s.push(a):d.includes(i[0])&&n.push(a))}let o=s.length?s:n;return t===void 0?o:o.slice(0,t)}function Pr(r){return r.kind==="view"?`${r.viewType} ${Lt(r)}`:[Pt(r.path),r.path].filter(Boolean).join(" ")}var Ke=class{constructor(e,t){this.list=e;this.quiet=t;this.tips=new WeakMap;this.held=!1;this.onOver=e=>{if(e.pointerType==="touch"){this.forget();return}if(this.quiet?.()){this.forget();return}let t=this.subject(e.target);if(t===this.anchor||(this.forget(),!t))return;let i=this.tips.get(t);i&&(this.anchor=t,this.timer=this.win.setTimeout(()=>{this.timer=void 0,this.anchor===t&&!this.quiet?.()&&this.show(t,i)},1e3))};this.onOut=e=>{if(this.held)return;let t=e.relatedTarget;this.anchor&&t&&this.anchor.contains(t)||this.forget()};this.onLeave=()=>{this.forget()};this.doc=e.ownerDocument,this.win=this.doc.defaultView??window,this.list.addEventListener("pointerover",this.onOver),this.list.addEventListener("pointerout",this.onOut),this.list.addEventListener("pointerdown",this.onLeave),this.list.addEventListener("scroll",this.onLeave,{passive:!0})}attach(e,t){this.tips.set(e,t)}retract(){this.forget()}speak(e){if(this.quiet?.())return;let t=this.subject(e);if(!t)return;let i=this.tips.get(t);i&&(this.forget(),this.anchor=t,this.held=!0,this.show(t,i))}reset(){this.forget()}destroy(){this.forget(),this.list.removeEventListener("pointerover",this.onOver),this.list.removeEventListener("pointerout",this.onOut),this.list.removeEventListener("pointerdown",this.onLeave),this.list.removeEventListener("scroll",this.onLeave)}subject(e){let t=e&&e.nodeType===1?e:e?.parentElement??null;for(;t&&t!==this.list;){if(this.tips.has(t))return t;t=t.parentElement}}forget(){this.clearTimer(),this.hide(),this.anchor=void 0,this.held=!1}clearTimer(){this.timer!==void 0&&(this.win.clearTimeout(this.timer),this.timer=void 0)}hide(){this.el?.remove(),this.el=void 0}show(e,t){let i=this.doc.body.createDiv({cls:"position-restore-nav-tip",attr:{"aria-hidden":"true"}});t.path&&this.pathLine(i,t.path),t.frontTitle&&i.createDiv({cls:"nav-tip-text",text:t.frontTitle}),t.text&&i.createDiv({cls:"nav-tip-text",text:t.text}),t.trail&&i.createDiv({cls:"nav-tip-trail",text:t.trail}),this.el=i,this.place(i,e)}pathLine(e,t){let i=e.createDiv({cls:"nav-tip-path"}),n=t.split("/");n.forEach((s,o)=>{o>0&&i.createSpan({cls:"nav-tip-sep",text:"/"}),s&&i.createSpan({cls:o===n.length-1?"nav-tip-name":"nav-tip-seg",text:s})})}place(e,t){let i=t.getBoundingClientRect(),n=e.getBoundingClientRect(),s={w:this.win.innerWidth,h:this.win.innerHeight},o=i.bottom+6;o+n.height>s.h&&(o=Math.max(6,i.top-6-n.height));let a=i.left;a+n.width>s.w&&(a=s.w-n.width-6),e.setCssStyles({top:`${Math.round(o)}px`,left:`${Math.round(Math.max(6,a))}px`})}};var $e=class{constructor(e,t){this.el=e;this.opts=t;this.claimed=!1;this.onDown=e=>{if(this.cancel(),this.claimed=!1,e.button!==0)return;this.at={x:e.clientX,y:e.clientY};let t=e.target instanceof Node?e.target:this.el;this.timer=this.win.setTimeout(()=>{this.timer=void 0,this.at=void 0,this.opts.onArm(t)},this.opts.ms)};this.onMove=e=>{this.at&&(Math.abs(e.clientX-this.at.x)>this.opts.slop||Math.abs(e.clientY-this.at.y)>this.opts.slop)&&this.cancel()};this.onEnd=()=>{this.cancel()};this.win=e.ownerDocument.defaultView??window,this.el.addEventListener("pointerdown",this.onDown),this.el.addEventListener("pointermove",this.onMove),this.el.addEventListener("pointerup",this.onEnd),this.el.addEventListener("pointercancel",this.onEnd)}destroy(){this.cancel(),this.el.removeEventListener("pointerdown",this.onDown),this.el.removeEventListener("pointermove",this.onMove),this.el.removeEventListener("pointerup",this.onEnd),this.el.removeEventListener("pointercancel",this.onEnd)}markArmed(){this.claimed=!0}consumeClick(){let e=this.claimed;return this.claimed=!1,e}release(){this.cancel(),this.claimed=!1}cance
|
||
|
|
module.exports = module.exports.default || module.exports;
|
||
|
|
|
||
|
|
/* nosourcemap */
|