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

4
node_modules/hastscript/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
export type Child = import('./lib/index.js').Child;
export type Properties = import('./lib/index.js').Properties;
export type Result = import('./lib/index.js').Result;
export { h, s } from "./lib/index.js";

7
node_modules/hastscript/index.js generated vendored Normal file
View File

@@ -0,0 +1,7 @@
/**
* @typedef {import('./lib/index.js').Child} Child
* @typedef {import('./lib/index.js').Properties} Properties
* @typedef {import('./lib/index.js').Result} Result
*/
export {h, s} from './lib/index.js'

View File

@@ -0,0 +1,20 @@
export * from "./jsx-automatic.js";
export const Fragment: null;
export const jsx: {
(type: null, props: {
children?: import("./create-h.js").Child;
}, key?: string | undefined): import("hast").Root;
(type: string, props: import("./create-automatic-runtime.js").JSXProps, key?: string | undefined): import("hast").Element;
};
export const jsxDEV: {
(type: null, props: {
children?: import("./create-h.js").Child;
}, key?: string | undefined): import("hast").Root;
(type: string, props: import("./create-automatic-runtime.js").JSXProps, key?: string | undefined): import("hast").Element;
};
export const jsxs: {
(type: null, props: {
children?: import("./create-h.js").Child;
}, key?: string | undefined): import("hast").Root;
(type: string, props: import("./create-automatic-runtime.js").JSXProps, key?: string | undefined): import("hast").Element;
};

View File

@@ -0,0 +1,7 @@
import {createAutomaticRuntime} from './create-automatic-runtime.js'
import {h} from './index.js'
// Export `JSX` as a global for TypeScript.
export * from './jsx-automatic.js'
export const {Fragment, jsx, jsxDEV, jsxs} = createAutomaticRuntime(h)

20
node_modules/hastscript/lib/automatic-runtime-svg.d.ts generated vendored Normal file
View File

@@ -0,0 +1,20 @@
export * from "./jsx-automatic.js";
export const Fragment: null;
export const jsx: {
(type: null, props: {
children?: import("./create-h.js").Child;
}, key?: string | undefined): import("hast").Root;
(type: string, props: import("./create-automatic-runtime.js").JSXProps, key?: string | undefined): import("hast").Element;
};
export const jsxDEV: {
(type: null, props: {
children?: import("./create-h.js").Child;
}, key?: string | undefined): import("hast").Root;
(type: string, props: import("./create-automatic-runtime.js").JSXProps, key?: string | undefined): import("hast").Element;
};
export const jsxs: {
(type: null, props: {
children?: import("./create-h.js").Child;
}, key?: string | undefined): import("hast").Root;
(type: string, props: import("./create-automatic-runtime.js").JSXProps, key?: string | undefined): import("hast").Element;
};

7
node_modules/hastscript/lib/automatic-runtime-svg.js generated vendored Normal file
View File

@@ -0,0 +1,7 @@
import {createAutomaticRuntime} from './create-automatic-runtime.js'
import {s} from './index.js'
// Export `JSX` as a global for TypeScript.
export * from './jsx-automatic.js'
export const {Fragment, jsx, jsxDEV, jsxs} = createAutomaticRuntime(s)

View File

@@ -0,0 +1,38 @@
/**
* Create an automatic runtime.
*
* @param {ReturnType<CreateH>} f
* `h` function.
* @returns
* Automatic JSX runtime.
*/
export function createAutomaticRuntime(f: ReturnType<CreateH>): {
Fragment: null;
jsx: {
(type: null, props: {
children?: Child;
}, key?: string | undefined): Root;
(type: string, props: JSXProps, key?: string | undefined): Element;
};
jsxDEV: {
(type: null, props: {
children?: Child;
}, key?: string | undefined): Root;
(type: string, props: JSXProps, key?: string | undefined): Element;
};
jsxs: {
(type: null, props: {
children?: Child;
}, key?: string | undefined): Root;
(type: string, props: JSXProps, key?: string | undefined): Element;
};
};
export type Element = import('hast').Element;
export type Root = import('hast').Root;
export type Child = import('./create-h.js').Child;
export type Properties = import('./create-h.js').Properties;
export type PropertyValue = import('./create-h.js').PropertyValue;
export type Result = import('./create-h.js').Result;
export type Style = import('./create-h.js').Style;
export type CreateH = typeof import("./create-h.js").createH;
export type JSXProps = Record<string, Child | PropertyValue | Style>;

