From 539a79c288574a833fdd40709e5926b2dd9f4c58 Mon Sep 17 00:00:00 2001 From: yutent Date: Sun, 5 Mar 2023 22:39:21 +0800 Subject: [PATCH] update --- src/core.js | 81 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 68 insertions(+), 13 deletions(-) diff --git a/src/core.js b/src/core.js index 7cd7cb7..860e52a 100644 --- a/src/core.js +++ b/src/core.js @@ -4,17 +4,72 @@ * @date 2023/03/03 11:21:44 */ -export function css(str) {} - -const foo = css` - .foo { - color: red; - color: green; - background: green; - - .bar { - display: flex; - } +export function css(strs, ...args) { + let output = '' + let tmp = Array.from(strs) + while (tmp.length) { + output += tmp.shift() + (args.shift() || '') } -` -const bar = html`

` + + if (args.length) { + output += args.join(' ') + } + return output +} + +export function html(strs, ...args) { + let output = '' + let tmp = Array.from(strs) + // console.log(tmp, args) + + while (tmp.length) { + let _ = args.shift() + switch (typeof _) { + case 'function': + console.log([_], _.name) + _ = _.name + break + case 'object': + if (Array.isArray(_)) { + _ = _.join('') + } + break + } + output += tmp.shift() + (_ === void 0 ? '' : _) + } + + if (args.length) { + output += args.join(' ') + } + return output +} + +function getTemplate(html) { + let template = document.createElement('template') + template.innerHTML = html + return template.content.cloneNode(true) +} + +export class Compoent extends HTMLElement { + static get observedAttributes() { + console.log(this.properties) + return [] + } + + constructor() { + super() + } + + render() { + return '' + } + + connectedCallback() { + Object.defineProperty(this, 'root', { + value: this.attachShadow({ mode: 'open' }), + enumerable: false + }) + + this.root.appendChild(getTemplate(this.render())) + } +}