@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/LICENSE +21 -0
- package/README.md +165 -0
- package/dist/index.cjs +675 -0
- package/dist/index.d.cts +814 -0
- package/dist/index.d.ts +814 -0
- package/dist/index.js +637 -0
- package/package.json +86 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 WC Toolkit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
# WC Toolkit Custom Element VueJS Types Generator
|
|
8
|
+
|
|
9
|
+
This package generates Vue-specific TypeScript declaration files for your Custom Elements so consuming Vue projects get inline documentation, autocomplete, and type-safe validation when using your components in templates.
|
|
10
|
+
|
|
11
|
+
Types are generated from a Custom Elements Manifest (CEM) and include documentation for:
|
|
12
|
+
|
|
13
|
+
- Custom elements (types + docs)
|
|
14
|
+
- Attributes & properties (types + docs)
|
|
15
|
+
- Events (strongly typed when enabled)
|
|
16
|
+
- Methods (docs)
|
|
17
|
+
- Slots (docs)
|
|
18
|
+
- CSS custom properties & states (docs)
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
Two primary ways to generate types:
|
|
23
|
+
|
|
24
|
+
1. Programmatically, from a build script
|
|
25
|
+
2. As a plugin for the Custom Elements Manifest Analyzer
|
|
26
|
+
|
|
27
|
+
### Install
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
npm i -D @wc-toolkit/vuejs-types
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Build pipeline
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import { generateVuejsTypes, VuejsTypesOptions } from "@wc-toolkit/vuejs-types";
|
|
37
|
+
import manifest from "./path/to/custom-elements.json";
|
|
38
|
+
|
|
39
|
+
const options: VuejsTypesOptions = {
|
|
40
|
+
/* see Configuration Options below */
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
generateVuejsTypes(manifest, options);
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Run the script as part of your build:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
node scripts/generate-types.js
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### CEM Analyzer plugin
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
// custom-elements-manifest.config.js
|
|
56
|
+
import { vuejsTypesPlugin } from "@wc-toolkit/vuejs-types";
|
|
57
|
+
|
|
58
|
+
export default {
|
|
59
|
+
plugins: [
|
|
60
|
+
vuejsTypesPlugin({
|
|
61
|
+
outdir: "./dist/types",
|
|
62
|
+
fileName: "custom-elements.vue.d.ts",
|
|
63
|
+
}),
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Implementation / Integrating generated types
|
|
69
|
+
|
|
70
|
+
There are two common ways consumers can include the generated types in their Vue projects.
|
|
71
|
+
|
|
72
|
+
### Option 1: tsconfig
|
|
73
|
+
|
|
74
|
+
Add the generated types to `tsconfig.json` so the compiler picks them up automatically:
|
|
75
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"compilerOptions": {
|
|
79
|
+
"types": ["path/to/custom-elements.vue.d.ts"]
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Option 2: Small module file
|
|
85
|
+
|
|
86
|
+
Create a tiny module under `src/` to ensure the file is part of the TS program (recommended for libraries):
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
// src/custom-elements.d.ts
|
|
90
|
+
import "../dist/types/custom-elements.vue.d.ts";
|
|
91
|
+
export {};
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Vue compiler notes
|
|
95
|
+
|
|
96
|
+
- For Vite + Vue, add `compilerOptions.isCustomElement` so the template compiler treats your custom tags as native custom elements.
|
|
97
|
+
- Ensure the generated `.d.ts` is included in the consuming project's TS program (tsconfig `include` or the module file approach above).
|
|
98
|
+
|
|
99
|
+
## Configuration Options
|
|
100
|
+
|
|
101
|
+
The Vue generator accepts a `VuejsTypesOptions` object to customize output.
|
|
102
|
+
|
|
103
|
+
### Common options
|
|
104
|
+
|
|
105
|
+
| Option | Type | Default | What it does |
|
|
106
|
+
| ------------------- | ------------------------: | ----------------------------: | ------------------------------------------------------------- |
|
|
107
|
+
| `outdir` | `string` | `"./"` | Output directory for the generated `.d.ts`. |
|
|
108
|
+
| `fileName` | `string` | `"custom-element-vuejs.d.ts"` | Output file name. |
|
|
109
|
+
| `exclude` | `string[]` | `[]` | Exclude components by **class name** from the manifest. |
|
|
110
|
+
| `tagFormatter` | `(tag: string) => string` | — | Rewrite tag names before emitting `GlobalComponents` entries. |
|
|
111
|
+
| `prefix` / `suffix` | `string` | `""` | (Deprecated) Legacy tag rewriting; prefer `tagFormatter`. |
|
|
112
|
+
|
|
113
|
+
### Type source & imports
|
|
114
|
+
|
|
115
|
+
| Option | Type | Default | Notes |
|
|
116
|
+
| ------------------- | ------------------------------------: | -------: | -------------------------------------------------------------------------------------------------------------------------- |
|
|
117
|
+
| `useCemTypes` | `boolean` | `false` | Use types embedded in the CEM instead of `ComponentClass["prop"]`. Helpful for JS components + JSDoc. |
|
|
118
|
+
| `typesSrc` | `string` | `"type"` | Which CEM field to read when `useCemTypes` is on (e.g. `"type"` vs `"parsedType"`). |
|
|
119
|
+
| `componentTypePath` | `(name, tag?, modulePath?) => string` | — | Override the import path used for component class types. Useful if your CEM module paths don’t match your published paths. |
|
|
120
|
+
| `globalTypePath` | `string` | — | Add a global type import reference used by generated types (advanced). |
|
|
121
|
+
| `defaultExport` | `boolean` | `false` | If your component classes are default exports, set this so imports are generated correctly. |
|
|
122
|
+
|
|
123
|
+
### Template checking behavior
|
|
124
|
+
|
|
125
|
+
| Option | Type | Default | Notes |
|
|
126
|
+
| ---------------------------- | --------: | ------: | ------------------------------------------------------------------------------------- |
|
|
127
|
+
| `stronglyTypedEvents` | `boolean` | `false` | Improves custom event typing (e.g. event targets, `CustomEvent<detail>` payloads). |
|
|
128
|
+
| `allowUnknownProps` | `boolean` | `false` | Loosens template checking by allowing extra attributes/props on your custom elements. |
|
|
129
|
+
| `excludeCssCustomProperties` | `boolean` | `false` | Skip augmenting `CSSProperties` with CSS custom properties from the manifest. |
|
|
130
|
+
|
|
131
|
+
### Docs & troubleshooting
|
|
132
|
+
|
|
133
|
+
| Option | Type | Default | Notes |
|
|
134
|
+
| ----------------------------- | ----------------------------: | ------: | ------------------------------------------------------------------------ |
|
|
135
|
+
| `componentDescriptionOptions` | `ComponentDescriptionOptions` | — | Controls how descriptions are rendered into JSDoc (used for hover docs). |
|
|
136
|
+
| `debug` | `boolean` | `false` | Emit contextual logs while generating. |
|
|
137
|
+
| `skip` | `boolean` | `false` | Skip generation (useful in CI toggles). |
|
|
138
|
+
| `overrideCustomEventType` | `boolean` | — | (Deprecated) Will be removed in a future major version. |
|
|
139
|
+
|
|
140
|
+
See `src/types.ts` for the authoritative option definitions.
|
|
141
|
+
|
|
142
|
+
## Example complete configuration
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import { generateVuejsTypes } from "@wc-toolkit/vuejs-types";
|
|
146
|
+
import manifest from "./custom-elements.json";
|
|
147
|
+
|
|
148
|
+
generateVuejsTypes(manifest, {
|
|
149
|
+
fileName: "custom-elements.vue.d.ts",
|
|
150
|
+
outdir: "./dist/types",
|
|
151
|
+
stronglyTypedEvents: true,
|
|
152
|
+
useCemTypes: true,
|
|
153
|
+
tagFormatter: (tag) => tag.toLowerCase(),
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Troubleshooting
|
|
158
|
+
|
|
159
|
+
- No editor completions: confirm the consuming project's TS program includes the generated `.d.ts` (module file or tsconfig `types`/`include`).
|
|
160
|
+
- No hover docs on the tag: ensure your CEM includes a component `description` (it is emitted as JSDoc on the `GlobalComponents` entry).
|
|
161
|
+
- Event names clobbered by native events: avoid reusing native DOM event names for custom events.
|
|
162
|
+
|
|
163
|
+
## Contributing
|
|
164
|
+
|
|
165
|
+
See [CONTRIBUTING.md](./CONTRIBUTING.md) for developer instructions and guidance for automated agents.
|