🎉 initiate project *astro_rewrite*

This commit is contained in:
sindrekjelsrud 2023-07-19 21:31:30 +02:00
parent ffd4d5e86c
commit 2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions

23
node_modules/hast-util-to-html/lib/handle/comment.d.ts generated vendored Normal file
View file

@ -0,0 +1,23 @@
/**
* Serialize a comment.
*
* @param {Comment} node
* Node to handle.
* @param {number | undefined} _1
* Index of `node` in `parent.
* @param {Parent | undefined} _2
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function comment(
node: Comment,
_1: number | undefined,
_2: Parent | undefined,
state: State
): string
export type Comment = import('../types.js').Comment
export type Parent = import('../types.js').Parent
export type State = import('../types.js').State

45
node_modules/hast-util-to-html/lib/handle/comment.js generated vendored Normal file
View file

@ -0,0 +1,45 @@
/**
* @typedef {import('../types.js').Comment} Comment
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').State} State
*/
import {stringifyEntities} from 'stringify-entities'
/**
* Serialize a comment.
*
* @param {Comment} node
* Node to handle.
* @param {number | undefined} _1
* Index of `node` in `parent.
* @param {Parent | undefined} _2
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function comment(node, _1, _2, state) {
// See: <https://html.spec.whatwg.org/multipage/syntax.html#comments>
return state.settings.bogusComments
? '<?' +
stringifyEntities(
node.value,
Object.assign({}, state.settings.characterReferences, {subset: ['>']})
) +
'>'
: '<!--' + node.value.replace(/^>|^->|<!--|-->|--!>|<!-$/g, encode) + '-->'
/**
* @param {string} $0
*/
function encode($0) {
return stringifyEntities(
$0,
Object.assign({}, state.settings.characterReferences, {
subset: ['<', '>']
})
)
}
}

28
node_modules/hast-util-to-html/lib/handle/doctype.d.ts generated vendored Normal file
View file

