tagu-tagu 3.5.1 → 4.0.0-alpha.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 +1 -1
- package/src/Modify.ts +82 -14
package/dist/bundle.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var b=class{node2Data=new WeakMap;addCallbacks(e,n){if(!n)return;this.node2DescendantCallbacks.has(e)||this.node2DescendantCallbacks.set(e,{});let
|
|
1
|
+
var b=class{node2Data=new WeakMap;addCallbacks(e,n){if(!n)return;this.node2DescendantCallbacks.has(e)||this.node2DescendantCallbacks.set(e,{});let i=this.node2DescendantCallbacks.get(e);D(i,n);let o=this.node2Data.get(e);k(i,o)}setDataRecord(e,n){n&&this.node2Data.set(e,n)}resolveCallbacks(e,n){let i=(s,l)=>{if(k(l,this.node2Data.get(s)),!!Object.keys(l).length){if(!s.parentElement){this.node2DescendantCallbacks.has(s)||this.node2DescendantCallbacks.set(s,{});let m=this.node2DescendantCallbacks.get(s);m&&D(m,l);return}i(s.parentElement,l)}},o=this.node2DescendantCallbacks.get(n);o&&i(e,o)}node2DescendantCallbacks=new WeakMap};function k(t,e){for(let n in e)if(n in t){for(let i of t[n])i(e[n]);delete t[n]}}var c=new b;function H(t,e){c.setDataRecord(t,e)}function O(t){if(!t)return;let e={};for(let n in t){let i=t[n];e[n]=[i]}if(Object.keys(e).length)return e}function D(t,e){for(let n in e)t[n]||(t[n]=[]),t[n].push(...e[n])}function w(t,e){if(!t)return;let n=c.node2Data.get(t);return n&&e in n?n[e]:w(t.parentElement,e)}function h(t,e){if(typeof e=="string")return j(t,e);c.addCallbacks(t,O(e))}function j(t,e){return new Promise(n=>{let i=w(t,e);i!==void 0?n(i):c.addCallbacks(t,{[e]:[n]})})}function q(t,e=n=>n){return new T(t,e)}var T=class{constructor(e,n){this.key=e;this.map=n}};var f=class{next=null;firstNode=null};var d=class{#t;constructor(e){this.#t=e}get=()=>this.#t;set(e){this.#t=e,this.#n("change")}#n(e){this.#e.dispatchEvent(new Event(e))}#e=new EventTarget;on(e,n){this.#e.addEventListener(e,n)}};function R(t,e){return typeof e=="function"?Array.isArray(t)?z(t,e):z([t],()=>e(t.get())):new d(t)}function z(t,e){let n=new d(e()),i=()=>{n.set(e())};for(let o of t)o.on("change",i);return n}function B(t,e){let n=K(e);W(n);for(let i of n)V(t,i)}function V(t,e){e instanceof f?e.run(t):(c.resolveCallbacks(t,e),t.appendChild(e))}function K(t){return t.map(e=>{if(typeof e=="string"||e instanceof d){let n=document.createTextNode("");return v(e,i=>{n.textContent=i}),n}return e})}function W(t){for(let e=0;e<t.length;e++){let n=t[e];n instanceof f&&(n.next=t[e+1]??null)}}function F(t){let e=t.next;return e===null?null:e instanceof Node?e:e.firstNode?e.firstNode:F(e)}function g(t){let e=F(t);return e?.parentElement?e:null}function v(t,e){if(typeof t=="string")e(t);else if(t instanceof d){let n=()=>{e(t.get())};n(),t.on("change",n)}else e(t)}function x(t,e,n){e instanceof T?h(t,{[e.key]:i=>{let s=i instanceof d?R([i],()=>e.map(i.get())):e.map(i);v(s,n)}}):v(e,n)}function G(t,e){e!==void 0&&x(t,e,n=>{t.innerHTML=n})}function A(t,e){e!==void 0&&x(t,e,n=>{t.textContent=n})}function U(t,e){let n=t.style;if(n instanceof CSSStyleDeclaration)for(let i in e){let o=e[i];x(t,o,s=>n.setProperty(i,s))}}function Q(t,e){for(let n in e){let i=e[n];x(t,i,o=>{o?t.setAttribute(n,o):t.removeAttribute(n)})}}function _(t,e){for(let n in e){let i=e[n];x(t,i,o=>{t[n]=o})}}function J(t,e){for(let n in e){let i=t.querySelector(n);i&&C(i,e[n])}}function X(t,e){for(let n in e){let i=t.querySelectorAll(n);for(let o of i)C(o,e[n])}}function Y(t,e){for(let n in e){let o=e[n];o&&(typeof o=="function"?t.addEventListener(n,o):o instanceof T?h(t,{[o.key]:s=>{let l=o.map(s);t.addEventListener(n,l)}}):t.addEventListener(n,o.listener,o.options))}}function P(t,e){G(t,e.html),A(t,e.text),Q(t,e.attr),_(t,e.prop),U(t,e.css),J(t,e.$),X(t,e.$$),Y(t,e.on),H(t,e.data)}function Z(t,e){let n={};for(let s in e.css){let l=e.css[s];typeof l=="string"&&(n[s]=l),l instanceof d&&(n[s]=l.get())}let i=e.animate;return i&&typeof i!="number"&&(i.duration??=400,i.easing??="swing",i.easing=i.easing==="swing"?"ease-in-out":i.easing),t.animate([{},n],i).finished.then(()=>P(t,e))}function C(t,e){if(t)if(typeof e=="string"||e instanceof d)A(t,e);else if(Array.isArray(e))B(t,e);else if(typeof e=="function"){let n=e(t);if(n instanceof Promise)return n}else{if(e.animate!==void 0)return Z(t,e);P(t,e)}}function y(t,...e){let n=typeof t=="string"?document.querySelector(t):t;return(async()=>{for(let i of e){let o=C(n,i);o&&await o}})(),n}function yt(t,...e){for(let n of document.querySelectorAll(t))y(n,...e)}function xt(t,...e){return new Promise(n=>{y(t,...e,i=>{n(i)})})}function bt(t,...e){let n=document.createElementNS("http://www.w3.org/2000/svg",t);return y(n,...e)}function r(t,...e){let n=document.createElement(t);return y(n,...e),n}function wt(t,...e){let n=I({html:t}).children[0];return y(n,...e)}function Lt(...t){return r("h1",...t)}function Mt(...t){return r("h2",...t)}function Nt(...t){return r("h3",...t)}function kt(...t){return r("h4",...t)}function Dt(...t){return r("h5",...t)}function Ht(...t){return r("h6",...t)}function zt(...t){return r("p",...t)}function Rt(...t){return r("section",...t)}function Bt(...t){return r("button",...t)}function Ft(...t){return r("span",...t)}function At(t){function e(n,i){return`${n} {${Object.keys(i).map(o=>`${o}: ${i[o]};`).join("")}}`}return r("style",[Object.keys(t).map(n=>e(n,t[n])).join("")])}function I(...t){return r("div",...t)}function Pt(...t){return I({css:{display:"flex"}},...t)}function $t(...t){return r("input",...t)}function Ot(...t){return r("textarea",...t)}function jt(...t){return r("select",...t)}function qt(...t){return r("option",...t)}function Vt(...t){return r("br",...t)}function Kt(...t){return r("th",...t)}function Wt(...t){return r("tr",...t)}function Gt(...t){return r("td",...t)}function Ut(...t){return r("b",...t)}function Qt(...t){return r("label",...t)}function _t(...t){return r("a",...t)}function Jt(...t){return r("blockquote",...t)}function Xt(...t){return r("li",...t)}function Yt(...t){return r("ol",...t)}function Zt(...t){return r("ul",...t)}function te(...t){return r("audio",...t)}function ee(...t){return r("video",...t)}function ne(...t){return r("img",...t)}function ie(...t){return r("canvas",...t)}function oe(...t){return r("iframe",...t)}function re(...t){return r("form",...t)}function ae(...t){return r("table",...t)}function se(...t){return r("tbody",...t)}function le(...t){return r("hr",...t)}function ce(...t){return r("main",...t)}function tt(t,e){return new L(t,e)}var L=class extends f{constructor(n,i){super();this.list=n;this.map=i}run(n){let i=new Map,o=new Map,s=()=>{let l=[];for(let a of this.list.get())i.has(a)||l.push(a);let m=[],u=new Set(this.list.get());for(let a of o.keys()){let p=o.get(a);p&&!u.has(p)&&m.push(a)}for(let a of l){let p=this.map(a),S=typeof p=="string"?document.createTextNode(p):p;c.resolveCallbacks(n,S),o.set(S,a),i.set(a,S)}for(let a of m){a.parentNode?.removeChild(a);let p=o.get(a);o.delete(a),p&&i.delete(p)}for(let a of[...o.keys()])a.parentElement?.removeChild(a);let E=g(this);for(let a of this.list.get())n.insertBefore(i.get(a),E);this.firstNode=i.get(this.list.get()[0])??null};s(),this.list.on("change",()=>{s()})}};function et(t,e,n){return new M(t,e,n)}var M=class extends f{#t;#n;#e;constructor(e,n,i){super(),this.#t=e,this.#n=n,this.#e=i}run(e){let n,i,o=()=>{let s=g(this);this.#t.get()?(n||(n=this.#n()),c.resolveCallbacks(e,n),this.firstNode=n,i?.remove(),e.insertBefore(n,s)):(i||(i=this.#e?.()),i&&c.resolveCallbacks(e,i),this.firstNode=i??null,n?.remove(),i&&e.insertBefore(i,s))};o(),this.#t.on("change",o)}};function $(t,e,n){return Array.isArray(e)?new N(t,e,n):$(t,Object.keys(e).map(i=>({case:i,show:e[i]})),n)}var N=class extends f{#t;#n;#e;constructor(e,n,i){super(),this.#t=e,this.#n=n,this.#e=i}run(e){let n=new Map,i=new Map;for(let u of this.#n)i.set(u.case,u);let o,s,l=u=>{let E=i.get(u);if(E){if(!n.has(u)){let a=E.show();n.set(u,a)}return n.get(u)}return this.#e&&!s&&(s=this.#e()),s},m=()=>{let u=this.#t.get(),E=g(this),a=l(u);a&&c.resolveCallbacks(e,a),o?.remove(),a&&e.insertBefore(a,E),o=a};m(),this.#t.on("change",m)}};export{f as ControlFlow,Pt as FlexDiv,tt as For,r as Html,et as If,y as Modify,yt as ModifyAll,xt as ModifyAsync,d as State,bt as Svg,$ as Switch,wt as Tag,_t as a,v as applyStringOrState,te as audio,Ut as b,Jt as blockquote,Vt as br,Bt as button,ie as canvas,I as div,w as findData,re as form,Lt as h1,Mt as h2,Nt as h3,kt as h4,Dt as h5,Ht as h6,le as hr,oe as iframe,ne as img,$t as input,Qt as label,Xt as li,ce as main,Yt as ol,qt as option,zt as p,Rt as section,jt as select,Ft as span,At as style,ae as table,se as tbody,Gt as td,Ot as textarea,Kt as th,Wt as tr,Zt as ul,q as useBinding,R as useState,ee as video,h as waitForData};
|
package/package.json
CHANGED
package/src/Modify.ts
CHANGED
|
@@ -33,6 +33,12 @@ type ElementPropertyInitializer<TEventType2Event> = {
|
|
|
33
33
|
$?: $Record;
|
|
34
34
|
$$?: $Record;
|
|
35
35
|
data?: DataRecord;
|
|
36
|
+
animate?: number | AnimationOptions;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type AnimationOptions = {
|
|
40
|
+
duration?: number;
|
|
41
|
+
easing?: string;
|
|
36
42
|
};
|
|
37
43
|
|
|
38
44
|
export type ElementInitializer<
|
|
@@ -43,7 +49,7 @@ export type ElementInitializer<
|
|
|
43
49
|
| State
|
|
44
50
|
| ElementPropertyInitializer<TEventType2Event>
|
|
45
51
|
| ChildType[]
|
|
46
|
-
| ((element: TElement) =>
|
|
52
|
+
| ((element: TElement) => any);
|
|
47
53
|
|
|
48
54
|
export function applyStringOrState(
|
|
49
55
|
value: string | State,
|
|
@@ -190,6 +196,56 @@ function initializeEventListeners<TEventType2Event>(
|
|
|
190
196
|
}
|
|
191
197
|
}
|
|
192
198
|
|
|
199
|
+
function initializePropertyInitializerWithoutAnimation<
|
|
200
|
+
TElement extends Element,
|
|
201
|
+
TEventType2Event,
|
|
202
|
+
>(
|
|
203
|
+
element: TElement,
|
|
204
|
+
initializer: ElementPropertyInitializer<TEventType2Event>,
|
|
205
|
+
) {
|
|
206
|
+
initializeHtml(element, initializer.html);
|
|
207
|
+
initializeText(element, initializer.text);
|
|
208
|
+
initializeAttributes(element, initializer.attr);
|
|
209
|
+
initializeProps(element, initializer.prop);
|
|
210
|
+
initializeStyle(element, initializer.css);
|
|
211
|
+
initialize$(element, initializer.$);
|
|
212
|
+
initialize$$(element, initializer.$$);
|
|
213
|
+
initializeEventListeners(element, initializer.on);
|
|
214
|
+
initializeData(element, initializer.data);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function initializePropertyInitializerWithAnimation<
|
|
218
|
+
TElement extends Element,
|
|
219
|
+
TEventType2Event,
|
|
220
|
+
>(
|
|
221
|
+
element: TElement,
|
|
222
|
+
initializer: ElementPropertyInitializer<TEventType2Event>,
|
|
223
|
+
) {
|
|
224
|
+
const css = {} as Record<string, string>;
|
|
225
|
+
for (const key in initializer.css) {
|
|
226
|
+
const value = initializer.css[key];
|
|
227
|
+
if (typeof value === "string") {
|
|
228
|
+
css[key] = value;
|
|
229
|
+
}
|
|
230
|
+
if (value instanceof State) {
|
|
231
|
+
css[key] = value.get();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const options = initializer.animate;
|
|
236
|
+
if (options && typeof options !== "number") {
|
|
237
|
+
options.duration ??= 400;
|
|
238
|
+
options.easing ??= "swing";
|
|
239
|
+
options.easing =
|
|
240
|
+
options.easing === "swing" ? "ease-in-out" : options.easing;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const animation = element.animate([{}, css], options);
|
|
244
|
+
return animation.finished.then(() =>
|
|
245
|
+
initializePropertyInitializerWithoutAnimation(element, initializer),
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
193
249
|
function initialize<TElement extends Element, TEventType2Event>(
|
|
194
250
|
element: TElement | null,
|
|
195
251
|
initializer: ElementInitializer<TElement, TEventType2Event>,
|
|
@@ -200,17 +256,13 @@ function initialize<TElement extends Element, TEventType2Event>(
|
|
|
200
256
|
} else if (Array.isArray(initializer)) {
|
|
201
257
|
initializeChildBlock(element, initializer);
|
|
202
258
|
} else if (typeof initializer === "function") {
|
|
203
|
-
initializer(element);
|
|
259
|
+
const result = initializer(element);
|
|
260
|
+
if (result instanceof Promise) return result;
|
|
204
261
|
} else {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
initializeStyle(element, initializer.css);
|
|
210
|
-
initialize$(element, initializer.$);
|
|
211
|
-
initialize$$(element, initializer.$$);
|
|
212
|
-
initializeEventListeners(element, initializer.on);
|
|
213
|
-
initializeData(element, initializer.data);
|
|
262
|
+
if (initializer.animate !== undefined) {
|
|
263
|
+
return initializePropertyInitializerWithAnimation(element, initializer);
|
|
264
|
+
}
|
|
265
|
+
initializePropertyInitializerWithoutAnimation(element, initializer);
|
|
214
266
|
}
|
|
215
267
|
}
|
|
216
268
|
|
|
@@ -222,9 +274,14 @@ export function Modify<T extends Element>(
|
|
|
222
274
|
typeof elementOrSelector === "string"
|
|
223
275
|
? (document.querySelector(elementOrSelector) as T)
|
|
224
276
|
: elementOrSelector;
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
277
|
+
|
|
278
|
+
(async () => {
|
|
279
|
+
for (const initializer of initializers) {
|
|
280
|
+
const animation = initialize(element, initializer);
|
|
281
|
+
if (animation) await animation;
|
|
282
|
+
}
|
|
283
|
+
})();
|
|
284
|
+
|
|
228
285
|
return element;
|
|
229
286
|
}
|
|
230
287
|
|
|
@@ -236,3 +293,14 @@ export function ModifyAll(
|
|
|
236
293
|
Modify<Element>(element, ...initializers);
|
|
237
294
|
}
|
|
238
295
|
}
|
|
296
|
+
|
|
297
|
+
export function ModifyAsync<T extends Element>(
|
|
298
|
+
elementOrSelector: T | string,
|
|
299
|
+
...initializers: ElementInitializer<T>[]
|
|
300
|
+
) {
|
|
301
|
+
return new Promise<T>((resolve) => {
|
|
302
|
+
Modify(elementOrSelector, ...initializers, (e) => {
|
|
303
|
+
resolve(e);
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
}
|