
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
cdgraphics
Advanced tools
A fast, flexible CD+Graphics (CD+G) renderer.
npm i cdgraphics
new CDGraphics(buffer: ArrayBuffer)
Instantiates a new renderer with the given CD+G file data. The data must be an ArrayBuffer, which can be had via the Response of a fetch().
import CDGraphics from 'cdgraphics'
let cdg
fetch(cdgFileUrl)
.then(response => response.arrayBuffer())
.then(buffer => {
cdg = new CDGraphics(buffer)
})
.render(time: number, options?: RenderOptions): Frame
Renders the frame at the given time index.
time
: Number (in fractional seconds) of the frame to render. Should usually be the currentTime from an <audio>
element.options
: Object with one or more of the following:
forceKey
: Boolean forcing the background to be transparent, even if the CD+G title did not explicitly specify it. Defaults to false
.Returns an object with the following properties:
imageData
: ImageData object containing the rendered frame's pixel data.isChanged
: Boolean indicating whether the frame changed since the last render. Useful for skipping unnecessary re-paints to a canvas.backgroundRGBA
: Array containing the frame's background color in the form [r, g, b, a]
with alpha being 0
or 1
. The reported alpha includes the effect of the forceKey option, if enabled.contentBounds
: Array containing the coordinates of a bounding box that fits the frame's non-transparent pixels in the form [x1, y1, x2, y2]
. Typically only useful when the forceKey option is enabled.The following excerpt demonstrates an audio-synced render loop that draws to a canvas. See the demo code for a more complete example.
const audio = document.getElementById('audio')
const canvas = document.getElementById('canvas')
const ctx = canvas.getContext('2d')
let frameId
const doRender = time => {
const frame = cdg.render(time)
if (!frame.isChanged) return
createImageBitmap(frame.imageData)
.then(bitmap => {
ctx.clearRect(0, 0, canvas.clientWidth, canvas.clientHeight)
ctx.drawImage(bitmap, 0, 0, canvas.clientWidth, canvas.clientHeight)
})
}
// render loop
const pause = () => cancelAnimationFrame(frameId)
const play = () => {
frameId = requestAnimationFrame(play)
doRender(audio.currentTime)
}
// follow <audio> events
audio.addEventListener('play', play)
audio.addEventListener('pause', pause)
audio.addEventListener('ended', pause)
audio.addEventListener('seeked', () => doRender(audio.currentTime))
To run the demo and see how it all comes together:
public
foldersrc/demo.js
with those filenames$ npm i
$ npm run dev
v7.0.0 (2025-08-04)
Breaking changes:
load()
method has been removed in favor of simply passing your file's ArrayBuffer to the constructorImproved:
npm run dev
Fixed:
FAQs
A fast, flexible CD+Graphics (CD+G) renderer
The npm package cdgraphics receives a total of 119 weekly downloads. As such, cdgraphics popularity was classified as not popular.
We found that cdgraphics demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.