2025-12-05 17:32:39 +01:00
|
|
|
|
<template>
|
|
|
|
|
|
<div
|
|
|
|
|
|
v-if="visible"
|
|
|
|
|
|
id="page-popup"
|
2025-12-08 16:17:34 +01:00
|
|
|
|
class="settings-popup"
|
2025-12-05 17:32:39 +01:00
|
|
|
|
:style="{ top: position.y + 'px', left: position.x + 'px' }"
|
|
|
|
|
|
>
|
|
|
|
|
|
<div class="popup-header">
|
2025-12-05 17:39:51 +01:00
|
|
|
|
<div class="header-left">
|
|
|
|
|
|
<span class="page-label">@page</span>
|
2025-12-08 12:38:16 +01:00
|
|
|
|
<span class="page-name">{{ templateName || 'default' }}</span>
|
2025-12-08 12:29:55 +01:00
|
|
|
|
<span class="page-count">{{ pageCount }} page{{ pageCount > 1 ? 's' : '' }}</span>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
</div>
|
2025-12-05 17:32:39 +01:00
|
|
|
|
<button class="close-btn" @click="close">×</button>
|
|
|
|
|
|
</div>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
|
2025-12-05 17:32:39 +01:00
|
|
|
|
<div class="popup-body">
|
2025-12-05 17:39:51 +01:00
|
|
|
|
<!-- Left: Controls -->
|
2025-12-05 17:32:39 +01:00
|
|
|
|
<div class="popup-controls">
|
2025-12-05 17:39:51 +01:00
|
|
|
|
<!-- Margins -->
|
2025-12-05 17:46:38 +01:00
|
|
|
|
<div class="settings-subsection">
|
2025-12-05 17:39:51 +01:00
|
|
|
|
<h4>Marges</h4>
|
|
|
|
|
|
<div class="margin-grid">
|
2025-12-05 18:21:54 +01:00
|
|
|
|
<div
|
|
|
|
|
|
class="field"
|
|
|
|
|
|
:class="{ 'field--view-only': inheritanceLocked }"
|
|
|
|
|
|
>
|
|
|
|
|
|
<label class="label-with-tooltip" data-css="margin-top">Haut</label>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
<div class="input-with-unit">
|
2025-12-09 17:08:40 +01:00
|
|
|
|
<NumberInput
|
|
|
|
|
|
v-model="margins.top.value"
|
|
|
|
|
|
:min="0"
|
|
|
|
|
|
:step="1"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:39:51 +01:00
|
|
|
|
/>
|
|
|
|
|
|
<div class="unit-toggle">
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
:class="{ active: margins.top.unit === 'mm' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:39:51 +01:00
|
|
|
|
@click="margins.top.unit = 'mm'"
|
|
|
|
|
|
>
|
|
|
|
|
|
mm
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
:class="{ active: margins.top.unit === 'px' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:39:51 +01:00
|
|
|
|
@click="margins.top.unit = 'px'"
|
|
|
|
|
|
>
|
|
|
|
|
|
px
|
|
|
|
|
|
</button>
|
2025-12-05 17:43:58 +01:00
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
:class="{ active: margins.top.unit === 'rem' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:43:58 +01:00
|
|
|
|
@click="margins.top.unit = 'rem'"
|
|
|
|
|
|
>
|
|
|
|
|
|
rem
|
|
|
|
|
|
</button>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-12-05 18:21:54 +01:00
|
|
|
|
<div
|
|
|
|
|
|
class="field"
|
|
|
|
|
|
:class="{ 'field--view-only': inheritanceLocked }"
|
|
|
|
|
|
>
|
|
|
|
|
|
<label class="label-with-tooltip" data-css="margin-bottom">Bas</label>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
<div class="input-with-unit">
|
2025-12-09 17:08:40 +01:00
|
|
|
|
<NumberInput
|
|
|
|
|
|
v-model="margins.bottom.value"
|
|
|
|
|
|
:min="0"
|
|
|
|
|
|
:step="1"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:39:51 +01:00
|
|
|
|
/>
|
|
|
|
|
|
<div class="unit-toggle">
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
:class="{ active: margins.bottom.unit === 'mm' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:39:51 +01:00
|
|
|
|
@click="margins.bottom.unit = 'mm'"
|
|
|
|
|
|
>
|
|
|
|
|
|
mm
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
:class="{ active: margins.bottom.unit === 'px' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:39:51 +01:00
|
|
|
|
@click="margins.bottom.unit = 'px'"
|
|
|
|
|
|
>
|
|
|
|
|
|
px
|
|
|
|
|
|
</button>
|
2025-12-05 17:43:58 +01:00
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
:class="{ active: margins.bottom.unit === 'rem' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:43:58 +01:00
|
|
|
|
@click="margins.bottom.unit = 'rem'"
|
|
|
|
|
|
>
|
|
|
|
|
|
rem
|
|
|
|
|
|
</button>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-12-05 18:21:54 +01:00
|
|
|
|
<div
|
|
|
|
|
|
class="field"
|
|
|
|
|
|
:class="{ 'field--view-only': inheritanceLocked }"
|
|
|
|
|
|
>
|
|
|
|
|
|
<label class="label-with-tooltip" data-css="margin-left">Gauche</label>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
<div class="input-with-unit">
|
2025-12-09 17:08:40 +01:00
|
|
|
|
<NumberInput
|
|
|
|
|
|
v-model="margins.left.value"
|
|
|
|
|
|
:min="0"
|
|
|
|
|
|
:step="1"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:39:51 +01:00
|
|
|
|
/>
|
|
|
|
|
|
<div class="unit-toggle">
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
:class="{ active: margins.left.unit === 'mm' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:39:51 +01:00
|
|
|
|
@click="margins.left.unit = 'mm'"
|
|
|
|
|
|
>
|
|
|
|
|
|
mm
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
:class="{ active: margins.left.unit === 'px' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:39:51 +01:00
|
|
|
|
@click="margins.left.unit = 'px'"
|
|
|
|
|
|
>
|
|
|
|
|
|
px
|
|
|
|
|
|
</button>
|
2025-12-05 17:43:58 +01:00
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
:class="{ active: margins.left.unit === 'rem' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:43:58 +01:00
|
|
|
|
@click="margins.left.unit = 'rem'"
|
|
|
|
|
|
>
|
|
|
|
|
|
rem
|
|
|
|
|
|
</button>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-12-05 18:21:54 +01:00
|
|
|
|
<div
|
|
|
|
|
|
class="field"
|
|
|
|
|
|
:class="{ 'field--view-only': inheritanceLocked }"
|
|
|
|
|
|
>
|
|
|
|
|
|
<label class="label-with-tooltip" data-css="margin-right">Droite</label>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
<div class="input-with-unit">
|
2025-12-09 17:08:40 +01:00
|
|
|
|
<NumberInput
|
|
|
|
|
|
v-model="margins.right.value"
|
|
|
|
|
|
:min="0"
|
|
|
|
|
|
:step="1"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:39:51 +01:00
|
|
|
|
/>
|
|
|
|
|
|
<div class="unit-toggle">
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
:class="{ active: margins.right.unit === 'mm' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:39:51 +01:00
|
|
|
|
@click="margins.right.unit = 'mm'"
|
|
|
|
|
|
>
|
|
|
|
|
|
mm
|
|
|
|
|
|
</button>
|
|
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
:class="{ active: margins.right.unit === 'px' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:39:51 +01:00
|
|
|
|
@click="margins.right.unit = 'px'"
|
|
|
|
|
|
>
|
|
|
|
|
|
px
|
|
|
|
|
|
</button>
|
2025-12-05 17:43:58 +01:00
|
|
|
|
<button
|
|
|
|
|
|
type="button"
|
|
|
|
|
|
:class="{ active: margins.right.unit === 'rem' }"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:43:58 +01:00
|
|
|
|
@click="margins.right.unit = 'rem'"
|
|
|
|
|
|
>
|
|
|
|
|
|
rem
|
|
|
|
|
|
</button>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Background -->
|
2025-12-05 17:46:38 +01:00
|
|
|
|
<div class="settings-subsection">
|
2025-12-05 18:21:54 +01:00
|
|
|
|
<div class="field" :class="{ 'field--view-only': inheritanceLocked }">
|
|
|
|
|
|
<label class="label-with-tooltip" data-css="background">Arrière-plan</label>
|
2025-12-05 17:46:38 +01:00
|
|
|
|
<div class="input-with-color">
|
|
|
|
|
|
<input
|
|
|
|
|
|
ref="backgroundColorInput"
|
|
|
|
|
|
type="text"
|
|
|
|
|
|
v-model="background.value"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:46:38 +01:00
|
|
|
|
data-coloris
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- Patterns -->
|
2025-12-05 17:46:38 +01:00
|
|
|
|
<div class="settings-subsection">
|
2025-12-05 18:21:54 +01:00
|
|
|
|
<div class="field" :class="{ 'field--view-only': inheritanceLocked }">
|
|
|
|
|
|
<label class="label-with-tooltip" data-css="background-image">Motifs</label>
|
|
|
|
|
|
<select v-model="pattern" :disabled="inheritanceLocked">
|
2025-12-05 17:46:38 +01:00
|
|
|
|
<option value="">Choisissez</option>
|
|
|
|
|
|
<option value="dots">Points</option>
|
|
|
|
|
|
<option value="lines">Lignes</option>
|
|
|
|
|
|
<option value="grid">Grille</option>
|
|
|
|
|
|
</select>
|
|
|
|
|
|
</div>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
</div>
|
|
|
|
|
|
|
2025-12-05 17:51:09 +01:00
|
|
|
|
<!-- Lock/Unlock Inheritance Button -->
|
2025-12-05 17:46:38 +01:00
|
|
|
|
<div class="settings-subsection">
|
2025-12-05 17:51:09 +01:00
|
|
|
|
<button class="inheritance-btn" @click="toggleInheritance">
|
2025-12-05 18:21:54 +01:00
|
|
|
|
<svg
|
|
|
|
|
|
v-if="inheritanceLocked"
|
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
|
fill="currentColor"
|
|
|
|
|
|
>
|
|
|
|
|
|
<path
|
|
|
|
|
|
d="M19 10H20C20.5523 10 21 10.4477 21 11V21C21 21.5523 20.5523 22 20 22H4C3.44772 22 3 21.5523 3 21V11C3 10.4477 3.44772 10 4 10H5V9C5 5.13401 8.13401 2 12 2C15.866 2 19 5.13401 19 9V10ZM5 12V20H19V12H5ZM11 14H13V18H11V14ZM17 10V9C17 6.23858 14.7614 4 12 4C9.23858 4 7 6.23858 7 9V10H17Z"
|
|
|
|
|
|
></path>
|
2025-12-05 17:51:09 +01:00
|
|
|
|
</svg>
|
2025-12-05 18:21:54 +01:00
|
|
|
|
<svg
|
|
|
|
|
|
v-else
|
|
|
|
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
|
fill="currentColor"
|
|
|
|
|
|
>
|
|
|
|
|
|
<path
|
|
|
|
|
|
d="M7 10H20C20.5523 10 21 10.4477 21 11V21C21 21.5523 20.5523 22 20 22H4C3.44772 22 3 21.5523 3 21V11C3 10.4477 3.44772 10 4 10H5V9C5 5.13401 8.13401 2 12 2C14.7405 2 17.1131 3.5748 18.2624 5.86882L16.4731 6.76344C15.6522 5.12486 13.9575 4 12 4C9.23858 4 7 6.23858 7 9V10ZM5 12V20H19V12H5ZM10 15H14V17H10V15Z"
|
|
|
|
|
|
></path>
|
2025-12-05 17:51:09 +01:00
|
|
|
|
</svg>
|
2025-12-05 18:21:54 +01:00
|
|
|
|
<span>{{
|
|
|
|
|
|
inheritanceLocked
|
|
|
|
|
|
? "Déverrouiller l'héritage"
|
|
|
|
|
|
: "Verrouiller l'héritage"
|
|
|
|
|
|
}}</span>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
2025-12-05 17:32:39 +01:00
|
|
|
|
</div>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
|
|
|
|
|
|
<!-- Right: CSS Editor -->
|
2025-12-05 17:32:39 +01:00
|
|
|
|
<div class="popup-css">
|
2025-12-05 17:39:51 +01:00
|
|
|
|
<div class="css-header">
|
|
|
|
|
|
<span>CSS</span>
|
2025-12-05 18:21:54 +01:00
|
|
|
|
<label
|
|
|
|
|
|
class="toggle"
|
|
|
|
|
|
:class="{ 'field--view-only': inheritanceLocked }"
|
|
|
|
|
|
>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
<span class="toggle-label">Mode édition</span>
|
2025-12-05 18:21:54 +01:00
|
|
|
|
<input
|
|
|
|
|
|
type="checkbox"
|
|
|
|
|
|
v-model="isEditable"
|
|
|
|
|
|
:disabled="inheritanceLocked"
|
|
|
|
|
|
/>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
<span class="toggle-switch"></span>
|
|
|
|
|
|
</label>
|
|
|
|
|
|
</div>
|
2025-12-05 18:21:54 +01:00
|
|
|
|
<pre
|
|
|
|
|
|
v-if="!isEditable"
|
|
|
|
|
|
class="readonly"
|
|
|
|
|
|
><code class="hljs language-css" v-html="highlightedCss"></code></pre>
|
2025-12-05 17:32:39 +01:00
|
|
|
|
<textarea
|
2025-12-05 17:39:51 +01:00
|
|
|
|
v-else
|
2025-12-05 17:32:39 +01:00
|
|
|
|
:value="pageCss"
|
|
|
|
|
|
@input="handleCssInput"
|
2025-12-05 18:21:54 +01:00
|
|
|
|
:disabled="inheritanceLocked"
|
2025-12-05 17:32:39 +01:00
|
|
|
|
spellcheck="false"
|
|
|
|
|
|
></textarea>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-12-05 17:39:51 +01:00
|
|
|
|
import { ref, computed, watch, onMounted } from 'vue';
|
2025-12-05 17:32:39 +01:00
|
|
|
|
import { useStylesheetStore } from '../stores/stylesheet';
|
2025-12-05 18:21:54 +01:00
|
|
|
|
import { usePopupPosition } from '../composables/usePopupPosition';
|
2025-12-10 11:51:53 +01:00
|
|
|
|
import { useDebounce } from '../composables/useDebounce';
|
2025-12-09 17:08:40 +01:00
|
|
|
|
import NumberInput from './ui/NumberInput.vue';
|
2025-12-05 17:39:51 +01:00
|
|
|
|
import Coloris from '@melloware/coloris';
|
2025-12-05 17:43:58 +01:00
|
|
|
|
import '@melloware/coloris/dist/coloris.css';
|
|
|
|
|
|
import hljs from 'highlight.js/lib/core';
|
|
|
|
|
|
import css from 'highlight.js/lib/languages/css';
|
|
|
|
|
|
import 'highlight.js/styles/atom-one-dark.css';
|
|
|
|
|
|
|
|
|
|
|
|
hljs.registerLanguage('css', css);
|
2025-12-05 17:32:39 +01:00
|
|
|
|
|
|
|
|
|
|
const stylesheetStore = useStylesheetStore();
|
|
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
|
iframeRef: Object,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-08 12:29:55 +01:00
|
|
|
|
const emit = defineEmits(['close']);
|
|
|
|
|
|
|
2025-12-05 17:32:39 +01:00
|
|
|
|
const visible = ref(false);
|
|
|
|
|
|
const position = ref({ x: 0, y: 0 });
|
|
|
|
|
|
const selectedPageElement = ref(null);
|
2025-12-08 12:29:55 +01:00
|
|
|
|
const pageCount = ref(0);
|
2025-12-08 12:38:16 +01:00
|
|
|
|
const templateName = ref('');
|
2025-12-05 17:39:51 +01:00
|
|
|
|
const isEditable = ref(false);
|
2025-12-05 17:51:09 +01:00
|
|
|
|
const inheritanceLocked = ref(true);
|
2025-12-05 17:43:58 +01:00
|
|
|
|
const backgroundColorInput = ref(null);
|
|
|
|
|
|
|
|
|
|
|
|
let isUpdatingFromStore = false;
|
2025-12-10 11:51:53 +01:00
|
|
|
|
const { debouncedUpdate } = useDebounce(500);
|
2025-12-05 17:39:51 +01:00
|
|
|
|
|
|
|
|
|
|
const margins = ref({
|
2025-12-08 12:33:55 +01:00
|
|
|
|
top: { value: 0, unit: 'mm' },
|
|
|
|
|
|
bottom: { value: 0, unit: 'mm' },
|
|
|
|
|
|
left: { value: 0, unit: 'mm' },
|
|
|
|
|
|
right: { value: 0, unit: 'mm' },
|
2025-12-05 17:39:51 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-05 17:43:58 +01:00
|
|
|
|
const background = ref({
|
|
|
|
|
|
value: '',
|
|
|
|
|
|
format: 'hex',
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-05 17:39:51 +01:00
|
|
|
|
const pattern = ref('');
|
2025-12-05 17:32:39 +01:00
|
|
|
|
|
2025-12-05 17:43:58 +01:00
|
|
|
|
const immediateUpdate = (callback) => {
|
|
|
|
|
|
callback();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-12-05 18:21:54 +01:00
|
|
|
|
const POPUP_WIDTH = 550;
|
|
|
|
|
|
const POPUP_HEIGHT = 600;
|
|
|
|
|
|
|
|
|
|
|
|
const { calculatePosition } = usePopupPosition(POPUP_WIDTH, POPUP_HEIGHT);
|
2025-12-05 17:32:39 +01:00
|
|
|
|
|
2025-12-08 12:38:16 +01:00
|
|
|
|
// Get the selector for the current template's @page rule
|
|
|
|
|
|
const getTemplateSelector = () => {
|
|
|
|
|
|
return templateName.value ? `@page ${templateName.value}` : '@page';
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Get or create the template-specific @page block
|
|
|
|
|
|
const getOrCreateTemplateBlock = () => {
|
|
|
|
|
|
const selector = getTemplateSelector();
|
|
|
|
|
|
let block = stylesheetStore.extractBlock(selector);
|
|
|
|
|
|
|
|
|
|
|
|
if (!block && templateName.value) {
|
|
|
|
|
|
// Create new block with current values from @page
|
|
|
|
|
|
const baseBlock = stylesheetStore.extractBlock('@page');
|
|
|
|
|
|
if (baseBlock) {
|
|
|
|
|
|
// Insert the new template block after @page
|
|
|
|
|
|
const marginValue = `${margins.value.top.value}${margins.value.top.unit} ${margins.value.right.value}${margins.value.right.unit} ${margins.value.bottom.value}${margins.value.bottom.unit} ${margins.value.left.value}${margins.value.left.unit}`;
|
|
|
|
|
|
const newBlock = `\n@page ${templateName.value} {\n margin: ${marginValue};${background.value.value ? `\n background: ${background.value.value};` : ''}\n}\n`;
|
|
|
|
|
|
|
|
|
|
|
|
stylesheetStore.content = stylesheetStore.content.replace(
|
|
|
|
|
|
baseBlock,
|
|
|
|
|
|
baseBlock + newBlock
|
|
|
|
|
|
);
|
|
|
|
|
|
block = stylesheetStore.extractBlock(selector);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return block;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Remove the template-specific @page block
|
|
|
|
|
|
const removeTemplateBlock = () => {
|
|
|
|
|
|
if (!templateName.value) return;
|
|
|
|
|
|
|
|
|
|
|
|
const selector = `@page ${templateName.value}`;
|
|
|
|
|
|
const block = stylesheetStore.extractBlock(selector);
|
|
|
|
|
|
|
|
|
|
|
|
if (block) {
|
|
|
|
|
|
// Remove the block and any surrounding whitespace
|
|
|
|
|
|
stylesheetStore.content = stylesheetStore.content.replace(
|
|
|
|
|
|
new RegExp(`\\n?${selector.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\s*\\{[^}]*\\}\\n?`),
|
|
|
|
|
|
'\n'
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-12-05 17:43:58 +01:00
|
|
|
|
const updateMargins = () => {
|
2025-12-08 12:38:16 +01:00
|
|
|
|
// Only update if inheritance is unlocked
|
|
|
|
|
|
if (inheritanceLocked.value) return;
|
|
|
|
|
|
|
2025-12-05 17:43:58 +01:00
|
|
|
|
const marginValue = `${margins.value.top.value}${margins.value.top.unit} ${margins.value.right.value}${margins.value.right.unit} ${margins.value.bottom.value}${margins.value.bottom.unit} ${margins.value.left.value}${margins.value.left.unit}`;
|
|
|
|
|
|
|
2025-12-08 12:38:16 +01:00
|
|
|
|
const currentBlock = getOrCreateTemplateBlock();
|
2025-12-05 17:43:58 +01:00
|
|
|
|
if (!currentBlock) return;
|
|
|
|
|
|
|
2025-12-08 12:38:16 +01:00
|
|
|
|
const selector = getTemplateSelector();
|
2025-12-05 17:43:58 +01:00
|
|
|
|
|
2025-12-08 12:38:16 +01:00
|
|
|
|
if (currentBlock.includes('margin:')) {
|
|
|
|
|
|
const updatedBlock = currentBlock.replace(
|
|
|
|
|
|
/(margin:\s*)[^;]+/,
|
|
|
|
|
|
`$1${marginValue}`
|
|
|
|
|
|
);
|
|
|
|
|
|
stylesheetStore.content = stylesheetStore.content.replace(
|
|
|
|
|
|
currentBlock,
|
|
|
|
|
|
updatedBlock
|
|
|
|
|
|
);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const updatedBlock = currentBlock.replace(
|
|
|
|
|
|
/(\s*})$/,
|
|
|
|
|
|
` margin: ${marginValue};\n$1`
|
|
|
|
|
|
);
|
|
|
|
|
|
stylesheetStore.content = stylesheetStore.content.replace(
|
|
|
|
|
|
currentBlock,
|
|
|
|
|
|
updatedBlock
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2025-12-05 17:43:58 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const updateBackground = () => {
|
2025-12-08 12:38:16 +01:00
|
|
|
|
// Only update if inheritance is unlocked
|
|
|
|
|
|
if (inheritanceLocked.value) return;
|
2025-12-05 17:43:58 +01:00
|
|
|
|
if (!background.value.value) return;
|
|
|
|
|
|
|
2025-12-08 12:38:16 +01:00
|
|
|
|
const currentBlock = getOrCreateTemplateBlock();
|
2025-12-05 17:43:58 +01:00
|
|
|
|
if (!currentBlock) return;
|
|
|
|
|
|
|
|
|
|
|
|
if (currentBlock.includes('background:')) {
|
|
|
|
|
|
const updatedBlock = currentBlock.replace(
|
|
|
|
|
|
/(background:\s*)[^;]+/,
|
|
|
|
|
|
`$1${background.value.value}`
|
|
|
|
|
|
);
|
|
|
|
|
|
stylesheetStore.content = stylesheetStore.content.replace(
|
|
|
|
|
|
currentBlock,
|
|
|
|
|
|
updatedBlock
|
|
|
|
|
|
);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
const updatedBlock = currentBlock.replace(
|
|
|
|
|
|
/(\s*})$/,
|
|
|
|
|
|
` background: ${background.value.value};\n$1`
|
|
|
|
|
|
);
|
|
|
|
|
|
stylesheetStore.content = stylesheetStore.content.replace(
|
|
|
|
|
|
currentBlock,
|
|
|
|
|
|
updatedBlock
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Watch margin values (number inputs) with debounce
|
|
|
|
|
|
watch(
|
|
|
|
|
|
() => [
|
|
|
|
|
|
margins.value.top.value,
|
|
|
|
|
|
margins.value.bottom.value,
|
|
|
|
|
|
margins.value.left.value,
|
|
|
|
|
|
margins.value.right.value,
|
|
|
|
|
|
],
|
|
|
|
|
|
() => {
|
|
|
|
|
|
if (isUpdatingFromStore) return;
|
|
|
|
|
|
debouncedUpdate(updateMargins);
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// Watch margin units (button clicks) without debounce
|
|
|
|
|
|
watch(
|
|
|
|
|
|
() => [
|
|
|
|
|
|
margins.value.top.unit,
|
|
|
|
|
|
margins.value.bottom.unit,
|
|
|
|
|
|
margins.value.left.unit,
|
|
|
|
|
|
margins.value.right.unit,
|
|
|
|
|
|
],
|
|
|
|
|
|
() => {
|
|
|
|
|
|
if (isUpdatingFromStore) return;
|
|
|
|
|
|
immediateUpdate(updateMargins);
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
// Watch background value with debounce
|
|
|
|
|
|
watch(
|
|
|
|
|
|
() => background.value.value,
|
|
|
|
|
|
() => {
|
|
|
|
|
|
if (isUpdatingFromStore) return;
|
|
|
|
|
|
debouncedUpdate(updateBackground);
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2025-12-05 18:21:54 +01:00
|
|
|
|
const loadValuesFromStylesheet = () => {
|
|
|
|
|
|
try {
|
|
|
|
|
|
isUpdatingFromStore = true;
|
|
|
|
|
|
|
2025-12-08 12:33:55 +01:00
|
|
|
|
// Extract values from @page block (same logic as PageSettings)
|
|
|
|
|
|
const pageBlock = stylesheetStore.extractBlock('@page');
|
|
|
|
|
|
if (!pageBlock) return;
|
|
|
|
|
|
|
|
|
|
|
|
// 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],
|
|
|
|
|
|
};
|
2025-12-05 18:21:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-08 12:33:55 +01:00
|
|
|
|
// Extract background
|
|
|
|
|
|
const bgMatch = pageBlock.match(/background:\s*([^;]+)/);
|
|
|
|
|
|
if (bgMatch) {
|
|
|
|
|
|
background.value.value = bgMatch[1].trim();
|
2025-12-05 18:21:54 +01:00
|
|
|
|
}
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Error loading values from stylesheet:', error);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
isUpdatingFromStore = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-12-08 12:29:55 +01:00
|
|
|
|
const open = (pageElement, event, count = 1) => {
|
2025-12-05 17:32:39 +01:00
|
|
|
|
selectedPageElement.value = pageElement;
|
2025-12-08 12:29:55 +01:00
|
|
|
|
pageCount.value = count;
|
2025-12-05 18:21:54 +01:00
|
|
|
|
position.value = calculatePosition(event);
|
2025-12-05 17:32:39 +01:00
|
|
|
|
|
2025-12-08 12:38:16 +01:00
|
|
|
|
// Extract template name from data-page-type attribute
|
|
|
|
|
|
templateName.value = pageElement.getAttribute('data-page-type') || '';
|
|
|
|
|
|
|
2025-12-10 12:04:58 +01:00
|
|
|
|
// Read inheritance state from page element's data attribute
|
|
|
|
|
|
inheritanceLocked.value = pageElement.dataset.inheritanceUnlocked !== 'true';
|
2025-12-08 12:38:16 +01:00
|
|
|
|
|
|
|
|
|
|
// Load values from stylesheet (@page block)
|
2025-12-05 18:21:54 +01:00
|
|
|
|
loadValuesFromStylesheet();
|
|
|
|
|
|
|
2025-12-05 17:32:39 +01:00
|
|
|
|
visible.value = true;
|
2025-12-05 17:39:51 +01:00
|
|
|
|
|
|
|
|
|
|
// Initialize Coloris after opening
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
Coloris.init();
|
|
|
|
|
|
Coloris({
|
2025-12-05 17:43:58 +01:00
|
|
|
|
el: '[data-coloris]',
|
|
|
|
|
|
theme: 'pill',
|
|
|
|
|
|
themeMode: 'dark',
|
2025-12-05 17:39:51 +01:00
|
|
|
|
formatToggle: true,
|
2025-12-05 17:43:58 +01:00
|
|
|
|
alpha: true,
|
|
|
|
|
|
closeButton: true,
|
|
|
|
|
|
closeLabel: 'Fermer',
|
|
|
|
|
|
clearButton: true,
|
|
|
|
|
|
clearLabel: 'Effacer',
|
|
|
|
|
|
swatchesOnly: false,
|
|
|
|
|
|
inline: false,
|
|
|
|
|
|
wrap: true,
|
|
|
|
|
|
swatches: [
|
|
|
|
|
|
'#264653',
|
|
|
|
|
|
'#2a9d8f',
|
|
|
|
|
|
'#e9c46a',
|
|
|
|
|
|
'#f4a261',
|
|
|
|
|
|
'#e76f51',
|
|
|
|
|
|
'#d62828',
|
|
|
|
|
|
'#023e8a',
|
|
|
|
|
|
'#0077b6',
|
|
|
|
|
|
'#ffffff',
|
|
|
|
|
|
'#000000',
|
|
|
|
|
|
],
|
2025-12-05 17:39:51 +01:00
|
|
|
|
});
|
|
|
|
|
|
}, 0);
|
2025-12-05 17:32:39 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const close = () => {
|
2025-12-08 12:29:55 +01:00
|
|
|
|
selectedPageElement.value = null;
|
2025-12-05 17:32:39 +01:00
|
|
|
|
visible.value = false;
|
2025-12-05 17:39:51 +01:00
|
|
|
|
isEditable.value = false;
|
2025-12-08 12:29:55 +01:00
|
|
|
|
emit('close');
|
2025-12-05 17:39:51 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const toggleInheritance = () => {
|
2025-12-08 12:38:16 +01:00
|
|
|
|
const wasLocked = inheritanceLocked.value;
|
2025-12-05 17:51:09 +01:00
|
|
|
|
inheritanceLocked.value = !inheritanceLocked.value;
|
2025-12-08 12:38:16 +01:00
|
|
|
|
|
2025-12-10 12:04:58 +01:00
|
|
|
|
// Store the inheritance state in the page element's data attribute
|
|
|
|
|
|
if (selectedPageElement.value) {
|
|
|
|
|
|
if (inheritanceLocked.value) {
|
|
|
|
|
|
delete selectedPageElement.value.dataset.inheritanceUnlocked;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
selectedPageElement.value.dataset.inheritanceUnlocked = 'true';
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-08 12:38:16 +01:00
|
|
|
|
if (inheritanceLocked.value && !wasLocked) {
|
|
|
|
|
|
// Re-locking: remove the template-specific block
|
|
|
|
|
|
// Fields keep their values, but preview returns to @page defaults
|
|
|
|
|
|
removeTemplateBlock();
|
|
|
|
|
|
}
|
|
|
|
|
|
// When unlocking: fields already have values, block will be created on first edit
|
2025-12-05 17:32:39 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const pageCss = computed(() => {
|
2025-12-08 12:38:16 +01:00
|
|
|
|
// Show template-specific block if unlocked and exists, otherwise show @page
|
|
|
|
|
|
if (!inheritanceLocked.value && templateName.value) {
|
|
|
|
|
|
const templateBlock = stylesheetStore.extractBlock(`@page ${templateName.value}`);
|
|
|
|
|
|
if (templateBlock) return templateBlock;
|
|
|
|
|
|
}
|
2025-12-05 17:32:39 +01:00
|
|
|
|
return stylesheetStore.extractBlock('@page') || '';
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-05 17:43:58 +01:00
|
|
|
|
const highlightedCss = computed(() => {
|
|
|
|
|
|
if (!pageCss.value) return '';
|
|
|
|
|
|
return hljs.highlight(pageCss.value, { language: 'css' }).value;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-05 17:32:39 +01:00
|
|
|
|
let cssDebounceTimer = null;
|
|
|
|
|
|
|
|
|
|
|
|
const handleCssInput = (event) => {
|
|
|
|
|
|
const newCss = event.target.value;
|
|
|
|
|
|
|
|
|
|
|
|
if (cssDebounceTimer) {
|
|
|
|
|
|
clearTimeout(cssDebounceTimer);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cssDebounceTimer = setTimeout(() => {
|
|
|
|
|
|
const oldBlock = pageCss.value;
|
|
|
|
|
|
if (oldBlock) {
|
2025-12-05 18:21:54 +01:00
|
|
|
|
stylesheetStore.content = stylesheetStore.content.replace(
|
|
|
|
|
|
oldBlock,
|
|
|
|
|
|
newCss
|
|
|
|
|
|
);
|
2025-12-05 17:32:39 +01:00
|
|
|
|
}
|
|
|
|
|
|
}, 500);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-12-05 17:43:58 +01:00
|
|
|
|
// Watch isEditable to format when exiting edit mode
|
|
|
|
|
|
watch(isEditable, async (newValue, oldValue) => {
|
|
|
|
|
|
stylesheetStore.isEditing = newValue;
|
2025-12-05 17:39:51 +01:00
|
|
|
|
|
2025-12-05 17:43:58 +01:00
|
|
|
|
// Format when exiting editing mode
|
|
|
|
|
|
if (oldValue && !newValue) {
|
|
|
|
|
|
await stylesheetStore.formatContent();
|
|
|
|
|
|
}
|
2025-12-05 17:39:51 +01:00
|
|
|
|
});
|
|
|
|
|
|
|
2025-12-05 18:21:54 +01:00
|
|
|
|
// Watch stylesheet changes to sync values
|
|
|
|
|
|
watch(
|
|
|
|
|
|
() => stylesheetStore.content,
|
|
|
|
|
|
() => {
|
|
|
|
|
|
if (visible.value && !stylesheetStore.isEditing) {
|
|
|
|
|
|
loadValuesFromStylesheet();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2025-12-05 17:32:39 +01:00
|
|
|
|
defineExpose({ open, close, visible });
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2025-12-08 16:17:34 +01:00
|
|
|
|
/* PagePopup-specific styles (orange theme) */
|
2025-12-05 17:39:51 +01:00
|
|
|
|
.page-label {
|
2025-12-08 12:29:55 +01:00
|
|
|
|
background: var(--color-page-highlight);
|
2025-12-05 17:39:51 +01:00
|
|
|
|
color: white;
|
|
|
|
|
|
padding: 0.25rem 0.5rem;
|
|
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
font-size: 0.875rem;
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.page-name {
|
|
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
font-size: 0.875rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.page-count {
|
2025-12-08 12:29:55 +01:00
|
|
|
|
color: var(--color-page-highlight);
|
2025-12-05 17:32:39 +01:00
|
|
|
|
font-size: 0.875rem;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-05 17:39:51 +01:00
|
|
|
|
.margin-grid {
|
|
|
|
|
|
display: grid;
|
|
|
|
|
|
grid-template-columns: 1fr 1fr;
|
|
|
|
|
|
gap: 0.75rem;
|
|
|
|
|
|
}
|
2025-12-05 17:32:39 +01:00
|
|
|
|
</style>
|