tagu-tagu 4.2.1 → 4.3.1
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 +1 -1
- package/src/flow/Await.ts +59 -0
- package/src/flow/index.ts +1 -0
package/dist/bundle.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var k=class{node2Data=new WeakMap;addCallbacks(t,n){if(!n)return;this.node2DescendantCallbacks.has(t)||this.node2DescendantCallbacks.set(t,{});let i=this.node2DescendantCallbacks.get(t);j(i,n);let r=this.node2Data.get(t);$(i,r)}setDataRecord(t,n){n&&this.node2Data.set(t,n)}resolveCallbacks(t,n){let i=(l,a)=>{if($(a,this.node2Data.get(l)),!!Object.keys(a).length){if(!l.parentElement){this.node2DescendantCallbacks.has(l)||this.node2DescendantCallbacks.set(l,{});let m=this.node2DescendantCallbacks.get(l);m&&j(m,a);return}i(l.parentElement,a)}},r=this.node2DescendantCallbacks.get(n);r&&i(t,r)}node2DescendantCallbacks=new WeakMap};function $(e,t){for(let n in t)if(n in e){for(let i of e[n])i(t[n]);delete e[n]}}var u=new k;function O(e,t){u.setDataRecord(e,t)}function Q(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 j(e,t){for(let n in t)e[n]||(e[n]=[]),e[n].push(...t[n])}function z(e,t){if(!e)return;let n=u.node2Data.get(e);return n&&t in n?n[t]:z(e.parentElement,t)}function b(e,t){if(typeof t=="string")return _(e,t);u.addCallbacks(e,Q(t))}function _(e,t){return new Promise(n=>{let i=z(e,t);i!==void 0?n(i):u.addCallbacks(e,{[t]:[n]})})}function J(e,t=n=>n){return new g(e,t)}var g=class{constructor(t,n){this.key=t;this.map=n}};var f=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()}},H=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 T(e){let t;new I(()=>{t?.(),e({onCleanup(r){t=r}})}).get()}function U(e){return new H(e)}function V(e){return new I(e)}function q(e,t){let n=Y(t);Z(n);for(let i of n)X(e,i)}function X(e,t){t instanceof f?t.run(e):(u.resolveCallbacks(e,t),e.appendChild(t))}function Y(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 Z(e){for(let t=0;t<e.length;t++){let n=e[t];n instanceof f&&(n.next=e[t+1]??null)}}function K(e){let t=e.next;return t===null?null:t instanceof Node?t:t.firstNode?t.firstNode:K(t)}function y(e){let t=K(e);return t?.parentElement?t:null}function L(e,t){typeof e=="string"?t(e):e instanceof p?T(()=>t(e.get())):t(e)}function v(e,t,n){t instanceof g?b(e,{[t.key]:i=>{let l=i instanceof p?V(()=>t.map(i.get())):t.map(i);L(l,n)}}):L(t,n)}function ee(e,t){t!==void 0&&v(e,t,n=>{e.innerHTML=n})}function W(e,t){t!==void 0&&v(e,t,n=>{e.textContent=n})}function te(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 ne(e,t){for(let n in t){let i=t[n];v(e,i,r=>{r?e.setAttribute(n,r):e.removeAttribute(n)})}}function ie(e,t){for(let n in t){let i=t[n];v(e,i,r=>{e[n]=r})}}function re(e,t){let n=[];for(let i in t){let r=e.querySelector(i);r&&n.push(D(r,t[i]))}return R(n)}function R(e){let t=e.filter(n=>n instanceof Promise);if(t.length!==0)return Promise.all(t)}function oe(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 R(n)}function le(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 G(e,t){ee(e,t.html),W(e,t.text),ne(e,t.attr),ie(e,t.prop),te(e,t.css);let n=re(e,t.$),i=oe(e,t.$$);return le(e,t.on),O(e,t.data),R([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(()=>G(e,t))}function ae(e,t){return t.animate!==void 0?se(e,t):G(e,t)}function D(e,t){if(e)if(typeof t=="string"||t instanceof p)W(e,t);else if(Array.isArray(t))q(e,t);else if(typeof t=="function"){let n=t(e);if(n instanceof Promise)return n}else return ae(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 ke(e,...t){for(let n of document.querySelectorAll(e))x(n,...t)}function ze(e,...t){return new Promise(n=>{x(e,...t,i=>{n(i)})})}function Fe(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=F({html:e}).children[0];return x(n,...t)}function $e(...e){return o("h1",...e)}function je(...e){return o("h2",...e)}function Oe(...e){return o("h3",...e)}function Ue(...e){return o("h4",...e)}function Ve(...e){return o("h5",...e)}function qe(...e){return o("h6",...e)}function Ke(...e){return o("p",...e)}function We(...e){return o("section",...e)}function Ge(...e){return o("button",...e)}function Qe(...e){return o("span",...e)}function _e(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 F(...e){return o("div",...e)}function Je(...e){return F({css:{display:"flex"}},...e)}function Xe(...e){return o("input",...e)}function Ye(...e){return o("textarea",...e)}function Ze(...e){return o("select",...e)}function et(...e){return o("option",...e)}function tt(...e){return o("br",...e)}function nt(...e){return o("th",...e)}function it(...e){return o("tr",...e)}function rt(...e){return o("td",...e)}function ot(...e){return o("b",...e)}function lt(...e){return o("label",...e)}function st(...e){return o("a",...e)}function at(...e){return o("blockquote",...e)}function ct(...e){return o("li",...e)}function ut(...e){return o("ol",...e)}function ft(...e){return o("ul",...e)}function pt(...e){return o("audio",...e)}function dt(...e){return o("video",...e)}function mt(...e){return o("img",...e)}function Et(...e){return o("canvas",...e)}function Tt(...e){return o("iframe",...e)}function gt(...e){return o("form",...e)}function yt(...e){return o("table",...e)}function xt(...e){return o("tbody",...e)}function ht(...e){return o("hr",...e)}function vt(...e){return o("main",...e)}function M(e,t,n){return Array.isArray(t)?new B(e,t,n):M(e,Object.keys(t).map(i=>({case:i,show:t[i]})),n)}var B=class extends f{#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 c of this.#n)i.set(c.case,c);let r,l,a=c=>{let d=i.get(c);if(d){if(!n.has(c)){let s=d.show();n.set(c,s)}return n.get(c)}return this.#e&&!l&&(l=this.#e()),l};T(()=>{let c=this.#t.get(),d=y(this),s=a(c);s&&u.resolveCallbacks(t,s),r?.remove(),s&&t.insertBefore(s,d),r=s})}};function ce(e,t){let n="pending",i="fulfilled",r="rejected",l=U(n),a,m;e.then(d=>{a=d,l.set(i)}).catch(d=>{m=d,l.set(r)});let c={};return t?.pending&&(c[n]=t.pending),c[i]=()=>t?.fulfilled?.(a)??a,t?.rejected&&(c[r]=()=>t.rejected(m)),M(l,c)}function ue(e,t){return new A(e,t)}var A=class extends f{constructor(n,i){super();this.list=n;this.map=i}run(n){let i=new Map,r=new Map;T(()=>{let a=[];for(let s of this.list.get())i.has(s)||a.push(s);let m=[],c=new Set(this.list.get());for(let s of r.keys()){let E=r.get(s);E&&!c.has(E)&&m.push(s)}for(let s of a){let E=this.map(s),N=typeof E=="string"?document.createTextNode(E):E;u.resolveCallbacks(n,N),r.set(N,s),i.set(s,N)}for(let s of m){s.parentNode?.removeChild(s);let E=r.get(s);r.delete(s),E&&i.delete(E)}for(let s of[...r.keys()])s.parentElement?.removeChild(s);let d=y(this);for(let s of this.list.get())n.insertBefore(i.get(s),d);this.firstNode=i.get(this.list.get()[0])??null})}};function fe(e,t,n){return new P(e,t,n)}var P=class extends f{#t;#n;#e;constructor(t,n,i){super(),this.#t=t,this.#n=n,this.#e=i}run(t){let n,i;T(()=>{let l=y(this);this.#t.get()?(n||(n=this.#n()),u.resolveCallbacks(t,n),this.firstNode=n,i?.remove(),t.insertBefore(n,l)):(i||(i=this.#e?.()),i&&u.resolveCallbacks(t,i),this.firstNode=i??null,n?.remove(),i&&t.insertBefore(i,l))})}};function Gt(e){return new Promise(t=>setTimeout(t,e))}export{ce as Await,I as Computed,f as ControlFlow,Je as FlexDiv,ue as For,o as Html,fe as If,x as Modify,ke as ModifyAll,ze as ModifyAsync,p as Signal,H as State,Fe as Svg,M as Switch,Be as Tag,st as a,L as applyStringOrSignal,pt as audio,ot as b,at as blockquote,tt as br,Ge as button,Et as canvas,F as div,z as findData,gt as form,$e as h1,je as h2,Oe as h3,Ue as h4,Ve as h5,qe as h6,ht as hr,Tt as iframe,mt as img,Xe as input,lt as label,ct as li,vt as main,ut as ol,et as option,Ke as p,We as section,Ze as select,Gt as sleep,Qe as span,_e as style,yt as table,xt as tbody,rt as td,Ye as textarea,nt as th,it as tr,ft as ul,J as useBinding,V as useComputed,T as useEffect,U as useState,dt as video,b as waitForData};
|
package/package.json
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useState } from "../signal/Signal";
|
|
2
|
+
import type { ControlFlow } from "./ControlFlow";
|
|
3
|
+
import { Switch } from "./Switch";
|
|
4
|
+
|
|
5
|
+
export function Await(
|
|
6
|
+
promise: Promise<Element>,
|
|
7
|
+
options?: {
|
|
8
|
+
pending?: () => Element;
|
|
9
|
+
rejected?: (error: any) => Element;
|
|
10
|
+
},
|
|
11
|
+
): ControlFlow;
|
|
12
|
+
export function Await<T>(
|
|
13
|
+
promise: Promise<T>,
|
|
14
|
+
options?: {
|
|
15
|
+
pending?: () => Element;
|
|
16
|
+
fulfilled: (value: T) => Element;
|
|
17
|
+
rejected?: (error: any) => Element;
|
|
18
|
+
},
|
|
19
|
+
): ControlFlow;
|
|
20
|
+
export function Await<T>(
|
|
21
|
+
promise: Promise<T>,
|
|
22
|
+
options?: {
|
|
23
|
+
pending?: () => Element;
|
|
24
|
+
fulfilled?: (value: T) => Element;
|
|
25
|
+
rejected?: (error: any) => Element;
|
|
26
|
+
},
|
|
27
|
+
) {
|
|
28
|
+
const pending = "pending";
|
|
29
|
+
const fulfilled = "fulfilled";
|
|
30
|
+
const rejected = "rejected";
|
|
31
|
+
const promiseState = useState(pending);
|
|
32
|
+
|
|
33
|
+
let value: T;
|
|
34
|
+
let error: any;
|
|
35
|
+
promise
|
|
36
|
+
.then((v) => {
|
|
37
|
+
value = v;
|
|
38
|
+
promiseState.set(fulfilled);
|
|
39
|
+
})
|
|
40
|
+
.catch((reason) => {
|
|
41
|
+
error = reason;
|
|
42
|
+
promiseState.set(rejected);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const switchOptions = {} as Record<string, () => Element>;
|
|
46
|
+
|
|
47
|
+
if (options?.pending) {
|
|
48
|
+
switchOptions[pending] = options.pending;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
switchOptions[fulfilled] = () =>
|
|
52
|
+
options?.fulfilled?.(value) ?? (value as Element);
|
|
53
|
+
|
|
54
|
+
if (options?.rejected) {
|
|
55
|
+
switchOptions[rejected] = () => options.rejected!(error);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return Switch(promiseState, switchOptions);
|
|
59
|
+
}
|
package/src/flow/index.ts
CHANGED