@absolutejs/absolute 0.19.0-beta.783 → 0.19.0-beta.785

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 (252) hide show
  1. package/dist/angular/browser.js +57 -9801
  2. package/dist/angular/browser.js.map +4 -246
  3. package/dist/angular/index.js +61 -14967
  4. package/dist/angular/index.js.map +4 -282
  5. package/dist/angular/server.js +45 -5699
  6. package/dist/angular/server.js.map +3 -52
  7. package/dist/build.js +45 -18021
  8. package/dist/build.js.map +3 -100
  9. package/dist/chunk-102fp7xe.js +63 -0
  10. package/dist/chunk-102fp7xe.js.map +10 -0
  11. package/dist/chunk-11zpfqz6.js +19 -0
  12. package/dist/chunk-11zpfqz6.js.map +10 -0
  13. package/dist/chunk-1e9vsfyh.js +100 -0
  14. package/dist/chunk-1e9vsfyh.js.map +10 -0
  15. package/dist/chunk-25v9t56f.js +29 -0
  16. package/dist/chunk-25v9t56f.js.map +11 -0
  17. package/dist/chunk-2f21eenc.js +21 -0
  18. package/dist/chunk-2f21eenc.js.map +10 -0
  19. package/dist/chunk-2ga2znex.js +13 -0
  20. package/dist/chunk-2ga2znex.js.map +9 -0
  21. package/dist/chunk-30yrw0f6.js +33 -0
  22. package/dist/chunk-30yrw0f6.js.map +10 -0
  23. package/dist/chunk-3c7mpj3m.js +784 -0
  24. package/dist/chunk-3c7mpj3m.js.map +10 -0
  25. package/dist/chunk-3g91wb4f.js +358 -0
  26. package/dist/chunk-3g91wb4f.js.map +10 -0
  27. package/dist/chunk-3yjzpcne.js +34 -0
  28. package/dist/chunk-3yjzpcne.js.map +10 -0
  29. package/dist/chunk-4bq79t8v.js +136 -0
  30. package/dist/chunk-4bq79t8v.js.map +10 -0
  31. package/dist/chunk-4d39r92n.js +81 -0
  32. package/dist/chunk-4d39r92n.js.map +10 -0
  33. package/dist/chunk-4m75s5xf.js +184 -0
  34. package/dist/chunk-4m75s5xf.js.map +11 -0
  35. package/dist/chunk-5003emhv.js +17 -0
  36. package/dist/chunk-5003emhv.js.map +10 -0
  37. package/dist/chunk-5fhp1jap.js +9169 -0
  38. package/dist/chunk-5fhp1jap.js.map +236 -0
  39. package/dist/chunk-6fkgm9s5.js +569 -0
  40. package/dist/chunk-6fkgm9s5.js.map +10 -0
  41. package/dist/chunk-6pdj08z3.js +73 -0
  42. package/dist/chunk-6pdj08z3.js.map +12 -0
  43. package/dist/chunk-6qjbrt0k.js +13 -0
  44. package/dist/chunk-6qjbrt0k.js.map +9 -0
  45. package/dist/chunk-6sccb4jr.js +14 -0
  46. package/dist/chunk-6sccb4jr.js.map +9 -0
  47. package/dist/chunk-73brtyw5.js +16 -0
  48. package/dist/chunk-73brtyw5.js.map +9 -0
  49. package/dist/chunk-77cqkarb.js +25 -0
  50. package/dist/chunk-77cqkarb.js.map +9 -0
  51. package/dist/chunk-798spvzv.js +50 -0
  52. package/dist/chunk-798spvzv.js.map +10 -0
  53. package/dist/chunk-7fw6x3js.js +131 -0
  54. package/dist/chunk-7fw6x3js.js.map +11 -0
  55. package/dist/chunk-7kjj42xm.js +11 -0
  56. package/dist/chunk-7kjj42xm.js.map +10 -0
  57. package/dist/chunk-851whwc7.js +17 -0
  58. package/dist/chunk-851whwc7.js.map +10 -0
  59. package/dist/chunk-85n68sy6.js +103 -0
  60. package/dist/chunk-85n68sy6.js.map +10 -0
  61. package/dist/chunk-8feq2qek.js +17 -0
  62. package/dist/chunk-8feq2qek.js.map +9 -0
  63. package/dist/chunk-8kcfffry.js +35 -0
  64. package/dist/chunk-8kcfffry.js.map +10 -0
  65. package/dist/chunk-93sqk7be.js +139 -0
  66. package/dist/chunk-93sqk7be.js.map +12 -0
  67. package/dist/chunk-97572s32.js +262 -0
  68. package/dist/chunk-97572s32.js.map +12 -0
  69. package/dist/chunk-9a307ca6.js +1742 -0
  70. package/dist/chunk-9a307ca6.js.map +11 -0
  71. package/dist/chunk-9c5tj4k3.js +130 -0
  72. package/dist/chunk-9c5tj4k3.js.map +10 -0
  73. package/dist/chunk-9xrsjeem.js +12 -0
  74. package/dist/chunk-9xrsjeem.js.map +9 -0
  75. package/dist/chunk-a9mvyp04.js +87 -0
  76. package/dist/chunk-a9mvyp04.js.map +10 -0
  77. package/dist/chunk-b3gbnrwe.js +21 -0
  78. package/dist/chunk-b3gbnrwe.js.map +10 -0
  79. package/dist/chunk-bmgqm774.js +65 -0
  80. package/dist/chunk-bmgqm774.js.map +9 -0
  81. package/dist/chunk-bxfghpma.js +69 -0
  82. package/dist/chunk-bxfghpma.js.map +10 -0
  83. package/dist/chunk-c1jfjnka.js +74 -0
  84. package/dist/chunk-c1jfjnka.js.map +10 -0
  85. package/dist/chunk-cbkrwmvh.js +80 -0
  86. package/dist/chunk-cbkrwmvh.js.map +10 -0
  87. package/dist/chunk-cdxd7sy2.js +71 -0
  88. package/dist/chunk-cdxd7sy2.js.map +10 -0
  89. package/dist/chunk-cg95827x.js +21 -0
  90. package/dist/chunk-cg95827x.js.map +10 -0
  91. package/dist/chunk-d9c0am65.js +12 -0
  92. package/dist/chunk-d9c0am65.js.map +10 -0
  93. package/dist/chunk-daqghmg8.js +12 -0
  94. package/dist/chunk-daqghmg8.js.map +9 -0
  95. package/dist/chunk-dr9yqsdb.js +203 -0
  96. package/dist/chunk-dr9yqsdb.js.map +10 -0
  97. package/dist/chunk-e8eecyrq.js +244 -0
  98. package/dist/chunk-e8eecyrq.js.map +10 -0
  99. package/dist/chunk-ex2hxe0v.js +160 -0
  100. package/dist/chunk-ex2hxe0v.js.map +11 -0
  101. package/dist/chunk-ey5hs6x6.js +253 -0
  102. package/dist/chunk-ey5hs6x6.js.map +11 -0
  103. package/dist/chunk-fak944et.js +91 -0
  104. package/dist/chunk-fak944et.js.map +10 -0
  105. package/dist/chunk-fygx2ymm.js +118 -0
  106. package/dist/chunk-fygx2ymm.js.map +12 -0
  107. package/dist/chunk-g15qj669.js +271 -0
  108. package/dist/chunk-g15qj669.js.map +11 -0
  109. package/dist/chunk-g3j22qf6.js +51 -0
  110. package/dist/chunk-g3j22qf6.js.map +9 -0
  111. package/dist/chunk-gd6wmknh.js +121 -0
  112. package/dist/chunk-gd6wmknh.js.map +11 -0
  113. package/dist/chunk-gf0ygptk.js +85 -0
  114. package/dist/chunk-gf0ygptk.js.map +11 -0
  115. package/dist/chunk-gq0zxpm0.js +90 -0
  116. package/dist/chunk-gq0zxpm0.js.map +10 -0
  117. package/dist/chunk-gytkmthr.js +220 -0
  118. package/dist/chunk-gytkmthr.js.map +10 -0
  119. package/dist/chunk-h5bbfn3n.js +28 -0
  120. package/dist/chunk-h5bbfn3n.js.map +11 -0
  121. package/dist/chunk-h6mye9r3.js +93 -0
  122. package/dist/chunk-h6mye9r3.js.map +10 -0
  123. package/dist/chunk-hcsmxw1v.js +85 -0
  124. package/dist/chunk-hcsmxw1v.js.map +10 -0
  125. package/dist/chunk-hep68ja7.js +4444 -0
  126. package/dist/chunk-hep68ja7.js.map +29 -0
  127. package/dist/chunk-hhqh49fz.js +149 -0
  128. package/dist/chunk-hhqh49fz.js.map +10 -0
  129. package/dist/chunk-hyjs4bqs.js +8 -0
  130. package/dist/chunk-hyjs4bqs.js.map +10 -0
  131. package/dist/chunk-hza0n8qm.js +20 -0
  132. package/dist/chunk-hza0n8qm.js.map +9 -0
  133. package/dist/chunk-jn91vzkh.js +66 -0
  134. package/dist/chunk-jn91vzkh.js.map +10 -0
  135. package/dist/chunk-jwxt8gnp.js +13 -0
  136. package/dist/chunk-jwxt8gnp.js.map +9 -0
  137. package/dist/chunk-kk8w9rh5.js +195 -0
  138. package/dist/chunk-kk8w9rh5.js.map +10 -0
  139. package/dist/chunk-kndkjsya.js +261 -0
  140. package/dist/chunk-kndkjsya.js.map +10 -0
  141. package/dist/chunk-kvq01j35.js +36 -0
  142. package/dist/chunk-kvq01j35.js.map +10 -0
  143. package/dist/chunk-mbazhahf.js +60 -0
  144. package/dist/chunk-mbazhahf.js.map +10 -0
  145. package/dist/chunk-mgfwq18r.js +15 -0
  146. package/dist/chunk-mgfwq18r.js.map +9 -0
  147. package/dist/chunk-mtgf69xn.js +88 -0
  148. package/dist/chunk-mtgf69xn.js.map +10 -0
  149. package/dist/chunk-nehhtthw.js +225 -0
  150. package/dist/chunk-nehhtthw.js.map +10 -0
  151. package/dist/chunk-nhzf4az4.js +149 -0
  152. package/dist/chunk-nhzf4az4.js.map +10 -0
  153. package/dist/chunk-p5504p14.js +16 -0
  154. package/dist/chunk-p5504p14.js.map +10 -0
  155. package/dist/chunk-pnscgw95.js +90 -0
  156. package/dist/chunk-pnscgw95.js.map +10 -0
  157. package/dist/chunk-pvpp4pvs.js +17 -0
  158. package/dist/chunk-pvpp4pvs.js.map +10 -0
  159. package/dist/chunk-qh75agse.js +95 -0
  160. package/dist/chunk-qh75agse.js.map +10 -0
  161. package/dist/chunk-qk8kd3hr.js +526 -0
  162. package/dist/chunk-qk8kd3hr.js.map +12 -0
  163. package/dist/chunk-qxq2zcty.js +52 -0
  164. package/dist/chunk-qxq2zcty.js.map +10 -0
  165. package/dist/chunk-r7jmgqnw.js +114 -0
  166. package/dist/chunk-r7jmgqnw.js.map +10 -0
  167. package/dist/chunk-s6defjk2.js +116 -0
  168. package/dist/chunk-s6defjk2.js.map +10 -0
  169. package/dist/chunk-sd39p726.js +619 -0
  170. package/dist/chunk-sd39p726.js.map +10 -0
  171. package/dist/chunk-smgj0epn.js +18 -0
  172. package/dist/chunk-smgj0epn.js.map +9 -0
  173. package/dist/chunk-swrnzs4c.js +63 -0
  174. package/dist/chunk-swrnzs4c.js.map +10 -0
  175. package/dist/chunk-t81a331y.js +27 -0
  176. package/dist/chunk-t81a331y.js.map +10 -0
  177. package/dist/chunk-tfe3sb44.js +33 -0
  178. package/dist/chunk-tfe3sb44.js.map +10 -0
  179. package/dist/chunk-tx9edm1x.js +34 -0
  180. package/dist/chunk-tx9edm1x.js.map +10 -0
  181. package/dist/chunk-vkrpm7kc.js +247 -0
  182. package/dist/chunk-vkrpm7kc.js.map +12 -0
  183. package/dist/chunk-vvz7dcvq.js +434 -0
  184. package/dist/chunk-vvz7dcvq.js.map +13 -0
  185. package/dist/chunk-w3m4m5we.js +4925 -0
  186. package/dist/chunk-w3m4m5we.js.map +12 -0
  187. package/dist/chunk-wrxtn9ve.js +18 -0
  188. package/dist/chunk-wrxtn9ve.js.map +10 -0
  189. package/dist/chunk-xpkjbmd3.js +428 -0
  190. package/dist/chunk-xpkjbmd3.js.map +14 -0
  191. package/dist/chunk-xrmjy8kk.js +454 -0
  192. package/dist/chunk-xrmjy8kk.js.map +10 -0
  193. package/dist/chunk-xw0tx842.js +13 -0
  194. package/dist/chunk-xw0tx842.js.map +9 -0
  195. package/dist/chunk-xx5b6b9m.js +69 -0
  196. package/dist/chunk-xx5b6b9m.js.map +10 -0
  197. package/dist/chunk-xz1kdswj.js +21 -0
  198. package/dist/chunk-xz1kdswj.js.map +9 -0
  199. package/dist/chunk-xzvy9hr4.js +377 -0
  200. package/dist/chunk-xzvy9hr4.js.map +10 -0
  201. package/dist/chunk-yfqhr31t.js +39 -0
  202. package/dist/chunk-yfqhr31t.js.map +9 -0
  203. package/dist/chunk-ygzd5s4z.js +184 -0
  204. package/dist/chunk-ygzd5s4z.js.map +10 -0
  205. package/dist/chunk-ywjn0rad.js +14 -0
  206. package/dist/chunk-ywjn0rad.js.map +9 -0
  207. package/dist/chunk-z9nvhm6r.js +13 -0
  208. package/dist/chunk-z9nvhm6r.js.map +9 -0
  209. package/dist/chunk-zhmvdpk6.js +15 -0
  210. package/dist/chunk-zhmvdpk6.js.map +9 -0
  211. package/dist/client/index.js +32 -1112
  212. package/dist/client/index.js.map +4 -22
  213. package/dist/core/streamingSlotRegistrar.js +11 -108
  214. package/dist/core/streamingSlotRegistrar.js.map +3 -4
  215. package/dist/core/streamingSlotRegistry.js +7 -169
  216. package/dist/core/streamingSlotRegistry.js.map +3 -5
  217. package/dist/index.js +536 -19835
  218. package/dist/index.js.map +3 -117
  219. package/dist/islands/browser.js +9 -228
  220. package/dist/islands/browser.js.map +4 -9
  221. package/dist/islands/index.js +17 -1986
  222. package/dist/islands/index.js.map +3 -28
  223. package/dist/react/browser.js +12 -328
  224. package/dist/react/browser.js.map +4 -12
  225. package/dist/react/components/index.js +16 -167
  226. package/dist/react/components/index.js.map +3 -6
  227. package/dist/react/hooks/index.js +8 -183
  228. package/dist/react/hooks/index.js.map +3 -7
  229. package/dist/react/index.js +36 -3705
  230. package/dist/react/index.js.map +4 -46
  231. package/dist/react/jsxDevRuntimeCompat.js +2 -61
  232. package/dist/react/jsxDevRuntimeCompat.js.map +2 -2
  233. package/dist/react/server.js +18 -1789
  234. package/dist/react/server.js.map +3 -21
  235. package/dist/src/core/index.d.ts +0 -2
  236. package/dist/svelte/browser.js +12 -247
  237. package/dist/svelte/browser.js.map +3 -10
  238. package/dist/svelte/index.js +37 -3810
  239. package/dist/svelte/index.js.map +4 -48
  240. package/dist/svelte/server.js +21 -2787
  241. package/dist/svelte/server.js.map +3 -27
  242. package/dist/vue/browser.js +12 -348
  243. package/dist/vue/browser.js.map +4 -12
  244. package/dist/vue/components/Image.js +7 -240
  245. package/dist/vue/components/Image.js.map +3 -6
  246. package/dist/vue/components/index.js +11 -544
  247. package/dist/vue/components/index.js.map +3 -9
  248. package/dist/vue/index.js +52 -4290
  249. package/dist/vue/index.js.map +4 -51
  250. package/dist/vue/server.js +18 -1849
  251. package/dist/vue/server.js.map +3 -21
  252. package/package.json +1 -1
