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

14
node_modules/@mdx-js/mdx/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,14 @@
export { createProcessor } from "./lib/core.js";
export { nodeTypes } from "./lib/node-types.js";
export type Fragment = import('./lib/util/resolve-evaluate-options.js').Fragment;
export type Jsx = import('./lib/util/resolve-evaluate-options.js').Jsx;
export type JsxDev = import('./lib/util/resolve-evaluate-options.js').JsxDev;
export type UseMdxComponents = import('./lib/util/resolve-evaluate-options.js').UseMdxComponents;
export type CompileOptions = import('./lib/compile.js').CompileOptions;
export type ProcessorOptions = import('./lib/core.js').ProcessorOptions;
export type EvaluateOptions = import('./lib/evaluate.js').EvaluateOptions;
export type RunOptions = import('./lib/run.js').RunOptions;
export { compile, compileSync } from "./lib/compile.js";
export { evaluate, evaluateSync } from "./lib/evaluate.js";
export { run, runSync } from "./lib/run.js";
//# sourceMappingURL=index.d.ts.map

1
node_modules/@mdx-js/mdx/index.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":";;uBACa,OAAO,wCAAwC,EAAE,QAAQ;kBACzD,OAAO,wCAAwC,EAAE,GAAG;qBACpD,OAAO,wCAAwC,EAAE,MAAM;+BACvD,OAAO,wCAAwC,EAAE,gBAAgB;6BACjE,OAAO,kBAAkB,EAAE,cAAc;+BACzC,OAAO,eAAe,EAAE,gBAAgB;8BACxC,OAAO,mBAAmB,EAAE,eAAe;yBAC3C,OAAO,cAAc,EAAE,UAAU"}

16
node_modules/@mdx-js/mdx/index.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
/**
* @typedef {import('./lib/util/resolve-evaluate-options.js').Fragment} Fragment
* @typedef {import('./lib/util/resolve-evaluate-options.js').Jsx} Jsx
* @typedef {import('./lib/util/resolve-evaluate-options.js').JsxDev} JsxDev
* @typedef {import('./lib/util/resolve-evaluate-options.js').UseMdxComponents} UseMdxComponents
* @typedef {import('./lib/compile.js').CompileOptions} CompileOptions
* @typedef {import('./lib/core.js').ProcessorOptions} ProcessorOptions
* @typedef {import('./lib/evaluate.js').EvaluateOptions} EvaluateOptions
* @typedef {import('./lib/run.js').RunOptions} RunOptions
*/
export {compile, compileSync} from './lib/compile.js'
export {createProcessor} from './lib/core.js'
export {evaluate, evaluateSync} from './lib/evaluate.js'
export {nodeTypes} from './lib/node-types.js'
export {run, runSync} from './lib/run.js'

50
node_modules/@mdx-js/mdx/lib/compile.d.ts generated vendored Normal file
View File

@@ -0,0 +1,50 @@
/**
* Compile MDX to JS.
*
* @param {Readonly<Compatible>} vfileCompatible
* MDX document to parse.
* @param {Readonly<CompileOptions> | null | undefined} [compileOptions]
* Compile configuration (optional).
* @return {Promise<VFile>}
* Promise to compiled file.
*/
export function compile(vfileCompatible: Readonly<Compatible>, compileOptions?: Readonly<CompileOptions> | null | undefined): Promise<VFile>;
/**
* Synchronously compile MDX to JS.
*
* When possible please use the async `compile`.
*
* @param {Readonly<Compatible>} vfileCompatible
* MDX document to parse.
* @param {Readonly<CompileOptions> | null | undefined} [compileOptions]
* Compile configuration (optional).
* @return {VFile}
* Compiled file.
*/
export function compileSync(vfileCompatible: Readonly<Compatible>, compileOptions?: Readonly<CompileOptions> | null | undefined): VFile;
export type VFile = import('vfile').VFile;
export type Compatible = import('vfile').Compatible;
export type ProcessorOptions = import('./core.js').ProcessorOptions;
/**
* Core configuration.
*/
export type CoreProcessorOptions = Omit<ProcessorOptions, 'format'>;
/**
* Extra configuration.
*/
export type ExtraOptions = {
/**
* Format of `file` (default: `'detect'`).
*/
format?: 'detect' | 'md' | 'mdx' | null | undefined;
};
/**
* Configuration for `compile`.
*
* `CompileOptions` is the same as `ProcessorOptions` with the exception that
* the `format` option supports a `'detect'` value, which is the default.
* The `'detect'` format means to use `'md'` for files with an extension in
* `mdExtensions` and `'mdx'` otherwise.
*/
export type CompileOptions = CoreProcessorOptions & ExtraOptions;
//# sourceMappingURL=compile.d.ts.map

1
node_modules/@mdx-js/mdx/lib/compile.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["compile.js"],"names":[],"mappings":"AA2BA;;;;;;;;;GASG;AACH,yCAPW,SAAS,UAAU,CAAC,mBAEpB,SAAS,cAAc,CAAC,GAAG,IAAI,GAAG,SAAS,GAE1C,QAAQ,KAAK,CAAC,CAMzB;AAED;;;;;;;;;;;GAWG;AACH,6CAPW,SAAS,UAAU,CAAC,mBAEpB,SAAS,cAAc,CAAC,GAAG,IAAI,GAAG,SAAS,GAE1C,KAAK,CAMhB;oBAxDY,OAAO,OAAO,EAAE,KAAK;yBACrB,OAAO,OAAO,EAAE,UAAU;+BAC1B,OAAO,WAAW,EAAE,gBAAgB;;;;mCAIpC,KAAK,gBAAgB,EAAE,QAAQ,CAAC;;;;;;;;aAK/B,QAAQ,GAAG,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS;;;;;;;;;;6BAG3C,oBAAoB,GAAG,YAAY"}

58
node_modules/@mdx-js/mdx/lib/compile.js generated vendored Normal file
View File

@@ -0,0 +1,58 @@
/**
* @typedef {import('vfile').VFile} VFile
* @typedef {import('vfile').Compatible} Compatible
* @typedef {import('./core.js').ProcessorOptions} ProcessorOptions
*/
/**
* @typedef {Omit<ProcessorOptions, 'format'>} CoreProcessorOptions
* Core configuration.
*
* @typedef ExtraOptions
* Extra configuration.
* @property {'detect' | 'md' | 'mdx' | null | undefined} [format='detect']
* Format of `file` (default: `'detect'`).
*
* @typedef {CoreProcessorOptions & ExtraOptions} CompileOptions
* Configuration for `compile`.
*
* `CompileOptions` is the same as `ProcessorOptions` with the exception that
* the `format` option supports a `'detect'` value, which is the default.
* The `'detect'` format means to use `'md'` for files with an extension in
* `mdExtensions` and `'mdx'` otherwise.
*/
import {resolveFileAndOptions} from './util/resolve-file-and-options.js'
import {createProcessor} from './core.js'
/**
* Compile MDX to JS.
*
* @param {Readonly<Compatible>} vfileCompatible
* MDX document to parse.
* @param {Readonly<CompileOptions> | null | undefined} [compileOptions]
* Compile configuration (optional).
* @return {Promise<VFile>}
* Promise to compiled file.
*/
export function compile(vfileCompatible, compileOptions) {
const {file, options} = resolveFileAndOptions(vfileCompatible, compileOptions)
return createProcessor(options).process(file)
}
/**
* Synchronously compile MDX to JS.
*
* When possible please use the async `compile`.
*
* @param {Readonly<Compatible>} vfileCompatible
* MDX document to parse.
* @param {Readonly<CompileOptions> | null | undefined} [compileOptions]
* Compile configuration (optional).
* @return {VFile}
* Compiled file.
*/
export function compileSync(vfileCompatible, compileOptions) {
const {file, options} = resolveFileAndOptions(vfileCompatible, compileOptions)
return createProcessor(options).processSync(file)
}

178
node_modules/@mdx-js/mdx/lib/core.d.ts generated vendored Normal file
View File

@@ -0,0 +1,178 @@
/**
* Create a processor to compile markdown or MDX to JavaScript.
*
* > **Note**: `format: 'detect'` is not allowed in `ProcessorOptions`.
*
* @param {Readonly<ProcessorOptions> | null | undefined} [options]
* Configuration (optional).
* @return {Processor}
* Processor.
*/
export function createProcessor(options?: Readonly<ProcessorOptions> | null | undefined): Processor;
export type Program = import('estree-jsx').Program;
export type ElementAttributeNameCase = import('hast-util-to-estree').ElementAttributeNameCase;
export type StylePropertyNameCase = import('hast-util-to-estree').StylePropertyNameCase;
export type Root = import('mdast').Root;
export type RemarkRehypeOptions = import('remark-rehype').Options;
export type SourceMapGenerator = typeof import('source-map').SourceMapGenerator;
export type PluggableList = import('unified').PluggableList;
export type Processor = import('unified').Processor<Root, Program, Program, Program, string>;
/**
* Configuration for `createProcessor`.
*/
export type ProcessorOptions = {
/**
* Add a source map (object form) as the `map` field on the resulting file
* (optional).
*/
SourceMapGenerator?: SourceMapGenerator | null | undefined;
/**
* Use this URL as `import.meta.url` and resolve `import` and `export … from`
* relative to it (optional, example: `import.meta.url`).
*/
baseUrl?: URL | string | null | undefined;
/**
* Whether to add extra info to error messages in generated code and use the
* development automatic JSX runtime (`Fragment` and `jsxDEV` from
* `/jsx-dev-runtime`) (default: `false`);
* when using the webpack loader (`@mdx-js/loader`) or the Rollup integration
* (`@mdx-js/rollup`) through Vite, this is automatically inferred from how
* you configure those tools.
*/
development?: boolean | null | undefined;
/**
* Casing to use for attribute names (default: `'react'`);
* HTML casing is for example `class`, `stroke-linecap`, `xml:lang`;
* React casing is for example `className`, `strokeLinecap`, `xmlLang`;
* for JSX components written in MDX, the author has to be aware of which
* framework they use and write code accordingly;
* for AST nodes generated by this project, this option configures it
*/
elementAttributeNameCase?: ElementAttributeNameCase | null | undefined;
/**
* format of the file (default: `'mdx'`);
* `'md'` means treat as markdown and `'mdx'` means treat as MDX.
*/
format?: 'md' | 'mdx' | null | undefined;
/**
* Whether to keep JSX (default: `false`);
* the default is to compile JSX away so that the resulting file is
* immediately runnable.
*/
jsx?: boolean | null | undefined;
/**
* Place to import automatic JSX runtimes from (default: `'react'`);
* when in the `automatic` runtime, this is used to define an import for
* `Fragment`, `jsx`, `jsxDEV`, and `jsxs`.
*/
jsxImportSource?: string | null | undefined;
/**
* JSX runtime to use (default: `'automatic'`);
* the automatic runtime compiles to `import _jsx from
* '$importSource/jsx-runtime'\n_jsx('p')`;
* the classic runtime compiles to calls such as `h('p')`.
*
* > 👉 **Note**: support for the classic runtime is deprecated and will
* > likely be removed in the next major version.
*/
jsxRuntime?: 'automatic' | 'classic' | null | undefined;
/**
* List of markdown extensions, with dot (default: `['.md', '.markdown', …]`);
* affects integrations.
*/
mdExtensions?: ReadonlyArray<string> | null | undefined;
/**
* List of MDX extensions, with dot (default: `['.mdx']`);
* affects integrations.
*/
mdxExtensions?: ReadonlyArray<string> | null | undefined;
/**
* Output format to generate (default: `'program'`);
* in most cases `'program'` should be used, it results in a whole program;
* internally `evaluate` uses `'function-body'` to compile to
* code that can be passed to `run`;
* in some cases, you might want what `evaluate` does in separate steps, such
* as when compiling on the server and running on the client.
*/
outputFormat?: 'function-body' | 'program' | null | undefined;
/**
* Pragma for JSX, used in the classic runtime as an identifier for function
* calls: `<x />` to `React.createElement('x')` (default:
* `'React.createElement'`);
* when changing this, you should also define `pragmaFrag` and
* `pragmaImportSource` too.
*
* > 👉 **Note**: support for the classic runtime is deprecated and will
* > likely be removed in the next major version.
*/
pragma?: string | null | undefined;
/**
* Pragma for fragment symbol, used in the classic runtime as an identifier
* for unnamed calls: `<>` to `React.createElement(React.Fragment)` (default:
* `'React.Fragment'`);
* when changing this, you should also define `pragma` and
* `pragmaImportSource` too.
*
* > 👉 **Note**: support for the classic runtime is deprecated and will
* > likely be removed in the next major version.
*/
pragmaFrag?: string | null | undefined;
/**
* Where to import the identifier of `pragma` from, used in the classic
* runtime (default: `'react'`);
* to illustrate, when `pragma` is `'a.b'` and `pragmaImportSource` is `'c'`
* the following will be generated: `import a from 'c'` and things such as
* `a.b('h1', {})`.
* when changing this, you should also define `pragma` and `pragmaFrag` too.
*
* > 👉 **Note**: support for the classic runtime is deprecated and will
* > likely be removed in the next major version.
*/
pragmaImportSource?: string | null | undefined;
/**
* Place to import a provider from (optional, example: `'@mdx-js/react'`);
* normally its used for runtimes that support context (React, Preact), but
* it can be used to inject components into the compiled code;
* the module must export and identifier `useMDXComponents` which is called
* without arguments to get an object of components (`MDXComponents` from
* `mdx/types.js`).
*/
providerImportSource?: string | null | undefined;
/**
* List of recma plugins (optional);
* this is a new ecosystem, currently in beta, to transform esast trees
* (JavaScript)
*/
recmaPlugins?: import("unified").PluggableList | null | undefined;
/**
* List of remark plugins (optional).
*/
remarkPlugins?: import("unified").PluggableList | null | undefined;
/**
* List of rehype plugins (optional).
*/
rehypePlugins?: import("unified").PluggableList | null | undefined;
/**
* Options to pass through to `remark-rehype` (optional);
* the option `allowDangerousHtml` will always be set to `true` and the MDX
* nodes (see `nodeTypes`) are passed through;
* In particular, you might want to pass configuration for footnotes if your
* content is not in English.
*/
remarkRehypeOptions?: Readonly<RemarkRehypeOptions> | null | undefined;
/**
* Casing to use for property names in `style` objects (default: `'dom'`);
* CSS casing is for example `background-color` and `-webkit-line-clamp`;
* DOM casing is for example `backgroundColor` and `WebkitLineClamp`;
* for JSX components written in MDX, the author has to be aware of which
* framework they use and write code accordingly;
* for AST nodes generated by this project, this option configures it
*/
stylePropertyNameCase?: StylePropertyNameCase | null | undefined;
/**
* Turn obsolete `align` properties on `td` and `th` into CSS `style`
* properties (default: `true`).
*/
tableCellAlignToStyle?: boolean | null | undefined;
};
//# sourceMappingURL=core.d.ts.map

1
node_modules/@mdx-js/mdx/lib/core.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["core.js"],"names":[],"mappings":"AAwJA;;;;;;;;;GASG;AACH,0CALW,SAAS,gBAAgB,CAAC,GAAG,IAAI,GAAG,SAAS,GAE5C,SAAS,CA0EpB;sBAxOY,OAAO,YAAY,EAAE,OAAO;uCAC5B,OAAO,qBAAqB,EAAE,wBAAwB;oCACtD,OAAO,qBAAqB,EAAE,qBAAqB;mBACnD,OAAO,OAAO,EAAE,IAAI;kCACpB,OAAO,eAAe,EAAE,OAAO;iCAC/B,cAAc,YAAY,EAAE,kBAAkB;4BAC9C,OAAO,SAAS,EAAE,aAAa;wBAC/B,OAAO,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC;;;;;;;;;yBAMnE,kBAAkB,GAAG,IAAI,GAAG,SAAS;;;;;cAGrC,GAAG,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS;;;;;;;;;kBAG/B,OAAO,GAAG,IAAI,GAAG,SAAS;;;;;;;;;+BAO1B,wBAAwB,GAAG,IAAI,GAAG,SAAS;;;;;aAO3C,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,SAAS;;;;;;UAG/B,OAAO,GAAG,IAAI,GAAG,SAAS;;;;;;sBAI1B,MAAM,GAAG,IAAI,GAAG,SAAS;;;;;;;;;;iBAIzB,WAAW,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS;;;;;mBAQ1C,cAAc,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS;;;;;oBAGxC,cAAc,MAAM,CAAC,GAAG,IAAI,GAAG,SAAS;;;;;;;;;mBAGxC,eAAe,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS;;;;;;;;;;;aAO9C,MAAM,GAAG,IAAI,GAAG,SAAS;;;;;;;;;;;iBASzB,MAAM,GAAG,IAAI,GAAG,SAAS;;;;;;;;;;;;yBASzB,MAAM,GAAG,IAAI,GAAG,SAAS;;;;;;;;;2BAUzB,MAAM,GAAG,IAAI,GAAG,SAAS;;;;;;mBAOzB,kCAAgB,IAAI,GAAG,SAAS;;;;oBAIhC,kCAAgB,IAAI,GAAG,SAAS;;;;oBAEhC,kCAAgB,IAAI,GAAG,SAAS;;;;;;;;0BAEhC,SAAS,mBAAmB,CAAC,GAAG,IAAI,GAAG,SAAS;;;;;;;;;4BAMhD,qBAAqB,GAAG,IAAI,GAAG,SAAS;;;;;4BAOxC,OAAO,GAAG,IAAI,GAAG,SAAS"}

234
node_modules/@mdx-js/mdx/lib/core.js generated vendored Normal file
View File

