@krate/runtime 0.5.0-beta.3 → 0.5.0-rc.10

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.
Files changed (219) hide show
  1. package/dist/action-context.js +1 -1
  2. package/dist/actions.d.ts +7 -0
  3. package/dist/actions.js +34 -10
  4. package/dist/after.d.ts +28 -0
  5. package/dist/after.js +48 -0
  6. package/dist/assets-static.d.ts +10 -1
  7. package/dist/assets-static.js +10 -2
  8. package/dist/base-path.d.ts +7 -0
  9. package/dist/base-path.js +20 -0
  10. package/dist/boundary.js +1 -1
  11. package/dist/builtin-tags.d.ts +12 -0
  12. package/dist/builtin-tags.js +42 -0
  13. package/dist/cache-adapter.js +1 -1
  14. package/dist/cache-scope.d.ts +8 -0
  15. package/dist/cache-scope.js +14 -1
  16. package/dist/cloudflare-workers.d.ts +2 -0
  17. package/dist/cloudflare-workers.js +27 -0
  18. package/dist/context.d.ts +5 -0
  19. package/dist/context.js +28 -17
  20. package/dist/dev-overlay.d.ts +54 -3
  21. package/dist/dev-overlay.js +496 -91
  22. package/dist/dom.d.ts +4 -0
  23. package/dist/dom.js +62 -16
  24. package/dist/effects.js +43 -10
  25. package/dist/events.d.ts +2 -0
  26. package/dist/events.js +18 -0
  27. package/dist/flight-props.d.ts +7 -0
  28. package/dist/flight-props.js +105 -0
  29. package/dist/handler-html.js +4 -4
  30. package/dist/handler-routing.d.ts +2 -23
  31. package/dist/handler-routing.js +9 -190
  32. package/dist/handler-segments.d.ts +6 -0
  33. package/dist/handler-segments.js +18 -4
  34. package/dist/head-tags.d.ts +9 -0
  35. package/dist/head-tags.js +93 -6
  36. package/dist/highlight-bind.js +1 -1
  37. package/dist/highlight.d.ts +3 -2
  38. package/dist/highlight.js +17 -12
  39. package/dist/hints.d.ts +25 -2
  40. package/dist/hints.js +147 -74
  41. package/dist/index.d.ts +2 -0
  42. package/dist/index.js +3 -0
  43. package/dist/island-swap.d.ts +47 -0
  44. package/dist/island-swap.js +635 -0
  45. package/dist/jsx-dev-runtime.d.ts +1 -1
  46. package/dist/jsx-types.d.ts +99 -3
  47. package/dist/krate-core.js +1 -1
  48. package/dist/krate-dev.js +407 -80
  49. package/dist/krate-f-actions.js +1 -1
  50. package/dist/krate-f-classes.js +1 -1
  51. package/dist/krate-f-highlight.js +1 -1
  52. package/dist/krate-f-list.js +1 -1
  53. package/dist/krate-f-navigation.js +1 -1
  54. package/dist/krate-f-router-lite.js +1 -1
  55. package/dist/krate-f-router.js +1 -1
  56. package/dist/krate-features.json +455 -0
  57. package/dist/krate-hydrate-lite.js +5 -5
  58. package/dist/krate-hydrate.js +5 -5
  59. package/dist/krate-island-swap.js +1 -0
  60. package/dist/krate-runtime.js +5 -5
  61. package/dist/krate-suspense.js +1 -1
  62. package/dist/list.d.ts +14 -4
  63. package/dist/list.js +30 -23
  64. package/dist/metadata.js +5 -2
  65. package/dist/navigation-react.d.ts +13 -0
  66. package/dist/navigation-react.js +86 -0
  67. package/dist/navigation.d.ts +19 -0
  68. package/dist/navigation.js +35 -0
  69. package/dist/node-server.js +3 -3
  70. package/dist/og.js +1 -1
  71. package/dist/platform.d.ts +52 -0
  72. package/dist/platform.js +57 -0
  73. package/dist/react-compat.d.ts +39 -0
  74. package/dist/react-compat.js +359 -0
  75. package/dist/react-server.d.ts +63 -0
  76. package/dist/react-server.js +125 -0
  77. package/dist/region-wire.d.ts +10 -0
  78. package/dist/region-wire.js +154 -0
  79. package/dist/request-context.js +1 -1
  80. package/dist/request-extras.d.ts +4 -0
  81. package/dist/request-extras.js +51 -0
  82. package/dist/resp.js +1 -1
  83. package/dist/route-source.d.ts +39 -0
  84. package/dist/route-source.js +532 -0
  85. package/dist/router-lite.js +3 -9
  86. package/dist/router.d.ts +1 -1
  87. package/dist/router.js +675 -100
  88. package/dist/server-handler.d.ts +69 -1
  89. package/dist/server-handler.js +515 -96
  90. package/dist/server-renderer.js +16 -7
  91. package/dist/server.d.ts +73 -16
  92. package/dist/server.js +619 -102
  93. package/dist/sha256.js +9 -9
  94. package/dist/signal.js +47 -20
  95. package/dist/site-config.d.ts +15 -0
  96. package/dist/site-config.js +28 -0
  97. package/dist/slot.d.ts +12 -0
  98. package/dist/slot.js +23 -0
  99. package/dist/ssr-core.d.ts +2 -0
  100. package/dist/ssr-core.js +12 -4
  101. package/dist/suspense.js +34 -2
  102. package/dist/testing.d.ts +62 -0
  103. package/dist/testing.js +90 -0
  104. package/dist/use-id.js +1 -1
  105. package/package.json +28 -3
  106. package/dist/action-context.test.d.ts +0 -1
  107. package/dist/action-context.test.js +0 -72
  108. package/dist/actions.test.d.ts +0 -1
  109. package/dist/actions.test.js +0 -477
  110. package/dist/cache-adapter.test.d.ts +0 -1
  111. package/dist/cache-adapter.test.js +0 -244
  112. package/dist/cache.test.d.ts +0 -1
  113. package/dist/cache.test.js +0 -233
  114. package/dist/class-component.test.d.ts +0 -1
  115. package/dist/class-component.test.js +0 -462
  116. package/dist/class-helpers.test.d.ts +0 -1
  117. package/dist/class-helpers.test.js +0 -169
  118. package/dist/context.test.d.ts +0 -1
  119. package/dist/context.test.js +0 -57
  120. package/dist/derived.test.d.ts +0 -1
  121. package/dist/derived.test.js +0 -140
  122. package/dist/dev-overlay.test.d.ts +0 -1
  123. package/dist/dev-overlay.test.js +0 -152
  124. package/dist/discrete.test.d.ts +0 -1
  125. package/dist/discrete.test.js +0 -100
  126. package/dist/dom.test.d.ts +0 -1
  127. package/dist/dom.test.js +0 -31
  128. package/dist/effect-errors.test.d.ts +0 -1
  129. package/dist/effect-errors.test.js +0 -163
  130. package/dist/effects.test.d.ts +0 -1
  131. package/dist/effects.test.js +0 -485
  132. package/dist/events.test.d.ts +0 -1
  133. package/dist/events.test.js +0 -447
  134. package/dist/handler-html.test.d.ts +0 -1
  135. package/dist/handler-html.test.js +0 -256
  136. package/dist/handler-routing.test.d.ts +0 -1
  137. package/dist/handler-routing.test.js +0 -99
  138. package/dist/handler-segments.test.d.ts +0 -1
  139. package/dist/handler-segments.test.js +0 -217
  140. package/dist/head-tags.test.d.ts +0 -1
  141. package/dist/head-tags.test.js +0 -131
  142. package/dist/highlight-bind.test.d.ts +0 -1
  143. package/dist/highlight-bind.test.js +0 -124
  144. package/dist/highlight.test.d.ts +0 -1
  145. package/dist/highlight.test.js +0 -56
  146. package/dist/lanes.test.d.ts +0 -1
  147. package/dist/lanes.test.js +0 -59
  148. package/dist/list.test.d.ts +0 -1
  149. package/dist/list.test.js +0 -344
  150. package/dist/metadata.test.d.ts +0 -1
  151. package/dist/metadata.test.js +0 -167
  152. package/dist/navigation.test.d.ts +0 -1
  153. package/dist/navigation.test.js +0 -130
  154. package/dist/node-server.test.d.ts +0 -1
  155. package/dist/node-server.test.js +0 -492
  156. package/dist/optimistic-lanes.test.d.ts +0 -1
  157. package/dist/optimistic-lanes.test.js +0 -45
  158. package/dist/patterns.test.d.ts +0 -1
  159. package/dist/patterns.test.js +0 -98
  160. package/dist/portal.test.d.ts +0 -1
  161. package/dist/portal.test.js +0 -99
  162. package/dist/react-effects.test.d.ts +0 -1
  163. package/dist/react-effects.test.js +0 -96
  164. package/dist/react-suspense.test.d.ts +0 -1
  165. package/dist/react-suspense.test.js +0 -194
  166. package/dist/react.test.d.ts +0 -1
  167. package/dist/react.test.js +0 -60
  168. package/dist/react19.test.d.ts +0 -1
  169. package/dist/react19.test.js +0 -176
  170. package/dist/reactivity-core.test.d.ts +0 -1
  171. package/dist/reactivity-core.test.js +0 -152
  172. package/dist/reconcile.test.d.ts +0 -1
  173. package/dist/reconcile.test.js +0 -110
  174. package/dist/refs.test.d.ts +0 -1
  175. package/dist/refs.test.js +0 -257
  176. package/dist/router-layout.test.d.ts +0 -1
  177. package/dist/router-layout.test.js +0 -249
  178. package/dist/router-nav.test.d.ts +0 -1
  179. package/dist/router-nav.test.js +0 -464
  180. package/dist/router-slots.test.d.ts +0 -1
  181. package/dist/router-slots.test.js +0 -144
  182. package/dist/router-speculation.test.d.ts +0 -1
  183. package/dist/router-speculation.test.js +0 -25
  184. package/dist/router-styles.test.d.ts +0 -1
  185. package/dist/router-styles.test.js +0 -98
  186. package/dist/router.test.d.ts +0 -1
  187. package/dist/router.test.js +0 -36
  188. package/dist/server-async.test.d.ts +0 -1
  189. package/dist/server-async.test.js +0 -216
  190. package/dist/server-handler.test.d.ts +0 -1
  191. package/dist/server-handler.test.js +0 -535
  192. package/dist/server-highlight.test.d.ts +0 -1
  193. package/dist/server-highlight.test.js +0 -32
  194. package/dist/server-renderer.test.d.ts +0 -1
  195. package/dist/server-renderer.test.js +0 -266
  196. package/dist/server.test.d.ts +0 -1
  197. package/dist/server.test.js +0 -88
  198. package/dist/sha256.test.d.ts +0 -1
  199. package/dist/sha256.test.js +0 -13
  200. package/dist/signal-lanes.test.d.ts +0 -1
  201. package/dist/signal-lanes.test.js +0 -32
  202. package/dist/signal.test.d.ts +0 -1
  203. package/dist/signal.test.js +0 -68
  204. package/dist/slots.test.d.ts +0 -1
  205. package/dist/slots.test.js +0 -169
  206. package/dist/snapshots.test.d.ts +0 -1
  207. package/dist/snapshots.test.js +0 -208
  208. package/dist/ssr-core-behavior.test.d.ts +0 -1
  209. package/dist/ssr-core-behavior.test.js +0 -620
  210. package/dist/ssr-core.test.d.ts +0 -1
  211. package/dist/ssr-core.test.js +0 -324
  212. package/dist/static-memory.test.d.ts +0 -1
  213. package/dist/static-memory.test.js +0 -26
  214. package/dist/storage.test.d.ts +0 -1
  215. package/dist/storage.test.js +0 -46
  216. package/dist/suspense-actions.test.d.ts +0 -1
  217. package/dist/suspense-actions.test.js +0 -72
  218. package/dist/suspense.test.d.ts +0 -1
  219. package/dist/suspense.test.js +0 -518
