ranuts 0.4.1-alpha.2 → 0.5.0

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 (330) hide show
  1. package/CLAUDE.md +23 -16
  2. package/README.de.md +62 -0
  3. package/README.es.md +62 -0
  4. package/README.fa.md +62 -0
  5. package/README.ja.md +62 -0
  6. package/README.ko.md +62 -0
  7. package/README.md +35 -92
  8. package/README.pt.md +62 -0
  9. package/README.zh-CN.md +35 -91
  10. package/dist/iife/index.iife.js +4 -0
  11. package/dist/iife/utils.iife.js +4 -0
  12. package/dist/index.d.ts +1 -1
  13. package/dist/index.js +306 -1
  14. package/dist/src/_virtual/_rolldown/runtime/index.js +12 -0
  15. package/dist/src/conversation/engine.d.ts +1 -1
  16. package/dist/src/conversation/engine.js +101 -0
  17. package/dist/src/conversation/index.d.ts +3 -3
  18. package/dist/src/conversation/index.js +4 -1
  19. package/dist/src/stream/accumulator.d.ts +1 -1
  20. package/dist/src/stream/accumulator.js +79 -0
  21. package/dist/src/stream/budget.d.ts +1 -1
  22. package/dist/src/stream/budget.js +45 -0
  23. package/dist/src/stream/index.d.ts +7 -7
  24. package/dist/src/stream/index.js +11 -1
  25. package/dist/src/stream/sse.d.ts +1 -1
  26. package/dist/src/stream/sse.js +61 -0
  27. package/dist/src/sw/index.js +52 -1
  28. package/dist/src/utils/async.js +49 -0
  29. package/dist/src/utils/audioRecorder.js +1121 -0
  30. package/dist/src/utils/behavior.js +9 -0
  31. package/dist/src/utils/binary.js +89 -0
  32. package/dist/src/utils/bom.d.ts +31 -9
  33. package/dist/src/utils/bom.js +165 -0
  34. package/dist/src/utils/bridge.js +310 -0
  35. package/dist/src/utils/canvas.js +103 -0
  36. package/dist/src/utils/chain.js +76 -0
  37. package/dist/src/utils/color.d.ts +0 -1
  38. package/dist/src/utils/color.js +312 -0
  39. package/dist/src/utils/compose.js +22 -0
  40. package/dist/src/utils/console.js +22 -0
  41. package/dist/src/utils/debounce.js +18 -0
  42. package/dist/src/utils/device.d.ts +0 -9
  43. package/dist/src/utils/device.js +31 -0
  44. package/dist/src/utils/diff.js +110 -0
  45. package/dist/src/utils/dom.d.ts +1 -1
  46. package/dist/src/utils/dom.js +89 -0
  47. package/dist/src/utils/error.js +11 -0
  48. package/dist/src/utils/event.d.ts +3 -3
  49. package/dist/src/utils/event.js +39 -0
  50. package/dist/src/utils/file.js +14 -0
  51. package/dist/src/utils/func.js +4 -0
  52. package/dist/src/utils/i18n/index.js +79 -1
  53. package/dist/src/utils/idb.js +177 -0
  54. package/dist/src/utils/img.d.ts +1 -1
  55. package/dist/src/utils/img.js +68 -0
  56. package/dist/src/utils/index.d.ts +80 -80
  57. package/dist/src/utils/index.js +306 -1
  58. package/dist/src/utils/lang.d.ts +23 -6
  59. package/dist/src/utils/lang.js +42 -0
  60. package/dist/src/utils/localePath.js +48 -0
  61. package/dist/src/utils/memoize.d.ts +1 -7
  62. package/dist/src/utils/memoize.js +16 -0
  63. package/dist/src/utils/mimeType.js +841 -0
  64. package/dist/src/utils/monitor.js +84 -0
  65. package/dist/src/utils/network.js +117 -0
  66. package/dist/src/utils/noop.js +5 -0
  67. package/dist/src/utils/number.js +185 -0
  68. package/dist/src/utils/obj.d.ts +2 -2
  69. package/dist/src/utils/obj.js +140 -0
  70. package/dist/src/utils/paginate.js +93 -0
  71. package/dist/src/utils/performance.js +26 -0
  72. package/dist/src/utils/placement.js +37 -0
  73. package/dist/src/utils/prefetch.js +69 -0
  74. package/dist/src/utils/queue.js +46 -0
  75. package/dist/src/utils/report.js +44 -0
  76. package/dist/src/utils/request.js +35 -0
  77. package/dist/src/utils/script.d.ts +1 -1
  78. package/dist/src/utils/script.js +46 -0
  79. package/dist/src/utils/scroll.js +62 -0
  80. package/dist/src/utils/secure.js +36 -0
  81. package/dist/src/utils/segment.js +43 -0
  82. package/dist/src/utils/signal.d.ts +1 -1
  83. package/dist/src/utils/signal.js +13 -0
  84. package/dist/src/utils/speech.js +59 -0
  85. package/dist/src/utils/storage.js +53 -0
  86. package/dist/src/utils/str.d.ts +0 -6
  87. package/dist/src/utils/str.js +395 -0
  88. package/dist/src/utils/style.js +29 -0
  89. package/dist/src/utils/subscribe.js +58 -0
  90. package/dist/src/utils/throttle.js +17 -0
  91. package/dist/src/utils/time.d.ts +0 -21
  92. package/dist/src/utils/time.js +97 -0
  93. package/dist/src/utils/totp/sha/common.d.ts +1 -1
  94. package/dist/src/utils/totp/sha/common.js +201 -0
  95. package/dist/src/utils/totp/sha/converters.d.ts +1 -1
  96. package/dist/src/utils/totp/sha/converters.js +188 -0
  97. package/dist/src/utils/totp/sha/primitives_32.js +55 -0
  98. package/dist/src/utils/totp/sha/primitives_64.js +85 -0
  99. package/dist/src/utils/totp/sha/sha.d.ts +1 -1
  100. package/dist/src/utils/totp/sha/sha.js +30 -0
  101. package/dist/src/utils/totp/sha/sha1.d.ts +2 -2
  102. package/dist/src/utils/totp/sha/sha1.js +51 -0
  103. package/dist/src/utils/totp/sha/sha256.d.ts +2 -2
  104. package/dist/src/utils/totp/sha/sha256.js +56 -0
  105. package/dist/src/utils/totp/sha/sha3.d.ts +3 -3
  106. package/dist/src/utils/totp/sha/sha3.js +253 -0
  107. package/dist/src/utils/totp/sha/sha512.d.ts +3 -3
  108. package/dist/src/utils/totp/sha/sha512.js +177 -0
  109. package/dist/src/utils/totp/totp.js +49 -0
  110. package/dist/src/utils/tween.js +59 -0
  111. package/dist/src/utils/visual/application.d.ts +4 -4
  112. package/dist/src/utils/visual/application.js +42 -0
  113. package/dist/src/utils/visual/enums.js +19 -0
  114. package/dist/src/utils/visual/event/boundary.d.ts +2 -2
  115. package/dist/src/utils/visual/event/boundary.js +93 -0
  116. package/dist/src/utils/visual/event/event.d.ts +1 -1
  117. package/dist/src/utils/visual/event/event.js +34 -0
  118. package/dist/src/utils/visual/event/index.d.ts +4 -4
  119. package/dist/src/utils/visual/event/types.d.ts +2 -2
  120. package/dist/src/utils/visual/event/types.js +23 -0
  121. package/dist/src/utils/visual/graphics/graphics.d.ts +8 -8
  122. package/dist/src/utils/visual/graphics/graphics.js +168 -0
  123. package/dist/src/utils/visual/graphics/graphicsData.d.ts +3 -3
  124. package/dist/src/utils/visual/graphics/graphicsData.js +12 -0
  125. package/dist/src/utils/visual/graphics/graphicsGeometry.d.ts +7 -7
  126. package/dist/src/utils/visual/graphics/graphicsGeometry.js +39 -0
  127. package/dist/src/utils/visual/graphics/index.d.ts +3 -3
  128. package/dist/src/utils/visual/index.d.ts +8 -8
  129. package/dist/src/utils/visual/index.js +20 -1
  130. package/dist/src/utils/visual/math/bezier.js +15 -0
  131. package/dist/src/utils/visual/math/enums.js +6 -0
  132. package/dist/src/utils/visual/math/index.d.ts +4 -4
  133. package/dist/src/utils/visual/math/matrix.d.ts +1 -1
  134. package/dist/src/utils/visual/math/matrix.js +59 -0
  135. package/dist/src/utils/visual/math/transform.d.ts +2 -2
  136. package/dist/src/utils/visual/math/transform.js +50 -0
  137. package/dist/src/utils/visual/render/batchRenderer.d.ts +4 -4
  138. package/dist/src/utils/visual/render/batchRenderer.js +59 -0
  139. package/dist/src/utils/visual/render/canvasRenderer.d.ts +3 -3
  140. package/dist/src/utils/visual/render/canvasRenderer.js +17 -0
  141. package/dist/src/utils/visual/render/filter.d.ts +1 -1
  142. package/dist/src/utils/visual/render/filter.js +92 -0
  143. package/dist/src/utils/visual/render/index.d.ts +2 -2
  144. package/dist/src/utils/visual/render/index.js +20 -0
  145. package/dist/src/utils/visual/render/render.d.ts +4 -4
  146. package/dist/src/utils/visual/render/render.js +19 -0
  147. package/dist/src/utils/visual/render/renderTarget.js +28 -0
  148. package/dist/src/utils/visual/render/utils/batch/index.d.ts +4 -4
  149. package/dist/src/utils/visual/render/utils/batch/index.js +88 -0
  150. package/dist/src/utils/visual/render/utils/earcut.js +328 -0
  151. package/dist/src/utils/visual/render/utils/float.js +65 -0
  152. package/dist/src/utils/visual/render/utils/index.js +50 -0
  153. package/dist/src/utils/visual/render/utils/verticy.d.ts +2 -2
  154. package/dist/src/utils/visual/render/utils/verticy.js +162 -0
  155. package/dist/src/utils/visual/render/utils/webgl/initShader.d.ts +1 -1
  156. package/dist/src/utils/visual/render/utils/webgl/initShader.js +31 -0
  157. package/dist/src/utils/visual/render/utils/webgl/shaders.js +22 -0
  158. package/dist/src/utils/visual/render/utils/webgpu/shaders.js +32 -0
  159. package/dist/src/utils/visual/render/webGPURenderer.d.ts +2 -2
  160. package/dist/src/utils/visual/render/webGPURenderer.js +185 -0
  161. package/dist/src/utils/visual/render/webGlRenderer.d.ts +2 -2
  162. package/dist/src/utils/visual/render/webGlRenderer.js +88 -0
  163. package/dist/src/utils/visual/shape/circle.d.ts +3 -3
  164. package/dist/src/utils/visual/shape/circle.js +17 -0
  165. package/dist/src/utils/visual/shape/ellipse.d.ts +3 -3
  166. package/dist/src/utils/visual/shape/ellipse.js +18 -0
  167. package/dist/src/utils/visual/shape/index.d.ts +6 -6
  168. package/dist/src/utils/visual/shape/polygon.d.ts +3 -3
  169. package/dist/src/utils/visual/shape/polygon.js +29 -0
  170. package/dist/src/utils/visual/shape/rectangle.d.ts +3 -3
  171. package/dist/src/utils/visual/shape/rectangle.js +18 -0
  172. package/dist/src/utils/visual/shape/roundedRectangle.d.ts +3 -3
  173. package/dist/src/utils/visual/shape/roundedRectangle.js +32 -0
  174. package/dist/src/utils/visual/shape/shape.d.ts +2 -2
  175. package/dist/src/utils/visual/shape/shape.js +5 -0
  176. package/dist/src/utils/visual/style/fill.js +18 -0
  177. package/dist/src/utils/visual/style/index.d.ts +2 -2
  178. package/dist/src/utils/visual/style/line.d.ts +2 -2
  179. package/dist/src/utils/visual/style/line.js +18 -0
  180. package/dist/src/utils/visual/types.d.ts +1 -1
  181. package/dist/src/utils/visual/vertex/container.d.ts +5 -5
  182. package/dist/src/utils/visual/vertex/container.js +54 -0
  183. package/dist/src/utils/visual/vertex/point.js +37 -0
  184. package/dist/src/utils/visual/vertex/vertex.d.ts +7 -7
  185. package/dist/src/utils/visual/vertex/vertex.js +76 -0
  186. package/dist/src/utils/worker.js +89 -0
  187. package/dist/src/utils/zip.js +161 -0
  188. package/dist/src/vnode/h.d.ts +1 -1
  189. package/dist/src/vnode/h.js +22 -0
  190. package/dist/src/vnode/hooks.d.ts +1 -1
  191. package/dist/src/vnode/htmlDomApi.js +94 -0
  192. package/dist/src/vnode/index.d.ts +16 -16
  193. package/dist/src/vnode/index.js +28 -1
  194. package/dist/src/vnode/init.d.ts +1 -1
  195. package/dist/src/vnode/init.js +104 -0
  196. package/dist/src/vnode/is.d.ts +1 -1
  197. package/dist/src/vnode/is.js +20 -0
  198. package/dist/src/vnode/modules/attributes.d.ts +1 -1
  199. package/dist/src/vnode/modules/attributes.js +21 -0
  200. package/dist/src/vnode/modules/class.d.ts +1 -1
  201. package/dist/src/vnode/modules/class.js +18 -0
  202. package/dist/src/vnode/modules/index.js +15 -0
  203. package/dist/src/vnode/modules/listeners.d.ts +1 -1
  204. package/dist/src/vnode/modules/listeners.js +36 -0
  205. package/dist/src/vnode/modules/props.d.ts +1 -1
  206. package/dist/src/vnode/modules/props.js +17 -0
  207. package/dist/src/vnode/modules/style.d.ts +1 -1
  208. package/dist/src/vnode/modules/style.js +52 -0
  209. package/dist/src/vnode/vnode.d.ts +6 -6
  210. package/dist/src/vnode/vnode.js +13 -0
  211. package/dist/third-party/jschardet/LICENSE.txt +504 -0
  212. package/dist/third-party/jschardet/NOTICE.txt +33 -0
  213. package/docs/API.md +8 -64
  214. package/package.json +12 -16
  215. package/dist/bin/generate-api-docs.d.ts +0 -1
  216. package/dist/build/build.es.d.ts +0 -2
  217. package/dist/build/build.umd.d.ts +0 -2
  218. package/dist/build/build.umd.node.d.ts +0 -2
  219. package/dist/build/build.umd.utils.d.ts +0 -2
  220. package/dist/chain-CTywmh_H.js +0 -1
  221. package/dist/color-BTvZUuf-.js +0 -1
  222. package/dist/enums-BAgbyGdH.js +0 -1
  223. package/dist/examples/clone-deep-example.d.ts +0 -1
  224. package/dist/examples/is-equal-example.d.ts +0 -1
  225. package/dist/i18n-DW21b_DJ.js +0 -1
  226. package/dist/plugins/vite-plugins-banner.d.ts +0 -2
  227. package/dist/rolldown-runtime-I3TIJKkN.js +0 -1
  228. package/dist/src/node/appendFile.d.ts +0 -7
  229. package/dist/src/node/body.d.ts +0 -9
  230. package/dist/src/node/color.d.ts +0 -7
  231. package/dist/src/node/command.d.ts +0 -8
  232. package/dist/src/node/ctx2req.d.ts +0 -5
  233. package/dist/src/node/fileInfo.d.ts +0 -7
  234. package/dist/src/node/fs.d.ts +0 -7
  235. package/dist/src/node/get.d.ts +0 -10
  236. package/dist/src/node/getIPAdress.d.ts +0 -1
  237. package/dist/src/node/index.d.ts +0 -25
  238. package/dist/src/node/index.js +0 -1
  239. package/dist/src/node/isColorSupported.d.ts +0 -2
  240. package/dist/src/node/paresUrl.d.ts +0 -19
  241. package/dist/src/node/readDir.d.ts +0 -6
  242. package/dist/src/node/readFile.d.ts +0 -9
  243. package/dist/src/node/router.d.ts +0 -42
  244. package/dist/src/node/send.d.ts +0 -7
  245. package/dist/src/node/server.d.ts +0 -18
  246. package/dist/src/node/startTask.d.ts +0 -2
  247. package/dist/src/node/stream.d.ts +0 -15
  248. package/dist/src/node/taskEnd.d.ts +0 -2
  249. package/dist/src/node/traverse.d.ts +0 -17
  250. package/dist/src/node/watchFile.d.ts +0 -8
  251. package/dist/src/node/writeFile.d.ts +0 -8
  252. package/dist/src/node/ws.d.ts +0 -8
  253. package/dist/src/utils/visual/render/utils/batch/index.test.d.ts +0 -1
  254. package/dist/src/utils/visual/render/utils/index.test.d.ts +0 -1
  255. package/dist/test/binary.test.d.ts +0 -1
  256. package/dist/test/bridge.test.d.ts +0 -1
  257. package/dist/test/budget.test.d.ts +0 -1
  258. package/dist/test/canvas.test.d.ts +0 -1
  259. package/dist/test/clearBr.test.d.ts +0 -1
  260. package/dist/test/cloneDeep.test.d.ts +0 -1
  261. package/dist/test/color.test.d.ts +0 -1
  262. package/dist/test/command.test.d.ts +0 -1
  263. package/dist/test/conversation.test.d.ts +0 -1
  264. package/dist/test/diff.test.d.ts +0 -1
  265. package/dist/test/encodeUrl.test.d.ts +0 -1
  266. package/dist/test/escapeHtml.test.d.ts +0 -1
  267. package/dist/test/formatBytes.test.d.ts +0 -1
  268. package/dist/test/is-equal.test.d.ts +0 -1
  269. package/dist/test/mimeType.test.d.ts +0 -1
  270. package/dist/test/package-exports.test.d.ts +0 -1
  271. package/dist/test/scroll.test.d.ts +0 -1
  272. package/dist/test/server.test.d.ts +0 -1
  273. package/dist/test/status.test.d.ts +0 -1
  274. package/dist/test/stream.test.d.ts +0 -1
  275. package/dist/test/sw.test.d.ts +0 -1
  276. package/dist/test/totp.test.d.ts +0 -1
  277. package/dist/test/tween.test.d.ts +0 -1
  278. package/dist/test/utils/async.test.d.ts +0 -1
  279. package/dist/test/utils/autosize.test.d.ts +0 -1
  280. package/dist/test/utils/color-grade.test.d.ts +0 -1
  281. package/dist/test/utils/compose.test.d.ts +0 -1
  282. package/dist/test/utils/event.test.d.ts +0 -1
  283. package/dist/test/utils/file-read.test.d.ts +0 -1
  284. package/dist/test/utils/format.test.d.ts +0 -1
  285. package/dist/test/utils/i18n.test.d.ts +0 -1
  286. package/dist/test/utils/idb-collection.test.d.ts +0 -1
  287. package/dist/test/utils/idb.test.d.ts +0 -1
  288. package/dist/test/utils/instrumentation.test.d.ts +0 -1
  289. package/dist/test/utils/interp.test.d.ts +0 -1
  290. package/dist/test/utils/lang.test.d.ts +0 -1
  291. package/dist/test/utils/locale-path.test.d.ts +0 -1
  292. package/dist/test/utils/media-query.test.d.ts +0 -1
  293. package/dist/test/utils/mergeObj.test.d.ts +0 -1
  294. package/dist/test/utils/number-parse.test.d.ts +0 -1
  295. package/dist/test/utils/paginate.test.d.ts +0 -1
  296. package/dist/test/utils/placement.test.d.ts +0 -1
  297. package/dist/test/utils/prefetch.test.d.ts +0 -1
  298. package/dist/test/utils/query-storage.test.d.ts +0 -1
  299. package/dist/test/utils/queue.test.d.ts +0 -1
  300. package/dist/test/utils/report-config.test.d.ts +0 -1
  301. package/dist/test/utils/report-image.test.d.ts +0 -1
  302. package/dist/test/utils/secure.test.d.ts +0 -1
  303. package/dist/test/utils/segment.test.d.ts +0 -1
  304. package/dist/test/utils/signal-once.test.d.ts +0 -1
  305. package/dist/test/utils/single-flight.test.d.ts +0 -1
  306. package/dist/test/utils/speech.test.d.ts +0 -1
  307. package/dist/test/utils/text-boundary.test.d.ts +0 -1
  308. package/dist/test/utils/time.test.d.ts +0 -1
  309. package/dist/test/utils/timing.test.d.ts +0 -1
  310. package/dist/test/utils/truncate.test.d.ts +0 -1
  311. package/dist/test/utils/visual/filter.test.d.ts +0 -1
  312. package/dist/test/utils/worker-client.test.d.ts +0 -1
  313. package/dist/test/utils/worker-serve.test.d.ts +0 -1
  314. package/dist/test/utils/zip.test.d.ts +0 -1
  315. package/dist/test/visual/math.test.d.ts +0 -1
  316. package/dist/test/visual-application.test.d.ts +0 -1
  317. package/dist/test/visual-batch.test.d.ts +0 -1
  318. package/dist/test/visual-math.test.d.ts +0 -1
  319. package/dist/test/vnode/index.d.ts +0 -1
  320. package/dist/test/vnode/server.d.ts +0 -2
  321. package/dist/test/vnode/vnode.d.ts +0 -1
  322. package/dist/test/vnode.test.d.ts +0 -1
  323. package/dist/test/websocket.test.d.ts +0 -1
  324. package/dist/test/writeFile.test.d.ts +0 -1
  325. package/dist/umd/index.umd.cjs +0 -1
  326. package/dist/umd/node/node.umd.cjs +0 -1
  327. package/dist/umd/utils/utils.umd.cjs +0 -1
  328. package/dist/utils-B4FnyUzW.js +0 -1
  329. package/dist/vite.config.d.ts +0 -8
  330. package/dist/vitest.config.d.ts +0 -2