@@ -0,0 +1,619 @@
1
+ // @bun
2
+ import {
3
+ escapeScriptContent
4
+ } from "./chunk-851whwc7.js";
5
+ import {
6
+ getStreamSwapRuntimeScript
7
+ } from "./chunk-s6defjk2.js";
8
+ import {
9
+ BASE_36_RADIX,
10
+ RANDOM_ID_END_INDEX
11
+ } from "./chunk-qh75agse.js";
12
+
13
+ // src/utils/streamingSlots.ts
14
+ var SLOT_ID_PREFIX = "abs-slot-";
15
+ var CLOSING_BODY_TAG = "</body>";
16
+ var CLOSING_HEAD_TAG = "</head>";
17
+ var CLOSING_BODY_TAG_LENGTH = CLOSING_BODY_TAG.length;
18
+ var CLOSING_HEAD_TAG_LENGTH = CLOSING_HEAD_TAG.length;
19
+ var CLOSING_PAGE_TAG_REGEX = /<\/body>\s*<\/html>\s*$/i;
20
+ var STREAMING_RUNTIME_GLOBAL = "__ABS_SLOT_ENQUEUE__";
21
+ var STREAMING_PENDING_GLOBAL = "__ABS_SLOT_PENDING__";
22
+ var STREAM_TAIL_LOOKBEHIND = 128;
23
+ var STREAMING_SLOT_TIMEOUT_MS = 5000;
24
+ var STREAMING_SLOT_MAX_PER_RESPONSE = 128;
25
+ var STREAMING_SLOT_MAX_HTML_BYTES = 64000;
26
+ var createSlotPatchStatement = (id, payload) => `(window.${STREAMING_RUNTIME_GLOBAL}||function(i,p){window.${STREAMING_PENDING_GLOBAL}=window.${STREAMING_PENDING_GLOBAL}||{};window.${STREAMING_PENDING_GLOBAL}[i]=p;})(${JSON.stringify(id)},${JSON.stringify(payload)});`;
27
+ var createNonceAttr = (nonce) => nonce ? ` nonce="${nonce}"` : "";
28
+ var createStreamingSlotId = () => `${SLOT_ID_PREFIX}${Math.random().toString(BASE_36_RADIX).slice(2, RANDOM_ID_END_INDEX)}`;
29
+ var getStreamingSlotsRuntimeScript = () => getStreamSwapRuntimeScript();
30
+ var injectHtmlIntoBody = (html, injection) => {
31
+ const closingBodyIndex = html.indexOf(CLOSING_BODY_TAG);
32
+ if (closingBodyIndex >= 0) {
33
+ return `${html.slice(0, closingBodyIndex)}${injection}${html.slice(closingBodyIndex)}`;
34
+ }
35
+ return `${html}${injection}`;
36
+ };
37
+ var injectHtmlIntoHead = (html, injection) => {
38
+ const closingHeadIndex = html.indexOf(CLOSING_HEAD_TAG);
39
+ if (closingHeadIndex >= 0) {
40
+ return `${html.slice(0, closingHeadIndex)}${injection}${html.slice(closingHeadIndex)}`;
41
+ }
42
+ return `${html}${injection}`;
43
+ };
44
+ var renderStreamingSlotPatchTag = (id, payload, nonce) => `<script${createNonceAttr(nonce)}>${escapeScriptContent(createSlotPatchStatement(id, payload))}</script>`;
45
+ var renderStreamingSlotPlaceholder = (id, fallbackHtml = "") => `<div id="${id}" data-absolute-slot="true" data-absolute-slot-state="fallback">${fallbackHtml}</div>`;
46
+ var renderStreamingSlotsRuntimeTag = (nonce, runtimePreludeScript) => {
47
+ const runtimeBody = [
48
+ runtimePreludeScript?.trim() ? runtimePreludeScript.trim() : "",
49
+ getStreamingSlotsRuntimeScript()
50
+ ].filter(Boolean).join(";");
51
+ return `<script${createNonceAttr(nonce)}>${escapeScriptContent(runtimeBody)}</script>`;
52
+ };
53
+ var toUint8 = (value, encoder) => encoder.encode(value);
54
+ var isRecord = (value) => Boolean(value) && typeof value === "object";
55
+ var isSafeHtmlLike = (value) => isRecord(value) && typeof value.changingThisBreaksApplicationSecurity === "string";
56
+ var normalizeSafeHtml = (value) => {
57
+ if (isSafeHtmlLike(value)) {
58
+ return value.changingThisBreaksApplicationSecurity;
59
+ }
60
+ return value;
61
+ };
62
+ var currentStreamingSlotPolicy = {
63
+ errorHtml: undefined,
64
+ fallbackHtml: "",
65
+ maxSlotHtmlSizeBytes: STREAMING_SLOT_MAX_HTML_BYTES,
66
+ maxSlotsPerResponse: STREAMING_SLOT_MAX_PER_RESPONSE,
67
+ timeoutMs: STREAMING_SLOT_TIMEOUT_MS
68
+ };
69
+ var clonePolicy = (policy) => ({
70
+ ...policy
71
+ });
72
+ var normalizeSlotBytes = (value, fallback) => {
73
+ if (typeof value === "number" && Number.isFinite(value) && value >= 0) {
74
+ return Math.floor(value);
75
+ }
76
+ return fallback;
77
+ };
78
+ var normalizeSlotText = (value, fallback) => {
79
+ const normalizedValue = normalizeSafeHtml(value);
80
+ return typeof normalizedValue === "string" ? normalizedValue : fallback;
81
+ };
82
+ var normalizeSlotError = (value, fallback = undefined) => {
83
+ const safeValue = normalizeSafeHtml(value);
84
+ if (typeof safeValue === "string")
85
+ return safeValue;
86
+ return fallback;
87
+ };
88
+ var hasPolicyValue = (policy, key) => Object.prototype.hasOwnProperty.call(policy, key);
89
+ var applyStreamingSlotPolicyOverrides = (base, overridePolicy = {}) => ({
90
+ errorHtml: hasPolicyValue(overridePolicy, "errorHtml") ? normalizeSlotError(overridePolicy.errorHtml) : base.errorHtml,
91
+ fallbackHtml: hasPolicyValue(overridePolicy, "fallbackHtml") ? normalizeSlotText(overridePolicy.fallbackHtml, "") : base.fallbackHtml,
92
+ maxSlotHtmlSizeBytes: hasPolicyValue(overridePolicy, "maxSlotHtmlSizeBytes") ? normalizeSlotBytes(overridePolicy.maxSlotHtmlSizeBytes, base.maxSlotHtmlSizeBytes) : base.maxSlotHtmlSizeBytes,
93
+ maxSlotsPerResponse: hasPolicyValue(overridePolicy, "maxSlotsPerResponse") ? normalizeSlotBytes(overridePolicy.maxSlotsPerResponse, base.maxSlotsPerResponse) : base.maxSlotsPerResponse,
94
+ onError: hasPolicyValue(overridePolicy, "onError") ? overridePolicy.onError : base.onError,
95
+ onSlotMetric: hasPolicyValue(overridePolicy, "onSlotMetric") ? overridePolicy.onSlotMetric : base.onSlotMetric,
96
+ timeoutMs: hasPolicyValue(overridePolicy, "timeoutMs") ? normalizeSlotBytes(overridePolicy.timeoutMs, base.timeoutMs) : base.timeoutMs
97
+ });
98
+ var createCombinedSlotErrorHandler = (policyOnError, enhancerOnError) => {
99
+ if (!policyOnError && !enhancerOnError)
100
+ return;
101
+ return (error, slot) => {
102
+ policyOnError?.(error, slot);
103
+ enhancerOnError?.(error, slot);
104
+ };
105
+ };
106
+ var createCombinedSlotMetricHandler = (policyOnSlotMetric, callOnSlotMetric) => {
107
+ if (!policyOnSlotMetric && !callOnSlotMetric)
108
+ return;
109
+ return (metric) => {
110
+ policyOnSlotMetric?.(metric);
111
+ callOnSlotMetric?.(metric);
112
+ };
113
+ };
114
+ var resolveStreamingSlotPolicy = (overridePolicy = {}) => {
115
+ const base = getStreamingSlotPolicy();
116
+ return applyStreamingSlotPolicyOverrides(base, overridePolicy);
117
+ };
118
+ var getStreamingSlotPolicy = () => clonePolicy(currentStreamingSlotPolicy);
119
+ var setStreamingSlotPolicy = (policy = {}) => {
120
+ const base = getStreamingSlotPolicy();
121
+ currentStreamingSlotPolicy = applyStreamingSlotPolicyOverrides(base, policy);
122
+ };
123
+ var withStreamingSlotPolicy = async (policy, callback) => {
124
+ const previous = getStreamingSlotPolicy();
125
+ setStreamingSlotPolicy(policy);
126
+ try {
127
+ return await callback();
128
+ } finally {
129
+ currentStreamingSlotPolicy = previous;
130
+ }
131
+ };
132
+ var emitSlotMetric = (metric, onSlotMetric) => {
133
+ onSlotMetric?.(metric);
134
+ };
135
+ var createTimeoutError = (slot, timeoutMs) => {
136
+ const error = Object.assign(new Error(`Streaming slot "${slot.id}" timed out after ${timeoutMs}ms`), { __absTimeout: true });
137
+ return error;
138
+ };
139
+ var isSlotPatchPayloadObject = (value) => isRecord(value) && ("html" in value);
140
+ var isTimeoutError = (error) => isRecord(error) && error.__absTimeout === true;
141
+ var toStreamingSlot = (slot, policy) => ({
142
+ errorHtml: slot.errorHtml === undefined ? policy.errorHtml : slot.errorHtml,
143
+ fallbackHtml: normalizeSlotText(slot.fallbackHtml, policy.fallbackHtml),
144
+ id: slot.id ?? createStreamingSlotId(),
145
+ resolve: slot.resolve,
146
+ timeoutMs: normalizeSlotBytes(slot.timeoutMs, policy.timeoutMs)
147
+ });
148
+ var prepareSlots = ({
149
+ policy,
150
+ slots,
151
+ onError,
152
+ onSlotMetric
153
+ }) => {
154
+ const preparedSlots = slots.map((slot) => toStreamingSlot(slot, policy));
155
+ const emitPreparedSlotMetric = (slot) => {
156
+ emitSlotMetric({
157
+ slotId: slot.id,
158
+ type: "prepared"
159
+ }, onSlotMetric);
160
+ };
161
+ const dropPreparedSlot = (slot, reason) => {
162
+ onError?.(new Error(reason), slot);
163
+ emitSlotMetric({
164
+ reason,
165
+ slotId: slot.id,
166
+ type: "dropped"
167
+ }, onSlotMetric);
168
+ };
169
+ const { maxSlotsPerResponse } = policy;
170
+ if (maxSlotsPerResponse === 0) {
171
+ preparedSlots.forEach((slot) => dropPreparedSlot(slot, "maxSlotsPerResponse is 0"));
172
+ return [];
173
+ }
174
+ if (preparedSlots.length <= maxSlotsPerResponse) {
175
+ preparedSlots.forEach(emitPreparedSlotMetric);
176
+ return preparedSlots;
177
+ }
178
+ const keptSlots = preparedSlots.slice(0, maxSlotsPerResponse);
179
+ const droppedSlots = preparedSlots.slice(maxSlotsPerResponse);
180
+ droppedSlots.forEach((slot) => {
181
+ dropPreparedSlot(slot, `Streaming slot "${slot.id}" dropped because ${maxSlotsPerResponse} slots is the configured maximum`);
182
+ });
183
+ keptSlots.forEach(emitPreparedSlotMetric);
184
+ return keptSlots;
185
+ };
186
+ var htmlByteLength = (value, encoder) => encoder.encode(value).length;
187
+ var normalizeSlotPatchPayload = (value) => {
188
+ const safeValue = normalizeSafeHtml(value);
189
+ if (isSlotPatchPayloadObject(safeValue) && typeof safeValue.html === "string") {
190
+ return {
191
+ ...safeValue,
192
+ html: normalizeSlotText(safeValue.html, "")
193
+ };
194
+ }
195
+ return typeof safeValue === "string" ? safeValue : `${safeValue}`;
196
+ };
197
+ var getPayloadHtml = (payload) => typeof payload === "string" ? payload : payload.html;
198
+ var enqueueEncodedText = (controller, encoder, value) => {
199
+ if (value.length === 0) {
200
+ return;
201
+ }
202
+ controller.enqueue(encoder.encode(value));
203
+ };
204
+ var readStreamingRuntimeChunk = async (reader) => {
205
+ const { done, value } = await reader.read();
206
+ if (done || !value) {
207
+ return { done, value: undefined };
208
+ }
209
+ return { done, value };
210
+ };
211
+ var applyBaseWinnerState = (state, winner, handleResolved) => {
212
+ if (!state.handled && winner.kind === "slot") {
213
+ handleResolved(winner);
214
+ }
215
+ return state;
216
+ };
217
+ var resolveOversizedSlotPayload = (input) => {
218
+ const {
219
+ encoder,
220
+ html,
221
+ maxSlotHtmlSizeBytes,
222
+ onError,
223
+ onSlotMetric,
224
+ slot,
225
+ start
226
+ } = input;
227
+ const bytes = htmlByteLength(html, encoder);
228
+ if (bytes <= maxSlotHtmlSizeBytes) {
229
+ return null;
230
+ }
231
+ const error = new Error(`Streaming slot "${slot.id}" exceeded max payload size of ${maxSlotHtmlSizeBytes} bytes`);
232
+ const durationMs = Date.now() - start;
233
+ onError?.(error, slot);
234
+ emitSlotMetric({
235
+ bytes,
236
+ durationMs,
237
+ error,
238
+ slotId: slot.id,
239
+ type: "size_exceeded"
240
+ }, onSlotMetric);
241
+ const fallbackHtml = normalizeSlotError(slot.errorHtml, undefined);
242
+ return {
243
+ bytes: fallbackHtml === undefined ? 0 : htmlByteLength(fallbackHtml, encoder),
244
+ durationMs,
245
+ id: slot.id,
246
+ payload: fallbackHtml === undefined ? null : fallbackHtml
247
+ };
248
+ };
249
+ var raceWithTimeout = (promise, slot) => {
250
+ const { timeoutMs } = slot;
251
+ if (typeof timeoutMs !== "number" || timeoutMs <= 0) {
252
+ return promise;
253
+ }
254
+ const { promise: timeoutPromise, reject } = Promise.withResolvers();
255
+ setTimeout(() => {
256
+ reject(createTimeoutError(slot, timeoutMs));
257
+ }, timeoutMs);
258
+ return Promise.race([promise, timeoutPromise]);
259
+ };
260
+ var resolveSlot = async (slot, onError, policy, onSlotMetric) => {
261
+ const safePolicy = policy ?? getStreamingSlotPolicy();
262
+ const encoder = new TextEncoder;
263
+ const start = Date.now();
264
+ try {
265
+ const maybeAsyncValue = Promise.resolve(slot.resolve());
266
+ const resolved = await raceWithTimeout(maybeAsyncValue, slot);
267
+ const payload = normalizeSlotPatchPayload(resolved);
268
+ const html = getPayloadHtml(payload);
269
+ const oversizedResult = safePolicy.maxSlotHtmlSizeBytes > 0 ? resolveOversizedSlotPayload({
270
+ encoder,
271
+ html,
272
+ maxSlotHtmlSizeBytes: safePolicy.maxSlotHtmlSizeBytes,
273
+ onError,
274
+ onSlotMetric,
275
+ slot,
276
+ start
277
+ }) : null;
278
+ if (oversizedResult) {
279
+ return oversizedResult;
280
+ }
281
+ const durationMs = Date.now() - start;
282
+ const bytes = htmlByteLength(html, encoder);
283
+ emitSlotMetric({
284
+ bytes,
285
+ durationMs,
286
+ slotId: slot.id,
287
+ type: "resolved"
288
+ }, onSlotMetric);
289
+ return {
290
+ bytes,
291
+ durationMs,
292
+ id: slot.id,
293
+ payload
294
+ };
295
+ } catch (error) {
296
+ const durationMs = Date.now() - start;
297
+ onError?.(error, slot);
298
+ emitSlotMetric({
299
+ durationMs,
300
+ error,
301
+ slotId: slot.id,
302
+ type: isTimeoutError(error) ? "timeout" : "error"
303
+ }, onSlotMetric);
304
+ const html = normalizeSlotError(slot.errorHtml, undefined);
305
+ if (html) {
306
+ return {
307
+ bytes: htmlByteLength(html, encoder),
308
+ durationMs,
309
+ id: slot.id,
310
+ payload: html
311
+ };
312
+ }
313
+ return {
314
+ bytes: 0,
315
+ durationMs,
316
+ id: slot.id,
317
+ payload: null
318
+ };
319
+ }
320
+ };
321
+ var nextResolvedSlot = async (pending) => {
322
+ const wrapped = pending.map((promise) => promise.then((result) => ({
323
+ original: promise,
324
+ result
325
+ })));
326
+ return Promise.race(wrapped);
327
+ };
328
+ var streamChunkToString = (value, decoder) => typeof value === "string" ? value : decoder.decode(value, { stream: true });
329
+ var appendStreamingSlotPatchesToStream = (stream, slots = [], {
330
+ injectRuntime = true,
331
+ nonce,
332
+ onError,
333
+ onSlotMetric,
334
+ policy,
335
+ runtimePreludeScript,
336
+ runtimePlacement = "head"
337
+ } = {}) => {
338
+ const resolvedPolicy = resolveStreamingSlotPolicy(policy);
339
+ const combinedOnError = createCombinedSlotErrorHandler(resolvedPolicy.onError, onError);
340
+ const combinedOnSlotMetric = createCombinedSlotMetricHandler(resolvedPolicy.onSlotMetric, onSlotMetric);
341
+ const effectivePolicy = {
342
+ ...resolvedPolicy,
343
+ onSlotMetric: combinedOnSlotMetric
344
+ };
345
+ const preparedSlots = prepareSlots({
346
+ onError: combinedOnError,
347
+ onSlotMetric: combinedOnSlotMetric,
348
+ policy: effectivePolicy,
349
+ slots
350
+ });
351
+ if (preparedSlots.length === 0)
352
+ return stream;
353
+ const source = injectRuntime ? injectStreamingRuntimeIntoStream(stream, nonce, runtimePlacement, runtimePreludeScript) : stream;
354
+ const encoder = new TextEncoder;
355
+ const decoder = new TextDecoder;
356
+ const reader = source.getReader();
357
+ const pending = preparedSlots.map((slot) => resolveSlot(slot, combinedOnError, effectivePolicy, combinedOnSlotMetric));
358
+ const createRaceCandidates = (baseDone, baseRead) => {
359
+ const racers = [];
360
+ if (!baseDone) {
361
+ racers.push(baseRead.then(({ done, value }) => ({
362
+ done,
363
+ kind: "base",
364
+ value
365
+ })));
366
+ }
367
+ if (pending.length > 0) {
368
+ racers.push(nextResolvedSlot(pending).then((resolved) => ({
369
+ kind: "slot",
370
+ ...resolved
371
+ })));
372
+ }
373
+ return racers;
374
+ };
375
+ const flushTailLookbehind = (controller, tail) => {
376
+ if (tail.length <= STREAM_TAIL_LOOKBEHIND) {
377
+ return tail;
378
+ }
379
+ const content = tail.slice(0, tail.length - STREAM_TAIL_LOOKBEHIND);
380
+ controller.enqueue(encoder.encode(content));
381
+ return tail.slice(-STREAM_TAIL_LOOKBEHIND);
382
+ };
383
+ const finalizeCompletedBaseWinner = (controller, decodedTail, baseRead) => {
384
+ const footerStart = decodedTail.search(CLOSING_PAGE_TAG_REGEX);
385
+ if (footerStart < 0) {
386
+ enqueueEncodedText(controller, encoder, decodedTail);
387
+ return {
388
+ baseDone: true,
389
+ baseRead,
390
+ footer: "",
391
+ handled: true,
392
+ tail: ""
393
+ };
394
+ }
395
+ const content = decodedTail.slice(0, footerStart);
396
+ const nextFooter = decodedTail.slice(footerStart);
397
+ enqueueEncodedText(controller, encoder, content);
398
+ return {
399
+ baseDone: true,
400
+ baseRead,
401
+ footer: nextFooter,
402
+ handled: true,
403
+ tail: ""
404
+ };
405
+ };
406
+ const handleBaseWinner = (controller, winner, baseRead, tail, footer) => {
407
+ if (winner.kind !== "base") {
408
+ return { baseDone: false, baseRead, footer, handled: false, tail };
409
+ }
410
+ if (winner.done) {
411
+ return finalizeCompletedBaseWinner(controller, tail + decoder.decode(), baseRead);
412
+ }
413
+ if (!winner.value) {
414
+ return { baseDone: false, baseRead, footer, handled: true, tail };
415
+ }
416
+ const nextTail = flushTailLookbehind(controller, tail + streamChunkToString(winner.value, decoder));
417
+ return {
418
+ baseDone: false,
419
+ baseRead: reader.read(),
420
+ footer,
421
+ handled: true,
422
+ tail: nextTail
423
+ };
424
+ };
425
+ const handleResolvedSlot = (controller, winner) => {
426
+ const index = pending.indexOf(winner.original);
427
+ if (index >= 0)
428
+ pending.splice(index, 1);
429
+ if (winner.result.payload === null) {
430
+ return;
431
+ }
432
+ emitSlotMetric({
433
+ bytes: winner.result.bytes,
434
+ durationMs: winner.result.durationMs,
435
+ slotId: winner.result.id,
436
+ type: "patched"
437
+ }, combinedOnSlotMetric);
438
+ controller.enqueue(encoder.encode(renderStreamingSlotPatchTag(winner.result.id, winner.result.payload, nonce)));
439
+ };
440
+ const runPatchedStreamLoop = async (controller) => {
441
+ let baseDone = false;
442
+ let baseRead = reader.read();
443
+ let tail = "";
444
+ let footer = "";
445
+ const readNextRaceWinner = async () => {
446
+ const racers = createRaceCandidates(baseDone, baseRead);
447
+ if (racers.length === 0) {
448
+ return footer;
449
+ }
450
+ const winner = await Promise.race(racers);
451
+ const baseWinnerState = applyBaseWinnerState(handleBaseWinner(controller, winner, baseRead, tail, footer), winner, (slotWinner) => {
452
+ handleResolvedSlot(controller, slotWinner);
453
+ });
454
+ ({ baseDone, baseRead, footer, tail } = baseWinnerState);
455
+ if (baseDone && pending.length === 0) {
456
+ return footer;
457
+ }
458
+ return readNextRaceWinner();
459
+ };
460
+ return readNextRaceWinner();
461
+ };
462
+ return new ReadableStream({
463
+ async start(controller) {
464
+ try {
465
+ const footer = await runPatchedStreamLoop(controller);
466
+ enqueueEncodedText(controller, encoder, footer);
467
+ controller.close();
468
+ } catch (error) {
469
+ controller.error(error);
470
+ }
471
+ }
472
+ });
473
+ };
474
+ var injectStreamingRuntimeIntoStream = (stream, nonce, runtimePlacement = "head", runtimePreludeScript) => {
475
+ const runtimeTag = renderStreamingSlotsRuntimeTag(nonce, runtimePreludeScript);
476
+ const encoder = new TextEncoder;
477
+ const decoder = new TextDecoder;
478
+ const closingTag = runtimePlacement === "body" ? CLOSING_BODY_TAG : CLOSING_HEAD_TAG;
479
+ const lookbehind = (runtimePlacement === "body" ? CLOSING_BODY_TAG_LENGTH : CLOSING_HEAD_TAG_LENGTH) - 1;
480
+ const flushRuntimeLookbehind = (controller, pending) => {
481
+ if (pending.length <= lookbehind) {
482
+ return pending;
483
+ }
484
+ const safeText = pending.slice(0, pending.length - lookbehind);
485
+ controller.enqueue(encoder.encode(safeText));
486
+ return pending.slice(-lookbehind);
487
+ };
488
+ const injectRuntimeIntoPending = (pending) => runtimePlacement === "body" ? injectHtmlIntoBody(pending, runtimeTag) : injectHtmlIntoHead(pending, runtimeTag);
489
+ const processRuntimePending = (controller, pending, injected) => {
490
+ if (injected) {
491
+ controller.enqueue(encoder.encode(pending));
492
+ return { injected, pending: "" };
493
+ }
494
+ const closingTagIndex = pending.indexOf(closingTag);
495
+ if (closingTagIndex >= 0) {
496
+ const withRuntime = `${pending.slice(0, closingTagIndex)}${runtimeTag}${pending.slice(closingTagIndex)}`;
497
+ controller.enqueue(encoder.encode(withRuntime));
498
+ return { injected: true, pending: "" };
499
+ }
500
+ return {
501
+ injected,
502
+ pending: flushRuntimeLookbehind(controller, pending)
503
+ };
504
+ };
505
+ return new ReadableStream({
506
+ async start(controller) {
507
+ const reader = stream.getReader();
508
+ let injected = false;
509
+ let pending = "";
510
+ const enqueuePending = () => enqueueEncodedText(controller, encoder, pending);
511
+ const consumeRuntimeChunk = async () => {
512
+ const { done, value } = await readStreamingRuntimeChunk(reader);
513
+ if (done || !value) {
514
+ return done;
515
+ }
516
+ pending += streamChunkToString(value, decoder);
517
+ ({ injected, pending } = processRuntimePending(controller, pending, injected));
518
+ return false;
519
+ };
520
+ const runRuntimeInjectionLoop = async () => {
521
+ const done = await consumeRuntimeChunk();
522
+ if (done) {
523
+ return;
524
+ }
525
+ await runRuntimeInjectionLoop();
526
+ };
527
+ try {
528
+ await runRuntimeInjectionLoop();
529
+ pending += decoder.decode();
530
+ pending = injected ? pending : injectRuntimeIntoPending(pending);
531
+ enqueuePending();
532
+ controller.close();
533
+ } catch (error) {
534
+ controller.error(error);
535
+ }
536
+ }
537
+ });
538
+ };
539
+ var streamOutOfOrderSlots = ({
540
+ footerHtml = "",
541
+ headerHtml = "",
542
+ nonce,
543
+ policy,
544
+ onSlotMetric,
545
+ onError,
546
+ slots
547
+ }) => {
548
+ const resolvedPolicy = resolveStreamingSlotPolicy(policy);
549
+ const combinedOnError = createCombinedSlotErrorHandler(resolvedPolicy.onError, onError);
550
+ const combinedOnSlotMetric = createCombinedSlotMetricHandler(resolvedPolicy.onSlotMetric, onSlotMetric);
551
+ const effectivePolicy = {
552
+ ...resolvedPolicy,
553
+ onSlotMetric: combinedOnSlotMetric
554
+ };
555
+ const preparedSlots = prepareSlots({
556
+ onError: combinedOnError,
557
+ onSlotMetric: combinedOnSlotMetric,
558
+ policy: effectivePolicy,
559
+ slots
560
+ });
561
+ const encoder = new TextEncoder;
562
+ const createPendingSlots = (controller) => preparedSlots.map((slot) => {
563
+ const fallback = renderStreamingSlotPlaceholder(slot.id, normalizeSlotText(slot.fallbackHtml, ""));
564
+ controller.enqueue(toUint8(fallback, encoder));
565
+ return resolveSlot(slot, combinedOnError, effectivePolicy, combinedOnSlotMetric);
566
+ });
567
+ const handleResolvedPreparedSlot = async (controller, pending) => {
568
+ const { original, result } = await nextResolvedSlot(pending);
569
+ const index = pending.indexOf(original);
570
+ if (index >= 0)
571
+ pending.splice(index, 1);
572
+ if (result.payload === null) {
573
+ return;
574
+ }
575
+ emitSlotMetric({
576
+ bytes: result.bytes,
577
+ durationMs: result.durationMs,
578
+ slotId: result.id,
579
+ type: "patched"
580
+ }, combinedOnSlotMetric);
581
+ controller.enqueue(toUint8(renderStreamingSlotPatchTag(result.id, result.payload, nonce), encoder));
582
+ };
583
+ const streamPreparedSlots = async (controller) => {
584
+ const pending = createPendingSlots(controller);
585
+ const streamNextPreparedSlot = async () => {
586
+ if (pending.length === 0) {
587
+ return;
588
+ }
589
+ await handleResolvedPreparedSlot(controller, pending);
590
+ await streamNextPreparedSlot();
591
+ };
592
+ await streamNextPreparedSlot();
593
+ };
594
+ const resolveHeaderHtml = () => {
595
+ const needsRuntimeTag = preparedSlots.length > 0 && !headerHtml.includes(STREAMING_RUNTIME_GLOBAL);
596
+ if (!needsRuntimeTag) {
597
+ return headerHtml;
598
+ }
599
+ return injectHtmlIntoHead(headerHtml, renderStreamingSlotsRuntimeTag(nonce));
600
+ };
601
+ return new ReadableStream({
602
+ async start(controller) {
603
+ try {
604
+ const header = resolveHeaderHtml();
605
+ controller.enqueue(toUint8(header, encoder));
606
+ await streamPreparedSlots(controller);
607
+ enqueueEncodedText(controller, encoder, footerHtml);
608
+ controller.close();
609
+ } catch (error) {
610
+ controller.error(error);
611
+ }
612
+ }
613
+ });
614
+ };
615
+
616
+ export { createStreamingSlotId, getStreamingSlotsRuntimeScript, injectHtmlIntoBody, injectHtmlIntoHead, renderStreamingSlotPatchTag, renderStreamingSlotPlaceholder, renderStreamingSlotsRuntimeTag, getStreamingSlotPolicy, setStreamingSlotPolicy, withStreamingSlotPolicy, appendStreamingSlotPatchesToStream, injectStreamingRuntimeIntoStream, streamOutOfOrderSlots };
617
+
618
+ //# debugId=469B6C14F150BF0864756E2164756E21
619
+ //# sourceMappingURL=chunk-sd39p726.js.map