iconpeek 1.0.1
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/LICENSE +21 -0
- package/README.md +140 -0
- package/assets/placeholder-icon.png +0 -0
- package/generate_icons.py +219 -0
- package/package.json +24 -0
- package/server.js +1454 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# iconpeek
|
|
2
|
+
|
|
3
|
+
`iconpeek` is a zero-dependency local preview server for Expo app branding. It solves the slow feedback loop of changing app config, rebuilding native shells, and reinstalling just to see whether your adaptive icon crop, iOS icon mask, or splash colors are in the right neighborhood.
|
|
4
|
+
|
|
5
|
+
It is useful for React Native apps that use Expo config, including Expo-managed apps and many prebuild projects. Bare React Native support is not complete yet because native icon sources can live in Android resource folders, iOS asset catalogs, Gradle files, Xcode project settings, and third-party tooling.
|
|
6
|
+
|
|
7
|
+
## Quick Start
|
|
8
|
+
|
|
9
|
+
Run this inside your Expo project:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npx iconpeek
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
You can also point it at another project root or choose a starting port:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npx iconpeek --project /path/to/expo/app
|
|
19
|
+
npx iconpeek --port 5000
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## CLI Flags
|
|
23
|
+
|
|
24
|
+
- `--project <path>`: Read `app.json`, `app.config.json`, or `app.config.js` from a different Expo project root.
|
|
25
|
+
- `--port <number>`: Set the starting port. `iconpeek` defaults to `4200` and auto-increments if that port is already in use.
|
|
26
|
+
- `--no-open`: Start the server without opening a browser window.
|
|
27
|
+
|
|
28
|
+
## What It Previews
|
|
29
|
+
|
|
30
|
+
- Android adaptive icon mask math using the 108dp canvas, 72dp viewport, 18dp crop margin, and 66dp safe zone used by adaptive icons
|
|
31
|
+
- Android mask shape toggles for squircle, rounded rectangle, circle, and square
|
|
32
|
+
- Android foreground-only parallax movement to simulate launcher depth
|
|
33
|
+
- iOS icon preview with an approximate system rounded mask and transparency warning
|
|
34
|
+
- Android launcher and iOS homescreen context previews with the selected app icon highlighted
|
|
35
|
+
- Android and iOS size comparison rows for common system contexts
|
|
36
|
+
- Splash screen previews for light and dark themes with automatic status bar contrast
|
|
37
|
+
|
|
38
|
+
## `app.json` Field Mapping
|
|
39
|
+
|
|
40
|
+
`iconpeek` reads these keys:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"expo": {
|
|
45
|
+
"icon": "./assets/icon.png",
|
|
46
|
+
"android": {
|
|
47
|
+
"adaptiveIcon": {
|
|
48
|
+
"foregroundImage": "./assets/adaptive-icon.png",
|
|
49
|
+
"backgroundColor": "#FFFFFF"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"splash": {
|
|
53
|
+
"image": "./assets/splash.png",
|
|
54
|
+
"imageWidth": 160,
|
|
55
|
+
"backgroundColor": "#FFFFFF",
|
|
56
|
+
"dark": {
|
|
57
|
+
"image": "./assets/splash-dark.png",
|
|
58
|
+
"backgroundColor": "#121212"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
If the config file is missing or any asset path does not exist, `iconpeek` falls back to `assets/placeholder-icon.png` and shows a warning in the UI instead of crashing.
|
|
66
|
+
|
|
67
|
+
For `app.config.js`, `iconpeek` loads the local config module directly. That matches normal Expo expectations, but it also means config code can run. `module.exports = {...}` and `module.exports = ({ config }) => ({...})` always work. `export default` (ES module syntax) works automatically on Node 20.19+ or 22.12+, since those versions added native `require(esm)` support — on older Node (this package's declared floor is 14), it fails with an explicit error telling you to upgrade Node, convert the file to CommonJS, or use `app.json`/`app.config.json` instead.
|
|
68
|
+
|
|
69
|
+
## `generate_icons.py` Usage
|
|
70
|
+
|
|
71
|
+
Install the only Python dependency:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
pip install Pillow
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Basic usage:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
python generate_icons.py --source icon-1024.png --out ./icon_output
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
All supported flags:
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
python generate_icons.py \
|
|
87
|
+
--source icon-1024.png \
|
|
88
|
+
--out ./icon_output \
|
|
89
|
+
--android-fg adaptive-fg.png \
|
|
90
|
+
--android-bg "#F5A623" \
|
|
91
|
+
--ios-source ios-flat.png
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Flags:
|
|
95
|
+
|
|
96
|
+
- `--source`: Required base icon image used for Android legacy icons and, by default, every other output.
|
|
97
|
+
- `--out`: Output directory. Defaults to `./icon_output`.
|
|
98
|
+
- `--android-fg`: Optional dedicated Android adaptive foreground asset.
|
|
99
|
+
- `--android-bg`: Optional Android adaptive icon background color. Defaults to `#FFFFFF`.
|
|
100
|
+
- `--ios-source`: Optional alternate flat source used only for iOS icons.
|
|
101
|
+
|
|
102
|
+
The generator creates:
|
|
103
|
+
|
|
104
|
+
- Android legacy launcher icons per density
|
|
105
|
+
- Android adaptive foreground and background layers plus `mipmap-anydpi-v26` XML files. Foreground content is sized to the standard 72dp area on the 108dp canvas (matching Android Studio's Image Asset Studio default), not shrunk down to the 66dp safe-zone diameter — that diameter is the guaranteed-visible region, not a target canvas size for your artwork.
|
|
106
|
+
- A 512x512 Play Store icon flattened onto white
|
|
107
|
+
- A complete iOS `AppIcon.appiconset` with `Contents.json`, including both `iphone` and `ipad` idiom entries at every shared point size (20/29/40pt), not just iPhone sizes
|
|
108
|
+
|
|
109
|
+
The script warns when a source image is not square or is smaller than `1024x1024`.
|
|
110
|
+
|
|
111
|
+
## Testing
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
npm test
|
|
115
|
+
# or: bash tests/smoke-test.sh
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
This boots the real server against a set of fixture Expo projects (missing config, malformed JSON, `splash.imageWidth` set, 8-digit hex colors, a path-traversal attempt, an `app.config.js` using `export default`, and a fully-populated project) and checks actual HTTP responses — status codes, content types, warning text, and CLI argument validation.
|
|
119
|
+
|
|
120
|
+
It also statically diffs every `document.getElementById(...)` call in the rendered page against every `id="..."` attribute actually present, so a client-side id typo fails the suite immediately instead of only breaking in a browser on a specific config shape. `generate_icons.py` output is checked structurally too: iOS idiom coverage, Android adaptive-icon foreground sizing, and the embedded placeholder asset all get inspected, not just "did it exit 0."
|
|
121
|
+
|
|
122
|
+
## Publishing To npm
|
|
123
|
+
|
|
124
|
+
For contributors publishing a new release:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
npm test
|
|
128
|
+
npm version patch
|
|
129
|
+
npm publish
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Make sure `server.js`, `generate_icons.py`, `README.md`, `LICENSE`, and `assets/` are included in the package before publishing.
|
|
133
|
+
|
|
134
|
+
## Contributing
|
|
135
|
+
|
|
136
|
+
Ideas for future additions:
|
|
137
|
+
|
|
138
|
+
- Bare React Native config path support outside Expo
|
|
139
|
+
- Android 13 monochrome icon preview and export
|
|
140
|
+
- watchOS and additional Apple platform icon size generation
|
|
Binary file
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import base64
|
|
3
|
+
import io
|
|
4
|
+
import json
|
|
5
|
+
import sys
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
from PIL import Image, ImageDraw
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
ANDROID_DENSITIES = {
|
|
12
|
+
"mdpi": 48,
|
|
13
|
+
"hdpi": 72,
|
|
14
|
+
"xhdpi": 96,
|
|
15
|
+
"xxhdpi": 144,
|
|
16
|
+
"xxxhdpi": 192,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# (points, scale, idiom) tuples matching Apple's real AppIcon.appiconset
|
|
20
|
+
# requirements. Previously this only emitted "iphone" or "ipad" per *size*,
|
|
21
|
+
# which silently dropped the iPad entries for 20/29/40pt that Xcode expects
|
|
22
|
+
# alongside the iPhone ones at the same point size.
|
|
23
|
+
IOS_ICONS = [
|
|
24
|
+
(20, 2, "iphone"),
|
|
25
|
+
(20, 3, "iphone"),
|
|
26
|
+
(29, 2, "iphone"),
|
|
27
|
+
(29, 3, "iphone"),
|
|
28
|
+
(40, 2, "iphone"),
|
|
29
|
+
(40, 3, "iphone"),
|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lUKe3I3IAAAAASUVORK5CYII="
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def parse_args():
|
|
49
|
+
parser = argparse.ArgumentParser(description="Generate Android and iOS icon assets from one source image.")
|
|
50
|
+
parser.add_argument("--source", help="Source icon PNG", default=None)
|
|
51
|
+
parser.add_argument("--out", help="Output directory", default="icon_output")
|
|
52
|
+
parser.add_argument("--android-fg", help="Foreground image for adaptive icon", default=None)
|
|
53
|
+
parser.add_argument("--android-bg", help="Adaptive icon background color", default="#FFFFFF")
|
|
54
|
+
parser.add_argument("--ios-source", help="Alternate source image for iOS icons", default=None)
|
|
55
|
+
return parser.parse_args()
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def ensure_placeholder_asset():
|
|
59
|
+
return Image.open(io.BytesIO(base64.b64decode(PLACEHOLDER_BASE64))).convert("RGBA")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def ensure_repo_placeholder():
|
|
63
|
+
assets_dir = Path(__file__).resolve().parent / "assets"
|
|
64
|
+
placeholder_path = assets_dir / "placeholder-icon.png"
|
|
65
|
+
if placeholder_path.exists():
|
|
66
|
+
return
|
|
67
|
+
|
|
68
|
+
assets_dir.mkdir(parents=True, exist_ok=True)
|
|
69
|
+
ensure_placeholder_asset().save(placeholder_path)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def ensure_source_image(source_value):
|
|
73
|
+
if source_value:
|
|
74
|
+
source_path = Path(source_value).expanduser().resolve()
|
|
75
|
+
if not source_path.exists():
|
|
76
|
+
raise FileNotFoundError(f"Source image not found: {source_path}")
|
|
77
|
+
return source_path
|
|
78
|
+
|
|
79
|
+
return None
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def open_image(path_value):
|
|
83
|
+
return Image.open(path_value).convert("RGBA")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def flatten_to_white(image):
|
|
87
|
+
background = Image.new("RGB", image.size, "#FFFFFF")
|
|
88
|
+
background.paste(image, mask=image.getchannel("A") if "A" in image.getbands() else None)
|
|
89
|
+
return background
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def square_fit(image, size):
|
|
93
|
+
return image.resize((size, size), Image.LANCZOS)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def circular_icon(image, size):
|
|
97
|
+
base = image.resize((size, size), Image.LANCZOS)
|
|
98
|
+
mask = Image.new("L", (size, size), 0)
|
|
99
|
+
draw = ImageDraw.Draw(mask)
|
|
100
|
+
draw.ellipse((0, 0, size - 1, size - 1), fill=255)
|
|
101
|
+
result = Image.new("RGBA", (size, size), (0, 0, 0, 0))
|
|
102
|
+
result.paste(base, (0, 0), mask)
|
|
103
|
+
return result
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def centered_foreground_layer(image, canvas_size):
|
|
107
|
+
"""Build an Android adaptive icon foreground layer.
|
|
108
|
+
|
|
109
|
+
The layer canvas is the full 108dp square. Content should be sized so its
|
|
110
|
+
important detail sits inside the 66dp "safe zone" (guaranteed visible
|
|
111
|
+
under every mask shape), while the artwork itself typically fills closer
|
|
112
|
+
to the 72dp legacy-icon area so it doesn't look tiny once masked. We size
|
|
113
|
+
to 72/108 here to match what tools like Android Studio's Image Asset
|
|
114
|
+
Studio use as a default, rather than shrinking everything down to the
|
|
115
|
+
66dp safe-zone diameter (which under-fills the icon and looks padded).
|
|
116
|
+
"""
|
|
117
|
+
content_size = round(canvas_size * (72 / 108))
|
|
118
|
+
resized = image.resize((content_size, content_size), Image.LANCZOS)
|
|
119
|
+
canvas = Image.new("RGBA", (canvas_size, canvas_size), (0, 0, 0, 0))
|
|
120
|
+
offset = ((canvas_size - content_size) // 2, (canvas_size - content_size) // 2)
|
|
121
|
+
canvas.paste(resized, offset, resized)
|
|
122
|
+
return canvas
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def write_android_assets(source_image, foreground_image, output_root, background_color):
|
|
126
|
+
android_root = output_root / "android"
|
|
127
|
+
for density, px in ANDROID_DENSITIES.items():
|
|
128
|
+
mipmap_dir = android_root / f"mipmap-{density}"
|
|
129
|
+
mipmap_dir.mkdir(parents=True, exist_ok=True)
|
|
130
|
+
|
|
131
|
+
square_fit(source_image, px).save(mipmap_dir / "ic_launcher.png")
|
|
132
|
+
circular_icon(source_image, px).save(mipmap_dir / "ic_launcher_round.png")
|
|
133
|
+
|
|
134
|
+
adaptive_layer_size = round(px * (108 / 72))
|
|
135
|
+
Image.new("RGBA", (adaptive_layer_size, adaptive_layer_size), background_color).save(
|
|
136
|
+
mipmap_dir / "ic_launcher_background.png"
|
|
137
|
+
)
|
|
138
|
+
centered_foreground_layer(foreground_image, adaptive_layer_size).save(mipmap_dir / "ic_launcher_foreground.png")
|
|
139
|
+
|
|
140
|
+
anydpi = android_root / "mipmap-anydpi-v26"
|
|
141
|
+
anydpi.mkdir(parents=True, exist_ok=True)
|
|
142
|
+
xml = """<adaptive-icon xmlns:android=\"http://schemas.android.com/apk/res/android\">
|
|
143
|
+
<background android:drawable=\"@mipmap/ic_launcher_background\" />
|
|
144
|
+
<foreground android:drawable=\"@mipmap/ic_launcher_foreground\" />
|
|
145
|
+
</adaptive-icon>
|
|
146
|
+
"""
|
|
147
|
+
(anydpi / "ic_launcher.xml").write_text(xml, encoding="utf-8")
|
|
148
|
+
(anydpi / "ic_launcher_round.xml").write_text(xml, encoding="utf-8")
|
|
149
|
+
|
|
150
|
+
play_store_dir = android_root / "play-store"
|
|
151
|
+
play_store_dir.mkdir(parents=True, exist_ok=True)
|
|
152
|
+
flatten_to_white(square_fit(source_image, 512)).save(play_store_dir / "play_store_icon.png")
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def write_ios_assets(ios_image, output_root):
|
|
156
|
+
appiconset = output_root / "ios" / "AppIcon.appiconset"
|
|
157
|
+
appiconset.mkdir(parents=True, exist_ok=True)
|
|
158
|
+
|
|
159
|
+
images = []
|
|
160
|
+
for points, scale, idiom in IOS_ICONS:
|
|
161
|
+
size_px = int(round(points * scale))
|
|
162
|
+
points_label = f"{int(points)}" if float(points).is_integer() else f"{points}"
|
|
163
|
+
# Include idiom in the filename: the same (points, scale) pair can
|
|
164
|
+
# appear for both iphone and ipad (e.g. 20pt@2x), so the size alone
|
|
165
|
+
# isn't a unique filename and would silently overwrite the other.
|
|
166
|
+
filename = f"icon_{idiom}_{points_label}x{points_label}@{scale}x.png"
|
|
167
|
+
|
|
168
|
+
flatten_to_white(square_fit(ios_image, size_px)).save(appiconset / filename)
|
|
169
|
+
images.append(
|
|
170
|
+
{
|
|
171
|
+
"size": f"{points_label}x{points_label}",
|
|
172
|
+
"idiom": idiom,
|
|
173
|
+
"filename": filename,
|
|
174
|
+
"scale": f"{scale}x",
|
|
175
|
+
}
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
contents = {"images": images, "info": {"version": 1, "author": "xcode"}}
|
|
179
|
+
(appiconset / "Contents.json").write_text(json.dumps(contents, indent=2), encoding="utf-8")
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def warn_about_source(image, label):
|
|
183
|
+
width, height = image.size
|
|
184
|
+
if width != height:
|
|
185
|
+
print(f"Warning: {label} is not square ({width}x{height}). Output will be forced to square.", file=sys.stderr)
|
|
186
|
+
if width < 1024 or height < 1024:
|
|
187
|
+
print(f"Warning: {label} is smaller than 1024x1024. Upscaling will reduce quality.", file=sys.stderr)
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
def main():
|
|
191
|
+
args = parse_args()
|
|
192
|
+
ensure_repo_placeholder()
|
|
193
|
+
source_path = ensure_source_image(args.source)
|
|
194
|
+
if source_path is None:
|
|
195
|
+
print("Error: --source is required for icon generation.", file=sys.stderr)
|
|
196
|
+
return 1
|
|
197
|
+
|
|
198
|
+
output_root = Path(args.out).expanduser().resolve()
|
|
199
|
+
output_root.mkdir(parents=True, exist_ok=True)
|
|
200
|
+
|
|
201
|
+
source_image = open_image(source_path)
|
|
202
|
+
android_fg_image = open_image(Path(args.android_fg).expanduser().resolve()) if args.android_fg else source_image
|
|
203
|
+
ios_source_image = open_image(Path(args.ios_source).expanduser().resolve()) if args.ios_source else source_image
|
|
204
|
+
|
|
205
|
+
warn_about_source(source_image, "source image")
|
|
206
|
+
if args.android_fg:
|
|
207
|
+
warn_about_source(android_fg_image, "android foreground image")
|
|
208
|
+
if args.ios_source:
|
|
209
|
+
warn_about_source(ios_source_image, "iOS source image")
|
|
210
|
+
|
|
211
|
+
write_android_assets(source_image, android_fg_image, output_root, args.android_bg)
|
|
212
|
+
write_ios_assets(ios_source_image, output_root)
|
|
213
|
+
|
|
214
|
+
print(f"Generated icon assets in {output_root}")
|
|
215
|
+
return 0
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
if __name__ == "__main__":
|
|
219
|
+
sys.exit(main())
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "iconpeek",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Live Expo app icon and splash preview with Android adaptive-icon mask checks - no native build required.",
|
|
5
|
+
"main": "server.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"iconpeek": "./server.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "node server.js",
|
|
11
|
+
"test": "node tests/smoke-test.js"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=14"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"server.js",
|
|
19
|
+
"generate_icons.py",
|
|
20
|
+
"README.md",
|
|
21
|
+
"LICENSE",
|
|
22
|
+
"assets/"
|
|
23
|
+
]
|
|
24
|
+
}
|