Files
cloud-code/claude-code-source/node_modules/.ignored/qrcode/lib/renderer/png.js
janlaywss 6187147b74 reconstruct and build @anthropic-ai/claude-code source from source map
- Extract 4756 source files from cli.js.map (57MB)
- Set up Bun build system with bun:bundle feature flag shim
- Configure 90+ compile-time feature flags matching production defaults
- Inject MACRO constants (VERSION, BUILD_TIME, etc.)
- Create stubs for private packages (color-diff-napi, modifiers-napi, etc.)
- Install all public dependencies via pnpm
- Patch commander v14 to allow multi-char short flags (-d2e)
- Build output: dist/cli.js (22MB), verified working
2026-03-31 19:19:50 +08: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)
}