@xyd-js/sources 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.
Files changed (97) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/ISSUES.md +10 -0
  3. package/LICENSE +21 -0
  4. package/README.md +3 -0
  5. package/TODO.md +9 -0
  6. package/__fixtures__/-1.typescript/package.json +5 -0
  7. package/__fixtures__/-1.typescript/src/index.ts +0 -0
  8. package/__fixtures__/-1.typescript/src/settings.ts +592 -0
  9. package/__fixtures__/-1.typescript/tsconfig.json +8 -0
  10. package/__fixtures__/-2.react.basic/1.flat-interface.output.json +114 -0
  11. package/__fixtures__/-2.react.basic/2.file-connect-interface.output.json +60 -0
  12. package/__fixtures__/-2.react.basic/2a.file-connect-interface-advanced.output.json +92 -0
  13. package/__fixtures__/-2.react.basic/3.props-as-variants.output.json +166 -0
  14. package/__fixtures__/-2.react.basic/4.outside-interface.output.json +60 -0
  15. package/__fixtures__/-2.react.basic/5.inline-props.output.json +60 -0
  16. package/__fixtures__/-2.react.basic/5.outside-inline-props.output.json +60 -0
  17. package/__fixtures__/-2.react.basic/5a.inline-props+outside.output.json +60 -0
  18. package/__fixtures__/-2.react.basic/5b.inline-props+interfaces.output.json +92 -0
  19. package/__fixtures__/-2.react.basic/package.json +4 -0
  20. package/__fixtures__/-2.react.basic/src/1.flat-interface.tsx +41 -0
  21. package/__fixtures__/-2.react.basic/src/2.file-connect-interface.tsx +28 -0
  22. package/__fixtures__/-2.react.basic/src/2a.file-connect-interace+advanced.tsx +54 -0
  23. package/__fixtures__/-2.react.basic/src/3.props-as-variants.tsx +67 -0
  24. package/__fixtures__/-2.react.basic/src/4.outside-interface.tsx +13 -0
  25. package/__fixtures__/-2.react.basic/src/4.outside-interface2.ts +15 -0
  26. package/__fixtures__/-2.react.basic/src/5.inline-props.tsx +19 -0
  27. package/__fixtures__/-2.react.basic/src/5a.inline-props+outside.tsx +19 -0
  28. package/__fixtures__/-2.react.basic/src/5b.inline-props+interfaces.tsx +62 -0
  29. package/__fixtures__/-2.react.basic/src/index.ts +0 -0
  30. package/__fixtures__/-2.react.basic/tsconfig.json +8 -0
  31. package/__tests__/sourcesToUniform.test.ts +167 -0
  32. package/__tests__/testResolvePropertySymbol.ts +838 -0
  33. package/__tests__/types.ts +12 -0
  34. package/__tests__/utils.ts +108 -0
  35. package/dist/index.cjs +2 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.cts +2 -0
  38. package/dist/index.d.ts +2 -0
  39. package/dist/index.js +1 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/react.cjs +237 -0
  42. package/dist/react.cjs.map +1 -0
  43. package/dist/react.d.cts +6 -0
  44. package/dist/react.d.ts +6 -0
  45. package/dist/react.js +212 -0
  46. package/dist/react.js.map +1 -0
  47. package/dist/ts.cjs +1794 -0
  48. package/dist/ts.cjs.map +1 -0
  49. package/dist/ts.d.cts +14 -0
  50. package/dist/ts.d.ts +14 -0
  51. package/dist/ts.js +1760 -0
  52. package/dist/ts.js.map +1 -0
  53. package/package.json +41 -0
  54. package/packages/react/index.ts +1 -0
  55. package/packages/react/uniformToReactUniform.ts +275 -0
  56. package/packages/ts/SignatureText.ts +233 -0
  57. package/packages/ts/TypeDocTransformer.ts +1519 -0
  58. package/packages/ts/__fixtures__/packages/package-a/package.json +4 -0
  59. package/packages/ts/__fixtures__/packages/package-a/src/index.ts +56 -0
  60. package/packages/ts/__fixtures__/packages/package-a/tsconfig.json +23 -0
  61. package/packages/ts/__fixtures__/packages/package-b/package.json +7 -0
  62. package/packages/ts/__fixtures__/packages/package-b/src/billing.ts +193 -0
  63. package/packages/ts/__fixtures__/packages/package-b/src/index.ts +8 -0
  64. package/packages/ts/__fixtures__/packages/package-b/tsconfig.json +20 -0
  65. package/packages/ts/__fixtures__/packages2/package-a/package.json +4 -0
  66. package/packages/ts/__fixtures__/packages2/package-a/src/index.ts +496 -0
  67. package/packages/ts/__fixtures__/packages2/package-a/tsconfig.json +6 -0
  68. package/packages/ts/__fixtures__/packages3/package-a/package.json +4 -0
  69. package/packages/ts/__fixtures__/packages3/package-a/src/index.ts +488 -0
  70. package/packages/ts/__fixtures__/packages3/package-a/tsconfig.json +6 -0
  71. package/packages/ts/__fixtures__/packages3/project.json +171 -0
  72. package/packages/ts/__fixtures__/react/react-a/package.json +5 -0
  73. package/packages/ts/__fixtures__/react/react-a/src/TestAbc.tsx +90 -0
  74. package/packages/ts/__fixtures__/react/react-a/src/TestBasic.tsx +27 -0
  75. package/packages/ts/__fixtures__/react/react-a/src/TestNamedParameters.tsx +27 -0
  76. package/packages/ts/__fixtures__/react/react-a/src/TestNamedParameters2.tsx +26 -0
  77. package/packages/ts/__fixtures__/react/react-a/src/TestUnion.tsx +32 -0
  78. package/packages/ts/__fixtures__/react/react-a/src/index.ts +1 -0
  79. package/packages/ts/__fixtures__/react/react-a/tsconfig.json +8 -0
  80. package/packages/ts/__fixtures__/references-output-project.json +344 -0
  81. package/packages/ts/__fixtures__/references-output-react.json +68 -0
  82. package/packages/ts/__fixtures__/references-output.json +129 -0
  83. package/packages/ts/__tests__/sourcesToUniform.test.ts +106 -0
  84. package/packages/ts/context.ts +0 -0
  85. package/packages/ts/converterts/ts-class.ts +0 -0
  86. package/packages/ts/converterts/ts-enum.ts +0 -0
  87. package/packages/ts/converterts/ts-function.ts +0 -0
  88. package/packages/ts/converterts/ts-interface.ts +0 -0
  89. package/packages/ts/converterts/ts-type.ts +0 -0
  90. package/packages/ts/index.ts +129 -0
  91. package/packages/ts/ts-core.ts +0 -0
  92. package/packages/ts/uniformToMiniUniform.ts +486 -0
  93. package/src/index.ts +0 -0
  94. package/test-cmd/index.ts +62 -0
  95. package/tsconfig.json +38 -0
  96. package/tsup.config.ts +39 -0
  97. package/vitest.config.ts +34 -0
