progressively-enhance-web-components 1.0.3 → 2.0.1

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/CHANGELOG.md CHANGED
@@ -1,8 +1,30 @@
1
- # Changelog
1
+ ## 2.0.1
2
+
3
+ - Altered the npm package to not include unnecessary files.
4
+
5
+ ## 2.0.0
6
+
7
+ - Breaking: A component is now written into a declarative shadow root, with a copy of its markup kept beside that as fallback content, rather than into the light DOM alone. This keeps the `<style>`, `<script>` and `<slot>` elements a fallback cannot use, styles the component and makes its slots work before any JavaScript runs, and leaves nothing to be swapped once the component upgrades, while a browser that does not build shadow roots still renders the fallback as it always did.
8
+ - Related: A component class that calls `attachShadow` unconditionally now throws away what the server rendered. The browser's parser has already built the shadow root, and `attachShadow` on one it built does not fail: it hands back that same root having emptied it, so the class appears to work while rebuilding in the browser everything that had already arrived rendered, which is the cost a declarative shadow root exists to avoid. Read `this.shadowRoot` instead, falling back to `attachShadow` for an element created in JavaScript rather than written into the page, and fill the shadow root from the `<template>` only when it is empty.
9
+ - Related: The children of an invocation are now left where they were written, being the light DOM that the slots of the shadow root project. Previously a child carrying a `slot` attribute was moved to the top level of the fallback and a child without one was dropped. Only a direct child of an element can be assigned to a slot, so a slotted child written deeper than that no longer reaches one.
10
+ - To keep the previous output exactly, set the new `mode` param to `light`.
11
+ - Added `both`, `shadow`, and `light` enhancement modes, set for the whole project with the `mode` param or per component with a `mode` attribute on its `<template>`. `both` is the default and is described above. `shadow` writes only the declarative shadow root, which is smaller but renders nothing at all where declarative shadow DOM is unsupported. `light` writes only the fallback markup, which is what this module did before this version.
12
+ - Added a `data-enhanced` attribute, written onto every element this module enhances. An element that already carries one is left exactly as it was, so running this over templates it has already preprocessed no longer stacks a second shadow root and a second copy of the fallback onto the same element. Write it yourself to keep an invocation whose markup you have written out by hand.
13
+ - Related: An invocation holding a `<template shadowrootmode>` of its own is left alone whether or not it carries the attribute, a browser refusing to build a second declarative shadow root on the same element.
14
+ - Added browser tests that drive the express sample app in Chromium with Playwright, covering what no preprocessor test can: that the parser builds the shadow root, that the component class upgrades the element without discarding what the server rendered into it, that slotted content is projected, that the fallback stays inert where a shadow root was built and renders where one was not, and that nothing is shown twice in either case.
15
+ - Fixed the sample app calling `body-parser`, which it never declared as a dependency and which Express has had built in for years.
16
+ - Fixed the pieces of an enhanced element running together on one line, the shadow root, the fallback and the light DOM now each starting on their own. js-beautify treats `<template>` as an inline element and would not break the line before one.
17
+ - Improved performance.
18
+ - Fixed a file invoking more than one kind of custom element only having the last one enhanced. Each custom element was applied to the file as it was on disk rather than to what the previous one had produced, so every pass but the last was thrown away.
19
+ - Fixed a custom element invoked inside another of the same kind producing malformed markup, with a stray closing tag left behind. Pairing an opening tag with the closing tag that belongs to it is not something a regular expression can do, so it is no longer asked to.
20
+ - Fixed `disableBeautify` being ignored when building a component's markup, so the option now leaves the markup alone as it says it does.
21
+ - Fixed the module silencing part of the host application's `console.error` for the life of the process. jsdom's complaints about unparseable CSS are now silenced only while the module is doing its work.
22
+ - Updated various dependencies.
2
23
 
3
- ## Next version
24
+ ## 1.0.4
4
25
 
5
- - Put your changes here...
26
+ - Fixed a bug that would cause the module to crash if the file list provided by the user wasn't a directory.
27
+ - Updated various dependencies.
6
28
 
7
29
  ## 1.0.3
8
30
 
