@zeus-js/component-dts 0.1.0-beta.6 → 0.1.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * component-dts v0.1.0-beta.6
2
+ * component-dts v0.1.0-beta.7
3
3
  * (c) 2026 baicie
4
4
  * Released under the MIT License.
5
5
  **/
@@ -113,6 +113,54 @@ function sanitizeFileName(value) {
113
113
  return value.trim().replace(/[^a-zA-Z0-9._-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
114
114
  }
115
115
  //#endregion
116
+ //#region packages/web-c/component-dts/src/generateElementType.ts
117
+ function generateElementType(component, options = {}) {
118
+ var _component$methods;
119
+ const elementTypeName = getElementTypeName(component);
120
+ const propsTypeName = `${elementTypeName}Props`;
121
+ const methodsTypeName = `${elementTypeName}Methods`;
122
+ const eventTargetTypeName = `${elementTypeName}EventTarget`;
123
+ const lines = [];
124
+ lines.push(`interface ${propsTypeName} {`);
125
+ for (const [name, prop] of Object.entries(component.props)) {
126
+ const optional = isRequiredProp(prop) ? "" : "?";
127
+ lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
128
+ }
129
+ lines.push("}");
130
+ lines.push("");
131
+ lines.push(`interface ${methodsTypeName} {`);
132
+ for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method, { forcePromise: options.forcePromise })}`);
133
+ if (options.componentOnReady) lines.push(` componentOnReady(): Promise<${elementTypeName}>`);
134
+ lines.push("}");
135
+ if (options.eventMapTypeName) {
136
+ lines.push("");
137
+ lines.push(generateEventTargetType(elementTypeName, eventTargetTypeName, options.eventMapTypeName));
138
+ }
139
+ const intersections = [methodsTypeName];
140
+ if (options.eventMapTypeName) intersections.push(eventTargetTypeName);
141
+ intersections.push("HTMLElement", `Omit<${propsTypeName}, keyof HTMLElement>`);
142
+ lines.push("");
143
+ lines.push(`export type ${elementTypeName} = ${intersections.join(" & ")}`);
144
+ return lines.join("\n");
145
+ }
146
+ function generateEventTargetType(elementTypeName, eventTargetTypeName, eventMapTypeName) {
147
+ const lines = [];
148
+ lines.push(`interface ${eventTargetTypeName} {`);
149
+ lines.push(` addEventListener<K extends keyof ${eventMapTypeName}>(`);
150
+ lines.push(" type: K,");
151
+ lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapTypeName}[K]) => unknown,`);
152
+ lines.push(" options?: boolean | AddEventListenerOptions,");
153
+ lines.push(" ): void");
154
+ lines.push("");
155
+ lines.push(` removeEventListener<K extends keyof ${eventMapTypeName}>(`);
156
+ lines.push(" type: K,");
157
+ lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapTypeName}[K]) => unknown,`);
158
+ lines.push(" options?: boolean | EventListenerOptions,");
159
+ lines.push(" ): void");
160
+ lines.push("}");
161
+ return lines.join("\n");
162
+ }
163
+ //#endregion
116
164
  //#region packages/web-c/component-dts/src/generateWcDts.ts
117
165
  function generateComponentWCDts(component) {
118
166
  const elementTypeName = getElementTypeName(component);
@@ -122,7 +170,7 @@ function generateComponentWCDts(component) {
122
170
  lines.push("");
123
171
  lines.push(generateEventMap(component));
124
172
  lines.push("");
125
- lines.push(generateElementInterface$1(component));
173
+ lines.push(generateElementInterface(component));
126
174
  lines.push("");
127
175
  lines.push(`export declare const ${component.exportName}: {`);
128
176
  lines.push(` new (): ${elementTypeName}`);
@@ -159,43 +207,8 @@ function generateEventMap(component) {
159
207
  lines.push("}");
160
208
  return lines.join("\n");
161
209
  }
162
- function generateElementInterface$1(component) {
163
- var _component$methods;
164
- const elementTypeName = getElementTypeName(component);
165
- const eventMapName = getEventMapTypeName(component);
166
- const lines = [];
167
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
168
- for (const [name, prop] of Object.entries(component.props)) {
169
- const optional = isRequiredProp(prop) ? "" : "?";
170
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
171
- }
172
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method)}`);
173
- lines.push("");
174
- lines.push(` addEventListener<K extends keyof ${eventMapName}>(`);
175
- lines.push(" type: K,");
176
- lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapName}[K]) => unknown,`);
177
- lines.push(" options?: boolean | AddEventListenerOptions,");
178
- lines.push(" ): void");
179
- lines.push("");
180
- lines.push(" addEventListener(");
181
- lines.push(" type: string,");
182
- lines.push(" listener: EventListenerOrEventListenerObject | null,");
183
- lines.push(" options?: boolean | AddEventListenerOptions,");
184
- lines.push(" ): void");
185
- lines.push("");
186
- lines.push(` removeEventListener<K extends keyof ${eventMapName}>(`);
187
- lines.push(" type: K,");
188
- lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapName}[K]) => unknown,`);
189
- lines.push(" options?: boolean | EventListenerOptions,");
190
- lines.push(" ): void");
191
- lines.push("");
192
- lines.push(" removeEventListener(");
193
- lines.push(" type: string,");
194
- lines.push(" listener: EventListenerOrEventListenerObject | null,");
195
- lines.push(" options?: boolean | EventListenerOptions,");
196
- lines.push(" ): void");
197
- lines.push("}");
198
- return lines.join("\n");
210
+ function generateElementInterface(component) {
211
+ return generateElementType(component, { eventMapTypeName: getEventMapTypeName(component) });
199
212
  }
