@xyd-js/uniform 0.0.0-build

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.
@@ -0,0 +1,45 @@
1
+ import { R as Reference } from './types-BiglsETJ.js';
2
+ export { B as BaseReferenceContext, m as CodeBlock, n as CodeBlockTab, C as CommonDefinitionVariantMeta, i as DEFINED_DEFINITION_PROPERTY_TYPE, d as Definition, b as DefinitionGraphqlMeta, c as DefinitionMeta, D as DefinitionOpenAPIMeta, j as DefinitionProperty, h as DefinitionPropertyMeta, a as DefinitionTypeDocMeta, g as DefinitionVariant, f as DefinitionVariantMeta, e as DefinitionVariantOpenAPIMeta, l as Example, o as ExampleContext, k as ExampleGroup, E as ExampleRoot, t as GraphQLExampleContext, G as GraphQLReferenceContext, M as Meta, u as OpenAPIExampleContext, O as OpenAPIReferenceContext, p as ReferenceCategory, s as ReferenceContext, q as ReferenceType, S as SymbolDef, r as TypeDocReferenceContext, T as TypeDocReferenceContextMeta } from './types-BiglsETJ.js';
3
+ import { Settings, MetadataMap, Sidebar } from '@xyd-js/core';
4
+ import 'react';
5
+ import 'codehike/code';
6
+
7
+ type UniformPluginArgs = {
8
+ references: Reference[] | Reference;
9
+ defer: (defer: () => any) => void;
10
+ };
11
+ type UniformPluginRestArgs = {
12
+ index: number;
13
+ };
14
+ type UniformPlugin<T> = (args: UniformPluginArgs) => (ref: Reference, restArgs: UniformPluginRestArgs) => void;
15
+ type NormalizeArray<T> = T extends Array<infer U> ? U[] : T;
16
+ type PluginResult<T extends UniformPlugin<any>> = T extends UniformPlugin<infer R> ? R : never;
17
+ type MergePluginResults<T extends UniformPlugin<any>[]> = {
18
+ [K in keyof UnionToIntersection<PluginResult<T[number]>>]: NormalizeArray<UnionToIntersection<PluginResult<T[number]>>[K]>;
19
+ };
20
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
21
+ declare function uniform<T extends UniformPlugin<any>[]>(references: Reference[], config: {
22
+ plugins: T;
23
+ }): {
24
+ references: Reference[];
25
+ out: MergePluginResults<T> extends infer T_1 ? { [K in keyof T_1]: MergePluginResults<T>[K]; } : never;
26
+ };
27
+
28
+ interface pluginJsonViewOptions {
29
+ }
30
+ type pluginJsonViewOutput = {
31
+ jsonViews: string;
32
+ };
33
+ declare function pluginJsonView(options?: pluginJsonViewOptions): UniformPlugin<pluginJsonViewOutput>;
34
+
35
+ interface pluginNavigationOptions {
36
+ urlPrefix: string;
37
+ defaultGroup?: string;
38
+ }
39
+ type pluginNavigationOutput = {
40
+ pageFrontMatter: MetadataMap;
41
+ sidebar: Sidebar[];
42
+ };
43
+ declare function pluginNavigation(settings: Settings, options: pluginNavigationOptions): UniformPlugin<pluginNavigationOutput>;
44
+
45
+ export { Reference, type UniformPlugin, type UniformPluginArgs, uniform as default, pluginJsonView, pluginNavigation };
package/dist/index.js ADDED
@@ -0,0 +1,194 @@
1
+ // src/types.ts
2
+ var DEFINED_DEFINITION_PROPERTY_TYPE = /* @__PURE__ */ ((DEFINED_DEFINITION_PROPERTY_TYPE2) => {
3
+ DEFINED_DEFINITION_PROPERTY_TYPE2["UNION"] = "$$union";
4
+ DEFINED_DEFINITION_PROPERTY_TYPE2["XOR"] = "$$xor";
5
+ DEFINED_DEFINITION_PROPERTY_TYPE2["ARRAY"] = "$$array";
6
+ DEFINED_DEFINITION_PROPERTY_TYPE2["ENUM"] = "$$enum";
7
+ return DEFINED_DEFINITION_PROPERTY_TYPE2;
8
+ })(DEFINED_DEFINITION_PROPERTY_TYPE || {});
9
+ var ReferenceCategory = /* @__PURE__ */ ((ReferenceCategory2) => {
10
+ ReferenceCategory2["COMPONENTS"] = "components";
11
+ ReferenceCategory2["HOOKS"] = "hooks";
12
+ ReferenceCategory2["REST"] = "rest";
13
+ ReferenceCategory2["GRAPHQL"] = "graphql";
14
+ ReferenceCategory2["FUNCTIONS"] = "functions";
15
+ return ReferenceCategory2;
16
+ })(ReferenceCategory || {});
17
+ var ReferenceType = /* @__PURE__ */ ((ReferenceType2) => {
18
+ ReferenceType2["COMPONENT"] = "component";
19
+ ReferenceType2["HOOK"] = "hook";
20
+ ReferenceType2["REST_HTTP_GET"] = "rest_get";
21
+ ReferenceType2["REST_HTTP_POST"] = "rest_post";
22
+ ReferenceType2["REST_HTTP_PUT"] = "rest_put";
23
+ ReferenceType2["REST_HTTP_PATCH"] = "rest_patch";
24
+ ReferenceType2["REST_HTTP_DELETE"] = "rest_delete";
25
+ ReferenceType2["REST_HTTP_OPTIONS"] = "rest_options";
26
+ ReferenceType2["REST_HTTP_HEAD"] = "rest_head";
27
+ ReferenceType2["REST_HTTP_TRACE"] = "rest_trace";
28
+ ReferenceType2["REST_COMPONENT_SCHEMA"] = "rest_component_schema";
29
+ ReferenceType2["GRAPHQL_QUERY"] = "graphql_query";
30
+ ReferenceType2["GRAPHQL_MUTATION"] = "graphql_mutation";
31
+ ReferenceType2["GRAPHQL_SUBSCRIPTION"] = "graphql_subscription";
32
+ ReferenceType2["GRAPHQL_SCALAR"] = "graphql_scalar";
33
+ ReferenceType2["GRAPHQL_OBJECT"] = "graphql_object";
34
+ ReferenceType2["GRAPHQL_INTERFACE"] = "graphql_interface";
35
+ ReferenceType2["GRAPHQL_UNION"] = "graphql_union";
36
+ ReferenceType2["GRAPHQL_ENUM"] = "graphql_enum";
37
+ ReferenceType2["GRAPHQL_INPUT"] = "graphql_input";
38
+ ReferenceType2["FUNCTION_JS"] = "function_js";
39
+ return ReferenceType2;
40
+ })(ReferenceType || {});
41
+
42
+ // src/index.ts
43
+ function uniform(references, config) {
44
+ const response = {
45
+ references,
46
+ out: {}
47
+ };
48
+ config.plugins.forEach((plugin) => {
49
+ let defer = void 0;
50
+ const call = plugin({
51
+ references,
52
+ defer: (cb) => {
53
+ if (typeof cb === "function") {
54
+ defer = cb;
55
+ }
56
+ }
57
+ // visit: (pattern, callback) => {
58
+ // }
59
+ });
60
+ references.map((ref, i) => {
61
+ call(ref, {
62
+ index: i
63
+ });
64
+ });
65
+ if (typeof defer === "function") {
66
+ const resp = defer();
67
+ if (typeof resp !== "object") {
68
+ throw new Error(`Invalid callback return type: ${typeof resp}`);
69
+ }
70
+ response.out = {
71
+ ...response.out,
72
+ ...resp
73
+ };
74
+ }
75
+ });
76
+ return response;
77
+ }
78
+
79
+ // src/plugins/pluginJsonView.ts
80
+ function pluginJsonView(options) {
81
+ return function pluginJsonViewInner({
82
+ defer
83
+ }) {
84
+ const jsonViews = [];
85
+ defer(() => ({
86
+ jsonViews
87
+ }));
88
+ return (ref) => {
89
+ const lines = [];
90
+ lines.push("{");
91
+ ref.definitions.forEach((def) => {
92
+ def.properties.forEach((prop, index) => {
93
+ var _a;
94
+ const value = (((_a = prop.examples) == null ? void 0 : _a[0]) || "").replace(/^"|"$|[^a-zA-Z0-9\s\-_.,:/@#=;+()]/g, "");
95
+ const comment = prop.examples && prop.examples.length > 1 ? ` // or "${prop.examples[1].replace(/^"|"$|[^a-zA-Z0-9\s\-_.,:/@#=;+()]/g, "")}"` : "";
96
+ const isLast = index === def.properties.length - 1;
97
+ lines.push(` "${prop.name}": "${value}"${isLast ? "" : ","}${comment}`);
98
+ });
99
+ });
100
+ lines.push("}");
101
+ jsonViews.push(lines.join("\n"));
102
+ };
103
+ };
104
+ }
105
+
106
+ // src/plugins/pluginNavigation.ts
107
+ import path from "path";
108
+ var DEFAULT_VIRTUAL_FOLDER = ".xyd/.cache/.content";
109
+ var DEFAULT_GROUP_NAME = "API Reference";
110
+ function pluginNavigation(settings, options) {
111
+ if (!options.urlPrefix) {
112
+ throw new Error("urlPrefix is required");
113
+ }
114
+ return function pluginNavigationInner({
115
+ defer
116
+ }) {
117
+ const pageFrontMatter = {};
118
+ const groupMaps = {};
119
+ defer(() => ({
120
+ pageFrontMatter,
121
+ sidebar: convertGroupMapsToSidebar(settings, groupMaps)
122
+ }));
123
+ return (ref) => {
124
+ const dataCtx = ref.context;
125
+ const pagePath = path.join(options.urlPrefix, ref.canonical);
126
+ let group = (dataCtx == null ? void 0 : dataCtx.group) || [];
127
+ let title = ref.title;
128
+ if (pageFrontMatter[pagePath]) {
129
+ console.error("(pluginNavigation): pageFrontMatter[pagePath] already exists", pagePath);
130
+ }
131
+ if (!group) {
132
+ group = [options.defaultGroup || DEFAULT_GROUP_NAME];
133
+ }
134
+ pageFrontMatter[pagePath] = {
135
+ title
136
+ };
137
+ if (typeof group === "string") {
138
+ throw new Error("group as string is not supported yet");
139
+ }
140
+ group.reduce((groups, groupName, i) => {
141
+ if (!groups[groupName]) {
142
+ groups[groupName] = {
143
+ __groups: {},
144
+ pages: /* @__PURE__ */ new Set()
145
+ };
146
+ }
147
+ if (i === group.length - 1) {
148
+ groups[groupName].pages.add(pagePath);
149
+ }
150
+ return groups[groupName].__groups;
151
+ }, groupMaps);
152
+ };
153
+ };
154
+ }
155
+ function convertGroupMapsToSidebar(settings, groupMaps) {
156
+ const nav = [];
157
+ Object.keys(groupMaps).map((groupName) => {
158
+ const current = groupMaps[groupName];
159
+ const pages = [];
160
+ current.pages.forEach((page) => {
161
+ var _a, _b;
162
+ if ((_b = (_a = settings == null ? void 0 : settings.engine) == null ? void 0 : _a.uniform) == null ? void 0 : _b.store) {
163
+ pages.push(page);
164
+ return;
165
+ }
166
+ pages.push({
167
+ virtual: path.join(DEFAULT_VIRTUAL_FOLDER, page),
168
+ page
169
+ });
170
+ });
171
+ if (Object.keys(current.__groups).length) {
172
+ const subNav = {
173
+ group: groupName,
174
+ pages: convertGroupMapsToSidebar(settings, current.__groups)
175
+ };
176
+ nav.push(subNav);
177
+ return;
178
+ }
179
+ nav.push({
180
+ group: groupName,
181
+ pages
182
+ });
183
+ });
184
+ return nav;
185
+ }
186
+ export {
187
+ DEFINED_DEFINITION_PROPERTY_TYPE,
188
+ ReferenceCategory,
189
+ ReferenceType,
190
+ uniform as default,
191
+ pluginJsonView,
192
+ pluginNavigation
193
+ };
194
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts","../src/index.ts","../src/plugins/pluginJsonView.ts","../src/plugins/pluginNavigation.ts"],"sourcesContent":["import React from \"react\";\nimport {HighlightedCode} from \"codehike/code\";\n\n// TODO: type, and category also as generic?\nexport interface Reference<\n C = ReferenceContext,\n M extends DefinitionMeta = DefinitionMeta,\n VM extends DefinitionVariantMeta = DefinitionVariantMeta\n> {\n title: string;\n description: string | React.ReactNode;\n canonical: string;\n\n definitions: Definition<M, VM>[] // TODO: in the future from generic?\n examples: ExampleRoot\n\n\n category?: ReferenceCategory; // TODO: do we need that?\n\n type?: ReferenceType; // TODO: do we need that?\n\n context?: C;\n\n /**\n * TODO: !!!! BETTER !!!!\n * @internal\n */\n __UNSAFE_selector?: (selector: string) => any;\n}\n\nexport type DefinitionOpenAPIMeta = Meta<\"contentType\" | \"required\" | \"definitionDescription\">;\nexport type DefinitionTypeDocMeta = Meta<\"type\">;\nexport type DefinitionGraphqlMeta = Meta<\"type\" | \"graphqlName\">;\n\nexport type DefinitionMeta = DefinitionOpenAPIMeta | DefinitionTypeDocMeta | DefinitionGraphqlMeta\n\nexport type SymbolDef = {\n id?: string | string[];\n\n canonical?: string | string[];\n}\n\nexport interface Definition<\n M extends DefinitionMeta = DefinitionMeta,\n VM extends DefinitionVariantMeta = DefinitionVariantMeta\n> {\n title: string;\n\n properties: DefinitionProperty[];\n\n rootProperty?: DefinitionProperty\n\n variants?: DefinitionVariant<VM>[];\n\n description?: string | React.ReactNode;\n\n meta?: M[];\n\n /**\n * @internal\n */\n symbolDef?: SymbolDef;\n\n /**\n * @internal\n */\n id?: string;\n\n /**\n * @internal\n */\n type?: string;\n}\n\nexport type DefinitionVariantOpenAPIMeta = Meta<\"status\" | \"contentType\" | \"definitionDescription\" | \"required\">;\nexport type CommonDefinitionVariantMeta = Meta<\"symbolName\">;\n\nexport type DefinitionVariantMeta = CommonDefinitionVariantMeta | DefinitionVariantOpenAPIMeta\n\nexport interface DefinitionVariant<\n M extends DefinitionVariantMeta = DefinitionVariantMeta\n> {\n title: string;\n\n properties: DefinitionProperty[];\n\n rootProperty?: DefinitionProperty\n\n description?: string | React.ReactNode;\n\n symbolDef?: SymbolDef;\n\n meta?: M[];\n}\n\nexport interface Meta<T = string> {\n name: T;\n\n value?: unknown; // TODO: better type?\n}\n\nexport type DefinitionPropertyMeta = Meta<\"required\" | \"deprecated\" | \"internal\" | \"defaults\" | \"nullable\" | \"example\" | \"examples\" | \"minimum\" | \"maximum\" | \"enum-type\"> // TODO: better solution than enum-type?\n\nexport enum DEFINED_DEFINITION_PROPERTY_TYPE {\n UNION = \"$$union\",\n\n XOR = \"$$xor\",\n\n ARRAY = \"$$array\",\n\n ENUM = \"$$enum\",\n\n // TYPE = \"$$type\", TODO: good idea?\n}\n\nexport interface DefinitionProperty {\n name: string;\n\n type: string | DEFINED_DEFINITION_PROPERTY_TYPE\n\n description: string | React.ReactNode;\n\n // TODO: in the future more advanced examples?\n examples?: string | string[];\n\n symbolDef?: SymbolDef;\n\n meta?: DefinitionPropertyMeta[];\n\n context?: any // TODO: better type\n\n properties?: DefinitionProperty[];\n\n ofProperty?: DefinitionProperty;\n}\n\nexport interface ExampleRoot {\n groups: ExampleGroup[];\n}\n\nexport interface ExampleGroup {\n description?: string;\n\n examples: Example[];\n}\n\nexport interface Example {\n description?: string; // TODO: replace with title ?\n\n codeblock: CodeBlock;\n}\n\nexport interface CodeBlock {\n title?: string;\n\n tabs: CodeBlockTab[];\n}\n\nexport interface CodeBlockTab {\n // title of the tab e.g \"JavaScript\"\n title: string;\n\n // code in the tab e.g \"console.log('Hello World')\"\n code: string\n\n // language of the code e.g \"js\"\n language: string;\n\n // context of the generation method e.g openapi or graphql\n context?: ExampleContext;\n\n // TODO: highlighted code\n highlighted?: HighlightedCode;\n}\n\nexport type ExampleContext = GraphQLExampleContext | OpenAPIExampleContext;\n\n// TODO: concept only\nexport enum ReferenceCategory {\n // for React\n COMPONENTS = \"components\",\n HOOKS = \"hooks\",\n // end for React\n\n // for API\n REST = \"rest\",\n GRAPHQL = \"graphql\",\n // end for API\n\n // for code\n FUNCTIONS = \"functions\",\n //\n}\n\n// TODO: concept only\nexport enum ReferenceType {\n // for React\n COMPONENT = \"component\",\n HOOK = \"hook\",\n // end for React\n\n // for API\n // TODO: better type system for specific api typesl like gql or rest\n REST_HTTP_GET = \"rest_get\",\n REST_HTTP_POST = \"rest_post\",\n REST_HTTP_PUT = \"rest_put\",\n REST_HTTP_PATCH = \"rest_patch\",\n REST_HTTP_DELETE = \"rest_delete\",\n REST_HTTP_OPTIONS = \"rest_options\",\n REST_HTTP_HEAD = \"rest_head\",\n REST_HTTP_TRACE = \"rest_trace\",\n\n REST_COMPONENT_SCHEMA = \"rest_component_schema\",\n // ---\n GRAPHQL_QUERY = \"graphql_query\",\n GRAPHQL_MUTATION = \"graphql_mutation\",\n GRAPHQL_SUBSCRIPTION = \"graphql_subscription\",\n\n GRAPHQL_SCALAR = \"graphql_scalar\",\n GRAPHQL_OBJECT = \"graphql_object\",\n GRAPHQL_INTERFACE = \"graphql_interface\",\n GRAPHQL_UNION = \"graphql_union\",\n GRAPHQL_ENUM = \"graphql_enum\",\n GRAPHQL_INPUT = \"graphql_input\",\n // end for API\n\n // for code\n FUNCTION_JS = \"function_js\",\n // end for code\n}\n\nexport interface BaseReferenceContext {\n group?: string[];\n\n scopes?: string[];\n}\n\nexport interface GraphQLReferenceContext extends BaseReferenceContext {\n /**\n * @internal\n */\n graphqlTypeShort: string;\n\n graphqlName: string;\n}\n\n// TODO: custom value?\nexport interface OpenAPIReferenceContext extends BaseReferenceContext {\n method?: string;\n\n path?: string;\n\n fullPath?: string;\n\n componentSchema?: string\n}\n\nexport type TypeDocReferenceContextMeta = Meta<\"internal\">\n\n// Add TypeDocReferenceContext to the union type\nexport interface TypeDocReferenceContext extends BaseReferenceContext {\n symbolId: string;\n symbolName: string;\n symbolKind: number;\n packageName: string;\n fileName: string;\n fileFullPath: string;\n line: number;\n col: number;\n signatureText: {\n code: string;\n lang: string;\n };\n sourcecode: {\n code: string;\n lang: string;\n };\n category?: string;\n meta?: TypeDocReferenceContextMeta[]\n}\n\nexport type ReferenceContext = GraphQLReferenceContext | OpenAPIReferenceContext | TypeDocReferenceContext\n\nexport interface GraphQLExampleContext {\n schema?: any; // TODO:\n}\n\nexport interface OpenAPIExampleContext {\n status?: number;\n\n content?: string;\n}\n\n\n","// Define the new PluginV type with a callback function that returns another function\nimport {Reference} from \"./types\";\n\nexport * from \"./types\";\n\n// Define the new PluginV type with a callback function that returns another function\nexport type UniformPluginArgs = {\n references: Reference[] | Reference,\n defer: (defer: () => any) => void;\n\n // TODO: maybe in the future\n // visit: (selector: string | \"[method] [path]\", callback: (...args: any[]) => void) => void;\n}\n\n\nexport type UniformPluginRestArgs = {\n index: number;\n}\nexport type UniformPlugin<T> = (args: UniformPluginArgs) => (ref: Reference, restArgs: UniformPluginRestArgs) => void;\n\n// Utility type to infer if a type is an array and avoid wrapping it into an array twice\ntype NormalizeArray<T> = T extends Array<infer U> ? U[] : T;\n\n// Infer the return type of the plugin callback properly and normalize array types\ntype PluginResult<T extends UniformPlugin<any>> = T extends UniformPlugin<infer R> ? R : never;\n\n// Merge all plugin return types into a single object and normalize arrays\ntype MergePluginResults<T extends UniformPlugin<any>[]> = {\n [K in keyof UnionToIntersection<PluginResult<T[number]>>]: NormalizeArray<UnionToIntersection<PluginResult<T[number]>>[K]>\n};\n\n// Utility type to handle intersection to an object type\ntype UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;\n\n// Implement the uniform function\nexport default function uniform<T extends UniformPlugin<any>[]>(\n references: Reference[],\n config: { plugins: T }\n) {\n // Infer the merged result type from all plugins\n type ResultType = MergePluginResults<T>;\n\n // Initialize the response with a type-safe out object\n const response: {\n references: Reference[]\n out: { [K in keyof ResultType]: ResultType[K] }\n } = {\n references,\n out: {} as { [K in keyof ResultType]: ResultType[K] }\n };\n\n config.plugins.forEach((plugin) => {\n let defer: any = undefined; // fix any\n\n const call = plugin({\n references: references,\n defer: (cb) => {\n if (typeof cb === \"function\") {\n defer = cb\n }\n },\n // visit: (pattern, callback) => {\n // }\n })\n\n references.map((ref, i) => {\n call(ref, {\n index: i,\n })\n });\n\n if (typeof defer === \"function\") {\n const resp = defer()\n if (typeof resp !== \"object\") {\n throw new Error(`Invalid callback return type: ${typeof resp}`)\n }\n\n response.out = {\n ...response.out,\n ...resp\n }\n }\n })\n\n return response;\n}\n\n// Example usage\n// const examplePlugin: UniformPlugin<{ value: boolean }> = (cb) => {\n// return (ref: Reference) => {\n// };\n// };\n// function examplePlugin(defer: (defer: () => { value: boolean }) => void) {\n// defer(() => ({\n// value: true,\n// }));\n//\n// return (ref: Reference) => {\n//\n// };\n// }\n// const response = uniform([/* references */], {\n// plugins: [examplePlugin],\n// });\n// response.out\n","import type { UniformPluginArgs, UniformPlugin } from \"../index\";\nimport { Reference } from \"../types\";\n\nexport interface pluginJsonViewOptions {\n}\n\ntype pluginJsonViewOutput = {\n jsonViews: string;\n}\n\nexport function pluginJsonView(\n options?: pluginJsonViewOptions\n): UniformPlugin<pluginJsonViewOutput> {\n\n return function pluginJsonViewInner({\n defer,\n }: UniformPluginArgs) {\n const jsonViews: string[] = [];\n\n defer(() => ({\n jsonViews\n }))\n\n return (ref: Reference) => {\n // Build the output string manually to ensure exact format\n const lines: string[] = [];\n lines.push('{');\n \n ref.definitions.forEach(def => {\n def.properties.forEach((prop, index) => {\n // Remove any quotes and trailing characters from the value\n const value = (prop.examples?.[0] || '').replace(/^\"|\"$|[^a-zA-Z0-9\\s\\-_.,:/@#=;+()]/g, '');\n const comment = prop.examples && prop.examples.length > 1 \n ? ` // or \"${(prop.examples as string[])[1].replace(/^\"|\"$|[^a-zA-Z0-9\\s\\-_.,:/@#=;+()]/g, '')}\"`\n : '';\n const isLast = index === def.properties.length - 1;\n // Add comma after the value but before the comment\n lines.push(` \"${prop.name}\": \"${value}\"${isLast ? '' : ','}${comment}`);\n });\n });\n \n lines.push('}');\n \n jsonViews.push(lines.join('\\n'));\n }\n }\n}\n\n// example usage:\n// const response = uniform([/* references */], {\n// plugins: [pluginJsonView({\n// \n// })],\n// });\n","import path from 'node:path';\n\nimport type { Sidebar, Metadata, MetadataMap, Settings, PageURL } from \"@xyd-js/core\";\n\nimport type { UniformPluginArgs, UniformPlugin } from \"../index\";\nimport { CodeBlockTab, Example, ExampleGroup, Reference } from \"../types\";\n\nconst DEFAULT_VIRTUAL_FOLDER = \".xyd/.cache/.content\" // TODO: share this + .xyd/.build/.content for build\n\nconst DEFAULT_GROUP_NAME = \"API Reference\" // TODO: configurable\n\ntype GroupMap = {\n [key: string]: {\n __groups: GroupMap\n pages: Set<string>\n }\n}\n\nexport interface pluginNavigationOptions {\n urlPrefix: string\n defaultGroup?: string\n}\n\ntype pluginNavigationOutput = {\n pageFrontMatter: MetadataMap;\n sidebar: Sidebar[];\n}\n\nexport function pluginNavigation(\n settings: Settings,\n options: pluginNavigationOptions\n): UniformPlugin<pluginNavigationOutput> {\n if (!options.urlPrefix) {\n throw new Error(\"urlPrefix is required\")\n }\n\n return function pluginNavigationInner({\n defer,\n }: UniformPluginArgs) {\n const pageFrontMatter: MetadataMap = {}\n const groupMaps: GroupMap = {}\n\n defer(() => ({\n pageFrontMatter,\n sidebar: convertGroupMapsToSidebar(settings, groupMaps) as Sidebar[]\n }))\n\n return (ref: Reference) => {\n const dataCtx = ref.context\n const pagePath = path.join(options.urlPrefix, ref.canonical)\n\n let group = dataCtx?.group || []\n let title = ref.title\n\n if (pageFrontMatter[pagePath]) {\n console.error(\"(pluginNavigation): pageFrontMatter[pagePath] already exists\", pagePath)\n }\n\n if (!group) {\n group = [options.defaultGroup || DEFAULT_GROUP_NAME]\n }\n\n pageFrontMatter[pagePath] = {\n title,\n }\n\n if (typeof group === \"string\") {\n // TODO: seek nested group (it's not always from 0)\n throw new Error(\"group as string is not supported yet\")\n }\n\n group.reduce((groups: GroupMap, groupName: string, i: number) => {\n if (!groups[groupName]) {\n groups[groupName] = {\n __groups: {},\n pages: new Set()\n }\n }\n\n if (i === group.length - 1) {\n groups[groupName].pages.add(pagePath)\n }\n\n return groups[groupName].__groups\n }, groupMaps)\n }\n }\n}\n\nfunction convertGroupMapsToSidebar(settings: Settings, groupMaps: GroupMap): Sidebar[] {\n const nav: Sidebar[] = []\n\n Object.keys(groupMaps).map((groupName) => {\n const current = groupMaps[groupName]\n\n const pages: PageURL[] = []\n\n current.pages.forEach((page: string) => {\n if (settings?.engine?.uniform?.store) {\n pages.push(page)\n return\n }\n pages.push({\n virtual: path.join(DEFAULT_VIRTUAL_FOLDER, page),\n page: page,\n })\n })\n\n if (Object.keys(current.__groups).length) {\n const subNav: Sidebar = {\n group: groupName,\n pages: convertGroupMapsToSidebar(settings, current.__groups)\n }\n\n nav.push(subNav)\n\n return\n }\n\n nav.push({\n group: groupName,\n pages,\n })\n })\n\n return nav\n}\n\n// TODO: in the future xyd settings must be removed cuz uniform will be part of opendocs\n// example usage:\n// const response = uniform([/* references */], {\n// plugins: [pluginNavigation({}, {\n// urlPrefix: \"/docs\"\n// })],\n// });\n"],"mappings":";AAuGO,IAAK,mCAAL,kBAAKA,sCAAL;AACH,EAAAA,kCAAA,WAAQ;AAER,EAAAA,kCAAA,SAAM;AAEN,EAAAA,kCAAA,WAAQ;AAER,EAAAA,kCAAA,UAAO;AAPC,SAAAA;AAAA,GAAA;AA2EL,IAAK,oBAAL,kBAAKC,uBAAL;AAEH,EAAAA,mBAAA,gBAAa;AACb,EAAAA,mBAAA,WAAQ;AAIR,EAAAA,mBAAA,UAAO;AACP,EAAAA,mBAAA,aAAU;AAIV,EAAAA,mBAAA,eAAY;AAZJ,SAAAA;AAAA,GAAA;AAiBL,IAAK,gBAAL,kBAAKC,mBAAL;AAEH,EAAAA,eAAA,eAAY;AACZ,EAAAA,eAAA,UAAO;AAKP,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,oBAAiB;AACjB,EAAAA,eAAA,mBAAgB;AAChB,EAAAA,eAAA,qBAAkB;AAClB,EAAA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AA,IACJ;AAEA,QAAI,KAAK;AAAA,MACL,OAAO;AAAA,MACP;AAAA,IACJ,CAAC;AAAA,EACL,CAAC;AAED,SAAO;AACX;","names":["DEFINED_DEFINITION_PROPERTY_TYPE","ReferenceCategory","ReferenceType"]}
@@ -0,0 +1,302 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // markdown.ts
31
+ var markdown_exports = {};
32
+ __export(markdown_exports, {
33
+ compile: () => compile,
34
+ referenceAST: () => referenceAST
35
+ });
36
+ module.exports = __toCommonJS(markdown_exports);
37
+
38
+ // src/markdown/index.ts
39
+ var import_remark = require("remark");
40
+ var import_remark_stringify = __toESM(require("remark-stringify"), 1);
41
+
42
+ // src/markdown/utils.ts
43
+ var import_mdast_util_from_markdown = require("mdast-util-from-markdown");
44
+ var import_unist_builder = require("unist-builder");
45
+ var START_DEPTH_LEVEL = 2;
46
+ function root(ast) {
47
+ return (0, import_unist_builder.u)("root", ast);
48
+ }
49
+ function heading(title, canonical, description, refCategory, refType, refContext) {
50
+ const uTitle = (0, import_unist_builder.u)(
51
+ "heading",
52
+ { depth: START_DEPTH_LEVEL },
53
+ [(0, import_unist_builder.u)("text", `!!references ${title}`)]
54
+ );
55
+ const uCanonical = (0, import_unist_builder.u)(
56
+ "heading",
57
+ { depth: uTitle.depth + 1 },
58
+ [(0, import_unist_builder.u)("text", `!canonical ${canonical}`)]
59
+ );
60
+ let uDesc = [
61
+ (0, import_unist_builder.u)(
62
+ "heading",
63
+ { depth: uTitle.depth + 1 },
64
+ [(0, import_unist_builder.u)("text", `!description`)]
65
+ ),
66
+ (0, import_unist_builder.u)("paragraph", [(0, import_unist_builder.u)("text", description)])
67
+ ];
68
+ let uRefCategory;
69
+ if (refCategory) {
70
+ uRefCategory = (0, import_unist_builder.u)(
71
+ "heading",
72
+ { depth: uTitle.depth + 1 },
73
+ [(0, import_unist_builder.u)("text", `!category ${refCategory}`)]
74
+ );
75
+ }
76
+ let uRefType;
77
+ if (refType) {
78
+ uRefType = (0, import_unist_builder.u)(
79
+ "heading",
80
+ { depth: uTitle.depth + 1 },
81
+ [(0, import_unist_builder.u)("text", `!type ${refType}`)]
82
+ );
83
+ }
84
+ let uContext = [];
85
+ if (refContext && Object.keys(refContext)) {
86
+ uContext.push((0, import_unist_builder.u)(
87
+ "heading",
88
+ { depth: uTitle.depth + 1 },
89
+ [
90
+ (0, import_unist_builder.u)("text", `!context`)
91
+ ]
92
+ ));
93
+ for (const [key, value] of Object.entries(refContext)) {
94
+ if (typeof value === "object") {
95
+ if (value.code) {
96
+ uContext.push(
97
+ (0, import_unist_builder.u)("heading", { depth: uContext[0].depth + 1 }, [(0, import_unist_builder.u)("text", `!${key}`)])
98
+ );
99
+ uContext.push(
100
+ (0, import_unist_builder.u)("code", { lang: value.lang }, value.code)
101
+ );
102
+ continue;
103
+ }
104
+ }
105
+ uContext.push(
106
+ (0, import_unist_builder.u)("heading", { depth: uContext[0].depth + 1 }, [(0, import_unist_builder.u)("text", `!${key} ${value.toString()}`)])
107
+ );
108
+ }
109
+ }
110
+ return {
111
+ title: uTitle,
112
+ canonical: uCanonical,
113
+ description: uDesc,
114
+ category: uRefCategory || null,
115
+ type: uRefType || null,
116
+ context: uContext || null
117
+ };
118
+ }
119
+ function examples(examples2) {
120
+ const md = [];
121
+ const uExampleRoot = (0, import_unist_builder.u)(
122
+ "heading",
123
+ { depth: START_DEPTH_LEVEL + 1 },
124
+ [(0, import_unist_builder.u)("text", `!examples`)]
125
+ );
126
+ md.push(uExampleRoot);
127
+ examples2.groups.forEach((group) => {
128
+ const uExampleGroups = (0, import_unist_builder.u)(
129
+ "heading",
130
+ { depth: uExampleRoot.depth + 1 },
131
+ [(0, import_unist_builder.u)("text", `!!groups`)]
132
+ );
133
+ md.push(uExampleGroups);
134
+ const uGroupDescription = (0, import_unist_builder.u)(
135
+ "heading",
136
+ { depth: uExampleGroups.depth + 1 },
137
+ [(0, import_unist_builder.u)("text", `!description ${group.description}`)]
138
+ );
139
+ md.push(uGroupDescription);
140
+ group.examples.forEach((example) => {
141
+ const uExamples = (0, import_unist_builder.u)(
142
+ "heading",
143
+ { depth: uExampleGroups.depth + 1 },
144
+ [(0, import_unist_builder.u)("text", `!!examples`)]
145
+ );
146
+ md.push(uExamples);
147
+ const codeBlock = (0, import_unist_builder.u)(
148
+ "heading",
149
+ { depth: uExamples.depth + 1 },
150
+ [(0, import_unist_builder.u)("text", `!codeblock`)]
151
+ );
152
+ md.push(codeBlock);
153
+ const codeBlockTitle = (0, import_unist_builder.u)(
154
+ "heading",
155
+ { depth: codeBlock.depth + 1 },
156
+ [(0, import_unist_builder.u)("text", `!title ${example.codeblock.title}`)]
157
+ );
158
+ md.push(codeBlockTitle);
159
+ const tabs = (0, import_unist_builder.u)(
160
+ "heading",
161
+ { depth: codeBlock.depth + 1 },
162
+ [(0, import_unist_builder.u)("text", `!!tabs`)]
163
+ );
164
+ md.push(tabs);
165
+ example.codeblock.tabs.forEach((tab) => {
166
+ const code = (0, import_unist_builder.u)("code", {
167
+ lang: tab.language,
168
+ meta: `!code ${tab.title}`
169
+ }, tab.code);
170
+ md.push(code);
171
+ });
172
+ });
173
+ });
174
+ return md;
175
+ }
176
+ function definitions(definitions2) {
177
+ const md = [];
178
+ definitions2.forEach((definition) => {
179
+ const uDefinition = (0, import_unist_builder.u)(
180
+ "heading",
181
+ { depth: START_DEPTH_LEVEL + 1 },
182
+ [(0, import_unist_builder.u)("text", `!!definitions`)]
183
+ );
184
+ md.push(uDefinition);
185
+ md.push((0, import_unist_builder.u)(
186
+ "heading",
187
+ { depth: uDefinition.depth + 1 },
188
+ [(0, import_unist_builder.u)("text", `!title ${definition.title}`)]
189
+ ));
190
+ definition.properties.forEach((prop) => {
191
+ properties(
192
+ uDefinition.depth + 1,
193
+ {
194
+ name: prop.name,
195
+ type: prop.type,
196
+ description: prop.description,
197
+ context: prop.context,
198
+ properties: prop.properties
199
+ // TODO: fix ts
200
+ },
201
+ md
202
+ );
203
+ });
204
+ });
205
+ return md;
206
+ }
207
+ function properties(depth, props, output = []) {
208
+ const paramName = props.name;
209
+ const propTitle = `!!properties ${paramName}`;
210
+ const uPropTitle = (0, import_unist_builder.u)("heading", { depth }, [(0, import_unist_builder.u)("text", propTitle)]);
211
+ const uPropName = (0, import_unist_builder.u)("paragraph", { depth }, [(0, import_unist_builder.u)("text", `!name ${paramName}`)]);
212
+ const uPropType = (0, import_unist_builder.u)("paragraph", { depth }, [(0, import_unist_builder.u)("text", `!type ${props.type}`)]);
213
+ const markdownAst = (0, import_mdast_util_from_markdown.fromMarkdown)(props.description || "");
214
+ const uPropDesc = (0, import_unist_builder.u)("paragraph", { depth }, markdownAst.children);
215
+ const uContext = [];
216
+ if (props.context && Object.keys(props.context)) {
217
+ uContext.push((0, import_unist_builder.u)(
218
+ "heading",
219
+ { depth: depth + 1 },
220
+ [
221
+ (0, import_unist_builder.u)("text", `!context`)
222
+ ]
223
+ ));
224
+ for (const [key, value] of Object.entries(props.context)) {
225
+ uContext.push(
226
+ (0, import_unist_builder.u)(
227
+ "heading",
228
+ { depth: uContext[0].depth + 1 },
229
+ [(0, import_unist_builder.u)("text", `!${key} ${value}`)]
230
+ )
231
+ );
232
+ }
233
+ }
234
+ output.push(
235
+ uPropTitle,
236
+ uPropName,
237
+ uPropType,
238
+ uPropDesc,
239
+ ...uContext
240
+ );
241
+ if (props.properties) {
242
+ const deepDepth = depth + 1;
243
+ for (const prop of props.properties) {
244
+ properties(deepDepth, prop, output);
245
+ }
246
+ }
247
+ }
248
+
249
+ // src/markdown/index.ts
250
+ function compile(ast) {
251
+ return (0, import_remark.remark)().use(import_remark_stringify.default, {
252
+ bullet: "-",
253
+ fences: true,
254
+ listItemIndent: "one",
255
+ incrementListMarker: false,
256
+ handlers: {
257
+ heading(node) {
258
+ return `${"#".repeat(node.depth)} ${node.children[0].value}`;
259
+ }
260
+ }
261
+ }).stringify(root(ast));
262
+ }
263
+ function referenceAST(ref) {
264
+ var _a, _b;
265
+ const md = [];
266
+ const mdHeading = heading(
267
+ ref.title,
268
+ ref.canonical,
269
+ typeof ref.description === "string" ? ref.description : "",
270
+ ref.category,
271
+ ref.type,
272
+ ref.context
273
+ );
274
+ md.push(
275
+ mdHeading.title
276
+ );
277
+ if ((_a = mdHeading == null ? void 0 : mdHeading.description) == null ? void 0 : _a.length) {
278
+ md.push(...mdHeading.description);
279
+ }
280
+ md.push(
281
+ mdHeading.canonical
282
+ );
283
+ if (mdHeading.category) {
284
+ md.push(mdHeading.category);
285
+ }
286
+ if (mdHeading.type) {
287
+ md.push(mdHeading.type);
288
+ }
289
+ if ((_b = mdHeading == null ? void 0 : mdHeading.context) == null ? void 0 : _b.length) {
290
+ md.push(...mdHeading.context);
291
+ }
292
+ const mdExamples = examples(ref.examples);
293
+ const mdDefinitions = definitions(ref.definitions);
294
+ md.push(...mdExamples, ...mdDefinitions);
295
+ return md;
296
+ }
297
+ // Annotate the CommonJS export names for ESM import in node:
298
+ 0 && (module.exports = {
299
+ compile,
300
+ referenceAST
301
+ });
302
+ //# sourceMappingURL=markdown.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../markdown.ts","../src/markdown/index.ts","../src/markdown/utils.ts"],"sourcesContent":["export * from \"./src/markdown/index\";\n","import {remark} from \"remark\";\nimport remarkStringify from \"remark-stringify\";\n\nimport {Reference} from \"../types\";\n\nimport {definitions, examples, heading, root} from \"./utils\";\n\n// TODO: any\nexport function compile(ast: any) {\n return remark()\n // .use(unlimitedHeadings)\n .use(remarkStringify, {\n bullet: '-',\n fences: true,\n listItemIndent: 'one',\n incrementListMarker: false,\n handlers: {\n heading(node) {\n return `${\"#\".repeat(node.depth)} ${node.children[0].value}`;\n },\n },\n })\n .stringify(root(ast));\n}\n\nexport function referenceAST(ref: Reference) {\n const md = []\n\n const mdHeading = heading(\n ref.title,\n ref.canonical,\n typeof ref.description === \"string\" ? ref.description : \"\",\n ref.category,\n ref.type,\n ref.context\n )\n\n md.push(\n mdHeading.title,\n )\n\n if (mdHeading?.description?.length) {\n md.push(...mdHeading.description)\n }\n\n md.push(\n mdHeading.canonical,\n )\n\n if (mdHeading.category) {\n md.push(mdHeading.category)\n }\n\n if (mdHeading.type) {\n md.push(mdHeading.type)\n }\n\n if (mdHeading?.context?.length) {\n md.push(...mdHeading.context)\n }\n\n const mdExamples = examples(ref.examples)\n const mdDefinitions = definitions(ref.definitions)\n md.push(...mdExamples, ...mdDefinitions)\n\n return md;\n}\n","import { fromMarkdown } from \"mdast-util-from-markdown\";\nimport {u} from \"unist-builder\";\n\nimport {\n ExampleRoot,\n Definition,\n ReferenceCategory,\n ReferenceContext,\n ReferenceType,\n DefinitionProperty\n} from \"../types\";\n\n// START_DEPTH_LEVEL is the start depth level for the markdown AST\n// starts from 2 because 1 is reserved for the title\nconst START_DEPTH_LEVEL = 2\n\n// TODO: fix any\nexport function root(ast: any) {\n return u('root', ast);\n}\n\nexport function heading(\n title: string,\n canonical: string,\n description: string,\n refCategory?: ReferenceCategory,\n refType?: ReferenceType,\n refContext?: ReferenceContext\n) {\n const uTitle = u(\n 'heading',\n {depth: START_DEPTH_LEVEL},\n [u('text', `!!references ${title}`)]\n )\n\n const uCanonical = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!canonical ${canonical}`)]\n )\n\n let uDesc = [\n u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!description`),]\n ),\n u('paragraph', [u('text', description)])\n ]\n\n let uRefCategory\n if (refCategory) {\n uRefCategory = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!category ${refCategory}`)]\n )\n }\n\n let uRefType\n if (refType) {\n uRefType = u(\n 'heading',\n {depth: uTitle.depth + 1},\n [u('text', `!type ${refType}`)]\n )\n }\n\n let uContext = []\n\n if (refContext && Object.keys(refContext)) {\n uContext.push(u(\n 'heading',\n {depth: uTitle.depth + 1},\n [\n u('text', `!context`),\n ]\n ))\n\n\n for (const [key, value] of Object.entries(refContext)) {\n if (typeof value === \"object\") {\n // TODO: support ```<lang> ??\n if (value.code) {\n uContext.push(\n u('heading', {depth: uContext[0].depth + 1}, [u('text', `!${key}`)])\n );\n\n uContext.push(\n u('code', {lang: value.lang}, value.code)\n );\n\n continue;\n }\n }\n\n uContext.push(\n u('heading', {depth: uContext[0].depth + 1}, [u('text', `!${key} ${value.toString()}`)])\n );\n }\n }\n\n return {\n title: uTitle,\n canonical: uCanonical,\n description: uDesc,\n category: uRefCategory || null,\n type: uRefType || null,\n context: uContext || null\n }\n}\n\nexport function examples(examples: ExampleRoot) {\n const md = []\n\n const uExampleRoot = u(\n 'heading',\n {depth: START_DEPTH_LEVEL + 1},\n [u('text', `!examples`)]\n )\n md.push(uExampleRoot)\n\n examples.groups.forEach(group => {\n const uExampleGroups = u(\n 'heading',\n {depth: uExampleRoot.depth + 1},\n [u('text', `!!groups`)]\n )\n md.push(uExampleGroups)\n\n const uGroupDescription = u(\n 'heading',\n {depth: uExampleGroups.depth + 1},\n [u('text', `!description ${group.description}`)]\n )\n md.push(uGroupDescription)\n\n group.examples.forEach(example => {\n const uExamples = u(\n 'heading',\n {depth: uExampleGroups.depth + 1},\n [u('text', `!!examples`)]\n )\n md.push(uExamples)\n\n const codeBlock = u(\n 'heading',\n {depth: uExamples.depth + 1},\n [u('text', `!codeblock`)]\n )\n md.push(codeBlock)\n\n const codeBlockTitle = u(\n 'heading',\n {depth: codeBlock.depth + 1},\n [u('text', `!title ${example.codeblock.title}`)]\n )\n md.push(codeBlockTitle)\n\n const tabs = u(\n 'heading',\n {depth: codeBlock.depth + 1},\n [u('text', `!!tabs`)]\n )\n md.push(tabs)\n\n example.codeblock.tabs.forEach(tab => {\n const code = u('code', {\n lang: tab.language,\n meta: `!code ${tab.title}`\n }, tab.code);\n\n md.push(code)\n })\n\n })\n })\n\n return md\n}\n\nexport function definitions(definitions: Definition[]) {\n const md: any[] = []\n\n definitions.forEach(definition => {\n const uDefinition = u(\n 'heading',\n {depth: START_DEPTH_LEVEL + 1},\n [u('text', `!!definitions`)]\n )\n md.push(uDefinition)\n\n md.push(u(\n 'heading',\n {depth: uDefinition.depth + 1},\n [u('text', `!title ${definition.title}`)]\n ))\n\n definition.properties.forEach(prop => {\n properties(\n uDefinition.depth + 1,\n {\n name: prop.name,\n type: prop.type,\n description: prop.description,\n context: prop.context,\n properties: prop.properties // TODO: fix ts\n },\n md,\n )\n })\n })\n\n return md\n}\n\n// TODO: any[]\nexport function properties(\n depth: number,\n props: DefinitionProperty,\n output: any[] = []\n) {\n const paramName = props.name;\n\n const propTitle = `!!properties ${paramName}`; // TODO: check if `!!properties is enough`\n const uPropTitle = u('heading', {depth}, [u('text', propTitle)]);\n const uPropName = u('paragraph', {depth}, [u('text', `!name ${paramName}`)]);\n const uPropType = u('paragraph', {depth}, [u('text', `!type ${props.type}`)]);\n const markdownAst = fromMarkdown(props.description || '');\n const uPropDesc = u(\"paragraph\", { depth }, markdownAst.children);\n const uContext = []\n\n if (props.context && Object.keys(props.context)) {\n uContext.push(u(\n 'heading',\n {depth: depth + 1},\n [\n u('text', `!context`),\n ]\n ))\n\n for (const [key, value] of Object.entries(props.context)) {\n uContext.push(u(\n 'heading',\n {depth: uContext[0].depth + 1},\n [u('text', `!${key} ${value}`)]\n )\n )\n }\n }\n\n output.push(\n uPropTitle,\n uPropName,\n uPropType,\n uPropDesc,\n ...uContext\n );\n\n if (props.properties) {\n const deepDepth = depth + 1\n\n for (const prop of props.properties) {\n properties(deepDepth, prop, output)\n }\n }\n}\n\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAqB;AACrB,8BAA4B;;;ACD5B,sCAA6B;AAC7B,2BAAgB;AAahB,IAAM,oBAAoB;AAGnB,SAAS,KAAK,KAAU;AAC3B,aAAO,wBAAE,QAAQ,GAAG;AACxB;AAEO,SAAS,QACZ,OACA,WACA,aACA,aACA,SACA,YACF;AACE,QAAM,aAAS;AAAA,IACX;AAAA,IACA,EAAC,OAAO,kBAAiB;AAAA,IACzB,KAAC,wBAAE,QAAQ,gBAAgB,KAAK,EAAE,CAAC;AAAA,EACvC;AAEA,QAAM,iBAAa;AAAA,IACf;AAAA,IACA,EAAC,OAAO,OAAO,QAAQ,EAAC;AAAA,IACxB,KAAC,wBAAE,QAAQ,cAAc,SAAS,EAAE,CAAC;AAAA,EACzC;AAEA,MAAI,QAAQ;AAAA,QACR;AAAA,MACI;AAAA,MACA,EAAC,OAAO,OAAO,QAAQ,EAAC;AAAA,MACxB,KAAC,wBAAE,QAAQ,cAAc,CAAE;AAAA,IAC/B;AAAA,QACA,wBAAE,aAAa,KAAC,wBAAE,QAAQ,WAAW,CAAC,CAAC;AAAA,EAC3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O,GAAG,IAAI,OAAO,KAAK,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,EAAE,KAAK;AAAA,MAC9D;AAAA,IACJ;AAAA,EACJ,CAAC,EACA,UAAU,KAAK,GAAG,CAAC;AAC5B;AAEO,SAAS,aAAa,KAAgB;AAzB7C;AA0BI,QAAM,KAAK,CAAC;AAEZ,QAAM,YAAY;AAAA,IACd,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,OAAO,IAAI,gBAAgB,WAAW,IAAI,cAAc;AAAA,IACxD,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,EACR;AAEA,KAAG;AAAA,IACC,UAAU;AAAA,EACd;AAEA,OAAI,4CAAW,gBAAX,mBAAwB,QAAQ;AAChC,OAAG,KAAK,GAAG,UAAU,WAAW;AAAA,EACpC;AAEA,KAAG;AAAA,IACC,UAAU;AAAA,EACd;AAEA,MAAI,UAAU,UAAU;AACpB,OAAG,KAAK,UAAU,QAAQ;AAAA,EAC9B;AAEA,MAAI,UAAU,MAAM;AAChB,OAAG,KAAK,UAAU,IAAI;AAAA,EAC1B;AAEA,OAAI,4CAAW,YAAX,mBAAoB,QAAQ;AAC5B,OAAG,KAAK,GAAG,UAAU,OAAO;AAAA,EAChC;AAEA,QAAM,aAAa,SAAS,IAAI,QAAQ;AACxC,QAAM,gBAAgB,YAAY,IAAI,WAAW;AACjD,KAAG,KAAK,GAAG,YAAY,GAAG,aAAa;AAEvC,SAAO;AACX;","names":["examples","definitions","remarkStringify"]}
@@ -0,0 +1,8 @@
1
+ import { R as Reference } from './types-BiglsETJ.cjs';
2
+ import 'react';
3
+ import 'codehike/code';
4
+
5
+ declare function compile(ast: any): string;
6
+ declare function referenceAST(ref: Reference): any[];
7
+
8
+ export { compile, referenceAST };
@@ -0,0 +1,8 @@
1
+ import { R as Reference } from './types-BiglsETJ.js';
2
+ import 'react';
3
+ import 'codehike/code';
4
+
5
+ declare function compile(ast: any): string;
6
+ declare function referenceAST(ref: Reference): any[];
7
+
8
+ export { compile, referenceAST };