@ -0,0 +1,28 @@
/**
* @typedef {import('../types.js').DocType} DocType
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').State} State
*/
/**
* Serialize a doctype.
*
* @param {DocType} _1
* Node to handle.
* @param {number | undefined} _2
* Index of `node` in `parent.
* @param {Parent | undefined} _3
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function doctype(
_1: DocType,
_2: number | undefined,
_3: Parent | undefined,
state: State
): string
export type DocType = import('../types.js').DocType
export type Parent = import('../types.js').Parent
export type State = import('../types.js').State

28
node_modules/hast-util-to-html/lib/handle/doctype.js generated vendored Normal file
View file

@ -0,0 +1,28 @@
/**
* @typedef {import('../types.js').DocType} DocType
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').State} State
*/
/**
* Serialize a doctype.
*
* @param {DocType} _1
* Node to handle.
* @param {number | undefined} _2
* Index of `node` in `parent.
* @param {Parent | undefined} _3
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function doctype(_1, _2, _3, state) {
return (
'<!' +
(state.settings.upperDoctype ? 'DOCTYPE' : 'doctype') +
(state.settings.tightDoctype ? '' : ' ') +
'html>'
)
}

25
node_modules/hast-util-to-html/lib/handle/element.d.ts generated vendored Normal file
View file

@ -0,0 +1,25 @@
/**
* Serialize an element node.
*
* @param {Element} node
* Node to handle.
* @param {number | undefined} index
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function element(
node: Element,
index: number | undefined,
parent: Parent | undefined,
state: State
): string
export type State = import('../types.js').State
export type Parent = import('../types.js').Parent
export type Element = import('../types.js').Element
export type Properties = import('../types.js').Properties
export type PropertyValue = import('../types.js').PropertyValue

268
node_modules/hast-util-to-html/lib/handle/element.js generated vendored Normal file
View file

@ -0,0 +1,268 @@
/**
* @typedef {import('../types.js').State} State
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Element} Element
* @typedef {import('../types.js').Properties} Properties
* @typedef {import('../types.js').PropertyValue} PropertyValue
*/
import {ccount} from 'ccount'
import {stringify as commas} from 'comma-separated-tokens'
import {svg, find} from 'property-information'
import {stringify as spaces} from 'space-separated-tokens'
import {stringifyEntities} from 'stringify-entities'
import {opening} from '../omission/opening.js'
import {closing} from '../omission/closing.js'
/**
* Maps of subsets.
*
* Each value is a matrix of tuples.
* The value at `0` causes parse errors, the value at `1` is valid.
* Of both, the value at `0` is unsafe, and the value at `1` is safe.
*
* @type {Record<'name' | 'unquoted' | 'single' | 'double', Array<[Array<string>, Array<string>]>>}
*/
const constants = {
// See: <https://html.spec.whatwg.org/#attribute-name-state>.
name: [
['\t\n\f\r &/=>'.split(''), '\t\n\f\r "&\'/=>`'.split('')],
['\0\t\n\f\r "&\'/<=>'.split(''), '\0\t\n\f\r "&\'/<=>`'.split('')]
],
// See: <https://html.spec.whatwg.org/#attribute-value-(unquoted)-state>.
unquoted: [
['\t\n\f\r &>'.split(''), '\0\t\n\f\r "&\'<=>`'.split('')],
['\0\t\n\f\r "&\'<=>`'.split(''), '\0\t\n\f\r "&\'<=>`'.split('')]
],
// See: <https://html.spec.whatwg.org/#attribute-value-(single-quoted)-state>.
single: [
["&'".split(''), '"&\'`'.split('')],
["\0&'".split(''), '\0"&\'`'.split('')]
],
// See: <https://html.spec.whatwg.org/#attribute-value-(double-quoted)-state>.
double: [
['"&'.split(''), '"&\'`'.split('')],
['\0"&'.split(''), '\0"&\'`'.split('')]
]
}
/**
* Serialize an element node.
*
* @param {Element} node
* Node to handle.
* @param {number | undefined} index
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
// eslint-disable-next-line complexity
export function element(node, index, parent, state) {
const schema = state.schema
const omit = schema.space === 'svg' ? false : state.settings.omitOptionalTags
let selfClosing =
schema.space === 'svg'
? state.settings.closeEmptyElements
: state.settings.voids.includes(node.tagName.toLowerCase())
/** @type {Array<string>} */
const parts = []
/** @type {string} */
let last
if (schema.space === 'html' && node.tagName === 'svg') {
state.schema = svg
}
const attrs = serializeAttributes(state, node.properties)
const content = state.all(
schema.space === 'html' && node.tagName === 'template' ? node.content : node
)
state.schema = schema
// If the node is categorised as void, but it has children, remove the
// categorisation.
// This enables for example `menuitem`s, which are void in W3C HTML but not
// void in WHATWG HTML, to be stringified properly.
if (content) selfClosing = false
if (attrs || !omit || !opening(node, index, parent)) {
parts.push('<', node.tagName, attrs ? ' ' + attrs : '')
if (
selfClosing &&
(schema.space === 'svg' || state.settings.closeSelfClosing)
) {
last = attrs.charAt(attrs.length - 1)
if (
!state.settings.tightSelfClosing ||
last === '/' ||
(last && last !== '"' && last !== "'")
) {
parts.push(' ')
}
parts.push('/')
}
parts.push('>')
}
parts.push(content)
if (!selfClosing && (!omit || !closing(node, index, parent))) {
parts.push('</' + node.tagName + '>')
}
return parts.join('')
}
/**
* @param {State} state
* @param {Properties | null | undefined} props
* @returns {string}
*/
function serializeAttributes(state, props) {
/** @type {Array<string>} */
const values = []
let index = -1
/** @type {string} */
let key
if (props) {
for (key in props) {
if (props[key] !== undefined && props[key] !== null) {
const value = serializeAttribute(state, key, props[key])
if (value) values.push(value)
}
}
}
while (++index < values.length) {
const last = state.settings.tightAttributes
? values[index].charAt(values[index].length - 1)
: null
// In tight mode, dont add a space after quoted attributes.
if (index !== values.length - 1 && last !== '"' && last !== "'") {
values[index] += ' '
}
}
return values.join('')
}
/**
* @param {State} state
* @param {string} key
* @param {PropertyValue} value
* @returns {string}
*/
// eslint-disable-next-line complexity
function serializeAttribute(state, key, value) {
const info = find(state.schema, key)
const x =
state.settings.allowParseErrors && state.schema.space === 'html' ? 0 : 1
const y = state.settings.allowDangerousCharacters ? 0 : 1
let quote = state.quote
/** @type {string | undefined} */
let result
if (info.overloadedBoolean && (value === info.attribute || value === '')) {
value = true
} else if (
info.boolean ||
(info.overloadedBoolean && typeof value !== 'string')
) {
value = Boolean(value)
}
if (
value === undefined ||
value === null ||
value === false ||
(typeof value === 'number' && Number.isNaN(value))
) {
return ''
}
const name = stringifyEntities(
info.attribute,
Object.assign({}, state.settings.characterReferences, {
// Always encode without parse errors in non-HTML.
subset: constants.name[x][y]
})
)
// No value.
// There is currently only one boolean property in SVG: `[download]` on
// `<a>`.
// This property does not seem to work in browsers (Firefox, Safari, Chrome),
// so I cant test if dropping the value works.
// But I assume that it should:
//
// ```html
// <!doctype html>
// <svg viewBox="0 0 100 100">
// <a href=https://example.com download>
// <circle cx=50 cy=40 r=35 />
// </a>
// </svg>
// ```
//
// See: <https://github.com/wooorm/property-information/blob/main/lib/svg.js>
if (value === true) return name
// `spaces` doesnt accept a second argument, but its given here just to
// keep the code cleaner.
value = Array.isArray(value)
? (info.commaSeparated ? commas : spaces)(value, {
padLeft: !state.settings.tightCommaSeparatedLists
})
: String(value)
if (state.settings.collapseEmptyAttributes && !value) return name
// Check unquoted value.
if (state.settings.preferUnquoted) {
result = stringifyEntities(
value,
Object.assign({}, state.settings.characterReferences, {
subset: constants.unquoted[x][y],
attribute: true
})
)
}
// If we dont want unquoted, or if `value` contains character references when
// unquoted…
if (result !== value) {
// If the alternative is less common than `quote`, switch.
if (
state.settings.quoteSmart &&
ccount(value, quote) > ccount(value, state.alternative)
) {
quote = state.alternative
}
result =
quote +
stringifyEntities(
value,
Object.assign({}, state.settings.characterReferences, {
// Always encode without parse errors in non-HTML.
subset: (quote === "'" ? constants.single : constants.double)[x][y],
attribute: true
})
) +
quote
}
// Dont add a `=` for unquoted empties.
return name + (result ? '=' + result : result)
}