200
213
  function toKebabCase$1(value) {
201
214
  return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
@@ -270,7 +283,6 @@ function generateReactDts(manifest, options = {}) {
270
283
  return lines.join("\n");
271
284
  }
272
285
  function generateReactComponentDts(component, options) {
273
- var _component$methods;
274
286
  const propsTypeName = getPropsTypeName(component);
275
287
  const elementTypeName = getElementTypeName(component);
276
288
  const lines = [];
@@ -295,13 +307,7 @@ function generateReactComponentDts(component, options) {
295
307
  }
296
308
  lines.push("}");
297
309
  lines.push("");
298
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
299
- for (const [name, prop] of Object.entries(component.props)) {
300
- const optional = isRequiredProp(prop) ? "" : "?";
301
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
302
- }
303
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method)}`);
304
- lines.push("}");
310
+ lines.push(generateElementType(component));
305
311
  lines.push("");
306
312
  lines.push(`export declare const ${component.name}: React.ForwardRefExoticComponent<`);
307
313
  lines.push(` ${propsTypeName} & React.RefAttributes<${elementTypeName}>`);
@@ -424,7 +430,10 @@ function generateLoaderDts(manifest) {
424
430
  lines.push("// Generated by @zeus-js/component-dts.");
425
431
  lines.push("");
426
432
  for (const component of manifest.components) {
427
- lines.push(generateElementInterface(component));
433
+ lines.push(generateElementType(component, {
434
+ componentOnReady: true,
435
+ forcePromise: true
436
+ }));
428
437
  lines.push("");
429
438
  }
430
439
  lines.push("export declare function defineCustomElements(): void");
@@ -441,20 +450,6 @@ function generateLoaderDts(manifest) {
441
450
  lines.push("");
442
451
  return lines.join("\n");
443
452
  }
444
- function generateElementInterface(component) {
445
- var _component$methods;
446
- const elementTypeName = getElementTypeName(component);
447
- const lines = [];
448
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
449
- for (const [name, prop] of Object.entries(component.props)) {
450
- const optional = isRequiredProp(prop) ? "" : "?";
451
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
452
- }
453
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method, { forcePromise: true })}`);
454
- lines.push(" componentOnReady(): Promise<this>");
455
- lines.push("}");
456
- return lines.join("\n");
457
- }
458
453
  //#endregion
459
454
  exports.formatDetailType = formatDetailType;
460
455
  exports.formatEventType = formatEventType;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * component-dts v0.1.0-beta.6
2
+ * component-dts v0.1.0-beta.7
3
3
  * (c) 2026 baicie
