@mybricks/to-code-taro 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/abstractEventTypeDef.d.ts +11 -0
- package/dist/cjs/abstractEventTypeDef.js +93 -0
- package/dist/cjs/core/comlib/Index.js +45 -0
- package/dist/cjs/core/comlib/_ScanQrcode.js +60 -0
- package/dist/cjs/core/comlib/_SetStorage.js +76 -0
- package/dist/cjs/core/comlib/_ShowToast.js +96 -0
- package/dist/cjs/core/mybricks/MyBricksDescriptor.js +213 -0
- package/dist/cjs/core/mybricks/Subject.js +115 -0
- package/dist/cjs/core/mybricks/constant.js +70 -0
- package/dist/cjs/core/mybricks/context.js +33 -0
- package/dist/cjs/core/mybricks/createEnv.js +39 -0
- package/dist/cjs/core/mybricks/createJSHandle.js +150 -0
- package/dist/cjs/core/mybricks/createModuleEventsHandle.js +49 -0
- package/dist/cjs/core/mybricks/createReactiveInputHandler.js +63 -0
- package/dist/cjs/core/mybricks/event.js +70 -0
- package/dist/cjs/core/mybricks/index.js +871 -0
- package/dist/cjs/core/mybricks/log.js +38 -0
- package/dist/cjs/core/mybricks/utils.js +69 -0
- package/dist/cjs/core/mybricks/variables.js +217 -0
- package/dist/cjs/core/utils/ComContext.js +39 -0
- package/dist/cjs/core/utils/index.js +88 -0
- package/dist/cjs/core/utils/useContext.js +53 -0
- package/dist/cjs/core/utils/with.js +84 -0
- package/dist/cjs/generate/generateTaroProjectJson.d.ts +24 -0
- package/dist/cjs/generate/generateTaroProjectJson.js +101 -0
- package/dist/cjs/generate/generateTaroTempalteJson.d.ts +15 -0
- package/dist/cjs/generate/generateTaroTempalteJson.js +103 -0
- package/dist/cjs/generate/utils/appConfig.d.ts +21 -0
- package/dist/cjs/generate/utils/appConfig.js +47 -0
- package/dist/cjs/generate/utils/commonDir.d.ts +21 -0
- package/dist/cjs/generate/utils/commonDir.js +50 -0
- package/dist/cjs/generate/utils/fileNode.d.ts +17 -0
- package/dist/cjs/generate/utils/fileNode.js +57 -0
- package/dist/cjs/generate/utils/index.d.ts +7 -0
- package/dist/cjs/generate/utils/index.js +29 -0
- package/dist/cjs/generate/utils/tabBarImages.d.ts +14 -0
- package/dist/cjs/generate/utils/tabBarImages.js +36 -0
- package/dist/cjs/handleCom.d.ts +31 -0
- package/dist/cjs/handleCom.js +260 -0
- package/dist/cjs/handleDom.d.ts +19 -0
- package/dist/cjs/handleDom.js +86 -0
- package/dist/cjs/handleExtension.d.ts +10 -0
- package/dist/cjs/handleExtension.js +300 -0
- package/dist/cjs/handleGlobal.d.ts +21 -0
- package/dist/cjs/handleGlobal.js +155 -0
- package/dist/cjs/handleModule.d.ts +15 -0
- package/dist/cjs/handleModule.js +108 -0
- package/dist/cjs/handleSlot.d.ts +27 -0
- package/dist/cjs/handleSlot.js +197 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +44 -0
- package/dist/cjs/taro-template.json +5370 -0
- package/dist/cjs/toCodeTaro.d.ts +130 -0
- package/dist/cjs/toCodeTaro.js +427 -0
- package/dist/cjs/utils/code/component.d.ts +19 -0
- package/dist/cjs/utils/code/component.js +85 -0
- package/dist/cjs/utils/code/index.d.ts +18 -0
- package/dist/cjs/utils/code/index.js +71 -0
- package/dist/cjs/utils/code/renderManager.d.ts +22 -0
- package/dist/cjs/utils/code/renderManager.js +80 -0
- package/dist/cjs/utils/code/scene.d.ts +19 -0
- package/dist/cjs/utils/code/scene.js +82 -0
- package/dist/cjs/utils/convertNamespace.d.ts +11 -0
- package/dist/cjs/utils/convertNamespace.js +43 -0
- package/dist/cjs/utils/genJSModules.d.ts +12 -0
- package/dist/cjs/utils/genJSModules.js +116 -0
- package/dist/cjs/utils/getComponentClassName.d.ts +16 -0
- package/dist/cjs/utils/getComponentClassName.js +47 -0
- package/dist/cjs/utils/handlePageConfig.d.ts +24 -0
- package/dist/cjs/utils/handlePageConfig.js +73 -0
- package/dist/cjs/utils/handleProcess.d.ts +9 -0
- package/dist/cjs/utils/handleProcess.js +370 -0
- package/dist/cjs/utils/index.d.ts +62 -0
- package/dist/cjs/utils/index.js +321 -0
- package/dist/cjs/utils/pageConfig/converter.d.ts +17 -0
- package/dist/cjs/utils/pageConfig/converter.js +83 -0
- package/dist/cjs/utils/pageConfig/index.d.ts +10 -0
- package/dist/cjs/utils/pageConfig/index.js +33 -0
- package/dist/cjs/utils/pageConfig/pageConfig.d.ts +10 -0
- package/dist/cjs/utils/pageConfig/pageConfig.js +87 -0
- package/dist/cjs/utils/pageConfig/saveBase64Image.d.ts +14 -0
- package/dist/cjs/utils/pageConfig/saveBase64Image.js +81 -0
- package/dist/cjs/utils/pageConfig/tabBarConfig.d.ts +13 -0
- package/dist/cjs/utils/pageConfig/tabBarConfig.js +74 -0
- package/dist/cjs/utils/pageConfig/types.d.ts +68 -0
- package/dist/cjs/utils/pageConfig/types.js +17 -0
- package/dist/cjs/utils/pageConfig/validator.d.ts +13 -0
- package/dist/cjs/utils/pageConfig/validator.js +67 -0
- package/dist/cjs/utils/pxtransform.d.ts +28 -0
- package/dist/cjs/utils/pxtransform.js +102 -0
- package/dist/esm/abstractEventTypeDef.d.ts +11 -0
- package/dist/esm/abstractEventTypeDef.js +63 -0
- package/dist/esm/core/comlib/Index.js +3 -0
- package/dist/esm/core/comlib/_ScanQrcode.js +27 -0
- package/dist/esm/core/comlib/_SetStorage.js +52 -0
- package/dist/esm/core/comlib/_ShowToast.js +68 -0
- package/dist/esm/core/mybricks/MyBricksDescriptor.js +232 -0
- package/dist/esm/core/mybricks/Subject.js +143 -0
- package/dist/esm/core/mybricks/constant.js +18 -0
- package/dist/esm/core/mybricks/context.js +5 -0
- package/dist/esm/core/mybricks/createEnv.js +9 -0
- package/dist/esm/core/mybricks/createJSHandle.js +138 -0
- package/dist/esm/core/mybricks/createModuleEventsHandle.js +26 -0
- package/dist/esm/core/mybricks/createReactiveInputHandler.js +40 -0
- package/dist/esm/core/mybricks/event.js +44 -0
- package/dist/esm/core/mybricks/index.js +952 -0
- package/dist/esm/core/mybricks/log.js +12 -0
- package/dist/esm/core/mybricks/utils.js +41 -0
- package/dist/esm/core/mybricks/variables.js +190 -0
- package/dist/esm/core/utils/ComContext.js +10 -0
- package/dist/esm/core/utils/index.js +57 -0
- package/dist/esm/core/utils/useContext.js +24 -0
- package/dist/esm/core/utils/with.js +67 -0
- package/dist/esm/generate/generateTaroProjectJson.d.ts +24 -0
- package/dist/esm/generate/generateTaroProjectJson.js +102 -0
- package/dist/esm/generate/generateTaroTempalteJson.d.ts +15 -0
- package/dist/esm/generate/generateTaroTempalteJson.js +94 -0
- package/dist/esm/generate/utils/appConfig.d.ts +21 -0
- package/dist/esm/generate/utils/appConfig.js +30 -0
- package/dist/esm/generate/utils/commonDir.d.ts +21 -0
- package/dist/esm/generate/utils/commonDir.js +36 -0
- package/dist/esm/generate/utils/fileNode.d.ts +17 -0
- package/dist/esm/generate/utils/fileNode.js +49 -0
- package/dist/esm/generate/utils/index.d.ts +7 -0
- package/dist/esm/generate/utils/index.js +8 -0
- package/dist/esm/generate/utils/tabBarImages.d.ts +14 -0
- package/dist/esm/generate/utils/tabBarImages.js +15 -0
- package/dist/esm/handleCom.d.ts +31 -0
- package/dist/esm/handleCom.js +297 -0
- package/dist/esm/handleDom.d.ts +19 -0
- package/dist/esm/handleDom.js +63 -0
- package/dist/esm/handleExtension.d.ts +10 -0
- package/dist/esm/handleExtension.js +243 -0
- package/dist/esm/handleGlobal.d.ts +21 -0
- package/dist/esm/handleGlobal.js +117 -0
- package/dist/esm/handleModule.d.ts +15 -0
- package/dist/esm/handleModule.js +78 -0
- package/dist/esm/handleSlot.d.ts +27 -0
- package/dist/esm/handleSlot.js +205 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/taro-template.json +5370 -0
- package/dist/esm/toCodeTaro.d.ts +130 -0
- package/dist/esm/toCodeTaro.js +452 -0
- package/dist/esm/utils/code/component.d.ts +19 -0
- package/dist/esm/utils/code/component.js +54 -0
- package/dist/esm/utils/code/index.d.ts +18 -0
- package/dist/esm/utils/code/index.js +51 -0
- package/dist/esm/utils/code/renderManager.d.ts +22 -0
- package/dist/esm/utils/code/renderManager.js +62 -0
- package/dist/esm/utils/code/scene.d.ts +19 -0
- package/dist/esm/utils/code/scene.js +47 -0
- package/dist/esm/utils/convertNamespace.d.ts +11 -0
- package/dist/esm/utils/convertNamespace.js +27 -0
- package/dist/esm/utils/genJSModules.d.ts +12 -0
- package/dist/esm/utils/genJSModules.js +44 -0
- package/dist/esm/utils/getComponentClassName.d.ts +16 -0
- package/dist/esm/utils/getComponentClassName.js +37 -0
- package/dist/esm/utils/handlePageConfig.d.ts +24 -0
- package/dist/esm/utils/handlePageConfig.js +68 -0
- package/dist/esm/utils/handleProcess.d.ts +9 -0
- package/dist/esm/utils/handleProcess.js +379 -0
- package/dist/esm/utils/index.d.ts +62 -0
- package/dist/esm/utils/index.js +345 -0
- package/dist/esm/utils/pageConfig/converter.d.ts +17 -0
- package/dist/esm/utils/pageConfig/converter.js +105 -0
- package/dist/esm/utils/pageConfig/index.d.ts +10 -0
- package/dist/esm/utils/pageConfig/index.js +11 -0
- package/dist/esm/utils/pageConfig/pageConfig.d.ts +10 -0
- package/dist/esm/utils/pageConfig/pageConfig.js +60 -0
- package/dist/esm/utils/pageConfig/saveBase64Image.d.ts +14 -0
- package/dist/esm/utils/pageConfig/saveBase64Image.js +105 -0
- package/dist/esm/utils/pageConfig/tabBarConfig.d.ts +13 -0
- package/dist/esm/utils/pageConfig/tabBarConfig.js +82 -0
- package/dist/esm/utils/pageConfig/types.d.ts +68 -0
- package/dist/esm/utils/pageConfig/types.js +1 -0
- package/dist/esm/utils/pageConfig/validator.d.ts +13 -0
- package/dist/esm/utils/pageConfig/validator.js +64 -0
- package/dist/esm/utils/pxtransform.d.ts +28 -0
- package/dist/esm/utils/pxtransform.js +121 -0
- package/package.json +74 -0
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/utils/index.ts
|
|
30
|
+
var utils_exports = {};
|
|
31
|
+
__export(utils_exports, {
|
|
32
|
+
ImportManager: () => ImportManager,
|
|
33
|
+
camelToKebab: () => camelToKebab,
|
|
34
|
+
convertComponentStyle: () => convertComponentStyle,
|
|
35
|
+
convertRootStyle: () => convertRootStyle,
|
|
36
|
+
convertStyleAryToCss: () => convertStyleAryToCss,
|
|
37
|
+
firstCharToLowerCase: () => firstCharToLowerCase,
|
|
38
|
+
firstCharToUpperCase: () => firstCharToUpperCase,
|
|
39
|
+
genObjectCode: () => genObjectCode,
|
|
40
|
+
getRootComponentClassName: () => import_getComponentClassName.getRootComponentClassName,
|
|
41
|
+
getUiComponentCode: () => import_code.getUiComponentCode,
|
|
42
|
+
indentation: () => indentation,
|
|
43
|
+
kebabToCamel: () => kebabToCamel
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(utils_exports);
|
|
46
|
+
var import_pxtransform = __toESM(require("./pxtransform"));
|
|
47
|
+
var import_code = require("./code");
|
|
48
|
+
var import_getComponentClassName = require("./getComponentClassName");
|
|
49
|
+
var ImportManager = class {
|
|
50
|
+
constructor(_config) {
|
|
51
|
+
this._config = _config;
|
|
52
|
+
this._imports = {};
|
|
53
|
+
}
|
|
54
|
+
/** 添加依赖 */
|
|
55
|
+
addImport({
|
|
56
|
+
packageName,
|
|
57
|
+
dependencyNames,
|
|
58
|
+
importType
|
|
59
|
+
}) {
|
|
60
|
+
if (!packageName) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const { _imports } = this;
|
|
64
|
+
if (!_imports[packageName]) {
|
|
65
|
+
_imports[packageName] = {};
|
|
66
|
+
}
|
|
67
|
+
if (importType === "module" && dependencyNames.length === 0) {
|
|
68
|
+
_imports[packageName]["__module__"] = {
|
|
69
|
+
importType: "module"
|
|
70
|
+
};
|
|
71
|
+
} else {
|
|
72
|
+
dependencyNames.forEach((dependencyName) => {
|
|
73
|
+
_imports[packageName][dependencyName] = {
|
|
74
|
+
importType
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/** 依赖解析为code */
|
|
80
|
+
toCode() {
|
|
81
|
+
const indent = indentation(this._config.codeStyle.indent);
|
|
82
|
+
return Object.entries(this._imports).reduce(
|
|
83
|
+
(pre, [packageName, dependencies]) => {
|
|
84
|
+
var _a;
|
|
85
|
+
let defaultDependency = "";
|
|
86
|
+
let namedDependencies = "";
|
|
87
|
+
let moduleDependency = "";
|
|
88
|
+
const dependencyEntries = Object.entries(dependencies);
|
|
89
|
+
const hasModuleType = ((_a = dependencies["__module__"]) == null ? void 0 : _a.importType) === "module" || dependencyEntries.some(([, { importType }]) => importType === "module");
|
|
90
|
+
if (hasModuleType) {
|
|
91
|
+
return pre + `import '${packageName}';
|
|
92
|
+
`;
|
|
93
|
+
}
|
|
94
|
+
const validEntries = dependencyEntries.filter(([key]) => key !== "__module__");
|
|
95
|
+
const wrap = validEntries.length > 3;
|
|
96
|
+
validEntries.forEach(([dependencyName, { importType }], index) => {
|
|
97
|
+
if (importType === "default") {
|
|
98
|
+
defaultDependency = dependencyName;
|
|
99
|
+
} else if (importType === "named") {
|
|
100
|
+
if (wrap) {
|
|
101
|
+
namedDependencies += `${indent}${dependencyName},
|
|
102
|
+
`;
|
|
103
|
+
} else {
|
|
104
|
+
namedDependencies += `${index ? ", " : ""}${dependencyName}`;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
if (namedDependencies) {
|
|
109
|
+
if (wrap) {
|
|
110
|
+
namedDependencies = `{
|
|
111
|
+
${namedDependencies}}`;
|
|
112
|
+
} else {
|
|
113
|
+
namedDependencies = `{ ${namedDependencies} }`;
|
|
114
|
+
}
|
|
115
|
+
if (defaultDependency) {
|
|
116
|
+
defaultDependency += ", ";
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return pre + `import ${defaultDependency}${namedDependencies} from '${packageName}';
|
|
120
|
+
`;
|
|
121
|
+
},
|
|
122
|
+
""
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
var firstCharToUpperCase = (str) => {
|
|
127
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
128
|
+
};
|
|
129
|
+
var firstCharToLowerCase = (str) => {
|
|
130
|
+
return str.charAt(0).toLowerCase() + str.slice(1);
|
|
131
|
+
};
|
|
132
|
+
var indentation = (level) => {
|
|
133
|
+
return " ".repeat(level);
|
|
134
|
+
};
|
|
135
|
+
var camelToKebab = (str) => {
|
|
136
|
+
return str.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
137
|
+
};
|
|
138
|
+
var kebabToCamel = (str) => {
|
|
139
|
+
return str.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
140
|
+
};
|
|
141
|
+
var convertRootStyle = (style) => {
|
|
142
|
+
const rootStyle = {};
|
|
143
|
+
Object.entries(style || {}).forEach(([key, value]) => {
|
|
144
|
+
if (key === "_new" || key === "themesId" || key === "visibility" || key === "styleAry") {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (key === "layout") {
|
|
148
|
+
if (typeof value === "object" && value !== null) {
|
|
149
|
+
const layoutObj = value;
|
|
150
|
+
Object.entries(layoutObj).forEach(([lKey, lValue]) => {
|
|
151
|
+
if (lKey === "position") {
|
|
152
|
+
if (lValue === "smart") {
|
|
153
|
+
rootStyle["position"] = "absolute";
|
|
154
|
+
} else if (lValue !== "inherit") {
|
|
155
|
+
rootStyle["position"] = lValue;
|
|
156
|
+
}
|
|
157
|
+
} else {
|
|
158
|
+
const camelLayoutKey = kebabToCamel(lKey);
|
|
159
|
+
rootStyle[camelLayoutKey] = (0, import_pxtransform.default)(lValue);
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
} else if (value === "flex-row") {
|
|
163
|
+
rootStyle["display"] = "flex";
|
|
164
|
+
rootStyle["flexDirection"] = "row";
|
|
165
|
+
} else if (value === "flex-column") {
|
|
166
|
+
rootStyle["display"] = "flex";
|
|
167
|
+
rootStyle["flexDirection"] = "column";
|
|
168
|
+
} else if (value === "smart") {
|
|
169
|
+
rootStyle["position"] = "relative";
|
|
170
|
+
}
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
const camelKey = key.includes("-") ? kebabToCamel(key) : key;
|
|
174
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
175
|
+
rootStyle[camelKey] = (0, import_pxtransform.default)(value);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
return rootStyle;
|
|
179
|
+
};
|
|
180
|
+
var convertComponentStyle = (style) => {
|
|
181
|
+
const resultStyle = {};
|
|
182
|
+
const rootStyle = convertRootStyle(style);
|
|
183
|
+
if (style.styleAry) {
|
|
184
|
+
style.styleAry.forEach(
|
|
185
|
+
({
|
|
186
|
+
css,
|
|
187
|
+
selector
|
|
188
|
+
}) => {
|
|
189
|
+
const transformedCss = {};
|
|
190
|
+
Object.entries(css).forEach(([cssKey, cssValue]) => {
|
|
191
|
+
if (cssKey === "layout") {
|
|
192
|
+
if (typeof cssValue === "object" && cssValue !== null) {
|
|
193
|
+
const layoutObj = cssValue;
|
|
194
|
+
Object.entries(layoutObj).forEach(([lKey, lValue]) => {
|
|
195
|
+
if (lKey === "position") {
|
|
196
|
+
if (lValue === "smart") {
|
|
197
|
+
transformedCss["position"] = "absolute";
|
|
198
|
+
} else if (lValue !== "inherit") {
|
|
199
|
+
transformedCss["position"] = lValue;
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
transformedCss[kebabToCamel(lKey)] = lValue;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
} else if (cssValue === "flex-row") {
|
|
206
|
+
transformedCss["display"] = "flex";
|
|
207
|
+
transformedCss["flexDirection"] = "row";
|
|
208
|
+
} else if (cssValue === "flex-column") {
|
|
209
|
+
transformedCss["display"] = "flex";
|
|
210
|
+
transformedCss["flexDirection"] = "column";
|
|
211
|
+
} else if (cssValue === "smart") {
|
|
212
|
+
transformedCss["position"] = "relative";
|
|
213
|
+
}
|
|
214
|
+
} else {
|
|
215
|
+
const camelKey = cssKey.includes("-") ? kebabToCamel(cssKey) : cssKey;
|
|
216
|
+
transformedCss[camelKey] = (0, import_pxtransform.default)(cssValue);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
resultStyle[selector] = transformedCss;
|
|
220
|
+
}
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
resultStyle["root"] = rootStyle;
|
|
224
|
+
return resultStyle;
|
|
225
|
+
};
|
|
226
|
+
var convertStyleAryToCss = (styleAry, parentSelector) => {
|
|
227
|
+
if (!Array.isArray(styleAry))
|
|
228
|
+
return "";
|
|
229
|
+
const prefix = parentSelector ? `.${parentSelector} ` : "";
|
|
230
|
+
return styleAry.map(({ selector, css }) => {
|
|
231
|
+
if (!selector || !css)
|
|
232
|
+
return "";
|
|
233
|
+
let finalSelector = selector;
|
|
234
|
+
if (finalSelector.startsWith(">")) {
|
|
235
|
+
finalSelector = `${prefix}${finalSelector}`;
|
|
236
|
+
} else {
|
|
237
|
+
finalSelector = `${prefix}${finalSelector}`;
|
|
238
|
+
}
|
|
239
|
+
const transformedCss = {};
|
|
240
|
+
Object.entries(css).forEach(([key, value]) => {
|
|
241
|
+
if (key === "layout") {
|
|
242
|
+
if (typeof value === "object" && value !== null) {
|
|
243
|
+
const layoutObj = value;
|
|
244
|
+
Object.entries(layoutObj).forEach(([lKey, lValue]) => {
|
|
245
|
+
if (lKey === "position") {
|
|
246
|
+
if (lValue === "smart") {
|
|
247
|
+
transformedCss["position"] = "absolute";
|
|
248
|
+
} else if (lValue !== "inherit") {
|
|
249
|
+
transformedCss["position"] = lValue;
|
|
250
|
+
}
|
|
251
|
+
} else {
|
|
252
|
+
transformedCss[kebabToCamel(lKey)] = lValue;
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
} else if (value === "flex-row") {
|
|
256
|
+
transformedCss["display"] = "flex";
|
|
257
|
+
transformedCss["flexDirection"] = "row";
|
|
258
|
+
} else if (value === "flex-column") {
|
|
259
|
+
transformedCss["display"] = "flex";
|
|
260
|
+
transformedCss["flexDirection"] = "column";
|
|
261
|
+
} else if (value === "smart") {
|
|
262
|
+
transformedCss["position"] = "relative";
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
transformedCss[kebabToCamel(key)] = value;
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
const cssString = Object.entries(transformedCss).map(([key, value]) => {
|
|
269
|
+
const kebabKey = camelToKebab(key);
|
|
270
|
+
const formattedValue = typeof value === "number" ? `${value}px` : value;
|
|
271
|
+
return ` ${kebabKey}: ${formattedValue};`;
|
|
272
|
+
}).join("\n");
|
|
273
|
+
return `${finalSelector} {
|
|
274
|
+
${cssString}
|
|
275
|
+
}`;
|
|
276
|
+
}).join("\n\n");
|
|
277
|
+
};
|
|
278
|
+
var genObjectCode = (object, config) => {
|
|
279
|
+
const { initialIndent, indentSize } = config;
|
|
280
|
+
const keys = Object.keys(object);
|
|
281
|
+
if (keys.length === 0)
|
|
282
|
+
return "{}";
|
|
283
|
+
let result = "{\n";
|
|
284
|
+
keys.forEach((key, idx) => {
|
|
285
|
+
const value = object[key];
|
|
286
|
+
let formattedValue;
|
|
287
|
+
if (Array.isArray(value)) {
|
|
288
|
+
formattedValue = JSON.stringify(value);
|
|
289
|
+
} else if (value && typeof value === "object") {
|
|
290
|
+
formattedValue = genObjectCode(value, {
|
|
291
|
+
initialIndent: initialIndent + indentSize,
|
|
292
|
+
indentSize
|
|
293
|
+
});
|
|
294
|
+
} else if (typeof value === "string") {
|
|
295
|
+
formattedValue = JSON.stringify(value);
|
|
296
|
+
} else {
|
|
297
|
+
formattedValue = String(value);
|
|
298
|
+
}
|
|
299
|
+
result += indentation(initialIndent + indentSize) + `${JSON.stringify(key)}: ${formattedValue}`;
|
|
300
|
+
if (idx < keys.length - 1)
|
|
301
|
+
result += ",";
|
|
302
|
+
result += "\n";
|
|
303
|
+
});
|
|
304
|
+
result += indentation(initialIndent) + "}";
|
|
305
|
+
return result;
|
|
306
|
+
};
|
|
307
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
308
|
+
0 && (module.exports = {
|
|
309
|
+
ImportManager,
|
|
310
|
+
camelToKebab,
|
|
311
|
+
convertComponentStyle,
|
|
312
|
+
convertRootStyle,
|
|
313
|
+
convertStyleAryToCss,
|
|
314
|
+
firstCharToLowerCase,
|
|
315
|
+
firstCharToUpperCase,
|
|
316
|
+
genObjectCode,
|
|
317
|
+
getRootComponentClassName,
|
|
318
|
+
getUiComponentCode,
|
|
319
|
+
indentation,
|
|
320
|
+
kebabToCamel
|
|
321
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { TabBarItemSource, TaroTabBarConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* 将 TabBar 数据转换为 Taro 配置格式
|
|
4
|
+
* @param tabBar TabBar 项数组(来自 toJson.tabbar)
|
|
5
|
+
* @param pageIdToPath 页面 ID 到路径的映射函数,默认格式为 `pages/${pageId}/index`
|
|
6
|
+
* @param processIcon 处理图标的函数(可选,用于处理 base64 图片)
|
|
7
|
+
* @returns Taro TabBar 配置,如果验证失败则返回 null
|
|
8
|
+
*/
|
|
9
|
+
export declare function convertToTaroTabBarConfig(tabBar: TabBarItemSource[] | undefined | null, pageIdToPath?: (pageId: string) => string, processIcon?: (iconPath: string | undefined, index: number, type: 'normal' | 'selected') => string | undefined): TaroTabBarConfig | null;
|
|
10
|
+
/**
|
|
11
|
+
* 获取入口页面 ID
|
|
12
|
+
* 如果启用 TabBar,返回第一个 TabBar 项的页面 ID;否则返回 null
|
|
13
|
+
* @param tabBar TabBar 项数组
|
|
14
|
+
* @param defaultEntryPageId 默认入口页面 ID(当 TabBar 未启用时使用)
|
|
15
|
+
* @returns 入口页面 ID
|
|
16
|
+
*/
|
|
17
|
+
export declare function getEntryPageId(tabBar: TabBarItemSource[] | undefined | null, defaultEntryPageId?: string): string | null;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/pageConfig/converter.ts
|
|
20
|
+
var converter_exports = {};
|
|
21
|
+
__export(converter_exports, {
|
|
22
|
+
convertToTaroTabBarConfig: () => convertToTaroTabBarConfig,
|
|
23
|
+
getEntryPageId: () => getEntryPageId
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(converter_exports);
|
|
26
|
+
var import_validator = require("./validator");
|
|
27
|
+
function convertTabBarItem(item, pageIdToPath, index = 0, processIcon) {
|
|
28
|
+
const pagePath = pageIdToPath(item.scene.id);
|
|
29
|
+
const text = item.text || item.scene.title || "";
|
|
30
|
+
const taroItem = {
|
|
31
|
+
pagePath,
|
|
32
|
+
text
|
|
33
|
+
};
|
|
34
|
+
if (item.normalIconPath) {
|
|
35
|
+
taroItem.iconPath = processIcon ? processIcon(item.normalIconPath, index, "normal") : item.normalIconPath;
|
|
36
|
+
}
|
|
37
|
+
if (item.selectedIconPath) {
|
|
38
|
+
taroItem.selectedIconPath = processIcon ? processIcon(item.selectedIconPath, index, "selected") : item.selectedIconPath;
|
|
39
|
+
}
|
|
40
|
+
return taroItem;
|
|
41
|
+
}
|
|
42
|
+
function extractColorFromTextStyle(textStyle) {
|
|
43
|
+
if (!textStyle || typeof textStyle !== "object") {
|
|
44
|
+
return void 0;
|
|
45
|
+
}
|
|
46
|
+
return textStyle.color || textStyle.colorValue;
|
|
47
|
+
}
|
|
48
|
+
function convertToTaroTabBarConfig(tabBar, pageIdToPath = (pageId) => `pages/${pageId}/index`, processIcon) {
|
|
49
|
+
const validation = (0, import_validator.validateTabBar)(tabBar);
|
|
50
|
+
if (!validation.useTabBar) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
const list = validation.validItems.map(
|
|
54
|
+
(item, index) => convertTabBarItem(item, pageIdToPath, index, processIcon)
|
|
55
|
+
);
|
|
56
|
+
const config = {
|
|
57
|
+
list
|
|
58
|
+
};
|
|
59
|
+
const firstItem = validation.validItems[0];
|
|
60
|
+
if (firstItem) {
|
|
61
|
+
const normalColor = extractColorFromTextStyle(firstItem.normalTextStyle);
|
|
62
|
+
const selectedColor = extractColorFromTextStyle(firstItem.selectedTextStyle);
|
|
63
|
+
if (normalColor) {
|
|
64
|
+
config.color = normalColor;
|
|
65
|
+
}
|
|
66
|
+
if (selectedColor) {
|
|
67
|
+
config.selectedColor = selectedColor;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return config;
|
|
71
|
+
}
|
|
72
|
+
function getEntryPageId(tabBar, defaultEntryPageId) {
|
|
73
|
+
const validation = (0, import_validator.validateTabBar)(tabBar);
|
|
74
|
+
if (validation.useTabBar && validation.validItems.length > 0) {
|
|
75
|
+
return validation.validItems[0].scene.id;
|
|
76
|
+
}
|
|
77
|
+
return defaultEntryPageId || null;
|
|
78
|
+
}
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
convertToTaroTabBarConfig,
|
|
82
|
+
getEntryPageId
|
|
83
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/utils/pageConfig/index.ts
|
|
17
|
+
var pageConfig_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(pageConfig_exports);
|
|
19
|
+
__reExport(pageConfig_exports, require("./types"), module.exports);
|
|
20
|
+
__reExport(pageConfig_exports, require("./validator"), module.exports);
|
|
21
|
+
__reExport(pageConfig_exports, require("./converter"), module.exports);
|
|
22
|
+
__reExport(pageConfig_exports, require("./pageConfig"), module.exports);
|
|
23
|
+
__reExport(pageConfig_exports, require("./tabBarConfig"), module.exports);
|
|
24
|
+
__reExport(pageConfig_exports, require("./saveBase64Image"), module.exports);
|
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
26
|
+
0 && (module.exports = {
|
|
27
|
+
...require("./types"),
|
|
28
|
+
...require("./validator"),
|
|
29
|
+
...require("./converter"),
|
|
30
|
+
...require("./pageConfig"),
|
|
31
|
+
...require("./tabBarConfig"),
|
|
32
|
+
...require("./saveBase64Image")
|
|
33
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 页面配置工具
|
|
3
|
+
* 负责从 systemPage 组件数据生成 definePageConfig 配置字符串
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 从 systemPage 组件数据生成 definePageConfig 配置字符串
|
|
7
|
+
* @param systemPageData systemPage 组件的 model.data
|
|
8
|
+
* @returns definePageConfig 配置字符串
|
|
9
|
+
*/
|
|
10
|
+
export declare function generatePageConfigContent(systemPageData?: any): string;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/pageConfig/pageConfig.ts
|
|
20
|
+
var pageConfig_exports = {};
|
|
21
|
+
__export(pageConfig_exports, {
|
|
22
|
+
generatePageConfigContent: () => generatePageConfigContent
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(pageConfig_exports);
|
|
25
|
+
var TARO_NAVIGATION_BAR_PROPERTIES = [
|
|
26
|
+
"navigationBarBackgroundColor",
|
|
27
|
+
"navigationBarTextStyle",
|
|
28
|
+
"navigationBarTitleText",
|
|
29
|
+
"navigationStyle"
|
|
30
|
+
];
|
|
31
|
+
var TARO_PAGE_CONFIG_TEMPLATE_PROPERTIES = [
|
|
32
|
+
"navigationBarBackgroundColor",
|
|
33
|
+
"navigationBarTextStyle",
|
|
34
|
+
"navigationBarTitleText",
|
|
35
|
+
"navigationStyle",
|
|
36
|
+
"transparentTitle",
|
|
37
|
+
"backgroundColor",
|
|
38
|
+
"backgroundTextStyle",
|
|
39
|
+
"backgroundColorTop",
|
|
40
|
+
"backgroundColorBottom",
|
|
41
|
+
"enablePullDownRefresh",
|
|
42
|
+
"onReachBottomDistance",
|
|
43
|
+
"pageOrientation",
|
|
44
|
+
"disableScroll",
|
|
45
|
+
"disableSwipeBack",
|
|
46
|
+
"enableShareAppMessage",
|
|
47
|
+
"enableShareTimeline",
|
|
48
|
+
"usingComponents",
|
|
49
|
+
"renderer"
|
|
50
|
+
];
|
|
51
|
+
function generatePageConfigContent(systemPageData) {
|
|
52
|
+
const pageConfig = {};
|
|
53
|
+
if (systemPageData) {
|
|
54
|
+
const useNavigationStyle = systemPageData.useNavigationStyle;
|
|
55
|
+
let propertiesToUse = [];
|
|
56
|
+
if (useNavigationStyle === "default") {
|
|
57
|
+
propertiesToUse = TARO_NAVIGATION_BAR_PROPERTIES;
|
|
58
|
+
} else {
|
|
59
|
+
propertiesToUse = TARO_PAGE_CONFIG_TEMPLATE_PROPERTIES;
|
|
60
|
+
}
|
|
61
|
+
propertiesToUse.forEach((prop) => {
|
|
62
|
+
if (systemPageData[prop] !== void 0 && systemPageData[prop] !== null) {
|
|
63
|
+
const value = systemPageData[prop];
|
|
64
|
+
if (typeof value === "string") {
|
|
65
|
+
pageConfig[prop] = `'${value}'`;
|
|
66
|
+
} else if (typeof value === "boolean" || typeof value === "number") {
|
|
67
|
+
pageConfig[prop] = value;
|
|
68
|
+
} else if (typeof value === "object") {
|
|
69
|
+
pageConfig[prop] = JSON.stringify(value);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (Object.keys(pageConfig).length === 0) {
|
|
75
|
+
pageConfig.navigationBarTitleText = `'页面'`;
|
|
76
|
+
}
|
|
77
|
+
const configLines = Object.entries(pageConfig).map(([key, value]) => {
|
|
78
|
+
return ` ${key}: ${value}`;
|
|
79
|
+
});
|
|
80
|
+
return `export default definePageConfig({
|
|
81
|
+
${configLines.join(",\n")}
|
|
82
|
+
})`;
|
|
83
|
+
}
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
generatePageConfigContent
|
|
87
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base64 图片处理工具
|
|
3
|
+
* 负责将 base64 图片保存为本地文件
|
|
4
|
+
*/
|
|
5
|
+
import type { ImageFileInfo } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* 处理 TabBar 图标,如果是 base64 则准备保存为文件
|
|
8
|
+
* @param iconPath 图标路径(可能是 base64 或普通路径)
|
|
9
|
+
* @param tabBarIndex TabBar 项的索引
|
|
10
|
+
* @param type 图标类型('normal' 或 'selected')
|
|
11
|
+
* @param imageFiles 用于收集需要保存的图片文件的数组(可选)
|
|
12
|
+
* @returns 处理后的图标路径(用于 app.config.ts),如果不是 base64 则返回原路径
|
|
13
|
+
*/
|
|
14
|
+
export declare function processTabBarIcon(iconPath: string | undefined, tabBarIndex: number, type: 'normal' | 'selected', imageFiles?: ImageFileInfo[]): string | undefined;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/utils/pageConfig/saveBase64Image.ts
|
|
20
|
+
var saveBase64Image_exports = {};
|
|
21
|
+
__export(saveBase64Image_exports, {
|
|
22
|
+
processTabBarIcon: () => processTabBarIcon
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(saveBase64Image_exports);
|
|
25
|
+
var MIME_TO_EXT = {
|
|
26
|
+
png: "png",
|
|
27
|
+
jpg: "jpg",
|
|
28
|
+
jpeg: "jpg",
|
|
29
|
+
gif: "gif",
|
|
30
|
+
webp: "webp",
|
|
31
|
+
svg: "svg"
|
|
32
|
+
};
|
|
33
|
+
function parseBase64Image(base64Str) {
|
|
34
|
+
if (typeof base64Str !== "string" || !base64Str.startsWith("data:image/")) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
const match = base64Str.match(/^data:image\/([^;]+);base64,(.+)$/);
|
|
38
|
+
if (!match) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
mimeType: match[1],
|
|
43
|
+
base64Data: match[2]
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function getFileExtension(mimeType) {
|
|
47
|
+
return MIME_TO_EXT[mimeType.toLowerCase()] || "png";
|
|
48
|
+
}
|
|
49
|
+
function generateFileName(index, type, extension) {
|
|
50
|
+
return `tabbar_${index}_${type}.${extension}`;
|
|
51
|
+
}
|
|
52
|
+
function processTabBarIcon(iconPath, tabBarIndex, type, imageFiles) {
|
|
53
|
+
if (!iconPath) {
|
|
54
|
+
return void 0;
|
|
55
|
+
}
|
|
56
|
+
const parsed = parseBase64Image(iconPath);
|
|
57
|
+
if (!parsed) {
|
|
58
|
+
return iconPath;
|
|
59
|
+
}
|
|
60
|
+
const extension = getFileExtension(parsed.mimeType);
|
|
61
|
+
const fileName = generateFileName(tabBarIndex, type, extension);
|
|
62
|
+
const fileSystemPath = `src/assets/tabbar/${fileName}`;
|
|
63
|
+
const configPath = `assets/tabbar/${fileName}`;
|
|
64
|
+
if (imageFiles) {
|
|
65
|
+
try {
|
|
66
|
+
const imageBuffer = Buffer.from(parsed.base64Data, "base64");
|
|
67
|
+
imageFiles.push({
|
|
68
|
+
filePath: fileSystemPath,
|
|
69
|
+
fileContent: imageBuffer
|
|
70
|
+
});
|
|
71
|
+
} catch (error) {
|
|
72
|
+
console.error(`处理 TabBar 图标失败: ${error}`);
|
|
73
|
+
return iconPath;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return configPath;
|
|
77
|
+
}
|
|
78
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
79
|
+
0 && (module.exports = {
|
|
80
|
+
processTabBarIcon
|
|
81
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TabBar 配置工具
|
|
3
|
+
* 负责从 tabBar 数据生成 app.config.ts 中的 tabBar 配置字符串
|
|
4
|
+
*/
|
|
5
|
+
import type { ImageFileInfo } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* 从 tabBar 数据生成 TabBar 配置字符串(用于 app.config.ts)
|
|
8
|
+
* @param tabBar tabBar 数据数组(来自 scenes[x].coms[id].model.data.tabBar)
|
|
9
|
+
* @param pageIdToPath 页面 ID 到路径的映射函数(默认使用 pages/${pageId}/index)
|
|
10
|
+
* @param imageFiles 用于收集需要保存的图片文件的数组(可选)
|
|
11
|
+
* @returns TabBar 配置字符串,如果验证失败则返回 null
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateTabBarConfigContent(tabBar: any[] | undefined, pageIdToPath?: (pageId: string) => string, imageFiles?: ImageFileInfo[]): string | null;
|