diff --git a/src/components/editor/PageSettings.vue b/src/components/editor/PageSettings.vue index 6e5f4f5..6a1c187 100644 --- a/src/components/editor/PageSettings.vue +++ b/src/components/editor/PageSettings.vue @@ -1,258 +1,231 @@ @@ -334,16 +308,15 @@ let isUpdatingFromStore = false; const pageFormat = ref('A4'); const pageFormats = { - A4: { width: 210, height: 297 }, - A5: { width: 148, height: 210 }, - // A3: { width: 297, height: 420 }, - // letter: { width: 216, height: 279 }, - // legal: { width: 216, height: 356 }, + A4: { width: '210mm', height: '297mm' }, + A5: { width: '148mm', height: '210mm' }, + A3: { width: '297mm', height: '420mm' }, + letter: { width: '8.5in', height: '11in' }, + legal: { width: '8.5in', height: '14in' }, }; -const customWidth = ref(210); -const customHeight = ref(297); -const isCustomFormat = computed(() => pageFormat.value === 'custom'); +const pageWidth = computed(() => pageFormats[pageFormat.value].width); +const pageHeight = computed(() => pageFormats[pageFormat.value].height); const margins = ref({ top: { value: 20, unit: 'mm' }, @@ -374,36 +347,8 @@ const immediateUpdate = (callback) => { watch(pageFormat, (newFormat) => { if (isUpdatingFromStore) return; - if (newFormat === 'custom') { - immediateUpdate(() => { - stylesheetStore.updateProperty( - '@page', - 'size', - `${customWidth.value}mm ${customHeight.value}mm`, - '' - ); - }); - } else { - const format = pageFormats[newFormat]; - if (format) { - customWidth.value = format.width; - customHeight.value = format.height; - } - immediateUpdate(() => { - stylesheetStore.updateProperty('@page', 'size', newFormat, ''); - }); - } -}); - -watch([customWidth, customHeight], () => { - if (isUpdatingFromStore || !isCustomFormat.value) return; - debouncedUpdate(() => { - stylesheetStore.updateProperty( - '@page', - 'size', - `${customWidth.value}mm ${customHeight.value}mm`, - '' - ); + immediateUpdate(() => { + stylesheetStore.updateProperty('@page', 'size', newFormat, ''); }); }); @@ -601,24 +546,9 @@ const syncFromStore = () => { try { const pageBlock = stylesheetStore.extractBlock('@page'); - // Try named format first (A4, A5), then custom dimensions - const namedSizeMatch = pageBlock.match(/size:\s*(A4|A5)\b/); - if (namedSizeMatch) { - pageFormat.value = namedSizeMatch[1]; - const format = pageFormats[namedSizeMatch[1]]; - if (format) { - customWidth.value = format.width; - customHeight.value = format.height; - } - } else { - const customSizeMatch = pageBlock.match( - /size:\s*([0-9.]+)mm\s+([0-9.]+)mm/ - ); - if (customSizeMatch) { - customWidth.value = parseFloat(customSizeMatch[1]); - customHeight.value = parseFloat(customSizeMatch[2]); - pageFormat.value = 'custom'; - } + const sizeMatch = pageBlock.match(/size:\s*([A-Za-z0-9]+)/); + if (sizeMatch) { + pageFormat.value = sizeMatch[1]; } const marginMatch = pageBlock.match( diff --git a/src/components/editor/TextSettings.vue b/src/components/editor/TextSettings.vue index 536f6aa..8df45ab 100644 --- a/src/components/editor/TextSettings.vue +++ b/src/components/editor/TextSettings.vue @@ -483,7 +483,7 @@ watch(color, (val) => { watch(background, (val) => { if (isUpdatingFromStore) return; - updateStyle('p', 'background', val); + updateStyle('body', 'background', val); }); // Watchers for paragraph styles @@ -668,7 +668,7 @@ const syncFromStore = () => { const colorVal = extractValue('body', 'color'); if (colorVal) color.value = colorVal; - const bgVal = extractValue('p', 'background'); + const bgVal = extractValue('body', 'background'); if (bgVal) background.value = bgVal; // Paragraph styles