@tldraw/utils
Version:
tldraw infinite canvas SDK (private utilities).
8 lines (7 loc) • 2.31 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../../src/lib/media/webp.ts"],
"sourcesContent": ["/*!\n * MIT License: https://github.com/sindresorhus/is-webp/blob/main/license\n * Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)\n */\n\n/**\n * Determines whether a byte array represents a WebP image by checking the WebP file signature.\n *\n * @param view - The Uint8Array containing the potential WebP image data\n * @returns True if the byte array is a valid WebP image, false otherwise\n * @example\n * ```ts\n * // Check if file data is WebP format\n * const file = new File([...], 'image.webp', { type: 'image/webp' })\n * const buffer = await file.arrayBuffer()\n * const view = new Uint8Array(buffer)\n * const isWebPImage = isWebp(view)\n * console.log(isWebPImage ? 'Valid WebP' : 'Not WebP')\n * ```\n * @internal\n */\nexport function isWebp(view: Uint8Array) {\n\tif (!view || view.length < 12) {\n\t\treturn false\n\t}\n\n\treturn view[8] === 87 && view[9] === 69 && view[10] === 66 && view[11] === 80\n}\n\n/**\n * Determines whether a WebP image file contains animation data by checking the animation flag in the WebP VP8X chunk.\n *\n * @param buffer - The ArrayBuffer containing the WebP image data\n * @returns True if the WebP image is animated, false otherwise\n * @example\n * ```ts\n * // Check if a WebP file from user input is animated\n * const file = new File([...], 'image.webp', { type: 'image/webp' })\n * const buffer = await file.arrayBuffer()\n * const animated = isWebpAnimated(buffer)\n * console.log(animated ? 'Animated WebP' : 'Static WebP')\n * ```\n * @public\n */\nexport function isWebpAnimated(buffer: ArrayBuffer) {\n\tconst view = new Uint8Array(buffer)\n\n\tif (!isWebp(view)) {\n\t\treturn false\n\t}\n\n\tif (!view || view.length < 21) {\n\t\treturn false\n\t}\n\n\treturn ((view[20] >> 1) & 1) === 1\n}\n"],
"mappings": "AAAA;AAAA;AAAA;AAAA;AAqBO,SAAS,OAAO,MAAkB;AACxC,MAAI,CAAC,QAAQ,KAAK,SAAS,IAAI;AAC9B,WAAO;AAAA,EACR;AAEA,SAAO,KAAK,CAAC,MAAM,MAAM,KAAK,CAAC,MAAM,MAAM,KAAK,EAAE,MAAM,MAAM,KAAK,EAAE,MAAM;AAC5E;AAiBO,SAAS,eAAe,QAAqB;AACnD,QAAM,OAAO,IAAI,WAAW,MAAM;AAElC,MAAI,CAAC,OAAO,IAAI,GAAG;AAClB,WAAO;AAAA,EACR;AAEA,MAAI,CAAC,QAAQ,KAAK,SAAS,IAAI;AAC9B,WAAO;AAAA,EACR;AAEA,UAAS,KAAK,EAAE,KAAK,IAAK,OAAO;AAClC;",
"names": []
}