@@ -0,0 +1,234 @@
/**
* @typedef {import('estree-jsx').Program} Program
* @typedef {import('hast-util-to-estree').ElementAttributeNameCase} ElementAttributeNameCase
* @typedef {import('hast-util-to-estree').StylePropertyNameCase} StylePropertyNameCase
* @typedef {import('mdast').Root} Root
* @typedef {import('remark-rehype').Options} RemarkRehypeOptions
* @typedef {typeof import('source-map').SourceMapGenerator} SourceMapGenerator
* @typedef {import('unified').PluggableList} PluggableList
* @typedef {import('unified').Processor<Root, Program, Program, Program, string>} Processor
*/
/**
* @typedef ProcessorOptions
* Configuration for `createProcessor`.
* @property {SourceMapGenerator | null | undefined} [SourceMapGenerator]
* Add a source map (object form) as the `map` field on the resulting file
* (optional).
* @property {URL | string | null | undefined} [baseUrl]
* Use this URL as `import.meta.url` and resolve `import` and `export … from`
* relative to it (optional, example: `import.meta.url`).
* @property {boolean | null | undefined} [development=false]
* Whether to add extra info to error messages in generated code and use the
* development automatic JSX runtime (`Fragment` and `jsxDEV` from
* `/jsx-dev-runtime`) (default: `false`);
* when using the webpack loader (`@mdx-js/loader`) or the Rollup integration
* (`@mdx-js/rollup`) through Vite, this is automatically inferred from how
* you configure those tools.
* @property {ElementAttributeNameCase | null | undefined} [elementAttributeNameCase='react']
* Casing to use for attribute names (default: `'react'`);
* HTML casing is for example `class`, `stroke-linecap`, `xml:lang`;
* React casing is for example `className`, `strokeLinecap`, `xmlLang`;
* for JSX components written in MDX, the author has to be aware of which
* framework they use and write code accordingly;
* for AST nodes generated by this project, this option configures it
* @property {'md' | 'mdx' | null | undefined} [format='mdx']
* format of the file (default: `'mdx'`);
* `'md'` means treat as markdown and `'mdx'` means treat as MDX.
* @property {boolean | null | undefined} [jsx=false]
* Whether to keep JSX (default: `false`);
* the default is to compile JSX away so that the resulting file is
* immediately runnable.
* @property {string | null | undefined} [jsxImportSource='react']
* Place to import automatic JSX runtimes from (default: `'react'`);
* when in the `automatic` runtime, this is used to define an import for
* `Fragment`, `jsx`, `jsxDEV`, and `jsxs`.
* @property {'automatic' | 'classic' | null | undefined} [jsxRuntime='automatic']
* JSX runtime to use (default: `'automatic'`);
* the automatic runtime compiles to `import _jsx from
* '$importSource/jsx-runtime'\n_jsx('p')`;
* the classic runtime compiles to calls such as `h('p')`.
*
* > 👉 **Note**: support for the classic runtime is deprecated and will
* > likely be removed in the next major version.
* @property {ReadonlyArray<string> | null | undefined} [mdExtensions]
* List of markdown extensions, with dot (default: `['.md', '.markdown', …]`);
* affects integrations.
* @property {ReadonlyArray<string> | null | undefined} [mdxExtensions]
* List of MDX extensions, with dot (default: `['.mdx']`);
* affects integrations.
* @property {'function-body' | 'program' | null | undefined} [outputFormat='program']
* Output format to generate (default: `'program'`);
* in most cases `'program'` should be used, it results in a whole program;
* internally `evaluate` uses `'function-body'` to compile to
* code that can be passed to `run`;
* in some cases, you might want what `evaluate` does in separate steps, such
* as when compiling on the server and running on the client.
* @property {string | null | undefined} [pragma='React.createElement']
* Pragma for JSX, used in the classic runtime as an identifier for function
* calls: `<x />` to `React.createElement('x')` (default:
* `'React.createElement'`);
* when changing this, you should also define `pragmaFrag` and
* `pragmaImportSource` too.
*
* > 👉 **Note**: support for the classic runtime is deprecated and will
* > likely be removed in the next major version.
* @property {string | null | undefined} [pragmaFrag='React.Fragment']
* Pragma for fragment symbol, used in the classic runtime as an identifier
* for unnamed calls: `<>` to `React.createElement(React.Fragment)` (default:
* `'React.Fragment'`);
* when changing this, you should also define `pragma` and
* `pragmaImportSource` too.
*
* > 👉 **Note**: support for the classic runtime is deprecated and will
* > likely be removed in the next major version.
* @property {string | null | undefined} [pragmaImportSource='react']
* Where to import the identifier of `pragma` from, used in the classic
* runtime (default: `'react'`);
* to illustrate, when `pragma` is `'a.b'` and `pragmaImportSource` is `'c'`
* the following will be generated: `import a from 'c'` and things such as
* `a.b('h1', {})`.
* when changing this, you should also define `pragma` and `pragmaFrag` too.
*
* > 👉 **Note**: support for the classic runtime is deprecated and will
* > likely be removed in the next major version.
* @property {string | null | undefined} [providerImportSource]
* Place to import a provider from (optional, example: `'@mdx-js/react'`);
* normally its used for runtimes that support context (React, Preact), but
* it can be used to inject components into the compiled code;
* the module must export and identifier `useMDXComponents` which is called
* without arguments to get an object of components (`MDXComponents` from
* `mdx/types.js`).
* @property {PluggableList | null | undefined} [recmaPlugins]
* List of recma plugins (optional);
* this is a new ecosystem, currently in beta, to transform esast trees
* (JavaScript)
* @property {PluggableList | null | undefined} [remarkPlugins]
* List of remark plugins (optional).
* @property {PluggableList | null | undefined} [rehypePlugins]
* List of rehype plugins (optional).
* @property {Readonly<RemarkRehypeOptions> | null | undefined} [remarkRehypeOptions]
* Options to pass through to `remark-rehype` (optional);
* the option `allowDangerousHtml` will always be set to `true` and the MDX
* nodes (see `nodeTypes`) are passed through;
* In particular, you might want to pass configuration for footnotes if your
* content is not in English.
* @property {StylePropertyNameCase | null | undefined} [stylePropertyNameCase='dom']
* Casing to use for property names in `style` objects (default: `'dom'`);
* CSS casing is for example `background-color` and `-webkit-line-clamp`;
* DOM casing is for example `backgroundColor` and `WebkitLineClamp`;
* for JSX components written in MDX, the author has to be aware of which
* framework they use and write code accordingly;
* for AST nodes generated by this project, this option configures it
* @property {boolean | null | undefined} [tableCellAlignToStyle=true]
* Turn obsolete `align` properties on `td` and `th` into CSS `style`
* properties (default: `true`).
*/
import {unreachable} from 'devlop'
import remarkMdx from 'remark-mdx'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import {unified} from 'unified'
import {recmaDocument} from './plugin/recma-document.js'
import {recmaJsxBuild} from './plugin/recma-jsx-build.js'
import {recmaJsxRewrite} from './plugin/recma-jsx-rewrite.js'
import {recmaStringify} from './plugin/recma-stringify.js'
import {rehypeRecma} from './plugin/rehype-recma.js'
import {rehypeRemoveRaw} from './plugin/rehype-remove-raw.js'
import {remarkMarkAndUnravel} from './plugin/remark-mark-and-unravel.js'
import {nodeTypes} from './node-types.js'
const removedOptions = [
'compilers',
'filepath',
'hastPlugins',
'mdPlugins',
'skipExport',
'wrapExport'
]
let warned = false
/**
* Create a processor to compile markdown or MDX to JavaScript.
*
* > **Note**: `format: 'detect'` is not allowed in `ProcessorOptions`.
*
* @param {Readonly<ProcessorOptions> | null | undefined} [options]
* Configuration (optional).
* @return {Processor}
* Processor.
*/
export function createProcessor(options) {
const settings = options || {}
let index = -1
while (++index < removedOptions.length) {
const key = removedOptions[index]
if (key in settings) {
unreachable(
'Unexpected removed option `' +
key +
'`; see <https://mdxjs.com/migrating/v2/> on how to migrate'
)
}
}
// @ts-expect-error: throw an error for a runtime value which is not allowed
// by the types.
if (settings.format === 'detect') {
unreachable(
"Unexpected `format: 'detect'`, which is not supported by `createProcessor`, expected `'mdx'` or `'md'`"
)
}
if (
(settings.jsxRuntime === 'classic' ||
settings.pragma ||
settings.pragmaFrag ||
settings.pragmaImportSource) &&
!warned
) {
warned = true
console.warn(
"Unexpected deprecated option `jsxRuntime: 'classic'`, `pragma`, `pragmaFrag`, or `pragmaImportSource`; see <https://mdxjs.com/migrating/v3/> on how to migrate"
)
}
const pipeline = unified().use(remarkParse)
if (settings.format !== 'md') {
pipeline.use(remarkMdx)
}
const remarkRehypeOptions = settings.remarkRehypeOptions || {}
pipeline
.use(remarkMarkAndUnravel)
.use(settings.remarkPlugins || [])
.use(remarkRehype, {
...remarkRehypeOptions,
allowDangerousHtml: true,
passThrough: [...(remarkRehypeOptions.passThrough || []), ...nodeTypes]
})
.use(settings.rehypePlugins || [])
if (settings.format === 'md') {
pipeline.use(rehypeRemoveRaw)
}
pipeline
.use(rehypeRecma, settings)
.use(recmaDocument, settings)
.use(recmaJsxRewrite, settings)
if (!settings.jsx) {
pipeline.use(recmaJsxBuild, settings)
}
pipeline.use(recmaStringify, settings).use(settings.recmaPlugins || [])
// @ts-expect-error: we added plugins with if-checks, which TS doesnt get.
return pipeline
}

56
node_modules/@mdx-js/mdx/lib/evaluate.d.ts generated vendored Normal file
View File

@@ -0,0 +1,56 @@
/**
* Compile and run MDX.
*
* When you trust your content, `evaluate` can work.
* When possible, use `compile`, write to a file, and then run with Node or use
* one of the integrations.
*
* > ☢️ **Danger**: its called **evaluate** because it `eval`s JavaScript.
*
* ###### Notes
*
* Compiling (and running) MDX takes time.
*
* If you are live-rendering a string of MDX that often changes using a virtual
* DOM based framework (such as React), one performance improvement is to call
* the `MDXContent` component yourself.
* The reason is that the `evaluate` creates a new function each time, which
* cannot be diffed:
*
* ```diff
* const {default: MDXContent} = await evaluate('…')
*
* -<MDXContent {...props} />
* +MDXContent(props)
* ```
*
* @param {Readonly<Compatible>} file
* MDX document to parse.
* @param {Readonly<EvaluateOptions>} options
* Configuration (**required**).
* @return {Promise<MDXModule>}
* Promise to a module;
* the result is an object with a `default` field set to the component;
* anything else that was exported is available too.
*/
export function evaluate(file: Readonly<Compatible>, options: Readonly<EvaluateOptions>): Promise<MDXModule>;
/**
* Compile and run MDX, synchronously.
*
* When possible please use the async `evaluate`.
*
* > ☢️ **Danger**: its called **evaluate** because it `eval`s JavaScript.
*
* @param {Readonly<Compatible>} file
* MDX document to parse.
* @param {Readonly<EvaluateOptions>} options
* Configuration (**required**).
* @return {MDXModule}
* Module.
*/
export function evaluateSync(file: Readonly<Compatible>, options: Readonly<EvaluateOptions>): MDXModule;
export type MDXModule = import('mdx/types.js').MDXModule;
export type Compatible = import('vfile').Compatible;
export type EvaluateOptions = import('./util/resolve-evaluate-options.js').EvaluateOptions;
//# sourceMappingURL=evaluate.d.ts.map

1
node_modules/@mdx-js/mdx/lib/evaluate.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["evaluate.js"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,+BAVW,SAAS,UAAU,CAAC,WAEpB,SAAS,eAAe,CAAC,GAExB,QAAQ,SAAS,CAAC,CAS7B;AAED;;;;;;;;;;;;;GAaG;AACH,mCAPW,SAAS,UAAU,CAAC,WAEpB,SAAS,eAAe,CAAC,GAExB,SAAS,CAMpB;wBAnEY,OAAO,cAAc,EAAE,SAAS;yBAChC,OAAO,OAAO,EAAE,UAAU;8BAC1B,OAAO,oCAAoC,EAAE,eAAe"}

69
node_modules/@mdx-js/mdx/lib/evaluate.js generated vendored Normal file
View File

@@ -0,0 +1,69 @@
/**
* @typedef {import('mdx/types.js').MDXModule} MDXModule
* @typedef {import('vfile').Compatible} Compatible
* @typedef {import('./util/resolve-evaluate-options.js').EvaluateOptions} EvaluateOptions
*/
import {resolveEvaluateOptions} from './util/resolve-evaluate-options.js'
import {compile, compileSync} from './compile.js'
import {run, runSync} from './run.js'
/**
* Compile and run MDX.
*
* When you trust your content, `evaluate` can work.
* When possible, use `compile`, write to a file, and then run with Node or use
* one of the integrations.
*
* > ☢️ **Danger**: its called **evaluate** because it `eval`s JavaScript.
*
* ###### Notes
*
* Compiling (and running) MDX takes time.
*
* If you are live-rendering a string of MDX that often changes using a virtual
* DOM based framework (such as React), one performance improvement is to call
* the `MDXContent` component yourself.
* The reason is that the `evaluate` creates a new function each time, which
* cannot be diffed:
*
* ```diff
* const {default: MDXContent} = await evaluate('…')
*
* -<MDXContent {...props} />
* +MDXContent(props)
* ```
*
* @param {Readonly<Compatible>} file
* MDX document to parse.
* @param {Readonly<EvaluateOptions>} options
* Configuration (**required**).
* @return {Promise<MDXModule>}
* Promise to a module;
* the result is an object with a `default` field set to the component;
* anything else that was exported is available too.
*/
export async function evaluate(file, options) {
const {compiletime, runtime} = resolveEvaluateOptions(options)
return run(await compile(file, compiletime), runtime)
}
/**
* Compile and run MDX, synchronously.
*
* When possible please use the async `evaluate`.
*
* > ☢️ **Danger**: its called **evaluate** because it `eval`s JavaScript.
*
* @param {Readonly<Compatible>} file
* MDX document to parse.
* @param {Readonly<EvaluateOptions>} options
* Configuration (**required**).
* @return {MDXModule}
* Module.
*/
export function evaluateSync(file, options) {
const {compiletime, runtime} = resolveEvaluateOptions(options)
return runSync(compileSync(file, compiletime), runtime)
}

6
node_modules/@mdx-js/mdx/lib/node-types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,6 @@
/**
* List of node types made by `mdast-util-mdx`, which have to be passed
* through untouched from the mdast tree to the hast tree.
*/
export const nodeTypes: readonly ["mdxFlowExpression", "mdxJsxFlowElement", "mdxJsxTextElement", "mdxTextExpression", "mdxjsEsm"];
//# sourceMappingURL=node-types.d.ts.map

1
node_modules/@mdx-js/mdx/lib/node-types.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"node-types.d.ts","sourceRoot":"","sources":["node-types.js"],"names":[],"mappings":"AAAA;;;GAGG;AACH,kIAME"}

11
node_modules/@mdx-js/mdx/lib/node-types.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
/**
* List of node types made by `mdast-util-mdx`, which have to be passed
* through untouched from the mdast tree to the hast tree.
*/
export const nodeTypes = /** @type {const} */ ([
'mdxFlowExpression',
'mdxJsxFlowElement',
'mdxJsxTextElement',
'mdxTextExpression',
'mdxjsEsm'
])

View File

@@ -0,0 +1,36 @@
/**
* Wrap the estree in `MDXContent`.
*
* @param {Readonly<ProcessorOptions>} options
* Configuration.
* @returns
* Transform.
*/
export function recmaDocument(options: Readonly<ProcessorOptions>): (tree: Program, file: VFile) => undefined;
export type CallExpression = import('estree-jsx').CallExpression;
export type Directive = import('estree-jsx').Directive;
export type ExportAllDeclaration = import('estree-jsx').ExportAllDeclaration;
export type ExportDefaultDeclaration = import('estree-jsx').ExportDefaultDeclaration;
export type ExportNamedDeclaration = import('estree-jsx').ExportNamedDeclaration;
export type ExportSpecifier = import('estree-jsx').ExportSpecifier;
export type Expression = import('estree-jsx').Expression;
export type FunctionDeclaration = import('estree-jsx').FunctionDeclaration;
export type Identifier = import('estree-jsx').Identifier;
export type ImportDeclaration = import('estree-jsx').ImportDeclaration;
export type ImportDefaultSpecifier = import('estree-jsx').ImportDefaultSpecifier;
export type ImportExpression = import('estree-jsx').ImportExpression;
export type ImportSpecifier = import('estree-jsx').ImportSpecifier;
export type JSXElement = import('estree-jsx').JSXElement;
export type JSXFragment = import('estree-jsx').JSXFragment;
export type Literal = import('estree-jsx').Literal;
export type ModuleDeclaration = import('estree-jsx').ModuleDeclaration;
export type Node = import('estree-jsx').Node;
export type Program = import('estree-jsx').Program;
export type Property = import('estree-jsx').Property;
export type SimpleLiteral = import('estree-jsx').SimpleLiteral;
export type SpreadElement = import('estree-jsx').SpreadElement;
export type Statement = import('estree-jsx').Statement;
export type VariableDeclarator = import('estree-jsx').VariableDeclarator;
export type VFile = import('vfile').VFile;
export type ProcessorOptions = import('../core.js').ProcessorOptions;
//# sourceMappingURL=recma-document.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"recma-document.d.ts","sourceRoot":"","sources":["recma-document.js"],"names":[],"mappings":"AA0CA;;;;;;;GAOG;AACH,uCALW,SAAS,gBAAgB,CAAC,UAkBxB,OAAO,QAEP,KAAK,KAEH,SAAS,CAknBvB;6BAprBY,OAAO,YAAY,EAAE,cAAc;wBACnC,OAAO,YAAY,EAAE,SAAS;mCAC9B,OAAO,YAAY,EAAE,oBAAoB;uCACzC,OAAO,YAAY,EAAE,wBAAwB;qCAC7C,OAAO,YAAY,EAAE,sBAAsB;8BAC3C,OAAO,YAAY,EAAE,eAAe;yBACpC,OAAO,YAAY,EAAE,UAAU;kCAC/B,OAAO,YAAY,EAAE,mBAAmB;yBACxC,OAAO,YAAY,EAAE,UAAU;gCAC/B,OAAO,YAAY,EAAE,iBAAiB;qCACtC,OAAO,YAAY,EAAE,sBAAsB;+BAC3C,OAAO,YAAY,EAAE,gBAAgB;8BACrC,OAAO,YAAY,EAAE,eAAe;yBACpC,OAAO,YAAY,EAAE,UAAU;0BAC/B,OAAO,YAAY,EAAE,WAAW;sBAChC,OAAO,YAAY,EAAE,OAAO;gCAC5B,OAAO,YAAY,EAAE,iBAAiB;mBACtC,OAAO,YAAY,EAAE,IAAI;sBACzB,OAAO,YAAY,EAAE,OAAO;uBAC5B,OAAO,YAAY,EAAE,QAAQ;4BAC7B,OAAO,YAAY,EAAE,aAAa;4BAClC,OAAO,YAAY,EAAE,aAAa;wBAClC,OAAO,YAAY,EAAE,SAAS;iCAC9B,OAAO,YAAY,EAAE,kBAAkB;oBAEvC,OAAO,OAAO,EAAE,KAAK;+BAErB,OAAO,YAAY,EAAE,gBAAgB"}

