@askrjs/askr 0.0.26 → 0.0.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -57,12 +57,18 @@ Proven with 133 tests covering:
57
57
  Every component gets an AbortSignal for automatic cancellation.
58
58
 
59
59
  ```typescript
60
- async function Data({ id }) {
61
- const signal = getSignal();
62
- const data = await fetch(`/api/${id}`, { signal });
63
- return <div>{data}</div>;
60
+ import { resource, getSignal } from '@askrjs/askr/resources';
61
+
62
+ function Data({ id }) {
63
+ const data = resource(async () => {
64
+ const res = await fetch(`/api/${id}`, { signal: getSignal() });
65
+ return res.json();
66
+ }, [id]);
67
+
68
+ if (!data) return <div>Loading...</div>;
69
+ return <div>{data.name}</div>;
64
70
  }
65
- // Fetch cancelled automatically on unmount
71
+ // Async work is cancelled automatically on unmount/navigation
66
72
  ```
67
73
 
68
74
  ### Explicit Reactivity
@@ -1 +1 @@
1
- {"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../src/renderer/dom.ts"],"names":[],"mappings":"AA6BA,OAAO,EAAiB,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,MAAM,SAAS,CAAC;AAgCrE,eAAO,MAAM,gBAAgB,SAAkC,CAAC;AAudhE;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAkExD;AA4JD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,gBAAgB,CA6DlB;AAMD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,OAAO,EACX,KAAK,EAAE,KAAK,EACZ,cAAc,UAAO,GACpB,IAAI,CA+LN;AAED,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,OAAO,EACX,QAAQ,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,SAAS,GACpC,IAAI,CAuDN;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,OAAO,EAAE,GACrB,IAAI,CA+JN;AAED;;;;;GAKG;AACH,wBAAgB,oCAAoC,CAClD,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;;;;;EAgE3D;AA4MD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE;;;;;;EA6B3E;AA6GD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,KAAK,EAAE,WAyCrB"}
1
+ {"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../src/renderer/dom.ts"],"names":[],"mappings":"AA6BA,OAAO,EAAiB,KAAK,UAAU,EAAE,KAAK,KAAK,EAAE,MAAM,SAAS,CAAC;AAgCrE,eAAO,MAAM,gBAAgB,SAAkC,CAAC;AAudhE;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,GAAG,IAAI,CAkExD;AA4JD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,gBAAgB,CA6DlB;AAMD;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,EAAE,EAAE,OAAO,EACX,KAAK,EAAE,KAAK,EACZ,cAAc,UAAO,GACpB,IAAI,CA+LN;AAED,wBAAgB,qBAAqB,CACnC,EAAE,EAAE,OAAO,EACX,QAAQ,EAAE,KAAK,GAAG,KAAK,EAAE,GAAG,SAAS,GACpC,IAAI,CAkFN;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,OAAO,EAAE,GACrB,IAAI,CAmLN;AAED;;;;;GAKG;AACH,wBAAgB,oCAAoC,CAClD,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC;;;;;EAgE3D;AA4MD,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE;;;;;;EA6B3E;AA6GD;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,KAAK,EAAE,WAyCrB"}
@@ -1 +1 @@
1
- import{logger as Oe}from"../dev/logger.js";import"../jsx-runtime.js";import{CONTEXT_FRAME_SYMBOL as re,getCurrentContextFrame as oe,withContext as K}from"../runtime/context.js";import{getCurrentInstance as V,setCurrentComponentInstance as x,createComponentInstance as ie,renderComponentInline as se,mountInstanceInline as U}from"../runtime/component.js";import{elementListeners as y,elementReactivePropsCleanup as A,cleanupInstanceIfPresent as h,removeAllListeners as C}from"./cleanup.js";import{incDevCounter as q,getDevValue as ce,setDevValue as D}from"../runtime/dev-namespace.js";import"./types.js";import{__FOR_BOUNDARY__ as j,_isDOMElement as g}from"../common/vnode.js";import{evaluateForState as z}from"../runtime/for.js";import{keyedElements as E}from"./keyed.js";import{reconcileKeyedChildren as ae}from"./reconcile.js";import{createWrappedHandler as G,getPassiveOptions as X,isSkippedProp as $,parseEventName as Y,now as F,logFastPathDebug as I,recordFastPathStats as fe,hasNonTrivialProps as B,recordDOMReplace as le}from"./utils.js";import{globalScheduler as O}from"../runtime/scheduler.js";import{isEventDelegationEnabled as W,isDelegatedEvent as J,addDelegatedListener as Q,getDelegatedHandlersForElement as ue,removeDelegatedListener as k}from"../runtime/events.js";import{Fragment as de}from"../common/jsx.js";var P={};const pe=typeof document<"u";let H=0;function me(){const e="__COMPONENT_INSTANCE_ID";try{q(e);const t=ce(e);if(typeof t=="number"&&Number.isFinite(t))return`comp-${t}`}catch{}return H++,`comp-${H}`}function ye(e,t,n){const o=W()&&J(t);o&&Q(e,t,n,n,void 0);const r=G(n,!0),c=X(t);o||(c!==void 0?e.addEventListener(t,r,c):e.addEventListener(t,r)),y.has(e)||y.set(e,new Map),y.get(e).set(t,{handler:Z(o,e,t,r),original:n,options:c,isDelegated:o})}function Z(e,t,n,o){if(!e)return o;const r=ue(t);if(r){const c=r.get(n);if(c)return c.handler}return o}const v=new Set;let d=null,N=!1;function ge(){if(!d){d={id:"reactive-props-coordinator",lastRenderToken:0,hasPendingUpdate:!1,notifyUpdate:null,abortController:new AbortController};const e=()=>{if(!N)return;N=!1;const t=V();try{for(const n of v){if(!n.isActive)continue;for(const c of n.readStates)c._readers&&c._readers.delete(d);n.readStates.clear();const o=new Set,r={_pendingReadStates:o,_currentRenderToken:d.lastRenderToken};x(r);try{const c=n.propFn();te(n.el,n.propName,c,n.tagName),n.readStates=o}catch{}}d&&(d.lastRenderToken=(d.lastRenderToken??0)+1);for(const n of v)if(n.isActive)for(const o of n.readStates)o._readers||(o._readers=new Map),o._readers.set(d,d.lastRenderToken??0)}finally{x(t)}};d.notifyUpdate=()=>{N||(N=!0,O.isExecuting()?e():O.enqueue(e))},d._pendingFlushTask=()=>{d.hasPendingUpdate=!1,d.notifyUpdate()}}return d}function ee(e,t,n,o){const r=ge(),c={el:e,propName:t,propFn:n,tagName:o,readStates:new Set,isActive:!0};v.add(c);const s=V(),i=new Set,f={_pendingReadStates:i,_currentRenderToken:r.lastRenderToken};x(f);try{const a=n();te(e,t,a,o),c.readStates=i;for(const l of i)l._readers||(l._readers=new Map),l._readers.set(r,r.lastRenderToken??0)}finally{x(s)}return()=>{if(c.isActive=!1,v.delete(c),d)for(const a of c.readStates)a._readers&&a._readers.delete(d);c.readStates.clear(),v.size===0&&d&&(d.abortController.abort(),d=null)}}function te(e,t,n,o){if(n==null||n===!1){t==="class"||t==="className"?e.className="":e.removeAttribute(t);return}t==="class"||t==="className"?e.className=String(n):t==="value"||t==="checked"?ne(e,t,n,o):e.setAttribute(t,String(n))}function he(e,t,n){for(const o in t){const r=t[o];if(o==="ref"){Ae(e,r);continue}if($(o)||r==null||r===!1)continue;const c=Y(o);if(c){ye(e,c,r);continue}if(typeof r=="function"&&!c&&o!=="ref"){const s=ee(e,o,r,n);A.has(e)||A.set(e,new Map),A.get(e).set(o,{cleanup:s,fnRef:r});continue}o==="class"||o==="className"?e.className=String(r):o==="value"||o==="checked"?ne(e,o,r,n):e.setAttribute(o,String(r))}}function Ae(e,t){const n=t;if(n){if(typeof n=="function"){n(e);return}Object.isExtensible(n)&&(n.current=e)}}function ne(e,t,n,o){t==="value"?((b(o,"input")||b(o,"textarea")||b(o,"select"))&&(e.value=String(n)),e.setAttribute("value",String(n))):t==="checked"&&(b(o,"input")&&(e.checked=!!n),e.setAttribute("checked",String(!!n)))}function R(e,t,n){const o=t.key??n?.key;o!==void 0&&e.setAttribute("data-key",String(o))}function p(e){if(!pe)return null;if(typeof e=="string")return document.createTextNode(e);if(typeof e=="number")return document.createTextNode(String(e));if(!e)return null;if(Array.isArray(e)){const t=document.createDocumentFragment();for(const n of e){const o=p(n);o&&t.appendChild(o)}return t}if(typeof e=="object"&&e!==null&&"type"in e){const t=e.type,n=e.props||{};if(typeof t=="string")return Se(e,t,n);if(typeof t=="function")return Te(e,t,n);if(t===j)return be(e,n);if(typeof t=="symbol"&&(t===de||String(t)==="Symbol(Fragment)"))return _e(e,n)}return null}function Se(e,t,n){const o=document.createElement(t);R(o,e,n),he(o,n,t);const r=n.children??e.children;if(r!=null)if(Array.isArray(r)){for(const c of r){const s=p(c);s&&o.appendChild(s)}}else{const c=p(r);c&&o.appendChild(c)}return o}function Te(e,t,n){const r=e[re]||oe(),c=t;if(c.constructor.name==="AsyncFunction")throw new Error("Async components are not supported. Use resource() for async work.");let i=e.__instance;i||(i=ie(me(),c,n||{},null),e.__instance=i),r&&(i.ownerFrame=r);const f=K(r,()=>se(i));if(f instanceof Promise)throw new Error("Async components are not supported. Components must return synchronously.");const a=K(r,()=>p(f));if(a instanceof Element)return U(i,a),R(a,e,n),a;if(!a){const u=document.createComment("");return i._placeholder=u,i.mounted=!0,i.notifyUpdate=i._enqueueRun,u}const l=document.createElement("div");return l.appendChild(a),U(i,l),R(l,e,n),l}function _e(e,t){const n=document.createDocumentFragment(),o=t.children||e.children;if(o)if(Array.isArray(o))for(const r of o){const c=p(r);c&&n.appendChild(c)}else{const r=p(o);r&&n.appendChild(r)}return n}function Ce(e,t){if(!g(t)||!(e instanceof Element))return!0;const n=t.type;return typeof n!="string"?!0:e.tagName.toLowerCase()!==n.toLowerCase()}function be(e,t){const n=e._forState;if(!n)return document.createDocumentFragment();const o=t.source,r=z(n,o),c=document.createDocumentFragment();for(let s=0;s<r.length;s++){const i=r[s],f=n.orderedKeys[s],a=f!=null?n.items.get(f):null;let l=null;if(a&&a._dom){const u=a._dom;Ce(u,i)||(l=u)}l||(l=p(i),a&&(a._dom=l??void 0)),l&&(l instanceof Element&&S(l,i,!0),c.appendChild(l))}return c}function S(e,t,n=!0){if(!g(t))return;const o=t.props||{};R(e,t,o);const r=y.get(e);let c=null;for(const s in o){const i=o[s];if($(s))continue;const f=Y(s);if(i==null||i===!1){if(s==="class"||s==="className")e.className="";else if(f&&r?.has(f)){const a=r.get(f);a.isDelegated?k(e,f):a.options!==void 0?e.removeEventListener(f,a.handler,a.options):e.removeEventListener(f,a.handler),r.delete(f)}else e.removeAttribute(s);continue}if(typeof i=="function"&&!f&&s!=="ref"){const l=A.get(e)?.get(s);if(l&&l.fnRef===i)continue;l&&l.cleanup();const u=ee(e,s,i,t.type);A.has(e)||A.set(e,new Map),A.get(e).set(s,{cleanup:u,fnRef:i});continue}if(s==="class"||s==="className")e.className=String(i);else if(s==="value"||s==="checked")e[s]=i;else if(f){r&&r.size>0&&(c??=new Set).add(f);const a=W()&&J(f),l=r?.get(f);if(l&&l.original===i)continue;l&&(l.isDelegated?k(e,f):l.options!==void 0?e.removeEventListener(f,l.handler,l.options):e.removeEventListener(f,l.handler)),a&&Q(e,f,i,i,void 0);const u=G(i,!0),m=X(f);a||(m!==void 0?e.addEventListener(f,u,m):e.addEventListener(f,u)),y.has(e)||y.set(e,new Map),y.get(e).set(f,{handler:Z(a,e,f,u),original:i,options:m,isDelegated:a})}else e.setAttribute(s,String(i))}if(r&&r.size>0)if(c===null){for(const[s,i]of r)i.isDelegated?k(e,s):i.options!==void 0?e.removeEventListener(s,i.handler,i.options):e.removeEventListener(s,i.handler);y.delete(e)}else{for(const[s,i]of r)c.has(s)||(i.isDelegated?k(e,s):i.options!==void 0?e.removeEventListener(s,i.handler,i.options):e.removeEventListener(s,i.handler),r.delete(s));r.size===0&&y.delete(e)}if(n){const s=t.children||o.children;ve(e,s)}}function ve(e,t){if(t==null){e.textContent="";return}if(!Array.isArray(t)&&(typeof t=="string"||typeof t=="number")){e.childNodes.length===1&&e.firstChild?.nodeType===3?e.firstChild.data=String(t):e.textContent=String(t);return}if(Array.isArray(t)&&t.length===1&&g(t[0])&&t[0].type===j){const o=t[0],r=o._forState;if(!r)throw new Error("[updateElementChildren] For boundary missing _forState");const c=(o.props||{}).source,s=z(r,c),i=E.get(e),f=ae(e,s,i||new Map);E.set(e,f);return}if(Array.isArray(t)){Ee(e,t);return}e.textContent="";const n=p(t);n&&e.appendChild(n)}function Ee(e,t){const n=Array.from(e.children),o=t.some(s=>typeof s=="string"||typeof s=="number"),r=t.some(s=>g(s));if(o&&r){const s=Array.from(e.childNodes),i=Math.max(s.length,t.length);for(let f=0;f<i;f++){const a=s[f],l=t[f];if(l===void 0&&a){a.nodeType===1&&h(a),a.remove();continue}if(!a&&l!==void 0){const u=p(l);u&&e.appendChild(u);continue}if(!(!a||l===void 0)){if(typeof l=="string"||typeof l=="number")if(a.nodeType===3)a.data=String(l);else{const u=document.createTextNode(String(l));e.replaceChild(u,a)}else if(g(l))if(a.nodeType===1){const u=a;if(typeof l.type=="string")if(_(u.tagName,l.type))S(u,l);else{const m=p(l);m&&(C(u),h(u),e.replaceChild(m,a))}}else{const u=p(l);u&&e.replaceChild(u,a)}}}return}if(t.length===1&&n.length===0&&e.childNodes.length===1){const s=t[0],i=e.firstChild;if((typeof s=="string"||typeof s=="number")&&i?.nodeType===3){i.data=String(s);return}}n.length===0&&e.childNodes.length>0&&(e.textContent="");const c=Math.max(n.length,t.length);for(let s=0;s<c;s++){const i=n[s],f=t[s];if(f===void 0&&i){h(i),i.remove();continue}if(!i&&f!==void 0){const a=p(f);a&&e.appendChild(a);continue}if(!(!i||f===void 0))if(typeof f=="string"||typeof f=="number")i.textContent=String(f);else if(g(f))if(typeof f.type=="string")if(_(i.tagName,f.type))S(i,f);else{const a=p(f);a&&(i instanceof Element&&C(i),h(i),e.replaceChild(a,i))}else{const a=p(f);a&&(i instanceof Element&&C(i),h(i),e.replaceChild(a,i))}else{const a=p(f);a&&(i instanceof Element&&C(i),h(i),e.replaceChild(a,i))}}}function tt(e,t){const n=t.length;let o=0,r=0;const c=F(),s=P.ASKR_FASTPATH_DEBUG==="1"||P.ASKR_FASTPATH_DEBUG==="true";for(let a=0;a<n;a++){const{key:l,vnode:u}=t[a],m=e.children[a];if(m&&g(u)&&typeof u.type=="string"){const L=u.type;if(_(m.tagName,L)){const w=u.children||u.props?.children;s&&I("positional idx",a,{chTag:m.tagName,vnodeType:L,chChildNodes:m.childNodes.length,childrenType:Array.isArray(w)?"array":typeof w}),ke(m,w,u),De(m,l,()=>r++),o++;continue}else s&&I("positional tag mismatch",a,{chTag:m.tagName,vnodeType:L})}else s&&I("positional missing or invalid",a,{ch:!!m});Fe(e,a,u)}const i=F()-c;Pe(e,t);const f={n,reused:o,updatedKeys:r,t:i};return fe(f,"bulkKeyedPositionalHits"),f}function ke(e,t,n){typeof t=="string"||typeof t=="number"?(T(e,String(t)),n.props&&B(n.props)&&S(e,n,!1)):Array.isArray(t)&&t.length===1&&(typeof t[0]=="string"||typeof t[0]=="number")?(T(e,String(t[0])),n.props&&B(n.props)&&S(e,n,!1)):Ne(e,n)||S(e,n)}function Ne(e,t){const n=t.children||t.props?.children;if(!Array.isArray(n)||n.length!==2)return!1;const o=n[0],r=n[1];if(!g(o)||!g(r)||typeof o.type!="string"||typeof r.type!="string")return!1;const c=e.children[0],s=e.children[1];if(!c||!s||!_(c.tagName,o.type)||!_(s.tagName,r.type))return!1;const i=o.children||o.props?.children,f=r.children||r.props?.children;if(typeof i=="string"||typeof i=="number")T(c,String(i));else if(Array.isArray(i)&&i.length===1&&(typeof i[0]=="string"||typeof i[0]=="number"))T(c,String(i[0]));else return!1;if(typeof f=="string"||typeof f=="number")T(s,String(f));else if(Array.isArray(f)&&f.length===1&&(typeof f[0]=="string"||typeof f[0]=="number"))T(s,String(f[0]));else return!1;return!0}function T(e,t){e.childNodes.length===1&&e.firstChild?.nodeType===3?e.firstChild.data=t:e.textContent=t}function De(e,t,n){try{const o=String(t);if(e.getAttribute("data-key")===o)return;e.setAttribute("data-key",o),n()}catch{}}function xe(e){switch(e){case"div":return"DIV";case"span":return"SPAN";case"p":return"P";case"a":return"A";case"button":return"BUTTON";case"input":return"INPUT";case"ul":return"UL";case"ol":return"OL";case"li":return"LI";default:return null}}function b(e,t){if(e===t)return!0;const n=e.length;if(n!==t.length)return!1;for(let o=0;o<n;o++){const r=e.charCodeAt(o),c=t.charCodeAt(o);if(r===c)continue;const s=r>=65&&r<=90?r+32:r,i=c>=65&&c<=90?c+32:c;if(s!==i)return!1}return!0}function _(e,t){const n=xe(t);return n!==null&&e===n?!0:b(e,t)}function Fe(e,t,n){const o=p(n);if(o){const r=e.children[t];r?(h(r),e.replaceChild(o,r)):e.appendChild(o)}}function Pe(e,t){try{const n=E.get(e),o=n?(n.clear(),n):new Map;for(let r=0;r<t.length;r++){const c=t[r].key,s=e.children[r];s&&o.set(c,s)}E.set(e,o)}catch{}}function nt(e,t){const n=F(),o=Array.from(e.childNodes),r=[];let c=0,s=0;for(let l=0;l<t.length;l++){const u=Re(t[l],o[l],r);u==="reused"?c++:u==="created"&&s++}const i=F()-n,f=Ie(e,r);E.delete(e);const a={n:t.length,reused:c,created:s,tBuild:i,tCommit:f};return Me(a),a}function Re(e,t,n){return typeof e=="string"||typeof e=="number"?Le(String(e),t,n):typeof e=="object"&&e!==null&&"type"in e?we(e,t,n):"skipped"}function Le(e,t,n){return t&&t.nodeType===3?(t.data=e,n.push(t),"reused"):(n.push(document.createTextNode(e)),"created")}function we(e,t,n){const o=e;if(typeof o.type=="string"){const c=o.type;if(t&&t.nodeType===1&&_(t.tagName,c))return S(t,e),n.push(t),"reused"}const r=p(e);return r?(n.push(r),"created"):"skipped"}function Ie(e,t){const n=Date.now(),o=document.createDocumentFragment();for(let r=0;r<t.length;r++)o.appendChild(t[r]);try{for(let r=e.firstChild;r;){const c=r.nextSibling;r instanceof Element&&C(r),h(r),r=c}}catch{}return le("bulk-text-replace"),e.replaceChildren(o),Date.now()-n}function Me(e){try{D("__LAST_BULK_TEXT_FASTPATH_STATS",e),D("__LAST_FASTPATH_STATS",e),D("__LAST_FASTPATH_COMMIT_COUNT",1),q("bulkTextFastpathHits")}catch{}}function rt(e,t){const n=Number(P.ASKR_BULK_TEXT_THRESHOLD)||1024,o=.8,r=Array.isArray(t)?t.length:0;if(r<n)return M({phase:"bulk-unkeyed-eligible",reason:"too-small",total:r,threshold:n}),!1;const c=Ke(t);if(c.componentFound!==void 0)return M({phase:"bulk-unkeyed-eligible",reason:"component-child",index:c.componentFound}),!1;const s=c.simple/r,i=s>=o&&e.childNodes.length>=r;return M({phase:"bulk-unkeyed-eligible",total:r,simple:c.simple,fraction:s,requiredFraction:o,eligible:i}),i}function Ke(e){let t=0;for(let n=0;n<e.length;n++){const o=e[n];if(typeof o=="string"||typeof o=="number"){t++;continue}if(typeof o=="object"&&o!==null&&"type"in o){const r=o;if(typeof r.type=="function")return{simple:t,componentFound:n};typeof r.type=="string"&&Ue(r)&&t++}}return{simple:t}}function Ue(e){const t=e.children||e.props?.children;return!!(t==null||typeof t=="string"||typeof t=="number"||Array.isArray(t)&&t.length===1&&(typeof t[0]=="string"||typeof t[0]=="number"))}function M(e){if(P.ASKR_FASTPATH_DEBUG==="1")try{D("__BULK_DIAG",e)}catch{}}export{pe as IS_DOM_AVAILABLE,p as createDOMNode,be as createForBoundary,rt as isBulkTextFastPathEligible,tt as performBulkPositionalKeyedTextUpdate,nt as performBulkTextReplace,ve as updateElementChildren,S as updateElementFromVnode,Ee as updateUnkeyedChildren};
1
+ import{logger as Oe}from"../dev/logger.js";import"../jsx-runtime.js";import{CONTEXT_FRAME_SYMBOL as re,getCurrentContextFrame as oe,withContext as K}from"../runtime/context.js";import{getCurrentInstance as V,setCurrentComponentInstance as D,createComponentInstance as ie,renderComponentInline as se,mountInstanceInline as U}from"../runtime/component.js";import{elementListeners as h,elementReactivePropsCleanup as A,removeAllListeners as y,cleanupInstanceIfPresent as g}from"./cleanup.js";import{incDevCounter as q,getDevValue as ce,setDevValue as N}from"../runtime/dev-namespace.js";import"./types.js";import{__FOR_BOUNDARY__ as j,_isDOMElement as S}from"../common/vnode.js";import{evaluateForState as z}from"../runtime/for.js";import{keyedElements as v}from"./keyed.js";import{reconcileKeyedChildren as ae}from"./reconcile.js";import{createWrappedHandler as G,getPassiveOptions as X,isSkippedProp as $,parseEventName as Y,now as F,logFastPathDebug as I,recordFastPathStats as fe,hasNonTrivialProps as B,recordDOMReplace as le}from"./utils.js";import{globalScheduler as O}from"../runtime/scheduler.js";import{isEventDelegationEnabled as W,isDelegatedEvent as J,addDelegatedListener as Q,getDelegatedHandlersForElement as ue,removeDelegatedListener as k}from"../runtime/events.js";import{Fragment as de}from"../common/jsx.js";var P={};const pe=typeof document<"u";let H=0;function me(){const e="__COMPONENT_INSTANCE_ID";try{q(e);const t=ce(e);if(typeof t=="number"&&Number.isFinite(t))return`comp-${t}`}catch{}return H++,`comp-${H}`}function ge(e,t,n){const r=W()&&J(t);r&&Q(e,t,n,n,void 0);const o=G(n,!0),a=X(t);r||(a!==void 0?e.addEventListener(t,o,a):e.addEventListener(t,o)),h.has(e)||h.set(e,new Map),h.get(e).set(t,{handler:Z(r,e,t,o),original:n,options:a,isDelegated:r})}function Z(e,t,n,r){if(!e)return r;const o=ue(t);if(o){const a=o.get(n);if(a)return a.handler}return r}const E=new Set;let d=null,x=!1;function ye(){if(!d){d={id:"reactive-props-coordinator",lastRenderToken:0,hasPendingUpdate:!1,notifyUpdate:null,abortController:new AbortController};const e=()=>{if(!x)return;x=!1;const t=V();try{for(const n of E){if(!n.isActive)continue;for(const a of n.readStates)a._readers&&a._readers.delete(d);n.readStates.clear();const r=new Set,o={_pendingReadStates:r,_currentRenderToken:d.lastRenderToken};D(o);try{const a=n.propFn();te(n.el,n.propName,a,n.tagName),n.readStates=r}catch{}}d&&(d.lastRenderToken=(d.lastRenderToken??0)+1);for(const n of E)if(n.isActive)for(const r of n.readStates)r._readers||(r._readers=new Map),r._readers.set(d,d.lastRenderToken??0)}finally{D(t)}};d.notifyUpdate=()=>{x||(x=!0,O.isExecuting()?e():O.enqueue(e))},d._pendingFlushTask=()=>{d.hasPendingUpdate=!1,d.notifyUpdate()}}return d}function ee(e,t,n,r){const o=ye(),a={el:e,propName:t,propFn:n,tagName:r,readStates:new Set,isActive:!0};E.add(a);const s=V(),i=new Set,f={_pendingReadStates:i,_currentRenderToken:o.lastRenderToken};D(f);try{const c=n();te(e,t,c,r),a.readStates=i;for(const l of i)l._readers||(l._readers=new Map),l._readers.set(o,o.lastRenderToken??0)}finally{D(s)}return()=>{if(a.isActive=!1,E.delete(a),d)for(const c of a.readStates)c._readers&&c._readers.delete(d);a.readStates.clear(),E.size===0&&d&&(d.abortController.abort(),d=null)}}function te(e,t,n,r){if(n==null||n===!1){t==="class"||t==="className"?e.className="":e.removeAttribute(t);return}t==="class"||t==="className"?e.className=String(n):t==="value"||t==="checked"?ne(e,t,n,r):e.setAttribute(t,String(n))}function he(e,t,n){for(const r in t){const o=t[r];if(r==="ref"){Se(e,o);continue}if($(r)||o==null||o===!1)continue;const a=Y(r);if(a){ge(e,a,o);continue}if(typeof o=="function"&&!a&&r!=="ref"){const s=ee(e,r,o,n);A.has(e)||A.set(e,new Map),A.get(e).set(r,{cleanup:s,fnRef:o});continue}r==="class"||r==="className"?e.className=String(o):r==="value"||r==="checked"?ne(e,r,o,n):e.setAttribute(r,String(o))}}function Se(e,t){const n=t;if(n){if(typeof n=="function"){n(e);return}Object.isExtensible(n)&&(n.current=e)}}function ne(e,t,n,r){t==="value"?((b(r,"input")||b(r,"textarea")||b(r,"select"))&&(e.value=String(n)),e.setAttribute("value",String(n))):t==="checked"&&(b(r,"input")&&(e.checked=!!n),e.setAttribute("checked",String(!!n)))}function R(e,t,n){const r=t.key??n?.key;r!==void 0&&e.setAttribute("data-key",String(r))}function p(e){if(!pe)return null;if(typeof e=="string")return document.createTextNode(e);if(typeof e=="number")return document.createTextNode(String(e));if(!e)return null;if(Array.isArray(e)){const t=document.createDocumentFragment();for(const n of e){const r=p(n);r&&t.appendChild(r)}return t}if(typeof e=="object"&&e!==null&&"type"in e){const t=e.type,n=e.props||{};if(typeof t=="string")return Ae(e,t,n);if(typeof t=="function")return Ce(e,t,n);if(t===j)return be(e,n);if(typeof t=="symbol"&&(t===de||String(t)==="Symbol(Fragment)"))return Te(e,n)}return null}function Ae(e,t,n){const r=document.createElement(t);R(r,e,n),he(r,n,t);const o=n.children??e.children;if(o!=null)if(Array.isArray(o)){for(const a of o){const s=p(a);s&&r.appendChild(s)}}else{const a=p(o);a&&r.appendChild(a)}return r}function Ce(e,t,n){const o=e[re]||oe(),a=t;if(a.constructor.name==="AsyncFunction")throw new Error("Async components are not supported. Use resource() for async work.");let i=e.__instance;i||(i=ie(me(),a,n||{},null),e.__instance=i),o&&(i.ownerFrame=o);const f=K(o,()=>se(i));if(f instanceof Promise)throw new Error("Async components are not supported. Components must return synchronously.");const c=K(o,()=>p(f));if(c instanceof Element)return U(i,c),R(c,e,n),c;if(!c){const u=document.createComment("");return i._placeholder=u,i.mounted=!0,i.notifyUpdate=i._enqueueRun,u}const l=document.createElement("div");return l.appendChild(c),U(i,l),R(l,e,n),l}function Te(e,t){const n=document.createDocumentFragment(),r=t.children||e.children;if(r)if(Array.isArray(r))for(const o of r){const a=p(o);a&&n.appendChild(a)}else{const o=p(r);o&&n.appendChild(o)}return n}function _e(e,t){if(!S(t)||!(e instanceof Element))return!0;const n=t.type;return typeof n!="string"?!0:e.tagName.toLowerCase()!==n.toLowerCase()}function be(e,t){const n=e._forState;if(!n)return document.createDocumentFragment();const r=t.source,o=z(n,r),a=document.createDocumentFragment();for(let s=0;s<o.length;s++){const i=o[s],f=n.orderedKeys[s],c=f!=null?n.items.get(f):null;let l=null;if(c&&c._dom){const u=c._dom;_e(u,i)||(l=u)}l||(l=p(i),c&&(c._dom=l??void 0)),l&&(l instanceof Element&&C(l,i,!0),a.appendChild(l))}return a}function C(e,t,n=!0){if(!S(t))return;const r=t.props||{};R(e,t,r);const o=h.get(e);let a=null;for(const s in r){const i=r[s];if($(s))continue;const f=Y(s);if(i==null||i===!1){if(s==="class"||s==="className")e.className="";else if(f&&o?.has(f)){const c=o.get(f);c.isDelegated?k(e,f):c.options!==void 0?e.removeEventListener(f,c.handler,c.options):e.removeEventListener(f,c.handler),o.delete(f)}else e.removeAttribute(s);continue}if(typeof i=="function"&&!f&&s!=="ref"){const l=A.get(e)?.get(s);if(l&&l.fnRef===i)continue;l&&l.cleanup();const u=ee(e,s,i,t.type);A.has(e)||A.set(e,new Map),A.get(e).set(s,{cleanup:u,fnRef:i});continue}if(s==="class"||s==="className")e.className=String(i);else if(s==="value"||s==="checked")e[s]=i;else if(f){o&&o.size>0&&(a??=new Set).add(f);const c=W()&&J(f),l=o?.get(f);if(l&&l.original===i)continue;l&&(l.isDelegated?k(e,f):l.options!==void 0?e.removeEventListener(f,l.handler,l.options):e.removeEventListener(f,l.handler)),c&&Q(e,f,i,i,void 0);const u=G(i,!0),m=X(f);c||(m!==void 0?e.addEventListener(f,u,m):e.addEventListener(f,u)),h.has(e)||h.set(e,new Map),h.get(e).set(f,{handler:Z(c,e,f,u),original:i,options:m,isDelegated:c})}else e.setAttribute(s,String(i))}if(o&&o.size>0)if(a===null){for(const[s,i]of o)i.isDelegated?k(e,s):i.options!==void 0?e.removeEventListener(s,i.handler,i.options):e.removeEventListener(s,i.handler);h.delete(e)}else{for(const[s,i]of o)a.has(s)||(i.isDelegated?k(e,s):i.options!==void 0?e.removeEventListener(s,i.handler,i.options):e.removeEventListener(s,i.handler),o.delete(s));o.size===0&&h.delete(e)}if(n){const s=t.children||r.children;Ee(e,s)}}function Ee(e,t){if(t==null){for(let r=e.firstChild;r;){const o=r.nextSibling;r instanceof Element&&(y(r),g(r)),r=o}e.textContent="";return}if(!Array.isArray(t)&&(typeof t=="string"||typeof t=="number")){if(e.childNodes.length===1&&e.firstChild?.nodeType===3)e.firstChild.data=String(t);else{for(let r=e.firstChild;r;){const o=r.nextSibling;r instanceof Element&&(y(r),g(r)),r=o}e.textContent=String(t)}return}if(Array.isArray(t)&&t.length===1&&S(t[0])&&t[0].type===j){const r=t[0],o=r._forState;if(!o)throw new Error("[updateElementChildren] For boundary missing _forState");const a=(r.props||{}).source,s=z(o,a),i=v.get(e),f=ae(e,s,i||new Map);v.set(e,f);return}if(Array.isArray(t)){ve(e,t);return}for(let r=e.firstChild;r;){const o=r.nextSibling;r instanceof Element&&(y(r),g(r)),r=o}e.textContent="";const n=p(t);n&&e.appendChild(n)}function ve(e,t){const n=Array.from(e.children),r=t.some(s=>typeof s=="string"||typeof s=="number"),o=t.some(s=>S(s));if(r&&o){const s=Array.from(e.childNodes),i=Math.max(s.length,t.length);for(let f=0;f<i;f++){const c=s[f],l=t[f];if(l===void 0&&c){c.nodeType===1&&g(c),c.remove();continue}if(!c&&l!==void 0){const u=p(l);u&&e.appendChild(u);continue}if(!(!c||l===void 0)){if(typeof l=="string"||typeof l=="number")if(c.nodeType===3)c.data=String(l);else{const u=document.createTextNode(String(l));e.replaceChild(u,c)}else if(S(l))if(c.nodeType===1){const u=c;if(typeof l.type=="string")if(_(u.tagName,l.type))C(u,l);else{const m=p(l);m&&(y(u),g(u),e.replaceChild(m,c))}}else{const u=p(l);u&&e.replaceChild(u,c)}}}return}if(t.length===1&&n.length===0&&e.childNodes.length===1){const s=t[0],i=e.firstChild;if((typeof s=="string"||typeof s=="number")&&i?.nodeType===3){i.data=String(s);return}}if(n.length===0&&e.childNodes.length>0){for(let s=e.firstChild;s;){const i=s.nextSibling;s instanceof Element&&(y(s),g(s)),s=i}e.textContent=""}const a=Math.max(n.length,t.length);for(let s=0;s<a;s++){const i=n[s],f=t[s];if(f===void 0&&i){g(i),i.remove();continue}if(!i&&f!==void 0){const c=p(f);c&&e.appendChild(c);continue}if(!(!i||f===void 0))if(typeof f=="string"||typeof f=="number"){if(i instanceof Element&&i.childNodes.length>0)for(let c=i.firstChild;c;){const l=c.nextSibling;c instanceof Element&&(y(c),g(c)),c=l}i.textContent=String(f)}else if(S(f))if(typeof f.type=="string")if(_(i.tagName,f.type))C(i,f);else{const c=p(f);c&&(i instanceof Element&&y(i),g(i),e.replaceChild(c,i))}else{const c=p(f);c&&(i instanceof Element&&y(i),g(i),e.replaceChild(c,i))}else{const c=p(f);c&&(i instanceof Element&&y(i),g(i),e.replaceChild(c,i))}}}function tt(e,t){const n=t.length;let r=0,o=0;const a=F(),s=P.ASKR_FASTPATH_DEBUG==="1"||P.ASKR_FASTPATH_DEBUG==="true";for(let c=0;c<n;c++){const{key:l,vnode:u}=t[c],m=e.children[c];if(m&&S(u)&&typeof u.type=="string"){const L=u.type;if(_(m.tagName,L)){const w=u.children||u.props?.children;s&&I("positional idx",c,{chTag:m.tagName,vnodeType:L,chChildNodes:m.childNodes.length,childrenType:Array.isArray(w)?"array":typeof w}),ke(m,w,u),Ne(m,l,()=>o++),r++;continue}else s&&I("positional tag mismatch",c,{chTag:m.tagName,vnodeType:L})}else s&&I("positional missing or invalid",c,{ch:!!m});Fe(e,c,u)}const i=F()-a;Pe(e,t);const f={n,reused:r,updatedKeys:o,t:i};return fe(f,"bulkKeyedPositionalHits"),f}function ke(e,t,n){typeof t=="string"||typeof t=="number"?(T(e,String(t)),n.props&&B(n.props)&&C(e,n,!1)):Array.isArray(t)&&t.length===1&&(typeof t[0]=="string"||typeof t[0]=="number")?(T(e,String(t[0])),n.props&&B(n.props)&&C(e,n,!1)):xe(e,n)||C(e,n)}function xe(e,t){const n=t.children||t.props?.children;if(!Array.isArray(n)||n.length!==2)return!1;const r=n[0],o=n[1];if(!S(r)||!S(o)||typeof r.type!="string"||typeof o.type!="string")return!1;const a=e.children[0],s=e.children[1];if(!a||!s||!_(a.tagName,r.type)||!_(s.tagName,o.type))return!1;const i=r.children||r.props?.children,f=o.children||o.props?.children;if(typeof i=="string"||typeof i=="number")T(a,String(i));else if(Array.isArray(i)&&i.length===1&&(typeof i[0]=="string"||typeof i[0]=="number"))T(a,String(i[0]));else return!1;if(typeof f=="string"||typeof f=="number")T(s,String(f));else if(Array.isArray(f)&&f.length===1&&(typeof f[0]=="string"||typeof f[0]=="number"))T(s,String(f[0]));else return!1;return!0}function T(e,t){e.childNodes.length===1&&e.firstChild?.nodeType===3?e.firstChild.data=t:e.textContent=t}function Ne(e,t,n){try{const r=String(t);if(e.getAttribute("data-key")===r)return;e.setAttribute("data-key",r),n()}catch{}}function De(e){switch(e){case"div":return"DIV";case"span":return"SPAN";case"p":return"P";case"a":return"A";case"button":return"BUTTON";case"input":return"INPUT";case"ul":return"UL";case"ol":return"OL";case"li":return"LI";default:return null}}function b(e,t){if(e===t)return!0;const n=e.length;if(n!==t.length)return!1;for(let r=0;r<n;r++){const o=e.charCodeAt(r),a=t.charCodeAt(r);if(o===a)continue;const s=o>=65&&o<=90?o+32:o,i=a>=65&&a<=90?a+32:a;if(s!==i)return!1}return!0}function _(e,t){const n=De(t);return n!==null&&e===n?!0:b(e,t)}function Fe(e,t,n){const r=p(n);if(r){const o=e.children[t];o?(g(o),e.replaceChild(r,o)):e.appendChild(r)}}function Pe(e,t){try{const n=v.get(e),r=n?(n.clear(),n):new Map;for(let o=0;o<t.length;o++){const a=t[o].key,s=e.children[o];s&&r.set(a,s)}v.set(e,r)}catch{}}function nt(e,t){const n=F(),r=Array.from(e.childNodes),o=[];let a=0,s=0;for(let l=0;l<t.length;l++){const u=Re(t[l],r[l],o);u==="reused"?a++:u==="created"&&s++}const i=F()-n,f=Ie(e,o);v.delete(e);const c={n:t.length,reused:a,created:s,tBuild:i,tCommit:f};return Me(c),c}function Re(e,t,n){return typeof e=="string"||typeof e=="number"?Le(String(e),t,n):typeof e=="object"&&e!==null&&"type"in e?we(e,t,n):"skipped"}function Le(e,t,n){return t&&t.nodeType===3?(t.data=e,n.push(t),"reused"):(n.push(document.createTextNode(e)),"created")}function we(e,t,n){const r=e;if(typeof r.type=="string"){const a=r.type;if(t&&t.nodeType===1&&_(t.tagName,a))return C(t,e),n.push(t),"reused"}const o=p(e);return o?(n.push(o),"created"):"skipped"}function Ie(e,t){const n=Date.now(),r=document.createDocumentFragment();for(let o=0;o<t.length;o++)r.appendChild(t[o]);try{for(let o=e.firstChild;o;){const a=o.nextSibling;o instanceof Element&&y(o),g(o),o=a}}catch{}return le("bulk-text-replace"),e.replaceChildren(r),Date.now()-n}function Me(e){try{N("__LAST_BULK_TEXT_FASTPATH_STATS",e),N("__LAST_FASTPATH_STATS",e),N("__LAST_FASTPATH_COMMIT_COUNT",1),q("bulkTextFastpathHits")}catch{}}function rt(e,t){const n=Number(P.ASKR_BULK_TEXT_THRESHOLD)||1024,r=.8,o=Array.isArray(t)?t.length:0;if(o<n)return M({phase:"bulk-unkeyed-eligible",reason:"too-small",total:o,threshold:n}),!1;const a=Ke(t);if(a.componentFound!==void 0)return M({phase:"bulk-unkeyed-eligible",reason:"component-child",index:a.componentFound}),!1;const s=a.simple/o,i=s>=r&&e.childNodes.length>=o;return M({phase:"bulk-unkeyed-eligible",total:o,simple:a.simple,fraction:s,requiredFraction:r,eligible:i}),i}function Ke(e){let t=0;for(let n=0;n<e.length;n++){const r=e[n];if(typeof r=="string"||typeof r=="number"){t++;continue}if(typeof r=="object"&&r!==null&&"type"in r){const o=r;if(typeof o.type=="function")return{simple:t,componentFound:n};typeof o.type=="string"&&Ue(o)&&t++}}return{simple:t}}function Ue(e){const t=e.children||e.props?.children;return!!(t==null||typeof t=="string"||typeof t=="number"||Array.isArray(t)&&t.length===1&&(typeof t[0]=="string"||typeof t[0]=="number"))}function M(e){if(P.ASKR_FASTPATH_DEBUG==="1")try{N("__BULK_DIAG",e)}catch{}}export{pe as IS_DOM_AVAILABLE,p as createDOMNode,be as createForBoundary,rt as isBulkTextFastPathEligible,tt as performBulkPositionalKeyedTextUpdate,nt as performBulkTextReplace,Ee as updateElementChildren,C as updateElementFromVnode,ve as updateUnkeyedChildren};
@@ -1 +1 @@
1
- {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/renderer/evaluate.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,gBAAgB,SAAkC,CAAC;AAijBhE,wBAAgB,QAAQ,CACtB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,OAAO,GAAG,IAAI,EACtB,OAAO,CAAC,EAAE,MAAM,GACf,IAAI,CA8IN;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAEnD"}
1
+ {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/renderer/evaluate.ts"],"names":[],"mappings":"AAuCA,eAAO,MAAM,gBAAgB,SAAkC,CAAC;AA0lBhE,wBAAgB,QAAQ,CACtB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,OAAO,GAAG,IAAI,EACtB,OAAO,CAAC,EAAE,MAAM,GACf,IAAI,CA8IN;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAEnD"}
@@ -1 +1 @@
1
- import{logger as k}from"../dev/logger.js";import{elementListeners as A,removeAllListeners as F}from"./cleanup.js";import{keyedElements as a}from"./keyed.js";import{reconcileKeyedChildren as T}from"./reconcile.js";import"./types.js";import{_isDOMElement as c,__FOR_BOUNDARY__ as h}from"../common/vnode.js";import{evaluateForState as b}from"../runtime/for.js";import{performBulkPositionalKeyedTextUpdate as M,isBulkTextFastPathEligible as D,performBulkTextReplace as B,updateUnkeyedChildren as w,createDOMNode as u,updateElementFromVnode as S}from"./dom.js";import{setDevValue as E,incDevCounter as P}from"../runtime/dev-namespace.js";import{Fragment as R}from"../common/jsx.js";import{extractKey as O,parseEventName as U,createWrappedHandler as H,getPassiveOptions as L}from"./utils.js";var p={};const ae=typeof document<"u",y=new WeakMap;function _(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){const i=e.charCodeAt(n),r=t.charCodeAt(n);if(i===r)continue;const s=i>=65&&i<=90?i+32:i,o=r>=65&&r<=90?r+32:r;if(s!==o)return!1}return!0}function I(e){if(Array.isArray(e)){if(e.length===1){const t=e[0];if(typeof t=="string"||typeof t=="number")return{isSimple:!0,text:String(t)}}}else if(typeof e=="string"||typeof e=="number")return{isSimple:!0,text:String(e)};return{isSimple:!1}}function v(e,t){return e.childNodes.length===1&&e.firstChild?.nodeType===3?(e.firstChild.data=t,!0):!1}function N(e){const t=new Map;for(let n=e.firstElementChild;n;n=n.nextElementSibling){const i=n.getAttribute("data-key");if(i!==null){t.set(i,n);const r=Number(i);Number.isNaN(r)||t.set(r,n)}}return t}function V(e){let t=a.get(e);return t||(t=N(e),t.size>0&&a.set(e,t)),t.size>0?t:void 0}function x(e){for(let t=0;t<e.length;t++)if(O(e[t])!==void 0)return!0;return!1}function G(e,t,n){if(p.ASKR_FORCE_BULK_POSREUSE==="1"&&W(e,t))return;const i=T(e,t,n);a.set(e,i)}function W(e,t){try{const n=[];for(const s of t)c(s)&&s.key!==void 0&&n.push({key:s.key,vnode:s});if(n.length===0||n.length!==t.length)return!1;(p.ASKR_FASTPATH_DEBUG==="1"||p.ASKR_FASTPATH_DEBUG==="true")&&k.warn("[Askr][FASTPATH] forced positional bulk keyed reuse (evaluate-level)");const i=M(e,n);if(p.ASKR_FASTPATH_DEBUG==="1")try{E("__LAST_FASTPATH_STATS",i),E("__LAST_FASTPATH_COMMIT_COUNT",1),P("bulkKeyedPositionalForced")}catch{}const r=N(e);return a.set(e,r),!0}catch(n){return(p.ASKR_FASTPATH_DEBUG==="1"||p.ASKR_FASTPATH_DEBUG==="true")&&k.warn("[Askr][FASTPATH] forced bulk path failed, falling back",n),!1}}function z(e,t){if(D(e,t)){const n=B(e,t);}else w(e,t);a.delete(e)}function C(e,t){const n=t._forState;if(!n)return;const i=(t.props||{}).source,r=b(n,i);for(;e.firstChild;)e.removeChild(e.firstChild);for(let s=0;s<r.length;s++){const o=r[s],f=n.orderedKeys[s],d=f!=null?n.items.get(f):null;let l=null;if(d&&d._dom){const m=d._dom;(!(m instanceof Element)||!o?.type||typeof o.type!="string"||m.tagName.toLowerCase()===o.type.toLowerCase())&&(l=m)}l||(l=u(o),d&&(d._dom=l??void 0)),l&&(l instanceof Element&&c(o)&&S(l,o,!0),e.appendChild(l))}a.delete(e)}function K(e,t){if(t==null){e.textContent="",a.delete(e);return}if(!Array.isArray(t)&&c(t)&&t.type===h){C(e,t);return}if(!Array.isArray(t)){e.textContent="";const n=u(t);n&&e.appendChild(n),a.delete(e);return}if(t.length===1&&c(t[0])&&t[0].type===h){C(e,t[0]);return}if(x(t)){const n=V(e);try{G(e,t,n)}catch{const i=T(e,t,n);a.set(e,i)}}else z(e,t)}function g(e,t){let n=t.children||t.props?.children;if(n&&c(n)&&n.type===h){K(e,n),S(e,t,!1);return}n&&!Array.isArray(n)&&(n=[n]);const i=I(n);i.isSimple&&v(e,i.text)||K(e,n),S(e,t,!1)}function j(e,t){let n=e.firstElementChild;for(let i=0;i<t.length;i++){const r=t[i],s=n?n.nextElementSibling:null;if(n&&c(r)&&typeof r.type=="string"&&_(n.tagName,r.type)){g(n,r),n=s;continue}const o=u(r);o&&(n?e.replaceChild(o,n):e.appendChild(o)),n=s}for(;n;){const i=n.nextElementSibling;e.removeChild(n),n=i}}function q(e,t){for(const[n,i]of Object.entries(t)){if(n==="children"||n==="key"||i==null||i===!1)continue;if(n==="ref"){X(e,i);continue}const r=U(n);if(r){const s=H(i,!0),o=L(r);o!==void 0?e.addEventListener(r,s,o):e.addEventListener(r,s),A.has(e)||A.set(e,new Map),A.get(e).set(r,{handler:s,original:i,options:o});continue}n==="class"||n==="className"?e.className=String(i):n==="value"||n==="checked"?e[n]=i:e.setAttribute(n,String(i))}}function X(e,t){const n=t;if(n){if(typeof n=="function"){n(e);return}try{n.current=e}catch{}}}function Y(e,t){const n=t.children;if(!Array.isArray(n)||!x(n))return!1;const i=document.createElement(t.type);e.appendChild(i),q(i,t.props||{});const r=T(i,n,void 0);return a.set(i,r),!0}function J(e){return c(e)&&typeof e.type=="symbol"&&(e.type===R||String(e.type)==="Symbol(askr.fragment)")}function Q(e){const t=e.props?.children||e.children||[];return Array.isArray(t)?t:[t]}function le(e,t,n){if(t&&!(typeof document>"u"))if(n&&y.has(n)){const i=y.get(n);let r=i.start.nextSibling;for(;r&&r!==i.end;){const o=r.nextSibling;r.remove(),r=o}const s=u(e);s&&t.insertBefore(s,i.end)}else if(n){const i=document.createComment("component-start"),r=document.createComment("component-end");t.appendChild(i),t.appendChild(r),y.set(n,{start:i,end:r});const s=u(e);s&&t.insertBefore(s,r)}else{let i=e;if(J(i)){const f=Q(i);if(f.length===1&&c(f[0])&&typeof f[0].type=="string")i=f[0];else{j(t,f);return}}const s=t.__ASKR_INSTANCE;if(s&&s.target===t)if(c(i)&&typeof i.type=="string"&&_(t.tagName,i.type)){g(t,i);return}else{const f=u(i);if(f&&t.parentNode){f instanceof Element&&(f.__ASKR_INSTANCE=s,s.target=f),F(t),t.parentNode.replaceChild(f,t);return}}const o=t.children[0];if(o&&c(i)&&typeof i.type=="string"&&_(o.tagName,i.type))g(o,i);else{if(t.textContent="",c(i)&&typeof i.type=="string"&&Y(t,i))return;const f=u(i);f&&t.appendChild(f)}}}function ue(e){y.delete(e)}export{ae as IS_DOM_AVAILABLE,ue as clearDOMRange,le as evaluate};
1
+ import{logger as b}from"../dev/logger.js";import{removeAllListeners as y,cleanupInstanceIfPresent as h,elementListeners as _}from"./cleanup.js";import{keyedElements as a}from"./keyed.js";import{reconcileKeyedChildren as C}from"./reconcile.js";import"./types.js";import{_isDOMElement as l,__FOR_BOUNDARY__ as T}from"../common/vnode.js";import{evaluateForState as D}from"../runtime/for.js";import{performBulkPositionalKeyedTextUpdate as B,isBulkTextFastPathEligible as P,performBulkTextReplace as R,updateUnkeyedChildren as O,createDOMNode as p,updateElementFromVnode as k}from"./dom.js";import{setDevValue as K,incDevCounter as U}from"../runtime/dev-namespace.js";import{Fragment as H}from"../common/jsx.js";import{extractKey as I,parseEventName as L,createWrappedHandler as v,getPassiveOptions as V}from"./utils.js";var d={};const pe=typeof document<"u",S=new WeakMap;function E(e,n){if(e===n)return!0;if(e.length!==n.length)return!1;for(let t=0;t<e.length;t++){const i=e.charCodeAt(t),r=n.charCodeAt(t);if(i===r)continue;const s=i>=65&&i<=90?i+32:i,f=r>=65&&r<=90?r+32:r;if(s!==f)return!1}return!0}function G(e){if(Array.isArray(e)){if(e.length===1){const n=e[0];if(typeof n=="string"||typeof n=="number")return{isSimple:!0,text:String(n)}}}else if(typeof e=="string"||typeof e=="number")return{isSimple:!0,text:String(e)};return{isSimple:!1}}function W(e,n){return e.childNodes.length===1&&e.firstChild?.nodeType===3?(e.firstChild.data=n,!0):!1}function M(e){const n=new Map;for(let t=e.firstElementChild;t;t=t.nextElementSibling){const i=t.getAttribute("data-key");if(i!==null){n.set(i,t);const r=Number(i);Number.isNaN(r)||n.set(r,t)}}return n}function z(e){let n=a.get(e);return n||(n=M(e),n.size>0&&a.set(e,n)),n.size>0?n:void 0}function w(e){for(let n=0;n<e.length;n++)if(I(e[n])!==void 0)return!0;return!1}function j(e,n,t){if(d.ASKR_FORCE_BULK_POSREUSE==="1"&&q(e,n))return;const i=C(e,n,t);a.set(e,i)}function q(e,n){try{const t=[];for(const s of n)l(s)&&s.key!==void 0&&t.push({key:s.key,vnode:s});if(t.length===0||t.length!==n.length)return!1;(d.ASKR_FASTPATH_DEBUG==="1"||d.ASKR_FASTPATH_DEBUG==="true")&&b.warn("[Askr][FASTPATH] forced positional bulk keyed reuse (evaluate-level)");const i=B(e,t);if(d.ASKR_FASTPATH_DEBUG==="1")try{K("__LAST_FASTPATH_STATS",i),K("__LAST_FASTPATH_COMMIT_COUNT",1),U("bulkKeyedPositionalForced")}catch{}const r=M(e);return a.set(e,r),!0}catch(t){return(d.ASKR_FASTPATH_DEBUG==="1"||d.ASKR_FASTPATH_DEBUG==="true")&&b.warn("[Askr][FASTPATH] forced bulk path failed, falling back",t),!1}}function X(e,n){if(P(e,n)){const t=R(e,n);}else O(e,n);a.delete(e)}function N(e,n){const t=n._forState;if(!t)return;const i=(n.props||{}).source,r=D(t,i),s=o=>{o instanceof Element&&(y(o),h(o));let c=o.firstChild;for(;c;){const A=c.nextSibling;s(c),c=A}};let f=e.firstChild;for(;f;){const o=f.nextSibling;s(f),e.removeChild(f),f=o}for(let o=0;o<r.length;o++){const c=r[o],A=t.orderedKeys[o],m=A!=null?t.items.get(A):null;let u=null;if(m&&m._dom){const g=m._dom;(!(g instanceof Element)||!c?.type||typeof c.type!="string"||g.tagName.toLowerCase()===c.type.toLowerCase())&&(u=g)}u||(u=p(c),m&&(m._dom=u??void 0)),u&&(u instanceof Element&&l(c)&&k(u,c,!0),e.appendChild(u))}a.delete(e)}function F(e,n){if(n==null){for(let t=e.firstChild;t;){const i=t.nextSibling;t instanceof Element&&(y(t),h(t)),t=i}e.textContent="",a.delete(e);return}if(!Array.isArray(n)&&l(n)&&n.type===T){N(e,n);return}if(!Array.isArray(n)){for(let i=e.firstChild;i;){const r=i.nextSibling;i instanceof Element&&(y(i),h(i)),i=r}e.textContent="";const t=p(n);t&&e.appendChild(t),a.delete(e);return}if(n.length===1&&l(n[0])&&n[0].type===T){N(e,n[0]);return}if(w(n)){const t=z(e);try{j(e,n,t)}catch{const i=C(e,n,t);a.set(e,i)}}else X(e,n)}function x(e,n){let t=n.children||n.props?.children;if(t&&l(t)&&t.type===T){F(e,t),k(e,n,!1);return}t&&!Array.isArray(t)&&(t=[t]);const i=G(t);i.isSimple&&W(e,i.text)||F(e,t),k(e,n,!1)}function Y(e,n){let t=e.firstElementChild;for(let i=0;i<n.length;i++){const r=n[i],s=t?t.nextElementSibling:null;if(t&&l(r)&&typeof r.type=="string"&&E(t.tagName,r.type)){x(t,r),t=s;continue}const f=p(r);f&&(t?(y(t),h(t),e.replaceChild(f,t)):e.appendChild(f)),t=s}for(;t;){const i=t.nextElementSibling;y(t),h(t),e.removeChild(t),t=i}}function J(e,n){for(const[t,i]of Object.entries(n)){if(t==="children"||t==="key"||i==null||i===!1)continue;if(t==="ref"){Q(e,i);continue}const r=L(t);if(r){const s=v(i,!0),f=V(r);f!==void 0?e.addEventListener(r,s,f):e.addEventListener(r,s),_.has(e)||_.set(e,new Map),_.get(e).set(r,{handler:s,original:i,options:f});continue}t==="class"||t==="className"?e.className=String(i):t==="value"||t==="checked"?e[t]=i:e.setAttribute(t,String(i))}}function Q(e,n){const t=n;if(t){if(typeof t=="function"){t(e);return}try{t.current=e}catch{}}}function Z(e,n){const t=n.children;if(!Array.isArray(t)||!w(t))return!1;const i=document.createElement(n.type);e.appendChild(i),J(i,n.props||{});const r=C(i,t,void 0);return a.set(i,r),!0}function $(e){return l(e)&&typeof e.type=="symbol"&&(e.type===H||String(e.type)==="Symbol(askr.fragment)")}function ee(e){const n=e.props?.children||e.children||[];return Array.isArray(n)?n:[n]}function de(e,n,t){if(n&&!(typeof document>"u"))if(t&&S.has(t)){const i=S.get(t);let r=i.start.nextSibling;for(;r&&r!==i.end;){const f=r.nextSibling;r.remove(),r=f}const s=p(e);s&&n.insertBefore(s,i.end)}else if(t){const i=document.createComment("component-start"),r=document.createComment("component-end");n.appendChild(i),n.appendChild(r),S.set(t,{start:i,end:r});const s=p(e);s&&n.insertBefore(s,r)}else{let i=e;if($(i)){const o=ee(i);if(o.length===1&&l(o[0])&&typeof o[0].type=="string")i=o[0];else{Y(n,o);return}}const s=n.__ASKR_INSTANCE;if(s&&s.target===n)if(l(i)&&typeof i.type=="string"&&E(n.tagName,i.type)){x(n,i);return}else{const o=p(i);if(o&&n.parentNode){o instanceof Element&&(o.__ASKR_INSTANCE=s,s.target=o),y(n),n.parentNode.replaceChild(o,n);return}}const f=n.children[0];if(f&&l(i)&&typeof i.type=="string"&&E(f.tagName,i.type))x(f,i);else{if(n.textContent="",l(i)&&typeof i.type=="string"&&Z(n,i))return;const o=p(i);o&&n.appendChild(o)}}}function ye(e){S.delete(e)}export{pe as IS_DOM_AVAILABLE,ye as clearDOMRange,de as evaluate};
@@ -1 +1 @@
1
- {"version":3,"file":"fastpath.d.ts","sourceRoot":"","sources":["../../src/renderer/fastpath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AASrC,eAAO,MAAM,gBAAgB,SAAkC,CAAC;AAMhE,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC,EAC1D,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EACzC,aAAa,CAAC,EAAE,KAAK,EAAE,GACtB,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAkMtC"}
1
+ {"version":3,"file":"fastpath.d.ts","sourceRoot":"","sources":["../../src/renderer/fastpath.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AASrC,eAAO,MAAM,gBAAgB,SAAkC,CAAC;AAMhE,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,KAAK,CAAC;IAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,CAAC,EAC1D,SAAS,CAAC,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EACzC,aAAa,CAAC,EAAE,KAAK,EAAE,GACtB,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAqMtC"}
@@ -1 +1 @@
1
- import{createDOMNode as S}from"./dom.js";import{_reconcilerRecordedParents as C}from"./keyed.js";import{logger as v}from"../dev/logger.js";import{removeAllListeners as P,cleanupInstanceIfPresent as D}from"./cleanup.js";import{incDevCounter as E,setDevValue as d}from"../runtime/dev-namespace.js";import{isSchedulerExecuting as F}from"../runtime/scheduler.js";import{isBulkCommitActive as k,markFastPathApplied as w}from"../runtime/fastlane.js";var y={};const x=typeof document<"u";function I(l,a,g,f){if(typeof document>"u")return null;const A=a.length;if(A===0&&(!f||f.length===0))return null;F()||v.warn("[Askr][FASTPATH][DEV] Fast-path reconciliation invoked outside scheduler execution");let c,m;if(A<=20)try{const e=l.children;c=new Array(e.length);for(let n=0;n<e.length;n++)c[n]=e[n]}catch(e){c=void 0}else{m=new Map;try{for(let e=l.firstElementChild;e;e=e.nextElementSibling){const n=e.getAttribute("data-key");if(n!==null){m.set(n,e);const r=Number(n);Number.isNaN(r)||m.set(r,e)}}}catch(e){m=void 0}}const s=[];let T=0,h=0,_=0;for(let e=0;e<a.length;e++){const{key:n,vnode:r}=a[e];T++;let o;if(A<=20&&c){const t=String(n);for(let i=0;i<c.length;i++){const u=c[i],p=u.getAttribute("data-key");if(p!==null&&(p===t||Number(p)===n)){o=u;break}}o||(o=g?.get(n))}else o=m?.get(n)??g?.get(n);if(o)s.push(o),_++;else{const t=S(r);t&&(s.push(t),h++)}}if(f&&f.length)for(const e of f){const n=S(e);n&&(s.push(n),h++)}try{const e=Date.now(),n=document.createDocumentFragment();let r=0;for(let t=0;t<s.length;t++)n.appendChild(s[t]),r++;try{for(let t=l.firstChild;t;){const i=t.nextSibling;t instanceof Element&&P(t),D(t),t=i}}catch(t){}try{E("__DOM_REPLACE_COUNT"),d("__LAST_DOM_REPLACE_STACK_FASTPATH",new Error().stack)}catch(t){}l.replaceChildren(n);try{d("__LAST_FASTPATH_COMMIT_COUNT",1)}catch(t){}try{k()&&w(l)}catch(t){}const o=new Map;for(let t=0;t<a.length;t++){const i=a[t].key,u=s[t];u instanceof Element&&o.set(i,u)}try{const t={n:A,moves:0,lisLen:0,t_lookup:0,t_fragment:Date.now()-e,t_commit:0,t_bookkeeping:0,fragmentAppendCount:r,mapLookups:T,createdNodes:h,reusedCount:_};typeof globalThis<"u"&&(d("__LAST_FASTPATH_STATS",t),d("__LAST_FASTPATH_REUSED",_>0),E("fastpathHistoryPush")),(y.ASKR_FASTPATH_DEBUG==="1"||y.ASKR_FASTPATH_DEBUG==="true")&&v.warn("[Askr][FASTPATH]",JSON.stringify({n:A,createdNodes:h,reusedCount:_}))}catch(t){}try{C.add(l)}catch(t){}return o}catch(e){return null}}export{x as IS_DOM_AVAILABLE,I as applyRendererFastPath};
1
+ import{createDOMNode as S}from"./dom.js";import{_reconcilerRecordedParents as P}from"./keyed.js";import{logger as v}from"../dev/logger.js";import{removeAllListeners as y,cleanupInstanceIfPresent as D}from"./cleanup.js";import{incDevCounter as E,setDevValue as p}from"../runtime/dev-namespace.js";import{isSchedulerExecuting as F}from"../runtime/scheduler.js";import{isBulkCommitActive as k,markFastPathApplied as w}from"../runtime/fastlane.js";var C={};const x=typeof document<"u";function I(l,a,h,f){if(typeof document>"u")return null;const A=a.length;if(A===0&&(!f||f.length===0))return null;F()||v.warn("[Askr][FASTPATH][DEV] Fast-path reconciliation invoked outside scheduler execution");let c,m;if(A<=20)try{const e=l.children;c=new Array(e.length);for(let n=0;n<e.length;n++)c[n]=e[n]}catch(e){c=void 0}else if(!h||h.size===0){m=new Map;try{for(let e=l.firstElementChild;e;e=e.nextElementSibling){const n=e.getAttribute("data-key");if(n!==null){m.set(n,e);const o=Number(n);Number.isNaN(o)||m.set(o,e)}}}catch(e){m=void 0}}const s=[];let T=0,_=0,d=0;for(let e=0;e<a.length;e++){const{key:n,vnode:o}=a[e];T++;let r;if(A<=20&&c){const t=String(n);for(let i=0;i<c.length;i++){const u=c[i],g=u.getAttribute("data-key");if(g!==null&&(g===t||Number(g)===n)){r=u;break}}r||(r=h?.get(n))}else r=m?.get(n)??h?.get(n);if(r)s.push(r),d++;else{const t=S(o);t&&(s.push(t),_++)}}if(f&&f.length)for(const e of f){const n=S(e);n&&(s.push(n),_++)}try{const e=Date.now(),n=document.createDocumentFragment();let o=0;for(let t=0;t<s.length;t++)n.appendChild(s[t]),o++;try{for(let t=l.firstChild;t;){const i=t.nextSibling;t instanceof Element&&y(t),D(t),t=i}}catch(t){}try{E("__DOM_REPLACE_COUNT"),p("__LAST_DOM_REPLACE_STACK_FASTPATH",new Error().stack)}catch(t){}l.replaceChildren(n);try{p("__LAST_FASTPATH_COMMIT_COUNT",1)}catch(t){}try{k()&&w(l)}catch(t){}const r=new Map;for(let t=0;t<a.length;t++){const i=a[t].key,u=s[t];u instanceof Element&&r.set(i,u)}try{const t={n:A,moves:0,lisLen:0,t_lookup:0,t_fragment:Date.now()-e,t_commit:0,t_bookkeeping:0,fragmentAppendCount:o,mapLookups:T,createdNodes:_,reusedCount:d};typeof globalThis<"u"&&(p("__LAST_FASTPATH_STATS",t),p("__LAST_FASTPATH_REUSED",d>0),E("fastpathHistoryPush")),(C.ASKR_FASTPATH_DEBUG==="1"||C.ASKR_FASTPATH_DEBUG==="true")&&v.warn("[Askr][FASTPATH]",JSON.stringify({n:A,createdNodes:_,reusedCount:d}))}catch(t){}try{P.add(l)}catch(t){}return r}catch(e){return null}}export{x as IS_DOM_AVAILABLE,I as applyRendererFastPath};
@@ -1 +1 @@
1
- {"version":3,"file":"keyed.d.ts","sourceRoot":"","sources":["../../src/renderer/keyed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAarC,eAAO,MAAM,aAAa,iDAGvB,CAAC;AAEJ;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,OAAO,6CAE9C;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAwB9D;AAKD,eAAO,MAAM,0BAA0B,kBAAyB,CAAC;AAiFjE;;GAEG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,KAAK,EAAE,EACpB,SAAS,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;;;;;;EAuDrD"}
1
+ {"version":3,"file":"keyed.d.ts","sourceRoot":"","sources":["../../src/renderer/keyed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAYrC,eAAO,MAAM,aAAa,iDAGvB,CAAC;AAEJ;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,EAAE,EAAE,OAAO,6CAE9C;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI,CAwB9D;AAKD,eAAO,MAAM,0BAA0B,kBAAyB,CAAC;AAsEjE;;GAEG;AACH,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,OAAO,EACf,WAAW,EAAE,KAAK,EAAE,EACpB,SAAS,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS;;;;;;EAwDrD"}
@@ -1 +1 @@
1
- import{buildKeyMapFromChildren as E,extractKey as O,hasNonTrivialProps as k,isIgnoredForPropChanges as _,hasPropChanged as P}from"./utils.js";const h=new WeakMap;function L(o){return h.get(o)}function C(o){try{if(h.has(o))return;let e=E(o);if(e.size===0){e=new Map;const n=Array.from(o.children);for(const t of n){const r=(t.textContent||"").trim();if(r){e.set(r,t);const s=Number(r);Number.isNaN(s)||e.set(s,t)}}}e.size>0&&h.set(o,e)}catch{}}const R=new WeakSet;function S(o){const e=[];for(const n of o){const t=O(n);t!==void 0&&e.push({key:t,vnode:n})}return e}function v(o){const e=[];for(const n of o){if(n===-1)continue;let t=0,r=e.length;for(;t<r;){const s=t+r>>1;e[s]<n?t=s+1:r=s}t===e.length?e.push(n):e[t]=n}return e.length}function F(o){for(const{vnode:e}of o){if(typeof e!="object"||e===null)continue;const n=e;if(n.props&&k(n.props))return!0}return!1}function T(o,e){for(const{key:n,vnode:t}of o){const r=e?.get(n);if(!r||typeof t!="object"||t===null)continue;const f=t.props||{};for(const i of Object.keys(f))if(!_(i)&&P(r,i,f[i]))return!0}return!1}function V(o,e,n){const t=S(e),r=t.length,s=t.map(c=>c.key),f=n?Array.from(n.keys()):[];let i=0;for(let c=0;c<s.length;c++){const l=s[c];(c>=f.length||f[c]!==l||!n?.has(l))&&i++}const g=r>=128&&f.length>0&&i>Math.max(64,Math.floor(r*.1));let u=!1,a=0;if(r>=128){const c=Array.from(o.children),l=t.map(({key:y})=>{const p=n?.get(y);return p?.parentElement===o?c.indexOf(p):-1});a=v(l),u=a<Math.floor(r*.5)}const m=F(t),d=T(t,n);return{useFastPath:(g||u)&&!d&&!m,totalKeyed:r,moveCount:i,lisLen:a,hasPropChanges:d}}export{R as _reconcilerRecordedParents,L as getKeyMapForElement,V as isKeyedReorderFastPathEligible,h as keyedElements,C as populateKeyMapForElement};
1
+ import{buildKeyMapFromChildren as E,extractKey as O,isIgnoredForPropChanges as _,hasPropChanged as S}from"./utils.js";const h=new WeakMap;function R(r){return h.get(r)}function b(r){try{if(h.has(r))return;let t=E(r);if(t.size===0){t=new Map;const n=Array.from(r.children);for(const e of n){const o=(e.textContent||"").trim();if(o){t.set(o,e);const s=Number(o);Number.isNaN(s)||t.set(s,e)}}}t.size>0&&h.set(r,t)}catch{}}const C=new WeakSet,p=64;function k(r){const t=[];for(const n of r){const e=O(n);e!==void 0&&t.push({key:e,vnode:n})}return t}function F(r){const t=[];for(const n of r){if(n===-1)continue;let e=0,o=t.length;for(;e<o;){const s=e+o>>1;t[s]<n?e=s+1:o=s}e===t.length?t.push(n):t[e]=n}return t.length}function L(r,t){for(const{key:n,vnode:e}of r){const o=t?.get(n);if(!o||typeof e!="object"||e===null)continue;const l=e.props||{};for(const i of Object.keys(l))if(!_(i)&&S(o,i,l[i]))return!0}return!1}function P(r,t,n){const e=k(t),o=e.length,s=e.map(c=>c.key),l=n?Array.from(n.keys()):[];let i=0;for(let c=0;c<s.length;c++){const f=s[c];(c>=l.length||l[c]!==f||!n?.has(f))&&i++}const m=o>=p&&l.length>0&&i>Math.max(64,Math.floor(o*.1));let u=!1,a=0;if(o>=p){const c=Array.from(r.children),f=e.map(({key:y})=>{const g=n?.get(y);return g?.parentElement===r?c.indexOf(g):-1});a=F(f),u=a<Math.floor(o*.5)}const d=L(e,n);return{useFastPath:(m||u)&&!d,totalKeyed:o,moveCount:i,lisLen:a,hasPropChanges:d}}export{C as _reconcilerRecordedParents,R as getKeyMapForElement,P as isKeyedReorderFastPathEligible,h as keyedElements,b as populateKeyMapForElement};
@@ -1 +1 @@
1
- import{performBulkPositionalKeyedTextUpdate as d,updateElementFromVnode as a,createDOMNode as y}from"./dom.js";import{isKeyedReorderFastPathEligible as p,keyedElements as s}from"./keyed.js";import{removeAllListeners as b,cleanupInstanceIfPresent as N}from"./cleanup.js";import{isBulkCommitActive as C}from"../runtime/fastlane.js";import{applyRendererFastPath as k}from"./fastpath.js";import{extractKey as h,recordFastPathStats as A,checkPropChanges as P,recordDOMReplace as S}from"./utils.js";const X=typeof document<"u";function l(e,r){if(e===r)return!0;if(e.length!==r.length)return!1;for(let t=0;t<e.length;t++){const n=e.charCodeAt(t),o=r.charCodeAt(t);if(n===o)continue;const i=n>=65&&n<=90?n+32:n,c=o>=65&&o<=90?o+32:o;if(i!==c)return!1}return!0}function Y(e,r,t){const{keyedVnodes:n,unkeyedVnodes:o}=E(r),i=t||R(e),c=F(e,r,n,o,i);return c||B(e,r,n,i)}function R(e){const r=new Map;try{for(let t=e.firstElementChild;t;t=t.nextElementSibling){const n=t.getAttribute("data-key");if(n!==null){r.set(n,t);const o=Number(n);Number.isNaN(o)||r.set(o,t)}}}catch{}return r}function E(e){const r=[],t=[];for(let n=0;n<e.length;n++){const o=e[n],i=h(o);i!==void 0?r.push({key:i,vnode:o}):t.push(o)}return{keyedVnodes:r,unkeyedVnodes:t}}function F(e,r,t,n,o){try{const i=v(e,r,t,n,o);if(i)return i;const c=x(e,t);if(c)return c}catch{}return null}function v(e,r,t,n,o){if(p(e,r,o).useFastPath&&t.length>=128||C())try{const c=k(e,t,o,n);if(c)return s.set(e,c),c}catch{}return null}function x(e,r){const t=r.length;if(t<10||e.children.length!==t)return null;const n=K(e,r),o=n/t;if(r.length>0){if(n!==t&&o>=.1)return null}else if(o<.9)return null;if(M(e,r))return null;try{const i=d(e,r);return A(i,"bulkKeyedPositionalHits"),j(e),s.get(e)}catch{return null}}function K(e,r){let t=0;try{for(let n=0;n<r.length;n++){const o=r[n].vnode,i=r[n].key;if(!o||typeof o!="object"||typeof o.type!="string")continue;const c=e.children[n];if(c&&l(c.tagName,o.type)){const u=c.getAttribute("data-key");(u===String(i)||u!==null&&!Number.isNaN(Number(u))&&Number(u)===i)&&t++}}}catch{}return t}function M(e,r){try{for(let t=0;t<r.length;t++){const n=r[t].vnode,o=e.children[t];if(!(!o||!n||typeof n!="object")&&P(o,n.props||{}))return!0}}catch{return!0}return!1}function j(e){try{const r=new Map;for(let t=e.firstElementChild;t;t=t.nextElementSibling){const n=t.getAttribute("data-key");if(n!==null){r.set(n,t);const o=Number(n);Number.isNaN(o)||r.set(o,t)}}s.set(e,r)}catch{}}function B(e,r,t,n){const o=new Map,i=[],c=new WeakSet,u=D(e,n,c);for(let f=0;f<r.length;f++){const g=r[f],m=U(g,f,e,u,c,o);m&&i.push(m)}return typeof document>"u"||(W(e,i),s.delete(e)),o}function D(e,r,t){return n=>{if(!r)return;const o=r.get(n);if(o&&!t.has(o))return t.add(o),o;const i=String(n),c=r.get(i);if(c&&!t.has(c))return t.add(c),c;const u=Number(i);if(!Number.isNaN(u)){const f=r.get(u);if(f&&!t.has(f))return t.add(f),f}return I(e,n,i,t)}}function I(e,r,t,n){try{for(let o=e.firstElementChild;o;o=o.nextElementSibling){if(n.has(o))continue;const i=o.getAttribute("data-key");if(i===t)return n.add(o),o;if(i!==null){const c=Number(i);if(!Number.isNaN(c)&&c===r)return n.add(o),o}}}catch{}}function U(e,r,t,n,o,i){const c=h(e);return c!==void 0?L(e,c,t,n,i):T(e,r,t,o)}function L(e,r,t,n,o){const i=n(r);if(i&&i.parentElement===t)try{const u=e;if(u&&typeof u=="object"&&typeof u.type=="string"&&l(i.tagName,u.type))return a(i,e),o.set(r,i),i}catch{}const c=y(e);return c?(c instanceof Element&&o.set(r,c),c):null}function T(e,r,t,n){try{const i=t.childNodes[r];if((typeof e=="string"||typeof e=="number")&&i&&i.nodeType===3)return i.data=String(e),n.add(i),i;if(i instanceof Element&&_(i,e))return a(i,e),n.add(i),i;const c=q(t,n);if(c){const u=H(c,e,n);if(u)return u}}catch{}return y(e)}function _(e,r){if(!e||typeof r!="object"||r===null||!("type"in r))return!1;const t=r,n=e.getAttribute("data-key");return n==null&&typeof t.type=="string"&&l(e.tagName,t.type)}function q(e,r){for(let t=e.firstElementChild;t;t=t.nextElementSibling)if(!r.has(t)&&t.getAttribute("data-key")===null)return t}function H(e,r,t){if(typeof r=="string"||typeof r=="number")return e.textContent=String(r),t.add(e),e;if(typeof r=="object"&&r!==null&&"type"in r){const n=r;if(typeof n.type=="string"&&l(e.tagName,n.type))return a(e,r),t.add(e),e}return null}function W(e,r){const t=document.createDocumentFragment();for(let n=0;n<r.length;n++)t.appendChild(r[n]);try{for(let n=e.firstChild;n;){const o=n.nextSibling;n instanceof Element&&b(n),N(n),n=o}}catch{}S("reconcile"),e.replaceChildren(t)}export{X as IS_DOM_AVAILABLE,Y as reconcileKeyedChildren};
1
+ import{performBulkPositionalKeyedTextUpdate as d,updateElementFromVnode as a,createDOMNode as y}from"./dom.js";import{isKeyedReorderFastPathEligible as p,keyedElements as s}from"./keyed.js";import{removeAllListeners as b,cleanupInstanceIfPresent as N}from"./cleanup.js";import{isBulkCommitActive as C}from"../runtime/fastlane.js";import{applyRendererFastPath as k}from"./fastpath.js";import{extractKey as h,recordFastPathStats as A,checkPropChanges as P,recordDOMReplace as S}from"./utils.js";const X=typeof document<"u";function l(e,r){if(e===r)return!0;if(e.length!==r.length)return!1;for(let t=0;t<e.length;t++){const n=e.charCodeAt(t),o=r.charCodeAt(t);if(n===o)continue;const i=n>=65&&n<=90?n+32:n,c=o>=65&&o<=90?o+32:o;if(i!==c)return!1}return!0}function Y(e,r,t){const{keyedVnodes:n,unkeyedVnodes:o}=E(r),i=t||R(e),c=F(e,r,n,o,i);return c||B(e,r,n,i)}function R(e){const r=new Map;try{for(let t=e.firstElementChild;t;t=t.nextElementSibling){const n=t.getAttribute("data-key");if(n!==null){r.set(n,t);const o=Number(n);Number.isNaN(o)||r.set(o,t)}}}catch{}return r}function E(e){const r=[],t=[];for(let n=0;n<e.length;n++){const o=e[n],i=h(o);i!==void 0?r.push({key:i,vnode:o}):t.push(o)}return{keyedVnodes:r,unkeyedVnodes:t}}function F(e,r,t,n,o){try{const i=v(e,r,t,n,o);if(i)return i;const c=x(e,t);if(c)return c}catch{}return null}function v(e,r,t,n,o){if(p(e,r,o).useFastPath&&t.length>=64||C())try{const c=k(e,t,o,n);if(c)return s.set(e,c),c}catch{}return null}function x(e,r){const t=r.length;if(t<10||e.children.length!==t)return null;const n=K(e,r),o=n/t;if(r.length>0){if(n!==t&&o>=.1)return null}else if(o<.9)return null;if(M(e,r))return null;try{const i=d(e,r);return A(i,"bulkKeyedPositionalHits"),j(e),s.get(e)}catch{return null}}function K(e,r){let t=0;try{for(let n=0;n<r.length;n++){const o=r[n].vnode,i=r[n].key;if(!o||typeof o!="object"||typeof o.type!="string")continue;const c=e.children[n];if(c&&l(c.tagName,o.type)){const u=c.getAttribute("data-key");(u===String(i)||u!==null&&!Number.isNaN(Number(u))&&Number(u)===i)&&t++}}}catch{}return t}function M(e,r){try{for(let t=0;t<r.length;t++){const n=r[t].vnode,o=e.children[t];if(!(!o||!n||typeof n!="object")&&P(o,n.props||{}))return!0}}catch{return!0}return!1}function j(e){try{const r=new Map;for(let t=e.firstElementChild;t;t=t.nextElementSibling){const n=t.getAttribute("data-key");if(n!==null){r.set(n,t);const o=Number(n);Number.isNaN(o)||r.set(o,t)}}s.set(e,r)}catch{}}function B(e,r,t,n){const o=new Map,i=[],c=new WeakSet,u=D(e,n,c);for(let f=0;f<r.length;f++){const g=r[f],m=U(g,f,e,u,c,o);m&&i.push(m)}return typeof document>"u"||(W(e,i),s.delete(e)),o}function D(e,r,t){return n=>{if(!r)return;const o=r.get(n);if(o&&!t.has(o))return t.add(o),o;const i=String(n),c=r.get(i);if(c&&!t.has(c))return t.add(c),c;const u=Number(i);if(!Number.isNaN(u)){const f=r.get(u);if(f&&!t.has(f))return t.add(f),f}return I(e,n,i,t)}}function I(e,r,t,n){try{for(let o=e.firstElementChild;o;o=o.nextElementSibling){if(n.has(o))continue;const i=o.getAttribute("data-key");if(i===t)return n.add(o),o;if(i!==null){const c=Number(i);if(!Number.isNaN(c)&&c===r)return n.add(o),o}}}catch{}}function U(e,r,t,n,o,i){const c=h(e);return c!==void 0?L(e,c,t,n,i):T(e,r,t,o)}function L(e,r,t,n,o){const i=n(r);if(i&&i.parentElement===t)try{const u=e;if(u&&typeof u=="object"&&typeof u.type=="string"&&l(i.tagName,u.type))return a(i,e),o.set(r,i),i}catch{}const c=y(e);return c?(c instanceof Element&&o.set(r,c),c):null}function T(e,r,t,n){try{const i=t.childNodes[r];if((typeof e=="string"||typeof e=="number")&&i&&i.nodeType===3)return i.data=String(e),n.add(i),i;if(i instanceof Element&&_(i,e))return a(i,e),n.add(i),i;const c=q(t,n);if(c){const u=H(c,e,n);if(u)return u}}catch{}return y(e)}function _(e,r){if(!e||typeof r!="object"||r===null||!("type"in r))return!1;const t=r,n=e.getAttribute("data-key");return n==null&&typeof t.type=="string"&&l(e.tagName,t.type)}function q(e,r){for(let t=e.firstElementChild;t;t=t.nextElementSibling)if(!r.has(t)&&t.getAttribute("data-key")===null)return t}function H(e,r,t){if(typeof r=="string"||typeof r=="number")return e.textContent=String(r),t.add(e),e;if(typeof r=="object"&&r!==null&&"type"in r){const n=r;if(typeof n.type=="string"&&l(e.tagName,n.type))return a(e,r),t.add(e),e}return null}function W(e,r){const t=document.createDocumentFragment();for(let n=0;n<r.length;n++)t.appendChild(r[n]);try{for(let n=e.firstChild;n;){const o=n.nextSibling;n instanceof Element&&b(n),N(n),n=o}}catch{}S("reconcile"),e.replaceChildren(t)}export{X as IS_DOM_AVAILABLE,Y as reconcileKeyedChildren};
@@ -1 +1 @@
1
- {"version":3,"file":"for.d.ts","sourceRoot":"","sources":["../../src/runtime/for.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EACL,KAAK,iBAAiB,EAOvB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAc,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAazD,UAAU,YAAY;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAmHD,iBAAS,eAAe,IAAI,YAAY,CAEvC;AAED,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC5B,IAAI,EAAE,CAAC,CAAC;IACR,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,IAAI,CAAC,EAAE,IAAI,CAAC;CACb;AAED,MAAM,WAAW,QAAQ,CAAC,CAAC;IACzB,WAAW,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IAC/B,KAAK,EAAE,GAAG,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IACvD,WAAW,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC,CAAC;IAC3C,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACzD,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,MAAM,KAAK,KAAK,CAAC;IAClD,cAAc,EAAE,iBAAiB,GAAG,IAAI,CAAC;IACzC,OAAO,EAAE,OAAO,CAAC;CAClB;AAoCD,wBAAgB,cAAc,CAAC,CAAC,EAC9B,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAChC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,EACjD,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,MAAM,KAAK,KAAK,GAChD,QAAQ,CAAC,CAAC,CAAC,CAab;AAID,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAC3B,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,GACpB,eAAe,CAAC,CAAC,CAAC,CAkJpB;AAED,wBAAgB,iBAAiB,CAAC,CAAC,EACjC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,QAAQ,EAAE,CAAC,EAAE,GACZ,KAAK,EAAE,CAoVT;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,GAC/B,KAAK,EAAE,CAST"}
1
+ {"version":3,"file":"for.d.ts","sourceRoot":"","sources":["../../src/runtime/for.ts"],"names":[],"mappings":"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"}
@@ -1 +1 @@
1
- import{getCurrentInstance as R,createComponentInstance as K,setCurrentComponentInstance as y,getCurrentStateIndex as H,finalizeReadSubscriptions as E,setStateIndex as L}from"./component.js";import{ELEMENT_TYPE as T}from"../common/jsx.js";const v=globalThis,s={itemsCreated:0,itemsReused:0,itemsRemoved:0,itemsMoved:0,rowFactoryInvocations:0,keyLookups:0,keyHits:0,keyMisses:0,domInserts:0,domRemoves:0,domMoves:0,domAttrSets:0,domTextSets:0,reconcilePhaseMs:0,domCommitPhaseMs:0,fastLaneName:null};function P(){v.__ASKR_BENCH__&&(s.itemsCreated=0,s.itemsReused=0,s.itemsRemoved=0,s.itemsMoved=0,s.rowFactoryInvocations=0,s.keyLookups=0,s.keyHits=0,s.keyMisses=0,s.domInserts=0,s.domRemoves=0,s.domMoves=0,s.domAttrSets=0,s.domTextSets=0,s.reconcilePhaseMs=0,s.domCommitPhaseMs=0,s.fastLaneName=null)}function l(r){if(v.__ASKR_BENCH__)switch(r){case"itemCreated":s.itemsCreated++;break;case"itemReused":s.itemsReused++;break;case"itemRemoved":s.itemsRemoved++;break;case"itemMoved":s.itemsMoved++;break;case"rowFactory":s.rowFactoryInvocations++;break;case"keyLookup":s.keyLookups++;break;case"keyHit":s.keyHits++;break;case"keyMiss":s.keyMisses++;break;case"domInsert":s.domInserts++;break;case"domRemove":s.domRemoves++;break;case"domMove":s.domMoves++;break;case"domAttrSet":s.domAttrSets++;break;case"domTextSet":s.domTextSets++;break}}function F(r){v.__ASKR_BENCH__&&(s.fastLaneName=r)}function M(r,i){v.__ASKR_BENCH__&&(r==="reconcile"?s.reconcilePhaseMs=i:s.domCommitPhaseMs=i)}function U(){return{...s}}function C(r){if(r&&typeof r=="object"&&"$$typeof"in r&&r.$$typeof===T){const i=r;if(typeof i.type=="function"){const u=i.type,m=u(i.props||{});return C(m)}return i}return r}function $(r,i,u){const m=typeof r=="function"?null:r,f=R();return{sourceState:m,items:new Map,orderedKeys:[],byFn:i,renderFn:u,parentInstance:f,mounted:!1}}let N=1;function w(r,i,u,m){l("itemCreated");let f=u;const p=Object.assign(()=>f,{set(t){const e=typeof t=="function"?t(f):t;e!==f&&(f=e)}});p[Symbol.iterator]=function*(){yield p,yield p.set};const _=()=>null,a=K(`for-item-${r}`,_,{},null);m.parentInstance&&(a.ownerFrame=m.parentInstance.ownerFrame);const b=R();y(a);const I=H();a._currentRenderToken=N++,a._pendingReadStates=new Set,l("rowFactory");const k=C(m.renderFn(i,()=>p()));if(k&&typeof k=="object"&&"type"in k){const t=k;t.key=r,typeof t.type=="string"&&(t.props||(t.props={}),t.props["data-key"]===void 0&&(t.props["data-key"]=String(r)))}E(a),y(b);const d={key:r,item:i,indexSignal:p,componentInstance:a,vnode:k,_startStateIndex:I};return a._pendingFlushTask=()=>{const t=R();y(a),a.stateIndexCheck=-1;const e=a.stateValues;for(let c=0;c<e.length;c++){const n=e[c];n&&(n._hasBeenRead=!1)}L(I),a._currentRenderToken=N++,a._pendingReadStates=new Set;try{const c=C(m.renderFn(i,()=>p()));d.vnode=c,E(a)}finally{y(t)}const o=m.parentInstance;o&&o._enqueueRun?.()},d}function A(r,i){v.__ASKR_BENCH__&&P();const u=v.__ASKR_BENCH__?performance.now():0,{items:m,orderedKeys:f,byFn:p}=r,_=f.length,a=i.length;if(_<=a){let d=!0;for(let t=0;t<_;t++)if(p(i[t],t)!==f[t]){d=!1;break}if(d){F("APPEND");const t=[];for(let e=0;e<_;e++){const o=i[e],c=f[e],n=m.get(c);l("itemReused");const g=n.item!==o,h=n.indexSignal()!==e;if(g){n.item=o;const S=R();y(n.componentInstance),l("rowFactory"),n.vnode=C(r.renderFn(o,()=>n.indexSignal()));try{n.vnode&&typeof n.vnode=="object"&&"type"in n.vnode&&(n.vnode.key=c)}catch(x){}y(S)}h&&n.indexSignal.set(e),t.push(n.vnode)}for(let e=_;e<a;e++){const o=i[e],c=p(o,e),n=w(c,o,e,r);m.set(c,n),t.push(n.vnode),f[e]=c}return v.__ASKR_BENCH__&&M("reconcile",performance.now()-u),t}}if(a<=_){let d=!0;for(let t=0;t<a;t++)if(p(i[t],t)!==f[t]){d=!1;break}if(d){F("TRUNCATE");const t=[];for(let e=0;e<a;e++){const o=i[e],c=f[e],n=m.get(c);l("itemReused");const g=n.item!==o,h=n.indexSignal()!==e;if(g){n.item=o;const S=R();y(n.componentInstance),l("rowFactory"),n.vnode=C(r.renderFn(o,()=>n.indexSignal()));try{n.vnode&&typeof n.vnode=="object"&&"type"in n.vnode&&(n.vnode.key=c)}catch(x){}y(S)}h&&n.indexSignal.set(e),t.push(n.vnode)}for(let e=a;e<_;e++){const o=f[e],c=m.get(o);if(c){l("itemRemoved");const n=c.componentInstance;n.abortController.abort();for(const g of n.cleanupFns)try{g()}catch{}m.delete(o)}}return f.length=a,r.orderedKeys=f,v.__ASKR_BENCH__&&M("reconcile",performance.now()-u),t}}if(_===a){let d=!0;for(let t=0;t<_;t++)if(p(i[t],t)!==f[t]){d=!1;break}if(d){F("NO_REORDER");const t=[];for(let e=0;e<_;e++){const o=i[e],c=f[e],n=m.get(c);l("itemReused");const g=n.item!==o,h=n.indexSignal()!==e;if(g){n.item=o;const S=R();y(n.componentInstance),l("rowFactory");const x=C(r.renderFn(o,()=>n.indexSignal()));n.vnode=x;try{n.vnode&&typeof n.vnode=="object"&&"type"in n.vnode&&(n.vnode.key=c)}catch(B){}y(S)}h&&n.indexSignal.set(e),t.push(n.vnode)}return v.__ASKR_BENCH__&&M("reconcile",performance.now()-u),t}}F("FULL_KEYED");const b=new Set(f),I=[],k=[];for(let d=0;d<i.length;d++){const t=i[d],e=p(t,d);l("keyLookup"),b.delete(e),I.push(e);const o=m.get(e);if(l(o?"keyHit":"keyMiss"),o){l("itemReused");const c=o.item!==t,n=o.indexSignal()!==d;if(c){o.item=t;const g=R();y(o.componentInstance),l("rowFactory"),o.vnode=C(r.renderFn(t,()=>o.indexSignal()));try{o.vnode&&typeof o.vnode=="object"&&"type"in o.vnode&&(o.vnode.key=e)}catch(h){}y(g)}n&&o.indexSignal.set(d),k.push(o.vnode)}else{const c=w(e,t,d,r);m.set(e,c),k.push(c.vnode)}}for(const d of b){const t=m.get(d);if(t){l("itemRemoved");const e=t.componentInstance;e.abortController.abort();for(const o of e.cleanupFns)try{o()}catch{}m.delete(d)}}return r.orderedKeys=I,v.__ASKR_BENCH__&&M("reconcile",performance.now()-u),k}function O(r,i){const u=i();if(!Array.isArray(u))throw new Error("For source must evaluate to an array");return A(r,u)}export{$ as createForState,w as createItemInstance,O as evaluateForState,U as getBenchMetrics,A as reconcileForItems};
1
+ import{getCurrentInstance as R,createComponentInstance as T,setCurrentComponentInstance as y,getCurrentStateIndex as P,finalizeReadSubscriptions as M,setStateIndex as A,cleanupComponent as N}from"./component.js";import{ELEMENT_TYPE as j}from"../common/jsx.js";import{removeAllListeners as w,cleanupInstanceIfPresent as B}from"../renderer/cleanup.js";const v=globalThis,s={itemsCreated:0,itemsReused:0,itemsRemoved:0,itemsMoved:0,rowFactoryInvocations:0,keyLookups:0,keyHits:0,keyMisses:0,domInserts:0,domRemoves:0,domMoves:0,domAttrSets:0,domTextSets:0,reconcilePhaseMs:0,domCommitPhaseMs:0,fastLaneName:null};function V(){v.__ASKR_BENCH__&&(s.itemsCreated=0,s.itemsReused=0,s.itemsRemoved=0,s.itemsMoved=0,s.rowFactoryInvocations=0,s.keyLookups=0,s.keyHits=0,s.keyMisses=0,s.domInserts=0,s.domRemoves=0,s.domMoves=0,s.domAttrSets=0,s.domTextSets=0,s.reconcilePhaseMs=0,s.domCommitPhaseMs=0,s.fastLaneName=null)}function l(i){if(v.__ASKR_BENCH__)switch(i){case"itemCreated":s.itemsCreated++;break;case"itemReused":s.itemsReused++;break;case"itemRemoved":s.itemsRemoved++;break;case"itemMoved":s.itemsMoved++;break;case"rowFactory":s.rowFactoryInvocations++;break;case"keyLookup":s.keyLookups++;break;case"keyHit":s.keyHits++;break;case"keyMiss":s.keyMisses++;break;case"domInsert":s.domInserts++;break;case"domRemove":s.domRemoves++;break;case"domMove":s.domMoves++;break;case"domAttrSet":s.domAttrSets++;break;case"domTextSet":s.domTextSets++;break}}function F(i){v.__ASKR_BENCH__&&(s.fastLaneName=i)}function E(i,c){v.__ASKR_BENCH__&&(i==="reconcile"?s.reconcilePhaseMs=c:s.domCommitPhaseMs=c)}function Y(){return{...s}}function I(i){if(i&&typeof i=="object"&&"$$typeof"in i&&i.$$typeof===j){const c=i;if(typeof c.type=="function"){const p=c.type,m=p(c.props||{});return I(m)}return c}return i}function q(i,c,p){const m=typeof i=="function"?null:i,f=R();return{sourceState:m,items:new Map,orderedKeys:[],byFn:c,renderFn:p,parentInstance:f,mounted:!1}}let K=1;function H(i,c,p,m){l("itemCreated");let f=p;const u=Object.assign(()=>f,{set(e){const n=typeof e=="function"?e(f):e;n!==f&&(f=n)}});u[Symbol.iterator]=function*(){yield u,yield u.set};const _=()=>null,a=T(`for-item-${i}`,_,{},null);m.parentInstance&&(a.ownerFrame=m.parentInstance.ownerFrame);const b=R();y(a);const C=P();a._currentRenderToken=K++,a._pendingReadStates=new Set,l("rowFactory");const k=I(m.renderFn(c,()=>u()));if(k&&typeof k=="object"&&"type"in k){const e=k;e.key=i,typeof e.type=="string"&&(e.props||(e.props={}),e.props["data-key"]===void 0&&(e.props["data-key"]=String(i)))}M(a),y(b);const d={key:i,item:c,indexSignal:u,componentInstance:a,vnode:k,_startStateIndex:C};return a._pendingFlushTask=()=>{const e=R();y(a),a.stateIndexCheck=-1;const n=a.stateValues;for(let r=0;r<n.length;r++){const t=n[r];t&&(t._hasBeenRead=!1)}A(C),a._currentRenderToken=K++,a._pendingReadStates=new Set;try{const r=I(m.renderFn(c,()=>u()));d.vnode=r,M(a)}finally{y(e)}const o=m.parentInstance;o&&o._enqueueRun?.()},d}function U(i,c){v.__ASKR_BENCH__&&V();const p=v.__ASKR_BENCH__?performance.now():0,{items:m,orderedKeys:f,byFn:u}=i,_=f.length,a=c.length;if(_<=a){let d=!0;for(let e=0;e<_;e++)if(u(c[e],e)!==f[e]){d=!1;break}if(d){F("APPEND");const e=[];for(let n=0;n<_;n++){const o=c[n],r=f[n],t=m.get(r);l("itemReused");const g=t.item!==o,h=t.indexSignal()!==n;if(g){t.item=o;const S=R();y(t.componentInstance),l("rowFactory"),t.vnode=I(i.renderFn(o,()=>t.indexSignal()));try{t.vnode&&typeof t.vnode=="object"&&"type"in t.vnode&&(t.vnode.key=r)}catch(x){}y(S)}h&&t.indexSignal.set(n),e.push(t.vnode)}for(let n=_;n<a;n++){const o=c[n],r=u(o,n),t=H(r,o,n,i);m.set(r,t),e.push(t.vnode),f[n]=r}return v.__ASKR_BENCH__&&E("reconcile",performance.now()-p),e}}if(a<=_){let d=!0;for(let e=0;e<a;e++)if(u(c[e],e)!==f[e]){d=!1;break}if(d){F("TRUNCATE");const e=[];for(let n=0;n<a;n++){const o=c[n],r=f[n],t=m.get(r);l("itemReused");const g=t.item!==o,h=t.indexSignal()!==n;if(g){t.item=o;const S=R();y(t.componentInstance),l("rowFactory"),t.vnode=I(i.renderFn(o,()=>t.indexSignal()));try{t.vnode&&typeof t.vnode=="object"&&"type"in t.vnode&&(t.vnode.key=r)}catch(x){}y(S)}h&&t.indexSignal.set(n),e.push(t.vnode)}for(let n=a;n<_;n++){const o=f[n],r=m.get(o);if(r){l("itemRemoved");const t=r.componentInstance;try{N(t)}catch{}r._dom instanceof Element&&(w(r._dom),B(r._dom)),r.vnode=void 0,r._dom=void 0,m.delete(o)}}return f.length=a,i.orderedKeys=f,v.__ASKR_BENCH__&&E("reconcile",performance.now()-p),e}}if(_===a){let d=!0;for(let e=0;e<_;e++)if(u(c[e],e)!==f[e]){d=!1;break}if(d){F("NO_REORDER");const e=[];for(let n=0;n<_;n++){const o=c[n],r=f[n],t=m.get(r);l("itemReused");const g=t.item!==o,h=t.indexSignal()!==n;if(g){t.item=o;const S=R();y(t.componentInstance),l("rowFactory");const x=I(i.renderFn(o,()=>t.indexSignal()));t.vnode=x;try{t.vnode&&typeof t.vnode=="object"&&"type"in t.vnode&&(t.vnode.key=r)}catch(L){}y(S)}h&&t.indexSignal.set(n),e.push(t.vnode)}return v.__ASKR_BENCH__&&E("reconcile",performance.now()-p),e}}F("FULL_KEYED");const b=new Set(f),C=[],k=[];for(let d=0;d<c.length;d++){const e=c[d],n=u(e,d);l("keyLookup"),b.delete(n),C.push(n);const o=m.get(n);if(l(o?"keyHit":"keyMiss"),o){l("itemReused");const r=o.item!==e,t=o.indexSignal()!==d;if(r){o.item=e;const g=R();y(o.componentInstance),l("rowFactory"),o.vnode=I(i.renderFn(e,()=>o.indexSignal()));try{o.vnode&&typeof o.vnode=="object"&&"type"in o.vnode&&(o.vnode.key=n)}catch(h){}y(g)}t&&o.indexSignal.set(d),k.push(o.vnode)}else{const r=H(n,e,d,i);m.set(n,r),k.push(r.vnode)}}for(const d of b){const e=m.get(d);if(e){l("itemRemoved");const n=e.componentInstance;try{N(n)}catch{}e._dom instanceof Element&&(w(e._dom),B(e._dom)),e.vnode=void 0,e._dom=void 0,m.delete(d)}}return i.orderedKeys=C,v.__ASKR_BENCH__&&E("reconcile",performance.now()-p),k}function z(i,c){const p=c();if(!Array.isArray(p))throw new Error("For source must evaluate to an array");return U(i,p)}export{q as createForState,H as createItemInstance,z as evaluateForState,Y as getBenchMetrics,U as reconcileForItems};
@@ -23,6 +23,7 @@ export declare class Scheduler {
23
23
  private taskCount;
24
24
  enqueue(task: Task): void;
25
25
  flush(): void;
26
+ private finalizeFlush;
26
27
  runWithSyncProgress<T>(fn: () => T): T;
27
28
  waitForFlush(targetVersion?: number, timeoutMs?: number): Promise<void>;
28
29
  getState(): {
@@ -1 +1 @@
1
- {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/runtime/scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;AAkBvB,qBAAa,SAAS;IACpB,OAAO,CAAC,CAAC,CAAc;IACvB,OAAO,CAAC,IAAI,CAAK;IAEjB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,cAAc,CAAK;IAG3B,OAAO,CAAC,YAAY,CAAK;IAGzB,OAAO,CAAC,aAAa,CAAS;IAG9B,OAAO,CAAC,iBAAiB,CAAS;IAGlC,OAAO,CAAC,OAAO,CAKP;IAGR,OAAO,CAAC,SAAS,CAAK;IAEtB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IA4CzB,KAAK,IAAI,IAAI;IAyEb,mBAAmB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAmEtC,YAAY,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,SAAS,SAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAgCrE,QAAQ;;;;;;;;;;IAeR,YAAY,CAAC,CAAC,EAAE,OAAO;IAIvB,WAAW,IAAI,OAAO;IAItB,WAAW,IAAI,OAAO;IAKtB,qBAAqB,IAAI,MAAM;IA0B/B,OAAO,CAAC,cAAc;CAiBvB;AAED,eAAO,MAAM,eAAe,WAAkB,CAAC;AAE/C,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CA0B1E"}
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../../src/runtime/scheduler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;AAkBvB,qBAAa,SAAS;IACpB,OAAO,CAAC,CAAC,CAAc;IACvB,OAAO,CAAC,IAAI,CAAK;IAEjB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,KAAK,CAAK;IAClB,OAAO,CAAC,cAAc,CAAK;IAG3B,OAAO,CAAC,YAAY,CAAK;IAGzB,OAAO,CAAC,aAAa,CAAS;IAG9B,OAAO,CAAC,iBAAiB,CAAS;IAGlC,OAAO,CAAC,OAAO,CAKP;IAGR,OAAO,CAAC,SAAS,CAAK;IAEtB,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;IA4CzB,KAAK,IAAI,IAAI;IAyEb,OAAO,CAAC,aAAa;IAIrB,mBAAmB,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAmEtC,YAAY,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,SAAS,SAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAgCrE,QAAQ;;;;;;;;;;IAeR,YAAY,CAAC,CAAC,EAAE,OAAO;IAIvB,WAAW,IAAI,OAAO;IAItB,WAAW,IAAI,OAAO;IAKtB,qBAAqB,IAAI,MAAM;IA0B/B,OAAO,CAAC,cAAc;CAiBvB;AAED,eAAO,MAAM,eAAe,WAAkB,CAAC;AAE/C,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,aAAa,GAAG,aAAa,CA0B1E"}
@@ -1 +1 @@
1
- import{assertSchedulingPrecondition as c,invariant as f}from"../dev/invariant.js";import{logger as d}from"../dev/logger.js";function h(){try{const s=globalThis.__ASKR_FASTLANE;return typeof s?.isBulkCommitActive=="function"?!!s.isBulkCommitActive():!1}catch(s){return!1}}class g{constructor(){this.q=[],this.head=0,this.running=!1,this.inHandler=!1,this.depth=0,this.executionDepth=0,this.flushVersion=0,this.kickScheduled=!1,this.allowSyncProgress=!1,this.waiters=[],this.taskCount=0}enqueue(t){c(typeof t=="function","enqueue() requires a function"),!(h()&&!this.allowSyncProgress)&&(this.q.push(t),this.taskCount++,!this.running&&!this.kickScheduled&&!this.inHandler&&!h()&&(this.kickScheduled=!0,queueMicrotask(()=>{if(this.kickScheduled=!1,!this.running&&!h())try{this.flush()}catch(i){setTimeout(()=>{throw i})}})))}flush(){f(!this.running,"[Scheduler] flush() called while already running"),this.running=!0,this.depth=0;let t=null;try{for(;this.head<this.q.length;){this.depth++;const i=this.q[this.head++];try{this.executionDepth++,i(),this.executionDepth--}catch(e){this.executionDepth>0&&(this.executionDepth=0),t=e;break}this.taskCount>0&&this.taskCount--}}finally{if(this.running=!1,this.depth=0,this.executionDepth=0,this.head>=this.q.length)this.q.length=0,this.head=0;else if(this.head>0){const i=this.q.length-this.head;for(let e=0;e<i;e++)this.q[e]=this.q[this.head+e];this.q.length=i,this.head=0}this.flushVersion++,this.resolveWaiters()}if(t)throw t}runWithSyncProgress(t){const i=this.allowSyncProgress;this.allowSyncProgress=!0;const e=globalThis,l=e.queueMicrotask,o=e.setTimeout,u=this.flushVersion;try{const n=t();return!this.running&&this.q.length-this.head>0&&this.flush(),n}finally{try{this.flushVersion===u&&(this.flushVersion++,this.resolveWaiters())}catch(n){}this.allowSyncProgress=i}}waitForFlush(t,i=2e3){const e=typeof t=="number"?t:this.flushVersion+1;return this.flushVersion>=e?Promise.resolve():new Promise((l,o)=>{const u=setTimeout(()=>{const n=globalThis.__ASKR__||{},a={flushVersion:this.flushVersion,queueLen:this.q.length-this.head,running:this.running,inHandler:this.inHandler,bulk:h(),namespace:n};o(new Error(`waitForFlush timeout ${i}ms: ${JSON.stringify(a)}`))},i);this.waiters.push({target:e,resolve:l,reject:o,timer:u})})}getState(){return{queueLength:this.q.length-this.head,running:this.running,depth:this.depth,executionDepth:this.executionDepth,taskCount:this.taskCount,flushVersion:this.flushVersion,inHandler:this.inHandler,allowSyncProgress:this.allowSyncProgress}}setInHandler(t){this.inHandler=t}isInHandler(){return this.inHandler}isExecuting(){return this.running||this.executionDepth>0}clearPendingSyncTasks(){const t=this.q.length-this.head;return t<=0?0:this.running?(this.q.length=this.head,this.taskCount=Math.max(0,this.taskCount-t),queueMicrotask(()=>{try{this.flushVersion++,this.resolveWaiters()}catch(i){}}),t):(this.q.length=0,this.head=0,this.taskCount=Math.max(0,this.taskCount-t),this.flushVersion++,this.resolveWaiters(),t)}resolveWaiters(){if(this.waiters.length===0)return;const t=[],i=[];for(const e of this.waiters)this.flushVersion>=e.target?(e.timer&&clearTimeout(e.timer),t.push(e.resolve)):i.push(e);this.waiters=i;for(const e of t)e()}}const r=new g;function k(){return r.isExecuting()}function S(s){return t=>{r.setInHandler(!0);try{s.call(null,t)}catch(i){d.error("[Askr] Event handler error:",i)}finally{r.setInHandler(!1);const i=r.getState();(i.queueLength??0)>0&&!i.running&&queueMicrotask(()=>{try{r.isExecuting()||r.flush()}catch(e){setTimeout(()=>{throw e})}})}}}export{g as Scheduler,r as globalScheduler,k as isSchedulerExecuting,S as scheduleEventHandler};
1
+ import{assertSchedulingPrecondition as c,invariant as f}from"../dev/invariant.js";import{logger as d}from"../dev/logger.js";function h(){try{const s=globalThis.__ASKR_FASTLANE;return typeof s?.isBulkCommitActive=="function"?!!s.isBulkCommitActive():!1}catch(s){return!1}}class g{constructor(){this.q=[],this.head=0,this.running=!1,this.inHandler=!1,this.depth=0,this.executionDepth=0,this.flushVersion=0,this.kickScheduled=!1,this.allowSyncProgress=!1,this.waiters=[],this.taskCount=0}enqueue(t){c(typeof t=="function","enqueue() requires a function"),!(h()&&!this.allowSyncProgress)&&(this.q.push(t),this.taskCount++,!this.running&&!this.kickScheduled&&!this.inHandler&&!h()&&(this.kickScheduled=!0,queueMicrotask(()=>{if(this.kickScheduled=!1,!this.running&&!h())try{this.flush()}catch(i){setTimeout(()=>{throw i})}})))}flush(){f(!this.running,"[Scheduler] flush() called while already running"),this.running=!0,this.depth=0;let t=null;try{for(;this.head<this.q.length;){this.depth++;const i=this.q[this.head++];try{this.executionDepth++,i(),this.executionDepth--}catch(e){this.executionDepth>0&&(this.executionDepth=0),t=e;break}this.taskCount>0&&this.taskCount--}}finally{if(this.running=!1,this.depth=0,this.executionDepth=0,this.head>=this.q.length)this.q.length=0,this.head=0;else if(this.head>0){const i=this.q.length-this.head;for(let e=0;e<i;e++)this.q[e]=this.q[this.head+e];this.q.length=i,this.head=0}this.flushVersion++,this.resolveWaiters()}if(t)throw t}finalizeFlush(){}runWithSyncProgress(t){const i=this.allowSyncProgress;this.allowSyncProgress=!0;const e=globalThis,l=e.queueMicrotask,o=e.setTimeout,u=this.flushVersion;try{const n=t();return!this.running&&this.q.length-this.head>0&&this.flush(),n}finally{try{this.flushVersion===u&&(this.flushVersion++,this.resolveWaiters())}catch(n){}this.allowSyncProgress=i}}waitForFlush(t,i=2e3){const e=typeof t=="number"?t:this.flushVersion+1;return this.flushVersion>=e?Promise.resolve():new Promise((l,o)=>{const u=setTimeout(()=>{const n=globalThis.__ASKR__||{},a={flushVersion:this.flushVersion,queueLen:this.q.length-this.head,running:this.running,inHandler:this.inHandler,bulk:h(),namespace:n};o(new Error(`waitForFlush timeout ${i}ms: ${JSON.stringify(a)}`))},i);this.waiters.push({target:e,resolve:l,reject:o,timer:u})})}getState(){return{queueLength:this.q.length-this.head,running:this.running,depth:this.depth,executionDepth:this.executionDepth,taskCount:this.taskCount,flushVersion:this.flushVersion,inHandler:this.inHandler,allowSyncProgress:this.allowSyncProgress}}setInHandler(t){this.inHandler=t}isInHandler(){return this.inHandler}isExecuting(){return this.running||this.executionDepth>0}clearPendingSyncTasks(){const t=this.q.length-this.head;return t<=0?0:this.running?(this.q.length=this.head,this.taskCount=Math.max(0,this.taskCount-t),queueMicrotask(()=>{try{this.flushVersion++,this.resolveWaiters()}catch(i){}}),t):(this.q.length=0,this.head=0,this.taskCount=Math.max(0,this.taskCount-t),this.flushVersion++,this.resolveWaiters(),t)}resolveWaiters(){if(this.waiters.length===0)return;const t=[],i=[];for(const e of this.waiters)this.flushVersion>=e.target?(e.timer&&clearTimeout(e.timer),t.push(e.resolve)):i.push(e);this.waiters=i;for(const e of t)e()}}const r=new g;function k(){return r.isExecuting()}function S(s){return t=>{r.setInHandler(!0);try{s.call(null,t)}catch(i){d.error("[Askr] Event handler error:",i)}finally{r.setInHandler(!1);const i=r.getState();(i.queueLength??0)>0&&!i.running&&queueMicrotask(()=>{try{r.isExecuting()||r.flush()}catch(e){setTimeout(()=>{throw e})}})}}}export{g as Scheduler,r as globalScheduler,k as isSchedulerExecuting,S as scheduleEventHandler};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askrjs/askr",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
4
4
  "description": "Actor-backed deterministic UI framework",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -77,8 +77,10 @@
77
77
  "scripts": {
78
78
  "build": "npm run build:prod",
79
79
  "build:prod": "cross-env NODE_ENV=production vite build && npm run build:types",
80
+ "build:dev": "cross-env NODE_ENV=development vite build && npm run build:types",
80
81
  "build:types": "tsc -p tsconfig.json --emitDeclarationOnly",
81
82
  "build:bench": "npm run build:prod",
83
+ "dev:watch": "vite build --watch --mode development",
82
84
  "prepare": "npm run build:prod",
83
85
  "dev": "vite",
84
86
  "test": "vitest run",