acrylblends 1.0.3 → 1.0.5

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 (256) hide show
  1. package/docs/framework/agents/index.md +6 -4
  2. package/docs/framework/workshop/README.md +3 -3
  3. package/docs/framework/workshop/facilitator.md +1 -0
  4. package/lib/accept-CNNHu4Cf.js +193 -0
  5. package/lib/{accepts-XBuZPVRI.js → accepts-Btq83xPd.js} +1 -1
  6. package/lib/accepts.js +1 -1
  7. package/lib/acryl-base.js +1 -331
  8. package/lib/adapter-CaZ6FZUU.js +37 -0
  9. package/lib/adapter.js +1 -36
  10. package/lib/{app-BM0rTCp7.js → app-CQcGWjrk.js} +4 -4
  11. package/lib/app-base-CpRMZL4v.js +332 -0
  12. package/lib/{audit-BXnYsLge.d.ts → audit-D5z9uwOP.d.ts} +14 -1
  13. package/lib/{base-NSN_SNv-.js → base-D_6kfOr-.js} +1 -1
  14. package/lib/basic-auth-C0HTRpXh.js +20 -0
  15. package/lib/basic-auth-DFLflXNe.js +95 -0
  16. package/lib/basic-auth.js +1 -94
  17. package/lib/bearer-auth-Cwxt-vgS.js +94 -0
  18. package/lib/bearer-auth.js +1 -93
  19. package/lib/body-D7f4e7w_.js +94 -0
  20. package/lib/body-limit-WmIjWRLt.js +66 -0
  21. package/lib/body-limit.js +1 -65
  22. package/lib/buffer-CkEOJCcY.js +51 -0
  23. package/lib/bun.js +3 -3
  24. package/lib/cache-B0bHH7s5.js +169 -0
  25. package/lib/cache.js +1 -168
  26. package/lib/{client-DDLXwhBo.js → client-BrMFnMEd.js} +1 -1
  27. package/lib/{client-modules-CLvWOjbd.js → client-modules-drj4mjhj.js} +4 -4
  28. package/lib/client.js +1 -1
  29. package/lib/color-COa3DplO.js +37 -0
  30. package/lib/combine-TWuGdcbC.js +137 -0
  31. package/lib/combine.js +1 -136
  32. package/lib/{components-cEW3ovK0.js → components-B2ka9Ax1.js} +4 -4
  33. package/lib/{components-JXVm45kK.js → components-PVXwaOaC.js} +2 -2
  34. package/lib/compress-BzWqsHF1.js +79 -0
  35. package/lib/compress-C-9vK4B2.d.ts +11 -0
  36. package/lib/compress-DCyrrQ5D.js +11 -0
  37. package/lib/compress.d.ts +1 -1
  38. package/lib/compress.js +2 -78
  39. package/lib/concurrent-DrF3d2c-.js +30 -0
  40. package/lib/conninfo-BCROmdnf.d.ts +11 -0
  41. package/lib/conninfo-CWJwieh4.js +19 -0
  42. package/lib/constants-CBSEudrb.js +7 -0
  43. package/lib/{context-DDO0cfuP.js → context-CkOh7Ygv.js} +2 -2
  44. package/lib/context-storage-iuPoI_CR.js +52 -0
  45. package/lib/context-storage.js +1 -51
  46. package/lib/cookie-B1LlkzOe.js +125 -0
  47. package/lib/cookie-BHIduy2T.js +82 -0
  48. package/lib/cookie.js +1 -81
  49. package/lib/cordis/db-sqlite.d.ts +1 -1
  50. package/lib/cordis/door.d.ts +17 -3
  51. package/lib/cordis/door.js +123 -16
  52. package/lib/cordis/inspect.js +4 -4
  53. package/lib/cordis/kv-db.d.ts +1 -1
  54. package/lib/cordis/kv-db.js +1 -1
  55. package/lib/cordis/kv-json.d.ts +1 -1
  56. package/lib/cordis/kv-json.js +1 -1
  57. package/lib/cordis/node-server.d.ts +1 -1
  58. package/lib/cordis/node-server.js +3 -116
  59. package/lib/cordis/router-http.d.ts +1 -1
  60. package/lib/cordis/router-http.js +2 -2
  61. package/lib/cordis/router.d.ts +1 -1
  62. package/lib/cordis/router.js +4 -4
  63. package/lib/cordis/state.js +7 -7
  64. package/lib/{core-CaY8XDZ6.js → core-BOu1jYua.js} +1 -1
  65. package/lib/cors-CbAQ-8qU.js +106 -0
  66. package/lib/cors.js +1 -105
  67. package/lib/crypto-iVP-N-tS.js +34 -0
  68. package/lib/csrf-DqqOZtgy.js +101 -0
  69. package/lib/csrf.js +1 -100
  70. package/lib/css-C5CPVMvM.js +134 -0
  71. package/lib/css.js +2 -133
  72. package/lib/db/sqlite.d.ts +1 -25
  73. package/lib/dev-CLgu-JRe.js +50 -0
  74. package/lib/dev.js +1 -49
  75. package/lib/dom-YjND9Jt3.js +74 -0
  76. package/lib/door/host.d.ts +2 -2
  77. package/lib/door/host.js +1 -1
  78. package/lib/door/page.d.ts +12 -1
  79. package/lib/door/page.js +22 -1
  80. package/lib/door/protocol.d.ts +2 -2
  81. package/lib/door/protocol.js +2 -197
  82. package/lib/encode-BhbNLrjp.js +33 -0
  83. package/lib/factory-CLdSf-xS.js +30 -0
  84. package/lib/factory.js +1 -29
  85. package/lib/handler-C0wZ0KwO.js +12 -0
  86. package/lib/helpers-BEjcdbgw.js +5 -0
  87. package/lib/{hooks-w72iLeFR.js → hooks-CfC07ri0.js} +1 -1
  88. package/lib/html-CgNa89xw.js +31 -0
  89. package/lib/html-DGExBFNg.js +103 -0
  90. package/lib/html.d.ts +2 -5
  91. package/lib/html.js +2 -30
  92. package/lib/http-exception-MjWkT89V.js +54 -0
  93. package/lib/http-exception.js +1 -53
  94. package/lib/{index-D4nVR3wu.d.ts → index-DMOtA-NJ.d.ts} +7 -1
  95. package/lib/index-dAzQsJG9.d.ts +6 -0
  96. package/lib/index.js +3 -3
  97. package/lib/ip-restriction-jKtKCRM_.js +166 -0
  98. package/lib/ip-restriction.js +1 -165
  99. package/lib/ipaddr-DCoIo528.js +238 -0
  100. package/lib/jsx/dom/client.js +1 -1
  101. package/lib/jsx/dom/jsx-dev-runtime.js +1 -1
  102. package/lib/jsx/dom/jsx-runtime.js +2 -1
  103. package/lib/jsx/dom/server.js +3 -3
  104. package/lib/jsx/dom.js +5 -73
  105. package/lib/jsx/jsx-dev-runtime.d.ts +2 -5
  106. package/lib/jsx/jsx-dev-runtime.js +2 -13
  107. package/lib/jsx/jsx-runtime.d.ts +2 -2
  108. package/lib/jsx/jsx-runtime.js +4 -4
  109. package/lib/jsx/streaming.js +1 -1
  110. package/lib/jsx-CUQgttxU.js +47 -0
  111. package/lib/jsx-dev-runtime-B4WTyq8r.js +14 -0
  112. package/lib/{jsx-dev-runtime-CWLRA2F3.js → jsx-dev-runtime-BLfA-EhI.js} +2 -2
  113. package/lib/jsx-dev-runtime-CGt4kNYr.d.ts +6 -0
  114. package/lib/jsx-renderer-CfifM4hT.js +99 -0
  115. package/lib/jsx-renderer.js +1 -98
  116. package/lib/jsx-runtime-COCRWBJ9.js +2 -0
  117. package/lib/jsx.js +5 -46
  118. package/lib/{jwk-LkzeoaU8.js → jwk-CDPpYQpD.js} +3 -3
  119. package/lib/jwk.js +1 -1
  120. package/lib/{jwt-BGJBw5AF.js → jwt-BXoIA2fQ.js} +2 -2
  121. package/lib/{jwt-CskdhEW9.js → jwt-lyS4Q3mT.js} +3 -3
  122. package/lib/jwt.js +2 -2
  123. package/lib/kv/db.d.ts +1 -10
  124. package/lib/kv/db.js +1 -56
  125. package/lib/kv/json.d.ts +1 -9
  126. package/lib/kv/json.js +1 -223
  127. package/lib/{language-D9a4zqvn.js → language-DeGRtLJt.js} +2 -2
  128. package/lib/language.js +1 -1
  129. package/lib/{linear-router-C3FPib6h.js → linear-router-CmZn_JLV.js} +2 -2
  130. package/lib/logger-Ckxu8diz.js +54 -0
  131. package/lib/logger.js +1 -53
  132. package/lib/loopback-only-BbasoF7R.js +90 -0
  133. package/lib/loopback-only.js +1 -89
  134. package/lib/method-not-allowed-TO2_hnfl.js +82 -0
  135. package/lib/method-not-allowed.js +1 -81
  136. package/lib/method-override-DnZKfJbV.js +103 -0
  137. package/lib/method-override.js +1 -102
  138. package/lib/middleware-BfG_fp8P.js +12 -0
  139. package/lib/mime-BnScXkQn.js +77 -0
  140. package/lib/mount-QkK_3NtJ.js +67 -0
  141. package/lib/mount.js +1 -66
  142. package/lib/node-server/conninfo.d.ts +1 -10
  143. package/lib/node-server/conninfo.js +1 -18
  144. package/lib/node-server/register.js +25 -2
  145. package/lib/node-server/serve-static.d.ts +1 -17
  146. package/lib/node-server/serve-static.js +1 -1
  147. package/lib/node-server.d.ts +2 -2
  148. package/lib/node-server.js +4 -4
  149. package/lib/open-BqK4D2Wn.d.ts +11 -0
  150. package/lib/open-But9E2rL.js +57 -0
  151. package/lib/open-CULVJgOc.d.ts +12 -0
  152. package/lib/open-Dp4sxspc.js +224 -0
  153. package/lib/open-T7kgbO2O.d.ts +27 -0
  154. package/lib/{pattern-router-HZxjDGEQ.js → pattern-router-CJBecJBd.js} +1 -1
  155. package/lib/powered-by-CXQNjNIX.js +24 -0
  156. package/lib/powered-by.js +1 -23
  157. package/lib/pretty-json-CeC1yvYt.js +39 -0
  158. package/lib/pretty-json.js +1 -38
  159. package/lib/{protocol-BizVt4J6.d.ts → protocol-C37gPePD.d.ts} +9 -2
  160. package/lib/protocol-Dt0AZBOz.js +213 -0
  161. package/lib/proxy-C2w_mH7k.js +121 -0
  162. package/lib/proxy.js +1 -120
  163. package/lib/quick.js +4 -4
  164. package/lib/{reg-exp-router-DC1R3qoY.js → reg-exp-router-C_WV84eV.js} +2 -2
  165. package/lib/request-DvMgGtlW.js +323 -0
  166. package/lib/request.js +1 -322
  167. package/lib/route-D8m-a2I1.js +126 -0
  168. package/lib/route.js +1 -125
  169. package/lib/router/linear-router.js +1 -1
  170. package/lib/router/pattern-router.js +1 -1
  171. package/lib/router/reg-exp-router.js +1 -1
  172. package/lib/router/smart-router.js +1 -1
  173. package/lib/router/trie-router.js +1 -1
  174. package/lib/router-Be_o6nFu.js +35 -0
  175. package/lib/router.js +1 -34
  176. package/lib/schema-validator-EK3cUUCt.js +22 -0
  177. package/lib/schema-validator.js +1 -21
  178. package/lib/{secure-headers-mP3j6Hm6.js → secure-headers-C5ZOcXqk.js} +1 -1
  179. package/lib/secure-headers.js +1 -1
  180. package/lib/serve-static-B7sqnftW.d.ts +18 -0
  181. package/lib/{serve-static-3uo_9rjF.js → serve-static-C1Nkj_xB.js} +2 -2
  182. package/lib/{serve-static-Cp5adzGo.js → serve-static-EiJf1zkO.js} +4 -4
  183. package/lib/serve-static.js +1 -1
  184. package/lib/{smart-router-C5CZ5XSM.js → smart-router-BjxkDQCE.js} +1 -1
  185. package/lib/{snapshot-text-DmE0YfeZ.js → snapshot-text-Bbx43mN0.js} +57 -9
  186. package/lib/{src-2Z4mJg0x.js → src-BTBm4OPD.js} +22 -6
  187. package/lib/src-LX0E4ec4.js +117 -0
  188. package/lib/{ssg-BwjcA-Ge.js → ssg-BEl7MHqg.js} +5 -5
  189. package/lib/ssg.js +1 -1
  190. package/lib/stream-CzM_SHkq.js +88 -0
  191. package/lib/{streaming-DHST3Scg.js → streaming-BlDaph8U.js} +3 -3
  192. package/lib/streaming.js +1 -1
  193. package/lib/{test-websocket-D8WWqE5G.js → test-websocket-BLeEvybj.js} +2 -2
  194. package/lib/testing-BQx5T_UX.js +17 -0
  195. package/lib/testing.js +1 -16
  196. package/lib/timeout-FeqZ9A-0.js +42 -0
  197. package/lib/timeout.js +1 -41
  198. package/lib/tiny.js +2 -2
  199. package/lib/trailing-slash-DwTx-1sk.js +85 -0
  200. package/lib/trailing-slash.js +1 -84
  201. package/lib/{trie-router-CfFbapzL.js → trie-router-JydLKUa2.js} +2 -2
  202. package/lib/url-BPh4d6j-.js +197 -0
  203. package/lib/utils/accept.js +1 -192
  204. package/lib/utils/basic-auth.js +1 -19
  205. package/lib/utils/body.js +1 -93
  206. package/lib/utils/buffer.js +1 -50
  207. package/lib/utils/color.js +1 -36
  208. package/lib/utils/compress.d.ts +1 -10
  209. package/lib/utils/compress.js +1 -10
  210. package/lib/utils/concurrent.js +1 -29
  211. package/lib/utils/constants.js +1 -6
  212. package/lib/utils/cookie.js +1 -124
  213. package/lib/utils/crypto.js +1 -33
  214. package/lib/utils/encode.js +1 -32
  215. package/lib/utils/handler.js +1 -11
  216. package/lib/utils/html.js +1 -102
  217. package/lib/utils/ipaddr.js +1 -237
  218. package/lib/utils/jwt.js +1 -1
  219. package/lib/utils/mime.js +1 -76
  220. package/lib/utils/stream.js +1 -87
  221. package/lib/utils/url.js +1 -196
  222. package/lib/{validator-D84mq-dO.js → validator-Btiyt5VJ.js} +3 -3
  223. package/lib/validator.js +1 -1
  224. package/lib/websocket-DsyBIKVA.js +56 -0
  225. package/lib/ws.js +1 -55
  226. package/package.json +1 -1
  227. package/plugins/acryl-door/src/cli/acryl.ts +5 -3
  228. package/plugins/acryl-door/src/host/channel.ts +36 -0
  229. package/plugins/acryl-door/src/host/chat-tools.ts +2 -0
  230. package/plugins/acryl-door/src/host/door.ts +44 -5
  231. package/plugins/acryl-door/src/host/shim.ts +23 -0
  232. package/plugins/acryl-door/src/host/verbs.ts +4 -3
  233. package/plugins/acryl-door/src/index.ts +39 -3
  234. package/plugins/acryl-door/src/page/driver/driver.ts +22 -1
  235. package/plugins/acryl-door/src/page/protocol.ts +13 -2
  236. package/plugins/acryl-node-server/src/register.ts +29 -2
  237. package/plugins/acryl-router/src/service.ts +19 -1
  238. package/plugins/agent/model.ts +6 -1
  239. package/plugins/agent/tools.ts +12 -2
  240. package/plugins/agent-panel/client/describe.ts +44 -0
  241. package/plugins/agent-panel/client/main.ts +67 -35
  242. package/plugins/agent-panel/index.ts +137 -35
  243. package/plugins/desktop/attach.ts +72 -0
  244. package/plugins/desktop/main.ts +17 -4
  245. package/plugins/extensions/index.ts +3 -4
  246. package/plugins/extensions/stage.ts +33 -5
  247. package/plugins/openai/index.ts +1 -1
  248. package/shared/DEFAULTS.md +4 -0
  249. package/templates/agent/AGENTS.md +2 -0
  250. package/templates/agent/blend.yaml +4 -1
  251. package/templates/agent/src/app.ts +2 -0
  252. package/templates/agent/src/routes.ts +1 -1
  253. package/templates/agent/template.json +1 -0
  254. package/templates/agent/test/builder.test.ts +26 -21
  255. package/lib/helpers-CvTauQT5.js +0 -5
  256. package/lib/middleware-CPQ8himN.js +0 -12