880
node_modules/@mdx-js/mdx/lib/plugin/recma-document.js generated vendored Normal file
View File

@@ -0,0 +1,880 @@
/**
* @typedef {import('estree-jsx').CallExpression} CallExpression
* @typedef {import('estree-jsx').Directive} Directive
* @typedef {import('estree-jsx').ExportAllDeclaration} ExportAllDeclaration
* @typedef {import('estree-jsx').ExportDefaultDeclaration} ExportDefaultDeclaration
* @typedef {import('estree-jsx').ExportNamedDeclaration} ExportNamedDeclaration
* @typedef {import('estree-jsx').ExportSpecifier} ExportSpecifier
* @typedef {import('estree-jsx').Expression} Expression
* @typedef {import('estree-jsx').FunctionDeclaration} FunctionDeclaration
* @typedef {import('estree-jsx').Identifier} Identifier
* @typedef {import('estree-jsx').ImportDeclaration} ImportDeclaration
* @typedef {import('estree-jsx').ImportDefaultSpecifier} ImportDefaultSpecifier
* @typedef {import('estree-jsx').ImportExpression} ImportExpression
* @typedef {import('estree-jsx').ImportSpecifier} ImportSpecifier
* @typedef {import('estree-jsx').JSXElement} JSXElement
* @typedef {import('estree-jsx').JSXFragment} JSXFragment
* @typedef {import('estree-jsx').Literal} Literal
* @typedef {import('estree-jsx').ModuleDeclaration} ModuleDeclaration
* @typedef {import('estree-jsx').Node} Node
* @typedef {import('estree-jsx').Program} Program
* @typedef {import('estree-jsx').Property} Property
* @typedef {import('estree-jsx').SimpleLiteral} SimpleLiteral
* @typedef {import('estree-jsx').SpreadElement} SpreadElement
* @typedef {import('estree-jsx').Statement} Statement
* @typedef {import('estree-jsx').VariableDeclarator} VariableDeclarator
*
* @typedef {import('vfile').VFile} VFile
*
* @typedef {import('../core.js').ProcessorOptions} ProcessorOptions
*/
import {ok as assert} from 'devlop'
import {walk} from 'estree-walker'
import {analyze} from 'periscopic'
import {positionFromEstree} from 'unist-util-position-from-estree'
import {stringifyPosition} from 'unist-util-stringify-position'
import {create} from '../util/estree-util-create.js'
import {declarationToExpression} from '../util/estree-util-declaration-to-expression.js'
import {isDeclaration} from '../util/estree-util-is-declaration.js'
import {specifiersToDeclarations} from '../util/estree-util-specifiers-to-declarations.js'
import {toIdOrMemberExpression} from '../util/estree-util-to-id-or-member-expression.js'
/**
* Wrap the estree in `MDXContent`.
*
* @param {Readonly<ProcessorOptions>} options
* Configuration.
* @returns
* Transform.
*/
export function recmaDocument(options) {
const baseUrl = options.baseUrl || undefined
const baseHref = typeof baseUrl === 'object' ? baseUrl.href : baseUrl
const outputFormat = options.outputFormat || 'program'
const pragma =
options.pragma === undefined ? 'React.createElement' : options.pragma
const pragmaFrag =
options.pragmaFrag === undefined ? 'React.Fragment' : options.pragmaFrag
const pragmaImportSource = options.pragmaImportSource || 'react'
const jsxImportSource = options.jsxImportSource || 'react'
const jsxRuntime = options.jsxRuntime || 'automatic'
/**
* @param {Program} tree
* Tree.
* @param {VFile} file
* File.
* @returns {undefined}
* Nothing.
*/
return function (tree, file) {
/** @type {Array<[string, string] | string>} */
const exportedIdentifiers = []
/** @type {Array<Directive | ModuleDeclaration | Statement>} */
const replacement = []
let exportAllCount = 0
/** @type {ExportDefaultDeclaration | ExportSpecifier | undefined} */
let layout
/** @type {boolean | undefined} */
let content
/** @type {Node} */
let child
if (jsxRuntime === 'classic' && pragmaFrag) {
injectPragma(tree, '@jsxFrag', pragmaFrag)
}
if (jsxRuntime === 'classic' && pragma) {
injectPragma(tree, '@jsx', pragma)
}
if (jsxRuntime === 'automatic' && jsxImportSource) {
injectPragma(tree, '@jsxImportSource', jsxImportSource)
}
if (jsxRuntime) {
injectPragma(tree, '@jsxRuntime', jsxRuntime)
}
if (jsxRuntime === 'classic' && pragmaImportSource) {
if (!pragma) {
throw new Error(
'Missing `pragma` in classic runtime with `pragmaImportSource`'
)
}
handleEsm({
type: 'ImportDeclaration',
specifiers: [
{
type: 'ImportDefaultSpecifier',
local: {type: 'Identifier', name: pragma.split('.')[0]}
}
],
source: {type: 'Literal', value: pragmaImportSource}
})
}
// Find the `export default`, the JSX expression, and leave the rest
// (import/exports) as they are.
for (child of tree.body) {
// ```tsx
// export default properties => <>{properties.children}</>
// ```
//
// Treat it as an inline layout declaration.
if (child.type === 'ExportDefaultDeclaration') {
if (layout) {
file.fail(
'Unexpected duplicate layout, expected a single layout (previous: ' +
stringifyPosition(positionFromEstree(layout)) +
')',
{
ancestors: [tree, child],
place: positionFromEstree(child),
ruleId: 'duplicate-layout',
source: 'recma-document'
}
)
}
layout = child
replacement.push({
type: 'VariableDeclaration',
kind: 'const',
declarations: [
{
type: 'VariableDeclarator',
id: {type: 'Identifier', name: 'MDXLayout'},
init: isDeclaration(child.declaration)
? declarationToExpression(child.declaration)
: child.declaration
}
]
})
}
// ```tsx
// export {a, b as c} from 'd'
// ```
else if (child.type === 'ExportNamedDeclaration' && child.source) {
// Cast because always simple.
const source = /** @type {SimpleLiteral} */ (child.source)
// Remove `default` or `as default`, but not `default as`, specifier.
child.specifiers = child.specifiers.filter(function (specifier) {
if (specifier.exported.name === 'default') {
if (layout) {
file.fail(
'Unexpected duplicate layout, expected a single layout (previous: ' +
stringifyPosition(positionFromEstree(layout)) +
')',
{
ancestors: [tree, child, specifier],
place: positionFromEstree(child),
ruleId: 'duplicate-layout',
source: 'recma-document'
}
)
}
layout = specifier
// Make it just an import: `import MDXLayout from '…'`.
/** @type {Array<ImportDefaultSpecifier | ImportSpecifier>} */
const specifiers = []
// Default as default / something else as default.
if (specifier.local.name === 'default') {
specifiers.push({
type: 'ImportDefaultSpecifier',
local: {type: 'Identifier', name: 'MDXLayout'}
})
} else {
/** @type {ImportSpecifier} */
const importSpecifier = {
type: 'ImportSpecifier',
imported: specifier.local,
local: {type: 'Identifier', name: 'MDXLayout'}
}
create(specifier.local, importSpecifier)
specifiers.push(importSpecifier)
}
/** @type {Literal} */
const from = {type: 'Literal', value: source.value}
create(source, from)
/** @type {ImportDeclaration} */
const declaration = {
type: 'ImportDeclaration',
specifiers,
source: from
}
create(specifier, declaration)
handleEsm(declaration)
return false
}
return true
})
// If there are other things imported, keep it.
if (child.specifiers.length > 0) {
handleExport(child)
}
}
// ```tsx
// export {a, b as c}
// export * from 'a'
// ```
else if (
child.type === 'ExportNamedDeclaration' ||
child.type === 'ExportAllDeclaration'
) {
handleExport(child)
} else if (child.type === 'ImportDeclaration') {
handleEsm(child)
} else if (
child.type === 'ExpressionStatement' &&
(child.expression.type === 'JSXElement' ||
// @ts-expect-error: `estree-jsx` does not register `JSXFragment` as an expression.
child.expression.type === 'JSXFragment')
) {
content = true
replacement.push(
...createMdxContent(child.expression, outputFormat, Boolean(layout))
)
} else {
// This catch-all branch is because plugins might add other things.
// Normally, we only have import/export/jsx, but just add whatevers
// there.
replacement.push(child)
}
}
// If there was no JSX content at all, add an empty function.
if (!content) {
replacement.push(
...createMdxContent(undefined, outputFormat, Boolean(layout))
)
}
exportedIdentifiers.push(['MDXContent', 'default'])
if (outputFormat === 'function-body') {
replacement.push({
type: 'ReturnStatement',
argument: {
type: 'ObjectExpression',
properties: [
...Array.from({length: exportAllCount}).map(
/**
* @param {undefined} _
* Nothing.
* @param {number} index
* Index.
* @returns {SpreadElement}
* Node.
*/
function (_, index) {
return {
type: 'SpreadElement',
argument: {
type: 'Identifier',
name: '_exportAll' + (index + 1)
}
}
}
),
...exportedIdentifiers.map(function (d) {
/** @type {Property} */
const property = {
type: 'Property',
kind: 'init',
method: false,
computed: false,
shorthand: typeof d === 'string',
key: {
type: 'Identifier',
name: typeof d === 'string' ? d : d[1]
},
value: {
type: 'Identifier',
name: typeof d === 'string' ? d : d[0]
}
}
return property
})
]
}
})
}
tree.body = replacement
let usesImportMetaUrlVariable = false
let usesResolveDynamicHelper = false
if (baseHref || outputFormat === 'function-body') {
walk(tree, {
enter(node) {
if (
(node.type === 'ExportAllDeclaration' ||
node.type === 'ExportNamedDeclaration' ||
node.type === 'ImportDeclaration') &&
node.source
) {
// We never hit this branch when generating function bodies, as
// statements are already compiled away into import expressions.
assert(baseHref, 'unexpected missing `baseHref` in branch')
let value = node.source.value
// The literal source for statements can only be string.
assert(typeof value === 'string', 'expected string source')
// Resolve a specifier.
// This is the same as `_resolveDynamicMdxSpecifier`, which has to
// be injected to work with expressions at runtime, but as we have
// `baseHref` at compile time here and statements are static
// strings, we can do it now.
try {
// To do: use `URL.canParse` next major.
// eslint-disable-next-line no-new
new URL(value)
// Fine: a full URL.
} catch {
if (
value.startsWith('/') ||
value.startsWith('./') ||
value.startsWith('../')
) {
value = new URL(value, baseHref).href
} else {
// Fine: are bare specifier.
}
}
/** @type {SimpleLiteral} */
const replacement = {type: 'Literal', value}
create(node.source, replacement)
node.source = replacement
return
}
if (node.type === 'ImportExpression') {
usesResolveDynamicHelper = true
/** @type {CallExpression} */
const replacement = {
type: 'CallExpression',
callee: {type: 'Identifier', name: '_resolveDynamicMdxSpecifier'},
arguments: [node.source],
optional: false
}
node.source = replacement
return
}
// To do: add support for `import.meta.resolve`.
if (
node.type === 'MemberExpression' &&
'object' in node &&
node.object.type === 'MetaProperty' &&
node.property.type === 'Identifier' &&
node.object.meta.name === 'import' &&
node.object.property.name === 'meta' &&
node.property.name === 'url'
) {
usesImportMetaUrlVariable = true
/** @type {Identifier} */
const replacement = {type: 'Identifier', name: '_importMetaUrl'}
create(node, replacement)
this.replace(replacement)
}
}
})
}
if (usesResolveDynamicHelper) {
if (!baseHref) {
usesImportMetaUrlVariable = true
}
tree.body.push(
resolveDynamicMdxSpecifier(
baseHref
? {type: 'Literal', value: baseHref}
: {type: 'Identifier', name: '_importMetaUrl'}
)
)
}
if (usesImportMetaUrlVariable) {
assert(
outputFormat === 'function-body',
'expected `function-body` when using dynamic url injection'
)
tree.body.unshift(...createImportMetaUrlVariable())
}
/**
* @param {ExportAllDeclaration | ExportNamedDeclaration} node
* Export node.
* @returns {undefined}
* Nothing.
*/
function handleExport(node) {
if (node.type === 'ExportNamedDeclaration') {
// ```tsx
// export function a() {}
// export class A {}
// export var a = 1
// ```
if (node.declaration) {
exportedIdentifiers.push(
...analyze(node.declaration).scope.declarations.keys()
)
}
// ```tsx
// export {a, b as c}
// export {a, b as c} from 'd'
// ```
for (child of node.specifiers) {
exportedIdentifiers.push(child.exported.name)
}
}
handleEsm(node)
}
/**
* @param {ExportAllDeclaration | ExportNamedDeclaration | ImportDeclaration} node
* Export or import node.
* @returns {undefined}
* Nothing.
*/
function handleEsm(node) {
/** @type {ModuleDeclaration | Statement | undefined} */
let replace
/** @type {Expression} */
let init
if (outputFormat === 'function-body') {
if (
// Always have a source:
node.type === 'ImportDeclaration' ||
node.type === 'ExportAllDeclaration' ||
// Source optional:
(node.type === 'ExportNamedDeclaration' && node.source)
) {
// We always have a source, but types say they can be missing.
assert(node.source, 'expected `node.source` to be defined')
// ```
// import 'a'
// //=> await import('a')
// import a from 'b'
// //=> const {default: a} = await import('b')
// export {a, b as c} from 'd'
// //=> const {a, c: b} = await import('d')
// export * from 'a'
// //=> const _exportAll0 = await import('a')
// ```
/** @type {ImportExpression} */
const argument = {type: 'ImportExpression', source: node.source}
create(node, argument)
init = {type: 'AwaitExpression', argument}
if (
(node.type === 'ImportDeclaration' ||
node.type === 'ExportNamedDeclaration') &&
node.specifiers.length === 0
) {
replace = {type: 'ExpressionStatement', expression: init}
} else {
replace = {
type: 'VariableDeclaration',
kind: 'const',
declarations:
node.type === 'ExportAllDeclaration'
? [
{
type: 'VariableDeclarator',
id: {
type: 'Identifier',
name: '_exportAll' + ++exportAllCount
},
init
}
]
: specifiersToDeclarations(node.specifiers, init)
}
}
} else if (node.declaration) {
replace = node.declaration
} else {
/** @type {Array<VariableDeclarator>} */
const declarators = node.specifiers
.filter(function (specifier) {
return specifier.local.name !== specifier.exported.name
})
.map(function (specifier) {
return {
type: 'VariableDeclarator',
id: specifier.exported,
init: specifier.local
}
})
if (declarators.length > 0) {
replace = {
type: 'VariableDeclaration',
kind: 'const',
declarations: declarators
}
}
}
} else {
replace = node
}
if (replace) {
replacement.push(replace)
}
}
}
/**
* @param {Readonly<Expression> | undefined} content
* Content.
* @param {'function-body' | 'program'} outputFormat
* Output format.
* @param {boolean | undefined} [hasInternalLayout=false]
* Whether theres an internal layout (default: `false`).
* @returns {Array<ExportDefaultDeclaration | FunctionDeclaration>}
* Functions.
*/
function createMdxContent(content, outputFormat, hasInternalLayout) {
/** @type {JSXElement} */
const element = {
type: 'JSXElement',
openingElement: {
type: 'JSXOpeningElement',
name: {type: 'JSXIdentifier', name: 'MDXLayout'},
attributes: [
{
type: 'JSXSpreadAttribute',
argument: {type: 'Identifier', name: 'props'}
}
],
selfClosing: false
},
closingElement: {
type: 'JSXClosingElement',
name: {type: 'JSXIdentifier', name: 'MDXLayout'}
},
children: [
{
type: 'JSXElement',
openingElement: {
type: 'JSXOpeningElement',
name: {type: 'JSXIdentifier', name: '_createMdxContent'},
attributes: [
{
type: 'JSXSpreadAttribute',
argument: {type: 'Identifier', name: 'props'}
}
],
selfClosing: true
},
closingElement: null,
children: []
}
]
}
let result = /** @type {Expression} */ (element)
if (!hasInternalLayout) {
result = {
type: 'ConditionalExpression',
test: {type: 'Identifier', name: 'MDXLayout'},
consequent: result,
alternate: {
type: 'CallExpression',
callee: {type: 'Identifier', name: '_createMdxContent'},
arguments: [{type: 'Identifier', name: 'props'}],
optional: false
}
}
}
let argument =
// Cast because TS otherwise does not think `JSXFragment`s are expressions.
/** @type {Readonly<Expression> | Readonly<JSXFragment>} */ (
content || {type: 'Identifier', name: 'undefined'}
)
// Unwrap a fragment of a single element.
if (
argument.type === 'JSXFragment' &&
argument.children.length === 1 &&
argument.children[0].type === 'JSXElement'
) {
argument = argument.children[0]
}
let awaitExpression = false
walk(argument, {
enter(node) {
if (
node.type === 'ArrowFunctionExpression' ||
node.type === 'FunctionDeclaration' ||
node.type === 'FunctionExpression'
) {
return this.skip()
}
if (
node.type === 'AwaitExpression' ||
/* c8 ignore next 2 -- can only occur in a function (which then can
* only be async, so skipped it) */
(node.type === 'ForOfStatement' && node.await)
) {
awaitExpression = true
}
}
})
/** @type {FunctionDeclaration} */
const declaration = {
type: 'FunctionDeclaration',
id: {type: 'Identifier', name: 'MDXContent'},
params: [
{
type: 'AssignmentPattern',
left: {type: 'Identifier', name: 'props'},
right: {type: 'ObjectExpression', properties: []}
}
],
body: {
type: 'BlockStatement',
body: [{type: 'ReturnStatement', argument: result}]
}
}
return [
{
type: 'FunctionDeclaration',
async: awaitExpression,
id: {type: 'Identifier', name: '_createMdxContent'},
params: [{type: 'Identifier', name: 'props'}],
body: {
type: 'BlockStatement',
body: [
{
type: 'ReturnStatement',
// Cast because TS doesnt think `JSXFragment` is an expression.
// eslint-disable-next-line object-shorthand
argument: /** @type {Expression} */ (argument)
}
]
}
},
outputFormat === 'program'
? {type: 'ExportDefaultDeclaration', declaration}
: declaration
]
}
}
/**
* @param {Program} tree
* @param {string} name
* @param {string} value
* @returns {undefined}
*/
function injectPragma(tree, name, value) {
tree.comments?.unshift({
type: 'Block',
value: name + ' ' + value,
data: {_mdxIsPragmaComment: true}
})
}
/**
* @param {Expression} importMetaUrl
* @returns {FunctionDeclaration}
*/
function resolveDynamicMdxSpecifier(importMetaUrl) {
return {
type: 'FunctionDeclaration',
id: {type: 'Identifier', name: '_resolveDynamicMdxSpecifier'},
generator: false,
async: false,
params: [{type: 'Identifier', name: 'd'}],
body: {
type: 'BlockStatement',
body: [
{
type: 'IfStatement',
test: {
type: 'BinaryExpression',
left: {
type: 'UnaryExpression',
operator: 'typeof',
prefix: true,
argument: {type: 'Identifier', name: 'd'}
},
operator: '!==',
right: {type: 'Literal', value: 'string'}
},
consequent: {
type: 'ReturnStatement',
argument: {type: 'Identifier', name: 'd'}
},
alternate: null
},
// To do: use `URL.canParse` when widely supported (see commented
// out code below).
{
type: 'TryStatement',
block: {
type: 'BlockStatement',
body: [
{
type: 'ExpressionStatement',
expression: {
type: 'NewExpression',
callee: {type: 'Identifier', name: 'URL'},
arguments: [{type: 'Identifier', name: 'd'}]
}
},
{
type: 'ReturnStatement',
argument: {type: 'Identifier', name: 'd'}
}
]
},
handler: {
type: 'CatchClause',
param: null,
body: {type: 'BlockStatement', body: []}
},
finalizer: null
},
// To do: use `URL.canParse` when widely supported.
// {
// type: 'IfStatement',
// test: {
// type: 'CallExpression',
// callee: toIdOrMemberExpression(['URL', 'canParse']),
// arguments: [{type: 'Identifier', name: 'd'}],
// optional: false
// },
// consequent: {
// type: 'ReturnStatement',
// argument: {type: 'Identifier', name: 'd'}
// },
// alternate: null
// },
{
type: 'IfStatement',
test: {
type: 'LogicalExpression',
left: {
type: 'LogicalExpression',
left: {
type: 'CallExpression',
callee: toIdOrMemberExpression(['d', 'startsWith']),
arguments: [{type: 'Literal', value: '/'}],
optional: false
},
operator: '||',
right: {
type: 'CallExpression',
callee: toIdOrMemberExpression(['d', 'startsWith']),
arguments: [{type: 'Literal', value: './'}],
optional: false
}
},
operator: '||',
right: {
type: 'CallExpression',
callee: toIdOrMemberExpression(['d', 'startsWith']),
arguments: [{type: 'Literal', value: '../'}],
optional: false
}
},
consequent: {
type: 'ReturnStatement',
argument: {
type: 'MemberExpression',
object: {
type: 'NewExpression',
callee: {type: 'Identifier', name: 'URL'},
arguments: [{type: 'Identifier', name: 'd'}, importMetaUrl]
},
property: {type: 'Identifier', name: 'href'},
computed: false,
optional: false
}
},
alternate: null
},
{
type: 'ReturnStatement',
argument: {type: 'Identifier', name: 'd'}
}
]
}
}
}
/**
* @returns {Array<Statement>}
*/
function createImportMetaUrlVariable() {
return [
{
type: 'VariableDeclaration',
declarations: [
{
type: 'VariableDeclarator',
id: {type: 'Identifier', name: '_importMetaUrl'},
init: toIdOrMemberExpression(['arguments', 0, 'baseUrl'])
}
],
kind: 'const'
},
{
type: 'IfStatement',
test: {
type: 'UnaryExpression',
operator: '!',
prefix: true,
argument: {type: 'Identifier', name: '_importMetaUrl'}
},
consequent: {
type: 'ThrowStatement',
argument: {
type: 'NewExpression',
callee: {type: 'Identifier', name: 'Error'},
arguments: [
{
type: 'Literal',
value:
'Unexpected missing `options.baseUrl` needed to support `export … from`, `import`, or `import.meta.url` when generating `function-body`'
}
]
}
},
alternate: null
}
]
}

