Skip to content

Commit 083ca4e

Browse files
committed
Make components more stylable, implement PPM filename checksum
1 parent 9fd46ad commit 083ca4e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+769
-260
lines changed

dist/cjs/KwzParser.cjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!!
2-
* flipnote.js v6.1.1
2+
* flipnote.js v6.2.0
33
* https://flipnote.js.org
44
* A JavaScript library for Flipnote Studio animation files
55
* 2018 - 2025 James Daniel
@@ -140,7 +140,7 @@ const hexFromBytes = (bytes, reverse = false) => {
140140
hex.push(bytes[i].toString(16).padStart(2, '0'));
141141
if (reverse)
142142
hex.reverse();
143-
return hex.join('');
143+
return hex.join('').toUpperCase();
144144
};
145145

146146
/**
@@ -1084,7 +1084,7 @@ class KwzParser extends BaseParser {
10841084
// check the buffer's magic to identify which format it uses
10851085
const magicBytes = new Uint8Array(buffer.slice(0, 4));
10861086
const magic = (magicBytes[0] << 24) | (magicBytes[1] << 16) | (magicBytes[2] << 8);
1087-
// check if magic is KFH (kwz magic) or KIC (fs3d folder icon)
1087+
// check if magic is KFH (kwz magic) or KIC (fs3d folder icon)
10881088
return magic === 0x4B464800 || magic === 0x4B494300;
10891089
}
10901090
/**

dist/cjs/Player.cjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!!
2-
* flipnote.js v6.1.1
2+
* flipnote.js v6.2.0
33
* https://flipnote.js.org
44
* A JavaScript library for Flipnote Studio animation files
55
* 2018 - 2025 James Daniel
@@ -140,7 +140,7 @@ const hexFromBytes = (bytes, reverse = false) => {
140140
hex.push(bytes[i].toString(16).padStart(2, '0'));
141141
if (reverse)
142142
hex.reverse();
143-
return hex.join('');
143+
return hex.join('').toUpperCase();
144144
};
145145

146146
/**
@@ -1984,7 +1984,7 @@ class KwzParser extends BaseParser {
19841984
// check the buffer's magic to identify which format it uses
19851985
const magicBytes = new Uint8Array(buffer.slice(0, 4));
19861986
const magic = (magicBytes[0] << 24) | (magicBytes[1] << 16) | (magicBytes[2] << 8);
1987-
// check if magic is KFH (kwz magic) or KIC (fs3d folder icon)
1987+
// check if magic is KFH (kwz magic) or KIC (fs3d folder icon)
19881988
return magic === 0x4B464800 || magic === 0x4B494300;
19891989
}
19901990
/**

dist/cjs/PpmParser.cjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!!
2-
* flipnote.js v6.1.1
2+
* flipnote.js v6.2.0
33
* https://flipnote.js.org
44
* A JavaScript library for Flipnote Studio animation files
55
* 2018 - 2025 James Daniel
@@ -140,7 +140,7 @@ const hexFromBytes = (bytes, reverse = false) => {
140140
hex.push(bytes[i].toString(16).padStart(2, '0'));
141141
if (reverse)
142142
hex.reverse();
143-
return hex.join('');
143+
return hex.join('').toUpperCase();
144144
};
145145

146146
/**

dist/cjs/filename.cjs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!!
2-
* flipnote.js v6.1.1
2+
* flipnote.js v6.2.0
33
* https://flipnote.js.org
44
* A JavaScript library for Flipnote Studio animation files
55
* 2018 - 2025 James Daniel
@@ -9,6 +9,7 @@
99

1010
const REGEX_PPM_LOCAL_FILENAME = /^[0-9A-Z]{1}[0-9A-F]{5}_[0-9A-F]{13}_[0-9]{3}$/;
1111
const REGEX_PPM_FILENAME = /^[0-9A-F]{6}_[0-9A-F]{13}_[0-9]{3}$/;
12+
const CHECKSUM_ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
1213
/**
1314
* Determines if a string matches the PPM filename format.
1415
*/
@@ -17,7 +18,34 @@ const isPpmFilename = (filename) => REGEX_PPM_LOCAL_FILENAME.test(filename);
1718
* Does the same thing as {@link isPpmFilename}, expect it only matches "basic" filenames, without the checksum character that is added when saving a Flipnote to the filesystem.
1819
*/
1920
const isPpmBasicFilename = (filename) => REGEX_PPM_FILENAME.test(filename);
20-
// TODO: checksum reverse-engineering and implementation
21+
/**
22+
*
23+
*/
24+
const ppmFilenameCalculateCheckDigit = (filename) => {
25+
let sum = parseInt(filename.slice(0, 2), 16);
26+
for (let i = 1; i < 16; i++) {
27+
const char = filename.charCodeAt(i);
28+
sum = (sum + char) & 0xff;
29+
}
30+
return CHECKSUM_ALPHABET[sum % 36];
31+
};
32+
/**
33+
*
34+
*/
35+
const ppmFilenameDecode = (filename) => {
36+
const macSuffix = filename.slice(0, 6);
37+
const random1 = filename.slice(7, 12);
38+
const random2 = filename.slice(12, 19);
39+
const edits = parseInt(filename.slice(-3));
40+
return { macSuffix, random1, random2, edits };
41+
};
42+
/**
43+
*
44+
*/
45+
const ppmFilenameEncode = (filename) => {
46+
const edits = filename.edits.toString().padEnd(3, '0');
47+
return `${filename.macSuffix}_${filename.random1}_${filename.random2}_${edits}`;
48+
};
2149

2250
/**
2351
* @internal
@@ -28,7 +56,7 @@ const hexFromBytes = (bytes, reverse = false) => {
2856
hex.push(bytes[i].toString(16).padStart(2, '0'));
2957
if (reverse)
3058
hex.reverse();
31-
return hex.join('');
59+
return hex.join('').toUpperCase();
3260
};
3361
/**
3462
* @internal
@@ -313,3 +341,6 @@ exports.isPpmBasicFilename = isPpmBasicFilename;
313341
exports.isPpmFilename = isPpmFilename;
314342
exports.kwzFilenameDecode = kwzFilenameDecode;
315343
exports.kwzFilenameEncode = kwzFilenameEncode;
344+
exports.ppmFilenameCalculateCheckDigit = ppmFilenameCalculateCheckDigit;
345+
exports.ppmFilenameDecode = ppmFilenameDecode;
346+
exports.ppmFilenameEncode = ppmFilenameEncode;

dist/cjs/flipnote.cjs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!!
2-
* flipnote.js v6.1.1
2+
* flipnote.js v6.2.0
33
* https://flipnote.js.org
44
* A JavaScript library for Flipnote Studio animation files
55
* 2018 - 2025 James Daniel
@@ -282,7 +282,7 @@ const hexFromBytes = (bytes, reverse = false) => {
282282
hex.push(bytes[i].toString(16).padStart(2, '0'));
283283
if (reverse)
284284
hex.reverse();
285-
return hex.join('');
285+
return hex.join('').toUpperCase();
286286
};
287287
/**
288288
* @internal
@@ -2188,7 +2188,7 @@ class KwzParser extends BaseParser {
21882188
// check the buffer's magic to identify which format it uses
21892189
const magicBytes = new Uint8Array(buffer.slice(0, 4));
21902190
const magic = (magicBytes[0] << 24) | (magicBytes[1] << 16) | (magicBytes[2] << 8);
2191-
// check if magic is KFH (kwz magic) or KIC (fs3d folder icon)
2191+
// check if magic is KFH (kwz magic) or KIC (fs3d folder icon)
21922192
return magic === 0x4B464800 || magic === 0x4B494300;
21932193
}
21942194
/**
@@ -3312,6 +3312,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
33123312

33133313
const REGEX_PPM_LOCAL_FILENAME = /^[0-9A-Z]{1}[0-9A-F]{5}_[0-9A-F]{13}_[0-9]{3}$/;
33143314
const REGEX_PPM_FILENAME = /^[0-9A-F]{6}_[0-9A-F]{13}_[0-9]{3}$/;
3315+
const CHECKSUM_ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
33153316
/**
33163317
* Determines if a string matches the PPM filename format.
33173318
*/
@@ -3320,7 +3321,34 @@ const isPpmFilename = (filename) => REGEX_PPM_LOCAL_FILENAME.test(filename);
33203321
* Does the same thing as {@link isPpmFilename}, expect it only matches "basic" filenames, without the checksum character that is added when saving a Flipnote to the filesystem.
33213322
*/
33223323
const isPpmBasicFilename = (filename) => REGEX_PPM_FILENAME.test(filename);
3323-
// TODO: checksum reverse-engineering and implementation
3324+
/**
3325+
*
3326+
*/
3327+
const ppmFilenameCalculateCheckDigit = (filename) => {
3328+
let sum = parseInt(filename.slice(0, 2), 16);
3329+
for (let i = 1; i < 16; i++) {
3330+
const char = filename.charCodeAt(i);
3331+
sum = (sum + char) & 0xff;
3332+
}
3333+
return CHECKSUM_ALPHABET[sum % 36];
3334+
};
3335+
/**
3336+
*
3337+
*/
3338+
const ppmFilenameDecode = (filename) => {
3339+
const macSuffix = filename.slice(0, 6);
3340+
const random1 = filename.slice(7, 12);
3341+
const random2 = filename.slice(12, 19);
3342+
const edits = parseInt(filename.slice(-3));
3343+
return { macSuffix, random1, random2, edits };
3344+
};
3345+
/**
3346+
*
3347+
*/
3348+
const ppmFilenameEncode = (filename) => {
3349+
const edits = filename.edits.toString().padEnd(3, '0');
3350+
return `${filename.macSuffix}_${filename.random1}_${filename.random2}_${edits}`;
3351+
};
33243352

33253353
const REGEX_KWZ_FILENAME = /^[0-5a-z]{28}$/;
33263354
const BASE32_ALPHABET = 'cwmfjordvegbalksnthpyxquiz012345';
@@ -3398,7 +3426,10 @@ var index$2 = /*#__PURE__*/Object.freeze({
33983426
isPpmBasicFilename: isPpmBasicFilename,
33993427
isPpmFilename: isPpmFilename,
34003428
kwzFilenameDecode: kwzFilenameDecode,
3401-
kwzFilenameEncode: kwzFilenameEncode
3429+
kwzFilenameEncode: kwzFilenameEncode,
3430+
ppmFilenameCalculateCheckDigit: ppmFilenameCalculateCheckDigit,
3431+
ppmFilenameDecode: ppmFilenameDecode,
3432+
ppmFilenameEncode: ppmFilenameEncode
34023433
});
34033434

34043435
const XOR_KEY = [
@@ -8136,7 +8167,7 @@ _WavAudio_header = new WeakMap(), _WavAudio_pcmData = new WeakMap();
81368167
* flipnote.js library version (exported as `flipnote.version`).
81378168
* You can find the latest version on the project's [NPM](https://www.npmjs.com/package/flipnote.js) page.
81388169
*/
8139-
const version = "6.1.1"; // replaced by @rollup/plugin-replace;
8170+
const version = "6.2.0"; // replaced by @rollup/plugin-replace;
81408171

81418172
exports.CanvasInterface = CanvasInterface;
81428173
exports.GifImage = GifImage;

0 commit comments

Comments
 (0)