@absolutejs/absolute 0.19.0-beta.381 → 0.19.0-beta.383

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.
@@ -4,7 +4,7 @@ export type StreamingSlotEnhancerOptions = Omit<AppendStreamingSlotsOptions, 'in
4
4
  streamingSlots?: StreamingSlot[];
5
5
  policy?: StreamingSlotPolicy;
6
6
  };
7
- export declare const enhanceHtmlResponseWithStreamingSlots: (response: Response, { nonce, onError, streamingSlots, policy }?: StreamingSlotEnhancerOptions) => Response;
7
+ export declare const enhanceHtmlResponseWithStreamingSlots: (response: Response, { nonce, onError, runtimePlacement, streamingSlots, policy }?: StreamingSlotEnhancerOptions) => Response;
8
8
  export declare const withStreamingSlots: (responseLike: ResponseLike, options?: StreamingSlotEnhancerOptions) => Promise<Response>;
9
9
  export declare const withRegisteredStreamingSlots: (renderResponse: () => ResponseLike, options?: StreamingSlotEnhancerOptions) => Promise<Response>;
10
10
  export {};
@@ -1 +1,2 @@
1
- export declare const wrapPageHandlerWithStreamingSlots: <Args extends unknown[]>(handler: (...args: Args) => Response | Promise<Response>) => (...args: Args) => Promise<Response>;
1
+ import { withRegisteredStreamingSlots } from './responseEnhancers';
2
+ export declare const wrapPageHandlerWithStreamingSlots: <Args extends unknown[]>(handler: (...args: Args) => Response | Promise<Response>, options?: Parameters<typeof withRegisteredStreamingSlots>[1]) => (...args: Args) => Promise<Response>;
@@ -44,6 +44,7 @@ export type AppendStreamingSlotsOptions = {
44
44
  policy?: StreamingSlotPolicy;
45
45
  onSlotMetric?: StreamingSlotMetricHandler;
46
46
  onError?: (error: unknown, slot: StreamingSlot) => void;
47
+ runtimePlacement?: 'body' | 'head';
47
48
  };
