@spacecorexdev/core 0.0.2 → 0.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 (345) hide show
  1. package/package.json +20 -38
  2. package/public/cmaps/78-EUC-H.bcmap +0 -0
  3. package/public/cmaps/78-EUC-V.bcmap +0 -0
  4. package/public/cmaps/78-H.bcmap +0 -0
  5. package/public/cmaps/78-RKSJ-H.bcmap +0 -0
  6. package/public/cmaps/78-RKSJ-V.bcmap +0 -0
  7. package/public/cmaps/78-V.bcmap +0 -0
  8. package/public/cmaps/78ms-RKSJ-H.bcmap +0 -0
  9. package/public/cmaps/78ms-RKSJ-V.bcmap +0 -0
  10. package/public/cmaps/83pv-RKSJ-H.bcmap +0 -0
  11. package/public/cmaps/90ms-RKSJ-H.bcmap +0 -0
  12. package/public/cmaps/90ms-RKSJ-V.bcmap +0 -0
  13. package/public/cmaps/90msp-RKSJ-H.bcmap +0 -0
  14. package/public/cmaps/90msp-RKSJ-V.bcmap +0 -0
  15. package/public/cmaps/90pv-RKSJ-H.bcmap +0 -0
  16. package/public/cmaps/90pv-RKSJ-V.bcmap +0 -0
  17. package/public/cmaps/Add-H.bcmap +0 -0
  18. package/public/cmaps/Add-RKSJ-H.bcmap +0 -0
  19. package/public/cmaps/Add-RKSJ-V.bcmap +0 -0
  20. package/public/cmaps/Add-V.bcmap +0 -0
  21. package/public/cmaps/Adobe-CNS1-0.bcmap +0 -0
  22. package/public/cmaps/Adobe-CNS1-1.bcmap +0 -0
  23. package/public/cmaps/Adobe-CNS1-2.bcmap +0 -0
  24. package/public/cmaps/Adobe-CNS1-3.bcmap +0 -0
  25. package/public/cmaps/Adobe-CNS1-4.bcmap +0 -0
  26. package/public/cmaps/Adobe-CNS1-5.bcmap +0 -0
  27. package/public/cmaps/Adobe-CNS1-6.bcmap +0 -0
  28. package/public/cmaps/Adobe-CNS1-UCS2.bcmap +0 -0
  29. package/public/cmaps/Adobe-GB1-0.bcmap +0 -0
  30. package/public/cmaps/Adobe-GB1-1.bcmap +0 -0
  31. package/public/cmaps/Adobe-GB1-2.bcmap +0 -0
  32. package/public/cmaps/Adobe-GB1-3.bcmap +0 -0
  33. package/public/cmaps/Adobe-GB1-4.bcmap +0 -0
  34. package/public/cmaps/Adobe-GB1-5.bcmap +0 -0
  35. package/public/cmaps/Adobe-GB1-UCS2.bcmap +0 -0
  36. package/public/cmaps/Adobe-Japan1-0.bcmap +0 -0
  37. package/public/cmaps/Adobe-Japan1-1.bcmap +0 -0
  38. package/public/cmaps/Adobe-Japan1-2.bcmap +0 -0
  39. package/public/cmaps/Adobe-Japan1-3.bcmap +0 -0
  40. package/public/cmaps/Adobe-Japan1-4.bcmap +0 -0
  41. package/public/cmaps/Adobe-Japan1-5.bcmap +0 -0
  42. package/public/cmaps/Adobe-Japan1-6.bcmap +0 -0
  43. package/public/cmaps/Adobe-Japan1-UCS2.bcmap +0 -0
  44. package/public/cmaps/Adobe-Korea1-0.bcmap +0 -0
  45. package/public/cmaps/Adobe-Korea1-1.bcmap +0 -0
  46. package/public/cmaps/Adobe-Korea1-2.bcmap +0 -0
  47. package/public/cmaps/Adobe-Korea1-UCS2.bcmap +0 -0
  48. package/public/cmaps/B5-H.bcmap +0 -0
  49. package/public/cmaps/B5-V.bcmap +0 -0
  50. package/public/cmaps/B5pc-H.bcmap +0 -0
  51. package/public/cmaps/B5pc-V.bcmap +0 -0
  52. package/public/cmaps/CNS-EUC-H.bcmap +0 -0
  53. package/public/cmaps/CNS-EUC-V.bcmap +0 -0
  54. package/public/cmaps/CNS1-H.bcmap +0 -0
  55. package/public/cmaps/CNS1-V.bcmap +0 -0
  56. package/public/cmaps/CNS2-H.bcmap +0 -0
  57. package/public/cmaps/CNS2-V.bcmap +3 -0
  58. package/public/cmaps/ETHK-B5-H.bcmap +0 -0
  59. package/public/cmaps/ETHK-B5-V.bcmap +0 -0
  60. package/public/cmaps/ETen-B5-H.bcmap +0 -0
  61. package/public/cmaps/ETen-B5-V.bcmap +0 -0
  62. package/public/cmaps/ETenms-B5-H.bcmap +3 -0
  63. package/public/cmaps/ETenms-B5-V.bcmap +0 -0
  64. package/public/cmaps/EUC-H.bcmap +0 -0
  65. package/public/cmaps/EUC-V.bcmap +0 -0
  66. package/public/cmaps/Ext-H.bcmap +0 -0
  67. package/public/cmaps/Ext-RKSJ-H.bcmap +0 -0
  68. package/public/cmaps/Ext-RKSJ-V.bcmap +0 -0
  69. package/public/cmaps/Ext-V.bcmap +0 -0
  70. package/public/cmaps/GB-EUC-H.bcmap +0 -0
  71. package/public/cmaps/GB-EUC-V.bcmap +0 -0
  72. package/public/cmaps/GB-H.bcmap +4 -0
  73. package/public/cmaps/GB-V.bcmap +0 -0
  74. package/public/cmaps/GBK-EUC-H.bcmap +0 -0
  75. package/public/cmaps/GBK-EUC-V.bcmap +0 -0
  76. package/public/cmaps/GBK2K-H.bcmap +0 -0
  77. package/public/cmaps/GBK2K-V.bcmap +0 -0
  78. package/public/cmaps/GBKp-EUC-H.bcmap +0 -0
  79. package/public/cmaps/GBKp-EUC-V.bcmap +0 -0
  80. package/public/cmaps/GBT-EUC-H.bcmap +0 -0
  81. package/public/cmaps/GBT-EUC-V.bcmap +0 -0
  82. package/public/cmaps/GBT-H.bcmap +0 -0
  83. package/public/cmaps/GBT-V.bcmap +0 -0
  84. package/public/cmaps/GBTpc-EUC-H.bcmap +0 -0
  85. package/public/cmaps/GBTpc-EUC-V.bcmap +0 -0
  86. package/public/cmaps/GBpc-EUC-H.bcmap +0 -0
  87. package/public/cmaps/GBpc-EUC-V.bcmap +0 -0
  88. package/public/cmaps/H.bcmap +0 -0
  89. package/public/cmaps/HKdla-B5-H.bcmap +0 -0
  90. package/public/cmaps/HKdla-B5-V.bcmap +0 -0
  91. package/public/cmaps/HKdlb-B5-H.bcmap +0 -0
  92. package/public/cmaps/HKdlb-B5-V.bcmap +0 -0
  93. package/public/cmaps/HKgccs-B5-H.bcmap +0 -0
  94. package/public/cmaps/HKgccs-B5-V.bcmap +0 -0
  95. package/public/cmaps/HKm314-B5-H.bcmap +0 -0
  96. package/public/cmaps/HKm314-B5-V.bcmap +0 -0
  97. package/public/cmaps/HKm471-B5-H.bcmap +0 -0
  98. package/public/cmaps/HKm471-B5-V.bcmap +0 -0
  99. package/public/cmaps/HKscs-B5-H.bcmap +0 -0
  100. package/public/cmaps/HKscs-B5-V.bcmap +0 -0
  101. package/public/cmaps/Hankaku.bcmap +0 -0
  102. package/public/cmaps/Hiragana.bcmap +0 -0
  103. package/public/cmaps/KSC-EUC-H.bcmap +0 -0
  104. package/public/cmaps/KSC-EUC-V.bcmap +0 -0
  105. package/public/cmaps/KSC-H.bcmap +0 -0
  106. package/public/cmaps/KSC-Johab-H.bcmap +0 -0
  107. package/public/cmaps/KSC-Johab-V.bcmap +0 -0
  108. package/public/cmaps/KSC-V.bcmap +0 -0
  109. package/public/cmaps/KSCms-UHC-H.bcmap +0 -0
  110. package/public/cmaps/KSCms-UHC-HW-H.bcmap +0 -0
  111. package/public/cmaps/KSCms-UHC-HW-V.bcmap +0 -0
  112. package/public/cmaps/KSCms-UHC-V.bcmap +0 -0
  113. package/public/cmaps/KSCpc-EUC-H.bcmap +0 -0
  114. package/public/cmaps/KSCpc-EUC-V.bcmap +0 -0
  115. package/public/cmaps/Katakana.bcmap +0 -0
  116. package/public/cmaps/LICENSE +36 -0
  117. package/public/cmaps/NWP-H.bcmap +0 -0
  118. package/public/cmaps/NWP-V.bcmap +0 -0
  119. package/public/cmaps/RKSJ-H.bcmap +0 -0
  120. package/public/cmaps/RKSJ-V.bcmap +0 -0
  121. package/public/cmaps/Roman.bcmap +0 -0
  122. package/public/cmaps/UniCNS-UCS2-H.bcmap +0 -0
  123. package/public/cmaps/UniCNS-UCS2-V.bcmap +0 -0
  124. package/public/cmaps/UniCNS-UTF16-H.bcmap +0 -0
  125. package/public/cmaps/UniCNS-UTF16-V.bcmap +0 -0
  126. package/public/cmaps/UniCNS-UTF32-H.bcmap +0 -0
  127. package/public/cmaps/UniCNS-UTF32-V.bcmap +0 -0
  128. package/public/cmaps/UniCNS-UTF8-H.bcmap +0 -0
  129. package/public/cmaps/UniCNS-UTF8-V.bcmap +0 -0
  130. package/public/cmaps/UniGB-UCS2-H.bcmap +0 -0
  131. package/public/cmaps/UniGB-UCS2-V.bcmap +0 -0
  132. package/public/cmaps/UniGB-UTF16-H.bcmap +0 -0
  133. package/public/cmaps/UniGB-UTF16-V.bcmap +0 -0
  134. package/public/cmaps/UniGB-UTF32-H.bcmap +0 -0
  135. package/public/cmaps/UniGB-UTF32-V.bcmap +0 -0
  136. package/public/cmaps/UniGB-UTF8-H.bcmap +0 -0
  137. package/public/cmaps/UniGB-UTF8-V.bcmap +0 -0
  138. package/public/cmaps/UniJIS-UCS2-H.bcmap +0 -0
  139. package/public/cmaps/UniJIS-UCS2-HW-H.bcmap +0 -0
  140. package/public/cmaps/UniJIS-UCS2-HW-V.bcmap +0 -0
  141. package/public/cmaps/UniJIS-UCS2-V.bcmap +0 -0
  142. package/public/cmaps/UniJIS-UTF16-H.bcmap +0 -0
  143. package/public/cmaps/UniJIS-UTF16-V.bcmap +0 -0
  144. package/public/cmaps/UniJIS-UTF32-H.bcmap +0 -0
  145. package/public/cmaps/UniJIS-UTF32-V.bcmap +0 -0
  146. package/public/cmaps/UniJIS-UTF8-H.bcmap +0 -0
  147. package/public/cmaps/UniJIS-UTF8-V.bcmap +0 -0
  148. package/public/cmaps/UniJIS2004-UTF16-H.bcmap +0 -0
  149. package/public/cmaps/UniJIS2004-UTF16-V.bcmap +0 -0
  150. package/public/cmaps/UniJIS2004-UTF32-H.bcmap +0 -0
  151. package/public/cmaps/UniJIS2004-UTF32-V.bcmap +0 -0
  152. package/public/cmaps/UniJIS2004-UTF8-H.bcmap +0 -0
  153. package/public/cmaps/UniJIS2004-UTF8-V.bcmap +0 -0
  154. package/public/cmaps/UniJISPro-UCS2-HW-V.bcmap +0 -0
  155. package/public/cmaps/UniJISPro-UCS2-V.bcmap +0 -0
  156. package/public/cmaps/UniJISPro-UTF8-V.bcmap +0 -0
  157. package/public/cmaps/UniJISX0213-UTF32-H.bcmap +0 -0
  158. package/public/cmaps/UniJISX0213-UTF32-V.bcmap +0 -0
  159. package/public/cmaps/UniJISX02132004-UTF32-H.bcmap +0 -0
  160. package/public/cmaps/UniJISX02132004-UTF32-V.bcmap +0 -0
  161. package/public/cmaps/UniKS-UCS2-H.bcmap +0 -0
  162. package/public/cmaps/UniKS-UCS2-V.bcmap +0 -0
  163. package/public/cmaps/UniKS-UTF16-H.bcmap +0 -0
  164. package/public/cmaps/UniKS-UTF16-V.bcmap +0 -0
  165. package/public/cmaps/UniKS-UTF32-H.bcmap +0 -0
  166. package/public/cmaps/UniKS-UTF32-V.bcmap +0 -0
  167. package/public/cmaps/UniKS-UTF8-H.bcmap +0 -0
  168. package/public/cmaps/UniKS-UTF8-V.bcmap +0 -0
  169. package/public/cmaps/V.bcmap +0 -0
  170. package/public/cmaps/WP-Symbol.bcmap +0 -0
  171. package/public/polyfills/polyfills.js +802 -0
  172. package/public/vendor/docx/docx.worker.js +5 -0
  173. package/public/vendor/docx/jszip.min.js +13 -0
  174. package/public/vendor/libarchive/libarchive.wasm +0 -0
  175. package/public/vendor/libarchive/worker-bundle.js +6 -0
  176. package/public/vendor/pptx/pptx.worker.js +26 -0
  177. package/public/wasm/cad/0.8.2/dwfv-render.wasm +0 -0
  178. package/public/wasm/cad/0.8.2/dwg-worker.js +24 -0
  179. package/public/wasm/cad/0.8.2/dwg-worker.js.map +1 -0
  180. package/public/wasm/cad/0.8.2/libredwg-web.js +2 -0
  181. package/public/wasm/cad/0.8.2/libredwg-web.wasm +0 -0
  182. package/public/wasm/cad/dwfv-render.wasm +0 -0
  183. package/public/wasm/cad/dwg-worker.js +24 -0
  184. package/public/wasm/cad/dwg-worker.js.map +1 -0
  185. package/public/wasm/cad/libredwg-web.js +2 -0
  186. package/public/wasm/cad/libredwg-web.wasm +0 -0
  187. package/public/wasm/data/sql-wasm.wasm +0 -0
  188. package/public/wasm/hdiff.wasm +0 -0
  189. package/public/wasm/model/LICENSE.occt-import-js.txt +504 -0
  190. package/public/wasm/model/LICENSE.occt.txt +502 -0
  191. package/public/wasm/model/occt-import-js.js +19 -0
  192. package/public/wasm/model/occt-import-js.wasm +0 -0
  193. package/public/wasm/model/occt-worker.js +83 -0
  194. package/public/wasm/typst/fonts/DejaVuSansMono-Bold.ttf +0 -0
  195. package/public/wasm/typst/fonts/DejaVuSansMono-BoldOblique.ttf +0 -0
  196. package/public/wasm/typst/fonts/DejaVuSansMono-Oblique.ttf +0 -0
  197. package/public/wasm/typst/fonts/DejaVuSansMono.ttf +0 -0
  198. package/public/wasm/typst/fonts/LibertinusSerif-Bold.otf +0 -0
  199. package/public/wasm/typst/fonts/LibertinusSerif-BoldItalic.otf +0 -0
  200. package/public/wasm/typst/fonts/LibertinusSerif-Italic.otf +0 -0
  201. package/public/wasm/typst/fonts/LibertinusSerif-Regular.otf +0 -0
  202. package/public/wasm/typst/fonts/LibertinusSerif-Semibold.otf +0 -0
  203. package/public/wasm/typst/fonts/LibertinusSerif-SemiboldItalic.otf +0 -0
  204. package/public/wasm/typst/fonts/NewCM10-Bold.otf +0 -0
  205. package/public/wasm/typst/fonts/NewCM10-BoldItalic.otf +0 -0
  206. package/public/wasm/typst/fonts/NewCM10-Italic.otf +0 -0
  207. package/public/wasm/typst/fonts/NewCM10-Regular.otf +0 -0
  208. package/public/wasm/typst/fonts/NewCMMath-Bold.otf +0 -0
  209. package/public/wasm/typst/fonts/NewCMMath-Book.otf +0 -0
  210. package/public/wasm/typst/fonts/NewCMMath-Regular.otf +0 -0
  211. package/public/wasm/typst/fonts/README.md +7 -0
  212. package/public/wasm/typst/typst_ts_renderer_bg.wasm +0 -0
  213. package/public/wasm/typst/typst_ts_web_compiler_bg.wasm +0 -0
  214. package/scripts/patch-docx-grid.cjs +412 -0
  215. package/src/api/_base.ts +243 -0
  216. package/src/api/index.ts +17 -0
  217. package/src/api/project.ts +1345 -0
  218. package/src/api/user.ts +1174 -0
  219. package/src/contract.ts +50 -0
  220. package/src/hooks/index.ts +2 -0
  221. package/{dist/hooks/index.js → src/hooks/useLongPress.ts} +53 -49
  222. package/src/hooks/useOnlineStatus.ts +22 -0
  223. package/src/index.ts +14 -0
  224. package/src/types/id.ts +2 -0
  225. package/src/types/index.ts +5 -0
  226. package/src/types/project/base.ts +63 -0
  227. package/src/types/project/contract.ts +79 -0
  228. package/src/types/project/contractStatus.tsx +15 -0
  229. package/src/types/project/index.ts +5 -0
  230. package/src/types/project/member.ts +46 -0
  231. package/src/types/project/progress.ts +43 -0
  232. package/src/types/projectRole.ts +17 -0
  233. package/src/types/theme.ts +1 -0
  234. package/src/types/user/index.ts +1 -0
  235. package/src/types/user/role.ts +7 -0
  236. package/src/ui/CommentTimeline/index.tsx +330 -0
  237. package/src/ui/FileManager/FileContextMenu.tsx +628 -0
  238. package/src/ui/FileManager/FileGridView.tsx +529 -0
  239. package/src/ui/FileManager/FileTableView.tsx +405 -0
  240. package/src/ui/FileManager/FileToolbar.tsx +119 -0
  241. package/src/ui/FileManager/FileVersionHistoryModal.tsx +175 -0
  242. package/src/ui/FileManager/MoveCopyToProjectModal.tsx +119 -0
  243. package/src/ui/FileManager/ShareToWechatModal.tsx +419 -0
  244. package/src/ui/FileManager/hooks/useFileManagerActions.ts +2532 -0
  245. package/src/ui/FileManager/hooks/useFileManagerState.ts +419 -0
  246. package/src/ui/FileManager/index.tsx +580 -0
  247. package/src/ui/FileManager/projectFileManagerApi.ts +57 -0
  248. package/src/ui/FileManager/types.ts +184 -0
  249. package/src/ui/FileManager/utils/fileDeltaWorker.ts +193 -0
  250. package/src/ui/FileManager/utils/fileTree.ts +178 -0
  251. package/src/ui/FileManager/utils/fileUpload.ts +714 -0
  252. package/src/ui/FileManager/utils/fileUtils.ts +65 -0
  253. package/src/ui/InvoiceRecordsList/index.tsx +813 -0
  254. package/src/ui/MyFileSelectorModal.tsx +261 -0
  255. package/src/ui/ProjectSelector/index.tsx +472 -0
  256. package/src/ui/ProjectSelector/projectCache.ts +40 -0
  257. package/src/ui/RoleSelector/index.tsx +473 -0
  258. package/src/ui/RoleSelector/roleCache.ts +40 -0
  259. package/src/ui/UIAlert.tsx +399 -0
  260. package/src/ui/UIAlertExample.tsx +129 -0
  261. package/src/ui/UIConfirm.tsx +335 -0
  262. package/src/ui/UIConfirmExample.tsx +165 -0
  263. package/src/ui/UIDatePicker.tsx +146 -0
  264. package/src/ui/UIDateRangePicker.tsx +38 -0
  265. package/src/ui/UIFilePreview/ExcelEditor/index.tsx +617 -0
  266. package/src/ui/UIFilePreview/ExcelEditor/types.ts +24 -0
  267. package/src/ui/UIFilePreview/ExportDropdown.css +85 -0
  268. package/src/ui/UIFilePreview/ExportDropdown.tsx +109 -0
  269. package/src/ui/UIFilePreview/IndexedDBUtils.ts +564 -0
  270. package/src/ui/UIFilePreview/MarkdownEditor/exportMarkdownPdf.ts +576 -0
  271. package/src/ui/UIFilePreview/MarkdownEditor/index.tsx +677 -0
  272. package/src/ui/UIFilePreview/MarkdownEditor/markdownEditor.css +1005 -0
  273. package/src/ui/UIFilePreview/MarkdownEditor/types.ts +15 -0
  274. package/src/ui/UIFilePreview/PPTXEditor/index.tsx +602 -0
  275. package/src/ui/UIFilePreview/RichDocEditor/exportRDocMarkdown.ts +77 -0
  276. package/src/ui/UIFilePreview/RichDocEditor/exportRDocPdf.ts +374 -0
  277. package/src/ui/UIFilePreview/RichDocEditor/index.tsx +730 -0
  278. package/src/ui/UIFilePreview/RichDocEditor/richdoc-editor.css +59 -0
  279. package/src/ui/UIFilePreview/UIFilePreview.tsx +611 -0
  280. package/src/ui/UIFilePreview/WordEditor/index.tsx +3933 -0
  281. package/src/ui/UIFilePreview/WordEditor/style.ts +1213 -0
  282. package/src/ui/UIFilePreview/WordEditor/word-editor.css +999 -0
  283. package/src/ui/UIFilePreview/filePreview.css +193 -0
  284. package/src/ui/UIFilePreview/filetypes/archive.tsx +66 -0
  285. package/src/ui/UIFilePreview/filetypes/cad.tsx +287 -0
  286. package/src/ui/UIFilePreview/filetypes/excel.tsx +355 -0
  287. package/src/ui/UIFilePreview/filetypes/image.tsx +20 -0
  288. package/src/ui/UIFilePreview/filetypes/imageLoader.ts +63 -0
  289. package/src/ui/UIFilePreview/filetypes/pdf.tsx +156 -0
  290. package/src/ui/UIFilePreview/filetypes/ppt.tsx +535 -0
  291. package/src/ui/UIFilePreview/filetypes/pptExportPdf.ts +523 -0
  292. package/src/ui/UIFilePreview/filetypes/video.tsx +482 -0
  293. package/src/ui/UIFilePreview/filetypes/word.tsx +245 -0
  294. package/src/ui/UIFilePreview/filetypes/wordExportMarkdown.ts +86 -0
  295. package/src/ui/UIFilePreview/filetypes/wordExportPdf.tsx +427 -0
  296. package/src/ui/UIFilePreview/index.ts +35 -0
  297. package/src/ui/UIFilePreview/pdfPagination.ts +143 -0
  298. package/src/ui/UIFilePreview/previewUtils.tsx +531 -0
  299. package/src/ui/UIFileUpload.tsx +382 -0
  300. package/src/ui/UIImageUpload.tsx +195 -0
  301. package/src/ui/UILoading.tsx +255 -0
  302. package/src/ui/UILoadingExample.tsx +139 -0
  303. package/src/ui/UISelect.tsx +105 -0
  304. package/src/ui/UIToast.tsx +381 -0
  305. package/src/ui/UIToastExample.tsx +69 -0
  306. package/src/ui/UIToastSingle.tsx +279 -0
  307. package/src/ui/UIViewToggle.tsx +64 -0
  308. package/src/ui/UserSelector/index.tsx +583 -0
  309. package/src/ui/index.ts +84 -0
  310. package/src/ui/upload/image.ts +135 -0
  311. package/src/ui/upload/index.ts +73 -0
  312. package/src/ui/upload/submitFile.ts +106 -0
  313. package/src/ui/upload/submitForm.ts +124 -0
  314. package/src/ui/upload/upload.err.ts +15 -0
  315. package/src/ui/upload/upload.ts +250 -0
  316. package/src/utils/CacheDepartmentInfo.ts +372 -0
  317. package/src/utils/CacheFileContent.ts +315 -0
  318. package/src/utils/CachePermissionInfo.ts +235 -0
  319. package/src/utils/CacheRoleInfo.ts +303 -0
  320. package/src/utils/CacheUserInfo.ts +818 -0
  321. package/src/utils/CacheViewToggleInfo.ts +182 -0
  322. package/src/utils/MessageContentUtils.ts +268 -0
  323. package/src/utils/clipboard.ts +70 -0
  324. package/src/utils/companyEmail.ts +19 -0
  325. package/src/utils/forbidDebugger.ts +59 -0
  326. package/src/utils/formatters.ts +94 -0
  327. package/src/utils/htmlUtils.tsx +59 -0
  328. package/src/utils/index.ts +18 -0
  329. package/src/utils/keyboard.ts +114 -0
  330. package/src/utils/mammothApi.ts +16 -0
  331. package/src/utils/polyfills.ts +928 -0
  332. package/src/utils/regex.ts +14 -0
  333. package/src/utils/storage.ts +95 -0
  334. package/src/utils/workerBootstrap.ts +87 -0
  335. package/dist/api/index.js +0 -1553
  336. package/dist/contract.js +0 -5
  337. package/dist/index.js +0 -4492
  338. package/dist/types/index.js +0 -49
  339. package/dist/ui/index.css +0 -1876
  340. package/dist/ui/index.js +0 -22245
  341. package/dist/utils/index.js +0 -4296
  342. /package/{dist → src}/styles/ant-modal.css +0 -0
  343. /package/{dist → src}/styles/ant-spin.css +0 -0
  344. /package/{dist → src}/styles/ant-table.css +0 -0
  345. /package/{dist → src}/styles/index.css +0 -0
