@zeus-js/component-dts 0.1.0-beta.5 → 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.5
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}`);
@@ -150,42 +198,17 @@ function generateWCIndexDts(manifest, options) {
150
198
  }
151
199
  function generateEventMap(component) {
152
200
  const eventMapName = getEventMapTypeName(component);
153
- const entries = Object.entries(component.events);
154
201
  const lines = [];
155
202
  lines.push(`export interface ${eventMapName} {`);
156
- if (!entries.length) lines.push(" [key: string]: CustomEvent<unknown>");
157
- else for (const [key, event] of Object.entries(component.events)) {
203
+ for (const [key, event] of Object.entries(component.events)) {
158
204
  var _event$name, _event$key;
159
205
  lines.push(` ${safePropertyName((_event$name = event.name) !== null && _event$name !== void 0 ? _event$name : toKebabCase$1((_event$key = event.key) !== null && _event$key !== void 0 ? _event$key : key))}: ${formatEventType(event)}`);
160
206
  }
161
207
  lines.push("}");
162
208
  return lines.join("\n");
163
209
  }
164
- function generateElementInterface$1(component) {
165
- var _component$methods;
166
- const elementTypeName = getElementTypeName(component);
167
- const eventMapName = getEventMapTypeName(component);
168
- const lines = [];
169
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
170
- for (const [name, prop] of Object.entries(component.props)) {
171
- const optional = isRequiredProp(prop) ? "" : "?";
172
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
173
- }
174
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method)}`);
175
- lines.push("");
176
- lines.push(` addEventListener<K extends keyof ${eventMapName}>(`);
177
- lines.push(" type: K,");
178
- lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapName}[K]) => unknown,`);
179
- lines.push(" options?: boolean | AddEventListenerOptions,");
180
- lines.push(" ): void");
181
- lines.push("");
182
- lines.push(` removeEventListener<K extends keyof ${eventMapName}>(`);
183
- lines.push(" type: K,");
184
- lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapName}[K]) => unknown,`);
185
- lines.push(" options?: boolean | EventListenerOptions,");
186
- lines.push(" ): void");
187
- lines.push("}");
188
- return lines.join("\n");
210
+ function generateElementInterface(component) {
211
+ return generateElementType(component, { eventMapTypeName: getEventMapTypeName(component) });
189
212
  }
190
213
  function toKebabCase$1(value) {
191
214
  return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
@@ -260,7 +283,6 @@ function generateReactDts(manifest, options = {}) {
260
283
  return lines.join("\n");
261
284
  }
262
285
  function generateReactComponentDts(component, options) {
263
- var _component$methods;
264
286
  const propsTypeName = getPropsTypeName(component);
265
287
  const elementTypeName = getElementTypeName(component);
266
288
  const lines = [];
@@ -285,13 +307,7 @@ function generateReactComponentDts(component, options) {
285
307
  }
286
308
  lines.push("}");
287
309
  lines.push("");
288
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
289
- for (const [name, prop] of Object.entries(component.props)) {
290
- const optional = isRequiredProp(prop) ? "" : "?";
291
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
292
- }
293
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method)}`);
294
- lines.push("}");
310
+ lines.push(generateElementType(component));
295
311
  lines.push("");
296
312
  lines.push(`export declare const ${component.name}: React.ForwardRefExoticComponent<`);
297
313
  lines.push(` ${propsTypeName} & React.RefAttributes<${elementTypeName}>`);
@@ -414,7 +430,10 @@ function generateLoaderDts(manifest) {
414
430
  lines.push("// Generated by @zeus-js/component-dts.");
415
431
  lines.push("");
416
432
  for (const component of manifest.components) {
417
- lines.push(generateElementInterface(component));
433
+ lines.push(generateElementType(component, {
434
+ componentOnReady: true,
435
+ forcePromise: true
436
+ }));
418
437
  lines.push("");
419
438
  }
420
439
  lines.push("export declare function defineCustomElements(): void");
@@ -431,20 +450,6 @@ function generateLoaderDts(manifest) {
431
450
  lines.push("");
432
451
  return lines.join("\n");
433
452
  }
434
- function generateElementInterface(component) {
435
- var _component$methods;
436
- const elementTypeName = getElementTypeName(component);
437
- const lines = [];
438
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
439
- for (const [name, prop] of Object.entries(component.props)) {
440
- const optional = isRequiredProp(prop) ? "" : "?";
441
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
442
- }
443
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method, { forcePromise: true })}`);
444
- lines.push(" componentOnReady(): Promise<this>");
445
- lines.push("}");
446
- return lines.join("\n");
447
- }
448
453
  //#endregion