4
4
  * Released under the MIT License.
5
5
  **/
@@ -113,6 +113,54 @@ function sanitizeFileName(value) {
113
113
  return value.trim().replace(/[^a-zA-Z0-9._-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
114
114
  }
115
115
  //#endregion
116
+ //#region packages/web-c/component-dts/src/generateElementType.ts
117
+ function generateElementType(component, options = {}) {
118
+ var _component$methods;
119
+ const elementTypeName = getElementTypeName(component);
120
+ const propsTypeName = `${elementTypeName}Props`;
121
+ const methodsTypeName = `${elementTypeName}Methods`;
122
+ const eventTargetTypeName = `${elementTypeName}EventTarget`;
123
+ const lines = [];
124
+ lines.push(`interface ${propsTypeName} {`);
125
+ for (const [name, prop] of Object.entries(component.props)) {
126
+ const optional = isRequiredProp(prop) ? "" : "?";
127
+ lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
128
+ }
129
+ lines.push("}");
130
+ lines.push("");
131
+ lines.push(`interface ${methodsTypeName} {`);
132
+ for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method, { forcePromise: options.forcePromise })}`);
133
+ if (options.componentOnReady) lines.push(` componentOnReady(): Promise<${elementTypeName}>`);
134
+ lines.push("}");
135
+ if (options.eventMapTypeName) {
136
+ lines.push("");
137
+ lines.push(generateEventTargetType(elementTypeName, eventTargetTypeName, options.eventMapTypeName));
138
+ }
139
+ const intersections = [methodsTypeName];
140
+ if (options.eventMapTypeName) intersections.push(eventTargetTypeName);
141
+ intersections.push("HTMLElement", `Omit<${propsTypeName}, keyof HTMLElement>`);
142
+ lines.push("");
143
+ lines.push(`export type ${elementTypeName} = ${intersections.join(" & ")}`);
144
+ return lines.join("\n");
145
+ }
146
+ function generateEventTargetType(elementTypeName, eventTargetTypeName, eventMapTypeName) {
147
+ const lines = [];
148
+ lines.push(`interface ${eventTargetTypeName} {`);
149
+ lines.push(` addEventListener<K extends keyof ${eventMapTypeName}>(`);
150
+ lines.push(" type: K,");
151
+ lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapTypeName}[K]) => unknown,`);
152
+ lines.push(" options?: boolean | AddEventListenerOptions,");
153
+ lines.push(" ): void");
154
+ lines.push("");
155
+ lines.push(` removeEventListener<K extends keyof ${eventMapTypeName}>(`);
156
+ lines.push(" type: K,");
157
+ lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapTypeName}[K]) => unknown,`);
158
+ lines.push(" options?: boolean | EventListenerOptions,");
159
+ lines.push(" ): void");
160
+ lines.push("}");
161
+ return lines.join("\n");
162
+ }
163
+ //#endregion
116
164
  //#region packages/web-c/component-dts/src/generateWcDts.ts
117
165
  function generateComponentWCDts(component) {
118
166
  const elementTypeName = getElementTypeName(component);
@@ -122,7 +170,7 @@ function generateComponentWCDts(component) {
122
170
  lines.push("");
123
171
  lines.push(generateEventMap(component));
124
172
  lines.push("");
125
- lines.push(generateElementInterface$1(component));
173
+ lines.push(generateElementInterface(component));
126
174
  lines.push("");
127
175
  lines.push(`export declare const ${component.exportName}: {`);
128
176
  lines.push(` new (): ${elementTypeName}`);
@@ -159,43 +207,8 @@ function generateEventMap(component) {
159
207
  lines.push("}");
160
208
  return lines.join("\n");
161
209
  }
162
- function generateElementInterface$1(component) {
163
- var _component$methods;
164
- const elementTypeName = getElementTypeName(component);
165
- const eventMapName = getEventMapTypeName(component);
166
- const lines = [];
167
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
168
- for (const [name, prop] of Object.entries(component.props)) {
169
- const optional = isRequiredProp(prop) ? "" : "?";
170
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
171
- }
172
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method)}`);
173
- lines.push("");
174
- lines.push(` addEventListener<K extends keyof ${eventMapName}>(`);
175
- lines.push(" type: K,");
176
- lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapName}[K]) => unknown,`);
177
- lines.push(" options?: boolean | AddEventListenerOptions,");
178
- lines.push(" ): void");
179
- lines.push("");
180
- lines.push(" addEventListener(");
181
- lines.push(" type: string,");
182
- lines.push(" listener: EventListenerOrEventListenerObject | null,");
183
- lines.push(" options?: boolean | AddEventListenerOptions,");
184
- lines.push(" ): void");
185
- lines.push("");
186
- lines.push(` removeEventListener<K extends keyof ${eventMapName}>(`);
187
- lines.push(" type: K,");
188
- lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapName}[K]) => unknown,`);
189
- lines.push(" options?: boolean | EventListenerOptions,");
190
- lines.push(" ): void");
191
- lines.push("");
192
- lines.push(" removeEventListener(");
193
- lines.push(" type: string,");
194
- lines.push(" listener: EventListenerOrEventListenerObject | null,");
195
- lines.push(" options?: boolean | EventListenerOptions,");
196
- lines.push(" ): void");
197
- lines.push("}");
198
- return lines.join("\n");
210
+ function generateElementInterface(component) {
211
+ return generateElementType(component, { eventMapTypeName: getEventMapTypeName(component) });
199
212
  }