View File

@@ -0,0 +1,28 @@
/**
* A plugin to build JSX into function calls.
* `estree-util-build-jsx` does all the work for us!
*
* @param {Readonly<Options> | null | undefined} [options]
* Configuration (optional).
* @returns
* Transform.
*/
export function recmaJsxBuild(options?: Readonly<Options> | null | undefined): (tree: Program, file: VFile) => undefined;
export type Program = import('estree-jsx').Program;
export type BuildJsxOptions = import('estree-util-build-jsx').Options;
export type VFile = import('vfile').VFile;
/**
* Configuration for internal plugin `recma-jsx-build`.
*/
export type ExtraOptions = {
/**
* Whether to keep the import of the automatic runtime or get it from
* `arguments[0]` instead (default: `'program'`).
*/
outputFormat?: 'function-body' | 'program' | null | undefined;
};
/**
* Options.
*/
export type Options = BuildJsxOptions & ExtraOptions;
//# sourceMappingURL=recma-jsx-build.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"recma-jsx-build.d.ts","sourceRoot":"","sources":["recma-jsx-build.js"],"names":[],"mappings":"AAqBA;;;;;;;;GAQG;AACH,wCALW,SAAS,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,UAUlC,OAAO,QAEP,KAAK,KAEH,SAAS,CAmDvB;sBAzFY,OAAO,YAAY,EAAE,OAAO;8BAC5B,OAAO,uBAAuB,EAAE,OAAO;oBACvC,OAAO,OAAO,EAAE,KAAK;;;;;;;;;mBAMpB,eAAe,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS;;;;;sBAI/C,eAAe,GAAG,YAAY"}

91
node_modules/@mdx-js/mdx/lib/plugin/recma-jsx-build.js generated vendored Normal file
View File

@@ -0,0 +1,91 @@
/**
* @typedef {import('estree-jsx').Program} Program
* @typedef {import('estree-util-build-jsx').Options} BuildJsxOptions
* @typedef {import('vfile').VFile} VFile
*/
/**
* @typedef ExtraOptions
* Configuration for internal plugin `recma-jsx-build`.
* @property {'function-body' | 'program' | null | undefined} [outputFormat='program']
* Whether to keep the import of the automatic runtime or get it from
* `arguments[0]` instead (default: `'program'`).
*
* @typedef {BuildJsxOptions & ExtraOptions} Options
* Options.
*/
import {buildJsx} from 'estree-util-build-jsx'
import {specifiersToDeclarations} from '../util/estree-util-specifiers-to-declarations.js'
import {toIdOrMemberExpression} from '../util/estree-util-to-id-or-member-expression.js'
/**
* A plugin to build JSX into function calls.
* `estree-util-build-jsx` does all the work for us!
*
* @param {Readonly<Options> | null | undefined} [options]
* Configuration (optional).
* @returns
* Transform.
*/
export function recmaJsxBuild(options) {
/* c8 ignore next -- always given in `@mdx-js/mdx` */
const {development, outputFormat} = options || {}
/**
* @param {Program} tree
* Tree.
* @param {VFile} file
* File.
* @returns {undefined}
* Nothing.
*/
return function (tree, file) {
buildJsx(tree, {development, filePath: file.history[0]})
// Remove the pragma comment that we injected ourselves as it is no longer
// needed.
if (tree.comments) {
tree.comments = tree.comments.filter(function (d) {
return !d.data?._mdxIsPragmaComment
})
}
// When compiling to a function body, replace the import that was just
// generated, and get `jsx`, `jsxs`, and `Fragment` from `arguments[0]`
// instead.
if (outputFormat === 'function-body') {
let index = 0
// Skip directives: JS currently only has `use strict`, but Acorn allows
// arbitrary ones.
// Practically things like `use client` could be used?
while (index < tree.body.length) {
const child = tree.body[index]
if ('directive' in child && child.directive) {
index++
} else {
break
}
}
const declaration = tree.body[index]
if (
declaration &&
declaration.type === 'ImportDeclaration' &&
typeof declaration.source.value === 'string' &&
/\/jsx-(dev-)?runtime$/.test(declaration.source.value)
) {
tree.body[index] = {
type: 'VariableDeclaration',
kind: 'const',
declarations: specifiersToDeclarations(
declaration.specifiers,
toIdOrMemberExpression(['arguments', 0])
)
}
}
}
}
}

View File

@@ -0,0 +1,68 @@
/**
* A plugin that rewrites JSX in functions to accept components as
* `props.components` (when the function is called `_createMdxContent`), or from
* a provider (if there is one).
* It also makes sure that any undefined components are defined: either from
* received components or as a function that throws an error.
*
* @param {Readonly<ProcessorOptions>} options
* Configuration (optional).
* @returns
* Transform.
*/
export function recmaJsxRewrite(options: Readonly<ProcessorOptions>): (tree: Program, file: VFile) => undefined;
export type Expression = import('estree-jsx').Expression;
export type EstreeFunction = import('estree-jsx').Function;
export type Identifier = import('estree-jsx').Identifier;
export type ImportSpecifier = import('estree-jsx').ImportSpecifier;
export type JSXElement = import('estree-jsx').JSXElement;
export type ModuleDeclaration = import('estree-jsx').ModuleDeclaration;
export type Node = import('estree-jsx').Node;
export type ObjectPattern = import('estree-jsx').ObjectPattern;
export type Program = import('estree-jsx').Program;
export type Property = import('estree-jsx').Property;
export type SpreadElement = import('estree-jsx').SpreadElement;
export type Statement = import('estree-jsx').Statement;
export type VariableDeclarator = import('estree-jsx').VariableDeclarator;
export type PeriscopicScope = import('periscopic').Scope;
export type VFile = import('vfile').VFile;
export type ProcessorOptions = import('../core.js').ProcessorOptions;
/**
* Scope (with a `node`).
*/
export type Scope = PeriscopicScope & {
node: Node;
};
/**
* Entry.
*/
export type StackEntry = {
/**
* Used components.
*/
components: Array<string>;
/**
* Map of JSX identifiers which cannot be used as JS identifiers, to valid JS identifiers.
*/
idToInvalidComponentName: Map<string, string>;
/**
* Function.
*/
node: Readonly<EstreeFunction>;
/**
* Identifiers of used objects (such as `x` in `x.y`).
*/
objects: Array<string>;
/**
* Map of JSX identifiers for components and objects, to where they were first used.
*/
references: Record<string, {
node: Readonly<JSXElement>;
component: boolean;
}>;
/**
* Tag names.
*/
tags: Array<string>;
};
//# sourceMappingURL=recma-jsx-rewrite.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"recma-jsx-rewrite.d.ts","sourceRoot":"","sources":["recma-jsx-rewrite.js"],"names":[],"mappings":"AAsDA;;;;;;;;;;;GAWG;AACH,yCALW,SAAS,gBAAgB,CAAC,UASxB,OAAO,QAEP,KAAK,KAEH,SAAS,CAofvB;yBA7jBY,OAAO,YAAY,EAAE,UAAU;6BAC/B,OAAO,YAAY,EAAE,QAAQ;yBAC7B,OAAO,YAAY,EAAE,UAAU;8BAC/B,OAAO,YAAY,EAAE,eAAe;yBACpC,OAAO,YAAY,EAAE,UAAU;gCAC/B,OAAO,YAAY,EAAE,iBAAiB;mBACtC,OAAO,YAAY,EAAE,IAAI;4BACzB,OAAO,YAAY,EAAE,aAAa;sBAClC,OAAO,YAAY,EAAE,OAAO;uBAC5B,OAAO,YAAY,EAAE,QAAQ;4BAC7B,OAAO,YAAY,EAAE,aAAa;wBAClC,OAAO,YAAY,EAAE,SAAS;iCAC9B,OAAO,YAAY,EAAE,kBAAkB;8BAEvC,OAAO,YAAY,EAAE,KAAK;oBAE1B,OAAO,OAAO,EAAE,KAAK;+BAErB,OAAO,YAAY,EAAE,gBAAgB;;;;oBAIrC,eAAe,GAAG;IAAC,IAAI,EAAE,IAAI,CAAA;CAAC;;;;;;;;gBAK7B,MAAM,MAAM,CAAC;;;;8BAEb,IAAI,MAAM,EAAE,MAAM,CAAC;;;;UAEnB,SAAS,cAAc,CAAC;;;;aAExB,MAAM,MAAM,CAAC;;;;gBAEb,OAAO,MAAM,EAAE;QAAC,IAAI,EAAE,SAAS,UAAU,CAAC,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAC,CAAC;;;;UAEhE,MAAM,MAAM,CAAC"}

View File

