init
This commit is contained in:
11
dom.js
Normal file
11
dom.js
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
export function addStyle(cssString) {
|
||||||
|
let stylesheet = new CSSStyleSheet();
|
||||||
|
stylesheet.replaceSync(cssString)
|
||||||
|
document.adoptedStyleSheets = [...document.adoptedStyleSheets, stylesheet];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function create(elementString) {
|
||||||
|
let parser = new DOMParser();
|
||||||
|
let doc = parser.parseFromString(elementString, 'text/html');
|
||||||
|
return doc.body.firstChild;
|
||||||
|
}
|
||||||
11
index.html
Normal file
11
index.html
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<title>Index</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<script type="module" src="index.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
30
index.js
Normal file
30
index.js
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import * as dom from './dom.js';
|
||||||
|
window.dom = {};
|
||||||
|
Object.entries(dom).forEach(([name, exported]) => window.dom[name] = exported);
|
||||||
|
|
||||||
|
class Index extends HTMLElement {
|
||||||
|
|
||||||
|
css = /*css*/ `
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
html = /*html*/ `
|
||||||
|
|
||||||
|
`
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
|
||||||
|
dom.addStyle(this.css);
|
||||||
|
this.innerHTML = this.html;
|
||||||
|
}
|
||||||
|
|
||||||
|
connectedCallback() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
customElements.define('index-el', Index);
|
||||||
|
export default Index;
|
||||||
|
|
||||||
Reference in New Issue
Block a user