Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.
This commit is contained in:
2
node_modules/hast-util-to-html/lib/omission/closing.d.ts
generated
vendored
Normal file
2
node_modules/hast-util-to-html/lib/omission/closing.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export const closing: import("./omission.js").OmitHandle;
|
||||
//# sourceMappingURL=closing.d.ts.map
|
1
node_modules/hast-util-to-html/lib/omission/closing.d.ts.map
generated
vendored
Normal file
1
node_modules/hast-util-to-html/lib/omission/closing.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"closing.d.ts","sourceRoot":"","sources":["closing.js"],"names":[],"mappings":"AAQA,yDAoBE"}
|
358
node_modules/hast-util-to-html/lib/omission/closing.js
generated
vendored
Normal file
358
node_modules/hast-util-to-html/lib/omission/closing.js
generated
vendored
Normal file
@@ -0,0 +1,358 @@
|
||||
/**
|
||||
* @import {Element, Parents} from 'hast'
|
||||
*/
|
||||
|
||||
import {whitespace} from 'hast-util-whitespace'
|
||||
import {siblingAfter} from './util/siblings.js'
|
||||
import {omission} from './omission.js'
|
||||
|
||||
export const closing = omission({
|
||||
body,
|
||||
caption: headOrColgroupOrCaption,
|
||||
colgroup: headOrColgroupOrCaption,
|
||||
dd,
|
||||
dt,
|
||||
head: headOrColgroupOrCaption,
|
||||
html,
|
||||
li,
|
||||
optgroup,
|
||||
option,
|
||||
p,
|
||||
rp: rubyElement,
|
||||
rt: rubyElement,
|
||||
tbody,
|
||||
td: cells,
|
||||
tfoot,
|
||||
th: cells,
|
||||
thead,
|
||||
tr
|
||||
})
|
||||
|
||||
/**
|
||||
* Macro for `</head>`, `</colgroup>`, and `</caption>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function headOrColgroupOrCaption(_, index, parent) {
|
||||
const next = siblingAfter(parent, index, true)
|
||||
return (
|
||||
!next ||
|
||||
(next.type !== 'comment' &&
|
||||
!(next.type === 'text' && whitespace(next.value.charAt(0))))
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</html>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function html(_, index, parent) {
|
||||
const next = siblingAfter(parent, index)
|
||||
return !next || next.type !== 'comment'
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</body>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function body(_, index, parent) {
|
||||
const next = siblingAfter(parent, index)
|
||||
return !next || next.type !== 'comment'
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</p>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function p(_, index, parent) {
|
||||
const next = siblingAfter(parent, index)
|
||||
return next
|
||||
? next.type === 'element' &&
|
||||
(next.tagName === 'address' ||
|
||||
next.tagName === 'article' ||
|
||||
next.tagName === 'aside' ||
|
||||
next.tagName === 'blockquote' ||
|
||||
next.tagName === 'details' ||
|
||||
next.tagName === 'div' ||
|
||||
next.tagName === 'dl' ||
|
||||
next.tagName === 'fieldset' ||
|
||||
next.tagName === 'figcaption' ||
|
||||
next.tagName === 'figure' ||
|
||||
next.tagName === 'footer' ||
|
||||
next.tagName === 'form' ||
|
||||
next.tagName === 'h1' ||
|
||||
next.tagName === 'h2' ||
|
||||
next.tagName === 'h3' ||
|
||||
next.tagName === 'h4' ||
|
||||
next.tagName === 'h5' ||
|
||||
next.tagName === 'h6' ||
|
||||
next.tagName === 'header' ||
|
||||
next.tagName === 'hgroup' ||
|
||||
next.tagName === 'hr' ||
|
||||
next.tagName === 'main' ||
|
||||
next.tagName === 'menu' ||
|
||||
next.tagName === 'nav' ||
|
||||
next.tagName === 'ol' ||
|
||||
next.tagName === 'p' ||
|
||||
next.tagName === 'pre' ||
|
||||
next.tagName === 'section' ||
|
||||
next.tagName === 'table' ||
|
||||
next.tagName === 'ul')
|
||||
: !parent ||
|
||||
// Confusing parent.
|
||||
!(
|
||||
parent.type === 'element' &&
|
||||
(parent.tagName === 'a' ||
|
||||
parent.tagName === 'audio' ||
|
||||
parent.tagName === 'del' ||
|
||||
parent.tagName === 'ins' ||
|
||||
parent.tagName === 'map' ||
|
||||
parent.tagName === 'noscript' ||
|
||||
parent.tagName === 'video')
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</li>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function li(_, index, parent) {
|
||||
const next = siblingAfter(parent, index)
|
||||
return !next || (next.type === 'element' && next.tagName === 'li')
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</dt>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function dt(_, index, parent) {
|
||||
const next = siblingAfter(parent, index)
|
||||
return Boolean(
|
||||
next &&
|
||||
next.type === 'element' &&
|
||||
(next.tagName === 'dt' || next.tagName === 'dd')
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</dd>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function dd(_, index, parent) {
|
||||
const next = siblingAfter(parent, index)
|
||||
return (
|
||||
!next ||
|
||||
(next.type === 'element' &&
|
||||
(next.tagName === 'dt' || next.tagName === 'dd'))
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</rt>` or `</rp>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function rubyElement(_, index, parent) {
|
||||
const next = siblingAfter(parent, index)
|
||||
return (
|
||||
!next ||
|
||||
(next.type === 'element' &&
|
||||
(next.tagName === 'rp' || next.tagName === 'rt'))
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</optgroup>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function optgroup(_, index, parent) {
|
||||
const next = siblingAfter(parent, index)
|
||||
return !next || (next.type === 'element' && next.tagName === 'optgroup')
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</option>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function option(_, index, parent) {
|
||||
const next = siblingAfter(parent, index)
|
||||
return (
|
||||
!next ||
|
||||
(next.type === 'element' &&
|
||||
(next.tagName === 'option' || next.tagName === 'optgroup'))
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</thead>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function thead(_, index, parent) {
|
||||
const next = siblingAfter(parent, index)
|
||||
return Boolean(
|
||||
next &&
|
||||
next.type === 'element' &&
|
||||
(next.tagName === 'tbody' || next.tagName === 'tfoot')
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</tbody>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function tbody(_, index, parent) {
|
||||
const next = siblingAfter(parent, index)
|
||||
return (
|
||||
!next ||
|
||||
(next.type === 'element' &&
|
||||
(next.tagName === 'tbody' || next.tagName === 'tfoot'))
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</tfoot>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function tfoot(_, index, parent) {
|
||||
return !siblingAfter(parent, index)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</tr>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function tr(_, index, parent) {
|
||||
const next = siblingAfter(parent, index)
|
||||
return !next || (next.type === 'element' && next.tagName === 'tr')
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `</td>` or `</th>`.
|
||||
*
|
||||
* @param {Element} _
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the closing tag can be omitted.
|
||||
*/
|
||||
function cells(_, index, parent) {
|
||||
const next = siblingAfter(parent, index)
|
||||
return (
|
||||
!next ||
|
||||
(next.type === 'element' &&
|
||||
(next.tagName === 'td' || next.tagName === 'th'))
|
||||
)
|
||||
}
|
17
node_modules/hast-util-to-html/lib/omission/omission.d.ts
generated
vendored
Normal file
17
node_modules/hast-util-to-html/lib/omission/omission.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Factory to check if a given node can have a tag omitted.
|
||||
*
|
||||
* @param {Record<string, OmitHandle>} handlers
|
||||
* Omission handlers, where each key is a tag name, and each value is the
|
||||
* corresponding handler.
|
||||
* @returns {OmitHandle}
|
||||
* Whether to omit a tag of an element.
|
||||
*/
|
||||
export function omission(handlers: Record<string, OmitHandle>): OmitHandle;
|
||||
/**
|
||||
* Check if a tag can be omitted.
|
||||
*/
|
||||
export type OmitHandle = (element: Element, index: number | undefined, parent: Parents | undefined) => boolean;
|
||||
import type { Element } from 'hast';
|
||||
import type { Parents } from 'hast';
|
||||
//# sourceMappingURL=omission.d.ts.map
|
1
node_modules/hast-util-to-html/lib/omission/omission.d.ts.map
generated
vendored
Normal file
1
node_modules/hast-util-to-html/lib/omission/omission.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"omission.d.ts","sourceRoot":"","sources":["omission.js"],"names":[],"mappings":"AAoBA;;;;;;;;GAQG;AACH,mCANW,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAGxB,UAAU,CAiBtB;;;;mCApCU,OAAO,SAEP,MAAM,GAAG,SAAS,UAElB,OAAO,GAAG,SAAS,KAEjB,OAAO;6BAZe,MAAM;6BAAN,MAAM"}
|
44
node_modules/hast-util-to-html/lib/omission/omission.js
generated
vendored
Normal file
44
node_modules/hast-util-to-html/lib/omission/omission.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* @import {Element, Parents} from 'hast'
|
||||
*/
|
||||
|
||||
/**
|
||||
* @callback OmitHandle
|
||||
* Check if a tag can be omitted.
|
||||
* @param {Element} element
|
||||
* Element to check.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether to omit a tag.
|
||||
*
|
||||
*/
|
||||
|
||||
const own = {}.hasOwnProperty
|
||||
|
||||
/**
|
||||
* Factory to check if a given node can have a tag omitted.
|
||||
*
|
||||
* @param {Record<string, OmitHandle>} handlers
|
||||
* Omission handlers, where each key is a tag name, and each value is the
|
||||
* corresponding handler.
|
||||
* @returns {OmitHandle}
|
||||
* Whether to omit a tag of an element.
|
||||
*/
|
||||
export function omission(handlers) {
|
||||
return omit
|
||||
|
||||
/**
|
||||
* Check if a given node can have a tag omitted.
|
||||
*
|
||||
* @type {OmitHandle}
|
||||
*/
|
||||
function omit(node, index, parent) {
|
||||
return (
|
||||
own.call(handlers, node.tagName) &&
|
||||
handlers[node.tagName](node, index, parent)
|
||||
)
|
||||
}
|
||||
}
|
2
node_modules/hast-util-to-html/lib/omission/opening.d.ts
generated
vendored
Normal file
2
node_modules/hast-util-to-html/lib/omission/opening.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export const opening: import("./omission.js").OmitHandle;
|
||||
//# sourceMappingURL=opening.d.ts.map
|
1
node_modules/hast-util-to-html/lib/omission/opening.d.ts.map
generated
vendored
Normal file
1
node_modules/hast-util-to-html/lib/omission/opening.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"opening.d.ts","sourceRoot":"","sources":["opening.js"],"names":[],"mappings":"AASA,yDAME"}
|
148
node_modules/hast-util-to-html/lib/omission/opening.js
generated
vendored
Normal file
148
node_modules/hast-util-to-html/lib/omission/opening.js
generated
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
/**
|
||||
* @import {Element, Parents} from 'hast'
|
||||
*/
|
||||
|
||||
import {whitespace} from 'hast-util-whitespace'
|
||||
import {siblingAfter, siblingBefore} from './util/siblings.js'
|
||||
import {closing} from './closing.js'
|
||||
import {omission} from './omission.js'
|
||||
|
||||
export const opening = omission({
|
||||
body,
|
||||
colgroup,
|
||||
head,
|
||||
html,
|
||||
tbody
|
||||
})
|
||||
|
||||
/**
|
||||
* Whether to omit `<html>`.
|
||||
*
|
||||
* @param {Element} node
|
||||
* Element.
|
||||
* @returns {boolean}
|
||||
* Whether the opening tag can be omitted.
|
||||
*/
|
||||
function html(node) {
|
||||
const head = siblingAfter(node, -1)
|
||||
return !head || head.type !== 'comment'
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `<head>`.
|
||||
*
|
||||
* @param {Element} node
|
||||
* Element.
|
||||
* @returns {boolean}
|
||||
* Whether the opening tag can be omitted.
|
||||
*/
|
||||
function head(node) {
|
||||
/** @type {Set<string>} */
|
||||
const seen = new Set()
|
||||
|
||||
// Whether `srcdoc` or not,
|
||||
// make sure the content model at least doesn’t have too many `base`s/`title`s.
|
||||
for (const child of node.children) {
|
||||
if (
|
||||
child.type === 'element' &&
|
||||
(child.tagName === 'base' || child.tagName === 'title')
|
||||
) {
|
||||
if (seen.has(child.tagName)) return false
|
||||
seen.add(child.tagName)
|
||||
}
|
||||
}
|
||||
|
||||
// “May be omitted if the element is empty,
|
||||
// or if the first thing inside the head element is an element.”
|
||||
const child = node.children[0]
|
||||
return !child || child.type === 'element'
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `<body>`.
|
||||
*
|
||||
* @param {Element} node
|
||||
* Element.
|
||||
* @returns {boolean}
|
||||
* Whether the opening tag can be omitted.
|
||||
*/
|
||||
function body(node) {
|
||||
const head = siblingAfter(node, -1, true)
|
||||
|
||||
return (
|
||||
!head ||
|
||||
(head.type !== 'comment' &&
|
||||
!(head.type === 'text' && whitespace(head.value.charAt(0))) &&
|
||||
!(
|
||||
head.type === 'element' &&
|
||||
(head.tagName === 'meta' ||
|
||||
head.tagName === 'link' ||
|
||||
head.tagName === 'script' ||
|
||||
head.tagName === 'style' ||
|
||||
head.tagName === 'template')
|
||||
))
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `<colgroup>`.
|
||||
* The spec describes some logic for the opening tag, but it’s easier to
|
||||
* implement in the closing tag, to the same effect, so we handle it there
|
||||
* instead.
|
||||
*
|
||||
* @param {Element} node
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the opening tag can be omitted.
|
||||
*/
|
||||
function colgroup(node, index, parent) {
|
||||
const previous = siblingBefore(parent, index)
|
||||
const head = siblingAfter(node, -1, true)
|
||||
|
||||
// Previous colgroup was already omitted.
|
||||
if (
|
||||
parent &&
|
||||
previous &&
|
||||
previous.type === 'element' &&
|
||||
previous.tagName === 'colgroup' &&
|
||||
closing(previous, parent.children.indexOf(previous), parent)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
return Boolean(head && head.type === 'element' && head.tagName === 'col')
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to omit `<tbody>`.
|
||||
*
|
||||
* @param {Element} node
|
||||
* Element.
|
||||
* @param {number | undefined} index
|
||||
* Index of element in parent.
|
||||
* @param {Parents | undefined} parent
|
||||
* Parent of element.
|
||||
* @returns {boolean}
|
||||
* Whether the opening tag can be omitted.
|
||||
*/
|
||||
function tbody(node, index, parent) {
|
||||
const previous = siblingBefore(parent, index)
|
||||
const head = siblingAfter(node, -1)
|
||||
|
||||
// Previous table section was already omitted.
|
||||
if (
|
||||
parent &&
|
||||
previous &&
|
||||
previous.type === 'element' &&
|
||||
(previous.tagName === 'thead' || previous.tagName === 'tbody') &&
|
||||
closing(previous, parent.children.indexOf(previous), parent)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
return Boolean(head && head.type === 'element' && head.tagName === 'tr')
|
||||
}
|
36
node_modules/hast-util-to-html/lib/omission/util/siblings.d.ts
generated
vendored
Normal file
36
node_modules/hast-util-to-html/lib/omission/util/siblings.d.ts
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Find applicable siblings in a direction.
|
||||
*
|
||||
* @template {Parents} Parent
|
||||
* Parent type.
|
||||
* @param {Parent | undefined} parent
|
||||
* Parent.
|
||||
* @param {number | undefined} index
|
||||
* Index of child in `parent`.
|
||||
* @param {boolean | undefined} [includeWhitespace=false]
|
||||
* Whether to include whitespace (default: `false`).
|
||||
* @returns {Parent extends {children: Array<infer Child>} ? Child | undefined : never}
|
||||
* Child of parent.
|
||||
*/
|
||||
export function siblingAfter<Parent extends Parents>(parent: Parent | undefined, index: number | undefined, includeWhitespace?: boolean | undefined): Parent extends {
|
||||
children: Array<infer Child>;
|
||||
} ? Child | undefined : never;
|
||||
/**
|
||||
* Find applicable siblings in a direction.
|
||||
*
|
||||
* @template {Parents} Parent
|
||||
* Parent type.
|
||||
* @param {Parent | undefined} parent
|
||||
* Parent.
|
||||
* @param {number | undefined} index
|
||||
* Index of child in `parent`.
|
||||
* @param {boolean | undefined} [includeWhitespace=false]
|
||||
* Whether to include whitespace (default: `false`).
|
||||
* @returns {Parent extends {children: Array<infer Child>} ? Child | undefined : never}
|
||||
* Child of parent.
|
||||
*/
|
||||
export function siblingBefore<Parent extends Parents>(parent: Parent | undefined, index: number | undefined, includeWhitespace?: boolean | undefined): Parent extends {
|
||||
children: Array<infer Child>;
|
||||
} ? Child | undefined : never;
|
||||
import type { Parents } from 'hast';
|
||||
//# sourceMappingURL=siblings.d.ts.map
|
1
node_modules/hast-util-to-html/lib/omission/util/siblings.d.ts.map
generated
vendored
Normal file
1
node_modules/hast-util-to-html/lib/omission/util/siblings.d.ts.map
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"version":3,"file":"siblings.d.ts","sourceRoot":"","sources":["siblings.js"],"names":[],"mappings":"AAoBE;;;;;;;;;;;;;GAaG;AACH,6BAXuB,MAAM,SAAhB,OAAS,UAEX,MAAM,GAAG,SAAS,SAElB,MAAM,GAAG,SAAS,sBAElB,OAAO,GAAG,SAAS,GAEjB,MAAM,SAAS;IAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,KAAK,CAAC,CAAA;CAAC,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,CAiBrF;AA5BD;;;;;;;;;;;;;GAaG;AACH,8BAXuB,MAAM,SAAhB,OAAS,UAEX,MAAM,GAAG,SAAS,SAElB,MAAM,GAAG,SAAS,sBAElB,OAAO,GAAG,SAAS,GAEjB,MAAM,SAAS;IAAC,QAAQ,EAAE,KAAK,CAAC,MAAM,KAAK,CAAC,CAAA;CAAC,GAAG,KAAK,GAAG,SAAS,GAAG,KAAK,CAiBrF;6BA/CoC,MAAM"}
|
50
node_modules/hast-util-to-html/lib/omission/util/siblings.js
generated
vendored
Normal file
50
node_modules/hast-util-to-html/lib/omission/util/siblings.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/**
|
||||
* @import {Parents, RootContent} from 'hast'
|
||||
*/
|
||||
|
||||
import {whitespace} from 'hast-util-whitespace'
|
||||
|
||||
export const siblingAfter = siblings(1)
|
||||
export const siblingBefore = siblings(-1)
|
||||
|
||||
/** @type {Array<RootContent>} */
|
||||
const emptyChildren = []
|
||||
|
||||
/**
|
||||
* Factory to check siblings in a direction.
|
||||
*
|
||||
* @param {number} increment
|
||||
*/
|
||||
function siblings(increment) {
|
||||
return sibling
|
||||
|
||||
/**
|
||||
* Find applicable siblings in a direction.
|
||||
*
|
||||
* @template {Parents} Parent
|
||||
* Parent type.
|
||||
* @param {Parent | undefined} parent
|
||||
* Parent.
|
||||
* @param {number | undefined} index
|
||||
* Index of child in `parent`.
|
||||
* @param {boolean | undefined} [includeWhitespace=false]
|
||||
* Whether to include whitespace (default: `false`).
|
||||
* @returns {Parent extends {children: Array<infer Child>} ? Child | undefined : never}
|
||||
* Child of parent.
|
||||
*/
|
||||
function sibling(parent, index, includeWhitespace) {
|
||||
const siblings = parent ? parent.children : emptyChildren
|
||||
let offset = (index || 0) + increment
|
||||
let next = siblings[offset]
|
||||
|
||||
if (!includeWhitespace) {
|
||||
while (next && whitespace(next)) {
|
||||
offset += increment
|
||||
next = siblings[offset]
|
||||
}
|
||||
}
|
||||
|
||||
// @ts-expect-error: it’s a correct child.
|
||||
return next
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user