@tldraw/utils
Version:
tldraw infinite canvas SDK (private utilities).
8 lines (7 loc) • 1.47 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/lib/media/avif.ts"],
"sourcesContent": ["/**\n * Determines whether an ArrayBuffer contains an animated AVIF image.\n *\n * This function performs a simple check by examining the 4th byte of the buffer.\n * AVIF animation is indicated when the byte at index 3 equals 44.\n *\n * @param buffer - The ArrayBuffer containing the AVIF image data to analyze\n * @returns True if the buffer contains an animated AVIF, false otherwise\n *\n * @example\n * ```typescript\n * // Check if an AVIF file is animated\n * const response = await fetch('image.avif')\n * const buffer = await response.arrayBuffer()\n * const isAnimated = isAvifAnimated(buffer)\n * if (isAnimated) {\n * console.log('This AVIF contains animation!')\n * }\n * ```\n *\n * @example\n * ```typescript\n * // Use with file input\n * const fileInput = document.querySelector('input[type=\"file\"]')\n * fileInput.addEventListener('change', async (event) => {\n * const file = event.target.files[0]\n * const buffer = await file.arrayBuffer()\n * const hasAnimation = isAvifAnimated(buffer)\n * console.log(hasAnimation ? 'Animated AVIF' : 'Static AVIF')\n * })\n * ```\n *\n * @public\n */\nexport const isAvifAnimated = (buffer: ArrayBuffer) => {\n\tconst view = new Uint8Array(buffer)\n\treturn view[3] === 44\n}\n"],
"mappings": "AAkCO,MAAM,iBAAiB,CAAC,WAAwB;AACtD,QAAM,OAAO,IAAI,WAAW,MAAM;AAClC,SAAO,KAAK,CAAC,MAAM;AACpB;",
"names": []
}