{"version":3,"file":"AudioPlayer.mjs","names":[],"sources":["../../../../src/components/AudioPlayback/AudioPlayer.ts"],"sourcesContent":["import { StateStore } from '@stream-io/state-store';\nimport throttle from 'lodash.throttle';\nimport type { AudioPlayerPlugin } from './plugins';\nimport type { AudioPlayerPool } from './AudioPlayerPool';\n\nexport type AudioPlayerErrorCode =\n  | 'failed-to-start'\n  | 'not-playable'\n  | 'seek-not-supported'\n  | (string & {});\n\nexport type RegisterAudioPlayerErrorParams = {\n  error?: Error;\n  errCode?: AudioPlayerErrorCode;\n};\n\nexport type AudioPlayerDescriptor = {\n  id: string;\n  src: string;\n  /** Audio duration in seconds. */\n  durationSeconds?: number;\n  fileSize?: number | string;\n  /**\n   * MIME type checked with `canPlayType` when the player is created. When unsupported,\n   * `canPlayRecord` is false and `play` registers a `'not-playable'` error.\n   */\n  mimeType?: string;\n  title?: string;\n  waveformData?: number[];\n};\n\nexport type AudioPlayerPlayAudioParams = {\n  currentPlaybackRate?: number;\n  playbackRates?: number[];\n};\n\nexport type AudioPlayerState = {\n  /** Signals whether the browser can play the record. */\n  canPlayRecord: boolean;\n  /** Current playback speed. Starts as the first item of `playbackRates`. */\n  currentPlaybackRate: number;\n  /** Audio duration in seconds, from descriptor or loaded metadata. */\n  durationSeconds?: number;\n  /** Audio element held by the player, `null` while it holds none. */\n  elementRef: HTMLAudioElement | null;\n  /** Signals whether the playback is in progress. */\n  isPlaying: boolean;\n  /** Keeps the latest playback error reference. */\n  playbackError: Error | null;\n  /** Available playback speeds. Defaults to 1.0, 1.5 and 2.0. */\n  playbackRates: number[];\n  /** Playback progress expressed in percent. */\n  progressPercent: number;\n  /** Playback progress expressed in seconds. */\n  secondsElapsed: number;\n};\n\nexport type AudioPlayerOptions = AudioPlayerDescriptor & {\n  /** Playback speeds that replace the defaults (1.0, 1.5, 2.0). */\n  playbackRates?: number[];\n  plugins?: AudioPlayerPlugin[];\n  pool: AudioPlayerPool;\n};\n\nconst DEFAULT_PLAYBACK_RATES = [1.0, 1.5, 2.0];\n\nconst isSeekable = (audioElement: HTMLAudioElement) =>\n  !(audioElement.duration === Infinity || isNaN(audioElement.duration));\n\nexport const defaultRegisterAudioPlayerError = ({\n  error,\n}: RegisterAudioPlayerErrorParams = {}) => {\n  if (!error) return;\n  console.error('[AUDIO PLAYER]', error);\n};\n\nexport const elementIsPlaying = (audioElement: HTMLAudioElement | null) =>\n  audioElement && !(audioElement.paused || audioElement.ended);\n\nexport type SeekFn = (params: {\n  clientX: number;\n  currentTarget: HTMLDivElement;\n}) => Promise<void>;\n\nexport class AudioPlayer {\n  state: StateStore<AudioPlayerState>;\n  private _data: AudioPlayerDescriptor;\n  private _plugins = new Map<string, AudioPlayerPlugin>();\n  private playTimeout: ReturnType<typeof setTimeout> | undefined = undefined;\n  private unsubscribeEventListeners: (() => void) | null = null;\n  private _pool: AudioPlayerPool;\n  private _disposed = false;\n  private _pendingLoadedMeta?: { element: HTMLAudioElement; onLoaded: () => void };\n  private _elementIsReadyPromise?: Promise<boolean>;\n  private _metadataProbe: HTMLAudioElement | null = null;\n  private _metadataProbePromise?: Promise<void>;\n  private _restoringPosition = false;\n  private _removalTimeout: ReturnType<typeof setTimeout> | undefined = undefined;\n\n  constructor({\n    durationSeconds,\n    fileSize,\n    id,\n    mimeType,\n    playbackRates: customPlaybackRates,\n    plugins,\n    pool,\n    src,\n    title,\n    waveformData,\n  }: AudioPlayerOptions) {\n    this._data = {\n      durationSeconds,\n      fileSize,\n      id,\n      mimeType,\n      src,\n      title,\n      waveformData,\n    };\n    this._pool = pool;\n    this.setPlugins(() => plugins ?? []);\n\n    const playbackRates = customPlaybackRates?.length\n      ? customPlaybackRates\n      : DEFAULT_PLAYBACK_RATES;\n\n    // The shared element is acquired lazily; a temporary `Audio` probes the MIME type instead.\n    const canPlayRecord = mimeType ? !!new Audio().canPlayType(mimeType) : true;\n\n    this.state = new StateStore<AudioPlayerState>({\n      canPlayRecord,\n      currentPlaybackRate: playbackRates[0],\n      durationSeconds,\n      elementRef: null,\n      isPlaying: false,\n      playbackError: null,\n      playbackRates,\n      progressPercent: 0,\n      secondsElapsed: 0,\n    });\n\n    this.plugins.forEach((p) => p.onInit?.({ player: this }));\n    this.preloadMetadata();\n  }\n\n  private get plugins(): AudioPlayerPlugin[] {\n    return Array.from(this._plugins.values());\n  }\n\n  get canPlayRecord() {\n    return this.state.getLatestValue().canPlayRecord;\n  }\n\n  get elementRef() {\n    return this.state.getLatestValue().elementRef;\n  }\n\n  get isPlaying(): boolean {\n    return this.state.getLatestValue().isPlaying;\n  }\n\n  get currentPlaybackRate() {\n    return this.state.getLatestValue().currentPlaybackRate;\n  }\n\n  get playbackRates() {\n    return this.state.getLatestValue().playbackRates;\n  }\n\n  get durationSeconds() {\n    return this.state.getLatestValue().durationSeconds;\n  }\n\n  get fileSize() {\n    return this._data.fileSize;\n  }\n\n  get id() {\n    return this._data.id;\n  }\n\n  get src() {\n    return this._data.src;\n  }\n\n  get mimeType() {\n    return this._data.mimeType;\n  }\n\n  get title() {\n    return this._data.title;\n  }\n\n  get waveformData() {\n    return this._data.waveformData;\n  }\n\n  get secondsElapsed() {\n    return this.state.getLatestValue().secondsElapsed;\n  }\n\n  get progressPercent() {\n    return this.state.getLatestValue().progressPercent;\n  }\n\n  get disposed() {\n    return this._disposed;\n  }\n\n  private setDurationSeconds = (durationSeconds?: number) => {\n    this._data.durationSeconds = durationSeconds;\n    this.state.partialNext({ durationSeconds });\n  };\n\n  private ensureElementRef(): HTMLAudioElement {\n    if (this._disposed) {\n      throw new Error('AudioPlayer is disposed');\n    }\n    if (!this.elementRef) {\n      const el = this._pool.acquireElement({\n        owner: this,\n        src: this.src,\n      });\n      this.setRef(el);\n    }\n    return this.elementRef as HTMLAudioElement;\n  }\n  private setPlaybackStartSafetyTimeout = () => {\n    clearTimeout(this.playTimeout);\n    this.playTimeout = setTimeout(() => {\n      if (!this.elementRef) return;\n      try {\n        this.elementRef.pause();\n        this.state.partialNext({ isPlaying: false });\n      } catch (e) {\n        this.registerError({ errCode: 'failed-to-start' });\n      }\n    }, 2000);\n  };\n\n  private updateDurationFromElement = (element: HTMLAudioElement) => {\n    const duration = element.duration;\n    if (\n      typeof duration !== 'number' ||\n      isNaN(duration) ||\n      !isFinite(duration) ||\n      duration <= 0\n    ) {\n      return;\n    }\n    this.setDurationSeconds(duration);\n  };\n\n  private clearMetadataProbe = () => {\n    const probe = this._metadataProbe;\n    this._metadataProbe = null;\n    this._metadataProbePromise = undefined;\n\n    if (!probe) return;\n\n    try {\n      probe.pause();\n    } catch {\n      // ignore\n    }\n\n    probe.removeAttribute('src');\n    try {\n      probe.load();\n    } catch {\n      // ignore\n    }\n  };\n\n  private preloadMetadata = () => {\n    if (\n      this._disposed ||\n      this.durationSeconds != null ||\n      !this.src ||\n      this._metadataProbePromise ||\n      typeof document === 'undefined'\n    ) {\n      return;\n    }\n\n    const probe = document.createElement('audio');\n    probe.preload = 'metadata';\n    this._metadataProbe = probe;\n    this._metadataProbePromise = new Promise((resolve) => {\n      const cleanup = () => {\n        probe.removeEventListener('loadedmetadata', handleLoadedMetadata);\n        probe.removeEventListener('error', handleError);\n        if (this._metadataProbe === probe) {\n          this.clearMetadataProbe();\n        } else {\n          this._metadataProbePromise = undefined;\n        }\n        resolve();\n      };\n\n      const handleLoadedMetadata = () => {\n        this.updateDurationFromElement(probe);\n        cleanup();\n      };\n\n      const handleError = () => {\n        cleanup();\n      };\n\n      probe.addEventListener('loadedmetadata', handleLoadedMetadata, { once: true });\n      probe.addEventListener('error', handleError, { once: true });\n      probe.src = this.src;\n      try {\n        probe.load();\n      } catch {\n        cleanup();\n      }\n    });\n  };\n\n  private clearPlaybackStartSafetyTimeout = () => {\n    if (!this.elementRef) return;\n    clearTimeout(this.playTimeout);\n    this.playTimeout = undefined;\n  };\n\n  private clearPendingLoadedMeta = () => {\n    const pending = this._pendingLoadedMeta;\n    if (pending?.element && pending.onLoaded) {\n      pending.element.removeEventListener('loadedmetadata', pending.onLoaded);\n    }\n    this._pendingLoadedMeta = undefined;\n  };\n\n  private restoreSavedPosition = (elementRef: HTMLAudioElement) => {\n    const saved = this.secondsElapsed;\n    if (!saved || saved <= 0) return;\n    const apply = () => {\n      const duration = elementRef.duration;\n      const clamped =\n        typeof duration === 'number' && !isNaN(duration) && isFinite(duration)\n          ? Math.min(saved, duration)\n          : saved;\n      try {\n        if (elementRef.currentTime === clamped) return;\n        elementRef.currentTime = clamped;\n        // Preempt UI with restored position to avoid flicker\n        this.setSecondsElapsed(clamped);\n      } catch {\n        // ignore\n      }\n    };\n    // readyState below 1 (HAVE_NOTHING): nothing is known about the media resource yet.\n    if (elementRef.readyState < 1) {\n      this.clearPendingLoadedMeta();\n      this._restoringPosition = true;\n      const onLoaded = () => {\n        // Ensure this callback still belongs to the same pending registration and same element\n        if (this._pendingLoadedMeta?.onLoaded !== onLoaded) return;\n        this._pendingLoadedMeta = undefined;\n        if (this.elementRef !== elementRef) {\n          this._restoringPosition = false;\n          return;\n        }\n        apply();\n        this._restoringPosition = false;\n      };\n      elementRef.addEventListener('loadedmetadata', onLoaded, { once: true });\n      this._pendingLoadedMeta = { element: elementRef, onLoaded };\n    } else {\n      this._restoringPosition = true;\n      apply();\n      this._restoringPosition = false;\n    }\n  };\n\n  setDescriptor(descriptor: AudioPlayerDescriptor) {\n    const previousSrc = this.src;\n    this._data = { ...this._data, ...descriptor };\n    if (descriptor.src !== previousSrc && this.elementRef) {\n      this.elementRef.src = descriptor.src;\n    }\n    if (descriptor.src && descriptor.src !== previousSrc) {\n      this.clearMetadataProbe();\n      if (descriptor.durationSeconds == null) {\n        this.setDurationSeconds(undefined);\n        this.preloadMetadata();\n      } else {\n        this.setDurationSeconds(descriptor.durationSeconds);\n      }\n      return;\n    }\n    if (descriptor.durationSeconds != null) {\n      this.setDurationSeconds(descriptor.durationSeconds);\n    }\n  }\n\n  private releaseElement({ resetState }: { resetState: boolean }) {\n    this.clearPendingLoadedMeta();\n    this.clearMetadataProbe();\n    this._restoringPosition = false;\n    if (resetState) {\n      this.stop();\n    } else {\n      // Ensure isPlaying reflects reality, but keep progress/seconds\n      this.state.partialNext({ isPlaying: false });\n      if (this.elementRef) {\n        try {\n          this.elementRef.pause();\n        } catch {\n          // ignore\n        }\n      }\n    }\n    if (this.elementRef) {\n      this._pool.releaseElement(this);\n      this.setRef(null);\n    }\n  }\n\n  private elementIsReady = (): Promise<boolean> => {\n    if (this._elementIsReadyPromise) return this._elementIsReadyPromise;\n\n    this._elementIsReadyPromise = new Promise((resolve) => {\n      if (!this.elementRef) return resolve(false);\n      const element = this.elementRef;\n      const handleLoaded = () => {\n        element.removeEventListener('loadedmetadata', handleLoaded);\n        resolve(element.readyState > 0);\n      };\n      element.addEventListener('loadedmetadata', handleLoaded);\n    });\n\n    return this._elementIsReadyPromise;\n  };\n\n  private setRef = (elementRef: HTMLAudioElement | null) => {\n    if (elementIsPlaying(this.elementRef)) {\n      // preserve state during swap\n      this.releaseElement({ resetState: false });\n    }\n    this.clearPendingLoadedMeta();\n    this.clearMetadataProbe();\n    this._restoringPosition = false;\n    this._elementIsReadyPromise = undefined;\n    this.state.partialNext({ elementRef });\n    if (elementRef) {\n      this.registerSubscriptions();\n    }\n  };\n\n  setSecondsElapsed = (secondsElapsed: number) => {\n    const duration = this.elementRef?.duration ?? this.durationSeconds;\n    this.state.partialNext({\n      progressPercent: duration && secondsElapsed ? (secondsElapsed / duration) * 100 : 0,\n      secondsElapsed,\n    });\n  };\n\n  setPlugins(setter: (currentPlugins: AudioPlayerPlugin[]) => AudioPlayerPlugin[]) {\n    this._plugins = setter(this.plugins).reduce((acc, plugin) => {\n      if (plugin.id) {\n        acc.set(plugin.id, plugin);\n      }\n      return acc;\n    }, new Map<string, AudioPlayerPlugin>());\n  }\n\n  canPlayMimeType = (mimeType: string) => {\n    if (!mimeType) return false;\n    if (this.elementRef) return !!this.elementRef.canPlayType(mimeType);\n    return !!new Audio().canPlayType(mimeType);\n  };\n\n  play = async (params?: AudioPlayerPlayAudioParams) => {\n    if (this._disposed) return;\n    const elementRef = this.ensureElementRef();\n    if (elementIsPlaying(this.elementRef)) {\n      if (this.isPlaying) return;\n      this.state.partialNext({ isPlaying: true });\n      return;\n    }\n\n    const { currentPlaybackRate, playbackRates } = {\n      currentPlaybackRate: this.currentPlaybackRate,\n      playbackRates: this.playbackRates,\n      ...params,\n    };\n\n    if (!this.canPlayRecord) {\n      this.registerError({ errCode: 'not-playable' });\n      return;\n    }\n\n    this.restoreSavedPosition(elementRef);\n\n    elementRef.playbackRate = currentPlaybackRate ?? this.currentPlaybackRate;\n\n    this.setPlaybackStartSafetyTimeout();\n\n    try {\n      await elementRef.play();\n      this.state.partialNext({\n        currentPlaybackRate,\n        isPlaying: true,\n        playbackRates,\n      });\n      this._pool.setActiveAudioPlayer(this);\n    } catch (e) {\n      this.registerError({ error: e as Error });\n      this.state.partialNext({ isPlaying: false });\n    } finally {\n      this.clearPlaybackStartSafetyTimeout();\n    }\n  };\n\n  pause = () => {\n    if (!elementIsPlaying(this.elementRef)) return;\n    this.clearPlaybackStartSafetyTimeout();\n\n    // existence of the element already checked by elementIsPlaying\n    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n    this.elementRef!.pause();\n    this.state.partialNext({ isPlaying: false });\n  };\n\n  stop = () => {\n    this.pause();\n    this.state.partialNext({ isPlaying: false });\n    this.setSecondsElapsed(0);\n    if (this.elementRef) this.elementRef.currentTime = 0;\n  };\n\n  togglePlay = async () => (this.isPlaying ? this.pause() : await this.play());\n\n  increasePlaybackRate = () => {\n    let currentPlaybackRateIndex = this.state\n      .getLatestValue()\n      .playbackRates.findIndex((rate) => rate === this.currentPlaybackRate);\n    if (currentPlaybackRateIndex === -1) {\n      currentPlaybackRateIndex = 0;\n    }\n    const nextIndex =\n      currentPlaybackRateIndex === this.playbackRates.length - 1\n        ? 0\n        : currentPlaybackRateIndex + 1;\n    const currentPlaybackRate = this.playbackRates[nextIndex];\n    this.state.partialNext({ currentPlaybackRate });\n    if (this.elementRef) {\n      this.elementRef.playbackRate = currentPlaybackRate;\n    }\n  };\n\n  seek = throttle<SeekFn>(async ({ clientX, currentTarget }) => {\n    let element = this.elementRef;\n    if (!this.elementRef) {\n      element = this.ensureElementRef();\n      const isReady = await this.elementIsReady();\n      if (!isReady) return;\n    }\n    if (!currentTarget || !element) return;\n    if (!isSeekable(element)) {\n      this.registerError({ errCode: 'seek-not-supported' });\n      return;\n    }\n\n    const { width, x } = currentTarget.getBoundingClientRect();\n\n    const ratio = (clientX - x) / width;\n    if (ratio > 1 || ratio < 0) return;\n    const currentTime = ratio * element.duration;\n    this.setSecondsElapsed(currentTime);\n    element.currentTime = currentTime;\n  }, 16);\n\n  registerError = (params: RegisterAudioPlayerErrorParams) => {\n    defaultRegisterAudioPlayerError(params);\n    this.plugins.forEach(({ onError }) => onError?.({ player: this, ...params }));\n  };\n\n  /**\n   * Disposes the player: releases its element and listeners, runs plugins' `onRemove`, and\n   * deregisters it from the pool.\n   */\n  requestRemoval = () => {\n    this._disposed = true;\n    this.cancelScheduledRemoval();\n    this.clearPendingLoadedMeta();\n    this.clearMetadataProbe();\n    this._restoringPosition = false;\n    this.releaseElement({ resetState: true });\n    this.unsubscribeEventListeners?.();\n    this.unsubscribeEventListeners = null;\n    this.plugins.forEach(({ onRemove }) => onRemove?.({ player: this }));\n    this._pool.deregister(this.id);\n  };\n\n  cancelScheduledRemoval = () => {\n    clearTimeout(this._removalTimeout);\n    this._removalTimeout = undefined;\n  };\n\n  scheduleRemoval = (ms: number = 0) => {\n    this.cancelScheduledRemoval();\n    this._removalTimeout = setTimeout(() => {\n      if (this.disposed) return;\n      this.requestRemoval();\n    }, ms);\n  };\n\n  /**\n   * Releases the element and its listeners without disposing the player. Used by\n   * `AudioPlaybackArbiter` to hand the shared element to another player.\n   */\n  releaseElementForHandoff = () => {\n    if (!this.elementRef) return;\n    this.releaseElement({ resetState: false });\n    this.unsubscribeEventListeners?.();\n    this.unsubscribeEventListeners = null;\n  };\n\n  registerSubscriptions = () => {\n    this.unsubscribeEventListeners?.();\n\n    const audioElement = this.elementRef;\n    if (!audioElement) return;\n\n    const handleEnded = () => {\n      if (audioElement) {\n        this.updateDurationFromElement(audioElement);\n      }\n      this.stop();\n    };\n\n    const handleError = (e: HTMLMediaElementEventMap['error']) => {\n      // `audio.error.code` is 1 MEDIA_ERR_ABORTED, 2 MEDIA_ERR_NETWORK, 3 MEDIA_ERR_DECODE or\n      // 4 MEDIA_ERR_SRC_NOT_SUPPORTED. The error is only logged; code 4 also marks the record\n      // as not playable.\n      const audio = e.currentTarget as HTMLAudioElement | null;\n      const state: Partial<AudioPlayerState> = { isPlaying: false };\n\n      if (!audio?.error?.code) {\n        this.state.partialNext(state);\n        return;\n      }\n\n      if (audio.error.code === 4) {\n        state.canPlayRecord = false;\n        this.state.partialNext(state);\n      }\n\n      const errorMsg = [\n        undefined,\n        'MEDIA_ERR_ABORTED: fetch aborted by user',\n        'MEDIA_ERR_NETWORK: network failed while fetching',\n        'MEDIA_ERR_DECODE: audio fetched but couldn’t decode',\n        'MEDIA_ERR_SRC_NOT_SUPPORTED: source not supported',\n      ][audio?.error?.code];\n      if (!errorMsg) return;\n\n      defaultRegisterAudioPlayerError({ error: new Error(errorMsg + ` (${audio.src})`) });\n    };\n\n    const handleTimeupdate = () => {\n      const t = audioElement?.currentTime ?? 0;\n      // Ignore spurious zero during restore/handoff to avoid UI flicker\n      if (this._restoringPosition && t === 0) return;\n      // Also avoid regressing UI to zero if we already have non-zero progress and we're not playing\n      if (!this.isPlaying && t === 0 && this.secondsElapsed > 0) return;\n      this.setSecondsElapsed(t);\n    };\n\n    const handleLoadedMetadata = () => {\n      if (audioElement) {\n        this.updateDurationFromElement(audioElement);\n      }\n    };\n\n    audioElement.addEventListener('ended', handleEnded);\n    audioElement.addEventListener('error', handleError);\n    audioElement.addEventListener('loadedmetadata', handleLoadedMetadata);\n    audioElement.addEventListener('timeupdate', handleTimeupdate);\n\n    this.unsubscribeEventListeners = () => {\n      audioElement.pause();\n      audioElement.removeEventListener('ended', handleEnded);\n      audioElement.removeEventListener('error', handleError);\n      audioElement.removeEventListener('loadedmetadata', handleLoadedMetadata);\n      audioElement.removeEventListener('timeupdate', handleTimeupdate);\n    };\n  };\n}\n"],"mappings":";;;AAgEA,IAAM,yBAAyB;CAAC;CAAK;CAAK;AAAG;AAE7C,IAAM,cAAc,iBAClB,EAAE,aAAa,aAAa,YAAY,MAAM,aAAa,QAAQ;AAErE,IAAa,mCAAmC,EAC9C,UACkC,CAAC,MAAM;CACzC,IAAI,CAAC,OAAO;CACZ,QAAQ,MAAM,kBAAkB,KAAK;AACvC;AAEA,IAAa,oBAAoB,iBAC/B,gBAAgB,EAAE,aAAa,UAAU,aAAa;AAOxD,IAAa,cAAb,MAAyB;CACvB;CACA;CACA,2BAAmB,IAAI,IAA+B;CACtD,cAAiE,KAAA;CACjE,4BAAyD;CACzD;CACA,YAAoB;CACpB;CACA;CACA,iBAAkD;CAClD;CACA,qBAA6B;CAC7B,kBAAqE,KAAA;CAErE,YAAY,EACV,iBACA,UACA,IACA,UACA,eAAe,qBACf,SACA,MACA,KACA,OACA,gBACqB;EACrB,KAAK,QAAQ;GACX;GACA;GACA;GACA;GACA;GACA;GACA;EACF;EACA,KAAK,QAAQ;EACb,KAAK,iBAAiB,WAAW,CAAC,CAAC;EAEnC,MAAM,gBAAgB,qBAAqB,SACvC,sBACA;EAGJ,MAAM,gBAAgB,WAAW,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,YAAY,QAAQ,IAAI;EAEvE,KAAK,QAAQ,IAAI,WAA6B;GAC5C;GACA,qBAAqB,cAAc;GACnC;GACA,YAAY;GACZ,WAAW;GACX,eAAe;GACf;GACA,iBAAiB;GACjB,gBAAgB;EAClB,CAAC;EAED,KAAK,QAAQ,SAAS,MAAM,EAAE,SAAS,EAAE,QAAQ,KAAK,CAAC,CAAC;EACxD,KAAK,gBAAgB;CACvB;CAEA,IAAY,UAA+B;EACzC,OAAO,MAAM,KAAK,KAAK,SAAS,OAAO,CAAC;CA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