@@ -0,0 +1,647 @@
/**
* @typedef {import('estree-jsx').Expression} Expression
* @typedef {import('estree-jsx').Function} EstreeFunction
* @typedef {import('estree-jsx').Identifier} Identifier
* @typedef {import('estree-jsx').ImportSpecifier} ImportSpecifier
* @typedef {import('estree-jsx').JSXElement} JSXElement
* @typedef {import('estree-jsx').ModuleDeclaration} ModuleDeclaration
* @typedef {import('estree-jsx').Node} Node
* @typedef {import('estree-jsx').ObjectPattern} ObjectPattern
* @typedef {import('estree-jsx').Program} Program
* @typedef {import('estree-jsx').Property} Property
* @typedef {import('estree-jsx').SpreadElement} SpreadElement
* @typedef {import('estree-jsx').Statement} Statement
* @typedef {import('estree-jsx').VariableDeclarator} VariableDeclarator
*
* @typedef {import('periscopic').Scope} PeriscopicScope
*
* @typedef {import('vfile').VFile} VFile
*
* @typedef {import('../core.js').ProcessorOptions} ProcessorOptions
*/
/**
* @typedef {PeriscopicScope & {node: Node}} Scope
* Scope (with a `node`).
*
* @typedef StackEntry
* Entry.
* @property {Array<string>} components
* Used components.
* @property {Map<string, string>} idToInvalidComponentName
* Map of JSX identifiers which cannot be used as JS identifiers, to valid JS identifiers.
* @property {Readonly<EstreeFunction>} node
* Function.
* @property {Array<string>} objects
* Identifiers of used objects (such as `x` in `x.y`).
* @property {Record<string, {node: Readonly<JSXElement>, component: boolean}>} references
* Map of JSX identifiers for components and objects, to where they were first used.
* @property {Array<string>} tags
* Tag names.
*/
import {name as isIdentifierName} from 'estree-util-is-identifier-name'
import {walk} from 'estree-walker'
import {analyze} from 'periscopic'
import {stringifyPosition} from 'unist-util-stringify-position'
import {positionFromEstree} from 'unist-util-position-from-estree'
import {specifiersToDeclarations} from '../util/estree-util-specifiers-to-declarations.js'
import {toBinaryAddition} from '../util/estree-util-to-binary-addition.js'
import {
toIdOrMemberExpression,
toJsxIdOrMemberExpression
} from '../util/estree-util-to-id-or-member-expression.js'
/**
* A plugin that rewrites JSX in functions to accept components as
* `props.components` (when the function is called `_createMdxContent`), or from
* a provider (if there is one).
* It also makes sure that any undefined components are defined: either from
* received components or as a function that throws an error.
*
* @param {Readonly<ProcessorOptions>} options
* Configuration (optional).
* @returns
* Transform.
*/
export function recmaJsxRewrite(options) {
const {development, outputFormat, providerImportSource} = options
/**
* @param {Program} tree
* Tree.
* @param {VFile} file
* File.
* @returns {undefined}
* Nothing.
*/
return function (tree, file) {
// Find everything thats defined in the top-level scope.
const scopeInfo = analyze(tree)
/** @type {Array<StackEntry>} */
const functionStack = []
let importProvider = false
let createErrorHelper = false
/** @type {Scope | undefined} */
let currentScope
walk(tree, {
enter(node) {
// Cast because we match `node`.
const newScope = /** @type {Scope | undefined} */ (
scopeInfo.map.get(node)
)
if (
node.type === 'FunctionDeclaration' ||
node.type === 'FunctionExpression' ||
node.type === 'ArrowFunctionExpression'
) {
functionStack.push({
components: [],
idToInvalidComponentName: new Map(),
node,
objects: [],
references: {},
tags: []
})
// MDXContent only ever contains MDXLayout
if (
isNamedFunction(node, 'MDXContent') &&
newScope &&
!inScope(newScope, 'MDXLayout')
) {
functionStack[0].components.push('MDXLayout')
}
}
const functionScope = functionStack[0]
if (
!functionScope ||
(!isNamedFunction(functionScope.node, '_createMdxContent') &&
!providerImportSource)
) {
return
}
if (newScope) {
newScope.node = node
currentScope = newScope
}
if (currentScope && node.type === 'JSXElement') {
let name = node.openingElement.name
// `<x.y>`, `<Foo.Bar>`, `<x.y.z>`.
if (name.type === 'JSXMemberExpression') {
/** @type {Array<string>} */
const ids = []
// Find the left-most identifier.
while (name.type === 'JSXMemberExpression') {
ids.unshift(name.property.name)
name = name.object
}
ids.unshift(name.name)
const fullId = ids.join('.')
const id = name.name
const isInScope = inScope(currentScope, id)
if (!Object.hasOwn(functionScope.references, fullId)) {
// Cast because we match `node`.
const parentScope = /** @type {Scope | undefined} */ (
currentScope.parent
)
if (
!isInScope ||
// If the parent scope is `_createMdxContent`, then this
// references a component we can add a check statement for.
(parentScope &&
parentScope.node.type === 'FunctionDeclaration' &&
isNamedFunction(parentScope.node, '_createMdxContent'))
) {
functionScope.references[fullId] = {component: true, node}
}
}
if (!functionScope.objects.includes(id) && !isInScope) {
functionScope.objects.push(id)
}
}
// `<xml:thing>`.
else if (name.type === 'JSXNamespacedName') {
// Ignore namespaces.
}
// If the name is a valid ES identifier, and it doesnt start with a
// lowercase letter, its a component.
// For example, `$foo`, `_bar`, `Baz` are all component names.
// But `foo` and `b-ar` are tag names.
else if (isIdentifierName(name.name) && !/^[a-z]/.test(name.name)) {
const id = name.name
if (!inScope(currentScope, id)) {
// No need to add an error for an undefined layout — we use an
// `if` later.
if (
id !== 'MDXLayout' &&
!Object.hasOwn(functionScope.references, id)
) {
functionScope.references[id] = {component: true, node}
}
if (!functionScope.components.includes(id)) {
functionScope.components.push(id)
}
}
} else if (node.data && node.data._mdxExplicitJsx) {
// Do not turn explicit JSX into components from `_components`.
// As in, a given `h1` component is used for `# heading` (next case),
// but not for `<h1>heading</h1>`.
} else {
const id = name.name
if (!functionScope.tags.includes(id)) {
functionScope.tags.push(id)
}
/** @type {Array<number | string>} */
let jsxIdExpression = ['_components', id]
if (isIdentifierName(id) === false) {
let invalidComponentName =
functionScope.idToInvalidComponentName.get(id)
if (invalidComponentName === undefined) {
invalidComponentName = `_component${functionScope.idToInvalidComponentName.size}`
functionScope.idToInvalidComponentName.set(
id,
invalidComponentName
)
}
jsxIdExpression = [invalidComponentName]
}
node.openingElement.name =
toJsxIdOrMemberExpression(jsxIdExpression)
if (node.closingElement) {
node.closingElement.name =
toJsxIdOrMemberExpression(jsxIdExpression)
}
}
}
},
leave(node) {
/** @type {Array<Property | SpreadElement>} */
const defaults = []
/** @type {Array<string>} */
const actual = []
/** @type {Array<Expression>} */
const parameters = []
/** @type {Array<VariableDeclarator>} */
const declarations = []
if (currentScope && currentScope.node === node) {
// Cast to patch our `node`.
currentScope = /** @type {Scope} */ (currentScope.parent)
}
if (
node.type === 'FunctionDeclaration' ||
node.type === 'FunctionExpression' ||
node.type === 'ArrowFunctionExpression'
) {
const scopeNode = node
const scope = functionStack[functionStack.length - 1]
/** @type {string} */
let name
for (name of scope.tags.sort()) {
defaults.push({
type: 'Property',
kind: 'init',
key: isIdentifierName(name)
? {type: 'Identifier', name}
: {type: 'Literal', value: name},
value: {type: 'Literal', value: name},
method: false,
shorthand: false,
computed: false
})
}
actual.push(...scope.components)
for (name of scope.objects) {
// In some cases, a component is used directly (`<X>`) but its also
// used as an object (`<X.Y>`).
if (!actual.includes(name)) {
actual.push(name)
}
}
actual.sort()
/** @type {Array<Statement>} */
const statements = []
if (
defaults.length > 0 ||
actual.length > 0 ||
scope.idToInvalidComponentName.size > 0
) {
if (providerImportSource) {
importProvider = true
parameters.push({
type: 'CallExpression',
callee: {type: 'Identifier', name: '_provideComponents'},
arguments: [],
optional: false
})
}
// Accept `components` as a prop if this is the `MDXContent` or
// `_createMdxContent` function.
if (
isNamedFunction(scope.node, 'MDXContent') ||
isNamedFunction(scope.node, '_createMdxContent')
) {
parameters.push(toIdOrMemberExpression(['props', 'components']))
}
if (defaults.length > 0 || parameters.length > 1) {
for (const parameter of parameters) {
defaults.push({type: 'SpreadElement', argument: parameter})
}
}
// If were getting components from several sources, merge them.
/** @type {Expression} */
let componentsInit =
defaults.length > 0
? {type: 'ObjectExpression', properties: defaults}
: // If were only getting components from `props.components`,
// make sure its defined.
{
type: 'LogicalExpression',
operator: '||',
left: parameters[0],
right: {type: 'ObjectExpression', properties: []}
}
/** @type {ObjectPattern | undefined} */
let componentsPattern
// Add components to scope.
// For `['MyComponent', 'MDXLayout']` this generates:
// ```tsx
// const {MyComponent, wrapper: MDXLayout} = _components
// ```
// Note that MDXLayout is special as its taken from
// `_components.wrapper`.
if (actual.length > 0) {
componentsPattern = {
type: 'ObjectPattern',
properties: actual.map(function (name) {
return {
type: 'Property',
kind: 'init',
key: {
type: 'Identifier',
name: name === 'MDXLayout' ? 'wrapper' : name
},
value: {type: 'Identifier', name},
method: false,
shorthand: name !== 'MDXLayout',
computed: false
}
})
}
}
if (scope.tags.length > 0) {
declarations.push({
type: 'VariableDeclarator',
id: {type: 'Identifier', name: '_components'},
init: componentsInit
})
componentsInit = {type: 'Identifier', name: '_components'}
}
if (isNamedFunction(scope.node, '_createMdxContent')) {
for (const [id, componentName] of [
...scope.idToInvalidComponentName
].sort(function ([a], [b]) {
return a.localeCompare(b)
})) {
// For JSX IDs that cant be represented as JavaScript IDs (as in,
// those with dashes, such as `custom-element`), generate a
// separate variable that is a valid JS ID (such as `_component0`),
// and takes it from components:
// `const _component0 = _components['custom-element']`
declarations.push({
type: 'VariableDeclarator',
id: {
type: 'Identifier',
name: componentName
},
init: {
type: 'MemberExpression',
object: {type: 'Identifier', name: '_components'},
property: {type: 'Literal', value: id},
computed: true,
optional: false
}
})
}
}
if (componentsPattern) {
declarations.push({
type: 'VariableDeclarator',
id: componentsPattern,
init: componentsInit
})
}
if (declarations.length > 0) {
statements.push({
type: 'VariableDeclaration',
kind: 'const',
declarations
})
}
}
/** @type {string} */
let key
// Add partials (so for `x.y.z` itd generate `x` and `x.y` too).
for (key in scope.references) {
if (Object.hasOwn(scope.references, key)) {
const parts = key.split('.')
let index = 0
while (++index < parts.length) {
const partial = parts.slice(0, index).join('.')
if (!Object.hasOwn(scope.references, partial)) {
scope.references[partial] = {
component: false,
node: scope.references[key].node
}
}
}
}
}
const references = Object.keys(scope.references).sort()
let index = -1
while (++index < references.length) {
const id = references[index]
const info = scope.references[id]
const place = stringifyPosition(positionFromEstree(info.node))
/** @type {Array<Expression>} */
const parameters = [
{type: 'Literal', value: id},
{type: 'Literal', value: info.component}
]
createErrorHelper = true
if (development && place) {
parameters.push({type: 'Literal', value: place})
}
statements.push({
type: 'IfStatement',
test: {
type: 'UnaryExpression',
operator: '!',
prefix: true,
argument: toIdOrMemberExpression(id.split('.'))
},
consequent: {
type: 'ExpressionStatement',
expression: {
type: 'CallExpression',
callee: {type: 'Identifier', name: '_missingMdxReference'},
arguments: parameters,
optional: false
}
},
alternate: undefined
})
}
if (statements.length > 0) {
// Arrow functions with an implied return:
if (scopeNode.body.type !== 'BlockStatement') {
scopeNode.body = {
type: 'BlockStatement',
body: [{type: 'ReturnStatement', argument: scopeNode.body}]
}
}
scopeNode.body.body.unshift(...statements)
}
functionStack.pop()
}
}
})
// If a provider is used (and can be used), import it.
if (importProvider && providerImportSource) {
tree.body.unshift(
createImportProvider(providerImportSource, outputFormat)
)
}
// If potentially missing components are used.
if (createErrorHelper) {
/** @type {Array<Expression>} */
const message = [
{type: 'Literal', value: 'Expected '},
{
type: 'ConditionalExpression',
test: {type: 'Identifier', name: 'component'},
consequent: {type: 'Literal', value: 'component'},
alternate: {type: 'Literal', value: 'object'}
},
{type: 'Literal', value: ' `'},
{type: 'Identifier', name: 'id'},
{
type: 'Literal',
value:
'` to be defined: you likely forgot to import, pass, or provide it.'
}
]
/** @type {Array<Identifier>} */
const parameters = [
{type: 'Identifier', name: 'id'},
{type: 'Identifier', name: 'component'}
]
if (development) {
message.push({
type: 'ConditionalExpression',
test: {type: 'Identifier', name: 'place'},
consequent: toBinaryAddition([
{type: 'Literal', value: '\nIts referenced in your code at `'},
{type: 'Identifier', name: 'place'},
{
type: 'Literal',
value: (file.path ? '` in `' + file.path : '') + '`'
}
]),
alternate: {type: 'Literal', value: ''}
})
parameters.push({type: 'Identifier', name: 'place'})
}
tree.body.push({
type: 'FunctionDeclaration',
id: {type: 'Identifier', name: '_missingMdxReference'},
generator: false,
async: false,
params: parameters,
body: {
type: 'BlockStatement',
body: [
{
type: 'ThrowStatement',
argument: {
type: 'NewExpression',
callee: {type: 'Identifier', name: 'Error'},
arguments: [toBinaryAddition(message)]
}
}
]
}
})
}
if (outputFormat === 'function-body') {
tree.body.unshift({
type: 'ExpressionStatement',
expression: {type: 'Literal', value: 'use strict'},
directive: 'use strict'
})
}
}
}
/**
* @param {string} providerImportSource
* Provider source.
* @param {'function-body' | 'program' | null | undefined} outputFormat
* Format.
* @returns {ModuleDeclaration | Statement}
* Node.
*/
function createImportProvider(providerImportSource, outputFormat) {
/** @type {Array<ImportSpecifier>} */
const specifiers = [
{
type: 'ImportSpecifier',
imported: {type: 'Identifier', name: 'useMDXComponents'},
local: {type: 'Identifier', name: '_provideComponents'}
}
]
return outputFormat === 'function-body'
? {
type: 'VariableDeclaration',
kind: 'const',
declarations: specifiersToDeclarations(
specifiers,
toIdOrMemberExpression(['arguments', 0])
)
}
: {
type: 'ImportDeclaration',
specifiers,
source: {type: 'Literal', value: providerImportSource}
}
}
/**
* @param {Readonly<EstreeFunction>} node
* Node.
* @param {string} name
* Name.
* @returns {boolean}
* Whether `node` is a named function with `name`.
*/
function isNamedFunction(node, name) {
return Boolean(node && 'id' in node && node.id && node.id.name === name)
}
/**
* @param {Readonly<Scope>} scope
* Scope.
* @param {string} id
* Identifier.
* @returns {boolean}
* Whether `id` is in `scope`.
*/
function inScope(scope, id) {
/** @type {Scope | undefined} */
let currentScope = scope
while (currentScope) {
if (currentScope.declarations.has(id)) {
return true
}
// Cast to patch our `node`.
currentScope = /** @type {Scope | undefined} */ (
currentScope.parent || undefined
)
}
return false
}

View File

@@ -0,0 +1,6 @@
export function recmaStringify(this: import("unified").Processor<undefined, undefined, undefined, undefined, undefined>, parameters_0: Readonly<import("../core.js").ProcessorOptions>): void | undefined;
export type Program = import('estree-jsx').Program;
export type Processor = import('unified').Processor<undefined, undefined, undefined, Program, string>;
export type VFile = import('vfile').VFile;
export type ProcessorOptions = import('../core.js').ProcessorOptions;
//# sourceMappingURL=recma-stringify.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"recma-stringify.d.ts","sourceRoot":"","sources":["recma-stringify.js"],"names":[],"mappings":"AA6CwinC,0MAA6U;sBA5Cx2nC,OAAO,YAAY,EAAE,OAAO;wBAC5B,OAAO,SAAS,EAAE,SAAS,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,CAAC;oBAC7E,OAAO,OAAO,EAAE,KAAK;+BAErB,OAAO,YAAY,EAAE,gBAAgB"}

45
node_modules/@mdx-js/mdx/lib/plugin/recma-stringify.js generated vendored Normal file
View File

@@ -0,0 +1,45 @@
/**
* @typedef {import('estree-jsx').Program} Program
* @typedef {import('unified').Processor<undefined, undefined, undefined, Program, string>} Processor
* @typedef {import('vfile').VFile} VFile
*
* @typedef {import('../core.js').ProcessorOptions} ProcessorOptions
*/
import {jsx, toJs} from 'estree-util-to-js'
/**
* Serialize an esast (estree) program to JavaScript.
*
* @type {import('unified').Plugin<[Readonly<ProcessorOptions>], Program, string>}
*/
export function recmaStringify(options) {
// @ts-expect-error: TS is wrong about `this`.
// eslint-disable-next-line unicorn/no-this-assignment
const self = /** @type {Processor} */ (this)
const {SourceMapGenerator} = options
self.compiler = compiler
/**
* @param {Program} tree
* Tree.
* @param {VFile} file
* File.
* @returns {string}
* JavaScript.
*/
function compiler(tree, file) {
const result = SourceMapGenerator
? toJs(tree, {
SourceMapGenerator,
filePath: file.path || 'unknown.mdx',
handlers: jsx
})
: toJs(tree, {handlers: jsx})
file.map = result.map
return result.value
}
}

14
node_modules/@mdx-js/mdx/lib/plugin/rehype-recma.d.ts generated vendored Normal file
View File

@@ -0,0 +1,14 @@
/**
* A plugin to transform an HTML (hast) tree to a JS (estree).
* `hast-util-to-estree` does all the work for us!
*
* @param {Readonly<ProcessorOptions>} options
* Configuration (optional).
* @returns
* Transform.
*/
export function rehypeRecma(options: Readonly<ProcessorOptions>): (tree: Root) => Program;
export type Program = import('estree-jsx').Program;
export type Root = import('hast').Root;
export type ProcessorOptions = import('../core.js').ProcessorOptions;
//# sourceMappingURL=rehype-recma.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"rehype-recma.d.ts","sourceRoot":"","sources":["rehype-recma.js"],"names":[],"mappings":"AAUA;;;;;;;;GAQG;AACH,qCALW,SAAS,gBAAgB,CAAC,UAOxB,IAAI,KAEF,OAAO,CAMrB;sBA5BY,OAAO,YAAY,EAAE,OAAO;mBAE5B,OAAO,MAAM,EAAE,IAAI;+BAEnB,OAAO,YAAY,EAAE,gBAAgB"}

30
node_modules/@mdx-js/mdx/lib/plugin/rehype-recma.js generated vendored Normal file
View File

@@ -0,0 +1,30 @@
/**
* @typedef {import('estree-jsx').Program} Program
*
* @typedef {import('hast').Root} Root
*
* @typedef {import('../core.js').ProcessorOptions} ProcessorOptions
*/
import {toEstree} from 'hast-util-to-estree'
/**
* A plugin to transform an HTML (hast) tree to a JS (estree).
* `hast-util-to-estree` does all the work for us!
*
* @param {Readonly<ProcessorOptions>} options
* Configuration (optional).
* @returns
* Transform.
*/
export function rehypeRecma(options) {
/**
* @param {Root} tree
* Tree (hast).
* @returns {Program}
* Program (esast).
*/
return function (tree) {
return toEstree(tree, options)
}
}

View File

@@ -0,0 +1,12 @@
/**
* A tiny plugin that removes raw HTML.
*
* This is needed if the format is `md` and `rehype-raw` was not used to parse
* dangerous HTML into nodes.
*
* @returns
* Transform.
*/
export function rehypeRemoveRaw(): (tree: Root) => undefined;
export type Root = import('hast').Root;
//# sourceMappingURL=rehype-remove-raw.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"rehype-remove-raw.d.ts","sourceRoot":"","sources":["rehype-remove-raw.js"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AACH,0CAEa,IAAI,KAEF,SAAS,CAWvB;mBA7BY,OAAO,MAAM,EAAE,IAAI"}

View File

@@ -0,0 +1,31 @@
/**
* @typedef {import('hast').Root} Root
*/
import {visit} from 'unist-util-visit'
/**
* A tiny plugin that removes raw HTML.
*
* This is needed if the format is `md` and `rehype-raw` was not used to parse
* dangerous HTML into nodes.
*
* @returns
* Transform.
*/
export function rehypeRemoveRaw() {
/**
* @param {Root} tree
* Tree.
* @returns {undefined}
* Nothing.
*/
return function (tree) {
visit(tree, 'raw', function (_, index, parent) {
if (parent && typeof index === 'number') {
parent.children.splice(index, 1)
return index
}
})
}
}

View File

@@ -0,0 +1,14 @@
/**
* A tiny plugin that unravels `<p><h1>x</h1></p>` but also
* `<p><Component /></p>` (so it has no knowledge of “HTML”).
*
* It also marks JSX as being explicitly JSX, so when a user passes a `h1`
* component, it is used for `# heading` but not for `<h1>heading</h1>`.
*
* @returns
* Transform.
*/
export function remarkMarkAndUnravel(): (tree: Root) => undefined;
export type Root = import('mdast').Root;
export type RootContent = import('mdast').RootContent;
//# sourceMappingURL=remark-mark-and-unravel.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"remark-mark-and-unravel.d.ts","sourceRoot":"","sources":["remark-mark-and-unravel.js"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AACH,+CAEa,IAAI,KAEF,SAAS,CA0EvB;mBA/FY,OAAO,OAAO,EAAE,IAAI;0BACpB,OAAO,OAAO,EAAE,WAAW"}

View File

@@ -0,0 +1,97 @@
/**
* @typedef {import('mdast').Root} Root
* @typedef {import('mdast').RootContent} RootContent
*/
import {collapseWhiteSpace} from 'collapse-white-space'
import {visit} from 'unist-util-visit'
/**
* A tiny plugin that unravels `<p><h1>x</h1></p>` but also
* `<p><Component /></p>` (so it has no knowledge of “HTML”).
*
* It also marks JSX as being explicitly JSX, so when a user passes a `h1`
* component, it is used for `# heading` but not for `<h1>heading</h1>`.
*
* @returns
* Transform.
*/
export function remarkMarkAndUnravel() {
/**
* @param {Root} tree
* Tree.
* @returns {undefined}
* Nothing.
*/
return function (tree) {
visit(tree, function (node, index, parent) {
let offset = -1
let all = true
let oneOrMore = false
if (parent && typeof index === 'number' && node.type === 'paragraph') {
const children = node.children
while (++offset < children.length) {
const child = children[offset]
if (
child.type === 'mdxJsxTextElement' ||
child.type === 'mdxTextExpression'
) {
oneOrMore = true
} else if (
child.type === 'text' &&
collapseWhiteSpace(child.value, {style: 'html', trim: true}) === ''
) {
// Empty.
} else {
all = false
break
}
}
if (all && oneOrMore) {
offset = -1
/** @type {Array<RootContent>} */
const newChildren = []
while (++offset < children.length) {
const child = children[offset]
if (child.type === 'mdxJsxTextElement') {
// @ts-expect-error: mutate because it is faster; content model is fine.
child.type = 'mdxJsxFlowElement'
}
if (child.type === 'mdxTextExpression') {
// @ts-expect-error: mutate because it is faster; content model is fine.
child.type = 'mdxFlowExpression'
}
if (
child.type === 'text' &&
/^[\t\r\n ]+$/.test(String(child.value))
) {
// Empty.
} else {
newChildren.push(child)
}
}
parent.children.splice(index, 1, ...newChildren)
return index
}
}
if (
node.type === 'mdxJsxFlowElement' ||
node.type === 'mdxJsxTextElement'
) {
const data = node.data || (node.data = {})
data._mdxExplicitJsx = true
}
})
}
}

