@blotch/angular-lynx-native 22.2.20 → 22.2.22
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 +8 -4
- package/dist/android/build.d.ts +6 -1
- package/dist/android/build.d.ts.map +1 -1
- package/dist/android/build.js +14 -3
- package/dist/android/icon.d.ts +29 -0
- package/dist/android/icon.d.ts.map +1 -0
- package/dist/android/icon.js +142 -0
- package/dist/android/project.d.ts +2 -1
- package/dist/android/project.d.ts.map +1 -1
- package/dist/android/project.js +5 -2
- package/dist/android/run.d.ts +10 -1
- package/dist/android/run.d.ts.map +1 -1
- package/dist/android/run.js +46 -1
- package/dist/dev-build.d.ts +16 -0
- package/dist/dev-build.d.ts.map +1 -0
- package/dist/dev-build.js +44 -0
- package/dist/generate.d.ts +26 -7
- package/dist/generate.d.ts.map +1 -1
- package/dist/generate.js +25 -10
- package/dist/index.d.ts +13 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +77 -13
- package/dist/ios/build.d.ts +68 -12
- package/dist/ios/build.d.ts.map +1 -1
- package/dist/ios/build.js +210 -45
- package/dist/ios/iphone.d.ts +99 -0
- package/dist/ios/iphone.d.ts.map +1 -0
- package/dist/ios/iphone.js +207 -0
- package/dist/ios/project.d.ts +10 -1
- package/dist/ios/project.d.ts.map +1 -1
- package/dist/ios/project.js +27 -4
- package/dist/ios/run.d.ts +18 -3
- package/dist/ios/run.d.ts.map +1 -1
- package/dist/ios/run.js +34 -5
- package/dist/options.d.ts +49 -3
- package/dist/options.d.ts.map +1 -1
- package/dist/options.js +33 -1
- package/dist/permissions.d.ts.map +1 -1
- package/dist/permissions.js +6 -0
- package/dist/png.d.ts +38 -0
- package/dist/png.d.ts.map +1 -1
- package/dist/png.js +167 -0
- package/dist/run.d.ts +54 -6
- package/dist/run.d.ts.map +1 -1
- package/dist/run.js +16 -1
- package/package.json +5 -1
- package/templates/android/README.md +5 -1
- package/templates/android/app/src/debug/java/dev/angularlynx/shell/DevServer.kt +159 -0
- package/templates/android/app/src/debug/java/dev/angularlynx/shell/DevServerModules.kt +163 -0
- package/templates/android/app/src/debug/res/xml/network_security_config.xml +13 -0
- package/templates/android/app/src/main/AndroidManifest.xml +16 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/AssetsModule.kt +22 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/MainActivity.kt +24 -1
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ResourceFetchers.kt +12 -6
- package/templates/android/app/src/main/java/dev/angularlynx/shell/ShareModule.kt +274 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLContext.kt +57 -0
- package/templates/android/app/src/main/java/dev/angularlynx/shell/WebGLModule.kt +95 -0
- package/templates/android/app/src/main/res/mipmap/ic_launcher_round.xml +6 -0
- package/templates/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +6 -0
- package/templates/android/app/src/main/res/xml/share_paths.xml +8 -0
- package/templates/android/app/src/release/java/dev/angularlynx/shell/DevServer.kt +24 -0
- package/templates/ios/App/AngularLynxWebGL.h +7 -0
- package/templates/ios/App/AngularLynxWebGL.m +27 -0
- package/templates/ios/App/AngularLynxWebGLContext.m +139 -0
- package/templates/ios/App/AssetsModule.swift +21 -3
- package/templates/ios/App/BundleResourceFetcher.swift +46 -2
- package/templates/ios/App/DevServer.swift +190 -0
- package/templates/ios/App/DevServerModules.swift +223 -0
- package/templates/ios/App/LynxViewController.swift +11 -1
- package/templates/ios/App/ShareModule.swift +215 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/ios/project.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,eAAe,CAAC;AAiB9D;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,iBA6B1B,CAAC;AAQF,eAAO,MAAM,QAAQ,GAAI,KAAK,WAAW,KAAG,MAY9B,CAAC;AAEf,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"project.d.ts","sourceRoot":"","sources":["../../src/ios/project.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,OAAO,KAAK,EAAe,WAAW,EAAE,MAAM,eAAe,CAAC;AAiB9D;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,iBA6B1B,CAAC;AAQF,eAAO,MAAM,QAAQ,GAAI,KAAK,WAAW,KAAG,MAY9B,CAAC;AAEf,mFAAmF;AACnF,eAAO,MAAM,0BAA0B,uDACe,CAAC;AAEvD;;;GAGG;AACH,eAAO,MAAM,oBAAoB,uEACqC,CAAC;AAEvE,eAAO,MAAM,gBAAgB,GAC3B,KAAK,WAAW,EAChB,kBAAyB;IAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAO,KAC/D,MAmEF,CAAC"}
|
package/dist/ios/project.js
CHANGED
|
@@ -21,10 +21,10 @@ const ORIENTATIONS = {
|
|
|
21
21
|
* between the template's `angular-lynx:info` markers.
|
|
22
22
|
*/
|
|
23
23
|
export const iosGenerator = {
|
|
24
|
-
configure: (dir, app, projectRoot) => {
|
|
24
|
+
configure: (dir, app, projectRoot, development = false) => {
|
|
25
25
|
writeFileSync(path.join(dir, 'Config/App.xcconfig'), xcconfig(app));
|
|
26
26
|
const plistPath = path.join(dir, 'App/Info.plist');
|
|
27
|
-
writeFileSync(plistPath, replaceMarker(readFileSync(plistPath, 'utf8'), 'info', infoPlistEntries(app)));
|
|
27
|
+
writeFileSync(plistPath, replaceMarker(readFileSync(plistPath, 'utf8'), 'info', infoPlistEntries(app, { development })));
|
|
28
28
|
if (app.icon) {
|
|
29
29
|
const icon = path.resolve(projectRoot, app.icon);
|
|
30
30
|
const size = readPngSize(icon);
|
|
@@ -52,7 +52,14 @@ export const xcconfig = (app) => [
|
|
|
52
52
|
`DEVELOPMENT_TEAM = ${app.ios.teamId ?? ''}`,
|
|
53
53
|
'',
|
|
54
54
|
].join('\n');
|
|
55
|
-
|
|
55
|
+
/** What iOS shows the first time someone taps Save Image, without `savePhotos`. */
|
|
56
|
+
export const DEFAULT_SAVE_PHOTOS_REASON = 'Saves the images you choose to your photo library.';
|
|
57
|
+
/**
|
|
58
|
+
* What iOS shows the first time the development app connects to the dev
|
|
59
|
+
* server, on a real iPhone. The simulator never asks.
|
|
60
|
+
*/
|
|
61
|
+
export const LOCAL_NETWORK_REASON = 'Loads the app from ng serve on your computer while you develop it.';
|
|
62
|
+
export const infoPlistEntries = (app, { development = false } = {}) => {
|
|
56
63
|
const lines = [];
|
|
57
64
|
const array = (key, values) => {
|
|
58
65
|
lines.push(`<key>${key}</key>`, '<array>');
|
|
@@ -63,12 +70,28 @@ export const infoPlistEntries = (app) => {
|
|
|
63
70
|
// Read by LynxViewController, which lays the LynxView out over the whole
|
|
64
71
|
// screen or inside the safe area.
|
|
65
72
|
lines.push('<key>AngularLynxEdgeToEdge</key>', app.edgeToEdge ? '<true/>' : '<false/>');
|
|
66
|
-
for
|
|
73
|
+
// The share sheet LynxShare opens has Save Image for an image, which adds
|
|
74
|
+
// it to the photo library, and iOS ends an app that does so without a
|
|
75
|
+
// reason in Info.plist. So every app has one, which `savePhotos` changes.
|
|
76
|
+
const permissions = {
|
|
77
|
+
savePhotos: DEFAULT_SAVE_PHOTOS_REASON,
|
|
78
|
+
...app.permissions,
|
|
79
|
+
};
|
|
80
|
+
for (const [permission, reason] of Object.entries(permissions)) {
|
|
67
81
|
for (const key of PERMISSION_MAP[permission]
|
|
68
82
|
.ios) {
|
|
69
83
|
lines.push(`<key>${key}</key>`, `<string>${escapeXml(reason)}</string>`);
|
|
70
84
|
}
|
|
71
85
|
}
|
|
86
|
+
// `ng serve --platform ios`'s development app loads from the dev server at
|
|
87
|
+
// the Mac's address on the local network, which iOS (14 and later) lets an
|
|
88
|
+
// app reach only once the person allows it. iOS asks the first time, with
|
|
89
|
+
// this reason. Only the development app has it: the app for the stores
|
|
90
|
+
// loads its own bundle, and App Review asks about any reason it doesn't
|
|
91
|
+
// need.
|
|
92
|
+
if (development) {
|
|
93
|
+
lines.push('<key>NSLocalNetworkUsageDescription</key>', `<string>${escapeXml(LOCAL_NETWORK_REASON)}</string>`);
|
|
94
|
+
}
|
|
72
95
|
// The schemes LinkingModule's canOpenURL can ask about: iOS answers false
|
|
73
96
|
// for any other. UIApplication.open needs none of them.
|
|
74
97
|
array('LSApplicationQueriesSchemes', app.canOpenURLSchemes);
|
package/dist/ios/run.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type RunTarget } from '../run.ts';
|
|
2
2
|
/** What `xcrun simctl list --json devices runtimes` prints, as far as it's read here. */
|
|
3
3
|
export type SimctlList = {
|
|
4
4
|
readonly devices: Readonly<Record<string, readonly SimctlDevice[]>>;
|
|
@@ -46,16 +46,31 @@ export type Simulator = {
|
|
|
46
46
|
* newest iOS runtime, preferring a simulator that exists (Xcode creates one
|
|
47
47
|
* of each iPhone) over creating one.
|
|
48
48
|
*/
|
|
49
|
-
export declare const pickSimulator: (list: SimctlList, device: string | undefined
|
|
49
|
+
export declare const pickSimulator: (list: SimctlList, device: string | undefined,
|
|
50
|
+
/** The paired iPhones' names, listed when `device` names nothing. */
|
|
51
|
+
iPhones?: readonly string[]) => Simulator;
|
|
52
|
+
/**
|
|
53
|
+
* Picks where `ng build --platform ios --run` opens the app: the paired
|
|
54
|
+
* iPhone `--device` names, or else a simulator. Without `--device` it's
|
|
55
|
+
* always a simulator, so a phone left plugged in doesn't change what `--run`
|
|
56
|
+
* does.
|
|
57
|
+
*/
|
|
58
|
+
export declare const startIosTarget: ({ device, logFile, log, }: {
|
|
59
|
+
readonly device: string | undefined;
|
|
60
|
+
readonly logFile: string;
|
|
61
|
+
readonly log: (message: string) => void;
|
|
62
|
+
}) => Promise<RunTarget>;
|
|
50
63
|
/**
|
|
51
64
|
* Picks the simulator for `--run` and starts booting it, so it boots while
|
|
52
65
|
* xcodebuild compiles. The returned target installs and opens the app once
|
|
53
66
|
* it's built.
|
|
54
67
|
*/
|
|
55
|
-
export declare const startIosSimulator: ({ device, logFile, log, }: {
|
|
68
|
+
export declare const startIosSimulator: ({ device, logFile, log, iPhones, }: {
|
|
56
69
|
readonly device: string | undefined;
|
|
57
70
|
readonly logFile: string;
|
|
58
71
|
readonly log: (message: string) => void;
|
|
72
|
+
/** The paired iPhones' names, listed when `device` names nothing. */
|
|
73
|
+
readonly iPhones?: readonly string[];
|
|
59
74
|
}) => Promise<RunTarget>;
|
|
60
75
|
export {};
|
|
61
76
|
//# sourceMappingURL=run.d.ts.map
|
package/dist/ios/run.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/ios/run.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"run.d.ts","sourceRoot":"","sources":["../../src/ios/run.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAyB,MAAM,WAAW,CAAC;AAGlE,yFAAyF;AACzF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,YAAY,EAAE,CAAC,CAAC,CAAC;IACpE,QAAQ,CAAC,QAAQ,EAAE,SAAS,aAAa,EAAE,CAAC;CAC7C,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0DAA0D;IAC1D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC;IACtC,QAAQ,CAAC,UAA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O,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC,KAAG,OAAO,CAAC,SAAS,CAcpB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAU,oCAKrC;IACD,QAAQ,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,qEAAqE;IACrE,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACtC,KAAG,OAAO,CAAC,SAAS,CAgEpB,CAAC"}
|
package/dist/ios/run.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { existsSync } from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { NativeBuildError, capture, run } from "../process.js";
|
|
4
|
+
import { iosDevServerArguments } from "../run.js";
|
|
5
|
+
import { listIPhones, pickIPhone, startIPhone } from "./iphone.js";
|
|
4
6
|
/**
|
|
5
7
|
* Chooses the simulator `ng build --platform ios --run` opens the app on.
|
|
6
8
|
*
|
|
@@ -10,7 +12,9 @@ import { NativeBuildError, capture, run } from "../process.js";
|
|
|
10
12
|
* newest iOS runtime, preferring a simulator that exists (Xcode creates one
|
|
11
13
|
* of each iPhone) over creating one.
|
|
12
14
|
*/
|
|
13
|
-
export const pickSimulator = (list, device
|
|
15
|
+
export const pickSimulator = (list, device,
|
|
16
|
+
/** The paired iPhones' names, listed when `device` names nothing. */
|
|
17
|
+
iPhones = []) => {
|
|
14
18
|
const runtimes = list.runtimes
|
|
15
19
|
.filter((runtime) => runtime.isAvailable &&
|
|
16
20
|
(runtime.platform
|
|
@@ -39,7 +43,9 @@ export const pickSimulator = (list, device) => {
|
|
|
39
43
|
const match = matches.find((simulator) => simulator.booted) ?? matches[0];
|
|
40
44
|
if (!match) {
|
|
41
45
|
const names = [...new Set(simulators.map((simulator) => simulator.name))];
|
|
42
|
-
throw new NativeBuildError(`There's no iOS simulator named "${device}". Pass the name or UDID of one of these: ${names.join(', ')}.
|
|
46
|
+
throw new NativeBuildError(`There's no iOS simulator or paired iPhone named "${device}". Pass the name or UDID of one of these simulators: ${names.join(', ')}${iPhones.length > 0
|
|
47
|
+
? `; or of one of these iPhones: ${iPhones.join(', ')}.`
|
|
48
|
+
: `. Or create a simulator in Xcode's DeviceHub, or pair an iPhone: connect it with a USB cable, unlock it and tap Trust.`}`);
|
|
43
49
|
}
|
|
44
50
|
return match;
|
|
45
51
|
}
|
|
@@ -87,12 +93,33 @@ const compareVersions = (a, b) => {
|
|
|
87
93
|
}
|
|
88
94
|
return 0;
|
|
89
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* Picks where `ng build --platform ios --run` opens the app: the paired
|
|
98
|
+
* iPhone `--device` names, or else a simulator. Without `--device` it's
|
|
99
|
+
* always a simulator, so a phone left plugged in doesn't change what `--run`
|
|
100
|
+
* does.
|
|
101
|
+
*/
|
|
102
|
+
export const startIosTarget = async ({ device, logFile, log, }) => {
|
|
103
|
+
if (!device) {
|
|
104
|
+
return startIosSimulator({ device, logFile, log });
|
|
105
|
+
}
|
|
106
|
+
const iPhones = await listIPhones();
|
|
107
|
+
const iPhone = pickIPhone(iPhones, device);
|
|
108
|
+
return iPhone
|
|
109
|
+
? startIPhone({ phone: iPhone, logFile, log })
|
|
110
|
+
: startIosSimulator({
|
|
111
|
+
device,
|
|
112
|
+
logFile,
|
|
113
|
+
log,
|
|
114
|
+
iPhones: iPhones.map((phone) => phone.name),
|
|
115
|
+
});
|
|
116
|
+
};
|
|
90
117
|
/**
|
|
91
118
|
* Picks the simulator for `--run` and starts booting it, so it boots while
|
|
92
119
|
* xcodebuild compiles. The returned target installs and opens the app once
|
|
93
120
|
* it's built.
|
|
94
121
|
*/
|
|
95
|
-
export const startIosSimulator = async ({ device, logFile, log, }) => {
|
|
122
|
+
export const startIosSimulator = async ({ device, logFile, log, iPhones, }) => {
|
|
96
123
|
const output = await capture('xcrun', [
|
|
97
124
|
'simctl',
|
|
98
125
|
'list',
|
|
@@ -103,7 +130,7 @@ export const startIosSimulator = async ({ device, logFile, log, }) => {
|
|
|
103
130
|
if (output === undefined) {
|
|
104
131
|
throw new NativeBuildError("Couldn't list the iOS simulators with `xcrun simctl`. Install Xcode and open it once, so it installs its command-line tools and the iOS platform.");
|
|
105
132
|
}
|
|
106
|
-
const simulator = pickSimulator(JSON.parse(output), device);
|
|
133
|
+
const simulator = pickSimulator(JSON.parse(output), device, iPhones);
|
|
107
134
|
const xcrun = (args) => run('xcrun', args, { cwd: process.cwd(), logFile });
|
|
108
135
|
const label = `${simulator.name} (${simulator.runtime.name})`;
|
|
109
136
|
log(simulator.booted
|
|
@@ -123,7 +150,8 @@ export const startIosSimulator = async ({ device, logFile, log, }) => {
|
|
|
123
150
|
const booted = xcrun(['simctl', 'bootstatus', udid, '-b']);
|
|
124
151
|
booted.catch(() => { });
|
|
125
152
|
return {
|
|
126
|
-
|
|
153
|
+
simulator: { udid },
|
|
154
|
+
launch: async (binary, app, devServer) => {
|
|
127
155
|
await booted;
|
|
128
156
|
await showSimulator(udid, logFile, log);
|
|
129
157
|
log(`Installing the app on ${simulator.name}`);
|
|
@@ -136,6 +164,7 @@ export const startIosSimulator = async ({ device, logFile, log, }) => {
|
|
|
136
164
|
'--terminate-running-process',
|
|
137
165
|
udid,
|
|
138
166
|
app.id,
|
|
167
|
+
...iosDevServerArguments(devServer),
|
|
139
168
|
]);
|
|
140
169
|
log(`Opened ${app.name} on ${simulator.name}`);
|
|
141
170
|
},
|
package/dist/options.d.ts
CHANGED
|
@@ -38,16 +38,39 @@ export type NativeAppOptions = {
|
|
|
38
38
|
* `mailto`, `tel` and `sms` are always there.
|
|
39
39
|
*/
|
|
40
40
|
readonly canOpenURLSchemes?: readonly string[];
|
|
41
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* A 1024×1024 PNG without transparency, relative to the project root. iOS
|
|
43
|
+
* uses it as it is. Android gets it resized for each screen density, round
|
|
44
|
+
* for the launchers that want a round icon, and as an adaptive icon (see
|
|
45
|
+
* {@link AndroidOptions.adaptiveIcon}).
|
|
46
|
+
*/
|
|
42
47
|
readonly icon?: string;
|
|
43
48
|
readonly ios?: IosOptions;
|
|
44
49
|
readonly android?: AndroidOptions;
|
|
45
50
|
};
|
|
46
51
|
export type Orientation = 'portrait' | 'landscape' | 'all';
|
|
47
|
-
export type Permission = 'camera' | 'microphone' | 'location' | 'photos' | 'contacts' | 'notifications';
|
|
52
|
+
export type Permission = 'camera' | 'microphone' | 'location' | 'photos' | 'savePhotos' | 'contacts' | 'notifications';
|
|
53
|
+
/**
|
|
54
|
+
* How the `.ipa` is signed, as Xcode's export methods name it:
|
|
55
|
+
* `app-store-connect` for App Store Connect and TestFlight, and
|
|
56
|
+
* `release-testing` (ad hoc) for the iPhones registered to the team, which
|
|
57
|
+
* install it from Finder or Apple Configurator.
|
|
58
|
+
*/
|
|
59
|
+
export type IosExportMethod = 'app-store-connect' | 'release-testing';
|
|
60
|
+
export declare const IOS_EXPORT_METHODS: readonly IosExportMethod[];
|
|
48
61
|
export type IosOptions = {
|
|
49
|
-
/**
|
|
62
|
+
/**
|
|
63
|
+
* The Apple Developer team that signs the app. On its own, it signs the
|
|
64
|
+
* development builds `--run --device <iPhone>` installs, with the Apple ID
|
|
65
|
+
* signed in to Xcode; a free Apple ID's Personal Team works for those.
|
|
66
|
+
*/
|
|
50
67
|
readonly teamId?: string;
|
|
68
|
+
/**
|
|
69
|
+
* Builds an `.ipa` signed this way. Defaults to `app-store-connect` once
|
|
70
|
+
* `signing` is set; without `signing`, the Apple ID signed in to Xcode
|
|
71
|
+
* signs it.
|
|
72
|
+
*/
|
|
73
|
+
readonly export?: IosExportMethod;
|
|
51
74
|
/**
|
|
52
75
|
* Headless signing with an App Store Connect API key. Each field names the
|
|
53
76
|
* environment variable that holds the value, so no secret is ever written
|
|
@@ -70,6 +93,23 @@ export type AndroidOptions = {
|
|
|
70
93
|
readonly keyAlias?: string;
|
|
71
94
|
readonly keyPasswordEnv?: string;
|
|
72
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* The two layers of the adaptive icon Android 8 and later show. The
|
|
98
|
+
* launcher masks it to its own shape and moves the layers apart as the
|
|
99
|
+
* icon is touched. Without it, the adaptive icon is `icon` alone, as the
|
|
100
|
+
* background layer, scaled so the masked shape shows all of it.
|
|
101
|
+
*/
|
|
102
|
+
readonly adaptiveIcon?: AdaptiveIcon;
|
|
103
|
+
};
|
|
104
|
+
export type AdaptiveIcon = {
|
|
105
|
+
/**
|
|
106
|
+
* A 1024×1024 PNG with transparency, relative to the project root. The
|
|
107
|
+
* launcher's mask crops its edges: keep what matters inside the middle 66
|
|
108
|
+
* of its 108 dp, about 626 px of the 1024.
|
|
109
|
+
*/
|
|
110
|
+
readonly foreground?: string;
|
|
111
|
+
/** A color (`#RRGGBB` or `#RGB`), or a 1024×1024 PNG like `foreground`. */
|
|
112
|
+
readonly background?: string;
|
|
73
113
|
};
|
|
74
114
|
/** {@link NativeAppOptions} with every default applied and every value checked. */
|
|
75
115
|
export type ResolvedApp = {
|
|
@@ -96,6 +136,12 @@ export type ResolvedApp = {
|
|
|
96
136
|
};
|
|
97
137
|
export declare class NativeConfigError extends Error {
|
|
98
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* The colors both CSS and Android resources read the same way. Android also
|
|
141
|
+
* takes `#ARGB` and `#AARRGGBB`, but CSS reads 4 and 8 digits with the alpha
|
|
142
|
+
* last, and an adaptive icon's background should be opaque anyway.
|
|
143
|
+
*/
|
|
144
|
+
export declare const ICON_BACKGROUND_COLOR: RegExp;
|
|
99
145
|
/**
|
|
100
146
|
* The schemes `LynxLinking.canOpenURL()` can always ask about: the web, mail,
|
|
101
147
|
* the phone and messages, which most apps link to.
|
package/dist/options.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","s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C,OAAO,EAAE,cAAc,CAAC;CAClC,CAAC;AAEF,qBAAa,iBAAkB,SAAQ,KAAK;CAAG;AAW/C;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAuC,CAAC;AAG1E;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAMnD,CAAC;AAaF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAC5B,YAAY,gBAAgB,EAC5B,UAAU;IAAE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAA;CAAE,KAC3E,WA+IF,CAAC;AAUF;;;;;;GAMG;AACH,eAAO,MAAM,OAAO,GAAI,OAAO,OAAO,KAAG,OAWxC,CAAC"}
|
package/dist/options.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export const IOS_EXPORT_METHODS = [
|
|
2
|
+
'app-store-connect',
|
|
3
|
+
'release-testing',
|
|
4
|
+
];
|
|
1
5
|
export class NativeConfigError extends Error {
|
|
2
6
|
}
|
|
3
7
|
/**
|
|
@@ -9,6 +13,12 @@ const APP_ID = /^[A-Za-z][A-Za-z0-9]*(\.[A-Za-z][A-Za-z0-9]*)+$/;
|
|
|
9
13
|
/** Up to three period-separated integers, as App Store Connect requires. */
|
|
10
14
|
const VERSION = /^\d+(\.\d+){0,2}$/;
|
|
11
15
|
const SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/;
|
|
16
|
+
/**
|
|
17
|
+
* The colors both CSS and Android resources read the same way. Android also
|
|
18
|
+
* takes `#ARGB` and `#AARRGGBB`, but CSS reads 4 and 8 digits with the alpha
|
|
19
|
+
* last, and an adaptive icon's background should be opaque anyway.
|
|
20
|
+
*/
|
|
21
|
+
export const ICON_BACKGROUND_COLOR = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;
|
|
12
22
|
/** Google Play's maximum versionCode. */
|
|
13
23
|
const MAX_BUILD_NUMBER = 2_100_000_000;
|
|
14
24
|
/**
|
|
@@ -29,6 +39,7 @@ const PERMISSIONS = [
|
|
|
29
39
|
'microphone',
|
|
30
40
|
'location',
|
|
31
41
|
'photos',
|
|
42
|
+
'savePhotos',
|
|
32
43
|
'contacts',
|
|
33
44
|
'notifications',
|
|
34
45
|
];
|
|
@@ -90,6 +101,27 @@ export const resolveAppOptions = (rawOptions, defaults) => {
|
|
|
90
101
|
if (canOpenURLSchemes.length > MAX_QUERIED_SCHEMES) {
|
|
91
102
|
throw new NativeConfigError(`canOpenURLSchemes lists ${canOpenURLSchemes.length} schemes with the ${ALWAYS_QUERIED_SCHEMES.length} always there (${ALWAYS_QUERIED_SCHEMES.join(', ')}). iOS reads no more than ${MAX_QUERIED_SCHEMES}.`);
|
|
92
103
|
}
|
|
104
|
+
const android = options.android ?? {};
|
|
105
|
+
if (android.adaptiveIcon) {
|
|
106
|
+
const { foreground, background } = android.adaptiveIcon;
|
|
107
|
+
if (!foreground || !background) {
|
|
108
|
+
throw new NativeConfigError('android.adaptiveIcon needs both a foreground (a PNG) and a background (a color like "#111111", or a PNG).');
|
|
109
|
+
}
|
|
110
|
+
if (!ICON_BACKGROUND_COLOR.test(background) &&
|
|
111
|
+
!background.toLowerCase().endsWith('.png')) {
|
|
112
|
+
throw new NativeConfigError(`android.adaptiveIcon.background "${background}" is neither a color (#RRGGBB or #RGB) nor a PNG file.`);
|
|
113
|
+
}
|
|
114
|
+
// Android 7, and launchers that ignore adaptive icons, still show the
|
|
115
|
+
// flat icon made from \`icon\`.
|
|
116
|
+
if (!options.icon) {
|
|
117
|
+
throw new NativeConfigError('android.adaptiveIcon needs icon too: Android 7 shows the flat icon made from it.');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const exportMethod = options.ios?.export;
|
|
121
|
+
if (exportMethod !== undefined &&
|
|
122
|
+
!IOS_EXPORT_METHODS.includes(exportMethod)) {
|
|
123
|
+
throw new NativeConfigError(`ios.export "${exportMethod}" is not valid. Use ${IOS_EXPORT_METHODS.join(' or ')}.`);
|
|
124
|
+
}
|
|
93
125
|
const productName = name.replace(/[^A-Za-z0-9]/g, '') || 'App';
|
|
94
126
|
const artifactName = name
|
|
95
127
|
.toLowerCase()
|
|
@@ -109,7 +141,7 @@ export const resolveAppOptions = (rawOptions, defaults) => {
|
|
|
109
141
|
productName,
|
|
110
142
|
artifactName,
|
|
111
143
|
ios: options.ios ?? {},
|
|
112
|
-
android
|
|
144
|
+
android,
|
|
113
145
|
};
|
|
114
146
|
};
|
|
115
147
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CACjC,UAAU,EACV;IACE,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C,
|
|
1
|
+
{"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../src/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,MAAM,CACjC,UAAU,EACV;IACE,QAAQ,CAAC,GAAG,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C,CAuCF,CAAC"}
|
package/dist/permissions.js
CHANGED
|
@@ -26,6 +26,12 @@ export const PERMISSION_MAP = {
|
|
|
26
26
|
ios: ['NSPhotoLibraryUsageDescription'],
|
|
27
27
|
android: ['android.permission.READ_MEDIA_IMAGES'],
|
|
28
28
|
},
|
|
29
|
+
// Adding to the photo library only, as the share sheet's Save Image does
|
|
30
|
+
// (LynxShare). Android needs no permission for it.
|
|
31
|
+
savePhotos: {
|
|
32
|
+
ios: ['NSPhotoLibraryAddUsageDescription'],
|
|
33
|
+
android: [],
|
|
34
|
+
},
|
|
29
35
|
contacts: {
|
|
30
36
|
ios: ['NSContactsUsageDescription'],
|
|
31
37
|
android: ['android.permission.READ_CONTACTS'],
|
package/dist/png.d.ts
CHANGED
|
@@ -7,4 +7,42 @@ export declare const readPngSize: (file: string) => {
|
|
|
7
7
|
readonly width: number;
|
|
8
8
|
readonly height: number;
|
|
9
9
|
};
|
|
10
|
+
/** A decoded image: 8-bit RGBA rows, top to bottom, not premultiplied. */
|
|
11
|
+
export type Image = {
|
|
12
|
+
readonly width: number;
|
|
13
|
+
readonly height: number;
|
|
14
|
+
readonly data: Uint8Array;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* Decodes a PNG of any color type and bit depth (palette, grayscale, 16-bit,
|
|
18
|
+
* interlaced) into 8-bit RGBA. pngjs is plain JavaScript, so this runs
|
|
19
|
+
* wherever Node does: Android builds don't need a Mac, so the icon can't be
|
|
20
|
+
* resized with macOS's `sips` the way an Xcode build could.
|
|
21
|
+
*/
|
|
22
|
+
export declare const decodePng: (bytes: Buffer) => Image;
|
|
23
|
+
export declare const encodePng: (image: Image) => Buffer;
|
|
24
|
+
/**
|
|
25
|
+
* Scales an image to `width`×`height` by averaging the source pixels each
|
|
26
|
+
* output pixel covers (a box filter, weighted by the fraction of each pixel
|
|
27
|
+
* covered). For the big reductions icons need (1024 px to 48), that keeps
|
|
28
|
+
* every source pixel's contribution, where bilinear sampling would skip most
|
|
29
|
+
* of them and alias thin lines.
|
|
30
|
+
*
|
|
31
|
+
* It averages premultiplied colors, so the color of a fully transparent
|
|
32
|
+
* pixel (often black) doesn't bleed into the edge of a shape next to it.
|
|
33
|
+
*/
|
|
34
|
+
export declare const resize: (image: Image, width: number, height: number) => Image;
|
|
35
|
+
/**
|
|
36
|
+
* Adds `inset` pixels on every side, each a copy of the nearest edge pixel.
|
|
37
|
+
* An adaptive icon layer is 108 dp, but the launcher shows only about the
|
|
38
|
+
* middle 72 and moves the layer around under its mask, so the margin must
|
|
39
|
+
* continue the picture rather than show a frame of another color.
|
|
40
|
+
*/
|
|
41
|
+
export declare const extendEdges: (image: Image, inset: number) => Image;
|
|
42
|
+
/**
|
|
43
|
+
* Clears everything outside the largest circle that fits, with a one-pixel
|
|
44
|
+
* soft edge so the circle isn't jagged: the round icon launchers on
|
|
45
|
+
* Android 7.1 show (`android:roundIcon`), which predates adaptive icons.
|
|
46
|
+
*/
|
|
47
|
+
export declare const maskCircle: (image: Image) => Image;
|
|
10
48
|
//# sourceMappingURL=png.d.ts.map
|
package/dist/png.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"png.d.ts","sourceRoot":"","sources":["../src/png.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"png.d.ts","sourceRoot":"","sources":["../src/png.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,eAAO,MAAM,WAAW,GACtB,MAAM,MAAM,KACX;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAiBnD,CAAC;AAYF,0EAA0E;AAC1E,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;CAC3B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,SAAS,GAAI,OAAO,MAAM,KAAG,KAGzC,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,OAAO,KAAK,KAAG,MAStC,CAAC;AAEJ;;;;;;;;;GASG;AACH,eAAO,MAAM,MAAM,GAAI,OAAO,KAAK,EAAE,OAAO,MAAM,EAAE,QAAQ,MAAM,KAAG,KAsBpE,CAAC;AA8FF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,OAAO,KAAK,EAAE,OAAO,MAAM,KAAG,KAazD,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,KAAK,KAAG,KAezC,CAAC"}
|
package/dist/png.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { closeSync, openSync, readSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
2
3
|
const SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
3
4
|
/**
|
|
4
5
|
* Reads a PNG's dimensions from its header, without decoding it. Enough to
|
|
@@ -22,3 +23,169 @@ export const readPngSize = (file) => {
|
|
|
22
23
|
}
|
|
23
24
|
return { width: header.readUInt32BE(16), height: header.readUInt32BE(20) };
|
|
24
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* pngjs, loaded the first time an icon is resized rather than with this
|
|
28
|
+
* module. Only Android needs it, and CI builds the iOS app from this
|
|
29
|
+
* package's tarball unpacked without its dependencies (packages/e2e's
|
|
30
|
+
* README), which works as long as the iOS path loads nothing but Node's
|
|
31
|
+
* built-ins.
|
|
32
|
+
*/
|
|
33
|
+
const pngjs = () => createRequire(import.meta.url)('pngjs').PNG;
|
|
34
|
+
/**
|
|
35
|
+
* Decodes a PNG of any color type and bit depth (palette, grayscale, 16-bit,
|
|
36
|
+
* interlaced) into 8-bit RGBA. pngjs is plain JavaScript, so this runs
|
|
37
|
+
* wherever Node does: Android builds don't need a Mac, so the icon can't be
|
|
38
|
+
* resized with macOS's `sips` the way an Xcode build could.
|
|
39
|
+
*/
|
|
40
|
+
export const decodePng = (bytes) => {
|
|
41
|
+
const png = pngjs().sync.read(bytes);
|
|
42
|
+
return { width: png.width, height: png.height, data: png.data };
|
|
43
|
+
};
|
|
44
|
+
export const encodePng = (image) => pngjs().sync.write(Object.assign(new (pngjs())({ width: image.width, height: image.height }), {
|
|
45
|
+
data: Buffer.from(image.data.buffer, image.data.byteOffset, image.data.byteLength),
|
|
46
|
+
}));
|
|
47
|
+
/**
|
|
48
|
+
* Scales an image to `width`×`height` by averaging the source pixels each
|
|
49
|
+
* output pixel covers (a box filter, weighted by the fraction of each pixel
|
|
50
|
+
* covered). For the big reductions icons need (1024 px to 48), that keeps
|
|
51
|
+
* every source pixel's contribution, where bilinear sampling would skip most
|
|
52
|
+
* of them and alias thin lines.
|
|
53
|
+
*
|
|
54
|
+
* It averages premultiplied colors, so the color of a fully transparent
|
|
55
|
+
* pixel (often black) doesn't bleed into the edge of a shape next to it.
|
|
56
|
+
*/
|
|
57
|
+
export const resize = (image, width, height) => {
|
|
58
|
+
// Separable: rows first, then columns, which is the same average as over
|
|
59
|
+
// each output pixel's rectangle, at a fraction of the work.
|
|
60
|
+
const rows = resizeAxis(premultiply(image), image.width, width, image.height, true);
|
|
61
|
+
const both = resizeAxis(rows, image.height, height, width, false);
|
|
62
|
+
const data = new Uint8Array(width * height * 4);
|
|
63
|
+
for (let i = 0; i < width * height * 4; i += 4) {
|
|
64
|
+
const alpha = both[i + 3];
|
|
65
|
+
const unpremultiply = alpha > 0 ? 1 / alpha : 0;
|
|
66
|
+
data[i] = toByte(both[i] * unpremultiply);
|
|
67
|
+
data[i + 1] = toByte(both[i + 1] * unpremultiply);
|
|
68
|
+
data[i + 2] = toByte(both[i + 2] * unpremultiply);
|
|
69
|
+
data[i + 3] = toByte(alpha * 255);
|
|
70
|
+
}
|
|
71
|
+
return { width, height, data };
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* Each image's premultiplied pixels, kept while the image is: the generator
|
|
75
|
+
* resizes one icon to a dozen sizes.
|
|
76
|
+
*/
|
|
77
|
+
const premultipliedCache = new WeakMap();
|
|
78
|
+
const premultiply = (image) => {
|
|
79
|
+
const cached = premultipliedCache.get(image);
|
|
80
|
+
if (cached) {
|
|
81
|
+
return cached;
|
|
82
|
+
}
|
|
83
|
+
const pixels = new Float32Array(image.data.length);
|
|
84
|
+
for (let i = 0; i < image.data.length; i += 4) {
|
|
85
|
+
const alpha = image.data[i + 3] / 255;
|
|
86
|
+
pixels[i] = image.data[i] * alpha;
|
|
87
|
+
pixels[i + 1] = image.data[i + 1] * alpha;
|
|
88
|
+
pixels[i + 2] = image.data[i + 2] * alpha;
|
|
89
|
+
pixels[i + 3] = alpha;
|
|
90
|
+
}
|
|
91
|
+
premultipliedCache.set(image, pixels);
|
|
92
|
+
return pixels;
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Box-filters one axis of an image `lines` pixels across the other axis.
|
|
96
|
+
* Rows (`horizontal`) are `from` pixels long going in and `to` coming out.
|
|
97
|
+
* Columns are `from` pixels tall going in and `to` coming out, and `lines`
|
|
98
|
+
* is the width, both before and after, since rows were resized first.
|
|
99
|
+
*/
|
|
100
|
+
const resizeAxis = (pixels, from, to, lines, horizontal) => {
|
|
101
|
+
const scale = from / to;
|
|
102
|
+
// Which source pixels each output pixel covers, and by how much: output
|
|
103
|
+
// pixel i reads `tapCount[i]` source pixels from `tapStart[i]`, with
|
|
104
|
+
// their weights in `weights` from `tapOffset[i]`. Flat typed arrays keep
|
|
105
|
+
// the loop below, run for every pixel of every line, free of objects.
|
|
106
|
+
const tapStart = new Int32Array(to);
|
|
107
|
+
const tapCount = new Int32Array(to);
|
|
108
|
+
const tapOffset = new Int32Array(to);
|
|
109
|
+
const weights = [];
|
|
110
|
+
for (let i = 0; i < to; i++) {
|
|
111
|
+
const start = i * scale;
|
|
112
|
+
const end = start + scale;
|
|
113
|
+
const first = Math.floor(start);
|
|
114
|
+
const last = Math.min(Math.ceil(end), from);
|
|
115
|
+
tapStart[i] = first;
|
|
116
|
+
tapCount[i] = last - first;
|
|
117
|
+
tapOffset[i] = weights.length;
|
|
118
|
+
for (let j = first; j < last; j++) {
|
|
119
|
+
weights.push((Math.min(end, j + 1) - Math.max(start, j)) / scale);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const weight = Float32Array.from(weights);
|
|
123
|
+
// How far apart, in floats, neighboring pixels along the axis are, and
|
|
124
|
+
// where each line starts, in the input and the output.
|
|
125
|
+
const step = horizontal ? 4 : lines * 4;
|
|
126
|
+
const inLine = horizontal ? from * 4 : 4;
|
|
127
|
+
const outLine = horizontal ? to * 4 : 4;
|
|
128
|
+
const out = new Float32Array(to * lines * 4);
|
|
129
|
+
for (let line = 0; line < lines; line++) {
|
|
130
|
+
for (let i = 0; i < to; i++) {
|
|
131
|
+
const target = line * outLine + i * step;
|
|
132
|
+
let r = 0;
|
|
133
|
+
let g = 0;
|
|
134
|
+
let b = 0;
|
|
135
|
+
let a = 0;
|
|
136
|
+
let source = line * inLine + tapStart[i] * step;
|
|
137
|
+
for (let k = 0, w = tapOffset[i]; k < tapCount[i]; k++, w++) {
|
|
138
|
+
const factor = weight[w];
|
|
139
|
+
r += pixels[source] * factor;
|
|
140
|
+
g += pixels[source + 1] * factor;
|
|
141
|
+
b += pixels[source + 2] * factor;
|
|
142
|
+
a += pixels[source + 3] * factor;
|
|
143
|
+
source += step;
|
|
144
|
+
}
|
|
145
|
+
out[target] = r;
|
|
146
|
+
out[target + 1] = g;
|
|
147
|
+
out[target + 2] = b;
|
|
148
|
+
out[target + 3] = a;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
return out;
|
|
152
|
+
};
|
|
153
|
+
const toByte = (value) => Math.min(255, Math.max(0, Math.round(value)));
|
|
154
|
+
/**
|
|
155
|
+
* Adds `inset` pixels on every side, each a copy of the nearest edge pixel.
|
|
156
|
+
* An adaptive icon layer is 108 dp, but the launcher shows only about the
|
|
157
|
+
* middle 72 and moves the layer around under its mask, so the margin must
|
|
158
|
+
* continue the picture rather than show a frame of another color.
|
|
159
|
+
*/
|
|
160
|
+
export const extendEdges = (image, inset) => {
|
|
161
|
+
const width = image.width + inset * 2;
|
|
162
|
+
const height = image.height + inset * 2;
|
|
163
|
+
const data = new Uint8Array(width * height * 4);
|
|
164
|
+
for (let y = 0; y < height; y++) {
|
|
165
|
+
const sourceY = Math.min(image.height - 1, Math.max(0, y - inset));
|
|
166
|
+
for (let x = 0; x < width; x++) {
|
|
167
|
+
const sourceX = Math.min(image.width - 1, Math.max(0, x - inset));
|
|
168
|
+
const source = (sourceY * image.width + sourceX) * 4;
|
|
169
|
+
data.set(image.data.subarray(source, source + 4), (y * width + x) * 4);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return { width, height, data };
|
|
173
|
+
};
|
|
174
|
+
/**
|
|
175
|
+
* Clears everything outside the largest circle that fits, with a one-pixel
|
|
176
|
+
* soft edge so the circle isn't jagged: the round icon launchers on
|
|
177
|
+
* Android 7.1 show (`android:roundIcon`), which predates adaptive icons.
|
|
178
|
+
*/
|
|
179
|
+
export const maskCircle = (image) => {
|
|
180
|
+
const data = Uint8Array.from(image.data);
|
|
181
|
+
const radius = Math.min(image.width, image.height) / 2;
|
|
182
|
+
for (let y = 0; y < image.height; y++) {
|
|
183
|
+
for (let x = 0; x < image.width; x++) {
|
|
184
|
+
const distance = Math.hypot(x + 0.5 - image.width / 2, y + 0.5 - image.height / 2);
|
|
185
|
+
const coverage = Math.min(1, Math.max(0, radius - distance + 0.5));
|
|
186
|
+
const alpha = (y * image.width + x) * 4 + 3;
|
|
187
|
+
data[alpha] = Math.round(data[alpha] * coverage);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return { width: image.width, height: image.height, data };
|
|
191
|
+
};
|