@@ -0,0 +1,238 @@
1
+ //#region ../../plugins/acryl-router/src/core/utils/ipaddr.ts
2
+ /**
3
+ * Expand IPv6 Address
4
+ * @param ipV6 Shorten IPv6 Address
5
+ * @return expanded IPv6 Address
6
+ */
7
+ const expandIPv6 = (ipV6) => {
8
+ const sections = ipV6.split(":");
9
+ const lastSection = sections.at(-1);
10
+ if (IPV4_REGEX.test(lastSection)) {
11
+ const octets = lastSection.split(".").map(Number);
12
+ sections.splice(-1, 1, (octets[0] << 8 | octets[1]).toString(16), (octets[2] << 8 | octets[3]).toString(16));
13
+ }
14
+ for (let i = 0; i < sections.length; i++) {
15
+ const node = sections[i];
16
+ if (node !== "") sections[i] = node.padStart(4, "0");
17
+ else {
18
+ while (sections[i + 1] === "") sections.splice(i + 1, 1);
19
+ sections[i] = new Array(8 - sections.length + 1).fill("0000").join(":");
20
+ }
21
+ }
22
+ return sections.join(":");
23
+ };
24
+ const IPV4_OCTET_PART = "(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])";
25
+ const IPV4_REGEX = new RegExp(`^(?:${IPV4_OCTET_PART}\\.){3}${IPV4_OCTET_PART}$`);
26
+ const INVALID_IP_ADDRESS_ERROR_CODE = "ERR_INVALID_IP_ADDRESS";
27
+ const CHAR_CODE_0 = 48;
28
+ const CHAR_CODE_9 = 57;
29
+ const CHAR_CODE_A = 65;
30
+ const CHAR_CODE_F = 70;
31
+ const CHAR_CODE_a = 97;
32
+ const CHAR_CODE_f = 102;
33
+ const CHAR_CODE_DOT = 46;
34
+ const CHAR_CODE_COLON = 58;
35
+ const CHAR_CODE_PERCENT = 37;
36
+ /**
37
+ * Distinct Remote Addr
38
+ * @param remoteAddr Remote Addr
39
+ */
40
+ const distinctRemoteAddr = (remoteAddr) => {
41
+ if (IPV4_REGEX.test(remoteAddr)) return "IPv4";
42
+ if (remoteAddr.includes(":")) return "IPv6";
43
+ };
44
+ const createInvalidIPAddressError = (message) => {
45
+ const error = new TypeError(message);
46
+ error.code = INVALID_IP_ADDRESS_ERROR_CODE;
47
+ return error;
48
+ };
49
+ const throwInvalidIPv4Address = (ipv4) => {
50
+ throw createInvalidIPAddressError(`Invalid IPv4 address: ${ipv4}`);
51
+ };
52
+ const throwInvalidIPv6Address = (ipv6) => {
53
+ throw createInvalidIPAddressError(`Invalid IPv6 address: ${ipv6}`);
54
+ };
55
+ const parseIPv4ToBinary = (ipv4, start, end, onInvalid) => {
56
+ let result = 0n;
57
+ let octets = 0;
58
+ let octet = 0;
59
+ let digits = 0;
60
+ let firstDigit = 0;
61
+ for (let i = start; i <= end; i++) {
62
+ const code = i < end ? ipv4.charCodeAt(i) : CHAR_CODE_DOT;
63
+ if (code >= CHAR_CODE_0 && code <= CHAR_CODE_9) {
64
+ if (digits === 0) firstDigit = code;
65
+ else if (firstDigit === CHAR_CODE_0) onInvalid();
66
+ octet = octet * 10 + code - CHAR_CODE_0;
67
+ if (octet > 255) onInvalid();
68
+ digits++;
69
+ continue;
70
+ }
71
+ if (code !== CHAR_CODE_DOT || digits === 0 || octets === 4) onInvalid();
72
+ result = (result << 8n) + BigInt(octet);
73
+ octets++;
74
+ octet = 0;
75
+ digits = 0;
76
+ }
77
+ if (octets !== 4) onInvalid();
78
+ return result;
79
+ };
80
+ const parseIPv6HexCode = (code) => {
81
+ if (code >= CHAR_CODE_0 && code <= CHAR_CODE_9) return code - CHAR_CODE_0;
82
+ if (code >= CHAR_CODE_A && code <= CHAR_CODE_F) return code - CHAR_CODE_A + 10;
83
+ if (code >= CHAR_CODE_a && code <= CHAR_CODE_f) return code - CHAR_CODE_a + 10;
84
+ return -1;
85
+ };
86
+ const isIPv6LinkLocal = (ipv6binary) => ipv6binary >> 118n === 1018n;
87
+ /**
88
+ * Convert IPv4 to Uint8Array
89
+ * @param ipv4 IPv4 Address
90
+ * @returns BigInt
91
+ */
92
+ const convertIPv4ToBinary = (ipv4) => {
93
+ return parseIPv4ToBinary(ipv4, 0, ipv4.length, () => throwInvalidIPv4Address(ipv4));
94
+ };
95
+ /**
96
+ * Convert IPv6 to Uint8Array
97
+ * @param ipv6 IPv6 Address
98
+ * @returns BigInt
99
+ */
100
+ const convertIPv6ToBinary = (ipv6) => {
101
+ const length = ipv6.length;
102
+ const sections = [];
103
+ let hasZoneId = false;
104
+ let compressAt = -1;
105
+ let index = 0;
106
+ if (length === 0) throwInvalidIPv6Address(ipv6);
107
+ while (index < length) {
108
+ if (sections.length > 8) throwInvalidIPv6Address(ipv6);
109
+ let code = ipv6.charCodeAt(index);
110
+ if (code === CHAR_CODE_PERCENT) {
111
+ if (index + 1 === length) throwInvalidIPv6Address(ipv6);
112
+ hasZoneId = true;
113
+ break;
114
+ }
115
+ if (code === CHAR_CODE_COLON) {
116
+ if (index + 1 < length && ipv6.charCodeAt(index + 1) === CHAR_CODE_COLON) {
117
+ if (compressAt !== -1) throwInvalidIPv6Address(ipv6);
118
+ compressAt = sections.length;
119
+ index += 2;
120
+ continue;
121
+ }
122
+ throwInvalidIPv6Address(ipv6);
123
+ }
124
+ let value = 0;
125
+ let digits = 0;
126
+ const sectionStart = index;
127
+ while (index < length) {
128
+ code = ipv6.charCodeAt(index);
129
+ const hex = parseIPv6HexCode(code);
130
+ if (hex === -1) break;
131
+ if (digits === 4) throwInvalidIPv6Address(ipv6);
132
+ value = value << 4 | hex;
133
+ digits++;
134
+ index++;
135
+ }
136
+ if (index < length && ipv6.charCodeAt(index) === CHAR_CODE_DOT) {
137
+ let ipv4End = length;
138
+ for (let i = index; i < length; i++) if (ipv6.charCodeAt(i) === CHAR_CODE_PERCENT) {
139
+ if (i + 1 === length) throwInvalidIPv6Address(ipv6);
140
+ hasZoneId = true;
141
+ ipv4End = i;
142
+ break;
143
+ }
144
+ const ipv4 = parseIPv4ToBinary(ipv6, sectionStart, ipv4End, () => throwInvalidIPv6Address(ipv6));
145
+ sections.push(Number(ipv4 >> 16n & 65535n), Number(ipv4 & 65535n));
146
+ index = length;
147
+ break;
148
+ }
149
+ if (digits === 0) throwInvalidIPv6Address(ipv6);
150
+ sections.push(value);
151
+ if (index === length) break;
152
+ code = ipv6.charCodeAt(index);
153
+ if (code === CHAR_CODE_PERCENT) {
154
+ if (index + 1 === length) throwInvalidIPv6Address(ipv6);
155
+ hasZoneId = true;
156
+ break;
157
+ }
158
+ if (code !== CHAR_CODE_COLON) throwInvalidIPv6Address(ipv6);
159
+ if (index + 1 < length && ipv6.charCodeAt(index + 1) === CHAR_CODE_COLON) {
160
+ if (compressAt !== -1) throwInvalidIPv6Address(ipv6);
161
+ compressAt = sections.length;
162
+ index += 2;
163
+ continue;
164
+ }
165
+ index++;
166
+ if (index === length) throwInvalidIPv6Address(ipv6);
167
+ }
168
+ if (compressAt === -1 ? sections.length !== 8 : sections.length >= 8) throwInvalidIPv6Address(ipv6);
169
+ let result = 0n;
170
+ const zeros = compressAt === -1 ? 0 : 8 - sections.length;
171
+ const firstSectionEnd = compressAt === -1 ? sections.length : compressAt;
172
+ for (let i = 0; i < firstSectionEnd; i++) {
173
+ result <<= 16n;
174
+ result += BigInt(sections[i]);
175
+ }
176
+ for (let i = 0; i < zeros; i++) result <<= 16n;
177
+ for (let i = firstSectionEnd; i < sections.length; i++) {
178
+ result <<= 16n;
179
+ result += BigInt(sections[i]);
180
+ }
181
+ if (hasZoneId && !isIPv6LinkLocal(result)) throwInvalidIPv6Address(ipv6);
182
+ return result;
183
+ };
184
+ /**
185
+ * Convert a binary representation of an IPv4 address to a string.
186
+ * @param ipV4 binary IPv4 Address
187
+ * @return IPv4 Address in string
188
+ */
189
+ const convertIPv4BinaryToString = (ipV4) => {
190
+ const sections = [];
191
+ for (let i = 0; i < 4; i++) sections.push(ipV4 >> BigInt(8 * (3 - i)) & 255n);
192
+ return sections.join(".");
193
+ };
194
+ /**
195
+ * Check if a binary IPv6 address is an IPv4-mapped IPv6 address (::ffff:x.x.x.x)
196
+ * @param ipv6binary binary IPv6 Address
197
+ * @return true if the address is an IPv4-mapped IPv6 address
198
+ */
199
+ const isIPv4MappedIPv6 = (ipv6binary) => ipv6binary >> 32n === 65535n;
200
+ /**
201
+ * Extract the IPv4 portion from an IPv4-mapped IPv6 address
202
+ * @param ipv6binary binary IPv4-mapped IPv6 Address
203
+ * @return binary IPv4 Address
204
+ */
205
+ const convertIPv4MappedIPv6ToIPv4 = (ipv6binary) => ipv6binary & 4294967295n;
206
+ /**
207
+ * Convert a binary representation of an IPv6 address to a string.
208
+ * @param ipV6 binary IPv6 Address
209
+ * @return normalized IPv6 Address in string
210
+ */
211
+ const convertIPv6BinaryToString = (ipV6) => {
212
+ if (ipV6 === 0n) return "::";
213
+ if (isIPv4MappedIPv6(ipV6)) return `::ffff:${convertIPv4BinaryToString(convertIPv4MappedIPv6ToIPv4(ipV6))}`;
214
+ const sections = [];
215
+ for (let i = 0; i < 8; i++) sections.push((ipV6 >> BigInt(16 * (7 - i)) & 65535n).toString(16));
216
+ let currentZeroStart = -1;
217
+ let maxZeroStart = -1;
218
+ let maxZeroEnd = -1;
219
+ for (let i = 0; i < 8; i++) if (sections[i] === "0") {
220
+ if (currentZeroStart === -1) currentZeroStart = i;
221
+ } else if (currentZeroStart > -1) {
222
+ if (i - currentZeroStart > maxZeroEnd - maxZeroStart) {
223
+ maxZeroStart = currentZeroStart;
224
+ maxZeroEnd = i;
225
+ }
226
+ currentZeroStart = -1;
227
+ }
228
+ if (currentZeroStart > -1) {
229
+ if (8 - currentZeroStart > maxZeroEnd - maxZeroStart) {
230
+ maxZeroStart = currentZeroStart;
231
+ maxZeroEnd = 8;
232
+ }
233
+ }
234
+ if (maxZeroStart !== -1 && maxZeroEnd - maxZeroStart > 1) sections.splice(maxZeroStart, maxZeroEnd - maxZeroStart, ":");
235
+ return sections.join(":").replace(/:{2,}/g, "::");
236
+ };
237
+ //#endregion
238
+ export { convertIPv6BinaryToString as a, expandIPv6 as c, convertIPv4ToBinary as i, isIPv4MappedIPv6 as l, convertIPv4BinaryToString as n, convertIPv6ToBinary as o, convertIPv4MappedIPv6ToIPv4 as r, distinctRemoteAddr as s, INVALID_IP_ADDRESS_ERROR_CODE as t };
@@ -1,4 +1,4 @@
1
- import { D as renderNode, S as buildNode, _ as useState } from "../../hooks-w72iLeFR.js";
1
+ import { D as renderNode, S as buildNode, _ as useState } from "../../hooks-CfC07ri0.js";
2
2
  //#region ../../plugins/acryl-router/src/core/jsx/dom/client.ts