37
node_modules/@mdx-js/mdx/lib/run.d.ts generated vendored Normal file
View File

@@ -0,0 +1,37 @@
/**
* Run code compiled with `outputFormat: 'function-body'`.
*
* > ☢️ **Danger**: this `eval`s JavaScript.
*
* @param {{toString(): string}} code
* JavaScript function body to run.
* @param {RunOptions} options
* Configuration (**required**).
* @return {Promise<MDXModule>}
* Promise to a module;
* the result is an object with a `default` field set to the component;
* anything else that was exported is available too.
*/
export function run(code: {
toString(): string;
}, options: RunOptions): Promise<MDXModule>;
/**
* Run code, synchronously.
*
* When possible please use the async `run`.
*
* > ☢️ **Danger**: this `eval`s JavaScript.
*
* @param {{toString(): string}} code
* JavaScript function body to run.
* @param {RunOptions} options
* Configuration (**required**).
* @return {MDXModule}
* Module.
*/
export function runSync(code: {
toString(): string;
}, options: RunOptions): MDXModule;
export type MDXModule = import('mdx/types.js').MDXModule;
export type RunOptions = import('./util/resolve-evaluate-options.js').RunOptions;
//# sourceMappingURL=run.d.ts.map

1
node_modules/@mdx-js/mdx/lib/run.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["run.js"],"names":[],"mappings":"AASA;;;;;;;;;;;;;GAaG;AACH,0BATW;IAAC,YAAY,MAAM,CAAA;CAAC,WAEpB,UAAU,GAET,QAAQ,SAAS,CAAC,CAO7B;AAED;;;;;;;;;;;;;GAaG;AACH,8BAPW;IAAC,YAAY,MAAM,CAAA;CAAC,WAEpB,UAAU,GAET,SAAS,CAMpB;wBA3CY,OAAO,cAAc,EAAE,SAAS;yBAEhC,OAAO,oCAAoC,EAAE,UAAU"}

45
node_modules/@mdx-js/mdx/lib/run.js generated vendored Normal file
View File

@@ -0,0 +1,45 @@
/**
* @typedef {import('mdx/types.js').MDXModule} MDXModule
*
* @typedef {import('./util/resolve-evaluate-options.js').RunOptions} RunOptions
*/
/** @type {new (code: string, ...args: Array<unknown>) => Function} **/
const AsyncFunction = Object.getPrototypeOf(run).constructor
/**
* Run code compiled with `outputFormat: 'function-body'`.
*
* > ☢️ **Danger**: this `eval`s JavaScript.
*
* @param {{toString(): string}} code
* JavaScript function body to run.
* @param {RunOptions} options
* Configuration (**required**).
* @return {Promise<MDXModule>}
* Promise to a module;
* the result is an object with a `default` field set to the component;
* anything else that was exported is available too.
*/
export async function run(code, options) {
return new AsyncFunction(String(code))(options)
}
/**
* Run code, synchronously.
*
* When possible please use the async `run`.
*
* > ☢️ **Danger**: this `eval`s JavaScript.
*
* @param {{toString(): string}} code
* JavaScript function body to run.
* @param {RunOptions} options
* Configuration (**required**).
* @return {MDXModule}
* Module.
*/
export function runSync(code, options) {
// eslint-disable-next-line no-new-func
return new Function(String(code))(options)
}

65
node_modules/@mdx-js/mdx/lib/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,65 @@
import type {Data as UnistData} from 'unist'
interface EsastData extends UnistData {
/**
* Whether a node was authored as explicit JSX (`<h1>`) or as implicitly
* turned into JSX (`# hi`).
*
* Registered by `@mdx-js/mdx/lib/types.d.ts`.
*/
_mdxExplicitJsx?: boolean | null | undefined
}
interface EsastCommentData extends EsastData {
/**
* Whether a node (only used on comments) was generated by us to include the
* JSX pragmas, so that when we compile JSX away, we can remove it.
*
* Registered by `@mdx-js/mdx/lib/types.d.ts`.
*/
_mdxIsPragmaComment?: boolean | null | undefined
}
// Register data on `estree`.
declare module 'estree' {
interface BaseNode {
/**
* Extra unist data passed through from mdast through hast to esast.
*
* Registered by `@mdx-js/mdx/lib/types.d.ts`.
*/
data?: EsastData | undefined
}
interface Comment {
/**
* Extra unist data passed added by `recma-document`.
*
* Registered by `@mdx-js/mdx/lib/types.d.ts`.
*/
data?: EsastCommentData | undefined
}
}
// Register data on `mdast`.
declare module 'mdast-util-mdx-jsx' {
interface MdxJsxFlowElementData {
/**
* Whether a node was authored as explicit JSX (`<h1>`) or as implicitly
* turned into JSX (`# hi`).
*
* Registered by `@mdx-js/mdx/lib/types.d.ts`.
*/
_mdxExplicitJsx?: boolean | null | undefined
}
interface MdxJsxTextElementData {
/**
* Whether a node was authored as explicit JSX (`<h1>`) or as implicitly
* turned into JSX (`# hi`).
*
* Registered by `@mdx-js/mdx/lib/types.d.ts`.
*/
_mdxExplicitJsx?: boolean | null | undefined
}
}

View File

@@ -0,0 +1,33 @@
/**
* Create smart processors to handle different formats.
*
* @param {Readonly<CompileOptions> | null | undefined} [compileOptions]
* Configuration (optional).
* @return {FormatAwareProcessors}
* Smart processor.
*/
export function createFormatAwareProcessors(compileOptions?: Readonly<CompileOptions> | null | undefined): FormatAwareProcessors;
export type Program = import('estree-jsx').Program;
export type Root = import('mdast').Root;
export type Processor = import('unified').Processor<Root, Program, Program, Program, string>;
export type Compatible = import('vfile').Compatible;
export type VFile = import('vfile').VFile;
export type CompileOptions = import('../compile.js').CompileOptions;
/**
* Result.
*/
export type FormatAwareProcessors = {
/**
* Extensions to use.
*/
extnames: ReadonlyArray<string>;
/**
* Smart processor, async.
*/
process: Process;
};
/**
* Smart processor.
*/
export type Process = (vfileCompatible: Compatible) => Promise<VFile>;
//# sourceMappingURL=create-format-aware-processors.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"create-format-aware-processors.d.ts","sourceRoot":"","sources":["create-format-aware-processors.js"],"names":[],"mappings":"AA6BA;;;;;;;GAOG;AACH,6DALW,SAAS,cAAc,CAAC,GAAG,IAAI,GAAG,SAAS,GAE1C,qBAAqB,CAsDhC;sBAvFY,OAAO,YAAY,EAAE,OAAO;mBAC5B,OAAO,OAAO,EAAE,IAAI;wBACpB,OAAO,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC;yBACpE,OAAO,OAAO,EAAE,UAAU;oBAC1B,OAAO,OAAO,EAAE,KAAK;6BACrB,OAAO,eAAe,EAAE,cAAc;;;;;;;;cAMrC,cAAc,MAAM,CAAC;;;;aAErB,OAAO;;;;;wCAKV,UAAU,KAET,QAAQ,KAAK,CAAC"}

View File

@@ -0,0 +1,89 @@
/**
* @typedef {import('estree-jsx').Program} Program
* @typedef {import('mdast').Root} Root
* @typedef {import('unified').Processor<Root, Program, Program, Program, string>} Processor
* @typedef {import('vfile').Compatible} Compatible
* @typedef {import('vfile').VFile} VFile
* @typedef {import('../compile.js').CompileOptions} CompileOptions
*/
/**
* @typedef FormatAwareProcessors
* Result.
* @property {ReadonlyArray<string>} extnames
* Extensions to use.
* @property {Process} process
* Smart processor, async.
*
* @callback Process
* Smart processor.
* @param {Compatible} vfileCompatible
* MDX or markdown document.
* @return {Promise<VFile>}
* File.
*/
import {createProcessor} from '../core.js'
import {md, mdx} from './extnames.js'
import {resolveFileAndOptions} from './resolve-file-and-options.js'
/**
* Create smart processors to handle different formats.
*
* @param {Readonly<CompileOptions> | null | undefined} [compileOptions]
* Configuration (optional).
* @return {FormatAwareProcessors}
* Smart processor.
*/
export function createFormatAwareProcessors(compileOptions) {
const compileOptions_ = compileOptions || {}
const mdExtensions = compileOptions_.mdExtensions || md
const mdxExtensions = compileOptions_.mdxExtensions || mdx
/** @type {Processor} */
let cachedMarkdown
/** @type {Processor} */
let cachedMdx
return {
extnames:
compileOptions_.format === 'md'
? mdExtensions
: compileOptions_.format === 'mdx'
? mdxExtensions
: [...mdExtensions, ...mdxExtensions],
process
}
/**
* Smart processor.
*
* @type {Process}
*/
function process(vfileCompatible) {
const {file, processor} = split(vfileCompatible)
return processor.process(file)
}
/**
* Make a full vfile from whats given, and figure out which processor
* should be used for it.
* This caches processors (one for markdown and one for MDX) so that they do
* not have to be reconstructed for each file.
*
* @param {Compatible} vfileCompatible
* MDX or markdown document.
* @return {{file: VFile, processor: Processor}}
* File and corresponding processor.
*/
function split(vfileCompatible) {
const {file, options} = resolveFileAndOptions(
vfileCompatible,
compileOptions_
)
const processor =
options.format === 'md'
? cachedMarkdown || (cachedMarkdown = createProcessor(options))
: cachedMdx || (cachedMdx = createProcessor(options))
return {file, processor}
}
}

View File

@@ -0,0 +1,11 @@
/**
* @param {Readonly<Node>} from
* Node to take from.
* @param {Node} to
* Node to add to.
* @returns {undefined}
* Nothing.
*/
export function create(from: Readonly<Node>, to: Node): undefined;
export type Node = import('estree-jsx').Node;
//# sourceMappingURL=estree-util-create.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estree-util-create.d.ts","sourceRoot":"","sources":["estree-util-create.js"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,6BAPW,SAAS,IAAI,CAAC,MAEd,IAAI,GAEF,SAAS,CAiBrB;mBA5BY,OAAO,YAAY,EAAE,IAAI"}

View File

@@ -0,0 +1,30 @@
/**
* @typedef {import('estree-jsx').Node} Node
*/
// Fix to show references to above types in VS Code.
''
/**
* @param {Readonly<Node>} from
* Node to take from.
* @param {Node} to
* Node to add to.
* @returns {undefined}
* Nothing.
*/
export function create(from, to) {
/** @type {Array<keyof Node>} */
// @ts-expect-error: `start`, `end`, `comments` are custom Acorn fields.
const fields = ['start', 'end', 'loc', 'range', 'comments']
let index = -1
while (++index < fields.length) {
const field = fields[index]
if (field in from) {
// @ts-expect-error: assume theyre settable.
to[field] = from[field]
}
}
}

View File

@@ -0,0 +1,18 @@
/**
* Turn a declaration into an expression.
*
* Doesnt work for variable declarations, but thats fine for our use case
* because currently were using this utility for export default declarations,
* which cant contain variable declarations.
*
* @param {Readonly<Declaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration>} declaration
* Declaration.
* @returns {Expression}
* Expression.
*/
export function declarationToExpression(declaration: Readonly<Declaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration>): Expression;
export type Declaration = import('estree-jsx').Declaration;
export type Expression = import('estree-jsx').Expression;
export type MaybeNamedClassDeclaration = import('estree-jsx').MaybeNamedClassDeclaration;
export type MaybeNamedFunctionDeclaration = import('estree-jsx').MaybeNamedFunctionDeclaration;
//# sourceMappingURL=estree-util-declaration-to-expression.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estree-util-declaration-to-expression.d.ts","sourceRoot":"","sources":["estree-util-declaration-to-expression.js"],"names":[],"mappings":"AASA;;;;;;;;;;;GAWG;AACH,qDALW,SAAS,WAAW,GAAG,0BAA0B,GAAG,6BAA6B,CAAC,GAEhF,UAAU,CAYtB;0BA7BY,OAAO,YAAY,EAAE,WAAW;yBAChC,OAAO,YAAY,EAAE,UAAU;yCAC/B,OAAO,YAAY,EAAE,0BAA0B;4CAC/C,OAAO,YAAY,EAAE,6BAA6B"}

View File

@@ -0,0 +1,31 @@
/**
* @typedef {import('estree-jsx').Declaration} Declaration
* @typedef {import('estree-jsx').Expression} Expression
* @typedef {import('estree-jsx').MaybeNamedClassDeclaration} MaybeNamedClassDeclaration
* @typedef {import('estree-jsx').MaybeNamedFunctionDeclaration} MaybeNamedFunctionDeclaration
*/
import {ok as assert} from 'devlop'
/**
* Turn a declaration into an expression.
*
* Doesnt work for variable declarations, but thats fine for our use case
* because currently were using this utility for export default declarations,
* which cant contain variable declarations.
*
* @param {Readonly<Declaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration>} declaration
* Declaration.
* @returns {Expression}
* Expression.
*/
export function declarationToExpression(declaration) {
if (declaration.type === 'FunctionDeclaration') {
return {...declaration, type: 'FunctionExpression'}
}
// This is currently an internal utility so the next shouldnt happen or a
// maintainer is making a mistake.
assert(declaration.type === 'ClassDeclaration', 'unexpected node type')
return {...declaration, type: 'ClassExpression'}
}

View File

@@ -0,0 +1,14 @@
/**
* Check if `node` is a declaration.
*
* @param {Readonly<MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration | Node>} node
* Node to check.
* @returns {node is Declaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration}
* Whether `node` is a declaration.
*/
export function isDeclaration(node: Readonly<MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration | Node>): node is import("estree").MaybeNamedClassDeclaration | import("estree").MaybeNamedFunctionDeclaration | import("estree").Declaration;
export type Declaration = import('estree-jsx').Declaration;
export type MaybeNamedClassDeclaration = import('estree-jsx').MaybeNamedClassDeclaration;
export type MaybeNamedFunctionDeclaration = import('estree-jsx').MaybeNamedFunctionDeclaration;
export type Node = import('estree-jsx').Node;
//# sourceMappingURL=estree-util-is-declaration.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estree-util-is-declaration.d.ts","sourceRoot":"","sources":["estree-util-is-declaration.js"],"names":[],"mappings":"AAUA;;;;;;;GAOG;AACH,oCALW,SAAS,0BAA0B,GAAG,6BAA6B,GAAG,IAAI,CAAC,uIAWrF;0BAvBY,OAAO,YAAY,EAAE,WAAW;yCAChC,OAAO,YAAY,EAAE,0BAA0B;4CAC/C,OAAO,YAAY,EAAE,6BAA6B;mBAClD,OAAO,YAAY,EAAE,IAAI"}

View File

@@ -0,0 +1,25 @@
/**
* @typedef {import('estree-jsx').Declaration} Declaration
* @typedef {import('estree-jsx').MaybeNamedClassDeclaration} MaybeNamedClassDeclaration
* @typedef {import('estree-jsx').MaybeNamedFunctionDeclaration} MaybeNamedFunctionDeclaration
* @typedef {import('estree-jsx').Node} Node
*/
// Fix to show references to above types in VS Code.
''
/**
* Check if `node` is a declaration.
*
* @param {Readonly<MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration | Node>} node
* Node to check.
* @returns {node is Declaration | MaybeNamedClassDeclaration | MaybeNamedFunctionDeclaration}
* Whether `node` is a declaration.
*/
export function isDeclaration(node) {
return Boolean(
node.type === 'FunctionDeclaration' ||
node.type === 'ClassDeclaration' ||
node.type === 'VariableDeclaration'
)
}

View File

@@ -0,0 +1,18 @@
/**
* @param {ReadonlyArray<Readonly<ExportSpecifier> | Readonly<ImportDefaultSpecifier> | Readonly<ImportNamespaceSpecifier> | Readonly<ImportSpecifier>>} specifiers
* Specifiers.
* @param {Readonly<Expression>} init
* Initializer.
* @returns {Array<VariableDeclarator>}
* Declarations.
*/
export function specifiersToDeclarations(specifiers: ReadonlyArray<Readonly<ExportSpecifier> | Readonly<ImportDefaultSpecifier> | Readonly<ImportNamespaceSpecifier> | Readonly<ImportSpecifier>>, init: Readonly<Expression>): Array<VariableDeclarator>;
export type AssignmentProperty = import('estree-jsx').AssignmentProperty;
export type ExportSpecifier = import('estree-jsx').ExportSpecifier;
export type Expression = import('estree-jsx').Expression;
export type Identifier = import('estree-jsx').Identifier;
export type ImportDefaultSpecifier = import('estree-jsx').ImportDefaultSpecifier;
export type ImportNamespaceSpecifier = import('estree-jsx').ImportNamespaceSpecifier;
export type ImportSpecifier = import('estree-jsx').ImportSpecifier;
export type VariableDeclarator = import('estree-jsx').VariableDeclarator;
//# sourceMappingURL=estree-util-specifiers-to-declarations.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estree-util-specifiers-to-declarations.d.ts","sourceRoot":"","sources":["estree-util-specifiers-to-declarations.js"],"names":[],"mappings":"AAaA;;;;;;;GAOG;AACH,qDAPW,cAAc,SAAS,eAAe,CAAC,GAAG,SAAS,sBAAsB,CAAC,GAAG,SAAS,wBAAwB,CAAC,GAAG,SAAS,eAAe,CAAC,CAAC,QAE5I,SAAS,UAAU,CAAC,GAElB,MAAM,kBAAkB,CAAC,CA0ErC;iCA3FY,OAAO,YAAY,EAAE,kBAAkB;8BACvC,OAAO,YAAY,EAAE,eAAe;yBACpC,OAAO,YAAY,EAAE,UAAU;yBAC/B,OAAO,YAAY,EAAE,UAAU;qCAC/B,OAAO,YAAY,EAAE,sBAAsB;uCAC3C,OAAO,YAAY,EAAE,wBAAwB;8BAC7C,OAAO,YAAY,EAAE,eAAe;iCACpC,OAAO,YAAY,EAAE,kBAAkB"}

