🎉 initiate project *astro_rewrite*
This commit is contained in:
parent
ffd4d5e86c
commit
2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions
1
node_modules/hast-util-parse-selector/index.d.ts
generated
vendored
Normal file
1
node_modules/hast-util-parse-selector/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
export {parseSelector} from './lib/index.js'
|
||||
1
node_modules/hast-util-parse-selector/index.js
generated
vendored
Normal file
1
node_modules/hast-util-parse-selector/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
export {parseSelector} from './lib/index.js'
|
||||
1
node_modules/hast-util-parse-selector/lib/extract-legacy.ts
generated
vendored
Normal file
1
node_modules/hast-util-parse-selector/lib/extract-legacy.ts
generated
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
export type ExtractTagName<X, Y> = string
|
||||
16
node_modules/hast-util-parse-selector/lib/extract.d.ts
generated
vendored
Normal file
16
node_modules/hast-util-parse-selector/lib/extract.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
export type ExtractTagName<
|
||||
SimpleSelector extends string,
|
||||
DefaultTagName extends string
|
||||
> = SimpleSelector extends `#${infer Rest}`
|
||||
? DefaultTagName
|
||||
: SimpleSelector extends `.${infer Rest}`
|
||||
? DefaultTagName
|
||||
: SimpleSelector extends `${infer TagName}.${infer Rest}`
|
||||
? ExtractTagName<TagName, DefaultTagName>
|
||||
: SimpleSelector extends `${infer TagName}#${infer Rest}`
|
||||
? TagName
|
||||
: SimpleSelector extends ''
|
||||
? DefaultTagName
|
||||
: SimpleSelector extends string
|
||||
? SimpleSelector
|
||||
: DefaultTagName
|
||||
16
node_modules/hast-util-parse-selector/lib/extract.ts
generated
vendored
Normal file
16
node_modules/hast-util-parse-selector/lib/extract.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
export type ExtractTagName<
|
||||
SimpleSelector extends string,
|
||||
DefaultTagName extends string
|
||||
> = SimpleSelector extends `#${infer Rest}`
|
||||
? DefaultTagName
|
||||
: SimpleSelector extends `.${infer Rest}`
|
||||
? DefaultTagName
|
||||
: SimpleSelector extends `${infer TagName}.${infer Rest}`
|
||||
? ExtractTagName<TagName, DefaultTagName>
|
||||
: SimpleSelector extends `${infer TagName}#${infer Rest}`
|
||||
? TagName
|
||||
: SimpleSelector extends ''
|
||||
? DefaultTagName
|
||||
: SimpleSelector extends string
|
||||
? SimpleSelector
|
||||
: DefaultTagName
|
||||
29
node_modules/hast-util-parse-selector/lib/index.d.ts
generated
vendored
Normal file
29
node_modules/hast-util-parse-selector/lib/index.d.ts
generated
vendored
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/**
|
||||
* Create a hast element from a simple CSS selector.
|
||||
*
|
||||
* @template {string} Selector
|
||||
* Type of selector.
|
||||
* @template {string} [DefaultTagName='div']
|
||||
* Type of default tag name.
|
||||
* @param {Selector | null | undefined} [selector]
|
||||
* Simple CSS selector.
|
||||
*
|
||||
* Can contain a tag-name (`foo`), classes (`.bar`), and an ID (`#baz`).
|
||||
* Multiple classes are allowed.
|
||||
* Uses the last ID if multiple IDs are found.
|
||||
* @param {DefaultTagName | null | undefined} [defaultTagName='div']
|
||||
* Tag name to use if `selector` does not specify one (default: `'div'`).
|
||||
* @returns {Element & {tagName: import('./extract.js').ExtractTagName<Selector, DefaultTagName>}}
|
||||
* Built element.
|
||||
*/
|
||||
export function parseSelector<
|
||||
Selector extends string,
|
||||
DefaultTagName extends string = 'div'
|
||||
>(
|
||||
selector?: Selector | null | undefined,
|
||||
defaultTagName?: DefaultTagName | null | undefined
|
||||
): import('hast').Element & {
|
||||
tagName: import('./extract.js').ExtractTagName<Selector, DefaultTagName>
|
||||
}
|
||||
export type Properties = import('hast').Properties
|
||||
export type Element = import('hast').Element
|
||||
68
node_modules/hast-util-parse-selector/lib/index.js
generated
vendored
Normal file
68
node_modules/hast-util-parse-selector/lib/index.js
generated
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/**
|
||||
* @typedef {import('hast').Properties} Properties
|
||||
* @typedef {import('hast').Element} Element
|
||||
*/
|
||||
|
||||
const search = /[#.]/g
|
||||
|
||||
/**
|
||||
* Create a hast element from a simple CSS selector.
|
||||
*
|
||||
* @template {string} Selector
|
||||
* Type of selector.
|
||||
* @template {string} [DefaultTagName='div']
|
||||
* Type of default tag name.
|
||||
* @param {Selector | null | undefined} [selector]
|
||||
* Simple CSS selector.
|
||||
*
|
||||
* Can contain a tag name (`foo`), classes (`.bar`), and an ID (`#baz`).
|
||||
* Multiple classes are allowed.
|
||||
* Uses the last ID if multiple IDs are found.
|
||||
* @param {DefaultTagName | null | undefined} [defaultTagName='div']
|
||||
* Tag name to use if `selector` does not specify one (default: `'div'`).
|
||||
* @returns {Element & {tagName: import('./extract.js').ExtractTagName<Selector, DefaultTagName>}}
|
||||
* Built element.
|
||||
*/
|
||||
export function parseSelector(selector, defaultTagName) {
|
||||
const value = selector || ''
|
||||
/** @type {Properties} */
|
||||
const props = {}
|
||||
let start = 0
|
||||
/** @type {string | undefined} */
|
||||
let previous
|
||||
/** @type {string | undefined} */
|
||||
let tagName
|
||||
|
||||
while (start < value.length) {
|
||||
search.lastIndex = start
|
||||
const match = search.exec(value)
|
||||
const subvalue = value.slice(start, match ? match.index : value.length)
|
||||
|
||||
if (subvalue) {
|
||||
if (!previous) {
|
||||
tagName = subvalue
|
||||
} else if (previous === '#') {
|
||||
props.id = subvalue
|
||||
} else if (Array.isArray(props.className)) {
|
||||
props.className.push(subvalue)
|
||||
} else {
|
||||
props.className = [subvalue]
|
||||
}
|
||||
|
||||
start += subvalue.length
|
||||
}
|
||||
|
||||
if (match) {
|
||||
previous = match[0]
|
||||
start++
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'element',
|
||||
// @ts-expect-error: fine.
|
||||
tagName: tagName || defaultTagName || 'div',
|
||||
properties: props,
|
||||
children: []
|
||||
}
|
||||
}
|
||||
22
node_modules/hast-util-parse-selector/license
generated
vendored
Normal file
22
node_modules/hast-util-parse-selector/license
generated
vendored
Normal 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-parse-selector/package.json
generated
vendored
Normal file
86
node_modules/hast-util-parse-selector/package.json
generated
vendored
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
{
|
||||
"name": "hast-util-parse-selector",
|
||||
"version": "3.1.1",
|
||||
"description": "hast utility to create an element from a simple CSS selector",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"unist",
|
||||
"hast",
|
||||
"hast-util",
|
||||
"util",
|
||||
"utility",
|
||||
"html",
|
||||
"css",
|
||||
"selector",
|
||||
"parse"
|
||||
],
|
||||
"repository": "syntax-tree/hast-util-parse-selector",
|
||||
"bugs": "https://github.com/syntax-tree/hast-util-parse-selector/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",
|
||||
"typesVersions": {
|
||||
"<=4.1": {
|
||||
"lib/extract.d.ts": [
|
||||
"lib/extract-legacy.d.ts"
|
||||
]
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"lib/",
|
||||
"index.d.ts",
|
||||
"index.js"
|
||||
],
|
||||
"dependencies": {
|
||||
"@types/hast": "^2.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^18.0.0",
|
||||
"c8": "^7.0.0",
|
||||
"prettier": "^2.0.0",
|
||||
"remark-cli": "^11.0.0",
|
||||
"remark-preset-wooorm": "^9.0.0",
|
||||
"tsd": "^0.25.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
|
||||
}
|
||||
}
|
||||
203
node_modules/hast-util-parse-selector/readme.md
generated
vendored
Normal file
203
node_modules/hast-util-parse-selector/readme.md
generated
vendored
Normal file
|
|
@ -0,0 +1,203 @@
|
|||
# hast-util-parse-selector
|
||||
|
||||
[![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 create an element from a simple CSS selector.
|
||||
|
||||
## Contents
|
||||
|
||||
* [What is this?](#what-is-this)
|
||||
* [When should I use this?](#when-should-i-use-this)
|
||||
* [Install](#install)
|
||||
* [Use](#use)
|
||||
* [API](#api)
|
||||
* [`parseSelector(selector?[, defaultTagName])`](#parseselectorselector-defaulttagname)
|
||||
* [Types](#types)
|
||||
* [Compatibility](#compatibility)
|
||||
* [Security](#security)
|
||||
* [Related](#related)
|
||||
* [Contribute](#contribute)
|
||||
* [License](#license)
|
||||
|
||||
## What is this?
|
||||
|
||||
This package is a tiny utility that helps create elements.
|
||||
|
||||
## When should I use this?
|
||||
|
||||
This utility is super niche.
|
||||
You probably want the more powerful [`hastscript`][hastscript] or
|
||||
[`hast-util-from-selector`][hast-util-from-selector]
|
||||
|
||||
## Install
|
||||
|
||||
This package is [ESM only][esm].
|
||||
In Node.js (version 14.14+ and 16.0+), install with [npm][]:
|
||||
|
||||
```sh
|
||||
npm install hast-util-parse-selector
|
||||
```
|
||||
|
||||
In Deno with [`esm.sh`][esmsh]:
|
||||
|
||||
```js
|
||||
import {parseSelector} from 'https://esm.sh/hast-util-parse-selector@3'
|
||||
```
|
||||
|
||||
In browsers with [`esm.sh`][esmsh]:
|
||||
|
||||
```html
|
||||
<script type="module">
|
||||
import {parseSelector} from 'https://esm.sh/hast-util-parse-selector@3?bundle'
|
||||
</script>
|
||||
```
|
||||
|
||||
## Use
|
||||
|
||||
```js
|
||||
import {parseSelector} from 'hast-util-parse-selector'
|
||||
|
||||
console.log(parseSelector('.quux#bar.baz.qux'))
|
||||
```
|
||||
|
||||
Yields:
|
||||
|
||||
```js
|
||||
{ type: 'element',
|
||||
tagName: 'div',
|
||||
properties: { id: 'bar', className: [ 'quux', 'baz', 'qux' ] },
|
||||
children: [] }
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
This package exports the identifier [`parseSelector`][parseselector].
|
||||
There is no default export.
|
||||
|
||||
### `parseSelector(selector?[, defaultTagName])`
|
||||
|
||||
Create a hast element from a simple CSS selector.
|
||||
|
||||
###### Parameters
|
||||
|
||||
* `selector` (`string`, optional)
|
||||
— simple CSS selector, can contain a tag name (`foo`), classes (`.bar`),
|
||||
and an ID (`#baz`), multiple classes are allowed, uses the last ID if
|
||||
multiple IDs are found
|
||||
* `defaultTagName` (`string`, default: `'div'`)
|
||||
— tag name to use if `selector` does not specify one
|
||||
|
||||
###### Returns
|
||||
|
||||
Built element ([`Element`][element]).
|
||||
|
||||
## Types
|
||||
|
||||
This package is fully typed with [TypeScript][].
|
||||
It exports no additional types.
|
||||
|
||||
In TypeScript 4.2+, the type system can infer the tag name of literal
|
||||
`selector`s and knows that the return element has that name.
|
||||
|
||||
## 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
|
||||
|
||||
Improper use of the `selector` or `defaultTagName` can open you up to a
|
||||
[cross-site scripting (XSS)][xss] attack as the value of `tagName`, when
|
||||
resolving to `script`, injects a `script` element into the syntax tree.
|
||||
|
||||
Do not use user input in `selector` or use
|
||||
[`hast-util-santize`][hast-util-sanitize].
|
||||
|
||||
## Related
|
||||
|
||||
* [`hast-util-from-selector`](https://github.com/syntax-tree/hast-util-from-selector)
|
||||
— parse complex CSS selectors to nodes
|
||||
|
||||
## 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-parse-selector/workflows/main/badge.svg
|
||||
|
||||
[build]: https://github.com/syntax-tree/hast-util-parse-selector/actions
|
||||
|
||||
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hast-util-parse-selector.svg
|
||||
|
||||
[coverage]: https://codecov.io/github/syntax-tree/hast-util-parse-selector
|
||||
|
||||
[downloads-badge]: https://img.shields.io/npm/dm/hast-util-parse-selector.svg
|
||||
|
||||
[downloads]: https://www.npmjs.com/package/hast-util-parse-selector
|
||||
|
||||
[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-parse-selector.svg
|
||||
|
||||
[size]: https://bundlephobia.com/result?p=hast-util-parse-selector
|
||||
|
||||
[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
|
||||
|
||||
[hast]: https://github.com/syntax-tree/hast
|
||||
|
||||
[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize
|
||||
|
||||
[hastscript]: https://github.com/syntax-tree/hastscript
|
||||
|
||||
[hast-util-from-selector]: https://github.com/syntax-tree/hast-util-from-selector
|
||||
|
||||
[element]: https://github.com/syntax-tree/hast#element
|
||||
|
||||
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
|
||||
|
||||
[parseselector]: #parseselectorselector-defaulttagname
|
||||
Loading…
Add table
Add a link
Reference in a new issue