3
3
  /**
4
4
  * Create a root object for rendering
@@ -1,2 +1,2 @@
1
- import { n as jsxDEV, t as Fragment } from "../../jsx-dev-runtime-CWLRA2F3.js";
1
+ import { n as jsxDEV, t as Fragment } from "../../jsx-dev-runtime-BLfA-EhI.js";
2
2
  export { Fragment, jsxDEV };
@@ -1,2 +1,3 @@
1
- import { n as jsxDEV, t as Fragment } from "../../jsx-dev-runtime-CWLRA2F3.js";
1
+ import { n as jsxDEV, t as Fragment } from "../../jsx-dev-runtime-BLfA-EhI.js";
2
+ import "../../jsx-runtime-COCRWBJ9.js";
2
3
  export { Fragment, jsxDEV as jsx, jsxDEV as jsxs };
@@ -1,6 +1,6 @@
1
- import { u as renderChildren } from "../../base-NSN_SNv-.js";
2
- import { i as renderToReadableStream$1 } from "../../components-cEW3ovK0.js";
3
- import dom_default from "../dom.js";
1
+ import { u as renderChildren } from "../../base-D_6kfOr-.js";
2
+ import { i as renderToReadableStream$1 } from "../../components-B2ka9Ax1.js";
3
+ import { r as dom_default } from "../../dom-YjND9Jt3.js";
4
4
  //#region ../../plugins/acryl-router/src/core/jsx/dom/server.ts
5
5
  const prepareRoot = (element) => typeof element === "string" || Array.isArray(element) ? renderChildren([element]) : element;
6
6
  /**
package/lib/jsx/dom.js CHANGED
@@ -1,74 +1,6 @@
1
- import { D as createContext, E as useContext, a as isValidElement, f as shallowEqual, g as Children, l as reactAPICompatVersion } from "../base-NSN_SNv-.js";
2
- import { r as DOM_MEMO } from "../constants-BR9jM9BC.js";
3
- import { C as createPortal, E as render, _ as useState, a as use, b as useViewTransition, c as useDeferredValue, d as useImperativeHandle, f as useInsertionEffect, g as useRef, h as useReducer, i as startViewTransition, l as useEffect, m as useMemo, n as forwardRef, o as useCallback, p as useLayoutEffect, r as startTransition, s as useDebugValue, t as createRef, u as useId, v as useSyncExternalStore, w as flushSync, y as useTransition } from "../hooks-w72iLeFR.js";
4
- import { a as useOptimistic, i as useFormStatus, n as jsxDEV, r as useActionState, t as Fragment } from "../jsx-dev-runtime-CWLRA2F3.js";
5
- import "./dom/jsx-runtime.js";
6
- import { n as Suspense, t as ErrorBoundary } from "../components-JXVm45kK.js";
7
- //#region ../../plugins/acryl-router/src/core/jsx/dom/index.ts
8
- /**
9
- * @module
10
- * This module provides APIs for `acryl-router/jsx/dom`.
11
- */
12
- const createElement = (tag, props, ...children) => {
13
- const jsxProps = props ? { ...props } : {};
14
- if (children.length) jsxProps.children = children.length === 1 ? children[0] : children;
15
- let key = void 0;
16
- if ("key" in jsxProps) {
17
- key = jsxProps.key;
18
- delete jsxProps.key;
19
- }
20
- return jsxDEV(tag, jsxProps, key);
21
- };
22
- const cloneElement = (element, props, ...children) => {
23
- return jsxDEV(element.tag, {
24
- ...element.props,
25
- ...props,
26
- children: children.length ? children : element.props.children
27
- }, element.key);
28
- };
29
- const memo = (component, propsAreEqual = shallowEqual) => {
30
- const wrapper = ((props) => component(props));
31
- wrapper[DOM_MEMO] = propsAreEqual;
32
- return wrapper;
33
- };
34
- var dom_default = {
35
- version: reactAPICompatVersion,
36
- useState,
37
- useEffect,
38
- useRef,
39
- useCallback,
40
- use,
41
- startTransition,
42
- useTransition,
43
- useDeferredValue,
44
- startViewTransition,
45
- useViewTransition,
46
- useMemo,
47
- useLayoutEffect,
48
- useInsertionEffect,
49
- useReducer,
50
- useId,
51
- useDebugValue,
52
- createRef,
53
- forwardRef,
54
- useImperativeHandle,
55
- useSyncExternalStore,
56
- useFormStatus,
57
- useActionState,
58
- useOptimistic,
59
- Suspense,
60
- ErrorBoundary,
61
- createContext,
62
- useContext,
63
- memo,
64
- isValidElement,
65
- createElement,
66
- cloneElement,
67
- Children,
68
- Fragment,
69
- StrictMode: Fragment,
70
- flushSync,
71
- createPortal
72
- };
73
- //#endregion
1
+ import { D as createContext, E as useContext, a as isValidElement, g as Children, l as reactAPICompatVersion } from "../base-D_6kfOr-.js";
2
+ import { C as createPortal, E as render, _ as useState, a as use, b as useViewTransition, c as useDeferredValue, d as useImperativeHandle, f as useInsertionEffect, g as useRef, h as useReducer, i as startViewTransition, l as useEffect, m as useMemo, n as forwardRef, o as useCallback, p as useLayoutEffect, r as startTransition, s as useDebugValue, t as createRef, u as useId, v as useSyncExternalStore, w as flushSync, y as useTransition } from "../hooks-CfC07ri0.js";
3
+ import { a as useOptimistic, i as useFormStatus, r as useActionState, t as Fragment } from "../jsx-dev-runtime-BLfA-EhI.js";
4
+ import { n as Suspense, t as ErrorBoundary } from "../components-PVXwaOaC.js";
5
+ import { i as memo, n as createElement, r as dom_default, t as cloneElement } from "../dom-YjND9Jt3.js";
74
6
  export { Children, ErrorBoundary, Fragment, Fragment as StrictMode, Suspense, cloneElement, createContext, createElement, createElement as jsx, createPortal, createRef, dom_default as default, flushSync, forwardRef, isValidElement, memo, render, startTransition, startViewTransition, use, useActionState, useCallback, useContext, useDebugValue, useDeferredValue, useEffect, useFormStatus, useId, useImperativeHandle, useInsertionEffect, useLayoutEffect, useMemo, useOptimistic, useReducer, useRef, useState, useSyncExternalStore, useTransition, useViewTransition, reactAPICompatVersion as version };
