tagu-tagu 4.1.0 → 4.2.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/bundle.min.js +1 -1
- package/package.json +2 -2
- package/src/signal/Signal.ts +14 -2
package/dist/bundle.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var N=class{node2Data=new WeakMap;addCallbacks(t,n){if(!n)return;this.node2DescendantCallbacks.has(t)||this.node2DescendantCallbacks.set(t,{});let i=this.node2DescendantCallbacks.get(t);$(i,n);let r=this.node2Data.get(t);A(i,r)}setDataRecord(t,n){n&&this.node2Data.set(t,n)}resolveCallbacks(t,n){let i=(l,a)=>{if(A(a,this.node2Data.get(l)),!!Object.keys(a).length){if(!l.parentElement){this.node2DescendantCallbacks.has(l)||this.node2DescendantCallbacks.set(l,{});let E=this.node2DescendantCallbacks.get(l);E&&$(E,a);return}i(l.parentElement,a)}},r=this.node2DescendantCallbacks.get(n);r&&i(t,r)}node2DescendantCallbacks=new WeakMap};function A(e,t){for(let n in t)if(n in e){for(let i of e[n])i(t[n]);delete e[n]}}var c=new N;function O(e,t){c.setDataRecord(e,t)}function G(e){if(!e)return;let t={};for(let n in e){let i=e[n];t[n]=[i]}if(Object.keys(t).length)return t}function $(e,t){for(let n in t)e[n]||(e[n]=[]),e[n].push(...t[n])}function k(e,t){if(!e)return;let n=c.node2Data.get(e);return n&&t in n?n[t]:k(e.parentElement,t)}function b(e,t){if(typeof t=="string")return Q(e,t);c.addCallbacks(e,G(t))}function Q(e,t){return new Promise(n=>{let i=k(e,t);i!==void 0?n(i):c.addCallbacks(e,{[t]:[n]})})}function _(e,t=n=>n){return new g(e,t)}var g=class{constructor(t,n){this.key=t;this.map=n}};var u=class{next=null;firstNode=null};var S=class{subscribers=new Set;prepareUpdate(){for(let t of this.subscribers)t.prepareUpdate()}},w=class extends S{constructor(n){super();this.value=n}get(){return this.value}set(n){this.value=n,this.prepareUpdate(),this.updateFromLeaft()}updateFromLeaft(){for(let n of this.subscribers)n.updateFromLeaf()}},
|
|
1
|
+
var N=class{node2Data=new WeakMap;addCallbacks(t,n){if(!n)return;this.node2DescendantCallbacks.has(t)||this.node2DescendantCallbacks.set(t,{});let i=this.node2DescendantCallbacks.get(t);$(i,n);let r=this.node2Data.get(t);A(i,r)}setDataRecord(t,n){n&&this.node2Data.set(t,n)}resolveCallbacks(t,n){let i=(l,a)=>{if(A(a,this.node2Data.get(l)),!!Object.keys(a).length){if(!l.parentElement){this.node2DescendantCallbacks.has(l)||this.node2DescendantCallbacks.set(l,{});let E=this.node2DescendantCallbacks.get(l);E&&$(E,a);return}i(l.parentElement,a)}},r=this.node2DescendantCallbacks.get(n);r&&i(t,r)}node2DescendantCallbacks=new WeakMap};function A(e,t){for(let n in t)if(n in e){for(let i of e[n])i(t[n]);delete e[n]}}var c=new N;function O(e,t){c.setDataRecord(e,t)}function G(e){if(!e)return;let t={};for(let n in e){let i=e[n];t[n]=[i]}if(Object.keys(t).length)return t}function $(e,t){for(let n in t)e[n]||(e[n]=[]),e[n].push(...t[n])}function k(e,t){if(!e)return;let n=c.node2Data.get(e);return n&&t in n?n[t]:k(e.parentElement,t)}function b(e,t){if(typeof t=="string")return Q(e,t);c.addCallbacks(e,G(t))}function Q(e,t){return new Promise(n=>{let i=k(e,t);i!==void 0?n(i):c.addCallbacks(e,{[t]:[n]})})}function _(e,t=n=>n){return new g(e,t)}var g=class{constructor(t,n){this.key=t;this.map=n}};var u=class{next=null;firstNode=null};var S=class{subscribers=new Set;prepareUpdate(){for(let t of this.subscribers)t.prepareUpdate()}},w=class extends S{constructor(n){super();this.value=n}get(){return this.value}set(n){this.value=n,this.prepareUpdate(),this.updateFromLeaft()}updateFromLeaft(){for(let n of this.subscribers)n.updateFromLeaf()}},C=class extends S{constructor(n){super();this.map=n}cache;dirty=!0;get(){return this.dirty&&(this.cache=this.map(),this.dirty=!1),this.cache}prepareUpdate(){this.dirty||(this.dirty=!0,super.prepareUpdate())}updateFromLeaf(){for(let n of this.subscribers)n.updateFromLeaf();this.subscribers.size===0&&this.get()}};var p=class{internal;constructor(t){this.internal=t}get(){return h&&this.internal.subscribers.add(h),this.internal.get()}},z=class extends p{constructor(t){super(new w(t))}set(t){this.internal.set(t)}},h,I=class extends p{constructor(t){super(new C(()=>{let n=h;h=this.internal;let i=t();return h=n,i}))}};function m(e){let t;new I(()=>{t?.(),e({onCleanup(r){t=r}})}).get()}function ye(e){return new z(e)}function U(e){return new I(e)}function j(e,t){let n=X(t);Y(n);for(let i of n)J(e,i)}function J(e,t){t instanceof u?t.run(e):(c.resolveCallbacks(e,t),e.appendChild(t))}function X(e){return e.map(t=>{if(typeof t=="string"||t instanceof p){let n=document.createTextNode("");return L(t,i=>{n.textContent=i}),n}return t})}function Y(e){for(let t=0;t<e.length;t++){let n=e[t];n instanceof u&&(n.next=e[t+1]??null)}}function V(e){let t=e.next;return t===null?null:t instanceof Node?t:t.firstNode?t.firstNode:V(t)}function y(e){let t=V(e);return t?.parentElement?t:null}function L(e,t){typeof e=="string"?t(e):e instanceof p?m(()=>t(e.get())):t(e)}function v(e,t,n){t instanceof g?b(e,{[t.key]:i=>{let l=i instanceof p?U(()=>t.map(i.get())):t.map(i);L(l,n)}}):L(t,n)}function Z(e,t){t!==void 0&&v(e,t,n=>{e.innerHTML=n})}function q(e,t){t!==void 0&&v(e,t,n=>{e.textContent=n})}function ee(e,t){let n=e.style;if(n instanceof CSSStyleDeclaration)for(let i in t){let r=t[i];v(e,r,l=>n.setProperty(i,l))}}function te(e,t){for(let n in t){let i=t[n];v(e,i,r=>{r?e.setAttribute(n,r):e.removeAttribute(n)})}}function ne(e,t){for(let n in t){let i=t[n];v(e,i,r=>{e[n]=r})}}function ie(e,t){let n=[];for(let i in t){let r=e.querySelector(i);r&&n.push(D(r,t[i]))}return H(n)}function H(e){let t=e.filter(n=>n instanceof Promise);if(t.length!==0)return Promise.all(t)}function re(e,t){let n=[];for(let i in t){let r=e.querySelectorAll(i);for(let l of r)n.push(D(l,t[i]))}return H(n)}function oe(e,t){for(let n in t){let r=t[n];r&&(typeof r=="function"?e.addEventListener(n,r):r instanceof g?b(e,{[r.key]:l=>{let a=r.map(l);e.addEventListener(n,a)}}):e.addEventListener(n,r.listener,r.options))}}function K(e,t){Z(e,t.html),q(e,t.text),te(e,t.attr),ne(e,t.prop),ee(e,t.css);let n=ie(e,t.$),i=re(e,t.$$);return oe(e,t.on),O(e,t.data),H([n,i])}function se(e,t){let n={};for(let l in t.css){let a=t.css[l];typeof a=="string"&&(n[l]=a),a instanceof p&&(n[l]=a.get())}let i=t.animate;return i&&typeof i!="number"&&(i.duration??=400,i.easing??="swing",i.easing=i.easing==="swing"?"ease-in-out":i.easing),e.animate([{},n],i).finished.then(()=>K(e,t))}function le(e,t){return t.animate!==void 0?se(e,t):K(e,t)}function D(e,t){if(e)if(typeof t=="string"||t instanceof p)q(e,t);else if(Array.isArray(t))j(e,t);else if(typeof t=="function"){let n=t(e);if(n instanceof Promise)return n}else return le(e,t)}function x(e,...t){let n=typeof e=="string"?document.querySelector(e):e;return(async()=>{for(let i of t){let r=D(n,i);r&&await r}})(),n}function Ne(e,...t){for(let n of document.querySelectorAll(e))x(n,...t)}function ke(e,...t){return new Promise(n=>{x(e,...t,i=>{n(i)})})}function Re(e,...t){let n=document.createElementNS("http://www.w3.org/2000/svg",e);return x(n,...t)}function o(e,...t){let n=document.createElement(e);return x(n,...t),n}function Be(e,...t){let n=R({html:e}).children[0];return x(n,...t)}function Ae(...e){return o("h1",...e)}function $e(...e){return o("h2",...e)}function Oe(...e){return o("h3",...e)}function Ue(...e){return o("h4",...e)}function je(...e){return o("h5",...e)}function Ve(...e){return o("h6",...e)}function qe(...e){return o("p",...e)}function Ke(...e){return o("section",...e)}function We(...e){return o("button",...e)}function Ge(...e){return o("span",...e)}function Qe(e){function t(n,i){return`${n} {${Object.keys(i).map(r=>`${r}: ${i[r]};`).join("")}}`}return o("style",[Object.keys(e).map(n=>t(n,e[n])).join("")])}function R(...e){return o("div",...e)}function _e(...e){return R({css:{display:"flex"}},...e)}function Je(...e){return o("input",...e)}function Xe(...e){return o("textarea",...e)}function Ye(...e){return o("select",...e)}function Ze(...e){return o("option",...e)}function et(...e){return o("br",...e)}function tt(...e){return o("th",...e)}function nt(...e){return o("tr",...e)}function it(...e){return o("td",...e)}function rt(...e){return o("b",...e)}function ot(...e){return o("label",...e)}function st(...e){return o("a",...e)}function lt(...e){return o("blockquote",...e)}function at(...e){return o("li",...e)}function ct(...e){return o("ol",...e)}function ut(...e){return o("ul",...e)}function ft(...e){return o("audio",...e)}function pt(...e){return o("video",...e)}function dt(...e){return o("img",...e)}function mt(...e){return o("canvas",...e)}function Et(...e){return o("iframe",...e)}function Tt(...e){return o("form",...e)}function gt(...e){return o("table",...e)}function yt(...e){return o("tbody",...e)}function xt(...e){return o("hr",...e)}function ht(...e){return o("main",...e)}function ae(e,t){return new B(e,t)}var B=class extends u{constructor(n,i){super();this.list=n;this.map=i}run(n){let i=new Map,r=new Map;m(()=>{let a=[];for(let s of this.list.get())i.has(s)||a.push(s);let E=[],f=new Set(this.list.get());for(let s of r.keys()){let d=r.get(s);d&&!f.has(d)&&E.push(s)}for(let s of a){let d=this.map(s),M=typeof d=="string"?document.createTextNode(d):d;c.resolveCallbacks(n,M),r.set(M,s),i.set(s,M)}for(let s of E){s.parentNode?.removeChild(s);let d=r.get(s);r.delete(s),d&&i.delete(d)}for(let s of[...r.keys()])s.parentElement?.removeChild(s);let T=y(this);for(let s of this.list.get())n.insertBefore(i.get(s),T);this.firstNode=i.get(this.list.get()[0])??null})}};function ce(e,t,n){return new F(e,t,n)}var F=class extends u{#t;#n;#e;constructor(t,n,i){super(),this.#t=t,this.#n=n,this.#e=i}run(t){let n,i;m(()=>{let l=y(this);this.#t.get()?(n||(n=this.#n()),c.resolveCallbacks(t,n),this.firstNode=n,i?.remove(),t.insertBefore(n,l)):(i||(i=this.#e?.()),i&&c.resolveCallbacks(t,i),this.firstNode=i??null,n?.remove(),i&&t.insertBefore(i,l))})}};function W(e,t,n){return Array.isArray(t)?new P(e,t,n):W(e,Object.keys(t).map(i=>({case:i,show:t[i]})),n)}var P=class extends u{#t;#n;#e;constructor(t,n,i){super(),this.#t=t,this.#n=n,this.#e=i}run(t){let n=new Map,i=new Map;for(let f of this.#n)i.set(f.case,f);let r,l,a=f=>{let T=i.get(f);if(T){if(!n.has(f)){let s=T.show();n.set(f,s)}return n.get(f)}return this.#e&&!l&&(l=this.#e()),l};m(()=>{let f=this.#t.get(),T=y(this),s=a(f);s&&c.resolveCallbacks(t,s),r?.remove(),s&&t.insertBefore(s,T),r=s})}};function jt(e){return new Promise(t=>setTimeout(t,e))}export{I as Computed,u as ControlFlow,_e as FlexDiv,ae as For,o as Html,ce as If,x as Modify,Ne as ModifyAll,ke as ModifyAsync,p as Signal,z as State,Re as Svg,W as Switch,Be as Tag,st as a,L as applyStringOrSignal,ft as audio,rt as b,lt as blockquote,et as br,We as button,mt as canvas,R as div,k as findData,Tt as form,Ae as h1,$e as h2,Oe as h3,Ue as h4,je as h5,Ve as h6,xt as hr,Et as iframe,dt as img,Je as input,ot as label,at as li,ht as main,ct as ol,Ze as option,qe as p,Ke as section,Ye as select,jt as sleep,Ge as span,Qe as style,gt as table,yt as tbody,it as td,Xe as textarea,tt as th,nt as tr,ut as ul,_ as useBinding,U as useComputed,m as useEffect,ye as useState,pt as video,b as waitForData};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tagu-tagu",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "A lightweight helper for vanilla `HTMLElement`, with reactivity.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"front-end",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"watch": "tsx --watch scripts/watch.ts"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@biomejs/biome": "2.3.
|
|
33
|
+
"@biomejs/biome": "2.3.10",
|
|
34
34
|
"@vitest/browser-playwright": "^4.0.15",
|
|
35
35
|
"esbuild": "^0.27.2",
|
|
36
36
|
"tsx": "^4.21.0",
|
package/src/signal/Signal.ts
CHANGED
|
@@ -46,8 +46,20 @@ export class Computed<T> extends Signal<T> {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export
|
|
50
|
-
|
|
49
|
+
export interface Effect {
|
|
50
|
+
onCleanup(callback: () => void): void;
|
|
51
|
+
}
|
|
52
|
+
export function useEffect(effectCallback: (effect: Effect) => void) {
|
|
53
|
+
let cleanup: () => void;
|
|
54
|
+
const effect = new Computed<void>(() => {
|
|
55
|
+
cleanup?.();
|
|
56
|
+
const e = {
|
|
57
|
+
onCleanup(cb) {
|
|
58
|
+
cleanup = cb;
|
|
59
|
+
},
|
|
60
|
+
} satisfies Effect;
|
|
61
|
+
effectCallback(e);
|
|
62
|
+
});
|
|
51
63
|
effect.get();
|
|
52
64
|
}
|
|
53
65
|
|