2021-02-17 10:02:58 +00:00
|
|
|
const setup = (root) => {
|
2020-10-27 15:29:29 +00:00
|
|
|
root.parts = {}
|
|
|
|
root.querySelectorAll("[part-id]").forEach( element => {
|
|
|
|
root.parts[element.getAttribute("part-id")] = element
|
|
|
|
})
|
|
|
|
root.clone = function() { return setup(this.cloneNode(true)) }
|
|
|
|
return root
|
|
|
|
}
|
|
|
|
|
2021-02-17 10:02:58 +00:00
|
|
|
export const template = (strings, ...args) => {
|
2020-10-27 15:29:29 +00:00
|
|
|
let buf = []
|
|
|
|
for (i=0;i<strings.length;i++) {
|
|
|
|
buf.push(strings[i], args[i])
|
|
|
|
}
|
|
|
|
let template = document.createElement("template")
|
|
|
|
template.innerHTML = buf.join("")
|
|
|
|
return setup(template.content)
|
|
|
|
}
|