@stencil/templates 5.0.0-beta.25 → 5.0.0-beta.26

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 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. Pass the file extension — not the tag name:
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 = getStyleBoilerplate('css'); // :host {\n display: block;\n}
60
- const scss = getStyleBoilerplate('scss'); // same, brace syntax
61
- const sass = getStyleBoilerplate('sass'); // :host\n display: block (indented syntax)
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
  ---
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,10 +15,15 @@ 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 styleExtension - Optional stylesheet extension (e.g. `'css'`, `'scss'`).
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?: string): string;
23
+ declare function getComponentBoilerplate(tagName: string, { styleExtension, encapsulation }?: {
24
+ styleExtension?: string;
25
+ encapsulation?: ComponentEncapsulation;
26
+ }): string;
21
27
  //#endregion
22
28
  //#region src/generate/css-component.d.ts
23
29
  /**
@@ -35,12 +41,15 @@ declare function getCssOnlyComponentBoilerplate(tagName: string, ext?: string):
35
41
  //#region src/generate/style.d.ts
36
42
  /**
37
43
  * Returns the stylesheet boilerplate for `stencil generate`.
44
+ * Shadow and scoped components target `:host`; components without encapsulation target the tag itself.
38
45
  * SASS indented syntax uses indentation instead of braces.
39
46
  *
47
+ * @param tagName - Dash-case custom element tag name.
40
48
  * @param ext - File extension (e.g. `'css'`, `'sass'`, `'scss'`).
49
+ * @param encapsulation - Component encapsulation type. Defaults to `'none'`.
41
50
  * @returns Stylesheet source string.
42
51
  */
43
- declare function getStyleBoilerplate(ext: string): string;
52
+ declare function getStyleBoilerplate(tagName: string, ext: string, encapsulation?: ComponentEncapsulation): string;
44
53
  //#endregion
45
54
  //#region src/project/paths.d.ts
46
55
  declare const PROJECT_TEMPLATES: readonly ["component-starter"];
@@ -125,4 +134,4 @@ declare function getUsageExampleBoilerplate(tagName: string): string;
125
134
  */
126
135
  declare function getPreviewHtmlBoilerplate(tagName: string, entryScriptSrc: string | null): string;
127
136
  //#endregion
128
- export { 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 };
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 styleExtension - Optional stylesheet extension (e.g. `'css'`, `'scss'`).
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: 'shadow' },`);
27
+ decorator.push(` encapsulation: { type: '${encapsulation}' },`);
26
28
  decorator.push("}");
27
29
  return `import { Component, Host } from '@stencil/core';
28
30
 
@@ -69,13 +71,17 @@ ${tagName} {
69
71
  //#region src/generate/style.ts
70
72
  /**
71
73
  * Returns the stylesheet boilerplate for `stencil generate`.
74
+ * Shadow and scoped components target `:host`; components without encapsulation target the tag itself.
72
75
  * SASS indented syntax uses indentation instead of braces.
73
76
  *
77
+ * @param tagName - Dash-case custom element tag name.
74
78
  * @param ext - File extension (e.g. `'css'`, `'sass'`, `'scss'`).
79
+ * @param encapsulation - Component encapsulation type. Defaults to `'none'`.
75
80
  * @returns Stylesheet source string.
76
81
  */
77
- function getStyleBoilerplate(ext) {
78
- return ext === "sass" ? `:host\n display: block\n` : `:host {\n display: block;\n}\n`;
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`;
79
85
  }
80
86
  //#endregion
81
87
  //#region src/project/paths.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stencil/templates",
3
- "version": "5.0.0-beta.25",
3
+ "version": "5.0.0-beta.26",
4
4
  "description": "Project and generate templates for Stencil",
5
5
  "keywords": [
6
6
  "scaffolding",
@@ -33,7 +33,7 @@
33
33
  "vitest": "^4.1.10"
34
34
  },
35
35
  "peerDependencies": {
36
- "@stencil/core": "^5.0.0 || 5.0.0-beta.25"
36
+ "@stencil/core": "^5.0.0 || 5.0.0-beta.26"
37
37
  },
38
38
  "engines": {
39
39
  "node": ">=22.0.0"