13
node_modules/hast-util-to-html/lib/handle/handle.d.ts generated vendored Normal file
View file

@ -0,0 +1,13 @@
/**
* @type {(node: Node, index: number | undefined, parent: Parent | undefined, state: State) => string}
*/
export const handle: (
node: Node,
index: number | undefined,
parent: Parent | undefined,
state: State
) => string
export type Handle = import('./types.js').Handle
export type State = import('./types.js').State
export type Node = import('./types.js').Node
export type Parent = import('./types.js').Parent

12
node_modules/hast-util-to-html/lib/handle/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,12 @@
/**
* @type {(node: Node, index: number | undefined, parent: Parent | undefined, state: State) => string}
*/
export const handle: (
node: Node,
index: number | undefined,
parent: Parent | undefined,
state: State
) => string
export type State = import('../types.js').State
export type Node = import('../types.js').Node
export type Parent = import('../types.js').Parent

47
node_modules/hast-util-to-html/lib/handle/index.js generated vendored Normal file
View file

@ -0,0 +1,47 @@
/**
* @typedef {import('../types.js').State} State
* @typedef {import('../types.js').Node} Node
* @typedef {import('../types.js').Parent} Parent
*/
import {zwitch} from 'zwitch'
import {comment} from './comment.js'
import {doctype} from './doctype.js'
import {element} from './element.js'
import {raw} from './raw.js'
import {root} from './root.js'
import {text} from './text.js'
/**
* @type {(node: Node, index: number | undefined, parent: Parent | undefined, state: State) => string}
*/
export const handle = zwitch('type', {
invalid,
unknown,
handlers: {comment, doctype, element, raw, root, text}
})
/**
* Fail when a non-node is found in the tree.
*
* @param {unknown} node
* Unknown value.
* @returns {never}
* Never.
*/
function invalid(node) {
throw new Error('Expected node, not `' + node + '`')
}
/**
* Fail when a node with an unknown type is found in the tree.
*
* @param {unknown} node
* Unknown node.
* @returns {never}
* Never.
*/
function unknown(node) {
// @ts-expect-error: `type` is defined.
throw new Error('Cannot compile unknown node `' + node.type + '`')
}

