tiny-essentials 1.28.18 → 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/css/TinyCookieConsent.min.css +1 -0
- package/dist/v1/css/TinyCookieConsent.min.css.map +1 -0
- package/dist/v1/css/TinyDraggerExample.min.css +1 -0
- package/dist/v1/css/TinyDraggerExample.min.css.map +1 -0
- package/dist/v1/css/TinyLoadingScreen.min.css +1 -0
- package/dist/v1/css/TinyLoadingScreen.min.css.map +1 -0
- package/dist/v1/css/TinyNotify.min.css +1 -0
- package/dist/v1/css/TinyNotify.min.css.map +1 -0
- package/dist/v1/css/aiMarker.min.css +1 -0
- package/dist/v1/css/aiMarker.min.css.map +1 -0
- 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 +725 -0
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.d.mts +293 -0
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.d.mts.map +1 -0
- package/dist/v1/webTemplates/bootstrap/5.3/html/BootstrapDialogs.mjs +614 -0
- package/dist/v1/webTemplates/bootstrap/5.3/scss/input/Placeholder-Colors-Fix.scss +64 -0
- package/dist/v1/webTemplates/bootstrap/5.3/scss/spacing/Spacing-Plus.scss +31 -0
- 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 +111 -0
- package/docs/v1/README.md +117 -13
- 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 +174 -0
- 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 +313 -18
- package/types/EventEmitter.d.ts +48 -0
- package/dist/v1/libs/text/TinyI18.d.mts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{"use strict";const t={d:(e,r)=>{for(var s in r)t.o(r,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:r[s]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};let e={};t.d(e,{TinyHtmlTagRegexBuilder:()=>r});const r=class{#t;#e=[];#r=!1;#s;#o="";constructor(t){const e=t.tagName;if("string"!=typeof e)throw new TypeError("The tagName must be a string.");if(/[<>\s]/.test(e))throw new TypeError("The tagName must be a single word without spaces or < > characters.");if(this.#t=e,t.attributes){if(!Array.isArray(t.attributes))throw new TypeError("The attributes property must be an array of strings.");for(const e of t.attributes)if("string"!=typeof e||/[<>\s]/.test(e))throw new TypeError("Each attribute name must be a single word string without spaces or < > characters.");this.#e=t.attributes}if("boolean"!=typeof t.captureAllAttributes)throw new TypeError("captureAllAttributes must be a boolean.");this.#s=t.captureAllAttributes,this.freeMode=t.freeMode??!1,this.contentPattern=t.contentPattern||(this.#r?"[\\s\\S]*?":".*?")}get tagName(){return this.#t}get attributes(){return[...this.#e]}get freeMode(){return this.#r}set freeMode(t){if("boolean"!=typeof t)throw new TypeError("freeMode must be a boolean.");this.#r=t}get captureAllAttributes(){return this.#s}get contentPattern(){return this.#o}set contentPattern(t){if("string"!=typeof t)throw new TypeError("contentPattern must be a string.");this.#o=t}toString(){let t=`<${this.#t}`;if(this.#s)t+="([^>]*)";else{for(const e of this.#e)t+=`(?=[^>]*?\\s+${e}(?:=(?:["']([^"']*)["']|([^"'>\\s]+)))?(?=\\s|>|\\/))`;t+="[^>]*"}return t+=`>(${this.#o})</${this.#t}>`,t}toRegExp(t="g"){return new RegExp(this.toString(),t)}parse(t){const e=this.toRegExp("g"),r=[];let s;for(;null!==(s=e.exec(t));){const t={};let e="";if(this.#s){const r=s[1]||"";e=s[2]||"";const o=/([^\s=]+)(?:\s*=\s*(?:(?:"([^"]*)")|(?:'([^']*)')|([^\s"'>]+)))?/g;let n;for(;null!==(n=o.exec(r));){const e=n[1],r=n[2]??n[3]??n[4]??!0;t[e]=r}}else{for(let e=0;e<this.#e.length;e++){const r=this.#e[e],o=s[2*e+1],n=s[2*e+2];t[r]=o??n??!0}e=s[2*this.#e.length+1]||""}r.push({attributes:t,child:e})}return r}};window.TinyHtmlTagRegexBuilder=e.TinyHtmlTagRegexBuilder})();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(()=>{"use strict";const e={d:(t,r)=>{for(var s in r)e.o(r,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:r[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};e.d(t,{TinyHttpResponseRegistry:()=>u}),Object.freeze({F_OK:0,R_OK:4,W_OK:2,X_OK:1,COPYFILE_EXCL:1,COPYFILE_FICLONE:2,COPYFILE_FICLONE_FORCE:4,O_RDONLY:0,O_WRONLY:1,O_RDWR:2,O_CREAT:64,O_EXCL:128,O_TRUNC:512,O_APPEND:1024}),Object.freeze({OWNER_READ:256,OWNER_WRITE:128,OWNER_EXECUTE:64,GROUP_READ:32,GROUP_WRITE:16,GROUP_EXECUTE:8,OTHER_READ:4,OTHER_WRITE:2,OTHER_EXECUTE:1,SETUID:2048,SETGID:1024,STICKY:512}),Object.freeze({FILE:32768,DIRECTORY:16384,SYMBOLIC_LINK:40960}),Object.freeze(["utf8","utf-8","base64","hex"]);const r=e=>{if(e)throw new Error("This TinyI18 instance has been destroyed and can no longer be used.")};class s{static#e=null;static#t=null;static#r=null;static#s=null;static set _join(e){if("function"!=typeof e)throw new TypeError('TinyI18: "_join" must be a function');if(null!==s.#e)throw new Error('TinyI18: "_join" has already been set');s.#e=e}static set _existsSync(e){if("function"!=typeof e&&!1!==e)throw new TypeError('TinyI18: "_existsSync" must be a function or false');if(null!==s.#t)throw new Error('TinyI18: "_existsSync" has already been set');s.#t=e}static set _readFile(e){if("function"!=typeof e)throw new TypeError('TinyI18: "_readFile" must be a function');if(null!==s.#r)throw new Error('TinyI18: "_readFile" has already been set');s.#r=e}static set _writeFile(e){if("function"!=typeof e)throw new TypeError('TinyI18: "_writeFile" must be a function');if(null!==s.#s)throw new Error('TinyI18: "_writeFile" has already been set');s.#s=e}static async mergeLocaleFiles({files:e,output:t,spaces:r=0}){if(null===s.#t||null===s.#r||null===s.#s)throw new Error('TinyI18: "mergeLocaleFiles" requires "_existsSync", "_readFile", and "_writeFile" to be set');if("number"!=typeof r||Number.isNaN(r)||r<0)throw new TypeError('mergeLocaleFiles: "spaces" must be a non-negative number');if(!Array.isArray(e)||0===e.length)throw new TypeError('mergeLocaleFiles: "files" must be a non-empty array of file paths');if("string"!=typeof t||!t)throw new TypeError('mergeLocaleFiles: "output" must be a non-empty string path');const o={};for(const t of e){if("string"!=typeof t||!t)throw new TypeError("mergeLocaleFiles: each file path must be a non-empty string");if(!1!==s.#t&&!s.#t(t))throw new Error(`mergeLocaleFiles: file "${t}" does not exist`);const e=await s.#r(t,"utf-8");let r;try{r=JSON.parse(e)}catch(e){throw new Error(`mergeLocaleFiles: file "${t}" is not valid JSON`)}Object.assign(o,r)}await s.#s(t,JSON.stringify(o,null,r),"utf-8")}#o=!1;get destroyed(){return this.#o}#n;#i;#a=null;#l;#c=!1;#u=null;#p=new Map;#y=new Map;#m=new Map;#d=new Map;get currentLocale(){return r(this.#o),this.#a}get defaultLocale(){return r(this.#o),this.#i}get mode(){return r(this.#o),this.#n}get strict(){return r(this.#o),this.#l}get acceptNullResults(){return r(this.#o),this.#c}get basePath(){return r(this.#o),this.#u}get stats(){r(this.#o);const e=[];for(const t of this.#p.keys())e.push(this.getStatsForLocale(t));return e}get stringTables(){r(this.#o);const e={};for(const[t,r]of this.#p.entries())e[t]=this.#f(r);return e}get patternTables(){r(this.#o);const e={};for(const[t,r]of this.#y.entries())e[t]=r.map(e=>({$pattern:new RegExp(e.$pattern.source,e.$pattern.flags),value:this.#f(e.value),elseValue:this.#f(e.elseValue)}));return e}get helpers(){r(this.#o);const e={};for(const[t,r]of this.#m.entries())e[t]=r;return e}get regexCache(){r(this.#o);const e={};for(const[t,r]of this.#d.entries())e[t]=new RegExp(r.source,r.flags);return e}#f(e){if(null==e||"string"==typeof e||"function"==typeof e||"number"==typeof e)return e;if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(Array.isArray(e))return e.map(e=>this.#f(e));if("object"==typeof e){const t={};for(const[r,s]of Object.entries(e))t[r]=this.#f(s);return t}return e}#h(e){if(void 0!==e&&"string"!=typeof e)throw new TypeError('#resolveOrder: "forceLocale" must be a string if provided');const t=[];return e&&"string"==typeof e&&this.#p.has(e)?t.push(e):this.#a&&t.push(this.#a),t.push(this.#i),t}#g(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError('#resolveExact: "order" must be an array of strings');if("string"!=typeof t||!t)throw new TypeError('#resolveExact: "key" must be a non-empty string');for(const r of e){const e=this.#p.get(r);if(e&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}}#w(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError('#resolveByPattern: "order" must be an array of strings');if("string"!=typeof t||!t)throw new TypeError('#resolveByPattern: "key" must be a non-empty string');for(const r of e){const e=this.#y.get(r)||[];for(const r of e)return r.$pattern.test(t)?r.value:r.elseValue??void 0}}#b(e,t){if(null==e){if(this.#l)throw new TypeError('#materialize: "value" cannot be null or undefined');return""}if("string"==typeof e)return this.#T(e,t);if("function"==typeof e)return e(t??{},this.#E());if(e&&"object"==typeof e&&"string"==typeof e.$fn){const r=this.#m.get(e.$fn);if("function"!=typeof r){if(this.#l)throw new Error(`TinyI18: helper "${e.$fn}" is not registered`);return""}return r({...t??{},args:void 0!==e.args?e.args:void 0},this.#E())}if(this.#l)throw new Error("TinyI18: unsupported entry type");return""}#T(e,t){if("string"!=typeof e)throw new TypeError('#interpolate: "template" must be a string');if(void 0!==t&&(null===t||"object"!=typeof t))throw new TypeError('#interpolate: "params" must be an object if provided');return t&&"object"==typeof t?e.replace(/\{([a-zA-Z0-9_.$-]+)\}/g,(e,r)=>{const s=this.#L(t,r);return null==s?"":String(s)}):e}#L(e,t){if(!e||"object"!=typeof e)throw new TypeError('#dotGet: "obj" must be an object');if("string"!=typeof t||!t)throw new TypeError('#dotGet: "path" must be a non-empty string');const r=t.split(".");let s=e;for(const e of r){if(null==s)return;s=s[e]}return s}#E(){return{has:e=>this.#m.has(e),call:(e,t,r)=>{const s=this.#m.get(e);if("function"!=typeof s)throw new Error(`Helper "${e}" not found`);return s(t,r??{})}}}#R(e,t){if("string"!=typeof e||!e)throw new TypeError('#ingestLocale: "locale" must be a non-empty string');if(!t||"object"!=typeof t)throw new TypeError('#ingestLocale: "raw" must be an object');if("string"!=typeof e||!e)throw new TypeError("#ingestLocale: invalid locale");if(!t||"object"!=typeof t)throw new TypeError('#ingestLocale: "raw" must be an object');const r={...this.#p.get(e)??{}},s=[...this.#y.get(e)??[]],o=(e,t)=>{if(null!=t)if("string"==typeof t||"function"==typeof t||t&&"object"==typeof t&&"string"==typeof t.$fn){if(!e)throw new TypeError("Leaf value requires a key path");r[e]=t}else if(t&&"object"==typeof t){if(t.$pattern instanceof RegExp&&Object.prototype.hasOwnProperty.call(t,"value"))return void s.push({$pattern:t.$pattern,value:t.value,elseValue:t.elseValue});for(const[r,s]of Object.entries(t))o(e?`${e}.${r}`:r,s)}};o("",t),this.#p.set(e,r),this.#y.set(e,s),this.#p.has(this.#i)||(this.#p.set(this.#i,{}),this.#y.set(this.#i,[]))}#v(e){if("string"!=typeof e||!e)throw new TypeError('#unloadLocale: "locale" must be a non-empty string');e!==this.#i&&(this.#p.delete(e),this.#y.delete(e))}async#O(e){if(null===s.#e||null===s.#r)throw new Error('TinyI18: "file" mode requires "_join" and "_readFile" to be set');if("string"!=typeof e||!e)throw new TypeError('#loadLocaleFromFile: "locale" must be a non-empty string');if("string"!=typeof this.#u||!this.#u)throw new TypeError('#loadLocaleFromFile: "this.#basePath" must be a non-empty string');const t=s.#e(this.#u,`${e}.json`);let r;try{const e=await s.#r(t,"utf8");r=JSON.parse(e)}catch(r){if(!(r instanceof Error))return;if(this.#l)throw new Error(`TinyI18: failed to load or parse ${t}: ${r.message}`);return this.#p.set(e,{}),void this.#y.set(e,[])}const o={...this.#p.get(e)??{}},n=[...this.#y.get(e)??[]],i=(e,t)=>{if(null!=t){if(t&&"object"==typeof t&&"string"==typeof t.$pattern&&Object.prototype.hasOwnProperty.call(t,"value")){const e=this.#j(t.$pattern);return void n.push({$pattern:e,value:this.#F(t.value),elseValue:this.#F(t.elseValue)})}if("string"==typeof t||t&&"object"==typeof t&&"string"==typeof t.$fn){if(!e)throw new TypeError("Leaf value requires a key path");o[e]=this.#F(t)}else if(t&&"object"==typeof t)for(const[r,s]of Object.entries(t))i(e?`${e}.${r}`:r,s)}};i("",r),this.#p.set(e,o),this.#y.set(e,n)}#j(e){if("string"!=typeof e||!e)throw new TypeError('#safeRegExp: "src" must be a non-empty string');const t=this.#d.get(e);if(t)return t;try{const t=new RegExp(e);return this.#d.set(e,t),t}catch{if(this.#l)throw new Error(`TinyI18: invalid regex "${e}" in file`);return/^$/}}#F(e){if("string"==typeof e)return e;if(e&&"object"==typeof e&&"string"==typeof e.$fn)return{$fn:String(e.$fn),args:e.args};if(this.#l)throw new Error("TinyI18: unsupported value in file JSON");return""}constructor(e){if(!e||"object"!=typeof e)throw new TypeError("TinyI18: options must be an object");const{mode:t,defaultLocale:r,basePath:s,localResources:o,strict:n=!0,acceptNullResults:i=!1}=e;if("local"!==t&&"file"!==t)throw new TypeError('TinyI18: "mode" must be "local" or "file"');if("string"!=typeof r||!r)throw new TypeError('TinyI18: "defaultLocale" must be a non-empty string');if("boolean"!=typeof n)throw new TypeError('TinyI18: "strict" must be a boolean');if("boolean"!=typeof i)throw new TypeError('TinyI18: "acceptNullResults" must be a boolean');if("file"===t){if("string"!=typeof s||!s)throw new TypeError('TinyI18: "basePath" is required in file mode');this.#u=s}if(this.#n=t,this.#i=r,this.#l=n,this.#c=i,"local"===t&&o&&"object"==typeof o)for(const[e,t]of Object.entries(o))this.#R(e,t);this.#p.has(this.#i)||(this.#p.set(this.#i,{}),this.#y.set(this.#i,[]))}clearRegexCache(){r(this.#o),this.#d.clear()}registerHelper(e,t){if(r(this.#o),"string"!=typeof e||!e)throw new TypeError('registerHelper: "name" must be non-empty string');if("function"!=typeof t)throw new TypeError('registerHelper: "fn" must be a function');this.#m.set(e,t)}unregisterHelper(e){if(r(this.#o),"string"!=typeof e||!e)throw new TypeError('unregisterHelper: "name" must be a non-empty string');return this.#m.delete(e)}loadLocaleLocal(e,t){if(r(this.#o),"local"!==this.#n)throw new TypeError('loadLocaleLocal is only available in "local" mode');this.#R(e,t)}async setLocale(e){if(r(this.#o),null!==e&&("string"!=typeof e||!e))throw new TypeError('setLocale: "locale" must be string or null');const t=this.#a;null!==e&&("file"===this.#n?await this.#O(e):this.#p.has(e)||(this.#p.set(e,{}),this.#y.set(e,[]))),"file"===this.#n&&t&&t!==this.#i&&t!==e&&this.#v(t),this.#a=e}t(e,t=void 0,r=void 0){return this.get(e,t,r)}get(e,t=void 0,s=void 0){if(r(this.#o),"string"!=typeof e||!e)throw new TypeError('get: "key" must be a non-empty string');const{locale:o}=s||{},n=this.#h(o);let i=this.#g(n,e);if(void 0===i){if(this.#l)throw new Error(`TinyI18: missing translation for key "${e}"`);return this.#c?null:e}return this.#b(i,t)}p(e,t){return this.resolveByPattern(e,t)}resolveByPattern(e,t){if(r(this.#o),"string"!=typeof e||!e)throw new TypeError('get: "key" must be a non-empty string');const{locale:s}=t||{},o=this.#h(s);let n=this.#w(o,e);if(void 0===n){if(this.#l)throw new Error(`TinyI18: missing translation for key "${e}"`);return this.#c?null:e}return n}resetToDefaultOnly(){if(r(this.#o),"file"===this.#n)for(const e of Array.from(this.#p.keys()))e!==this.#i&&this.#v(e);this.#a=null}getStatsForLocale(e){if(r(this.#o),"string"!=typeof e||!e)throw new TypeError('getStatsForLocale: "locale" must be a non-empty string');if(!this.#p.has(e))throw new Error(`getStatsForLocale: locale "${e}" is not registered`);return{locale:e,strings:Object.keys(this.#p.get(e)??{}).length,patterns:this.#y.get(e)?.length??0,isDefault:e===this.#i,isCurrent:e===this.#a}}destroy(){this.#o||(this.#p.clear(),this.#y.clear(),this.#m.clear(),this.#d.clear(),this.#a=null,this.#u=null,this.#o=!0)}}const o=s;class n extends o{constructor(e){super(e)}}n._join=(...e)=>"/"+(e=>{const t=[];for(const r of e.split("/"))0!==r.length&&"."!==r&&(".."!==r?t.push(r):t.pop());return t})(e.join("/")).join("/"),n._existsSync=!1,n._readFile=async e=>{const t=await fetch(e);if(!t.ok)throw new Error(`TinyI18: failed to load "${e}": ${t.status} ${t.statusText}`);return t.text()},n._writeFile=async(e,t)=>{const r=new Blob([t],{type:"application/json"}),s=URL.createObjectURL(r),o=document.createElement("a");o.href=s,o.download=e.split("/").pop()||"download.json",o.click(),setTimeout(()=>URL.revokeObjectURL(s),0)};const i=n;const a={100:{name:"Continue",summary:"",description:""},101:{name:"Switching Protocols",summary:"",description:""},102:{name:"Processing",summary:"",description:""},103:{name:"Early Hints",summary:"",description:""},200:{name:"OK",summary:"",description:""},201:{name:"Created",summary:"",description:""},202:{name:"Accepted",summary:"",description:""},203:{name:"Non-Authoritative Information",summary:"",description:""},204:{name:"No Content",summary:"",description:""},205:{name:"Reset Content",summary:"",description:""},206:{name:"Partial Content",summary:"",description:""},207:{name:"Multi-Status",summary:"",description:""},208:{name:"Already Reported",summary:"",description:""},226:{name:"IM Used",summary:"",description:""},300:{name:"Multiple Choices",summary:"",description:""},301:{name:"Moved Permanently",summary:"",description:""},302:{name:"Found",summary:"",description:""},303:{name:"See Other",summary:"",description:""},304:{name:"Not Modified",summary:"",description:""},305:{name:"Use Proxy",summary:"",description:""},306:{name:"Unused",summary:"",description:""},307:{name:"Temporary Redirect",summary:"",description:""},308:{name:"Permanent Redirect",summary:"",description:""},400:{name:"Bad Request",summary:"",description:""},401:{name:"Unauthorized",summary:"",description:""},402:{name:"Payment Required",summary:"",description:""},403:{name:"Forbidden",summary:"",description:""},404:{name:"Not Found",summary:"",description:""},405:{name:"Method Not Allowed",summary:"",description:""},406:{name:"Not Acceptable",summary:"",description:""},407:{name:"Proxy Authentication Required",summary:"",description:""},408:{name:"Request Timeout",summary:"",description:""},409:{name:"Conflict",summary:"",description:""},410:{name:"Gone",summary:"",description:""},411:{name:"Length Required",summary:"",description:""},412:{name:"Precondition Failed",summary:"",description:""},413:{name:"Content Too Large",summary:"",description:""},414:{name:"URI Too Long",summary:"",description:""},415:{name:"Unsupported Media Type",summary:"",description:""},416:{name:"Range Not Satisfiable",summary:"",description:""},417:{name:"Expectation Failed",summary:"",description:""},418:{name:"I'm a teapot",summary:"",description:""},421:{name:"Misdirected Request",summary:"",description:""},422:{name:"Unprocessable Content",summary:"",description:""},423:{name:"Locked",summary:"",description:""},424:{name:"Failed Dependency",summary:"",description:""},425:{name:"Too Early",summary:"",description:""},426:{name:"Upgrade Required",summary:"",description:""},428:{name:"Precondition Required",summary:"",description:""},429:{name:"Too Many Requests",summary:"",description:""},431:{name:"Request Header Fields Too Large",summary:"",description:""},451:{name:"Unavailable For Legal Reasons",summary:"",description:""},500:{name:"Internal Server Error",summary:"",description:""},501:{name:"Not Implemented",summary:"",description:""},502:{name:"Bad Gateway",summary:"",description:""},503:{name:"Service Unavailable",summary:"",description:""},504:{name:"Gateway Timeout",summary:"",description:""},505:{name:"HTTP Version Not Supported",summary:"",description:""},506:{name:"Variant Also Negotiates",summary:"",description:""},507:{name:"Insufficient Storage",summary:"",description:""},508:{name:"Loop Detected",summary:"",description:""},510:{name:"Not Extended",summary:"",description:""},511:{name:"Network Authentication Required",summary:"",description:""}};class l{static#N=a;static codeIs=Object.freeze({info:e=>{if("number"!=typeof e||Number.isNaN(e))throw new TypeError("The status code must be a valid number.");return e>=100&&e<=199},success:e=>{if("number"!=typeof e||Number.isNaN(e))throw new TypeError("The status code must be a valid number.");return e>=200&&e<=299},redirect:e=>{if("number"!=typeof e||Number.isNaN(e))throw new TypeError("The status code must be a valid number.");return e>=300&&e<=399},clientError:e=>{if("number"!=typeof e||Number.isNaN(e))throw new TypeError("The status code must be a valid number.");return e>=400&&e<=499},serverError:e=>{if("number"!=typeof e||Number.isNaN(e))throw new TypeError("The status code must be a valid number.");return e>=500&&e<=599}});static get defaultRequestCodes(){return structuredClone(l.#N)}static set defaultRequestCodes(e){if("object"!=typeof e||null===e||Array.isArray(e))throw new TypeError("The value must be a non-null object.");for(const[t,r]of Object.entries(e)){if(Number.isNaN(Number(t)))throw new TypeError(`Invalid key: "${t}". Status code keys must be numeric.`);if("object"!=typeof r||null===r||Array.isArray(r))throw new TypeError(`The value for status code ${t} must be an object.`);if("string"!=typeof r.name)throw new TypeError(`Property 'name' in status ${t} must be a string.`);if("string"!=typeof r.summary)throw new TypeError(`Property 'summary' in status ${t} must be a string.`);if("string"!=typeof r.description)throw new TypeError(`Property 'description' in status ${t} must be a string.`)}l.#N=structuredClone(e)}#C=new Set;#I;#$="en";constructor(e,t={}){if(null===(r=t)||"object"!=typeof r||Array.isArray(r)||"[object Object]"!==Object.prototype.toString.call(r))throw new TypeError("Initial responses must be an object.");var r;if(this.#I=new e({defaultLocale:"en",mode:"local",strict:!1,acceptNullResults:!0}),!(this.#I instanceof o))throw new TypeError('The "i18" must be an instance of TinyI18.');this.#I.loadLocaleLocal(this.#$,{});for(const e in l.#N){const t=l.#N[e];this.addResponse(Number(e),t)}for(const e in t){const r=t[e];this.addResponse(Number(e),r)}}#_(e,t){if("object"!=typeof t||null===t)throw new TypeError("Response must be a non-null object.");if("string"!=typeof t.name)throw new TypeError('The "name" property must be a string.');if("string"!=typeof t.summary)throw new TypeError('The "summary" property must be a string.');if("string"!=typeof t.description)throw new TypeError('The "description" property must be a string.');if(this.#I.get(String(e)))throw new Error(`Response with ID ${e} already exists in the registry.`)}addResponse(e,t,r=this.#$){this.#_(e,t),this.#C.add(e),this.#I.loadLocaleLocal(r,{[e]:{name:t.name,summary:t.summary,description:t.description}})}get(e,t={},r=this.#$){const s=this.#I.get(`${e}.name`,t,{locale:r}),o=this.#I.get(`${e}.summary`,t,{locale:r}),n=this.#I.get(`${e}.description`,t,{locale:r});return"string"!=typeof s||"string"!=typeof o||"string"!=typeof n?null:{name:s,summary:o,description:n}}has(e){return!!this.#I.get(String(e))}getAll(){const e={};return this.#C.forEach(t=>{const r=this.get(t);r&&(e[t]=r)}),e}}const c=l,u=class extends c{constructor(e){super(i,e)}};window.TinyHttpResponseRegistry=t.TinyHttpResponseRegistry})();
|
package/dist/v1/TinyI18.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{var e={975(e,t,r){"use strict";var n=r(606);function o(e){if("string"!=typeof e)throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}function s(e,t){for(var r,n="",o=0,s=-1,i=0,a=0;a<=e.length;++a){if(a<e.length)r=e.charCodeAt(a);else{if(47===r)break;r=47}if(47===r){if(s===a-1||1===i);else if(s!==a-1&&2===i){if(n.length<2||2!==o||46!==n.charCodeAt(n.length-1)||46!==n.charCodeAt(n.length-2))if(n.length>2){var l=n.lastIndexOf("/");if(l!==n.length-1){-1===l?(n="",o=0):o=(n=n.slice(0,l)).length-1-n.lastIndexOf("/"),s=a,i=0;continue}}else if(2===n.length||1===n.length){n="",o=0,s=a,i=0;continue}t&&(n.length>0?n+="/..":n="..",o=2)}else n.length>0?n+="/"+e.slice(s+1,a):n=e.slice(s+1,a),o=a-s-1;s=a,i=0}else 46===r&&-1!==i?++i:i=-1}return n}var i={resolve:function(){for(var e,t="",r=!1,i=arguments.length-1;i>=-1&&!r;i--){var a;i>=0?a=arguments[i]:(void 0===e&&(e=n.cwd()),a=e),o(a),0!==a.length&&(t=a+"/"+t,r=47===a.charCodeAt(0))}return t=s(t,!r),r?t.length>0?"/"+t:"/":t.length>0?t:"."},normalize:function(e){if(o(e),0===e.length)return".";var t=47===e.charCodeAt(0),r=47===e.charCodeAt(e.length-1);return 0!==(e=s(e,!t)).length||t||(e="."),e.length>0&&r&&(e+="/"),t?"/"+e:e},isAbsolute:function(e){return o(e),e.length>0&&47===e.charCodeAt(0)},join:function(){if(0===arguments.length)return".";for(var e,t=0;t<arguments.length;++t){var r=arguments[t];o(r),r.length>0&&(void 0===e?e=r:e+="/"+r)}return void 0===e?".":i.normalize(e)},relative:function(e,t){if(o(e),o(t),e===t)return"";if((e=i.resolve(e))===(t=i.resolve(t)))return"";for(var r=1;r<e.length&&47===e.charCodeAt(r);++r);for(var n=e.length,s=n-r,a=1;a<t.length&&47===t.charCodeAt(a);++a);for(var l=t.length-a,c=s<l?s:l,f=-1,h=0;h<=c;++h){if(h===c){if(l>c){if(47===t.charCodeAt(a+h))return t.slice(a+h+1);if(0===h)return t.slice(a+h)}else s>c&&(47===e.charCodeAt(r+h)?f=h:0===h&&(f=0));break}var u=e.charCodeAt(r+h);if(u!==t.charCodeAt(a+h))break;47===u&&(f=h)}var p="";for(h=r+f+1;h<=n;++h)h!==n&&47!==e.charCodeAt(h)||(0===p.length?p+="..":p+="/..");return p.length>0?p+t.slice(a+f):(a+=f,47===t.charCodeAt(a)&&++a,t.slice(a))},_makeLong:function(e){return e},dirname:function(e){if(o(e),0===e.length)return".";for(var t=e.charCodeAt(0),r=47===t,n=-1,s=!0,i=e.length-1;i>=1;--i)if(47===(t=e.charCodeAt(i))){if(!s){n=i;break}}else s=!1;return-1===n?r?"/":".":r&&1===n?"//":e.slice(0,n)},basename:function(e,t){if(void 0!==t&&"string"!=typeof t)throw new TypeError('"ext" argument must be a string');o(e);var r,n=0,s=-1,i=!0;if(void 0!==t&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return"";var a=t.length-1,l=-1;for(r=e.length-1;r>=0;--r){var c=e.charCodeAt(r);if(47===c){if(!i){n=r+1;break}}else-1===l&&(i=!1,l=r+1),a>=0&&(c===t.charCodeAt(a)?-1===--a&&(s=r):(a=-1,s=l))}return n===s?s=l:-1===s&&(s=e.length),e.slice(n,s)}for(r=e.length-1;r>=0;--r)if(47===e.charCodeAt(r)){if(!i){n=r+1;break}}else-1===s&&(i=!1,s=r+1);return-1===s?"":e.slice(n,s)},extname:function(e){o(e);for(var t=-1,r=0,n=-1,s=!0,i=0,a=e.length-1;a>=0;--a){var l=e.charCodeAt(a);if(47!==l)-1===n&&(s=!1,n=a+1),46===l?-1===t?t=a:1!==i&&(i=1):-1!==t&&(i=-1);else if(!s){r=a+1;break}}return-1===t||-1===n||0===i||1===i&&t===n-1&&t===r+1?"":e.slice(t,n)},format:function(e){if(null===e||"object"!=typeof e)throw new TypeError('The "pathObject" argument must be of type Object. Received type '+typeof e);return function(e,t){var r=t.dir||t.root,n=t.base||(t.name||"")+(t.ext||"");return r?r===t.root?r+n:r+"/"+n:n}(0,e)},parse:function(e){o(e);var t={root:"",dir:"",base:"",ext:"",name:""};if(0===e.length)return t;var r,n=e.charCodeAt(0),s=47===n;s?(t.root="/",r=1):r=0;for(var i=-1,a=0,l=-1,c=!0,f=e.length-1,h=0;f>=r;--f)if(47!==(n=e.charCodeAt(f)))-1===l&&(c=!1,l=f+1),46===n?-1===i?i=f:1!==h&&(h=1):-1!==i&&(h=-1);else if(!c){a=f+1;break}return-1===i||-1===l||0===h||1===h&&i===l-1&&i===a+1?-1!==l&&(t.base=t.name=0===a&&s?e.slice(1,l):e.slice(a,l)):(0===a&&s?(t.name=e.slice(1,i),t.base=e.slice(1,l)):(t.name=e.slice(a,i),t.base=e.slice(a,l)),t.ext=e.slice(i,l)),a>0?t.dir=e.slice(0,a-1):s&&(t.dir="/"),t},sep:"/",delimiter:":",win32:null,posix:null};i.posix=i,e.exports=i},606(e){var t,r,n=e.exports={};function o(){throw new Error("setTimeout has not been defined")}function s(){throw new Error("clearTimeout has not been defined")}function i(e){if(t===setTimeout)return setTimeout(e,0);if((t===o||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(r){try{return t.call(null,e,0)}catch(r){return t.call(this,e,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:o}catch(e){t=o}try{r="function"==typeof clearTimeout?clearTimeout:s}catch(e){r=s}}();var a,l=[],c=!1,f=-1;function h(){c&&a&&(c=!1,a.length?l=a.concat(l):f=-1,l.length&&u())}function u(){if(!c){var e=i(h);c=!0;for(var t=l.length;t;){for(a=l,l=[];++f<t;)a&&a[f].run();f=-1,t=l.length}a=null,c=!1,function(e){if(r===clearTimeout)return clearTimeout(e);if((r===s||!r)&&clearTimeout)return r=clearTimeout,clearTimeout(e);try{return r(e)}catch(t){try{return r.call(null,e)}catch(t){return r.call(this,e)}}}(e)}}function p(e,t){this.fun=e,this.array=t}function y(){}n.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];l.push(new p(e,t)),1!==l.length||c||i(u)},p.prototype.run=function(){this.fun.apply(null,this.array)},n.title="browser",n.browser=!0,n.env={},n.argv=[],n.version="",n.versions={},n.on=y,n.addListener=y,n.once=y,n.off=y,n.removeListener=y,n.removeAllListeners=y,n.emit=y,n.prependListener=y,n.prependOnceListener=y,n.listeners=function(e){return[]},n.binding=function(e){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(e){throw new Error("process.chdir is not supported")},n.umask=function(){return 0}},494(){},31(){}};const t={};function r(n){const o=t[n];if(void 0!==o)return o.exports;const s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}r.d=(e,t)=>{if(Array.isArray(t))for(var n=0;n<t.length;){var o=t[n++],s=t[n++];r.o(e,o)?0===s&&n++:0===s?Object.defineProperty(e,o,{enumerable:!0,value:t[n++]}):Object.defineProperty(e,o,{enumerable:!0,get:s})}else for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);let n={};(()=>{"use strict";r.d(n,{TinyI18:()=>i});var e=r(31),t=r(494),o=r(975);const s=e=>{if(e)throw new Error("This TinyI18 instance has been destroyed and can no longer be used.")};const i=class{static async mergeLocaleFiles({files:r,output:n,spaces:o=0}){if("number"!=typeof o||Number.isNaN(o)||o<0)throw new TypeError('mergeLocaleFiles: "spaces" must be a non-negative number');if(!Array.isArray(r)||0===r.length)throw new TypeError('mergeLocaleFiles: "files" must be a non-empty array of file paths');if("string"!=typeof n||!n)throw new TypeError('mergeLocaleFiles: "output" must be a non-empty string path');const s={};for(const n of r){if("string"!=typeof n||!n)throw new TypeError("mergeLocaleFiles: each file path must be a non-empty string");if(!(0,t.existsSync)(n))throw new Error(`mergeLocaleFiles: file "${n}" does not exist`);const r=await(0,e.readFile)(n,"utf-8");let o;try{o=JSON.parse(r)}catch(e){throw new Error(`mergeLocaleFiles: file "${n}" is not valid JSON`)}Object.assign(s,o)}await(0,e.writeFile)(n,JSON.stringify(s,null,o),"utf-8")}#e=!1;get destroyed(){return this.#e}#t;#r;#n=null;#o;#s=null;#i=new Map;#a=new Map;#l=new Map;#c=new Map;get currentLocale(){return s(this.#e),this.#n}get defaultLocale(){return s(this.#e),this.#r}get mode(){return s(this.#e),this.#t}get strict(){return s(this.#e),this.#o}get basePath(){return s(this.#e),this.#s}get stats(){s(this.#e);const e=[];for(const t of this.#i.keys())e.push(this.getStatsForLocale(t));return e}get stringTables(){s(this.#e);const e={};for(const[t,r]of this.#i.entries())e[t]=this.#f(r);return e}get patternTables(){s(this.#e);const e={};for(const[t,r]of this.#a.entries())e[t]=r.map(e=>({$pattern:new RegExp(e.$pattern.source,e.$pattern.flags),value:this.#f(e.value),elseValue:this.#f(e.elseValue)}));return e}get helpers(){s(this.#e);const e={};for(const[t,r]of this.#l.entries())e[t]=r;return e}get regexCache(){s(this.#e);const e={};for(const[t,r]of this.#c.entries())e[t]=new RegExp(r.source,r.flags);return e}#f(e){if(null==e||"string"==typeof e||"function"==typeof e||"number"==typeof e)return e;if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(Array.isArray(e))return e.map(e=>this.#f(e));if("object"==typeof e){const t={};for(const[r,n]of Object.entries(e))t[r]=this.#f(n);return t}return e}#h(e){if(void 0!==e&&"string"!=typeof e)throw new TypeError('#resolveOrder: "forceLocale" must be a string if provided');const t=[];return e&&"string"==typeof e&&this.#i.has(e)?t.push(e):this.#n&&t.push(this.#n),t.push(this.#r),t}#u(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError('#resolveExact: "order" must be an array of strings');if("string"!=typeof t||!t)throw new TypeError('#resolveExact: "key" must be a non-empty string');for(const r of e){const e=this.#i.get(r);if(e&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}}#p(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError('#resolveByPattern: "order" must be an array of strings');if("string"!=typeof t||!t)throw new TypeError('#resolveByPattern: "key" must be a non-empty string');for(const r of e){const e=this.#a.get(r)||[];for(const r of e)return r.$pattern.test(t)?r.value:r.elseValue??void 0}}#y(e,t){if(null==e){if(this.#o)throw new TypeError('#materialize: "value" cannot be null or undefined');return""}if("string"==typeof e)return this.#g(e,t);if("function"==typeof e)return e(t??{},this.#d());if(e&&"object"==typeof e&&"string"==typeof e.$fn){const r=this.#l.get(e.$fn);if("function"!=typeof r){if(this.#o)throw new Error(`TinyI18: helper "${e.$fn}" is not registered`);return""}return r({...t??{},args:void 0!==e.args?e.args:void 0},this.#d())}if(this.#o)throw new Error("TinyI18: unsupported entry type");return""}#g(e,t){if("string"!=typeof e)throw new TypeError('#interpolate: "template" must be a string');if(void 0!==t&&(null===t||"object"!=typeof t))throw new TypeError('#interpolate: "params" must be an object if provided');return t&&"object"==typeof t?e.replace(/\{([a-zA-Z0-9_.$-]+)\}/g,(e,r)=>{const n=this.#b(t,r);return null==n?"":String(n)}):e}#b(e,t){if(!e||"object"!=typeof e)throw new TypeError('#dotGet: "obj" must be an object');if("string"!=typeof t||!t)throw new TypeError('#dotGet: "path" must be a non-empty string');const r=t.split(".");let n=e;for(const e of r){if(null==n)return;n=n[e]}return n}#d(){return{has:e=>this.#l.has(e),call:(e,t,r)=>{const n=this.#l.get(e);if("function"!=typeof n)throw new Error(`Helper "${e}" not found`);return n(t,r??{})}}}#w(e,t){if("string"!=typeof e||!e)throw new TypeError('#ingestLocale: "locale" must be a non-empty string');if(!t||"object"!=typeof t)throw new TypeError('#ingestLocale: "raw" must be an object');if("string"!=typeof e||!e)throw new TypeError("#ingestLocale: invalid locale");if(!t||"object"!=typeof t)throw new TypeError('#ingestLocale: "raw" must be an object');const r={...this.#i.get(e)??{}},n=[...this.#a.get(e)??[]],o=(e,t)=>{if(null!=t)if("string"==typeof t||"function"==typeof t||t&&"object"==typeof t&&"string"==typeof t.$fn){if(!e)throw new TypeError("Leaf value requires a key path");r[e]=t}else if(t&&"object"==typeof t){if(t.$pattern instanceof RegExp&&Object.prototype.hasOwnProperty.call(t,"value"))return void n.push({$pattern:t.$pattern,value:t.value,elseValue:t.elseValue});for(const[r,n]of Object.entries(t))o(e?`${e}.${r}`:r,n)}};o("",t),this.#i.set(e,r),this.#a.set(e,n),this.#i.has(this.#r)||(this.#i.set(this.#r,{}),this.#a.set(this.#r,[]))}#m(e){if("string"!=typeof e||!e)throw new TypeError('#unloadLocale: "locale" must be a non-empty string');e!==this.#r&&(this.#i.delete(e),this.#a.delete(e))}async#T(t){if("string"!=typeof t||!t)throw new TypeError('#loadLocaleFromFile: "locale" must be a non-empty string');if("string"!=typeof this.#s||!this.#s)throw new TypeError('#loadLocaleFromFile: "this.#basePath" must be a non-empty string');const r=(0,o.join)(this.#s,`${t}.json`);let n;try{const t=await(0,e.readFile)(r,"utf8");n=JSON.parse(t)}catch(e){if(!(e instanceof Error))return;if(this.#o)throw new Error(`TinyI18: failed to load or parse ${r}: ${e.message}`);return this.#i.set(t,{}),void this.#a.set(t,[])}const s={...this.#i.get(t)??{}},i=[...this.#a.get(t)??[]],a=(e,t)=>{if(null!=t){if(t&&"object"==typeof t&&"string"==typeof t.$pattern&&Object.prototype.hasOwnProperty.call(t,"value")){const e=this.#v(t.$pattern);return void i.push({$pattern:e,value:this.#E(t.value),elseValue:this.#E(t.elseValue)})}if("string"==typeof t||t&&"object"==typeof t&&"string"==typeof t.$fn){if(!e)throw new TypeError("Leaf value requires a key path");s[e]=this.#E(t)}else if(t&&"object"==typeof t)for(const[r,n]of Object.entries(t))a(e?`${e}.${r}`:r,n)}};a("",n),this.#i.set(t,s),this.#a.set(t,i)}#v(e){if("string"!=typeof e||!e)throw new TypeError('#safeRegExp: "src" must be a non-empty string');const t=this.#c.get(e);if(t)return t;try{const t=new RegExp(e);return this.#c.set(e,t),t}catch{if(this.#o)throw new Error(`TinyI18: invalid regex "${e}" in file`);return/^$/}}#E(e){if("string"==typeof e)return e;if(e&&"object"==typeof e&&"string"==typeof e.$fn)return{$fn:String(e.$fn),args:e.args};if(this.#o)throw new Error("TinyI18: unsupported value in file JSON");return""}constructor(e){if(!e||"object"!=typeof e)throw new TypeError("TinyI18: options must be an object");const{mode:t,defaultLocale:r,basePath:n,localResources:o,strict:s=!0}=e;if("local"!==t&&"file"!==t)throw new TypeError('TinyI18: "mode" must be "local" or "file"');if("string"!=typeof r||!r)throw new TypeError('TinyI18: "defaultLocale" must be a non-empty string');if("boolean"!=typeof s)throw new TypeError('TinyI18: "strict" must be a boolean');if("file"===t){if("string"!=typeof n||!n)throw new TypeError('TinyI18: "basePath" is required in file mode');this.#s=n}if(this.#t=t,this.#r=r,this.#o=s,"local"===t&&o&&"object"==typeof o)for(const[e,t]of Object.entries(o))this.#w(e,t);this.#i.has(this.#r)||(this.#i.set(this.#r,{}),this.#a.set(this.#r,[]))}clearRegexCache(){s(this.#e),this.#c.clear()}registerHelper(e,t){if(s(this.#e),"string"!=typeof e||!e)throw new TypeError('registerHelper: "name" must be non-empty string');if("function"!=typeof t)throw new TypeError('registerHelper: "fn" must be a function');this.#l.set(e,t)}unregisterHelper(e){if(s(this.#e),"string"!=typeof e||!e)throw new TypeError('unregisterHelper: "name" must be non-empty string');return this.#l.delete(e)}loadLocaleLocal(e,t){if(s(this.#e),"local"!==this.#t)throw new TypeError('loadLocaleLocal is only available in "local" mode');this.#w(e,t)}async setLocale(e){if(s(this.#e),null!==e&&("string"!=typeof e||!e))throw new TypeError('setLocale: "locale" must be string or null');const t=this.#n;null!==e&&("file"===this.#t?await this.#T(e):this.#i.has(e)||(this.#i.set(e,{}),this.#a.set(e,[]))),"file"===this.#t&&t&&t!==this.#r&&t!==e&&this.#m(t),this.#n=e}t(e,t=void 0,r=void 0){return this.get(e,t,r)}get(e,t=void 0,r=void 0){if(s(this.#e),"string"!=typeof e||!e)throw new TypeError('get: "key" must be a non-empty string');const{locale:n}=r||{},o=this.#h(n);let i=this.#u(o,e);if(void 0===i){if(this.#o)throw new Error(`TinyI18: missing translation for key "${e}"`);return e}return this.#y(i,t)}p(e,t){return this.resolveByPattern(e,t)}resolveByPattern(e,t){if(s(this.#e),"string"!=typeof e||!e)throw new TypeError('get: "key" must be a non-empty string');const{locale:r}=t||{},n=this.#h(r);let o=this.#p(n,e);if(void 0===o){if(this.#o)throw new Error(`TinyI18: missing translation for key "${e}"`);return e}return o}resetToDefaultOnly(){if(s(this.#e),"file"===this.#t)for(const e of Array.from(this.#i.keys()))e!==this.#r&&this.#m(e);this.#n=null}getStatsForLocale(e){if(s(this.#e),"string"!=typeof e||!e)throw new TypeError('getStatsForLocale: "locale" must be a non-empty string');if(!this.#i.has(e))throw new Error(`getStatsForLocale: locale "${e}" is not registered`);return{locale:e,strings:Object.keys(this.#i.get(e)??{}).length,patterns:this.#a.get(e)?.length??0,isDefault:e===this.#r,isCurrent:e===this.#n}}destroy(){this.#e||(this.#i.clear(),this.#a.clear(),this.#l.clear(),this.#c.clear(),this.#n=null,this.#s=null,this.#e=!0)}}})(),window.TinyI18=n.TinyI18})();
|
|
1
|
+
(()=>{"use strict";const e={d:(t,r)=>{for(var s in r)e.o(r,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:r[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};e.d(t,{TinyI18:()=>i}),Object.freeze({F_OK:0,R_OK:4,W_OK:2,X_OK:1,COPYFILE_EXCL:1,COPYFILE_FICLONE:2,COPYFILE_FICLONE_FORCE:4,O_RDONLY:0,O_WRONLY:1,O_RDWR:2,O_CREAT:64,O_EXCL:128,O_TRUNC:512,O_APPEND:1024}),Object.freeze({OWNER_READ:256,OWNER_WRITE:128,OWNER_EXECUTE:64,GROUP_READ:32,GROUP_WRITE:16,GROUP_EXECUTE:8,OTHER_READ:4,OTHER_WRITE:2,OTHER_EXECUTE:1,SETUID:2048,SETGID:1024,STICKY:512}),Object.freeze({FILE:32768,DIRECTORY:16384,SYMBOLIC_LINK:40960}),Object.freeze(["utf8","utf-8","base64","hex"]);const r=e=>{if(e)throw new Error("This TinyI18 instance has been destroyed and can no longer be used.")};class s{static#e=null;static#t=null;static#r=null;static#s=null;static set _join(e){if("function"!=typeof e)throw new TypeError('TinyI18: "_join" must be a function');if(null!==s.#e)throw new Error('TinyI18: "_join" has already been set');s.#e=e}static set _existsSync(e){if("function"!=typeof e&&!1!==e)throw new TypeError('TinyI18: "_existsSync" must be a function or false');if(null!==s.#t)throw new Error('TinyI18: "_existsSync" has already been set');s.#t=e}static set _readFile(e){if("function"!=typeof e)throw new TypeError('TinyI18: "_readFile" must be a function');if(null!==s.#r)throw new Error('TinyI18: "_readFile" has already been set');s.#r=e}static set _writeFile(e){if("function"!=typeof e)throw new TypeError('TinyI18: "_writeFile" must be a function');if(null!==s.#s)throw new Error('TinyI18: "_writeFile" has already been set');s.#s=e}static async mergeLocaleFiles({files:e,output:t,spaces:r=0}){if(null===s.#t||null===s.#r||null===s.#s)throw new Error('TinyI18: "mergeLocaleFiles" requires "_existsSync", "_readFile", and "_writeFile" to be set');if("number"!=typeof r||Number.isNaN(r)||r<0)throw new TypeError('mergeLocaleFiles: "spaces" must be a non-negative number');if(!Array.isArray(e)||0===e.length)throw new TypeError('mergeLocaleFiles: "files" must be a non-empty array of file paths');if("string"!=typeof t||!t)throw new TypeError('mergeLocaleFiles: "output" must be a non-empty string path');const o={};for(const t of e){if("string"!=typeof t||!t)throw new TypeError("mergeLocaleFiles: each file path must be a non-empty string");if(!1!==s.#t&&!s.#t(t))throw new Error(`mergeLocaleFiles: file "${t}" does not exist`);const e=await s.#r(t,"utf-8");let r;try{r=JSON.parse(e)}catch(e){throw new Error(`mergeLocaleFiles: file "${t}" is not valid JSON`)}Object.assign(o,r)}await s.#s(t,JSON.stringify(o,null,r),"utf-8")}#o=!1;get destroyed(){return this.#o}#n;#i;#a=null;#l;#c=!1;#f=null;#h=new Map;#p=new Map;#u=new Map;#y=new Map;get currentLocale(){return r(this.#o),this.#a}get defaultLocale(){return r(this.#o),this.#i}get mode(){return r(this.#o),this.#n}get strict(){return r(this.#o),this.#l}get acceptNullResults(){return r(this.#o),this.#c}get basePath(){return r(this.#o),this.#f}get stats(){r(this.#o);const e=[];for(const t of this.#h.keys())e.push(this.getStatsForLocale(t));return e}get stringTables(){r(this.#o);const e={};for(const[t,r]of this.#h.entries())e[t]=this.#d(r);return e}get patternTables(){r(this.#o);const e={};for(const[t,r]of this.#p.entries())e[t]=r.map(e=>({$pattern:new RegExp(e.$pattern.source,e.$pattern.flags),value:this.#d(e.value),elseValue:this.#d(e.elseValue)}));return e}get helpers(){r(this.#o);const e={};for(const[t,r]of this.#u.entries())e[t]=r;return e}get regexCache(){r(this.#o);const e={};for(const[t,r]of this.#y.entries())e[t]=new RegExp(r.source,r.flags);return e}#d(e){if(null==e||"string"==typeof e||"function"==typeof e||"number"==typeof e)return e;if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(Array.isArray(e))return e.map(e=>this.#d(e));if("object"==typeof e){const t={};for(const[r,s]of Object.entries(e))t[r]=this.#d(s);return t}return e}#g(e){if(void 0!==e&&"string"!=typeof e)throw new TypeError('#resolveOrder: "forceLocale" must be a string if provided');const t=[];return e&&"string"==typeof e&&this.#h.has(e)?t.push(e):this.#a&&t.push(this.#a),t.push(this.#i),t}#w(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError('#resolveExact: "order" must be an array of strings');if("string"!=typeof t||!t)throw new TypeError('#resolveExact: "key" must be a non-empty string');for(const r of e){const e=this.#h.get(r);if(e&&Object.prototype.hasOwnProperty.call(e,t))return e[t]}}#b(e,t){if(!Array.isArray(e)||!e.every(e=>"string"==typeof e))throw new TypeError('#resolveByPattern: "order" must be an array of strings');if("string"!=typeof t||!t)throw new TypeError('#resolveByPattern: "key" must be a non-empty string');for(const r of e){const e=this.#p.get(r)||[];for(const r of e)return r.$pattern.test(t)?r.value:r.elseValue??void 0}}#T(e,t){if(null==e){if(this.#l)throw new TypeError('#materialize: "value" cannot be null or undefined');return""}if("string"==typeof e)return this.#E(e,t);if("function"==typeof e)return e(t??{},this.#m());if(e&&"object"==typeof e&&"string"==typeof e.$fn){const r=this.#u.get(e.$fn);if("function"!=typeof r){if(this.#l)throw new Error(`TinyI18: helper "${e.$fn}" is not registered`);return""}return r({...t??{},args:void 0!==e.args?e.args:void 0},this.#m())}if(this.#l)throw new Error("TinyI18: unsupported entry type");return""}#E(e,t){if("string"!=typeof e)throw new TypeError('#interpolate: "template" must be a string');if(void 0!==t&&(null===t||"object"!=typeof t))throw new TypeError('#interpolate: "params" must be an object if provided');return t&&"object"==typeof t?e.replace(/\{([a-zA-Z0-9_.$-]+)\}/g,(e,r)=>{const s=this.#L(t,r);return null==s?"":String(s)}):e}#L(e,t){if(!e||"object"!=typeof e)throw new TypeError('#dotGet: "obj" must be an object');if("string"!=typeof t||!t)throw new TypeError('#dotGet: "path" must be a non-empty string');const r=t.split(".");let s=e;for(const e of r){if(null==s)return;s=s[e]}return s}#m(){return{has:e=>this.#u.has(e),call:(e,t,r)=>{const s=this.#u.get(e);if("function"!=typeof s)throw new Error(`Helper "${e}" not found`);return s(t,r??{})}}}#O(e,t){if("string"!=typeof e||!e)throw new TypeError('#ingestLocale: "locale" must be a non-empty string');if(!t||"object"!=typeof t)throw new TypeError('#ingestLocale: "raw" must be an object');if("string"!=typeof e||!e)throw new TypeError("#ingestLocale: invalid locale");if(!t||"object"!=typeof t)throw new TypeError('#ingestLocale: "raw" must be an object');const r={...this.#h.get(e)??{}},s=[...this.#p.get(e)??[]],o=(e,t)=>{if(null!=t)if("string"==typeof t||"function"==typeof t||t&&"object"==typeof t&&"string"==typeof t.$fn){if(!e)throw new TypeError("Leaf value requires a key path");r[e]=t}else if(t&&"object"==typeof t){if(t.$pattern instanceof RegExp&&Object.prototype.hasOwnProperty.call(t,"value"))return void s.push({$pattern:t.$pattern,value:t.value,elseValue:t.elseValue});for(const[r,s]of Object.entries(t))o(e?`${e}.${r}`:r,s)}};o("",t),this.#h.set(e,r),this.#p.set(e,s),this.#h.has(this.#i)||(this.#h.set(this.#i,{}),this.#p.set(this.#i,[]))}#F(e){if("string"!=typeof e||!e)throw new TypeError('#unloadLocale: "locale" must be a non-empty string');e!==this.#i&&(this.#h.delete(e),this.#p.delete(e))}async#j(e){if(null===s.#e||null===s.#r)throw new Error('TinyI18: "file" mode requires "_join" and "_readFile" to be set');if("string"!=typeof e||!e)throw new TypeError('#loadLocaleFromFile: "locale" must be a non-empty string');if("string"!=typeof this.#f||!this.#f)throw new TypeError('#loadLocaleFromFile: "this.#basePath" must be a non-empty string');const t=s.#e(this.#f,`${e}.json`);let r;try{const e=await s.#r(t,"utf8");r=JSON.parse(e)}catch(r){if(!(r instanceof Error))return;if(this.#l)throw new Error(`TinyI18: failed to load or parse ${t}: ${r.message}`);return this.#h.set(e,{}),void this.#p.set(e,[])}const o={...this.#h.get(e)??{}},n=[...this.#p.get(e)??[]],i=(e,t)=>{if(null!=t){if(t&&"object"==typeof t&&"string"==typeof t.$pattern&&Object.prototype.hasOwnProperty.call(t,"value")){const e=this.#v(t.$pattern);return void n.push({$pattern:e,value:this.#R(t.value),elseValue:this.#R(t.elseValue)})}if("string"==typeof t||t&&"object"==typeof t&&"string"==typeof t.$fn){if(!e)throw new TypeError("Leaf value requires a key path");o[e]=this.#R(t)}else if(t&&"object"==typeof t)for(const[r,s]of Object.entries(t))i(e?`${e}.${r}`:r,s)}};i("",r),this.#h.set(e,o),this.#p.set(e,n)}#v(e){if("string"!=typeof e||!e)throw new TypeError('#safeRegExp: "src" must be a non-empty string');const t=this.#y.get(e);if(t)return t;try{const t=new RegExp(e);return this.#y.set(e,t),t}catch{if(this.#l)throw new Error(`TinyI18: invalid regex "${e}" in file`);return/^$/}}#R(e){if("string"==typeof e)return e;if(e&&"object"==typeof e&&"string"==typeof e.$fn)return{$fn:String(e.$fn),args:e.args};if(this.#l)throw new Error("TinyI18: unsupported value in file JSON");return""}constructor(e){if(!e||"object"!=typeof e)throw new TypeError("TinyI18: options must be an object");const{mode:t,defaultLocale:r,basePath:s,localResources:o,strict:n=!0,acceptNullResults:i=!1}=e;if("local"!==t&&"file"!==t)throw new TypeError('TinyI18: "mode" must be "local" or "file"');if("string"!=typeof r||!r)throw new TypeError('TinyI18: "defaultLocale" must be a non-empty string');if("boolean"!=typeof n)throw new TypeError('TinyI18: "strict" must be a boolean');if("boolean"!=typeof i)throw new TypeError('TinyI18: "acceptNullResults" must be a boolean');if("file"===t){if("string"!=typeof s||!s)throw new TypeError('TinyI18: "basePath" is required in file mode');this.#f=s}if(this.#n=t,this.#i=r,this.#l=n,this.#c=i,"local"===t&&o&&"object"==typeof o)for(const[e,t]of Object.entries(o))this.#O(e,t);this.#h.has(this.#i)||(this.#h.set(this.#i,{}),this.#p.set(this.#i,[]))}clearRegexCache(){r(this.#o),this.#y.clear()}registerHelper(e,t){if(r(this.#o),"string"!=typeof e||!e)throw new TypeError('registerHelper: "name" must be non-empty string');if("function"!=typeof t)throw new TypeError('registerHelper: "fn" must be a function');this.#u.set(e,t)}unregisterHelper(e){if(r(this.#o),"string"!=typeof e||!e)throw new TypeError('unregisterHelper: "name" must be a non-empty string');return this.#u.delete(e)}loadLocaleLocal(e,t){if(r(this.#o),"local"!==this.#n)throw new TypeError('loadLocaleLocal is only available in "local" mode');this.#O(e,t)}async setLocale(e){if(r(this.#o),null!==e&&("string"!=typeof e||!e))throw new TypeError('setLocale: "locale" must be string or null');const t=this.#a;null!==e&&("file"===this.#n?await this.#j(e):this.#h.has(e)||(this.#h.set(e,{}),this.#p.set(e,[]))),"file"===this.#n&&t&&t!==this.#i&&t!==e&&this.#F(t),this.#a=e}t(e,t=void 0,r=void 0){return this.get(e,t,r)}get(e,t=void 0,s=void 0){if(r(this.#o),"string"!=typeof e||!e)throw new TypeError('get: "key" must be a non-empty string');const{locale:o}=s||{},n=this.#g(o);let i=this.#w(n,e);if(void 0===i){if(this.#l)throw new Error(`TinyI18: missing translation for key "${e}"`);return this.#c?null:e}return this.#T(i,t)}p(e,t){return this.resolveByPattern(e,t)}resolveByPattern(e,t){if(r(this.#o),"string"!=typeof e||!e)throw new TypeError('get: "key" must be a non-empty string');const{locale:s}=t||{},o=this.#g(s);let n=this.#b(o,e);if(void 0===n){if(this.#l)throw new Error(`TinyI18: missing translation for key "${e}"`);return this.#c?null:e}return n}resetToDefaultOnly(){if(r(this.#o),"file"===this.#n)for(const e of Array.from(this.#h.keys()))e!==this.#i&&this.#F(e);this.#a=null}getStatsForLocale(e){if(r(this.#o),"string"!=typeof e||!e)throw new TypeError('getStatsForLocale: "locale" must be a non-empty string');if(!this.#h.has(e))throw new Error(`getStatsForLocale: locale "${e}" is not registered`);return{locale:e,strings:Object.keys(this.#h.get(e)??{}).length,patterns:this.#p.get(e)?.length??0,isDefault:e===this.#i,isCurrent:e===this.#a}}destroy(){this.#o||(this.#h.clear(),this.#p.clear(),this.#u.clear(),this.#y.clear(),this.#a=null,this.#f=null,this.#o=!0)}}const o=s;class n extends o{constructor(e){super(e)}}n._join=(...e)=>"/"+(e=>{const t=[];for(const r of e.split("/"))0!==r.length&&"."!==r&&(".."!==r?t.push(r):t.pop());return t})(e.join("/")).join("/"),n._existsSync=!1,n._readFile=async e=>{const t=await fetch(e);if(!t.ok)throw new Error(`TinyI18: failed to load "${e}": ${t.status} ${t.statusText}`);return t.text()},n._writeFile=async(e,t)=>{const r=new Blob([t],{type:"application/json"}),s=URL.createObjectURL(r),o=document.createElement("a");o.href=s,o.download=e.split("/").pop()||"download.json",o.click(),setTimeout(()=>URL.revokeObjectURL(s),0)};const i=n;window.TinyI18=t.TinyI18})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var e={187(e,t,n){n.d(t,{TinyIframeEvents:()=>h});var r=n.cjs(function(e,t){var n,r="object"==typeof Reflect?Reflect:null,i=r&&"function"==typeof r.apply?r.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};n=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var s=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}e.exports=o,e.exports.once=function(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,s),r(n)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}l(e,t,s,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&l(e,"error",t,{once:!0})}(e,i)})},o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var a=10;function h(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function u(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function d(e,t,n,r){var i,s,o,a;if(h(n),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),o=s[t]),void 0===o)o=s[t]=n,++e._eventsCount;else if("function"==typeof o?o=s[t]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),(i=u(e))>0&&o.length>i&&!o.warned){o.warned=!0;var d=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");d.name="MaxListenersExceededWarning",d.emitter=e,d.type=t,d.count=o.length,a=d,console&&console.warn&&console.warn(a)}return e}function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}function v(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):y(i,i.length)}function c(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function y(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function l(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function i(s){r.once&&e.removeEventListener(t,i),n(s)})}}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),o.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return u(this)},o.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var r="error"===e,s=this._events;if(void 0!==s)r=r&&void 0===s.error;else if(!r)return!1;if(r){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var h=s[e];if(void 0===h)return!1;if("function"==typeof h)i(h,this,t);else{var u=h.length,d=y(h,u);for(n=0;n<u;++n)i(d[n],this,t)}return!0},o.prototype.addListener=function(e,t){return d(this,e,t,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(e,t){return d(this,e,t,!0)},o.prototype.once=function(e,t){return h(t),this.on(e,p(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return h(t),this.prependListener(e,p(this,e,t)),this},o.prototype.removeListener=function(e,t){var n,r,i,s,o;if(h(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){o=n[s].listener,i=s;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,o||t)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,s=Object.keys(n);for(r=0;r<s.length;++r)"removeListener"!==(i=s[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},o.prototype.listeners=function(e){return v(this,e,!0)},o.prototype.rawListeners=function(e){return v(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):c.call(e,t)},o.prototype.listenerCount=c,o.prototype.eventNames=function(){return this._eventsCount>0?n(this._events):[]}});function i(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"===Object.prototype.toString.call(e)}const s=e=>{if(e)throw new Error("This TinyIframeEvents instance has been destroyed and can no longer be used.")};const o=new WeakMap;class a extends r.EventEmitter{#e;get targetWindow(){return s(this.#t),this.#e}#n;get targetIframeElement(){return s(this.#t),this.#n}#r;get targetOrigin(){return s(this.#t),this.#r}#i;get selfType(){return s(this.#t),this.#i}#t=!1;#s=!1;get ready(){return s(this.#t),this.#s}onReady(e){s(this.#t),this.#s?e():this.once(this.#o,e)}#a=null;#h=[];#u;#d;#o;#f=null;constructor({targetIframe:e,targetOrigin:t=window.location.origin,secretEventName:n="__tinyIframeEvent__",handshakeEventName:r="__tinyIframeHandshake__",readyEventName:i="__tinyIframeReady__"}={}){if(super(),!(void 0===e||e instanceof HTMLIFrameElement&&e.contentWindow))throw new TypeError('[TinyIframeEvents] Invalid "targetIframe": expected HTMLIFrameElement, received '+typeof e);if("string"!=typeof t)throw new TypeError('[TinyIframeEvents] Invalid "targetOrigin": expected string, received '+typeof t);if(this.#n=e,this.#e=e?.contentWindow??window.parent,this.#r=t,this.#i=e?"parent":"iframe",this.#u=n,this.#d=r,this.#o=i,o.has(this.#e))throw new Error("Duplicate window reference.");this._boundWindowMessage=this.#p.bind(this),this._boundPortMessage=this.#v.bind(this),this.#c(),o.set(this.#e,this)}get secretEventName(){return s(this.#t),this.#u}set secretEventName(e){if(s(this.#t),"string"!=typeof e)throw new TypeError("TinyIframeEvents: secretEventName must be a string.");this.#u=e}get handshakeEventName(){return s(this.#t),this.#d}set handshakeEventName(e){if(s(this.#t),"string"!=typeof e)throw new TypeError("TinyIframeEvents: handshakeEventName must be a string.");this.#d=e}get readyEventName(){return s(this.#t),this.#o}set readyEventName(e){if(s(this.#t),"string"!=typeof e)throw new TypeError("TinyIframeEvents: readyEventName must be a string.");this.#o=e}#c(){"parent"===this.#i?(this.#f=()=>{if(this.#t)return;this.#a&&this.#a.close();const e=new MessageChannel;this.#a=e.port1,this.#a.onmessage=this._boundPortMessage,this.#s=!1,this.#e.postMessage({type:this.#d},this.#r,[e.port2])},this.#n&&(this.#n.addEventListener("load",this.#f),this.#f())):window.addEventListener("message",this._boundWindowMessage,!1)}#p(e){const t=e.data,n=e.ports;i(t)&&t.type===this.#d&&0!==n.length&&(this.#a=n[0],this.#a.onmessage=this._boundPortMessage,window.removeEventListener("message",this._boundWindowMessage),this.#a.postMessage({type:`${this.#d}_ACK`}),this.#y())}#v(e){const t=e.data;if(i(t)&&t.type===`${this.#d}_ACK`)return void this.#y();if(!i(t)||!t[this.#u])return;const n=t.eventName,r=t.payload,s=t.direction;"string"!=typeof n||"iframe"===this.#i&&"iframe"!==s||"parent"===this.#i&&"parent"!==s||this.emit(`win:${n}`,r,e)}#y(){this.#s||(this.#s=!0,this.#l(),this.emit(this.#o))}#l(){for(;this.#h.length>0;){const e=this.#h.shift();e&&this.#a&&this.#a.postMessage(e)}}winEmit(e,t){if(s(this.#t),"string"!=typeof e)throw new TypeError("Event name must be a string.");if(this.#t)throw new Error("Cannot emit: instance has been destroyed.");const n={[this.#u]:!0,eventName:e,payload:t,direction:"parent"===this.#i?"iframe":"parent"};this.#s&&this.#a?this.#a.postMessage(n):this.#h.push(n)}isDestroyed(){return this.#t}destroy(){this.#t||(this.#s=!1,window.removeEventListener("message",this._boundWindowMessage),this.#n&&this.#f&&this.#n.removeEventListener("load",this.#f),this.#a&&(this.#a.close(),this.#a=null),this.removeAllListeners(),this.#h=[],o.delete(this.#e),this.#t=!0)}}const h=a}};const t={};function n(r){const i=t[r];if(void 0!==i)return i.exports;const s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.d=(e,t)=>{if(Array.isArray(t))for(var r=0;r<t.length;){var i=t[r++],s=t[r++];n.o(e,i)?0===s&&r++:0===s?Object.defineProperty(e,i,{enumerable:!0,value:t[r++]}):Object.defineProperty(e,i,{enumerable:!0,get:s})}else for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.cjs=e=>{const t={exports:{}};return e.call(t.exports,t,t.exports),t.exports};let r=n(187);window.TinyIframeEvents=r.TinyIframeEvents})();
|
|
1
|
+
(()=>{"use strict";const e={cw:e=>{var t;return()=>{if(e){var n=e;e=0,t={exports:{}},n.call(t.exports,t,t.exports)}return t.exports}},d:(t,n)=>{for(var r in n)e.o(n,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:n[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};e.d(t,{TinyIframeEvents:()=>a});var n=e.cw(function(e,t){var n,r="object"==typeof Reflect?Reflect:null,i=r&&"function"==typeof r.apply?r.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)};n=r&&"function"==typeof r.ownKeys?r.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var s=Number.isNaN||function(e){return e!=e};function o(){o.init.call(this)}e.exports=o,e.exports.once=function(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,s),r(n)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",i),n([].slice.call(arguments))}l(e,t,s,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&l(e,"error",t,{once:!0})}(e,i)})},o.EventEmitter=o,o.prototype._events=void 0,o.prototype._eventsCount=0,o.prototype._maxListeners=void 0;var a=10;function h(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function d(e){return void 0===e._maxListeners?o.defaultMaxListeners:e._maxListeners}function u(e,t,n,r){var i,s,o,a;if(h(n),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),o=s[t]),void 0===o)o=s[t]=n,++e._eventsCount;else if("function"==typeof o?o=s[t]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),(i=d(e))>0&&o.length>i&&!o.warned){o.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=o.length,a=u,console&&console.warn&&console.warn(a)}return e}function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}function v(e,t,n){var r=e._events;if(void 0===r)return[];var i=r[t];return void 0===i?[]:"function"==typeof i?n?[i.listener||i]:[i]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(i):y(i,i.length)}function c(e){var t=this._events;if(void 0!==t){var n=t[e];if("function"==typeof n)return 1;if(void 0!==n)return n.length}return 0}function y(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}function l(e,t,n,r){if("function"==typeof e.on)r.once?e.once(t,n):e.on(t,n);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function i(s){r.once&&e.removeEventListener(t,i),n(s)})}}Object.defineProperty(o,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),o.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},o.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},o.prototype.getMaxListeners=function(){return d(this)},o.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var r="error"===e,s=this._events;if(void 0!==s)r=r&&void 0===s.error;else if(!r)return!1;if(r){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var h=s[e];if(void 0===h)return!1;if("function"==typeof h)i(h,this,t);else{var d=h.length,u=y(h,d);for(n=0;n<d;++n)i(u[n],this,t)}return!0},o.prototype.addListener=function(e,t){return u(this,e,t,!1)},o.prototype.on=o.prototype.addListener,o.prototype.prependListener=function(e,t){return u(this,e,t,!0)},o.prototype.once=function(e,t){return h(t),this.on(e,p(this,e,t)),this},o.prototype.prependOnceListener=function(e,t){return h(t),this.prependListener(e,p(this,e,t)),this},o.prototype.removeListener=function(e,t){var n,r,i,s,o;if(h(t),void 0===(r=this._events))return this;if(void 0===(n=r[e]))return this;if(n===t||n.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){o=n[s].listener,i=s;break}if(i<0)return this;0===i?n.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(n,i),1===n.length&&(r[e]=n[0]),void 0!==r.removeListener&&this.emit("removeListener",e,o||t)}return this},o.prototype.off=o.prototype.removeListener,o.prototype.removeAllListeners=function(e){var t,n,r;if(void 0===(n=this._events))return this;if(void 0===n.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==n[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete n[e]),this;if(0===arguments.length){var i,s=Object.keys(n);for(r=0;r<s.length;++r)"removeListener"!==(i=s[r])&&this.removeAllListeners(i);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(void 0!==t)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this},o.prototype.listeners=function(e){return v(this,e,!0)},o.prototype.rawListeners=function(e){return v(this,e,!1)},o.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):c.call(e,t)},o.prototype.listenerCount=c,o.prototype.eventNames=function(){return this._eventsCount>0?n(this._events):[]}});function r(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"===Object.prototype.toString.call(e)}n();const i=e=>{if(e)throw new Error("This TinyIframeEvents instance has been destroyed and can no longer be used.")};const s=new WeakMap,o=n().EventEmitter,a=class extends o{#e;get targetWindow(){return i(this.#t),this.#e}#n;get targetIframeElement(){return i(this.#t),this.#n}#r;get targetOrigin(){return i(this.#t),this.#r}#i;get selfType(){return i(this.#t),this.#i}#t=!1;#s=!1;get ready(){return i(this.#t),this.#s}onReady(e){i(this.#t),this.#s?e():this.once(this.#o,e)}#a=null;#h=[];#d;#u;#o;#f=null;constructor({targetIframe:e,targetOrigin:t=window.location.origin,secretEventName:n="__tinyIframeEvent__",handshakeEventName:r="__tinyIframeHandshake__",readyEventName:i="__tinyIframeReady__"}={}){if(super(),!(void 0===e||e instanceof HTMLIFrameElement&&e.contentWindow))throw new TypeError('[TinyIframeEvents] Invalid "targetIframe": expected HTMLIFrameElement, received '+typeof e);if("string"!=typeof t)throw new TypeError('[TinyIframeEvents] Invalid "targetOrigin": expected string, received '+typeof t);if(this.#n=e,this.#e=e?.contentWindow??window.parent,this.#r=t,this.#i=e?"parent":"iframe",this.#d=n,this.#u=r,this.#o=i,s.has(this.#e))throw new Error("Duplicate window reference.");this._boundWindowMessage=this.#p.bind(this),this._boundPortMessage=this.#v.bind(this),this.#c(),s.set(this.#e,this)}get secretEventName(){return i(this.#t),this.#d}set secretEventName(e){if(i(this.#t),"string"!=typeof e)throw new TypeError("TinyIframeEvents: secretEventName must be a string.");this.#d=e}get handshakeEventName(){return i(this.#t),this.#u}set handshakeEventName(e){if(i(this.#t),"string"!=typeof e)throw new TypeError("TinyIframeEvents: handshakeEventName must be a string.");this.#u=e}get readyEventName(){return i(this.#t),this.#o}set readyEventName(e){if(i(this.#t),"string"!=typeof e)throw new TypeError("TinyIframeEvents: readyEventName must be a string.");this.#o=e}#c(){"parent"===this.#i?(this.#f=()=>{if(this.#t)return;this.#a&&this.#a.close();const e=new MessageChannel;this.#a=e.port1,this.#a.onmessage=this._boundPortMessage,this.#s=!1,this.#e.postMessage({type:this.#u},this.#r,[e.port2])},this.#n&&(this.#n.addEventListener("load",this.#f),this.#f())):window.addEventListener("message",this._boundWindowMessage,!1)}#p(e){const t=e.data,n=e.ports;r(t)&&t.type===this.#u&&0!==n.length&&(this.#a=n[0],this.#a.onmessage=this._boundPortMessage,window.removeEventListener("message",this._boundWindowMessage),this.#a.postMessage({type:`${this.#u}_ACK`}),this.#y())}#v(e){const t=e.data;if(r(t)&&t.type===`${this.#u}_ACK`)return void this.#y();if(!r(t)||!t[this.#d])return;const n=t.eventName,i=t.payload,s=t.direction;"string"!=typeof n||"iframe"===this.#i&&"iframe"!==s||"parent"===this.#i&&"parent"!==s||this.emit(`win:${n}`,i,e)}#y(){this.#s||(this.#s=!0,this.#l(),this.emit(this.#o))}#l(){for(;this.#h.length>0;){const e=this.#h.shift();e&&this.#a&&this.#a.postMessage(e)}}winEmit(e,t){if(i(this.#t),"string"!=typeof e)throw new TypeError("Event name must be a string.");if(this.#t)throw new Error("Cannot emit: instance has been destroyed.");const n={[this.#d]:!0,eventName:e,payload:t,direction:"parent"===this.#i?"iframe":"parent"};this.#s&&this.#a?this.#a.postMessage(n):this.#h.push(n)}isDestroyed(){return this.#t}destroy(){this.#t||(this.#s=!1,window.removeEventListener("message",this._boundWindowMessage),this.#n&&this.#f&&this.#n.removeEventListener("load",this.#f),this.#a&&(this.#a.close(),this.#a=null),this.removeAllListeners(),this.#h=[],s.delete(this.#e),this.#t=!0)}};window.TinyIframeEvents=t.TinyIframeEvents})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";const t={d:(e,i)=>{if(Array.isArray(i))for(var r=0;r<i.length;){var o=i[r++],n=i[r++];t.o(e,o)?0===n&&r++:0===n?Object.defineProperty(e,o,{enumerable:!0,value:i[r++]}):Object.defineProperty(e,o,{enumerable:!0,get:n})}else for(var o in i)t.o(i,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:i[o]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};let e={};t.d(e,{TinyInventory:()=>r});class i{static#t=new Map;static get itemRegistry(){const t={},e=Object.fromEntries(i.#t);for(const i in e)t[i]={...e[i],metadata:{...e[i].metadata}};return t}static defineItem(t){if(!t||"object"!=typeof t)throw new TypeError("Config must be a valid object.");if(!t.id||"string"!=typeof t.id)throw new TypeError("Item must have a valid string 'id'.");if(void 0!==t.weight&&("number"!=typeof t.weight||t.weight<0))throw new TypeError(`weight must be a number >= 0. Received: ${t.weight}`);if(void 0!==t.maxStack&&(!Number.isInteger(t.maxStack)||t.maxStack<=0))throw new TypeError(`maxStack must be a positive integer. Received: ${t.maxStack}`);if(void 0!==t.metadata&&"object"!=typeof t.metadata)throw new TypeError("metadata must be an object.");if(void 0!==t.onUse&&null!==t.onUse&&"function"!=typeof t.onUse)throw new TypeError("onUse must be a function or null.");if(void 0!==t.type&&null!==t.type&&"string"!=typeof t.type)throw new TypeError("type must be a string or null.");i.#t.set(t.id,{id:t.id,weight:t.weight||0,maxStack:t.maxStack||1,metadata:t.metadata||{},type:t.type??null,onUse:"function"==typeof t.onUse?t.onUse:null})}static removeItem(t){if("string"!=typeof t)throw new TypeError("itemId must be a string.");return i.#t.delete(t)}static hasItem(t){if("string"!=typeof t)throw new TypeError("itemId must be a string.");return i.#t.has(t)}static getItem(t){if("string"!=typeof t)throw new TypeError("itemId must be a string.");const e=i.#t.get(t);if(!e)throw new Error(`Item '${t}' not defined in registry.`);return e}#e=new Map;#i={add:[],remove:[],use:[],set:[]};#r=[];#o;#n;#s;#a;get maxStack(){return this.#o}set maxStack(t){if(!Number.isInteger(t)||Number.isFinite(t)&&t<=0)throw new TypeError(`maxStack must be a positive integer. Received: ${t}`);this.#o=t}get maxSize(){return this.#n}set maxSize(t){if(null!==t&&(!Number.isInteger(t)||t<=0))throw new TypeError(`maxSize must be null or a positive integer. Received: ${t}`);this.#n=t}get maxSlots(){return this.#s}set maxSlots(t){if(null!==t&&(!Number.isInteger(t)||t<=0))throw new TypeError(`maxSlots must be null or a positive integer. Received: ${t}`);this.#s=t}get maxWeight(){return this.#a}set maxWeight(t){if(null!==t&&("number"!=typeof t||t<=0))throw new TypeError(`maxWeight must be null or a positive number. Received: ${t}`);this.#a=t}get events(){return{add:[...this.#i.add],remove:[...this.#i.remove],use:[...this.#i.use],set:[...this.#i.set]}}get items(){return[...this.#r].map(t=>t?this.#l(t):null)}get specialSlots(){return new Map([...this.#e.entries()].map(([t,e])=>[t,{type:e.type,item:e.item?this.#l(e.item):null}]))}get size(){const t=this.getAllItems();let e=0;for(const i of t)e+=i.quantity;return e}get slotsSize(){return this.getAllItems().length}get weight(){return this.getAllItems().reduce((t,e)=>{const r=i.getItem(e.id);return t+(r?.weight||0)*e.quantity},0)}_cleanNulls(){let t=this.#r.length-1;for(;t>=0&&null===this.#r[t];)t--;this.#r=this.#r.slice(0,t+1)}constructor(t={}){if("object"!=typeof t||null===t)throw new TypeError("`options` must be an object.");if(void 0!==t.maxWeight&&null!==t.maxWeight&&"number"!=typeof t.maxWeight)throw new TypeError("`maxWeight` must be a number or null.");if(void 0!==t.maxSlots&&null!==t.maxSlots&&"number"!=typeof t.maxSlots)throw new TypeError("`maxSlots` must be a number or null.");if(void 0!==t.maxSize&&null!==t.maxSize&&"number"!=typeof t.maxSize)throw new TypeError("`maxSize` must be a number or null.");if(void 0!==t.maxStack&&"number"!=typeof t.maxStack)throw new TypeError("`maxStack` must be a number.");if(void 0!==t.specialSlots&&"object"!=typeof t.specialSlots)throw new TypeError("`specialSlots` must be an object if defined.");if(this.#a=t.maxWeight??null,this.#s=t.maxSlots??null,this.#n=t.maxSize??null,this.#o=t.maxStack??1/0,t.specialSlots)for(const e in t.specialSlots){const i=t.specialSlots[e];if("object"!=typeof i||null===i)throw new TypeError("Each `specialSlot` entry must be an object.");if(void 0!==i.type&&null!==i.type&&"string"!=typeof i.type)throw new TypeError("`specialSlot.type` must be a string or null.");this.#e.set(e,{type:i.type??null,item:null})}}hasSpace({weight:t=0,sizeLength:e=0,slotsLength:i=0}={}){if("number"!=typeof t)throw new TypeError("`weight` must be a number.");if("number"!=typeof e)throw new TypeError("`sizeLength` must be a number.");if("number"!=typeof i)throw new TypeError("`slotsLength` must be a number.");return!(this.areFull(e)||this.areFullSlots(i)||this.isHeavy(t))}isHeavy(t=0){if("number"!=typeof t)throw new TypeError("`extraWeight` must be a number.");return null!==this.#a&&this.weight+t>this.#a}areFull(t=0){if("number"!=typeof t)throw new TypeError("`extraLength` must be a number.");return null!==this.#n&&this.size+t>this.#n}isFull(t=0){if("number"!=typeof t)throw new TypeError("`extraLength` must be a number.");return null!==this.#n&&this.size+t>=this.#n}areFullSlots(t=0){if("number"!=typeof t)throw new TypeError("`extraLength` must be a number.");return null!==this.#s&&this.slotsSize+t>this.#s}isFullSlots(t=0){if("number"!=typeof t)throw new TypeError("`extraLength` must be a number.");return null!==this.#s&&this.slotsSize+t>=this.#s}#m(t,e){if("string"!=typeof t)throw new TypeError("`type` must be a string.");if("object"!=typeof e||null===e)throw new TypeError("`payload` must be an object.");if(this.#i[t])for(const i of this.#i[t])i(e)}off(t,e){if("string"!=typeof t)throw new TypeError("`eventType` must be a string.");if("function"!=typeof e)throw new TypeError("`callback` must be a function.");if(!this.#i[t])return;const i=this.#i[t],r=i.indexOf(e);-1!==r&&i.splice(r,1)}offAll(t){if("string"!=typeof t)throw new TypeError("`eventType` must be a string.");this.#i[t]&&(this.#i[t]=[])}cloneEventCallbacks(t){if("string"!=typeof t)throw new TypeError("`eventType` must be a string.");return this.#i[t]?[...this.#i[t]]:[]}onAddItem(t){if("function"!=typeof t)throw new TypeError("`callback` must be a function.");this.#i.add.push(t)}onSetItem(t){if("function"!=typeof t)throw new TypeError("`callback` must be a function.");this.#i.set.push(t)}onRemoveItem(t){if("function"!=typeof t)throw new TypeError("`callback` must be a function.");this.#i.remove.push(t)}onUseItem(t){if("function"!=typeof t)throw new TypeError("`callback` must be a function.");this.#i.use.push(t)}compactInventory(){this.#r=this.#r.filter((t,e)=>{const i=null!==t;return i||this.#m("remove",{index:e,item:null,isCollection:!0,specialSlot:null,remove:()=>{}}),i})}addItem({itemId:t,quantity:e=1,metadata:r={},forceSpace:o=!1}){if("string"!=typeof t)throw new TypeError("`itemId` must be a string.");if("number"!=typeof e||!Number.isFinite(e)||e<=0)throw new TypeError("`quantity` must be a positive number.");if("object"!=typeof r||null===r)throw new TypeError("`metadata` must be an object.");if("boolean"!=typeof o)throw new TypeError("`forceSpace` must be a boolean.");const n=i.getItem(t);let s=e;const a=n.maxStack<=this.#o?n.maxStack:this.#o,l=[],m=(t,e)=>JSON.stringify(t)===JSON.stringify(e);let u=!0;for(;s>0&&u;){u=!1;for(const e in this.#r){const i=this.#r[e];if(i&&i.id===t&&i.quantity<a&&m(i.metadata,r)){const t=Math.min(a-i.quantity,s);if(!o&&!this.hasSpace({weight:n.weight*t,sizeLength:t}))continue;i.quantity+=t,s-=t,u=!0;const r=Number(e),m=l.findIndex(t=>t.index===r);if(m<0?l.push({index:r,quantity:t}):l[m].quantity+=t,this.#m("add",{item:this.#l(i),index:r,isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:r,forceSpace:o,item:i})}),s<=0)break}}}if(s>0)for(const e in this.#r)if(null===this.#r[e]){const i=Math.min(a,s);if(!o&&!this.hasSpace({weight:n.weight*i,sizeLength:i}))continue;const m={id:t,quantity:i,metadata:r};this.#r[e]=m,s-=i;const u=Number(e),c=l.findIndex(t=>t.index===u);if(c<0?l.push({index:u,quantity:i}):l[c].quantity+=i,this.#m("add",{item:this.#l(m),index:u,isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:u,forceSpace:o,item:m})}),s<=0)break}for(;s>0;){const e=Math.min(a,s);if(!o&&!this.hasSpace({weight:n.weight*e,sizeLength:e,slotsLength:1}))break;const i={id:t,quantity:e,metadata:r};this.#r.push(i);const m=this.#r.length-1,u=l.findIndex(t=>t.index===m);u<0?l.push({index:m,quantity:e}):l[u].quantity+=e,this.#m("add",{item:this.#l(i),index:m,isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:m,forceSpace:o,item:i})}),s-=e}return{remaining:s,placesAdded:l}}getItemFrom(t){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`slotIndex` must be an integer.");if(t<0||t>=this.#r.length)throw new Error(`Slot index '${t}' out of bounds .`);return this.#r[t]?this.#l(this.#r[t]):null}setItem({slotIndex:t,item:e,forceSpace:r=!1}){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`slotIndex` must be an integer.");if("boolean"!=typeof r)throw new TypeError("`forceSpace` must be a boolean.");const o=e&&"object"==typeof e&&"string"==typeof e.id&&"number"==typeof e.quantity&&!Number.isNaN(e.quantity)&&Number.isFinite(e.quantity)&&e.quantity>-1&&"object"==typeof e.metadata;if(null!==e&&!o)throw new Error("Invalid item type: must be null or a valid InventoryItem.");const n=e?i.#t.get(e.id):null;if(null!==e&&!n)throw new Error(`Item '${e?.id??"unknown"}' not defined in registry.`);if(n&&e){const t=n.maxStack<=this.#o?n.maxStack:this.#o;if(e.quantity>t)throw new Error(`Item '${e.id}' exceeds max stack size. Allowed: ${t}, got: ${e.quantity}.`)}if(null!==this.#s&&(t<0||t>=this.#s))throw new Error(`Slot index ${t} out of range.`);const s=this.#r[t]??null,a=s?i.#t.get(s.id)??null:null,l=(t,e)=>e?e.weight*(t?t.quantity:0):0,m=t=>t?t.quantity:0;if(!r&&!this.hasSpace({weight:l(e,n)-l(s,a),sizeLength:m(e)-m(s)}))throw new Error("Inventory is full or overweight.");for(;this.#r.length<=t;)this.#r.push(null);this.#r[t]=e,this._cleanNulls(),this.#m("set",{index:t,isCollection:!0,item:e?this.#l(e):null,specialSlot:null,remove:e?this.#u({locationType:"normal",slotIndex:t,forceSpace:r,item:e}):()=>{}})}deleteItem(t,e=!1){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`slotIndex` must be an integer.");if("boolean"!=typeof e)throw new TypeError("`forceSpace` must be a boolean.");this.setItem({slotIndex:t,item:null,forceSpace:e})}moveItem(t,e,i=!1){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`fromIndex` must be an integer.");if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`toIndex` must be an integer.");if("boolean"!=typeof i)throw new TypeError("`forceSpace` must be a boolean.");const r=this.#r[t];if(!r)throw new Error(`No item found in slot ${t}.`);this.setItem({slotIndex:e,item:r,forceSpace:i}),this.setItem({slotIndex:t,item:null,forceSpace:i})}removeItem({itemId:t,metadata:e=null,quantity:i=1}){if("string"!=typeof t)throw new TypeError("`itemId` must be a string.");if(null!==e&&"object"!=typeof e)throw new TypeError("`metadata` must be an object or null.");if("number"!=typeof i||!Number.isFinite(i)||i<=0)throw new TypeError("`quantity` must be a positive number.");let r=i;const o=(t,e)=>JSON.stringify(t)===JSON.stringify(e);for(let i=0;i<this.#r.length;i++){const n=this.#r[i];if(n&&n.id===t&&(null===e||o(n.metadata,e))){const t=Math.min(n.quantity,r);n.quantity-=t,r-=t;const e=Number(i);if(n.quantity<=0&&(this.#r[i]=null),r<=0)return this._cleanNulls(),this.#m("remove",{index:e,item:this.#l(n),isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:e,item:n})}),!0}}return this._cleanNulls(),this.#e.forEach((i,n)=>{if(r>0&&i.item&&i.item.id===t&&(null===e||o(i.item.metadata,e))){const t=Math.min(i.item.quantity,r);i.item.quantity-=t,i.item.quantity<0&&(i.item.quantity=0),r-=t,i.item.quantity<=0&&(i.item=null),this.#e.set(n,i),this.#m("remove",{index:null,item:i.item?this.#l(i.item):null,isCollection:!1,specialSlot:n,remove:i.item?this.#u({locationType:"special",specialSlot:n,item:i.item}):()=>{}})}}),r<=0}#u({locationType:t,specialSlot:e,slotIndex:i,item:r,forceSpace:o=!1}){if("normal"!==t&&"special"!==t)throw new TypeError("`locationType` must be 'normal' or 'special'.");if("boolean"!=typeof o)throw new TypeError("`forceSpace` must be boolean.");if(!r||"object"!=typeof r)throw new TypeError("`item` must be an InventoryItem object.");if("special"===t&&e&&"string"!=typeof e)throw new TypeError("`specialSlot` must be a string when locationType is 'special'.");if("normal"===t&&"number"!=typeof i)throw new TypeError("`slotIndex` must be a number when locationType is 'normal'.");return(n=o)=>{if("special"===t&&e){const t=this.#e.get(e);if(!t?.item)throw new Error(`Special slot '${e}' is empty.`);t.item.quantity>1?(t.item.quantity-=1,this.#e.set(e,t)):this.setSpecialSlot({slotId:e,item:null,forceSpace:n})}else{if("number"!=typeof i)throw new Error("Invalid remove operation: no valid slotIndex or specialSlot provided.");r.quantity>1?this.setItem({slotIndex:i,item:{...r,quantity:r.quantity-1},forceSpace:n}):this.setItem({slotIndex:i,item:null,forceSpace:n})}}}useItem({slotIndex:t,specialSlot:e,forceSpace:r=!1},...o){if(void 0!==t&&("number"!=typeof t||!Number.isInteger(t)))throw new TypeError("`slotIndex` must be an integer if provided.");if(void 0!==e&&"string"!=typeof e)throw new TypeError("`specialSlot` must be a string if provided.");if("boolean"!=typeof r)throw new TypeError("`forceSpace` must be boolean.");let n=null,s="normal",a=null;if(e){if(!this.#e.has(e))throw new Error(`Special slot '${e}' not found.`);n=this.#e.get(e).item,s="special"}else a=this.#r,n=a[t??-1]??null,s="normal";if(!n)throw new Error("special"===s?`No item found in special slot '${e}'.`:`No item found in slot ${t} of inventory.`);const l=i.getItem(n.id);if(l.onUse){const i={inventory:this,item:this.#l(n),index:t??null,specialSlot:e??null,isCollection:!!a,itemDef:l,remove:this.#u({locationType:s,specialSlot:e,slotIndex:t,forceSpace:r,item:n}),...o},m=l.onUse(i);return this.#m("use",i),m}return null}hasSpecialSlot(t){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");return this.#e.has(t)}getSpecialItem(t){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");if(!this.#e.has(t))throw new Error(`Special slot '${t}' does not exist.`);const e=this.#e.get(t);return e?.item?this.#l(e.item):null}getSpecialSlotType(t){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");if(!this.#e.has(t))throw new Error(`Special slot '${t}' does not exist.`);const e=this.#e.get(t);return e?.type??null}setSpecialSlot({slotId:t,item:e,forceSpace:r=!1}){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");if("boolean"!=typeof r)throw new TypeError("`forceSpace` must be boolean.");if(!this.#e.has(t))throw new Error(`Special slot '${t}' not found.`);const o=e&&"object"==typeof e&&"string"==typeof e.id&&"number"==typeof e.quantity&&!Number.isNaN(e.quantity)&&Number.isFinite(e.quantity)&&e.quantity>-1&&"object"==typeof e.metadata;if(null!==e&&!o)throw new Error("Invalid item type: must be null or a valid InventoryItem.");const n=e?i.#t.get(e.id):null;if(null!==e&&!n)throw new Error(`Item '${e?.id??"unknown"}' not defined in registry.`);const s=this.#e.get(t);if(!s)throw new Error(`Special slot ${t} out of range for slot '${t}'.`);const a=s.item?i.#t.get(s.item.id):null,l=(t,e)=>e?e.weight*(t?1:0):0,m=t=>t?1:0;if(!r&&!this.hasSpace({weight:l(e,n)-l(s.item,a),sizeLength:m(e)-m(s.item)}))throw new Error("Inventory is full or overweight.");s.item=e,this.#m("set",{index:null,item:e?this.#l(e):null,isCollection:!1,specialSlot:t,remove:e?this.#u({locationType:"special",specialSlot:t,forceSpace:r,item:e}):()=>{}})}deleteSpecialItem(t,e=!1){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");if("boolean"!=typeof e)throw new TypeError("`forceSpace` must be boolean.");this.setSpecialSlot({slotId:t,item:null,forceSpace:e})}equipItem({slotId:t,slotIndex:e,quantity:r=1,forceSpace:o=!1}){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`slotIndex` must be an integer.");if("number"!=typeof r||!Number.isFinite(r)||r<=0)throw new TypeError("`quantity` must be a positive number.");if("boolean"!=typeof o)throw new TypeError("`forceSpace` must be boolean.");if(r<=0||!Number.isFinite(r))throw new Error(`Invalid quantity '${r}'.`);if(!this.#e.has(t))throw new Error(`Special slot '${t}' does not exist.`);const n=this.getItemFrom(e);if(!n)throw new Error(`No item found in inventory slot ${e}.`);if(n.quantity<r)throw new Error(`Not enough quantity of item '${n.id}' in inventory slot.`);const s=i.getItem(n.id),a=this.#e.get(t);if(!a)throw new Error(`Slot '${t}' not defined in registry.`);const l=a.type??null;if(null!==l&&s.type!==l)throw new Error(`Item '${n.id}' cannot be equipped in slot '${t}'.`);const m=Math.min(s.maxStack,this.#o);if(a.item&&a.item.id===n.id){const e=Math.max(0,m-a.item.quantity);if(e<=0)return r;const i=Math.min(r,e);return this.removeItem({itemId:n.id,quantity:i,metadata:null}),a.item.quantity+=i,this.#e.set(t,a),r-i}a.item&&this.unequipItem({slotId:t,forceSpace:o});const u=Math.min(r,m);return this.removeItem({itemId:n.id,quantity:u,metadata:null}),a.item={id:n.id,quantity:u,metadata:n.metadata},this.#e.set(t,a),r-u}unequipItem({slotId:t,quantity:e=null,forceSpace:i=!1}){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");if(null!==e&&("number"!=typeof e||!Number.isFinite(e)||e<=0))throw new TypeError("`quantity` must be a positive number or null.");if("boolean"!=typeof i)throw new TypeError("`forceSpace` must be boolean.");if(!this.#e.has(t))throw new Error(`Special slot '${t}' does not exist.`);const r=this.#e.get(t);if(!r)throw new Error(`Slot '${t}' not defined in registry.`);if(!r.item)return!1;const o=r.item,n=null===e?o.quantity:e;if(n<=0)throw new Error(`Invalid unequip quantity: ${n}`);if(n>o.quantity)throw new Error(`Not enough items in slot '${t}' to unequip.`);return this.addItem({itemId:o.id,quantity:n,metadata:o.metadata,forceSpace:i}),n===o.quantity?r.item=null:(o.quantity-=n,r.item=o),this.#e.set(t,r),!0}#l(t){if(!t||"object"!=typeof t)throw new TypeError("`item` must be an InventoryItem object.");if("string"!=typeof t.id)throw new TypeError("`item.id` must be a string.");if("number"!=typeof t.quantity||!Number.isFinite(t.quantity))throw new TypeError("`item.quantity` must be a finite number.");if(!t.metadata||"object"!=typeof t.metadata)throw new TypeError("`item.metadata` must be an object.");return{id:t.id,quantity:t.quantity,metadata:{...t.metadata}}}getItemList(){return[...this.#r].map((t,e)=>[t?this.#l(t):null,e]).filter(t=>null!==t[0])}getAllItems(){const t=[...this.#r].filter(t=>null!==t).map(this.#l);return this.#e.forEach(e=>{const i=e.item;i&&t.push(i)}),t}getItemsByMetadata(t){if("function"!=typeof t)throw new TypeError("`filterFn` must be a function.");return this.getAllItems().filter(e=>{const r=i.getItem(e.id);return t(r.metadata,e)})}findItem(t){if("function"!=typeof t)throw new TypeError("`predicate` must be a function.");return this.getAllItems().find(t)}findItems(t){if("function"!=typeof t)throw new TypeError("`predicate` must be a function.");return this.getAllItems().filter(t)}getItemCount(t){if("string"!=typeof t)throw new TypeError("`itemId` must be a string.");return this.getAllItems().filter(e=>e.id===t).reduce((t,e)=>t+e.quantity,0)}hasItem(t,e=1){if("string"!=typeof t)throw new TypeError("`itemId` must be a string.");if("number"!=typeof e||!Number.isFinite(e)||e<0)throw new TypeError("`quantity` must be a non-negative number.");return this.getItemCount(t)>=e}existsItemAt(t){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`slotIndex` must be an integer.");return!!this.#r[t]}clear(){this.clearAllItems(),this.clearAllEvents()}clearAllEvents(){this.#i={add:[],remove:[],use:[],set:[]}}clearAllItems(){this.clearItems(),this.clearSpecialItems()}clearItems(){for(let t=this.#r.length-1;t>=0;t--)this.#r[t]&&this.deleteItem(t,!0)}clearSpecialItems(){for(const t of this.#e.keys()){const e=this.#e.get(t);e?.item&&this.deleteSpecialItem(t,!0)}}clone(){const t=this.toObject();return i.fromObject(t)}toObject(){const t={};for(const[e,i]of this.#e.entries())t[e]={type:i?.type??null,item:i?.item?this.#l(i.item):null};return{__schema:"TinyInventory",version:1,maxWeight:this.#a,maxSlots:this.#s,maxSize:this.#n,maxStack:this.#o,items:this.#r.map(t=>t?this.#l(t):null),specialSlots:t}}toJSON(t=0){if("number"!=typeof t||!Number.isFinite(t)||t<0)throw new TypeError("`space` must be a non-negative number.");return JSON.stringify(this.toObject(),null,t)}static fromObject(t){if(!t||"object"!=typeof t)throw new TypeError("Invalid state: expected object.");if("TinyInventory"!==t.__schema||"number"!=typeof t.version)throw new TypeError("Invalid or missing schema header.");if(1!==t.version)throw new TypeError(`Unsupported TinyInventory state version: ${t.version}`);const e={};if(t.specialSlots&&"object"==typeof t.specialSlots)for(const i of Object.keys(t.specialSlots))e[i]={type:t.specialSlots[i]?.type??null};const r=new i({maxWeight:t.maxWeight??null,maxSlots:t.maxSlots??null,maxSize:t.maxSize??null,maxStack:t.maxStack??null,specialSlots:e});if(Array.isArray(t.items))for(const e in t.items){const i=t.items[e];if(null!==i){const t={id:String(i.id),quantity:Math.max(1,Number(i.quantity)||1),metadata:i.metadata&&"object"==typeof i.metadata?i.metadata:{}};r.setItem({slotIndex:Number(e),item:t,forceSpace:!0})}else r.setItem({slotIndex:Number(e),item:null,forceSpace:!0})}if(t.specialSlots&&"object"==typeof t.specialSlots)for(const[e,i]of Object.entries(t.specialSlots)){if(!r.hasSpecialSlot(e))continue;const t=i?.item;if(t&&t.id){const i={id:String(t.id),quantity:Math.max(1,Number(t.quantity)||1),metadata:t.metadata&&"object"==typeof t.metadata?t.metadata:{}};r.setSpecialSlot({slotId:e,item:i,forceSpace:!0})}}return r}static fromJSON(t){if("string"!=typeof t)throw new TypeError("`json` must be a string.");const e=JSON.parse(t);return i.fromObject(e)}}const r=i;window.TinyInventory=e.TinyInventory})();
|
|
1
|
+
(()=>{"use strict";const t={d:(e,i)=>{for(var r in i)t.o(i,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:i[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)};let e={};t.d(e,{TinyInventory:()=>r});class i{static#t=new Map;static get itemRegistry(){const t={},e=Object.fromEntries(i.#t);for(const i in e)t[i]={...e[i],metadata:{...e[i].metadata}};return t}static defineItem(t){if(!t||"object"!=typeof t)throw new TypeError("Config must be a valid object.");if(!t.id||"string"!=typeof t.id)throw new TypeError("Item must have a valid string 'id'.");if(void 0!==t.weight&&("number"!=typeof t.weight||t.weight<0))throw new TypeError(`weight must be a number >= 0. Received: ${t.weight}`);if(void 0!==t.maxStack&&(!Number.isInteger(t.maxStack)||t.maxStack<=0))throw new TypeError(`maxStack must be a positive integer. Received: ${t.maxStack}`);if(void 0!==t.metadata&&"object"!=typeof t.metadata)throw new TypeError("metadata must be an object.");if(void 0!==t.onUse&&null!==t.onUse&&"function"!=typeof t.onUse)throw new TypeError("onUse must be a function or null.");if(void 0!==t.type&&null!==t.type&&"string"!=typeof t.type)throw new TypeError("type must be a string or null.");i.#t.set(t.id,{id:t.id,weight:t.weight||0,maxStack:t.maxStack||1,metadata:t.metadata||{},type:t.type??null,onUse:"function"==typeof t.onUse?t.onUse:null})}static removeItem(t){if("string"!=typeof t)throw new TypeError("itemId must be a string.");return i.#t.delete(t)}static hasItem(t){if("string"!=typeof t)throw new TypeError("itemId must be a string.");return i.#t.has(t)}static getItem(t){if("string"!=typeof t)throw new TypeError("itemId must be a string.");const e=i.#t.get(t);if(!e)throw new Error(`Item '${t}' not defined in registry.`);return e}#e=new Map;#i={add:[],remove:[],use:[],set:[]};#r=[];#o;#n;#s;#a;get maxStack(){return this.#o}set maxStack(t){if(!Number.isInteger(t)||Number.isFinite(t)&&t<=0)throw new TypeError(`maxStack must be a positive integer. Received: ${t}`);this.#o=t}get maxSize(){return this.#n}set maxSize(t){if(null!==t&&(!Number.isInteger(t)||t<=0))throw new TypeError(`maxSize must be null or a positive integer. Received: ${t}`);this.#n=t}get maxSlots(){return this.#s}set maxSlots(t){if(null!==t&&(!Number.isInteger(t)||t<=0))throw new TypeError(`maxSlots must be null or a positive integer. Received: ${t}`);this.#s=t}get maxWeight(){return this.#a}set maxWeight(t){if(null!==t&&("number"!=typeof t||t<=0))throw new TypeError(`maxWeight must be null or a positive number. Received: ${t}`);this.#a=t}get events(){return{add:[...this.#i.add],remove:[...this.#i.remove],use:[...this.#i.use],set:[...this.#i.set]}}get items(){return[...this.#r].map(t=>t?this.#l(t):null)}get specialSlots(){return new Map([...this.#e.entries()].map(([t,e])=>[t,{type:e.type,item:e.item?this.#l(e.item):null}]))}get size(){const t=this.getAllItems();let e=0;for(const i of t)e+=i.quantity;return e}get slotsSize(){return this.getAllItems().length}get weight(){return this.getAllItems().reduce((t,e)=>{const r=i.getItem(e.id);return t+(r?.weight||0)*e.quantity},0)}_cleanNulls(){let t=this.#r.length-1;for(;t>=0&&null===this.#r[t];)t--;this.#r=this.#r.slice(0,t+1)}constructor(t={}){if("object"!=typeof t||null===t)throw new TypeError("`options` must be an object.");if(void 0!==t.maxWeight&&null!==t.maxWeight&&"number"!=typeof t.maxWeight)throw new TypeError("`maxWeight` must be a number or null.");if(void 0!==t.maxSlots&&null!==t.maxSlots&&"number"!=typeof t.maxSlots)throw new TypeError("`maxSlots` must be a number or null.");if(void 0!==t.maxSize&&null!==t.maxSize&&"number"!=typeof t.maxSize)throw new TypeError("`maxSize` must be a number or null.");if(void 0!==t.maxStack&&"number"!=typeof t.maxStack)throw new TypeError("`maxStack` must be a number.");if(void 0!==t.specialSlots&&"object"!=typeof t.specialSlots)throw new TypeError("`specialSlots` must be an object if defined.");if(this.#a=t.maxWeight??null,this.#s=t.maxSlots??null,this.#n=t.maxSize??null,this.#o=t.maxStack??1/0,t.specialSlots)for(const e in t.specialSlots){const i=t.specialSlots[e];if("object"!=typeof i||null===i)throw new TypeError("Each `specialSlot` entry must be an object.");if(void 0!==i.type&&null!==i.type&&"string"!=typeof i.type)throw new TypeError("`specialSlot.type` must be a string or null.");this.#e.set(e,{type:i.type??null,item:null})}}hasSpace({weight:t=0,sizeLength:e=0,slotsLength:i=0}={}){if("number"!=typeof t)throw new TypeError("`weight` must be a number.");if("number"!=typeof e)throw new TypeError("`sizeLength` must be a number.");if("number"!=typeof i)throw new TypeError("`slotsLength` must be a number.");return!(this.areFull(e)||this.areFullSlots(i)||this.isHeavy(t))}isHeavy(t=0){if("number"!=typeof t)throw new TypeError("`extraWeight` must be a number.");return null!==this.#a&&this.weight+t>this.#a}areFull(t=0){if("number"!=typeof t)throw new TypeError("`extraLength` must be a number.");return null!==this.#n&&this.size+t>this.#n}isFull(t=0){if("number"!=typeof t)throw new TypeError("`extraLength` must be a number.");return null!==this.#n&&this.size+t>=this.#n}areFullSlots(t=0){if("number"!=typeof t)throw new TypeError("`extraLength` must be a number.");return null!==this.#s&&this.slotsSize+t>this.#s}isFullSlots(t=0){if("number"!=typeof t)throw new TypeError("`extraLength` must be a number.");return null!==this.#s&&this.slotsSize+t>=this.#s}#m(t,e){if("string"!=typeof t)throw new TypeError("`type` must be a string.");if("object"!=typeof e||null===e)throw new TypeError("`payload` must be an object.");if(this.#i[t])for(const i of this.#i[t])i(e)}off(t,e){if("string"!=typeof t)throw new TypeError("`eventType` must be a string.");if("function"!=typeof e)throw new TypeError("`callback` must be a function.");if(!this.#i[t])return;const i=this.#i[t],r=i.indexOf(e);-1!==r&&i.splice(r,1)}offAll(t){if("string"!=typeof t)throw new TypeError("`eventType` must be a string.");this.#i[t]&&(this.#i[t]=[])}cloneEventCallbacks(t){if("string"!=typeof t)throw new TypeError("`eventType` must be a string.");return this.#i[t]?[...this.#i[t]]:[]}onAddItem(t){if("function"!=typeof t)throw new TypeError("`callback` must be a function.");this.#i.add.push(t)}onSetItem(t){if("function"!=typeof t)throw new TypeError("`callback` must be a function.");this.#i.set.push(t)}onRemoveItem(t){if("function"!=typeof t)throw new TypeError("`callback` must be a function.");this.#i.remove.push(t)}onUseItem(t){if("function"!=typeof t)throw new TypeError("`callback` must be a function.");this.#i.use.push(t)}compactInventory(){this.#r=this.#r.filter((t,e)=>{const i=null!==t;return i||this.#m("remove",{index:e,item:null,isCollection:!0,specialSlot:null,remove:()=>{}}),i})}addItem({itemId:t,quantity:e=1,metadata:r={},forceSpace:o=!1}){if("string"!=typeof t)throw new TypeError("`itemId` must be a string.");if("number"!=typeof e||!Number.isFinite(e)||e<=0)throw new TypeError("`quantity` must be a positive number.");if("object"!=typeof r||null===r)throw new TypeError("`metadata` must be an object.");if("boolean"!=typeof o)throw new TypeError("`forceSpace` must be a boolean.");const n=i.getItem(t);let s=e;const a=n.maxStack<=this.#o?n.maxStack:this.#o,l=[],m=(t,e)=>JSON.stringify(t)===JSON.stringify(e);let u=!0;for(;s>0&&u;){u=!1;for(const e in this.#r){const i=this.#r[e];if(i&&i.id===t&&i.quantity<a&&m(i.metadata,r)){const t=Math.min(a-i.quantity,s);if(!o&&!this.hasSpace({weight:n.weight*t,sizeLength:t}))continue;i.quantity+=t,s-=t,u=!0;const r=Number(e),m=l.findIndex(t=>t.index===r);if(m<0?l.push({index:r,quantity:t}):l[m].quantity+=t,this.#m("add",{item:this.#l(i),index:r,isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:r,forceSpace:o,item:i})}),s<=0)break}}}if(s>0)for(const e in this.#r)if(null===this.#r[e]){const i=Math.min(a,s);if(!o&&!this.hasSpace({weight:n.weight*i,sizeLength:i}))continue;const m={id:t,quantity:i,metadata:r};this.#r[e]=m,s-=i;const u=Number(e),c=l.findIndex(t=>t.index===u);if(c<0?l.push({index:u,quantity:i}):l[c].quantity+=i,this.#m("add",{item:this.#l(m),index:u,isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:u,forceSpace:o,item:m})}),s<=0)break}for(;s>0;){const e=Math.min(a,s);if(!o&&!this.hasSpace({weight:n.weight*e,sizeLength:e,slotsLength:1}))break;const i={id:t,quantity:e,metadata:r};this.#r.push(i);const m=this.#r.length-1,u=l.findIndex(t=>t.index===m);u<0?l.push({index:m,quantity:e}):l[u].quantity+=e,this.#m("add",{item:this.#l(i),index:m,isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:m,forceSpace:o,item:i})}),s-=e}return{remaining:s,placesAdded:l}}getItemFrom(t){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`slotIndex` must be an integer.");if(t<0||t>=this.#r.length)throw new Error(`Slot index '${t}' out of bounds .`);return this.#r[t]?this.#l(this.#r[t]):null}setItem({slotIndex:t,item:e,forceSpace:r=!1}){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`slotIndex` must be an integer.");if("boolean"!=typeof r)throw new TypeError("`forceSpace` must be a boolean.");const o=e&&"object"==typeof e&&"string"==typeof e.id&&"number"==typeof e.quantity&&!Number.isNaN(e.quantity)&&Number.isFinite(e.quantity)&&e.quantity>-1&&"object"==typeof e.metadata;if(null!==e&&!o)throw new Error("Invalid item type: must be null or a valid InventoryItem.");const n=e?i.#t.get(e.id):null;if(null!==e&&!n)throw new Error(`Item '${e?.id??"unknown"}' not defined in registry.`);if(n&&e){const t=n.maxStack<=this.#o?n.maxStack:this.#o;if(e.quantity>t)throw new Error(`Item '${e.id}' exceeds max stack size. Allowed: ${t}, got: ${e.quantity}.`)}if(null!==this.#s&&(t<0||t>=this.#s))throw new Error(`Slot index ${t} out of range.`);const s=this.#r[t]??null,a=s?i.#t.get(s.id)??null:null,l=(t,e)=>e?e.weight*(t?t.quantity:0):0,m=t=>t?t.quantity:0;if(!r&&!this.hasSpace({weight:l(e,n)-l(s,a),sizeLength:m(e)-m(s)}))throw new Error("Inventory is full or overweight.");for(;this.#r.length<=t;)this.#r.push(null);this.#r[t]=e,this._cleanNulls(),this.#m("set",{index:t,isCollection:!0,item:e?this.#l(e):null,specialSlot:null,remove:e?this.#u({locationType:"normal",slotIndex:t,forceSpace:r,item:e}):()=>{}})}deleteItem(t,e=!1){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`slotIndex` must be an integer.");if("boolean"!=typeof e)throw new TypeError("`forceSpace` must be a boolean.");this.setItem({slotIndex:t,item:null,forceSpace:e})}moveItem(t,e,i=!1){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`fromIndex` must be an integer.");if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`toIndex` must be an integer.");if("boolean"!=typeof i)throw new TypeError("`forceSpace` must be a boolean.");const r=this.#r[t];if(!r)throw new Error(`No item found in slot ${t}.`);this.setItem({slotIndex:e,item:r,forceSpace:i}),this.setItem({slotIndex:t,item:null,forceSpace:i})}removeItem({itemId:t,metadata:e=null,quantity:i=1}){if("string"!=typeof t)throw new TypeError("`itemId` must be a string.");if(null!==e&&"object"!=typeof e)throw new TypeError("`metadata` must be an object or null.");if("number"!=typeof i||!Number.isFinite(i)||i<=0)throw new TypeError("`quantity` must be a positive number.");let r=i;const o=(t,e)=>JSON.stringify(t)===JSON.stringify(e);for(let i=0;i<this.#r.length;i++){const n=this.#r[i];if(n&&n.id===t&&(null===e||o(n.metadata,e))){const t=Math.min(n.quantity,r);n.quantity-=t,r-=t;const e=Number(i);if(n.quantity<=0&&(this.#r[i]=null),r<=0)return this._cleanNulls(),this.#m("remove",{index:e,item:this.#l(n),isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:e,item:n})}),!0}}return this._cleanNulls(),this.#e.forEach((i,n)=>{if(r>0&&i.item&&i.item.id===t&&(null===e||o(i.item.metadata,e))){const t=Math.min(i.item.quantity,r);i.item.quantity-=t,i.item.quantity<0&&(i.item.quantity=0),r-=t,i.item.quantity<=0&&(i.item=null),this.#e.set(n,i),this.#m("remove",{index:null,item:i.item?this.#l(i.item):null,isCollection:!1,specialSlot:n,remove:i.item?this.#u({locationType:"special",specialSlot:n,item:i.item}):()=>{}})}}),r<=0}#u({locationType:t,specialSlot:e,slotIndex:i,item:r,forceSpace:o=!1}){if("normal"!==t&&"special"!==t)throw new TypeError("`locationType` must be 'normal' or 'special'.");if("boolean"!=typeof o)throw new TypeError("`forceSpace` must be boolean.");if(!r||"object"!=typeof r)throw new TypeError("`item` must be an InventoryItem object.");if("special"===t&&e&&"string"!=typeof e)throw new TypeError("`specialSlot` must be a string when locationType is 'special'.");if("normal"===t&&"number"!=typeof i)throw new TypeError("`slotIndex` must be a number when locationType is 'normal'.");return(n=o)=>{if("special"===t&&e){const t=this.#e.get(e);if(!t?.item)throw new Error(`Special slot '${e}' is empty.`);t.item.quantity>1?(t.item.quantity-=1,this.#e.set(e,t)):this.setSpecialSlot({slotId:e,item:null,forceSpace:n})}else{if("number"!=typeof i)throw new Error("Invalid remove operation: no valid slotIndex or specialSlot provided.");r.quantity>1?this.setItem({slotIndex:i,item:{...r,quantity:r.quantity-1},forceSpace:n}):this.setItem({slotIndex:i,item:null,forceSpace:n})}}}useItem({slotIndex:t,specialSlot:e,forceSpace:r=!1},...o){if(void 0!==t&&("number"!=typeof t||!Number.isInteger(t)))throw new TypeError("`slotIndex` must be an integer if provided.");if(void 0!==e&&"string"!=typeof e)throw new TypeError("`specialSlot` must be a string if provided.");if("boolean"!=typeof r)throw new TypeError("`forceSpace` must be boolean.");let n=null,s="normal",a=null;if(e){if(!this.#e.has(e))throw new Error(`Special slot '${e}' not found.`);n=this.#e.get(e).item,s="special"}else a=this.#r,n=a[t??-1]??null,s="normal";if(!n)throw new Error("special"===s?`No item found in special slot '${e}'.`:`No item found in slot ${t} of inventory.`);const l=i.getItem(n.id);if(l.onUse){const i={inventory:this,item:this.#l(n),index:t??null,specialSlot:e??null,isCollection:!!a,itemDef:l,remove:this.#u({locationType:s,specialSlot:e,slotIndex:t,forceSpace:r,item:n}),...o},m=l.onUse(i);return this.#m("use",i),m}return null}hasSpecialSlot(t){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");return this.#e.has(t)}getSpecialItem(t){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");if(!this.#e.has(t))throw new Error(`Special slot '${t}' does not exist.`);const e=this.#e.get(t);return e?.item?this.#l(e.item):null}getSpecialSlotType(t){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");if(!this.#e.has(t))throw new Error(`Special slot '${t}' does not exist.`);const e=this.#e.get(t);return e?.type??null}setSpecialSlot({slotId:t,item:e,forceSpace:r=!1}){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");if("boolean"!=typeof r)throw new TypeError("`forceSpace` must be boolean.");if(!this.#e.has(t))throw new Error(`Special slot '${t}' not found.`);const o=e&&"object"==typeof e&&"string"==typeof e.id&&"number"==typeof e.quantity&&!Number.isNaN(e.quantity)&&Number.isFinite(e.quantity)&&e.quantity>-1&&"object"==typeof e.metadata;if(null!==e&&!o)throw new Error("Invalid item type: must be null or a valid InventoryItem.");const n=e?i.#t.get(e.id):null;if(null!==e&&!n)throw new Error(`Item '${e?.id??"unknown"}' not defined in registry.`);const s=this.#e.get(t);if(!s)throw new Error(`Special slot ${t} out of range for slot '${t}'.`);const a=s.item?i.#t.get(s.item.id):null,l=(t,e)=>e?e.weight*(t?1:0):0,m=t=>t?1:0;if(!r&&!this.hasSpace({weight:l(e,n)-l(s.item,a),sizeLength:m(e)-m(s.item)}))throw new Error("Inventory is full or overweight.");s.item=e,this.#m("set",{index:null,item:e?this.#l(e):null,isCollection:!1,specialSlot:t,remove:e?this.#u({locationType:"special",specialSlot:t,forceSpace:r,item:e}):()=>{}})}deleteSpecialItem(t,e=!1){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");if("boolean"!=typeof e)throw new TypeError("`forceSpace` must be boolean.");this.setSpecialSlot({slotId:t,item:null,forceSpace:e})}equipItem({slotId:t,slotIndex:e,quantity:r=1,forceSpace:o=!1}){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`slotIndex` must be an integer.");if("number"!=typeof r||!Number.isFinite(r)||r<=0)throw new TypeError("`quantity` must be a positive number.");if("boolean"!=typeof o)throw new TypeError("`forceSpace` must be boolean.");if(r<=0||!Number.isFinite(r))throw new Error(`Invalid quantity '${r}'.`);if(!this.#e.has(t))throw new Error(`Special slot '${t}' does not exist.`);const n=this.getItemFrom(e);if(!n)throw new Error(`No item found in inventory slot ${e}.`);if(n.quantity<r)throw new Error(`Not enough quantity of item '${n.id}' in inventory slot.`);const s=i.getItem(n.id),a=this.#e.get(t);if(!a)throw new Error(`Slot '${t}' not defined in registry.`);const l=a.type??null;if(null!==l&&s.type!==l)throw new Error(`Item '${n.id}' cannot be equipped in slot '${t}'.`);const m=Math.min(s.maxStack,this.#o);if(a.item&&a.item.id===n.id){const e=Math.max(0,m-a.item.quantity);if(e<=0)return r;const i=Math.min(r,e);return this.removeItem({itemId:n.id,quantity:i,metadata:null}),a.item.quantity+=i,this.#e.set(t,a),r-i}a.item&&this.unequipItem({slotId:t,forceSpace:o});const u=Math.min(r,m);return this.removeItem({itemId:n.id,quantity:u,metadata:null}),a.item={id:n.id,quantity:u,metadata:n.metadata},this.#e.set(t,a),r-u}unequipItem({slotId:t,quantity:e=null,forceSpace:i=!1}){if("string"!=typeof t)throw new TypeError("`slotId` must be a string.");if(null!==e&&("number"!=typeof e||!Number.isFinite(e)||e<=0))throw new TypeError("`quantity` must be a positive number or null.");if("boolean"!=typeof i)throw new TypeError("`forceSpace` must be boolean.");if(!this.#e.has(t))throw new Error(`Special slot '${t}' does not exist.`);const r=this.#e.get(t);if(!r)throw new Error(`Slot '${t}' not defined in registry.`);if(!r.item)return!1;const o=r.item,n=null===e?o.quantity:e;if(n<=0)throw new Error(`Invalid unequip quantity: ${n}`);if(n>o.quantity)throw new Error(`Not enough items in slot '${t}' to unequip.`);return this.addItem({itemId:o.id,quantity:n,metadata:o.metadata,forceSpace:i}),n===o.quantity?r.item=null:(o.quantity-=n,r.item=o),this.#e.set(t,r),!0}#l(t){if(!t||"object"!=typeof t)throw new TypeError("`item` must be an InventoryItem object.");if("string"!=typeof t.id)throw new TypeError("`item.id` must be a string.");if("number"!=typeof t.quantity||!Number.isFinite(t.quantity))throw new TypeError("`item.quantity` must be a finite number.");if(!t.metadata||"object"!=typeof t.metadata)throw new TypeError("`item.metadata` must be an object.");return{id:t.id,quantity:t.quantity,metadata:{...t.metadata}}}getItemList(){return[...this.#r].map((t,e)=>[t?this.#l(t):null,e]).filter(t=>null!==t[0])}getAllItems(){const t=[...this.#r].filter(t=>null!==t).map(this.#l);return this.#e.forEach(e=>{const i=e.item;i&&t.push(i)}),t}getItemsByMetadata(t){if("function"!=typeof t)throw new TypeError("`filterFn` must be a function.");return this.getAllItems().filter(e=>{const r=i.getItem(e.id);return t(r.metadata,e)})}findItem(t){if("function"!=typeof t)throw new TypeError("`predicate` must be a function.");return this.getAllItems().find(t)}findItems(t){if("function"!=typeof t)throw new TypeError("`predicate` must be a function.");return this.getAllItems().filter(t)}getItemCount(t){if("string"!=typeof t)throw new TypeError("`itemId` must be a string.");return this.getAllItems().filter(e=>e.id===t).reduce((t,e)=>t+e.quantity,0)}hasItem(t,e=1){if("string"!=typeof t)throw new TypeError("`itemId` must be a string.");if("number"!=typeof e||!Number.isFinite(e)||e<0)throw new TypeError("`quantity` must be a non-negative number.");return this.getItemCount(t)>=e}existsItemAt(t){if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`slotIndex` must be an integer.");return!!this.#r[t]}clear(){this.clearAllItems(),this.clearAllEvents()}clearAllEvents(){this.#i={add:[],remove:[],use:[],set:[]}}clearAllItems(){this.clearItems(),this.clearSpecialItems()}clearItems(){for(let t=this.#r.length-1;t>=0;t--)this.#r[t]&&this.deleteItem(t,!0)}clearSpecialItems(){for(const t of this.#e.keys()){const e=this.#e.get(t);e?.item&&this.deleteSpecialItem(t,!0)}}clone(){const t=this.toObject();return i.fromObject(t)}toObject(){const t={};for(const[e,i]of this.#e.entries())t[e]={type:i?.type??null,item:i?.item?this.#l(i.item):null};return{__schema:"TinyInventory",version:1,maxWeight:this.#a,maxSlots:this.#s,maxSize:this.#n,maxStack:this.#o,items:this.#r.map(t=>t?this.#l(t):null),specialSlots:t}}toJSON(t=0){if("number"!=typeof t||!Number.isFinite(t)||t<0)throw new TypeError("`space` must be a non-negative number.");return JSON.stringify(this.toObject(),null,t)}static fromObject(t){if(!t||"object"!=typeof t)throw new TypeError("Invalid state: expected object.");if("TinyInventory"!==t.__schema||"number"!=typeof t.version)throw new TypeError("Invalid or missing schema header.");if(1!==t.version)throw new TypeError(`Unsupported TinyInventory state version: ${t.version}`);const e={};if(t.specialSlots&&"object"==typeof t.specialSlots)for(const i of Object.keys(t.specialSlots))e[i]={type:t.specialSlots[i]?.type??null};const r=new i({maxWeight:t.maxWeight??null,maxSlots:t.maxSlots??null,maxSize:t.maxSize??null,maxStack:t.maxStack??null,specialSlots:e});if(Array.isArray(t.items))for(const e in t.items){const i=t.items[e];if(null!==i){const t={id:String(i.id),quantity:Math.max(1,Number(i.quantity)||1),metadata:i.metadata&&"object"==typeof i.metadata?i.metadata:{}};r.setItem({slotIndex:Number(e),item:t,forceSpace:!0})}else r.setItem({slotIndex:Number(e),item:null,forceSpace:!0})}if(t.specialSlots&&"object"==typeof t.specialSlots)for(const[e,i]of Object.entries(t.specialSlots)){if(!r.hasSpecialSlot(e))continue;const t=i?.item;if(t&&t.id){const i={id:String(t.id),quantity:Math.max(1,Number(t.quantity)||1),metadata:t.metadata&&"object"==typeof t.metadata?t.metadata:{}};r.setSpecialSlot({slotId:e,item:i,forceSpace:!0})}}return r}static fromJSON(t){if("string"!=typeof t)throw new TypeError("`json` must be a string.");const e=JSON.parse(t);return i.fromObject(e)}}const r=i;window.TinyInventory=e.TinyInventory})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";const e={d:(t,i)=>{if(Array.isArray(i))for(var r=0;r<i.length;){var n=i[r++],o=i[r++];e.o(t,n)?0===o&&r++:0===o?Object.defineProperty(t,n,{enumerable:!0,value:i[r++]}):Object.defineProperty(t,n,{enumerable:!0,get:o})}else for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};e.d(t,{TinyInventoryTrader:()=>n});class i{static#e=new Map;static get itemRegistry(){const e={},t=Object.fromEntries(i.#e);for(const i in t)e[i]={...t[i],metadata:{...t[i].metadata}};return e}static defineItem(e){if(!e||"object"!=typeof e)throw new TypeError("Config must be a valid object.");if(!e.id||"string"!=typeof e.id)throw new TypeError("Item must have a valid string 'id'.");if(void 0!==e.weight&&("number"!=typeof e.weight||e.weight<0))throw new TypeError(`weight must be a number >= 0. Received: ${e.weight}`);if(void 0!==e.maxStack&&(!Number.isInteger(e.maxStack)||e.maxStack<=0))throw new TypeError(`maxStack must be a positive integer. Received: ${e.maxStack}`);if(void 0!==e.metadata&&"object"!=typeof e.metadata)throw new TypeError("metadata must be an object.");if(void 0!==e.onUse&&null!==e.onUse&&"function"!=typeof e.onUse)throw new TypeError("onUse must be a function or null.");if(void 0!==e.type&&null!==e.type&&"string"!=typeof e.type)throw new TypeError("type must be a string or null.");i.#e.set(e.id,{id:e.id,weight:e.weight||0,maxStack:e.maxStack||1,metadata:e.metadata||{},type:e.type??null,onUse:"function"==typeof e.onUse?e.onUse:null})}static removeItem(e){if("string"!=typeof e)throw new TypeError("itemId must be a string.");return i.#e.delete(e)}static hasItem(e){if("string"!=typeof e)throw new TypeError("itemId must be a string.");return i.#e.has(e)}static getItem(e){if("string"!=typeof e)throw new TypeError("itemId must be a string.");const t=i.#e.get(e);if(!t)throw new Error(`Item '${e}' not defined in registry.`);return t}#t=new Map;#i={add:[],remove:[],use:[],set:[]};#r=[];#n;#o;#s;#a;get maxStack(){return this.#n}set maxStack(e){if(!Number.isInteger(e)||Number.isFinite(e)&&e<=0)throw new TypeError(`maxStack must be a positive integer. Received: ${e}`);this.#n=e}get maxSize(){return this.#o}set maxSize(e){if(null!==e&&(!Number.isInteger(e)||e<=0))throw new TypeError(`maxSize must be null or a positive integer. Received: ${e}`);this.#o=e}get maxSlots(){return this.#s}set maxSlots(e){if(null!==e&&(!Number.isInteger(e)||e<=0))throw new TypeError(`maxSlots must be null or a positive integer. Received: ${e}`);this.#s=e}get maxWeight(){return this.#a}set maxWeight(e){if(null!==e&&("number"!=typeof e||e<=0))throw new TypeError(`maxWeight must be null or a positive number. Received: ${e}`);this.#a=e}get events(){return{add:[...this.#i.add],remove:[...this.#i.remove],use:[...this.#i.use],set:[...this.#i.set]}}get items(){return[...this.#r].map(e=>e?this.#l(e):null)}get specialSlots(){return new Map([...this.#t.entries()].map(([e,t])=>[e,{type:t.type,item:t.item?this.#l(t.item):null}]))}get size(){const e=this.getAllItems();let t=0;for(const i of e)t+=i.quantity;return t}get slotsSize(){return this.getAllItems().length}get weight(){return this.getAllItems().reduce((e,t)=>{const r=i.getItem(t.id);return e+(r?.weight||0)*t.quantity},0)}_cleanNulls(){let e=this.#r.length-1;for(;e>=0&&null===this.#r[e];)e--;this.#r=this.#r.slice(0,e+1)}constructor(e={}){if("object"!=typeof e||null===e)throw new TypeError("`options` must be an object.");if(void 0!==e.maxWeight&&null!==e.maxWeight&&"number"!=typeof e.maxWeight)throw new TypeError("`maxWeight` must be a number or null.");if(void 0!==e.maxSlots&&null!==e.maxSlots&&"number"!=typeof e.maxSlots)throw new TypeError("`maxSlots` must be a number or null.");if(void 0!==e.maxSize&&null!==e.maxSize&&"number"!=typeof e.maxSize)throw new TypeError("`maxSize` must be a number or null.");if(void 0!==e.maxStack&&"number"!=typeof e.maxStack)throw new TypeError("`maxStack` must be a number.");if(void 0!==e.specialSlots&&"object"!=typeof e.specialSlots)throw new TypeError("`specialSlots` must be an object if defined.");if(this.#a=e.maxWeight??null,this.#s=e.maxSlots??null,this.#o=e.maxSize??null,this.#n=e.maxStack??1/0,e.specialSlots)for(const t in e.specialSlots){const i=e.specialSlots[t];if("object"!=typeof i||null===i)throw new TypeError("Each `specialSlot` entry must be an object.");if(void 0!==i.type&&null!==i.type&&"string"!=typeof i.type)throw new TypeError("`specialSlot.type` must be a string or null.");this.#t.set(t,{type:i.type??null,item:null})}}hasSpace({weight:e=0,sizeLength:t=0,slotsLength:i=0}={}){if("number"!=typeof e)throw new TypeError("`weight` must be a number.");if("number"!=typeof t)throw new TypeError("`sizeLength` must be a number.");if("number"!=typeof i)throw new TypeError("`slotsLength` must be a number.");return!(this.areFull(t)||this.areFullSlots(i)||this.isHeavy(e))}isHeavy(e=0){if("number"!=typeof e)throw new TypeError("`extraWeight` must be a number.");return null!==this.#a&&this.weight+e>this.#a}areFull(e=0){if("number"!=typeof e)throw new TypeError("`extraLength` must be a number.");return null!==this.#o&&this.size+e>this.#o}isFull(e=0){if("number"!=typeof e)throw new TypeError("`extraLength` must be a number.");return null!==this.#o&&this.size+e>=this.#o}areFullSlots(e=0){if("number"!=typeof e)throw new TypeError("`extraLength` must be a number.");return null!==this.#s&&this.slotsSize+e>this.#s}isFullSlots(e=0){if("number"!=typeof e)throw new TypeError("`extraLength` must be a number.");return null!==this.#s&&this.slotsSize+e>=this.#s}#m(e,t){if("string"!=typeof e)throw new TypeError("`type` must be a string.");if("object"!=typeof t||null===t)throw new TypeError("`payload` must be an object.");if(this.#i[e])for(const i of this.#i[e])i(t)}off(e,t){if("string"!=typeof e)throw new TypeError("`eventType` must be a string.");if("function"!=typeof t)throw new TypeError("`callback` must be a function.");if(!this.#i[e])return;const i=this.#i[e],r=i.indexOf(t);-1!==r&&i.splice(r,1)}offAll(e){if("string"!=typeof e)throw new TypeError("`eventType` must be a string.");this.#i[e]&&(this.#i[e]=[])}cloneEventCallbacks(e){if("string"!=typeof e)throw new TypeError("`eventType` must be a string.");return this.#i[e]?[...this.#i[e]]:[]}onAddItem(e){if("function"!=typeof e)throw new TypeError("`callback` must be a function.");this.#i.add.push(e)}onSetItem(e){if("function"!=typeof e)throw new TypeError("`callback` must be a function.");this.#i.set.push(e)}onRemoveItem(e){if("function"!=typeof e)throw new TypeError("`callback` must be a function.");this.#i.remove.push(e)}onUseItem(e){if("function"!=typeof e)throw new TypeError("`callback` must be a function.");this.#i.use.push(e)}compactInventory(){this.#r=this.#r.filter((e,t)=>{const i=null!==e;return i||this.#m("remove",{index:t,item:null,isCollection:!0,specialSlot:null,remove:()=>{}}),i})}addItem({itemId:e,quantity:t=1,metadata:r={},forceSpace:n=!1}){if("string"!=typeof e)throw new TypeError("`itemId` must be a string.");if("number"!=typeof t||!Number.isFinite(t)||t<=0)throw new TypeError("`quantity` must be a positive number.");if("object"!=typeof r||null===r)throw new TypeError("`metadata` must be an object.");if("boolean"!=typeof n)throw new TypeError("`forceSpace` must be a boolean.");const o=i.getItem(e);let s=t;const a=o.maxStack<=this.#n?o.maxStack:this.#n,l=[],m=(e,t)=>JSON.stringify(e)===JSON.stringify(t);let u=!0;for(;s>0&&u;){u=!1;for(const t in this.#r){const i=this.#r[t];if(i&&i.id===e&&i.quantity<a&&m(i.metadata,r)){const e=Math.min(a-i.quantity,s);if(!n&&!this.hasSpace({weight:o.weight*e,sizeLength:e}))continue;i.quantity+=e,s-=e,u=!0;const r=Number(t),m=l.findIndex(e=>e.index===r);if(m<0?l.push({index:r,quantity:e}):l[m].quantity+=e,this.#m("add",{item:this.#l(i),index:r,isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:r,forceSpace:n,item:i})}),s<=0)break}}}if(s>0)for(const t in this.#r)if(null===this.#r[t]){const i=Math.min(a,s);if(!n&&!this.hasSpace({weight:o.weight*i,sizeLength:i}))continue;const m={id:e,quantity:i,metadata:r};this.#r[t]=m,s-=i;const u=Number(t),c=l.findIndex(e=>e.index===u);if(c<0?l.push({index:u,quantity:i}):l[c].quantity+=i,this.#m("add",{item:this.#l(m),index:u,isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:u,forceSpace:n,item:m})}),s<=0)break}for(;s>0;){const t=Math.min(a,s);if(!n&&!this.hasSpace({weight:o.weight*t,sizeLength:t,slotsLength:1}))break;const i={id:e,quantity:t,metadata:r};this.#r.push(i);const m=this.#r.length-1,u=l.findIndex(e=>e.index===m);u<0?l.push({index:m,quantity:t}):l[u].quantity+=t,this.#m("add",{item:this.#l(i),index:m,isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:m,forceSpace:n,item:i})}),s-=t}return{remaining:s,placesAdded:l}}getItemFrom(e){if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`slotIndex` must be an integer.");if(e<0||e>=this.#r.length)throw new Error(`Slot index '${e}' out of bounds .`);return this.#r[e]?this.#l(this.#r[e]):null}setItem({slotIndex:e,item:t,forceSpace:r=!1}){if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`slotIndex` must be an integer.");if("boolean"!=typeof r)throw new TypeError("`forceSpace` must be a boolean.");const n=t&&"object"==typeof t&&"string"==typeof t.id&&"number"==typeof t.quantity&&!Number.isNaN(t.quantity)&&Number.isFinite(t.quantity)&&t.quantity>-1&&"object"==typeof t.metadata;if(null!==t&&!n)throw new Error("Invalid item type: must be null or a valid InventoryItem.");const o=t?i.#e.get(t.id):null;if(null!==t&&!o)throw new Error(`Item '${t?.id??"unknown"}' not defined in registry.`);if(o&&t){const e=o.maxStack<=this.#n?o.maxStack:this.#n;if(t.quantity>e)throw new Error(`Item '${t.id}' exceeds max stack size. Allowed: ${e}, got: ${t.quantity}.`)}if(null!==this.#s&&(e<0||e>=this.#s))throw new Error(`Slot index ${e} out of range.`);const s=this.#r[e]??null,a=s?i.#e.get(s.id)??null:null,l=(e,t)=>t?t.weight*(e?e.quantity:0):0,m=e=>e?e.quantity:0;if(!r&&!this.hasSpace({weight:l(t,o)-l(s,a),sizeLength:m(t)-m(s)}))throw new Error("Inventory is full or overweight.");for(;this.#r.length<=e;)this.#r.push(null);this.#r[e]=t,this._cleanNulls(),this.#m("set",{index:e,isCollection:!0,item:t?this.#l(t):null,specialSlot:null,remove:t?this.#u({locationType:"normal",slotIndex:e,forceSpace:r,item:t}):()=>{}})}deleteItem(e,t=!1){if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`slotIndex` must be an integer.");if("boolean"!=typeof t)throw new TypeError("`forceSpace` must be a boolean.");this.setItem({slotIndex:e,item:null,forceSpace:t})}moveItem(e,t,i=!1){if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`fromIndex` must be an integer.");if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`toIndex` must be an integer.");if("boolean"!=typeof i)throw new TypeError("`forceSpace` must be a boolean.");const r=this.#r[e];if(!r)throw new Error(`No item found in slot ${e}.`);this.setItem({slotIndex:t,item:r,forceSpace:i}),this.setItem({slotIndex:e,item:null,forceSpace:i})}removeItem({itemId:e,metadata:t=null,quantity:i=1}){if("string"!=typeof e)throw new TypeError("`itemId` must be a string.");if(null!==t&&"object"!=typeof t)throw new TypeError("`metadata` must be an object or null.");if("number"!=typeof i||!Number.isFinite(i)||i<=0)throw new TypeError("`quantity` must be a positive number.");let r=i;const n=(e,t)=>JSON.stringify(e)===JSON.stringify(t);for(let i=0;i<this.#r.length;i++){const o=this.#r[i];if(o&&o.id===e&&(null===t||n(o.metadata,t))){const e=Math.min(o.quantity,r);o.quantity-=e,r-=e;const t=Number(i);if(o.quantity<=0&&(this.#r[i]=null),r<=0)return this._cleanNulls(),this.#m("remove",{index:t,item:this.#l(o),isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:t,item:o})}),!0}}return this._cleanNulls(),this.#t.forEach((i,o)=>{if(r>0&&i.item&&i.item.id===e&&(null===t||n(i.item.metadata,t))){const e=Math.min(i.item.quantity,r);i.item.quantity-=e,i.item.quantity<0&&(i.item.quantity=0),r-=e,i.item.quantity<=0&&(i.item=null),this.#t.set(o,i),this.#m("remove",{index:null,item:i.item?this.#l(i.item):null,isCollection:!1,specialSlot:o,remove:i.item?this.#u({locationType:"special",specialSlot:o,item:i.item}):()=>{}})}}),r<=0}#u({locationType:e,specialSlot:t,slotIndex:i,item:r,forceSpace:n=!1}){if("normal"!==e&&"special"!==e)throw new TypeError("`locationType` must be 'normal' or 'special'.");if("boolean"!=typeof n)throw new TypeError("`forceSpace` must be boolean.");if(!r||"object"!=typeof r)throw new TypeError("`item` must be an InventoryItem object.");if("special"===e&&t&&"string"!=typeof t)throw new TypeError("`specialSlot` must be a string when locationType is 'special'.");if("normal"===e&&"number"!=typeof i)throw new TypeError("`slotIndex` must be a number when locationType is 'normal'.");return(o=n)=>{if("special"===e&&t){const e=this.#t.get(t);if(!e?.item)throw new Error(`Special slot '${t}' is empty.`);e.item.quantity>1?(e.item.quantity-=1,this.#t.set(t,e)):this.setSpecialSlot({slotId:t,item:null,forceSpace:o})}else{if("number"!=typeof i)throw new Error("Invalid remove operation: no valid slotIndex or specialSlot provided.");r.quantity>1?this.setItem({slotIndex:i,item:{...r,quantity:r.quantity-1},forceSpace:o}):this.setItem({slotIndex:i,item:null,forceSpace:o})}}}useItem({slotIndex:e,specialSlot:t,forceSpace:r=!1},...n){if(void 0!==e&&("number"!=typeof e||!Number.isInteger(e)))throw new TypeError("`slotIndex` must be an integer if provided.");if(void 0!==t&&"string"!=typeof t)throw new TypeError("`specialSlot` must be a string if provided.");if("boolean"!=typeof r)throw new TypeError("`forceSpace` must be boolean.");let o=null,s="normal",a=null;if(t){if(!this.#t.has(t))throw new Error(`Special slot '${t}' not found.`);o=this.#t.get(t).item,s="special"}else a=this.#r,o=a[e??-1]??null,s="normal";if(!o)throw new Error("special"===s?`No item found in special slot '${t}'.`:`No item found in slot ${e} of inventory.`);const l=i.getItem(o.id);if(l.onUse){const i={inventory:this,item:this.#l(o),index:e??null,specialSlot:t??null,isCollection:!!a,itemDef:l,remove:this.#u({locationType:s,specialSlot:t,slotIndex:e,forceSpace:r,item:o}),...n},m=l.onUse(i);return this.#m("use",i),m}return null}hasSpecialSlot(e){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");return this.#t.has(e)}getSpecialItem(e){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");if(!this.#t.has(e))throw new Error(`Special slot '${e}' does not exist.`);const t=this.#t.get(e);return t?.item?this.#l(t.item):null}getSpecialSlotType(e){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");if(!this.#t.has(e))throw new Error(`Special slot '${e}' does not exist.`);const t=this.#t.get(e);return t?.type??null}setSpecialSlot({slotId:e,item:t,forceSpace:r=!1}){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");if("boolean"!=typeof r)throw new TypeError("`forceSpace` must be boolean.");if(!this.#t.has(e))throw new Error(`Special slot '${e}' not found.`);const n=t&&"object"==typeof t&&"string"==typeof t.id&&"number"==typeof t.quantity&&!Number.isNaN(t.quantity)&&Number.isFinite(t.quantity)&&t.quantity>-1&&"object"==typeof t.metadata;if(null!==t&&!n)throw new Error("Invalid item type: must be null or a valid InventoryItem.");const o=t?i.#e.get(t.id):null;if(null!==t&&!o)throw new Error(`Item '${t?.id??"unknown"}' not defined in registry.`);const s=this.#t.get(e);if(!s)throw new Error(`Special slot ${e} out of range for slot '${e}'.`);const a=s.item?i.#e.get(s.item.id):null,l=(e,t)=>t?t.weight*(e?1:0):0,m=e=>e?1:0;if(!r&&!this.hasSpace({weight:l(t,o)-l(s.item,a),sizeLength:m(t)-m(s.item)}))throw new Error("Inventory is full or overweight.");s.item=t,this.#m("set",{index:null,item:t?this.#l(t):null,isCollection:!1,specialSlot:e,remove:t?this.#u({locationType:"special",specialSlot:e,forceSpace:r,item:t}):()=>{}})}deleteSpecialItem(e,t=!1){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");if("boolean"!=typeof t)throw new TypeError("`forceSpace` must be boolean.");this.setSpecialSlot({slotId:e,item:null,forceSpace:t})}equipItem({slotId:e,slotIndex:t,quantity:r=1,forceSpace:n=!1}){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`slotIndex` must be an integer.");if("number"!=typeof r||!Number.isFinite(r)||r<=0)throw new TypeError("`quantity` must be a positive number.");if("boolean"!=typeof n)throw new TypeError("`forceSpace` must be boolean.");if(r<=0||!Number.isFinite(r))throw new Error(`Invalid quantity '${r}'.`);if(!this.#t.has(e))throw new Error(`Special slot '${e}' does not exist.`);const o=this.getItemFrom(t);if(!o)throw new Error(`No item found in inventory slot ${t}.`);if(o.quantity<r)throw new Error(`Not enough quantity of item '${o.id}' in inventory slot.`);const s=i.getItem(o.id),a=this.#t.get(e);if(!a)throw new Error(`Slot '${e}' not defined in registry.`);const l=a.type??null;if(null!==l&&s.type!==l)throw new Error(`Item '${o.id}' cannot be equipped in slot '${e}'.`);const m=Math.min(s.maxStack,this.#n);if(a.item&&a.item.id===o.id){const t=Math.max(0,m-a.item.quantity);if(t<=0)return r;const i=Math.min(r,t);return this.removeItem({itemId:o.id,quantity:i,metadata:null}),a.item.quantity+=i,this.#t.set(e,a),r-i}a.item&&this.unequipItem({slotId:e,forceSpace:n});const u=Math.min(r,m);return this.removeItem({itemId:o.id,quantity:u,metadata:null}),a.item={id:o.id,quantity:u,metadata:o.metadata},this.#t.set(e,a),r-u}unequipItem({slotId:e,quantity:t=null,forceSpace:i=!1}){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");if(null!==t&&("number"!=typeof t||!Number.isFinite(t)||t<=0))throw new TypeError("`quantity` must be a positive number or null.");if("boolean"!=typeof i)throw new TypeError("`forceSpace` must be boolean.");if(!this.#t.has(e))throw new Error(`Special slot '${e}' does not exist.`);const r=this.#t.get(e);if(!r)throw new Error(`Slot '${e}' not defined in registry.`);if(!r.item)return!1;const n=r.item,o=null===t?n.quantity:t;if(o<=0)throw new Error(`Invalid unequip quantity: ${o}`);if(o>n.quantity)throw new Error(`Not enough items in slot '${e}' to unequip.`);return this.addItem({itemId:n.id,quantity:o,metadata:n.metadata,forceSpace:i}),o===n.quantity?r.item=null:(n.quantity-=o,r.item=n),this.#t.set(e,r),!0}#l(e){if(!e||"object"!=typeof e)throw new TypeError("`item` must be an InventoryItem object.");if("string"!=typeof e.id)throw new TypeError("`item.id` must be a string.");if("number"!=typeof e.quantity||!Number.isFinite(e.quantity))throw new TypeError("`item.quantity` must be a finite number.");if(!e.metadata||"object"!=typeof e.metadata)throw new TypeError("`item.metadata` must be an object.");return{id:e.id,quantity:e.quantity,metadata:{...e.metadata}}}getItemList(){return[...this.#r].map((e,t)=>[e?this.#l(e):null,t]).filter(e=>null!==e[0])}getAllItems(){const e=[...this.#r].filter(e=>null!==e).map(this.#l);return this.#t.forEach(t=>{const i=t.item;i&&e.push(i)}),e}getItemsByMetadata(e){if("function"!=typeof e)throw new TypeError("`filterFn` must be a function.");return this.getAllItems().filter(t=>{const r=i.getItem(t.id);return e(r.metadata,t)})}findItem(e){if("function"!=typeof e)throw new TypeError("`predicate` must be a function.");return this.getAllItems().find(e)}findItems(e){if("function"!=typeof e)throw new TypeError("`predicate` must be a function.");return this.getAllItems().filter(e)}getItemCount(e){if("string"!=typeof e)throw new TypeError("`itemId` must be a string.");return this.getAllItems().filter(t=>t.id===e).reduce((e,t)=>e+t.quantity,0)}hasItem(e,t=1){if("string"!=typeof e)throw new TypeError("`itemId` must be a string.");if("number"!=typeof t||!Number.isFinite(t)||t<0)throw new TypeError("`quantity` must be a non-negative number.");return this.getItemCount(e)>=t}existsItemAt(e){if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`slotIndex` must be an integer.");return!!this.#r[e]}clear(){this.clearAllItems(),this.clearAllEvents()}clearAllEvents(){this.#i={add:[],remove:[],use:[],set:[]}}clearAllItems(){this.clearItems(),this.clearSpecialItems()}clearItems(){for(let e=this.#r.length-1;e>=0;e--)this.#r[e]&&this.deleteItem(e,!0)}clearSpecialItems(){for(const e of this.#t.keys()){const t=this.#t.get(e);t?.item&&this.deleteSpecialItem(e,!0)}}clone(){const e=this.toObject();return i.fromObject(e)}toObject(){const e={};for(const[t,i]of this.#t.entries())e[t]={type:i?.type??null,item:i?.item?this.#l(i.item):null};return{__schema:"TinyInventory",version:1,maxWeight:this.#a,maxSlots:this.#s,maxSize:this.#o,maxStack:this.#n,items:this.#r.map(e=>e?this.#l(e):null),specialSlots:e}}toJSON(e=0){if("number"!=typeof e||!Number.isFinite(e)||e<0)throw new TypeError("`space` must be a non-negative number.");return JSON.stringify(this.toObject(),null,e)}static fromObject(e){if(!e||"object"!=typeof e)throw new TypeError("Invalid state: expected object.");if("TinyInventory"!==e.__schema||"number"!=typeof e.version)throw new TypeError("Invalid or missing schema header.");if(1!==e.version)throw new TypeError(`Unsupported TinyInventory state version: ${e.version}`);const t={};if(e.specialSlots&&"object"==typeof e.specialSlots)for(const i of Object.keys(e.specialSlots))t[i]={type:e.specialSlots[i]?.type??null};const r=new i({maxWeight:e.maxWeight??null,maxSlots:e.maxSlots??null,maxSize:e.maxSize??null,maxStack:e.maxStack??null,specialSlots:t});if(Array.isArray(e.items))for(const t in e.items){const i=e.items[t];if(null!==i){const e={id:String(i.id),quantity:Math.max(1,Number(i.quantity)||1),metadata:i.metadata&&"object"==typeof i.metadata?i.metadata:{}};r.setItem({slotIndex:Number(t),item:e,forceSpace:!0})}else r.setItem({slotIndex:Number(t),item:null,forceSpace:!0})}if(e.specialSlots&&"object"==typeof e.specialSlots)for(const[t,i]of Object.entries(e.specialSlots)){if(!r.hasSpecialSlot(t))continue;const e=i?.item;if(e&&e.id){const i={id:String(e.id),quantity:Math.max(1,Number(e.quantity)||1),metadata:e.metadata&&"object"==typeof e.metadata?e.metadata:{}};r.setSpecialSlot({slotId:t,item:i,forceSpace:!0})}}return r}static fromJSON(e){if("string"!=typeof e)throw new TypeError("`json` must be a string.");const t=JSON.parse(e);return i.fromObject(t)}}const r=i,n=class{#c=null;#h=null;get sender(){return this.#c}get receiver(){return this.#h}set sender(e){if(!(e instanceof r&&this.receiver instanceof r))throw new Error("Both sender and receiver must be TinyInventory instances.");this.#c=e}set receiver(e){if(!(this.sender instanceof r&&e instanceof r))throw new Error("Both sender and receiver must be TinyInventory instances.");this.#h=e}constructor(e,t){if(e||t){if(!(e instanceof r&&t instanceof r))throw new Error("Both sender and receiver must be TinyInventory instances.");this.connect(e,t)}}connect(e,t){if(!(e instanceof r&&t instanceof r))throw new Error("Both sender and receiver must be TinyInventory instances.");this.#c=e,this.#h=t}disconnect(){this.#c=null,this.#h=null}invert(){const e=this.#c,t=this.#h;this.#c=t,this.#h=e}transferItem({slotIndex:e,specialSlot:t,quantity:i=1,receiverSlotIndex:n,forceSpace:o=!1,strict:s=!1}){if(!this.#c||!this.#h)throw new Error("Sender and receiver inventories must be connected.");let a;if(t){if(a=this.#c.getSpecialItem(t),!a)throw new Error(`No item found in sender special slot '${t}'.`)}else{if("number"!=typeof e)throw new Error("Must provide either slotIndex or specialSlot.");if(a=this.#c.getItemFrom(e),!a)throw new Error(`No item found in sender slot ${e}.`)}if(a.quantity<i)throw new Error(`Sender does not have enough quantity of '${a.id}' to transfer.`);const l={id:a.id,quantity:i,metadata:a.metadata};let m;if(s)if("number"==typeof n){const e=this.#h.existsItemAt(n)?this.#h.getItemFrom(n):null;if(e){if(e.id!==l.id)throw new Error(`Receiver slot ${n} contains a different item.`);const t=r.getItem(e.id).maxStack-e.quantity;if(l.quantity>t)throw new Error(`Strict mode: not enough space in receiver slot ${n}.`)}}else if(this.#h.clone().addItem({itemId:l.id,quantity:l.quantity,metadata:l.metadata,forceSpace:o}).remaining>0)throw new Error("Strict mode: not enough space in receiver inventory.");if("number"==typeof n){const e=this.#h.existsItemAt(n)?this.#h.getItemFrom(n):null;let t=l.quantity;if(e){if(e.id!==l.id)throw new Error(`Receiver slot ${n} contains a different item.`);const i=r.getItem(e.id).maxStack-e.quantity;t=Math.min(i,l.quantity),t>0&&this.#h.setItem({slotIndex:n,item:{...e,quantity:e.quantity+t},forceSpace:o})}else this.#h.setItem({slotIndex:n,item:l,forceSpace:o});m={remaining:l.quantity-t}}else m=this.#h.addItem({itemId:l.id,quantity:l.quantity,metadata:l.metadata,forceSpace:o});const u=l.quantity-m.remaining;if(u>0)if(t)this.#c.unequipItem({slotId:t,quantity:u,forceSpace:o});else if("number"==typeof e){const t=a.quantity-u;this.#c.setItem({slotIndex:e,item:t>0?{...a,quantity:t}:null,forceSpace:o})}return m}transferMultiple(e){return e.map(e=>this.transferItem(e))}};window.TinyInventoryTrader=t.TinyInventoryTrader})();
|
|
1
|
+
(()=>{"use strict";const e={d:(t,i)=>{for(var r in i)e.o(i,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:i[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};e.d(t,{TinyInventoryTrader:()=>n});class i{static#e=new Map;static get itemRegistry(){const e={},t=Object.fromEntries(i.#e);for(const i in t)e[i]={...t[i],metadata:{...t[i].metadata}};return e}static defineItem(e){if(!e||"object"!=typeof e)throw new TypeError("Config must be a valid object.");if(!e.id||"string"!=typeof e.id)throw new TypeError("Item must have a valid string 'id'.");if(void 0!==e.weight&&("number"!=typeof e.weight||e.weight<0))throw new TypeError(`weight must be a number >= 0. Received: ${e.weight}`);if(void 0!==e.maxStack&&(!Number.isInteger(e.maxStack)||e.maxStack<=0))throw new TypeError(`maxStack must be a positive integer. Received: ${e.maxStack}`);if(void 0!==e.metadata&&"object"!=typeof e.metadata)throw new TypeError("metadata must be an object.");if(void 0!==e.onUse&&null!==e.onUse&&"function"!=typeof e.onUse)throw new TypeError("onUse must be a function or null.");if(void 0!==e.type&&null!==e.type&&"string"!=typeof e.type)throw new TypeError("type must be a string or null.");i.#e.set(e.id,{id:e.id,weight:e.weight||0,maxStack:e.maxStack||1,metadata:e.metadata||{},type:e.type??null,onUse:"function"==typeof e.onUse?e.onUse:null})}static removeItem(e){if("string"!=typeof e)throw new TypeError("itemId must be a string.");return i.#e.delete(e)}static hasItem(e){if("string"!=typeof e)throw new TypeError("itemId must be a string.");return i.#e.has(e)}static getItem(e){if("string"!=typeof e)throw new TypeError("itemId must be a string.");const t=i.#e.get(e);if(!t)throw new Error(`Item '${e}' not defined in registry.`);return t}#t=new Map;#i={add:[],remove:[],use:[],set:[]};#r=[];#n;#o;#s;#a;get maxStack(){return this.#n}set maxStack(e){if(!Number.isInteger(e)||Number.isFinite(e)&&e<=0)throw new TypeError(`maxStack must be a positive integer. Received: ${e}`);this.#n=e}get maxSize(){return this.#o}set maxSize(e){if(null!==e&&(!Number.isInteger(e)||e<=0))throw new TypeError(`maxSize must be null or a positive integer. Received: ${e}`);this.#o=e}get maxSlots(){return this.#s}set maxSlots(e){if(null!==e&&(!Number.isInteger(e)||e<=0))throw new TypeError(`maxSlots must be null or a positive integer. Received: ${e}`);this.#s=e}get maxWeight(){return this.#a}set maxWeight(e){if(null!==e&&("number"!=typeof e||e<=0))throw new TypeError(`maxWeight must be null or a positive number. Received: ${e}`);this.#a=e}get events(){return{add:[...this.#i.add],remove:[...this.#i.remove],use:[...this.#i.use],set:[...this.#i.set]}}get items(){return[...this.#r].map(e=>e?this.#l(e):null)}get specialSlots(){return new Map([...this.#t.entries()].map(([e,t])=>[e,{type:t.type,item:t.item?this.#l(t.item):null}]))}get size(){const e=this.getAllItems();let t=0;for(const i of e)t+=i.quantity;return t}get slotsSize(){return this.getAllItems().length}get weight(){return this.getAllItems().reduce((e,t)=>{const r=i.getItem(t.id);return e+(r?.weight||0)*t.quantity},0)}_cleanNulls(){let e=this.#r.length-1;for(;e>=0&&null===this.#r[e];)e--;this.#r=this.#r.slice(0,e+1)}constructor(e={}){if("object"!=typeof e||null===e)throw new TypeError("`options` must be an object.");if(void 0!==e.maxWeight&&null!==e.maxWeight&&"number"!=typeof e.maxWeight)throw new TypeError("`maxWeight` must be a number or null.");if(void 0!==e.maxSlots&&null!==e.maxSlots&&"number"!=typeof e.maxSlots)throw new TypeError("`maxSlots` must be a number or null.");if(void 0!==e.maxSize&&null!==e.maxSize&&"number"!=typeof e.maxSize)throw new TypeError("`maxSize` must be a number or null.");if(void 0!==e.maxStack&&"number"!=typeof e.maxStack)throw new TypeError("`maxStack` must be a number.");if(void 0!==e.specialSlots&&"object"!=typeof e.specialSlots)throw new TypeError("`specialSlots` must be an object if defined.");if(this.#a=e.maxWeight??null,this.#s=e.maxSlots??null,this.#o=e.maxSize??null,this.#n=e.maxStack??1/0,e.specialSlots)for(const t in e.specialSlots){const i=e.specialSlots[t];if("object"!=typeof i||null===i)throw new TypeError("Each `specialSlot` entry must be an object.");if(void 0!==i.type&&null!==i.type&&"string"!=typeof i.type)throw new TypeError("`specialSlot.type` must be a string or null.");this.#t.set(t,{type:i.type??null,item:null})}}hasSpace({weight:e=0,sizeLength:t=0,slotsLength:i=0}={}){if("number"!=typeof e)throw new TypeError("`weight` must be a number.");if("number"!=typeof t)throw new TypeError("`sizeLength` must be a number.");if("number"!=typeof i)throw new TypeError("`slotsLength` must be a number.");return!(this.areFull(t)||this.areFullSlots(i)||this.isHeavy(e))}isHeavy(e=0){if("number"!=typeof e)throw new TypeError("`extraWeight` must be a number.");return null!==this.#a&&this.weight+e>this.#a}areFull(e=0){if("number"!=typeof e)throw new TypeError("`extraLength` must be a number.");return null!==this.#o&&this.size+e>this.#o}isFull(e=0){if("number"!=typeof e)throw new TypeError("`extraLength` must be a number.");return null!==this.#o&&this.size+e>=this.#o}areFullSlots(e=0){if("number"!=typeof e)throw new TypeError("`extraLength` must be a number.");return null!==this.#s&&this.slotsSize+e>this.#s}isFullSlots(e=0){if("number"!=typeof e)throw new TypeError("`extraLength` must be a number.");return null!==this.#s&&this.slotsSize+e>=this.#s}#m(e,t){if("string"!=typeof e)throw new TypeError("`type` must be a string.");if("object"!=typeof t||null===t)throw new TypeError("`payload` must be an object.");if(this.#i[e])for(const i of this.#i[e])i(t)}off(e,t){if("string"!=typeof e)throw new TypeError("`eventType` must be a string.");if("function"!=typeof t)throw new TypeError("`callback` must be a function.");if(!this.#i[e])return;const i=this.#i[e],r=i.indexOf(t);-1!==r&&i.splice(r,1)}offAll(e){if("string"!=typeof e)throw new TypeError("`eventType` must be a string.");this.#i[e]&&(this.#i[e]=[])}cloneEventCallbacks(e){if("string"!=typeof e)throw new TypeError("`eventType` must be a string.");return this.#i[e]?[...this.#i[e]]:[]}onAddItem(e){if("function"!=typeof e)throw new TypeError("`callback` must be a function.");this.#i.add.push(e)}onSetItem(e){if("function"!=typeof e)throw new TypeError("`callback` must be a function.");this.#i.set.push(e)}onRemoveItem(e){if("function"!=typeof e)throw new TypeError("`callback` must be a function.");this.#i.remove.push(e)}onUseItem(e){if("function"!=typeof e)throw new TypeError("`callback` must be a function.");this.#i.use.push(e)}compactInventory(){this.#r=this.#r.filter((e,t)=>{const i=null!==e;return i||this.#m("remove",{index:t,item:null,isCollection:!0,specialSlot:null,remove:()=>{}}),i})}addItem({itemId:e,quantity:t=1,metadata:r={},forceSpace:n=!1}){if("string"!=typeof e)throw new TypeError("`itemId` must be a string.");if("number"!=typeof t||!Number.isFinite(t)||t<=0)throw new TypeError("`quantity` must be a positive number.");if("object"!=typeof r||null===r)throw new TypeError("`metadata` must be an object.");if("boolean"!=typeof n)throw new TypeError("`forceSpace` must be a boolean.");const o=i.getItem(e);let s=t;const a=o.maxStack<=this.#n?o.maxStack:this.#n,l=[],m=(e,t)=>JSON.stringify(e)===JSON.stringify(t);let u=!0;for(;s>0&&u;){u=!1;for(const t in this.#r){const i=this.#r[t];if(i&&i.id===e&&i.quantity<a&&m(i.metadata,r)){const e=Math.min(a-i.quantity,s);if(!n&&!this.hasSpace({weight:o.weight*e,sizeLength:e}))continue;i.quantity+=e,s-=e,u=!0;const r=Number(t),m=l.findIndex(e=>e.index===r);if(m<0?l.push({index:r,quantity:e}):l[m].quantity+=e,this.#m("add",{item:this.#l(i),index:r,isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:r,forceSpace:n,item:i})}),s<=0)break}}}if(s>0)for(const t in this.#r)if(null===this.#r[t]){const i=Math.min(a,s);if(!n&&!this.hasSpace({weight:o.weight*i,sizeLength:i}))continue;const m={id:e,quantity:i,metadata:r};this.#r[t]=m,s-=i;const u=Number(t),c=l.findIndex(e=>e.index===u);if(c<0?l.push({index:u,quantity:i}):l[c].quantity+=i,this.#m("add",{item:this.#l(m),index:u,isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:u,forceSpace:n,item:m})}),s<=0)break}for(;s>0;){const t=Math.min(a,s);if(!n&&!this.hasSpace({weight:o.weight*t,sizeLength:t,slotsLength:1}))break;const i={id:e,quantity:t,metadata:r};this.#r.push(i);const m=this.#r.length-1,u=l.findIndex(e=>e.index===m);u<0?l.push({index:m,quantity:t}):l[u].quantity+=t,this.#m("add",{item:this.#l(i),index:m,isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:m,forceSpace:n,item:i})}),s-=t}return{remaining:s,placesAdded:l}}getItemFrom(e){if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`slotIndex` must be an integer.");if(e<0||e>=this.#r.length)throw new Error(`Slot index '${e}' out of bounds .`);return this.#r[e]?this.#l(this.#r[e]):null}setItem({slotIndex:e,item:t,forceSpace:r=!1}){if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`slotIndex` must be an integer.");if("boolean"!=typeof r)throw new TypeError("`forceSpace` must be a boolean.");const n=t&&"object"==typeof t&&"string"==typeof t.id&&"number"==typeof t.quantity&&!Number.isNaN(t.quantity)&&Number.isFinite(t.quantity)&&t.quantity>-1&&"object"==typeof t.metadata;if(null!==t&&!n)throw new Error("Invalid item type: must be null or a valid InventoryItem.");const o=t?i.#e.get(t.id):null;if(null!==t&&!o)throw new Error(`Item '${t?.id??"unknown"}' not defined in registry.`);if(o&&t){const e=o.maxStack<=this.#n?o.maxStack:this.#n;if(t.quantity>e)throw new Error(`Item '${t.id}' exceeds max stack size. Allowed: ${e}, got: ${t.quantity}.`)}if(null!==this.#s&&(e<0||e>=this.#s))throw new Error(`Slot index ${e} out of range.`);const s=this.#r[e]??null,a=s?i.#e.get(s.id)??null:null,l=(e,t)=>t?t.weight*(e?e.quantity:0):0,m=e=>e?e.quantity:0;if(!r&&!this.hasSpace({weight:l(t,o)-l(s,a),sizeLength:m(t)-m(s)}))throw new Error("Inventory is full or overweight.");for(;this.#r.length<=e;)this.#r.push(null);this.#r[e]=t,this._cleanNulls(),this.#m("set",{index:e,isCollection:!0,item:t?this.#l(t):null,specialSlot:null,remove:t?this.#u({locationType:"normal",slotIndex:e,forceSpace:r,item:t}):()=>{}})}deleteItem(e,t=!1){if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`slotIndex` must be an integer.");if("boolean"!=typeof t)throw new TypeError("`forceSpace` must be a boolean.");this.setItem({slotIndex:e,item:null,forceSpace:t})}moveItem(e,t,i=!1){if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`fromIndex` must be an integer.");if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`toIndex` must be an integer.");if("boolean"!=typeof i)throw new TypeError("`forceSpace` must be a boolean.");const r=this.#r[e];if(!r)throw new Error(`No item found in slot ${e}.`);this.setItem({slotIndex:t,item:r,forceSpace:i}),this.setItem({slotIndex:e,item:null,forceSpace:i})}removeItem({itemId:e,metadata:t=null,quantity:i=1}){if("string"!=typeof e)throw new TypeError("`itemId` must be a string.");if(null!==t&&"object"!=typeof t)throw new TypeError("`metadata` must be an object or null.");if("number"!=typeof i||!Number.isFinite(i)||i<=0)throw new TypeError("`quantity` must be a positive number.");let r=i;const n=(e,t)=>JSON.stringify(e)===JSON.stringify(t);for(let i=0;i<this.#r.length;i++){const o=this.#r[i];if(o&&o.id===e&&(null===t||n(o.metadata,t))){const e=Math.min(o.quantity,r);o.quantity-=e,r-=e;const t=Number(i);if(o.quantity<=0&&(this.#r[i]=null),r<=0)return this._cleanNulls(),this.#m("remove",{index:t,item:this.#l(o),isCollection:!0,specialSlot:null,remove:this.#u({locationType:"normal",slotIndex:t,item:o})}),!0}}return this._cleanNulls(),this.#t.forEach((i,o)=>{if(r>0&&i.item&&i.item.id===e&&(null===t||n(i.item.metadata,t))){const e=Math.min(i.item.quantity,r);i.item.quantity-=e,i.item.quantity<0&&(i.item.quantity=0),r-=e,i.item.quantity<=0&&(i.item=null),this.#t.set(o,i),this.#m("remove",{index:null,item:i.item?this.#l(i.item):null,isCollection:!1,specialSlot:o,remove:i.item?this.#u({locationType:"special",specialSlot:o,item:i.item}):()=>{}})}}),r<=0}#u({locationType:e,specialSlot:t,slotIndex:i,item:r,forceSpace:n=!1}){if("normal"!==e&&"special"!==e)throw new TypeError("`locationType` must be 'normal' or 'special'.");if("boolean"!=typeof n)throw new TypeError("`forceSpace` must be boolean.");if(!r||"object"!=typeof r)throw new TypeError("`item` must be an InventoryItem object.");if("special"===e&&t&&"string"!=typeof t)throw new TypeError("`specialSlot` must be a string when locationType is 'special'.");if("normal"===e&&"number"!=typeof i)throw new TypeError("`slotIndex` must be a number when locationType is 'normal'.");return(o=n)=>{if("special"===e&&t){const e=this.#t.get(t);if(!e?.item)throw new Error(`Special slot '${t}' is empty.`);e.item.quantity>1?(e.item.quantity-=1,this.#t.set(t,e)):this.setSpecialSlot({slotId:t,item:null,forceSpace:o})}else{if("number"!=typeof i)throw new Error("Invalid remove operation: no valid slotIndex or specialSlot provided.");r.quantity>1?this.setItem({slotIndex:i,item:{...r,quantity:r.quantity-1},forceSpace:o}):this.setItem({slotIndex:i,item:null,forceSpace:o})}}}useItem({slotIndex:e,specialSlot:t,forceSpace:r=!1},...n){if(void 0!==e&&("number"!=typeof e||!Number.isInteger(e)))throw new TypeError("`slotIndex` must be an integer if provided.");if(void 0!==t&&"string"!=typeof t)throw new TypeError("`specialSlot` must be a string if provided.");if("boolean"!=typeof r)throw new TypeError("`forceSpace` must be boolean.");let o=null,s="normal",a=null;if(t){if(!this.#t.has(t))throw new Error(`Special slot '${t}' not found.`);o=this.#t.get(t).item,s="special"}else a=this.#r,o=a[e??-1]??null,s="normal";if(!o)throw new Error("special"===s?`No item found in special slot '${t}'.`:`No item found in slot ${e} of inventory.`);const l=i.getItem(o.id);if(l.onUse){const i={inventory:this,item:this.#l(o),index:e??null,specialSlot:t??null,isCollection:!!a,itemDef:l,remove:this.#u({locationType:s,specialSlot:t,slotIndex:e,forceSpace:r,item:o}),...n},m=l.onUse(i);return this.#m("use",i),m}return null}hasSpecialSlot(e){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");return this.#t.has(e)}getSpecialItem(e){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");if(!this.#t.has(e))throw new Error(`Special slot '${e}' does not exist.`);const t=this.#t.get(e);return t?.item?this.#l(t.item):null}getSpecialSlotType(e){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");if(!this.#t.has(e))throw new Error(`Special slot '${e}' does not exist.`);const t=this.#t.get(e);return t?.type??null}setSpecialSlot({slotId:e,item:t,forceSpace:r=!1}){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");if("boolean"!=typeof r)throw new TypeError("`forceSpace` must be boolean.");if(!this.#t.has(e))throw new Error(`Special slot '${e}' not found.`);const n=t&&"object"==typeof t&&"string"==typeof t.id&&"number"==typeof t.quantity&&!Number.isNaN(t.quantity)&&Number.isFinite(t.quantity)&&t.quantity>-1&&"object"==typeof t.metadata;if(null!==t&&!n)throw new Error("Invalid item type: must be null or a valid InventoryItem.");const o=t?i.#e.get(t.id):null;if(null!==t&&!o)throw new Error(`Item '${t?.id??"unknown"}' not defined in registry.`);const s=this.#t.get(e);if(!s)throw new Error(`Special slot ${e} out of range for slot '${e}'.`);const a=s.item?i.#e.get(s.item.id):null,l=(e,t)=>t?t.weight*(e?1:0):0,m=e=>e?1:0;if(!r&&!this.hasSpace({weight:l(t,o)-l(s.item,a),sizeLength:m(t)-m(s.item)}))throw new Error("Inventory is full or overweight.");s.item=t,this.#m("set",{index:null,item:t?this.#l(t):null,isCollection:!1,specialSlot:e,remove:t?this.#u({locationType:"special",specialSlot:e,forceSpace:r,item:t}):()=>{}})}deleteSpecialItem(e,t=!1){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");if("boolean"!=typeof t)throw new TypeError("`forceSpace` must be boolean.");this.setSpecialSlot({slotId:e,item:null,forceSpace:t})}equipItem({slotId:e,slotIndex:t,quantity:r=1,forceSpace:n=!1}){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");if("number"!=typeof t||!Number.isInteger(t))throw new TypeError("`slotIndex` must be an integer.");if("number"!=typeof r||!Number.isFinite(r)||r<=0)throw new TypeError("`quantity` must be a positive number.");if("boolean"!=typeof n)throw new TypeError("`forceSpace` must be boolean.");if(r<=0||!Number.isFinite(r))throw new Error(`Invalid quantity '${r}'.`);if(!this.#t.has(e))throw new Error(`Special slot '${e}' does not exist.`);const o=this.getItemFrom(t);if(!o)throw new Error(`No item found in inventory slot ${t}.`);if(o.quantity<r)throw new Error(`Not enough quantity of item '${o.id}' in inventory slot.`);const s=i.getItem(o.id),a=this.#t.get(e);if(!a)throw new Error(`Slot '${e}' not defined in registry.`);const l=a.type??null;if(null!==l&&s.type!==l)throw new Error(`Item '${o.id}' cannot be equipped in slot '${e}'.`);const m=Math.min(s.maxStack,this.#n);if(a.item&&a.item.id===o.id){const t=Math.max(0,m-a.item.quantity);if(t<=0)return r;const i=Math.min(r,t);return this.removeItem({itemId:o.id,quantity:i,metadata:null}),a.item.quantity+=i,this.#t.set(e,a),r-i}a.item&&this.unequipItem({slotId:e,forceSpace:n});const u=Math.min(r,m);return this.removeItem({itemId:o.id,quantity:u,metadata:null}),a.item={id:o.id,quantity:u,metadata:o.metadata},this.#t.set(e,a),r-u}unequipItem({slotId:e,quantity:t=null,forceSpace:i=!1}){if("string"!=typeof e)throw new TypeError("`slotId` must be a string.");if(null!==t&&("number"!=typeof t||!Number.isFinite(t)||t<=0))throw new TypeError("`quantity` must be a positive number or null.");if("boolean"!=typeof i)throw new TypeError("`forceSpace` must be boolean.");if(!this.#t.has(e))throw new Error(`Special slot '${e}' does not exist.`);const r=this.#t.get(e);if(!r)throw new Error(`Slot '${e}' not defined in registry.`);if(!r.item)return!1;const n=r.item,o=null===t?n.quantity:t;if(o<=0)throw new Error(`Invalid unequip quantity: ${o}`);if(o>n.quantity)throw new Error(`Not enough items in slot '${e}' to unequip.`);return this.addItem({itemId:n.id,quantity:o,metadata:n.metadata,forceSpace:i}),o===n.quantity?r.item=null:(n.quantity-=o,r.item=n),this.#t.set(e,r),!0}#l(e){if(!e||"object"!=typeof e)throw new TypeError("`item` must be an InventoryItem object.");if("string"!=typeof e.id)throw new TypeError("`item.id` must be a string.");if("number"!=typeof e.quantity||!Number.isFinite(e.quantity))throw new TypeError("`item.quantity` must be a finite number.");if(!e.metadata||"object"!=typeof e.metadata)throw new TypeError("`item.metadata` must be an object.");return{id:e.id,quantity:e.quantity,metadata:{...e.metadata}}}getItemList(){return[...this.#r].map((e,t)=>[e?this.#l(e):null,t]).filter(e=>null!==e[0])}getAllItems(){const e=[...this.#r].filter(e=>null!==e).map(this.#l);return this.#t.forEach(t=>{const i=t.item;i&&e.push(i)}),e}getItemsByMetadata(e){if("function"!=typeof e)throw new TypeError("`filterFn` must be a function.");return this.getAllItems().filter(t=>{const r=i.getItem(t.id);return e(r.metadata,t)})}findItem(e){if("function"!=typeof e)throw new TypeError("`predicate` must be a function.");return this.getAllItems().find(e)}findItems(e){if("function"!=typeof e)throw new TypeError("`predicate` must be a function.");return this.getAllItems().filter(e)}getItemCount(e){if("string"!=typeof e)throw new TypeError("`itemId` must be a string.");return this.getAllItems().filter(t=>t.id===e).reduce((e,t)=>e+t.quantity,0)}hasItem(e,t=1){if("string"!=typeof e)throw new TypeError("`itemId` must be a string.");if("number"!=typeof t||!Number.isFinite(t)||t<0)throw new TypeError("`quantity` must be a non-negative number.");return this.getItemCount(e)>=t}existsItemAt(e){if("number"!=typeof e||!Number.isInteger(e))throw new TypeError("`slotIndex` must be an integer.");return!!this.#r[e]}clear(){this.clearAllItems(),this.clearAllEvents()}clearAllEvents(){this.#i={add:[],remove:[],use:[],set:[]}}clearAllItems(){this.clearItems(),this.clearSpecialItems()}clearItems(){for(let e=this.#r.length-1;e>=0;e--)this.#r[e]&&this.deleteItem(e,!0)}clearSpecialItems(){for(const e of this.#t.keys()){const t=this.#t.get(e);t?.item&&this.deleteSpecialItem(e,!0)}}clone(){const e=this.toObject();return i.fromObject(e)}toObject(){const e={};for(const[t,i]of this.#t.entries())e[t]={type:i?.type??null,item:i?.item?this.#l(i.item):null};return{__schema:"TinyInventory",version:1,maxWeight:this.#a,maxSlots:this.#s,maxSize:this.#o,maxStack:this.#n,items:this.#r.map(e=>e?this.#l(e):null),specialSlots:e}}toJSON(e=0){if("number"!=typeof e||!Number.isFinite(e)||e<0)throw new TypeError("`space` must be a non-negative number.");return JSON.stringify(this.toObject(),null,e)}static fromObject(e){if(!e||"object"!=typeof e)throw new TypeError("Invalid state: expected object.");if("TinyInventory"!==e.__schema||"number"!=typeof e.version)throw new TypeError("Invalid or missing schema header.");if(1!==e.version)throw new TypeError(`Unsupported TinyInventory state version: ${e.version}`);const t={};if(e.specialSlots&&"object"==typeof e.specialSlots)for(const i of Object.keys(e.specialSlots))t[i]={type:e.specialSlots[i]?.type??null};const r=new i({maxWeight:e.maxWeight??null,maxSlots:e.maxSlots??null,maxSize:e.maxSize??null,maxStack:e.maxStack??null,specialSlots:t});if(Array.isArray(e.items))for(const t in e.items){const i=e.items[t];if(null!==i){const e={id:String(i.id),quantity:Math.max(1,Number(i.quantity)||1),metadata:i.metadata&&"object"==typeof i.metadata?i.metadata:{}};r.setItem({slotIndex:Number(t),item:e,forceSpace:!0})}else r.setItem({slotIndex:Number(t),item:null,forceSpace:!0})}if(e.specialSlots&&"object"==typeof e.specialSlots)for(const[t,i]of Object.entries(e.specialSlots)){if(!r.hasSpecialSlot(t))continue;const e=i?.item;if(e&&e.id){const i={id:String(e.id),quantity:Math.max(1,Number(e.quantity)||1),metadata:e.metadata&&"object"==typeof e.metadata?e.metadata:{}};r.setSpecialSlot({slotId:t,item:i,forceSpace:!0})}}return r}static fromJSON(e){if("string"!=typeof e)throw new TypeError("`json` must be a string.");const t=JSON.parse(e);return i.fromObject(t)}}const r=i,n=class{#c=null;#h=null;get sender(){return this.#c}get receiver(){return this.#h}set sender(e){if(!(e instanceof r&&this.receiver instanceof r))throw new Error("Both sender and receiver must be TinyInventory instances.");this.#c=e}set receiver(e){if(!(this.sender instanceof r&&e instanceof r))throw new Error("Both sender and receiver must be TinyInventory instances.");this.#h=e}constructor(e,t){if(e||t){if(!(e instanceof r&&t instanceof r))throw new Error("Both sender and receiver must be TinyInventory instances.");this.connect(e,t)}}connect(e,t){if(!(e instanceof r&&t instanceof r))throw new Error("Both sender and receiver must be TinyInventory instances.");this.#c=e,this.#h=t}disconnect(){this.#c=null,this.#h=null}invert(){const e=this.#c,t=this.#h;this.#c=t,this.#h=e}transferItem({slotIndex:e,specialSlot:t,quantity:i=1,receiverSlotIndex:n,forceSpace:o=!1,strict:s=!1}){if(!this.#c||!this.#h)throw new Error("Sender and receiver inventories must be connected.");let a;if(t){if(a=this.#c.getSpecialItem(t),!a)throw new Error(`No item found in sender special slot '${t}'.`)}else{if("number"!=typeof e)throw new Error("Must provide either slotIndex or specialSlot.");if(a=this.#c.getItemFrom(e),!a)throw new Error(`No item found in sender slot ${e}.`)}if(a.quantity<i)throw new Error(`Sender does not have enough quantity of '${a.id}' to transfer.`);const l={id:a.id,quantity:i,metadata:a.metadata};let m;if(s)if("number"==typeof n){const e=this.#h.existsItemAt(n)?this.#h.getItemFrom(n):null;if(e){if(e.id!==l.id)throw new Error(`Receiver slot ${n} contains a different item.`);const t=r.getItem(e.id).maxStack-e.quantity;if(l.quantity>t)throw new Error(`Strict mode: not enough space in receiver slot ${n}.`)}}else if(this.#h.clone().addItem({itemId:l.id,quantity:l.quantity,metadata:l.metadata,forceSpace:o}).remaining>0)throw new Error("Strict mode: not enough space in receiver inventory.");if("number"==typeof n){const e=this.#h.existsItemAt(n)?this.#h.getItemFrom(n):null;let t=l.quantity;if(e){if(e.id!==l.id)throw new Error(`Receiver slot ${n} contains a different item.`);const i=r.getItem(e.id).maxStack-e.quantity;t=Math.min(i,l.quantity),t>0&&this.#h.setItem({slotIndex:n,item:{...e,quantity:e.quantity+t},forceSpace:o})}else this.#h.setItem({slotIndex:n,item:l,forceSpace:o});m={remaining:l.quantity-t}}else m=this.#h.addItem({itemId:l.id,quantity:l.quantity,metadata:l.metadata,forceSpace:o});const u=l.quantity-m.remaining;if(u>0)if(t)this.#c.unequipItem({slotId:t,quantity:u,forceSpace:o});else if("number"==typeof e){const t=a.quantity-u;this.#c.setItem({slotIndex:e,item:t>0?{...a,quantity:t}:null,forceSpace:o})}return m}transferMultiple(e){return e.map(e=>this.transferItem(e))}};window.TinyInventoryTrader=t.TinyInventoryTrader})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";const e={d:(r,t)=>{
|
|
1
|
+
(()=>{"use strict";const e={d:(r,t)=>{for(var i in t)e.o(t,i)&&!e.o(r,i)&&Object.defineProperty(r,i,{enumerable:!0,get:t[i]})},o:(e,r)=>Object.prototype.hasOwnProperty.call(e,r)};let r={};e.d(r,{TinyLevelUp:()=>t});const t=class{constructor(e,r){if("number"!=typeof e||Number.isNaN(e))throw new Error("giveExp must be a valid number");if("number"!=typeof r||Number.isNaN(r))throw new Error("expLevel must be a valid number");this.giveExp=e,this.expLevel=r}createUser(){return{exp:0,level:1,totalExp:0}}validateUser(e){if("number"!=typeof e.exp||Number.isNaN(e.exp))throw new Error("exp must be a valid number");if("number"!=typeof e.level||Number.isNaN(e.level))throw new Error("level must be a valid number");if(e.level<1)throw new Error("level must be at least 1");if("number"!=typeof e.totalExp||Number.isNaN(e.totalExp))throw new Error("totalExp must be a valid number")}isValidUser(e){return!("number"!=typeof e.exp||Number.isNaN(e.exp)||"number"!=typeof e.level||Number.isNaN(e.level)||e.level<1||"number"!=typeof e.totalExp||Number.isNaN(e.totalExp))}getGiveExpBase(){if("number"!=typeof this.giveExp||Number.isNaN(this.giveExp))throw new Error("giveExp must be a valid number");return this.giveExp}getExpLevelBase(){if("number"!=typeof this.expLevel||Number.isNaN(this.expLevel))throw new Error("expLevel must be a valid number");return this.expLevel}expValidator(e){const r=this.getExpLevelBase();this.validateUser(e);let t=0;const i=r*e.level;return e.exp>=i&&(e.level++,t=e.exp-i,e.exp=0,t>0)?this.give(e,t,"extra"):e.exp<1&&e.level>1&&(e.level--,t=Math.abs(e.exp),e.exp=r*e.level,t>0)?this.remove(e,t,"extra"):e}getTotalExp(e){this.validateUser(e);let r=0;for(let t=1;t<=e.level;t++)r+=this.getExpLevelBase()*t;return r+=e.exp,r}expGenerator(e=1){if("number"!=typeof e||Number.isNaN(e))throw new Error("multi must be a valid number");return Math.floor(Math.random()*this.getGiveExpBase())*e}getMissingExp(e){return this.getProgress(e)-e.exp}progress(e){return this.getProgress(e)}getProgress(e){return this.validateUser(e),this.getExpLevelBase()*e.level}set(e,r){if("number"!=typeof r||Number.isNaN(r))throw new Error("value must be a valid number");return e.exp=r,this.expValidator(e),e.totalExp=this.getTotalExp(e),e}give(e,r=0,t="add",i=1){if("number"!=typeof i||Number.isNaN(i))throw new Error("multi must be a valid number");if("number"!=typeof r||Number.isNaN(r))throw new Error("extraExp must be a valid number");if("string"!=typeof t)throw new Error("type must be a valid string");return"add"===t?e.exp+=this.expGenerator(i)+r:"extra"===t&&(e.exp+=r),this.expValidator(e),e.totalExp=this.getTotalExp(e),e}remove(e,r=0,t="add",i=1){if("number"!=typeof i||Number.isNaN(i))throw new Error("multi must be a valid number");if("number"!=typeof r||Number.isNaN(r))throw new Error("extraExp must be a valid number");if("string"!=typeof t)throw new Error("type must be a valid string");return"add"===t?e.exp-=this.expGenerator(i)+r:"extra"===t&&(e.exp-=r),this.expValidator(e),e.totalExp=this.getTotalExp(e),e}};window.TinyLevelUp=r.TinyLevelUp})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";const e={d:(t,s)=>{
|
|
1
|
+
(()=>{"use strict";const e={d:(t,s)=>{for(var n in s)e.o(s,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:s[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};e.d(t,{TinyLoadingScreen:()=>s});const s=class{#e=null;get overlay(){return this.#e}#t=null;get messageElement(){return this.#t}#s;get container(){return this.#s}#n={fadeIn:null,fadeOut:null,zIndex:9999};get options(){return{...this.#n}}set options(e){if("object"!=typeof e||null===e)throw new TypeError("options must be an object");if(void 0!==e.fadeIn&&null!==e.fadeIn&&("number"!=typeof e.fadeIn||e.fadeIn<0))throw new TypeError("fadeIn must be a non-negative number or null");if(void 0!==e.fadeOut&&null!==e.fadeOut&&("number"!=typeof e.fadeOut||e.fadeOut<0))throw new TypeError("fadeOut must be a non-negative number or null");if(void 0!==e.zIndex&&("number"!=typeof e.zIndex||!Number.isInteger(e.zIndex)))throw new TypeError("zIndex must be an integer number");this.#n={fadeIn:e.fadeIn??null,fadeOut:e.fadeOut??null,zIndex:e.zIndex??9999}}#a="none";get status(){return this.#a}#i="";get defaultMessage(){return this.#i}set defaultMessage(e){if("string"!=typeof e&&!(e instanceof HTMLElement))throw new TypeError("defaultMessage must be a string or an HTMLElement");this.#i=e}#o=null;get message(){return this.#o}#l=!1;get allowHtmlText(){return this.#l}set allowHtmlText(e){if("boolean"!=typeof e)throw new TypeError("allowHtmlText must be a boolean");this.#l=e}#r=null;get fadeInTimeout(){return null!==this.#r}#u=null;get fadeOutTimeout(){return null!==this.#u}get visible(){return!!this.#e}#d=null;get onChange(){return this.#d}set onChange(e){if(null!==e&&"function"!=typeof e)throw new TypeError("onChange must be a function or null");this.#d=e}_emitChange(){"function"==typeof this.#d&&this.#d(this.#a)}constructor(e=document.body){if(!(e instanceof HTMLElement))throw new TypeError("container must be an HTMLElement");this.#s=e}_updateMessage(e=this.#i){if(!this.#t)throw new Error("messageElement is not initialized");if("string"!=typeof e&&!(e instanceof HTMLElement))throw new TypeError("message must be a string or an HTMLElement");if(this.#o=e,"string"==typeof e)this.#l?this.#t.innerHTML=e:this.#t.textContent=e;else{if(!this.#l)throw new Error("HTMLElement messages require allowHtmlText = true");this.#t.textContent="",this.#t.appendChild(e)}}_removeOldClasses(){this.#e?.classList.remove("active"),this.#e?.classList.remove("fadeIn"),this.#e?.classList.remove("fadeOut")}start(e=this.#i){if("string"!=typeof e&&!(e instanceof HTMLElement))throw new TypeError("message must be a string or an HTMLElement");if(!this.#e){this.#e=document.createElement("div"),this.#e.classList.add("loading-overlay"),this.#e.style.zIndex=String(this.#n.zIndex);const t=document.createElement("div");t.classList.add("loading-container");const s=document.createElement("div");s.classList.add("loading-content");const n=document.createElement("div");n.classList.add("loading-spinner"),this.#t=document.createElement("div"),this.#t.classList.add("loading-message"),s.appendChild(n),s.appendChild(this.#t),t.appendChild(s),this.#e.appendChild(t),this.#s.appendChild(this.#e),this._removeOldClasses(),this.#a="fadeIn",this.#e.classList.add("fadeIn"),this._emitChange();const a=()=>{this._removeOldClasses(),this.#r=null,this.#a="active",this.#e?.classList.add("active"),this._emitChange()};return"number"==typeof this.#n.fadeIn?(this.#r&&clearTimeout(this.#r),this.#r=setTimeout(a,this.#n.fadeIn)):a(),this._updateMessage(e),!0}return this.#t&&this._updateMessage(e),!1}update(e=this.#i){if("string"!=typeof e&&!(e instanceof HTMLElement))throw new TypeError("message must be a string or an HTMLElement");return!!this.#t&&(this._updateMessage(e),!0)}stop(){if(this.#e){this._removeOldClasses(),this.#a="fadeOut",this.#e.classList.add("fadeOut"),this._emitChange();const e=()=>{this._removeOldClasses(),this.#u=null,this.#a="none",this.#e?.remove(),this.#e=null,this.#t=null,this.#o=null,this._emitChange()};return"number"==typeof this.#n.fadeOut?(this.#u&&clearTimeout(this.#u),this.#u=setTimeout(e,this.#n.fadeOut)):e(),!0}return!1}};window.TinyLoadingScreen=t.TinyLoadingScreen})();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(()=>{"use strict";var e={757(e,t,r){r.d(t,{TinyLocalStorage:()=>u});var n=r.cjs(function(e,t){var r,n="object"==typeof Reflect?Reflect:null,o=n&&"function"==typeof n.apply?n.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};r=n&&"function"==typeof n.ownKeys?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var s=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}e.exports=i,e.exports.once=function(e,t){return new Promise(function(r,n){function o(r){e.removeListener(t,s),n(r)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",o),r([].slice.call(arguments))}g(e,t,s,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&g(e,"error",t,{once:!0})}(e,o)})},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var a=10;function l(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function c(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function u(e,t,r,n){var o,s,i,a;if(l(r),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),i=s[t]),void 0===i)i=s[t]=r,++e._eventsCount;else if("function"==typeof i?i=s[t]=n?[r,i]:[i,r]:n?i.unshift(r):i.push(r),(o=c(e))>0&&i.length>o&&!i.warned){i.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=i.length,a=u,console&&console.warn&&console.warn(a)}return e}function y(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function f(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=y.bind(n);return o.listener=r,n.wrapFn=o,o}function h(e,t,r){var n=e._events;if(void 0===n)return[];var o=n[t];return void 0===o?[]:"function"==typeof o?r?[o.listener||o]:[o]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(o):d(o,o.length)}function p(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function d(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function g(e,t,r,n){if("function"==typeof e.on)n.once?e.once(t,r):e.on(t,r);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function o(s){n.once&&e.removeEventListener(t,o),r(s)})}}Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),i.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},i.prototype.getMaxListeners=function(){return c(this)},i.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var n="error"===e,s=this._events;if(void 0!==s)n=n&&void 0===s.error;else if(!n)return!1;if(n){var i;if(t.length>0&&(i=t[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var l=s[e];if(void 0===l)return!1;if("function"==typeof l)o(l,this,t);else{var c=l.length,u=d(l,c);for(r=0;r<c;++r)o(u[r],this,t)}return!0},i.prototype.addListener=function(e,t){return u(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return u(this,e,t,!0)},i.prototype.once=function(e,t){return l(t),this.on(e,f(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return l(t),this.prependListener(e,f(this,e,t)),this},i.prototype.removeListener=function(e,t){var r,n,o,s,i;if(l(t),void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(o=-1,s=r.length-1;s>=0;s--)if(r[s]===t||r[s].listener===t){i=r[s].listener,o=s;break}if(o<0)return this;0===o?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,o),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,i||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var o,s=Object.keys(r);for(n=0;n<s.length;++n)"removeListener"!==(o=s[n])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},i.prototype.listeners=function(e){return h(this,e,!0)},i.prototype.rawListeners=function(e){return h(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):p.call(e,t)},i.prototype.listenerCount=p,i.prototype.eventNames=function(){return this._eventsCount>0?r(this._events):[]}});function o(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"===Object.prototype.toString.call(e)}const s=e=>{if(e)throw new Error("This TinyLocalStorage instance has been destroyed and can no longer be used.")};const i=new Map,a=new Map,l=new Set(["string","boolean","object","array",String,Boolean,Number,Object,Array,BigInt,Symbol]);class c extends n.EventEmitter{static hasJsonType(e){return i.has(e)&&a.has(e)||l.has(e)}static registerJsonType(e,t,r,n=!1){if(l.has(e))throw new Error(`Cannot register type "${e}" because it is frozen.`);i.set(e,t),a.set(e,r),n&&l.add(e)}static deleteJsonType(e){if(l.has(e))throw new Error(`Cannot remove type "${e}" because it is frozen.`);let t=!1;return i.delete(e)&&(t=!0),a.delete(e)&&(t=!0),t}static encodeSpecialJson(e){if(void 0===e)return{__undefined__:!0};if(null===e)return{__null__:!0};for(const[t,r]of i.entries())if("string"!=typeof t&&e instanceof t||typeof e===t)return r(e,c.encodeSpecialJson);if(Array.isArray(e))return e.map(c.encodeSpecialJson);if(o(e)){const t={};for(const r in e)t[r]=c.encodeSpecialJson(e[r]);return t}return e}static decodeSpecialJson(e){const t=o(e);if(t){if(e.__undefined__)return;if(e.__null__)return null}if(Array.isArray(e))return e.map(c.decodeSpecialJson);if(t){for(const[t,r]of a.entries())if(r.check&&r.check(e))return r.decode(e,c.decodeSpecialJson);const t={};for(const r in e)t[r]=c.decodeSpecialJson(e[r]);return t}return e}#e=!1;get destroyed(){return this.#e}#t=window.localStorage;#r=null;#n=0;#o=e=>this.emit("storage",e);constructor(e){if(super(),void 0!==e&&"string"!=typeof e)throw new TypeError("TinyLocalStorage: dbName must be a string if provided.");"string"==typeof e&&(this.#r=`LSDB::${e}`),window.addEventListener("storage",this.#o)}#s(e){if("string"==typeof e&&e.startsWith("LSDB::"))throw new Error(`TinyLocalStorage: Key "${e}" may conflict with reserved dbKeys.`)}updateStorageVersion(e,t){if(s(this.#e),"string"!=typeof this.#r)throw new Error("TinyLocalStorage: Database key is not initialized. Set a valid dbName in the constructor.");if("number"!=typeof e||Number.isNaN(e)||e<1)throw new TypeError("TinyLocalStorage: version must be a positive number.");if("function"!=typeof t)throw new TypeError("TinyLocalStorage: onUpgrade must be a function.");const r=parseInt(localStorage.getItem(this.#r),10)||0;if("number"!=typeof r||Number.isNaN(r)||r<0)throw new TypeError("TinyLocalStorage: saved version in localStorage is not a valid number.");if(e<r)throw new Error(`TinyLocalStorage: Cannot downgrade database version from ${r} to ${e}.`);e>r&&(t(r,e),localStorage.setItem(this.#r,String(e)),this.#n=e)}getDbKey(){return s(this.#e),this.#r}getVersion(){return s(this.#e),this.#n}setLocalStorage(e){if(s(this.#e),!(e instanceof Storage))throw new TypeError("Argument must be a valid instance of Storage.");this.#t=e}localStorageExists(){return s(this.#e),this.#t instanceof Storage}#i(e,t){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return c.encodeSpecialJson(t)}setJson(e,t){if(s(this.#e),this.#s(e),!(o(t)||Array.isArray(t)||t instanceof Map||t instanceof Set))throw new TypeError("The storage value is not a valid JSON-compatible structure.");const r=this.#i(e,t);return this.emit("setJson",e,t),this.#t.setItem(e,JSON.stringify(r))}#a(e,t){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");const r=this.#t.getItem(e),n={obj:()=>({}),array:()=>[],map:()=>new Map,set:()=>new Set},o="function"==typeof n[t]?n[t]():null;let s;try{s=JSON.parse(r)}catch{return o}return{decoded:c.decodeSpecialJson(s),fallback:o}}getJson(e,t){s(this.#e);const{decoded:r,fallback:n}=this.#a(e,t);return r instanceof Map||r instanceof Set||Array.isArray(r)||o(r)?r:n}setDate(e,t){if(s(this.#e),this.#s(e),!(t instanceof Date))throw new TypeError("Value must be a Date.");const r=this.#i(e,t);return this.emit("setDate",e,t),this.#t.setItem(e,JSON.stringify(r))}getDate(e){s(this.#e);const t=this.#a(e).decoded;return t instanceof Date?t:null}setRegExp(e,t){if(s(this.#e),this.#s(e),!(t instanceof RegExp))throw new TypeError("Value must be a RegExp.");const r=this.#i(e,t);return this.emit("setRegExp",e,t),this.#t.setItem(e,JSON.stringify(r))}getRegExp(e){s(this.#e);const t=this.#a(e).decoded;return t instanceof RegExp?t:null}setBigInt(e,t){if(s(this.#e),this.#s(e),"bigint"!=typeof t)throw new TypeError("Value must be a BigInt.");const r=this.#i(e,t);return this.emit("setBigInt",e,t),this.#t.setItem(e,JSON.stringify(r))}getBigInt(e){s(this.#e);const t=this.#a(e).decoded;return"bigint"==typeof t?t:null}setSymbol(e,t){if(s(this.#e),this.#s(e),"symbol"!=typeof t)throw new TypeError("Value must be a Symbol.");const r=this.#i(e,t);return this.emit("setSymbol",e,t),this.#t.setItem(e,JSON.stringify(r))}getSymbol(e){s(this.#e);const t=this.#a(e).decoded;return"symbol"==typeof t?t:null}getValue(e){return s(this.#e),this.#a(e).decoded??null}setItem(e,t){if(s(this.#e),this.#s(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return this.emit("setItem",e,t),this.#t.setItem(e,t)}getItem(e){if(s(this.#e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return this.#t.getItem(e)}setString(e,t){if(s(this.#e),this.#s(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");if("string"!=typeof t)throw new TypeError("Value must be a string.");return this.emit("setString",e,t),this.#t.setItem(e,JSON.stringify({__string__:!0,value:t}))}getString(e){if(s(this.#e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");let t=this.#t.getItem(e);try{if(t=JSON.parse(t),!o(t)||!t.__string__||"string"!=typeof t.value)return null;t=t.value}catch{t=null}return"string"==typeof t?t:null}setNumber(e,t){if(s(this.#e),this.#s(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");if("number"!=typeof t)throw new TypeError("Value must be a number.");return this.emit("setNumber",e,t),this.#t.setItem(e,String(t))}getNumber(e){if(s(this.#e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");let t=this.#t.getItem(e);return"number"==typeof t||"string"==typeof t&&t.length>0&&(t=parseFloat(t),!Number.isNaN(t))?t:null}setBool(e,t){if(s(this.#e),this.#s(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");if("boolean"!=typeof t)throw new TypeError("Value must be a boolean.");return this.emit("setBool",e,t),this.#t.setItem(e,String(t))}getBool(e){if(s(this.#e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");const t=this.#t.getItem(e);if("boolean"==typeof t)return t;if("string"==typeof t){if("true"===t)return!0;if("false"===t)return!1}return null}removeItem(e){if(s(this.#e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return this.emit("removeItem",e),this.#t.removeItem(e)}clearLocalStorage(){return s(this.#e),this.#t.clear()}destroy(){this.#e||(window.removeEventListener("storage",this.#o),this.removeAllListeners(),this.#e=!0)}}c.registerJsonType(Map,(e,t)=>({__map__:!0,data:Array.from(e.entries()).map(([e,r])=>[e,t(r)])}),{check:e=>e.__map__,decode:(e,t)=>new Map(e.data.map(([e,r])=>[e,t(r)]))},!0),c.registerJsonType(Set,(e,t)=>({__set__:!0,data:Array.from(e).map(t)}),{check:e=>e.__set__,decode:(e,t)=>new Set(e.data.map(t))},!0),c.registerJsonType(Date,e=>({__date__:!0,value:e.toISOString()}),{check:e=>e.__date__,decode:e=>new Date(e.value)},!0),c.registerJsonType(RegExp,e=>({__regexp__:!0,source:e.source,flags:e.flags}),{check:e=>e.__regexp__,decode:e=>new RegExp(e.source,e.flags)},!0),c.registerJsonType("number",e=>({__number__:!0,value:e.toString()}),{check:e=>e.__number__,decode:e=>Number(e.value)},!0),c.registerJsonType("bigint",e=>({__bigint__:!0,value:e.toString()}),{check:e=>e.__bigint__,decode:e=>BigInt(e.value)},!0),c.registerJsonType("symbol",e=>({__symbol__:!0,key:Symbol.keyFor(e)??e.description??null}),{check:e=>e.__symbol__,decode:e=>{const t=e.key;return null!=t?Symbol.for(t):Symbol()}},!0);const u=c}};const t={};function r(n){const o=t[n];if(void 0!==o)return o.exports;const s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}r.d=(e,t)=>{if(Array.isArray(t))for(var n=0;n<t.length;){var o=t[n++],s=t[n++];r.o(e,o)?0===s&&n++:0===s?Object.defineProperty(e,o,{enumerable:!0,value:t[n++]}):Object.defineProperty(e,o,{enumerable:!0,get:s})}else for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.cjs=e=>{const t={exports:{}};return e.call(t.exports,t,t.exports),t.exports};let n=r(757);window.TinyLocalStorage=n.TinyLocalStorage})();
|
|
1
|
+
(()=>{"use strict";const e={cw:e=>{var t;return()=>{if(e){var r=e;e=0,t={exports:{}},r.call(t.exports,t,t.exports)}return t.exports}},d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};let t={};e.d(t,{TinyLocalStorage:()=>u});var r=e.cw(function(e,t){var r,n="object"==typeof Reflect?Reflect:null,o=n&&"function"==typeof n.apply?n.apply:function(e,t,r){return Function.prototype.apply.call(e,t,r)};r=n&&"function"==typeof n.ownKeys?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};var s=Number.isNaN||function(e){return e!=e};function i(){i.init.call(this)}e.exports=i,e.exports.once=function(e,t){return new Promise(function(r,n){function o(r){e.removeListener(t,s),n(r)}function s(){"function"==typeof e.removeListener&&e.removeListener("error",o),r([].slice.call(arguments))}g(e,t,s,{once:!0}),"error"!==t&&function(e,t){"function"==typeof e.on&&g(e,"error",t,{once:!0})}(e,o)})},i.EventEmitter=i,i.prototype._events=void 0,i.prototype._eventsCount=0,i.prototype._maxListeners=void 0;var a=10;function l(e){if("function"!=typeof e)throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}function c(e){return void 0===e._maxListeners?i.defaultMaxListeners:e._maxListeners}function u(e,t,r,n){var o,s,i,a;if(l(r),void 0===(s=e._events)?(s=e._events=Object.create(null),e._eventsCount=0):(void 0!==s.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),s=e._events),i=s[t]),void 0===i)i=s[t]=r,++e._eventsCount;else if("function"==typeof i?i=s[t]=n?[r,i]:[i,r]:n?i.unshift(r):i.push(r),(o=c(e))>0&&i.length>o&&!i.warned){i.warned=!0;var u=new Error("Possible EventEmitter memory leak detected. "+i.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");u.name="MaxListenersExceededWarning",u.emitter=e,u.type=t,u.count=i.length,a=u,console&&console.warn&&console.warn(a)}return e}function y(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,0===arguments.length?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function f(e,t,r){var n={fired:!1,wrapFn:void 0,target:e,type:t,listener:r},o=y.bind(n);return o.listener=r,n.wrapFn=o,o}function h(e,t,r){var n=e._events;if(void 0===n)return[];var o=n[t];return void 0===o?[]:"function"==typeof o?r?[o.listener||o]:[o]:r?function(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}(o):p(o,o.length)}function d(e){var t=this._events;if(void 0!==t){var r=t[e];if("function"==typeof r)return 1;if(void 0!==r)return r.length}return 0}function p(e,t){for(var r=new Array(t),n=0;n<t;++n)r[n]=e[n];return r}function g(e,t,r,n){if("function"==typeof e.on)n.once?e.once(t,r):e.on(t,r);else{if("function"!=typeof e.addEventListener)throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e);e.addEventListener(t,function o(s){n.once&&e.removeEventListener(t,o),r(s)})}}Object.defineProperty(i,"defaultMaxListeners",{enumerable:!0,get:function(){return a},set:function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");a=e}}),i.init=function(){void 0!==this._events&&this._events!==Object.getPrototypeOf(this)._events||(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},i.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||s(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this},i.prototype.getMaxListeners=function(){return c(this)},i.prototype.emit=function(e){for(var t=[],r=1;r<arguments.length;r++)t.push(arguments[r]);var n="error"===e,s=this._events;if(void 0!==s)n=n&&void 0===s.error;else if(!n)return!1;if(n){var i;if(t.length>0&&(i=t[0]),i instanceof Error)throw i;var a=new Error("Unhandled error."+(i?" ("+i.message+")":""));throw a.context=i,a}var l=s[e];if(void 0===l)return!1;if("function"==typeof l)o(l,this,t);else{var c=l.length,u=p(l,c);for(r=0;r<c;++r)o(u[r],this,t)}return!0},i.prototype.addListener=function(e,t){return u(this,e,t,!1)},i.prototype.on=i.prototype.addListener,i.prototype.prependListener=function(e,t){return u(this,e,t,!0)},i.prototype.once=function(e,t){return l(t),this.on(e,f(this,e,t)),this},i.prototype.prependOnceListener=function(e,t){return l(t),this.prependListener(e,f(this,e,t)),this},i.prototype.removeListener=function(e,t){var r,n,o,s,i;if(l(t),void 0===(n=this._events))return this;if(void 0===(r=n[e]))return this;if(r===t||r.listener===t)0===--this._eventsCount?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,r.listener||t));else if("function"!=typeof r){for(o=-1,s=r.length-1;s>=0;s--)if(r[s]===t||r[s].listener===t){i=r[s].listener,o=s;break}if(o<0)return this;0===o?r.shift():function(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}(r,o),1===r.length&&(n[e]=r[0]),void 0!==n.removeListener&&this.emit("removeListener",e,i||t)}return this},i.prototype.off=i.prototype.removeListener,i.prototype.removeAllListeners=function(e){var t,r,n;if(void 0===(r=this._events))return this;if(void 0===r.removeListener)return 0===arguments.length?(this._events=Object.create(null),this._eventsCount=0):void 0!==r[e]&&(0===--this._eventsCount?this._events=Object.create(null):delete r[e]),this;if(0===arguments.length){var o,s=Object.keys(r);for(n=0;n<s.length;++n)"removeListener"!==(o=s[n])&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if("function"==typeof(t=r[e]))this.removeListener(e,t);else if(void 0!==t)for(n=t.length-1;n>=0;n--)this.removeListener(e,t[n]);return this},i.prototype.listeners=function(e){return h(this,e,!0)},i.prototype.rawListeners=function(e){return h(this,e,!1)},i.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):d.call(e,t)},i.prototype.listenerCount=d,i.prototype.eventNames=function(){return this._eventsCount>0?r(this._events):[]}});function n(e){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"===Object.prototype.toString.call(e)}r();const o=e=>{if(e)throw new Error("This TinyLocalStorage instance has been destroyed and can no longer be used.")};const s=new Map,i=new Map,a=new Set(["string","boolean","object","array",String,Boolean,Number,Object,Array,BigInt,Symbol]),l=r().EventEmitter;class c extends l{static hasJsonType(e){return s.has(e)&&i.has(e)||a.has(e)}static registerJsonType(e,t,r,n=!1){if(a.has(e))throw new Error(`Cannot register type "${e}" because it is frozen.`);s.set(e,t),i.set(e,r),n&&a.add(e)}static deleteJsonType(e){if(a.has(e))throw new Error(`Cannot remove type "${e}" because it is frozen.`);let t=!1;return s.delete(e)&&(t=!0),i.delete(e)&&(t=!0),t}static encodeSpecialJson(e){if(void 0===e)return{__undefined__:!0};if(null===e)return{__null__:!0};for(const[t,r]of s.entries())if("string"!=typeof t&&e instanceof t||typeof e===t)return r(e,c.encodeSpecialJson);if(Array.isArray(e))return e.map(c.encodeSpecialJson);if(n(e)){const t={};for(const r in e)t[r]=c.encodeSpecialJson(e[r]);return t}return e}static decodeSpecialJson(e){const t=n(e);if(t){if(e.__undefined__)return;if(e.__null__)return null}if(Array.isArray(e))return e.map(c.decodeSpecialJson);if(t){for(const[t,r]of i.entries())if(r.check&&r.check(e))return r.decode(e,c.decodeSpecialJson);const t={};for(const r in e)t[r]=c.decodeSpecialJson(e[r]);return t}return e}#e=!1;get destroyed(){return this.#e}#t=window.localStorage;#r=null;#n=0;#o=e=>this.emit("storage",e);constructor(e){if(super(),void 0!==e&&"string"!=typeof e)throw new TypeError("TinyLocalStorage: dbName must be a string if provided.");"string"==typeof e&&(this.#r=`LSDB::${e}`),window.addEventListener("storage",this.#o)}#s(e){if("string"==typeof e&&e.startsWith("LSDB::"))throw new Error(`TinyLocalStorage: Key "${e}" may conflict with reserved dbKeys.`)}updateStorageVersion(e,t){if(o(this.#e),"string"!=typeof this.#r)throw new Error("TinyLocalStorage: Database key is not initialized. Set a valid dbName in the constructor.");if("number"!=typeof e||Number.isNaN(e)||e<1)throw new TypeError("TinyLocalStorage: version must be a positive number.");if("function"!=typeof t)throw new TypeError("TinyLocalStorage: onUpgrade must be a function.");const r=parseInt(localStorage.getItem(this.#r),10)||0;if("number"!=typeof r||Number.isNaN(r)||r<0)throw new TypeError("TinyLocalStorage: saved version in localStorage is not a valid number.");if(e<r)throw new Error(`TinyLocalStorage: Cannot downgrade database version from ${r} to ${e}.`);e>r&&(t(r,e),localStorage.setItem(this.#r,String(e)),this.#n=e)}getDbKey(){return o(this.#e),this.#r}getVersion(){return o(this.#e),this.#n}setLocalStorage(e){if(o(this.#e),!(e instanceof Storage))throw new TypeError("Argument must be a valid instance of Storage.");this.#t=e}localStorageExists(){return o(this.#e),this.#t instanceof Storage}#i(e,t){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return c.encodeSpecialJson(t)}setJson(e,t){if(o(this.#e),this.#s(e),!(n(t)||Array.isArray(t)||t instanceof Map||t instanceof Set))throw new TypeError("The storage value is not a valid JSON-compatible structure.");const r=this.#i(e,t);return this.emit("setJson",e,t),this.#t.setItem(e,JSON.stringify(r))}#a(e,t){if("string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");const r=this.#t.getItem(e),n={obj:()=>({}),array:()=>[],map:()=>new Map,set:()=>new Set},o="function"==typeof n[t]?n[t]():null;let s;try{s=JSON.parse(r)}catch{return o}return{decoded:c.decodeSpecialJson(s),fallback:o}}getJson(e,t){o(this.#e);const{decoded:r,fallback:s}=this.#a(e,t);return r instanceof Map||r instanceof Set||Array.isArray(r)||n(r)?r:s}setDate(e,t){if(o(this.#e),this.#s(e),!(t instanceof Date))throw new TypeError("Value must be a Date.");const r=this.#i(e,t);return this.emit("setDate",e,t),this.#t.setItem(e,JSON.stringify(r))}getDate(e){o(this.#e);const t=this.#a(e).decoded;return t instanceof Date?t:null}setRegExp(e,t){if(o(this.#e),this.#s(e),!(t instanceof RegExp))throw new TypeError("Value must be a RegExp.");const r=this.#i(e,t);return this.emit("setRegExp",e,t),this.#t.setItem(e,JSON.stringify(r))}getRegExp(e){o(this.#e);const t=this.#a(e).decoded;return t instanceof RegExp?t:null}setBigInt(e,t){if(o(this.#e),this.#s(e),"bigint"!=typeof t)throw new TypeError("Value must be a BigInt.");const r=this.#i(e,t);return this.emit("setBigInt",e,t),this.#t.setItem(e,JSON.stringify(r))}getBigInt(e){o(this.#e);const t=this.#a(e).decoded;return"bigint"==typeof t?t:null}setSymbol(e,t){if(o(this.#e),this.#s(e),"symbol"!=typeof t)throw new TypeError("Value must be a Symbol.");const r=this.#i(e,t);return this.emit("setSymbol",e,t),this.#t.setItem(e,JSON.stringify(r))}getSymbol(e){o(this.#e);const t=this.#a(e).decoded;return"symbol"==typeof t?t:null}getValue(e){return o(this.#e),this.#a(e).decoded??null}setItem(e,t){if(o(this.#e),this.#s(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return this.emit("setItem",e,t),this.#t.setItem(e,t)}getItem(e){if(o(this.#e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return this.#t.getItem(e)}setString(e,t){if(o(this.#e),this.#s(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");if("string"!=typeof t)throw new TypeError("Value must be a string.");return this.emit("setString",e,t),this.#t.setItem(e,JSON.stringify({__string__:!0,value:t}))}getString(e){if(o(this.#e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");let t=this.#t.getItem(e);try{if(t=JSON.parse(t),!n(t)||!t.__string__||"string"!=typeof t.value)return null;t=t.value}catch{t=null}return"string"==typeof t?t:null}setNumber(e,t){if(o(this.#e),this.#s(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");if("number"!=typeof t)throw new TypeError("Value must be a number.");return this.emit("setNumber",e,t),this.#t.setItem(e,String(t))}getNumber(e){if(o(this.#e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");let t=this.#t.getItem(e);return"number"==typeof t||"string"==typeof t&&t.length>0&&(t=parseFloat(t),!Number.isNaN(t))?t:null}setBool(e,t){if(o(this.#e),this.#s(e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");if("boolean"!=typeof t)throw new TypeError("Value must be a boolean.");return this.emit("setBool",e,t),this.#t.setItem(e,String(t))}getBool(e){if(o(this.#e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");const t=this.#t.getItem(e);if("boolean"==typeof t)return t;if("string"==typeof t){if("true"===t)return!0;if("false"===t)return!1}return null}removeItem(e){if(o(this.#e),"string"!=typeof e||!e.length)throw new TypeError("Key must be a non-empty string.");return this.emit("removeItem",e),this.#t.removeItem(e)}clearLocalStorage(){return o(this.#e),this.#t.clear()}destroy(){this.#e||(window.removeEventListener("storage",this.#o),this.removeAllListeners(),this.#e=!0)}}c.registerJsonType(Map,(e,t)=>({__map__:!0,data:Array.from(e.entries()).map(([e,r])=>[e,t(r)])}),{check:e=>e.__map__,decode:(e,t)=>new Map(e.data.map(([e,r])=>[e,t(r)]))},!0),c.registerJsonType(Set,(e,t)=>({__set__:!0,data:Array.from(e).map(t)}),{check:e=>e.__set__,decode:(e,t)=>new Set(e.data.map(t))},!0),c.registerJsonType(Date,e=>({__date__:!0,value:e.toISOString()}),{check:e=>e.__date__,decode:e=>new Date(e.value)},!0),c.registerJsonType(RegExp,e=>({__regexp__:!0,source:e.source,flags:e.flags}),{check:e=>e.__regexp__,decode:e=>new RegExp(e.source,e.flags)},!0),c.registerJsonType("number",e=>({__number__:!0,value:e.toString()}),{check:e=>e.__number__,decode:e=>Number(e.value)},!0),c.registerJsonType("bigint",e=>({__bigint__:!0,value:e.toString()}),{check:e=>e.__bigint__,decode:e=>BigInt(e.value)},!0),c.registerJsonType("symbol",e=>({__symbol__:!0,key:Symbol.keyFor(e)??e.description??null}),{check:e=>e.__symbol__,decode:e=>{const t=e.key;return null!=t?Symbol.for(t):Symbol()}},!0);const u=c;window.TinyLocalStorage=t.TinyLocalStorage})();
|