View File

@@ -0,0 +1,57 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Root} Root
*
* @typedef {import('./create-h.js').Child} Child
* @typedef {import('./create-h.js').Properties} Properties
* @typedef {import('./create-h.js').PropertyValue} PropertyValue
* @typedef {import('./create-h.js').Result} Result
* @typedef {import('./create-h.js').Style} Style
* @typedef {import('./create-h.js').createH} CreateH
*
* @typedef {Record<string, Child | PropertyValue | Style>} JSXProps
*/
// Make VS code see references to above symbols.
''
/**
* Create an automatic runtime.
*
* @param {ReturnType<CreateH>} f
* `h` function.
* @returns
* Automatic JSX runtime.
*/
export function createAutomaticRuntime(f) {
/**
* @overload
* @param {null} type
* @param {{children?: Child}} props
* @param {string} [key]
* @returns {Root}
*
* @overload
* @param {string} type
* @param {JSXProps} props
* @param {string} [key]
* @returns {Element}
*
* @param {string | null} type
* Element name or `null` to get a root.
* @param {Properties & {children?: Child}} props
* Properties.
* @returns {Result}
* Result.
*/
function jsx(type, props) {
const {children, ...properties} = props
const result =
// @ts-ignore: `children` is fine: TS has a recursion problem which
// sometimes generates broken types.
type === null ? f(null, children) : f(type, properties, children)
return result
}
return {Fragment: null, jsx, jsxDEV: jsx, jsxs: jsx}
}

67
node_modules/hastscript/lib/create-h.d.ts generated vendored Normal file
View File

@@ -0,0 +1,67 @@
/**
* @param {Schema} schema
* Schema to use.
* @param {string} defaultTagName
* Default tag name.
* @param {Array<string> | undefined} [caseSensitive]
* Case-sensitive tag names (default: `undefined`).
* @returns
* `h`.
*/
export function createH(schema: Schema, defaultTagName: string, caseSensitive?: Array<string> | undefined): {
(selector?: null | undefined, ...children: Child[]): Root;
(selector: string, properties: Properties, ...children: Child[]): Element;
(selector: string, ...children: Child[]): Element;
};
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 Info = import('property-information').Info;
export type Schema = import('property-information').Schema;
/**
* Result from a `h` (or `s`) call.
*/
export type Result = Element | Root;
/**
* Value for a CSS style field.
*/
export type StyleValue = number | string;
/**
* Supported value of a `style` prop.
*/
export type Style = Record<string, StyleValue>;
/**
* Primitive property value.
*/
export type PrimitiveValue = boolean | number | string | null | undefined;
/**
* List of property values for space- or comma separated values (such as `className`).
*/
export type ArrayValue = Array<number | string>;
/**
* Primitive value or list value.
*/
export type PropertyValue = (string | number)[] | PrimitiveValue;
/**
* Acceptable value for element properties.
*/
export type Properties = {
[property: string]: Style | PropertyValue;
};
/**
* Primitive children, either ignored (nullish), or turned into text nodes.
*/
export type PrimitiveChild = number | string | null | undefined;
/**
* List of children.
*/
export type ArrayChild = Array<(import("hast").Nodes | PrimitiveChild)[] | Nodes | PrimitiveChild>;
/**
* List of children (deep).
*/
export type ArrayChildNested = Array<Nodes | PrimitiveChild>;
/**
* Acceptable child value.
*/
export type Child = (import("hast").Nodes | PrimitiveChild | ArrayChildNested)[] | Nodes | PrimitiveChild;

345
node_modules/hastscript/lib/create-h.js generated vendored Normal file
View File

