MCPcopy Create free account
hub / github.com/violentmonkey/violentmonkey / createIcons

Function createIcons

gulpfile.js:60–102  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

58}
59
60async function createIcons() {
61 const ALPHA = 0.5;
62 const dist = `${DIST}/public/images`;
63 await fs.mkdir(dist, { recursive: true });
64 const icon = Sharp(`src/resources/icon${isBeta() ? '-beta' : ''}.png`);
65 const gray = icon.clone().grayscale();
66 const transparent = icon.clone().composite([{
67 input: Buffer.from([255, 255, 255, 256 * ALPHA]),
68 raw: { width: 1, height: 1, channels: 4 },
69 tile: true,
70 blend: 'dest-in',
71 }]);
72 const types = [
73 ['', icon],
74 ['b', gray],
75 ['w', transparent],
76 ];
77 const handle = (size, type = '', image = icon) => {
78 let res = image.clone().resize({ width: size });
79 if (size < 48) res = res.sharpen(size < 32 ? 0.5 : 0.25);
80 return res.toFile(`${dist}/icon${size}${type}.png`);
81 };
82 const darkenOuterEdge = async img => img.composite([{
83 input: await img.toBuffer(),
84 blend: 'over',
85 }]);
86 const handle16 = async ([type, image]) => {
87 const res = image.clone()
88 .resize({ width: 18 })
89 .sharpen(0.5, 0)
90 .extract({ left: 1, top: 2, width: 16, height: 16 });
91 return (type === 'w' ? res : await darkenOuterEdge(res))
92 .toFile(`${dist}/icon16${type}.png`);
93 };
94 return Promise.all([
95 handle(128),
96 ...types.map(handle16),
97 // 32px dashboard icon (recycled) + 2xDPI browser_action desktop
98 // 38px dashboard icon (normal) + 1.5xDPI browser_action Android
99 // 48px 2xDPI browser_action Android
100 ...[32, 38, 48, 64].flatMap(size => types.map(t => handle(size, ...t))),
101 ]);
102}
103
104/**
105 * Bump `beta` in `package.json` to release a new beta version.

Callers

nothing calls this directly

Calls 3

isBetaFunction · 0.85
mapMethod · 0.80
handleFunction · 0.70

Tested by

no test coverage detected