Compare commits

..

No commits in common. "merger" and "master" have entirely different histories.

19 changed files with 224 additions and 304 deletions

14
app.js
View File

@ -1,4 +1,4 @@
const {DOM, Tag, Div} = Gale({
const {DOM, Tag, H} = Gale({
Button: {
padding: "20px",
background: "orange",
@ -30,15 +30,15 @@ const {DOM, Tag, Div} = Gale({
Orange:{
background:"orange"
}
});
}, "abilities");
const UI =()=>
{
return Div.Window(
Div.Ability({class:Tag("Ability", "Orange")}),
Div.Ability(),
Div.Ability(),
Div.Ability.Orange(),
return H.Window(
H.Ability({class:Tag("Ability", "Orange")}),
H.Ability(),
H.Ability(),
H.Ability.Orange(),
)
}

View File

@ -3,17 +3,16 @@
{
"checkJs": true,
"lib": ["deno.window", "DOM"],
"types": ["GALE@HOST/types.d.ts"]
"types": ["./dist/core.d.ts"]
},
"tasks":
{
"work": "deno run -Ar GALE@HOST/scripts/dev_server.ts",
"scan": "deno run -Ar GALE@HOST/scripts/refresh_types.ts",
"html": "deno run -Ar GALE@HOST/scripts/scaffold.ts --html"
"work": "deno run -Ar ./scripts/dev_server.ts",
"scan": "deno run -Ar ./scripts/refresh_types.ts",
"html": "deno run -Ar ./scripts/scaffold.ts --html"
},
"imports":
{
"GALE@HOST/":"./",
"GALE@ENTRY":"./app.js"
"entry":"./app.js"
}
}

View File

@ -1,27 +1,13 @@
{
"version": "5",
"version": "4",
"specifiers": {
"jsr:@std/media-types@*": "1.1.0",
"npm:vanjs-core@*": "1.5.5",
"npm:vanjs-core@^1.5.5": "1.5.5",
"npm:vanjs-ext@~0.6.3": "0.6.3"
"jsr:@std/media-types@*": "1.1.0"
},
"jsr": {
"@std/media-types@1.1.0": {
"integrity": "c9d093f0c05c3512932b330e3cc1fe1d627b301db33a4c2c2185c02471d6eaa4"
}
},
"npm": {
"vanjs-core@1.5.5": {
"integrity": "sha512-BC9MjbXYIRqnwncXfacT6upJpVmIKyrV2MjZi8NuCK+yc9RP0hfdghTpmEuYswXOfkLarDPPcYK4X6q68T9e+g=="
},
"vanjs-ext@0.6.3": {
"integrity": "sha512-Jmaeqx9nCjelwDVSQEaRtt7R4Y/Kj/zJBG3bZSiIPj8Wtr8nEFRsJX9K5qcGl1o3cGEEFBE9suyoSqs/6tiOBg==",
"dependencies": [
"vanjs-core"
]
}
},
"redirects": {
"https://deno.land/std/path/mod.ts": "https://deno.land/std@0.224.0/path/mod.ts"
},
@ -104,8 +90,6 @@
"https://deno.land/std@0.224.0/path/windows/relative.ts": "3e1abc7977ee6cc0db2730d1f9cb38be87b0ce4806759d271a70e4997fc638d7",
"https://deno.land/std@0.224.0/path/windows/resolve.ts": "8dae1dadfed9d46ff46cc337c9525c0c7d959fb400a6308f34595c45bdca1972",
"https://deno.land/std@0.224.0/path/windows/to_file_url.ts": "40e560ee4854fe5a3d4d12976cef2f4e8914125c81b11f1108e127934ced502e",
"https://deno.land/std@0.224.0/path/windows/to_namespaced_path.ts": "4ffa4fb6fae321448d5fe810b3ca741d84df4d7897e61ee29be961a6aac89a4c",
"https://vanjs.org/code/van-1.5.5.nomodule.min.js": "32403d4dd6203a46513f000fd64b18e4eaef0823bf757ca0092e70130d059aa3",
"https://vanjs.org/code/van-x-0.6.3.nomodule.min.js": "e4b7de89bf2f84c22669ce7bcef592fb398d9dcf8b8a36f4562b8ac6354b1f2f"
"https://deno.land/std@0.224.0/path/windows/to_namespaced_path.ts": "4ffa4fb6fae321448d5fe810b3ca741d84df4d7897e61ee29be961a6aac89a4c"
}
}

File diff suppressed because one or more lines are too long

103
dist/core.d.ts vendored Normal file
View File

@ -0,0 +1,103 @@
export {}
declare global
{
namespace Van {
interface State<T> {
val: T
readonly oldVal: T
readonly rawVal: T
}
// Defining readonly view of State<T> for covariance.
// Basically we want StateView<string> to implement StateView<string | number>
type StateView<T> = Readonly<State<T>>
type Val<T> = State<T> | T
type Primitive = string | number | boolean | bigint
// deno-lint-ignore no-explicit-any
type PropValue = Primitive | ((e: any) => void) | null
type PropValueOrDerived = PropValue | StateView<PropValue> | (() => PropValue)
type Props = Record<string, PropValueOrDerived> & { class?: PropValueOrDerived; is?: string }
type PropsWithKnownKeys<ElementType> = Partial<{[K in keyof ElementType]: PropValueOrDerived}>
type ValidChildDomValue = Primitive | Node | null | undefined
type BindingFunc = ((dom?: Node) => ValidChildDomValue) | ((dom?: Element) => Element)
type ChildDom = ValidChildDomValue | StateView<Primitive | null | undefined> | BindingFunc | readonly ChildDom[]
type TagFunc<Result> = (first?: Props & PropsWithKnownKeys<Result> | ChildDom, ...rest: readonly ChildDom[]) => Result
type Tags = Readonly<Record<string, TagFunc<Element>>> & {
[K in keyof HTMLElementTagNameMap]: TagFunc<HTMLElementTagNameMap[K]>
}
}
const van:{
readonly state: <T>(initVal: T, HMRKey?:string)=> Van.State<T>
readonly derive: <T>(f: () => T) => Van.State<T>
readonly add: (dom: Element, ...children: readonly Van.ChildDom[]) => Element
readonly tags: Van.Tags & ((namespaceURI: string) => Readonly<Record<string, Van.TagFunc<Element>>>)
readonly hydrate: <T extends Node>(dom: T, f: (dom: T) => T | null | undefined) => T
};
namespace VanX
{
type StateOf<T> = { readonly [K in keyof T]: Van.State<T[K]> }
type ValueType<T> = T extends (infer V)[] ? V : T[keyof T]
type KeyType<T> = T extends unknown[] ? number : string
type ReplacementFunc<T> =
T extends (infer V)[] ? (items: V[]) => readonly V[] :
(items: [string, T[keyof T]][]) => readonly [string, T[keyof T]][]
}
const vanX:{
readonly calc: <R>(f: () => R) => R
readonly reactive: <T extends object>(obj: T, HMRKey?:string) => T
readonly noreactive: <T extends object>(obj: T) => T
readonly stateFields: <T extends object>(obj: T) => VanX.StateOf<T>
readonly raw: <T extends object>(obj: T) => T
readonly list: <T extends object, ElementType extends Element>(
container: (() => ElementType) | ElementType,
items: T,itemFunc: (v: Van.State<VanX.ValueType<T>>, deleter: () => void, k: VanX.KeyType<T>) => Node
) => ElementType
readonly replace: <T extends object>(obj: T, replacement: VanX.ReplacementFunc<T> | T) => T
readonly compact: <T extends object>(obj: T) => T
// my addition
readonly Store: <T extends object>(obj:T, key:string)=>T
};
namespace Gale {
type KeyQuery = "@";
type KeyState = ":";
type KeyChild = ".";
type KeyGroup = "^";
type UserStyles = Partial<CSSStyleDeclaration> & {[key: `${KeyQuery|KeyState|KeyChild|KeyGroup}${string}`]: UserStyles }
type UserSheet = Record<string, UserStyles>
type CollectKeys<Obj> = {[Key in keyof Obj]: Obj[Key] extends object ? Key | CollectKeys<Obj[Key]> : Key }[keyof Obj]
type FilterKeys<Keys> = Keys extends `${KeyChild|KeyGroup}${infer Rest}` ? Keys : never
type CrossMultiply<A, B> = A extends string ? B extends string ? `${A}${B}` : never : never
type CrossMultiplyRecord<Rec> = keyof Rec | { [K in keyof Rec]: K extends string ? CrossMultiply<K, FilterKeys<CollectKeys<Rec[K]>>> : never }[keyof Rec]
type Tier = (selector:string, obj:UserStyles, suffix:string)=>string;
type CreateSheet = <T extends UserSheet>(sheet:UserSheet&T, hash?:string)=>{
Tag:(...args:CrossMultiplyRecord<T>[])=>string,
CSS:string,
DOM:Elemental<CrossMultiplyRecord<T>>,
H:Circular<CrossMultiplyRecord<T>, Van.TagFunc<HTMLDivElement>>
}
type Elemental<T extends string> = {[K in keyof HTMLElementTagNameMap]: Van.TagFunc<HTMLElementTagNameMap[K]>&Circular<T, Van.TagFunc<HTMLElementTagNameMap[K]>>}
type Circular<Keys extends string, Func> = {
[K in Keys]: Circular<Keys, Func>&Func
};
}
const Gale:Gale.CreateSheet
}

14
dist/core.js vendored Normal file
View File

@ -0,0 +1,14 @@
//van
{let e,t,r,o,n,l,s,i,f,h,w,a,d,u,_,c,S,g,y,b,m,v,j,x,O;s=Object.getPrototypeOf,f={},h=s(i={isConnected:1}),w=s(s),a=(e,t,r,o)=>(e??(setTimeout(r,o),new Set)).add(t),d=(e,t,o)=>{let n=r;r=t;try{return e(o)}catch(e){return console.error(e),o}finally{r=n}},u=e=>e.filter(e=>e.t?.isConnected),_=e=>n=a(n,e,()=>{for(let e of n)e.o=u(e.o),e.l=u(e.l);n=l},1e3),c={get val(){return r?.i?.add(this),this.rawVal},get oldVal(){return r?.i?.add(this),this.h},set val(o){r?.u?.add(this),o!==this.rawVal&&(this.rawVal=o,this.o.length+this.l.length?(t?.add(this),e=a(e,this,x)):this.h=o)}},S=e=>({__proto__:c,rawVal:e,h:e,o:[],l:[]}),g=(e,t)=>{let r={i:new Set,u:new Set},n={f:e},l=o;o=[];let s=d(e,r,t);s=(s??document).nodeType?s:new Text(s);for(let e of r.i)r.u.has(e)||(_(e),e.o.push(n));for(let e of o)e.t=s;return o=l,n.t=s},y=(e,t=S(),r)=>{let n={i:new Set,u:new Set},l={f:e,s:t};l.t=r??o?.push(l)??i,t.val=d(e,n,t.rawVal);for(let e of n.i)n.u.has(e)||(_(e),e.l.push(l));return t},b=(e,...t)=>{for(let r of t.flat(1/0)){let t=s(r??0),o=t===c?g(()=>r.val):t===w?g(r):r;o!=l&&e.append(o)}return e},m=(e,t,...r)=>{let[{is:o,...n},...i]=s(r[0]??0)===h?r:[{},...r],a=e?document.createElementNS(e,t,{is:o}):document.createElement(t,{is:o});for(let[e,r]of Object.entries(n)){let o=t=>t?Object.getOwnPropertyDescriptor(t,e)??o(s(t)):l,n=t+","+e,i=f[n]??=o(s(a))?.set??0,h=e.startsWith("on")?(t,r)=>{let o=e.slice(2);a.removeEventListener(o,r),a.addEventListener(o,t)}:i?i.bind(a):a.setAttribute.bind(a,e),d=s(r??0);e.startsWith("on")||d===w&&(r=y(r),d=c),d===c?g(()=>(h(r.val,r.h),a)):h(r)}return b(a,i)},v=e=>({get:(t,r)=>m.bind(l,e,r)}),j=(e,t)=>t?t!==e&&e.replaceWith(t):e.remove(),x=()=>{let r=0,o=[...e].filter(e=>e.rawVal!==e.h);do{t=new Set;for(let e of new Set(o.flatMap(e=>e.l=u(e.l))))y(e.f,e.s,e.t),e.t=l}while(++r<100&&(o=[...t]).length);let n=[...e].filter(e=>e.rawVal!==e.h);e=l;for(let e of new Set(n.flatMap(e=>e.o=u(e.o))))j(e.t,g(e.f,e.t)),e.t=l;for(let e of n)e.h=e.rawVal},O={tags:new Proxy(e=>new Proxy(m,v(e)),v()),hydrate:(e,t)=>j(e,g(t,e)),add:b,state:S,derive:y},window.van=O;}
//vanx
{let e,t,r,{fromEntries:o,entries:l,keys:n,hasOwn:f,getPrototypeOf:a}=Object,{get:i,set:y,deleteProperty:c,ownKeys:s}=Reflect,{state:m,derive:d,add:u}=van,b=1e3,w=Symbol(),A=Symbol(),S=Symbol(),_=Symbol(),g=Symbol(),p=Symbol(),P=e=>(e[A]=1,e),v=e=>e instanceof Object&&!(e instanceof Function)&&!e[p],h=e=>{if(e?.[A]){let t=m();return d(()=>{let r=e();v(t.rawVal)&&v(r)?B(t.rawVal,r):t.val=x(r)}),t}return m(x(e))},F=e=>{let t=Array.isArray(e)?[]:{__proto__:a(e)};for(let[r,o]of l(e))t[r]=h(o);return t[S]=[],t[_]=m(1),t},O={get:(e,t,r)=>t===w?e:f(e,t)?Array.isArray(e)&&"length"===t?(e[_].val,e.length):e[t].val:i(e,t,r),set:(e,o,l,n)=>f(e,o)?Array.isArray(e)&&"length"===o?(l!==e.length&&++e[_].val,e.length=l,1):(e[o].val=x(l),1):o in e?y(e,o,l,n):y(e,o,h(l))&&(++e[_].val,C(e).forEach(E.bind(t,n,o,e[o],r)),1),deleteProperty:(e,t)=>(c(e,t)&&R(e,t),++e[_].val),ownKeys:e=>(e[_].val,s(e))},x=e=>!v(e)||e[w]?e:new Proxy(F(e),O),D=e=>(e[p]=1,e),j=e=>e[w],K=a(m()),N=e=>new Proxy(e,{get:(e,t,r)=>a(e[t]??0)===K?{val:k(e[t].rawVal)}:i(e,t,r)}),k=e=>e?.[w]?new Proxy(N(e[w]),O):e,C=e=>e[S]=e[S].filter(e=>e.t.isConnected),E=(e,t,r,o,{t:l,f:f})=>{let a=Array.isArray(e),i=a?Number(t):t;u(l,()=>l[g][t]=f(r,()=>delete e[t],i)),a&&!o&&i!==e.length-1&&l.insertBefore(l.lastChild,l[g][n(e).find(e=>Number(e)>i)])},R=(e,t)=>{for(let r of C(e)){let e=r.t[g];e[t]?.remove(),delete e[t]}},T=r=>(e??(setTimeout(()=>(e.forEach(C),e=t),b),e=new Set)).add(r),q=(e,t,r)=>{let o={t:e instanceof Function?e():e,f:r},n=t[w];o.t[g]={},n[S].push(o),T(n);for(let[e,r]of l(n))E(t,e,r,1,o);return o.t},z=(e,t)=>{for(let[r,o]of l(t)){let t=e[r];v(t)&&v(o)?z(t,o):e[r]=o}for(let r in e)f(t,r)||delete e[r];let r=n(t),o=Array.isArray(e);if(o||n(e).some((e,t)=>e!==r[t])){let l=e[w];if(o)e.length=t.length;else{++l[_].val;let e={...l};for(let e of r)delete l[e];for(let t of r)l[t]=e[t]}for(let{t:e}of C(l)){let{firstChild:t,[g]:o}=e;for(let l of r)t===o[l]?t=t.nextSibling:e.insertBefore(o[l],t)}}return e},B=(e,n)=>{r=1;try{return z(e,n instanceof Function?Array.isArray(e)?n(e.filter(e=>1)):o(n(l(e))):n)}finally{r=t}},G=e=>Array.isArray(e)?e.filter(e=>1).map(G):v(e)?o(l(e).map(([e,t])=>[e,G(t)])):e;window.vanX={calc:P,reactive:x,noreactive:D,stateFields:j,raw:k,list:q,replace:B,compact:G}}
//Store
vanX.Store=(e,t)=>{const a=localStorage.getItem(t),r=vanX.reactive(a?JSON.parse(a):e);return van.derive((()=>localStorage.setItem(t,JSON.stringify(vanX.compact(r))))),r};
//gale
globalThis.Gale=(e,t="")=>{const n=(e,t,s)=>`${e}{${Object.keys(t).map((e=>{const r=t[e];switch(e[0]){case"@":return n(`@media(max-width:${e.substring(1)})`,r,s);case":":return n(`&${e}`,r,s);case".":return n(`${e}${s}`,r,s);case"^":return n(`&:hover .${e.substring(1)}${s}`,r,s)}return`${e.replace(/([a-z])([A-Z])/g,"$1-$2")}: ${r};`})).join("\n")}}`,s=(e,t)=>{const n=t.lastIndexOf(e)+e.length;return n?t.substring(n):t},r=e=>{const t=van.tags[e];let n=[];const s=new Proxy(((...e)=>{const s=t(...e);return s.className=n.join(a+" ")+a+" "+s.className,n=[],s}),{get:(e,t)=>(n.push(t.substring(t.lastIndexOf(".")+1)),s)});return s},a=t?"_"+t:"",c=Object.keys(e).map((t=>n("."+t+a,e[t],a))).join("\n");return globalThis.document?.head.insertAdjacentHTML("beforeend",`<style data-sheet="${a}">${c}</style>`),{Tag:(...e)=>e.map((e=>s("^",s(".",e)))).join(a+" ")+a,CSS:c,DOM:new Proxy({},{get:(e,t)=>r(t)}),H:new Proxy({},{get:(e,t)=>r("div")[t]})}};
//boot
((t="/")=>{fetch(t+"deno.json").then((t=>t.json())).then((e=>{const n=(t,e)=>{let n=document.createElement("script");n.type=t,n.textContent=e,document.head.appendChild(n)},o=e.imports;for(let e in o){const n=o[e];n.startsWith("./")&&(o[e]=t+n.substring(2))}n("importmap",JSON.stringify({imports:o})),n("module",'import "entry"; ')}))})();

9
dist/index.html vendored Normal file
View File

@ -0,0 +1,9 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- css reset --><style>*{margin:0;padding:0;box-sizing:border-box;}html, body{height:100%;width:100%;font-family:Arial, sans-serif;line-height:1.6;}body{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;}img, video{max-width:100%;height:auto;}a{text-decoration:none;color:inherit;}ul, ol{list-style:none;}button, input, textarea{font-family:inherit;font-size:inherit;line-height:inherit;border:none;background:none;padding:0;margin:0;outline:none;}table{border-collapse:collapse;width:100%;}</style>
</head>
<body></body>
</html>

View File

@ -3,6 +3,9 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- css reset --><style>*{margin:0;padding:0;box-sizing:border-box;}html, body{height:100%;width:100%;font-family:Arial, sans-serif;line-height:1.6;}body{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;}img, video{max-width:100%;height:auto;}a{text-decoration:none;color:inherit;}ul, ol{list-style:none;}button, input, textarea{font-family:inherit;font-size:inherit;line-height:inherit;border:none;background:none;padding:0;margin:0;outline:none;}table{border-collapse:collapse;width:100%;}</style>
<script src="./dist/core.js"></script>
<script src="./src/gale.js"></script>
</head>
<body></body>
</html>

View File

@ -1,13 +1,6 @@
const bundle = await fetch(import.meta.resolve("../dist/core.js")).then(r=>r.text());
const index = await fetch(import.meta.resolve("../dist/index.html")).then(r=>r.text());
export const HTML = index.replace(`</head>`, `<script>${bundle}</script></head>`);
export const Root = import.meta.resolve("../");
export const Load =async(file:string)=> await fetch(Root + file).then(resp=>resp.text());
export const Save =async(text:string, name:string)=> await Deno.writeTextFile(name, text);
const index = await Load("index.html");
export const HTML = index.replace(
`</head>`,
`
<style>*{margin:0;padding:0;box-sizing:border-box;}html, body{height:100%;width:100%;font-family:Arial, sans-serif;line-height:1.6;}body{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;}img, video{max-width:100%;height:auto;}a{text-decoration:none;color:inherit;}ul, ol{list-style:none;}button, input, textarea{font-family:inherit;font-size:inherit;line-height:inherit;border:none;background:none;padding:0;margin:0;outline:none;}table{border-collapse:collapse;width:100%;}</style>
<script type="module" src="/proxy/dist/bundle_entry.js?hmr&map"}"></script>
</head>`);

View File

@ -1,34 +0,0 @@
import Van from "npm:vanjs-core@^1.5.5";
globalThis.van = Van;
import * as VanX from "npm:vanjs-ext@^0.6.3";
globalThis.vanX = VanX;
import Gale from "../src/gale.js";
globalThis.Gale = Gale;
const args = new URL(import.meta.url).searchParams;
//Store
vanX.Store=(e,t)=>{const a=localStorage.getItem(t),r=vanX.reactive(a?JSON.parse(a):e);return van.derive((()=>localStorage.setItem(t,JSON.stringify(vanX.compact(r))))),r};
if(args.has("hmr"))
{
const path = "/proxy/"+"src/hmr.js";
await import(path);
}
const root = args.get("root")||"/";
fetch(root+"deno.json")
.then(text=>text.json())
.then(json=>{
const Script=(t,e)=>{let n=document.createElement("script"); n.type=t; n.textContent=e; document.head.appendChild(n); return n;};
const imports = json.imports;
for(let n in imports)
{
const path=imports[n];
path.startsWith("./")&&(imports[n]=root+path.substring(2))
}
args.has("map") && Script("importmap",JSON.stringify({imports}));
Script("module", "").src=imports["GALE@ENTRY"];
});

View File

@ -1,18 +0,0 @@
const command = new Deno.Command("deno", {
args:[
"bundle",
"--no-lock",
"--platform=browser",
"--inline-imports=true",
"--output=dist/core.js",
"--outdir=dist",
"--minify",
"--code-splitting",
"scripts/bundle_entry.ts"
]
});
const result = command.outputSync();
const textDecoder = new TextDecoder();
console.log("stdout:", textDecoder.decode(result.stdout));
console.log("stderr:", textDecoder.decode(result.stderr));

View File

@ -1,9 +1,18 @@
import { contentType } from "jsr:@std/media-types";
import {HTML, Root} from "./assemble_files.ts";
import {HTML} from "./assemble_files.ts";
// Parse the port from the command-line arguments, defaulting to 8000
const port = parseInt(Deno.args[0] || "8000", 10);
const sockets: WebSocket[] = [];
const devinc = await fetch(import.meta.resolve("../src/dev.js")).then(r=>r.text());
let html: string;
try {
html = Deno.readTextFileSync("./index.html");
} catch (_) {
html = HTML;
}
html = html.replace("</head>", `<script>${devinc}</script></head>`);
function extension(path: string): string {
// Remove trailing slash if it exists
@ -16,48 +25,32 @@ function extension(path: string): string {
// Start the HTTP server using Deno.serve
Deno.serve({ port }, async (req: Request) => {
const path = new URL(req.url).pathname;
const url = new URL(req.url);
// Handle WebSocket connections
if (path === "/ws") {
if (url.pathname === "/ws") {
const { socket, response } = Deno.upgradeWebSocket(req);
sockets.push(socket);
return response;
}
// Serve static files or the predefined HTML for non-file routes
const path = new URL(req.url).pathname;
const ext = extension(path);
// Serve the predefined HTML for non-file routes
if (!ext) {
return new Response(HTML, {
return new Response(html, {
headers: { "Content-Type": "text/html" },
});
}
try
{
const proxyPrefix = "/proxy/";
let streamable;
if(path.startsWith(proxyPrefix))
{
const file = await fetch(Root + path.slice(proxyPrefix.length));
streamable = file.body;
}
else
{
const file = await Deno.open("." + path, { read: true });
streamable = file.readable;
}
return new Response(streamable, {
try {
const file = await Deno.open("." + path, { read: true });
return new Response(file.readable, {
headers: { "Content-Type": contentType(ext) || "application/javascript" },
});
}
catch (err)
{
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
return new Response("File not found", { status: 404 });
} else {

View File

@ -6,20 +6,16 @@ async function main()
const denoJson = JSON.parse(await Deno.readTextFile("./deno.json"));
// Check if compilerOptions and types are defined
if (denoJson.compilerOptions?.types)
{
if (denoJson.compilerOptions?.types) {
const types:string[] = denoJson.compilerOptions.types;
// Iterate over each type file and cache it
for (const typeFile of types)
{
let lookup:string = typeFile;
console.log(`found ambient type file`, lookup);
if(typeFile.startsWith("."))
{
lookup = toFileUrl(resolve(Deno.cwd(), typeFile)).href;
}
for (const typeFile of types) {
let lookup:string = typeFile;
if(!typeFile.startsWith("http"))
{
lookup = toFileUrl(resolve(Deno.cwd(), typeFile)).href;
}
console.log(`Scan found types: ${lookup}`);
await import(lookup); // This will cache the file
}

View File

@ -9,8 +9,6 @@ if(args.html)
else
{
const config = await Load("deno.json");
const json = JSON.parse(config);
json.imports["GALE@HOST/"] = Root;
Save(JSON.stringify(json, null, "\t"), "deno.json");
Save(config.replaceAll("./scripts/", Root+"scripts/").replaceAll("./dist/", Root+"dist/"), "deno.json");
Save(await Load("app.js"), "app.js");
}

15
src/boot.js Normal file
View File

@ -0,0 +1,15 @@
(
(root="/")=>fetch(root+"deno.json")
.then(text=>text.json())
.then(json=>{
const n=(t,e)=>{let n=document.createElement("script");n.type=t,n.textContent=e,document.head.appendChild(n)};
const imports = json.imports;
for(let n in imports)
{
const path=imports[n];
path.startsWith("./")&&(imports[n]=root+path.substring(2))
}
n("importmap",JSON.stringify({imports})),
n("module",'import "entry"; ')
})
)();

33
src/dev.js Normal file
View File

@ -0,0 +1,33 @@
// added in devmode to index.html
new WebSocket('ws://'+window.location.host+'/ws').addEventListener('message',e=>e.data==='reload'&&window.location.reload());
vanX.Store =(obj, key)=>
{
let checkInit = JSON.stringify(obj);
let checkStore = localStorage.getItem(key+"check");
localStorage.setItem(key+"check", checkInit);
let recallJSON;
if(checkInit == checkStore)
{
let recallText = localStorage.getItem(key);
try
{
recallJSON = JSON.parse(recallText) || obj;
}
catch(e)
{
recallJSON = obj;
}
}
else
{
recallJSON = obj;
}
const store = vanX.reactive( recallJSON );
van.derive(() => localStorage.setItem(key, JSON.stringify(vanX.compact(store))));
return store;
}

View File

@ -1,5 +1,5 @@
/** @type {Gale.CreateSheet} */
export default (sheet, hash="")=>
globalThis.Gale = (sheet, hash="")=>
{
const KeyQuery = "@";
const KeyState = ":";
@ -76,7 +76,7 @@ export default (sheet, hash="")=>
}
}
),
Div: new Proxy(
H: new Proxy(
{},
{
get(_, prop)

View File

@ -1,120 +0,0 @@
let Time = 0;
/** @type {Record<string, string>} */
let Temp = {};
function Tick()
{
for(const k in Temp)
{
sessionStorage.setItem(k, Temp[k]);
}
Temp = {};
Time = 0;
}
/** @type {(key:string, value:string)=>void} */
function Save(key, value)
{
Temp[key] = value;
if(!Time)
{
Time = setTimeout(Tick, 500);
}
console.log("SAVE", key, value);
};
/** @type {(key:string)=>string|null} */
function Load(key)
{
const value = sessionStorage.getItem(key);
console.log("LOAD", key, value);
return value;
}
/** @type {string|undefined} */
let _ID = undefined;
let _index = 0;
/** @type {(id:string|undefined = undefined)=>void} */
function StartID(id)
{
_index = 0;
_ID = id;
}
function NextID()
{
return _ID ? _ID + "_" + (_index++) + "_" : "";
}
//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_" + NextID() + key;
const stringValue = Load(fullKey);
const signal = origninalState((stringValue ? reader(stringValue) : value));
van.derive(()=>Save(fullKey, writer(signal.val)));
return signal;
};
//bind VanX
const originalReactive = globalThis.vanX.reactive;
globalThis.vanX = {...globalThis.VanX, reactive:(obj, id)=>
{
StartID(id);
const state = originalReactive(obj);
StartID();
return state;
}};
// added in devmode to index.html
new WebSocket('ws://'+window.location.host+'/ws').addEventListener('message',e=>e.data==='reload'&&window.location.reload());
vanX.Store =(obj, key)=>
{
let checkInit = JSON.stringify(obj);
let checkStore = localStorage.getItem(key+"check");
localStorage.setItem(key+"check", checkInit);
let recallJSON;
if(checkInit == checkStore)
{
let recallText = localStorage.getItem(key);
try
{
recallJSON = JSON.parse(recallText) || obj;
}
catch(e)
{
recallJSON = obj;
}
}
else
{
recallJSON = obj;
}
const store = vanX.reactive( recallJSON );
van.derive(() => localStorage.setItem(key, JSON.stringify(vanX.compact(store))));
return store;
}

45
types.d.ts vendored
View File

@ -1,45 +0,0 @@
import type * as VAN from "https://vanjs.org/code/van-1.5.5.d.ts";
import type * as VANX from "https://vanjs.org/code/van-x-0.6.3.d.ts";
type Replace<T extends object, K extends keyof T, R> = Omit<T, K> & { readonly [P in K]: R };
declare module "vanjs-core" { export type State<T> = VAN.State<T> }
declare global
{
namespace Van { export type * from "https://vanjs.org/code/van-1.5.5.d.ts"; }
namespace VanX { export type * from "https://vanjs.org/code/van-x-0.6.3.d.ts"; }
const van: Replace<VAN.Van, "state", <T>(arg:T, HMRKey?:string)=>VAN.State<T>>
const vanX: Replace<typeof VANX, "reactive", <T extends object>(obj: T, HMRKey?:string) => T> & {Store:<T>(obj:T, key:string)=>T}
}
declare global {
namespace Gale {
type KeyQuery = "@";
type KeyState = ":";
type KeyChild = ".";
type KeyGroup = "^";
type UserStyles = Partial<CSSStyleDeclaration> & {[key: `${KeyQuery|KeyState|KeyChild|KeyGroup}${string}`]: UserStyles }
type UserSheet = Record<string, UserStyles>
type CollectKeys<Obj> = {[Key in keyof Obj]: Obj[Key] extends object ? Key | CollectKeys<Obj[Key]> : Key }[keyof Obj]
type FilterKeys<Keys> = Keys extends `${KeyChild|KeyGroup}${infer Rest}` ? Keys : never
type CrossMultiply<A, B> = A extends string ? B extends string ? `${A}${B}` : never : never
type CrossMultiplyRecord<Rec> = keyof Rec | { [K in keyof Rec]: K extends string ? CrossMultiply<K, FilterKeys<CollectKeys<Rec[K]>>> : never }[keyof Rec]
type Tier = (selector:string, obj:UserStyles, suffix:string)=>string;
type CreateSheet = <T extends UserSheet>(sheet:UserSheet&T, hash?:string)=>{
Tag:(...args:CrossMultiplyRecord<T>[])=>string,
CSS:string,
DOM:Elemental<CrossMultiplyRecord<T>>,
Div:Circular<CrossMultiplyRecord<T>, Van.TagFunc<HTMLDivElement>>
}
type Elemental<T extends string> = {[K in keyof HTMLElementTagNameMap]: Van.TagFunc<HTMLElementTagNameMap[K]>&Circular<T, Van.TagFunc<HTMLElementTagNameMap[K]>>}
type Circular<Keys extends string, Func> = {
[K in Keys]: Circular<Keys, Func>&Func
};
}
const Gale:Gale.CreateSheet
}