@zk-tech/bedrock 0.0.1

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 (390) hide show
  1. package/README.md +24 -0
  2. package/dist/array/index.cjs +22 -0
  3. package/dist/array/index.cjs.map +1 -0
  4. package/dist/array/index.d.cts +13 -0
  5. package/dist/array/index.d.ts +13 -0
  6. package/dist/array/index.js +19 -0
  7. package/dist/array/index.js.map +1 -0
  8. package/dist/assert/index.cjs +29 -0
  9. package/dist/assert/index.cjs.map +1 -0
  10. package/dist/assert/index.d.cts +25 -0
  11. package/dist/assert/index.d.ts +25 -0
  12. package/dist/assert/index.js +24 -0
  13. package/dist/assert/index.js.map +1 -0
  14. package/dist/async/index.cjs +746 -0
  15. package/dist/async/index.cjs.map +1 -0
  16. package/dist/async/index.d.cts +47 -0
  17. package/dist/async/index.d.ts +47 -0
  18. package/dist/async/index.js +738 -0
  19. package/dist/async/index.js.map +1 -0
  20. package/dist/barrier-316Xonfd.d.cts +18 -0
  21. package/dist/barrier-316Xonfd.d.ts +18 -0
  22. package/dist/byte/index.cjs +59 -0
  23. package/dist/byte/index.cjs.map +1 -0
  24. package/dist/byte/index.d.cts +12 -0
  25. package/dist/byte/index.d.ts +12 -0
  26. package/dist/byte/index.js +49 -0
  27. package/dist/byte/index.js.map +1 -0
  28. package/dist/cache/index.cjs +418 -0
  29. package/dist/cache/index.cjs.map +1 -0
  30. package/dist/cache/index.d.cts +40 -0
  31. package/dist/cache/index.d.ts +40 -0
  32. package/dist/cache/index.js +415 -0
  33. package/dist/cache/index.js.map +1 -0
  34. package/dist/cancellation-BIIv2UJm.d.cts +25 -0
  35. package/dist/cancellation-ClqPPsV1.d.ts +25 -0
  36. package/dist/context/index.cjs +59 -0
  37. package/dist/context/index.cjs.map +1 -0
  38. package/dist/context/index.d.cts +33 -0
  39. package/dist/context/index.d.ts +33 -0
  40. package/dist/context/index.js +51 -0
  41. package/dist/context/index.js.map +1 -0
  42. package/dist/di/index.cjs +1965 -0
  43. package/dist/di/index.cjs.map +1 -0
  44. package/dist/di/index.d.cts +140 -0
  45. package/dist/di/index.d.ts +140 -0
  46. package/dist/di/index.js +1949 -0
  47. package/dist/di/index.js.map +1 -0
  48. package/dist/disposable-t-B15Nu57y.d.ts +93 -0
  49. package/dist/disposable-t-CVsiyHPL.d.cts +93 -0
  50. package/dist/dispose/index.cjs +356 -0
  51. package/dist/dispose/index.cjs.map +1 -0
  52. package/dist/dispose/index.d.cts +26 -0
  53. package/dist/dispose/index.d.ts +26 -0
  54. package/dist/dispose/index.js +340 -0
  55. package/dist/dispose/index.js.map +1 -0
  56. package/dist/dispose-base-CAeXDpjg.d.cts +6 -0
  57. package/dist/dispose-base-CAeXDpjg.d.ts +6 -0
  58. package/dist/emitter-CAfCtSTg.d.cts +35 -0
  59. package/dist/emitter-DeM5mlEm.d.ts +35 -0
  60. package/dist/error/index.cjs +145 -0
  61. package/dist/error/index.cjs.map +1 -0
  62. package/dist/error/index.d.cts +45 -0
  63. package/dist/error/index.d.ts +45 -0
  64. package/dist/error/index.js +126 -0
  65. package/dist/error/index.js.map +1 -0
  66. package/dist/error-base-B4zaiJ5m.d.cts +32 -0
  67. package/dist/error-base-B4zaiJ5m.d.ts +32 -0
  68. package/dist/event/index.cjs +550 -0
  69. package/dist/event/index.cjs.map +1 -0
  70. package/dist/event/index.d.cts +139 -0
  71. package/dist/event/index.d.ts +139 -0
  72. package/dist/event/index.js +538 -0
  73. package/dist/event/index.js.map +1 -0
  74. package/dist/function/index.cjs +132 -0
  75. package/dist/function/index.cjs.map +1 -0
  76. package/dist/function/index.d.cts +26 -0
  77. package/dist/function/index.d.ts +26 -0
  78. package/dist/function/index.js +129 -0
  79. package/dist/function/index.js.map +1 -0
  80. package/dist/graph-BGbNOniY.d.cts +23 -0
  81. package/dist/graph-BGbNOniY.d.ts +23 -0
  82. package/dist/hash/index.cjs +54 -0
  83. package/dist/hash/index.cjs.map +1 -0
  84. package/dist/hash/index.d.cts +5 -0
  85. package/dist/hash/index.d.ts +5 -0
  86. package/dist/hash/index.js +50 -0
  87. package/dist/hash/index.js.map +1 -0
  88. package/dist/instantiation-service.interface-CVFMBUUD.d.cts +78 -0
  89. package/dist/instantiation-service.interface-CVFMBUUD.d.ts +78 -0
  90. package/dist/json/index.cjs +28 -0
  91. package/dist/json/index.cjs.map +1 -0
  92. package/dist/json/index.d.cts +8 -0
  93. package/dist/json/index.d.ts +8 -0
  94. package/dist/json/index.js +26 -0
  95. package/dist/json/index.js.map +1 -0
  96. package/dist/launch/index.cjs +213 -0
  97. package/dist/launch/index.cjs.map +1 -0
  98. package/dist/launch/index.d.cts +46 -0
  99. package/dist/launch/index.d.ts +46 -0
  100. package/dist/launch/index.js +211 -0
  101. package/dist/launch/index.js.map +1 -0
  102. package/dist/linked-list-CUkue5DZ.d.cts +24 -0
  103. package/dist/linked-list-CUkue5DZ.d.ts +24 -0
  104. package/dist/lock/index.cjs +662 -0
  105. package/dist/lock/index.cjs.map +1 -0
  106. package/dist/lock/index.d.cts +145 -0
  107. package/dist/lock/index.d.ts +145 -0
  108. package/dist/lock/index.js +656 -0
  109. package/dist/lock/index.js.map +1 -0
  110. package/dist/lodash-es/index.cjs +14 -0
  111. package/dist/lodash-es/index.cjs.map +1 -0
  112. package/dist/lodash-es/index.d.cts +1 -0
  113. package/dist/lodash-es/index.d.ts +1 -0
  114. package/dist/lodash-es/index.js +3 -0
  115. package/dist/lodash-es/index.js.map +1 -0
  116. package/dist/math/index.cjs +161 -0
  117. package/dist/math/index.cjs.map +1 -0
  118. package/dist/math/index.d.cts +76 -0
  119. package/dist/math/index.d.ts +76 -0
  120. package/dist/math/index.js +156 -0
  121. package/dist/math/index.js.map +1 -0
  122. package/dist/network/index.cjs +91 -0
  123. package/dist/network/index.cjs.map +1 -0
  124. package/dist/network/index.d.cts +62 -0
  125. package/dist/network/index.d.ts +62 -0
  126. package/dist/network/index.js +82 -0
  127. package/dist/network/index.js.map +1 -0
  128. package/dist/objects/index.cjs +80 -0
  129. package/dist/objects/index.cjs.map +1 -0
  130. package/dist/objects/index.d.cts +11 -0
  131. package/dist/objects/index.d.ts +11 -0
  132. package/dist/objects/index.js +77 -0
  133. package/dist/objects/index.js.map +1 -0
  134. package/dist/platform/index.cjs +62 -0
  135. package/dist/platform/index.cjs.map +1 -0
  136. package/dist/platform/index.d.cts +21 -0
  137. package/dist/platform/index.d.ts +21 -0
  138. package/dist/platform/index.js +48 -0
  139. package/dist/platform/index.js.map +1 -0
  140. package/dist/promise/index.cjs +639 -0
  141. package/dist/promise/index.cjs.map +1 -0
  142. package/dist/promise/index.d.cts +63 -0
  143. package/dist/promise/index.d.ts +63 -0
  144. package/dist/promise/index.js +633 -0
  145. package/dist/promise/index.js.map +1 -0
  146. package/dist/scheduler/index.cjs +599 -0
  147. package/dist/scheduler/index.cjs.map +1 -0
  148. package/dist/scheduler/index.d.cts +57 -0
  149. package/dist/scheduler/index.d.ts +57 -0
  150. package/dist/scheduler/index.js +594 -0
  151. package/dist/scheduler/index.js.map +1 -0
  152. package/dist/sprintf/index.cjs +101 -0
  153. package/dist/sprintf/index.cjs.map +1 -0
  154. package/dist/sprintf/index.d.cts +3 -0
  155. package/dist/sprintf/index.d.ts +3 -0
  156. package/dist/sprintf/index.js +99 -0
  157. package/dist/sprintf/index.js.map +1 -0
  158. package/dist/structure/index.cjs +300 -0
  159. package/dist/structure/index.cjs.map +1 -0
  160. package/dist/structure/index.d.cts +21 -0
  161. package/dist/structure/index.d.ts +21 -0
  162. package/dist/structure/index.js +296 -0
  163. package/dist/structure/index.js.map +1 -0
  164. package/dist/type/index.cjs +4 -0
  165. package/dist/type/index.cjs.map +1 -0
  166. package/dist/type/index.d.cts +20 -0
  167. package/dist/type/index.d.ts +20 -0
  168. package/dist/type/index.js +3 -0
  169. package/dist/type/index.js.map +1 -0
  170. package/dist/undo-redo-stack/index.cjs +545 -0
  171. package/dist/undo-redo-stack/index.cjs.map +1 -0
  172. package/dist/undo-redo-stack/index.d.cts +130 -0
  173. package/dist/undo-redo-stack/index.d.ts +130 -0
  174. package/dist/undo-redo-stack/index.js +542 -0
  175. package/dist/undo-redo-stack/index.js.map +1 -0
  176. package/dist/uuid/index.cjs +67 -0
  177. package/dist/uuid/index.cjs.map +1 -0
  178. package/dist/uuid/index.d.cts +17 -0
  179. package/dist/uuid/index.d.ts +17 -0
  180. package/dist/uuid/index.js +61 -0
  181. package/dist/uuid/index.js.map +1 -0
  182. package/dist/worker/index.cjs +271 -0
  183. package/dist/worker/index.cjs.map +1 -0
  184. package/dist/worker/index.d.cts +66 -0
  185. package/dist/worker/index.d.ts +66 -0
  186. package/dist/worker/index.js +267 -0
  187. package/dist/worker/index.js.map +1 -0
  188. package/package.json +285 -0
  189. package/src/_internal/logger.ts +59 -0
  190. package/src/array/array.test.ts +35 -0
  191. package/src/array/array.ts +25 -0
  192. package/src/array/index.ts +1 -0
  193. package/src/assert/assert.test.ts +86 -0
  194. package/src/assert/assert.ts +42 -0
  195. package/src/assert/index.ts +2 -0
  196. package/src/async/barrier.test.ts +90 -0
  197. package/src/async/barrier.ts +58 -0
  198. package/src/async/cancellation.test.ts +85 -0
  199. package/src/async/cancellation.ts +193 -0
  200. package/src/async/index.ts +18 -0
  201. package/src/async/queue/queue.test.ts +70 -0
  202. package/src/async/queue/queue.ts +56 -0
  203. package/src/async/queue/task.test.ts +155 -0
  204. package/src/async/queue/task.ts +67 -0
  205. package/src/async/utils.test.ts +28 -0
  206. package/src/async/utils.ts +8 -0
  207. package/src/async/wait.ts +9 -0
  208. package/src/byte/format.test.ts +64 -0
  209. package/src/byte/format.ts +44 -0
  210. package/src/byte/index.ts +2 -0
  211. package/src/byte/node_modules/.vitest/results.json +1 -0
  212. package/src/byte/var.ts +11 -0
  213. package/src/cache/index.ts +2 -0
  214. package/src/cache/lru-with-timeout.test.ts +88 -0
  215. package/src/cache/lru-with-timeout.ts +85 -0
  216. package/src/cache/lru.test.ts +56 -0
  217. package/src/cache/lru.ts +59 -0
  218. package/src/context/context.test.ts +17 -0
  219. package/src/context/context.ts +60 -0
  220. package/src/context/index.ts +8 -0
  221. package/src/di/base.ts +73 -0
  222. package/src/di/container-service.test.ts +179 -0
  223. package/src/di/context.web.tsx +41 -0
  224. package/src/di/descriptor.ts +31 -0
  225. package/src/di/idle-value.test.ts +73 -0
  226. package/src/di/idle-value.ts +63 -0
  227. package/src/di/index.common.ts +32 -0
  228. package/src/di/index.ts +2 -0
  229. package/src/di/instantiation-service.interface.ts +46 -0
  230. package/src/di/instantiation-service.test.ts +337 -0
  231. package/src/di/instantiation-service.ts +468 -0
  232. package/src/di/lazy/foo.mock.ts +28 -0
  233. package/src/di/lazy/idle-load.ts +39 -0
  234. package/src/di/lazy/index.ts +4 -0
  235. package/src/di/lazy/lazy-service.test.ts +65 -0
  236. package/src/di/lazy/lazy-service.ts +71 -0
  237. package/src/di/lazy/type.ts +5 -0
  238. package/src/di/node_modules/.vitest/results.json +1 -0
  239. package/src/di/proxy-builder.test.ts +45 -0
  240. package/src/di/proxy-builder.ts +38 -0
  241. package/src/di/service-collection.test.ts +27 -0
  242. package/src/di/service-collection.ts +46 -0
  243. package/src/di/service-ownership-collection.test.ts +39 -0
  244. package/src/di/service-ownership-collection.ts +38 -0
  245. package/src/di/service-registry.test.ts +66 -0
  246. package/src/di/service-registry.ts +99 -0
  247. package/src/di/trace.ts +85 -0
  248. package/src/dispose/disposable-store.test.ts +57 -0
  249. package/src/dispose/disposable-store.ts +80 -0
  250. package/src/dispose/disposable-t.test.ts +123 -0
  251. package/src/dispose/disposable-t.ts +238 -0
  252. package/src/dispose/disposable-utils.test.ts +15 -0
  253. package/src/dispose/disposable-utils.ts +28 -0
  254. package/src/dispose/dispose-base.ts +9 -0
  255. package/src/dispose/index.ts +34 -0
  256. package/src/dispose/logger.test.ts +65 -0
  257. package/src/dispose/logger.ts +39 -0
  258. package/src/dispose/timer.test.ts +30 -0
  259. package/src/dispose/timer.ts +16 -0
  260. package/src/dispose/tracker.test.ts +51 -0
  261. package/src/dispose/tracker.ts +105 -0
  262. package/src/error/error-base.ts +45 -0
  263. package/src/error/error-code.ts +39 -0
  264. package/src/error/error-const.test.ts +30 -0
  265. package/src/error/error-const.ts +16 -0
  266. package/src/error/error-or.test.ts +44 -0
  267. package/src/error/error-or.ts +2 -0
  268. package/src/error/error-t.test.ts +116 -0
  269. package/src/error/error-t.ts +100 -0
  270. package/src/error/index.ts +24 -0
  271. package/src/error/node_modules/.vitest/results.json +1 -0
  272. package/src/event/disposable-linked-list.ts +29 -0
  273. package/src/event/emitter.test.ts +191 -0
  274. package/src/event/emitter.ts +162 -0
  275. package/src/event/error-handler.ts +22 -0
  276. package/src/event/index.ts +34 -0
  277. package/src/event/once.ts +29 -0
  278. package/src/event/phase-emitter.test.ts +212 -0
  279. package/src/event/phase-emitter.ts +209 -0
  280. package/src/event/shortcut-event-utils.ts +33 -0
  281. package/src/event/utils.ts +6 -0
  282. package/src/event/when.ts +40 -0
  283. package/src/function/debounce.test.ts +274 -0
  284. package/src/function/debounce.ts +168 -0
  285. package/src/function/index.ts +2 -0
  286. package/src/function/node_modules/.vitest/results.json +1 -0
  287. package/src/function/throttle.test.ts +179 -0
  288. package/src/function/throttle.ts +26 -0
  289. package/src/hash/hash-t.test.ts +100 -0
  290. package/src/hash/hash-t.ts +51 -0
  291. package/src/hash/index.ts +3 -0
  292. package/src/json/index.ts +1 -0
  293. package/src/json/node_modules/.vitest/results.json +1 -0
  294. package/src/json/parse.ts +19 -0
  295. package/src/launch/abstract-job.ts +45 -0
  296. package/src/launch/cost-recorder.ts +22 -0
  297. package/src/launch/index.ts +2 -0
  298. package/src/launch/job-scheduler.test.ts +122 -0
  299. package/src/launch/job-scheduler.ts +118 -0
  300. package/src/launch/node_modules/.vitest/deps/_metadata.json +8 -0
  301. package/src/launch/node_modules/.vitest/deps/package.json +3 -0
  302. package/src/launch/node_modules/.vitest/results.json +1 -0
  303. package/src/lock/README.md +11 -0
  304. package/src/lock/capability.test.ts +110 -0
  305. package/src/lock/capability.ts +89 -0
  306. package/src/lock/index.ts +15 -0
  307. package/src/lock/node_modules/.vitest/results.json +1 -0
  308. package/src/lock/semaphore.ts +21 -0
  309. package/src/lock/shared-mutex.test.ts +537 -0
  310. package/src/lock/shared-mutex.ts +242 -0
  311. package/src/lock/utils.test.ts +165 -0
  312. package/src/lock/utils.ts +135 -0
  313. package/src/lodash-es/index.ts +1 -0
  314. package/src/math/degree.ts +16 -0
  315. package/src/math/index.ts +7 -0
  316. package/src/math/math.test.ts +40 -0
  317. package/src/math/math.ts +64 -0
  318. package/src/math/node_modules/.vitest/results.json +1 -0
  319. package/src/math/vector.test.ts +73 -0
  320. package/src/math/vector.ts +114 -0
  321. package/src/network/client.interface.ts +104 -0
  322. package/src/network/client.web.ts +24 -0
  323. package/src/network/index.common.ts +10 -0
  324. package/src/network/index.ts +2 -0
  325. package/src/network/plugins/retry.ts +98 -0
  326. package/src/objects/deep-clone.test.ts +40 -0
  327. package/src/objects/deep-clone.ts +13 -0
  328. package/src/objects/deep-equal.test.ts +86 -0
  329. package/src/objects/deep-equal.ts +60 -0
  330. package/src/objects/index.ts +4 -0
  331. package/src/platform/index.ts +64 -0
  332. package/src/promise/index.ts +16 -0
  333. package/src/promise/promise.test.ts +254 -0
  334. package/src/promise/promise.ts +212 -0
  335. package/src/scheduler/callback-token.ts +31 -0
  336. package/src/scheduler/core/actuator-args.test.ts +47 -0
  337. package/src/scheduler/core/actuator.test.ts +82 -0
  338. package/src/scheduler/core/actuator.ts +58 -0
  339. package/src/scheduler/core/chunk-scheduler.test.ts +54 -0
  340. package/src/scheduler/core/chunk-scheduler.ts +28 -0
  341. package/src/scheduler/core/node_modules/.vitest/results.json +1 -0
  342. package/src/scheduler/core/scheduler.test.ts +328 -0
  343. package/src/scheduler/core/scheduler.ts +172 -0
  344. package/src/scheduler/core/task-queue.test.ts +78 -0
  345. package/src/scheduler/core/task-queue.ts +44 -0
  346. package/src/scheduler/core/task.test.ts +34 -0
  347. package/src/scheduler/core/task.ts +52 -0
  348. package/src/scheduler/core/utils.ts +48 -0
  349. package/src/scheduler/executor/abstract-executor.test.ts +44 -0
  350. package/src/scheduler/executor/abstract-executor.ts +38 -0
  351. package/src/scheduler/executor/executor.interface.ts +39 -0
  352. package/src/scheduler/executor/idle-callback-executor.test.ts +70 -0
  353. package/src/scheduler/executor/idle-callback-executor.ts +98 -0
  354. package/src/scheduler/executor/make-executor.ts +18 -0
  355. package/src/scheduler/executor/post-message-executor.test.ts +66 -0
  356. package/src/scheduler/executor/post-message-executor.ts +52 -0
  357. package/src/scheduler/index.ts +15 -0
  358. package/src/scheduler/lv-scheduler-callback.ts +19 -0
  359. package/src/scheduler/lv-scheduler-config.ts +17 -0
  360. package/src/scheduler/type.ts +48 -0
  361. package/src/sprintf/index.ts +2 -0
  362. package/src/sprintf/sprintf.test.ts +95 -0
  363. package/src/sprintf/sprintf.ts +97 -0
  364. package/src/structure/graph.test.ts +181 -0
  365. package/src/structure/graph.ts +105 -0
  366. package/src/structure/index.ts +8 -0
  367. package/src/structure/linked-list.test.ts +74 -0
  368. package/src/structure/linked-list.ts +145 -0
  369. package/src/structure/min-heap.test.ts +71 -0
  370. package/src/structure/min-heap.ts +91 -0
  371. package/src/type/REAME.md +2 -0
  372. package/src/type/distributive-omit.interface.ts +4 -0
  373. package/src/type/index.ts +3 -0
  374. package/src/type/object-key-paths.interface.ts +40 -0
  375. package/src/undo-redo-stack/README.md +61 -0
  376. package/src/undo-redo-stack/action-stack.test.ts +330 -0
  377. package/src/undo-redo-stack/action-stack.ts +150 -0
  378. package/src/undo-redo-stack/element.ts +4 -0
  379. package/src/undo-redo-stack/index.ts +7 -0
  380. package/src/undo-redo-stack/state-stack.test.ts +118 -0
  381. package/src/undo-redo-stack/state-stack.ts +133 -0
  382. package/src/uuid/index.ts +7 -0
  383. package/src/uuid/uuid.ts +86 -0
  384. package/src/worker/cors-worker.ts +38 -0
  385. package/src/worker/index.ts +4 -0
  386. package/src/worker/node_modules/.vitest/results.json +1 -0
  387. package/src/worker/promise-worker-main-thread.test.ts +91 -0
  388. package/src/worker/promise-worker-main-thread.ts +76 -0
  389. package/src/worker/promise-worker-worker-thread.ts +64 -0
  390. package/src/worker/promise-worker.interface.ts +15 -0