200
213
  function toKebabCase$1(value) {
201
214
  return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
@@ -270,7 +283,6 @@ function generateReactDts(manifest, options = {}) {
270
283
  return lines.join("\n");
271
284
  }
272
285
  function generateReactComponentDts(component, options) {
273
- var _component$methods;
274
286
  const propsTypeName = getPropsTypeName(component);
275
287
  const elementTypeName = getElementTypeName(component);
276
288
  const lines = [];
@@ -295,13 +307,7 @@ function generateReactComponentDts(component, options) {
295
307
  }
296
308
  lines.push("}");
297
309
  lines.push("");
298
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
299
- for (const [name, prop] of Object.entries(component.props)) {
300
- const optional = isRequiredProp(prop) ? "" : "?";
301
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
302
- }
303
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method)}`);
304
- lines.push("}");
310
+ lines.push(generateElementType(component));
305
311
  lines.push("");
306
312
  lines.push(`export declare const ${component.name}: React.ForwardRefExoticComponent<`);
307
313
  lines.push(` ${propsTypeName} & React.RefAttributes<${elementTypeName}>`);
@@ -424,7 +430,10 @@ function generateLoaderDts(manifest) {
424
430
  lines.push("// Generated by @zeus-js/component-dts.");
425
431
  lines.push("");
426
432
  for (const component of manifest.components) {
427
- lines.push(generateElementInterface(component));
433
+ lines.push(generateElementType(component, {
434
+ componentOnReady: true,
435
+ forcePromise: true
436
+ }));
428
437
  lines.push("");
429
438
  }
430
439
  lines.push("export declare function defineCustomElements(): void");
@@ -441,20 +450,6 @@ function generateLoaderDts(manifest) {
441
450
  lines.push("");
442
451
  return lines.join("\n");
443
452
  }
444
- function generateElementInterface(component) {
445
- var _component$methods;
446
- const elementTypeName = getElementTypeName(component);
447
- const lines = [];
448
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
449
- for (const [name, prop] of Object.entries(component.props)) {
450
- const optional = isRequiredProp(prop) ? "" : "?";
451
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
452
- }
453
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method, { forcePromise: true })}`);
454
- lines.push(" componentOnReady(): Promise<this>");
455
- lines.push("}");
456
- return lines.join("\n");
457
- }
458
453
  //#endregion
459
454
  exports.formatDetailType = formatDetailType;
460
455
  exports.formatEventType = formatEventType;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * component-dts v0.1.0-beta.6
2
+ * component-dts v0.1.0-beta.7
3
3
  * (c) 2026 baicie
4
4
  * Released under the MIT License.
5
5
  **/
