🎉 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

3
node_modules/hast-util-to-parse5/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,3 @@
export {toParse5} from './lib/index.js'
export type Options = import('./lib/index.js').Options
export type Space = import('./lib/index.js').Space

6
node_modules/hast-util-to-parse5/index.js generated vendored Normal file
View file

@ -0,0 +1,6 @@
/**
* @typedef {import('./lib/index.js').Options} Options
* @typedef {import('./lib/index.js').Space} Space
*/
export {toParse5} from './lib/index.js'

47
node_modules/hast-util-to-parse5/lib/index.d.ts generated vendored Normal file
View file

@ -0,0 +1,47 @@
/**
* Transform a hast tree to Parse5s AST.
*
* @param {Node} tree
* Tree to transform.
* @param {Options | Space | null | undefined} [options]
* Configuration.
* @returns {P5Node}
* `parse5` node.
*/
export function toParse5(
tree: Node,
options?: Options | Space | null | undefined
): P5Node
export type DefaultTreeAdapterMap = import('parse5').DefaultTreeAdapterMap
export type P5Document = DefaultTreeAdapterMap['document']
export type P5Fragment = DefaultTreeAdapterMap['documentFragment']
export type P5Element = DefaultTreeAdapterMap['element']
export type P5Node = DefaultTreeAdapterMap['node']
export type P5Doctype = DefaultTreeAdapterMap['documentType']
export type P5Comment = DefaultTreeAdapterMap['commentNode']
export type P5Text = DefaultTreeAdapterMap['textNode']
export type P5Parent = DefaultTreeAdapterMap['parentNode']
export type P5Attribute = import('parse5').Token.Attribute
export type P5Child = Exclude<P5Node, P5Document | P5Fragment>
export type Schema = import('property-information').Schema
export type Root = import('hast').Root
export type Doctype = import('hast').DocType
export type Element = import('hast').Element
export type Text = import('hast').Text
export type Comment = import('hast').Comment
export type Content = import('hast').Content
export type Node = Content | Root
export type Space = 'html' | 'svg'
/**
* Configuration.
*/
export type Options = {
/**
* Which space the document is in.
*
* When an `<svg>` element is found in the HTML space, this package already
* automatically switches to and from the SVG space when entering and exiting
* it.
*/
space?: Space | null | undefined
}

321
node_modules/hast-util-to-parse5/lib/index.js generated vendored Normal file
View file

