defaults values reglages script

This commit is contained in:
Julie Blanc 2026-03-08 20:15:45 +01:00
parent fc227bf519
commit 048a1b67e6
5 changed files with 81 additions and 38 deletions

View file

@ -31,20 +31,7 @@ figure, img{
} }
/* h1{ /* p.author{
font-size: 38px;
background: rgba(255, 255, 255, 0.521);
padding-top: 10px;
padding-left: 20px;
padding-bottom: 10px;
padding-right: 20px;
margin-left: 0px;
margin-right: 0px;
margin-bottom: 0px;
margin-top: 60px;
} */
p.author{
font-size: 24px; font-size: 24px;
font-weight: bold; font-weight: bold;
background: rgba(255, 255, 255, 0.521); background: rgba(255, 255, 255, 0.521);
@ -59,7 +46,7 @@ p.author{
padding: 10px 20px; padding: 10px 20px;
margin: 0; margin: 0;
margin-top: 60px; margin-top: 60px;
} } */
.figure-backgroung-cover img{ .figure-backgroung-cover img{
width: 100%; width: 100%;
height: 100%; height: 100%;
@ -77,7 +64,7 @@ p.author{
break-before: right; break-before: right;
} }
/*
h2{ h2{
font-size: 38px; font-size: 38px;
margin-top: 36px; margin-top: 36px;
@ -85,7 +72,7 @@ h2{
padding: 20px; padding: 20px;
break-after: avoid; break-after: avoid;
} }
*/
@ -94,36 +81,36 @@ h2{
*/ */
h3{ /* h3{
margin-top: 30px; margin-top: 30px;
break-after: avoid; break-after: avoid;
} } */
/* /*
CARTES CARTES
*/ */
h4{ /* h4{
break-after: avoid; break-after: avoid;
margin-top: 30px; margin-top: 30px;
text-decoration: underline; text-decoration: underline;
} } */
/* /*
MARKERS MARKERS
*/ */
/*
h5{ h5{
display: flex; display: flex;
align-items: center; align-items: center;
} }
.marker-title img{ .marker-title img{
width: 40px; width: 40px;
} } */

View file

@ -433,6 +433,8 @@ const getInstanceCount = (sel) => {
const open = (element, event, count = null) => { const open = (element, event, count = null) => {
elementInstanceCount.value = count !== null ? count : getInstanceCount(getSelectorFromElement(element)); elementInstanceCount.value = count !== null ? count : getInstanceCount(getSelectorFromElement(element));
marginLocked.value = false;
paddingLocked.value = false;
openSettings(element, event, { openSettings(element, event, {
getSelectorFromElement, getSelectorFromElement,
getInstanceCount, getInstanceCount,

View file

@ -234,6 +234,35 @@ export function useElementSettings({ margin, padding, basePopup }) {
} }
}; };
// --- Pre-toggle CSS snapshot ---
// Saves the CSS values for a group before toggle ON, restores them on toggle OFF
const preToggleSnapshots = new Map(); // key: `${selector}::${group}` → { cssProp: extractedValue }
const savePreToggleSnapshot = (group) => {
const key = `${selector.value}::${group}`;
const cssProps = settingGroups[group];
const snapshot = {};
for (const cssProp of cssProps) {
const val = stylesheetStore.extractValue(selector.value, cssProp);
if (val) snapshot[cssProp] = val;
}
preToggleSnapshots.set(key, snapshot);
};
const restorePreToggleSnapshot = (group) => {
const key = `${selector.value}::${group}`;
const snapshot = preToggleSnapshots.get(key);
if (!snapshot) return;
for (const [cssProp, val] of Object.entries(snapshot)) {
if (typeof val === 'object' && 'value' in val) {
updateProp(cssProp, val.value, val.unit);
} else {
updateProp(cssProp, val);
}
}
preToggleSnapshots.delete(key);
};
// --- Toggle actions --- // --- Toggle actions ---
const onSubsectionClick = (group) => { const onSubsectionClick = (group) => {
if (settingEnabled[group]) return; if (settingEnabled[group]) return;
@ -244,6 +273,7 @@ export function useElementSettings({ margin, padding, basePopup }) {
settingEnabled[group] = enabled; settingEnabled[group] = enabled;
isUpdatingFromStore = true; isUpdatingFromStore = true;
if (enabled) { if (enabled) {
savePreToggleSnapshot(group);
restoreFromCache(group); restoreFromCache(group);
applyAllEnabledGroups(); applyAllEnabledGroups();
} else { } else {
@ -254,6 +284,7 @@ export function useElementSettings({ margin, padding, basePopup }) {
} else { } else {
removeProps(settingGroups[group]); removeProps(settingGroups[group]);
} }
restorePreToggleSnapshot(group);
} }
saveElementState(); saveElementState();
nextTick(() => { isUpdatingFromStore = false; }); nextTick(() => { isUpdatingFromStore = false; });
@ -349,15 +380,13 @@ export function useElementSettings({ margin, padding, basePopup }) {
const comment = isTextDefault ? ' /* valeur par défaut */' : ''; const comment = isTextDefault ? ' /* valeur par défaut */' : '';
lines.push(` ${entry.css}: ${val};${comment}`); lines.push(` ${entry.css}: ${val};${comment}`);
} }
const showMargin = settingEnabled.margin || ['top', 'right', 'bottom', 'left'].some(s => hasInCss(`margin-${s}`)); for (const side of ['top', 'right', 'bottom', 'left']) {
if (showMargin) { if (settingEnabled.margin || hasInCss(`margin-${side}`)) {
for (const side of ['top', 'right', 'bottom', 'left']) {
lines.push(` margin-${side}: ${margin[side].value}${margin[side].unit};`); lines.push(` margin-${side}: ${margin[side].value}${margin[side].unit};`);
} }
} }
const showPadding = settingEnabled.padding || ['top', 'right', 'bottom', 'left'].some(s => hasInCss(`padding-${s}`)); for (const side of ['top', 'right', 'bottom', 'left']) {
if (showPadding) { if (settingEnabled.padding || hasInCss(`padding-${side}`)) {
for (const side of ['top', 'right', 'bottom', 'left']) {
lines.push(` padding-${side}: ${padding[side].value}${padding[side].unit};`); lines.push(` padding-${side}: ${padding[side].value}${padding[side].unit};`);
} }
} }

View file

@ -196,17 +196,41 @@ export const useStylesheetStore = defineStore('stylesheet', () => {
set('p', 'line-height', TEXT_DEFAULTS.lineHeight.value, TEXT_DEFAULTS.lineHeight.unit); set('p', 'line-height', TEXT_DEFAULTS.lineHeight.value, TEXT_DEFAULTS.lineHeight.unit);
// Heading defaults (h1, h2, ...) // Heading defaults (h1, h2, ...)
// Unit props: { value, unit } objects mapped to a CSS property
const unitPropsMap = {
fontSize: 'font-size',
lineHeight: 'line-height',
borderWidth: 'border-width',
textDecorationThickness: 'text-decoration-thickness',
textUnderlineOffset: 'text-underline-offset',
};
// String props: plain string values mapped to a CSS property
const stringPropsMap = {
background: 'background',
color: 'color',
fontFamily: 'font-family',
textAlign: 'text-align',
borderStyle: 'border-style',
borderColor: 'border-color',
textDecorationLine: 'text-decoration-line',
textDecorationStyle: 'text-decoration-style',
textDecorationColor: 'text-decoration-color',
};
// Spacing props: objects with top/right/bottom/left sides
const spacingProps = ['padding', 'margin'];
for (const [tag, props] of Object.entries(HEADING_DEFAULTS)) { for (const [tag, props] of Object.entries(HEADING_DEFAULTS)) {
if (props.fontSize) set(tag, 'font-size', props.fontSize.value, props.fontSize.unit); for (const [key, cssProp] of Object.entries(unitPropsMap)) {
if (props.background) set(tag, 'background', props.background); if (props[key]) set(tag, cssProp, props[key].value, props[key].unit);
if (props.padding) {
for (const side of ['top', 'right', 'bottom', 'left']) {
if (props.padding[side]) set(tag, `padding-${side}`, props.padding[side].value, props.padding[side].unit);
}
} }
if (props.margin) { for (const [key, cssProp] of Object.entries(stringPropsMap)) {
for (const side of ['top', 'right', 'bottom', 'left']) { if (props[key]) set(tag, cssProp, props[key]);
if (props.margin[side]) set(tag, `margin-${side}`, props.margin[side].value, props.margin[side].unit); }
for (const prop of spacingProps) {
if (props[prop]) {
for (const side of ['top', 'right', 'bottom', 'left']) {
if (props[prop][side]) set(tag, `${prop}-${side}`, props[prop][side].value, props[prop][side].unit);
}
} }
} }
} }

View file

@ -56,6 +56,7 @@ export const HEADING_DEFAULTS = Object.freeze({
}), }),
margin: Object.freeze({ margin: Object.freeze({
top: Object.freeze({ value: 60, unit: 'px' }), top: Object.freeze({ value: 60, unit: 'px' }),
bottom: Object.freeze({ value: 30, unit: 'px' }),
}), }),
}), }),
}); });