@@ -86,6 +86,54 @@ function sanitizeFileName(value) {
86
86
  return value.trim().replace(/[^a-zA-Z0-9._-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
87
87
  }
88
88
  //#endregion
89
+ //#region packages/web-c/component-dts/src/generateElementType.ts
90
+ function generateElementType(component, options = {}) {
91
+ var _component$methods;
92
+ const elementTypeName = getElementTypeName(component);
93
+ const propsTypeName = `${elementTypeName}Props`;
94
+ const methodsTypeName = `${elementTypeName}Methods`;
95
+ const eventTargetTypeName = `${elementTypeName}EventTarget`;
96
+ const lines = [];
97
+ lines.push(`interface ${propsTypeName} {`);
98
+ for (const [name, prop] of Object.entries(component.props)) {
99
+ const optional = isRequiredProp(prop) ? "" : "?";
100
+ lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
101
+ }
102
+ lines.push("}");
103
+ lines.push("");
104
+ lines.push(`interface ${methodsTypeName} {`);
105
+ for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method, { forcePromise: options.forcePromise })}`);
106
+ if (options.componentOnReady) lines.push(` componentOnReady(): Promise<${elementTypeName}>`);
107
+ lines.push("}");
108
+ if (options.eventMapTypeName) {
109
+ lines.push("");
110
+ lines.push(generateEventTargetType(elementTypeName, eventTargetTypeName, options.eventMapTypeName));
111
+ }
112
+ const intersections = [methodsTypeName];
113
+ if (options.eventMapTypeName) intersections.push(eventTargetTypeName);
114
+ intersections.push("HTMLElement", `Omit<${propsTypeName}, keyof HTMLElement>`);
115
+ lines.push("");
116
+ lines.push(`export type ${elementTypeName} = ${intersections.join(" & ")}`);
117
+ return lines.join("\n");
118
+ }
119
+ function generateEventTargetType(elementTypeName, eventTargetTypeName, eventMapTypeName) {
120
+ const lines = [];
121
+ lines.push(`interface ${eventTargetTypeName} {`);
122
+ lines.push(` addEventListener<K extends keyof ${eventMapTypeName}>(`);
123
+ lines.push(" type: K,");
124
+ lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapTypeName}[K]) => unknown,`);
125
+ lines.push(" options?: boolean | AddEventListenerOptions,");
126
+ lines.push(" ): void");
127
+ lines.push("");
128
+ lines.push(` removeEventListener<K extends keyof ${eventMapTypeName}>(`);
129
+ lines.push(" type: K,");
130
+ lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapTypeName}[K]) => unknown,`);
131
+ lines.push(" options?: boolean | EventListenerOptions,");
132
+ lines.push(" ): void");
133
+ lines.push("}");
134
+ return lines.join("\n");
135
+ }
136
+ //#endregion
89
137
  //#region packages/web-c/component-dts/src/generateWcDts.ts
90
138
  function generateComponentWCDts(component) {
91
139
  const elementTypeName = getElementTypeName(component);
@@ -95,7 +143,7 @@ function generateComponentWCDts(component) {
95
143
  lines.push("");
96
144
  lines.push(generateEventMap(component));
97
145
  lines.push("");
98
- lines.push(generateElementInterface$1(component));
146
+ lines.push(generateElementInterface(component));
99
147
  lines.push("");
100
148
  lines.push(`export declare const ${component.exportName}: {`);
101
149
  lines.push(` new (): ${elementTypeName}`);
@@ -132,43 +180,8 @@ function generateEventMap(component) {
132
180
  lines.push("}");
133
181
  return lines.join("\n");
134
182
  }
135
- function generateElementInterface$1(component) {
136
- var _component$methods;
137
- const elementTypeName = getElementTypeName(component);
138
- const eventMapName = getEventMapTypeName(component);
139
- const lines = [];
140
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
141
- for (const [name, prop] of Object.entries(component.props)) {
142
- const optional = isRequiredProp(prop) ? "" : "?";
143
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
144
- }
145
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method)}`);
146
- lines.push("");
147
- lines.push(` addEventListener<K extends keyof ${eventMapName}>(`);
148
- lines.push(" type: K,");
149
- lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapName}[K]) => unknown,`);
150
- lines.push(" options?: boolean | AddEventListenerOptions,");
151
- lines.push(" ): void");
152
- lines.push("");
153
- lines.push(" addEventListener(");
154
- lines.push(" type: string,");
155
- lines.push(" listener: EventListenerOrEventListenerObject | null,");
156
- lines.push(" options?: boolean | AddEventListenerOptions,");
157
- lines.push(" ): void");
158
- lines.push("");
159
- lines.push(` removeEventListener<K extends keyof ${eventMapName}>(`);
160
- lines.push(" type: K,");
161
- lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapName}[K]) => unknown,`);
162
- lines.push(" options?: boolean | EventListenerOptions,");
163
- lines.push(" ): void");
164
- lines.push("");
165
- lines.push(" removeEventListener(");
166
- lines.push(" type: string,");
167
- lines.push(" listener: EventListenerOrEventListenerObject | null,");
168
- lines.push(" options?: boolean | EventListenerOptions,");
169
- lines.push(" ): void");
170
- lines.push("}");
171
- return lines.join("\n");
183
+ function generateElementInterface(component) {
184
+ return generateElementType(component, { eventMapTypeName: getEventMapTypeName(component) });
172
185
  }
