mirror of
https://gitee.com/onvia/ccc-tnt-psd2ui
synced 2024-12-26 19:58:25 +00:00
2 lines
40 KiB
JavaScript
2 lines
40 KiB
JavaScript
!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<e.length;i++)b(t,e[i])}function w(t){return(e,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<I.length;t++){let e=I[t];N[e]=t}const z=new class{uuid(){var t=(new Date).getTime();return globalThis.performance&&"function"==typeof globalThis.performance.now&&(t+=performance.now()),"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var i=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?i:3&i|8).toString(16)}))}decodeUuid(t){const e=t.split("@")[0];if(22!==e.length)return t;j[0]=t[0],j[1]=t[1];for(let e=2,i=2;e<22;e+=2){const o=P[t.charCodeAt(e)],s=P[t.charCodeAt(e+1)];j[C[i++]]=I[o>>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<t.children.length;e++){const i=t.children[e];if(i.attr.comps.bar){let t=i.uiObject;this._totalLength=this._N$totalLength=t._contentSize.width;for(let e=0;e<t.components.length;e++){const i=t.components[e];if(i instanceof R){this.setBar(i);break t}}}}else console.error("CCProgressBar-> 只能作用在 组图层 上")}};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<t.children.length;e++){const i=t.children[e];if(i.attr.comps.check){let t=i.uiObject;for(let e=0;e<t.components.length;e++){const i=t.components[e];if(i instanceof R){this.setCheckMark(i);break t}}}}else console.error("CCToggle-> 只能作用在 组图层 上")}};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<e.length;t++){const i=e[t];let o=X.getMD5(i);console.log("ImageCacheMgr->缓存 ",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<o.length;e++){const i=o[e].trim();let r={},n=i.indexOf("{"),a=i;if(-1!=n){let e=i.indexOf("}");if(-1==e){console.log(`PsdLayer->${t} 属性 解析错误`);continue}let o=i.substring(n+1,e);a=i.substr(0,n),o=o.trim(),o.split(",").forEach((e=>{let i=(e=e.trim()).split(":");i.length?(i.map((t=>t.trim())),r[i[0]]=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;s<this.children.length;s++){let r=this.children[s].rect;t=Math.min(r.left,t),e=Math.max(r.right,e),i=Math.min(r.top,i),o=Math.max(r.bottom,o)}this.rect.left=t,this.rect.right=e,this.rect.top=i,this.rect.bottom=o}onCtor(){}}class it extends et{constructor(t){super(t,null,null),this.images=new Map,this.objectMap=new Map,this.objectArray=[],this.size=new Q(t.width,t.height),this.rect=new K(0,this.size.width,0,this.size.height)}pushObject(t){let e=this.objectArray.length;return t.idx=e,this.objectMap.set(t.uuid,e),this.objectArray.push(t),e}getObjectIdx(t){return this.objectMap.get(t)}getObject(t){let e=this.objectMap.get(t);return e<this.objectArray.length?this.objectArray[e]:null}onCtor(){super.onCtor()}}class ot{static safeBorder(t,e){var i,o,s,r;return e.l=(null!==(i=e.l)&&void 0!==i?i:e.r)||0,e.r=(null!==(o=e.r)&&void 0!==o?o:e.l)||0,e.t=(null!==(s=e.t)&&void 0!==s?s:e.b)||0,e.b=(null!==(r=e.b)&&void 0!==r?r:e.t)||0,e}static split(t,e){this.safeBorder(t,e);let i=t.width,o=t.height,s=e.l||i,r=e.r||i,n=e.t||o,l=e.b||o;if(0==e.b&&0==e.t&&0==e.l&&0==e.r)return t;if(e.l+e.r>i+4)return console.log("Texture9Utils-> 设置的九宫格 left, right 数据不合理,请重新设置"),t;if(e.b+e.t>o+4)return console.log("Texture9Utils-> 设置的九宫格 bottom, top 数据不合理,请重新设置"),t;let 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<t.length;e++){const i=t[e];if(i.enabled){let t=i.color;this.color=new k(t.r,t.g,t.b,255*i.opacity)}}}}}const nt=new class{parseLayerType(t){return"children"in t?"width"in t&&"height"in t?q.Doc:q.Group:"text"in t?q.Text:q.Image}parseLayer(t,e,i){let o=null,s=this.parseLayerType(t);switch(s){case q.Doc:case q.Group:{let r=null;if(s==q.Group){if(r=new et(t,e,i),r.attr.comps.ignorenode||r.attr.comps.ignore)return null}else r=new it(t);for(let e=0;e<t.children.length;e++){const o=t.children[e];let s=this.parseLayer(o,r,i||r);s?s.attr.comps.ignorenode||s.attr.comps.ignore||r.children.push(s):console.error("图层解析错误")}o=r}break;case q.Image:{if(!t.canvas)return console.error(`Parser-> 空图层 ${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<i.length;t++){const o=i[t];yield this.parsePsd(o,e)}}))}parsePsd(t,e){return d(this,void 0,void 0,(function*(){J.clear(),this.textObjects.length=0,console.log("========================================="),console.log(`处理 ${t} 文件`);let i=s.basename(t,".psd"),r=o.readFileSync(t);const n=p.readPsd(r);let a=nt.parseLayer(n);a.name=i;let l=s.join(e,i),c=s.join(l,"textures");o.mkdirsSync(l),o.emptyDirSync(l),o.mkdirsSync(c),yield this.saveImage(c),yield this.saveTextFile(a,l),console.log(`psd2ui ${t} 处理完成`)}))}saveImage(t){let e=J.getAllImage(),i=0;e.forEach(((e,r)=>{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<t.children.length;i++){const o=t.children[i];this.scanText(o,e)}else if(t instanceof rt){let e={text:t.text,fontSize:t.fontSize,color:`#${t.color.toHEX()}`};t.outline&&(e.outlineWidth=t.outline.width,e.outlineColor=`#${t.outline.color.toHEX()}`),this.textObjects.push(e)}}static getInstance(){return this._instance||(this._instance=new gt),this._instance}}gt._instance=null;let ft=gt.getInstance(),yt=class extends T{constructor(){super(...arguments),this._opacity=255}updateWithLayer(t){}};h([w(c.v342)],yt.prototype,"_opacity",void 0),yt=h([_("cc.UIOpacity")],yt);let mt=class extends T{constructor(){super(...arguments),this._contentSize=new lt,this._anchorPoint=new B(0,0)}updateWithLayer(t){}};h([w(c.v342)],mt.prototype,"_contentSize",void 0),h([w(c.v342)],mt.prototype,"_anchorPoint",void 0),mt=h([_("cc.UITransform")],mt),console.log("当前目录: ",__dirname);const bt=process.argv.slice(2),xt=t(bt);let wt=new class{constructor(){this.spriteFrameMetaContent="",this.prefabMetaContent="",this.psdConfig=null,this.isForceImg=!1}test(){return d(this,void 0,void 0,(function*(){console.log("Main-> 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<i.length;t++){const o=i[t];yield this.parsePsd(o,e)}}))}parsePsd(t,e){return d(this,void 0,void 0,(function*(){J.clear(),console.log("========================================="),console.log(`处理 ${t} 文件`);let i=s.basename(t,".psd"),r=o.readFileSync(t);const n=p.readPsd(r);let a=nt.parseLayer(n);a.name=i;let l=s.join(e,i),c=s.join(l,"textures");o.mkdirsSync(l),o.mkdirsSync(c),yield this.saveImage(c),yield this.buildPrefab(a),yield this.savePrefab(a,l),console.log(`psd2ui ${t} 处理完成`)}))}buildPrefab(t){let e=new ut;t.pushObject(e);let i=this.createCCNode(t,t);e.data={__id__:i.idx},this.postUIObject(t,t)}createCCNode(t,e){var i,o,s;let r=new ht(e);if(t.uiObject=r,r._name=t.name,r._active=!t.hidden,r._opacity=t.opacity,V.editorVersion>=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<t.children.length;i++){const o=t.children[i];let s=this.createCCNode(o,e);s&&r.addChild(s)}else if(t instanceof st){let e=new R;if(r.addComponent(e),e._materials.push({__uuid__:V.SpriteFrame_Material}),e.updateWithLayer(t),t.isIgnore());else{let i=J.getSerialNumberImage(t),o=Y.get(i.md5);e.setSpriteFrame(o?o.textureUuid:i.textureUuid)}this.applyConfig(e)}else if(t instanceof rt){let e=new _t;if(r.addComponent(e),r._color.set(t.color),e._color.set(t.color),e._materials.push({__uuid__:V.Label_Material}),e.updateWithLayer(t),this.applyConfig(e),t.outline){let e=new vt;r.addComponent(e),e.updateWithLayer(t),this.applyConfig(e)}}if(t.attr)for(const e in t.attr.comps)if(Object.prototype.hasOwnProperty.call(t.attr.comps,e)&&t.attr.comps[e]){let i=V.CompMappings[e];if(i){let e=new i;r.addComponent(e),e.updateWithLayer(t),this.applyConfig(e)}}return this.createPrefabInfo(t,e),r}createPrefabInfo(t,e){let i=t.uiObject,o=new dt,s=e.pushObject(o);i._prefab={__id__:s}}postUIObject(t,e){}saveImage(t){J.getAllImage().forEach(((e,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()}));
|