Files
securebit-chat/node_modules/qrcode/lib/renderer/png.js
lockbitchat 0f8399ec88 feat(security,ui): self-host React deps, Tailwind, fonts; strict CSP; local QR; better selection state
Replace CDN React/ReactDOM/Babel with local libs; remove Babel and inline scripts
Build Tailwind locally, add safelist; switch to assets/tailwind.css
Self-host Font Awesome and Inter (CSS + woff2); remove external font CDNs
Implement strict CSP (no unsafe-inline/eval; scripts/styles/fonts from self)
Extract inline handlers; move PWA scripts to external files
Add local QR code generation (qrcode lib) and remove api.qrserver.com
Improve SessionTypeSelector visual selection (highlighted background and ring)
Keep PWA working with service worker and offline assets
Refs: CSP hardening, offline-first, no external dependencies
2025-09-08 16:04:58 -04:00

79 lines
1.7 KiB
JavaScript

const fs = require('fs')
const PNG = require('pngjs').PNG
const Utils = require('./utils')
exports.render = function render (qrData, options) {
const opts = Utils.getOptions(options)
const pngOpts = opts.rendererOpts
const size = Utils.getImageWidth(qrData.modules.size, opts)
pngOpts.width = size
pngOpts.height = size
const pngImage = new PNG(pngOpts)
Utils.qrToImageData(pngImage.data, qrData, opts)
return pngImage
}
exports.renderToDataURL = function renderToDataURL (qrData, options, cb) {
if (typeof cb === 'undefined') {
cb = options
options = undefined
}
exports.renderToBuffer(qrData, options, function (err, output) {
if (err) cb(err)
let url = 'data:image/png;base64,'
url += output.toString('base64')
cb(null, url)
})
}
exports.renderToBuffer = function renderToBuffer (qrData, options, cb) {
if (typeof cb === 'undefined') {
cb = options
options = undefined
}
const png = exports.render(qrData, options)
const buffer = []
png.on('error', cb)
png.on('data', function (data) {
buffer.push(data)
})
png.on('end', function () {
cb(null, Buffer.concat(buffer))
})
png.pack()
}
exports.renderToFile = function renderToFile (path, qrData, options, cb) {
if (typeof cb === 'undefined') {
cb = options
options = undefined
}
let called = false
const done = (...args) => {
if (called) return
called = true
cb.apply(null, args)
}
const stream = fs.createWriteStream(path)
stream.on('error', done)
stream.on('close', done)
exports.renderToFileStream(stream, qrData, options)
}
exports.renderToFileStream = function renderToFileStream (stream, qrData, options) {
const png = exports.render(qrData, options)
png.pack().pipe(stream)
}