@@ -0,0 +1,345 @@
/**
* @typedef {import('hast').Element} Element
* @typedef {import('hast').Nodes} Nodes
* @typedef {import('hast').Root} Root
* @typedef {import('hast').RootContent} RootContent
*
* @typedef {import('property-information').Info} Info
* @typedef {import('property-information').Schema} Schema
*/
/**
* @typedef {Element | Root} Result
* Result from a `h` (or `s`) call.
*
* @typedef {number | string} StyleValue
* Value for a CSS style field.
* @typedef {Record<string, StyleValue>} Style
* Supported value of a `style` prop.
* @typedef {boolean | number | string | null | undefined} PrimitiveValue
* Primitive property value.
* @typedef {Array<number | string>} ArrayValue
* List of property values for space- or comma separated values (such as `className`).
* @typedef {ArrayValue | PrimitiveValue} PropertyValue
* Primitive value or list value.
* @typedef {{[property: string]: PropertyValue | Style}} Properties
* Acceptable value for element properties.
*
* @typedef {number | string | null | undefined} PrimitiveChild
* Primitive children, either ignored (nullish), or turned into text nodes.
* @typedef {Array<ArrayChildNested | Nodes | PrimitiveChild>} ArrayChild
* List of children.
* @typedef {Array<Nodes | PrimitiveChild>} ArrayChildNested
* List of children (deep).
* @typedef {ArrayChild | Nodes | PrimitiveChild} Child
* Acceptable child value.
*/
import {parse as commas} from 'comma-separated-tokens'
import {parseSelector} from 'hast-util-parse-selector'
import {find, normalize} from 'property-information'
import {parse as spaces} from 'space-separated-tokens'
const buttonTypes = new Set(['button', 'menu', 'reset', 'submit'])
const own = {}.hasOwnProperty
/**
* @param {Schema} schema
* Schema to use.
* @param {string} defaultTagName
* Default tag name.
* @param {Array<string> | undefined} [caseSensitive]
* Case-sensitive tag names (default: `undefined`).
* @returns
* `h`.
*/
export function createH(schema, defaultTagName, caseSensitive) {
const adjust = caseSensitive && createAdjustMap(caseSensitive)
/**
* Hyperscript compatible DSL for creating virtual hast trees.
*
* @overload
* @param {null | undefined} [selector]
* @param {...Child} children
* @returns {Root}
*
* @overload
* @param {string} selector
* @param {Properties} properties
* @param {...Child} children
* @returns {Element}
*
* @overload
* @param {string} selector
* @param {...Child} children
* @returns {Element}
*
* @param {string | null | undefined} [selector]
* Selector.
* @param {Child | Properties | null | undefined} [properties]
* Properties (or first child) (default: `undefined`).
* @param {...Child} children
* Children.
* @returns {Result}
* Result.
*/
function h(selector, properties, ...children) {
let index = -1
/** @type {Result} */
let node
if (selector === undefined || selector === null) {
node = {type: 'root', children: []}
// Properties are not supported for roots.
const child = /** @type {Child} */ (properties)
children.unshift(child)
} else {
node = parseSelector(selector, defaultTagName)
// Normalize the name.
node.tagName = node.tagName.toLowerCase()
if (adjust && own.call(adjust, node.tagName)) {
node.tagName = adjust[node.tagName]
}
// Handle props.
if (isProperties(properties, node.tagName)) {
/** @type {string} */
let key
for (key in properties) {
if (own.call(properties, key)) {
addProperty(schema, node.properties, key, properties[key])
}
}
} else {
children.unshift(properties)
}
}
// Handle children.
while (++index < children.length) {
addChild(node.children, children[index])
}
if (node.type === 'element' && node.tagName === 'template') {
node.content = {type: 'root', children: node.children}
node.children = []
}
return node
}
return h
}
/**
* Check if something is properties or a child.
*
* @param {Child | Properties} value
* Value to check.
* @param {string} name
* Tag name.
* @returns {value is Properties}
* Whether `value` is a properties object.
*/
function isProperties(value, name) {
if (
value === null ||
value === undefined ||
typeof value !== 'object' ||
Array.isArray(value)
) {
return false
}
if (name === 'input' || !value.type || typeof value.type !== 'string') {
return true
}
if ('children' in value && Array.isArray(value.children)) {
return false
}
if (name === 'button') {
return buttonTypes.has(value.type.toLowerCase())
}
return !('value' in value)
}
/**
* @param {Schema} schema
* Schema.
* @param {Properties} properties
* Properties object.
* @param {string} key
* Property name.
* @param {PropertyValue | Style} value
* Property value.
* @returns {undefined}
* Nothing.
*/
function addProperty(schema, properties, key, value) {
const info = find(schema, key)
let index = -1
/** @type {PropertyValue} */
let result
// Ignore nullish and NaN values.
if (value === undefined || value === null) return
if (typeof value === 'number') {
// Ignore NaN.
if (Number.isNaN(value)) return
result = value
}
// Booleans.
else if (typeof value === 'boolean') {
result = value
}
// Handle list values.
else if (typeof value === 'string') {
if (info.spaceSeparated) {
result = spaces(value)
} else if (info.commaSeparated) {
result = commas(value)
} else if (info.commaOrSpaceSeparated) {
result = spaces(commas(value).join(' '))
} else {
result = parsePrimitive(info, info.property, value)
}
} else if (Array.isArray(value)) {
result = value.concat()
} else {
result = info.property === 'style' ? style(value) : String(value)
}
if (Array.isArray(result)) {
/** @type {Array<number | string>} */
const finalResult = []
while (++index < result.length) {
// Assume no booleans in array.
const value = /** @type {number | string} */ (
parsePrimitive(info, info.property, result[index])
)
finalResult[index] = value
}
result = finalResult
}
// Class names (which can be added both on the `selector` and here).
if (info.property === 'className' && Array.isArray(properties.className)) {
// Assume no booleans in `className`.
const value = /** @type {number | string} */ (result)
result = properties.className.concat(value)
}
properties[info.property] = result
}
/**
* @param {Array<RootContent>} nodes
* Children.
* @param {Child} value
* Child.
* @returns {undefined}
* Nothing.
*/
function addChild(nodes, value) {
let index = -1
if (value === undefined || value === null) {
// Empty.
} else if (typeof value === 'string' || typeof value === 'number') {
nodes.push({type: 'text', value: String(value)})
} else if (Array.isArray(value)) {
while (++index < value.length) {
addChild(nodes, value[index])
}
} else if (typeof value === 'object' && 'type' in value) {
if (value.type === 'root') {
addChild(nodes, value.children)
} else {
nodes.push(value)
}
} else {
throw new Error('Expected node, nodes, or string, got `' + value + '`')
}
}
/**
* Parse a single primitives.
*
* @param {Info} info
* Property information.
* @param {string} name
* Property name.
* @param {PrimitiveValue} value
* Property value.
* @returns {PrimitiveValue}
* Property value.
*/
function parsePrimitive(info, name, value) {
if (typeof value === 'string') {
if (info.number && value && !Number.isNaN(Number(value))) {
return Number(value)
}
if (
(info.boolean || info.overloadedBoolean) &&
(value === '' || normalize(value) === normalize(name))
) {
return true
}
}
return value
}
/**
* Serialize a `style` object as a string.
*
* @param {Style} value
* Style object.
* @returns {string}
* CSS string.
*/
function style(value) {
/** @type {Array<string>} */
const result = []
/** @type {string} */
let key
for (key in value) {
if (own.call(value, key)) {
result.push([key, value[key]].join(': '))
}
}
return result.join('; ')
}
/**
* Create a map to adjust casing.
*
* @param {Array<string>} values
* List of properly cased keys.
* @returns {Record<string, string>}
* Map of lowercase keys to uppercase keys.
*/
function createAdjustMap(values) {
/** @type {Record<string, string>} */
const result = {}
let index = -1
while (++index < values.length) {
result[values[index].toLowerCase()] = values[index]
}
return result
}