@ -0,0 +1,321 @@
/**
* @typedef {import('parse5').DefaultTreeAdapterMap} DefaultTreeAdapterMap
* @typedef {DefaultTreeAdapterMap['document']} P5Document
* @typedef {DefaultTreeAdapterMap['documentFragment']} P5Fragment
* @typedef {DefaultTreeAdapterMap['element']} P5Element
* @typedef {DefaultTreeAdapterMap['node']} P5Node
* @typedef {DefaultTreeAdapterMap['documentType']} P5Doctype
* @typedef {DefaultTreeAdapterMap['commentNode']} P5Comment
* @typedef {DefaultTreeAdapterMap['textNode']} P5Text
* @typedef {DefaultTreeAdapterMap['parentNode']} P5Parent
* @typedef {import('parse5').Token.Attribute} P5Attribute
* @typedef {Exclude<P5Node, P5Document | P5Fragment>} P5Child
* @typedef {import('property-information').Schema} Schema
* @typedef {import('hast').Root} Root
* @typedef {import('hast').DocType} Doctype
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Text} Text
* @typedef {import('hast').Comment} Comment
* @typedef {import('hast').Content} Content
*/
/**
* @typedef {Content | Root} Node
* @typedef {'html' | 'svg'} Space
*
* @typedef Options
* Configuration.
* @property {Space | null | undefined} [space='html']
* Which space the document is in.
*
* When an `<svg>` element is found in the HTML space, this package already
* automatically switches to and from the SVG space when entering and exiting
* it.
*/
import {stringify as commas} from 'comma-separated-tokens'
import {html, svg, find} from 'property-information'
import {stringify as spaces} from 'space-separated-tokens'
import {webNamespaces} from 'web-namespaces'
import {zwitch} from 'zwitch'
const own = {}.hasOwnProperty
/** @type {(from: Node, schema: Schema) => P5Node} */
const one = zwitch('type', {handlers: {root, element, text, comment, doctype}})
/**
* Transform a hast tree to Parse5s AST.
*
* @param {Node} tree
* Tree to transform.
* @param {Options | Space | null | undefined} [options]
* Configuration.
* @returns {P5Node}
* `parse5` node.
*/
export function toParse5(tree, options) {
const space = options && typeof options === 'object' ? options.space : options
return one(tree, space === 'svg' ? svg : html)
}
/**
* @param {Root} node
* @param {Schema} schema
* Current schema.
* @returns {P5Document}
*/
function root(node, schema) {
/** @type {P5Document} */
const result = {
nodeName: '#document',
// @ts-expect-error: `parse5` uses enums, which are actually strings.
mode: (node.data || {}).quirksMode ? 'quirks' : 'no-quirks',
childNodes: []
}
result.childNodes = all(node.children, result, schema)
patch(node, result)
return result
}
/**
* @param {Root} node
* @param {Schema} schema
* Current schema.
* @returns {P5Fragment}
*/
function fragment(node, schema) {
/** @type {P5Fragment} */
const result = {nodeName: '#document-fragment', childNodes: []}
result.childNodes = all(node.children, result, schema)
patch(node, result)
return result
}
/**
* @param {Doctype} node
* @returns {P5Doctype}
*/
function doctype(node) {
/** @type {P5Doctype} */
const result = {
nodeName: '#documentType',
name: 'html',
publicId: '',
systemId: '',
// @ts-expect-error: change to `null` in a major?
parentNode: undefined
}
patch(node, result)
return result
}
/**
* @param {Text} node
* @returns {P5Text}
*/
function text(node) {
/** @type {P5Text} */
const result = {
nodeName: '#text',
value: node.value,
// @ts-expect-error: no `parentNode`
parentNode: undefined
}
patch(node, result)
return result
}
/**
* @param {Comment} node
* @returns {P5Comment}
*/
function comment(node) {
/** @type {P5Comment} */
const result = {
nodeName: '#comment',
data: node.value,
// @ts-expect-error: no `parentNode`
parentNode: undefined
}
patch(node, result)
return result
}
/**
* @param {Element} node
* @param {Schema} schema
* Current schema.
* @returns {P5Element}
* `parse5` node.
*/
function element(node, schema) {
const parentSchema = schema
let currentSchema = parentSchema
if (
node.type === 'element' &&
node.tagName.toLowerCase() === 'svg' &&
parentSchema.space === 'html'
) {
currentSchema = svg
}
/** @type {Array<P5Attribute>} */
const attrs = []
/** @type {string} */
let prop
if (node.properties) {
for (prop in node.properties) {
if (prop !== 'children' && own.call(node.properties, prop)) {
const result = createProperty(
currentSchema,
prop,
node.properties[prop]
)
if (result) {
attrs.push(result)
}
}
}
}
/** @type {P5Element} */
const result = {
nodeName: node.tagName,
tagName: node.tagName,
attrs,
// @ts-expect-error: html and svg both have a space.
namespaceURI: webNamespaces[currentSchema.space],
childNodes: [],
// @ts-expect-error: no `parentNode`
parentNode: undefined
}
result.childNodes = all(node.children, result, currentSchema)
patch(node, result)
if (node.tagName === 'template' && node.content) {
// @ts-expect-error: `parse5` types are wrong.
result.content = fragment(node.content, currentSchema)
}
return result
}
/**
* Handle a property.
*
* @param {Schema} schema
* Current schema.
* @param {string} prop
* Key.
* @param {Array<string | number> | string | number | boolean | null | undefined} value
* hast property value.
* @returns {P5Attribute | void}
* Field for runtime, optional.
*/
function createProperty(schema, prop, value) {
const info = find(schema, prop)
// Ignore nullish and `NaN` values.
if (
value === undefined ||
value === null ||
value === false ||
(typeof value === 'number' && Number.isNaN(value)) ||
(!value && info.boolean)
) {
return
}
if (Array.isArray(value)) {
// Accept `array`.
// Most props are space-separated.
value = info.commaSeparated ? commas(value) : spaces(value)
}
/** @type {P5Attribute} */
const attribute = {
name: info.attribute,
value: value === true ? '' : String(value)
}
if (info.space && info.space !== 'html' && info.space !== 'svg') {
const index = attribute.name.indexOf(':')
if (index < 0) {
attribute.prefix = ''
} else {
attribute.name = attribute.name.slice(index + 1)
attribute.prefix = info.attribute.slice(0, index)
}
attribute.namespace = webNamespaces[info.space]
}
return attribute
}
/**
* Transform all hast nodes.
*
* @param {Array<Content>} children
* List of children.
* @param {P5Parent} parentNode
* `parse5` parent node.
* @param {Schema} schema
* Current schema.
* @returns {Array<P5Child>}
* Transformed children.
*/
function all(children, parentNode, schema) {
let index = -1
/** @type {Array<P5Child>} */
const results = []
if (children) {
while (++index < children.length) {
/** @type {P5Child} */
// @ts-expect-error assume no document.
const child = one(children[index], schema)
child.parentNode = parentNode
results.push(child)
}
}
return results
}
/**
* Add position info from `from` to `to`.
*
* @param {Node} from
* hast node.
* @param {P5Node} to
* `parse5` node.
* @returns {void}
* Nothing.
*/
function patch(from, to) {
const position = from.position
if (position && position.start && position.end) {
to.sourceCodeLocation = {
startLine: position.start.line,
startCol: position.start.column,
// @ts-expect-error assume this is set.
startOffset: position.start.offset,
endLine: position.end.line,
endCol: position.end.column,
// @ts-expect-error assume this is set.
endOffset: position.end.offset
}
}
}

