From 6e294f7a19a9cc3f93913ab777115b0c529fd59d Mon Sep 17 00:00:00 2001 From: onvia <272493431@qq.com> Date: Mon, 31 Jul 2023 09:26:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=8F=92=E4=BB=B6=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/index.js | 2 +- ccc-tnt-psd2ui-v3.4.+/dist/main.js | 355 +++++++++++---------- ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/index.js | 2 +- psd2ui-tools/dist/index.js | 2 +- psd2ui-tools/src/psd/PsdLayer.ts | 6 + 5 files changed, 195 insertions(+), 172 deletions(-) diff --git a/ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/index.js b/ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/index.js index d3c5ad0..95f237d 100644 --- a/ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/index.js +++ b/ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/index.js @@ -1 +1 @@ -!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{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>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 只能作用在 组图层 上")}};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 只能作用在 组图层 上")}};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缓存 ",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${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;si+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 空图层 ${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{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} 不存在`);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=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{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()})); +!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){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 c,p=l(i);function h(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 d(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"}(c||(c={}));let u=(t,e)=>{t.__unserialization||(t.__unserialization=[]),t.__unserialization.push(e)};function _(t){return e=>{Object.defineProperty(e.prototype,"$__type__",{value:t,enumerable:!0})}}let v={},g={},f={},y=0;function m(t){return void 0!==t.constructor.__ver_tag_id__&&f[t.constructor.__ver_tag_id__]==t||(t.constructor.__ver_tag_id__=`${y}`,f[t.constructor.__ver_tag_id__]=t,y++),t.constructor.__ver_tag_id__}function b(t,e){for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)){if(i in t)continue;t[i]=e[i]}}function x(t,...e){for(let i=0;i{let o=e.constructor.name;o=m(e),!g[o]&&(g[o]={});let s=g[o];if(s[i]||(s[i]={}),c.all===t)for(const t in c)s[i][c[t]]=!0;else s[i][c[t]]=!0;var r=S(e.constructor);if(r){let t=m(r.prototype);!v[o]&&(v[o]=t);for(var n=S(r);n;){let e=m(n.prototype);!v[t]&&(v[t]=e),n=S(n)}for(;t;)t in g&&x(s,g[t]),t=v[t]}e._version||(e._version={}),e._version[o]=g[o]=s}}function S(t){var e=t.prototype,i=e&&Object.getPrototypeOf(e);return i&&i.constructor}const M="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",F=new Array(123);for(let t=0;t<123;++t)F[t]=64;for(let t=0;t<64;++t)F[M.charCodeAt(t)]=t;const P=F,I="0123456789abcdef".split(""),$=["","","",""],j=$.concat($,"-",$,"-",$,"-",$,"-",$,$,$),C=j.map(((t,e)=>"-"===t?NaN:e)).filter(isFinite);let N={};for(let t=0;t>2],j[C[i++]]=I[(3&o)<<2|s>>4],j[C[i++]]=I[15&s]}return t.replace(e,j.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=N[String.fromCharCode(o.charCodeAt(t))],r=N[String.fromCharCode(o.charCodeAt(t+1))],n=N[String.fromCharCode(o.charCodeAt(t+2))];i[e++]=M[(s<<2)+(r>>2)],i[e++]=M[((3&r)<<4)+n]}return t.replace(e,i.join(""))}isNumber(t){return!isNaN(parseFloat(t))&&isFinite(t)}};class O{constructor(){this.uuid="",this.idx=0,this.uuid=z.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][c[V.editorVersion]])continue;const s=this[i];e[i]=s}return e}}h([u],O.prototype,"uuid",void 0),h([u],O.prototype,"idx",void 0);class A extends O{constructor(){super(),this._name="",this._objFlags=0,this.__type__=this.$__type__}}h([w(c.all)],A.prototype,"__type__",void 0),h([w(c.all)],A.prototype,"_name",void 0),h([w(c.all)],A.prototype,"_objFlags",void 0);class T extends A{constructor(){super(...arguments),this._enabled=!0,this.node=null,this._id="",this.__prefab=null}}h([w(c.all)],T.prototype,"_enabled",void 0),h([w(c.all)],T.prototype,"node",void 0),h([w(c.all)],T.prototype,"_id",void 0),h([w(c.v342)],T.prototype,"__prefab",void 0);let E=class extends T{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){}};h([w(c.v249)],E.prototype,"duration",void 0),h([w(c.v249)],E.prototype,"zoomScale",void 0),h([w(c.all)],E.prototype,"clickEvents",void 0),h([w(c.v249)],E.prototype,"_N$interactable",void 0),h([w(c.v249)],E.prototype,"_N$enableAutoGrayEffect",void 0),h([w(c.v249)],E.prototype,"_N$transition",void 0),h([w(c.v249)],E.prototype,"transition",void 0),h([w(c.v249)],E.prototype,"_N$target",void 0),h([w(c.v342)],E.prototype,"_interactable",void 0),h([w(c.v342)],E.prototype,"_transition",void 0),h([w(c.v342)],E.prototype,"_duration",void 0),h([w(c.v342)],E.prototype,"_zoomScale",void 0),h([w(c.v342)],E.prototype,"_target",void 0),E=h([_("cc.Button")],E);class k{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 D extends k{constructor(){super(...arguments),this.__type__="cc.Color"}}class L{constructor(t=0,e=0){this.x=t||0,this.y=e||0}}let B=class extends L{constructor(){super(...arguments),this.__type__="cc.Vec2"}};B=h([_("cc.Vec2")],B);let R=class extends T{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 B,this._fillStart=0,this._fillRange=0,this._isTrimmedMode=!0,this._atlas=null,this._visFlags=0,this._customMaterial=null,this._color=new D(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),V.editorVersion>=c.v342&&(this._srcBlendFactor=2,this._dstBlendFactor=4)}setSpriteFrame(t){V.editorVersion>=c.v342?this._spriteFrame={__uuid__:`${t}@f9941`,__expectedType__:"cc.SpriteFrame"}:this._spriteFrame={__uuid__:t}}};h([w(c.v249)],R.prototype,"_materials",void 0),h([w(c.all)],R.prototype,"_srcBlendFactor",void 0),h([w(c.all)],R.prototype,"_dstBlendFactor",void 0),h([w(c.all)],R.prototype,"_spriteFrame",void 0),h([w(c.all)],R.prototype,"_type",void 0),h([w(c.all)],R.prototype,"_sizeMode",void 0),h([w(c.all)],R.prototype,"_fillType",void 0),h([w(c.all)],R.prototype,"_fillCenter",void 0),h([w(c.all)],R.prototype,"_fillStart",void 0),h([w(c.all)],R.prototype,"_fillRange",void 0),h([w(c.all)],R.prototype,"_isTrimmedMode",void 0),h([w(c.all)],R.prototype,"_atlas",void 0),h([w(c.v342)],R.prototype,"_visFlags",void 0),h([w(c.v342)],R.prototype,"_customMaterial",void 0),h([w(c.v342)],R.prototype,"_color",void 0),h([w(c.v342)],R.prototype,"_useGrayscale",void 0),R=h([_("cc.Sprite")],R);let U=class extends T{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 只能作用在 组图层 上")}};h([w(c.v249)],U.prototype,"_N$totalLength",void 0),h([w(c.v249)],U.prototype,"_N$barSprite",void 0),h([w(c.v249)],U.prototype,"_N$mode",void 0),h([w(c.v249)],U.prototype,"_N$progress",void 0),h([w(c.v249)],U.prototype,"_N$reverse",void 0),h([w(c.v342)],U.prototype,"_barSprite",void 0),h([w(c.v342)],U.prototype,"_mode",void 0),h([w(c.v342)],U.prototype,"_totalLength",void 0),h([w(c.v342)],U.prototype,"_progress",void 0),h([w(c.v342)],U.prototype,"_reverse",void 0),U=h([_("cc.ProgressBar")],U);let W=class extends E{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 只能作用在 组图层 上")}};h([w(c.v249)],W.prototype,"_N$isChecked",void 0),h([w(c.v249)],W.prototype,"toggleGroup",void 0),h([w(c.v249)],W.prototype,"checkMark",void 0),h([w(c.all)],W.prototype,"checkEvents",void 0),h([w(c.v342)],W.prototype,"_isChecked",void 0),h([w(c.v342)],W.prototype,"_checkMark",void 0),W=h([_("cc.Toggle")],W);const V=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=c.v249,this.DEFAULT_SPRITE_FRAME_MATERIAL={[c.v249]:"eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432",[c.v342]:""},this.DEFAULT_LABEL_MATERIAL={[c.v249]:"eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432",[c.v342]:""},this.CompMappings={Btn:E,ProgressBar:U,Toggle:W},this.textOffsetY={default:0,36:0},this.textLineHeightOffset=0}get SpriteFrame_Material(){return this.DEFAULT_SPRITE_FRAME_MATERIAL[V.editorVersion]}get Label_Material(){return this.DEFAULT_LABEL_MATERIAL[V.editorVersion]}};let X=new class{DFS(t,e,i=0){if(!o.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);let r=o.readdirSync(t),n=i;i++,r.forEach((r=>{let a=s.join(t,r),l=o.lstatSync(a).isDirectory();null==e||e({isDirectory:l,fullPath:a,fileName:r,depth:n}),l&&this.DFS(a,e,i)}))}filterFile(t,e){if(!o.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);var i=[];return o.readdirSync(t).forEach((r=>{let n=s.join(t,r),a=o.lstatSync(n).isDirectory();if(!a){if(!e(r))return}a?i=i.concat(this.filterFile(n,e)):i.push(n)})),i}getFolderFiles(t,e){if(!o.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);let i=[];return o.readdirSync(t).forEach((r=>{let n=s.join(t,r);o.lstatSync(n).isDirectory()?"folder"===e&&i.push({fullPath:n,basename:r}):"file"===e&&i.push({fullPath:n,basename:r})})),i}writeFile(t,e){return d(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=s.dirname(t);yield o.mkdirp(i),yield o.writeFile(t,e),console.log(`写入完成 ${t} `)}))}getMD5(t){return"string"==typeof t&&(t=o.readFileSync(t)),r.createHash("md5").update(t).digest("hex")}};class G{constructor(){this._imageMap=new Map,this._cachePath=null}initWithPath(t){if(!o.existsSync(t))return void console.log(`ImageCacheMgr-> 文件不存在: ${t}`);this._cachePath=t;let e=o.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 d(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 X.writeFile(t,i)}))}loadImages(t){if(this._imageMap.size>0)return void console.error("ImageCacheMgr-> 暂时只能在 启动时加载");let e=X.filterFile(t,(t=>".png"==s.extname(t)));if(e)for(let t=0;t缓存 ",i);let s=this._loadImageMetaWarp(`${i}.meta`);s&&this.set(o,s)}}_loadImageMetaWarp(t){let e=o.readFileSync(t,{encoding:"utf-8"}),i=null;switch(V.editorVersion){case c.v249:i=this._loadImageMeta249(e,t);break;case c.v342:i=this._loadImageMeta34x(e,t);break;default:console.log(`ImageCacheMgr-> 暂未实现 ${c[V.editorVersion]} 版本`)}return i}_loadImageMeta249(t,e){var i;let o=s.basename(e,".png.meta"),r=s.join(s.dirname(e),`${o}.png`),n=JSON.parse(t);return(null===(i=null==n?void 0:n.subMetas)||void 0===i?void 0:i[o])?{path:r,textureUuid:n.subMetas[o].uuid,uuid:n.uuid,isOutput:!0}:null}_loadImageMeta34x(t,e){var i;let o=s.basename(e,".png.meta"),r=s.join(s.dirname(e),`${o}.png`),n=JSON.parse(t);if(!(null===(i=null==n?void 0:n.subMetas)||void 0===i?void 0:i["6c48a"]))return null;let a=n.subMetas["6c48a"].uuid.replace("@6c48a","");return{path:r,textureUuid:a,uuid:a,isOutput:!0}}static getInstance(){return this._instance||(this._instance=new G),this._instance}}G._instance=null;const Y=G.getInstance();class H{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 H),this._instance}}H._instance=null;const J=H.getInstance();var q;!function(t){t[t.Doc=0]="Doc",t[t.Group=1]="Group",t[t.Text=2]="Text",t[t.Image=3]="Image"}(q||(q={}));class K{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 Q{constructor(t=0,e=0){this.width=t||0,this.height=e||0}}class Z{constructor(t=0,e=0,i=0){this.x=t||0,this.y=e||0,this.z=i||0}}class tt{constructor(t,e,i){var o,s,r,n;this.uuid=z.uuid(),this.source=t,this.parent=e,this.rootDoc=i,this.name=t.name,this.position=new L,this.size=new Q,this.rect=new K(t),this.anchorPoint=new L(.5,.5),this.hidden=!1,this.opacity=255,this.color=new k(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 Z(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${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]]=z.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||!tt.isPinyin)return t;if(!new RegExp("[\\u4E00-\\u9FFF]+","g").test(t))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}}tt.isPinyin=!1;class et extends tt{constructor(t,e,i){super(t,e,i),this.children=[],i&&(this.rect=new K(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;si+4)return console.log("Texture9Utils-> 设置的九宫格 left, right 数据不合理,请重新设置"),t;if(e.b+e.t>o+4)return console.log("Texture9Utils-> 设置的九宫格 bottom, top 数据不合理,请重新设置"),t;let c=a.createCanvas(Math.min(i,e.l+e.r+4)||i,Math.min(o,e.b+e.t+4)||o),p=c.getContext("2d");return p.drawImage(t,0,0,s+4,n+4,0,0,s+4,n+4),p.drawImage(t,0,o-l,s+4,l,0,n+4,s+4,l),p.drawImage(t,i-s,0,r,n+4,s+4,0,r,n+4),p.drawImage(t,i-s,o-l,r,l,s+4,n+4,r,l),c}}class st extends tt{constructor(t,e,i){var o;if(super(t,e,i),this.textureUuid=z.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=ot.safeBorder(this.source.canvas,t);let e=ot.split(this.source.canvas,t);this.source.canvas=e}let s=this.source.canvas;this.imgBuffer=s.toBuffer("image/png"),this.md5=X.getMD5(this.imgBuffer),this.textureSize=new Q(s.width,s.height),this.scale=new Z((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 rt extends tt{parseSource(){super.parseSource();let t=this.source.text,e=t.style;if(e){let t=e.fillColor;t&&(this.color=new k(t.r,t.g,t.b,255*t.a))}return this.text=t.text,this.fontSize=e.fontSize,this.offsetY=V.textOffsetY[this.fontSize]||V.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 k(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 空图层 ${null==t?void 0:t.name}`),null;let s=o=new st(t,e,i);J.add(s),s.isIgnore()||s.isBind()||Y.has(s.md5)||Y.set(s.md5,{uuid:s.uuid,textureUuid:s.textureUuid})}break;case q.Text:o=new rt(t,e,i)}return o.layerType=s,o.parseSource(),o.onCtor(),o}};class at extends O{constructor(){super(),this.__type__="cc.CompPrefabInfo",this.fileId="",this.fileId=z.compressUuid(this.uuid)}}let lt=class extends Q{constructor(){super(...arguments),this.__type__="cc.Size"}};lt=h([_("cc.Size")],lt);let ct=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}};ct=h([_("TypedArray")],ct);class pt extends Z{constructor(){super(...arguments),this.__type__="cc.Vec3"}}let ht=class extends A{constructor(t){super(),this._parent=null,this._children=[],this._active=!0,this._components=[],this._prefab=null,this._id="",this._opacity=255,this._color=new D(255,255,255,255),this._contentSize=new lt,this._anchorPoint=new B(0,0),this._trs=new ct,this._eulerAngles=new pt,this._skewX=0,this._skewY=0,this._is3DNode=!1,this._groupIndex=0,this.groupIndex=0,this._renderEnable=!1,this._bfsRenderFlag=!1,this._lpos=new pt,this._lrot=new pt,this._lscale=new pt,this._euler=new pt,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),V.editorVersion>=c.v342&&this.addCompPrefabInfo(t)}addCompPrefabInfo(t){let e=new at,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)}};h([w(c.all)],ht.prototype,"_parent",void 0),h([w(c.all)],ht.prototype,"_children",void 0),h([w(c.all)],ht.prototype,"_active",void 0),h([w(c.all)],ht.prototype,"_components",void 0),h([w(c.all)],ht.prototype,"_prefab",void 0),h([w(c.all)],ht.prototype,"_id",void 0),h([w(c.v249)],ht.prototype,"_opacity",void 0),h([w(c.v249)],ht.prototype,"_color",void 0),h([w(c.v249)],ht.prototype,"_contentSize",void 0),h([w(c.v249)],ht.prototype,"_anchorPoint",void 0),h([w(c.v249)],ht.prototype,"_trs",void 0),h([w(c.v249)],ht.prototype,"_eulerAngles",void 0),h([w(c.v249)],ht.prototype,"_skewX",void 0),h([w(c.v249)],ht.prototype,"_skewY",void 0),h([w(c.v249)],ht.prototype,"_is3DNode",void 0),h([w(c.v249)],ht.prototype,"_groupIndex",void 0),h([w(c.v249)],ht.prototype,"groupIndex",void 0),h([w(c.v249)],ht.prototype,"_renderEnable",void 0),h([w(c.v249)],ht.prototype,"_bfsRenderFlag",void 0),h([w(c.v342)],ht.prototype,"_lpos",void 0),h([w(c.v342)],ht.prototype,"_lrot",void 0),h([w(c.v342)],ht.prototype,"_lscale",void 0),h([w(c.v342)],ht.prototype,"_euler",void 0),h([w(c.v342)],ht.prototype,"_layer",void 0),h([u],ht.prototype,"psdDoc",void 0),h([u],ht.prototype,"components",void 0),h([u],ht.prototype,"children",void 0),ht=h([_("cc.Node")],ht);class dt extends O{constructor(){super(),this.__type__="cc.PrefabInfo",this.root={__id__:1},this.asset={__id__:0},this.fileId="",this.sync=!1,this.fileId=z.compressUuid(this.uuid)}}h([w(c.all)],dt.prototype,"__type__",void 0),h([w(c.all)],dt.prototype,"root",void 0),h([w(c.all)],dt.prototype,"asset",void 0),h([w(c.all)],dt.prototype,"fileId",void 0),h([w(c.all)],dt.prototype,"sync",void 0);let ut=class extends A{constructor(){super(...arguments),this._native="",this.data=null,this.optimizationPolicy=0,this.asyncLoadAssets=!1,this.readonly=!1,this.persistent=!1}};h([w(c.all)],ut.prototype,"_native",void 0),h([w(c.all)],ut.prototype,"data",void 0),h([w(c.all)],ut.prototype,"optimizationPolicy",void 0),h([w(c.all)],ut.prototype,"asyncLoadAssets",void 0),h([w(c.v249)],ut.prototype,"readonly",void 0),h([w(c.v342)],ut.prototype,"persistent",void 0),ut=h([_("cc.Prefab")],ut);let _t=class extends T{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 D(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+V.textLineHeightOffset,V.editorVersion>=c.v342&&(this._srcBlendFactor=2,this._dstBlendFactor=4)}};h([w(c.all)],_t.prototype,"_srcBlendFactor",void 0),h([w(c.all)],_t.prototype,"_dstBlendFactor",void 0),h([w(c.all)],_t.prototype,"_string",void 0),h([w(c.all)],_t.prototype,"_fontSize",void 0),h([w(c.all)],_t.prototype,"_lineHeight",void 0),h([w(c.all)],_t.prototype,"_enableWrapText",void 0),h([w(c.all)],_t.prototype,"_isSystemFontUsed",void 0),h([w(c.all)],_t.prototype,"_spacingX",void 0),h([w(c.all)],_t.prototype,"_underlineHeight",void 0),h([w(c.v249)],_t.prototype,"_materials",void 0),h([w(c.v249)],_t.prototype,"_N$string",void 0),h([w(c.v249)],_t.prototype,"_N$file",void 0),h([w(c.v249)],_t.prototype,"_batchAsBitmap",void 0),h([w(c.v249)],_t.prototype,"_styleFlags",void 0),h([w(c.v249)],_t.prototype,"_N$horizontalAlign",void 0),h([w(c.v249)],_t.prototype,"_N$verticalAlign",void 0),h([w(c.v249)],_t.prototype,"_N$fontFamily",void 0),h([w(c.v249)],_t.prototype,"_N$overflow",void 0),h([w(c.v249)],_t.prototype,"_N$cacheMode",void 0),h([w(c.v342)],_t.prototype,"_visFlags",void 0),h([w(c.v342)],_t.prototype,"_customMaterial",void 0),h([w(c.v342)],_t.prototype,"_color",void 0),h([w(c.v342)],_t.prototype,"_overflow",void 0),h([w(c.v342)],_t.prototype,"_cacheMode",void 0),h([w(c.v342)],_t.prototype,"_horizontalAlign",void 0),h([w(c.v342)],_t.prototype,"_verticalAlign",void 0),h([w(c.v342)],_t.prototype,"_actualFontSize",void 0),h([w(c.v342)],_t.prototype,"_isItalic",void 0),h([w(c.v342)],_t.prototype,"_isBold",void 0),h([w(c.v342)],_t.prototype,"_isUnderline",void 0),_t=h([_("cc.Label")],_t);let vt=class extends T{constructor(){super(...arguments),this._color=new D(255,255,255,255),this._width=1}updateWithLayer(t){this._width=t.outline.width,this._color.set(t.outline.color)}};h([w(c.all)],vt.prototype,"_color",void 0),h([w(c.all)],vt.prototype,"_width",void 0),vt=h([_("cc.LabelOutline")],vt);class gt{constructor(){this.textObjects=[]}test(){const t=s.join(__dirname,"..","out");this.parsePsd("./test-img-only/境界奖励-优化.psd",t)}exec(t){return d(this,void 0,void 0,(function*(){if(!this.checkArgs(t))return;if(o.lstatSync(t.input).isDirectory())t.output||(t.output=s.join(t.input,"psd2ui")),this.parsePsdDir(t.input,t.output);else{if(!t.output){let e=s.dirname(t.input);t.output=s.join(e,"psd2ui")}this.parsePsd(t.input,t.output)}}))}checkArgs(t){return t.input?!!o.existsSync(t.input)||(console.error(`输入路径不存在: ${t.input}`),!1):(console.error("请设置 --input"),!1)}parsePsdDir(t,e){return d(this,void 0,void 0,(function*(){o.emptyDirSync(e);let i=X.filterFile(t,(t=>".psd"==s.extname(t)));for(let t=0;t{let n=J.getSerialNumberImage(e),a=`${n.imgName}_${i}`;console.log(`保存图片 [${n.imgName}] 重命名为 [${a}] md5: ${n.md5}`);let l=s.join(t,`${a}.png`);o.writeFileSync(l,n.imgBuffer),i++}))}saveTextFile(t,e){this.scanText(t,t);let i=JSON.stringify(this.textObjects,null,2),r=s.join(e,"text.txt");o.writeFileSync(r,i,{encoding:"utf-8"})}scanText(t,e){if(t instanceof et)for(let i=0;i test")}))}loadMetaTemplete(){return d(this,void 0,void 0,(function*(){this.spriteFrameMetaContent=o.readFileSync(s.join(__dirname,`../assets/cc/meta/CCSpriteFrame.meta.${c[V.editorVersion]}`),"utf-8"),this.prefabMetaContent=o.readFileSync(s.join(__dirname,`../assets/cc/meta/CCPrefab.meta.${c[V.editorVersion]}`),"utf-8")}))}loadPsdConfig(t){return d(this,void 0,void 0,(function*(){if(!o.existsSync(t))return void console.log(`Main-> 配置 ${t} 不存在`);let e=o.readFileSync(t,"utf-8");this.psdConfig=JSON.parse(e);for(const t in this.psdConfig)t in V&&("object"==typeof this.psdConfig[t]?V[t]=Object.assign({},V[t],this.psdConfig[t]):V[t]=this.psdConfig[t]||V[t])}))}exec(t){return d(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",V.help),!1;if(t["img-only"])return ft.exec(t),!0;let e=()=>d(this,void 0,void 0,(function*(){t.cache&&(o.mkdirsSync(s.dirname(t.cache)),yield Y.saveImageMap(t.cache))}));if(t["engine-version"]&&(V.editorVersion=c[t["engine-version"]]),console.log(`Main-> 数据版本 ${c[V.editorVersion]}`),!t.init||t["project-assets"]&&t.cache){if(t.cache&&!o.existsSync(t.cache)&&e(),t["project-assets"]&&(t["cache-remake"]||t.init)&&(yield Y.loadImages(t["project-assets"]),e(),t.init))console.log("psd2ui 缓存完成");else if(this.checkArgs(t)){if(t.cache&&(yield Y.initWithPath(t.cache)),yield this.loadMetaTemplete(),t.config&&(yield this.loadPsdConfig(t.config)),this.isForceImg=!!t["force-img"],tt.isPinyin=t.pinyin,o.lstatSync(t.input).isDirectory())t.output||(t.output=s.join(t.input,"psd2ui")),this.parsePsdDir(t.input,t.output);else{if(!t.output){let e=s.dirname(t.input);t.output=s.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(!o.existsSync(t.input))return console.error(`输入路径不存在: ${t.input}`),!1;if(t["engine-version"]){switch(c[t["engine-version"]]){case c.v249:case c.v342:break;default:return console.log(`暂未实现该引擎版本 ${t["engine-version"]}`),!1}}return!0}parsePsdDir(t,e){return d(this,void 0,void 0,(function*(){let i=X.filterFile(t,(t=>".psd"==s.extname(t)));for(let t=0;t=c.v342&&255!==t.opacity){let e=new yt;e._opacity=t.opacity,e.updateWithLayer(t),r.addComponent(e)}let n=new lt(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 rt&&(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 B(t.anchorPoint.x,t.anchorPoint.y),V.editorVersion>=c.v342){r._lpos=new pt(t.position.x,t.position.y+a,0),r._lrot=new pt(0,0,0),r._lscale=new pt(t.scale.x,t.scale.y,t.scale.z),r._euler=new pt;let e=new mt;e._contentSize=n,e._anchorPoint=r._anchorPoint,e.updateWithLayer(t),r.addComponent(e)}if(t instanceof et)for(let i=0;i{let r=J.getSerialNumberImage(e),n=Y.get(r.md5);if(!this.isForceImg&&(null==n?void 0:n.isOutput))return void console.log(`已有相同资源,不再导出 [${e.imgName}] md5: ${e.md5}`);console.log(`保存图片 [${r.imgName}] md5: ${r.md5}`),n&&(n.isOutput=!0);let a=s.join(t,`${r.imgName}.png`);o.writeFileSync(a,r.imgBuffer),this.saveImageMeta(r,a)}))}saveImageMeta(t,e){let i=J.getSerialNumberImage(t),s=Y.get(i.md5);s||(s=i);let r=this.spriteFrameMetaContent.replace(/\$SPRITE_FRAME_UUID/g,s.uuid);r=r.replace(/\$TEXTURE_UUID/g,s.textureUuid),r=r.replace(/\$FILE_NAME/g,i.imgName),r=r.replace(/\$WIDTH/g,i.textureSize.width),r=r.replace(/\$HEIGHT/g,i.textureSize.height);let n=i.s9||{b:0,t:0,l:0,r:0};r=r.replace(/\$BORDER_TOP/g,n.t),r=r.replace(/\$BORDER_BOTTOM/g,n.b),r=r.replace(/\$BORDER_LEFT/g,n.l),r=r.replace(/\$BORDER_RIGHT/g,n.r),o.writeFileSync(e+".meta",r)}savePrefab(t,e){let i=s.join(e,`${t.name}.prefab`);o.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);o.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}}}};bt.length?wt.exec(xt):wt.test()})); diff --git a/ccc-tnt-psd2ui-v3.4.+/dist/main.js b/ccc-tnt-psd2ui-v3.4.+/dist/main.js index 8e03650..0b99234 100644 --- a/ccc-tnt-psd2ui-v3.4.+/dist/main.js +++ b/ccc-tnt-psd2ui-v3.4.+/dist/main.js @@ -1,169 +1,186 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.unload = exports.load = exports.methods = void 0; -//@ts-ignore -const package_json_1 = __importDefault(require("../package.json")); -const fs_extra_1 = __importDefault(require("fs-extra")); -const path_1 = __importDefault(require("path")); -const os_1 = __importDefault(require("os")); -const child_process_1 = __importDefault(require("child_process")); -let exec = child_process_1.default.exec; -const ENGINE_VER = "v342"; // -const packagePath = path_1.default.join(Editor.Project.path, "extensions", package_json_1.default.name); -const projectAssets = path_1.default.join(Editor.Project.path, "assets"); -const cacheFile = path_1.default.join(Editor.Project.path, "local", "psd-to-prefab-cache.json"); -const configFile = path_1.default.join(`${packagePath}/config/psd.config.json`); -const nodejsFile = path_1.default.join(packagePath, "bin", `node${os_1.default.platform() == 'darwin' ? "" : ".exe"}`); -const psd = path_1.default.join(packagePath, "libs", "psd2ui", "index.js"); -let uuid2md5 = new Map(); -let cacheFileJson = {}; -/** - * @en - * @zh 为扩展的主进程的注册方法 - */ -exports.methods = { - openPanel() { - Editor.Panel.open(package_json_1.default.name); - }, - onClickPsd2UICache() { - console.log(`main-> onClickPsd2UICache111 `); - return new Promise((resolve, reject) => { - console.log(`main-> onClickPsd2UICache`); - let options = { - "project-assets": projectAssets, - "cache": cacheFile, - "init": true, - "engine-version": ENGINE_VER - }; - Promise.all(_exec(options, [])).then(() => { - console.log("[psd2prefab] 执行缓存结束"); - resolve(); - }); - }); - }, - async onPsd2UIDropFiles(param) { - let files = param.files; - let isForceImg = param.isForceImg; - let isImgOnly = param.isImgOnly; - let output = param.output; - let isPinyin = param.isPinyin; - let options = { - "project-assets": projectAssets, - "cache": cacheFile, - "engine-version": ENGINE_VER, - "pinyin": isPinyin, - }; - let tasks = []; - for (let i = 0; i < files.length; i++) { - const file = files[i]; - let stat = fs_extra_1.default.statSync(file); - if (stat.isFile()) { - let ext = path_1.default.extname(file); - if (ext != '.psd') { - continue; - } - } - let args = JSON.parse(JSON.stringify(options)); - args["input"] = file; - if (output) { - args["output"] = output; - } - if (isImgOnly) { - // 只导出图片 - args["img-only"] = true; - } - else { - // 强制导出图片 - if (isForceImg) { - args["force-img"] = true; - } - args["config"] = configFile; - } - _exec(args, tasks); - } - Promise.all(tasks).then(() => { - genUUID2MD5Mapping(); - console.log("[ccc-tnt-psd2ui] psd 导出完成,输出位置为:", output ? output : "psd 同级目录"); - }).catch((reason) => { - console.log("[ccc-tnt-psd2ui] 导出失败", reason); - }).finally(() => { - }); - }, -}; -function _exec(options, tasks) { - let jsonContent = JSON.stringify(options); - if (!fs_extra_1.default.existsSync(nodejsFile)) { - console.log(`[ccc-tnt-psd2ui] 没有内置 nodejs`, nodejsFile); - return tasks; - } - // 处理权限问题 - if (os_1.default.platform() === 'darwin') { - if (fs_extra_1.default.statSync(nodejsFile).mode != 33261) { - console.log(`[ccc-tnt-psd2ui] 设置权限`); - fs_extra_1.default.chmodSync(nodejsFile, 33261); - } - } - console.log("[ccc-tnt-psd2ui] 命令参数:" + jsonContent); - console.log("[ccc-tnt-psd2ui] 命令执行中"); - let base64 = Buffer.from(jsonContent).toString("base64"); - tasks.push(new Promise((rs) => { - // console.log(`[ccc-tnt-psd2ui] `, `${nodejsFile} ${psd}` + ' ' + `--json ${base64}`); - exec(`${nodejsFile} ${psd}` + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => { - console.log("[ccc-tnt-psd2ui]:\n", stdout); - if (stderr) { - console.log(stderr); - } - rs(); - }); - })); - return tasks; -} -/** - * 资源删除的监听 - * - * @param {*} event - */ -function onAssetDeletedListener(event) { - if (uuid2md5.has(event)) { - let md5 = uuid2md5.get(event); - console.log(`[ccc-tnt-psd2ui] 删除资源 md5: ${md5}, uuid: ${event}`); - delete cacheFileJson[`${md5}`]; - fs_extra_1.default.writeFileSync(cacheFile, JSON.stringify(cacheFileJson, null, 2)); - } -} -/** - * 生成 uuid 转 MD5 的映射 - * - */ -function genUUID2MD5Mapping() { - if (!fs_extra_1.default.existsSync(cacheFile)) { - return; - } - let content = fs_extra_1.default.readFileSync(cacheFile, 'utf-8'); - let obj = JSON.parse(content); - cacheFileJson = obj; - for (const key in obj) { - const element = obj[key]; - uuid2md5.set(element.textureUuid, key); - } -} -/** - * @en Hooks triggered after extension loading is complete - * @zh 扩展加载完成后触发的钩子 - */ -const load = function () { - genUUID2MD5Mapping(); - Editor.Message.addBroadcastListener("asset-db:asset-delete", onAssetDeletedListener); -}; -exports.load = load; -/** - * @en Hooks triggered after extension uninstallation is complete - * @zh 扩展卸载完成后触发的钩子 - */ -const unload = function () { - Editor.Message.removeBroadcastListener("asset-db:asset-delete", onAssetDeletedListener); -}; -exports.unload = unload; +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.unload = exports.load = exports.methods = void 0; +//@ts-ignore +const package_json_1 = __importDefault(require("../package.json")); +const fs_extra_1 = __importDefault(require("fs-extra")); +const path_1 = __importDefault(require("path")); +const os_1 = __importDefault(require("os")); +const child_process_1 = __importDefault(require("child_process")); +let exec = child_process_1.default.exec; +const ENGINE_VER = "v342"; // +const packagePath = path_1.default.join(Editor.Project.path, "extensions", package_json_1.default.name); +const projectAssets = path_1.default.join(Editor.Project.path, "assets"); +const cacheFile = path_1.default.join(Editor.Project.path, "local", "psd-to-prefab-cache.json"); +const configFile = path_1.default.join(`${packagePath}/config/psd.config.json`); +const nodejsFile = path_1.default.join(packagePath, "bin", `node${os_1.default.platform() == 'darwin' ? "" : ".exe"}`); +const commandFile = path_1.default.join(packagePath, "libs", "psd2ui", `command.${os_1.default.platform() == 'darwin' ? "sh" : "bat"}`); +const psd = path_1.default.join(packagePath, "libs", "psd2ui", "index.js"); +let uuid2md5 = new Map(); +let cacheFileJson = {}; +/** + * @en + * @zh 为扩展的主进程的注册方法 + */ +exports.methods = { + openPanel() { + Editor.Panel.open(package_json_1.default.name); + }, + onClickPsd2UICache() { + console.log(`main-> onClickPsd2UICache111 `); + return new Promise((resolve, reject) => { + console.log(`main-> onClickPsd2UICache`); + let options = { + "project-assets": projectAssets, + "cache": cacheFile, + "init": true, + "engine-version": ENGINE_VER + }; + Promise.all(_exec(options, [])).then(() => { + console.log("[psd2prefab] 执行缓存结束"); + resolve(); + }); + }); + }, + async onPsd2UIDropFiles(param) { + let files = param.files; + let isForceImg = param.isForceImg; + let isImgOnly = param.isImgOnly; + let output = param.output; + let isPinyin = param.isPinyin; + let options = { + "project-assets": projectAssets, + "cache": cacheFile, + "engine-version": ENGINE_VER, + "pinyin": isPinyin, + }; + let tasks = []; + for (let i = 0; i < files.length; i++) { + const file = files[i]; + let stat = fs_extra_1.default.statSync(file); + if (stat.isFile()) { + let ext = path_1.default.extname(file); + if (ext != '.psd') { + continue; + } + } + let args = JSON.parse(JSON.stringify(options)); + args["input"] = file; + if (output) { + args["output"] = output; + } + if (isImgOnly) { + // 只导出图片 + args["img-only"] = true; + } + else { + // 强制导出图片 + if (isForceImg) { + args["force-img"] = true; + } + args["config"] = configFile; + } + _exec(args, tasks); + } + Promise.all(tasks).then(() => { + genUUID2MD5Mapping(); + console.log("[ccc-tnt-psd2ui] psd 导出完成,输出位置为:", output ? output : "psd 同级目录"); + }).catch((reason) => { + console.log("[ccc-tnt-psd2ui] 导出失败", reason); + }).finally(() => { + }); + }, +}; +function _exec(options, tasks) { + let jsonContent = JSON.stringify(options); + if (!fs_extra_1.default.existsSync(nodejsFile)) { + console.log(`[ccc-tnt-psd2ui] 没有内置 nodejs`, nodejsFile); + return tasks; + } + // 处理权限问题 + if (os_1.default.platform() === 'darwin') { + if (fs_extra_1.default.statSync(nodejsFile).mode != 33261) { + console.log(`[ccc-tnt-psd2ui] 设置权限`); + fs_extra_1.default.chmodSync(nodejsFile, 33261); + } + if (fs_extra_1.default.statSync(commandFile).mode != 33261) { + console.log(`[ccc-tnt-psd2ui] commandFile 设置权限`); + fs_extra_1.default.chmodSync(commandFile, 33261); + } + } + console.log("[ccc-tnt-psd2ui] 命令参数:" + jsonContent); + console.log("[ccc-tnt-psd2ui] 命令执行中"); + let base64 = Buffer.from(jsonContent).toString("base64"); + tasks.push(new Promise((rs) => { + // console.log(`[ccc-tnt-psd2ui] `, `${nodejsFile} ${psd}` + ' ' + `--json ${base64}`); + // exec(`${nodejsFile} ${psd}` + ' ' + `--json ${base64}`, { windowsHide: false }, (err, stdout, stderr) => { + // console.log("[ccc-tnt-psd2ui]:\n", stdout); + // if (stderr) { + // console.log(stderr); + // } + // rs(); + // }) + let shellScript = commandFile; // 你的脚本路径 + let scriptArgs = `--json ${base64}`; // 你的脚本参数 + let command = os_1.default.platform() == 'darwin' ? `osascript -e 'tell app "Terminal" to do script "cd ${process.cwd()}; ${shellScript} ${scriptArgs}"'` + : `start ${commandFile} ${scriptArgs}`; + exec(command, (error, stdout, stderr) => { + console.log("[ccc-tnt-psd2ui]:\n", stdout); + console.log("[ccc-tnt-psd2ui]: 程序执行完后请手动关闭终端窗口"); + if (stderr) { + console.log(stderr); + } + rs(); + }); + })); + return tasks; +} +/** + * 资源删除的监听 + * + * @param {*} event + */ +function onAssetDeletedListener(event) { + if (uuid2md5.has(event)) { + let md5 = uuid2md5.get(event); + console.log(`[ccc-tnt-psd2ui] 删除资源 md5: ${md5}, uuid: ${event}`); + delete cacheFileJson[`${md5}`]; + fs_extra_1.default.writeFileSync(cacheFile, JSON.stringify(cacheFileJson, null, 2)); + } +} +/** + * 生成 uuid 转 MD5 的映射 + * + */ +function genUUID2MD5Mapping() { + if (!fs_extra_1.default.existsSync(cacheFile)) { + return; + } + let content = fs_extra_1.default.readFileSync(cacheFile, 'utf-8'); + let obj = JSON.parse(content); + cacheFileJson = obj; + for (const key in obj) { + const element = obj[key]; + uuid2md5.set(element.textureUuid, key); + } +} +/** + * @en Hooks triggered after extension loading is complete + * @zh 扩展加载完成后触发的钩子 + */ +const load = function () { + genUUID2MD5Mapping(); + Editor.Message.addBroadcastListener("asset-db:asset-delete", onAssetDeletedListener); +}; +exports.load = load; +/** + * @en Hooks triggered after extension uninstallation is complete + * @zh 扩展卸载完成后触发的钩子 + */ +const unload = function () { + Editor.Message.removeBroadcastListener("asset-db:asset-delete", onAssetDeletedListener); +}; +exports.unload = unload; diff --git a/ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/index.js b/ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/index.js index d3c5ad0..95f237d 100644 --- a/ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/index.js +++ b/ccc-tnt-psd2ui-v3.4.+/libs/psd2ui/index.js @@ -1 +1 @@ -!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{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>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 只能作用在 组图层 上")}};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 只能作用在 组图层 上")}};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缓存 ",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${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;si+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 空图层 ${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{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} 不存在`);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=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{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()})); +!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){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 c,p=l(i);function h(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 d(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"}(c||(c={}));let u=(t,e)=>{t.__unserialization||(t.__unserialization=[]),t.__unserialization.push(e)};function _(t){return e=>{Object.defineProperty(e.prototype,"$__type__",{value:t,enumerable:!0})}}let v={},g={},f={},y=0;function m(t){return void 0!==t.constructor.__ver_tag_id__&&f[t.constructor.__ver_tag_id__]==t||(t.constructor.__ver_tag_id__=`${y}`,f[t.constructor.__ver_tag_id__]=t,y++),t.constructor.__ver_tag_id__}function b(t,e){for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)){if(i in t)continue;t[i]=e[i]}}function x(t,...e){for(let i=0;i{let o=e.constructor.name;o=m(e),!g[o]&&(g[o]={});let s=g[o];if(s[i]||(s[i]={}),c.all===t)for(const t in c)s[i][c[t]]=!0;else s[i][c[t]]=!0;var r=S(e.constructor);if(r){let t=m(r.prototype);!v[o]&&(v[o]=t);for(var n=S(r);n;){let e=m(n.prototype);!v[t]&&(v[t]=e),n=S(n)}for(;t;)t in g&&x(s,g[t]),t=v[t]}e._version||(e._version={}),e._version[o]=g[o]=s}}function S(t){var e=t.prototype,i=e&&Object.getPrototypeOf(e);return i&&i.constructor}const M="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",F=new Array(123);for(let t=0;t<123;++t)F[t]=64;for(let t=0;t<64;++t)F[M.charCodeAt(t)]=t;const P=F,I="0123456789abcdef".split(""),$=["","","",""],j=$.concat($,"-",$,"-",$,"-",$,"-",$,$,$),C=j.map(((t,e)=>"-"===t?NaN:e)).filter(isFinite);let N={};for(let t=0;t>2],j[C[i++]]=I[(3&o)<<2|s>>4],j[C[i++]]=I[15&s]}return t.replace(e,j.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=N[String.fromCharCode(o.charCodeAt(t))],r=N[String.fromCharCode(o.charCodeAt(t+1))],n=N[String.fromCharCode(o.charCodeAt(t+2))];i[e++]=M[(s<<2)+(r>>2)],i[e++]=M[((3&r)<<4)+n]}return t.replace(e,i.join(""))}isNumber(t){return!isNaN(parseFloat(t))&&isFinite(t)}};class O{constructor(){this.uuid="",this.idx=0,this.uuid=z.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][c[V.editorVersion]])continue;const s=this[i];e[i]=s}return e}}h([u],O.prototype,"uuid",void 0),h([u],O.prototype,"idx",void 0);class A extends O{constructor(){super(),this._name="",this._objFlags=0,this.__type__=this.$__type__}}h([w(c.all)],A.prototype,"__type__",void 0),h([w(c.all)],A.prototype,"_name",void 0),h([w(c.all)],A.prototype,"_objFlags",void 0);class T extends A{constructor(){super(...arguments),this._enabled=!0,this.node=null,this._id="",this.__prefab=null}}h([w(c.all)],T.prototype,"_enabled",void 0),h([w(c.all)],T.prototype,"node",void 0),h([w(c.all)],T.prototype,"_id",void 0),h([w(c.v342)],T.prototype,"__prefab",void 0);let E=class extends T{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){}};h([w(c.v249)],E.prototype,"duration",void 0),h([w(c.v249)],E.prototype,"zoomScale",void 0),h([w(c.all)],E.prototype,"clickEvents",void 0),h([w(c.v249)],E.prototype,"_N$interactable",void 0),h([w(c.v249)],E.prototype,"_N$enableAutoGrayEffect",void 0),h([w(c.v249)],E.prototype,"_N$transition",void 0),h([w(c.v249)],E.prototype,"transition",void 0),h([w(c.v249)],E.prototype,"_N$target",void 0),h([w(c.v342)],E.prototype,"_interactable",void 0),h([w(c.v342)],E.prototype,"_transition",void 0),h([w(c.v342)],E.prototype,"_duration",void 0),h([w(c.v342)],E.prototype,"_zoomScale",void 0),h([w(c.v342)],E.prototype,"_target",void 0),E=h([_("cc.Button")],E);class k{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 D extends k{constructor(){super(...arguments),this.__type__="cc.Color"}}class L{constructor(t=0,e=0){this.x=t||0,this.y=e||0}}let B=class extends L{constructor(){super(...arguments),this.__type__="cc.Vec2"}};B=h([_("cc.Vec2")],B);let R=class extends T{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 B,this._fillStart=0,this._fillRange=0,this._isTrimmedMode=!0,this._atlas=null,this._visFlags=0,this._customMaterial=null,this._color=new D(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),V.editorVersion>=c.v342&&(this._srcBlendFactor=2,this._dstBlendFactor=4)}setSpriteFrame(t){V.editorVersion>=c.v342?this._spriteFrame={__uuid__:`${t}@f9941`,__expectedType__:"cc.SpriteFrame"}:this._spriteFrame={__uuid__:t}}};h([w(c.v249)],R.prototype,"_materials",void 0),h([w(c.all)],R.prototype,"_srcBlendFactor",void 0),h([w(c.all)],R.prototype,"_dstBlendFactor",void 0),h([w(c.all)],R.prototype,"_spriteFrame",void 0),h([w(c.all)],R.prototype,"_type",void 0),h([w(c.all)],R.prototype,"_sizeMode",void 0),h([w(c.all)],R.prototype,"_fillType",void 0),h([w(c.all)],R.prototype,"_fillCenter",void 0),h([w(c.all)],R.prototype,"_fillStart",void 0),h([w(c.all)],R.prototype,"_fillRange",void 0),h([w(c.all)],R.prototype,"_isTrimmedMode",void 0),h([w(c.all)],R.prototype,"_atlas",void 0),h([w(c.v342)],R.prototype,"_visFlags",void 0),h([w(c.v342)],R.prototype,"_customMaterial",void 0),h([w(c.v342)],R.prototype,"_color",void 0),h([w(c.v342)],R.prototype,"_useGrayscale",void 0),R=h([_("cc.Sprite")],R);let U=class extends T{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 只能作用在 组图层 上")}};h([w(c.v249)],U.prototype,"_N$totalLength",void 0),h([w(c.v249)],U.prototype,"_N$barSprite",void 0),h([w(c.v249)],U.prototype,"_N$mode",void 0),h([w(c.v249)],U.prototype,"_N$progress",void 0),h([w(c.v249)],U.prototype,"_N$reverse",void 0),h([w(c.v342)],U.prototype,"_barSprite",void 0),h([w(c.v342)],U.prototype,"_mode",void 0),h([w(c.v342)],U.prototype,"_totalLength",void 0),h([w(c.v342)],U.prototype,"_progress",void 0),h([w(c.v342)],U.prototype,"_reverse",void 0),U=h([_("cc.ProgressBar")],U);let W=class extends E{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 只能作用在 组图层 上")}};h([w(c.v249)],W.prototype,"_N$isChecked",void 0),h([w(c.v249)],W.prototype,"toggleGroup",void 0),h([w(c.v249)],W.prototype,"checkMark",void 0),h([w(c.all)],W.prototype,"checkEvents",void 0),h([w(c.v342)],W.prototype,"_isChecked",void 0),h([w(c.v342)],W.prototype,"_checkMark",void 0),W=h([_("cc.Toggle")],W);const V=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=c.v249,this.DEFAULT_SPRITE_FRAME_MATERIAL={[c.v249]:"eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432",[c.v342]:""},this.DEFAULT_LABEL_MATERIAL={[c.v249]:"eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432",[c.v342]:""},this.CompMappings={Btn:E,ProgressBar:U,Toggle:W},this.textOffsetY={default:0,36:0},this.textLineHeightOffset=0}get SpriteFrame_Material(){return this.DEFAULT_SPRITE_FRAME_MATERIAL[V.editorVersion]}get Label_Material(){return this.DEFAULT_LABEL_MATERIAL[V.editorVersion]}};let X=new class{DFS(t,e,i=0){if(!o.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);let r=o.readdirSync(t),n=i;i++,r.forEach((r=>{let a=s.join(t,r),l=o.lstatSync(a).isDirectory();null==e||e({isDirectory:l,fullPath:a,fileName:r,depth:n}),l&&this.DFS(a,e,i)}))}filterFile(t,e){if(!o.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);var i=[];return o.readdirSync(t).forEach((r=>{let n=s.join(t,r),a=o.lstatSync(n).isDirectory();if(!a){if(!e(r))return}a?i=i.concat(this.filterFile(n,e)):i.push(n)})),i}getFolderFiles(t,e){if(!o.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);let i=[];return o.readdirSync(t).forEach((r=>{let n=s.join(t,r);o.lstatSync(n).isDirectory()?"folder"===e&&i.push({fullPath:n,basename:r}):"file"===e&&i.push({fullPath:n,basename:r})})),i}writeFile(t,e){return d(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=s.dirname(t);yield o.mkdirp(i),yield o.writeFile(t,e),console.log(`写入完成 ${t} `)}))}getMD5(t){return"string"==typeof t&&(t=o.readFileSync(t)),r.createHash("md5").update(t).digest("hex")}};class G{constructor(){this._imageMap=new Map,this._cachePath=null}initWithPath(t){if(!o.existsSync(t))return void console.log(`ImageCacheMgr-> 文件不存在: ${t}`);this._cachePath=t;let e=o.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 d(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 X.writeFile(t,i)}))}loadImages(t){if(this._imageMap.size>0)return void console.error("ImageCacheMgr-> 暂时只能在 启动时加载");let e=X.filterFile(t,(t=>".png"==s.extname(t)));if(e)for(let t=0;t缓存 ",i);let s=this._loadImageMetaWarp(`${i}.meta`);s&&this.set(o,s)}}_loadImageMetaWarp(t){let e=o.readFileSync(t,{encoding:"utf-8"}),i=null;switch(V.editorVersion){case c.v249:i=this._loadImageMeta249(e,t);break;case c.v342:i=this._loadImageMeta34x(e,t);break;default:console.log(`ImageCacheMgr-> 暂未实现 ${c[V.editorVersion]} 版本`)}return i}_loadImageMeta249(t,e){var i;let o=s.basename(e,".png.meta"),r=s.join(s.dirname(e),`${o}.png`),n=JSON.parse(t);return(null===(i=null==n?void 0:n.subMetas)||void 0===i?void 0:i[o])?{path:r,textureUuid:n.subMetas[o].uuid,uuid:n.uuid,isOutput:!0}:null}_loadImageMeta34x(t,e){var i;let o=s.basename(e,".png.meta"),r=s.join(s.dirname(e),`${o}.png`),n=JSON.parse(t);if(!(null===(i=null==n?void 0:n.subMetas)||void 0===i?void 0:i["6c48a"]))return null;let a=n.subMetas["6c48a"].uuid.replace("@6c48a","");return{path:r,textureUuid:a,uuid:a,isOutput:!0}}static getInstance(){return this._instance||(this._instance=new G),this._instance}}G._instance=null;const Y=G.getInstance();class H{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 H),this._instance}}H._instance=null;const J=H.getInstance();var q;!function(t){t[t.Doc=0]="Doc",t[t.Group=1]="Group",t[t.Text=2]="Text",t[t.Image=3]="Image"}(q||(q={}));class K{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 Q{constructor(t=0,e=0){this.width=t||0,this.height=e||0}}class Z{constructor(t=0,e=0,i=0){this.x=t||0,this.y=e||0,this.z=i||0}}class tt{constructor(t,e,i){var o,s,r,n;this.uuid=z.uuid(),this.source=t,this.parent=e,this.rootDoc=i,this.name=t.name,this.position=new L,this.size=new Q,this.rect=new K(t),this.anchorPoint=new L(.5,.5),this.hidden=!1,this.opacity=255,this.color=new k(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 Z(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${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]]=z.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||!tt.isPinyin)return t;if(!new RegExp("[\\u4E00-\\u9FFF]+","g").test(t))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}}tt.isPinyin=!1;class et extends tt{constructor(t,e,i){super(t,e,i),this.children=[],i&&(this.rect=new K(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;si+4)return console.log("Texture9Utils-> 设置的九宫格 left, right 数据不合理,请重新设置"),t;if(e.b+e.t>o+4)return console.log("Texture9Utils-> 设置的九宫格 bottom, top 数据不合理,请重新设置"),t;let c=a.createCanvas(Math.min(i,e.l+e.r+4)||i,Math.min(o,e.b+e.t+4)||o),p=c.getContext("2d");return p.drawImage(t,0,0,s+4,n+4,0,0,s+4,n+4),p.drawImage(t,0,o-l,s+4,l,0,n+4,s+4,l),p.drawImage(t,i-s,0,r,n+4,s+4,0,r,n+4),p.drawImage(t,i-s,o-l,r,l,s+4,n+4,r,l),c}}class st extends tt{constructor(t,e,i){var o;if(super(t,e,i),this.textureUuid=z.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=ot.safeBorder(this.source.canvas,t);let e=ot.split(this.source.canvas,t);this.source.canvas=e}let s=this.source.canvas;this.imgBuffer=s.toBuffer("image/png"),this.md5=X.getMD5(this.imgBuffer),this.textureSize=new Q(s.width,s.height),this.scale=new Z((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 rt extends tt{parseSource(){super.parseSource();let t=this.source.text,e=t.style;if(e){let t=e.fillColor;t&&(this.color=new k(t.r,t.g,t.b,255*t.a))}return this.text=t.text,this.fontSize=e.fontSize,this.offsetY=V.textOffsetY[this.fontSize]||V.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 k(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 空图层 ${null==t?void 0:t.name}`),null;let s=o=new st(t,e,i);J.add(s),s.isIgnore()||s.isBind()||Y.has(s.md5)||Y.set(s.md5,{uuid:s.uuid,textureUuid:s.textureUuid})}break;case q.Text:o=new rt(t,e,i)}return o.layerType=s,o.parseSource(),o.onCtor(),o}};class at extends O{constructor(){super(),this.__type__="cc.CompPrefabInfo",this.fileId="",this.fileId=z.compressUuid(this.uuid)}}let lt=class extends Q{constructor(){super(...arguments),this.__type__="cc.Size"}};lt=h([_("cc.Size")],lt);let ct=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}};ct=h([_("TypedArray")],ct);class pt extends Z{constructor(){super(...arguments),this.__type__="cc.Vec3"}}let ht=class extends A{constructor(t){super(),this._parent=null,this._children=[],this._active=!0,this._components=[],this._prefab=null,this._id="",this._opacity=255,this._color=new D(255,255,255,255),this._contentSize=new lt,this._anchorPoint=new B(0,0),this._trs=new ct,this._eulerAngles=new pt,this._skewX=0,this._skewY=0,this._is3DNode=!1,this._groupIndex=0,this.groupIndex=0,this._renderEnable=!1,this._bfsRenderFlag=!1,this._lpos=new pt,this._lrot=new pt,this._lscale=new pt,this._euler=new pt,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),V.editorVersion>=c.v342&&this.addCompPrefabInfo(t)}addCompPrefabInfo(t){let e=new at,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)}};h([w(c.all)],ht.prototype,"_parent",void 0),h([w(c.all)],ht.prototype,"_children",void 0),h([w(c.all)],ht.prototype,"_active",void 0),h([w(c.all)],ht.prototype,"_components",void 0),h([w(c.all)],ht.prototype,"_prefab",void 0),h([w(c.all)],ht.prototype,"_id",void 0),h([w(c.v249)],ht.prototype,"_opacity",void 0),h([w(c.v249)],ht.prototype,"_color",void 0),h([w(c.v249)],ht.prototype,"_contentSize",void 0),h([w(c.v249)],ht.prototype,"_anchorPoint",void 0),h([w(c.v249)],ht.prototype,"_trs",void 0),h([w(c.v249)],ht.prototype,"_eulerAngles",void 0),h([w(c.v249)],ht.prototype,"_skewX",void 0),h([w(c.v249)],ht.prototype,"_skewY",void 0),h([w(c.v249)],ht.prototype,"_is3DNode",void 0),h([w(c.v249)],ht.prototype,"_groupIndex",void 0),h([w(c.v249)],ht.prototype,"groupIndex",void 0),h([w(c.v249)],ht.prototype,"_renderEnable",void 0),h([w(c.v249)],ht.prototype,"_bfsRenderFlag",void 0),h([w(c.v342)],ht.prototype,"_lpos",void 0),h([w(c.v342)],ht.prototype,"_lrot",void 0),h([w(c.v342)],ht.prototype,"_lscale",void 0),h([w(c.v342)],ht.prototype,"_euler",void 0),h([w(c.v342)],ht.prototype,"_layer",void 0),h([u],ht.prototype,"psdDoc",void 0),h([u],ht.prototype,"components",void 0),h([u],ht.prototype,"children",void 0),ht=h([_("cc.Node")],ht);class dt extends O{constructor(){super(),this.__type__="cc.PrefabInfo",this.root={__id__:1},this.asset={__id__:0},this.fileId="",this.sync=!1,this.fileId=z.compressUuid(this.uuid)}}h([w(c.all)],dt.prototype,"__type__",void 0),h([w(c.all)],dt.prototype,"root",void 0),h([w(c.all)],dt.prototype,"asset",void 0),h([w(c.all)],dt.prototype,"fileId",void 0),h([w(c.all)],dt.prototype,"sync",void 0);let ut=class extends A{constructor(){super(...arguments),this._native="",this.data=null,this.optimizationPolicy=0,this.asyncLoadAssets=!1,this.readonly=!1,this.persistent=!1}};h([w(c.all)],ut.prototype,"_native",void 0),h([w(c.all)],ut.prototype,"data",void 0),h([w(c.all)],ut.prototype,"optimizationPolicy",void 0),h([w(c.all)],ut.prototype,"asyncLoadAssets",void 0),h([w(c.v249)],ut.prototype,"readonly",void 0),h([w(c.v342)],ut.prototype,"persistent",void 0),ut=h([_("cc.Prefab")],ut);let _t=class extends T{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 D(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+V.textLineHeightOffset,V.editorVersion>=c.v342&&(this._srcBlendFactor=2,this._dstBlendFactor=4)}};h([w(c.all)],_t.prototype,"_srcBlendFactor",void 0),h([w(c.all)],_t.prototype,"_dstBlendFactor",void 0),h([w(c.all)],_t.prototype,"_string",void 0),h([w(c.all)],_t.prototype,"_fontSize",void 0),h([w(c.all)],_t.prototype,"_lineHeight",void 0),h([w(c.all)],_t.prototype,"_enableWrapText",void 0),h([w(c.all)],_t.prototype,"_isSystemFontUsed",void 0),h([w(c.all)],_t.prototype,"_spacingX",void 0),h([w(c.all)],_t.prototype,"_underlineHeight",void 0),h([w(c.v249)],_t.prototype,"_materials",void 0),h([w(c.v249)],_t.prototype,"_N$string",void 0),h([w(c.v249)],_t.prototype,"_N$file",void 0),h([w(c.v249)],_t.prototype,"_batchAsBitmap",void 0),h([w(c.v249)],_t.prototype,"_styleFlags",void 0),h([w(c.v249)],_t.prototype,"_N$horizontalAlign",void 0),h([w(c.v249)],_t.prototype,"_N$verticalAlign",void 0),h([w(c.v249)],_t.prototype,"_N$fontFamily",void 0),h([w(c.v249)],_t.prototype,"_N$overflow",void 0),h([w(c.v249)],_t.prototype,"_N$cacheMode",void 0),h([w(c.v342)],_t.prototype,"_visFlags",void 0),h([w(c.v342)],_t.prototype,"_customMaterial",void 0),h([w(c.v342)],_t.prototype,"_color",void 0),h([w(c.v342)],_t.prototype,"_overflow",void 0),h([w(c.v342)],_t.prototype,"_cacheMode",void 0),h([w(c.v342)],_t.prototype,"_horizontalAlign",void 0),h([w(c.v342)],_t.prototype,"_verticalAlign",void 0),h([w(c.v342)],_t.prototype,"_actualFontSize",void 0),h([w(c.v342)],_t.prototype,"_isItalic",void 0),h([w(c.v342)],_t.prototype,"_isBold",void 0),h([w(c.v342)],_t.prototype,"_isUnderline",void 0),_t=h([_("cc.Label")],_t);let vt=class extends T{constructor(){super(...arguments),this._color=new D(255,255,255,255),this._width=1}updateWithLayer(t){this._width=t.outline.width,this._color.set(t.outline.color)}};h([w(c.all)],vt.prototype,"_color",void 0),h([w(c.all)],vt.prototype,"_width",void 0),vt=h([_("cc.LabelOutline")],vt);class gt{constructor(){this.textObjects=[]}test(){const t=s.join(__dirname,"..","out");this.parsePsd("./test-img-only/境界奖励-优化.psd",t)}exec(t){return d(this,void 0,void 0,(function*(){if(!this.checkArgs(t))return;if(o.lstatSync(t.input).isDirectory())t.output||(t.output=s.join(t.input,"psd2ui")),this.parsePsdDir(t.input,t.output);else{if(!t.output){let e=s.dirname(t.input);t.output=s.join(e,"psd2ui")}this.parsePsd(t.input,t.output)}}))}checkArgs(t){return t.input?!!o.existsSync(t.input)||(console.error(`输入路径不存在: ${t.input}`),!1):(console.error("请设置 --input"),!1)}parsePsdDir(t,e){return d(this,void 0,void 0,(function*(){o.emptyDirSync(e);let i=X.filterFile(t,(t=>".psd"==s.extname(t)));for(let t=0;t{let n=J.getSerialNumberImage(e),a=`${n.imgName}_${i}`;console.log(`保存图片 [${n.imgName}] 重命名为 [${a}] md5: ${n.md5}`);let l=s.join(t,`${a}.png`);o.writeFileSync(l,n.imgBuffer),i++}))}saveTextFile(t,e){this.scanText(t,t);let i=JSON.stringify(this.textObjects,null,2),r=s.join(e,"text.txt");o.writeFileSync(r,i,{encoding:"utf-8"})}scanText(t,e){if(t instanceof et)for(let i=0;i test")}))}loadMetaTemplete(){return d(this,void 0,void 0,(function*(){this.spriteFrameMetaContent=o.readFileSync(s.join(__dirname,`../assets/cc/meta/CCSpriteFrame.meta.${c[V.editorVersion]}`),"utf-8"),this.prefabMetaContent=o.readFileSync(s.join(__dirname,`../assets/cc/meta/CCPrefab.meta.${c[V.editorVersion]}`),"utf-8")}))}loadPsdConfig(t){return d(this,void 0,void 0,(function*(){if(!o.existsSync(t))return void console.log(`Main-> 配置 ${t} 不存在`);let e=o.readFileSync(t,"utf-8");this.psdConfig=JSON.parse(e);for(const t in this.psdConfig)t in V&&("object"==typeof this.psdConfig[t]?V[t]=Object.assign({},V[t],this.psdConfig[t]):V[t]=this.psdConfig[t]||V[t])}))}exec(t){return d(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",V.help),!1;if(t["img-only"])return ft.exec(t),!0;let e=()=>d(this,void 0,void 0,(function*(){t.cache&&(o.mkdirsSync(s.dirname(t.cache)),yield Y.saveImageMap(t.cache))}));if(t["engine-version"]&&(V.editorVersion=c[t["engine-version"]]),console.log(`Main-> 数据版本 ${c[V.editorVersion]}`),!t.init||t["project-assets"]&&t.cache){if(t.cache&&!o.existsSync(t.cache)&&e(),t["project-assets"]&&(t["cache-remake"]||t.init)&&(yield Y.loadImages(t["project-assets"]),e(),t.init))console.log("psd2ui 缓存完成");else if(this.checkArgs(t)){if(t.cache&&(yield Y.initWithPath(t.cache)),yield this.loadMetaTemplete(),t.config&&(yield this.loadPsdConfig(t.config)),this.isForceImg=!!t["force-img"],tt.isPinyin=t.pinyin,o.lstatSync(t.input).isDirectory())t.output||(t.output=s.join(t.input,"psd2ui")),this.parsePsdDir(t.input,t.output);else{if(!t.output){let e=s.dirname(t.input);t.output=s.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(!o.existsSync(t.input))return console.error(`输入路径不存在: ${t.input}`),!1;if(t["engine-version"]){switch(c[t["engine-version"]]){case c.v249:case c.v342:break;default:return console.log(`暂未实现该引擎版本 ${t["engine-version"]}`),!1}}return!0}parsePsdDir(t,e){return d(this,void 0,void 0,(function*(){let i=X.filterFile(t,(t=>".psd"==s.extname(t)));for(let t=0;t=c.v342&&255!==t.opacity){let e=new yt;e._opacity=t.opacity,e.updateWithLayer(t),r.addComponent(e)}let n=new lt(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 rt&&(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 B(t.anchorPoint.x,t.anchorPoint.y),V.editorVersion>=c.v342){r._lpos=new pt(t.position.x,t.position.y+a,0),r._lrot=new pt(0,0,0),r._lscale=new pt(t.scale.x,t.scale.y,t.scale.z),r._euler=new pt;let e=new mt;e._contentSize=n,e._anchorPoint=r._anchorPoint,e.updateWithLayer(t),r.addComponent(e)}if(t instanceof et)for(let i=0;i{let r=J.getSerialNumberImage(e),n=Y.get(r.md5);if(!this.isForceImg&&(null==n?void 0:n.isOutput))return void console.log(`已有相同资源,不再导出 [${e.imgName}] md5: ${e.md5}`);console.log(`保存图片 [${r.imgName}] md5: ${r.md5}`),n&&(n.isOutput=!0);let a=s.join(t,`${r.imgName}.png`);o.writeFileSync(a,r.imgBuffer),this.saveImageMeta(r,a)}))}saveImageMeta(t,e){let i=J.getSerialNumberImage(t),s=Y.get(i.md5);s||(s=i);let r=this.spriteFrameMetaContent.replace(/\$SPRITE_FRAME_UUID/g,s.uuid);r=r.replace(/\$TEXTURE_UUID/g,s.textureUuid),r=r.replace(/\$FILE_NAME/g,i.imgName),r=r.replace(/\$WIDTH/g,i.textureSize.width),r=r.replace(/\$HEIGHT/g,i.textureSize.height);let n=i.s9||{b:0,t:0,l:0,r:0};r=r.replace(/\$BORDER_TOP/g,n.t),r=r.replace(/\$BORDER_BOTTOM/g,n.b),r=r.replace(/\$BORDER_LEFT/g,n.l),r=r.replace(/\$BORDER_RIGHT/g,n.r),o.writeFileSync(e+".meta",r)}savePrefab(t,e){let i=s.join(e,`${t.name}.prefab`);o.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);o.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}}}};bt.length?wt.exec(xt):wt.test()})); diff --git a/psd2ui-tools/dist/index.js b/psd2ui-tools/dist/index.js index a049817..95f237d 100644 --- a/psd2ui-tools/dist/index.js +++ b/psd2ui-tools/dist/index.js @@ -1 +1 @@ -!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){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 c,p=l(i);function h(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 d(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"}(c||(c={}));let u=(t,e)=>{t.__unserialization||(t.__unserialization=[]),t.__unserialization.push(e)};function _(t){return e=>{Object.defineProperty(e.prototype,"$__type__",{value:t,enumerable:!0})}}let v={},g={},f={},y=0;function m(t){return void 0!==t.constructor.__ver_tag_id__&&f[t.constructor.__ver_tag_id__]==t||(t.constructor.__ver_tag_id__=`${y}`,f[t.constructor.__ver_tag_id__]=t,y++),t.constructor.__ver_tag_id__}function b(t,e){for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)){if(i in t)continue;t[i]=e[i]}}function x(t,...e){for(let i=0;i{let o=e.constructor.name;o=m(e),!g[o]&&(g[o]={});let s=g[o];if(s[i]||(s[i]={}),c.all===t)for(const t in c)s[i][c[t]]=!0;else s[i][c[t]]=!0;var r=S(e.constructor);if(r){let t=m(r.prototype);!v[o]&&(v[o]=t);for(var n=S(r);n;){let e=m(n.prototype);!v[t]&&(v[t]=e),n=S(n)}for(;t;)t in g&&x(s,g[t]),t=v[t]}e._version||(e._version={}),e._version[o]=g[o]=s}}function S(t){var e=t.prototype,i=e&&Object.getPrototypeOf(e);return i&&i.constructor}const M="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",F=new Array(123);for(let t=0;t<123;++t)F[t]=64;for(let t=0;t<64;++t)F[M.charCodeAt(t)]=t;const P=F,I="0123456789abcdef".split(""),$=["","","",""],j=$.concat($,"-",$,"-",$,"-",$,"-",$,$,$),C=j.map(((t,e)=>"-"===t?NaN:e)).filter(isFinite);let N={};for(let t=0;t>2],j[C[i++]]=I[(3&o)<<2|s>>4],j[C[i++]]=I[15&s]}return t.replace(e,j.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=N[String.fromCharCode(o.charCodeAt(t))],r=N[String.fromCharCode(o.charCodeAt(t+1))],n=N[String.fromCharCode(o.charCodeAt(t+2))];i[e++]=M[(s<<2)+(r>>2)],i[e++]=M[((3&r)<<4)+n]}return t.replace(e,i.join(""))}isNumber(t){return!isNaN(parseFloat(t))&&isFinite(t)}};class O{constructor(){this.uuid="",this.idx=0,this.uuid=z.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][c[V.editorVersion]])continue;const s=this[i];e[i]=s}return e}}h([u],O.prototype,"uuid",void 0),h([u],O.prototype,"idx",void 0);class A extends O{constructor(){super(),this._name="",this._objFlags=0,this.__type__=this.$__type__}}h([w(c.all)],A.prototype,"__type__",void 0),h([w(c.all)],A.prototype,"_name",void 0),h([w(c.all)],A.prototype,"_objFlags",void 0);class T extends A{constructor(){super(...arguments),this._enabled=!0,this.node=null,this._id="",this.__prefab=null}}h([w(c.all)],T.prototype,"_enabled",void 0),h([w(c.all)],T.prototype,"node",void 0),h([w(c.all)],T.prototype,"_id",void 0),h([w(c.v342)],T.prototype,"__prefab",void 0);let E=class extends T{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){}};h([w(c.v249)],E.prototype,"duration",void 0),h([w(c.v249)],E.prototype,"zoomScale",void 0),h([w(c.all)],E.prototype,"clickEvents",void 0),h([w(c.v249)],E.prototype,"_N$interactable",void 0),h([w(c.v249)],E.prototype,"_N$enableAutoGrayEffect",void 0),h([w(c.v249)],E.prototype,"_N$transition",void 0),h([w(c.v249)],E.prototype,"transition",void 0),h([w(c.v249)],E.prototype,"_N$target",void 0),h([w(c.v342)],E.prototype,"_interactable",void 0),h([w(c.v342)],E.prototype,"_transition",void 0),h([w(c.v342)],E.prototype,"_duration",void 0),h([w(c.v342)],E.prototype,"_zoomScale",void 0),h([w(c.v342)],E.prototype,"_target",void 0),E=h([_("cc.Button")],E);class k{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 D extends k{constructor(){super(...arguments),this.__type__="cc.Color"}}class L{constructor(t=0,e=0){this.x=t||0,this.y=e||0}}let B=class extends L{constructor(){super(...arguments),this.__type__="cc.Vec2"}};B=h([_("cc.Vec2")],B);let R=class extends T{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 B,this._fillStart=0,this._fillRange=0,this._isTrimmedMode=!0,this._atlas=null,this._visFlags=0,this._customMaterial=null,this._color=new D(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),V.editorVersion>=c.v342&&(this._srcBlendFactor=2,this._dstBlendFactor=4)}setSpriteFrame(t){V.editorVersion>=c.v342?this._spriteFrame={__uuid__:`${t}@f9941`,__expectedType__:"cc.SpriteFrame"}:this._spriteFrame={__uuid__:t}}};h([w(c.v249)],R.prototype,"_materials",void 0),h([w(c.all)],R.prototype,"_srcBlendFactor",void 0),h([w(c.all)],R.prototype,"_dstBlendFactor",void 0),h([w(c.all)],R.prototype,"_spriteFrame",void 0),h([w(c.all)],R.prototype,"_type",void 0),h([w(c.all)],R.prototype,"_sizeMode",void 0),h([w(c.all)],R.prototype,"_fillType",void 0),h([w(c.all)],R.prototype,"_fillCenter",void 0),h([w(c.all)],R.prototype,"_fillStart",void 0),h([w(c.all)],R.prototype,"_fillRange",void 0),h([w(c.all)],R.prototype,"_isTrimmedMode",void 0),h([w(c.all)],R.prototype,"_atlas",void 0),h([w(c.v342)],R.prototype,"_visFlags",void 0),h([w(c.v342)],R.prototype,"_customMaterial",void 0),h([w(c.v342)],R.prototype,"_color",void 0),h([w(c.v342)],R.prototype,"_useGrayscale",void 0),R=h([_("cc.Sprite")],R);let U=class extends T{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 只能作用在 组图层 上")}};h([w(c.v249)],U.prototype,"_N$totalLength",void 0),h([w(c.v249)],U.prototype,"_N$barSprite",void 0),h([w(c.v249)],U.prototype,"_N$mode",void 0),h([w(c.v249)],U.prototype,"_N$progress",void 0),h([w(c.v249)],U.prototype,"_N$reverse",void 0),h([w(c.v342)],U.prototype,"_barSprite",void 0),h([w(c.v342)],U.prototype,"_mode",void 0),h([w(c.v342)],U.prototype,"_totalLength",void 0),h([w(c.v342)],U.prototype,"_progress",void 0),h([w(c.v342)],U.prototype,"_reverse",void 0),U=h([_("cc.ProgressBar")],U);let W=class extends E{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 只能作用在 组图层 上")}};h([w(c.v249)],W.prototype,"_N$isChecked",void 0),h([w(c.v249)],W.prototype,"toggleGroup",void 0),h([w(c.v249)],W.prototype,"checkMark",void 0),h([w(c.all)],W.prototype,"checkEvents",void 0),h([w(c.v342)],W.prototype,"_isChecked",void 0),h([w(c.v342)],W.prototype,"_checkMark",void 0),W=h([_("cc.Toggle")],W);const V=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=c.v249,this.DEFAULT_SPRITE_FRAME_MATERIAL={[c.v249]:"eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432",[c.v342]:""},this.DEFAULT_LABEL_MATERIAL={[c.v249]:"eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432",[c.v342]:""},this.CompMappings={Btn:E,ProgressBar:U,Toggle:W},this.textOffsetY={default:0,36:0},this.textLineHeightOffset=0}get SpriteFrame_Material(){return this.DEFAULT_SPRITE_FRAME_MATERIAL[V.editorVersion]}get Label_Material(){return this.DEFAULT_LABEL_MATERIAL[V.editorVersion]}};let X=new class{DFS(t,e,i=0){if(!o.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);let r=o.readdirSync(t),n=i;i++,r.forEach((r=>{let a=s.join(t,r),l=o.lstatSync(a).isDirectory();null==e||e({isDirectory:l,fullPath:a,fileName:r,depth:n}),l&&this.DFS(a,e,i)}))}filterFile(t,e){if(!o.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);var i=[];return o.readdirSync(t).forEach((r=>{let n=s.join(t,r),a=o.lstatSync(n).isDirectory();if(!a){if(!e(r))return}a?i=i.concat(this.filterFile(n,e)):i.push(n)})),i}getFolderFiles(t,e){if(!o.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);let i=[];return o.readdirSync(t).forEach((r=>{let n=s.join(t,r);o.lstatSync(n).isDirectory()?"folder"===e&&i.push({fullPath:n,basename:r}):"file"===e&&i.push({fullPath:n,basename:r})})),i}writeFile(t,e){return d(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=s.dirname(t);yield o.mkdirp(i),yield o.writeFile(t,e),console.log(`写入完成 ${t} `)}))}getMD5(t){return"string"==typeof t&&(t=o.readFileSync(t)),r.createHash("md5").update(t).digest("hex")}};class G{constructor(){this._imageMap=new Map,this._cachePath=null}initWithPath(t){if(!o.existsSync(t))return void console.log(`ImageCacheMgr-> 文件不存在: ${t}`);this._cachePath=t;let e=o.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 d(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 X.writeFile(t,i)}))}loadImages(t){if(this._imageMap.size>0)return void console.error("ImageCacheMgr-> 暂时只能在 启动时加载");let e=X.filterFile(t,(t=>".png"==s.extname(t)));if(e)for(let t=0;t缓存 ",i);let s=this._loadImageMetaWarp(`${i}.meta`);s&&this.set(o,s)}}_loadImageMetaWarp(t){let e=o.readFileSync(t,{encoding:"utf-8"}),i=null;switch(V.editorVersion){case c.v249:i=this._loadImageMeta249(e,t);break;case c.v342:i=this._loadImageMeta34x(e,t);break;default:console.log(`ImageCacheMgr-> 暂未实现 ${c[V.editorVersion]} 版本`)}return i}_loadImageMeta249(t,e){var i;let o=s.basename(e,".png.meta"),r=s.join(s.dirname(e),`${o}.png`),n=JSON.parse(t);return(null===(i=null==n?void 0:n.subMetas)||void 0===i?void 0:i[o])?{path:r,textureUuid:n.subMetas[o].uuid,uuid:n.uuid,isOutput:!0}:null}_loadImageMeta34x(t,e){var i;let o=s.basename(e,".png.meta"),r=s.join(s.dirname(e),`${o}.png`),n=JSON.parse(t);if(!(null===(i=null==n?void 0:n.subMetas)||void 0===i?void 0:i["6c48a"]))return null;let a=n.subMetas["6c48a"].uuid.replace("@6c48a","");return{path:r,textureUuid:a,uuid:a,isOutput:!0}}static getInstance(){return this._instance||(this._instance=new G),this._instance}}G._instance=null;const Y=G.getInstance();class H{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 H),this._instance}}H._instance=null;const J=H.getInstance();var q;!function(t){t[t.Doc=0]="Doc",t[t.Group=1]="Group",t[t.Text=2]="Text",t[t.Image=3]="Image"}(q||(q={}));class K{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 Q{constructor(t=0,e=0){this.width=t||0,this.height=e||0}}class Z{constructor(t=0,e=0,i=0){this.x=t||0,this.y=e||0,this.z=i||0}}class tt{constructor(t,e,i){var o,s,r,n;this.uuid=z.uuid(),this.source=t,this.parent=e,this.rootDoc=i,this.name=t.name,this.position=new L,this.size=new Q,this.rect=new K(t),this.anchorPoint=new L(.5,.5),this.hidden=!1,this.opacity=255,this.color=new k(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 Z(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${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]]=z.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||!tt.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}}tt.isPinyin=!1;class et extends tt{constructor(t,e,i){super(t,e,i),this.children=[],i&&(this.rect=new K(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;si+4)return console.log("Texture9Utils-> 设置的九宫格 left, right 数据不合理,请重新设置"),t;if(e.b+e.t>o+4)return console.log("Texture9Utils-> 设置的九宫格 bottom, top 数据不合理,请重新设置"),t;let c=a.createCanvas(Math.min(i,e.l+e.r+4)||i,Math.min(o,e.b+e.t+4)||o),p=c.getContext("2d");return p.drawImage(t,0,0,s+4,n+4,0,0,s+4,n+4),p.drawImage(t,0,o-l,s+4,l,0,n+4,s+4,l),p.drawImage(t,i-s,0,r,n+4,s+4,0,r,n+4),p.drawImage(t,i-s,o-l,r,l,s+4,n+4,r,l),c}}class st extends tt{constructor(t,e,i){var o;if(super(t,e,i),this.textureUuid=z.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=ot.safeBorder(this.source.canvas,t);let e=ot.split(this.source.canvas,t);this.source.canvas=e}let s=this.source.canvas;this.imgBuffer=s.toBuffer("image/png"),this.md5=X.getMD5(this.imgBuffer),this.textureSize=new Q(s.width,s.height),this.scale=new Z((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 rt extends tt{parseSource(){super.parseSource();let t=this.source.text,e=t.style;if(e){let t=e.fillColor;t&&(this.color=new k(t.r,t.g,t.b,255*t.a))}return this.text=t.text,this.fontSize=e.fontSize,this.offsetY=V.textOffsetY[this.fontSize]||V.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 k(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 空图层 ${null==t?void 0:t.name}`),null;let s=o=new st(t,e,i);J.add(s),s.isIgnore()||s.isBind()||Y.has(s.md5)||Y.set(s.md5,{uuid:s.uuid,textureUuid:s.textureUuid})}break;case q.Text:o=new rt(t,e,i)}return o.layerType=s,o.parseSource(),o.onCtor(),o}};class at extends O{constructor(){super(),this.__type__="cc.CompPrefabInfo",this.fileId="",this.fileId=z.compressUuid(this.uuid)}}let lt=class extends Q{constructor(){super(...arguments),this.__type__="cc.Size"}};lt=h([_("cc.Size")],lt);let ct=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}};ct=h([_("TypedArray")],ct);class pt extends Z{constructor(){super(...arguments),this.__type__="cc.Vec3"}}let ht=class extends A{constructor(t){super(),this._parent=null,this._children=[],this._active=!0,this._components=[],this._prefab=null,this._id="",this._opacity=255,this._color=new D(255,255,255,255),this._contentSize=new lt,this._anchorPoint=new B(0,0),this._trs=new ct,this._eulerAngles=new pt,this._skewX=0,this._skewY=0,this._is3DNode=!1,this._groupIndex=0,this.groupIndex=0,this._renderEnable=!1,this._bfsRenderFlag=!1,this._lpos=new pt,this._lrot=new pt,this._lscale=new pt,this._euler=new pt,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),V.editorVersion>=c.v342&&this.addCompPrefabInfo(t)}addCompPrefabInfo(t){let e=new at,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)}};h([w(c.all)],ht.prototype,"_parent",void 0),h([w(c.all)],ht.prototype,"_children",void 0),h([w(c.all)],ht.prototype,"_active",void 0),h([w(c.all)],ht.prototype,"_components",void 0),h([w(c.all)],ht.prototype,"_prefab",void 0),h([w(c.all)],ht.prototype,"_id",void 0),h([w(c.v249)],ht.prototype,"_opacity",void 0),h([w(c.v249)],ht.prototype,"_color",void 0),h([w(c.v249)],ht.prototype,"_contentSize",void 0),h([w(c.v249)],ht.prototype,"_anchorPoint",void 0),h([w(c.v249)],ht.prototype,"_trs",void 0),h([w(c.v249)],ht.prototype,"_eulerAngles",void 0),h([w(c.v249)],ht.prototype,"_skewX",void 0),h([w(c.v249)],ht.prototype,"_skewY",void 0),h([w(c.v249)],ht.prototype,"_is3DNode",void 0),h([w(c.v249)],ht.prototype,"_groupIndex",void 0),h([w(c.v249)],ht.prototype,"groupIndex",void 0),h([w(c.v249)],ht.prototype,"_renderEnable",void 0),h([w(c.v249)],ht.prototype,"_bfsRenderFlag",void 0),h([w(c.v342)],ht.prototype,"_lpos",void 0),h([w(c.v342)],ht.prototype,"_lrot",void 0),h([w(c.v342)],ht.prototype,"_lscale",void 0),h([w(c.v342)],ht.prototype,"_euler",void 0),h([w(c.v342)],ht.prototype,"_layer",void 0),h([u],ht.prototype,"psdDoc",void 0),h([u],ht.prototype,"components",void 0),h([u],ht.prototype,"children",void 0),ht=h([_("cc.Node")],ht);class dt extends O{constructor(){super(),this.__type__="cc.PrefabInfo",this.root={__id__:1},this.asset={__id__:0},this.fileId="",this.sync=!1,this.fileId=z.compressUuid(this.uuid)}}h([w(c.all)],dt.prototype,"__type__",void 0),h([w(c.all)],dt.prototype,"root",void 0),h([w(c.all)],dt.prototype,"asset",void 0),h([w(c.all)],dt.prototype,"fileId",void 0),h([w(c.all)],dt.prototype,"sync",void 0);let ut=class extends A{constructor(){super(...arguments),this._native="",this.data=null,this.optimizationPolicy=0,this.asyncLoadAssets=!1,this.readonly=!1,this.persistent=!1}};h([w(c.all)],ut.prototype,"_native",void 0),h([w(c.all)],ut.prototype,"data",void 0),h([w(c.all)],ut.prototype,"optimizationPolicy",void 0),h([w(c.all)],ut.prototype,"asyncLoadAssets",void 0),h([w(c.v249)],ut.prototype,"readonly",void 0),h([w(c.v342)],ut.prototype,"persistent",void 0),ut=h([_("cc.Prefab")],ut);let _t=class extends T{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 D(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+V.textLineHeightOffset,V.editorVersion>=c.v342&&(this._srcBlendFactor=2,this._dstBlendFactor=4)}};h([w(c.all)],_t.prototype,"_srcBlendFactor",void 0),h([w(c.all)],_t.prototype,"_dstBlendFactor",void 0),h([w(c.all)],_t.prototype,"_string",void 0),h([w(c.all)],_t.prototype,"_fontSize",void 0),h([w(c.all)],_t.prototype,"_lineHeight",void 0),h([w(c.all)],_t.prototype,"_enableWrapText",void 0),h([w(c.all)],_t.prototype,"_isSystemFontUsed",void 0),h([w(c.all)],_t.prototype,"_spacingX",void 0),h([w(c.all)],_t.prototype,"_underlineHeight",void 0),h([w(c.v249)],_t.prototype,"_materials",void 0),h([w(c.v249)],_t.prototype,"_N$string",void 0),h([w(c.v249)],_t.prototype,"_N$file",void 0),h([w(c.v249)],_t.prototype,"_batchAsBitmap",void 0),h([w(c.v249)],_t.prototype,"_styleFlags",void 0),h([w(c.v249)],_t.prototype,"_N$horizontalAlign",void 0),h([w(c.v249)],_t.prototype,"_N$verticalAlign",void 0),h([w(c.v249)],_t.prototype,"_N$fontFamily",void 0),h([w(c.v249)],_t.prototype,"_N$overflow",void 0),h([w(c.v249)],_t.prototype,"_N$cacheMode",void 0),h([w(c.v342)],_t.prototype,"_visFlags",void 0),h([w(c.v342)],_t.prototype,"_customMaterial",void 0),h([w(c.v342)],_t.prototype,"_color",void 0),h([w(c.v342)],_t.prototype,"_overflow",void 0),h([w(c.v342)],_t.prototype,"_cacheMode",void 0),h([w(c.v342)],_t.prototype,"_horizontalAlign",void 0),h([w(c.v342)],_t.prototype,"_verticalAlign",void 0),h([w(c.v342)],_t.prototype,"_actualFontSize",void 0),h([w(c.v342)],_t.prototype,"_isItalic",void 0),h([w(c.v342)],_t.prototype,"_isBold",void 0),h([w(c.v342)],_t.prototype,"_isUnderline",void 0),_t=h([_("cc.Label")],_t);let vt=class extends T{constructor(){super(...arguments),this._color=new D(255,255,255,255),this._width=1}updateWithLayer(t){this._width=t.outline.width,this._color.set(t.outline.color)}};h([w(c.all)],vt.prototype,"_color",void 0),h([w(c.all)],vt.prototype,"_width",void 0),vt=h([_("cc.LabelOutline")],vt);class gt{constructor(){this.textObjects=[]}test(){const t=s.join(__dirname,"..","out");this.parsePsd("./test-img-only/境界奖励-优化.psd",t)}exec(t){return d(this,void 0,void 0,(function*(){if(!this.checkArgs(t))return;if(o.lstatSync(t.input).isDirectory())t.output||(t.output=s.join(t.input,"psd2ui")),this.parsePsdDir(t.input,t.output);else{if(!t.output){let e=s.dirname(t.input);t.output=s.join(e,"psd2ui")}this.parsePsd(t.input,t.output)}}))}checkArgs(t){return t.input?!!o.existsSync(t.input)||(console.error(`输入路径不存在: ${t.input}`),!1):(console.error("请设置 --input"),!1)}parsePsdDir(t,e){return d(this,void 0,void 0,(function*(){o.emptyDirSync(e);let i=X.filterFile(t,(t=>".psd"==s.extname(t)));for(let t=0;t{let n=J.getSerialNumberImage(e),a=`${n.imgName}_${i}`;console.log(`保存图片 [${n.imgName}] 重命名为 [${a}] md5: ${n.md5}`);let l=s.join(t,`${a}.png`);o.writeFileSync(l,n.imgBuffer),i++}))}saveTextFile(t,e){this.scanText(t,t);let i=JSON.stringify(this.textObjects,null,2),r=s.join(e,"text.txt");o.writeFileSync(r,i,{encoding:"utf-8"})}scanText(t,e){if(t instanceof et)for(let i=0;i test")}))}loadMetaTemplete(){return d(this,void 0,void 0,(function*(){this.spriteFrameMetaContent=o.readFileSync(s.join(__dirname,`../assets/cc/meta/CCSpriteFrame.meta.${c[V.editorVersion]}`),"utf-8"),this.prefabMetaContent=o.readFileSync(s.join(__dirname,`../assets/cc/meta/CCPrefab.meta.${c[V.editorVersion]}`),"utf-8")}))}loadPsdConfig(t){return d(this,void 0,void 0,(function*(){if(!o.existsSync(t))return void console.log(`Main-> 配置 ${t} 不存在`);let e=o.readFileSync(t,"utf-8");this.psdConfig=JSON.parse(e);for(const t in this.psdConfig)t in V&&("object"==typeof this.psdConfig[t]?V[t]=Object.assign({},V[t],this.psdConfig[t]):V[t]=this.psdConfig[t]||V[t])}))}exec(t){return d(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",V.help),!1;if(t["img-only"])return ft.exec(t),!0;let e=()=>d(this,void 0,void 0,(function*(){t.cache&&(o.mkdirsSync(s.dirname(t.cache)),yield Y.saveImageMap(t.cache))}));if(t["engine-version"]&&(V.editorVersion=c[t["engine-version"]]),console.log(`Main-> 数据版本 ${c[V.editorVersion]}`),!t.init||t["project-assets"]&&t.cache){if(t.cache&&!o.existsSync(t.cache)&&e(),t["project-assets"]&&(t["cache-remake"]||t.init)&&(yield Y.loadImages(t["project-assets"]),e(),t.init))console.log("psd2ui 缓存完成");else if(this.checkArgs(t)){if(t.cache&&(yield Y.initWithPath(t.cache)),yield this.loadMetaTemplete(),t.config&&(yield this.loadPsdConfig(t.config)),this.isForceImg=!!t["force-img"],tt.isPinyin=t.pinyin,o.lstatSync(t.input).isDirectory())t.output||(t.output=s.join(t.input,"psd2ui")),this.parsePsdDir(t.input,t.output);else{if(!t.output){let e=s.dirname(t.input);t.output=s.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(!o.existsSync(t.input))return console.error(`输入路径不存在: ${t.input}`),!1;if(t["engine-version"]){switch(c[t["engine-version"]]){case c.v249:case c.v342:break;default:return console.log(`暂未实现该引擎版本 ${t["engine-version"]}`),!1}}return!0}parsePsdDir(t,e){return d(this,void 0,void 0,(function*(){let i=X.filterFile(t,(t=>".psd"==s.extname(t)));for(let t=0;t=c.v342&&255!==t.opacity){let e=new yt;e._opacity=t.opacity,e.updateWithLayer(t),r.addComponent(e)}let n=new lt(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 rt&&(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 B(t.anchorPoint.x,t.anchorPoint.y),V.editorVersion>=c.v342){r._lpos=new pt(t.position.x,t.position.y+a,0),r._lrot=new pt(0,0,0),r._lscale=new pt(t.scale.x,t.scale.y,t.scale.z),r._euler=new pt;let e=new mt;e._contentSize=n,e._anchorPoint=r._anchorPoint,e.updateWithLayer(t),r.addComponent(e)}if(t instanceof et)for(let i=0;i{let r=J.getSerialNumberImage(e),n=Y.get(r.md5);if(!this.isForceImg&&(null==n?void 0:n.isOutput))return void console.log(`已有相同资源,不再导出 [${e.imgName}] md5: ${e.md5}`);console.log(`保存图片 [${r.imgName}] md5: ${r.md5}`),n&&(n.isOutput=!0);let a=s.join(t,`${r.imgName}.png`);o.writeFileSync(a,r.imgBuffer),this.saveImageMeta(r,a)}))}saveImageMeta(t,e){let i=J.getSerialNumberImage(t),s=Y.get(i.md5);s||(s=i);let r=this.spriteFrameMetaContent.replace(/\$SPRITE_FRAME_UUID/g,s.uuid);r=r.replace(/\$TEXTURE_UUID/g,s.textureUuid),r=r.replace(/\$FILE_NAME/g,i.imgName),r=r.replace(/\$WIDTH/g,i.textureSize.width),r=r.replace(/\$HEIGHT/g,i.textureSize.height);let n=i.s9||{b:0,t:0,l:0,r:0};r=r.replace(/\$BORDER_TOP/g,n.t),r=r.replace(/\$BORDER_BOTTOM/g,n.b),r=r.replace(/\$BORDER_LEFT/g,n.l),r=r.replace(/\$BORDER_RIGHT/g,n.r),o.writeFileSync(e+".meta",r)}savePrefab(t,e){let i=s.join(e,`${t.name}.prefab`);o.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);o.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}}}};bt.length?wt.exec(xt):wt.test()})); +!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){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 c,p=l(i);function h(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 d(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"}(c||(c={}));let u=(t,e)=>{t.__unserialization||(t.__unserialization=[]),t.__unserialization.push(e)};function _(t){return e=>{Object.defineProperty(e.prototype,"$__type__",{value:t,enumerable:!0})}}let v={},g={},f={},y=0;function m(t){return void 0!==t.constructor.__ver_tag_id__&&f[t.constructor.__ver_tag_id__]==t||(t.constructor.__ver_tag_id__=`${y}`,f[t.constructor.__ver_tag_id__]=t,y++),t.constructor.__ver_tag_id__}function b(t,e){for(const i in e)if(Object.prototype.hasOwnProperty.call(e,i)){if(i in t)continue;t[i]=e[i]}}function x(t,...e){for(let i=0;i{let o=e.constructor.name;o=m(e),!g[o]&&(g[o]={});let s=g[o];if(s[i]||(s[i]={}),c.all===t)for(const t in c)s[i][c[t]]=!0;else s[i][c[t]]=!0;var r=S(e.constructor);if(r){let t=m(r.prototype);!v[o]&&(v[o]=t);for(var n=S(r);n;){let e=m(n.prototype);!v[t]&&(v[t]=e),n=S(n)}for(;t;)t in g&&x(s,g[t]),t=v[t]}e._version||(e._version={}),e._version[o]=g[o]=s}}function S(t){var e=t.prototype,i=e&&Object.getPrototypeOf(e);return i&&i.constructor}const M="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",F=new Array(123);for(let t=0;t<123;++t)F[t]=64;for(let t=0;t<64;++t)F[M.charCodeAt(t)]=t;const P=F,I="0123456789abcdef".split(""),$=["","","",""],j=$.concat($,"-",$,"-",$,"-",$,"-",$,$,$),C=j.map(((t,e)=>"-"===t?NaN:e)).filter(isFinite);let N={};for(let t=0;t>2],j[C[i++]]=I[(3&o)<<2|s>>4],j[C[i++]]=I[15&s]}return t.replace(e,j.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=N[String.fromCharCode(o.charCodeAt(t))],r=N[String.fromCharCode(o.charCodeAt(t+1))],n=N[String.fromCharCode(o.charCodeAt(t+2))];i[e++]=M[(s<<2)+(r>>2)],i[e++]=M[((3&r)<<4)+n]}return t.replace(e,i.join(""))}isNumber(t){return!isNaN(parseFloat(t))&&isFinite(t)}};class O{constructor(){this.uuid="",this.idx=0,this.uuid=z.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][c[V.editorVersion]])continue;const s=this[i];e[i]=s}return e}}h([u],O.prototype,"uuid",void 0),h([u],O.prototype,"idx",void 0);class A extends O{constructor(){super(),this._name="",this._objFlags=0,this.__type__=this.$__type__}}h([w(c.all)],A.prototype,"__type__",void 0),h([w(c.all)],A.prototype,"_name",void 0),h([w(c.all)],A.prototype,"_objFlags",void 0);class T extends A{constructor(){super(...arguments),this._enabled=!0,this.node=null,this._id="",this.__prefab=null}}h([w(c.all)],T.prototype,"_enabled",void 0),h([w(c.all)],T.prototype,"node",void 0),h([w(c.all)],T.prototype,"_id",void 0),h([w(c.v342)],T.prototype,"__prefab",void 0);let E=class extends T{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){}};h([w(c.v249)],E.prototype,"duration",void 0),h([w(c.v249)],E.prototype,"zoomScale",void 0),h([w(c.all)],E.prototype,"clickEvents",void 0),h([w(c.v249)],E.prototype,"_N$interactable",void 0),h([w(c.v249)],E.prototype,"_N$enableAutoGrayEffect",void 0),h([w(c.v249)],E.prototype,"_N$transition",void 0),h([w(c.v249)],E.prototype,"transition",void 0),h([w(c.v249)],E.prototype,"_N$target",void 0),h([w(c.v342)],E.prototype,"_interactable",void 0),h([w(c.v342)],E.prototype,"_transition",void 0),h([w(c.v342)],E.prototype,"_duration",void 0),h([w(c.v342)],E.prototype,"_zoomScale",void 0),h([w(c.v342)],E.prototype,"_target",void 0),E=h([_("cc.Button")],E);class k{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 D extends k{constructor(){super(...arguments),this.__type__="cc.Color"}}class L{constructor(t=0,e=0){this.x=t||0,this.y=e||0}}let B=class extends L{constructor(){super(...arguments),this.__type__="cc.Vec2"}};B=h([_("cc.Vec2")],B);let R=class extends T{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 B,this._fillStart=0,this._fillRange=0,this._isTrimmedMode=!0,this._atlas=null,this._visFlags=0,this._customMaterial=null,this._color=new D(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),V.editorVersion>=c.v342&&(this._srcBlendFactor=2,this._dstBlendFactor=4)}setSpriteFrame(t){V.editorVersion>=c.v342?this._spriteFrame={__uuid__:`${t}@f9941`,__expectedType__:"cc.SpriteFrame"}:this._spriteFrame={__uuid__:t}}};h([w(c.v249)],R.prototype,"_materials",void 0),h([w(c.all)],R.prototype,"_srcBlendFactor",void 0),h([w(c.all)],R.prototype,"_dstBlendFactor",void 0),h([w(c.all)],R.prototype,"_spriteFrame",void 0),h([w(c.all)],R.prototype,"_type",void 0),h([w(c.all)],R.prototype,"_sizeMode",void 0),h([w(c.all)],R.prototype,"_fillType",void 0),h([w(c.all)],R.prototype,"_fillCenter",void 0),h([w(c.all)],R.prototype,"_fillStart",void 0),h([w(c.all)],R.prototype,"_fillRange",void 0),h([w(c.all)],R.prototype,"_isTrimmedMode",void 0),h([w(c.all)],R.prototype,"_atlas",void 0),h([w(c.v342)],R.prototype,"_visFlags",void 0),h([w(c.v342)],R.prototype,"_customMaterial",void 0),h([w(c.v342)],R.prototype,"_color",void 0),h([w(c.v342)],R.prototype,"_useGrayscale",void 0),R=h([_("cc.Sprite")],R);let U=class extends T{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 只能作用在 组图层 上")}};h([w(c.v249)],U.prototype,"_N$totalLength",void 0),h([w(c.v249)],U.prototype,"_N$barSprite",void 0),h([w(c.v249)],U.prototype,"_N$mode",void 0),h([w(c.v249)],U.prototype,"_N$progress",void 0),h([w(c.v249)],U.prototype,"_N$reverse",void 0),h([w(c.v342)],U.prototype,"_barSprite",void 0),h([w(c.v342)],U.prototype,"_mode",void 0),h([w(c.v342)],U.prototype,"_totalLength",void 0),h([w(c.v342)],U.prototype,"_progress",void 0),h([w(c.v342)],U.prototype,"_reverse",void 0),U=h([_("cc.ProgressBar")],U);let W=class extends E{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 只能作用在 组图层 上")}};h([w(c.v249)],W.prototype,"_N$isChecked",void 0),h([w(c.v249)],W.prototype,"toggleGroup",void 0),h([w(c.v249)],W.prototype,"checkMark",void 0),h([w(c.all)],W.prototype,"checkEvents",void 0),h([w(c.v342)],W.prototype,"_isChecked",void 0),h([w(c.v342)],W.prototype,"_checkMark",void 0),W=h([_("cc.Toggle")],W);const V=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=c.v249,this.DEFAULT_SPRITE_FRAME_MATERIAL={[c.v249]:"eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432",[c.v342]:""},this.DEFAULT_LABEL_MATERIAL={[c.v249]:"eca5d2f2-8ef6-41c2-bbe6-f9c79d09c432",[c.v342]:""},this.CompMappings={Btn:E,ProgressBar:U,Toggle:W},this.textOffsetY={default:0,36:0},this.textLineHeightOffset=0}get SpriteFrame_Material(){return this.DEFAULT_SPRITE_FRAME_MATERIAL[V.editorVersion]}get Label_Material(){return this.DEFAULT_LABEL_MATERIAL[V.editorVersion]}};let X=new class{DFS(t,e,i=0){if(!o.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);let r=o.readdirSync(t),n=i;i++,r.forEach((r=>{let a=s.join(t,r),l=o.lstatSync(a).isDirectory();null==e||e({isDirectory:l,fullPath:a,fileName:r,depth:n}),l&&this.DFS(a,e,i)}))}filterFile(t,e){if(!o.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);var i=[];return o.readdirSync(t).forEach((r=>{let n=s.join(t,r),a=o.lstatSync(n).isDirectory();if(!a){if(!e(r))return}a?i=i.concat(this.filterFile(n,e)):i.push(n)})),i}getFolderFiles(t,e){if(!o.existsSync(t))return void console.log(`FileUtils-> ${t} is not exists`);let i=[];return o.readdirSync(t).forEach((r=>{let n=s.join(t,r);o.lstatSync(n).isDirectory()?"folder"===e&&i.push({fullPath:n,basename:r}):"file"===e&&i.push({fullPath:n,basename:r})})),i}writeFile(t,e){return d(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=s.dirname(t);yield o.mkdirp(i),yield o.writeFile(t,e),console.log(`写入完成 ${t} `)}))}getMD5(t){return"string"==typeof t&&(t=o.readFileSync(t)),r.createHash("md5").update(t).digest("hex")}};class G{constructor(){this._imageMap=new Map,this._cachePath=null}initWithPath(t){if(!o.existsSync(t))return void console.log(`ImageCacheMgr-> 文件不存在: ${t}`);this._cachePath=t;let e=o.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 d(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 X.writeFile(t,i)}))}loadImages(t){if(this._imageMap.size>0)return void console.error("ImageCacheMgr-> 暂时只能在 启动时加载");let e=X.filterFile(t,(t=>".png"==s.extname(t)));if(e)for(let t=0;t缓存 ",i);let s=this._loadImageMetaWarp(`${i}.meta`);s&&this.set(o,s)}}_loadImageMetaWarp(t){let e=o.readFileSync(t,{encoding:"utf-8"}),i=null;switch(V.editorVersion){case c.v249:i=this._loadImageMeta249(e,t);break;case c.v342:i=this._loadImageMeta34x(e,t);break;default:console.log(`ImageCacheMgr-> 暂未实现 ${c[V.editorVersion]} 版本`)}return i}_loadImageMeta249(t,e){var i;let o=s.basename(e,".png.meta"),r=s.join(s.dirname(e),`${o}.png`),n=JSON.parse(t);return(null===(i=null==n?void 0:n.subMetas)||void 0===i?void 0:i[o])?{path:r,textureUuid:n.subMetas[o].uuid,uuid:n.uuid,isOutput:!0}:null}_loadImageMeta34x(t,e){var i;let o=s.basename(e,".png.meta"),r=s.join(s.dirname(e),`${o}.png`),n=JSON.parse(t);if(!(null===(i=null==n?void 0:n.subMetas)||void 0===i?void 0:i["6c48a"]))return null;let a=n.subMetas["6c48a"].uuid.replace("@6c48a","");return{path:r,textureUuid:a,uuid:a,isOutput:!0}}static getInstance(){return this._instance||(this._instance=new G),this._instance}}G._instance=null;const Y=G.getInstance();class H{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 H),this._instance}}H._instance=null;const J=H.getInstance();var q;!function(t){t[t.Doc=0]="Doc",t[t.Group=1]="Group",t[t.Text=2]="Text",t[t.Image=3]="Image"}(q||(q={}));class K{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 Q{constructor(t=0,e=0){this.width=t||0,this.height=e||0}}class Z{constructor(t=0,e=0,i=0){this.x=t||0,this.y=e||0,this.z=i||0}}class tt{constructor(t,e,i){var o,s,r,n;this.uuid=z.uuid(),this.source=t,this.parent=e,this.rootDoc=i,this.name=t.name,this.position=new L,this.size=new Q,this.rect=new K(t),this.anchorPoint=new L(.5,.5),this.hidden=!1,this.opacity=255,this.color=new k(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 Z(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${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]]=z.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||!tt.isPinyin)return t;if(!new RegExp("[\\u4E00-\\u9FFF]+","g").test(t))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}}tt.isPinyin=!1;class et extends tt{constructor(t,e,i){super(t,e,i),this.children=[],i&&(this.rect=new K(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;si+4)return console.log("Texture9Utils-> 设置的九宫格 left, right 数据不合理,请重新设置"),t;if(e.b+e.t>o+4)return console.log("Texture9Utils-> 设置的九宫格 bottom, top 数据不合理,请重新设置"),t;let c=a.createCanvas(Math.min(i,e.l+e.r+4)||i,Math.min(o,e.b+e.t+4)||o),p=c.getContext("2d");return p.drawImage(t,0,0,s+4,n+4,0,0,s+4,n+4),p.drawImage(t,0,o-l,s+4,l,0,n+4,s+4,l),p.drawImage(t,i-s,0,r,n+4,s+4,0,r,n+4),p.drawImage(t,i-s,o-l,r,l,s+4,n+4,r,l),c}}class st extends tt{constructor(t,e,i){var o;if(super(t,e,i),this.textureUuid=z.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=ot.safeBorder(this.source.canvas,t);let e=ot.split(this.source.canvas,t);this.source.canvas=e}let s=this.source.canvas;this.imgBuffer=s.toBuffer("image/png"),this.md5=X.getMD5(this.imgBuffer),this.textureSize=new Q(s.width,s.height),this.scale=new Z((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 rt extends tt{parseSource(){super.parseSource();let t=this.source.text,e=t.style;if(e){let t=e.fillColor;t&&(this.color=new k(t.r,t.g,t.b,255*t.a))}return this.text=t.text,this.fontSize=e.fontSize,this.offsetY=V.textOffsetY[this.fontSize]||V.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 k(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 空图层 ${null==t?void 0:t.name}`),null;let s=o=new st(t,e,i);J.add(s),s.isIgnore()||s.isBind()||Y.has(s.md5)||Y.set(s.md5,{uuid:s.uuid,textureUuid:s.textureUuid})}break;case q.Text:o=new rt(t,e,i)}return o.layerType=s,o.parseSource(),o.onCtor(),o}};class at extends O{constructor(){super(),this.__type__="cc.CompPrefabInfo",this.fileId="",this.fileId=z.compressUuid(this.uuid)}}let lt=class extends Q{constructor(){super(...arguments),this.__type__="cc.Size"}};lt=h([_("cc.Size")],lt);let ct=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}};ct=h([_("TypedArray")],ct);class pt extends Z{constructor(){super(...arguments),this.__type__="cc.Vec3"}}let ht=class extends A{constructor(t){super(),this._parent=null,this._children=[],this._active=!0,this._components=[],this._prefab=null,this._id="",this._opacity=255,this._color=new D(255,255,255,255),this._contentSize=new lt,this._anchorPoint=new B(0,0),this._trs=new ct,this._eulerAngles=new pt,this._skewX=0,this._skewY=0,this._is3DNode=!1,this._groupIndex=0,this.groupIndex=0,this._renderEnable=!1,this._bfsRenderFlag=!1,this._lpos=new pt,this._lrot=new pt,this._lscale=new pt,this._euler=new pt,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),V.editorVersion>=c.v342&&this.addCompPrefabInfo(t)}addCompPrefabInfo(t){let e=new at,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)}};h([w(c.all)],ht.prototype,"_parent",void 0),h([w(c.all)],ht.prototype,"_children",void 0),h([w(c.all)],ht.prototype,"_active",void 0),h([w(c.all)],ht.prototype,"_components",void 0),h([w(c.all)],ht.prototype,"_prefab",void 0),h([w(c.all)],ht.prototype,"_id",void 0),h([w(c.v249)],ht.prototype,"_opacity",void 0),h([w(c.v249)],ht.prototype,"_color",void 0),h([w(c.v249)],ht.prototype,"_contentSize",void 0),h([w(c.v249)],ht.prototype,"_anchorPoint",void 0),h([w(c.v249)],ht.prototype,"_trs",void 0),h([w(c.v249)],ht.prototype,"_eulerAngles",void 0),h([w(c.v249)],ht.prototype,"_skewX",void 0),h([w(c.v249)],ht.prototype,"_skewY",void 0),h([w(c.v249)],ht.prototype,"_is3DNode",void 0),h([w(c.v249)],ht.prototype,"_groupIndex",void 0),h([w(c.v249)],ht.prototype,"groupIndex",void 0),h([w(c.v249)],ht.prototype,"_renderEnable",void 0),h([w(c.v249)],ht.prototype,"_bfsRenderFlag",void 0),h([w(c.v342)],ht.prototype,"_lpos",void 0),h([w(c.v342)],ht.prototype,"_lrot",void 0),h([w(c.v342)],ht.prototype,"_lscale",void 0),h([w(c.v342)],ht.prototype,"_euler",void 0),h([w(c.v342)],ht.prototype,"_layer",void 0),h([u],ht.prototype,"psdDoc",void 0),h([u],ht.prototype,"components",void 0),h([u],ht.prototype,"children",void 0),ht=h([_("cc.Node")],ht);class dt extends O{constructor(){super(),this.__type__="cc.PrefabInfo",this.root={__id__:1},this.asset={__id__:0},this.fileId="",this.sync=!1,this.fileId=z.compressUuid(this.uuid)}}h([w(c.all)],dt.prototype,"__type__",void 0),h([w(c.all)],dt.prototype,"root",void 0),h([w(c.all)],dt.prototype,"asset",void 0),h([w(c.all)],dt.prototype,"fileId",void 0),h([w(c.all)],dt.prototype,"sync",void 0);let ut=class extends A{constructor(){super(...arguments),this._native="",this.data=null,this.optimizationPolicy=0,this.asyncLoadAssets=!1,this.readonly=!1,this.persistent=!1}};h([w(c.all)],ut.prototype,"_native",void 0),h([w(c.all)],ut.prototype,"data",void 0),h([w(c.all)],ut.prototype,"optimizationPolicy",void 0),h([w(c.all)],ut.prototype,"asyncLoadAssets",void 0),h([w(c.v249)],ut.prototype,"readonly",void 0),h([w(c.v342)],ut.prototype,"persistent",void 0),ut=h([_("cc.Prefab")],ut);let _t=class extends T{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 D(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+V.textLineHeightOffset,V.editorVersion>=c.v342&&(this._srcBlendFactor=2,this._dstBlendFactor=4)}};h([w(c.all)],_t.prototype,"_srcBlendFactor",void 0),h([w(c.all)],_t.prototype,"_dstBlendFactor",void 0),h([w(c.all)],_t.prototype,"_string",void 0),h([w(c.all)],_t.prototype,"_fontSize",void 0),h([w(c.all)],_t.prototype,"_lineHeight",void 0),h([w(c.all)],_t.prototype,"_enableWrapText",void 0),h([w(c.all)],_t.prototype,"_isSystemFontUsed",void 0),h([w(c.all)],_t.prototype,"_spacingX",void 0),h([w(c.all)],_t.prototype,"_underlineHeight",void 0),h([w(c.v249)],_t.prototype,"_materials",void 0),h([w(c.v249)],_t.prototype,"_N$string",void 0),h([w(c.v249)],_t.prototype,"_N$file",void 0),h([w(c.v249)],_t.prototype,"_batchAsBitmap",void 0),h([w(c.v249)],_t.prototype,"_styleFlags",void 0),h([w(c.v249)],_t.prototype,"_N$horizontalAlign",void 0),h([w(c.v249)],_t.prototype,"_N$verticalAlign",void 0),h([w(c.v249)],_t.prototype,"_N$fontFamily",void 0),h([w(c.v249)],_t.prototype,"_N$overflow",void 0),h([w(c.v249)],_t.prototype,"_N$cacheMode",void 0),h([w(c.v342)],_t.prototype,"_visFlags",void 0),h([w(c.v342)],_t.prototype,"_customMaterial",void 0),h([w(c.v342)],_t.prototype,"_color",void 0),h([w(c.v342)],_t.prototype,"_overflow",void 0),h([w(c.v342)],_t.prototype,"_cacheMode",void 0),h([w(c.v342)],_t.prototype,"_horizontalAlign",void 0),h([w(c.v342)],_t.prototype,"_verticalAlign",void 0),h([w(c.v342)],_t.prototype,"_actualFontSize",void 0),h([w(c.v342)],_t.prototype,"_isItalic",void 0),h([w(c.v342)],_t.prototype,"_isBold",void 0),h([w(c.v342)],_t.prototype,"_isUnderline",void 0),_t=h([_("cc.Label")],_t);let vt=class extends T{constructor(){super(...arguments),this._color=new D(255,255,255,255),this._width=1}updateWithLayer(t){this._width=t.outline.width,this._color.set(t.outline.color)}};h([w(c.all)],vt.prototype,"_color",void 0),h([w(c.all)],vt.prototype,"_width",void 0),vt=h([_("cc.LabelOutline")],vt);class gt{constructor(){this.textObjects=[]}test(){const t=s.join(__dirname,"..","out");this.parsePsd("./test-img-only/境界奖励-优化.psd",t)}exec(t){return d(this,void 0,void 0,(function*(){if(!this.checkArgs(t))return;if(o.lstatSync(t.input).isDirectory())t.output||(t.output=s.join(t.input,"psd2ui")),this.parsePsdDir(t.input,t.output);else{if(!t.output){let e=s.dirname(t.input);t.output=s.join(e,"psd2ui")}this.parsePsd(t.input,t.output)}}))}checkArgs(t){return t.input?!!o.existsSync(t.input)||(console.error(`输入路径不存在: ${t.input}`),!1):(console.error("请设置 --input"),!1)}parsePsdDir(t,e){return d(this,void 0,void 0,(function*(){o.emptyDirSync(e);let i=X.filterFile(t,(t=>".psd"==s.extname(t)));for(let t=0;t{let n=J.getSerialNumberImage(e),a=`${n.imgName}_${i}`;console.log(`保存图片 [${n.imgName}] 重命名为 [${a}] md5: ${n.md5}`);let l=s.join(t,`${a}.png`);o.writeFileSync(l,n.imgBuffer),i++}))}saveTextFile(t,e){this.scanText(t,t);let i=JSON.stringify(this.textObjects,null,2),r=s.join(e,"text.txt");o.writeFileSync(r,i,{encoding:"utf-8"})}scanText(t,e){if(t instanceof et)for(let i=0;i test")}))}loadMetaTemplete(){return d(this,void 0,void 0,(function*(){this.spriteFrameMetaContent=o.readFileSync(s.join(__dirname,`../assets/cc/meta/CCSpriteFrame.meta.${c[V.editorVersion]}`),"utf-8"),this.prefabMetaContent=o.readFileSync(s.join(__dirname,`../assets/cc/meta/CCPrefab.meta.${c[V.editorVersion]}`),"utf-8")}))}loadPsdConfig(t){return d(this,void 0,void 0,(function*(){if(!o.existsSync(t))return void console.log(`Main-> 配置 ${t} 不存在`);let e=o.readFileSync(t,"utf-8");this.psdConfig=JSON.parse(e);for(const t in this.psdConfig)t in V&&("object"==typeof this.psdConfig[t]?V[t]=Object.assign({},V[t],this.psdConfig[t]):V[t]=this.psdConfig[t]||V[t])}))}exec(t){return d(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",V.help),!1;if(t["img-only"])return ft.exec(t),!0;let e=()=>d(this,void 0,void 0,(function*(){t.cache&&(o.mkdirsSync(s.dirname(t.cache)),yield Y.saveImageMap(t.cache))}));if(t["engine-version"]&&(V.editorVersion=c[t["engine-version"]]),console.log(`Main-> 数据版本 ${c[V.editorVersion]}`),!t.init||t["project-assets"]&&t.cache){if(t.cache&&!o.existsSync(t.cache)&&e(),t["project-assets"]&&(t["cache-remake"]||t.init)&&(yield Y.loadImages(t["project-assets"]),e(),t.init))console.log("psd2ui 缓存完成");else if(this.checkArgs(t)){if(t.cache&&(yield Y.initWithPath(t.cache)),yield this.loadMetaTemplete(),t.config&&(yield this.loadPsdConfig(t.config)),this.isForceImg=!!t["force-img"],tt.isPinyin=t.pinyin,o.lstatSync(t.input).isDirectory())t.output||(t.output=s.join(t.input,"psd2ui")),this.parsePsdDir(t.input,t.output);else{if(!t.output){let e=s.dirname(t.input);t.output=s.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(!o.existsSync(t.input))return console.error(`输入路径不存在: ${t.input}`),!1;if(t["engine-version"]){switch(c[t["engine-version"]]){case c.v249:case c.v342:break;default:return console.log(`暂未实现该引擎版本 ${t["engine-version"]}`),!1}}return!0}parsePsdDir(t,e){return d(this,void 0,void 0,(function*(){let i=X.filterFile(t,(t=>".psd"==s.extname(t)));for(let t=0;t=c.v342&&255!==t.opacity){let e=new yt;e._opacity=t.opacity,e.updateWithLayer(t),r.addComponent(e)}let n=new lt(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 rt&&(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 B(t.anchorPoint.x,t.anchorPoint.y),V.editorVersion>=c.v342){r._lpos=new pt(t.position.x,t.position.y+a,0),r._lrot=new pt(0,0,0),r._lscale=new pt(t.scale.x,t.scale.y,t.scale.z),r._euler=new pt;let e=new mt;e._contentSize=n,e._anchorPoint=r._anchorPoint,e.updateWithLayer(t),r.addComponent(e)}if(t instanceof et)for(let i=0;i{let r=J.getSerialNumberImage(e),n=Y.get(r.md5);if(!this.isForceImg&&(null==n?void 0:n.isOutput))return void console.log(`已有相同资源,不再导出 [${e.imgName}] md5: ${e.md5}`);console.log(`保存图片 [${r.imgName}] md5: ${r.md5}`),n&&(n.isOutput=!0);let a=s.join(t,`${r.imgName}.png`);o.writeFileSync(a,r.imgBuffer),this.saveImageMeta(r,a)}))}saveImageMeta(t,e){let i=J.getSerialNumberImage(t),s=Y.get(i.md5);s||(s=i);let r=this.spriteFrameMetaContent.replace(/\$SPRITE_FRAME_UUID/g,s.uuid);r=r.replace(/\$TEXTURE_UUID/g,s.textureUuid),r=r.replace(/\$FILE_NAME/g,i.imgName),r=r.replace(/\$WIDTH/g,i.textureSize.width),r=r.replace(/\$HEIGHT/g,i.textureSize.height);let n=i.s9||{b:0,t:0,l:0,r:0};r=r.replace(/\$BORDER_TOP/g,n.t),r=r.replace(/\$BORDER_BOTTOM/g,n.b),r=r.replace(/\$BORDER_LEFT/g,n.l),r=r.replace(/\$BORDER_RIGHT/g,n.r),o.writeFileSync(e+".meta",r)}savePrefab(t,e){let i=s.join(e,`${t.name}.prefab`);o.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);o.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}}}};bt.length?wt.exec(xt):wt.test()})); diff --git a/psd2ui-tools/src/psd/PsdLayer.ts b/psd2ui-tools/src/psd/PsdLayer.ts index 263b4fc..33e35ed 100644 --- a/psd2ui-tools/src/psd/PsdLayer.ts +++ b/psd2ui-tools/src/psd/PsdLayer.ts @@ -245,6 +245,12 @@ export abstract class PsdLayer { if (!text || !PsdLayer.isPinyin) { return text; } + + let reg = new RegExp("[\\u4E00-\\u9FFF]+", "g"); + if (!reg.test(text)) { + return text; + } + let names = pinyin(text, { toneType: "none", type: "array"