@@ -0,0 +1,9 @@
1
+ import { noop as n } from "./noop.js";
2
+ var c = (t = n) => {
3
+ if (typeof document > "u") return n;
4
+ const e = (r) => t(r);
5
+ return document.addEventListener("click", e, !0), () => document.removeEventListener("click", e, !0);
6
+ };
7
+ export {
8
+ c as handleClick
9
+ };
@@ -0,0 +1,89 @@
1
+ var i = (e) => {
2
+ const r = e instanceof Uint8Array ? e : new Uint8Array(e), t = 32768;
3
+ let n = "";
4
+ for (let a = 0; a < r.length; a += t) n += String.fromCharCode.apply(null, Array.from(r.subarray(a, a + t)));
5
+ return btoa(n);
6
+ }, l = (e) => {
7
+ const r = e.startsWith("data:") ? e.slice(e.indexOf(",") + 1) : e, t = atob(r), n = new Uint8Array(t.length);
8
+ for (let a = 0; a < t.length; a++) n[a] = t.charCodeAt(a);
9
+ return n;
10
+ }, h = (e) => i(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), f = (e) => {
11
+ try {
12
+ const r = e.replace(/-/g, "+").replace(/_/g, "/"), t = r.padEnd(Math.ceil(r.length / 4) * 4, "=");
13
+ return l(t);
14
+ } catch {
15
+ return null;
16
+ }
17
+ }, w = (e) => {
18
+ let r = 0;
19
+ for (const a of e) r += a.length;
20
+ const t = new Uint8Array(r);
21
+ let n = 0;
22
+ for (const a of e)
23
+ t.set(a, n), n += a.length;
24
+ return t;
25
+ }, s = (e) => e.length >= 2 && e[0] === 31 && e[1] === 139, u = (e) => e.length >= 4 && e[0] === 80 && e[1] === 75 && e[2] === 3 && e[3] === 4, m = (e) => {
26
+ if (e.length < 8 || u(e)) return !1;
27
+ const r = e[0] === 239 && e[1] === 187 && e[2] === 191 ? 3 : 0, t = new TextDecoder("latin1").decode(e.subarray(r, r + 2048)).replace(/^\s+/, "");
28
+ return /^<(!doctype\s+html|html|head|body|table|meta|\?xml[^>]*>\s*<html)/i.test(t);
29
+ }, p = async (e) => {
30
+ if (!s(e)) return e;
31
+ if (typeof DecompressionStream > "u") throw new Error("DecompressionStream is not available in this runtime");
32
+ const r = new Response(e).body.pipeThrough(new DecompressionStream("gzip"));
33
+ return new Uint8Array(await new Response(r).arrayBuffer());
34
+ }, y = async (e, r) => {
35
+ const t = await fetch(e, r);
36
+ if (!t.ok) throw new Error(`Failed to fetch '${String(e)}' (${t.status} ${t.statusText})`);
37
+ return p(new Uint8Array(await t.arrayBuffer()));
38
+ }, g = (e, r = [
39
+ "utf-8",
40
+ "gb18030",
41
+ "latin1"
42
+ ]) => {
43
+ if (e.length >= 3 && e[0] === 239 && e[1] === 187 && e[2] === 191) return new TextDecoder("utf-8").decode(e.subarray(3));
44
+ for (let t = 0; t < r.length; t++) {
45
+ const n = t === r.length - 1;
46
+ try {
47
+ return new TextDecoder(r[t], { fatal: !n }).decode(e);
48
+ } catch {
49
+ }
50
+ }
51
+ return new TextDecoder("latin1").decode(e);
52
+ }, v = async (e, r, t = {}) => {
53
+ const n = e instanceof Blob ? e : new Blob([e], { type: t.mimeType }), a = globalThis.showSaveFilePicker;
54
+ if (typeof a == "function") {
55
+ const c = r.includes(".") ? `.${r.split(".").pop()}` : "";
56
+ try {
57
+ const o = await (await a({
58
+ suggestedName: r,
59
+ types: [{
60
+ description: t.description || "File",
61
+ accept: { [t.mimeType || n.type || "application/octet-stream"]: c ? [c] : [] }
62
+ }]
63
+ })).createWritable();
64
+ return await o.write(n), await o.close(), !0;
65
+ } catch (o) {
66
+ if (o?.name === "AbortError") return !1;
67
+ }
68
+ }
69
+ return d(n, r);
70
+ }, d = (e, r) => {
71
+ const t = URL.createObjectURL(e), n = document.createElement("a");
72
+ return n.href = t, n.download = r, n.style.display = "none", document.body.appendChild(n), n.click(), setTimeout(() => {
73
+ n.remove(), URL.revokeObjectURL(t);
74
+ }, 100), !0;
75
+ };
76
+ export {
77
+ l as base64ToBytes,
78
+ f as base64UrlToBytes,
79
+ i as bytesToBase64,
80
+ h as bytesToBase64Url,
81
+ w as concatBytes,
82
+ g as decodeTextBytes,
83
+ y as fetchMaybeGzip,
84
+ p as gunzipMaybe,
85
+ s as isGzip,
86
+ m as isHtmlDocument,
87
+ u as isZipContainer,
88
+ v as saveFileToDisk
89
+ };
@@ -4,28 +4,34 @@
4
4
  * @return {*}
