@powerhousedao/connect 1.0.0-dev.220 → 1.0.0-dev.222

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 (247) hide show
  1. package/dist/assets/ArrowFilledRight-64XHqK_h.js +7 -0
  2. package/dist/assets/ArrowLeft-cTTfZFZ1.js +7 -0
  3. package/dist/assets/ArrowUp-DZrDe-Bp.js +7 -0
  4. package/dist/assets/BarChart-DT4puBXm.js +7 -0
  5. package/dist/assets/BaseArrowLeft-G433oBpP.js +7 -0
  6. package/dist/assets/BaseArrowRight-cpxwDGIe.js +7 -0
  7. package/dist/assets/Braces-CJktWttT.js +7 -0
  8. package/dist/assets/Branch-iPu-a2T3.js +7 -0
  9. package/dist/assets/BrickGlobe-BZrrYdL4.js +7 -0
  10. package/dist/assets/Briefcase-XpuJYuUR.js +7 -0
  11. package/dist/assets/Calendar-Dt0VwGrR.js +7 -0
  12. package/dist/assets/CalendarTime-CwwzsmKX.js +7 -0
  13. package/dist/assets/Caret-ZEgiNBNU.js +7 -0
  14. package/dist/assets/CaretDown-DP6bOwI2.js +7 -0
  15. package/dist/assets/CaretLeft-BD_N0UUw.js +7 -0
  16. package/dist/assets/CaretRight-DWPoTF9X.js +7 -0
  17. package/dist/assets/CaretSort-Bw0XHsjI.js +7 -0
  18. package/dist/assets/Check-cqhfhLxP.js +7 -0
  19. package/dist/assets/CheckCircle-DH9iEyZM.js +7 -0
  20. package/dist/assets/CheckCircleFill-DXFYGKQ5.js +7 -0
  21. package/dist/assets/Checkmark-9n4byVGp.js +7 -0
  22. package/dist/assets/ChevronDown-DvTsRsq2.js +7 -0
  23. package/dist/assets/Circle-B2Lns-7w.js +7 -0
  24. package/dist/assets/CircleInfo-1kjSg19s.js +7 -0
  25. package/dist/assets/Clock-BGRQRM60.js +7 -0
  26. package/dist/assets/ClockFill-Bvmknv7u.js +7 -0
  27. package/dist/assets/CloudSlash-DPvYwLm3.js +7 -0
  28. package/dist/assets/Collapse-D5jXkhQz.js +7 -0
  29. package/dist/assets/Connect-DZiPc2IO.js +7 -0
  30. package/dist/assets/ConnectSmall-C4hYVYQO.js +7 -0
  31. package/dist/assets/Copy-CoVU9BJY.js +7 -0
  32. package/dist/assets/Created-DzIi8Oqs.js +7 -0
  33. package/dist/assets/CrossCircle-Cz9Xbcsr.js +7 -0
  34. package/dist/assets/Danger-DkDnPFWT.js +7 -0
  35. package/dist/assets/Discord-C9rQaS93.js +7 -0
  36. package/dist/assets/Drive-gptzvasW.js +7 -0
  37. package/dist/assets/Duplicated-C2v6xG93.js +7 -0
  38. package/dist/assets/Edit-BWdYDo8C.js +7 -0
  39. package/dist/assets/Ellipsis-_Yp_-wDZ.js +7 -0
  40. package/dist/assets/Error-Bf2pG8sD.js +7 -0
  41. package/dist/assets/Exclamation-DLUhwcPI.js +7 -0
  42. package/dist/assets/File-C3wkPB_r.js +7 -0
  43. package/dist/assets/FilesEarmark-CgUelQay.js +7 -0
  44. package/dist/assets/FolderClose-BvAQd6IG.js +7 -0
  45. package/dist/assets/FolderOpen-Bma1Ngbb.js +7 -0
  46. package/dist/assets/FolderPlus-Dn00AVa8.js +7 -0
  47. package/dist/assets/Forum-C-dTIstS.js +7 -0
  48. package/dist/assets/Gear-B58aepsd.js +7 -0
  49. package/dist/assets/Github-YaYviWSS.js +7 -0
  50. package/dist/assets/Globe-BGlyCRpD.js +7 -0
  51. package/dist/assets/GlobeWww-B1pUKxRP.js +7 -0
  52. package/dist/assets/Hdd-Bk7BpLL-.js +7 -0
  53. package/dist/assets/History-CDfNjY3P.js +7 -0
  54. package/dist/assets/InfoSquare-CLtlquCL.js +7 -0
  55. package/dist/assets/Link-BHshUK_k.js +7 -0
  56. package/dist/assets/Linkedin-BSk0sey6.js +7 -0
  57. package/dist/assets/Lock-BFCeokdp.js +7 -0
  58. package/dist/assets/M-V6iG_x6o.js +7 -0
  59. package/dist/assets/Modified-D04FuhUt.js +7 -0
  60. package/dist/assets/Moved-D3mS-uot.js +7 -0
  61. package/dist/assets/PackageManager-1Wpl0DVS.js +7 -0
  62. package/dist/assets/Pencil-aiwjx26f.js +7 -0
  63. package/dist/assets/People-CgDbL4kS.js +7 -0
  64. package/dist/assets/PeopleFill-CUgqKMA4.js +7 -0
  65. package/dist/assets/Person-B0cfH7KV.js +7 -0
  66. package/dist/assets/Pin-CeMtNsZD.js +7 -0
  67. package/dist/assets/PinFilled-DsQqlbF3.js +7 -0
  68. package/dist/assets/Plus-CtnpCWqG.js +7 -0
  69. package/dist/assets/PlusCircle-BOEotEGi.js +7 -0
  70. package/dist/assets/PlusSquare-fWkZh3-r.js +7 -0
  71. package/dist/assets/PowerhouseLogoSmall-CgaHbPzx.js +7 -0
  72. package/dist/assets/Project-D33G_Tlb.js +7 -0
  73. package/dist/assets/QuestionSquare-Cilqw-NF.js +7 -0
  74. package/dist/assets/RedoArrow-BZg6K-nT.js +7 -0
  75. package/dist/assets/Reload-DSYHnfCV.js +7 -0
  76. package/dist/assets/Removed-B35cyBgu.js +7 -0
  77. package/dist/assets/Renown-DdF-DRzW.js +7 -0
  78. package/dist/assets/RenownHover-ayMKqS2y.js +7 -0
  79. package/dist/assets/Ring-DDC_wea5.js +7 -0
  80. package/dist/assets/Save-BqsDjvWT.js +7 -0
  81. package/dist/assets/Search-BmJu6qh2.js +7 -0
  82. package/dist/assets/Server-BsTH0P96.js +7 -0
  83. package/dist/assets/Settings-wzKf1ItW.js +7 -0
  84. package/dist/assets/Synced-BREnp3Gk.js +7 -0
  85. package/dist/assets/Syncing-oLFcuSQr.js +7 -0
  86. package/dist/assets/Tabler-Dd4wGhvu.js +7 -0
  87. package/dist/assets/Trash-C2Az1OA8.js +7 -0
  88. package/dist/assets/TrashFill-Cop-3QYY.js +7 -0
  89. package/dist/assets/TreeViewSlash-C5vFO1Yq.js +7 -0
  90. package/dist/assets/TriangleDown-BJdJslsa.js +7 -0
  91. package/dist/assets/VariantArrowLeft-DfAacH04.js +7 -0
  92. package/dist/assets/VerticalDots-B4dDMl7Z.js +7 -0
  93. package/dist/assets/WarningFill-Drxpmg7X.js +7 -0
  94. package/dist/assets/XTwitter-C0dxLb5W.js +7 -0
  95. package/dist/assets/Xmark-DZtv823K.js +7 -0
  96. package/dist/assets/XmarkLight-BYzxLa1T.js +7 -0
  97. package/dist/assets/Youtube-DnhnDSfB.js +7 -0
  98. package/dist/assets/{app-oYMmxEg4.js → app-BUiL0TO6.js} +58823 -60583
  99. package/dist/assets/app-Cln9uYMI.css +1242 -0
  100. package/dist/assets/app-loader-BY0bGSIq.css +5397 -0
  101. package/dist/assets/app-loader-Co6VFBhx.js +31007 -0
  102. package/dist/assets/{ccip-BvX6f5m7.js → ccip-BiEYPCqN.js} +8 -5
  103. package/dist/assets/connect-loader-CvOC68Ih.mp4 +0 -0
  104. package/dist/assets/content-BlSrA1gF.js +3907 -0
  105. package/dist/assets/home-bg-BEhF9NuW.png +0 -0
  106. package/dist/assets/{index-WXoiV0zm.js → index-C3PHLsWB.js} +3 -3
  107. package/dist/assets/{index-t8f2apK5.js → index-DDSSN5k1.js} +4 -7
  108. package/dist/assets/{index-CxJ1Vq_H.js → index-w8HBb0gA.js} +278 -41
  109. package/dist/assets/{main.CDMuibNl.js → main.CvO2RTHM.js} +1 -1
  110. package/dist/assets/powerhouse-rounded-CeKGGUG4.png +0 -0
  111. package/dist/assets/renown-short-hover-BiSLBV7L.png +0 -0
  112. package/dist/assets/rwa-report-Bb0W5-ac.png +0 -0
  113. package/dist/assets/style-CQ-MDl3w.css +1662 -0
  114. package/dist/assets/types-b4BfZ8ti.js +102 -0
  115. package/dist/hmr.js +1 -8
  116. package/dist/index.html +1 -1
  117. package/dist/modules/@powerhousedao/reactor-browser/{chunk-LHXH5HR7.js → chunk-AF3TNTAG.js} +1 -1
  118. package/dist/modules/@powerhousedao/reactor-browser/{chunk-5BAZISS7.js → chunk-IFKFX4E7.js} +2 -2
  119. package/dist/modules/@powerhousedao/reactor-browser/{chunk-VIGH2HV7.js → chunk-IQTSFTNF.js} +1 -1
  120. package/dist/modules/@powerhousedao/reactor-browser/{chunk-MT6QXFYC.js → chunk-KDBDV2ML.js} +57 -25
  121. package/dist/modules/@powerhousedao/reactor-browser/{chunk-JMVGM43L.js → chunk-LRNZZ3SR.js} +1 -1
  122. package/dist/modules/@powerhousedao/reactor-browser/{chunk-PVRRQHLK.js → chunk-OS3WZ4EZ.js} +1 -1
  123. package/dist/modules/@powerhousedao/reactor-browser/{chunk-OZHQMTGT.js → chunk-R3DNAUCO.js} +1 -1
  124. package/dist/modules/@powerhousedao/reactor-browser/{chunk-N6IPBMAU.js → chunk-Y7NTRTMT.js} +1 -1
  125. package/dist/modules/@powerhousedao/reactor-browser/{chunk-6FYOYIRO.js → chunk-YBWJLG4N.js} +2 -3
  126. package/dist/modules/@powerhousedao/reactor-browser/context/index.js +3 -3
  127. package/dist/modules/@powerhousedao/reactor-browser/context/read-mode.js +3 -3
  128. package/dist/modules/@powerhousedao/reactor-browser/document-model.js +2 -2
  129. package/dist/modules/@powerhousedao/reactor-browser/hooks/index.js +6 -6
  130. package/dist/modules/@powerhousedao/reactor-browser/hooks/useDocumentEditor.js +3 -3
  131. package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActions.js +3 -3
  132. package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActionsWithUiNodes.js +4 -4
  133. package/dist/modules/@powerhousedao/reactor-browser/index.js +10 -10
  134. package/dist/modules/@powerhousedao/reactor-browser/reactor.js +3 -3
  135. package/dist/modules/@powerhousedao/reactor-browser/utils/export-document.js +2 -2
  136. package/dist/modules/@powerhousedao/reactor-browser/utils/signature.js +2 -2
  137. package/dist/vite-envs.sh +1 -1
  138. package/package.json +22 -26
  139. package/scripts/install-packages.js +9 -0
  140. package/dist/assets/ArrowFilledRight-DR0hNbwn.js +0 -7
  141. package/dist/assets/ArrowLeft-B0Xj8PvP.js +0 -15
  142. package/dist/assets/ArrowUp-CwtCJqy6.js +0 -7
  143. package/dist/assets/BarChart-nVfxphhs.js +0 -7
  144. package/dist/assets/BaseArrowLeft-C8cn--_E.js +0 -7
  145. package/dist/assets/BaseArrowRight-D3q0C2-y.js +0 -7
  146. package/dist/assets/Braces-B9gXulWt.js +0 -17
  147. package/dist/assets/Branch-DWau4RYZ.js +0 -7
  148. package/dist/assets/BrickGlobe-Dz0dBSi2.js +0 -7
  149. package/dist/assets/Briefcase-CvO1rhlH.js +0 -7
  150. package/dist/assets/Calendar-BUcLO8hE.js +0 -7
  151. package/dist/assets/CalendarTime-DPWILM_L.js +0 -27
  152. package/dist/assets/Caret-DhnOHiAk.js +0 -7
  153. package/dist/assets/CaretDown-Dlfvehxg.js +0 -14
  154. package/dist/assets/CaretLeft-a4NLMV88.js +0 -27
  155. package/dist/assets/CaretRight-B5YZKpzX.js +0 -27
  156. package/dist/assets/CaretSort-Ct9KtNAH.js +0 -14
  157. package/dist/assets/Check-DFFCZvyb.js +0 -7
  158. package/dist/assets/CheckCircle-D0cadyWB.js +0 -23
  159. package/dist/assets/CheckCircleFill-D9omvoi2.js +0 -7
  160. package/dist/assets/Checkmark-B9Fhan_U.js +0 -14
  161. package/dist/assets/ChevronDown-C2q5ewWu.js +0 -15
  162. package/dist/assets/Circle-DvbXQBRR.js +0 -7
  163. package/dist/assets/CircleInfo-B-ZX0ilU.js +0 -40
  164. package/dist/assets/Clock-DZfefmeN.js +0 -26
  165. package/dist/assets/ClockFill-CABo21fb.js +0 -7
  166. package/dist/assets/CloudSlash-CMWY3Yiz.js +0 -7
  167. package/dist/assets/Collapse-B6so4C4x.js +0 -7
  168. package/dist/assets/Connect-BwTXbdDU.js +0 -16
  169. package/dist/assets/ConnectSmall-QnqlDdXI.js +0 -24
  170. package/dist/assets/Copy-B6zR-spv.js +0 -14
  171. package/dist/assets/Created-DFpCpnA0.js +0 -30
  172. package/dist/assets/CrossCircle-CqWwlop8.js +0 -27
  173. package/dist/assets/Danger-pz0IZ9ht.js +0 -18
  174. package/dist/assets/Discord-BBOYl-Cv.js +0 -31
  175. package/dist/assets/Drive-U3vNMpII.js +0 -7
  176. package/dist/assets/Duplicated-8BQyTQTq.js +0 -39
  177. package/dist/assets/Edit-Csq3Kjo4.js +0 -17
  178. package/dist/assets/Ellipsis-9SpKcRLu.js +0 -7
  179. package/dist/assets/Error-Aw8n4vvA.js +0 -7
  180. package/dist/assets/Exclamation-BrTZuGoh.js +0 -10
  181. package/dist/assets/File-CZLnU7sR.js +0 -24
  182. package/dist/assets/FilesEarmark-BFvgl_Tg.js +0 -7
  183. package/dist/assets/FolderClose-CKAhNitU.js +0 -13
  184. package/dist/assets/FolderOpen-BeUyXyGp.js +0 -7
  185. package/dist/assets/FolderPlus-vsjvCtD1.js +0 -7
  186. package/dist/assets/Forum-D9m-5WTT.js +0 -22
  187. package/dist/assets/Gear-yPrII5SD.js +0 -7
  188. package/dist/assets/Github-CD-46ylo.js +0 -24
  189. package/dist/assets/Globe-31ZjNNZd.js +0 -7
  190. package/dist/assets/GlobeWww-NUl-mssK.js +0 -22
  191. package/dist/assets/Hdd-iEstELlC.js +0 -7
  192. package/dist/assets/History-Bqbk20Zf.js +0 -7
  193. package/dist/assets/InfoSquare-PvIdwYp_.js +0 -7
  194. package/dist/assets/Link-CkpgSxML.js +0 -14
  195. package/dist/assets/Linkedin-CwtjXXnu.js +0 -22
  196. package/dist/assets/Lock-iwF_5hIn.js +0 -7
  197. package/dist/assets/M-JPfHvUlx.js +0 -22
  198. package/dist/assets/Modified-DJa3zTii.js +0 -29
  199. package/dist/assets/Moved-Bj3ueg6N.js +0 -42
  200. package/dist/assets/PackageManager-ByYYO-CH.js +0 -17
  201. package/dist/assets/Pencil-B5DNXkv2.js +0 -7
  202. package/dist/assets/People-DWpcpRpZ.js +0 -7
  203. package/dist/assets/PeopleFill-BxcdOZRn.js +0 -23
  204. package/dist/assets/Person-Dd4QCiac.js +0 -7
  205. package/dist/assets/Pin-DSN6BBS6.js +0 -24
  206. package/dist/assets/PinFilled-Du7ciT8p.js +0 -35
  207. package/dist/assets/Plus-dRXu8yLK.js +0 -7
  208. package/dist/assets/PlusCircle-kj00UDxx.js +0 -7
  209. package/dist/assets/PlusSquare-CASzVJ_x.js +0 -24
  210. package/dist/assets/PowerhouseLogoSmall-C7rkb4Ku.js +0 -14
  211. package/dist/assets/Project-BLYGn5jD.js +0 -7
  212. package/dist/assets/QuestionSquare-hGUPKN7o.js +0 -17
  213. package/dist/assets/RedoArrow-C1UsCGGt.js +0 -7
  214. package/dist/assets/Reload-Clzg07Z8.js +0 -14
  215. package/dist/assets/Removed-BdJpuaHB.js +0 -29
  216. package/dist/assets/Renown-BQJirg5w.js +0 -15
  217. package/dist/assets/RenownHover-CIsVCjKE.js +0 -21
  218. package/dist/assets/Ring-BnzZk41B.js +0 -7
  219. package/dist/assets/Save-DB-qMoQ6.js +0 -7
  220. package/dist/assets/Search-C4fgASd0.js +0 -7
  221. package/dist/assets/Server-DdLkUTUf.js +0 -7
  222. package/dist/assets/Settings-XVLcCNRw.js +0 -24
  223. package/dist/assets/Synced-Dp7j8Wr1.js +0 -7
  224. package/dist/assets/Syncing-B3eGgW4P.js +0 -7
  225. package/dist/assets/Tabler-Dv8tnKMX.js +0 -39
  226. package/dist/assets/Trash-GSQzjB0i.js +0 -7
  227. package/dist/assets/TrashFill-D7pcPl3s.js +0 -7
  228. package/dist/assets/TreeViewSlash-vQKVapHr.js +0 -43
  229. package/dist/assets/TriangleDown-eodKDfJJ.js +0 -25
  230. package/dist/assets/VariantArrowLeft-DMEp2hza.js +0 -7
  231. package/dist/assets/VerticalDots-BKEnBm9D.js +0 -7
  232. package/dist/assets/WarningFill-CDTwbvyA.js +0 -7
  233. package/dist/assets/XTwitter-BT5khtsS.js +0 -22
  234. package/dist/assets/Xmark-D0fieu2C.js +0 -14
  235. package/dist/assets/XmarkLight-XhDqUkWV.js +0 -7
  236. package/dist/assets/Youtube-CN2M5XHi.js +0 -24
  237. package/dist/assets/app-loader-BeDENjt_.js +0 -2850
  238. package/dist/assets/app-loader-DaEnUcee.css +0 -1585
  239. package/dist/assets/browser-CXOATk-i.js +0 -21739
  240. package/dist/assets/browser-DZJ42QJ_.js +0 -69
  241. package/dist/assets/content-Dx5DTk0e.js +0 -7631
  242. package/dist/assets/getEnsName-DNB1jgXF.js +0 -3736
  243. package/dist/assets/isAddressEqual-DocwgR-l.js +0 -11
  244. package/dist/assets/react-error-boundary.esm-CWMHErCn.js +0 -927
  245. package/dist/assets/root-CxkOZa6M.js +0 -788
  246. package/dist/assets/router-kNHA756e.js +0 -637
  247. /package/dist/modules/@powerhousedao/reactor-browser/{chunk-VPFTIVBD.js → chunk-FQF4YAVC.js} +0 -0
