├── docs-src ├── .nojekyll ├── package.json ├── .eleventyignore ├── _includes │ ├── header.11ty.cjs │ ├── footer.11ty.cjs │ ├── relative-path.cjs │ ├── nav.11ty.cjs │ ├── example.11ty.cjs │ └── page.11ty.cjs ├── examples │ ├── name-property.md │ └── index.md ├── _data │ └── api.11tydata.js ├── _README.md ├── install.md ├── index.md ├── docs.css └── api.11ty.cjs ├── docs ├── .nojekyll ├── prism-okaidia.css ├── examples │ ├── name-property │ │ └── index.html │ └── index.html ├── install │ └── index.html ├── docs.css ├── api │ └── index.html └── index.html ├── .eslintignore ├── .prettierrc.json ├── dev ├── README.md └── index.html ├── .gitignore ├── index.html ├── .vscode └── extensions.json ├── web-dev-server.config.js ├── .eleventy.cjs ├── tsconfig.json ├── rollup.config.js ├── .eslintrc.json ├── LICENSE ├── src ├── my-element.ts └── test │ └── my-element_test.ts ├── package.json ├── web-test-runner.config.js ├── README.md └── CHANGELOG.md /docs-src/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/.nojekyll: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs-src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "commonjs" 3 | } 4 | -------------------------------------------------------------------------------- /docs-src/.eleventyignore: -------------------------------------------------------------------------------- 1 | # Ignore files with a leading underscore; useful for e.g. readmes in source documentation 2 | _*.md -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | docs/* 3 | docs-src/* 4 | rollup-config.js 5 | custom-elements.json 6 | web-dev-server.config.js 7 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "tabWidth": 2, 4 | "singleQuote": true, 5 | "bracketSpacing": false, 6 | "arrowParens": "always" 7 | } 8 | -------------------------------------------------------------------------------- /dev/README.md: -------------------------------------------------------------------------------- 1 | This directory contains HTML files containing your element for development. By running `npm run build:watch` and `npm run serve` you can edit and see changes without bundling. 2 | -------------------------------------------------------------------------------- /docs-src/_includes/header.11ty.cjs: -------------------------------------------------------------------------------- 1 | module.exports = function (data) { 2 | return ` 3 |
4 |

<my-element>

5 |

A web component just for me.

6 |
`; 7 | }; 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | /lib/ 3 | /test/ 4 | custom-elements.json 5 | # top level source 6 | my-element.js 7 | my-element.js.map 8 | my-element.d.ts 9 | my-element.d.ts.map 10 | # only generated for size check 11 | my-element.bundled.js -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Lit Starter Kit 7 | 8 | 9 | Component Demo 10 | 11 | 12 | -------------------------------------------------------------------------------- /docs-src/_includes/footer.11ty.cjs: -------------------------------------------------------------------------------- 1 | module.exports = function (data) { 2 | return ` 3 | `; 9 | }; 10 | -------------------------------------------------------------------------------- /docs-src/_includes/relative-path.cjs: -------------------------------------------------------------------------------- 1 | const path = require('path').posix; 2 | 3 | module.exports = (base, p) => { 4 | const relativePath = path.relative(base, p); 5 | if (p.endsWith('/') && !relativePath.endsWith('/') && relativePath !== '') { 6 | return relativePath + '/'; 7 | } 8 | return relativePath; 9 | }; 10 | -------------------------------------------------------------------------------- /docs-src/examples/name-property.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: example.11ty.cjs 3 | title: ⌲ Examples ⌲ Name Property 4 | tags: example 5 | name: Name Property 6 | description: Setting the name property 7 | --- 8 | 9 | 10 | 11 |

HTML

12 | 13 | ```html 14 | 15 | ``` 16 | -------------------------------------------------------------------------------- /docs-src/_data/api.11tydata.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | const fs = require('fs'); 8 | 9 | module.exports = () => { 10 | const customElements = JSON.parse( 11 | fs.readFileSync('custom-elements.json', 'utf-8') 12 | ); 13 | return { 14 | customElements, 15 | }; 16 | }; 17 | -------------------------------------------------------------------------------- /docs-src/_includes/nav.11ty.cjs: -------------------------------------------------------------------------------- 1 | const relative = require('./relative-path.cjs'); 2 | 3 | module.exports = function ({page}) { 4 | return ` 5 | `; 11 | }; 12 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations. 3 | // Extension identifier format: ${publisher}.${name}. Example: vscode.csharp 4 | 5 | // List of extensions which should be recommended for users of this workspace. 6 | "recommendations": ["runem.lit-plugin"], 7 | // List of extensions recommended by VS Code that should not be recommended for users of this workspace. 8 | "unwantedRecommendations": [] 9 | } 10 | -------------------------------------------------------------------------------- /docs-src/_README.md: -------------------------------------------------------------------------------- 1 | This directory contains the sources for the static site contained in the /docs/ directory. The site is based on the [eleventy](11ty.dev) static site generator. 2 | 3 | The site is intended to be used with GitHub pages. To enable the site go to the GitHub settings and change the GitHub Pages "Source" setting to "master branch /docs folder". 4 | 5 | To view the site locally, run `npm run docs:serve`. 6 | 7 | To edit the site, add to or edit the files in this directory then run `npm run docs` to build the site. The built files must be checked in and pushed to GitHub to appear on GitHub pages. 8 | -------------------------------------------------------------------------------- /docs-src/examples/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: example.11ty.cjs 3 | title: ⌲ Examples ⌲ Basic 4 | tags: example 5 | name: Basic 6 | description: A basic example 7 | --- 8 | 9 | 15 | 16 |

This is child content

17 |
18 | 19 |

CSS

20 | 21 | ```css 22 | p { 23 | border: solid 1px blue; 24 | padding: 8px; 25 | } 26 | ``` 27 | 28 |

HTML

29 | 30 | ```html 31 | 32 |

This is child content

