@blotch/angular-lynx-native 22.3.0 → 22.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +41 -15
  2. package/dist/android/project.d.ts +90 -1
  3. package/dist/android/project.d.ts.map +1 -1
  4. package/dist/android/project.js +369 -5
  5. package/dist/eject.d.ts +15 -1
  6. package/dist/eject.d.ts.map +1 -1
  7. package/dist/eject.js +13 -2
  8. package/dist/features.d.ts +70 -0
  9. package/dist/features.d.ts.map +1 -0
  10. package/dist/features.js +115 -0
  11. package/dist/generate.d.ts +17 -1
  12. package/dist/generate.d.ts.map +1 -1
  13. package/dist/generate.js +12 -4
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +8 -1
  17. package/dist/ios/build.d.ts.map +1 -1
  18. package/dist/ios/build.js +8 -2
  19. package/dist/ios/frameworks.d.ts +6 -5
  20. package/dist/ios/frameworks.d.ts.map +1 -1
  21. package/dist/ios/frameworks.js +46 -15
  22. package/dist/ios/project.d.ts +173 -11
  23. package/dist/ios/project.d.ts.map +1 -1
  24. package/dist/ios/project.js +767 -33
  25. package/dist/options.d.ts +143 -2
  26. package/dist/options.d.ts.map +1 -1
  27. package/dist/options.js +127 -0
  28. package/dist/permissions.d.ts +18 -1
  29. package/dist/permissions.d.ts.map +1 -1
  30. package/dist/permissions.js +63 -3
  31. package/package.json +1 -1
  32. package/templates/android/README.md +37 -2
  33. package/templates/android/angular-lynx.properties +2 -0
  34. package/templates/android/app/build.gradle.kts +70 -1
  35. package/templates/android/app/src/main/AndroidManifest.xml +24 -3
  36. package/templates/android/app/src/main/java/dev/angularlynx/shell/BarcodeScannerModule.kt +144 -0
  37. package/templates/android/app/src/main/java/dev/angularlynx/shell/BiometricsModule.kt +433 -0
  38. package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapPresenter.kt +98 -0
  39. package/templates/android/app/src/main/java/dev/angularlynx/shell/BitmapRendererContext.kt +175 -0
  40. package/templates/android/app/src/main/java/dev/angularlynx/shell/BluetoothModule.kt +1288 -0
  41. package/templates/android/app/src/main/java/dev/angularlynx/shell/CalendarModule.kt +127 -0
  42. package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DContext.kt +1557 -0
  43. package/templates/android/app/src/main/java/dev/angularlynx/shell/Canvas2DOps.kt +63 -0
  44. package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasFilter.kt +357 -0
  45. package/templates/android/app/src/main/java/dev/angularlynx/shell/CanvasUI.kt +4 -3
  46. package/templates/android/app/src/main/java/dev/angularlynx/shell/FilePickerModule.kt +263 -0
  47. package/templates/android/app/src/main/java/dev/angularlynx/shell/HapticsModule.kt +82 -0
  48. package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +376 -6
  49. package/templates/android/app/src/main/java/dev/angularlynx/shell/ModuleBytes.kt +58 -0
  50. package/templates/android/app/src/main/java/dev/angularlynx/shell/MotionModule.kt +332 -0
  51. package/templates/android/app/src/main/java/dev/angularlynx/shell/NfcModule.kt +274 -0
  52. package/templates/android/app/src/main/java/dev/angularlynx/shell/PermissionRequests.kt +25 -0
  53. package/templates/android/app/src/main/java/dev/angularlynx/shell/PhotoLibraryModule.kt +168 -0
  54. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShareTargetModule.kt +234 -0
  55. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellApplication.kt +6 -0
  56. package/templates/android/app/src/main/java/dev/angularlynx/shell/ShellModule.kt +47 -3
  57. package/templates/android/app/src/main/java/dev/angularlynx/shell/StoreReviewModule.kt +66 -0
  58. package/templates/android/app/src/main/java/dev/angularlynx/shell/SystemFontFamilies.kt +68 -0
  59. package/templates/android/app/src/main/java/dev/angularlynx/shell/TrackingModule.kt +74 -0
  60. package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoFrameTarget.kt +429 -0
  61. package/templates/android/app/src/main/java/dev/angularlynx/shell/VideoUI.kt +676 -0
  62. package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +128 -13
  63. package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +493 -65
  64. package/templates/android/app/src/main/java/dev/angularlynx/shell/WifiModule.kt +429 -0
  65. package/templates/android/app/src/main/res/values/biometrics.xml +9 -0
  66. package/templates/android/app/src/main/res/values/share_target.xml +11 -0
  67. package/templates/android/app/src/main/res/xml/backup_rules.xml +5 -3
  68. package/templates/android/app/src/main/res/xml/data_extraction_rules.xml +6 -3
  69. package/templates/android/build.gradle.kts +1 -1
  70. package/templates/android/gradle/wrapper/gradle-wrapper.properties +2 -2
  71. package/templates/ios/App/AngularLynxBitmapRendererContext.m +188 -0
  72. package/templates/ios/App/AngularLynxCanvas2DContext.m +2467 -0
  73. package/templates/ios/App/AngularLynxCanvas2DOps.h +61 -0
  74. package/templates/ios/App/AngularLynxVideo.h +37 -0
  75. package/templates/ios/App/AngularLynxVideo.m +435 -0
  76. package/templates/ios/App/AngularLynxWebGL.h +69 -7
  77. package/templates/ios/App/AngularLynxWebGL.m +538 -29
  78. package/templates/ios/App/AngularLynxWebGLContext.m +148 -46
  79. package/templates/ios/App/AppDelegate.swift +34 -2
  80. package/templates/ios/App/AppleSignInButton.swift +106 -0
  81. package/templates/ios/App/AppleSignInModule.swift +222 -0
  82. package/templates/ios/App/BarcodeScannerModule.swift +284 -0
  83. package/templates/ios/App/BiometricsModule.swift +256 -0
  84. package/templates/ios/App/BluetoothModule.swift +1086 -0
  85. package/templates/ios/App/CalendarModule.swift +158 -0
  86. package/templates/ios/App/FilePickerModule.swift +240 -0
  87. package/templates/ios/App/HapticsModule.swift +90 -0
  88. package/templates/ios/App/Info.plist +2 -0
  89. package/templates/ios/App/LynxViewController.swift +210 -6
  90. package/templates/ios/App/MotionModule.swift +430 -0
  91. package/templates/ios/App/NfcModule.swift +346 -0
  92. package/templates/ios/App/PhotoLibraryModule.swift +169 -0
  93. package/templates/ios/App/ShareTargetModule.swift +150 -0
  94. package/templates/ios/App/ShellModule.swift +17 -0
  95. package/templates/ios/App/StoreReviewModule.swift +61 -0
  96. package/templates/ios/App/TrackingModule.swift +121 -0
  97. package/templates/ios/App/WifiModule.swift +237 -0
  98. package/templates/ios/App/XElementRegistry.swift +13 -3
  99. package/templates/ios/ShareExtension/Info.plist +42 -0
  100. package/templates/ios/ShareExtension/ShareViewController.swift +387 -0
