관리-도구
편집 파일: Image.g0jgwvuo.js
import{E as y,F as A,G as F,b as v,H as D,I as $,J as B,K as T,u as w,a as h,g as U}from"./index.nsvc8vqf.js";import{g as L,a as N,b as M,d as R,c as k,e as q}from"./postSlug.cemx0kwk.js";import"./translations.lf9cwm9a.js";import{g as I,f as P}from"./runtime-dom.esm-bundler.h3clfjuw.js";import{_ as c}from"./default-i18n.hohxoesu.js";const G=()=>{var a;let t=0;return(y()||A())&&(t=parseInt((a=document.getElementById("post_author_override"))==null?void 0:a.value)),F()&&(t=window.wp.data.select("core/editor").getEditedPostAttribute("author")),t||(t=v().currentPost.postAuthor),t},H=()=>{const t=document.querySelector("#set-post-thumbnail img");return t?t.getAttribute("src"):""},x=async(t=!1)=>{var e;const a=window.wp.data.select("core/editor"),r=t&&a?a==null?void 0:a.getEditedPostAttribute("featured_media"):(e=a==null?void 0:a.getCurrentPost())==null?void 0:e.featured_media;return typeof r>"u"?new Promise(o=>setTimeout(()=>o(x(t)),1e3)):r},O=async()=>{if(y()||A())return H();if(F()){const t=await x(!0).then(r=>r);return isNaN(t)||t===0?"":v().getMediaData({mediaId:t}).then(r=>r.source_url)}return D()?L().featuredImage:$()?N().featuredImage:B()?M().featuredImage:T()?R().featuredImage:""},d="all-in-one-seo-pack",C=()=>{let t=null;const a=/<img.*?src=['"](.*?)['"].*?>/i.exec(q());return a&&a[1]&&(t=a[1]),t},J=async(t,a,r)=>{let e=k(t[`${r}image_custom_fields`]);return e||await O().then(o=>{e=o}),e||await v().getFirstAttachedImage({postId:t.id}).then(p=>{e=p}),e||(e=C()),e||(e=h().options.social[a].homePage.image),e},K=async()=>{let t="";const a=G();return await v().getUserImage({userId:a}).then(e=>{t=e}),t},te=()=>{const t=I(["featured","content","author"]),a=I(["auto"]),r=I(["featured","attach","content","author","auto"]),e=I(""),o=I(!1),p=P(()=>[{label:c("Default Image (Set Below)",d),value:"default"},{label:c("Featured Image",d),value:"featured"},{label:c("Attached Image",d),value:"attach"},{label:c("First Image in Content",d),value:"content"},{label:c("Image from Custom Field",d),value:"custom"},{label:c("Post Author Image",d),value:"author"},{label:c("First Available Image",d),value:"auto"}]),_=P(()=>{var l,u,m;const n=v(),s=p.value.map(i=>(i.value==="default"&&(i.label=c("Default Image Source (Set in Social Networks)",d)),i)).concat({label:c("Custom Image",d),value:"custom_image"});if(((l=n.currentPost)==null?void 0:l.context)==="term")return s.filter(i=>!r.value.includes(i.value));if(((u=n.currentPost)==null?void 0:u.context)==="post"&&((m=n.currentPost)==null?void 0:m.postType)==="attachment")return s.filter(i=>!t.value.includes(i.value));const g=w(),S=h();return g.aioseo.integration?((g.aioseo.integration==="seedprod"||g.aioseo.integration==="wpbakery"&&window.vc_mode==="admin_frontend_editor")&&a.value.push("featured"),g.aioseo.integration==="siteorigin"&&!S.options.searchAppearance.advanced.runShortcodes&&a.value.push("content"),s.filter(i=>!a.value.includes(i.value))):s});return{getImageSourceOption:n=>p.value.find(s=>s.value===n),getImageSourceOptionFiltered:n=>_.value.find(s=>s.value===n),getTermImageSourceOptions:()=>p.value.filter(n=>!r.value.includes(n.value)),imageSourceOptions:p,imageSourceOptionsFiltered:_,imageUrl:e,loading:o,setImageUrl:async(n="")=>{var E;const s=h(),g=v(),S=U(),l=g.currentPost,u=n||((E=S.metaBoxTabs)==null?void 0:E.social)||"facebook",m=u==="facebook"||u==="twitter"&&l.twitter_use_og?"og_":"twitter_";let i=l[`${m}image_type`]||"default";switch(i==="default"&&(i=s.options.social[u].general.defaultImageSourcePosts),e.value="",i){case"featured":o.value=!0,await O().then(f=>{e.value=f,o.value=!1});break;case"attach":o.value=!0,await g.getFirstAttachedImage({postId:l.id}).then(f=>{e.value=f,o.value=!1});break;case"content":e.value=C();break;case"author":o.value=!0,await K().then(f=>{e.value=f,o.value=!1});break;case"auto":o.value=!0,await J(l,u,m).then(f=>{e.value=f,o.value=!1});break;case"custom":e.value=k(l[`${m}image_custom_fields`]);break;case"custom_image":e.value=l[`${m}image_custom_url`];break;case"default":default:e.value=s.options.social[u].general.defaultImagePosts;break}!e.value&&s.options.social[u].general.defaultImagePosts&&(e.value=s.options.social[u].general.defaultImagePosts);const b=w();!e.value&&b.aioseo.urls.siteLogo&&(e.value=b.aioseo.urls.siteLogo),window.aioseoBus.$emit("updateSocialImagePreview",{social:u,image:e.value})}}};export{te as u};