{
  "version": 3,
  "sources": ["../../src/utils/waveform-player.js"],
  "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\nimport { useRefEffect } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport { initWaveformPlayer } from './waveform-utils';\n\n/**\n * A reusable WaveformPlayer component for the block editor.\n *\n * Renders an audio waveform visualization with play/pause controls.\n * Automatically inherits colors from the parent block's text color.\n *\n * @param {Object}   props         - Component props.\n * @param {string}   props.src     - The audio file URL.\n * @param {string}   props.title   - The track title.\n * @param {string}   props.artist  - The artist name.\n * @param {string}   props.image   - The artwork image URL.\n * @param {Function} props.onEnded - Callback when the track finishes playing.\n * @return {Element} The WaveformPlayer element.\n */\nexport function WaveformPlayer( { src, title, artist, image, onEnded } ) {\n\t// Store onEnded in a ref so it doesn't need to be a useRefEffect dependency.\n\t// The callback changes reference on every render (its dependency chain\n\t// includes an unstable array), which would cause useRefEffect to destroy\n\t// and recreate the entire player on every re-render, making it disappear\n\t// during editor resizes.\n\tconst onEndedRef = useRef( onEnded );\n\tonEndedRef.current = onEnded;\n\n\tconst ref = useRefEffect(\n\t\t( element ) => {\n\t\t\tif ( ! src ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet cancelled = false;\n\t\t\tlet playerDestroy;\n\n\t\t\tfunction init() {\n\t\t\t\tif ( cancelled ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst { destroy } = initWaveformPlayer( element, {\n\t\t\t\t\tsrc,\n\t\t\t\t\ttitle,\n\t\t\t\t\tartist,\n\t\t\t\t\timage,\n\t\t\t\t\tonEnded: () => onEndedRef.current?.(),\n\t\t\t\t} );\n\t\t\t\tplayerDestroy = destroy;\n\t\t\t}\n\n\t\t\t// Defer initialization so the element inherits the correct\n\t\t\t// text color, which is used to derive waveform colors. In the\n\t\t\t// editor iframe, theme styles (CSS custom properties) are\n\t\t\t// injected dynamically, so getComputedStyle may return the\n\t\t\t// default black on first render.\n\t\t\t// Using a requestAnimationFrame loop isn't sufficient to solve the issue.\n\t\t\t// TODO - find a better option than a setTimeout, so we're not relying on an arbitrary number.\n\t\t\tconst timeoutId = setTimeout( init, 100 );\n\n\t\t\treturn () => {\n\t\t\t\tcancelled = true;\n\t\t\t\tclearTimeout( timeoutId );\n\t\t\t\tplayerDestroy?.();\n\t\t\t};\n\t\t},\n\t\t[ src, title, artist, image ]\n\t);\n\n\treturn <div ref={ ref } className=\"wp-block-playlist__waveform-player\" />;\n}\n"],
  "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAuB;AACvB,qBAA6B;AAK7B,4BAAmC;AAkE3B;AAlDD,SAAS,eAAgB,EAAE,KAAK,OAAO,QAAQ,OAAO,QAAQ,GAAI;AAMxE,QAAM,iBAAa,uBAAQ,OAAQ;AACnC,aAAW,UAAU;AAErB,QAAM,UAAM;AAAA,IACX,CAAE,YAAa;AACd,UAAK,CAAE,KAAM;AACZ;AAAA,MACD;AAEA,UAAI,YAAY;AAChB,UAAI;AAEJ,eAAS,OAAO;AACf,YAAK,WAAY;AAChB;AAAA,QACD;AACA,cAAM,EAAE,QAAQ,QAAI,0CAAoB,SAAS;AAAA,UAChD;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,SAAS,MAAM,WAAW,UAAU;AAAA,QACrC,CAAE;AACF,wBAAgB;AAAA,MACjB;AASA,YAAM,YAAY,WAAY,MAAM,GAAI;AAExC,aAAO,MAAM;AACZ,oBAAY;AACZ,qBAAc,SAAU;AACxB,wBAAgB;AAAA,MACjB;AAAA,IACD;AAAA,IACA,CAAE,KAAK,OAAO,QAAQ,KAAM;AAAA,EAC7B;AAEA,SAAO,4CAAC,SAAI,KAAY,WAAU,sCAAqC;AACxE;",
  "names": []
}