449
454
  exports.formatDetailType = formatDetailType;
450
455
  exports.formatEventType = formatEventType;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * component-dts v0.1.0-beta.5
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}`);
@@ -150,42 +198,17 @@ function generateWCIndexDts(manifest, options) {
150
198
  }
151
199
  function generateEventMap(component) {
152
200
  const eventMapName = getEventMapTypeName(component);
153
- const entries = Object.entries(component.events);
154
201
  const lines = [];
155
202
  lines.push(`export interface ${eventMapName} {`);
156
- if (!entries.length) lines.push(" [key: string]: CustomEvent<unknown>");
157
- else for (const [key, event] of Object.entries(component.events)) {
203
+ for (const [key, event] of Object.entries(component.events)) {
158
204
  var _event$name, _event$key;
159
205
  lines.push(` ${safePropertyName((_event$name = event.name) !== null && _event$name !== void 0 ? _event$name : toKebabCase$1((_event$key = event.key) !== null && _event$key !== void 0 ? _event$key : key))}: ${formatEventType(event)}`);
160
206
  }
161
207
  lines.push("}");
162
208
  return lines.join("\n");
163
209
  }
164
- function generateElementInterface$1(component) {
165
- var _component$methods;
166
- const elementTypeName = getElementTypeName(component);
167
- const eventMapName = getEventMapTypeName(component);
168
- const lines = [];
169
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
170
- for (const [name, prop] of Object.entries(component.props)) {
171
- const optional = isRequiredProp(prop) ? "" : "?";
172
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
173
- }
174
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method)}`);
175
- lines.push("");
176
- lines.push(` addEventListener<K extends keyof ${eventMapName}>(`);
177
- lines.push(" type: K,");
178
- lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapName}[K]) => unknown,`);
179
- lines.push(" options?: boolean | AddEventListenerOptions,");
180
- lines.push(" ): void");
181
- lines.push("");
182
- lines.push(` removeEventListener<K extends keyof ${eventMapName}>(`);
183
- lines.push(" type: K,");
184
- lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapName}[K]) => unknown,`);
185
- lines.push(" options?: boolean | EventListenerOptions,");
186
- lines.push(" ): void");
187
- lines.push("}");
188
- return lines.join("\n");
210
+ function generateElementInterface(component) {
211
+ return generateElementType(component, { eventMapTypeName: getEventMapTypeName(component) });
189
212
  }
190
213
  function toKebabCase$1(value) {
191
214
  return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
@@ -260,7 +283,6 @@ function generateReactDts(manifest, options = {}) {
260
283
  return lines.join("\n");
261
284
  }
262
285
  function generateReactComponentDts(component, options) {
263
- var _component$methods;
264
286
  const propsTypeName = getPropsTypeName(component);
265
287
  const elementTypeName = getElementTypeName(component);
266
288
  const lines = [];
@@ -285,13 +307,7 @@ function generateReactComponentDts(component, options) {
285
307
  }
286
308
  lines.push("}");
287
309
  lines.push("");
288
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
289
- for (const [name, prop] of Object.entries(component.props)) {
290
- const optional = isRequiredProp(prop) ? "" : "?";
291
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
292
- }
293
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method)}`);
294
- lines.push("}");
310
+ lines.push(generateElementType(component));
295
311
  lines.push("");
296
312
  lines.push(`export declare const ${component.name}: React.ForwardRefExoticComponent<`);
297
313
  lines.push(` ${propsTypeName} & React.RefAttributes<${elementTypeName}>`);
@@ -414,7 +430,10 @@ function generateLoaderDts(manifest) {
414
430
  lines.push("// Generated by @zeus-js/component-dts.");
415
431
  lines.push("");
416
432
  for (const component of manifest.components) {
417
- lines.push(generateElementInterface(component));
433
+ lines.push(generateElementType(component, {
434
+ componentOnReady: true,
435
+ forcePromise: true
436
+ }));
418
437
  lines.push("");
419
438
  }
420
439
  lines.push("export declare function defineCustomElements(): void");
@@ -431,20 +450,6 @@ function generateLoaderDts(manifest) {
431
450
  lines.push("");
432
451
  return lines.join("\n");
433
452
  }
434
- function generateElementInterface(component) {
435
- var _component$methods;
436
- const elementTypeName = getElementTypeName(component);
437
- const lines = [];
438
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
439
- for (const [name, prop] of Object.entries(component.props)) {
440
- const optional = isRequiredProp(prop) ? "" : "?";
441
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
442
- }
443
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method, { forcePromise: true })}`);
444
- lines.push(" componentOnReady(): Promise<this>");
445
- lines.push("}");
446
- return lines.join("\n");
447
- }
448
453
  //#endregion
