// LGPL-3.0-or-later; Tomar modifications 11 October 2026. // Deterministic, offline vendoring. Input is the SHA-512-verified heic-to 1.6.6 // npm package; no install script, CDN, compiler or source photo leaves the device. import fs from 'node:fs'; import path from 'node:path'; import crypto from 'node:crypto'; const input = process.argv[2]; if (!input) throw new Error('Pass the extracted heic-to 1.6.6 package directory.'); const original = fs.readFileSync(path.join(input, 'src/lib/libheif-without-unsafe-eval.js'), 'utf8'); const sha = bytes => crypto.createHash('sha256').update(bytes).digest('hex'); if (sha(original) !== 'd6ad000a632567ef3b8ff13063fdaa0d6b9fa3a51f49f2e91aa15c994965ade8') throw new Error('Unexpected upstream decoder. Review a new version before vendoring.'); let source = original; for (const [before, after] of [ ['var getHeapMax=()=>2147483648;', 'var getHeapMax=()=>201326592;'], ['if(WaHEAPU8;'], ]) { if (source.split(before).length !== 2) throw new Error('Decoder patch no longer has exactly one target.'); source = source.replace(before, after); } source = '// Tomar modification, 11 October 2026: 192 MiB heap ceiling and a current heap view for bounded C API calls.\n' + source; const target = path.resolve(import.meta.dirname, '../../apps/staff-mobile/public/photo-decoder/libheif-1.23.6'); fs.mkdirSync(target, { recursive: true }); fs.writeFileSync(path.join(target, 'decoder.js'), source); console.log(JSON.stringify({ source_sha256: sha(original), decoder_sha256: sha(source), bytes: Buffer.byteLength(source), heap_ceiling: 201326592 }));