{"version":3,"file":"utils.mjs","names":[],"sources":["../../../../src/components/Attachment/utils.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\nimport type { Attachment, SharedLocationResponseData } from 'stream-chat';\nimport type { ATTACHMENT_GROUPS_ORDER, AttachmentProps } from './Attachment';\nimport * as linkify from 'linkifyjs';\n\nexport const SUPPORTED_VIDEO_FORMATS = [\n  'video/mp4',\n  'video/ogg',\n  'video/webm',\n  'video/quicktime',\n];\n\nexport type AttachmentComponentType =\n  | 'card'\n  | 'gallery'\n  | 'giphy'\n  | 'image'\n  | 'media'\n  | 'audio'\n  | 'voiceRecording'\n  | 'file'\n  | 'geolocation'\n  | 'unsupported';\n\nexport type AttachmentContainerType = (typeof ATTACHMENT_GROUPS_ORDER)[number];\n\nexport type GroupedRenderedAttachment = Record<AttachmentContainerType, ReactNode[]>;\n\nexport type GalleryAttachment = {\n  items: Attachment[];\n  type: 'gallery';\n};\n\nexport type RenderAttachmentProps = Omit<AttachmentProps, 'attachments'> & {\n  attachment: Attachment;\n};\n\nexport type RenderGalleryProps = Omit<AttachmentProps, 'attachments'> & {\n  attachment: GalleryAttachment;\n};\n\nexport type RenderMediaProps = Omit<AttachmentProps, 'attachments'> & {\n  attachments: Attachment[];\n};\n\nexport type GeolocationContainerProps = Omit<AttachmentProps, 'attachments'> & {\n  location: SharedLocationResponseData;\n};\n\n/**\n * Whether the attachment is a gallery, which this SDK builds from several media attachments.\n * @param attachment - Attachment to check.\n */\nexport const isGalleryAttachmentType = (\n  attachment: Attachment | GalleryAttachment,\n): attachment is GalleryAttachment =>\n  Array.isArray((attachment as GalleryAttachment).items);\n\nexport const isSvgAttachment = (attachment: Attachment) => {\n  const filename = attachment.fallback || '';\n  return filename.toLowerCase().endsWith('.svg');\n};\n\nexport const divMod = (num: number, divisor: number) => [\n  Math.floor(num / divisor),\n  num % divisor,\n];\n\nexport const displayDuration = (totalSeconds?: number) => {\n  if (!totalSeconds || totalSeconds < 0) return '00:00';\n\n  const [hours, hoursLeftover] = divMod(totalSeconds, 3600);\n  const [minutes, seconds] = divMod(hoursLeftover, 60);\n  const roundedSeconds = Math.ceil(seconds);\n  const prependHrsZero = String(hours).padStart(2, '0');\n  const prependMinZero = String(minutes).padStart(2, '0');\n  const prependSecZero = String(roundedSeconds).padStart(2, '0');\n  const minSec = `${prependMinZero}:${prependSecZero}`;\n\n  return hours ? `${prependHrsZero}:` + minSec : minSec;\n};\nexport function getCssDimensionsVariables(url: string) {\n  const cssVars = {\n    '--original-height': 1000000,\n    '--original-width': 1000000,\n  } as Record<string, number>;\n\n  if (linkify.test(url, 'url')) {\n    const urlParams = new URL(url).searchParams;\n    const oh = Number(urlParams.get('oh'));\n    const ow = Number(urlParams.get('ow'));\n    const originalHeight = oh > 1 ? oh : 1000000;\n    const originalWidth = ow > 1 ? ow : 1000000;\n    cssVars['--original-width'] = originalWidth;\n    cssVars['--original-height'] = originalHeight;\n  }\n\n  return cssVars;\n}\n"],"mappings":";;AAKA,IAAa,0BAA0B;CACrC;CACA;CACA;CACA;AACF;;;;;AA2CA,IAAa,2BACX,eAEA,MAAM,QAAS,WAAiC,KAAK;AAEvD,IAAa,mBAAmB,eAA2B;CAEzD,QADiB,WAAW,YAAY,GAAA,CACxB,YAAY,CAAC,CAAC,SAAS,MAAM;AAC/C;AAEA,IAAa,UAAU,KAAa,YAAoB,CACtD,KAAK,MAAM,MAAM,OAAO,GACxB,MAAM,OACR;AAEA,IAAa,mBAAmB,iBAA0B;CACxD,IAAI,CAAC,gBAAgB,eAAe,GAAG,OAAO;CAE9C,MAAM,CAAC,OAAO,iBAAiB,OAAO,cAAc,IAAI;CACxD,MAAM,CAAC,SAAS,WAAW,OAAO,eAAe,EAAE;CACnD,MAAM,iBAAiB,KAAK,KAAK,OAAO;CACxC,MAAM,iBAAiB,OAAO,KAAK,CAAC,CAAC,SAAS,GAAG,GAAG;CAGpD,MAAM,SAAS,GAFQ,OAAO,OAAO,CAAC,CAAC,SAAS,GAAG,GAEjC,EAAe,GADV,OAAO,cAAc,CAAC,CAAC,SAAS,GAAG,GACtB;CAEpC,OAAO,QAAQ,GAAG,eAAe,KAAK,SAAS;AACjD;AACA,SAAgB,0BAA0B,KAAa;CACrD,MAAM,UAAU;EACd,qBAAqB;EACrB,oBAAoB;CACtB;CAEA,IAAI,QAAQ,KAAK,KAAK,KAAK,GAAG;EAC5B,MAAM,YAAY,IAAI,IAAI,GAAG,CAAC,CAAC;EAC/B,MAAM,KAAK,OAAO,UAAU,IAAI,IAAI,CAAC;EACrC,MAAM,KAAK,OAAO,UAAU,IAAI,IAAI,CAAC;EACrC,MAAM,iBAAiB,KAAK,IAAI,KAAK;EAErC,QAAQ,sBADc,KAAK,IAAI,KAAK;EAEpC,QAAQ,uBAAuB;CACjC;CAEA,OAAO;AACT"}