23
node_modules/hast-util-to-html/lib/handle/raw.d.ts generated vendored Normal file
View file

@ -0,0 +1,23 @@
/**
* Serialize a raw node.
*
* @param {Raw} node
* Node to handle.
* @param {number | undefined} index
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function raw(
node: Raw,
index: number | undefined,
parent: Parent | undefined,
state: State
): string
export type State = import('../types.js').State
export type Parent = import('../types.js').Parent
export type Raw = import('../types.js').Raw

27
node_modules/hast-util-to-html/lib/handle/raw.js generated vendored Normal file
View file

@ -0,0 +1,27 @@
/**
* @typedef {import('../types.js').State} State
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Raw} Raw
*/
import {text} from './text.js'
/**
* Serialize a raw node.
*
* @param {Raw} node
* Node to handle.
* @param {number | undefined} index
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function raw(node, index, parent, state) {
return state.settings.allowDangerousHtml
? node.value
: text(node, index, parent, state)
}

28
node_modules/hast-util-to-html/lib/handle/root.d.ts generated vendored Normal file
View file

@ -0,0 +1,28 @@
/**
* @typedef {import('../types.js').Root} Root
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').State} State
*/
/**
* Serialize a root.
*
* @param {Root} node
* Node to handle.
* @param {number | undefined} _1
* Index of `node` in `parent.
* @param {Parent | undefined} _2
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function root(
node: Root,
_1: number | undefined,
_2: Parent | undefined,
state: State
): string
export type Root = import('../types.js').Root
export type Parent = import('../types.js').Parent
export type State = import('../types.js').State

23
node_modules/hast-util-to-html/lib/handle/root.js generated vendored Normal file
View file

@ -0,0 +1,23 @@
/**
* @typedef {import('../types.js').Root} Root
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').State} State
*/
/**
* Serialize a root.
*
* @param {Root} node
* Node to handle.
* @param {number | undefined} _1
* Index of `node` in `parent.
* @param {Parent | undefined} _2
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function root(node, _1, _2, state) {
return state.all(node)
}

24
node_modules/hast-util-to-html/lib/handle/text.d.ts generated vendored Normal file
View file

@ -0,0 +1,24 @@
/**
* Serialize a text node.
*
* @param {Text | Raw} node
* Node to handle.
* @param {number | undefined} _
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function text(
node: Text | Raw,
_: number | undefined,
parent: Parent | undefined,
state: State
): string
export type State = import('../types.js').State
export type Parent = import('../types.js').Parent
export type Raw = import('../types.js').Raw
export type Text = import('../types.js').Text

36
node_modules/hast-util-to-html/lib/handle/text.js generated vendored Normal file
View file

@ -0,0 +1,36 @@
/**
* @typedef {import('../types.js').State} State
* @typedef {import('../types.js').Parent} Parent
* @typedef {import('../types.js').Raw} Raw
* @typedef {import('../types.js').Text} Text
*/
import {stringifyEntities} from 'stringify-entities'
/**
* Serialize a text node.
*
* @param {Text | Raw} node
* Node to handle.
* @param {number | undefined} _
* Index of `node` in `parent.
* @param {Parent | undefined} parent
* Parent of `node`.
* @param {State} state
* Info passed around about the current state.
* @returns {string}
* Serialized node.
*/
export function text(node, _, parent, state) {
// Check if content of `node` should be escaped.
return parent &&
parent.type === 'element' &&
(parent.tagName === 'script' || parent.tagName === 'style')
? node.value
: stringifyEntities(
node.value,
Object.assign({}, state.settings.characterReferences, {
subset: ['<', '&']
})
)
}