Files
cloud-code/claude-code-source/node_modules/.ignored/qrcode/lib/renderer/canvas.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

64 lines
1.5 KiB
JavaScript

const Utils = require('./utils')
function clearCanvas (ctx, canvas, size) {
ctx.clearRect(0, 0, canvas.width, canvas.height)
if (!canvas.style) canvas.style = {}
canvas.height = size
canvas.width = size
canvas.style.height = size + 'px'
canvas.style.width = size + 'px'
}
function getCanvasElement () {
try {
return document.createElement('canvas')
} catch (e) {
throw new Error('You need to specify a canvas element')
}
}
exports.render = function render (qrData, canvas, options) {
let opts = options
let canvasEl = canvas
if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
opts = canvas
canvas = undefined
}
if (!canvas) {
canvasEl = getCanvasElement()
}
opts = Utils.getOptions(opts)
const size = Utils.getImageWidth(qrData.modules.size, opts)
const ctx = canvasEl.getContext('2d')
const image = ctx.createImageData(size, size)
Utils.qrToImageData(image.data, qrData, opts)
clearCanvas(ctx, canvasEl, size)
ctx.putImageData(image, 0, 0)
return canvasEl
}
exports.renderToDataURL = function renderToDataURL (qrData, canvas, options) {
let opts = options
if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
opts = canvas
canvas = undefined
}
if (!opts) opts = {}
const canvasEl = exports.render(qrData, canvas, opts)
const type = opts.type || 'image/png'
const rendererOpts = opts.rendererOpts || {}
return canvasEl.toDataURL(type, rendererOpts.quality)
}