react-native-inapp-inspector 2.3.19 → 2.3.21
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 +14 -14
- package/android/src/main/java/com/inappinspector/NetworkInspectorModule.kt +67 -0
- package/dist/commonjs/analytics.js +1 -24
- package/dist/commonjs/bundle.js +1 -16
- package/dist/commonjs/capture.js +1 -35
- package/dist/commonjs/components/AnalyticsDetail.js +92 -623
- package/dist/commonjs/components/AnalyticsEventCard.js +54 -350
- package/dist/commonjs/components/AnalyticsGraph.js +70 -370
- package/dist/commonjs/components/AnimatedEntrance.js +1 -11
- package/dist/commonjs/components/AppHeaderLogo.js +7 -134
- package/dist/commonjs/components/BrandCircleIcon.js +73 -118
- package/dist/commonjs/components/BrandSquareIcon.js +63 -108
- package/dist/commonjs/components/CodeSnippet.js +48 -623
- package/dist/commonjs/components/ConsoleLogCard.js +63 -537
- package/dist/commonjs/components/CopyButton.js +3 -89
- package/dist/commonjs/components/DiffViewer.js +19 -83
- package/dist/commonjs/components/DomainHeader.js +27 -127
- package/dist/commonjs/components/EmptyState.js +10 -87
- package/dist/commonjs/components/EndOfListFooter.js +7 -81
- package/dist/commonjs/components/ErrorBoundary.js +72 -566
- package/dist/commonjs/components/HeadersSection.js +31 -110
- package/dist/commonjs/components/HighlightText.js +17 -58
- package/dist/commonjs/components/Inspector/AboutModal.d.ts +6 -0
- package/dist/commonjs/components/Inspector/AboutModal.js +243 -0
- package/dist/commonjs/components/Inspector/AnalyticsFilterModal.js +98 -797
- package/dist/commonjs/components/Inspector/AnalyticsTab.js +284 -930
- package/dist/commonjs/components/Inspector/BundleTab.js +551 -2918
- package/dist/commonjs/components/Inspector/ConsoleTab.js +79 -492
- package/dist/commonjs/components/Inspector/CrashDetail.js +123 -672
- package/dist/commonjs/components/Inspector/CrashFilterModal.js +66 -498
- package/dist/commonjs/components/Inspector/CrashTab.js +98 -670
- package/dist/commonjs/components/Inspector/DebuggingTab.js +74 -875
- package/dist/commonjs/components/Inspector/DeviceInfoTab.js +143 -907
- package/dist/commonjs/components/Inspector/FabLauncher.js +42 -466
- package/dist/commonjs/components/Inspector/FeatureUnderDevNotice.js +6 -99
- package/dist/commonjs/components/Inspector/InspectorContext.js +1 -21
- package/dist/commonjs/components/Inspector/InspectorHeader.js +191 -1110
- package/dist/commonjs/components/Inspector/LogDetail.js +168 -994
- package/dist/commonjs/components/Inspector/MainScreen.js +52 -335
- package/dist/commonjs/components/Inspector/MediaGalleryTab.js +97 -644
- package/dist/commonjs/components/Inspector/MediaPreviewModal.js +90 -605
- package/dist/commonjs/components/Inspector/NavigationTracker.js +1 -12
- package/dist/commonjs/components/Inspector/NetworkDetail.js +89 -411
- package/dist/commonjs/components/Inspector/NetworkFilterModal.js +60 -576
- package/dist/commonjs/components/Inspector/NetworkTab.js +84 -514
- package/dist/commonjs/components/Inspector/NpmStarPrompt.js +18 -434
- package/dist/commonjs/components/Inspector/NpmUpdateToast.js +25 -298
- package/dist/commonjs/components/Inspector/PerformanceTab.js +182 -1397
- package/dist/commonjs/components/Inspector/ReduxDetail.js +188 -1089
- package/dist/commonjs/components/Inspector/ReduxTab.js +85 -701
- package/dist/commonjs/components/Inspector/SettingsPanel.js +427 -3807
- package/dist/commonjs/components/Inspector/SkeletonPlaceholder.js +11 -180
- package/dist/commonjs/components/Inspector/StorageTab.js +93 -826
- package/dist/commonjs/components/Inspector/TabBar.js +36 -334
- package/dist/commonjs/components/Inspector/UpdateAvailableModal.js +37 -412
- package/dist/commonjs/components/JsonViewer.js +168 -381
- package/dist/commonjs/components/LogCard.js +57 -567
- package/dist/commonjs/components/LogSyntaxHighlighter.js +11 -130
- package/dist/commonjs/components/MetaAccordion.js +69 -238
- package/dist/commonjs/components/MiniBarChart.js +3 -56
- package/dist/commonjs/components/MiniLineChart.js +3 -58
- package/dist/commonjs/components/NetworkIcons.d.ts +13 -0
- package/dist/commonjs/components/NetworkIcons.js +521 -1022
- package/dist/commonjs/components/QRCodeView.js +5 -79
- package/dist/commonjs/components/SectionHeader.js +15 -37
- package/dist/commonjs/components/SegmentedTabs.js +7 -62
- package/dist/commonjs/components/SkeletonPlaceholder.js +11 -180
- package/dist/commonjs/components/Slider.js +15 -243
- package/dist/commonjs/components/SourcePageCard.js +30 -89
- package/dist/commonjs/components/Toast.js +5 -147
- package/dist/commonjs/components/TouchableScale.js +3 -24
- package/dist/commonjs/components/TreeNode.js +55 -130
- package/dist/commonjs/console.js +1 -16
- package/dist/commonjs/constants/index.js +1 -32
- package/dist/commonjs/constants/telemetryConfig.js +1 -6
- package/dist/commonjs/constants/version.d.ts +1 -1
- package/dist/commonjs/constants/version.js +1 -4
- package/dist/commonjs/crash.js +1 -23
- package/dist/commonjs/customHooks/analyticsLogger.js +1 -250
- package/dist/commonjs/customHooks/bundleAnalyzer.js +1 -957
- package/dist/commonjs/customHooks/consoleLogger.js +6 -445
- package/dist/commonjs/customHooks/crashHandler.js +7 -656
- package/dist/commonjs/customHooks/logFilters.js +1 -23
- package/dist/commonjs/customHooks/networkLogger.js +2 -536
- package/dist/commonjs/customHooks/performanceTracker.js +63 -750
- package/dist/commonjs/customHooks/reduxLogger.js +2 -313
- package/dist/commonjs/customHooks/storageInspector.js +1 -435
- package/dist/commonjs/customHooks/useAccordion.js +1 -18
- package/dist/commonjs/decorators/index.js +1 -100
- package/dist/commonjs/helpers/gaAnalyticsRegistry.js +1 -148
- package/dist/commonjs/helpers/index.d.ts +1 -0
- package/dist/commonjs/helpers/index.js +8 -921
- package/dist/commonjs/helpers/memoryManager.js +1 -99
- package/dist/commonjs/helpers/qrGenerator.js +1 -367
- package/dist/commonjs/helpers/remoteConfig.js +1 -165
- package/dist/commonjs/helpers/searchQueryParser.js +1 -62
- package/dist/commonjs/helpers/settingsStore.js +1 -144
- package/dist/commonjs/helpers/telemetry.js +1 -501
- package/dist/commonjs/helpers/toast.js +1 -20
- package/dist/commonjs/i18n/index.js +1 -90
- package/dist/commonjs/i18n/locales/en.json +1 -1140
- package/dist/commonjs/index.js +5 -2168
- package/dist/commonjs/metro.js +6 -468
- package/dist/commonjs/native/NativeInspector.d.ts +1 -0
- package/dist/commonjs/native/NativeInspector.js +1 -415
- package/dist/commonjs/native/NativeNetworkInspector.js +1 -4
- package/dist/commonjs/network.js +1 -13
- package/dist/commonjs/performance.js +1 -29
- package/dist/commonjs/redux.js +1 -20
- package/dist/commonjs/storage.js +1 -14
- package/dist/commonjs/styles/AppColors.js +1 -423
- package/dist/commonjs/styles/AppFonts.js +1 -17
- package/dist/commonjs/styles/common.js +1 -190
- package/dist/commonjs/styles/index.d.ts +6 -0
- package/dist/commonjs/styles/index.js +1 -1589
- package/dist/commonjs/types/enums.d.ts +0 -1
- package/dist/commonjs/types/enums.js +1 -152
- package/dist/commonjs/types/index.js +1 -18
- package/dist/commonjs/types/interfaces.d.ts +2 -2
- package/dist/commonjs/types/interfaces.js +1 -2
- package/dist/esm/analytics.js +1 -2
- package/dist/esm/bundle.js +1 -2
- package/dist/esm/capture.js +1 -32
- package/dist/esm/components/AnalyticsDetail.js +171 -664
- package/dist/esm/components/AnalyticsEventCard.js +77 -335
- package/dist/esm/components/AnalyticsGraph.js +95 -357
- package/dist/esm/components/AnimatedEntrance.js +1 -6
- package/dist/esm/components/AppHeaderLogo.js +7 -94
- package/dist/esm/components/BrandCircleIcon.js +114 -119
- package/dist/esm/components/BrandSquareIcon.js +73 -78
- package/dist/esm/components/CodeSnippet.js +58 -595
- package/dist/esm/components/ConsoleLogCard.js +91 -526
- package/dist/esm/components/CopyButton.js +3 -51
- package/dist/esm/components/DiffViewer.js +22 -48
- package/dist/esm/components/DomainHeader.js +43 -138
- package/dist/esm/components/EmptyState.js +17 -56
- package/dist/esm/components/EndOfListFooter.js +15 -83
- package/dist/esm/components/ErrorBoundary.js +125 -582
- package/dist/esm/components/HeadersSection.js +52 -93
- package/dist/esm/components/HighlightText.js +17 -53
- package/dist/esm/components/Inspector/AboutModal.d.ts +6 -0
- package/dist/esm/components/Inspector/AboutModal.js +243 -0
- package/dist/esm/components/Inspector/AnalyticsFilterModal.js +225 -886
- package/dist/esm/components/Inspector/AnalyticsTab.js +296 -904
- package/dist/esm/components/Inspector/BundleTab.js +1175 -3502
- package/dist/esm/components/Inspector/ConsoleTab.js +113 -488
- package/dist/esm/components/Inspector/CrashDetail.js +236 -747
- package/dist/esm/components/Inspector/CrashFilterModal.js +149 -541
- package/dist/esm/components/Inspector/CrashTab.js +177 -711
- package/dist/esm/components/Inspector/DebuggingTab.js +164 -925
- package/dist/esm/components/Inspector/DeviceInfoTab.js +199 -924
- package/dist/esm/components/Inspector/FabLauncher.js +68 -454
- package/dist/esm/components/Inspector/FeatureUnderDevNotice.js +14 -70
- package/dist/esm/components/Inspector/InspectorContext.js +1 -12
- package/dist/esm/components/Inspector/InspectorHeader.js +282 -1163
- package/dist/esm/components/Inspector/LogDetail.js +235 -1023
- package/dist/esm/components/Inspector/MainScreen.js +78 -323
- package/dist/esm/components/Inspector/MediaGalleryTab.js +143 -650
- package/dist/esm/components/Inspector/MediaPreviewModal.js +138 -613
- package/dist/esm/components/Inspector/NavigationTracker.js +1 -10
- package/dist/esm/components/Inspector/NetworkDetail.js +138 -455
- package/dist/esm/components/Inspector/NetworkFilterModal.js +122 -597
- package/dist/esm/components/Inspector/NetworkTab.js +125 -517
- package/dist/esm/components/Inspector/NpmStarPrompt.js +58 -434
- package/dist/esm/components/Inspector/NpmUpdateToast.js +45 -281
- package/dist/esm/components/Inspector/PerformanceTab.js +393 -1570
- package/dist/esm/components/Inspector/ReduxDetail.js +307 -1170
- package/dist/esm/components/Inspector/ReduxTab.js +144 -722
- package/dist/esm/components/Inspector/SettingsPanel.js +643 -3985
- package/dist/esm/components/Inspector/SkeletonPlaceholder.js +30 -163
- package/dist/esm/components/Inspector/StorageTab.js +172 -866
- package/dist/esm/components/Inspector/TabBar.js +45 -305
- package/dist/esm/components/Inspector/UpdateAvailableModal.js +80 -418
- package/dist/esm/components/JsonViewer.js +179 -354
- package/dist/esm/components/LogCard.js +93 -565
- package/dist/esm/components/LogSyntaxHighlighter.js +11 -123
- package/dist/esm/components/MetaAccordion.js +136 -267
- package/dist/esm/components/MiniBarChart.js +3 -18
- package/dist/esm/components/MiniLineChart.js +3 -20
- package/dist/esm/components/NetworkIcons.d.ts +13 -0
- package/dist/esm/components/NetworkIcons.js +523 -838
- package/dist/esm/components/QRCodeView.js +8 -45
- package/dist/esm/components/SectionHeader.js +22 -39
- package/dist/esm/components/SegmentedTabs.js +8 -58
- package/dist/esm/components/SkeletonPlaceholder.js +30 -163
- package/dist/esm/components/Slider.js +24 -213
- package/dist/esm/components/SourcePageCard.js +65 -86
- package/dist/esm/components/Toast.js +10 -117
- package/dist/esm/components/TouchableScale.js +3 -19
- package/dist/esm/components/TreeNode.js +58 -95
- package/dist/esm/console.js +1 -2
- package/dist/esm/constants/index.js +1 -28
- package/dist/esm/constants/telemetryConfig.js +1 -3
- package/dist/esm/constants/version.d.ts +1 -1
- package/dist/esm/constants/version.js +1 -1
- package/dist/esm/crash.js +1 -2
- package/dist/esm/customHooks/analyticsLogger.js +1 -230
- package/dist/esm/customHooks/bundleAnalyzer.js +1 -944
- package/dist/esm/customHooks/consoleLogger.js +6 -432
- package/dist/esm/customHooks/crashHandler.js +7 -630
- package/dist/esm/customHooks/logFilters.js +1 -20
- package/dist/esm/customHooks/networkLogger.js +2 -519
- package/dist/esm/customHooks/performanceTracker.js +63 -723
- package/dist/esm/customHooks/reduxLogger.js +2 -293
- package/dist/esm/customHooks/storageInspector.js +1 -418
- package/dist/esm/customHooks/useAccordion.js +1 -16
- package/dist/esm/decorators/index.js +1 -95
- package/dist/esm/helpers/gaAnalyticsRegistry.js +1 -143
- package/dist/esm/helpers/index.d.ts +1 -0
- package/dist/esm/helpers/index.js +8 -861
- package/dist/esm/helpers/memoryManager.js +1 -91
- package/dist/esm/helpers/qrGenerator.js +1 -364
- package/dist/esm/helpers/remoteConfig.js +1 -160
- package/dist/esm/helpers/searchQueryParser.js +1 -59
- package/dist/esm/helpers/settingsStore.js +1 -134
- package/dist/esm/helpers/telemetry.js +1 -489
- package/dist/esm/helpers/toast.js +1 -15
- package/dist/esm/i18n/index.js +1 -78
- package/dist/esm/i18n/locales/en.json +1 -1140
- package/dist/esm/index.js +7 -1982
- package/dist/esm/metro.js +6 -459
- package/dist/esm/native/NativeInspector.d.ts +1 -0
- package/dist/esm/native/NativeInspector.js +1 -382
- package/dist/esm/native/NativeNetworkInspector.js +1 -2
- package/dist/esm/network.js +1 -1
- package/dist/esm/performance.js +1 -2
- package/dist/esm/redux.js +1 -1
- package/dist/esm/storage.js +1 -1
- package/dist/esm/styles/AppColors.js +1 -417
- package/dist/esm/styles/AppFonts.js +1 -13
- package/dist/esm/styles/common.js +1 -186
- package/dist/esm/styles/index.d.ts +6 -0
- package/dist/esm/styles/index.js +1 -1551
- package/dist/esm/types/enums.d.ts +0 -1
- package/dist/esm/types/enums.js +1 -149
- package/dist/esm/types/index.js +1 -2
- package/dist/esm/types/interfaces.d.ts +2 -2
- package/dist/esm/types/interfaces.js +1 -1
- package/ios/NetworkInspectorModule.mm +60 -12
- package/package.json +5 -3
- package/src/native/NativeInspector.ts +18 -0
- package/dist/commonjs/components/Inspector/FeedbackModal.d.ts +0 -7
- package/dist/commonjs/components/Inspector/FeedbackModal.js +0 -552
- package/dist/esm/components/Inspector/FeedbackModal.d.ts +0 -7
- package/dist/esm/components/Inspector/FeedbackModal.js +0 -515
- package/src/analytics.ts +0 -35
- package/src/bundle.ts +0 -25
- package/src/capture.ts +0 -109
- package/src/components/AnalyticsDetail.tsx +0 -870
- package/src/components/AnalyticsEventCard.tsx +0 -444
- package/src/components/AnalyticsGraph.tsx +0 -583
- package/src/components/AnimatedEntrance.tsx +0 -20
- package/src/components/AppHeaderLogo.tsx +0 -143
- package/src/components/BrandCircleIcon.tsx +0 -144
- package/src/components/BrandSquareIcon.tsx +0 -184
- package/src/components/CodeSnippet.tsx +0 -725
- package/src/components/ConsoleLogCard.tsx +0 -679
- package/src/components/CopyButton.tsx +0 -87
- package/src/components/DiffViewer.tsx +0 -82
- package/src/components/DomainHeader.tsx +0 -224
- package/src/components/EmptyState.tsx +0 -97
- package/src/components/EndOfListFooter.tsx +0 -100
- package/src/components/ErrorBoundary.tsx +0 -688
- package/src/components/HeadersSection.tsx +0 -172
- package/src/components/HighlightText.tsx +0 -100
- package/src/components/Inspector/AnalyticsFilterModal.tsx +0 -1250
- package/src/components/Inspector/AnalyticsTab.tsx +0 -1362
- package/src/components/Inspector/BundleTab.tsx +0 -4768
- package/src/components/Inspector/ConsoleTab.tsx +0 -726
- package/src/components/Inspector/CrashDetail.tsx +0 -997
- package/src/components/Inspector/CrashFilterModal.tsx +0 -721
- package/src/components/Inspector/CrashTab.tsx +0 -933
- package/src/components/Inspector/DebuggingTab.tsx +0 -1103
- package/src/components/Inspector/DeviceInfoTab.tsx +0 -1397
- package/src/components/Inspector/FabLauncher.tsx +0 -590
- package/src/components/Inspector/FeatureUnderDevNotice.tsx +0 -94
- package/src/components/Inspector/FeedbackModal.tsx +0 -626
- package/src/components/Inspector/InspectorContext.tsx +0 -28
- package/src/components/Inspector/InspectorHeader.tsx +0 -1583
- package/src/components/Inspector/LogDetail.tsx +0 -1431
- package/src/components/Inspector/MainScreen.tsx +0 -460
- package/src/components/Inspector/MediaGalleryTab.tsx +0 -829
- package/src/components/Inspector/MediaPreviewModal.tsx +0 -783
- package/src/components/Inspector/NavigationTracker.tsx +0 -13
- package/src/components/Inspector/NetworkDetail.tsx +0 -778
- package/src/components/Inspector/NetworkFilterModal.tsx +0 -730
- package/src/components/Inspector/NetworkTab.tsx +0 -820
- package/src/components/Inspector/NpmStarPrompt.tsx +0 -532
- package/src/components/Inspector/NpmUpdateToast.tsx +0 -387
- package/src/components/Inspector/PerformanceTab.tsx +0 -1967
- package/src/components/Inspector/ReduxDetail.tsx +0 -1651
- package/src/components/Inspector/ReduxTab.tsx +0 -987
- package/src/components/Inspector/SettingsPanel.tsx +0 -5136
- package/src/components/Inspector/SkeletonPlaceholder.tsx +0 -206
- package/src/components/Inspector/StorageTab.tsx +0 -1159
- package/src/components/Inspector/TabBar.tsx +0 -431
- package/src/components/Inspector/UpdateAvailableModal.tsx +0 -555
- package/src/components/JsonViewer.tsx +0 -549
- package/src/components/LogCard.tsx +0 -694
- package/src/components/LogSyntaxHighlighter.tsx +0 -178
- package/src/components/MetaAccordion.tsx +0 -355
- package/src/components/MiniBarChart.tsx +0 -42
- package/src/components/MiniLineChart.tsx +0 -33
- package/src/components/NetworkIcons.tsx +0 -2655
- package/src/components/QRCodeView.tsx +0 -75
- package/src/components/SectionHeader.tsx +0 -101
- package/src/components/SegmentedTabs.tsx +0 -84
- package/src/components/SkeletonPlaceholder.tsx +0 -206
- package/src/components/Slider.tsx +0 -300
- package/src/components/SourcePageCard.tsx +0 -150
- package/src/components/Toast.tsx +0 -131
- package/src/components/TouchableScale.tsx +0 -61
- package/src/components/TreeNode.tsx +0 -171
- package/src/console.ts +0 -24
- package/src/constants/index.ts +0 -41
- package/src/constants/telemetryConfig.ts +0 -4
- package/src/constants/version.ts +0 -3
- package/src/crash.ts +0 -32
- package/src/customHooks/analyticsLogger.ts +0 -336
- package/src/customHooks/bundleAnalyzer.ts +0 -1256
- package/src/customHooks/consoleLogger.ts +0 -530
- package/src/customHooks/crashHandler.ts +0 -944
- package/src/customHooks/logFilters.ts +0 -32
- package/src/customHooks/networkLogger.ts +0 -624
- package/src/customHooks/performanceTracker.ts +0 -1014
- package/src/customHooks/reduxLogger.ts +0 -406
- package/src/customHooks/storageInspector.ts +0 -513
- package/src/customHooks/useAccordion.tsx +0 -27
- package/src/decorators/index.ts +0 -184
- package/src/helpers/gaAnalyticsRegistry.ts +0 -204
- package/src/helpers/index.ts +0 -1092
- package/src/helpers/memoryManager.ts +0 -138
- package/src/helpers/qrGenerator.ts +0 -430
- package/src/helpers/remoteConfig.ts +0 -212
- package/src/helpers/searchQueryParser.ts +0 -84
- package/src/helpers/settingsStore.ts +0 -171
- package/src/helpers/telemetry.ts +0 -568
- package/src/helpers/toast.ts +0 -17
- package/src/i18n/index.ts +0 -104
- package/src/i18n/locales/en.json +0 -1141
- package/src/index.tsx +0 -2650
- package/src/metro.ts +0 -598
- package/src/network.ts +0 -22
- package/src/performance.ts +0 -38
- package/src/redux.ts +0 -23
- package/src/storage.ts +0 -18
- package/src/styles/AppColors.ts +0 -455
- package/src/styles/AppFonts.ts +0 -26
- package/src/styles/common.ts +0 -209
- package/src/styles/index.ts +0 -1606
- package/src/types/enums.ts +0 -210
- package/src/types/index.ts +0 -34
- package/src/types/interfaces.ts +0 -535
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import {AppState, NativeEventSubscription, Platform} from 'react-native';
|
|
2
|
-
import {pruneNetworkLogs} from '../customHooks/networkLogger';
|
|
3
|
-
import {pruneConsoleLogs} from '../customHooks/consoleLogger';
|
|
4
|
-
import {pruneReduxHistory} from '../customHooks/reduxLogger';
|
|
5
|
-
import {pruneAnalyticsLogs} from '../customHooks/analyticsLogger';
|
|
6
|
-
import {pruneCrashRecords, addCrashBreadcrumb} from '../customHooks/crashHandler';
|
|
7
|
-
import {prunePerformanceEvents} from '../customHooks/performanceTracker';
|
|
8
|
-
import {showToast} from './toast';
|
|
9
|
-
|
|
10
|
-
export interface MemoryPruneSummary {
|
|
11
|
-
timestamp: number;
|
|
12
|
-
prunedNetwork: number;
|
|
13
|
-
prunedConsole: number;
|
|
14
|
-
prunedRedux: number;
|
|
15
|
-
prunedAnalytics: number;
|
|
16
|
-
prunedCrashes: number;
|
|
17
|
-
prunedPerformance: number;
|
|
18
|
-
totalPruned: number;
|
|
19
|
-
triggeredBy: 'memory-warning' | 'manual' | 'ram-threshold';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
type MemoryWarningListener = (summary: MemoryPruneSummary) => void;
|
|
23
|
-
|
|
24
|
-
const memoryListeners = new Set<MemoryWarningListener>();
|
|
25
|
-
let appStateSubscription: NativeEventSubscription | null = null;
|
|
26
|
-
let isMemoryWarningHandlerActive = false;
|
|
27
|
-
let lastPruneTimestamp = 0;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Prunes all in-memory log stores to prevent OOM / memory pressure.
|
|
31
|
-
* Keeps targetRetentionPct (default: 50%) of existing logs.
|
|
32
|
-
*/
|
|
33
|
-
export const pruneAllLogs = (
|
|
34
|
-
triggeredBy: MemoryPruneSummary['triggeredBy'] = 'manual',
|
|
35
|
-
targetRetentionPct: number = 0.5,
|
|
36
|
-
): MemoryPruneSummary => {
|
|
37
|
-
const targetPct = Math.max(0.1, Math.min(1.0, targetRetentionPct));
|
|
38
|
-
|
|
39
|
-
const prunedNetwork = pruneNetworkLogs(undefined);
|
|
40
|
-
const prunedConsole = pruneConsoleLogs(undefined);
|
|
41
|
-
const prunedRedux = pruneReduxHistory(undefined);
|
|
42
|
-
const prunedAnalytics = pruneAnalyticsLogs(undefined);
|
|
43
|
-
const prunedCrashes = pruneCrashRecords(undefined);
|
|
44
|
-
const prunedPerformance = prunePerformanceEvents(undefined);
|
|
45
|
-
|
|
46
|
-
const totalPruned =
|
|
47
|
-
prunedNetwork +
|
|
48
|
-
prunedConsole +
|
|
49
|
-
prunedRedux +
|
|
50
|
-
prunedAnalytics +
|
|
51
|
-
prunedCrashes +
|
|
52
|
-
prunedPerformance;
|
|
53
|
-
|
|
54
|
-
lastPruneTimestamp = Date.now();
|
|
55
|
-
|
|
56
|
-
// Trigger Hermes/V8 Garbage Collection if exposed
|
|
57
|
-
if (typeof (globalThis as any).gc === 'function') {
|
|
58
|
-
try {
|
|
59
|
-
(globalThis as any).gc();
|
|
60
|
-
} catch {}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const summary: MemoryPruneSummary = {
|
|
64
|
-
timestamp: lastPruneTimestamp,
|
|
65
|
-
prunedNetwork,
|
|
66
|
-
prunedConsole,
|
|
67
|
-
prunedRedux,
|
|
68
|
-
prunedAnalytics,
|
|
69
|
-
prunedCrashes,
|
|
70
|
-
prunedPerformance,
|
|
71
|
-
totalPruned,
|
|
72
|
-
triggeredBy,
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
addCrashBreadcrumb(
|
|
77
|
-
'system',
|
|
78
|
-
`[MemoryManager] Low memory auto-prune executed (${triggeredBy}). Freed ${totalPruned} log records.`,
|
|
79
|
-
summary,
|
|
80
|
-
);
|
|
81
|
-
} catch {}
|
|
82
|
-
|
|
83
|
-
memoryListeners.forEach(listener => {
|
|
84
|
-
try {
|
|
85
|
-
listener(summary);
|
|
86
|
-
} catch {}
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
return summary;
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Starts listening to OS memory pressure warnings via AppState 'memoryWarning'.
|
|
94
|
-
* Automatically prunes logs and notifies subscribers when memory is constrained.
|
|
95
|
-
*/
|
|
96
|
-
export const setupMemoryWarningHandler = (): (() => void) => {
|
|
97
|
-
if (isMemoryWarningHandlerActive) {
|
|
98
|
-
return () => {};
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
isMemoryWarningHandlerActive = true;
|
|
102
|
-
|
|
103
|
-
try {
|
|
104
|
-
appStateSubscription = AppState.addEventListener('memoryWarning' as any, (state: any) => {
|
|
105
|
-
const summary = pruneAllLogs('memory-warning', 0.5);
|
|
106
|
-
try {
|
|
107
|
-
showToast(`Memory Warning: Auto-pruned ${summary.totalPruned} inspector logs`);
|
|
108
|
-
} catch {}
|
|
109
|
-
});
|
|
110
|
-
} catch (e) {
|
|
111
|
-
// AppState memoryWarning might not be supported on all mock/test platforms
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
return () => {
|
|
115
|
-
if (appStateSubscription) {
|
|
116
|
-
try {
|
|
117
|
-
appStateSubscription.remove();
|
|
118
|
-
} catch {}
|
|
119
|
-
appStateSubscription = null;
|
|
120
|
-
}
|
|
121
|
-
isMemoryWarningHandlerActive = false;
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Subscribes to memory prune events.
|
|
127
|
-
*/
|
|
128
|
-
export const subscribeMemoryWarning = (
|
|
129
|
-
listener: MemoryWarningListener,
|
|
130
|
-
): (() => void) => {
|
|
131
|
-
memoryListeners.add(listener);
|
|
132
|
-
return () => {
|
|
133
|
-
memoryListeners.delete(listener);
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
export const getLastPruneTimestamp = (): number => lastPruneTimestamp;
|
|
138
|
-
export const isMemoryHandlerActive = (): boolean => isMemoryWarningHandlerActive;
|
|
@@ -1,430 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Zero-Dependency Pure TypeScript ISO/IEC 18004 QR Code Matrix Generator.
|
|
3
|
-
* Self-contained engine with Reed-Solomon Error Correction & BCH Format encoding.
|
|
4
|
-
* 100% compatible with Android Camera & Google Lens.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
export type QRECC = 'L' | 'M' | 'Q' | 'H';
|
|
8
|
-
|
|
9
|
-
const QR_ECC_LEVEL: Record<QRECC, number> = {
|
|
10
|
-
L: 1,
|
|
11
|
-
M: 0,
|
|
12
|
-
Q: 3,
|
|
13
|
-
H: 2,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// Galois field tables for GF(256)
|
|
17
|
-
const EXP_TABLE = new Uint8Array(256);
|
|
18
|
-
const LOG_TABLE = new Uint8Array(256);
|
|
19
|
-
|
|
20
|
-
(function initGaloisField() {
|
|
21
|
-
let x = 1;
|
|
22
|
-
for (let i = 0; i < 255; i++) {
|
|
23
|
-
EXP_TABLE[i] = x;
|
|
24
|
-
LOG_TABLE[x] = i;
|
|
25
|
-
x <<= 1;
|
|
26
|
-
if (x & 0x100) {
|
|
27
|
-
x ^= 0x11d; // GF(256) polynomial: x^8 + x^4 + x^3 + x^2 + 1
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
EXP_TABLE[255] = EXP_TABLE[0];
|
|
31
|
-
})();
|
|
32
|
-
|
|
33
|
-
function glog(n: number): number {
|
|
34
|
-
if (n < 1) throw new Error(`glog(${n})`);
|
|
35
|
-
return LOG_TABLE[n]!;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function gexp(n: number): number {
|
|
39
|
-
while (n < 0) n += 255;
|
|
40
|
-
while (n >= 256) n -= 255;
|
|
41
|
-
return EXP_TABLE[n]!;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
class Polynomial {
|
|
45
|
-
num: number[];
|
|
46
|
-
constructor(num: number[], shift = 0) {
|
|
47
|
-
let offset = 0;
|
|
48
|
-
while (offset < num.length && num[offset] === 0) {
|
|
49
|
-
offset++;
|
|
50
|
-
}
|
|
51
|
-
this.num = new Array(num.length - offset + shift);
|
|
52
|
-
for (let i = 0; i < num.length - offset; i++) {
|
|
53
|
-
this.num[i] = num[i + offset]!;
|
|
54
|
-
}
|
|
55
|
-
for (let i = num.length - offset; i < this.num.length; i++) {
|
|
56
|
-
this.num[i] = 0;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
get(index: number): number {
|
|
61
|
-
return this.num[index] || 0;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
getLength(): number {
|
|
65
|
-
return this.num.length;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
multiply(e: Polynomial): Polynomial {
|
|
69
|
-
const num = new Array(this.getLength() + e.getLength() - 1).fill(0);
|
|
70
|
-
for (let i = 0; i < this.getLength(); i++) {
|
|
71
|
-
for (let j = 0; j < e.getLength(); j++) {
|
|
72
|
-
num[i + j] ^= gexp(glog(this.get(i)) + glog(e.get(j)));
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return new Polynomial(num);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
mod(e: Polynomial): Polynomial {
|
|
79
|
-
if (this.getLength() - e.getLength() < 0) {
|
|
80
|
-
return this;
|
|
81
|
-
}
|
|
82
|
-
const ratio = glog(this.get(0)) - glog(e.get(0));
|
|
83
|
-
const num = new Array(this.getLength());
|
|
84
|
-
for (let i = 0; i < this.getLength(); i++) {
|
|
85
|
-
num[i] = this.get(i);
|
|
86
|
-
}
|
|
87
|
-
for (let i = 0; i < e.getLength(); i++) {
|
|
88
|
-
num[i] ^= gexp(glog(e.get(i)) + ratio);
|
|
89
|
-
}
|
|
90
|
-
return new Polynomial(num).mod(e);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// QR Code RS Block definition tables [totalCount, dataCount]
|
|
95
|
-
const RS_BLOCK_TABLE: number[][][] = [
|
|
96
|
-
// 1
|
|
97
|
-
[[1, 26, 19], [1, 26, 16], [1, 26, 13], [1, 26, 9]],
|
|
98
|
-
// 2
|
|
99
|
-
[[1, 44, 34], [1, 44, 28], [1, 44, 22], [1, 44, 16]],
|
|
100
|
-
// 3
|
|
101
|
-
[[1, 70, 55], [1, 70, 44], [2, 35, 17], [2, 35, 13]],
|
|
102
|
-
// 4
|
|
103
|
-
[[1, 100, 80], [2, 50, 32], [2, 50, 24], [4, 25, 9]],
|
|
104
|
-
// 5
|
|
105
|
-
[[1, 134, 108], [2, 67, 43], [2, 33, 15, 2, 34, 16], [2, 33, 11, 2, 34, 12]],
|
|
106
|
-
// 6
|
|
107
|
-
[[2, 86, 68], [4, 43, 27], [4, 43, 19], [4, 43, 15]],
|
|
108
|
-
// 7
|
|
109
|
-
[[2, 98, 78], [4, 49, 31], [2, 32, 14, 4, 33, 15], [4, 39, 13, 1, 40, 14]],
|
|
110
|
-
// 8
|
|
111
|
-
[[2, 121, 97], [2, 60, 38, 2, 61, 39], [4, 40, 18, 2, 41, 19], [4, 40, 14, 2, 41, 15]],
|
|
112
|
-
// 9
|
|
113
|
-
[[2, 146, 116], [3, 58, 36, 2, 59, 37], [4, 36, 16, 4, 37, 17], [4, 36, 12, 4, 37, 13]],
|
|
114
|
-
// 10
|
|
115
|
-
[[2, 86, 68, 2, 87, 69], [4, 69, 43, 1, 70, 44], [6, 43, 19, 2, 44, 20], [6, 43, 15, 2, 44, 16]],
|
|
116
|
-
];
|
|
117
|
-
|
|
118
|
-
// Alignment pattern centers for Versions 1-10
|
|
119
|
-
const PATTERN_POSITION_TABLE: number[][] = [
|
|
120
|
-
[],
|
|
121
|
-
[6, 18],
|
|
122
|
-
[6, 22],
|
|
123
|
-
[6, 26],
|
|
124
|
-
[6, 30],
|
|
125
|
-
[6, 34],
|
|
126
|
-
[6, 22, 38],
|
|
127
|
-
[6, 24, 42],
|
|
128
|
-
[6, 26, 46],
|
|
129
|
-
[6, 28, 50],
|
|
130
|
-
];
|
|
131
|
-
|
|
132
|
-
const G15 = (1 << 10) | (1 << 8) | (1 << 5) | (1 << 4) | (1 << 2) | (1 << 1) | (1 << 0);
|
|
133
|
-
const G15_MASK = (1 << 14) | (1 << 12) | (1 << 10) | (1 << 4) | (1 << 1);
|
|
134
|
-
|
|
135
|
-
function getBCHTypeInfo(data: number): number {
|
|
136
|
-
let d = data << 10;
|
|
137
|
-
while (getBCHDigit(d) - getBCHDigit(G15) >= 0) {
|
|
138
|
-
d ^= G15 << (getBCHDigit(d) - getBCHDigit(G15));
|
|
139
|
-
}
|
|
140
|
-
return ((data << 10) | d) ^ G15_MASK;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function getBCHDigit(data: number): number {
|
|
144
|
-
let digit = 0;
|
|
145
|
-
while (data !== 0) {
|
|
146
|
-
digit++;
|
|
147
|
-
data >>>= 1;
|
|
148
|
-
}
|
|
149
|
-
return digit;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
function getMask(maskPattern: number, i: number, j: number): boolean {
|
|
153
|
-
switch (maskPattern) {
|
|
154
|
-
case 0: return (i + j) % 2 === 0;
|
|
155
|
-
case 1: return i % 2 === 0;
|
|
156
|
-
case 2: return j % 3 === 0;
|
|
157
|
-
case 3: return (i + j) % 3 === 0;
|
|
158
|
-
case 4: return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
|
|
159
|
-
case 5: return ((i * j) % 2) + ((i * j) % 3) === 0;
|
|
160
|
-
case 6: return (((i * j) % 2) + ((i * j) % 3)) % 2 === 0;
|
|
161
|
-
case 7: return (((i * j) % 3) + ((i + j) % 2)) % 2 === 0;
|
|
162
|
-
default: return false;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
class BitBuffer {
|
|
167
|
-
buffer: number[] = [];
|
|
168
|
-
length = 0;
|
|
169
|
-
|
|
170
|
-
get(index: number): boolean {
|
|
171
|
-
const bufIndex = Math.floor(index / 8);
|
|
172
|
-
return ((this.buffer[bufIndex]! >>> (7 - (index % 8))) & 1) === 1;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
put(num: number, length: number): void {
|
|
176
|
-
for (let i = 0; i < length; i++) {
|
|
177
|
-
this.putBit(((num >>> (length - i - 1)) & 1) === 1);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
putBit(bit: boolean): void {
|
|
182
|
-
const bufIndex = Math.floor(this.length / 8);
|
|
183
|
-
if (this.buffer.length <= bufIndex) {
|
|
184
|
-
this.buffer.push(0);
|
|
185
|
-
}
|
|
186
|
-
if (bit) {
|
|
187
|
-
this.buffer[bufIndex] |= 0x80 >>> (this.length % 8);
|
|
188
|
-
}
|
|
189
|
-
this.length++;
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function getErrorCorrectionPolynomial(errorCorrectionLength: number): Polynomial {
|
|
194
|
-
let a = new Polynomial([1], 0);
|
|
195
|
-
for (let i = 0; i < errorCorrectionLength; i++) {
|
|
196
|
-
a = a.multiply(new Polynomial([1, gexp(i)], 0));
|
|
197
|
-
}
|
|
198
|
-
return a;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Generates boolean matrix for QR code string.
|
|
203
|
-
* Zero external dependencies.
|
|
204
|
-
*/
|
|
205
|
-
export function generateQRMatrix(text: string, ecc: QRECC = 'M'): boolean[][] {
|
|
206
|
-
const eccLevel = QR_ECC_LEVEL[ecc] ?? 0;
|
|
207
|
-
const utf8Bytes: number[] = [];
|
|
208
|
-
|
|
209
|
-
for (let i = 0; i < text.length; i++) {
|
|
210
|
-
let c = text.charCodeAt(i);
|
|
211
|
-
if (c < 128) {
|
|
212
|
-
utf8Bytes.push(c);
|
|
213
|
-
} else if (c < 2048) {
|
|
214
|
-
utf8Bytes.push((c >> 6) | 192);
|
|
215
|
-
utf8Bytes.push((c & 63) | 128);
|
|
216
|
-
} else {
|
|
217
|
-
utf8Bytes.push((c >> 12) | 224);
|
|
218
|
-
utf8Bytes.push(((c >> 6) & 63) | 128);
|
|
219
|
-
utf8Bytes.push((c & 63) | 128);
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Determine minimum viable QR Version (1 to 10)
|
|
224
|
-
let version = 1;
|
|
225
|
-
for (let v = 1; v <= 10; v++) {
|
|
226
|
-
const blockList = RS_BLOCK_TABLE[v - 1]![eccLevel]!;
|
|
227
|
-
let totalDataCount = 0;
|
|
228
|
-
for (let i = 0; i < blockList.length; i += 3) {
|
|
229
|
-
totalDataCount += blockList[i]! * blockList[i + 2]!;
|
|
230
|
-
}
|
|
231
|
-
// 8-bit byte mode overhead: 4 bits mode + 8 bits length
|
|
232
|
-
if (utf8Bytes.length + 2 <= totalDataCount) {
|
|
233
|
-
version = v;
|
|
234
|
-
break;
|
|
235
|
-
}
|
|
236
|
-
version = v;
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const moduleCount = version * 4 + 17;
|
|
240
|
-
const modules: (boolean | null)[][] = Array.from({ length: moduleCount }, () =>
|
|
241
|
-
Array(moduleCount).fill(null),
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
// 1. Position detection patterns
|
|
245
|
-
function setupPositionProbePattern(row: number, col: number) {
|
|
246
|
-
for (let r = -1; r <= 7; r++) {
|
|
247
|
-
if (row + r <= -1 || moduleCount <= row + r) continue;
|
|
248
|
-
for (let c = -1; c <= 7; c++) {
|
|
249
|
-
if (col + c <= -1 || moduleCount <= col + c) continue;
|
|
250
|
-
if (
|
|
251
|
-
(0 <= r && r <= 6 && (c === 0 || c === 6)) ||
|
|
252
|
-
(0 <= c && c <= 6 && (r === 0 || r === 6)) ||
|
|
253
|
-
(2 <= r && r <= 4 && 2 <= c && c <= 4)
|
|
254
|
-
) {
|
|
255
|
-
modules[row + r]![col + c] = true;
|
|
256
|
-
} else {
|
|
257
|
-
modules[row + r]![col + c] = false;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
setupPositionProbePattern(0, 0);
|
|
264
|
-
setupPositionProbePattern(moduleCount - 7, 0);
|
|
265
|
-
setupPositionProbePattern(0, moduleCount - 7);
|
|
266
|
-
|
|
267
|
-
// 2. Alignment patterns
|
|
268
|
-
const pos = PATTERN_POSITION_TABLE[version - 1] || [];
|
|
269
|
-
for (let i = 0; i < pos.length; i++) {
|
|
270
|
-
for (let j = 0; j < pos.length; j++) {
|
|
271
|
-
const row = pos[i]!;
|
|
272
|
-
const col = pos[j]!;
|
|
273
|
-
if (modules[row]![col] !== null) continue;
|
|
274
|
-
|
|
275
|
-
for (let r = -2; r <= 2; r++) {
|
|
276
|
-
for (let c = -2; c <= 2; c++) {
|
|
277
|
-
if (r === -2 || r === 2 || c === -2 || c === 2 || (r === 0 && c === 0)) {
|
|
278
|
-
modules[row + r]![col + c] = true;
|
|
279
|
-
} else {
|
|
280
|
-
modules[row + r]![col + c] = false;
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
// 3. Timing patterns
|
|
288
|
-
for (let r = 8; r < moduleCount - 8; r++) {
|
|
289
|
-
if (modules[r]![6] === null) modules[r]![6] = r % 2 === 0;
|
|
290
|
-
}
|
|
291
|
-
for (let c = 8; c < moduleCount - 8; c++) {
|
|
292
|
-
if (modules[6]![c] === null) modules[6]![c] = c % 2 === 0;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
// 4. Encode data stream
|
|
296
|
-
const buffer = new BitBuffer();
|
|
297
|
-
buffer.put(4, 4); // 8-bit byte mode indicator
|
|
298
|
-
buffer.put(utf8Bytes.length, 8); // character count
|
|
299
|
-
for (let i = 0; i < utf8Bytes.length; i++) {
|
|
300
|
-
buffer.put(utf8Bytes[i]!, 8);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const rsBlocks = RS_BLOCK_TABLE[version - 1]![eccLevel]!;
|
|
304
|
-
let totalDataCount = 0;
|
|
305
|
-
for (let i = 0; i < rsBlocks.length; i += 3) {
|
|
306
|
-
totalDataCount += rsBlocks[i]! * rsBlocks[i + 2]!;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
// Terminator
|
|
310
|
-
if (buffer.length + 4 <= totalDataCount * 8) {
|
|
311
|
-
buffer.put(0, 4);
|
|
312
|
-
}
|
|
313
|
-
while (buffer.length % 8 !== 0) {
|
|
314
|
-
buffer.putBit(false);
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
// Padding
|
|
318
|
-
while (buffer.length < totalDataCount * 8) {
|
|
319
|
-
buffer.put(0xec, 8);
|
|
320
|
-
if (buffer.length < totalDataCount * 8) {
|
|
321
|
-
buffer.put(0x11, 8);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
// RS Error Correction calculation
|
|
326
|
-
const dataBytes = buffer.buffer;
|
|
327
|
-
let offset = 0;
|
|
328
|
-
const dcData: number[][] = [];
|
|
329
|
-
const ecData: number[][] = [];
|
|
330
|
-
|
|
331
|
-
for (let i = 0; i < rsBlocks.length; i += 3) {
|
|
332
|
-
const numBlocks = rsBlocks[i]!;
|
|
333
|
-
const totalCount = rsBlocks[i + 1]!;
|
|
334
|
-
const dataCount = rsBlocks[i + 2]!;
|
|
335
|
-
const ecCount = totalCount - dataCount;
|
|
336
|
-
const rsPoly = getErrorCorrectionPolynomial(ecCount);
|
|
337
|
-
|
|
338
|
-
for (let b = 0; b < numBlocks; b++) {
|
|
339
|
-
const rawDc = dataBytes.slice(offset, offset + dataCount);
|
|
340
|
-
offset += dataCount;
|
|
341
|
-
dcData.push(rawDc);
|
|
342
|
-
|
|
343
|
-
const rawPoly = new Polynomial(rawDc, rsPoly.getLength() - 1);
|
|
344
|
-
const modPoly = rawPoly.mod(rsPoly);
|
|
345
|
-
const ec = new Array(rsPoly.getLength() - 1).fill(0);
|
|
346
|
-
for (let k = 0; k < ec.length; k++) {
|
|
347
|
-
const modIndex = k + modPoly.getLength() - ec.length;
|
|
348
|
-
ec[k] = modIndex >= 0 ? modPoly.get(modIndex) : 0;
|
|
349
|
-
}
|
|
350
|
-
ecData.push(ec);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
// Interleave data & error correction codewords
|
|
355
|
-
const finalCodewords: number[] = [];
|
|
356
|
-
let maxDcCount = 0;
|
|
357
|
-
for (const block of dcData) maxDcCount = Math.max(maxDcCount, block.length);
|
|
358
|
-
for (let i = 0; i < maxDcCount; i++) {
|
|
359
|
-
for (const block of dcData) {
|
|
360
|
-
if (i < block.length) finalCodewords.push(block[i]!);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
let maxEcCount = 0;
|
|
365
|
-
for (const block of ecData) maxEcCount = Math.max(maxEcCount, block.length);
|
|
366
|
-
for (let i = 0; i < maxEcCount; i++) {
|
|
367
|
-
for (const block of ecData) {
|
|
368
|
-
if (i < block.length) finalCodewords.push(block[i]!);
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
// 5. Place data into matrix using standard mask 0
|
|
373
|
-
let inc = -1;
|
|
374
|
-
let row = moduleCount - 1;
|
|
375
|
-
let bitIndex = 0;
|
|
376
|
-
const maskPattern = 0;
|
|
377
|
-
|
|
378
|
-
for (let col = moduleCount - 1; col > 0; col -= 2) {
|
|
379
|
-
if (col === 6) col--;
|
|
380
|
-
while (true) {
|
|
381
|
-
for (let c = 0; c < 2; c++) {
|
|
382
|
-
if (modules[row]![col - c] === null) {
|
|
383
|
-
let dark = false;
|
|
384
|
-
if (bitIndex < finalCodewords.length * 8) {
|
|
385
|
-
const byte = finalCodewords[Math.floor(bitIndex / 8)]!;
|
|
386
|
-
dark = ((byte >>> (7 - (bitIndex % 8))) & 1) === 1;
|
|
387
|
-
bitIndex++;
|
|
388
|
-
}
|
|
389
|
-
const mask = getMask(maskPattern, row, col - c);
|
|
390
|
-
modules[row]![col - c] = mask ? !dark : dark;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
row += inc;
|
|
394
|
-
if (row < 0 || moduleCount <= row) {
|
|
395
|
-
row -= inc;
|
|
396
|
-
inc = -inc;
|
|
397
|
-
break;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
// 6. Format Info (Type Info)
|
|
403
|
-
const typeData = (eccLevel << 3) | maskPattern;
|
|
404
|
-
const bits = getBCHTypeInfo(typeData);
|
|
405
|
-
|
|
406
|
-
for (let i = 0; i < 15; i++) {
|
|
407
|
-
const mod = ((bits >> i) & 1) === 1;
|
|
408
|
-
if (i < 6) {
|
|
409
|
-
modules[i]![8] = mod;
|
|
410
|
-
} else if (i < 8) {
|
|
411
|
-
modules[i + 1]![8] = mod;
|
|
412
|
-
} else {
|
|
413
|
-
modules[moduleCount - 15 + i]![8] = mod;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
if (i < 8) {
|
|
417
|
-
modules[8]![moduleCount - i - 1] = mod;
|
|
418
|
-
} else if (i < 9) {
|
|
419
|
-
modules[8]![15 - i - 1 + 1] = mod;
|
|
420
|
-
} else {
|
|
421
|
-
modules[8]![15 - i - 1] = mod;
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
modules[moduleCount - 8]![8] = true;
|
|
426
|
-
|
|
427
|
-
return modules.map(r => r.map(cell => cell === true));
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
export default generateQRMatrix;
|