33
node_modules/hastscript/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,33 @@
/** @type {ReturnType<createH>} */
export const h: ReturnType<typeof createH>;
export namespace h {
namespace JSX {
type Element = import('./jsx-classic.js').Element;
type ElementChildrenAttribute = import('./jsx-classic.js').ElementChildrenAttribute;
type IntrinsicAttributes = import('./jsx-classic.js').IntrinsicAttributes;
type IntrinsicElements = import('./jsx-classic.js').IntrinsicElements;
}
}
/** @type {ReturnType<createH>} */
export const s: ReturnType<typeof createH>;
export namespace s {
namespace JSX {
type Element = import('./jsx-classic.js').Element;
type ElementChildrenAttribute = import('./jsx-classic.js').ElementChildrenAttribute;
type IntrinsicAttributes = import('./jsx-classic.js').IntrinsicAttributes;
type IntrinsicElements = import('./jsx-classic.js').IntrinsicElements;
}
}
/**
* Acceptable child value.
*/
export type Child = import('./create-h.js').Child;
/**
* Acceptable value for element properties.
*/
export type Properties = import('./create-h.js').Properties;
/**
* Result from a `h` (or `s`) call.
*/
export type Result = import('./create-h.js').Result;
import { createH } from './create-h.js';

36
node_modules/hastscript/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
/**
* @typedef {import('./create-h.js').Child} Child
* Acceptable child value.
* @typedef {import('./create-h.js').Properties} Properties
* Acceptable value for element properties.
* @typedef {import('./create-h.js').Result} Result
* Result from a `h` (or `s`) call.
*/
// Register the JSX namespace on `h`.
/**
* @typedef {import('./jsx-classic.js').Element} h.JSX.Element
* @typedef {import('./jsx-classic.js').ElementChildrenAttribute} h.JSX.ElementChildrenAttribute
* @typedef {import('./jsx-classic.js').IntrinsicAttributes} h.JSX.IntrinsicAttributes
* @typedef {import('./jsx-classic.js').IntrinsicElements} h.JSX.IntrinsicElements
*/
// Register the JSX namespace on `s`.
/**
* @typedef {import('./jsx-classic.js').Element} s.JSX.Element
* @typedef {import('./jsx-classic.js').ElementChildrenAttribute} s.JSX.ElementChildrenAttribute
* @typedef {import('./jsx-classic.js').IntrinsicAttributes} s.JSX.IntrinsicAttributes
* @typedef {import('./jsx-classic.js').IntrinsicElements} s.JSX.IntrinsicElements
*/
import {html, svg} from 'property-information'
import {createH} from './create-h.js'
import {svgCaseSensitiveTagNames} from './svg-case-sensitive-tag-names.js'
// Note: this explicit type is needed, otherwise TS creates broken types.
/** @type {ReturnType<createH>} */
export const h = createH(html, 'div')
// Note: this explicit type is needed, otherwise TS creates broken types.
/** @type {ReturnType<createH>} */
export const s = createH(svg, 'g', svgCaseSensitiveTagNames)

