@capgo/capacitor-document-scanner 8.4.14 → 8.4.16
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/CapgoCapacitorDocumentScanner.podspec +8 -0
- package/Package.swift +11 -2
- package/README.md +52 -12
- package/dist/docs.json +3 -3
- package/dist/esm/definitions.d.ts +14 -7
- package/dist/esm/definitions.js.map +1 -1
- package/ios/Sources/DocumentScannerPlugin/DocScanner.swift +14 -635
- package/ios/Sources/DocumentScannerPlugin/DocumentScannerPlugin.swift +1 -1
- package/ios/Sources/DocumentScannerPlugin/VisionKitScanSwizzle.swift +675 -0
- package/ios/Tests/DocumentScannerPluginTests/DocumentScannerPluginTests.swift +6 -1
- package/package.json +5 -3
- package/scripts/configure-visionkit-swizzle.mjs +66 -0
- package/ios/Sources/DocumentScannerPlugin/VisionKitPrivateConstants.swift +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-document-scanner",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.16",
|
|
4
4
|
"description": "Capacitor plugin to scan document iOS and Android",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"ios/Sources",
|
|
14
14
|
"ios/Tests",
|
|
15
15
|
"Package.swift",
|
|
16
|
-
"CapgoCapacitorDocumentScanner.podspec"
|
|
16
|
+
"CapgoCapacitorDocumentScanner.podspec",
|
|
17
|
+
"scripts/configure-visionkit-swizzle.mjs"
|
|
17
18
|
],
|
|
18
19
|
"author": "Martin Donadieu <martin@capgo.app>",
|
|
19
20
|
"license": "MPL-2.0",
|
|
@@ -31,6 +32,7 @@
|
|
|
31
32
|
"native"
|
|
32
33
|
],
|
|
33
34
|
"scripts": {
|
|
35
|
+
"capacitor:sync:before": "node scripts/configure-visionkit-swizzle.mjs",
|
|
34
36
|
"verify": "bun run verify:ios && bun run verify:android && bun run verify:web",
|
|
35
37
|
"verify:ios": "xcodebuild -scheme CapgoCapacitorDocumentScanner -destination generic/platform=iOS",
|
|
36
38
|
"verify:android": "cd android && ./gradlew clean build test && cd ..",
|
|
@@ -50,7 +52,7 @@
|
|
|
50
52
|
"check:wiring": "node scripts/check-capacitor-plugin-wiring.mjs",
|
|
51
53
|
"check:cap9-deprecated": "node scripts/check-cap9-deprecated.mjs",
|
|
52
54
|
"check:ios-app-store": "node scripts/check-ios-app-store-dynamic-code.mjs",
|
|
53
|
-
"test:ios-app-store-check": "node --test scripts/check-ios-app-store-dynamic-code.test.mjs",
|
|
55
|
+
"test:ios-app-store-check": "node --test scripts/check-ios-app-store-dynamic-code.test.mjs scripts/configure-visionkit-swizzle.test.mjs",
|
|
54
56
|
"example:install": "cd example-app && bun install --frozen-lockfile",
|
|
55
57
|
"example:build": "bun run build && cd example-app && bun install --frozen-lockfile && bun run build",
|
|
56
58
|
"changelog:ai": "node scripts/generate-ai-changelog.mjs"
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Capacitor hook. Runs before `cap sync` and compiles the private VisionKit
|
|
4
|
+
* swizzle only when plugins.DocumentScanner.iosVisionKitSwizzle is true.
|
|
5
|
+
* The default binary does not contain that swizzle.
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
10
|
+
|
|
11
|
+
const swiftMarker = String.raw`let visionKitSwizzleEnabled = (true|false)`;
|
|
12
|
+
const podspecMarker = String.raw`vision_kit_swizzle_enabled = (true|false)`;
|
|
13
|
+
|
|
14
|
+
export function readSwizzleEnabled(configJson) {
|
|
15
|
+
if (!configJson) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const config = JSON.parse(configJson);
|
|
20
|
+
return config?.plugins?.DocumentScanner?.iosVisionKitSwizzle === true;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function setSwizzleEnabled(source, pattern, enabled) {
|
|
24
|
+
const regex = new RegExp(pattern);
|
|
25
|
+
if (!regex.test(source)) {
|
|
26
|
+
throw new Error(`Missing VisionKit swizzle marker (${pattern})`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return source.replace(new RegExp(pattern), (full) => full.replace(/true|false/, enabled ? 'true' : 'false'));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function writeIfChanged(filePath, pattern, enabled) {
|
|
33
|
+
const current = readFileSync(filePath, 'utf8');
|
|
34
|
+
const next = setSwizzleEnabled(current, pattern, enabled);
|
|
35
|
+
if (next !== current) {
|
|
36
|
+
writeFileSync(filePath, next);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function main() {
|
|
41
|
+
const args = new Set(process.argv.slice(2));
|
|
42
|
+
let enabled;
|
|
43
|
+
|
|
44
|
+
if (args.has('--enable')) {
|
|
45
|
+
enabled = true;
|
|
46
|
+
} else if (args.has('--disable')) {
|
|
47
|
+
enabled = false;
|
|
48
|
+
} else {
|
|
49
|
+
try {
|
|
50
|
+
enabled = readSwizzleEnabled(process.env.CAPACITOR_CONFIG);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error(`[DocumentScanner] Invalid CAPACITOR_CONFIG: ${error.message}`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
58
|
+
writeIfChanged(path.join(root, 'Package.swift'), swiftMarker, enabled);
|
|
59
|
+
writeIfChanged(path.join(root, 'CapgoCapacitorDocumentScanner.podspec'), podspecMarker, enabled);
|
|
60
|
+
console.log(`[DocumentScanner] iOS VisionKit swizzle ${enabled ? 'enabled' : 'disabled'}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const entryPath = process.argv[1];
|
|
64
|
+
if (entryPath && import.meta.url === pathToFileURL(path.resolve(entryPath)).href) {
|
|
65
|
+
main();
|
|
66
|
+
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
|
|
3
|
-
enum VisionKitPrivateConstants {
|
|
4
|
-
static let inProcessViewControllerClassName = "VNDocumentCameraViewController_InProcess"
|
|
5
|
-
static let documentCameraCanAddImagesSelector = Selector("documentCameraController:canAddImages:")
|
|
6
|
-
static let gestureRecognizerTargetsKey = "_targets"
|
|
7
|
-
static let gestureTargetIvarName = "_target"
|
|
8
|
-
static let gestureActionIvarName = "_action"
|
|
9
|
-
static let thumbnailContainerViewClassFragment = "ICDocCamThumbnailContainerView"
|
|
10
|
-
}
|