5
5
  */
6
6
  export declare const getCookie: (objName: string) => string;
7
- export interface RequestUrlToArraybufferOption {
8
- responseType: XMLHttpRequestResponseType;
7
+ export interface RequestUrlToArraybufferOption<T extends XMLHttpRequestResponseType = XMLHttpRequestResponseType> {
8
+ responseType: T;
9
9
  method: string;
10
10
  withCredentials: boolean;
11
11
  headers: Record<string, string>;
12
12
  body: string;
13
- onProgress?: Function;
13
+ onProgress?: (event: ProgressEvent) => void;
14
14
  }
15
- export interface requestUrlToArraybufferReturn extends BaseReturn {
16
- data: Blob;
15
+ export interface requestUrlToArraybufferReturn<T = ArrayBuffer> extends BaseReturn {
16
+ data: T;
17
17
  }
18
+ type RequestUrlResponse<T extends XMLHttpRequestResponseType> = T extends '' | 'arraybuffer' ? ArrayBuffer : T extends 'blob' ? Blob : T extends 'text' ? string : T extends 'document' ? Document | null : unknown;
18
19
  export interface BaseReturn {
19
20
  success: boolean;
20
21
  message?: string;
21
22
  }
22
23
  /**
23
- * @description: Fetch a URL as an ArrayBuffer
24
+ * @description: Fetch a URL as an ArrayBuffer by default, or as the requested XHR response type
25
+ * An empty responseType also uses ArrayBuffer. JSON responses require validation before use.
24
26
  * @param {string} src
25
27
  * @param {RequestUrlToArraybufferOption} options
26
28
  * @return {*}
27
29
  */
28
- export declare const requestUrlToBuffer: (src: string, options: Partial<RequestUrlToArraybufferOption>) => Promise<requestUrlToArraybufferReturn>;
30
+ export declare function requestUrlToBuffer(src: string, options?: Partial<RequestUrlToArraybufferOption<'' | 'arraybuffer'>>): Promise<requestUrlToArraybufferReturn>;
31
+ export declare function requestUrlToBuffer<T extends XMLHttpRequestResponseType>(src: string, options: Partial<RequestUrlToArraybufferOption<T>> & {
32
+ responseType: T;
33
+ }): Promise<requestUrlToArraybufferReturn<RequestUrlResponse<T>>>;
34
+ export declare function requestUrlToBuffer<T extends XMLHttpRequestResponseType>(src: string, options: Partial<RequestUrlToArraybufferOption<T>>): Promise<requestUrlToArraybufferReturn<RequestUrlResponse<T | 'arraybuffer'>>>;
29
35
  export interface Context {
30
36
  backingStorePixelRatio: number;
31
37
  webkitBackingStorePixelRatio: number;
@@ -39,7 +45,7 @@ export interface Context {
39
45
  * @return {*}
40
46
  */
41
47
  export declare const getPixelRatio: (context: CanvasRenderingContext2D & Partial<Context>) => number;
42
- export declare const createObjectURL: (src: Blob | ArrayBuffer | Response) => Promise<string>;
48
+ export declare const createObjectURL: (src: string | Blob | ArrayBuffer | Response) => Promise<string>;
43
49
  /**
44
50
  * @description: Frames per millisecond; multiply by 1000 for frames per second
45
51
  * @return {*}
@@ -112,10 +118,26 @@ interface ClientRatio {
112
118
  * Get the viewport size across browsers
113
119
  */
114
120
  export declare const getWindow: () => ClientRatio;
121
+ /**
122
+ * The subset of the Network Information API's `NetworkInformation` object that browsers
123
+ * actually ship. It is not in TypeScript's DOM lib because the spec is not standardised.
124
+ */
125
+ export interface NetworkInformation extends EventTarget {
126
+ /** 'slow-2g' | '2g' | '3g' | '4g' */
127
+ effectiveType?: string;
128
+ /** Estimated downlink bandwidth in Mbps */
129
+ downlink?: number;
130
+ /** Estimated round-trip time in milliseconds */
131
+ rtt?: number;
132
+ /** Whether the user has asked for reduced data usage */
133
+ saveData?: boolean;
134
+ /** 'wifi' | 'cellular' | 'ethernet' | … where the platform exposes it */
135
+ type?: string;
136
+ }
115
137
  /**
116
138
  * @description: Current network status: type, throughput, and whether the connection changed
117
139
  */
118
- export declare const connection: () => number | undefined;
140
+ export declare const connection: () => NetworkInformation | undefined;
119
141
  /**
120
142
  * Encode a URL to a percent-encoded form, excluding already-encoded sequences.
121
143
  *
@@ -0,0 +1,165 @@
1
+ import { performanceTime as f } from "./time.js";
2
+ var v = (t) => {
3
+ const e = document.cookie.split("; ");
4
+ for (let i = 0; i < e.length; i++) {
5
+ const n = e[i].split("=");
6
+ if (n[0] === t) return decodeURIComponent(n[1]);
7
+ }
8
+ return "";
9
+ };
10
+ function x(t, e = {}) {
11
+ return new Promise(function(i, n) {
12
+ const r = new XMLHttpRequest();
13
+ r.open(e.method || "GET", t, !0), r.responseType = e.responseType || "arraybuffer", r.onload = function() {
14
+ r.status === 200 ? i({
15
+ success: !0,
16
+ data: r.response,
17
+ message: ""
18
+ }) : n({
19
+ success: !1,
20
+ data: r.status,
21
+ message: `The request status is${r.status}`
22
+ });
23
+ }, r.onerror = function(o) {
24
+ n({
25
+ success: !1,
26
+ data: o,
27
+ message: ""
28
+ });
29
+ }, r.onprogress = (o) => {
30
+ e.onProgress && e.onProgress(o);
31
+ }, r.withCredentials = e.withCredentials || !1, e.headers && Object.keys(e.headers).forEach(function(o) {
32
+ e.headers?.[o] && r.setRequestHeader(o, e.headers[o]);
33
+ }), r.send(e.body);
34
+ });
35
+ }
36
+ var y = (t) => {
37
+ const e = t.backingStorePixelRatio || t.webkitBackingStorePixelRatio || t.mozBackingStorePixelRatio || t.msBackingStorePixelRatio || t.oBackingStorePixelRatio || 1;
38
+ return ((typeof window > "u" ? 1 : window.devicePixelRatio) || 1) / e;
39
+ }, F = async (t) => {
40
+ if (typeof t == "string") return t;
41
+ if (t instanceof Blob) return URL.createObjectURL(t);
42
+ if (t instanceof ArrayBuffer) return URL.createObjectURL(new Blob([t]));
43
+ if (t instanceof Response) {
44
+ const e = await t.blob();
45
+ return URL.createObjectURL(e);
46
+ } else return t;
47
+ }, P = (t = 10) => {
48
+ const e = [];
49
+ let i = 0, n;
50
+ return new Promise((r) => {
51
+ const o = () => {
52
+ const a = f(), s = a - i;
53
+ i !== 0 && e.push(s), i = a, e.length > t && (r(1 / (e.reduce((u, c) => u + c) / t)), cancelAnimationFrame(n)), n = requestAnimationFrame(o);
54
+ };
55
+ e.length <= t && (n = requestAnimationFrame(o));
56
+ });
57
+ }, d = (t) => {
58
+ const e = t ?? (typeof window > "u" ? "" : window.location.href), i = e.indexOf("?");
59
+ if (i === -1) return "";
60
+ const n = e.slice(i + 1), r = n.indexOf("#");
61
+ return r === -1 ? n : n.slice(0, r);
62
+ }, l = (t) => {
63
+ const e = {}, i = d(t);
64
+ if (!i) return e;
65
+ for (const n of i.split("&")) {
66
+ if (!n) continue;
67
+ const r = n.indexOf("="), o = r === -1 ? n : n.slice(0, r), a = r === -1 ? "" : n.slice(r + 1);
68
+ if (o)
69
+ try {
70
+ e[decodeURIComponent(o.replace(/\+/g, " "))] = decodeURIComponent(a.replace(/\+/g, " "));
71
+ } catch {
72
+ e[o] = a;
73
+ }
74
+ }
75
+ return e;
76
+ }, U = (t, e) => {
77
+ const i = l(e)[t];
78
+ if (i === void 0) return !1;
79
+ const n = i.toLowerCase();
80
+ return n === "" || n === "1" || n === "true";
81
+ }, A = () => {
82
+ if (typeof window > "u") return !1;
83
+ try {
84
+ return window.parent !== window;
85
+ } catch {
86
+ return !0;
87
+ }
88
+ };
89
+ function O(t, e = {}) {
90
+ let i = t;
91
+ i.indexOf("//") === 0 && (i = i.replace("//", "https://"));
92
+ const n = new URL(i);
93
+ return e && Object.keys(e).forEach((r) => {
94
+ e[r] && n.searchParams.set(r, e[r]);
95
+ }), n.href;
96
+ }
97
+ function b(t) {
98
+ if (typeof window < "u") {
99
+ const e = new RegExp(`(^| )${t}(?:=([^;]*))?(;|$)`).exec(document.cookie);
100
+ if (e && e[2]) return e[2];
101
+ }
102
+ return "";
103
+ }
104
+ var E = () => typeof window < "u" ? {
105
+ width: window.innerWidth,
106
+ height: window.innerHeight
107
+ } : {
108
+ width: 0,
109
+ height: 0
110
+ }, C = () => {
111
+ if (typeof window < "u") return window.navigator.connection;
112
+ }, g = /(?:[^\x21\x25\x26-\x3B\x3D\x3F-\x5B\x5D\x5F\x7E]|%(?:[^\da-f]|[\da-f][^\da-f]|$))+/gi, w = /(^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF]([^\uDC00-\uDFFF]|$)/g, m = "$1�$2";
113
+ function S(t) {
114
+ return String(t).replace(w, m).replace(g, encodeURI);
115
+ }
116
+ var h = (t) => new Promise((e, i) => {
117
+ const n = new Image(), r = (/* @__PURE__ */ new Date()).getTime();
118
+ n.src = t || `https://github.com/favicon.ico?d=${r}`, n.onload = () => {
119
+ e((/* @__PURE__ */ new Date()).getTime() - r);
120
+ }, n.onerror = (o) => {
121
+ i(o);
122
+ };
123
+ }), R = (t, ...e) => (i) => new Promise((n, r) => {
124
+ setTimeout(async () => {
125
+ try {
126
+ n(await t(...e));
127
+ } catch (o) {
128
+ r(o);
129
+ }
130
+ }, i);
131
+ }), D = async (t) => {
132
+ const { url: e, duration: i = 3e3, count: n = 5 } = t;
133
+ let r = 0, o = 0;
134
+ const a = [];
135
+ for (let s = 0; s < n; s++) {
136
+ const u = await R(h, e)(i);
137
+ a.push(u);
138
+ }
139
+ return r = Math.max(...a) - Math.min(...a), o = a.reduce((s, u) => s + u) / a.length, {
140
+ ping: o,
141
+ jitter: r
142
+ };
143
+ }, L = () => {
144
+ if (!(typeof navigator > "u"))
145
+ return navigator.vendor && navigator.vendor.indexOf("Apple") > -1 && navigator.userAgent && !navigator.userAgent.includes("CriOS") && !navigator.userAgent.includes("FxiOS");
146
+ };
147
+ export {
148
+ O as appendUrl,
149
+ C as connection,
150
+ F as createObjectURL,
151
+ R as durationHandler,
152
+ S as encodeUrl,
153
+ l as getAllQueryString,
154
+ v as getCookie,
155
+ b as getCookieByName,
156
+ P as getFrame,
157
+ y as getPixelRatio,
158
+ E as getWindow,
159
+ h as imageRequest,
160
+ A as isInIframe,
161
+ L as isSafari,
162
+ D as networkSpeed,
163
+ U as queryFlag,
164
+ x as requestUrlToBuffer
165
+ };
@@ -0,0 +1,310 @@
1
+ import { getRandomString as p } from "./str.js";
2
+ import { isFunction as w } from "./func.js";
3
+ var b = 12e4, m = "__ranuts_bridge__", v = "default", R = class {
4
+ bridges = /* @__PURE__ */ new Set();
5
+ attachedWindow = null;
6
+ handleMessage = (e) => {
7
+ for (const t of Array.from(this.bridges)) t.receive(e);
8
+ };
9
+ add(e) {
10
+ this.bridges.add(e), typeof window < "u" && this.attachedWindow !== window && (window.addEventListener("message", this.handleMessage), this.attachedWindow = window);
11
+ }
12
+ remove(e) {
13
+ this.bridges.delete(e), this.bridges.size === 0 && this.attachedWindow && (this.attachedWindow.removeEventListener("message", this.handleMessage), this.attachedWindow = null);
14
+ }
15
+ }, y = new R(), M = class {
16
+ targetWindow;
17
+ targetOrigin;
18
+ messageHandlers;
19
+ pendingRequests;
20
+ channel;
21
+ senderId;
22
+ available;
23
+ constructor(e, t = "*", r = v) {
24
+ if (this.targetOrigin = t, this.channel = r, this.senderId = p(12), this.messageHandlers = /* @__PURE__ */ new Map(), this.pendingRequests = /* @__PURE__ */ new Map(), this.available = typeof window < "u", !this.available) {
25
+ this.targetWindow = void 0;
26
+ return;
27
+ }
28
+ this.targetWindow = e ?? window, y.add(this);
29
+ }
30
+ post(e, t) {
31
+ const r = {
32
+ ...t,
33
+ __bridge: m,
34
+ channel: this.channel,
35
+ senderId: this.senderId
36
+ };
37
+ e.postMessage(r, this.targetOrigin);
38
+ }
39
+ receive = (e) => {
40
+ if (!this.available || this.targetOrigin !== "*" && e.origin !== this.targetOrigin || e.source && e.source !== this.targetWindow) return;
41
+ const t = e.data;
42
+ if (!t || typeof t != "object" || t.__bridge !== "__ranuts_bridge__" || (t.channel ?? "default") !== this.channel) return;
43
+ const { type: r, payload: a, id: s, isResponse: n, isError: o, senderId: c } = t;
44
+ if (n && s) {
45
+ const g = this.pendingRequests.get(s);
46
+ g && (o ? g.reject(new Error(typeof a == "string" ? a : "Bridge request failed")) : g.resolve(a), this.pendingRequests.delete(s));
47
+ return;
48
+ }
49
+ if (c && c === this.senderId || typeof r != "string" || !this.messageHandlers.has(r)) return;
50
+ const i = this.messageHandlers.get(r);
51
+ if (w(i)) {
52
+ const g = e.source ?? this.targetWindow;
53
+ Promise.resolve(i(a)).then((l) => {
54
+ s && this.post(g, {
55
+ type: r,
56
+ payload: l,
57
+ id: s,
58
+ isResponse: !0
59
+ });
60
+ }).catch((l) => {
61
+ s && this.post(g, {
62
+ type: r,
63
+ payload: l instanceof Error ? l.message : String(l),
64
+ id: s,
65
+ isResponse: !0,
66
+ isError: !0
67
+ });
68
+ });
69
+ }
70
+ };
71
+ on = (e, t) => {
72
+ this.messageHandlers.set(e, t);
73
+ };
74
+ off = (e) => {
75
+ this.messageHandlers.delete(e);
76
+ };
77
+ send = async (e, t) => {
78
+ if (!this.available) return Promise.reject(/* @__PURE__ */ new Error("PostMessageBridge is unavailable outside a browser environment"));
79
+ const r = p(10);
80
+ return new Promise((a, s) => {
81
+ const n = setTimeout(() => {
82
+ this.pendingRequests.has(r) && (this.pendingRequests.delete(r), s(/* @__PURE__ */ new Error("Request timeout")));
83
+ }, b), o = (i) => {
84
+ clearTimeout(n), a(i);
85
+ }, c = (i) => {
86
+ clearTimeout(n), s(i);
87
+ };
88
+ this.pendingRequests.set(r, {
89
+ resolve: o,
90
+ reject: c
91
+ });
92
+ try {
93
+ this.post(this.targetWindow, {
94
+ type: e,
95
+ payload: t,
96
+ id: r
97
+ });
98
+ } catch (i) {
99
+ this.pendingRequests.delete(r), c(i instanceof Error ? i : /* @__PURE__ */ new Error("Failed to post message"));
100
+ }
101
+ });
102
+ };
103
+ broadcast = (e) => {
104
+ if (this.available)
105
+ try {
106
+ this.post(this.targetWindow, {
107
+ type: e.type,
108
+ payload: e.payload
109
+ });
110
+ } catch {
111
+ }
112
+ };
113
+ destroy = () => {
114
+ y.remove(this), this.messageHandlers.clear(), this.pendingRequests.forEach((e) => {
115
+ e.reject(/* @__PURE__ */ new Error("Bridge destroyed"));
116
+ }), this.pendingRequests.clear();
117
+ };
118
+ }, B = class f {
119
+ static instance;
120
+ bridges = /* @__PURE__ */ new Map();
121
+ constructor() {
122
+ }
123
+ static getInstance() {
124
+ return f.instance || (f.instance = new f()), f.instance;
125
+ }
126
+ connectClient = ({ id: t, targetOrigin: r, targetWindow: a, channel: s }) => {
127
+ const n = new M(a, r, s);
128
+ if (t || (t = p(10)), this.bridges.has(t)) throw new Error(`Bridge ${t} already exists`);
129
+ return this.bridges.set(t, n), {
130
+ bridge: n,
131
+ id: t
132
+ };
133
+ };
134
+ getClient = (t) => this.bridges.get(t);
135
+ removeClient = (t) => {
136
+ const r = this.bridges.get(t);
137
+ r && (r.destroy(), this.bridges.delete(t));
138
+ };
139
+ removeAllClient = () => {
140
+ this.bridges.forEach((t) => {
141
+ t.destroy();
142
+ }), this.bridges.clear();
143
+ };
144
+ broadcast = (t) => {
145
+ this.bridges.forEach((r) => {
146
+ r.broadcast(t);
147
+ });
148
+ };
149
+ sendTo = (t, r, a) => {
150
+ const s = this.getClient(t);
151
+ return s ? s.send(r, a) : Promise.reject(/* @__PURE__ */ new Error(`Bridge ${t} not found`));
152
+ };
153
+ }, u = B.getInstance(), T = {
154
+ connect: ({ id: e, targetWindow: t, targetOrigin: r, channel: a }) => u.connectClient({
155
+ id: e,
156
+ targetWindow: t,
157
+ targetOrigin: r,
158
+ channel: a
159
+ }),
160
+ remove: (e) => {
161
+ e && u.removeClient(e);
162
+ },
163
+ removeAll: () => {
164
+ u.removeAllClient();
165
+ },
166
+ broadcast: (e) => u.broadcast(e),
167
+ call: ({ id: e, type: t, payload: r }) => u.sendTo(e, t, r),
168
+ broadcastToAll: (e) => {
169
+ if (typeof window > "u") return;
170
+ const t = {
171
+ __bridge: m,
172
+ channel: v,
173
+ type: e.type,
174
+ payload: e.payload
175
+ };
176
+ return window.postMessage(t, "*");
177
+ }
178
+ }, P = (e) => {
179
+ const t = new Map(Object.entries(e).filter((s) => w(s[1]))), r = async (s) => {
180
+ const n = s.data;
181
+ if (!n || typeof n != "object" || n.__bridge !== "__ranuts_bridge__") return;
182
+ const { type: o, payload: c, id: i } = n, g = n.channel ?? "default";
183
+ if (typeof o != "string" || !t.has(o)) return;
184
+ const l = t.get(o);
185
+ if (!l) return;
186
+ const h = (d) => {
187
+ i && s.source?.postMessage({
188
+ __bridge: m,
189
+ channel: g,
190
+ type: o,
191
+ id: i,
192
+ isResponse: !0,
193
+ ...d
194
+ }, { targetOrigin: s.origin });
195
+ };
196
+ try {
197
+ h({ payload: await l(c) });
198
+ } catch (d) {
199
+ h({
200
+ payload: d instanceof Error ? d.message : String(d),
201
+ isError: !0
202
+ });
203
+ }
204
+ };
205
+ return window.removeEventListener("message", r), window.addEventListener("message", r), { destroy: () => {
206
+ window.removeEventListener("message", r);
207
+ } };
208
+ }, j = { init: P }, E = "__ranuts_port_init__", _ = (e) => {
209
+ const t = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), a = (s) => {
210
+ const n = s.data;
211
+ if (!n || typeof n != "object" || typeof n.type != "string") return;
212
+ const { type: o, payload: c, id: i, isResponse: g, isError: l } = n;
213
+ if (g && i) {
214
+ const d = r.get(i);
215
+ d && (l ? d.reject(new Error(typeof c == "string" ? c : "Bridge request failed")) : d.resolve(c), r.delete(i));
216
+ return;
217
+ }
218
+ if (!t.has(o)) return;
219
+ const h = t.get(o);
220
+ w(h) && Promise.resolve(h(c)).then((d) => {
221
+ i && e.postMessage({
222
+ type: o,
223
+ payload: d,
224
+ id: i,
225
+ isResponse: !0
226
+ });
227
+ }).catch((d) => {
228
+ i && e.postMessage({
229
+ type: o,
230
+ payload: d instanceof Error ? d.message : String(d),
231
+ id: i,
232
+ isResponse: !0,
233
+ isError: !0
234
+ });
235
+ });
236
+ };
237
+ return e.addEventListener("message", a), e.start(), {
238
+ on: (s, n) => {
239
+ t.set(s, n);
240
+ },
241
+ off: (s) => {
242
+ t.delete(s);
243
+ },
244
+ send: (s, n) => {
245
+ const o = p(10);
246
+ return new Promise((c, i) => {
247
+ const g = setTimeout(() => {
248
+ r.has(o) && (r.delete(o), i(/* @__PURE__ */ new Error("Request timeout")));
249
+ }, b), l = (d) => {
250
+ clearTimeout(g), c(d);
251
+ }, h = (d) => {
252
+ clearTimeout(g), i(d);
253
+ };
254
+ r.set(o, {
255
+ resolve: l,
256
+ reject: h
257
+ });
258
+ try {
259
+ e.postMessage({
260
+ type: s,
261
+ payload: n,
262
+ id: o
263
+ });
264
+ } catch (d) {
265
+ r.delete(o), h(d instanceof Error ? d : /* @__PURE__ */ new Error("Failed to post message"));
266
+ }
267
+ });
268
+ },
269
+ broadcast: (s) => {
270
+ try {
271
+ e.postMessage({
272
+ type: s.type,
273
+ payload: s.payload
274
+ });
275
+ } catch {
276
+ }
277
+ },
278
+ destroy: () => {
279
+ e.removeEventListener("message", a), t.clear(), r.forEach((s) => s.reject(/* @__PURE__ */ new Error("Bridge destroyed"))), r.clear(), e.close();
280
+ }
281
+ };
282
+ }, I = ({ targetWindow: e, targetOrigin: t = "*", name: r = "default" }) => {
283
+ const a = new MessageChannel();
284
+ return e.postMessage({
285
+ [E]: !0,
286
+ name: r
287
+ }, t, [a.port2]), _(a.port1);
288
+ }, L = ({ targetOrigin: e = "*", name: t = "default" } = {}) => typeof window > "u" ? Promise.reject(/* @__PURE__ */ new Error("acceptPortBridge is unavailable outside a browser environment")) : new Promise((r) => {
289
+ const a = (s) => {
290
+ if (e !== "*" && s.origin !== e) return;
291
+ const n = s.data;
292
+ if (!n || typeof n != "object" || n[E] !== !0 || n.name !== t) return;
293
+ const o = s.ports?.[0];
294
+ o && (window.removeEventListener("message", a), r(_(o)));
295
+ };
296
+ window.addEventListener("message", a);
297
+ });
298
+ export {
299
+ m as BRIDGE_MARKER,
300
+ B as BridgeManager,
301
+ T as Client,
302
+ v as DEFAULT_CHANNEL,
303
+ j as Platform,
304
+ M as PostMessageBridge,
305
+ L as acceptPortBridge,
306
+ u as bridgeManager,
307
+ _ as createPortBridge,
308
+ P as initPlatform,
309
+ I as openPortBridge
310
+ };