fumadocs-openapi 8.1.11 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,38 +1,73 @@
1
- import { type GenerateOptions } from './generate.js';
2
- export interface Config extends GenerateOptions {
1
+ import { type GenerateOptions, type GeneratePageOutput, type GenerateTagOutput } from './generate.js';
2
+ import { type ProcessedDocument } from './utils/process-document.js';
3
+ interface GenerateFileOutput {
3
4
  /**
4
- * Schema files
5
+ * The original schema file path/url from `input`
5
6
  */
6
- input: string[] | string;
7
+ pathOrUrl: string;
8
+ content: string;
9
+ }
10
+ interface OperationConfig extends BaseConfig {
7
11
  /**
8
- * Output directory
12
+ * Generate a page for each API endpoint/operation (default).
9
13
  */
10
- output: string;
14
+ per?: 'operation';
11
15
  /**
12
- * tag: Generate a page for each tag
13
- * file: Generate a page for each schema
14
- * operation: Generate a page for each API endpoint/operation
16
+ * Group output using folders (Only works on `operation` mode)
17
+ * - tag: `{tag}/{file}`
18
+ * - route: `{endpoint}/{method}` (it will ignore the `name` option)
19
+ * - none: `{file}` (default)
15
20
  *
16
- * @defaultValue 'operation'
21
+ * @defaultValue 'none'
17
22
  */
18
- per?: 'tag' | 'file' | 'operation';
23
+ groupBy?: 'tag' | 'route' | 'none';
19
24
  /**
20
25
  * Specify name for output file
21
26
  */
22
- name?: (type: 'file' | 'tag', name: string) => string;
27
+ name?: ((output: GeneratePageOutput, document: ProcessedDocument['document']) => string) | BaseName;
28
+ }
29
+ interface TagConfig extends BaseConfig {
23
30
  /**
24
- * Group output using folders (Only works on `operation` mode)
25
- *
26
- * @deprecated Use `groupBy` instead
27
- * @defaultValue false
31
+ * Generate a page for each tag.
28
32
  */
29
- groupByFolder?: boolean;
33
+ per: 'tag';
30
34
  /**
31
- * Group output using folders (Only works on `operation` mode)
35
+ * Specify name for output file
36
+ */
37
+ name?: ((output: GenerateTagOutput, document: ProcessedDocument['document']) => string) | BaseName;
38
+ }
39
+ interface FileConfig extends BaseConfig {
40
+ /**
41
+ * Generate a page for each schema file.
42
+ */
43
+ per: 'file';
44
+ /**
45
+ * Specify name for output file
46
+ */
47
+ name?: ((output: GenerateFileOutput, document: ProcessedDocument['document']) => string) | BaseName;
48
+ }
49
+ export type Config = FileConfig | TagConfig | OperationConfig;
50
+ interface BaseName {
51
+ /**
52
+ * The version of algorithm used to generate file paths.
32
53
  *
33
- * @defaultValue 'none'
54
+ * v1: Fumadocs OpenAPI v8
55
+ * v2: Fumadocs OpenAPI v9
56
+ *
57
+ * @defaultValue v2
34
58
  */
35
- groupBy?: 'tag' | 'route' | 'none';
59
+ algorithm?: 'v2' | 'v1';
60
+ }
61
+ interface BaseConfig extends GenerateOptions {
62
+ /**
63
+ * Schema files
64
+ */
65
+ input: string[] | string;
66
+ /**
67
+ * Output directory
68
+ */
69
+ output: string;
36
70
  }
37
71
  export declare function generateFiles(options: Config): Promise<void>;
72
+ export {};
38
73
  //# sourceMappingURL=generate-file.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate-file.d.ts","sourceRoot":"","sources":["../src/generate-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,eAAe,EAIrB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C;;OAEG;IACH,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAEzB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,WAAW,CAAC;IAEnC;;OAEG;IACH,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAEtD;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,OAAO,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;CACpC;AAED,wBA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,CAAC;AAE9D,UAAU,QAAQ;IAChB;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;CACzB;AAED,UAAU,UAAW,SAAQ,eAAe;IAC1C;;OAEG;IACH,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAEzB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA6BlE"}
@@ -1,9 +1,11 @@
1
1
  import { mkdir, writeFile } from 'node:fs/promises';
2
2
  import * as path from 'node:path';
3
- import fg from 'fast-glob';
3
+ import { resolve } from 'node:path';
4
+ import { glob } from 'tinyglobby';
4
5
  import { generateAll, generatePages, generateTags, } from './generate.js';
6
+ import { processDocument, } from './utils/process-document.js';
5
7
  export async function generateFiles(options) {
6
- const { input, output, name: nameFn, per = 'operation', groupBy = 'none', cwd = process.cwd(), } = options;
8
+ const { input, cwd = process.cwd() } = options;
7
9
  const urlInputs = [];
8
10
  const fileInputs = [];
9
11
  for (const v of typeof input === 'string' ? [input] : input) {
@@ -15,97 +17,115 @@ export async function generateFiles(options) {
15
17
  }
16
18
  }
17
19
  const resolvedInputs = [
18
- ...(await fg.glob(fileInputs, { cwd, absolute: false })),
20
+ ...(await glob(fileInputs, { cwd, absolute: false })),
19
21
  ...urlInputs,
20
22
  ];
21
23
  if (resolvedInputs.length === 0) {
22
24
  throw new Error(`No input files found. Tried resolving: ${typeof input === 'string' ? input : input.join(', ')}`);
23
25
  }
24
- function getOutputPaths(result) {
25
- let file;
26
- if (result.pathItem.summary) {
27
- file = getFilename(result.pathItem.summary);
28
- }
29
- else if (result.type === 'operation') {
30
- file = path.join(getOutputPathFromRoute(result.item.path), result.item.method.toLowerCase());
31
- }
32
- else {
33
- file = getFilename(result.item.name);
26
+ await Promise.all(resolvedInputs.map((input) => generateFromDocument(input, options)));
27
+ }
28
+ async function generateFromDocument(pathOrUrl, options) {
29
+ const { output, cwd = process.cwd() } = options;
30
+ let nameFn;
31
+ if (!options.name || typeof options.name !== 'function') {
32
+ const { algorithm = 'v2' } = options.name ?? {};
33
+ nameFn = (output, document) => {
34
+ if (options.per === 'tag') {
35
+ const result = output;
36
+ return getFilename(result.tag);
37
+ }
38
+ if (options.per === 'file') {
39
+ return isUrl(pathOrUrl)
40
+ ? 'index'
41
+ : path.basename(pathOrUrl, path.extname(pathOrUrl));
42
+ }
43
+ const result = output;
44
+ if (result.type === 'operation') {
45
+ const operation = document.paths[result.item.path][result.item.method];
46
+ if (algorithm === 'v2' && operation.operationId) {
47
+ return operation.operationId;
48
+ }
49
+ return path.join(getOutputPathFromRoute(result.item.path), result.item.method.toLowerCase());
50
+ }
51
+ const hook = document.webhooks[result.item.name][result.item.method];
52
+ if (algorithm === 'v2' && hook.operationId) {
53
+ return hook.operationId;
54
+ }
55
+ return getFilename(result.item.name);
56
+ };
57
+ }
58
+ else {
59
+ nameFn = options.name;
60
+ }
61
+ const document = await dereference(pathOrUrl, options);
62
+ const outputDir = path.join(cwd, output);
63
+ async function write(file, content) {
64
+ await mkdir(path.dirname(file), { recursive: true });
65
+ await writeFile(file, content);
66
+ }
67
+ function getOutputPaths(groupBy = 'none', result) {
68
+ const file = nameFn(result, document.document);
69
+ if (groupBy === 'route') {
70
+ return [
71
+ path.join(result.type === 'operation' ? result.item.path : result.item.name, result.item.method) + '.mdx',
72
+ ];
34
73
  }
35
- const outPaths = [];
36
74
  if (groupBy === 'tag') {
37
- let tags = result.operation.tags;
75
+ let tags = result.type === 'operation'
76
+ ? document.document.paths[result.item.path][result.item.method]
77
+ .tags
78
+ : document.document.webhooks[result.item.name][result.item.method]
79
+ .tags;
38
80
  if (!tags || tags.length === 0) {
39
81
  console.warn('When `groupBy` is set to `tag`, make sure a `tags` is defined for every operation schema.');
40
82
  tags = ['unknown'];
41
83
  }
42
- for (const tag of tags) {
43
- outPaths.push(path.join(getFilename(tag), `${file}.mdx`));
44
- }
84
+ return tags.map((tag) => path.join(getFilename(tag), `${file}.mdx`));
45
85
  }
46
- else {
47
- outPaths.push(`${file}.mdx`);
48
- }
49
- return outPaths;
86
+ return [`${file}.mdx`];
50
87
  }
51
- const metaFiles = new Set();
52
- async function writeMetafile(file, data) {
53
- if (metaFiles.has(file))
54
- return;
55
- metaFiles.add(file);
56
- await write(file, JSON.stringify(data, null, 2));
57
- console.log(`Generated Meta: ${file}`);
88
+ if (options.per === 'file') {
89
+ const result = await generateAll(document, options);
90
+ const filename = nameFn({
91
+ pathOrUrl,
92
+ content: result,
93
+ }, document.document);
94
+ const outPath = path.join(outputDir, `${filename}.mdx`);
95
+ await write(outPath, result);
96
+ console.log(`Generated: ${outPath}`);
58
97
  }
59
- async function generateFromDocument(pathOrUrl) {
60
- const outputDir = path.join(cwd, output);
61
- if (per === 'file') {
62
- let filename = isUrl(pathOrUrl)
63
- ? 'index'
64
- : path.basename(pathOrUrl, path.extname(pathOrUrl));
65
- if (nameFn)
66
- filename = nameFn('file', filename);
98
+ else if (options.per === 'tag') {
99
+ const results = await generateTags(document, options);
100
+ for (const result of results) {
101
+ const filename = nameFn(result, document.document);
67
102
  const outPath = path.join(outputDir, `${filename}.mdx`);
68
- const result = await generateAll(pathOrUrl, options);
69
- await write(outPath, result);
103
+ await write(outPath, result.content);
70
104
  console.log(`Generated: ${outPath}`);
71
105
  }
72
- if (per === 'operation') {
73
- const results = await generatePages(pathOrUrl, options);
74
- const mapping = new Map();
75
- for (const result of results) {
76
- const outputPaths = getOutputPaths(result);
77
- for (const outputPath of outputPaths) {
78
- mapping.set(outputPath, result);
79
- }
106
+ }
107
+ else {
108
+ const results = await generatePages(document, options);
109
+ const mapping = new Map();
110
+ for (const result of results) {
111
+ for (const outputPath of getOutputPaths(options.groupBy, result)) {
112
+ mapping.set(outputPath, result);
80
113
  }
81
- for (const [key, output] of mapping.entries()) {
82
- let outputPath = key;
114
+ }
115
+ for (const [key, output] of mapping.entries()) {
116
+ let outputPath = key;
117
+ // v1 will remove nested directories
118
+ if (typeof options.name === 'object' && options.name.algorithm === 'v1') {
83
119
  const isSharedDir = Array.from(mapping.keys()).some((item) => item !== outputPath &&
84
120
  path.dirname(item) === path.dirname(outputPath));
85
121
  if (!isSharedDir && path.dirname(outputPath) !== '.') {
86
122
  outputPath = path.join(path.dirname(outputPath) + '.mdx');
87
123
  }
88
- await write(path.join(outputDir, outputPath), output.content);
89
- if (groupBy === 'route' && output.pathItem.summary) {
90
- await writeMetafile(path.join(outputDir, path.dirname(outputPath), 'meta.json'), {
91
- title: output.pathItem.summary,
92
- });
93
- }
94
- console.log(`Generated: ${outputPath}`);
95
- }
96
- }
97
- if (per === 'tag') {
98
- const results = await generateTags(pathOrUrl, options);
99
- for (const result of results) {
100
- let tagName = result.tag;
101
- tagName = nameFn?.('tag', tagName) ?? getFilename(tagName);
102
- const outPath = path.join(outputDir, `${tagName}.mdx`);
103
- await write(outPath, result.content);
104
- console.log(`Generated: ${outPath}`);
105
124
  }
125
+ await write(path.join(outputDir, outputPath), output.content);
126
+ console.log(`Generated: ${outputPath}`);
106
127
  }
107
128
  }
108
- await Promise.all(resolvedInputs.map(generateFromDocument));
109
129
  }
110
130
  function isUrl(input) {
111
131
  return input.startsWith('https://') || input.startsWith('http://');
@@ -125,7 +145,12 @@ function getOutputPathFromRoute(path) {
125
145
  function getFilename(s) {
126
146
  return s.replace(/\s+/g, '-').toLowerCase();
127
147
  }
128
- async function write(file, content) {
129
- await mkdir(path.dirname(file), { recursive: true });
130
- await writeFile(file, content);
148
+ async function dereference(pathOrDocument, options) {
149
+ return processDocument(
150
+ // resolve paths
151
+ typeof pathOrDocument === 'string' &&
152
+ !pathOrDocument.startsWith('http://') &&
153
+ !pathOrDocument.startsWith('https://')
154
+ ? resolve(options.cwd ?? process.cwd(), pathOrDocument)
155
+ : pathOrDocument);
131
156
  }
@@ -1,8 +1,6 @@
1
1
  import { type DocumentContext } from './utils/generate-document.js';
2
- import type { OperationObject, PathItemObject } from './types.js';
3
- import type { NoReference } from './utils/schema.js';
4
2
  import type { OperationItem, WebhookItem } from './render/api-page.js';
5
- import { type DocumentInput } from './utils/process-document.js';
3
+ import type { ProcessedDocument } from './utils/process-document.js';
6
4
  export interface GenerateOptions {
7
5
  /**
8
6
  * Additional imports of your MDX components.
@@ -42,18 +40,14 @@ export interface GenerateTagOutput {
42
40
  }
43
41
  export type GeneratePageOutput = {
44
42
  type: 'operation';
45
- pathItem: NoReference<PathItemObject>;
46
- operation: NoReference<OperationObject>;
47
43
  item: OperationItem;
48
44
  content: string;
49
45
  } | {
50
46
  type: 'webhook';
51
- pathItem: NoReference<PathItemObject>;
52
- operation: NoReference<OperationObject>;
53
47
  item: WebhookItem;
54
48
  content: string;
55
49
  };
56
- export declare function generateAll(pathOrDocument: DocumentInput, options?: GenerateOptions): Promise<string>;
57
- export declare function generatePages(pathOrDocument: DocumentInput, options?: GenerateOptions): Promise<GeneratePageOutput[]>;
58
- export declare function generateTags(pathOrDocument: DocumentInput, options?: GenerateOptions): Promise<GenerateTagOutput[]>;
50
+ export declare function generateAll({ document, downloaded }: ProcessedDocument, options?: GenerateOptions): Promise<string>;
51
+ export declare function generatePages({ document, downloaded }: ProcessedDocument, options?: GenerateOptions): Promise<GeneratePageOutput[]>;
52
+ export declare function generateTags({ document, downloaded }: ProcessedDocument, options?: GenerateOptions): Promise<GenerateTagOutput[]>;
59
53
  //# sourceMappingURL=generate.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,eAAe,EAErB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,E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,wBAAsB,WAAW,CAC/B,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,iBAAiB,EAC3C,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAmBjB;AAED,wBAAsB,aAAa,CACjC,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,iBAAiB,EAC3C,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,kBAAkB,EAAE,CAAC,CA4D/B;AAED,wBAAsB,YAAY,CAChC,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,iBAAiB,EAC3C,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAqC9B"}
package/dist/generate.js CHANGED
@@ -1,19 +1,7 @@
1
- import { resolve } from 'node:path';
2
1
  import { getAPIPageItems } from './build-routes.js';
3
2
  import { generateDocument, } from './utils/generate-document.js';
4
3
  import { idToTitle } from './utils/id-to-title.js';
5
- import { processDocument } from './utils/process-document.js';
6
- async function dereference(pathOrDocument, options) {
7
- return await processDocument(
8
- // resolve paths
9
- typeof pathOrDocument === 'string' &&
10
- !pathOrDocument.startsWith('http://') &&
11
- !pathOrDocument.startsWith('https://')
12
- ? resolve(options.cwd ?? process.cwd(), pathOrDocument)
13
- : pathOrDocument).then((res) => res.document);
14
- }
15
- export async function generateAll(pathOrDocument, options = {}) {
16
- const document = await dereference(pathOrDocument, options);
4
+ export async function generateAll({ document, downloaded }, options = {}) {
17
5
  const items = getAPIPageItems(document);
18
6
  return generateDocument({
19
7
  ...options,
@@ -24,15 +12,14 @@ export async function generateAll(pathOrDocument, options = {}) {
24
12
  operations: items.operations,
25
13
  webhooks: items.webhooks,
26
14
  hasHead: true,
27
- document: pathOrDocument,
15
+ document: downloaded,
28
16
  },
29
17
  context: {
30
18
  type: 'file',
31
19
  },
32
20
  });
33
21
  }
34
- export async function generatePages(pathOrDocument, options = {}) {
35
- const document = await dereference(pathOrDocument, options);
22
+ export async function generatePages({ document, downloaded }, options = {}) {
36
23
  const items = getAPIPageItems(document);
37
24
  const result = [];
38
25
  for (const item of items.operations) {
@@ -44,15 +31,13 @@ export async function generatePages(pathOrDocument, options = {}) {
44
31
  continue;
45
32
  result.push({
46
33
  type: 'operation',
47
- pathItem,
48
- operation,
49
34
  item,
50
35
  content: generateDocument({
51
36
  ...options,
52
37
  page: {
53
38
  operations: [item],
54
39
  hasHead: false,
55
- document: pathOrDocument,
40
+ document: downloaded,
56
41
  },
57
42
  dereferenced: document,
58
43
  title: operation.summary ??
@@ -74,15 +59,13 @@ export async function generatePages(pathOrDocument, options = {}) {
74
59
  continue;
75
60
  result.push({
76
61
  type: 'webhook',
77
- pathItem,
78
- operation,
79
62
  item,
80
63
  content: generateDocument({
81
64
  ...options,
82
65
  page: {
83
66
  webhooks: [item],
84
67
  hasHead: false,
85
- document: pathOrDocument,
68
+ document: downloaded,
86
69
  },
87
70
  dereferenced: document,
88
71
  title: operation.summary ?? pathItem.summary ?? idToTitle(item.name),
@@ -95,8 +78,7 @@ export async function generatePages(pathOrDocument, options = {}) {
95
78
  }
96
79
  return result;
97
80
  }
98
- export async function generateTags(pathOrDocument, options = {}) {
99
- const document = await dereference(pathOrDocument, options);
81
+ export async function generateTags({ document, downloaded }, options = {}) {
100
82
  if (!document.tags)
101
83
  return [];
102
84
  const items = getAPIPageItems(document);
@@ -111,7 +93,7 @@ export async function generateTags(pathOrDocument, options = {}) {
111
93
  content: generateDocument({
112
94
  ...options,
113
95
  page: {
114
- document: pathOrDocument,
96
+ document: downloaded,
115
97
  operations,
116
98
  webhooks,
117
99
  hasHead: true,
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from './generate.js';
2
2
  export * from './generate-file.js';
3
3
  export * from './types.js';
4
+ export type { MediaAdapter } from './media/adapter.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC"}
@@ -1,24 +1,20 @@
1
- import { type HTMLAttributes, type ReactNode } from 'react';
1
+ import { ComponentProps, type HTMLAttributes, type ReactNode } from 'react';
2
2
  import type { RequestSchema } from '../playground/index.js';
3
3
  export declare function ObjectInput({ field: _field, fieldName, ...props }: {
4
4
  field: Exclude<RequestSchema, boolean>;
5
5
  fieldName: string;
6
- } & HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
6
+ } & ComponentProps<'div'>): import("react/jsx-runtime").JSX.Element | undefined;
7
7
  export declare function JsonInput({ fieldName, children, }: {
8
8
  fieldName: string;
9
9
  children: ReactNode;
10
10
  }): import("react/jsx-runtime").JSX.Element;
11
- export declare function FieldInput({ field, fieldName, isRequired, ...props }: HTMLAttributes<HTMLElement> & {
12
- field: Exclude<RequestSchema, boolean>;
13
- isRequired?: boolean;
14
- fieldName: string;
15
- }): import("react/jsx-runtime").JSX.Element;
16
- export declare function FieldSet({ field: _field, fieldName, toolbar, name, isRequired, depth, ...props }: HTMLAttributes<HTMLElement> & {
11
+ export declare function FieldSet({ field: _field, fieldName, toolbar, name, isRequired, depth, slotType, ...props }: HTMLAttributes<HTMLElement> & {
17
12
  isRequired?: boolean;
18
13
  name?: ReactNode;
19
14
  field: RequestSchema;
20
15
  fieldName: string;
21
16
  depth?: number;
17
+ slotType?: ReactNode;
22
18
  toolbar?: ReactNode;
23
19
  }): import("react/jsx-runtime").JSX.Element | null;
24
20
  //# sourceMappingURL=inputs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/playground/inputs.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAef,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AA8CxD,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EACT,GAAG,KAAK,EACT,EAAE;IACD,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACvC,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,cAAc,CAAC,cAAc,CAAC,2CAqCjC;AAED,wBAAgB,SAAS,CAAC,EACxB,SAAS,EACT,QAAQ,GACT,EAAE;IACD,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,SAAS,CAAC;CACrB,2CA0BA;AAyFD,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,SAAS,EACT,UAAU,EACV,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,2CAmGA;AAED,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EAAE,MAAM,EACb,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,EACV,KAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,SAAS,CAAC;CACrB,kDA2HA"}
1
+ {"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/playground/inputs.tsx"],"names":[],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