@rivinia/popup 0.0.0-stage → 1.0.0-rc.4

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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,13 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0-rc.4
4
+
5
+ - First public release of the shared headless positioning and dismissal core.
6
+ - Select and Menu consume Popup as a regular runtime dependency; host-specific behavior remains in each package.
7
+
8
+ ## 0.0.0 — Unreleased development
9
+
10
+ - Add shared headless popup position calculation and per-host dismissal
11
+ listener binding for Rivinia UI packages.
12
+ - Development-only version; release-group version alignment happens only at
13
+ an approved release.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rivinia contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,53 @@
1
- # Temporary Holding Version
1
+ # @rivinia/popup
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Headless popup positioning and dismissal mechanics shared by Rivinia UI packages.
4
+ This package contains no popup markup, styles, focus policy, or component state.
5
+
6
+ ## Position calculation
7
+
8
+ `computePopupPosition` calculates viewport coordinates from trigger and panel
9
+ geometry. The host supplies direction explicitly, so applications can retain
10
+ their own direction source.
11
+
12
+ ```ts
13
+ import { computePopupPosition } from '@rivinia/popup';
14
+
15
+ const position = computePopupPosition(
16
+ { left: 24, top: 40, width: 160, height: 36 },
17
+ { width: 220, height: 180 },
18
+ 'bottom-start',
19
+ { width: window.innerWidth, height: window.innerHeight },
20
+ 'ltr',
21
+ );
22
+ ```
23
+
24
+ The result contains `left`, `top`, and whether vertical placement flipped.
25
+ Coordinates are clamped to the viewport edge inset. `POPUP_GAP` and
26
+ `POPUP_EDGE_INSET` expose the default geometry constants.
27
+
28
+ ## Dismissal binding
29
+
30
+ `bindPopupDismissal(options, destroyRef)` attaches outside-pointer, scroll,
31
+ and resize listeners for one open popup host. The caller supplies the browser
32
+ `document` and `window` (or `null` during server rendering), host and panel
33
+ lookups, the editable-focus predicate, and a dismiss callback. The binding
34
+ cleans up listeners through Angular `DestroyRef` and the optional effect
35
+ cleanup callback. Null browser objects make it a no-op, keeping the helper
36
+ safe during SSR.
37
+
38
+ The host remains responsible for open state, focus movement and restoration,
39
+ keyboard ownership, event cancellation, row semantics, styling, and sizing.
40
+ Select and Menu intentionally retain their different behavior policies.
41
+
42
+ ## Compatibility
43
+
44
+ Package version: **1.0.0-rc.4**. This is the first public release of the
45
+ shared popup core. See the [core specification](https://github.com/abdelfattahqandil21-oss/Revinia/blob/popup/v1.0.0-rc.4/projects/popup/specifications/popup-core.md)
46
+ and [release notes](https://github.com/abdelfattahqandil21-oss/Revinia/blob/popup/v1.0.0-rc.4/projects/popup/CHANGELOG.md). The
47
+ [release policy](https://github.com/abdelfattahqandil21-oss/Revinia/blob/popup/v1.0.0-rc.4/docs/engineering/VERSIONING.md)
48
+ describes synchronized package versioning.
49
+
50
+
51
+ This package is under development at `0.0.0`. It is included in the
52
+ `rivinia-1.0` synchronized release group but aligns to that group's version
53
+ only as part of an explicitly approved release.
@@ -0,0 +1,66 @@
1
+ const POPUP_GAP = 6;
2
+ const POPUP_EDGE_INSET = 8;
3
+ function computePopupPosition(trigger, panel, placement, viewport, direction, gap = 6) {
4
+ const [vertical, horizontal] = placement.split("-");
5
+ const below = vertical !== "top";
6
+ const alignLeft = horizontal !== "end" !== (direction === "rtl");
7
+ let left = alignLeft ? trigger.left : trigger.left + trigger.width - panel.width;
8
+ let top = below ? trigger.top + trigger.height + gap : trigger.top - gap - panel.height;
9
+ let flipped = false;
10
+ const fitsBelow = trigger.top + trigger.height + gap + panel.height <= viewport.height - 8;
11
+ const fitsAbove = trigger.top - gap - panel.height >= 8;
12
+ if (below && top + panel.height > viewport.height - 8 && fitsAbove) {
13
+ top = trigger.top - gap - panel.height;
14
+ flipped = true;
15
+ } else if (!below && top < 8 && fitsBelow) {
16
+ top = trigger.top + trigger.height + gap;
17
+ flipped = true;
18
+ }
19
+ const fitsLeft = trigger.left + trigger.width - panel.width >= 8;
20
+ const fitsRight = trigger.left + panel.width <= viewport.width - 8;
21
+ if (alignLeft && left + panel.width > viewport.width - 8 && fitsLeft) left = trigger.left + trigger.width - panel.width;
22
+ else if (!alignLeft && left < 8 && fitsRight) left = trigger.left;
23
+ left = Math.min(Math.max(left, 8), Math.max(8, viewport.width - panel.width - 8));
24
+ top = Math.min(Math.max(top, 8), Math.max(8, viewport.height - panel.height - 8));
25
+ return {
26
+ left: Math.round(left),
27
+ top: Math.round(top),
28
+ flipped
29
+ };
30
+ }
31
+ function bindPopupDismissal(options, destroyRef) {
32
+ const { document: doc, window: win } = options;
33
+ if (!doc || !win) return;
34
+ const onPointer = (event) => {
35
+ const host = options.host();
36
+ if (host && !host.contains(event.target)) options.dismiss();
37
+ };
38
+ const onScroll = (event) => {
39
+ const panel = options.panel();
40
+ if (panel && event.target instanceof Node && panel.contains(event.target)) return;
41
+ options.dismiss();
42
+ };
43
+ let widthAtOpen = win.innerWidth;
44
+ const onResize = () => {
45
+ const width = win.innerWidth;
46
+ if (width === widthAtOpen && options.editableFocusInsidePanel()) return;
47
+ widthAtOpen = width;
48
+ options.dismiss();
49
+ };
50
+ doc.addEventListener("pointerdown", onPointer);
51
+ win.addEventListener("scroll", onScroll, true);
52
+ win.addEventListener("resize", onResize);
53
+ let active = true;
54
+ const cleanup = () => {
55
+ if (!active) return;
56
+ active = false;
57
+ doc.removeEventListener("pointerdown", onPointer);
58
+ win.removeEventListener("scroll", onScroll, true);
59
+ win.removeEventListener("resize", onResize);
60
+ };
61
+ options.onCleanup?.(cleanup);
62
+ destroyRef.onDestroy(cleanup);
63
+ }
64
+ export { POPUP_EDGE_INSET, POPUP_GAP, bindPopupDismissal, computePopupPosition };
65
+
66
+ //# sourceMappingURL=rivinia-popup.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rivinia-popup.mjs","names":[],"sources":["../../../projects/popup/src/lib/popup-core.ts"],"sourcesContent":["import type { DestroyRef } from '@angular/core';\n\nexport type PopupDirection = 'ltr' | 'rtl';\nexport type PopupPlacement = 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end';\n\nexport interface PopupRect {\n readonly left: number;\n readonly top: number;\n readonly width: number;\n readonly height: number;\n}\n\nexport interface PopupSize {\n readonly width: number;\n readonly height: number;\n}\n\nexport interface PopupViewport {\n readonly width: number;\n readonly height: number;\n}\n\nexport interface PopupPosition {\n readonly left: number;\n readonly top: number;\n readonly flipped: boolean;\n}\n\nexport interface PopupDismissalOptions {\n readonly document: Document | null;\n readonly window: Window | null;\n readonly host: () => Element | null;\n readonly panel: () => Element | null;\n readonly editableFocusInsidePanel: () => boolean;\n readonly dismiss: () => void;\n readonly onCleanup?: (cleanup: () => void) => void;\n}\n\nexport const POPUP_GAP = 6;\nexport const POPUP_EDGE_INSET = 8;\n\n/** Pure geometry calculation. Direction is always supplied by the host. */\nexport function computePopupPosition(\n trigger: PopupRect,\n panel: PopupSize,\n placement: PopupPlacement,\n viewport: PopupViewport,\n direction: PopupDirection,\n gap = POPUP_GAP,\n): PopupPosition {\n const [vertical, horizontal] = placement.split('-');\n const below = vertical !== 'top';\n const alignLeft = (horizontal !== 'end') !== (direction === 'rtl');\n\n let left = alignLeft ? trigger.left : trigger.left + trigger.width - panel.width;\n let top = below ? trigger.top + trigger.height + gap : trigger.top - gap - panel.height;\n let flipped = false;\n\n const fitsBelow = trigger.top + trigger.height + gap + panel.height <= viewport.height - POPUP_EDGE_INSET;\n const fitsAbove = trigger.top - gap - panel.height >= POPUP_EDGE_INSET;\n if (below && top + panel.height > viewport.height - POPUP_EDGE_INSET && fitsAbove) {\n top = trigger.top - gap - panel.height;\n flipped = true;\n } else if (!below && top < POPUP_EDGE_INSET && fitsBelow) {\n top = trigger.top + trigger.height + gap;\n flipped = true;\n }\n\n const fitsLeft = trigger.left + trigger.width - panel.width >= POPUP_EDGE_INSET;\n const fitsRight = trigger.left + panel.width <= viewport.width - POPUP_EDGE_INSET;\n if (alignLeft && left + panel.width > viewport.width - POPUP_EDGE_INSET && fitsLeft) {\n left = trigger.left + trigger.width - panel.width;\n } else if (!alignLeft && left < POPUP_EDGE_INSET && fitsRight) {\n left = trigger.left;\n }\n\n left = Math.min(Math.max(left, POPUP_EDGE_INSET), Math.max(POPUP_EDGE_INSET, viewport.width - panel.width - POPUP_EDGE_INSET));\n top = Math.min(Math.max(top, POPUP_EDGE_INSET), Math.max(POPUP_EDGE_INSET, viewport.height - panel.height - POPUP_EDGE_INSET));\n return { left: Math.round(left), top: Math.round(top), flipped };\n}\n\n/** Attach equivalent outside-dismissal listeners to one open host instance. */\nexport function bindPopupDismissal(\n options: PopupDismissalOptions,\n destroyRef: DestroyRef,\n): void {\n const { document: doc, window: win } = options;\n if (!doc || !win) return;\n\n const onPointer = (event: PointerEvent) => {\n const host = options.host();\n if (host && !host.contains(event.target as Node)) options.dismiss();\n };\n const onScroll = (event: Event) => {\n const panel = options.panel();\n if (panel && event.target instanceof Node && panel.contains(event.target)) return;\n options.dismiss();\n };\n let widthAtOpen = win.innerWidth;\n const onResize = () => {\n const width = win.innerWidth;\n if (width === widthAtOpen && options.editableFocusInsidePanel()) return;\n widthAtOpen = width;\n options.dismiss();\n };\n\n doc.addEventListener('pointerdown', onPointer);\n win.addEventListener('scroll', onScroll, true);\n win.addEventListener('resize', onResize);\n let active = true;\n const cleanup = () => {\n if (!active) return;\n active = false;\n doc.removeEventListener('pointerdown', onPointer);\n win.removeEventListener('scroll', onScroll, true);\n win.removeEventListener('resize', onResize);\n };\n options.onCleanup?.(cleanup);\n destroyRef.onDestroy(cleanup);\n}\n"],"mappings":"AAsCA,MAAa,YAAY;AACzB,MAAa,mBAAmB;AAGhC,SAAgB,qBACd,SACA,OACA,WACA,UACA,WACA,MAAA,GAAe;CAEf,MAAM,CAAC,UAAU,cAAc,UAAU,MAAM,GAAG;CAClD,MAAM,QAAQ,aAAa;CAC3B,MAAM,YAAa,eAAe,WAAY,cAAc;CAE5D,IAAI,OAAO,YAAY,QAAQ,OAAO,QAAQ,OAAO,QAAQ,QAAQ,MAAM;CAC3E,IAAI,MAAM,QAAQ,QAAQ,MAAM,QAAQ,SAAS,MAAM,QAAQ,MAAM,MAAM,MAAM;CACjF,IAAI,UAAU;CAEd,MAAM,YAAY,QAAQ,MAAM,QAAQ,SAAS,MAAM,MAAM,UAAU,SAAS,SAAA;CAChF,MAAM,YAAY,QAAQ,MAAM,MAAM,MAAM,UAAA;CAC5C,IAAI,SAAS,MAAM,MAAM,SAAS,SAAS,SAAA,KAA6B,WAAW;EACjF,MAAM,QAAQ,MAAM,MAAM,MAAM;EAChC,UAAU;CACZ,OAAO,IAAI,CAAC,SAAS,MAAA,KAA0B,WAAW;EACxD,MAAM,QAAQ,MAAM,QAAQ,SAAS;EACrC,UAAU;CACZ;CAEA,MAAM,WAAW,QAAQ,OAAO,QAAQ,QAAQ,MAAM,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ACnB,IAAI,CAAC,QAAQ;EACb,SAAS;EACT,IAAI,oBAAoB,eAAe,SAAS;EAChD,IAAI,oBAAoB,UAAU,UAAU,IAAI;EAChD,IAAI,oBAAoB,UAAU,QAAQ;CAC5C;CACA,QAAQ,YAAY,OAAO;CAC3B,WAAW,UAAU,OAAO;AAC9B"}
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@rivinia/popup",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "1.0.0-rc.4",
4
+ "description": "Headless shared popup mechanics for Rivinia Angular components.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/abdelfattahqandil21-oss/Revinia.git",
9
+ "directory": "projects/popup"
10
+ },
11
+ "homepage": "https://github.com/abdelfattahqandil21-oss/Revinia/tree/main/projects/popup#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/abdelfattahqandil21-oss/Revinia/issues"
14
+ },
15
+ "engines": {
16
+ "node": "^22.22.3 || ^24.15.0 || >=26.0.0"
17
+ },
18
+ "peerDependencies": {
19
+ "@angular/core": "^22.0.0"
20
+ },
21
+ "sideEffects": false,
22
+ "module": "fesm2022/rivinia-popup.mjs",
23
+ "typings": "types/rivinia-popup.d.ts",
24
+ "exports": {
25
+ "./package.json": {
26
+ "default": "./package.json"
27
+ },
28
+ ".": {
29
+ "types": "./types/rivinia-popup.d.ts",
30
+ "default": "./fesm2022/rivinia-popup.mjs"
31
+ }
32
+ },
33
+ "type": "module",
34
+ "dependencies": {
35
+ "tslib": "^2.3.0"
36
+ }
6
37
  }