@@ -1,6 +1,3 @@
1
- import { a as JSX, i as Fragment, o as JSXNode } from "../base-BpQy2Rk7.js";
2
-
3
- //#region ../../plugins/acryl-router/src/core/jsx/jsx-dev-runtime.d.ts
4
- declare function jsxDEV(tag: string | Function, props: Record<string, unknown>, key?: string): JSXNode;
5
- //#endregion
1
+ import { a as JSX, i as Fragment } from "../base-BpQy2Rk7.js";
2
+ import { t as jsxDEV } from "../jsx-dev-runtime-CGt4kNYr.js";
6
3
  export { Fragment, type JSX, jsxDEV };
@@ -1,14 +1,3 @@
1
- import { s as jsxFn, t as Fragment } from "../base-NSN_SNv-.js";
2
- //#region ../../plugins/acryl-router/src/core/jsx/jsx-dev-runtime.ts
3
- function jsxDEV(tag, props, key) {
4
- let node;
5
- if (!props || !("children" in props)) node = jsxFn(tag, props, []);
6
- else {
7
- const children = props.children;
8
- node = Array.isArray(children) ? jsxFn(tag, props, children) : jsxFn(tag, props, [children]);
9
- }
10
- node.key = key;
11
- return node;
12
- }
13
- //#endregion
1
+ import { t as Fragment } from "../base-D_6kfOr-.js";
2
+ import { t as jsxDEV } from "../jsx-dev-runtime-B4WTyq8r.js";
14
3
  export { Fragment, jsxDEV };