449
454
  exports.formatDetailType = formatDetailType;
450
455
  exports.formatEventType = formatEventType;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * component-dts v0.1.0-beta.5
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}`);
@@ -123,42 +171,17 @@ function generateWCIndexDts(manifest, options) {
123
171
  }
124
172
  function generateEventMap(component) {
125
173
  const eventMapName = getEventMapTypeName(component);
126
- const entries = Object.entries(component.events);
127
174
  const lines = [];
128
175
  lines.push(`export interface ${eventMapName} {`);
129
- if (!entries.length) lines.push(" [key: string]: CustomEvent<unknown>");
130
- else for (const [key, event] of Object.entries(component.events)) {
176
+ for (const [key, event] of Object.entries(component.events)) {
131
177
  var _event$name, _event$key;
132
178
  lines.push(` ${safePropertyName((_event$name = event.name) !== null && _event$name !== void 0 ? _event$name : toKebabCase$1((_event$key = event.key) !== null && _event$key !== void 0 ? _event$key : key))}: ${formatEventType(event)}`);
133
179
  }
134
180
  lines.push("}");
135
181
  return lines.join("\n");
136
182
  }
137
- function generateElementInterface$1(component) {
138
- var _component$methods;
139
- const elementTypeName = getElementTypeName(component);
140
- const eventMapName = getEventMapTypeName(component);
141
- const lines = [];
142
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
143
- for (const [name, prop] of Object.entries(component.props)) {
144
- const optional = isRequiredProp(prop) ? "" : "?";
145
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
146
- }
147
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method)}`);
148
- lines.push("");
149
- lines.push(` addEventListener<K extends keyof ${eventMapName}>(`);
150
- lines.push(" type: K,");
151
- lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapName}[K]) => unknown,`);
152
- lines.push(" options?: boolean | AddEventListenerOptions,");
153
- lines.push(" ): void");
154
- lines.push("");
155
- lines.push(` removeEventListener<K extends keyof ${eventMapName}>(`);
156
- lines.push(" type: K,");
157
- lines.push(` listener: (this: ${elementTypeName}, ev: ${eventMapName}[K]) => unknown,`);
158
- lines.push(" options?: boolean | EventListenerOptions,");
159
- lines.push(" ): void");
160
- lines.push("}");
161
- return lines.join("\n");
183
+ function generateElementInterface(component) {
184
+ return generateElementType(component, { eventMapTypeName: getEventMapTypeName(component) });
162
185
  }
163
186
  function toKebabCase$1(value) {
164
187
  return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
@@ -233,7 +256,6 @@ function generateReactDts(manifest, options = {}) {
233
256
  return lines.join("\n");
234
257
  }
235
258
  function generateReactComponentDts(component, options) {
236
- var _component$methods;
237
259
  const propsTypeName = getPropsTypeName(component);
238
260
  const elementTypeName = getElementTypeName(component);
239
261
  const lines = [];
@@ -258,13 +280,7 @@ function generateReactComponentDts(component, options) {
258
280
  }
259
281
  lines.push("}");
260
282
  lines.push("");
261
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
262
- for (const [name, prop] of Object.entries(component.props)) {
263
- const optional = isRequiredProp(prop) ? "" : "?";
264
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
265
- }
266
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method)}`);
267
- lines.push("}");
283
+ lines.push(generateElementType(component));
268
284
  lines.push("");
