yanki 2.0.12 → 2.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lib/index.js CHANGED
@@ -576,27 +576,26 @@ function getBaseAndQueryParts(filePath) {
576
576
  return [path.join(directoryPath, base), query];
577
577
  }
578
578
  /**
579
- * Get every plausible base and anchor interpretation of a file path whose name
580
- * may contain anchor delimiter characters (`#`, `^`), ordered from the longest
581
- * literal file name (no anchor at all) to the shortest (anchor starts at the
582
- * first delimiter in the file name, matching Obsidian's anchor syntax).
583
- * Delimiters in directory names are never treated as anchor starts.
584
- *
585
- * File names may legitimately contain these characters, so callers should try
586
- * candidates in order against a list of real files instead of assuming the
587
- * first delimiter starts an anchor.
579
+ * Get every plausible base and anchor interpretation of a local link target
580
+ * that may contain anchor delimiter characters (`#`, `^`), ordered from the
581
+ * longest literal path (no anchor at all) to the shortest (anchor starts at the
582
+ * first delimiter, matching Obsidian's anchor syntax).
583
+ *
584
+ * This operates on the unnormalized link target and deliberately considers
585
+ * delimiters before slashes. A slash after a delimiter belongs to the anchor,
586
+ * not the file path. File and directory names may also legitimately contain
587
+ * these characters, so callers must normalize only each candidate's `filePath`
588
+ * and try candidates in order against a list of real files.
588
589
  * https://github.com/kitschpatrol/yanki/issues/20
589
590
  */