33 |
34 | ``` 35 | -------------------------------------------------------------------------------- /dev/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | <my-element> Demo 7 | 8 | 9 | 10 | 16 | 17 | 18 | 19 |

This is child content

20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /web-dev-server.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | import {legacyPlugin} from '@web/dev-server-legacy'; 8 | 9 | const mode = process.env.MODE || 'dev'; 10 | if (!['dev', 'prod'].includes(mode)) { 11 | throw new Error(`MODE must be "dev" or "prod", was "${mode}"`); 12 | } 13 | 14 | export default { 15 | nodeResolve: {exportConditions: mode === 'dev' ? ['development'] : []}, 16 | preserveSymlinks: true, 17 | plugins: [ 18 | legacyPlugin({ 19 | polyfills: { 20 | // Manually imported in index.html file 21 | webcomponents: false, 22 | }, 23 | }), 24 | ], 25 | }; 26 | -------------------------------------------------------------------------------- /.eleventy.cjs: -------------------------------------------------------------------------------- 1 | const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight'); 2 | 3 | module.exports = function (eleventyConfig) { 4 | eleventyConfig.addPlugin(syntaxHighlight); 5 | eleventyConfig.addPassthroughCopy('docs-src/docs.css'); 6 | eleventyConfig.addPassthroughCopy('docs-src/.nojekyll'); 7 | eleventyConfig.addPassthroughCopy( 8 | 'node_modules/@webcomponents/webcomponentsjs' 9 | ); 10 | eleventyConfig.addPassthroughCopy('node_modules/lit/polyfill-support.js'); 11 | return { 12 | dir: { 13 | input: 'docs-src', 14 | output: 'docs', 15 | }, 16 | templateExtensionAliases: { 17 | '11ty.cjs': '11ty.js', 18 | '11tydata.cjs': '11tydata.js', 19 | }, 20 | }; 21 | }; 22 | -------------------------------------------------------------------------------- /docs-src/install.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: page.11ty.cjs 3 | title: ⌲ Install 4 | --- 5 | 6 | # Install 7 | 8 | `` is distributed on npm, so you can install it locally or use it via npm CDNs like unpkg.com. 9 | 10 | ## Local Installation 11 | 12 | ```bash 13 | npm i my-element 14 | ``` 15 | 16 | ## CDN 17 | 18 | npm CDNs like [unpkg.com]() can directly serve files that have been published to npm. This works great for standard JavaScript modules that the browser can load natively. 19 | 20 | For this element to work from unpkg.com specifically, you need to include the `?module` query parameter, which tells unpkg.com to rewrite "bare" module specifiers to full URLs. 21 | 22 | ### HTML 23 | 24 | ```html 25 | 26 | ``` 27 | 28 | ### JavaScript 29 | 30 | ```html 31 | import {MyElement} from 'https://unpkg.com/my-element?module'; 32 | ``` 33 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2021", 4 | "module": "es2020", 5 | "lib": ["es2021", "DOM", "DOM.Iterable"], 6 | "declaration": true, 7 | "declarationMap": true, 8 | "sourceMap": true, 9 | "inlineSources": true, 10 | "outDir": "./", 11 | "rootDir": "./src", 12 | "strict": true, 13 | "noUnusedLocals": true, 14 | "noUnusedParameters": true, 15 | "noImplicitReturns": true, 16 | "noFallthroughCasesInSwitch": true, 17 | "noImplicitAny": true, 18 | "noImplicitThis": true, 19 | "moduleResolution": "node", 20 | "allowSyntheticDefaultImports": true, 21 | "experimentalDecorators": true, 22 | "forceConsistentCasingInFileNames": true, 23 | "noImplicitOverride": true, 24 | "plugins": [ 25 | { 26 | "name": "ts-lit-plugin", 27 | "strict": true 28 | } 29 | ], 30 | "types": ["mocha"] 31 | }, 32 | "include": ["src/**/*.ts"], 33 | "exclude": [] 34 | } 35 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2018 Google LLC 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | import summary from 'rollup-plugin-summary'; 8 | import terser from '@rollup/plugin-terser'; 9 | import resolve from '@rollup/plugin-node-resolve'; 10 | import replace from '@rollup/plugin-replace'; 11 | 12 | export default { 13 | input: 'my-element.js', 14 | output: { 15 | file: 'my-element.bundled.js', 16 | format: 'esm', 17 | }, 18 | onwarn(warning) { 19 | if (warning.code !== 'THIS_IS_UNDEFINED') { 20 | console.error(`(!) ${warning.message}`); 21 | } 22 | }, 23 | plugins: [ 24 | replace({preventAssignment: false, 'Reflect.decorate': 'undefined'}), 25 | resolve(), 26 | /** 27 | * This minification setup serves the static site generation. 28 | * For bundling and minification, check the README.md file. 29 | */ 30 | terser({ 31 | ecma: 2021, 32 | module: true, 33 | warnings: true, 34 | mangle: { 35 | properties: { 36 | regex: /^__/, 37 | }, 38 | }, 39 | }), 40 | summary(), 41 | ], 42 | }; 43 | -------------------------------------------------------------------------------- /docs-src/_includes/example.11ty.cjs: -------------------------------------------------------------------------------- 1 | const page = require('./page.11ty.cjs'); 2 | const relative = require('./relative-path.cjs'); 3 | 4 | /** 5 | * This template extends the page template and adds an examples list. 6 | */ 7 | module.exports = function (data) { 8 | return page({ 9 | ...data, 10 | content: renderExample(data), 11 | }); 12 | }; 13 | 14 | const renderExample = ({name, content, collections, page}) => { 15 | return ` 16 |

Example: ${name}

17 |
18 | 38 |
39 | ${content} 40 |
41 |
42 | `; 43 | }; 44 | -------------------------------------------------------------------------------- /docs-src/_includes/page.11ty.cjs: -------------------------------------------------------------------------------- 1 | const header = require('./header.11ty.cjs'); 2 | const footer = require('./footer.11ty.cjs'); 3 | const nav = require('./nav.11ty.cjs'); 4 | const relative = require('./relative-path.cjs'); 5 | 6 | module.exports = function (data) { 7 | const {title, page, content} = data; 8 | return ` 9 | 10 | 11 | 12 | 13 | 14 | 15 | ${title} 16 | 17 | 18 | 19 | 20 | 21 | 25 | 26 | 27 | ${header()} 28 | ${nav(data)} 29 |
30 |
31 | ${content} 32 |
33 |
34 | ${footer()} 35 | 36 | `; 37 | }; 38 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "extends": [ 4 | "eslint:recommended", 5 | "plugin:@typescript-eslint/eslint-recommended", 6 | "plugin:@typescript-eslint/recommended" 7 | ], 8 | "parser": "@typescript-eslint/parser", 9 | "parserOptions": { 10 | "ecmaVersion": 2020, 11 | "sourceType": "module" 12 | }, 13 | "plugins": ["@typescript-eslint"], 14 | "env": { 15 | "browser": true 16 | }, 17 | "rules": { 18 | "no-prototype-builtins": "off", 19 | "@typescript-eslint/ban-types": "off", 20 | "@typescript-eslint/explicit-function-return-type": "off", 21 | "@typescript-eslint/explicit-module-boundary-types": "off", 22 | "@typescript-eslint/no-explicit-any": "error", 23 | "@typescript-eslint/no-empty-function": "off", 24 | "@typescript-eslint/no-non-null-assertion": "off", 25 | "@typescript-eslint/no-unused-vars": [ 26 | "warn", 27 | { 28 | "argsIgnorePattern": "^_" 29 | } 30 | ] 31 | }, 32 | "overrides": [ 33 | { 34 | "files": ["rollup.config.js", "web-test-runner.config.js"], 35 | "env": { 36 | "node": true 37 | } 38 | }, 39 | { 40 | "files": [ 41 | "*_test.ts", 42 | "**/custom_typings/*.ts", 43 | "packages/labs/ssr/src/test/integration/tests/**", 44 | "packages/labs/ssr/src/lib/util/parse5-utils.ts" 45 | ], 46 | "rules": { 47 | "@typescript-eslint/no-explicit-any": "off" 48 | } 49 | } 50 | ] 51 | } 52 | -------------------------------------------------------------------------------- /docs-src/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | layout: page.11ty.cjs 3 | title: ⌲ Home 4 | --- 5 | 6 | # <my-element> 7 | 8 | `` is an awesome element. It's a great introduction to building web components with LitElement, with nice documentation site as well. 9 | 10 | ## As easy as HTML 11 | 12 |
13 |
14 | 15 | `` is just an HTML element. You can it anywhere you can use HTML! 16 | 17 | ```html 18 | 19 | ``` 20 | 21 |
22 |
23 | 24 | 25 | 26 |
27 |
28 | 29 | ## Configure with attributes 30 | 31 |
32 |
33 | 34 | `` can be configured with attributed in plain HTML. 35 | 36 | ```html 37 | 38 | ``` 39 | 40 |
41 |
42 | 43 | 44 | 45 |
46 |
47 | 48 | ## Declarative rendering 49 | 50 |
51 |
52 | 53 | `` can be used with declarative rendering libraries like Angular, React, Vue, and lit-html 54 | 55 | ```js 56 | import {html, render} from 'lit-html'; 57 | 58 | const name = 'lit-html'; 59 | 60 | render( 61 | html` 62 |

This is a <my-element>

63 | 64 | `, 65 | document.body 66 | ); 67 | ``` 68 | 69 |
70 |
71 | 72 |

This is a <my-element>

73 | 74 | 75 |
76 |
77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2019 Google LLC. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /src/my-element.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2019 Google LLC 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | import {LitElement, html, css} from 'lit'; 8 | import {customElement, property} from 'lit/decorators.js'; 9 | 10 | /** 11 | * An example element. 12 | * 13 | * @fires count-changed - Indicates when the count changes 14 | * @slot - This element has a slot 15 | * @csspart button - The button 16 | */ 17 | @customElement('my-element') 18 | export class MyElement extends LitElement { 19 | static override styles = css` 20 | :host { 21 | display: block; 22 | border: solid 1px gray; 23 | padding: 16px; 24 | max-width: 800px; 25 | } 26 | `; 27 | 28 | /** 29 | * The name to say "Hello" to. 30 | */ 31 | @property() 32 | name = 'World'; 33 | 34 | /** 35 | * The number of times the button has been clicked. 36 | */ 37 | @property({type: Number}) 38 | count = 0; 39 | 40 | override render() { 41 | return html` 42 |

${this.sayHello(this.name)}!

