Files
securebit-chat/node_modules/qrcode/lib/renderer/utf8.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

72 lines
1.5 KiB
JavaScript

const Utils = require('./utils')
const BLOCK_CHAR = {
WW: ' ',
WB: '▄',
BB: '█',
BW: '▀'
}
const INVERTED_BLOCK_CHAR = {
BB: ' ',
BW: '▄',
WW: '█',
WB: '▀'
}
function getBlockChar (top, bottom, blocks) {
if (top && bottom) return blocks.BB
if (top && !bottom) return blocks.BW
if (!top && bottom) return blocks.WB
return blocks.WW
}
exports.render = function (qrData, options, cb) {
const opts = Utils.getOptions(options)
let blocks = BLOCK_CHAR
if (opts.color.dark.hex === '#ffffff' || opts.color.light.hex === '#000000') {
blocks = INVERTED_BLOCK_CHAR
}
const size = qrData.modules.size
const data = qrData.modules.data
let output = ''
let hMargin = Array(size + (opts.margin * 2) + 1).join(blocks.WW)
hMargin = Array((opts.margin / 2) + 1).join(hMargin + '\n')
const vMargin = Array(opts.margin + 1).join(blocks.WW)
output += hMargin
for (let i = 0; i < size; i += 2) {
output += vMargin
for (let j = 0; j < size; j++) {
const topModule = data[i * size + j]
const bottomModule = data[(i + 1) * size + j]
output += getBlockChar(topModule, bottomModule, blocks)
}
output += vMargin + '\n'
}
output += hMargin.slice(0, -1)
if (typeof cb === 'function') {
cb(null, output)
}
return output
}
exports.renderToFile = function renderToFile (path, qrData, options, cb) {
if (typeof cb === 'undefined') {
cb = options
options = undefined
}
const fs = require('fs')
const utf8 = exports.render(qrData, options)
fs.writeFile(path, utf8, cb)
}