@@ -1,2 +1,2 @@
1
- var __krate_exports=(()=>{var O=Object.defineProperty;var fe=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var he=Object.prototype.hasOwnProperty;var Te=(e,n)=>{for(var t in n)O(e,t,{get:n[t],enumerable:!0})},we=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of pe(n))!he.call(e,r)&&r!==t&&O(e,r,{get:()=>n[r],enumerable:!(o=fe(n,r))||o.enumerable});return e};var ve=e=>we(O({},"__esModule",{value:!0}),e);var De={};Te(De,{SuspenseSignal:()=>g,__krateBoundary:()=>Be,__krateLazy:()=>Re,__krateLazyPayload:()=>Ne,__krateLazyRun:()=>Me,__krateRead:()=>Oe,__krateTransitionStarter:()=>te,__krateUse:()=>Ce,boundarySlotId:()=>le,connectActionTransitions:()=>ne,connectErrorBoundaries:()=>be,createBoundary:()=>se,createDeferredValue:()=>ce,createExternalStore:()=>de,currentBoundary:()=>ue,getBoundary:()=>q,isInTransition:()=>Z,isSuspenseSignal:()=>D,isThenable:()=>_,noteFallbackShown:()=>m,readValue:()=>Q,registerBoundary:()=>Ae,reportSuspenseError:()=>y,resetBoundaries:()=>Ee,runAsyncTransition:()=>C,setFallbackThrottle:()=>Pe,setLazyChunkImporter:()=>je,setSuspenseErrorHandler:()=>ge,startTransition:()=>xe,suspendOn:()=>$,trackThenable:()=>z,useDeferredValue:()=>Ve,useSyncExternalStore:()=>ze,useTransition:()=>Se,withReplayScope:()=>ke});var w=(...e)=>window.createSignal(...e),R=(...e)=>window.createEffect(...e),F=(...e)=>window.onCleanup(...e),G=(...e)=>window.krateGetOwner(...e),L=(...e)=>window.krateSetOwner(...e);var W=new WeakSet;function _(e){return e!=null&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function z(e){return W.has(e)||(W.add(e),e.status==="fulfilled"||e.status==="rejected")||(e.status="pending",e.then(n=>{e.status==="pending"&&(e.status="fulfilled",e.value=n)},n=>{e.status==="pending"&&(e.status="rejected",e.reason=n)})),e}var g=class{constructor(n){this.thenable=n}};function D(e){return e instanceof g}function A(){}var ye=Symbol.for("krate.context"),S=null;function E(e,n){let t=S;S=e;try{return n()}finally{S=t}}function ke(e,n){return e.i=0,E(e,n)}function Q(e){let n=e;if(n&&(typeof n=="object"||typeof n=="function")&&typeof n.useContext=="function"&&(n.$$typeof===ye||!_(e)))return n.useContext();if(!_(e))return e;let t=e,o=S;if(o){let r=o.i++,i=o.list[r];i!==void 0&&i!==t?(t.then(A,A),t=i):o.list[r]=t}if(z(t),t.status==="fulfilled")return t.value;throw t.status==="rejected"?t.reason:new g(t)}var N=null;function ge(e){N=e}var j=null;function be(e){j=e}function Y(){if(j)return j;let e=globalThis;return typeof e.getOwner=="function"&&typeof e.handleError=="function"?{getOwner:e.getOwner,handleError:e.handleError}:null}function I(){let e=Y();return e?e.getOwner():null}function y(e,n,t){if(N&&N(e,n)===!0)return;let o=t?Y():null;if(o){o.handleError(e,t);return}let r=globalThis;typeof r.__krateReportError=="function"&&r.__krateReportError(e,n?n.anchor:null)===!0||console.error("[krate] uncaught error in suspended work:",e)}var M=class{constructor(){this.count=0;this.error=void 0;this.failed=!1;this.settled=!1;this.signal=null;this.pending=()=>(this.signal||(this.signal=w(!this.settled)),this.signal[0]());this.promise=new Promise((n,t)=>{this.resolve=n,this.reject=t}),this.promise.catch(A)}add(){this.count++}release(){--this.count>0||(this.settled=!0,this.signal?.[1](!1),this.failed?this.reject(this.error):this.resolve())}wait(n){this.add();let t=()=>this.release();n.then(t,t)}},k=null;function Z(){return B()!==null}function C(e,n){let t=n?.report!==!1,o=new M,r=me();o.promise.then(r,r),o.add();let i=k;k=o;let l;try{l=e()}catch(s){return o.failed=!0,o.error=s,k=i,o.release(),t&&y(s,null),o}return k=i,_(l)&&(o.add(),l.then(()=>o.release(),s=>{o.failed=!0,o.error=s,o.release(),t&&y(s,null)})),P=o,queueMicrotask(()=>{P===o&&(P=null),o.release()}),o}var ee=null;function me(){let e=ee??globalThis.__krateBeginAction;return typeof e=="function"?e():A}function ne(e){let n=e??globalThis;e?.__krateBeginAction&&(ee=e.__krateBeginAction),typeof n.setActionTransitionRunner=="function"&&n.setActionTransitionRunner(t=>{let o,r=!1,i,l=C(()=>{try{o=t()}catch(s){throw r=!0,i=s,s}return o},{report:!1});return r?Promise.reject(i):Promise.resolve(o).then(s=>l.promise.then(()=>s))})}var P=null;function B(){return k??P}function xe(e){C(e)}function te(e){let n=0;return t=>{n++,e(!0);let o=C(t),r=()=>{--n===0&&e(!1)};o.promise.then(r,r)}}function Se(){let[e,n]=w(!1);return[e,te(n)]}var oe=300,re=-1/0;function ie(){return typeof performance<"u"?performance.now():Date.now()}function m(){re=ie()}function Pe(e){oe=e}var H=class{constructor(n,t,o,r){this.pending=new Set;this.holds=0;this.scheduled=!1;this.throttle=null;this.id=n,this.anchor=t,this.content=o,this.apply=r}get pendingCount(){return this.pending.size}showingContent(){return this.content}suspend(n,t=!1){if(t&&this.content){B()?.wait(n);return}if(this.pending.has(n))return;this.pending.add(n),this.update();let o=()=>{this.pending.delete(n),this.schedule()};n.then(o,o)}hold(){this.holds++}release(){this.holds>0&&this.holds--,this.schedule()}schedule(){this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{queueMicrotask(()=>{this.scheduled=!1,this.update()})}))}update(){let n=this.pending.size===0&&this.holds===0;if(n!==this.content){if(n){let t=re+oe-ie();if(t>0){this.throttle===null&&(this.throttle=setTimeout(()=>{this.throttle=null,this.update()},t));return}}else m();this.content=n,this.apply(n),n&&V&&V(this)}}},V=null;function se(e,n,t){return new H(e,t?.anchor??null,t?.initialContent??!0,n)}var b=new Map;function le(e){return"s"+e}function q(e){let n=le(e),t=globalThis,o=typeof t.findSlot=="function"?t.findSlot(n):null,r=b.get(e);if(r&&(o===null||r.anchor===o))return r;let i=typeof document<"u"?document.querySelector('template[data-kc="'+n+'"]'):null,l=!i||i.getAttribute("data-kb")!=="c",s=globalThis.krateCondActivity,c=o&&o.nodeType===8?_e(o,i,l):null,p=se(e,h=>{c&&(s&&!h&&s(n,"a"),c(h),s&&h&&s(n,"c"))},{anchor:o,initialContent:l});return!l&&o&&o.isConnected&&m(),b.set(e,p),p}V=e=>{for(let n of b.values())if(n!==e&&!n.showingContent()&&n.anchor&&n.anchor.isConnected){m();return}};function _e(e,n,t){let o="/"+(e.nodeValue||""),r=()=>{for(let d=e.nextSibling;d;d=d.nextSibling)if(d.nodeType===8&&d.nodeValue===o)return d;return null},i=()=>{let d=[],u=r();for(let a=e.nextSibling;a&&a!==u;a=a.nextSibling)d.push(a);return d},l=t?i():[],s=t?[]:i(),c=!1,f=()=>!n||c?[]:(c=!0,Array.from(n.content.childNodes)),p=new Map,h=d=>{let u=e.parentNode;if(!u)return;let a=r();for(let T of d)u.insertBefore(T,a)},x=d=>{for(let u of d)u.parentNode?.removeChild(u)};return d=>{if(d){if(x(s),l.length===0){l=f(),h(l),K();return}for(let u of l){let a=p.get(u);a!==void 0&&(typeof a=="string"?u.nodeValue=a:a[0]===""?u.style.removeProperty("display"):u.style.setProperty("display",a[0],a[1]))}p.clear();return}for(let u of l)if(!p.has(u))if(u.nodeType===1&&u.style){let a=u.style;p.set(u,[a.getPropertyValue("display"),a.getPropertyPriority("display")]),a.setProperty("display","none","important")}else u.nodeType===3&&(p.set(u,u.nodeValue||""),u.nodeValue="");s.length===0&&(s=f()),h(s),K()}}function K(){let e=globalThis.krateRefsEnter;typeof e=="function"&&e()}function Ae(e){b.set(e.id,e)}function Ee(){b.clear()}function $(e,n){let t=B()!==null;e?e.suspend(n,t):t&&B()?.wait(n)}var v=null;function ue(){return v?v.boundary:null}function Be(e,n){let t=e?q(e):null,o={boundary:t,scope:{list:[],i:0},disposers:[]},r=I();t?.hold();let i=()=>{o.scope.i=0;let l=v;v=o;let s=G();try{E(o.scope,n),v=l,L(s),t?.release()}catch(c){v=l,L(s);for(let f of o.disposers.splice(0))f();if(D(c)){c.thenable.then(i,i);return}t?.release(),y(c,t,r)}};i()}function Ce(e){let n=v,t=n?n.boundary:null,o=I(),r=n?n.scope:{list:[],i:0},i=r.i,l=E(r,e),s=r.list.slice(i,r.i),[c,f]=w(l),[p,h]=w(0),x=()=>h(a=>a+1),d=!0,u=R(()=>{p();let a=d?{list:s,i:0}:null;d=!1;try{let T=E(a,e);f(()=>T)}catch(T){if(D(T)){T.thenable.then(x,x),$(t,T.thenable);return}y(T,t,o)}});return n&&n.disposers.push(u),c}function Oe(e){return Q(e)}var U=new Map;function Re(e,n){let t=n?q(n):null,o=I();t?.hold();let r=U.get(e);if(!r){let i=t?t.anchor:null;r=i&&!i.isConnected?Le(i).then(()=>(m(),J(e))):J(e),U.set(e,r)}return r.then(()=>t?.release(),i=>{t?.release(),y(i,t,o)}),r}function Le(e){return e.isConnected||typeof MutationObserver>"u"?Promise.resolve():new Promise(n=>{let t=new MutationObserver(()=>{e.isConnected&&(t.disconnect(),n())});t.observe(document.documentElement,{childList:!0,subtree:!0})})}var X=new WeakMap;function Ne(e){let n=X.get(e);return n||(n=Promise.resolve().then(()=>e()).then(t=>{if(typeof(t&&typeof t=="object"?t.default:void 0)!="function")throw new Error("lazy: the loader did not resolve to a module with a component as its default export (resolve to { default: Component })");return t}),z(n),X.set(e,n)),n}var ae=e=>import(e);function je(e){ae=e}function J(e){try{return Promise.resolve(ae(e))}catch(n){return Promise.reject(n)}}function Me(e){e()}function He(e){setTimeout(e,0)}function ce(e,...n){let t=n.length>0,o,r,i=!1,[l,s]=w(void 0),c=()=>{i=!1,Object.is(o,r)||(r=o,s(()=>o))},f=!0;return R(()=>{if(o=e(),!(f&&(f=!1,r=t?n[0]:o,s(()=>r),!t||Object.is(r,o)))&&!Object.is(o,r)){if(Z()){c();return}i||(i=!0,He(c))}}),l}function Ve(e,...n){return typeof e=="function"?ce(e,...n):e}function de(e,n,t){let o=n();Object.is(o,n())||console.error("[krate] The result of getSnapshot should be cached to avoid an infinite loop");let[r,i]=w(o),l=()=>{let c=n();Object.is(c,o)||(o=c,i(()=>c))},s=e(l);return l(),F(()=>{typeof s=="function"&&s()}),r}function ze(e,n,t){return de(e,n,t)}ne();globalThis.__krateSuspenseHook={current:ue,suspend:(e,n)=>$(e,n)};return ve(De);})();
1
+ var __krate_exports=(()=>{var L=Object.defineProperty;var Te=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var ve=(e,n)=>{for(var t in n)L(e,t,{get:n[t],enumerable:!0})},ke=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of we(n))!ye.call(e,r)&&r!==t&&L(e,r,{get:()=>n[r],enumerable:!(o=Te(n,r))||o.enumerable});return e};var be=e=>ke(L({},"__esModule",{value:!0}),e);var $e={};ve($e,{SuspenseSignal:()=>m,__krateBoundary:()=>Re,__krateLazy:()=>je,__krateLazyPayload:()=>He,__krateLazyRun:()=>ze,__krateRead:()=>Ne,__krateTransitionStarter:()=>ie,__krateUse:()=>Le,boundarySlotId:()=>ce,connectActionTransitions:()=>re,connectErrorBoundaries:()=>Se,createBoundary:()=>ue,createDeferredValue:()=>pe,createExternalStore:()=>he,currentBoundary:()=>de,getBoundary:()=>F,isInTransition:()=>te,isSuspenseSignal:()=>q,isThenable:()=>A,noteFallbackShown:()=>x,readValue:()=>ee,registerBoundary:()=>Ee,reportSuspenseError:()=>k,resetBoundaries:()=>Be,runAsyncTransition:()=>R,setFallbackThrottle:()=>Ce,setLazyChunkImporter:()=>Ve,setSuspenseErrorHandler:()=>xe,startTransition:()=>_e,suspendOn:()=>G,trackThenable:()=>I,useDeferredValue:()=>Ie,useSyncExternalStore:()=>qe,useTransition:()=>Ae,withReplayScope:()=>me});var w=(...e)=>window.createSignal(...e),N=(...e)=>window.createEffect(...e),W=(...e)=>window.onCleanup(...e),K=(...e)=>window.krateGetOwner(...e),j=(...e)=>window.krateSetOwner(...e),U=(...e)=>window.krateOnDispose(...e),M=(...e)=>window.krateCurrentScope(...e);var X=new WeakSet;function A(e){return e!=null&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function"}function I(e){return X.has(e)||(X.add(e),e.status==="fulfilled"||e.status==="rejected")||(e.status="pending",e.then(n=>{e.status==="pending"&&(e.status="fulfilled",e.value=n)},n=>{e.status==="pending"&&(e.status="rejected",e.reason=n)})),e}var m=class{constructor(n){this.thenable=n}};function q(e){return e instanceof m}function C(){}var ge=Symbol.for("krate.context"),P=null;function O(e,n){let t=P;P=e;try{return n()}finally{P=t}}function me(e,n){return e.i=0,O(e,n)}function ee(e){let n=e;if(n&&(typeof n=="object"||typeof n=="function")&&typeof n.useContext=="function"&&(n.$$typeof===ge||!A(e)))return n.useContext();if(!A(e))return e;let t=e,o=P;if(o){let r=o.i++,i=o.list[r];i!==void 0&&i!==t?(t.then(C,C),t=i):o.list[r]=t}if(I(t),t.status==="fulfilled")return t.value;throw t.status==="rejected"?t.reason:new m(t)}var H=null;function xe(e){H=e}var V=null;function Se(e){V=e}function ne(){if(V)return V;let e=globalThis;return typeof e.getOwner=="function"&&typeof e.handleError=="function"?{getOwner:e.getOwner,handleError:e.handleError}:null}function $(){let e=ne();return e?e.getOwner():null}function k(e,n,t){if(H&&H(e,n)===!0)return;let o=t?ne():null;if(o){o.handleError(e,t);return}let r=globalThis;typeof r.__krateReportError=="function"&&r.__krateReportError(e,n?n.anchor:null)===!0||console.error("[krate] uncaught error in suspended work:",e)}var z=class{constructor(){this.count=0;this.error=void 0;this.failed=!1;this.settled=!1;this.signal=null;this.pending=()=>(this.signal||(this.signal=w(!this.settled)),this.signal[0]());this.promise=new Promise((n,t)=>{this.resolve=n,this.reject=t}),this.promise.catch(C)}add(){this.count++}release(){--this.count>0||(this.settled=!0,this.signal?.[1](!1),this.failed?this.reject(this.error):this.resolve())}wait(n){this.add();let t=()=>this.release();n.then(t,t)}},b=null;function te(){return E()!==null}function R(e,n){let t=n?.report!==!1,o=new z,r=Pe();o.promise.then(r,r),o.add();let i=b;b=o;let l;try{l=e()}catch(s){return o.failed=!0,o.error=s,b=i,o.release(),t&&k(s,null),o}return b=i,A(l)&&(o.add(),l.then(()=>o.release(),s=>{o.failed=!0,o.error=s,o.release(),t&&k(s,null)})),_=o,queueMicrotask(()=>{_===o&&(_=null),o.release()}),o}var oe=null;function Pe(){let e=oe??globalThis.__krateBeginAction;return typeof e=="function"?e():C}function re(e){let n=e??globalThis;e?.__krateBeginAction&&(oe=e.__krateBeginAction),typeof n.setActionTransitionRunner=="function"&&n.setActionTransitionRunner(t=>{let o,r=!1,i,l=R(()=>{try{o=t()}catch(s){throw r=!0,i=s,s}return o},{report:!1});return r?Promise.reject(i):Promise.resolve(o).then(s=>l.promise.then(()=>s))})}var _=null;function E(){return b??_}function _e(e){R(e)}function ie(e){let n=0;return t=>{n++,e(!0);let o=R(t),r=()=>{--n===0&&e(!1)};o.promise.then(r,r)}}function Ae(){let[e,n]=w(!1);return[e,ie(n)]}var se=300,le=-1/0;function ae(){return typeof performance<"u"?performance.now():Date.now()}function x(){le=ae()}function Ce(e){se=e}var B=class{constructor(n,t,o,r){this.pending=new Set;this.holds=0;this.scheduled=!1;this.route=M();this.dead=!1;this.throttle=null;this.id=n,this.anchor=t,this.content=o,this.apply=r}get pendingCount(){return this.pending.size}showingContent(){return this.content}suspend(n,t=!1){if(t&&this.content){E()?.wait(n);return}if(this.pending.has(n))return;this.pending.add(n),this.update();let o=()=>{this.pending.delete(n),this.schedule()};n.then(o,o)}hold(){this.holds++}release(){this.holds>0&&this.holds--,this.schedule()}schedule(){this.scheduled||(this.scheduled=!0,queueMicrotask(()=>{queueMicrotask(()=>{this.scheduled=!1,this.update()})}))}update(){if(this.dead)return;let n=this.pending.size===0&&this.holds===0;if(n!==this.content){if(n){let t=le+se-ae();if(t>0){this.throttle===null&&(this.throttle=setTimeout(()=>{this.throttle=null,this.update()},t));return}}else x();this.content=n,this.apply(n),n&&D&&D(this)}}},D=null;function ue(e,n,t){return new B(e,t?.anchor??null,t?.initialContent??!0,n)}var v=new Map;function ce(e){return"s"+e}function F(e){let n=ce(e),t=globalThis,o=typeof t.findSlot=="function"?t.findSlot(n):null,r=v.get(e);if(r&&(o===null||r.anchor===o))return r;let i=typeof document<"u"?document.querySelector('template[data-kc="'+n+'"]'):null,l=!i||i.getAttribute("data-kb")!=="c",s=globalThis.krateCondActivity,c=o&&o.nodeType===8?Oe(o,i,l):null,p=ue(e,h=>{c&&(s&&!h&&s(n,"a"),c(h),s&&h&&s(n,"c"))},{anchor:o,initialContent:l});return!l&&o&&o.isConnected&&x(),v.set(e,p),p}D=e=>{for(let n of v.values())if(n!==e&&!n.showingContent()&&n.anchor&&n.anchor.isConnected){x();return}};function Oe(e,n,t){let o="/"+(e.nodeValue||""),r=()=>{for(let d=e.nextSibling;d;d=d.nextSibling)if(d.nodeType===8&&d.nodeValue===o)return d;return null},i=()=>{let d=[],a=r();for(let u=e.nextSibling;u&&u!==a;u=u.nextSibling)d.push(u);return d},l=t?i():[],s=t?[]:i(),c=!1,f=()=>!n||c?[]:(c=!0,Array.from(n.content.childNodes)),p=new Map,h=d=>{let a=e.parentNode;if(!a)return;let u=r();for(let T of d)a.insertBefore(T,u)},S=d=>{for(let a of d)a.parentNode?.removeChild(a)};return d=>{if(d){if(S(s),l.length===0){l=f(),h(l),J();return}for(let a of l){let u=p.get(a);u!==void 0&&(typeof u=="string"?a.nodeValue=u:u[0]===""?a.style.removeProperty("display"):a.style.setProperty("display",u[0],u[1]))}p.clear();return}for(let a of l)if(!p.has(a))if(a.nodeType===1&&a.style){let u=a.style;p.set(a,[u.getPropertyValue("display"),u.getPropertyPriority("display")]),u.setProperty("display","none","important")}else a.nodeType===3&&(p.set(a,a.nodeValue||""),a.nodeValue="");s.length===0&&(s=f()),h(s),J()}}function J(){let e=globalThis.krateRefsEnter;typeof e=="function"&&e()}function Ee(e){v.set(e.id,e)}function Be(){v.clear()}var g=new Set;U(e=>{for(let n of g)(e===null||e(n.route))&&(n.dead=!0);for(let[n,t]of Array.from(v))t instanceof B&&(e===null||e(t.route))&&(t.dead=!0,v.delete(n))});function G(e,n){let t=E()!==null;e?e.suspend(n,t):t&&E()?.wait(n)}var y=null;function de(){return y?y.boundary:null}function Re(e,n){let t=e?F(e):null,o={boundary:t,scope:{list:[],i:0},disposers:[],route:M(),dead:!1},r=$();t?.hold();let i=()=>{if(o.dead){g.delete(o);return}o.scope.i=0;let l=y;y=o;let s=K();try{O(o.scope,n),y=l,j(s),g.delete(o),t?.release()}catch(c){y=l,j(s);for(let f of o.disposers.splice(0))f();if(q(c)){g.add(o),c.thenable.then(i,i);return}g.delete(o),t?.release(),k(c,t,r)}};i()}function Le(e){let n=y,t=n?n.boundary:null,o=$(),r=n?n.scope:{list:[],i:0},i=r.i,l=O(r,e),s=r.list.slice(i,r.i),[c,f]=w(l),[p,h]=w(0),S=()=>h(u=>u+1),d=!0,a=N(()=>{p();let u=d?{list:s,i:0}:null;d=!1;try{let T=O(u,e);f(()=>T)}catch(T){if(q(T)){T.thenable.then(S,S),G(t,T.thenable);return}k(T,t,o)}});return n&&n.disposers.push(a),c}function Ne(e){return ee(e)}var Q=new Map;function je(e,n){let t=n?F(n):null,o=$();t?.hold();let r=Q.get(e);if(!r){let i=t?t.anchor:null;r=i&&!i.isConnected?Me(i).then(()=>(x(),Z(e))):Z(e),Q.set(e,r)}return r.then(()=>t?.release(),i=>{t?.release(),k(i,t,o)}),r}function Me(e){return e.isConnected||typeof MutationObserver>"u"?Promise.resolve():new Promise(n=>{let t=new MutationObserver(()=>{e.isConnected&&(t.disconnect(),n())});t.observe(document.documentElement,{childList:!0,subtree:!0})})}var Y=new WeakMap;function He(e){let n=Y.get(e);return n||(n=Promise.resolve().then(()=>e()).then(t=>{if(typeof(t&&typeof t=="object"?t.default:void 0)!="function")throw new Error("lazy: the loader did not resolve to a module with a component as its default export (resolve to { default: Component })");return t}),I(n),Y.set(e,n)),n}var fe=e=>import(e);function Ve(e){fe=e}function Z(e){try{return Promise.resolve(fe(e))}catch(n){return Promise.reject(n)}}function ze(e){e()}function De(e){setTimeout(e,0)}function pe(e,...n){let t=n.length>0,o,r,i=!1,[l,s]=w(void 0),c=()=>{i=!1,Object.is(o,r)||(r=o,s(()=>o))},f=!0;return N(()=>{if(o=e(),!(f&&(f=!1,r=t?n[0]:o,s(()=>r),!t||Object.is(r,o)))&&!Object.is(o,r)){if(te()){c();return}i||(i=!0,De(c))}}),l}function Ie(e,...n){return typeof e=="function"?pe(e,...n):e}function he(e,n,t){let o=n();Object.is(o,n())||console.error("[krate] The result of getSnapshot should be cached to avoid an infinite loop");let[r,i]=w(o),l=()=>{let c=n();Object.is(c,o)||(o=c,i(()=>c))},s=e(l);return l(),W(()=>{typeof s=="function"&&s()}),r}function qe(e,n,t){return he(e,n,t)}re();globalThis.__krateSuspenseHook={current:de,suspend:(e,n)=>G(e,n)};return be($e);})();
2
2
  for (const k in __krate_exports) { window[k] = __krate_exports[k]; }
package/dist/list.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type KrateAdoptable } from './dom.js';
2
- type KeyFn = ((item: unknown, index: number) => unknown) | null;
3
- type RenderFn = (item: unknown, index: unknown) => unknown;
2
+ export type KeyFn = ((item: unknown, index: number) => unknown) | null;
3
+ export type RenderFn = (item: unknown, index: unknown) => unknown;
4
4
  /**
5
5
  * Indices (into `seq`) of a longest strictly increasing subsequence of the
6
6
  * non-negative entries. O(n log n).
@@ -16,5 +16,15 @@ export declare function krateBindList(start: Comment, getItems: () => unknown, k
16
16
  * mounts as a fragment with its own markers, or adopts a server-rendered list
17
17
  * at the hydration cursor.
18
18
  */