43 | 46 | 47 | `; 48 | } 49 | 50 | private _onClick() { 51 | this.count++; 52 | this.dispatchEvent(new CustomEvent('count-changed')); 53 | } 54 | 55 | /** 56 | * Formats a greeting 57 | * @param name The name to say "Hello" to 58 | */ 59 | sayHello(name: string): string { 60 | return `Hello, ${name}`; 61 | } 62 | } 63 | 64 | declare global { 65 | interface HTMLElementTagNameMap { 66 | 'my-element': MyElement; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/test/my-element_test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | import {MyElement} from '../my-element.js'; 8 | 9 | import {fixture, assert} from '@open-wc/testing'; 10 | import {html} from 'lit/static-html.js'; 11 | 12 | suite('my-element', () => { 13 | test('is defined', () => { 14 | const el = document.createElement('my-element'); 15 | assert.instanceOf(el, MyElement); 16 | }); 17 | 18 | test('renders with default values', async () => { 19 | const el = await fixture(html``); 20 | assert.shadowDom.equal( 21 | el, 22 | ` 23 |

Hello, World!

24 | 25 | 26 | ` 27 | ); 28 | }); 29 | 30 | test('renders with a set name', async () => { 31 | const el = await fixture(html``); 32 | assert.shadowDom.equal( 33 | el, 34 | ` 35 |

Hello, Test!

36 | 37 | 38 | ` 39 | ); 40 | }); 41 | 42 | test('handles a click', async () => { 43 | const el = (await fixture(html``)) as MyElement; 44 | const button = el.shadowRoot!.querySelector('button')!; 45 | button.click(); 46 | await el.updateComplete; 47 | assert.shadowDom.equal( 48 | el, 49 | ` 50 |

Hello, World!

