1 line
27 KiB
JavaScript
1 line
27 KiB
JavaScript
import{r as e}from"./rolldown-runtime-hePW80VL.js";import{A as t,U as n,W as r,j as i,r as a,t as o}from"./button-BhAQo6Sy.js";import{$ as s,X as c,Z as l,n as u,t as d,tt as f}from"./api-Bb85n68L.js";import{Mt as ee}from"./usePositioner-BR1Prb1t.js";import{t as te}from"./cloud-upload-C1d9L0C_.js";import{t as ne}from"./spinner-B0ROFxgI.js";import{a as re,i as p,n as m,r as h,t as ie}from"./use-unsaved-changes-CBW9Uy54.js";import{r as ae,t as g}from"./switch-DMNAfdJq.js";import{t as oe}from"./type-Df9tHIH_.js";import{i as _,n as se,o as ce,t as v}from"./tooltip-BJCKJ7vw.js";import{t as le}from"./input-DbQb1wvc.js";import{a as ue,s as de}from"./app-Di4tDCA1.js";import{a as y,i as b,n as x,o as S,r as fe,t as C}from"./frame-Bg0IxU65.js";import{i as w,n as pe,r as T,t as me}from"./font-editor-layout-DqX_DfJ-.js";import{t as he}from"./font-preview-Sn0GCLRT.js";var ge=n(`arrow-down-0-1`,[[`path`,{d:`m3 16 4 4 4-4`,key:`1co6wj`}],[`path`,{d:`M7 20V4`,key:`1yoxec`}],[`rect`,{x:`15`,y:`4`,width:`4`,height:`6`,ry:`2`,key:`1bwicg`}],[`path`,{d:`M17 20v-6h-2`,key:`1qp1so`}],[`path`,{d:`M15 20h4`,key:`1j968p`}]]),_e=n(`file-plus-corner`,[[`path`,{d:`M11.35 22H6a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v5.35`,key:`17jvcc`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M14 19h6`,key:`bvotb8`}],[`path`,{d:`M17 16v6`,key:`18yu1i`}]]),E=e(r(),1),D=20971520,O=15e3,k=new Set([`woff2`,`woff`,`ttf`,`otf`]),A={woff2:1,woff:2,ttf:3,otf:4,eot:5},j=[{value:`100 900`,pattern:/variablefont|\[[^\]]*(?:wght|opsz)[^\]]*\]|(?:^|[-_.\s])(?:wght|opsz,wght)(?=$|[-_.\s])/i},{value:200,pattern:/(?:^|[-_.\s])(?:200|extra[-_ ]?light|ultra[-_ ]?light)(?=$|[-_.\s]|italic|oblique)/i},{value:800,pattern:/(?:^|[-_.\s])(?:800|extra[-_ ]?bold|ultra[-_ ]?bold)(?=$|[-_.\s]|italic|oblique)/i},{value:600,pattern:/(?:^|[-_.\s])(?:600|semi[-_ ]?bold|demi[-_ ]?bold)(?=$|[-_.\s]|italic|oblique)/i},{value:100,pattern:/(?:^|[-_.\s])(?:100|thin|hairline)(?=$|[-_.\s]|italic|oblique)/i},{value:300,pattern:/(?:^|[-_.\s])(?:300|light)(?=$|[-_.\s]|italic|oblique)/i},{value:400,pattern:/(?:^|[-_.\s])(?:400|normal|regular|book)(?=$|[-_.\s]|italic|oblique)/i},{value:500,pattern:/(?:^|[-_.\s])(?:500|medium)(?=$|[-_.\s]|italic|oblique)/i},{value:700,pattern:/(?:^|[-_.\s])(?:700|bold)(?=$|[-_.\s]|italic|oblique)/i},{value:900,pattern:/(?:^|[-_.\s])(?:900|black|heavy)(?=$|[-_.\s]|italic|oblique)/i}],M=[{value:`italic`,pattern:/italic(?=$|[-_.\s])/i},{value:`oblique`,pattern:/oblique(?=$|[-_.\s])/i}];function N(e){return String(Number.isInteger(e)?e:Number(e.toFixed(3)))}function P(e){return e instanceof ArrayBuffer?e:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength)}function F(e){return e.replace(/\.(?:woff2?|ttf|otf|eot)$/i,``).replace(/\[[^\]]+\]/g,` `).replace(/variablefont|wght|wdth|opsz|slnt|italic|ital|oblique|normal|regular|book|hairline|thin|extra[-_ ]?light|ultra[-_ ]?light|light|medium|semi[-_ ]?bold|demi[-_ ]?bold|extra[-_ ]?bold|ultra[-_ ]?bold|bold|black|heavy/gi,` `).replace(/\b(?:100|200|300|400|500|600|700|800|900)\b/g,` `).replace(/[-_.]+/g,` `).replace(/\s+/g,` `).trim()}function I(e){let t=e.name.toLowerCase(),n=j.find(({pattern:e})=>e.test(t))?.value??400,r=M.find(({pattern:e})=>e.test(t))?.value??`normal`;return{family:F(e.name),weight:n,width:``,style:r}}function L(e,t){let n=e.getEnglishName?.(t);if(typeof n==`string`&&n.trim())return n.trim();for(let n of[`unicode`,`windows`,`macintosh`]){let r=e.names[n]?.[t]?.en;if(typeof r==`string`&&r.trim())return r.trim()}return``}function ve(e){return(e.tables.fvar?.axes??[]).filter(e=>[e.minValue,e.defaultValue,e.maxValue].every(Number.isFinite)).map(e=>({tag:e.tag,name:typeof e.name==`string`&&e.name.trim()?e.name.trim():void 0,min:e.minValue,defaultValue:e.defaultValue,max:e.maxValue}))}async function ye(t){let{parse:n}=await s(async()=>{let{parse:t}=await import(`./opentype-6XcYdTgz.js`).then(t=>e(t.default,1));return{parse:t}},[],import.meta.url);return n(t,{lowMemory:!0})}var R=null;async function z(){if(R)return R;R=(async()=>{let e=await s(()=>import(`./decompress-BFqEkQYo.js`),[],import.meta.url);return await e.preload(),e.default})();try{return await R}catch(e){throw R=null,e}}async function be(e){return(await z())(e)}async function B(){await z()}function xe(e,t){let n=ve(e),r=n.find(e=>e.tag===`wght`),i=n.find(e=>e.tag===`wdth`),a=n.find(e=>e.tag===`slnt`),o=n.find(e=>e.tag===`ital`),s=L(e,`fontSubfamily`).toLowerCase(),c=e.tables.os2?.fsSelection??0,l=/italic/.test(s)||!!(c&1),u=/oblique/.test(s),d=l?`italic`:u?`oblique`:t.style;return a?d=`oblique ${N(-a.max)}deg ${N(-a.min)}deg`:o&&o.defaultValue>.5&&(d=`italic`),{family:L(e,`fontFamily`)||t.family,weight:r?`${N(r.min)} ${N(r.max)}`:e.tables.os2?.usWeightClass||t.weight,width:i?`${N(i.min)}% ${N(i.max)}%`:t.width,style:d,axes:n}}async function V(e){let t=I(e),n=e.extension.toLowerCase();if(!k.has(n)||Number(e.filesize??e.file_size??0)>D)return{...t,file:e,axes:[],metadataDetected:!1};let r=new AbortController,i=setTimeout(()=>r.abort(),O);try{let i=await fetch(e.attachment_url,{credentials:`same-origin`,signal:r.signal});if(!i.ok)throw Error(`Unable to read ${e.name}.`);if(Number(i.headers.get(`content-length`)??0)>D)return{...t,file:e,axes:[],metadataDetected:!1};let a=await i.arrayBuffer(),o=a;return n===`woff2`&&(o=await be(a)),{...xe(await ye(P(o)),t),file:e,metadataDetected:!0}}catch{return{...t,file:e,axes:[],metadataDetected:!1}}finally{clearTimeout(i)}}function Se(e){return{...I(e),file:e,axes:[],metadataDetected:!1}}function Ce(){return!(typeof Worker>`u`)}function H(){return new Worker(new URL(``+new URL(`font-inspector.worker-BL51xWdh.js`,import.meta.url).href,``+import.meta.url),{type:`module`})}function U(e,t){return new Promise((n,r)=>{let i=t=>{e.onmessage=null,e.onerror=null,t?r(t):n()};e.onmessage=e=>{if(e.data.type===`ready`){i();return}e.data.type===`init-error`&&i(Error(e.data.error||`Unable to initialize the font inspector worker.`))},e.onerror=e=>{i(Error(e.message||`Unable to initialize the font inspector worker.`))},e.postMessage({type:`init`,preloadWoff2:t})})}function we(e,t){return new Promise(n=>{let r=!1,i=Se(t),a=(t,i)=>{r||(r=!0,clearTimeout(o),e.onmessage=null,e.onerror=null,n({result:t,restartWorker:i}))},o=setTimeout(()=>{a(i,!0)},O);e.onmessage=e=>{e.data.result?a(e.data.result,!1):a(i,!0)},e.onerror=e=>{a(i,!0)};try{e.postMessage({type:`inspect`,id:1,file:t})}catch{a(i,!0)}})}function W(){return new Promise(e=>{if(typeof requestAnimationFrame==`function`){requestAnimationFrame(()=>e());return}setTimeout(e,0)})}async function G(e,t){if(e.length===0)return[];let n=Array(e.length),r=0,i=0;e.some(e=>e.extension.toLowerCase()===`woff2`)&&await B();for(let[a,o]of e.entries()){i=1,t?.(null,r,e.length,i);let s=await V(o);n[a]=s,i=0,r+=1,t?.(s,r,e.length,i),r<e.length&&await W()}return n}async function K(e,t){let n=Array(e.length),r=H(),i=0,a=0;try{await U(r,e.some(e=>e.extension.toLowerCase()===`woff2`));for(let[o,s]of e.entries()){a=1,t?.(null,i,e.length,a);let{result:c,restartWorker:l}=await we(r,s);n[o]=c,a=0,i+=1,t?.(c,i,e.length,a),l&&(r.terminate(),r=H()),i<e.length&&await W()}}finally{r.terminate()}return n}async function Te(e,t){if(e.length===0)return[];if(!Ce())return G(e,t);try{return await K(e,t)}catch{return G(e,t)}}function q(e){return[String(e.weight).trim(),String(e.width).trim(),String(e.style).trim().toLowerCase()].join(`|`)}function J(e){return A[e.extension.toLowerCase()]??2**53-1}var Ee=`woff2,woff,ttf,otf,eot`,De={"font/woff2":`woff2`,"font/woff":`woff`,"font/ttf":`ttf`,"font/otf":`otf`,"font/eot":`eot`,"application/font-woff2":`woff2`,"application/font-woff":`woff`,"application/x-font-woff2":`woff2`,"application/x-font-woff":`woff`,"application/x-font-ttf":`ttf`,"application/x-font-truetype":`ttf`,"application/x-font-opentype":`otf`,"application/vnd.ms-opentype":`otf`,"application/vnd.ms-fontobject":`eot`,"x-font-woff2":`woff2`,"x-font-woff":`woff`,"x-font-ttf":`ttf`,"x-font-opentype":`otf`,"vnd.ms-opentype":`otf`,"vnd.ms-fontobject":`eot`,truetype:`ttf`,opentype:`otf`,"embedded-opentype":`eot`};function Y(e,t=``){let n=[t.split(`?`)[0].split(`.`).pop(),e];for(let e of n){let t=String(e??``).trim().toLowerCase();if([`woff2`,`woff`,`ttf`,`otf`,`eot`].includes(t))return t;let n=De[t];if(n)return n}return null}function Oe(e){let t=e.filename||e.url.split(`/`).pop()||`font.woff2`;return Y(e.subtype,t)||`woff2`}function ke(e){let t=Oe(e),n=e.filename||e.url.split(`/`).pop()||`font.${t}`;return{uid:w(10),attachment_id:Number(e.id),attachment_url:e.url,extension:t,mime:e.mime||`font/${t}`,filesize:e.filesizeInBytes||0,name:n.replace(RegExp(`\\.${t}$`,`i`),``)}}function Ae(e){return{...e,attachment_id:Number(e.attachment_id),extension:Y(e.extension,e.name)||e.extension}}function X(e){let t=e.uploader?.uploader;t?.param?.(`jooosi_fon_font_upload`,!0);let n=t?.uploader,r=n?.getOption?.(`filters`);!n?.setOption||!r||n.setOption(`filters`,{...r,mime_types:[{title:wp.i18n.__(`Font files`,`jooosi-fon`),extensions:Ee}]})}function je(e){let t=window.wp?.media;if(!t)throw Error(wp.i18n.__(`WordPress Media is unavailable on this page.`,`jooosi-fon`));let n=t({title:e.title,multiple:e.multiple??!0,library:{type:`font`,uploadedTo:null}});n.on(`uploader:ready`,()=>X(n)),n.on(`open`,()=>X(n)),n.on(`select`,()=>{let t=n.state().get(`selection`);e.onSelect(t.map(e=>ke(e.toJSON())))}),n.open(),X(n)}var Z=a(),Me=[`auto`,`block`,`swap`,`fallback`,`optional`];function Q({label:e,description:t}){return(0,Z.jsxs)(v,{children:[(0,Z.jsxs)(_,{render:(0,Z.jsx)(`span`,{className:`inline-flex w-fit cursor-help items-center gap-1 border-b border-dotted border-muted-foreground/60 focus-visible:rounded-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,tabIndex:0}),children:[e,(0,Z.jsx)(de,{className:`size-3.5 text-muted-foreground`,"aria-hidden":`true`})]}),(0,Z.jsx)(se,{children:t})]})}function Ne(e){let t=Number(e.file_size??e.filesize??0);if(!Number.isFinite(t)||t<=0)return`0 B`;let n=[`B`,`KB`,`MB`,`GB`],r=Math.min(Math.floor(Math.log(t)/Math.log(1024)),n.length-1);return`${Number((t/1024**r).toFixed(r===0?0:2))} ${n[r]}`}function Pe(){return{id:w(10),isEnabled:!0,weight:400,width:``,style:`normal`,display:``,selector:``,comment:``,unicodeRange:``,preload:!1,axes:[],files:[]}}var Fe={title:``,family:``,status:!0,preload:!1,selector:``,display:`swap`,fontFaces:[]};function Ie(e,t){let n=e.fontFaces.map(e=>({...e,files:[...e.files],axes:e.axes?[...e.axes]:[]})),r=e.family.trim()||t.family,i={weight:t.weight,width:t.width,style:t.style},a=q(i),o=n.find(e=>q(e)===a);return o?o.axes?.length===0&&t.axes.length>0&&(o.axes=t.axes):(o={...Pe(),...i,axes:t.axes},n.push(o)),o.files.some(e=>e.attachment_id===t.file.attachment_id)||(o.files.push(t.file),o.files.sort((e,t)=>J(e)-J(t))),{...e,title:e.title.trim()||r,family:r,fontFaces:n}}function $(e){return{title:e.title.trim(),family:e.family.trim(),status:e.status,font_faces:e.fontFaces.map(e=>({...e,id:String(e.id),weight:typeof e.weight==`string`?e.weight.trim():e.weight,style:String(e.style||`normal`),isEnabled:e.isEnabled!==!1,files:e.files.map(Ae)})),metadata:{preload:e.preload,selector:e.selector.trim(),display:e.display}}}function Le(){let{id:e}=l(),n=c(),r=!!e,[a,s]=(0,E.useState)(Fe),[de,w]=(0,E.useState)(()=>JSON.stringify($(Fe))),[D,O]=(0,E.useState)(r),[k,A]=(0,E.useState)(!1),[j,M]=(0,E.useState)(!1),[N,P]=(0,E.useState)(!1),[F,I]=(0,E.useState)(null),[L,ve]=(0,E.useState)(null),[ye,R]=(0,E.useState)(wp.i18n.__(`Sphinx of black quartz, judge my vow.`,`jooosi-fon`)),[z,be]=(0,E.useState)(18),[B,xe]=(0,E.useState)(400),[V,Se]=(0,E.useState)(100),[Ce,H]=(0,E.useState)([]),U=(0,E.useMemo)(()=>$(a),[a]),we=!D&&JSON.stringify(U)!==de,W=ie(we);(0,E.useEffect)(()=>{if(!r||!e)return;let t=new AbortController;return O(!0),d.get(`/fonts/detail/${e}`,{signal:t.signal}).then(({data:e})=>{let t={title:e.title,family:e.family,status:e.status,preload:!!e.metadata.preload,selector:e.metadata.selector||``,display:e.metadata.display||`swap`,fontFaces:(e.font_faces||[]).map(e=>({...e,isEnabled:e.isEnabled!==!1}))};s(t),w(JSON.stringify($(t)))}).catch(e=>{t.signal.aborted||ve(u(e))}).finally(()=>{t.signal.aborted||O(!1)}),()=>t.abort()},[r,e]);let G=(e,t)=>{s(n=>({...n,fontFaces:n.fontFaces.map(n=>n.id===e?{...n,...t}:n)}))},K=()=>{let e=Pe();s(t=>({...t,fontFaces:[...t.fontFaces,e]})),H(t=>[...t,e.id])},q=e=>{H(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e])},J=()=>{s(e=>({...e,fontFaces:[...e.fontFaces].sort((e,t)=>Number.parseInt(String(e.weight),10)-Number.parseInt(String(t.weight),10)||e.style.localeCompare(t.style))}))},Ee=()=>{try{je({title:wp.i18n.__(`Upload font files`,`jooosi-fon`),onSelect:e=>{e.length!==0&&(P(!0),I({completed:0,total:e.length,active:0}),Te(e,(e,t,n,r)=>{I({completed:t,total:n,active:r}),e&&s(t=>Ie(t,e))}).catch(e=>f.error(u(e))).finally(()=>{P(!1),I(null)}))}})}catch(e){f.error(u(e))}},De=e=>{try{je({title:wp.i18n.__(`Select files for this variant`,`jooosi-fon`),onSelect:t=>s(n=>({...n,fontFaces:n.fontFaces.map(n=>n.id===e?{...n,files:[...n.files,...t.filter(e=>!n.files.some(t=>t.attachment_id===e.attachment_id))]}:n)}))})}catch(e){f.error(u(e))}},Y=()=>!a.title.trim()||!a.family.trim()?(f.error(wp.i18n.__(`Add a font name and CSS family.`,`jooosi-fon`)),!1):a.fontFaces.length===0||a.fontFaces.every(e=>e.isEnabled===!1||e.files.length===0)?(f.error(wp.i18n.__(`Enable a variant with a font file before saving.`,`jooosi-fon`)),!1):!0,Oe=async t=>{if(t.preventDefault(),!(!Y()||k)){A(!0);try{let t=r?`/fonts/custom/update/${e}`:`/fonts/custom/store`,{data:i}=await d.post(t,U);w(JSON.stringify(U)),f.success(r?wp.i18n.__(`Custom font updated.`,`jooosi-fon`):wp.i18n.__(`Custom font created.`,`jooosi-fon`)),r||(W(),n(`/fonts/edit/${i.id}/custom`,{replace:!0}))}catch(e){f.error(u(e))}finally{A(!1)}}},ke=async()=>{if(!(!e||j||!window.confirm(wp.i18n.__(`Move this font to the trash?`,`jooosi-fon`)))){M(!0);try{await d.post(`/fonts/delete/${e}`),w(JSON.stringify(U)),f.success(wp.i18n.__(`Font moved to trash.`,`jooosi-fon`)),W(),n(`/fonts/index`,{replace:!0})}catch(e){f.error(u(e))}finally{M(!1)}}};if(D)return(0,Z.jsx)(pe,{});if(L)return(0,Z.jsx)(C,{children:(0,Z.jsxs)(y,{role:`status`,"aria-live":`polite`,children:[(0,Z.jsx)(`p`,{className:`text-sm text-destructive`,children:L}),(0,Z.jsx)(o,{type:`button`,className:`mt-4`,onClick:()=>n(`/fonts/index`),children:wp.i18n.__(`Back to fonts`,`jooosi-fon`)})]})});let Ae=he(a.family,a.fontFaces,a.display),X=a.fontFaces.some(e=>String(e.weight).trim().includes(` `)),Le=a.fontFaces.some(e=>String(e.width).trim().includes(` `));return(0,Z.jsxs)(`form`,{className:`grid gap-5`,onSubmit:Oe,children:[(0,Z.jsx)(me,{source:wp.i18n.__(`Custom upload`,`jooosi-fon`),title:r?a.title||wp.i18n.__(`Edit custom font`,`jooosi-fon`):wp.i18n.__(`Create custom font`,`jooosi-fon`),description:wp.i18n.__(`Assemble a locally hosted family from WordPress Media files and control its exact CSS output.`,`jooosi-fon`)}),(0,Z.jsxs)(C,{spacing:`sm`,children:[(0,Z.jsxs)(b,{children:[(0,Z.jsx)(S,{children:wp.i18n.__(`Font details`,`jooosi-fon`)}),(0,Z.jsx)(x,{children:wp.i18n.__(`Name the family and define its default CSS behavior.`,`jooosi-fon`)})]}),(0,Z.jsxs)(y,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-[1.1fr_1.1fr_.9fr_1.25fr_.8fr]`,children:[(0,Z.jsx)(m,{label:wp.i18n.__(`Library name`,`jooosi-fon`),hint:wp.i18n.__(`Shown in the font library.`,`jooosi-fon`),children:(0,Z.jsx)(p,{required:!0,value:a.title,onChange:e=>s({...a,title:e.target.value}),placeholder:wp.i18n.__(`Acme Sans — Brand`,`jooosi-fon`)})}),(0,Z.jsx)(m,{label:wp.i18n.__(`CSS font-family`,`jooosi-fon`),hint:wp.i18n.__(`Used in generated @font-face rules.`,`jooosi-fon`),children:(0,Z.jsx)(p,{required:!0,value:a.family,onChange:e=>s({...a,family:e.target.value}),placeholder:`Acme Sans`})}),(0,Z.jsx)(m,{label:wp.i18n.__(`Font display`,`jooosi-fon`),hint:wp.i18n.__(`Text appearance while loading.`,`jooosi-fon`),children:(0,Z.jsx)(h,{value:a.display,onChange:e=>s({...a,display:e.target.value}),children:Me.map(e=>(0,Z.jsx)(`option`,{children:e},e))})}),(0,Z.jsx)(m,{label:wp.i18n.__(`CSS selector / fallback`,`jooosi-fon`),hint:wp.i18n.__(`Optional automatic assignment.`,`jooosi-fon`),children:(0,Z.jsx)(p,{placeholder:`h1, .site-title | Arial, sans-serif`,value:a.selector,onChange:e=>s({...a,selector:e.target.value})})}),(0,Z.jsxs)(`div`,{className:`grid gap-1.5 text-sm font-medium`,children:[(0,Z.jsx)(`span`,{id:`preload-family-label`,children:wp.i18n.__(`Preload family`,`jooosi-fon`)}),(0,Z.jsxs)(`div`,{className:`flex h-8 items-center justify-between gap-3 rounded-lg border bg-background px-2.5`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-normal text-muted-foreground`,children:a.preload?wp.i18n.__(`Enabled`,`jooosi-fon`):wp.i18n.__(`Disabled`,`jooosi-fon`)}),(0,Z.jsx)(g,{size:`sm`,checked:a.preload,onCheckedChange:e=>s({...a,preload:e}),"aria-labelledby":`preload-family-label`,"aria-describedby":`preload-family-help`})]}),(0,Z.jsx)(`span`,{id:`preload-family-help`,className:`text-xs font-normal text-muted-foreground`,children:wp.i18n.__(`Request selected files early.`,`jooosi-fon`)})]})]})]}),(0,Z.jsxs)(`div`,{className:`grid gap-5 xl:grid-cols-[minmax(0,1fr)_300px] xl:items-start`,children:[(0,Z.jsxs)(`div`,{className:`grid min-w-0 gap-5`,children:[(0,Z.jsx)(`style`,{children:Ae}),(0,Z.jsxs)(C,{className:`min-w-0`,spacing:`sm`,dense:!0,children:[(0,Z.jsx)(b,{className:`gap-3 px-4 py-3`,children:(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(S,{children:wp.i18n.__(`Font variants`,`jooosi-fon`)}),(0,Z.jsx)(x,{children:wp.i18n.__(`Edit essentials in the row; open a row only for advanced settings and files.`,`jooosi-fon`)})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsxs)(o,{type:`button`,size:`sm`,variant:`ghost`,onClick:J,disabled:a.fontFaces.length<2,children:[(0,Z.jsx)(ge,{}),wp.i18n.__(`Sort`,`jooosi-fon`)]}),(0,Z.jsxs)(o,{type:`button`,size:`sm`,variant:`outline`,onClick:K,children:[(0,Z.jsx)(ue,{}),wp.i18n.__(`Empty variant`,`jooosi-fon`)]}),(0,Z.jsxs)(o,{type:`button`,size:`sm`,onClick:Ee,disabled:N,children:[(0,Z.jsx)(te,{}),N?(0,Z.jsxs)(Z.Fragment,{children:[wp.i18n.__(`Inspecting files…`,`jooosi-fon`),` `,F&&`${F.completed}/${F.total}`]}):wp.i18n.__(`Upload files`,`jooosi-fon`)]})]})]})}),F&&(0,Z.jsxs)(`div`,{className:`mx-4 mb-3 rounded-lg border bg-muted/20 p-3`,role:`status`,"aria-live":`polite`,children:[(0,Z.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-3 text-xs`,children:[(0,Z.jsx)(`span`,{className:`text-muted-foreground`,children:wp.i18n.__(`Inspecting font metadata…`,`jooosi-fon`)}),(0,Z.jsxs)(`span`,{className:`font-medium tabular-nums`,children:[F.completed,`/`,F.total,F.active>0&&` · ${F.active} ${wp.i18n.__(`running`,`jooosi-fon`)}`]})]}),(0,Z.jsx)(`div`,{className:`h-1.5 overflow-hidden rounded-full bg-muted`,role:`progressbar`,"aria-label":wp.i18n.__(`Font inspection progress`,`jooosi-fon`),"aria-valuemin":0,"aria-valuemax":F.total,"aria-valuenow":F.completed,children:(0,Z.jsx)(`div`,{className:i(`h-full rounded-full bg-primary transition-[width] duration-200`,F.completed===0&&F.active>0&&`w-1/3 animate-pulse`),style:F.completed>0?{width:`${Math.round(F.completed/F.total*100)}%`}:void 0})})]}),(0,Z.jsxs)(y,{className:`p-0`,children:[a.fontFaces.length===0&&(0,Z.jsx)(`button`,{type:`button`,onClick:K,className:`grid min-h-44 w-full place-items-center border border-dashed bg-muted/20 p-8 text-center transition-colors hover:bg-muted/40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring`,children:(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(oe,{"aria-hidden":`true`,className:`mx-auto mb-3 size-7 text-primary`}),(0,Z.jsx)(`strong`,{className:`block text-sm`,children:wp.i18n.__(`Add your first font variant`,`jooosi-fon`)}),(0,Z.jsx)(`span`,{className:`mt-1 block text-xs text-muted-foreground`,children:wp.i18n.__(`Define its weight and style, then attach font files.`,`jooosi-fon`)})]})}),a.fontFaces.map((e,n)=>{let r=Ce.includes(e.id),c=e.isEnabled!==!1,l=String(e.weight).trim().includes(` `)?B:e.weight,u=String(e.width).trim().includes(` `)?`${V}%`:String(e.width||`100%`);return(0,Z.jsxs)(`section`,{className:i(`border-b last:border-b-0`,!c&&`bg-muted/20`),children:[(0,Z.jsxs)(`h3`,{className:`sr-only`,children:[wp.i18n.__(`Variant`,`jooosi-fon`),` `,n+1]}),(0,Z.jsxs)(`div`,{className:`grid gap-3 px-3 py-3 md:grid-cols-[44px_90px_110px_minmax(12rem,1fr)_auto] md:items-center`,children:[(0,Z.jsx)(g,{checked:c,onCheckedChange:t=>G(e.id,{isEnabled:t}),"aria-label":`${wp.i18n.__(`Include variant`,`jooosi-fon`)} ${n+1}`}),(0,Z.jsxs)(v,{children:[(0,Z.jsx)(_,{render:(0,Z.jsx)(p,{className:`h-8`,value:String(e.weight),onChange:t=>G(e.id,{weight:t.target.value}),"aria-label":`${wp.i18n.__(`Weight for variant`,`jooosi-fon`)} ${n+1}`})}),(0,Z.jsx)(se,{children:wp.i18n.__(`Weight`,`jooosi-fon`)})]}),(0,Z.jsxs)(v,{children:[(0,Z.jsx)(_,{render:(0,Z.jsxs)(h,{className:`h-8`,value:e.style,onChange:t=>G(e.id,{style:t.target.value}),"aria-label":`${wp.i18n.__(`Style for variant`,`jooosi-fon`)} ${n+1}`,children:[(0,Z.jsx)(`option`,{value:`normal`,children:`normal`}),(0,Z.jsx)(`option`,{value:`italic`,children:`italic`}),(0,Z.jsx)(`option`,{value:`oblique`,children:`oblique`}),![`normal`,`italic`,`oblique`].includes(e.style)&&(0,Z.jsx)(`option`,{value:e.style,children:e.style})]})}),(0,Z.jsx)(se,{children:wp.i18n.__(`Style`,`jooosi-fon`)})]}),(0,Z.jsx)(`div`,{className:i(`min-w-0 rounded-lg border bg-card px-3 py-2 transition-[background-color,color,opacity]`,!c&&`bg-muted/50 text-muted-foreground opacity-50`),children:(0,Z.jsx)(le,{value:ye,onChange:e=>R(e.target.value),"aria-label":`${wp.i18n.__(`Preview text for variant`,`jooosi-fon`)} ${n+1}`,placeholder:wp.i18n.__(`Type preview text…`,`jooosi-fon`),className:i(`h-auto min-w-0 border-0 bg-transparent p-0 shadow-none focus-visible:border-transparent focus-visible:ring-0`,!c&&`text-muted-foreground`),style:{fontFamily:a.family?`'${a.family}', sans-serif`:`inherit`,fontSize:`${z}px`,fontWeight:l,fontStyle:e.style,fontStretch:u}})}),(0,Z.jsxs)(`div`,{className:`flex items-center justify-end gap-1`,children:[(0,Z.jsx)(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":r?wp.i18n.__(`Close variant settings`,`jooosi-fon`):wp.i18n.__(`Open variant settings`,`jooosi-fon`),"aria-expanded":r,onClick:()=>q(e.id),children:(0,Z.jsx)(ee,{className:r?`rotate-180 transition-transform`:`transition-transform`})}),(0,Z.jsx)(o,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":wp.i18n.__(`Remove variant`,`jooosi-fon`),onClick:()=>s(t=>({...t,fontFaces:t.fontFaces.filter(t=>t.id!==e.id)})),children:(0,Z.jsx)(ae,{className:`text-destructive`})})]})]}),r&&(0,Z.jsxs)(`div`,{className:`grid gap-4 border-t bg-muted/20 p-4 sm:grid-cols-2 lg:grid-cols-6`,children:[(0,Z.jsx)(m,{label:(0,Z.jsx)(Q,{label:wp.i18n.__(`Width`,`jooosi-fon`),description:wp.i18n.__(`Value or variable range.`,`jooosi-fon`)}),children:(0,Z.jsx)(p,{value:String(e.width),onChange:t=>G(e.id,{width:t.target.value}),placeholder:`75% 125%`})}),(0,Z.jsx)(m,{label:(0,Z.jsx)(Q,{label:wp.i18n.__(`Display override`,`jooosi-fon`),description:wp.i18n.__(`Use a different font-display value for this variant.`,`jooosi-fon`)}),children:(0,Z.jsxs)(h,{value:e.display,onChange:t=>G(e.id,{display:t.target.value}),children:[(0,Z.jsx)(`option`,{value:``,children:wp.i18n.__(`Use family default`,`jooosi-fon`)}),Me.map(e=>(0,Z.jsx)(`option`,{children:e},e))]})}),(0,Z.jsx)(m,{label:(0,Z.jsx)(Q,{label:wp.i18n.__(`Unicode range`,`jooosi-fon`),description:`U+0000-00FF`}),children:(0,Z.jsx)(p,{value:e.unicodeRange,onChange:t=>G(e.id,{unicodeRange:t.target.value})})}),(0,Z.jsx)(m,{label:(0,Z.jsx)(Q,{label:wp.i18n.__(`Variant selector`,`jooosi-fon`),description:wp.i18n.__(`Apply this variant to matching elements.`,`jooosi-fon`)}),children:(0,Z.jsx)(p,{value:e.selector,onChange:t=>G(e.id,{selector:t.target.value}),placeholder:`.font-bold`})}),(0,Z.jsx)(m,{label:(0,Z.jsx)(Q,{label:wp.i18n.__(`Comment`,`jooosi-fon`),description:wp.i18n.__(`Optional comment for this variant.`,`jooosi-fon`)}),children:(0,Z.jsx)(p,{value:e.comment,onChange:t=>G(e.id,{comment:t.target.value})})}),(0,Z.jsx)(m,{label:(0,Z.jsx)(Q,{label:wp.i18n.__(`Preload variant`,`jooosi-fon`),description:wp.i18n.__(`Request this variant early.`,`jooosi-fon`)}),children:(0,Z.jsx)(g,{checked:e.preload,onCheckedChange:t=>G(e.id,{preload:t}),"aria-label":wp.i18n.__(`Preload variant`,`jooosi-fon`)})}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-t pt-4 sm:col-span-2 lg:col-span-6`,children:[e.files.map(n=>(0,Z.jsxs)(t,{variant:`outline`,children:[(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[`[`,n.extension,`]`]}),` `,n.name,(0,Z.jsxs)(`span`,{className:`text-muted-foreground`,children:[` · `,Ne(n)]}),(0,Z.jsx)(`button`,{type:`button`,className:`ml-1 rounded-sm text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,"aria-label":wp.i18n.__(`Remove file`,`jooosi-fon`),onClick:()=>G(e.id,{files:e.files.filter(e=>e.uid!==n.uid)}),children:(0,Z.jsx)(ce,{"aria-hidden":`true`,className:`size-3`})})]},n.uid)),(0,Z.jsxs)(o,{type:`button`,size:`sm`,variant:`outline`,onClick:()=>De(e.id),children:[(0,Z.jsx)(_e,{}),wp.i18n.__(`Add files`,`jooosi-fon`)]})]})]})]},e.id)})]}),a.fontFaces.length>0&&(0,Z.jsxs)(fe,{className:`flex-row flex-wrap items-center justify-end gap-3 px-4 py-3`,children:[(0,Z.jsx)(T,{compact:!0,label:wp.i18n.__(`Size`,`jooosi-fon`),value:z,suffix:`px`,min:12,max:96,onChange:be}),Le&&(0,Z.jsx)(T,{compact:!0,label:wp.i18n.__(`Width`,`jooosi-fon`),value:V,suffix:`%`,min:50,max:200,onChange:Se}),X&&(0,Z.jsx)(T,{compact:!0,label:wp.i18n.__(`Weight`,`jooosi-fon`),value:B,min:100,max:900,step:1,onChange:xe})]})]})]}),(0,Z.jsx)(`aside`,{className:`grid gap-5 xl:sticky xl:top-[calc(var(--wp-admin--admin-bar--height,32px)+5rem)]`,children:(0,Z.jsxs)(C,{stacked:!0,spacing:`sm`,children:[(0,Z.jsxs)(b,{children:[(0,Z.jsx)(S,{children:wp.i18n.__(`Publish`,`jooosi-fon`)}),(0,Z.jsx)(x,{children:wp.i18n.__(`Make this font available on your website.`,`jooosi-fon`)})]}),(0,Z.jsx)(y,{className:`grid gap-4 text-sm`,children:(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,Z.jsx)(`span`,{children:a.status?wp.i18n.__(`Publish`,`jooosi-fon`):wp.i18n.__(`Draft`,`jooosi-fon`)}),(0,Z.jsx)(g,{checked:a.status,onCheckedChange:e=>s({...a,status:e}),"aria-label":wp.i18n.__(`Publish status`,`jooosi-fon`)})]})}),(0,Z.jsxs)(fe,{className:`gap-2`,children:[(0,Z.jsxs)(o,{type:`submit`,className:`w-full`,disabled:k||N,children:[k?(0,Z.jsx)(ne,{}):(0,Z.jsx)(re,{"data-icon":`inline-start`}),wp.i18n.__(`Save`,`jooosi-fon`)]}),r&&(0,Z.jsxs)(o,{type:`button`,variant:`destructive`,className:`w-full`,onClick:ke,disabled:j||N,children:[j?(0,Z.jsx)(ne,{}):(0,Z.jsx)(ae,{}),wp.i18n.__(`Move to trash`,`jooosi-fon`)]})]})]})})]})]})}export{Le as CustomFontEditorPage}; |