@wc-toolkit/vuejs-types 1.0.0

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/index.cjs ADDED
@@ -0,0 +1,675 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ generateVuejsTypes: () => generateVuejsTypes,
34
+ vuejsTypesPlugin: () => vuejsTypesPlugin
35
+ });
36
+ module.exports = __toCommonJS(index_exports);
37
+
38
+ // src/type-generator.ts
39
+ var import_fs = __toESM(require("fs"), 1);
40
+ var import_path = __toESM(require("path"), 1);
41
+
42
+ // node_modules/.pnpm/@wc-toolkit+cem-utilities@1.4.1/node_modules/@wc-toolkit/cem-utilities/dist/index.js
43
+ var definitionExports = /* @__PURE__ */ new Map();
44
+ var components = [];
45
+ var manifest;
46
+ function getAllComponents(customElementsManifest, exclude = []) {
47
+ if (!customElementsManifest) {
48
+ return [];
49
+ }
50
+ if (!customElementsManifest || areObjectsEqual(customElementsManifest, manifest)) {
51
+ return components;
52
+ }
53
+ resetCache();
54
+ manifest = customElementsManifest;
55
+ setAllDefinitionExports(customElementsManifest);
56
+ manifest.modules.forEach((module2) => {
57
+ const ces = module2.declarations?.filter(
58
+ (d) => d.customElement
59
+ );
60
+ if (ces?.length) {
61
+ ces.forEach((ce) => {
62
+ if (exclude?.includes(ce.name)) {
63
+ return;
64
+ }
65
+ ce.modulePath = module2.path;
66
+ ce.definitionPath = definitionExports.get(ce.name);
67
+ if ("typeDefinitionPath" in module2 && module2.typeDefinitionPath) {
68
+ ce.typeDefinitionPath = module2.typeDefinitionPath;
69
+ }
70
+ components.push(ce);
71
+ });
72
+ }
73
+ });
74
+ return components;
75
+ }
76
+ function resetCache() {
77
+ components = [];
78
+ manifest = void 0;
79
+ definitionExports.clear();
80
+ }
81
+ function getComponentPublicProperties(component) {
82
+ if (!component || !component.members) {
83
+ return [];
84
+ }
85
+ return component?.members?.filter(
86
+ (member) => member.kind === "field" && member.privacy !== "private" && member.privacy !== "protected" && !member.static && !member.name.startsWith("#")
87
+ ) || [];
88
+ }
89
+ function setAllDefinitionExports(customElementsManifest) {
90
+ if (!customElementsManifest) {
91
+ return;
92
+ }
93
+ customElementsManifest.modules.forEach((mod) => {
94
+ const defExports = mod?.exports?.filter(
95
+ (e) => e.kind === "custom-element-definition"
96
+ );
97
+ if (defExports?.length) {
98
+ defExports.forEach((e) => {
99
+ if (e.declaration.name) {
100
+ definitionExports.set(e.declaration.name, mod.path);
101
+ }
102
+ });
103
+ }
104
+ });
105
+ }
106
+ function areObjectsEqual(obj1, obj2) {
107
+ if (obj1 === obj2) return true;
108
+ if (obj1 === null || obj2 === null || typeof obj1 !== "object" || typeof obj2 !== "object")
109
+ return false;
110
+ if (Array.isArray(obj1) && Array.isArray(obj2)) {
111
+ if (obj1.length !== obj2.length) return false;
112
+ return obj1.every((item, index) => areObjectsEqual(item, obj2[index]));
113
+ }
114
+ const keys1 = Object.keys(obj1);
115
+ const keys2 = Object.keys(obj2);
116
+ if (keys1.length !== keys2.length) return false;
117
+ if (!keys2.every((key) => key in obj1)) return false;
118
+ return keys1.every((key) => {
119
+ const val1 = obj1[key];
120
+ const val2 = obj2[key];
121
+ if (val1 === null && val2 === null) return true;
122
+ if (val1 === null || val2 === null) return false;
123
+ if (typeof val1 === "object" && typeof val2 === "object") {
124
+ return areObjectsEqual(val1, val2);
125
+ }
126
+ return val1 === val2;
127
+ });
128
+ }
129
+ function getMemberDescription(description, deprecated) {
130
+ if (!deprecated) {
131
+ return description || "";
132
+ }
133
+ const desc = description ? `- ${description}` : "";
134
+ return typeof deprecated === "string" ? `@deprecated ${deprecated} ${desc}` : `@deprecated ${desc}`;
135
+ }
136
+ function toPascalCase(value) {
137
+ return value.replace(new RegExp(/[-_]+/, "g"), " ").replace(new RegExp(/[^\w\s]/, "g"), "").replace(
138
+ new RegExp(/\s+(.)(\w*)/, "g"),
139
+ ($1, $2, $3) => `${$2.toUpperCase() + $3}`
140
+ ).replace(new RegExp(/\w/), (s) => s.toUpperCase());
141
+ }
142
+
143
+ // src/logger.ts
144
+ var Logger = class {
145
+ #debug;
146
+ constructor(debug = false) {
147
+ this.#debug = debug;
148
+ }
149
+ log(message, color = "\x1B[30m%s\x1B[0m") {
150
+ if (!this.#debug) {
151
+ return;
152
+ }
153
+ console.log(color, message);
154
+ }
155
+ red(message) {
156
+ this.log(message, "\x1B[31m%s\x1B[0m");
157
+ }
158
+ green(message) {
159
+ this.log(message, "\x1B[32m%s\x1B[0m");
160
+ }
161
+ yellow(message) {
162
+ this.log(message, "\x1B[33m%s\x1B[0m");
163
+ }
164
+ blue(message) {
165
+ this.log(message, "\x1B[34m%s\x1B[0m");
166
+ }
167
+ magenta(message) {
168
+ this.log(message, "\x1B[35m%s\x1B[0m");
169
+ }
170
+ cyan(message) {
171
+ this.log(message, "\x1B[36m%s\x1B[0m");
172
+ }
173
+ };
174
+
175
+ // src/type-generator.ts
176
+ var import_sync = __toESM(require("@prettier/sync"), 1);
177
+ var DEFAULT_OPTIONS = {
178
+ fileName: "custom-element-vuejs.d.ts",
179
+ outdir: "./",
180
+ exclude: [],
181
+ prefix: "",
182
+ suffix: ""
183
+ };
184
+ var KNOWN_FILE_EXTENSIONS = [
185
+ ".d.ts",
186
+ ".ts",
187
+ ".tsx",
188
+ ".js",
189
+ ".jsx",
190
+ ".mjs",
191
+ ".cjs",
192
+ ".mts",
193
+ ".cts"
194
+ ];
195
+ function toPosixPath(p) {
196
+ return p.split(import_path.default.sep).join("/");
197
+ }
198
+ function ensureRelativeSpecifier(p) {
199
+ return p.startsWith(".") ? p : `./${p}`;
200
+ }
201
+ function normalizeImportPath(importPath, options) {
202
+ const outDirAbs = import_path.default.resolve(options.outdir ?? "./");
203
+ const isAbsPath = importPath.startsWith("/") || /^[A-Za-z]:[\\/]/.test(importPath);
204
+ const hasPathSeparators = importPath.includes("/") || importPath.includes("\\");
205
+ const hasKnownExt = KNOWN_FILE_EXTENSIONS.some(
206
+ (ext) => importPath.endsWith(ext)
207
+ );
208
+ const shouldTryFs = isAbsPath || importPath.startsWith(".") || hasPathSeparators || hasKnownExt;
209
+ if (!shouldTryFs) {
210
+ return importPath;
211
+ }
212
+ const abs = import_path.default.resolve(importPath);
213
+ if (!import_fs.default.existsSync(abs)) {
214
+ return importPath;
215
+ }
216
+ try {
217
+ if (!import_fs.default.statSync(abs).isFile()) {
218
+ return importPath;
219
+ }
220
+ } catch {
221
+ return importPath;
222
+ }
223
+ const rel = toPosixPath(import_path.default.relative(outDirAbs, abs));
224
+ return ensureRelativeSpecifier(rel);
225
+ }
226
+ function generateVuejsTypes(manifest2, options = {}) {
227
+ const mergedOptions = { ...DEFAULT_OPTIONS, ...options };
228
+ const log = new Logger(mergedOptions.debug);
229
+ if (mergedOptions.skip) {
230
+ log.yellow("[vuejs-types] - Skipped");
231
+ return;
232
+ }
233
+ if (!manifest2 || !manifest2.modules || manifest2.modules.length === 0) {
234
+ log.red("[vuejs-types] - No modules found in the manifest.");
235
+ return;
236
+ }
237
+ if (!mergedOptions.outdir) {
238
+ log.red("[vuejs-types] - No output directory specified.");
239
+ return;
240
+ }
241
+ log.log("[vuejs-types] - Generating types...");
242
+ const template = getTypeTemplate(manifest2, mergedOptions);
243
+ if (mergedOptions.fileName) {
244
+ createOutDir(mergedOptions.outdir);
245
+ const outputPath = saveFile(
246
+ mergedOptions.outdir,
247
+ mergedOptions.fileName,
248
+ template
249
+ );
250
+ log.green(`[vuejs-types] - Generated "${outputPath}".`);
251
+ } else {
252
+ log.yellow(
253
+ `[vuejs-types] - File generation skipped because \`fileName\` was not defined.`
254
+ );
255
+ }
256
+ return template;
257
+ }
258
+ function getImports(manifest2, options) {
259
+ const imports = /* @__PURE__ */ new Map();
260
+ const componentModules = /* @__PURE__ */ new Map();
261
+ manifest2.modules.forEach((module2) => {
262
+ if (!module2.declarations || !module2.declarations.length || !module2.declarations.some((d) => d.customElement)) {
263
+ return;
264
+ }
265
+ module2.declarations?.forEach((element) => {
266
+ const component = element;
267
+ if (!component.customElement || !component.name) {
268
+ return;
269
+ }
270
+ componentModules.set(component.name, {
271
+ modulePath: module2.path,
272
+ tagName: component.tagName
273
+ });
274
+ });
275
+ if (options.globalTypePath) {
276
+ module2.exports?.forEach((exportDeclaration) => {
277
+ const exportName = exportDeclaration.declaration.name;
278
+ if (!exportName || exportName === "*") {
279
+ return;
280
+ }
281
+ addImport(imports, options.globalTypePath, exportName);
282
+ });
283
+ } else {
284
+ module2.declarations?.forEach((element) => {
285
+ const component = element;
286
+ if (!component.customElement || !component.name) {
287
+ return;
288
+ }
289
+ const importPath = normalizeImportPath(
290
+ getComponentImportPath(
291
+ component.name,
292
+ component.tagName,
293
+ module2.path,
294
+ options
295
+ ),
296
+ options
297
+ );
298
+ module2.exports?.forEach((exportDeclaration) => {
299
+ const exportName = exportDeclaration.declaration.name;
300
+ if (!exportName || exportName === "*") {
301
+ return;
302
+ }
303
+ if (!(options.defaultExport && exportName === component.name)) {
304
+ addImport(imports, importPath, exportName);
305
+ }
306
+ });
307
+ if (options.defaultExport) {
308
+ addImport(imports, importPath, `default as ${component.name}`);
309
+ }
310
+ });
311
+ }
312
+ });
313
+ if (options.useCemTypes) {
314
+ getAllComponents(manifest2, options.exclude).forEach((component) => {
315
+ if (!component.name) {
316
+ return;
317
+ }
318
+ const componentModule = componentModules.get(component.name);
319
+ if (!componentModule) {
320
+ return;
321
+ }
322
+ getComponentProps(component).forEach((prop) => {
323
+ const propType = getResolvedPropType(prop, options);
324
+ propType?.references?.forEach((reference) => {
325
+ if (!reference.name || reference.name === "default") {
326
+ return;
327
+ }
328
+ const importPath = getTypeImportPath(
329
+ reference,
330
+ componentModule.modulePath,
331
+ component,
332
+ options
333
+ );
334
+ if (!importPath) {
335
+ return;
336
+ }
337
+ addImport(imports, importPath, reference.name);
338
+ });
339
+ });
340
+ });
341
+ }
342
+ return Array.from(imports.entries()).map(
343
+ ([importPath, exportNames]) => `import type { ${Array.from(exportNames).join(", ")} } from "${importPath}";`
344
+ ).join("\n");
345
+ }
346
+ function getTypeTemplate(manifest2, options) {
347
+ const components2 = getAllComponents(manifest2, options.exclude);
348
+ const imports = getImports(manifest2, options);
349
+ return `
350
+ ${imports}
351
+ import type { HTMLAttributes, PublicProps, EmitFn, EmitsToProps } from "vue";
352
+
353
+ /**
354
+ * This file was autogenerated by @wc-toolkit/vuejs-types
355
+ ${options.stronglyTypedEvents ? `/**
356
+ * A generic type for strongly typing custom events with their targets
357
+ * @template T - The type of the event target (extends EventTarget)
358
+ * @template D - The type of the detail payload for the custom event
359
+ */
360
+ type TypedEvent<
361
+ T extends EventTarget,
362
+ E = Event
363
+ > = E & {
364
+ target: T;
365
+ };` : ""}
366
+
367
+ export type EventMap = {
368
+ [event: string]: Event;
369
+ };
370
+
371
+ // Vue's template type-checking reads props from $props and events from $emit.
372
+ // See: https://vuejs.org/guide/extras/web-components.html#non-vue-web-components-and-typescript
373
+ export type VueEmitsOptions<T extends EventMap> = {
374
+ [K in keyof T]: (event: T[K]) => void;
375
+ };
376
+
377
+ export type VueEmit<T extends EventMap> = EmitFn<VueEmitsOptions<T>>;
378
+
379
+ // Helps Volar autocomplete "@event" by providing "onXxx" props.
380
+ export type VueOnProps<T extends EventMap> = EmitsToProps<VueEmitsOptions<T>>;
381
+
382
+ export type DefineCustomElement<
383
+ ElementType extends HTMLElement,
384
+ Props = {},
385
+ Events extends EventMap = {},
386
+ > = new () => ElementType & {
387
+ /** @deprecated Do not use the $props property on a Custom Element ref; this is for template prop types only. */
388
+ $props: HTMLAttributes & Props & PublicProps & VueOnProps<Events>${options.allowUnknownProps ? " & Record<string, any>" : ""};
389
+
390
+ /** @deprecated Do not use the $emit property on a Custom Element ref; this is for template event types only. */
391
+ $emit: VueEmit<Events>;
392
+ };
393
+
394
+ ${components2?.map((component) => {
395
+ if (!component.name || !component.tagName) {
396
+ return "";
397
+ }
398
+ const cachedProps = getComponentProps(component)?.filter(
399
+ (prop) => !prop.readonly && !prop.static
400
+ ) || [];
401
+ const strongEventTypes = getStrongEventTypes(component);
402
+ const vueEventsTemplate = component.events?.filter((e) => e.name)?.map((event) => {
403
+ const eventType = event.type?.text?.startsWith("{") ? `CustomEvent<${event.type.text}>` : event.type?.text || "Event";
404
+ const resolvedEventType = getEventTypeName(
405
+ eventType,
406
+ strongEventTypes?.find((x) => x.name === event.name)?.newType || null,
407
+ component.name,
408
+ options.stronglyTypedEvents
409
+ );
410
+ return ` /** ${getMemberDescription(
411
+ event.description,
412
+ event.deprecated
413
+ )} */
414
+ "${event.name}": ${resolvedEventType};`;
415
+ }).join("\n") || "";
416
+ return `
417
+ ${options.stronglyTypedEvents ? getStronglyTypedEvents(component) : ""}
418
+
419
+ export type ${component.name}VueProps = {
420
+ ${(() => {
421
+ if (!cachedProps?.length) {
422
+ return "";
423
+ }
424
+ return cachedProps.reduce((acc, prop) => {
425
+ const description = getMemberDescription(prop.description, prop.deprecated);
426
+ const typeInfo = getResolvedPropType(prop, options);
427
+ const type = getPropType(component.name, prop, typeInfo, options);
428
+ const propExists = prop.propName ? acc.includes(` "${prop.propName}"?:`) : false;
429
+ const attrExists = prop.attrName ? acc.includes(` "${prop.attrName}"?:`) : false;
430
+ let result = acc;
431
+ if (prop.attrName && prop.attrName !== prop.propName && !attrExists) {
432
+ result += ` /** ${description} */
433
+ "${prop.attrName}"?: ${type};
434
+ `;
435
+ }
436
+ if (prop.propName && !propExists) {
437
+ result += ` /** ${description} */
438
+ "${prop.propName}"?: ${type};
439
+ `;
440
+ }
441
+ return result;
442
+ }, "");
443
+ })()}
444
+ };
445
+
446
+ export type ${component.name}VueEvents = {
447
+ ${vueEventsTemplate}
448
+ };
449
+ `;
450
+ }).join("\n")}
451
+
452
+ export type CustomCssProperties = {
453
+ ${(() => {
454
+ const uniqueCssProperties = /* @__PURE__ */ new Set();
455
+ const cssPropertiesArray = [];
456
+ components2.forEach((component) => {
457
+ component.cssProperties?.forEach((property) => {
458
+ if (!uniqueCssProperties.has(property.name)) {
459
+ uniqueCssProperties.add(property.name);
460
+ cssPropertiesArray.push(
461
+ ` /** ${getMemberDescription(property.description, property.deprecated)} */
462
+ "${property.name}"?: string;`
463
+ );
464
+ }
465
+ });
466
+ });
467
+ return cssPropertiesArray.join("\n");
468
+ })()}
469
+ }
470
+
471
+ // Vue SFC template type-checking (GlobalComponents) for non-Vue custom elements.
472
+ // Note: Some tooling expects this augmentation under "@vue/runtime-core", while
473
+ // other docs/examples use "vue". We emit both for compatibility.
474
+ export interface WcToolkitVueGlobalComponents {
475
+ ${components2.map((component) => {
476
+ if (!component.name || !component.tagName) {
477
+ return "";
478
+ }
479
+ let tagName = component.tagName;
480
+ if (options.tagFormatter) {
481
+ tagName = options.tagFormatter(component.tagName);
482
+ } else if (options.prefix || options.suffix) {
483
+ tagName = `${options.prefix}${component.tagName}${options.suffix}`;
484
+ }
485
+ const componentDoc = component.description ? getMemberDescription(
486
+ component.description,
487
+ component.deprecated
488
+ ).replace(/\n/g, " ").replace(/`/g, "'") : void 0;
489
+ return componentDoc ? ` /** ${componentDoc} */
490
+ "${tagName}": DefineCustomElement<${component.name}, ${component.name}VueProps, ${component.name}VueEvents>;` : ` "${tagName}": DefineCustomElement<${component.name}, ${component.name}VueProps, ${component.name}VueEvents>;`;
491
+ }).join("\n")}
492
+ }
493
+
494
+ declare module "@vue/runtime-core" {
495
+ interface GlobalComponents extends WcToolkitVueGlobalComponents {}
496
+ }
497
+
498
+ declare module "@vue/runtime-dom" {
499
+ interface GlobalComponents extends WcToolkitVueGlobalComponents {}
500
+
501
+ // Needed for named slots on native elements when using Web Components.
502
+ // Vue templates otherwise reject: <span slot="icon" />
503
+ interface HTMLAttributes {
504
+ slot?: string;
505
+ }
506
+ }
507
+
508
+ declare module "vue" {
509
+ interface GlobalComponents extends WcToolkitVueGlobalComponents {}
510
+
511
+ // Some package managers (notably pnpm) may not make "@vue/runtime-dom" directly
512
+ // resolvable from the consuming project, so we also augment via "vue".
513
+ interface HTMLAttributes {
514
+ slot?: string;
515
+ }
516
+
517
+ ${options.excludeCssCustomProperties ? "" : "interface CSSProperties extends CustomCssProperties {}"}
518
+ }
519
+ `;
520
+ }
521
+ function addImport(imports, importPath, exportName) {
522
+ const existing = imports.get(importPath);
523
+ if (existing) {
524
+ existing.add(exportName);
525
+ return;
526
+ }
527
+ imports.set(importPath, /* @__PURE__ */ new Set([exportName]));
528
+ }
529
+ function getComponentImportPath(componentName, tagName, modulePath, options) {
530
+ return typeof options.componentTypePath === "function" ? options.componentTypePath(componentName, tagName, modulePath) : modulePath;
531
+ }
532
+ function getTypeImportPath(reference, componentModulePath, component, options) {
533
+ if (reference.package) {
534
+ return reference.package;
535
+ }
536
+ if (!reference.module) {
537
+ return null;
538
+ }
539
+ if (reference.module === componentModulePath) {
540
+ if (options.globalTypePath) {
541
+ return normalizeImportPath(options.globalTypePath, options);
542
+ }
543
+ if (component.name) {
544
+ return normalizeImportPath(
545
+ getComponentImportPath(
546
+ component.name,
547
+ component.tagName,
548
+ componentModulePath,
549
+ options
550
+ ),
551
+ options
552
+ );
553
+ }
554
+ }
555
+ return normalizeImportPath(reference.module, options);
556
+ }
557
+ function getComponentProps(component) {
558
+ const properties = getComponentPublicProperties(
559
+ component
560
+ );
561
+ const propertyMap = new Map(
562
+ properties.map((property) => [property.name, property])
563
+ );
564
+ const attributeProps = component.attributes?.map(
565
+ (attribute) => ({
566
+ attrName: attribute.name,
567
+ propName: attribute.fieldName,
568
+ description: attribute.description,
569
+ deprecated: attribute.deprecated,
570
+ readonly: false,
571
+ static: false,
572
+ type: attribute.type,
573
+ attribute,
574
+ property: attribute.fieldName ? propertyMap.get(attribute.fieldName) : void 0
575
+ })
576
+ ) || [];
577
+ const attributePropNames = new Set(
578
+ attributeProps.map((attribute) => attribute.propName).filter((propName) => Boolean(propName))
579
+ );
580
+ const propertyOnlyProps = properties.filter((property) => !attributePropNames.has(property.name)).map((property) => ({
581
+ attrName: void 0,
582
+ propName: property.name,
583
+ description: property.description,
584
+ deprecated: property.deprecated,
585
+ readonly: property.readonly,
586
+ static: property.static,
587
+ type: property.type,
588
+ attribute: void 0,
589
+ property
590
+ }));
591
+ return [...attributeProps, ...propertyOnlyProps];
592
+ }
593
+ function getTypeFromSource(source, sourceKey) {
594
+ const candidate = source ? source[sourceKey] : void 0;
595
+ if (candidate && typeof candidate === "object" && "text" in candidate && typeof candidate.text === "string") {
596
+ return candidate;
597
+ }
598
+ return void 0;
599
+ }
600
+ function getResolvedPropType(prop, options) {
601
+ const sourceKey = options.typesSrc || "type";
602
+ return getTypeFromSource(prop.property, sourceKey) ?? getTypeFromSource(prop.attribute, sourceKey) ?? (sourceKey === "type" ? void 0 : getTypeFromSource(prop.property, "type")) ?? (sourceKey === "type" ? void 0 : getTypeFromSource(prop.attribute, "type")) ?? prop.type;
603
+ }
604
+ function getPropType(componentName, prop, propType, options) {
605
+ if (options.useCemTypes) {
606
+ return propType?.text || "unknown";
607
+ }
608
+ return prop.propName ? `${componentName}['${prop.propName}']` : "unknown";
609
+ }
610
+ function getEventTypeName(eventType, strongEventType, componentName = "", stronglyTyped) {
611
+ return stronglyTyped ? strongEventType ?? `${componentName}ElementEvent` : eventType;
612
+ }
613
+ function getStrongEventTypes(component) {
614
+ const eventTypes = component?.events?.filter((e) => e.name)?.map((event) => ({
615
+ name: event.name,
616
+ type: event?.type?.text
617
+ }));
618
+ if (!eventTypes) {
619
+ return [];
620
+ }
621
+ return eventTypes.filter(
622
+ (eventType) => eventType.type && eventType.type !== "Event" && eventType.type !== "CustomEvent"
623
+ ).map((eventType) => {
624
+ return {
625
+ name: eventType.name,
626
+ type: eventType.type.startsWith("{") ? `CustomEvent<${eventType.type}>` : eventType.type,
627
+ newType: `${component.name}${toPascalCase(eventType.name)}ElementEvent`
628
+ };
629
+ });
630
+ }
631
+ function getStronglyTypedEvents(component) {
632
+ if (!component.events?.length) {
633
+ return "";
634
+ }
635
+ const eventTypes = getStrongEventTypes(component);
636
+ const types = [
637
+ `/** \`${component.name}\` component event */
638
+ export type ${component.name}ElementEvent<E = Event> = TypedEvent<${component.name}, E>;`
639
+ ];
640
+ eventTypes.forEach((eventType) => {
641
+ types.push(
642
+ `/** \`${eventType.name}\` event type */
643
+ export type ${eventType.newType} = ${component.name}ElementEvent<${eventType.type}>;`
644
+ );
645
+ });
646
+ return types.join("\n");
647
+ }
648
+ function createOutDir(outDir) {
649
+ if (outDir !== "./" && !import_fs.default.existsSync(outDir)) {
650
+ import_fs.default.mkdirSync(outDir, { recursive: true });
651
+ }
652
+ }
653
+ function saveFile(outDir, fileName, contents) {
654
+ const outputPath = import_path.default.join(outDir, fileName);
655
+ import_fs.default.writeFileSync(
656
+ outputPath,
657
+ import_sync.default.format(contents, { parser: "typescript", printWidth: 80 })
658
+ );
659
+ return outputPath;
660
+ }
661
+
662
+ // src/cem-plugin.ts
663
+ function vuejsTypesPlugin(options = {}) {
664
+ return {
665
+ name: "@wc-toolkit/vuejs-types",
666
+ packageLinkPhase({ customElementsManifest }) {
667
+ generateVuejsTypes(customElementsManifest, options);
668
+ }
669
+ };
670
+ }
671
+ // Annotate the CommonJS export names for ESM import in node:
672
+ 0 && (module.exports = {
673
+ generateVuejsTypes,
674
+ vuejsTypesPlugin
675
+ });