View File

@@ -0,0 +1,93 @@
/**
* @typedef {import('estree-jsx').AssignmentProperty} AssignmentProperty
* @typedef {import('estree-jsx').ExportSpecifier} ExportSpecifier
* @typedef {import('estree-jsx').Expression} Expression
* @typedef {import('estree-jsx').Identifier} Identifier
* @typedef {import('estree-jsx').ImportDefaultSpecifier} ImportDefaultSpecifier
* @typedef {import('estree-jsx').ImportNamespaceSpecifier} ImportNamespaceSpecifier
* @typedef {import('estree-jsx').ImportSpecifier} ImportSpecifier
* @typedef {import('estree-jsx').VariableDeclarator} VariableDeclarator
*/
import {create} from './estree-util-create.js'
/**
* @param {ReadonlyArray<Readonly<ExportSpecifier> | Readonly<ImportDefaultSpecifier> | Readonly<ImportNamespaceSpecifier> | Readonly<ImportSpecifier>>} specifiers
* Specifiers.
* @param {Readonly<Expression>} init
* Initializer.
* @returns {Array<VariableDeclarator>}
* Declarations.
*/
export function specifiersToDeclarations(specifiers, init) {
let index = -1
/** @type {Array<VariableDeclarator>} */
const declarations = []
/** @type {Array<ExportSpecifier | ImportDefaultSpecifier | ImportSpecifier>} */
const otherSpecifiers = []
// Can only be one according to JS syntax.
/** @type {ImportNamespaceSpecifier | undefined} */
let importNamespaceSpecifier
while (++index < specifiers.length) {
const specifier = specifiers[index]
if (specifier.type === 'ImportNamespaceSpecifier') {
importNamespaceSpecifier = specifier
} else {
otherSpecifiers.push(specifier)
}
}
if (importNamespaceSpecifier) {
/** @type {VariableDeclarator} */
const declarator = {
type: 'VariableDeclarator',
id: importNamespaceSpecifier.local,
init
}
create(importNamespaceSpecifier, declarator)
declarations.push(declarator)
}
declarations.push({
type: 'VariableDeclarator',
id: {
type: 'ObjectPattern',
properties: otherSpecifiers.map(function (specifier) {
/** @type {Identifier} */
let key =
specifier.type === 'ImportSpecifier'
? specifier.imported
: specifier.type === 'ExportSpecifier'
? specifier.exported
: {type: 'Identifier', name: 'default'}
let value = specifier.local
// Switch them around if were exporting.
if (specifier.type === 'ExportSpecifier') {
value = key
key = specifier.local
}
/** @type {AssignmentProperty} */
const property = {
type: 'Property',
kind: 'init',
shorthand: key.name === value.name,
method: false,
computed: false,
key,
value
}
create(specifier, property)
return property
})
},
init: importNamespaceSpecifier
? {type: 'Identifier', name: importNamespaceSpecifier.local.name}
: init
})
return declarations
}

View File

@@ -0,0 +1,9 @@
/**
* @param {ReadonlyArray<Expression>} expressions
* Expressions.
* @returns {Expression}
* Addition.
*/
export function toBinaryAddition(expressions: ReadonlyArray<Expression>): Expression;
export type Expression = import('estree-jsx').Expression;
//# sourceMappingURL=estree-util-to-binary-addition.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estree-util-to-binary-addition.d.ts","sourceRoot":"","sources":["estree-util-to-binary-addition.js"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,8CALW,cAAc,UAAU,CAAC,GAEvB,UAAU,CAetB;yBAvBY,OAAO,YAAY,EAAE,UAAU"}

View File

@@ -0,0 +1,25 @@
/**
* @typedef {import('estree-jsx').Expression} Expression
*/
import {ok as assert} from 'devlop'
/**
* @param {ReadonlyArray<Expression>} expressions
* Expressions.
* @returns {Expression}
* Addition.
*/
export function toBinaryAddition(expressions) {
let index = -1
/** @type {Expression | undefined} */
let left
while (++index < expressions.length) {
const right = expressions[index]
left = left ? {type: 'BinaryExpression', left, operator: '+', right} : right
}
assert(left, 'expected non-empty `expressions` to be passed')
return left
}

View File

@@ -0,0 +1,20 @@
/**
* @param {ReadonlyArray<number | string>} ids
* Identifiers (example: `['list', 0]).
* @returns {Identifier | MemberExpression}
* Identifier or member expression.
*/
export function toIdOrMemberExpression(ids: ReadonlyArray<number | string>): Identifier | MemberExpression;
/**
* @param {ReadonlyArray<number | string>} ids
* Identifiers (example: `['list', 0]).
* @returns {JSXIdentifier | JSXMemberExpression}
* Identifier or member expression.
*/
export function toJsxIdOrMemberExpression(ids: ReadonlyArray<number | string>): JSXIdentifier | JSXMemberExpression;
export type Identifier = import('estree-jsx').Identifier;
export type JSXIdentifier = import('estree-jsx').JSXIdentifier;
export type JSXMemberExpression = import('estree-jsx').JSXMemberExpression;
export type Literal = import('estree-jsx').Literal;
export type MemberExpression = import('estree-jsx').MemberExpression;
//# sourceMappingURL=estree-util-to-id-or-member-expression.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"estree-util-to-id-or-member-expression.d.ts","sourceRoot":"","sources":["estree-util-to-id-or-member-expression.js"],"names":[],"mappings":"AAWA;;;;;GAKG;AACH,4CALW,cAAc,MAAM,GAAG,MAAM,CAAC,GAE5B,UAAU,GAAG,gBAAgB,CA6BzC;AAED;;;;;GAKG;AACH,+CALW,cAAc,MAAM,GAAG,MAAM,CAAC,GAE5B,aAAa,GAAG,mBAAmB,CAsB/C;yBArEY,OAAO,YAAY,EAAE,UAAU;4BAC/B,OAAO,YAAY,EAAE,aAAa;kCAClC,OAAO,YAAY,EAAE,mBAAmB;sBACxC,OAAO,YAAY,EAAE,OAAO;+BAC5B,OAAO,YAAY,EAAE,gBAAgB"}

View File

@@ -0,0 +1,71 @@
/**
* @typedef {import('estree-jsx').Identifier} Identifier
* @typedef {import('estree-jsx').JSXIdentifier} JSXIdentifier
* @typedef {import('estree-jsx').JSXMemberExpression} JSXMemberExpression
* @typedef {import('estree-jsx').Literal} Literal
* @typedef {import('estree-jsx').MemberExpression} MemberExpression
*/
import {ok as assert} from 'devlop'
import {name as isIdentifierName} from 'estree-util-is-identifier-name'
/**
* @param {ReadonlyArray<number | string>} ids
* Identifiers (example: `['list', 0]).
* @returns {Identifier | MemberExpression}
* Identifier or member expression.
*/
export function toIdOrMemberExpression(ids) {
let index = -1
/** @type {Identifier | Literal | MemberExpression | undefined} */
let object
while (++index < ids.length) {
const name = ids[index]
/** @type {Identifier | Literal} */
const id =
typeof name === 'string' && isIdentifierName(name)
? {type: 'Identifier', name}
: {type: 'Literal', value: name}
object = object
? {
type: 'MemberExpression',
object,
property: id,
computed: id.type === 'Literal',
optional: false
}
: id
}
assert(object, 'expected non-empty `ids` to be passed')
assert(object.type !== 'Literal', 'expected identifier as left-most value')
return object
}
/**
* @param {ReadonlyArray<number | string>} ids
* Identifiers (example: `['list', 0]).
* @returns {JSXIdentifier | JSXMemberExpression}
* Identifier or member expression.
*/
export function toJsxIdOrMemberExpression(ids) {
let index = -1
/** @type {JSXIdentifier | JSXMemberExpression | undefined} */
let object
while (++index < ids.length) {
const name = ids[index]
assert(
typeof name === 'string' && isIdentifierName(name, {jsx: true}),
'expected valid jsx identifier, not `' + name + '`'
)
/** @type {JSXIdentifier} */
const id = {type: 'JSXIdentifier', name}
object = object ? {type: 'JSXMemberExpression', object, property: id} : id
}
assert(object, 'expected non-empty `ids` to be passed')
return object
}

View File

@@ -0,0 +1,10 @@
/**
* Turn a list of extnames (*with* dots) into an expression.
*
* @param {ReadonlyArray<string>} extnames
* List of extnames.
* @returns {RegExp}
* Regex matching them.
*/
export function extnamesToRegex(extnames: ReadonlyArray<string>): RegExp;
//# sourceMappingURL=extnames-to-regex.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"extnames-to-regex.d.ts","sourceRoot":"","sources":["extnames-to-regex.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,0CALW,cAAc,MAAM,CAAC,GAEnB,MAAM,CAalB"}

19
node_modules/@mdx-js/mdx/lib/util/extnames-to-regex.js generated vendored Normal file
View File

@@ -0,0 +1,19 @@
/**
* Turn a list of extnames (*with* dots) into an expression.
*
* @param {ReadonlyArray<string>} extnames
* List of extnames.
* @returns {RegExp}
* Regex matching them.
*/
export function extnamesToRegex(extnames) {
return new RegExp(
'\\.(' +
extnames
.map(function (d) {
return d.slice(1)
})
.join('|') +
')([?#]|$)'
)
}

3
node_modules/@mdx-js/mdx/lib/util/extnames.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
export const md: string[];
export const mdx: string[];
//# sourceMappingURL=extnames.d.ts.map

1
node_modules/@mdx-js/mdx/lib/util/extnames.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"extnames.d.ts","sourceRoot":"","sources":["extnames.js"],"names":[],"mappings":"AAEA,0BAEE;AACF,2BAA2B"}

6
node_modules/@mdx-js/mdx/lib/util/extnames.js generated vendored Normal file
View File

@@ -0,0 +1,6 @@
import markdownExtensions from 'markdown-extensions'
export const md = markdownExtensions.map(function (d) {
return '.' + d
})
export const mdx = ['.mdx']

View File

@@ -0,0 +1,71 @@
/**
* Split compiletime options from runtime options.
*
* @param {Readonly<EvaluateOptions> | null | undefined} options
* Configuration.
* @returns {{compiletime: CompileOptions, runtime: RunOptions}}
* Split options.
*/
export function resolveEvaluateOptions(options: Readonly<EvaluateOptions> | null | undefined): {
compiletime: CompileOptions;
runtime: RunOptions;
};
export type Fragment = import('hast-util-to-jsx-runtime').Fragment;
export type Jsx = import('hast-util-to-jsx-runtime').Jsx;
export type JsxDev = import('hast-util-to-jsx-runtime').JsxDev;
export type Components = import('mdx/types.js').MDXComponents;
export type CompileOptions = import('../compile.js').CompileOptions;
/**
* Configuration for `evaluate`.
*/
export type EvaluateOptions = EvaluateProcessorOptions & RunOptions;
/**
* Compile configuration without JSX options for evaluation.
*/
export type EvaluateProcessorOptions = Omit<CompileOptions, 'baseUrl' | 'jsx' | 'jsxImportSource' | 'jsxRuntime' | 'outputFormat' | 'pragma' | 'pragmaFrag' | 'pragmaImportSource' | 'providerImportSource'>;
/**
* Configuration to run compiled code.
*
* `Fragment`, `jsx`, and `jsxs` are used when the code is compiled in
* production mode (`development: false`).
* `Fragment` and `jsxDEV` are used when compiled in development mode
* (`development: true`).
* `useMDXComponents` is used when the code is compiled with
* `providerImportSource: '#'` (the exact value of this compile option
* doesnt matter).
*/
export type RunOptions = {
/**
* Use this URL as `import.meta.url` and resolve `import` and `export … from`
* relative to it (optional, example: `import.meta.url`);
* this option can also be given at compile time in `CompileOptions`;
* you should pass this (likely at runtime), as you might get runtime errors
* when using `import.meta.url` / `import` / `export … from ` otherwise.
*/
baseUrl?: URL | string | null | undefined;
/**
* Symbol to use for fragments (**required**).
*/
Fragment: Fragment;
/**
* Function to generate an element with static children in production mode.
*/
jsx?: Jsx | null | undefined;
/**
* Function to generate an element in development mode.
*/
jsxDEV?: JsxDev | null | undefined;
/**
* Function to generate an element with dynamic children in production mode.
*/
jsxs?: Jsx | null | undefined;
/**
* Function to get components from context.
*/
useMDXComponents?: UseMdxComponents | null | undefined;
};
/**
* Get components from context.
*/
export type UseMdxComponents = () => Components;
//# sourceMappingURL=resolve-evaluate-options.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"resolve-evaluate-options.d.ts","sourceRoot":"","sources":["resolve-evaluate-options.js"],"names":[],"mappings":"AAmDA;;;;;;;GAOG;AACH,gDALW,SAAS,eAAe,CAAC,GAAG,IAAI,GAAG,SAAS,GAE1C;IAAC,WAAW,EAAE,cAAc,CAAC;IAAC,OAAO,EAAE,UAAU,CAAA;CAAC,CAgC9D;uBAvFY,OAAO,0BAA0B,EAAE,QAAQ;kBAC3C,OAAO,0BAA0B,EAAE,GAAG;qBACtC,OAAO,0BAA0B,EAAE,MAAM;yBACzC,OAAO,cAAc,EAAE,aAAa;6BACpC,OAAO,eAAe,EAAE,cAAc;;;;8BAItC,wBAAwB,GAAG,UAAU;;;;uCAGrC,KAAK,cAAc,EAAE,SAAS,GAAG,KAAK,GAAG,iBAAiB,GAAG,YAAY,GAAG,cAAc,GAAG,QAAQ,GAAG,YAAY,GAAG,oBAAoB,GAAG,sBAAsB,CAAC;;;;;;;;;;;;;;;;;;;;cAapK,GAAG,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS;;;;cAM/B,QAAQ;;;;UAER,GAAG,GAAG,IAAI,GAAG,SAAS;;;;aAEtB,MAAM,GAAG,IAAI,GAAG,SAAS;;;;WAEzB,GAAG,GAAG,IAAI,GAAG,SAAS;;;;uBAEtB,gBAAgB,GAAG,IAAI,GAAG,SAAS;;;;;qCAKpC,UAAU"}

View File

@@ -0,0 +1,89 @@
/**
* @typedef {import('hast-util-to-jsx-runtime').Fragment} Fragment
* @typedef {import('hast-util-to-jsx-runtime').Jsx} Jsx
* @typedef {import('hast-util-to-jsx-runtime').JsxDev} JsxDev
* @typedef {import('mdx/types.js').MDXComponents} Components
* @typedef {import('../compile.js').CompileOptions} CompileOptions
*/
/**
* @typedef {EvaluateProcessorOptions & RunOptions} EvaluateOptions
* Configuration for `evaluate`.
*
* @typedef {Omit<CompileOptions, 'baseUrl' | 'jsx' | 'jsxImportSource' | 'jsxRuntime' | 'outputFormat' | 'pragma' | 'pragmaFrag' | 'pragmaImportSource' | 'providerImportSource'> } EvaluateProcessorOptions
* Compile configuration without JSX options for evaluation.
*
* @typedef RunOptions
* Configuration to run compiled code.
*
* `Fragment`, `jsx`, and `jsxs` are used when the code is compiled in
* production mode (`development: false`).
* `Fragment` and `jsxDEV` are used when compiled in development mode
* (`development: true`).
* `useMDXComponents` is used when the code is compiled with
* `providerImportSource: '#'` (the exact value of this compile option
* doesnt matter).
* @property {URL | string | null | undefined} [baseUrl]
* Use this URL as `import.meta.url` and resolve `import` and `export … from`
* relative to it (optional, example: `import.meta.url`);
* this option can also be given at compile time in `CompileOptions`;
* you should pass this (likely at runtime), as you might get runtime errors
* when using `import.meta.url` / `import` / `export … from ` otherwise.
* @property {Fragment} Fragment
* Symbol to use for fragments (**required**).
* @property {Jsx | null | undefined} [jsx]
* Function to generate an element with static children in production mode.
* @property {JsxDev | null | undefined} [jsxDEV]
* Function to generate an element in development mode.
* @property {Jsx | null | undefined} [jsxs]
* Function to generate an element with dynamic children in production mode.
* @property {UseMdxComponents | null | undefined} [useMDXComponents]
* Function to get components from context.
*
* @callback UseMdxComponents
* Get components from context.
* @returns {Components}
* Current components.
*/
// Fix to show references to above types in VS Code.
''
/**
* Split compiletime options from runtime options.
*
* @param {Readonly<EvaluateOptions> | null | undefined} options
* Configuration.
* @returns {{compiletime: CompileOptions, runtime: RunOptions}}
* Split options.
*/
export function resolveEvaluateOptions(options) {
const {
Fragment,
baseUrl,
development,
jsx,
jsxDEV,
jsxs,
useMDXComponents,
...rest
} = options || {}
if (!Fragment) throw new Error('Expected `Fragment` given to `evaluate`')
if (development) {
if (!jsxDEV) throw new Error('Expected `jsxDEV` given to `evaluate`')
} else {
if (!jsx) throw new Error('Expected `jsx` given to `evaluate`')
if (!jsxs) throw new Error('Expected `jsxs` given to `evaluate`')
}
return {
compiletime: {
...rest,
development,
outputFormat: 'function-body',
providerImportSource: useMDXComponents ? '#' : undefined
},
runtime: {Fragment, baseUrl, jsx, jsxDEV, jsxs, useMDXComponents}
}
}

View File

