2023-07-27 14:30:29 +08:00

2 lines
42 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("minimist"),require("ag-psd/initialize-canvas"),require("ag-psd"),require("fs-extra"),require("path"),require("crypto"),require("pinyin-pro"),require("canvas")):"function"==typeof define&&define.amd?define(["minimist","ag-psd/initialize-canvas","ag-psd","fs-extra","path","crypto","pinyin-pro","canvas"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).minimist,null,t.psd,t.fs,t.path,t.crypto,t.pinyinPro,t.canvas)}(this,(function(t,e,i,o,s,r,n,a){"use strict";function l(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}function c(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var o=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,o.get?o:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var p,d=l(t),h=c(i),u=l(o),_=l(s),f=l(r),v=l(a);function g(t,e,i,o){var s,r=arguments.length,n=r<3?e:null===o?o=Object.getOwnPropertyDescriptor(e,i):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,o);else for(var a=t.length-1;a>=0;a--)(s=t[a])&&(n=(r<3?s(n):r>3?s(e,i,n):s(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n}function y(t,e,i,o){return new(i||(i=Promise))((function(s,r){function n(t){try{l(o.next(t))}catch(t){r(t)}}function a(t){try{l(o.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?s(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(n,a)}l((o=o.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError,function(t){t[t.all=0]="all",t[t.v249=1]="v249",t[t.v342=2]="v342"}(p||(p={}));let m=(t,e)=>{t.__unserialization||(t.__unserialization=[]),t.__unserialization.push(e)};function b(t){return e=>{Object.defineProperty(e.prototype,"$__type__",{value:t,enumerable:!0})}}let x={},w={},S={},M=0;function P(t){return void 0!==t.constructor.__ver_tag_id__&&S[t.constructor.__ver_tag_id__]==t||(t.constructor.__ver_tag_id__=`${M}`,S[t.constructor.__ver_tag_id__]=t,M++),t.constructor.__ver_tag_id__}function F(t,e){for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)){if(i in t)continue;t[i]=e[i]}}function I(t,...e){for(let i=0;i<e.length;i++)F(t,e[i])}function j(t){return(e,i)=>{let o=e.constructor.name;o=P(e),!w[o]&&(w[o]={});let s=w[o];if(s[i]||(s[i]={}),p.all===t)for(const t in p)s[i][p[t]]=!0;else s[i][p[t]]=!0;var r=$(e.constructor);if(r){let t=P(r.prototype);!x[o]&&(x[o]=t);for(var n=$(r);n;){let e=P(n.prototype);!x[t]&&(x[t]=e),n=$(n)}for(;t;)t in w&&I(s,w[t]),t=x[t]}e._version||(e._version={}),e._version[o]=w[o]=s}}function $(t){var e=t.prototype,i=e&&Object.getPrototypeOf(e);return i&&i.constructor}const C="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",N=new Array(123);for(let t=0;t<123;++t)N[t]=64;for(let t=0;t<64;++t)N[C.charCodeAt(t)]=t;const z=N,O="0123456789abcdef".split(""),A=["","","",""],T=A.concat(A,"-",A,"-",A,"-",A,"-",A,A,A),E=T.map(((t,e)=>"-"===t?NaN:e)).filter(isFinite);let k={};for(let t=0;t<O.length;t++){let e=O[t];k[e]=t}const D=new class{uuid(){var t=(new Date).getTime();return globalThis.performance&&"function"==typeof globalThis.performance.now&&(t+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var i=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?i:3&i|8).toString(16)}))}decodeUuid(t){const e=t.split("@")[0];if(22!==e.length)return t;T[0]=t[0],T[1]=t[1];for(let e=2,i=2;e<22;e+=2){const o=z[t.charCodeAt(e)],s=z[t.charCodeAt(e+1)];T[E[i++]]=O[o>>2],T[E[i++]]=O[(3&o)<<2|s>>4],T[E[i++]]=O[15&s]}return t.replace(e,T.join(""))}compressUuid(t){const e=t.split("@")[0];if(36!==e.length)return t;let i=[];i[0]=e[0],i[1]=e[1];let o=e.replace("-","").replace("-","").replace("-","").replace("-","");for(let t=2,e=2;t<32;t+=3){const s=k[String.fromCharCode(o.charCodeAt(t))],r=k[String.fromCharCode(o.charCodeAt(t+1))],n=k[String.fromCharCode(o.charCodeAt(t+2))];i[e++]=C[(s<<2)+(r>>2)],i[e++]=C[((3&r)<<4)+n]}return t.replace(e,i.join(""))}isNumber(t){return!isNaN(parseFloat(t))&&isFinite(t)}};class L{constructor(){this.uuid="",this.idx=0,this.uuid=D.uuid()}toJSON(){var t;let e={};for(const i in this)if(Object.prototype.hasOwnProperty.call(this,i)){if(this.__unserialization&&-1!==this.__unserialization.indexOf(i))continue;let o=this.constructor.__ver_tag_id__;if(this._version&&(null===(t=this._version[o])||void 0===t?void 0:t[i])&&!this._version[o][i][p[q.editorVersion]])continue;const s=this[i];e[i]=s}return e}}g([m],L.prototype,"uuid",void 0),g([m],L.prototype,"idx",void 0);class B extends L{constructor(){super(),this._name="",this._objFlags=0,this.__type__=this.$__type__}}g([j(p.all)],B.prototype,"__type__",void 0),g([j(p.all)],B.prototype,"_name",void 0),g([j(p.all)],B.prototype,"_objFlags",void 0);class R extends B{constructor(){super(...arguments),this._enabled=!0,this.node=null,this._id="",this.__prefab=null}}g([j(p.all)],R.prototype,"_enabled",void 0),g([j(p.all)],R.prototype,"node",void 0),g([j(p.all)],R.prototype,"_id",void 0),g([j(p.v342)],R.prototype,"__prefab",void 0);let U=class extends R{constructor(){super(...arguments),this.duration=.1,this.zoomScale=1.2,this.clickEvents=[],this._N$interactable=!0,this._N$enableAutoGrayEffect=!1,this._N$transition=3,this.transition=3,this._N$target=null,this._interactable=!0,this._transition=3,this._duration=.1,this._zoomScale=1.2,this._target=null}updateWithLayer(t){}};g([j(p.v249)],U.prototype,"duration",void 0),g([j(p.v249)],U.prototype,"zoomScale",void 0),g([j(p.all)],U.prototype,"clickEvents",void 0),g([j(p.v249)],U.prototype,"_N$interactable",void 0),g([j(p.v249)],U.prototype,"_N$enableAutoGrayEffect",void 0),g([j(p.v249)],U.prototype,"_N$transition",void 0),g([j(p.v249)],U.prototype,"transition",void 0),g([j(p.v249)],U.prototype,"_N$target",void 0),g([j(p.v342)],U.prototype,"_interactable",void 0),g([j(p.v342)],U.prototype,"_transition",void 0),g([j(p.v342)],U.prototype,"_duration",void 0),g([j(p.v342)],U.prototype,"_zoomScale",void 0),g([j(p.v342)],U.prototype,"_target",void 0),U=g([b("cc.Button")],U);class W{constructor(t,e,i,o){this.r=Math.ceil(t||0),this.g=Math.ceil(e||0),this.b=Math.ceil(i||0),this.a=Math.ceil(o||0)}set(t){this.r=Math.ceil(t.r||0),this.g=Math.ceil(t.g||0),this.b=Math.ceil(t.b||0),this.a=Math.ceil(t.a||0)}toHEX(t="#rrggbb"){const e="0",i=[(this.r<16?e:"")+this.r.toString(16),(this.g<16?e:"")+this.g.toString(16),(this.b<16?e:"")+this.b.toString(16)];return"#rgb"===t?(i[0]=i[0][0],i[1]=i[1][0],i[2]=i[2][0]):"#rrggbbaa"===t&&i.push((this.a<16?e:"")+this.a.toString(16)),i.join("")}}class V extends W{constructor(){super(...arguments),this.__type__="cc.Color"}}class X{constructor(t=0,e=0){this.x=t||0,this.y=e||0}}let G=class extends X{constructor(){super(...arguments),this.__type__="cc.Vec2"}};G=g([b("cc.Vec2")],G);let Y=class extends R{constructor(){super(...arguments),this._materials=[],this._srcBlendFactor=770,this._dstBlendFactor=771,this._spriteFrame=null,this._type=0,this._sizeMode=1,this._fillType=0,this._fillCenter=new G,this._fillStart=0,this._fillRange=0,this._isTrimmedMode=!0,this._atlas=null,this._visFlags=0,this._customMaterial=null,this._color=new V(255,255,255,255),this._useGrayscale=!1}use9(){this._type=1,this._sizeMode=0}updateWithLayer(t){t.s9&&this.use9(),1==Math.abs(t.scale.x)&&1==Math.abs(t.scale.y)||(this._sizeMode=0),q.editorVersion>=p.v342&&(this._srcBlendFactor=2,this._dstBlendFactor=4)}setSpriteFrame(t){q.editorVersion>=p.v342?this._spriteFrame={__uuid__:`${t}@f9941`,__expectedType__:"cc.SpriteFrame"}:this._spriteFrame={__uuid__:t}}};g([j(p.v249)],Y.prototype,"_materials",void 0),g([j(p.all)],Y.prototype,"_srcBlendFactor",void 0),g([j(p.all)],Y.prototype,"_dstBlendFactor",void 0),g([j(p.all)],Y.prototype,"_spriteFrame",void 0),g([j(p.all)],Y.prototype,"_type",void 0),g([j(p.all)],Y.prototype,"_sizeMode",void 0),g([j(p.all)],Y.prototype,"_fillType",void 0),g([j(p.all)],Y.prototype,"_fillCenter",void 0),g([j(p.all)],Y.prototype,"_fillStart",void 0),g([j(p.all)],Y.prototype,"_fillRange",void 0),g([j(p.all)],Y.prototype,"_isTrimmedMode",void 0),g([j(p.all)],Y.prototype,"_atlas",void 0),g([j(p.v342)],Y.prototype,"_visFlags",void 0),g([j(p.v342)],Y.prototype,"_customMaterial",void 0),g([j(p.v342)],Y.prototype,"_color",void 0),g([j(p.v342)],Y.prototype,"_useGrayscale",void 0),Y=g([b("cc.Sprite")],Y);let H=class extends R{constructor(){super(...arguments),this._N$totalLength=0,this._N$barSprite=null,this._N$mode=0,this._N$progress=1,this._N$reverse=!1,this._barSprite=null,this._mode=0,this._totalLength=0,this._progress=1,this._reverse=!1}setBar(t){this._barSprite=this._N$barSprite={__id__:t.idx}}updateWithLayer(t){if(t.children)t:for(let e=0;e<t.children.length;e++){const i=t.children[e];if(i.attr.comps.bar){let t=i.uiObject;this._totalLength=this._N$totalLength=t._contentSize.width;for(let e=0;e<t.components.length;e++){const i=t.components[e];if(i instanceof Y){this.setBar(i);break t}}}}else console.error("CCProgressBar-> 只能作用在 组图层 上")}};g([j(p.v249)],H.prototype,"_N$totalLength",void 0),g([j(p.v249)],H.prototype,"_N$barSprite",void 0),g([j(p.v249)],H.prototype,"_N$mode",void 0),g([j(p.v249)],H.prototype,"_N$progress",void 0),g([j(p.v249)],H.prototype,"_N$reverse",void 0),g([j(p.v342)],H.prototype,"_barSprite",void 0),g([j(p.v342)],H.prototype,"_mode",void 0),g([j(p.v342)],H.prototype,"_totalLength",void 0),g([j(p.v342)],H.prototype,"_progress",void 0),g([j(p.v342)],H.prototype,"_reverse",void 0),H=g([b("cc.ProgressBar")],H);let J=class extends U{constructor(){super(...arguments),this._N$isChecked=!0,this.toggleGroup=null,this.checkMark=null,this.checkEvents=[],this._isChecked=!0,this._checkMark=null}setCheckMark(t){this._checkMark=this.checkMark={__id__:t.idx}}updateWithLayer(t){if(t.children)t:for(let e=0;e<t.children.length;e++){const i=t.children[e];if(i.attr.comps.check){let t=i.uiObject;for(let e=0;e<t.components.length;e++){const i=t.components[e];if(i instanceof Y){this.setCheckMark(i);break t}}}}else console.error("CCToggle-> 只能作用在 组图层 上")}};g([j(p.v249)],J.prototype,"_N$isChecked",void 0),g([j(p.v249)],J.prototype,"toggleGroup",void 0),g([j(p.v249)],J.prototype,"checkMark",void 0),g([j(p.all)],J.prototype,"checkEvents",void 0),g([j(p.v342)],J.prototype,"_isChecked",void 0),g([j(p.v342)],J.prototype,"_checkMark",void 0),J=g([b("cc.Toggle")],J);const q=new class{constructor(){this.help="\n--help | 帮助信息 \n--init | 初始化缓存文件 必须设置 --project-assets --cache 两项\n--force-img | 强制导出图片 即使在有缓存的情况下也要导出\n--input | 输入目录或者 psd 文件 非 init 时 必选 [dir or psd] \n--output | 输出目录 可选 缺省时为 --input [dir] \n--engine-version | 引擎版本 可选 [v249 | v342] \n--project-assets | 指定项目文件夹 可选 [dir] \n--cache-remake | 重新创建缓存文件 可选\n--cache | 缓存文件全路径 可选 [file-full-path] \n--config | 预制体配置 可选 [file-full-path] \n--pinyin | 中文转拼音 可选\n--img-only | 只导出图片 可选 \n--json | json 对象参数 插件工具使用 将所有参数用对象的形式编码成 base64 字符串 \n",this.editorVersion=p.v249,this.DEFAULT_SPRITE_FRAME_MATERIAL={[p.v249]:"eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432",[p.v342]:""},this.DEFAULT_LABEL_MATERIAL={[p.v249]:"eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432",[p.v342]:""},this.CompMappings={Btn:U,ProgressBar:H,Toggle:J},this.textOffsetY={default:0,36:0},this.textLineHeightOffset=0}get SpriteFrame_Material(){return this.DEFAULT_SPRITE_FRAME_MATERIAL[q.editorVersion]}get Label_Material(){return this.DEFAULT_LABEL_MATERIAL[q.editorVersion]}};let K=new class{DFS(t,e,i=0){if(!u.default.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);let o=u.default.readdirSync(t),s=i;i++,o.forEach((o=>{let r=_.default.join(t,o),n=u.default.lstatSync(r).isDirectory();null==e||e({isDirectory:n,fullPath:r,fileName:o,depth:s}),n&&this.DFS(r,e,i)}))}filterFile(t,e){if(!u.default.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);var i=[];return u.default.readdirSync(t).forEach((o=>{let s=_.default.join(t,o),r=u.default.lstatSync(s).isDirectory();if(!r){if(!e(o))return}r?i=i.concat(this.filterFile(s,e)):i.push(s)})),i}getFolderFiles(t,e){if(!u.default.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);let i=[];return u.default.readdirSync(t).forEach((o=>{let s=_.default.join(t,o);u.default.lstatSync(s).isDirectory()?"folder"===e&&i.push({fullPath:s,basename:o}):"file"===e&&i.push({fullPath:s,basename:o})})),i}writeFile(t,e){return y(this,void 0,void 0,(function*(){if("string"!=typeof e)try{e=JSON.stringify(e,null,2)}catch(t){return void console.log("FileUtils->writeFile ",t)}console.log(`写入文件 ${t}`);let i=_.default.dirname(t);yield u.default.mkdirp(i),yield u.default.writeFile(t,e),console.log(`写入完成 ${t} `)}))}getMD5(t){return"string"==typeof t&&(t=u.default.readFileSync(t)),f.default.createHash("md5").update(t).digest("hex")}};class Q{constructor(){this._imageMap=new Map,this._cachePath=null}initWithPath(t){if(!u.default.existsSync(t))return void console.log(`ImageCacheMgr-> 文件不存在: ${t}`);this._cachePath=t;let e=u.default.readFileSync(t,"utf-8");this.initWithFile(e)}initWithFile(t){let e=JSON.parse(t);this.initWithJson(e)}initWithJson(t){for(const e in t)Object.prototype.hasOwnProperty.call(t,e)&&this._imageMap.set(e,t[e])}set(t,e){this._imageMap.set(t,e)}has(t){return this._imageMap.has(t)}get(t){return this._imageMap.get(t)}saveImageMap(t){return y(this,void 0,void 0,(function*(){if(t||(t=this._cachePath),!t)return void console.log(`ImageCacheMgr-> 缓存路径 [${t}] 不存在,无法保存 `);let e=Object.create(null);this._imageMap.forEach(((t,i)=>{e[i]=t}));let i=JSON.stringify(e,null,2);yield K.writeFile(t,i)}))}loadImages(t){if(this._imageMap.size>0)return void console.error("ImageCacheMgr-> 暂时只能在 启动时加载");let e=K.filterFile(t,(t=>".png"==_.default.extname(t)));if(e)for(let t=0;t<e.length;t++){const i=e[t];let o=K.getMD5(i);console.log("ImageCacheMgr->缓存 ",i);let s=this._loadImageMetaWarp(`${i}.meta`);s&&this.set(o,s)}}_loadImageMetaWarp(t){let e=u.default.readFileSync(t,{encoding:"utf-8"}),i=null;switch(q.editorVersion){case p.v249:i=this._loadImageMeta249(e,t);break;case p.v342:i=this._loadImageMeta34x(e,t);break;default:console.log(`ImageCacheMgr-> 暂未实现 ${p[q.editorVersion]} 版本`)}return i}_loadImageMeta249(t,e){var i;let o=_.default.basename(e,".png.meta"),s=_.default.join(_.default.dirname(e),`${o}.png`),r=JSON.parse(t);return(null===(i=null==r?void 0:r.subMetas)||void 0===i?void 0:i[o])?{path:s,textureUuid:r.subMetas[o].uuid,uuid:r.uuid,isOutput:!0}:null}_loadImageMeta34x(t,e){var i;let o=_.default.basename(e,".png.meta"),s=_.default.join(_.default.dirname(e),`${o}.png`),r=JSON.parse(t);if(!(null===(i=null==r?void 0:r.subMetas)||void 0===i?void 0:i["6c48a"]))return null;let n=r.subMetas["6c48a"].uuid.replace("@6c48a","");return{path:s,textureUuid:n,uuid:n,isOutput:!0}}static getInstance(){return this._instance||(this._instance=new Q),this._instance}}Q._instance=null;const Z=Q.getInstance();class tt{constructor(){this._imageIdKeyMap=new Map,this._imageArray=new Map}add(t){var e;if(t.isIgnore()||t.isBind()||this._imageArray.has(t.md5)||this._imageArray.set(t.md5,t),void 0!==(null===(e=t.attr.comps.img)||void 0===e?void 0:e.id)){let e=t.attr.comps.img.id;this._imageIdKeyMap.has(e)&&console.warn(`ImageMgr-> ${t.source.name} 已有相同 @img{id:${e}},请检查 psd 图层`),this._imageIdKeyMap.set(e,t)}}getAllImage(){return this._imageArray}getSerialNumberImage(t){var e,i,o;let s=null!==(i=null===(e=t.attr.comps.flip)||void 0===e?void 0:e.bind)&&void 0!==i?i:null===(o=t.attr.comps.img)||void 0===o?void 0:o.bind;if(void 0!==s){if(this._imageIdKeyMap.has(s))return this._imageIdKeyMap.get(s);console.warn(`ImageMgr-> ${t.source.name} 未找到绑定的图像 {${s}},请检查 psd 图层`)}return t}clear(){this._imageIdKeyMap.clear(),this._imageArray.clear()}static getInstance(){return this._instance||(this._instance=new tt),this._instance}}tt._instance=null;const et=tt.getInstance();var it;!function(t){t[t.Doc=0]="Doc",t[t.Group=1]="Group",t[t.Text=2]="Text",t[t.Image=3]="Image"}(it||(it={}));class ot{constructor(t=0,e=0,i=0,o=0){"object"!=typeof t?(this.left=t||0,this.right=e||0,this.top=i||0,this.bottom=o||0):this.set(t)}set(t){this.left=t.left,this.right=t.right,this.top=t.top,this.bottom=t.bottom}}class st{constructor(t=0,e=0){this.width=t||0,this.height=e||0}}class rt{constructor(t=0,e=0,i=0){this.x=t||0,this.y=e||0,this.z=i||0}}class nt{constructor(t,e,i){var o,s,r,n;this.uuid=D.uuid(),this.source=t,this.parent=e,this.rootDoc=i,this.name=t.name,this.position=new X,this.size=new st,this.rect=new ot(t),this.anchorPoint=new X(.5,.5),this.hidden=!1,this.opacity=255,this.color=new W(255,255,255,255),console.log("PsdLayer->解析到图层 ",this.name),this.attr=this.parseNameRule(this.name),this.name=this.chineseToPinyin((null===(o=this.attr)||void 0===o?void 0:o.name)||this.name);let a=null===(s=this.attr)||void 0===s?void 0:s.comps.scale;this.scale=new rt(null!==(r=null==a?void 0:a.x)&&void 0!==r?r:1,null!==(n=null==a?void 0:a.y)&&void 0!==n?n:1,1)}parseNameRule(t){var e,i;if(!t)return;let o=(t=t.trim()).split("@");if(0===o.length)return void console.error("PsdLayer-> 名字解析错误");let s={name:null!==(i=null===(e=o[0])||void 0===e?void 0:e.replace(/\.|>|\/|\ /g,"_"))&&void 0!==i?i:"unknow",comps:{}};for(let e=1;e<o.length;e++){const i=o[e].trim();let r={},n=i.indexOf("{"),a=i;if(-1!=n){let e=i.indexOf("}");if(-1==e){console.log(`PsdLayer->${t} 属性 解析错误`);continue}let o=i.substring(n+1,e);a=i.substr(0,n),o=o.trim(),o.split(",").forEach((e=>{let i=(e=e.trim()).split(":");i.length?(i.map((t=>t.trim())),r[i[0]]=D.isNumber(i[1])?parseFloat(i[1]):i[1]):console.log(`PsdLayer->${t} 属性 解析错误`)}))}a=a.trim(),a=a.replace(":",""),s.comps[a]=r}return s.comps.ignore=s.comps.ignore||s.comps.ig,s.comps.ignorenode=s.comps.ignorenode||s.comps.ignode,s.comps.ignoreimg=s.comps.ignoreimg||s.comps.igimg,s.comps.Btn=s.comps.Btn||s.comps.btn,s.comps.ProgressBar=s.comps.ProgressBar||s.comps.progressBar,s.comps.Toggle=s.comps.Toggle||s.comps.toggle,s.comps.img&&s.comps.img.name&&(s.comps.img.name=this.chineseToPinyin(s.comps.img.name)),(s.comps.flip||s.comps.flipX||s.comps.flipY)&&(s.comps.flip=Object.assign({},s.comps.flip,s.comps.flipX,s.comps.flipY),s.comps.flipX&&(s.comps.flip.x=1),s.comps.flipY&&(s.comps.flip.y=1),void 0!==s.comps.flip.bind&&(s.comps.flip.y||(s.comps.flip.x=1),s.comps.flip.x&&(s.comps.flipX=Object.assign({},s.comps.flipX,s.comps.flip)),s.comps.flip.y&&(s.comps.flipY=Object.assign({},s.comps.flipY,s.comps.flip)))),s.comps.full&&s.comps.size&&console.warn(`PsdLayer->${s.name} 同时存在 @full 和 @size`),s}parseSource(){var t,e;let i=this.source;if(!this.parent)return!1;this.hidden=i.hidden,this.opacity=Math.round(255*i.opacity);let o=this.attr.comps.ar;return o&&(this.anchorPoint.x=null!==(t=o.x)&&void 0!==t?t:this.anchorPoint.x,this.anchorPoint.y=null!==(e=o.y)&&void 0!==e?e:this.anchorPoint.y),this.computeBasePosition(),!0}parseEffects(){}chineseToPinyin(t){if(!t||!nt.isPinyin)return t;let e=n.pinyin(t,{toneType:"none",type:"array"});return e=e.map((t=>t.slice(0,1).toUpperCase()+t.slice(1).toLowerCase())),e.join("")}computeBasePosition(){if(!this.rootDoc)return;let t=this.rect,e=t.right-t.left,i=t.bottom-t.top;this.size.width=e,this.size.height=i;let o=t.left,s=this.rootDoc.size.height-t.bottom;this.position.x=o,this.position.y=s}updatePositionWithAR(){if(!this.parent)return;let t=this.parent;for(;t;)this.position.x-=t.position.x,this.position.y-=t.position.y,t=t.parent;this.position.x=this.position.x-this.rootDoc.size.width*this.rootDoc.anchorPoint.x+this.size.width*this.anchorPoint.x,this.position.y=this.position.y-this.rootDoc.size.height*this.rootDoc.anchorPoint.y+this.size.height*this.anchorPoint.y}}nt.isPinyin=!1;class at extends nt{constructor(t,e,i){super(t,e,i),this.children=[],i&&(this.rect=new ot(0,i.size.width,0,i.size.height))}parseSource(){var t;return super.parseSource(),(null===(t=this.attr)||void 0===t?void 0:t.comps.full)||(this.resize(),this.computeBasePosition()),!0}resize(){let t=Number.MAX_SAFE_INTEGER,e=Number.MIN_SAFE_INTEGER,i=Number.MAX_SAFE_INTEGER,o=Number.MIN_SAFE_INTEGER;for(let s=0;s<this.children.length;s++){let r=this.children[s].rect;t=Math.min(r.left,t),e=Math.max(r.right,e),i=Math.min(r.top,i),o=Math.max(r.bottom,o)}this.rect.left=t,this.rect.right=e,this.rect.top=i,this.rect.bottom=o}onCtor(){}}class lt extends at{constructor(t){super(t,null,null),this.images=new Map,this.objectMap=new Map,this.objectArray=[],this.size=new st(t.width,t.height),this.rect=new ot(0,this.size.width,0,this.size.height)}pushObject(t){let e=this.objectArray.length;return t.idx=e,this.objectMap.set(t.uuid,e),this.objectArray.push(t),e}getObjectIdx(t){return this.objectMap.get(t)}getObject(t){let e=this.objectMap.get(t);return e<this.objectArray.length?this.objectArray[e]:null}onCtor(){super.onCtor()}}class ct{static safeBorder(t,e){var i,o,s,r;return e.l=(null!==(i=e.l)&&void 0!==i?i:e.r)||0,e.r=(null!==(o=e.r)&&void 0!==o?o:e.l)||0,e.t=(null!==(s=e.t)&&void 0!==s?s:e.b)||0,e.b=(null!==(r=e.b)&&void 0!==r?r:e.t)||0,e}static split(t,e){this.safeBorder(t,e);let i=t.width,o=t.height,s=e.l||i,r=e.r||i,n=e.t||o,a=e.b||o;if(0==e.b&&0==e.t&&0==e.l&&0==e.r)return t;if(e.l+e.r>i+4)return console.log("Texture9Utils-> 设置的九宫格 left right 数据不合理,请重新设置"),t;if(e.b+e.t>o+4)return console.log("Texture9Utils-> 设置的九宫格 bottom top 数据不合理,请重新设置"),t;let l=v.default.createCanvas(Math.min(i,e.l+e.r+4)||i,Math.min(o,e.b+e.t+4)||o),c=l.getContext("2d");return c.drawImage(t,0,0,s+4,n+4,0,0,s+4,n+4),c.drawImage(t,0,o-a,s+4,a,0,n+4,s+4,a),c.drawImage(t,i-s,0,r,n+4,s+4,0,r,n+4),c.drawImage(t,i-s,o-a,r,a,s+4,n+4,r,a),l}}class pt extends nt{constructor(t,e,i){var o;if(super(t,e,i),this.textureUuid=D.uuid(),this.imgName=(null===(o=this.attr.comps.img)||void 0===o?void 0:o.name)||this.name,this.attr.comps[".9"]){let t=this.attr.comps[".9"];this.s9=ct.safeBorder(this.source.canvas,t);let e=ct.split(this.source.canvas,t);this.source.canvas=e}let s=this.source.canvas;this.imgBuffer=s.toBuffer("image/png"),this.md5=K.getMD5(this.imgBuffer),this.textureSize=new st(s.width,s.height),this.scale=new rt((this.isFilpX()?-1:1)*this.scale.x,(this.isFilpY()?-1:1)*this.scale.y,1)}onCtor(){}isIgnore(){return!(!this.attr.comps.ignore&&!this.attr.comps.ignoreimg)}isBind(){var t,e;return void 0!==(null===(t=this.attr.comps.flip)||void 0===t?void 0:t.bind)||void 0!==(null===(e=this.attr.comps.img)||void 0===e?void 0:e.bind)}isFilpX(){var t;return void 0!==(null===(t=this.attr.comps.flipX)||void 0===t?void 0:t.bind)}isFilpY(){var t;return void 0!==(null===(t=this.attr.comps.flipY)||void 0===t?void 0:t.bind)}updatePositionWithAR(){if(!this.parent)return;let t=this.parent;for(;t;)this.position.x-=t.position.x,this.position.y-=t.position.y,t=t.parent;let e=this.isFilpX()?1-this.anchorPoint.x:this.anchorPoint.x,i=this.isFilpY()?1-this.anchorPoint.y:this.anchorPoint.y;this.position.x=this.position.x-this.rootDoc.size.width*this.rootDoc.anchorPoint.x+this.size.width*e,this.position.y=this.position.y-this.rootDoc.size.height*this.rootDoc.anchorPoint.y+this.size.height*i}}class dt extends nt{parseSource(){super.parseSource();let t=this.source.text,e=t.style;if(e){let t=e.fillColor;t&&(this.color=new W(t.r,t.g,t.b,255*t.a))}return this.text=t.text,this.fontSize=e.fontSize,this.offsetY=q.textOffsetY[this.fontSize]||q.textOffsetY.default||0,this.parseSolidFill(),this.parseStroke(),!0}onCtor(){}parseStroke(){var t,e;if(null===(t=this.source.effects)||void 0===t?void 0:t.stroke){let t=null===(e=this.source.effects)||void 0===e?void 0:e.stroke[0];if((null==t?void 0:t.enabled)&&"outside"===(null==t?void 0:t.position)){let e=t.color;this.outline={width:t.size.value,color:new W(e.r,e.g,e.b,255*t.opacity)}}}}parseSolidFill(){var t,e;if(null===(t=this.source.effects)||void 0===t?void 0:t.solidFill){let t=null===(e=this.source.effects)||void 0===e?void 0:e.solidFill;for(let e=0;e<t.length;e++){const i=t[e];if(i.enabled){let t=i.color;this.color=new W(t.r,t.g,t.b,255*i.opacity)}}}}}const ht=new class{parseLayerType(t){return"children"in t?"width"in t&&"height"in t?it.Doc:it.Group:"text"in t?it.Text:it.Image}parseLayer(t,e,i){let o=null,s=this.parseLayerType(t);switch(s){case it.Doc:case it.Group:{let r=null;if(s==it.Group){if(r=new at(t,e,i),r.attr.comps.ignorenode||r.attr.comps.ignore)return null}else r=new lt(t);for(let e=0;e<t.children.length;e++){const o=t.children[e];let s=this.parseLayer(o,r,i||r);s?s.attr.comps.ignorenode||s.attr.comps.ignore||r.children.push(s):console.error("图层解析错误")}o=r}break;case it.Image:{if(!t.canvas)return console.error(`Parser-> 空图层 ${null==t?void 0:t.name}`),null;let s=o=new pt(t,e,i);et.add(s),s.isIgnore()||s.isBind()||Z.has(s.md5)||Z.set(s.md5,{uuid:s.uuid,textureUuid:s.textureUuid})}break;case it.Text:o=new dt(t,e,i)}return o.layerType=s,o.parseSource(),o.onCtor(),o}};class ut extends L{constructor(){super(),this.__type__="cc.CompPrefabInfo",this.fileId="",this.fileId=D.compressUuid(this.uuid)}}let _t=class extends st{constructor(){super(...arguments),this.__type__="cc.Size"}};_t=g([b("cc.Size")],_t);let ft=class{constructor(){this.__type__="TypedArray",this.ctor="Float64Array",this.array=[]}setPosition(t,e,i){this.array[0]=t,this.array[1]=e,this.array[2]=i}setRotation(t,e,i,o){this.array[3]=t,this.array[4]=e,this.array[5]=i,this.array[6]=o}setScale(t,e,i){this.array[7]=t,this.array[8]=e,this.array[9]=i}};ft=g([b("TypedArray")],ft);class vt extends rt{constructor(){super(...arguments),this.__type__="cc.Vec3"}}let gt=class extends B{constructor(t){super(),this._parent=null,this._children=[],this._active=!0,this._components=[],this._prefab=null,this._id="",this._opacity=255,this._color=new V(255,255,255,255),this._contentSize=new _t,this._anchorPoint=new G(0,0),this._trs=new ft,this._eulerAngles=new vt,this._skewX=0,this._skewY=0,this._is3DNode=!1,this._groupIndex=0,this.groupIndex=0,this._renderEnable=!1,this._bfsRenderFlag=!1,this._lpos=new vt,this._lrot=new vt,this._lscale=new vt,this._euler=new vt,this._layer=33554432,this.psdDoc=null,this.components=[],this.children=[],t&&(this.psdDoc=t,t.pushObject(this))}addComponent(t){t.node={__id__:this.idx};let e=this.psdDoc.pushObject(t);this._components.push({__id__:e}),this.components.push(t),q.editorVersion>=p.v342&&this.addCompPrefabInfo(t)}addCompPrefabInfo(t){let e=new ut,i=this.psdDoc.pushObject(e);t.__prefab={__id__:i}}addChild(t){this._children.push({__id__:t.idx}),t._parent={__id__:this.idx},this.children.push(t)}};g([j(p.all)],gt.prototype,"_parent",void 0),g([j(p.all)],gt.prototype,"_children",void 0),g([j(p.all)],gt.prototype,"_active",void 0),g([j(p.all)],gt.prototype,"_components",void 0),g([j(p.all)],gt.prototype,"_prefab",void 0),g([j(p.all)],gt.prototype,"_id",void 0),g([j(p.v249)],gt.prototype,"_opacity",void 0),g([j(p.v249)],gt.prototype,"_color",void 0),g([j(p.v249)],gt.prototype,"_contentSize",void 0),g([j(p.v249)],gt.prototype,"_anchorPoint",void 0),g([j(p.v249)],gt.prototype,"_trs",void 0),g([j(p.v249)],gt.prototype,"_eulerAngles",void 0),g([j(p.v249)],gt.prototype,"_skewX",void 0),g([j(p.v249)],gt.prototype,"_skewY",void 0),g([j(p.v249)],gt.prototype,"_is3DNode",void 0),g([j(p.v249)],gt.prototype,"_groupIndex",void 0),g([j(p.v249)],gt.prototype,"groupIndex",void 0),g([j(p.v249)],gt.prototype,"_renderEnable",void 0),g([j(p.v249)],gt.prototype,"_bfsRenderFlag",void 0),g([j(p.v342)],gt.prototype,"_lpos",void 0),g([j(p.v342)],gt.prototype,"_lrot",void 0),g([j(p.v342)],gt.prototype,"_lscale",void 0),g([j(p.v342)],gt.prototype,"_euler",void 0),g([j(p.v342)],gt.prototype,"_layer",void 0),g([m],gt.prototype,"psdDoc",void 0),g([m],gt.prototype,"components",void 0),g([m],gt.prototype,"children",void 0),gt=g([b("cc.Node")],gt);class yt extends L{constructor(){super(),this.__type__="cc.PrefabInfo",this.root={__id__:1},this.asset={__id__:0},this.fileId="",this.sync=!1,this.fileId=D.compressUuid(this.uuid)}}g([j(p.all)],yt.prototype,"__type__",void 0),g([j(p.all)],yt.prototype,"root",void 0),g([j(p.all)],yt.prototype,"asset",void 0),g([j(p.all)],yt.prototype,"fileId",void 0),g([j(p.all)],yt.prototype,"sync",void 0);let mt=class extends B{constructor(){super(...arguments),this._native="",this.data=null,this.optimizationPolicy=0,this.asyncLoadAssets=!1,this.readonly=!1,this.persistent=!1}};g([j(p.all)],mt.prototype,"_native",void 0),g([j(p.all)],mt.prototype,"data",void 0),g([j(p.all)],mt.prototype,"optimizationPolicy",void 0),g([j(p.all)],mt.prototype,"asyncLoadAssets",void 0),g([j(p.v249)],mt.prototype,"readonly",void 0),g([j(p.v342)],mt.prototype,"persistent",void 0),mt=g([b("cc.Prefab")],mt);let bt=class extends R{constructor(){super(...arguments),this._srcBlendFactor=770,this._dstBlendFactor=771,this._string="",this._fontSize=0,this._lineHeight=0,this._enableWrapText=!0,this._isSystemFontUsed=!0,this._spacingX=0,this._underlineHeight=0,this._materials=[],this._N$string="",this._N$file=null,this._batchAsBitmap=!1,this._styleFlags=0,this._N$horizontalAlign=1,this._N$verticalAlign=1,this._N$fontFamily="Arial",this._N$overflow=0,this._N$cacheMode=0,this._visFlags=0,this._customMaterial=null,this._color=new V(255,255,255,255),this._overflow=0,this._cacheMode=0,this._horizontalAlign=1,this._verticalAlign=1,this._actualFontSize=0,this._isItalic=!1,this._isBold=!1,this._isUnderline=!1}updateWithLayer(t){this._fontSize=t.fontSize,this._string=this._N$string=t.text,this._lineHeight=this._fontSize+q.textLineHeightOffset,q.editorVersion>=p.v342&&(this._srcBlendFactor=2,this._dstBlendFactor=4)}};g([j(p.all)],bt.prototype,"_srcBlendFactor",void 0),g([j(p.all)],bt.prototype,"_dstBlendFactor",void 0),g([j(p.all)],bt.prototype,"_string",void 0),g([j(p.all)],bt.prototype,"_fontSize",void 0),g([j(p.all)],bt.prototype,"_lineHeight",void 0),g([j(p.all)],bt.prototype,"_enableWrapText",void 0),g([j(p.all)],bt.prototype,"_isSystemFontUsed",void 0),g([j(p.all)],bt.prototype,"_spacingX",void 0),g([j(p.all)],bt.prototype,"_underlineHeight",void 0),g([j(p.v249)],bt.prototype,"_materials",void 0),g([j(p.v249)],bt.prototype,"_N$string",void 0),g([j(p.v249)],bt.prototype,"_N$file",void 0),g([j(p.v249)],bt.prototype,"_batchAsBitmap",void 0),g([j(p.v249)],bt.prototype,"_styleFlags",void 0),g([j(p.v249)],bt.prototype,"_N$horizontalAlign",void 0),g([j(p.v249)],bt.prototype,"_N$verticalAlign",void 0),g([j(p.v249)],bt.prototype,"_N$fontFamily",void 0),g([j(p.v249)],bt.prototype,"_N$overflow",void 0),g([j(p.v249)],bt.prototype,"_N$cacheMode",void 0),g([j(p.v342)],bt.prototype,"_visFlags",void 0),g([j(p.v342)],bt.prototype,"_customMaterial",void 0),g([j(p.v342)],bt.prototype,"_color",void 0),g([j(p.v342)],bt.prototype,"_overflow",void 0),g([j(p.v342)],bt.prototype,"_cacheMode",void 0),g([j(p.v342)],bt.prototype,"_horizontalAlign",void 0),g([j(p.v342)],bt.prototype,"_verticalAlign",void 0),g([j(p.v342)],bt.prototype,"_actualFontSize",void 0),g([j(p.v342)],bt.prototype,"_isItalic",void 0),g([j(p.v342)],bt.prototype,"_isBold",void 0),g([j(p.v342)],bt.prototype,"_isUnderline",void 0),bt=g([b("cc.Label")],bt);let xt=class extends R{constructor(){super(...arguments),this._color=new V(255,255,255,255),this._width=1}updateWithLayer(t){this._width=t.outline.width,this._color.set(t.outline.color)}};g([j(p.all)],xt.prototype,"_color",void 0),g([j(p.all)],xt.prototype,"_width",void 0),xt=g([b("cc.LabelOutline")],xt);class wt{constructor(){this.textObjects=[]}test(){const t=_.default.join(__dirname,"..","out");this.parsePsd("./test-img-only/境界奖励-优化.psd",t)}exec(t){return y(this,void 0,void 0,(function*(){if(!this.checkArgs(t))return;if(u.default.lstatSync(t.input).isDirectory())t.output||(t.output=_.default.join(t.input,"psd2ui")),this.parsePsdDir(t.input,t.output);else{if(!t.output){let e=_.default.dirname(t.input);t.output=_.default.join(e,"psd2ui")}this.parsePsd(t.input,t.output)}}))}checkArgs(t){return t.input?!!u.default.existsSync(t.input)||(console.error(`输入路径不存在: ${t.input}`),!1):(console.error("请设置 --input"),!1)}parsePsdDir(t,e){return y(this,void 0,void 0,(function*(){u.default.emptyDirSync(e);let i=K.filterFile(t,(t=>".psd"==_.default.extname(t)));for(let t=0;t<i.length;t++){const o=i[t];yield this.parsePsd(o,e)}}))}parsePsd(t,e){return y(this,void 0,void 0,(function*(){et.clear(),this.textObjects.length=0,console.log("========================================="),console.log(`处理 ${t} 文件`);let i=_.default.basename(t,".psd"),o=u.default.readFileSync(t);const s=h.readPsd(o);let r=ht.parseLayer(s);r.name=i;let n=_.default.join(e,i),a=_.default.join(n,"textures");u.default.mkdirsSync(n),u.default.emptyDirSync(n),u.default.mkdirsSync(a),yield this.saveImage(a),yield this.saveTextFile(r,n),console.log(`psd2ui ${t} 处理完成`)}))}saveImage(t){let e=et.getAllImage(),i=0;e.forEach(((e,o)=>{let s=et.getSerialNumberImage(e),r=`${s.imgName}_${i}`;console.log(`保存图片 [${s.imgName}] 重命名为 [${r}] md5: ${s.md5}`);let n=_.default.join(t,`${r}.png`);u.default.writeFileSync(n,s.imgBuffer),i++}))}saveTextFile(t,e){this.scanText(t,t);let i=JSON.stringify(this.textObjects,null,2),o=_.default.join(e,"text.txt");u.default.writeFileSync(o,i,{encoding:"utf-8"})}scanText(t,e){if(t instanceof at)for(let i=0;i<t.children.length;i++){const o=t.children[i];this.scanText(o,e)}else if(t instanceof dt){let e={text:t.text,fontSize:t.fontSize,color:`#${t.color.toHEX()}`};t.outline&&(e.outlineWidth=t.outline.width,e.outlineColor=`#${t.outline.color.toHEX()}`),this.textObjects.push(e)}}static getInstance(){return this._instance||(this._instance=new wt),this._instance}}wt._instance=null;let St=wt.getInstance(),Mt=class extends R{constructor(){super(...arguments),this._opacity=255}updateWithLayer(t){}};g([j(p.v342)],Mt.prototype,"_opacity",void 0),Mt=g([b("cc.UIOpacity")],Mt);let Pt=class extends R{constructor(){super(...arguments),this._contentSize=new _t,this._anchorPoint=new G(0,0)}updateWithLayer(t){}};g([j(p.v342)],Pt.prototype,"_contentSize",void 0),g([j(p.v342)],Pt.prototype,"_anchorPoint",void 0),Pt=g([b("cc.UITransform")],Pt),console.log("当前目录: ",__dirname);const Ft=process.argv.slice(2),It=d.default(Ft);let jt=new class{constructor(){this.spriteFrameMetaContent="",this.prefabMetaContent="",this.psdConfig=null,this.isForceImg=!1}test(){return y(this,void 0,void 0,(function*(){const t=_.default.join(__dirname,"..","out");this.loadPsdConfig(_.default.join(__dirname,"../test/test.config.json")),yield Z.initWithPath("E:\\Git\\ccc-framework-3d\\tools\\psd2ui\\cache\\cache.json"),yield this.loadMetaTemplete();let e="./test/demo.psd";e="./test/活动icon.psd",this.parsePsd("./test/活动icon.psd",t),yield Z.saveImageMap(),console.log("psd2ui 导出完成")}))}loadMetaTemplete(){return y(this,void 0,void 0,(function*(){this.spriteFrameMetaContent=u.default.readFileSync(_.default.join(__dirname,`../assets/cc/meta/CCSpriteFrame.meta.${p[q.editorVersion]}`),"utf-8"),this.prefabMetaContent=u.default.readFileSync(_.default.join(__dirname,`../assets/cc/meta/CCPrefab.meta.${p[q.editorVersion]}`),"utf-8")}))}loadPsdConfig(t){return y(this,void 0,void 0,(function*(){if(!u.default.existsSync(t))return void console.log(`Main-> 配置 ${t} 不存在`);let e=u.default.readFileSync(t,"utf-8");this.psdConfig=JSON.parse(e);for(const t in this.psdConfig)t in q&&("object"==typeof this.psdConfig[t]?q[t]=Object.assign({},q[t],this.psdConfig[t]):q[t]=this.psdConfig[t]||q[t])}))}exec(t){return y(this,void 0,void 0,(function*(){if((t=function(t){if(t.json){let e=t.json;t=JSON.parse(Buffer.from(e,"base64").toString())}return t.help=t.help||t.h,t.input=t.input||t.in,t.output=t.output||t.out,t["engine-version"]=t["engine-version"]||t.ev,t["project-assets"]=t["project-assets"]||t.p,t["cache-remake"]=t["cache-remake"]||t.crm,t["force-img"]=t["force-img"]||t.fimg,t.pinyin=t.pinyin||t.py,t.cache=t.cache||t.c,t.init=t.init||t.i,t.config=t.config,t}(t)).help)return console.log("help:\n",q.help),!1;if(t["img-only"])return St.exec(t),!0;let e=()=>y(this,void 0,void 0,(function*(){t.cache&&(u.default.mkdirsSync(_.default.dirname(t.cache)),yield Z.saveImageMap(t.cache))}));if(t["engine-version"]&&(q.editorVersion=p[t["engine-version"]]),console.log(`Main-> 数据版本 ${p[q.editorVersion]}`),!t.init||t["project-assets"]&&t.cache){if(t["project-assets"]&&(!u.default.existsSync(t.cache)||t["cache-remake"]||t.init)&&(yield Z.loadImages(t["project-assets"]),e(),t.init))console.log("psd2ui 缓存完成");else if(this.checkArgs(t)){if(t.cache&&(yield Z.initWithPath(t.cache)),yield this.loadMetaTemplete(),t.config&&(yield this.loadPsdConfig(t.config)),this.isForceImg=!!t["force-img"],nt.isPinyin=t.pinyin,u.default.lstatSync(t.input).isDirectory())t.output||(t.output=_.default.join(t.input,"psd2ui")),this.parsePsdDir(t.input,t.output);else{if(!t.output){let e=_.default.dirname(t.input);t.output=_.default.join(e,"psd2ui")}this.parsePsd(t.input,t.output)}yield e(),console.log("psd2ui 导出完成")}}else console.log("psd2ui --init 无法处理,请设置 --project-assets")}))}checkArgs(t){if(!t.input)return console.error("请设置 --input"),!1;if(!u.default.existsSync(t.input))return console.error(`输入路径不存在: ${t.input}`),!1;if(t["engine-version"]){switch(p[t["engine-version"]]){case p.v249:case p.v342:break;default:return console.log(`暂未实现该引擎版本 ${t["engine-version"]}`),!1}}return!0}parsePsdDir(t,e){return y(this,void 0,void 0,(function*(){let i=K.filterFile(t,(t=>".psd"==_.default.extname(t)));for(let t=0;t<i.length;t++){const o=i[t];yield this.parsePsd(o,e)}}))}parsePsd(t,e){return y(this,void 0,void 0,(function*(){et.clear(),console.log("========================================="),console.log(`处理 ${t} 文件`);let i=_.default.basename(t,".psd"),o=u.default.readFileSync(t);const s=h.readPsd(o);let r=ht.parseLayer(s);r.name=i;let n=_.default.join(e,i),a=_.default.join(n,"textures");u.default.mkdirsSync(n),u.default.mkdirsSync(a),yield this.saveImage(a),yield this.buildPrefab(r),yield this.savePrefab(r,n),console.log(`psd2ui ${t} 处理完成`)}))}buildPrefab(t){let e=new mt;t.pushObject(e);let i=this.createCCNode(t,t);e.data={__id__:i.idx},this.postUIObject(t,t)}createCCNode(t,e){var i,o,s;let r=new gt(e);if(t.uiObject=r,r._name=t.name,r._active=!t.hidden,r._opacity=t.opacity,q.editorVersion>=p.v342&&255!==t.opacity){let e=new Mt;e._opacity=t.opacity,e.updateWithLayer(t),r.addComponent(e)}let n=new _t(t.size.width,t.size.height);if(null===(i=t.attr)||void 0===i?void 0:i.comps.size){let e=t.attr.comps.size;n.width=null!==(o=e.w)&&void 0!==o?o:n.width,n.height=null!==(s=e.h)&&void 0!==s?s:n.height}n.width=Math.round(Math.abs(n.width/t.scale.x)),n.height=Math.round(Math.abs(n.height/t.scale.y));let a=0;if(t instanceof dt&&(a=t.offsetY),r._contentSize=n,t.updatePositionWithAR(),r._trs.setPosition(t.position.x,t.position.y+a,0),r._trs.setRotation(0,0,0,1),r._trs.setScale(t.scale.x,t.scale.y,t.scale.z),r._anchorPoint=new G(t.anchorPoint.x,t.anchorPoint.y),q.editorVersion>=p.v342){r._lpos=new vt(t.position.x,t.position.y+a,0),r._lrot=new vt(0,0,0),r._lscale=new vt(t.scale.x,t.scale.y,t.scale.z),r._euler=new vt;let e=new Pt;e._contentSize=n,e._anchorPoint=r._anchorPoint,e.updateWithLayer(t),r.addComponent(e)}if(t instanceof at)for(let i=0;i<t.children.length;i++){const o=t.children[i];let s=this.createCCNode(o,e);s&&r.addChild(s)}else if(t instanceof pt){let e=new Y;if(r.addComponent(e),e._materials.push({__uuid__:q.SpriteFrame_Material}),e.updateWithLayer(t),t.isIgnore());else{let i=et.getSerialNumberImage(t),o=Z.get(i.md5);e.setSpriteFrame(o?o.textureUuid:i.textureUuid)}this.applyConfig(e)}else if(t instanceof dt){let e=new bt;if(r.addComponent(e),r._color.set(t.color),e._color.set(t.color),e._materials.push({__uuid__:q.Label_Material}),e.updateWithLayer(t),this.applyConfig(e),t.outline){let e=new xt;r.addComponent(e),e.updateWithLayer(t),this.applyConfig(e)}}if(t.attr)for(const e in t.attr.comps)if(Object.prototype.hasOwnProperty.call(t.attr.comps,e)&&t.attr.comps[e]){let i=q.CompMappings[e];if(i){let e=new i;r.addComponent(e),e.updateWithLayer(t),this.applyConfig(e)}}return this.createPrefabInfo(t,e),r}createPrefabInfo(t,e){let i=t.uiObject,o=new yt,s=e.pushObject(o);i._prefab={__id__:s}}postUIObject(t,e){}saveImage(t){et.getAllImage().forEach(((e,i)=>{let o=et.getSerialNumberImage(e),s=Z.get(o.md5);if(!this.isForceImg&&(null==s?void 0:s.isOutput))return void console.log(`已有相同资源,不再导出 [${e.imgName}] md5: ${e.md5}`);console.log(`保存图片 [${o.imgName}] md5: ${o.md5}`),s&&(s.isOutput=!0);let r=_.default.join(t,`${o.imgName}.png`);u.default.writeFileSync(r,o.imgBuffer),this.saveImageMeta(o,r)}))}saveImageMeta(t,e){let i=et.getSerialNumberImage(t),o=Z.get(i.md5);o||(o=i);let s=this.spriteFrameMetaContent.replace(/\$SPRITE_FRAME_UUID/g,o.uuid);s=s.replace(/\$TEXTURE_UUID/g,o.textureUuid),s=s.replace(/\$FILE_NAME/g,i.imgName),s=s.replace(/\$WIDTH/g,i.textureSize.width),s=s.replace(/\$HEIGHT/g,i.textureSize.height);let r=i.s9||{b:0,t:0,l:0,r:0};s=s.replace(/\$BORDER_TOP/g,r.t),s=s.replace(/\$BORDER_BOTTOM/g,r.b),s=s.replace(/\$BORDER_LEFT/g,r.l),s=s.replace(/\$BORDER_RIGHT/g,r.r),u.default.writeFileSync(e+".meta",s)}savePrefab(t,e){let i=_.default.join(e,`${t.name}.prefab`);u.default.writeFileSync(i,JSON.stringify(t.objectArray,null,2)),this.savePrefabMeta(t,i)}savePrefabMeta(t,e){let i=this.prefabMetaContent.replace(/\$PREFB_UUID/g,t.uuid);u.default.writeFileSync(e+".meta",i)}applyConfig(t){if(this.psdConfig&&t.__type__ in this.psdConfig){let e=this.psdConfig[t.__type__];for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)){const o=e[i];t[i]=o}}}};Ft.length?jt.exec(It):jt.test()}));