@firsthandjs/dom 0.8.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-6BRSYQCI.js +1 -0
- package/dist/chunk-E4GAI5XA.js +1 -0
- package/dist/chunk-P4PXTIUD.js +1 -0
- package/dist/claim.d.ts +86 -0
- package/dist/claim.d.ts.map +1 -0
- package/dist/dev-chunk-6V32MCOI.js +45 -0
- package/dist/dev-chunk-ADHDPKZW.js +525 -0
- package/dist/{dev-chunk-2CKM3OGC.js → dev-chunk-MKONDKMD.js} +152 -450
- package/dist/dev.d.ts +11 -0
- package/dist/dev.d.ts.map +1 -1
- package/dist/dev.prod.d.ts +1 -0
- package/dist/dev.prod.d.ts.map +1 -1
- package/dist/hydrate.d.ts +102 -0
- package/dist/hydrate.d.ts.map +1 -0
- package/dist/hydrate.dev.js +160 -0
- package/dist/hydrate.js +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.dev.js +19 -35
- package/dist/index.js +1 -1
- package/dist/insert.d.ts +64 -1
- package/dist/insert.d.ts.map +1 -1
- package/dist/internal.d.ts +1 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.dev.js +30 -12
- package/dist/internal.js +1 -1
- package/dist/list.d.ts.map +1 -1
- package/dist/props.d.ts.map +1 -1
- package/dist/render.d.ts +9 -0
- package/dist/render.d.ts.map +1 -1
- package/dist/template.d.ts.map +1 -1
- package/package.json +7 -2
- package/dist/chunk-EWYTWH5D.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{r as d,s as i}from"./chunk-P4PXTIUD.js";import{createRoot as r,onCleanup as s,untrack as u}from"@firsthandjs/core";function y(o,e=document.body){return f(o,e,null)}function f(o,e,l){let t;return r(n=>{t=n;let p=()=>{c(e,u(o),l!==null)};l===null?p():l(p)}),t}function c(o,e,l){if(typeof e=="function"){d(o,e);return}let t=null;if(l){let n=[...o.childNodes];t=n.length===1?n[0]:n}t=i(o,null,t,e),s(()=>{i(o,null,t,null)})}export{y as a,f as b};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as S,e as T,f as A,g as N,h as g,i as j,s as L,t as H}from"./chunk-P4PXTIUD.js";var C=null,E=new WeakMap;function $n(n){C=n,E=new WeakMap}var R=class extends Error{constructor(e){super(`${e} is not a Firsthand component. If it is a React component, import '@firsthandjs/react/auto' once at startup to render React components directly, or wrap it with fromReact(). Otherwise, declare it with component().`),this.name="FirsthandComponentError"}};function M(n){let e=E.get(n);if(e!==void 0)return e;if(C===null){let o=typeof n=="function"&&n.name!==""?n.name:"The value";throw new R(o)}let t=C(n);return E.set(n,t),t}import{signal as un,createOwner as D,devEnterSetup as V,devExitSetup as y,disposeOwner as ln,getOwner as F,handleError as W,setOwner as w,untrack as I}from"@firsthandjs/core";var z=Symbol.for("firsthand.component"),K=Symbol.for("firsthand.view"),an=0,Z="firsthand";function Mn(n){Z=n}function Dn(n,e,t,o){let s=Object.assign(i=>fn(s,i),{[z]:!0,setup:n,options:e,id:t??`c${String(++an)}`,tag:void 0});return Object.defineProperty(s,"name",{configurable:!0,value:o??(n.name===""?"Component":n.name)}),t===void 0&&(`${s.name}`,void 0),(e?.tag!==void 0||e?.shadow===!0)&&mn(s,typeof e.tag=="string"?e.tag:void 0),s}function Vn(n){return typeof n=="function"&&z in n}function Fn(n){return n[K]=!0,n}function fn(n,e){if(Object.freeze(e),n.setup===void 0)return K in n?g(()=>n(e)):M(n)(e);if(n.tag!==void 0)return yn(n,e);let t=D(F());n.name;let o=w(t);try{V(n.id);let r=I(()=>n.setup(e));return y(),w(o),r}catch(r){return y(),w(o),W(r,t),null}}function pn(n){let e=n.name.replace(/([a-z0-9])([A-Z])/g,"$1-$2").replace(/[^a-zA-Z0-9-]/g,"-").toLowerCase();return`${Z}-${e}`}function mn(n,e){let t=n;if(t.tag!==void 0)return t.tag;let o=e??pn(t);return customElements.get(o)!==void 0&&(o=`${o}-${t.id.replace(/[^a-zA-Z0-9]/g,"").toLowerCase()}`),t.tag=o,customElements.define(o,wn(t)),o}function wn(n){let e=n.options?.shadow===!0,t=n.options?.attributes,o=t!==void 0?Object.keys(t):[];return class extends HTMLElement{static observedAttributes=o;constructor(){super(),this.$owner=null,this.$props=null,this.$attrs=null,this.$standalone=!1}connectedCallback(){this.$owner===null&&(this.$standalone=!0,this.$attrs={},this.$props=gn(this,t,this.$attrs),q(this,n,e))}disconnectedCallback(){!this.$standalone||this.$owner===null||(ln(this.$owner),this.$owner=null)}attributeChangedCallback(s,i,u){let l=this.$attrs?.[s];l!==void 0&&(l.value=t[s]?.(u))}}}function gn(n,e,t){let o={};if(e!==void 0)for(let r in e){let s=un(e[r](n.getAttribute(r)));t[r]=s,Object.defineProperty(o,r,{enumerable:!0,get:()=>s.value})}return Object.freeze(o)}function q(n,e,t){let o=D(F());e.name,n.$owner=o;let r=w(o);try{V(e.id);let s=t?n.attachShadow({mode:"open"}):n,i=I(()=>e.setup(n.$props));y(),L(s,null,null,i)}catch(s){y(),W(s,o)}finally{w(r)}}function yn(n,e){let t=document.createElement(n.tag);return t.$props=e,q(t,n,n.options?.shadow===!0),t}import{batch as hn,createOwner as J,disposeOwner as bn,getOwner as kn,setOwner as B,signal as G,untrack as Q}from"@firsthandjs/core";function Gn(n,e,t){let o=J(kn()),r=new Map,s,i=!1;return()=>{let u=n();if(i&&s!==void 0){s.length=0;for(let d of r.values())for(let f of d.pieces===void 0?d.nodes:Y(d))s.push(f)}let l=new Map,a=[];a[A]=!0;let m;if(Q(()=>{hn(()=>{cn()})}),r=l,s=a,m!==void 0){let d=m;a[N]=f=>{for(let p of d)_(p,f)}}return a;function cn(){for(let d=0;d<u.length;d++){let f=u[d],p=e(f,d);if(l.has(p)){`${String(p)}`;continue}let c=r.get(p);c===void 0?(c=Cn(o,f,d,t),c.pieces!==void 0&&(i=!0,_(c,null)||(m=m===void 0?[c]:[...m,c]))):(r.delete(p),c.item.value=f,c.index.value=d),l.set(p,c);let $=c.pieces===void 0?c.nodes:Y(c);for(let k=0;k<$.length;k++)a.push($[k])}T(()=>{for(let d of r.values())bn(d.owner)})}}}function U(n){return typeof n.nodeType=="number"}function _(n,e){let t=n.pieces;for(let o of t){if(U(o))continue;let r=e??S.current?.place(o.child.anchor)??null;if(r===null)return!1;H(o.child,r,s=>{o.nodes=s})}return!0}function Y(n){let e=[];for(let t of n.pieces)if(U(t))e.push(t);else for(let o of t.nodes)e.push(o);return e}function Cn(n,e,t,o){let r=J(n),s=G(e),i=G(t),u=B(r),l=[],a;try{a=X(Q(()=>o(s,i)),l)}finally{B(u)}return a?{owner:r,item:s,index:i,nodes:[],pieces:l}:{owner:r,item:s,index:i,nodes:l}}function X(n,e){if(n==null||typeof n=="boolean")return!1;if(Array.isArray(n)){let t=!1;for(let o=0;o<n.length;o++)t=X(n[o],e)||t;return t}if(typeof n=="function"){let t=g(n);return e.push({child:t,nodes:[t.anchor]}),!0}if(typeof n=="object"){if(j(n))return e.push({child:n,nodes:[n.anchor]}),!0;if(typeof n.nodeType=="number")return e.push(n),!1}return e.push(document.createTextNode(String(n))),!1}var En=new Set(["click","dblclick","contextmenu","input","beforeinput","change","keydown","keyup","keypress","pointerdown","pointerup","pointermove","mousedown","mouseup","mouseover","mouseout","submit","focusin","focusout","touchstart","touchend"]),nn=new Set;function h(n){return`$firsthand$${n}`}function Rn(n){let e=h(n.type),t=n.composedPath(),o=null;Object.defineProperty(n,"currentTarget",{configurable:!0,get:()=>o});for(let r=0;r<t.length;r++){let s=t[r],i=s[e];if(i!==void 0&&(o=s,i.call(s,n),n.cancelBubble)||s===document)break}o=null}function b(n,e,t,o){if(o!==void 0||!En.has(e)){let r=n,s=o===!0?void 0:o,i=`${h(e)}$${s===void 0?"":Object.keys(s).sort().join(",")}`,u=r[i];u!==void 0&&n.removeEventListener(e,u.handler,u.options),r[i]={handler:t,options:s},n.addEventListener(e,t,s);return}n[h(e)]=t,nn.has(e)||(nn.add(e),document.addEventListener(e,Rn))}function Yn(n,e){n[h(e)]=void 0}var Pn={class:"className",for:"htmlFor"};function x(n,e,t){t==null||t===!1?n.removeAttribute(e):n.setAttribute(e,t===!0?"":String(t))}function Xn(n,e,t,o){o==null||o===!1?n.removeAttributeNS(e,t):n.setAttributeNS(e,t,o===!0?"":String(o))}function v(n,e,t){n[Pn[e]??e]=t}function ne(n,e,t){n[e]=!!t}function O(n,e){e==null?n.removeAttribute("class"):n.className=String(e)}function tn(n,e,t){let o=n.classList;if(t!==void 0)for(let r in t)r in e||o.remove(r);for(let r in e){let s=!!e[r];(t===void 0||!!t[r]!==s)&&o.toggle(r,s)}}function on(n,e){e==null?n.style.cssText="":n.style.cssText=String(e)}function rn(n,e,t){let o=n.style;if(t!==void 0)for(let r in t)r in e||o.removeProperty(P(r));for(let r in e){let s=e[r];(t===void 0||t[r]!==s)&&(s==null?o.removeProperty(P(r)):o.setProperty(P(r),String(s)))}}var xn=/[A-Z]/g,en=new Map;function P(n){let e=en.get(n);return e===void 0&&(e=n.startsWith("--")?n:n.replace(xn,t=>`-${t.toLowerCase()}`),en.set(n,e)),e}function vn(n,e,t){if(e==="class"||e==="className"){Array.isArray(t)?O(n,t.filter(Boolean).join(" ")):t!==null&&typeof t=="object"?tn(n,t,dn(n,"class",t)):O(n,t);return}if(e==="style"){t!==null&&typeof t=="object"?rn(n,t,dn(n,"style",t)):on(n,t);return}if(e==="ref"){t(n);return}if(e.startsWith("prop:")){v(n,e.slice(5),t);return}if(e.startsWith("attr:")){x(n,e.slice(5),t);return}if(e.startsWith("on")&&e.length>2&&/[A-Z:]/.test(e[2])){On(n,e,t);return}if(e in n&&typeof t!="string"){v(n,e,t);return}x(n,e,t)}function On(n,e,t){let o=e.slice(2).split(":"),r=o[0]==="",s=r?o[1]:o[0].toLowerCase(),i=o[r?2:1];i===void 0?b(n,s,t):i==="native"?b(n,s,t,!0):b(n,s,t,{[i]:!0})}function re(n,e){for(let t in e)t!=="children"&&vn(n,t,e[t])}function se(...n){let e={};for(let t=0;t<n.length;t++){let o=n[t];for(let r of Object.keys(o))Object.defineProperty(e,r,{enumerable:!0,configurable:!0,get:()=>o[r]})}return e}function ie(n,e){let t={};for(let o of Object.keys(n))e.includes(o)||Object.defineProperty(t,o,{enumerable:!0,get:()=>n[o]});return Object.freeze(t)}var sn=new WeakMap;function dn(n,e,t){let o=sn.get(n);o===void 0&&(o={},sn.set(n,o));let r=o[e];return o[e]=t,r}export{$n as a,R as b,z as c,K as d,Mn as e,Dn as f,Vn as g,Fn as h,fn as i,mn as j,Gn as k,b as l,Yn as m,x as n,Xn as o,v as p,ne as q,O as r,tn as s,on as t,rn as u,vn as v,re as w,se as x,ie as y};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function Q(n,i,e){return n}var a={current:null};function V(n){let i=n.firstChild,e=a.current;return e===null?i:e.step(i)}function Y(n){let i=n.nextSibling,e=a.current;return e===null?i:e.step(i)}import{bind as v,createOwner as B,signal as H,disposeOwner as G,getOwner as A,onCleanup as k,runWithOwner as E,setOwner as I}from"@firsthandjs/core";var S=0;function dn(n){S++;try{n()}finally{S--}}var M=3;function P(n){return typeof n.nodeType=="number"}var W=Symbol("firsthand.part"),L=Symbol("firsthand.flat"),X=Symbol("firsthand.pending"),w=new WeakSet;function sn(n){return{[W]:!0,anchor:document.createTextNode(""),thunk:n,owner:A()}}function T(n){return W in n}function un(n=""){return{slots:[],owner:A(),generation:0,name:n}}function C(n){n.busy=!0}function q(n,i){let e=n.slots[i];if(e!==void 0)return e.seen=n.generation,e;let o={seen:n.generation};return n.slots[i]=o,o}function fn(n,i){let e=B(n.owner);return i.owner=e,I(e)}function cn(n){I(n)}function an(n,i){let e=n.generation,o=n.slots;for(let t=0;t<o.length;t++){let l=o[t];l===void 0||l.seen===e||(l.owner!==void 0&&G(l.owner),o[t]=void 0)}return n.generation=e+1,i}function yn(n,i,e){let o=q(n,i),t=o.cell;if(t===void 0){let l=H(e);return o.cell=l,l}return t.peek()!==e&&(C(n),t.value=e),t}function hn(n,i,e,o,t){let l=q(n,i);if(l.node===void 0&&a.current!==null){let r=a.current.claim(e,o);if(r!==null){if(typeof t=="object"&&t!==null&&T(t)){l.last=t,a.current.keep(l,e,t.anchor,r),E(t.owner,()=>{m(e,t.thunk,t.anchor)});return}l.node=r.nodes,l.text=r.text}}let d=typeof t;if(d==="string"||d==="number"){let r=String(t);if(r===l.text)return;C(n),l.text=r,l.node=h(e,o,l.node??null,r);return}l.text=void 0,t!==l.last&&(C(n),l.last=t,l.node=h(e,o,l.node??null,t))}function m(n,i,e=null,o,t){if(typeof i!="function"){h(n,e,null,i);return}let l=null,d,r=o!==void 0?o:a.current===null?null:a.current.claim(n,e),u=r!==null;r!==null&&(l=r.nodes,d=r.text);let f=()=>{c(),t?.(z(l,e))},c=()=>{let y=i(),g=typeof y;if(g==="string"||g==="number"){let p=String(y);p!==d&&(d=p,l=h(n,e,l,p));return}if(d=void 0,g==="function"){if(u){l=null,m(n,y,e,r);return}l=x(l),m(n,y,e,null);return}l=h(n,e,l,y)};r===null?v(f):a.current.within(r.region,()=>{v(f)}),u=!1,k(()=>{l=S>0?null:x(l)})}function z(n,i){let e=n===null?[]:Array.isArray(n)?[...n]:[n];return e.push(i),e}function h(n,i,e,o){let t=typeof o;if(o==null||t==="boolean")return b(n,i,e);if(t==="string"||t==="number"){let l=String(o);return e!==null&&!Array.isArray(e)&&e.nodeType===M?(e.data=l,e):D(n,i,e,document.createTextNode(l))}if(t==="function")return h(n,i,e,o());if(Array.isArray(o)){if(L in o){let r=o;return r.length===0?b(n,i,e):(R(n,i,e===null?[]:Array.isArray(e)?e:[e],r),o[X]?.(n),r)}let l=[],d=[];if(F(o,l,d),l.length===0)return b(n,i,e);R(n,i,e===null?[]:Array.isArray(e)?e:[e],l);for(let r=0;r<d.length;r++)J(d[r],n);return l}return T(o)?h(n,i,e,[o]):P(o)?D(n,i,e,o):h(n,i,e,String(o))}function J(n,i,e){w.has(n)||(w.add(n),E(n.owner??A(),()=>{m(i,n.thunk,n.anchor,void 0,e),k(()=>{w.delete(n)})}))}function F(n,i,e){for(let o=0;o<n.length;o++){let t=n[o];if(typeof t=="object"&&t!==null&&T(t)){i.push(t.anchor),e.push(t);continue}for(;typeof t=="function";)t=t();t==null||typeof t=="boolean"||(Array.isArray(t)?F(t,i,e):typeof t=="object"&&P(t)?i.push(t):i.push(document.createTextNode(String(t))))}}function j(n){let i=n.parentNode;i!==null&&i.removeChild(n)}function b(n,i,e){return i===null&&Array.isArray(e)&&e.length>1&&n.childNodes.length===e.length?(n.textContent="",null):x(e)}function x(n){if(n!==null)if(Array.isArray(n))for(let i=0;i<n.length;i++)j(n[i]);else j(n);return null}function D(n,i,e,o){return e===o?o:e!==null&&!Array.isArray(e)?(n.replaceChild(o,e),o):(x(e),n.insertBefore(o,i),o)}function R(n,i,e,o){let t=0,l=0,d=e.length-1,r=o.length-1;for(;t<=d&&l<=r&&e[t]===o[l];)t++,l++;for(;t<=d&&l<=r&&e[d]===o[r];)d--,r--;let u=r+1<o.length?o[r+1]:i;if(t>d){for(let s=l;s<=r;s++)n.insertBefore(o[s],u);return}if(l>r){for(let s=t;s<=d;s++)n.removeChild(e[s]);return}let f=new Map;for(let s=t;s<=d;s++)f.set(e[s],s);let c=r-l+1,y=new Int32Array(c).fill(-1);for(let s=0;s<c;s++){let N=o[l+s],_=f.get(N);_!==void 0&&(y[s]=_,f.delete(N))}for(let s of f.keys())n.removeChild(s);let g=K(y),p=g.length-1,O=u;for(let s=c-1;s>=0;s--){let N=o[l+s];p>=0&&g[p]===s?p--:n.insertBefore(N,O),O=N}}function K(n){let i=n.length,e=new Int32Array(i).fill(-1),o=[];for(let d=0;d<i;d++){let r=n[d];if(r===-1)continue;let u=0,f=o.length;for(;u<f;){let c=u+f>>1;n[o[c]]<r?u=c+1:f=c}u>0&&(e[d]=o[u-1]),o[u]=d}let t=[],l=o.length>0?o[o.length-1]:-1;for(;l!==-1;)t.push(l),l=e[l];return t.reverse()}export{Q as a,a as b,V as c,Y as d,dn as e,L as f,X as g,sn as h,T as i,un as j,C as k,q as l,fn as m,cn as n,an as o,yn as p,hn as q,m as r,h as s,J as t,R as u};
|
package/dist/claim.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The seam hydration is installed through.
|
|
3
|
+
*
|
|
4
|
+
* `template` and `insert` have to be able to adopt nodes a server sent, and
|
|
5
|
+
* an application that has no server must not pay for the machinery that does
|
|
6
|
+
* it. So they do not import it. They read one holder, which is empty until
|
|
7
|
+
* `@firsthandjs/dom/hydrate` fills it — and a bundle that never imports that
|
|
8
|
+
* module never contains the machinery at all, because nothing references it.
|
|
9
|
+
*
|
|
10
|
+
* What is left behind in the ordinary path is one property read and one
|
|
11
|
+
* comparison against `null`, in two places.
|
|
12
|
+
*/
|
|
13
|
+
/** What a region of server markup turned out to hold. */
|
|
14
|
+
export type Claimed = {
|
|
15
|
+
/** The nodes the region holds, as a child slot. */
|
|
16
|
+
nodes: Node | Node[] | null;
|
|
17
|
+
/** The text already there, when the region is one text node. */
|
|
18
|
+
text: string | undefined;
|
|
19
|
+
/** The region itself, for the calls made while a child's first run happens. */
|
|
20
|
+
region: Region;
|
|
21
|
+
};
|
|
22
|
+
/** Where a claim has got to. */
|
|
23
|
+
export type Region = {
|
|
24
|
+
/** The next unclaimed node, or null when the region is used up. */
|
|
25
|
+
node: Node | null;
|
|
26
|
+
/** The node the region stops before. */
|
|
27
|
+
end: Node | null;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The part of a site hydration fills in.
|
|
31
|
+
*
|
|
32
|
+
* Structural, so that the holder does not have to import `insert.ts` and
|
|
33
|
+
* `insert.ts` does not have to export its record type to reach through it.
|
|
34
|
+
*/
|
|
35
|
+
export type Filled = {
|
|
36
|
+
node?: Node | Node[] | null;
|
|
37
|
+
};
|
|
38
|
+
export type Claimer = {
|
|
39
|
+
/** The element name a template's markup makes. */
|
|
40
|
+
tag(html: string): string;
|
|
41
|
+
/** The next node of the current region, if it is a `tag`. */
|
|
42
|
+
adopt(tag: string): Node | null;
|
|
43
|
+
/**
|
|
44
|
+
* Gives a child a run keeps the nodes the run claimed for it.
|
|
45
|
+
*
|
|
46
|
+
* Puts `anchor` at the end of the region and offers the region to whoever
|
|
47
|
+
* claims against that anchor next, which is the child's own `insert`.
|
|
48
|
+
*/
|
|
49
|
+
keep(slot: Filled, parent: Node, anchor: Node, claimed: Claimed): void;
|
|
50
|
+
/** The region belonging to the next dynamic child of `parent`. */
|
|
51
|
+
claim(parent: Node, marker: Node | null): Claimed | null;
|
|
52
|
+
/** Makes `region` the one nodes are adopted from while `body` runs. */
|
|
53
|
+
within<T>(region: Region, body: () => T): T;
|
|
54
|
+
/** A step through the template that goes over a whole region at a time. */
|
|
55
|
+
step(node: Node): Node;
|
|
56
|
+
/**
|
|
57
|
+
* Puts `anchor` where hydration has got to, and says what it went into.
|
|
58
|
+
*
|
|
59
|
+
* What a keyed list needs to adopt a row that is a view: the row has
|
|
60
|
+
* nothing of its own until it runs, and it has to run where its markup is,
|
|
61
|
+
* in the order the rows come in — not after the list has decided what goes
|
|
62
|
+
* where. Null when the region is used up, which is a list with more rows
|
|
63
|
+
* than the server sent: those are built.
|
|
64
|
+
*/
|
|
65
|
+
place(anchor: Node): Node | null;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The installed claimer, or nothing.
|
|
69
|
+
*
|
|
70
|
+
* A holder rather than an exported binding, so that every reader sees the
|
|
71
|
+
* same value however the module is bundled.
|
|
72
|
+
*/
|
|
73
|
+
export declare const hydration: {
|
|
74
|
+
current: Claimer | null;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* The first child of `node`, stepping over a dynamic child's content.
|
|
78
|
+
*
|
|
79
|
+
* Emitted by the compiler in place of `.firstChild` for a build that can
|
|
80
|
+
* hydrate. `.firstChild` would walk into the content of a dynamic child,
|
|
81
|
+
* because the content has a length the template does not.
|
|
82
|
+
*/
|
|
83
|
+
export declare function first(node: Node): Node;
|
|
84
|
+
/** The next sibling of `node`, stepping over a dynamic child's content. */
|
|
85
|
+
export declare function next(node: Node): Node;
|
|
86
|
+
//# sourceMappingURL=claim.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"claim.d.ts","sourceRoot":"","sources":["../src/claim.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,yDAAyD;AACzD,MAAM,MAAM,OAAO,GAAG;IACpB,mDAAmD;IACnD,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;IAC5B,gEAAgE;IAChE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,gCAAgC;AAChC,MAAM,MAAM,MAAM,GAAG;IACnB,mEAAmE;IACnE,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IAClB,wCAAwC;IACxC,GAAG,EAAE,IAAI,GAAG,IAAI,CAAC;CAClB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,OAAO,GAAG;IACpB,kDAAkD;IAClD,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAC1B,6DAA6D;IAC7D,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAC;IAChC;;;;;OAKG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACvE,kEAAkE;IAClE,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,OAAO,GAAG,IAAI,CAAC;IACzD,uEAAuE;IACvE,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5C,2EAA2E;IAC3E,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB;;;;;;;;OAQG;IACH,KAAK,CAAC,MAAM,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;CAClC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,EAAE;IAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;CAAsB,CAAC;AAExE;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAItC;AAED,2EAA2E;AAC3E,wBAAgB,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAIrC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
applyChild,
|
|
3
|
+
insert
|
|
4
|
+
} from "./dev-chunk-ADHDPKZW.js";
|
|
5
|
+
|
|
6
|
+
// packages/dom/src/render.ts
|
|
7
|
+
import { createRoot, onCleanup, untrack } from "@firsthandjs/core";
|
|
8
|
+
function render(view, container = document.body) {
|
|
9
|
+
return mount(view, container, null);
|
|
10
|
+
}
|
|
11
|
+
function mount(view, container, around) {
|
|
12
|
+
let dispose;
|
|
13
|
+
createRoot((stop) => {
|
|
14
|
+
dispose = stop;
|
|
15
|
+
const run = () => {
|
|
16
|
+
attach(container, untrack(view), around !== null);
|
|
17
|
+
};
|
|
18
|
+
if (around === null) {
|
|
19
|
+
run();
|
|
20
|
+
} else {
|
|
21
|
+
around(run);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return dispose;
|
|
25
|
+
}
|
|
26
|
+
function attach(container, result, adopting) {
|
|
27
|
+
if (typeof result === "function") {
|
|
28
|
+
insert(container, result);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let slot = null;
|
|
32
|
+
if (adopting) {
|
|
33
|
+
const children = [...container.childNodes];
|
|
34
|
+
slot = children.length === 1 ? children[0] : children;
|
|
35
|
+
}
|
|
36
|
+
slot = applyChild(container, null, slot, result);
|
|
37
|
+
onCleanup(() => {
|
|
38
|
+
applyChild(container, null, slot, null);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export {
|
|
43
|
+
render,
|
|
44
|
+
mount
|
|
45
|
+
};
|
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
// packages/dom/src/dev.ts
|
|
2
|
+
function devWarn(message) {
|
|
3
|
+
console.warn(`[firsthand] ${message}`);
|
|
4
|
+
}
|
|
5
|
+
var seen = /* @__PURE__ */ new Set();
|
|
6
|
+
function devWarnOnce(key, message) {
|
|
7
|
+
if (!seen.has(key)) {
|
|
8
|
+
seen.add(key);
|
|
9
|
+
devWarn(message);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function devWarnRenderedObject(value) {
|
|
13
|
+
const cellish = "peek" in value && typeof value.peek === "function" && "value" in value;
|
|
14
|
+
devWarnOnce(
|
|
15
|
+
cellish ? "rendered-cell" : "rendered-object",
|
|
16
|
+
cellish ? 'A signal or computed was rendered directly, so the page shows "[object Object]". Read it instead: {count.value} rather than {count}.' : `An object was rendered as text, so the page shows "${String(value)}". Render a string, a number or a node.`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
function hook() {
|
|
20
|
+
const installed = globalThis.__FIRSTHAND_DEVTOOLS__;
|
|
21
|
+
return installed !== void 0 && installed.attached ? installed : void 0;
|
|
22
|
+
}
|
|
23
|
+
function devPart(node, property) {
|
|
24
|
+
hook()?.part(node, property);
|
|
25
|
+
}
|
|
26
|
+
function devComponent(owner, name) {
|
|
27
|
+
hook()?.component(owner, name);
|
|
28
|
+
}
|
|
29
|
+
function label(value, kind, name) {
|
|
30
|
+
if (typeof value === "object" && value !== null) {
|
|
31
|
+
hook()?.label(value, kind, name);
|
|
32
|
+
}
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
35
|
+
var QUIET = 20;
|
|
36
|
+
function devRan(store2) {
|
|
37
|
+
if (store2.busy === true) {
|
|
38
|
+
store2.busy = false;
|
|
39
|
+
store2.quiet = 0;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const quiet = (store2.quiet ?? 0) + 1;
|
|
43
|
+
store2.quiet = quiet;
|
|
44
|
+
if (quiet !== QUIET) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
devWarnOnce(
|
|
48
|
+
`quiet-run:${store2.name}`,
|
|
49
|
+
`<${store2.name}> ran ${String(QUIET)} times and wrote nothing.
|
|
50
|
+
Something it reads in a statement changes more often than what it shows. Move that read into the markup, where it is a part of its own, or move the derivation into a computed in the setup.`
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
function devHandedNewFunction(store2, value) {
|
|
54
|
+
if (typeof value !== "function") {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
devWarnOnce(
|
|
58
|
+
`new-function:${store2.name}`,
|
|
59
|
+
`<${store2.name}> hands a child a new function on every run, so that child runs again whenever this one does.
|
|
60
|
+
If the handler does not depend on the run, define it in the setup.`
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
function devHydrationMismatch(node, html) {
|
|
64
|
+
const template = document.createElement("template");
|
|
65
|
+
template.innerHTML = html;
|
|
66
|
+
const expected = template.content.firstElementChild;
|
|
67
|
+
if (expected === null) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
for (const attribute of expected.attributes) {
|
|
71
|
+
const found = node.getAttribute(attribute.name);
|
|
72
|
+
if (found !== attribute.value) {
|
|
73
|
+
devWarn(
|
|
74
|
+
`Hydration found <${node.tagName.toLowerCase()} ${attribute.name}="${found ?? ""}"> where this render describes "${attribute.value}". The markup is kept as the server sent it, because static markup is never written again. Render the same thing on both sides, or render this part in the browser only.`
|
|
75
|
+
);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// packages/dom/src/claim.ts
|
|
82
|
+
var hydration = { current: null };
|
|
83
|
+
function first(node) {
|
|
84
|
+
const child = node.firstChild;
|
|
85
|
+
const claimer = hydration.current;
|
|
86
|
+
return claimer === null ? child : claimer.step(child);
|
|
87
|
+
}
|
|
88
|
+
function next(node) {
|
|
89
|
+
const sibling = node.nextSibling;
|
|
90
|
+
const claimer = hydration.current;
|
|
91
|
+
return claimer === null ? sibling : claimer.step(sibling);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// packages/dom/src/insert.ts
|
|
95
|
+
import {
|
|
96
|
+
bind,
|
|
97
|
+
createOwner,
|
|
98
|
+
signal,
|
|
99
|
+
disposeOwner,
|
|
100
|
+
getOwner,
|
|
101
|
+
onCleanup,
|
|
102
|
+
runWithOwner,
|
|
103
|
+
setOwner
|
|
104
|
+
} from "@firsthandjs/core";
|
|
105
|
+
var discarding = 0;
|
|
106
|
+
function discard(body) {
|
|
107
|
+
discarding++;
|
|
108
|
+
try {
|
|
109
|
+
body();
|
|
110
|
+
} finally {
|
|
111
|
+
discarding--;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
var TEXT_NODE = 3;
|
|
115
|
+
function isNode(value) {
|
|
116
|
+
return typeof value.nodeType === "number";
|
|
117
|
+
}
|
|
118
|
+
var PART = /* @__PURE__ */ Symbol("firsthand.part");
|
|
119
|
+
var FLAT = /* @__PURE__ */ Symbol("firsthand.flat");
|
|
120
|
+
var PENDING = /* @__PURE__ */ Symbol("firsthand.pending");
|
|
121
|
+
var mounted = /* @__PURE__ */ new WeakSet();
|
|
122
|
+
function part(thunk) {
|
|
123
|
+
return { [PART]: true, anchor: document.createTextNode(""), thunk, owner: getOwner() };
|
|
124
|
+
}
|
|
125
|
+
function isDynamicChild(value) {
|
|
126
|
+
return PART in value;
|
|
127
|
+
}
|
|
128
|
+
function store(name = "") {
|
|
129
|
+
return { slots: [], owner: getOwner(), generation: 0, name };
|
|
130
|
+
}
|
|
131
|
+
function wrote(store2) {
|
|
132
|
+
store2.busy = true;
|
|
133
|
+
}
|
|
134
|
+
function site(store2, index) {
|
|
135
|
+
const existing = store2.slots[index];
|
|
136
|
+
if (existing !== void 0) {
|
|
137
|
+
existing.seen = store2.generation;
|
|
138
|
+
return existing;
|
|
139
|
+
}
|
|
140
|
+
const slot = { seen: store2.generation };
|
|
141
|
+
store2.slots[index] = slot;
|
|
142
|
+
return slot;
|
|
143
|
+
}
|
|
144
|
+
function open(store2, slot) {
|
|
145
|
+
const owner = createOwner(store2.owner);
|
|
146
|
+
slot.owner = owner;
|
|
147
|
+
return setOwner(owner);
|
|
148
|
+
}
|
|
149
|
+
function close(previous) {
|
|
150
|
+
setOwner(previous);
|
|
151
|
+
}
|
|
152
|
+
function ran(store2, value) {
|
|
153
|
+
devRan(store2);
|
|
154
|
+
const generation = store2.generation;
|
|
155
|
+
const slots = store2.slots;
|
|
156
|
+
for (let i = 0; i < slots.length; i++) {
|
|
157
|
+
const slot = slots[i];
|
|
158
|
+
if (slot === void 0 || slot.seen === generation) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (slot.owner !== void 0) {
|
|
162
|
+
disposeOwner(slot.owner);
|
|
163
|
+
}
|
|
164
|
+
slots[i] = void 0;
|
|
165
|
+
}
|
|
166
|
+
store2.generation = generation + 1;
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
169
|
+
function cell(store2, index, value) {
|
|
170
|
+
const slot = site(store2, index);
|
|
171
|
+
const existing = slot.cell;
|
|
172
|
+
if (existing === void 0) {
|
|
173
|
+
const made = signal(value);
|
|
174
|
+
slot.cell = made;
|
|
175
|
+
return made;
|
|
176
|
+
}
|
|
177
|
+
if (existing.peek() !== value) {
|
|
178
|
+
devHandedNewFunction(store2, value);
|
|
179
|
+
wrote(store2);
|
|
180
|
+
existing.value = value;
|
|
181
|
+
}
|
|
182
|
+
return existing;
|
|
183
|
+
}
|
|
184
|
+
function writeChild(store2, index, parent, marker, value) {
|
|
185
|
+
const slot = site(store2, index);
|
|
186
|
+
if (slot.node === void 0 && hydration.current !== null) {
|
|
187
|
+
const claimed = hydration.current.claim(parent, marker);
|
|
188
|
+
if (claimed !== null) {
|
|
189
|
+
if (typeof value === "object" && value !== null && isDynamicChild(value)) {
|
|
190
|
+
slot.last = value;
|
|
191
|
+
hydration.current.keep(slot, parent, value.anchor, claimed);
|
|
192
|
+
runWithOwner(value.owner, () => {
|
|
193
|
+
insert(parent, value.thunk, value.anchor);
|
|
194
|
+
});
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
slot.node = claimed.nodes;
|
|
198
|
+
slot.text = claimed.text;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const type = typeof value;
|
|
202
|
+
if (type === "string" || type === "number") {
|
|
203
|
+
const text = String(value);
|
|
204
|
+
if (text === slot.text) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
wrote(store2);
|
|
208
|
+
slot.text = text;
|
|
209
|
+
slot.node = applyChild(parent, marker, slot.node ?? null, text);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
slot.text = void 0;
|
|
213
|
+
if (value === slot.last) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
wrote(store2);
|
|
217
|
+
slot.last = value;
|
|
218
|
+
slot.node = applyChild(parent, marker, slot.node ?? null, value);
|
|
219
|
+
}
|
|
220
|
+
function insert(parent, value, marker = null, seed, report) {
|
|
221
|
+
if (typeof value !== "function") {
|
|
222
|
+
applyChild(parent, marker, null, value);
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
let current = null;
|
|
226
|
+
let written;
|
|
227
|
+
const claimed = seed !== void 0 ? seed : hydration.current === null ? null : hydration.current.claim(parent, marker);
|
|
228
|
+
let adopting = claimed !== null;
|
|
229
|
+
if (claimed !== null) {
|
|
230
|
+
current = claimed.nodes;
|
|
231
|
+
written = claimed.text;
|
|
232
|
+
}
|
|
233
|
+
const body = () => {
|
|
234
|
+
run();
|
|
235
|
+
report?.(nodesOf(current, marker));
|
|
236
|
+
};
|
|
237
|
+
const run = () => {
|
|
238
|
+
const next2 = value();
|
|
239
|
+
const type = typeof next2;
|
|
240
|
+
if (type === "string" || type === "number") {
|
|
241
|
+
const text = String(next2);
|
|
242
|
+
if (text !== written) {
|
|
243
|
+
written = text;
|
|
244
|
+
current = applyChild(parent, marker, current, text);
|
|
245
|
+
}
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
written = void 0;
|
|
249
|
+
if (type === "function") {
|
|
250
|
+
if (adopting) {
|
|
251
|
+
current = null;
|
|
252
|
+
insert(parent, next2, marker, claimed);
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
current = clear(current);
|
|
256
|
+
insert(parent, next2, marker, null);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
current = applyChild(parent, marker, current, next2);
|
|
260
|
+
};
|
|
261
|
+
if (claimed === null) {
|
|
262
|
+
bind(body);
|
|
263
|
+
} else {
|
|
264
|
+
hydration.current.within(claimed.region, () => {
|
|
265
|
+
bind(body);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
adopting = false;
|
|
269
|
+
onCleanup(() => {
|
|
270
|
+
current = discarding > 0 ? null : clear(current);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
function nodesOf(current, anchor) {
|
|
274
|
+
const nodes = current === null ? [] : Array.isArray(current) ? [...current] : [current];
|
|
275
|
+
nodes.push(anchor);
|
|
276
|
+
return nodes;
|
|
277
|
+
}
|
|
278
|
+
function applyChild(parent, marker, current, value) {
|
|
279
|
+
const type = typeof value;
|
|
280
|
+
if (value == null || type === "boolean") {
|
|
281
|
+
devPart(parent, "text");
|
|
282
|
+
return clearIn(parent, marker, current);
|
|
283
|
+
}
|
|
284
|
+
if (type === "string" || type === "number") {
|
|
285
|
+
devPart(parent, "text");
|
|
286
|
+
const text = String(value);
|
|
287
|
+
if (current !== null && !Array.isArray(current) && current.nodeType === TEXT_NODE) {
|
|
288
|
+
current.data = text;
|
|
289
|
+
return current;
|
|
290
|
+
}
|
|
291
|
+
return single(parent, marker, current, document.createTextNode(text));
|
|
292
|
+
}
|
|
293
|
+
if (type === "function") {
|
|
294
|
+
return applyChild(parent, marker, current, value());
|
|
295
|
+
}
|
|
296
|
+
if (Array.isArray(value)) {
|
|
297
|
+
if (FLAT in value) {
|
|
298
|
+
const rows = value;
|
|
299
|
+
if (rows.length === 0) {
|
|
300
|
+
return clearIn(parent, marker, current);
|
|
301
|
+
}
|
|
302
|
+
reconcile(
|
|
303
|
+
parent,
|
|
304
|
+
marker,
|
|
305
|
+
current === null ? [] : Array.isArray(current) ? current : [current],
|
|
306
|
+
rows
|
|
307
|
+
);
|
|
308
|
+
value[PENDING]?.(parent);
|
|
309
|
+
return rows;
|
|
310
|
+
}
|
|
311
|
+
const next2 = [];
|
|
312
|
+
const dynamic = [];
|
|
313
|
+
flatten(value, next2, dynamic);
|
|
314
|
+
if (next2.length === 0) {
|
|
315
|
+
return clearIn(parent, marker, current);
|
|
316
|
+
}
|
|
317
|
+
reconcile(
|
|
318
|
+
parent,
|
|
319
|
+
marker,
|
|
320
|
+
current === null ? [] : Array.isArray(current) ? current : [current],
|
|
321
|
+
next2
|
|
322
|
+
);
|
|
323
|
+
for (let i = 0; i < dynamic.length; i++) {
|
|
324
|
+
bindPart(dynamic[i], parent);
|
|
325
|
+
}
|
|
326
|
+
return next2;
|
|
327
|
+
}
|
|
328
|
+
if (isDynamicChild(value)) {
|
|
329
|
+
return applyChild(parent, marker, current, [value]);
|
|
330
|
+
}
|
|
331
|
+
if (isNode(value)) {
|
|
332
|
+
return single(parent, marker, current, value);
|
|
333
|
+
}
|
|
334
|
+
devWarnRenderedObject(value);
|
|
335
|
+
return applyChild(parent, marker, current, String(value));
|
|
336
|
+
}
|
|
337
|
+
function bindPart(child, parent, report) {
|
|
338
|
+
if (mounted.has(child)) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
mounted.add(child);
|
|
342
|
+
runWithOwner(child.owner ?? getOwner(), () => {
|
|
343
|
+
insert(parent, child.thunk, child.anchor, void 0, report);
|
|
344
|
+
onCleanup(() => {
|
|
345
|
+
mounted.delete(child);
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
function flatten(value, out, dynamic) {
|
|
350
|
+
for (let i = 0; i < value.length; i++) {
|
|
351
|
+
let item = value[i];
|
|
352
|
+
if (typeof item === "object" && item !== null && isDynamicChild(item)) {
|
|
353
|
+
out.push(item.anchor);
|
|
354
|
+
dynamic.push(item);
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
while (typeof item === "function") {
|
|
358
|
+
item = item();
|
|
359
|
+
}
|
|
360
|
+
if (item == null || typeof item === "boolean") {
|
|
361
|
+
continue;
|
|
362
|
+
}
|
|
363
|
+
if (Array.isArray(item)) {
|
|
364
|
+
flatten(item, out, dynamic);
|
|
365
|
+
} else if (typeof item === "object" && isNode(item)) {
|
|
366
|
+
out.push(item);
|
|
367
|
+
} else {
|
|
368
|
+
out.push(document.createTextNode(String(item)));
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
function detach(node) {
|
|
373
|
+
const owner = node.parentNode;
|
|
374
|
+
if (owner !== null) {
|
|
375
|
+
owner.removeChild(node);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
function clearIn(parent, marker, current) {
|
|
379
|
+
if (marker === null && Array.isArray(current) && current.length > 1 && parent.childNodes.length === current.length) {
|
|
380
|
+
parent.textContent = "";
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
return clear(current);
|
|
384
|
+
}
|
|
385
|
+
function clear(current) {
|
|
386
|
+
if (current !== null) {
|
|
387
|
+
if (Array.isArray(current)) {
|
|
388
|
+
for (let i = 0; i < current.length; i++) {
|
|
389
|
+
detach(current[i]);
|
|
390
|
+
}
|
|
391
|
+
} else {
|
|
392
|
+
detach(current);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
function single(parent, marker, current, node) {
|
|
398
|
+
if (current === node) {
|
|
399
|
+
return node;
|
|
400
|
+
}
|
|
401
|
+
if (current !== null && !Array.isArray(current)) {
|
|
402
|
+
parent.replaceChild(node, current);
|
|
403
|
+
return node;
|
|
404
|
+
}
|
|
405
|
+
clear(current);
|
|
406
|
+
parent.insertBefore(node, marker);
|
|
407
|
+
return node;
|
|
408
|
+
}
|
|
409
|
+
function reconcile(parent, marker, a, b) {
|
|
410
|
+
let aStart = 0;
|
|
411
|
+
let bStart = 0;
|
|
412
|
+
let aEnd = a.length - 1;
|
|
413
|
+
let bEnd = b.length - 1;
|
|
414
|
+
while (aStart <= aEnd && bStart <= bEnd && a[aStart] === b[bStart]) {
|
|
415
|
+
aStart++;
|
|
416
|
+
bStart++;
|
|
417
|
+
}
|
|
418
|
+
while (aStart <= aEnd && bStart <= bEnd && a[aEnd] === b[bEnd]) {
|
|
419
|
+
aEnd--;
|
|
420
|
+
bEnd--;
|
|
421
|
+
}
|
|
422
|
+
const after = bEnd + 1 < b.length ? b[bEnd + 1] : marker;
|
|
423
|
+
if (aStart > aEnd) {
|
|
424
|
+
for (let i = bStart; i <= bEnd; i++) {
|
|
425
|
+
parent.insertBefore(b[i], after);
|
|
426
|
+
}
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (bStart > bEnd) {
|
|
430
|
+
for (let i = aStart; i <= aEnd; i++) {
|
|
431
|
+
parent.removeChild(a[i]);
|
|
432
|
+
}
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
const oldIndex = /* @__PURE__ */ new Map();
|
|
436
|
+
for (let i = aStart; i <= aEnd; i++) {
|
|
437
|
+
oldIndex.set(a[i], i);
|
|
438
|
+
}
|
|
439
|
+
const middle = bEnd - bStart + 1;
|
|
440
|
+
const sources = new Int32Array(middle).fill(-1);
|
|
441
|
+
for (let j = 0; j < middle; j++) {
|
|
442
|
+
const node = b[bStart + j];
|
|
443
|
+
const found = oldIndex.get(node);
|
|
444
|
+
if (found !== void 0) {
|
|
445
|
+
sources[j] = found;
|
|
446
|
+
oldIndex.delete(node);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
for (const node of oldIndex.keys()) {
|
|
450
|
+
parent.removeChild(node);
|
|
451
|
+
}
|
|
452
|
+
const keep = longestIncreasing(sources);
|
|
453
|
+
let k = keep.length - 1;
|
|
454
|
+
let anchor = after;
|
|
455
|
+
for (let j = middle - 1; j >= 0; j--) {
|
|
456
|
+
const node = b[bStart + j];
|
|
457
|
+
if (k >= 0 && keep[k] === j) {
|
|
458
|
+
k--;
|
|
459
|
+
} else {
|
|
460
|
+
parent.insertBefore(node, anchor);
|
|
461
|
+
}
|
|
462
|
+
anchor = node;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
function longestIncreasing(sources) {
|
|
466
|
+
const length = sources.length;
|
|
467
|
+
const predecessor = new Int32Array(length).fill(-1);
|
|
468
|
+
const tails = [];
|
|
469
|
+
for (let i = 0; i < length; i++) {
|
|
470
|
+
const value = sources[i];
|
|
471
|
+
if (value === -1) {
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
let low = 0;
|
|
475
|
+
let high = tails.length;
|
|
476
|
+
while (low < high) {
|
|
477
|
+
const mid = low + high >> 1;
|
|
478
|
+
if (sources[tails[mid]] < value) {
|
|
479
|
+
low = mid + 1;
|
|
480
|
+
} else {
|
|
481
|
+
high = mid;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
if (low > 0) {
|
|
485
|
+
predecessor[i] = tails[low - 1];
|
|
486
|
+
}
|
|
487
|
+
tails[low] = i;
|
|
488
|
+
}
|
|
489
|
+
const result = [];
|
|
490
|
+
let cursor = tails.length > 0 ? tails[tails.length - 1] : -1;
|
|
491
|
+
while (cursor !== -1) {
|
|
492
|
+
result.push(cursor);
|
|
493
|
+
cursor = predecessor[cursor];
|
|
494
|
+
}
|
|
495
|
+
return result.reverse();
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
export {
|
|
499
|
+
devWarn,
|
|
500
|
+
devWarnOnce,
|
|
501
|
+
devPart,
|
|
502
|
+
devComponent,
|
|
503
|
+
label,
|
|
504
|
+
devHydrationMismatch,
|
|
505
|
+
hydration,
|
|
506
|
+
first,
|
|
507
|
+
next,
|
|
508
|
+
discard,
|
|
509
|
+
FLAT,
|
|
510
|
+
PENDING,
|
|
511
|
+
part,
|
|
512
|
+
isDynamicChild,
|
|
513
|
+
store,
|
|
514
|
+
wrote,
|
|
515
|
+
site,
|
|
516
|
+
open,
|
|
517
|
+
close,
|
|
518
|
+
ran,
|
|
519
|
+
cell,
|
|
520
|
+
writeChild,
|
|
521
|
+
insert,
|
|
522
|
+
applyChild,
|
|
523
|
+
bindPart,
|
|
524
|
+
reconcile
|
|
525
|
+
};
|