This commit is contained in:
icssoa 2025-07-09 20:57:40 +08:00
parent 62f54008ce
commit 3b46c8cf07
4 changed files with 51 additions and 14 deletions

View File

@ -1815,6 +1815,23 @@ if (typeof window !== 'undefined') {
"/": "-slash-",
":": "-colon-",
};
/**
* 特殊字符映射表国际化
*/
const SAFE_CHAR_MAP_LOCALE = {
"[": "-bracket-start-",
"]": "-bracket-end-",
"(": "-paren-start-",
")": "-paren-end-",
"{": "-brace-start-",
"}": "-brace-end-",
$: "-dollar-",
"#": "-hash-",
"!": "-important-",
"/": "-slash-",
":": "-colon-",
" ": "-space-",
};
// @ts-ignore
/**
@ -2146,9 +2163,9 @@ if (typeof window !== 'undefined') {
if (id.includes("/cool/ctx/index.ts")) {
const ctx = await createCtx();
const theme = await readFile(rootDir("theme.json"), true);
ctx["SAFE_CHAR_MAP"] = [];
for (const i in SAFE_CHAR_MAP) {
ctx["SAFE_CHAR_MAP"].push([i, SAFE_CHAR_MAP[i]]);
ctx["SAFE_CHAR_MAP_LOCALE"] = [];
for (const i in SAFE_CHAR_MAP_LOCALE) {
ctx["SAFE_CHAR_MAP_LOCALE"].push([i, SAFE_CHAR_MAP_LOCALE[i]]);
}
ctx["theme"] = theme;
code = code.replace("const ctx = {}", `const ctx = ${JSON.stringify(ctx, null, 4)}`);
@ -2168,8 +2185,8 @@ if (typeof window !== 'undefined') {
const d = JSON.parse(code);
for (let i in d) {
let k = i;
for (let j in SAFE_CHAR_MAP) {
k = k.replaceAll(j, SAFE_CHAR_MAP[j]);
for (let j in SAFE_CHAR_MAP_LOCALE) {
k = k.replaceAll(j, SAFE_CHAR_MAP_LOCALE[j]);
}
if (k != i) {
d[k] = d[i];

View File

@ -2,3 +2,7 @@
*
*/
export declare const SAFE_CHAR_MAP: Record<string, string>;
/**
*
*/
export declare const SAFE_CHAR_MAP_LOCALE: Record<string, string>;

View File

@ -1,11 +1,9 @@
import type { Plugin } from "vite";
import { SAFE_CHAR_MAP } from "./config";
import { SAFE_CHAR_MAP_LOCALE } from "./config";
import { createCtx } from "../ctx";
import { readFile, rootDir } from "../utils";
import { createEps } from "../eps";
import { isEmpty, uniq } from "lodash";
import { config } from "../config";
import axios from "axios";
import { uniq } from "lodash";
export function codePlugin(): Plugin[] {
return [
@ -17,9 +15,9 @@ export function codePlugin(): Plugin[] {
const ctx = await createCtx();
const theme = await readFile(rootDir("theme.json"), true);
ctx["SAFE_CHAR_MAP"] = [];
for (const i in SAFE_CHAR_MAP) {
ctx["SAFE_CHAR_MAP"].push([i, SAFE_CHAR_MAP[i]]);
ctx["SAFE_CHAR_MAP_LOCALE"] = [];
for (const i in SAFE_CHAR_MAP_LOCALE) {
ctx["SAFE_CHAR_MAP_LOCALE"].push([i, SAFE_CHAR_MAP_LOCALE[i]]);
}
ctx["theme"] = theme;
@ -50,8 +48,8 @@ export function codePlugin(): Plugin[] {
for (let i in d) {
let k = i;
for (let j in SAFE_CHAR_MAP) {
k = k.replaceAll(j, SAFE_CHAR_MAP[j]);
for (let j in SAFE_CHAR_MAP_LOCALE) {
k = k.replaceAll(j, SAFE_CHAR_MAP_LOCALE[j]);
}
if (k != i) {

View File

@ -14,3 +14,21 @@ export const SAFE_CHAR_MAP: Record<string, string> = {
"/": "-slash-",
":": "-colon-",
};
/**
*
*/
export const SAFE_CHAR_MAP_LOCALE: Record<string, string> = {
"[": "-bracket-start-",
"]": "-bracket-end-",
"(": "-paren-start-",
")": "-paren-end-",
"{": "-brace-start-",
"}": "-brace-end-",
$: "-dollar-",
"#": "-hash-",
"!": "-important-",
"/": "-slash-",
":": "-colon-",
" ": "-space-",
};