@askrjs/askr 0.0.25 → 0.0.26

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.
@@ -1,9 +1,27 @@
1
- import { type VNode } from './types';
1
+ import { type DOMElement, type VNode } from './types';
2
2
  export declare const IS_DOM_AVAILABLE: boolean;
3
3
  /**
4
4
  * Create a DOM node from a VNode
5
5
  */
6
6
  export declare function createDOMNode(node: unknown): Node | null;
7
+ /**
8
+ * Create DOM from For boundary - evaluates list and renders items
9
+ *
10
+ * CRITICAL INVARIANT:
11
+ * DOM order MUST be reconstructed from the current vnode list on every render.
12
+ * Reusing DOM nodes never implies preserving their position.
13
+ *
14
+ * This function ALWAYS returns a fragment whose child order exactly matches
15
+ * the evaluated vnode list, even when all DOM nodes are reused.
16
+ * Appending an existing node to the fragment is how we express reordering
17
+ * (per DOM spec, appendChild moves already-attached nodes).
18
+ *
19
+ * Do NOT:
20
+ * - Skip appending based on parentElement or existing attachment
21
+ * - Rely on vnode identity (===) to decide DOM reuse (vnodes are mutable)
22
+ * - Introduce fast-paths that might skip DOM reconstruction
23
+ */
24
+ export declare function createForBoundary(node: DOMElement, props: Record<string, unknown>): DocumentFragment;
7
25
  /**
8
26
  * Update an existing element's attributes and children from vnode
9
27
  */
