vitepress 0.21.3 → 0.22.0

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.
@@ -5,7 +5,8 @@ import { withBase } from './utils';
5
5
  export const dataSymbol = Symbol();
6
6
  export const siteDataRef = shallowRef(parse(serializedSiteData));
7
7
  function parse(data) {
8
- return readonly(JSON.parse(data));
8
+ const parsed = JSON.parse(data);
9
+ return (import.meta.env.DEV ? readonly(parsed) : parsed);
9
10
  }
10
11
  // hmr
11
12
  if (import.meta.hot) {
@@ -1,5 +1,6 @@
1
1
  import { reactive, inject, markRaw, nextTick, readonly } from 'vue';
2
2
  import { inBrowser } from './utils';
3
+ import { siteDataRef } from './data';
3
4
  export const RouterSymbol = Symbol();
4
5
  // we are just using URL to parse the pathname and hash - the base doesn't
5
6
  // matter and is only passed to support same-host hrefs.
@@ -148,7 +149,16 @@ function scrollTo(el, hash, smooth = false) {
148
149
  console.warn(e);
149
150
  }
150
151
  if (target) {
151
- const targetTop = target.offsetTop;
152
+ let offset = siteDataRef.value.scrollOffset;
153
+ if (typeof offset === 'string') {
154
+ offset =
155
+ document.querySelector(offset).getBoundingClientRect().bottom + 24;
156
+ }
157
+ const targetPadding = parseInt(window.getComputedStyle(target).paddingTop, 10);
158
+ const targetTop = window.scrollY +
159
+ target.getBoundingClientRect().top -
160
+ offset +
161
+ targetPadding;
152
162
  // only smooth scroll if distance is smaller than screen height.
153
163
  if (!smooth || Math.abs(targetTop - window.scrollY) > window.innerHeight) {
154
164
  window.scrollTo(0, targetTop);
@@ -6,6 +6,7 @@ import { ComponentOptions } from 'vue';
6
6
  import { ComponentOptionsMixin } from 'vue';
7
7
  import { DefineComponent } from 'vue';
8
8
  import { EmitsOptions } from 'vue';
9
+ import { ExtractPropTypes } from 'vue';
9
10
  import { Ref } from 'vue';
10
11
  import { RendererElement } from 'vue';
11
12
  import { RendererNode } from 'vue';
@@ -14,7 +15,7 @@ import { VNodeProps } from 'vue';
14
15
 
15
16
  export declare const Content: DefineComponent< {}, () => VNode<RendererNode, RendererElement, {
16
17
  [key: string]: any;
17
- }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<{} & {} & {}>, {}>;
18
+ }>, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, EmitsOptions, string, VNodeProps & AllowedComponentProps & ComponentCustomProps, Readonly<ExtractPropTypes< {}>>, {}>;
18
19
 
19
20
  export declare const Debug: ComponentOptions<{}, any, any, any, any, any, any, any>;
20
21
 
@@ -76,6 +77,7 @@ export declare interface SiteData<ThemeConfig = any> {
76
77
  description: string
77
78
  head: HeadConfig[]
78
79
  themeConfig: ThemeConfig
80
+ scrollOffset: number | string
79
81
  locales: Record<string, LocaleConfig>
80
82
  /**
81
83
  * Available locales for the site when it has defined `locales` in its
@@ -1,4 +1,5 @@
1
1
  export const EXTERNAL_URL_RE = /^https?:/i;
2
+ // @ts-ignore
2
3
  export const inBrowser = typeof window !== 'undefined';
3
4
  function findMatchRoot(route, roots) {
4
5
  // first match to the routes with the most deep level.
package/dist/node/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var serve = require('./serve-d0483577.js');
3
+ var serve = require('./serve-9874c5ac.js');
4
4
  require('fs');
5
5
  require('path');
6
6
  require('url');
@@ -256,6 +256,7 @@ export declare interface SiteData<ThemeConfig = any> {
256
256
  description: string
257
257
  head: HeadConfig[]
258
258
  themeConfig: ThemeConfig
259
+ scrollOffset: number | string
259
260
  locales: Record<string, LocaleConfig>
260
261
  /**
261
262
  * Available locales for the site when it has defined `locales` in its
@@ -301,6 +302,11 @@ export declare interface UserConfig<ThemeConfig = any> {
301
302
  srcExclude?: string[];
302
303
  outDir?: string;
303
304
  shouldPreload?: (link: string, page: string) => boolean;
305
+ /**
306
+ * Configure the scroll offset when the theme has a sticky header.
307
+ * Can be a number or a selector element to get the offset from.
308
+ */
309
+ scrollOffset?: number | string;
304
310
  /**
305
311
  * Enable MPA / zero-JS mode
306
312
  * @experimental
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var serve = require('./serve-d0483577.js');
5
+ var serve = require('./serve-9874c5ac.js');
6
6
  require('vite');
7
7
  require('readline');
8
8
  require('assert');
@@ -12302,7 +12302,7 @@ function cleanRoute(siteData, route) {
12302
12302
  const PKG_ROOT = path__default["default"].join(__dirname, "../../");
12303
12303
  const DIST_CLIENT_PATH = path__default["default"].join(__dirname, "../client");
12304
12304
  const APP_PATH = path__default["default"].join(DIST_CLIENT_PATH, "app");
12305
- const SHARED_PATH = path__default["default"].join(DIST_CLIENT_PATH, "shared");
12305
+ path__default["default"].join(DIST_CLIENT_PATH, "shared");
12306
12306
  const DEFAULT_THEME_PATH = path__default["default"].join(DIST_CLIENT_PATH, "theme-default");
12307
12307
  const SITE_DATA_ID = "@siteData";
12308
12308
  const SITE_DATA_REQUEST_PATH = "/" + SITE_DATA_ID;
@@ -12310,7 +12310,7 @@ const vueRuntimePath = "vue/dist/vue.runtime.esm-bundler.js";
12310
12310
  function resolveAliases(root, themeDir) {
12311
12311
  const paths = {
12312
12312
  "/@theme": themeDir,
12313
- "/@shared": SHARED_PATH,
12313
+ "@theme": themeDir,
12314
12314
  [SITE_DATA_ID]: SITE_DATA_REQUEST_PATH
12315
12315
  };
12316
12316
  let vuePath;
@@ -13455,7 +13455,8 @@ async function resolveSiteData(root, userConfig, command = "serve", mode = "deve
13455
13455
  head: userConfig.head || [],
13456
13456
  themeConfig: userConfig.themeConfig || {},
13457
13457
  locales: userConfig.locales || {},
13458
- langs: createLangDictionary(userConfig)
13458
+ langs: createLangDictionary(userConfig),
13459
+ scrollOffset: userConfig.scrollOffset || 90
13459
13460
  };
13460
13461
  }
13461
13462
 
@@ -24508,7 +24509,7 @@ Renderer$1.prototype.renderToken = function renderToken(tokens, idx, options) {
24508
24509
 
24509
24510
  /**
24510
24511
  * Renderer.renderInline(tokens, options, env) -> String
24511
- * - tokens (Array): list on block tokens to renter
24512
+ * - tokens (Array): list on block tokens to render
24512
24513
  * - options (Object): params of parser instance
24513
24514
  * - env (Object): additional data from parsed input (references, for example)
24514
24515
  *
@@ -24535,7 +24536,7 @@ Renderer$1.prototype.renderInline = function (tokens, options, env) {
24535
24536
 
24536
24537
  /** internal
24537
24538
  * Renderer.renderInlineAsText(tokens, options, env) -> String
24538
- * - tokens (Array): list on block tokens to renter
24539
+ * - tokens (Array): list on block tokens to render
24539
24540
  * - options (Object): params of parser instance
24540
24541
  * - env (Object): additional data from parsed input (references, for example)
24541
24542
  *
@@ -24562,7 +24563,7 @@ Renderer$1.prototype.renderInlineAsText = function (tokens, options, env) {
24562
24563
 
24563
24564
  /**
24564
24565
  * Renderer.render(tokens, options, env) -> String
24565
- * - tokens (Array): list on block tokens to renter
24566
+ * - tokens (Array): list on block tokens to render
24566
24567
  * - options (Object): params of parser instance
24567
24568
  * - env (Object): additional data from parsed input (references, for example)
24568
24569
  *
@@ -26492,7 +26493,7 @@ var list$1 = function list(state, startLine, endLine, silent) {
26492
26493
  // This code can fail if plugins use blkIndent as well as lists,
26493
26494
  // but I hope the spec gets fixed long before that happens.
26494
26495
  //
26495
- if (state.tShift[startLine] >= state.blkIndent) {
26496
+ if (state.sCount[startLine] >= state.blkIndent) {
26496
26497
  isTerminatingParagraph = true;
26497
26498
  }
26498
26499
  }
@@ -27644,7 +27645,7 @@ var isSpace$3 = utils$3.isSpace;
27644
27645
 
27645
27646
 
27646
27647
  var newline = function newline(state, silent) {
27647
- var pmax, max, pos = state.pos;
27648
+ var pmax, max, ws, pos = state.pos;
27648
27649
 
27649
27650
  if (state.src.charCodeAt(pos) !== 0x0A/* \n */) { return false; }
27650
27651
 
@@ -27658,7 +27659,11 @@ var newline = function newline(state, silent) {
27658
27659
  if (!silent) {
27659
27660
  if (pmax >= 0 && state.pending.charCodeAt(pmax) === 0x20) {
27660
27661
  if (pmax >= 1 && state.pending.charCodeAt(pmax - 1) === 0x20) {
27661
- state.pending = state.pending.replace(/ +$/, '');
27662
+ // Find whitespaces tail of pending chars.
27663
+ ws = pmax - 1;
27664
+ while (ws >= 1 && state.pending.charCodeAt(ws - 1) === 0x20) ws--;
27665
+
27666
+ state.pending = state.pending.slice(0, ws);
27662
27667
  state.push('hardbreak', 'br', 0);
27663
27668
  } else {
27664
27669
  state.pending = state.pending.slice(0, -1);
@@ -27819,7 +27824,6 @@ strikethrough.tokenize = function strikethrough(state, silent) {
27819
27824
  state.delimiters.push({
27820
27825
  marker: marker,
27821
27826
  length: 0, // disable "rule of 3" length checks meant for emphasis
27822
- jump: i / 2, // for `~~` 1 marker = 2 characters
27823
27827
  token: state.tokens.length - 1,
27824
27828
  end: -1,
27825
27829
  open: scanned.can_open,
@@ -27944,15 +27948,6 @@ emphasis.tokenize = function emphasis(state, silent) {
27944
27948
  //
27945
27949
  length: scanned.length,
27946
27950
 
27947
- // An amount of characters before this one that's equivalent to
27948
- // current one. In plain English: if this delimiter does not open
27949
- // an emphasis, neither do previous `jump` characters.
27950
- //
27951
- // Used to skip sequences like "*****" in one step, for 1st asterisk
27952
- // value will be 0, for 2nd it's 1 and so on.
27953
- //
27954
- jump: i,
27955
-
27956
27951
  // A position of the token this delimiter corresponds to.
27957
27952
  //
27958
27953
  token: state.tokens.length - 1,
@@ -28006,9 +28001,11 @@ function postProcess(state, delimiters) {
28006
28001
  //
28007
28002
  isStrong = i > 0 &&
28008
28003
  delimiters[i - 1].end === startDelim.end + 1 &&
28004
+ // check that first two markers match and adjacent
28005
+ delimiters[i - 1].marker === startDelim.marker &&
28009
28006
  delimiters[i - 1].token === startDelim.token - 1 &&
28010
- delimiters[startDelim.end + 1].token === endDelim.token + 1 &&
28011
- delimiters[i - 1].marker === startDelim.marker;
28007
+ // check that last two markers are adjacent (we can safely assume they match)
28008
+ delimiters[startDelim.end + 1].token === endDelim.token + 1;
28012
28009
 
28013
28010
  ch = String.fromCharCode(startDelim.marker);
28014
28011
 
@@ -28511,9 +28508,28 @@ function processDelimiters(state, delimiters) {
28511
28508
  openersBottom = {},
28512
28509
  max = delimiters.length;
28513
28510
 
28511
+ if (!max) return;
28512
+
28513
+ // headerIdx is the first delimiter of the current (where closer is) delimiter run
28514
+ var headerIdx = 0;
28515
+ var lastTokenIdx = -2; // needs any value lower than -1
28516
+ var jumps = [];
28517
+
28514
28518
  for (closerIdx = 0; closerIdx < max; closerIdx++) {
28515
28519
  closer = delimiters[closerIdx];
28516
28520
 
28521
+ jumps.push(0);
28522
+
28523
+ // markers belong to same delimiter run if:
28524
+ // - they have adjacent tokens
28525
+ // - AND markers are the same
28526
+ //
28527
+ if (delimiters[headerIdx].marker !== closer.marker || lastTokenIdx !== closer.token - 1) {
28528
+ headerIdx = closerIdx;
28529
+ }
28530
+
28531
+ lastTokenIdx = closer.token;
28532
+
28517
28533
  // Length is only used for emphasis-specific "rule of 3",
28518
28534
  // if it's not defined (in strikethrough or 3rd party plugins),
28519
28535
  // we can default it to 0 to disable those checks.
@@ -28532,14 +28548,11 @@ function processDelimiters(state, delimiters) {
28532
28548
 
28533
28549
  minOpenerIdx = openersBottom[closer.marker][(closer.open ? 3 : 0) + (closer.length % 3)];
28534
28550
 
28535
- openerIdx = closerIdx - closer.jump - 1;
28536
-
28537
- // avoid crash if `closer.jump` is pointing outside of the array, see #742
28538
- if (openerIdx < -1) openerIdx = -1;
28551
+ openerIdx = headerIdx - jumps[headerIdx] - 1;
28539
28552
 
28540
28553
  newMinOpenerIdx = openerIdx;
28541
28554
 
28542
- for (; openerIdx > minOpenerIdx; openerIdx -= opener.jump + 1) {
28555
+ for (; openerIdx > minOpenerIdx; openerIdx -= jumps[openerIdx] + 1) {
28543
28556
  opener = delimiters[openerIdx];
28544
28557
 
28545
28558
  if (opener.marker !== closer.marker) continue;
@@ -28569,15 +28582,19 @@ function processDelimiters(state, delimiters) {
28569
28582
  // sure algorithm has linear complexity (see *_*_*_*_*_... case).
28570
28583
  //
28571
28584
  lastJump = openerIdx > 0 && !delimiters[openerIdx - 1].open ?
28572
- delimiters[openerIdx - 1].jump + 1 :
28585
+ jumps[openerIdx - 1] + 1 :
28573
28586
  0;
28574
28587
 
28575
- closer.jump = closerIdx - openerIdx + lastJump;
28588
+ jumps[closerIdx] = closerIdx - openerIdx + lastJump;
28589
+ jumps[openerIdx] = lastJump;
28590
+
28576
28591
  closer.open = false;
28577
28592
  opener.end = closerIdx;
28578
- opener.jump = lastJump;
28579
28593
  opener.close = false;
28580
28594
  newMinOpenerIdx = -1;
28595
+ // treat next token as start of run,
28596
+ // it optimizes skips in **<...>**a**<...>** pathological case
28597
+ lastTokenIdx = -2;
28581
28598
  break;
28582
28599
  }
28583
28600
  }
@@ -35151,7 +35168,7 @@ const headingPlugin = (md, include = ["h2", "h3"]) => {
35151
35168
  };
35152
35169
  };
35153
35170
 
35154
- var e=!1,n={false:"push",true:"unshift",after:"push",before:"unshift"},t={isPermalinkSymbol:!0};function r(r,a,i,l){var o;if(!e){var c="Using deprecated markdown-it-anchor permalink option, see https://github.com/valeriangalliat/markdown-it-anchor#todo-anchor-or-file";"object"==typeof process&&process&&process.emitWarning?process.emitWarning(c):console.warn(c),e=!0;}var s=[Object.assign(new i.Token("link_open","a",1),{attrs:[].concat(a.permalinkClass?[["class",a.permalinkClass]]:[],[["href",a.permalinkHref(r,i)]],Object.entries(a.permalinkAttrs(r,i)))}),Object.assign(new i.Token("html_block","",0),{content:a.permalinkSymbol,meta:t}),new i.Token("link_close","a",-1)];a.permalinkSpace&&i.tokens[l+1].children[n[a.permalinkBefore]](Object.assign(new i.Token("text","",0),{content:" "})),(o=i.tokens[l+1].children)[n[a.permalinkBefore]].apply(o,s);}function a(e){return "#"+e}function i(e){return {}}var l={class:"header-anchor",symbol:"#",renderHref:a,renderAttrs:i};function o(e){function n(t){return t=Object.assign({},n.defaults,t),function(n,r,a,i){return e(n,t,r,a,i)}}return n.defaults=Object.assign({},l),n.renderPermalinkImpl=e,n}var c=o(function(e,r,a,i,l){var o,c=[Object.assign(new i.Token("link_open","a",1),{attrs:[].concat(r.class?[["class",r.class]]:[],[["href",r.renderHref(e,i)]],r.ariaHidden?[["aria-hidden","true"]]:[],Object.entries(r.renderAttrs(e,i)))}),Object.assign(new i.Token("html_inline","",0),{content:r.symbol,meta:t}),new i.Token("link_close","a",-1)];r.space&&i.tokens[l+1].children[n[r.placement]](Object.assign(new i.Token("text","",0),{content:" "})),(o=i.tokens[l+1].children)[n[r.placement]].apply(o,c);});Object.assign(c.defaults,{space:!0,placement:"after",ariaHidden:!1});var s$1=o(c.renderPermalinkImpl);s$1.defaults=Object.assign({},c.defaults,{ariaHidden:!0});var d$1=o(function(e,n,t,r,a){var i=[Object.assign(new r.Token("link_open","a",1),{attrs:[].concat(n.class?[["class",n.class]]:[],[["href",n.renderHref(e,r)]],Object.entries(n.renderAttrs(e,r)))})].concat(r.tokens[a+1].children,[new r.Token("link_close","a",-1)]);r.tokens[a+1]=Object.assign(new r.Token("inline","",0),{children:i});}),u=o(function(e,r,a,i,l){var o;if(!["visually-hidden","aria-label","aria-describedby","aria-labelledby"].includes(r.style))throw new Error("`permalink.linkAfterHeader` called with unknown style option `"+r.style+"`");if(!["aria-describedby","aria-labelledby"].includes(r.style)&&!r.assistiveText)throw new Error("`permalink.linkAfterHeader` called without the `assistiveText` option in `"+r.style+"` style");if("visually-hidden"===r.style&&!r.visuallyHiddenClass)throw new Error("`permalink.linkAfterHeader` called without the `visuallyHiddenClass` option in `visually-hidden` style");var c=i.tokens[l+1].children.filter(function(e){return "text"===e.type||"code_inline"===e.type}).reduce(function(e,n){return e+n.content},""),s=[],d=[];r.class&&d.push(["class",r.class]),d.push(["href",r.renderHref(e,i)]),d.push.apply(d,Object.entries(r.renderAttrs(e,i))),"visually-hidden"===r.style?(s.push(Object.assign(new i.Token("span_open","span",1),{attrs:[["class",r.visuallyHiddenClass]]}),Object.assign(new i.Token("text","",0),{content:r.assistiveText(c)}),new i.Token("span_close","span",-1)),r.space&&s[n[r.placement]](Object.assign(new i.Token("text","",0),{content:" "})),s[n[r.placement]](Object.assign(new i.Token("span_open","span",1),{attrs:[["aria-hidden","true"]]}),Object.assign(new i.Token("html_inline","",0),{content:r.symbol,meta:t}),new i.Token("span_close","span",-1))):s.push(Object.assign(new i.Token("html_inline","",0),{content:r.symbol,meta:t})),"aria-label"===r.style?d.push(["aria-label",r.assistiveText(c)]):["aria-describedby","aria-labelledby"].includes(r.style)&&d.push([r.style,e]);var u=[Object.assign(new i.Token("link_open","a",1),{attrs:d})].concat(s,[new i.Token("link_close","a",-1)]);(o=i.tokens).splice.apply(o,[l+3,0].concat(u));});function f(e,n,t,r){var a=e,i=r;if(t&&Object.prototype.hasOwnProperty.call(n,a))throw new Error("User defined `id` attribute `"+e+"` is not unique. Please fix it in your Markdown to continue.");for(;Object.prototype.hasOwnProperty.call(n,a);)a=e+"-"+i,i+=1;return n[a]=!0,a}function b(e,n){n=Object.assign({},b.defaults,n),e.core.ruler.push("anchor",function(e){for(var t,a={},i=e.tokens,l=Array.isArray(n.level)?(t=n.level,function(e){return t.includes(e)}):function(e){return function(n){return n>=e}}(n.level),o=0;o<i.length;o++){var c=i[o];if("heading_open"===c.type&&l(Number(c.tag.substr(1)))){var s=i[o+1].children.filter(function(e){return "text"===e.type||"code_inline"===e.type}).reduce(function(e,n){return e+n.content},""),d=c.attrGet("id");d=null==d?f(n.slugify(s),a,!1,n.uniqueSlugStartIndex):f(d,a,!0,n.uniqueSlugStartIndex),c.attrSet("id",d),!1!==n.tabIndex&&c.attrSet("tabindex",""+n.tabIndex),"function"==typeof n.permalink?n.permalink(d,n,e,o):(n.permalink||n.renderPermalink&&n.renderPermalink!==r)&&n.renderPermalink(d,n,e,o),o=i.indexOf(c),n.callback&&n.callback(c,{slug:d,title:s});}}});}Object.assign(u.defaults,{style:"visually-hidden",space:!0,placement:"after"}),b.permalink={__proto__:null,legacy:r,renderHref:a,renderAttrs:i,makePermalink:o,linkInsideHeader:c,ariaHidden:s$1,headerLink:d$1,linkAfterHeader:u},b.defaults={level:1,slugify:function(e){return encodeURIComponent(String(e).trim().toLowerCase().replace(/\s+/g,"-"))},uniqueSlugStartIndex:1,tabIndex:"-1",permalink:!1,renderPermalink:r,permalinkClass:s$1.defaults.class,permalinkSpace:s$1.defaults.space,permalinkSymbol:"¶",permalinkBefore:"before"===s$1.defaults.placement,permalinkHref:s$1.defaults.renderHref,permalinkAttrs:s$1.defaults.renderAttrs},b.default=b;
35171
+ var e=!1,n={false:"push",true:"unshift",after:"push",before:"unshift"},t={isPermalinkSymbol:!0};function r(r,a,i,l){var o;if(!e){var c="Using deprecated markdown-it-anchor permalink option, see https://github.com/valeriangalliat/markdown-it-anchor#todo-anchor-or-file";"object"==typeof process&&process&&process.emitWarning?process.emitWarning(c):console.warn(c),e=!0;}var s=[Object.assign(new i.Token("link_open","a",1),{attrs:[].concat(a.permalinkClass?[["class",a.permalinkClass]]:[],[["href",a.permalinkHref(r,i)]],Object.entries(a.permalinkAttrs(r,i)))}),Object.assign(new i.Token("html_block","",0),{content:a.permalinkSymbol,meta:t}),new i.Token("link_close","a",-1)];a.permalinkSpace&&i.tokens[l+1].children[n[a.permalinkBefore]](Object.assign(new i.Token("text","",0),{content:" "})),(o=i.tokens[l+1].children)[n[a.permalinkBefore]].apply(o,s);}function a(e){return "#"+e}function i(e){return {}}var l={class:"header-anchor",symbol:"#",renderHref:a,renderAttrs:i};function o(e){function n(t){return t=Object.assign({},n.defaults,t),function(n,r,a,i){return e(n,t,r,a,i)}}return n.defaults=Object.assign({},l),n.renderPermalinkImpl=e,n}var c=o(function(e,r,a,i,l){var o,c=[Object.assign(new i.Token("link_open","a",1),{attrs:[].concat(r.class?[["class",r.class]]:[],[["href",r.renderHref(e,i)]],r.ariaHidden?[["aria-hidden","true"]]:[],Object.entries(r.renderAttrs(e,i)))}),Object.assign(new i.Token("html_inline","",0),{content:r.symbol,meta:t}),new i.Token("link_close","a",-1)];r.space&&i.tokens[l+1].children[n[r.placement]](Object.assign(new i.Token("text","",0),{content:" "})),(o=i.tokens[l+1].children)[n[r.placement]].apply(o,c);});Object.assign(c.defaults,{space:!0,placement:"after",ariaHidden:!1});var s$1=o(c.renderPermalinkImpl);s$1.defaults=Object.assign({},c.defaults,{ariaHidden:!0});var d$1=o(function(e,n,t,r,a){var i=[Object.assign(new r.Token("link_open","a",1),{attrs:[].concat(n.class?[["class",n.class]]:[],[["href",n.renderHref(e,r)]],Object.entries(n.renderAttrs(e,r)))})].concat(n.safariReaderFix?[new r.Token("span_open","span",1)]:[],r.tokens[a+1].children,n.safariReaderFix?[new r.Token("span_close","span",-1)]:[],[new r.Token("link_close","a",-1)]);r.tokens[a+1]=Object.assign(new r.Token("inline","",0),{children:i});});Object.assign(d$1.defaults,{safariReaderFix:!1});var u=o(function(e,r,a,i,l){var o;if(!["visually-hidden","aria-label","aria-describedby","aria-labelledby"].includes(r.style))throw new Error("`permalink.linkAfterHeader` called with unknown style option `"+r.style+"`");if(!["aria-describedby","aria-labelledby"].includes(r.style)&&!r.assistiveText)throw new Error("`permalink.linkAfterHeader` called without the `assistiveText` option in `"+r.style+"` style");if("visually-hidden"===r.style&&!r.visuallyHiddenClass)throw new Error("`permalink.linkAfterHeader` called without the `visuallyHiddenClass` option in `visually-hidden` style");var c=i.tokens[l+1].children.filter(function(e){return "text"===e.type||"code_inline"===e.type}).reduce(function(e,n){return e+n.content},""),s=[],d=[];r.class&&d.push(["class",r.class]),d.push(["href",r.renderHref(e,i)]),d.push.apply(d,Object.entries(r.renderAttrs(e,i))),"visually-hidden"===r.style?(s.push(Object.assign(new i.Token("span_open","span",1),{attrs:[["class",r.visuallyHiddenClass]]}),Object.assign(new i.Token("text","",0),{content:r.assistiveText(c)}),new i.Token("span_close","span",-1)),r.space&&s[n[r.placement]](Object.assign(new i.Token("text","",0),{content:" "})),s[n[r.placement]](Object.assign(new i.Token("span_open","span",1),{attrs:[["aria-hidden","true"]]}),Object.assign(new i.Token("html_inline","",0),{content:r.symbol,meta:t}),new i.Token("span_close","span",-1))):s.push(Object.assign(new i.Token("html_inline","",0),{content:r.symbol,meta:t})),"aria-label"===r.style?d.push(["aria-label",r.assistiveText(c)]):["aria-describedby","aria-labelledby"].includes(r.style)&&d.push([r.style,e]);var u=[Object.assign(new i.Token("link_open","a",1),{attrs:d})].concat(s,[new i.Token("link_close","a",-1)]);(o=i.tokens).splice.apply(o,[l+3,0].concat(u));});function f(e,n,t,r){var a=e,i=r;if(t&&Object.prototype.hasOwnProperty.call(n,a))throw new Error("User defined `id` attribute `"+e+"` is not unique. Please fix it in your Markdown to continue.");for(;Object.prototype.hasOwnProperty.call(n,a);)a=e+"-"+i,i+=1;return n[a]=!0,a}function b(e,n){n=Object.assign({},b.defaults,n),e.core.ruler.push("anchor",function(e){for(var t,a={},i=e.tokens,l=Array.isArray(n.level)?(t=n.level,function(e){return t.includes(e)}):function(e){return function(n){return n>=e}}(n.level),o=0;o<i.length;o++){var c=i[o];if("heading_open"===c.type&&l(Number(c.tag.substr(1)))){var s=i[o+1].children.filter(function(e){return "text"===e.type||"code_inline"===e.type}).reduce(function(e,n){return e+n.content},""),d=c.attrGet("id");d=null==d?f(n.slugify(s),a,!1,n.uniqueSlugStartIndex):f(d,a,!0,n.uniqueSlugStartIndex),c.attrSet("id",d),!1!==n.tabIndex&&c.attrSet("tabindex",""+n.tabIndex),"function"==typeof n.permalink?n.permalink(d,n,e,o):(n.permalink||n.renderPermalink&&n.renderPermalink!==r)&&n.renderPermalink(d,n,e,o),o=i.indexOf(c),n.callback&&n.callback(c,{slug:d,title:s});}}});}Object.assign(u.defaults,{style:"visually-hidden",space:!0,placement:"after"}),b.permalink={__proto__:null,legacy:r,renderHref:a,renderAttrs:i,makePermalink:o,linkInsideHeader:c,ariaHidden:s$1,headerLink:d$1,linkAfterHeader:u},b.defaults={level:1,slugify:function(e){return encodeURIComponent(String(e).trim().toLowerCase().replace(/\s+/g,"-"))},uniqueSlugStartIndex:1,tabIndex:"-1",permalink:!1,renderPermalink:r,permalinkClass:s$1.defaults.class,permalinkSpace:s$1.defaults.space,permalinkSymbol:"¶",permalinkBefore:"before"===s$1.defaults.placement,permalinkHref:s$1.defaults.renderHref,permalinkAttrs:s$1.defaults.renderAttrs},b.default=b;
35155
35172
 
35156
35173
  var utils$1 = {};
35157
35174
 
@@ -35727,7 +35744,8 @@ var patterns = options => {
35727
35744
  token.nesting = 0;
35728
35745
  let content = tokens[i + 1].content;
35729
35746
  let start = content.lastIndexOf(options.leftDelimiter);
35730
- token.attrs = utils.getAttrs(content, start, options);
35747
+ let attrs = utils.getAttrs(content, start, options);
35748
+ utils.addAttrs(attrs, token);
35731
35749
  token.markup = content;
35732
35750
  tokens.splice(i + 1, 2);
35733
35751
  }
@@ -35744,7 +35762,7 @@ var patterns = options => {
35744
35762
  {
35745
35763
  position: -1,
35746
35764
  content: utils.hasDelimiters('end', options),
35747
- type: (t) => t !== 'code_inline'
35765
+ type: (t) => t !== 'code_inline' && t !== 'math_inline'
35748
35766
  }
35749
35767
  ]
35750
35768
  }
@@ -35827,6 +35845,12 @@ function test(tokens, i, t) {
35827
35845
  let ii = t.shift !== undefined
35828
35846
  ? i + t.shift
35829
35847
  : t.position;
35848
+
35849
+ if (t.shift !== undefined && ii < 0) {
35850
+ // we should never shift to negative indexes (rolling around to back of array)
35851
+ return res;
35852
+ }
35853
+
35830
35854
  let token = get(tokens, ii); // supports negative ii
35831
35855
 
35832
35856
 
@@ -36129,16 +36153,25 @@ var markdownItEmoji = function emoji_plugin(md, options) {
36129
36153
  bare_emoji_plugin(md, opts);
36130
36154
  };
36131
36155
 
36132
- var slugify = function(s){
36133
- return encodeURIComponent(String(s).trim().toLowerCase().replace(/\s+/g, '-'))
36156
+ /*
36157
+ * markdown-it-table-of-contents
36158
+ *
36159
+ * The algorithm works as follows:
36160
+ * Step 1: Gather all headline tokens from a Markdown document and put them in an array.
36161
+ * Step 2: Turn the flat array into a nested tree, respecting the correct headline level.
36162
+ * Step 3: Turn the nested tree into HTML code.
36163
+ */
36164
+
36165
+ const slugify = function (s) {
36166
+ return encodeURIComponent(String(s).trim().toLowerCase().replace(/\s+/g, '-'));
36134
36167
  };
36135
- var defaults$2 = {
36136
- includeLevel: [ 1, 2 ],
36168
+ const defaults$2 = {
36169
+ includeLevel: [1, 2],
36137
36170
  containerClass: 'table-of-contents',
36138
36171
  slugify: slugify,
36139
36172
  markerPattern: /^\[\[toc\]\]/im,
36140
36173
  listType: 'ul',
36141
- format: function(content, md) {
36174
+ format: function (content, md) {
36142
36175
  return md.renderInline(content);
36143
36176
  },
36144
36177
  forceFullToc: false,
@@ -36147,17 +36180,182 @@ var defaults$2 = {
36147
36180
  transformLink: undefined,
36148
36181
  };
36149
36182
 
36150
- var markdownItTableOfContents = function(md, o) {
36151
- var options = Object.assign({}, defaults$2, o);
36152
- var tocRegexp = options.markerPattern;
36153
- var gstate;
36183
+ /**
36184
+ * @typedef {Object} HeadlineItem
36185
+ * @property {number} level Headline level
36186
+ * @property {string} anchor Anchor target
36187
+ * @property {string} text Text of headline
36188
+ */
36189
+
36190
+ /**
36191
+ * @typedef {Object} TocItem
36192
+ * @property {number} level Item level
36193
+ * @property {string} text Text of link
36194
+ * @property {string} anchor Target of link
36195
+ * @property {Array<TocItem>} children Sub-items for this list item
36196
+ * @property {TocItem} parent Parent this item belongs to
36197
+ */
36198
+
36199
+ /**
36200
+ * Finds all headline items for the defined levels in a Markdown document.
36201
+ * @param {Array<number>} levels includeLevels like `[1, 2, 3]`
36202
+ * @param {*} tokens Tokens gathered by the plugin
36203
+ * @param {*} options Plugin options
36204
+ * @returns {Array<HeadlineItem>}
36205
+ */
36206
+ function findHeadlineElements(levels, tokens, options) {
36207
+ const headings = [];
36208
+ let currentHeading = null;
36209
+
36210
+ tokens.forEach(token => {
36211
+ if (token.type === 'heading_open') {
36212
+ const id = findExistingIdAttr(token);
36213
+ const level = parseInt(token.tag.toLowerCase().replace('h', ''), 10);
36214
+ if (levels.indexOf(level) >= 0) {
36215
+ currentHeading = {
36216
+ level: level,
36217
+ text: null,
36218
+ anchor: id || null
36219
+ };
36220
+ }
36221
+ }
36222
+ else if (currentHeading && token.type === 'inline') {
36223
+ const textContent = token.children
36224
+ .filter((childToken) => childToken.type === 'text' || childToken.type === 'code_inline')
36225
+ .reduce((acc, t) => acc + t.content, '');
36226
+ currentHeading.text = textContent;
36227
+ if (! currentHeading.anchor) {
36228
+ currentHeading.anchor = options.slugify(textContent, token.content);
36229
+ }
36230
+ }
36231
+ else if (token.type === 'heading_close') {
36232
+ if (currentHeading) {
36233
+ headings.push(currentHeading);
36234
+ }
36235
+ currentHeading = null;
36236
+ }
36237
+ });
36238
+
36239
+ return headings;
36240
+ }
36241
+
36242
+ /**
36243
+ * Helper to find an existing id attr on a token. Should be a heading_open token, but could be anything really
36244
+ * Provided by markdown-it-anchor or markdown-it-attrs
36245
+ * @param {any} token Token
36246
+ * @returns {string} Id attribute to use as anchor
36247
+ */
36248
+ function findExistingIdAttr(token) {
36249
+ if (token && token.attrs && token.attrs.length > 0) {
36250
+ const idAttr = token.attrs.find( (attr) => {
36251
+ if (Array.isArray(attr) && attr.length >= 2) {
36252
+ return attr[0] === 'id';
36253
+ }
36254
+ return false;
36255
+ });
36256
+ if (idAttr && Array.isArray(idAttr) && idAttr.length >= 2) {
36257
+ const [key, val] = idAttr;
36258
+ return val;
36259
+ }
36260
+ }
36261
+ return null;
36262
+ }
36263
+
36264
+ /**
36265
+ * Helper to get minimum headline level so that the TOC is nested correctly
36266
+ * @param {Array<HeadlineItem>} headlineItems Search these
36267
+ * @returns {number} Minimum level
36268
+ */
36269
+ function getMinLevel(headlineItems) {
36270
+ return Math.min(...headlineItems.map(item => item.level));
36271
+ }
36272
+
36273
+ /**
36274
+ * Helper that creates a TOCItem
36275
+ * @param {number} level
36276
+ * @param {string} text
36277
+ * @param {string} anchor
36278
+ * @param {TocItem} rootNode
36279
+ * @returns {TocItem}
36280
+ */
36281
+ function addListItem(level, text, anchor, rootNode) {
36282
+ const listItem = { level, text, anchor, children: [], parent: rootNode };
36283
+ rootNode.children.push(listItem);
36284
+ return listItem;
36285
+ }
36286
+
36287
+ /**
36288
+ * Turns a list of flat headline items into a nested tree object representing the TOC
36289
+ * @param {Array<HeadlineItem>} headlineItems
36290
+ * @returns {TocItem} Tree of TOC items
36291
+ */
36292
+ function flatHeadlineItemsToNestedTree(headlineItems) {
36293
+ // create a root node with no text that holds the entire TOC. this won't be rendered, but only its children
36294
+ const toc = { level: getMinLevel(headlineItems) - 1, anchor: null, text: null, children: [], parent: null };
36295
+ // pointer that tracks the last root item of the current list
36296
+ let currentRootNode = toc;
36297
+ // pointer that tracks the last item (to turn it into a new root node if necessary)
36298
+ let prevListItem = currentRootNode;
36299
+
36300
+ headlineItems.forEach(headlineItem => {
36301
+ // if level is bigger, take the previous node, add a child list, set current list to this new child list
36302
+ if (headlineItem.level > prevListItem.level) {
36303
+ // eslint-disable-next-line no-unused-vars
36304
+ Array.from({ length: headlineItem.level - prevListItem.level }).forEach(_ => {
36305
+ currentRootNode = prevListItem;
36306
+ prevListItem = addListItem(headlineItem.level, null, null, currentRootNode);
36307
+ });
36308
+ prevListItem.text = headlineItem.text;
36309
+ prevListItem.anchor = headlineItem.anchor;
36310
+ }
36311
+ // if level is same, add to the current list
36312
+ else if (headlineItem.level === prevListItem.level) {
36313
+ prevListItem = addListItem(headlineItem.level, headlineItem.text, headlineItem.anchor, currentRootNode);
36314
+ }
36315
+ // if level is smaller, set current list to currentlist.parent
36316
+ else if (headlineItem.level < prevListItem.level) {
36317
+ for (let i = 0; i < prevListItem.level - headlineItem.level; i++) {
36318
+ currentRootNode = currentRootNode.parent;
36319
+ }
36320
+ prevListItem = addListItem(headlineItem.level, headlineItem.text, headlineItem.anchor, currentRootNode);
36321
+ }
36322
+ });
36323
+
36324
+ return toc;
36325
+ }
36326
+
36327
+ /**
36328
+ * Recursively turns a nested tree of tocItems to HTML.
36329
+ * @param {TocItem} tocItem
36330
+ * @returns {string}
36331
+ */
36332
+ function tocItemToHtml(tocItem, options, md) {
36333
+ return '<' + options.listType + '>' + tocItem.children.map(childItem => {
36334
+ let li = '<li>';
36335
+ let anchor = childItem.anchor;
36336
+ if (options && options.transformLink) {
36337
+ anchor = options.transformLink(anchor);
36338
+ }
36339
+
36340
+ let text = childItem.text ? options.format(childItem.text, md, anchor) : null;
36341
+
36342
+ li += anchor ? `<a href="#${anchor}">${text}</a>` : (text || '');
36343
+
36344
+ return li + (childItem.children.length > 0 ? tocItemToHtml(childItem, options, md) : '') + '</li>';
36345
+ }).join('') + '</' + options.listType + '>';
36346
+ }
36347
+
36348
+ var markdownItTableOfContents = function (md, o) {
36349
+ const options = Object.assign({}, defaults$2, o);
36350
+ const tocRegexp = options.markerPattern;
36351
+ let gstate;
36154
36352
 
36155
36353
  function toc(state, silent) {
36156
- var token;
36157
- var match;
36354
+ let token;
36355
+ let match;
36158
36356
 
36159
36357
  // Reject if the token does not start with [
36160
- if (state.src.charCodeAt(state.pos) !== 0x5B /* [ */ ) {
36358
+ if (state.src.charCodeAt(state.pos) !== 0x5B /* [ */) {
36161
36359
  return false;
36162
36360
  }
36163
36361
  // Don't run any pairs in validation mode
@@ -36167,7 +36365,7 @@ var markdownItTableOfContents = function(md, o) {
36167
36365
 
36168
36366
  // Detect TOC markdown
36169
36367
  match = tocRegexp.exec(state.src.substr(state.pos));
36170
- match = !match ? [] : match.filter(function(m) { return m; });
36368
+ match = !match ? [] : match.filter(function (m) { return m; });
36171
36369
  if (match.length < 1) {
36172
36370
  return false;
36173
36371
  }
@@ -36189,8 +36387,8 @@ var markdownItTableOfContents = function(md, o) {
36189
36387
  return true;
36190
36388
  }
36191
36389
 
36192
- md.renderer.rules.toc_open = function(tokens, index) {
36193
- var tocOpenHtml = '<div class="'+ options.containerClass +'">';
36390
+ md.renderer.rules.toc_open = function (tokens, index) {
36391
+ var tocOpenHtml = '<div class="' + options.containerClass + '">';
36194
36392
 
36195
36393
  if (options.containerHeaderHtml) {
36196
36394
  tocOpenHtml += options.containerHeaderHtml;
@@ -36199,7 +36397,7 @@ var markdownItTableOfContents = function(md, o) {
36199
36397
  return tocOpenHtml;
36200
36398
  };
36201
36399
 
36202
- md.renderer.rules.toc_close = function(tokens, index) {
36400
+ md.renderer.rules.toc_close = function (tokens, index) {
36203
36401
  var tocFooterHtml = '';
36204
36402
 
36205
36403
  if (options.containerFooterHtml) {
@@ -36209,69 +36407,19 @@ var markdownItTableOfContents = function(md, o) {
36209
36407
  return tocFooterHtml + '</div>';
36210
36408
  };
36211
36409
 
36212
- md.renderer.rules.toc_body = function(tokens, index) {
36410
+ md.renderer.rules.toc_body = function (tokens, index) {
36213
36411
  if (options.forceFullToc) {
36214
- throw("forceFullToc was removed in version 0.5.0. For more information, see https://github.com/Oktavilla/markdown-it-table-of-contents/pull/41")
36412
+ throw ("forceFullToc was removed in version 0.5.0. For more information, see https://github.com/Oktavilla/markdown-it-table-of-contents/pull/41");
36215
36413
  } else {
36216
- return renderChildsTokens(0, gstate.tokens)[1];
36414
+ const headlineItems = findHeadlineElements(options.includeLevel, gstate.tokens, options);
36415
+ const toc = flatHeadlineItemsToNestedTree(headlineItems);
36416
+ const html = tocItemToHtml(toc, options, md);
36417
+ return html;
36217
36418
  }
36218
36419
  };
36219
36420
 
36220
- function renderChildsTokens(pos, tokens) {
36221
- var headings = [],
36222
- buffer = '',
36223
- currentLevel,
36224
- subHeadings,
36225
- size = tokens.length,
36226
- i = pos;
36227
- while(i < size) {
36228
- var token = tokens[i];
36229
- var heading = tokens[i - 1];
36230
- var level = token.tag && parseInt(token.tag.substr(1, 1));
36231
- if (token.type !== 'heading_close' || options.includeLevel.indexOf(level) == -1 || heading.type !== 'inline') {
36232
- i++; continue; // Skip if not matching criteria
36233
- }
36234
- if (!currentLevel) {
36235
- currentLevel = level;// We init with the first found level
36236
- } else {
36237
- if (level > currentLevel) {
36238
- subHeadings = renderChildsTokens(i, tokens);
36239
- buffer += subHeadings[1];
36240
- i = subHeadings[0];
36241
- continue;
36242
- }
36243
- if (level < currentLevel) {
36244
- // Finishing the sub headings
36245
- buffer += "</li>";
36246
- headings.push(buffer);
36247
- return [i, "<"+ options.listType +">"+ headings.join('') +"</"+ options.listType +">"];
36248
- }
36249
- if (level == currentLevel) {
36250
- // Finishing the sub headings
36251
- buffer += "</li>";
36252
- headings.push(buffer);
36253
- }
36254
- }
36255
- var content = heading.children
36256
- .filter((token) => token.type === 'text' || token.type === 'code_inline')
36257
- .reduce((acc, t) => acc + t.content, '');
36258
- var slugifiedContent = options.slugify(content);
36259
- var link = "#"+slugifiedContent;
36260
- if (options.transformLink) {
36261
- link = options.transformLink(link);
36262
- }
36263
- buffer = `<li><a href="${link}">`;
36264
- buffer += options.format(content, md, link);
36265
- buffer += `</a>`;
36266
- i++;
36267
- }
36268
- buffer += buffer === '' ? '' : '</li>';
36269
- headings.push(buffer);
36270
- return [i, "<"+ options.listType +">"+ headings.join('') +"</"+ options.listType +">"];
36271
- }
36272
-
36273
36421
  // Catch all the tokens for iteration later
36274
- md.core.ruler.push('grab_state', function(state) {
36422
+ md.core.ruler.push('grab_state', function (state) {
36275
36423
  gstate = state;
36276
36424
  });
36277
36425
 
@@ -36318,6 +36466,11 @@ const createMarkdownRenderer = (srcDir, options = {}) => {
36318
36466
  if (options.lineNumbers) {
36319
36467
  md.use(lineNumberPlugin);
36320
36468
  }
36469
+ const originalRender = md.render;
36470
+ md.render = (...args) => {
36471
+ md.__data = {};
36472
+ return originalRender.call(md, ...args);
36473
+ };
36321
36474
  return md;
36322
36475
  };
36323
36476
 
@@ -36351,7 +36504,6 @@ function createMarkdownToVueRenderFn(srcDir, options = {}, pages, userDefines, i
36351
36504
  const { content, data: frontmatter } = grayMatter(src);
36352
36505
  md.__path = file;
36353
36506
  md.__relativePath = relativePath;
36354
- md.__data = {};
36355
36507
  let html = md.render(content);
36356
36508
  const data = md.__data;
36357
36509
  if (isBuild) {
@@ -36427,12 +36579,12 @@ export default {}<\/script>`);
36427
36579
  return tags;
36428
36580
  }
36429
36581
  const inferTitle = (frontmatter, content) => {
36430
- if (frontmatter.home) {
36431
- return "Home";
36432
- }
36433
36582
  if (frontmatter.title) {
36434
36583
  return deeplyParseHeader(frontmatter.title);
36435
36584
  }
36585
+ if (frontmatter.home) {
36586
+ return "Home";
36587
+ }
36436
36588
  const match = content.match(/^\s*#+\s+(.*)/m);
36437
36589
  if (match) {
36438
36590
  return deeplyParseHeader(match[1].trim());
@@ -40079,7 +40231,7 @@ async function renderPage(config, page, result, appChunk, cssChunk, pageToHashMa
40079
40231
  const { __pageData } = require(path__default["default"].join(config.tempDir, pageServerJsFileName));
40080
40232
  const pageData = JSON.parse(__pageData);
40081
40233
  let preloadLinks = config.mpa ? appChunk ? [appChunk.fileName] : [] : result && appChunk ? [
40082
- ...new Set([
40234
+ .../* @__PURE__ */ new Set([
40083
40235
  ...resolvePageImports(config, page, result, appChunk),
40084
40236
  pageClientJsFileName,
40085
40237
  appChunk.fileName
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitepress",
3
- "version": "0.21.3",
3
+ "version": "0.22.0",
4
4
  "description": "Vite & Vue powered static site generator",
5
5
  "main": "dist/node/index.js",
6
6
  "typings": "types/index.d.ts",
@@ -11,7 +11,8 @@
11
11
  "bin",
12
12
  "dist",
13
13
  "types",
14
- "client.d.ts"
14
+ "client.d.ts",
15
+ "theme.d.ts"
15
16
  ],
16
17
  "engines": {
17
18
  "node": ">=12.0.0"
@@ -45,10 +46,10 @@
45
46
  "dependencies": {
46
47
  "@docsearch/css": "^3.0.0-alpha.41",
47
48
  "@docsearch/js": "^3.0.0-alpha.41",
48
- "@vitejs/plugin-vue": "^2.0.0",
49
+ "@vitejs/plugin-vue": "^2.2.0",
49
50
  "prismjs": "^1.25.0",
50
- "vite": "^2.7.0",
51
- "vue": "^3.2.26"
51
+ "vite": "^2.8.0",
52
+ "vue": "^3.2.30"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@microsoft/api-extractor": "^7.18.9",
@@ -59,7 +60,6 @@
59
60
  "@types/compression": "^1.7.0",
60
61
  "@types/debug": "^4.1.7",
61
62
  "@types/fs-extra": "^9.0.11",
62
- "@types/jest": "^26.0.23",
63
63
  "@types/koa": "^2.13.1",
64
64
  "@types/koa-static": "^4.0.1",
65
65
  "@types/lru-cache": "^5.1.0",
@@ -74,22 +74,21 @@
74
74
  "debug": "^4.3.2",
75
75
  "diacritics": "^1.3.0",
76
76
  "enquirer": "^2.3.6",
77
- "esbuild": "^0.13.4",
77
+ "esbuild": "^0.14.0",
78
78
  "escape-html": "^1.0.3",
79
79
  "execa": "^5.0.0",
80
80
  "fast-glob": "^3.2.7",
81
81
  "fs-extra": "^10.0.0",
82
82
  "globby": "^11.0.3",
83
83
  "gray-matter": "^4.0.3",
84
- "jest": "^27.0.1",
85
84
  "lint-staged": "^11.0.0",
86
85
  "lru-cache": "^6.0.0",
87
- "markdown-it": "^12.0.6",
88
- "markdown-it-anchor": "^8.1.2",
89
- "markdown-it-attrs": "^4.0.0",
86
+ "markdown-it": "^12.3.2",
87
+ "markdown-it-anchor": "^8.4.1",
88
+ "markdown-it-attrs": "^4.1.3",
90
89
  "markdown-it-container": "^3.0.0",
91
90
  "markdown-it-emoji": "^2.0.0",
92
- "markdown-it-table-of-contents": "^0.5.2",
91
+ "markdown-it-table-of-contents": "^0.6.0",
93
92
  "micromatch": "^4.0.4",
94
93
  "minimist": "^1.2.5",
95
94
  "npm-run-all": "^4.1.5",
@@ -98,11 +97,11 @@
98
97
  "prettier": "^2.3.0",
99
98
  "rimraf": "^3.0.2",
100
99
  "rollup": "^2.56.3",
101
- "rollup-plugin-esbuild": "^4.5.0",
100
+ "rollup-plugin-esbuild": "^4.8.2",
102
101
  "semver": "^7.3.5",
103
102
  "sirv": "^1.0.12",
104
- "ts-jest": "^27.0.1",
105
103
  "typescript": "^4.3.2",
104
+ "vitest": "^0.1.19",
106
105
  "yorkie": "^2.0.0"
107
106
  },
108
107
  "scripts": {
@@ -122,7 +121,7 @@
122
121
  "lint": "run-s lint:js lint:ts",
123
122
  "lint:js": "prettier --check --write \"{bin,docs,scripts,src}/**/*.js\"",
124
123
  "lint:ts": "prettier --check --write --parser typescript \"{__tests__,src,docs,types}/**/*.ts\"",
125
- "test": "jest",
124
+ "test": "vitest run __tests__ -c __tests__/vitest.config.js --global",
126
125
  "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
127
126
  "release": "node scripts/release.js",
128
127
  "docs": "run-p dev docs-dev",
package/theme.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ // so that users can do `import DefaultTheme from 'vitepress/theme'`
2
+ import { ComponentOptions } from 'vue'
3
+
4
+ declare const defaultTheme: {
5
+ Layout: ComponentOptions
6
+ NotFound: ComponentOptions
7
+ }
8
+
9
+ export default defaultTheme
package/types/shared.d.ts CHANGED
@@ -22,6 +22,7 @@ export interface SiteData<ThemeConfig = any> {
22
22
  description: string
23
23
  head: HeadConfig[]
24
24
  themeConfig: ThemeConfig
25
+ scrollOffset: number | string
25
26
  locales: Record<string, LocaleConfig>
26
27
  /**
27
28
  * Available locales for the site when it has defined `locales` in its
@@ -1,311 +0,0 @@
1
- import { AliasOptions } from 'vite';
2
- import anchor from 'markdown-it-anchor';
3
- import { BuildOptions } from 'vite';
4
- import MarkdownIt from 'markdown-it';
5
- import { Options } from '@vitejs/plugin-vue';
6
- import { ServerOptions } from 'vite';
7
- import { UserConfig as UserConfig_2 } from 'vite';
8
- import { ViteDevServer } from 'vite';
9
-
10
- export declare function build(root: string, buildOptions?: BuildOptions & {
11
- mpa?: string;
12
- }): Promise<void>;
13
-
14
- export declare const createMarkdownRenderer: (srcDir: string, options?: MarkdownOptions) => MarkdownRenderer;
15
-
16
- export declare function createServer(root?: string, serverOptions?: ServerOptions): Promise<ViteDevServer>;
17
-
18
- export declare namespace DefaultTheme {
19
- export interface Config {
20
- logo?: string
21
- nav?: NavItem[] | false
22
- sidebar?: SideBarConfig | MultiSideBarConfig
23
-
24
- /**
25
- * GitHub repository following the format <user>/<project>.
26
- *
27
- * @example `"vuejs/vue-next"`
28
- */
29
- repo?: string
30
-
31
- /**
32
- * Customize the header label. Defaults to GitHub/Gitlab/Bitbucket
33
- * depending on the provided repo.
34
- *
35
- * @example `"Contribute!"`
36
- */
37
- repoLabel?: string
38
-
39
- /**
40
- * If your docs are in a different repository from your main project.
41
- *
42
- * @example `"vuejs/docs-next"`
43
- */
44
- docsRepo?: string
45
-
46
- /**
47
- * If your docs are not at the root of the repo.
48
- *
49
- * @example `"docs"`
50
- */
51
- docsDir?: string
52
-
53
- /**
54
- * If your docs are in a different branch. Defaults to `master`.
55
- *
56
- * @example `"next"`
57
- */
58
- docsBranch?: string
59
-
60
- /**
61
- * Enable links to edit pages at the bottom of the page.
62
- */
63
- editLinks?: boolean
64
-
65
- /**
66
- * Custom text for edit link. Defaults to "Edit this page".
67
- */
68
- editLinkText?: string
69
-
70
- /**
71
- * Show last updated time at the bottom of the page. Defaults to `false`.
72
- * If given a string, it will be displayed as a prefix (default value:
73
- * "Last Updated").
74
- */
75
- lastUpdated?: string | boolean
76
-
77
- prevLinks?: boolean
78
- nextLinks?: boolean
79
-
80
- locales?: Record<string, LocaleConfig & Omit<Config, 'locales'>>
81
-
82
- algolia?: AlgoliaSearchOptions
83
-
84
- carbonAds?: {
85
- carbon: string
86
- custom?: string
87
- placement: string
88
- }
89
- }
90
-
91
- // navbar --------------------------------------------------------------------
92
-
93
- export type NavItem = NavItemWithLink | NavItemWithChildren
94
-
95
- export interface NavItemBase {
96
- text: string
97
- target?: string
98
- rel?: string
99
- ariaLabel?: string
100
- activeMatch?: string
101
- }
102
-
103
- export interface NavItemWithLink extends NavItemBase {
104
- link: string
105
- }
106
-
107
- export interface NavItemWithChildren extends NavItemBase {
108
- items: NavItemWithLink[]
109
- }
110
-
111
- // sidebar -------------------------------------------------------------------
112
-
113
- export type SideBarConfig = SideBarItem[] | 'auto' | false
114
-
115
- export interface MultiSideBarConfig {
116
- [path: string]: SideBarConfig
117
- }
118
-
119
- export type SideBarItem = SideBarLink | SideBarGroup
120
-
121
- export interface SideBarLink {
122
- text: string
123
- link: string
124
- }
125
-
126
- export interface SideBarGroup {
127
- text: string
128
- link?: string
129
-
130
- /**
131
- * @default false
132
- */
133
- collapsable?: boolean
134
-
135
- children: SideBarItem[]
136
- }
137
-
138
- // algolia ------------------------------------------------------------------
139
- // partially copied from @docsearch/react/dist/esm/DocSearch.d.ts
140
- export interface AlgoliaSearchOptions {
141
- appId?: string
142
- apiKey: string
143
- indexName: string
144
- placeholder?: string
145
- searchParameters?: any
146
- disableUserPersonalization?: boolean
147
- initialQuery?: string
148
- }
149
-
150
- // locales -------------------------------------------------------------------
151
-
152
- export interface LocaleConfig {
153
- /**
154
- * Text for the language dropdown.
155
- */
156
- selectText?: string
157
-
158
- /**
159
- * Label for this locale in the language dropdown.
160
- */
161
- label?: string
162
- }
163
- }
164
-
165
- /**
166
- * Type config helper
167
- */
168
- export declare function defineConfig(config: UserConfig<DefaultTheme.Config>): UserConfig<DefaultTheme.Config>;
169
-
170
- /**
171
- * Type config helper for custom theme config
172
- */
173
- export declare function defineConfigWithTheme<ThemeConfig>(config: UserConfig<ThemeConfig>): UserConfig<ThemeConfig>;
174
-
175
- export declare type HeadConfig =
176
- | [string, Record<string, string>]
177
- | [string, Record<string, string>, string]
178
-
179
- export declare interface Header {
180
- level: number
181
- title: string
182
- slug: string
183
- }
184
-
185
- export declare interface LocaleConfig {
186
- lang: string
187
- title?: string
188
- description?: string
189
- head?: HeadConfig[]
190
- label?: string
191
- selectText?: string
192
- }
193
-
194
- export declare interface MarkdownOptions extends MarkdownIt.Options {
195
- lineNumbers?: boolean;
196
- config?: (md: MarkdownIt) => void;
197
- anchor?: {
198
- permalink?: anchor.AnchorOptions['permalink'];
199
- };
200
- attrs?: {
201
- leftDelimiter?: string;
202
- rightDelimiter?: string;
203
- allowedAttributes?: string[];
204
- };
205
- toc?: any;
206
- externalLinks?: Record<string, string>;
207
- }
208
-
209
- export declare interface MarkdownParsedData {
210
- hoistedTags?: string[];
211
- links?: string[];
212
- headers?: Header[];
213
- }
214
-
215
- export declare interface MarkdownRenderer extends MarkdownIt {
216
- __path: string;
217
- __relativePath: string;
218
- __data: MarkdownParsedData;
219
- }
220
-
221
- export declare type RawConfigExports<ThemeConfig = any> = UserConfig<ThemeConfig> | Promise<UserConfig<ThemeConfig>> | (() => UserConfig<ThemeConfig> | Promise<UserConfig<ThemeConfig>>);
222
-
223
- export declare function resolveConfig(root?: string, command?: 'serve' | 'build', mode?: string): Promise<SiteConfig>;
224
-
225
- export declare function resolveSiteData(root: string, userConfig?: UserConfig, command?: 'serve' | 'build', mode?: string): Promise<SiteData>;
226
-
227
- export declare function resolveSiteDataByRoute(siteData: SiteData, route: string): SiteData;
228
-
229
- export declare function serve(options?: ServeOptions): Promise<void>;
230
-
231
- export declare interface ServeOptions {
232
- root?: string;
233
- port?: number;
234
- }
235
-
236
- export declare interface SiteConfig<ThemeConfig = any> extends Pick<UserConfig, 'markdown' | 'vue' | 'vite' | 'shouldPreload' | 'mpa'> {
237
- root: string;
238
- srcDir: string;
239
- site: SiteData<ThemeConfig>;
240
- configPath: string | undefined;
241
- themeDir: string;
242
- outDir: string;
243
- tempDir: string;
244
- alias: AliasOptions;
245
- pages: string[];
246
- }
247
-
248
- export declare interface SiteData<ThemeConfig = any> {
249
- base: string
250
- /**
251
- * Language of the site as it should be set on the `html` element.
252
- * @example `en-US`, `zh-CN`
253
- */
254
- lang: string
255
- title: string
256
- description: string
257
- head: HeadConfig[]
258
- themeConfig: ThemeConfig
259
- locales: Record<string, LocaleConfig>
260
- /**
261
- * Available locales for the site when it has defined `locales` in its
262
- * `themeConfig`. This object is otherwise empty. Keys are paths like `/` or
263
- * `/zh/`.
264
- */
265
- langs: Record<
266
- string,
267
- {
268
- /**
269
- * Lang attribute as set on the `<html>` element.
270
- * @example `en-US`, `zh-CN`
271
- */
272
- lang: string
273
- /**
274
- * Label to display in the language menu.
275
- * @example `English`, `简体中文`
276
- */
277
- label: string
278
- }
279
- >
280
- }
281
-
282
- export declare interface UserConfig<ThemeConfig = any> {
283
- extends?: RawConfigExports<ThemeConfig>;
284
- lang?: string;
285
- base?: string;
286
- title?: string;
287
- description?: string;
288
- head?: HeadConfig[];
289
- themeConfig?: ThemeConfig;
290
- locales?: Record<string, LocaleConfig>;
291
- markdown?: MarkdownOptions;
292
- /**
293
- * Options to pass on to `@vitejs/plugin-vue`
294
- */
295
- vue?: Options;
296
- /**
297
- * Vite config
298
- */
299
- vite?: UserConfig_2;
300
- srcDir?: string;
301
- srcExclude?: string[];
302
- outDir?: string;
303
- shouldPreload?: (link: string, page: string) => boolean;
304
- /**
305
- * Enable MPA / zero-JS mode
306
- * @experimental
307
- */
308
- mpa?: boolean;
309
- }
310
-
311
- export { }