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;