vite-plugin-xhtml2shadow 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -10
- package/dist/index.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -49,13 +49,16 @@ class LoginForm extends HTMLElement {
|
|
|
49
49
|
|
|
50
50
|
constructor() {
|
|
51
51
|
super()
|
|
52
|
-
build(this)
|
|
52
|
+
if (build(this)) return
|
|
53
|
+
// other set up here
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
connectedCallback() {
|
|
53
57
|
const submit = this.shadowRoot!.querySelector("button")!
|
|
54
58
|
submit.onclick = () => {
|
|
55
59
|
// perform login here
|
|
56
60
|
}
|
|
57
61
|
}
|
|
58
|
-
|
|
59
62
|
}
|
|
60
63
|
customElements.define("login-form", LoginForm)
|
|
61
64
|
```
|
|
@@ -100,20 +103,23 @@ you'll need to escape their unicode values instead. In practice this
|
|
|
100
103
|
issue only comes up with non-breaking spaces. Instead of using ` `
|
|
101
104
|
like you would in HTML, use ` ` instead.
|
|
102
105
|
|
|
103
|
-
Note that although you
|
|
104
|
-
|
|
106
|
+
Note that although you _author_ your markup as XHTML, the plugin
|
|
107
|
+
_produces_ JavaScript that creates HTML5 elements. The usage of xhtml
|
|
108
|
+
is simply for self-closing tags.
|
|
105
109
|
|
|
106
110
|
## Server-Side Rendering
|
|
107
111
|
|
|
108
112
|
If the passed-in element already has a shadow root, the functions
|
|
109
|
-
produced by this plugin do nothing, just
|
|
110
|
-
done to support web components that were rendered by a server via
|
|
113
|
+
produced by this plugin do nothing, just return `true`. This is
|
|
114
|
+
done to support web components that were rendered by a server via
|
|
115
|
+
Declarative Shadow DOM. In your component's constructor, you can
|
|
116
|
+
check the result of the `build` function to exit early if the
|
|
117
|
+
element already has a shadow root.
|
|
111
118
|
|
|
112
119
|
## Viteness
|
|
113
120
|
|
|
114
121
|
This plugin is vite-specific because it relies on vite's ability to
|
|
115
122
|
import static assets as URLs. This is done for `href` and `src`
|
|
116
|
-
attributes that reference a relative URL
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
hashed URL when building with vite.
|
|
123
|
+
attributes that reference a relative URL. Doing so allows you to specify
|
|
124
|
+
an asset in your `/src` directory via its path, but the plugin will
|
|
125
|
+
output the correct hashed URL when building with vite.
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ function compile(src) {
|
|
|
22
22
|
let code = `import {getCSS} from "dubc-client-global-css";`;
|
|
23
23
|
code += parser.style.s;
|
|
24
24
|
code += parser.code.s;
|
|
25
|
-
code += "}";
|
|
25
|
+
code += "return false;}";
|
|
26
26
|
return code;
|
|
27
27
|
}
|
|
28
28
|
class Parser {
|
|
@@ -40,8 +40,8 @@ class Parser {
|
|
|
40
40
|
throw new Error(n.textContent);
|
|
41
41
|
}
|
|
42
42
|
this.code.write(`export default function xhtml(el){`);
|
|
43
|
-
this.code.write(`if(el.shadowRoot!==null)return;`);
|
|
44
|
-
this.code.write(`const sh=el.attachShadow({mode:"open",delegatesFocus:true});`);
|
|
43
|
+
this.code.write(`if(el.shadowRoot!==null)return true;`);
|
|
44
|
+
this.code.write(`const sh=el.attachShadow({mode:"open",delegatesFocus:true,clonable:true,serializable:true});`);
|
|
45
45
|
this.code.write(`sh.adoptedStyleSheets.push(getCSS());`);
|
|
46
46
|
this.parsed = parsed;
|
|
47
47
|
}
|
|
@@ -90,7 +90,7 @@ class Parser {
|
|
|
90
90
|
for (const x of el.attributes) {
|
|
91
91
|
let { name, value } = x;
|
|
92
92
|
if (name === "src" || name === "href") {
|
|
93
|
-
if (value.startsWith(".")
|
|
93
|
+
if (value.startsWith(".")) {
|
|
94
94
|
const imp = this.style.next();
|
|
95
95
|
this.style.write(`import ${imp} from ${esc(value)};`);
|
|
96
96
|
value = imp;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-xhtml2shadow",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.2",
|
|
5
5
|
"description": "Converts .xhtml files into JavaScript code that produces a shadow root with that HTML.",
|
|
6
6
|
"keywords": ["vite-plugin"],
|
|
7
7
|
"main": "dist/index.js",
|