tiny-essentials 1.28.19 → 1.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (556) hide show
  1. package/README.md +1 -1
  2. package/changelog/1/28/19.md +24 -0
  3. package/changelog/1/29/0.md +58 -0
  4. package/changelog/1/29/1.md +11 -0
  5. package/dist/v1/ColorSafeStringify.min.js +1 -1
  6. package/dist/v1/TinyAdvancedRaffle.min.js +1 -1
  7. package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
  8. package/dist/v1/TinyAnalogClock.min.js +1 -1
  9. package/dist/v1/TinyArrayComparator.min.js +1 -1
  10. package/dist/v1/TinyArrayPaginator.min.js +1 -1
  11. package/dist/v1/TinyBasicsEs.min.js +1 -1
  12. package/dist/v1/TinyBrowserMonitor.min.js +1 -0
  13. package/dist/v1/TinyClassManager.min.js +1 -1
  14. package/dist/v1/TinyClipboard.min.js +1 -1
  15. package/dist/v1/TinyCloner.min.js +1 -0
  16. package/dist/v1/TinyColorConverter.min.js +1 -1
  17. package/dist/v1/TinyColorValidator.min.js +1 -1
  18. package/dist/v1/TinyCookieConsent.min.js +1 -1
  19. package/dist/v1/TinyDayNightCycle.min.js +1 -1
  20. package/dist/v1/TinyDebugger.min.js +1 -1
  21. package/dist/v1/TinyDomReadyManager.min.js +1 -1
  22. package/dist/v1/TinyDragDropDetector.min.js +1 -1
  23. package/dist/v1/TinyDragger.min.js +1 -1
  24. package/dist/v1/TinyElementObserver.min.js +1 -1
  25. package/dist/v1/TinyEssentials.min.js +1 -1
  26. package/dist/v1/TinyGamepad.min.js +1 -1
  27. package/dist/v1/TinyHtml.min.js +1 -1
  28. package/dist/v1/TinyHtmlTagRegexBuilder.min.js +1 -0
  29. package/dist/v1/TinyHttpResponseRegistry.min.js +1 -0
  30. package/dist/v1/TinyI18.min.js +1 -1
  31. package/dist/v1/TinyIframeEvents.min.js +1 -1
  32. package/dist/v1/TinyInventory.min.js +1 -1
  33. package/dist/v1/TinyInventoryTrader.min.js +1 -1
  34. package/dist/v1/TinyLevelUp.min.js +1 -1
  35. package/dist/v1/TinyLoadingScreen.min.js +1 -1
  36. package/dist/v1/TinyLocalStorage.min.js +1 -1
  37. package/dist/v1/TinyMaInSys.min.js +1 -1
  38. package/dist/v1/TinyMapCache.min.js +1 -0
  39. package/dist/v1/TinyMediaPlayer.min.js +1 -1
  40. package/dist/v1/TinyNeedBar.min.js +1 -1
  41. package/dist/v1/TinyNewWinEvents.min.js +1 -1
  42. package/dist/v1/TinyNotificationAdapter.min.js +1 -0
  43. package/dist/v1/TinyNotifications.min.js +1 -1
  44. package/dist/v1/TinyNotifyCenter.min.js +1 -1
  45. package/dist/v1/TinyOPFSFileSystem.min.js +1 -0
  46. package/dist/v1/TinyPasswordValidator.min.js +1 -0
  47. package/dist/v1/TinyPluginPackage.min.js +1 -0
  48. package/dist/v1/TinyPromiseQueue.min.js +1 -1
  49. package/dist/v1/TinyPushManager.min.js +1 -0
  50. package/dist/v1/TinyPushPayload.min.js +1 -0
  51. package/dist/v1/TinyPushRouter.min.js +1 -0
  52. package/dist/v1/TinyRadioFm.min.js +1 -1
  53. package/dist/v1/TinyRateLimiter.min.js +1 -1
  54. package/dist/v1/TinyRegexEs.min.js +1 -0
  55. package/dist/v1/TinyRouter.min.js +1 -0
  56. package/dist/v1/TinyServiceWorker.min.js +1 -0
  57. package/dist/v1/TinyServiceWorkerEngine.min.js +1 -0
  58. package/dist/v1/TinySetMapPackage.min.js +1 -0
  59. package/dist/v1/TinySimpleDice.min.js +1 -1
  60. package/dist/v1/TinySmartScroller.min.js +1 -1
  61. package/dist/v1/TinyStorageBucketFileSystem.min.js +1 -0
  62. package/dist/v1/TinyTextDiffer.min.js +1 -1
  63. package/dist/v1/TinyTextRangeEditor.min.js +1 -1
  64. package/dist/v1/TinyTextarea.min.js +1 -1
  65. package/dist/v1/TinyThrottledApi.min.js +1 -0
  66. package/dist/v1/TinyTimeout.min.js +1 -1
  67. package/dist/v1/TinyToastNotify.min.js +1 -1
  68. package/dist/v1/TinyUploadClicker.min.js +1 -1
  69. package/dist/v1/TinyUriParser.min.js +1 -0
  70. package/dist/v1/TinyVersion.min.js +1 -0
  71. package/dist/v1/TinyWebWorker.min.js +1 -0
  72. package/dist/v1/TinyWebWorkerEngine.min.js +1 -0
  73. package/dist/v1/UltraRandomMsgGen.min.js +1 -1
  74. package/dist/v1/basics/array.cjs +2 -2
  75. package/dist/v1/basics/array.d.mts +2 -0
  76. package/dist/v1/basics/array.d.mts.map +1 -1
  77. package/dist/v1/basics/array.mjs +2 -1
  78. package/dist/v1/basics/browserDetector.cjs +37 -12
  79. package/dist/v1/basics/browserDetector.d.mts +8 -0
  80. package/dist/v1/basics/browserDetector.d.mts.map +1 -1
  81. package/dist/v1/basics/browserDetector.mjs +32 -13
  82. package/dist/v1/basics/crypto.cjs +23 -0
  83. package/dist/v1/basics/crypto.d.mts +10 -0
  84. package/dist/v1/basics/crypto.d.mts.map +1 -0
  85. package/dist/v1/basics/crypto.mjs +18 -0
  86. package/dist/v1/basics/html.cjs +0 -3
  87. package/dist/v1/basics/html.d.mts.map +1 -1
  88. package/dist/v1/basics/html.mjs +0 -2
  89. package/dist/v1/basics/index.cjs +8 -1
  90. package/dist/v1/basics/index.d.mts +6 -5
  91. package/dist/v1/basics/index.d.mts.map +1 -1
  92. package/dist/v1/basics/index.mjs +6 -5
  93. package/dist/v1/basics/objChecker.cjs +88 -0
  94. package/dist/v1/basics/objChecker.d.mts +26 -0
  95. package/dist/v1/basics/objChecker.d.mts.map +1 -1
  96. package/dist/v1/basics/objChecker.mjs +74 -0
  97. package/dist/v1/basics/objFilter.cjs +234 -93
  98. package/dist/v1/basics/objFilter.d.mts +96 -22
  99. package/dist/v1/basics/objFilter.d.mts.map +1 -1
  100. package/dist/v1/basics/objFilter.mjs +216 -92
  101. package/dist/v1/basics/promiseUtils.cjs +48 -12
  102. package/dist/v1/basics/promiseUtils.d.mts +45 -12
  103. package/dist/v1/basics/promiseUtils.d.mts.map +1 -1
  104. package/dist/v1/basics/promiseUtils.mjs +47 -12
  105. package/dist/v1/basics/text.cjs +0 -12
  106. package/dist/v1/basics/text.d.mts +0 -10
  107. package/dist/v1/basics/text.d.mts.map +1 -1
  108. package/dist/v1/basics/text.mjs +0 -10
  109. package/dist/v1/index.cjs +88 -3
  110. package/dist/v1/index.d.mts +31 -6
  111. package/dist/v1/index.d.mts.map +1 -1
  112. package/dist/v1/index.mjs +32 -7
  113. package/dist/v1/jsdoc/EventEmitter.cjs +4 -0
  114. package/dist/v1/jsdoc/EventEmitter.d.mts +33 -0
  115. package/dist/v1/jsdoc/EventEmitter.d.mts.map +1 -0
  116. package/dist/v1/jsdoc/EventEmitter.mjs +18 -0
  117. package/dist/v1/libs/array/TinyArrayComparator.cjs +240 -25
  118. package/dist/v1/libs/array/TinyArrayComparator.d.mts +130 -22
  119. package/dist/v1/libs/array/TinyArrayComparator.d.mts.map +1 -1
  120. package/dist/v1/libs/array/TinyArrayComparator.mjs +210 -24
  121. package/dist/v1/libs/fs/constants.cjs +74 -0
  122. package/dist/v1/libs/fs/constants.d.mts +22 -0
  123. package/dist/v1/libs/fs/constants.d.mts.map +1 -0
  124. package/dist/v1/libs/fs/constants.mjs +53 -0
  125. package/dist/v1/libs/fs/encoding.cjs +118 -0
  126. package/dist/v1/libs/fs/encoding.d.mts +50 -0
  127. package/dist/v1/libs/fs/encoding.d.mts.map +1 -0
  128. package/dist/v1/libs/fs/encoding.mjs +102 -0
  129. package/dist/v1/libs/fs/error.cjs +188 -0
  130. package/dist/v1/libs/fs/error.d.mts +105 -0
  131. package/dist/v1/libs/fs/error.d.mts.map +1 -0
  132. package/dist/v1/libs/fs/error.mjs +158 -0
  133. package/dist/v1/libs/fs/handle.cjs +121 -0
  134. package/dist/v1/libs/fs/handle.d.mts +56 -0
  135. package/dist/v1/libs/fs/handle.d.mts.map +1 -0
  136. package/dist/v1/libs/fs/handle.mjs +100 -0
  137. package/dist/v1/libs/fs/index.cjs +700 -0
  138. package/dist/v1/libs/fs/index.d.mts +377 -0
  139. package/dist/v1/libs/fs/index.d.mts.map +1 -0
  140. package/dist/v1/libs/fs/index.mjs +630 -0
  141. package/dist/v1/libs/fs/path.cjs +234 -0
  142. package/dist/v1/libs/fs/path.d.mts +176 -0
  143. package/dist/v1/libs/fs/path.d.mts.map +1 -0
  144. package/dist/v1/libs/fs/path.mjs +197 -0
  145. package/dist/v1/libs/fs/plugins/OPFS/StorageBucket.cjs +202 -0
  146. package/dist/v1/libs/fs/plugins/OPFS/StorageBucket.d.mts +121 -0
  147. package/dist/v1/libs/fs/plugins/OPFS/StorageBucket.d.mts.map +1 -0
  148. package/dist/v1/libs/fs/plugins/OPFS/StorageBucket.mjs +172 -0
  149. package/dist/v1/libs/fs/plugins/OPFS/index.cjs +334 -0
  150. package/dist/v1/libs/fs/plugins/OPFS/index.d.mts +98 -0
  151. package/dist/v1/libs/fs/plugins/OPFS/index.d.mts.map +1 -0
  152. package/dist/v1/libs/fs/plugins/OPFS/index.mjs +300 -0
  153. package/dist/v1/libs/fs/stats.cjs +245 -0
  154. package/dist/v1/libs/fs/stats.d.mts +226 -0
  155. package/dist/v1/libs/fs/stats.d.mts.map +1 -0
  156. package/dist/v1/libs/fs/stats.mjs +197 -0
  157. package/dist/v1/libs/html/events/TinyIframeEvents.cjs +10 -1
  158. package/dist/v1/libs/html/events/TinyIframeEvents.d.mts +9 -2
  159. package/dist/v1/libs/html/events/TinyIframeEvents.d.mts.map +1 -1
  160. package/dist/v1/libs/html/events/TinyIframeEvents.mjs +8 -1
  161. package/dist/v1/libs/html/events/TinyNewWinEvents.cjs +14 -3
  162. package/dist/v1/libs/html/events/TinyNewWinEvents.d.mts +21 -5
  163. package/dist/v1/libs/html/events/TinyNewWinEvents.d.mts.map +1 -1
  164. package/dist/v1/libs/html/events/TinyNewWinEvents.mjs +12 -3
  165. package/dist/v1/libs/html/scroll/TinySmartScroller.cjs +13 -1
  166. package/dist/v1/libs/html/scroll/TinySmartScroller.d.mts +29 -2
  167. package/dist/v1/libs/html/scroll/TinySmartScroller.d.mts.map +1 -1
  168. package/dist/v1/libs/html/scroll/TinySmartScroller.mjs +11 -1
  169. package/dist/v1/libs/math/TinyAdvancedRaffle.cjs +13 -1
  170. package/dist/v1/libs/math/TinyAdvancedRaffle.d.mts +32 -2
  171. package/dist/v1/libs/math/TinyAdvancedRaffle.d.mts.map +1 -1
  172. package/dist/v1/libs/math/TinyAdvancedRaffle.mjs +11 -1
  173. package/dist/v1/libs/math/TinyTimeout.cjs +0 -14
  174. package/dist/v1/libs/math/TinyTimeout.d.mts +0 -11
  175. package/dist/v1/libs/math/TinyTimeout.d.mts.map +1 -1
  176. package/dist/v1/libs/math/TinyTimeout.mjs +0 -13
  177. package/dist/v1/libs/media/TinyMediaPlayer/index.cjs +25 -1
  178. package/dist/v1/libs/media/TinyMediaPlayer/index.d.mts +35 -2
  179. package/dist/v1/libs/media/TinyMediaPlayer/index.d.mts.map +1 -1
  180. package/dist/v1/libs/media/TinyMediaPlayer/index.mjs +23 -1
  181. package/dist/v1/libs/media/TinyMediaPlayer.cjs +2 -2
  182. package/dist/v1/libs/media/TinyMediaPlayer.d.mts +2 -2
  183. package/dist/v1/libs/media/TinyMediaPlayer.d.mts.map +1 -1
  184. package/dist/v1/libs/media/TinyMediaPlayer.mjs +2 -2
  185. package/dist/v1/libs/media/TinyRadioFm.cjs +19 -1
  186. package/dist/v1/libs/media/TinyRadioFm.d.mts +78 -2
  187. package/dist/v1/libs/media/TinyRadioFm.d.mts.map +1 -1
  188. package/dist/v1/libs/media/TinyRadioFm.mjs +17 -1
  189. package/dist/v1/libs/plugin/TinyPlugin.cjs +1630 -0
  190. package/dist/v1/libs/plugin/TinyPlugin.d.mts +753 -0
  191. package/dist/v1/libs/plugin/TinyPlugin.d.mts.map +1 -0
  192. package/dist/v1/libs/plugin/TinyPlugin.mjs +1376 -0
  193. package/dist/v1/libs/plugin/TinyVersion.cjs +204 -0
  194. package/dist/v1/libs/plugin/TinyVersion.d.mts +70 -0
  195. package/dist/v1/libs/plugin/TinyVersion.d.mts.map +1 -0
  196. package/dist/v1/libs/plugin/TinyVersion.mjs +179 -0
  197. package/dist/v1/libs/router/TinyRouter.cjs +661 -0
  198. package/dist/v1/libs/router/TinyRouter.d.mts +320 -0
  199. package/dist/v1/libs/router/TinyRouter.d.mts.map +1 -0
  200. package/dist/v1/libs/router/TinyRouter.mjs +572 -0
  201. package/dist/v1/libs/storage/TinyLocalStorage.cjs +20 -1
  202. package/dist/v1/libs/storage/TinyLocalStorage.d.mts +64 -2
  203. package/dist/v1/libs/storage/TinyLocalStorage.d.mts.map +1 -1
  204. package/dist/v1/libs/storage/TinyLocalStorage.mjs +18 -1
  205. package/dist/v1/libs/storage/TinyMapCache.cjs +373 -0
  206. package/dist/v1/libs/storage/TinyMapCache.d.mts +274 -0
  207. package/dist/v1/libs/storage/TinyMapCache.d.mts.map +1 -0
  208. package/dist/v1/libs/storage/TinyMapCache.mjs +333 -0
  209. package/dist/v1/libs/storage/TinySetMapDatabase.cjs +1167 -0
  210. package/dist/v1/libs/storage/TinySetMapDatabase.d.mts +603 -0
  211. package/dist/v1/libs/storage/TinySetMapDatabase.d.mts.map +1 -0
  212. package/dist/v1/libs/storage/TinySetMapDatabase.mjs +1059 -0
  213. package/dist/v1/libs/sw/browser/TinyNotificationAdapter.cjs +126 -0
  214. package/dist/v1/libs/sw/browser/TinyNotificationAdapter.d.mts +132 -0
  215. package/dist/v1/libs/sw/browser/TinyNotificationAdapter.d.mts.map +1 -0
  216. package/dist/v1/libs/sw/browser/TinyNotificationAdapter.mjs +109 -0
  217. package/dist/v1/libs/sw/browser/TinyPushManager.cjs +310 -0
  218. package/dist/v1/libs/sw/browser/TinyPushManager.d.mts +168 -0
  219. package/dist/v1/libs/sw/browser/TinyPushManager.d.mts.map +1 -0
  220. package/dist/v1/libs/sw/browser/TinyPushManager.mjs +264 -0
  221. package/dist/v1/libs/sw/browser/TinyServiceWorker.cjs +1060 -0
  222. package/dist/v1/libs/sw/browser/TinyServiceWorker.d.mts +348 -0
  223. package/dist/v1/libs/sw/browser/TinyServiceWorker.d.mts.map +1 -0
  224. package/dist/v1/libs/sw/browser/TinyServiceWorker.mjs +933 -0
  225. package/dist/v1/libs/sw/browser/plugins/TabManager.cjs +315 -0
  226. package/dist/v1/libs/sw/browser/plugins/TabManager.d.mts +178 -0
  227. package/dist/v1/libs/sw/browser/plugins/TabManager.d.mts.map +1 -0
  228. package/dist/v1/libs/sw/browser/plugins/TabManager.mjs +274 -0
  229. package/dist/v1/libs/sw/browser/utils.cjs +28 -0
  230. package/dist/v1/libs/sw/browser/utils.d.mts +8 -0
  231. package/dist/v1/libs/sw/browser/utils.d.mts.map +1 -0
  232. package/dist/v1/libs/sw/browser/utils.mjs +21 -0
  233. package/dist/v1/libs/sw/service/TinyPushRouter.cjs +222 -0
  234. package/dist/v1/libs/sw/service/TinyPushRouter.d.mts +138 -0
  235. package/dist/v1/libs/sw/service/TinyPushRouter.d.mts.map +1 -0
  236. package/dist/v1/libs/sw/service/TinyPushRouter.mjs +201 -0
  237. package/dist/v1/libs/sw/service/TinyServiceWorkerEngine.cjs +3016 -0
  238. package/dist/v1/libs/sw/service/TinyServiceWorkerEngine.d.mts +993 -0
  239. package/dist/v1/libs/sw/service/TinyServiceWorkerEngine.d.mts.map +1 -0
  240. package/dist/v1/libs/sw/service/TinyServiceWorkerEngine.mjs +2558 -0
  241. package/dist/v1/libs/sw/service/plugins/GlobBypassPlugin.cjs +88 -0
  242. package/dist/v1/libs/sw/service/plugins/GlobBypassPlugin.d.mts +32 -0
  243. package/dist/v1/libs/sw/service/plugins/GlobBypassPlugin.d.mts.map +1 -0
  244. package/dist/v1/libs/sw/service/plugins/GlobBypassPlugin.mjs +69 -0
  245. package/dist/v1/libs/sw/service/plugins/GlobCachePlugin.cjs +112 -0
  246. package/dist/v1/libs/sw/service/plugins/GlobCachePlugin.d.mts +31 -0
  247. package/dist/v1/libs/sw/service/plugins/GlobCachePlugin.d.mts.map +1 -0
  248. package/dist/v1/libs/sw/service/plugins/GlobCachePlugin.mjs +91 -0
  249. package/dist/v1/libs/sw/service/plugins/Ping.cjs +32 -0
  250. package/dist/v1/libs/sw/service/plugins/Ping.d.mts +9 -0
  251. package/dist/v1/libs/sw/service/plugins/Ping.d.mts.map +1 -0
  252. package/dist/v1/libs/sw/service/plugins/Ping.mjs +25 -0
  253. package/dist/v1/libs/sw/service/plugins/TabManager.cjs +457 -0
  254. package/dist/v1/libs/sw/service/plugins/TabManager.d.mts +91 -0
  255. package/dist/v1/libs/sw/service/plugins/TabManager.d.mts.map +1 -0
  256. package/dist/v1/libs/sw/service/plugins/TabManager.mjs +372 -0
  257. package/dist/v1/libs/sw/service/plugins/ViteFileDetector.cjs +180 -0
  258. package/dist/v1/libs/sw/service/plugins/ViteFileDetector.d.mts +28 -0
  259. package/dist/v1/libs/sw/service/plugins/ViteFileDetector.d.mts.map +1 -0
  260. package/dist/v1/libs/sw/service/plugins/ViteFileDetector.mjs +148 -0
  261. package/dist/v1/libs/sw/service/shared/TinyPushPayload.cjs +199 -0
  262. package/dist/v1/libs/sw/service/shared/TinyPushPayload.d.mts +80 -0
  263. package/dist/v1/libs/sw/service/shared/TinyPushPayload.d.mts.map +1 -0
  264. package/dist/v1/libs/sw/service/shared/TinyPushPayload.mjs +174 -0
  265. package/dist/v1/libs/sw/utils.cjs +57 -0
  266. package/dist/v1/libs/sw/utils.d.mts +173 -0
  267. package/dist/v1/libs/sw/utils.d.mts.map +1 -0
  268. package/dist/v1/libs/sw/utils.mjs +50 -0
  269. package/dist/v1/libs/text/TinyI18/Browser-NON-DOM.cjs +57 -0
  270. package/dist/v1/libs/text/TinyI18/Browser-NON-DOM.d.mts +39 -0
  271. package/dist/v1/libs/text/TinyI18/Browser-NON-DOM.d.mts.map +1 -0
  272. package/dist/v1/libs/text/TinyI18/Browser-NON-DOM.mjs +48 -0
  273. package/dist/v1/libs/text/TinyI18/Browser.cjs +64 -0
  274. package/dist/v1/libs/text/TinyI18/Browser.d.mts +47 -0
  275. package/dist/v1/libs/text/TinyI18/Browser.d.mts.map +1 -0
  276. package/dist/v1/libs/text/TinyI18/Browser.mjs +57 -0
  277. package/dist/v1/libs/text/TinyI18/Node.cjs +49 -0
  278. package/dist/v1/libs/text/TinyI18/Node.d.mts +38 -0
  279. package/dist/v1/libs/text/TinyI18/Node.d.mts.map +1 -0
  280. package/dist/v1/libs/text/TinyI18/Node.mjs +43 -0
  281. package/dist/v1/libs/text/TinyI18/browser-utils.cjs +17 -0
  282. package/dist/v1/libs/text/TinyI18/browser-utils.d.mts +8 -0
  283. package/dist/v1/libs/text/TinyI18/browser-utils.d.mts.map +1 -0
  284. package/dist/v1/libs/text/TinyI18/browser-utils.mjs +13 -0
  285. package/dist/v1/libs/text/{TinyI18.cjs → TinyI18/index.cjs} +205 -104
  286. package/dist/v1/libs/text/{TinyI18.d.mts → TinyI18/index.d.mts} +141 -92
  287. package/dist/v1/libs/text/TinyI18/index.d.mts.map +1 -0
  288. package/dist/v1/libs/text/{TinyI18.mjs → TinyI18/index.mjs} +195 -101
  289. package/dist/v1/libs/tools/TinyBrowserMonitor.cjs +1088 -0
  290. package/dist/v1/libs/tools/TinyBrowserMonitor.d.mts +621 -0
  291. package/dist/v1/libs/tools/TinyBrowserMonitor.d.mts.map +1 -0
  292. package/dist/v1/libs/tools/TinyBrowserMonitor.mjs +940 -0
  293. package/dist/v1/libs/tools/TinyDebugger.cjs +180 -19
  294. package/dist/v1/libs/tools/TinyDebugger.d.mts +220 -24
  295. package/dist/v1/libs/tools/TinyDebugger.d.mts.map +1 -1
  296. package/dist/v1/libs/tools/TinyDebugger.mjs +161 -19
  297. package/dist/v1/libs/tools/TinyHtmlTagRegexBuilder.cjs +256 -0
  298. package/dist/v1/libs/tools/TinyHtmlTagRegexBuilder.d.mts +125 -0
  299. package/dist/v1/libs/tools/TinyHtmlTagRegexBuilder.d.mts.map +1 -0
  300. package/dist/v1/libs/tools/TinyHtmlTagRegexBuilder.mjs +223 -0
  301. package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser-NON-DOM.cjs +23 -0
  302. package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser-NON-DOM.d.mts +17 -0
  303. package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser-NON-DOM.d.mts.map +1 -0
  304. package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser-NON-DOM.mjs +19 -0
  305. package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser.cjs +23 -0
  306. package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser.d.mts +17 -0
  307. package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser.d.mts.map +1 -0
  308. package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser.mjs +19 -0
  309. package/dist/v1/libs/tools/TinyHttpResponseRegistry/EmptyRequestCodes.cjs +390 -0
  310. package/dist/v1/libs/tools/TinyHttpResponseRegistry/EmptyRequestCodes.d.mts +9 -0
  311. package/dist/v1/libs/tools/TinyHttpResponseRegistry/EmptyRequestCodes.d.mts.map +1 -0
  312. package/dist/v1/libs/tools/TinyHttpResponseRegistry/EmptyRequestCodes.mjs +387 -0
  313. package/dist/v1/libs/tools/TinyHttpResponseRegistry/JsDoc.cjs +2 -0
  314. package/dist/v1/libs/tools/TinyHttpResponseRegistry/JsDoc.d.mts +27 -0
  315. package/dist/v1/libs/tools/TinyHttpResponseRegistry/JsDoc.d.mts.map +1 -0
  316. package/dist/v1/libs/tools/TinyHttpResponseRegistry/JsDoc.mjs +12 -0
  317. package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/LICENSE +53 -0
  318. package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/index.cjs +405 -0
  319. package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/index.d.mts +34 -0
  320. package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/index.d.mts.map +1 -0
  321. package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/index.mjs +342 -0
  322. package/dist/v1/libs/tools/TinyHttpResponseRegistry/Node.cjs +23 -0
  323. package/dist/v1/libs/tools/TinyHttpResponseRegistry/Node.d.mts +17 -0
  324. package/dist/v1/libs/tools/TinyHttpResponseRegistry/Node.d.mts.map +1 -0
  325. package/dist/v1/libs/tools/TinyHttpResponseRegistry/Node.mjs +19 -0
  326. package/dist/v1/libs/tools/TinyHttpResponseRegistry/RequestCodes.cjs +327 -0
  327. package/dist/v1/libs/tools/TinyHttpResponseRegistry/RequestCodes.d.mts +9 -0
  328. package/dist/v1/libs/tools/TinyHttpResponseRegistry/RequestCodes.d.mts.map +1 -0
  329. package/dist/v1/libs/tools/TinyHttpResponseRegistry/RequestCodes.mjs +324 -0
  330. package/dist/v1/libs/tools/TinyHttpResponseRegistry/index.cjs +268 -0
  331. package/dist/v1/libs/tools/TinyHttpResponseRegistry/index.d.mts +107 -0
  332. package/dist/v1/libs/tools/TinyHttpResponseRegistry/index.d.mts.map +1 -0
  333. package/dist/v1/libs/tools/TinyHttpResponseRegistry/index.mjs +238 -0
  334. package/dist/v1/libs/tools/TinyPasswordValidator.cjs +491 -0
  335. package/dist/v1/libs/tools/TinyPasswordValidator.d.mts +246 -0
  336. package/dist/v1/libs/tools/TinyPasswordValidator.d.mts.map +1 -0
  337. package/dist/v1/libs/tools/TinyPasswordValidator.mjs +434 -0
  338. package/dist/v1/libs/tools/TinyPkgExportValidator.cjs +48 -0
  339. package/dist/v1/libs/tools/TinyPkgExportValidator.d.mts +14 -0
  340. package/dist/v1/libs/tools/TinyPkgExportValidator.d.mts.map +1 -1
  341. package/dist/v1/libs/tools/TinyPkgExportValidator.mjs +44 -0
  342. package/dist/v1/libs/tools/TinySiteMap.cjs +1029 -0
  343. package/dist/v1/libs/tools/TinySiteMap.d.mts +429 -0
  344. package/dist/v1/libs/tools/TinySiteMap.d.mts.map +1 -0
  345. package/dist/v1/libs/tools/TinySiteMap.mjs +910 -0
  346. package/dist/v1/libs/tools/TinySiteMapStream.cjs +121 -0
  347. package/dist/v1/libs/tools/TinySiteMapStream.d.mts +51 -0
  348. package/dist/v1/libs/tools/TinySiteMapStream.d.mts.map +1 -0
  349. package/dist/v1/libs/tools/TinySiteMapStream.mjs +85 -0
  350. package/dist/v1/libs/tools/TinyURLSecurityVerifier.cjs +444 -0
  351. package/dist/v1/libs/tools/TinyURLSecurityVerifier.d.mts +217 -0
  352. package/dist/v1/libs/tools/TinyURLSecurityVerifier.d.mts.map +1 -0
  353. package/dist/v1/libs/tools/TinyURLSecurityVerifier.mjs +394 -0
  354. package/dist/v1/libs/tools/TinyUriParser/BlueSky.cjs +613 -0
  355. package/dist/v1/libs/tools/TinyUriParser/BlueSky.d.mts +152 -0
  356. package/dist/v1/libs/tools/TinyUriParser/BlueSky.d.mts.map +1 -0
  357. package/dist/v1/libs/tools/TinyUriParser/BlueSky.mjs +527 -0
  358. package/dist/v1/libs/tools/TinyUriParser/Discord.cjs +1119 -0
  359. package/dist/v1/libs/tools/TinyUriParser/Discord.d.mts +306 -0
  360. package/dist/v1/libs/tools/TinyUriParser/Discord.d.mts.map +1 -0
  361. package/dist/v1/libs/tools/TinyUriParser/Discord.mjs +968 -0
  362. package/dist/v1/libs/tools/TinyUriParser/MatrixProtocol.cjs +469 -0
  363. package/dist/v1/libs/tools/TinyUriParser/MatrixProtocol.d.mts +80 -0
  364. package/dist/v1/libs/tools/TinyUriParser/MatrixProtocol.d.mts.map +1 -0
  365. package/dist/v1/libs/tools/TinyUriParser/MatrixProtocol.mjs +379 -0
  366. package/dist/v1/libs/tools/TinyUriParser.cjs +217 -0
  367. package/dist/v1/libs/tools/TinyUriParser.d.mts +109 -0
  368. package/dist/v1/libs/tools/TinyUriParser.d.mts.map +1 -0
  369. package/dist/v1/libs/tools/TinyUriParser.mjs +183 -0
  370. package/dist/v1/libs/utils/TinyCloner.cjs +466 -0
  371. package/dist/v1/libs/utils/TinyCloner.d.mts +221 -0
  372. package/dist/v1/libs/utils/TinyCloner.d.mts.map +1 -0
  373. package/dist/v1/libs/utils/TinyCloner.mjs +416 -0
  374. package/dist/v1/libs/utils/TinyPromiseQueue.cjs +1 -1
  375. package/dist/v1/libs/utils/TinyPromiseQueue.d.mts +2 -2
  376. package/dist/v1/libs/utils/TinyPromiseQueue.d.mts.map +1 -1
  377. package/dist/v1/libs/utils/TinyPromiseQueue.mjs +1 -1
  378. package/dist/v1/libs/utils/TinyThrottledApi.cjs +333 -0
  379. package/dist/v1/libs/utils/TinyThrottledApi.d.mts +163 -0
  380. package/dist/v1/libs/utils/TinyThrottledApi.d.mts.map +1 -0
  381. package/dist/v1/libs/utils/TinyThrottledApi.mjs +294 -0
  382. package/dist/v1/libs/worker/browser/TinyWebWorker.cjs +342 -0
  383. package/dist/v1/libs/worker/browser/TinyWebWorker.d.mts +97 -0
  384. package/dist/v1/libs/worker/browser/TinyWebWorker.d.mts.map +1 -0
  385. package/dist/v1/libs/worker/browser/TinyWebWorker.mjs +305 -0
  386. package/dist/v1/libs/worker/engine/TinyWebWorkerEngine.cjs +346 -0
  387. package/dist/v1/libs/worker/engine/TinyWebWorkerEngine.d.mts +127 -0
  388. package/dist/v1/libs/worker/engine/TinyWebWorkerEngine.d.mts.map +1 -0
  389. package/dist/v1/libs/worker/engine/TinyWebWorkerEngine.mjs +304 -0
  390. package/dist/v1/regexp/Email.cjs +185 -0
  391. package/dist/v1/regexp/Email.d.mts +73 -0
  392. package/dist/v1/regexp/Email.d.mts.map +1 -0
  393. package/dist/v1/regexp/Email.mjs +153 -0
  394. package/dist/v1/regexp/Glob.cjs +293 -0
  395. package/dist/v1/regexp/Glob.d.mts +45 -0
  396. package/dist/v1/regexp/Glob.d.mts.map +1 -0
  397. package/dist/v1/regexp/Glob.mjs +260 -0
  398. package/dist/v1/regexp/Ipv4.cjs +57 -0
  399. package/dist/v1/regexp/Ipv4.d.mts +29 -0
  400. package/dist/v1/regexp/Ipv4.d.mts.map +1 -0
  401. package/dist/v1/regexp/Ipv4.mjs +45 -0
  402. package/dist/v1/regexp/Ipv6.cjs +67 -0
  403. package/dist/v1/regexp/Ipv6.d.mts +29 -0
  404. package/dist/v1/regexp/Ipv6.d.mts.map +1 -0
  405. package/dist/v1/regexp/Ipv6.mjs +54 -0
  406. package/dist/v1/regexp/SegmentExtractor.cjs +145 -0
  407. package/dist/v1/regexp/SegmentExtractor.d.mts +91 -0
  408. package/dist/v1/regexp/SegmentExtractor.d.mts.map +1 -0
  409. package/dist/v1/regexp/SegmentExtractor.mjs +116 -0
  410. package/dist/v1/regexp/UrlDetector.cjs +125 -0
  411. package/dist/v1/regexp/UrlDetector.d.mts +67 -0
  412. package/dist/v1/regexp/UrlDetector.d.mts.map +1 -0
  413. package/dist/v1/regexp/UrlDetector.mjs +102 -0
  414. package/dist/v1/regexp/Username/index.cjs +233 -0
  415. package/dist/v1/regexp/Username/index.d.mts +77 -0
  416. package/dist/v1/regexp/Username/index.d.mts.map +1 -0
  417. package/dist/v1/regexp/Username/index.mjs +199 -0
  418. package/dist/v1/regexp/Username/jsDoc.cjs +2 -0
  419. package/dist/v1/regexp/Username/jsDoc.d.mts +57 -0
  420. package/dist/v1/regexp/Username/jsDoc.d.mts.map +1 -0
  421. package/dist/v1/regexp/Username/jsDoc.mjs +18 -0
  422. package/dist/v1/regexp/Username/templates/BlueSky.cjs +56 -0
  423. package/dist/v1/regexp/Username/templates/BlueSky.d.mts +35 -0
  424. package/dist/v1/regexp/Username/templates/BlueSky.d.mts.map +1 -0
  425. package/dist/v1/regexp/Username/templates/BlueSky.mjs +52 -0
  426. package/dist/v1/regexp/Username/templates/Discord.cjs +505 -0
  427. package/dist/v1/regexp/Username/templates/Discord.d.mts +209 -0
  428. package/dist/v1/regexp/Username/templates/Discord.d.mts.map +1 -0
  429. package/dist/v1/regexp/Username/templates/Discord.mjs +458 -0
  430. package/dist/v1/regexp/Username/templates/MatrixProtocol.cjs +143 -0
  431. package/dist/v1/regexp/Username/templates/MatrixProtocol.d.mts +70 -0
  432. package/dist/v1/regexp/Username/templates/MatrixProtocol.d.mts.map +1 -0
  433. package/dist/v1/regexp/Username/templates/MatrixProtocol.mjs +128 -0
  434. package/dist/v1/regexp/Username/templates/deprecated/Discord.cjs +24 -0
  435. package/dist/v1/regexp/Username/templates/deprecated/Discord.d.mts +17 -0
  436. package/dist/v1/regexp/Username/templates/deprecated/Discord.d.mts.map +1 -0
  437. package/dist/v1/regexp/Username/templates/deprecated/Discord.mjs +20 -0
  438. package/dist/v1/regexp/Username/templates/index.cjs +11 -0
  439. package/dist/v1/regexp/Username/templates/index.d.mts +5 -0
  440. package/dist/v1/regexp/Username/templates/index.d.mts.map +1 -0
  441. package/dist/v1/regexp/Username/templates/index.mjs +4 -0
  442. package/dist/v1/regexp/index.cjs +41 -0
  443. package/dist/v1/regexp/index.d.mts +9 -0
  444. package/dist/v1/regexp/index.d.mts.map +1 -0
  445. package/dist/v1/regexp/index.mjs +8 -0
  446. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Browser.cjs +64 -0
  447. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Browser.d.mts +11 -0
  448. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Browser.d.mts.map +1 -0
  449. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Browser.mjs +51 -0
  450. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/FileInput.cjs +66 -0
  451. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/FileInput.d.mts +11 -0
  452. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/FileInput.d.mts.map +1 -0
  453. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/FileInput.mjs +51 -0
  454. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Node.cjs +39 -0
  455. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Node.d.mts +11 -0
  456. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Node.d.mts.map +1 -0
  457. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Node.mjs +28 -0
  458. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Template.cjs +494 -0
  459. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Template.d.mts +142 -0
  460. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Template.d.mts.map +1 -0
  461. package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Template.mjs +445 -0
  462. package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.cjs +30 -4
  463. package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.d.mts +5 -2
  464. package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.d.mts.map +1 -1
  465. package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.mjs +29 -5
  466. package/dist/v1/webTemplates/media/MediaValidator/v1/Browser/index.cjs +135 -0
  467. package/dist/v1/webTemplates/media/MediaValidator/v1/Browser/index.d.mts +83 -0
  468. package/dist/v1/webTemplates/media/MediaValidator/v1/Browser/index.d.mts.map +1 -0
  469. package/dist/v1/webTemplates/media/MediaValidator/v1/Browser/index.mjs +120 -0
  470. package/dist/v1/webTemplates/media/MediaValidator/v1/Node/index.cjs +127 -0
  471. package/dist/v1/webTemplates/media/MediaValidator/v1/Node/index.d.mts +95 -0
  472. package/dist/v1/webTemplates/media/MediaValidator/v1/Node/index.d.mts.map +1 -0
  473. package/dist/v1/webTemplates/media/MediaValidator/v1/Node/index.mjs +109 -0
  474. package/dist/v1/webTemplates/multiformats/14.0/IPFSHasher/index.cjs +83 -0
  475. package/dist/v1/webTemplates/multiformats/14.0/IPFSHasher/index.d.mts +46 -0
  476. package/dist/v1/webTemplates/multiformats/14.0/IPFSHasher/index.d.mts.map +1 -0
  477. package/dist/v1/webTemplates/multiformats/14.0/IPFSHasher/index.mjs +71 -0
  478. package/dist/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.cjs +493 -0
  479. package/dist/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.d.mts +67 -0
  480. package/dist/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.d.mts.map +1 -0
  481. package/dist/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.mjs +399 -0
  482. package/dist/v1/webTemplates/vite/7.3/plugins/githubUtils.cjs +35 -0
  483. package/dist/v1/webTemplates/vite/7.3/plugins/githubUtils.d.mts +6 -0
  484. package/dist/v1/webTemplates/vite/7.3/plugins/githubUtils.d.mts.map +1 -0
  485. package/dist/v1/webTemplates/vite/7.3/plugins/githubUtils.mjs +29 -0
  486. package/docs/info/RegExp.md +74 -0
  487. package/docs/v1/Exports.md +101 -0
  488. package/docs/v1/README.md +113 -15
  489. package/docs/v1/basics/asyncReplace.md +2 -0
  490. package/docs/v1/basics/browserDetector.md +28 -11
  491. package/docs/v1/basics/crypto.md +85 -0
  492. package/docs/v1/basics/deprecated/html.md +2 -0
  493. package/docs/v1/basics/deprecated/objFilter.md +2 -0
  494. package/docs/v1/basics/html.md +2 -0
  495. package/docs/v1/basics/objChecker.md +55 -0
  496. package/docs/v1/basics/objFilter.md +57 -86
  497. package/docs/v1/basics/promiseUtils.md +12 -3
  498. package/docs/v1/basics/text.md +0 -1
  499. package/docs/v1/libs/array/TinyArrayComparator.md +50 -39
  500. package/docs/v1/libs/fs/TinyFS.md +752 -0
  501. package/docs/v1/libs/fs/TinyOPFSFileSystem.md +495 -0
  502. package/docs/v1/libs/fs/TinyStorageBucketFileSystem.md +407 -0
  503. package/docs/v1/libs/plugin/TinyPlugin.md +441 -0
  504. package/docs/v1/libs/plugin/TinyVersion.md +145 -0
  505. package/docs/v1/libs/router/TinyRouter.md +216 -0
  506. package/docs/v1/libs/storage/TinyMapCache.md +219 -0
  507. package/docs/v1/libs/storage/TinySetMapDatabase.md +478 -0
  508. package/docs/v1/libs/sw/browser/TinyNotificationAdapter.md +280 -0
  509. package/docs/v1/libs/sw/browser/TinyPushManager.md +782 -0
  510. package/docs/v1/libs/sw/browser/TinyServiceWorker.md +365 -0
  511. package/docs/v1/libs/sw/browser/plugins/TabManager.md +133 -0
  512. package/docs/v1/libs/sw/service/TinyPushRouter.md +314 -0
  513. package/docs/v1/libs/sw/service/TinyServiceWorkerEngine.md +748 -0
  514. package/docs/v1/libs/sw/service/plugins/GlobBypassPlugin.md +229 -0
  515. package/docs/v1/libs/sw/service/plugins/GlobCachePlugin.md +91 -0
  516. package/docs/v1/libs/sw/service/plugins/Ping.md +36 -0
  517. package/docs/v1/libs/sw/service/plugins/TabManager.md +64 -0
  518. package/docs/v1/libs/sw/service/plugins/ViteFileDetector.md +92 -0
  519. package/docs/v1/libs/sw/service/shared/TinyPushPayload.md +316 -0
  520. package/docs/v1/libs/text/TinyI18.md +80 -56
  521. package/docs/v1/libs/tools/TinyBrowserMonitor.md +170 -0
  522. package/docs/v1/libs/tools/TinyDebugger.md +117 -1
  523. package/docs/v1/libs/tools/TinyHtmlTagRegexBuilder.md +141 -0
  524. package/docs/v1/libs/tools/TinyHttpResponseRegistry.md +129 -0
  525. package/docs/v1/libs/tools/TinyPasswordValidator.md +153 -0
  526. package/docs/v1/libs/tools/TinyPkgExportValidator.md +45 -1
  527. package/docs/v1/libs/tools/TinySiteMap.md +134 -0
  528. package/docs/v1/libs/tools/TinySiteMapStream.md +97 -0
  529. package/docs/v1/libs/tools/TinyURLSecurityVerifier.md +146 -0
  530. package/docs/v1/libs/tools/TinyUriParser/Discord.md +374 -0
  531. package/docs/v1/libs/tools/TinyUriParser/MatrixProtocol.md +54 -0
  532. package/docs/v1/libs/tools/TinyUriParser.md +128 -0
  533. package/docs/v1/libs/utils/TinyCloner.md +126 -0
  534. package/docs/v1/libs/utils/TinyPromiseQueue.md +1 -1
  535. package/docs/v1/libs/utils/TinyThrottledApi.md +219 -0
  536. package/docs/v1/libs/worker/browser/TinyWebWorker.md +331 -0
  537. package/docs/v1/libs/worker/engine/TinyWebWorkerEngine.md +137 -0
  538. package/docs/v1/regexp/Email.md +127 -0
  539. package/docs/v1/regexp/Glob.md +155 -0
  540. package/docs/v1/regexp/IPv4.md +103 -0
  541. package/docs/v1/regexp/IPv6.md +122 -0
  542. package/docs/v1/regexp/SegmentExtractor.md +120 -0
  543. package/docs/v1/regexp/UrlDetector.md +117 -0
  544. package/docs/v1/regexp/Username/Base.md +131 -0
  545. package/docs/v1/regexp/Username/Discord.md +267 -0
  546. package/docs/v1/regexp/Username/MatrixProtocol.md +131 -0
  547. package/docs/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters.md +565 -0
  548. package/docs/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.md +19 -7
  549. package/docs/v1/webTemplates/media/MediaValidator/v1/Browser.md +123 -0
  550. package/docs/v1/webTemplates/media/MediaValidator/v1/Node.md +136 -0
  551. package/docs/v1/webTemplates/multiformats/14.0/IPFSHasher.md +310 -0
  552. package/docs/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.md +131 -0
  553. package/docs/v1/webTemplates/vite/7.3/plugins/githubUtils.md +50 -0
  554. package/package.json +340 -22
  555. package/types/EventEmitter.d.ts +48 -0
  556. package/dist/v1/libs/text/TinyI18.d.mts.map +0 -1
@@ -0,0 +1,940 @@
1
+ import { EventEmitter } from 'events';
2
+ import { createCheckDestroyed } from '../utils/tools.mjs';
3
+ import TinyArrayComparator from '../array/TinyArrayComparator.mjs';
4
+ const checkDestroy = createCheckDestroyed('TinyBrowserMonitor');
5
+ /**
6
+ * Defines the valid identifiers for the various monitoring systems available.
7
+ * @typedef {'connectivity'|'quality'|'battery'|'device'|'cpu'|'gpu'|'performance'|'resource'|'paint'|'navigation'|'layout-shift'|'lcp'|'longtask'|'memory-usage'|'fps'|'window'|'screen'} SystemValue
8
+ */
9
+ /**
10
+ * Represents the valid units for memory formatting.
11
+ * @typedef {'bytes'|'KB'|'MB'|'GB'} MemoryFormat
12
+ */
13
+ /**
14
+ * Represents memory usage data formatted into human-readable units.
15
+ * @typedef {{ used: number; total: number; limit: number; }} MemoryHumanData
16
+ */
17
+ /**
18
+ * Represents the JavaScript heap memory usage.
19
+ * @typedef {Object} MemoryUsage
20
+ * @property {number} usedJSHeapSize - The amount of memory currently being used by the JS heap in bytes.
21
+ * @property {number} totalJSHeapSize - The total amount of memory currently allocated for the JS heap in bytes.
22
+ * @property {number} jsHeapSizeLimit - The maximum amount of memory that can be allocated for the JS heap in bytes.
23
+ * @property {boolean} enabled - Indicates if the Memory API is available.
24
+ */
25
+ /**
26
+ * Configuration options used to initialize the TinyBrowserMonitor instance.
27
+ * @typedef {Object} MonitorOptions
28
+ * @property {number} [resourceLimit=1000] - Maximum number of resource metrics to store. Use -1 for infinite.
29
+ * @property {SystemValue[]} [systems] - List of systems to enable. If empty, all are enabled.
30
+ * @property {number} [memoryIntervalMs=100] - Interval in milliseconds for memory polling.
31
+ * @property {number} [fpsIntervalMs=1000] - Interval in miliseconds for fps polling.
32
+ */
33
+ /**
34
+ * Represents the current connectivity status of the network connection.
35
+ * @typedef {Object} ConnectivityStatus
36
+ * @property {boolean} isOnline - Indicates if the browser is currently connected to a network.
37
+ */
38
+ /**
39
+ * Represents the qualitative metrics of the current network connection.
40
+ * @typedef {Object} ConnectionQuality
41
+ * @property {number} downlink - Effective bandwidth estimate in Mbps.
42
+ * @property {number} rtt - Estimated round-trip time in ms.
43
+ * @property {string} effectiveType - Effective connection type (e.g., '4g').
44
+ * @property {boolean} saveData - Whether the user has enabled data saver mode.
45
+ * @property {boolean} enabled - Indicates whether the Network Information API is available.
46
+ */
47
+ /**
48
+ * Represents the current state and availability of the device's battery information.
49
+ * @typedef {Object} BatteryStatus
50
+ * @property {number} level - Battery charge level (0 to 1).
51
+ * @property {boolean} charging - Whether the device is currently charging.
52
+ * @property {number} chargingTime - Time until full charge in seconds.
53
+ * @property {number} dischargingTime - Time until empty in seconds.
54
+ * @property {boolean} enabled - Indicates if the Battery Status API is available.
55
+ */
56
+ /**
57
+ * Represents the hardware-specific metrics of the user's device.
58
+ * @typedef {Object} GPUInfo
59
+ * @property {string} vendor - The GPU manufacturer.
60
+ * @property {string} renderer - The specific GPU model name.
61
+ */
62
+ /**
63
+ * Represents the CPU-related metrics of the user's device.
64
+ * @typedef {Object} CPUInfo
65
+ * @property {number} logicalCores - The number of logical processing cores.
66
+ */
67
+ /**
68
+ * Represents the hardware-specific metrics of the user's device.
69
+ * @typedef {Object} DeviceMetrics
70
+ * @property {number} memory - Approximate amount of device memory in GB.
71
+ * @property {CPUInfo} cpu - CPU-related metrics.
72
+ * @property {GPUInfo} gpu - GPU-related metrics.
73
+ * @property {boolean} enabled - Indicates if the requested device information was successfully retrieved.
74
+ */
75
+ /**
76
+ * Represents the performance metrics of a single loaded resource.
77
+ * @typedef {Object} ResourceMetric
78
+ * @property {string} name - The URL of the resource.
79
+ * @property {number} duration - Time taken to load the resource in ms.
80
+ * @property {string} entryType - The type of performance entry (e.g., 'resource').
81
+ */
82
+ /**
83
+ * Represents the timing data related to browser paint events.
84
+ * @typedef {Object} PaintMetrics
85
+ * @property {number} firstPaint - Time when the first pixel was painted.
86
+ * @property {number} firstContentfulPaint - Time when the first content was painted.
87
+ */
88
+ /**
89
+ * Represents the performance timing metrics related to page navigation.
90
+ * @typedef {Object} NavigationMetrics
91
+ * @property {number} ttfb - Time to first byte in ms.
92
+ * @property {number} domContentLoaded - Time until DOMContentLoaded in ms.
93
+ * @property {number} loadEvent - Time until load event in ms.
94
+ */
95
+ /**
96
+ * Represents the rendering performance in frames per second.
97
+ * @typedef {Object} FrameRateMetrics
98
+ * @property {number} fps - The current frames per second.
99
+ * @property {number} timestamp - The timestamp of the last measurement.
100
+ */
101
+ /**
102
+ * Aggregates various performance and timing metrics into a single object.
103
+ * @typedef {Object} PerformanceMetrics
104
+ * @property {PaintMetrics} paint - Paint timing metrics.
105
+ * @property {NavigationMetrics|null} navigation - Navigation timing metrics.
106
+ * @property {number} layoutShift - Cumulative Layout Shift (CLS) value.
107
+ * @property {number} lcp - Largest Contentful Paint (LCP) value in ms.
108
+ * @property {number[]} longTasks - Array of durations of long tasks in ms.
109
+ * @property {Readonly<FrameRateMetrics>} fps - Current frame rate metrics.
110
+ */
111
+ /**
112
+ * Represents the dimensions and pixel ratio of the browser viewport.
113
+ * @typedef {Object} WindowMetrics
114
+ * @property {number} width - The width of the viewport in pixels.
115
+ * @property {number} height - The height of the viewport in pixels.
116
+ * @property {number} devicePixelRatio - The device pixel ratio.
117
+ */
118
+ /**
119
+ * Represents the physical screen/monitor properties.
120
+ * @typedef {Object} ScreenMetrics
121
+ * @property {number} width - The screen width in pixels.
122
+ * @property {number} height - The screen height in pixels.
123
+ * @property {number} availWidth - The available screen width in pixels (excluding OS taskbars).
124
+ * @property {number} availHeight - The available screen height in pixels (excluding OS taskbars).
125
+ * @property {number} colorDepth - The color depth of the screen in bits.
126
+ * @property {number} pixelDepth - The pixel depth of the screen in bits.
127
+ * @property {string} orientation - The orientation of the screen (e.g., 'landscape-primary').
128
+ */
129
+ /**
130
+ * Represents a comprehensive report containing connectivity status, connection quality, recent resource performance metrics, and memory usage.
131
+ * @typedef {Object} NetworkEvent
132
+ * @property {Readonly<ConnectivityStatus>} connectivity - Current online/offline status.
133
+ * @property {Readonly<ConnectionQuality>} quality - Current network quality metrics.
134
+ * @property {Readonly<BatteryStatus>} battery - Current battery status.
135
+ * @property {Readonly<DeviceMetrics>} device - Current device hardware metrics.
136
+ * @property {Readonly<PerformanceMetrics>} performance - Comprehensive performance metrics.
137
+ * @property {Readonly<ResourceMetric[]>} resources - Recent resource loading metrics.
138
+ * @property {Readonly<MemoryUsage>} memoryUsage - Current JavaScript heap memory metrics.
139
+ * @property {Readonly<WindowMetrics>} windowMetrics - Current viewport dimensions.
140
+ * @property {Readonly<ScreenMetrics>} screenMetrics - Current screen/monitor properties.
141
+ * @property {Event} [event]
142
+ */
143
+ /**
144
+ * A callback function signature for receiving network updates.
145
+ * @typedef {(data: NetworkEvent) => void} NetworkCallback
146
+ */
147
+ /**
148
+ * Event map for {@link TinyBrowserMonitor}.
149
+ * @typedef {Object} TinyBrowserMonitorEvents
150
+ * @property {(metrics: Readonly<WindowMetrics>) => void} WindowResize - Emitted when the window is resized.
151
+ * @property {(metrics: Readonly<FrameRateMetrics>) => void} FPS - Emitted with the latest FPS sample.
152
+ * @property {(status: Readonly<BatteryStatus>) => void} BatteryUpdated - Emitted when the battery status changes.
153
+ * @property {(usage: Readonly<MemoryUsage>) => void} MemoryUsage - Emitted when the memory usage is sampled.
154
+ * @property {(oldItem: ResourceMetric|undefined, newItem: ResourceMetric) => void} ResourceAdded - Emitted when a resource is added.
155
+ * @property {(oldItem: ResourceMetric|undefined, newItem: ResourceMetric) => void} ResourceDeleted - Emitted when a resource is removed.
156
+ * @property {(oldItem: ResourceMetric|undefined, newItem: ResourceMetric) => void} ResourceEdited - Emitted when a resource is edited.
157
+ * @property {(paint: Readonly<PaintMetrics>) => void} PaintUpdated - Emitted when paint metrics change.
158
+ * @property {(navigation: Partial<NavigationMetrics>) => void} NavigationUpdated - Emitted when navigation metrics change.
159
+ * @property {(data: { layoutShift: number }) => void} LayoutShiftUpdated - Emitted when the layout shift changes.
160
+ * @property {(data: { lcp: number }) => void} LcpUpdated - Emitted when the LCP value changes.
161
+ * @property {(data: { lcp: number[] }) => void} LongTaskUpdated - Emitted when long tasks are recorded.
162
+ * @property {(status: Readonly<ConnectivityStatus>) => void} ConnectivityUpdated - Emitted when connectivity changes.
163
+ * @property {(data: NetworkEvent) => void} NetworkUpdated - Emitted with the full network report.
164
+ * @property {() => void} Destroyed - Emitted when the monitor is destroyed.
165
+ */
166
+ /** @type {new (options?: MonitorOptions) => import('../../jsdoc/EventEmitter.mjs').ICustomEventEmitter<TinyBrowserMonitorEvents>} */
167
+ const TypedEventEmitter = /** @type {any} */ (EventEmitter);
168
+ /**
169
+ * An advanced monitor that tracks connectivity, connection quality, battery,
170
+ * device constraints, and comprehensive performance metrics.
171
+ */
172
+ class TinyBrowserMonitor extends TypedEventEmitter {
173
+ /**
174
+ * A list of all valid identifiers for the monitoring systems.
175
+ * @type {SystemValue[]}
176
+ */
177
+ static #VALID_SYSTEMS = [
178
+ 'connectivity',
179
+ 'quality',
180
+ 'battery',
181
+ 'device',
182
+ 'cpu',
183
+ 'gpu',
184
+ 'performance',
185
+ 'resource',
186
+ 'paint',
187
+ 'navigation',
188
+ 'layout-shift',
189
+ 'lcp',
190
+ 'longtask',
191
+ 'memory-usage',
192
+ 'fps',
193
+ 'window',
194
+ 'screen',
195
+ ];
196
+ /**
197
+ * Retrieves a read-only copy of the valid system identifiers.
198
+ * @returns {Readonly<SystemValue[]>} A read-only array of valid system values.
199
+ */
200
+ static get VALID_SYSTEMS() {
201
+ return Object.freeze([...TinyBrowserMonitor.#VALID_SYSTEMS]);
202
+ }
203
+ /** @type {boolean} Indicates whether the monitor has been destroyed. */
204
+ #isDestroyed = false;
205
+ /** @type {Set<SystemValue>} A set containing the identifiers for the systems currently being monitored. */
206
+ #enabledSystems = new Set();
207
+ /**
208
+ * The current network status.
209
+ * @type {ConnectivityStatus}
210
+ */
211
+ #connectivity = { isOnline: navigator.onLine };
212
+ /** @type {null|NodeJS.Timeout} */
213
+ #memoryInterval = null;
214
+ /** @type {number} */
215
+ #memoryIntervalMs;
216
+ /** @type {number} */
217
+ #fpsInternvalMs;
218
+ /** @type {MemoryUsage} The current JavaScript heap memory usage. */
219
+ #memoryUsage = {
220
+ usedJSHeapSize: 0,
221
+ totalJSHeapSize: 0,
222
+ jsHeapSizeLimit: 0,
223
+ enabled: !!performance.memory,
224
+ };
225
+ /** @type {ConnectionQuality} Stores the current network quality metrics. */
226
+ #quality = {
227
+ downlink: 0,
228
+ rtt: 0,
229
+ effectiveType: 'unknown',
230
+ saveData: false,
231
+ enabled: !!navigator.connection,
232
+ };
233
+ /** @type {ResourceMetric[]} A collection of recent resource loading metrics. */
234
+ #resources = [];
235
+ /** @type {BatteryStatus} The current status of the device's battery. */
236
+ #battery = {
237
+ level: 1,
238
+ charging: true,
239
+ chargingTime: 0,
240
+ dischargingTime: 0,
241
+ enabled: false,
242
+ };
243
+ /** @type {DeviceMetrics} The current hardware metrics of the device. */
244
+ #deviceMetrics = {
245
+ memory: 0,
246
+ cpu: {
247
+ logicalCores: 0,
248
+ },
249
+ gpu: {
250
+ vendor: 'unknown',
251
+ renderer: 'unknown',
252
+ },
253
+ enabled: !!navigator.deviceMemory,
254
+ };
255
+ /** @type {FrameRateMetrics} The current frame rate metrics. */
256
+ #fps = {
257
+ fps: 60,
258
+ timestamp: performance.now(),
259
+ };
260
+ /** @type {number|null} The animation frame request ID for the FPS loop. */
261
+ #fpsRequestId = null;
262
+ /** @type {PerformanceMetrics} The current performance and timing metrics. */
263
+ #performance = {
264
+ paint: { firstPaint: 0, firstContentfulPaint: 0 },
265
+ navigation: null,
266
+ layoutShift: 0,
267
+ lcp: 0,
268
+ fps: this.#fps,
269
+ longTasks: [],
270
+ };
271
+ /** @type {WindowMetrics} The current viewport dimensions. */
272
+ #windowMetrics = {
273
+ width: window.innerWidth,
274
+ height: window.innerHeight,
275
+ devicePixelRatio: window.devicePixelRatio,
276
+ };
277
+ /** @type {ScreenMetrics} The current screen/monitor properties. */
278
+ #screenMetrics = {
279
+ width: window.screen.width,
280
+ height: window.screen.height,
281
+ availWidth: window.screen.availWidth,
282
+ availHeight: window.screen.availHeight,
283
+ colorDepth: window.screen.colorDepth,
284
+ pixelDepth: window.screen.pixelDepth,
285
+ orientation: window.screen.orientation?.type || 'unknown',
286
+ };
287
+ /** @type {number} Maximum number of resource metrics to store. Use -1 for infinite. */
288
+ #resourceLimit;
289
+ /** @type {PerformanceObserver[]} The observer used to track performance entries. */
290
+ #observers = [];
291
+ /**
292
+ * Creates an instance of TinyBrowserMonitor.
293
+ * @param {MonitorOptions} [options={}] - Configuration options.
294
+ * @throws {TypeError} If the provided resourceLimit is invalid, memoryIntervalMs is invalid, or systems is not an array.
295
+ * @throws {TypeError} If any provided system is not a valid SystemValue.
296
+ */
297
+ constructor(options = {}) {
298
+ super();
299
+ const { resourceLimit = 1000, systems = [], memoryIntervalMs = 100, fpsIntervalMs = 1000, } = options;
300
+ // 1. Validate resourceLimit
301
+ if (typeof resourceLimit !== 'number' || resourceLimit < -1) {
302
+ throw new TypeError('The resourceLimit must be a number greater than or equal to -1.');
303
+ }
304
+ // 2. Validate memoryIntervalMs with a safety floor (16ms ~ 60fps) to prevent CPU exhaustion
305
+ if (typeof memoryIntervalMs !== 'number' || memoryIntervalMs < 16) {
306
+ throw new TypeError('The memoryIntervalMs must be a number greater than or equal to 16.');
307
+ }
308
+ // 2. Validate fpsIntervalMs value
309
+ if (typeof fpsIntervalMs !== 'number' || fpsIntervalMs < 0) {
310
+ throw new TypeError('The fpsIntervalMs must be a number greater than or equal to 0.');
311
+ }
312
+ // 3. Validate systems is an array and contains only valid SystemValue types
313
+ if (!Array.isArray(systems)) {
314
+ throw new TypeError('The systems option must be an array.');
315
+ }
316
+ for (const system of systems) {
317
+ if (!TinyBrowserMonitor.#VALID_SYSTEMS.includes(system)) {
318
+ throw new TypeError(`Invalid system identifier: "${system}". Must be one of: ${TinyBrowserMonitor.#VALID_SYSTEMS.join(', ')}`);
319
+ }
320
+ }
321
+ this.#resourceLimit = resourceLimit;
322
+ this.#memoryIntervalMs = memoryIntervalMs;
323
+ this.#fpsInternvalMs = fpsIntervalMs;
324
+ // Logic: If systems array is empty, enable everything.
325
+ this.#enabledSystems =
326
+ systems.length === 0 ? new Set(TinyBrowserMonitor.#VALID_SYSTEMS) : new Set(systems);
327
+ this.#initializeSelectedSystems();
328
+ this.#notify();
329
+ }
330
+ /**
331
+ * Initializes only the systems selected in the options.
332
+ */
333
+ #initializeSelectedSystems() {
334
+ if (this.#enabledSystems.has('connectivity')) {
335
+ this.#setupListeners();
336
+ }
337
+ if (this.#enabledSystems.has('quality')) {
338
+ this.#updateQualityMetrics();
339
+ }
340
+ if (this.#enabledSystems.has('battery')) {
341
+ this.#setupBatteryMonitoring();
342
+ }
343
+ if (this.#enabledSystems.has('memory-usage')) {
344
+ this.#setupMemoryUsage();
345
+ }
346
+ if (this.#enabledSystems.has('fps')) {
347
+ this.#setupFPSMonitoring();
348
+ }
349
+ if (this.#enabledSystems.has('window')) {
350
+ this.#setupWindowMonitoring();
351
+ }
352
+ if (this.#enabledSystems.has('screen')) {
353
+ this.#updateScreenMetrics();
354
+ }
355
+ // Hardware initialization:
356
+ // Triggers if 'device' (memory), 'cpu', or 'gpu' is explicitly requested.
357
+ const hasHardwareRequested = this.#enabledSystems.has('device') ||
358
+ this.#enabledSystems.has('cpu') ||
359
+ this.#enabledSystems.has('gpu');
360
+ if (hasHardwareRequested) {
361
+ this.#setupDeviceMetrics();
362
+ }
363
+ // Performance logic:
364
+ // If 'performance' is enabled, we enable all performance observers.
365
+ // Otherwise, we only enable the specific sub-types requested in the systems array.
366
+ /** @type {SystemValue[]} */
367
+ const performanceKeys = ['resource', 'paint', 'navigation', 'layout-shift', 'lcp', 'longtask'];
368
+ const isPerformanceEnabled = this.#enabledSystems.has('performance');
369
+ const hasSpecificPerformanceRequested = performanceKeys.some((key) => this.#enabledSystems.has(key));
370
+ if (isPerformanceEnabled || hasSpecificPerformanceRequested) {
371
+ this.#setupPerformanceObservers(isPerformanceEnabled);
372
+ }
373
+ }
374
+ /**
375
+ * Indicates whether the monitor has been destroyed.
376
+ * @returns {boolean} True if the monitor has been destroyed, false otherwise.
377
+ */
378
+ get isDestroyed() {
379
+ return this.#isDestroyed;
380
+ }
381
+ /**
382
+ * Returns the current connectivity status.
383
+ * @returns {Readonly<ConnectivityStatus>} A deep clone of the connectivity status.
384
+ */
385
+ get connectivity() {
386
+ checkDestroy(this.#isDestroyed);
387
+ return Object.freeze({ ...this.#connectivity });
388
+ }
389
+ /**
390
+ * Returns the current connection quality metrics.
391
+ * @returns {Readonly<ConnectionQuality>} A deep clone of the quality metrics.
392
+ */
393
+ get quality() {
394
+ checkDestroy(this.#isDestroyed);
395
+ return Object.freeze({ ...this.#quality });
396
+ }
397
+ /**
398
+ * Returns the collection of recent resource loading metrics.
399
+ * @returns {Readonly<ResourceMetric[]>} A deep freeze of the resources array.
400
+ */
401
+ get resources() {
402
+ checkDestroy(this.#isDestroyed);
403
+ return Object.freeze(this.#resources.map((res) => Object.freeze({ ...res })));
404
+ }
405
+ /**
406
+ * Returns the current battery status.
407
+ * @returns {Readonly<BatteryStatus>} A deep clone of the battery status.
408
+ */
409
+ get battery() {
410
+ checkDestroy(this.#isDestroyed);
411
+ return Object.freeze({ ...this.#battery });
412
+ }
413
+ /**
414
+ * Returns the current viewport dimensions.
415
+ * @returns {Readonly<WindowMetrics>} A deep clone of the window metrics.
416
+ */
417
+ get windowMetrics() {
418
+ checkDestroy(this.#isDestroyed);
419
+ return Object.freeze({ ...this.#windowMetrics });
420
+ }
421
+ /**
422
+ * Returns the current screen/monitor properties.
423
+ * @returns {Readonly<ScreenMetrics>} A deep clone of the screen metrics.
424
+ */
425
+ get screenMetrics() {
426
+ checkDestroy(this.#isDestroyed);
427
+ return Object.freeze({ ...this.#screenMetrics });
428
+ }
429
+ /**
430
+ * Returns the current device hardware metrics.
431
+ * @returns {Readonly<DeviceMetrics>} A deep clone of the device metrics.
432
+ */
433
+ get device() {
434
+ checkDestroy(this.#isDestroyed);
435
+ return Object.freeze({ ...this.#deviceMetrics });
436
+ }
437
+ /**
438
+ * Returns the current frame rate metrics.
439
+ * @type {FrameRateMetrics}
440
+ */
441
+ get fps() {
442
+ checkDestroy(this.#isDestroyed);
443
+ return Object.freeze({ ...this.#fps });
444
+ }
445
+ /**
446
+ * Returns the current performance metrics.
447
+ * @returns {Readonly<PerformanceMetrics>} A deep clone of the performance metrics.
448
+ */
449
+ get performance() {
450
+ checkDestroy(this.#isDestroyed);
451
+ return Object.freeze({
452
+ ...this.#performance,
453
+ paint: Object.freeze({ ...this.#performance.paint }),
454
+ fps: Object.freeze({ ...this.#performance.fps }),
455
+ navigation: this.#performance.navigation
456
+ ? Object.freeze({ ...this.#performance.navigation })
457
+ : null,
458
+ });
459
+ }
460
+ /**
461
+ * Returns the current JavaScript heap memory usage.
462
+ * @type {MemoryUsage}
463
+ */
464
+ get memoryUsage() {
465
+ checkDestroy(this.#isDestroyed);
466
+ return Object.freeze({ ...this.#memoryUsage });
467
+ }
468
+ /**
469
+ * Returns an array of all currently enabled systems.
470
+ * @returns {Readonly<SystemValue[]>} A read-only array of enabled system identifiers.
471
+ */
472
+ get enabledSystems() {
473
+ checkDestroy(this.#isDestroyed);
474
+ return Object.freeze([...this.#enabledSystems]);
475
+ }
476
+ /**
477
+ * Checks if a specific system is currently enabled.
478
+ * @param {SystemValue} system - The identifier of the system to check.
479
+ * @returns {boolean} True if the system is enabled, false otherwise.
480
+ * @throws {TypeError} If the provided system is not a string.
481
+ */
482
+ has(system) {
483
+ checkDestroy(this.#isDestroyed);
484
+ if (typeof system !== 'string') {
485
+ throw new TypeError('The system identifier must be a string.');
486
+ }
487
+ return this.#enabledSystems.has(system);
488
+ }
489
+ /**
490
+ * Returns the number of currently enabled systems.
491
+ * @returns {number} The count of enabled systems.
492
+ */
493
+ get size() {
494
+ checkDestroy(this.#isDestroyed);
495
+ return this.#enabledSystems.size;
496
+ }
497
+ /**
498
+ * Formats the current memory usage metrics into a human-readable string.
499
+ * @param {MemoryFormat} format - The desired unit for the output.
500
+ * @param {MemoryUsage} [memoryUsage=this.#memoryUsage] - The memory usage object.
501
+ * @returns {MemoryHumanData} A formatted string containing used, total, and limit memory.
502
+ * @throws {TypeError} If the provided format is invalid or if memoryUsage is malformed.
503
+ */
504
+ getFormattedMemoryUsage(format, memoryUsage = this.#memoryUsage) {
505
+ checkDestroy(this.#isDestroyed);
506
+ const validFormats = ['bytes', 'KB', 'MB', 'GB'];
507
+ if (typeof format !== 'string' || !validFormats.includes(format)) {
508
+ throw new TypeError(`Invalid format: "${format}". Must be one of: ${validFormats.join(', ')}`);
509
+ }
510
+ if (typeof memoryUsage !== 'object' || memoryUsage === null) {
511
+ throw new TypeError('The memoryUsage argument must be a non-null object.');
512
+ }
513
+ const requiredProperties = ['usedJSHeapSize', 'totalJSHeapSize', 'jsHeapSizeLimit'];
514
+ for (const prop of requiredProperties) {
515
+ // @ts-ignore
516
+ if (typeof memoryUsage[prop] !== 'number' || Number.isNaN(memoryUsage[prop])) {
517
+ throw new TypeError(`Invalid memoryUsage: Property "${prop}" must be a valid number.`);
518
+ }
519
+ }
520
+ const units = {
521
+ bytes: 1,
522
+ KB: 1024,
523
+ MB: Math.pow(1024, 2),
524
+ GB: Math.pow(1024, 3),
525
+ };
526
+ const divisor = units[format];
527
+ /** @type {(value: number) => number} */
528
+ const formatValue = (value) => value / divisor;
529
+ return {
530
+ used: formatValue(memoryUsage.usedJSHeapSize),
531
+ total: formatValue(memoryUsage.totalJSHeapSize),
532
+ limit: formatValue(memoryUsage.jsHeapSizeLimit),
533
+ };
534
+ }
535
+ /**
536
+ * Initializes window size monitoring by listening to resize events.
537
+ */
538
+ #setupWindowMonitoring() {
539
+ window.addEventListener('resize', this.#handleWindowResize);
540
+ this.#updateWindowMetrics();
541
+ }
542
+ /**
543
+ * Updates the window metrics based on the current viewport state.
544
+ */
545
+ #updateWindowMetrics() {
546
+ this.#windowMetrics = {
547
+ width: window.innerWidth,
548
+ height: window.innerHeight,
549
+ devicePixelRatio: window.devicePixelRatio,
550
+ };
551
+ }
552
+ /**
553
+ * Updates the screen metrics.
554
+ */
555
+ #updateScreenMetrics() {
556
+ this.#screenMetrics = {
557
+ width: window.screen.width,
558
+ height: window.screen.height,
559
+ availWidth: window.screen.availWidth,
560
+ availHeight: window.screen.availHeight,
561
+ colorDepth: window.screen.colorDepth,
562
+ pixelDepth: window.screen.pixelDepth,
563
+ orientation: window.screen.orientation?.type || 'unknown',
564
+ };
565
+ }
566
+ /**
567
+ * Event handler for window resize events.
568
+ * @bind {TinyBrowserMonitor}
569
+ */
570
+ #handleWindowResize = () => {
571
+ this.#updateWindowMetrics();
572
+ this.emit('WindowResize', Object.freeze({ ...this.#windowMetrics }));
573
+ };
574
+ /**
575
+ * Attaches event listeners to the window and connection APIs.
576
+ */
577
+ #setupListeners() {
578
+ window.addEventListener('online', this.#handleUpdate);
579
+ window.addEventListener('offline', this.#handleUpdate);
580
+ if (navigator.connection) {
581
+ navigator.connection.addEventListener('change', this.#handleUpdate);
582
+ }
583
+ }
584
+ /**
585
+ * Initializes FPS monitoring to track rendering performance (GPU/CPU proxy).
586
+ */
587
+ #setupFPSMonitoring() {
588
+ let frameCount = 0;
589
+ let lastTime = performance.now();
590
+ /** @param {number} currentTime */
591
+ const loop = (currentTime) => {
592
+ frameCount++;
593
+ // Update metrics every 1 second
594
+ if (currentTime - lastTime >= this.#fpsInternvalMs) {
595
+ this.#fps = {
596
+ fps: Math.round((frameCount * 1000) / (currentTime - lastTime)),
597
+ timestamp: currentTime,
598
+ };
599
+ frameCount = 0;
600
+ lastTime = currentTime;
601
+ this.emit('FPS', Object.freeze({ ...this.#fps }));
602
+ }
603
+ this.#fpsRequestId = requestAnimationFrame(loop);
604
+ };
605
+ this.#fpsRequestId = requestAnimationFrame(loop);
606
+ }
607
+ /**
608
+ * Initializes hardware-specific metrics based on enabled systems.
609
+ */
610
+ #setupDeviceMetrics() {
611
+ // Initialize with default/empty values to maintain structure
612
+ this.#deviceMetrics = {
613
+ memory: 0,
614
+ cpu: { logicalCores: 0 },
615
+ gpu: { vendor: 'unknown', renderer: 'unknown' },
616
+ enabled: false,
617
+ };
618
+ let anyDataRetrieved = false;
619
+ if (this.#enabledSystems.has('device')) {
620
+ // 1. Memory (via 'device' permission)
621
+ if (typeof navigator.deviceMemory === 'number') {
622
+ this.#deviceMetrics.memory = navigator.deviceMemory;
623
+ anyDataRetrieved = true;
624
+ }
625
+ // 2. CPU (via 'cpu' or 'device' permission)
626
+ if (this.#enabledSystems.has('cpu')) {
627
+ if (typeof navigator.hardwareConcurrency === 'number') {
628
+ this.#deviceMetrics.cpu.logicalCores = navigator.hardwareConcurrency;
629
+ anyDataRetrieved = true;
630
+ }
631
+ }
632
+ // 3. GPU (via 'gpu' or 'device' permission)
633
+ if (this.#enabledSystems.has('gpu')) {
634
+ try {
635
+ const canvas = document.createElement('canvas');
636
+ const gl = canvas.getContext('webgl') || canvas.getContext('experimental-webgl');
637
+ if (gl instanceof WebGLRenderingContext) {
638
+ const debugInfo = gl.getExtension('WEBGL_debug_renderer_info');
639
+ if (debugInfo) {
640
+ this.#deviceMetrics.gpu.vendor =
641
+ gl.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL) || 'unknown';
642
+ this.#deviceMetrics.gpu.renderer =
643
+ gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL) || 'unknown';
644
+ anyDataRetrieved = true;
645
+ }
646
+ }
647
+ }
648
+ catch (e) {
649
+ console.warn('TinyBrowserMonitor: GPU retrieval failed.', e);
650
+ }
651
+ }
652
+ }
653
+ this.#deviceMetrics.enabled = anyDataRetrieved;
654
+ }
655
+ /**
656
+ * Asynchronously initializes battery monitoring using the Battery Status API.
657
+ * @returns {Promise<void>}
658
+ */
659
+ async #setupBatteryMonitoring() {
660
+ if (navigator.getBattery) {
661
+ try {
662
+ const battery = await navigator.getBattery();
663
+ this.#battery.enabled = true;
664
+ const updateBattery = () => {
665
+ this.#battery = {
666
+ level: battery.level,
667
+ charging: battery.charging,
668
+ chargingTime: battery.chargingTime,
669
+ dischargingTime: battery.dischargingTime,
670
+ enabled: true,
671
+ };
672
+ this.emit('BatteryUpdated', Object.freeze({ ...this.#battery }));
673
+ this.#notify();
674
+ };
675
+ battery.addEventListener('levelchange', updateBattery);
676
+ battery.addEventListener('chargingchange', updateBattery);
677
+ battery.addEventListener('chargingtimechange', updateBattery);
678
+ battery.addEventListener('dischargingtimechange', updateBattery);
679
+ updateBattery();
680
+ }
681
+ catch (error) {
682
+ console.warn('Battery Status API failed to initialize:', error);
683
+ }
684
+ }
685
+ }
686
+ /**
687
+ * Initializes memory monitoring using the Performance Memory API.
688
+ */
689
+ #setupMemoryUsage() {
690
+ const memory = performance.memory;
691
+ if (memory) {
692
+ const updateMemory = () => {
693
+ const memory = performance.memory;
694
+ if (!memory)
695
+ return;
696
+ this.#memoryUsage = {
697
+ usedJSHeapSize: memory.usedJSHeapSize,
698
+ totalJSHeapSize: memory.totalJSHeapSize,
699
+ jsHeapSizeLimit: memory.jsHeapSizeLimit,
700
+ enabled: true,
701
+ };
702
+ this.emit('MemoryUsage', Object.freeze({ ...this.#memoryUsage }));
703
+ };
704
+ // Since performance.memory is not event-driven, we poll it periodically.
705
+ // We use a standard interval to check for changes.
706
+ this.#memoryInterval = setInterval(updateMemory, this.#memoryIntervalMs);
707
+ updateMemory();
708
+ }
709
+ }
710
+ /**
711
+ * Initializes and starts PerformanceObservers based on enabled systems.
712
+ * @param {boolean} [enableAll=false] - If true, enables all performance observers.
713
+ */
714
+ #setupPerformanceObservers(enableAll = false) {
715
+ /** @type {({ key: SystemValue; type: string; callback: (list: PerformanceObserverEntryList) => void; })[]} */
716
+ const observerMapping = [
717
+ { key: 'resource', type: 'resource', callback: this.#handleResourceEntry.bind(this) },
718
+ { key: 'paint', type: 'paint', callback: this.#handlePaintEntry.bind(this) },
719
+ { key: 'navigation', type: 'navigation', callback: this.#handleNavigationEntry.bind(this) },
720
+ {
721
+ key: 'layout-shift',
722
+ type: 'layout-shift',
723
+ callback: this.#handleLayoutShiftEntry.bind(this),
724
+ },
725
+ { key: 'lcp', type: 'largest-contentful-paint', callback: this.#handleLCPEntry.bind(this) },
726
+ { key: 'longtask', type: 'longtask', callback: this.#handleLongTaskEntry.bind(this) },
727
+ ];
728
+ for (const config of observerMapping) {
729
+ if (enableAll || this.#enabledSystems.has(config.key)) {
730
+ try {
731
+ const observer = new PerformanceObserver(config.callback);
732
+ observer.observe({ type: config.type, buffered: true });
733
+ this.#observers.push(observer);
734
+ }
735
+ catch (e) {
736
+ console.error(e);
737
+ // Silently skip unsupported observer types
738
+ }
739
+ }
740
+ }
741
+ }
742
+ /**
743
+ * Processes new resource performance entries and maintains the resource history.
744
+ * @param {PerformanceObserverEntryList} list - The list of performance entries.
745
+ */
746
+ #handleResourceEntry(list) {
747
+ const entries = list.getEntries();
748
+ /** @type {TinyArrayComparator<ResourceMetric>} */
749
+ const comparator = new TinyArrayComparator(this.#resources.map((v) => ({ ...v })), { idKey: 'name' });
750
+ entries.forEach((entry) => {
751
+ this.#resources.push({
752
+ name: entry.name,
753
+ duration: entry.duration,
754
+ entryType: entry.entryType,
755
+ });
756
+ });
757
+ // Handle resource limit (FIFO logic)
758
+ if (this.#resourceLimit > 0 && this.#resources.length > this.#resourceLimit) {
759
+ this.#resources.splice(0, this.#resources.length - this.#resourceLimit);
760
+ }
761
+ const compareResult = comparator.compare(this.#resources);
762
+ for (const result of compareResult) {
763
+ this.emit(`Resource${result.status === 'added' ? 'Added' : result.status === 'deleted' ? 'Deleted' : 'Edited'}`, result.oldItem, result.item);
764
+ }
765
+ this.#notify();
766
+ }
767
+ /**
768
+ * Processes paint-related performance entries to update paint timing metrics.
769
+ * @param {PerformanceObserverEntryList} list - The list of performance entries.
770
+ */
771
+ #handlePaintEntry(list) {
772
+ list.getEntries().forEach((entry) => {
773
+ if (entry.name === 'first-paint') {
774
+ this.#performance.paint.firstPaint = entry.startTime;
775
+ }
776
+ else if (entry.name === 'first-contentful-paint') {
777
+ this.#performance.paint.firstContentfulPaint = entry.startTime;
778
+ }
779
+ });
780
+ this.emit('PaintUpdated', Object.freeze({ ...this.#performance.paint }));
781
+ this.#notify();
782
+ }
783
+ /**
784
+ * Extracts and updates navigation timing metrics from performance entries.
785
+ * @param {PerformanceObserverEntryList} list - The list of performance entries.
786
+ */
787
+ #handleNavigationEntry(list) {
788
+ /** @type {PerformanceNavigationTiming} */
789
+ // @ts-ignore
790
+ const entry = list.getEntries()[0];
791
+ if (entry) {
792
+ this.#performance.navigation = {
793
+ ttfb: entry.responseStart - entry.requestStart,
794
+ domContentLoaded: entry.domContentLoadedEventEnd - entry.startTime,
795
+ loadEvent: entry.loadEventEnd - entry.startTime,
796
+ };
797
+ }
798
+ this.emit('NavigationUpdated', Object.freeze({ ...this.#performance.navigation }));
799
+ this.#notify();
800
+ }
801
+ /**
802
+ * Processes layout shift entries to track Cumulative Layout Shift (CLS).
803
+ * @param {PerformanceObserverEntryList} list - The list of performance entries.
804
+ */
805
+ #handleLayoutShiftEntry(list) {
806
+ list.getEntries().forEach((entry) => {
807
+ /** @type {LayoutShift} */
808
+ // @ts-ignore
809
+ const shiftEntry = entry;
810
+ if (!shiftEntry.hadRecentInput) {
811
+ this.#performance.layoutShift += shiftEntry.value;
812
+ }
813
+ });
814
+ this.emit('LayoutShiftUpdated', { layoutShift: this.#performance.layoutShift });
815
+ this.#notify();
816
+ }
817
+ /**
818
+ * Updates the Largest Contentful Paint (LCP) value using the latest entry.
819
+ * @param {PerformanceObserverEntryList} list - The list of performance entries.
820
+ */
821
+ #handleLCPEntry(list) {
822
+ const lastEntry = list.getEntries().pop();
823
+ if (lastEntry) {
824
+ this.#performance.lcp = lastEntry.startTime;
825
+ }
826
+ this.emit('LcpUpdated', { lcp: this.#performance.lcp });
827
+ this.#notify();
828
+ }
829
+ /**
830
+ * Collects durations of long tasks to monitor main thread responsiveness.
831
+ * @param {PerformanceObserverEntryList} list - The list of performance entries.
832
+ */
833
+ #handleLongTaskEntry(list) {
834
+ list.getEntries().forEach((entry) => {
835
+ this.#performance.longTasks.push(entry.duration);
836
+ });
837
+ this.emit('LongTaskUpdated', { lcp: [...this.#performance.longTasks] });
838
+ this.#notify();
839
+ }
840
+ /**
841
+ * Internal handler for network events.
842
+ * @param {Event} event - The browser event object.
843
+ * @bind {TinyBrowserMonitor}
844
+ */
845
+ #handleUpdate = (event) => {
846
+ if (this.#enabledSystems.has('connectivity')) {
847
+ this.#updateConnectivity();
848
+ }
849
+ if (this.#enabledSystems.has('quality')) {
850
+ this.#updateQualityMetrics();
851
+ }
852
+ this.#notify(event);
853
+ };
854
+ /**
855
+ * Updates the connectivity status.
856
+ */
857
+ #updateConnectivity() {
858
+ this.#connectivity = { isOnline: navigator.onLine };
859
+ this.emit('ConnectivityUpdated', { ...this.#connectivity });
860
+ }
861
+ /**
862
+ * Updates the connection quality metrics using the Network Information API.
863
+ */
864
+ #updateQualityMetrics() {
865
+ if (navigator.connection) {
866
+ const { downlink, rtt, effectiveType, saveData } = navigator.connection;
867
+ // Strict validation of connection properties
868
+ this.#quality = {
869
+ downlink: typeof downlink === 'number' ? downlink : 0,
870
+ rtt: typeof rtt === 'number' ? rtt : 0,
871
+ effectiveType: typeof effectiveType === 'string' ? effectiveType : 'unknown',
872
+ saveData: typeof saveData === 'boolean' ? saveData : false,
873
+ enabled: true,
874
+ };
875
+ }
876
+ }
877
+ /**
878
+ * Validates the data structure and executes the callback and emitters.
879
+ * @param {Event} [event] - The browser event object.
880
+ */
881
+ #notify(event) {
882
+ this.#validateInternalState();
883
+ /** @type {NetworkEvent} */
884
+ const data = {
885
+ connectivity: Object.freeze({ ...this.#connectivity }),
886
+ quality: Object.freeze({ ...this.#quality }),
887
+ resources: Object.freeze(this.#resources.map((res) => Object.freeze({ ...res }))),
888
+ battery: Object.freeze({ ...this.#battery }),
889
+ device: Object.freeze({ ...this.#deviceMetrics }),
890
+ performance: this.performance,
891
+ memoryUsage: Object.freeze({ ...this.#memoryUsage }),
892
+ windowMetrics: Object.freeze({ ...this.#windowMetrics }),
893
+ screenMetrics: Object.freeze({ ...this.#screenMetrics }),
894
+ event,
895
+ };
896
+ this.emit('NetworkUpdated', data);
897
+ }
898
+ /**
899
+ * Validates internal state to prevent runtime corruption.
900
+ * @throws {TypeError} If internal state is inconsistent.
901
+ */
902
+ #validateInternalState() {
903
+ if (typeof this.#connectivity.isOnline !== 'boolean') {
904
+ throw new TypeError('Internal Error: Connectivity status is invalid.');
905
+ }
906
+ if (typeof this.#quality.downlink !== 'number') {
907
+ throw new TypeError('Internal Error: Quality metrics are invalid.');
908
+ }
909
+ }
910
+ /**
911
+ * Removes all listeners and observers to prevent memory leaks.
912
+ */
913
+ destroy() {
914
+ if (this.#isDestroyed)
915
+ return;
916
+ if (this.#enabledSystems.has('connectivity')) {
917
+ window.removeEventListener('online', this.#handleUpdate);
918
+ window.removeEventListener('offline', this.#handleUpdate);
919
+ }
920
+ if (this.#enabledSystems.has('window')) {
921
+ window.removeEventListener('resize', this.#handleWindowResize);
922
+ }
923
+ if (this.#enabledSystems.has('quality') && navigator.connection) {
924
+ navigator.connection.removeEventListener('change', this.#handleUpdate);
925
+ }
926
+ if (this.#enabledSystems.has('performance')) {
927
+ this.#observers.forEach((obs) => obs.disconnect());
928
+ this.#observers = [];
929
+ }
930
+ if (this.#memoryInterval)
931
+ clearInterval(this.#memoryInterval);
932
+ if (this.#fpsRequestId) {
933
+ cancelAnimationFrame(this.#fpsRequestId);
934
+ }
935
+ this.removeAllListeners();
936
+ this.#isDestroyed = true;
937
+ this.emit('Destroyed');
938
+ }
939
+ }
940
+ export default TinyBrowserMonitor;