tiny-essentials 1.28.19 → 1.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/changelog/1/28/19.md +24 -0
- package/changelog/1/29/0.md +58 -0
- package/dist/v1/ColorSafeStringify.min.js +1 -1
- package/dist/v1/TinyAdvancedRaffle.min.js +1 -1
- package/dist/v1/TinyAfterScrollWatcher.min.js +1 -1
- package/dist/v1/TinyAnalogClock.min.js +1 -1
- package/dist/v1/TinyArrayComparator.min.js +1 -1
- package/dist/v1/TinyArrayPaginator.min.js +1 -1
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyBrowserMonitor.min.js +1 -0
- package/dist/v1/TinyClassManager.min.js +1 -1
- package/dist/v1/TinyClipboard.min.js +1 -1
- package/dist/v1/TinyCloner.min.js +1 -0
- package/dist/v1/TinyColorConverter.min.js +1 -1
- package/dist/v1/TinyColorValidator.min.js +1 -1
- package/dist/v1/TinyCookieConsent.min.js +1 -1
- package/dist/v1/TinyDayNightCycle.min.js +1 -1
- package/dist/v1/TinyDebugger.min.js +1 -1
- package/dist/v1/TinyDomReadyManager.min.js +1 -1
- package/dist/v1/TinyDragDropDetector.min.js +1 -1
- package/dist/v1/TinyDragger.min.js +1 -1
- package/dist/v1/TinyElementObserver.min.js +1 -1
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyGamepad.min.js +1 -1
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinyHtmlTagRegexBuilder.min.js +1 -0
- package/dist/v1/TinyHttpResponseRegistry.min.js +1 -0
- package/dist/v1/TinyI18.min.js +1 -1
- package/dist/v1/TinyIframeEvents.min.js +1 -1
- package/dist/v1/TinyInventory.min.js +1 -1
- package/dist/v1/TinyInventoryTrader.min.js +1 -1
- package/dist/v1/TinyLevelUp.min.js +1 -1
- package/dist/v1/TinyLoadingScreen.min.js +1 -1
- package/dist/v1/TinyLocalStorage.min.js +1 -1
- package/dist/v1/TinyMaInSys.min.js +1 -1
- package/dist/v1/TinyMapCache.min.js +1 -0
- package/dist/v1/TinyMediaPlayer.min.js +1 -1
- package/dist/v1/TinyNeedBar.min.js +1 -1
- package/dist/v1/TinyNewWinEvents.min.js +1 -1
- package/dist/v1/TinyNotificationAdapter.min.js +1 -0
- package/dist/v1/TinyNotifications.min.js +1 -1
- package/dist/v1/TinyNotifyCenter.min.js +1 -1
- package/dist/v1/TinyOPFSFileSystem.min.js +1 -0
- package/dist/v1/TinyPasswordValidator.min.js +1 -0
- package/dist/v1/TinyPluginPackage.min.js +1 -0
- package/dist/v1/TinyPromiseQueue.min.js +1 -1
- package/dist/v1/TinyPushManager.min.js +1 -0
- package/dist/v1/TinyPushPayload.min.js +1 -0
- package/dist/v1/TinyPushRouter.min.js +1 -0
- package/dist/v1/TinyRadioFm.min.js +1 -1
- package/dist/v1/TinyRateLimiter.min.js +1 -1
- package/dist/v1/TinyRegexEs.min.js +1 -0
- package/dist/v1/TinyRouter.min.js +1 -0
- package/dist/v1/TinyServiceWorker.min.js +1 -0
- package/dist/v1/TinyServiceWorkerEngine.min.js +1 -0
- package/dist/v1/TinySetMapPackage.min.js +1 -0
- package/dist/v1/TinySimpleDice.min.js +1 -1
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyStorageBucketFileSystem.min.js +1 -0
- package/dist/v1/TinyTextDiffer.min.js +1 -1
- package/dist/v1/TinyTextRangeEditor.min.js +1 -1
- package/dist/v1/TinyTextarea.min.js +1 -1
- package/dist/v1/TinyThrottledApi.min.js +1 -0
- package/dist/v1/TinyTimeout.min.js +1 -1
- package/dist/v1/TinyToastNotify.min.js +1 -1
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/TinyUriParser.min.js +1 -0
- package/dist/v1/TinyVersion.min.js +1 -0
- package/dist/v1/TinyWebWorker.min.js +1 -0
- package/dist/v1/TinyWebWorkerEngine.min.js +1 -0
- package/dist/v1/UltraRandomMsgGen.min.js +1 -1
- package/dist/v1/basics/array.cjs +2 -2
- package/dist/v1/basics/array.d.mts +2 -0
- package/dist/v1/basics/array.d.mts.map +1 -1
- package/dist/v1/basics/array.mjs +2 -1
- package/dist/v1/basics/browserDetector.cjs +37 -12
- package/dist/v1/basics/browserDetector.d.mts +8 -0
- package/dist/v1/basics/browserDetector.d.mts.map +1 -1
- package/dist/v1/basics/browserDetector.mjs +32 -13
- package/dist/v1/basics/crypto.cjs +23 -0
- package/dist/v1/basics/crypto.d.mts +10 -0
- package/dist/v1/basics/crypto.d.mts.map +1 -0
- package/dist/v1/basics/crypto.mjs +18 -0
- package/dist/v1/basics/html.cjs +0 -3
- package/dist/v1/basics/html.d.mts.map +1 -1
- package/dist/v1/basics/html.mjs +0 -2
- package/dist/v1/basics/index.cjs +8 -1
- package/dist/v1/basics/index.d.mts +6 -5
- package/dist/v1/basics/index.d.mts.map +1 -1
- package/dist/v1/basics/index.mjs +6 -5
- package/dist/v1/basics/objChecker.cjs +88 -0
- package/dist/v1/basics/objChecker.d.mts +26 -0
- package/dist/v1/basics/objChecker.d.mts.map +1 -1
- package/dist/v1/basics/objChecker.mjs +74 -0
- package/dist/v1/basics/objFilter.cjs +234 -93
- package/dist/v1/basics/objFilter.d.mts +96 -22
- package/dist/v1/basics/objFilter.d.mts.map +1 -1
- package/dist/v1/basics/objFilter.mjs +216 -92
- package/dist/v1/basics/promiseUtils.cjs +48 -12
- package/dist/v1/basics/promiseUtils.d.mts +45 -12
- package/dist/v1/basics/promiseUtils.d.mts.map +1 -1
- package/dist/v1/basics/promiseUtils.mjs +47 -12
- package/dist/v1/basics/text.cjs +0 -12
- package/dist/v1/basics/text.d.mts +0 -10
- package/dist/v1/basics/text.d.mts.map +1 -1
- package/dist/v1/basics/text.mjs +0 -10
- package/dist/v1/index.cjs +88 -3
- package/dist/v1/index.d.mts +31 -6
- package/dist/v1/index.d.mts.map +1 -1
- package/dist/v1/index.mjs +32 -7
- package/dist/v1/jsdoc/EventEmitter.cjs +4 -0
- package/dist/v1/jsdoc/EventEmitter.d.mts +33 -0
- package/dist/v1/jsdoc/EventEmitter.d.mts.map +1 -0
- package/dist/v1/jsdoc/EventEmitter.mjs +18 -0
- package/dist/v1/libs/array/TinyArrayComparator.cjs +240 -25
- package/dist/v1/libs/array/TinyArrayComparator.d.mts +130 -22
- package/dist/v1/libs/array/TinyArrayComparator.d.mts.map +1 -1
- package/dist/v1/libs/array/TinyArrayComparator.mjs +210 -24
- package/dist/v1/libs/fs/constants.cjs +74 -0
- package/dist/v1/libs/fs/constants.d.mts +22 -0
- package/dist/v1/libs/fs/constants.d.mts.map +1 -0
- package/dist/v1/libs/fs/constants.mjs +53 -0
- package/dist/v1/libs/fs/encoding.cjs +118 -0
- package/dist/v1/libs/fs/encoding.d.mts +50 -0
- package/dist/v1/libs/fs/encoding.d.mts.map +1 -0
- package/dist/v1/libs/fs/encoding.mjs +102 -0
- package/dist/v1/libs/fs/error.cjs +188 -0
- package/dist/v1/libs/fs/error.d.mts +105 -0
- package/dist/v1/libs/fs/error.d.mts.map +1 -0
- package/dist/v1/libs/fs/error.mjs +158 -0
- package/dist/v1/libs/fs/handle.cjs +121 -0
- package/dist/v1/libs/fs/handle.d.mts +56 -0
- package/dist/v1/libs/fs/handle.d.mts.map +1 -0
- package/dist/v1/libs/fs/handle.mjs +100 -0
- package/dist/v1/libs/fs/index.cjs +700 -0
- package/dist/v1/libs/fs/index.d.mts +377 -0
- package/dist/v1/libs/fs/index.d.mts.map +1 -0
- package/dist/v1/libs/fs/index.mjs +630 -0
- package/dist/v1/libs/fs/path.cjs +234 -0
- package/dist/v1/libs/fs/path.d.mts +176 -0
- package/dist/v1/libs/fs/path.d.mts.map +1 -0
- package/dist/v1/libs/fs/path.mjs +197 -0
- package/dist/v1/libs/fs/plugins/OPFS/StorageBucket.cjs +202 -0
- package/dist/v1/libs/fs/plugins/OPFS/StorageBucket.d.mts +121 -0
- package/dist/v1/libs/fs/plugins/OPFS/StorageBucket.d.mts.map +1 -0
- package/dist/v1/libs/fs/plugins/OPFS/StorageBucket.mjs +172 -0
- package/dist/v1/libs/fs/plugins/OPFS/index.cjs +334 -0
- package/dist/v1/libs/fs/plugins/OPFS/index.d.mts +98 -0
- package/dist/v1/libs/fs/plugins/OPFS/index.d.mts.map +1 -0
- package/dist/v1/libs/fs/plugins/OPFS/index.mjs +300 -0
- package/dist/v1/libs/fs/stats.cjs +245 -0
- package/dist/v1/libs/fs/stats.d.mts +226 -0
- package/dist/v1/libs/fs/stats.d.mts.map +1 -0
- package/dist/v1/libs/fs/stats.mjs +197 -0
- package/dist/v1/libs/html/events/TinyIframeEvents.cjs +10 -1
- package/dist/v1/libs/html/events/TinyIframeEvents.d.mts +9 -2
- package/dist/v1/libs/html/events/TinyIframeEvents.d.mts.map +1 -1
- package/dist/v1/libs/html/events/TinyIframeEvents.mjs +8 -1
- package/dist/v1/libs/html/events/TinyNewWinEvents.cjs +14 -3
- package/dist/v1/libs/html/events/TinyNewWinEvents.d.mts +21 -5
- package/dist/v1/libs/html/events/TinyNewWinEvents.d.mts.map +1 -1
- package/dist/v1/libs/html/events/TinyNewWinEvents.mjs +12 -3
- package/dist/v1/libs/html/scroll/TinySmartScroller.cjs +13 -1
- package/dist/v1/libs/html/scroll/TinySmartScroller.d.mts +29 -2
- package/dist/v1/libs/html/scroll/TinySmartScroller.d.mts.map +1 -1
- package/dist/v1/libs/html/scroll/TinySmartScroller.mjs +11 -1
- package/dist/v1/libs/math/TinyAdvancedRaffle.cjs +13 -1
- package/dist/v1/libs/math/TinyAdvancedRaffle.d.mts +32 -2
- package/dist/v1/libs/math/TinyAdvancedRaffle.d.mts.map +1 -1
- package/dist/v1/libs/math/TinyAdvancedRaffle.mjs +11 -1
- package/dist/v1/libs/math/TinyTimeout.cjs +0 -14
- package/dist/v1/libs/math/TinyTimeout.d.mts +0 -11
- package/dist/v1/libs/math/TinyTimeout.d.mts.map +1 -1
- package/dist/v1/libs/math/TinyTimeout.mjs +0 -13
- package/dist/v1/libs/media/TinyMediaPlayer/index.cjs +25 -1
- package/dist/v1/libs/media/TinyMediaPlayer/index.d.mts +35 -2
- package/dist/v1/libs/media/TinyMediaPlayer/index.d.mts.map +1 -1
- package/dist/v1/libs/media/TinyMediaPlayer/index.mjs +23 -1
- package/dist/v1/libs/media/TinyMediaPlayer.cjs +2 -2
- package/dist/v1/libs/media/TinyMediaPlayer.d.mts +2 -2
- package/dist/v1/libs/media/TinyMediaPlayer.d.mts.map +1 -1
- package/dist/v1/libs/media/TinyMediaPlayer.mjs +2 -2
- package/dist/v1/libs/media/TinyRadioFm.cjs +19 -1
- package/dist/v1/libs/media/TinyRadioFm.d.mts +78 -2
- package/dist/v1/libs/media/TinyRadioFm.d.mts.map +1 -1
- package/dist/v1/libs/media/TinyRadioFm.mjs +17 -1
- package/dist/v1/libs/plugin/TinyPlugin.cjs +1630 -0
- package/dist/v1/libs/plugin/TinyPlugin.d.mts +753 -0
- package/dist/v1/libs/plugin/TinyPlugin.d.mts.map +1 -0
- package/dist/v1/libs/plugin/TinyPlugin.mjs +1376 -0
- package/dist/v1/libs/plugin/TinyVersion.cjs +204 -0
- package/dist/v1/libs/plugin/TinyVersion.d.mts +70 -0
- package/dist/v1/libs/plugin/TinyVersion.d.mts.map +1 -0
- package/dist/v1/libs/plugin/TinyVersion.mjs +179 -0
- package/dist/v1/libs/router/TinyRouter.cjs +661 -0
- package/dist/v1/libs/router/TinyRouter.d.mts +320 -0
- package/dist/v1/libs/router/TinyRouter.d.mts.map +1 -0
- package/dist/v1/libs/router/TinyRouter.mjs +572 -0
- package/dist/v1/libs/storage/TinyLocalStorage.cjs +20 -1
- package/dist/v1/libs/storage/TinyLocalStorage.d.mts +64 -2
- package/dist/v1/libs/storage/TinyLocalStorage.d.mts.map +1 -1
- package/dist/v1/libs/storage/TinyLocalStorage.mjs +18 -1
- package/dist/v1/libs/storage/TinyMapCache.cjs +373 -0
- package/dist/v1/libs/storage/TinyMapCache.d.mts +274 -0
- package/dist/v1/libs/storage/TinyMapCache.d.mts.map +1 -0
- package/dist/v1/libs/storage/TinyMapCache.mjs +333 -0
- package/dist/v1/libs/storage/TinySetMapDatabase.cjs +1167 -0
- package/dist/v1/libs/storage/TinySetMapDatabase.d.mts +603 -0
- package/dist/v1/libs/storage/TinySetMapDatabase.d.mts.map +1 -0
- package/dist/v1/libs/storage/TinySetMapDatabase.mjs +1059 -0
- package/dist/v1/libs/sw/browser/TinyNotificationAdapter.cjs +126 -0
- package/dist/v1/libs/sw/browser/TinyNotificationAdapter.d.mts +132 -0
- package/dist/v1/libs/sw/browser/TinyNotificationAdapter.d.mts.map +1 -0
- package/dist/v1/libs/sw/browser/TinyNotificationAdapter.mjs +109 -0
- package/dist/v1/libs/sw/browser/TinyPushManager.cjs +310 -0
- package/dist/v1/libs/sw/browser/TinyPushManager.d.mts +168 -0
- package/dist/v1/libs/sw/browser/TinyPushManager.d.mts.map +1 -0
- package/dist/v1/libs/sw/browser/TinyPushManager.mjs +264 -0
- package/dist/v1/libs/sw/browser/TinyServiceWorker.cjs +1060 -0
- package/dist/v1/libs/sw/browser/TinyServiceWorker.d.mts +348 -0
- package/dist/v1/libs/sw/browser/TinyServiceWorker.d.mts.map +1 -0
- package/dist/v1/libs/sw/browser/TinyServiceWorker.mjs +933 -0
- package/dist/v1/libs/sw/browser/plugins/TabManager.cjs +315 -0
- package/dist/v1/libs/sw/browser/plugins/TabManager.d.mts +178 -0
- package/dist/v1/libs/sw/browser/plugins/TabManager.d.mts.map +1 -0
- package/dist/v1/libs/sw/browser/plugins/TabManager.mjs +274 -0
- package/dist/v1/libs/sw/browser/utils.cjs +28 -0
- package/dist/v1/libs/sw/browser/utils.d.mts +8 -0
- package/dist/v1/libs/sw/browser/utils.d.mts.map +1 -0
- package/dist/v1/libs/sw/browser/utils.mjs +21 -0
- package/dist/v1/libs/sw/service/TinyPushRouter.cjs +222 -0
- package/dist/v1/libs/sw/service/TinyPushRouter.d.mts +138 -0
- package/dist/v1/libs/sw/service/TinyPushRouter.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/TinyPushRouter.mjs +201 -0
- package/dist/v1/libs/sw/service/TinyServiceWorkerEngine.cjs +3016 -0
- package/dist/v1/libs/sw/service/TinyServiceWorkerEngine.d.mts +993 -0
- package/dist/v1/libs/sw/service/TinyServiceWorkerEngine.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/TinyServiceWorkerEngine.mjs +2558 -0
- package/dist/v1/libs/sw/service/plugins/GlobBypassPlugin.cjs +88 -0
- package/dist/v1/libs/sw/service/plugins/GlobBypassPlugin.d.mts +32 -0
- package/dist/v1/libs/sw/service/plugins/GlobBypassPlugin.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/plugins/GlobBypassPlugin.mjs +69 -0
- package/dist/v1/libs/sw/service/plugins/GlobCachePlugin.cjs +112 -0
- package/dist/v1/libs/sw/service/plugins/GlobCachePlugin.d.mts +31 -0
- package/dist/v1/libs/sw/service/plugins/GlobCachePlugin.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/plugins/GlobCachePlugin.mjs +91 -0
- package/dist/v1/libs/sw/service/plugins/Ping.cjs +32 -0
- package/dist/v1/libs/sw/service/plugins/Ping.d.mts +9 -0
- package/dist/v1/libs/sw/service/plugins/Ping.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/plugins/Ping.mjs +25 -0
- package/dist/v1/libs/sw/service/plugins/TabManager.cjs +457 -0
- package/dist/v1/libs/sw/service/plugins/TabManager.d.mts +91 -0
- package/dist/v1/libs/sw/service/plugins/TabManager.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/plugins/TabManager.mjs +372 -0
- package/dist/v1/libs/sw/service/plugins/ViteFileDetector.cjs +180 -0
- package/dist/v1/libs/sw/service/plugins/ViteFileDetector.d.mts +28 -0
- package/dist/v1/libs/sw/service/plugins/ViteFileDetector.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/plugins/ViteFileDetector.mjs +148 -0
- package/dist/v1/libs/sw/service/shared/TinyPushPayload.cjs +199 -0
- package/dist/v1/libs/sw/service/shared/TinyPushPayload.d.mts +80 -0
- package/dist/v1/libs/sw/service/shared/TinyPushPayload.d.mts.map +1 -0
- package/dist/v1/libs/sw/service/shared/TinyPushPayload.mjs +174 -0
- package/dist/v1/libs/sw/utils.cjs +57 -0
- package/dist/v1/libs/sw/utils.d.mts +173 -0
- package/dist/v1/libs/sw/utils.d.mts.map +1 -0
- package/dist/v1/libs/sw/utils.mjs +50 -0
- package/dist/v1/libs/text/TinyI18/Browser-NON-DOM.cjs +57 -0
- package/dist/v1/libs/text/TinyI18/Browser-NON-DOM.d.mts +39 -0
- package/dist/v1/libs/text/TinyI18/Browser-NON-DOM.d.mts.map +1 -0
- package/dist/v1/libs/text/TinyI18/Browser-NON-DOM.mjs +48 -0
- package/dist/v1/libs/text/TinyI18/Browser.cjs +64 -0
- package/dist/v1/libs/text/TinyI18/Browser.d.mts +47 -0
- package/dist/v1/libs/text/TinyI18/Browser.d.mts.map +1 -0
- package/dist/v1/libs/text/TinyI18/Browser.mjs +57 -0
- package/dist/v1/libs/text/TinyI18/Node.cjs +49 -0
- package/dist/v1/libs/text/TinyI18/Node.d.mts +38 -0
- package/dist/v1/libs/text/TinyI18/Node.d.mts.map +1 -0
- package/dist/v1/libs/text/TinyI18/Node.mjs +43 -0
- package/dist/v1/libs/text/TinyI18/browser-utils.cjs +17 -0
- package/dist/v1/libs/text/TinyI18/browser-utils.d.mts +8 -0
- package/dist/v1/libs/text/TinyI18/browser-utils.d.mts.map +1 -0
- package/dist/v1/libs/text/TinyI18/browser-utils.mjs +13 -0
- package/dist/v1/libs/text/{TinyI18.cjs → TinyI18/index.cjs} +205 -104
- package/dist/v1/libs/text/{TinyI18.d.mts → TinyI18/index.d.mts} +141 -92
- package/dist/v1/libs/text/TinyI18/index.d.mts.map +1 -0
- package/dist/v1/libs/text/{TinyI18.mjs → TinyI18/index.mjs} +195 -101
- package/dist/v1/libs/tools/TinyBrowserMonitor.cjs +1088 -0
- package/dist/v1/libs/tools/TinyBrowserMonitor.d.mts +621 -0
- package/dist/v1/libs/tools/TinyBrowserMonitor.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyBrowserMonitor.mjs +940 -0
- package/dist/v1/libs/tools/TinyDebugger.cjs +180 -19
- package/dist/v1/libs/tools/TinyDebugger.d.mts +220 -24
- package/dist/v1/libs/tools/TinyDebugger.d.mts.map +1 -1
- package/dist/v1/libs/tools/TinyDebugger.mjs +161 -19
- package/dist/v1/libs/tools/TinyHtmlTagRegexBuilder.cjs +256 -0
- package/dist/v1/libs/tools/TinyHtmlTagRegexBuilder.d.mts +125 -0
- package/dist/v1/libs/tools/TinyHtmlTagRegexBuilder.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHtmlTagRegexBuilder.mjs +223 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser-NON-DOM.cjs +23 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser-NON-DOM.d.mts +17 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser-NON-DOM.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser-NON-DOM.mjs +19 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser.cjs +23 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser.d.mts +17 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Browser.mjs +19 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/EmptyRequestCodes.cjs +390 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/EmptyRequestCodes.d.mts +9 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/EmptyRequestCodes.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/EmptyRequestCodes.mjs +387 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/JsDoc.cjs +2 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/JsDoc.d.mts +27 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/JsDoc.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/JsDoc.mjs +12 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/LICENSE +53 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/index.cjs +405 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/index.d.mts +34 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/index.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/MozillaRequestCodes/index.mjs +342 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Node.cjs +23 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Node.d.mts +17 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Node.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/Node.mjs +19 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/RequestCodes.cjs +327 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/RequestCodes.d.mts +9 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/RequestCodes.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/RequestCodes.mjs +324 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/index.cjs +268 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/index.d.mts +107 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/index.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyHttpResponseRegistry/index.mjs +238 -0
- package/dist/v1/libs/tools/TinyPasswordValidator.cjs +491 -0
- package/dist/v1/libs/tools/TinyPasswordValidator.d.mts +246 -0
- package/dist/v1/libs/tools/TinyPasswordValidator.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyPasswordValidator.mjs +434 -0
- package/dist/v1/libs/tools/TinyPkgExportValidator.cjs +48 -0
- package/dist/v1/libs/tools/TinyPkgExportValidator.d.mts +14 -0
- package/dist/v1/libs/tools/TinyPkgExportValidator.d.mts.map +1 -1
- package/dist/v1/libs/tools/TinyPkgExportValidator.mjs +44 -0
- package/dist/v1/libs/tools/TinySiteMap.cjs +1029 -0
- package/dist/v1/libs/tools/TinySiteMap.d.mts +429 -0
- package/dist/v1/libs/tools/TinySiteMap.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinySiteMap.mjs +910 -0
- package/dist/v1/libs/tools/TinySiteMapStream.cjs +121 -0
- package/dist/v1/libs/tools/TinySiteMapStream.d.mts +51 -0
- package/dist/v1/libs/tools/TinySiteMapStream.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinySiteMapStream.mjs +85 -0
- package/dist/v1/libs/tools/TinyURLSecurityVerifier.cjs +444 -0
- package/dist/v1/libs/tools/TinyURLSecurityVerifier.d.mts +217 -0
- package/dist/v1/libs/tools/TinyURLSecurityVerifier.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyURLSecurityVerifier.mjs +394 -0
- package/dist/v1/libs/tools/TinyUriParser/BlueSky.cjs +613 -0
- package/dist/v1/libs/tools/TinyUriParser/BlueSky.d.mts +152 -0
- package/dist/v1/libs/tools/TinyUriParser/BlueSky.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyUriParser/BlueSky.mjs +527 -0
- package/dist/v1/libs/tools/TinyUriParser/Discord.cjs +1119 -0
- package/dist/v1/libs/tools/TinyUriParser/Discord.d.mts +306 -0
- package/dist/v1/libs/tools/TinyUriParser/Discord.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyUriParser/Discord.mjs +968 -0
- package/dist/v1/libs/tools/TinyUriParser/MatrixProtocol.cjs +469 -0
- package/dist/v1/libs/tools/TinyUriParser/MatrixProtocol.d.mts +80 -0
- package/dist/v1/libs/tools/TinyUriParser/MatrixProtocol.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyUriParser/MatrixProtocol.mjs +379 -0
- package/dist/v1/libs/tools/TinyUriParser.cjs +217 -0
- package/dist/v1/libs/tools/TinyUriParser.d.mts +109 -0
- package/dist/v1/libs/tools/TinyUriParser.d.mts.map +1 -0
- package/dist/v1/libs/tools/TinyUriParser.mjs +183 -0
- package/dist/v1/libs/utils/TinyCloner.cjs +466 -0
- package/dist/v1/libs/utils/TinyCloner.d.mts +221 -0
- package/dist/v1/libs/utils/TinyCloner.d.mts.map +1 -0
- package/dist/v1/libs/utils/TinyCloner.mjs +416 -0
- package/dist/v1/libs/utils/TinyPromiseQueue.cjs +1 -1
- package/dist/v1/libs/utils/TinyPromiseQueue.d.mts +2 -2
- package/dist/v1/libs/utils/TinyPromiseQueue.d.mts.map +1 -1
- package/dist/v1/libs/utils/TinyPromiseQueue.mjs +1 -1
- package/dist/v1/libs/utils/TinyThrottledApi.cjs +333 -0
- package/dist/v1/libs/utils/TinyThrottledApi.d.mts +163 -0
- package/dist/v1/libs/utils/TinyThrottledApi.d.mts.map +1 -0
- package/dist/v1/libs/utils/TinyThrottledApi.mjs +294 -0
- package/dist/v1/libs/worker/browser/TinyWebWorker.cjs +342 -0
- package/dist/v1/libs/worker/browser/TinyWebWorker.d.mts +97 -0
- package/dist/v1/libs/worker/browser/TinyWebWorker.d.mts.map +1 -0
- package/dist/v1/libs/worker/browser/TinyWebWorker.mjs +305 -0
- package/dist/v1/libs/worker/engine/TinyWebWorkerEngine.cjs +346 -0
- package/dist/v1/libs/worker/engine/TinyWebWorkerEngine.d.mts +127 -0
- package/dist/v1/libs/worker/engine/TinyWebWorkerEngine.d.mts.map +1 -0
- package/dist/v1/libs/worker/engine/TinyWebWorkerEngine.mjs +304 -0
- package/dist/v1/regexp/Email.cjs +185 -0
- package/dist/v1/regexp/Email.d.mts +73 -0
- package/dist/v1/regexp/Email.d.mts.map +1 -0
- package/dist/v1/regexp/Email.mjs +153 -0
- package/dist/v1/regexp/Glob.cjs +293 -0
- package/dist/v1/regexp/Glob.d.mts +45 -0
- package/dist/v1/regexp/Glob.d.mts.map +1 -0
- package/dist/v1/regexp/Glob.mjs +260 -0
- package/dist/v1/regexp/Ipv4.cjs +57 -0
- package/dist/v1/regexp/Ipv4.d.mts +29 -0
- package/dist/v1/regexp/Ipv4.d.mts.map +1 -0
- package/dist/v1/regexp/Ipv4.mjs +45 -0
- package/dist/v1/regexp/Ipv6.cjs +67 -0
- package/dist/v1/regexp/Ipv6.d.mts +29 -0
- package/dist/v1/regexp/Ipv6.d.mts.map +1 -0
- package/dist/v1/regexp/Ipv6.mjs +54 -0
- package/dist/v1/regexp/SegmentExtractor.cjs +145 -0
- package/dist/v1/regexp/SegmentExtractor.d.mts +91 -0
- package/dist/v1/regexp/SegmentExtractor.d.mts.map +1 -0
- package/dist/v1/regexp/SegmentExtractor.mjs +116 -0
- package/dist/v1/regexp/UrlDetector.cjs +125 -0
- package/dist/v1/regexp/UrlDetector.d.mts +67 -0
- package/dist/v1/regexp/UrlDetector.d.mts.map +1 -0
- package/dist/v1/regexp/UrlDetector.mjs +102 -0
- package/dist/v1/regexp/Username/index.cjs +233 -0
- package/dist/v1/regexp/Username/index.d.mts +77 -0
- package/dist/v1/regexp/Username/index.d.mts.map +1 -0
- package/dist/v1/regexp/Username/index.mjs +199 -0
- package/dist/v1/regexp/Username/jsDoc.cjs +2 -0
- package/dist/v1/regexp/Username/jsDoc.d.mts +57 -0
- package/dist/v1/regexp/Username/jsDoc.d.mts.map +1 -0
- package/dist/v1/regexp/Username/jsDoc.mjs +18 -0
- package/dist/v1/regexp/Username/templates/BlueSky.cjs +56 -0
- package/dist/v1/regexp/Username/templates/BlueSky.d.mts +35 -0
- package/dist/v1/regexp/Username/templates/BlueSky.d.mts.map +1 -0
- package/dist/v1/regexp/Username/templates/BlueSky.mjs +52 -0
- package/dist/v1/regexp/Username/templates/Discord.cjs +505 -0
- package/dist/v1/regexp/Username/templates/Discord.d.mts +209 -0
- package/dist/v1/regexp/Username/templates/Discord.d.mts.map +1 -0
- package/dist/v1/regexp/Username/templates/Discord.mjs +458 -0
- package/dist/v1/regexp/Username/templates/MatrixProtocol.cjs +143 -0
- package/dist/v1/regexp/Username/templates/MatrixProtocol.d.mts +70 -0
- package/dist/v1/regexp/Username/templates/MatrixProtocol.d.mts.map +1 -0
- package/dist/v1/regexp/Username/templates/MatrixProtocol.mjs +128 -0
- package/dist/v1/regexp/Username/templates/deprecated/Discord.cjs +24 -0
- package/dist/v1/regexp/Username/templates/deprecated/Discord.d.mts +17 -0
- package/dist/v1/regexp/Username/templates/deprecated/Discord.d.mts.map +1 -0
- package/dist/v1/regexp/Username/templates/deprecated/Discord.mjs +20 -0
- package/dist/v1/regexp/Username/templates/index.cjs +11 -0
- package/dist/v1/regexp/Username/templates/index.d.mts +5 -0
- package/dist/v1/regexp/Username/templates/index.d.mts.map +1 -0
- package/dist/v1/regexp/Username/templates/index.mjs +4 -0
- package/dist/v1/regexp/index.cjs +41 -0
- package/dist/v1/regexp/index.d.mts +9 -0
- package/dist/v1/regexp/index.d.mts.map +1 -0
- package/dist/v1/regexp/index.mjs +8 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Browser.cjs +64 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Browser.d.mts +11 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Browser.d.mts.map +1 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Browser.mjs +51 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/FileInput.cjs +66 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/FileInput.d.mts +11 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/FileInput.d.mts.map +1 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/FileInput.mjs +51 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Node.cjs +39 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Node.d.mts +11 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Node.d.mts.map +1 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Node.mjs +28 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Template.cjs +494 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Template.d.mts +142 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Template.d.mts.map +1 -0
- package/dist/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters/Template.mjs +445 -0
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.cjs +30 -4
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.d.mts +5 -2
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.d.mts.map +1 -1
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.mjs +29 -5
- package/dist/v1/webTemplates/media/MediaValidator/v1/Browser/index.cjs +135 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Browser/index.d.mts +83 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Browser/index.d.mts.map +1 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Browser/index.mjs +120 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Node/index.cjs +127 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Node/index.d.mts +95 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Node/index.d.mts.map +1 -0
- package/dist/v1/webTemplates/media/MediaValidator/v1/Node/index.mjs +109 -0
- package/dist/v1/webTemplates/multiformats/14.0/IPFSHasher/index.cjs +83 -0
- package/dist/v1/webTemplates/multiformats/14.0/IPFSHasher/index.d.mts +46 -0
- package/dist/v1/webTemplates/multiformats/14.0/IPFSHasher/index.d.mts.map +1 -0
- package/dist/v1/webTemplates/multiformats/14.0/IPFSHasher/index.mjs +71 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.cjs +493 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.d.mts +67 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.d.mts.map +1 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.mjs +399 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/githubUtils.cjs +35 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/githubUtils.d.mts +6 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/githubUtils.d.mts.map +1 -0
- package/dist/v1/webTemplates/vite/7.3/plugins/githubUtils.mjs +29 -0
- package/docs/info/RegExp.md +74 -0
- package/docs/v1/Exports.md +101 -0
- package/docs/v1/README.md +113 -15
- package/docs/v1/basics/asyncReplace.md +2 -0
- package/docs/v1/basics/browserDetector.md +28 -11
- package/docs/v1/basics/crypto.md +85 -0
- package/docs/v1/basics/deprecated/html.md +2 -0
- package/docs/v1/basics/deprecated/objFilter.md +2 -0
- package/docs/v1/basics/html.md +2 -0
- package/docs/v1/basics/objChecker.md +55 -0
- package/docs/v1/basics/objFilter.md +57 -86
- package/docs/v1/basics/promiseUtils.md +12 -3
- package/docs/v1/basics/text.md +0 -1
- package/docs/v1/libs/array/TinyArrayComparator.md +50 -39
- package/docs/v1/libs/fs/TinyFS.md +752 -0
- package/docs/v1/libs/fs/TinyOPFSFileSystem.md +495 -0
- package/docs/v1/libs/fs/TinyStorageBucketFileSystem.md +407 -0
- package/docs/v1/libs/plugin/TinyPlugin.md +441 -0
- package/docs/v1/libs/plugin/TinyVersion.md +145 -0
- package/docs/v1/libs/router/TinyRouter.md +216 -0
- package/docs/v1/libs/storage/TinyMapCache.md +219 -0
- package/docs/v1/libs/storage/TinySetMapDatabase.md +478 -0
- package/docs/v1/libs/sw/browser/TinyNotificationAdapter.md +280 -0
- package/docs/v1/libs/sw/browser/TinyPushManager.md +782 -0
- package/docs/v1/libs/sw/browser/TinyServiceWorker.md +365 -0
- package/docs/v1/libs/sw/browser/plugins/TabManager.md +133 -0
- package/docs/v1/libs/sw/service/TinyPushRouter.md +314 -0
- package/docs/v1/libs/sw/service/TinyServiceWorkerEngine.md +748 -0
- package/docs/v1/libs/sw/service/plugins/GlobBypassPlugin.md +229 -0
- package/docs/v1/libs/sw/service/plugins/GlobCachePlugin.md +91 -0
- package/docs/v1/libs/sw/service/plugins/Ping.md +36 -0
- package/docs/v1/libs/sw/service/plugins/TabManager.md +64 -0
- package/docs/v1/libs/sw/service/plugins/ViteFileDetector.md +92 -0
- package/docs/v1/libs/sw/service/shared/TinyPushPayload.md +316 -0
- package/docs/v1/libs/text/TinyI18.md +80 -56
- package/docs/v1/libs/tools/TinyBrowserMonitor.md +170 -0
- package/docs/v1/libs/tools/TinyDebugger.md +117 -1
- package/docs/v1/libs/tools/TinyHtmlTagRegexBuilder.md +141 -0
- package/docs/v1/libs/tools/TinyHttpResponseRegistry.md +129 -0
- package/docs/v1/libs/tools/TinyPasswordValidator.md +153 -0
- package/docs/v1/libs/tools/TinyPkgExportValidator.md +45 -1
- package/docs/v1/libs/tools/TinySiteMap.md +134 -0
- package/docs/v1/libs/tools/TinySiteMapStream.md +97 -0
- package/docs/v1/libs/tools/TinyURLSecurityVerifier.md +146 -0
- package/docs/v1/libs/tools/TinyUriParser/Discord.md +374 -0
- package/docs/v1/libs/tools/TinyUriParser/MatrixProtocol.md +54 -0
- package/docs/v1/libs/tools/TinyUriParser.md +128 -0
- package/docs/v1/libs/utils/TinyCloner.md +126 -0
- package/docs/v1/libs/utils/TinyPromiseQueue.md +1 -1
- package/docs/v1/libs/utils/TinyThrottledApi.md +219 -0
- package/docs/v1/libs/worker/browser/TinyWebWorker.md +331 -0
- package/docs/v1/libs/worker/engine/TinyWebWorkerEngine.md +137 -0
- package/docs/v1/regexp/Email.md +127 -0
- package/docs/v1/regexp/Glob.md +155 -0
- package/docs/v1/regexp/IPv4.md +103 -0
- package/docs/v1/regexp/IPv6.md +122 -0
- package/docs/v1/regexp/SegmentExtractor.md +120 -0
- package/docs/v1/regexp/UrlDetector.md +117 -0
- package/docs/v1/regexp/Username/Base.md +131 -0
- package/docs/v1/regexp/Username/Discord.md +267 -0
- package/docs/v1/regexp/Username/MatrixProtocol.md +131 -0
- package/docs/v1/webTemplates/ag-psd/31.0/ProcessSolidFilters.md +569 -0
- package/docs/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.md +19 -7
- package/docs/v1/webTemplates/media/MediaValidator/v1/Browser.md +123 -0
- package/docs/v1/webTemplates/media/MediaValidator/v1/Node.md +136 -0
- package/docs/v1/webTemplates/multiformats/14.0/IPFSHasher.md +310 -0
- package/docs/v1/webTemplates/vite/7.3/plugins/TinyVitePwaPlugin.md +131 -0
- package/docs/v1/webTemplates/vite/7.3/plugins/githubUtils.md +50 -0
- package/package.json +303 -13
- package/types/EventEmitter.d.ts +48 -0
- package/dist/v1/libs/text/TinyI18.d.mts.map +0 -1
|
@@ -0,0 +1,572 @@
|
|
|
1
|
+
import * as SegmentExtractor from '../../regexp/SegmentExtractor.mjs';
|
|
2
|
+
import TinyDebugger from '../tools/TinyDebugger.mjs';
|
|
3
|
+
import TinyPromiseQueue from '../utils/TinyPromiseQueue.mjs';
|
|
4
|
+
import { createCheckDestroyed } from '../utils/tools.mjs';
|
|
5
|
+
const checkDestroy = createCheckDestroyed('TinyRouter');
|
|
6
|
+
const { makeSegmentExtractor, segmentExtractorV1 } = SegmentExtractor;
|
|
7
|
+
/**
|
|
8
|
+
* Represents a single entry in the navigation history.
|
|
9
|
+
* @typedef {Object} RouterHistoryEntry
|
|
10
|
+
* @property {string} path - The URL path recorded in history.
|
|
11
|
+
* @property {number} timestamp - The Unix timestamp when this path was visited.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Additional metadata stored alongside segment extraction results.
|
|
15
|
+
* @typedef {Object} SegExResultExtra
|
|
16
|
+
* @property {string} [pattern] - Stored to allow removal by string.
|
|
17
|
+
*/
|
|
18
|
+
/**
|
|
19
|
+
* Configuration for registering a route using a function to generate the pattern.
|
|
20
|
+
* @typedef {Object} AddRouteOptionsWithFunction
|
|
21
|
+
* @property {import('../../regexp/SegmentExtractor.mjs').SegExFunction} callback - A function used to process the pattern.
|
|
22
|
+
* @property {string} pattern - Stored to allow removal by string.
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* The result of a segment extraction combined with additional metadata.
|
|
26
|
+
* @typedef {import('../../regexp/SegmentExtractor.mjs').SegExResult & SegExResultExtra} SegExResult
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Configuration for registering a route using a custom segment extraction pattern.
|
|
30
|
+
* @typedef {Object} AddRouteOptions
|
|
31
|
+
* @property {string} pattern - Stored to allow removal by string.
|
|
32
|
+
* @property {string|RegExp} searchValue - The search pattern (string or RegExp) used to identify dynamic segments.
|
|
33
|
+
* @property {import('../../regexp/SegmentExtractor.mjs').SegExReplacer} replaceValue - The function defining how to transform a segment into a capture group.
|
|
34
|
+
* @property {import('../../regexp/SegmentExtractor.mjs').SegExErrorConfig} errorConfig - Optional configuration to customize error messages.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* Data structure containing the results of a successful route match.
|
|
38
|
+
* @typedef {Object} RouteMatch
|
|
39
|
+
* @property {string} path - The matched URL path.
|
|
40
|
+
* @property {Record<string, string>} params - The dynamic parameters extracted from the path.
|
|
41
|
+
* @property {URLSearchParams} query - The URL search parameters.
|
|
42
|
+
*/
|
|
43
|
+
/**
|
|
44
|
+
* Data structure containing details when no route matches the current URL.
|
|
45
|
+
* @typedef {Object} RouteNotFoundData
|
|
46
|
+
* @property {string} path - The path that failed to match.
|
|
47
|
+
* @property {URLSearchParams} query - The URL search parameters.
|
|
48
|
+
*/
|
|
49
|
+
/**
|
|
50
|
+
* A function executed when a route is successfully matched.
|
|
51
|
+
* @callback RouteCallback
|
|
52
|
+
* @param {RouteMatch} match - The object containing path, params, and query.
|
|
53
|
+
* @returns {Promise<void>|void} - A promise or void indicating completion.
|
|
54
|
+
*/
|
|
55
|
+
/**
|
|
56
|
+
* A function executed when no route matches the current URL.
|
|
57
|
+
* @callback RouteNotFoundCallback
|
|
58
|
+
* @param {RouteNotFoundData} match - The object containing path and query.
|
|
59
|
+
* @returns {void}
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* Configuration options for initializing the TinyRouter instance.
|
|
63
|
+
* @typedef {Object} RouterOptions
|
|
64
|
+
* @property {boolean} [debugMode=false] - Whether to enable internal debug logging.
|
|
65
|
+
* @property {boolean} [useLogColors=false] - Whether to enable log color support.
|
|
66
|
+
* @property {boolean} [detectHistoryChange=true] - Whether to detect if the history navigation actually changed the URL.
|
|
67
|
+
* @property {Partial<Console>} [logger=console] - A custom logger object (must implement console methods).
|
|
68
|
+
* @property {RouteCallback} [onRouteChanged] - Callback executed whenever the route changes.
|
|
69
|
+
* @property {RouteNotFoundCallback} [onRouteNotFound] - Callback executed when no route matches.
|
|
70
|
+
* @property {number} [historyLimit=0] - Maximum number of history entries. Use -1 for unlimited, or 0 to disable history.
|
|
71
|
+
*/
|
|
72
|
+
/**
|
|
73
|
+
* A definition of a route, combining its pattern extractor and its execution callback.
|
|
74
|
+
* @typedef {Object} RouteDefinition
|
|
75
|
+
* @property {SegExResult} segmentExtractor - The extraction logic and metadata used to match the path and retrieve parameters.
|
|
76
|
+
* @property {RouteCallback} callback - The function to execute on match.
|
|
77
|
+
*/
|
|
78
|
+
/**
|
|
79
|
+
* A lightweight, framework-agnostic router for managing client-side navigation.
|
|
80
|
+
*/
|
|
81
|
+
class TinyRouter extends TinyDebugger {
|
|
82
|
+
/** The SegmentExtractor module. */
|
|
83
|
+
static SegmentExtractor = SegmentExtractor;
|
|
84
|
+
/** @type {RouteDefinition[]} The collection of registered routes. */
|
|
85
|
+
#routes = [];
|
|
86
|
+
/** @type {RouteCallback} The callback function triggered on route changes. */
|
|
87
|
+
#onRouteChanged;
|
|
88
|
+
/** @type {RouteNotFoundCallback} The callback function triggered when no route matches. */
|
|
89
|
+
#onRouteNotFound;
|
|
90
|
+
/** @type {boolean} Indicates whether the router has been started. */
|
|
91
|
+
#started = false;
|
|
92
|
+
/** @type {EventListenerOrEventListenerObject} The event handler for the popstate event. */
|
|
93
|
+
#popstateHandler;
|
|
94
|
+
/** @type {boolean} Flag to determine if history navigation changes should be detected. */
|
|
95
|
+
#detectHistoryChange;
|
|
96
|
+
/** @type {RouterHistoryEntry[]} The internal record of visited paths. */
|
|
97
|
+
#history = [];
|
|
98
|
+
/** @type {number} Maximum number of entries to keep in history. */
|
|
99
|
+
#historyLimit;
|
|
100
|
+
/** @type {number} Current position index in the internal history. */
|
|
101
|
+
#historyIndex = -1;
|
|
102
|
+
/** @type {TinyPromiseQueue} A promise queue used to handle asynchronous routing operations sequentially. */
|
|
103
|
+
#queue = new TinyPromiseQueue();
|
|
104
|
+
/** @type {boolean} A flag indicating if the router instance has been destroyed. */
|
|
105
|
+
#isDestroyed = false;
|
|
106
|
+
/**
|
|
107
|
+
* @param {RouterOptions} [options={}] - Configuration options for the router.
|
|
108
|
+
* @throws {TypeError} If options is not an object or if the logger lacks required methods.
|
|
109
|
+
*/
|
|
110
|
+
constructor(options = {}) {
|
|
111
|
+
if (typeof options !== 'object' || options === null) {
|
|
112
|
+
throw new TypeError('Options must be a non-null object.');
|
|
113
|
+
}
|
|
114
|
+
if (typeof options.detectHistoryChange !== 'undefined' &&
|
|
115
|
+
typeof options.detectHistoryChange !== 'boolean')
|
|
116
|
+
throw new TypeError('detectHistoryChange must be a boolean.');
|
|
117
|
+
if (typeof options.onRouteChanged !== 'undefined' &&
|
|
118
|
+
typeof options.onRouteChanged !== 'function')
|
|
119
|
+
throw new TypeError('onRouteChanged must be a function.');
|
|
120
|
+
if (typeof options.onRouteNotFound !== 'undefined' &&
|
|
121
|
+
typeof options.onRouteNotFound !== 'function')
|
|
122
|
+
throw new TypeError('onRouteNotFound must be a function.');
|
|
123
|
+
if (typeof options.historyLimit !== 'undefined' &&
|
|
124
|
+
(!Number.isInteger(options.historyLimit) || options.historyLimit < -1))
|
|
125
|
+
throw new TypeError('historyLimit must be an integer and greater than or equal to -1.');
|
|
126
|
+
super({
|
|
127
|
+
id: '[_main_class_TinyRouter_reset_]',
|
|
128
|
+
logger: options.logger ?? console,
|
|
129
|
+
debugMode: options.debugMode ?? false,
|
|
130
|
+
useLogColors: options.useLogColors ?? false,
|
|
131
|
+
});
|
|
132
|
+
this.#onRouteChanged = options.onRouteChanged || (() => { });
|
|
133
|
+
this.#onRouteNotFound = options.onRouteNotFound || (() => { });
|
|
134
|
+
this.#detectHistoryChange = options.detectHistoryChange ?? true;
|
|
135
|
+
this.#historyIndex = -1;
|
|
136
|
+
// Initialize history limit and handle the "0" (disabled) case
|
|
137
|
+
this.#historyLimit = options.historyLimit ?? 0;
|
|
138
|
+
this.#popstateHandler = this.#resolve.bind(this);
|
|
139
|
+
}
|
|
140
|
+
/** @returns {boolean} Returns whether the router instance has been destroyed. */
|
|
141
|
+
get isDestroyed() {
|
|
142
|
+
return this.#isDestroyed;
|
|
143
|
+
}
|
|
144
|
+
/** @returns {number} Returns the current position in history. */
|
|
145
|
+
get historyIndex() {
|
|
146
|
+
checkDestroy(this.#isDestroyed);
|
|
147
|
+
return this.#historyIndex;
|
|
148
|
+
}
|
|
149
|
+
/** @returns {number} Returns the maximum number of history entries allowed. */
|
|
150
|
+
get historyLimit() {
|
|
151
|
+
checkDestroy(this.#isDestroyed);
|
|
152
|
+
return this.#historyLimit;
|
|
153
|
+
}
|
|
154
|
+
/** @returns {boolean} Returns whether the router detects changes in history navigation. */
|
|
155
|
+
get detectHistoryChange() {
|
|
156
|
+
checkDestroy(this.#isDestroyed);
|
|
157
|
+
return this.#detectHistoryChange;
|
|
158
|
+
}
|
|
159
|
+
/** @param {boolean} value Sets whether the router detects changes in history navigation. */
|
|
160
|
+
set detectHistoryChange(value) {
|
|
161
|
+
checkDestroy(this.#isDestroyed);
|
|
162
|
+
if (typeof value !== 'boolean')
|
|
163
|
+
throw new TypeError('detectHistoryChange must be a boolean.');
|
|
164
|
+
this.#detectHistoryChange = value;
|
|
165
|
+
}
|
|
166
|
+
/** @returns {RouteCallback} Returns the callback function for route changes. */
|
|
167
|
+
get onRouteChanged() {
|
|
168
|
+
checkDestroy(this.#isDestroyed);
|
|
169
|
+
return this.#onRouteChanged;
|
|
170
|
+
}
|
|
171
|
+
/** @param {RouteCallback} value Sets the callback function for route changes. */
|
|
172
|
+
set onRouteChanged(value) {
|
|
173
|
+
checkDestroy(this.#isDestroyed);
|
|
174
|
+
if (typeof value !== 'function')
|
|
175
|
+
throw new TypeError('onRouteChanged must be a function.');
|
|
176
|
+
this.#onRouteChanged = value;
|
|
177
|
+
}
|
|
178
|
+
/** @returns {RouteNotFoundCallback} Returns the callback function for unmatched routes. */
|
|
179
|
+
get onRouteNotFound() {
|
|
180
|
+
checkDestroy(this.#isDestroyed);
|
|
181
|
+
return this.#onRouteNotFound;
|
|
182
|
+
}
|
|
183
|
+
/** @param {RouteNotFoundCallback} value Sets the callback function for unmatched routes. */
|
|
184
|
+
set onRouteNotFound(value) {
|
|
185
|
+
checkDestroy(this.#isDestroyed);
|
|
186
|
+
if (typeof value !== 'function')
|
|
187
|
+
throw new TypeError('onRouteNotFound must be a function.');
|
|
188
|
+
this.#onRouteNotFound = value;
|
|
189
|
+
}
|
|
190
|
+
/** @returns {boolean} Returns whether the router is currently active. */
|
|
191
|
+
get started() {
|
|
192
|
+
checkDestroy(this.#isDestroyed);
|
|
193
|
+
return this.#started;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Returns the current number of registered routes.
|
|
197
|
+
* @returns {number}
|
|
198
|
+
*/
|
|
199
|
+
get size() {
|
|
200
|
+
checkDestroy(this.#isDestroyed);
|
|
201
|
+
return this.#routes.length;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Returns an array of all registered path patterns.
|
|
205
|
+
* @returns {string[]} An array of path pattern strings.
|
|
206
|
+
*/
|
|
207
|
+
get routes() {
|
|
208
|
+
checkDestroy(this.#isDestroyed);
|
|
209
|
+
return this.#routes.map((route) => route.segmentExtractor.pattern ?? '');
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Returns a copy of the current navigation history.
|
|
213
|
+
* @returns {RouterHistoryEntry[]} An array of history entries.
|
|
214
|
+
*/
|
|
215
|
+
get history() {
|
|
216
|
+
checkDestroy(this.#isDestroyed);
|
|
217
|
+
return this.#history.map((i) => ({ ...i }));
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Imports and validates a history log to restore previous navigation state.
|
|
221
|
+
* @param {RouterHistoryEntry[]} historyData - The array of history entries to import.
|
|
222
|
+
* @throws {TypeError} If historyData is not an array or if any entry is invalid.
|
|
223
|
+
*/
|
|
224
|
+
set history(historyData) {
|
|
225
|
+
checkDestroy(this.#isDestroyed);
|
|
226
|
+
if (!Array.isArray(historyData)) {
|
|
227
|
+
throw new TypeError('History data must be an array.');
|
|
228
|
+
}
|
|
229
|
+
// Deep validation of every entry
|
|
230
|
+
for (const entry of historyData) {
|
|
231
|
+
if (typeof entry !== 'object' || entry === null) {
|
|
232
|
+
throw new TypeError('Each history entry must be an object.');
|
|
233
|
+
}
|
|
234
|
+
if (typeof entry.path !== 'string') {
|
|
235
|
+
throw new TypeError('Each history entry must have a string "path" property.');
|
|
236
|
+
}
|
|
237
|
+
if (typeof entry.timestamp !== 'number') {
|
|
238
|
+
throw new TypeError('Each history entry must have a number "timestamp" property.');
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
this.#history = historyData.map((i) => ({ ...i }));
|
|
242
|
+
this.log('info', 'History has been successfully imported.');
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Registers a new route pattern.
|
|
246
|
+
* @param {string | AddRouteOptions | AddRouteOptionsWithFunction} patternOrOptions -
|
|
247
|
+
* A path pattern string (e.g., '/user/:id') OR a configuration object for custom regex.
|
|
248
|
+
* @param {RouteCallback} callback - Function to execute when this route is matched.
|
|
249
|
+
* @throws {TypeError} If arguments are invalid.
|
|
250
|
+
* @throws {Error} If the route pattern is already registered.
|
|
251
|
+
*/
|
|
252
|
+
add(patternOrOptions, callback) {
|
|
253
|
+
checkDestroy(this.#isDestroyed);
|
|
254
|
+
/** @type {SegExResult} */
|
|
255
|
+
// @ts-ignore
|
|
256
|
+
let se = {};
|
|
257
|
+
// 1. Handle String Input (Legacy/Simple Mode)
|
|
258
|
+
if (typeof patternOrOptions === 'string') {
|
|
259
|
+
se = segmentExtractorV1(patternOrOptions);
|
|
260
|
+
se.pattern = patternOrOptions;
|
|
261
|
+
// 2. Handle Object Input (Advanced/Custom Regex Mode)
|
|
262
|
+
}
|
|
263
|
+
else if (typeof patternOrOptions === 'object' && patternOrOptions !== null) {
|
|
264
|
+
// @ts-ignore
|
|
265
|
+
if (typeof patternOrOptions.callback === 'function') {
|
|
266
|
+
/** @type {AddRouteOptionsWithFunction} */
|
|
267
|
+
// @ts-ignore
|
|
268
|
+
const options = patternOrOptions;
|
|
269
|
+
options.callback(options.pattern);
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
/** @type {AddRouteOptions} */
|
|
273
|
+
// @ts-ignore
|
|
274
|
+
const options = patternOrOptions;
|
|
275
|
+
se = makeSegmentExtractor(options.searchValue, options.replaceValue, options.errorConfig)(options.pattern);
|
|
276
|
+
}
|
|
277
|
+
se.pattern = patternOrOptions.pattern;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
throw new TypeError('The first argument must be a string (e.g., "/user/:id") or an object of SegmentExtractor maker.');
|
|
281
|
+
}
|
|
282
|
+
// 3. Callback Validation
|
|
283
|
+
if (typeof callback !== 'function') {
|
|
284
|
+
throw new TypeError('The callback must be a function.');
|
|
285
|
+
}
|
|
286
|
+
// 4. Prevent duplicate route registration
|
|
287
|
+
if (this.has(se.pattern)) {
|
|
288
|
+
throw new Error(`Route with pattern "${se.pattern}" is already registered.`);
|
|
289
|
+
}
|
|
290
|
+
// 5. Final Registration
|
|
291
|
+
this.#routes.push({ segmentExtractor: se, callback });
|
|
292
|
+
this.emit('RouteAdded', se.pattern);
|
|
293
|
+
this.log('info', `New route registered: ${se.pattern}`);
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Removes a registered route by its original pattern string.
|
|
297
|
+
* @param {string} pathPattern - The pattern to remove.
|
|
298
|
+
* @throws {TypeError} If pathPattern is not a string.
|
|
299
|
+
*/
|
|
300
|
+
remove(pathPattern) {
|
|
301
|
+
checkDestroy(this.#isDestroyed);
|
|
302
|
+
if (typeof pathPattern !== 'string')
|
|
303
|
+
throw new TypeError('pathPattern must be a string.');
|
|
304
|
+
const initialLength = this.#routes.length;
|
|
305
|
+
this.#routes = this.#routes.filter((route) => route.segmentExtractor.pattern !== pathPattern);
|
|
306
|
+
if (this.#routes.length === initialLength) {
|
|
307
|
+
this.log('warn', `Attempted to remove non-existent route: ${pathPattern}`);
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
this.emit('RouteRemoved', pathPattern);
|
|
311
|
+
this.log('info', `Route removed: ${pathPattern}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Checks if a route pattern is already registered.
|
|
316
|
+
* @param {string} pathPattern - The pattern to check.
|
|
317
|
+
* @returns {boolean} True if the route exists, false otherwise.
|
|
318
|
+
* @throws {TypeError} If pathPattern is not a string.
|
|
319
|
+
*/
|
|
320
|
+
has(pathPattern) {
|
|
321
|
+
checkDestroy(this.#isDestroyed);
|
|
322
|
+
if (typeof pathPattern !== 'string')
|
|
323
|
+
throw new TypeError('pathPattern must be a string.');
|
|
324
|
+
return this.#routes.some((route) => route.segmentExtractor.pattern === pathPattern);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Navigates to a specific path programmatically.
|
|
328
|
+
* @param {string | URL | null | undefined} path - The target path.
|
|
329
|
+
* @param {any} [state={}] - Optional state object to associate with history.
|
|
330
|
+
* @returns {Promise<void>}
|
|
331
|
+
* @throws {TypeError} If path is not a string or state is not an object.
|
|
332
|
+
*/
|
|
333
|
+
async navigate(path, state = {}) {
|
|
334
|
+
checkDestroy(this.#isDestroyed);
|
|
335
|
+
// Prevent redundant navigation if the path is the same
|
|
336
|
+
if (window.location.pathname + window.location.search === path)
|
|
337
|
+
return;
|
|
338
|
+
window.history.pushState(state, '', path);
|
|
339
|
+
await this.#queue.enqueue(() => this.#resolve());
|
|
340
|
+
this.log('info', `Navigated to: ${path}`);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Triggers the initial route resolution (for deep linking on page load).
|
|
344
|
+
* @returns {Promise<void>}
|
|
345
|
+
* @throws {Error} If the router has already been started.
|
|
346
|
+
*/
|
|
347
|
+
start() {
|
|
348
|
+
if (this.#started)
|
|
349
|
+
return new Promise((resolve, reject) => reject(new Error('Router has already been started.')));
|
|
350
|
+
// Wrapped handler to synchronize the internal index when popstate is triggered by the browser
|
|
351
|
+
this.#popstateHandler = () => {
|
|
352
|
+
const path = window.location.pathname;
|
|
353
|
+
if (this.#historyLimit !== 0) {
|
|
354
|
+
const index = this.#history.findIndex((h) => h.path === path);
|
|
355
|
+
if (index !== -1) {
|
|
356
|
+
this.#historyIndex = index;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return this.#resolve();
|
|
360
|
+
};
|
|
361
|
+
window.addEventListener('popstate', this.#popstateHandler);
|
|
362
|
+
this.#started = true;
|
|
363
|
+
return this.#queue.enqueue(() => new Promise((resolve, reject) => {
|
|
364
|
+
let err;
|
|
365
|
+
try {
|
|
366
|
+
checkDestroy(this.#isDestroyed);
|
|
367
|
+
}
|
|
368
|
+
catch (error) {
|
|
369
|
+
err = error;
|
|
370
|
+
}
|
|
371
|
+
if (err)
|
|
372
|
+
return reject(err);
|
|
373
|
+
this.#resolve()
|
|
374
|
+
.then(() => {
|
|
375
|
+
this.emit('RouterStarted');
|
|
376
|
+
this.log('info', 'Router started successfully.');
|
|
377
|
+
resolve();
|
|
378
|
+
})
|
|
379
|
+
.catch(reject);
|
|
380
|
+
}));
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Cleans up the router, removes event listeners, and stops the router.
|
|
384
|
+
*/
|
|
385
|
+
stop() {
|
|
386
|
+
checkDestroy(this.#isDestroyed);
|
|
387
|
+
window.removeEventListener('popstate', this.#popstateHandler);
|
|
388
|
+
this.#started = false;
|
|
389
|
+
this.clearAll();
|
|
390
|
+
this.emit('RouterStopped');
|
|
391
|
+
this.log('info', 'Router stopped and event listeners removed.');
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Navigates to a specific number of steps in the browser's history.
|
|
395
|
+
* @param {number} delta - The number of steps to move (positive for forward, negative for backward).
|
|
396
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the URL changed, false otherwise.
|
|
397
|
+
* @throws {TypeError} If delta is not an integer.
|
|
398
|
+
*/
|
|
399
|
+
async go(delta) {
|
|
400
|
+
checkDestroy(this.#isDestroyed);
|
|
401
|
+
if (!this.#started) {
|
|
402
|
+
this.log('warn', 'Attempted to navigate while the router is stopped.');
|
|
403
|
+
return false;
|
|
404
|
+
}
|
|
405
|
+
if (!Number.isInteger(delta)) {
|
|
406
|
+
throw new TypeError('The "delta" parameter must be an integer.');
|
|
407
|
+
}
|
|
408
|
+
// If history limit is active, navigate using the internal cache
|
|
409
|
+
if (this.#historyLimit !== 0) {
|
|
410
|
+
const newIndex = this.#historyIndex + delta;
|
|
411
|
+
if (newIndex >= 0 && newIndex < this.#history.length) {
|
|
412
|
+
const targetPath = this.#history[newIndex].path;
|
|
413
|
+
window.history.pushState(null, '', targetPath);
|
|
414
|
+
await this.#queue.enqueue(() => this.#resolve());
|
|
415
|
+
return true;
|
|
416
|
+
}
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
// Native behavior when historyLimit is 0
|
|
420
|
+
if (!this.#detectHistoryChange) {
|
|
421
|
+
window.history.go(delta);
|
|
422
|
+
this.log('info', `Navigation command: go(${delta}) (detection disabled)`);
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
const oldUrl = window.location.pathname + window.location.search;
|
|
426
|
+
return this.#queue.enqueue(() => new Promise((resolve) => {
|
|
427
|
+
// We use a temporary handler to detect the 'popstate' event
|
|
428
|
+
const handler = () => {
|
|
429
|
+
window.removeEventListener('popstate', handler);
|
|
430
|
+
const newUrl = window.location.pathname + window.location.search;
|
|
431
|
+
// Returns true if the URL actually changed
|
|
432
|
+
resolve(oldUrl !== newUrl);
|
|
433
|
+
};
|
|
434
|
+
window.addEventListener('popstate', handler);
|
|
435
|
+
// Safety mechanism: If 'popstate' is not triggered (e.g., no history to move to),
|
|
436
|
+
// we wait for a very short time and then check if the URL changed anyway.
|
|
437
|
+
setTimeout(() => {
|
|
438
|
+
window.removeEventListener('popstate', handler);
|
|
439
|
+
const currentUrl = window.location.pathname + window.location.search;
|
|
440
|
+
resolve(oldUrl !== currentUrl);
|
|
441
|
+
}, 100);
|
|
442
|
+
window.history.go(delta);
|
|
443
|
+
this.log('info', `Navigation command: go(${delta})`);
|
|
444
|
+
}));
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Navigates to the previous entry in the browser's history stack.
|
|
448
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the URL changed, false otherwise.
|
|
449
|
+
*/
|
|
450
|
+
async back() {
|
|
451
|
+
return this.go(-1);
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Navigates to the next entry in the browser's history stack.
|
|
455
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the URL changed, false otherwise.
|
|
456
|
+
*/
|
|
457
|
+
async forward() {
|
|
458
|
+
return this.go(1);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Internal method to record a successful navigation.
|
|
462
|
+
* @param {string} path - The path to record.
|
|
463
|
+
*/
|
|
464
|
+
#recordHistory(path) {
|
|
465
|
+
checkDestroy(this.#isDestroyed);
|
|
466
|
+
// If limit is 0, the feature is disabled; do nothing.
|
|
467
|
+
if (this.#historyLimit === 0)
|
|
468
|
+
return;
|
|
469
|
+
// If we are already at the current path (e.g., via go() or popstate), do not add a duplicate
|
|
470
|
+
if (this.#historyIndex >= 0 && this.#history[this.#historyIndex].path === path) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
// Branching Logic: If we are in the middle of the history and a new route is opened,
|
|
474
|
+
// remove all entries ahead of the current position.
|
|
475
|
+
if (this.#historyIndex >= 0) {
|
|
476
|
+
this.#history = this.#history.slice(0, this.#historyIndex + 1);
|
|
477
|
+
}
|
|
478
|
+
this.#history.push({ path, timestamp: Date.now() });
|
|
479
|
+
this.#historyIndex++;
|
|
480
|
+
// Maintain the maximum allowed size for the cache
|
|
481
|
+
if (this.#historyLimit > 0 && this.#history.length > this.#historyLimit) {
|
|
482
|
+
this.#history.shift(); // Removes the oldest entry (first element)
|
|
483
|
+
this.#historyIndex--;
|
|
484
|
+
}
|
|
485
|
+
this.emit('HistoryRecorded', { ...this.#history[this.#historyIndex] });
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Internal method to match the current URL against registered routes.
|
|
489
|
+
* @returns {Promise<void>}
|
|
490
|
+
*/
|
|
491
|
+
async #resolve() {
|
|
492
|
+
checkDestroy(this.#isDestroyed);
|
|
493
|
+
const path = window.location.pathname;
|
|
494
|
+
const search = window.location.search;
|
|
495
|
+
const query = new URLSearchParams(search);
|
|
496
|
+
for (const route of this.#routes) {
|
|
497
|
+
const { params, match } = route.segmentExtractor.exec(path);
|
|
498
|
+
if (match) {
|
|
499
|
+
const matchResult = { path, params, query };
|
|
500
|
+
// Record the successful navigation in our private history
|
|
501
|
+
this.#recordHistory(path);
|
|
502
|
+
// Execute the route's specific callback
|
|
503
|
+
this.emit('BeforeRouteChanged', matchResult);
|
|
504
|
+
await route.callback(matchResult);
|
|
505
|
+
// Notify the global listener
|
|
506
|
+
this.#onRouteChanged(matchResult);
|
|
507
|
+
this.emit('AfterRouteChanged', matchResult);
|
|
508
|
+
this.log('info', `Route matched: ${path}`);
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
// If no route matches, you could implement a 404 logic here
|
|
513
|
+
const matchResult = { path, query };
|
|
514
|
+
this.#onRouteNotFound(matchResult);
|
|
515
|
+
this.emit('RouteNotFound', matchResult);
|
|
516
|
+
this.log('warn', `No route matched the current URL: ${path}`);
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* Removes a specific entry from the navigation history by its index.
|
|
520
|
+
* @param {number} index - The index of the entry to remove.
|
|
521
|
+
* @throws {TypeError} If index is not an integer.
|
|
522
|
+
* @throws {RangeError} If the index is out of bounds.
|
|
523
|
+
*/
|
|
524
|
+
removeHistoryEntry(index) {
|
|
525
|
+
checkDestroy(this.#isDestroyed);
|
|
526
|
+
if (!Number.isInteger(index)) {
|
|
527
|
+
throw new TypeError('The index must be an integer.');
|
|
528
|
+
}
|
|
529
|
+
if (index < 0 || index >= this.#history.length) {
|
|
530
|
+
throw new RangeError('The provided index is out of bounds.');
|
|
531
|
+
}
|
|
532
|
+
this.#history.splice(index, 1);
|
|
533
|
+
this.emit('HistoryEntryRemoved', index);
|
|
534
|
+
this.log('info', `History entry at index ${index} was removed.`);
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Clears all entries from the navigation history.
|
|
538
|
+
*/
|
|
539
|
+
clearHistory() {
|
|
540
|
+
checkDestroy(this.#isDestroyed);
|
|
541
|
+
this.#history = [];
|
|
542
|
+
this.emit('HistoryCleared');
|
|
543
|
+
this.log('info', 'Navigation history has been cleared.');
|
|
544
|
+
}
|
|
545
|
+
/**
|
|
546
|
+
* Removes all registered routes.
|
|
547
|
+
*/
|
|
548
|
+
clear() {
|
|
549
|
+
checkDestroy(this.#isDestroyed);
|
|
550
|
+
this.#routes = [];
|
|
551
|
+
this.emit('RoutesCleared');
|
|
552
|
+
this.log('info', 'All routes have been cleared.');
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* Removes all instance data.
|
|
556
|
+
*/
|
|
557
|
+
clearAll() {
|
|
558
|
+
checkDestroy(this.#isDestroyed);
|
|
559
|
+
this.clear();
|
|
560
|
+
this.clearHistory();
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* Destroy the instance.
|
|
564
|
+
*/
|
|
565
|
+
destroy() {
|
|
566
|
+
if (this.#isDestroyed)
|
|
567
|
+
return;
|
|
568
|
+
this.stop();
|
|
569
|
+
this.#isDestroyed = true;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
export default TinyRouter;
|
|
@@ -72,6 +72,25 @@ const customTypesFreezed = new Set([
|
|
|
72
72
|
* @typedef {(Record<string|number|symbol, any> | any[] | Map<string|number|symbol, any> | Set<any>)} LocalStorageJsonValue
|
|
73
73
|
*/
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Event map for {@link TinyLocalStorage}.
|
|
77
|
+
* @typedef {Object} TinyLocalStorageEvents
|
|
78
|
+
* @property {(ev: StorageEvent) => void} storage - Emitted when a cross-tab storage event is received.
|
|
79
|
+
* @property {(name: string, data: any) => void} setJson - Emitted when a JSON value is stored.
|
|
80
|
+
* @property {(name: string, data: Date) => void} setDate - Emitted when a Date is stored.
|
|
81
|
+
* @property {(name: string, data: RegExp) => void} setRegExp - Emitted when a RegExp is stored.
|
|
82
|
+
* @property {(name: string, data: bigint) => void} setBigInt - Emitted when a BigInt is stored.
|
|
83
|
+
* @property {(name: string, data: symbol) => void} setSymbol - Emitted when a Symbol is stored.
|
|
84
|
+
* @property {(name: string, data: any) => void} setItem - Emitted when a raw item is stored.
|
|
85
|
+
* @property {(name: string, data: string) => void} setString - Emitted when a string is stored.
|
|
86
|
+
* @property {(name: string, data: number) => void} setNumber - Emitted when a number is stored.
|
|
87
|
+
* @property {(name: string, data: boolean) => void} setBool - Emitted when a boolean is stored.
|
|
88
|
+
* @property {(name: string) => void} removeItem - Emitted when an item is removed.
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
/** @type {new (dbName?: string) => import('../../jsdoc/EventEmitter.mjs').ICustomEventEmitter<TinyLocalStorageEvents>} */
|
|
92
|
+
const TypedEventEmitter = /** @type {any} */ (events.EventEmitter);
|
|
93
|
+
|
|
75
94
|
/**
|
|
76
95
|
* A powerful wrapper for Web Storage (`localStorage` or `sessionStorage`) that supports
|
|
77
96
|
* type-safe methods and full JSON-like structure encoding and decoding.
|
|
@@ -96,7 +115,7 @@ const customTypesFreezed = new Set([
|
|
|
96
115
|
*
|
|
97
116
|
* This class is suitable for applications that require structured persistence in the browser.
|
|
98
117
|
*/
|
|
99
|
-
class TinyLocalStorage extends
|
|
118
|
+
class TinyLocalStorage extends TypedEventEmitter {
|
|
100
119
|
/**
|
|
101
120
|
* Checks whether a JSON-serializable type is already registered.
|
|
102
121
|
*
|