43
node_modules/hastscript/lib/jsx-automatic.d.ts generated vendored Normal file
View File

@@ -0,0 +1,43 @@
import type {Child, Properties, Result} from './create-h.js'
export namespace JSX {
/**
* Define the return value of JSX syntax.
*/
type Element = Result
/**
* Key of this interface defines as what prop children are passed.
*/
interface ElementChildrenAttribute {
/**
* Only the key matters, not the value.
*/
children?: never
}
/**
* Disallow the use of functional components.
*/
type IntrinsicAttributes = never
/**
* Define the prop types for known elements.
*
* For `hastscript` this defines any string may be used in combination with
* `hast` `Properties`.
*
* This **must** be an interface.
*/
interface IntrinsicElements {
[name: string]:
| Properties
| {
/**
* The prop that matches `ElementChildrenAttribute` key defines the
* type of JSX children, defines the children type.
*/
children?: Child
}
}
}

2
node_modules/hastscript/lib/jsx-automatic.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
// Empty (only used for TypeScript).
export {}

47
node_modules/hastscript/lib/jsx-classic.d.ts generated vendored Normal file
View File

@@ -0,0 +1,47 @@
import type {Child, Properties, Result} from './create-h.js'
/**
* This unique symbol is declared to specify the key on which JSX children are
* passed, without conflicting with the `Attributes` type.
*/
declare const children: unique symbol
/**
* Define the return value of JSX syntax.
*/
export type Element = Result
/**
* Key of this interface defines as what prop children are passed.
*/
export interface ElementChildrenAttribute {
/**
* Only the key matters, not the value.
*/
[children]?: never
}
/**
* Disallow the use of functional components.
*/
export type IntrinsicAttributes = never
/**
* Define the prop types for known elements.
*
* For `hastscript` this defines any string may be used in combination with
* `hast` `Properties`.
*
* This **must** be an interface.
*/
export interface IntrinsicElements {
[name: string]:
| Properties
| {
/**
* The prop that matches `ElementChildrenAttribute` key defines the
* type of JSX children, defines the children type.
*/
[children]?: Child
}
}

2
node_modules/hastscript/lib/jsx-classic.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
// Empty (only used for TypeScript).
export {}

View File

