fix: sync PagePopup values with PageSettings from @page block
Use the same regex parsing logic as PageSettings to extract margin and background values from the @page CSS block. This ensures PagePopup displays the correct inherited values when the inheritance is locked. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
7647aadb63
commit
ed856972bc
3 changed files with 34 additions and 35 deletions
|
|
@ -312,10 +312,10 @@ let isUpdatingFromStore = false;
|
|||
let updateTimer = null;
|
||||
|
||||
const margins = ref({
|
||||
top: { value: 6, unit: 'mm' },
|
||||
bottom: { value: 7, unit: 'mm' },
|
||||
left: { value: 6, unit: 'mm' },
|
||||
right: { value: 7, unit: 'mm' },
|
||||
top: { value: 0, unit: 'mm' },
|
||||
bottom: { value: 0, unit: 'mm' },
|
||||
left: { value: 0, unit: 'mm' },
|
||||
right: { value: 0, unit: 'mm' },
|
||||
});
|
||||
|
||||
const background = ref({
|
||||
|
|
@ -424,39 +424,37 @@ const loadValuesFromStylesheet = () => {
|
|||
try {
|
||||
isUpdatingFromStore = true;
|
||||
|
||||
// Extract margin from @page
|
||||
const marginData = stylesheetStore.extractValue('@page', 'margin');
|
||||
if (marginData) {
|
||||
// Parse margin shorthand (top right bottom left)
|
||||
const marginStr = typeof marginData === 'string' ? marginData : marginData.value;
|
||||
const marginValues = marginStr.split(' ');
|
||||
// Extract values from @page block (same logic as PageSettings)
|
||||
const pageBlock = stylesheetStore.extractBlock('@page');
|
||||
if (!pageBlock) return;
|
||||
|
||||
if (marginValues.length === 4) {
|
||||
// Parse each margin value
|
||||
const parseMargin = (value) => {
|
||||
const match = value.match(/^([\d.]+)(\w+)$/);
|
||||
if (match) {
|
||||
return { value: parseFloat(match[1]), unit: match[2] };
|
||||
}
|
||||
return { value: 0, unit: 'mm' };
|
||||
};
|
||||
|
||||
const top = parseMargin(marginValues[0]);
|
||||
const right = parseMargin(marginValues[1]);
|
||||
const bottom = parseMargin(marginValues[2]);
|
||||
const left = parseMargin(marginValues[3]);
|
||||
|
||||
margins.value.top = top;
|
||||
margins.value.right = right;
|
||||
margins.value.bottom = bottom;
|
||||
margins.value.left = left;
|
||||
}
|
||||
// Parse margins with regex (top right bottom left)
|
||||
const marginMatch = pageBlock.match(
|
||||
/margin:\s*([0-9.]+)([a-z]+)\s+([0-9.]+)([a-z]+)\s+([0-9.]+)([a-z]+)\s+([0-9.]+)([a-z]+)/i
|
||||
);
|
||||
if (marginMatch) {
|
||||
margins.value.top = {
|
||||
value: parseFloat(marginMatch[1]),
|
||||
unit: marginMatch[2],
|
||||
};
|
||||
margins.value.right = {
|
||||
value: parseFloat(marginMatch[3]),
|
||||
unit: marginMatch[4],
|
||||
};
|
||||
margins.value.bottom = {
|
||||
value: parseFloat(marginMatch[5]),
|
||||
unit: marginMatch[6],
|
||||
};
|
||||
margins.value.left = {
|
||||
value: parseFloat(marginMatch[7]),
|
||||
unit: marginMatch[8],
|
||||
};
|
||||
}
|
||||
|
||||
// Extract background from @page
|
||||
const backgroundData = stylesheetStore.extractValue('@page', 'background');
|
||||
if (backgroundData) {
|
||||
background.value.value = typeof backgroundData === 'string' ? backgroundData : backgroundData.value;
|
||||
// Extract background
|
||||
const bgMatch = pageBlock.match(/background:\s*([^;]+)/);
|
||||
if (bgMatch) {
|
||||
background.value.value = bgMatch[1].trim();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading values from stylesheet:', error);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue