diff --git a/public/assets/css/stylesheet.css b/public/assets/css/stylesheet.css index 660780c..0e6b841 100644 --- a/public/assets/css/stylesheet.css +++ b/public/assets/css/stylesheet.css @@ -31,7 +31,7 @@ h2 { } p { - font-size: 1rem; + font-size: 16px; margin: 0mm 0mm 5mm 0mm; } diff --git a/src/components/editor/TextSettings.vue b/src/components/editor/TextSettings.vue index 6dfaf8a..aa8e49c 100644 --- a/src/components/editor/TextSettings.vue +++ b/src/components/editor/TextSettings.vue @@ -2,7 +2,7 @@

Réglage du texte

- +

Ces réglages s'appliquent à l'ensemble des éléments du document. Vous pouvez modifier ensuite les éléments indépendamment. @@ -38,7 +38,7 @@

+ +
+
+ + +
+
+
@@ -151,6 +165,7 @@ const font = ref('Alegreya Sans'); const italic = ref(false); const weight = ref('400'); const fontSize = ref({ value: 16, unit: 'px' }); +const lineHeight = ref({ value: 1.2, unit: 'em' }); const alignment = ref('left'); const color = ref('rgb(0, 0, 0)'); const background = ref('transparent'); @@ -203,10 +218,92 @@ watch(weight, (val) => { updateStyle('p', 'font-weight', val); }); -watch(fontSize, (val) => { +watch(fontSize, (newVal, oldVal) => { if (isUpdatingFromStore) return; + + // If unit changed, convert the value + if (oldVal && newVal.unit !== oldVal.unit) { + const baseFontSize = 16; // Default base font size for rem + let convertedValue = newVal.value; + + // Convert from px to em/rem + if (oldVal.unit === 'px' && (newVal.unit === 'em' || newVal.unit === 'rem')) { + convertedValue = newVal.value / baseFontSize; + // Round to 1 decimal place + convertedValue = Math.round(convertedValue * 10) / 10; + } + // Convert from em/rem to px + else if ((oldVal.unit === 'em' || oldVal.unit === 'rem') && newVal.unit === 'px') { + convertedValue = newVal.value * baseFontSize; + // Round to whole number for px + convertedValue = Math.round(convertedValue); + } + + // Clamp to valid range based on new unit + if (newVal.unit === 'em' || newVal.unit === 'rem') { + convertedValue = Math.max(0, Math.min(4, convertedValue)); + } else { + convertedValue = Math.max(8, Math.min(72, convertedValue)); + } + + // Update with converted value - create new object to trigger reactivity + fontSize.value = { value: convertedValue, unit: newVal.unit }; + return; // Exit early to avoid double update + } + debouncedUpdate(() => { - updateStyle('p', 'font-size', `${val.value}${val.unit}`); + updateStyle('p', 'font-size', `${newVal.value}${newVal.unit}`); + }); +}, { deep: true }); + +watch(lineHeight, (newVal, oldVal) => { + if (isUpdatingFromStore) return; + + // If unit changed, convert the value + if (oldVal && newVal.unit !== oldVal.unit) { + const baseFontSize = 16; // Default base font size for rem + let convertedValue = newVal.value; + + // Convert from px to em/rem + if (oldVal.unit === 'px' && (newVal.unit === 'em' || newVal.unit === 'rem')) { + const divisor = newVal.unit === 'em' ? fontSize.value.value : baseFontSize; + convertedValue = newVal.value / divisor; + // Round to 1 decimal place + convertedValue = Math.round(convertedValue * 10) / 10; + } + // Convert from em/rem to px + else if ((oldVal.unit === 'em' || oldVal.unit === 'rem') && newVal.unit === 'px') { + const multiplier = oldVal.unit === 'em' ? fontSize.value.value : baseFontSize; + convertedValue = newVal.value * multiplier; + // Round to whole number for px + convertedValue = Math.round(convertedValue); + } + // Convert between em and rem + else if (oldVal.unit === 'em' && newVal.unit === 'rem') { + convertedValue = (newVal.value * fontSize.value.value) / baseFontSize; + // Round to 1 decimal place + convertedValue = Math.round(convertedValue * 10) / 10; + } + else if (oldVal.unit === 'rem' && newVal.unit === 'em') { + convertedValue = (newVal.value * baseFontSize) / fontSize.value.value; + // Round to 1 decimal place + convertedValue = Math.round(convertedValue * 10) / 10; + } + + // Clamp to valid range based on new unit + if (newVal.unit === 'em' || newVal.unit === 'rem') { + convertedValue = Math.max(0, Math.min(4, convertedValue)); + } else { + convertedValue = Math.max(0, Math.min(72, convertedValue)); + } + + // Update with converted value - create new object to trigger reactivity + lineHeight.value = { value: convertedValue, unit: newVal.unit }; + return; // Exit early to avoid double update + } + + debouncedUpdate(() => { + updateStyle('p', 'line-height', `${newVal.value}${newVal.unit}`); }); }, { deep: true }); @@ -257,6 +354,9 @@ const syncFromStore = () => { const fontSizeVal = extractNumericValue('p', 'font-size', ['px', 'em', 'rem']); if (fontSizeVal) fontSize.value = fontSizeVal; + const lineHeightVal = extractNumericValue('p', 'line-height', ['px', 'em', 'rem']); + if (lineHeightVal) lineHeight.value = lineHeightVal; + // Margins const margins = extractSpacing('p', 'margin'); if (margins) { diff --git a/src/components/ui/InputWithUnit.vue b/src/components/ui/InputWithUnit.vue index a87ae90..d6d1643 100644 --- a/src/components/ui/InputWithUnit.vue +++ b/src/components/ui/InputWithUnit.vue @@ -4,16 +4,16 @@ v-if="showRange" type="range" :value="modelValue.value" - :min="min" - :max="max" - :step="step" + :min="computedMin" + :max="computedMax" + :step="computedStep" @input="updateValue(Number($event.target.value))" /> @@ -27,6 +27,7 @@ diff --git a/src/components/ui/NumberInput.vue b/src/components/ui/NumberInput.vue index 9f4d3fd..6b670b3 100644 --- a/src/components/ui/NumberInput.vue +++ b/src/components/ui/NumberInput.vue @@ -2,7 +2,7 @@