diff --git a/src/components/editor/PageSettings.vue b/src/components/editor/PageSettings.vue index 6a1c187..6e5f4f5 100644 --- a/src/components/editor/PageSettings.vue +++ b/src/components/editor/PageSettings.vue @@ -1,231 +1,258 @@ @@ -308,15 +334,16 @@ let isUpdatingFromStore = false; const pageFormat = ref('A4'); const pageFormats = { - 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' }, + 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 }, }; -const pageWidth = computed(() => pageFormats[pageFormat.value].width); -const pageHeight = computed(() => pageFormats[pageFormat.value].height); +const customWidth = ref(210); +const customHeight = ref(297); +const isCustomFormat = computed(() => pageFormat.value === 'custom'); const margins = ref({ top: { value: 20, unit: 'mm' }, @@ -347,8 +374,36 @@ const immediateUpdate = (callback) => { watch(pageFormat, (newFormat) => { if (isUpdatingFromStore) return; - immediateUpdate(() => { - stylesheetStore.updateProperty('@page', 'size', newFormat, ''); + 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`, + '' + ); }); }); @@ -546,9 +601,24 @@ const syncFromStore = () => { try { const pageBlock = stylesheetStore.extractBlock('@page'); - const sizeMatch = pageBlock.match(/size:\s*([A-Za-z0-9]+)/); - if (sizeMatch) { - pageFormat.value = sizeMatch[1]; + // 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 marginMatch = pageBlock.match(