Comparing version 0.20.2 to 0.20.3
@@ -1,2 +0,2 @@ | ||
function e(e,t){e.cursor[t].prev&&(e.cursor[t].prev.cursor[t].next=e.cursor[t].next),e.cursor[t].next&&(e.cursor[t].next.cursor[t].prev=e.cursor[t].prev),e.queue[t].last===e&&(e.queue[t].last=e.cursor[t].prev),e.queue[t].first===e&&(e.queue[t].first=e.cursor[t].next),e.cursor[t].prev=null,e.cursor[t].next=null}function t(e){var t,l;e.status='active',t=a(e),(l=e).cursor.prev&&(l.cursor.prev.cursor.next=l.cursor.next),l.cursor.next&&(l.cursor.next.cursor.prev=l.cursor.prev),t.last===l&&(t.last=l.cursor.prev),t.first===l&&(t.first=l.cursor.next),l.cursor.prev=null,l.cursor.next=null}function a(e){return e.group.activeChilds[e.priority]}function l(e,a){a.value.active=a.value.pending=e,'active'!==a.status&&t(a)}function n(l,n){if(n.value.active===l)return n.value.pending=l,void('pending'===n.status&&(t(n),a(n).first||e(n.group,n.priority)));var r,o,i,s;'active'===n.status&&(n.status='pending',a(n).first||((i=n.group).queue[s=n.priority].last?(i.cursor[s].prev=i.queue[s].last,i.queue[s].last.cursor[s].next=i,i.queue[s].last=i):i.queue[s].first=i.queue[s].last=i),o=n,(r=a(n)).last?(o.cursor.prev=r.last,r.last.cursor.next=o,r.last=o):r.first=r.last=o),n.value.pending=l,n.group.queue.rafID||(n.group.queue.rafID=ce(n.group.queue.execQueue))}function r(a){ie('execQueue');let l,n,r=ae(),o=0;e:for(;a.props.first||a.tree.first||a.data.first;){if(ae()-r>=1e3){o=1;break e}let i=!!a.props.first;for(i&&ie('props');l=a.props.first;){for(;n=l.activeChilds.props.first;){if(ae()-r>=1e3){o=1,se('props');break e}n.runOp(n.value.pending),n.value.active=n.value.pending,t(n)}e(l,'props')}i&&se('props');let s=!!a.tree.first;for(s&&ie('tree');l=a.tree.first;){for(;n=l.activeChilds.tree.first;){if(ae()-r>=1e3){o=1,se('tree');break e}n.runOp(n.value.pending),n.value.active=n.value.pending,t(n)}e(l,'tree')}s&&se('tree');let c=!!a.data.first;for(c&&ie('data');l=a.data.first;){for(;n=l.activeChilds.data.first;){if(ae()-r>=1e3){o=1,se('data');break e}n.runOp(n.value.pending),n.value.active=n.value.pending,t(n)}e(l,'data')}c&&se('data')}if(se('execQueue'),o)a.rafID=ce(a.execQueue);else if(a.rafID=null,a.onDrain){let e=a.onDrain;a.onDrain=null,e()}}function o({value:e,runOp:t,group:a,priority:l}){return{value:{active:e,pending:e},runOp:t,status:'active',priority:l,group:a,cursor:{prev:null,next:null}}}function i({onComplete:e}){let t={props:{first:null,last:null},tree:{first:null,last:null},data:{first:null,last:null},rafID:null,execQueue(){},onDrain:e};return t.execQueue=r.bind(null,t),t}function s(e){return{ops:[],queue:e,activeChilds:{props:{first:null,last:null},tree:{first:null,last:null},data:{first:null,last:null}},cursor:{props:{prev:null,next:null},tree:{prev:null,next:null},data:{prev:null,next:null}}}}function c({value:e,group:t,onInit:a,onChange:l}){let r=o({value:e,group:t,runOp(e){i.status='A',l(e)},priority:'data'}),i={status:'IA',value:r.value,ops:{init:o({value:0,group:t,runOp(e){i.status='A',a(i.value.active)},priority:'data'}),change:r,terminate:o({value:0,group:t,runOp(e){i.status='T'},priority:'data'})}};return n(1,i.ops.init),i}function u(e){switch(e.status){case'I':case'T':case'AT':return;case'A':e.status='AT',n(1,e.ops.terminate);break;case'AA':e.status='AT',n(1,e.ops.terminate),n(e.value.active,e.ops.change);break;case'IA':e.status='T',n(0,e.ops.init)}}function p(e,t){switch(t.status){case'I':case'T':return;case'A':t.value.active!==e&&(t.status='AA',n(e,t.ops.change));break;case'AA':t.value.active===e?(t.status='A',n(e,t.ops.change)):t.value.pending!==e&&(t.value.pending=e);break;case'IA':t.value.active=t.value.pending=e}}function d(e){switch(e=String(e)){case'__proto__':case'__defineGetter__':case'__defineSetter__':case'constructor':case'prototype':case'hasOwnProperty':case'toString':case'valueOf':case'setProperty':case'removeProperty':return'forbidden';default:return e.replace(/[^a-zA-Z0-9\-_]/g,'')}}function f(e,t){for(let a=0;a<t.length;a++){let{type:l,field:n,value:r}=t[a];ue[l](e,n,r)}}function v(e){return''!==e&&0!==e&&'0'!==e&&(0==e||null==e)}function m(e,t,a){v(a)?e.style.removeProperty(`--${t}`):e.style.setProperty(`--${t}`,`${a}`)}function h(e,t,a){v(a)?delete e.style[t]:e.style[t]=`${a}`}function g(e,t,a){v(a)?delete e.dataset[t]:e.dataset[t]=`${a}`}function b(e,t,a){if(v(a)){switch(t){case'value':delete e.value;break;case'checked':e.checked=0;break;case'spellcheck':if(0==a)return void e.setAttribute('spellcheck','false')}e.removeAttribute(t)}else{switch(t){case'value':e.value=`${a}`;break;case'checked':e.checked=`${a}`}e.setAttribute(t,`${a}`)}}function y(e,t){e.replaceData(0,(e.textContent||'').length,String(t))}function k({fn:e,state:t={},defer:a=0,name:l="",draft:n,isSvgRoot:r,namespace:o,env:i,isBlock:s=0}){let c=me,u={id:++fe,name:l,plain:[],watch:[],nameMap:{},pages:[],closure:[],childTemplates:[],handlers:de,upward:effector.step.filter({fn(e,t,a){if(!a.page){if(!a.parent||!a.parent.page)return 1;a.page=a.parent.page}if(!a.page.root.activeSpawns.has(a.page.fullID))return console.count('inactive page upward'),0;let l=[a.page.template],n=[a.page];{let e=a.page.parent;for(;e;)n.push(e),l.push(e.template),e=e.parent}return a.node.next.forEach((t=>{let r=t.meta.nativeTemplate;if(r)if(l.includes(r)){let o=n[l.indexOf(r)];effector.launch({target:t,params:e,defer:1,page:o,stack:a,scope:a.scope})}else console.error('context drift',{stack:a,node:t});else effector.launch({target:t,params:e,defer:1,page:a.page,stack:a,scope:a.scope})})),0}}),loader:effector.step.filter({fn(e,t,a){if(a.parent){let t=a.scope?a.scope.graphite.id:null;if(a.page){if(!a.page.root.activeSpawns.has(a.page.fullID))return console.count('inactive page loader'),0;if(a.page.template===u)return 1;if(a.page.root.childSpawns[a.page.fullID][u.id])a.page.root.childSpawns[a.page.fullID][u.id].forEach((l=>{(!t||l.root.scope&&t===l.root.scope.graphite.id)&&effector.launch({params:e,target:a.node,page:l,defer:1,scope:a.scope})}));else{let l=a.page.fullID,n='rec'===a.page.template.name;u.pages.forEach((r=>{if(!t||r.root.scope&&t===r.root.scope.graphite.id)if(r.fullID===l||r.fullID.startsWith(`${l}_`)){let t=1;if(n){let e=a.page.template.id,l=r.parent;for(;l&&l!==a.page;){if(l.template.id===e){t=0;break}l=l.parent}}t&&effector.launch({params:e,target:a.node,page:r,defer:1,scope:a.scope})}else l.startsWith(`${r.fullID}_`)&&effector.launch({params:e,target:a.node,page:a.page,defer:1,scope:a.scope})}))}}else u.pages.forEach((l=>{(!t||l.root.scope&&t===l.root.scope.graphite.id)&&effector.launch({params:e,target:a.node,page:l,defer:1,scope:a.scope})}));return 0}return 1}}),parent:c,node:null,api:null,trigger:{mount:effector.createEvent({named:'mount'})},draft:n,isSvgRoot:r,namespace:o,env:i,isBlock:s||!(!c||!c.isBlock)};c&&c.childTemplates.push(u);let p=effector.createNode({meta:{template:u}});return u.node=p,me=u,a?u.deferredInit=()=>{let a=me;me=u,u.deferredInit=null;try{effector.withRegion(p,(()=>{let a=effector.restore(t);u.api=e(a,u.trigger),u.nameMap=a}))}finally{me=a}}:effector.withRegion(p,(()=>{let a=effector.restore(t);u.api=e(a,u.trigger),u.nameMap=a})),me=c,u}function I(e,t){let a;switch(a=t?t.getState(e):e.current,e.type){case'list':return[...a];case'shape':return{...a};default:return a}}function x(e,t,a){let l=t;for(;l&&!ge(l,e);)l=l.parent;return l?ge(l,e):a?(a.getState(e),a.reg[e.id]):e}function w(e,t){ge(t,e)||(t.reg[e.id]=x(e,t.parent,t.root.scope))}function S(e,t,a){t in a||(a[t]=[]),a[t].push(...e)}function D(e,{values:t={},parentLeaf:a,mountNode:l,svgRoot:n,leafData:r,opGroup:o,domSubtree:i,hydration:s,root:c}){function u(e){if(e.before)for(let t=0;t<e.before.length;t++){let a=e.before[t];switch(a.type){case'map':{let t,l=a.from;if(!a.fn&&!l)break;l&&(w(l,f),t=d[l.id].current),d[e.id].current=a.fn?a.fn(t):t;break}case'field':{let t=a.from;w(t,f),d[e.id].current[a.field]=d[t.id].current;break}case'closure':w(a.of,f)}}}function p(e,t,a){let l;t.stop=1;try{for(;t.i<e.length;)l=e[t.i],t.i++,l.fn(a[l.of.id]?a[l.of.id].current:x(l.of,f.parent,f.root.scope).current)}catch(e){console.error(e),t.stop=0}}let d={},f={draft:e.draft,svgRoot:n,data:r,parent:a,hydration:s,mountNode:l,root:c,id:++ve,fullID:'',reg:d,template:e};e.pages.push(f);let v=he;he=f,a&&S([f],e.id,c.childSpawns[a.fullID]),f.fullID=a?`${a.fullID}_${f.id}`:`${f.id}`,c.childSpawns[f.fullID]={},c.activeSpawns.add(f.fullID),c.leafOps[f.fullID]={group:o,domSubtree:i};for(let t=0;t<e.closure.length;t++){let a=e.closure[t],l=a,n=f.parent;e:for(;n;){if(ge(n,a)){l=ge(n,a);break e}n=n.parent}!n&&c.scope&&(c.scope.getState(a),l=c.scope.reg[a.id]),d[a.id]=l}for(let t=0;t<e.plain.length;t++){let a=e.plain[t],l={id:a.id,current:I(a,c.scope)};d[a.id]=l}for(let a in t){let l=e.nameMap[a].stateRef.id;d[l]={id:l,current:t[a]}}e.closure.forEach(u),e.plain.forEach(u);let m={i:0,stop:0};for(;!m.stop;)p(e.watch,m,d);if(a)for(let e in c.childSpawns[f.fullID])S(c.childSpawns[f.fullID][e],e,c.childSpawns[a.fullID]);if(be)be.steps.push({target:e.trigger.mount,params:f,defer:1,page:f,scope:c.scope});else{let t;be={parent:be,steps:[{target:e.trigger.mount,params:f,defer:1,page:f,scope:c.scope}]};do{for(;t=be.steps.shift();)be={parent:be,steps:[]},effector.launch(t)}while(be=be.parent)}return he=v,f}function C(e){let t=e.parent;for(;'element'!==t.type&&'using'!==t.type;)t=t.parent;return t?t.value:null}function O(e){if(!e.visible)return null;switch(e.type){case'text':case'element':return e;case'LF':case'route':case'rec':case'recItem':case'block':case'blockItem':for(let t=e.child.length-1;t>=0;t--){let a=O(e.child[t]);if(a)return a}return null;case'list':{let t=e.lastChild;if(!t)return null;for(;t;){let e=O(t);if(e)return e;t=t.left}return null}default:return null}}function T(e){switch(e.type){case'using':return null;case'LF':{let t=e.left;for(;t;){let e=O(t);if(e)return e;t=t.left}return T(e.parent)}case'element':case'text':case'route':case'rec':case'recItem':case'block':case'blockItem':case'list':{let t=e.parent;for(let a=e.index-1;a>=0;a--){let e=t.child[a];if(!e)continue;let l=O(e);if(l)return l}switch(t.type){case'element':case'using':return null}return T(t)}default:return null}}function q(e){let t=T(e);return t?t.value:null}function R(e,t){if(!e)throw Error(t)}function A(e,t){if(!e)throw Error(`${t}() called outside from using() closure`)}function P(e){if(!me)return;let{draft:t}=e;if('listItem'!==t.type&&'rec'!==t.type)switch(me.draft.type){case'element':case'using':case'route':case'list':case'rec':case'recItem':case'block':case'blockItem':t.inParentIndex=me.draft.childCount,me.draft.childCount+=1,me.draft.childTemplates.push(e);break;default:console.warn(`unexpected currentTemplate type ${me.draft.type}`)}}function E(e,{parentBlockFragment:t,leaf:a,node:l,svgRoot:n,values:r}){e.childTemplates.forEach((e=>{N({parentBlockFragment:t,leaf:a,node:l,svgRoot:n,values:r,actor:e})}))}function N({parentBlockFragment:e,leaf:t,node:a=t.mountNode,actor:l,svgRoot:n,values:r}){let i;R(ye.includes(e.type),`incorrect parent ${e.type}`);let{draft:c}=l,{queue:u}=t.root.leafOps[t.fullID].group,p=s(u),d=t.root.leafOps[t.fullID].domSubtree,v=d;switch(c.type){case'route':{let t={type:'route',parent:e,child:[],visible:0,index:c.inParentIndex};e.child[c.inParentIndex]=t,i={type:'route',block:t,ops:{},initialized:0,pendingInit:null};break}case'element':{let a;if(l.isBlock){let e,l,n=t;for(;n&&(!l||!e);){n.template.env&&(e=n.template.env);let{draft:t}=n;'element'===t.type&&('svg'===t.tag?l='svg':'foreignObject'===t.tag&&(l='html')),n=n.parent}l||(l='html'),e&&(a='svg'===l?e.document.createElementNS('http://www.w3.org/2000/svg',c.tag):e.document.createElement(c.tag),f(a,c.staticSeq))}else a=c.stencil.cloneNode();let n={type:'element',parent:e,child:[],value:a,visible:0,index:c.inParentIndex};e.child[c.inParentIndex]=n,i={type:'element',block:n,ops:{visible:o({value:0,priority:'tree',runOp(e){if(e){M(n);let e=i;e.needToCallNode&&(e.needToCallNode=0,effector.launch({target:ke,params:{element:n.value,fns:c.node},page:m,scope:t.root.scope})),n.visible=1}else n.value.remove(),n.visible=0},group:d})},needToCallNode:c.node.length>0},v=s(u);break}case'list':{let t={type:'list',parent:e,child:[],lastChild:null,visible:1,index:c.inParentIndex};e.child[c.inParentIndex]=t,i={type:'list',draft:c,block:t,records:[],pendingUpdate:null};break}case'using':case'listItem':break;case'rec':{let t={type:'rec',parent:e,child:[],visible:1,index:c.inParentIndex};e.child[c.inParentIndex]=t,i={type:'rec',block:t};break}case'recItem':{let t={type:'recItem',parent:e,child:[],visible:1,index:c.inParentIndex};e.child[c.inParentIndex]=t,i={type:'rec item',block:t};break}case'block':{let t={type:'block',parent:e,child:[],visible:1,index:c.inParentIndex};e.child[c.inParentIndex]=t,i={type:'block',block:t};break}case'blockItem':{let t={type:'blockItem',parent:e,child:[],visible:1,index:c.inParentIndex};e.child[c.inParentIndex]=t,i={type:'block item',block:t};break}default:console.warn(`unexpected draft type ${c.type}`)}let m=D(l,{values:r,parentLeaf:t,mountNode:a,svgRoot:n||t.svgRoot,leafData:i,opGroup:p,domSubtree:v,hydration:t.hydration,root:t.root})}function M(e){let t=q(e);t?t.after(e.value):C(e).prepend(e.value),e.visible=1}function B({mount:e,state:t,onMount:a,onState:l}){return{onMount:effector.sample({source:t,clock:e,fn:a,greedy:1}),onState:effector.sample({source:e,clock:t,fn:l,greedy:1})}}function F(e,t){for(let a in e)t(e[a],a)}function _(e,t){if(!me)return;let a=me.draft;R('element'===a.type,`"handler" extension can be used only with element nodes, got "${a.type}"`),void 0===t&&(t=e,e={});for(let e in t)R(effector.is.unit(t[e]),`handler for "${e}" should be event`);let{passive:l=0,capture:n=0,prevent:r=0,stop:o=0}=e;a.handler.push({options:{prevent:r,stop:o},domConfig:{passive:r?0:l,capture:n},map:t})}function $(e){A(me,'spec');let t=me.draft;switch(t.type){case'list':return void(e.visible&&(t.itemVisible=e.visible));case'listItem':case'using':case'route':case'rec':case'recItem':case'block':case'blockItem':return}if(e.attr&&t.attr.push(e.attr),e.data&&t.data.push(e.data),'text'in e){let a=e.text,l=t.childCount;Array.isArray(a)?(t.text.push(...a.map(((e,t)=>({index:t+l,value:e})))),t.childCount+=a.length):(t.text.push({index:l,value:a}),t.childCount+=1)}if(e.style){let a={};for(let t in e.style)a[d(t)]=e.style[t];t.style.push(a)}if(e.styleVar&&t.styleVar.push(e.styleVar),e.visible&&(t.visible=e.visible),e.handler){let t=e.handler;'object'==typeof t.on?_(t.config||{},t.on):_(t)}e.\u0254&&$(e.\u0254)}function V(e,{initCtx:t,runOp:a,hooks:{onMount:l,onState:r}}){let i=e.opsAmount++;l.watch((({value:e,leaf:l})=>{let n=o({value:e,priority:'props',runOp(e){a(e,r)},group:l.root.leafOps[l.fullID].group});l.root.leafOps[l.fullID].group.ops[i]=n;let r=t(e,l)})),r.watch((({value:e,leaf:t})=>{n(e,t.root.leafOps[t.fullID].group.ops[i])}))}function U(e,t,a){e[t].forEach((e=>{F(e,((e,l)=>{switch(t){case'data':case'styleVar':a[t][l]=e;break;case'attr':a.attr['xlink:href'===l?'href':l]=e;break;case'style':l.startsWith('--')?a.styleVar[l.slice(2)]=e:a.style[l]=e}}))}))}function j(e,t,a){let l=e.data.block,n={type:'text',parent:l,visible:0,index:a,value:null};if(l.child[a]=n,e.hydration){let a=T(n);if(a)switch(a.type){case'text':n.value=e.root.env.document.createTextNode(t),a.value.after(n.value);break;case'element':n.value=a.value.nextSibling,y(n.value,t)}else{let e=C(n);n.value=e.firstChild,y(n.value,t)}n.visible=1}else n.value=e.root.env.document.createTextNode(t),M(n);return n}function L(e){let t=e.stateRef,a=me;a.plain.includes(t)||a.closure.includes(t)||a.closure.push(t)}function z(){if('undefined'!=typeof document)return{document};throw Error('your environment has no document')}function G(e,t){let a=e.root.childSpawns[e.fullID];for(let e in a){let l=a[e];for(let e=0;e<l.length;e++)t(l[e])}}function Q(e,t){let a=t=>{let l=t.data;if(e&&'list'===l.type&&l.pendingUpdate){let e=l.pendingUpdate;l.pendingUpdate=null,effector.launch({target:t.template.api.pendingUpdate,params:e,defer:1,page:t,scope:t.root.scope})}if(e&&'route'===l.type)if(l.pendingInit){let e=l.pendingInit.value;l.pendingInit=null,effector.launch({target:t.template.api.pendingInit,params:e,defer:1,page:t,scope:t.root.scope})}else if(!l.block.visible)return;switch(l.type){case'element':n(e,l.ops.visible);break;case'route':case'list':case'list item':G(t,a);break;default:console.log('unsupported type',l.type)}};G(t,a)}function W(e){e.root.activeSpawns.delete(e.fullID),G(e,H)}function Z(e){J(e,e.root.childSpawns[e.parent.fullID][e.template.id]),J(e,e.template.pages)}function H(e){let{data:t,root:a}=e;switch(t.type){case'element':J(e,a.childSpawns[e.parent.fullID][e.template.id]),function e(t){a.activeSpawns.delete(t.fullID);let l=a.childSpawns[t.fullID];delete a.childSpawns[t.fullID],delete a.leafOps[t.fullID],J(t,t.template.pages);for(let t in l)l[t].forEach(e)}(e),n(0,t.ops.visible);break;case'list':{let a=t.records;for(let e=0;e<a.length;e++){let t=a[e];t.instance&&H(t.instance),t.active=0}e.root.activeSpawns.delete(e.fullID),Z(e);break}case'list item':{let a=t.block;J(a,a.parent.child);let l=a.left,n=a.right;l&&(l.right=n,n||a.parent.lastChild!==a||(a.parent.lastChild=l)),n&&(n.left=l),l||n||a.parent.lastChild!==a||(a.parent.lastChild=null),a.left=null,a.right=null,W(e),Z(e);break}case'route':W(e),Z(e);break;case'block':case'block item':case'rec':case'rec item':W(e)}delete a.childSpawns[e.fullID],delete a.leafOps[e.fullID]}function J(e,t){if(!t)return;let a=t.indexOf(e);-1!==a&&t.splice(a,1)}function K(e,t){if(Array.isArray(t))return t.map((t=>e.map((e=>e[t]))));if('object'==typeof t&&null!==t){let a={};for(let l in t){let n=t[l];a[l]=e.map('function'==typeof n?e=>n(e):e=>e[n])}return a}return e.map((e=>e[t]))}function X(e,t){A(me,'list'),'function'==typeof t&&(effector.is.unit(e)?e={source:e,fn:t}:e.fn=t);let{fn:a,key:l,source:n,fields:r=[]}=e,o=void 0!==l?'function'==typeof l?l:e=>e[l]:(e,t)=>t,i={type:'list',key:effector.is.store(e)?{type:'index'}:{type:'key',key:e.key},childTemplates:[],childCount:0,inParentIndex:-1},{env:d,namespace:f}=me;P(k({name:'list',draft:i,isSvgRoot:0,namespace:f,fn(e,{mount:t}){let l=k({name:'list item',state:{id:-1,store:null},draft:i,isSvgRoot:0,namespace:f,fn({id:e,store:t},{mount:l}){a({store:t,key:e,fields:K(t,r)});let n=effector.createEvent({named:'itemUpdater'});if(t.on(n,((e,t)=>t)),i.itemVisible){let{onMount:e,onState:t}=B({mount:l,state:i.itemVisible,onMount:(e,t)=>({visible:e,leaf:t}),onState:(e,t)=>({visible:t,leaf:e})});e.watch((({visible:e,leaf:t})=>{let a=t.data.block;a.visible=e,a.childInitialized=e,e&&E(i,{parentBlockFragment:a,leaf:t})})),t.watch((({visible:e,leaf:t})=>{let a=t.data.block;a.visible=e,a.childInitialized?Q(e,t):e&&(a.childInitialized=1,E(i,{parentBlockFragment:a,leaf:t}))}))}else l.watch(Se.listItem);return{itemUpdater:n}},env:d}),v=effector.createStore([]),m=n.map((e=>e)),h=effector.sample({source:n,clock:t,fn:(e,t)=>({updates:e,leaf:t,hydration:t.hydration}),greedy:1}),g=effector.createEvent(),b=effector.sample({source:h,clock:[m,g],fn:({leaf:e},t)=>({updates:t,leaf:e,hydration:0}),greedy:1});return effector.sample({source:v,clock:[h,b],greedy:1,fn(e,{updates:t,leaf:a,hydration:r}){let d=a.data,f=a;for(;f;){if('route'===f.data.type&&!f.data.block.visible)return void(d.pendingUpdate=t);f=f.parent}let v=d.block;ie('list update ['+n.shortName+']');let m=Array(t.length).fill(0),h=t.map(o),g=[];for(let a=0;a<e.length;a++){let l=e[a],n=h.indexOf(l.key);-1!==n?(g.push(l),m[n]=1,p(t[n],l.asyncValue)):(l.active=0,l.instance&&H(l.instance),u(l.asyncValue))}for(let e=0;e<t.length;e++){if(m[e])continue;let n=t[e],o=h[e],u=s(a.root.leafOps[a.fullID].group.queue),p={type:'LF',parent:v,child:[],childInitialized:0,visible:0,left:null,right:null},d={type:'listItem',key:o,index:o,active:1,leafData:{type:'list item',block:p,listDraft:i},asyncValue:c({value:n,group:u,onChange(e){d.instance&&effector.launch({target:d.instance.template.api.itemUpdater,params:e,defer:1,page:d.instance,scope:d.instance.root.scope})},onInit(e){d.active&&(r||(d.instance=D(l,{values:{id:o,store:e},parentLeaf:a,mountNode:a.mountNode,svgRoot:a.svgRoot,leafData:d.leafData,opGroup:u,domSubtree:a.root.leafOps[a.fullID].domSubtree,hydration:r,root:a.root})))}})},f=g.length;g.push(d);let b=f>0?g[f-1].leafData:null;if(v.child.push(p),b){let e=b.block;p.left=e;let t=e.right;t?(t.left=p,p.right=t):v.lastChild=p,e.right=p}else v.lastChild=p;r&&(d.instance=D(l,{values:{id:o,store:n},parentLeaf:a,mountNode:a.mountNode,svgRoot:a.svgRoot,leafData:d.leafData,opGroup:u,domSubtree:a.root.leafOps[a.fullID].domSubtree,hydration:r,root:a.root}))}return se('list update ['+n.shortName+']'),0===g.length&&(v.lastChild=null),d.records=g,g},target:v}),{pendingUpdate:g}},env:d}))}function Y({source:e,visible:t,fn:a}){A(me,'route');let{env:l,namespace:n}=me,r=k({name:'route',isSvgRoot:0,namespace:n,env:l,draft:{type:'route',childTemplates:[],childCount:0,inParentIndex:-1},fn(r,{mount:o}){let i;if(effector.is.store(t))i=effector.combine({value:e,visible:t});else{let a=t;i=e.map((e=>({value:e,visible:a(e)})))}let s=k({name:'route item',isSvgRoot:0,namespace:n,env:l,draft:{type:'route',childTemplates:[],childCount:0,inParentIndex:-1},state:{store:null},fn({store:e},{mount:t}){let l=effector.createEvent({named:'itemUpdater'});e.on(l,((e,t)=>t)),a({store:e});let n=effector.sample({source:t,clock:i,fn:(e,{visible:t,value:a})=>({leaf:e,visible:t,value:a}),greedy:1});t.watch(Se.routeItem),n.watch((({leaf:e,visible:t,value:a})=>{if(e.data.block.visible=t,t&&effector.launch({target:l,params:a,defer:1,page:e,scope:e.root.scope}),t){let t=e.parent;for(;t;){if('route'===t.data.type&&!t.data.block.visible)return;t=t.parent}}Q(t,e)}))}});P(s);let{onMount:c,onState:u}=B({mount:o,state:i,onMount:({visible:e,value:t},a)=>({leaf:a,visible:e,value:t}),onState:(e,{visible:t,value:a})=>({leaf:e,visible:t,value:a})}),p=effector.createEvent(),d=effector.sample({source:o,clock:p,greedy:1,fn:(e,t)=>({leaf:e,value:t,visible:1})});return effector.merge([c,u,d]).watch((({leaf:e,visible:t,value:a})=>{let l=e.data;if(l.block.visible=t,t||l.initialized||!l.pendingInit){if(t&&!l.initialized){let t=e.parent;for(;t;){if('route'===t.data.type&&!t.data.block.visible)return void(l.pendingInit={value:a});t=t.parent}}t&&!l.initialized&&(N({parentBlockFragment:l.block,leaf:e,actor:s,values:{store:a}}),l.initialized=1)}else l.pendingInit=null})),{pendingInit:p}}});P(r)}function ee(e){let t='function'==typeof e?e:e.fn,a=k({name:'rec',state:{store:null},isSvgRoot:0,namespace:null,env:null,draft:{type:'rec',childTemplates:[],childCount:0,inParentIndex:0},defer:1,isBlock:1,fn({store:e},{mount:a}){t({store:e,state:e});let l=effector.createEvent({named:'itemUpdater'});return e.on(l,((e,t)=>t)),a.watch(Se.rec),{itemUpdater:l}}});return({store:e,state:t=e})=>{A(me,'(rec instance)');let{env:l,namespace:n}=me;a.deferredInit&&a.deferredInit(),P(k({name:'rec item',isSvgRoot:0,namespace:n,env:l,draft:{type:'recItem',childTemplates:[],childCount:0,inParentIndex:-1},fn(e,{mount:l}){let{onMount:n,onState:r}=B({state:t,mount:l,onMount:(e,t)=>({state:e,leaf:t}),onState:(e,t)=>({state:t,leaf:e})});r.watch((({state:e,leaf:t})=>{G(t,(a=>{effector.launch({target:a.template.api.itemUpdater,params:e,defer:1,page:t,scope:t.root.scope})}))})),n.watch((({leaf:e,state:t})=>{N({parentBlockFragment:e.data.block,leaf:e,actor:a,values:{store:t}})}))}}))}}function te(e,t){if(0===t.length)return e;let a=[e[0]];for(let l=0;l<t.length;l++)a.push(t[l],e[l+1]);return a}Object.defineProperty(exports,'__esModule',{value:1});var effector=require('effector');let ae;ae='undefined'!=typeof performance&&performance.now?()=>performance.now():'undefined'!=typeof process&&process.hrtime?()=>{let e=process.hrtime();return(1e9*e[0]+e[1])/1e6}:()=>Date.now();let le=new Map;const ne=[],re=e=>{let t=le.get(e);t||(t={calls:0,time:0,label:e,childTime:0},le.set(e,t)),t.calls+=1,ne.push({bucket:t,pendingStart:ae()})},oe=e=>{let t=le.get(e),a=ne.pop().pendingStart,l=ae()-a;t.time+=l,ne.length>0&&(ne[ne.length-1].bucket.childTime+=l)};let ie,se;'undefined'!=typeof performance&&performance.mark?(ie=e=>{performance.mark('\u2604\ufe0f '+e+' start'),re(e)},se=e=>{oe(e);try{performance.measure('\u2604\ufe0f '+e,'\u2604\ufe0f '+e+' start')}catch(e){}performance.clearMarks('\u2604\ufe0f '+e+' start'),performance.clearMeasures('\u2604\ufe0f '+e)}):(ie=e=>{re(e)},se=e=>{oe(e)});let ce='undefined'!=typeof requestAnimationFrame?requestAnimationFrame:e=>setTimeout(e,0);const ue={attr:b,data:g,style:h,styleVar:m},pe=(e,t)=>e.includes(t);let de={storeBase(e,t){e.plain.push(t)},storeOnMap(e,t,a,l){var n,r;a.unshift(e.loader),a.push(e.upward),l&&(pe(e.plain,l)||(pe(e.closure,l)||e.closure.push(l),r={type:'closure',of:l},(n=t).before||(n.before=[]),n.before.push(r)))},storeMap(e,t,a){pe(e.plain,t)||pe(a.seq,e.loader)||a.seq.unshift(e.loader)},storeWatch:(e,t,a)=>(e.watch.push({of:t,fn:a}),1),eventPrepend(e,t){t.seq.push(e.upward)},combineBase(e,t,a){e.plain.push(t,a)},combineField(e,t,a){pe(e.plain,t)||a.seq.unshift(e.loader)},splitBase(e,t){e.plain.push(t)},splitMatchStore(e,t,a){pe(e.plain,t)||a.seq.unshift(e.loader)},sampleStoreSource(e,t){pe(e.plain,t)||pe(e.closure,t)||e.closure.push(t)},sampleNonStoreSource(e,t,a,l){e.plain.push(t,a,l)},sampleTarget(e,t){t.seq.push(e.loader)},sampleSourceLoader:e=>e.loader,sampleSourceUpward:(e,t)=>t&&e.upward},fe=0,ve=0,me=null,he=null;const ge=(e,t)=>e.reg[t.id];let be=null;const ye=['LF','using','element','recItem','rec','block','blockItem','route'];let ke=effector.createEvent({named:'onMount'});ke.watch((({fns:e,element:t})=>{e.forEach((e=>{e(t)}))}));const Ie=[{type:'attr',field:'value'},{type:'attr',field:'checked'},{type:'attr',field:'min'},{type:'attr',field:'max'}],xe={attr:b,data:g,style:h,styleVar:m},we=e=>e.data.block.value;let Se={using(e){let t=e.data;E(t.draft,{parentBlockFragment:t.block,leaf:e})},routeItem(e){let t=e.draft,a=e.data;a.block.visible=1,E(t,{parentBlockFragment:a.block,leaf:e})},block(e){E(e.draft,{parentBlockFragment:e.data.block,leaf:e})},blockItem(e){N({parentBlockFragment:e.data.block,leaf:e,actor:e.draft.itemOf})},rec(e){E(e.draft,{parentBlockFragment:e.data.block,leaf:e})},listItem(e){let t=e.data,a=t.block;a.visible=1,a.childInitialized=1,E(t.listDraft,{parentBlockFragment:a,leaf:e})}};exports.block=({fn:e,env:t,namespace:a="html"})=>{let l=k({name:'block',isSvgRoot:0,namespace:a,env:t,draft:{type:'block',childTemplates:[],childCount:0,inParentIndex:0},isBlock:1,fn({},{mount:t}){e(),t.watch(Se.block)}});return()=>{A(me,'(block instance)');let e={type:'blockItem',childTemplates:[],childCount:0,inParentIndex:-1,itemOf:l},{env:t,namespace:a}=me;P(k({name:'block item',isSvgRoot:0,namespace:a,env:t,draft:e,fn(e,{mount:t}){t.watch(Se.blockItem)}}))}},exports.h=(e,t)=>{let a,r=0,o=0;'function'==typeof t?(r=1,a=t):t&&(o=1,t.fn&&(r=1,a=t.fn),t.\u0254&&('function'==typeof t.\u0254?(r=1,a=t.\u0254):'function'==typeof t.\u0254.fn&&(r=1,a=t.\u0254.fn))),A(me,'h');let i,s=me.env,c=me.namespace,u=c,p='html';u=p='svg'===c?'svg':'html','svg'===e&&(p='svg',u='svg'),me.isBlock||(i='svg'===p?s.document.createElementNS('http://www.w3.org/2000/svg',e):s.document.createElement(e));let d=i,v={type:'element',tag:e,attr:[],data:[],text:[],style:[],styleVar:[],handler:[],stencil:d,seq:[],staticSeq:[],childTemplates:[],childCount:0,inParentIndex:-1,opsAmount:1,node:[]};'foreignObject'===c?(v.attr.push({xmlns:'http://www.w3.org/1999/xhtml'}),u='html'):'svg'===e?(v.attr.push({xmlns:'http://www.w3.org/2000/svg'}),u='svg'):'foreignObject'===e&&(u='foreignObject');let m=k({name:'element',draft:v,isSvgRoot:'svg'===e,namespace:u,fn(e,{mount:i}){let s=effector.createEvent({named:'domElementCreated'});r&&a(),o&&$(t),effector.is.unit(v.visible)&&(v.seq.push({type:'visible',value:v.visible}),L(v.visible));let c={attr:{},data:{},style:{},styleVar:{}};U(v,'attr',c),U(v,'data',c),U(v,'style',c),U(v,'styleVar',c),F(c,((e,t)=>{F(e,((e,a)=>{effector.is.unit(e)?(v.seq.push({type:t,field:a,value:e}),L(e)):v.staticSeq.push({type:t,field:a,value:e})}))})),v.text.forEach((e=>{null!==e.value&&(effector.is.unit(e.value)?(v.seq.push({type:'dynamicText',value:e.value,childIndex:e.index}),L(e.value)):v.seq.push({type:'staticText',value:String(e.value),childIndex:e.index}))})),v.handler.forEach((e=>{F(e.map,((t,a)=>{v.seq.push({type:'handler',for:a,handler:t,options:e.options,domConfig:e.domConfig})}))})),d&&f(d,v.staticSeq),v.seq.forEach((e=>{switch(e.type){case'visible':{let{onMount:t,onState:a}=B({mount:i,state:e.value,onMount:(e,t)=>({leaf:t,value:e,hydration:t.hydration}),onState:(e,t)=>({leaf:e,value:t,hydration:0})});t.watch((({leaf:e,value:t,hydration:a})=>{let n=e.data,r=n.block;if(a&&(l(t,n.ops.visible),t)){let e,t=q(r);if(e=t?t.nextSibling:C(r).firstChild,'#text'===e.nodeName){let t=e;e=e.nextSibling,t.remove()}r.value=e,r.visible=1}E(v,{parentBlockFragment:r,leaf:e,node:r.value,svgRoot:m.isSvgRoot?r.value:null}),t&&n.needToCallNode&&(n.needToCallNode=0,effector.launch({target:ke,params:{element:n.block.value,fns:v.node},page:e,defer:1,scope:e.root.scope})),effector.launch({target:s,params:e,defer:1,page:e,scope:e.root.scope})})),effector.merge([a,t]).watch((({leaf:e,value:t,hydration:a})=>{a||n(t,e.data.ops.visible)}));break}case'attr':case'data':case'style':case'styleVar':{let t=xe[e.type],a=Ie.some((({type:t,field:a})=>e.type===t&&e.field===a)),l=B({mount:s,state:e.value,onMount:(e,t)=>({leaf:t,value:e}),onState:(e,t)=>({leaf:e,value:t})});a?effector.merge([l.onState,l.onMount]).watch((({leaf:a,value:l})=>{t(we(a),e.field,l)})):V(v,{initCtx(a,l){let n=we(l);return t(n,e.field,a),n},runOp(a,l){t(l,e.field,a)},hooks:l});break}case'dynamicText':V(v,{initCtx:(t,a)=>j(a,t,e.childIndex),runOp(e,t){y(t.value,e)},hooks:B({mount:s,state:e.value,onMount:(e,t)=>({leaf:t,value:String(e)}),onState:(e,t)=>({leaf:e,value:String(t)})})});break;case'staticText':s.watch((t=>{j(t,e.value,e.childIndex)}));break;case'handler':{let t=e.handler.graphite.meta.nativeTemplate||null;s.watch((a=>{let l=null;if(t){let e=0,n=a;for(;!e&&n;)n.template===t?(e=1,l=n):n=n.parent}else l=null;we(a).addEventListener(e.for,(t=>{e.options.prevent&&t.preventDefault(),e.options.stop&&t.stopPropagation(),effector.launch({target:e.handler,params:t,page:l,scope:a.root.scope})}),e.domConfig)}));break}}})),i.watch((e=>{let t=e.data;if(!v.visible){let a=t.ops.visible,r=t.block;if(e.hydration){l(1,a);let e,t=q(r);if(e=t?t.nextSibling:C(r).firstChild,'#text'===e.nodeName){let t=e;e=e.nextSibling,t.remove()}r.value=e,r.visible=1}E(v,{parentBlockFragment:r,leaf:e,node:r.value,svgRoot:m.isSvgRoot?r.value:null}),effector.launch({target:s,params:e,defer:1,page:e,scope:e.root.scope}),e.hydration?t.needToCallNode&&(t.needToCallNode=0,effector.launch({target:ke,params:{element:t.block.value,fns:v.node},page:e,defer:1,scope:e.root.scope})):n(1,a)}}))},env:s});P(m)},exports.handler=_,exports.list=X,exports.node=e=>{A(me,'node');let t=me.draft;switch(t.type){case'list':case'listItem':case'using':case'route':case'rec':case'recItem':case'block':case'blockItem':return void console.error('node() hook supported only in h() nodes')}t.node.push(e)},exports.rec=ee,exports.remap=K,exports.route=Y,exports.spec=$,exports.text=(e,...t)=>{Array.isArray(e)?$({text:te(e,t)}):$({text:e})},exports.tree=({source:e,key:t,child:a,fn:l})=>{let n=ee((({store:e})=>{X({source:e,key:t,fn({store:e}){let t=e.map((e=>e[a]||[]));l({store:e,child(){n({store:t})}})}})}));n({store:e})},exports.using=(e,t)=>{let a,l,n,r,o,c;if('function'==typeof t)a=t,n=z(),r=0;else{if(!t)throw Error('using() second argument is missing');a=t.fn,n=t.env?t.env:z(),r=t.hydrate,l=t.onComplete,o=t.onRoot,c=t.scope}R(e,'using() first argument is missing');let u={scope:c,env:n,activeSpawns:new Set,childSpawns:{},leafOps:{}},p=e.namespaceURI,d=e.tagName.toLowerCase(),f={type:'using',childTemplates:[],childCount:0,inParentIndex:-1},v=k({name:'using',draft:f,isSvgRoot:'svg'===d,namespace:'http://www.w3.org/2000/svg'===p?'svg':'foreignobject'===d?'foreignObject':'html',fn(e,{mount:t}){a(),t.watch(Se.using)},env:n}),m={type:'using',child:[],value:e},h=i({onComplete:l}),g=D(v,{parentLeaf:he||null,mountNode:e,svgRoot:v.isSvgRoot?e:he?he.svgRoot:null,leafData:{type:'using',draft:f,element:e,block:m},opGroup:s(h),domSubtree:s(h),hydration:r,root:u});if(o&&o({template:v,leaf:g}),h.onDrain&&!h.rafID){let e=h.onDrain;h.onDrain=null,e()}},exports.val=(e,...t)=>t.every((e=>!effector.is.store(e)))?te(e,t).join(''):effector.combine(t,(t=>te(e,t).join(''))),exports.variant=({source:e,cases:t,key:a})=>{let l;A(me,'variant'),R(effector.is.unit(e),'variant({source}) should be unit'),l='function'==typeof a?a:null==a?e=>String(e):e=>String(e[a]);let n=0;for(let a in t)'__'!==a?Y({source:e,visible:e=>l(e)===a,fn:t[a]}):n=1;if(n){let a=Object.keys(t);Y({source:e,visible:e=>!a.includes(l(e)),fn:t.__})}}; | ||
function e(e,t){e.cursor[t].prev&&(e.cursor[t].prev.cursor[t].next=e.cursor[t].next),e.cursor[t].next&&(e.cursor[t].next.cursor[t].prev=e.cursor[t].prev),e.queue[t].last===e&&(e.queue[t].last=e.cursor[t].prev),e.queue[t].first===e&&(e.queue[t].first=e.cursor[t].next),e.cursor[t].prev=null,e.cursor[t].next=null}function t(e){var t,l;e.status='active',t=a(e),(l=e).cursor.prev&&(l.cursor.prev.cursor.next=l.cursor.next),l.cursor.next&&(l.cursor.next.cursor.prev=l.cursor.prev),t.last===l&&(t.last=l.cursor.prev),t.first===l&&(t.first=l.cursor.next),l.cursor.prev=null,l.cursor.next=null}function a(e){return e.group.activeChilds[e.priority]}function l(e,a){a.value.active=a.value.pending=e,'active'!==a.status&&t(a)}function n(l,n){if(n.value.active===l)return n.value.pending=l,void('pending'===n.status&&(t(n),a(n).first||e(n.group,n.priority)));var r,o,i,s;'active'===n.status&&(n.status='pending',a(n).first||((i=n.group).queue[s=n.priority].last?(i.cursor[s].prev=i.queue[s].last,i.queue[s].last.cursor[s].next=i,i.queue[s].last=i):i.queue[s].first=i.queue[s].last=i),o=n,(r=a(n)).last?(o.cursor.prev=r.last,r.last.cursor.next=o,r.last=o):r.first=r.last=o),n.value.pending=l,n.group.queue.rafID||(n.group.queue.rafID=ce(n.group.queue.execQueue))}function r(a){ie('execQueue');let l,n,r=ae(),o=0;e:for(;a.props.first||a.tree.first||a.data.first;){if(ae()-r>=1e3){o=1;break e}let i=!!a.props.first;for(i&&ie('props');l=a.props.first;){for(;n=l.activeChilds.props.first;){if(ae()-r>=1e3){o=1,se('props');break e}n.runOp(n.value.pending),n.value.active=n.value.pending,t(n)}e(l,'props')}i&&se('props');let s=!!a.tree.first;for(s&&ie('tree');l=a.tree.first;){for(;n=l.activeChilds.tree.first;){if(ae()-r>=1e3){o=1,se('tree');break e}n.runOp(n.value.pending),n.value.active=n.value.pending,t(n)}e(l,'tree')}s&&se('tree');let c=!!a.data.first;for(c&&ie('data');l=a.data.first;){for(;n=l.activeChilds.data.first;){if(ae()-r>=1e3){o=1,se('data');break e}n.runOp(n.value.pending),n.value.active=n.value.pending,t(n)}e(l,'data')}c&&se('data')}if(se('execQueue'),o)a.rafID=ce(a.execQueue);else if(a.rafID=null,a.onDrain){let e=a.onDrain;a.onDrain=null,e()}}function o({value:e,runOp:t,group:a,priority:l}){return{value:{active:e,pending:e},runOp:t,status:'active',priority:l,group:a,cursor:{prev:null,next:null}}}function i({onComplete:e}){let t={props:{first:null,last:null},tree:{first:null,last:null},data:{first:null,last:null},rafID:null,execQueue(){},onDrain:e};return t.execQueue=r.bind(null,t),t}function s(e){return{ops:[],queue:e,activeChilds:{props:{first:null,last:null},tree:{first:null,last:null},data:{first:null,last:null}},cursor:{props:{prev:null,next:null},tree:{prev:null,next:null},data:{prev:null,next:null}}}}function c({value:e,group:t,onInit:a,onChange:l}){let r=o({value:e,group:t,runOp(e){i.status='A',l(e)},priority:'data'}),i={status:'IA',value:r.value,ops:{init:o({value:0,group:t,runOp(e){i.status='A',a(i.value.active)},priority:'data'}),change:r,terminate:o({value:0,group:t,runOp(e){i.status='T'},priority:'data'})}};return n(1,i.ops.init),i}function u(e){switch(e.status){case'I':case'T':case'AT':return;case'A':e.status='AT',n(1,e.ops.terminate);break;case'AA':e.status='AT',n(1,e.ops.terminate),n(e.value.active,e.ops.change);break;case'IA':e.status='T',n(0,e.ops.init)}}function p(e,t){switch(t.status){case'I':case'T':return;case'A':t.value.active!==e&&(t.status='AA',n(e,t.ops.change));break;case'AA':t.value.active===e?(t.status='A',n(e,t.ops.change)):t.value.pending!==e&&(t.value.pending=e);break;case'IA':t.value.active=t.value.pending=e}}function d(e){switch(e=String(e)){case'__proto__':case'__defineGetter__':case'__defineSetter__':case'constructor':case'prototype':case'hasOwnProperty':case'toString':case'valueOf':case'setProperty':case'removeProperty':return'forbidden';default:return e.replace(/[^a-zA-Z0-9\-_]/g,'')}}function f(e,t){for(let a=0;a<t.length;a++){let{type:l,field:n,value:r}=t[a];ue[l](e,n,r)}}function v(e){return''!==e&&0!==e&&'0'!==e&&(0==e||null==e)}function m(e,t,a){v(a)?e.style.removeProperty(`--${t}`):e.style.setProperty(`--${t}`,`${a}`)}function h(e,t,a){v(a)?delete e.style[t]:e.style[t]=`${a}`}function g(e,t,a){v(a)?delete e.dataset[t]:e.dataset[t]=`${a}`}function b(e,t,a){if(v(a)){switch(t){case'value':delete e.value;break;case'checked':e.checked=0;break;case'spellcheck':if(0==a)return void e.setAttribute('spellcheck','false')}e.removeAttribute(t)}else{switch(t){case'value':e.value=`${a}`;break;case'checked':e.checked=`${a}`}e.setAttribute(t,`${a}`)}}function y(e,t){e.replaceData(0,(e.textContent||'').length,String(t))}function k({fn:e,state:t={},defer:a=0,name:l="",draft:n,isSvgRoot:r,namespace:o,env:i,isBlock:s=0}){let c=me,u={id:++fe,name:l,plain:[],watch:[],nameMap:{},pages:[],closure:[],childTemplates:[],handlers:de,upward:effector.step.filter({fn(e,t,a){if(!a.page){if(!a.parent||!a.parent.page)return 1;a.page=a.parent.page}if(!a.page.root.activeSpawns.has(a.page.fullID))return console.count('inactive page upward'),0;let l=[a.page.template],n=[a.page];{let e=a.page.parent;for(;e;)n.push(e),l.push(e.template),e=e.parent}return a.node.next.forEach((t=>{let r=t.meta.nativeTemplate;if(r)if(l.includes(r)){let o=n[l.indexOf(r)];effector.launch({target:t,params:e,defer:1,page:o,stack:a,scope:a.scope})}else console.error('context drift',{stack:a,node:t});else effector.launch({target:t,params:e,defer:1,page:a.page,stack:a,scope:a.scope})})),0}}),loader:effector.step.filter({fn(e,t,a){if(a.parent){let t=a.scope?a.scope.graphite.id:null;if(a.page){if(!a.page.root.activeSpawns.has(a.page.fullID))return console.count('inactive page loader'),0;if(a.page.template===u)return 1;if(a.page.root.childSpawns[a.page.fullID][u.id])a.page.root.childSpawns[a.page.fullID][u.id].forEach((l=>{(!t||l.root.scope&&t===l.root.scope.graphite.id)&&effector.launch({params:e,target:a.node,page:l,defer:1,scope:a.scope})}));else{let l=a.page.fullID,n='rec'===a.page.template.name;u.pages.forEach((r=>{if(!t||r.root.scope&&t===r.root.scope.graphite.id)if(r.fullID===l||r.fullID.startsWith(`${l}_`)){let t=1;if(n){let e=a.page.template.id,l=r.parent;for(;l&&l!==a.page;){if(l.template.id===e){t=0;break}l=l.parent}}t&&effector.launch({params:e,target:a.node,page:r,defer:1,scope:a.scope})}else l.startsWith(`${r.fullID}_`)&&effector.launch({params:e,target:a.node,page:a.page,defer:1,scope:a.scope})}))}}else u.pages.forEach((l=>{(!t||l.root.scope&&t===l.root.scope.graphite.id)&&effector.launch({params:e,target:a.node,page:l,defer:1,scope:a.scope})}));return 0}return 1}}),parent:c,node:null,api:null,trigger:{mount:effector.createEvent({named:'mount'})},draft:n,isSvgRoot:r,namespace:o,env:i,isBlock:s||!(!c||!c.isBlock)};c&&c.childTemplates.push(u);let p=effector.createNode({meta:{template:u}});return u.node=p,me=u,a?u.deferredInit=()=>{let a=me;me=u,u.deferredInit=null;try{effector.withRegion(p,(()=>{let a=effector.restore(t);u.api=e(a,u.trigger),u.nameMap=a}))}finally{me=a}}:effector.withRegion(p,(()=>{let a=effector.restore(t);u.api=e(a,u.trigger),u.nameMap=a})),me=c,u}function I(e,t){let a;switch(a=t?t.getState(e):e.current,e.type){case'list':return[...a];case'shape':return{...a};default:return a}}function x(e,t,a){let l=t;for(;l&&!ge(l,e);)l=l.parent;return l?ge(l,e):a?(a.getState(e),a.reg[e.id]):e}function w(e,t){ge(t,e)||(t.reg[e.id]=x(e,t.parent,t.root.scope))}function S(e,t,a){t in a||(a[t]=[]),a[t].push(...e)}function D(e,{values:t={},parentLeaf:a,mountNode:l,svgRoot:n,leafData:r,opGroup:o,domSubtree:i,hydration:s,root:c}){function u(e){if(e.before)for(let t=0;t<e.before.length;t++){let a=e.before[t];switch(a.type){case'map':{let t,l=a.from;if(!a.fn&&!l)break;l&&(w(l,f),t=d[l.id].current),d[e.id].current=a.fn?a.fn(t):t;break}case'field':{let t=a.from;w(t,f),d[e.id].current[a.field]=d[t.id].current;break}case'closure':w(a.of,f)}}}function p(e,t,a){let l;t.stop=1;try{for(;t.i<e.length;)l=e[t.i],t.i++,l.fn(a[l.of.id]?a[l.of.id].current:x(l.of,f.parent,f.root.scope).current)}catch(e){console.error(e),t.stop=0}}let d={},f={draft:e.draft,svgRoot:n,data:r,parent:a,hydration:s,mountNode:l,root:c,id:++ve,fullID:'',reg:d,template:e};e.pages.push(f);let v=he;he=f,a&&S([f],e.id,c.childSpawns[a.fullID]),f.fullID=a?`${a.fullID}_${f.id}`:`${f.id}`,c.childSpawns[f.fullID]={},c.activeSpawns.add(f.fullID),c.leafOps[f.fullID]={group:o,domSubtree:i};for(let t=0;t<e.closure.length;t++){let a=e.closure[t],l=a,n=f.parent;e:for(;n;){if(ge(n,a)){l=ge(n,a);break e}n=n.parent}!n&&c.scope&&(c.scope.getState(a),l=c.scope.reg[a.id]),d[a.id]=l}for(let t=0;t<e.plain.length;t++){let a=e.plain[t],l={id:a.id,current:I(a,c.scope)};d[a.id]=l}for(let a in t){let l=e.nameMap[a].stateRef.id;d[l]={id:l,current:t[a]}}e.closure.forEach(u),e.plain.forEach(u);let m={i:0,stop:0};for(;!m.stop;)p(e.watch,m,d);if(a)for(let e in c.childSpawns[f.fullID])S(c.childSpawns[f.fullID][e],e,c.childSpawns[a.fullID]);if(be)be.steps.push({target:e.trigger.mount,params:f,defer:1,page:f,scope:c.scope});else{let t;be={parent:be,steps:[{target:e.trigger.mount,params:f,defer:1,page:f,scope:c.scope}]};do{for(;t=be.steps.shift();)be={parent:be,steps:[]},effector.launch(t)}while(be=be.parent)}return he=v,f}function C(e){let t=e.parent;for(;'element'!==t.type&&'using'!==t.type;)t=t.parent;return t?t.value:null}function O(e){if(!e.visible)return null;switch(e.type){case'text':case'element':return e;case'LF':case'route':case'rec':case'recItem':case'block':case'blockItem':for(let t=e.child.length-1;t>=0;t--){let a=O(e.child[t]);if(a)return a}return null;case'list':{let t=e.lastChild;if(!t)return null;for(;t;){let e=O(t);if(e)return e;t=t.left}return null}default:return null}}function T(e){switch(e.type){case'using':return null;case'LF':{let t=e.left;for(;t;){let e=O(t);if(e)return e;t=t.left}return T(e.parent)}case'element':case'text':case'route':case'rec':case'recItem':case'block':case'blockItem':case'list':{let t=e.parent;for(let a=e.index-1;a>=0;a--){let e=t.child[a];if(!e)continue;let l=O(e);if(l)return l}switch(t.type){case'element':case'using':return null}return T(t)}default:return null}}function q(e){let t=T(e);return t?t.value:null}function R(e,t){if(!e)throw Error(t)}function A(e,t){if(!e)throw Error(`${t}() called outside from using() closure`)}function P(e){if(!me)return;let{draft:t}=e;if('listItem'!==t.type&&'rec'!==t.type)switch(me.draft.type){case'element':case'using':case'route':case'list':case'rec':case'recItem':case'block':case'blockItem':t.inParentIndex=me.draft.childCount,me.draft.childCount+=1,me.draft.childTemplates.push(e);break;default:console.warn(`unexpected currentTemplate type ${me.draft.type}`)}}function E(e,{parentBlockFragment:t,leaf:a,node:l,svgRoot:n,values:r}){e.childTemplates.forEach((e=>{N({parentBlockFragment:t,leaf:a,node:l,svgRoot:n,values:r,actor:e})}))}function N({parentBlockFragment:e,leaf:t,node:a=t.mountNode,actor:l,svgRoot:n,values:r}){let i;R(ye.includes(e.type),`incorrect parent ${e.type}`);let{draft:c}=l,{queue:u}=t.root.leafOps[t.fullID].group,p=s(u),d=t.root.leafOps[t.fullID].domSubtree,v=d;switch(c.type){case'route':{let t={type:'route',parent:e,child:[],visible:0,index:c.inParentIndex};e.child[c.inParentIndex]=t,i={type:'route',block:t,ops:{},initialized:0,pendingInit:null};break}case'element':{let a;if(l.isBlock){let e,l,n=t;for(;n&&(!l||!e);){n.template.env&&(e=n.template.env);let{draft:t}=n;'element'===t.type&&('svg'===t.tag?l='svg':'foreignObject'===t.tag&&(l='html')),n=n.parent}l||(l='html'),e&&(a='svg'===l?e.document.createElementNS('http://www.w3.org/2000/svg',c.tag):e.document.createElement(c.tag),f(a,c.staticSeq))}else a=c.stencil.cloneNode();let n={type:'element',parent:e,child:[],value:a,visible:0,index:c.inParentIndex};e.child[c.inParentIndex]=n,i={type:'element',block:n,ops:{visible:o({value:0,priority:'tree',runOp(e){if(e){M(n);let e=i;e.needToCallNode&&(e.needToCallNode=0,effector.launch({target:ke,params:{element:n.value,fns:c.node},page:m,scope:t.root.scope})),n.visible=1}else n.value.remove(),n.visible=0},group:d})},needToCallNode:c.node.length>0},v=s(u);break}case'list':{let t={type:'list',parent:e,child:[],lastChild:null,visible:1,index:c.inParentIndex};e.child[c.inParentIndex]=t,i={type:'list',draft:c,block:t,records:[],pendingUpdate:null};break}case'using':case'listItem':break;case'rec':{let t={type:'rec',parent:e,child:[],visible:1,index:c.inParentIndex};e.child[c.inParentIndex]=t,i={type:'rec',block:t};break}case'recItem':{let t={type:'recItem',parent:e,child:[],visible:1,index:c.inParentIndex};e.child[c.inParentIndex]=t,i={type:'rec item',block:t};break}case'block':{let t={type:'block',parent:e,child:[],visible:1,index:c.inParentIndex};e.child[c.inParentIndex]=t,i={type:'block',block:t};break}case'blockItem':{let t={type:'blockItem',parent:e,child:[],visible:1,index:c.inParentIndex};e.child[c.inParentIndex]=t,i={type:'block item',block:t};break}default:console.warn(`unexpected draft type ${c.type}`)}let m=D(l,{values:r,parentLeaf:t,mountNode:a,svgRoot:n||t.svgRoot,leafData:i,opGroup:p,domSubtree:v,hydration:t.hydration,root:t.root})}function M(e){let t=q(e);t?t.after(e.value):C(e).prepend(e.value),e.visible=1}function B({mount:e,state:t,onMount:a,onState:l}){return{onMount:effector.sample({source:t,clock:e,fn:a,greedy:1}),onState:effector.sample({source:e,clock:t,fn:l,greedy:1})}}function F(e,t){for(let a in e)t(e[a],a)}function _(e,t){if(!me)return;let a=me.draft;R('element'===a.type,`"handler" extension can be used only with element nodes, got "${a.type}"`),void 0===t&&(t=e,e={});for(let e in t)R(effector.is.unit(t[e]),`handler for "${e}" should be event`);let{passive:l=0,capture:n=0,prevent:r=0,stop:o=0}=e;a.handler.push({options:{prevent:r,stop:o},domConfig:{passive:r?0:l,capture:n},map:t})}function $(e){A(me,'spec');let t=me.draft;switch(t.type){case'list':return void(e.visible&&(t.itemVisible=e.visible));case'listItem':case'using':case'route':case'rec':case'recItem':case'block':case'blockItem':return}if(e.attr&&t.attr.push(e.attr),e.data&&t.data.push(e.data),'text'in e){let a=e.text,l=t.childCount;Array.isArray(a)?(t.text.push(...a.map(((e,t)=>({index:t+l,value:e})))),t.childCount+=a.length):(t.text.push({index:l,value:a}),t.childCount+=1)}if(e.style){let a={};for(let t in e.style)a[d(t)]=e.style[t];t.style.push(a)}if(e.styleVar&&t.styleVar.push(e.styleVar),e.visible&&(t.visible=e.visible),e.handler){let t=e.handler;'object'==typeof t.on?_(t.config||{},t.on):_(t)}e.\u0254&&$(e.\u0254)}function V(e,{initCtx:t,runOp:a,hooks:{onMount:l,onState:r}}){let i=e.opsAmount++;l.watch((({value:e,leaf:l})=>{let n=o({value:e,priority:'props',runOp(e){a(e,r)},group:l.root.leafOps[l.fullID].group});l.root.leafOps[l.fullID].group.ops[i]=n;let r=t(e,l)})),r.watch((({value:e,leaf:t})=>{n(e,t.root.leafOps[t.fullID].group.ops[i])}))}function U(e,t,a){e[t].forEach((e=>{F(e,((e,l)=>{switch(t){case'data':case'styleVar':a[t][l]=e;break;case'attr':a.attr['xlink:href'===l?'href':l]=e;break;case'style':l.startsWith('--')?a.styleVar[l.slice(2)]=e:a.style[l]=e}}))}))}function j(e,t,a){let l=e.data.block,n={type:'text',parent:l,visible:0,index:a,value:null};if(l.child[a]=n,e.hydration){let a=T(n);if(a)switch(a.type){case'text':n.value=e.root.env.document.createTextNode(t),a.value.after(n.value);break;case'element':n.value=a.value.nextSibling,y(n.value,t)}else{let e=C(n);n.value=e.firstChild,y(n.value,t)}n.visible=1}else n.value=e.root.env.document.createTextNode(t),M(n);return n}function L(e){let t=e.stateRef,a=me;a.plain.includes(t)||a.closure.includes(t)||a.closure.push(t)}function z(){if('undefined'!=typeof document)return{document};throw Error('your environment has no document')}function G(e,t){let a=e.root.childSpawns[e.fullID];for(let e in a){let l=a[e];for(let e=0;e<l.length;e++)t(l[e])}}function Q(e,t){let a=t=>{let l=t.data;if(e&&'list'===l.type&&l.pendingUpdate){let e=l.pendingUpdate;l.pendingUpdate=null,effector.launch({target:t.template.api.pendingUpdate,params:e,defer:1,page:t,scope:t.root.scope})}if(e&&'route'===l.type)if(l.pendingInit){let e=l.pendingInit.value;l.pendingInit=null,effector.launch({target:t.template.api.pendingInit,params:e,defer:1,page:t,scope:t.root.scope})}else if(!l.block.visible)return;switch(l.type){case'element':n(e,l.ops.visible);break;case'route':case'list':case'list item':G(t,a);break;default:console.log('unsupported type',l.type)}};G(t,a)}function W(e){e.root.activeSpawns.delete(e.fullID),G(e,H)}function Z(e){J(e,e.root.childSpawns[e.parent.fullID][e.template.id]),J(e,e.template.pages)}function H(e){let{data:t,root:a}=e;switch(t.type){case'element':J(e,a.childSpawns[e.parent.fullID][e.template.id]),function e(t){a.activeSpawns.delete(t.fullID);let l=a.childSpawns[t.fullID];delete a.childSpawns[t.fullID],delete a.leafOps[t.fullID],J(t,t.template.pages);for(let t in l)l[t].forEach(e)}(e),n(0,t.ops.visible);break;case'list':{let a=t.records;for(let e=0;e<a.length;e++){let t=a[e];t.instance&&H(t.instance),t.active=0}e.root.activeSpawns.delete(e.fullID),Z(e);break}case'list item':{let a=t.block;J(a,a.parent.child);let l=a.left,n=a.right;l&&(l.right=n,n||a.parent.lastChild!==a||(a.parent.lastChild=l)),n&&(n.left=l),l||n||a.parent.lastChild!==a||(a.parent.lastChild=null),a.left=null,a.right=null,W(e),Z(e);break}case'route':W(e),Z(e);break;case'block':case'block item':case'rec':case'rec item':W(e)}delete a.childSpawns[e.fullID],delete a.leafOps[e.fullID]}function J(e,t){if(!t)return;let a=t.indexOf(e);-1!==a&&t.splice(a,1)}function K(e,t){if(Array.isArray(t))return t.map((t=>e.map((e=>e[t]))));if('object'==typeof t&&null!==t){let a={};for(let l in t){let n=t[l];a[l]=e.map('function'==typeof n?e=>n(e):e=>e[n])}return a}return e.map((e=>e[t]))}function X(e,t){A(me,'list'),'function'==typeof t&&(effector.is.unit(e)?e={source:e,fn:t}:e.fn=t);let{fn:a,key:l,source:n,fields:r=[]}=e,o=void 0!==l?'function'==typeof l?l:e=>e[l]:(e,t)=>t,i={type:'list',key:effector.is.store(e)?{type:'index'}:{type:'key',key:e.key},childTemplates:[],childCount:0,inParentIndex:-1},{env:d,namespace:f}=me;P(k({name:'list',draft:i,isSvgRoot:0,namespace:f,fn(e,{mount:t}){let l=k({name:'list item',state:{id:-1,store:null},draft:i,isSvgRoot:0,namespace:f,fn({id:e,store:t},{mount:l}){a({store:t,key:e,fields:K(t,r)});let n=effector.createEvent({named:'itemUpdater'});if(t.on(n,((e,t)=>t)),i.itemVisible){let{onMount:e,onState:t}=B({mount:l,state:i.itemVisible,onMount:(e,t)=>({visible:e,leaf:t}),onState:(e,t)=>({visible:t,leaf:e})});e.watch((({visible:e,leaf:t})=>{let a=t.data.block;a.visible=e,a.childInitialized=e,e&&E(i,{parentBlockFragment:a,leaf:t})})),t.watch((({visible:e,leaf:t})=>{let a=t.data.block;a.visible=e,a.childInitialized?Q(e,t):e&&(a.childInitialized=1,E(i,{parentBlockFragment:a,leaf:t}))}))}else l.watch(Se.listItem);return{itemUpdater:n}},env:d}),v=effector.createStore([]),m=n.map((e=>e)),h=effector.sample({source:n,clock:t,fn:(e,t)=>({updates:e,leaf:t,hydration:t.hydration}),greedy:1}),g=effector.createEvent(),b=effector.sample({source:h,clock:[m,g],fn:({leaf:e},t)=>({updates:t,leaf:e,hydration:0}),greedy:1});return effector.sample({source:v,clock:[h,b],greedy:1,fn(e,{updates:t,leaf:a,hydration:r}){let d=a.data,f=a;for(;f;){if('route'===f.data.type&&!f.data.block.visible)return void(d.pendingUpdate=t);f=f.parent}let v=d.block;ie('list update ['+n.shortName+']');let m=Array(t.length).fill(0),h=t.map(o),g=[];for(let a=0;a<e.length;a++){let l=e[a],n=h.indexOf(l.key);-1!==n?(g.push(l),m[n]=1,p(t[n],l.asyncValue)):(l.active=0,l.instance&&H(l.instance),u(l.asyncValue))}for(let e=0;e<t.length;e++){if(m[e])continue;let n=t[e],o=h[e],u=s(a.root.leafOps[a.fullID].group.queue),p={type:'LF',parent:v,child:[],childInitialized:0,visible:0,left:null,right:null},d={type:'listItem',key:o,index:o,active:1,leafData:{type:'list item',block:p,listDraft:i},asyncValue:c({value:n,group:u,onChange(e){d.instance&&effector.launch({target:d.instance.template.api.itemUpdater,params:e,defer:1,page:d.instance,scope:d.instance.root.scope})},onInit(e){d.active&&(r||(d.instance=D(l,{values:{id:o,store:e},parentLeaf:a,mountNode:a.mountNode,svgRoot:a.svgRoot,leafData:d.leafData,opGroup:u,domSubtree:a.root.leafOps[a.fullID].domSubtree,hydration:r,root:a.root})))}})},f=g.length;g.push(d);let b=f>0?g[f-1].leafData:null;if(v.child.push(p),b){let e=b.block;p.left=e;let t=e.right;t?(t.left=p,p.right=t):v.lastChild=p,e.right=p}else v.lastChild=p;r&&(d.instance=D(l,{values:{id:o,store:n},parentLeaf:a,mountNode:a.mountNode,svgRoot:a.svgRoot,leafData:d.leafData,opGroup:u,domSubtree:a.root.leafOps[a.fullID].domSubtree,hydration:r,root:a.root}))}return se('list update ['+n.shortName+']'),0===g.length&&(v.lastChild=null),d.records=g,g},target:v}),{pendingUpdate:g}},env:d}))}function Y({source:e,visible:t,fn:a}){A(me,'route');let{env:l,namespace:n}=me,r=k({name:'route',isSvgRoot:0,namespace:n,env:l,draft:{type:'route',childTemplates:[],childCount:0,inParentIndex:-1},fn(r,{mount:o}){let i;if(effector.is.store(t))i=effector.combine({value:e,visible:t});else{let a=t;i=e.map((e=>({value:e,visible:a(e)})))}let s=k({name:'route item',isSvgRoot:0,namespace:n,env:l,draft:{type:'route',childTemplates:[],childCount:0,inParentIndex:-1},state:{store:null},fn({store:e},{mount:t}){let l=effector.createEvent({named:'itemUpdater'});e.on(l,((e,t)=>t)),a({store:e});let n=effector.sample({source:t,clock:i,fn:(e,{visible:t,value:a})=>({leaf:e,visible:t,value:a}),greedy:1});t.watch(Se.routeItem),n.watch((({leaf:e,visible:t,value:a})=>{if(e.data.block.visible=t,t&&effector.launch({target:l,params:a,defer:1,page:e,scope:e.root.scope}),t){let t=e.parent;for(;t;){if('route'===t.data.type&&!t.data.block.visible)return;t=t.parent}}Q(t,e)}))}});P(s);let{onMount:c,onState:u}=B({mount:o,state:i,onMount:({visible:e,value:t},a)=>({leaf:a,visible:e,value:t}),onState:(e,{visible:t,value:a})=>({leaf:e,visible:t,value:a})}),p=effector.createEvent(),d=effector.sample({source:o,clock:p,greedy:1,fn:(e,t)=>({leaf:e,value:t,visible:1})});return effector.merge([c,u,d]).watch((({leaf:e,visible:t,value:a})=>{let l=e.data;if(l.block.visible=t,t||l.initialized||!l.pendingInit){if(t&&!l.initialized){let t=e.parent;for(;t;){if('route'===t.data.type&&!t.data.block.visible)return void(l.pendingInit={value:a});t=t.parent}}t&&!l.initialized&&(N({parentBlockFragment:l.block,leaf:e,actor:s,values:{store:a}}),l.initialized=1)}else l.pendingInit=null})),{pendingInit:p}}});P(r)}function ee(e){let t='function'==typeof e?e:e.fn,a=k({name:'rec',state:{store:null},isSvgRoot:0,namespace:null,env:null,draft:{type:'rec',childTemplates:[],childCount:0,inParentIndex:0},defer:1,isBlock:1,fn({store:e},{mount:a}){t({store:e,state:e});let l=effector.createEvent({named:'itemUpdater'});return e.on(l,((e,t)=>t)),a.watch(Se.rec),{itemUpdater:l}}});return({store:e,state:t=e})=>{A(me,'(rec instance)');let{env:l,namespace:n}=me;a.deferredInit&&a.deferredInit(),P(k({name:'rec item',isSvgRoot:0,namespace:n,env:l,draft:{type:'recItem',childTemplates:[],childCount:0,inParentIndex:-1},fn(e,{mount:l}){let{onMount:n,onState:r}=B({state:t,mount:l,onMount:(e,t)=>({state:e,leaf:t}),onState:(e,t)=>({state:t,leaf:e})});r.watch((({state:e,leaf:t})=>{G(t,(a=>{effector.launch({target:a.template.api.itemUpdater,params:e,defer:1,page:t,scope:t.root.scope})}))})),n.watch((({leaf:e,state:t})=>{N({parentBlockFragment:e.data.block,leaf:e,actor:a,values:{store:t}})}))}}))}}function te(e,t){if(0===t.length)return e;let a=[e[0]];for(let l=0;l<t.length;l++)a.push(t[l],e[l+1]);return a}Object.defineProperty(exports,'__esModule',{value:1});var effector=require('effector');let ae;ae='undefined'!=typeof performance&&performance.now?()=>performance.now():'undefined'!=typeof process&&process.hrtime?()=>{let e=process.hrtime();return(1e9*e[0]+e[1])/1e6}:()=>Date.now();let le=new Map;const ne=[],re=e=>{let t=le.get(e);t||(t={calls:0,time:0,label:e,childTime:0},le.set(e,t)),t.calls+=1,ne.push({bucket:t,pendingStart:ae()})},oe=e=>{let t=le.get(e),a=ne.pop().pendingStart,l=ae()-a;t.time+=l,ne.length>0&&(ne[ne.length-1].bucket.childTime+=l)};let ie,se;'undefined'!=typeof performance&&performance.mark?(ie=e=>{performance.mark('\u2604\ufe0f '+e+' start'),re(e)},se=e=>{oe(e);try{performance.measure('\u2604\ufe0f '+e,'\u2604\ufe0f '+e+' start')}catch(e){}performance.clearMarks('\u2604\ufe0f '+e+' start'),performance.clearMeasures('\u2604\ufe0f '+e)}):(ie=e=>{re(e)},se=e=>{oe(e)});let ce='undefined'!=typeof requestAnimationFrame?requestAnimationFrame:e=>setTimeout(e,0);const ue={attr:b,data:g,style:h,styleVar:m},pe=(e,t)=>e.includes(t);let de={storeBase(e,t){e.plain.push(t)},storeOnMap(e,t,a,l){var n,r;a.unshift(e.loader),a.push(e.upward),l&&(pe(e.plain,l)||(pe(e.closure,l)||e.closure.push(l),r={type:'closure',of:l},(n=t).before||(n.before=[]),n.before.push(r)))},storeMap(e,t,a){pe(e.plain,t)||pe(a.seq,e.loader)||a.seq.unshift(e.loader)},storeWatch:(e,t,a)=>(e.watch.push({of:t,fn:a}),1),eventPrepend(e,t){t.seq.push(e.upward)},combineBase(e,t,a){e.plain.push(t,a)},combineField(e,t,a){pe(e.plain,t)||a.seq.unshift(e.loader)},splitBase(e,t){e.plain.push(t)},splitMatchStore(e,t,a){pe(e.plain,t)||a.seq.unshift(e.loader)},sampleSource(e,t,a,l){t.current?pe(e.plain,a)||pe(e.closure,a)||e.closure.push(a):e.plain.push(a),e.plain.push(t),pe(e.plain,l)||e.plain.push(l)},sampleTarget(e,t){t.seq.push(e.loader)},sampleSourceLoader:e=>e.loader,sampleSourceUpward:(e,t)=>t&&e.upward},fe=0,ve=0,me=null,he=null;const ge=(e,t)=>e.reg[t.id];let be=null;const ye=['LF','using','element','recItem','rec','block','blockItem','route'];let ke=effector.createEvent({named:'onMount'});ke.watch((({fns:e,element:t})=>{e.forEach((e=>{e(t)}))}));const Ie=[{type:'attr',field:'value'},{type:'attr',field:'checked'},{type:'attr',field:'min'},{type:'attr',field:'max'}],xe={attr:b,data:g,style:h,styleVar:m},we=e=>e.data.block.value;let Se={using(e){let t=e.data;E(t.draft,{parentBlockFragment:t.block,leaf:e})},routeItem(e){let t=e.draft,a=e.data;a.block.visible=1,E(t,{parentBlockFragment:a.block,leaf:e})},block(e){E(e.draft,{parentBlockFragment:e.data.block,leaf:e})},blockItem(e){N({parentBlockFragment:e.data.block,leaf:e,actor:e.draft.itemOf})},rec(e){E(e.draft,{parentBlockFragment:e.data.block,leaf:e})},listItem(e){let t=e.data,a=t.block;a.visible=1,a.childInitialized=1,E(t.listDraft,{parentBlockFragment:a,leaf:e})}};exports.block=({fn:e,env:t,namespace:a="html"})=>{let l=k({name:'block',isSvgRoot:0,namespace:a,env:t,draft:{type:'block',childTemplates:[],childCount:0,inParentIndex:0},isBlock:1,fn({},{mount:t}){e(),t.watch(Se.block)}});return()=>{A(me,'(block instance)');let e={type:'blockItem',childTemplates:[],childCount:0,inParentIndex:-1,itemOf:l},{env:t,namespace:a}=me;P(k({name:'block item',isSvgRoot:0,namespace:a,env:t,draft:e,fn(e,{mount:t}){t.watch(Se.blockItem)}}))}},exports.h=(e,t)=>{let a,r=0,o=0;'function'==typeof t?(r=1,a=t):t&&(o=1,t.fn&&(r=1,a=t.fn),t.\u0254&&('function'==typeof t.\u0254?(r=1,a=t.\u0254):'function'==typeof t.\u0254.fn&&(r=1,a=t.\u0254.fn))),A(me,'h');let i,s=me.env,c=me.namespace,u=c,p='html';u=p='svg'===c?'svg':'html','svg'===e&&(p='svg',u='svg'),me.isBlock||(i='svg'===p?s.document.createElementNS('http://www.w3.org/2000/svg',e):s.document.createElement(e));let d=i,v={type:'element',tag:e,attr:[],data:[],text:[],style:[],styleVar:[],handler:[],stencil:d,seq:[],staticSeq:[],childTemplates:[],childCount:0,inParentIndex:-1,opsAmount:1,node:[]};'foreignObject'===c?(v.attr.push({xmlns:'http://www.w3.org/1999/xhtml'}),u='html'):'svg'===e?(v.attr.push({xmlns:'http://www.w3.org/2000/svg'}),u='svg'):'foreignObject'===e&&(u='foreignObject');let m=k({name:'element',draft:v,isSvgRoot:'svg'===e,namespace:u,fn(e,{mount:i}){let s=effector.createEvent({named:'domElementCreated'});r&&a(),o&&$(t),effector.is.unit(v.visible)&&(v.seq.push({type:'visible',value:v.visible}),L(v.visible));let c={attr:{},data:{},style:{},styleVar:{}};U(v,'attr',c),U(v,'data',c),U(v,'style',c),U(v,'styleVar',c),F(c,((e,t)=>{F(e,((e,a)=>{effector.is.unit(e)?(v.seq.push({type:t,field:a,value:e}),L(e)):v.staticSeq.push({type:t,field:a,value:e})}))})),v.text.forEach((e=>{null!==e.value&&(effector.is.unit(e.value)?(v.seq.push({type:'dynamicText',value:e.value,childIndex:e.index}),L(e.value)):v.seq.push({type:'staticText',value:String(e.value),childIndex:e.index}))})),v.handler.forEach((e=>{F(e.map,((t,a)=>{v.seq.push({type:'handler',for:a,handler:t,options:e.options,domConfig:e.domConfig})}))})),d&&f(d,v.staticSeq),v.seq.forEach((e=>{switch(e.type){case'visible':{let{onMount:t,onState:a}=B({mount:i,state:e.value,onMount:(e,t)=>({leaf:t,value:e,hydration:t.hydration}),onState:(e,t)=>({leaf:e,value:t,hydration:0})});t.watch((({leaf:e,value:t,hydration:a})=>{let n=e.data,r=n.block;if(a&&(l(t,n.ops.visible),t)){let e,t=q(r);if(e=t?t.nextSibling:C(r).firstChild,'#text'===e.nodeName){let t=e;e=e.nextSibling,t.remove()}r.value=e,r.visible=1}E(v,{parentBlockFragment:r,leaf:e,node:r.value,svgRoot:m.isSvgRoot?r.value:null}),t&&n.needToCallNode&&(n.needToCallNode=0,effector.launch({target:ke,params:{element:n.block.value,fns:v.node},page:e,defer:1,scope:e.root.scope})),effector.launch({target:s,params:e,defer:1,page:e,scope:e.root.scope})})),effector.merge([a,t]).watch((({leaf:e,value:t,hydration:a})=>{a||n(t,e.data.ops.visible)}));break}case'attr':case'data':case'style':case'styleVar':{let t=xe[e.type],a=Ie.some((({type:t,field:a})=>e.type===t&&e.field===a)),l=B({mount:s,state:e.value,onMount:(e,t)=>({leaf:t,value:e}),onState:(e,t)=>({leaf:e,value:t})});a?effector.merge([l.onState,l.onMount]).watch((({leaf:a,value:l})=>{t(we(a),e.field,l)})):V(v,{initCtx(a,l){let n=we(l);return t(n,e.field,a),n},runOp(a,l){t(l,e.field,a)},hooks:l});break}case'dynamicText':V(v,{initCtx:(t,a)=>j(a,t,e.childIndex),runOp(e,t){y(t.value,e)},hooks:B({mount:s,state:e.value,onMount:(e,t)=>({leaf:t,value:String(e)}),onState:(e,t)=>({leaf:e,value:String(t)})})});break;case'staticText':s.watch((t=>{j(t,e.value,e.childIndex)}));break;case'handler':{let t=e.handler.graphite.meta.nativeTemplate||null;s.watch((a=>{let l=null;if(t){let e=0,n=a;for(;!e&&n;)n.template===t?(e=1,l=n):n=n.parent}else l=null;we(a).addEventListener(e.for,(t=>{e.options.prevent&&t.preventDefault(),e.options.stop&&t.stopPropagation(),effector.launch({target:e.handler,params:t,page:l,scope:a.root.scope})}),e.domConfig)}));break}}})),i.watch((e=>{let t=e.data;if(!v.visible){let a=t.ops.visible,r=t.block;if(e.hydration){l(1,a);let e,t=q(r);if(e=t?t.nextSibling:C(r).firstChild,'#text'===e.nodeName){let t=e;e=e.nextSibling,t.remove()}r.value=e,r.visible=1}E(v,{parentBlockFragment:r,leaf:e,node:r.value,svgRoot:m.isSvgRoot?r.value:null}),effector.launch({target:s,params:e,defer:1,page:e,scope:e.root.scope}),e.hydration?t.needToCallNode&&(t.needToCallNode=0,effector.launch({target:ke,params:{element:t.block.value,fns:v.node},page:e,defer:1,scope:e.root.scope})):n(1,a)}}))},env:s});P(m)},exports.handler=_,exports.list=X,exports.node=e=>{A(me,'node');let t=me.draft;switch(t.type){case'list':case'listItem':case'using':case'route':case'rec':case'recItem':case'block':case'blockItem':return void console.error('node() hook supported only in h() nodes')}t.node.push(e)},exports.rec=ee,exports.remap=K,exports.route=Y,exports.spec=$,exports.text=(e,...t)=>{Array.isArray(e)?$({text:te(e,t)}):$({text:e})},exports.tree=({source:e,key:t,child:a,fn:l})=>{let n=ee((({store:e})=>{X({source:e,key:t,fn({store:e}){let t=e.map((e=>e[a]||[]));l({store:e,child(){n({store:t})}})}})}));n({store:e})},exports.using=(e,t)=>{let a,l,n,r,o,c;if('function'==typeof t)a=t,n=z(),r=0;else{if(!t)throw Error('using() second argument is missing');a=t.fn,n=t.env?t.env:z(),r=t.hydrate,l=t.onComplete,o=t.onRoot,c=t.scope}R(e,'using() first argument is missing');let u={scope:c,env:n,activeSpawns:new Set,childSpawns:{},leafOps:{}},p=e.namespaceURI,d=e.tagName.toLowerCase(),f={type:'using',childTemplates:[],childCount:0,inParentIndex:-1},v=k({name:'using',draft:f,isSvgRoot:'svg'===d,namespace:'http://www.w3.org/2000/svg'===p?'svg':'foreignobject'===d?'foreignObject':'html',fn(e,{mount:t}){a(),t.watch(Se.using)},env:n}),m={type:'using',child:[],value:e},h=i({onComplete:l}),g=D(v,{parentLeaf:he||null,mountNode:e,svgRoot:v.isSvgRoot?e:he?he.svgRoot:null,leafData:{type:'using',draft:f,element:e,block:m},opGroup:s(h),domSubtree:s(h),hydration:r,root:u});if(o&&o({template:v,leaf:g}),h.onDrain&&!h.rafID){let e=h.onDrain;h.onDrain=null,e()}},exports.val=(e,...t)=>t.every((e=>!effector.is.store(e)))?te(e,t).join(''):effector.combine(t,(t=>te(e,t).join(''))),exports.variant=({source:e,cases:t,key:a})=>{let l;A(me,'variant'),R(effector.is.unit(e),'variant({source}) should be unit'),l='function'==typeof a?a:null==a?e=>String(e):e=>String(e[a]);let n=0;for(let a in t)'__'!==a?Y({source:e,visible:e=>l(e)===a,fn:t[a]}):n=1;if(n){let a=Object.keys(t);Y({source:e,visible:e=>!a.includes(l(e)),fn:t.__})}}; | ||
//# sourceMappingURL=forest.cjs.js.map |
@@ -1,2 +0,2 @@ | ||
((e,t)=>{'object'==typeof exports&&'undefined'!=typeof module?t(exports,require('effector')):'function'==typeof define&&define.amd?define(['exports','effector'],t):t((e='undefined'!=typeof globalThis?globalThis:e||self).forest={},e.effector)})(this,((e,effector)=>{function t(e,t){e.cursor[t].prev&&(e.cursor[t].prev.cursor[t].next=e.cursor[t].next),e.cursor[t].next&&(e.cursor[t].next.cursor[t].prev=e.cursor[t].prev),e.queue[t].last===e&&(e.queue[t].last=e.cursor[t].prev),e.queue[t].first===e&&(e.queue[t].first=e.cursor[t].next),e.cursor[t].prev=null,e.cursor[t].next=null}function a(e){e.status='active',((e,t)=>{t.cursor.prev&&(t.cursor.prev.cursor.next=t.cursor.next),t.cursor.next&&(t.cursor.next.cursor.prev=t.cursor.prev),e.last===t&&(e.last=t.cursor.prev),e.first===t&&(e.first=t.cursor.next),t.cursor.prev=null,t.cursor.next=null})(l(e),e)}function l(e){return e.group.activeChilds[e.priority]}function n(e,t){t.value.active=t.value.pending=e,'active'!==t.status&&a(t)}function r(e,n){if(n.value.active===e)return n.value.pending=e,void('pending'===n.status&&(a(n),l(n).first||t(n.group,n.priority)));'active'===n.status&&(n.status='pending',l(n).first||((e,t)=>{e.queue[t].last?(e.cursor[t].prev=e.queue[t].last,e.queue[t].last.cursor[t].next=e,e.queue[t].last=e):e.queue[t].first=e.queue[t].last=e})(n.group,n.priority),((e,t)=>{e.last?(t.cursor.prev=e.last,e.last.cursor.next=t,e.last=t):e.first=e.last=t})(l(n),n)),n.value.pending=e,n.group.queue.rafID||(n.group.queue.rafID=de(n.group.queue.execQueue))}function o(e){ue('execQueue');let l,n,r=ne(),o=0;e:for(;e.props.first||e.tree.first||e.data.first;){if(ne()-r>=re){o=1;break e}let i=!!e.props.first;for(i&&ue('props');l=e.props.first;){for(;n=l.activeChilds.props.first;){if(ne()-r>=re){o=1,pe('props');break e}n.runOp(n.value.pending),n.value.active=n.value.pending,a(n)}t(l,'props')}i&&pe('props');let s=!!e.tree.first;for(s&&ue('tree');l=e.tree.first;){for(;n=l.activeChilds.tree.first;){if(ne()-r>=re){o=1,pe('tree');break e}n.runOp(n.value.pending),n.value.active=n.value.pending,a(n)}t(l,'tree')}s&&pe('tree');let c=!!e.data.first;for(c&&ue('data');l=e.data.first;){for(;n=l.activeChilds.data.first;){if(ne()-r>=re){o=1,pe('data');break e}n.runOp(n.value.pending),n.value.active=n.value.pending,a(n)}t(l,'data')}c&&pe('data')}if(pe('execQueue'),o)e.rafID=de(e.execQueue);else if(e.rafID=null,e.onDrain){let t=e.onDrain;e.onDrain=null,t()}}function i({value:e,runOp:t,group:a,priority:l}){return{value:{active:e,pending:e},runOp:t,status:'active',priority:l,group:a,cursor:{prev:null,next:null}}}function s({onComplete:e}){let t={props:{first:null,last:null},tree:{first:null,last:null},data:{first:null,last:null},rafID:null,execQueue(){},onDrain:e};return t.execQueue=o.bind(null,t),t}function c(e){return{ops:[],queue:e,activeChilds:{props:{first:null,last:null},tree:{first:null,last:null},data:{first:null,last:null}},cursor:{props:{prev:null,next:null},tree:{prev:null,next:null},data:{prev:null,next:null}}}}function u({value:e,group:t,onInit:a,onChange:l}){let n=i({value:e,group:t,runOp(e){o.status='A',l(e)},priority:'data'}),o={status:'IA',value:n.value,ops:{init:i({value:0,group:t,runOp(e){o.status='A',a(o.value.active)},priority:'data'}),change:n,terminate:i({value:0,group:t,runOp(e){o.status='T'},priority:'data'})}};return r(1,o.ops.init),o}function p(e){switch(e.status){case'I':case'T':case'AT':return;case'A':e.status='AT',r(1,e.ops.terminate);break;case'AA':e.status='AT',r(1,e.ops.terminate),r(e.value.active,e.ops.change);break;case'IA':e.status='T',r(0,e.ops.init)}}function d(e,t){switch(t.status){case'I':case'T':return;case'A':t.value.active!==e&&(t.status='AA',r(e,t.ops.change));break;case'AA':t.value.active===e?(t.status='A',r(e,t.ops.change)):t.value.pending!==e&&(t.value.pending=e);break;case'IA':t.value.active=t.value.pending=e}}function f(e){switch(e=String(e)){case'__proto__':case'__defineGetter__':case'__defineSetter__':case'constructor':case'prototype':case'hasOwnProperty':case'toString':case'valueOf':case'setProperty':case'removeProperty':return'forbidden';default:return e.replace(/[^a-zA-Z0-9\-_]/g,'')}}function m(e,t){for(let a=0;a<t.length;a++){let{type:l,field:n,value:r}=t[a];fe[l](e,n,r)}}function h(e){return''!==e&&0!==e&&'0'!==e&&(0==e||null==e)}function v(e,t,a){h(a)?e.style.removeProperty(`--${t}`):e.style.setProperty(`--${t}`,`${a}`)}function g(e,t,a){h(a)?delete e.style[t]:e.style[t]=`${a}`}function b(e,t,a){h(a)?delete e.dataset[t]:e.dataset[t]=`${a}`}function y(e,t,a){if(h(a)){switch(t){case'value':delete e.value;break;case'checked':e.checked=0;break;case'spellcheck':if(0==a)return void e.setAttribute('spellcheck','false')}e.removeAttribute(t)}else{switch(t){case'value':e.value=`${a}`;break;case'checked':e.checked=`${a}`}e.setAttribute(t,`${a}`)}}function k(e,t){e.replaceData(0,(e.textContent||'').length,String(t))}function I({fn:e,state:t={},defer:a=0,name:l="",draft:n,isSvgRoot:r,namespace:o,env:i,isBlock:s=0}){let c=be,u={id:++ve,name:l,plain:[],watch:[],nameMap:{},pages:[],closure:[],childTemplates:[],handlers:he,upward:effector.step.filter({fn(e,t,a){if(!a.page){if(!a.parent||!a.parent.page)return 1;a.page=a.parent.page}if(!a.page.root.activeSpawns.has(a.page.fullID))return console.count('inactive page upward'),0;let l=[a.page.template],n=[a.page];{let e=a.page.parent;for(;e;)n.push(e),l.push(e.template),e=e.parent}return a.node.next.forEach((t=>{let r=t.meta.nativeTemplate;if(r)if(l.includes(r)){let o=n[l.indexOf(r)];effector.launch({target:t,params:e,defer:1,page:o,stack:a,scope:a.scope})}else console.error('context drift',{stack:a,node:t});else effector.launch({target:t,params:e,defer:1,page:a.page,stack:a,scope:a.scope})})),0}}),loader:effector.step.filter({fn(e,t,a){if(a.parent){let t=a.scope?a.scope.graphite.id:null;if(a.page){if(!a.page.root.activeSpawns.has(a.page.fullID))return console.count('inactive page loader'),0;if(a.page.template===u)return 1;if(a.page.root.childSpawns[a.page.fullID][u.id])a.page.root.childSpawns[a.page.fullID][u.id].forEach((l=>{(!t||l.root.scope&&t===l.root.scope.graphite.id)&&effector.launch({params:e,target:a.node,page:l,defer:1,scope:a.scope})}));else{let l=a.page.fullID,n='rec'===a.page.template.name;u.pages.forEach((r=>{if(!t||r.root.scope&&t===r.root.scope.graphite.id)if(r.fullID===l||r.fullID.startsWith(`${l}_`)){let t=1;if(n){let e=a.page.template.id,l=r.parent;for(;l&&l!==a.page;){if(l.template.id===e){t=0;break}l=l.parent}}t&&effector.launch({params:e,target:a.node,page:r,defer:1,scope:a.scope})}else l.startsWith(`${r.fullID}_`)&&effector.launch({params:e,target:a.node,page:a.page,defer:1,scope:a.scope})}))}}else u.pages.forEach((l=>{(!t||l.root.scope&&t===l.root.scope.graphite.id)&&effector.launch({params:e,target:a.node,page:l,defer:1,scope:a.scope})}));return 0}return 1}}),parent:c,node:null,api:null,trigger:{mount:effector.createEvent({named:'mount'})},draft:n,isSvgRoot:r,namespace:o,env:i,isBlock:s||!(!c||!c.isBlock)};c&&c.childTemplates.push(u);let p=effector.createNode({meta:{template:u}});return u.node=p,be=u,a?u.deferredInit=()=>{let a=be;be=u,u.deferredInit=null;try{effector.withRegion(p,(()=>{let a=effector.restore(t);u.api=e(a,u.trigger),u.nameMap=a}))}finally{be=a}}:effector.withRegion(p,(()=>{let a=effector.restore(t);u.api=e(a,u.trigger),u.nameMap=a})),be=c,u}function x(e,t){let a;switch(a=t?t.getState(e):e.current,e.type){case'list':return[...a];case'shape':return{...a};default:return a}}function w(e,t,a){let l=t;for(;l&&!ke(l,e);)l=l.parent;return l?ke(l,e):a?(a.getState(e),a.reg[e.id]):e}function S(e,t,a){return w(e,t,a).current}function D(e,t){ke(t,e)||(t.reg[e.id]=w(e,t.parent,t.root.scope))}function C(e,t,a){t in a||(a[t]=[]),a[t].push(...e)}function T(e,{values:t={},parentLeaf:a,mountNode:l,svgRoot:n,leafData:r,opGroup:o,domSubtree:i,hydration:s,root:c}){function u(e){if(e.before)for(let t=0;t<e.before.length;t++){let a=e.before[t];switch(a.type){case'map':{let t,l=a.from;if(!a.fn&&!l)break;l&&(D(l,f),t=d[l.id].current),d[e.id].current=a.fn?a.fn(t):t;break}case'field':{let t=a.from;D(t,f),d[e.id].current[a.field]=d[t.id].current;break}case'closure':D(a.of,f)}}}function p(e,t,a){let l;t.stop=1;try{for(;t.i<e.length;)l=e[t.i],t.i++,l.fn(a[l.of.id]?a[l.of.id].current:S(l.of,f.parent,f.root.scope))}catch(e){console.error(e),t.stop=0}}let d={},f={draft:e.draft,svgRoot:n,data:r,parent:a,hydration:s,mountNode:l,root:c,id:++ge,fullID:'',reg:d,template:e};e.pages.push(f);let m=ye;ye=f,a&&C([f],e.id,c.childSpawns[a.fullID]),f.fullID=a?`${a.fullID}_${f.id}`:`${f.id}`,c.childSpawns[f.fullID]={},c.activeSpawns.add(f.fullID),c.leafOps[f.fullID]={group:o,domSubtree:i};for(let t=0;t<e.closure.length;t++){let a=e.closure[t],l=a,n=f.parent;e:for(;n;){if(ke(n,a)){l=ke(n,a);break e}n=n.parent}!n&&c.scope&&(c.scope.getState(a),l=c.scope.reg[a.id]),d[a.id]=l}for(let t=0;t<e.plain.length;t++){let a=e.plain[t],l={id:a.id,current:x(a,c.scope)};d[a.id]=l}for(let a in t){let l=e.nameMap[a].stateRef.id;d[l]={id:l,current:t[a]}}e.closure.forEach(u),e.plain.forEach(u);let h={i:0,stop:0};for(;!h.stop;)p(e.watch,h,d);if(a)for(let e in c.childSpawns[f.fullID])C(c.childSpawns[f.fullID][e],e,c.childSpawns[a.fullID]);if(Ie)Ie.steps.push({target:e.trigger.mount,params:f,defer:1,page:f,scope:c.scope});else{let t;Ie={parent:Ie,steps:[{target:e.trigger.mount,params:f,defer:1,page:f,scope:c.scope}]};do{for(;t=Ie.steps.shift();)Ie={parent:Ie,steps:[]},effector.launch(t)}while(Ie=Ie.parent)}return ye=m,f}function O(e){let t=e.parent;for(;'element'!==t.type&&'using'!==t.type;)t=t.parent;return t?t.value:null}function q(e){if(!e.visible)return null;switch(e.type){case'text':case'element':return e;case'LF':case'route':case'rec':case'recItem':case'block':case'blockItem':for(let t=e.child.length-1;t>=0;t--){let a=q(e.child[t]);if(a)return a}return null;case'list':{let t=e.lastChild;if(!t)return null;for(;t;){let e=q(t);if(e)return e;t=t.left}return null}default:return null}}function R(e){switch(e.type){case'using':return null;case'LF':{let t=e.left;for(;t;){let e=q(t);if(e)return e;t=t.left}return R(e.parent)}case'element':case'text':case'route':case'rec':case'recItem':case'block':case'blockItem':case'list':{let t=e.parent;for(let a=e.index-1;a>=0;a--){let e=t.child[a];if(!e)continue;let l=q(e);if(l)return l}switch(t.type){case'element':case'using':return null}return R(t)}default:return null}}function A(e){let t=R(e);return t?t.value:null}function P(e,t){if(!e)throw Error(t)}function E(e,t){if(!e)throw Error(`${t}() called outside from using() closure`)}function N(e){if(!be)return;let{draft:t}=e;if('listItem'!==t.type&&'rec'!==t.type)switch(be.draft.type){case'element':case'using':case'route':case'list':case'rec':case'recItem':case'block':case'blockItem':t.inParentIndex=be.draft.childCount,be.draft.childCount+=1,be.draft.childTemplates.push(e);break;default:console.warn(`unexpected currentTemplate type ${be.draft.type}`)}}function M(e,{parentBlockFragment:t,leaf:a,node:l,svgRoot:n,values:r}){e.childTemplates.forEach((e=>{B({parentBlockFragment:t,leaf:a,node:l,svgRoot:n,values:r,actor:e})}))}function B({parentBlockFragment:e,leaf:t,node:a=t.mountNode,actor:l,svgRoot:n,values:r}){let o;P(xe.includes(e.type),`incorrect parent ${e.type}`);let{draft:s}=l,{queue:u}=t.root.leafOps[t.fullID].group,p=c(u),d=t.root.leafOps[t.fullID].domSubtree,f=d;switch(s.type){case'route':{let t={type:'route',parent:e,child:[],visible:0,index:s.inParentIndex};e.child[s.inParentIndex]=t,o={type:'route',block:t,ops:{},initialized:0,pendingInit:null};break}case'element':{let a;if(l.isBlock){let e,l,n=t;for(;n&&(!l||!e);){n.template.env&&(e=n.template.env);let{draft:t}=n;'element'===t.type&&('svg'===t.tag?l='svg':'foreignObject'===t.tag&&(l='html')),n=n.parent}l||(l='html'),e&&(a='svg'===l?e.document.createElementNS('http://www.w3.org/2000/svg',s.tag):e.document.createElement(s.tag),m(a,s.staticSeq))}else a=s.stencil.cloneNode();let n={type:'element',parent:e,child:[],value:a,visible:0,index:s.inParentIndex};e.child[s.inParentIndex]=n,o={type:'element',block:n,ops:{visible:i({value:0,priority:'tree',runOp(e){if(e){F(n);let e=o;e.needToCallNode&&(e.needToCallNode=0,effector.launch({target:we,params:{element:n.value,fns:s.node},page:h,scope:t.root.scope})),n.visible=1}else n.value.remove(),n.visible=0},group:d})},needToCallNode:s.node.length>0},f=c(u);break}case'list':{let t={type:'list',parent:e,child:[],lastChild:null,visible:1,index:s.inParentIndex};e.child[s.inParentIndex]=t,o={type:'list',draft:s,block:t,records:[],pendingUpdate:null};break}case'using':case'listItem':break;case'rec':{let t={type:'rec',parent:e,child:[],visible:1,index:s.inParentIndex};e.child[s.inParentIndex]=t,o={type:'rec',block:t};break}case'recItem':{let t={type:'recItem',parent:e,child:[],visible:1,index:s.inParentIndex};e.child[s.inParentIndex]=t,o={type:'rec item',block:t};break}case'block':{let t={type:'block',parent:e,child:[],visible:1,index:s.inParentIndex};e.child[s.inParentIndex]=t,o={type:'block',block:t};break}case'blockItem':{let t={type:'blockItem',parent:e,child:[],visible:1,index:s.inParentIndex};e.child[s.inParentIndex]=t,o={type:'block item',block:t};break}default:console.warn(`unexpected draft type ${s.type}`)}let h=T(l,{values:r,parentLeaf:t,mountNode:a,svgRoot:n||t.svgRoot,leafData:o,opGroup:p,domSubtree:f,hydration:t.hydration,root:t.root})}function F(e){let t=A(e);t?t.after(e.value):O(e).prepend(e.value),e.visible=1}function _({mount:e,state:t,onMount:a,onState:l}){return{onMount:effector.sample({source:t,clock:e,fn:a,greedy:1}),onState:effector.sample({source:e,clock:t,fn:l,greedy:1})}}function $(e,t){for(let a in e)t(e[a],a)}function V(e,t){if(!be)return;let a=be.draft;P('element'===a.type,`"handler" extension can be used only with element nodes, got "${a.type}"`),void 0===t&&(t=e,e={});for(let e in t)P(effector.is.unit(t[e]),`handler for "${e}" should be event`);let{passive:l=0,capture:n=0,prevent:r=0,stop:o=0}=e;a.handler.push({options:{prevent:r,stop:o},domConfig:{passive:r?0:l,capture:n},map:t})}function U(e){E(be,'spec');let t=be.draft;switch(t.type){case'list':return void(e.visible&&(t.itemVisible=e.visible));case'listItem':case'using':case'route':case'rec':case'recItem':case'block':case'blockItem':return}if(e.attr&&t.attr.push(e.attr),e.data&&t.data.push(e.data),'text'in e){let a=e.text,l=t.childCount;Array.isArray(a)?(t.text.push(...a.map(((e,t)=>({index:t+l,value:e})))),t.childCount+=a.length):(t.text.push({index:l,value:a}),t.childCount+=1)}if(e.style){let a={};for(let t in e.style)a[f(t)]=e.style[t];t.style.push(a)}if(e.styleVar&&t.styleVar.push(e.styleVar),e.visible&&(t.visible=e.visible),e.handler){let t=e.handler;'object'==typeof t.on?V(t.config||{},t.on):V(t)}e.\u0254&&U(e.\u0254)}function j(e,{initCtx:t,runOp:a,hooks:{onMount:l,onState:n}}){let o=e.opsAmount++;l.watch((({value:e,leaf:l})=>{let n=i({value:e,priority:'props',runOp(e){a(e,r)},group:l.root.leafOps[l.fullID].group});l.root.leafOps[l.fullID].group.ops[o]=n;let r=t(e,l)})),n.watch((({value:e,leaf:t})=>{r(e,t.root.leafOps[t.fullID].group.ops[o])}))}function L(e,t,a){e[t].forEach((e=>{$(e,((e,l)=>{switch(t){case'data':case'styleVar':a[t][l]=e;break;case'attr':a.attr['xlink:href'===l?'href':l]=e;break;case'style':l.startsWith('--')?a.styleVar[l.slice(2)]=e:a.style[l]=e}}))}))}function z(e,t,a){let l=e.data.block,n={type:'text',parent:l,visible:0,index:a,value:null};if(l.child[a]=n,e.hydration){let a=R(n);if(a)switch(a.type){case'text':n.value=e.root.env.document.createTextNode(t),a.value.after(n.value);break;case'element':n.value=a.value.nextSibling,k(n.value,t)}else{let e=O(n);n.value=e.firstChild,k(n.value,t)}n.visible=1}else n.value=e.root.env.document.createTextNode(t),F(n);return n}function G(e){let t=e.stateRef,a=be;a.plain.includes(t)||a.closure.includes(t)||a.closure.push(t)}function Q(){if('undefined'!=typeof document)return{document};throw Error('your environment has no document')}function W(e,t){let a=e.root.childSpawns[e.fullID];for(let e in a){let l=a[e];for(let e=0;e<l.length;e++)t(l[e])}}function Z(e,t){let a=t=>{let l=t.data;if(e&&'list'===l.type&&l.pendingUpdate){let e=l.pendingUpdate;l.pendingUpdate=null,effector.launch({target:t.template.api.pendingUpdate,params:e,defer:1,page:t,scope:t.root.scope})}if(e&&'route'===l.type)if(l.pendingInit){let e=l.pendingInit.value;l.pendingInit=null,effector.launch({target:t.template.api.pendingInit,params:e,defer:1,page:t,scope:t.root.scope})}else if(!l.block.visible)return;switch(l.type){case'element':r(e,l.ops.visible);break;case'route':case'list':case'list item':W(t,a);break;default:console.log('unsupported type',l.type)}};W(t,a)}function H(e){e.root.activeSpawns.delete(e.fullID),W(e,K)}function J(e){X(e,e.root.childSpawns[e.parent.fullID][e.template.id]),X(e,e.template.pages)}function K(e){let{data:t,root:a}=e;switch(t.type){case'element':X(e,a.childSpawns[e.parent.fullID][e.template.id]),function e(t){a.activeSpawns.delete(t.fullID);let l=a.childSpawns[t.fullID];delete a.childSpawns[t.fullID],delete a.leafOps[t.fullID],X(t,t.template.pages);for(let t in l)l[t].forEach(e)}(e),r(0,t.ops.visible);break;case'list':{let a=t.records;for(let e=0;e<a.length;e++){let t=a[e];t.instance&&K(t.instance),t.active=0}e.root.activeSpawns.delete(e.fullID),J(e);break}case'list item':{let a=t.block;X(a,a.parent.child);let l=a.left,n=a.right;l&&(l.right=n,n||a.parent.lastChild!==a||(a.parent.lastChild=l)),n&&(n.left=l),l||n||a.parent.lastChild!==a||(a.parent.lastChild=null),a.left=null,a.right=null,H(e),J(e);break}case'route':H(e),J(e);break;case'block':case'block item':case'rec':case'rec item':H(e)}delete a.childSpawns[e.fullID],delete a.leafOps[e.fullID]}function X(e,t){if(!t)return;let a=t.indexOf(e);-1!==a&&t.splice(a,1)}function Y(e,t){if(Array.isArray(t))return t.map((t=>e.map((e=>e[t]))));if('object'==typeof t&&null!==t){let a={};for(let l in t){let n=t[l];a[l]=e.map('function'==typeof n?e=>n(e):e=>e[n])}return a}return e.map((e=>e[t]))}function ee(e,t){E(be,'list'),'function'==typeof t&&(effector.is.unit(e)?e={source:e,fn:t}:e.fn=t);let{fn:a,key:l,source:n,fields:r=[]}=e,o=void 0!==l?'function'==typeof l?l:e=>e[l]:(e,t)=>t,i={type:'list',key:effector.is.store(e)?{type:'index'}:{type:'key',key:e.key},childTemplates:[],childCount:0,inParentIndex:-1},{env:s,namespace:f}=be;N(I({name:'list',draft:i,isSvgRoot:0,namespace:f,fn(e,{mount:t}){let l=I({name:'list item',state:{id:-1,store:null},draft:i,isSvgRoot:0,namespace:f,fn({id:e,store:t},{mount:l}){a({store:t,key:e,fields:Y(t,r)});let n=effector.createEvent({named:'itemUpdater'});if(t.on(n,((e,t)=>t)),i.itemVisible){let{onMount:e,onState:t}=_({mount:l,state:i.itemVisible,onMount:(e,t)=>({visible:e,leaf:t}),onState:(e,t)=>({visible:t,leaf:e})});e.watch((({visible:e,leaf:t})=>{let a=t.data.block;a.visible=e,a.childInitialized=e,e&&M(i,{parentBlockFragment:a,leaf:t})})),t.watch((({visible:e,leaf:t})=>{let a=t.data.block;a.visible=e,a.childInitialized?Z(e,t):e&&(a.childInitialized=1,M(i,{parentBlockFragment:a,leaf:t}))}))}else l.watch(Te.listItem);return{itemUpdater:n}},env:s}),m=effector.createStore([]),h=n.map((e=>e)),v=effector.sample({source:n,clock:t,fn:(e,t)=>({updates:e,leaf:t,hydration:t.hydration}),greedy:1}),g=effector.createEvent(),b=effector.sample({source:v,clock:[h,g],fn:({leaf:e},t)=>({updates:t,leaf:e,hydration:0}),greedy:1});return effector.sample({source:m,clock:[v,b],greedy:1,fn(e,{updates:t,leaf:a,hydration:r}){let s=a.data,f=a;for(;f;){if('route'===f.data.type&&!f.data.block.visible)return void(s.pendingUpdate=t);f=f.parent}let m=s.block;ue('list update ['+n.shortName+']');let h=Array(t.length).fill(0),v=t.map(o),g=[];for(let a=0;a<e.length;a++){let l=e[a],n=v.indexOf(l.key);-1!==n?(g.push(l),h[n]=1,d(t[n],l.asyncValue)):(l.active=0,l.instance&&K(l.instance),p(l.asyncValue))}for(let e=0;e<t.length;e++){if(h[e])continue;let n=t[e],o=v[e],s=c(a.root.leafOps[a.fullID].group.queue),p={type:'LF',parent:m,child:[],childInitialized:0,visible:0,left:null,right:null},d={type:'listItem',key:o,index:o,active:1,leafData:{type:'list item',block:p,listDraft:i},asyncValue:u({value:n,group:s,onChange(e){d.instance&&effector.launch({target:d.instance.template.api.itemUpdater,params:e,defer:1,page:d.instance,scope:d.instance.root.scope})},onInit(e){d.active&&(r||(d.instance=T(l,{values:{id:o,store:e},parentLeaf:a,mountNode:a.mountNode,svgRoot:a.svgRoot,leafData:d.leafData,opGroup:s,domSubtree:a.root.leafOps[a.fullID].domSubtree,hydration:r,root:a.root})))}})},f=g.length;g.push(d);let b=f>0?g[f-1].leafData:null;if(m.child.push(p),b){let e=b.block;p.left=e;let t=e.right;t?(t.left=p,p.right=t):m.lastChild=p,e.right=p}else m.lastChild=p;r&&(d.instance=T(l,{values:{id:o,store:n},parentLeaf:a,mountNode:a.mountNode,svgRoot:a.svgRoot,leafData:d.leafData,opGroup:s,domSubtree:a.root.leafOps[a.fullID].domSubtree,hydration:r,root:a.root}))}return pe('list update ['+n.shortName+']'),0===g.length&&(m.lastChild=null),s.records=g,g},target:m}),{pendingUpdate:g}},env:s}))}function te({source:e,visible:t,fn:a}){E(be,'route');let{env:l,namespace:n}=be,r=I({name:'route',isSvgRoot:0,namespace:n,env:l,draft:{type:'route',childTemplates:[],childCount:0,inParentIndex:-1},fn(r,{mount:o}){let i;if(effector.is.store(t))i=effector.combine({value:e,visible:t});else{let a=t;i=e.map((e=>({value:e,visible:a(e)})))}let s=I({name:'route item',isSvgRoot:0,namespace:n,env:l,draft:{type:'route',childTemplates:[],childCount:0,inParentIndex:-1},state:{store:null},fn({store:e},{mount:t}){let l=effector.createEvent({named:'itemUpdater'});e.on(l,((e,t)=>t)),a({store:e});let n=effector.sample({source:t,clock:i,fn:(e,{visible:t,value:a})=>({leaf:e,visible:t,value:a}),greedy:1});t.watch(Te.routeItem),n.watch((({leaf:e,visible:t,value:a})=>{if(e.data.block.visible=t,t&&effector.launch({target:l,params:a,defer:1,page:e,scope:e.root.scope}),t){let t=e.parent;for(;t;){if('route'===t.data.type&&!t.data.block.visible)return;t=t.parent}}Z(t,e)}))}});N(s);let{onMount:c,onState:u}=_({mount:o,state:i,onMount:({visible:e,value:t},a)=>({leaf:a,visible:e,value:t}),onState:(e,{visible:t,value:a})=>({leaf:e,visible:t,value:a})}),p=effector.createEvent(),d=effector.sample({source:o,clock:p,greedy:1,fn:(e,t)=>({leaf:e,value:t,visible:1})});return effector.merge([c,u,d]).watch((({leaf:e,visible:t,value:a})=>{let l=e.data;if(l.block.visible=t,t||l.initialized||!l.pendingInit){if(t&&!l.initialized){let t=e.parent;for(;t;){if('route'===t.data.type&&!t.data.block.visible)return void(l.pendingInit={value:a});t=t.parent}}t&&!l.initialized&&(B({parentBlockFragment:l.block,leaf:e,actor:s,values:{store:a}}),l.initialized=1)}else l.pendingInit=null})),{pendingInit:p}}});N(r)}function ae(e){let t='function'==typeof e?e:e.fn,a=I({name:'rec',state:{store:null},isSvgRoot:0,namespace:null,env:null,draft:{type:'rec',childTemplates:[],childCount:0,inParentIndex:0},defer:1,isBlock:1,fn({store:e},{mount:a}){t({store:e,state:e});let l=effector.createEvent({named:'itemUpdater'});return e.on(l,((e,t)=>t)),a.watch(Te.rec),{itemUpdater:l}}});return({store:e,state:t=e})=>{E(be,'(rec instance)');let{env:l,namespace:n}=be;a.deferredInit&&a.deferredInit(),N(I({name:'rec item',isSvgRoot:0,namespace:n,env:l,draft:{type:'recItem',childTemplates:[],childCount:0,inParentIndex:-1},fn(e,{mount:l}){let{onMount:n,onState:r}=_({state:t,mount:l,onMount:(e,t)=>({state:e,leaf:t}),onState:(e,t)=>({state:t,leaf:e})});r.watch((({state:e,leaf:t})=>{W(t,(a=>{effector.launch({target:a.template.api.itemUpdater,params:e,defer:1,page:t,scope:t.root.scope})}))})),n.watch((({leaf:e,state:t})=>{B({parentBlockFragment:e.data.block,leaf:e,actor:a,values:{store:t}})}))}}))}}function le(e,t){if(0===t.length)return e;let a=[e[0]];for(let l=0;l<t.length;l++)a.push(t[l],e[l+1]);return a}let ne,re=1e3;ne='undefined'!=typeof performance&&performance.now?()=>performance.now():'undefined'!=typeof process&&process.hrtime?()=>{let e=process.hrtime();return(1e9*e[0]+e[1])/1e6}:()=>Date.now();let oe=new Map;const ie=[],se=e=>{let t=oe.get(e);t||(t={calls:0,time:0,label:e,childTime:0},oe.set(e,t)),t.calls+=1,ie.push({bucket:t,pendingStart:ne()})},ce=e=>{let t=oe.get(e),a=ie.pop().pendingStart,l=ne()-a;t.time+=l,ie.length>0&&(ie[ie.length-1].bucket.childTime+=l)};let ue,pe;'undefined'!=typeof performance&&performance.mark?(ue=e=>{performance.mark('\u2604\ufe0f '+e+' start'),se(e)},pe=e=>{ce(e);try{performance.measure('\u2604\ufe0f '+e,'\u2604\ufe0f '+e+' start')}catch(e){}performance.clearMarks('\u2604\ufe0f '+e+' start'),performance.clearMeasures('\u2604\ufe0f '+e)}):(ue=e=>{se(e)},pe=e=>{ce(e)});let de='undefined'!=typeof requestAnimationFrame?requestAnimationFrame:e=>setTimeout(e,0);const fe={attr:y,data:b,style:g,styleVar:v},me=(e,t)=>e.includes(t);let he={storeBase(e,t){e.plain.push(t)},storeOnMap(e,t,a,l){a.unshift(e.loader),a.push(e.upward),l&&(me(e.plain,l)||(me(e.closure,l)||e.closure.push(l),((e,t)=>{e.before||(e.before=[]),e.before.push(t)})(t,{type:'closure',of:l})))},storeMap(e,t,a){me(e.plain,t)||me(a.seq,e.loader)||a.seq.unshift(e.loader)},storeWatch:(e,t,a)=>(e.watch.push({of:t,fn:a}),1),eventPrepend(e,t){t.seq.push(e.upward)},combineBase(e,t,a){e.plain.push(t,a)},combineField(e,t,a){me(e.plain,t)||a.seq.unshift(e.loader)},splitBase(e,t){e.plain.push(t)},splitMatchStore(e,t,a){me(e.plain,t)||a.seq.unshift(e.loader)},sampleStoreSource(e,t){me(e.plain,t)||me(e.closure,t)||e.closure.push(t)},sampleNonStoreSource(e,t,a,l){e.plain.push(t,a,l)},sampleTarget(e,t){t.seq.push(e.loader)},sampleSourceLoader:e=>e.loader,sampleSourceUpward:(e,t)=>t&&e.upward},ve=0,ge=0,be=null,ye=null;const ke=(e,t)=>e.reg[t.id];let Ie=null;const xe=['LF','using','element','recItem','rec','block','blockItem','route'];let we=effector.createEvent({named:'onMount'});we.watch((({fns:e,element:t})=>{e.forEach((e=>{e(t)}))}));const Se=[{type:'attr',field:'value'},{type:'attr',field:'checked'},{type:'attr',field:'min'},{type:'attr',field:'max'}],De={attr:y,data:b,style:g,styleVar:v},Ce=e=>e.data.block.value;let Te={using(e){let t=e.data;M(t.draft,{parentBlockFragment:t.block,leaf:e})},routeItem(e){let t=e.draft,a=e.data;a.block.visible=1,M(t,{parentBlockFragment:a.block,leaf:e})},block(e){M(e.draft,{parentBlockFragment:e.data.block,leaf:e})},blockItem(e){B({parentBlockFragment:e.data.block,leaf:e,actor:e.draft.itemOf})},rec(e){M(e.draft,{parentBlockFragment:e.data.block,leaf:e})},listItem(e){let t=e.data,a=t.block;a.visible=1,a.childInitialized=1,M(t.listDraft,{parentBlockFragment:a,leaf:e})}};e.block=({fn:e,env:t,namespace:a="html"})=>{let l=I({name:'block',isSvgRoot:0,namespace:a,env:t,draft:{type:'block',childTemplates:[],childCount:0,inParentIndex:0},isBlock:1,fn({},{mount:t}){e(),t.watch(Te.block)}});return()=>{E(be,'(block instance)');let e={type:'blockItem',childTemplates:[],childCount:0,inParentIndex:-1,itemOf:l},{env:t,namespace:a}=be;N(I({name:'block item',isSvgRoot:0,namespace:a,env:t,draft:e,fn(e,{mount:t}){t.watch(Te.blockItem)}}))}},e.h=(e,t)=>{let a,l=0,o=0;'function'==typeof t?(l=1,a=t):t&&(o=1,t.fn&&(l=1,a=t.fn),t.\u0254&&('function'==typeof t.\u0254?(l=1,a=t.\u0254):'function'==typeof t.\u0254.fn&&(l=1,a=t.\u0254.fn))),E(be,'h');let i,s=be.env,c=be.namespace,u=c,p='html';u=p='svg'===c?'svg':'html','svg'===e&&(p='svg',u='svg'),be.isBlock||(i='svg'===p?s.document.createElementNS('http://www.w3.org/2000/svg',e):s.document.createElement(e));let d=i,f={type:'element',tag:e,attr:[],data:[],text:[],style:[],styleVar:[],handler:[],stencil:d,seq:[],staticSeq:[],childTemplates:[],childCount:0,inParentIndex:-1,opsAmount:1,node:[]};'foreignObject'===c?(f.attr.push({xmlns:'http://www.w3.org/1999/xhtml'}),u='html'):'svg'===e?(f.attr.push({xmlns:'http://www.w3.org/2000/svg'}),u='svg'):'foreignObject'===e&&(u='foreignObject');let h=I({name:'element',draft:f,isSvgRoot:'svg'===e,namespace:u,fn(e,{mount:i}){let s=effector.createEvent({named:'domElementCreated'});l&&a(),o&&U(t),effector.is.unit(f.visible)&&(f.seq.push({type:'visible',value:f.visible}),G(f.visible));let c={attr:{},data:{},style:{},styleVar:{}};L(f,'attr',c),L(f,'data',c),L(f,'style',c),L(f,'styleVar',c),$(c,((e,t)=>{$(e,((e,a)=>{effector.is.unit(e)?(f.seq.push({type:t,field:a,value:e}),G(e)):f.staticSeq.push({type:t,field:a,value:e})}))})),f.text.forEach((e=>{null!==e.value&&(effector.is.unit(e.value)?(f.seq.push({type:'dynamicText',value:e.value,childIndex:e.index}),G(e.value)):f.seq.push({type:'staticText',value:String(e.value),childIndex:e.index}))})),f.handler.forEach((e=>{$(e.map,((t,a)=>{f.seq.push({type:'handler',for:a,handler:t,options:e.options,domConfig:e.domConfig})}))})),d&&m(d,f.staticSeq),f.seq.forEach((e=>{switch(e.type){case'visible':{let{onMount:t,onState:a}=_({mount:i,state:e.value,onMount:(e,t)=>({leaf:t,value:e,hydration:t.hydration}),onState:(e,t)=>({leaf:e,value:t,hydration:0})});t.watch((({leaf:e,value:t,hydration:a})=>{let l=e.data,r=l.block;if(a&&(n(t,l.ops.visible),t)){let e,t=A(r);if(e=t?t.nextSibling:O(r).firstChild,'#text'===e.nodeName){let t=e;e=e.nextSibling,t.remove()}r.value=e,r.visible=1}M(f,{parentBlockFragment:r,leaf:e,node:r.value,svgRoot:h.isSvgRoot?r.value:null}),t&&l.needToCallNode&&(l.needToCallNode=0,effector.launch({target:we,params:{element:l.block.value,fns:f.node},page:e,defer:1,scope:e.root.scope})),effector.launch({target:s,params:e,defer:1,page:e,scope:e.root.scope})})),effector.merge([a,t]).watch((({leaf:e,value:t,hydration:a})=>{a||r(t,e.data.ops.visible)}));break}case'attr':case'data':case'style':case'styleVar':{let t=De[e.type],a=Se.some((({type:t,field:a})=>e.type===t&&e.field===a)),l=_({mount:s,state:e.value,onMount:(e,t)=>({leaf:t,value:e}),onState:(e,t)=>({leaf:e,value:t})});a?effector.merge([l.onState,l.onMount]).watch((({leaf:a,value:l})=>{t(Ce(a),e.field,l)})):j(f,{initCtx(a,l){let n=Ce(l);return t(n,e.field,a),n},runOp(a,l){t(l,e.field,a)},hooks:l});break}case'dynamicText':j(f,{initCtx:(t,a)=>z(a,t,e.childIndex),runOp(e,t){k(t.value,e)},hooks:_({mount:s,state:e.value,onMount:(e,t)=>({leaf:t,value:String(e)}),onState:(e,t)=>({leaf:e,value:String(t)})})});break;case'staticText':s.watch((t=>{z(t,e.value,e.childIndex)}));break;case'handler':{let t=e.handler.graphite.meta.nativeTemplate||null;s.watch((a=>{let l=null;if(t){let e=0,n=a;for(;!e&&n;)n.template===t?(e=1,l=n):n=n.parent}else l=null;Ce(a).addEventListener(e.for,(t=>{e.options.prevent&&t.preventDefault(),e.options.stop&&t.stopPropagation(),effector.launch({target:e.handler,params:t,page:l,scope:a.root.scope})}),e.domConfig)}));break}}})),i.watch((e=>{let t=e.data;if(!f.visible){let a=t.ops.visible,l=t.block;if(e.hydration){n(1,a);let e,t=A(l);if(e=t?t.nextSibling:O(l).firstChild,'#text'===e.nodeName){let t=e;e=e.nextSibling,t.remove()}l.value=e,l.visible=1}M(f,{parentBlockFragment:l,leaf:e,node:l.value,svgRoot:h.isSvgRoot?l.value:null}),effector.launch({target:s,params:e,defer:1,page:e,scope:e.root.scope}),e.hydration?t.needToCallNode&&(t.needToCallNode=0,effector.launch({target:we,params:{element:t.block.value,fns:f.node},page:e,defer:1,scope:e.root.scope})):r(1,a)}}))},env:s});N(h)},e.handler=V,e.list=ee,e.node=e=>{E(be,'node');let t=be.draft;switch(t.type){case'list':case'listItem':case'using':case'route':case'rec':case'recItem':case'block':case'blockItem':return void console.error('node() hook supported only in h() nodes')}t.node.push(e)},e.rec=ae,e.remap=Y,e.route=te,e.spec=U,e.text=(e,...t)=>{Array.isArray(e)?U({text:le(e,t)}):U({text:e})},e.tree=({source:e,key:t,child:a,fn:l})=>{let n=ae((({store:e})=>{ee({source:e,key:t,fn({store:e}){let t=e.map((e=>e[a]||[]));l({store:e,child(){n({store:t})}})}})}));n({store:e})},e.using=(e,t)=>{let a,l,n,r,o,i;if('function'==typeof t)a=t,n=Q(),r=0;else{if(!t)throw Error('using() second argument is missing');a=t.fn,n=t.env?t.env:Q(),r=t.hydrate,l=t.onComplete,o=t.onRoot,i=t.scope}P(e,'using() first argument is missing');let u={scope:i,env:n,activeSpawns:new Set,childSpawns:{},leafOps:{}},p=e.namespaceURI,d=e.tagName.toLowerCase(),f={type:'using',childTemplates:[],childCount:0,inParentIndex:-1},m=I({name:'using',draft:f,isSvgRoot:'svg'===d,namespace:'http://www.w3.org/2000/svg'===p?'svg':'foreignobject'===d?'foreignObject':'html',fn(e,{mount:t}){a(),t.watch(Te.using)},env:n}),h={type:'using',child:[],value:e},v=s({onComplete:l}),g=T(m,{parentLeaf:ye||null,mountNode:e,svgRoot:m.isSvgRoot?e:ye?ye.svgRoot:null,leafData:{type:'using',draft:f,element:e,block:h},opGroup:c(v),domSubtree:c(v),hydration:r,root:u});if(o&&o({template:m,leaf:g}),v.onDrain&&!v.rafID){let e=v.onDrain;v.onDrain=null,e()}},e.val=(e,...t)=>t.every((e=>!effector.is.store(e)))?le(e,t).join(''):effector.combine(t,(t=>le(e,t).join(''))),e.variant=({source:e,cases:t,key:a})=>{let l;E(be,'variant'),P(effector.is.unit(e),'variant({source}) should be unit'),l='function'==typeof a?a:null==a?e=>String(e):e=>String(e[a]);let n=0;for(let a in t)'__'!==a?te({source:e,visible:e=>l(e)===a,fn:t[a]}):n=1;if(n){let a=Object.keys(t);te({source:e,visible:e=>!a.includes(l(e)),fn:t.__})}},Object.defineProperty(e,'__esModule',{value:1})})); | ||
((e,t)=>{'object'==typeof exports&&'undefined'!=typeof module?t(exports,require('effector')):'function'==typeof define&&define.amd?define(['exports','effector'],t):t((e='undefined'!=typeof globalThis?globalThis:e||self).forest={},e.effector)})(this,((e,effector)=>{function t(e,t){e.cursor[t].prev&&(e.cursor[t].prev.cursor[t].next=e.cursor[t].next),e.cursor[t].next&&(e.cursor[t].next.cursor[t].prev=e.cursor[t].prev),e.queue[t].last===e&&(e.queue[t].last=e.cursor[t].prev),e.queue[t].first===e&&(e.queue[t].first=e.cursor[t].next),e.cursor[t].prev=null,e.cursor[t].next=null}function a(e){e.status='active',((e,t)=>{t.cursor.prev&&(t.cursor.prev.cursor.next=t.cursor.next),t.cursor.next&&(t.cursor.next.cursor.prev=t.cursor.prev),e.last===t&&(e.last=t.cursor.prev),e.first===t&&(e.first=t.cursor.next),t.cursor.prev=null,t.cursor.next=null})(l(e),e)}function l(e){return e.group.activeChilds[e.priority]}function n(e,t){t.value.active=t.value.pending=e,'active'!==t.status&&a(t)}function r(e,n){if(n.value.active===e)return n.value.pending=e,void('pending'===n.status&&(a(n),l(n).first||t(n.group,n.priority)));'active'===n.status&&(n.status='pending',l(n).first||((e,t)=>{e.queue[t].last?(e.cursor[t].prev=e.queue[t].last,e.queue[t].last.cursor[t].next=e,e.queue[t].last=e):e.queue[t].first=e.queue[t].last=e})(n.group,n.priority),((e,t)=>{e.last?(t.cursor.prev=e.last,e.last.cursor.next=t,e.last=t):e.first=e.last=t})(l(n),n)),n.value.pending=e,n.group.queue.rafID||(n.group.queue.rafID=de(n.group.queue.execQueue))}function o(e){ue('execQueue');let l,n,r=ne(),o=0;e:for(;e.props.first||e.tree.first||e.data.first;){if(ne()-r>=re){o=1;break e}let i=!!e.props.first;for(i&&ue('props');l=e.props.first;){for(;n=l.activeChilds.props.first;){if(ne()-r>=re){o=1,pe('props');break e}n.runOp(n.value.pending),n.value.active=n.value.pending,a(n)}t(l,'props')}i&&pe('props');let s=!!e.tree.first;for(s&&ue('tree');l=e.tree.first;){for(;n=l.activeChilds.tree.first;){if(ne()-r>=re){o=1,pe('tree');break e}n.runOp(n.value.pending),n.value.active=n.value.pending,a(n)}t(l,'tree')}s&&pe('tree');let c=!!e.data.first;for(c&&ue('data');l=e.data.first;){for(;n=l.activeChilds.data.first;){if(ne()-r>=re){o=1,pe('data');break e}n.runOp(n.value.pending),n.value.active=n.value.pending,a(n)}t(l,'data')}c&&pe('data')}if(pe('execQueue'),o)e.rafID=de(e.execQueue);else if(e.rafID=null,e.onDrain){let t=e.onDrain;e.onDrain=null,t()}}function i({value:e,runOp:t,group:a,priority:l}){return{value:{active:e,pending:e},runOp:t,status:'active',priority:l,group:a,cursor:{prev:null,next:null}}}function s({onComplete:e}){let t={props:{first:null,last:null},tree:{first:null,last:null},data:{first:null,last:null},rafID:null,execQueue(){},onDrain:e};return t.execQueue=o.bind(null,t),t}function c(e){return{ops:[],queue:e,activeChilds:{props:{first:null,last:null},tree:{first:null,last:null},data:{first:null,last:null}},cursor:{props:{prev:null,next:null},tree:{prev:null,next:null},data:{prev:null,next:null}}}}function u({value:e,group:t,onInit:a,onChange:l}){let n=i({value:e,group:t,runOp(e){o.status='A',l(e)},priority:'data'}),o={status:'IA',value:n.value,ops:{init:i({value:0,group:t,runOp(e){o.status='A',a(o.value.active)},priority:'data'}),change:n,terminate:i({value:0,group:t,runOp(e){o.status='T'},priority:'data'})}};return r(1,o.ops.init),o}function p(e){switch(e.status){case'I':case'T':case'AT':return;case'A':e.status='AT',r(1,e.ops.terminate);break;case'AA':e.status='AT',r(1,e.ops.terminate),r(e.value.active,e.ops.change);break;case'IA':e.status='T',r(0,e.ops.init)}}function d(e,t){switch(t.status){case'I':case'T':return;case'A':t.value.active!==e&&(t.status='AA',r(e,t.ops.change));break;case'AA':t.value.active===e?(t.status='A',r(e,t.ops.change)):t.value.pending!==e&&(t.value.pending=e);break;case'IA':t.value.active=t.value.pending=e}}function f(e){switch(e=String(e)){case'__proto__':case'__defineGetter__':case'__defineSetter__':case'constructor':case'prototype':case'hasOwnProperty':case'toString':case'valueOf':case'setProperty':case'removeProperty':return'forbidden';default:return e.replace(/[^a-zA-Z0-9\-_]/g,'')}}function m(e,t){for(let a=0;a<t.length;a++){let{type:l,field:n,value:r}=t[a];fe[l](e,n,r)}}function h(e){return''!==e&&0!==e&&'0'!==e&&(0==e||null==e)}function v(e,t,a){h(a)?e.style.removeProperty(`--${t}`):e.style.setProperty(`--${t}`,`${a}`)}function g(e,t,a){h(a)?delete e.style[t]:e.style[t]=`${a}`}function b(e,t,a){h(a)?delete e.dataset[t]:e.dataset[t]=`${a}`}function y(e,t,a){if(h(a)){switch(t){case'value':delete e.value;break;case'checked':e.checked=0;break;case'spellcheck':if(0==a)return void e.setAttribute('spellcheck','false')}e.removeAttribute(t)}else{switch(t){case'value':e.value=`${a}`;break;case'checked':e.checked=`${a}`}e.setAttribute(t,`${a}`)}}function k(e,t){e.replaceData(0,(e.textContent||'').length,String(t))}function I({fn:e,state:t={},defer:a=0,name:l="",draft:n,isSvgRoot:r,namespace:o,env:i,isBlock:s=0}){let c=be,u={id:++ve,name:l,plain:[],watch:[],nameMap:{},pages:[],closure:[],childTemplates:[],handlers:he,upward:effector.step.filter({fn(e,t,a){if(!a.page){if(!a.parent||!a.parent.page)return 1;a.page=a.parent.page}if(!a.page.root.activeSpawns.has(a.page.fullID))return console.count('inactive page upward'),0;let l=[a.page.template],n=[a.page];{let e=a.page.parent;for(;e;)n.push(e),l.push(e.template),e=e.parent}return a.node.next.forEach((t=>{let r=t.meta.nativeTemplate;if(r)if(l.includes(r)){let o=n[l.indexOf(r)];effector.launch({target:t,params:e,defer:1,page:o,stack:a,scope:a.scope})}else console.error('context drift',{stack:a,node:t});else effector.launch({target:t,params:e,defer:1,page:a.page,stack:a,scope:a.scope})})),0}}),loader:effector.step.filter({fn(e,t,a){if(a.parent){let t=a.scope?a.scope.graphite.id:null;if(a.page){if(!a.page.root.activeSpawns.has(a.page.fullID))return console.count('inactive page loader'),0;if(a.page.template===u)return 1;if(a.page.root.childSpawns[a.page.fullID][u.id])a.page.root.childSpawns[a.page.fullID][u.id].forEach((l=>{(!t||l.root.scope&&t===l.root.scope.graphite.id)&&effector.launch({params:e,target:a.node,page:l,defer:1,scope:a.scope})}));else{let l=a.page.fullID,n='rec'===a.page.template.name;u.pages.forEach((r=>{if(!t||r.root.scope&&t===r.root.scope.graphite.id)if(r.fullID===l||r.fullID.startsWith(`${l}_`)){let t=1;if(n){let e=a.page.template.id,l=r.parent;for(;l&&l!==a.page;){if(l.template.id===e){t=0;break}l=l.parent}}t&&effector.launch({params:e,target:a.node,page:r,defer:1,scope:a.scope})}else l.startsWith(`${r.fullID}_`)&&effector.launch({params:e,target:a.node,page:a.page,defer:1,scope:a.scope})}))}}else u.pages.forEach((l=>{(!t||l.root.scope&&t===l.root.scope.graphite.id)&&effector.launch({params:e,target:a.node,page:l,defer:1,scope:a.scope})}));return 0}return 1}}),parent:c,node:null,api:null,trigger:{mount:effector.createEvent({named:'mount'})},draft:n,isSvgRoot:r,namespace:o,env:i,isBlock:s||!(!c||!c.isBlock)};c&&c.childTemplates.push(u);let p=effector.createNode({meta:{template:u}});return u.node=p,be=u,a?u.deferredInit=()=>{let a=be;be=u,u.deferredInit=null;try{effector.withRegion(p,(()=>{let a=effector.restore(t);u.api=e(a,u.trigger),u.nameMap=a}))}finally{be=a}}:effector.withRegion(p,(()=>{let a=effector.restore(t);u.api=e(a,u.trigger),u.nameMap=a})),be=c,u}function x(e,t){let a;switch(a=t?t.getState(e):e.current,e.type){case'list':return[...a];case'shape':return{...a};default:return a}}function w(e,t,a){let l=t;for(;l&&!ke(l,e);)l=l.parent;return l?ke(l,e):a?(a.getState(e),a.reg[e.id]):e}function S(e,t,a){return w(e,t,a).current}function D(e,t){ke(t,e)||(t.reg[e.id]=w(e,t.parent,t.root.scope))}function C(e,t,a){t in a||(a[t]=[]),a[t].push(...e)}function T(e,{values:t={},parentLeaf:a,mountNode:l,svgRoot:n,leafData:r,opGroup:o,domSubtree:i,hydration:s,root:c}){function u(e){if(e.before)for(let t=0;t<e.before.length;t++){let a=e.before[t];switch(a.type){case'map':{let t,l=a.from;if(!a.fn&&!l)break;l&&(D(l,f),t=d[l.id].current),d[e.id].current=a.fn?a.fn(t):t;break}case'field':{let t=a.from;D(t,f),d[e.id].current[a.field]=d[t.id].current;break}case'closure':D(a.of,f)}}}function p(e,t,a){let l;t.stop=1;try{for(;t.i<e.length;)l=e[t.i],t.i++,l.fn(a[l.of.id]?a[l.of.id].current:S(l.of,f.parent,f.root.scope))}catch(e){console.error(e),t.stop=0}}let d={},f={draft:e.draft,svgRoot:n,data:r,parent:a,hydration:s,mountNode:l,root:c,id:++ge,fullID:'',reg:d,template:e};e.pages.push(f);let m=ye;ye=f,a&&C([f],e.id,c.childSpawns[a.fullID]),f.fullID=a?`${a.fullID}_${f.id}`:`${f.id}`,c.childSpawns[f.fullID]={},c.activeSpawns.add(f.fullID),c.leafOps[f.fullID]={group:o,domSubtree:i};for(let t=0;t<e.closure.length;t++){let a=e.closure[t],l=a,n=f.parent;e:for(;n;){if(ke(n,a)){l=ke(n,a);break e}n=n.parent}!n&&c.scope&&(c.scope.getState(a),l=c.scope.reg[a.id]),d[a.id]=l}for(let t=0;t<e.plain.length;t++){let a=e.plain[t],l={id:a.id,current:x(a,c.scope)};d[a.id]=l}for(let a in t){let l=e.nameMap[a].stateRef.id;d[l]={id:l,current:t[a]}}e.closure.forEach(u),e.plain.forEach(u);let h={i:0,stop:0};for(;!h.stop;)p(e.watch,h,d);if(a)for(let e in c.childSpawns[f.fullID])C(c.childSpawns[f.fullID][e],e,c.childSpawns[a.fullID]);if(Ie)Ie.steps.push({target:e.trigger.mount,params:f,defer:1,page:f,scope:c.scope});else{let t;Ie={parent:Ie,steps:[{target:e.trigger.mount,params:f,defer:1,page:f,scope:c.scope}]};do{for(;t=Ie.steps.shift();)Ie={parent:Ie,steps:[]},effector.launch(t)}while(Ie=Ie.parent)}return ye=m,f}function O(e){let t=e.parent;for(;'element'!==t.type&&'using'!==t.type;)t=t.parent;return t?t.value:null}function q(e){if(!e.visible)return null;switch(e.type){case'text':case'element':return e;case'LF':case'route':case'rec':case'recItem':case'block':case'blockItem':for(let t=e.child.length-1;t>=0;t--){let a=q(e.child[t]);if(a)return a}return null;case'list':{let t=e.lastChild;if(!t)return null;for(;t;){let e=q(t);if(e)return e;t=t.left}return null}default:return null}}function R(e){switch(e.type){case'using':return null;case'LF':{let t=e.left;for(;t;){let e=q(t);if(e)return e;t=t.left}return R(e.parent)}case'element':case'text':case'route':case'rec':case'recItem':case'block':case'blockItem':case'list':{let t=e.parent;for(let a=e.index-1;a>=0;a--){let e=t.child[a];if(!e)continue;let l=q(e);if(l)return l}switch(t.type){case'element':case'using':return null}return R(t)}default:return null}}function A(e){let t=R(e);return t?t.value:null}function P(e,t){if(!e)throw Error(t)}function E(e,t){if(!e)throw Error(`${t}() called outside from using() closure`)}function N(e){if(!be)return;let{draft:t}=e;if('listItem'!==t.type&&'rec'!==t.type)switch(be.draft.type){case'element':case'using':case'route':case'list':case'rec':case'recItem':case'block':case'blockItem':t.inParentIndex=be.draft.childCount,be.draft.childCount+=1,be.draft.childTemplates.push(e);break;default:console.warn(`unexpected currentTemplate type ${be.draft.type}`)}}function M(e,{parentBlockFragment:t,leaf:a,node:l,svgRoot:n,values:r}){e.childTemplates.forEach((e=>{B({parentBlockFragment:t,leaf:a,node:l,svgRoot:n,values:r,actor:e})}))}function B({parentBlockFragment:e,leaf:t,node:a=t.mountNode,actor:l,svgRoot:n,values:r}){let o;P(xe.includes(e.type),`incorrect parent ${e.type}`);let{draft:s}=l,{queue:u}=t.root.leafOps[t.fullID].group,p=c(u),d=t.root.leafOps[t.fullID].domSubtree,f=d;switch(s.type){case'route':{let t={type:'route',parent:e,child:[],visible:0,index:s.inParentIndex};e.child[s.inParentIndex]=t,o={type:'route',block:t,ops:{},initialized:0,pendingInit:null};break}case'element':{let a;if(l.isBlock){let e,l,n=t;for(;n&&(!l||!e);){n.template.env&&(e=n.template.env);let{draft:t}=n;'element'===t.type&&('svg'===t.tag?l='svg':'foreignObject'===t.tag&&(l='html')),n=n.parent}l||(l='html'),e&&(a='svg'===l?e.document.createElementNS('http://www.w3.org/2000/svg',s.tag):e.document.createElement(s.tag),m(a,s.staticSeq))}else a=s.stencil.cloneNode();let n={type:'element',parent:e,child:[],value:a,visible:0,index:s.inParentIndex};e.child[s.inParentIndex]=n,o={type:'element',block:n,ops:{visible:i({value:0,priority:'tree',runOp(e){if(e){F(n);let e=o;e.needToCallNode&&(e.needToCallNode=0,effector.launch({target:we,params:{element:n.value,fns:s.node},page:h,scope:t.root.scope})),n.visible=1}else n.value.remove(),n.visible=0},group:d})},needToCallNode:s.node.length>0},f=c(u);break}case'list':{let t={type:'list',parent:e,child:[],lastChild:null,visible:1,index:s.inParentIndex};e.child[s.inParentIndex]=t,o={type:'list',draft:s,block:t,records:[],pendingUpdate:null};break}case'using':case'listItem':break;case'rec':{let t={type:'rec',parent:e,child:[],visible:1,index:s.inParentIndex};e.child[s.inParentIndex]=t,o={type:'rec',block:t};break}case'recItem':{let t={type:'recItem',parent:e,child:[],visible:1,index:s.inParentIndex};e.child[s.inParentIndex]=t,o={type:'rec item',block:t};break}case'block':{let t={type:'block',parent:e,child:[],visible:1,index:s.inParentIndex};e.child[s.inParentIndex]=t,o={type:'block',block:t};break}case'blockItem':{let t={type:'blockItem',parent:e,child:[],visible:1,index:s.inParentIndex};e.child[s.inParentIndex]=t,o={type:'block item',block:t};break}default:console.warn(`unexpected draft type ${s.type}`)}let h=T(l,{values:r,parentLeaf:t,mountNode:a,svgRoot:n||t.svgRoot,leafData:o,opGroup:p,domSubtree:f,hydration:t.hydration,root:t.root})}function F(e){let t=A(e);t?t.after(e.value):O(e).prepend(e.value),e.visible=1}function _({mount:e,state:t,onMount:a,onState:l}){return{onMount:effector.sample({source:t,clock:e,fn:a,greedy:1}),onState:effector.sample({source:e,clock:t,fn:l,greedy:1})}}function $(e,t){for(let a in e)t(e[a],a)}function V(e,t){if(!be)return;let a=be.draft;P('element'===a.type,`"handler" extension can be used only with element nodes, got "${a.type}"`),void 0===t&&(t=e,e={});for(let e in t)P(effector.is.unit(t[e]),`handler for "${e}" should be event`);let{passive:l=0,capture:n=0,prevent:r=0,stop:o=0}=e;a.handler.push({options:{prevent:r,stop:o},domConfig:{passive:r?0:l,capture:n},map:t})}function U(e){E(be,'spec');let t=be.draft;switch(t.type){case'list':return void(e.visible&&(t.itemVisible=e.visible));case'listItem':case'using':case'route':case'rec':case'recItem':case'block':case'blockItem':return}if(e.attr&&t.attr.push(e.attr),e.data&&t.data.push(e.data),'text'in e){let a=e.text,l=t.childCount;Array.isArray(a)?(t.text.push(...a.map(((e,t)=>({index:t+l,value:e})))),t.childCount+=a.length):(t.text.push({index:l,value:a}),t.childCount+=1)}if(e.style){let a={};for(let t in e.style)a[f(t)]=e.style[t];t.style.push(a)}if(e.styleVar&&t.styleVar.push(e.styleVar),e.visible&&(t.visible=e.visible),e.handler){let t=e.handler;'object'==typeof t.on?V(t.config||{},t.on):V(t)}e.\u0254&&U(e.\u0254)}function j(e,{initCtx:t,runOp:a,hooks:{onMount:l,onState:n}}){let o=e.opsAmount++;l.watch((({value:e,leaf:l})=>{let n=i({value:e,priority:'props',runOp(e){a(e,r)},group:l.root.leafOps[l.fullID].group});l.root.leafOps[l.fullID].group.ops[o]=n;let r=t(e,l)})),n.watch((({value:e,leaf:t})=>{r(e,t.root.leafOps[t.fullID].group.ops[o])}))}function L(e,t,a){e[t].forEach((e=>{$(e,((e,l)=>{switch(t){case'data':case'styleVar':a[t][l]=e;break;case'attr':a.attr['xlink:href'===l?'href':l]=e;break;case'style':l.startsWith('--')?a.styleVar[l.slice(2)]=e:a.style[l]=e}}))}))}function z(e,t,a){let l=e.data.block,n={type:'text',parent:l,visible:0,index:a,value:null};if(l.child[a]=n,e.hydration){let a=R(n);if(a)switch(a.type){case'text':n.value=e.root.env.document.createTextNode(t),a.value.after(n.value);break;case'element':n.value=a.value.nextSibling,k(n.value,t)}else{let e=O(n);n.value=e.firstChild,k(n.value,t)}n.visible=1}else n.value=e.root.env.document.createTextNode(t),F(n);return n}function G(e){let t=e.stateRef,a=be;a.plain.includes(t)||a.closure.includes(t)||a.closure.push(t)}function Q(){if('undefined'!=typeof document)return{document};throw Error('your environment has no document')}function W(e,t){let a=e.root.childSpawns[e.fullID];for(let e in a){let l=a[e];for(let e=0;e<l.length;e++)t(l[e])}}function Z(e,t){let a=t=>{let l=t.data;if(e&&'list'===l.type&&l.pendingUpdate){let e=l.pendingUpdate;l.pendingUpdate=null,effector.launch({target:t.template.api.pendingUpdate,params:e,defer:1,page:t,scope:t.root.scope})}if(e&&'route'===l.type)if(l.pendingInit){let e=l.pendingInit.value;l.pendingInit=null,effector.launch({target:t.template.api.pendingInit,params:e,defer:1,page:t,scope:t.root.scope})}else if(!l.block.visible)return;switch(l.type){case'element':r(e,l.ops.visible);break;case'route':case'list':case'list item':W(t,a);break;default:console.log('unsupported type',l.type)}};W(t,a)}function H(e){e.root.activeSpawns.delete(e.fullID),W(e,K)}function J(e){X(e,e.root.childSpawns[e.parent.fullID][e.template.id]),X(e,e.template.pages)}function K(e){let{data:t,root:a}=e;switch(t.type){case'element':X(e,a.childSpawns[e.parent.fullID][e.template.id]),function e(t){a.activeSpawns.delete(t.fullID);let l=a.childSpawns[t.fullID];delete a.childSpawns[t.fullID],delete a.leafOps[t.fullID],X(t,t.template.pages);for(let t in l)l[t].forEach(e)}(e),r(0,t.ops.visible);break;case'list':{let a=t.records;for(let e=0;e<a.length;e++){let t=a[e];t.instance&&K(t.instance),t.active=0}e.root.activeSpawns.delete(e.fullID),J(e);break}case'list item':{let a=t.block;X(a,a.parent.child);let l=a.left,n=a.right;l&&(l.right=n,n||a.parent.lastChild!==a||(a.parent.lastChild=l)),n&&(n.left=l),l||n||a.parent.lastChild!==a||(a.parent.lastChild=null),a.left=null,a.right=null,H(e),J(e);break}case'route':H(e),J(e);break;case'block':case'block item':case'rec':case'rec item':H(e)}delete a.childSpawns[e.fullID],delete a.leafOps[e.fullID]}function X(e,t){if(!t)return;let a=t.indexOf(e);-1!==a&&t.splice(a,1)}function Y(e,t){if(Array.isArray(t))return t.map((t=>e.map((e=>e[t]))));if('object'==typeof t&&null!==t){let a={};for(let l in t){let n=t[l];a[l]=e.map('function'==typeof n?e=>n(e):e=>e[n])}return a}return e.map((e=>e[t]))}function ee(e,t){E(be,'list'),'function'==typeof t&&(effector.is.unit(e)?e={source:e,fn:t}:e.fn=t);let{fn:a,key:l,source:n,fields:r=[]}=e,o=void 0!==l?'function'==typeof l?l:e=>e[l]:(e,t)=>t,i={type:'list',key:effector.is.store(e)?{type:'index'}:{type:'key',key:e.key},childTemplates:[],childCount:0,inParentIndex:-1},{env:s,namespace:f}=be;N(I({name:'list',draft:i,isSvgRoot:0,namespace:f,fn(e,{mount:t}){let l=I({name:'list item',state:{id:-1,store:null},draft:i,isSvgRoot:0,namespace:f,fn({id:e,store:t},{mount:l}){a({store:t,key:e,fields:Y(t,r)});let n=effector.createEvent({named:'itemUpdater'});if(t.on(n,((e,t)=>t)),i.itemVisible){let{onMount:e,onState:t}=_({mount:l,state:i.itemVisible,onMount:(e,t)=>({visible:e,leaf:t}),onState:(e,t)=>({visible:t,leaf:e})});e.watch((({visible:e,leaf:t})=>{let a=t.data.block;a.visible=e,a.childInitialized=e,e&&M(i,{parentBlockFragment:a,leaf:t})})),t.watch((({visible:e,leaf:t})=>{let a=t.data.block;a.visible=e,a.childInitialized?Z(e,t):e&&(a.childInitialized=1,M(i,{parentBlockFragment:a,leaf:t}))}))}else l.watch(Te.listItem);return{itemUpdater:n}},env:s}),m=effector.createStore([]),h=n.map((e=>e)),v=effector.sample({source:n,clock:t,fn:(e,t)=>({updates:e,leaf:t,hydration:t.hydration}),greedy:1}),g=effector.createEvent(),b=effector.sample({source:v,clock:[h,g],fn:({leaf:e},t)=>({updates:t,leaf:e,hydration:0}),greedy:1});return effector.sample({source:m,clock:[v,b],greedy:1,fn(e,{updates:t,leaf:a,hydration:r}){let s=a.data,f=a;for(;f;){if('route'===f.data.type&&!f.data.block.visible)return void(s.pendingUpdate=t);f=f.parent}let m=s.block;ue('list update ['+n.shortName+']');let h=Array(t.length).fill(0),v=t.map(o),g=[];for(let a=0;a<e.length;a++){let l=e[a],n=v.indexOf(l.key);-1!==n?(g.push(l),h[n]=1,d(t[n],l.asyncValue)):(l.active=0,l.instance&&K(l.instance),p(l.asyncValue))}for(let e=0;e<t.length;e++){if(h[e])continue;let n=t[e],o=v[e],s=c(a.root.leafOps[a.fullID].group.queue),p={type:'LF',parent:m,child:[],childInitialized:0,visible:0,left:null,right:null},d={type:'listItem',key:o,index:o,active:1,leafData:{type:'list item',block:p,listDraft:i},asyncValue:u({value:n,group:s,onChange(e){d.instance&&effector.launch({target:d.instance.template.api.itemUpdater,params:e,defer:1,page:d.instance,scope:d.instance.root.scope})},onInit(e){d.active&&(r||(d.instance=T(l,{values:{id:o,store:e},parentLeaf:a,mountNode:a.mountNode,svgRoot:a.svgRoot,leafData:d.leafData,opGroup:s,domSubtree:a.root.leafOps[a.fullID].domSubtree,hydration:r,root:a.root})))}})},f=g.length;g.push(d);let b=f>0?g[f-1].leafData:null;if(m.child.push(p),b){let e=b.block;p.left=e;let t=e.right;t?(t.left=p,p.right=t):m.lastChild=p,e.right=p}else m.lastChild=p;r&&(d.instance=T(l,{values:{id:o,store:n},parentLeaf:a,mountNode:a.mountNode,svgRoot:a.svgRoot,leafData:d.leafData,opGroup:s,domSubtree:a.root.leafOps[a.fullID].domSubtree,hydration:r,root:a.root}))}return pe('list update ['+n.shortName+']'),0===g.length&&(m.lastChild=null),s.records=g,g},target:m}),{pendingUpdate:g}},env:s}))}function te({source:e,visible:t,fn:a}){E(be,'route');let{env:l,namespace:n}=be,r=I({name:'route',isSvgRoot:0,namespace:n,env:l,draft:{type:'route',childTemplates:[],childCount:0,inParentIndex:-1},fn(r,{mount:o}){let i;if(effector.is.store(t))i=effector.combine({value:e,visible:t});else{let a=t;i=e.map((e=>({value:e,visible:a(e)})))}let s=I({name:'route item',isSvgRoot:0,namespace:n,env:l,draft:{type:'route',childTemplates:[],childCount:0,inParentIndex:-1},state:{store:null},fn({store:e},{mount:t}){let l=effector.createEvent({named:'itemUpdater'});e.on(l,((e,t)=>t)),a({store:e});let n=effector.sample({source:t,clock:i,fn:(e,{visible:t,value:a})=>({leaf:e,visible:t,value:a}),greedy:1});t.watch(Te.routeItem),n.watch((({leaf:e,visible:t,value:a})=>{if(e.data.block.visible=t,t&&effector.launch({target:l,params:a,defer:1,page:e,scope:e.root.scope}),t){let t=e.parent;for(;t;){if('route'===t.data.type&&!t.data.block.visible)return;t=t.parent}}Z(t,e)}))}});N(s);let{onMount:c,onState:u}=_({mount:o,state:i,onMount:({visible:e,value:t},a)=>({leaf:a,visible:e,value:t}),onState:(e,{visible:t,value:a})=>({leaf:e,visible:t,value:a})}),p=effector.createEvent(),d=effector.sample({source:o,clock:p,greedy:1,fn:(e,t)=>({leaf:e,value:t,visible:1})});return effector.merge([c,u,d]).watch((({leaf:e,visible:t,value:a})=>{let l=e.data;if(l.block.visible=t,t||l.initialized||!l.pendingInit){if(t&&!l.initialized){let t=e.parent;for(;t;){if('route'===t.data.type&&!t.data.block.visible)return void(l.pendingInit={value:a});t=t.parent}}t&&!l.initialized&&(B({parentBlockFragment:l.block,leaf:e,actor:s,values:{store:a}}),l.initialized=1)}else l.pendingInit=null})),{pendingInit:p}}});N(r)}function ae(e){let t='function'==typeof e?e:e.fn,a=I({name:'rec',state:{store:null},isSvgRoot:0,namespace:null,env:null,draft:{type:'rec',childTemplates:[],childCount:0,inParentIndex:0},defer:1,isBlock:1,fn({store:e},{mount:a}){t({store:e,state:e});let l=effector.createEvent({named:'itemUpdater'});return e.on(l,((e,t)=>t)),a.watch(Te.rec),{itemUpdater:l}}});return({store:e,state:t=e})=>{E(be,'(rec instance)');let{env:l,namespace:n}=be;a.deferredInit&&a.deferredInit(),N(I({name:'rec item',isSvgRoot:0,namespace:n,env:l,draft:{type:'recItem',childTemplates:[],childCount:0,inParentIndex:-1},fn(e,{mount:l}){let{onMount:n,onState:r}=_({state:t,mount:l,onMount:(e,t)=>({state:e,leaf:t}),onState:(e,t)=>({state:t,leaf:e})});r.watch((({state:e,leaf:t})=>{W(t,(a=>{effector.launch({target:a.template.api.itemUpdater,params:e,defer:1,page:t,scope:t.root.scope})}))})),n.watch((({leaf:e,state:t})=>{B({parentBlockFragment:e.data.block,leaf:e,actor:a,values:{store:t}})}))}}))}}function le(e,t){if(0===t.length)return e;let a=[e[0]];for(let l=0;l<t.length;l++)a.push(t[l],e[l+1]);return a}let ne,re=1e3;ne='undefined'!=typeof performance&&performance.now?()=>performance.now():'undefined'!=typeof process&&process.hrtime?()=>{let e=process.hrtime();return(1e9*e[0]+e[1])/1e6}:()=>Date.now();let oe=new Map;const ie=[],se=e=>{let t=oe.get(e);t||(t={calls:0,time:0,label:e,childTime:0},oe.set(e,t)),t.calls+=1,ie.push({bucket:t,pendingStart:ne()})},ce=e=>{let t=oe.get(e),a=ie.pop().pendingStart,l=ne()-a;t.time+=l,ie.length>0&&(ie[ie.length-1].bucket.childTime+=l)};let ue,pe;'undefined'!=typeof performance&&performance.mark?(ue=e=>{performance.mark('\u2604\ufe0f '+e+' start'),se(e)},pe=e=>{ce(e);try{performance.measure('\u2604\ufe0f '+e,'\u2604\ufe0f '+e+' start')}catch(e){}performance.clearMarks('\u2604\ufe0f '+e+' start'),performance.clearMeasures('\u2604\ufe0f '+e)}):(ue=e=>{se(e)},pe=e=>{ce(e)});let de='undefined'!=typeof requestAnimationFrame?requestAnimationFrame:e=>setTimeout(e,0);const fe={attr:y,data:b,style:g,styleVar:v},me=(e,t)=>e.includes(t);let he={storeBase(e,t){e.plain.push(t)},storeOnMap(e,t,a,l){a.unshift(e.loader),a.push(e.upward),l&&(me(e.plain,l)||(me(e.closure,l)||e.closure.push(l),((e,t)=>{e.before||(e.before=[]),e.before.push(t)})(t,{type:'closure',of:l})))},storeMap(e,t,a){me(e.plain,t)||me(a.seq,e.loader)||a.seq.unshift(e.loader)},storeWatch:(e,t,a)=>(e.watch.push({of:t,fn:a}),1),eventPrepend(e,t){t.seq.push(e.upward)},combineBase(e,t,a){e.plain.push(t,a)},combineField(e,t,a){me(e.plain,t)||a.seq.unshift(e.loader)},splitBase(e,t){e.plain.push(t)},splitMatchStore(e,t,a){me(e.plain,t)||a.seq.unshift(e.loader)},sampleSource(e,t,a,l){t.current?me(e.plain,a)||me(e.closure,a)||e.closure.push(a):e.plain.push(a),e.plain.push(t),me(e.plain,l)||e.plain.push(l)},sampleTarget(e,t){t.seq.push(e.loader)},sampleSourceLoader:e=>e.loader,sampleSourceUpward:(e,t)=>t&&e.upward},ve=0,ge=0,be=null,ye=null;const ke=(e,t)=>e.reg[t.id];let Ie=null;const xe=['LF','using','element','recItem','rec','block','blockItem','route'];let we=effector.createEvent({named:'onMount'});we.watch((({fns:e,element:t})=>{e.forEach((e=>{e(t)}))}));const Se=[{type:'attr',field:'value'},{type:'attr',field:'checked'},{type:'attr',field:'min'},{type:'attr',field:'max'}],De={attr:y,data:b,style:g,styleVar:v},Ce=e=>e.data.block.value;let Te={using(e){let t=e.data;M(t.draft,{parentBlockFragment:t.block,leaf:e})},routeItem(e){let t=e.draft,a=e.data;a.block.visible=1,M(t,{parentBlockFragment:a.block,leaf:e})},block(e){M(e.draft,{parentBlockFragment:e.data.block,leaf:e})},blockItem(e){B({parentBlockFragment:e.data.block,leaf:e,actor:e.draft.itemOf})},rec(e){M(e.draft,{parentBlockFragment:e.data.block,leaf:e})},listItem(e){let t=e.data,a=t.block;a.visible=1,a.childInitialized=1,M(t.listDraft,{parentBlockFragment:a,leaf:e})}};e.block=({fn:e,env:t,namespace:a="html"})=>{let l=I({name:'block',isSvgRoot:0,namespace:a,env:t,draft:{type:'block',childTemplates:[],childCount:0,inParentIndex:0},isBlock:1,fn({},{mount:t}){e(),t.watch(Te.block)}});return()=>{E(be,'(block instance)');let e={type:'blockItem',childTemplates:[],childCount:0,inParentIndex:-1,itemOf:l},{env:t,namespace:a}=be;N(I({name:'block item',isSvgRoot:0,namespace:a,env:t,draft:e,fn(e,{mount:t}){t.watch(Te.blockItem)}}))}},e.h=(e,t)=>{let a,l=0,o=0;'function'==typeof t?(l=1,a=t):t&&(o=1,t.fn&&(l=1,a=t.fn),t.\u0254&&('function'==typeof t.\u0254?(l=1,a=t.\u0254):'function'==typeof t.\u0254.fn&&(l=1,a=t.\u0254.fn))),E(be,'h');let i,s=be.env,c=be.namespace,u=c,p='html';u=p='svg'===c?'svg':'html','svg'===e&&(p='svg',u='svg'),be.isBlock||(i='svg'===p?s.document.createElementNS('http://www.w3.org/2000/svg',e):s.document.createElement(e));let d=i,f={type:'element',tag:e,attr:[],data:[],text:[],style:[],styleVar:[],handler:[],stencil:d,seq:[],staticSeq:[],childTemplates:[],childCount:0,inParentIndex:-1,opsAmount:1,node:[]};'foreignObject'===c?(f.attr.push({xmlns:'http://www.w3.org/1999/xhtml'}),u='html'):'svg'===e?(f.attr.push({xmlns:'http://www.w3.org/2000/svg'}),u='svg'):'foreignObject'===e&&(u='foreignObject');let h=I({name:'element',draft:f,isSvgRoot:'svg'===e,namespace:u,fn(e,{mount:i}){let s=effector.createEvent({named:'domElementCreated'});l&&a(),o&&U(t),effector.is.unit(f.visible)&&(f.seq.push({type:'visible',value:f.visible}),G(f.visible));let c={attr:{},data:{},style:{},styleVar:{}};L(f,'attr',c),L(f,'data',c),L(f,'style',c),L(f,'styleVar',c),$(c,((e,t)=>{$(e,((e,a)=>{effector.is.unit(e)?(f.seq.push({type:t,field:a,value:e}),G(e)):f.staticSeq.push({type:t,field:a,value:e})}))})),f.text.forEach((e=>{null!==e.value&&(effector.is.unit(e.value)?(f.seq.push({type:'dynamicText',value:e.value,childIndex:e.index}),G(e.value)):f.seq.push({type:'staticText',value:String(e.value),childIndex:e.index}))})),f.handler.forEach((e=>{$(e.map,((t,a)=>{f.seq.push({type:'handler',for:a,handler:t,options:e.options,domConfig:e.domConfig})}))})),d&&m(d,f.staticSeq),f.seq.forEach((e=>{switch(e.type){case'visible':{let{onMount:t,onState:a}=_({mount:i,state:e.value,onMount:(e,t)=>({leaf:t,value:e,hydration:t.hydration}),onState:(e,t)=>({leaf:e,value:t,hydration:0})});t.watch((({leaf:e,value:t,hydration:a})=>{let l=e.data,r=l.block;if(a&&(n(t,l.ops.visible),t)){let e,t=A(r);if(e=t?t.nextSibling:O(r).firstChild,'#text'===e.nodeName){let t=e;e=e.nextSibling,t.remove()}r.value=e,r.visible=1}M(f,{parentBlockFragment:r,leaf:e,node:r.value,svgRoot:h.isSvgRoot?r.value:null}),t&&l.needToCallNode&&(l.needToCallNode=0,effector.launch({target:we,params:{element:l.block.value,fns:f.node},page:e,defer:1,scope:e.root.scope})),effector.launch({target:s,params:e,defer:1,page:e,scope:e.root.scope})})),effector.merge([a,t]).watch((({leaf:e,value:t,hydration:a})=>{a||r(t,e.data.ops.visible)}));break}case'attr':case'data':case'style':case'styleVar':{let t=De[e.type],a=Se.some((({type:t,field:a})=>e.type===t&&e.field===a)),l=_({mount:s,state:e.value,onMount:(e,t)=>({leaf:t,value:e}),onState:(e,t)=>({leaf:e,value:t})});a?effector.merge([l.onState,l.onMount]).watch((({leaf:a,value:l})=>{t(Ce(a),e.field,l)})):j(f,{initCtx(a,l){let n=Ce(l);return t(n,e.field,a),n},runOp(a,l){t(l,e.field,a)},hooks:l});break}case'dynamicText':j(f,{initCtx:(t,a)=>z(a,t,e.childIndex),runOp(e,t){k(t.value,e)},hooks:_({mount:s,state:e.value,onMount:(e,t)=>({leaf:t,value:String(e)}),onState:(e,t)=>({leaf:e,value:String(t)})})});break;case'staticText':s.watch((t=>{z(t,e.value,e.childIndex)}));break;case'handler':{let t=e.handler.graphite.meta.nativeTemplate||null;s.watch((a=>{let l=null;if(t){let e=0,n=a;for(;!e&&n;)n.template===t?(e=1,l=n):n=n.parent}else l=null;Ce(a).addEventListener(e.for,(t=>{e.options.prevent&&t.preventDefault(),e.options.stop&&t.stopPropagation(),effector.launch({target:e.handler,params:t,page:l,scope:a.root.scope})}),e.domConfig)}));break}}})),i.watch((e=>{let t=e.data;if(!f.visible){let a=t.ops.visible,l=t.block;if(e.hydration){n(1,a);let e,t=A(l);if(e=t?t.nextSibling:O(l).firstChild,'#text'===e.nodeName){let t=e;e=e.nextSibling,t.remove()}l.value=e,l.visible=1}M(f,{parentBlockFragment:l,leaf:e,node:l.value,svgRoot:h.isSvgRoot?l.value:null}),effector.launch({target:s,params:e,defer:1,page:e,scope:e.root.scope}),e.hydration?t.needToCallNode&&(t.needToCallNode=0,effector.launch({target:we,params:{element:t.block.value,fns:f.node},page:e,defer:1,scope:e.root.scope})):r(1,a)}}))},env:s});N(h)},e.handler=V,e.list=ee,e.node=e=>{E(be,'node');let t=be.draft;switch(t.type){case'list':case'listItem':case'using':case'route':case'rec':case'recItem':case'block':case'blockItem':return void console.error('node() hook supported only in h() nodes')}t.node.push(e)},e.rec=ae,e.remap=Y,e.route=te,e.spec=U,e.text=(e,...t)=>{Array.isArray(e)?U({text:le(e,t)}):U({text:e})},e.tree=({source:e,key:t,child:a,fn:l})=>{let n=ae((({store:e})=>{ee({source:e,key:t,fn({store:e}){let t=e.map((e=>e[a]||[]));l({store:e,child(){n({store:t})}})}})}));n({store:e})},e.using=(e,t)=>{let a,l,n,r,o,i;if('function'==typeof t)a=t,n=Q(),r=0;else{if(!t)throw Error('using() second argument is missing');a=t.fn,n=t.env?t.env:Q(),r=t.hydrate,l=t.onComplete,o=t.onRoot,i=t.scope}P(e,'using() first argument is missing');let u={scope:i,env:n,activeSpawns:new Set,childSpawns:{},leafOps:{}},p=e.namespaceURI,d=e.tagName.toLowerCase(),f={type:'using',childTemplates:[],childCount:0,inParentIndex:-1},m=I({name:'using',draft:f,isSvgRoot:'svg'===d,namespace:'http://www.w3.org/2000/svg'===p?'svg':'foreignobject'===d?'foreignObject':'html',fn(e,{mount:t}){a(),t.watch(Te.using)},env:n}),h={type:'using',child:[],value:e},v=s({onComplete:l}),g=T(m,{parentLeaf:ye||null,mountNode:e,svgRoot:m.isSvgRoot?e:ye?ye.svgRoot:null,leafData:{type:'using',draft:f,element:e,block:h},opGroup:c(v),domSubtree:c(v),hydration:r,root:u});if(o&&o({template:m,leaf:g}),v.onDrain&&!v.rafID){let e=v.onDrain;v.onDrain=null,e()}},e.val=(e,...t)=>t.every((e=>!effector.is.store(e)))?le(e,t).join(''):effector.combine(t,(t=>le(e,t).join(''))),e.variant=({source:e,cases:t,key:a})=>{let l;E(be,'variant'),P(effector.is.unit(e),'variant({source}) should be unit'),l='function'==typeof a?a:null==a?e=>String(e):e=>String(e[a]);let n=0;for(let a in t)'__'!==a?te({source:e,visible:e=>l(e)===a,fn:t[a]}):n=1;if(n){let a=Object.keys(t);te({source:e,visible:e=>!a.includes(l(e)),fn:t.__})}},Object.defineProperty(e,'__esModule',{value:1})})); | ||
//# sourceMappingURL=forest.umd.js.map |
{ | ||
"name": "forest", | ||
"version": "0.20.2", | ||
"version": "0.20.3", | ||
"description": "UI engine for web", | ||
@@ -26,3 +26,3 @@ "main": "forest.cjs.js", | ||
"peerDependencies": { | ||
"effector": "^22.0.2" | ||
"effector": "^22.2.0" | ||
}, | ||
@@ -29,0 +29,0 @@ "keywords": [ |
@@ -12,3 +12,3 @@ # forest | ||
using(document.body, () => { | ||
const {change, submit, state} = formModel() | ||
const {change, submit, $fields} = formModel() | ||
@@ -43,3 +43,3 @@ h('section', () => { | ||
attr: { | ||
disabled: state.map(values => !(values.username && values.password)), | ||
disabled: $fields.map(fields => !(fields.username && fields.password)), | ||
}, | ||
@@ -52,3 +52,3 @@ }) | ||
h('div', {text: 'Reactive form debug:'}) | ||
h('pre', {text: state.map(stringify)}) | ||
h('pre', {text: $fields.map(stringify)}) | ||
}) | ||
@@ -59,7 +59,9 @@ }) | ||
function formModel() { | ||
const state = createStore({}) | ||
const changed = createEvent() | ||
const submit = createEvent() | ||
state.on(changed, (data, {name, value}) => ({...data, [name]: value})) | ||
const $fields = createStore({}) | ||
.on(changed, (fields, {name, value}) => ({ | ||
...fields, [name]: value | ||
})) | ||
@@ -69,3 +71,3 @@ const change = name => changed.prepend(e => ({name, value: e.target.value})) | ||
sample({ | ||
source: state, | ||
source: $fields, | ||
clock: submit, | ||
@@ -75,3 +77,3 @@ fn: stringify, | ||
return {change, submit, state} | ||
return {change, submit, $fields} | ||
} | ||
@@ -269,6 +271,6 @@ | ||
```typescript | ||
const username = createStore('guest') | ||
const $username = createStore('guest') | ||
h('h1', () => { | ||
text`Hello ${username}!` | ||
text`Hello ${$username}!` | ||
}) | ||
@@ -326,7 +328,8 @@ ``` | ||
```typescript | ||
const x = createStore(10) | ||
const y = 20 | ||
const $store = createStore(10) | ||
const a = 20 | ||
h('g', { | ||
attr: { | ||
transform: val`translate(${x} ${y})`, | ||
transform: val`translate(${$store} ${a})`, | ||
}, | ||
@@ -333,0 +336,0 @@ }) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
635992
1337
356