@mrdemonwolf/iconwolf 0.1.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/dist/generator.d.ts +3 -0
- package/dist/generator.d.ts.map +1 -0
- package/dist/generator.js +122 -0
- package/dist/generator.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/lib.d.ts +10 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js +9 -0
- package/dist/lib.js.map +1 -0
- package/dist/types.d.ts +21 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/icon-composer.d.ts +14 -0
- package/dist/utils/icon-composer.d.ts.map +1 -0
- package/dist/utils/icon-composer.js +200 -0
- package/dist/utils/icon-composer.js.map +1 -0
- package/dist/utils/image.d.ts +22 -0
- package/dist/utils/image.d.ts.map +1 -0
- package/dist/utils/image.js +145 -0
- package/dist/utils/image.js.map +1 -0
- package/dist/utils/logger.d.ts +10 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +38 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/paths.d.ts +17 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +27 -0
- package/dist/utils/paths.js.map +1 -0
- package/dist/utils/update-notifier.d.ts +9 -0
- package/dist/utils/update-notifier.d.ts.map +1 -0
- package/dist/utils/update-notifier.js +80 -0
- package/dist/utils/update-notifier.js.map +1 -0
- package/dist/variants/android.d.ts +5 -0
- package/dist/variants/android.d.ts.map +1 -0
- package/dist/variants/android.js +18 -0
- package/dist/variants/android.js.map +1 -0
- package/dist/variants/favicon.d.ts +3 -0
- package/dist/variants/favicon.d.ts.map +1 -0
- package/dist/variants/favicon.js +23 -0
- package/dist/variants/favicon.js.map +1 -0
- package/dist/variants/splash.d.ts +3 -0
- package/dist/variants/splash.d.ts.map +1 -0
- package/dist/variants/splash.js +7 -0
- package/dist/variants/splash.js.map +1 -0
- package/dist/variants/standard.d.ts +3 -0
- package/dist/variants/standard.d.ts.map +1 -0
- package/dist/variants/standard.js +7 -0
- package/dist/variants/standard.js.map +1 -0
- package/eslint.config.js +10 -0
- package/package.json +57 -0
- package/scripts/build-release.sh +63 -0
- package/src/generator.ts +163 -0
- package/src/index.ts +73 -0
- package/src/lib.ts +16 -0
- package/src/types.ts +22 -0
- package/src/utils/icon-composer.ts +283 -0
- package/src/utils/image.ts +207 -0
- package/src/utils/logger.ts +61 -0
- package/src/utils/paths.ts +30 -0
- package/src/utils/update-notifier.ts +99 -0
- package/src/variants/android.ts +45 -0
- package/src/variants/favicon.ts +32 -0
- package/src/variants/splash.ts +11 -0
- package/src/variants/standard.ts +11 -0
- package/tests/cli.test.ts +84 -0
- package/tests/generator.test.ts +368 -0
- package/tests/helpers.ts +36 -0
- package/tests/utils/icon-composer.test.ts +208 -0
- package/tests/utils/image.test.ts +207 -0
- package/tests/utils/logger.test.ts +128 -0
- package/tests/utils/paths.test.ts +51 -0
- package/tests/utils/update-notifier.test.ts +184 -0
- package/tests/variants/android.test.ts +77 -0
- package/tests/variants/favicon.test.ts +36 -0
- package/tests/variants/splash.test.ts +35 -0
- package/tests/variants/standard.test.ts +35 -0
- package/tsconfig.json +19 -0
- package/vitest.config.ts +8 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 MrDemonWolf
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA8BrE,wBAAsB,QAAQ,CAC5B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAqH7B"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isIconComposerFolder, renderIconComposerFolder, } from './utils/icon-composer.js';
|
|
4
|
+
import { validateSourceImage } from './utils/image.js';
|
|
5
|
+
import * as logger from './utils/logger.js';
|
|
6
|
+
import { DEFAULT_OUTPUT_DIR } from './utils/paths.js';
|
|
7
|
+
import { generateStandardIcon } from './variants/standard.js';
|
|
8
|
+
import { generateFavicon } from './variants/favicon.js';
|
|
9
|
+
import { generateSplashIcon } from './variants/splash.js';
|
|
10
|
+
import { generateAndroidIcons } from './variants/android.js';
|
|
11
|
+
async function resolveInput(resolvedPath, bgColor, silent) {
|
|
12
|
+
if (isIconComposerFolder(resolvedPath)) {
|
|
13
|
+
if (!silent)
|
|
14
|
+
logger.info(`Apple Icon Composer file: ${resolvedPath}`);
|
|
15
|
+
const result = await renderIconComposerFolder(resolvedPath);
|
|
16
|
+
const inputPath = result.composedImagePath;
|
|
17
|
+
const cleanupPath = path.dirname(result.composedImagePath);
|
|
18
|
+
if (bgColor === '#FFFFFF') {
|
|
19
|
+
bgColor = result.extractedBgColor;
|
|
20
|
+
if (!silent)
|
|
21
|
+
logger.info(`Extracted background color: ${bgColor}`);
|
|
22
|
+
}
|
|
23
|
+
return { inputPath, cleanupPath, bgColor };
|
|
24
|
+
}
|
|
25
|
+
return { inputPath: resolvedPath, bgColor };
|
|
26
|
+
}
|
|
27
|
+
export async function generate(options) {
|
|
28
|
+
const resolvedInput = path.resolve(options.inputPath);
|
|
29
|
+
const outputDir = path.resolve(options.outputDir || DEFAULT_OUTPUT_DIR);
|
|
30
|
+
let { bgColor } = options;
|
|
31
|
+
const { variants } = options;
|
|
32
|
+
const silent = options.silent ?? false;
|
|
33
|
+
if (!silent)
|
|
34
|
+
logger.banner();
|
|
35
|
+
// Check source exists
|
|
36
|
+
if (!fs.existsSync(resolvedInput)) {
|
|
37
|
+
throw new Error(`Source not found: ${resolvedInput}`);
|
|
38
|
+
}
|
|
39
|
+
let inputPath;
|
|
40
|
+
let cleanupPath;
|
|
41
|
+
let splashPath;
|
|
42
|
+
let splashCleanupPath;
|
|
43
|
+
try {
|
|
44
|
+
// Resolve main input (Apple Icon Composer .icon folder or PNG)
|
|
45
|
+
const mainInput = await resolveInput(resolvedInput, bgColor, silent);
|
|
46
|
+
inputPath = mainInput.inputPath;
|
|
47
|
+
cleanupPath = mainInput.cleanupPath;
|
|
48
|
+
bgColor = mainInput.bgColor;
|
|
49
|
+
// Resolve splash input if provided
|
|
50
|
+
if (options.splashInputPath) {
|
|
51
|
+
const resolvedSplashInput = path.resolve(options.splashInputPath);
|
|
52
|
+
if (!fs.existsSync(resolvedSplashInput)) {
|
|
53
|
+
throw new Error(`Splash source not found: ${resolvedSplashInput}`);
|
|
54
|
+
}
|
|
55
|
+
const splashInput = await resolveInput(resolvedSplashInput, bgColor, silent);
|
|
56
|
+
splashPath = splashInput.inputPath;
|
|
57
|
+
splashCleanupPath = splashInput.cleanupPath;
|
|
58
|
+
}
|
|
59
|
+
// Validate source image
|
|
60
|
+
if (!silent)
|
|
61
|
+
logger.info(`Validating source image: ${inputPath}`);
|
|
62
|
+
const meta = await validateSourceImage(inputPath);
|
|
63
|
+
if (!silent)
|
|
64
|
+
logger.info(`Source: ${meta.width}x${meta.height} ${meta.format.toUpperCase()}`);
|
|
65
|
+
// Validate splash source image if separate
|
|
66
|
+
if (splashPath) {
|
|
67
|
+
if (!silent)
|
|
68
|
+
logger.info(`Validating splash source image: ${splashPath}`);
|
|
69
|
+
const splashMeta = await validateSourceImage(splashPath);
|
|
70
|
+
if (!silent)
|
|
71
|
+
logger.info(`Splash source: ${splashMeta.width}x${splashMeta.height} ${splashMeta.format.toUpperCase()}`);
|
|
72
|
+
}
|
|
73
|
+
// Create output directory
|
|
74
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
75
|
+
if (!silent)
|
|
76
|
+
logger.info(`Output directory: ${outputDir}`);
|
|
77
|
+
// Determine which variants to generate
|
|
78
|
+
const anyFlagSet = variants.android || variants.favicon || variants.splash || variants.icon;
|
|
79
|
+
const generateAll = !anyFlagSet;
|
|
80
|
+
const results = [];
|
|
81
|
+
// Generate selected variants
|
|
82
|
+
if (generateAll || variants.icon) {
|
|
83
|
+
const result = await generateStandardIcon(inputPath, outputDir);
|
|
84
|
+
results.push(result);
|
|
85
|
+
if (!silent)
|
|
86
|
+
logger.generated(result);
|
|
87
|
+
}
|
|
88
|
+
if (generateAll || variants.android) {
|
|
89
|
+
const androidResults = await generateAndroidIcons(inputPath, outputDir, bgColor, { includeBackground: variants.android });
|
|
90
|
+
for (const result of androidResults) {
|
|
91
|
+
results.push(result);
|
|
92
|
+
if (!silent)
|
|
93
|
+
logger.generated(result);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (generateAll || variants.favicon) {
|
|
97
|
+
const result = await generateFavicon(inputPath, outputDir);
|
|
98
|
+
results.push(result);
|
|
99
|
+
if (!silent)
|
|
100
|
+
logger.generated(result);
|
|
101
|
+
}
|
|
102
|
+
if (generateAll || variants.splash) {
|
|
103
|
+
const result = await generateSplashIcon(splashPath || inputPath, outputDir);
|
|
104
|
+
results.push(result);
|
|
105
|
+
if (!silent)
|
|
106
|
+
logger.generated(result);
|
|
107
|
+
}
|
|
108
|
+
if (!silent)
|
|
109
|
+
logger.summary(results);
|
|
110
|
+
return results;
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
// Clean up temp composed images
|
|
114
|
+
if (cleanupPath) {
|
|
115
|
+
fs.rmSync(cleanupPath, { recursive: true, force: true });
|
|
116
|
+
}
|
|
117
|
+
if (splashCleanupPath) {
|
|
118
|
+
fs.rmSync(splashCleanupPath, { recursive: true, force: true });
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,eAAe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B,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { generate } from './generator.js';
|
|
4
|
+
import * as logger from './utils/logger.js';
|
|
5
|
+
import { resolveDefaultOutputDir } from './utils/paths.js';
|
|
6
|
+
import { readCachedUpdateInfo, refreshCacheInBackground, } from './utils/update-notifier.js';
|
|
7
|
+
const VERSION = '0.1.0';
|
|
8
|
+
const program = new Command();
|
|
9
|
+
program
|
|
10
|
+
.name('iconwolf')
|
|
11
|
+
.description('Generate all necessary icon variants for cross-platform Expo/React Native projects from a single source icon.')
|
|
12
|
+
.version(VERSION)
|
|
13
|
+
.argument('<input>', 'Path to an Apple Icon Composer .icon folder or a source PNG')
|
|
14
|
+
.option('-o, --output <dir>', 'Output directory', resolveDefaultOutputDir())
|
|
15
|
+
.option('--android', 'Generate Android adaptive icon variants only')
|
|
16
|
+
.option('--favicon', 'Generate web favicon only')
|
|
17
|
+
.option('--splash', 'Generate splash screen icon only')
|
|
18
|
+
.option('--icon', 'Generate standard icon.png only')
|
|
19
|
+
.option('--splash-input <path>', 'Use a separate image for the splash screen icon')
|
|
20
|
+
.option('--bg-color <hex>', 'Background color for Android adaptive icon', '#FFFFFF')
|
|
21
|
+
.action(async (input, opts) => {
|
|
22
|
+
const updateInfo = readCachedUpdateInfo(VERSION);
|
|
23
|
+
refreshCacheInBackground().catch(() => { });
|
|
24
|
+
const options = {
|
|
25
|
+
inputPath: input,
|
|
26
|
+
outputDir: opts.output,
|
|
27
|
+
variants: {
|
|
28
|
+
android: opts.android ?? false,
|
|
29
|
+
favicon: opts.favicon ?? false,
|
|
30
|
+
splash: opts.splash ?? false,
|
|
31
|
+
icon: opts.icon ?? false,
|
|
32
|
+
},
|
|
33
|
+
bgColor: opts.bgColor,
|
|
34
|
+
splashInputPath: opts.splashInput,
|
|
35
|
+
};
|
|
36
|
+
try {
|
|
37
|
+
await generate(options);
|
|
38
|
+
if (updateInfo?.updateAvailable) {
|
|
39
|
+
logger.updateNotice(updateInfo.currentVersion, updateInfo.latestVersion);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (err) {
|
|
43
|
+
logger.error(err instanceof Error ? err.message : String(err));
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
program.parse();
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,4BAA4B,CAAC;AAGpC,MAAM,OAAO,GAAG,OAAO,CAAC;AAExB,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B,OAAO;KACJ,IAAI,CAAC,UAAU,CAAC;KAChB,WAAW,CACV,+GAA+G,CAChH;KACA,OAAO,CAAC,OAAO,CAAC;KAChB,QAAQ,CACP,SAAS,EACT,6DAA6D,CAC9D;KACA,MAAM,CAAC,oBAAoB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,CAAC;KAC3E,MAAM,CAAC,WAAW,EAAE,8CAA8C,CAAC;KACnE,MAAM,CAAC,WAAW,EAAE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AAC,CAAC,CAAC;AAEL,OAAO,CAAC,KAAK,EAAE,CAAC"}
|
package/dist/lib.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { generate } from './generator.js';
|
|
2
|
+
export { generateStandardIcon } from './variants/standard.js';
|
|
3
|
+
export { generateFavicon } from './variants/favicon.js';
|
|
4
|
+
export { generateSplashIcon } from './variants/splash.js';
|
|
5
|
+
export { generateAndroidIcons } from './variants/android.js';
|
|
6
|
+
export { validateSourceImage } from './utils/image.js';
|
|
7
|
+
export { isIconComposerFolder, renderIconComposerFolder, } from './utils/icon-composer.js';
|
|
8
|
+
export { OUTPUT_FILES, resolveOutputPath } from './utils/paths.js';
|
|
9
|
+
export type { VariantFlags, GeneratorOptions, GenerationResult, } from './types.js';
|
|
10
|
+
//# sourceMappingURL=lib.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.d.ts","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACnE,YAAY,EACV,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,GACjB,MAAM,YAAY,CAAC"}
|
package/dist/lib.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { generate } from './generator.js';
|
|
2
|
+
export { generateStandardIcon } from './variants/standard.js';
|
|
3
|
+
export { generateFavicon } from './variants/favicon.js';
|
|
4
|
+
export { generateSplashIcon } from './variants/splash.js';
|
|
5
|
+
export { generateAndroidIcons } from './variants/android.js';
|
|
6
|
+
export { validateSourceImage } from './utils/image.js';
|
|
7
|
+
export { isIconComposerFolder, renderIconComposerFolder, } from './utils/icon-composer.js';
|
|
8
|
+
export { OUTPUT_FILES, resolveOutputPath } from './utils/paths.js';
|
|
9
|
+
//# sourceMappingURL=lib.js.map
|
package/dist/lib.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lib.js","sourceRoot":"","sources":["../src/lib.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EACL,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface VariantFlags {
|
|
2
|
+
android: boolean;
|
|
3
|
+
favicon: boolean;
|
|
4
|
+
splash: boolean;
|
|
5
|
+
icon: boolean;
|
|
6
|
+
}
|
|
7
|
+
export interface GeneratorOptions {
|
|
8
|
+
inputPath: string;
|
|
9
|
+
outputDir: string;
|
|
10
|
+
variants: VariantFlags;
|
|
11
|
+
bgColor: string;
|
|
12
|
+
splashInputPath?: string;
|
|
13
|
+
silent?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface GenerationResult {
|
|
16
|
+
filePath: string;
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
size: number;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface IconComposerResult {
|
|
2
|
+
composedImagePath: string;
|
|
3
|
+
extractedBgColor: string;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Check if a path is an Apple Icon Composer .icon folder.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isIconComposerFolder(inputPath: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Render an Apple Icon Composer .icon folder into a composed 1024x1024 PNG.
|
|
11
|
+
* Returns the path to the composed image and the extracted background color.
|
|
12
|
+
*/
|
|
13
|
+
export declare function renderIconComposerFolder(iconFolderPath: string): Promise<IconComposerResult>;
|
|
14
|
+
//# sourceMappingURL=icon-composer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon-composer.d.ts","sourceRoot":"","sources":["../../src/utils/icon-composer.ts"],"names":[],"mappings":"AAsCA,MAAM,WAAW,kBAAkB;IACjC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAS/D;AA6HD;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,kBAAkB,CAAC,CAgG7B"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import sharp from 'sharp';
|
|
5
|
+
const ICON_SIZE = 1024;
|
|
6
|
+
/**
|
|
7
|
+
* Check if a path is an Apple Icon Composer .icon folder.
|
|
8
|
+
*/
|
|
9
|
+
export function isIconComposerFolder(inputPath) {
|
|
10
|
+
if (!inputPath.endsWith('.icon'))
|
|
11
|
+
return false;
|
|
12
|
+
try {
|
|
13
|
+
const stat = fs.statSync(inputPath);
|
|
14
|
+
if (!stat.isDirectory())
|
|
15
|
+
return false;
|
|
16
|
+
return fs.existsSync(path.join(inputPath, 'icon.json'));
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Parse a color string from icon.json to sRGB values.
|
|
24
|
+
* Supports formats: "display-p3:R,G,B,A" and "srgb:R,G,B,A" (values 0-1).
|
|
25
|
+
*/
|
|
26
|
+
function parseIconColor(color) {
|
|
27
|
+
const match = color.match(/^[\w-]+:([\d.]+),([\d.]+),([\d.]+),([\d.]+)$/);
|
|
28
|
+
if (!match) {
|
|
29
|
+
throw new Error(`Unsupported color format: ${color}`);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
r: Math.round(parseFloat(match[1]) * 255),
|
|
33
|
+
g: Math.round(parseFloat(match[2]) * 255),
|
|
34
|
+
b: Math.round(parseFloat(match[3]) * 255),
|
|
35
|
+
a: parseFloat(match[4]),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Convert RGB values to hex string.
|
|
40
|
+
*/
|
|
41
|
+
function rgbToHex(r, g, b) {
|
|
42
|
+
return ('#' +
|
|
43
|
+
[r, g, b]
|
|
44
|
+
.map((c) => c.toString(16).padStart(2, '0'))
|
|
45
|
+
.join('')
|
|
46
|
+
.toUpperCase());
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Create an SVG string for a linear gradient background.
|
|
50
|
+
*/
|
|
51
|
+
function createGradientSvg(colors, orientation, size) {
|
|
52
|
+
const parsedColors = colors.map(parseIconColor);
|
|
53
|
+
const x1 = (orientation.start.x * 100).toFixed(1);
|
|
54
|
+
const y1 = (orientation.start.y * 100).toFixed(1);
|
|
55
|
+
const x2 = (orientation.stop.x * 100).toFixed(1);
|
|
56
|
+
const y2 = (orientation.stop.y * 100).toFixed(1);
|
|
57
|
+
const stops = parsedColors
|
|
58
|
+
.map((c, i) => {
|
|
59
|
+
const offset = parsedColors.length === 1 ? 0 : (i / (parsedColors.length - 1)) * 100;
|
|
60
|
+
return `<stop offset="${offset}%" stop-color="rgb(${c.r},${c.g},${c.b})" stop-opacity="${c.a}" />`;
|
|
61
|
+
})
|
|
62
|
+
.join('\n ');
|
|
63
|
+
return `<svg width="${size}" height="${size}" xmlns="http://www.w3.org/2000/svg">
|
|
64
|
+
<defs>
|
|
65
|
+
<linearGradient id="bg" x1="${x1}%" y1="${y1}%" x2="${x2}%" y2="${y2}%">
|
|
66
|
+
${stops}
|
|
67
|
+
</linearGradient>
|
|
68
|
+
</defs>
|
|
69
|
+
<rect width="${size}" height="${size}" fill="url(#bg)" />
|
|
70
|
+
</svg>`;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Create the background buffer from the icon.json fill definition.
|
|
74
|
+
*/
|
|
75
|
+
async function createBackground(fill) {
|
|
76
|
+
if (fill['linear-gradient'] && fill.orientation) {
|
|
77
|
+
const colors = fill['linear-gradient'];
|
|
78
|
+
const svg = createGradientSvg(colors, fill.orientation, ICON_SIZE);
|
|
79
|
+
const buffer = await sharp(Buffer.from(svg)).png().toBuffer();
|
|
80
|
+
const firstColor = parseIconColor(colors[0]);
|
|
81
|
+
return {
|
|
82
|
+
buffer,
|
|
83
|
+
bgColor: rgbToHex(firstColor.r, firstColor.g, firstColor.b),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
const solidColor = fill.solid ?? fill.color;
|
|
87
|
+
if (solidColor) {
|
|
88
|
+
const color = parseIconColor(solidColor);
|
|
89
|
+
const buffer = await sharp({
|
|
90
|
+
create: {
|
|
91
|
+
width: ICON_SIZE,
|
|
92
|
+
height: ICON_SIZE,
|
|
93
|
+
channels: 4,
|
|
94
|
+
background: {
|
|
95
|
+
r: color.r,
|
|
96
|
+
g: color.g,
|
|
97
|
+
b: color.b,
|
|
98
|
+
alpha: Math.round(color.a * 255),
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
})
|
|
102
|
+
.png()
|
|
103
|
+
.toBuffer();
|
|
104
|
+
return { buffer, bgColor: rgbToHex(color.r, color.g, color.b) };
|
|
105
|
+
}
|
|
106
|
+
// Fallback: white background
|
|
107
|
+
const buffer = await sharp({
|
|
108
|
+
create: {
|
|
109
|
+
width: ICON_SIZE,
|
|
110
|
+
height: ICON_SIZE,
|
|
111
|
+
channels: 4,
|
|
112
|
+
background: { r: 255, g: 255, b: 255, alpha: 255 },
|
|
113
|
+
},
|
|
114
|
+
})
|
|
115
|
+
.png()
|
|
116
|
+
.toBuffer();
|
|
117
|
+
return { buffer, bgColor: '#FFFFFF' };
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Render an Apple Icon Composer .icon folder into a composed 1024x1024 PNG.
|
|
121
|
+
* Returns the path to the composed image and the extracted background color.
|
|
122
|
+
*/
|
|
123
|
+
export async function renderIconComposerFolder(iconFolderPath) {
|
|
124
|
+
const manifestPath = path.join(iconFolderPath, 'icon.json');
|
|
125
|
+
const assetsPath = path.join(iconFolderPath, 'Assets');
|
|
126
|
+
if (!fs.existsSync(manifestPath)) {
|
|
127
|
+
throw new Error(`icon.json not found in ${iconFolderPath}`);
|
|
128
|
+
}
|
|
129
|
+
const manifestRaw = fs.readFileSync(manifestPath, 'utf-8');
|
|
130
|
+
const manifest = JSON.parse(manifestRaw);
|
|
131
|
+
// Create background
|
|
132
|
+
const { buffer: backgroundBuffer, bgColor: extractedBgColor } = await createBackground(manifest.fill);
|
|
133
|
+
// Build composite operations for each layer
|
|
134
|
+
const compositeOps = [];
|
|
135
|
+
for (const group of manifest.groups) {
|
|
136
|
+
for (const layer of group.layers) {
|
|
137
|
+
const imagePath = path.join(assetsPath, layer['image-name']);
|
|
138
|
+
if (!fs.existsSync(imagePath)) {
|
|
139
|
+
throw new Error(`Layer image not found: ${imagePath}`);
|
|
140
|
+
}
|
|
141
|
+
const meta = await sharp(imagePath).metadata();
|
|
142
|
+
if (!meta.width || !meta.height) {
|
|
143
|
+
throw new Error(`Cannot read dimensions of layer: ${layer['image-name']}`);
|
|
144
|
+
}
|
|
145
|
+
// Scale relative to original image size
|
|
146
|
+
const scaledWidth = Math.round(meta.width * layer.position.scale);
|
|
147
|
+
const scaledHeight = Math.round(meta.height * layer.position.scale);
|
|
148
|
+
// Center on canvas with translation offset (in points/pixels)
|
|
149
|
+
const tx = layer.position['translation-in-points'][0];
|
|
150
|
+
const ty = layer.position['translation-in-points'][1];
|
|
151
|
+
let left = Math.round((ICON_SIZE - scaledWidth) / 2 + tx);
|
|
152
|
+
let top = Math.round((ICON_SIZE - scaledHeight) / 2 + ty);
|
|
153
|
+
let layerBuffer = await sharp(imagePath)
|
|
154
|
+
.resize(scaledWidth, scaledHeight, {
|
|
155
|
+
fit: 'contain',
|
|
156
|
+
background: { r: 0, g: 0, b: 0, alpha: 0 },
|
|
157
|
+
})
|
|
158
|
+
.png()
|
|
159
|
+
.toBuffer();
|
|
160
|
+
// If the layer extends beyond the canvas, crop to visible region
|
|
161
|
+
if (left < 0 ||
|
|
162
|
+
top < 0 ||
|
|
163
|
+
left + scaledWidth > ICON_SIZE ||
|
|
164
|
+
top + scaledHeight > ICON_SIZE) {
|
|
165
|
+
const cropLeft = Math.max(0, -left);
|
|
166
|
+
const cropTop = Math.max(0, -top);
|
|
167
|
+
const cropRight = Math.min(scaledWidth, ICON_SIZE - left);
|
|
168
|
+
const cropBottom = Math.min(scaledHeight, ICON_SIZE - top);
|
|
169
|
+
const cropWidth = cropRight - cropLeft;
|
|
170
|
+
const cropHeight = cropBottom - cropTop;
|
|
171
|
+
if (cropWidth <= 0 || cropHeight <= 0)
|
|
172
|
+
continue;
|
|
173
|
+
layerBuffer = await sharp(layerBuffer)
|
|
174
|
+
.extract({
|
|
175
|
+
left: cropLeft,
|
|
176
|
+
top: cropTop,
|
|
177
|
+
width: cropWidth,
|
|
178
|
+
height: cropHeight,
|
|
179
|
+
})
|
|
180
|
+
.png()
|
|
181
|
+
.toBuffer();
|
|
182
|
+
left = Math.max(0, left);
|
|
183
|
+
top = Math.max(0, top);
|
|
184
|
+
}
|
|
185
|
+
compositeOps.push({ input: layerBuffer, left, top });
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
// Compose final image
|
|
189
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'iconwolf-compose-'));
|
|
190
|
+
const composedPath = path.join(tmpDir, 'composed-icon.png');
|
|
191
|
+
await sharp(backgroundBuffer)
|
|
192
|
+
.composite(compositeOps)
|
|
193
|
+
.png()
|
|
194
|
+
.toFile(composedPath);
|
|
195
|
+
return {
|
|
196
|
+
composedImagePath: composedPath,
|
|
197
|
+
extractedBgColor,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=icon-composer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon-composer.js","sourceRoot":"","sources":["../../src/utils/icon-composer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,SAAS,GAAG,IAAI,CAAC;AAsCvB;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAAiB;IACpD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IAC/C,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;QACpC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE;YAAE,OAAO,KAAK,CAAC;QACtC,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAC;IAC1D,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,KAAa;IAMnC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAC1E,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,6BAA6B,KAAK,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,OAAO;QACL,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC;QACz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,OAAO;QACL,iBAAiB,EAAE,YAAY;QAC/B,gBAAgB;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { GenerationResult } from '../types.js';
|
|
2
|
+
export interface SourceImageMeta {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
format: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function validateSourceImage(inputPath: string): Promise<SourceImageMeta>;
|
|
8
|
+
export declare function resizeImage(inputPath: string, width: number, height: number, outputPath: string): Promise<GenerationResult>;
|
|
9
|
+
export declare function createAdaptiveForeground(inputPath: string, targetSize: number, outputPath: string): Promise<GenerationResult>;
|
|
10
|
+
export declare function createSolidBackground(hexColor: string, size: number, outputPath: string): Promise<GenerationResult>;
|
|
11
|
+
export declare function createMonochromeIcon(inputPath: string, targetSize: number, outputPath: string): Promise<GenerationResult>;
|
|
12
|
+
/**
|
|
13
|
+
* Apply rounded corners to an image using an SVG mask.
|
|
14
|
+
* Uses Apple's icon corner radius ratio (~22.37%).
|
|
15
|
+
*/
|
|
16
|
+
export declare function applyRoundedCorners(inputBuffer: Buffer, size: number): Promise<Buffer>;
|
|
17
|
+
export declare function parseHexColor(hex: string): {
|
|
18
|
+
r: number;
|
|
19
|
+
g: number;
|
|
20
|
+
b: number;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/utils/image.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAMpD,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,eAAe,CAAC,CAwB1B;AAED,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,gBAAgB,CAAC,CAe3B;AAED,wBAAsB,wBAAwB,CAC5C,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,gBAAgB,CAAC,CA6B3B;AAED,wBAAsB,qBAAqB,CACzC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,gBAAgB,CAAC,CAoB3B;AAED,wBAAsB,oBAAoB,CACxC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,gBAAgB,CAAC,CA8B3B;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,CAAC,CAWjB;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG;IAC1C,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAsBA"}
|