@@ -1 +1 @@
1
- {"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../src/renderer/dom.ts"],"names":[],"mappings":"AA6BA,OAAO,EAAkC,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;AAmPD;;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,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 +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,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 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 +1 @@
1
- {"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../src/renderer/evaluate.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,gBAAgB,SAAkC,CAAC;AAshBhE,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":"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 +1 @@
1
- import{logger as S}from"../dev/logger.js";import{elementListeners as d,removeAllListeners as M}from"./cleanup.js";import{keyedElements as f}from"./keyed.js";import{reconcileKeyedChildren as y}from"./reconcile.js";import"./types.js";import{_isDOMElement as a,__FOR_BOUNDARY__ as m}from"../common/vnode.js";import{evaluateForState as N}from"../runtime/for.js";import{performBulkPositionalKeyedTextUpdate as b,isBulkTextFastPathEligible as C,performBulkTextReplace as B,updateUnkeyedChildren as D,createDOMNode as u,updateElementFromVnode as _}from"./dom.js";import{setDevValue as T,incDevCounter as P}from"../runtime/dev-namespace.js";import{Fragment as R}from"../common/jsx.js";import{extractKey as w,parseEventName as O,createWrappedHandler as U,getPassiveOptions as H}from"./utils.js";var l={};const oe=typeof document<"u",p=new WeakMap;function A(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++){const r=e.charCodeAt(n),i=t.charCodeAt(n);if(r===i)continue;const s=r>=65&&r<=90?r+32:r,o=i>=65&&i<=90?i+32:i;if(s!==o)return!1}return!0}function L(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 I(e,t){return e.childNodes.length===1&&e.firstChild?.nodeType===3?(e.firstChild.data=t,!0):!1}function E(e){const t=new Map;for(let n=e.firstElementChild;n;n=n.nextElementSibling){const r=n.getAttribute("data-key");if(r!==null){t.set(r,n);const i=Number(r);Number.isNaN(i)||t.set(i,n)}}return t}function K(e){let t=f.get(e);return t||(t=E(e),t.size>0&&f.set(e,t)),t.size>0?t:void 0}function x(e){for(let t=0;t<e.length;t++)if(w(e[t])!==void 0)return!0;return!1}function F(e,t,n){if(l.ASKR_FORCE_BULK_POSREUSE==="1"&&V(e,t))return;const r=y(e,t,n);f.set(e,r)}function V(e,t){try{const n=[];for(const s of t)a(s)&&s.key!==void 0&&n.push({key:s.key,vnode:s});if(n.length===0||n.length!==t.length)return!1;(l.ASKR_FASTPATH_DEBUG==="1"||l.ASKR_FASTPATH_DEBUG==="true")&&S.warn("[Askr][FASTPATH] forced positional bulk keyed reuse (evaluate-level)");const r=b(e,n);if(l.ASKR_FASTPATH_DEBUG==="1")try{T("__LAST_FASTPATH_STATS",r),T("__LAST_FASTPATH_COMMIT_COUNT",1),P("bulkKeyedPositionalForced")}catch{}const i=E(e);return f.set(e,i),!0}catch(n){return(l.ASKR_FASTPATH_DEBUG==="1"||l.ASKR_FASTPATH_DEBUG==="true")&&S.warn("[Askr][FASTPATH] forced bulk path failed, falling back",n),!1}}function v(e,t){if(C(e,t)){const n=B(e,t);}else D(e,t);f.delete(e)}function g(e,t){const n=t._forState;if(!n)return;const r=(t.props||{}).source,i=N(n,r);if(i.length>0){const s=K(e);try{F(e,i,s)}catch{const o=y(e,i,s);f.set(e,o)}}else e.textContent="",f.delete(e)}function k(e,t){if(t==null){e.textContent="",f.delete(e);return}if(!Array.isArray(t)&&a(t)&&t.type===m){g(e,t);return}if(!Array.isArray(t)){e.textContent="";const n=u(t);n&&e.appendChild(n),f.delete(e);return}if(t.length===1&&a(t[0])&&t[0].type===m){g(e,t[0]);return}if(x(t)){const n=K(e);try{F(e,t,n)}catch{const r=y(e,t,n);f.set(e,r)}}else v(e,t)}function h(e,t){let n=t.children||t.props?.children;if(n&&a(n)&&n.type===m){k(e,n),_(e,t,!1);return}n&&!Array.isArray(n)&&(n=[n]);const r=L(n);r.isSimple&&I(e,r.text)||k(e,n),_(e,t,!1)}function G(e,t){let n=e.firstElementChild;for(let r=0;r<t.length;r++){const i=t[r],s=n?n.nextElementSibling:null;if(n&&a(i)&&typeof i.type=="string"&&A(n.tagName,i.type)){h(n,i),n=s;continue}const o=u(i);o&&(n?e.replaceChild(o,n):e.appendChild(o)),n=s}for(;n;){const r=n.nextElementSibling;e.removeChild(n),n=r}}function W(e,t){for(const[n,r]of Object.entries(t)){if(n==="children"||n==="key"||r==null||r===!1)continue;if(n==="ref"){z(e,r);continue}const i=O(n);if(i){const s=U(r,!0),o=H(i);o!==void 0?e.addEventListener(i,s,o):e.addEventListener(i,s),d.has(e)||d.set(e,new Map),d.get(e).set(i,{handler:s,original:r,options:o});continue}n==="class"||n==="className"?e.className=String(r):n==="value"||n==="checked"?e[n]=r:e.setAttribute(n,String(r))}}function z(e,t){const n=t;if(n){if(typeof n=="function"){n(e);return}try{n.current=e}catch{}}}function j(e,t){const n=t.children;if(!Array.isArray(n)||!x(n))return!1;const r=document.createElement(t.type);e.appendChild(r),W(r,t.props||{});const i=y(r,n,void 0);return f.set(r,i),!0}function q(e){return a(e)&&typeof e.type=="symbol"&&(e.type===R||String(e.type)==="Symbol(askr.fragment)")}function X(e){const t=e.props?.children||e.children||[];return Array.isArray(t)?t:[t]}function ce(e,t,n){if(t&&!(typeof document>"u"))if(n&&p.has(n)){const r=p.get(n);let i=r.start.nextSibling;for(;i&&i!==r.end;){const o=i.nextSibling;i.remove(),i=o}const s=u(e);s&&t.insertBefore(s,r.end)}else if(n){const r=document.createComment("component-start"),i=document.createComment("component-end");t.appendChild(r),t.appendChild(i),p.set(n,{start:r,end:i});const s=u(e);s&&t.insertBefore(s,i)}else{let r=e;if(q(r)){const c=X(r);if(c.length===1&&a(c[0])&&typeof c[0].type=="string")r=c[0];else{G(t,c);return}}const s=t.__ASKR_INSTANCE;if(s&&s.target===t)if(a(r)&&typeof r.type=="string"&&A(t.tagName,r.type)){h(t,r);return}else{const c=u(r);if(c&&t.parentNode){c instanceof Element&&(c.__ASKR_INSTANCE=s,s.target=c),M(t),t.parentNode.replaceChild(c,t);return}}const o=t.children[0];if(o&&a(r)&&typeof r.type=="string"&&A(o.tagName,r.type))h(o,r);else{if(t.textContent="",a(r)&&typeof r.type=="string"&&j(t,r))return;const c=u(r);c&&t.appendChild(c)}}}function fe(e){p.delete(e)}export{oe as IS_DOM_AVAILABLE,fe as clearDOMRange,ce as evaluate};
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 +1 @@
1
- import"./types.js";import{cleanupInstanceIfPresent as i,cleanupInstancesUnder as s,elementListeners as d,elementReactivePropsCleanup as c,removeAllListeners as u,removeElementListeners as E,removeElementReactiveProps as f}from"./cleanup.js";import{getKeyMapForElement as t,isKeyedReorderFastPathEligible as r}from"./keyed.js";import{_reconcilerRecordedParents as x,keyedElements as g,populateKeyMapForElement as v}from"./keyed.js";import{IS_DOM_AVAILABLE as P,createDOMNode as _,isBulkTextFastPathEligible as h,performBulkPositionalKeyedTextUpdate as k,performBulkTextReplace as A,updateElementChildren as F,updateElementFromVnode as I,updateUnkeyedChildren as K}from"./dom.js";import{evaluate as o}from"./evaluate.js";import{clearDOMRange as M}from"./evaluate.js";if(typeof globalThis<"u"){const e=globalThis;e.__ASKR_RENDERER={evaluate:o,isKeyedReorderFastPathEligible:r,getKeyMapForElement:t}}export{P as IS_DOM_AVAILABLE,x as _reconcilerRecordedParents,i as cleanupInstanceIfPresent,s as cleanupInstancesUnder,M as clearDOMRange,_ as createDOMNode,d as elementListeners,c as elementReactivePropsCleanup,o as evaluate,t as getKeyMapForElement,h as isBulkTextFastPathEligible,r as isKeyedReorderFastPathEligible,g as keyedElements,k as performBulkPositionalKeyedTextUpdate,A as performBulkTextReplace,v as populateKeyMapForElement,u as removeAllListeners,E as removeElementListeners,f as removeElementReactiveProps,F as updateElementChildren,I as updateElementFromVnode,K as updateUnkeyedChildren};
1
+ import"./types.js";import{cleanupInstanceIfPresent as i,cleanupInstancesUnder as s,elementListeners as d,elementReactivePropsCleanup as c,removeAllListeners as u,removeElementListeners as E,removeElementReactiveProps as f}from"./cleanup.js";import{getKeyMapForElement as t,isKeyedReorderFastPathEligible as r}from"./keyed.js";import{_reconcilerRecordedParents as x,keyedElements as y,populateKeyMapForElement as g}from"./keyed.js";import{IS_DOM_AVAILABLE as P,createDOMNode as _,createForBoundary as h,isBulkTextFastPathEligible as F,performBulkPositionalKeyedTextUpdate as k,performBulkTextReplace as A,updateElementChildren as B,updateElementFromVnode as I,updateUnkeyedChildren as K}from"./dom.js";import{evaluate as o}from"./evaluate.js";import{clearDOMRange as M}from"./evaluate.js";if(typeof globalThis<"u"){const e=globalThis;e.__ASKR_RENDERER={evaluate:o,isKeyedReorderFastPathEligible:r,getKeyMapForElement:t}}export{P as IS_DOM_AVAILABLE,x as _reconcilerRecordedParents,i as cleanupInstanceIfPresent,s as cleanupInstancesUnder,M as clearDOMRange,_ as createDOMNode,h as createForBoundary,d as elementListeners,c as elementReactivePropsCleanup,o as evaluate,t as getKeyMapForElement,F as isBulkTextFastPathEligible,r as isKeyedReorderFastPathEligible,y as keyedElements,k as performBulkPositionalKeyedTextUpdate,A as performBulkTextReplace,g as populateKeyMapForElement,u as removeAllListeners,E as removeElementListeners,f as removeElementReactiveProps,B as updateElementChildren,I as updateElementFromVnode,K as updateUnkeyedChildren};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@askrjs/askr",
3
- "version": "0.0.25",
3
+ "version": "0.0.26",
4
4
  "description": "Actor-backed deterministic UI framework",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",