@sentropic/design-system-svelte 0.35.0 → 0.36.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -33,6 +33,10 @@
33
33
  let maxHeight = $state(0);
34
34
  let alignmentRight = $state(false);
35
35
  let alignmentCenter = $state(false);
36
+ // True once the requested vertical side no longer fits and the panel is
37
+ // shown on the opposite side (flip). The placement class follows so the
38
+ // existing translate transforms keep working.
39
+ let flipped = $state(false);
36
40
 
37
41
  const GAP = 4;
38
42
  // Marge anti-débordement entre le panneau et le bord du viewport.
@@ -41,8 +45,19 @@
41
45
  // plutôt qu'un menu écrasé (cas rare d'un déclencheur collé au bord).
42
46
  const MIN_HEIGHT = 160;
43
47
 
48
+ function effectivePlacement(): "bottom-start" | "bottom-end" | "top-start" | "top-end" {
49
+ if (!flipped) return placement;
50
+ if (placement === "bottom-start") return "top-start";
51
+ if (placement === "bottom-end") return "top-end";
52
+ if (placement === "top-start") return "bottom-start";
53
+ return "bottom-end";
54
+ }
55
+
44
56
  function computePosition() {
45
57
  if (!trigger) return;
58
+ // Viewport coordinates (getBoundingClientRect) with `position: fixed`:
59
+ // no scroll offsets — the old document coordinates were wrong inside any
60
+ // positioned ancestor and the panel was clipped by overflow containers.
46
61
  const rect = trigger.getBoundingClientRect();
47
62
  const verticalUp = placement === "top-start" || placement === "top-end";
48
63
  const horizontalEnd = placement === "bottom-end" || placement === "top-end";
@@ -54,15 +69,26 @@
54
69
  alignmentRight = resolvedAlign === "end";
55
70
  alignmentCenter = resolvedAlign === "center";
56
71
 
57
- if (verticalUp) {
58
- // We don't know the panel height yet on first frame; position the panel's
59
- // bottom edge above the trigger using transform.
60
- top = rect.top + window.scrollY - GAP;
61
- // Espace réellement disponible AU-DESSUS du déclencheur (le panneau est
62
- // remonté de 100% de sa hauteur), borné pour rester dans le viewport.
72
+ const panelHeight = panel?.offsetHeight ?? 0;
73
+ const panelWidth = panel?.offsetWidth ?? 0;
74
+ const need = panelHeight > 0 ? panelHeight : MIN_HEIGHT;
75
+ const spaceBelow = window.innerHeight - rect.bottom - GAP;
76
+ const spaceAbove = rect.top - GAP;
77
+
78
+ // Flip when the requested side cannot fit the panel and the other side
79
+ // offers more room.
80
+ let showUp = verticalUp;
81
+ if (!verticalUp && spaceBelow < need && spaceAbove > spaceBelow) showUp = true;
82
+ else if (verticalUp && spaceAbove < need && spaceBelow > spaceAbove) showUp = false;
83
+ flipped = showUp !== verticalUp;
84
+
85
+ if (showUp) {
86
+ // The panel's bottom edge sits above the trigger (transform handles the
87
+ // flip); available space is what's ABOVE the trigger.
88
+ top = rect.top - GAP;
63
89
  maxHeight = Math.max(rect.top - GAP - VIEWPORT_MARGIN, MIN_HEIGHT);
64
90
  } else {
65
- top = rect.bottom + window.scrollY + GAP;
91
+ top = rect.bottom + GAP;
66
92
  // Espace réellement disponible SOUS le déclencheur : c'est ce qui manquait —
67
93
  // `max-height: 100vh` ignorait l'offset du panneau et débordait par le bas.
68
94
  maxHeight = Math.max(
@@ -71,18 +97,71 @@
71
97
  );
72
98
  }
73
99
 
100
+ // Reclamp horizontally so the measured panel stays inside the viewport.
74
101
  if (resolvedAlign === "end") {
75
- left = rect.right + window.scrollX;
102
+ left = rect.right;
103
+ if (panelWidth > 0) left = Math.min(Math.max(left, panelWidth + VIEWPORT_MARGIN), window.innerWidth - VIEWPORT_MARGIN);
76
104
  } else if (resolvedAlign === "center") {
77
- left = rect.left + window.scrollX + rect.width / 2;
105
+ left = rect.left + rect.width / 2;
106
+ if (panelWidth > 0) {
107
+ left = Math.min(
108
+ Math.max(left, panelWidth / 2 + VIEWPORT_MARGIN),
109
+ window.innerWidth - panelWidth / 2 - VIEWPORT_MARGIN
110
+ );
111
+ }
78
112
  } else {
79
- left = rect.left + window.scrollX;
113
+ left = rect.left;
114
+ if (panelWidth > 0) left = Math.min(Math.max(left, VIEWPORT_MARGIN), window.innerWidth - panelWidth - VIEWPORT_MARGIN);
115
+ }
116
+ }
117
+
118
+ // --- Top layer -----------------------------------------------------------
119
+ // The element stays in place in the DOM (no portal to <body>) so it keeps
120
+ // inheriting the theme's `--st-*` custom properties; the Popover API only
121
+ // lifts rendering into the top layer, above overflow clipping. Where the
122
+ // API is missing (jsdom), plain `position: fixed` still applies.
123
+ let popoverShown = false;
124
+
125
+ function showTopLayer() {
126
+ const el = panel as (HTMLDivElement & { showPopover?: () => void }) | undefined;
127
+ if (!el || popoverShown) return;
128
+ if (typeof el.showPopover !== "function") return;
129
+ // The attribute is set ONLY here (never statically in markup): environments
130
+ // without the API (jsdom) hide every [popover] element via the UA rule, so
131
+ // a static attribute would force display:none under test.
132
+ el.setAttribute("popover", "manual");
133
+ try {
134
+ el.showPopover();
135
+ popoverShown = true;
136
+ } catch {
137
+ el.removeAttribute("popover");
138
+ // Already open or not ready — fixed positioning still applies.
139
+ }
140
+ }
141
+
142
+ function hideTopLayer() {
143
+ const el = panel as (HTMLDivElement & { hidePopover?: () => void }) | undefined;
144
+ popoverShown = false;
145
+ if (!el || typeof el.hidePopover !== "function") return;
146
+ try {
147
+ el.hidePopover();
148
+ } catch {
149
+ // Already hidden — nothing to do.
150
+ } finally {
151
+ el.removeAttribute("popover");
80
152
  }
81
153
  }
82
154
 
83
155
  $effect(() => {
84
156
  if (!open) return;
85
157
  computePosition();
158
+ showTopLayer();
159
+ // Re-measure once the panel is laid out (size known for flip/clamp).
160
+ if (typeof requestAnimationFrame === "function") {
161
+ requestAnimationFrame(() => {
162
+ if (open) computePosition();
163
+ });
164
+ }
86
165
  const onScroll = () => computePosition();
87
166
  const onResize = () => computePosition();
88
167
  window.addEventListener("scroll", onScroll, true);
@@ -90,6 +169,7 @@
90
169
  return () => {
91
170
  window.removeEventListener("scroll", onScroll, true);
92
171
  window.removeEventListener("resize", onResize);
172
+ hideTopLayer();
93
173
  };
94
174
  });
95
175
 
@@ -121,7 +201,7 @@
121
201
  const classes = () =>
122
202
  [
123
203
  "st-menuPopover",
124
- `st-menuPopover--${placement}`,
204
+ `st-menuPopover--${effectivePlacement()}`,
125
205
  alignmentRight ? "st-menuPopover--alignEnd" : null,
126
206
  alignmentCenter ? "st-menuPopover--alignCenter" : null,
127
207
  className
@@ -133,6 +213,8 @@
133
213
  <svelte:window onpointerdown={onWindowPointerDown} onkeydown={onWindowKeyDown} />
134
214
 
135
215
  {#if open}
216
+ <!-- No static popover attribute: it is set imperatively by showTopLayer()
217
+ only where the Popover API exists (see above). -->
136
218
  <div
137
219
  {...rest}
138
220
  bind:this={panel}
@@ -160,7 +242,14 @@
160
242
  max-height: calc(100vh - 2rem);
161
243
  overflow: auto;
162
244
  padding: 0;
163
- position: absolute;
245
+ /* The Popover API UA sheet gives [popover] `inset: 0; margin: auto`: without
246
+ this reset the top-layer panel is re-centred between its top/left and the
247
+ viewport edges instead of sitting on the trigger. Inline top/left win. */
248
+ inset: auto;
249
+ margin: 0;
250
+ /* Viewport coordinates from getBoundingClientRect: fixed, never absolute
251
+ (absolute + document coords broke inside any positioned ancestor). */
252
+ position: fixed;
164
253
  z-index: var(--st-component-popover-zIndex, 80);
165
254
  }
166
255
 
@@ -1 +1 @@
1
- {"version":3,"file":"MenuPopover.svelte.d.ts","sourceRoot":"","sources":["../src/lib/MenuPopover.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGpD,KAAK,gBAAgB,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,GAAG;IACtE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,cAAc,GAAG,YAAY,GAAG,WAAW,GAAG,SAAS,CAAC;IACpE,KAAK,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAsIJ,QAAA,MAAM,WAAW,0DAAwC,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"MenuPopover.svelte.d.ts","sourceRoot":"","sources":["../src/lib/MenuPopover.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGpD,KAAK,gBAAgB,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,GAAG;IACtE,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,EAAE,WAAW,GAAG,IAAI,CAAC;IAC5B,SAAS,CAAC,EAAE,cAAc,GAAG,YAAY,GAAG,WAAW,GAAG,SAAS,CAAC;IACpE,KAAK,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC;IACnC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAuNJ,QAAA,MAAM,WAAW,0DAAwC,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
@@ -0,0 +1,241 @@
1
+ <script lang="ts" module>
2
+ import { placePriorityLabels, type PriorityMatrixObstacle } from "./priorityLabels.js";
3
+
4
+ export type PriorityMatrixTone =
5
+ | "category1" | "category2" | "category3" | "category4"
6
+ | "category5" | "category6" | "category7" | "category8";
7
+
8
+ export type PriorityMatrixDatum = {
9
+ /** Complexité, 0–100 (bornée à l'affichage). */
10
+ x: number;
11
+ /** Valeur, 0–100 (bornée à l'affichage). */
12
+ y: number;
13
+ /** Étiquette affichée (une ou deux lignes). */
14
+ label: string;
15
+ tone?: PriorityMatrixTone;
16
+ };
17
+
18
+ type PriorityMatrixProps = {
19
+ data: PriorityMatrixDatum[];
20
+ /** Titre visible au-dessus du cadre. */
21
+ title?: string;
22
+ xLabel?: string;
23
+ yLabel?: string;
24
+ /** Seuils de quadrants (0–100). */
25
+ xThreshold?: number;
26
+ yThreshold?: number;
27
+ width?: number;
28
+ height?: number;
29
+ radius?: number;
30
+ label: string;
31
+ class?: string;
32
+ };
33
+ </script>
34
+
35
+ <script lang="ts">
36
+ import ChartDataList from "./ChartDataList.svelte";
37
+
38
+ let {
39
+ data,
40
+ title = "Matrice de priorisation",
41
+ xLabel = "Complexité (0-100 pts)",
42
+ yLabel = "Valeur (0-100 pts)",
43
+ xThreshold = 50,
44
+ yThreshold = 50,
45
+ width = 640,
46
+ height = 400,
47
+ radius = 5,
48
+ label,
49
+ class: className
50
+ }: PriorityMatrixProps = $props();
51
+
52
+ const MARGIN = { top: 26, right: 18, bottom: 36, left: 48 };
53
+ const TICKS = [0, 20, 40, 60, 80, 100];
54
+ const TONES: PriorityMatrixTone[] = ["category1","category2","category3","category4","category5","category6","category7","category8"];
55
+ const QUADRANTS = [
56
+ { id: "quick-wins", name: "Gains rapides" },
57
+ { id: "major-projects", name: "Projets majeurs" },
58
+ { id: "wait", name: "Attendre" },
59
+ { id: "drop", name: "Ne pas faire" }
60
+ ] as const;
61
+
62
+ function splitLabel(value: string): string[] {
63
+ const chars = [...value];
64
+ if (chars.length <= 12) return [value];
65
+ const mid = Math.ceil(chars.length / 2);
66
+ const space = value.lastIndexOf(" ", mid + 4);
67
+ if (space > 2 && space < value.length - 2) return [value.slice(0, space), value.slice(space + 1)];
68
+ return [value.slice(0, mid), value.slice(mid)];
69
+ }
70
+
71
+ /**
72
+ * Fixed obstacles for the placement: keep-out bands around the two threshold
73
+ * lines plus one rectangle per quadrant name, in frame pixels. Estimated from
74
+ * the rendered geometry (11px names); a soft cost, not a hard exclusion.
75
+ */
76
+ function buildMatrixObstacles(
77
+ tx: number,
78
+ ty: number,
79
+ plotW: number,
80
+ plotH: number
81
+ ): PriorityMatrixObstacle[] {
82
+ const names = [
83
+ { x: MARGIN.left + 6, y: MARGIN.top + 14, anchor: "start" as const, text: QUADRANTS[0]!.name },
84
+ { x: MARGIN.left + plotW - 6, y: MARGIN.top + 14, anchor: "end" as const, text: QUADRANTS[1]!.name },
85
+ { x: MARGIN.left + 6, y: MARGIN.top + plotH - 8, anchor: "start" as const, text: QUADRANTS[2]!.name },
86
+ { x: MARGIN.left + plotW - 6, y: MARGIN.top + plotH - 8, anchor: "end" as const, text: QUADRANTS[3]!.name }
87
+ ];
88
+ const out: PriorityMatrixObstacle[] = [
89
+ { x: tx - 3, y: MARGIN.top, w: 6, h: plotH },
90
+ { x: MARGIN.left, y: ty - 3, w: plotW, h: 6 }
91
+ ];
92
+ for (const q of names) {
93
+ const w = [...q.text].length * 6.5 + 4;
94
+ out.push({ x: q.anchor === "start" ? q.x : q.x - w, y: q.y - 9, w, h: 12 });
95
+ }
96
+ return out;
97
+ }
98
+
99
+ /** Accessible coordinate text; non-finite values read as N/A, never NaN. */
100
+ function coordText(v: number): string {
101
+ return Number.isFinite(v) ? String(v) : "N/A";
102
+ }
103
+
104
+ const plotW = $derived(Math.max(width - MARGIN.left - MARGIN.right, 1));
105
+ const plotH = $derived(Math.max(height - MARGIN.top - MARGIN.bottom, 1));
106
+ const scaleX = $derived((v: number) =>
107
+ Number.isFinite(v) ? MARGIN.left + (Math.min(Math.max(v, 0), 100) / 100) * plotW : MARGIN.left);
108
+ const scaleY = $derived((v: number) =>
109
+ Number.isFinite(v) ? MARGIN.top + (1 - Math.min(Math.max(v, 0), 100) / 100) * plotH : MARGIN.top);
110
+ const tx = $derived(scaleX(xThreshold));
111
+ const ty = $derived(scaleY(yThreshold));
112
+
113
+ const quads = $derived([
114
+ { id: "quick-wins", x: MARGIN.left, y: MARGIN.top, w: tx - MARGIN.left, h: ty - MARGIN.top },
115
+ { id: "major-projects", x: tx, y: MARGIN.top, w: MARGIN.left + plotW - tx, h: ty - MARGIN.top },
116
+ { id: "wait", x: MARGIN.left, y: ty, w: tx - MARGIN.left, h: MARGIN.top + plotH - ty },
117
+ { id: "drop", x: tx, y: ty, w: MARGIN.left + plotW - tx, h: MARGIN.top + plotH - ty }
118
+ ]);
119
+
120
+ const quadNames = $derived([
121
+ { id: "quick-wins", x: MARGIN.left + 6, y: MARGIN.top + 14, anchor: "start" },
122
+ { id: "major-projects", x: MARGIN.left + plotW - 6, y: MARGIN.top + 14, anchor: "end" },
123
+ { id: "wait", x: MARGIN.left + 6, y: MARGIN.top + plotH - 8, anchor: "start" },
124
+ { id: "drop", x: MARGIN.left + plotW - 6, y: MARGIN.top + plotH - 8, anchor: "end" }
125
+ ]);
126
+
127
+ const points = $derived(
128
+ data.map((d, i) => ({
129
+ cx: scaleX(d.x),
130
+ cy: scaleY(d.y),
131
+ datum: d,
132
+ index: i,
133
+ tone: d.tone ?? TONES[i % TONES.length]
134
+ }))
135
+ );
136
+
137
+ const placed = $derived.by(() => {
138
+ const boxes = data.map((d) => {
139
+ const lines = splitLabel(d.label);
140
+ const longest = Math.max(...lines.map((l) => [...l].length));
141
+ return { w: Math.min(120, 12 + 7 * longest), h: lines.length > 1 ? 34 : 20, lines };
142
+ });
143
+ const result = placePriorityLabels(
144
+ data.map((d) => ({ x: d.x, y: d.y, label: d.label })),
145
+ boxes,
146
+ { width, height, marginLeft: MARGIN.left, marginTop: MARGIN.top, plotWidth: plotW, plotHeight: plotH },
147
+ { xThreshold, yThreshold, obstacles: buildMatrixObstacles(tx, ty, plotW, plotH) }
148
+ );
149
+ return result.map((p) => ({ ...p, lines: boxes[p.index]!.lines as string[] }));
150
+ });
151
+
152
+ const dataValueItems = $derived(
153
+ data.map((d) => `${d.label} : complexité ${coordText(d.x)}, valeur ${coordText(d.y)}`)
154
+ );
155
+
156
+ const quadName = (id: string) => QUADRANTS.find((q) => q.id === id)?.name ?? id;
157
+ const classes = () => ["st-priorityMatrix", className].filter(Boolean).join(" ");
158
+ </script>
159
+
160
+ <div class={classes()}>
161
+ <div class="st-priorityMatrix__visual" role="img" aria-label={label}>
162
+ <svg viewBox="0 0 {width} {height}" preserveAspectRatio="xMidYMid meet" width="100%" height="100%" focusable="false" aria-hidden="true">
163
+ {#if title}
164
+ <text class="st-priorityMatrix__title" x={MARGIN.left} y={15} text-anchor="start">{title}</text>
165
+ {/if}
166
+
167
+ {#each quads as q (q.id)}
168
+ <rect class="st-priorityMatrix__quad st-priorityMatrix__quad--{q.id}" x={q.x} y={q.y} width={q.w} height={q.h} />
169
+ {/each}
170
+
171
+ {#each TICKS as t (t)}
172
+ {@const y = scaleY(t)}
173
+ <line class="st-priorityMatrix__grid" x1={MARGIN.left} x2={width - MARGIN.right} y1={y} y2={y} />
174
+ <text class="st-priorityMatrix__tick" x={MARGIN.left - 6} y={y} text-anchor="end" dominant-baseline="middle">{t}</text>
175
+ {/each}
176
+ {#each TICKS as t (t)}
177
+ {@const x = scaleX(t)}
178
+ <text class="st-priorityMatrix__tick" x={x} y={height - MARGIN.bottom + 16} text-anchor="middle">{t}</text>
179
+ {/each}
180
+
181
+ <line class="st-priorityMatrix__axis" x1={MARGIN.left} x2={MARGIN.left} y1={MARGIN.top} y2={height - MARGIN.bottom} />
182
+ <line class="st-priorityMatrix__axis" x1={MARGIN.left} x2={width - MARGIN.right} y1={height - MARGIN.bottom} y2={height - MARGIN.bottom} />
183
+
184
+ <line class="st-priorityMatrix__threshold" x1={tx} x2={tx} y1={MARGIN.top} y2={MARGIN.top + plotH} />
185
+ <line class="st-priorityMatrix__threshold" x1={MARGIN.left} x2={MARGIN.left + plotW} y1={ty} y2={ty} />
186
+
187
+ {#each quadNames as q (q.id)}
188
+ <text class="st-priorityMatrix__quadName" x={q.x} y={q.y} text-anchor={q.anchor}>{quadName(q.id)}</text>
189
+ {/each}
190
+
191
+ {#if xLabel}
192
+ <text class="st-priorityMatrix__axisLabel" x={MARGIN.left + plotW / 2} y={height - 4} text-anchor="middle">{xLabel}</text>
193
+ {/if}
194
+ {#if yLabel}
195
+ <text class="st-priorityMatrix__axisLabel" x={12} y={MARGIN.top + plotH / 2} text-anchor="middle" transform="rotate(-90 12 {MARGIN.top + plotH / 2})">{yLabel}</text>
196
+ {/if}
197
+
198
+ {#each points as p (p.index)}
199
+ <circle class="st-priorityMatrix__point st-priorityMatrix__point--{p.tone}" cx={p.cx} cy={p.cy} r={radius} />
200
+ {/each}
201
+
202
+ {#each placed as p (p.index)}
203
+ <line class="st-priorityMatrix__leader" x1={p.leaderX1} y1={p.leaderY1} x2={p.leaderX2} y2={p.leaderY2} />
204
+ <rect class="st-priorityMatrix__labelBox" x={p.x} y={p.y} width={p.w} height={p.h} rx={3} />
205
+ {#each p.lines as line, li (li)}
206
+ <text class="st-priorityMatrix__labelText" x={p.x + p.w / 2} y={p.y + 13 + li * 13} text-anchor="middle">{line}</text>
207
+ {/each}
208
+ {/each}
209
+ </svg>
210
+ </div>
211
+
212
+ <ChartDataList {label} items={dataValueItems} />
213
+ </div>
214
+
215
+ <style>
216
+ .st-priorityMatrix { color: var(--st-semantic-text-secondary); display: block; font-family: inherit; position: relative; width: 100%; }
217
+ .st-priorityMatrix__visual { display: block; }
218
+ .st-priorityMatrix svg { display: block; overflow: visible; }
219
+ .st-priorityMatrix__title { fill: var(--st-semantic-text-primary); font-size: 0.875rem; font-weight: 700; }
220
+ .st-priorityMatrix__quad--quick-wins { fill: color-mix(in srgb, var(--st-semantic-feedback-success) 12%, transparent); }
221
+ .st-priorityMatrix__quad--major-projects { fill: color-mix(in srgb, var(--st-semantic-feedback-info) 12%, transparent); }
222
+ .st-priorityMatrix__quad--wait { fill: color-mix(in srgb, var(--st-semantic-feedback-warning) 12%, transparent); }
223
+ .st-priorityMatrix__quad--drop { fill: color-mix(in srgb, var(--st-semantic-border-subtle) 22%, transparent); }
224
+ .st-priorityMatrix__threshold { stroke: var(--st-semantic-text-secondary); stroke-width: 1.5; stroke-dasharray: 5 4; }
225
+ .st-priorityMatrix__quadName { fill: var(--st-semantic-text-secondary); font-size: 0.6875rem; font-weight: 600; }
226
+ .st-priorityMatrix__grid { stroke: var(--st-semantic-border-subtle); stroke-dasharray: 2 3; stroke-width: 1; opacity: 0.7; }
227
+ .st-priorityMatrix__axis { stroke: var(--st-semantic-border-subtle); stroke-width: 1; }
228
+ .st-priorityMatrix__tick { fill: var(--st-semantic-text-secondary); font-size: 0.6875rem; }
229
+ .st-priorityMatrix__axisLabel { fill: var(--st-semantic-text-secondary); font-size: 0.75rem; font-weight: 600; }
230
+ .st-priorityMatrix__point--category1 { fill: var(--st-semantic-data-category1); }
231
+ .st-priorityMatrix__point--category2 { fill: var(--st-semantic-data-category2); }
232
+ .st-priorityMatrix__point--category3 { fill: var(--st-semantic-data-category3); }
233
+ .st-priorityMatrix__point--category4 { fill: var(--st-semantic-data-category4); }
234
+ .st-priorityMatrix__point--category5 { fill: var(--st-semantic-data-category5); }
235
+ .st-priorityMatrix__point--category6 { fill: var(--st-semantic-data-category6); }
236
+ .st-priorityMatrix__point--category7 { fill: var(--st-semantic-data-category7); }
237
+ .st-priorityMatrix__point--category8 { fill: var(--st-semantic-data-category8); }
238
+ .st-priorityMatrix__leader { stroke: var(--st-semantic-text-secondary); stroke-width: 1; opacity: 0.8; }
239
+ .st-priorityMatrix__labelBox { fill: var(--st-semantic-surface-default); stroke: var(--st-semantic-border-subtle); stroke-width: 1; }
240
+ .st-priorityMatrix__labelText { fill: var(--st-semantic-text-primary); font-size: 0.6875rem; }
241
+ </style>
@@ -0,0 +1,29 @@
1
+ export type PriorityMatrixTone = "category1" | "category2" | "category3" | "category4" | "category5" | "category6" | "category7" | "category8";
2
+ export type PriorityMatrixDatum = {
3
+ /** Complexité, 0–100 (bornée à l'affichage). */
4
+ x: number;
5
+ /** Valeur, 0–100 (bornée à l'affichage). */
6
+ y: number;
7
+ /** Étiquette affichée (une ou deux lignes). */
8
+ label: string;
9
+ tone?: PriorityMatrixTone;
10
+ };
11
+ type PriorityMatrixProps = {
12
+ data: PriorityMatrixDatum[];
13
+ /** Titre visible au-dessus du cadre. */
14
+ title?: string;
15
+ xLabel?: string;
16
+ yLabel?: string;
17
+ /** Seuils de quadrants (0–100). */
18
+ xThreshold?: number;
19
+ yThreshold?: number;
20
+ width?: number;
21
+ height?: number;
22
+ radius?: number;
23
+ label: string;
24
+ class?: string;
25
+ };
26
+ declare const PriorityMatrix: import("svelte").Component<PriorityMatrixProps, {}, "">;
27
+ type PriorityMatrix = ReturnType<typeof PriorityMatrix>;
28
+ export default PriorityMatrix;
29
+ //# sourceMappingURL=PriorityMatrix.svelte.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PriorityMatrix.svelte.d.ts","sourceRoot":"","sources":["../src/lib/PriorityMatrix.svelte.ts"],"names":[],"mappings":"AAKE,MAAM,MAAM,kBAAkB,GAC1B,WAAW,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,GACrD,WAAW,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC;AAE1D,MAAM,MAAM,mBAAmB,GAAG;IAChC,gDAAgD;IAChD,CAAC,EAAE,MAAM,CAAC;IACV,4CAA4C;IAC5C,CAAC,EAAE,MAAM,CAAC;IACV,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,kBAAkB,CAAC;CAC3B,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,IAAI,EAAE,mBAAmB,EAAE,CAAC;IAC5B,wCAAwC;IACxC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,mCAAmC;IACnC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AA+LJ,QAAA,MAAM,cAAc,yDAAwC,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
@@ -82,7 +82,10 @@
82
82
 
83
83
  .st-radioGroup__legend {
84
84
  color: var(--st-component-field-labelText, var(--st-semantic-text-primary));
85
- font-size: 0.9375rem;
85
+ /* Point d'entrée de personnalisation (même modèle que
86
+ --st-component-selection-choiceLabelFontSize) ; md = rendu actuel.
87
+ Pas de prop `size` : Checkbox/CheckboxGroup n'en ont aucune. */
88
+ font-size: var(--st-component-selection-legendFontSize, 0.9375rem);
86
89
  font-weight: 650;
87
90
  line-height: 1.3;
88
91
  padding: 0;
@@ -23,6 +23,7 @@
23
23
  // NOT trap focus or return it to the trigger on close (see its own docs), so
24
24
  // both are added here (mirrors Modal.svelte's trapFocus pattern).
25
25
  import { tick, untrack } from "svelte";
26
+ import type { Snippet } from "svelte";
26
27
  import { Clock, ChevronDown } from "@lucide/svelte";
27
28
  import MenuPopover from "./MenuPopover.svelte";
28
29
  import ContentSwitcher from "./ContentSwitcher.svelte";
@@ -62,6 +63,17 @@
62
63
  class?: string;
63
64
  formatRange?: (value: TimeRange, locale: string) => string;
64
65
  formatPresetLabel?: (token: string, locale: string) => string;
66
+ /**
67
+ * Optional consumer controls rendered in the Custom tab, directly above the
68
+ * From/To fields (e.g. a "date basis" radio group). The Custom tab is
69
+ * staged behind Apply, so treat whatever this snippet edits as a DRAFT:
70
+ * reseed it from `onOpenChange(true)` and commit it from `onChange` when
71
+ * the emitted value has `mode: "absolute"` (that emit only happens on
72
+ * Apply). Cancel / Escape / outside click emit nothing.
73
+ */
74
+ customExtra?: Snippet;
75
+ /** Fires whenever the panel opens (`true`) or closes (`false`). */
76
+ onOpenChange?: (open: boolean) => void;
65
77
  };
66
78
 
67
79
  let {
@@ -82,7 +94,9 @@
82
94
  size = "md",
83
95
  class: className,
84
96
  formatRange,
85
- formatPresetLabel: formatPresetLabelProp
97
+ formatPresetLabel: formatPresetLabelProp,
98
+ customExtra,
99
+ onOpenChange
86
100
  }: TimeRangePickerProps = $props();
87
101
 
88
102
  const isFr = $derived((locale ?? "fr-FR").toLowerCase().startsWith("fr"));
@@ -182,6 +196,19 @@
182
196
  return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}`;
183
197
  }
184
198
 
199
+ // --- Couplage des deux mois (mode deux calendriers) -----------------------
200
+ // Invariant : droite > gauche, toujours. La comparaison lexicographique
201
+ // vaut l'ordre chronologique pour des "YYYY-MM" à mois rembourrés.
202
+ function onLeftMonthChange(next: string) {
203
+ leftMonth = next;
204
+ if (rightMonth <= next) rightMonth = monthOf(next, 1);
205
+ }
206
+
207
+ function onRightMonthChange(next: string) {
208
+ rightMonth = next;
209
+ if (leftMonth >= next) leftMonth = monthOf(next, -1);
210
+ }
211
+
185
212
  let leftMonth = $state<string>("");
186
213
  let rightMonth = $state<string>("");
187
214
 
@@ -200,7 +227,10 @@
200
227
  toText: `${split.toDate} ${split.toTime}`
201
228
  };
202
229
  leftMonth = monthOf(split.fromDate, 0);
203
- rightMonth = monthOf(split.fromDate, 1);
230
+ // Droite = mois de la fin quand il est après la gauche, sinon gauche + 1 :
231
+ // les deux bornes deviennent visibles dès l'ouverture.
232
+ const endMonth = monthOf(split.toDate, 0);
233
+ rightMonth = endMonth > leftMonth ? endMonth : monthOf(leftMonth, 1);
204
234
  }
205
235
 
206
236
  let previousFocus: HTMLElement | null = null;
@@ -247,6 +277,17 @@
247
277
  // in the overwhelming majority of cases). Reads other than `panelOpen` are
248
278
  // untracked so a controlled `value` change while the panel stays open does
249
279
  // NOT clobber in-progress edits.
280
+ // `onOpenChange` is notified on every real transition only (the initial
281
+ // closed state is not reported).
282
+ let reportedOpen = false;
283
+ $effect(() => {
284
+ const isOpen = panelOpen;
285
+ if (isOpen !== reportedOpen) {
286
+ reportedOpen = isOpen;
287
+ untrack(() => onOpenChange?.(isOpen));
288
+ }
289
+ });
290
+
250
291
  $effect(() => {
251
292
  if (panelOpen) {
252
293
  untrack(() => {
@@ -429,6 +470,7 @@
429
470
  range
430
471
  value={calendarValue}
431
472
  onChange={onCalendarChange}
473
+ onMonthChange={onLeftMonthChange}
432
474
  min={calendarMinIso}
433
475
  max={calendarMaxIso}
434
476
  {locale}
@@ -439,6 +481,7 @@
439
481
  range
440
482
  value={calendarValue}
441
483
  onChange={onCalendarChange}
484
+ onMonthChange={onRightMonthChange}
442
485
  min={calendarMinIso}
443
486
  max={calendarMaxIso}
444
487
  {locale}
@@ -447,6 +490,12 @@
447
490
  {/if}
448
491
  </div>
449
492
 
493
+ {#if customExtra}
494
+ <div class="st-timeRangePicker__customExtra">
495
+ {@render customExtra()}
496
+ </div>
497
+ {/if}
498
+
450
499
  <div class="st-timeRangePicker__bounds">
451
500
  <div class="st-timeRangePicker__bound">
452
501
  <Input
@@ -592,6 +641,12 @@
592
641
  min-width: 16rem;
593
642
  }
594
643
 
644
+ .st-timeRangePicker__customExtra {
645
+ display: flex;
646
+ flex-direction: column;
647
+ gap: var(--st-spacing-2, 0.5rem);
648
+ }
649
+
595
650
  .st-timeRangePicker__bounds {
596
651
  display: grid;
597
652
  gap: var(--st-spacing-3, 0.75rem);
@@ -10,6 +10,7 @@ export type TimeRangePreset = string | {
10
10
  label?: string;
11
11
  durationMs?: number;
12
12
  };
13
+ import type { Snippet } from "svelte";
13
14
  type TimeRangePickerProps = {
14
15
  value?: TimeRange;
15
16
  defaultValue?: TimeRange;
@@ -29,6 +30,17 @@ type TimeRangePickerProps = {
29
30
  class?: string;
30
31
  formatRange?: (value: TimeRange, locale: string) => string;
31
32
  formatPresetLabel?: (token: string, locale: string) => string;
33
+ /**
34
+ * Optional consumer controls rendered in the Custom tab, directly above the
35
+ * From/To fields (e.g. a "date basis" radio group). The Custom tab is
36
+ * staged behind Apply, so treat whatever this snippet edits as a DRAFT:
37
+ * reseed it from `onOpenChange(true)` and commit it from `onChange` when
38
+ * the emitted value has `mode: "absolute"` (that emit only happens on
39
+ * Apply). Cancel / Escape / outside click emit nothing.
40
+ */
41
+ customExtra?: Snippet;
42
+ /** Fires whenever the panel opens (`true`) or closes (`false`). */
43
+ onOpenChange?: (open: boolean) => void;
32
44
  };
33
45
  declare const TimeRangePicker: import("svelte").Component<TimeRangePickerProps, {}, "value">;
34
46
  type TimeRangePicker = ReturnType<typeof TimeRangePicker>;
@@ -1 +1 @@
1
- {"version":3,"file":"TimeRangePicker.svelte.d.ts","sourceRoot":"","sources":["../src/lib/TimeRangePicker.svelte.ts"],"names":[],"mappings":"AAOE,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,UAAU,CAAC;AACpD,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,EAAE,aAAa,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AACF,MAAM,MAAM,eAAe,GACvB,MAAM,GACN;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AA+B3D,KAAK,oBAAoB,GAAG;IAC1B,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,IAAI,CAAC;IACtC,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B,GAAG,CAAC,EAAE,MAA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,QAAA,MAAM,eAAe,+DAAwC,CAAC;AAC9D,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAC1D,eAAe,eAAe,CAAC"}
package/dist/index.d.ts CHANGED
@@ -179,6 +179,7 @@ export { default as VariablePieChart } from "./VariablePieChart.svelte";
179
179
  export { default as VennChart } from "./VennChart.svelte";
180
180
  export { default as Row } from "./Row.svelte";
181
181
  export { default as ScatterPlot } from "./ScatterPlot.svelte";
182
+ export { default as PriorityMatrix } from "./PriorityMatrix.svelte";
182
183
  export { default as Search } from "./Search.svelte";
183
184
  export { default as Select } from "./Select.svelte";
184
185
  export { default as SelectableRow } from "./SelectableRow.svelte";
@@ -262,6 +263,7 @@ export type { VennChartArea, VennChartProps, VennChartTone } from "./VennChart.s
262
263
  export type { SankeyChartLink, SankeyChartNode, SankeyChartTone } from "./SankeyChart.svelte";
263
264
  export type { SunburstChartDatum, SunburstChartTone } from "./SunburstChart.svelte";
264
265
  export type { ScatterPlotDatum, ScatterPlotTone, ScatterPlotCentroid } from "./ScatterPlot.svelte";
266
+ export type { PriorityMatrixDatum, PriorityMatrixTone } from "./PriorityMatrix.svelte";
265
267
  export type { StackedBarDatum, StackedBarSegment, StackedBarTone } from "./StackedBarChart.svelte";
266
268
  export type { LineChartDatum, LineChartTone } from "./LineChart.svelte";
267
269
  export type { ChartOverlayTone, ChartReferenceLine, ChartBand, ChartGoalLine, ChartScale } from "./LineChart.svelte";