@zeus-js/component-dts 0.1.1-beta.1 → 0.1.1-beta.10
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.
- package/dist/component-dts.cjs +160 -12
- package/dist/component-dts.esm-bundler.js +212 -12
- package/dist/component-dts.prod.cjs +160 -12
- package/package.json +2 -2
package/dist/component-dts.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* component-dts v0.1.1-beta.
|
|
2
|
+
* component-dts v0.1.1-beta.10
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
@@ -29,11 +29,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
enumerable: true
|
|
30
30
|
}) : target, mod));
|
|
31
31
|
//#endregion
|
|
32
|
+
let _zeus_js_component_analyzer = require("@zeus-js/component-analyzer");
|
|
32
33
|
let node_path = require("node:path");
|
|
33
34
|
node_path = __toESM(node_path, 1);
|
|
34
35
|
//#region packages/web-c/component-dts/src/formatType.ts
|
|
35
36
|
function formatPropType(prop) {
|
|
36
37
|
var _prop$values;
|
|
38
|
+
if (prop.declaration) {
|
|
39
|
+
var _prop$declaration$ref;
|
|
40
|
+
return (_prop$declaration$ref = prop.declaration.reference) !== null && _prop$declaration$ref !== void 0 ? _prop$declaration$ref : prop.declaration.type;
|
|
41
|
+
}
|
|
37
42
|
if ((_prop$values = prop.values) === null || _prop$values === void 0 ? void 0 : _prop$values.length) return prop.values.map((value) => JSON.stringify(value)).join(" | ");
|
|
38
43
|
switch (prop.type) {
|
|
39
44
|
case "string": return "string";
|
|
@@ -64,6 +69,7 @@ function normalizeKnownType(type) {
|
|
|
64
69
|
case "FocusEvent":
|
|
65
70
|
case "InputEvent":
|
|
66
71
|
case "Event": return type;
|
|
72
|
+
case "function": return "Function";
|
|
67
73
|
case "object": return "Record<string, unknown>";
|
|
68
74
|
case "array": return "unknown[]";
|
|
69
75
|
default: return type || "unknown";
|
|
@@ -100,6 +106,26 @@ function getEventMapTypeName(component) {
|
|
|
100
106
|
function getPropsTypeName(component) {
|
|
101
107
|
return `${component.name}Props`;
|
|
102
108
|
}
|
|
109
|
+
function getGeneratedDeclarationNames(components) {
|
|
110
|
+
const names = new Set(_zeus_js_component_analyzer.PORTABLE_GLOBAL_TYPE_REFERENCES);
|
|
111
|
+
names.add("HTMLElementTagNameMap");
|
|
112
|
+
names.add("JSX");
|
|
113
|
+
names.add("React");
|
|
114
|
+
names.add("DefineComponent");
|
|
115
|
+
names.add("GlobalComponents");
|
|
116
|
+
for (const component of components) {
|
|
117
|
+
const elementTypeName = getElementTypeName(component);
|
|
118
|
+
names.add(component.name);
|
|
119
|
+
names.add(component.exportName);
|
|
120
|
+
names.add(elementTypeName);
|
|
121
|
+
names.add(`${elementTypeName}Props`);
|
|
122
|
+
names.add(`${elementTypeName}Methods`);
|
|
123
|
+
names.add(`${elementTypeName}EventTarget`);
|
|
124
|
+
names.add(getEventMapTypeName(component));
|
|
125
|
+
names.add(getPropsTypeName(component));
|
|
126
|
+
}
|
|
127
|
+
return names;
|
|
128
|
+
}
|
|
103
129
|
function getComponentFileBaseName(tag, options) {
|
|
104
130
|
if (options.fileName) return sanitizeFileName(options.fileName(tag)).replace(/\.d\.ts$/, "");
|
|
105
131
|
let name = tag;
|
|
@@ -161,18 +187,102 @@ function generateEventTargetType(elementTypeName, eventTargetTypeName, eventMapT
|
|
|
161
187
|
return lines.join("\n");
|
|
162
188
|
}
|
|
163
189
|
//#endregion
|
|
190
|
+
//#region packages/web-c/component-dts/src/generatePropTypeDeclarations.ts
|
|
191
|
+
function generatePropTypeDeclarations(components, options = {}) {
|
|
192
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
193
|
+
const conflicts = /* @__PURE__ */ new Set();
|
|
194
|
+
for (const component of components) for (const prop of Object.values(component.props)) {
|
|
195
|
+
const declaration = prop.declaration;
|
|
196
|
+
const reference = declaration === null || declaration === void 0 ? void 0 : declaration.reference;
|
|
197
|
+
if (!reference) continue;
|
|
198
|
+
const existing = declarations.get(reference);
|
|
199
|
+
if (existing && existing !== declaration.type) {
|
|
200
|
+
conflicts.add(reference);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
declarations.set(reference, declaration.type);
|
|
204
|
+
}
|
|
205
|
+
for (const reference of conflicts) declarations.delete(reference);
|
|
206
|
+
const allocatedNames = allocateDeclarationNames(declarations.keys(), options.reservedNames);
|
|
207
|
+
const normalizedComponents = components.map((component) => normalizeDeclarations(component, conflicts, allocatedNames));
|
|
208
|
+
const declarationPrefix = options.exported === false ? "type" : "export type";
|
|
209
|
+
return {
|
|
210
|
+
code: Array.from(declarations, ([name, type]) => {
|
|
211
|
+
return `${declarationPrefix} ${allocatedNames.get(name)} = ${type}`;
|
|
212
|
+
}).join("\n"),
|
|
213
|
+
components: normalizedComponents
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function allocateDeclarationNames(references, reservedNames) {
|
|
217
|
+
const sourceNames = Array.from(references);
|
|
218
|
+
const used = new Set(reservedNames);
|
|
219
|
+
const result = /* @__PURE__ */ new Map();
|
|
220
|
+
for (const name of sourceNames) if (!used.has(name)) used.add(name);
|
|
221
|
+
for (const name of sourceNames) {
|
|
222
|
+
if (!(reservedNames === null || reservedNames === void 0 ? void 0 : reservedNames.has(name))) {
|
|
223
|
+
result.set(name, name);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const base = `${name}PropType`;
|
|
227
|
+
let candidate = base;
|
|
228
|
+
let suffix = 2;
|
|
229
|
+
while (used.has(candidate)) {
|
|
230
|
+
candidate = `${base}${suffix}`;
|
|
231
|
+
suffix += 1;
|
|
232
|
+
}
|
|
233
|
+
used.add(candidate);
|
|
234
|
+
result.set(name, candidate);
|
|
235
|
+
}
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
function normalizeDeclarations(component, conflicts, allocatedNames) {
|
|
239
|
+
let changed = false;
|
|
240
|
+
const props = Object.fromEntries(Object.entries(component.props).map(([name, prop]) => {
|
|
241
|
+
const declaration = prop.declaration;
|
|
242
|
+
if (!(declaration === null || declaration === void 0 ? void 0 : declaration.reference)) return [name, prop];
|
|
243
|
+
const reference = declaration.reference;
|
|
244
|
+
const allocatedName = allocatedNames.get(reference);
|
|
245
|
+
if (!conflicts.has(reference) && allocatedName === reference) return [name, prop];
|
|
246
|
+
changed = true;
|
|
247
|
+
return [name, {
|
|
248
|
+
...prop,
|
|
249
|
+
declaration: conflicts.has(reference) ? { type: declaration.type } : {
|
|
250
|
+
...declaration,
|
|
251
|
+
reference: allocatedName
|
|
252
|
+
}
|
|
253
|
+
}];
|
|
254
|
+
}));
|
|
255
|
+
return changed ? {
|
|
256
|
+
...component,
|
|
257
|
+
props
|
|
258
|
+
} : component;
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
164
261
|
//#region packages/web-c/component-dts/src/generateWcDts.ts
|
|
165
262
|
function generateComponentWCDts(component) {
|
|
166
|
-
|
|
263
|
+
return generateComponentWCDtsFile(component);
|
|
264
|
+
}
|
|
265
|
+
function generateComponentWCDtsFile(component, options = {}) {
|
|
266
|
+
var _options$exportPropTy, _propTypeDeclarations;
|
|
267
|
+
const propTypeDeclarations = generatePropTypeDeclarations([component], {
|
|
268
|
+
exported: (_options$exportPropTy = options.exportPropTypes) !== null && _options$exportPropTy !== void 0 ? _options$exportPropTy : true,
|
|
269
|
+
reservedNames: mergeReservedNames(getGeneratedDeclarationNames([component]), options.reservedNames)
|
|
270
|
+
});
|
|
271
|
+
const resolvedComponent = (_propTypeDeclarations = propTypeDeclarations.components[0]) !== null && _propTypeDeclarations !== void 0 ? _propTypeDeclarations : component;
|
|
272
|
+
const elementTypeName = getElementTypeName(resolvedComponent);
|
|
167
273
|
const lines = [];
|
|
168
274
|
lines.push("/* eslint-disable */");
|
|
169
275
|
lines.push("// Generated by @zeus-js/component-dts.");
|
|
170
276
|
lines.push("");
|
|
171
|
-
|
|
277
|
+
if (propTypeDeclarations.code) {
|
|
278
|
+
lines.push(propTypeDeclarations.code);
|
|
279
|
+
lines.push("");
|
|
280
|
+
}
|
|
281
|
+
lines.push(generateEventMap(resolvedComponent));
|
|
172
282
|
lines.push("");
|
|
173
|
-
lines.push(generateElementInterface(
|
|
283
|
+
lines.push(generateElementInterface(resolvedComponent));
|
|
174
284
|
lines.push("");
|
|
175
|
-
lines.push(`export declare const ${
|
|
285
|
+
lines.push(`export declare const ${resolvedComponent.exportName}: {`);
|
|
176
286
|
lines.push(` new (): ${elementTypeName}`);
|
|
177
287
|
lines.push("}");
|
|
178
288
|
lines.push("");
|
|
@@ -184,7 +294,11 @@ function generateWCIndexDts(manifest, options) {
|
|
|
184
294
|
lines.push("// Generated by @zeus-js/component-dts.");
|
|
185
295
|
lines.push("");
|
|
186
296
|
for (const component of manifest.components) lines.push(`import type { ${getElementTypeName(component)} } from ${JSON.stringify(options.getComponentImportPath(component))}`);
|
|
187
|
-
for (const component of manifest.components)
|
|
297
|
+
for (const component of manifest.components) {
|
|
298
|
+
const importPath = JSON.stringify(options.getComponentImportPath(component));
|
|
299
|
+
lines.push(`export { ${component.exportName} } from ${importPath}`);
|
|
300
|
+
lines.push(`export type { ${getElementTypeName(component)}, ${getEventMapTypeName(component)} } from ${importPath}`);
|
|
301
|
+
}
|
|
188
302
|
lines.push("");
|
|
189
303
|
lines.push("declare global {");
|
|
190
304
|
lines.push(" interface HTMLElementTagNameMap {");
|
|
@@ -213,6 +327,9 @@ function generateElementInterface(component) {
|
|
|
213
327
|
function toKebabCase$1(value) {
|
|
214
328
|
return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
215
329
|
}
|
|
330
|
+
function mergeReservedNames(defaults, additional) {
|
|
331
|
+
return /* @__PURE__ */ new Set([...defaults, ...additional !== null && additional !== void 0 ? additional : []]);
|
|
332
|
+
}
|
|
216
333
|
//#endregion
|
|
217
334
|
//#region packages/web-c/component-dts/src/generateJsxDts.ts
|
|
218
335
|
function generateWCJsxDts(manifest) {
|
|
@@ -220,7 +337,14 @@ function generateWCJsxDts(manifest) {
|
|
|
220
337
|
lines.push("/* eslint-disable */");
|
|
221
338
|
lines.push("// Generated by @zeus-js/component-dts.");
|
|
222
339
|
lines.push("");
|
|
223
|
-
|
|
340
|
+
const reservedNames = getGeneratedDeclarationNames(manifest.components);
|
|
341
|
+
reservedNames.add("JSX");
|
|
342
|
+
const propTypeDeclarations = generatePropTypeDeclarations(manifest.components, { reservedNames });
|
|
343
|
+
if (propTypeDeclarations.code) {
|
|
344
|
+
lines.push(propTypeDeclarations.code);
|
|
345
|
+
lines.push("");
|
|
346
|
+
}
|
|
347
|
+
for (const component of propTypeDeclarations.components) {
|
|
224
348
|
lines.push(generateComponentJsxProps(component));
|
|
225
349
|
lines.push("");
|
|
226
350
|
}
|
|
@@ -276,7 +400,14 @@ function generateReactDts(manifest, options = {}) {
|
|
|
276
400
|
lines.push("");
|
|
277
401
|
lines.push(`import type * as React from 'react'`);
|
|
278
402
|
lines.push("");
|
|
279
|
-
|
|
403
|
+
const reservedNames = getGeneratedDeclarationNames(manifest.components);
|
|
404
|
+
reservedNames.add("React");
|
|
405
|
+
const propTypeDeclarations = generatePropTypeDeclarations(manifest.components, { reservedNames });
|
|
406
|
+
if (propTypeDeclarations.code) {
|
|
407
|
+
lines.push(propTypeDeclarations.code);
|
|
408
|
+
lines.push("");
|
|
409
|
+
}
|
|
410
|
+
for (const component of propTypeDeclarations.components) {
|
|
280
411
|
lines.push(generateReactComponentDts(component, options));
|
|
281
412
|
lines.push("");
|
|
282
413
|
}
|
|
@@ -326,7 +457,14 @@ function generateVueDts(manifest) {
|
|
|
326
457
|
lines.push("");
|
|
327
458
|
lines.push(`import type { DefineComponent } from 'vue'`);
|
|
328
459
|
lines.push("");
|
|
329
|
-
|
|
460
|
+
const reservedNames = getGeneratedDeclarationNames(manifest.components);
|
|
461
|
+
reservedNames.add("DefineComponent");
|
|
462
|
+
const propTypeDeclarations = generatePropTypeDeclarations(manifest.components, { reservedNames });
|
|
463
|
+
if (propTypeDeclarations.code) {
|
|
464
|
+
lines.push(propTypeDeclarations.code);
|
|
465
|
+
lines.push("");
|
|
466
|
+
}
|
|
467
|
+
for (const component of propTypeDeclarations.components) {
|
|
330
468
|
lines.push(generateVueComponentDts(component));
|
|
331
469
|
lines.push("");
|
|
332
470
|
}
|
|
@@ -397,9 +535,14 @@ function toKebabCase(value) {
|
|
|
397
535
|
function generateWCDtsFiles(manifest, options = {}) {
|
|
398
536
|
const normalized = normalizeOptions(options);
|
|
399
537
|
const files = [];
|
|
400
|
-
|
|
538
|
+
const reservedNames = getGeneratedDeclarationNames(manifest.components);
|
|
539
|
+
const resolvedComponents = generatePropTypeDeclarations(manifest.components, { reservedNames }).components;
|
|
540
|
+
if (normalized.perComponent) for (const component of resolvedComponents) files.push({
|
|
401
541
|
fileName: node_path.default.posix.join(normalized.outDir, getComponentDtsFileName(component.tag, normalized)),
|
|
402
|
-
source:
|
|
542
|
+
source: generateComponentWCDtsFile(component, {
|
|
543
|
+
exportPropTypes: false,
|
|
544
|
+
reservedNames
|
|
545
|
+
})
|
|
403
546
|
});
|
|
404
547
|
if (normalized.index) files.push({
|
|
405
548
|
fileName: node_path.default.posix.join(normalized.outDir, "index.d.ts"),
|
|
@@ -429,7 +572,12 @@ function generateLoaderDts(manifest) {
|
|
|
429
572
|
lines.push("/* eslint-disable */");
|
|
430
573
|
lines.push("// Generated by @zeus-js/component-dts.");
|
|
431
574
|
lines.push("");
|
|
432
|
-
|
|
575
|
+
const propTypeDeclarations = generatePropTypeDeclarations(manifest.components, { reservedNames: getGeneratedDeclarationNames(manifest.components) });
|
|
576
|
+
if (propTypeDeclarations.code) {
|
|
577
|
+
lines.push(propTypeDeclarations.code);
|
|
578
|
+
lines.push("");
|
|
579
|
+
}
|
|
580
|
+
for (const component of propTypeDeclarations.components) {
|
|
433
581
|
lines.push(generateElementType(component, {
|
|
434
582
|
componentOnReady: true,
|
|
435
583
|
forcePromise: true
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* component-dts v0.1.1-beta.
|
|
2
|
+
* component-dts v0.1.1-beta.10
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
6
|
+
import { PORTABLE_GLOBAL_TYPE_REFERENCES } from "@zeus-js/component-analyzer";
|
|
6
7
|
import path from "node:path";
|
|
7
8
|
//#region packages/web-c/component-dts/src/formatType.ts
|
|
8
9
|
function formatPropType(prop) {
|
|
9
10
|
var _prop$values;
|
|
11
|
+
if (prop.declaration) {
|
|
12
|
+
var _prop$declaration$ref;
|
|
13
|
+
return (_prop$declaration$ref = prop.declaration.reference) !== null && _prop$declaration$ref !== void 0 ? _prop$declaration$ref : prop.declaration.type;
|
|
14
|
+
}
|
|
10
15
|
if ((_prop$values = prop.values) === null || _prop$values === void 0 ? void 0 : _prop$values.length) return prop.values.map((value) => JSON.stringify(value)).join(" | ");
|
|
11
16
|
switch (prop.type) {
|
|
12
17
|
case "string": return "string";
|
|
@@ -37,6 +42,7 @@ function normalizeKnownType(type) {
|
|
|
37
42
|
case "FocusEvent":
|
|
38
43
|
case "InputEvent":
|
|
39
44
|
case "Event": return type;
|
|
45
|
+
case "function": return "Function";
|
|
40
46
|
case "object": return "Record<string, unknown>";
|
|
41
47
|
case "array": return "unknown[]";
|
|
42
48
|
default: return type || "unknown";
|
|
@@ -73,6 +79,26 @@ function getEventMapTypeName(component) {
|
|
|
73
79
|
function getPropsTypeName(component) {
|
|
74
80
|
return `${component.name}Props`;
|
|
75
81
|
}
|
|
82
|
+
function getGeneratedDeclarationNames(components) {
|
|
83
|
+
const names = new Set(PORTABLE_GLOBAL_TYPE_REFERENCES);
|
|
84
|
+
names.add("HTMLElementTagNameMap");
|
|
85
|
+
names.add("JSX");
|
|
86
|
+
names.add("React");
|
|
87
|
+
names.add("DefineComponent");
|
|
88
|
+
names.add("GlobalComponents");
|
|
89
|
+
for (const component of components) {
|
|
90
|
+
const elementTypeName = getElementTypeName(component);
|
|
91
|
+
names.add(component.name);
|
|
92
|
+
names.add(component.exportName);
|
|
93
|
+
names.add(elementTypeName);
|
|
94
|
+
names.add(`${elementTypeName}Props`);
|
|
95
|
+
names.add(`${elementTypeName}Methods`);
|
|
96
|
+
names.add(`${elementTypeName}EventTarget`);
|
|
97
|
+
names.add(getEventMapTypeName(component));
|
|
98
|
+
names.add(getPropsTypeName(component));
|
|
99
|
+
}
|
|
100
|
+
return names;
|
|
101
|
+
}
|
|
76
102
|
function getComponentFileBaseName(tag, options) {
|
|
77
103
|
if (options.fileName) return sanitizeFileName(options.fileName(tag)).replace(/\.d\.ts$/, "");
|
|
78
104
|
let name = tag;
|
|
@@ -134,18 +160,154 @@ function generateEventTargetType(elementTypeName, eventTargetTypeName, eventMapT
|
|
|
134
160
|
return lines.join("\n");
|
|
135
161
|
}
|
|
136
162
|
//#endregion
|
|
163
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
164
|
+
function _typeof(o) {
|
|
165
|
+
"@babel/helpers - typeof";
|
|
166
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
167
|
+
return typeof o;
|
|
168
|
+
} : function(o) {
|
|
169
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
170
|
+
}, _typeof(o);
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
174
|
+
function toPrimitive(t, r) {
|
|
175
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
176
|
+
var e = t[Symbol.toPrimitive];
|
|
177
|
+
if (void 0 !== e) {
|
|
178
|
+
var i = e.call(t, r || "default");
|
|
179
|
+
if ("object" != _typeof(i)) return i;
|
|
180
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
181
|
+
}
|
|
182
|
+
return ("string" === r ? String : Number)(t);
|
|
183
|
+
}
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
186
|
+
function toPropertyKey(t) {
|
|
187
|
+
var i = toPrimitive(t, "string");
|
|
188
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
189
|
+
}
|
|
190
|
+
//#endregion
|
|
191
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
192
|
+
function _defineProperty(e, r, t) {
|
|
193
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
194
|
+
value: t,
|
|
195
|
+
enumerable: !0,
|
|
196
|
+
configurable: !0,
|
|
197
|
+
writable: !0
|
|
198
|
+
}) : e[r] = t, e;
|
|
199
|
+
}
|
|
200
|
+
//#endregion
|
|
201
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/objectSpread2.js
|
|
202
|
+
function ownKeys(e, r) {
|
|
203
|
+
var t = Object.keys(e);
|
|
204
|
+
if (Object.getOwnPropertySymbols) {
|
|
205
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
206
|
+
r && (o = o.filter(function(r) {
|
|
207
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
208
|
+
})), t.push.apply(t, o);
|
|
209
|
+
}
|
|
210
|
+
return t;
|
|
211
|
+
}
|
|
212
|
+
function _objectSpread2(e) {
|
|
213
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
214
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
215
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
|
|
216
|
+
_defineProperty(e, r, t[r]);
|
|
217
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
|
|
218
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return e;
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region packages/web-c/component-dts/src/generatePropTypeDeclarations.ts
|
|
225
|
+
function generatePropTypeDeclarations(components, options = {}) {
|
|
226
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
227
|
+
const conflicts = /* @__PURE__ */ new Set();
|
|
228
|
+
for (const component of components) for (const prop of Object.values(component.props)) {
|
|
229
|
+
const declaration = prop.declaration;
|
|
230
|
+
const reference = declaration === null || declaration === void 0 ? void 0 : declaration.reference;
|
|
231
|
+
if (!reference) continue;
|
|
232
|
+
const existing = declarations.get(reference);
|
|
233
|
+
if (existing && existing !== declaration.type) {
|
|
234
|
+
conflicts.add(reference);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
declarations.set(reference, declaration.type);
|
|
238
|
+
}
|
|
239
|
+
for (const reference of conflicts) declarations.delete(reference);
|
|
240
|
+
const allocatedNames = allocateDeclarationNames(declarations.keys(), options.reservedNames);
|
|
241
|
+
const normalizedComponents = components.map((component) => normalizeDeclarations(component, conflicts, allocatedNames));
|
|
242
|
+
const declarationPrefix = options.exported === false ? "type" : "export type";
|
|
243
|
+
return {
|
|
244
|
+
code: Array.from(declarations, ([name, type]) => {
|
|
245
|
+
return `${declarationPrefix} ${allocatedNames.get(name)} = ${type}`;
|
|
246
|
+
}).join("\n"),
|
|
247
|
+
components: normalizedComponents
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
function allocateDeclarationNames(references, reservedNames) {
|
|
251
|
+
const sourceNames = Array.from(references);
|
|
252
|
+
const used = new Set(reservedNames);
|
|
253
|
+
const result = /* @__PURE__ */ new Map();
|
|
254
|
+
for (const name of sourceNames) if (!used.has(name)) used.add(name);
|
|
255
|
+
for (const name of sourceNames) {
|
|
256
|
+
if (!(reservedNames === null || reservedNames === void 0 ? void 0 : reservedNames.has(name))) {
|
|
257
|
+
result.set(name, name);
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
const base = `${name}PropType`;
|
|
261
|
+
let candidate = base;
|
|
262
|
+
let suffix = 2;
|
|
263
|
+
while (used.has(candidate)) {
|
|
264
|
+
candidate = `${base}${suffix}`;
|
|
265
|
+
suffix += 1;
|
|
266
|
+
}
|
|
267
|
+
used.add(candidate);
|
|
268
|
+
result.set(name, candidate);
|
|
269
|
+
}
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
function normalizeDeclarations(component, conflicts, allocatedNames) {
|
|
273
|
+
let changed = false;
|
|
274
|
+
const props = Object.fromEntries(Object.entries(component.props).map(([name, prop]) => {
|
|
275
|
+
const declaration = prop.declaration;
|
|
276
|
+
if (!(declaration === null || declaration === void 0 ? void 0 : declaration.reference)) return [name, prop];
|
|
277
|
+
const reference = declaration.reference;
|
|
278
|
+
const allocatedName = allocatedNames.get(reference);
|
|
279
|
+
if (!conflicts.has(reference) && allocatedName === reference) return [name, prop];
|
|
280
|
+
changed = true;
|
|
281
|
+
return [name, _objectSpread2(_objectSpread2({}, prop), {}, { declaration: conflicts.has(reference) ? { type: declaration.type } : _objectSpread2(_objectSpread2({}, declaration), {}, { reference: allocatedName }) })];
|
|
282
|
+
}));
|
|
283
|
+
return changed ? _objectSpread2(_objectSpread2({}, component), {}, { props }) : component;
|
|
284
|
+
}
|
|
285
|
+
//#endregion
|
|
137
286
|
//#region packages/web-c/component-dts/src/generateWcDts.ts
|
|
138
287
|
function generateComponentWCDts(component) {
|
|
139
|
-
|
|
288
|
+
return generateComponentWCDtsFile(component);
|
|
289
|
+
}
|
|
290
|
+
function generateComponentWCDtsFile(component, options = {}) {
|
|
291
|
+
var _options$exportPropTy, _propTypeDeclarations;
|
|
292
|
+
const propTypeDeclarations = generatePropTypeDeclarations([component], {
|
|
293
|
+
exported: (_options$exportPropTy = options.exportPropTypes) !== null && _options$exportPropTy !== void 0 ? _options$exportPropTy : true,
|
|
294
|
+
reservedNames: mergeReservedNames(getGeneratedDeclarationNames([component]), options.reservedNames)
|
|
295
|
+
});
|
|
296
|
+
const resolvedComponent = (_propTypeDeclarations = propTypeDeclarations.components[0]) !== null && _propTypeDeclarations !== void 0 ? _propTypeDeclarations : component;
|
|
297
|
+
const elementTypeName = getElementTypeName(resolvedComponent);
|
|
140
298
|
const lines = [];
|
|
141
299
|
lines.push("/* eslint-disable */");
|
|
142
300
|
lines.push("// Generated by @zeus-js/component-dts.");
|
|
143
301
|
lines.push("");
|
|
144
|
-
|
|
302
|
+
if (propTypeDeclarations.code) {
|
|
303
|
+
lines.push(propTypeDeclarations.code);
|
|
304
|
+
lines.push("");
|
|
305
|
+
}
|
|
306
|
+
lines.push(generateEventMap(resolvedComponent));
|
|
145
307
|
lines.push("");
|
|
146
|
-
lines.push(generateElementInterface(
|
|
308
|
+
lines.push(generateElementInterface(resolvedComponent));
|
|
147
309
|
lines.push("");
|
|
148
|
-
lines.push(`export declare const ${
|
|
310
|
+
lines.push(`export declare const ${resolvedComponent.exportName}: {`);
|
|
149
311
|
lines.push(` new (): ${elementTypeName}`);
|
|
150
312
|
lines.push("}");
|
|
151
313
|
lines.push("");
|
|
@@ -157,7 +319,11 @@ function generateWCIndexDts(manifest, options) {
|
|
|
157
319
|
lines.push("// Generated by @zeus-js/component-dts.");
|
|
158
320
|
lines.push("");
|
|
159
321
|
for (const component of manifest.components) lines.push(`import type { ${getElementTypeName(component)} } from ${JSON.stringify(options.getComponentImportPath(component))}`);
|
|
160
|
-
for (const component of manifest.components)
|
|
322
|
+
for (const component of manifest.components) {
|
|
323
|
+
const importPath = JSON.stringify(options.getComponentImportPath(component));
|
|
324
|
+
lines.push(`export { ${component.exportName} } from ${importPath}`);
|
|
325
|
+
lines.push(`export type { ${getElementTypeName(component)}, ${getEventMapTypeName(component)} } from ${importPath}`);
|
|
326
|
+
}
|
|
161
327
|
lines.push("");
|
|
162
328
|
lines.push("declare global {");
|
|
163
329
|
lines.push(" interface HTMLElementTagNameMap {");
|
|
@@ -186,6 +352,9 @@ function generateElementInterface(component) {
|
|
|
186
352
|
function toKebabCase$1(value) {
|
|
187
353
|
return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
188
354
|
}
|
|
355
|
+
function mergeReservedNames(defaults, additional) {
|
|
356
|
+
return /* @__PURE__ */ new Set([...defaults, ...additional !== null && additional !== void 0 ? additional : []]);
|
|
357
|
+
}
|
|
189
358
|
//#endregion
|
|
190
359
|
//#region packages/web-c/component-dts/src/generateJsxDts.ts
|
|
191
360
|
function generateWCJsxDts(manifest) {
|
|
@@ -193,7 +362,14 @@ function generateWCJsxDts(manifest) {
|
|
|
193
362
|
lines.push("/* eslint-disable */");
|
|
194
363
|
lines.push("// Generated by @zeus-js/component-dts.");
|
|
195
364
|
lines.push("");
|
|
196
|
-
|
|
365
|
+
const reservedNames = getGeneratedDeclarationNames(manifest.components);
|
|
366
|
+
reservedNames.add("JSX");
|
|
367
|
+
const propTypeDeclarations = generatePropTypeDeclarations(manifest.components, { reservedNames });
|
|
368
|
+
if (propTypeDeclarations.code) {
|
|
369
|
+
lines.push(propTypeDeclarations.code);
|
|
370
|
+
lines.push("");
|
|
371
|
+
}
|
|
372
|
+
for (const component of propTypeDeclarations.components) {
|
|
197
373
|
lines.push(generateComponentJsxProps(component));
|
|
198
374
|
lines.push("");
|
|
199
375
|
}
|
|
@@ -249,7 +425,14 @@ function generateReactDts(manifest, options = {}) {
|
|
|
249
425
|
lines.push("");
|
|
250
426
|
lines.push(`import type * as React from 'react'`);
|
|
251
427
|
lines.push("");
|
|
252
|
-
|
|
428
|
+
const reservedNames = getGeneratedDeclarationNames(manifest.components);
|
|
429
|
+
reservedNames.add("React");
|
|
430
|
+
const propTypeDeclarations = generatePropTypeDeclarations(manifest.components, { reservedNames });
|
|
431
|
+
if (propTypeDeclarations.code) {
|
|
432
|
+
lines.push(propTypeDeclarations.code);
|
|
433
|
+
lines.push("");
|
|
434
|
+
}
|
|
435
|
+
for (const component of propTypeDeclarations.components) {
|
|
253
436
|
lines.push(generateReactComponentDts(component, options));
|
|
254
437
|
lines.push("");
|
|
255
438
|
}
|
|
@@ -299,7 +482,14 @@ function generateVueDts(manifest) {
|
|
|
299
482
|
lines.push("");
|
|
300
483
|
lines.push(`import type { DefineComponent } from 'vue'`);
|
|
301
484
|
lines.push("");
|
|
302
|
-
|
|
485
|
+
const reservedNames = getGeneratedDeclarationNames(manifest.components);
|
|
486
|
+
reservedNames.add("DefineComponent");
|
|
487
|
+
const propTypeDeclarations = generatePropTypeDeclarations(manifest.components, { reservedNames });
|
|
488
|
+
if (propTypeDeclarations.code) {
|
|
489
|
+
lines.push(propTypeDeclarations.code);
|
|
490
|
+
lines.push("");
|
|
491
|
+
}
|
|
492
|
+
for (const component of propTypeDeclarations.components) {
|
|
303
493
|
lines.push(generateVueComponentDts(component));
|
|
304
494
|
lines.push("");
|
|
305
495
|
}
|
|
@@ -370,9 +560,14 @@ function toKebabCase(value) {
|
|
|
370
560
|
function generateWCDtsFiles(manifest, options = {}) {
|
|
371
561
|
const normalized = normalizeOptions(options);
|
|
372
562
|
const files = [];
|
|
373
|
-
|
|
563
|
+
const reservedNames = getGeneratedDeclarationNames(manifest.components);
|
|
564
|
+
const resolvedComponents = generatePropTypeDeclarations(manifest.components, { reservedNames }).components;
|
|
565
|
+
if (normalized.perComponent) for (const component of resolvedComponents) files.push({
|
|
374
566
|
fileName: path.posix.join(normalized.outDir, getComponentDtsFileName(component.tag, normalized)),
|
|
375
|
-
source:
|
|
567
|
+
source: generateComponentWCDtsFile(component, {
|
|
568
|
+
exportPropTypes: false,
|
|
569
|
+
reservedNames
|
|
570
|
+
})
|
|
376
571
|
});
|
|
377
572
|
if (normalized.index) files.push({
|
|
378
573
|
fileName: path.posix.join(normalized.outDir, "index.d.ts"),
|
|
@@ -402,7 +597,12 @@ function generateLoaderDts(manifest) {
|
|
|
402
597
|
lines.push("/* eslint-disable */");
|
|
403
598
|
lines.push("// Generated by @zeus-js/component-dts.");
|
|
404
599
|
lines.push("");
|
|
405
|
-
|
|
600
|
+
const propTypeDeclarations = generatePropTypeDeclarations(manifest.components, { reservedNames: getGeneratedDeclarationNames(manifest.components) });
|
|
601
|
+
if (propTypeDeclarations.code) {
|
|
602
|
+
lines.push(propTypeDeclarations.code);
|
|
603
|
+
lines.push("");
|
|
604
|
+
}
|
|
605
|
+
for (const component of propTypeDeclarations.components) {
|
|
406
606
|
lines.push(generateElementType(component, {
|
|
407
607
|
componentOnReady: true,
|
|
408
608
|
forcePromise: true
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* component-dts v0.1.1-beta.
|
|
2
|
+
* component-dts v0.1.1-beta.10
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
@@ -29,11 +29,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
29
29
|
enumerable: true
|
|
30
30
|
}) : target, mod));
|
|
31
31
|
//#endregion
|
|
32
|
+
let _zeus_js_component_analyzer = require("@zeus-js/component-analyzer");
|
|
32
33
|
let node_path = require("node:path");
|
|
33
34
|
node_path = __toESM(node_path, 1);
|
|
34
35
|
//#region packages/web-c/component-dts/src/formatType.ts
|
|
35
36
|
function formatPropType(prop) {
|
|
36
37
|
var _prop$values;
|
|
38
|
+
if (prop.declaration) {
|
|
39
|
+
var _prop$declaration$ref;
|
|
40
|
+
return (_prop$declaration$ref = prop.declaration.reference) !== null && _prop$declaration$ref !== void 0 ? _prop$declaration$ref : prop.declaration.type;
|
|
41
|
+
}
|
|
37
42
|
if ((_prop$values = prop.values) === null || _prop$values === void 0 ? void 0 : _prop$values.length) return prop.values.map((value) => JSON.stringify(value)).join(" | ");
|
|
38
43
|
switch (prop.type) {
|
|
39
44
|
case "string": return "string";
|
|
@@ -64,6 +69,7 @@ function normalizeKnownType(type) {
|
|
|
64
69
|
case "FocusEvent":
|
|
65
70
|
case "InputEvent":
|
|
66
71
|
case "Event": return type;
|
|
72
|
+
case "function": return "Function";
|
|
67
73
|
case "object": return "Record<string, unknown>";
|
|
68
74
|
case "array": return "unknown[]";
|
|
69
75
|
default: return type || "unknown";
|
|
@@ -100,6 +106,26 @@ function getEventMapTypeName(component) {
|
|
|
100
106
|
function getPropsTypeName(component) {
|
|
101
107
|
return `${component.name}Props`;
|
|
102
108
|
}
|
|
109
|
+
function getGeneratedDeclarationNames(components) {
|
|
110
|
+
const names = new Set(_zeus_js_component_analyzer.PORTABLE_GLOBAL_TYPE_REFERENCES);
|
|
111
|
+
names.add("HTMLElementTagNameMap");
|
|
112
|
+
names.add("JSX");
|
|
113
|
+
names.add("React");
|
|
114
|
+
names.add("DefineComponent");
|
|
115
|
+
names.add("GlobalComponents");
|
|
116
|
+
for (const component of components) {
|
|
117
|
+
const elementTypeName = getElementTypeName(component);
|
|
118
|
+
names.add(component.name);
|
|
119
|
+
names.add(component.exportName);
|
|
120
|
+
names.add(elementTypeName);
|
|
121
|
+
names.add(`${elementTypeName}Props`);
|
|
122
|
+
names.add(`${elementTypeName}Methods`);
|
|
123
|
+
names.add(`${elementTypeName}EventTarget`);
|
|
124
|
+
names.add(getEventMapTypeName(component));
|
|
125
|
+
names.add(getPropsTypeName(component));
|
|
126
|
+
}
|
|
127
|
+
return names;
|
|
128
|
+
}
|
|
103
129
|
function getComponentFileBaseName(tag, options) {
|
|
104
130
|
if (options.fileName) return sanitizeFileName(options.fileName(tag)).replace(/\.d\.ts$/, "");
|
|
105
131
|
let name = tag;
|
|
@@ -161,18 +187,102 @@ function generateEventTargetType(elementTypeName, eventTargetTypeName, eventMapT
|
|
|
161
187
|
return lines.join("\n");
|
|
162
188
|
}
|
|
163
189
|
//#endregion
|
|
190
|
+
//#region packages/web-c/component-dts/src/generatePropTypeDeclarations.ts
|
|
191
|
+
function generatePropTypeDeclarations(components, options = {}) {
|
|
192
|
+
const declarations = /* @__PURE__ */ new Map();
|
|
193
|
+
const conflicts = /* @__PURE__ */ new Set();
|
|
194
|
+
for (const component of components) for (const prop of Object.values(component.props)) {
|
|
195
|
+
const declaration = prop.declaration;
|
|
196
|
+
const reference = declaration === null || declaration === void 0 ? void 0 : declaration.reference;
|
|
197
|
+
if (!reference) continue;
|
|
198
|
+
const existing = declarations.get(reference);
|
|
199
|
+
if (existing && existing !== declaration.type) {
|
|
200
|
+
conflicts.add(reference);
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
declarations.set(reference, declaration.type);
|
|
204
|
+
}
|
|
205
|
+
for (const reference of conflicts) declarations.delete(reference);
|
|
206
|
+
const allocatedNames = allocateDeclarationNames(declarations.keys(), options.reservedNames);
|
|
207
|
+
const normalizedComponents = components.map((component) => normalizeDeclarations(component, conflicts, allocatedNames));
|
|
208
|
+
const declarationPrefix = options.exported === false ? "type" : "export type";
|
|
209
|
+
return {
|
|
210
|
+
code: Array.from(declarations, ([name, type]) => {
|
|
211
|
+
return `${declarationPrefix} ${allocatedNames.get(name)} = ${type}`;
|
|
212
|
+
}).join("\n"),
|
|
213
|
+
components: normalizedComponents
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function allocateDeclarationNames(references, reservedNames) {
|
|
217
|
+
const sourceNames = Array.from(references);
|
|
218
|
+
const used = new Set(reservedNames);
|
|
219
|
+
const result = /* @__PURE__ */ new Map();
|
|
220
|
+
for (const name of sourceNames) if (!used.has(name)) used.add(name);
|
|
221
|
+
for (const name of sourceNames) {
|
|
222
|
+
if (!(reservedNames === null || reservedNames === void 0 ? void 0 : reservedNames.has(name))) {
|
|
223
|
+
result.set(name, name);
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
const base = `${name}PropType`;
|
|
227
|
+
let candidate = base;
|
|
228
|
+
let suffix = 2;
|
|
229
|
+
while (used.has(candidate)) {
|
|
230
|
+
candidate = `${base}${suffix}`;
|
|
231
|
+
suffix += 1;
|
|
232
|
+
}
|
|
233
|
+
used.add(candidate);
|
|
234
|
+
result.set(name, candidate);
|
|
235
|
+
}
|
|
236
|
+
return result;
|
|
237
|
+
}
|
|
238
|
+
function normalizeDeclarations(component, conflicts, allocatedNames) {
|
|
239
|
+
let changed = false;
|
|
240
|
+
const props = Object.fromEntries(Object.entries(component.props).map(([name, prop]) => {
|
|
241
|
+
const declaration = prop.declaration;
|
|
242
|
+
if (!(declaration === null || declaration === void 0 ? void 0 : declaration.reference)) return [name, prop];
|
|
243
|
+
const reference = declaration.reference;
|
|
244
|
+
const allocatedName = allocatedNames.get(reference);
|
|
245
|
+
if (!conflicts.has(reference) && allocatedName === reference) return [name, prop];
|
|
246
|
+
changed = true;
|
|
247
|
+
return [name, {
|
|
248
|
+
...prop,
|
|
249
|
+
declaration: conflicts.has(reference) ? { type: declaration.type } : {
|
|
250
|
+
...declaration,
|
|
251
|
+
reference: allocatedName
|
|
252
|
+
}
|
|
253
|
+
}];
|
|
254
|
+
}));
|
|
255
|
+
return changed ? {
|
|
256
|
+
...component,
|
|
257
|
+
props
|
|
258
|
+
} : component;
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
164
261
|
//#region packages/web-c/component-dts/src/generateWcDts.ts
|
|
165
262
|
function generateComponentWCDts(component) {
|
|
166
|
-
|
|
263
|
+
return generateComponentWCDtsFile(component);
|
|
264
|
+
}
|
|
265
|
+
function generateComponentWCDtsFile(component, options = {}) {
|
|
266
|
+
var _options$exportPropTy, _propTypeDeclarations;
|
|
267
|
+
const propTypeDeclarations = generatePropTypeDeclarations([component], {
|
|
268
|
+
exported: (_options$exportPropTy = options.exportPropTypes) !== null && _options$exportPropTy !== void 0 ? _options$exportPropTy : true,
|
|
269
|
+
reservedNames: mergeReservedNames(getGeneratedDeclarationNames([component]), options.reservedNames)
|
|
270
|
+
});
|
|
271
|
+
const resolvedComponent = (_propTypeDeclarations = propTypeDeclarations.components[0]) !== null && _propTypeDeclarations !== void 0 ? _propTypeDeclarations : component;
|
|
272
|
+
const elementTypeName = getElementTypeName(resolvedComponent);
|
|
167
273
|
const lines = [];
|
|
168
274
|
lines.push("/* eslint-disable */");
|
|
169
275
|
lines.push("// Generated by @zeus-js/component-dts.");
|
|
170
276
|
lines.push("");
|
|
171
|
-
|
|
277
|
+
if (propTypeDeclarations.code) {
|
|
278
|
+
lines.push(propTypeDeclarations.code);
|
|
279
|
+
lines.push("");
|
|
280
|
+
}
|
|
281
|
+
lines.push(generateEventMap(resolvedComponent));
|
|
172
282
|
lines.push("");
|
|
173
|
-
lines.push(generateElementInterface(
|
|
283
|
+
lines.push(generateElementInterface(resolvedComponent));
|
|
174
284
|
lines.push("");
|
|
175
|
-
lines.push(`export declare const ${
|
|
285
|
+
lines.push(`export declare const ${resolvedComponent.exportName}: {`);
|
|
176
286
|
lines.push(` new (): ${elementTypeName}`);
|
|
177
287
|
lines.push("}");
|
|
178
288
|
lines.push("");
|
|
@@ -184,7 +294,11 @@ function generateWCIndexDts(manifest, options) {
|
|
|
184
294
|
lines.push("// Generated by @zeus-js/component-dts.");
|
|
185
295
|
lines.push("");
|
|
186
296
|
for (const component of manifest.components) lines.push(`import type { ${getElementTypeName(component)} } from ${JSON.stringify(options.getComponentImportPath(component))}`);
|
|
187
|
-
for (const component of manifest.components)
|
|
297
|
+
for (const component of manifest.components) {
|
|
298
|
+
const importPath = JSON.stringify(options.getComponentImportPath(component));
|
|
299
|
+
lines.push(`export { ${component.exportName} } from ${importPath}`);
|
|
300
|
+
lines.push(`export type { ${getElementTypeName(component)}, ${getEventMapTypeName(component)} } from ${importPath}`);
|
|
301
|
+
}
|
|
188
302
|
lines.push("");
|
|
189
303
|
lines.push("declare global {");
|
|
190
304
|
lines.push(" interface HTMLElementTagNameMap {");
|
|
@@ -213,6 +327,9 @@ function generateElementInterface(component) {
|
|
|
213
327
|
function toKebabCase$1(value) {
|
|
214
328
|
return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
215
329
|
}
|
|
330
|
+
function mergeReservedNames(defaults, additional) {
|
|
331
|
+
return /* @__PURE__ */ new Set([...defaults, ...additional !== null && additional !== void 0 ? additional : []]);
|
|
332
|
+
}
|
|
216
333
|
//#endregion
|
|
217
334
|
//#region packages/web-c/component-dts/src/generateJsxDts.ts
|
|
218
335
|
function generateWCJsxDts(manifest) {
|
|
@@ -220,7 +337,14 @@ function generateWCJsxDts(manifest) {
|
|
|
220
337
|
lines.push("/* eslint-disable */");
|
|
221
338
|
lines.push("// Generated by @zeus-js/component-dts.");
|
|
222
339
|
lines.push("");
|
|
223
|
-
|
|
340
|
+
const reservedNames = getGeneratedDeclarationNames(manifest.components);
|
|
341
|
+
reservedNames.add("JSX");
|
|
342
|
+
const propTypeDeclarations = generatePropTypeDeclarations(manifest.components, { reservedNames });
|
|
343
|
+
if (propTypeDeclarations.code) {
|
|
344
|
+
lines.push(propTypeDeclarations.code);
|
|
345
|
+
lines.push("");
|
|
346
|
+
}
|
|
347
|
+
for (const component of propTypeDeclarations.components) {
|
|
224
348
|
lines.push(generateComponentJsxProps(component));
|
|
225
349
|
lines.push("");
|
|
226
350
|
}
|
|
@@ -276,7 +400,14 @@ function generateReactDts(manifest, options = {}) {
|
|
|
276
400
|
lines.push("");
|
|
277
401
|
lines.push(`import type * as React from 'react'`);
|
|
278
402
|
lines.push("");
|
|
279
|
-
|
|
403
|
+
const reservedNames = getGeneratedDeclarationNames(manifest.components);
|
|
404
|
+
reservedNames.add("React");
|
|
405
|
+
const propTypeDeclarations = generatePropTypeDeclarations(manifest.components, { reservedNames });
|
|
406
|
+
if (propTypeDeclarations.code) {
|
|
407
|
+
lines.push(propTypeDeclarations.code);
|
|
408
|
+
lines.push("");
|
|
409
|
+
}
|
|
410
|
+
for (const component of propTypeDeclarations.components) {
|
|
280
411
|
lines.push(generateReactComponentDts(component, options));
|
|
281
412
|
lines.push("");
|
|
282
413
|
}
|
|
@@ -326,7 +457,14 @@ function generateVueDts(manifest) {
|
|
|
326
457
|
lines.push("");
|
|
327
458
|
lines.push(`import type { DefineComponent } from 'vue'`);
|
|
328
459
|
lines.push("");
|
|
329
|
-
|
|
460
|
+
const reservedNames = getGeneratedDeclarationNames(manifest.components);
|
|
461
|
+
reservedNames.add("DefineComponent");
|
|
462
|
+
const propTypeDeclarations = generatePropTypeDeclarations(manifest.components, { reservedNames });
|
|
463
|
+
if (propTypeDeclarations.code) {
|
|
464
|
+
lines.push(propTypeDeclarations.code);
|
|
465
|
+
lines.push("");
|
|
466
|
+
}
|
|
467
|
+
for (const component of propTypeDeclarations.components) {
|
|
330
468
|
lines.push(generateVueComponentDts(component));
|
|
331
469
|
lines.push("");
|
|
332
470
|
}
|
|
@@ -397,9 +535,14 @@ function toKebabCase(value) {
|
|
|
397
535
|
function generateWCDtsFiles(manifest, options = {}) {
|
|
398
536
|
const normalized = normalizeOptions(options);
|
|
399
537
|
const files = [];
|
|
400
|
-
|
|
538
|
+
const reservedNames = getGeneratedDeclarationNames(manifest.components);
|
|
539
|
+
const resolvedComponents = generatePropTypeDeclarations(manifest.components, { reservedNames }).components;
|
|
540
|
+
if (normalized.perComponent) for (const component of resolvedComponents) files.push({
|
|
401
541
|
fileName: node_path.default.posix.join(normalized.outDir, getComponentDtsFileName(component.tag, normalized)),
|
|
402
|
-
source:
|
|
542
|
+
source: generateComponentWCDtsFile(component, {
|
|
543
|
+
exportPropTypes: false,
|
|
544
|
+
reservedNames
|
|
545
|
+
})
|
|
403
546
|
});
|
|
404
547
|
if (normalized.index) files.push({
|
|
405
548
|
fileName: node_path.default.posix.join(normalized.outDir, "index.d.ts"),
|
|
@@ -429,7 +572,12 @@ function generateLoaderDts(manifest) {
|
|
|
429
572
|
lines.push("/* eslint-disable */");
|
|
430
573
|
lines.push("// Generated by @zeus-js/component-dts.");
|
|
431
574
|
lines.push("");
|
|
432
|
-
|
|
575
|
+
const propTypeDeclarations = generatePropTypeDeclarations(manifest.components, { reservedNames: getGeneratedDeclarationNames(manifest.components) });
|
|
576
|
+
if (propTypeDeclarations.code) {
|
|
577
|
+
lines.push(propTypeDeclarations.code);
|
|
578
|
+
lines.push("");
|
|
579
|
+
}
|
|
580
|
+
for (const component of propTypeDeclarations.components) {
|
|
433
581
|
lines.push(generateElementType(component, {
|
|
434
582
|
componentOnReady: true,
|
|
435
583
|
forcePromise: true
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeus-js/component-dts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.1-beta.
|
|
4
|
+
"version": "0.1.1-beta.10",
|
|
5
5
|
"description": "DTS generators for Zeus component manifest",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"dist"
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@zeus-js/component-analyzer": "0.1.1-beta.
|
|
34
|
+
"@zeus-js/component-analyzer": "0.1.1-beta.10"
|
|
35
35
|
},
|
|
36
36
|
"author": "Baicie",
|
|
37
37
|
"buildOptions": {
|