@@ -1,7 +1,7 @@
1
1
  import { i as HtmlEscapedString } from "../html-SllAe0YT.js";
2
- import { html } from "../html.js";
2
+ import { t as html } from "../index-dAzQsJG9.js";
3
3
  import { a as JSX, i as Fragment } from "../base-BpQy2Rk7.js";
4
- import { jsxDEV } from "./jsx-dev-runtime.js";
4
+ import { t as jsxDEV } from "../jsx-dev-runtime-CGt4kNYr.js";
5
5
 
6
6
  //#region ../../plugins/acryl-router/src/core/jsx/jsx-runtime.d.ts
7
7
  declare const jsxAttr: (key: string, v: string | Promise<string> | Record<string, string | number | null | undefined | boolean>) => HtmlEscapedString | Promise<HtmlEscapedString>;
@@ -1,7 +1,7 @@
1
- import { h as styleObjectForEach, p as isValidAttributeName, t as Fragment } from "../base-NSN_SNv-.js";
2
- import { escapeToBuffer, raw, stringBufferToString } from "../utils/html.js";
3
- import { html } from "../html.js";
4
- import { jsxDEV } from "./jsx-dev-runtime.js";
1
+ import { h as styleObjectForEach, p as isValidAttributeName, t as Fragment } from "../base-D_6kfOr-.js";
2
+ import { n as escapeToBuffer, o as stringBufferToString, r as raw } from "../html-DGExBFNg.js";
3
+ import { t as html } from "../html-CgNa89xw.js";
4
+ import { t as jsxDEV } from "../jsx-dev-runtime-B4WTyq8r.js";
5
5
  //#region ../../plugins/acryl-router/src/core/jsx/jsx-runtime.ts