19
- export declare function krateList(getItems: () => unknown, keyFn: KeyFn, render: RenderFn, mode: number): KrateAdoptable;
20
- export {};
19
+ /**
20
+ * The value krateList returns. Besides mounting itself as DOM it carries its
21
+ * arguments, so a custom renderer (a renderer component's children) can
22
+ * reconcile the list itself.
23
+ */
24
+ export interface KrateListValue extends KrateAdoptable {
25
+ items: () => unknown;
26
+ key: KeyFn;
27
+ render: RenderFn;
28
+ mode: number;
29
+ }
30
+ export declare function krateList(getItems: () => unknown, keyFn: KeyFn, render: RenderFn, mode: number): KrateListValue;
package/dist/list.js CHANGED
@@ -25,6 +25,7 @@
25
25
  import { createEffect, createRoot, createSignal, onCleanup, untrack } from './signal.js';
26
26
  import { krateUnmount, krateWithOwner } from './effects.js';
27
27
  import { adoptValue, appendChild, disposeNode, insertAt, removeRest, trackEffect, withDOM, withVNodes, } from './dom.js';
28
+ import { krateMuteEvents } from './events.js';
28
29
  import { krateWithIdScope } from './use-id.js';
29
30
  /** Canonical key: explicit keys are `$` + String(key); implicit keys are the index. */
