var d=Object.defineProperty;var u=(s,e,t)=>e in s?d(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var a=(s,e,t)=>(u(s,typeof e!="symbol"?e+"":e,t),t);import{c2 as m,c8 as y,c9 as h,ca as b,bj as w,aU as j,aC as v,c3 as x,a1 as f,j as F,a7 as O,n as U,e as A,o as R}from"./index-a76b28be.js";import"./index-4d966268.js";import"./postmen-a4b10828.js";import{A as g}from"./AssetViewer-06848056.js";async function C(s){const e={uploadFiles:[],errors:[]};for(const t in s){const n=s[t],r=n.name.toLocaleLowerCase();(r.endsWith(".ttf")||r.endsWith(".otf")||r.endsWith(".woff"))&&e.uploadFiles.push({main:n})}return e}async function L(s){const e=m(s.main,"font.ttf");try{const t=e.name,n=y(t),r=h(t,n),o=await b.uploadBlob(`${t}.json`,e),i={fontName:r,fontUrl:encodeURI(o.url).replace(/\(/g,"%28").replace(/\)/g,"%29")};return new File([JSON.stringify(i)],r)}catch(t){console.error(t),w.error(`parse font file fail ${t}`)}return e}class p extends g{constructor(){super()}setViewAsset(e,t){const n=t.createChild("font_entity"),r=n.addComponent(f);r.font=e.engineObject,r.text=`ABCDEFGHIJKLM
NOPQRSTUVWXYZ
abcdefghijklm
nopqrstuvwxyz
1234567890`,this._entity=n}}const P=j(({asset:s})=>v.jsx(x,{asset:s}));p.previewer=P;class c{static update(e,t){this.entity?this.entity.isActive=!0:this.initScene(e),this.textRenderer.font=t.engineObject}static clear(){this.entity.isActive=!1}static initScene(e){const t=this.entity=e.createChild("font"),n=this.textRenderer=t.addComponent(f);n.text="Aa",n.fontSize=60}}a(c,"entity"),a(c,"textRenderer");var _=Object.defineProperty,T=Object.getOwnPropertyDescriptor,S=(s,e,t,n)=>{for(var r=n>1?void 0:n?T(e,t):e,o=s.length-1,i;o>=0;o--)(i=s[o])&&(r=(n?i(e,t,r):i(r))||r);return n&&r&&_(e,t,r),r};let l=class extends F{constructor(e){super(e);a(this,"urlObj")}async initByMain(e){this.urlObj=e;const t=URL.createObjectURL(e),n=await this.engine.resourceManager.load({url:t,type:O.Font});URL.revokeObjectURL(t),this.bindEngineObject(n)}};l=S([U({type:"Font",label:A("asset.font.title"),loaderType:"Font",extname:"font",viewer:p,thumbnail:c,importMenuConfig:{type:R.Upload,tooltip:"请上传字体文件(支持 TTF, OTF, WOFF)",accept:".ttf,.otf,.woff"},filterUploadFiles:C,preUpload:L})],l);export{l as FontAsset};