@@ -0,0 +1,12 @@
1
+ export interface Test {
2
+ id: string
3
+ file: string;
4
+ description: string;
5
+ react?: boolean;
6
+ miniUniformRoot?: string;
7
+ entryPoints?: string[];
8
+ forceSave?: boolean;
9
+ saveUniform?: boolean;
10
+ saveTypedoc?: boolean;
11
+ multiOutput?: boolean;
12
+ }
@@ -0,0 +1,108 @@
1
+ import * as path from "node:path";
2
+ import * as fs from "node:fs";
3
+
4
+ import {expect} from "vitest";
5
+
6
+ import type {Test} from "./types";
7
+ import {sourcesToUniformV2, uniformToMiniUniform} from "../packages/ts";
8
+ import {Reference, TypeDocReferenceContext} from "@xyd-js/uniform";
9
+ import {uniformToReactUniform} from "../packages/react";
10
+
11
+ // Helper function to run a test with a specific fixture
12
+ export async function testSourcesToUniform(test: Test) {
13
+ const {
14
+ id: fixtureName,
15
+ file: fixtureFile,
16
+ } = test;
17
+ const fixtureRoot = fullFixturePath(fixtureFile);
18
+
19
+ const resp = await sourcesToUniformV2(fixtureRoot,
20
+ test.entryPoints || [],
21
+ );
22
+ if (!resp || !resp.references || !resp.projectJson) {
23
+ throw new Error("Failed to generate documentation.")
24
+ }
25
+
26
+ if (resp.projectJson && test.saveTypedoc) {
27
+ const typedocOutputPath = fullFixturePath(path.join(fixtureFile, `${fixtureName}.output.typedoc.json`));
28
+ fs.writeFileSync(typedocOutputPath, JSON.stringify(resp.projectJson, null, 2));
29
+ }
30
+
31
+ let result: Reference[]
32
+ {
33
+ const references = resp.references as Reference<TypeDocReferenceContext>[]
34
+ const referencesCopy = JSON.parse(JSON.stringify(references));
35
+ if (test.react) {
36
+ const reactUniform = uniformToReactUniform(references, resp.projectJson)
37
+ result = reactUniform;
38
+ } else if (test.miniUniformRoot) {
39
+ const miniUniform = uniformToMiniUniform(test.miniUniformRoot, references)
40
+ result = miniUniform;
41
+ } else {
42
+ result = resp.references;
43
+ }
44
+
45
+ if (test.saveUniform) {
46
+ saveResultAsOutput(fixtureFile, fixtureName, referencesCopy, test.multiOutput || false, true);
47
+ }
48
+ }
49
+
50
+ if (test.forceSave) {
51
+ saveResultAsOutput(fixtureFile, fixtureName, result, test.multiOutput || false);
52
+ }
53
+
54
+ const expectedOutput = readFixtureOutput(fixtureFile, fixtureName, test.multiOutput || false);
55
+
56
+ try {
57
+ expect(result).toEqual(expectedOutput);
58
+ } catch (error) {
59
+ if (result?.length > 100) {
60
+ throw new Error(`FAILED: The diff result is too long (${result.length} items) to show.`);
61
+ }
62
+ throw error;
63
+ }
64
+ }
65
+
66
+ // Helper function to read fixture output
67
+ function readFixtureOutput(
68
+ fixtureBasePath: string,
69
+ fixtureName: string,
70
+ multiOutput: boolean,
71
+ ) {
72
+ const name = outputName(fixtureName, multiOutput, false);
73
+ const fixturePath = fullFixturePath(path.join(fixtureBasePath, name));
74
+
75
+ return JSON.parse(fs.readFileSync(fixturePath, "utf8"));
76
+ }
77
+
78
+ function fullFixturePath(name: string) {
79
+ return path.join(__dirname, "../__fixtures__", name);
80
+ }
81
+
82
+ function saveResultAsOutput(fixtureBasePath: string, fixtureName: string, result: any, multiOutput: boolean, uniform?: boolean) {
83
+ const name = outputName(fixtureName, multiOutput, uniform);
84
+ const fixturePath = fullFixturePath(path.join(fixtureBasePath, name));
85
+
86
+ fs.writeFileSync(fixturePath, JSON.stringify(result, null, 2));
87
+ }
88
+
89
+ function outputName(
90
+ fixtureName: string,
91
+ multiOutput: boolean,
92
+ uniform?: boolean,
93
+ ) {
94
+ let name = "";
95
+ if (multiOutput) {
96
+ name = `${fixtureName}.output.json`;
97
+ if (uniform) {
98
+ name = `${fixtureName}.output.uniform.json`;
99
+ }
100
+ } else {
101
+ name = name || "output.json";
102
+ if (uniform) {
103
+ name = "output.uniform.json";
104
+ }
105
+ }
106
+
107
+ return name;
108
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1,2 @@
1
+
2
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/react.cjs ADDED
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/react/index.ts
21
+ var react_exports = {};
22
+ __export(react_exports, {
23
+ uniformToReactUniform: () => uniformToReactUniform
24
+ });
25
+ module.exports = __toCommonJS(react_exports);
26
+
27
+ // packages/react/uniformToReactUniform.ts
28
+ var import_typedoc = require("typedoc");
29
+ var import_uniform = require("@xyd-js/uniform");
30
+ var TXT = {
31
+ Props: "Props",
32
+ Component: "Component"
33
+ };
34
+ function uniformToReactUniform(references, projectJson) {
35
+ const output = [];
36
+ let refBySymbolId = {};
37
+ for (const reference of references) {
38
+ const ctx = reference.context;
39
+ if (ctx == null ? void 0 : ctx.symbolId) {
40
+ refBySymbolId[ctx.symbolId] = reference;
41
+ }
42
+ }
43
+ for (const reference of references) {
44
+ const ctx = reference.context;
45
+ if ((ctx == null ? void 0 : ctx.category) !== "Component") {
46
+ console.warn(`skipping non-component: ${ctx == null ? void 0 : ctx.symbolName}`);
47
+ continue;
48
+ }
49
+ const reactRef = {
50
+ ...reference,
51
+ title: (ctx == null ? void 0 : ctx.symbolName) || reference.title,
52
+ canonical: reactCanonical(reference.canonical),
53
+ context: {
54
+ ...ctx,
55
+ group: reactGroup((ctx == null ? void 0 : ctx.group) || [])
56
+ },
57
+ definitions: []
58
+ };
59
+ for (const def of reference.definitions) {
60
+ if (!def.meta) {
61
+ continue;
62
+ }
63
+ let isParamDefinition = false;
64
+ for (let meta of def.meta) {
65
+ if (meta.name === "type" && meta.value === "parameters") {
66
+ isParamDefinition = true;
67
+ break;
68
+ }
69
+ }
70
+ if (!isParamDefinition) {
71
+ continue;
72
+ }
73
+ const reactDef = {
74
+ ...def,
75
+ title: TXT.Props,
76
+ properties: []
77
+ };
78
+ definitionReactPropsPassThrough(
79
+ refBySymbolId,
80
+ def.properties || [],
81
+ reactDef
82
+ );
83
+ reactRef.definitions.push(reactDef);
84
+ }
85
+ output.push(reactRef);
86
+ }
87
+ return output;
88
+ }
89
+ function definitionReactPropsPassThrough(refBySymbolId, defProperties, reactDef, options) {
90
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
91
+ for (const property of defProperties) {
92
+ if (property.type === import_uniform.DEFINED_DEFINITION_PROPERTY_TYPE.UNION && !((_a = property == null ? void 0 : property.symbolDef) == null ? void 0 : _a.id)) {
93
+ definitionReactPropsPassThrough(
94
+ refBySymbolId,
95
+ property.properties || [],
96
+ reactDef,
97
+ {
98
+ paramProps: true
99
+ }
100
+ );
101
+ continue;
102
+ }
103
+ const symbolId = (_b = property.symbolDef) == null ? void 0 : _b.id;
104
+ if (typeof symbolId != "string") {
105
+ if (options == null ? void 0 : options.paramProps) {
106
+ reactDef.properties.push(property);
107
+ continue;
108
+ }
109
+ console.error(`symbolId is not a string: ${symbolId}`);
110
+ continue;
111
+ }
112
+ if (!symbolId) {
113
+ if (property.type === "param" && ((_c = property.properties) == null ? void 0 : _c.length)) {
114
+ reactDef.properties = property.properties;
115
+ }
116
+ continue;
117
+ }
118
+ const refSymbol = refBySymbolId[symbolId];
119
+ if (!refSymbol) {
120
+ console.error(`Reference for symbol ${symbolId} not found`);
121
+ continue;
122
+ }
123
+ const refSymbolCtx = refSymbol.context;
124
+ const isPropsVariant = refSymbolCtx.symbolKind === import_typedoc.ReflectionKind.TypeAlias;
125
+ const symbolRefMainRef = (_d = refSymbol.definitions) == null ? void 0 : _d[0];
126
+ if (!symbolRefMainRef) {
127
+ console.error(`Reference for symbol ${symbolId} has no main ref`);
128
+ continue;
129
+ }
130
+ for (const i in symbolRefMainRef.properties) {
131
+ let propIndex = parseInt(i);
132
+ if ((options == null ? void 0 : options.paramProps) && reactDef.properties.length) {
133
+ propIndex += reactDef.properties.length;
134
+ }
135
+ const symbolProp = symbolRefMainRef.properties[i];
136
+ const unionProp = (_e = symbolProp == null ? void 0 : symbolProp.symbolDef) == null ? void 0 : _e.id;
137
+ if (unionProp && unionProp.length && isPropsVariant) {
138
+ for (const symbolId2 of unionProp) {
139
+ const unionPropRef = refBySymbolId[symbolId2];
140
+ if (!unionPropRef) {
141
+ console.error(`unionProp: Reference for symbol ${symbolId2} not found`);
142
+ continue;
143
+ }
144
+ const unionPropRefCtx = unionPropRef.context;
145
+ const meta = [
146
+ {
147
+ name: "symbolName",
148
+ value: (unionPropRefCtx == null ? void 0 : unionPropRefCtx.symbolName) || ""
149
+ }
150
+ ];
151
+ const variant = {
152
+ title: unionPropRefCtx == null ? void 0 : unionPropRefCtx.symbolName,
153
+ properties: [],
154
+ meta
155
+ };
156
+ const unionPropDefs = (_f = unionPropRef.definitions) == null ? void 0 : _f[0];
157
+ if (unionPropDefs && unionPropDefs.properties) {
158
+ variant.properties = unionPropDefs.properties;
159
+ }
160
+ if (unionPropRef.definitions.length > 1) {
161
+ console.error(`unionProp: Reference for symbol ${symbolId2} has multiple definitions`);
162
+ }
163
+ if (!reactDef.variants) {
164
+ reactDef.variants = [];
165
+ }
166
+ reactDef.variants.push(variant);
167
+ }
168
+ } else {
169
+ const symbolId2 = (_g = property.symbolDef) == null ? void 0 : _g.id;
170
+ if (!symbolId2) {
171
+ console.error(`non-union property ${property.name} has no symbolId`);
172
+ continue;
173
+ }
174
+ if (typeof symbolId2 != "string") {
175
+ console.error(`symbolId is not a string: ${symbolId2}`);
176
+ continue;
177
+ }
178
+ const symbolRef = refBySymbolId[symbolId2];
179
+ if (!symbolRef) {
180
+ console.error(`symbolRef: Reference for symbol ${symbolId2} not found`);
181
+ continue;
182
+ }
183
+ const firstDef = (_h = symbolRef.definitions) == null ? void 0 : _h[0];
184
+ if (!firstDef) {
185
+ console.error(`symbolRef: Reference for symbol ${symbolId2} has no main ref`);
186
+ continue;
187
+ }
188
+ if (firstDef.properties.length > 1) {
189
+ console.warn(`symbolRef: Reference for symbol ${symbolId2} has multiple properties`);
190
+ }
191
+ reactDef.properties[propIndex] = firstDef.properties[i];
192
+ if (unionProp && typeof unionProp === "string") {
193
+ const unionPropRef = refBySymbolId[unionProp];
194
+ if (!unionPropRef) {
195
+ console.error(`unionProp: Reference for symbol ${symbolId2} not found`);
196
+ continue;
197
+ }
198
+ const joinPropTypes = [];
199
+ if ((_k = (_j = (_i = unionPropRef == null ? void 0 : unionPropRef.definitions) == null ? void 0 : _i[0]) == null ? void 0 : _j.properties) == null ? void 0 : _k.length) {
200
+ for (const prop of unionPropRef.definitions[0].properties) {
201
+ if (prop.type) {
202
+ joinPropTypes.push(prop.type);
203
+ }
204
+ }
205
+ }
206
+ if (joinPropTypes.length) {
207
+ reactDef.properties[propIndex].type = joinPropTypes.join(" | ");
208
+ }
209
+ }
210
+ }
211
+ }
212
+ }
213
+ }
214
+ function reactCanonical(canonical) {
215
+ const parts = canonical.split("/");
216
+ for (const i in parts) {
217
+ const part = parts[i];
218
+ if (part === "functions") {
219
+ parts[i] = "components";
220
+ }
221
+ }
222
+ return parts.join("/");
223
+ }
224
+ function reactGroup(group) {
225
+ for (const i in group) {
226
+ const part = group[i].toLowerCase();
227
+ if (part === "functions") {
228
+ group[i] = TXT.Component;
229
+ }
230
+ }
231
+ return group;
232
+ }
233
+ // Annotate the CommonJS export names for ESM import in node:
234
+ 0 && (module.exports = {
235
+ uniformToReactUniform
236
+ });
237
+ //# sourceMappingURL=react.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../packages/react/index.ts","../packages/react/uniformToReactUniform.ts"],"sourcesContent":["export { uniformToReactUniform } from './uniformToReactUniform';","import * as TypeDoc from 'typedoc';\nimport {ReflectionKind} from 'typedoc';\n\nimport {\n CommonDefinitionVariantMeta,\n DEFINED_DEFINITION_PROPERTY_TYPE,\n Definition, DefinitionProperty,\n DefinitionVariant,\n Reference,\n TypeDocReferenceContext\n} from \"@xyd-js/uniform\";\n\n// TODO: in the future translation system\nconst TXT = {\n Props: \"Props\",\n\n Component: \"Component\",\n}\n\nexport function uniformToReactUniform(\n references: Reference<TypeDocReferenceContext>[],\n projectJson: TypeDoc.JSONOutput.ProjectReflection // TODO: in the future unimap\n): Reference[] {\n const output: Reference[] = []\n\n let refBySymbolId: { [symbolId: string]: Reference } = {}\n\n for (const reference of references) {\n const ctx = reference.context\n\n if (ctx?.symbolId) {\n refBySymbolId[ctx.symbolId] = reference\n }\n }\n\n // TODO: in the future `unimap`\n for (const reference of references) {\n const ctx = reference.context\n\n if (ctx?.category !== \"Component\") {\n console.warn(`skipping non-component: ${ctx?.symbolName}`)\n continue\n }\n\n const reactRef: Reference = {\n ...reference,\n title: ctx?.symbolName || reference.title,\n canonical: reactCanonical(reference.canonical),\n context: {\n ...ctx,\n group: reactGroup(ctx?.group || []),\n },\n definitions: [],\n }\n\n for (const def of reference.definitions) {\n if (!def.meta) {\n continue\n }\n\n let isParamDefinition = false\n for (let meta of def.meta) {\n if (meta.name === \"type\" && meta.value === \"parameters\") {\n isParamDefinition = true\n break\n }\n }\n\n if (!isParamDefinition) {\n continue\n }\n\n const reactDef: Definition = {\n ...def,\n title: TXT.Props,\n properties: [],\n }\n\n definitionReactPropsPassThrough(\n refBySymbolId,\n def.properties || [],\n reactDef,\n )\n\n reactRef.definitions.push(reactDef)\n }\n\n output.push(reactRef)\n }\n\n return output\n}\n\nfunction definitionReactPropsPassThrough(\n refBySymbolId: { [symbolId: string]: Reference },\n defProperties: DefinitionProperty[],\n reactDef: Definition,\n options?: {\n paramProps?: boolean, // TODO: in the future\n }\n) {\n for (const property of defProperties) {\n if (property.type === DEFINED_DEFINITION_PROPERTY_TYPE.UNION && !property?.symbolDef?.id) {\n definitionReactPropsPassThrough(\n refBySymbolId,\n property.properties || [],\n reactDef,\n {\n paramProps: true,\n }\n )\n continue\n }\n\n const symbolId = property.symbolDef?.id\n if (typeof symbolId != \"string\") {\n if (options?.paramProps) {\n reactDef.properties.push(property)\n continue\n }\n console.error(`symbolId is not a string: ${symbolId}`)\n continue\n }\n\n // TODO: handle not symbol types\n if (!symbolId) {\n if (property.type === \"param\" && property.properties?.length) {\n reactDef.properties = property.properties\n }\n continue\n }\n\n\n const refSymbol = refBySymbolId[symbolId]\n if (!refSymbol) {\n console.error(`Reference for symbol ${symbolId} not found`)\n continue\n }\n const refSymbolCtx = refSymbol.context as TypeDocReferenceContext\n\n const isPropsVariant = refSymbolCtx.symbolKind === ReflectionKind.TypeAlias // TODO: in the future more symbol kinds?\n\n // TODO: in the future mainref or multiple refs?\n const symbolRefMainRef = refSymbol.definitions?.[0]\n if (!symbolRefMainRef) {\n console.error(`Reference for symbol ${symbolId} has no main ref`)\n continue\n }\n\n // TODO: suppot `&` and combined like `&` and `|`\n for (const i in symbolRefMainRef.properties) {\n let propIndex = parseInt(i)\n if (options?.paramProps && reactDef.properties.length) {\n propIndex += reactDef.properties.length\n }\n\n const symbolProp = symbolRefMainRef.properties[i]\n\n const unionProp = symbolProp?.symbolDef?.id\n\n if (unionProp && unionProp.length && isPropsVariant) {\n for (const symbolId of unionProp) {\n const unionPropRef = refBySymbolId[symbolId]\n if (!unionPropRef) {\n console.error(`unionProp: Reference for symbol ${symbolId} not found`)\n continue\n }\n\n const unionPropRefCtx = unionPropRef.context as TypeDocReferenceContext\n\n const meta: CommonDefinitionVariantMeta[] = [\n {\n name: \"symbolName\",\n value: unionPropRefCtx?.symbolName || \"\",\n }\n ]\n\n const variant: DefinitionVariant = {\n title: unionPropRefCtx?.symbolName,\n properties: [],\n meta,\n }\n\n // TODO: handle multiple definitions\n const unionPropDefs = unionPropRef.definitions?.[0]\n if (unionPropDefs && unionPropDefs.properties) {\n variant.properties = unionPropDefs.properties\n }\n if (unionPropRef.definitions.length > 1) {\n console.error(`unionProp: Reference for symbol ${symbolId} has multiple definitions`)\n }\n\n if (!reactDef.variants) {\n reactDef.variants = []\n }\n reactDef.variants.push(variant)\n }\n } else {\n const symbolId = property.symbolDef?.id\n if (!symbolId) {\n console.error(`non-union property ${property.name} has no symbolId`)\n continue\n }\n\n if (typeof symbolId != \"string\") {\n console.error(`symbolId is not a string: ${symbolId}`)\n continue\n }\n\n const symbolRef = refBySymbolId[symbolId]\n if (!symbolRef) {\n console.error(`symbolRef: Reference for symbol ${symbolId} not found`)\n continue\n }\n\n const firstDef = symbolRef.definitions?.[0]\n if (!firstDef) {\n console.error(`symbolRef: Reference for symbol ${symbolId} has no main ref`)\n continue\n }\n if (firstDef.properties.length > 1) {\n console.warn(`symbolRef: Reference for symbol ${symbolId} has multiple properties`)\n }\n\n reactDef.properties[propIndex] = firstDef.properties[i]\n\n if (unionProp && typeof unionProp === \"string\") {\n const unionPropRef = refBySymbolId[unionProp]\n if (!unionPropRef) {\n console.error(`unionProp: Reference for symbol ${symbolId} not found`)\n continue\n }\n\n const joinPropTypes: string[] = []\n // TODO: in the future by meta not by `[0]`\n if (unionPropRef?.definitions?.[0]?.properties?.length) {\n // TODO: configurable - join types or nested properties\n for (const prop of unionPropRef.definitions[0].properties) {\n if (prop.type) {\n joinPropTypes.push(prop.type)\n }\n }\n }\n\n if (joinPropTypes.length) {\n reactDef.properties[propIndex].type = joinPropTypes.join(\" | \")\n }\n }\n }\n }\n }\n}\n\nfunction reactCanonical(canonical: string): string {\n const parts = canonical.split(\"/\")\n for (const i in parts) {\n const part = parts[i]\n if (part === \"functions\") {\n parts[i] = \"components\"\n }\n }\n\n return parts.join(\"/\")\n}\n\nfunction reactGroup(group: string[]): string[] {\n for (const i in group) {\n const part = group[i].toLowerCase()\n if (part === \"functions\") {\n group[i] = TXT.Component\n }\n }\n\n return group\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,qBAA6B;AAE7B,qBAOO;AAGP,IAAM,MAAM;AAAA,EACR,OAAO;AAAA,EAEP,WAAW;AACf;AAEO,SAAS,sBACZ,YACA,aACW;AACX,QAAM,SAAsB,CAAC;AAE7B,MAAI,gBAAmD,CAAC;AAExD,aAAW,aAAa,YAAY;AAChC,UAAM,MAAM,UAAU;AAEtB,QAAI,2BAAK,UAAU;AACf,oBAAc,IAAI,QAAQ,IAAI;AAAA,IAClC;AAAA,EACJ;AAGA,aAAW,aAAa,YAAY;AAChC,UAAM,MAAM,UAAU;AAEtB,SAAI,2BAAK,cAAa,aAAa;AAC/B,cAAQ,KAAK,2BAA2B,2BAAK,UAAU,EAAE;AACzD;AAAA,IACJ;AAEA,UAAM,WAAsB;AAAA,MACxB,GAAG;AAAA,MACH,QAAO,2BAAK,eAAc,UAAU;AAAA,MACpC,WAAW,eAAe,UAAU,SAAS;AAAA,MAC7C,SAAS;AAAA,QACL,GAAG;AAAA,QACH,OAAO,YAAW,2BAAK,UAAS,CAAC,CAAC;AAAA,MACtC;AAAA,MACA,aAAa,CAAC;AAAA,IAClB;AAEA,eAAW,OAAO,UAAU,aAAa;AACrC,UAAI,CAAC,IAAI,MAAM;AACX;AAAA,MACJ;AAEA,UAAI,oBAAoB;AACxB,eAAS,QAAQ,IAAI,MAAM;AACvB,YAAI,KAAK,SAAS,UAAU,KAAK,UAAU,cAAc;AACrD,8BAAoB;AACpB;AAAA,QACJ;AAAA,MACJ;AAEA,UAAI,CAAC,mBAAmB;AACpB;AAAA,MACJ;AAEA,YAAM,WAAuB;AAAA,QACzB,GAAG;AAAA,QACH,OAAO,IAAI;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6 @@
1
+ import * as TypeDoc from 'typedoc';
2
+ import { Reference, TypeDocReferenceContext } from '@xyd-js/uniform';
3
+
4
+ declare function uniformToReactUniform(references: Reference<TypeDocReferenceContext>[], projectJson: TypeDoc.JSONOutput.ProjectReflection): Reference[];
5
+
6
+ export { uniformToReactUniform };
@@ -0,0 +1,6 @@
1
+ import * as TypeDoc from 'typedoc';
2
+ import { Reference, TypeDocReferenceContext } from '@xyd-js/uniform';
3
+
4
+ declare function uniformToReactUniform(references: Reference<TypeDocReferenceContext>[], projectJson: TypeDoc.JSONOutput.ProjectReflection): Reference[];
5
+
6
+ export { uniformToReactUniform };
package/dist/react.js ADDED
@@ -0,0 +1,212 @@
1
+ // packages/react/uniformToReactUniform.ts
2
+ import { ReflectionKind } from "typedoc";
3
+ import {
4
+ DEFINED_DEFINITION_PROPERTY_TYPE
5
+ } from "@xyd-js/uniform";
6
+ var TXT = {
7
+ Props: "Props",
8
+ Component: "Component"
9
+ };
10
+ function uniformToReactUniform(references, projectJson) {
11
+ const output = [];
12
+ let refBySymbolId = {};
13
+ for (const reference of references) {
14
+ const ctx = reference.context;
15
+ if (ctx == null ? void 0 : ctx.symbolId) {
16
+ refBySymbolId[ctx.symbolId] = reference;
17
+ }
18
+ }
19
+ for (const reference of references) {
20
+ const ctx = reference.context;
21
+ if ((ctx == null ? void 0 : ctx.category) !== "Component") {
22
+ console.warn(`skipping non-component: ${ctx == null ? void 0 : ctx.symbolName}`);
23
+ continue;
24
+ }
25
+ const reactRef = {
26
+ ...reference,
27
+ title: (ctx == null ? void 0 : ctx.symbolName) || reference.title,
28
+ canonical: reactCanonical(reference.canonical),
29
+ context: {
30
+ ...ctx,
31
+ group: reactGroup((ctx == null ? void 0 : ctx.group) || [])
32
+ },
33
+ definitions: []
34
+ };
35
+ for (const def of reference.definitions) {
36
+ if (!def.meta) {
37
+ continue;
38
+ }
39
+ let isParamDefinition = false;
40
+ for (let meta of def.meta) {
41
+ if (meta.name === "type" && meta.value === "parameters") {
42
+ isParamDefinition = true;
43
+ break;
44
+ }
45
+ }
46
+ if (!isParamDefinition) {
47
+ continue;
48
+ }
49
+ const reactDef = {
50
+ ...def,
51
+ title: TXT.Props,
52
+ properties: []
53
+ };
54
+ definitionReactPropsPassThrough(
55
+ refBySymbolId,
56
+ def.properties || [],
57
+ reactDef
58
+ );
59
+ reactRef.definitions.push(reactDef);
60
+ }
61
+ output.push(reactRef);
62
+ }
63
+ return output;
64
+ }
65
+ function definitionReactPropsPassThrough(refBySymbolId, defProperties, reactDef, options) {
66
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
67
+ for (const property of defProperties) {
68
+ if (property.type === DEFINED_DEFINITION_PROPERTY_TYPE.UNION && !((_a = property == null ? void 0 : property.symbolDef) == null ? void 0 : _a.id)) {
69
+ definitionReactPropsPassThrough(
70
+ refBySymbolId,
71
+ property.properties || [],
72
+ reactDef,
73
+ {
74
+ paramProps: true
75
+ }
76
+ );
77
+ continue;
78
+ }
79
+ const symbolId = (_b = property.symbolDef) == null ? void 0 : _b.id;
80
+ if (typeof symbolId != "string") {
81
+ if (options == null ? void 0 : options.paramProps) {
82
+ reactDef.properties.push(property);
83
+ continue;
84
+ }
85
+ console.error(`symbolId is not a string: ${symbolId}`);
86
+ continue;
87
+ }
88
+ if (!symbolId) {
89
+ if (property.type === "param" && ((_c = property.properties) == null ? void 0 : _c.length)) {
90
+ reactDef.properties = property.properties;
91
+ }
92
+ continue;
93
+ }
94
+ const refSymbol = refBySymbolId[symbolId];
95
+ if (!refSymbol) {
96
+ console.error(`Reference for symbol ${symbolId} not found`);
97
+ continue;
98
+ }
99
+ const refSymbolCtx = refSymbol.context;
100
+ const isPropsVariant = refSymbolCtx.symbolKind === ReflectionKind.TypeAlias;
101
+ const symbolRefMainRef = (_d = refSymbol.definitions) == null ? void 0 : _d[0];
102
+ if (!symbolRefMainRef) {
103
+ console.error(`Reference for symbol ${symbolId} has no main ref`);
104
+ continue;
105
+ }
106
+ for (const i in symbolRefMainRef.properties) {
107
+ let propIndex = parseInt(i);
108
+ if ((options == null ? void 0 : options.paramProps) && reactDef.properties.length) {
109
+ propIndex += reactDef.properties.length;
110
+ }
111
+ const symbolProp = symbolRefMainRef.properties[i];
112
+ const unionProp = (_e = symbolProp == null ? void 0 : symbolProp.symbolDef) == null ? void 0 : _e.id;
113
+ if (unionProp && unionProp.length && isPropsVariant) {
114
+ for (const symbolId2 of unionProp) {
115
+ const unionPropRef = refBySymbolId[symbolId2];
116
+ if (!unionPropRef) {
117
+ console.error(`unionProp: Reference for symbol ${symbolId2} not found`);
118
+ continue;
119
+ }
120
+ const unionPropRefCtx = unionPropRef.context;
121
+ const meta = [
122
+ {
123
+ name: "symbolName",
124
+ value: (unionPropRefCtx == null ? void 0 : unionPropRefCtx.symbolName) || ""
125
+ }
126
+ ];
127
+ const variant = {
128
+ title: unionPropRefCtx == null ? void 0 : unionPropRefCtx.symbolName,
129
+ properties: [],
130
+ meta
131
+ };
132
+ const unionPropDefs = (_f = unionPropRef.definitions) == null ? void 0 : _f[0];
133
+ if (unionPropDefs && unionPropDefs.properties) {
134
+ variant.properties = unionPropDefs.properties;
135
+ }
136
+ if (unionPropRef.definitions.length > 1) {
137
+ console.error(`unionProp: Reference for symbol ${symbolId2} has multiple definitions`);
138
+ }
139
+ if (!reactDef.variants) {
140
+ reactDef.variants = [];
141
+ }
142
+ reactDef.variants.push(variant);
143
+ }
144
+ } else {
145
+ const symbolId2 = (_g = property.symbolDef) == null ? void 0 : _g.id;
146
+ if (!symbolId2) {
147
+ console.error(`non-union property ${property.name} has no symbolId`);
148
+ continue;
149
+ }
150
+ if (typeof symbolId2 != "string") {
151
+ console.error(`symbolId is not a string: ${symbolId2}`);
152
+ continue;
153
+ }
154
+ const symbolRef = refBySymbolId[symbolId2];
155
+ if (!symbolRef) {
156
+ console.error(`symbolRef: Reference for symbol ${symbolId2} not found`);
157
+ continue;
158
+ }
159
+ const firstDef = (_h = symbolRef.definitions) == null ? void 0 : _h[0];
160
+ if (!firstDef) {
161
+ console.error(`symbolRef: Reference for symbol ${symbolId2} has no main ref`);
162
+ continue;
163
+ }
164
+ if (firstDef.properties.length > 1) {
165
+ console.warn(`symbolRef: Reference for symbol ${symbolId2} has multiple properties`);
166
+ }
167
+ reactDef.properties[propIndex] = firstDef.properties[i];
168
+ if (unionProp && typeof unionProp === "string") {
169
+ const unionPropRef = refBySymbolId[unionProp];
170
+ if (!unionPropRef) {
171
+ console.error(`unionProp: Reference for symbol ${symbolId2} not found`);
172
+ continue;
173
+ }
174
+ const joinPropTypes = [];
175
+ if ((_k = (_j = (_i = unionPropRef == null ? void 0 : unionPropRef.definitions) == null ? void 0 : _i[0]) == null ? void 0 : _j.properties) == null ? void 0 : _k.length) {
176
+ for (const prop of unionPropRef.definitions[0].properties) {
177
+ if (prop.type) {
178
+ joinPropTypes.push(prop.type);
179
+ }
180
+ }
181
+ }
182
+ if (joinPropTypes.length) {
183
+ reactDef.properties[propIndex].type = joinPropTypes.join(" | ");
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ }
190
+ function reactCanonical(canonical) {
191
+ const parts = canonical.split("/");
192
+ for (const i in parts) {
193
+ const part = parts[i];
194
+ if (part === "functions") {
195
+ parts[i] = "components";
196
+ }
197
+ }
198
+ return parts.join("/");
199
+ }
200
+ function reactGroup(group) {
201
+ for (const i in group) {
202
+ const part = group[i].toLowerCase();
203
+ if (part === "functions") {
204
+ group[i] = TXT.Component;
205
+ }
206
+ }
207
+ return group;
208
+ }
209
+ export {
210
+ uniformToReactUniform
211
+ };
212
+ //# sourceMappingURL=react.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../packages/react/uniformToReactUniform.ts"],"sourcesContent":["import * as TypeDoc from 'typedoc';\nimport {ReflectionKind} from 'typedoc';\n\nimport {\n CommonDefinitionVariantMeta,\n DEFINED_DEFINITION_PROPERTY_TYPE,\n Definition, DefinitionProperty,\n DefinitionVariant,\n Reference,\n TypeDocReferenceContext\n} from \"@xyd-js/uniform\";\n\n// TODO: in the future translation system\nconst TXT = {\n Props: \"Props\",\n\n Component: \"Component\",\n}\n\nexport function uniformToReactUniform(\n references: Reference<TypeDocReferenceContext>[],\n projectJson: TypeDoc.JSONOutput.ProjectReflection // TODO: in the future unimap\n): Reference[] {\n const output: Reference[] = []\n\n let refBySymbolId: { [symbolId: string]: Reference } = {}\n\n for (const reference of references) {\n const ctx = reference.context\n\n if (ctx?.symbolId) {\n refBySymbolId[ctx.symbolId] = reference\n }\n }\n\n // TODO: in the future `unimap`\n for (const reference of references) {\n const ctx = reference.context\n\n if (ctx?.category !== \"Component\") {\n console.warn(`skipping non-component: ${ctx?.symbolName}`)\n continue\n }\n\n const reactRef: Reference = {\n ...reference,\n title: ctx?.symbolName || reference.title,\n canonical: reactCanonical(reference.canonical),\n context: {\n ...ctx,\n group: reactGroup(ctx?.group || []),\n },\n definitions: [],\n }\n\n for (const def of reference.definitions) {\n if (!def.meta) {\n continue\n }\n\n let isParamDefinition = false\n for (let meta of def.meta) {\n if (meta.name === \"type\" && meta.value === \"parameters\") {\n isParamDefinition = true\n break\n }\n }\n\n if (!isParamDefinition) {\n continue\n }\n\n const reactDef: Definition = {\n ...def,\n title: TXT.Props,\n properties: [],\n }\n\n definitionReactPropsPassThrough(\n refBySymbolId,\n def.properties || [],\n reactDef,\n )\n\n reactRef.definitions.push(reactDef)\n }\n\n output.push(reactRef)\n }\n\n return output\n}\n\nfunction definitionReactPropsPassThrough(\n refBySymbolId: { [symbolId: string]: Reference },\n defProperties: DefinitionProperty[],\n reactDef: Definition,\n options?: {\n paramProps?: boolean, // TODO: in the future\n }\n) {\n for (const property of defProperties) {\n if (property.type === DEFINED_DEFINITION_PROPERTY_TYPE.UNION && !property?.symbolDef?.id) {\n definitionReactPropsPassThrough(\n refBySymbolId,\n property.properties || [],\n reactDef,\n {\n paramProps: true,\n }\n )\n continue\n }\n\n const symbolId = property.symbolDef?.id\n if (typeof symbolId != \"string\") {\n if (options?.paramProps) {\n reactDef.properties.push(property)\n continue\n }\n console.error(`symbolId is not a string: ${symbolId}`)\n continue\n }\n\n // TODO: handle not symbol types\n if (!symbolId) {\n if (property.type === \"param\" && property.properties?.length) {\n reactDef.properties = property.properties\n }\n continue\n }\n\n\n const refSymbol = refBySymbolId[symbolId]\n if (!refSymbol) {\n console.error(`Reference for symbol ${symbolId} not found`)\n continue\n }\n const refSymbolCtx = refSymbol.context as TypeDocReferenceContext\n\n const isPropsVariant = refSymbolCtx.symbolKind === ReflectionKind.TypeAlias // TODO: in the future more symbol kinds?\n\n // TODO: in the future mainref or multiple refs?\n const symbolRefMainRef = refSymbol.definitions?.[0]\n if (!symbolRefMainRef) {\n console.error(`Reference for symbol ${symbolId} has no main ref`)\n continue\n }\n\n // TODO: suppot `&` and combined like `&` and `|`\n for (const i in symbolRefMainRef.properties) {\n let propIndex = parseInt(i)\n if (options?.paramProps && reactDef.properties.length) {\n propIndex += reactDef.properties.length\n }\n\n const symbolProp = symbolRefMainRef.properties[i]\n\n const unionProp = symbolProp?.symbolDef?.id\n\n if (unionProp && unionProp.length && isPropsVariant) {\n for (const symbolId of unionProp) {\n const unionPropRef = refBySymbolId[symbolId]\n if (!unionPropRef) {\n console.error(`unionProp: Reference for symbol ${symbolId} not found`)\n continue\n }\n\n const unionPropRefCtx = unionPropRef.context as TypeDocReferenceContext\n\n const meta: CommonDefinitionVariantMeta[] = [\n {\n name: \"symbolName\",\n value: unionPropRefCtx?.symbolName || \"\",\n }\n ]\n\n const variant: DefinitionVariant = {\n title: unionPropRefCtx?.symbolName,\n properties: [],\n meta,\n }\n\n // TODO: handle multiple definitions\n const unionPropDefs = unionPropRef.definitions?.[0]\n if (unionPropDefs && unionPropDefs.properties) {\n variant.properties = unionPropDefs.properties\n }\n if (unionPropRef.definitions.length > 1) {\n console.error(`unionProp: Reference for symbol ${symbolId} has multiple definitions`)\n }\n\n if (!reactDef.variants) {\n reactDef.variants = []\n }\n reactDef.variants.push(variant)\n }\n } else {\n const symbolId = property.symbolDef?.id\n if (!symbolId) {\n console.error(`non-union property ${property.name} has no symbolId`)\n continue\n }\n\n if (typeof symbolId != \"string\") {\n console.error(`symbolId is not a string: ${symbolId}`)\n continue\n }\n\n const symbolRef = refBySymbolId[symbolId]\n if (!symbolRef) {\n console.error(`symbolRef: Reference for symbol ${symbolId} not found`)\n continue\n }\n\n const firstDef = symbolRef.definitions?.[0]\n if (!firstDef) {\n console.error(`symbolRef: Reference for symbol ${symbolId} has no main ref`)\n continue\n }\n if (firstDef.properties.length > 1) {\n console.warn(`symbolRef: Reference for symbol ${symbolId} has multiple properties`)\n }\n\n reactDef.properties[propIndex] = firstDef.properties[i]\n\n if (unionProp && typeof unionProp === \"string\") {\n const unionPropRef = refBySymbolId[unionProp]\n if (!unionPropRef) {\n console.error(`unionProp: Reference for symbol ${symbolId} not found`)\n continue\n }\n\n const joinPropTypes: string[] = []\n // TODO: in the future by meta not by `[0]`\n if (unionPropRef?.definitions?.[0]?.properties?.length) {\n // TODO: configurable - join types or nested properties\n for (const prop of unionPropRef.definitions[0].properties) {\n if (prop.type) {\n joinPropTypes.push(prop.type)\n }\n }\n }\n\n if (joinPropTypes.length) {\n reactDef.properties[propIndex].type = joinPropTypes.join(\" | \")\n }\n }\n }\n }\n }\n}\n\nfunction reactCanonical(canonical: string): string {\n const parts = canonical.split(\"/\")\n for (const i in parts) {\n const part = parts[i]\n if (part === \"functions\") {\n parts[i] = \"components\"\n }\n }\n\n return parts.join(\"/\")\n}\n\nfunction reactGroup(group: string[]): string[] {\n for (const i in group) {\n const part = group[i].toLowerCase()\n if (part === \"functions\") {\n group[i] = TXT.Component\n }\n }\n\n return group\n}\n"],"mappings":";AACA,SAAQ,sBAAqB;AAE7B;AAAA,EAEI;AAAA,OAKG;AAGP,IAAM,MAAM;AAAA,EACR,OAAO;AAAA,EAEP,WAAW;AACf;AAEO,SAAS,sBACZ,YACA,aACW;AACX,QAAM,SAAsB,CAAC;AAE7B,MAAI,gBAAmD,CAAC;AAExD,aAAW,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