Files
Docker/uniapp/youjiala/src/utils/rotateGlyph.ts
T
2026-10-21 09:31:20 +08:00

33 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 图片查看器左旋/右旋自定义字形(内联 SVG,不依赖 iconfont 字体文件)。
* uview-pro 图标库没有旋转语义(reload 是循环箭头、形不似),按 custom-icon.md
* 规范自绘:path 取自 Material Icons 的 rotate_left / rotate_right,原 fill 色
* 改为按参数注入(查看器内恒白)。
*/
/* 字形分段存(每个元素一条子路径):单行超长拼接会撞 operator-linebreak/Prettier 对撞 */
const ROTATE_LEFT_SEGMENTS = [
"M7.11 8.53L5.7 7.11C4.8 8.27 4.24 9.61 4.07 11h2.02c.14-.87.49-1.72 1.02-2.47zM6.09 13H4.07c.17 1.39.72 2.73 1.62 3.89l1.41-1.42c-.52-.75-.87-1.59-1.01-2.47zm1.01 5.32c1.16.9 2.51 1.44 3.9 1.61V17.9c-.87-.15-1.71-.49-2.46-1.03L7.1 18.32z",
"M13 4.07V1L8.45 5.55 13 10V6.09c2.84.48 5 2.94 5 5.91s-2.16 5.43-5 5.91v2.02c3.95-.49 7-3.85 7-7.93s-3.05-7.44-7-7.93z",
];
const ROTATE_RIGHT_SEGMENTS = [
"M15.55 5.55L11 1v3.07C7.06 4.56 4 7.92 4 12s3.05 7.44 7 7.93v-2.02c-2.84-.48-5-2.94-5-5.91s2.16-5.43 5-5.91V10l4.55-4.45zM19.93 11c-.17-1.39-.72-2.73-1.62-3.89l-1.42 1.42c.54.75.88 1.6 1.02 2.47h2.02z",
"M13 17.9v2.02c1.39-.17 2.74-.71 3.9-1.61l-1.44-1.44c-.75.54-1.59.89-2.46 1.03zm3.89-2.42l1.42 1.41c.9-1.16 1.45-2.5 1.62-3.89h-2.02c-.14.87-.48 1.72-1.02 2.48z",
];
/** 拼 data URI:fill 注入色值,viewBox 原样保留 Material 的 24 方形 */
function glyphOf(segments: string[], color: string): string {
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="${color}" d="${segments.join("")}" /></svg>`;
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
}
/** 向左(逆时针)旋转 */
export function rotateLeftGlyph(color: string): string {
return glyphOf(ROTATE_LEFT_SEGMENTS, color);
}
/** 向右(顺时针)旋转 */
export function rotateRightGlyph(color: string): string {
return glyphOf(ROTATE_RIGHT_SEGMENTS, color);
}