@@ -1,6 +1,7 @@
1
- import { chmodSync, existsSync, readFileSync, writeFileSync } from 'node:fs';
1
+ import { chmodSync, existsSync, readFileSync, rmSync, writeFileSync, } from 'node:fs';
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
+ import { leaveOutWifi, removeMarkedLines, removeTemplateFiles, } from "../features.js";
4
5
  import { shortcutIdentifier, } from "../options.js";
5
6
  import { PERMISSION_MAP } from "../permissions.js";
6
7
  import { writeAndroidSplash } from "../splash.js";
@@ -8,6 +9,11 @@ import { writeAndroidIcon } from "./icon.js";
8
9
  import { escapeXml, replaceMarker } from "../xml.js";
9
10
  const MANIFEST = 'app/src/main/AndroidManifest.xml';
10
11
  const RESOURCES = 'app/src/main/res';
12
+ const APP_BUILD_FILE = 'app/build.gradle.kts';
13
+ const BARCODE_SCANNER_MARKER = '// angular-lynx:barcode-scanner';
14
+ /** LynxBarcodeScanner's module, which needs the `camera` permission. */
15
+ export const ANDROID_BARCODE_SCANNER_SOURCE = 'app/src/main/java/dev/angularlynx/shell/BarcodeScannerModule.kt';
16
+ const BLUETOOTH_MODULE = 'app/src/main/java/dev/angularlynx/shell/BluetoothModule.kt';
11
17
  const SCREEN_ORIENTATIONS = {
12
18
  portrait: 'portrait',
13
19
  landscape: 'sensorLandscape',
@@ -19,7 +25,15 @@ const SCREEN_ORIENTATIONS = {
19
25
  * deep links and the apps canOpenURL can see go between the manifest's
20
26
  * `angular-lynx:*` markers, the icon options become the launcher icon's
21
27
  * resources, the shortcuts become the static shortcuts' resources, and the
22
- * splash becomes the splash theme's color and image.
28
+ * splash becomes the splash theme's color and image. The barcode scanner's
29
+ * module and the library behind it stay only in an app with the `camera`
30
+ * permission, and the Bluetooth module only in an app with the `bluetooth`
31
+ * permission. The store review module stays only in an app with
32
+ * `storeReview`, the calendar module only in one with `calendar`, the
33
+ * tracking module only in one with `permissions.tracking`, the NFC module
34
+ * only in one with `permissions.nfc`, the motion module only in one with
35
+ * `motion`, and the Wi-Fi module only in one with `wifi`, with only the parts
36
+ * it turns on.
23
37
  */
24
38
  export const androidGenerator = {
25
39
  configure: (dir, app, projectRoot) => {
@@ -32,6 +46,7 @@ export const androidGenerator = {
32
46
  manifest = replaceMarker(manifest, 'permissions', permissionEntries(app));
33
47
  manifest = replaceMarker(manifest, 'deep-links', deepLinkEntries(app));
34
48
  manifest = replaceMarker(manifest, 'queries', queriesEntries(app));
49
+ manifest = replaceMarker(manifest, 'share-target', shareTargetEntries(app));
35
50
  writeFileSync(manifestPath, manifest);
36
51
  // The template's shortcuts.xml is an empty list, which an app without
37
52
  // shortcuts keeps.
@@ -39,11 +54,243 @@ export const androidGenerator = {
39
54
  writeFileSync(path.join(dir, RESOURCES, 'xml/shortcuts.xml'), shortcutsXml(app));
40
55
  writeFileSync(path.join(dir, RESOURCES, 'values/shortcuts.xml'), shortcutStringsXml(app));
41
56
  }
57
+ // As on iOS (see iosGenerator), an app that doesn't ask for the camera
58
+ // ships no scanner: neither the module nor Google's code scanner, which
59
+ // brings Play services' libraries. MainActivity registers the module
60
+ // only when its class is there.
61
+ if (!app.permissions.camera) {
62
+ rmSync(path.join(dir, ANDROID_BARCODE_SCANNER_SOURCE), { force: true });
63
+ const buildFile = path.join(dir, APP_BUILD_FILE);
64
+ // Configuring the same copy twice finds the lines already gone.
65
+ if (readFileSync(buildFile, 'utf8').includes(BARCODE_SCANNER_MARKER)) {
66
+ removeMarkedLines(buildFile, 'barcode-scanner');
67
+ }
68
+ }
69
+ // As on iOS (see iosGenerator), an app that doesn't ask for Bluetooth
70
+ // ships no Bluetooth code. MainActivity registers the module only when
71
+ // its class is there.
72
+ if (!app.permissions.bluetooth) {
73
+ rmSync(path.join(dir, BLUETOOTH_MODULE), { force: true });
74
+ }
42
75
  writeAndroidIcon(dir, app, projectRoot);
43
76
  writeAndroidSplash(dir, app, projectRoot);
77
+ // The types ShareTargetModule checks each shared file against.
78
+ if (app.shareTarget) {
79
+ writeFileSync(path.join(dir, SHARE_TARGET_STRINGS), shareTargetStringsXml(app.shareTarget.mimeTypes));
80
+ }
81
+ // The prompt's subtitle when the app gives none, as iOS shows
82
+ // NSFaceIDUsageDescription. leaveOut deletes the file without it.
83
+ const reason = app.permissions.biometrics;
84
+ if (reason) {
85
+ writeFileSync(path.join(dir, BIOMETRICS_STRINGS), biometricsStringsXml(reason));
86
+ }
87
+ },
88
+ leaveOut: (dir, features, app) => {
89
+ // The biometrics module, AndroidX Biometric and the lines that register
90
+ // it are only for an app that asks for biometrics.
91
+ if (!app.permissions.biometrics) {
92
+ removeTemplateFiles(dir, [
93
+ ...ANDROID_BIOMETRICS_SOURCES.map((file) => path.join(SHELL_SOURCES, file)),
94
+ BIOMETRICS_STRINGS,
95
+ ]);
96
+ for (const file of ANDROID_BIOMETRICS_MARKED) {
97
+ removeMarkedLines(path.join(dir, file), 'biometrics');
98
+ }
99
+ }
100
+ // The document picker is only for an app that turns it on with
101
+ // `filePicker`: the module, and MainActivity's lines that launch the
102
+ // pickers and register it.
103
+ if (!app.filePicker) {
104
+ removeTemplateFiles(dir, ANDROID_FILE_PICKER_SOURCES.map((file) => path.join(SHELL_SOURCES, file)));
105
+ removeMarkedLines(path.join(dir, SHELL_SOURCES, 'MainActivity.kt'), 'file-picker');
106
+ }
107
+ // As on iOS, an app that doesn't ask for ratings in the app leaves the
108
+ // module out, with the lines that register it and Google Play's review
109
+ // library (`// angular-lynx:store-review`), so its APK carries none of
110
+ // Play's review code.
111
+ if (!app.storeReview) {
112
+ removeTemplateFiles(dir, [ANDROID_STORE_REVIEW_SOURCE]);
113
+ for (const file of ANDROID_STORE_REVIEW_MARKED) {
114
+ removeMarkedLines(path.join(dir, file), 'store-review');
115
+ }
116
+ }
117
+ // An app that doesn't add events to the calendar (angular.json's
118
+ // `calendar`) leaves out the module and MainActivity's lines that open
119
+ // the calendar app's editor for it (`// angular-lynx:calendar`).
120
+ if (!app.calendar) {
121
+ removeTemplateFiles(dir, [ANDROID_CALENDAR_SOURCE]);
122
+ removeMarkedLines(path.join(dir, SHELL_SOURCES, 'MainActivity.kt'), 'calendar');
123
+ }
124
+ // An app that isn't a share target (angular.json's `shareTarget`) has
125
+ // no intent filters for it (configure writes none), and leaves out the
126
+ // module, its types and MainActivity's lines that hand it the intents
127
+ // (`// angular-lynx:share-target`).
128
+ if (!app.shareTarget) {
129
+ removeTemplateFiles(dir, [
130
+ ANDROID_SHARE_TARGET_SOURCE,
131
+ SHARE_TARGET_STRINGS,
132
+ ]);
133
+ removeMarkedLines(path.join(dir, SHELL_SOURCES, 'MainActivity.kt'), 'share-target');
134
+ }
135
+ // As on iOS, an app that doesn't say why it tracks
136
+ // (`permissions.tracking`) leaves out the module, the lines that register
137
+ // it and Play's advertising ID library (`// angular-lynx:tracking`),
138
+ // which would otherwise declare AD_ID for it.
139
+ if (!app.permissions.tracking) {
140
+ removeTemplateFiles(dir, [ANDROID_TRACKING_SOURCE]);
141
+ for (const file of ANDROID_TRACKING_MARKED) {
142
+ removeMarkedLines(path.join(dir, file), 'tracking');
143
+ }
144
+ }
145
+ // As on iOS, the NFC module is only for an app that says why it reads
146
+ // tags (`permissions.nfc`, which also declares the NFC permission): the
147
+ // module and MainActivity's lines that register it
148
+ // (`// angular-lynx:nfc`).
149
+ if (!app.permissions.nfc) {
150
+ removeTemplateFiles(dir, [ANDROID_NFC_SOURCE]);
151
+ removeMarkedLines(path.join(dir, SHELL_SOURCES, 'MainActivity.kt'), 'nfc');
152
+ }
153
+ // The photo library module, and the lines that register it, are only
154
+ // for an app that asks for savePhotos.
155
+ if (!app.permissions.savePhotos) {
156
+ removeTemplateFiles(dir, ANDROID_PHOTO_LIBRARY_SOURCES.map((file) => path.join(SHELL_SOURCES, file)));
157
+ removeMarkedLines(path.join(dir, SHELL_SOURCES, 'MainActivity.kt'), 'photo-library');
158
+ }
159
+ // As on iOS, an app keeps only the Wi-Fi code of the parts of `wifi` it
160
+ // turns on, and none, nor MainActivity's lines that register the module
161
+ // (`// angular-lynx:wifi`), without either.
162
+ if (!app.wifi.join && !app.wifi.readCurrentNetwork) {
163
+ removeMarkedLines(path.join(dir, SHELL_SOURCES, 'MainActivity.kt'), 'wifi');
164
+ }
165
+ leaveOutWifi(dir, app.wifi, ANDROID_WIFI_SOURCE);
166
+ // As on iOS, an app that doesn't read the motion sensors leaves the
167
+ // module out, with the lines in MainActivity that register it
168
+ // (`// angular-lynx:motion`).
169
+ if (!app.motion) {
170
+ removeTemplateFiles(dir, [ANDROID_MOTION_SOURCE]);
171
+ removeMarkedLines(path.join(dir, SHELL_SOURCES, 'MainActivity.kt'), 'motion');
172
+ }
173
+ leaveOutCanvas(dir, features);
44
174
  },
45
175
  bundleDir: (dir) => path.join(dir, 'app/src/main/assets'),
46
176
  };
177
+ /**
178
+ * Takes out the canvas code the bundle doesn't use (see NativeFeatures).
179
+ */
180
+ const leaveOutCanvas = (dir, features) => {
181
+ if (features.webgl)
182
+ return;
183
+ if (features.canvas) {
184
+ // A 2D canvas keeps the module, without the WebGL2 context and the
185
+ // module's lines that make one (`// angular-lynx:webgl`).
186
+ removeTemplateFiles(dir, ANDROID_WEBGL_SOURCES.map((file) => path.join(SHELL_SOURCES, file)));
187
+ removeMarkedLines(path.join(dir, SHELL_SOURCES, 'WebGLModule.kt'), 'webgl');
188
+ return;
189
+ }
190
+ removeTemplateFiles(dir, ANDROID_CANVAS_SOURCES.map((file) => path.join(SHELL_SOURCES, file)));
191
+ // The lines that register them (`// angular-lynx:canvas`).
192
+ removeMarkedLines(path.join(dir, SHELL_SOURCES, 'MainActivity.kt'), 'canvas');
193
+ };
194
+ const SHELL_SOURCES = 'app/src/main/java/dev/angularlynx/shell';
195
+ /** The module behind `LynxStoreReview`, which only `storeReview` keeps. */
196
+ export const ANDROID_STORE_REVIEW_SOURCE = `${SHELL_SOURCES}/StoreReviewModule.kt`;
197
+ /** The module behind `LynxWifi`, which only `wifi` keeps. */
198
+ export const ANDROID_WIFI_SOURCE = `${SHELL_SOURCES}/WifiModule.kt`;
199
+ /** The module behind `LynxCalendar`, which only `calendar` keeps. */
200
+ export const ANDROID_CALENDAR_SOURCE = `${SHELL_SOURCES}/CalendarModule.kt`;
201
+ /** The module behind `LynxNfc`, which only `permissions.nfc` keeps. */
202
+ export const ANDROID_NFC_SOURCE = `${SHELL_SOURCES}/NfcModule.kt`;
203
+ /**
204
+ * The module behind `LynxTracking`, which only an app with
205
+ * `permissions.tracking` keeps.
206
+ */
207
+ export const ANDROID_TRACKING_SOURCE = `${SHELL_SOURCES}/TrackingModule.kt`;
208
+ /**
209
+ * The files with lines for the tracking module: MainActivity registers it,
210
+ * and app/build.gradle.kts adds Google Play's advertising ID library.
211
+ */
212
+ const ANDROID_TRACKING_MARKED = [
213
+ `${SHELL_SOURCES}/MainActivity.kt`,
214
+ 'app/build.gradle.kts',
215
+ ];
216
+ /**
217
+ * The files with lines for the store review module: MainActivity registers
218
+ * it, and app/build.gradle.kts adds Google Play's review library.
219
+ */
220
+ const ANDROID_STORE_REVIEW_MARKED = [
221
+ `${SHELL_SOURCES}/MainActivity.kt`,
222
+ 'app/build.gradle.kts',
223
+ ];
224
+ /** The module behind `LynxMotion`, which only `motion` keeps. */
225
+ export const ANDROID_MOTION_SOURCE = `${SHELL_SOURCES}/MotionModule.kt`;
226
+ /**
227
+ * The shell's biometrics module, `AngularLynxBiometrics` (LynxBiometrics, and
228
+ * the values LynxSecureStorage keeps behind a fingerprint or a face), which
229
+ * only an app with `permissions.biometrics` keeps.
230
+ */
231
+ export const ANDROID_BIOMETRICS_SOURCES = ['BiometricsModule.kt'];
232
+ /**
233
+ * The shell's file picker module, `AngularLynxFilePicker` (LynxFilePicker),
234
+ * which only an app with `filePicker` keeps.
235
+ */
236
+ export const ANDROID_FILE_PICKER_SOURCES = ['FilePickerModule.kt'];
237
+ /**
238
+ * The shell's photo library module, `AngularLynxPhotoLibrary`
239
+ * (LynxPhotoLibrary), which only an app with `permissions.savePhotos` keeps.
240
+ */
241
+ export const ANDROID_PHOTO_LIBRARY_SOURCES = ['PhotoLibraryModule.kt'];
242
+ /** The prompt's default reason, from `permissions.biometrics`. */
243
+ const BIOMETRICS_STRINGS = `${RESOURCES}/values/biometrics.xml`;
244
+ /**
245
+ * The files whose lines between `// angular-lynx:biometrics` markers name
246
+ * the module or AndroidX Biometric: MainActivity's registration and the
247
+ * Gradle dependency.
248
+ */
249
+ const ANDROID_BIOMETRICS_MARKED = [
250
+ 'app/build.gradle.kts',
251
+ `${SHELL_SOURCES}/MainActivity.kt`,
252
+ ];
253
+ /**
254
+ * res/values/biometrics.xml: the reason a biometric prompt shows when the
255
+ * app gives none, angular.json's `permissions.biometrics`.
256
+ */
257
+ export const biometricsStringsXml = (reason) => [
258
+ '<?xml version="1.0" encoding="utf-8"?>',
259
+ "<!-- Written from angular.json's permissions.biometrics on every build. -->",
260
+ '<resources>',
261
+ ` <string name="angular_lynx_biometrics_reason">${stringResource(reason)}</string>`,
262
+ '</resources>',
263
+ '',
264
+ ].join('\n');
265
+ /**
266
+ * The shell's `<canvas>`, its `AngularLynxWebGL` module and its contexts, and
267
+ * `<video>`'s readable frames, which only MainActivity's marked lines reach.
268
+ * R8 can't drop them while those lines register them, so they go with the
269
+ * lines.
270
+ */
271
+ export const ANDROID_CANVAS_SOURCES = [
272
+ 'BitmapPresenter.kt',
273
+ 'BitmapRendererContext.kt',
274
+ 'Canvas2DContext.kt',
275
+ 'Canvas2DOps.kt',
276
+ 'CanvasFilter.kt',
277
+ 'CanvasUI.kt',
278
+ 'VideoFrameTarget.kt',
279
+ 'VideoUI.kt',
280
+ 'WebGLContext.kt',
281
+ 'WebGLModule.kt',
282
+ 'WebGLOps.kt',
283
+ ];
284
+ /**
285
+ * The WebGL2 context, which an app that draws only in 2D leaves out, and
286
+ * `WebGLModule.kt`'s lines that make one (issue #847). `VideoFrameTarget.kt`
287
+ * reads a video's frames with an EGL context of its own, for the 2D
288
+ * context's `drawImage()` too, so it stays.
289
+ */
290
+ export const ANDROID_WEBGL_SOURCES = [
291
+ 'WebGLContext.kt',
292
+ 'WebGLOps.kt',
293
+ ];
47
294
  /**
48
295
  * Escapes a value for a Java properties file. `Properties.load` reads the
49
296
  * file as ISO-8859-1, so anything outside ASCII (an app named "Café" or
@@ -63,19 +310,95 @@ export const properties = (app) => [
63
310
  `appName=${propertyValue(app.name)}`,
64
311
  `screenOrientation=${SCREEN_ORIENTATIONS[app.orientation]}`,
65
312
  `edgeToEdge=${app.edgeToEdge}`,
313
+ // MainActivity's font scale: the system's, capped at the max (0 for
314
+ // none), or 1 when it's off.
315
+ `textScaling=${app.textScaling.enabled}`,
316
+ `maxTextScale=${app.textScaling.max ?? 0}`,
66
317
  '',
67
318
  ].join('\n');
319
+ /**
320
+ * The manifest permissions `LynxWifi`'s parts need, all granted at install:
321
+ * reading the network (`WifiManager.getConnectionInfo`, with the location
322
+ * permission `permissions.location` adds) and joining one
323
+ * (`WifiNetworkSuggestion`, and `ConnectivityManager.requestNetwork` for a
324
+ * `WifiNetworkSpecifier`).
325
+ */
326
+ const wifiPermissions = (app) => [
327
+ ...(app.wifi.readCurrentNetwork
328
+ ? [
329
+ 'android.permission.ACCESS_WIFI_STATE',
330
+ 'android.permission.ACCESS_NETWORK_STATE',
331
+ ]
332
+ : []),
333
+ ...(app.wifi.join
334
+ ? [
335
+ 'android.permission.ACCESS_WIFI_STATE',
336
+ 'android.permission.CHANGE_WIFI_STATE',
337
+ 'android.permission.ACCESS_NETWORK_STATE',
338
+ 'android.permission.CHANGE_NETWORK_STATE',
339
+ ]
340
+ : []),
341
+ ];
68
342
  export const permissionEntries = (app) => {
69
343
  const entries = Object.keys(app.permissions).map((permission) => PERMISSION_MAP[permission]);
70
- const permissions = [...new Set(entries.flatMap((entry) => entry.android))];
71
344
  const features = [
72
- ...new Set(entries.flatMap((entry) => entry.androidFeatures ?? [])),
345
+ ...new Set([
346
+ ...entries.flatMap((entry) => entry.androidFeatures ?? []),
347
+ ...(app.wifi.join || app.wifi.readCurrentNetwork
348
+ ? ['android.hardware.wifi']
349
+ : []),
350
+ ]),
73
351
  ];
74
352
  return [
75
- ...permissions.map((name) => `<uses-permission android:name="${escapeXml(name)}" />`),
353
+ ...usesPermissions([
354
+ ...entries.flatMap((entry) => entry.android),
355
+ ...wifiPermissions(app),
356
+ ]),
76
357
  ...features.map((name) => `<uses-feature android:name="${escapeXml(name)}" android:required="false" />`),
77
358
  ].join('\n');
78
359
  };
360
+ /**
361
+ * One `<uses-permission>` for each name, in the order the names first come.
362
+ * Two of the app's permissions can need the same Android one: `bluetooth`
363
+ * needs fine location to scan on old Android versions only, and `location`
364
+ * needs it on every version. The one element has to give each what it needs,
365
+ * so it keeps an attribute only when every declaration has it: the highest
366
+ * `maxSdkVersion`, and only the `usesPermissionFlags` they all promise.
367
+ *
368
+ * `usesPermissionFlags` came in Android 12 (codename S), which the app's
369
+ * minSdk predates. Older versions ignore it, and `tools:targetApi` tells
370
+ * Android lint that's intended.
371
+ */
372
+ export const usesPermissions = (permissions) => {
373
+ const declarations = new Map();
374
+ for (const permission of permissions) {
375
+ const declaration = typeof permission === 'string' ? { name: permission } : permission;
376
+ declarations.set(declaration.name, [
377
+ ...(declarations.get(declaration.name) ?? []),
378
+ declaration,
379
+ ]);
380
+ }
381
+ return [...declarations].map(([name, all]) => {
382
+ const maxSdkVersions = all.map((each) => each.maxSdkVersion);
383
+ const flags = all
384
+ .map((each) => each.usesPermissionFlags?.split('|') ?? [])
385
+ .reduce((common, each) => common.filter((flag) => each.includes(flag)));
386
+ return [
387
+ '<uses-permission',
388
+ `android:name="${escapeXml(name)}"`,
389
+ ...(maxSdkVersions.every((version) => version !== undefined)
390
+ ? [`android:maxSdkVersion="${Math.max(...maxSdkVersions)}"`]
391
+ : []),
392
+ ...(flags.length > 0
393
+ ? [
394
+ `android:usesPermissionFlags="${escapeXml(flags.join('|'))}"`,
395
+ 'tools:targetApi="s"',
396
+ ]
397
+ : []),
398
+ '/>',
399
+ ].join(' ');
400
+ });
401
+ };
79
402
  /**
80
403
  * The intent filters for the links that open the app: one for the
81
404
  * `deepLinkSchemes`, and one for https links to the `appLinkDomains`.
@@ -106,6 +429,47 @@ export const deepLinkEntries = (app) => [
106
429
  '</intent-filter>',
107
430
  ]),
108
431
  ].join('\n');
432
+ /** The module behind `LynxShareTarget`, which only `shareTarget` keeps. */
433
+ export const ANDROID_SHARE_TARGET_SOURCE = `${SHELL_SOURCES}/ShareTargetModule.kt`;
434
+ /** `shareTarget.mimeTypes`, which ShareTargetModule reads. */
435
+ const SHARE_TARGET_STRINGS = 'app/src/main/res/values/share_target.xml';
436
+ /**
437
+ * The intent filters that put the app in other apps' share sheets for
438
+ * `shareTarget.mimeTypes`: one for a share of one thing (`ACTION_SEND`) and
439
+ * one for several (`ACTION_SEND_MULTIPLE`), each with every type.
440
+ *
441
+ * Android shares a link as text: Chrome sends a page's URL as `text/plain`,
442
+ * and few apps send `text/uri-list`. So `text/uri-list` keeps its own type
443
+ * and also takes `text/plain`, and ShareTargetModule hands the app only the shares whose
444
+ * text is one link when `text/plain` itself isn't listed.
445
+ */
446
+ export const shareTargetEntries = (app) => {
447
+ if (!app.shareTarget)
448
+ return '';
449
+ const types = [
450
+ ...new Set(app.shareTarget.mimeTypes.flatMap((type) => type === 'text/uri-list' ? ['text/uri-list', 'text/plain'] : [type])),
451
+ ];
452
+ return ['SEND', 'SEND_MULTIPLE']
453
+ .flatMap((action) => [
454
+ '<intent-filter>',
455
+ ` <action android:name="android.intent.action.${action}" />`,
456
+ ' <category android:name="android.intent.category.DEFAULT" />',
457
+ ...types.map((type) => ` <data android:mimeType="${escapeXml(type)}" />`),
458
+ '</intent-filter>',
459
+ ])
460
+ .join('\n');
461
+ };
462
+ /** res/values/share_target.xml: the types the app takes, for ShareTargetModule. */
463
+ export const shareTargetStringsXml = (mimeTypes) => [
464
+ '<?xml version="1.0" encoding="utf-8"?>',
465
+ '<!-- Written by @blotch/angular-lynx-native from shareTarget in angular.json. -->',
466
+ '<resources>',
467
+ ' <string-array name="angular_lynx_share_mime_types" translatable="false">',
468
+ ...mimeTypes.map((type) => ` <item>${escapeXml(type)}</item>`),
469
+ ' </string-array>',
470
+ '</resources>',
471
+ '',
472
+ ].join('\n');
109
473
  /** What an intent filter for links a browser can follow opens on. */
110
474
  const VIEW_INTENT = [
111
475
  ' <action android:name="android.intent.action.VIEW" />',
package/dist/eject.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type NativeFeatures } from './features.ts';
1
2
  import { type Platform } from './generate.ts';
2
3
  import { type NativeAppOptions } from './options.ts';
3
4
  /**
@@ -5,8 +6,16 @@ import { type NativeAppOptions } from './options.ts';
5
6
  * `ng generate @blotch/angular-lynx:eject`: the same project the builder
6
7
  * generates, plus the marker that tells the builder to build it as it is.
7
8
  * Returns its files (relative path → contents), for the schematic to write.
9
+ *
10
+ * It keeps all the shells' optional native code unless `features` says
11
+ * otherwise. The builder never leaves anything out of an ejected project
12
+ * (it's built as it is), so the schematic passes none: the project is the
13
+ * user's to grow, and a canvas added later has to draw. A script that renders
14
+ * a project only to build it, as the benchmark's ReactLynx iOS app does
15
+ * (issue #858), passes what its bundle uses, so the shell leaves out what a
16
+ * generated one would.
8
17
  */
9
- export declare const renderEjectedProject: ({ platform, projectRoot, projectName, packageVersion, app, generatorVersion, }: {
18
+ export declare const renderEjectedProject: ({ platform, projectRoot, projectName, packageVersion, app, generatorVersion, features, }: {
10
19
  readonly platform: Platform;
11
20
  readonly projectRoot: string;
12
21
  readonly projectName: string;
@@ -14,5 +23,10 @@ export declare const renderEjectedProject: ({ platform, projectRoot, projectName
14
23
  readonly app: NativeAppOptions;
15
24
  /** This package's version, recorded in the marker for later upgrades. */
16
25
  readonly generatorVersion: string;
26
+ /**
27
+ * The optional native code to keep, as readNativeFeatures reads it from a
28
+ * bundle. Everything by default.
29
+ */
30
+ readonly features?: NativeFeatures;
17
31
  }) => Map<string, Buffer>;
18
32
  //# sourceMappingURL=eject.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"eject.d.ts","sourceRoot":"","sources":["../src/eject.ts"],"names":[],"mappings":"AAYA,OAAO,EAAgB,KAAK,QAAQ,EAAiB,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAE,KAAK,gBAAgB,EAAqB,MAAM,cAAc,CAAC;AA+BxE;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,GAAI,gFAOlC;IACD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC;IAC/B,yEAAyE;IACzE,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;CACnC,KAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CA8BrB,CAAC"}
1
+ {"version":3,"file":"eject.d.ts","sourceRoot":"","sources":["../src/eject.ts"],"names":[],"mappings":"AAYA,OAAO,EAAuB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAgB,KAAK,QAAQ,EAAiB,MAAM,eAAe,CAAC;AAE3E,OAAO,EAAE,KAAK,gBAAgB,EAAqB,MAAM,cAAc,CAAC;AA+BxE;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,oBAAoB,GAAI,0FAQlC;IACD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,GAAG,EAAE,gBAAgB,CAAC;IAC/B,yEAAyE;IACzE,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,cAAc,CAAC;CACpC,KAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CA4BrB,CAAC"}
package/dist/eject.js CHANGED
@@ -2,6 +2,7 @@ import { cpSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync,
2
2
  import os from 'node:os';
3
3
  import path from 'node:path';
4
4
  import { androidGenerator } from "./android/project.js";
5
+ import { ALL_NATIVE_FEATURES } from "./features.js";
5
6
  import { EJECT_MARKER, TEMPLATES_DIR } from "./generate.js";
6
7
  import { iosGenerator } from "./ios/project.js";
7
8
  import { resolveAppOptions } from "./options.js";
@@ -38,13 +39,23 @@ const GITIGNORE = {
38
39
  * `ng generate @blotch/angular-lynx:eject`: the same project the builder
39
40
  * generates, plus the marker that tells the builder to build it as it is.
40
41
  * Returns its files (relative path → contents), for the schematic to write.
42
+ *
43
+ * It keeps all the shells' optional native code unless `features` says
44
+ * otherwise. The builder never leaves anything out of an ejected project
45
+ * (it's built as it is), so the schematic passes none: the project is the
46
+ * user's to grow, and a canvas added later has to draw. A script that renders
47
+ * a project only to build it, as the benchmark's ReactLynx iOS app does
48
+ * (issue #858), passes what its bundle uses, so the shell leaves out what a
49
+ * generated one would.
41
50
  */
42
- export const renderEjectedProject = ({ platform, projectRoot, projectName, packageVersion, app, generatorVersion, }) => {
51
+ export const renderEjectedProject = ({ platform, projectRoot, projectName, packageVersion, app, generatorVersion, features = ALL_NATIVE_FEATURES, }) => {
43
52
  const resolved = resolveAppOptions(app, { projectName, packageVersion });
44
53
  const dir = mkdtempSync(path.join(os.tmpdir(), `angular-lynx-eject-`));
45
54
  try {
46
55
  cpSync(path.join(TEMPLATES_DIR, platform), dir, { recursive: true });
47
- (platform === 'ios' ? iosGenerator : androidGenerator).configure(dir, resolved, projectRoot);
56
+ const generator = platform === 'ios' ? iosGenerator : androidGenerator;
57
+ generator.configure(dir, resolved, projectRoot);
58
+ generator.leaveOut(dir, features, resolved);
48
59
  writeFileSync(path.join(dir, '.gitignore'), GITIGNORE[platform]);
49
60
  writeFileSync(path.join(dir, EJECT_MARKER), [
50
61
  `Ejected from @blotch/angular-lynx-native ${generatorVersion}.`,
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The file the build plugin writes beside the Lynx bundle
3
+ * (`@blotch/rsbuild-plugin-angular-lynx`'s native-features.ts, under the
4
+ * same name): which of the shells' optional native code the app needs, from
5
+ * what its main-thread modules name. The leading dot keeps copyBundle from
6
+ * copying it into the app.
7
+ */
8
+ export declare const NATIVE_FEATURES_FILE = ".angular-lynx-native.json";
9
+ /**
10
+ * The shells' optional native code. `canvas` is `<canvas>` and its
11
+ * `AngularLynxWebGL` module (the WebGL2, 2D and `bitmaprenderer` contexts,
12
+ * and the decoding behind `Image` and `createImageBitmap()`), `<video>`'s
13
+ * frames a canvas reads, and on iOS ANGLE, which WebGL draws with. Without
14
+ * it, an app's iOS executable is about 176 kB smaller and it embeds no ANGLE
15
+ * frameworks, about 6 MB (issue #837).
16
+ *
17
+ * `webgl` is the part of it only the WebGL2 context uses: the context itself
18
+ * (`AngularLynxWebGLContext.m`, `WebGLContext.kt`), its command numbers and,
19
+ * on iOS, ANGLE. An app that draws only in 2D (a chart, a signature pad, an
20
+ * image editor) keeps the canvas without it, since the 2D context draws with
21
+ * Core Graphics and `android.graphics.Canvas` (issue #847). It's never true
22
+ * without `canvas`.
23
+ */
24
+ export type NativeFeatures = {
25
+ readonly canvas: boolean;
26
+ readonly webgl: boolean;
27
+ };
28
+ /** Everything: what an app gets when nothing says what it needs. */
29
+ export declare const ALL_NATIVE_FEATURES: NativeFeatures;
30
+ /**
31
+ * What the bundle in `bundleDir` needs, from NATIVE_FEATURES_FILE.
32
+ *
33
+ * Everything when there's no bundle (`ng serve --platform`'s development
34
+ * app, which loads its bundle from the dev server and gets every edit, so a
35
+ * canvas added while it runs has to draw), or no file or one this version
36
+ * can't read (a bundle from an older plugin or another build): leaving out
37
+ * code the app uses would leave it a blank canvas, while keeping what it
38
+ * doesn't use only costs size. For the same reason a file with
39
+ * `"canvas": true` and no `webgl`, from a plugin before #847, keeps WebGL.
40
+ *
41
+ * @param bundleDir - The rspeedy output folder, or undefined for the
42
+ * development app.
43
+ */
44
+ export declare const readNativeFeatures: (bundleDir: string | undefined) => NativeFeatures;
45
+ /**
46
+ * Deletes `files` (relative to `dir`), each of which must be in the
47
+ * template: a renamed file would otherwise stay in every app unnoticed.
48
+ */
49
+ export declare const removeTemplateFiles: (dir: string, files: readonly string[]) => void;
50
+ /**
51
+ * Takes out of a source file the lines between `// angular-lynx:<name>` and
52
+ * `// /angular-lynx:<name>`, the markers with them, wherever they are. The
53
+ * templates mark the few lines that use optional code, so the project still
54
+ * builds once it's gone.
55
+ */
56
+ export declare const removeMarkedLines: (file: string, name: string) => void;
57
+ /**
58
+ * Takes out of the Wi-Fi module (`source`, the Swift or Kotlin file) what
59
+ * angular.json's `wifi` doesn't turn on: the whole file without either part,
60
+ * or the lines of the part that's off, between `// angular-lynx:wifi-read`
61
+ * (currentNetwork, and the location code behind it) or
62
+ * `// angular-lynx:wifi-join` (join and leave) markers. Each module's
63
+ * `methodLookup` or `@LynxMethod`s are in those lines too, so the runtime
64
+ * rejects a part that's off with `unavailable`.
65
+ */
66
+ export declare const leaveOutWifi: (dir: string, wifi: {
67
+ readonly join: boolean;
68
+ readonly readCurrentNetwork: boolean;
69
+ }, source: string) => void;
70
+ //# sourceMappingURL=features.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../src/features.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,8BAA8B,CAAC;AAEhE;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IACzB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF,oEAAoE;AACpE,eAAO,MAAM,mBAAmB,EAAE,cAGjC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,kBAAkB,GAC7B,WAAW,MAAM,GAAG,SAAS,KAC5B,cAoBF,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,GAC9B,KAAK,MAAM,EACX,OAAO,SAAS,MAAM,EAAE,KACvB,IAQF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,EAAE,MAAM,MAAM,KAAG,IAwB9D,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,GACvB,KAAK,MAAM,EACX,MAAM;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAA;CAAE,EACtE,QAAQ,MAAM,KACb,IASF,CAAC"}