22
node_modules/hast-util-to-parse5/license generated vendored Normal file
View file

@ -0,0 +1,22 @@
(The MIT License)
Copyright (c) 2016 Titus Wormer <tituswormer@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

86
node_modules/hast-util-to-parse5/package.json generated vendored Normal file
View file

@ -0,0 +1,86 @@
{
"name": "hast-util-to-parse5",
"version": "7.1.0",
"description": "hast utility to transform hast to Parse5s AST",
"license": "MIT",
"keywords": [
"unist",
"hast",
"hast-util",
"util",
"utility",
"html",
"parse5",
"ast",
"tree"
],
"repository": "syntax-tree/hast-util-to-parse5",
"bugs": "https://github.com/syntax-tree/hast-util-to-parse5/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"contributors": [
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/hast": "^2.0.0",
"comma-separated-tokens": "^2.0.0",
"property-information": "^6.0.0",
"space-separated-tokens": "^2.0.0",
"web-namespaces": "^2.0.0",
"zwitch": "^2.0.0"
},
"devDependencies": {
"@types/json-stringify-safe": "^5.0.0",
"@types/node": "^18.0.0",
"c8": "^7.0.0",
"json-stringify-safe": "^5.0.0",
"parse5": "^7.0.0",
"prettier": "^2.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.53.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
"useTabs": false,
"singleQuote": true,
"bracketSpacing": false,
"semi": false,
"trailingComma": "none"
},
"xo": {
"prettier": true
},
"remarkConfig": {
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}

242
node_modules/hast-util-to-parse5/readme.md generated vendored Normal file
View file