@@ -0,0 +1,38 @@
1
+ import { DestroyRef } from "@angular/core";
2
+ type PopupDirection = 'ltr' | 'rtl';
3
+ type PopupPlacement = 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end';
4
+ interface PopupRect {
5
+ readonly left: number;
6
+ readonly top: number;
7
+ readonly width: number;
8
+ readonly height: number;
9
+ }
10
+ interface PopupSize {
11
+ readonly width: number;
12
+ readonly height: number;
13
+ }
14
+ interface PopupViewport {
15
+ readonly width: number;
16
+ readonly height: number;
17
+ }
18
+ interface PopupPosition {
19
+ readonly left: number;
20
+ readonly top: number;
21
+ readonly flipped: boolean;
22
+ }
23
+ interface PopupDismissalOptions {
24
+ readonly document: Document | null;
25
+ readonly window: Window | null;
26
+ readonly host: () => Element | null;
27
+ readonly panel: () => Element | null;
28
+ readonly editableFocusInsidePanel: () => boolean;
29
+ readonly dismiss: () => void;
30
+ readonly onCleanup?: (cleanup: () => void) => void;
31
+ }
32
+ export declare const POPUP_GAP = 6;
33
+ export declare const POPUP_EDGE_INSET = 8;
34
+ /** Pure geometry calculation. Direction is always supplied by the host. */
35
+ export declare function computePopupPosition(trigger: PopupRect, panel: PopupSize, placement: PopupPlacement, viewport: PopupViewport, direction: PopupDirection, gap?: number): PopupPosition;
36
+ /** Attach equivalent outside-dismissal listeners to one open host instance. */
37
+ export declare function bindPopupDismissal(options: PopupDismissalOptions, destroyRef: DestroyRef): void;
38
+ export type { PopupDirection, PopupDismissalOptions, PopupPlacement, PopupPosition, PopupRect, PopupSize, PopupViewport };