30
31
  function keyOf(keyFn, item, i) {
@@ -275,10 +276,14 @@ function update(state, items) {
275
276
  next[i] = row;
276
277
  }
277
278
  // Unmount removed rows first, so their cleanups run before new rows mount.
278
- for (let i = 0; i < oldRows.length; i++) {
279
- if (!kept[i])
280
- removeRow(oldRows[i]);
281
- }
279
+ // A browser blurs a focused node it removes; React's commit hides that from
280
+ // handlers, and so does this.
281
+ krateMuteEvents(() => {
282
+ for (let i = 0; i < oldRows.length; i++) {
283
+ if (!kept[i])
284
+ removeRow(oldRows[i]);
285
+ }
286
+ });
282
287
  // Update or adopt the rows that stay.
283
288
  for (let i = 0; i < n; i++) {
284
289
  const row = next[i];
@@ -324,21 +329,24 @@ function update(state, items) {
324
329
  const stay = new Uint8Array(n);
325
330
  for (const i of longestIncreasingSubsequence(sources))
326
331
  stay[i] = 1;
327
- let anchor = end;
328
- for (let i = n - 1; i >= 0; i--) {
329
- const row = next[i];
330
- const pending = runs[i];
331
- if (pending) {
332
- parent.insertBefore(pending, anchor);
333
- }
334
- else if (sources[i] >= 0 && !stay[i]) {
335
- moveRow(row, anchor);
332
+ // The blur and focus a move causes are not user events (see above).
333
+ krateMuteEvents(() => {
334
+ let anchor = end;
335
+ for (let i = n - 1; i >= 0; i--) {
336
+ const row = next[i];
337
+ const pending = runs[i];
338
+ if (pending) {
339
+ parent.insertBefore(pending, anchor);
340
+ }
341
+ else if (sources[i] >= 0 && !stay[i]) {
342
+ moveRow(row, anchor);
343
+ }
344
+ anchor = row.start;
336
345
  }
337
- anchor = row.start;
338
- }
339
- state.rows = next;
340
- if (restoreFocus)
341
- restoreFocus();
346
+ state.rows = next;
347
+ if (restoreFocus)
348
+ restoreFocus();
349
+ });
342
350
  }
343
351
  // Collect the server-rendered rows between the list markers. Anything else
344
352
  // between the markers (stray text, unexpected nodes) is removed.
@@ -428,14 +436,13 @@ export function krateBindList(start, getItems, keyFn, render, mode) {
428
436
  }
429
437
  run(newState(start, end, keyFn, render, mode), getItems, true);
430
438
  }
431
- /**
432
- * A list nested in rendered JSX (a `.map()` inside a row or component). It
433
- * mounts as a fragment with its own markers, or adopts a server-rendered list
434
- * at the hydration cursor.
435
- */
436
439
  export function krateList(getItems, keyFn, render, mode) {
437
440
  return {
438
441
  __ka: 1,
442
+ items: getItems,
443
+ key: keyFn,
444
+ render,
445
+ mode,
439
446
  mount() {
440
447
  const frag = document.createDocumentFragment();
441
448
  const start = document.createComment('');
package/dist/metadata.js CHANGED
@@ -131,10 +131,10 @@ function fillParams(files, params) {
131
131
  function mergeFiles(acc, files, own) {
132
132
  const out = { ...acc, metadata: { ...acc.metadata } };
133
133
  if (files.openGraph && files.openGraph.images !== undefined && !(own && own.openGraph && own.openGraph.images !== undefined)) {
134
- out.metadata.openGraph = { ...(out.metadata.openGraph || {}), images: files.openGraph.images };
134
+ out.metadata.openGraph = { ...out.metadata.openGraph, images: files.openGraph.images };
135
135
  }
136
136
  if (files.twitter && files.twitter.images !== undefined && !(own && own.twitter && own.twitter.images !== undefined)) {
137
- out.metadata.twitter = { card: 'summary_large_image', ...(out.metadata.twitter || {}), images: files.twitter.images };
137
+ out.metadata.twitter = { card: 'summary_large_image', ...out.metadata.twitter, images: files.twitter.images };
138
138
  }
139
139
  if (files.icons !== undefined && !(own && own.icons !== undefined))
140
140
  out.metadata.icons = files.icons;
@@ -170,6 +170,9 @@ function resolveBaseJoin(value, base) {
170
170
  // metadataBase's path is a prefix: "/docs" + "/a" = "/docs/a".
171
171
  const prefix = b.pathname.replace(/\/$/, '');
172
172
  const path = s.startsWith('/') ? s : '/' + s;
173
+ // A convention image URL already carries the site base path.
174
+ if (prefix && (path === prefix || path.startsWith(prefix + '/')))
175
+ return b.origin + path;
173
176
  return b.origin + prefix + path;
174
177
  }
175
178
  catch {
@@ -0,0 +1,13 @@
1
+ import type { AppRouterInstance } from './navigation.js';
2
+ type ParamValue = string | string[];
3
+ type UseSyncExternalStore = <T>(subscribe: (cb: () => void) => () => void, getSnapshot: () => T, getServerSnapshot?: () => T) => T;
4
+ export interface ValueNavigationHooks {
5
+ usePathname(): string;
6
+ useSearchParams(): URLSearchParams;
7
+ useParams<T extends Record<string, ParamValue> = Record<string, ParamValue>>(): T;
8
+ useRouter(): AppRouterInstance;
9
+ useSelectedLayoutSegments(parallelRouteKey?: string, depth?: number): string[];
10
+ useSelectedLayoutSegment(parallelRouteKey?: string, depth?: number): string | null;
11
+ }
12
+ export declare function createValueNavigationHooks(useSyncExternalStore: UseSyncExternalStore): ValueNavigationHooks;
13
+ export {};
@@ -0,0 +1,86 @@
1
+ // Router hooks for React-model components: modules that run on Preact compat
2
+ // or on real React (a "use client" module under a server component, an island
3
+ // that uses an npm React library). They read hook results as plain values, so
4
+ // each hook returns a value and the component re-renders when the URL changes.
5
+ // Krate-compiled components use the getter-returning hooks of navigation.ts.
6
+ //
7
+ // The compiler's island builds replace the router hooks of `@krate/runtime`
8
+ // with createValueNavigationHooks(useSyncExternalStore) of their React.
9
+ import { getRequestContext } from './request-context.js';
10
+ import * as serverNav from './navigation-server.js';
11
+ import { krateRouter } from './router.js';
12
+ import { krateRouteStore, krateMatchParams, krateLayoutSegments } from './navigation.js';
13
+ const routerInstance = {
14
+ push: (href, options) => void krateRouter.push(href, options),
15
+ replace: (href, options) => void krateRouter.replace(href, options),
16
+ back: () => krateRouter.back(),
17
+ forward: () => krateRouter.forward(),
18
+ refresh: () => void krateRouter.refresh(),
19
+ prefetch: (href) => void krateRouter.prefetch(href),
20
+ };
21
+ export function createValueNavigationHooks(useSyncExternalStore) {
22
+ const store = krateRouteStore();
23
+ const route = () => useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
24
+ // Values derived from the snapshot are cached so they keep their identity
25
+ // between renders of the same URL, as React's hooks do.
26
+ let paramsKey = '';
27
+ let paramsVal = new URLSearchParams();
28
+ let routeKey = '';
29
+ let routeVal = {};
30
+ let segKey = '';
31
+ let segVal = [];
32
+ const segments = (depth) => {
33
+ const s = route();
34
+ const key = s.pathname + '\0' + (depth ?? '');
35
+ if (key !== segKey) {
36
+ segKey = key;
37
+ segVal = krateLayoutSegments(s.pathname, depth);
38
+ }
39
+ return segVal;
40
+ };
41
+ return {
42
+ usePathname() {
43
+ if (getRequestContext())
44
+ return serverNav.usePathname();
45
+ return route().pathname;
46
+ },
47
+ useSearchParams() {
48
+ if (getRequestContext())
49
+ return serverNav.useSearchParams();
50
+ const s = route();
51
+ if (s.search !== paramsKey) {
52
+ paramsKey = s.search;
53
+ paramsVal = new URLSearchParams(s.search);
54
+ }
55
+ return paramsVal;
56
+ },
57
+ useParams() {
58
+ if (getRequestContext())
59
+ return serverNav.useParams();
60
+ const s = route();
61
+ const key = s.route + '\0' + s.pathname;
62
+ if (key !== routeKey) {
63
+ routeKey = key;
64
+ routeVal = krateMatchParams(s.route, s.pathname);
65
+ }
66
+ return routeVal;
67
+ },
68
+ useRouter() {
69
+ if (getRequestContext())
70
+ return serverNav.useRouter();
71
+ return routerInstance;
72
+ },
73
+ useSelectedLayoutSegments(parallelRouteKey, depth) {
74
+ if (getRequestContext())
75
+ return serverNav.useSelectedLayoutSegments(parallelRouteKey, depth);
76
+ return segments(depth);
77
+ },
78
+ useSelectedLayoutSegment(parallelRouteKey, depth) {
79
+ if (getRequestContext())
80
+ return serverNav.useSelectedLayoutSegment(parallelRouteKey, depth);
81
+ const at = typeof depth === 'number' ? depth : 0;
82
+ const parts = krateLayoutSegments(route().pathname);
83
+ return parts.length > at ? parts[at] : null;
84
+ },
85
+ };
86
+ }
@@ -1,3 +1,22 @@
1
+ interface RouteSnapshot {
2
+ pathname: string;
3
+ search: string;
4
+ /** The route pattern of the current document ("/blog/[slug]"), "" for a static route. */
5
+ route: string;
6
+ }
7
+ /**
8
+ * An external store of the route for React-model components (Preact compat and
9
+ * real React islands), which read hook results as plain values and re-render
10
+ * when the URL changes. The snapshot object only changes with the route.
11
+ */
12
+ export declare function krateRouteStore(): {
13
+ subscribe: (cb: () => void) => () => void;
14
+ getSnapshot: () => RouteSnapshot;
15
+ };
16
+ /** The params a route pattern matches in a pathname (see useParams). */
17
+ export declare function krateMatchParams(route: string, pathname: string): Record<string, string | string[]>;
18
+ /** The path segments below depth (see useSelectedLayoutSegments). */
19
+ export declare function krateLayoutSegments(pathname: string, depth?: number): string[];
1
20
  /** Test hook: forgets the shared snapshot so the next hook call reads the URL again. */
2
21
  export declare function krateResetNavigation(): void;
3
22
  /** The current URL path without the base path and the query ("/blog/hello"). */
@@ -58,6 +58,41 @@ function routeState() {
58
58
  }
59
59
  return read;
60
60
  }
61
+ /**
62
+ * An external store of the route for React-model components (Preact compat and
63
+ * real React islands), which read hook results as plain values and re-render
64
+ * when the URL changes. The snapshot object only changes with the route.
65
+ */
66
+ export function krateRouteStore() {
67
+ let last = null;
68
+ const getSnapshot = () => {
69
+ const next = snapshot();
70
+ if (last && last.pathname === next.pathname && last.search === next.search && last.route === next.route)
71
+ return last;
72
+ last = next;
73
+ return next;
74
+ };
75
+ const subscribe = (cb) => {
76
+ const off = subscribeNavigation(cb);
77
+ // The router swaps the document before it emits the final status.
78
+ if (typeof window !== 'undefined')
79
+ window.addEventListener('krate:navigate-end', cb);
80
+ return () => {
81
+ off();
82
+ if (typeof window !== 'undefined')
83
+ window.removeEventListener('krate:navigate-end', cb);
84
+ };
85
+ };
86
+ return { subscribe, getSnapshot };
87
+ }
88
+ /** The params a route pattern matches in a pathname (see useParams). */
89
+ export function krateMatchParams(route, pathname) {
90
+ return matchRouteParams(route, pathname);
91
+ }
92
+ /** The path segments below depth (see useSelectedLayoutSegments). */
93
+ export function krateLayoutSegments(pathname, depth) {
94
+ return pathname.split('/').filter(Boolean).map(safeDecode).slice(typeof depth === 'number' ? depth : 0);
95
+ }
61
96
  /** Test hook: forgets the shared snapshot so the next hook call reads the URL again. */
62
97
  export function krateResetNavigation() {
63
98
  state = null;
@@ -71,7 +71,7 @@ function acceptsEncoding(header, coding) {
71
71
  let token = part;
72
72
  let q = 1;
73
73
  const semi = part.indexOf(";");
74
- if (semi >= 0) {
74
+ if (semi !== -1) {
75
75
  token = part.slice(0, semi).trim();
76
76
  for (const param of part.slice(semi + 1).split(";")) {
77
77
  const t = param.trim();
@@ -198,7 +198,7 @@ export function createNodeStaticLayer(distDir) {
198
198
  return null;
199
199
  }
200
200
  const ext = path.extname(target).toLowerCase();
201
- let contentType = MIME[ext] || "application/octet-stream";
201
+ const contentType = MIME[ext] || "application/octet-stream";
202
202
  const headers = new Headers();
203
203
  const ae = request.headers.get("accept-encoding");
204
204
  let encoding = "";
@@ -235,7 +235,7 @@ export function createNodeStaticLayer(distDir) {
235
235
  let start = 0;
236
236
  let end = size - 1;
237
237
  const range = request.headers.get("range");
238
- if (range && /^bytes=/.test(range) && !range.includes(",")) {
238
+ if (range && range.startsWith('bytes=') && !range.includes(",")) {
239
239
  const m = /^bytes=(\d*)-(\d*)$/.exec(range.trim());
240
240
  if (m && (m[1] !== "" || m[2] !== "")) {
241
241
  if (m[1] === "") {
package/dist/og.js CHANGED
@@ -35,7 +35,7 @@ export function serializeElement(node, path = 'root') {
35
35
  const el = node;
36
36
  if (typeof el.__raw === 'string')
37
37
  throw new TypeError(`ImageResponse: ${path} is raw HTML, which is not supported`);
38
- const props = { ...(el.props || {}) };
38
+ const props = { ...el.props };
39
39
  const children = el.children || [];
40
40
  if (typeof el.type === 'function') {
41
41
  const out = el.type({ ...props, children: children.length === 1 ? children[0] : children });
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Platform access for server code, exported from `@krate/runtime/server`.
3
+ *
4
+ * The portable server handler runs every request inside an AsyncLocalStorage
5
+ * scope published on `globalThis[Symbol.for('krate.platform.store')]` (the
6
+ * same pattern as the request store), so pages, API routes, server actions
7
+ * and middleware all see the same `{ env, ctx, cf }` of the request in flight.
8
+ * On the cloudflare target `env` holds the Worker bindings (D1, KV, R2,
9
+ * Durable Objects, secrets); it is never copied into `process.env`.
10
+ */
11
+ /** The deploy target the handler runs on, or "none" outside a handler (dev, tests). */
12
+ export type PlatformTarget = 'cloudflare' | 'vercel' | 'netlify' | 'node' | 'none';
13
+ /** Keeps the instance alive for work that outlives the response. */
14
+ export interface PlatformExecutionContext {
15
+ waitUntil(work: Promise<unknown>): void;
16
+ /** Cloudflare only: let the request fall through to the origin when the Worker throws. */
17
+ passThroughOnException?(): void;
18
+ }
19
+ /**
20
+ * Augment this interface with your bindings to type `env`:
21
+ *
22
+ * declare module '@krate/runtime/server' {
23
+ * interface KrateCloudflareEnv { DB: D1Database; CACHE: KVNamespace }
24
+ * }
25
+ */
26
+ export interface KrateCloudflareEnv {
27
+ }
28
+ export interface PlatformContext<Env = Record<string, unknown>> {
29
+ target: PlatformTarget;
30
+ /** The Worker `env` on cloudflare; an empty object elsewhere. */
31
+ env: Env;
32
+ ctx: PlatformExecutionContext;
33
+ /** Cloudflare's `request.cf` properties (colo, country, ...), when present. */
34
+ cf: Record<string, unknown> | undefined;
35
+ }
36
+ export interface CloudflareContext<Env = KrateCloudflareEnv & Record<string, any>> extends PlatformContext<Env> {
37
+ target: 'cloudflare';
38
+ }
39
+ /**
40
+ * The platform of the request being served. Outside a request handler (`krate
41
+ * dev`, tests) it returns an empty environment and a `waitUntil` that just
42
+ * detaches the promise, so code that only uses it opportunistically keeps working.
43
+ */
44
+ export declare function getPlatform<Env = Record<string, unknown>>(): PlatformContext<Env>;
45
+ /**
46
+ * The Cloudflare `{ env, ctx, cf }` of the request being served. Throws
47
+ * outside a Worker request, so a missing binding is an error at the call
48
+ * site rather than an `undefined` later.
49
+ */
50
+ export declare function getCloudflareContext<Env = KrateCloudflareEnv & Record<string, any>>(): CloudflareContext<Env>;
51
+ /** Runs work after the response is sent, through the platform's waitUntil when there is one. */
52
+ export declare function platformWaitUntil(work: Promise<unknown>): boolean;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Platform access for server code, exported from `@krate/runtime/server`.
3
+ *
4
+ * The portable server handler runs every request inside an AsyncLocalStorage
5
+ * scope published on `globalThis[Symbol.for('krate.platform.store')]` (the
6
+ * same pattern as the request store), so pages, API routes, server actions
7
+ * and middleware all see the same `{ env, ctx, cf }` of the request in flight.
8
+ * On the cloudflare target `env` holds the Worker bindings (D1, KV, R2,
9
+ * Durable Objects, secrets); it is never copied into `process.env`.
10
+ */
11
+ const PLATFORM_STORE = Symbol.for('krate.platform.store');
12
+ function current() {
13
+ const store = globalThis[PLATFORM_STORE];
14
+ return store && typeof store.getStore === 'function' ? store.getStore() : undefined;
15
+ }
16
+ /**
17
+ * The platform of the request being served. Outside a request handler (`krate
18
+ * dev`, tests) it returns an empty environment and a `waitUntil` that just
19
+ * detaches the promise, so code that only uses it opportunistically keeps working.
20
+ */
21
+ export function getPlatform() {
22
+ const c = current();
23
+ if (c)
24
+ return c;
25
+ return {
26
+ target: 'none',
27
+ env: {},
28
+ ctx: {
29
+ waitUntil(work) {
30
+ Promise.resolve(work).catch((err) => console.error(`[krate] waitUntil task failed: ${(err && err.stack) || err}`));
31
+ },
32
+ },
33
+ cf: undefined,
34
+ };
35
+ }
36
+ /**
37
+ * The Cloudflare `{ env, ctx, cf }` of the request being served. Throws
38
+ * outside a Worker request, so a missing binding is an error at the call
39
+ * site rather than an `undefined` later.
40
+ */
41
+ export function getCloudflareContext() {
42
+ const c = current();
43
+ if (!c || c.target !== 'cloudflare') {
44
+ throw new Error('getCloudflareContext() works only while a request is served by the cloudflare target (krate deploy --target cloudflare); ' +
45
+ (c ? `this request is served by "${c.target}"` : 'there is no request in flight here (krate dev and krate serve run on Node and have no Worker bindings)') +
46
+ '. Use getPlatform() for code that also has to run elsewhere.');
47
+ }
48
+ return c;
49
+ }
50
+ /** Runs work after the response is sent, through the platform's waitUntil when there is one. */
51
+ export function platformWaitUntil(work) {
52
+ const c = current();
53
+ if (!c || c.target === 'none' || !c.ctx || typeof c.ctx.waitUntil !== 'function')
54
+ return false;
55
+ c.ctx.waitUntil(work);
56
+ return true;
57
+ }
@@ -0,0 +1,39 @@
1
+ type AnyFn = (...args: any[]) => any;
2
+ export interface FormStatus {
3
+ pending: boolean;
4
+ data: FormData | null;
5
+ method: string | null;
6
+ action: unknown;
7
+ }
8
+ export interface ReactCompatExtras {
9
+ useOptimistic: AnyFn;
10
+ useActionState: AnyFn;
11
+ useFormState: AnyFn;
12
+ useFormStatus: () => FormStatus;
13
+ requestFormReset: (form: HTMLFormElement) => void;
14
+ use: AnyFn;
15
+ cache: AnyFn;
16
+ useEffectEvent: AnyFn;
17
+ startTransition: AnyFn;
18
+ useTransition: AnyFn;
19
+ }
20
+ /**
21
+ * Builds the additions once per Preact instance: the `react` and `react-dom`
22
+ * modules of a bundle (and of every island chunk) share one action scope and
23
+ * one form-status context.
24
+ */
25
+ export declare function createReactCompatExtras(c: any, options: any): ReactCompatExtras;
26
+ /**
27
+ * React 18 flushes the passive effects of a render caused by a discrete event
28
+ * (a click, a key press, typing) synchronously at the end of its commit, and
29
+ * renders the updates those effects make in the same task. Preact runs them
30
+ * after the next frame, so a quick second event could render a component with
31
+ * a new prop and a state update from its previous effects at once: react-colorful
32
+ * then took its own color prop for user input and called onChange with a
33
+ * stale colour. While a discrete event's task runs, this flushes Preact's
34
+ * effect queue after every commit (Preact's render loop picks up the updates
35
+ * they make); otherwise effects keep running after paint. The compiler's
36
+ * client builds call it from their `react` module, once per Preact instance.
37
+ */
38
+ export declare function installDiscreteEffects(options: any): void;
39
+ export {};