@@ -0,0 +1 @@
export const svgCaseSensitiveTagNames: string[];

View File

@@ -0,0 +1,41 @@
export const svgCaseSensitiveTagNames = [
'altGlyph',
'altGlyphDef',
'altGlyphItem',
'animateColor',
'animateMotion',
'animateTransform',
'clipPath',
'feBlend',
'feColorMatrix',
'feComponentTransfer',
'feComposite',
'feConvolveMatrix',
'feDiffuseLighting',
'feDisplacementMap',
'feDistantLight',
'feDropShadow',
'feFlood',
'feFuncA',
'feFuncB',
'feFuncG',
'feFuncR',
'feGaussianBlur',
'feImage',
'feMerge',
'feMergeNode',
'feMorphology',
'feOffset',
'fePointLight',
'feSpecularLighting',
'feSpotLight',
'feTile',
'feTurbulence',
'foreignObject',
'glyphRef',
'linearGradient',
'radialGradient',
'solidColor',
'textArea',
'textPath'
]

22
node_modules/hastscript/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.

117
node_modules/hastscript/package.json generated vendored Normal file
View File

@@ -0,0 +1,117 @@
{
"name": "hastscript",
"version": "8.0.0",
"description": "hast utility to create trees",
"license": "MIT",
"keywords": [
"unist",
"hast",
"hast-util",
"util",
"utility",
"html",
"rehype",
"vdom",
"virtual",
"dom",
"hyperscript",
"dsl"
],
"repository": "syntax-tree/hastscript",
"bugs": "https://github.com/syntax-tree/hastscript/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",
"exports": {
".": "./index.js",
"./jsx-runtime": "./lib/automatic-runtime-html.js",
"./jsx-dev-runtime": "./lib/automatic-runtime-html.js",
"./svg/jsx-runtime": "./lib/automatic-runtime-svg.js",
"./svg/jsx-dev-runtime": "./lib/automatic-runtime-svg.js"
},
"files": [
"lib/",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/hast": "^3.0.0",
"comma-separated-tokens": "^2.0.0",
"hast-util-parse-selector": "^4.0.0",
"property-information": "^6.0.0",
"space-separated-tokens": "^2.0.0"
},
"devDependencies": {
"@types/node": "^20.0.0",
"acorn-jsx": "^5.0.0",
"c8": "^8.0.0",
"esast-util-from-js": "^2.0.0",
"estree-util-build-jsx": "^3.0.0",
"estree-util-to-js": "^2.0.0",
"prettier": "^3.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"svg-tag-names": "^3.0.0",
"tsd": "^0.28.0",
"type-coverage": "^2.0.0",
"typescript": "^5.0.0",
"unist-builder": "^4.0.0",
"xo": "^0.55.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "tsc --build --clean && tsc --build && tsd && type-coverage",
"generate": "node script/generate-jsx.js && node script/build.js",
"format": "remark . -qfo && prettier . -w --log-level warn && xo --fix",
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api",
"test": "npm run generate && 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,
"#": "needed `any`s :'(",
"ignoreFiles": [
"test/jsx-build-jsx-automatic-development.js"
],
"strict": true
},
"xo": {
"overrides": [
{
"files": "**/*.ts",
"rules": {
"@typescript-eslint/consistent-indexed-object-style": "off",
"@typescript-eslint/consistent-type-definitions": "off"
}
}
],
"prettier": true,
"rules": {
"n/file-extension-in-import": "off"
}
}
}

472
node_modules/hastscript/readme.md generated vendored Normal file
View File

