74 lines
4.9 KiB
JavaScript
74 lines
4.9 KiB
JavaScript
let CssSpecialTreatment = [
|
||
{ "titleEn": "@keyframes", "title": "@关键帧动画","T_usage":"请直接在CSS中使用本命令,使用本命令可以创建动画;创建动画是通过逐步改变从一个CSS样式设定到另一个样式。" },
|
||
{ "titleEn": "@media", "title": "@媒体查询","T_usage":"请直接在CSS中使用本命令,媒体查询可以判断用户的页面大小来执行不同的代码;具体用法可在网络代码块中搜索媒体查询关键字" },
|
||
{ "titleEn": "!important", "title": "@样式提权","T_usage":"请直接在CSS中使用本命令,样式提权最主要作用是提高指定CSS样式规则的应用优先权" },
|
||
//@CSS专属特殊关键字
|
||
]
|
||
//单独处理CSS的伪类
|
||
function CssTranslateToPseudoClass(code, Translate, TranslateEN) {
|
||
if (Translate == "after" || TranslateEN == "after" || Translate == "before" || TranslateEN == "before" || Translate == "nth-child" || TranslateEN == "nth-child" || Translate == "hover" || TranslateEN == "hover" || Translate == "placeholder" || TranslateEN == "placeholder" || Translate == "focus" || TranslateEN == "focus" || Translate == "link" || TranslateEN == "link" || Translate == "active" || TranslateEN == "active" || Translate == "visited" || TranslateEN == "visited" || Translate == "checked" || TranslateEN == "checked" || Translate == "root" || TranslateEN == "root") {
|
||
code = code.replaceAll(":" + Translate + " ", ":" + TranslateEN + " ")
|
||
code = code.replaceAll(":" + Translate + "{", ":" + TranslateEN + "{")
|
||
code = code.replaceAll(":" + Translate + "\r\n", ":" + TranslateEN + "\r\n")
|
||
code = code.replaceAll(":" + Translate + "\n", ":" + TranslateEN + "\n")
|
||
code = code.replaceAll(":" + Translate + ",", ":" + TranslateEN + ",")
|
||
code = code.replaceAll(":" + Translate + " ,", ":" + TranslateEN + " ,")
|
||
code = code.replaceAll(":" + Translate + ":", ":" + TranslateEN + ":")
|
||
code = code.replaceAll(":" + Translate + " :", ":" + TranslateEN + " :")
|
||
code = code.replaceAll(":" + Translate + " (", ":" + TranslateEN + " (")
|
||
code = code.replaceAll(":" + Translate + "(", ":" + TranslateEN + "(")
|
||
code = code.replaceAll(":" + Translate + "~", ":" + TranslateEN + "~")
|
||
code = code.replaceAll(":" + Translate + "+", ":" + TranslateEN + "+")
|
||
|
||
|
||
code = code.replaceAll(": " + Translate + " ", ": " + TranslateEN + " ")
|
||
code = code.replaceAll(": " + Translate + "{", ": " + TranslateEN + "{")
|
||
code = code.replaceAll(": " + Translate + "\r\n", ": " + TranslateEN + "\r\n")
|
||
code = code.replaceAll(": " + Translate + "\n", ": " + TranslateEN + "\n")
|
||
code = code.replaceAll(": " + Translate + ",", ": " + TranslateEN + ",")
|
||
code = code.replaceAll(": " + Translate + " ,", ": " + TranslateEN + " ,")
|
||
code = code.replaceAll(": " + Translate + ":", ": " + TranslateEN + ":")
|
||
code = code.replaceAll(": " + Translate + " :", ": " + TranslateEN + " :")
|
||
code = code.replaceAll(": " + Translate + "(", ": " + TranslateEN + "(")
|
||
code = code.replaceAll(": " + Translate + " (", ": " + TranslateEN + " (")
|
||
code = code.replaceAll(": " + Translate + "~", ": " + TranslateEN + "~")
|
||
code = code.replaceAll(": " + Translate + "+", ": " + TranslateEN + "+")
|
||
}
|
||
return code;
|
||
}
|
||
//单独处理一些CSS命令的特殊翻译
|
||
//注意:本方法在uniapp的编译中有单独调用,所以不要使用一些css才有的专属数据!
|
||
function CssTranslateToEN(code) {
|
||
if (code == undefined) {
|
||
code = "";
|
||
}
|
||
if (ComPilerDataMsgType.IfComPiler == true) {
|
||
code = code.replaceAll("fofstudiotextcolor", "color");
|
||
}
|
||
code = code.replaceAll("(最大-宽度:", "(max-width:");
|
||
code = code.replaceAll("(最小-宽度:", "(min-width:");
|
||
code = code.replaceAll("( 最大-宽度:", "( max-width:");
|
||
code = code.replaceAll("( 最小-宽度:", "( min-width:");
|
||
code = code.replaceAll("( 最大-宽度:", "( max-width:");
|
||
code = code.replaceAll("( 最小-宽度:", "( min-width:");
|
||
return code;
|
||
}
|
||
//CodeType-1代表编译成本地语言,2代表编译成英文
|
||
//【注意:本地语言,例如中文、柬埔寨或者其他国家语言以正则为主,目前暂时支持中文】
|
||
function CssSpecialTreatmentFun(code, CodeType) {
|
||
if (code == undefined) {
|
||
code = "";
|
||
}
|
||
for (let index = 0; index < CssSpecialTreatment.length; index++) {
|
||
if (code.indexOf(CssSpecialTreatment[index]["title"]) != -1 || code.indexOf(CssSpecialTreatment[index]["titleEn"]) != -1) {
|
||
if (CodeType == 1) {
|
||
code = code.replaceAll(CssSpecialTreatment[index]["titleEn"], CssSpecialTreatment[index]["title"]);
|
||
} else {
|
||
code = code.replaceAll(CssSpecialTreatment[index]["title"], CssSpecialTreatment[index]["titleEn"]);
|
||
}
|
||
}
|
||
}
|
||
|
||
code = CssTranslateToEN(code);
|
||
return code;
|
||
} |