@stencil/templates 5.0.0-beta.9 → 5.0.0-rc.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/README.md +12 -12
- package/dist/index.d.mts +29 -5
- package/dist/index.mjs +45 -11
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -10,23 +10,23 @@ npm install --save-dev @stencil/templates
|
|
|
10
10
|
|
|
11
11
|
## API
|
|
12
12
|
|
|
13
|
-
### `getComponentBoilerplate(tagName, styleExtension?)` — component TSX
|
|
13
|
+
### `getComponentBoilerplate(tagName, { styleExtension?, encapsulation? })` — component TSX
|
|
14
14
|
|
|
15
15
|
Generates the `.tsx` file content for a new Stencil component:
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
18
|
import { getComponentBoilerplate } from '@stencil/templates';
|
|
19
19
|
|
|
20
|
-
// With a stylesheet
|
|
21
|
-
const tsx = getComponentBoilerplate('my-button', 'css');
|
|
20
|
+
// With a stylesheet and shadow DOM
|
|
21
|
+
const tsx = getComponentBoilerplate('my-button', { styleExtension: 'css', encapsulation: 'shadow' });
|
|
22
22
|
|
|
23
|
-
// Without (no styleUrl in @Component decorator)
|
|
23
|
+
// Without (no styleUrl in @Component decorator, no encapsulation)
|
|
24
24
|
const bare = getComponentBoilerplate('my-button');
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
-
`styleExtension` accepts `'css'`, `'scss'`, `'sass'`, or `'less'`.
|
|
27
|
+
`styleExtension` accepts `'css'`, `'scss'`, `'sass'`, or `'less'`. `encapsulation` accepts `'none'` (default), `'scoped'`, or `'shadow'`.
|
|
28
28
|
|
|
29
|
-
Output for `getComponentBoilerplate('my-button', 'css')`:
|
|
29
|
+
Output for `getComponentBoilerplate('my-button', { styleExtension: 'css', encapsulation: 'shadow' })`:
|
|
30
30
|
|
|
31
31
|
```tsx
|
|
32
32
|
import { Component, Host } from '@stencil/core';
|
|
@@ -49,16 +49,16 @@ export class MyButton {
|
|
|
49
49
|
|
|
50
50
|
---
|
|
51
51
|
|
|
52
|
-
### `getStyleBoilerplate(ext)` — stylesheet
|
|
52
|
+
### `getStyleBoilerplate(tagName, ext, encapsulation?)` — stylesheet
|
|
53
53
|
|
|
54
|
-
Generates the initial stylesheet content.
|
|
54
|
+
Generates the initial stylesheet content. Shadow and scoped components target `:host`; components without encapsulation (the default) target the tag name:
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
57
|
import { getStyleBoilerplate } from '@stencil/templates';
|
|
58
58
|
|
|
59
|
-
const css
|
|
60
|
-
const
|
|
61
|
-
const sass
|
|
59
|
+
const css = getStyleBoilerplate('my-button', 'css'); // my-button {\n display: block;\n}
|
|
60
|
+
const shadow = getStyleBoilerplate('my-button', 'css', 'shadow'); // :host {\n display: block;\n}
|
|
61
|
+
const sass = getStyleBoilerplate('my-button', 'sass'); // my-button\n display: block (indented syntax)
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
---
|
|
@@ -119,7 +119,7 @@ Returns the `module`, `types`, and `type` fields to merge into `package.json` fo
|
|
|
119
119
|
import { generatePackageJsonFields } from '@stencil/templates';
|
|
120
120
|
|
|
121
121
|
generatePackageJsonFields([]); // loader-bundle (default)
|
|
122
|
-
// { type: 'module', module: './dist/loader-bundle/
|
|
122
|
+
// { type: 'module', module: './dist/loader-bundle/esm/loader.js', types: './dist/types/loader.d.ts' }
|
|
123
123
|
|
|
124
124
|
generatePackageJsonFields(['standalone']);
|
|
125
125
|
// { type: 'module', module: './dist/standalone/index.js', types: './dist/types/standalone.d.ts' }
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
//#region src/types.d.ts
|
|
2
2
|
type StyleExtension = 'css' | 'sass' | 'scss' | 'less';
|
|
3
|
+
type ComponentEncapsulation = 'shadow' | 'scoped' | 'none';
|
|
3
4
|
//#endregion
|
|
4
5
|
//#region src/generate/component.d.ts
|
|
5
6
|
/**
|
|
@@ -14,20 +15,41 @@ declare function toPascalCase(str: string): string;
|
|
|
14
15
|
* Uses the v5 `encapsulation` API.
|
|
15
16
|
*
|
|
16
17
|
* @param tagName - Dash-case custom element tag name.
|
|
17
|
-
* @param
|
|
18
|
+
* @param options - Generation options.
|
|
19
|
+
* @param options.styleExtension - Optional stylesheet extension (e.g. `'css'`, `'scss'`).
|
|
20
|
+
* @param options.encapsulation - Component encapsulation type. Defaults to `'none'`.
|
|
18
21
|
* @returns TSX source string for the new component file.
|
|
19
22
|
*/
|
|
20
|
-
declare function getComponentBoilerplate(tagName: string, styleExtension?:
|
|
23
|
+
declare function getComponentBoilerplate(tagName: string, { styleExtension, encapsulation }?: {
|
|
24
|
+
styleExtension?: string;
|
|
25
|
+
encapsulation?: ComponentEncapsulation;
|
|
26
|
+
}): string;
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region src/generate/css-component.d.ts
|
|
29
|
+
/**
|
|
30
|
+
* Returns the CSS-only component boilerplate for `stencil generate` - a documented tag
|
|
31
|
+
* definition with no backing JS class, no shadow root, and no `customElements.define()`.
|
|
32
|
+
* See `packages/core/src/compiler/css-components/`.
|
|
33
|
+
* SASS indented syntax uses indentation instead of braces.
|
|
34
|
+
*
|
|
35
|
+
* @param tagName - Dash-case custom element tag name.
|
|
36
|
+
* @param ext - File extension (e.g. `'css'`, `'scss'`, `'sass'`, `'less'`). Defaults to `'css'`.
|
|
37
|
+
* @returns Stylesheet source string for the new CSS-only component file.
|
|
38
|
+
*/
|
|
39
|
+
declare function getCssOnlyComponentBoilerplate(tagName: string, ext?: string): string;
|
|
21
40
|
//#endregion
|
|
22
41
|
//#region src/generate/style.d.ts
|
|
23
42
|
/**
|
|
24
43
|
* Returns the stylesheet boilerplate for `stencil generate`.
|
|
44
|
+
* Shadow and scoped components target `:host`; components without encapsulation target the tag itself.
|
|
25
45
|
* SASS indented syntax uses indentation instead of braces.
|
|
26
46
|
*
|
|
47
|
+
* @param tagName - Dash-case custom element tag name.
|
|
27
48
|
* @param ext - File extension (e.g. `'css'`, `'sass'`, `'scss'`).
|
|
49
|
+
* @param encapsulation - Component encapsulation type. Defaults to `'none'`.
|
|
28
50
|
* @returns Stylesheet source string.
|
|
29
51
|
*/
|
|
30
|
-
declare function getStyleBoilerplate(ext: string): string;
|
|
52
|
+
declare function getStyleBoilerplate(tagName: string, ext: string, encapsulation?: ComponentEncapsulation): string;
|
|
31
53
|
//#endregion
|
|
32
54
|
//#region src/project/paths.d.ts
|
|
33
55
|
declare const PROJECT_TEMPLATES: readonly ["component-starter"];
|
|
@@ -53,11 +75,13 @@ interface ConfigSelections {
|
|
|
53
75
|
namespace: string;
|
|
54
76
|
outputs: ReadonlyArray<OutputKey>;
|
|
55
77
|
signals: boolean;
|
|
78
|
+
/** Write an `exports` map into `package.json` on each production build. */
|
|
79
|
+
exportMaps?: boolean;
|
|
56
80
|
docs: ReadonlyArray<DocKey>;
|
|
57
81
|
}
|
|
58
82
|
/**
|
|
59
83
|
* Returns stencil.config.ts source for the given selections, or null if zero-config
|
|
60
|
-
* covers everything (outputs = [] | ['loader'], no signals, no docs).
|
|
84
|
+
* covers everything (outputs = [] | ['loader'], no signals, no export maps, no docs).
|
|
61
85
|
*
|
|
62
86
|
* @param sel - Wizard selections to encode into the config file.
|
|
63
87
|
* @returns TypeScript source string, or null if no config file is needed.
|
|
@@ -110,4 +134,4 @@ declare function getUsageExampleBoilerplate(tagName: string): string;
|
|
|
110
134
|
*/
|
|
111
135
|
declare function getPreviewHtmlBoilerplate(tagName: string, entryScriptSrc: string | null): string;
|
|
112
136
|
//#endregion
|
|
113
|
-
export { type ConfigSelections, type DocKey, type IndexHtmlSelections, type OutputKey, PROJECT_TEMPLATES, type PackageJsonFields, type ProjectTemplateId, type StyleExtension, generateIndexHtml, generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getPreviewHtmlBoilerplate, getStyleBoilerplate, getTemplatePath, getUsageExampleBoilerplate, toPascalCase };
|
|
137
|
+
export { type ComponentEncapsulation, type ConfigSelections, type DocKey, type IndexHtmlSelections, type OutputKey, PROJECT_TEMPLATES, type PackageJsonFields, type ProjectTemplateId, type StyleExtension, generateIndexHtml, generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getCssOnlyComponentBoilerplate, getPreviewHtmlBoilerplate, getStyleBoilerplate, getTemplatePath, getUsageExampleBoilerplate, toPascalCase };
|
package/dist/index.mjs
CHANGED
|
@@ -15,14 +15,16 @@ function toPascalCase(str) {
|
|
|
15
15
|
* Uses the v5 `encapsulation` API.
|
|
16
16
|
*
|
|
17
17
|
* @param tagName - Dash-case custom element tag name.
|
|
18
|
-
* @param
|
|
18
|
+
* @param options - Generation options.
|
|
19
|
+
* @param options.styleExtension - Optional stylesheet extension (e.g. `'css'`, `'scss'`).
|
|
20
|
+
* @param options.encapsulation - Component encapsulation type. Defaults to `'none'`.
|
|
19
21
|
* @returns TSX source string for the new component file.
|
|
20
22
|
*/
|
|
21
|
-
function getComponentBoilerplate(tagName, styleExtension) {
|
|
23
|
+
function getComponentBoilerplate(tagName, { styleExtension, encapsulation = "none" } = {}) {
|
|
22
24
|
const decorator = ["{"];
|
|
23
25
|
decorator.push(` tag: '${tagName}',`);
|
|
24
26
|
if (styleExtension) decorator.push(` styleUrl: '${tagName}.${styleExtension}',`);
|
|
25
|
-
decorator.push(` encapsulation: { type: '
|
|
27
|
+
decorator.push(` encapsulation: { type: '${encapsulation}' },`);
|
|
26
28
|
decorator.push("}");
|
|
27
29
|
return `import { Component, Host } from '@stencil/core';
|
|
28
30
|
|
|
@@ -39,16 +41,47 @@ export class ${toPascalCase(tagName)} {
|
|
|
39
41
|
`;
|
|
40
42
|
}
|
|
41
43
|
//#endregion
|
|
44
|
+
//#region src/generate/css-component.ts
|
|
45
|
+
/**
|
|
46
|
+
* Returns the CSS-only component boilerplate for `stencil generate` - a documented tag
|
|
47
|
+
* definition with no backing JS class, no shadow root, and no `customElements.define()`.
|
|
48
|
+
* See `packages/core/src/compiler/css-components/`.
|
|
49
|
+
* SASS indented syntax uses indentation instead of braces.
|
|
50
|
+
*
|
|
51
|
+
* @param tagName - Dash-case custom element tag name.
|
|
52
|
+
* @param ext - File extension (e.g. `'css'`, `'scss'`, `'sass'`, `'less'`). Defaults to `'css'`.
|
|
53
|
+
* @returns Stylesheet source string for the new CSS-only component file.
|
|
54
|
+
*/
|
|
55
|
+
function getCssOnlyComponentBoilerplate(tagName, ext = "css") {
|
|
56
|
+
if (ext === "sass") return `/**
|
|
57
|
+
* @component
|
|
58
|
+
*/
|
|
59
|
+
${tagName}
|
|
60
|
+
display: block
|
|
61
|
+
`;
|
|
62
|
+
return `/**
|
|
63
|
+
* @component
|
|
64
|
+
*/
|
|
65
|
+
${tagName} {
|
|
66
|
+
display: block;
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
42
71
|
//#region src/generate/style.ts
|
|
43
72
|
/**
|
|
44
73
|
* Returns the stylesheet boilerplate for `stencil generate`.
|
|
74
|
+
* Shadow and scoped components target `:host`; components without encapsulation target the tag itself.
|
|
45
75
|
* SASS indented syntax uses indentation instead of braces.
|
|
46
76
|
*
|
|
77
|
+
* @param tagName - Dash-case custom element tag name.
|
|
47
78
|
* @param ext - File extension (e.g. `'css'`, `'sass'`, `'scss'`).
|
|
79
|
+
* @param encapsulation - Component encapsulation type. Defaults to `'none'`.
|
|
48
80
|
* @returns Stylesheet source string.
|
|
49
81
|
*/
|
|
50
|
-
function getStyleBoilerplate(ext) {
|
|
51
|
-
|
|
82
|
+
function getStyleBoilerplate(tagName, ext, encapsulation = "none") {
|
|
83
|
+
const selector = encapsulation === "none" ? tagName : ":host";
|
|
84
|
+
return ext === "sass" ? `${selector}\n display: block\n` : `${selector} {\n display: block;\n}\n`;
|
|
52
85
|
}
|
|
53
86
|
//#endregion
|
|
54
87
|
//#region src/project/paths.ts
|
|
@@ -68,20 +101,20 @@ function getTemplatePath(templateId) {
|
|
|
68
101
|
//#region src/project/config.ts
|
|
69
102
|
/**
|
|
70
103
|
* Returns stencil.config.ts source for the given selections, or null if zero-config
|
|
71
|
-
* covers everything (outputs = [] | ['loader'], no signals, no docs).
|
|
104
|
+
* covers everything (outputs = [] | ['loader'], no signals, no export maps, no docs).
|
|
72
105
|
*
|
|
73
106
|
* @param sel - Wizard selections to encode into the config file.
|
|
74
107
|
* @returns TypeScript source string, or null if no config file is needed.
|
|
75
108
|
*/
|
|
76
109
|
function generateStencilConfig(sel) {
|
|
77
|
-
if ((sel.outputs.length === 0 || sel.outputs.length === 1 && sel.outputs[0] === "loader") && !sel.signals && sel.docs.length === 0) return null;
|
|
110
|
+
if ((sel.outputs.length === 0 || sel.outputs.length === 1 && sel.outputs[0] === "loader") && !sel.signals && !sel.exportMaps && sel.docs.length === 0) return null;
|
|
78
111
|
const outputLines = [];
|
|
79
|
-
if (sel.outputs.includes("loader")
|
|
112
|
+
if (sel.outputs.includes("loader")) outputLines.push(` { type: 'loader-bundle' },`);
|
|
80
113
|
if (sel.outputs.includes("standalone")) outputLines.push(` { type: 'standalone' },`);
|
|
81
114
|
if (sel.outputs.includes("ssr")) outputLines.push(` { type: 'ssr' },`);
|
|
82
115
|
if (sel.outputs.includes("ssr-wasm")) outputLines.push(` { type: 'ssr-wasm' },`);
|
|
83
116
|
if (sel.outputs.includes("www")) outputLines.push(` { type: 'www' },`);
|
|
84
|
-
if (sel.docs.includes("cem")) outputLines.push(` { type: 'docs-custom-elements-manifest'
|
|
117
|
+
if (sel.docs.includes("cem")) outputLines.push(` { type: 'docs-custom-elements-manifest' },`);
|
|
85
118
|
if (sel.docs.includes("json")) outputLines.push(` { type: 'docs-json', file: 'docs/api.json' },`);
|
|
86
119
|
if (sel.docs.includes("skill")) outputLines.push(` { type: 'docs-agent-skill' },`);
|
|
87
120
|
if (sel.docs.includes("vscode")) outputLines.push(` { type: 'docs-vscode', file: 'vscode-data.json' },`);
|
|
@@ -97,6 +130,7 @@ function generateStencilConfig(sel) {
|
|
|
97
130
|
parts.push(` ],`);
|
|
98
131
|
}
|
|
99
132
|
if (sel.signals) parts.push(` signalBacking: true,`);
|
|
133
|
+
if (sel.exportMaps) parts.push(` generateExportMaps: true,`);
|
|
100
134
|
parts.push(`};`);
|
|
101
135
|
parts.push(``);
|
|
102
136
|
return parts.join("\n");
|
|
@@ -113,7 +147,7 @@ function generatePackageJsonFields(outputs) {
|
|
|
113
147
|
const has = (key) => outputs.includes(key);
|
|
114
148
|
if (isDefault || has("loader")) return {
|
|
115
149
|
type: "module",
|
|
116
|
-
module: "./dist/loader-bundle/
|
|
150
|
+
module: "./dist/loader-bundle/esm/loader.js",
|
|
117
151
|
types: "./dist/types/loader.d.ts"
|
|
118
152
|
};
|
|
119
153
|
if (has("standalone")) return {
|
|
@@ -208,4 +242,4 @@ ${entryScriptSrc ? ` <script type="module" src="${entryScriptSrc}"><\/script>
|
|
|
208
242
|
`;
|
|
209
243
|
}
|
|
210
244
|
//#endregion
|
|
211
|
-
export { PROJECT_TEMPLATES, generateIndexHtml, generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getPreviewHtmlBoilerplate, getStyleBoilerplate, getTemplatePath, getUsageExampleBoilerplate, toPascalCase };
|
|
245
|
+
export { PROJECT_TEMPLATES, generateIndexHtml, generatePackageJsonFields, generateStencilConfig, getComponentBoilerplate, getCssOnlyComponentBoilerplate, getPreviewHtmlBoilerplate, getStyleBoilerplate, getTemplatePath, getUsageExampleBoilerplate, toPascalCase };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stencil/templates",
|
|
3
|
-
"version": "5.0.0-
|
|
3
|
+
"version": "5.0.0-rc.0",
|
|
4
4
|
"description": "Project and generate templates for Stencil",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"scaffolding",
|
|
@@ -33,7 +33,10 @@
|
|
|
33
33
|
"vitest": "^4.1.10"
|
|
34
34
|
},
|
|
35
35
|
"peerDependencies": {
|
|
36
|
-
"@stencil/core": "^5.0.0 || 5.0.0-
|
|
36
|
+
"@stencil/core": "^5.0.0 || 5.0.0-rc.0"
|
|
37
|
+
},
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=22.0.0"
|
|
37
40
|
},
|
|
38
41
|
"volta": {
|
|
39
42
|
"extends": "../../package.json"
|