@@ -0,0 +1,20 @@
/**
* Create a file and options from a given `vfileCompatible` and options that
* might contain `format: 'detect'`.
*
* @param {Readonly<Compatible>} vfileCompatible
* File.
* @param {Readonly<CompileOptions> | null | undefined} [options]
* Configuration (optional).
* @returns {{file: VFile, options: ProcessorOptions}}
* File and options.
*/
export function resolveFileAndOptions(vfileCompatible: Readonly<Compatible>, options?: Readonly<CompileOptions> | null | undefined): {
file: VFile;
options: ProcessorOptions;
};
export type Compatible = import('vfile').Compatible;
export type CompileOptions = import('../compile.js').CompileOptions;
export type ProcessorOptions = import('../core.js').ProcessorOptions;
import { VFile } from 'vfile';
//# sourceMappingURL=resolve-file-and-options.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"resolve-file-and-options.d.ts","sourceRoot":"","sources":["resolve-file-and-options.js"],"names":[],"mappings":"AASA;;;;;;;;;;GAUG;AACH,uDAPW,SAAS,UAAU,CAAC,YAEpB,SAAS,cAAc,CAAC,GAAG,IAAI,GAAG,SAAS;UAElC,KAAK;aAAW,gBAAgB;EAoBnD;yBApCY,OAAO,OAAO,EAAE,UAAU;6BAC1B,OAAO,eAAe,EAAE,cAAc;+BACtC,OAAO,YAAY,EAAE,gBAAgB;sBAG9B,OAAO"}

View File

@@ -0,0 +1,53 @@
/**
* @typedef {import('vfile').Compatible} Compatible
* @typedef {import('../compile.js').CompileOptions} CompileOptions
* @typedef {import('../core.js').ProcessorOptions} ProcessorOptions
*/
import {VFile} from 'vfile'
import {md} from './extnames.js'
/**
* Create a file and options from a given `vfileCompatible` and options that
* might contain `format: 'detect'`.
*
* @param {Readonly<Compatible>} vfileCompatible
* File.
* @param {Readonly<CompileOptions> | null | undefined} [options]
* Configuration (optional).
* @returns {{file: VFile, options: ProcessorOptions}}
* File and options.
*/
export function resolveFileAndOptions(vfileCompatible, options) {
const file = looksLikeAVFile(vfileCompatible)
? vfileCompatible
: new VFile(vfileCompatible)
const {format, ...rest} = options || {}
return {
file,
options: {
format:
format === 'md' || format === 'mdx'
? format
: file.extname && (rest.mdExtensions || md).includes(file.extname)
? 'md'
: 'mdx',
...rest
}
}
}
/**
* @param {Readonly<Compatible> | null | undefined} [value]
* Thing.
* @returns {value is VFile}
* Check.
*/
function looksLikeAVFile(value) {
return Boolean(
value &&
typeof value === 'object' &&
'message' in value &&
'messages' in value
)
}

21
node_modules/@mdx-js/mdx/license generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2017 Compositor, Inc. and Vercel, Inc.
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.

106
node_modules/@mdx-js/mdx/package.json generated vendored Normal file
View File

@@ -0,0 +1,106 @@
{
"name": "@mdx-js/mdx",
"version": "3.0.1",
"description": "MDX compiler",
"license": "MIT",
"keywords": [
"jsx",
"markdown",
"mdx",
"remark"
],
"homepage": "https://mdxjs.com",
"repository": {
"type": "git",
"url": "https://github.com/mdx-js/mdx",
"directory": "packages/mdx/"
},
"bugs": "https://github.com/mdx-js/mdx/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "John Otander <johnotander@gmail.com> (https://johno.com)",
"contributors": [
"John Otander <johnotander@gmail.com> (https://johno.com)",
"Tim Neutkens <tim@vercel.com>",
"Matija Marohnić <matija.marohnic@gmail.com>",
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"JounQin <admin@1stg.me> (https://www.1stg.me)",
"Christian Murphy <christian.murphy.42@gmail.com>"
],
"type": "module",
"sideEffects": false,
"exports": {
".": "./index.js",
"./internal-create-format-aware-processors": "./lib/util/create-format-aware-processors.js",
"./internal-extnames-to-regex": "./lib/util/extnames-to-regex.js"
},
"files": [
"lib/",
"index.d.ts.map",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/estree": "^1.0.0",
"@types/estree-jsx": "^1.0.0",
"@types/hast": "^3.0.0",
"@types/mdx": "^2.0.0",
"collapse-white-space": "^2.0.0",
"devlop": "^1.0.0",
"estree-util-build-jsx": "^3.0.0",
"estree-util-is-identifier-name": "^3.0.0",
"estree-util-to-js": "^2.0.0",
"estree-walker": "^3.0.0",
"hast-util-to-estree": "^3.0.0",
"hast-util-to-jsx-runtime": "^2.0.0",
"markdown-extensions": "^2.0.0",
"periscopic": "^3.0.0",
"remark-mdx": "^3.0.0",
"remark-parse": "^11.0.0",
"remark-rehype": "^11.0.0",
"source-map": "^0.7.0",
"unified": "^11.0.0",
"unist-util-position-from-estree": "^2.0.0",
"unist-util-stringify-position": "^4.0.0",
"unist-util-visit": "^5.0.0",
"vfile": "^6.0.0"
},
"scripts": {
"test": "npm run test-coverage",
"test-api": "node --conditions development --enable-source-maps test/index.js",
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"xo": {
"overrides": [
{
"files": [
"test/**/*.js"
],
"rules": {
"no-restricted-globals": "off"
}
},
{
"files": [
"**/*.ts"
],
"rules": {
"@typescript-eslint/array-type": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/consistent-type-definitions": "off"
}
}
],
"prettier": true,
"rules": {
"complexity": "off",
"logical-assignment-operators": "off",
"max-depth": "off",
"n/file-extension-in-import": "off",
"unicorn/prefer-at": "off",
"unicorn/prefer-code-point": "off"
}
}
}

1310
node_modules/@mdx-js/mdx/readme.md generated vendored Normal file

File diff suppressed because it is too large Load Diff

2
node_modules/@mdx-js/react/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export { MDXProvider, useMDXComponents } from "./lib/index.js";
//# sourceMappingURL=index.d.ts.map

1
node_modules/@mdx-js/react/index.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":""}

1
node_modules/@mdx-js/react/index.js generated vendored Normal file
View File

@@ -0,0 +1 @@
export {MDXProvider, useMDXComponents} from './lib/index.js'

44
node_modules/@mdx-js/react/lib/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,44 @@
/**
* Get current components from the MDX Context.
*
* @param {Readonly<MDXComponents> | MergeComponents | null | undefined} [components]
* Additional components to use or a function that creates them (optional).
* @returns {MDXComponents}
* Current components.
*/
export function useMDXComponents(components?: Readonly<MDXComponents> | MergeComponents | null | undefined): MDXComponents;
/**
* Provider for MDX context.
*
* @param {Readonly<Props>} properties
* Properties.
* @returns {JSX.Element}
* Element.
* @satisfies {Component}
*/
export function MDXProvider(properties: Readonly<Props>): JSX.Element;
export type MDXComponents = import('mdx/types.js').MDXComponents;
export type Component = import('react').Component<{}, {}, unknown>;
export type ReactNode = import('react').ReactNode;
/**
* Custom merge function.
*/
export type MergeComponents = (currentComponents: Readonly<MDXComponents>) => MDXComponents;
/**
* Configuration for `MDXProvider`.
*/
export type Props = {
/**
* Children (optional).
*/
children?: ReactNode | null | undefined;
/**
* Additional components to use or a function that creates them (optional).
*/
components?: Readonly<MDXComponents> | MergeComponents | null | undefined;
/**
* Turn off outer component context (default: `false`).
*/
disableParentContext?: boolean | null | undefined;
};
//# sourceMappingURL=index.d.ts.map

1
node_modules/@mdx-js/react/lib/index.d.ts.map generated vendored Normal file
View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.js"],"names":[],"mappings":"AA+BA;;;;;;;GAOG;AACH,8CALW,SAAS,aAAa,CAAC,GAAG,eAAe,GAAG,IAAI,GAAG,SAAS,GAE1D,aAAa,CAkBzB;AAED;;;;;;;;GAQG;AACH,wCANW,SAAS,KAAK,CAAC,GAEb,WAAW,CAsBvB;4BAlFY,OAAO,cAAc,EAAE,aAAa;wBACpC,OAAO,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC;wBAC1C,OAAO,OAAO,EAAE,SAAS;;;;kDAM3B,SAAS,aAAa,CAAC,KAErB,aAAa;;;;;;;;eAKZ,SAAS,GAAG,IAAI,GAAG,SAAS;;;;iBAE5B,SAAS,aAAa,CAAC,GAAG,eAAe,GAAG,IAAI,GAAG,SAAS;;;;2BAE5D,OAAO,GAAG,IAAI,GAAG,SAAS"}

84
node_modules/@mdx-js/react/lib/index.js generated vendored Normal file
View File

@@ -0,0 +1,84 @@
/**
* @typedef {import('mdx/types.js').MDXComponents} MDXComponents
* @typedef {import('react').Component<{}, {}, unknown>} Component
* @typedef {import('react').ReactNode} ReactNode
*/
/**
* @callback MergeComponents
* Custom merge function.
* @param {Readonly<MDXComponents>} currentComponents
* Current components from the context.
* @returns {MDXComponents}
* Additional components.
*
* @typedef Props
* Configuration for `MDXProvider`.
* @property {ReactNode | null | undefined} [children]
* Children (optional).
* @property {Readonly<MDXComponents> | MergeComponents | null | undefined} [components]
* Additional components to use or a function that creates them (optional).
* @property {boolean | null | undefined} [disableParentContext=false]
* Turn off outer component context (default: `false`).
*/
import React from 'react'
/** @type {Readonly<MDXComponents>} */
const emptyComponents = {}
const MDXContext = React.createContext(emptyComponents)
/**
* Get current components from the MDX Context.
*
* @param {Readonly<MDXComponents> | MergeComponents | null | undefined} [components]
* Additional components to use or a function that creates them (optional).
* @returns {MDXComponents}
* Current components.
*/
export function useMDXComponents(components) {
const contextComponents = React.useContext(MDXContext)
// Memoize to avoid unnecessary top-level context changes
return React.useMemo(
function () {
// Custom merge via a function prop
if (typeof components === 'function') {
return components(contextComponents)
}
return {...contextComponents, ...components}
},
[contextComponents, components]
)
}
/**
* Provider for MDX context.
*
* @param {Readonly<Props>} properties
* Properties.
* @returns {JSX.Element}
* Element.
* @satisfies {Component}
*/
export function MDXProvider(properties) {
/** @type {Readonly<MDXComponents>} */
let allComponents
if (properties.disableParentContext) {
allComponents =
typeof properties.components === 'function'
? properties.components(emptyComponents)
: properties.components || emptyComponents
} else {
allComponents = useMDXComponents(properties.components)
}
return React.createElement(
MDXContext.Provider,
{value: allComponents},
properties.children
)
}

21
node_modules/@mdx-js/react/license generated vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2017 Compositor and Vercel, Inc.
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.

73
node_modules/@mdx-js/react/package.json generated vendored Normal file
View File

@@ -0,0 +1,73 @@
{
"name": "@mdx-js/react",
"version": "3.0.1",
"description": "React context for MDX",
"license": "MIT",
"keywords": [
"jsx",
"markdown",
"mdx",
"react",
"remark"
],
"homepage": "https://mdxjs.com",
"repository": {
"type": "git",
"url": "https://github.com/mdx-js/mdx",
"directory": "packages/react/"
},
"bugs": "https://github.com/mdx-js/mdx/issues",
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/unified"
},
"author": "John Otander <johnotander@gmail.com> (https://johno.com)",
"contributors": [
"John Otander <johnotander@gmail.com> (https://johno.com)",
"Tim Neutkens <tim@vercel.com>",
"Matija Marohnić <matija.marohnic@gmail.com>",
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)",
"JounQin <admin@1stg.me> (https://www.1stg.me)",
"Christian Murphy <christian.murphy.42@gmail.com>"
],
"type": "module",
"sideEffects": false,
"exports": "./index.js",
"files": [
"lib/",
"index.d.ts.map",
"index.d.ts",
"index.js"
],
"dependencies": {
"@types/mdx": "^2.0.0"
},
"peerDependencies": {
"@types/react": ">=16",
"react": ">=16"
},
"devDependencies": {},
"scripts": {
"test": "npm run test-coverage",
"test-api": "node --conditions development --loader=../../script/jsx-loader.js test/index.jsx",
"test-coverage": "c8 --100 --reporter lcov npm run test-api"
},
"xo": {
"overrides": [
{
"extends": "xo-react",
"files": [
"**/*.jsx"
],
"rules": {
"react/jsx-no-bind": "off",
"react/react-in-jsx-scope": "off"
}
}
],
"prettier": true,
"rules": {
"n/file-extension-in-import": "off"
}
}
}

271
node_modules/@mdx-js/react/readme.md generated vendored Normal file
View File

@@ -0,0 +1,271 @@
# `@mdx-js/react`
[![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]
React context for MDX.
<!-- more -->
## Contents
* [What is this?](#what-is-this)
* [When should I use this?](#when-should-i-use-this)
* [Install](#install)
* [Use](#use)
* [API](#api)
* [`MDXProvider(properties?)`](#mdxproviderproperties)
* [`useMDXComponents(components?)`](#usemdxcomponentscomponents)
* [`MergeComponents`](#mergecomponents)
* [`Props`](#props)
* [Types](#types)
* [Compatibility](#compatibility)
* [Security](#security)
* [Contribute](#contribute)
* [License](#license)
## What is this?
This package is a *context* based components provider for combining React with
MDX.
## When should I use this?
This package is **not needed** for MDX to work with React.
See [¶ MDX provider in § Using MDX][use-provider] for when and how to use an MDX
provider.
If you use Next.js, **do not use this**.
Add an `mdx-components.tsx` (in `src/` or `/`) file instead.
See [Configuring MDX on `nextjs.org`][next-configuring-mdx] for more info.
## Install
This package is [ESM only][esm].
In Node.js (version 16+), install with [npm][]:
```sh
npm install @mdx-js/react
```
In Deno with [`esm.sh`][esmsh]:
```tsx
import {MDXProvider} from 'https://esm.sh/@mdx-js/react@3'
```
In browsers with [`esm.sh`][esmsh]:
```html
<script type="module">
import {MDXProvider} from 'https://esm.sh/@mdx-js/react@3?bundle'
</script>
```
## Use
```tsx
import {MDXProvider} from '@mdx-js/react'
import Post from './post.mdx'
// ^-- Assumes an integration is used to compile MDX to JS, such as
// `@mdx-js/esbuild`, `@mdx-js/loader`, `@mdx-js/node-loader`, or
// `@mdx-js/rollup`, and that it is configured with
// `options.providerImportSource: '@mdx-js/react'`.
/** @type {import('mdx/types.js').MDXComponents} */
const components = {
em(properties) {
return <i {...properties} />
}
}
console.log(
<MDXProvider components={components}>
<Post />
</MDXProvider>
)
```
> 👉 **Note**: you dont have to use `MDXProvider` and can pass components
> directly:
>
> ```diff
> -<MDXProvider components={components}>
> - <Post />
> -</MDXProvider>
> +<Post components={components} />
> ```
See [¶ React in § Getting started][start-react] for how to get started with MDX
and React.
See [¶ MDX provider in § Using MDX][use-provider] for how to use an MDX
provider.
## API
This package exports the identifiers [`MDXProvider`][api-mdx-provider] and
[`useMDXComponents`][api-use-mdx-components].
There is no default export.
### `MDXProvider(properties?)`
Provider for MDX context.
###### Parameters
* `properties` ([`Props`][api-props])
— configuration
##### Returns
Element (`JSX.Element`).
### `useMDXComponents(components?)`
Get current components from the MDX Context.
###### Parameters
* `components` ([`MDXComponents` from `mdx/types.js`][mdx-types-components]
or [`MergeComponents`][api-merge-components], optional)
— additional components to use or a function that creates them
###### Returns
Current components ([`MDXComponents` from
`mdx/types.js`][mdx-types-components]).
### `MergeComponents`
Custom merge function (TypeScript type).
###### Parameters
* `components` ([`MDXComponents` from `mdx/types.js`][mdx-types-components])
— current components from the context
###### Returns
Additional components ([`MDXComponents` from
`mdx/types.js`][mdx-types-components]).
### `Props`
Configuration for `MDXProvider` (TypeScript type).
###### Fields
* `children` ([`ReactNode` from `react`][react-node],
optional)
— children
* `components` ([`MDXComponents` from `mdx/types.js`][mdx-types-components]
or [`MergeComponents`][api-merge-components], optional)
— additional components to use or a function that creates them
* `disableParentContext` (`boolean`, default: `false`)
— turn off outer component context
## Types
This package is fully typed with [TypeScript][].
It exports the additional types [`MergeComponents`][api-merge-components] and
[`Props`][api-props].
For types to work, make sure the TypeScript `JSX` namespace is typed.
This is done by installing and using the types of your framework, as in
[`@types/react`](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react).
## 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, `@mdx-js/react@^3`,
compatible with Node.js 16.
## Security
See [§ Security][security] on our website for information.
## Contribute
See [§ Contribute][contribute] on our website for ways to get started.
See [§ Support][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][] © Compositor and [Vercel][]
[build-badge]: https://github.com/mdx-js/mdx/workflows/main/badge.svg
[build]: https://github.com/mdx-js/mdx/actions
[coverage-badge]: https://img.shields.io/codecov/c/github/mdx-js/mdx/main.svg
[coverage]: https://codecov.io/github/mdx-js/mdx
[downloads-badge]: https://img.shields.io/npm/dm/@mdx-js/react.svg
[downloads]: https://www.npmjs.com/package/@mdx-js/react
[size-badge]: https://img.shields.io/bundlejs/size/@mdx-js/react
[size]: https://bundlejs.com/?q=@mdx-js/react
[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/mdx-js/mdx/discussions
[npm]: https://docs.npmjs.com/cli/install
[contribute]: https://mdxjs.com/community/contribute/
[support]: https://mdxjs.com/community/support/
[coc]: https://github.com/mdx-js/.github/blob/main/code-of-conduct.md
[mit]: https://github.com/mdx-js/mdx/blob/main/packages/react/license
[vercel]: https://vercel.com
[start-react]: https://mdxjs.com/getting-started/#react
[use-provider]: https://mdxjs.com/docs/using-mdx/#mdx-provider
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
[esmsh]: https://esm.sh
[security]: https://mdxjs.com/getting-started/#security
[typescript]: https://www.typescriptlang.org
[mdx-types-components]: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/HEAD/types/mdx/types.d.ts#L65
[react-node]: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/HEAD/types/react/index.d.ts#L244
[next-configuring-mdx]: https://nextjs.org/docs/pages/building-your-application/configuring/mdx
[api-mdx-provider]: #mdxproviderproperties
[api-merge-components]: #mergecomponents
[api-props]: #props
[api-use-mdx-components]: #usemdxcomponentscomponents