269
285
  lines.push(`export declare const ${component.name}: React.ForwardRefExoticComponent<`);
270
286
  lines.push(` ${propsTypeName} & React.RefAttributes<${elementTypeName}>`);
@@ -387,7 +403,10 @@ function generateLoaderDts(manifest) {
387
403
  lines.push("// Generated by @zeus-js/component-dts.");
388
404
  lines.push("");
389
405
  for (const component of manifest.components) {
390
- lines.push(generateElementInterface(component));
406
+ lines.push(generateElementType(component, {
407
+ componentOnReady: true,
408
+ forcePromise: true
409
+ }));
391
410
  lines.push("");
392
411
  }
393
412
  lines.push("export declare function defineCustomElements(): void");
@@ -404,19 +423,5 @@ function generateLoaderDts(manifest) {
404
423
  lines.push("");
405
424
  return lines.join("\n");
406
425
  }
407
- function generateElementInterface(component) {
408
- var _component$methods;
409
- const elementTypeName = getElementTypeName(component);
410
- const lines = [];
411
- lines.push(`export interface ${elementTypeName} extends HTMLElement {`);
412
- for (const [name, prop] of Object.entries(component.props)) {
413
- const optional = isRequiredProp(prop) ? "" : "?";
414
- lines.push(` ${safePropertyName(name)}${optional}: ${formatPropType(prop)}`);
415
- }
416
- for (const method of Object.values((_component$methods = component.methods) !== null && _component$methods !== void 0 ? _component$methods : {})) lines.push(` ${formatMethodSignature(method, { forcePromise: true })}`);
417
- lines.push(" componentOnReady(): Promise<this>");
418
- lines.push("}");
419
- return lines.join("\n");
420
- }
421
426
  //#endregion
422
427
  export { formatDetailType, formatEventType, formatPropType, generateComponentWCDts, generateLoaderDts, generateReactDts, generateVueDts, generateVueGlobalDts, generateWCDtsFiles, generateWCIndexDts, generateWCJsxDts };
package/package.json CHANGED
@@ -1,15 +1,19 @@
1
1
  {
2
2
  "name": "@zeus-js/component-dts",
3
- "version": "0.1.0-beta.5",
4
- "description": "DTS generators for Zeus component manifest",
5
3
  "type": "module",
6
- "main": "index.js",
7
- "module": "dist/component-dts.esm-bundler.js",
8
- "types": "dist/component-dts.d.ts",
9
- "files": [
10
- "index.js",
11
- "dist"
12
- ],
4
+ "version": "0.1.0-beta.7",
5
+ "description": "DTS generators for Zeus component manifest",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/baicie/zeus.git",
10
+ "directory": "packages/web-c/component-dts"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public",
14
+ "provenance": true
15
+ },
16
+ "sideEffects": false,
13
17
  "exports": {
14
18
  ".": {
15
19
  "types": "./dist/component-dts.d.ts",
@@ -23,11 +27,14 @@
23
27
  }
24
28
  }
25
29
  },
26
- "sideEffects": false,
27
- "repository": {
28
- "type": "git",
29
- "url": "https://github.com/baicie/zeus"
30
+ "files": [
31
+ "index.js",
32
+ "dist"
33
+ ],
34
+ "dependencies": {
35
+ "@zeus-js/component-analyzer": "0.1.0-beta.7"
30
36
  },
37
+ "author": "Baicie",
31
38
  "buildOptions": {
32
39
  "name": "ZeusComponentDts",
33
40
  "formats": [
@@ -35,15 +42,13 @@
35
42
  "cjs"
36
43
  ]
37
44
  },
38
- "dependencies": {
39
- "@zeus-js/component-analyzer": "0.1.0-beta.5"
40
- },
41
45
  "keywords": [
42
46
  "zeus",
43
47
  "web-components",
44
48
  "dts",
45
49
  "types"
46
50
  ],
47
- "author": "Baicie",
48
- "license": "MIT"
51
+ "main": "index.js",
52
+ "module": "dist/component-dts.esm-bundler.js",
53
+ "types": "dist/component-dts.d.ts"
49
54
  }