590
- function getBaseAndQueryCandidates(filePath) {
591
- const directoryPath = path.dirname(filePath);
592
- const fileName = path.basename(filePath);
591
+ function getLocalPathCandidates(linkTarget) {
593
592
  const candidates = [{
594
- base: path.join(directoryPath, fileName),
595
- query: void 0
593
+ anchor: void 0,
594
+ filePath: linkTarget
596
595
  }];
597
- for (let index = fileName.length - 1; index >= 0; index--) if (QUERY_FRAGMENT_START_REGEX.test(fileName.charAt(index))) candidates.push({
598
- base: path.join(directoryPath, fileName.slice(0, index)),
599
- query: fileName.slice(index)
596
+ for (let index = linkTarget.length - 1; index >= 0; index--) if (QUERY_FRAGMENT_START_REGEX.test(linkTarget.charAt(index))) candidates.push({
597
+ anchor: linkTarget.slice(index),
598
+ filePath: linkTarget.slice(0, index)
600
599
  });
601
600
  return candidates;
602
601
  }
@@ -1813,48 +1812,25 @@ const defaultResolveLinkOptions = {
1813
1812
  * parameters)
1814
1813
  */
1815
1814
  function resolveLink(filePathOrUrl, options) {
1816
- const { allFilePaths, basePath, convertFilePathsToProtocol, cwd, obsidianVaultName, type } = deepmerge(defaultResolveLinkOptions, options ?? {});
1815
+ const resolvedOptions = deepmerge(defaultResolveLinkOptions, options ?? {});
1816
+ const { allFilePaths, convertFilePathsToProtocol, cwd, obsidianVaultName } = resolvedOptions;
1817
1817
  if (convertFilePathsToProtocol === "obsidian" && obsidianVaultName === void 0) console.warn(`convertFilePathsToProtocol is 'obsidian', but no obsidianVaultName provided`);
1818
- let currentPathOrUrl = filePathOrUrl;
1819
- for (;;) {
1820
- const decodedUrl = safeDecodeURI(currentPathOrUrl) ?? currentPathOrUrl;
1821
- const sourceType = getSrcType(decodedUrl);
1822
- if (sourceType === "localFileName") {
1823
- const resolvedUrl = resolveNameLink(normalize(decodedUrl), cwd, allFilePaths ?? []) ?? resolveWithBasePath(decodedUrl, {
1824
- basePath,
1825
- cwd
1826
- });
1827
- if (getSrcType(resolvedUrl) === "localFilePath") {
1828
- currentPathOrUrl = resolvedUrl;
1829
- continue;
1830
- }
1831
- console.warn(`Failed to convert local file wiki-style name to path: ${currentPathOrUrl} --> ${resolvedUrl}`);
1832
- return resolvedUrl;
1833
- }
1834
- if (sourceType === "localFileUrl") {
1835
- const resolvedUrl = normalize(fileUrlToPath(currentPathOrUrl));
1836
- if (getSrcType(resolvedUrl) === "localFilePath") {
1837
- currentPathOrUrl = resolvedUrl;
1838
- continue;
1839
- }
1840
- console.warn(`Failed to convert file URL to path: ${currentPathOrUrl} --> ${resolvedUrl}`);
1841
- return resolvedUrl;
1818
+ const decodedUrl = safeDecodeURI(filePathOrUrl) ?? filePathOrUrl;
1819
+ switch (getSrcType(decodedUrl)) {
1820
+ case "localFileName": {
1821
+ const resolvedNameLink = resolveNameLink(decodedUrl, cwd, allFilePaths ?? []);
1822
+ return resolvedNameLink === void 0 ? resolveLocalFilePath(decodedUrl, resolvedOptions) : resolveMatchedLocalLink(resolvedNameLink, resolvedOptions);
1842
1823
  }
1843
- switch (sourceType) {
1844
- case "localFilePath": return resolveLocalFilePath(decodedUrl, {
1845
- allFilePaths,
1846
- basePath,
1847
- convertFilePathsToProtocol,
1848
- cwd,
1849
- obsidianVaultName,
1850
- type
1851
- });
1852
- case "obsidianVaultUrl": return currentPathOrUrl;
1853
- case "remoteHttpUrl": return currentPathOrUrl;
1854
- case "unsupportedProtocolUrl":
1855
- console.warn(`Unsupported URL protocol: ${currentPathOrUrl}`);
1856
- return currentPathOrUrl;
1824
+ case "localFilePath": return resolveLocalFilePath(decodedUrl, resolvedOptions);
1825
+ case "localFileUrl": {
1826
+ const encodedFilePath = fileUrlToPath(filePathOrUrl);
1827
+ return resolveLocalFilePath(safeDecodeURI(encodedFilePath) ?? encodedFilePath, resolvedOptions);
1857
1828
  }
1829
+ case "obsidianVaultUrl":
1830
+ case "remoteHttpUrl": return filePathOrUrl;
1831
+ case "unsupportedProtocolUrl":
1832
+ console.warn(`Unsupported URL protocol: ${filePathOrUrl}`);
1833
+ return filePathOrUrl;
1858
1834
  }
1859
1835
  }
1860
1836
  /**
@@ -1863,28 +1839,33 @@ function resolveLink(filePathOrUrl, options) {
1863
1839
  * `max-depth` lint rule).
1864
1840
  */
1865
1841
  function resolveLocalFilePath(decodedUrl, options) {
1866
- const { allFilePaths, basePath, convertFilePathsToProtocol, cwd, obsidianVaultName, type } = options;
1867
- const resolvedUrl = resolveWithBasePath(normalize(decodedUrl), {
1842
+ const { allFilePaths, basePath, cwd } = options;
1843
+ const candidates = getLocalPathCandidates(decodedUrl);
1844
+ for (const { anchor, filePath } of candidates) {
1845
+ const resolvedBase = resolveWithBasePath(normalize(filePath), {
1846
+ basePath,
1847
+ cwd
1848
+ });
1849
+ const matchedPath = (path.extname(resolvedBase) === "" ? [`${resolvedBase}.md`] : [resolvedBase, `${resolvedBase}.md`]).find((candidate) => pathExistsInAllFiles(candidate, allFilePaths ?? []));
1850
+ if (matchedPath !== void 0) return resolveMatchedLocalLink({
1851
+ anchor,
1852
+ filePath: matchedPath
1853
+ }, options);
1854
+ }
1855
+ return resolveWithBasePath(normalize(candidates.at(-1)?.filePath ?? decodedUrl), {
1868
1856
  basePath,
1869
1857
  cwd
1870
1858
  });
1871
- let matchedPath;
1872
- let matchedQuery;
1873
- for (const { base, query } of getBaseAndQueryCandidates(resolvedUrl)) {
1874
- matchedPath = (path.extname(base) === "" ? [`${base}.md`] : [base, `${base}.md`]).find((candidate) => pathExistsInAllFiles(candidate, allFilePaths ?? []));
1875
- if (matchedPath !== void 0) {
1876
- matchedQuery = query;
1877
- break;
1878
- }
1879
- }
1880
- if (matchedPath !== void 0) {
1881
- if (convertFilePathsToProtocol !== "none" && (type === "link" || type === "embed" && [".md", ".pdf"].includes(path.extname(matchedPath)))) {
1882
- if (convertFilePathsToProtocol === "obsidian" && obsidianVaultName !== void 0) return createObsidianVaultLink(`${matchedPath}${matchedQuery ?? ""}`, basePath ?? "", obsidianVaultName);
1883
- if (convertFilePathsToProtocol === "file") return createFileLink(`${matchedPath}${matchedQuery ?? ""}`);
1884
- }
1885
- return matchedPath;
1859
+ }
1860
+ /** Render a matched local file and its still-unmodified Obsidian anchor. */
1861
+ function resolveMatchedLocalLink(link, options) {
1862
+ const { anchor, filePath } = link;
1863
+ const { basePath, convertFilePathsToProtocol, obsidianVaultName, type } = options;
1864
+ if (convertFilePathsToProtocol !== "none" && (type === "link" || type === "embed" && [".md", ".pdf"].includes(path.extname(filePath)))) {
1865
+ if (convertFilePathsToProtocol === "obsidian" && obsidianVaultName !== void 0) return createObsidianVaultLink(link, basePath ?? "", obsidianVaultName);
1866
+ if (convertFilePathsToProtocol === "file") return createFileLink(`${filePath}${anchor ?? ""}`);
1886
1867
  }
1887
- return getBase(resolvedUrl);
1868
+ return filePath;
1888
1869
  }
1889
1870
  /**
1890
1871
  * Convert from a (usually wiki-style) named link to an absolute path to an
@@ -1904,14 +1885,18 @@ function resolveLocalFilePath(decodedUrl, options) {
1904
1885
  * @param allFilePaths Array of absolute paths to all other files in the paths
1905
1886
  * to be considered. (POSIX-style paths.)
1906
1887
  *
1907
- * @returns Absolute path to the best matching file with the name provided, or
1908
- * undefined if there's no valid match. (POSIX-style paths.)
1888
+ * @returns The absolute path to the best matching file and its unmodified
1889
+ * anchor, or undefined if there's no valid match. (POSIX-style path.)
1909
1890
  */
1910
1891
  function resolveNameLink(name, cwd, allFilePaths) {
1911
1892
  if (allFilePaths.length === 0) return;
1912
- for (const { base, query } of getBaseAndQueryCandidates(name)) {
1913
- const match = findBestNameMatch(path.extname(base) === "" ? `${base}.md` : base, cwd, allFilePaths);
1914
- if (match !== void 0) return `${match}${query ?? ""}`;
1893
+ for (const { anchor, filePath } of getLocalPathCandidates(name)) {
1894
+ const normalizedBase = normalize(filePath);
1895
+ const match = findBestNameMatch(path.extname(normalizedBase) === "" ? `${normalizedBase}.md` : normalizedBase, cwd, allFilePaths);
1896
+ if (match !== void 0) return {
1897
+ anchor,
1898
+ filePath: match
1899
+ };
1915
1900
  }
1916
1901
  }
1917
1902
  /**
@@ -1965,9 +1950,9 @@ function pathExistsInAllFiles(filePath, allFilePaths) {
1965
1950
  function createFileLink(absolutePath) {
1966
1951
  return `file://${absolutePath}`;
1967
1952
  }
1968
- function createObsidianVaultLink(absolutePath, basePath, obsidianVault) {
1969
- const relativePath = stripBasePath(absolutePath, basePath);
1970
- return `obsidian://open?vault=${encodeURIComponent(obsidianVault)}&file=${encodeURIComponent(relativePath)}`;
1953
+ function createObsidianVaultLink(link, basePath, obsidianVault) {
1954
+ const linkPath = `${stripBasePath(link.filePath, basePath)}${link.anchor ?? ""}`;
1955
+ return `obsidian://open?vault=${encodeURIComponent(obsidianVault)}&file=${encodeURIComponent(linkPath)}`;
1971
1956
  }
1972
1957
  //#endregion
1973
1958
  //#region src/lib/parse/remark-resolve-links.ts
@@ -971,7 +971,7 @@ var n=Hb().isPrimitive;function r(e){var t,r;return!n(e)||(r=e.length,r===0)?!1:
971
971
  * See the License for the specific language governing permissions and
972
972
  * limitations under the License.
973
973
  */
974
- var n=xb(),r=Cb(),i=Ub(),a=Wb(),o=r?a:i;n(o,`posix`,i),n(o,`win32`,a),t.exports=o}))(),1);function Kb(e){return e.startsWith(`\\\\?\\`)?e:e.replace(/\\/g,`/`)}const qb=RegExp(`^[A-Z]:`,`iv`),Jb=RegExp(`[#^]`,`v`);function Yb(e){return Gb.default.posix(e)||Gb.default.win32(e)}const Xb=RegExp(`^\\\\\\\\\\?\\\\.+`,`v`);function Zb(e){if(Xb.test(e))return console.warn(`Unsupported extended length path detected: ${e}`),e;let t=Kb(e),n=q.normalize(t);return t.startsWith(`./`)?`./${n}`:n}function Qb(e,t){let{basePath:n,compoundBase:r=!1,cwd:i}=t;return n!==void 0&&(Yb(n)||console.warn(`Base path "${n}" is not absolute`),i.startsWith(n)||console.warn(`CWD "${i}" does not start with base path "${n}"`)),Yb(i)||console.warn(`CWD "${i}" is not absolute`),Yb(e)?n===void 0||qb.test(e)||!r&&e.startsWith(n)?e:q.join(n,e):q.join(i,e)}function $b(e,t){return e.toLowerCase().startsWith(t.toLowerCase())?e.slice(t.length):e}function ex(e){let t=q.dirname(e),[n,r]=ly(q.basename(e),Jb);return[q.join(t,n),r]}function tx(e){let t=q.dirname(e),n=q.basename(e),r=[{base:q.join(t,n),query:void 0}];for(let e=n.length-1;e>=0;e--)Jb.test(n.charAt(e))&&r.push({base:q.join(t,n.slice(0,e)),query:n.slice(e)});return r}function nx(e){return ex(e)[0]}function rx(e){return ex(e).at(1)??``}const ix=RegExp(`^[a-z]:`,`iv`),ax=RegExp(`^file:`,`iv`);function ox(e){try{return decodeURI(e)}catch(t){console.warn(`Error decoding URI text: "${e}"`,t);return}}function sx(e){try{let t=new URL(e);return(ax.test(t.protocol)||ix.test(t.protocol))&&!ax.test(e)?void 0:t}catch{return}}function cx(e){return sx(e)!==void 0}function lx(e){let t=sx(e);return t?.protocol===`file:`?t.pathname:e}function ux(e){let t=sx(e);if(t===void 0){let t=Zb(e);return Yb(t)||t.startsWith(`./`)||t.startsWith(`../`)?`localFilePath`:`localFileName`}return t.protocol===`file:`?`localFileUrl`:t.protocol===`obsidian:`?`obsidianVaultUrl`:t.protocol===`http:`||t.protocol===`https:`?`remoteHttpUrl`:`unsupportedProtocolUrl`}function dx(e,t){if(e===void 0)return;e instanceof Headers||(e=fx(e));let n=(e instanceof Headers?t.map(t=>e.get(t)):t.map(t=>e[t])).filter(e=>e!=null).join(``);if(n!==``)return n}function fx(e){let t={};for(let[n,r]of Object.entries(e))t[n.toLowerCase()]=r;return t}async function px(e,t){try{return(await t(e,{method:`HEAD`}))?.status===200}catch{return!1}}async function mx(e,t,n=`metadata`){if(n===`metadata`&&t!==void 0)try{let n=dx((await t(e,{method:`HEAD`}))?.headers,[`content-type`]);if(n===void 0)throw Error(`No content-type header found`);let r=tb(n);if(r!==void 0)return r}catch{}let r=sx(e);if(r===void 0){console.warn(`Could not parse URL: ${e}`);return}let i,a=r.pathname.split(`.`);if(i=a.length>1?a.at(-1):r.search.split(`.`).at(-1),vy.includes(i??``))return i}async function hx(e,t,n=`metadata`){if(n===`content`&&console.warn("`content` hash mode is not yet implemented for URLs"),n!==`name`)try{let n=dx((await t(e,{method:`HEAD`}))?.headers,[`etag`,`last-modified`,`content-length`]);if(n===void 0)throw Error(`No headers found`);return ey(n,16)}catch{}return ey(e,16)}const gx={"ftp:":21,"http:":80,"https:":443,"ws:":80,"wss:":443};function _x(e){let t=sx(e);if(t!==void 0)return{host:`${t.protocol}//${t.hostname}`,port:t.port===``?gx[t.protocol]??NaN:Number(t.port)}}function vx(e,t){return`${e}:${t}`}async function yx(e,t){let n=cx(e)?await mx(e,t):q.extname(e).slice(1);if(!(n===void 0||!vy.includes(n)))return n}async function bx(e,t,n){return cx(e)?px(e,n):Ky(e,t)}async function xx(e,t,n,r,i){if(!await bx(e,r,i))return;let a=eb(t),o=await Sx(e,r,i),s=n===void 0?``:`.${n}`,c;if(c=`${a}-${o}${s}`,c.length>120)throw Error(`Filename too long: ${c}`);return c}async function Sx(e,t,n){return cx(e)?hx(e,n):qy(e,t)}const Cx=RegExp(`([\\{\\}])(?=[\\{\\}])`,`gv`);function wx(e){return e.replaceAll(Cx,`$1 `)}const Tx=function(){return function(e){let t=!1;A(e,(e,n,r)=>{if(r===void 0||n===void 0||e.type!==`element`)return!0;let[i]=e.children;if(e.tagName===`pre`&&e.children.length===1&&i?.type===`element`&&i.tagName===`code`&&Array.isArray(i.properties.className)&&i.properties.className.includes(`language-math`)&&(t=!0,r.children[n]=i),e.tagName===`code`&&Array.isArray(e.properties.className)&&e.properties.className.includes(`language-math`)){let n=e.properties.className.includes(`math-display`)||t;t=!1;for(let t of e.children)t.type===`text`&&(t.value=wx(t.value));e.tagName=n?`div`:`span`,e.children=[{type:`text`,value:n?String.raw`\[`:String.raw`\(`},...e.children,{type:`text`,value:n?String.raw`\]`:String.raw`\)`}]}return!0})}};function Ex(e,t,n){let r=jo((n||{}).ignore||[]),i=Dx(t),a=-1;for(;++a<i.length;)Vo(e,`text`,o);function o(e,t){let n=-1,i;for(;++n<t.length;){let e=t[n],a=i?i.children:void 0;if(r(e,a?a.indexOf(e):void 0,i))return;i=e}if(i)return s(e,t)}function s(e,t){let n=t[t.length-1],r=i[a][0],o=i[a][1],s=0,c=n.children.indexOf(e),l=!1,u=[];r.lastIndex=0;let d=r.exec(e.value);for(;d;){let n=d.index,i={index:d.index,input:d.input,stack:[...t,e]},a=o(...d,i);if(typeof a==`string`&&(a=a.length>0?{type:`text`,value:a}:void 0),a===!1?r.lastIndex=n+1:(s!==n&&u.push({type:`text`,value:e.value.slice(s,n)}),Array.isArray(a)?u.push(...a):a&&u.push(a),s=n+d[0].length,l=!0),!r.global)break;d=r.exec(e.value)}return l?(s<e.value.length&&u.push({type:`text`,value:e.value.slice(s)}),n.children.splice(c,1,...u)):u=[e],c+u.length}}function Dx(e){let t=[];if(!Array.isArray(e))throw TypeError(`Expected find and replace tuple or list of tuples`);let n=!e[0]||Array.isArray(e[0])?e:[e],r=-1;for(;++r<n.length;){let e=n[r];t.push([Ox(e[0]),kx(e[1])])}return t}function Ox(e){return typeof e==`string`?new RegExp(Ey(e),`g`):e}function kx(e){return typeof e==`function`?e:function(){return e}}function Ax(e){Ex(e,[/\r?\n|\r/g,jx])}function jx(){return{type:`break`}}function Mx(){return function(e){Ax(e)}}const Nx=function(){return function(e,t){if(t.data.strictLineBreaks===!1){Mx()(e);return}return e}},Px=RegExp(`^[\\dx]+$`,`v`),Fx=Ao({engine:kv(),langs:[Ee,De,Fe,Ie,Le,Re,ze,He,Ue,Be,We,Ge,Ke,qe,Ze,Qe,Oe,lt,ut,ft,Ee,je,pt,mt,nt,tt,Ye,st],themes:[Xo,Zo]}),Ix=Rv().use(Nx).use(ih,{allowDangerousHtml:!0}).use(em).use(Tx).use(Yo,Fx,{defaultLanguage:`plaintext`,fallbackLanguage:`plaintext`,themes:{dark:`github-dark`,light:`github-light`}}).use(nc).use(tm),Lx={...Cy};async function Rx(e,t){if(e===void 0)return``;let{cssClassNames:n,fetchAdapter:r=Ty(),fileAdapter:i=await wy(),namespace:a,strictLineBreaks:o,syncMediaAssets:s,useEmptyPlaceholder:c}=w(Lx,t??{}),l=await Ix.run(e,{data:{strictLineBreaks:o}}),u=K(`root`,[K(`element`,{properties:{className:n?.map(e=>ry(e))},tagName:`div`},l.children)]),d=[];A(u,`element`,(e,t,n)=>{if(n===void 0||t===void 0||e.tagName!==`img`)return!0;if(typeof e.properties.src!=`string`||e.properties?.src?.trim().length===0)return console.warn(`Image has no src`),!0;let o,c=ux(e.properties.src);switch(c){case`localFilePath`:if(o=ox(e.properties.src),o===void 0)return!0;o=nx(o);break;case`unsupportedProtocolUrl`:case`localFileName`:console.warn(`Unsupported URL for media asset, treating as link: "${e.properties.src}"`),o=e.properties.src;break;case`obsidianVaultUrl`:case`localFileUrl`:o=e.properties.src;break;case`remoteHttpUrl`:o=e.properties.src;break}return d.push(async()=>{let l=await yx(o,c===`obsidianVaultUrl`?void 0:r),u=l!==void 0&&c!==`unsupportedProtocolUrl`&&c!==`localFileName`&&c!==`obsidianVaultUrl`&&c!==`localFileUrl`,d=(c===`localFilePath`&&s===`local`||c===`remoteHttpUrl`&&s===`remote`||s===`all`)&&u,f=d?await xx(o,a,l,i,r):void 0,p=f??o,m=d&&f!==void 0?`true`:`false`;if(!u||_y.includes(l)){let r=cx(p)?p:`${p}${rx(String(e.properties.dataYankiSrcOriginal))}`;n.children[t]=K(`element`,{properties:{className:[`yanki-media`,`yanki-media-${u?`file`:`unsupported`}`],"data-yanki-alt-text":e.properties.alt,"data-yanki-media-src":o,"data-yanki-media-sync":m,"data-yanki-src":p,"data-yanki-src-original":e.properties.dataYankiSrcOriginal},tagName:`span`},[K(`element`,{properties:{href:r},tagName:`a`},[K(`text`,decodeURI(String(e.properties.dataYankiSrcOriginal)))])])}else hy.includes(l)?(e.properties.src=p,e.properties.className=[`yanki-media`,`yanki-media-image`],e.properties.dataYankiMediaSrc=o,e.properties.dataYankiMediaSync=m):gy.includes(l)&&(n.children[t]=K(`element`,{properties:{className:[`yanki-media`,`yanki-media-audio-video`],"data-yanki-alt-text":e.properties.alt,"data-yanki-media-src":o,"data-yanki-media-sync":m,"data-yanki-src":p,"data-yanki-src-original":e.properties.dataYankiSrcOriginal},tagName:`span`},[K(`text`,`[sound:${p}]`)]))}),!0});for(let e of d)await e();A(u,`element`,(e,t,n)=>{if(n===void 0||t===void 0||e.tagName!==`img`||iy(String(e.properties.alt))===void 0)return!0;let{alt:r,height:i,width:a}=Kx(e.properties.alt??``);return r===void 0?delete e.properties.alt:e.properties.alt=r,i!==void 0&&(e.properties.height=i),a!==void 0&&(e.properties.width=a),!0});let f=Jx(u);if(f&&!c)return``;let p=f?Yx(u,py):u;return Bx(Ix.stringify(p)).trim()}const zx=Rv().use(ap,{fragment:!0});function Bx(e){return`<!-- This HTML was generated by Yanki, a Markdown to Anki converter. Do not edit directly. -->\n${e}`}function Vx(e){return ms(e)}function Hx(e){return Vx(zx.parse(e))}function Ux(e){return Hx(e).split(`
974
+ var n=xb(),r=Cb(),i=Ub(),a=Wb(),o=r?a:i;n(o,`posix`,i),n(o,`win32`,a),t.exports=o}))(),1);function Kb(e){return e.startsWith(`\\\\?\\`)?e:e.replace(/\\/g,`/`)}const qb=RegExp(`^[A-Z]:`,`iv`),Jb=RegExp(`[#^]`,`v`);function Yb(e){return Gb.default.posix(e)||Gb.default.win32(e)}const Xb=RegExp(`^\\\\\\\\\\?\\\\.+`,`v`);function Zb(e){if(Xb.test(e))return console.warn(`Unsupported extended length path detected: ${e}`),e;let t=Kb(e),n=q.normalize(t);return t.startsWith(`./`)?`./${n}`:n}function Qb(e,t){let{basePath:n,compoundBase:r=!1,cwd:i}=t;return n!==void 0&&(Yb(n)||console.warn(`Base path "${n}" is not absolute`),i.startsWith(n)||console.warn(`CWD "${i}" does not start with base path "${n}"`)),Yb(i)||console.warn(`CWD "${i}" is not absolute`),Yb(e)?n===void 0||qb.test(e)||!r&&e.startsWith(n)?e:q.join(n,e):q.join(i,e)}function $b(e,t){return e.toLowerCase().startsWith(t.toLowerCase())?e.slice(t.length):e}function ex(e){let t=q.dirname(e),[n,r]=ly(q.basename(e),Jb);return[q.join(t,n),r]}function tx(e){let t=[{anchor:void 0,filePath:e}];for(let n=e.length-1;n>=0;n--)Jb.test(e.charAt(n))&&t.push({anchor:e.slice(n),filePath:e.slice(0,n)});return t}function nx(e){return ex(e)[0]}function rx(e){return ex(e).at(1)??``}const ix=RegExp(`^[a-z]:`,`iv`),ax=RegExp(`^file:`,`iv`);function ox(e){try{return decodeURI(e)}catch(t){console.warn(`Error decoding URI text: "${e}"`,t);return}}function sx(e){try{let t=new URL(e);return(ax.test(t.protocol)||ix.test(t.protocol))&&!ax.test(e)?void 0:t}catch{return}}function cx(e){return sx(e)!==void 0}function lx(e){let t=sx(e);return t?.protocol===`file:`?t.pathname:e}function ux(e){let t=sx(e);if(t===void 0){let t=Zb(e);return Yb(t)||t.startsWith(`./`)||t.startsWith(`../`)?`localFilePath`:`localFileName`}return t.protocol===`file:`?`localFileUrl`:t.protocol===`obsidian:`?`obsidianVaultUrl`:t.protocol===`http:`||t.protocol===`https:`?`remoteHttpUrl`:`unsupportedProtocolUrl`}function dx(e,t){if(e===void 0)return;e instanceof Headers||(e=fx(e));let n=(e instanceof Headers?t.map(t=>e.get(t)):t.map(t=>e[t])).filter(e=>e!=null).join(``);if(n!==``)return n}function fx(e){let t={};for(let[n,r]of Object.entries(e))t[n.toLowerCase()]=r;return t}async function px(e,t){try{return(await t(e,{method:`HEAD`}))?.status===200}catch{return!1}}async function mx(e,t,n=`metadata`){if(n===`metadata`&&t!==void 0)try{let n=dx((await t(e,{method:`HEAD`}))?.headers,[`content-type`]);if(n===void 0)throw Error(`No content-type header found`);let r=tb(n);if(r!==void 0)return r}catch{}let r=sx(e);if(r===void 0){console.warn(`Could not parse URL: ${e}`);return}let i,a=r.pathname.split(`.`);if(i=a.length>1?a.at(-1):r.search.split(`.`).at(-1),vy.includes(i??``))return i}async function hx(e,t,n=`metadata`){if(n===`content`&&console.warn("`content` hash mode is not yet implemented for URLs"),n!==`name`)try{let n=dx((await t(e,{method:`HEAD`}))?.headers,[`etag`,`last-modified`,`content-length`]);if(n===void 0)throw Error(`No headers found`);return ey(n,16)}catch{}return ey(e,16)}const gx={"ftp:":21,"http:":80,"https:":443,"ws:":80,"wss:":443};function _x(e){let t=sx(e);if(t!==void 0)return{host:`${t.protocol}//${t.hostname}`,port:t.port===``?gx[t.protocol]??NaN:Number(t.port)}}function vx(e,t){return`${e}:${t}`}async function yx(e,t){let n=cx(e)?await mx(e,t):q.extname(e).slice(1);if(!(n===void 0||!vy.includes(n)))return n}async function bx(e,t,n){return cx(e)?px(e,n):Ky(e,t)}async function xx(e,t,n,r,i){if(!await bx(e,r,i))return;let a=eb(t),o=await Sx(e,r,i),s=n===void 0?``:`.${n}`,c;if(c=`${a}-${o}${s}`,c.length>120)throw Error(`Filename too long: ${c}`);return c}async function Sx(e,t,n){return cx(e)?hx(e,n):qy(e,t)}const Cx=RegExp(`([\\{\\}])(?=[\\{\\}])`,`gv`);function wx(e){return e.replaceAll(Cx,`$1 `)}const Tx=function(){return function(e){let t=!1;A(e,(e,n,r)=>{if(r===void 0||n===void 0||e.type!==`element`)return!0;let[i]=e.children;if(e.tagName===`pre`&&e.children.length===1&&i?.type===`element`&&i.tagName===`code`&&Array.isArray(i.properties.className)&&i.properties.className.includes(`language-math`)&&(t=!0,r.children[n]=i),e.tagName===`code`&&Array.isArray(e.properties.className)&&e.properties.className.includes(`language-math`)){let n=e.properties.className.includes(`math-display`)||t;t=!1;for(let t of e.children)t.type===`text`&&(t.value=wx(t.value));e.tagName=n?`div`:`span`,e.children=[{type:`text`,value:n?String.raw`\[`:String.raw`\(`},...e.children,{type:`text`,value:n?String.raw`\]`:String.raw`\)`}]}return!0})}};function Ex(e,t,n){let r=jo((n||{}).ignore||[]),i=Dx(t),a=-1;for(;++a<i.length;)Vo(e,`text`,o);function o(e,t){let n=-1,i;for(;++n<t.length;){let e=t[n],a=i?i.children:void 0;if(r(e,a?a.indexOf(e):void 0,i))return;i=e}if(i)return s(e,t)}function s(e,t){let n=t[t.length-1],r=i[a][0],o=i[a][1],s=0,c=n.children.indexOf(e),l=!1,u=[];r.lastIndex=0;let d=r.exec(e.value);for(;d;){let n=d.index,i={index:d.index,input:d.input,stack:[...t,e]},a=o(...d,i);if(typeof a==`string`&&(a=a.length>0?{type:`text`,value:a}:void 0),a===!1?r.lastIndex=n+1:(s!==n&&u.push({type:`text`,value:e.value.slice(s,n)}),Array.isArray(a)?u.push(...a):a&&u.push(a),s=n+d[0].length,l=!0),!r.global)break;d=r.exec(e.value)}return l?(s<e.value.length&&u.push({type:`text`,value:e.value.slice(s)}),n.children.splice(c,1,...u)):u=[e],c+u.length}}function Dx(e){let t=[];if(!Array.isArray(e))throw TypeError(`Expected find and replace tuple or list of tuples`);let n=!e[0]||Array.isArray(e[0])?e:[e],r=-1;for(;++r<n.length;){let e=n[r];t.push([Ox(e[0]),kx(e[1])])}return t}function Ox(e){return typeof e==`string`?new RegExp(Ey(e),`g`):e}function kx(e){return typeof e==`function`?e:function(){return e}}function Ax(e){Ex(e,[/\r?\n|\r/g,jx])}function jx(){return{type:`break`}}function Mx(){return function(e){Ax(e)}}const Nx=function(){return function(e,t){if(t.data.strictLineBreaks===!1){Mx()(e);return}return e}},Px=RegExp(`^[\\dx]+$`,`v`),Fx=Ao({engine:kv(),langs:[Ee,De,Fe,Ie,Le,Re,ze,He,Ue,Be,We,Ge,Ke,qe,Ze,Qe,Oe,lt,ut,ft,Ee,je,pt,mt,nt,tt,Ye,st],themes:[Xo,Zo]}),Ix=Rv().use(Nx).use(ih,{allowDangerousHtml:!0}).use(em).use(Tx).use(Yo,Fx,{defaultLanguage:`plaintext`,fallbackLanguage:`plaintext`,themes:{dark:`github-dark`,light:`github-light`}}).use(nc).use(tm),Lx={...Cy};async function Rx(e,t){if(e===void 0)return``;let{cssClassNames:n,fetchAdapter:r=Ty(),fileAdapter:i=await wy(),namespace:a,strictLineBreaks:o,syncMediaAssets:s,useEmptyPlaceholder:c}=w(Lx,t??{}),l=await Ix.run(e,{data:{strictLineBreaks:o}}),u=K(`root`,[K(`element`,{properties:{className:n?.map(e=>ry(e))},tagName:`div`},l.children)]),d=[];A(u,`element`,(e,t,n)=>{if(n===void 0||t===void 0||e.tagName!==`img`)return!0;if(typeof e.properties.src!=`string`||e.properties?.src?.trim().length===0)return console.warn(`Image has no src`),!0;let o,c=ux(e.properties.src);switch(c){case`localFilePath`:if(o=ox(e.properties.src),o===void 0)return!0;o=nx(o);break;case`unsupportedProtocolUrl`:case`localFileName`:console.warn(`Unsupported URL for media asset, treating as link: "${e.properties.src}"`),o=e.properties.src;break;case`obsidianVaultUrl`:case`localFileUrl`:o=e.properties.src;break;case`remoteHttpUrl`:o=e.properties.src;break}return d.push(async()=>{let l=await yx(o,c===`obsidianVaultUrl`?void 0:r),u=l!==void 0&&c!==`unsupportedProtocolUrl`&&c!==`localFileName`&&c!==`obsidianVaultUrl`&&c!==`localFileUrl`,d=(c===`localFilePath`&&s===`local`||c===`remoteHttpUrl`&&s===`remote`||s===`all`)&&u,f=d?await xx(o,a,l,i,r):void 0,p=f??o,m=d&&f!==void 0?`true`:`false`;if(!u||_y.includes(l)){let r=cx(p)?p:`${p}${rx(String(e.properties.dataYankiSrcOriginal))}`;n.children[t]=K(`element`,{properties:{className:[`yanki-media`,`yanki-media-${u?`file`:`unsupported`}`],"data-yanki-alt-text":e.properties.alt,"data-yanki-media-src":o,"data-yanki-media-sync":m,"data-yanki-src":p,"data-yanki-src-original":e.properties.dataYankiSrcOriginal},tagName:`span`},[K(`element`,{properties:{href:r},tagName:`a`},[K(`text`,decodeURI(String(e.properties.dataYankiSrcOriginal)))])])}else hy.includes(l)?(e.properties.src=p,e.properties.className=[`yanki-media`,`yanki-media-image`],e.properties.dataYankiMediaSrc=o,e.properties.dataYankiMediaSync=m):gy.includes(l)&&(n.children[t]=K(`element`,{properties:{className:[`yanki-media`,`yanki-media-audio-video`],"data-yanki-alt-text":e.properties.alt,"data-yanki-media-src":o,"data-yanki-media-sync":m,"data-yanki-src":p,"data-yanki-src-original":e.properties.dataYankiSrcOriginal},tagName:`span`},[K(`text`,`[sound:${p}]`)]))}),!0});for(let e of d)await e();A(u,`element`,(e,t,n)=>{if(n===void 0||t===void 0||e.tagName!==`img`||iy(String(e.properties.alt))===void 0)return!0;let{alt:r,height:i,width:a}=Kx(e.properties.alt??``);return r===void 0?delete e.properties.alt:e.properties.alt=r,i!==void 0&&(e.properties.height=i),a!==void 0&&(e.properties.width=a),!0});let f=Jx(u);if(f&&!c)return``;let p=f?Yx(u,py):u;return Bx(Ix.stringify(p)).trim()}const zx=Rv().use(ap,{fragment:!0});function Bx(e){return`<!-- This HTML was generated by Yanki, a Markdown to Anki converter. Do not edit directly. -->\n${e}`}function Vx(e){return ms(e)}function Hx(e){return Vx(zx.parse(e))}function Ux(e){return Hx(e).split(`
975
975
  `).map(e=>e.trim()).filter(e=>e.length>0).join(` `)}function Wx(e){return Hx(e).split(`
976
976
  `).map(e=>e.trim()).find(e=>e.length>0)??``}function Gx(e){let t=zx.parse(e),n=[];return A(t,`element`,e=>{if(e.tagName!==`img`&&e.tagName!==`span`||e.properties?.dataYankiMediaSync!==`true`)return;let t=e.properties?.src??e.properties?.dataYankiSrc,r=e.properties?.dataYankiMediaSrc;t!==void 0&&r!==void 0&&typeof t==`string`&&typeof r==`string`&&n.push({filename:t,originalSrc:r})}),n}function Kx(e){let t=e.split(`|`),n=iy(t.pop()),r=iy(t.join(`|`));if(n!==void 0){let{width:e,height:t}=qx(n);if(e!==void 0||t!==void 0)return{alt:r,height:t,width:e}}return{alt:e,height:void 0,width:void 0}}function qx(e){if(!Px.test(e))return{width:void 0,height:void 0};if(!e.includes(`x`)){let t=Number(e);if(!Number.isNaN(t))return{width:t,height:void 0}}let[t,n]=e.split(`x`).map(e=>Number.parseInt(e,10));return{width:Number.isNaN(t)||t===void 0?void 0:t,height:Number.isNaN(n)||n===void 0?void 0:n}}function Jx(e){let t=!1;return A(e,e=>{if(t)return!1;if(e.type===`element`){let n=e,{tagName:r}=n;if([`img`,`video`,`audio`,`iframe`,`object`,`embed`,`canvas`,`svg`,`picture`].includes(r)||ms(n).trim()!==``)return t=!0,!1}return e.type===`text`&&e.value!==void 0&&e.value.trim()!==``?(t=!0,!1):!0}),!t}function Yx(e,t){return A(e,`element`,e=>{if(e.tagName===`div`)return e.children.unshift(t),!1}),e}const Xx=Object.prototype.toString;function Zx(e,t,n){return e?e.constructor===t||Xx.call(e)===n:!1}function Qx(e){return Zx(e,Uint8Array,`[object Uint8Array]`)}function $x(e){if(!Qx(e))throw TypeError(`Expected \`Uint8Array\`, got \`${typeof e}\``)}new globalThis.TextDecoder(`utf8`),new globalThis.TextEncoder;function eS(e){return e.replaceAll(`+`,`-`).replaceAll(`/`,`_`).replace(/=+$/,``)}const tS=65535;function nS(e,{urlSafe:t=!1}={}){$x(e);let n=``;for(let t=0;t<e.length;t+=tS){let r=e.subarray(t,t+tS);n+=globalThis.btoa(String.fromCodePoint.apply(void 0,r))}return t?eS(n):n}Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));const rS=[{cardTemplates:[{Back:`{{FrontSide}}
977
977
 
@@ -1132,12 +1132,12 @@ $&`).replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g,`$1$2`).replace(/\
1132
1132
  `)+1;for(;e!==0;)this.onNewLine(this.offset+e),e=this.source.indexOf(`
1133
1133
  `,e)+1}yield*this.pop();break;default:yield*this.pop(),yield*this.step()}}*blockMap(e){let t=e.items[e.items.length-1];switch(this.type){case`newline`:if(this.onKeyLine=!1,t.value){let n=`end`in t.value?t.value.end:void 0;(Array.isArray(n)?n[n.length-1]:void 0)?.type===`comment`?n?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case`space`:case`comment`:if(t.value)e.items.push({start:[this.sourceToken]});else if(t.sep)t.sep.push(this.sourceToken);else{if(this.atIndentedComment(t.start,e.indent)){let n=e.items[e.items.length-2]?.value?.end;if(Array.isArray(n)){uN(n,t.start),n.push(this.sourceToken),e.items.pop();return}}t.start.push(this.sourceToken)}return}if(this.indent>=e.indent){let n=!this.onKeyLine&&this.indent===e.indent,r=n&&(t.sep||t.explicitKey)&&this.type!==`seq-item-ind`,i=[];if(r&&t.sep&&!t.value){let n=[];for(let r=0;r<t.sep.length;++r){let i=t.sep[r];switch(i.type){case`newline`:n.push(r);break;case`space`:break;case`comment`:i.indent>e.indent&&(n.length=0);break;default:n.length=0}}n.length>=2&&(i=t.sep.splice(n[1]))}switch(this.type){case`anchor`:case`tag`:r||t.value?(i.push(this.sourceToken),e.items.push({start:i}),this.onKeyLine=!0):t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case`explicit-key-ind`:!t.sep&&!t.explicitKey?(t.start.push(this.sourceToken),t.explicitKey=!0):r||t.value?(i.push(this.sourceToken),e.items.push({start:i,explicitKey:!0})):this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken],explicitKey:!0}]}),this.onKeyLine=!0;return;case`map-value-ind`:if(t.explicitKey)if(!t.sep)if(aN(t.start,`newline`))Object.assign(t,{key:null,sep:[this.sourceToken]});else{let e=lN(t.start);this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:e,key:null,sep:[this.sourceToken]}]})}else if(t.value)e.items.push({start:[],key:null,sep:[this.sourceToken]});else if(aN(t.sep,`map-value-ind`))this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:i,key:null,sep:[this.sourceToken]}]});else if(sN(t.key)&&!aN(t.sep,`newline`)){let e=lN(t.start),n=t.key,r=t.sep;r.push(this.sourceToken),delete t.key,delete t.sep,this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:e,key:n,sep:r}]})}else i.length>0?t.sep=t.sep.concat(i,this.sourceToken):t.sep.push(this.sourceToken);else t.sep?t.value||r?e.items.push({start:i,key:null,sep:[this.sourceToken]}):aN(t.sep,`map-value-ind`)?this.stack.push({type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:[],key:null,sep:[this.sourceToken]}]}):t.sep.push(this.sourceToken):Object.assign(t,{key:null,sep:[this.sourceToken]});this.onKeyLine=!0;return;case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:{let n=this.flowScalar(this.type);r||t.value?(e.items.push({start:i,key:n,sep:[]}),this.onKeyLine=!0):t.sep?this.stack.push(n):(Object.assign(t,{key:n,sep:[]}),this.onKeyLine=!0);return}default:{let r=this.startBlockValue(e);if(r){if(r.type===`block-seq`){if(!t.explicitKey&&t.sep&&!aN(t.sep,`newline`)){yield*this.pop({type:`error`,offset:this.offset,message:`Unexpected block-seq-ind on same line with key`,source:this.source});return}}else n&&e.items.push({start:i});this.stack.push(r);return}}}}yield*this.pop(),yield*this.step()}*blockSequence(e){let t=e.items[e.items.length-1];switch(this.type){case`newline`:if(t.value){let n=`end`in t.value?t.value.end:void 0;(Array.isArray(n)?n[n.length-1]:void 0)?.type===`comment`?n?.push(this.sourceToken):e.items.push({start:[this.sourceToken]})}else t.start.push(this.sourceToken);return;case`space`:case`comment`:if(t.value)e.items.push({start:[this.sourceToken]});else{if(this.atIndentedComment(t.start,e.indent)){let n=e.items[e.items.length-2]?.value?.end;if(Array.isArray(n)){uN(n,t.start),n.push(this.sourceToken),e.items.pop();return}}t.start.push(this.sourceToken)}return;case`anchor`:case`tag`:if(t.value||this.indent<=e.indent)break;t.start.push(this.sourceToken);return;case`seq-item-ind`:if(this.indent!==e.indent)break;t.value||aN(t.start,`seq-item-ind`)?e.items.push({start:[this.sourceToken]}):t.start.push(this.sourceToken);return}if(this.indent>e.indent){let t=this.startBlockValue(e);if(t){this.stack.push(t);return}}yield*this.pop(),yield*this.step()}*flowCollection(e){let t=e.items[e.items.length-1];if(this.type===`flow-error-end`){let e;do yield*this.pop(),e=this.peek(1);while(e?.type===`flow-collection`)}else if(e.end.length===0){switch(this.type){case`comma`:case`explicit-key-ind`:!t||t.sep?e.items.push({start:[this.sourceToken]}):t.start.push(this.sourceToken);return;case`map-value-ind`:!t||t.value?e.items.push({start:[],key:null,sep:[this.sourceToken]}):t.sep?t.sep.push(this.sourceToken):Object.assign(t,{key:null,sep:[this.sourceToken]});return;case`space`:case`comment`:case`newline`:case`anchor`:case`tag`:!t||t.value?e.items.push({start:[this.sourceToken]}):t.sep?t.sep.push(this.sourceToken):t.start.push(this.sourceToken);return;case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:{let n=this.flowScalar(this.type);!t||t.value?e.items.push({start:[],key:n,sep:[]}):t.sep?this.stack.push(n):Object.assign(t,{key:n,sep:[]});return}case`flow-map-end`:case`flow-seq-end`:e.end.push(this.sourceToken);return}let n=this.startBlockValue(e);n?this.stack.push(n):(yield*this.pop(),yield*this.step())}else{let t=this.peek(2);if(t.type===`block-map`&&(this.type===`map-value-ind`&&t.indent===e.indent||this.type===`newline`&&!t.items[t.items.length-1].sep))yield*this.pop(),yield*this.step();else if(this.type===`map-value-ind`&&t.type!==`flow-collection`){let n=lN(cN(t));dN(e);let r=e.end.splice(1,e.end.length);r.push(this.sourceToken);let i={type:`block-map`,offset:e.offset,indent:e.indent,items:[{start:n,key:e,sep:r}]};this.onKeyLine=!0,this.stack[this.stack.length-1]=i}else yield*this.lineEnd(e)}}flowScalar(e){if(this.onNewLine){let e=this.source.indexOf(`
1134
1134
  `)+1;for(;e!==0;)this.onNewLine(this.offset+e),e=this.source.indexOf(`
1135
- `,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=lN(cN(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=lN(cN(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}};function pN(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new iN||null,prettyErrors:t}}function mN(e,t={}){let{lineCounter:n,prettyErrors:r}=pN(t),i=new fN(n?.addNewLine),a=new WM(t),o=null;for(let t of a.compose(i.parse(e),!0,e.length))if(!o)o=t;else if(o.options.logLevel!==`silent`){o.errors.push(new oM(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return r&&n&&(o.errors.forEach(cM(e,n)),o.warnings.forEach(cM(e,n))),o}function hN(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let i=mN(e,n);if(!i)return null;if(i.warnings.forEach(e=>zA(i.options.logLevel,e)),i.errors.length>0){if(i.options.logLevel!==`silent`)throw i.errors[0];i.errors=[]}return i.toJS(Object.assign({reviver:r},n))}function gN(e,t,n){let r=null;if(typeof t==`function`||Array.isArray(t)?r=t:n===void 0&&t&&(n=t),typeof n==`string`&&(n=n.length),typeof n==`number`){let e=Math.round(n);n=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=n??t??{};if(!e)return}return Vk(e)&&!r?e.toString(n):new rM(e,r,n).toString(n)}const _N=RegExp(`\\.md$`,`v`),vN={allFilePaths:[],basePath:void 0,convertFilePathsToProtocol:`none`,obsidianVaultName:void 0};function yN(e,t){let{allFilePaths:n,basePath:r,convertFilePathsToProtocol:i,cwd:a,obsidianVaultName:o,type:s}=w(vN,t??{});i===`obsidian`&&o===void 0&&console.warn(`convertFilePathsToProtocol is 'obsidian', but no obsidianVaultName provided`);let c=e;for(;;){let e=ox(c)??c,t=ux(e);if(t===`localFileName`){let t=xN(Zb(e),a,n??[])??Qb(e,{basePath:r,cwd:a});if(ux(t)===`localFilePath`){c=t;continue}return console.warn(`Failed to convert local file wiki-style name to path: ${c} --> ${t}`),t}if(t===`localFileUrl`){let e=Zb(lx(c));if(ux(e)===`localFilePath`){c=e;continue}return console.warn(`Failed to convert file URL to path: ${c} --> ${e}`),e}switch(t){case`localFilePath`:return bN(e,{allFilePaths:n,basePath:r,convertFilePathsToProtocol:i,cwd:a,obsidianVaultName:o,type:s});case`obsidianVaultUrl`:return c;case`remoteHttpUrl`:return c;case`unsupportedProtocolUrl`:return console.warn(`Unsupported URL protocol: ${c}`),c}}}function bN(e,t){let{allFilePaths:n,basePath:r,convertFilePathsToProtocol:i,cwd:a,obsidianVaultName:o,type:s}=t,c=Qb(Zb(e),{basePath:r,cwd:a}),l,u;for(let{base:e,query:t}of tx(c))if(l=(q.extname(e)===``?[`${e}.md`]:[e,`${e}.md`]).find(e=>CN(e,n??[])),l!==void 0){u=t;break}if(l!==void 0){if(i!==`none`&&(s===`link`||s===`embed`&&[`.md`,`.pdf`].includes(q.extname(l)))){if(i===`obsidian`&&o!==void 0)return TN(`${l}${u??``}`,r??``,o);if(i===`file`)return wN(`${l}${u??``}`)}return l}return nx(c)}function xN(e,t,n){if(n.length!==0)for(let{base:r,query:i}of tx(e)){let e=SN(q.extname(r)===``?`${r}.md`:r,t,n);if(e!==void 0)return`${e}${i??``}`}}function SN(e,t,n){let r=e.replace(_N,``).toLowerCase(),i=n.filter(e=>e.replace(_N,``).toLowerCase().endsWith(r));if(i.length!==0)return i.length===1?i[0]:i.toSorted((n,r)=>{if(!e.endsWith(`.md`)||e.includes(q.sep)){let e=n.startsWith(t);if(e!==r.startsWith(t))return e?-1:1}let i=n.split(q.sep).length,a=r.split(q.sep).length;return i===a?n.localeCompare(r):i-a})[0]}function CN(e,t){let n=e.toLowerCase();return t.some(e=>e.toLowerCase().endsWith(n))}function wN(e){return`file://${e}`}function TN(e,t,n){let r=$b(e,t);return`obsidian://open?vault=${encodeURIComponent(n)}&file=${encodeURIComponent(r)}`}const EN=function(e){let{allFilePaths:t=[],basePath:n,cwd:r,enabled:i=!0,obsidianVault:a}=e;return function(e){i&&(A(e,`link`,e=>{e.data??={},e.data.hProperties={...e.data?.hProperties,"data-yanki-src-original":e.url};let i=yN(e.url,{allFilePaths:t,basePath:n,convertFilePathsToProtocol:a===void 0?`none`:`obsidian`,cwd:r,obsidianVaultName:a,type:`link`});e.url=cx(i)?i:encodeURI(i).replaceAll(`?`,`%3F`).replaceAll(`#`,`%23`)}),A(e,`image`,e=>{e.data??={},e.data.hProperties={...e.data?.hProperties,"data-yanki-src-original":e.url};let i=yN(e.url,{allFilePaths:t,basePath:n,convertFilePathsToProtocol:a===void 0?`none`:`obsidian`,cwd:r,obsidianVaultName:a,type:`embed`});e.url=cx(i)?i:encodeURI(i)}))}};function DN(){let e=``,t;return{enter:{wikiEmbed:r,wikiLabel:o,wikiLink:n,wikiUrl:i},exit:{wikiEmbed:l,wikiLabel:s,wikiLink:c,wikiUrl:a}};function n(n){e=``,t=void 0,this.enter({children:[],title:void 0,type:`link`,url:``},n)}function r(n){e=``,t=void 0,this.enter({type:`image`,url:``},n)}function i(){this.buffer()}function a(){e=this.resume()}function o(){this.buffer()}function s(){t=this.resume()}function c(n){let r=this.stack.at(-1);r.url=ym(e),r.children=[{type:`text`,value:iy((t??``).replaceAll(`|`,``))??e.split(`#`).pop()??e.split(`/`).pop()??e}],this.exit(n)}function l(n){let r=this.stack.at(-1);r.url=ym(e),t!==void 0&&(r.alt=t),this.exit(n)}}function ON(){return{text:{33:{name:`wikiEmbed`,tokenize:e},91:{name:`wikiLink`,tokenize:e}}};function e(e,t,n){let r=!1,i=!1,a=0,o=0;return s;function s(t){return t===33?(r=!0,e.enter(`wikiEmbed`),e.enter(`wikiMarker`),e.consume(t),c):(e.enter(`wikiLink`),e.enter(`wikiMarker`),c(t))}function c(t){return t===91?(e.consume(t),l):n(t)}function l(t){return t===91?(e.consume(t),e.exit(`wikiMarker`),u):n(t)}function u(t){return t===null||[-5,-4,-3].includes(t)||t===124||t===93?n(t):(e.enter(`wikiUrl`),e.enter(`chunkString`,{contentType:`string`}),e.consume(t),a++,d)}function d(t){return t===null||[-5,-4,-3].includes(t)?n(t):t===124?a===1?n(t):x(t):t===92?e.check({partial:!0,tokenize:b},x,f)(t):t===93?h(t):f(t)}function f(t){return e.consume(t),a++,d}function p(t){return t===null||[-5,-4,-3].includes(t)?n(t):t===93?h(t):(e.enter(`wikiLabel`),e.enter(`chunkString`,{contentType:`string`}),e.consume(t),o++,m)}function m(t){return t===null||[-5,-4,-3].includes(t)?n(t):t===93?h(t):(e.consume(t),o++,m)}function h(t){return t===93?e.check({partial:!0,tokenize:y},g,v)(t):n(t)}function g(t){return t===93?(i?o>0&&(e.exit(`chunkString`),e.exit(`wikiLabel`)):a>0&&(e.exit(`chunkString`),e.exit(`wikiUrl`)),e.enter(`wikiMarker`),e.consume(t),_):n(t)}function _(i){return i!==93||a===0?n(i):(e.consume(i),e.exit(`wikiMarker`),r?e.exit(`wikiEmbed`):e.exit(`wikiLink`),t)}function v(t){return t===93?(e.consume(t),i?(o++,m):(a++,d)):n(t)}function y(e,t,n){return r;function r(r){return r===93?(e.enter(`wikiMarkerTemp`),e.consume(r),e.exit(`wikiMarkerTemp`),t(r)):n(r)}}function b(e,t,n){return r;function r(t){return t===92?(e.enter(`wikiMarkerTemp`),e.consume(t),i):n(t)}function i(r){return r===124?(e.consume(r),e.exit(`wikiMarkerTemp`),t(r)):(e.exit(`wikiMarkerTemp`),n(r))}}function x(t){return e.exit(`chunkString`),e.exit(`wikiUrl`),e.enter(`wikiMarker`),e.consume(t),t===92?ee:(e.exit(`wikiMarker`),i=!0,e.check({partial:!0,tokenize:S},h,p)(t))}function S(e,t,n){return r;function r(r){return r===93?(e.enter(`wikiMarkerTemp`),e.consume(r),e.exit(`wikiMarkerTemp`),t(r)):n(r)}}function ee(t){return t===124?(e.consume(t),e.exit(`wikiMarker`),i=!0,p):n(t)}}}const kN=function(){let e=this.data();e.micromarkExtensions=[...e.micromarkExtensions??[],ON()],e.fromMarkdownExtensions=[...e.fromMarkdownExtensions??[],DN()]},AN=RegExp(`^[\\(\\|]?(\\d{1,2})(?:[\\s\\).\\|]|$)(.*)$`,`v`),jN={...Cy};async function MN(e,t){let{allFilePaths:n,basePath:r,cwd:i,obsidianVault:a,resolveUrls:o}=w(jN,t??{}),s=Rv().use(Mk).use(MC,[{anywhere:!1,marker:`-`,type:`yaml`}]).use(kN).use(OO,{singleTilde:!1}).use(EN,{allFilePaths:n,basePath:r,cwd:i,enabled:o,obsidianVault:a}).use(qO).use(PO).use(fC).use(XS);return s.run(s.parse(e))}function NN(e){return e.type===`text`}function PN(e,t){return A(e,t,(e,t,n)=>{if(!(!n||t===void 0))return n.children.splice(t,1),!1}),e}function FN(e){let t=e.at(0);t?.type===`text`&&(t.value=t.value.trimStart(),t.value===``&&e.shift());let n=e.at(-1);return n?.type===`text`&&(n.value=n.value.trimEnd(),n.value===``&&e.pop()),e}function IN(e){let t=1;return A(e,`delete`,(e,n,r)=>{if(r===void 0||n===void 0||!(`children`in e)||e.children.length===0)return!0;let[i]=e.children;if(i!==void 0&&NN(i)){let n=AN.exec(i.value);if(n!==null&&(e.children.length>1||(n.at(2)??``).length>0)){let e=Number(n.at(1));Number.isNaN(e)||(t=e,i.value=(n.at(2)?.trim().length??0)>0?n.at(2)??``:``)}}let a=e.children.at(-1),o=e.children.length>1&&a?.type===`emphasis`?[K(`text`,`{{c${t}::`),...FN(e.children.slice(0,-1)),K(`text`,`::`),...FN(e.children.slice(-1)),K(`text`,`}}`)]:[K(`text`,`{{c${t}::`),...FN(e.children),K(`text`,`}}`)];return r.children.splice(n,1,...o),t+=1,!0}),e}function LN(e){let t,n=!1;return A(e,`thematicBreak`,(e,r,i)=>r===void 0||i===void 0?!0:(t=r,i.children[r+1]?.type===`thematicBreak`&&(n=!0),!1)),t===void 0?[e,void 0]:[{children:e.children.slice(0,t),type:`root`},{children:e.children.slice(t+(n?2:1)),type:`root`}]}function RN(e){let t;if(A(e,e=>e.type===`thematicBreak`?(t=void 0,!1):e.type===`delete`?(t=`Yanki - Cloze`,!1):!0),t!==void 0)return t;if(!BN(e)&&VN(e))return`Yanki - Basic (type in the answer)`;let n;return A(e,(e,r,i)=>{if(i===null||r===null)return!0;if(e.type===`thematicBreak`){if(t===void 0)t=`Yanki - Basic`;else if(t===`Yanki - Basic`&&n?.type===`thematicBreak`)return t=`Yanki - Basic (and reversed card with extra)`,!1}return n=e,!0}),t??`Yanki - Basic`}function zN(e){let t;if(A(e,`yaml`,e=>`value`in e?(t=e.value,!1):!0),t===void 0||t===``)return{};let n=hN(t)??void 0;if(n===void 0)throw Error(`Could not parse frontmatter`);return n}function BN(e){let t=!1;return A(e,`thematicBreak`,()=>(t=!0,!1)),t}function VN(e){let t,n=0;return A(e,e=>{if(e.type===`text`&&e.value.trim()!==``)t=e,n++;else if(e.type===`emphasis`&&e.children.some(e=>e.type===`text`&&e.value.trim()!==``))return t=e,n++,Bo;return!0}),t?.type===`emphasis`&&n>1}function HN(e){let t,n,r;if(A(e,`emphasis`,(e,i,a)=>a===void 0||i===void 0||e.type!==`emphasis`?!0:(t=e,n=a,r=i,!0)),n&&t&&typeof r==`number`)return n.children.splice(r,1),t}const UN={namespaceValidationAndSanitization:!0,...Cy};async function WN(e,t){let{allFilePaths:n,basePath:r,cwd:i,fetchAdapter:a=Ty(),fileAdapter:o=await wy(),namespace:s,namespaceValidationAndSanitization:c,obsidianVault:l,resolveUrls:u,strictLineBreaks:d,syncMediaAssets:f}=w(UN,t??{}),p=c?Zy(s):s,m=await MN(e,{allFilePaths:n,basePath:r,cwd:i,obsidianVault:l,resolveUrls:u}),h=RN(m),g=zN(m);m=PN(m,`yaml`);let _=``,v=``,y;switch(h){case`Yanki - Basic`:case`Yanki - Basic (and reversed card with extra)`:{let[e,t]=LN(m),n;if(t!==void 0&&h===`Yanki - Basic (and reversed card with extra)`){y=``;let[e,r]=LN(t);t=e,n=r}_=await Rx(e,{cssClassNames:[dy,`namespace-${p}`,`front`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!0}),v=await Rx(t,{cssClassNames:[dy,`namespace-${p}`,`back`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!0}),n!==void 0&&(y=await Rx(n,{cssClassNames:[dy,`namespace-${p}`,`extra`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!1}));break}case`Yanki - Basic (type in the answer)`:{let e=HN(m);if(e===void 0)throw Error(`Could not find emphasis in Basic (type in the answer) note AST.`);let t=m,n=K(`root`,K(`paragraph`,e.children));_=await Rx(t,{cssClassNames:[dy,`namespace-${p}`,`front`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!0}),v=await Rx(n,{cssClassNames:[dy,`namespace-${p}`,`back`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!1});break}case`Yanki - Cloze`:{let[e,t]=LN(m);_=await Rx(IN(e),{cssClassNames:[dy,`namespace-${p}`,`front`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!0}),v=await Rx(t,{cssClassNames:[dy,`namespace-${p}`,`back`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!1});break}}return{deckName:``,fields:{Back:v,...y!==void 0&&{Extra:y},Front:_,YankiNamespace:p},modelName:h,noteId:g.noteId??void 0,tags:GN(g.tags)}}function GN(e){return(Array.isArray(e)?e:e===void 0?[]:[e]).map(e=>String(e).replaceAll(`/`,`::`))}const KN={...Cy};async function qN(e,t){let{allFilePaths:n,basePath:r,fetchAdapter:i=Ty(),fileAdapter:a=await wy(),namespace:o,obsidianVault:s,strictLineBreaks:c,syncMediaAssets:l}=w(KN,t??{}),u=Zy(o);e.sort((e,t)=>e.localeCompare(t));let d=YN(e);return await Promise.all(e.map(async(e,t)=>{let o=await a.readFile(e),f=await WN(o,{allFilePaths:n,basePath:r,cwd:q.dirname(e),fetchAdapter:i,fileAdapter:a,namespace:u,namespaceValidationAndSanitization:!1,obsidianVault:s,strictLineBreaks:c,syncMediaAssets:l});return f.deckName===``&&(f.deckName=d[t]??``),{filePath:e,filePathOriginal:e,markdown:o,note:f}}))}const JN={mode:`common-root`};function YN(e,t){let{mode:n}=w(JN,t??{});if(e.length===0)return[];let r=e.map(e=>q.dirname(e).split(q.sep)),i=r.reduce((e,t)=>e.filter((e,n)=>e===t[n])),a=r.some(e=>e.at(-1)===i.at(-1)),o=n===`common-parent`?1:+!!a;return r.map(e=>e.slice(i.length-o).join(`::`))}const XN={...Cy};async function ZN(e,t){let{dryRun:n,fileAdapter:r=await wy(),manageFilenames:i,maxFilenameLength:a}=w(XN,t??{});if(i!==`off`){let t=[];for(let n of e){let{filePath:e,note:r}=n;if(e===void 0)throw Error(`File path is undefined`);let o=BS(r,i,a),s=HS(q.join(q.dirname(e),`${o}${q.extname(e)}`),t);n.filePath=s,t.push(s.toLowerCase())}for(let n of e){let{filePath:e}=n;if(e===void 0)throw Error(`File path is undefined`);n.filePath=US(e,t)}let o=new Map;for(let t of e){let{filePath:i,filePathOriginal:a}=t;if(a===void 0)throw Error(`Original file path is undefined.`);if(i===void 0)throw Error(`File path is undefined.`);if(i===a)continue;let s=i;e.some(({filePath:e,filePathOriginal:t})=>e!==i&&t?.toLowerCase()===i.toLowerCase())&&(s=KS(i),o.set(s,i)),n||await r.rename(a,s)}for(let[e,t]of o)n||await r.rename(e,t)}return e.sort((e,t)=>e.filePath.localeCompare(t.filePath)),e}const QN={...Cy};async function $N(e,t){let{allFilePaths:n,basePath:r,dryRun:i,fetchAdapter:a=Ty(),fileAdapter:o=await wy(),manageFilenames:s,maxFilenameLength:c,namespace:l,obsidianVault:u,strictLineBreaks:d,syncMediaAssets:f}=w(QN,t??{}),p=e.map(e=>Zb(e)),m=r===void 0?void 0:Zb(r);return{dryRun:i,notes:await ZN(await qN(p,{allFilePaths:n.map(e=>Zb(e)),basePath:m,fetchAdapter:a,fileAdapter:o,namespace:Zy(l),obsidianVault:u,strictLineBreaks:d,syncMediaAssets:f}),{dryRun:i,fileAdapter:o,manageFilenames:s,maxFilenameLength:c})}}const eP={css:uy,...Cy},tP={...Cy};async function nP(e){let{ankiConnectOptions:t}=w(eP,e??{}),n=new Te(t);if(await wS(n)===`ankiUnreachable`)throw Error(`Anki is unreachable. Is Anki running?`);let r=new Set;for(let e of iS){let t=await xS(n,e);r.add(t)}let[i]=r;if(i===void 0)throw Error(`No CSS found in any Yanki model.`);if(r.size>1)throw Error(`Expected all Yanki models to have identical CSS.`);return i}async function rP(e){let t=performance.now(),{ankiConnectOptions:n,ankiWeb:r,css:i,dryRun:a}=w(eP,e??{}),o=new Te(n);if(await wS(o)===`ankiUnreachable`)throw Error(`Anki is unreachable. Is Anki running?`);let s=[];for(let e of iS){let t=await bS(o,e,i,a);s.push({action:t?`updated`:`unchanged`,name:e})}return s.some(e=>e.action!==`unchanged`),!a&&r&&await TS(o),{ankiWeb:r,dryRun:a,duration:performance.now()-t,models:s}}function iP(e,t=!1){let n=[],r=e.models.filter(e=>e.action===`unchanged`),i=e.models.filter(e=>e.action===`updated`);if(n.push(`${e.dryRun?`Will`:`Successfully`} update ${i.length} ${ue(`model`,i.length)} and left ${r.length} ${ue(`model`,r.length)} unchanged${e.dryRun?``:` in ${ve(e.duration)}`}.`),t){if(i.length>0){n.push(``,e.dryRun?`Models to update:`:`Updated models:`);for(let e of i)n.push(` ${e.name}`)}if(r.length>0){n.push(``,e.dryRun?`Models unchanged:`:`Unchanged models:`);for(let e of r)n.push(` ${e.name}`)}}return n.join(`
1136
- `)}const aP=RegExp(`\\r?\\n`,`v`);async function oP(e,t){let[n,r]=sP(e),i=e.split(aP);if(n===void 0||r===void 0)return t===void 0?e:[`---`,gN({noteId:t}).trim(),`---
1135
+ `,e)+1}return{type:e,offset:this.offset,indent:this.indent,source:this.source}}startBlockValue(e){switch(this.type){case`alias`:case`scalar`:case`single-quoted-scalar`:case`double-quoted-scalar`:return this.flowScalar(this.type);case`block-scalar-header`:return{type:`block-scalar`,offset:this.offset,indent:this.indent,props:[this.sourceToken],source:``};case`flow-map-start`:case`flow-seq-start`:return{type:`flow-collection`,offset:this.offset,indent:this.indent,start:this.sourceToken,items:[],end:[]};case`seq-item-ind`:return{type:`block-seq`,offset:this.offset,indent:this.indent,items:[{start:[this.sourceToken]}]};case`explicit-key-ind`:{this.onKeyLine=!0;let t=lN(cN(e));return t.push(this.sourceToken),{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,explicitKey:!0}]}}case`map-value-ind`:{this.onKeyLine=!0;let t=lN(cN(e));return{type:`block-map`,offset:this.offset,indent:this.indent,items:[{start:t,key:null,sep:[this.sourceToken]}]}}}return null}atIndentedComment(e,t){return this.type!==`comment`||this.indent<=t?!1:e.every(e=>e.type===`newline`||e.type===`space`)}*documentEnd(e){this.type!==`doc-mode`&&(e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop()))}*lineEnd(e){switch(this.type){case`comma`:case`doc-start`:case`doc-end`:case`flow-seq-end`:case`flow-map-end`:case`map-value-ind`:yield*this.pop(),yield*this.step();break;case`newline`:this.onKeyLine=!1;default:e.end?e.end.push(this.sourceToken):e.end=[this.sourceToken],this.type===`newline`&&(yield*this.pop())}}};function pN(e){let t=e.prettyErrors!==!1;return{lineCounter:e.lineCounter||t&&new iN||null,prettyErrors:t}}function mN(e,t={}){let{lineCounter:n,prettyErrors:r}=pN(t),i=new fN(n?.addNewLine),a=new WM(t),o=null;for(let t of a.compose(i.parse(e),!0,e.length))if(!o)o=t;else if(o.options.logLevel!==`silent`){o.errors.push(new oM(t.range.slice(0,2),`MULTIPLE_DOCS`,`Source contains multiple documents; please use YAML.parseAllDocuments()`));break}return r&&n&&(o.errors.forEach(cM(e,n)),o.warnings.forEach(cM(e,n))),o}function hN(e,t,n){let r;typeof t==`function`?r=t:n===void 0&&t&&typeof t==`object`&&(n=t);let i=mN(e,n);if(!i)return null;if(i.warnings.forEach(e=>zA(i.options.logLevel,e)),i.errors.length>0){if(i.options.logLevel!==`silent`)throw i.errors[0];i.errors=[]}return i.toJS(Object.assign({reviver:r},n))}function gN(e,t,n){let r=null;if(typeof t==`function`||Array.isArray(t)?r=t:n===void 0&&t&&(n=t),typeof n==`string`&&(n=n.length),typeof n==`number`){let e=Math.round(n);n=e<1?void 0:e>8?{indent:8}:{indent:e}}if(e===void 0){let{keepUndefined:e}=n??t??{};if(!e)return}return Vk(e)&&!r?e.toString(n):new rM(e,r,n).toString(n)}const _N=RegExp(`\\.md$`,`v`),vN={allFilePaths:[],basePath:void 0,convertFilePathsToProtocol:`none`,obsidianVaultName:void 0};function yN(e,t){let n=w(vN,t??{}),{allFilePaths:r,convertFilePathsToProtocol:i,cwd:a,obsidianVaultName:o}=n;i===`obsidian`&&o===void 0&&console.warn(`convertFilePathsToProtocol is 'obsidian', but no obsidianVaultName provided`);let s=ox(e)??e;switch(ux(s)){case`localFileName`:{let e=SN(s,a,r??[]);return e===void 0?bN(s,n):xN(e,n)}case`localFilePath`:return bN(s,n);case`localFileUrl`:{let t=lx(e);return bN(ox(t)??t,n)}case`obsidianVaultUrl`:case`remoteHttpUrl`:return e;case`unsupportedProtocolUrl`:return console.warn(`Unsupported URL protocol: ${e}`),e}}function bN(e,t){let{allFilePaths:n,basePath:r,cwd:i}=t,a=tx(e);for(let{anchor:e,filePath:o}of a){let a=Qb(Zb(o),{basePath:r,cwd:i}),s=(q.extname(a)===``?[`${a}.md`]:[a,`${a}.md`]).find(e=>wN(e,n??[]));if(s!==void 0)return xN({anchor:e,filePath:s},t)}return Qb(Zb(a.at(-1)?.filePath??e),{basePath:r,cwd:i})}function xN(e,t){let{anchor:n,filePath:r}=e,{basePath:i,convertFilePathsToProtocol:a,obsidianVaultName:o,type:s}=t;if(a!==`none`&&(s===`link`||s===`embed`&&[`.md`,`.pdf`].includes(q.extname(r)))){if(a===`obsidian`&&o!==void 0)return EN(e,i??``,o);if(a===`file`)return TN(`${r}${n??``}`)}return r}function SN(e,t,n){if(n.length!==0)for(let{anchor:r,filePath:i}of tx(e)){let e=Zb(i),a=CN(q.extname(e)===``?`${e}.md`:e,t,n);if(a!==void 0)return{anchor:r,filePath:a}}}function CN(e,t,n){let r=e.replace(_N,``).toLowerCase(),i=n.filter(e=>e.replace(_N,``).toLowerCase().endsWith(r));if(i.length!==0)return i.length===1?i[0]:i.toSorted((n,r)=>{if(!e.endsWith(`.md`)||e.includes(q.sep)){let e=n.startsWith(t);if(e!==r.startsWith(t))return e?-1:1}let i=n.split(q.sep).length,a=r.split(q.sep).length;return i===a?n.localeCompare(r):i-a})[0]}function wN(e,t){let n=e.toLowerCase();return t.some(e=>e.toLowerCase().endsWith(n))}function TN(e){return`file://${e}`}function EN(e,t,n){let r=`${$b(e.filePath,t)}${e.anchor??``}`;return`obsidian://open?vault=${encodeURIComponent(n)}&file=${encodeURIComponent(r)}`}const DN=function(e){let{allFilePaths:t=[],basePath:n,cwd:r,enabled:i=!0,obsidianVault:a}=e;return function(e){i&&(A(e,`link`,e=>{e.data??={},e.data.hProperties={...e.data?.hProperties,"data-yanki-src-original":e.url};let i=yN(e.url,{allFilePaths:t,basePath:n,convertFilePathsToProtocol:a===void 0?`none`:`obsidian`,cwd:r,obsidianVaultName:a,type:`link`});e.url=cx(i)?i:encodeURI(i).replaceAll(`?`,`%3F`).replaceAll(`#`,`%23`)}),A(e,`image`,e=>{e.data??={},e.data.hProperties={...e.data?.hProperties,"data-yanki-src-original":e.url};let i=yN(e.url,{allFilePaths:t,basePath:n,convertFilePathsToProtocol:a===void 0?`none`:`obsidian`,cwd:r,obsidianVaultName:a,type:`embed`});e.url=cx(i)?i:encodeURI(i)}))}};function ON(){let e=``,t;return{enter:{wikiEmbed:r,wikiLabel:o,wikiLink:n,wikiUrl:i},exit:{wikiEmbed:l,wikiLabel:s,wikiLink:c,wikiUrl:a}};function n(n){e=``,t=void 0,this.enter({children:[],title:void 0,type:`link`,url:``},n)}function r(n){e=``,t=void 0,this.enter({type:`image`,url:``},n)}function i(){this.buffer()}function a(){e=this.resume()}function o(){this.buffer()}function s(){t=this.resume()}function c(n){let r=this.stack.at(-1);r.url=ym(e),r.children=[{type:`text`,value:iy((t??``).replaceAll(`|`,``))??e.split(`#`).pop()??e.split(`/`).pop()??e}],this.exit(n)}function l(n){let r=this.stack.at(-1);r.url=ym(e),t!==void 0&&(r.alt=t),this.exit(n)}}function kN(){return{text:{33:{name:`wikiEmbed`,tokenize:e},91:{name:`wikiLink`,tokenize:e}}};function e(e,t,n){let r=!1,i=!1,a=0,o=0;return s;function s(t){return t===33?(r=!0,e.enter(`wikiEmbed`),e.enter(`wikiMarker`),e.consume(t),c):(e.enter(`wikiLink`),e.enter(`wikiMarker`),c(t))}function c(t){return t===91?(e.consume(t),l):n(t)}function l(t){return t===91?(e.consume(t),e.exit(`wikiMarker`),u):n(t)}function u(t){return t===null||[-5,-4,-3].includes(t)||t===124||t===93?n(t):(e.enter(`wikiUrl`),e.enter(`chunkString`,{contentType:`string`}),e.consume(t),a++,d)}function d(t){return t===null||[-5,-4,-3].includes(t)?n(t):t===124?a===1?n(t):x(t):t===92?e.check({partial:!0,tokenize:b},x,f)(t):t===93?h(t):f(t)}function f(t){return e.consume(t),a++,d}function p(t){return t===null||[-5,-4,-3].includes(t)?n(t):t===93?h(t):(e.enter(`wikiLabel`),e.enter(`chunkString`,{contentType:`string`}),e.consume(t),o++,m)}function m(t){return t===null||[-5,-4,-3].includes(t)?n(t):t===93?h(t):(e.consume(t),o++,m)}function h(t){return t===93?e.check({partial:!0,tokenize:y},g,v)(t):n(t)}function g(t){return t===93?(i?o>0&&(e.exit(`chunkString`),e.exit(`wikiLabel`)):a>0&&(e.exit(`chunkString`),e.exit(`wikiUrl`)),e.enter(`wikiMarker`),e.consume(t),_):n(t)}function _(i){return i!==93||a===0?n(i):(e.consume(i),e.exit(`wikiMarker`),r?e.exit(`wikiEmbed`):e.exit(`wikiLink`),t)}function v(t){return t===93?(e.consume(t),i?(o++,m):(a++,d)):n(t)}function y(e,t,n){return r;function r(r){return r===93?(e.enter(`wikiMarkerTemp`),e.consume(r),e.exit(`wikiMarkerTemp`),t(r)):n(r)}}function b(e,t,n){return r;function r(t){return t===92?(e.enter(`wikiMarkerTemp`),e.consume(t),i):n(t)}function i(r){return r===124?(e.consume(r),e.exit(`wikiMarkerTemp`),t(r)):(e.exit(`wikiMarkerTemp`),n(r))}}function x(t){return e.exit(`chunkString`),e.exit(`wikiUrl`),e.enter(`wikiMarker`),e.consume(t),t===92?ee:(e.exit(`wikiMarker`),i=!0,e.check({partial:!0,tokenize:S},h,p)(t))}function S(e,t,n){return r;function r(r){return r===93?(e.enter(`wikiMarkerTemp`),e.consume(r),e.exit(`wikiMarkerTemp`),t(r)):n(r)}}function ee(t){return t===124?(e.consume(t),e.exit(`wikiMarker`),i=!0,p):n(t)}}}const AN=function(){let e=this.data();e.micromarkExtensions=[...e.micromarkExtensions??[],kN()],e.fromMarkdownExtensions=[...e.fromMarkdownExtensions??[],ON()]},jN=RegExp(`^[\\(\\|]?(\\d{1,2})(?:[\\s\\).\\|]|$)(.*)$`,`v`),MN={...Cy};async function NN(e,t){let{allFilePaths:n,basePath:r,cwd:i,obsidianVault:a,resolveUrls:o}=w(MN,t??{}),s=Rv().use(Mk).use(MC,[{anywhere:!1,marker:`-`,type:`yaml`}]).use(AN).use(OO,{singleTilde:!1}).use(DN,{allFilePaths:n,basePath:r,cwd:i,enabled:o,obsidianVault:a}).use(qO).use(PO).use(fC).use(XS);return s.run(s.parse(e))}function PN(e){return e.type===`text`}function FN(e,t){return A(e,t,(e,t,n)=>{if(!(!n||t===void 0))return n.children.splice(t,1),!1}),e}function IN(e){let t=e.at(0);t?.type===`text`&&(t.value=t.value.trimStart(),t.value===``&&e.shift());let n=e.at(-1);return n?.type===`text`&&(n.value=n.value.trimEnd(),n.value===``&&e.pop()),e}function LN(e){let t=1;return A(e,`delete`,(e,n,r)=>{if(r===void 0||n===void 0||!(`children`in e)||e.children.length===0)return!0;let[i]=e.children;if(i!==void 0&&PN(i)){let n=jN.exec(i.value);if(n!==null&&(e.children.length>1||(n.at(2)??``).length>0)){let e=Number(n.at(1));Number.isNaN(e)||(t=e,i.value=(n.at(2)?.trim().length??0)>0?n.at(2)??``:``)}}let a=e.children.at(-1),o=e.children.length>1&&a?.type===`emphasis`?[K(`text`,`{{c${t}::`),...IN(e.children.slice(0,-1)),K(`text`,`::`),...IN(e.children.slice(-1)),K(`text`,`}}`)]:[K(`text`,`{{c${t}::`),...IN(e.children),K(`text`,`}}`)];return r.children.splice(n,1,...o),t+=1,!0}),e}function RN(e){let t,n=!1;return A(e,`thematicBreak`,(e,r,i)=>r===void 0||i===void 0?!0:(t=r,i.children[r+1]?.type===`thematicBreak`&&(n=!0),!1)),t===void 0?[e,void 0]:[{children:e.children.slice(0,t),type:`root`},{children:e.children.slice(t+(n?2:1)),type:`root`}]}function zN(e){let t;if(A(e,e=>e.type===`thematicBreak`?(t=void 0,!1):e.type===`delete`?(t=`Yanki - Cloze`,!1):!0),t!==void 0)return t;if(!VN(e)&&HN(e))return`Yanki - Basic (type in the answer)`;let n;return A(e,(e,r,i)=>{if(i===null||r===null)return!0;if(e.type===`thematicBreak`){if(t===void 0)t=`Yanki - Basic`;else if(t===`Yanki - Basic`&&n?.type===`thematicBreak`)return t=`Yanki - Basic (and reversed card with extra)`,!1}return n=e,!0}),t??`Yanki - Basic`}function BN(e){let t;if(A(e,`yaml`,e=>`value`in e?(t=e.value,!1):!0),t===void 0||t===``)return{};let n=hN(t)??void 0;if(n===void 0)throw Error(`Could not parse frontmatter`);return n}function VN(e){let t=!1;return A(e,`thematicBreak`,()=>(t=!0,!1)),t}function HN(e){let t,n=0;return A(e,e=>{if(e.type===`text`&&e.value.trim()!==``)t=e,n++;else if(e.type===`emphasis`&&e.children.some(e=>e.type===`text`&&e.value.trim()!==``))return t=e,n++,Bo;return!0}),t?.type===`emphasis`&&n>1}function UN(e){let t,n,r;if(A(e,`emphasis`,(e,i,a)=>a===void 0||i===void 0||e.type!==`emphasis`?!0:(t=e,n=a,r=i,!0)),n&&t&&typeof r==`number`)return n.children.splice(r,1),t}const WN={namespaceValidationAndSanitization:!0,...Cy};async function GN(e,t){let{allFilePaths:n,basePath:r,cwd:i,fetchAdapter:a=Ty(),fileAdapter:o=await wy(),namespace:s,namespaceValidationAndSanitization:c,obsidianVault:l,resolveUrls:u,strictLineBreaks:d,syncMediaAssets:f}=w(WN,t??{}),p=c?Zy(s):s,m=await NN(e,{allFilePaths:n,basePath:r,cwd:i,obsidianVault:l,resolveUrls:u}),h=zN(m),g=BN(m);m=FN(m,`yaml`);let _=``,v=``,y;switch(h){case`Yanki - Basic`:case`Yanki - Basic (and reversed card with extra)`:{let[e,t]=RN(m),n;if(t!==void 0&&h===`Yanki - Basic (and reversed card with extra)`){y=``;let[e,r]=RN(t);t=e,n=r}_=await Rx(e,{cssClassNames:[dy,`namespace-${p}`,`front`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!0}),v=await Rx(t,{cssClassNames:[dy,`namespace-${p}`,`back`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!0}),n!==void 0&&(y=await Rx(n,{cssClassNames:[dy,`namespace-${p}`,`extra`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!1}));break}case`Yanki - Basic (type in the answer)`:{let e=UN(m);if(e===void 0)throw Error(`Could not find emphasis in Basic (type in the answer) note AST.`);let t=m,n=K(`root`,K(`paragraph`,e.children));_=await Rx(t,{cssClassNames:[dy,`namespace-${p}`,`front`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!0}),v=await Rx(n,{cssClassNames:[dy,`namespace-${p}`,`back`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!1});break}case`Yanki - Cloze`:{let[e,t]=RN(m);_=await Rx(LN(e),{cssClassNames:[dy,`namespace-${p}`,`front`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!0}),v=await Rx(t,{cssClassNames:[dy,`namespace-${p}`,`back`,`model-${h}`],fetchAdapter:a,fileAdapter:o,namespace:p,strictLineBreaks:d,syncMediaAssets:f,useEmptyPlaceholder:!1});break}}return{deckName:``,fields:{Back:v,...y!==void 0&&{Extra:y},Front:_,YankiNamespace:p},modelName:h,noteId:g.noteId??void 0,tags:KN(g.tags)}}function KN(e){return(Array.isArray(e)?e:e===void 0?[]:[e]).map(e=>String(e).replaceAll(`/`,`::`))}const qN={...Cy};async function JN(e,t){let{allFilePaths:n,basePath:r,fetchAdapter:i=Ty(),fileAdapter:a=await wy(),namespace:o,obsidianVault:s,strictLineBreaks:c,syncMediaAssets:l}=w(qN,t??{}),u=Zy(o);e.sort((e,t)=>e.localeCompare(t));let d=XN(e);return await Promise.all(e.map(async(e,t)=>{let o=await a.readFile(e),f=await GN(o,{allFilePaths:n,basePath:r,cwd:q.dirname(e),fetchAdapter:i,fileAdapter:a,namespace:u,namespaceValidationAndSanitization:!1,obsidianVault:s,strictLineBreaks:c,syncMediaAssets:l});return f.deckName===``&&(f.deckName=d[t]??``),{filePath:e,filePathOriginal:e,markdown:o,note:f}}))}const YN={mode:`common-root`};function XN(e,t){let{mode:n}=w(YN,t??{});if(e.length===0)return[];let r=e.map(e=>q.dirname(e).split(q.sep)),i=r.reduce((e,t)=>e.filter((e,n)=>e===t[n])),a=r.some(e=>e.at(-1)===i.at(-1)),o=n===`common-parent`?1:+!!a;return r.map(e=>e.slice(i.length-o).join(`::`))}const ZN={...Cy};async function QN(e,t){let{dryRun:n,fileAdapter:r=await wy(),manageFilenames:i,maxFilenameLength:a}=w(ZN,t??{});if(i!==`off`){let t=[];for(let n of e){let{filePath:e,note:r}=n;if(e===void 0)throw Error(`File path is undefined`);let o=BS(r,i,a),s=HS(q.join(q.dirname(e),`${o}${q.extname(e)}`),t);n.filePath=s,t.push(s.toLowerCase())}for(let n of e){let{filePath:e}=n;if(e===void 0)throw Error(`File path is undefined`);n.filePath=US(e,t)}let o=new Map;for(let t of e){let{filePath:i,filePathOriginal:a}=t;if(a===void 0)throw Error(`Original file path is undefined.`);if(i===void 0)throw Error(`File path is undefined.`);if(i===a)continue;let s=i;e.some(({filePath:e,filePathOriginal:t})=>e!==i&&t?.toLowerCase()===i.toLowerCase())&&(s=KS(i),o.set(s,i)),n||await r.rename(a,s)}for(let[e,t]of o)n||await r.rename(e,t)}return e.sort((e,t)=>e.filePath.localeCompare(t.filePath)),e}const $N={...Cy};async function eP(e,t){let{allFilePaths:n,basePath:r,dryRun:i,fetchAdapter:a=Ty(),fileAdapter:o=await wy(),manageFilenames:s,maxFilenameLength:c,namespace:l,obsidianVault:u,strictLineBreaks:d,syncMediaAssets:f}=w($N,t??{}),p=e.map(e=>Zb(e)),m=r===void 0?void 0:Zb(r);return{dryRun:i,notes:await QN(await JN(p,{allFilePaths:n.map(e=>Zb(e)),basePath:m,fetchAdapter:a,fileAdapter:o,namespace:Zy(l),obsidianVault:u,strictLineBreaks:d,syncMediaAssets:f}),{dryRun:i,fileAdapter:o,manageFilenames:s,maxFilenameLength:c})}}const tP={css:uy,...Cy},nP={...Cy};async function rP(e){let{ankiConnectOptions:t}=w(tP,e??{}),n=new Te(t);if(await wS(n)===`ankiUnreachable`)throw Error(`Anki is unreachable. Is Anki running?`);let r=new Set;for(let e of iS){let t=await xS(n,e);r.add(t)}let[i]=r;if(i===void 0)throw Error(`No CSS found in any Yanki model.`);if(r.size>1)throw Error(`Expected all Yanki models to have identical CSS.`);return i}async function iP(e){let t=performance.now(),{ankiConnectOptions:n,ankiWeb:r,css:i,dryRun:a}=w(tP,e??{}),o=new Te(n);if(await wS(o)===`ankiUnreachable`)throw Error(`Anki is unreachable. Is Anki running?`);let s=[];for(let e of iS){let t=await bS(o,e,i,a);s.push({action:t?`updated`:`unchanged`,name:e})}return s.some(e=>e.action!==`unchanged`),!a&&r&&await TS(o),{ankiWeb:r,dryRun:a,duration:performance.now()-t,models:s}}function aP(e,t=!1){let n=[],r=e.models.filter(e=>e.action===`unchanged`),i=e.models.filter(e=>e.action===`updated`);if(n.push(`${e.dryRun?`Will`:`Successfully`} update ${i.length} ${ue(`model`,i.length)} and left ${r.length} ${ue(`model`,r.length)} unchanged${e.dryRun?``:` in ${ve(e.duration)}`}.`),t){if(i.length>0){n.push(``,e.dryRun?`Models to update:`:`Updated models:`);for(let e of i)n.push(` ${e.name}`)}if(r.length>0){n.push(``,e.dryRun?`Models unchanged:`:`Unchanged models:`);for(let e of r)n.push(` ${e.name}`)}}return n.join(`
1136
+ `)}const oP=RegExp(`\\r?\\n`,`v`);async function sP(e,t){let[n,r]=cP(e),i=e.split(oP);if(n===void 0||r===void 0)return t===void 0?e:[`---`,gN({noteId:t}).trim(),`---
1137
1137
  `,...i].join(`
1138
1138
  `);let a=await hN(i.slice(n+1,r).join(`
1139
1139
  `))??{};if(t===void 0){if(delete a.noteId,Object.keys(a).length===0){let e=i.slice(r+1);return e[0]?.trim()===``?e.slice(1).join(`
1140
1140
  `):e.join(`
1141
1141
  `)}}else a.noteId=t;let o=gN(a,{lineWidth:0}).trim();return[...i.slice(0,n+1),o,...i.slice(r)].join(`
1142
- `)}function sP(e){let t=e.split(aP);if(!t.join(``).trimStart().startsWith(`---`))return[void 0,void 0];let n=t.findIndex(e=>e.startsWith(`---`)),r=t.findIndex((e,t)=>t>n&&e.startsWith(`---`));return n===-1||r===-1?[void 0,void 0]:[n,r]}const cP={...Cy};async function lP(e,t){let n=performance.now(),r=structuredClone(e),{ankiConnectOptions:i,ankiWeb:a,checkDatabase:o,dryRun:s,fileAdapter:c,namespace:l,strictMatching:u}=w(cP,t??{}),d=Zy(l),f=[],p=new Te(i);if(await wS(p)===`ankiUnreachable`)return{ankiWeb:a,deletedDecks:[],deletedMedia:[],dryRun:s,duration:performance.now()-n,fixedDatabase:!1,namespace:d,reuploadedMedia:[],synced:r.map(e=>({action:`ankiUnreachable`,note:e}))};for(let e of r)e.deckName===``&&(e.deckName=`Yanki`);let m=await pS(p,`*`),h=m.filter(e=>e.fields.YankiNamespace===d);for(let e of r){if(e.noteId===void 0)continue;let t=uP(r,e.noteId);if(t.length<=1)continue;let n=dP(t,h.find(t=>t.noteId===e.noteId));for(let e of t)e!==n&&(e.noteId=void 0)}let g=new Set(r.filter(e=>e.noteId!==void 0&&h.some(t=>e.noteId===t.noteId)).map(e=>e.noteId));for(let e of r){let t=m.find(t=>t.noteId===e.noteId);if(t?.fields.YankiNamespace!==d&&(e.noteId=void 0,t=void 0),t===void 0)e.noteId=u?void 0:fP(e,h,g),e.noteId===void 0?(e.noteId=await cS(p,{...e,noteId:void 0},s,c??void 0),f.push({action:`created`,note:e})):f.push({action:`matched`,note:e});else{if(t.noteId===void 0)throw Error(`Remote note ID is undefined`);let n=await lS(p,e,t,s,c??void 0);f.push({action:n?`updated`:`unchanged`,note:e})}if(e.noteId===void 0)throw Error(`Note ID is undefined`);g.add(e.noteId)}let _=h.filter(e=>r.every(t=>t.noteId!==e.noteId));await sS(p,_,s);for(let e of _)f.push({action:`deleted`,note:e});let v=[],y=[];for(let e of f)e.action===`deleted`?y.push(e.note):v.push(e.note);let b=await vS(p,v,h,s),x=!1;if(o){let e=h.filter(e=>f.some(t=>t.action===`updated`&&t.note.noteId===e.noteId&&t.note.modelName!==e.modelName));if(e.length>0){let t=e.flatMap(({cards:e})=>e??[]);try{await p.card.cardsInfo({cards:t})}catch{x=!0,await p.graphical.guiCheckDatabase(),await p.miscellaneous.reloadCollection()}}}let{deleted:S,reuploaded:ee}=await CS(p,v,d,s,c??void 0);return b.length>0||f.some(e=>e.action!==`unchanged`),!s&&a&&await TS(p),{ankiWeb:a,deletedDecks:b,deletedMedia:S,dryRun:s,duration:performance.now()-n,fixedDatabase:x,namespace:d,reuploadedMedia:ee,synced:f}}function uP(e,t){return e.filter(e=>e.noteId!==void 0&&e.noteId===t)}function dP(e,t){return e.find(e=>e.fields.Front===t?.fields.Front&&e.fields.Back===t.fields.Back&&e.fields.Extra===t.fields.Extra)??e[0]}function fP(e,t,n){return t.find(t=>t.noteId!==void 0&&!n.has(t.noteId)&&dS(e,t,!1))?.noteId??void 0}const pP={...Cy,...cP};async function mP(e,t){let n=performance.now(),{allFilePaths:r,ankiConnectOptions:i,ankiWeb:a,basePath:o,checkDatabase:s,dryRun:c,fetchAdapter:l=Ty(),fileAdapter:u=await wy(),manageFilenames:d,maxFilenameLength:f,namespace:p,obsidianVault:m,strictLineBreaks:h,strictMatching:g,syncMediaAssets:_}=w(pP,t??{}),v=e.map(e=>Zb(e)),y=o===void 0?void 0:Zb(o),b=r.map(e=>Zb(e)),x=Zy(p),S=await ZN(await qN(v,{allFilePaths:b,basePath:y,fetchAdapter:l,fileAdapter:u,namespace:x,obsidianVault:m,strictLineBreaks:h,syncMediaAssets:_}),{dryRun:c,fileAdapter:u,manageFilenames:d,maxFilenameLength:f});if(m!==void 0&&!c&&S.some(e=>e.filePath!==e.filePathOriginal)){let e=await qN(S.map(e=>e.filePath),{allFilePaths:b.map(e=>{let t=S.find(t=>t.filePathOriginal===e);return t?t.filePath:e}),basePath:y,fetchAdapter:l,fileAdapter:u,namespace:x,obsidianVault:m,strictLineBreaks:h,syncMediaAssets:_});for(let[t,n]of S.entries())n.note=e[t].note}let{deletedDecks:ee,deletedMedia:te,fixedDatabase:C,reuploadedMedia:ne,synced:T}=await lP(S.map(e=>e.note),{ankiConnectOptions:i,ankiWeb:a,checkDatabase:s,dryRun:c,fileAdapter:u,namespace:x,strictMatching:g}),re=T.filter(e=>e.action!==`deleted`);for(let[e,t]of S.entries()){let n=re[e];if((t.note.noteId===void 0||t.note.noteId!==n.note.noteId)&&n.action!==`ankiUnreachable`){let e=await oP(t.markdown,n.note.noteId);c||await u.writeFile(t.filePath,e)}n.filePath=t.filePath,n.filePathOriginal=t.filePathOriginal}let ie=[...T.filter(e=>e.action===`deleted`).map(e=>({action:`deleted`,filePath:void 0,filePathOriginal:void 0,note:e.note})),...re].toSorted((e,t)=>(e.filePath??``).localeCompare(t.filePath??``));return{ankiWeb:a,deletedDecks:ee,deletedMedia:te,dryRun:c,duration:performance.now()-n,fixedDatabase:C,namespace:x,reuploadedMedia:ne,synced:ie}}function hP(e,t=!1){let n=[],{synced:r}=e,i=r.reduce((e,t)=>(e[t.action]=(e[t.action]??0)+1,e),{}),a=r.filter(e=>e.action!==`deleted`).length,o=r.filter(e=>e.filePath!==e.filePathOriginal).length,s=(i.ankiUnreachable??0)>0;if(n.push(`${e.dryRun?`Will sync`:s?`Failed to sync`:`Successfully synced`} ${a} ${ue(`note`,a)} to Anki${e.dryRun?``:` in ${ve(e.duration)}`}.`),t){n.push(``,e.dryRun?`Sync Plan Summary:`:`Sync Summary:`);for(let[e,t]of Object.entries(i))n.push(` ${ty(e)}: ${t}`);o>0&&n.push(``,`Local notes renamed: ${o}`),e.deletedDecks.length>0&&n.push(``,`Decks pruned: ${e.deletedDecks.length}`),e.deletedMedia.length>0&&n.push(``,`Media assets deleted: ${e.deletedMedia.length}`),e.reuploadedMedia.length>0&&n.push(``,`Media assets re-uploaded: ${e.reuploadedMedia.length}`),e.dryRun||n.push(``,`Database automatically fixed: ${e.fixedDatabase?`Yes`:`No`}`),n.push(``,e.dryRun?`Sync Plan Details:`:`Sync Details:`);for(let{action:e,filePath:t,note:i}of r)t===void 0?n.push(` Note ID ${i.noteId} ${ty(e)} (From Anki)`):n.push(` Note ID ${i.noteId} ${ty(e)} ${t}`)}return n.join(`
1143
- `)}export{DS as cleanNotes,ES as defaultCleanOptions,UN as defaultGetNoteFromMarkdownOptions,tP as defaultGetStyleOptions,kS as defaultListOptions,QN as defaultRenameFilesOptions,eP as defaultSetStyleOptions,pP as defaultSyncFilesOptions,cP as defaultSyncNotesOptions,OS as formatCleanResult,jS as formatListResult,iP as formatSetStyleResult,hP as formatSyncFilesResult,WN as getNoteFromMarkdown,nP as getStyle,vx as hostAndPortToUrl,AS as listNotes,$N as renameFiles,rP as setStyle,mP as syncFiles,lP as syncNotes,_x as urlToHostAndPort};
1142
+ `)}function cP(e){let t=e.split(oP);if(!t.join(``).trimStart().startsWith(`---`))return[void 0,void 0];let n=t.findIndex(e=>e.startsWith(`---`)),r=t.findIndex((e,t)=>t>n&&e.startsWith(`---`));return n===-1||r===-1?[void 0,void 0]:[n,r]}const lP={...Cy};async function uP(e,t){let n=performance.now(),r=structuredClone(e),{ankiConnectOptions:i,ankiWeb:a,checkDatabase:o,dryRun:s,fileAdapter:c,namespace:l,strictMatching:u}=w(lP,t??{}),d=Zy(l),f=[],p=new Te(i);if(await wS(p)===`ankiUnreachable`)return{ankiWeb:a,deletedDecks:[],deletedMedia:[],dryRun:s,duration:performance.now()-n,fixedDatabase:!1,namespace:d,reuploadedMedia:[],synced:r.map(e=>({action:`ankiUnreachable`,note:e}))};for(let e of r)e.deckName===``&&(e.deckName=`Yanki`);let m=await pS(p,`*`),h=m.filter(e=>e.fields.YankiNamespace===d);for(let e of r){if(e.noteId===void 0)continue;let t=dP(r,e.noteId);if(t.length<=1)continue;let n=fP(t,h.find(t=>t.noteId===e.noteId));for(let e of t)e!==n&&(e.noteId=void 0)}let g=new Set(r.filter(e=>e.noteId!==void 0&&h.some(t=>e.noteId===t.noteId)).map(e=>e.noteId));for(let e of r){let t=m.find(t=>t.noteId===e.noteId);if(t?.fields.YankiNamespace!==d&&(e.noteId=void 0,t=void 0),t===void 0)e.noteId=u?void 0:pP(e,h,g),e.noteId===void 0?(e.noteId=await cS(p,{...e,noteId:void 0},s,c??void 0),f.push({action:`created`,note:e})):f.push({action:`matched`,note:e});else{if(t.noteId===void 0)throw Error(`Remote note ID is undefined`);let n=await lS(p,e,t,s,c??void 0);f.push({action:n?`updated`:`unchanged`,note:e})}if(e.noteId===void 0)throw Error(`Note ID is undefined`);g.add(e.noteId)}let _=h.filter(e=>r.every(t=>t.noteId!==e.noteId));await sS(p,_,s);for(let e of _)f.push({action:`deleted`,note:e});let v=[],y=[];for(let e of f)e.action===`deleted`?y.push(e.note):v.push(e.note);let b=await vS(p,v,h,s),x=!1;if(o){let e=h.filter(e=>f.some(t=>t.action===`updated`&&t.note.noteId===e.noteId&&t.note.modelName!==e.modelName));if(e.length>0){let t=e.flatMap(({cards:e})=>e??[]);try{await p.card.cardsInfo({cards:t})}catch{x=!0,await p.graphical.guiCheckDatabase(),await p.miscellaneous.reloadCollection()}}}let{deleted:S,reuploaded:ee}=await CS(p,v,d,s,c??void 0);return b.length>0||f.some(e=>e.action!==`unchanged`),!s&&a&&await TS(p),{ankiWeb:a,deletedDecks:b,deletedMedia:S,dryRun:s,duration:performance.now()-n,fixedDatabase:x,namespace:d,reuploadedMedia:ee,synced:f}}function dP(e,t){return e.filter(e=>e.noteId!==void 0&&e.noteId===t)}function fP(e,t){return e.find(e=>e.fields.Front===t?.fields.Front&&e.fields.Back===t.fields.Back&&e.fields.Extra===t.fields.Extra)??e[0]}function pP(e,t,n){return t.find(t=>t.noteId!==void 0&&!n.has(t.noteId)&&dS(e,t,!1))?.noteId??void 0}const mP={...Cy,...lP};async function hP(e,t){let n=performance.now(),{allFilePaths:r,ankiConnectOptions:i,ankiWeb:a,basePath:o,checkDatabase:s,dryRun:c,fetchAdapter:l=Ty(),fileAdapter:u=await wy(),manageFilenames:d,maxFilenameLength:f,namespace:p,obsidianVault:m,strictLineBreaks:h,strictMatching:g,syncMediaAssets:_}=w(mP,t??{}),v=e.map(e=>Zb(e)),y=o===void 0?void 0:Zb(o),b=r.map(e=>Zb(e)),x=Zy(p),S=await QN(await JN(v,{allFilePaths:b,basePath:y,fetchAdapter:l,fileAdapter:u,namespace:x,obsidianVault:m,strictLineBreaks:h,syncMediaAssets:_}),{dryRun:c,fileAdapter:u,manageFilenames:d,maxFilenameLength:f});if(m!==void 0&&!c&&S.some(e=>e.filePath!==e.filePathOriginal)){let e=await JN(S.map(e=>e.filePath),{allFilePaths:b.map(e=>{let t=S.find(t=>t.filePathOriginal===e);return t?t.filePath:e}),basePath:y,fetchAdapter:l,fileAdapter:u,namespace:x,obsidianVault:m,strictLineBreaks:h,syncMediaAssets:_});for(let[t,n]of S.entries())n.note=e[t].note}let{deletedDecks:ee,deletedMedia:te,fixedDatabase:C,reuploadedMedia:ne,synced:T}=await uP(S.map(e=>e.note),{ankiConnectOptions:i,ankiWeb:a,checkDatabase:s,dryRun:c,fileAdapter:u,namespace:x,strictMatching:g}),re=T.filter(e=>e.action!==`deleted`);for(let[e,t]of S.entries()){let n=re[e];if((t.note.noteId===void 0||t.note.noteId!==n.note.noteId)&&n.action!==`ankiUnreachable`){let e=await sP(t.markdown,n.note.noteId);c||await u.writeFile(t.filePath,e)}n.filePath=t.filePath,n.filePathOriginal=t.filePathOriginal}let ie=[...T.filter(e=>e.action===`deleted`).map(e=>({action:`deleted`,filePath:void 0,filePathOriginal:void 0,note:e.note})),...re].toSorted((e,t)=>(e.filePath??``).localeCompare(t.filePath??``));return{ankiWeb:a,deletedDecks:ee,deletedMedia:te,dryRun:c,duration:performance.now()-n,fixedDatabase:C,namespace:x,reuploadedMedia:ne,synced:ie}}function gP(e,t=!1){let n=[],{synced:r}=e,i=r.reduce((e,t)=>(e[t.action]=(e[t.action]??0)+1,e),{}),a=r.filter(e=>e.action!==`deleted`).length,o=r.filter(e=>e.filePath!==e.filePathOriginal).length,s=(i.ankiUnreachable??0)>0;if(n.push(`${e.dryRun?`Will sync`:s?`Failed to sync`:`Successfully synced`} ${a} ${ue(`note`,a)} to Anki${e.dryRun?``:` in ${ve(e.duration)}`}.`),t){n.push(``,e.dryRun?`Sync Plan Summary:`:`Sync Summary:`);for(let[e,t]of Object.entries(i))n.push(` ${ty(e)}: ${t}`);o>0&&n.push(``,`Local notes renamed: ${o}`),e.deletedDecks.length>0&&n.push(``,`Decks pruned: ${e.deletedDecks.length}`),e.deletedMedia.length>0&&n.push(``,`Media assets deleted: ${e.deletedMedia.length}`),e.reuploadedMedia.length>0&&n.push(``,`Media assets re-uploaded: ${e.reuploadedMedia.length}`),e.dryRun||n.push(``,`Database automatically fixed: ${e.fixedDatabase?`Yes`:`No`}`),n.push(``,e.dryRun?`Sync Plan Details:`:`Sync Details:`);for(let{action:e,filePath:t,note:i}of r)t===void 0?n.push(` Note ID ${i.noteId} ${ty(e)} (From Anki)`):n.push(` Note ID ${i.noteId} ${ty(e)} ${t}`)}return n.join(`
1143
+ `)}export{DS as cleanNotes,ES as defaultCleanOptions,WN as defaultGetNoteFromMarkdownOptions,nP as defaultGetStyleOptions,kS as defaultListOptions,$N as defaultRenameFilesOptions,tP as defaultSetStyleOptions,mP as defaultSyncFilesOptions,lP as defaultSyncNotesOptions,OS as formatCleanResult,jS as formatListResult,aP as formatSetStyleResult,gP as formatSyncFilesResult,GN as getNoteFromMarkdown,rP as getStyle,vx as hostAndPortToUrl,AS as listNotes,eP as renameFiles,iP as setStyle,hP as syncFiles,uP as syncNotes,_x as urlToHostAndPort};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yanki",
3
- "version": "2.0.12",
3
+ "version": "2.0.13",
4
4
  "description": "A CLI tool and TypeScript library to turn Markdown into Anki flashcards.",
5
5
  "keywords": [
6
6
  "anki",
@@ -105,7 +105,7 @@
105
105
  },
106
106
  "devDependencies": {
107
107
  "@arethetypeswrong/cli": "^0.18.5",
108
- "@kitschpatrol/shared-config": "^8.2.0",
108
+ "@kitschpatrol/shared-config": "^8.3.0",
109
109
  "@vitest/browser-playwright": "^4.1.10",
110
110
  "@vitest/coverage-v8": "^4.1.10",
111
111
  "bumpp": "^11.1.0",
@@ -114,8 +114,8 @@
114
114
  "playwright": "^1.61.1",
115
115
  "publint": "^0.3.21",
116
116
  "shx": "^0.4.0",
117
- "tsdown": "^0.22.5",
118
- "tsx": "^4.23.0",
117
+ "tsdown": "^0.22.7",
118
+ "tsx": "^4.23.1",
119
119
  "typescript": "~6.0.3",
120
120
  "vitest": "^4.1.10"
121
121
  },