Skip to content

Commit

Permalink
breaking: updating to new canvas module, latest svg-render
Browse files Browse the repository at this point in the history
  • Loading branch information
catdad committed Apr 27, 2024
1 parent 4ffd2de commit 35233b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"dependencies": {
"@catdad/to-ico": "^1.0.0",
"@fiahfy/icns": "0.0.6",
"canvas": "^2.8.0",
"@napi-rs/canvas": "^0.1.52",
"cheerio": "^1.0.0-rc.10",
"getopts": "^2.2.5",
"svg-render": "^1.3.0"
"svg-render": "^2.0.0"
},
"engines": {
"node": ">=16.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/generator.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const renderSvg = require('svg-render');
const toIco = require('@catdad/to-ico');
const { Icns, IcnsImage } = require('@fiahfy/icns');
const { createCanvas, loadImage } = require('canvas');
const { createCanvas, loadImage } = require('@napi-rs/canvas');
const cheerio = require('cheerio');

const { toArray } = require('./helpers.js');
Expand Down
24 changes: 16 additions & 8 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ const layers = [svg, `<svg viewBox="0 0 500 500">
<ellipse cx="222.25" cy="412.5" rx="54.75" ry="39.5" style="fill:rgb(255,110,0);"/>
</svg>`];

const defaultHashes = {
'32x32.png': 'd0fa2f4c025c9d4f3a23a02b80d43ff4ac3c76086c7b637efd7496acaa678320',
'256x256.png': '475443b27966c9eaf9b277232ed39be5fb8991c51e715e555e9d3be958b20579',
// it's weird that these two are different?
'512x512.png': '16fed629eb1e857b90a1cda053d6e65bf3ccf43946cefe59e83df0d25350d56c',
'icon.svg': '8d374e1f9540eff522ca1d1ee408a906b923f8df2fb9051c9f321bb3936f2e48'
};

const layerHashes = {
'32x32.png': 'c450e4c48d310cac5e1432dc3d8855b9a08da0c1e456eeacdbe4b809c8eb5b27',
'256x256.png': '7413a0717534701a7518a4e35633cae0edb63002c31ef58f092c555f2fa4bdfb',
'32x32.png': '85162a43990dc8ad30762ac386a19e1d1b3d8e3e39a0547ef231699085f5964a',
'256x256.png': 'f99eb45439cb6881829597b570b3f966295ecf67f00c087f53e37304578c2edb',
// it's weird that these two are different?
'512x512.png': '926163d94eb5dd6309861db76e952d8562c83b815583440508f79b8213ed44b7',
'icon.svg': 'bba03b4311a86f6e6f6b7e8b37d444604bca27d95984bd56894ab98857a43cdf'
'512x512.png': 'f54887d57d0ebc9d7a2adbc9c277a8201a70351a628428baac32ca81dd24a899',
'icon.svg': '5c2f43c9a83d2f3b05bf51cf48cf4861d20f42d5175aaf4d67d31d9c58b17a37'
};

const hash = buffer => crypto.createHash('sha256').update(buffer).digest('hex');
Expand All @@ -33,7 +41,7 @@ const validators = {
'icon.ico': async (buffer) => {
expect(await type.fromBuffer(buffer)).to.deep.equal({ ext: 'ico', mime: 'image/x-icon' });
},
'32x32.png': async (buffer, filehash = '84983735a5aa163aed058191c920e4b87831227182a9d800b0d0796c54d9635d') => {
'32x32.png': async (buffer, filehash = defaultHashes['32x32.png']) => {
expect(await type.fromBuffer(buffer)).to.deep.equal({ ext: 'png', mime: 'image/png' });
const { width, height, depth, data } = png.read(buffer);

Expand All @@ -43,7 +51,7 @@ const validators = {

expect(hash(data), '32x32.png has different pixels').to.equal(filehash);
},
'256x256.png': async (buffer, filehash = '4db3b3bbfa792b966042487401d098e0ff6e477f32620020ff43c57e5ad1fa8b') => {
'256x256.png': async (buffer, filehash = defaultHashes['256x256.png']) => {
expect(await type.fromBuffer(buffer)).to.deep.equal({ ext: 'png', mime: 'image/png' });
const { width, height, depth, data } = png.read(buffer);

Expand All @@ -53,7 +61,7 @@ const validators = {

expect(hash(data), '256x256.png has different pixels').to.equal(filehash);
},
'512x512.png': async (buffer, filehash = '4314abee99d494ab7a6675107fb5005c7a17367c3800a9b980ce207b1334cb36') => {
'512x512.png': async (buffer, filehash = defaultHashes['512x512.png']) => {
expect(await type.fromBuffer(buffer)).to.deep.equal({ ext: 'png', mime: 'image/png' });
const { width, height, depth, data } = png.read(buffer);

Expand All @@ -63,7 +71,7 @@ const validators = {

expect(hash(data), '512x512.png has different pixels').to.equal(filehash);
},
'icon.svg': async (buffer, filehash) => {
'icon.svg': async (buffer, filehash = defaultHashes['icon.svg']) => {
// soo... because of layers, the svg won't be just a passthrough, but rather
// an svg that renders equivalently, so...
const size = 512;
Expand Down

0 comments on commit 35233b3

Please sign in to comment.