diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7fd4c47..642efc77 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,9 @@ This is an alpha version! The changes listed here are not final.
### Changed
- Updated package dependencies.
+### Fixed
+- Lossless image optimization for images (should improve performance with no visible changes).
+
## [0.24.0] - 2024-08-15
### Changed
- Updated package dependencies. [#38665]
diff --git a/build/block-editor/blocks/video/index.asset.php b/build/block-editor/blocks/video/index.asset.php
index ec5bbedc..a6cbbfe1 100644
--- a/build/block-editor/blocks/video/index.asset.php
+++ b/build/block-editor/blocks/video/index.asset.php
@@ -1 +1 @@
- array('lodash', 'react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-escape-html', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => '86a498bac91bea265846');
+ array('lodash', 'react', 'react-jsx-runtime', 'wp-api-fetch', 'wp-blob', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-editor', 'wp-element', 'wp-escape-html', 'wp-hooks', 'wp-html-entities', 'wp-i18n', 'wp-plugins', 'wp-polyfill', 'wp-primitives', 'wp-url'), 'version' => '30c307a983fe2a590b41');
diff --git a/build/block-editor/blocks/video/index.js b/build/block-editor/blocks/video/index.js
index e496daaa..82b294dc 100644
--- a/build/block-editor/blocks/video/index.js
+++ b/build/block-editor/blocks/video/index.js
@@ -7,4 +7,4 @@ __("Video duration: %s.","jetpack-videopress-pkg"),(0,d.fJ)(n)),{em:Rea
__("Minimum: %1$ss. Maximum: %2$ss.","jetpack-videopress-pkg"),Math.min(g/1e3,v),v),{em:React.createElement("em",null)}),_=0===f,E=m<=g,R=(0,a.useCallback)((e=>{c(e);const t=Math.min(y,n-e);h(t),r>t&&l(t)}),[c,n,r,l]);return React.createElement(React.Fragment,null,React.createElement(o.ToggleControl,{className:"poster-panel__preview-toggle",label:__("Video preview on hover","jetpack-videopress-pkg"),checked:e,onChange:s,disabled:!e&&p}),e&&React.createElement(React.Fragment,null,React.createElement(u.ZP,{label:__("Starting point","jetpack-videopress-pkg"),max:f,fineAdjustment:50,value:t,onDebounceChange:R,wait:300,disabled:p||_,help:w}),React.createElement(u.ZP,{max:m,min:g,fineAdjustment:50,label:__("Loop duration","jetpack-videopress-pkg"),value:r,onDebounceChange:l,wait:300,help:k,disabled:p||E,marksEvery:1e3})))}function S({attributes:e,setAttributes:t,isGeneratingPoster:r,videoBelongToSite:n}){const{poster:i,posterData:s}=e,u=e?.duration,p="video-frame"===s?.type,d=s?.previewOnHover||!1,f=s?.previewAtTime??s?.atTime??0;let m=s?.previewLoopDuration??b;m>u-f&&(m=u-f);const h=(0,a.useCallback)((r=>{t({posterData:{...e.posterData,type:r?"video-frame":"media-library"},poster:r?"":e.posterData.url||""})}),[e]),g=(0,a.useCallback)((r=>{let n={...e.posterData,previewOnHover:r};r&&(n={previewAtTime:f,previewLoopDuration:m,...n}),t({posterData:n,controls:!r&&e.controls})}),[e]),y=(0,a.useCallback)((r=>{t({posterData:{...e.posterData,previewAtTime:r}})}),[e]),k=(0,a.useCallback)((r=>{let n=f;f+r>u&&(n=u-r),t({posterData:{...e.posterData,previewLoopDuration:r,previewAtTime:n}})}),[e]),E=w()?__("Poster and preview","jetpack-videopress-pkg"):__("Poster","jetpack-videopress-pkg");return React.createElement(o.PanelBody,{title:E,className:"poster-panel",initialOpen:!1},React.createElement(o.ToggleControl,{label:__("Pick from video frame","jetpack-videopress-pkg"),checked:p&&n,onChange:h,disabled:!n}),React.createElement("div",{className:(0,l.Z)("poster-panel__frame-wrapper",{"is-selected":p})},React.createElement(R,{isGeneratingPoster:r,guid:e?.guid,atTime:s?.atTime,duration:u,onVideoFrameSelect:r=>{t({posterData:{...e.posterData,type:"video-frame",atTime:r},poster:""})}})),React.createElement("div",{className:(0,l.Z)("poster-panel__image-wrapper",{"is-selected":!p})},React.createElement(_,{attributes:e,setAttributes:t}),React.createElement(v.u,{poster:i,className:"poster-panel-card"}),i&&React.createElement(o.MenuItem,{onClick:()=>{t({poster:"",posterData:{...e.posterData,url:""}})},icon:c.Z,isDestructive:!0,variant:"tertiary"},__("Remove and use default","jetpack-videopress-pkg"))),w()&&React.createElement(C,{previewOnHover:d,previewAtTime:f,loopDuration:m,videoDuration:u,onPreviewOnHoverChange:g,onPreviewAtTimeChange:y,onLoopDurationChange:k}))}},8864:(e,t,r)=>{"use strict";r.d(t,{Z:()=>o});var n=r(3853);function o({attributes:e,setAttributes:t,privateEnabledForSite:r,videoBelongToSite:o}){return React.createElement(n.Z,{attributes:e,setAttributes:t,privateEnabledForSite:r,videoBelongToSite:o})}},3853:(e,t,r)=>{"use strict";r.d(t,{Z:()=>i});var n=r(5609),o=r(5736),a=r(4391);const __=o.__,_x=o._x;function i({attributes:e,setAttributes:t,privateEnabledForSite:r,videoBelongToSite:o}){const{privacySetting:i,rating:s,allowDownload:c,displayEmbed:l}=e,u={private:_x("Site Default (Private)","VideoPress privacy setting","jetpack-videopress-pkg"),public:_x("Site Default (Public)","VideoPress privacy setting","jetpack-videopress-pkg")},p={value:String(a.Vz.indexOf(a.O1)),label:r?u.private:u.public},d={value:String(a.Vz.indexOf(a.$A)),label:_x("Public","VideoPress privacy setting","jetpack-videopress-pkg")},f={value:String(a.Vz.indexOf(a.UJ)),label:_x("Private","VideoPress privacy setting","jetpack-videopress-pkg")};return React.createElement(n.PanelBody,{title:__("Privacy and rating","jetpack-videopress-pkg"),initialOpen:!1},React.createElement(n.SelectControl,{label:_x("Rating","The age rating for this video.","jetpack-videopress-pkg"),value:s??"",options:[{label:_x("G",'Video rating for "General Audiences".',"jetpack-videopress-pkg"),value:a.x4},{label:_x("PG-13",'Video rating for "Parental Guidance", unsuitable for children under 13.',"jetpack-videopress-pkg"),value:a.pf},{label:_x("R",'Video rating for "Restricted", not recommended for children under 17.',"jetpack-videopress-pkg"),value:a.Gr}],onChange:e=>{t({rating:e})},disabled:!o}),React.createElement(n.SelectControl,{label:__("Privacy","jetpack-videopress-pkg"),onChange:e=>{const n={};n.isPrivate=e!==p.value?e===f.value:r,n.privacySetting=Number(e),t(n)},value:String(i),options:[p,d,f],disabled:!o}),React.createElement(n.ToggleControl,{label:__("Allow download","jetpack-videopress-pkg"),checked:c,onChange:e=>{t({allowDownload:e})},disabled:!o}),React.createElement(n.ToggleControl,{label:__("Show video sharing menu","jetpack-videopress-pkg"),checked:l,onChange:e=>{t({displayEmbed:e})},help:__("Gives viewers the option to share the video link and HTML embed code","jetpack-videopress-pkg"),disabled:!o}))}},6458:(e,t,r)=>{"use strict";r.d(t,{Z:()=>a});var n=r(2175),o=r(2917);const a=({attributes:e,onUploadFileStart:t,onSelectVideoFromLibrary:r,onSelectURL:a})=>{const i=e.isPrivate?"https://video.wordpress.com/v":"https://videopress.com/v";return React.createElement(n.MediaReplaceFlow,{mediaId:e.id,handleUpload:!1,accept:"video/*",allowedTypes:o.T,onSelect:function(e){e?.[0]?.name&&e?.[0]?.size&&e?.[0]?.type?t(e[0]):r(e)},mediaURL:`${i}/${e.guid}`,onSelectURL:a})}},7898:(e,t,r)=>{"use strict";r.d(t,{Z:()=>y});var n=r(5609),o=r(7798),a=r(9818),i=r(9307),s=r(5736),c=r(7659),l=r(951),u=r.n(l),p=r(515),d=r(2198),f=r(520),m=r(879);const __=s.__,h=u()("videopress:tracks:tracks-control");function v({track:e,guid:t,onDelete:r}){const[o,a]=(0,i.useState)(!1),{kind:s,label:c,srcLang:l}=e;return React.createElement("div",{className:"video-tracks-control__track-item "+(o?"is-deleting":"")},React.createElement("div",{className:"video-tracks-control__track-item-label"},React.createElement("strong",null,c),React.createElement("span",{className:"video-tracks-control__track-item-kind"},s,l?.length?` [${l}]`:"")),React.createElement(n.Button,{variant:"link",isDestructive:!0,onClick:()=>{a(!0),(0,d.qL)(e,t).then((()=>{a(!1),r?.(e)}))},disabled:o},__("Delete","jetpack-videopress-pkg")))}function g({tracks:e,guid:t,onTrackListUpdate:r}){if(!e?.length)return React.createElement(n.MenuGroup,null,React.createElement("div",{className:"video-tracks-control__track_list__no-tracks"},__("Tracks can be subtitles, captions, chapters, or descriptions. They help make your content more accessible to a wider range of users.","jetpack-videopress-pkg")));const o=(0,i.useCallback)((t=>{const n=[...e].filter((e=>e!==t));r(n)}),[e]);return React.createElement(n.MenuGroup,{className:"video-tracks-control__track_list",label:__("Text tracks","jetpack-videopress-pkg")},e.map(((e,r)=>React.createElement(v,{key:`${e.kind}-${r}`,track:e,guid:t,onDelete:o}))))}function y({attributes:e,setAttributes:t}){const{tracks:r,guid:s}=e,[l,u]=(0,i.useState)(!1),[v,y]=(0,i.useState)(""),b=(0,a.useDispatch)(o.store).invalidateResolution,w=(0,p.pg)(s,e),k=(0,i.useCallback)((e=>{(0,d.nb)(e,s).then((n=>{if(n?.error)return h("catch at regular response",n),void y(`Track error: ${n?.message||n.error}`);const o={...e,src:n};delete o.tmpFile;const a=r.findIndex((e=>e.kind===o.kind&&e.srcLang===o.srcLang)),i=[...r];a>-1?(h("new track already exists, replacing it"),i[a]=o):(h("new track does not exist, adding it"),i.push(o)),t({tracks:i}),u(!1),b("getEmbedPreview",[w])})).catch((e=>{h("catch at catch"),y(`Track error: ${e?.message||e.error}`)}))}),[r]),_=(0,i.useCallback)((e=>{t({tracks:e}),b("getEmbedPreview",[w])}),[r]),E=(0,i.useCallback)((()=>{y(""),u(!0)}),[]);return React.createElement(n.ToolbarDropdownMenu,{icon:f.u,label:__("Text tracks","jetpack-videopress-pkg"),popoverProps:{variant:"toolbar"}},(()=>l?React.createElement(m.Z,{onCancel:()=>{u(!1)},onSave:k,tracks:r,errorMessage:v}):React.createElement(React.Fragment,null,React.createElement(g,{tracks:r,guid:s,onTrackListUpdate:_}),React.createElement(n.MenuGroup,{label:__("Add tracks","jetpack-videopress-pkg"),className:"video-tracks-control"},React.createElement(n.MenuItem,{icon:c.Z,onClick:E},__("Upload track","jetpack-videopress-pkg"))))))}},879:(e,t,r)=>{"use strict";r.d(t,{Z:()=>m});var n=r(2175),o=r(5609),a=r(9818),i=r(9307),s=r(5736),c=r(951),l=r.n(c);const __=s.__,u="subtitles",p=".vtt,text/vtt",d=[{label:__("Subtitles","jetpack-videopress-pkg"),value:"subtitles"},{label:__("Captions","jetpack-videopress-pkg"),value:"captions"},{label:__("Descriptions","jetpack-videopress-pkg"),value:"descriptions"},{label:__("Chapters","jetpack-videopress-pkg"),value:"chapters"},{label:__("Metadata","jetpack-videopress-pkg"),value:"metadata"}],f=l()("videopress:tracks:track-form");function m({onCancel:e,onSave:t,tracks:r,errorMessage:c}){const[l,m]=(0,i.useState)(!1),[h,v]=(0,i.useState)(!1),[g,y]=(0,i.useState)(""),[b,w]=(0,i.useState)(!1),[k,_]=(0,i.useState)({kind:u,srcLang:"",label:"",tmpFile:null});f("props.errorMessage",c);const E=(0,i.useCallback)(((e,t)=>{f("updateTrack",e,t),"tmpFile"===e&&y(""),_((r=>({...r,[e]:t})))}),[k]);(0,i.useEffect)((()=>{const e=r.some((e=>e.srcLang===k.srcLang&&e.kind===k.kind));v(e)}),[k,r]),(0,i.useEffect)((()=>{y(c),c&&m(!1)}),[c]);const R=k.tmpFile?.name,C=(0,a.useSelect)((e=>e(n.store).getSettings().mediaUpload),[]),S=(0,i.useCallback)((()=>{m(!0),y(""),t(k)}),[k]),P=(0,i.useCallback)((e=>{if(E("srcLang",e),e?.length>5)return y(__("Language must be five characters or less.","jetpack-videopress-pkg"));y(c||"")}),[c]);if(!C)return null;const j=(0,s.sprintf)(/* translators: %s: The allowed file types to be uploaded as a video text track." */
__("Add a new text track to the video. Allowed formats: %s","jetpack-videopress-pkg"),p);return f("error",g),React.createElement(o.MenuGroup,{className:"video-tracks-control__track-form",label:__("Upload track","jetpack-videopress-pkg")},React.createElement("div",{className:"video-tracks-control__track-form-container"},React.createElement("div",{className:"video-tracks-control__track-form-upload-file"},React.createElement("div",{className:"video-tracks-control__track-form-upload-file-label"},React.createElement("span",null,__("File","jetpack-videopress-pkg"),":"),R&&React.createElement("strong",null,R),React.createElement(n.MediaUploadCheck,null,React.createElement(o.FormFileUpload,{onChange:e=>{const t=e.target.files;t?.length&&E("tmpFile",t[0])},accept:p,render:({openFileDialog:e})=>React.createElement(o.Button,{variant:"link",onClick:()=>{e()}},__("Select track","jetpack-videopress-pkg"))}))),React.createElement("div",{className:"video-tracks-control__track-form-upload-file-help"},j)),React.createElement("div",{className:"video-tracks-control__track-form-label-language"},React.createElement(o.TextControl,{onChange:e=>E("label",e),label:__("Label","jetpack-videopress-pkg"),value:k.label,help:__("Title of track","jetpack-videopress-pkg"),disabled:l}),React.createElement(o.TextControl,{className:"video-tracks-control__track-form-language-tag",label:__("Source language","jetpack-videopress-pkg"),value:k.srcLang,onChange:P,help:__("Language (en, fr, etc.)","jetpack-videopress-pkg"),disabled:l})),React.createElement(o.SelectControl,{options:d,value:k.kind,label:/* translators: %s: The kind of video text track e.g: "Subtitles, Captions" */
__("Kind","jetpack-videopress-pkg"),onChange:e=>E("kind",e),disabled:l}),g&&React.createElement(o.Notice,{status:"error",isDismissible:!1},g),React.createElement("div",{className:"video-tracks-control__track-form-buttons-container "+(h?" track-exists":"")},h&&React.createElement(o.ToggleControl,{className:"video-tracks-control__track-form-toggle",label:__("Track exists. Replace?","jetpack-videopress-pkg"),checked:b,onChange:w}),React.createElement(o.Button,{isBusy:l,variant:"secondary",disabled:!k.tmpFile||l||h&&!b||!!g,onClick:S},__("Save","jetpack-videopress-pkg")),React.createElement(o.Button,{variant:"link",onClick:e},__("Cancel","jetpack-videopress-pkg")))))}},4744:(e,t,r)=>{"use strict";r.d(t,{Z:()=>y});var n=r(6895),o=r(6989),a=r.n(o),i=r(2175),s=r(5609),c=r(9307),l=r(5736),u=r(9272),p=r(1207),d=r(515),f=r(2917),m=r(3414),h=r(520),v=r(125),g=r(2374);const __=l.__,y=(0,s.withNotices)((({attributes:e,setAttributes:t,noticeUI:r,noticeOperations:o,handleDoneUpload:l,fileToUpload:y,isReplacing:b,onReplaceCancel:w})=>{const[k,_]=(0,c.useState)(!1),[E,R]=(0,c.useState)(!1),[C,S]=(0,c.useState)(!1),[P,j]=(0,c.useState)(!1);(0,c.useEffect)((()=>{y&&M(y)}),[y]);const[x,T]=(0,c.useState)(null),[U,O]=(0,c.useState)([]),N=(0,c.useCallback)((function(...e){O(e)}),[]),[A,L]=(0,c.useState)(null),Z=(0,c.useCallback)((function(e){if(e?.originalResponse)try{const t=e?.originalResponse?.getBody?.(),r=JSON.parse(t);return void L(r)}catch{}L(e)}),[]),{uploadHandler:D,resumeHandler:F,error:I}=(0,u.Z)({onError:Z,onProgress:N,onSuccess:R});function B(e,t){const{guid:r,url:n}=(0,d.Yv)(e);if(!r)return void L({data:{message:__("Invalid VideoPress URL","jetpack-videopress-pkg")}});const o=(0,d.qD)(n);l({...o,guid:r,id:t})}const M=e=>{A&&Z(null),T(e),N(0,e.size),S(!0),D(e)},H=()=>{if(!F)return;F[k?"start":"abort"](),_(!k)},z=function(){F.abort(),w()};if("owner_not_connected"===I?.code){const e=(0,c.createInterpolateElement)(__("Connect your site to use the VideoPress video block.","jetpack-videopress-pkg"),{connectLink:React.createElement("a",{href:I?.data?.connect_url,rel:"noreferrer noopener"}),moreAboutVideoPressLink:React.createElement(s.ExternalLink,{href:(0,n.Z)("jetpack-videopress")})});return React.createElement(m.l,{errorMessage:e},React.createElement(s.Button,{key:"videopress-connect-user",variant:"primary",href:I?.data?.connect_url},__("Connect","jetpack-videopress-pkg")))}if(A){const e=()=>{M(x)},t=()=>{T(null),N([]),Z(null),S(!1)};return React.createElement(v.Z,{onRetry:e,onCancel:t,errorData:A})}if(C){const r=U[0]/U[1]*100;return React.createElement(g.Z,{attributes:e,setAttributes:t,file:x,progress:r,paused:k,uploadedVideoData:E,onPauseOrResume:H,onReplaceCancel:z,isReplacing:b,onDone:l,supportPauseOrResume:!!F})}return P?React.createElement(m.l,{disableInstructions:!0},React.createElement("div",{className:"loading-wrapper"},React.createElement(s.Spinner,null),React.createElement("span",null,__("Loading…","jetpack-videopress-pkg")))):React.createElement(i.MediaPlaceholder,{handleUpload:!1,className:"is-videopress-placeholder",icon:React.createElement(i.BlockIcon,{icon:h.l}),labels:{title:__("VideoPress","jetpack-videopress-pkg"),instructions:__("Embed a video from your media library or upload a new one with VideoPress.","jetpack-videopress-pkg")},onSelect:function(e){if(e=e?.[0]?e[0]:e,e?.name&&e?.size&&e?.type)M(e);else if(e.videopress_guid){B(Array.isArray(e.videopress_guid)?e.videopress_guid[0]:e.videopress_guid,e?.id)}else{if(e.id){const t=`videopress/v1/upload/${e.id}`;return j(!0),void a()({path:t,method:"GET"}).then((t=>{var r;j(!1),"new"===t.status||"resume"===t.status?(T(e),N(t.file_size,t.file_size),S(!0),r=e.id,(0,p.R2)(r).then((e=>{R(e)})).catch((e=>{L(e)}))):"uploaded"===t.status?B(t.uploaded_video_guid):L({data:{message:t.message?t.message:__("Error selecting video. Please try again.","jetpack-videopress-pkg")}})})).catch((e=>{j(!1),L({data:{message:e.message}})}))}L({data:{message:__("Please select a video from Library or upload a new one","jetpack-videopress-pkg")}})}},onSelectURL:B,accept:"video/*",allowedTypes:f.T,value:e,notices:r,onError:function(e){o.removeAllNotices(),o.createErrorNotice(e)}})}))},7215:(e,t,r)=>{"use strict";r.d(t,{Z:()=>h});var n=r(2175),o=r(5609),a=r(9307),i=r(5736),s=r(1074),c=r(3228),l=r(2346),u=r(7535);const __=i.__,p=["image"],d=({videoPosterImageUrl:e})=>React.createElement("div",{className:"uploading-editor__poster-image"},e?React.createElement("img",{src:e,alt:"Poster"}):React.createElement("span",null,"No Poster Selected")),f=({file:e,videoPosterImageData:t,onVideoFrameSelected:r})=>{const n=Boolean(t?.url),o=(0,a.useRef)(e?.url??URL.createObjectURL(e));return React.createElement("div",{className:(0,c.Z)("uploading-editor__poster-container")},React.createElement(u.Z,{src:o?.current,onVideoFrameSelected:r,className:(0,c.Z)({"uploading-editor__hide":n})}),n&&React.createElement(React.Fragment,null,React.createElement(d,{videoPosterImageUrl:t?.url}),React.createElement(s.Z,{className:"uploading-editor__play-icon",icon:l.Z})))},m=({hasPoster:e,onSelectPoster:t,onRemovePoster:r})=>e?React.createElement(n.MediaUpload,{title:__("Select Poster Image","jetpack-videopress-pkg"),onSelect:t,allowedTypes:p,render:({open:e})=>React.createElement("div",{className:"uploading-editor__poster-buttons"},React.createElement(o.Button,{onClick:r,variant:"secondary",isDestructive:!0},__("Remove Poster Image","jetpack-videopress-pkg")),React.createElement(o.Button,{variant:"secondary",onClick:e},__("Select Poster Image","jetpack-videopress-pkg")))}):React.createElement("span",{className:"uploading-editor__scrubber-help"},__("This is how the video will look. Use the slider to choose a poster image or change it from the block settings.","jetpack-videopress-pkg")),h=e=>{const{file:t,onSelectPoster:r,onRemovePoster:n,videoPosterImageData:a,onVideoFrameSelected:i}=e;return React.createElement("div",{className:"uploading-editor"},React.createElement(o.BaseControl,{label:__("Video poster (optional)","jetpack-videopress-pkg")},React.createElement(f,{file:t,videoPosterImageData:a,onVideoFrameSelected:i}),React.createElement(m,{hasPoster:Boolean(a),onSelectPoster:r,onRemovePoster:n})))}},125:(e,t,r)=>{"use strict";r.d(t,{Z:()=>i});var n=r(5609),o=r(5736),a=r(3414);const __=o.__,i=({errorData:e,onRetry:t,onCancel:r})=>{const o=(e=>{if(!e)return"";let t=e?.data?.message||__("Failed to upload your video. Please try again.","jetpack-videopress-pkg");return"Invalid Mime"===t&&(t=React.createElement(React.Fragment,null,__("The format of the video you uploaded is not supported.","jetpack-videopress-pkg")," ",React.createElement(n.ExternalLink,{href:"https://wordpress.com/support/videopress/recommended-video-settings/",target:"_blank",rel:"noreferrer"},__("Check the recommended video settings.","jetpack-videopress-pkg")))),t})(e);return React.createElement(a.l,{errorMessage:o,onNoticeRemove:r},React.createElement("div",{className:"videopress-uploader__error-actions"},React.createElement(n.Button,{variant:"primary",onClick:t},__("Try again","jetpack-videopress-pkg")),React.createElement(n.Button,{variant:"secondary",onClick:r},__("Cancel","jetpack-videopress-pkg"))))}},2374:(e,t,r)=>{"use strict";r.d(t,{Z:()=>_});var n=r(6989),o=r.n(n),a=r(5609),i=r(4333),s=r(9307),c=r(1975),l=r(5736),u=r(951),p=r.n(u),d=r(861),f=r.n(d),m=r(5134),h=r(6650),v=r(3897),g=r(515),y=r(3414),b=r(7215);const __=l.__,w=p()("videopress:block:uploader"),k=({setAttributes:e,videoData:t,onDone:r})=>{const[n,a]=(0,s.useState)(!1),[c,l]=(0,s.useState)(null),[u,p]=(0,s.useState)(null),{title:d}=t,f=t?.guid,g=(0,v.Z)(f),y=(0,h.Z)(f),b=(0,m.Z)(t?.id),w=({data:t})=>{t?.generating?setTimeout((()=>{new Promise(((e,t)=>{y(f).then((t=>e(t))).catch((()=>{o()({path:`/videos/${f}/poster`,apiNamespace:"rest/v1.1",global:!0,method:"GET"}).then((t=>e(t))).catch((e=>t(e)))}))})).then((e=>w(e)))}),2e3):t?.poster&&e({poster:t?.poster})},k=(0,i.useDebounce)((e=>{var t;t=e,new Promise(((e,r)=>{g(t).then((t=>{w(t),e()})).catch((()=>{o()({path:`/videos/${f}/poster`,apiNamespace:"rest/v1.1",method:"POST",global:!0,data:t}).then((()=>{e()})).catch((e=>{r(e)}))}))}))}),1e3);return(0,s.useEffect)((()=>{if(f)return u?k({poster_attachment_id:u?.id}):void(null!=c&&k({at_time:c,is_millisec:!0}))}),[u,c,f]),[e=>{l(e),p(null)},e=>{p(e)},()=>{p(null)},()=>{a(!0);const e=[];d&&e.push(b({title:d})),Promise.allSettled(e).then((()=>{a(!1),r(t)}))},u,n]},_=({attributes:e,setAttributes:t,progress:r,file:n,paused:o,uploadedVideoData:i,onPauseOrResume:u,onDone:p,supportPauseOrResume:d,isReplacing:m,onReplaceCancel:h})=>{const[v,_,E,R,C,S]=k({setAttributes:t,videoData:{...i,title:e.title},onDone:p}),[P,j]=(0,s.useState)(!0);(0,s.useEffect)((()=>{i&&!S&&P&&(w("Waiting for some time before enabling the DONE button..."),setTimeout((()=>{w("Done, enabling the DONE button now..."),j(!1)}),2500))}),[i,S]);const x=Math.round(r),T={width:`${x}%`},U=__("Resume","jetpack-videopress-pkg"),O=__("Pause","jetpack-videopress-pkg"),N=n?.filesizeHumanReadable??f()(n?.size),{title:A}=e,L=(0,g.K8)((0,c.escapeHTML)(n?.name));return React.createElement(y.l,{disableInstructions:!0},React.createElement(a.TextControl,{label:__("Video title","jetpack-videopress-pkg"),className:"uploading-editor__title",onChange:e=>t({title:e}),value:A,placeholder:L}),React.createElement(b.Z,{file:n,onSelectPoster:_,onRemovePoster:E,onVideoFrameSelected:v,videoPosterImageData:C}),React.createElement("div",{className:"videopress-uploader-progress"},x<100?React.createElement(React.Fragment,null,React.createElement("div",{className:"videopress-uploader-progress__file-info"},React.createElement("div",{className:"videopress-uploader-progress__progress"},React.createElement("div",{className:"videopress-uploader-progress__progress-loaded",style:T})),React.createElement("div",{className:"videopress-upload__percent-complete"},(0,l.sprintf)(/* translators: Placeholder is an upload progress percenatage number, from 0-100. */
-__("Uploading (%1$s%%)","jetpack-videopress-pkg"),x)),React.createElement("div",{className:"videopress-uploader-progress__file-size"},N)),m&&React.createElement("div",{className:"videopress-uploader-progress__actions"},React.createElement(a.Button,{onClick:h,variant:"tertiary",isDestructive:!0},__("Cancel","jetpack-videopress-pkg"))),React.createElement("div",{className:"videopress-uploader-progress__actions"},x<100&&React.createElement(a.Button,{variant:"tertiary",onClick:u,disabled:!d},o?U:O))):React.createElement(React.Fragment,null,P?React.createElement("span",null,__("Finishing up …","jetpack-videopress-pkg")," 🎬"):React.createElement("span",null,__("Upload Complete!","jetpack-videopress-pkg")," 🎉"),React.createElement(a.Button,{variant:"primary",onClick:R,disabled:P,isBusy:P},__("Done","jetpack-videopress-pkg")))))}},2917:(e,t,r)=>{"use strict";r.d(t,{T:()=>n,U:()=>o});const n=["video"],o=["image"]},6429:(e,t,r)=>{"use strict";r.d(t,{Z:()=>l});var n=r(2674),o=r.n(n),a=r(2175),i=r(3228),s=r(515),c=r(4874);const l=[{attributes:{autoplay:{type:"boolean"},title:{type:"string"},description:{type:"string"},caption:{type:"string",source:"html",selector:"figcaption"},controls:{type:"boolean",default:!0},loop:{type:"boolean"},maxWidth:{type:"string",default:"100%"},muted:{type:"boolean"},playsinline:{type:"boolean"},preload:{type:"string",default:"metadata"},seekbarPlayedColor:{type:"string",default:""},seekbarLoadingColor:{type:"string",default:""},seekbarColor:{type:"string",default:""},useAverageColor:{type:"boolean",default:!0},id:{type:"number"},guid:{type:"string"},src:{type:"string"},cacheHtml:{type:"string",default:""},poster:{type:"string"},posterData:{type:"object",default:{}},videoRatio:{type:"number"},tracks:{type:"array",items:{type:"object"},default:[]},privacySetting:{type:"number",default:1},allowDownload:{type:"boolean",default:!0},displayEmbed:{type:"boolean",default:!0},rating:{type:"string"},isPrivate:{type:"boolean"},isExample:{type:"boolean",default:!1},duration:{type:"number"}},supports:{align:!0,anchor:!0},save:function({attributes:e}){const{align:t,autoplay:r,caption:n,loop:l,muted:u,controls:p,playsinline:d,preload:f,useAverageColor:m,seekbarColor:h,seekbarLoadingColor:v,seekbarPlayedColor:g,guid:y,maxWidth:b,poster:w,posterData:k}=e,_=a.useBlockProps.save({className:(0,i.Z)("wp-block-jetpack-videopress","jetpack-videopress-player",{[`align${t}`]:t})}),E=(0,c.zQ)(),R=E?r||k.previewOnHover:r,C=E?u||k.previewOnHover:u,S=(0,s.pg)(y,{autoplay:R,controls:p,loop:l,muted:C,playsinline:d,preload:f,seekbarColor:h,seekbarLoadingColor:v,seekbarPlayedColor:g,useAverageColor:m,poster:w}),P={};return b&&b.length>0&&"100%"!==b&&(P.maxWidth=b,P.margin="auto"),React.createElement("figure",o()({},_,{style:P}),S&&React.createElement("div",{className:"jetpack-videopress-player__wrapper"},`\n${S}\n`),!a.RichText.isEmpty(n)&&React.createElement(a.RichText.Content,{tagName:"figcaption",value:n}))}}]},3414:(e,t,r)=>{"use strict";r.d(t,{Z:()=>z,l:()=>H});var n=r(2674),o=r.n(n),a=r(1313),i=r(2175),s=r(4981),c=r(5609),l=r(7798),u=r(9818),p=r(9307),d=r(5736),f=r(3805),m=r(3228),h=r(951),v=r.n(h),g=r(8232),y=r(515),b=r(5417),w=r(1584),k=r(8038),_=r(6397),E=r(7159),R=r(4706),C=r(520),S=r(6681),P=r(7153),j=r(723),x=r(4874),T=r(8864),U=r(6458),O=r(7898),N=r(4744),A=r(1471);const __=d.__,L=v()("videopress:video:edit"),{myJetpackConnectUrl:Z,jetpackVideoPressSettingUrl:D}=window?.videoPressEditorState||{},F=(0,g.Hn)(),I=(0,g.$U)(),B=(0,g.yD)(),M=10,H=(0,c.withNotices)((function({children:e,errorMessage:t,noticeUI:r,noticeOperations:n,instructions:o=A.WL,disableInstructions:a}){return(0,p.useEffect)((()=>{t&&(n.removeAllNotices(),n.createErrorNotice(t))}),[t,n]),React.createElement(c.Placeholder,{icon:React.createElement(i.BlockIcon,{icon:C.l}),label:A.TN,instructions:a?null:o,notices:r},e)}));function z({attributes:e,setAttributes:t,isSelected:r,clientId:n}){const{autoplay:d,loop:h,muted:v,controls:g,playsinline:C,preload:A,useAverageColor:z,seekbarColor:V,seekbarLoadingColor:q,seekbarPlayedColor:$,guid:G,cacheHtml:J,poster:W,posterData:K,align:Y,videoRatio:X,tracks:Q,src:ee,caption:te,isExample:re}=e,ne=(0,y.pg)(G,{autoplay:d||K.previewOnHover,controls:g,loop:h,muted:v||K.previewOnHover,playsinline:C,preload:A,seekbarColor:V,seekbarLoadingColor:q,seekbarPlayedColor:$,useAverageColor:z,poster:W}),[oe,ae]=(0,p.useState)(!1),ie=Q?.filter((e=>"chapters"===e.kind))?.[0],[se,ce]=(0,p.useState)(!!te),{videoData:le,isRequestingVideoData:ue,error:pe,isOverwriteChapterAllowed:de,isGeneratingPoster:fe,videoBelongToSite:me}=(0,w.v)(e,t),{filename:he,private_enabled_for_site:ve}=le,{preview:ge,isRequestingEmbedPreview:ye}=(0,b.u)(ne),{html:be,width:we,height:ke}=ge;(0,p.useEffect)((()=>{be&&be!==J&&t({cacheHtml:be})}),[be,J,t]);const _e=be||J;(0,p.useEffect)((()=>{if(!we||!ke)return;const e=ke/we*100;e!==X&&t({videoRatio:e})}),[X,we,ke,t]);const Ee=(0,u.useDispatch)(l.store).invalidateResolution,Re=(0,p.useCallback)((()=>{Ee("getEmbedPreview",[ne])}),[ne,Ee]),[Ce,Se]=(0,p.useState)(0),Pe=(0,p.useRef)();function je(){Pe?.current&&(Pe.current=clearInterval(Pe.current))}(0,p.useEffect)((()=>Ce>=M?(L("Generating preview ➡ attempts number reached out 😪",Ce),je()):ne?ye?(L("Generating preview ➡ Requesting… ⌛"),je()):ge.html?(L("Generating preview ➡ Preview achieved 🎉 %o",ge),je()):Pe?.current?void L("Generating preview ➡ Process already requested ⌛"):(Pe.current=setTimeout((()=>{if(ge.html)return L("Generating preview ➡ Preview already achieved 🎉 %o",ge),void Se(0);Se((e=>e+1)),L("Generating preview ➡ Not achieved so far. Start attempt %o 🔥",Ce+1),Re()}),2e3),je):(L("Generating preview ➡ No URL Provided 👋🏻"),je())),[Ce,Pe,Re,ge,ne,ye]);const{className:xe,...Te}=(0,i.useBlockProps)({className:"wp-block-jetpack-videopress"}),[Ue,Oe]=(0,p.useState)(!G),[Ne,Ae]=(0,p.useState)(null);(0,p.useEffect)((()=>{if(!ee)return;if(!(0,a.isBlobURL)(ee))return;const e=(0,a.getBlobByURL)(ee);e&&(0,k.N)(e)&&(t({src:void 0}),Oe(!0),Ae(e))}),[ee]);const{replaceBlock:Le}=(0,u.useDispatch)(i.store),[Ze,De]=(0,p.useState)({isReplacing:!1,prevAttrs:{}}),Fe=()=>{t(Ze.prevAttrs),De({isReplacing:!1,prevAttrs:{}}),Oe(!1)};if(re)return React.createElement("img",{style:{width:"100%",height:"auto",backgroundSize:"cover"},className:"wp-block-jetpack-videopress__example",src:ee,alt:te});if(Ue){const r=r=>{if(Oe(!1),Ze.isReplacing){const t={...e,...r};return delete t.poster,De({isReplacing:!1,prevAttrs:{}}),void Le(n,(0,s.createBlock)("videopress/video",t))}t(r)};return React.createElement("div",o()({},Te,{className:xe}),React.createElement(React.Fragment,null,React.createElement(_.Z,{isConnected:I,isModuleActive:B||F,isConnecting:oe,onConnect:()=>{if(ae(!0),!F)return window.location.href=D;window.location.href=Z}}),React.createElement(N.Z,{setAttributes:t,attributes:e,handleDoneUpload:r,fileToUpload:Ne,isReplacing:Ze?.isReplacing,onReplaceCancel:Fe})))}if((ye||!ge.html)&&Ce>0&&Ce=M&&!ge.html)return React.createElement("div",o()({},Te,{className:xe}),React.createElement(H,{errorMessage:__("Impossible to get a video preview after ten attempts.","jetpack-videopress-pkg"),onNoticeRemove:Ee},React.createElement("div",{className:"videopress-uploader__error-actions"},React.createElement(c.Button,{variant:"primary",onClick:Ee},__("Try again","jetpack-videopress-pkg")),React.createElement(c.Button,{variant:"secondary",onClick:()=>{t({src:void 0,id:void 0,guid:void 0})}},__("Cancel","jetpack-videopress-pkg")))));const Ie=__("Remove caption","jetpack-videopress-pkg"),Be=__("Add caption","jetpack-videopress-pkg");return React.createElement("div",o()({},Te,{className:(0,m.Z)(xe,{[`align${Y}`]:Y,"is-updating-preview":!be})}),React.createElement(i.BlockControls,{group:"block"},React.createElement(c.ToolbarButton,{onClick:()=>{ce(!se),se&&te&&t({caption:void 0})},icon:f.Z,"aria-pressed":se,label:se?Ie:Be}),React.createElement(j.Z,{attributes:e,setAttributes:t,clientId:n}),React.createElement(O.Z,{attributes:e,setAttributes:t})),React.createElement(i.BlockControls,{group:"other"},React.createElement(U.Z,{setAttributes:t,attributes:e,onUploadFileStart:r=>{De({isReplacing:!0,prevAttrs:e}),Oe(!0),t({id:null,guid:null,cacheHtml:"",videoRatio:null}),Ae(r)},onSelectVideoFromLibrary:e=>{const r=Array.isArray(e.videopress_guid)?e.videopress_guid[0]:e.videopress_guid;r?t({guid:r,id:e.id,src:e.url,title:e.title,description:e.description}):L("No media guid provided")},onSelectURL:e=>{const{guid:r,url:n}=(0,y.Yv)(e);r?t({guid:r,src:n}):L("Invalid URL. No video GUID provided")}})),React.createElement(i.InspectorControls,null,React.createElement(R.Z,{filename:he,chapter:ie,isAutoGeneratedChapter:de,updateError:pe,isRequestingVideoData:ue,videoBelongToSite:me,attributes:e,setAttributes:t}),React.createElement(S.Z,{attributes:e,setAttributes:t,isRequestingVideoData:ue}),React.createElement(x.ZP,{clientId:n,attributes:e,setAttributes:t,isGeneratingPoster:fe,videoBelongToSite:me}),React.createElement(T.Z,{attributes:e,setAttributes:t,isRequestingVideoData:ue,privateEnabledForSite:ve,videoBelongToSite:me})),React.createElement(i.InspectorControls,{group:"color"},React.createElement(E.Z,{clientId:n,attributes:e,setAttributes:t,isRequestingVideoData:ue})),React.createElement(_.Z,{isModuleActive:B||F,isConnected:I,isConnecting:oe,onConnect:()=>{if(ae(!0),!F)return window.location.href=D;window.location.href=Z}}),React.createElement(P.Z,{showCaption:se,html:_e,isRequestingEmbedPreview:ye,attributes:e,setAttributes:t,isSelected:r,preview:ge}))}},1471:(e,t,r)=>{"use strict";r.d(t,{TN:()=>d,WL:()=>f});var n=r(4981),o=r(2030),a=r(4205),i=r(520),s=r(6429),c=r(3414),l=r(9892),u=r(5147);r(8921);const{name:p,title:d,description:f,attributes:m}=a;(0,n.registerBlockType)(p,{edit:c.Z,title:d,save:()=>null,icon:i.l,attributes:m,example:{attributes:{src:(0,o.Z)(u),isExample:!0}},transforms:l.Z,deprecated:s.Z})},9892:(e,t,r)=>{"use strict";r.d(t,{Z:()=>u});var n=r(1313),o=r(2175),a=r(4981),i=r(9818),s=r(3228),c=r(515),l=r(8038);const u={from:[{type:"files",isMatch:e=>!(!e||!e.length)&&e.some(l.N),priority:8,transform:e=>(0,l.W)(e).map((e=>(0,a.createBlock)("videopress/video",{src:(0,n.createBlobURL)(e)})))},{type:"block",blocks:["core/embed"],isMatch:e=>"videopress"===e.providerNameSlug&&(0,c.Zx)(e?.url),transform:e=>{const{url:t,providerNameSlug:r}=e,n=(0,c.Zx)(t);if(!("videopress"===r&&!!n))return(0,a.createBlock)("core/embed",e);return e.className=e.className?.replace(/(wp-embed-aspect-\d+-\d+)|(wp-has-aspect-ratio)/g,"").trim(),(0,a.createBlock)("videopress/video",{guid:n,src:t})}},{type:"raw",isMatch:e=>{const{textContent:t}=e;return!!t&&(0,c.Di)(t.trim())},transform:e=>{const{textContent:t}=e;if(!t)return!1;const r=t.trim(),n=(0,c.Zx)(r),o=(0,c.qD)(r);return!!n&&(0,a.createBlock)("videopress/video",{guid:n,...o})}}],to:[{type:"block",blocks:["core/embed"],isMatch:e=>e?.src||e?.guid,transform:e=>{const{updateBlockAttributes:t}=(0,i.dispatch)(o.store),{getBlockAttributes:r}=(0,i.select)(o.store),{guid:n,src:l,className:u}=e,{url:p}=(0,c.Yv)(n);if(!(l||p))return(0,a.createBlock)("core/embed");const d=(0,a.createBlock)("core/embed",{allowResponsive:!0,providerNameSlug:"videopress",responsive:!0,type:"video",url:p}),{clientId:f}=d;return setTimeout((()=>{const{className:e}=r(f)||{},n=(0,s.Z)(u,e);t(f,{className:n})}),100),d}}]}},8921:(e,t,r)=>{"use strict";var n=r(4981),o=r(2694);(0,o.addFilter)("blocks.registerBlockType","videopress/core-embed/handle-representation",((e,t)=>("core/embed"!==t||(e=>{"variations"in e&&"object"==typeof e.variations&&(0,n.getBlockType)("videopress/video")&&e.variations.some((e=>"videopress"===e.name&&(e.scope=[],!0)))})(e),e)))},5417:(e,t,r)=>{"use strict";r.d(t,{u:()=>i});var n=r(7798),o=r(9818);const a={html:null,width:null,height:null,thumbnail_height:null,thumbnail_width:null,title:null,version:"1.0",type:"video",provider_name:"VideoPress",provider_url:"https://videopress.com"},i=e=>(0,o.useSelect)((t=>e?{preview:t(n.store).getEmbedPreview(e)||a,isRequestingEmbedPreview:t(n.store).isRequestingEmbedPreview(e)||!1}:{preview:a,isRequestingEmbedPreview:!1}),[e])},1584:(e,t,r)=>{"use strict";r.d(t,{v:()=>R});var n=r(4333),o=r(7798),a=r(9818),i=r(2238),s=r(9307),c=r(5736),l=r(951),u=r.n(l),p=r(515),d=r(2198),f=r(5178),m=r(172),h=r(2677),v=r(5304),g=r(5452),y=r(8382),b=r(610);const __=c.__,w=u()("videopress:video:use-sync-media"),k=["post_id","title","description","privacy_setting","rating","allow_download","display_embed","is_private","duration"],_={privacy_setting:"privacySetting",allow_download:"allowDownload",display_embed:"displayEmbed",is_private:"isPrivate",post_id:"id"},E=["title","privacy_setting","is_private","allow_download","display_embed"];function R(e,t){const{id:r,guid:c,isPrivate:l}=e,{videoData:u,isRequestingVideoData:R,videoBelongToSite:C}=(0,g.Z)({id:r,guid:c,skipRatingControl:!0,maybeIsPrivate:l}),[S,P]=(0,s.useState)(!1),j=(0,a.useSelect)((e=>e(i.store).isSavingPost()),[]),x=(0,n.usePrevious)(j),T=(0,a.useDispatch)(o.store).invalidateResolution,[U,O]=(0,s.useState)({}),[N,A]=(0,s.useState)(null),L=(0,s.useCallback)((e=>{O((t=>({...t,...e})))}),[]);(0,s.useEffect)((()=>{if(R)return;if(!u||0===Object.keys(u).filter((e=>k.includes(e))).length)return;const r={},n=k.reduce(((t,n)=>{if(void 0===u[n])return t;let o=u[n];"privacy_setting"===n&&(o=Number(o)),t[n]=o;const a=_[n]||(0,f.T)(n);return o!==e[a]&&(w("%o is out of sync. Updating %o attr from %o to %o ",n,a,e[a],o),r[a]=o),t}),{});if(L(n),w("Initial state: ",n),!Object.keys(n).length)return;const[o,a]=function(e,t){if(!e?.tracks)return[[],!1];const r=[];let n=!1;return Object.keys(e.tracks).forEach((o=>{for(const a in e.tracks[o]){const i=e.tracks[o][a];t.tracks.find((e=>e.kind===o&&e.srcLang===a&&e.src===i.src&&e.label===i.label))||(w("Track %o is out of sync. Set tracks attr",i.src),n=!0),r.push({src:i.src,kind:o,srcLang:a,label:i.label})}})),t.tracks.forEach((t=>{const r=e.tracks[t.kind]?.[t.srcLang];r&&r.src===t.src&&r.label===t.label||(w("Block track %o is out of sync and will be removed",t.src),n=!0)})),[r,n]}(u,e);a&&(r.tracks=o),Object.keys(r).length&&(w("Updating attributes: ",r),t(r))}),[u,R]);const Z=e.tracks.filter((e=>"chapters"===e.kind&&"en"===e.srcLang))[0]?.src;(0,s.useEffect)((()=>{(async()=>{if(Z){const e="https://videos.files.wordpress.com/"+c+"/"+Z,t=await(0,d.ss)(e,{guid:c,isPrivate:l});w("Chapter %o detected. Overwritable: %o",Z,t?"yes":"no"),P(t)}else w("Allow overwrite chapter: File does not exist"),P(!0)})()}),[Z]);const D=(0,y.Z)(r),F=!(!x||j),{isGeneratingPoster:I}=(0,b.Q)(e);return(0,s.useEffect)((()=>{if(!F)return;if(w("%o Post has been just saved. Syncing...",e?.guid),!e?.id)return void w("%o No media ID found. Impossible to sync. Bail early",e?.guid);const r=k.reduce(((t,r)=>{const n=_[r]||r,o=U[r],a=e[n];return U[r]!==e[n]&&(w("Field to sync %o: %o => %o: %o",r,o,n,a),t[r]=e[n]),t}),{});if(!Object.keys(r).length)return w("No data to sync. Bail early");w("Syncing data: ",r),D(r).then((()=>{if(L(r),r.privacy_setting){const e=2!==r.privacy_setting?1===r.privacy_setting:u.private_enabled_for_site;w("Updating isPrivate attribute: %o",e),t({isPrivate:e})}const n=(0,m.ZP)(r?.description);if(S&&e?.guid&&r?.description?.length&&(0,v.Z)(n)){w("Autogenerated chapter detected. Processing...");const n={label:__("English (auto-generated)","jetpack-videopress-pkg"),srcLang:"en",kind:"chapters",tmpFile:(0,h.ZP)(r.description)};w("Autogenerated track: %o",n),(0,d.nb)(n,e.guid).then((r=>{const o=e.tracks.findIndex((e=>"chapters"===e.kind&&"en"===e.srcLang)),a={...n,src:r},i=[...e.tracks];o>-1?(w("Updating %o auto-generated track",a.src),i[o]=a):(w("Adding auto-generated %o track",a.src),i.push(a)),t({tracks:i});const s=(0,p.pg)(e.guid,e);T("getEmbedPreview",[s])}))}else{const t=Object.keys(r).filter((e=>E.includes(e)));if(t?.length){w("Invalidate resolution because of %o",t.join(", "));const r=(0,p.pg)(e.guid,e);T("getEmbedPreview",[r])}}})).catch((t=>{w("%o Error while syncing data: %o",e?.guid,t),A(t)}))}),[F,D,L,e,U,T,k]),{forceInitialState:L,videoData:u,isRequestingVideoData:R,videoBelongToSite:C,error:N,isOverwriteChapterAllowed:S,isGeneratingPoster:I}}},8382:(e,t,r)=>{"use strict";r.d(t,{Z:()=>a});var n=r(6989),o=r.n(n);function a(e){return t=>new Promise(((r,n)=>{o()({path:"/wpcom/v2/videopress/meta",method:"POST",data:{id:e,...t}}).then((e=>{if(200!==e?.data)return n(e);r(e)})).catch(n)}))}},5452:(e,t,r)=>{"use strict";r.d(t,{Z:()=>m});var n=r(6989),o=r.n(n),a=r(9307),i=r(2629),s=r(951),c=r.n(s),l=r(8232),u=r(5955);const p=a.Platform.isNative,d=c()("videopress:video:use-video-data"),f=(0,l.b$)();function m({id:e,guid:t,skipRatingControl:r=!1,maybeIsPrivate:n=!1}){const[s,c]=(0,a.useState)({}),[l,m]=(0,a.useState)(!1),[h,v]=(0,a.useState)(!0);return(0,a.useEffect)((()=>{f||p?t&&(m(!0),async function(e=null){try{let a;for(let o=0;o<5;o++){if(a=await(0,u.B)({guid:t,isPrivate:n,token:e,skipRatingControl:r}),a.duration){d(`video duration available: ${a.duration}, retried ${o} times`,a);break}d(`video duration not yet available, retrying (${o+1})`,a),await new Promise((e=>setTimeout(e,1500)))}m(!1);const s=a.original?.split("/")?.at(-1);c({duration:a.duration,allow_download:a.allow_download,post_id:a.post_id,guid:a.guid,title:(0,i.decodeEntities)(a.title),description:(0,i.decodeEntities)(a.description),display_embed:a.display_embed,privacy_setting:a.privacy_setting,rating:a.rating,filename:s,tracks:a.tracks,is_private:a.is_private,private_enabled_for_site:a.private_enabled_for_site});try{const e=await o()({path:`/wpcom/v2/videopress/${t}/check-ownership/${a.post_id}`,method:"GET"});v("boolean"==typeof e?.["video-belong-to-site"]?e["video-belong-to-site"]:!!e?.body?.["video-belong-to-site"])}catch(e){d("Error checking if video belongs to site",e)}}catch(e){throw m(!1),new Error(e?.message??e)}}()):d("User is not connected")}),[e,t]),{videoData:s,isRequestingVideoData:l,videoBelongToSite:h}}},3145:(e,t,r)=>{"use strict";r.d(t,{H:()=>c,Z:()=>l});var n=r(4333),o=r(951),a=r.n(o),i=r(9196);const s=a()("videopress:use-video-player"),c=e=>{const t=e?.current?.querySelector("iframe.components-sandbox");return t?.contentWindow},l=(e,t,{initialTimePosition:r,wrapperElement:o,previewOnHover:a})=>{const[l,u]=(0,i.useState)(!1),p=(0,i.useRef)("not-rendered");function d(e){const{data:t={},source:n}=e,{event:o}=e?.data||{};if("videopress_loading_state"===o&&"loaded"===t.state&&(s("state: loaded"),p.current="loaded"),"videopress_playing"===o&&"loaded"===p.current&&(p.current="first-play",s("state: first-play detected"),a&&(s("pause video"),n.postMessage({event:"videopress_action_pause"},{targetOrigin:"*"}),void 0!==r&&(s("set position at time %o ",r),n.postMessage({event:"videopress_action_set_currenttime",currentTime:r/1e3},{targetOrigin:"*"}))),u(!0),p.current="ready"),"videopress_timeupdate"===o&&a){const e=t.currentTimeMs,r=a.atTime,o=a.atTime+a.duration;(eo)&&n.postMessage({event:"videopress_action_set_currenttime",currentTime:r/1e3},{targetOrigin:"*"})}}const f=!!a,m=(0,n.usePrevious)(f),h=f&&!m,v=c(e);(0,i.useEffect)((()=>{const r=c(e);if(r&&!t)return s("player is ready to listen events"),r.addEventListener("message",d),()=>{r.removeEventListener("message",d)}}),[e,t,h,a]);const g=(0,i.useCallback)((()=>{v&&l&&v.postMessage({event:"videopress_action_play"},"*")}),[e,l,v]),y=(0,i.useCallback)((()=>{v&&l&&v.postMessage({event:"videopress_action_pause"},"*")}),[e,l,v]);return(0,i.useEffect)((()=>{if(o&&f)return o.addEventListener("mouseenter",g),o.addEventListener("mouseleave",y),()=>{o.removeEventListener("mouseenter",g),o.removeEventListener("mouseleave",y)}}),[f,o,l]),(0,i.useEffect)((()=>{l&&a&&v&&v.postMessage({event:"videopress_action_set_currenttime",currentTime:a.atTime/1e3},{targetOrigin:"*"})}),[a?.atTime,l,v]),(0,i.useEffect)((()=>{l&&a&&v&&v.postMessage({event:"videopress_action_set_currenttime",currentTime:(a.atTime+a.duration)/1e3},{targetOrigin:"*"})}),[a?.duration,l,v]),{playerIsReady:l,play:g,pause:y}}},610:(e,t,r)=>{"use strict";r.d(t,{Q:()=>f});var n=r(4333),o=r(7798),a=r(9818),i=r(2238),s=r(9307),c=r(951),l=r.n(c),u=r(6279),p=r(515);const d=l()("videopress:video:use-sync-media");function f(e){const t=(0,a.useSelect)((e=>e(i.store).isSavingPost()),[]),r=!(!(0,n.usePrevious)(t)||t),c=(0,a.useDispatch)(o.store).invalidateResolution,l=(0,s.useRef)(),[f,m]=(0,s.useState)(!1);return(0,s.useEffect)((()=>{r&&l.current?"video-frame"===e?.posterData?.type&&e?.posterData?.atTime!==l.current?.posterData?.atTime&&(d("(*) %o Poster image needs to be generated %s => %s",e?.guid,l.current?.posterData?.atTime,e?.posterData?.atTime),l.current=e,(0,u.Td)(e?.guid,e.posterData.atTime),d("(*) %o Requesting poster image generation",e?.guid),m(!0)):l.current||(l.current=e)}),[r]),(0,s.useEffect)((()=>{f&&(async()=>{if(await(0,u.t2)(e?.guid)){d("(*) %o Poster image has been generated",e?.guid),m(!1);const t=(0,p.pg)(e.guid,e);c("getEmbedPreview",[t])}})()}),[f]),{isGeneratingPoster:f}}},2030:(e,t,r)=>{"use strict";r.d(t,{Z:()=>a});var n=r(6483);const{imagesURLBase:o=""}=window?.videoPressEditorState||{};function a(e){const t=(0,n.getFilename)(e);return o?`${o}${t}`:e}},8038:(e,t,r)=>{"use strict";function n(e){return!!e?.type&&e.type.startsWith("video/")}function o(e){return e.filter(n)}r.d(t,{N:()=>n,W:()=>o})},6029:(e,t,r)=>{"use strict";r.d(t,{Z:()=>c});var n=r(526),o=r(9307),a=r(5736),i=r(9196),s=r(6152);const __=a.__,c=()=>{const[e,t]=(0,i.useState)(!1);return React.createElement(React.Fragment,null,(0,o.createInterpolateElement)(__("Did you know you can now add Chapters to your videos? Learn how","jetpack-videopress-pkg"),{link:React.createElement(n.Z,{variant:"link",size:"small",onClick:()=>t(!0)})}),React.createElement(s.Z,{onClose:()=>t(!1),isOpen:e}))}},2346:(e,t,r)=>{"use strict";r.d(t,{Z:()=>o});var n=r(5609);const o=React.createElement(n.SVG,{viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},React.createElement(n.Path,{d:"M4.75725 2.075C4.60279 1.97745 4.41041 1.97489 4.25365 2.06832C4.09689 2.16174 4 2.3367 4 2.52632V21.4737C4 21.6633 4.09689 21.8383 4.25365 21.9317C4.41041 22.0251 4.60279 22.0226 4.75725 21.925L19.7573 12.4513C19.9079 12.3562 20 12.1849 20 12C20 11.8151 19.9079 11.6438 19.7573 11.5487L4.75725 2.075Z",fill:"white"}))},1875:(e,t,r)=>{"use strict";r.d(t,{Z:()=>l});var n=r(526),o=r(5609),a=r(9307),i=r(5736),s=r(9196),c=r(6152);const __=i.__,l=({className:e})=>{const[t,r]=(0,s.useState)(!1);return React.createElement(React.Fragment,null,React.createElement(o.Notice,{status:"warning",className:e,isDismissible:!1},(0,a.createInterpolateElement)(__("It seems there are some chapters, but they are incomplete. Check out the format and try again.","jetpack-videopress-pkg"),{link:React.createElement(n.Z,{variant:"link",size:"small",onClick:()=>r(!0)})})),React.createElement(c.Z,{onClose:()=>r(!1),isOpen:t}))}},6194:(e,t,r)=>{"use strict";r.d(t,{ZP:()=>g});var n=r(2674),o=r.n(n),a=r(5609),i=r(4333),s=r(9307),c=r(3228),l=r(993),u=r(4027);const p=a.useBaseControlProps||function(e){const{help:t,id:r,...n}=e,o=(0,i.useInstanceId)(a.BaseControl,"wp-components-base-control",r),s="string"==typeof t?"aria-describedby":"aria-details";return{baseControlProps:{id:o,help:t,...n},controlProps:{id:o,...t?{[s]:`${o}__help`}:{}}}},d=e=>{if(a.__experimentalNumberControl)return React.createElement(a.__experimentalNumberControl,e);const t={...e};return["spinControls","isPressEnterToChange","isDragEnabled","isShiftStepEnabled","__unstableStateReducer"].forEach((e=>delete t[e])),React.createElement(a.TextControl,t)},f=({char:e=":"})=>React.createElement("span",{className:u.Z["timestamp-control-divider"]},e),m=e=>(t,r)=>{const n={...t};return"COMMIT"!==r.type&&"PRESS_UP"!==r.type&&"PRESS_DOWN"!==r.type&&"CHANGE"!==r.type||void 0!==n.value&&(n.value=n.value.toString().padStart(e,"0")),n};function h(e,t,r){e>r&&(e=r);const n=Number.isNaN(e),o=n||void 0===t?0:Math.floor(e%1e3/Number("1e"+(3-t)));return{hh:n?0:Math.floor(e/36e5%24),mm:n?0:Math.floor(e/6e4%60),ss:n?0:Math.floor(e/1e3%60),decimal:o}}const v=({onChange:e,disabled:t,value:r,max:n,autoHideTimeInput:o=!0,decimalPlaces:a})=>{const i={value:h(r,a,n)},s=n>36e5,l=n>6e4,p=t=>o=>{if("string"!=typeof o||isNaN(parseInt(o,10))||(o=parseInt(o,10)),"hh"===t&&o>99||("mm"===t||"ss"===t)&&o>59||"decimal"===t&&o>Number(`1e${a}`)-1)return;if("string"==typeof o)return;i.value={...h(r,a,n),[t]:o};const s=i.value.decimal?i.value.decimal*Number("1e"+(3-a)):0;e?.(1e3*(3600*i.value.hh+60*i.value.mm+i.value.ss)+s)};return React.createElement("div",{className:(0,c.Z)(u.Z["timestamp-input-wrapper"],{[u.Z["is-disabled"]]:t})},(s||!o)&&React.createElement(React.Fragment,null,React.createElement(d,{className:u.Z["timestamp-control-input"],disabled:t,min:0,max:99,step:1,hideLabelFromVision:!0,spinControls:"none",placeholder:"00",isPressEnterToChange:!0,isDragEnabled:!1,isShiftStepEnabled:!1,__unstableStateReducer:m(2),value:String(i.value.hh).padStart(2,"0"),onChange:p("hh")}),React.createElement(f,null)),(l||!o)&&React.createElement(React.Fragment,null,React.createElement(d,{className:u.Z["timestamp-control-input"],disabled:t,min:0,max:59,step:1,hideLabelFromVision:!0,spinControls:"none",placeholder:"00",isPressEnterToChange:!0,isDragEnabled:!1,isShiftStepEnabled:!1,__unstableStateReducer:m(2),value:String(i.value.mm).padStart(2,"0"),onChange:p("mm")}),React.createElement(f,null)),React.createElement(d,{className:u.Z["timestamp-control-input"],disabled:t,min:0,max:59,step:1,hideLabelFromVision:!0,spinControls:"none",placeholder:"00",isPressEnterToChange:!0,isDragEnabled:!1,isShiftStepEnabled:!1,__unstableStateReducer:m(2),value:String(i.value.ss).padStart(2,"0"),onChange:p("ss")}),a&&React.createElement(React.Fragment,null,React.createElement(f,{char:"."}),React.createElement(d,{className:u.Z["timestamp-control-input"],style:{"--input-width":12*a+"px"},disabled:t,min:0,max:Number("9".repeat(a)),step:1,hideLabelFromVision:!0,spinControls:"none",placeholder:"0".repeat(a),isPressEnterToChange:!0,isDragEnabled:!1,isShiftStepEnabled:!1,__unstableStateReducer:m(a),value:String(i.value.decimal).padStart(a,"0"),onChange:p("decimal")})))},g=e=>{const{disabled:t=!1,min:r=0,max:n=Number.MAX_SAFE_INTEGER,value:i,onChange:c,onDebounceChange:f,wait:m=1e3,fineAdjustment:h=50,autoHideTimeInput:g=!0,decimalPlaces:y,marksEvery:b,renderTooltip:w}=e,k=(0,s.useRef)(),[_,E]=(0,s.useState)(i);(0,s.useEffect)((()=>{E(i)}),[i]);const{baseControlProps:R}=p?.(e)||{},C=(0,s.useCallback)((e=>{clearTimeout(k?.current),e>n&&(e=n),e(0,l.m)(e);return React.createElement(a.BaseControl,R,React.createElement("div",{className:u.Z["timestamp-control__controls-wrapper"]},d&&React.createElement(v,{disabled:t,max:n,value:_,onChange:C,autoHideTimeInput:g,decimalPlaces:y}),React.createElement(a.RangeControl,o()({disabled:t,className:u.Z["timestamp-range-control"],min:r,step:h,initialPosition:_,value:_,max:n,withInputField:!1,onChange:C,marks:b?S:void 0,renderTooltipContent:P},!1===w?{showTooltip:!1}:{}))))}},7535:(e,t,r)=>{"use strict";r.d(t,{Z:()=>u});var n=r(5609),o=r(9307),a=r(1074),i=r(3228),s=r(2346),c=r(4641);const l=({src:e,setMaxDuration:t=null,currentTime:r})=>{const a=(0,o.useRef)(null),[i,s]=(0,o.useState)(!0);(0,o.useEffect)((()=>{a.current.src=e}),[e]),(0,o.useEffect)((()=>{a.current&&Number.isFinite(r)&&(a.current.currentTime=r)}),[r]);return React.createElement("div",{className:c.Z["video-player-wrapper"]},i&&React.createElement("div",{className:c.Z["video-player-spinner-wrapper"]},React.createElement(n.Spinner,{className:c.Z.spinner})),React.createElement("video",{onLoadedData:()=>s(!1),ref:a,muted:!0,className:c.Z.video,onDurationChange:e=>{const n=e.target.duration;if(t?.(n),a.current){const e=Number.isFinite(r)?r:n/2;a.current.currentTime=e}}}))},u=({src:e="",onVideoFrameSelected:t,className:r="",initialCurrentTime:u=null})=>{const[p,d]=(0,o.useState)(0),[f,m]=(0,o.useState)(Number.isFinite(u)?u:null);return React.createElement("div",{className:(0,i.Z)(c.Z.container,r)},React.createElement(a.Z,{className:c.Z["play-icon"],icon:s.Z}),React.createElement(l,{src:e,setMaxDuration:d,currentTime:f}),React.createElement(n.RangeControl,{className:c.Z.range,min:0,step:.1,initialPosition:f,max:p,showTooltip:!1,withInputField:!1,onChange:e=>{m(e),t?.(1e3*e)}}))}},1048:(e,t,r)=>{"use strict";r.d(t,{Z:()=>s});var n=r(4333),o=r(9196),a=r(172),i=r(5304);const s=e=>{const[t,r]=(0,o.useState)(!1),s=(0,o.useCallback)((()=>{const t=(0,a.ZP)(e);0===t.length?r(!1):r(!(0,i.Z)(t))}),[e]),c=(0,n.useDebounce)(s,3e3);return(0,o.useEffect)((()=>{c()}),[e]),(0,o.useEffect)(s,[]),{hasIncompleteChapters:t}}},5134:(e,t,r)=>{"use strict";r.d(t,{Z:()=>a});var n=r(6989),o=r.n(n);const a=e=>{const t={allowDownload:"allow_download",displayEmbed:"display_embed"};return r=>new Promise(((n,a)=>{const i=(s=Object.assign({id:e},r),Object.keys(s).reduce(((e,r)=>(e[t[r]||r]=s[r],e)),{}));var s;o()({path:"/wpcom/v2/videopress/meta",method:"POST",data:i}).then((e=>{"success"===e?.code||a()})).catch((e=>a(e))).finally((()=>{n()}))}))}},6650:(e,t,r)=>{"use strict";r.d(t,{Z:()=>a});var n=r(6989),o=r.n(n);const a=e=>()=>new Promise((function(t,r){o()({path:`/wpcom/v2/videopress/${e}/poster`,method:"GET"}).then((function(e){t(e)})).catch((function(e){r(e)}))}))},3897:(e,t,r)=>{"use strict";r.d(t,{Z:()=>a});var n=r(6989),o=r.n(n);const a=e=>function(t){return new Promise((function(r,n){o()({path:`/wpcom/v2/videopress/${e}/poster`,method:"POST",data:t}).then((function(e){r(e)})).catch((function(e){n(e)}))}))}},9272:(e,t,r)=>{"use strict";r.d(t,{Z:()=>l});var n=r(9307),o=r(951),a=r.n(o),i=r(6998),s=r(5042);const c=a()("videopress:use-resumable-uploader"),l=({onProgress:e,onSuccess:t,onError:r})=>{const[o,a]=(0,n.useState)({bytesSent:0,bytesTotal:0,percent:0,status:"idle"}),[l,u]=(0,n.useState)(),[p,d]=(0,n.useState)(null),[f,m]=(0,n.useState)();async function h(n){const c=await(0,i.Z)("upload-jwt");if(!c.token)return r("No token provided");"idle"===o.status&&a((e=>({...e,status:"uploading"})));let l=!1;const p=(0,s.Z)({file:n,tokenData:c,onProgress:(t,r)=>{if(l)return;const n=Math.round(t/r*100);a({bytesSent:t,bytesTotal:r,percent:n,status:"uploading"}),e(t,r)},onSuccess:e=>{l=!0,a((e=>({...e,status:"done"}))),u(e),t(e)},onError:e=>{a((e=>({...e,status:"error"}))),d(e),r(e)}});m({start:()=>{a((e=>({...e,status:"uploading"}))),p.start()},abort:()=>{a((e=>({...e,status:"aborted"}))),p.abort()}})}return{onUploadHandler:function(e){const t=e.target.files[0];t?h(t):c("No file selected. Bail early")},uploadHandler:h,resumeHandler:f,uploadingData:o,media:l,error:p}}},1207:(e,t,r)=>{"use strict";r.d(t,{R2:()=>i});var n=r(6989),o=r.n(n),a=(r(9307),r(5736));r(9537);const __=a.__,i=e=>{const t=`videopress/v1/upload/${e}`;return new Promise(((r,n)=>{o()({path:t,method:"POST"}).then((t=>{"uploading"===t.status||"new"===t.status||"resume"===t.status?i(e).then(r).catch(n):"complete"===t.status?r({guid:t.uploaded_details.guid,id:t.uploaded_details.media_id,src:t.uploaded_details.upload_src}):"error"===t.status?n({data:{message:t.error}}):n({data:{message:__("Unexpected error uploading video.","jetpack-videopress-pkg")}})})).catch((e=>{n({data:{message:e?.message}})}))}))}},8232:(e,t,r)=>{"use strict";r.d(t,{$U:()=>u,Hn:()=>p,b$:()=>c,yD:()=>l});var n=r(951),o=r.n(n);const a=window?.JP_CONNECTION_INITIAL_STATE,{siteType:i=""}=window?.videoPressEditorState||{},s=o()("videopress:connection");function c(){return"simple"===i?(s("Simple site connected ✅"),!0):a?.connectionStatus?.isUserConnected?(s("Jetpack user is connected ✅"),!0):(s("User is not connected ❌"),!1)}function l(){return"1"===window?.videoPressEditorState?.isVideoPressModuleActive}function u(){return!!c()&&(l()||p())}function p(){return"1"===window?.videoPressEditorState?.isStandaloneActive}},5955:(e,t,r)=>{"use strict";r.d(t,{B:()=>p});var n=r(6989),o=r.n(n),a=r(9307),i=r(951),s=r.n(i),c=r(6998);const l=a.Platform.isNative,u=s()("videopress:lib:fetch-video-item");async function p({guid:e,isPrivate:t,token:r=null,skipRatingControl:n=!1,retries:a=0}){try{const a=n?{}:{birth_day:"1",birth_month:"1",birth_year:"2000"};let i;t&&!r&&(i=await(0,c.Z)("playback",{guid:e})),(r||i?.token)&&(a.metadata_token=r||i.token);const s=Object.keys(a).length?`?${new URLSearchParams(a).toString()}`:"",u=l?{path:`/rest/v1.1/videos/${e}${s}`}:{url:`https://public-api.wordpress.com/rest/v1.1/videos/${e}${s}`};return await o()({...u,credentials:"omit",global:!0})}catch(t){u("updating retry from",a,"to",a+1);const r=a+1;if(r>2)throw u("Too many attempts to get video. Aborting."),new Error(t?.message??t);if("auth"===t?.error)return u("Authentication error. Reattempt %o",r+"/3"),p({guid:e,isPrivate:!0,token:null,skipRatingControl:n,retries:r});if("Please supply the birthdate parameters."===t?.message)return u("Rating error. Reattempt %o",r+"/3"),p({guid:e,isPrivate:!0,token:null,skipRatingControl:!1,retries:r});throw new Error(t?.message??t)}}},6998:(e,t,r)=>{"use strict";r.d(t,{Z:()=>s});var n=r(951),o=r.n(n),a=r(5368);const i=o()("videopress:get-media-token");const s=async function(e,t={}){const{id:r=0,guid:n=0,flushToken:o}=t,s=`vpc-${e}-${r}-${n}`,c=window?.videopressAjax?.context||"main";let l;const u=localStorage.getItem(s);if(o)i("(%s) Flushing %o token",c,s),localStorage.removeItem(s);else try{if(u){if(l=await JSON.parse(u),l&&l.expire>Date.now())return i("(%s) Providing %o token from the store",c,s),l.data;i("(%s) Token %o expired. Clean.",c,s),localStorage.removeItem(s)}}catch(e){i("Invalid token in the localStore")}const p=await function(e,t={}){const{id:r=0,guid:n,subscriptionPlanId:o=0,adminAjaxAPI:i,filename:s}=t;return new Promise((function(t,c){const l=i||window.videopressAjax?.ajaxUrl||window?.ajaxurl||"/wp-admin/admin-ajax.php";if(!a.M.includes(e))return c("Invalid scope");const u={action:"videopress-get-playback-jwt"};switch(e){case"upload":u.action="videopress-get-upload-token",s&&(u.filename=s);break;case"upload-jwt":u.action="videopress-get-upload-jwt";break;case"playback":u.action="videopress-get-playback-jwt",u.guid=n,u.post_id=String(r),u.subscription_plan_id=o}fetch(l,{method:"POST",credentials:"same-origin",body:new URLSearchParams(u)}).then((e=>{if(!e.ok)throw new Error("Network response was not ok");return e.json()})).then((r=>{if(!r.success)throw new Error("Token is not achievable");switch(e){case"upload":case"upload-jwt":t({token:r.data.upload_token,blogId:r.data.upload_blog_id,url:r.data.upload_action_url});break;case"playback":t({token:r.data.jwt})}})).catch((()=>{console.warn("Token is not achievable"),t({token:null})}))}))}(e,t);return"playback"===e&&p?.token&&(i("(%s) Storing %o token",c,s),localStorage.setItem(s,JSON.stringify({data:p,expire:Date.now()+864e5}))),i("(%s) Providing %o token from request/response",c,s),p}},5368:(e,t,r)=>{"use strict";r.d(t,{M:()=>n});const n=["upload","playback","upload-jwt"]},6279:(e,t,r)=>{"use strict";r.d(t,{Td:()=>i,t2:()=>c});var n=r(3419),o=r(6989),a=r.n(o);const i=function(e,t){const r={at_time:t,is_millisec:!0};return(0,n.Wp)()?a()({path:`/videos/${e}/poster`,apiNamespace:"rest/v1.1",method:"POST",global:!0,data:r}):a()({path:`/wpcom/v2/videopress/${e}/poster`,method:"POST",data:r})},s=async function(e){const t=await function(e){return a()({path:`/wpcom/v2/videopress/${e}/poster`,method:"GET"})}(e);return!t.data?.generating};async function c(e,{wait:t=3e3,attemps:r=10,initialWait:n=!0}={}){for(n&&await new Promise((e=>setTimeout(e,t)));!await s(e);){if(0==r--)throw new Error("Poster generation timed out");await new Promise((e=>setTimeout(e,t)))}return!0}},5042:(e,t,r)=>{"use strict";r.d(t,{Z:()=>l});var n=r(951),o=r.n(n),a=r(9537),i=r(6998);const s=o()("videopress:resumable-file-uploader"),c={},l=({file:e,tokenData:t,onProgress:r,onSuccess:n,onError:o})=>{const l=new a.gq(e,{onError:o,onProgress:r,endpoint:t.url,removeFingerprintOnSuccess:!0,overridePatchMethod:!1,chunkSize:1e7,metadata:{filename:e.name,filetype:e.type},retryDelays:[0,1e3,3e3,5e3,1e4],onShouldRetry:function(e){return 400!==(e.originalResponse?e.originalResponse.getStatus():0)||(s("cleanup retry due to 400 error"),localStorage.removeItem(l._urlStorageKey),!1)},onBeforeRequest:async function(e){const r=e._method;if(["HEAD","OPTIONS"].indexOf(r)>=0&&(e._method="GET",e.setHeader("X-HTTP-Method-Override",r)),["DELETE","PUT","PATCH"].indexOf(r)>=0&&(e._method="POST",e.setHeader("X-HTTP-Method-Override",r)),e._xhr.open(e._method,e._url,!0),Object.keys(e._headers).forEach((function(t){e.setHeader(t,e._headers[t])})),"POST"===r){if(!!!t.token)throw"should never happen";e.setHeader("x-videopress-upload-token",t.token)}if(["OPTIONS","GET","HEAD","DELETE","PUT","PATCH"].indexOf(r)>=0){const t=(n=e._url,new URL(n).pathname.split("/").pop());if(c[t])e.setHeader("x-videopress-upload-token",c[t]);else if("HEAD"===r){const r=await(0,i.Z)("upload-jwt");r?.token&&(c[t]=r.token,e.setHeader("x-videopress-upload-token",r.token))}}var n},onAfterResponse:async function(t,r){if(r.getStatus()>=400)return void s("upload error");const o=r.getHeader("x-videopress-upload-guid"),a=r.getHeader("x-videopress-upload-media-id"),i=r.getHeader("x-videopress-upload-src-url");if(o&&a&&i)return void(n&&n({id:Number(a),guid:o,src:i},e));const l={"x-videopress-upload-key-token":"token","x-videopress-upload-key":"key"},u={};Object.keys(l).forEach((function(e){const t=r.getHeader(e);t&&(u[l[e]]=t)})),u.key&&u.token&&(c[u.key]=u.token)}});return l.findPreviousUploads().then((function(e){e.length&&l.resumeFromPreviousUpload(e[0]),l.start()})),l}},515:(e,t,r)=>{"use strict";r.d(t,{Di:()=>u,K8:()=>l,Yv:()=>c,Zx:()=>s,pg:()=>i,qD:()=>p});var n=r(6483);const o=["autoPlay","cover","controls","hd","loop","muted","persistVolume","playsinline","posterUrl","preloadContent","sbc","sbpc","sblc","resizeToParent","useAverageColor"],a={autoPlay:"autoplay",cover:"cover",controls:"controls",hd:"hd",loop:"loop",muted:"muted",persistVolume:"persistVolume",playsinline:"playsinline",posterUrl:"poster",preloadContent:"preload",sbc:"seekbarColor",sbpc:"seekbarPlayedColor",sblc:"seekbarLoadingColor",resizeToParent:"resizeToParent",useAverageColor:"useAverageColor"},i=(e,{autoplay:t,controls:r,loop:o,muted:a,playsinline:i,poster:s,preload:c,seekbarColor:l,seekbarPlayedColor:u,seekbarLoadingColor:p,useAverageColor:d})=>{if(!e)return null;const f={resizeToParent:!0,cover:!0,...t&&{autoPlay:!0},...!r&&{controls:!1},...o&&{loop:!0},...a&&{muted:!0,persistVolume:!1},...i&&{playsinline:!0},...s&&{posterUrl:s},...""!==c&&{preloadContent:c},...""!==l&&{sbc:l},...""!==u&&{sbpc:u},...""!==p&&{sblc:p},...d&&{useAverageColor:!0}};return(0,n.addQueryArgs)(`https://videopress.com/v/${e}`,f)},s=e=>{if(!e||"string"!=typeof e)return null;const t=e.match(/^https?:\/\/(?video(?:\.word|s\.files\.word)?press\.com)(?:\/v|\/embed)?\/(?[a-zA-Z\d]{8})/);return t?.groups?.guid?t.groups.guid:null};function c(e,t){const r=function(e){const t=e.match(/^[a-zA-Z\d]{8}$/);return!!t&&t[0]}(e);if(r)return t?{url:i(e,t),guid:e}:{url:`https://videopress.com/v/${e}`,guid:e};const n=s(e);return n?{url:e,guid:n}:{}}const l=e=>e.replace(/\.[^/.]+$/,"");function u(e){return/^https?:\/\/(?:(?:v(?:ideo)?\.wordpress\.com|videopress\.com)\/(?:v|embed)|v\.wordpress\.com)\/([a-z\d]{8})(\/|\b)/i.test(e)}function p(e){let t;try{t=new URLSearchParams(new URL(e).search)}catch(e){return{}}return o.reduce(((e,r)=>{const n=t.get(r);if(null!==n){e[a[r]]=["autoPlay","cover","controls","hd","loop","muted","persistVolume","playsinline","resizeToParent","useAverageColor"].includes(r)?(e=>"1"===e||"true"===e||"0"!==e&&"false"!==e&&null)(n):n}return e}),{})}},2198:(e,t,r)=>{"use strict";r.d(t,{nb:()=>d,qL:()=>f,ss:()=>p});var n=r(6989),o=r.n(n),a=r(951),i=r.n(a),s=r(6998);const{siteType:c=""}=window?.videoPressEditorState||{},l="simple"!==c,u=i()("videopress:tracks:lib:video-tracks");async function p(e,t){if(!e)return!1;let r,n="";t.isPrivate&&(r=await(0,s.Z)("playback",{guid:t.guid}),n="?"+new URLSearchParams({metadata_token:r?.token}).toString());let o=await fetch(e+n);if(!o.ok&&403===o.status&&t.guid&&(r=await(0,s.Z)("playback",{guid:t.guid}),n="?"+new URLSearchParams({metadata_token:r?.token}).toString(),o=await fetch(e+n)),!o.ok)return!1;const a=await o.text();return/videopress-chapters-auto-generated/.test(a)}const d=(e,t)=>{const{kind:r,srcLang:n,label:a,tmpFile:i}=e;return l?function(e,t){return u("using jetpack api fetch"),new Promise((function(r,n){const{kind:o,srcLang:a,label:i,tmpFile:c}=e;(0,s.Z)("upload",{filename:c.name}).then((({token:e,blogId:s})=>{const l=new FormData;l.append("kind",o),l.append("srclang",a),l.append("label",i),l.append("vtt",c),fetch(`https://public-api.wordpress.com/rest/v1.1/videos/${t}/tracks`,{headers:{Authorization:`X_UPLOAD_TOKEN token="${e}" blog_id="${s}"`},method:"POST",body:l}).then((e=>{try{const t=e.json();return u("data",e),u("json",t),r(t)}catch(e){return u("error",e),n(e)}})).catch(n)}))}))}({kind:r,srcLang:n,label:a,tmpFile:i},t):(u("using wpcom api fetch"),new Promise((function(e,s){return o()({method:"POST",path:`/videos/${t}/tracks`,apiNamespace:"rest/v1.1",global:!0,parse:!1,formData:[["kind",r],["srclang",n],["label",a],["vtt",i]]}).then((t=>{try{const r=t.json();return u("data",t),u("json",r),e(r)}catch(e){return u("error",e),s(e)}})).catch(s)})))},f=(e,t)=>{const{kind:r,srcLang:n}=e;if(l)return function({kind:e,srcLang:t},r){return new Promise((function(n,o){(0,s.Z)("upload").then((({token:a,blogId:i})=>{const s=new FormData;s.append("kind",e),s.append("srclang",t),fetch(`https://public-api.wordpress.com/rest/v1.1/videos/${r}/tracks/delete`,{headers:{Authorization:`X_UPLOAD_TOKEN token="${a}" blog_id="${i}"`},method:"POST",body:s}).then((e=>{try{return n(e.json())}catch(e){return o(e)}})).catch(o)}))}))}({kind:r,srcLang:n},t);const a={method:"POST",path:`/videos/${t}/tracks/delete`,apiNamespace:"rest/v1.1",global:!0,parse:!1,formData:[["kind",r],["srclang",n]]};return o()(a)}},4391:(e,t,r)=>{"use strict";r.d(t,{$A:()=>n,Gr:()=>l,O1:()=>a,UJ:()=>o,Vz:()=>i,pf:()=>c,x4:()=>s});const n="public",o="private",a="site-default",i=[n,o,a],s="G",c="PG-13",l="R-17"},5178:(e,t,r)=>{"use strict";function n(e){return e.replace(/([-_][a-z])/gi,(e=>e.toUpperCase().replace("_","")))}r.d(t,{T:()=>n})},993:(e,t,r)=>{"use strict";function n(e){const t=Math.floor(e/36e5),r=Math.floor(e/6e4)%60,n=Math.floor(e/1e3)%60,o=Math.floor(e/10)%100;return[t>0?t.toString().padStart(2,"0")+":":"",t>0||r>0?r.toString().padStart(2,"0")+":":"",n.toString().padStart(2,"0"),"."+o.toString().padStart(2,"0")].join("")}r.d(t,{m:()=>n})},172:(e,t,r)=>{"use strict";function n(e){if(!e)return[];return e.split("\n").map((e=>function(e){const t=/(?\(?(?