@@ -0,0 +1,21 @@
1
+ declare const isWindows: boolean;
2
+ declare const isMac: boolean;
3
+ declare const isLinux: boolean;
4
+ declare const isWeb: boolean;
5
+ declare const isIOS: boolean;
6
+ declare const isAndroid: boolean;
7
+ declare const isIPad: boolean;
8
+ declare const isMobile: boolean;
9
+ declare const isChrome: boolean;
10
+ declare const isFirefox: boolean;
11
+ declare const isSafari: boolean;
12
+ /**
13
+ * 判断是否为 Arc 浏览器
14
+ * arc 浏览器判定方式比较奇特,无法通过 UA 判断
15
+ * https://stackoverflow.com/questions/76123232/can-javascript-detect-the-arc-browser
16
+ */
17
+ declare function isArcBrowser(): boolean;
18
+ /** ace2.0 不再提供这个方法 用于判断是否为浏览器环境*/
19
+ declare function isBrowser(): boolean;
20
+
21
+ export { isAndroid, isArcBrowser, isBrowser, isChrome, isFirefox, isIOS, isIPad, isLinux, isMac, isMobile, isSafari, isWeb, isWindows };
@@ -0,0 +1,48 @@
1
+ // src/platform/index.ts
2
+ var _isWindows = false;
3
+ var _isMac = false;
4
+ var _isLinux = false;
5
+ var _isWeb = false;
6
+ var _isIOS = false;
7
+ var _isAndroid = false;
8
+ var _isMobile = false;
9
+ var _isIPad = false;
10
+ var _isFirefox = false;
11
+ var _isChrome = false;
12
+ var _isSafari = false;
13
+ var _userAgent;
14
+ if (typeof navigator === "object") {
15
+ _userAgent = navigator.userAgent;
16
+ _isWindows = _userAgent.indexOf("Windows") >= 0;
17
+ _isIOS = (_userAgent.indexOf("Macintosh") >= 0 || _userAgent.indexOf("iPad") >= 0 || _userAgent.indexOf("iPhone") >= 0) && Boolean(navigator.maxTouchPoints) && navigator.maxTouchPoints > 0;
18
+ _isAndroid = _userAgent.indexOf("Android") >= 0;
19
+ _isLinux = _userAgent.indexOf("Linux") >= 0;
20
+ _isMobile = _userAgent.indexOf("Mobi") >= 0;
21
+ _isIPad = _userAgent.indexOf("iPad") >= 0;
22
+ _isMac = !_isMobile && _userAgent.indexOf("Macintosh") >= 0;
23
+ _isFirefox = /firefox/i.test(_userAgent);
24
+ _isChrome = /chrome/i.test(_userAgent);
25
+ _isSafari = /^((?!chrome|android).)*safari/i.test(_userAgent);
26
+ _isWeb = true;
27
+ }
28
+ var isWindows = _isWindows;
29
+ var isMac = _isMac;
30
+ var isLinux = _isLinux;
31
+ var isWeb = _isWeb;
32
+ var isIOS = _isIOS;
33
+ var isAndroid = _isAndroid;
34
+ var isIPad = _isIPad;
35
+ var isMobile = _isMobile;
36
+ var isChrome = _isChrome;
37
+ var isFirefox = _isFirefox;
38
+ var isSafari = _isSafari;
39
+ function isArcBrowser() {
40
+ return getComputedStyle(document.documentElement).getPropertyValue("--arc-palette-title") ? true : false;
41
+ }
42
+ function isBrowser() {
43
+ return typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
44
+ }
45
+
46
+ export { isAndroid, isArcBrowser, isBrowser, isChrome, isFirefox, isIOS, isIPad, isLinux, isMac, isMobile, isSafari, isWeb, isWindows };
47
+ //# sourceMappingURL=index.js.map
48
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/platform/index.ts"],"names":[],"mappings":";AACA,IAAI,UAAA,GAAa,KAAA;AACjB,IAAI,MAAA,GAAS,KAAA;AACb,IAAI,QAAA,GAAW,KAAA;AACf,IAAI,MAAA,GAAS,KAAA;AACb,IAAI,MAAA,GAAS,KAAA;AACb,IAAI,UAAA,GAAa,KAAA;AACjB,IAAI,SAAA,GAAY,KAAA;AAChB,IAAI,OAAA,GAAU,KAAA;AACd,IAAI,UAAA,GAAa,KAAA;AACjB,IAAI,SAAA,GAAY,KAAA;AAChB,IAAI,SAAA,GAAY,KAAA;AAChB,IAAI,UAAA;AAGJ,IAAI,OAAO,cAAc,QAAA,EAAU;AACjC,EAAA,UAAA,GAAa,SAAA,CAAU,SAAA;AACvB,EAAA,UAAA,GAAa,UAAA,CAAW,OAAA,CAAQ,SAAS,CAAA,IAAK,CAAA;AAC9C,EAAA,MAAA,GAAA,CACG,UAAA,CAAW,QAAQ,WAAW,CAAA,IAAK,KAClC,UAAA,CAAW,OAAA,CAAQ,MAAM,CAAA,IAAK,CAAA,IAC9B,WAAW,OAAA,CAAQ,QAAQ,KAAK,CAAA,KAClC,OAAA,CAAQ,UAAU,cAAc,CAAA,IAChC,UAAU,cAAA,GAAiB,CAAA;AAC7B,EAAA,UAAA,GAAa,UAAA,CAAW,OAAA,CAAQ,SAAS,CAAA,IAAK,CAAA;AAC9C,EAAA,QAAA,GAAW,UAAA,CAAW,OAAA,CAAQ,OAAO,CAAA,IAAK,CAAA;AAC1C,EAAA,SAAA,GAAY,UAAA,CAAW,OAAA,CAAQ,MAAM,CAAA,IAAK,CAAA;AAC1C,EAAA,OAAA,GAAU,UAAA,CAAW,OAAA,CAAQ,MAAM,CAAA,IAAK,CAAA;AACxC,EAAA,MAAA,GAAS,CAAC,SAAA,IAAa,UAAA,CAAW,OAAA,CAAQ,WAAW,CAAA,IAAK,CAAA;AAC1D,EAAA,UAAA,GAAa,UAAA,CAAW,KAAK,UAAU,CAAA;AACvC,EAAA,SAAA,GAAY,SAAA,CAAU,KAAK,UAAU,CAAA;AACrC,EAAA,SAAA,GAAY,gCAAA,CAAiC,KAAK,UAAU,CAAA;AAC5D,EAAA,MAAA,GAAS,IAAA;AACX;AAEO,IAAM,SAAA,GAAY;AAClB,IAAM,KAAA,GAAQ;AACd,IAAM,OAAA,GAAU;AAChB,IAAM,KAAA,GAAQ;AACd,IAAM,KAAA,GAAQ;AACd,IAAM,SAAA,GAAY;AAClB,IAAM,MAAA,GAAS;AACf,IAAM,QAAA,GAAW;AACjB,IAAM,QAAA,GAAW;AACjB,IAAM,SAAA,GAAY;AAClB,IAAM,QAAA,GAAW;AAOjB,SAAS,YAAA,GAAwB;AACtC,EAAA,OAAO,iBAAiB,QAAA,CAAS,eAAe,EAAE,gBAAA,CAAiB,qBAAqB,IAAI,IAAA,GAAO,KAAA;AACrG;AAGO,SAAS,SAAA,GAAqB;AACnC,EAAA,OACE,OAAO,MAAA,KAAW,WAAA,IAClB,OAAO,MAAA,CAAO,aAAa,WAAA,IAC3B,OAAO,MAAA,CAAO,QAAA,CAAS,aAAA,KAAkB,WAAA;AAE7C","file":"index.js","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nlet _isWindows = false;\nlet _isMac = false;\nlet _isLinux = false;\nlet _isWeb = false;\nlet _isIOS = false;\nlet _isAndroid = false;\nlet _isMobile = false;\nlet _isIPad = false;\nlet _isFirefox = false;\nlet _isChrome = false;\nlet _isSafari = false;\nlet _userAgent: string | undefined;\n\n// Web environment\nif (typeof navigator === 'object') {\n _userAgent = navigator.userAgent;\n _isWindows = _userAgent.indexOf('Windows') >= 0;\n _isIOS =\n (_userAgent.indexOf('Macintosh') >= 0 ||\n _userAgent.indexOf('iPad') >= 0 ||\n _userAgent.indexOf('iPhone') >= 0) &&\n Boolean(navigator.maxTouchPoints) &&\n navigator.maxTouchPoints > 0;\n _isAndroid = _userAgent.indexOf('Android') >= 0;\n _isLinux = _userAgent.indexOf('Linux') >= 0;\n _isMobile = _userAgent.indexOf('Mobi') >= 0;\n _isIPad = _userAgent.indexOf('iPad') >= 0;\n _isMac = !_isMobile && _userAgent.indexOf('Macintosh') >= 0;\n _isFirefox = /firefox/i.test(_userAgent);\n _isChrome = /chrome/i.test(_userAgent);\n _isSafari = /^((?!chrome|android).)*safari/i.test(_userAgent);\n _isWeb = true;\n}\n\nexport const isWindows = _isWindows;\nexport const isMac = _isMac;\nexport const isLinux = _isLinux;\nexport const isWeb = _isWeb;\nexport const isIOS = _isIOS;\nexport const isAndroid = _isAndroid;\nexport const isIPad = _isIPad;\nexport const isMobile = _isMobile;\nexport const isChrome = _isChrome;\nexport const isFirefox = _isFirefox;\nexport const isSafari = _isSafari;\n\n/**\n * 判断是否为 Arc 浏览器\n * arc 浏览器判定方式比较奇特,无法通过 UA 判断\n * https://stackoverflow.com/questions/76123232/can-javascript-detect-the-arc-browser\n */\nexport function isArcBrowser(): boolean {\n return getComputedStyle(document.documentElement).getPropertyValue('--arc-palette-title') ? true : false;\n};\n\n/** ace2.0 不再提供这个方法 用于判断是否为浏览器环境*/\nexport function isBrowser(): boolean {\n return (\n typeof window !== 'undefined' &&\n typeof window.document !== 'undefined' &&\n typeof window.document.createElement !== 'undefined'\n );\n}\n"]}
@@ -0,0 +1,639 @@
1
+ 'use strict';
2
+
3
+ // src/error/error-t.ts
4
+ var lvErrorRefSymbol = /* @__PURE__ */ Symbol("lvErrorRef");
5
+ function findJsError(error) {
6
+ let obj = error;
7
+ while (obj) {
8
+ if (obj instanceof Error) {
9
+ return obj;
10
+ }
11
+ obj = obj.cause;
12
+ }
13
+ return new Error(error.toString());
14
+ }
15
+ function makeOk() {
16
+ return {
17
+ ok: true,
18
+ value: null,
19
+ pair() {
20
+ return [null, null];
21
+ },
22
+ code: 0,
23
+ msg: "",
24
+ ...{ [lvErrorRefSymbol]: true }
25
+ // 跳过类型检测
26
+ };
27
+ }
28
+ function makeOkWith(value) {
29
+ return {
30
+ ok: true,
31
+ value,
32
+ pair() {
33
+ return [null, value];
34
+ },
35
+ code: 0,
36
+ msg: "",
37
+ ...{ [lvErrorRefSymbol]: true }
38
+ // 跳过类型检测
39
+ };
40
+ }
41
+ function printCause(cause) {
42
+ if (cause === void 0) {
43
+ return "";
44
+ } else if (cause instanceof Error) {
45
+ return `
46
+ caused by [jsError]${cause.name}-${cause.message}`;
47
+ } else {
48
+ return `
49
+ caused by [${cause.code}]${cause.msg}${cause.ok ? "" : printCause(cause.cause)}`;
50
+ }
51
+ }
52
+ function internalMakeError(code, msg, cause, errorInfo) {
53
+ const errorRef = {
54
+ ok: false,
55
+ code,
56
+ msg,
57
+ cause,
58
+ errorInfo,
59
+ toString() {
60
+ return `[${code}]${msg}.${cause ? printCause(cause) : ""}`;
61
+ },
62
+ pair() {
63
+ return [errorRef, null];
64
+ },
65
+ stack: cause instanceof Error ? cause.stack : void 0,
66
+ findJsError: () => findJsError(errorRef),
67
+ ...{ [lvErrorRefSymbol]: true }
68
+ // 跳过类型检测
69
+ };
70
+ return errorRef;
71
+ }
72
+ function makeError(code, msg, errorInfo) {
73
+ return internalMakeError(code, msg, void 0, errorInfo);
74
+ }
75
+ function makeErrorBy(code, msg, cause, errorInfo) {
76
+ return internalMakeError(code, msg, cause, errorInfo);
77
+ }
78
+ function isLvErrorRef(val) {
79
+ return typeof val === "object" && val !== null && lvErrorRefSymbol in val;
80
+ }
81
+
82
+ // src/error/error-const.ts
83
+ function lvErrorConst(code, msg) {
84
+ return (rewrite) => {
85
+ if (!rewrite) {
86
+ return makeError(code, msg);
87
+ }
88
+ if (typeof rewrite === "string") {
89
+ return makeError(code, rewrite);
90
+ }
91
+ return makeErrorBy(code, rewrite.message, rewrite);
92
+ };
93
+ }
94
+
95
+ // src/error/error-code.ts
96
+ var cancelledError = lvErrorConst(1 /* Cancelled */, "operation(s) cancelled.");
97
+ var timeoutError = lvErrorConst(2 /* TimedOut */, "operation(s) timed out.");
98
+
99
+ // src/dispose/dispose-base.ts
100
+ var EmptyDispose = Object.freeze({ dispose() {
101
+ } });
102
+
103
+ // src/dispose/disposable-t.ts
104
+ var SafeDisposable = class {
105
+ constructor(value) {
106
+ this._value = value;
107
+ }
108
+ get value() {
109
+ return this._value;
110
+ }
111
+ isEmpty() {
112
+ return this._value === void 0;
113
+ }
114
+ dispose() {
115
+ if (!this._value) {
116
+ return;
117
+ }
118
+ this._value.dispose();
119
+ this._value = void 0;
120
+ }
121
+ };
122
+
123
+ // src/dispose/disposable-utils.ts
124
+ function makeSafeDisposable(fn) {
125
+ const disposable = new SafeDisposable({
126
+ dispose: fn
127
+ });
128
+ return disposable;
129
+ }
130
+
131
+ // src/structure/linked-list.ts
132
+ var ListNode = class {
133
+ constructor(value, next = null, prev = null) {
134
+ this.value = value;
135
+ this.next = next;
136
+ this.prev = prev;
137
+ }
138
+ };
139
+ var LinkedList = class {
140
+ constructor() {
141
+ this._head = null;
142
+ this._tail = null;
143
+ this._count = 0;
144
+ }
145
+ get size() {
146
+ return this._count;
147
+ }
148
+ get firstNode() {
149
+ return this._head;
150
+ }
151
+ isEmpty() {
152
+ return this._head === null;
153
+ }
154
+ clear() {
155
+ let current = this._head;
156
+ while (current !== null) {
157
+ const next = current.next;
158
+ current.prev = null;
159
+ current.next = null;
160
+ current = next;
161
+ }
162
+ this._head = null;
163
+ this._tail = null;
164
+ this._count = 0;
165
+ }
166
+ unshift(value) {
167
+ const node = new ListNode(value);
168
+ if (this.isEmpty()) {
169
+ this._head = node;
170
+ this._tail = node;
171
+ } else {
172
+ const oldHead = this._head;
173
+ this._head = node;
174
+ node.next = oldHead;
175
+ oldHead.prev = node;
176
+ }
177
+ this._count++;
178
+ return this;
179
+ }
180
+ push(value) {
181
+ const node = new ListNode(value);
182
+ if (this.isEmpty()) {
183
+ this._head = node;
184
+ this._tail = node;
185
+ } else {
186
+ const oldTail = this._tail;
187
+ this._tail = node;
188
+ node.prev = oldTail;
189
+ oldTail.next = node;
190
+ }
191
+ this._count++;
192
+ return this;
193
+ }
194
+ shift() {
195
+ if (this.isEmpty()) {
196
+ return null;
197
+ }
198
+ const node = this._head;
199
+ const value = node.value;
200
+ this._remove(node);
201
+ return value;
202
+ }
203
+ pop() {
204
+ if (this.isEmpty()) {
205
+ return null;
206
+ }
207
+ const node = this._tail;
208
+ const value = node.value;
209
+ this._remove(node);
210
+ return value;
211
+ }
212
+ toArray() {
213
+ const result = [];
214
+ for (const value of this) {
215
+ result.push(value);
216
+ }
217
+ return result;
218
+ }
219
+ *[Symbol.iterator]() {
220
+ let current = this._head;
221
+ while (current !== null) {
222
+ yield current.value;
223
+ current = current.next;
224
+ }
225
+ }
226
+ _remove(node) {
227
+ if (node.prev === null && node.next === null && node !== this._head && node !== this._tail) {
228
+ return;
229
+ }
230
+ if (node === this._head) {
231
+ this._head = node.next;
232
+ if (this._head) {
233
+ this._head.prev = null;
234
+ }
235
+ }
236
+ if (node === this._tail) {
237
+ this._tail = node.prev;
238
+ if (this._tail) {
239
+ this._tail.next = null;
240
+ }
241
+ }
242
+ if (node.prev) {
243
+ node.prev.next = node.next;
244
+ }
245
+ if (node.next) {
246
+ node.next.prev = node.prev;
247
+ }
248
+ node.prev = null;
249
+ node.next = null;
250
+ this._count--;
251
+ }
252
+ };
253
+
254
+ // src/event/disposable-linked-list.ts
255
+ var DisposableLinkedList = class extends LinkedList {
256
+ unshiftAndGetDisposableNode(value) {
257
+ this.unshift(value);
258
+ const node = this._head;
259
+ let hasRemoved = false;
260
+ return () => {
261
+ if (!hasRemoved) {
262
+ hasRemoved = true;
263
+ super._remove(node);
264
+ }
265
+ };
266
+ }
267
+ pushAndGetDisposableNode(value) {
268
+ this.push(value);
269
+ const node = this._tail;
270
+ let hasRemoved = false;
271
+ return () => {
272
+ if (!hasRemoved) {
273
+ hasRemoved = true;
274
+ super._remove(node);
275
+ }
276
+ };
277
+ }
278
+ };
279
+
280
+ // src/event/error-handler.ts
281
+ function asyncUnexpectedError(e) {
282
+ setTimeout(() => {
283
+ throw e;
284
+ }, 0);
285
+ }
286
+
287
+ // src/event/emitter.ts
288
+ var Listener = class {
289
+ constructor(callback, callbackThis) {
290
+ this._callback = callback;
291
+ this._callbackThis = callbackThis;
292
+ }
293
+ invoke(...args) {
294
+ this._callback.call(this._callbackThis, ...args);
295
+ }
296
+ };
297
+ var EventDeliveryQueueElement = class {
298
+ constructor(emitter, listener, event) {
299
+ this.emitter = emitter;
300
+ this.listener = listener;
301
+ this.event = event;
302
+ }
303
+ };
304
+ var EventDeliveryQueue = class {
305
+ constructor(_onListenerError = asyncUnexpectedError) {
306
+ this._onListenerError = _onListenerError;
307
+ this._queue = new DisposableLinkedList();
308
+ }
309
+ get size() {
310
+ return this._queue.size;
311
+ }
312
+ push(emitter, listener, event) {
313
+ this._queue.push(new EventDeliveryQueueElement(emitter, listener, event));
314
+ }
315
+ clear(emitter) {
316
+ const newQueue = new DisposableLinkedList();
317
+ for (const element of this._queue) {
318
+ if (element.emitter !== emitter) {
319
+ newQueue.push(element);
320
+ }
321
+ }
322
+ this._queue = newQueue;
323
+ }
324
+ deliver() {
325
+ while (this._queue.size > 0) {
326
+ const element = this._queue.shift();
327
+ try {
328
+ element.listener.invoke(...element.event);
329
+ } catch (e) {
330
+ this._onListenerError(e);
331
+ }
332
+ }
333
+ }
334
+ };
335
+ var Emitter = class {
336
+ constructor(options) {
337
+ this._disposed = false;
338
+ this._options = options;
339
+ }
340
+ get event() {
341
+ if (this._event) {
342
+ return this._event;
343
+ }
344
+ this._event = (callback, thisArgs) => {
345
+ const listener = new Listener(callback, thisArgs);
346
+ if (!this._listeners) {
347
+ this._listeners = new DisposableLinkedList();
348
+ }
349
+ const removeListener = this._listeners.pushAndGetDisposableNode(listener);
350
+ if (this._options?.onAddListener) {
351
+ this._options.onAddListener(this, callback, thisArgs);
352
+ }
353
+ const result = () => {
354
+ if (!this._disposed) {
355
+ removeListener();
356
+ if (this._options?.onRemoveListener) {
357
+ this._options.onRemoveListener(this, callback, thisArgs);
358
+ }
359
+ }
360
+ };
361
+ return makeSafeDisposable(result);
362
+ };
363
+ return this._event;
364
+ }
365
+ dispose() {
366
+ if (this._disposed) {
367
+ return;
368
+ }
369
+ this._disposed = true;
370
+ this._listeners?.clear();
371
+ this._deliveryQueue?.clear(this);
372
+ }
373
+ fire(...event) {
374
+ if (!this._listeners || this._listeners.size === 0) {
375
+ return;
376
+ }
377
+ if (this._listeners.size === 1) {
378
+ const listener = this._listeners.firstNode;
379
+ try {
380
+ listener.value.invoke(...event);
381
+ } catch (e) {
382
+ if (this._options?.onListenerError) {
383
+ this._options.onListenerError(e);
384
+ } else {
385
+ asyncUnexpectedError(e);
386
+ }
387
+ }
388
+ return;
389
+ }
390
+ this._deliveryQueue ?? (this._deliveryQueue = new EventDeliveryQueue(this._options?.onListenerError));
391
+ for (const listener of this._listeners) {
392
+ this._deliveryQueue.push(this, listener, event);
393
+ }
394
+ this._deliveryQueue.deliver();
395
+ }
396
+ };
397
+
398
+ // src/async/cancellation.ts
399
+ var shortcutEvent = Object.freeze(function(callback, context) {
400
+ const handle = setTimeout(callback.bind(context), 0);
401
+ return {
402
+ dispose() {
403
+ clearTimeout(handle);
404
+ }
405
+ };
406
+ });
407
+ var MutableToken = class {
408
+ constructor() {
409
+ // 是否已经取消该异步调用
410
+ this._isCancelled = false;
411
+ this._emitter = null;
412
+ }
413
+ get reason() {
414
+ return this._reason;
415
+ }
416
+ // 获取当前是否已经取消该异步调用
417
+ get isCancellationRequested() {
418
+ return this._isCancelled;
419
+ }
420
+ // 外界可以监听异步取消发起
421
+ get onCancellationRequested() {
422
+ if (this._isCancelled) {
423
+ return shortcutEvent;
424
+ }
425
+ if (!this._emitter) {
426
+ this._emitter = new Emitter();
427
+ }
428
+ return this._emitter.event;
429
+ }
430
+ cancel(reason) {
431
+ if (!this._isCancelled) {
432
+ this._reason = reason;
433
+ this._isCancelled = true;
434
+ if (this._emitter) {
435
+ this._emitter.fire();
436
+ this.dispose();
437
+ }
438
+ }
439
+ }
440
+ dispose() {
441
+ if (this._emitter) {
442
+ this._emitter.dispose();
443
+ this._emitter = null;
444
+ }
445
+ }
446
+ };
447
+ var CancellationToken = class {
448
+ };
449
+ CancellationToken.None = Object.freeze({
450
+ isCancellationRequested: false,
451
+ onCancellationRequested: () => EmptyDispose
452
+ });
453
+ CancellationToken.Cancelled = Object.freeze({
454
+ isCancellationRequested: true,
455
+ onCancellationRequested: shortcutEvent
456
+ });
457
+ CancellationToken.Make = (reason) => {
458
+ return Object.freeze({
459
+ isCancellationRequested: true,
460
+ onCancellationRequested: shortcutEvent,
461
+ reason
462
+ });
463
+ };
464
+ var CancellationTokenSource = class {
465
+ constructor(parent) {
466
+ // 真正的token
467
+ this._token = void 0;
468
+ // 可能存在父级CancellationTokenSource
469
+ this._parentListener = void 0;
470
+ // 为了支持signal场景,所以在需要时会初始化浏览器提供的abortController原生结构
471
+ this._abortController = void 0;
472
+ this._parentListener = parent?.onCancellationRequested(this.cancel, this);
473
+ }
474
+ /**
475
+ * 传统的cancellation用法
476
+ */
477
+ get token() {
478
+ if (!this._token) {
479
+ this._token = new MutableToken();
480
+ }
481
+ return this._token;
482
+ }
483
+ /**
484
+ * 对齐浏览器提供的abortSignal,支持给fetch、axios等传参使用
485
+ */
486
+ get signal() {
487
+ if (this._abortController) {
488
+ return this._abortController.signal;
489
+ }
490
+ this._abortController = new AbortController();
491
+ if (this._token?.isCancellationRequested) {
492
+ this._abortController.abort();
493
+ }
494
+ return this._abortController.signal;
495
+ }
496
+ cancel(reason) {
497
+ if (!this._token) {
498
+ this._token = reason === void 0 ? CancellationToken.Cancelled : CancellationToken.Make(reason);
499
+ } else if (this._token instanceof MutableToken) {
500
+ this._token.cancel(reason);
501
+ }
502
+ if (this._abortController) {
503
+ this._abortController.abort(reason);
504
+ }
505
+ }
506
+ dispose(cancel = false) {
507
+ if (cancel) {
508
+ this.cancel();
509
+ }
510
+ this._parentListener?.dispose();
511
+ if (!this._token) {
512
+ this._token = CancellationToken.None;
513
+ } else if (this._token instanceof MutableToken) {
514
+ this._token.dispose();
515
+ }
516
+ }
517
+ };
518
+
519
+ // src/promise/promise.ts
520
+ function makeCancelablePromise(callback) {
521
+ const source = new CancellationTokenSource();
522
+ const thenable = callback(source.token);
523
+ const promise = new Promise((resolve, reject) => {
524
+ const subscription = source.token.onCancellationRequested(() => {
525
+ subscription.dispose();
526
+ source.dispose();
527
+ resolve(cancelledError());
528
+ });
529
+ Promise.resolve(thenable).then(
530
+ (value) => {
531
+ subscription.dispose();
532
+ source.dispose();
533
+ if (isLvErrorRef(value)) {
534
+ resolve(value);
535
+ } else {
536
+ resolve(makeOkWith(value));
537
+ }
538
+ },
539
+ (err) => {
540
+ subscription.dispose();
541
+ source.dispose();
542
+ reject(err);
543
+ }
544
+ );
545
+ });
546
+ return new class {
547
+ cancel() {
548
+ source.cancel();
549
+ }
550
+ then(resolve, reject) {
551
+ return promise.then(resolve, reject);
552
+ }
553
+ catch(reject) {
554
+ return this.then(void 0, reject);
555
+ }
556
+ finally(onfinally) {
557
+ return promise.finally(onfinally);
558
+ }
559
+ }();
560
+ }
561
+ function parallelPromise(promiseList) {
562
+ if (promiseList.length === 0) {
563
+ return Promise.resolve(makeOk());
564
+ }
565
+ let todo = promiseList.length;
566
+ const finish = () => {
567
+ todo = -1;
568
+ for (const promise of promiseList) {
569
+ promise.cancel?.();
570
+ }
571
+ };
572
+ return new Promise((resolve, reject) => {
573
+ for (const promise of promiseList) {
574
+ promise.then((res) => {
575
+ if (isLvErrorRef(res) && !res.ok) {
576
+ finish();
577
+ resolve(res);
578
+ return;
579
+ }
580
+ todo--;
581
+ if (todo === 0) {
582
+ resolve(makeOk());
583
+ }
584
+ }).catch((err) => {
585
+ finish();
586
+ reject(err);
587
+ });
588
+ }
589
+ });
590
+ }
591
+ function makePromiseWithTimeout(callback, timeout, defaultValue) {
592
+ const cancellable = makeCancelablePromise(callback);
593
+ const timer = setTimeout(() => {
594
+ cancellable.cancel();
595
+ }, timeout);
596
+ return cancellable.then((res) => {
597
+ clearTimeout(timer);
598
+ if (res.ok) {
599
+ return res;
600
+ }
601
+ if (res.code === 1 /* Cancelled */) {
602
+ if (defaultValue !== void 0) {
603
+ return makeOkWith(defaultValue);
604
+ }
605
+ return timeoutError();
606
+ } else {
607
+ return res;
608
+ }
609
+ });
610
+ }
611
+ function defer() {
612
+ let resolve;
613
+ let reject;
614
+ const promise = new Promise((_resolve, _reject) => {
615
+ resolve = _resolve;
616
+ reject = _reject;
617
+ });
618
+ return { resolve, reject, promise };
619
+ }
620
+ function waitForAbortSignal(signal) {
621
+ const { promise, reject } = defer();
622
+ if (signal.aborted) {
623
+ reject(signal.reason);
624
+ }
625
+ const handleAbort = () => {
626
+ reject(signal.reason);
627
+ signal.removeEventListener("abort", handleAbort);
628
+ };
629
+ signal.addEventListener("abort", handleAbort);
630
+ return promise;
631
+ }
632
+
633
+ exports.defer = defer;
634
+ exports.makeCancelablePromise = makeCancelablePromise;
635
+ exports.makePromiseWithTimeout = makePromiseWithTimeout;
636
+ exports.parallelPromise = parallelPromise;
637
+ exports.waitForAbortSignal = waitForAbortSignal;
638
+ //# sourceMappingURL=index.cjs.map
639
+ //# sourceMappingURL=index.cjs.map