@absolutejs/absolute 0.19.0-beta.808 → 0.19.0-beta.809

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 (260) hide show
  1. package/dist/angular/browser.js +9801 -57
  2. package/dist/angular/browser.js.map +246 -4
  3. package/dist/angular/components/core/streamingSlotRegistrar.js +1 -1
  4. package/dist/angular/components/core/streamingSlotRegistry.js +2 -2
  5. package/dist/angular/index.js +14877 -60
  6. package/dist/angular/index.js.map +281 -4
  7. package/dist/angular/server.js +5610 -45
  8. package/dist/angular/server.js.map +51 -3
  9. package/dist/build.js +18092 -45
  10. package/dist/build.js.map +99 -3
  11. package/dist/cli/index.js +317 -86
  12. package/dist/client/index.js +1100 -40
  13. package/dist/client/index.js.map +24 -4
  14. package/dist/core/streamingSlotRegistrar.js +108 -11
  15. package/dist/core/streamingSlotRegistrar.js.map +4 -3
  16. package/dist/core/streamingSlotRegistry.js +169 -7
  17. package/dist/core/streamingSlotRegistry.js.map +5 -3
  18. package/dist/index.js +19957 -547
  19. package/dist/index.js.map +116 -3
  20. package/dist/islands/browser.js +228 -9
  21. package/dist/islands/browser.js.map +9 -4
  22. package/dist/islands/index.js +1908 -17
  23. package/dist/islands/index.js.map +27 -3
  24. package/dist/react/browser.js +328 -12
  25. package/dist/react/browser.js.map +12 -4
  26. package/dist/react/components/index.js +167 -16
  27. package/dist/react/components/index.js.map +6 -3
  28. package/dist/react/hooks/index.js +183 -8
  29. package/dist/react/hooks/index.js.map +7 -3
  30. package/dist/react/index.js +3627 -36
  31. package/dist/react/index.js.map +45 -4
  32. package/dist/react/jsxDevRuntimeCompat.js +61 -2
  33. package/dist/react/jsxDevRuntimeCompat.js.map +2 -2
  34. package/dist/react/server.js +1789 -18
  35. package/dist/react/server.js.map +21 -3
  36. package/dist/src/angular/injectorPatch.d.ts +1 -0
  37. package/dist/src/index.d.ts +1 -0
  38. package/dist/svelte/browser.js +247 -12
  39. package/dist/svelte/browser.js.map +10 -3
  40. package/dist/svelte/index.js +3732 -37
  41. package/dist/svelte/index.js.map +47 -4
  42. package/dist/svelte/server.js +2794 -21
  43. package/dist/svelte/server.js.map +27 -3
  44. package/dist/vue/browser.js +348 -12
  45. package/dist/vue/browser.js.map +12 -4
  46. package/dist/vue/components/Image.js +240 -7
  47. package/dist/vue/components/Image.js.map +6 -3
  48. package/dist/vue/components/index.js +544 -11
  49. package/dist/vue/components/index.js.map +9 -3
  50. package/dist/vue/index.js +4212 -52
  51. package/dist/vue/index.js.map +50 -4
  52. package/dist/vue/server.js +1849 -18
  53. package/dist/vue/server.js.map +21 -3
  54. package/package.json +1 -1
  55. package/dist/chunk-0867j0r0.js +0 -136
  56. package/dist/chunk-0867j0r0.js.map +0 -10
  57. package/dist/chunk-0kdc6r16.js +0 -20
  58. package/dist/chunk-0kdc6r16.js.map +0 -10
  59. package/dist/chunk-102fp7xe.js +0 -63
  60. package/dist/chunk-102fp7xe.js.map +0 -10
  61. package/dist/chunk-11zpfqz6.js +0 -19
  62. package/dist/chunk-11zpfqz6.js.map +0 -10
  63. package/dist/chunk-1rfh7hw9.js +0 -319
  64. package/dist/chunk-1rfh7hw9.js.map +0 -11
  65. package/dist/chunk-25v9t56f.js +0 -29
  66. package/dist/chunk-25v9t56f.js.map +0 -11
  67. package/dist/chunk-2f21eenc.js +0 -21
  68. package/dist/chunk-2f21eenc.js.map +0 -10
  69. package/dist/chunk-2ga2znex.js +0 -13
  70. package/dist/chunk-2ga2znex.js.map +0 -9
  71. package/dist/chunk-30yrw0f6.js +0 -33
  72. package/dist/chunk-30yrw0f6.js.map +0 -10
  73. package/dist/chunk-38jwhqcw.js +0 -4410
  74. package/dist/chunk-38jwhqcw.js.map +0 -28
  75. package/dist/chunk-3g91wb4f.js +0 -358
  76. package/dist/chunk-3g91wb4f.js.map +0 -10
  77. package/dist/chunk-3yjzpcne.js +0 -34
  78. package/dist/chunk-3yjzpcne.js.map +0 -10
  79. package/dist/chunk-41bf6aqt.js +0 -17
  80. package/dist/chunk-41bf6aqt.js.map +0 -9
  81. package/dist/chunk-4d39r92n.js +0 -81
  82. package/dist/chunk-4d39r92n.js.map +0 -10
  83. package/dist/chunk-5003emhv.js +0 -17
  84. package/dist/chunk-5003emhv.js.map +0 -10
  85. package/dist/chunk-5f67rsed.js +0 -466
  86. package/dist/chunk-5f67rsed.js.map +0 -10
  87. package/dist/chunk-5fhp1jap.js +0 -9169
  88. package/dist/chunk-5fhp1jap.js.map +0 -236
  89. package/dist/chunk-6pdj08z3.js +0 -73
  90. package/dist/chunk-6pdj08z3.js.map +0 -12
  91. package/dist/chunk-6qjbrt0k.js +0 -13
  92. package/dist/chunk-6qjbrt0k.js.map +0 -9
  93. package/dist/chunk-6sccb4jr.js +0 -14
  94. package/dist/chunk-6sccb4jr.js.map +0 -9
  95. package/dist/chunk-798spvzv.js +0 -50
  96. package/dist/chunk-798spvzv.js.map +0 -10
  97. package/dist/chunk-7fw6x3js.js +0 -131
  98. package/dist/chunk-7fw6x3js.js.map +0 -11
  99. package/dist/chunk-7kjj42xm.js +0 -11
  100. package/dist/chunk-7kjj42xm.js.map +0 -10
  101. package/dist/chunk-7mtstdqn.js +0 -90
  102. package/dist/chunk-7mtstdqn.js.map +0 -10
  103. package/dist/chunk-851whwc7.js +0 -17
  104. package/dist/chunk-851whwc7.js.map +0 -10
  105. package/dist/chunk-85n68sy6.js +0 -103
  106. package/dist/chunk-85n68sy6.js.map +0 -10
  107. package/dist/chunk-8kcfffry.js +0 -35
  108. package/dist/chunk-8kcfffry.js.map +0 -10
  109. package/dist/chunk-8qqxc1h2.js +0 -426
  110. package/dist/chunk-8qqxc1h2.js.map +0 -14
  111. package/dist/chunk-92fsjfpp.js +0 -1731
  112. package/dist/chunk-92fsjfpp.js.map +0 -11
  113. package/dist/chunk-93sqk7be.js +0 -139
  114. package/dist/chunk-93sqk7be.js.map +0 -12
  115. package/dist/chunk-94gvx0hg.js +0 -28
  116. package/dist/chunk-94gvx0hg.js.map +0 -10
  117. package/dist/chunk-9c5tj4k3.js +0 -130
  118. package/dist/chunk-9c5tj4k3.js.map +0 -10
  119. package/dist/chunk-9ve9jq72.js +0 -203
  120. package/dist/chunk-9ve9jq72.js.map +0 -10
  121. package/dist/chunk-9xrsjeem.js +0 -12
  122. package/dist/chunk-9xrsjeem.js.map +0 -9
  123. package/dist/chunk-a9mvyp04.js +0 -87
  124. package/dist/chunk-a9mvyp04.js.map +0 -10
  125. package/dist/chunk-b3gbnrwe.js +0 -21
  126. package/dist/chunk-b3gbnrwe.js.map +0 -10
  127. package/dist/chunk-bmgqm774.js +0 -65
  128. package/dist/chunk-bmgqm774.js.map +0 -9
  129. package/dist/chunk-bxfghpma.js +0 -69
  130. package/dist/chunk-bxfghpma.js.map +0 -10
  131. package/dist/chunk-c1jfjnka.js +0 -74
  132. package/dist/chunk-c1jfjnka.js.map +0 -10
  133. package/dist/chunk-cbkrwmvh.js +0 -80
  134. package/dist/chunk-cbkrwmvh.js.map +0 -10
  135. package/dist/chunk-cdxd7sy2.js +0 -71
  136. package/dist/chunk-cdxd7sy2.js.map +0 -10
  137. package/dist/chunk-cg95827x.js +0 -21
  138. package/dist/chunk-cg95827x.js.map +0 -10
  139. package/dist/chunk-cm0g4q6w.js +0 -149
  140. package/dist/chunk-cm0g4q6w.js.map +0 -10
  141. package/dist/chunk-cwfy538a.js +0 -51
  142. package/dist/chunk-cwfy538a.js.map +0 -9
  143. package/dist/chunk-d7mwkzry.js +0 -261
  144. package/dist/chunk-d7mwkzry.js.map +0 -10
  145. package/dist/chunk-d8w0qm28.js +0 -184
  146. package/dist/chunk-d8w0qm28.js.map +0 -11
  147. package/dist/chunk-d9c0am65.js +0 -12
  148. package/dist/chunk-d9c0am65.js.map +0 -10
  149. package/dist/chunk-daqghmg8.js +0 -12
  150. package/dist/chunk-daqghmg8.js.map +0 -9
  151. package/dist/chunk-e3r9fxaa.js +0 -149
  152. package/dist/chunk-e3r9fxaa.js.map +0 -10
  153. package/dist/chunk-e8eecyrq.js +0 -244
  154. package/dist/chunk-e8eecyrq.js.map +0 -10
  155. package/dist/chunk-ex2hxe0v.js +0 -160
  156. package/dist/chunk-ex2hxe0v.js.map +0 -11
  157. package/dist/chunk-fak944et.js +0 -91
  158. package/dist/chunk-fak944et.js.map +0 -10
  159. package/dist/chunk-ff70rnhd.js +0 -672
  160. package/dist/chunk-ff70rnhd.js.map +0 -15
  161. package/dist/chunk-fygx2ymm.js +0 -118
  162. package/dist/chunk-fygx2ymm.js.map +0 -12
  163. package/dist/chunk-g15qj669.js +0 -271
  164. package/dist/chunk-g15qj669.js.map +0 -11
  165. package/dist/chunk-gd6wmknh.js +0 -121
  166. package/dist/chunk-gd6wmknh.js.map +0 -11
  167. package/dist/chunk-gf0ygptk.js +0 -85
  168. package/dist/chunk-gf0ygptk.js.map +0 -11
  169. package/dist/chunk-gytkmthr.js +0 -220
  170. package/dist/chunk-gytkmthr.js.map +0 -10
  171. package/dist/chunk-h5bbfn3n.js +0 -28
  172. package/dist/chunk-h5bbfn3n.js.map +0 -11
  173. package/dist/chunk-h6mye9r3.js +0 -93
  174. package/dist/chunk-h6mye9r3.js.map +0 -10
  175. package/dist/chunk-hcsmxw1v.js +0 -85
  176. package/dist/chunk-hcsmxw1v.js.map +0 -10
  177. package/dist/chunk-hyjs4bqs.js +0 -8
  178. package/dist/chunk-hyjs4bqs.js.map +0 -10
  179. package/dist/chunk-j88z31ep.js +0 -25
  180. package/dist/chunk-j88z31ep.js.map +0 -10
  181. package/dist/chunk-jn91vzkh.js +0 -66
  182. package/dist/chunk-jn91vzkh.js.map +0 -10
  183. package/dist/chunk-jpkjdgsk.js +0 -167
  184. package/dist/chunk-jpkjdgsk.js.map +0 -11
  185. package/dist/chunk-jwxt8gnp.js +0 -13
  186. package/dist/chunk-jwxt8gnp.js.map +0 -9
  187. package/dist/chunk-kk8w9rh5.js +0 -195
  188. package/dist/chunk-kk8w9rh5.js.map +0 -10
  189. package/dist/chunk-m97ze5hz.js +0 -46
  190. package/dist/chunk-m97ze5hz.js.map +0 -10
  191. package/dist/chunk-mbazhahf.js +0 -60
  192. package/dist/chunk-mbazhahf.js.map +0 -10
  193. package/dist/chunk-mgfwq18r.js +0 -15
  194. package/dist/chunk-mgfwq18r.js.map +0 -9
  195. package/dist/chunk-mtgf69xn.js +0 -88
  196. package/dist/chunk-mtgf69xn.js.map +0 -10
  197. package/dist/chunk-mtxzyxpg.js +0 -102
  198. package/dist/chunk-mtxzyxpg.js.map +0 -10
  199. package/dist/chunk-nehhtthw.js +0 -225
  200. package/dist/chunk-nehhtthw.js.map +0 -10
  201. package/dist/chunk-p5504p14.js +0 -16
  202. package/dist/chunk-p5504p14.js.map +0 -10
  203. package/dist/chunk-pnscgw95.js +0 -90
  204. package/dist/chunk-pnscgw95.js.map +0 -10
  205. package/dist/chunk-pvpp4pvs.js +0 -17
  206. package/dist/chunk-pvpp4pvs.js.map +0 -10
  207. package/dist/chunk-qh75agse.js +0 -95
  208. package/dist/chunk-qh75agse.js.map +0 -10
  209. package/dist/chunk-qxq2zcty.js +0 -52
  210. package/dist/chunk-qxq2zcty.js.map +0 -10
  211. package/dist/chunk-r6e8pytx.js +0 -22
  212. package/dist/chunk-r6e8pytx.js.map +0 -9
  213. package/dist/chunk-r7jmgqnw.js +0 -114
  214. package/dist/chunk-r7jmgqnw.js.map +0 -10
  215. package/dist/chunk-s6defjk2.js +0 -116
  216. package/dist/chunk-s6defjk2.js.map +0 -10
  217. package/dist/chunk-sd39p726.js +0 -619
  218. package/dist/chunk-sd39p726.js.map +0 -10
  219. package/dist/chunk-swrnzs4c.js +0 -63
  220. package/dist/chunk-swrnzs4c.js.map +0 -10
  221. package/dist/chunk-tfe3sb44.js +0 -33
  222. package/dist/chunk-tfe3sb44.js.map +0 -10
  223. package/dist/chunk-tjr0kcev.js +0 -41
  224. package/dist/chunk-tjr0kcev.js.map +0 -9
  225. package/dist/chunk-tx9edm1x.js +0 -34
  226. package/dist/chunk-tx9edm1x.js.map +0 -10
  227. package/dist/chunk-txhm2vb5.js +0 -18
  228. package/dist/chunk-txhm2vb5.js.map +0 -9
  229. package/dist/chunk-v5vmsxmy.js +0 -526
  230. package/dist/chunk-v5vmsxmy.js.map +0 -12
  231. package/dist/chunk-vjhxm8n2.js +0 -29
  232. package/dist/chunk-vjhxm8n2.js.map +0 -9
  233. package/dist/chunk-vkrpm7kc.js +0 -247
  234. package/dist/chunk-vkrpm7kc.js.map +0 -12
  235. package/dist/chunk-w3m4m5we.js +0 -4925
  236. package/dist/chunk-w3m4m5we.js.map +0 -12
  237. package/dist/chunk-wrxtn9ve.js +0 -18
  238. package/dist/chunk-wrxtn9ve.js.map +0 -10
  239. package/dist/chunk-wwzvp0zn.js +0 -192
  240. package/dist/chunk-wwzvp0zn.js.map +0 -10
  241. package/dist/chunk-x09cskqd.js +0 -377
  242. package/dist/chunk-x09cskqd.js.map +0 -10
  243. package/dist/chunk-xnt8c6h2.js +0 -576
  244. package/dist/chunk-xnt8c6h2.js.map +0 -10
  245. package/dist/chunk-xw0tx842.js +0 -13
  246. package/dist/chunk-xw0tx842.js.map +0 -9
  247. package/dist/chunk-xx5b6b9m.js +0 -69
  248. package/dist/chunk-xx5b6b9m.js.map +0 -10
  249. package/dist/chunk-xz1kdswj.js +0 -21
  250. package/dist/chunk-xz1kdswj.js.map +0 -9
  251. package/dist/chunk-y84qnsd3.js +0 -32
  252. package/dist/chunk-y84qnsd3.js.map +0 -10
  253. package/dist/chunk-ywjn0rad.js +0 -14
  254. package/dist/chunk-ywjn0rad.js.map +0 -9
  255. package/dist/chunk-z9nvhm6r.js +0 -13
  256. package/dist/chunk-z9nvhm6r.js.map +0 -9
  257. package/dist/chunk-zhmvdpk6.js +0 -15
  258. package/dist/chunk-zhmvdpk6.js.map +0 -9
  259. package/dist/chunk-zrg9d4zw.js +0 -784
  260. package/dist/chunk-zrg9d4zw.js.map +0 -10
@@ -1,619 +0,0 @@
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