uraniyum 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers.d.ts +5 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +89 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +96 -0
- package/dist/index.js.map +1 -0
- package/dist/index.min.js +2 -0
- package/dist/index.min.js.map +1 -0
- package/dist/router.d.ts +4 -0
- package/dist/state.d.ts +5 -0
- package/dist/tags.d.ts +1 -0
- package/package.json +33 -0
- package/src/helpers.ts +20 -0
- package/src/index.ts +4 -0
- package/src/router.ts +25 -0
- package/src/state.ts +21 -0
- package/src/tags.ts +20 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
function state(initial) {
|
|
2
|
+
let value = initial;
|
|
3
|
+
const listeners = [];
|
|
4
|
+
const set = (newValue) => {
|
|
5
|
+
value = newValue;
|
|
6
|
+
listeners.forEach(fn => fn(value));
|
|
7
|
+
};
|
|
8
|
+
const get = () => value;
|
|
9
|
+
const subscribe = (fn) => {
|
|
10
|
+
listeners.push(fn);
|
|
11
|
+
return () => {
|
|
12
|
+
const index = listeners.indexOf(fn);
|
|
13
|
+
if (index > -1)
|
|
14
|
+
listeners.splice(index, 1);
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
return { get, set, subscribe };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const tags = new Proxy({}, {
|
|
21
|
+
get(_, tag) {
|
|
22
|
+
return (attrsOrChild, ...children) => {
|
|
23
|
+
const el = document.createElement(tag);
|
|
24
|
+
if (attrsOrChild && typeof attrsOrChild === 'object' && !Array.isArray(attrsOrChild) && !(attrsOrChild instanceof Node)) {
|
|
25
|
+
for (const [k, v] of Object.entries(attrsOrChild)) {
|
|
26
|
+
el.setAttribute(k, v);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (attrsOrChild != null) {
|
|
30
|
+
children.unshift(attrsOrChild);
|
|
31
|
+
}
|
|
32
|
+
for (const child of children.flat()) {
|
|
33
|
+
if (child instanceof Node)
|
|
34
|
+
el.appendChild(child);
|
|
35
|
+
else
|
|
36
|
+
el.appendChild(document.createTextNode(String(child)));
|
|
37
|
+
}
|
|
38
|
+
return el;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
function router(routes) {
|
|
44
|
+
const getRoute = (path) => {
|
|
45
|
+
return routes[path] || routes["*"];
|
|
46
|
+
};
|
|
47
|
+
const renderRoute = () => {
|
|
48
|
+
const path = window.location.pathname;
|
|
49
|
+
const pageFn = getRoute(path);
|
|
50
|
+
const page = pageFn();
|
|
51
|
+
const app = document.getElementById("app");
|
|
52
|
+
if (!app)
|
|
53
|
+
throw new Error("No #app element found");
|
|
54
|
+
app.innerHTML = "";
|
|
55
|
+
app.appendChild(page);
|
|
56
|
+
};
|
|
57
|
+
window.addEventListener("popstate", renderRoute);
|
|
58
|
+
return {
|
|
59
|
+
render: renderRoute,
|
|
60
|
+
navigate: (path) => {
|
|
61
|
+
history.pushState(null, "", path);
|
|
62
|
+
renderRoute();
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function add(...components) {
|
|
68
|
+
const app = document.getElementById("app");
|
|
69
|
+
if (!app)
|
|
70
|
+
throw new Error("No #app element found");
|
|
71
|
+
for (const c of components) {
|
|
72
|
+
if (typeof c === "function") {
|
|
73
|
+
const el = c();
|
|
74
|
+
if (!(el instanceof Node)) {
|
|
75
|
+
throw new Error("Component function must return an HTMLElement");
|
|
76
|
+
}
|
|
77
|
+
app.appendChild(el);
|
|
78
|
+
}
|
|
79
|
+
else if ("render" in c && typeof c.render === "function") {
|
|
80
|
+
c.render();
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
throw new Error("Invalid component passed to add()");
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export { add, router, state, tags };
|
|
89
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/state.ts","../src/tags.ts","../src/router.ts","../src/helpers.ts"],"sourcesContent":["export function state<T>(initial: T) {\r\n let value = initial\r\n const listeners: Function[] = []\r\n\r\n const set = (newValue: T) => {\r\n value = newValue\r\n listeners.forEach(fn => fn(value))\r\n }\r\n\r\n const get = () => value\r\n\r\n const subscribe = (fn: Function) => {\r\n listeners.push(fn)\r\n return () => {\r\n const index = listeners.indexOf(fn)\r\n if (index > -1) listeners.splice(index, 1)\r\n }\r\n }\r\n\r\n return { get, set, subscribe }\r\n}","export const tags = new Proxy({}, {\r\n get(_, tag: string) {\r\n return (attrsOrChild?: any, ...children: any[]) => {\r\n const el = document.createElement(tag)\r\n if (attrsOrChild && typeof attrsOrChild === 'object' && !Array.isArray(attrsOrChild) && !(attrsOrChild instanceof Node)) {\r\n for (const [k, v] of Object.entries(attrsOrChild)) {\r\n el.setAttribute(k, v as string)\r\n }\r\n } else if (attrsOrChild != null) {\r\n children.unshift(attrsOrChild)\r\n }\r\n\r\n for (const child of children.flat()) {\r\n if (child instanceof Node) el.appendChild(child)\r\n else el.appendChild(document.createTextNode(String(child)))\r\n }\r\n return el\r\n }\r\n }\r\n})","export function router(routes: Record<string, () => HTMLElement>) {\r\n const getRoute = (path: string) => {\r\n return routes[path] || routes[\"*\"]\r\n }\r\n\r\n const renderRoute = () => {\r\n const path = window.location.pathname\r\n const pageFn = getRoute(path)\r\n const page = pageFn()\r\n const app = document.getElementById(\"app\")\r\n if (!app) throw new Error(\"No #app element found\")\r\n app.innerHTML = \"\"\r\n app.appendChild(page)\r\n }\r\n\r\n window.addEventListener(\"popstate\", renderRoute)\r\n\r\n return {\r\n render: renderRoute,\r\n navigate: (path: string) => {\r\n history.pushState(null, \"\", path)\r\n renderRoute()\r\n }\r\n }\r\n}","type Component = (() => HTMLElement) | { render: () => void }\r\n\r\nexport function add(...components: Component[]) {\r\n const app = document.getElementById(\"app\")\r\n if (!app) throw new Error(\"No #app element found\")\r\n\r\n for (const c of components) {\r\n if (typeof c === \"function\") {\r\n const el = c()\r\n if (!(el instanceof Node)) {\r\n throw new Error(\"Component function must return an HTMLElement\")\r\n }\r\n app.appendChild(el)\r\n } else if (\"render\" in c && typeof c.render === \"function\") {\r\n c.render()\r\n } else {\r\n throw new Error(\"Invalid component passed to add()\")\r\n }\r\n }\r\n}\r\n"],"names":[],"mappings":"AAAM,SAAU,KAAK,CAAI,OAAU,EAAA;IAC/B,IAAI,KAAK,GAAG,OAAO,CAAA;IACnB,MAAM,SAAS,GAAe,EAAE,CAAA;AAEhC,IAAA,MAAM,GAAG,GAAG,CAAC,QAAW,KAAI;QACxB,KAAK,GAAG,QAAQ,CAAA;AAChB,QAAA,SAAS,CAAC,OAAO,CAAC,EAAE,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;AACtC,KAAC,CAAA;AAED,IAAA,MAAM,GAAG,GAAG,MAAM,KAAK,CAAA;AAEvB,IAAA,MAAM,SAAS,GAAG,CAAC,EAAY,KAAI;AAC/B,QAAA,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AAClB,QAAA,OAAO,MAAK;YACR,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YACnC,IAAI,KAAK,GAAG,CAAC,CAAC;AAAE,gBAAA,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;AAC9C,SAAC,CAAA;AACL,KAAC,CAAA;AAED,IAAA,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,CAAA;AAClC;;MCpBa,IAAI,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE;IAC9B,GAAG,CAAC,CAAC,EAAE,GAAW,EAAA;AACd,QAAA,OAAO,CAAC,YAAkB,EAAE,GAAG,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,mCAAmC,CAAC,CAAA;SACvD;KACJ;AACL;;;;"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function state(initial) {
|
|
6
|
+
let value = initial;
|
|
7
|
+
const listeners = [];
|
|
8
|
+
const set = (newValue) => {
|
|
9
|
+
value = newValue;
|
|
10
|
+
listeners.forEach(fn => fn(value));
|
|
11
|
+
};
|
|
12
|
+
const get = () => value;
|
|
13
|
+
const subscribe = (fn) => {
|
|
14
|
+
listeners.push(fn);
|
|
15
|
+
return () => {
|
|
16
|
+
const index = listeners.indexOf(fn);
|
|
17
|
+
if (index > -1)
|
|
18
|
+
listeners.splice(index, 1);
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
return { get, set, subscribe };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const tags = new Proxy({}, {
|
|
25
|
+
get(_, tag) {
|
|
26
|
+
return (attrsOrChild, ...children) => {
|
|
27
|
+
const el = document.createElement(tag);
|
|
28
|
+
if (attrsOrChild && typeof attrsOrChild === 'object' && !Array.isArray(attrsOrChild) && !(attrsOrChild instanceof Node)) {
|
|
29
|
+
for (const [k, v] of Object.entries(attrsOrChild)) {
|
|
30
|
+
el.setAttribute(k, v);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else if (attrsOrChild != null) {
|
|
34
|
+
children.unshift(attrsOrChild);
|
|
35
|
+
}
|
|
36
|
+
for (const child of children.flat()) {
|
|
37
|
+
if (child instanceof Node)
|
|
38
|
+
el.appendChild(child);
|
|
39
|
+
else
|
|
40
|
+
el.appendChild(document.createTextNode(String(child)));
|
|
41
|
+
}
|
|
42
|
+
return el;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
function router(routes) {
|
|
48
|
+
const getRoute = (path) => {
|
|
49
|
+
return routes[path] || routes["*"];
|
|
50
|
+
};
|
|
51
|
+
const renderRoute = () => {
|
|
52
|
+
const path = window.location.pathname;
|
|
53
|
+
const pageFn = getRoute(path);
|
|
54
|
+
const page = pageFn();
|
|
55
|
+
const app = document.getElementById("app");
|
|
56
|
+
if (!app)
|
|
57
|
+
throw new Error("No #app element found");
|
|
58
|
+
app.innerHTML = "";
|
|
59
|
+
app.appendChild(page);
|
|
60
|
+
};
|
|
61
|
+
window.addEventListener("popstate", renderRoute);
|
|
62
|
+
return {
|
|
63
|
+
render: renderRoute,
|
|
64
|
+
navigate: (path) => {
|
|
65
|
+
history.pushState(null, "", path);
|
|
66
|
+
renderRoute();
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function add(...components) {
|
|
72
|
+
const app = document.getElementById("app");
|
|
73
|
+
if (!app)
|
|
74
|
+
throw new Error("No #app element found");
|
|
75
|
+
for (const c of components) {
|
|
76
|
+
if (typeof c === "function") {
|
|
77
|
+
const el = c();
|
|
78
|
+
if (!(el instanceof Node)) {
|
|
79
|
+
throw new Error("Component function must return an HTMLElement");
|
|
80
|
+
}
|
|
81
|
+
app.appendChild(el);
|
|
82
|
+
}
|
|
83
|
+
else if ("render" in c && typeof c.render === "function") {
|
|
84
|
+
c.render();
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
throw new Error("Invalid component passed to add()");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
exports.add = add;
|
|
93
|
+
exports.router = router;
|
|
94
|
+
exports.state = state;
|
|
95
|
+
exports.tags = tags;
|
|
96
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/state.ts","../src/tags.ts","../src/router.ts","../src/helpers.ts"],"sourcesContent":["export function state<T>(initial: T) {\r\n let value = initial\r\n const listeners: Function[] = []\r\n\r\n const set = (newValue: T) => {\r\n value = newValue\r\n listeners.forEach(fn => fn(value))\r\n }\r\n\r\n const get = () => value\r\n\r\n const subscribe = (fn: Function) => {\r\n listeners.push(fn)\r\n return () => {\r\n const index = listeners.indexOf(fn)\r\n if (index > -1) listeners.splice(index, 1)\r\n }\r\n }\r\n\r\n return { get, set, subscribe }\r\n}","export const tags = new Proxy({}, {\r\n get(_, tag: string) {\r\n return (attrsOrChild?: any, ...children: any[]) => {\r\n const el = document.createElement(tag)\r\n if (attrsOrChild && typeof attrsOrChild === 'object' && !Array.isArray(attrsOrChild) && !(attrsOrChild instanceof Node)) {\r\n for (const [k, v] of Object.entries(attrsOrChild)) {\r\n el.setAttribute(k, v as string)\r\n }\r\n } else if (attrsOrChild != null) {\r\n children.unshift(attrsOrChild)\r\n }\r\n\r\n for (const child of children.flat()) {\r\n if (child instanceof Node) el.appendChild(child)\r\n else el.appendChild(document.createTextNode(String(child)))\r\n }\r\n return el\r\n }\r\n }\r\n})","export function router(routes: Record<string, () => HTMLElement>) {\r\n const getRoute = (path: string) => {\r\n return routes[path] || routes[\"*\"]\r\n }\r\n\r\n const renderRoute = () => {\r\n const path = window.location.pathname\r\n const pageFn = getRoute(path)\r\n const page = pageFn()\r\n const app = document.getElementById(\"app\")\r\n if (!app) throw new Error(\"No #app element found\")\r\n app.innerHTML = \"\"\r\n app.appendChild(page)\r\n }\r\n\r\n window.addEventListener(\"popstate\", renderRoute)\r\n\r\n return {\r\n render: renderRoute,\r\n navigate: (path: string) => {\r\n history.pushState(null, \"\", path)\r\n renderRoute()\r\n }\r\n }\r\n}","type Component = (() => HTMLElement) | { render: () => void }\r\n\r\nexport function add(...components: Component[]) {\r\n const app = document.getElementById(\"app\")\r\n if (!app) throw new Error(\"No #app element found\")\r\n\r\n for (const c of components) {\r\n if (typeof c === \"function\") {\r\n const el = c()\r\n if (!(el instanceof Node)) {\r\n throw new Error(\"Component function must return an HTMLElement\")\r\n }\r\n app.appendChild(el)\r\n } else if (\"render\" in c && typeof c.render === \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,KAAC,CAAA;AAED,IAAA,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,WAAW,CAAC,CAAA;IAEhD,OAAO;AACH,QAAA,MAAM,EAAE,WAAW;AACnB,QAAA,QAAQ,EAAE,CAAC,IAAY,KAAI;YACvB,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,CAAA;AACjC,YAAA,WAAW,EAAE,CAAA;SAChB;KACJ,CAAA;AACL;;ACtBgB,SAAA,GAAG,CAAC,GAAG,UAAuB,EAAA;IAC1C,MAAM,GAAG,GAAG,QAAQ,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;AAC1C,IAAA,IAAI,CAAC,GAAG;AAAE,QAAA,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAA;AAElD,IAAA,KAAK,MAAM,CAAC,IAAI,UAAU,EAAE;AACxB,QAAA,IAAI,OAAO,CAAC,KAAK,UAAU,EAAE;AACzB,YAAA,MAAM,EAAE,GAAG,CAAC,EAAE,CAAA;AACd,YAAA,IAAI,EAAE,EAAE,YAAY,IAAI,CAAC,EAAE;AACvB,gBAAA,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;aACnE;AACD,YAAA,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;SACtB;aAAM,IAAI,QAAQ,IAAI,CAAC,IAAI,OAAO,CAAC,CAAC,MAAM,KAAK,UAAU,EAAE;YACxD,CAAC,CAAC,MAAM,EAAE,CAAA;SACb;aAAM;AACH,YAAA,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAA;SACvD;KACJ;AACL;;;;;;;"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).MiniUI={})}(this,function(e){"use strict";const n=new Proxy({},{get:(e,n)=>(e,...t)=>{const o=document.createElement(n);if(!e||"object"!=typeof e||Array.isArray(e)||e instanceof Node)null!=e&&t.unshift(e);else for(const[n,t]of Object.entries(e))o.setAttribute(n,t);for(const e of t.flat())e instanceof Node?o.appendChild(e):o.appendChild(document.createTextNode(String(e)));return o}});e.add=function(...e){const n=document.getElementById("app");if(!n)throw new Error("No #app element found");for(const t of e)if("function"==typeof t){const e=t();if(!(e instanceof Node))throw new Error("Component function must return an HTMLElement");n.appendChild(e)}else{if(!("render"in t)||"function"!=typeof t.render)throw new Error("Invalid component passed to add()");t.render()}},e.router=function(e){const n=()=>{const n=(n=>e[n]||e["*"])(window.location.pathname),t=n(),o=document.getElementById("app");if(!o)throw new Error("No #app element found");o.innerHTML="",o.appendChild(t)};return window.addEventListener("popstate",n),{render:n,navigate:e=>{history.pushState(null,"",e),n()}}},e.state=function(e){let n=e;const t=[];return{get:()=>n,set:e=>{n=e,t.forEach(e=>e(n))},subscribe:e=>(t.push(e),()=>{const n=t.indexOf(e);n>-1&&t.splice(n,1)})}},e.tags=n,Object.defineProperty(e,"__esModule",{value:!0})});
|
|
2
|
+
//# sourceMappingURL=index.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.min.js","sources":["../src/tags.ts","../src/helpers.ts","../src/router.ts","../src/state.ts"],"sourcesContent":["export const tags = new Proxy({}, {\r\n get(_, tag: string) {\r\n return (attrsOrChild?: any, ...children: any[]) => {\r\n const el = document.createElement(tag)\r\n if (attrsOrChild && typeof attrsOrChild === 'object' && !Array.isArray(attrsOrChild) && !(attrsOrChild instanceof Node)) {\r\n for (const [k, v] of Object.entries(attrsOrChild)) {\r\n el.setAttribute(k, v as string)\r\n }\r\n } else if (attrsOrChild != null) {\r\n children.unshift(attrsOrChild)\r\n }\r\n\r\n for (const child of children.flat()) {\r\n if (child instanceof Node) el.appendChild(child)\r\n else el.appendChild(document.createTextNode(String(child)))\r\n }\r\n return el\r\n }\r\n }\r\n})","type Component = (() => HTMLElement) | { render: () => void }\r\n\r\nexport function add(...components: Component[]) {\r\n const app = document.getElementById(\"app\")\r\n if (!app) throw new Error(\"No #app element found\")\r\n\r\n for (const c of components) {\r\n if (typeof c === \"function\") {\r\n const el = c()\r\n if (!(el instanceof Node)) {\r\n throw new Error(\"Component function must return an HTMLElement\")\r\n }\r\n app.appendChild(el)\r\n } else if (\"render\" in c && typeof c.render === \"function\") {\r\n c.render()\r\n } else {\r\n throw new Error(\"Invalid component passed to add()\")\r\n }\r\n }\r\n}\r\n","export function router(routes: Record<string, () => HTMLElement>) {\r\n const getRoute = (path: string) => {\r\n return routes[path] || routes[\"*\"]\r\n }\r\n\r\n const renderRoute = () => {\r\n const path = window.location.pathname\r\n const pageFn = getRoute(path)\r\n const page = pageFn()\r\n const app = document.getElementById(\"app\")\r\n if (!app) throw new Error(\"No #app element found\")\r\n app.innerHTML = \"\"\r\n app.appendChild(page)\r\n }\r\n\r\n window.addEventListener(\"popstate\", renderRoute)\r\n\r\n return {\r\n render: renderRoute,\r\n navigate: (path: string) => {\r\n history.pushState(null, \"\", path)\r\n renderRoute()\r\n }\r\n }\r\n}","export function state<T>(initial: T) {\r\n let value = initial\r\n const listeners: Function[] = []\r\n\r\n const set = (newValue: T) => {\r\n value = newValue\r\n listeners.forEach(fn => fn(value))\r\n }\r\n\r\n const get = () => value\r\n\r\n const subscribe = (fn: Function) => {\r\n listeners.push(fn)\r\n return () => {\r\n const index = listeners.indexOf(fn)\r\n if (index > -1) listeners.splice(index, 1)\r\n }\r\n }\r\n\r\n return { get, set, subscribe }\r\n}"],"names":["tags","Proxy","get","_","tag","attrsOrChild","children","el","document","createElement","Array","isArray","Node","unshift","k","v","Object","entries","setAttribute","child","flat","appendChild","createTextNode","String","components","app","getElementById","Error","c","render","routes","renderRoute","pageFn","path","getRoute","window","location","pathname","page","innerHTML","addEventListener","navigate","history","pushState","initial","value","listeners","set","newValue","forEach","fn","subscribe","push","index","indexOf","splice"],"mappings":"mPAAaA,EAAO,IAAIC,MAAM,GAAI,C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C,GAAMA,EAAGL,KAaZM,UARAD,IACfJ,EAAUM,KAAKF,GACR,KACH,MAAMG,EAAQP,EAAUQ,QAAQJ,GAC5BG,GAAS,GAAGP,EAAUS,OAAOF,EAAO,KAKpD"}
|
package/dist/router.d.ts
ADDED
package/dist/state.d.ts
ADDED
package/dist/tags.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const tags: {};
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "uraniyum",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"module": "dist/index.esm.js",
|
|
6
|
+
"browser": "dist/index.min.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/",
|
|
10
|
+
"src/",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rollup -c",
|
|
15
|
+
"dev": "rollup -c -w",
|
|
16
|
+
"type-check": "tsc --noEmit"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"framework"
|
|
20
|
+
],
|
|
21
|
+
"author": "",
|
|
22
|
+
"license": "ISC",
|
|
23
|
+
"description": "yum",
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
26
|
+
"rollup": "^2.79.2",
|
|
27
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
28
|
+
"typescript": "^5.9.3"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"tslib": "^2.8.1"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type Component = (() => HTMLElement) | { render: () => void }
|
|
2
|
+
|
|
3
|
+
export function add(...components: Component[]) {
|
|
4
|
+
const app = document.getElementById("app")
|
|
5
|
+
if (!app) throw new Error("No #app element found")
|
|
6
|
+
|
|
7
|
+
for (const c of components) {
|
|
8
|
+
if (typeof c === "function") {
|
|
9
|
+
const el = c()
|
|
10
|
+
if (!(el instanceof Node)) {
|
|
11
|
+
throw new Error("Component function must return an HTMLElement")
|
|
12
|
+
}
|
|
13
|
+
app.appendChild(el)
|
|
14
|
+
} else if ("render" in c && typeof c.render === "function") {
|
|
15
|
+
c.render()
|
|
16
|
+
} else {
|
|
17
|
+
throw new Error("Invalid component passed to add()")
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/index.ts
ADDED
package/src/router.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export function router(routes: Record<string, () => HTMLElement>) {
|
|
2
|
+
const getRoute = (path: string) => {
|
|
3
|
+
return routes[path] || routes["*"]
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const renderRoute = () => {
|
|
7
|
+
const path = window.location.pathname
|
|
8
|
+
const pageFn = getRoute(path)
|
|
9
|
+
const page = pageFn()
|
|
10
|
+
const app = document.getElementById("app")
|
|
11
|
+
if (!app) throw new Error("No #app element found")
|
|
12
|
+
app.innerHTML = ""
|
|
13
|
+
app.appendChild(page)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
window.addEventListener("popstate", renderRoute)
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
render: renderRoute,
|
|
20
|
+
navigate: (path: string) => {
|
|
21
|
+
history.pushState(null, "", path)
|
|
22
|
+
renderRoute()
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
package/src/state.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function state<T>(initial: T) {
|
|
2
|
+
let value = initial
|
|
3
|
+
const listeners: Function[] = []
|
|
4
|
+
|
|
5
|
+
const set = (newValue: T) => {
|
|
6
|
+
value = newValue
|
|
7
|
+
listeners.forEach(fn => fn(value))
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const get = () => value
|
|
11
|
+
|
|
12
|
+
const subscribe = (fn: Function) => {
|
|
13
|
+
listeners.push(fn)
|
|
14
|
+
return () => {
|
|
15
|
+
const index = listeners.indexOf(fn)
|
|
16
|
+
if (index > -1) listeners.splice(index, 1)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return { get, set, subscribe }
|
|
21
|
+
}
|
package/src/tags.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const tags = new Proxy({}, {
|
|
2
|
+
get(_, tag: string) {
|
|
3
|
+
return (attrsOrChild?: any, ...children: any[]) => {
|
|
4
|
+
const el = document.createElement(tag)
|
|
5
|
+
if (attrsOrChild && typeof attrsOrChild === 'object' && !Array.isArray(attrsOrChild) && !(attrsOrChild instanceof Node)) {
|
|
6
|
+
for (const [k, v] of Object.entries(attrsOrChild)) {
|
|
7
|
+
el.setAttribute(k, v as string)
|
|
8
|
+
}
|
|
9
|
+
} else if (attrsOrChild != null) {
|
|
10
|
+
children.unshift(attrsOrChild)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
for (const child of children.flat()) {
|
|
14
|
+
if (child instanceof Node) el.appendChild(child)
|
|
15
|
+
else el.appendChild(document.createTextNode(String(child)))
|
|
16
|
+
}
|
|
17
|
+
return el
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
})
|