laipower/wp-content/plugins/gp-premium/dist/font-library.js

11 lines
372 KiB
JavaScript
Raw Normal View History

(()=>{var e={771:e=>{var t;globalThis,t=()=>(()=>{var e={703:(e,t,n)=>{"use strict";var r=n(414);function o(){}function i(){}i.resetWarningCache=o,e.exports=function(){function e(e,t,n,o,i,s){if(s!==r){var a=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw a.name="Invariant Violation",a}}function t(){return e}e.isRequired=e;var n={array:e,bigint:e,bool:e,func:e,number:e,object:e,string:e,symbol:e,any:e,arrayOf:t,element:e,elementType:e,instanceOf:t,node:e,objectOf:t,oneOf:t,oneOfType:t,shape:t,exact:t,checkPropTypes:i,resetWarningCache:o};return n.PropTypes=n,n}},697:(e,t,n)=>{e.exports=n(703)()},414:e=>{"use strict";e.exports="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED"},921:(e,t)=>{"use strict";Symbol.for("react.element"),Symbol.for("react.portal"),Symbol.for("react.fragment"),Symbol.for("react.strict_mode"),Symbol.for("react.profiler"),Symbol.for("react.provider"),Symbol.for("react.context"),Symbol.for("react.server_context"),Symbol.for("react.forward_ref"),Symbol.for("react.suspense"),Symbol.for("react.suspense_list"),Symbol.for("react.memo"),Symbol.for("react.lazy"),Symbol.for("react.offscreen"),Symbol.for("react.module.reference")},864:(e,t,n)=>{"use strict";n(921)},251:(e,t,n)=>{"use strict";var r=n(196),o=Symbol.for("react.element"),i=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),s=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a={key:!0,ref:!0,__self:!0,__source:!0};t.jsx=function(e,t,n){var r,l={},u=null,c=null;for(r in void 0!==n&&(u=""+n),void 0!==t.key&&(u=""+t.key),void 0!==t.ref&&(c=t.ref),t)i.call(t,r)&&!a.hasOwnProperty(r)&&(l[r]=t[r]);if(e&&e.defaultProps)for(r in t=e.defaultProps)void 0===l[r]&&(l[r]=t[r]);return{$$typeof:o,type:e,key:u,ref:c,props:l,_owner:s.current}}},893:(e,t,n)=>{"use strict";e.exports=n(251)},196:e=>{"use strict";e.exports=window.React}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.nc=void 0;var r={};return(()=>{"use strict";n.r(r),n.d(r,{Autocomplete:()=>Be,Checkbox:()=>Ke,ColorPicker:()=>on,SortableList:()=>Uo,SortableListItem:()=>Ho,Stack:()=>jo,Table:()=>Wi});var e=n(196),t=n.n(e);const o=window.wp.element,i=window.wp.components,s=window.wp.i18n,a=window.wp.primitives;var l=n(893);const u=(0,l.jsx)(a.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,l.jsx)(a.Path,{d:"M12 3.2c-4.8 0-8.8 3.9-8.8 8.8 0 4.8 3.9 8.8 8.8 8.8 4.8 0 8.8-3.9 8.8-8.8 0-4.8-4-8.8-8.8-8.8zm0 16c-4 0-7.2-3.3-7.2-7.2C4.8 8 8 4.8 12 4.8s7.2 3.3 7.2 7.2c0 4-3.2 7.2-7.2 7.2zM11 17h2v-6h-2v6zm0-8h2V7h-2v2z"})});function c(e,t){if(null==e)return{};var n={};for(var r in e)if({}.hasOwnProperty.call(e,r)){if(t.indexOf(r)>=0)continue;n[r]=e[r]}return n}function d(){return d=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var r in n)({}).hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e},d.apply(null,arguments)}var h=n(697),f=n.n(h);n(864);const g=e=>"object"==typeof e&&null!=e&&1===e.nodeType,p=(e,t)=>(!t||"hidden"!==e)&&"visible"!==e&&"clip"!==e,m=(e,t)=>{if(e.clientHeight<e.scrollHeight||e.clientWidth<e.scrollWidth){const n=getComputedStyle(e,null);return p(n.overflowY,t)||p(n.overflowX,t)||(e=>{const t=(e=>{if(!e.ownerDocument||!e.ownerDocument.defaultView)return null;try{return e.ownerDocument.defaultView.frameElement}catch(e){return null}})(e);return!!t&&(t.clientHeight<e.scrollHeight||t.clientWidth<e.scrollWidth)})(e)}return!1},b=(e,t,n,r,o,i,s,a)=>i<e&&s>t||i>e&&s<t?0:i<=e&&a<=n||s>=
(0,t.__)("Edit Font: %s","gp-premium"),O)),(0,e.createElement)(Yn.Stack,{gap:"30px"},(0,e.createElement)("div",{className:"gp-font-library-edit__control"},(0,e.createElement)("strong",null,(0,t.__)("Font Status","gp-premium")),(0,e.createElement)("p",null,(0,t.__)("If a font is disabled, no font variants are added to the frontend of your site.","gp-premium")),(0,e.createElement)(o.ToggleControl,{checked:!m,label:m?(0,t.__)("Disabled","gp-premium"):(0,t.__)("Enabled","gp-premium"),onChange:e=>{b(!e)}})),(0,e.createElement)("div",{className:"gp-font-library-edit__control"},(0,e.createElement)("strong",null,(0,t.__)("Available Font Variants","gp-premium")),(0,e.createElement)("p",null,(0,t.__)("Enable or disable individual font variants on the frontend of your site.","gp-premium")),(0,e.createElement)("ul",{className:"gp-font-library-edit__variants",style:{opacity:m?"0.5":"1"},role:"list"},x&&(0,e.createElement)(e.Fragment,null,x?.map((({name:n,src:r,disabled:i=!1,deleteStatus:s=!1},a)=>(0,e.createElement)("li",{key:r,className:qn("gp-font-library-edit__variant",s&&"gp-font-library-edit__variant--delete")},(0,e.createElement)(o.CheckboxControl,{className:s?"delete-variant":"",disabled:m||s,label:n,checked:!i,onChange:e=>{const t=[...x];t[a].disabled=!e,S(t),t.every((e=>e.disabled))&&b(!0)},__nextHasNoMarginBottom:!0}),(0,e.createElement)(o.Button,{size:"compact",title:s?(0,t.__)("Undelete font variant","gp-premium"):(0,t.__)("Delete font variant","gp-premium"),onClick:()=>{const e=[...x];e[a].deleteStatus=!s,S(e)}},(0,e.createElement)(o.Icon,{size:"18",color:"#cc1818",icon:Zn("trash")}))))))))),(0,e.createElement)("details",{className:"gp-font-library-edit__advanced"},(0,e.createElement)("summary",null,(0,t.__)("Advanced Options","gp-premium")," "),(0,e.createElement)(Yn.Stack,{gap:"30px"},(0,e.createElement)("div",{className:"gp-font-library-edit__control"},(0,e.createElement)("strong",null,(0,t.__)("Font Display")),(0,e.createElement)("p",{className:"gp-font-library__text"},(0,t.__)("Specify the font-display value, used in the @font-face CSS. This value determines how your text displays as the webfont loads.","gp-premium")),(0,e.createElement)(o.SelectControl,{className:"gp-font-library-edit__control",value:E,options:[{label:"Auto",value:"auto"},{label:"Block",value:"block"},{label:"Fallback",value:"fallback"},{label:"Optional",value:"optional"},{label:"Swap",value:"swap"}],onChange:e=>{R(e)}})),(0,e.createElement)("div",{className:"gp-font-library-edit__control"},(0,e.createElement)("strong",null,(0,t.__)("Font Alias")),(0,e.createElement)("p",{className:"gp-font-library__text"},(0,t.__)("Specify an alias for this font that will be used as the font family name in CSS. If left blank the default font family name will be used.","gp-premium")),(0,e.createElement)(o.TextControl,{className:"gp-font-library-edit__control",label:(0,t.__)("Add Font Family Alias","gp-premium"),placeholder:(0,t.sprintf)(/* translators: Font family alias */
(0,t.__)("e.g. Custom %s","gp-premium"),O),value:v,onChange:w,help:`${k}: ${M};`})),(0,e.createElement)("div",{className:"gp-font-library-edit__control"},(0,e.createElement)("strong",null,(0,t.__)("Font Family Fallback")),(0,e.createElement)("p",{className:"gp-font-library__text"},(0,t.__)("Enter the CSS font-family fallback value you want to use for this font here. This appears after the font family name in the CSS.","gp-premium")),(0,e.createElement)(o.TextControl,{className:"gp-font-library-edit__control",label:(0,t.__)("Font Family","gp-premium"),placeholder:(0,t.__)("sans-serif, system-ui","gp-premium"),value:y,onChange:C,help:`font-family: ${M};`})),(0,e.createElement)("div",{className:"gp-font-library-edit__control"},(0,e.createElement)("strong",null,(0,t.__)("CSS Variable Suffix")),(0,e.createElement)("p",{className:"gp-font-library__text"},(0,t.__)("You may customize the CSS variable suffix for your font if you wish to change it.","gp-premium")),(0,e.createElement)(o.TextControl,{className:"gp-font-library-edit__control",label:(0,t.__)("CSS Variable suffix","gp-premium"),placeholder:I||n.slug,value:g,onChange:p,help:(0,e.createElement)(e.Fragment,null,`font-family: var(${k});`,25===g.length&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("br",null),(0,e.createElement)("strong",null,(0,t.__)("Max 25 characters","gp-premium")))),minLength:"1",maxLength:"25",max:"25"})),0===g.length&&(0,e.createElement)(o.Notice,{status:"warning",isDismissible:!1,className:"gp-font-library-edit__control-notice"},(0,t.__)("CSS Variable suffix cannot be empty. Please enter a valid suffix.","gp-premium")))),k!==n.cssVariable&&(0,e.createElement)(o.Notice,{status:"warning",isDismissible:!1},(0,t.__)("If you have used this font's css variable, changing the variable suffix may cause loss of visual styles.","gp-premium")),(0,e.createElement)(o.Flex,{className:"gp-font-library-edit__footer",alignItems:"center",gap:"20px",justifyContent:"flex-start"},(0,e.createElement)(o.FlexItem,null,(0,e.createElement)(o.Button,{title:(0,t.__)("Delete font and all its variants","gp-premium"),isDestructive:!0,size:"compact",variant:"primary",onClick:D},(0,t.__)("Delete","gp-premium"))),u&&(0,e.createElement)(o.FlexItem,null,(0,e.createElement)(o.Button,{title:(0,t.__)("Save font changes","gp-premium"),size:"compact",variant:"primary",onClick:async()=>{let e=m?"draft":"publish";Array.isArray(x)&&x?.every((({disabled:e})=>e))&&(e="draft");const r=[],o=[];if(x.forEach((e=>{e.deleteStatus?o.push(e):r.push({...e,deleteStatus:!1})})),0===r.length)if(window.confirm((0,t.__)("You've selected to delete ALL variants. This will also delete the font from the library. Click OK to proceed, or Cancel to undelete variants.","gp-premium")))F();else{const e=x.map((e=>({...e,deleteStatus:!1})));S(e)}else{const a={data:{newVariants:r,deleteVariants:o,fontDisplay:E,fallback:y,alias:v,cssVariable:k,status:e,id:n.id}};await Bn("update-font-post",a),s(!0),l({type:"success",message:(0,t.__)("Font changes saved.")}),c(!1),i(null)}}},(0,t.__)("Save","gp-premium"))))))},Qn=(0,e.createElement)(Un.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,e.createElement)(Un.Path,{d:"M10.6 6L9.4 7l4.6 5-4.6 5 1.2 1 5.4-6z"})),$n=(0,r.memo)((function({font:n,loading:r="lazy",fallbackText:i=""}){const{preview:s,fontFamily:a,name:l,alias:u}=n;return(0,e.createElement)("div",{className:"gp-font-library-preview"},s?(0,e.createElement)(e.Fragment,null,(0,e.createElement)("img",{className:"gp-font-library-preview__image",src:s,alt:(0,t.__)("A graphical rendering of the font family","gp-premium"),height:"23",loading:r}),(0,e.createElement)(o.VisuallyHidden,null,i||l)):(0,e.createElement)("span",{className:"gp-font-library-preview__fallback",style:{fontFamily:a}},l," ",u&&`(${u})`))})),er=(0,r.memo)((function({font:n,onClick:i,category:s=""}){const a=(0,r.useMemo)((()=>function({variants:e=[],fontFace:t=[]}){var n;let r=0;const o=e.length>0?e:t,i=null!==(n=o?.length)&&void 0!==n?n:0;return o.forEach((({disabled:e=!1})=>{e||r++})),{total:i,enabled:r}}(n)),[n]);return(0,e.createEl
(0,t._n)("%d variant","%d variants",a.total,"gp-premium"),a.total):(0,t.sprintf)(/* translators: %s: Number of enabled font variants. */
(0,t.__)("%s variants","gp-premium"),`${a.enabled}/${a.total}`),(0,e.createElement)(o.Icon,{icon:Qn})))}));function tr({fonts:n,setUpdateFontList:i,unsavedChanges:s,setUnsavedChanges:a,editFont:l,setEditFont:u}){const[c,d]=(0,r.useState)(null),[h,f]=(0,r.useState)(null);return(0,r.useEffect)((()=>{if(n)return document.head.appendChild(function(e){const t=document.getElementById("gp-custom-font-style");t&&t.parentNode.removeChild(t);const n=document.createElement("style");n.id="gp-custom-font-style";let r="";return e.forEach((e=>{const{name:t="",alias:n="",variants:o=[],fontDisplay:i="auto",preview:s=""}=e;if(s)return null;const a=n||t;o&&o.length>0&&o.filter((e=>!e.disabled)).forEach((e=>{r+=`@font-face {\n\tfont-display: ${i};\n\tfont-family: '${a}';\n\tfont-style: ${e.fontStyle};\n\tfont-weight: ${e.fontWeight};\n\tsrc: url('${e.src}')${(e=>{const t={woff:"woff",woff2:"woff2",ttf:"truetype",otf:"opentype"}[e.split(".").pop()]||null;return t?` format('${t}')`:""})(e.src)};\n}\n`}))})),n.textContent=r,n}(n?.response)),()=>{const e=document.getElementById("gp-custom-font-style");e&&document.head.removeChild(e)}}),[n]),(0,r.useEffect)((()=>{l&&(d(null),f(null))}),[l]),l?(0,e.createElement)(Jn,{editFont:l,setEditFont:u,setUpdateFontList:i,setDeleteNotice:d,setSaveNotice:f,unsavedChanges:s,setUnsavedChanges:a}):(0,e.createElement)("div",{className:"gp-font-library__tab"},(0,e.createElement)("div",{className:"gp-font-library__notices"},c&&(0,e.createElement)("div",{style:{margin:"0 0 20px 0"}},(0,e.createElement)(o.Notice,{status:c.type,onRemove:()=>d(null)},c.message)),h&&(0,e.createElement)("div",{style:{margin:"0 0 20px 0"}},(0,e.createElement)(o.Notice,{status:h.type,onRemove:()=>f(null)},h.message))),(0,e.createElement)("h2",null,(0,t.__)("Installed Fonts","gp-premium")),n?(0,e.createElement)("div",null,0===n?.response.length&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("p",null,(0,t.__)("No fonts have been installed yet.","gp-premium")),(0,e.createElement)("div",{style:{display:"flex",gap:"10px"}},(0,e.createElement)(o.Button,{variant:"primary",onClick:()=>{const e=document.querySelector(".gp-font-library__google-fonts");e&&e.click()}},(0,t.__)("Install Google Fonts","gp-premium")),(0,e.createElement)(o.Button,{variant:"primary",onClick:()=>{const e=document.querySelector(".gp-font-library__upload");e&&e.click()}},(0,t.__)("Upload Custom Fonts","gp-premium")))),n?.response.length>0&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("div",{style:{marginBottom:"30px",__marginTop:"-20px"}},(0,t.__)("Installed and enabled fonts are automatically available on the frontend of your site."))),n?.response.length>0&&(0,e.createElement)(e.Fragment,null,(0,e.createElement)("ul",{style:{marginBottom:"25px"},className:"gp-font-library__list",role:"list"},n.response.map((t=>(0,e.createElement)("li",{key:t.id},(0,e.createElement)(er,{font:t,onClick:()=>u(t),loading:"eager"}))))))):(0,e.createElement)(o.Spinner,null))}const nr=(0,e.createElement)(Un.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,e.createElement)(Un.Path,{d:"M14.6 7l-1.2-1L8 12l5.4 6 1.2-1-4.6-5z"})),rr=window.wp.compose,or=[{value:"latin",label:"Latin"},{value:"latin-ext",label:"Latin Extended"},{value:"bengali",label:"Bengali"},{value:"chinese-hongkong",label:"Chinese (Hong Kong)"},{value:"chinese-simplified",label:"Chinese (Simplified)"},{value:"chinese-traditional",label:"Chinese (Traditional)"},{value:"cyrillic",label:"Cyrillic"},{value:"cyrillic-ext",label:"Cyrillic Extended"},{value:"devanagari",label:"Devanagari"},{value:"greek",label:"Greek"},{value:"greek-ext",label:"Greek Extended"},{value:"gujarati",label:"Gujarati"},{value:"gurmukhi",label:"Gurmukhi"},{value:"hebrew",label:"Hebrew"},{value:"japanese",label:"Japanese"},{value:"kannada",label:"Kannada"},{value:"khmer",label:"Khmer"},{value:"korean",label:"Korean"},{value:"malayalam",label:"Malayalam"},{value:"math",label:"Math"},{value:"myanmar",label:"Myanmar"},{value:"oriya",label:"Oriya"},{value:"sinhala",label:"Sinhala"},{value:"symbols",label:"Symbols"},{value:"tamil",l
(0,t._n)("%d matching font","%d matching fonts",F.length,"gp-premium"),F.length)),F.length!==a.length&&(0,e.createElement)("span",null,"( ",(0,t.sprintf)(/* translators: %d: Total number of fonts. */
"%d total",a.length)," )"),A&&(0,e.createElement)(o.Button,{onClick:V,variant:"link"},(0,t.__)("Reset","gp-premium"))):(0,e.createElement)("span",null,(0,t.__)("No matching fonts found.","gp-premium"))),(0,e.createElement)("ul",{role:"list",className:"gp-font-library__list"},D.map((t=>{var n;const r=null!==(n=t.font_family_settings)&&void 0!==n?n:{};return(0,e.createElement)("li",{key:r.slug},(0,e.createElement)(er,{font:r,onClick:()=>v(t),category:t.categories[0]}))}))),(0,e.createElement)("nav",{className:"gp-font-library-google__pagination","aria-label":(0,t.__)("Font list pagination","gp-premium")},(0,e.createElement)("div",{className:"gp-font-library-google__pagination-numbers"},(0,e.createElement)(o.Button,{disabled:1===C,onClick:()=>x(C-1)},(0,t.__)("Previous","gp-premium")),(0,e.createElement)(o.SelectControl,{label:(0,t.__)("Choose Page","gp-premium"),value:C,onChange:e=>x(parseInt(e,10)),options:P,hideLabelFromVision:!0,__nextHasNoMarginBottom:!0}),(0,e.createElement)(o.Button,{disabled:D.length<u,onClick:()=>x(C+1)},(0,t.__)("Next","gp-premium"))),(0,e.createElement)(o.SelectControl,{label:(0,t.__)("Per Page","gp-premium"),value:S.category,onChange:e=>c(e),options:[{label:(0,t.__)("5","gp-premium"),value:5},{label:(0,t.__)("10","gp-premium"),value:10},{label:(0,t.__)("15","gp-premium"),value:15},{label:(0,t.__)("20","gp-premium"),value:20}],style:{width:"100px"},__nextHasNoMarginBottom:!0})))):(0,e.createElement)("div",{className:"gp-font-library-authorize-fonts"},(0,e.createElement)("h3",null,(0,t.__)("Connect to Google Fonts?","gp-premium")),(0,e.createElement)("p",null,(0,t.__)("To install fonts from Google you must give permission to connect directly to Google servers. The fonts you install will be downloaded from Google and stored on your site. Your site will then use these locally-hosted fonts.","gp-premium")),(0,e.createElement)("p",null,(0,t.__)("You can alternatively upload fonts directly on the Upload Custom Fonts tab.","gp-premium")),(0,e.createElement)(o.Button,{variant:"primary",onClick:()=>{L(!0)}},(0,t.__)("Allow access to Google Fonts","gp-premium"))))}const sr=(0,r.forwardRef)((function({icon:e,size:t=24,...n},o){return(0,r.cloneElement)(e,{width:t,height:t,...n,ref:o})})),ar=(0,e.createElement)(Un.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,e.createElement)(Un.Path,{d:"M16.7 7.1l-6.3 8.5-3.3-2.5-.9 1.2 4.5 3.4L17.9 8z"})),lr=(0,e.createElement)(Un.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,e.createElement)(Un.Path,{d:"M13 11.8l6.1-6.3-1-1-6.1 6.2-6.1-6.2-1 1 6.1 6.3-6.5 6.7 1 1 6.5-6.6 6.5 6.6 1-1z"})),ur=/([\p{Ll}\d])(\p{Lu})/gu,cr=/(\p{Lu})([\p{Lu}][\p{Ll}])/gu,dr=/(\d)\p{Ll}|(\p{L})\d/u,hr=/[^\p{L}\d]+/giu,fr="$1\0$2",gr="";function pr(e){let t=e.trim();t=t.replace(ur,fr).replace(cr,fr),t=t.replace(hr,"\0");let n=0,r=t.length;for(;"\0"===t.charAt(n);)n++;if(n===r)return[];for(;"\0"===t.charAt(r-1);)r--;return t.slice(n,r).split(/\0/g)}function mr(e){const t=pr(e);for(let e=0;e<t.length;e++){const n=t[e],r=dr.exec(n);if(r){const o=r.index+(r[1]??r[2]).length;t.splice(e,1,n.slice(0,o),n.slice(o))}}return t}function br(e,t){const[n,r,o]=function(e,t={}){const n=t.split??(t.separateNumbers?mr:pr),r=t.prefixCharacters??gr,o=t.suffixCharacters??gr;let i=0,s=e.length;for(;i<e.length;){const t=e.charAt(i);if(!r.includes(t))break;i++}for(;s>i;){const t=s-1,n=e.charAt(t);if(!o.includes(n))break;s=t}return[e.slice(0,i),n(e.slice(i,s)),e.slice(s)]}(e,t);return n+r.map((i=t?.locale,!1===i?e=>e.toLowerCase():e=>e.toLocaleLowerCase(i))).join(t?.delimiter??" ")+o;var i}const vr=Ln.map((e=>`.${e}`)).join(","),wr=({setUpdateFontList:n})=>{const[i,s]=(0,r.useState)([]),[a,l]=(0,r.useState)(!1),u=(0,r.useCallback)((async r=>{try{const n=await async function(e){return await Promise.all(e.map((async e=>await Hn(e))))}(r),o=await async function(e){const t=[];for(const n of e){const{name:e}=n;try{const r=await Bn("upload-fonts",{body:Nn(n)});t.push({status:"fulfilled",value:{...r.response,name:e}})}catch(n){t.push({status:"rejected",value:{message:n.message,name:e}})}}con
// translators: %s: font family name
(0,t.__)("%s installed.","gp-premium"),n.name)))),o.errors.map((n=>(0,e.createElement)("li",{className:"gp-font-library__result gp-font-library__result--failure",key:n.fontFamily},(0,e.createElement)(sr,{icon:lr,size:"1.25em"}),(0,t.sprintf)(
// translators: %s: font family name
(0,t.__)("%s install failed.","gp-premium"),n.name))))))}]))}catch(e){s((e=>[...e,{type:"error",message:(0,t.__)("There was an error installing fonts.")}])),console.error(e.message)}n(!0),l(!1)}),[n,l,s]),c=(0,r.useCallback)((async n=>{l(!0),s([]);const r=new Set,o=[...n];let i=!1;const a=o.map((async n=>{const o=await async function(e){const t=new N("Uploaded Font");try{const n=await Gn(e);return await t.fromDataBuffer(n,"font"),!0}catch(e){return console.error("Error: ",e),!1}}(n);if(!o)return i=!0,s([{type:"error",message:(0,e.createElement)(e.Fragment,null,(0,t.__)("Invalid or corrupted font file: ","gp-premium")," ",`${n.name}`)}]),null;if(r.has(n.name))return null;const a=n.name.split(".").pop().toLowerCase();return Ln.includes(a)?(r.add(n.name),n):null})),c=(await Promise.all(a)).filter((e=>null!==e));if(c.length>0)u(c);else{const e=i?(0,t.__)("Sorry, you are not allowed to upload this file type."):(0,t.__)("No fonts found to install.");console.error("Error: ",e),l(!1)}}),[u,l,s]);return(0,e.createElement)(e.Fragment,null,i&&(0,e.createElement)("div",{style:{margin:"0 0 20px 0"}},(0,e.createElement)(Yn.Stack,{gap:"20px"},i.map(((t,n)=>(0,e.createElement)(o.Notice,{key:`${t.type}-${n}`,status:t.type,onRemove:()=>s(i.toSpliced(n,1))},t.message))))),(0,e.createElement)("h2",null,(0,t.__)("Upload Fonts","gp-premium")),(0,e.createElement)("div",{style:{position:"relative"},className:"gp-font-library-upload"},(0,e.createElement)(o.DropZone,{onFilesDrop:function(e){c(e)}}),(0,e.createElement)("div",{className:"gp-font-library-modal__local-fonts"},(0,e.createElement)(o.FormFileUpload,{accept:vr,multiple:!0,onChange:function(e){c(e.target.files)},render:({openFileDialog:n})=>(0,e.createElement)(o.Button,{style:{background:"#f0f0f0",alignItems:"center",display:"flex",height:"256px",justifyContent:"center",width:"100%"},className:"gp-font-library-modal__upload-area",onClick:n},a&&(0,e.createElement)(o.Spinner,null),!a&&(0,t.__)("Click to upload"))}))),(0,e.createElement)("p",{style:{margin:"25px 0"}},(0,t.__)("Upload one or more fonts. Once uploaded, they will appear via the Font Library tab above. Supported formats are: .ttf, .otf, .woff, and .woff2.","gp-premium")))},yr=(t,n)=>(0,e.createElement)("div",{className:"gp-tab-header",id:n},t),Cr=async({setFonts:e,updateFontList:t,setUpdateFontList:n})=>{const r=await zn("get-fonts");e({success:r.success,response:r.response}),t&&n(!1)};var xr,Sr;xr=(0,e.createElement)((()=>{const[n,i]=(0,r.useState)(null),[a,l]=(0,r.useState)(!1),[u,c]=(0,r.useState)({google_gdpr:!1}),[d,h]=(0,r.useState)(!1),[f,g]=(0,r.useState)(null),[p,m]=(0,r.useState)("library-font"),[b,v]=(0,r.useState)([]),w=(0,r.useMemo)((()=>[{disabled:d,name:"library-font",title:yr((0,t.__)("Font Library","gp-premium"),"library_font_hd"),content:(0,e.createElement)(tr,{fonts:n,editFont:f,setEditFont:g,unsavedChanges:d,setUnsavedChanges:h,setUpdateFontList:l}),className:"gp-font-library__fonts"},{disabled:d,name:"upload-font",title:yr((0,t.__)("Upload Custom Fonts","gp-premium"),"upload_font_hd"),content:(0,e.createElement)(wr,{setFonts:i,setUpdateFontList:l}),className:"gp-font-library__upload"},{disabled:d,name:"google-font",title:yr((0,t.__)("Install Google Fonts","gp-premium"),"google_font_hd"),content:(0,e.createElement)(ir,{settings:u,setSettings:c,setUpdateFontList:l,googleFonts:b}),className:"gp-font-library__google-fonts"}]),[n,f,d,h,i,l,u,c,b]),y=(0,r.useCallback)((e=>{"library-font"===e||d||g(null),m(e)}),[d]);return(0,r.useEffect)((()=>{0===b.length&&"google-font"===p&&async function({setGoogleFonts:e,setNotice:n}){try{var r;const t=await async function(e="google-fonts"){const t={path:`/wp/v2/font-collections/${e}`,method:"GET"};return await s()(t)}("google-fonts"),n=null!==(r=t?.font_families)&&void 0!==r?r:[];if(!n)throw new Error(t);e(n)}catch(e){n({type:"error",message:(0,t.__)("An error occurred while fetching Google Fonts.","gp-premium")}),console.error(e.message)}}({setGoogleFonts:v})}),[p,b.length,v]),(0,r.useEffect)((()=>{a&&Cr({updateFontList:a,setUpdateFontList:l,setFonts:i}).catch((e=>console.er