6
6
  const jsxAttr = (key, v) => {
7
7
  if (!isValidAttributeName(key)) return raw("");
@@ -1,2 +1,2 @@
1
- import { i as renderToReadableStream, n as StreamingContext, r as Suspense } from "../components-cEW3ovK0.js";
1
+ import { i as renderToReadableStream, n as StreamingContext, r as Suspense } from "../components-B2ka9Ax1.js";
2
2
  export { StreamingContext, Suspense, renderToReadableStream };
@@ -0,0 +1,47 @@
1
+ import { E as useContext, a as isValidElement, c as memo, g as Children, l as reactAPICompatVersion, o as jsx, r as cloneElement, t as Fragment, w as createContext } from "./base-D_6kfOr-.js";
2
+ import { _ as useState, a as use, b as useViewTransition, c as useDeferredValue, d as useImperativeHandle, f as useInsertionEffect, g as useRef, h as useReducer, i as startViewTransition, l as useEffect, m as useMemo, n as forwardRef, o as useCallback, p as useLayoutEffect, r as startTransition, s as useDebugValue, t as createRef, u as useId, v as useSyncExternalStore, y as useTransition } from "./hooks-CfC07ri0.js";
3
+ import { a as useOptimistic, r as useActionState } from "./jsx-dev-runtime-BLfA-EhI.js";
4
+ import { r as Suspense, t as ErrorBoundary } from "./components-B2ka9Ax1.js";
5
+ //#region ../../plugins/acryl-router/src/core/jsx/index.ts
6
+ /**
7
+ * @module
8
+ * JSX for Acryl.
9
+ */
10
+ var jsx_default = {
11
+ version: reactAPICompatVersion,
12
+ memo,
13
+ Fragment,
14
+ StrictMode: Fragment,
15
+ isValidElement,
16
+ createElement: jsx,
17
+ cloneElement,
18
+ ErrorBoundary,
19
+ createContext,
20
+ useContext,
21
+ useState,
22
+ useEffect,
23
+ useRef,
24
+ useCallback,
25
+ useReducer,
26
+ useId,
27
+ useDebugValue,
28
+ use,
29
+ startTransition,
30
+ useTransition,
31
+ useDeferredValue,
32
+ startViewTransition,
33
+ useViewTransition,
34
+ useMemo,
35
+ useLayoutEffect,
36
+ useInsertionEffect,
37
+ createRef,
38
+ forwardRef,
39
+ useImperativeHandle,
40
+ useSyncExternalStore,
41
+ useActionState,
42
+ useOptimistic,
43
+ Suspense,
44
+ Children
45
+ };
46
+ //#endregion
47
+ export { jsx_default as t };
@@ -0,0 +1,14 @@
1
+ import { s as jsxFn } from "./base-D_6kfOr-.js";
2
+ //#region ../../plugins/acryl-router/src/core/jsx/jsx-dev-runtime.ts
3
+ function jsxDEV(tag, props, key) {
4
+ let node;
5
+ if (!props || !("children" in props)) node = jsxFn(tag, props, []);
6
+ else {
7
+ const children = props.children;
8
+ node = Array.isArray(children) ? jsxFn(tag, props, children) : jsxFn(tag, props, [children]);
9
+ }
10
+ node.key = key;
11
+ return node;
12
+ }
13
+ //#endregion
14
+ export { jsxDEV as t };
@@ -1,6 +1,6 @@
1
- import { D as createContext, E as useContext, O as __exportAll, S as shouldDeDupeByKey, b as domRenderers, v as dataPrecedenceAttr, x as isStylesheetLinkWithPrecedence, y as deDupeKeyMap } from "./base-NSN_SNv-.js";
1
+ import { D as createContext, E as useContext, O as __exportAll, S as shouldDeDupeByKey, b as domRenderers, v as dataPrecedenceAttr, x as isStylesheetLinkWithPrecedence, y as deDupeKeyMap } from "./base-D_6kfOr-.js";
2
2
  import { o as PERMALINK } from "./constants-BR9jM9BC.js";
3
- import { C as createPortal, T as getNameSpaceContext, _ as useState, a as use, m as useMemo, o as useCallback } from "./hooks-w72iLeFR.js";
3
+ import { C as createPortal, T as getNameSpaceContext, _ as useState, a as use, m as useMemo, o as useCallback } from "./hooks-CfC07ri0.js";
4
4
  //#region ../../plugins/acryl-router/src/core/jsx/dom/hooks/index.ts
5
5
  /**
6
6
  * Provide hooks used only in jsx/dom
@@ -0,0 +1,6 @@
1
+ import { o as JSXNode } from "./base-BpQy2Rk7.js";
2
+
3
+ //#region ../../plugins/acryl-router/src/core/jsx/jsx-dev-runtime.d.ts
4
+ declare function jsxDEV(tag: string | Function, props: Record<string, unknown>, key?: string): JSXNode;
5
+ //#endregion
6
+ export { jsxDEV as t };
@@ -0,0 +1,99 @@
1
+ import { E as useContext, o as jsx, t as Fragment, w as createContext } from "./base-D_6kfOr-.js";
2
+ import { r as raw } from "./html-DGExBFNg.js";
3
+ import { t as html } from "./html-CgNa89xw.js";
4
+ import { i as renderToReadableStream } from "./components-B2ka9Ax1.js";
5
+ import "./jsx-CUQgttxU.js";
6
+ //#region ../../plugins/acryl-router/src/core/middleware/jsx-renderer/index.ts
7
+ const RequestContext = createContext(null);
8
+ const createRenderer = (c, Layout, component, options) => (children, props) => {
9
+ options = typeof options === "function" ? options(c) : options;
10
+ const docType = typeof options?.docType === "string" ? options.docType : options?.docType === false ? "" : "<!DOCTYPE html>";
11
+ const currentLayout = component ? jsx((props) => component(props, c), {
12
+ Layout,
13
+ ...props
14
+ }, children) : children;
15
+ const body = html`${raw(docType)}${jsx(RequestContext.Provider, { value: c }, currentLayout)}`;
16
+ if (options?.stream) {
17
+ if (options.stream === true) {
18
+ c.header("Transfer-Encoding", "chunked");
19
+ c.header("Content-Type", "text/html; charset=UTF-8");
20
+ c.header("Content-Encoding", "Identity");
21
+ } else for (const [key, value] of Object.entries(options.stream)) c.header(key, value);
22
+ return c.body(renderToReadableStream(body));
23
+ } else return c.html(body);
24
+ };
25
+ /**
26
+ * JSX Renderer Middleware for acryl.
27
+ *
28
+ *
29
+ * @param {ComponentWithChildren} [component] - The component to render, which can accept children and props.
30
+ * @param {RendererOptions} [options] - The options for the JSX renderer middleware.
31
+ * @param {boolean | string} [options.docType=true] - The DOCTYPE to be added at the beginning of the HTML. If set to false, no DOCTYPE will be added.
32
+ * @param {boolean | Record<string, string>} [options.stream=false] - If set to true, enables streaming response with default headers. If a record is provided, custom headers will be used.
33
+ * @returns {MiddlewareHandler} The middleware handler function.
34
+ *
35
+ * @example
36
+ * ```ts
37
+ * const app = new Acryl()
38
+ *
39
+ * app.get(
40
+ * '/page/*',
41
+ * jsxRenderer(({ children }) => {
42
+ * return (
43
+ * <html>
44
+ * <body>
45
+ * <header>Menu</header>
46
+ * <div>{children}</div>
47
+ * </body>
48
+ * </html>
49
+ * )
50
+ * })
51
+ * )
52
+ *
53
+ * app.get('/page/about', (c) => {
54
+ * return c.render(<h1>About me!</h1>)
55
+ * })
56
+ * ```
57
+ */
58
+ const jsxRenderer = (component, options) => function jsxRenderer(c, next) {
59
+ const Layout = c.getLayout() ?? Fragment;
60
+ if (component) c.setLayout((props) => {
61
+ return component({
62
+ ...props,
63
+ Layout
64
+ }, c);
65
+ });
66
+ c.setRenderer(createRenderer(c, Layout, component, options));
67
+ return next();
68
+ };
69
+ /**
70
+ * useRequestContext for Acryl.
71
+ *
72
+ * @template E - The environment type.
73
+ * @template P - The parameter type.
74
+ * @template I - The input type.
75
+ * @returns {Context<E, P, I>} An instance of Context.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * const RequestUrlBadge: FC = () => {
80
+ * const c = useRequestContext()
81
+ * return <b>{c.req.url}</b>
82
+ * }
83
+ *
84
+ * app.get('/page/info', (c) => {
85
+ * return c.render(
86
+ * <div>
87
+ * You are accessing: <RequestUrlBadge />
88
+ * </div>
89
+ * )
90
+ * })
91
+ * ```
92
+ */
93
+ const useRequestContext = () => {
94
+ const c = useContext(RequestContext);
95
+ if (!c) throw new Error("RequestContext is not provided.");
96
+ return c;
97
+ };
98
+ //#endregion
99
+ export { jsxRenderer as n, useRequestContext as r, RequestContext as t };