feat: 粗细滑块、移动端两行工具栏、二维码底部定位、字号修复及README更新

This commit is contained in:
2026-05-15 15:06:02 +08:00
parent 8789a76ecc
commit 315f568138
5 changed files with 172 additions and 50 deletions

View File

@@ -28,7 +28,8 @@
const bgScaleValue = document.getElementById('bgScaleValue');
const bgOpacitySlider = document.getElementById('bgOpacitySlider');
const bgOpacityValue = document.getElementById('bgOpacityValue');
const boldBtn = document.getElementById('boldBtn');
const weightSlider = document.getElementById('weightSlider');
const weightValue = document.getElementById('weightValue');
const italicBtn = document.getElementById('italicBtn');
const lockBtn = document.getElementById('lockBtn');
const colorPicker = document.getElementById('colorPicker');
@@ -1899,10 +1900,7 @@
const fontFamily = style.fontFamily.replace(/['"]/g, '');
const fontSize = parseInt(style.fontSize);
// 更新加粗按钮状态
boldBtn.classList.toggle('active', fontWeight === 'bold' || fontWeight === '700' || parseInt(fontWeight) >= 700);
// 更新斜体按钮状态
// 更新颜色选择器
italicBtn.classList.toggle('active', fontStyle === 'italic');
// 更新颜色选择器
@@ -1925,6 +1923,19 @@
fontPicker.value = fontPicker.options[0].value;
}
// 更新字重滑动条(兼容关键字 bold/normal 和数值)
var numericWeight = parseInt(style.fontWeight);
if (!isNaN(numericWeight)) {
weightSlider.value = numericWeight;
weightValue.textContent = numericWeight;
} else if (fontWeight === 'bold') {
weightSlider.value = 700;
weightValue.textContent = '700';
} else {
weightSlider.value = 400;
weightValue.textContent = '400';
}
// 更新锁定按钮状态
lockBtn.classList.toggle('active', element.classList.contains('locked'));
@@ -2370,22 +2381,15 @@
// 初始化文本编辑器工具栏
function initTextEditorToolbar() {
// 加粗按钮
boldBtn.addEventListener('click', () => {
const targetInput = editingInput || selectedInput;
if (!targetInput) return;
const selection = window.getSelection();
if (selection.rangeCount > 0 && !selection.isCollapsed) {
document.execCommand('bold', false, null);
} else {
const isBold = boldBtn.classList.contains('active');
if (isBold) {
targetInput.style.fontWeight = 'normal';
} else {
targetInput.style.fontWeight = 'bold';
}
boldBtn.classList.toggle('active');
}
// 字重滑动条
weightSlider.addEventListener('input', function() {
var target = editingInput || selectedInput;
if (!target) return;
var val = parseInt(this.value);
target.style.fontWeight = val;
weightValue.textContent = val;
});
weightSlider.addEventListener('change', function() {
saveState();
});
@@ -3669,11 +3673,11 @@
lineHeight = lineHeight * scale;
}
// 处理字体粗细 - 统一转换为标准格式
let fontWeight = style.fontWeight;
// 数值转换为关键字
if (fontWeight === '400' || fontWeight === 'normal') fontWeight = 'normal';
else if (fontWeight === '700' || fontWeight === 'bold') fontWeight = 'bold';
// 处理字体粗细 - 直接使用原始数值(canvas 支持 1~1000 的数值权重)
var fontWeight = style.fontWeight;
// 仅将 CSS 关键字映射为对应数值
if (fontWeight === 'normal') fontWeight = '400';
else if (fontWeight === 'bold') fontWeight = '700';
// 获取斜体样式
let fontStyle = style.fontStyle;