@@ -0,0 +1,16 @@
1
+ When you call:
2
+
3
+ ```javascript
4
+ const editedFiles = require('progressively-enhance-web-components')({
5
+ templatesDir: './mvc/views'
6
+ })
7
+ ```
8
+
9
+ There are other params you can pass to it besides `templatesDir`.
10
+
11
+ The full list of params available is:
12
+
13
+ - `templatesDir` *[String]*: What folder to examine. This is required.
14
+ - `disableBeautify` *[Boolean]*: If set to true, this module will not beautify the HTML in the outputted markup. Default: `false`.
15
+ - `beautifyOptions` *[Object]*: Options to pass to [js-beautify](https://github.com/beautifier/js-beautify). Default: `{ indent_size: 2 }`.
16
+ - `mode` *[String]*: How to enhance an invocation whose definition does not ask for a mode of its own. One of `both`, `shadow`, or `light`. Default: `'both'`. See usage section for details.
package/README.md CHANGED
@@ -1,15 +1,20 @@
1
- progressively-enhance-web-components
2
- ===
3
-
4
- [![npm](https://img.shields.io/npm/v/progressively-enhance-web-components.svg)](https://www.npmjs.com/package/progressively-enhance-web-components)
1
+ 🕸️ **progressively-enhance-web-components** [![npm](https://img.shields.io/npm/v/progressively-enhance-web-components.svg)](https://www.npmjs.com/package/progressively-enhance-web-components)
5
2
 
6
3
  A template file preprocessor for [progressively enhancing](https://en.wikipedia.org/wiki/Progressive_enhancement) web components in Node.js.
7
4
 
8
5
  It works by reading a directory of HTML templates for your web application, identifying any web components, and replacing custom element invocations with fallback markup that will work if JavaScript is disabled which will then be progressively enhanced into the desired web component when the JavaScript loads.
9
6
 
10
- This allows you to use web components in server-side templating the same way you would with client-side templating without creating a hard dependency on JavaScript for server-side template renders and without having to write two different templates for each context.
7
+ This allows you to use web components in server-side templating the same way you would with client-side templating without creating a hard dependency on JavaScript for rendering templates with web components and without having to write two different templates for each context.
8
+
9
+ This module was built and is maintained by the [Roosevelt web framework](https://rooseveltframework.org) [team](https://rooseveltframework.org/contributors), but it can be used independently of Roosevelt as well.
11
10
 
12
- This module was built and is maintained by the [Roosevelt web framework](https://github.com/rooseveltframework/roosevelt) [team](https://github.com/orgs/rooseveltframework/people), but it can be used independently of Roosevelt as well.
11
+ <details open>
12
+ <summary>Documentation</summary>
13
+ <ul>
14
+ <li><a href="./USAGE.md">Usage</a></li>
15
+ <li><a href="./CONFIGURATION.md">Configuration</a></li>
16
+ </ul>
17
+ </details>
13
18
 
14
19
  ## Technique
15
20
 
@@ -17,182 +22,4 @@ To leverage this module's progressive enhancement technique, you will need to fo
17
22
 
18
23
  1. Always define the markup structure using a `<template>` element. The definition can exist anywhere in any of your templates, but the definition must exist.
19
24
  2. The template element you create to define your web component must have an `id` matching the name of the web component. So `<my-component>` must have a corresponding `<template id="my-component">` somewhere in your templates.
20
- 3. Use `${templateLiteral}` values for values in your `<template>` markup. See how that works in the example below.
21
-
22
- ## Usage
23
-
24
- We will demo this technique end-to-end using a `<word-count>` component that counts the number of words a user types into a `<textarea>`.
25
-
26
- Suppose the intended use of the `<word-count>` component looks like this:
27
-
28
- ```html
29
- <word-count text="Once upon a time... " id="story">
30
- <p slot="description">Type your story in the box above!</p>
31
- </word-count>
32
- ```
33
-
34
- And suppose also that you have an Express application with templates loaded into `mvc/views`.
35
-
36
- So to leverage this module's progressive enhancement technique, you will need to define this component using a `<template>` element in any one of your templates as follows:
37
-
38
- ```html
39
- <template id="word-count">
40
- <style>
41
- div {
42
- position: relative;
43
- }
44
- textarea {
45
- margin-top: 35px;
46
- width: 100%;
47
- box-sizing: border-box;
48
- }
49
- span {
50
- display: block;
51
- position: absolute;
52
- top: 0;
53
- right: 0;
54
- margin-top: 10px;
55
- font-weight: bold;
56
- }
57
- </style>
58
- <div>
59
- <textarea rows="10" cols="50" name="${id}" id="${id}">${text}</textarea>
60
- <slot name="description"></slot>
61
- <span class="word-count"></span>
62
- </div>
63
- </template>
64
- ```
65
-
66
- *Note: Any `${templateLiterals}` present in the template markup will be replaced with attribute values from the custom element invocation. More on that below.*
67
-
68
- Then, in your Express application:
69
-
70
- ```javascript
71
- const fs = require('fs-extra')
72
-
73
- // load progressively-enhance-web-components.js
74
- const editedFiles = require('progressively-enhance-web-components')({
75
- templatesDir: './mvc/views'
76
- })
77
-
78
- // copy unmodified templates to a modified templates directory
79
- fs.copySync('mvc/views', 'mvc/.preprocessed_views')
80
-
81
- // update the relevant templates
82
- for (const file in editedFiles) {
83
- fs.writeFileSync(file.replace('mvc/views', 'mvc/.preprocessed_views'), editedFiles[file])
84
- }
85
-
86
- // configure express
87
- const express = require('express')
88
- const app = express()
89
- app.engine('html', require('teddy').__express) // set teddy as view engine that will load html files
90
- app.set('views', 'mvc/.preprocessed_views') // set template dir
91
- app.set('view engine', 'html') // set teddy as default view engine
92
-
93
- // start the server
94
- const port = 3000
95
- app.listen(port, () => {
96
- console.log(`🎧 express sample app server is running on http://localhost:${port}`)
97
- })
98
- ```
99
-
100
- *Note: The above example uses the [Teddy](https://github.com/rooseveltframework/teddy) templating system, but you can use any templating system you like, so long as your templates can survive being preprocessed by [jsdom](https://github.com/jsdom/jsdom), which is a core part of how this module does its progressive enhancement work.*
101
-
102
- In the above sample Express application, the `mvc/views` folder is copied to `mvc/.preprocessed_views`, then any template files in there will be updated to replace any uses of `<word-count>` with a more progressive enhancement-friendly version of `<word-count>` instead.
103
-
104
- So, for example, any web component in your templates that looks like this:
105
-
106
- ```html
107
- <word-count text="Once upon a time... " id="story">
108
- <p slot="description">Type your story in the box above!</p>
109
- </word-count>
110
- ```
111
-
112
- Will be replaced with this:
113
-
114
- ```html
115
- <word-count text="Once upon a time... " id="story">
116
- <div>
117
- <textarea rows="10" cols="50" name="story" id="story">Once upon a time... </textarea>
118
- <span class="word-count"></span>
119
- </div>
120
- <p slot="description">Type your story in the box above!</p>
121
- </word-count>
122
- ```
123
-
124
- The fallback markup is derived from the `<template>` element and is inserted into the "light DOM" of the web component, so it will display to users with JavaScript disabled.
125
-
126
- Because the `<template>` element has `${templateLiteral}` values for the `name` attribute, the `id` attribute, and the contents of the `<textarea>`, those values are prefilled properly on the fallback markup.
127
-
128
- Any tag in the `<template>` element that has a `slot` attribute will be moved to the top level of the fallback markup DOM because that is a requirement for the web component to work when JavaScript is enabled. That's why the `<p>` tag is not a child of the `<div>` in the replacement example like it is in the `<template>`. That is done intentionally by this module's preprocessing.
129
-
130
- Then, once the frontend JavaScript takes over, the web component can be progressively enhanced into the JS-driven version.
131
-
132
- Here's an example implementation for the frontend JS side:
133
-
134
- ```javascript
135
- class WordCount extends window.HTMLElement {
136
- connectedCallback () { // called whenever a new instance of this element is inserted into the dom
137
- this.shadow = this.attachShadow({ mode: 'open' }) // create and attach a shadow dom to the custom element
138
- this.shadow.appendChild(document.getElementById('word-count').content.cloneNode(true)) // create the elements in the shadow dom from the template element
139
-
140
- // set textarea attributes
141
- const textarea = this.shadow.querySelector('textarea')
142
- textarea.value = this.getAttribute('text') || ''
143
- textarea.id = this.getAttribute('id') || ''
144
- textarea.name = this.getAttribute('id') || ''
145
-
146
- // function for updating the word count
147
- const updateWordCount = () => {
148
- this.shadow.querySelector('span').textContent = `Words: ${textarea.value.trim().split(/\s+/g).filter(a => a.trim().length > 0).length}`
149
- }
150
-
151
- // update count when textarea content changes
152
- textarea.addEventListener('input', updateWordCount)
153
- updateWordCount() // update it on load as well
154
- }
155
- }
156
-
157
- window.customElements.define('word-count', WordCount) // define the new element
158
- ```
159
-
160
- Once that JS executes, the "light DOM" fallback markup will be hidden and the JS-enabled version of the web component will take over and behave as normal.
161
-
162
- ### Available options
163
-
164
- When you call:
165
-
166
- ```javascript
167
- const editedFiles = require('progressively-enhance-web-components')({
168
- templatesDir: './mvc/views'
169
- })
170
- ```
171
-
172
- There are other params you can pass to it besides `templatesDir`.
173
-
174
- The full list of params available is:
175
-
176
- - `templatesDir`: What folder to examine. This is required.
177
- - `disableBeautify`: If set to true, this module will not beautify the HTML in the outputted markup. Default: `false`.
178
- - `beautifyOptions`: Options to pass to [js-beautify](https://github.com/beautifier/js-beautify). Default: `{ indent_size: 2 }`.
179
-
180
- ### Sample app
181
-
182
- Here's how to run the sample app:
183
-
184
- - `cd sampleApps/express`
185
-
186
- - `npm ci`
187
-
188
- - `cd ../../`
189
-
190
- - `npm run express-sample`
191
-
192
- - Or `npm run sample`
193
-
194
- - Or `cd` into `sampleApps/express` and run `npm ci` and `npm start`
195
-
196
- - Go to [http://localhost:3000](http://localhost:3000)
197
-
198
- - The page with the web component is located at http://localhost:3000/pageWithForm
25
+ 3. Use `${templateLiteral}` values for values in your `<template>` markup. See "Usage" for more details.
package/USAGE.md ADDED
@@ -0,0 +1,271 @@
1
+ We will demo this technique end-to-end using a `<word-count>` component that counts the number of words a user types into a `<textarea>`.
2
+
3
+ Suppose the intended use of the `<word-count>` component looks like this:
4
+
5
+ ```html
6
+ <word-count text="Once upon a time... " id="story">
7
+ <p slot="description">Type your story in the box above!</p>
8
+ </word-count>
9
+ ```
10
+
11
+ And suppose also that you have an Express application with templates loaded into `mvc/views`.
12
+
13
+ To leverage this module's progressive enhancement technique, you will need to define this component using a `<template>` element in any one of your templates as follows:
14
+
15
+ ```html
16
+ <template id="word-count">
17
+ <style>
18
+ div {
19
+ position: relative;
20
+ }
21
+ textarea {
22
+ margin-top: 35px;
23
+ width: 100%;
24
+ box-sizing: border-box;
25
+ }
26
+ span {
27
+ display: block;
28
+ position: absolute;
29
+ top: 0;
30
+ right: 0;
31
+ margin-top: 10px;
32
+ font-weight: bold;
33
+ }
34
+ </style>
35
+ <div>
36
+ <textarea rows="10" cols="50" name="${id}" id="${id}">${text}</textarea>
37
+ <slot name="description"></slot>
38
+ <span class="word-count"></span>
39
+ </div>
40
+ </template>
41
+ ```
42
+
43
+ *Note: Any `${templateLiterals}` present in the template markup will be replaced with attribute values from the custom element invocation. More on that below.*
44
+
45
+ Then, in your Express application:
46
+
47
+ ```javascript
48
+ const fs = require('fs-extra')
49
+ const path = require('path')
50
+
51
+ const viewsDir = path.join('mvc', 'views')
52
+ const preprocessedViewsDir = path.join('mvc', '.preprocessed_views')
53
+
54
+ // load progressively-enhance-web-components.js
55
+ const editedFiles = require('progressively-enhance-web-components')({
56
+ templatesDir: viewsDir
57
+ })
58
+
59
+ // copy unmodified templates to a modified templates directory
60
+ fs.copySync(viewsDir, preprocessedViewsDir)
61
+
62
+ // update the relevant templates
63
+ for (const file in editedFiles) {
64
+ fs.writeFileSync(path.join(preprocessedViewsDir, path.relative(viewsDir, file)), editedFiles[file])
65
+ }
66
+
67
+ // configure express
68
+ const express = require('express')
69
+ const app = express()
70
+ app.engine('html', require('teddy').__express) // set teddy as view engine that will load html files
71
+ app.set('views', preprocessedViewsDir) // set template dir
72
+ app.set('view engine', 'html') // set teddy as default view engine
73
+
74
+ // start the server
75
+ const port = 3000
76
+ app.listen(port, () => {
77
+ console.log(`🎧 express sample app server is running on http://localhost:${port}`)
78
+ })
79
+ ```
80
+
81
+ *Note: The above example uses the [Teddy](https://rooseveltframework.org/docs/teddy) templating system, but you can use any templating system you like.*
82
+
83
+ In the above sample Express application, the `mvc/views` folder is copied to `mvc/.preprocessed_views`, then any template files in there will be updated to replace any uses of `<word-count>` with a more progressive enhancement-friendly version of `<word-count>` instead.
84
+
85
+ What that version looks like depends on the mode. There are three modes: `light`, `shadow`, and `both`. You can declare a mode with the `mode` attribute in your template element:
86
+
87
+ ```html
88
+ <template id="word-count" mode="shadow">
89
+ ```
90
+
91
+ Or set `mode` as a param instead to change the default for every component at once.
92
+
93
+ Whichever mode is used, the `${templateLiterals}` in the definition are replaced with the attribute values of the invocation, which is how the `name` attribute, the `id` attribute and the contents of the `<textarea>` come to be filled in below. The `<template>` element defining the component is also left in the page in every mode, so a component created in JavaScript still has something to render from.
94
+
95
+ ### Modes
96
+
97
+ #### `both`
98
+
99
+ The default. The component's markup is written into a [declarative shadow root](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/template#shadowrootmode), and a copy of it is kept beside that as fallback content. So a web component in your templates that looks like this:
100
+
101
+ ```html
102
+ <word-count text="Once upon a time... " id="story">
103
+ <p slot="description">Type your story in the box above!</p>
104
+ </word-count>
105
+ ```
106
+
107
+ Will be replaced with this:
108
+
109
+ ```html
110
+ <word-count text="Once upon a time... " id="story" data-enhanced>
111
+ <template shadowrootmode="open">
112
+ <style>
113
+ div {
114
+ position: relative;
115
+ }
116
+
117
+ textarea {
118
+ margin-top: 35px;
119
+ width: 100%;
120
+ box-sizing: border-box;
121
+ }
122
+
123
+ span {
124
+ display: block;
125
+ position: absolute;
126
+ top: 0;
127
+ right: 0;
128
+ margin-top: 10px;
129
+ font-weight: bold;
130
+ }
131
+ </style>
132
+ <div>
133
+ <textarea rows="10" cols="50" name="story" id="story">Once upon a time... </textarea>
134
+ <slot name="description"></slot>
135
+ <span class="word-count"></span>
136
+ </div>
137
+ </template>
138
+ <div slot="pewc-fallback">
139
+ <textarea rows="10" cols="50" name="story" id="story">Once upon a time... </textarea>
140
+ <span class="word-count"></span>
141
+ </div>
142
+
143
+ <p slot="description">Type your story in the box above!</p>
144
+ </word-count>
145
+ ```
146
+
147
+ This mode is the default because it is the most progressive enhancement-friendly: it is the only one that renders the component before any JavaScript loads whatever the browser supports, and where declarative shadow DOM is supported what it renders is the finished component, styled and with its slots filled, rather than a stand-in that appears unstyled and is then replaced. The tradeoff is it serves the most verbose amount of markup to the page, but that cost is trivial, especially when taking compression into consideration.
148
+
149
+ #### `shadow`
150
+
151
+ The declarative shadow root alone, with no fallback copy:
152
+
153
+ ```html
154
+ <word-count text="Once upon a time... " id="story" data-enhanced>
155
+ <template shadowrootmode="open">
156
+ <style>
157
+ div {
158
+ position: relative;
159
+ }
160
+
161
+ textarea {
162
+ margin-top: 35px;
163
+ width: 100%;
164
+ box-sizing: border-box;
165
+ }
166
+
167
+ span {
168
+ display: block;
169
+ position: absolute;
170
+ top: 0;
171
+ right: 0;
172
+ margin-top: 10px;
173
+ font-weight: bold;
174
+ }
175
+ </style>
176
+ <div>
177
+ <textarea rows="10" cols="50" name="story" id="story">Once upon a time... </textarea>
178
+ <slot name="description"></slot>
179
+ <span class="word-count"></span>
180
+ </div>
181
+ </template>
182
+
183
+ <p slot="description">Type your story in the box above!</p>
184
+ </word-count>
185
+ ```
186
+
187
+ Smaller, and worth choosing for a component whose content nobody would miss before the JavaScript loads, such as a tab bar or a toggle. The cost is that a browser which does not support declarative shadow DOM renders nothing at all, an unsupported `<template>` being inert. The same is true of anything that parses HTML without building shadow roots, such as a crawler that does not run a browser engine.
188
+
189
+ #### `light`
190
+
191
+ The fallback markup alone, written into the light DOM:
192
+
193
+ ```html
194
+ <word-count text="Once upon a time... " id="story" data-enhanced>
195
+ <div>
196
+ <textarea rows="10" cols="50" name="story" id="story">Once upon a time... </textarea>
197
+ <span class="word-count"></span>
198
+ </div>
199
+ <p slot="description">Type your story in the box above!</p>
200
+ </word-count>
201
+ ```
202
+
203
+ This displays to users with JavaScript disabled in every browser, but it is unstyled, the content given to a slot is not projected into it, and once the component upgrades the markup is shadowed and stays in the DOM unused.
204
+
205
+ ### How to ensure a custom element you want left untouched by this library is ignored
206
+
207
+ Apply a `data-enhanced` attribute:
208
+
209
+ ```html
210
+ <word-count text="Once upon a time... " id="story" data-enhanced>
211
+ <!-- whatever you wrote here is what stays here -->
212
+ </word-count>
213
+ ```
214
+
215
+ Alternatively, if a `<template shadowrootmode>` exists in your custom element invocation, that will also cause this library to ignore it.
216
+
217
+ This library will also apply the `data-enhanced` attribute to any custom element it enhances to prevent re-enhancing on a second pass.
218
+
219
+ ### Writing the frontend JavaScript
220
+
221
+ Then, once the frontend JavaScript takes over, the web component can be progressively enhanced into the JS-driven version.
222
+
223
+ Here's an example implementation for the frontend JS side:
224
+
225
+ ```javascript
226
+ class WordCount extends window.HTMLElement {
227
+ connectedCallback () { // called whenever a new instance of this element is inserted into the dom
228
+ // this.shadowRoot will exist already, except in light mode or for an element created in javascript
229
+ this.shadow = this.shadowRoot || this.attachShadow({ mode: 'open' })
230
+
231
+ // add the markup of the component if it is not already populated
232
+ if (!this.shadow.childElementCount) {
233
+ const markup = document.createElement('div')
234
+ markup.appendChild(document.getElementById('word-count').content.cloneNode(true))
235
+
236
+ // fill in its ${templateLiterals} from this element's attributes
237
+ for (const attrib of this.attributes) markup.innerHTML = markup.innerHTML.replace(new RegExp(`\\$\\{${attrib.name}\\}`, 'gi'), attrib.value)
238
+
239
+ this.shadow.append(...markup.childNodes)
240
+ }
241
+
242
+ const textarea = this.shadow.querySelector('textarea')
243
+
244
+ // function for updating the word count
245
+ const updateWordCount = () => {
246
+ this.shadow.querySelector('span').textContent = `Words: ${textarea.value.trim().split(/\s+/g).filter(a => a.trim().length > 0).length}`
247
+ }
248
+
249
+ // update count when textarea content changes
250
+ textarea.addEventListener('input', updateWordCount)
251
+ updateWordCount() // update it on load as well
252
+ }
253
+ }
254
+
255
+ window.customElements.define('word-count', WordCount) // define the new element
256
+ ```
257
+
258
+ ### Sample app
259
+
260
+ The sample app takes the default mode, so you can see each half of it working. See an end-to-end demo by running it:
261
+
262
+ - `cd sampleApps/express`
263
+ - `npm ci`
264
+ - `cd ../../`
265
+ - `npm run express-sample`
266
+ - Or `npm run sample`
267
+ - Or `cd` into `sampleApps/express` and run `npm ci` and `npm start`
268
+ - Go to [http://localhost:3000](http://localhost:3000)
269
+ - The page with the web component is located at [http://localhost:3000/pageWithForm](http://localhost:3000/pageWithForm)
270
+
271
+ Look at `mvc/.preprocessed_views/pageWithForm.html` to see what the invocation was turned into. Then turn JavaScript off and load the page again: the component still renders, still has its styles, and still shows the content given to its slot, because the browser's parser built the shadow root without being asked to run anything. Only the word counter is missing, that being the part JavaScript is there for.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "progressively-enhance-web-components",
3
- "description": "🕸️ Template file preprocessor for progressively enhancing web components.",
3
+ "description": "\ud83d\udd78\ufe0f Template file preprocessor for progressively enhancing web components.",
4
4
  "author": "Roosevelt Framework Team <rooseveltframework@gmail.com>",
5
5
  "contributors": [
6
6
  {
@@ -8,36 +8,42 @@
8
8
  "url": "https://github.com/rooseveltframework/progressively-enhance-web-components/graphs/contributors"
9
9
  }
10
10
  ],
11
- "version": "1.0.3",
12
- "homepage": "https://github.com/rooseveltframework/progressively-enhance-web-components",
11
+ "version": "2.0.1",
12
+ "homepage": "https://rooseveltframework.org/docs/progressively-enhance-web-components/latest",
13
13
  "license": "CC-BY-4.0",
14
14
  "main": "progressively-enhance-web-components.js",
15
+ "files": [
16
+ "progressively-enhance-web-components.js",
17
+ "CHANGELOG.md",
18
+ "CONFIGURATION.md",
19
+ "USAGE.md"
20
+ ],
15
21
  "engines": {
16
- "node": ">=18.0.0"
22
+ "node": ">=22.0.0"
17
23
  },
18
24
  "dependencies": {
19
- "js-beautify": "1.15.4",
20
- "jsdom": "26.0.0"
25
+ "js-beautify": "2.0.3",
26
+ "jsdom": "30.1.0"
21
27
  },
22
28
  "devDependencies": {
23
- "c8": "10.1.3",
24
- "mocha": "11.1.0",
29
+ "@playwright/test": "^1.63.0",
25
30
  "standard": "17.1.2"
26
31
  },
27
- "mocha": {
28
- "timeout": "700000ms"
29
- },
30
32
  "standard": {
31
33
  "ignore": [
32
34
  "dist/",
33
- "sampleApps/express/public"
35
+ "playwright-report/",
36
+ "sampleApps/express/public",
37
+ "test-results/"
34
38
  ]
35
39
  },
36
40
  "scripts": {
37
41
  "lint": "standard",
38
42
  "lint-fix": "standard --fix",
39
- "test": "mocha test/*.js",
40
- "coverage": "c8 --reporter=text --reporter=lcov mocha test/*.js --test",
43
+ "test": "npm run test-node && npm run test-browser",
44
+ "test-node": "node --test test/test.js",
45
+ "test-browser": "playwright test",
46
+ "coverage": "node --test --experimental-test-coverage test/test.js",
41
47
  "express-sample": "node -e \"process.chdir('sampleApps/express'); require('./sampleApps/express/server.js')\"",
42
48
  "sample": "npm run express-sample"
43
49
  },