@ -0,0 +1,242 @@
# hast-util-to-parse5
[![Build][build-badge]][build]
[![Coverage][coverage-badge]][coverage]
[![Downloads][downloads-badge]][downloads]
[![Size][size-badge]][size]
[![Sponsors][sponsors-badge]][collective]
[![Backers][backers-badge]][collective]
[![Chat][chat-badge]][chat]
[hast][] utility to generate [`parse5`][parse5]s [AST][parse5-node].
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`toParse5(tree[, space|options])`](#toparse5tree-spaceoptions)
* [`Options`](#options)
* [`Space`](#space)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a utility that can turn a hast syntax tree into `parse5`s AST.
Why not use a Parse5 adapter, you might ask?
Well, because its more code weight to use adapters, and more fragile.
## When should I use this?
This package is useful when working with `parse5`, and for some reason want to
generate its AST again.
The inverse utility, [`hast-util-from-parse5`][hast-util-from-parse5], is more
likely what you want.
## Install
This package is [ESM only][esm].
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
```sh
npm install hast-util-to-parse5
```
In Deno with [`esm.sh`][esmsh]:
```js
import {toParse5} from 'https://esm.sh/hast-util-to-parse5@7'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {toParse5} from 'https://esm.sh/hast-util-to-parse5@7?bundle'
</script>
```
## Use
```js
import {toParse5} from 'hast-util-to-parse5'
const tree = toParse5({
type: 'element',
tagName: 'h1',
properties: {},
children: [{type: 'text', value: 'World!'}]
})
console.log(tree)
```
Yields:
```js
{ nodeName: 'h1',
tagName: 'h1',
attrs: [],
namespaceURI: 'http://www.w3.org/1999/xhtml',
childNodes: [ { nodeName: '#text', value: 'World!', parentNode: [Circular] } ] }
```
## API
This package exports the identifier [`toParse5`][toparse5].
There is no default export.
### `toParse5(tree[, space|options])`
Transform a hast tree to Parse5s AST.
###### Parameters
* `tree` ([`HastNode`][hast-node])
— tree to transform
* `space` ([`Space`][space], optional)
— same as `{space: space}`
* `options` ([`Options`][options], optional)
— configuration
###### Returns
`parse5` node ([`Parse5Node`][parse5-node]).
### `Options`
Configuration (TypeScript type).
###### Fields
* `space` ([`Space`][space], optional)
— which space the document is in
### `Space`
Namespace (TypeScript type).
###### Type
```ts
type Space = 'html' | 'svg'
```
## Types
This package is fully typed with [TypeScript][].
It exports the additional types [`Options`][options] and [`Space`][space].
## Compatibility
Projects maintained by the unified collective are compatible with all maintained
versions of Node.js.
As of now, that is Node.js 14.14+ and 16.0+.
Our projects sometimes work with older versions, but this is not guaranteed.
## Security
Use of `hast-util-to-parse5` can open you up to a
[cross-site scripting (XSS)][xss] attack if the hast tree is unsafe.
## Related
* [`hast-util-from-parse5`](https://github.com/syntax-tree/hast-util-from-parse5)
— transform from Parse5s AST to hast
* [`hast-util-to-nlcst`](https://github.com/syntax-tree/hast-util-to-nlcst)
— transform hast to nlcst
* [`hast-util-to-mdast`](https://github.com/syntax-tree/hast-util-to-mdast)
— transform hast to mdast
* [`hast-util-to-xast`](https://github.com/syntax-tree/hast-util-to-xast)
— transform hast to xast
* [`mdast-util-to-hast`](https://github.com/syntax-tree/mdast-util-to-hast)
— transform mdast to hast
* [`mdast-util-to-nlcst`](https://github.com/syntax-tree/mdast-util-to-nlcst)
— transform mdast to nlcst
## Contribute
See [`contributing.md`][contributing] in [`syntax-tree/.github`][health] for
ways to get started.
See [`support.md`][support] for ways to get help.
This project has a [code of conduct][coc].
By interacting with this repository, organization, or community you agree to
abide by its terms.
## License
[MIT][license] © [Titus Wormer][author]
<!-- Definitions -->
[build-badge]: https://github.com/syntax-tree/hast-util-to-parse5/workflows/main/badge.svg
[build]: https://github.com/syntax-tree/hast-util-to-parse5/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-to-parse5.svg
[coverage]: https://codecov.io/github/syntax-tree/hast-util-to-parse5
[downloads-badge]: https://img.shields.io/npm/dm/hast-util-to-parse5.svg
[downloads]: https://www.npmjs.com/package/hast-util-to-parse5
[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-to-parse5.svg
[size]: https://bundlephobia.com/result?p=hast-util-to-parse5
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg
[backers-badge]: https://opencollective.com/unified/backers/badge.svg
[collective]: https://opencollective.com/unified
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg
[chat]: https://github.com/syntax-tree/unist/discussions
[npm]: https://docs.npmjs.com/cli/install
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[typescript]: https://www.typescriptlang.org
[license]: license
[author]: https://wooorm.com
[health]: https://github.com/syntax-tree/.github
[contributing]: https://github.com/syntax-tree/.github/blob/main/contributing.md
[support]: https://github.com/syntax-tree/.github/blob/main/support.md
[coc]: https://github.com/syntax-tree/.github/blob/main/code-of-conduct.md
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[hast]: https://github.com/syntax-tree/hast
[hast-node]: https://github.com/syntax-tree/hast#nodes
[parse5]: https://github.com/inikulin/parse5
[parse5-node]: https://github.com/inikulin/parse5/blob/master/packages/parse5/lib/tree-adapters/default.ts
[hast-util-from-parse5]: https://github.com/syntax-tree/hast-util-from-parse5
[toparse5]: #toparse5tree-spaceoptions
[options]: #options
[space]: #space