173
186
  function toKebabCase$1(value) {
174
187
  return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
@@ -243,7 +256,6 @@ function generateReactDts(manifest, options = {}) {
243
256
  return lines.join("\n");
244
257
  }
245
258
  function generateReactComponentDts(component, options) {
246
- var _component$methods;
247
259
  const propsTypeName = getPropsTypeName(component);
248
260
  const elementTypeName = getElementTypeName(component);
249
261
  const lines = [];
@@ -268,13 +280,7 @@ function generateReactComponentDts(component, options) {
268
280
  }
269
281
  lines.push("}");
270
282
  lines.push("");
271
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
272
- for (const [name, prop] of Object.entries(component.props)) {
273
- const optional = isRequiredProp(prop) ? "" : "?";
274
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
275
- }
276
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method)}`);
277
- lines.push("}");
283
+ lines.push(generateElementType(component));
278
284
  lines.push("");
279
285
  lines.push(`export declare const ${component.name}: React.ForwardRefExoticComponent<`);
280
286
  lines.push(` ${propsTypeName} & React.RefAttributes<${elementTypeName}>`);
@@ -397,7 +403,10 @@ function generateLoaderDts(manifest) {
397
403
  lines.push("// Generated by @zeus-js/component-dts.");
398
404
  lines.push("");
399
405
  for (const component of manifest.components) {
400
- lines.push(generateElementInterface(component));
406
+ lines.push(generateElementType(component, {
407
+ componentOnReady: true,
408
+ forcePromise: true
409
+ }));
401
410
  lines.push("");
402
411
  }
403
412
  lines.push("export declare function defineCustomElements(): void");
@@ -414,19 +423,5 @@ function generateLoaderDts(manifest) {
414
423
  lines.push("");
415
424
  return lines.join("\n");
416
425
  }
417
- function generateElementInterface(component) {
418
- var _component$methods;
419
- const elementTypeName = getElementTypeName(component);
420
- const lines = [];
421
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
422
- for (const [name, prop] of Object.entries(component.props)) {
423
- const optional = isRequiredProp(prop) ? "" : "?";
424
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
425
- }
426
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method, { forcePromise: true })}`);
427
- lines.push(" componentOnReady(): Promise<this>");
428
- lines.push("}");
429
- return lines.join("\n");
430
- }
431
426
  //#endregion
432
427
  export { formatDetailType, formatEventType, formatPropType, generateComponentWCDts, generateLoaderDts, generateReactDts, generateVueDts, generateVueGlobalDts, generateWCDtsFiles, generateWCIndexDts, generateWCJsxDts };
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.0-beta.6",
4
+ "version": "0.1.0-beta.7",
5
5
  "description": "DTS generators for Zeus component manifest",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -32,7 +32,7 @@
32
32
  "dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@zeus-js/component-analyzer": "0.1.0-beta.6"
35
+ "@zeus-js/component-analyzer": "0.1.0-beta.7"
36
36
  },
37
37
  "author": "Baicie",
38
38
  "buildOptions": {