{
  "version": 3,
  "sources": ["../../../src/lib/utils/assets.ts"],
  "sourcesContent": ["import downscale from 'downscale'\nimport { getBrowserCanvasMaxSize } from '../shapes/shared/getBrowserCanvasMaxSize'\nimport { isAnimated } from './assets/is-gif-animated'\n\ntype BoxWidthHeight = {\n\tw: number\n\th: number\n}\n\n/**\n * Contains the size within the given box size\n *\n * @param originalSize - The size of the asset\n * @param containBoxSize - The container size\n * @returns Adjusted size\n * @public\n */\nexport function containBoxSize(\n\toriginalSize: BoxWidthHeight,\n\tcontainBoxSize: BoxWidthHeight\n): BoxWidthHeight {\n\tconst overByXScale = originalSize.w / containBoxSize.w\n\tconst overByYScale = originalSize.h / containBoxSize.h\n\n\tif (overByXScale <= 1 && overByYScale <= 1) {\n\t\treturn originalSize\n\t} else if (overByXScale > overByYScale) {\n\t\treturn {\n\t\t\tw: originalSize.w / overByXScale,\n\t\t\th: originalSize.h / overByXScale,\n\t\t}\n\t} else {\n\t\treturn {\n\t\t\tw: originalSize.w / overByYScale,\n\t\t\th: originalSize.h / overByYScale,\n\t\t}\n\t}\n}\n\n/**\n * Get the size of an image from its source.\n *\n * @example\n * ```ts\n * const size = await getImageSize('https://example.com/image.jpg')\n * const dataUrl = await getResizedImageDataUrl('https://example.com/image.jpg', size.w, size.h, { type: \"image/jpeg\", quality: 0.92 })\n * ```\n *\n * @param dataURLForImage - The image file as a string.\n * @param width - The desired width.\n * @param height - The desired height.\n * @param opts - Options for the image.\n * @public\n */\nexport async function getResizedImageDataUrl(\n\tdataURLForImage: string,\n\twidth: number,\n\theight: number,\n\topts = {} as { type?: string; quality?: number }\n): Promise<string> {\n\tlet desiredWidth = width * 2\n\tlet desiredHeight = height * 2\n\tconst { type = 'image/jpeg', quality = 0.92 } = opts\n\n\tconst canvasSizes = await getBrowserCanvasMaxSize()\n\n\tconst aspectRatio = width / height\n\n\tif (desiredWidth > canvasSizes.maxWidth) {\n\t\tdesiredWidth = canvasSizes.maxWidth\n\t\tdesiredHeight = desiredWidth / aspectRatio\n\t}\n\n\tif (desiredHeight > canvasSizes.maxHeight) {\n\t\tdesiredHeight = canvasSizes.maxHeight\n\t\tdesiredWidth = desiredHeight * aspectRatio\n\t}\n\n\tif (desiredWidth * desiredHeight > canvasSizes.maxArea) {\n\t\tconst ratio = Math.sqrt(canvasSizes.maxArea / (desiredWidth * desiredHeight))\n\t\tdesiredWidth *= ratio\n\t\tdesiredHeight *= ratio\n\t}\n\n\treturn await downscale(dataURLForImage, desiredWidth, desiredHeight, { imageType: type, quality })\n}\n\n/** @public */\nexport const DEFAULT_ACCEPTED_IMG_TYPE = ['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml']\n/** @public */\nexport const DEFAULT_ACCEPTED_VID_TYPE = ['video/mp4', 'video/quicktime']\n\n/** @public */\nexport async function isGifAnimated(file: File): Promise<boolean> {\n\treturn await new Promise((resolve, reject) => {\n\t\tconst reader = new FileReader()\n\t\treader.onerror = () => reject(reader.error)\n\t\treader.onload = () => {\n\t\t\tresolve(reader.result ? isAnimated(reader.result as ArrayBuffer) : false)\n\t\t}\n\t\treader.readAsArrayBuffer(file)\n\t})\n}\n"],
  "mappings": "AAAA,OAAO,eAAe;AACtB,SAAS,+BAA+B;AACxC,SAAS,kBAAkB;AAepB,SAAS,eACf,cACAA,iBACiB;AACjB,QAAM,eAAe,aAAa,IAAIA,gBAAe;AACrD,QAAM,eAAe,aAAa,IAAIA,gBAAe;AAErD,MAAI,gBAAgB,KAAK,gBAAgB,GAAG;AAC3C,WAAO;AAAA,EACR,WAAW,eAAe,cAAc;AACvC,WAAO;AAAA,MACN,GAAG,aAAa,IAAI;AAAA,MACpB,GAAG,aAAa,IAAI;AAAA,IACrB;AAAA,EACD,OAAO;AACN,WAAO;AAAA,MACN,GAAG,aAAa,IAAI;AAAA,MACpB,GAAG,aAAa,IAAI;AAAA,IACrB;AAAA,EACD;AACD;AAiBA,eAAsB,uBACrB,iBACA,OACA,QACA,OAAO,CAAC,GACU;AAClB,MAAI,eAAe,QAAQ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