From 12975ba1a8f64401a89ad1b951a32485c18fea3e Mon Sep 17 00:00:00 2001 From: onvia <272493431@qq.com> Date: Fri, 15 Sep 2023 09:50:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A7=BB=E9=99=A4=E8=A7=84?= =?UTF-8?q?=E5=88=99=E6=A0=87=E8=AE=B0=E6=9C=AB=E5=B0=BE=E7=9A=84=E4=B8=AD?= =?UTF-8?q?=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- psd2ui-tools/dist/index.js | 15 ++++++++++++--- psd2ui-tools/src/psd/PsdLayer.ts | 18 +++++++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 6292e95..29601a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ccc-tnt-psd2ui", - "version": "1.0.1", + "version": "1.0.2", "description": "", "main": "index.js", "scripts": { diff --git a/psd2ui-tools/dist/index.js b/psd2ui-tools/dist/index.js index ddfc7ff..5e47352 100644 --- a/psd2ui-tools/dist/index.js +++ b/psd2ui-tools/dist/index.js @@ -1166,7 +1166,7 @@ this.scale = new Vec3(1, 1, 1); } parseNameRule(name) { - var _a, _b; + var _a, _b, _c; if (!name) { return; } @@ -1177,11 +1177,11 @@ return; } let obj = { - name: (_b = (_a = fragments[0]) === null || _a === void 0 ? void 0 : _a.replace(/\.|>|\/|\ /g, "_")) !== null && _b !== void 0 ? _b : "unknow", + name: (_c = (_b = (_a = fragments[0]) === null || _a === void 0 ? void 0 : _a.trim()) === null || _b === void 0 ? void 0 : _b.replace(/\.|>|\/|\ /g, "_")) !== null && _c !== void 0 ? _c : "unknow", comps: {}, }; for (let i = 1; i < fragments.length; i++) { - const fragment = fragments[i].trim(); + const fragment = this.removeChineseFromEnd(fragments[i].trim()).trim(); // 删除规则尾部的中文 let attr = {}; let startIdx = fragment.indexOf("{"); let comp = fragment; @@ -1255,6 +1255,15 @@ // } return obj; } + removeChineseFromEnd(inputString) { + const chineseRegex = /[\u4e00-\u9fa5]+$/; + const match = inputString.match(chineseRegex); + if (match && match[0]) { + const chineseLength = match[0].length; + return inputString.slice(0, -chineseLength); + } + return inputString; + } /** 解析数据 */ parseSource() { var _a, _b; diff --git a/psd2ui-tools/src/psd/PsdLayer.ts b/psd2ui-tools/src/psd/PsdLayer.ts index 486c8c0..8b2560e 100644 --- a/psd2ui-tools/src/psd/PsdLayer.ts +++ b/psd2ui-tools/src/psd/PsdLayer.ts @@ -112,11 +112,13 @@ export abstract class PsdLayer { return; } let obj: PsdAttr = { - name: fragments[0]?.replace(/\.|>|\/|\ /g, "_") ?? "unknow", + name: fragments[0]?.trim()?.replace(/\.|>|\/|\ /g, "_") ?? "unknow", comps: {}, } for (let i = 1; i < fragments.length; i++) { - const fragment = fragments[i].trim(); + const fragment = this.removeChineseFromEnd(fragments[i].trim()).trim(); // 删除规则尾部的中文 + + let attr = {}; let startIdx = fragment.indexOf("{"); let comp = fragment; @@ -203,7 +205,17 @@ export abstract class PsdLayer { return obj; } - + removeChineseFromEnd(inputString: string): string { + const chineseRegex = /[\u4e00-\u9fa5]+$/; + const match = inputString.match(chineseRegex); + + if (match && match[0]) { + const chineseLength = match[0].length; + return inputString.slice(0, -chineseLength); + } + + return inputString; + } /** 解析数据 */ parseSource() { let _source = this.source;