51 | 52 | 53 | ` 54 | ); 55 | }); 56 | 57 | test('styling applied', async () => { 58 | const el = (await fixture(html``)) as MyElement; 59 | await el.updateComplete; 60 | assert.equal(getComputedStyle(el).paddingTop, '16px'); 61 | }); 62 | }); 63 | -------------------------------------------------------------------------------- /docs/prism-okaidia.css: -------------------------------------------------------------------------------- 1 | /** 2 | * okaidia theme for JavaScript, CSS and HTML 3 | * Loosely based on Monokai textmate theme by http://www.monokai.nl/ 4 | * @author ocodia 5 | */ 6 | 7 | code[class*="language-"], 8 | pre[class*="language-"] { 9 | color: #f8f8f2; 10 | background: none; 11 | text-shadow: 0 1px rgba(0, 0, 0, 0.3); 12 | font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; 13 | font-size: 1em; 14 | text-align: left; 15 | white-space: pre; 16 | word-spacing: normal; 17 | word-break: normal; 18 | word-wrap: normal; 19 | line-height: 1.5; 20 | 21 | -moz-tab-size: 4; 22 | -o-tab-size: 4; 23 | tab-size: 4; 24 | 25 | -webkit-hyphens: none; 26 | -moz-hyphens: none; 27 | -ms-hyphens: none; 28 | hyphens: none; 29 | } 30 | 31 | /* Code blocks */ 32 | pre[class*="language-"] { 33 | padding: 1em; 34 | margin: .5em 0; 35 | overflow: auto; 36 | border-radius: 0.3em; 37 | } 38 | 39 | :not(pre) > code[class*="language-"], 40 | pre[class*="language-"] { 41 | background: #272822; 42 | } 43 | 44 | /* Inline code */ 45 | :not(pre) > code[class*="language-"] { 46 | padding: .1em; 47 | border-radius: .3em; 48 | white-space: normal; 49 | } 50 | 51 | .token.comment, 52 | .token.prolog, 53 | .token.doctype, 54 | .token.cdata { 55 | color: #8292a2; 56 | } 57 | 58 | .token.punctuation { 59 | color: #f8f8f2; 60 | } 61 | 62 | .token.namespace { 63 | opacity: .7; 64 | } 65 | 66 | .token.property, 67 | .token.tag, 68 | .token.constant, 69 | .token.symbol, 70 | .token.deleted { 71 | color: #f92672; 72 | } 73 | 74 | .token.boolean, 75 | .token.number { 76 | color: #ae81ff; 77 | } 78 | 79 | .token.selector, 80 | .token.attr-name, 81 | .token.string, 82 | .token.char, 83 | .token.builtin, 84 | .token.inserted { 85 | color: #a6e22e; 86 | } 87 | 88 | .token.operator, 89 | .token.entity, 90 | .token.url, 91 | .language-css .token.string, 92 | .style .token.string, 93 | .token.variable { 94 | color: #f8f8f2; 95 | } 96 | 97 | .token.atrule, 98 | .token.attr-value, 99 | .token.function, 100 | .token.class-name { 101 | color: #e6db74; 102 | } 103 | 104 | .token.keyword { 105 | color: #66d9ef; 106 | } 107 | 108 | .token.regex, 109 | .token.important { 110 | color: #fd971f; 111 | } 112 | 113 | .token.important, 114 | .token.bold { 115 | font-weight: bold; 116 | } 117 | .token.italic { 118 | font-style: italic; 119 | } 120 | 121 | .token.entity { 122 | cursor: help; 123 | } 124 | -------------------------------------------------------------------------------- /docs/examples/name-property/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <my-element> ⌲ Examples ⌲ Name Property 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |

<my-element>

20 |

A web component just for me.

21 |
22 | 23 |
29 |
30 |
31 | 32 |

Example: Name Property

33 |
34 | 47 |
48 |

49 |

HTML

50 |
<my-element name="Earth"></my-element>
51 | 52 |
53 |
54 | 55 |
56 |
57 | 58 | 64 | 65 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@lit/lit-starter-ts", 3 | "private": true, 4 | "version": "2.0.2", 5 | "description": "A simple web component", 6 | "main": "my-element.js", 7 | "module": "my-element.js", 8 | "type": "module", 9 | "scripts": { 10 | "build": "tsc", 11 | "build:watch": "tsc --watch", 12 | "clean": "rimraf my-element.{d.ts,d.ts.map,js,js.map} test/my-element.{d.ts,d.ts.map,js,js.map} test/my-element_test.{d.ts,d.ts.map,js,js.map}", 13 | "lint": "npm run lint:lit-analyzer && npm run lint:eslint", 14 | "lint:eslint": "eslint 'src/**/*.ts'", 15 | "lint:lit-analyzer": "lit-analyzer", 16 | "format": "prettier \"**/*.{cjs,html,js,json,md,ts}\" --ignore-path ./.eslintignore --write", 17 | "docs": "npm run docs:clean && npm run build && npm run analyze && npm run docs:build && npm run docs:assets && npm run docs:gen", 18 | "docs:clean": "rimraf docs", 19 | "docs:gen": "eleventy --config=.eleventy.cjs", 20 | "docs:gen:watch": "eleventy --config=.eleventy.cjs --watch", 21 | "docs:build": "rollup -c --file docs/my-element.bundled.js", 22 | "docs:assets": "cp node_modules/prismjs/themes/prism-okaidia.css docs/", 23 | "docs:serve": "wds --root-dir=docs --node-resolve --watch", 24 | "analyze": "cem analyze --litelement --globs \"src/**/*.ts\"", 25 | "analyze:watch": "cem analyze --litelement --globs \"src/**/*.ts\" --watch", 26 | "serve": "wds --watch", 27 | "serve:prod": "MODE=prod npm run serve", 28 | "test": "npm run test:dev && npm run test:prod", 29 | "test:dev": "wtr", 30 | "test:watch": "wtr --watch", 31 | "test:prod": "MODE=prod wtr", 32 | "test:prod:watch": "MODE=prod wtr --watch", 33 | "checksize": "rollup -c ; cat my-element.bundled.js | gzip -9 | wc -c ; rm my-element.bundled.js" 34 | }, 35 | "keywords": [ 36 | "web-components", 37 | "lit-element", 38 | "typescript", 39 | "lit" 40 | ], 41 | "author": "Google LLC", 42 | "license": "BSD-3-Clause", 43 | "dependencies": { 44 | "lit": "^3.2.0" 45 | }, 46 | "devDependencies": { 47 | "@11ty/eleventy": "^1.0.1", 48 | "@11ty/eleventy-plugin-syntaxhighlight": "^4.0.0", 49 | "@custom-elements-manifest/analyzer": "^0.6.3", 50 | "@open-wc/testing": "^4.0.0", 51 | "@rollup/plugin-node-resolve": "^15.2.3", 52 | "@rollup/plugin-replace": "^5.0.7", 53 | "@rollup/plugin-terser": "^0.4.4", 54 | "@typescript-eslint/eslint-plugin": "^5.25.0", 55 | "@typescript-eslint/parser": "^5.25.0", 56 | "@web/dev-server": "^0.1.31", 57 | "@web/dev-server-legacy": "^1.0.0", 58 | "@web/test-runner": "^0.15.0", 59 | "@web/test-runner-playwright": "^0.9.0", 60 | "@webcomponents/webcomponentsjs": "^2.8.0", 61 | "eslint": "^8.15.0", 62 | "lit-analyzer": "^1.2.1", 63 | "prettier": "^2.6.2", 64 | "rimraf": "^3.0.2", 65 | "rollup": "^4.18.0", 66 | "rollup-plugin-summary": "^2.0.1", 67 | "typescript": "~5.9.0" 68 | }, 69 | "customElements": "custom-elements.json" 70 | } 71 | -------------------------------------------------------------------------------- /docs/install/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <my-element> ⌲ Install 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |

<my-element>

20 |

A web component just for me.

21 |
22 | 23 | 29 |
30 |
31 |

Install

32 |

<my-element> is distributed on npm, so you can install it locally or use it via npm CDNs like unpkg.com.

33 |

Local Installation

34 |
npm i my-element
35 |

CDN

36 |

npm CDNs like unpkg.com can directly serve files that have been published to npm. This works great for standard JavaScript modules that the browser can load natively.

37 |

For this element to work from unpkg.com specifically, you need to include the ?module query parameter, which tells unpkg.com to rewrite "bare" module specifiers to full URLs.

38 |

HTML

39 |
<script type="module" src="https://unpkg.com/my-element?module"></script>
40 |

JavaScript

41 |
import {MyElement} from 'https://unpkg.com/my-element?module';
42 | 43 |
44 |
45 | 46 | 52 | 53 | -------------------------------------------------------------------------------- /docs/docs.css: -------------------------------------------------------------------------------- 1 | * { 2 | box-sizing: border-box; 3 | } 4 | 5 | body { 6 | margin: 0; 7 | color: #333; 8 | font-family: 'Open Sans', arial, sans-serif; 9 | min-width: min-content; 10 | min-height: 100vh; 11 | font-size: 18px; 12 | display: flex; 13 | flex-direction: column; 14 | align-items: stretch; 15 | } 16 | 17 | #main-wrapper { 18 | flex-grow: 1; 19 | } 20 | 21 | main { 22 | max-width: 1024px; 23 | margin: 0 auto; 24 | } 25 | 26 | a:visited { 27 | color: inherit; 28 | } 29 | 30 | header { 31 | width: 100%; 32 | display: flex; 33 | flex-direction: column; 34 | align-items: center; 35 | justify-content: center; 36 | height: 360px; 37 | margin: 0; 38 | background: linear-gradient(0deg, rgba(9,9,121,1) 0%, rgba(0,212,255,1) 100%); 39 | color: white; 40 | } 41 | 42 | footer { 43 | width: 100%; 44 | min-height: 120px; 45 | background: gray; 46 | color: white; 47 | display: flex; 48 | flex-direction: column; 49 | justify-content: center; 50 | padding: 12px; 51 | margin-top: 64px; 52 | } 53 | 54 | h1 { 55 | font-size: 2.5em; 56 | font-weight: 400; 57 | } 58 | 59 | h2 { 60 | font-size: 1.6em; 61 | font-weight: 300; 62 | margin: 64px 0 12px; 63 | } 64 | 65 | h3 { 66 | font-weight: 300; 67 | } 68 | 69 | header h1 { 70 | width: auto; 71 | font-size: 2.8em; 72 | margin: 0; 73 | } 74 | 75 | header h2 { 76 | width: auto; 77 | margin: 0; 78 | } 79 | 80 | nav { 81 | display: grid; 82 | width: 100%; 83 | max-width: 100%; 84 | grid-template-columns: repeat(auto-fit, 240px); 85 | justify-content: center; 86 | border-bottom: 1px solid #efefef; 87 | } 88 | 89 | nav > a { 90 | color: #444; 91 | display: block; 92 | flex: 1; 93 | font-size: 18px; 94 | padding: 20px 0; 95 | text-align: center; 96 | text-decoration: none; 97 | } 98 | 99 | nav > a:hover { 100 | text-decoration: underline; 101 | } 102 | 103 | nav.collection { 104 | border: none; 105 | } 106 | 107 | nav.collection > ul { 108 | padding: 0; 109 | list-style: none; 110 | } 111 | 112 | nav.collection > ul > li { 113 | padding: 4px 0; 114 | } 115 | 116 | nav.collection > ul > li.selected { 117 | font-weight: 600; 118 | } 119 | 120 | nav.collection a { 121 | text-decoration: none; 122 | } 123 | 124 | nav.collection a:hover { 125 | text-decoration: underline; 126 | } 127 | 128 | section.columns { 129 | display: grid; 130 | grid-template-columns: repeat(auto-fit, minmax(400px, 488px)); 131 | grid-gap: 48px; 132 | justify-content: center; 133 | } 134 | 135 | section.columns > div { 136 | flex: 1; 137 | } 138 | 139 | section.examples { 140 | display: grid; 141 | grid-template-columns: 240px minmax(400px, 784px); 142 | grid-gap: 48px; 143 | justify-content: center; 144 | } 145 | 146 | section.examples h2:first-of-type { 147 | margin-top: 0; 148 | } 149 | 150 | table { 151 | width: 100%; 152 | border-collapse: collapse; 153 | } 154 | th { 155 | font-weight: 600; 156 | } 157 | 158 | td, th { 159 | border: solid 1px #aaa; 160 | padding: 4px; 161 | text-align: left; 162 | vertical-align: top; 163 | } 164 | -------------------------------------------------------------------------------- /docs-src/docs.css: -------------------------------------------------------------------------------- 1 | * { 2 | box-sizing: border-box; 3 | } 4 | 5 | body { 6 | margin: 0; 7 | color: #333; 8 | font-family: 'Open Sans', arial, sans-serif; 9 | min-width: min-content; 10 | min-height: 100vh; 11 | font-size: 18px; 12 | display: flex; 13 | flex-direction: column; 14 | align-items: stretch; 15 | } 16 | 17 | #main-wrapper { 18 | flex-grow: 1; 19 | } 20 | 21 | main { 22 | max-width: 1024px; 23 | margin: 0 auto; 24 | } 25 | 26 | a:visited { 27 | color: inherit; 28 | } 29 | 30 | header { 31 | width: 100%; 32 | display: flex; 33 | flex-direction: column; 34 | align-items: center; 35 | justify-content: center; 36 | height: 360px; 37 | margin: 0; 38 | background: linear-gradient(0deg, rgba(9,9,121,1) 0%, rgba(0,212,255,1) 100%); 39 | color: white; 40 | } 41 | 42 | footer { 43 | width: 100%; 44 | min-height: 120px; 45 | background: gray; 46 | color: white; 47 | display: flex; 48 | flex-direction: column; 49 | justify-content: center; 50 | padding: 12px; 51 | margin-top: 64px; 52 | } 53 | 54 | h1 { 55 | font-size: 2.5em; 56 | font-weight: 400; 57 | } 58 | 59 | h2 { 60 | font-size: 1.6em; 61 | font-weight: 300; 62 | margin: 64px 0 12px; 63 | } 64 | 65 | h3 { 66 | font-weight: 300; 67 | } 68 | 69 | header h1 { 70 | width: auto; 71 | font-size: 2.8em; 72 | margin: 0; 73 | } 74 | 75 | header h2 { 76 | width: auto; 77 | margin: 0; 78 | } 79 | 80 | nav { 81 | display: grid; 82 | width: 100%; 83 | max-width: 100%; 84 | grid-template-columns: repeat(auto-fit, 240px); 85 | justify-content: center; 86 | border-bottom: 1px solid #efefef; 87 | } 88 | 89 | nav > a { 90 | color: #444; 91 | display: block; 92 | flex: 1; 93 | font-size: 18px; 94 | padding: 20px 0; 95 | text-align: center; 96 | text-decoration: none; 97 | } 98 | 99 | nav > a:hover { 100 | text-decoration: underline; 101 | } 102 | 103 | nav.collection { 104 | border: none; 105 | } 106 | 107 | nav.collection > ul { 108 | padding: 0; 109 | list-style: none; 110 | } 111 | 112 | nav.collection > ul > li { 113 | padding: 4px 0; 114 | } 115 | 116 | nav.collection > ul > li.selected { 117 | font-weight: 600; 118 | } 119 | 120 | nav.collection a { 121 | text-decoration: none; 122 | } 123 | 124 | nav.collection a:hover { 125 | text-decoration: underline; 126 | } 127 | 128 | section.columns { 129 | display: grid; 130 | grid-template-columns: repeat(auto-fit, minmax(400px, 488px)); 131 | grid-gap: 48px; 132 | justify-content: center; 133 | } 134 | 135 | section.columns > div { 136 | flex: 1; 137 | } 138 | 139 | section.examples { 140 | display: grid; 141 | grid-template-columns: 240px minmax(400px, 784px); 142 | grid-gap: 48px; 143 | justify-content: center; 144 | } 145 | 146 | section.examples h2:first-of-type { 147 | margin-top: 0; 148 | } 149 | 150 | table { 151 | width: 100%; 152 | border-collapse: collapse; 153 | } 154 | th { 155 | font-weight: 600; 156 | } 157 | 158 | td, th { 159 | border: solid 1px #aaa; 160 | padding: 4px; 161 | text-align: left; 162 | vertical-align: top; 163 | } 164 | -------------------------------------------------------------------------------- /docs/examples/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <my-element> ⌲ Examples ⌲ Basic 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |

<my-element>

20 |

A web component just for me.

21 |
22 | 23 | 29 |
30 |
31 | 32 |

Example: Basic

33 |
34 | 47 |
48 | 54 | 55 |

This is child content

56 |
57 |

CSS

58 |
p {
border: solid 1px blue;
padding: 8px;
}
59 |

HTML

60 |
<my-element>
<p>This is child content</p>
</my-element>
61 | 62 |
63 |
64 | 65 |
66 |
67 | 68 | 74 | 75 | -------------------------------------------------------------------------------- /docs-src/api.11ty.cjs: -------------------------------------------------------------------------------- 1 | /** 2 | * This page generates its content from the custom-element.json file as read by 3 | * the _data/api.11tydata.js script. 4 | */ 5 | module.exports = class Docs { 6 | data() { 7 | return { 8 | layout: 'page.11ty.cjs', 9 | title: ' ⌲ Docs', 10 | }; 11 | } 12 | 13 | render(data) { 14 | const manifest = data.api['11tydata'].customElements; 15 | const elements = manifest.modules.reduce( 16 | (els, module) => 17 | els.concat( 18 | module.declarations?.filter((dec) => dec.customElement) ?? [] 19 | ), 20 | [] 21 | ); 22 | return ` 23 |

