@sentropic/design-system-svelte 0.38.0 → 0.40.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.
@@ -0,0 +1,109 @@
1
+ // Pure geometry helpers for the Menu cascade (spec SPEC_EVOL_MENU_CASCADE §3.3/§3.4).
2
+ // No DOM access here: every function is deterministic and unit-testable in jsdom/Node.
3
+ export const OPEN_DELAY = 150;
4
+ export const CLOSE_DELAY = 250;
5
+ export const VIEWPORT_MARGIN = 8;
6
+ export const SUBMENU_PANEL_PADDING_TOP = 5;
7
+ export const SUBMENU_DEFAULT_WIDTH = 192;
8
+ export function resolvePreferredSide(preferred) {
9
+ if (preferred === "left")
10
+ return "left";
11
+ return "right";
12
+ }
13
+ /**
14
+ * Deterministic sub-menu solver (§3.4). Returns viewport coordinates for a
15
+ * `position: fixed` panel; the caller converts them with
16
+ * `toContainingBlockPosition` when the panel sits under a transformed ancestor.
17
+ */
18
+ export function computeSubMenuPosition(input) {
19
+ const { parentMenuRect, parentItemRect, panelSize, viewport, preferredSide, panelPaddingTop = SUBMENU_PANEL_PADDING_TOP } = input;
20
+ const vw = viewport.width;
21
+ const vh = viewport.height;
22
+ const width = panelSize.width;
23
+ const height = panelSize.height;
24
+ const W = width > 0 ? width : SUBMENU_DEFAULT_WIDTH;
25
+ const H = height;
26
+ const preferred = resolvePreferredSide(preferredSide);
27
+ const other = preferred === "right" ? "left" : "right";
28
+ const spaceRight = vw - VIEWPORT_MARGIN - parentMenuRect.right;
29
+ const spaceLeft = parentMenuRect.left - VIEWPORT_MARGIN;
30
+ const fits = (space) => space >= W;
31
+ let side;
32
+ if (fits(preferred === "right" ? spaceRight : spaceLeft)) {
33
+ side = preferred;
34
+ }
35
+ else if (fits(other === "right" ? spaceRight : spaceLeft)) {
36
+ side = other;
37
+ }
38
+ else if (spaceRight === spaceLeft) {
39
+ side = preferred;
40
+ }
41
+ else {
42
+ side = spaceRight > spaceLeft ? "right" : "left";
43
+ }
44
+ let left = side === "right" ? parentMenuRect.right : parentMenuRect.left - W;
45
+ if (W <= vw - 2 * VIEWPORT_MARGIN) {
46
+ const min = VIEWPORT_MARGIN;
47
+ const max = vw - VIEWPORT_MARGIN - W;
48
+ if (left < min)
49
+ left = min;
50
+ else if (left > max)
51
+ left = max;
52
+ }
53
+ else {
54
+ // Narrow viewport: cap the panel via `min-width: 0` +
55
+ // `max-width: calc(100vw - 16px)` so the 12rem CSS `min-width` cannot
56
+ // override the cap (§3.4 step 3). The component applies those styles when
57
+ // `isCappedSubMenuWidth` holds; the solver pins the origin.
58
+ left = VIEWPORT_MARGIN;
59
+ }
60
+ let top = parentItemRect.top - panelPaddingTop;
61
+ if (H > vh - 2 * VIEWPORT_MARGIN) {
62
+ return { side, top: VIEWPORT_MARGIN, left, maxHeight: vh - 2 * VIEWPORT_MARGIN };
63
+ }
64
+ if (H > 0) {
65
+ if (top + H > vh - VIEWPORT_MARGIN)
66
+ top = vh - VIEWPORT_MARGIN - H;
67
+ if (top < VIEWPORT_MARGIN)
68
+ top = VIEWPORT_MARGIN;
69
+ return { side, top, left };
70
+ }
71
+ // Unknown height (first frame): align on the parent line with only the
72
+ // top clamp; the bottom clamp SHALL NOT apply (it would pin the panel to
73
+ // the viewport bottom before measurement).
74
+ if (top < VIEWPORT_MARGIN)
75
+ top = VIEWPORT_MARGIN;
76
+ return { side, top, left };
77
+ }
78
+ /** Context key through which a host (`MenuPopover`, `OverflowMenu`) shares its
79
+ * root menu id and close entrypoint with an inner `Menu`. Internal only: no
80
+ * public prop carries it (§2.2, D5). */
81
+ export const MENU_HOST_CONTEXT = "st-menu-host";
82
+ /** True when the viewport is too narrow for the panel: the caller must apply
83
+ * `min-width: 0` with `max-width: calc(100vw - 16px)` (§3.4 step 3). */
84
+ export function isCappedSubMenuWidth(panelWidth, viewportWidth) {
85
+ const W = panelWidth > 0 ? panelWidth : SUBMENU_DEFAULT_WIDTH;
86
+ return W > viewportWidth - 2 * VIEWPORT_MARGIN;
87
+ }
88
+ function sign(p, a, b) {
89
+ return (p.x - b.x) * (a.y - b.y) - (a.x - b.x) * (p.y - b.y);
90
+ }
91
+ /**
92
+ * Inclusive-edge point-in-triangle test (§3.3 step 3). Points on an edge count
93
+ * as inside so a pointer grazing the triangle border never drops the panel.
94
+ */
95
+ export function pointInSafeTriangle(p, a, b, c) {
96
+ const d1 = sign(p, a, b);
97
+ const d2 = sign(p, b, c);
98
+ const d3 = sign(p, c, a);
99
+ const hasNeg = d1 < 0 || d2 < 0 || d3 < 0;
100
+ const hasPos = d1 > 0 || d2 > 0 || d3 > 0;
101
+ return !(hasNeg && hasPos);
102
+ }
103
+ /** Convert viewport coordinates into the containing-block frame (D3, §3.4). */
104
+ export function toContainingBlockPosition(viewportPosition, containingBlockRect) {
105
+ return {
106
+ top: viewportPosition.top - (containingBlockRect?.top ?? 0),
107
+ left: viewportPosition.left - (containingBlockRect?.left ?? 0)
108
+ };
109
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentropic/design-system-svelte",
3
- "version": "0.38.0",
3
+ "version": "0.40.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -56,12 +56,14 @@
56
56
  "!dist/**/diagram-card-corpus.d.ts.map",
57
57
  "!dist/**/diagram-zone-corpus.js",
58
58
  "!dist/**/diagram-zone-corpus.d.ts",
59
- "!dist/**/diagram-zone-corpus.d.ts.map"
59
+ "!dist/**/diagram-zone-corpus.d.ts.map",
60
+ "!dist/**/DiagramSceneFigure.test-support.*"
60
61
  ],
61
62
  "dependencies": {
62
63
  "@lucide/svelte": "^0.562.0",
63
64
  "@sentropic/design-system-rich-text": "0.1.0",
64
- "@sentropic/design-system-themes": "0.12.0",
65
+ "@sentropic/design-system-themes": "0.13.0",
66
+ "@sentropic/diagram-canvas": "0.1.0",
65
67
  "@sentropic/graph": "0.3.0"
66
68
  },
67
69
  "peerDependencies": {
@@ -93,7 +95,7 @@
93
95
  },
94
96
  "devDependencies": {
95
97
  "@sentropic/design-system-theme-dsfr": "0.2.2",
96
- "@sentropic/design-system-themes": "0.12.0",
98
+ "@sentropic/design-system-themes": "0.13.0",
97
99
  "@sveltejs/package": "^2.5.0",
98
100
  "@sveltejs/vite-plugin-svelte": "^7.1.2",
99
101
  "@testing-library/svelte": "^5.2.8",