@@ -0,0 +1,472 @@
# hastscript
[![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 trees with ease.
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`h(selector?[, properties][, …children])`](#hselector-properties-children)
* [`s(selector?[, properties][, …children])`](#sselector-properties-children)
* [`Child`](#child)
* [`Properties`](#properties-1)
* [`Result`](#result)
* [Syntax tree](#syntax-tree)
* [JSX](#jsx)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Related](#related)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a hyperscript interface (like `createElement` from React and
`h` from Vue and such) to help with creating hast trees.
## When should I use this?
You can use this utility in your project when you generate hast syntax trees
with code.
It helps because it replaces most of the repetition otherwise needed in a syntax
tree with function calls.
It also helps as it improves the attributes you pass by turning them into the
form that is required by hast.
You can instead use [`unist-builder`][u] when creating any unist nodes and
[`xastscript`][x] when creating xast (XML) nodes.
## Install
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
```sh
npm install hastscript
```
In Deno with [`esm.sh`][esmsh]:
```js
import {h} from 'https://esm.sh/hastscript@8'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {h} from 'https://esm.sh/hastscript@8?bundle'
</script>
```
## Use
```js
import {h, s} from 'hastscript'
console.log(
h('.foo#some-id', [
h('span', 'some text'),
h('input', {type: 'text', value: 'foo'}),
h('a.alpha', {class: 'bravo charlie', download: 'download'}, [
'delta',
'echo'
])
])
)
console.log(
s('svg', {xmlns: 'http://www.w3.org/2000/svg', viewbox: '0 0 500 500'}, [
s('title', 'SVG `<circle>` element'),
s('circle', {cx: 120, cy: 120, r: 100})
])
)
```
Yields:
```js
{
type: 'element',
tagName: 'div',
properties: {className: ['foo'], id: 'some-id'},
children: [
{
type: 'element',
tagName: 'span',
properties: {},
children: [{type: 'text', value: 'some text'}]
},
{
type: 'element',
tagName: 'input',
properties: {type: 'text', value: 'foo'},
children: []
},
{
type: 'element',
tagName: 'a',
properties: {className: ['alpha', 'bravo', 'charlie'], download: true},
children: [{type: 'text', value: 'delta'}, {type: 'text', value: 'echo'}]
}
]
}
{
type: 'element',
tagName: 'svg',
properties: {xmlns: 'http://www.w3.org/2000/svg', viewBox: '0 0 500 500'},
children: [
{
type: 'element',
tagName: 'title',
properties: {},
children: [{type: 'text', value: 'SVG `<circle>` element'}]
},
{
type: 'element',
tagName: 'circle',
properties: {cx: 120, cy: 120, r: 100},
children: []
}
]
}
```
## API
This package exports the identifiers [`h`][api-h] and [`s`][api-s].
There is no default export.
The export map supports the automatic JSX runtime.
You can pass `hastscript` or `hastscript/svg` to your build tool (TypeScript,
Babel, SWC) with an `importSource` option or similar.
### `h(selector?[, properties][, …children])`
Create virtual **[hast][]** trees for HTML.
##### Signatures
* `h(): root`
* `h(null[, …children]): root`
* `h(selector[, properties][, …children]): element`
##### Parameters
###### `selector`
Simple CSS selector (`string`, optional).
Can contain a tag name (`foo`), IDs (`#bar`), and classes (`.baz`).
If the selector is a string but there is no tag name in it, `h` defaults to
build a `div` element, and `s` to a `g` element.
`selector` is parsed by [`hast-util-parse-selector`][parse-selector].
When string, builds an [`Element`][element].
When nullish, builds a [`Root`][root] instead.
###### `properties`
Properties of the element ([`Properties`][api-properties], optional).
###### `children`
Children of the node ([`Child`][api-child] or `Array<Child>`, optional).
##### Returns
Created tree ([`Result`][api-result]).
[`Element`][element] when a `selector` is passed, otherwise [`Root`][root].
### `s(selector?[, properties][, …children])`
Create virtual **[hast][]** trees for SVG.
Signatures, parameters, and return value are the same as `h` above.
Importantly, the `selector` and `properties` parameters are interpreted as
SVG.
### `Child`
(Lists of) children (TypeScript type).
When strings or numbers are encountered, they are turned into [`Text`][text]
nodes.
[`Root`][root] nodes are treated as “fragments”, meaning that their children
are used instead.
###### Type
```ts
type Child =
| Array<Node | number | string | null | undefined>
| Node
| number
| string
| null
| undefined
```
### `Properties`
Map of properties (TypeScript type).
Keys should match either the HTML attribute name, or the DOM property name, but
are case-insensitive.
###### Type
```ts
type Properties = Record<
string,
| boolean
| number
| string
| null
| undefined
// For comma- and space-separated values such as `className`:
| Array<number | string>
// Accepts value for `style` prop as object.
| Record<string, number | string>
>
```
### `Result`
Result from a `h` (or `s`) call (TypeScript type).
###### Type
```ts
type Result = Element | Root
```
## Syntax tree
The syntax tree is [hast][].
## JSX
This package can be used with JSX.
You should use the automatic JSX runtime set to `hastscript` or
`hastscript/svg`.
> 👉 **Note**: while `h` supports dots (`.`) for classes or number signs (`#`)
> for IDs in `selector`, those are not supported in JSX.
> 🪦 **Legacy**: you can also use the classic JSX runtime, but this is not
> recommended.
> To do so, import `h` (or `s`) yourself and define it as the pragma (plus
> set the fragment to `null`).
The Use example above can then be written like so, using inline pragmas, so
that SVG can be used too:
`example-html.jsx`:
```jsx
/** @jsxImportSource hastscript */
console.log(
<div class="foo" id="some-id">
<span>some text</span>
<input type="text" value="foo" />
<a class="alpha bravo charlie" download>
deltaecho
</a>
</div>
)
```
`example-svg.jsx`:
```jsx
/** @jsxImportSource hastscript/svg */
console.log(
<svg xmlns="http://www.w3.org/2000/svg" viewbox="0 0 500 500">
<title>SVG `&lt;circle&gt;` element</title>
<circle cx={120} cy={120} r={100} />
</svg>
)
```
## Types
This package is fully typed with [TypeScript][].
It exports the additional types [`Child`][api-child],
[`Properties`][api-properties], and
[`Result`][api-result].
## 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, `hastscript@^8`,
compatible with Node.js 16.
## Security
Use of `hastscript` can open you up to a [cross-site scripting (XSS)][xss]
when you pass user-provided input to it because values are injected into the
syntax tree.
The following example shows how an image is injected that fails loading and
therefore runs code in a browser.
```js
const tree = h()
// Somehow someone injected these properties instead of an expected `src` and
// `alt`:
const otherProps = {src: 'x', onError: 'alert(1)'}
tree.children.push(h('img', {src: 'default.png', ...otherProps}))
```
Yields:
```html
<img src="x" onerror="alert(1)">
```
The following example shows how code can run in a browser because someone stored
an object in a database instead of the expected string.
```js
const tree = h()
// Somehow this isnt the expected `'wooorm'`.
const username = {
type: 'element',
tagName: 'script',
children: [{type: 'text', value: 'alert(2)'}]
}
tree.children.push(h('span.handle', username))
```
Yields:
```html
<span class="handle"><script>alert(2)</script></span>
```
Either do not use user-provided input in `hastscript` or use
[`hast-util-santize`][hast-util-sanitize].
## Related
* [`unist-builder`](https://github.com/syntax-tree/unist-builder)
— create unist trees
* [`xastscript`](https://github.com/syntax-tree/xastscript)
— create xast trees
* [`hast-to-hyperscript`](https://github.com/syntax-tree/hast-to-hyperscript)
— turn hast into React, Preact, Vue, etc
* [`hast-util-to-html`](https://github.com/syntax-tree/hast-util-to-html)
— turn hast into HTML
* [`hast-util-to-dom`](https://github.com/syntax-tree/hast-util-to-dom)
— turn hast into DOM trees
* [`estree-util-build-jsx`](https://github.com/syntax-tree/estree-util-build-jsx)
— compile JSX away
## 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/hastscript/workflows/main/badge.svg
[build]: https://github.com/syntax-tree/hastscript/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/syntax-tree/hastscript.svg
[coverage]: https://codecov.io/github/syntax-tree/hastscript
[downloads-badge]: https://img.shields.io/npm/dm/hastscript.svg
[downloads]: https://www.npmjs.com/package/hastscript
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hastscript
[size]: https://bundlejs.com/?q=hastscript
[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
[element]: https://github.com/syntax-tree/hast#element
[root]: https://github.com/syntax-tree/xast#root
[text]: https://github.com/syntax-tree/hast#text
[u]: https://github.com/syntax-tree/unist-builder
[x]: https://github.com/syntax-tree/xastscript
[parse-selector]: https://github.com/syntax-tree/hast-util-parse-selector
[xss]: https://en.wikipedia.org/wiki/Cross-site_scripting
[hast-util-sanitize]: https://github.com/syntax-tree/hast-util-sanitize
[api-h]: #hselector-properties-children
[api-s]: #sselector-properties-children
[api-child]: #child
[api-properties]: #properties-1
[api-result]: #result