API

24 | ${elements 25 | .map( 26 | (element) => ` 27 |

<${element.tagName}>

28 |
29 | ${element.description} 30 |
31 | ${renderTable( 32 | 'Attributes', 33 | ['name', 'description', 'type.text', 'default'], 34 | element.attributes 35 | )} 36 | ${renderTable( 37 | 'Properties', 38 | ['name', 'attribute', 'description', 'type.text', 'default'], 39 | element.members.filter((m) => m.kind === 'field') 40 | )} 41 | ${renderTable( 42 | 'Methods', 43 | ['name', 'parameters', 'description', 'return.type.text'], 44 | element.members 45 | .filter((m) => m.kind === 'method' && m.privacy !== 'private') 46 | .map((m) => ({ 47 | ...m, 48 | parameters: renderTable( 49 | '', 50 | ['name', 'description', 'type.text'], 51 | m.parameters 52 | ), 53 | })) 54 | )} 55 | ${renderTable('Events', ['name', 'description'], element.events)} 56 | ${renderTable( 57 | 'Slots', 58 | [['name', '(default)'], 'description'], 59 | element.slots 60 | )} 61 | ${renderTable( 62 | 'CSS Shadow Parts', 63 | ['name', 'description'], 64 | element.cssParts 65 | )} 66 | ${renderTable( 67 | 'CSS Custom Properties', 68 | ['name', 'description'], 69 | element.cssProperties 70 | )} 71 | ` 72 | ) 73 | .join('')} 74 | `; 75 | } 76 | }; 77 | 78 | /** 79 | * Reads a (possibly deep) path off of an object. 80 | */ 81 | const get = (obj, path) => { 82 | let fallback = ''; 83 | if (Array.isArray(path)) { 84 | [path, fallback] = path; 85 | } 86 | const parts = path.split('.'); 87 | while (obj && parts.length) { 88 | obj = obj[parts.shift()]; 89 | } 90 | return obj == null || obj === '' ? fallback : obj; 91 | }; 92 | 93 | /** 94 | * Renders a table of data, plucking the given properties from each item in 95 | * `data`. 96 | */ 97 | const renderTable = (name, properties, data) => { 98 | if (data === undefined || data.length === 0) { 99 | return ''; 100 | } 101 | return ` 102 | ${name ? `

${name}

` : ''} 103 | 104 | 105 | ${properties 106 | .map( 107 | (p) => 108 | `` 111 | ) 112 | .join('')} 113 | 114 | ${data 115 | .map( 116 | (i) => ` 117 | 118 | ${properties.map((p) => ``).join('')} 119 | 120 | ` 121 | ) 122 | .join('')} 123 |
${capitalize( 109 | (Array.isArray(p) ? p[0] : p).split('.')[0] 110 | )}
${get(i, p)}
124 | `; 125 | }; 126 | 127 | const capitalize = (s) => s[0].toUpperCase() + s.substring(1); 128 | -------------------------------------------------------------------------------- /docs/api/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <my-element> ⌲ Docs 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |

<my-element>

20 |

A web component just for me.

21 |
22 | 23 | 29 |
30 |
31 | 32 |

API

33 | 34 |

<my-element>

35 |
36 | An example element. 37 |
38 | 39 |

Attributes

40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
NameDescriptionTypeDefault
nameThe name to say "Hello" to.string'World'
countThe number of times the button has been clicked.number0
54 | 55 | 56 |

Properties

57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
NameAttributeDescriptionTypeDefault
namenameThe name to say "Hello" to.string'World'
countcountThe number of times the button has been clicked.number0
71 | 72 | 73 |

Methods

74 | 75 | 76 | 77 | 78 | 79 | 80 | 93 | 94 | 95 |
NameParametersDescriptionReturn
sayHello 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 |
NameDescriptionType
nameThe name to say "Hello" tostring
92 |
Formats a greetingstring
96 | 97 | 98 |

Events

99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 |
NameDescription
count-changedIndicates when the count changes
109 | 110 | 111 |

Slots

112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
NameDescription
(default)This element has a slot
122 | 123 | 124 |

CSS Shadow Parts

125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 |
NameDescription
buttonThe button
135 | 136 | 137 | 138 | 139 |
140 |
141 | 142 | 148 | 149 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <my-element> ⌲ Home 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |

<my-element>

20 |

A web component just for me.

21 |
22 | 23 | 29 |
30 |
31 |

<my-element>

32 |

<my-element> is an awesome element. It's a great introduction to building web components with LitElement, with nice documentation site as well.

33 |

As easy as HTML

34 |
35 |
36 |

<my-element> is just an HTML element. You can it anywhere you can use HTML!

37 |
<my-element></my-element>
38 |
39 |
40 |

41 |
42 |
43 |

Configure with attributes

44 |
45 |
46 |

<my-element> can be configured with attributed in plain HTML.

47 |
<my-element name="HTML"></my-element>
48 |
49 |
50 |

51 |
52 |
53 |

Declarative rendering

54 |
55 |
56 |

<my-element> can be used with declarative rendering libraries like Angular, React, Vue, and lit-html

57 |
import {html, render} from 'lit-html';

const name = 'lit-html';

render(
html`
<h2>This is a &lt;my-element&gt;</h2>
<my-element .name=
${name}></my-element>
`
,
document.body
);
58 |
59 |
60 |

This is a <my-element>

61 | 62 |
63 |
64 | 65 |
66 |
67 | 68 | 74 | 75 | -------------------------------------------------------------------------------- /web-test-runner.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @license 3 | * Copyright 2021 Google LLC 4 | * SPDX-License-Identifier: BSD-3-Clause 5 | */ 6 | 7 | import {legacyPlugin} from '@web/dev-server-legacy'; 8 | import {playwrightLauncher} from '@web/test-runner-playwright'; 9 | 10 | const mode = process.env.MODE || 'dev'; 11 | if (!['dev', 'prod'].includes(mode)) { 12 | throw new Error(`MODE must be "dev" or "prod", was "${mode}"`); 13 | } 14 | 15 | // Uncomment for testing on Sauce Labs 16 | // Must run `npm i --save-dev @web/test-runner-saucelabs` and set 17 | // SAUCE_USERNAME and SAUCE_USERNAME environment variables 18 | // =========== 19 | // import {createSauceLabsLauncher} from '@web/test-runner-saucelabs'; 20 | // const sauceLabsLauncher = createSauceLabsLauncher( 21 | // { 22 | // user: process.env.SAUCE_USERNAME, 23 | // key: process.env.SAUCE_USERNAME, 24 | // }, 25 | // { 26 | // 'sauce:options': { 27 | // name: 'unit tests', 28 | // build: `${process.env.GITHUB_REF ?? 'local'} build ${ 29 | // process.env.GITHUB_RUN_NUMBER ?? '' 30 | // }`, 31 | // }, 32 | // } 33 | // ); 34 | 35 | // Uncomment for testing on BrowserStack 36 | // Must run `npm i --save-dev @web/test-runner-browserstack` and set 37 | // BROWSER_STACK_USERNAME and BROWSER_STACK_ACCESS_KEY environment variables 38 | // =========== 39 | // import {browserstackLauncher as createBrowserstackLauncher} from '@web/test-runner-browserstack'; 40 | // const browserstackLauncher = (config) => createBrowserstackLauncher({ 41 | // capabilities: { 42 | // 'browserstack.user': process.env.BROWSER_STACK_USERNAME, 43 | // 'browserstack.key': process.env.BROWSER_STACK_ACCESS_KEY, 44 | // project: 'my-element', 45 | // name: 'unit tests', 46 | // build: `${process.env.GITHUB_REF ?? 'local'} build ${ 47 | // process.env.GITHUB_RUN_NUMBER ?? '' 48 | // }`, 49 | // ...config, 50 | // } 51 | // }); 52 | 53 | const browsers = { 54 | // Local browser testing via playwright 55 | // =========== 56 | chromium: playwrightLauncher({product: 'chromium'}), 57 | firefox: playwrightLauncher({product: 'firefox'}), 58 | webkit: playwrightLauncher({product: 'webkit'}), 59 | 60 | // Uncomment example launchers for running on Sauce Labs 61 | // =========== 62 | // chromium: sauceLabsLauncher({browserName: 'chrome', browserVersion: 'latest', platformName: 'Windows 10'}), 63 | // firefox: sauceLabsLauncher({browserName: 'firefox', browserVersion: 'latest', platformName: 'Windows 10'}), 64 | // safari: sauceLabsLauncher({browserName: 'safari', browserVersion: 'latest', platformName: 'macOS 10.15'}), 65 | 66 | // Uncomment example launchers for running on Sauce Labs 67 | // =========== 68 | // chromium: browserstackLauncher({browserName: 'Chrome', os: 'Windows', os_version: '10'}), 69 | // firefox: browserstackLauncher({browserName: 'Firefox', os: 'Windows', os_version: '10'}), 70 | // safari: browserstackLauncher({browserName: 'Safari', browser_version: '14.0', os: 'OS X', os_version: 'Big Sur'}), 71 | }; 72 | 73 | // Prepend BROWSERS=x,y to `npm run test` to run a subset of browsers 74 | // e.g. `BROWSERS=chromium,firefox npm run test` 75 | const noBrowser = (b) => { 76 | throw new Error(`No browser configured named '${b}'; using defaults`); 77 | }; 78 | let commandLineBrowsers; 79 | try { 80 | commandLineBrowsers = process.env.BROWSERS?.split(',').map( 81 | (b) => browsers[b] ?? noBrowser(b) 82 | ); 83 | } catch (e) { 84 | console.warn(e); 85 | } 86 | 87 | // https://modern-web.dev/docs/test-runner/cli-and-configuration/ 88 | export default { 89 | rootDir: '.', 90 | files: ['./test/**/*_test.js'], 91 | nodeResolve: {exportConditions: mode === 'dev' ? ['development'] : []}, 92 | preserveSymlinks: true, 93 | browsers: commandLineBrowsers ?? Object.values(browsers), 94 | testFramework: { 95 | // https://mochajs.org/api/mocha 96 | config: { 97 | ui: 'tdd', 98 | timeout: '60000', 99 | }, 100 | }, 101 | plugins: [ 102 | // Detect browsers without modules (e.g. IE11) and transform to SystemJS 103 | // (https://modern-web.dev/docs/dev-server/plugins/legacy/). 104 | legacyPlugin({ 105 | polyfills: { 106 | webcomponents: true, 107 | // Inject lit's polyfill-support module into test files, which is required 108 | // for interfacing with the webcomponents polyfills 109 | custom: [ 110 | { 111 | name: 'lit-polyfill-support', 112 | path: 'node_modules/lit/polyfill-support.js', 113 | test: "!('attachShadow' in Element.prototype) || !('getRootNode' in Element.prototype) || window.ShadyDOM && window.ShadyDOM.force", 114 | module: false, 115 | }, 116 | ], 117 | }, 118 | }), 119 | ], 120 | }; 121 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LitElement TypeScript starter 2 | 3 | This project includes a sample component using LitElement with TypeScript. 4 | 5 | This template is generated from the `lit-starter-ts` package in [the main Lit 6 | repo](https://github.com/lit/lit). Issues and PRs for this template should be 7 | filed in that repo. 8 | 9 | ## About this release 10 | 11 | This is a pre-release of Lit 3.0, the next major version of Lit. 12 | 13 | Lit 3.0 has very few breaking changes from Lit 2.0: 14 | 15 | - Drops support for IE11 16 | - Published as ES2021 17 | - Removes a couple of deprecated Lit 1.x APIs 18 | 19 | Lit 3.0 should require no changes to upgrade from Lit 2.0 for the vast majority of users. Once the full release is published, most apps and libraries will be able to extend their npm version ranges to include both 2.x and 3.x, like `"^2.7.0 || ^3.0.0"`. 20 | 21 | Lit 2.x and 3.0 are _interoperable_: templates, base classes, directives, decorators, etc., from one version of Lit will work with those from another. 22 | 23 | Please file any issues you find on our [issue tracker](https://github.com/lit/lit/issues). 24 | 25 | ## Setup 26 | 27 | Install dependencies: 28 | 29 | ```bash 30 | npm i 31 | ``` 32 | 33 | ## Build 34 | 35 | This sample uses the TypeScript compiler to produce JavaScript that runs in modern browsers. 36 | 37 | To build the JavaScript version of your component: 38 | 39 | ```bash 40 | npm run build 41 | ``` 42 | 43 | To watch files and rebuild when the files are modified, run the following command in a separate shell: 44 | 45 | ```bash 46 | npm run build:watch 47 | ``` 48 | 49 | Both the TypeScript compiler and lit-analyzer are configured to be very strict. You may want to change `tsconfig.json` to make them less strict. 50 | 51 | ## Testing 52 | 53 | This sample uses modern-web.dev's 54 | [@web/test-runner](https://www.npmjs.com/package/@web/test-runner) for testing. See the 55 | [modern-web.dev testing documentation](https://modern-web.dev/docs/test-runner/overview) for 56 | more information. 57 | 58 | Tests can be run with the `test` script, which will run your tests against Lit's development mode (with more verbose errors) as well as against Lit's production mode: 59 | 60 | ```bash 61 | npm test 62 | ``` 63 | 64 | For local testing during development, the `test:dev:watch` command will run your tests in Lit's development mode (with verbose errors) on every change to your source files: 65 | 66 | ```bash 67 | npm test:watch 68 | ``` 69 | 70 | Alternatively the `test:prod` and `test:prod:watch` commands will run your tests in Lit's production mode. 71 | 72 | ## Dev Server 73 | 74 | This sample uses modern-web.dev's [@web/dev-server](https://www.npmjs.com/package/@web/dev-server) for previewing the project without additional build steps. Web Dev Server handles resolving Node-style "bare" import specifiers, which aren't supported in browsers. It also automatically transpiles JavaScript and adds polyfills to support older browsers. See [modern-web.dev's Web Dev Server documentation](https://modern-web.dev/docs/dev-server/overview/) for more information. 75 | 76 | To run the dev server and open the project in a new browser tab: 77 | 78 | ```bash 79 | npm run serve 80 | ``` 81 | 82 | There is a development HTML file located at `/dev/index.html` that you can view at http://localhost:8000/dev/index.html. Note that this command will serve your code using Lit's development mode (with more verbose errors). To serve your code against Lit's production mode, use `npm run serve:prod`. 83 | 84 | ## Editing 85 | 86 | If you use VS Code, we highly recommend the [lit-plugin extension](https://marketplace.visualstudio.com/items?itemName=runem.lit-plugin), which enables some extremely useful features for lit-html templates: 87 | 88 | - Syntax highlighting 89 | - Type-checking 90 | - Code completion 91 | - Hover-over docs 92 | - Jump to definition 93 | - Linting 94 | - Quick Fixes 95 | 96 | The project is setup to recommend lit-plugin to VS Code users if they don't already have it installed. 97 | 98 | ## Linting 99 | 100 | Linting of TypeScript files is provided by [ESLint](eslint.org) and [TypeScript ESLint](https://github.com/typescript-eslint/typescript-eslint). In addition, [lit-analyzer](https://www.npmjs.com/package/lit-analyzer) is used to type-check and lint lit-html templates with the same engine and rules as lit-plugin. 101 | 102 | The rules are mostly the recommended rules from each project, but some have been turned off to make LitElement usage easier. The recommended rules are pretty strict, so you may want to relax them by editing `.eslintrc.json` and `tsconfig.json`. 103 | 104 | To lint the project run: 105 | 106 | ```bash 107 | npm run lint 108 | ``` 109 | 110 | ## Formatting 111 | 112 | [Prettier](https://prettier.io/) is used for code formatting. It has been pre-configured according to the Lit's style. You can change this in `.prettierrc.json`. 113 | 114 | Prettier has not been configured to run when committing files, but this can be added with Husky and `pretty-quick`. See the [prettier.io](https://prettier.io/) site for instructions. 115 | 116 | ## Static Site 117 | 118 | This project includes a simple website generated with the [eleventy](https://11ty.dev) static site generator and the templates and pages in `/docs-src`. The site is generated to `/docs` and intended to be checked in so that GitHub pages can serve the site [from `/docs` on the main branch](https://help.github.com/en/github/working-with-github-pages/configuring-a-publishing-source-for-your-github-pages-site). 119 | 120 | To enable the site go to the GitHub settings and change the GitHub Pages "Source" setting to "main branch /docs folder".

121 | 122 | To build the site, run: 123 | 124 | ```bash 125 | npm run docs 126 | ``` 127 | 128 | To serve the site locally, run: 129 | 130 | ```bash 131 | npm run docs:serve 132 | ``` 133 | 134 | To watch the site files, and re-build automatically, run: 135 | 136 | ```bash 137 | npm run docs:gen:watch 138 | ``` 139 | 140 | The site will usually be served at http://localhost:8000. 141 | 142 | **Note**: The project uses Rollup to bundle and minify the source code for the docs site and not to publish to NPM. For bundling and minification, check the [Bundling and minification](#bundling-and-minification) section. 143 | 144 | ## Bundling and minification 145 | 146 | As stated in the [static site generation](#static-site) section, the bundling and minification setup in the Rollup configuration in this project is there specifically for the docs generation. 147 | 148 | We recommend publishing components as unoptimized JavaScript modules and performing build-time optimizations at the application level. This gives build tools the best chance to deduplicate code, remove dead code, and so on. 149 | 150 | Please check the [Publishing best practices](https://lit.dev/docs/tools/publishing/#publishing-best-practices) for information on publishing reusable Web Components, and [Build for production](https://lit.dev/docs/tools/production/) for building application projects that include LitElement components, on the Lit site. 151 | 152 | ## More information 153 | 154 | See [Get started](https://lit.dev/docs/getting-started/) on the Lit site for more information. 155 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @lit/lit-starter-ts 2 | 3 | ## 2.0.2 4 | 5 | ### Patch Changes 6 | 7 | - [#4682](https://github.com/lit/lit/pull/4682) [`290a608a`](https://github.com/lit/lit/commit/290a608aa2297e8b99a5424dc90632b97c66386c) - Update typescript to 5.5.0 8 | 9 | - [#4681](https://github.com/lit/lit/pull/4681) [`5463b104`](https://github.com/lit/lit/commit/5463b1046e0589c9ce7041e67cd539ddfba2e5a7) - Update Rollup and Terser dependencies 10 | 11 | - Updated dependencies [[`feccc1ba`](https://github.com/lit/lit/commit/feccc1ba8e82b36d07a0e2576381bf2819926b98)]: 12 | - lit@3.2.0 13 | 14 | ## 2.0.1 15 | 16 | ### Patch Changes 17 | 18 | - [#4451](https://github.com/lit/lit/pull/4451) [`7852e130`](https://github.com/lit/lit/commit/7852e13022c9dcfcff5ed54a215c93420349e318) - Minor security fixes. 19 | 20 | ## 2.0.0 21 | 22 | ### Major Changes 23 | 24 | - [#4141](https://github.com/lit/lit/pull/4141) [`6b515e43`](https://github.com/lit/lit/commit/6b515e43c3a24cc8a593247d3aa72d81bcc724d5) - Update TypeScript to ~5.2.0 25 | 26 | - [#3756](https://github.com/lit/lit/pull/3756) [`f06f7972`](https://github.com/lit/lit/commit/f06f7972a027d2937fe2c68ab5af0274dec57cf4) - Drop IE11 support 27 | 28 | ### Patch Changes 29 | 30 | - [#3814](https://github.com/lit/lit/pull/3814) [`23326c6b`](https://github.com/lit/lit/commit/23326c6b9a6abdf01998dadf5d0f20a643e457aa) - Update to TypeScript v5.0 31 | 32 | - Updated dependencies [[`dfd747cf`](https://github.com/lit/lit/commit/dfd747cf4f7239e0c3bb7134f8acb967d0157654), [`6b515e43`](https://github.com/lit/lit/commit/6b515e43c3a24cc8a593247d3aa72d81bcc724d5), [`23c404fd`](https://github.com/lit/lit/commit/23c404fdec0cd7be834221b6ddf9b659c24ca8a2), [`1040f758`](https://github.com/lit/lit/commit/1040f75861b029527538b4ec36b2cfedcc32988a), [`0f6878dc`](https://github.com/lit/lit/commit/0f6878dc45fd95bbeb8750f277349c1392e2b3ad), [`1db01376`](https://github.com/lit/lit/commit/1db0137699b35d7e7bfac9b2ab274af4100fd7cf), [`2a01471a`](https://github.com/lit/lit/commit/2a01471a5f65fe34bad11e1099281811b8d0f79b), [`6f2833fd`](https://github.com/lit/lit/commit/6f2833fd05f2ecde5386f72d291dafc9dbae0cf7), [`c3e473b4`](https://github.com/lit/lit/commit/c3e473b499ff029b5e1aff01ca8799daf1ca1bbe), [`2eba6997`](https://github.com/lit/lit/commit/2eba69974c9e130e7483f44f9daca308345497d5), [`92cedaa2`](https://github.com/lit/lit/commit/92cedaa2c8cd8a306be3fe25d52e0e47bb044020), [`d27a77ec`](https://github.com/lit/lit/commit/d27a77ec3d3999e872df9218a2b07f90f22eb417), [`7e8491d4`](https://github.com/lit/lit/commit/7e8491d4ed9f0c39d974616c4678552ef50b81df), [`6470807f`](https://github.com/lit/lit/commit/6470807f3a0981f9d418cb26f05969912455d148), [`23326c6b`](https://github.com/lit/lit/commit/23326c6b9a6abdf01998dadf5d0f20a643e457aa), [`09949234`](https://github.com/lit/lit/commit/09949234445388d51bfb4ee24ff28a4c9f82fe17), [`f06f7972`](https://github.com/lit/lit/commit/f06f7972a027d2937fe2c68ab5af0274dec57cf4)]: 33 | - lit@3.0.0 34 | 35 | ## 2.0.0-pre.1 36 | 37 | ### Major Changes 38 | 39 | - [#4141](https://github.com/lit/lit/pull/4141) [`6b515e43`](https://github.com/lit/lit/commit/6b515e43c3a24cc8a593247d3aa72d81bcc724d5) - Update TypeScript to ~5.2.0 40 | 41 | ### Patch Changes 42 | 43 | - Updated dependencies [[`6b515e43`](https://github.com/lit/lit/commit/6b515e43c3a24cc8a593247d3aa72d81bcc724d5), [`0f6878dc`](https://github.com/lit/lit/commit/0f6878dc45fd95bbeb8750f277349c1392e2b3ad), [`2a01471a`](https://github.com/lit/lit/commit/2a01471a5f65fe34bad11e1099281811b8d0f79b), [`2eba6997`](https://github.com/lit/lit/commit/2eba69974c9e130e7483f44f9daca308345497d5), [`d27a77ec`](https://github.com/lit/lit/commit/d27a77ec3d3999e872df9218a2b07f90f22eb417), [`6470807f`](https://github.com/lit/lit/commit/6470807f3a0981f9d418cb26f05969912455d148), [`09949234`](https://github.com/lit/lit/commit/09949234445388d51bfb4ee24ff28a4c9f82fe17)]: 44 | - lit@3.0.0-pre.1 45 | 46 | ## 2.0.0-pre.0 47 | 48 | ### Major Changes 49 | 50 | - [#3756](https://github.com/lit/lit/pull/3756) [`f06f7972`](https://github.com/lit/lit/commit/f06f7972a027d2937fe2c68ab5af0274dec57cf4) - Drop IE11 support 51 | 52 | ### Patch Changes 53 | 54 | - [#3814](https://github.com/lit/lit/pull/3814) [`23326c6b`](https://github.com/lit/lit/commit/23326c6b9a6abdf01998dadf5d0f20a643e457aa) - Update to TypeScript v5.0 55 | 56 | - Updated dependencies [[`dfd747cf`](https://github.com/lit/lit/commit/dfd747cf4f7239e0c3bb7134f8acb967d0157654), [`23c404fd`](https://github.com/lit/lit/commit/23c404fdec0cd7be834221b6ddf9b659c24ca8a2), [`1db01376`](https://github.com/lit/lit/commit/1db0137699b35d7e7bfac9b2ab274af4100fd7cf), [`c3e473b4`](https://github.com/lit/lit/commit/c3e473b499ff029b5e1aff01ca8799daf1ca1bbe), [`92cedaa2`](https://github.com/lit/lit/commit/92cedaa2c8cd8a306be3fe25d52e0e47bb044020), [`23326c6b`](https://github.com/lit/lit/commit/23326c6b9a6abdf01998dadf5d0f20a643e457aa), [`f06f7972`](https://github.com/lit/lit/commit/f06f7972a027d2937fe2c68ab5af0274dec57cf4)]: 57 | - lit@3.0.0-pre.0 58 | 59 | ## 1.0.6 60 | 61 | ### Patch Changes 62 | 63 | - [#4157](https://github.com/lit/lit/pull/4157) [`da32db2e`](https://github.com/lit/lit/commit/da32db2e67547e0f17b7132065559eba2b1d3513) Thanks [@welingtonms](https://github.com/welingtonms)! - Improve bundling and minification recommendations. 64 | 65 | ## 1.0.5 66 | 67 | ### Patch Changes 68 | 69 | - [#3561](https://github.com/lit/lit/pull/3561) [`e5c254e9`](https://github.com/lit/lit/commit/e5c254e96cb5d0f770ec616332e231559325c5c5) - Update dependency `@rollup/plugin-replace` 70 | 71 | ## 1.0.4 72 | 73 | ### Patch Changes 74 | 75 | - [#2922](https://github.com/lit/lit/pull/2922) [`da9db86a`](https://github.com/lit/lit/commit/da9db86a33cba710d439e254df2492f9f6dcbbee) - Update dependencies and remove unused dependencies 76 | 77 | ## 1.0.3 78 | 79 | ### Patch Changes 80 | 81 | - [#2757](https://github.com/lit/lit/pull/2757) [`55841c14`](https://github.com/lit/lit/commit/55841c14f52891357dd93680d3bc5b1da6c89c8a) - Update Rollup and Rollup plugins 82 | 83 | ## 1.0.2 84 | 85 | ### Patch Changes 86 | 87 | - [#2535](https://github.com/lit/lit/pull/2535) [`d1359856`](https://github.com/lit/lit/commit/d1359856698d1af381b335fb757f9282574690b0) - Update the README to indicate that issues and PRs should be filed on the main Lit repo. 88 | 89 | ## 1.0.1 90 | 91 | ### Patch Changes 92 | 93 | - [#2300](https://github.com/lit/lit/pull/2300) [`8b9dcb4d`](https://github.com/lit/lit/commit/8b9dcb4d10e4161083146ae40d0b12174a63d31d) - Fix starter kits so `npm run serve` serves the root directory, and add a link to the `/dev/index.html` component example from `/`. 94 | 95 | - Updated dependencies [[`fcc2b3d0`](https://github.com/lit/lit/commit/fcc2b3d0054e69e6f76588ea9f440117b6d0deed), [`49ecf623`](https://github.com/lit/lit/commit/49ecf6239033e9578184d46116e6b89676d091db), [`1d563e83`](https://github.com/lit/lit/commit/1d563e830c02a2d1a22e1e939f1ace971b1d1ae7)]: 96 | - lit@2.1.0 97 | 98 | ## 1.0.0 99 | 100 | ### Patch Changes 101 | 102 | - [#2113](https://github.com/lit/lit/pull/2113) [`5b2f3642`](https://github.com/lit/lit/commit/5b2f3642ff91931b5b01f8bdd2ed98aba24f1047) - Dependency upgrades including TypeScript 4.4.2 103 | 104 | - [#2103](https://github.com/lit/lit/pull/2103) [`15a8356d`](https://github.com/lit/lit/commit/15a8356ddd59a1e80880a93acd21fadc9c24e14b) - Added Lit dev mode to test and serve commands, controlled via the MODE=dev or MODE=prod environment variables. 105 | 106 | - [#2117](https://github.com/lit/lit/pull/2117) [`eff2fbc7`](https://github.com/lit/lit/commit/eff2fbc7e45cfc2a7b8df21e18c84619dfbcb277) - Updated starter templates to use open-wc analyzer for generating custom-elements.json, and updated basic API docs generater included in the template to the new manifest format. 107 | 108 | - Updated dependencies [[`15a8356d`](https://github.com/lit/lit/commit/15a8356ddd59a1e80880a93acd21fadc9c24e14b), [`5fabe2b5`](https://github.com/lit/lit/commit/5fabe2b5ae4ab8fba9dc2d23a69105d32e4c0705), [`5b2f3642`](https://github.com/lit/lit/commit/5b2f3642ff91931b5b01f8bdd2ed98aba24f1047), [`5fabe2b5`](https://github.com/lit/lit/commit/5fabe2b5ae4ab8fba9dc2d23a69105d32e4c0705), [`5fabe2b5`](https://github.com/lit/lit/commit/5fabe2b5ae4ab8fba9dc2d23a69105d32e4c0705), [`0312f3e5`](https://github.com/lit/lit/commit/0312f3e533611eb3f4f9381594485a33ad003b74)]: 109 | - lit@2.0.0 110 | --------------------------------------------------------------------------------