48
49
  export type StreamOutOfOrderSlotsOptions = {
49
50
  footerHtml?: string;
@@ -60,10 +61,11 @@ export declare const renderStreamingSlotsRuntimeTag: (nonce?: string) => string;
60
61
  export declare const renderStreamingSlotPlaceholder: (id: string, fallbackHtml?: string) => string;
61
62
  export declare const renderStreamingSlotPatchTag: (id: string, html: string, nonce?: string) => string;
62
63
  export declare const injectHtmlIntoHead: (html: string, injection: string) => string;
64
+ export declare const injectHtmlIntoBody: (html: string, injection: string) => string;
63
65
  export declare const getStreamingSlotPolicy: () => StreamingSlotPolicyValue;
64
66
  export declare const setStreamingSlotPolicy: (policy?: StreamingSlotPolicy) => void;
65
67
  export declare const withStreamingSlotPolicy: <T>(policy: StreamingSlotPolicy, callback: () => Promise<T> | T) => Promise<T>;
66
68
  export declare const streamOutOfOrderSlots: ({ footerHtml, headerHtml, nonce, policy, onSlotMetric, onError, slots }: StreamOutOfOrderSlotsOptions) => ReadableStream<Uint8Array<ArrayBufferLike>>;
67
- export declare const injectStreamingRuntimeIntoStream: (stream: ReadableStream<string | Uint8Array>, nonce?: string) => ReadableStream<Uint8Array<ArrayBufferLike>>;
68
- export declare const appendStreamingSlotPatchesToStream: (stream: ReadableStream<string | Uint8Array>, slots?: DeferredStreamingSlot[], { injectRuntime, nonce, onError, onSlotMetric, policy }?: AppendStreamingSlotsOptions) => ReadableStream<string | Uint8Array<ArrayBufferLike>>;
69
+ export declare const injectStreamingRuntimeIntoStream: (stream: ReadableStream<string | Uint8Array>, nonce?: string, runtimePlacement?: "body" | "head") => ReadableStream<Uint8Array<ArrayBufferLike>>;
70
+ export declare const appendStreamingSlotPatchesToStream: (stream: ReadableStream<string | Uint8Array>, slots?: DeferredStreamingSlot[], { injectRuntime, nonce, onError, onSlotMetric, policy, runtimePlacement }?: AppendStreamingSlotsOptions) => ReadableStream<string | Uint8Array<ArrayBufferLike>>;
69
71
  export {};
@@ -1836,7 +1836,9 @@ var getStreamSwapRuntimeScript = () => `(function(){${stripFunctionWrapper(strea
1836
1836
  init_escapeScriptContent();
1837
1837
  var SLOT_ID_PREFIX = "abs-slot-";
1838
1838
  var SLOT_PLACEHOLDER_PREFIX = "slot-";
1839
+ var CLOSING_BODY_TAG = "</body>";
1839
1840
  var CLOSING_HEAD_TAG = "</head>";
1841
+ var CLOSING_BODY_TAG_LENGTH = CLOSING_BODY_TAG.length;
1840
1842
  var CLOSING_HEAD_TAG_LENGTH = CLOSING_HEAD_TAG.length;
1841
1843
  var CLOSING_PAGE_TAG_REGEX = /<\/body>\s*<\/html>\s*$/i;
1842
1844
  var STREAMING_RUNTIME_GLOBAL = "__ABS_SLOT_ENQUEUE__";
@@ -1860,6 +1862,13 @@ var injectHtmlIntoHead = (html, injection) => {
1860
1862
  }
1861
1863
  return `${html}${injection}`;
1862
1864
  };
1865
+ var injectHtmlIntoBody = (html, injection) => {
1866
+ const closingBodyIndex = html.indexOf(CLOSING_BODY_TAG);
1867
+ if (closingBodyIndex >= 0) {
1868
+ return `${html.slice(0, closingBodyIndex)}${injection}${html.slice(closingBodyIndex)}`;
1869
+ }
1870
+ return `${html}${injection}`;
1871
+ };
1863
1872
  var toUint8 = (value, encoder) => encoder.encode(value);
1864
1873
  var currentStreamingSlotPolicy = {
1865
1874
  timeoutMs: STREAMING_SLOT_TIMEOUT_MS,
@@ -2124,11 +2133,12 @@ var streamOutOfOrderSlots = ({
2124
2133
  }
2125
2134
  });
2126
2135
  };
2127
- var injectStreamingRuntimeIntoStream = (stream, nonce) => {
2136
+ var injectStreamingRuntimeIntoStream = (stream, nonce, runtimePlacement = "head") => {
2128
2137
  const runtimeTag = renderStreamingSlotsRuntimeTag(nonce);
2129
2138
  const encoder = new TextEncoder;
2130
2139
  const decoder = new TextDecoder;
2131
- const lookbehind = CLOSING_HEAD_TAG_LENGTH - 1;
2140
+ const closingTag = runtimePlacement === "body" ? CLOSING_BODY_TAG : CLOSING_HEAD_TAG;
2141
+ const lookbehind = (runtimePlacement === "body" ? CLOSING_BODY_TAG_LENGTH : CLOSING_HEAD_TAG_LENGTH) - 1;
2132
2142
  return new ReadableStream({
2133
2143
  async start(controller) {
2134
2144
  const reader = stream.getReader();
@@ -2147,9 +2157,9 @@ var injectStreamingRuntimeIntoStream = (stream, nonce) => {
2147
2157
  pending = "";
2148
2158
  continue;
2149
2159
  }
2150
- const headIndex = pending.indexOf(CLOSING_HEAD_TAG);
2151
- if (headIndex >= 0) {
2152
- const withRuntime = `${pending.slice(0, headIndex)}${runtimeTag}${pending.slice(headIndex)}`;
2160
+ const closingTagIndex = pending.indexOf(closingTag);
2161
+ if (closingTagIndex >= 0) {
2162
+ const withRuntime = `${pending.slice(0, closingTagIndex)}${runtimeTag}${pending.slice(closingTagIndex)}`;
2153
2163
  controller.enqueue(encoder.encode(withRuntime));
2154
2164
  pending = "";
2155
2165
  injected = true;
@@ -2163,7 +2173,7 @@ var injectStreamingRuntimeIntoStream = (stream, nonce) => {
2163
2173
  }
2164
2174
  pending += decoder.decode();
2165
2175
  if (!injected) {
2166
- pending = injectHtmlIntoHead(pending, runtimeTag);
2176
+ pending = runtimePlacement === "body" ? injectHtmlIntoBody(pending, runtimeTag) : injectHtmlIntoHead(pending, runtimeTag);
2167
2177
  }
2168
2178
  if (pending.length > 0) {
2169
2179
  controller.enqueue(encoder.encode(pending));
@@ -2180,7 +2190,8 @@ var appendStreamingSlotPatchesToStream = (stream, slots = [], {
2180
2190
  nonce,
2181
2191
  onError,
2182
2192
  onSlotMetric,
2183
- policy
2193
+ policy,
2194
+ runtimePlacement = "head"
2184
2195
  } = {}) => {
2185
2196
  const resolvedPolicy = resolveStreamingSlotPolicy(policy);
2186
2197
  const combinedOnError = createCombinedSlotErrorHandler(resolvedPolicy.onError, onError);
@@ -2197,7 +2208,7 @@ var appendStreamingSlotPatchesToStream = (stream, slots = [], {
2197
2208
  });
2198
2209
  if (preparedSlots.length === 0)
2199
2210
  return stream;
2200
- const source = injectRuntime ? injectStreamingRuntimeIntoStream(stream, nonce) : stream;
2211
+ const source = injectRuntime ? injectStreamingRuntimeIntoStream(stream, nonce, runtimePlacement) : stream;
2201
2212
  const encoder = new TextEncoder;
2202
2213
  const decoder = new TextDecoder;
2203
2214
  const reader = source.getReader();
@@ -2282,14 +2293,21 @@ var cloneHeaders = (response) => {
2282
2293
  const headers = new Headers(response.headers);
2283
2294
  return headers;
2284
2295
  };
2285
- var enhanceHtmlResponseWithStreamingSlots = (response, { nonce, onError, streamingSlots = [], policy } = {}) => {
2296
+ var enhanceHtmlResponseWithStreamingSlots = (response, {
2297
+ nonce,
2298
+ onError,
2299
+ runtimePlacement,
2300
+ streamingSlots = [],
2301
+ policy
2302
+ } = {}) => {
2286
2303
  if (!response.body || streamingSlots.length === 0) {
2287
2304
  return response;
2288
2305
  }
2289
2306
  const body = appendStreamingSlotPatchesToStream(response.body, streamingSlots, {
2290
2307
  nonce,
2291
2308
  onError,
2292
- policy
2309
+ policy,
2310
+ runtimePlacement
2293
2311
  });
2294
2312
  return new Response(body, {
2295
2313
  headers: cloneHeaders(response),
@@ -2316,7 +2334,7 @@ var withRegisteredStreamingSlots = async (renderResponse, options = {}) => {
2316
2334
  };
2317
2335
 
2318
2336
  // src/core/wrapPageHandlerWithStreamingSlots.ts
2319
- var wrapPageHandlerWithStreamingSlots = (handler) => (...args) => withRegisteredStreamingSlots(() => handler(...args));
2337
+ var wrapPageHandlerWithStreamingSlots = (handler, options) => (...args) => withRegisteredStreamingSlots(() => handler(...args), options);
2320
2338
 
2321
2339
  // src/svelte/index.ts
2322
2340
  init_pageHandler();
@@ -2453,7 +2471,7 @@ var resolveIslandHtml = (_slotId, props) => renderIslandMarkup(requireCurrentIsl
2453
2471
 
2454
2472
  // src/svelte/index.ts
2455
2473
  init_renderToReadableStream();
2456
- var handleSveltePageRequest2 = wrapPageHandlerWithStreamingSlots(handleSveltePageRequest);
2474
+ var handleSveltePageRequest2 = wrapPageHandlerWithStreamingSlots(handleSveltePageRequest, { runtimePlacement: "body" });
2457
2475
  export {
2458
2476
  useIslandStore,
2459
2477
  resolveIslandHtml,
@@ -2463,5 +2481,5 @@ export {
2463
2481
  createTypedIsland
2464
2482
  };
2465
2483
 
2466
- //# debugId=D95A79BDF1F3780B64756E2164756E21
2484
+ //# debugId=84C217567CFD6A2964756E2164756E21
2467
2485
  //# sourceMappingURL=index.js.map