@@ -1,2850 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/app-oYMmxEg4.js","assets/main.CDMuibNl.js"])))=>i.map(i=>d[i]);
2
- var __defProp = Object.defineProperty;
3
- var __typeError = (msg) => {
4
- throw TypeError(msg);
5
- };
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
9
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
10
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
11
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
12
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
13
- var _tags, _levelString, _errorHandler, _ConsoleLogger_instances, levelValue_get, _ServiceWorkerManager_instances, handleServiceWorkerMessage_fn, handleServiceWorker_fn;
14
- import { _ as __vitePreload } from "./main.CDMuibNl.js";
15
- import { jsx } from "react/jsx-runtime";
16
- import { Suspense, lazy } from "react";
17
- const isString = (obj) => typeof obj === "string";
18
- const defer = () => {
19
- let res;
20
- let rej;
21
- const promise = new Promise((resolve, reject) => {
22
- res = resolve;
23
- rej = reject;
24
- });
25
- promise.resolve = res;
26
- promise.reject = rej;
27
- return promise;
28
- };
29
- const makeString = (object) => {
30
- if (object == null) return "";
31
- return "" + object;
32
- };
33
- const copy = (a, s2, t2) => {
34
- a.forEach((m) => {
35
- if (s2[m]) t2[m] = s2[m];
36
- });
37
- };
38
- const lastOfPathSeparatorRegExp = /###/g;
39
- const cleanKey = (key) => key && key.indexOf("###") > -1 ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
40
- const canNotTraverseDeeper = (object) => !object || isString(object);
41
- const getLastOfPath = (object, path, Empty) => {
42
- const stack = !isString(path) ? path : path.split(".");
43
- let stackIndex = 0;
44
- while (stackIndex < stack.length - 1) {
45
- if (canNotTraverseDeeper(object)) return {};
46
- const key = cleanKey(stack[stackIndex]);
47
- if (!object[key] && Empty) object[key] = new Empty();
48
- if (Object.prototype.hasOwnProperty.call(object, key)) {
49
- object = object[key];
50
- } else {
51
- object = {};
52
- }
53
- ++stackIndex;
54
- }
55
- if (canNotTraverseDeeper(object)) return {};
56
- return {
57
- obj: object,
58
- k: cleanKey(stack[stackIndex])
59
- };
60
- };
61
- const setPath = (object, path, newValue) => {
62
- const {
63
- obj,
64
- k
65
- } = getLastOfPath(object, path, Object);
66
- if (obj !== void 0 || path.length === 1) {
67
- obj[k] = newValue;
68
- return;
69
- }
70
- let e = path[path.length - 1];
71
- let p = path.slice(0, path.length - 1);
72
- let last = getLastOfPath(object, p, Object);
73
- while (last.obj === void 0 && p.length) {
74
- e = `${p[p.length - 1]}.${e}`;
75
- p = p.slice(0, p.length - 1);
76
- last = getLastOfPath(object, p, Object);
77
- if (last && last.obj && typeof last.obj[`${last.k}.${e}`] !== "undefined") {
78
- last.obj = void 0;
79
- }
80
- }
81
- last.obj[`${last.k}.${e}`] = newValue;
82
- };
83
- const pushPath = (object, path, newValue, concat) => {
84
- const {
85
- obj,
86
- k
87
- } = getLastOfPath(object, path, Object);
88
- obj[k] = obj[k] || [];
89
- obj[k].push(newValue);
90
- };
91
- const getPath = (object, path) => {
92
- const {
93
- obj,
94
- k
95
- } = getLastOfPath(object, path);
96
- if (!obj) return void 0;
97
- return obj[k];
98
- };
99
- const getPathWithDefaults = (data, defaultData, key) => {
100
- const value = getPath(data, key);
101
- if (value !== void 0) {
102
- return value;
103
- }
104
- return getPath(defaultData, key);
105
- };
106
- const deepExtend = (target, source, overwrite) => {
107
- for (const prop in source) {
108
- if (prop !== "__proto__" && prop !== "constructor") {
109
- if (prop in target) {
110
- if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
111
- if (overwrite) target[prop] = source[prop];
112
- } else {
113
- deepExtend(target[prop], source[prop], overwrite);
114
- }
115
- } else {
116
- target[prop] = source[prop];
117
- }
118
- }
119
- }
120
- return target;
121
- };
122
- const regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
123
- var _entityMap = {
124
- "&": "&amp;",
125
- "<": "&lt;",
126
- ">": "&gt;",
127
- '"': "&quot;",
128
- "'": "&#39;",
129
- "/": "&#x2F;"
130
- };
131
- const escape = (data) => {
132
- if (isString(data)) {
133
- return data.replace(/[&<>"'\/]/g, (s2) => _entityMap[s2]);
134
- }
135
- return data;
136
- };
137
- class RegExpCache {
138
- constructor(capacity) {
139
- this.capacity = capacity;
140
- this.regExpMap = /* @__PURE__ */ new Map();
141
- this.regExpQueue = [];
142
- }
143
- getRegExp(pattern) {
144
- const regExpFromCache = this.regExpMap.get(pattern);
145
- if (regExpFromCache !== void 0) {
146
- return regExpFromCache;
147
- }
148
- const regExpNew = new RegExp(pattern);
149
- if (this.regExpQueue.length === this.capacity) {
150
- this.regExpMap.delete(this.regExpQueue.shift());
151
- }
152
- this.regExpMap.set(pattern, regExpNew);
153
- this.regExpQueue.push(pattern);
154
- return regExpNew;
155
- }
156
- }
157
- const chars = [" ", ",", "?", "!", ";"];
158
- const looksLikeObjectPathRegExpCache = new RegExpCache(20);
159
- const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
160
- nsSeparator = nsSeparator || "";
161
- keySeparator = keySeparator || "";
162
- const possibleChars = chars.filter((c) => nsSeparator.indexOf(c) < 0 && keySeparator.indexOf(c) < 0);
163
- if (possibleChars.length === 0) return true;
164
- const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
165
- let matched = !r.test(key);
166
- if (!matched) {
167
- const ki = key.indexOf(keySeparator);
168
- if (ki > 0 && !r.test(key.substring(0, ki))) {
169
- matched = true;
170
- }
171
- }
172
- return matched;
173
- };
174
- const deepFind = function(obj, path) {
175
- let keySeparator = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ".";
176
- if (!obj) return void 0;
177
- if (obj[path]) return obj[path];
178
- const tokens = path.split(keySeparator);
179
- let current = obj;
180
- for (let i = 0; i < tokens.length; ) {
181
- if (!current || typeof current !== "object") {
182
- return void 0;
183
- }
184
- let next;
185
- let nextPath = "";
186
- for (let j = i; j < tokens.length; ++j) {
187
- if (j !== i) {
188
- nextPath += keySeparator;
189
- }
190
- nextPath += tokens[j];
191
- next = current[nextPath];
192
- if (next !== void 0) {
193
- if (["string", "number", "boolean"].indexOf(typeof next) > -1 && j < tokens.length - 1) {
194
- continue;
195
- }
196
- i += j - i + 1;
197
- break;
198
- }
199
- }
200
- current = next;
201
- }
202
- return current;
203
- };
204
- const getCleanedCode = (code) => code && code.replace("_", "-");
205
- const consoleLogger = {
206
- type: "logger",
207
- log(args) {
208
- this.output("log", args);
209
- },
210
- warn(args) {
211
- this.output("warn", args);
212
- },
213
- error(args) {
214
- this.output("error", args);
215
- },
216
- output(type2, args) {
217
- if (console && console[type2]) console[type2].apply(console, args);
218
- }
219
- };
220
- class Logger {
221
- constructor(concreteLogger) {
222
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
223
- this.init(concreteLogger, options);
224
- }
225
- init(concreteLogger) {
226
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
227
- this.prefix = options.prefix || "i18next:";
228
- this.logger = concreteLogger || consoleLogger;
229
- this.options = options;
230
- this.debug = options.debug;
231
- }
232
- log() {
233
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
234
- args[_key] = arguments[_key];
235
- }
236
- return this.forward(args, "log", "", true);
237
- }
238
- warn() {
239
- for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
240
- args[_key2] = arguments[_key2];
241
- }
242
- return this.forward(args, "warn", "", true);
243
- }
244
- error() {
245
- for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
246
- args[_key3] = arguments[_key3];
247
- }
248
- return this.forward(args, "error", "");
249
- }
250
- deprecate() {
251
- for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
252
- args[_key4] = arguments[_key4];
253
- }
254
- return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
255
- }
256
- forward(args, lvl, prefix, debugOnly) {
257
- if (debugOnly && !this.debug) return null;
258
- if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
259
- return this.logger[lvl](args);
260
- }
261
- create(moduleName) {
262
- return new Logger(this.logger, {
263
- ...{
264
- prefix: `${this.prefix}:${moduleName}:`
265
- },
266
- ...this.options
267
- });
268
- }
269
- clone(options) {
270
- options = options || this.options;
271
- options.prefix = options.prefix || this.prefix;
272
- return new Logger(this.logger, options);
273
- }
274
- }
275
- var baseLogger = new Logger();
276
- class EventEmitter {
277
- constructor() {
278
- this.observers = {};
279
- }
280
- on(events, listener) {
281
- events.split(" ").forEach((event) => {
282
- if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
283
- const numListeners = this.observers[event].get(listener) || 0;
284
- this.observers[event].set(listener, numListeners + 1);
285
- });
286
- return this;
287
- }
288
- off(event, listener) {
289
- if (!this.observers[event]) return;
290
- if (!listener) {
291
- delete this.observers[event];
292
- return;
293
- }
294
- this.observers[event].delete(listener);
295
- }
296
- emit(event) {
297
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
298
- args[_key - 1] = arguments[_key];
299
- }
300
- if (this.observers[event]) {
301
- const cloned = Array.from(this.observers[event].entries());
302
- cloned.forEach((_ref) => {
303
- let [observer, numTimesAdded] = _ref;
304
- for (let i = 0; i < numTimesAdded; i++) {
305
- observer(...args);
306
- }
307
- });
308
- }
309
- if (this.observers["*"]) {
310
- const cloned = Array.from(this.observers["*"].entries());
311
- cloned.forEach((_ref2) => {
312
- let [observer, numTimesAdded] = _ref2;
313
- for (let i = 0; i < numTimesAdded; i++) {
314
- observer.apply(observer, [event, ...args]);
315
- }
316
- });
317
- }
318
- }
319
- }
320
- class ResourceStore extends EventEmitter {
321
- constructor(data) {
322
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
323
- ns: ["translation"],
324
- defaultNS: "translation"
325
- };
326
- super();
327
- this.data = data || {};
328
- this.options = options;
329
- if (this.options.keySeparator === void 0) {
330
- this.options.keySeparator = ".";
331
- }
332
- if (this.options.ignoreJSONStructure === void 0) {
333
- this.options.ignoreJSONStructure = true;
334
- }
335
- }
336
- addNamespaces(ns) {
337
- if (this.options.ns.indexOf(ns) < 0) {
338
- this.options.ns.push(ns);
339
- }
340
- }
341
- removeNamespaces(ns) {
342
- const index = this.options.ns.indexOf(ns);
343
- if (index > -1) {
344
- this.options.ns.splice(index, 1);
345
- }
346
- }
347
- getResource(lng, ns, key) {
348
- let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
349
- const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
350
- const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
351
- let path;
352
- if (lng.indexOf(".") > -1) {
353
- path = lng.split(".");
354
- } else {
355
- path = [lng, ns];
356
- if (key) {
357
- if (Array.isArray(key)) {
358
- path.push(...key);
359
- } else if (isString(key) && keySeparator) {
360
- path.push(...key.split(keySeparator));
361
- } else {
362
- path.push(key);
363
- }
364
- }
365
- }
366
- const result = getPath(this.data, path);
367
- if (!result && !ns && !key && lng.indexOf(".") > -1) {
368
- lng = path[0];
369
- ns = path[1];
370
- key = path.slice(2).join(".");
371
- }
372
- if (result || !ignoreJSONStructure || !isString(key)) return result;
373
- return deepFind(this.data && this.data[lng] && this.data[lng][ns], key, keySeparator);
374
- }
375
- addResource(lng, ns, key, value) {
376
- let options = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
377
- silent: false
378
- };
379
- const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
380
- let path = [lng, ns];
381
- if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
382
- if (lng.indexOf(".") > -1) {
383
- path = lng.split(".");
384
- value = ns;
385
- ns = path[1];
386
- }
387
- this.addNamespaces(ns);
388
- setPath(this.data, path, value);
389
- if (!options.silent) this.emit("added", lng, ns, key, value);
390
- }
391
- addResources(lng, ns, resources2) {
392
- let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {
393
- silent: false
394
- };
395
- for (const m in resources2) {
396
- if (isString(resources2[m]) || Array.isArray(resources2[m])) this.addResource(lng, ns, m, resources2[m], {
397
- silent: true
398
- });
399
- }
400
- if (!options.silent) this.emit("added", lng, ns, resources2);
401
- }
402
- addResourceBundle(lng, ns, resources2, deep, overwrite) {
403
- let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {
404
- silent: false,
405
- skipCopy: false
406
- };
407
- let path = [lng, ns];
408
- if (lng.indexOf(".") > -1) {
409
- path = lng.split(".");
410
- deep = resources2;
411
- resources2 = ns;
412
- ns = path[1];
413
- }
414
- this.addNamespaces(ns);
415
- let pack = getPath(this.data, path) || {};
416
- if (!options.skipCopy) resources2 = JSON.parse(JSON.stringify(resources2));
417
- if (deep) {
418
- deepExtend(pack, resources2, overwrite);
419
- } else {
420
- pack = {
421
- ...pack,
422
- ...resources2
423
- };
424
- }
425
- setPath(this.data, path, pack);
426
- if (!options.silent) this.emit("added", lng, ns, resources2);
427
- }
428
- removeResourceBundle(lng, ns) {
429
- if (this.hasResourceBundle(lng, ns)) {
430
- delete this.data[lng][ns];
431
- }
432
- this.removeNamespaces(ns);
433
- this.emit("removed", lng, ns);
434
- }
435
- hasResourceBundle(lng, ns) {
436
- return this.getResource(lng, ns) !== void 0;
437
- }
438
- getResourceBundle(lng, ns) {
439
- if (!ns) ns = this.options.defaultNS;
440
- if (this.options.compatibilityAPI === "v1") return {
441
- ...{},
442
- ...this.getResource(lng, ns)
443
- };
444
- return this.getResource(lng, ns);
445
- }
446
- getDataByLanguage(lng) {
447
- return this.data[lng];
448
- }
449
- hasLanguageSomeTranslations(lng) {
450
- const data = this.getDataByLanguage(lng);
451
- const n2 = data && Object.keys(data) || [];
452
- return !!n2.find((v) => data[v] && Object.keys(data[v]).length > 0);
453
- }
454
- toJSON() {
455
- return this.data;
456
- }
457
- }
458
- var postProcessor = {
459
- processors: {},
460
- addPostProcessor(module) {
461
- this.processors[module.name] = module;
462
- },
463
- handle(processors, value, key, options, translator) {
464
- processors.forEach((processor) => {
465
- if (this.processors[processor]) value = this.processors[processor].process(value, key, options, translator);
466
- });
467
- return value;
468
- }
469
- };
470
- const checkedLoadedFor = {};
471
- class Translator extends EventEmitter {
472
- constructor(services) {
473
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
474
- super();
475
- copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
476
- this.options = options;
477
- if (this.options.keySeparator === void 0) {
478
- this.options.keySeparator = ".";
479
- }
480
- this.logger = baseLogger.create("translator");
481
- }
482
- changeLanguage(lng) {
483
- if (lng) this.language = lng;
484
- }
485
- exists(key) {
486
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
487
- interpolation: {}
488
- };
489
- if (key === void 0 || key === null) {
490
- return false;
491
- }
492
- const resolved = this.resolve(key, options);
493
- return resolved && resolved.res !== void 0;
494
- }
495
- extractFromKey(key, options) {
496
- let nsSeparator = options.nsSeparator !== void 0 ? options.nsSeparator : this.options.nsSeparator;
497
- if (nsSeparator === void 0) nsSeparator = ":";
498
- const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
499
- let namespaces = options.ns || this.options.defaultNS || [];
500
- const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
501
- const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !options.keySeparator && !this.options.userDefinedNsSeparator && !options.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
502
- if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
503
- const m = key.match(this.interpolator.nestingRegexp);
504
- if (m && m.length > 0) {
505
- return {
506
- key,
507
- namespaces: isString(namespaces) ? [namespaces] : namespaces
508
- };
509
- }
510
- const parts = key.split(nsSeparator);
511
- if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
512
- key = parts.join(keySeparator);
513
- }
514
- return {
515
- key,
516
- namespaces: isString(namespaces) ? [namespaces] : namespaces
517
- };
518
- }
519
- translate(keys, options, lastKey) {
520
- if (typeof options !== "object" && this.options.overloadTranslationOptionHandler) {
521
- options = this.options.overloadTranslationOptionHandler(arguments);
522
- }
523
- if (typeof options === "object") options = {
524
- ...options
525
- };
526
- if (!options) options = {};
527
- if (keys === void 0 || keys === null) return "";
528
- if (!Array.isArray(keys)) keys = [String(keys)];
529
- const returnDetails = options.returnDetails !== void 0 ? options.returnDetails : this.options.returnDetails;
530
- const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
531
- const {
532
- key,
533
- namespaces
534
- } = this.extractFromKey(keys[keys.length - 1], options);
535
- const namespace = namespaces[namespaces.length - 1];
536
- const lng = options.lng || this.language;
537
- const appendNamespaceToCIMode = options.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
538
- if (lng && lng.toLowerCase() === "cimode") {
539
- if (appendNamespaceToCIMode) {
540
- const nsSeparator = options.nsSeparator || this.options.nsSeparator;
541
- if (returnDetails) {
542
- return {
543
- res: `${namespace}${nsSeparator}${key}`,
544
- usedKey: key,
545
- exactUsedKey: key,
546
- usedLng: lng,
547
- usedNS: namespace,
548
- usedParams: this.getUsedParamsDetails(options)
549
- };
550
- }
551
- return `${namespace}${nsSeparator}${key}`;
552
- }
553
- if (returnDetails) {
554
- return {
555
- res: key,
556
- usedKey: key,
557
- exactUsedKey: key,
558
- usedLng: lng,
559
- usedNS: namespace,
560
- usedParams: this.getUsedParamsDetails(options)
561
- };
562
- }
563
- return key;
564
- }
565
- const resolved = this.resolve(keys, options);
566
- let res = resolved && resolved.res;
567
- const resUsedKey = resolved && resolved.usedKey || key;
568
- const resExactUsedKey = resolved && resolved.exactUsedKey || key;
569
- const resType = Object.prototype.toString.apply(res);
570
- const noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
571
- const joinArrays = options.joinArrays !== void 0 ? options.joinArrays : this.options.joinArrays;
572
- const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
573
- const handleAsObject = !isString(res) && typeof res !== "boolean" && typeof res !== "number";
574
- if (handleAsObjectInI18nFormat && res && handleAsObject && noObject.indexOf(resType) < 0 && !(isString(joinArrays) && Array.isArray(res))) {
575
- if (!options.returnObjects && !this.options.returnObjects) {
576
- if (!this.options.returnedObjectHandler) {
577
- this.logger.warn("accessing an object - but returnObjects options is not enabled!");
578
- }
579
- const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, res, {
580
- ...options,
581
- ns: namespaces
582
- }) : `key '${key} (${this.language})' returned an object instead of string.`;
583
- if (returnDetails) {
584
- resolved.res = r;
585
- resolved.usedParams = this.getUsedParamsDetails(options);
586
- return resolved;
587
- }
588
- return r;
589
- }
590
- if (keySeparator) {
591
- const resTypeIsArray = Array.isArray(res);
592
- const copy2 = resTypeIsArray ? [] : {};
593
- const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
594
- for (const m in res) {
595
- if (Object.prototype.hasOwnProperty.call(res, m)) {
596
- const deepKey = `${newKeyToUse}${keySeparator}${m}`;
597
- copy2[m] = this.translate(deepKey, {
598
- ...options,
599
- ...{
600
- joinArrays: false,
601
- ns: namespaces
602
- }
603
- });
604
- if (copy2[m] === deepKey) copy2[m] = res[m];
605
- }
606
- }
607
- res = copy2;
608
- }
609
- } else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
610
- res = res.join(joinArrays);
611
- if (res) res = this.extendTranslation(res, keys, options, lastKey);
612
- } else {
613
- let usedDefault = false;
614
- let usedKey = false;
615
- const needsPluralHandling = options.count !== void 0 && !isString(options.count);
616
- const hasDefaultValue = Translator.hasDefaultValue(options);
617
- const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, options) : "";
618
- const defaultValueSuffixOrdinalFallback = options.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, options.count, {
619
- ordinal: false
620
- }) : "";
621
- const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
622
- const defaultValue = needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] || options[`defaultValue${defaultValueSuffix}`] || options[`defaultValue${defaultValueSuffixOrdinalFallback}`] || options.defaultValue;
623
- if (!this.isValidLookup(res) && hasDefaultValue) {
624
- usedDefault = true;
625
- res = defaultValue;
626
- }
627
- if (!this.isValidLookup(res)) {
628
- usedKey = true;
629
- res = key;
630
- }
631
- const missingKeyNoValueFallbackToKey = options.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
632
- const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? void 0 : res;
633
- const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
634
- if (usedKey || usedDefault || updateMissing) {
635
- this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
636
- if (keySeparator) {
637
- const fk = this.resolve(key, {
638
- ...options,
639
- keySeparator: false
640
- });
641
- if (fk && fk.res) this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.");
642
- }
643
- let lngs = [];
644
- const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, options.lng || this.language);
645
- if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
646
- for (let i = 0; i < fallbackLngs.length; i++) {
647
- lngs.push(fallbackLngs[i]);
648
- }
649
- } else if (this.options.saveMissingTo === "all") {
650
- lngs = this.languageUtils.toResolveHierarchy(options.lng || this.language);
651
- } else {
652
- lngs.push(options.lng || this.language);
653
- }
654
- const send = (l, k, specificDefaultValue) => {
655
- const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
656
- if (this.options.missingKeyHandler) {
657
- this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, options);
658
- } else if (this.backendConnector && this.backendConnector.saveMissing) {
659
- this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, options);
660
- }
661
- this.emit("missingKey", l, namespace, k, res);
662
- };
663
- if (this.options.saveMissing) {
664
- if (this.options.saveMissingPlurals && needsPluralHandling) {
665
- lngs.forEach((language) => {
666
- const suffixes = this.pluralResolver.getSuffixes(language, options);
667
- if (needsZeroSuffixLookup && options[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
668
- suffixes.push(`${this.options.pluralSeparator}zero`);
669
- }
670
- suffixes.forEach((suffix) => {
671
- send([language], key + suffix, options[`defaultValue${suffix}`] || defaultValue);
672
- });
673
- });
674
- } else {
675
- send(lngs, key, defaultValue);
676
- }
677
- }
678
- }
679
- res = this.extendTranslation(res, keys, options, resolved, lastKey);
680
- if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}:${key}`;
681
- if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
682
- if (this.options.compatibilityAPI !== "v1") {
683
- res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}:${key}` : key, usedDefault ? res : void 0);
684
- } else {
685
- res = this.options.parseMissingKeyHandler(res);
686
- }
687
- }
688
- }
689
- if (returnDetails) {
690
- resolved.res = res;
691
- resolved.usedParams = this.getUsedParamsDetails(options);
692
- return resolved;
693
- }
694
- return res;
695
- }
696
- extendTranslation(res, key, options, resolved, lastKey) {
697
- var _this = this;
698
- if (this.i18nFormat && this.i18nFormat.parse) {
699
- res = this.i18nFormat.parse(res, {
700
- ...this.options.interpolation.defaultVariables,
701
- ...options
702
- }, options.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
703
- resolved
704
- });
705
- } else if (!options.skipInterpolation) {
706
- if (options.interpolation) this.interpolator.init({
707
- ...options,
708
- ...{
709
- interpolation: {
710
- ...this.options.interpolation,
711
- ...options.interpolation
712
- }
713
- }
714
- });
715
- const skipOnVariables = isString(res) && (options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
716
- let nestBef;
717
- if (skipOnVariables) {
718
- const nb = res.match(this.interpolator.nestingRegexp);
719
- nestBef = nb && nb.length;
720
- }
721
- let data = options.replace && !isString(options.replace) ? options.replace : options;
722
- if (this.options.interpolation.defaultVariables) data = {
723
- ...this.options.interpolation.defaultVariables,
724
- ...data
725
- };
726
- res = this.interpolator.interpolate(res, data, options.lng || this.language || resolved.usedLng, options);
727
- if (skipOnVariables) {
728
- const na = res.match(this.interpolator.nestingRegexp);
729
- const nestAft = na && na.length;
730
- if (nestBef < nestAft) options.nest = false;
731
- }
732
- if (!options.lng && this.options.compatibilityAPI !== "v1" && resolved && resolved.res) options.lng = this.language || resolved.usedLng;
733
- if (options.nest !== false) res = this.interpolator.nest(res, function() {
734
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
735
- args[_key] = arguments[_key];
736
- }
737
- if (lastKey && lastKey[0] === args[0] && !options.context) {
738
- _this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
739
- return null;
740
- }
741
- return _this.translate(...args, key);
742
- }, options);
743
- if (options.interpolation) this.interpolator.reset();
744
- }
745
- const postProcess = options.postProcess || this.options.postProcess;
746
- const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
747
- if (res !== void 0 && res !== null && postProcessorNames && postProcessorNames.length && options.applyPostProcessor !== false) {
748
- res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
749
- i18nResolved: {
750
- ...resolved,
751
- usedParams: this.getUsedParamsDetails(options)
752
- },
753
- ...options
754
- } : options, this);
755
- }
756
- return res;
757
- }
758
- resolve(keys) {
759
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
760
- let found;
761
- let usedKey;
762
- let exactUsedKey;
763
- let usedLng;
764
- let usedNS;
765
- if (isString(keys)) keys = [keys];
766
- keys.forEach((k) => {
767
- if (this.isValidLookup(found)) return;
768
- const extracted = this.extractFromKey(k, options);
769
- const key = extracted.key;
770
- usedKey = key;
771
- let namespaces = extracted.namespaces;
772
- if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
773
- const needsPluralHandling = options.count !== void 0 && !isString(options.count);
774
- const needsZeroSuffixLookup = needsPluralHandling && !options.ordinal && options.count === 0 && this.pluralResolver.shouldUseIntlApi();
775
- const needsContextHandling = options.context !== void 0 && (isString(options.context) || typeof options.context === "number") && options.context !== "";
776
- const codes = options.lngs ? options.lngs : this.languageUtils.toResolveHierarchy(options.lng || this.language, options.fallbackLng);
777
- namespaces.forEach((ns) => {
778
- if (this.isValidLookup(found)) return;
779
- usedNS = ns;
780
- if (!checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(usedNS)) {
781
- checkedLoadedFor[`${codes[0]}-${ns}`] = true;
782
- this.logger.warn(`key "${usedKey}" for languages "${codes.join(", ")}" won't get resolved as namespace "${usedNS}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
783
- }
784
- codes.forEach((code) => {
785
- if (this.isValidLookup(found)) return;
786
- usedLng = code;
787
- const finalKeys = [key];
788
- if (this.i18nFormat && this.i18nFormat.addLookupKeys) {
789
- this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, options);
790
- } else {
791
- let pluralSuffix;
792
- if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, options.count, options);
793
- const zeroSuffix = `${this.options.pluralSeparator}zero`;
794
- const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
795
- if (needsPluralHandling) {
796
- finalKeys.push(key + pluralSuffix);
797
- if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
798
- finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
799
- }
800
- if (needsZeroSuffixLookup) {
801
- finalKeys.push(key + zeroSuffix);
802
- }
803
- }
804
- if (needsContextHandling) {
805
- const contextKey = `${key}${this.options.contextSeparator}${options.context}`;
806
- finalKeys.push(contextKey);
807
- if (needsPluralHandling) {
808
- finalKeys.push(contextKey + pluralSuffix);
809
- if (options.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
810
- finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
811
- }
812
- if (needsZeroSuffixLookup) {
813
- finalKeys.push(contextKey + zeroSuffix);
814
- }
815
- }
816
- }
817
- }
818
- let possibleKey;
819
- while (possibleKey = finalKeys.pop()) {
820
- if (!this.isValidLookup(found)) {
821
- exactUsedKey = possibleKey;
822
- found = this.getResource(code, ns, possibleKey, options);
823
- }
824
- }
825
- });
826
- });
827
- });
828
- return {
829
- res: found,
830
- usedKey,
831
- exactUsedKey,
832
- usedLng,
833
- usedNS
834
- };
835
- }
836
- isValidLookup(res) {
837
- return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
838
- }
839
- getResource(code, ns, key) {
840
- let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
841
- if (this.i18nFormat && this.i18nFormat.getResource) return this.i18nFormat.getResource(code, ns, key, options);
842
- return this.resourceStore.getResource(code, ns, key, options);
843
- }
844
- getUsedParamsDetails() {
845
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
846
- const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
847
- const useOptionsReplaceForData = options.replace && !isString(options.replace);
848
- let data = useOptionsReplaceForData ? options.replace : options;
849
- if (useOptionsReplaceForData && typeof options.count !== "undefined") {
850
- data.count = options.count;
851
- }
852
- if (this.options.interpolation.defaultVariables) {
853
- data = {
854
- ...this.options.interpolation.defaultVariables,
855
- ...data
856
- };
857
- }
858
- if (!useOptionsReplaceForData) {
859
- data = {
860
- ...data
861
- };
862
- for (const key of optionsKeys) {
863
- delete data[key];
864
- }
865
- }
866
- return data;
867
- }
868
- static hasDefaultValue(options) {
869
- const prefix = "defaultValue";
870
- for (const option in options) {
871
- if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && void 0 !== options[option]) {
872
- return true;
873
- }
874
- }
875
- return false;
876
- }
877
- }
878
- const capitalize = (string) => string.charAt(0).toUpperCase() + string.slice(1);
879
- class LanguageUtil {
880
- constructor(options) {
881
- this.options = options;
882
- this.supportedLngs = this.options.supportedLngs || false;
883
- this.logger = baseLogger.create("languageUtils");
884
- }
885
- getScriptPartFromCode(code) {
886
- code = getCleanedCode(code);
887
- if (!code || code.indexOf("-") < 0) return null;
888
- const p = code.split("-");
889
- if (p.length === 2) return null;
890
- p.pop();
891
- if (p[p.length - 1].toLowerCase() === "x") return null;
892
- return this.formatLanguageCode(p.join("-"));
893
- }
894
- getLanguagePartFromCode(code) {
895
- code = getCleanedCode(code);
896
- if (!code || code.indexOf("-") < 0) return code;
897
- const p = code.split("-");
898
- return this.formatLanguageCode(p[0]);
899
- }
900
- formatLanguageCode(code) {
901
- if (isString(code) && code.indexOf("-") > -1) {
902
- if (typeof Intl !== "undefined" && typeof Intl.getCanonicalLocales !== "undefined") {
903
- try {
904
- let formattedCode = Intl.getCanonicalLocales(code)[0];
905
- if (formattedCode && this.options.lowerCaseLng) {
906
- formattedCode = formattedCode.toLowerCase();
907
- }
908
- if (formattedCode) return formattedCode;
909
- } catch (e) {
910
- }
911
- }
912
- const specialCases = ["hans", "hant", "latn", "cyrl", "cans", "mong", "arab"];
913
- let p = code.split("-");
914
- if (this.options.lowerCaseLng) {
915
- p = p.map((part) => part.toLowerCase());
916
- } else if (p.length === 2) {
917
- p[0] = p[0].toLowerCase();
918
- p[1] = p[1].toUpperCase();
919
- if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
920
- } else if (p.length === 3) {
921
- p[0] = p[0].toLowerCase();
922
- if (p[1].length === 2) p[1] = p[1].toUpperCase();
923
- if (p[0] !== "sgn" && p[2].length === 2) p[2] = p[2].toUpperCase();
924
- if (specialCases.indexOf(p[1].toLowerCase()) > -1) p[1] = capitalize(p[1].toLowerCase());
925
- if (specialCases.indexOf(p[2].toLowerCase()) > -1) p[2] = capitalize(p[2].toLowerCase());
926
- }
927
- return p.join("-");
928
- }
929
- return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
930
- }
931
- isSupportedCode(code) {
932
- if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) {
933
- code = this.getLanguagePartFromCode(code);
934
- }
935
- return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
936
- }
937
- getBestMatchFromCodes(codes) {
938
- if (!codes) return null;
939
- let found;
940
- codes.forEach((code) => {
941
- if (found) return;
942
- const cleanedLng = this.formatLanguageCode(code);
943
- if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
944
- });
945
- if (!found && this.options.supportedLngs) {
946
- codes.forEach((code) => {
947
- if (found) return;
948
- const lngOnly = this.getLanguagePartFromCode(code);
949
- if (this.isSupportedCode(lngOnly)) return found = lngOnly;
950
- found = this.options.supportedLngs.find((supportedLng) => {
951
- if (supportedLng === lngOnly) return supportedLng;
952
- if (supportedLng.indexOf("-") < 0 && lngOnly.indexOf("-") < 0) return;
953
- if (supportedLng.indexOf("-") > 0 && lngOnly.indexOf("-") < 0 && supportedLng.substring(0, supportedLng.indexOf("-")) === lngOnly) return supportedLng;
954
- if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
955
- });
956
- });
957
- }
958
- if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
959
- return found;
960
- }
961
- getFallbackCodes(fallbacks, code) {
962
- if (!fallbacks) return [];
963
- if (typeof fallbacks === "function") fallbacks = fallbacks(code);
964
- if (isString(fallbacks)) fallbacks = [fallbacks];
965
- if (Array.isArray(fallbacks)) return fallbacks;
966
- if (!code) return fallbacks.default || [];
967
- let found = fallbacks[code];
968
- if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
969
- if (!found) found = fallbacks[this.formatLanguageCode(code)];
970
- if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
971
- if (!found) found = fallbacks.default;
972
- return found || [];
973
- }
974
- toResolveHierarchy(code, fallbackCode) {
975
- const fallbackCodes = this.getFallbackCodes(fallbackCode || this.options.fallbackLng || [], code);
976
- const codes = [];
977
- const addCode = (c) => {
978
- if (!c) return;
979
- if (this.isSupportedCode(c)) {
980
- codes.push(c);
981
- } else {
982
- this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
983
- }
984
- };
985
- if (isString(code) && (code.indexOf("-") > -1 || code.indexOf("_") > -1)) {
986
- if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
987
- if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
988
- if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
989
- } else if (isString(code)) {
990
- addCode(this.formatLanguageCode(code));
991
- }
992
- fallbackCodes.forEach((fc) => {
993
- if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
994
- });
995
- return codes;
996
- }
997
- }
998
- let sets = [{
999
- lngs: ["ach", "ak", "am", "arn", "br", "fil", "gun", "ln", "mfe", "mg", "mi", "oc", "pt", "pt-BR", "tg", "tl", "ti", "tr", "uz", "wa"],
1000
- nr: [1, 2],
1001
- fc: 1
1002
- }, {
1003
- lngs: ["af", "an", "ast", "az", "bg", "bn", "ca", "da", "de", "dev", "el", "en", "eo", "es", "et", "eu", "fi", "fo", "fur", "fy", "gl", "gu", "ha", "hi", "hu", "hy", "ia", "it", "kk", "kn", "ku", "lb", "mai", "ml", "mn", "mr", "nah", "nap", "nb", "ne", "nl", "nn", "no", "nso", "pa", "pap", "pms", "ps", "pt-PT", "rm", "sco", "se", "si", "so", "son", "sq", "sv", "sw", "ta", "te", "tk", "ur", "yo"],
1004
- nr: [1, 2],
1005
- fc: 2
1006
- }, {
1007
- lngs: ["ay", "bo", "cgg", "fa", "ht", "id", "ja", "jbo", "ka", "km", "ko", "ky", "lo", "ms", "sah", "su", "th", "tt", "ug", "vi", "wo", "zh"],
1008
- nr: [1],
1009
- fc: 3
1010
- }, {
1011
- lngs: ["be", "bs", "cnr", "dz", "hr", "ru", "sr", "uk"],
1012
- nr: [1, 2, 5],
1013
- fc: 4
1014
- }, {
1015
- lngs: ["ar"],
1016
- nr: [0, 1, 2, 3, 11, 100],
1017
- fc: 5
1018
- }, {
1019
- lngs: ["cs", "sk"],
1020
- nr: [1, 2, 5],
1021
- fc: 6
1022
- }, {
1023
- lngs: ["csb", "pl"],
1024
- nr: [1, 2, 5],
1025
- fc: 7
1026
- }, {
1027
- lngs: ["cy"],
1028
- nr: [1, 2, 3, 8],
1029
- fc: 8
1030
- }, {
1031
- lngs: ["fr"],
1032
- nr: [1, 2],
1033
- fc: 9
1034
- }, {
1035
- lngs: ["ga"],
1036
- nr: [1, 2, 3, 7, 11],
1037
- fc: 10
1038
- }, {
1039
- lngs: ["gd"],
1040
- nr: [1, 2, 3, 20],
1041
- fc: 11
1042
- }, {
1043
- lngs: ["is"],
1044
- nr: [1, 2],
1045
- fc: 12
1046
- }, {
1047
- lngs: ["jv"],
1048
- nr: [0, 1],
1049
- fc: 13
1050
- }, {
1051
- lngs: ["kw"],
1052
- nr: [1, 2, 3, 4],
1053
- fc: 14
1054
- }, {
1055
- lngs: ["lt"],
1056
- nr: [1, 2, 10],
1057
- fc: 15
1058
- }, {
1059
- lngs: ["lv"],
1060
- nr: [1, 2, 0],
1061
- fc: 16
1062
- }, {
1063
- lngs: ["mk"],
1064
- nr: [1, 2],
1065
- fc: 17
1066
- }, {
1067
- lngs: ["mnk"],
1068
- nr: [0, 1, 2],
1069
- fc: 18
1070
- }, {
1071
- lngs: ["mt"],
1072
- nr: [1, 2, 11, 20],
1073
- fc: 19
1074
- }, {
1075
- lngs: ["or"],
1076
- nr: [2, 1],
1077
- fc: 2
1078
- }, {
1079
- lngs: ["ro"],
1080
- nr: [1, 2, 20],
1081
- fc: 20
1082
- }, {
1083
- lngs: ["sl"],
1084
- nr: [5, 1, 2, 3],
1085
- fc: 21
1086
- }, {
1087
- lngs: ["he", "iw"],
1088
- nr: [1, 2, 20, 21],
1089
- fc: 22
1090
- }];
1091
- let _rulesPluralsTypes = {
1092
- 1: (n2) => Number(n2 > 1),
1093
- 2: (n2) => Number(n2 != 1),
1094
- 3: (n2) => 0,
1095
- 4: (n2) => Number(n2 % 10 == 1 && n2 % 100 != 11 ? 0 : n2 % 10 >= 2 && n2 % 10 <= 4 && (n2 % 100 < 10 || n2 % 100 >= 20) ? 1 : 2),
1096
- 5: (n2) => Number(n2 == 0 ? 0 : n2 == 1 ? 1 : n2 == 2 ? 2 : n2 % 100 >= 3 && n2 % 100 <= 10 ? 3 : n2 % 100 >= 11 ? 4 : 5),
1097
- 6: (n2) => Number(n2 == 1 ? 0 : n2 >= 2 && n2 <= 4 ? 1 : 2),
1098
- 7: (n2) => Number(n2 == 1 ? 0 : n2 % 10 >= 2 && n2 % 10 <= 4 && (n2 % 100 < 10 || n2 % 100 >= 20) ? 1 : 2),
1099
- 8: (n2) => Number(n2 == 1 ? 0 : n2 == 2 ? 1 : n2 != 8 && n2 != 11 ? 2 : 3),
1100
- 9: (n2) => Number(n2 >= 2),
1101
- 10: (n2) => Number(n2 == 1 ? 0 : n2 == 2 ? 1 : n2 < 7 ? 2 : n2 < 11 ? 3 : 4),
1102
- 11: (n2) => Number(n2 == 1 || n2 == 11 ? 0 : n2 == 2 || n2 == 12 ? 1 : n2 > 2 && n2 < 20 ? 2 : 3),
1103
- 12: (n2) => Number(n2 % 10 != 1 || n2 % 100 == 11),
1104
- 13: (n2) => Number(n2 !== 0),
1105
- 14: (n2) => Number(n2 == 1 ? 0 : n2 == 2 ? 1 : n2 == 3 ? 2 : 3),
1106
- 15: (n2) => Number(n2 % 10 == 1 && n2 % 100 != 11 ? 0 : n2 % 10 >= 2 && (n2 % 100 < 10 || n2 % 100 >= 20) ? 1 : 2),
1107
- 16: (n2) => Number(n2 % 10 == 1 && n2 % 100 != 11 ? 0 : n2 !== 0 ? 1 : 2),
1108
- 17: (n2) => Number(n2 == 1 || n2 % 10 == 1 && n2 % 100 != 11 ? 0 : 1),
1109
- 18: (n2) => Number(n2 == 0 ? 0 : n2 == 1 ? 1 : 2),
1110
- 19: (n2) => Number(n2 == 1 ? 0 : n2 == 0 || n2 % 100 > 1 && n2 % 100 < 11 ? 1 : n2 % 100 > 10 && n2 % 100 < 20 ? 2 : 3),
1111
- 20: (n2) => Number(n2 == 1 ? 0 : n2 == 0 || n2 % 100 > 0 && n2 % 100 < 20 ? 1 : 2),
1112
- 21: (n2) => Number(n2 % 100 == 1 ? 1 : n2 % 100 == 2 ? 2 : n2 % 100 == 3 || n2 % 100 == 4 ? 3 : 0),
1113
- 22: (n2) => Number(n2 == 1 ? 0 : n2 == 2 ? 1 : (n2 < 0 || n2 > 10) && n2 % 10 == 0 ? 2 : 3)
1114
- };
1115
- const nonIntlVersions = ["v1", "v2", "v3"];
1116
- const intlVersions = ["v4"];
1117
- const suffixesOrder = {
1118
- zero: 0,
1119
- one: 1,
1120
- two: 2,
1121
- few: 3,
1122
- many: 4,
1123
- other: 5
1124
- };
1125
- const createRules = () => {
1126
- const rules = {};
1127
- sets.forEach((set) => {
1128
- set.lngs.forEach((l) => {
1129
- rules[l] = {
1130
- numbers: set.nr,
1131
- plurals: _rulesPluralsTypes[set.fc]
1132
- };
1133
- });
1134
- });
1135
- return rules;
1136
- };
1137
- class PluralResolver {
1138
- constructor(languageUtils) {
1139
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1140
- this.languageUtils = languageUtils;
1141
- this.options = options;
1142
- this.logger = baseLogger.create("pluralResolver");
1143
- if ((!this.options.compatibilityJSON || intlVersions.includes(this.options.compatibilityJSON)) && (typeof Intl === "undefined" || !Intl.PluralRules)) {
1144
- this.options.compatibilityJSON = "v3";
1145
- this.logger.error("Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.");
1146
- }
1147
- this.rules = createRules();
1148
- this.pluralRulesCache = {};
1149
- }
1150
- addRule(lng, obj) {
1151
- this.rules[lng] = obj;
1152
- }
1153
- clearCache() {
1154
- this.pluralRulesCache = {};
1155
- }
1156
- getRule(code) {
1157
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1158
- if (this.shouldUseIntlApi()) {
1159
- const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
1160
- const type2 = options.ordinal ? "ordinal" : "cardinal";
1161
- const cacheKey = JSON.stringify({
1162
- cleanedCode,
1163
- type: type2
1164
- });
1165
- if (cacheKey in this.pluralRulesCache) {
1166
- return this.pluralRulesCache[cacheKey];
1167
- }
1168
- let rule;
1169
- try {
1170
- rule = new Intl.PluralRules(cleanedCode, {
1171
- type: type2
1172
- });
1173
- } catch (err) {
1174
- if (!code.match(/-|_/)) return;
1175
- const lngPart = this.languageUtils.getLanguagePartFromCode(code);
1176
- rule = this.getRule(lngPart, options);
1177
- }
1178
- this.pluralRulesCache[cacheKey] = rule;
1179
- return rule;
1180
- }
1181
- return this.rules[code] || this.rules[this.languageUtils.getLanguagePartFromCode(code)];
1182
- }
1183
- needsPlural(code) {
1184
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1185
- const rule = this.getRule(code, options);
1186
- if (this.shouldUseIntlApi()) {
1187
- return rule && rule.resolvedOptions().pluralCategories.length > 1;
1188
- }
1189
- return rule && rule.numbers.length > 1;
1190
- }
1191
- getPluralFormsOfKey(code, key) {
1192
- let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1193
- return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
1194
- }
1195
- getSuffixes(code) {
1196
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1197
- const rule = this.getRule(code, options);
1198
- if (!rule) {
1199
- return [];
1200
- }
1201
- if (this.shouldUseIntlApi()) {
1202
- return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
1203
- }
1204
- return rule.numbers.map((number) => this.getSuffix(code, number, options));
1205
- }
1206
- getSuffix(code, count) {
1207
- let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1208
- const rule = this.getRule(code, options);
1209
- if (rule) {
1210
- if (this.shouldUseIntlApi()) {
1211
- return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
1212
- }
1213
- return this.getSuffixRetroCompatible(rule, count);
1214
- }
1215
- this.logger.warn(`no plural rule found for: ${code}`);
1216
- return "";
1217
- }
1218
- getSuffixRetroCompatible(rule, count) {
1219
- const idx = rule.noAbs ? rule.plurals(count) : rule.plurals(Math.abs(count));
1220
- let suffix = rule.numbers[idx];
1221
- if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
1222
- if (suffix === 2) {
1223
- suffix = "plural";
1224
- } else if (suffix === 1) {
1225
- suffix = "";
1226
- }
1227
- }
1228
- const returnSuffix = () => this.options.prepend && suffix.toString() ? this.options.prepend + suffix.toString() : suffix.toString();
1229
- if (this.options.compatibilityJSON === "v1") {
1230
- if (suffix === 1) return "";
1231
- if (typeof suffix === "number") return `_plural_${suffix.toString()}`;
1232
- return returnSuffix();
1233
- } else if (this.options.compatibilityJSON === "v2") {
1234
- return returnSuffix();
1235
- } else if (this.options.simplifyPluralSuffix && rule.numbers.length === 2 && rule.numbers[0] === 1) {
1236
- return returnSuffix();
1237
- }
1238
- return this.options.prepend && idx.toString() ? this.options.prepend + idx.toString() : idx.toString();
1239
- }
1240
- shouldUseIntlApi() {
1241
- return !nonIntlVersions.includes(this.options.compatibilityJSON);
1242
- }
1243
- }
1244
- const deepFindWithDefaults = function(data, defaultData, key) {
1245
- let keySeparator = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : ".";
1246
- let ignoreJSONStructure = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : true;
1247
- let path = getPathWithDefaults(data, defaultData, key);
1248
- if (!path && ignoreJSONStructure && isString(key)) {
1249
- path = deepFind(data, key, keySeparator);
1250
- if (path === void 0) path = deepFind(defaultData, key, keySeparator);
1251
- }
1252
- return path;
1253
- };
1254
- const regexSafe = (val) => val.replace(/\$/g, "$$$$");
1255
- class Interpolator {
1256
- constructor() {
1257
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1258
- this.logger = baseLogger.create("interpolator");
1259
- this.options = options;
1260
- this.format = options.interpolation && options.interpolation.format || ((value) => value);
1261
- this.init(options);
1262
- }
1263
- init() {
1264
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1265
- if (!options.interpolation) options.interpolation = {
1266
- escapeValue: true
1267
- };
1268
- const {
1269
- escape: escape$1,
1270
- escapeValue,
1271
- useRawValueToEscape,
1272
- prefix,
1273
- prefixEscaped,
1274
- suffix,
1275
- suffixEscaped,
1276
- formatSeparator,
1277
- unescapeSuffix,
1278
- unescapePrefix,
1279
- nestingPrefix,
1280
- nestingPrefixEscaped,
1281
- nestingSuffix,
1282
- nestingSuffixEscaped,
1283
- nestingOptionsSeparator,
1284
- maxReplaces,
1285
- alwaysFormat
1286
- } = options.interpolation;
1287
- this.escape = escape$1 !== void 0 ? escape$1 : escape;
1288
- this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
1289
- this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
1290
- this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
1291
- this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
1292
- this.formatSeparator = formatSeparator || ",";
1293
- this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix || "-";
1294
- this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix || "";
1295
- this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
1296
- this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
1297
- this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
1298
- this.maxReplaces = maxReplaces || 1e3;
1299
- this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
1300
- this.resetRegExp();
1301
- }
1302
- reset() {
1303
- if (this.options) this.init(this.options);
1304
- }
1305
- resetRegExp() {
1306
- const getOrResetRegExp = (existingRegExp, pattern) => {
1307
- if (existingRegExp && existingRegExp.source === pattern) {
1308
- existingRegExp.lastIndex = 0;
1309
- return existingRegExp;
1310
- }
1311
- return new RegExp(pattern, "g");
1312
- };
1313
- this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
1314
- this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
1315
- this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}(.+?)${this.nestingSuffix}`);
1316
- }
1317
- interpolate(str, data, lng, options) {
1318
- let match;
1319
- let value;
1320
- let replaces;
1321
- const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
1322
- const handleFormat = (key) => {
1323
- if (key.indexOf(this.formatSeparator) < 0) {
1324
- const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
1325
- return this.alwaysFormat ? this.format(path, void 0, lng, {
1326
- ...options,
1327
- ...data,
1328
- interpolationkey: key
1329
- }) : path;
1330
- }
1331
- const p = key.split(this.formatSeparator);
1332
- const k = p.shift().trim();
1333
- const f = p.join(this.formatSeparator).trim();
1334
- return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
1335
- ...options,
1336
- ...data,
1337
- interpolationkey: k
1338
- });
1339
- };
1340
- this.resetRegExp();
1341
- const missingInterpolationHandler = options && options.missingInterpolationHandler || this.options.missingInterpolationHandler;
1342
- const skipOnVariables = options && options.interpolation && options.interpolation.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
1343
- const todos = [{
1344
- regex: this.regexpUnescape,
1345
- safeValue: (val) => regexSafe(val)
1346
- }, {
1347
- regex: this.regexp,
1348
- safeValue: (val) => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
1349
- }];
1350
- todos.forEach((todo) => {
1351
- replaces = 0;
1352
- while (match = todo.regex.exec(str)) {
1353
- const matchedVar = match[1].trim();
1354
- value = handleFormat(matchedVar);
1355
- if (value === void 0) {
1356
- if (typeof missingInterpolationHandler === "function") {
1357
- const temp = missingInterpolationHandler(str, match, options);
1358
- value = isString(temp) ? temp : "";
1359
- } else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
1360
- value = "";
1361
- } else if (skipOnVariables) {
1362
- value = match[0];
1363
- continue;
1364
- } else {
1365
- this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
1366
- value = "";
1367
- }
1368
- } else if (!isString(value) && !this.useRawValueToEscape) {
1369
- value = makeString(value);
1370
- }
1371
- const safeValue = todo.safeValue(value);
1372
- str = str.replace(match[0], safeValue);
1373
- if (skipOnVariables) {
1374
- todo.regex.lastIndex += value.length;
1375
- todo.regex.lastIndex -= match[0].length;
1376
- } else {
1377
- todo.regex.lastIndex = 0;
1378
- }
1379
- replaces++;
1380
- if (replaces >= this.maxReplaces) {
1381
- break;
1382
- }
1383
- }
1384
- });
1385
- return str;
1386
- }
1387
- nest(str, fc) {
1388
- let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1389
- let match;
1390
- let value;
1391
- let clonedOptions;
1392
- const handleHasOptions = (key, inheritedOptions) => {
1393
- const sep = this.nestingOptionsSeparator;
1394
- if (key.indexOf(sep) < 0) return key;
1395
- const c = key.split(new RegExp(`${sep}[ ]*{`));
1396
- let optionsString = `{${c[1]}`;
1397
- key = c[0];
1398
- optionsString = this.interpolate(optionsString, clonedOptions);
1399
- const matchedSingleQuotes = optionsString.match(/'/g);
1400
- const matchedDoubleQuotes = optionsString.match(/"/g);
1401
- if (matchedSingleQuotes && matchedSingleQuotes.length % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
1402
- optionsString = optionsString.replace(/'/g, '"');
1403
- }
1404
- try {
1405
- clonedOptions = JSON.parse(optionsString);
1406
- if (inheritedOptions) clonedOptions = {
1407
- ...inheritedOptions,
1408
- ...clonedOptions
1409
- };
1410
- } catch (e) {
1411
- this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
1412
- return `${key}${sep}${optionsString}`;
1413
- }
1414
- if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
1415
- return key;
1416
- };
1417
- while (match = this.nestingRegexp.exec(str)) {
1418
- let formatters = [];
1419
- clonedOptions = {
1420
- ...options
1421
- };
1422
- clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
1423
- clonedOptions.applyPostProcessor = false;
1424
- delete clonedOptions.defaultValue;
1425
- let doReduce = false;
1426
- if (match[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(match[1])) {
1427
- const r = match[1].split(this.formatSeparator).map((elem) => elem.trim());
1428
- match[1] = r.shift();
1429
- formatters = r;
1430
- doReduce = true;
1431
- }
1432
- value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
1433
- if (value && match[0] === str && !isString(value)) return value;
1434
- if (!isString(value)) value = makeString(value);
1435
- if (!value) {
1436
- this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
1437
- value = "";
1438
- }
1439
- if (doReduce) {
1440
- value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
1441
- ...options,
1442
- interpolationkey: match[1].trim()
1443
- }), value.trim());
1444
- }
1445
- str = str.replace(match[0], value);
1446
- this.regexp.lastIndex = 0;
1447
- }
1448
- return str;
1449
- }
1450
- }
1451
- const parseFormatStr = (formatStr) => {
1452
- let formatName = formatStr.toLowerCase().trim();
1453
- const formatOptions = {};
1454
- if (formatStr.indexOf("(") > -1) {
1455
- const p = formatStr.split("(");
1456
- formatName = p[0].toLowerCase().trim();
1457
- const optStr = p[1].substring(0, p[1].length - 1);
1458
- if (formatName === "currency" && optStr.indexOf(":") < 0) {
1459
- if (!formatOptions.currency) formatOptions.currency = optStr.trim();
1460
- } else if (formatName === "relativetime" && optStr.indexOf(":") < 0) {
1461
- if (!formatOptions.range) formatOptions.range = optStr.trim();
1462
- } else {
1463
- const opts = optStr.split(";");
1464
- opts.forEach((opt) => {
1465
- if (opt) {
1466
- const [key, ...rest] = opt.split(":");
1467
- const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
1468
- const trimmedKey = key.trim();
1469
- if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
1470
- if (val === "false") formatOptions[trimmedKey] = false;
1471
- if (val === "true") formatOptions[trimmedKey] = true;
1472
- if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
1473
- }
1474
- });
1475
- }
1476
- }
1477
- return {
1478
- formatName,
1479
- formatOptions
1480
- };
1481
- };
1482
- const createCachedFormatter = (fn) => {
1483
- const cache = {};
1484
- return (val, lng, options) => {
1485
- let optForCache = options;
1486
- if (options && options.interpolationkey && options.formatParams && options.formatParams[options.interpolationkey] && options[options.interpolationkey]) {
1487
- optForCache = {
1488
- ...optForCache,
1489
- [options.interpolationkey]: void 0
1490
- };
1491
- }
1492
- const key = lng + JSON.stringify(optForCache);
1493
- let formatter = cache[key];
1494
- if (!formatter) {
1495
- formatter = fn(getCleanedCode(lng), options);
1496
- cache[key] = formatter;
1497
- }
1498
- return formatter(val);
1499
- };
1500
- };
1501
- class Formatter {
1502
- constructor() {
1503
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1504
- this.logger = baseLogger.create("formatter");
1505
- this.options = options;
1506
- this.formats = {
1507
- number: createCachedFormatter((lng, opt) => {
1508
- const formatter = new Intl.NumberFormat(lng, {
1509
- ...opt
1510
- });
1511
- return (val) => formatter.format(val);
1512
- }),
1513
- currency: createCachedFormatter((lng, opt) => {
1514
- const formatter = new Intl.NumberFormat(lng, {
1515
- ...opt,
1516
- style: "currency"
1517
- });
1518
- return (val) => formatter.format(val);
1519
- }),
1520
- datetime: createCachedFormatter((lng, opt) => {
1521
- const formatter = new Intl.DateTimeFormat(lng, {
1522
- ...opt
1523
- });
1524
- return (val) => formatter.format(val);
1525
- }),
1526
- relativetime: createCachedFormatter((lng, opt) => {
1527
- const formatter = new Intl.RelativeTimeFormat(lng, {
1528
- ...opt
1529
- });
1530
- return (val) => formatter.format(val, opt.range || "day");
1531
- }),
1532
- list: createCachedFormatter((lng, opt) => {
1533
- const formatter = new Intl.ListFormat(lng, {
1534
- ...opt
1535
- });
1536
- return (val) => formatter.format(val);
1537
- })
1538
- };
1539
- this.init(options);
1540
- }
1541
- init(services) {
1542
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
1543
- interpolation: {}
1544
- };
1545
- this.formatSeparator = options.interpolation.formatSeparator || ",";
1546
- }
1547
- add(name2, fc) {
1548
- this.formats[name2.toLowerCase().trim()] = fc;
1549
- }
1550
- addCached(name2, fc) {
1551
- this.formats[name2.toLowerCase().trim()] = createCachedFormatter(fc);
1552
- }
1553
- format(value, format, lng) {
1554
- let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
1555
- const formats = format.split(this.formatSeparator);
1556
- if (formats.length > 1 && formats[0].indexOf("(") > 1 && formats[0].indexOf(")") < 0 && formats.find((f) => f.indexOf(")") > -1)) {
1557
- const lastIndex = formats.findIndex((f) => f.indexOf(")") > -1);
1558
- formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
1559
- }
1560
- const result = formats.reduce((mem, f) => {
1561
- const {
1562
- formatName,
1563
- formatOptions
1564
- } = parseFormatStr(f);
1565
- if (this.formats[formatName]) {
1566
- let formatted = mem;
1567
- try {
1568
- const valOptions = options && options.formatParams && options.formatParams[options.interpolationkey] || {};
1569
- const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
1570
- formatted = this.formats[formatName](mem, l, {
1571
- ...formatOptions,
1572
- ...options,
1573
- ...valOptions
1574
- });
1575
- } catch (error) {
1576
- this.logger.warn(error);
1577
- }
1578
- return formatted;
1579
- } else {
1580
- this.logger.warn(`there was no format function for ${formatName}`);
1581
- }
1582
- return mem;
1583
- }, value);
1584
- return result;
1585
- }
1586
- }
1587
- const removePending = (q, name2) => {
1588
- if (q.pending[name2] !== void 0) {
1589
- delete q.pending[name2];
1590
- q.pendingCount--;
1591
- }
1592
- };
1593
- class Connector extends EventEmitter {
1594
- constructor(backend, store, services) {
1595
- let options = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
1596
- super();
1597
- this.backend = backend;
1598
- this.store = store;
1599
- this.services = services;
1600
- this.languageUtils = services.languageUtils;
1601
- this.options = options;
1602
- this.logger = baseLogger.create("backendConnector");
1603
- this.waitingReads = [];
1604
- this.maxParallelReads = options.maxParallelReads || 10;
1605
- this.readingCalls = 0;
1606
- this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
1607
- this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
1608
- this.state = {};
1609
- this.queue = [];
1610
- if (this.backend && this.backend.init) {
1611
- this.backend.init(services, options.backend, options);
1612
- }
1613
- }
1614
- queueLoad(languages, namespaces, options, callback) {
1615
- const toLoad = {};
1616
- const pending = {};
1617
- const toLoadLanguages = {};
1618
- const toLoadNamespaces = {};
1619
- languages.forEach((lng) => {
1620
- let hasAllNamespaces = true;
1621
- namespaces.forEach((ns) => {
1622
- const name2 = `${lng}|${ns}`;
1623
- if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
1624
- this.state[name2] = 2;
1625
- } else if (this.state[name2] < 0) ;
1626
- else if (this.state[name2] === 1) {
1627
- if (pending[name2] === void 0) pending[name2] = true;
1628
- } else {
1629
- this.state[name2] = 1;
1630
- hasAllNamespaces = false;
1631
- if (pending[name2] === void 0) pending[name2] = true;
1632
- if (toLoad[name2] === void 0) toLoad[name2] = true;
1633
- if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
1634
- }
1635
- });
1636
- if (!hasAllNamespaces) toLoadLanguages[lng] = true;
1637
- });
1638
- if (Object.keys(toLoad).length || Object.keys(pending).length) {
1639
- this.queue.push({
1640
- pending,
1641
- pendingCount: Object.keys(pending).length,
1642
- loaded: {},
1643
- errors: [],
1644
- callback
1645
- });
1646
- }
1647
- return {
1648
- toLoad: Object.keys(toLoad),
1649
- pending: Object.keys(pending),
1650
- toLoadLanguages: Object.keys(toLoadLanguages),
1651
- toLoadNamespaces: Object.keys(toLoadNamespaces)
1652
- };
1653
- }
1654
- loaded(name2, err, data) {
1655
- const s2 = name2.split("|");
1656
- const lng = s2[0];
1657
- const ns = s2[1];
1658
- if (err) this.emit("failedLoading", lng, ns, err);
1659
- if (!err && data) {
1660
- this.store.addResourceBundle(lng, ns, data, void 0, void 0, {
1661
- skipCopy: true
1662
- });
1663
- }
1664
- this.state[name2] = err ? -1 : 2;
1665
- if (err && data) this.state[name2] = 0;
1666
- const loaded = {};
1667
- this.queue.forEach((q) => {
1668
- pushPath(q.loaded, [lng], ns);
1669
- removePending(q, name2);
1670
- if (err) q.errors.push(err);
1671
- if (q.pendingCount === 0 && !q.done) {
1672
- Object.keys(q.loaded).forEach((l) => {
1673
- if (!loaded[l]) loaded[l] = {};
1674
- const loadedKeys = q.loaded[l];
1675
- if (loadedKeys.length) {
1676
- loadedKeys.forEach((n2) => {
1677
- if (loaded[l][n2] === void 0) loaded[l][n2] = true;
1678
- });
1679
- }
1680
- });
1681
- q.done = true;
1682
- if (q.errors.length) {
1683
- q.callback(q.errors);
1684
- } else {
1685
- q.callback();
1686
- }
1687
- }
1688
- });
1689
- this.emit("loaded", loaded);
1690
- this.queue = this.queue.filter((q) => !q.done);
1691
- }
1692
- read(lng, ns, fcName) {
1693
- let tried = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0;
1694
- let wait = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : this.retryTimeout;
1695
- let callback = arguments.length > 5 ? arguments[5] : void 0;
1696
- if (!lng.length) return callback(null, {});
1697
- if (this.readingCalls >= this.maxParallelReads) {
1698
- this.waitingReads.push({
1699
- lng,
1700
- ns,
1701
- fcName,
1702
- tried,
1703
- wait,
1704
- callback
1705
- });
1706
- return;
1707
- }
1708
- this.readingCalls++;
1709
- const resolver = (err, data) => {
1710
- this.readingCalls--;
1711
- if (this.waitingReads.length > 0) {
1712
- const next = this.waitingReads.shift();
1713
- this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
1714
- }
1715
- if (err && data && tried < this.maxRetries) {
1716
- setTimeout(() => {
1717
- this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
1718
- }, wait);
1719
- return;
1720
- }
1721
- callback(err, data);
1722
- };
1723
- const fc = this.backend[fcName].bind(this.backend);
1724
- if (fc.length === 2) {
1725
- try {
1726
- const r = fc(lng, ns);
1727
- if (r && typeof r.then === "function") {
1728
- r.then((data) => resolver(null, data)).catch(resolver);
1729
- } else {
1730
- resolver(null, r);
1731
- }
1732
- } catch (err) {
1733
- resolver(err);
1734
- }
1735
- return;
1736
- }
1737
- return fc(lng, ns, resolver);
1738
- }
1739
- prepareLoading(languages, namespaces) {
1740
- let options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
1741
- let callback = arguments.length > 3 ? arguments[3] : void 0;
1742
- if (!this.backend) {
1743
- this.logger.warn("No backend was added via i18next.use. Will not load resources.");
1744
- return callback && callback();
1745
- }
1746
- if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
1747
- if (isString(namespaces)) namespaces = [namespaces];
1748
- const toLoad = this.queueLoad(languages, namespaces, options, callback);
1749
- if (!toLoad.toLoad.length) {
1750
- if (!toLoad.pending.length) callback();
1751
- return null;
1752
- }
1753
- toLoad.toLoad.forEach((name2) => {
1754
- this.loadOne(name2);
1755
- });
1756
- }
1757
- load(languages, namespaces, callback) {
1758
- this.prepareLoading(languages, namespaces, {}, callback);
1759
- }
1760
- reload(languages, namespaces, callback) {
1761
- this.prepareLoading(languages, namespaces, {
1762
- reload: true
1763
- }, callback);
1764
- }
1765
- loadOne(name2) {
1766
- let prefix = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
1767
- const s2 = name2.split("|");
1768
- const lng = s2[0];
1769
- const ns = s2[1];
1770
- this.read(lng, ns, "read", void 0, void 0, (err, data) => {
1771
- if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
1772
- if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
1773
- this.loaded(name2, err, data);
1774
- });
1775
- }
1776
- saveMissing(languages, namespace, key, fallbackValue, isUpdate) {
1777
- let options = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {};
1778
- let clb = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : () => {
1779
- };
1780
- if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(namespace)) {
1781
- this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
1782
- return;
1783
- }
1784
- if (key === void 0 || key === null || key === "") return;
1785
- if (this.backend && this.backend.create) {
1786
- const opts = {
1787
- ...options,
1788
- isUpdate
1789
- };
1790
- const fc = this.backend.create.bind(this.backend);
1791
- if (fc.length < 6) {
1792
- try {
1793
- let r;
1794
- if (fc.length === 5) {
1795
- r = fc(languages, namespace, key, fallbackValue, opts);
1796
- } else {
1797
- r = fc(languages, namespace, key, fallbackValue);
1798
- }
1799
- if (r && typeof r.then === "function") {
1800
- r.then((data) => clb(null, data)).catch(clb);
1801
- } else {
1802
- clb(null, r);
1803
- }
1804
- } catch (err) {
1805
- clb(err);
1806
- }
1807
- } else {
1808
- fc(languages, namespace, key, fallbackValue, clb, opts);
1809
- }
1810
- }
1811
- if (!languages || !languages[0]) return;
1812
- this.store.addResource(languages[0], namespace, key, fallbackValue);
1813
- }
1814
- }
1815
- const get = () => ({
1816
- debug: false,
1817
- initImmediate: true,
1818
- ns: ["translation"],
1819
- defaultNS: ["translation"],
1820
- fallbackLng: ["dev"],
1821
- fallbackNS: false,
1822
- supportedLngs: false,
1823
- nonExplicitSupportedLngs: false,
1824
- load: "all",
1825
- preload: false,
1826
- simplifyPluralSuffix: true,
1827
- keySeparator: ".",
1828
- nsSeparator: ":",
1829
- pluralSeparator: "_",
1830
- contextSeparator: "_",
1831
- partialBundledLanguages: false,
1832
- saveMissing: false,
1833
- updateMissing: false,
1834
- saveMissingTo: "fallback",
1835
- saveMissingPlurals: true,
1836
- missingKeyHandler: false,
1837
- missingInterpolationHandler: false,
1838
- postProcess: false,
1839
- postProcessPassResolved: false,
1840
- returnNull: false,
1841
- returnEmptyString: true,
1842
- returnObjects: false,
1843
- joinArrays: false,
1844
- returnedObjectHandler: false,
1845
- parseMissingKeyHandler: false,
1846
- appendNamespaceToMissingKey: false,
1847
- appendNamespaceToCIMode: false,
1848
- overloadTranslationOptionHandler: (args) => {
1849
- let ret = {};
1850
- if (typeof args[1] === "object") ret = args[1];
1851
- if (isString(args[1])) ret.defaultValue = args[1];
1852
- if (isString(args[2])) ret.tDescription = args[2];
1853
- if (typeof args[2] === "object" || typeof args[3] === "object") {
1854
- const options = args[3] || args[2];
1855
- Object.keys(options).forEach((key) => {
1856
- ret[key] = options[key];
1857
- });
1858
- }
1859
- return ret;
1860
- },
1861
- interpolation: {
1862
- escapeValue: true,
1863
- format: (value) => value,
1864
- prefix: "{{",
1865
- suffix: "}}",
1866
- formatSeparator: ",",
1867
- unescapePrefix: "-",
1868
- nestingPrefix: "$t(",
1869
- nestingSuffix: ")",
1870
- nestingOptionsSeparator: ",",
1871
- maxReplaces: 1e3,
1872
- skipOnVariables: true
1873
- }
1874
- });
1875
- const transformOptions = (options) => {
1876
- if (isString(options.ns)) options.ns = [options.ns];
1877
- if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
1878
- if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
1879
- if (options.supportedLngs && options.supportedLngs.indexOf("cimode") < 0) {
1880
- options.supportedLngs = options.supportedLngs.concat(["cimode"]);
1881
- }
1882
- return options;
1883
- };
1884
- const noop = () => {
1885
- };
1886
- const bindMemberFunctions = (inst) => {
1887
- const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
1888
- mems.forEach((mem) => {
1889
- if (typeof inst[mem] === "function") {
1890
- inst[mem] = inst[mem].bind(inst);
1891
- }
1892
- });
1893
- };
1894
- class I18n extends EventEmitter {
1895
- constructor() {
1896
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1897
- let callback = arguments.length > 1 ? arguments[1] : void 0;
1898
- super();
1899
- this.options = transformOptions(options);
1900
- this.services = {};
1901
- this.logger = baseLogger;
1902
- this.modules = {
1903
- external: []
1904
- };
1905
- bindMemberFunctions(this);
1906
- if (callback && !this.isInitialized && !options.isClone) {
1907
- if (!this.options.initImmediate) {
1908
- this.init(options, callback);
1909
- return this;
1910
- }
1911
- setTimeout(() => {
1912
- this.init(options, callback);
1913
- }, 0);
1914
- }
1915
- }
1916
- init() {
1917
- var _this = this;
1918
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1919
- let callback = arguments.length > 1 ? arguments[1] : void 0;
1920
- this.isInitializing = true;
1921
- if (typeof options === "function") {
1922
- callback = options;
1923
- options = {};
1924
- }
1925
- if (!options.defaultNS && options.defaultNS !== false && options.ns) {
1926
- if (isString(options.ns)) {
1927
- options.defaultNS = options.ns;
1928
- } else if (options.ns.indexOf("translation") < 0) {
1929
- options.defaultNS = options.ns[0];
1930
- }
1931
- }
1932
- const defOpts = get();
1933
- this.options = {
1934
- ...defOpts,
1935
- ...this.options,
1936
- ...transformOptions(options)
1937
- };
1938
- if (this.options.compatibilityAPI !== "v1") {
1939
- this.options.interpolation = {
1940
- ...defOpts.interpolation,
1941
- ...this.options.interpolation
1942
- };
1943
- }
1944
- if (options.keySeparator !== void 0) {
1945
- this.options.userDefinedKeySeparator = options.keySeparator;
1946
- }
1947
- if (options.nsSeparator !== void 0) {
1948
- this.options.userDefinedNsSeparator = options.nsSeparator;
1949
- }
1950
- const createClassOnDemand = (ClassOrObject) => {
1951
- if (!ClassOrObject) return null;
1952
- if (typeof ClassOrObject === "function") return new ClassOrObject();
1953
- return ClassOrObject;
1954
- };
1955
- if (!this.options.isClone) {
1956
- if (this.modules.logger) {
1957
- baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
1958
- } else {
1959
- baseLogger.init(null, this.options);
1960
- }
1961
- let formatter;
1962
- if (this.modules.formatter) {
1963
- formatter = this.modules.formatter;
1964
- } else if (typeof Intl !== "undefined") {
1965
- formatter = Formatter;
1966
- }
1967
- const lu = new LanguageUtil(this.options);
1968
- this.store = new ResourceStore(this.options.resources, this.options);
1969
- const s2 = this.services;
1970
- s2.logger = baseLogger;
1971
- s2.resourceStore = this.store;
1972
- s2.languageUtils = lu;
1973
- s2.pluralResolver = new PluralResolver(lu, {
1974
- prepend: this.options.pluralSeparator,
1975
- compatibilityJSON: this.options.compatibilityJSON,
1976
- simplifyPluralSuffix: this.options.simplifyPluralSuffix
1977
- });
1978
- if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
1979
- s2.formatter = createClassOnDemand(formatter);
1980
- s2.formatter.init(s2, this.options);
1981
- this.options.interpolation.format = s2.formatter.format.bind(s2.formatter);
1982
- }
1983
- s2.interpolator = new Interpolator(this.options);
1984
- s2.utils = {
1985
- hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
1986
- };
1987
- s2.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s2.resourceStore, s2, this.options);
1988
- s2.backendConnector.on("*", function(event) {
1989
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
1990
- args[_key - 1] = arguments[_key];
1991
- }
1992
- _this.emit(event, ...args);
1993
- });
1994
- if (this.modules.languageDetector) {
1995
- s2.languageDetector = createClassOnDemand(this.modules.languageDetector);
1996
- if (s2.languageDetector.init) s2.languageDetector.init(s2, this.options.detection, this.options);
1997
- }
1998
- if (this.modules.i18nFormat) {
1999
- s2.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
2000
- if (s2.i18nFormat.init) s2.i18nFormat.init(this);
2001
- }
2002
- this.translator = new Translator(this.services, this.options);
2003
- this.translator.on("*", function(event) {
2004
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
2005
- args[_key2 - 1] = arguments[_key2];
2006
- }
2007
- _this.emit(event, ...args);
2008
- });
2009
- this.modules.external.forEach((m) => {
2010
- if (m.init) m.init(this);
2011
- });
2012
- }
2013
- this.format = this.options.interpolation.format;
2014
- if (!callback) callback = noop;
2015
- if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
2016
- const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
2017
- if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
2018
- }
2019
- if (!this.services.languageDetector && !this.options.lng) {
2020
- this.logger.warn("init: no languageDetector is used and no lng is defined");
2021
- }
2022
- const storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
2023
- storeApi.forEach((fcName) => {
2024
- this[fcName] = function() {
2025
- return _this.store[fcName](...arguments);
2026
- };
2027
- });
2028
- const storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
2029
- storeApiChained.forEach((fcName) => {
2030
- this[fcName] = function() {
2031
- _this.store[fcName](...arguments);
2032
- return _this;
2033
- };
2034
- });
2035
- const deferred = defer();
2036
- const load = () => {
2037
- const finish = (err, t2) => {
2038
- this.isInitializing = false;
2039
- if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
2040
- this.isInitialized = true;
2041
- if (!this.options.isClone) this.logger.log("initialized", this.options);
2042
- this.emit("initialized", this.options);
2043
- deferred.resolve(t2);
2044
- callback(err, t2);
2045
- };
2046
- if (this.languages && this.options.compatibilityAPI !== "v1" && !this.isInitialized) return finish(null, this.t.bind(this));
2047
- this.changeLanguage(this.options.lng, finish);
2048
- };
2049
- if (this.options.resources || !this.options.initImmediate) {
2050
- load();
2051
- } else {
2052
- setTimeout(load, 0);
2053
- }
2054
- return deferred;
2055
- }
2056
- loadResources(language) {
2057
- let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
2058
- let usedCallback = callback;
2059
- const usedLng = isString(language) ? language : this.language;
2060
- if (typeof language === "function") usedCallback = language;
2061
- if (!this.options.resources || this.options.partialBundledLanguages) {
2062
- if (usedLng && usedLng.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
2063
- const toLoad = [];
2064
- const append = (lng) => {
2065
- if (!lng) return;
2066
- if (lng === "cimode") return;
2067
- const lngs = this.services.languageUtils.toResolveHierarchy(lng);
2068
- lngs.forEach((l) => {
2069
- if (l === "cimode") return;
2070
- if (toLoad.indexOf(l) < 0) toLoad.push(l);
2071
- });
2072
- };
2073
- if (!usedLng) {
2074
- const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
2075
- fallbacks.forEach((l) => append(l));
2076
- } else {
2077
- append(usedLng);
2078
- }
2079
- if (this.options.preload) {
2080
- this.options.preload.forEach((l) => append(l));
2081
- }
2082
- this.services.backendConnector.load(toLoad, this.options.ns, (e) => {
2083
- if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
2084
- usedCallback(e);
2085
- });
2086
- } else {
2087
- usedCallback(null);
2088
- }
2089
- }
2090
- reloadResources(lngs, ns, callback) {
2091
- const deferred = defer();
2092
- if (typeof lngs === "function") {
2093
- callback = lngs;
2094
- lngs = void 0;
2095
- }
2096
- if (typeof ns === "function") {
2097
- callback = ns;
2098
- ns = void 0;
2099
- }
2100
- if (!lngs) lngs = this.languages;
2101
- if (!ns) ns = this.options.ns;
2102
- if (!callback) callback = noop;
2103
- this.services.backendConnector.reload(lngs, ns, (err) => {
2104
- deferred.resolve();
2105
- callback(err);
2106
- });
2107
- return deferred;
2108
- }
2109
- use(module) {
2110
- if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
2111
- if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
2112
- if (module.type === "backend") {
2113
- this.modules.backend = module;
2114
- }
2115
- if (module.type === "logger" || module.log && module.warn && module.error) {
2116
- this.modules.logger = module;
2117
- }
2118
- if (module.type === "languageDetector") {
2119
- this.modules.languageDetector = module;
2120
- }
2121
- if (module.type === "i18nFormat") {
2122
- this.modules.i18nFormat = module;
2123
- }
2124
- if (module.type === "postProcessor") {
2125
- postProcessor.addPostProcessor(module);
2126
- }
2127
- if (module.type === "formatter") {
2128
- this.modules.formatter = module;
2129
- }
2130
- if (module.type === "3rdParty") {
2131
- this.modules.external.push(module);
2132
- }
2133
- return this;
2134
- }
2135
- setResolvedLanguage(l) {
2136
- if (!l || !this.languages) return;
2137
- if (["cimode", "dev"].indexOf(l) > -1) return;
2138
- for (let li = 0; li < this.languages.length; li++) {
2139
- const lngInLngs = this.languages[li];
2140
- if (["cimode", "dev"].indexOf(lngInLngs) > -1) continue;
2141
- if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
2142
- this.resolvedLanguage = lngInLngs;
2143
- break;
2144
- }
2145
- }
2146
- }
2147
- changeLanguage(lng, callback) {
2148
- var _this2 = this;
2149
- this.isLanguageChangingTo = lng;
2150
- const deferred = defer();
2151
- this.emit("languageChanging", lng);
2152
- const setLngProps = (l) => {
2153
- this.language = l;
2154
- this.languages = this.services.languageUtils.toResolveHierarchy(l);
2155
- this.resolvedLanguage = void 0;
2156
- this.setResolvedLanguage(l);
2157
- };
2158
- const done = (err, l) => {
2159
- if (l) {
2160
- setLngProps(l);
2161
- this.translator.changeLanguage(l);
2162
- this.isLanguageChangingTo = void 0;
2163
- this.emit("languageChanged", l);
2164
- this.logger.log("languageChanged", l);
2165
- } else {
2166
- this.isLanguageChangingTo = void 0;
2167
- }
2168
- deferred.resolve(function() {
2169
- return _this2.t(...arguments);
2170
- });
2171
- if (callback) callback(err, function() {
2172
- return _this2.t(...arguments);
2173
- });
2174
- };
2175
- const setLng = (lngs) => {
2176
- if (!lng && !lngs && this.services.languageDetector) lngs = [];
2177
- const l = isString(lngs) ? lngs : this.services.languageUtils.getBestMatchFromCodes(lngs);
2178
- if (l) {
2179
- if (!this.language) {
2180
- setLngProps(l);
2181
- }
2182
- if (!this.translator.language) this.translator.changeLanguage(l);
2183
- if (this.services.languageDetector && this.services.languageDetector.cacheUserLanguage) this.services.languageDetector.cacheUserLanguage(l);
2184
- }
2185
- this.loadResources(l, (err) => {
2186
- done(err, l);
2187
- });
2188
- };
2189
- if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
2190
- setLng(this.services.languageDetector.detect());
2191
- } else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
2192
- if (this.services.languageDetector.detect.length === 0) {
2193
- this.services.languageDetector.detect().then(setLng);
2194
- } else {
2195
- this.services.languageDetector.detect(setLng);
2196
- }
2197
- } else {
2198
- setLng(lng);
2199
- }
2200
- return deferred;
2201
- }
2202
- getFixedT(lng, ns, keyPrefix) {
2203
- var _this3 = this;
2204
- const fixedT = function(key, opts) {
2205
- let options;
2206
- if (typeof opts !== "object") {
2207
- for (var _len3 = arguments.length, rest = new Array(_len3 > 2 ? _len3 - 2 : 0), _key3 = 2; _key3 < _len3; _key3++) {
2208
- rest[_key3 - 2] = arguments[_key3];
2209
- }
2210
- options = _this3.options.overloadTranslationOptionHandler([key, opts].concat(rest));
2211
- } else {
2212
- options = {
2213
- ...opts
2214
- };
2215
- }
2216
- options.lng = options.lng || fixedT.lng;
2217
- options.lngs = options.lngs || fixedT.lngs;
2218
- options.ns = options.ns || fixedT.ns;
2219
- if (options.keyPrefix !== "") options.keyPrefix = options.keyPrefix || keyPrefix || fixedT.keyPrefix;
2220
- const keySeparator = _this3.options.keySeparator || ".";
2221
- let resultKey;
2222
- if (options.keyPrefix && Array.isArray(key)) {
2223
- resultKey = key.map((k) => `${options.keyPrefix}${keySeparator}${k}`);
2224
- } else {
2225
- resultKey = options.keyPrefix ? `${options.keyPrefix}${keySeparator}${key}` : key;
2226
- }
2227
- return _this3.t(resultKey, options);
2228
- };
2229
- if (isString(lng)) {
2230
- fixedT.lng = lng;
2231
- } else {
2232
- fixedT.lngs = lng;
2233
- }
2234
- fixedT.ns = ns;
2235
- fixedT.keyPrefix = keyPrefix;
2236
- return fixedT;
2237
- }
2238
- t() {
2239
- return this.translator && this.translator.translate(...arguments);
2240
- }
2241
- exists() {
2242
- return this.translator && this.translator.exists(...arguments);
2243
- }
2244
- setDefaultNamespace(ns) {
2245
- this.options.defaultNS = ns;
2246
- }
2247
- hasLoadedNamespace(ns) {
2248
- let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
2249
- if (!this.isInitialized) {
2250
- this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
2251
- return false;
2252
- }
2253
- if (!this.languages || !this.languages.length) {
2254
- this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
2255
- return false;
2256
- }
2257
- const lng = options.lng || this.resolvedLanguage || this.languages[0];
2258
- const fallbackLng = this.options ? this.options.fallbackLng : false;
2259
- const lastLng = this.languages[this.languages.length - 1];
2260
- if (lng.toLowerCase() === "cimode") return true;
2261
- const loadNotPending = (l, n2) => {
2262
- const loadState = this.services.backendConnector.state[`${l}|${n2}`];
2263
- return loadState === -1 || loadState === 0 || loadState === 2;
2264
- };
2265
- if (options.precheck) {
2266
- const preResult = options.precheck(this, loadNotPending);
2267
- if (preResult !== void 0) return preResult;
2268
- }
2269
- if (this.hasResourceBundle(lng, ns)) return true;
2270
- if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
2271
- if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
2272
- return false;
2273
- }
2274
- loadNamespaces(ns, callback) {
2275
- const deferred = defer();
2276
- if (!this.options.ns) {
2277
- if (callback) callback();
2278
- return Promise.resolve();
2279
- }
2280
- if (isString(ns)) ns = [ns];
2281
- ns.forEach((n2) => {
2282
- if (this.options.ns.indexOf(n2) < 0) this.options.ns.push(n2);
2283
- });
2284
- this.loadResources((err) => {
2285
- deferred.resolve();
2286
- if (callback) callback(err);
2287
- });
2288
- return deferred;
2289
- }
2290
- loadLanguages(lngs, callback) {
2291
- const deferred = defer();
2292
- if (isString(lngs)) lngs = [lngs];
2293
- const preloaded = this.options.preload || [];
2294
- const newLngs = lngs.filter((lng) => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
2295
- if (!newLngs.length) {
2296
- if (callback) callback();
2297
- return Promise.resolve();
2298
- }
2299
- this.options.preload = preloaded.concat(newLngs);
2300
- this.loadResources((err) => {
2301
- deferred.resolve();
2302
- if (callback) callback(err);
2303
- });
2304
- return deferred;
2305
- }
2306
- dir(lng) {
2307
- if (!lng) lng = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language);
2308
- if (!lng) return "rtl";
2309
- const rtlLngs = ["ar", "shu", "sqr", "ssh", "xaa", "yhd", "yud", "aao", "abh", "abv", "acm", "acq", "acw", "acx", "acy", "adf", "ads", "aeb", "aec", "afb", "ajp", "apc", "apd", "arb", "arq", "ars", "ary", "arz", "auz", "avl", "ayh", "ayl", "ayn", "ayp", "bbz", "pga", "he", "iw", "ps", "pbt", "pbu", "pst", "prp", "prd", "ug", "ur", "ydd", "yds", "yih", "ji", "yi", "hbo", "men", "xmn", "fa", "jpr", "peo", "pes", "prs", "dv", "sam", "ckb"];
2310
- const languageUtils = this.services && this.services.languageUtils || new LanguageUtil(get());
2311
- return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
2312
- }
2313
- static createInstance() {
2314
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
2315
- let callback = arguments.length > 1 ? arguments[1] : void 0;
2316
- return new I18n(options, callback);
2317
- }
2318
- cloneInstance() {
2319
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
2320
- let callback = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : noop;
2321
- const forkResourceStore = options.forkResourceStore;
2322
- if (forkResourceStore) delete options.forkResourceStore;
2323
- const mergedOptions = {
2324
- ...this.options,
2325
- ...options,
2326
- ...{
2327
- isClone: true
2328
- }
2329
- };
2330
- const clone = new I18n(mergedOptions);
2331
- if (options.debug !== void 0 || options.prefix !== void 0) {
2332
- clone.logger = clone.logger.clone(options);
2333
- }
2334
- const membersToCopy = ["store", "services", "language"];
2335
- membersToCopy.forEach((m) => {
2336
- clone[m] = this[m];
2337
- });
2338
- clone.services = {
2339
- ...this.services
2340
- };
2341
- clone.services.utils = {
2342
- hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
2343
- };
2344
- if (forkResourceStore) {
2345
- clone.store = new ResourceStore(this.store.data, mergedOptions);
2346
- clone.services.resourceStore = clone.store;
2347
- }
2348
- clone.translator = new Translator(clone.services, mergedOptions);
2349
- clone.translator.on("*", function(event) {
2350
- for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
2351
- args[_key4 - 1] = arguments[_key4];
2352
- }
2353
- clone.emit(event, ...args);
2354
- });
2355
- clone.init(mergedOptions, callback);
2356
- clone.translator.options = mergedOptions;
2357
- clone.translator.backendConnector.services.utils = {
2358
- hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone)
2359
- };
2360
- return clone;
2361
- }
2362
- toJSON() {
2363
- return {
2364
- options: this.options,
2365
- store: this.store,
2366
- language: this.language,
2367
- languages: this.languages,
2368
- resolvedLanguage: this.resolvedLanguage
2369
- };
2370
- }
2371
- }
2372
- const instance = I18n.createInstance();
2373
- instance.createInstance = I18n.createInstance;
2374
- instance.createInstance;
2375
- instance.dir;
2376
- instance.init;
2377
- instance.loadResources;
2378
- instance.reloadResources;
2379
- instance.use;
2380
- instance.changeLanguage;
2381
- instance.getFixedT;
2382
- const t = instance.t;
2383
- instance.exists;
2384
- instance.setDefaultNamespace;
2385
- instance.hasLoadedNamespace;
2386
- instance.loadNamespaces;
2387
- instance.loadLanguages;
2388
- const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
2389
- const htmlEntities = {
2390
- "&amp;": "&",
2391
- "&#38;": "&",
2392
- "&lt;": "<",
2393
- "&#60;": "<",
2394
- "&gt;": ">",
2395
- "&#62;": ">",
2396
- "&apos;": "'",
2397
- "&#39;": "'",
2398
- "&quot;": '"',
2399
- "&#34;": '"',
2400
- "&nbsp;": " ",
2401
- "&#160;": " ",
2402
- "&copy;": "©",
2403
- "&#169;": "©",
2404
- "&reg;": "®",
2405
- "&#174;": "®",
2406
- "&hellip;": "…",
2407
- "&#8230;": "…",
2408
- "&#x2F;": "/",
2409
- "&#47;": "/"
2410
- };
2411
- const unescapeHtmlEntity = (m) => htmlEntities[m];
2412
- const unescape = (text) => text.replace(matchHtmlEntity, unescapeHtmlEntity);
2413
- let defaultOptions = {
2414
- bindI18n: "languageChanged",
2415
- bindI18nStore: "",
2416
- transEmptyNodeValue: "",
2417
- transSupportBasicHtmlNodes: true,
2418
- transWrapTextNodes: "",
2419
- transKeepBasicHtmlNodesFor: ["br", "strong", "i", "p"],
2420
- useSuspense: true,
2421
- unescape
2422
- };
2423
- function setDefaults() {
2424
- let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
2425
- defaultOptions = {
2426
- ...defaultOptions,
2427
- ...options
2428
- };
2429
- }
2430
- function getDefaults() {
2431
- return defaultOptions;
2432
- }
2433
- let i18nInstance;
2434
- function setI18n(instance2) {
2435
- i18nInstance = instance2;
2436
- }
2437
- function getI18n() {
2438
- return i18nInstance;
2439
- }
2440
- const initReactI18next = {
2441
- type: "3rdParty",
2442
- init(instance2) {
2443
- setDefaults(instance2.options.react);
2444
- setI18n(instance2);
2445
- }
2446
- };
2447
- const common = { "cancel": "Cancel", "delete": "Delete", "continue": "Continue", "empty": "Empty", "create": "Create", "save": "Save", "export": "Export", "reload": "Reload", "reloadConnect": "Click here to reload Connect" };
2448
- const searchbar = { "placeholder": "Search Powerhouse", "filterLabel": "File type" };
2449
- const folderView = { "sections": { "folders": { "title": "Folders", "empty": "No folders 🗂️" }, "documents": { "title": "Documents and files", "empty": "No documents or files 📄" } } };
2450
- const files$1 = { "options": { "switchboardLink": "Switchboard Link" } };
2451
- const modals = { "deleteItem": { "folder": { "header": "Delete “{{item}}” folder?", "body": "Are you sure you want to delete this folder? All files and subfolders within it will be removed." }, "file": { "header": "Delete “{{item}}” file?", "body": "Are you sure you want to delete this file?" } }, "deleteDrive": { "title": 'Delete "{{label}}" drive?', "body": "Are you sure you want to delete this drive? All files and subfolders within it will be removed. Do you want to proceed?", "inputPlaceholder": "Enter drive name..." }, "upgradeDrive": { "header": "Upgrade to cloud drive", "body": "You are moving files from a private to a shared drive. These files will become accessible to others in the shared drive.Do you want to proceed?" }, "createDocument": { "header": "Create a new document", "placeholder": "Document name" }, "connectSettings": { "title": "Settings", "body": "These settings will apply to all drives.", "clearStorage": { "button": "Clear Storage", "description": "Delete previous session data", "confirmation": { "title": "Clear Storage", "body": "Are you sure you want to clear the storage? This will remove all previous session data.", "clearButton": "Clear Storage" } }, "enabledDocumentTypes": { "title": "Document Models", "description": "Documents enabled", "allSelected": "All documents are selected" } }, "exportDocumentWithErrors": { "title": "Your document contains errors", "body": "Your document contains structure errors. Do you want to export it anyway?" }, "disclaimer": { "title": "Disclaimer", "body": "All content provided herein our website, hyperlinked sites, associated applications, forums, blogs, social media accounts and other platforms (“Site”) is for your general information only, procured from third party sources. We make no warranties of any kind in relation to our content, including but not limited to accuracy and updatedness. No part of the content that we provide constitutes financial advice, legal advice or any other form of advice meant for your specific reliance for any purpose. Any use or reliance on our content is solely at your own risk and discretion. You should conduct your own research, review, analyse and verify our content before relying on them. Trading is a highly risky activity that can lead to major losses, please therefore consult your financial advisor before making any decision. No content on our Site is meant to be a solicitation or offer." }, "cookiesPolicy": { "title": "Cookies Policy", "body": "<subtitle>Use of Cookies and Similar Technologies</subtitle><p>The Site is using cookies. Cookies are small text files that are placed on your computer by websites that you visit. They are widely used in order to make websites work, or work more efficiently, as well as to provide information to the owners of the site. Cookies are typically stored on your computer´s hard drive.Information collected from cookies is used by us to evaluate the effectiveness of our Site and analyze trends. The information collected from cookies allows us to determine such things as which parts of the Site are most visited and difficulties our visitors may experience in accessing the SIte. With this knowledge, we can improve the quality of your experience on the Site by recognizing and delivering more of the most desired features and information, as well as by resolving access difficulties.</p><p>We use third party service providers, to assist us in better understanding the use of our Site. Our service providers will place cookies on the hard drive of your computer (or use similar technologies) and will receive information that we select that will educate us on such things as how visitors navigate around our Site. This information is aggregated to provide statistical data about our users browsing actions and patterns, and does not personally identify individuals. This information may include:</p><p>Computer or mobile device information, Website usage information, such as:<list></p><bullet>Page views,</bullet><bullet>Button clicks,</bullet><bullet>Input form changes (without the values being entered),</bullet><bullet>Errors.</bullet></list><p>Our service providers analyses this information and provides us with aggregate reports. The information and analysis provided by our service providers will be used to assist us in better understanding our visitors interests in our Site and how to better serve those interests. If you want to avoid using cookies altogether, you can disable cookies in your browser. However, disabling cookies might make it impossible for you to use certain features of the Site. Your use of the Site with a browser that is configured to accept cookies constitutes an acceptance of our and third-party cookies.</p>" } };
2452
- const notifications = { "deleteDriveSuccess": "Drive successfully deleted", "deleteFolderSuccess": "Folder deleted", "fileDeleteSuccess": "File deleted", "addDriveSuccess": "New drive successfully added", "driveSyncSuccess": "Drive synced successfully", "driveSyncError": "Error synchronizing drive {{drive}}", "driveSyncConflict": "Conflict error detected in {{drive}}", "reloadApp": "It seems like you're running an outdated version of the app. Please reload Connect to get the latest version." };
2453
- const footer = { "cookiePolicy": "Cookie Policy", "termsOfUse": "Terms of Use", "disclaimer": "Disclaimer", "builtWith": "Built with <icon /> Powerhouse" };
2454
- const cookieBanner = { "message": "This website uses cookies for analytic purposes only. Cookies are anonymous and do not link to user data. We collect information to improve the user experience and validate UI changes. You can still use the page without cookies. For more information, please read our <a>cookies policy.</a>", "accept": "Accept configured cookies", "reject": "Reject all cookies", "cookies": { "functional": "Functional cookies", "analytics": "Analytics cookies" } };
2455
- const translationEN = {
2456
- common,
2457
- searchbar,
2458
- folderView,
2459
- files: files$1,
2460
- modals,
2461
- notifications,
2462
- footer,
2463
- cookieBanner
2464
- };
2465
- const resources = {
2466
- en: {
2467
- code: "en",
2468
- name: "English",
2469
- translation: translationEN
2470
- }
2471
- };
2472
- instance.use(initReactI18next).init({
2473
- resources,
2474
- fallbackLng: "en",
2475
- debug: true,
2476
- interpolation: {
2477
- escapeValue: false
2478
- }
2479
- });
2480
- class DocumentEditorDebugTools {
2481
- constructor(document) {
2482
- __publicField(this, "document");
2483
- __publicField(this, "operations", []);
2484
- if (document) {
2485
- this.document = document;
2486
- }
2487
- }
2488
- operationsToTableObject(operations) {
2489
- return operations.map((op) => ({
2490
- ...op,
2491
- input: JSON.stringify(op.input)
2492
- }));
2493
- }
2494
- setDocument(document) {
2495
- this.document = document;
2496
- }
2497
- getDocument() {
2498
- return this.document;
2499
- }
2500
- getOperations() {
2501
- return this.operations;
2502
- }
2503
- pushOperation(operation) {
2504
- this.operations.push(operation);
2505
- }
2506
- operationsTable() {
2507
- var _a;
2508
- if (!this.document) {
2509
- console.warn("No document");
2510
- }
2511
- const ops = Object.values(((_a = this.document) == null ? void 0 : _a.operations) || {}).flatMap((array) => array).sort((a, b) => a.index - b.index);
2512
- console.table(this.operationsToTableObject(ops));
2513
- }
2514
- scopeOperationsTable(scope) {
2515
- var _a;
2516
- if (!this.document) {
2517
- console.warn("No document");
2518
- }
2519
- const ops = ((_a = this.document) == null ? void 0 : _a.operations[scope]) || [];
2520
- console.table(this.operationsToTableObject(ops));
2521
- }
2522
- operationsLog() {
2523
- console.log(this.operations);
2524
- }
2525
- operationsLogTable() {
2526
- console.table(this.operationsToTableObject(this.operations));
2527
- }
2528
- clear() {
2529
- this.operations = [];
2530
- this.document = void 0;
2531
- }
2532
- }
2533
- const L = "SWITCHBOARD", o = "LOCAL", s = "CLOUD", n = "PUBLIC";
2534
- var define_process_env_default = {};
2535
- const LEVELS = {
2536
- verbose: 1,
2537
- debug: 2,
2538
- info: 3,
2539
- warn: 4,
2540
- error: 5,
2541
- silent: 6
2542
- };
2543
- class ConsoleLogger {
2544
- constructor(tags, errorHandler2) {
2545
- __privateAdd(this, _ConsoleLogger_instances);
2546
- __privateAdd(this, _tags);
2547
- __privateAdd(this, _levelString, "env");
2548
- __privateAdd(this, _errorHandler);
2549
- __privateSet(this, _tags, (tags || []).map((tag) => `[${tag}]`));
2550
- __privateSet(this, _errorHandler, errorHandler2);
2551
- this.log = this.log.bind(this);
2552
- this.info = this.info.bind(this);
2553
- this.warn = this.warn.bind(this);
2554
- this.error = this.error.bind(this);
2555
- this.debug = this.debug.bind(this);
2556
- this.verbose = this.verbose.bind(this);
2557
- }
2558
- get level() {
2559
- return __privateGet(this, _levelString);
2560
- }
2561
- set level(level) {
2562
- __privateSet(this, _levelString, level);
2563
- }
2564
- get errorHandler() {
2565
- return __privateGet(this, _errorHandler);
2566
- }
2567
- set errorHandler(handler) {
2568
- __privateSet(this, _errorHandler, handler);
2569
- }
2570
- log(...data) {
2571
- return this.debug(...data);
2572
- }
2573
- verbose(...data) {
2574
- if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.verbose) {
2575
- return;
2576
- }
2577
- return this.debug(...data);
2578
- }
2579
- debug(...data) {
2580
- if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.debug) {
2581
- return;
2582
- }
2583
- return console.debug(...[...__privateGet(this, _tags), ...data]);
2584
- }
2585
- info(...data) {
2586
- if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.info) {
2587
- return;
2588
- }
2589
- return console.info(...[...__privateGet(this, _tags), ...data]);
2590
- }
2591
- warn(...data) {
2592
- if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.warn) {
2593
- return;
2594
- }
2595
- return console.warn(...[...__privateGet(this, _tags), ...data]);
2596
- }
2597
- error(...data) {
2598
- if (__privateGet(this, _ConsoleLogger_instances, levelValue_get) > LEVELS.error) {
2599
- return;
2600
- }
2601
- if (__privateGet(this, _errorHandler)) {
2602
- __privateGet(this, _errorHandler).call(this, ...data);
2603
- }
2604
- return console.error(...[...__privateGet(this, _tags), ...data]);
2605
- }
2606
- }
2607
- _tags = new WeakMap();
2608
- _levelString = new WeakMap();
2609
- _errorHandler = new WeakMap();
2610
- _ConsoleLogger_instances = new WeakSet();
2611
- levelValue_get = function() {
2612
- if (__privateGet(this, _levelString) === "env") {
2613
- const envLevel = define_process_env_default.LOG_LEVEL;
2614
- if (!envLevel) {
2615
- return LEVELS.debug;
2616
- }
2617
- if (!(envLevel in LEVELS)) {
2618
- return LEVELS.debug;
2619
- }
2620
- return LEVELS[envLevel];
2621
- }
2622
- return LEVELS[__privateGet(this, _levelString)];
2623
- };
2624
- const loggerInstance = new ConsoleLogger();
2625
- let logLevel = "env";
2626
- let errorHandler;
2627
- loggerInstance.level = logLevel;
2628
- loggerInstance.errorHandler = errorHandler;
2629
- const logger = loggerInstance;
2630
- const setLogLevel = (level) => {
2631
- logLevel = level;
2632
- loggerInstance.level = level;
2633
- };
2634
- const childLogger = (tags) => {
2635
- const logger2 = new ConsoleLogger(tags);
2636
- logger2.level = logLevel;
2637
- logger2.errorHandler = errorHandler;
2638
- return logger2;
2639
- };
2640
- const name = "@powerhousedao/connect";
2641
- const productName = "Powerhouse-Connect";
2642
- const version = "1.0.0-dev.220";
2643
- const description = "Powerhouse Connect";
2644
- const main = "./dist/index.html";
2645
- const imports = { "#*": "./src/*.js" };
2646
- const type = "module";
2647
- const engines = { "node": ">=20.0.0" };
2648
- const files = ["dist", "nginx.conf", "nginx.sh"];
2649
- const license = "AGPL-3.0-only";
2650
- const author = "acaldas@powerhouse.inc";
2651
- const repository = { "type": "git", "url": "git+https://github.com/powerhouse-inc/document-model-electron.git" };
2652
- const bugs = { "url": "https://github.com/powerhouse-inc/document-model-electron/issues" };
2653
- const homepage = "https://github.com/powerhouse-inc/document-model-electron#readme";
2654
- const scripts = { "build:tsc": "tsc --build", "start": "electron-forge start", "package": "electron-forge package", "make": "PH_CONNECT_BASE_HREF=./ electron-forge make", "make:mac": "PH_CONNECT_BASE_HREF=./ electron-forge make -p darwin", "make:linux": "PH_CONNECT_BASE_HREF=./ electron-forge make -p linux", "make:windows": "PH_CONNECT_BASE_HREF=./ electron-forge make -p win32", "publish:electron": "electron-forge publish", "prepublishOnly": "npm run build", "lint": "eslint .", "lint:fix": "eslint --fix .", "format": 'prettier --write "**/*.+(js|ts|jsx|tsx|json)"', "dev:web": "vite -c vite.renderer.config.mts", "dev:nocache": "rm -rf node_modules/.vite && rm -rf node_modules/.cache && npm run dev:web", "build": "NODE_OPTIONS=--max-old-space-size=6144 vite build -c vite.renderer.config.mts", "preview:web": "vite preview -c vite.renderer.config.mts", "e2e": "playwright test", "cy:open": "cypress open", "build:service-worker": "tsc --build ./tsconfig.sw.json" };
2655
- const dependencies = {};
2656
- const devDependencies = { "@electron-forge/cli": "^6.1.1", "@electron-forge/maker-deb": "^6.1.1", "@electron-forge/maker-rpm": "^6.1.1", "@electron-forge/maker-squirrel": "^6.1.1", "@electron-forge/maker-zip": "^6.1.1", "@electron-forge/plugin-vite": "^6.1.1", "@electron-forge/publisher-electron-release-server": "^6.2.1", "@electron-forge/publisher-github": "^7.2.0", "@electron-forge/shared-types": "^7.7.0", "@playwright/test": "^1.41.2", "@powerhousedao/builder-tools": "workspace:*", "@powerhousedao/common": "workspace:*", "@powerhousedao/config": "workspace:*", "@powerhousedao/design-system": "workspace:*", "@powerhousedao/reactor-browser": "workspace:*", "@powerhousedao/scalars": "workspace:*", "@sentry/browser": "^9.1.0", "@sentry/react": "^7.109.0", "@sentry/vite-plugin": "^2.22.2", "@tanstack/react-virtual": "^3.8.1", "@types/react": "^18.2.79", "@types/react-dom": "^18.2.18", "@types/uuid": "^9.0.7", "@types/wicg-file-system-access": "^2020.9.6", "@vitejs/plugin-react": "^4.2.1", "asar": "^3.2.0", "autoprefixer": "^10.4.14", "cypress": "^13.11.0", "did-key-creator": "^1.2.0", "document-drive": "workspace:*", "document-model": "workspace:*", "electron": "30.0.0", "electron-is-dev": "^3.0.1", "electron-playwright-helpers": "^1.7.1", "electron-squirrel-startup": "^1.0.0", "electron-store": "^8.1.0", "esbuild": "^0.24.0", "graphql": "^16.8.1", "graphql-request": "^6.1.0", "i18next": "^23.7.6", "jotai": "^2.1.0", "jotai-effect": "^1.1.6", "localforage": "^1.10.0", "lz-string": "^1.5.0", "playwright": "^1.41.2", "playwright-core": "^1.41.2", "postcss": "^8.4.33", "react": "^18.2.0", "react-dom": "^18.2.0", "react-error-boundary": "^4.0.11", "react-hotkeys-hook": "^4.5.0", "react-i18next": "^13.5.0", "react-router-dom": "^6.11.2", "react-stately": "^3.31.0", "rollup-plugin-node-polyfills": "^0.2.1", "rollup-plugin-shim": "^1.0.0", "sanitize-filename": "^1.6.3", "tailwind-merge": "^1.14.0", "tailwind-scrollbar": "^3.1.0", "tailwindcss": "^3.4.1", "tailwindcss-animate": "^1.0.7", "tw-colors": "^1.2.6", "uuid": "^9.0.1", "viem": "^2.8.13", "vite": "^6.1.1", "vite-envs": "^4.4.11", "vite-plugin-html": "^3.2.2", "vite-plugin-node-polyfills": "^0.23.0", "vite-plugin-svgr": "^4.2.0", "vite-tsconfig-paths": "^4.2.0", "xvfb-maybe": "^0.2.1" };
2657
- const optionalDependencies = { "@esbuild/linux-x64": "^0.21.4", "@rollup/rollup-linux-x64-musl": "4.14.3" };
2658
- const packageJson = {
2659
- name,
2660
- productName,
2661
- version,
2662
- description,
2663
- main,
2664
- imports,
2665
- type,
2666
- engines,
2667
- files,
2668
- license,
2669
- author,
2670
- repository,
2671
- bugs,
2672
- homepage,
2673
- scripts,
2674
- dependencies,
2675
- devDependencies,
2676
- optionalDependencies
2677
- };
2678
- const APP_VERSION = window.__VITE_ENVS.APP_VERSION || version;
2679
- const WARN_OUTDATED_APP = window.__VITE_ENVS.PH_CONNECT_WARN_OUTDATED_APP || "false";
2680
- const PH_CONNECT_STUDIO_MODE = window.__VITE_ENVS.PH_CONNECT_STUDIO_MODE || "false";
2681
- const DISABLE_ADD_PUBLIC_DRIVES = window.__VITE_ENVS.PH_CONNECT_DISABLE_ADD_PUBLIC_DRIVES || void 0;
2682
- const DISABLE_ADD_CLOUD_DRIVES = window.__VITE_ENVS.PH_CONNECT_DISABLE_ADD_CLOUD_DRIVES || void 0;
2683
- const DISABLE_ADD_LOCAL_DRIVES = window.__VITE_ENVS.PH_CONNECT_DISABLE_ADD_LOCAL_DRIVES || void 0;
2684
- const DISABLE_DELETE_PUBLIC_DRIVES = window.__VITE_ENVS.PH_CONNECT_DISABLE_DELETE_PUBLIC_DRIVES || void 0;
2685
- const DISABLE_DELETE_CLOUD_DRIVES = window.__VITE_ENVS.PH_CONNECT_DISABLE_DELETE_CLOUD_DRIVES || void 0;
2686
- const DISABLE_DELETE_LOCAL_DRIVES = window.__VITE_ENVS.PH_CONNECT_DISABLE_DELETE_LOCAL_DRIVES || void 0;
2687
- const LOCAL_DRIVES_ENABLED = window.__VITE_ENVS.PH_CONNECT_LOCAL_DRIVES_ENABLED || void 0;
2688
- const CLOUD_DRIVES_ENABLED = window.__VITE_ENVS.PH_CONNECT_CLOUD_DRIVES_ENABLED || void 0;
2689
- const PUBLIC_DRIVES_ENABLED = window.__VITE_ENVS.PH_CONNECT_PUBLIC_DRIVES_ENABLED || void 0;
2690
- const SEARCH_BAR_ENABLED = window.__VITE_ENVS.PH_CONNECT_SEARCH_BAR_ENABLED || void 0;
2691
- const HIDE_DOCUMENT_MODEL_SELECTION_SETTINGS = window.__VITE_ENVS.PH_CONNECT_HIDE_DOCUMENT_MODEL_SELECTION_SETTINGS || "false";
2692
- const PH_CONNECT_ROUTER_BASENAME = window.__VITE_ENVS.PH_CONNECT_ROUTER_BASENAME || "/";
2693
- const PH_CONNECT_SENTRY_DSN = window.__VITE_ENVS.PH_CONNECT_SENTRY_DSN || "";
2694
- const PH_CONNECT_SENTRY_ENV = window.__VITE_ENVS.PH_CONNECT_SENTRY_ENV || "dev";
2695
- const PH_CONNECT_SENTRY_TRACING_ENABLED = window.__VITE_ENVS.PH_CONNECT_SENTRY_TRACING_ENABLED || "false";
2696
- const GA_TRACKING_ID = window.__VITE_ENVS.PH_CONNECT_GA_TRACKING_ID;
2697
- const PH_CONNECT_CLI_VERSION = window.__VITE_ENVS.PH_CONNECT_CLI_VERSION || void 0;
2698
- setLogLevel(window.__VITE_ENVS.LOG_LEVEL);
2699
- logger.info(`Setting log level to ${window.__VITE_ENVS.LOG_LEVEL}.`);
2700
- const connectConfig = {
2701
- appVersion: APP_VERSION,
2702
- studioMode: PH_CONNECT_STUDIO_MODE.toString() === "true",
2703
- warnOutdatedApp: WARN_OUTDATED_APP === "true",
2704
- routerBasename: PH_CONNECT_ROUTER_BASENAME,
2705
- sentry: {
2706
- dsn: PH_CONNECT_SENTRY_DSN,
2707
- env: PH_CONNECT_SENTRY_ENV,
2708
- tracing: PH_CONNECT_SENTRY_TRACING_ENABLED === "true"
2709
- },
2710
- content: {
2711
- showSearchBar: SEARCH_BAR_ENABLED !== "false",
2712
- showDocumentModelSelectionSetting: HIDE_DOCUMENT_MODEL_SELECTION_SETTINGS !== "true"
2713
- },
2714
- drives: {
2715
- sections: {
2716
- [o]: {
2717
- enabled: LOCAL_DRIVES_ENABLED !== "false",
2718
- allowAdd: DISABLE_ADD_LOCAL_DRIVES !== "true",
2719
- allowDelete: DISABLE_DELETE_LOCAL_DRIVES !== "true"
2720
- },
2721
- [s]: {
2722
- enabled: CLOUD_DRIVES_ENABLED !== "false",
2723
- allowAdd: DISABLE_ADD_CLOUD_DRIVES !== "true",
2724
- allowDelete: DISABLE_DELETE_CLOUD_DRIVES !== "true"
2725
- },
2726
- [n]: {
2727
- enabled: PUBLIC_DRIVES_ENABLED !== "false",
2728
- allowAdd: DISABLE_ADD_PUBLIC_DRIVES !== "true",
2729
- allowDelete: DISABLE_DELETE_PUBLIC_DRIVES !== "true"
2730
- }
2731
- }
2732
- },
2733
- gaTrackingId: GA_TRACKING_ID,
2734
- phCliVersion: PH_CONNECT_CLI_VERSION
2735
- };
2736
- const VERSION_CHECK_INTERVAL = parseInt(window.__VITE_ENVS.PH_CONNECT_VERSION_CHECK_INTERVAL) || 60 * 60 * 1e3;
2737
- const basePath = connectConfig.routerBasename;
2738
- const serviceWorkerScriptPath = [basePath, "service-worker.js"].join("/").replace(/\/{2,}/gm, "/");
2739
- class ServiceWorkerManager {
2740
- constructor(debug = false) {
2741
- __privateAdd(this, _ServiceWorkerManager_instances);
2742
- __publicField(this, "ready", false);
2743
- __publicField(this, "debug", false);
2744
- __publicField(this, "registration", null);
2745
- this.debug = debug;
2746
- }
2747
- setDebug(debug) {
2748
- this.debug = debug;
2749
- }
2750
- registerServiceWorker(debug = false) {
2751
- this.debug = debug;
2752
- if (!("serviceWorker" in navigator)) {
2753
- console.warn("Service Worker not available");
2754
- return;
2755
- }
2756
- window.addEventListener("load", async () => {
2757
- try {
2758
- const existingRegistration = await navigator.serviceWorker.getRegistration();
2759
- if (existingRegistration) {
2760
- await existingRegistration.update();
2761
- __privateMethod(this, _ServiceWorkerManager_instances, handleServiceWorker_fn).call(this, existingRegistration);
2762
- } else {
2763
- const registration = await navigator.serviceWorker.register(
2764
- serviceWorkerScriptPath
2765
- );
2766
- __privateMethod(this, _ServiceWorkerManager_instances, handleServiceWorker_fn).call(this, registration);
2767
- registration.addEventListener("updatefound", () => {
2768
- __privateMethod(this, _ServiceWorkerManager_instances, handleServiceWorker_fn).call(this, registration);
2769
- });
2770
- }
2771
- const intervalId = setInterval(async () => {
2772
- const existingRegistration2 = await navigator.serviceWorker.getRegistration();
2773
- if (existingRegistration2) {
2774
- await existingRegistration2.update();
2775
- } else {
2776
- clearInterval(intervalId);
2777
- this.registerServiceWorker();
2778
- }
2779
- }, VERSION_CHECK_INTERVAL);
2780
- } catch (error) {
2781
- console.error("ServiceWorker registration failed: ", error);
2782
- }
2783
- });
2784
- }
2785
- }
2786
- _ServiceWorkerManager_instances = new WeakSet();
2787
- handleServiceWorkerMessage_fn = function(event) {
2788
- if (this.debug) {
2789
- console.log("ServiceWorker message: ", event);
2790
- }
2791
- const message = "type" in event.data ? event : null;
2792
- switch (message == null ? void 0 : message.data.type) {
2793
- case "NEW_VERSION_AVAILABLE": {
2794
- if (message.data.version === connectConfig.appVersion) {
2795
- return;
2796
- }
2797
- if (message.data.requiresHardRefresh) {
2798
- if (this.debug) {
2799
- console.log("New version available");
2800
- }
2801
- window.location.reload();
2802
- }
2803
- break;
2804
- }
2805
- default: {
2806
- console.warn("Unhandled message:", message);
2807
- break;
2808
- }
2809
- }
2810
- };
2811
- handleServiceWorker_fn = function(registration) {
2812
- {
2813
- if (this.debug) {
2814
- console.log("ServiceWorker registered: ", registration);
2815
- }
2816
- navigator.serviceWorker.addEventListener(
2817
- "message",
2818
- __privateMethod(this, _ServiceWorkerManager_instances, handleServiceWorkerMessage_fn).bind(this)
2819
- );
2820
- this.registration = registration;
2821
- this.ready = true;
2822
- }
2823
- };
2824
- const serviceWorkerManager = new ServiceWorkerManager();
2825
- if (window.__VITE_ENVS.MODE === "development") {
2826
- window.documentEditorDebugTools = new DocumentEditorDebugTools();
2827
- } else {
2828
- serviceWorkerManager.registerServiceWorker(false);
2829
- }
2830
- const App = lazy(() => __vitePreload(() => import("./app-oYMmxEg4.js").then((n2) => n2.dm), true ? __vite__mapDeps([0,1]) : void 0));
2831
- const AppLoader = /* @__PURE__ */ jsx(Suspense, { children: /* @__PURE__ */ jsx(App, {}) });
2832
- const appLoader = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
2833
- __proto__: null,
2834
- default: AppLoader
2835
- }, Symbol.toStringTag, { value: "Module" }));
2836
- export {
2837
- L,
2838
- getDefaults as a,
2839
- childLogger as b,
2840
- connectConfig as c,
2841
- serviceWorkerManager as d,
2842
- appLoader as e,
2843
- getI18n as g,
2844
- logger as l,
2845
- n,
2846
- o,
2847
- packageJson as p,
2848
- s,
2849
- t
2850
- };