This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 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'

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

@@ -0,0 +1,43 @@
/**
* Transform a hast tree to a `parse5` AST.
*
* @param {Nodes} tree
* Tree to transform.
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {Parse5Nodes}
* `parse5` node.
*/
export function toParse5(tree: Nodes, options?: Options | null | undefined): Parse5Nodes;
export type Comment = import('hast').Comment;
export type Doctype = import('hast').Doctype;
export type Element = import('hast').Element;
export type Nodes = import('hast').Nodes;
export type Root = import('hast').Root;
export type RootContent = import('hast').RootContent;
export type Text = import('hast').Text;
export type Parse5Document = import('parse5').DefaultTreeAdapterMap['document'];
export type Parse5Fragment = import('parse5').DefaultTreeAdapterMap['documentFragment'];
export type Parse5Element = import('parse5').DefaultTreeAdapterMap['element'];
export type Parse5Nodes = import('parse5').DefaultTreeAdapterMap['node'];
export type Parse5Doctype = import('parse5').DefaultTreeAdapterMap['documentType'];
export type Parse5Comment = import('parse5').DefaultTreeAdapterMap['commentNode'];
export type Parse5Text = import('parse5').DefaultTreeAdapterMap['textNode'];
export type Parse5Parent = import('parse5').DefaultTreeAdapterMap['parentNode'];
export type Parse5Attribute = import('parse5').Token.Attribute;
export type Schema = import('property-information').Schema;
/**
* Configuration.
*/
export type Options = {
/**
* Which space the document is in (default: `'html'`).
*
* 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;
};
export type Parse5Content = Exclude<Parse5Nodes, Parse5Document | Parse5Fragment>;
export type Space = 'html' | 'svg';

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

@@ -0,0 +1,338 @@
/**
* @typedef {import('hast').Comment} Comment
* @typedef {import('hast').Doctype} Doctype
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Nodes} Nodes
* @typedef {import('hast').Root} Root
* @typedef {import('hast').RootContent} RootContent
* @typedef {import('hast').Text} Text
*
* @typedef {import('parse5').DefaultTreeAdapterMap['document']} Parse5Document
* @typedef {import('parse5').DefaultTreeAdapterMap['documentFragment']} Parse5Fragment
* @typedef {import('parse5').DefaultTreeAdapterMap['element']} Parse5Element
* @typedef {import('parse5').DefaultTreeAdapterMap['node']} Parse5Nodes
* @typedef {import('parse5').DefaultTreeAdapterMap['documentType']} Parse5Doctype
* @typedef {import('parse5').DefaultTreeAdapterMap['commentNode']} Parse5Comment
* @typedef {import('parse5').DefaultTreeAdapterMap['textNode']} Parse5Text
* @typedef {import('parse5').DefaultTreeAdapterMap['parentNode']} Parse5Parent
* @typedef {import('parse5').Token.Attribute} Parse5Attribute
*
* @typedef {import('property-information').Schema} Schema
*/
/**
* @typedef Options
* Configuration.
* @property {Space | null | undefined} [space='html']
* Which space the document is in (default: `'html'`).
*
* 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.
*
* @typedef {Exclude<Parse5Nodes, Parse5Document | Parse5Fragment>} Parse5Content
*
* @typedef {'html' | 'svg'} Space
*/
import {stringify as commas} from 'comma-separated-tokens'
import {ok as assert} from 'devlop'
import {find, html, svg} from 'property-information'
import {stringify as spaces} from 'space-separated-tokens'
import {webNamespaces} from 'web-namespaces'
import {zwitch} from 'zwitch'
/** @type {Options} */
const emptyOptions = {}
const own = {}.hasOwnProperty
const one = zwitch('type', {handlers: {root, element, text, comment, doctype}})
/**
* Transform a hast tree to a `parse5` AST.
*
* @param {Nodes} tree
* Tree to transform.
* @param {Options | null | undefined} [options]
* Configuration (optional).
* @returns {Parse5Nodes}
* `parse5` node.
*/
export function toParse5(tree, options) {
const settings = options || emptyOptions
const space = settings.space
return one(tree, space === 'svg' ? svg : html)
}
/**
* @param {Root} node
* Node (hast) to transform.
* @param {Schema} schema
* Current schema.
* @returns {Parse5Document}
* Parse5 node.
*/
function root(node, schema) {
/** @type {Parse5Document} */
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
* Node (hast) to transform.
* @param {Schema} schema
* Current schema.
* @returns {Parse5Fragment}
* Parse5 node.
*/
function fragment(node, schema) {
/** @type {Parse5Fragment} */
const result = {nodeName: '#document-fragment', childNodes: []}
result.childNodes = all(node.children, result, schema)
patch(node, result)
return result
}
/**
* @param {Doctype} node
* Node (hast) to transform.
* @returns {Parse5Doctype}
* Parse5 node.
*/
function doctype(node) {
/** @type {Parse5Doctype} */
const result = {
nodeName: '#documentType',
name: 'html',
publicId: '',
systemId: '',
parentNode: null
}
patch(node, result)
return result
}
/**
* @param {Text} node
* Node (hast) to transform.
* @returns {Parse5Text}
* Parse5 node.
*/
function text(node) {
/** @type {Parse5Text} */
const result = {
nodeName: '#text',
value: node.value,
parentNode: null
}
patch(node, result)
return result
}
/**
* @param {Comment} node
* Node (hast) to transform.
* @returns {Parse5Comment}
* Parse5 node.
*/
function comment(node) {
/** @type {Parse5Comment} */
const result = {
nodeName: '#comment',
data: node.value,
parentNode: null
}
patch(node, result)
return result
}
/**
* @param {Element} node
* Node (hast) to transform.
* @param {Schema} schema
* Current schema.
* @returns {Parse5Element}
* 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<Parse5Attribute>} */
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)
}
}
}
}
const space = currentSchema.space
// `html` and `svg` both have a space.
assert(space)
/** @type {Parse5Element} */
const result = {
nodeName: node.tagName,
tagName: node.tagName,
attrs,
// @ts-expect-error: `parse5` types are wrong.
namespaceURI: webNamespaces[space],
childNodes: [],
parentNode: null
}
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<number | string> | boolean | number | string | null | undefined} value
* hast property value.
* @returns {Parse5Attribute | undefined}
* Field for runtime, optional.
*/
function createProperty(schema, prop, value) {
const info = find(schema, prop)
// Ignore nullish and `NaN` values.
if (
value === false ||
value === null ||
value === undefined ||
(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 {Parse5Attribute} */
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<RootContent>} children
* List of children.
* @param {Parse5Parent} parentNode
* `parse5` parent node.
* @param {Schema} schema
* Current schema.
* @returns {Array<Parse5Content>}
* Transformed children.
*/
function all(children, parentNode, schema) {
let index = -1
/** @type {Array<Parse5Content>} */
const results = []
if (children) {
while (++index < children.length) {
/** @type {Parse5Content} */
const child = one(children[index], schema)
child.parentNode = parentNode
results.push(child)
}
}
return results
}
/**
* Add position info from `from` to `to`.
*
* @param {Nodes} from
* hast node.
* @param {Parse5Nodes} to
* `parse5` node.
* @returns {undefined}
* Nothing.
*/
function patch(from, to) {
const position = from.position
if (position && position.start && position.end) {
assert(typeof position.start.offset === 'number')
assert(typeof position.end.offset === 'number')
to.sourceCodeLocation = {
startLine: position.start.line,
startCol: position.start.column,
startOffset: position.start.offset,
endLine: position.end.line,
endCol: position.end.column,
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.

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

@@ -0,0 +1,87 @@
{
"name": "hast-util-to-parse5",
"version": "8.0.0",
"description": "hast utility to transform to a `parse5` 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",
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/hast": "^3.0.0",
"comma-separated-tokens": "^2.0.0",
"devlop": "^1.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": "^20.0.0",
"c8": "^8.0.0",
"json-stringify-safe": "^5.0.0",
"parse5": "^7.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"xo": "^0.55.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && type-coverage",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api": "node --conditions development test.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"bracketSpacing": false,
"semi": false,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"useTabs": false
},
"remarkConfig": {
"plugins": [
"remark-preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"ignoreCatch": true,
"strict": true
},
"xo": {
"prettier": true
}
}

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

@@ -0,0 +1,244 @@
# 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 transform to a [`parse5`][parse5] [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[, options])`](#toparse5tree-options)
* [`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 a `parse5` 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 16+), 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@8'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {toParse5} from 'https://esm.sh/hast-util-to-parse5@8?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`][api-to-parse5].
There is no default export.
### `toParse5(tree[, options])`
Transform a hast tree to a `parse5` AST.
###### Parameters
* `tree` ([`HastNode`][hast-node])
— tree to transform
* `options` ([`Options`][api-options], optional)
— configuration
###### Returns
`parse5` node ([`Parse5Node`][parse5-node]).
### `Options`
Configuration (TypeScript type).
###### Fields
* `space` ([`Space`][api-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`][api-options] and
[`Space`][api-space].
## Compatibility
Projects maintained by the unified collective are compatible with maintained
versions of Node.js.
When we cut a new major release, we drop support for unmaintained versions of
Node.
This means we try to keep the current release line, `hast-util-to-parse5@^8`,
compatible with Node.js 16.
## 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/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-to-parse5
[size]: https://bundlejs.com/?q=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
[api-to-parse5]: #toparse5tree-options
[api-options]: #options
[api-space]: #space