@@ -0,0 +1,928 @@
1
+ /**
2
+ * 运行时能力兜底:
3
+ * - Promise.allSettled(部分旧 Safari 缺失)
4
+ * - Web Streams 相关构造器与 ReadableStream#pipeTo:
5
+ * ReadableStream / WritableStream / TransformStream / ReadableByteStreamController
6
+ * / ReadableStreamDefaultController / ReadableStreamDefaultReader
7
+ * / WritableStreamDefaultWriter / ByteLengthQueuingStrategy / CountQueuingStrategy
8
+ * / TextDecoderStream / TextEncoderStream
9
+ *
10
+ * 实现目标:避免 Safari 旧版本因 `typeof ReadableByteStreamController` 为 undefined 或
11
+ * 缺少 ReadableStream#pipeTo / WritableStream 时导致第三方库(文件预览、docx、压缩包等)报错。
12
+ * 只在缺失时赋值,不覆盖浏览器原生实现。
13
+ *
14
+ * 【经验】不要在顶层直接向 globalThis 注入大体积的 Web Streams polyfill:
15
+ * 第三方 stream polyfill 的 prototype patch 曾与 React dispatcher 的内部状态冲突,
16
+ * 导致懒加载 chunk 运行时 dispatcher.useState 为 null。因此:
17
+ * 1) 下面为轻量、最小可用的实现;
18
+ * 2) 仅在缺失时赋值;
19
+ * 3) 不修改 Promise / async generator 相关内置原型。
20
+ */
21
+
22
+ /* =========================================================
23
+ * 0. 本文件内部使用的 DOM 类型别名(避免因 tsconfig lib 缺项导致编译错误)
24
+ * ========================================================= */
25
+ type R<T> = { done: false; value: T } | { done: true; value?: undefined };
26
+ type ByteR<T> = { done: false; value: T } | { done: true; value: T | undefined };
27
+ type SPipeOptions = {
28
+ preventClose?: boolean;
29
+ preventAbort?: boolean;
30
+ preventCancel?: boolean;
31
+ signal?: AbortSignal;
32
+ };
33
+
34
+ /* =========================================================
35
+ * 1. Promise.allSettled polyfill(直接挂载到 Promise.allSettled)
36
+ * ========================================================= */
37
+ (function installPromiseAllSettled() {
38
+ if (typeof Promise === 'undefined') return;
39
+ if (typeof (Promise as any).allSettled === 'function') return;
40
+
41
+ type PolyfillSettled<T> =
42
+ | { status: 'fulfilled'; value: T }
43
+ | { status: 'rejected'; reason: unknown };
44
+
45
+ const allSettledImpl = function <T>(values: Iterable<T | PromiseLike<T>>) {
46
+ const items = Array.isArray(values)
47
+ ? (values as Array<T | PromiseLike<T>>)
48
+ : Array.from(values as Iterable<T | PromiseLike<T>>);
49
+ if (items.length === 0) return Promise.resolve([] as any);
50
+ return new Promise((resolve) => {
51
+ const results: PolyfillSettled<Awaited<T>>[] = new Array(items.length);
52
+ let remaining = items.length;
53
+ const done = () => {
54
+ remaining -= 1;
55
+ if (remaining === 0) resolve(results);
56
+ };
57
+ items.forEach((input, index) => {
58
+ Promise.resolve(input).then(
59
+ (value) => {
60
+ results[index] = { status: 'fulfilled', value } as any;
61
+ done();
62
+ },
63
+ (reason) => {
64
+ results[index] = { status: 'rejected', reason };
65
+ done();
66
+ }
67
+ );
68
+ });
69
+ });
70
+ };
71
+
72
+ try {
73
+ Object.defineProperty(Promise, 'allSettled', {
74
+ configurable: true,
75
+ writable: true,
76
+ value: allSettledImpl,
77
+ });
78
+ } catch (e) {
79
+ // 严格冻结对象:尝试直接赋值兜底
80
+ try { (Promise as any).allSettled = allSettledImpl; } catch (_) { /* skip */ }
81
+ }
82
+ // Safari 个别版本:内置构造器上的 defineProperty 既不抛错,也不生效(静默失败)
83
+ // 这里再次检测,强制赋值兜底。
84
+ try {
85
+ if (typeof (Promise as any).allSettled !== 'function') {
86
+ (Promise as any).allSettled = allSettledImpl;
87
+ }
88
+ } catch (_) { /* skip */ }
89
+ })();
90
+
91
+ /**
92
+ * 业务代码使用 Promise.allSettled 前的「自愈式」守卫。
93
+ * 即便 index.html 内联脚本 + 本文件顶层 IIFE 在极端 Safari/缓存/ServiceWorker 组合下
94
+ * 都没能生效,调用该函数会再次尝试安装。设计为多次调用零成本。
95
+ *
96
+ * 使用示例:
97
+ * import { ensurePromiseAllSettled } from './polyfills';
98
+ * ensurePromiseAllSettled();
99
+ * const results = await Promise.allSettled(jobs);
100
+ */
101
+ export function ensurePromiseAllSettled(): void {
102
+ try {
103
+ if (typeof Promise === 'undefined') return;
104
+ if (typeof (Promise as any).allSettled === 'function') return;
105
+
106
+ type PolyfillSettled<T> =
107
+ | { status: 'fulfilled'; value: T }
108
+ | { status: 'rejected'; reason: unknown };
109
+
110
+ const impl = <T>(values: Iterable<T | PromiseLike<T>>) => {
111
+ const items = Array.isArray(values)
112
+ ? (values as Array<T | PromiseLike<T>>)
113
+ : Array.from(values as Iterable<T | PromiseLike<T>>);
114
+ if (items.length === 0) return Promise.resolve([] as any);
115
+ return new Promise((resolve) => {
116
+ const results: PolyfillSettled<Awaited<T>>[] = new Array(items.length);
117
+ let remaining = items.length;
118
+ const done = () => { if (--remaining === 0) resolve(results); };
119
+ items.forEach((input, index) => {
120
+ Promise.resolve(input).then(
121
+ (value) => { results[index] = { status: 'fulfilled', value } as any; done(); },
122
+ (reason) => { results[index] = { status: 'rejected', reason }; done(); }
123
+ );
124
+ });
125
+ });
126
+ };
127
+
128
+ try {
129
+ Object.defineProperty(Promise, 'allSettled', { configurable: true, writable: true, value: impl });
130
+ } catch (_) { /* skip */ }
131
+ if (typeof (Promise as any).allSettled !== 'function') {
132
+ try { (Promise as any).allSettled = impl; } catch (_) { /* skip */ }
133
+ }
134
+ } catch (_) { /* 极端情况下任何抛错都不能阻断业务执行 */ }
135
+ }
136
+
137
+ /**
138
+ * ReadableByteStreamController 自愈守卫:对「ReadableByteStreamController is not implemented」
139
+ * 这条显式错误字符串做兜底。第三方库在做 feature detection 时会以
140
+ * `typeof globalThis.ReadableByteStreamController === 'function'` 为前提,
141
+ * 如果检测通过但实际构造函数抛错,就会把这句抛出来,因此我们确保构造函数真正可用。
142
+ */
143
+ export function ensureWebStreamsPolyfill(): void {
144
+ try { installWebStreamsPolyfill(); } catch (_) { /* skip */ }
145
+ }
146
+
147
+ /* =========================================================
148
+ * 2. QueuingStrategy
149
+ * ========================================================= */
150
+ class ByteLengthQueuingStrategy {
151
+ public highWaterMark: number;
152
+ constructor({ highWaterMark }: { highWaterMark: number }) {
153
+ this.highWaterMark = highWaterMark;
154
+ }
155
+ size(chunk: ArrayBufferView) {
156
+ return chunk?.byteLength ?? 0;
157
+ }
158
+ }
159
+
160
+ class CountQueuingStrategy {
161
+ public highWaterMark: number;
162
+ constructor({ highWaterMark }: { highWaterMark: number }) {
163
+ this.highWaterMark = highWaterMark;
164
+ }
165
+ size() {
166
+ return 1;
167
+ }
168
+ }
169
+
170
+ /* =========================================================
171
+ * 3. ReadableStream (支持 default / pull / cancel 与 BYOB 控制器空壳)
172
+ * 注意:类不写 implements,避免 tsconfig lib 未声明的接口造成协变/逆变报错。
173
+ * ========================================================= */
174
+ type QueueItem<T> =
175
+ | { type: 'chunk'; value: T }
176
+ | { type: 'close' }
177
+ | { type: 'error'; error: unknown };
178
+
179
+ interface StreamState {
180
+ closed: boolean;
181
+ errored: boolean;
182
+ error: unknown;
183
+ }
184
+
185
+ class PolyfillReadableStreamDefaultController<T = any> {
186
+ public readonly desiredSize: number | null = 0;
187
+ public readonly byobRequest: any = null;
188
+ private _stream: PolyfillReadableStream<T>;
189
+ constructor(stream: PolyfillReadableStream<T>) {
190
+ this._stream = stream;
191
+ }
192
+ enqueue(chunk: T) {
193
+ this._stream._push(chunk);
194
+ }
195
+ close() {
196
+ this._stream._close();
197
+ }
198
+ error(e?: unknown) {
199
+ this._stream._error(e ?? new Error('ReadableStream errored'));
200
+ }
201
+ get desiredSizeInternal() {
202
+ return this._stream._chunks ? 1 : 0;
203
+ }
204
+ }
205
+
206
+ class PolyfillReadableByteStreamController {
207
+ public readonly byobRequest: any = null;
208
+ public readonly desiredSize: number | null = 0;
209
+ private _stream: PolyfillReadableStream<Uint8Array>;
210
+ constructor(stream: PolyfillReadableStream<Uint8Array>) {
211
+ this._stream = stream;
212
+ }
213
+ close() {
214
+ this._stream._close();
215
+ }
216
+ enqueue(chunk: ArrayBufferView) {
217
+ this._stream._push(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
218
+ }
219
+ error(e?: unknown) {
220
+ this._stream._error(e ?? new Error('ReadableByteStream errored'));
221
+ }
222
+ }
223
+
224
+ class PolyfillReadableStreamDefaultReader<T = any> {
225
+ public readonly closed: Promise<undefined>;
226
+ private _stream: PolyfillReadableStream<T>;
227
+ private _resolveClosed!: (value: undefined) => void;
228
+ constructor(stream: PolyfillReadableStream<T>) {
229
+ this._stream = stream;
230
+ this._stream._reader = this;
231
+ this.closed = new Promise((resolve) => {
232
+ this._resolveClosed = resolve;
233
+ });
234
+ }
235
+ read(): Promise<R<T>> {
236
+ return this._stream._read();
237
+ }
238
+ releaseLock() {
239
+ if (this._stream._reader === this) this._stream._reader = null;
240
+ }
241
+ cancel(reason?: unknown): Promise<void> {
242
+ return this._stream.cancel(reason);
243
+ }
244
+ _onClosed() {
245
+ this._resolveClosed(undefined);
246
+ }
247
+ }
248
+
249
+ class PolyfillReadableStreamBYOBReader {
250
+ public readonly closed: Promise<undefined>;
251
+ private _stream: PolyfillReadableStream<any>;
252
+ private _resolveClosed!: (value: undefined) => void;
253
+ constructor(stream: PolyfillReadableStream<any>) {
254
+ this._stream = stream;
255
+ this._stream._byobReader = this;
256
+ this.closed = new Promise((resolve) => {
257
+ this._resolveClosed = resolve;
258
+ });
259
+ }
260
+ read<T extends ArrayBufferView>(view: T): Promise<ByteR<T>> {
261
+ // 最小实现:合并 bytes chunks 到传入 buffer 中
262
+ return this._stream._readInto(view);
263
+ }
264
+ releaseLock() {
265
+ if (this._stream._byobReader === this) this._stream._byobReader = null;
266
+ }
267
+ cancel(reason?: unknown): Promise<void> {
268
+ return this._stream.cancel(reason);
269
+ }
270
+ _onClosed() {
271
+ this._resolveClosed(undefined);
272
+ }
273
+ }
274
+
275
+ class PolyfillReadableStream<T = any> {
276
+ public locked = false;
277
+ // 内部字段用包内可见访问
278
+ _chunks: QueueItem<T>[] = [];
279
+ _waiting: null | ((value: R<T>) => void) = null;
280
+ _byobWaiting: null | ((value: any) => void) = null;
281
+ _reader: PolyfillReadableStreamDefaultReader<T> | null = null;
282
+ _byobReader: PolyfillReadableStreamBYOBReader | null = null;
283
+ _state: StreamState = { closed: false, errored: false, error: undefined };
284
+ _source: any = null;
285
+ _cancelCallback: null | ((reason: unknown) => void | PromiseLike<void>) = null;
286
+ _controller: any = null;
287
+ _pulling = false;
288
+ _pullScheduled = false;
289
+ _type: undefined | 'bytes' = undefined;
290
+ _autoAllocateChunkSize: number | undefined;
291
+
292
+ constructor(underlyingSource?: any, _strategy?: any) {
293
+ this._source = underlyingSource ?? null;
294
+ this._cancelCallback = underlyingSource?.cancel ?? null;
295
+ if (underlyingSource && underlyingSource.type === 'bytes') {
296
+ this._type = 'bytes';
297
+ this._autoAllocateChunkSize = underlyingSource.autoAllocateChunkSize;
298
+ this._controller = new PolyfillReadableByteStreamController(
299
+ this as unknown as PolyfillReadableStream<Uint8Array>
300
+ );
301
+ } else {
302
+ this._controller = new PolyfillReadableStreamDefaultController<T>(this);
303
+ }
304
+ const start = underlyingSource?.start;
305
+ if (typeof start === 'function') {
306
+ Promise.resolve(start.call(underlyingSource, this._controller)).catch((e: unknown) => {
307
+ this._error(e);
308
+ });
309
+ }
310
+ }
311
+
312
+ getReader(): any {
313
+ // 为避免签名冲突,运行时根据 options.mode 判断;不写 overload 防止与 lib.dom 不一致
314
+ // eslint-disable-next-line prefer-rest-params
315
+ const options = arguments[0] as { mode?: 'byob' } | undefined;
316
+ if (options?.mode === 'byob') {
317
+ if (this._byobReader) throw new TypeError('ReadableStream is locked');
318
+ return new PolyfillReadableStreamBYOBReader(this);
319
+ }
320
+ if (this._reader) throw new TypeError('ReadableStream is locked');
321
+ return new PolyfillReadableStreamDefaultReader<T>(this);
322
+ }
323
+
324
+ tee(): [any, any] {
325
+ const left = this._branch();
326
+ const right = this._branch();
327
+ return [left, right];
328
+ }
329
+
330
+ pipeThrough(transform: { readable: any; writable: any }, options?: SPipeOptions): any {
331
+ void this.pipeTo(transform.writable, options);
332
+ return transform.readable;
333
+ }
334
+
335
+ async pipeTo(dest: any, options?: SPipeOptions): Promise<void> {
336
+ const preventClose = !!options?.preventClose;
337
+ const preventAbort = !!options?.preventAbort;
338
+ const preventCancel = !!options?.preventCancel;
339
+ const writer = dest && typeof dest.getWriter === 'function' ? dest.getWriter() : null;
340
+ try {
341
+ const reader: any = this.getReader();
342
+ try {
343
+ while (true) {
344
+ const { done, value } = (await reader.read()) as { done: boolean; value: T };
345
+ if (done) break;
346
+ if (writer && typeof writer.ready !== 'undefined') await writer.ready;
347
+ if (writer && typeof writer.write === 'function') {
348
+ await writer.write(value);
349
+ } else if (dest && typeof dest.write === 'function') {
350
+ dest.write(value);
351
+ }
352
+ }
353
+ } finally {
354
+ try {
355
+ reader.releaseLock();
356
+ } catch {
357
+ /* ignore */
358
+ }
359
+ }
360
+ if (!preventClose) {
361
+ if (writer && typeof writer.close === 'function') await writer.close();
362
+ else if (dest && typeof dest.close === 'function') dest.close();
363
+ }
364
+ } catch (error) {
365
+ if (!preventAbort) {
366
+ try {
367
+ if (writer && typeof writer.abort === 'function') await writer.abort(error);
368
+ else if (dest && typeof dest.abort === 'function') dest.abort(error);
369
+ } catch {
370
+ /* ignore */
371
+ }
372
+ }
373
+ if (!preventCancel) {
374
+ try {
375
+ await this.cancel(error);
376
+ } catch {
377
+ /* ignore */
378
+ }
379
+ }
380
+ throw error;
381
+ } finally {
382
+ if (writer && typeof writer.releaseLock === 'function') {
383
+ try {
384
+ writer.releaseLock();
385
+ } catch {
386
+ /* ignore */
387
+ }
388
+ }
389
+ }
390
+ }
391
+
392
+ async cancel(reason?: unknown): Promise<void> {
393
+ if (this._state.closed || this._state.errored) return;
394
+ this._state.closed = true;
395
+ try {
396
+ if (this._cancelCallback) await this._cancelCallback(reason);
397
+ } finally {
398
+ this._finalizeClose();
399
+ }
400
+ }
401
+
402
+ // --- 内部接口 ----------------------------------------------------------
403
+ _branch(): PolyfillReadableStream<T> {
404
+ const self = this;
405
+ const out = new PolyfillReadableStream<T>({
406
+ start: async (controller: any) => {
407
+ const reader: any = self.getReader();
408
+ try {
409
+ while (true) {
410
+ const { done, value } = await reader.read();
411
+ if (done) break;
412
+ controller.enqueue(value);
413
+ }
414
+ controller.close();
415
+ } catch (e) {
416
+ controller.error(e);
417
+ } finally {
418
+ try {
419
+ reader.releaseLock();
420
+ } catch {
421
+ /* ignore */
422
+ }
423
+ }
424
+ },
425
+ });
426
+ return out;
427
+ }
428
+
429
+ _push(chunk: T) {
430
+ if (this._state.closed || this._state.errored) return;
431
+ if (this._waiting) {
432
+ const resolve = this._waiting;
433
+ this._waiting = null;
434
+ resolve({ done: false, value: chunk });
435
+ this._schedulePullIfNeeded();
436
+ return;
437
+ }
438
+ if (this._byobWaiting) {
439
+ const resolve = this._byobWaiting;
440
+ this._byobWaiting = null;
441
+ resolve(this._buildByobResult(chunk as unknown as ArrayBufferView));
442
+ this._schedulePullIfNeeded();
443
+ return;
444
+ }
445
+ this._chunks.push({ type: 'chunk', value: chunk });
446
+ this._schedulePullIfNeeded();
447
+ }
448
+
449
+ _close() {
450
+ if (this._state.closed || this._state.errored) return;
451
+ this._state.closed = true;
452
+ this._chunks.push({ type: 'close' });
453
+ if (this._waiting) {
454
+ const resolve = this._waiting;
455
+ this._waiting = null;
456
+ resolve({ done: true, value: undefined });
457
+ }
458
+ this._finalizeClose();
459
+ }
460
+
461
+ _error(error: unknown) {
462
+ if (this._state.closed || this._state.errored) return;
463
+ this._state.errored = true;
464
+ this._state.error = error;
465
+ this._chunks.push({ type: 'error', error });
466
+ if (this._waiting) {
467
+ const resolve = this._waiting;
468
+ this._waiting = null;
469
+ resolve(Promise.reject(error) as any);
470
+ }
471
+ this._finalizeClose();
472
+ }
473
+
474
+ _finalizeClose() {
475
+ if (this._reader) this._reader._onClosed();
476
+ if (this._byobReader) this._byobReader._onClosed();
477
+ }
478
+
479
+ _schedulePullIfNeeded() {
480
+ if (this._pullScheduled) return;
481
+ const pull = this._source?.pull;
482
+ if (typeof pull !== 'function') return;
483
+ if (this._state.closed || this._state.errored) return;
484
+ if (this._chunks.length > 0 || this._waiting || this._byobWaiting) return;
485
+ this._pullScheduled = true;
486
+ queueMicrotask(() => {
487
+ this._pullScheduled = false;
488
+ if (this._pulling) return;
489
+ if (this._state.closed || this._state.errored) return;
490
+ this._pulling = true;
491
+ Promise.resolve(pull.call(this._source, this._controller))
492
+ .catch((e: unknown) => this._error(e))
493
+ .finally(() => {
494
+ this._pulling = false;
495
+ });
496
+ });
497
+ }
498
+
499
+ _read(): Promise<R<T>> {
500
+ if (this._state.errored) return Promise.reject(this._state.error);
501
+ if (this._state.closed) return Promise.resolve({ done: true, value: undefined });
502
+ while (this._chunks.length) {
503
+ const item = this._chunks.shift()!;
504
+ if (item.type === 'chunk') {
505
+ this._schedulePullIfNeeded();
506
+ return Promise.resolve({ done: false, value: item.value });
507
+ }
508
+ if (item.type === 'close') {
509
+ return Promise.resolve({ done: true, value: undefined });
510
+ }
511
+ if (item.type === 'error') {
512
+ return Promise.reject(item.error);
513
+ }
514
+ }
515
+ return new Promise<R<T>>((resolve, reject) => {
516
+ this._waiting = (value: R<T>) => {
517
+ if (this._state.errored) reject(this._state.error);
518
+ else resolve(value);
519
+ };
520
+ this._schedulePullIfNeeded();
521
+ });
522
+ }
523
+
524
+ _readInto<T extends ArrayBufferView>(view: T): Promise<ByteR<T>> {
525
+ if (this._state.errored) return Promise.reject(this._state.error);
526
+ if (this._state.closed) return Promise.resolve({ done: true, value: view });
527
+ let written = 0;
528
+ const target = new Uint8Array(view.buffer, view.byteOffset, view.byteLength);
529
+ while (this._chunks.length && written < target.byteLength) {
530
+ const item = this._chunks[0];
531
+ if (item.type === 'chunk') {
532
+ const src = this._toUint8(item.value as unknown as ArrayBufferView);
533
+ const toCopy = Math.min(src.length, target.byteLength - written);
534
+ target.set(src.subarray(0, toCopy), written);
535
+ written += toCopy;
536
+ if (toCopy < src.length) {
537
+ (this._chunks[0] as any).value = src.subarray(toCopy);
538
+ } else {
539
+ this._chunks.shift();
540
+ }
541
+ } else if (item.type === 'close') {
542
+ this._chunks.shift();
543
+ const outView =
544
+ written === 0
545
+ ? view
546
+ : (new DataView(view.buffer, view.byteOffset, written) as unknown as T);
547
+ return Promise.resolve({ done: true, value: (written ? outView : view) as T });
548
+ } else if (item.type === 'error') {
549
+ this._chunks.shift();
550
+ return Promise.reject(item.error);
551
+ }
552
+ }
553
+ if (written > 0) {
554
+ const newView = new DataView(view.buffer, view.byteOffset, written) as unknown as T;
555
+ this._schedulePullIfNeeded();
556
+ return Promise.resolve({ done: false, value: newView });
557
+ }
558
+ return new Promise<ByteR<T>>((resolve, reject) => {
559
+ this._byobWaiting = (res: any) => {
560
+ if (this._state.errored) reject(this._state.error);
561
+ else resolve(res);
562
+ };
563
+ this._schedulePullIfNeeded();
564
+ });
565
+ }
566
+
567
+ _buildByobResult(chunk: ArrayBufferView): any {
568
+ const src = this._toUint8(chunk);
569
+ const out = new Uint8Array(src.length);
570
+ out.set(src);
571
+ return { done: false, value: out };
572
+ }
573
+
574
+ _toUint8(chunk: any): Uint8Array {
575
+ if (chunk instanceof Uint8Array) return chunk;
576
+ if (ArrayBuffer.isView(chunk)) {
577
+ return new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
578
+ }
579
+ if (chunk instanceof ArrayBuffer) return new Uint8Array(chunk);
580
+ if (typeof chunk === 'string') {
581
+ const enc = new TextEncoder();
582
+ return enc.encode(chunk);
583
+ }
584
+ if (Array.isArray(chunk)) return new Uint8Array(chunk);
585
+ return new Uint8Array(0);
586
+ }
587
+ }
588
+
589
+ /* =========================================================
590
+ * 4. WritableStream
591
+ * ========================================================= */
592
+ class PolyfillWritableStreamDefaultWriter<W = any> {
593
+ public readonly closed: Promise<undefined>;
594
+ public readonly ready: Promise<undefined>;
595
+ public readonly desiredSize: number | null = 1;
596
+ private _stream: PolyfillWritableStream<W>;
597
+ private _resolveClosed!: (v: undefined) => void;
598
+ private _resolveReady!: (v: undefined) => void;
599
+ constructor(stream: PolyfillWritableStream<W>) {
600
+ this._stream = stream;
601
+ this._stream._writer = this;
602
+ this.closed = new Promise((res) => {
603
+ this._resolveClosed = res;
604
+ });
605
+ this.ready = new Promise((res) => {
606
+ this._resolveReady = res;
607
+ });
608
+ Promise.resolve().then(() => this._resolveReady(undefined));
609
+ }
610
+ abort(reason?: unknown): Promise<void> {
611
+ return this._stream.abort(reason);
612
+ }
613
+ close(): Promise<void> {
614
+ return this._stream.close();
615
+ }
616
+ releaseLock() {
617
+ if (this._stream._writer === this) this._stream._writer = null;
618
+ }
619
+ write(chunk: W): Promise<void> {
620
+ return this._stream.write(chunk);
621
+ }
622
+ _onClosed() {
623
+ this._resolveClosed(undefined);
624
+ }
625
+ }
626
+
627
+ class PolyfillWritableStream<W = any> {
628
+ public locked = false;
629
+ _writer: PolyfillWritableStreamDefaultWriter<W> | null = null;
630
+ _state: StreamState = { closed: false, errored: false, error: undefined };
631
+ _sink: any = {};
632
+ _controller: any = null;
633
+ constructor(underlyingSink?: any, _strategy?: any) {
634
+ this._sink = underlyingSink ?? {};
635
+ const start = this._sink.start;
636
+ this._controller = {
637
+ error: (e?: unknown) => this._error(e ?? new Error('WritableStream errored')),
638
+ signal: { aborted: false, reason: undefined as unknown },
639
+ };
640
+ if (typeof start === 'function') {
641
+ Promise.resolve(start.call(this._sink, this._controller)).catch((e: unknown) => this._error(e));
642
+ }
643
+ }
644
+ getWriter() {
645
+ if (this._writer) throw new TypeError('WritableStream is locked');
646
+ return new PolyfillWritableStreamDefaultWriter<W>(this);
647
+ }
648
+ async abort(reason?: unknown): Promise<void> {
649
+ if (this._state.closed || this._state.errored) return;
650
+ this._controller.signal.aborted = true;
651
+ this._controller.signal.reason = reason;
652
+ this._state.errored = true;
653
+ this._state.error = reason;
654
+ const abort = this._sink.abort;
655
+ if (typeof abort === 'function') await abort.call(this._sink, reason);
656
+ this._finalize();
657
+ }
658
+ async close(): Promise<void> {
659
+ if (this._state.closed || this._state.errored) return;
660
+ this._state.closed = true;
661
+ const closeFn = this._sink.close;
662
+ if (typeof closeFn === 'function') await closeFn.call(this._sink);
663
+ this._finalize();
664
+ }
665
+ async write(chunk: W): Promise<void> {
666
+ if (this._state.errored) throw this._state.error;
667
+ if (this._state.closed) throw new TypeError('WritableStream is closed');
668
+ const writeFn = this._sink.write;
669
+ if (typeof writeFn === 'function') {
670
+ const result = writeFn.call(this._sink, chunk, this._controller);
671
+ await Promise.resolve(result);
672
+ }
673
+ }
674
+ _finalize() {
675
+ if (this._writer) this._writer._onClosed();
676
+ }
677
+ _error(e: unknown) {
678
+ if (this._state.closed || this._state.errored) return;
679
+ this._state.errored = true;
680
+ this._state.error = e;
681
+ this._finalize();
682
+ }
683
+ }
684
+
685
+ /* =========================================================
686
+ * 5. TransformStream
687
+ * ========================================================= */
688
+ class PolyfillTransformStream<I = any, O = any> {
689
+ public readonly readable: any;
690
+ public readonly writable: any;
691
+ constructor(transformer?: any, _writableStrategy?: any, _readableStrategy?: any) {
692
+ let readableController: any;
693
+ this.readable = new PolyfillReadableStream<O>({
694
+ start: (controller: any) => {
695
+ readableController = controller;
696
+ const startFn = transformer?.start;
697
+ if (typeof startFn === 'function') {
698
+ Promise.resolve(startFn.call(transformer, readableController)).catch((e: unknown) =>
699
+ readableController.error(e)
700
+ );
701
+ }
702
+ },
703
+ });
704
+ this.writable = new PolyfillWritableStream<I>({
705
+ write: async (chunk: I, _controller: any) => {
706
+ const fn = transformer?.transform;
707
+ if (typeof fn === 'function') {
708
+ await Promise.resolve(fn.call(transformer, chunk, readableController));
709
+ } else {
710
+ readableController.enqueue(chunk as unknown as O);
711
+ }
712
+ },
713
+ close: async () => {
714
+ const flush = transformer?.flush;
715
+ if (typeof flush === 'function') {
716
+ await Promise.resolve(flush.call(transformer, readableController));
717
+ }
718
+ readableController.close();
719
+ },
720
+ abort: async (reason: unknown) => {
721
+ readableController.error(reason);
722
+ const abort = transformer?.abort;
723
+ if (typeof abort === 'function') await abort.call(transformer, reason);
724
+ },
725
+ });
726
+ }
727
+ }
728
+
729
+ /* =========================================================
730
+ * 6. TextDecoderStream / TextEncoderStream
731
+ * ========================================================= */
732
+ class PolyfillTextDecoderStream {
733
+ public readonly readable: any;
734
+ public readonly writable: any;
735
+ public readonly encoding: string;
736
+ public readonly fatal: boolean;
737
+ public readonly ignoreBOM: boolean;
738
+ constructor(label?: string, options?: TextDecoderOptions) {
739
+ const decoder = new TextDecoder(label, options);
740
+ this.encoding = decoder.encoding;
741
+ this.fatal = decoder.fatal;
742
+ this.ignoreBOM = decoder.ignoreBOM;
743
+ const ts = new PolyfillTransformStream<ArrayBufferView, string>({
744
+ transform(chunk: ArrayBufferView, controller: any) {
745
+ controller.enqueue(decoder.decode(chunk, { stream: true }));
746
+ },
747
+ flush(controller: any) {
748
+ const tail = decoder.decode();
749
+ if (tail) controller.enqueue(tail);
750
+ },
751
+ });
752
+ this.readable = ts.readable;
753
+ this.writable = ts.writable;
754
+ }
755
+ }
756
+
757
+ class PolyfillTextEncoderStream {
758
+ public readonly readable: any;
759
+ public readonly writable: any;
760
+ public readonly encoding: string = 'utf-8';
761
+ constructor() {
762
+ const encoder = new TextEncoder();
763
+ const ts = new PolyfillTransformStream<string, Uint8Array>({
764
+ transform(chunk: string, controller: any) {
765
+ controller.enqueue(encoder.encode(chunk));
766
+ },
767
+ });
768
+ this.readable = ts.readable;
769
+ this.writable = ts.writable;
770
+ }
771
+ }
772
+
773
+ /* =========================================================
774
+ * 7. 安装:先处理 Safari「半残实现」再按缺失情况挂载
775
+ * ========================================================= */
776
+ function forceDefineOnGlobal(key: string, value: unknown): void {
777
+ const glb = globalThis as any;
778
+ try {
779
+ Object.defineProperty(glb, key, {
780
+ configurable: true,
781
+ writable: true,
782
+ enumerable: false,
783
+ value,
784
+ });
785
+ } catch (_) {
786
+ try { glb[key] = value; } catch (__) { /* skip */ }
787
+ }
788
+ // defineProperty 静默失败兜底
789
+ try { if (glb[key] !== value) glb[key] = value; } catch (_) { /* skip */ }
790
+ }
791
+
792
+ function installIfMissing(key: string, value: unknown) {
793
+ const glb = globalThis as any;
794
+ try {
795
+ if (typeof glb[key] === 'undefined') {
796
+ forceDefineOnGlobal(key, value);
797
+ }
798
+ } catch {
799
+ /* ignore strict-mode redefine errors */
800
+ }
801
+ }
802
+
803
+ /**
804
+ * 老版本 Safari「半残实现」探测器:
805
+ * ReadableStream 作为函数挂在全局,但 ReadableByteStreamController 缺失,
806
+ * 或 new ReadableStream({ type:'bytes' }) / getReader({mode:'byob'}) 直接抛出
807
+ * "ReadableByteStreamController is not implemented"。
808
+ * React 18 renderToReadableStream 会进入 bytes 分支,最终抛截图所示错误。
809
+ * 命中迹象即返回 true,调用方应当整体覆盖 Readable/Writable/TransformStream 三个构造器。
810
+ */
811
+ function detectBrokenWebStreamsImplementation(): boolean {
812
+ try {
813
+ const RS = (globalThis as any).ReadableStream;
814
+ const RBC = (globalThis as any).ReadableByteStreamController;
815
+ const WS = (globalThis as any).WritableStream;
816
+ const TS = (globalThis as any).TransformStream;
817
+ if (typeof RS !== 'function') return false;
818
+
819
+ if (typeof RBC !== 'function') return true;
820
+
821
+ try {
822
+ const src = {
823
+ type: 'bytes' as const,
824
+ start(c: any) { try { c.close(); } catch (_) { /* ignore */ } },
825
+ };
826
+ const tmp: any = new RS(src);
827
+ try {
828
+ const byob = tmp.getReader({ mode: 'byob' as const });
829
+ if (!byob) return true;
830
+ try { byob.releaseLock(); } catch (_) { /* ignore */ }
831
+ } catch (brErr: any) {
832
+ const msg = String(brErr?.message ?? '');
833
+ if (/not implemented|ReadableByteStreamController|byob|not supported|invalid mode/i.test(msg)) return true;
834
+ }
835
+ try { tmp.cancel && tmp.cancel(); } catch (_) { /* ignore */ }
836
+ } catch (e: any) {
837
+ const msg = String(e?.message ?? '');
838
+ if (/ReadableByteStreamController is not implemented|is not implemented|not supported|type bytes|invalid type/i.test(msg)) return true;
839
+ }
840
+
841
+ const proto = RS.prototype;
842
+ if (!proto || typeof proto.pipeTo !== 'function' || typeof proto.pipeThrough !== 'function' || typeof proto.tee !== 'function') {
843
+ if (typeof WS !== 'function') return true;
844
+ }
845
+ if (typeof TS !== 'undefined' && typeof TS !== 'function') return true;
846
+
847
+ return false;
848
+ } catch (_) {
849
+ return false;
850
+ }
851
+ }
852
+
853
+ export function installWebStreamsPolyfill(): void {
854
+ if (typeof globalThis === 'undefined') return;
855
+
856
+ const needsFullOverride = detectBrokenWebStreamsImplementation();
857
+
858
+ if (needsFullOverride) {
859
+ // 整体替换:把 Safari 的半残实现整个清洗掉,用我们的 polyfill 替换
860
+ forceDefineOnGlobal('ReadableStream', PolyfillReadableStream);
861
+ forceDefineOnGlobal('ReadableByteStreamController', PolyfillReadableByteStreamController);
862
+ forceDefineOnGlobal('ReadableStreamDefaultController', PolyfillReadableStreamDefaultController);
863
+ forceDefineOnGlobal('ReadableStreamDefaultReader', PolyfillReadableStreamDefaultReader);
864
+ forceDefineOnGlobal('ReadableStreamBYOBReader', PolyfillReadableStreamBYOBReader);
865
+ forceDefineOnGlobal('WritableStream', PolyfillWritableStream);
866
+ forceDefineOnGlobal('WritableStreamDefaultWriter', PolyfillWritableStreamDefaultWriter);
867
+ forceDefineOnGlobal('TransformStream', PolyfillTransformStream);
868
+ forceDefineOnGlobal('TextDecoderStream', PolyfillTextDecoderStream);
869
+ forceDefineOnGlobal('TextEncoderStream', PolyfillTextEncoderStream);
870
+ forceDefineOnGlobal('ByteLengthQueuingStrategy', ByteLengthQueuingStrategy);
871
+ forceDefineOnGlobal('CountQueuingStrategy', CountQueuingStrategy);
872
+ } else {
873
+ installIfMissing('ByteLengthQueuingStrategy', ByteLengthQueuingStrategy);
874
+ installIfMissing('CountQueuingStrategy', CountQueuingStrategy);
875
+
876
+ installIfMissing('ReadableStream', PolyfillReadableStream);
877
+ installIfMissing('WritableStream', PolyfillWritableStream);
878
+ installIfMissing('TransformStream', PolyfillTransformStream);
879
+
880
+ installIfMissing('ReadableByteStreamController', PolyfillReadableByteStreamController);
881
+ installIfMissing('ReadableStreamDefaultController', PolyfillReadableStreamDefaultController);
882
+ installIfMissing('ReadableStreamDefaultReader', PolyfillReadableStreamDefaultReader);
883
+ installIfMissing('ReadableStreamBYOBReader', PolyfillReadableStreamBYOBReader);
884
+ installIfMissing('WritableStreamDefaultWriter', PolyfillWritableStreamDefaultWriter);
885
+
886
+ installIfMissing('TextDecoderStream', PolyfillTextDecoderStream);
887
+ installIfMissing('TextEncoderStream', PolyfillTextEncoderStream);
888
+ }
889
+
890
+ // 浏览器自带 ReadableStream 但原型上没有 pipeTo(极个别老版本)
891
+ try {
892
+ const GlbReadable = (globalThis as any).ReadableStream;
893
+ if (typeof GlbReadable === 'function') {
894
+ const proto = GlbReadable.prototype;
895
+ if (proto && typeof proto.pipeTo !== 'function') {
896
+ Object.defineProperty(proto, 'pipeTo', {
897
+ configurable: true,
898
+ writable: true,
899
+ value: PolyfillReadableStream.prototype.pipeTo,
900
+ });
901
+ Object.defineProperty(proto, 'pipeThrough', {
902
+ configurable: true,
903
+ writable: true,
904
+ value: PolyfillReadableStream.prototype.pipeThrough,
905
+ });
906
+ Object.defineProperty(proto, 'tee', {
907
+ configurable: true,
908
+ writable: true,
909
+ value: PolyfillReadableStream.prototype.tee,
910
+ });
911
+ }
912
+ }
913
+ } catch {
914
+ /* ignore */
915
+ }
916
+ }
917
+
918
+ /**
919
+ * 立即尝试安装。
920
+ * 严格遵循 Lessons Learned:不触碰 Promise / Generator 原型,
921
+ * 从而避免与 React dispatcher 冲突。
922
+ */
923
+ try {
924
+ installWebStreamsPolyfill();
925
+ } catch (e) {
926
+
927
+ console.warn('[polyfills] 安装 Web Streams polyfill 失败:', e);
928
+ }