diff --git a/app.js b/app.js index 0b9feba..c55e432 100644 --- a/app.js +++ b/app.js @@ -15,7 +15,7 @@ const {DOM} = Gale( } ); -const state = vanX.reactive({key1:"value1", key2:"value2", count:4}, "THING"); +const state = vanX.reactive({key1:"value1", key2:"value2", count:4}, "counter"); console.log(state); van.add diff --git a/deno.json b/deno.json index 4e30dcd..a7302d9 100644 --- a/deno.json +++ b/deno.json @@ -7,7 +7,7 @@ "dom.asynciterable", "deno.ns" ], - "types": ["./van.d.ts"] + "types": ["./types.d.ts"] }, "imports": { "entry": "./app.js" diff --git a/gale.js b/gale.js deleted file mode 100644 index 6b5471a..0000000 --- a/gale.js +++ /dev/null @@ -1,89 +0,0 @@ -/** @type {Gale.CreateSheet} */ -export default (sheet, hash="")=> -{ - const KeyQuery = "@"; - const KeyState = ":"; - const KeyChild = "."; - const KeyGroup = "^"; - - /** @type {Gale.Tier} */ - const Tier=(selector, obj, suffix)=> - { - const styles = Object.keys(obj).map((key)=> - { - const value = obj[key]; - switch(key[0]) - { - case KeyQuery : - return Tier(`@media(max-width:${key.substring(KeyQuery.length)})`, value, suffix); - case KeyState : - return Tier(`&${key}`, value, suffix); - case KeyChild : - return Tier(`${key}${suffix}`, value, suffix); - case KeyGroup : - return Tier(`&:hover .${key.substring(KeyGroup.length)}${suffix}`, value, suffix); - } - return `${ key.replace(/([a-z])([A-Z])/g, '$1-$2') }: ${value};` - }); - - return `${selector}{${styles.join("\n")}}`; - } - - /** @type {(needle:string, str:string)=>string} */ - const extractLast =(needle, str)=>{ - const ind = str.lastIndexOf(needle)+needle.length; - return ind ? str.substring(ind) : str; - } - - const collect =(tagName)=> - { - const pending = van.tags[tagName]; - let mentioned = []; - const collector = new Proxy( - (...args)=> - { - const element = pending(...args); - element.className = mentioned.join(id+" ")+id + " " + element.className; - mentioned = []; - return element; - }, - { - get(_, prop) - { - mentioned.push(prop.substring(prop.lastIndexOf(".")+1)); - return collector; - } - } - ); - return collector; - } - - const id = hash ? "_"+hash : ""; - const css = Object.keys(sheet).map(key=>Tier("."+key+id, sheet[key], id)).join(`\n`); - globalThis.document?.head.insertAdjacentHTML("beforeend", ``); - - return { - Tag(...args){ - return args.map((arg)=>extractLast(KeyGroup, extractLast(KeyChild, arg))).join(id+" ")+id; - }, - CSS: css, - DOM: new Proxy( - {}, - { - get(_, prop) - { - return collect(prop) - } - } - ), - Div: new Proxy( - {}, - { - get(_, prop) - { - return collect("div")[prop] - } - } - ) - } -} \ No newline at end of file diff --git a/hmr.js b/hmr.js deleted file mode 100644 index 4275d01..0000000 --- a/hmr.js +++ /dev/null @@ -1,90 +0,0 @@ -const HMR = globalThis.HMR = { - Time: 0, - /** @type {Record} */ - Temp:{}, - Tick() - { - for(const k in HMR.Temp) - { - sessionStorage.setItem(k, HMR.Temp[k]); - } - HMR.Temp = {}; - HMR.Time = 0; - }, - /** @type {(key:string, value:string)=>void} */ - Save(key, value) - { - this.Temp[key] = value; - if(!this.Time) - { - this.Time = setTimeout(this.Tick, 500); - } - console.log("SAVE", key, value); - }, - /** @type {(key:string)=>string|null} */ - Load(key) - { - const value = sessionStorage.getItem(key); - console.log("LOAD", key, value); - return value; - }, - - /** @type {string|undefined} */ - _ID: undefined, - _index: 0, - /** @type {(id:string|undefined = undefined)=>void} */ - StartID(id) - { - this._index = 0; - this._ID = id; - }, - NextID() - { - return this._ID ? this._ID + "_" + (this._index++) + "_" : ""; - }, - - BindVan() - { - //bind Van - const origninalState = globalThis.van.state; - globalThis.van.state =(value, key="")=> - { - const type = typeof value; - let reader =d=>d; - let writer =d=>d?.toString() || null; - - switch(type) - { - case "boolean" : - reader =(data)=> data === "true"; break; - case "number" : - reader = parseFloat; break; - case "object" : - reader = JSON.parse; - writer = JSON.stringify; - break; - } - - const fullKey = "HMR_" + HMR.NextID() + key; - const stringValue = HMR.Load(fullKey); - const signal = origninalState((stringValue ? reader(stringValue) : value)); - van.derive(()=>HMR.Save(fullKey, writer(signal.val))); - - return signal; - }; - }, - - BindVanX() - { - //bind VanX - const originalReactive = globalThis.vanX.reactive; - globalThis.vanX.reactive =(obj, id)=> - { - HMR.StartID(id); - const state = originalReactive(obj); - HMR.StartID(); - return state; - } - } - -} diff --git a/index.html b/index.html index 7bffa4d..7ba467e 100644 --- a/index.html +++ b/index.html @@ -4,28 +4,203 @@ Document - + + diff --git a/van.d.ts b/types.d.ts similarity index 100% rename from van.d.ts rename to types.d.ts