@oscarpalmer/oui 0.26.0 → 0.27.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.
Files changed (66) hide show
  1. package/dist/css/floatable.css +0 -2
  2. package/dist/css/message.css +1 -0
  3. package/dist/css/reset.css +1 -0
  4. package/dist/js/dialog.d.mts +6 -0
  5. package/dist/js/dialog.mjs +23 -1
  6. package/dist/js/draggable-zszaW1qS.d.mts +155 -0
  7. package/dist/js/floatable/floatable.embedded.d.mts +2 -0
  8. package/dist/js/floatable/{embedded.mjs → floatable.embedded.mjs} +22 -17
  9. package/dist/js/floatable/floatable.standalone.d.mts +2 -0
  10. package/dist/js/floatable/floatable.standalone.mjs +2 -0
  11. package/dist/js/{embedded-ai6cqURc.d.mts → floatable.embedded-YxGwzgbE.d.mts} +13 -10
  12. package/dist/js/focus-trap/focus-trap.embedded.d.mts +2 -0
  13. package/dist/js/focus-trap/{embedded.mjs → focus-trap.embedded.mjs} +17 -15
  14. package/dist/js/focus-trap/focus-trap.standalone.d.mts +2 -0
  15. package/dist/js/focus-trap/focus-trap.standalone.mjs +2 -0
  16. package/dist/js/{embedded-CHK82Uh5.d.mts → focus-trap.embedded-DR8NpZfr.d.mts} +18 -18
  17. package/dist/js/index.d.mts +4 -3
  18. package/dist/js/index.mjs +8 -7
  19. package/dist/js/internal/draggable.d.mts +2 -2
  20. package/dist/js/internal/draggable.mjs +146 -94
  21. package/dist/js/movable/movable.embedded.d.mts +2 -0
  22. package/dist/js/movable/movable.embedded.mjs +184 -0
  23. package/dist/js/movable/movable.standalone.d.mts +2 -0
  24. package/dist/js/movable/movable.standalone.mjs +2 -0
  25. package/dist/js/popover.d.mts +3 -2
  26. package/dist/js/popover.mjs +8 -3
  27. package/dist/js/sortable/sortable.embedded.d.mts +2 -0
  28. package/dist/js/{sortable.mjs → sortable/sortable.embedded.mjs} +88 -63
  29. package/dist/js/sortable/sortable.standalone.d.mts +2 -0
  30. package/dist/js/sortable/sortable.standalone.mjs +2 -0
  31. package/dist/js/splitter.d.mts +24 -0
  32. package/dist/js/splitter.mjs +33 -9
  33. package/dist/js/toolbar.mjs +6 -6
  34. package/dist/js/tooltip.d.mts +12 -2
  35. package/dist/js/tooltip.mjs +49 -33
  36. package/package.json +11 -11
  37. package/src/css/floatable.scss +0 -2
  38. package/src/css/message.scss +1 -0
  39. package/src/css/reset.scss +1 -0
  40. package/src/js/dialog.ts +42 -1
  41. package/src/js/floatable/{embedded.ts → floatable.embedded.ts} +26 -18
  42. package/src/js/floatable/floatable.standalone.ts +6 -0
  43. package/src/js/focus-trap/{embedded.ts → focus-trap.embedded.ts} +20 -17
  44. package/src/js/focus-trap/focus-trap.standalone.ts +1 -0
  45. package/src/js/index.ts +4 -4
  46. package/src/js/internal/draggable.ts +309 -168
  47. package/src/js/movable/movable.embedded.ts +328 -0
  48. package/src/js/movable/movable.standalone.ts +2 -0
  49. package/src/js/popover.ts +11 -2
  50. package/src/js/{sortable.ts → sortable/sortable.embedded.ts} +170 -103
  51. package/src/js/sortable/sortable.standalone.ts +2 -0
  52. package/src/js/splitter.ts +28 -4
  53. package/src/js/tooltip.ts +66 -43
  54. package/dist/js/floatable/embedded.d.mts +0 -2
  55. package/dist/js/floatable/standalone.d.mts +0 -2
  56. package/dist/js/floatable/standalone.mjs +0 -2
  57. package/dist/js/focus-trap/embedded.d.mts +0 -2
  58. package/dist/js/focus-trap/standalone.d.mts +0 -2
  59. package/dist/js/focus-trap/standalone.mjs +0 -6
  60. package/dist/js/movable-dNqBctx3.d.mts +0 -101
  61. package/dist/js/movable.d.mts +0 -2
  62. package/dist/js/movable.mjs +0 -152
  63. package/dist/js/sortable.d.mts +0 -2
  64. package/src/js/floatable/standalone.ts +0 -1
  65. package/src/js/focus-trap/standalone.ts +0 -6
  66. package/src/js/movable.ts +0 -260
@@ -86,8 +86,6 @@ var)) {
86
86
  :where([oui-tooltip-content]) {
87
87
  max-width: 48ch;
88
88
  padding: 0.75em 1em;
89
- overflow: visible;
90
- opacity: 0;
91
89
  background-color: var(--oui-absolute);
92
90
  border-radius: 0.25rem;
93
91
  font-size: 0.875rem;
@@ -19,6 +19,7 @@
19
19
  line-height: 1.25;
20
20
  }
21
21
  :where(.oui-message h2, .oui-message h3, .oui-message h4, .oui-message h5, .oui-message h6) {
22
+ color: var(--oui-foreground, var(--oui-gray-10));
22
23
  font-size: 1em;
23
24
  font-weight: bold;
24
25
  }
@@ -126,6 +126,7 @@ summary) {
126
126
 
127
127
  :where(dialog) {
128
128
  display: none !important;
129
+ overflow: visible;
129
130
  overscroll-behavior: contain;
130
131
  border: none;
131
132
  color: currentcolor;
@@ -1,3 +1,4 @@
1
+ import { h as OuiMovable } from "./draggable-zszaW1qS.mjs";
1
2
  import { RemovableEventListener } from "@oscarpalmer/toretto/models";
2
3
 
3
4
  //#region src/js/dialog.d.ts
@@ -7,6 +8,10 @@ declare class OuiDialog {
7
8
  * Is the dialog open?
8
9
  */
9
10
  get open(): boolean;
11
+ /**
12
+ * Open or close the dialog
13
+ */
14
+ set open(value: boolean);
10
15
  constructor(state: OuiDialogState);
11
16
  /**
12
17
  * Closes the dialog by request
@@ -26,6 +31,7 @@ type OuiDialogState = {
26
31
  element: HTMLDialogElement;
27
32
  listeners: RemovableEventListener[];
28
33
  modal: boolean;
34
+ movable?: OuiMovable;
29
35
  };
30
36
  /**
31
37
  * Get the _OuiDialog_ for an element
@@ -1,5 +1,7 @@
1
- import { getOnBeforeToggleListener } from "./floatable/embedded.mjs";
1
+ import { getOnBeforeToggleListener } from "./floatable/floatable.embedded.mjs";
2
2
  import { attributable } from "./internal/attributable.mjs";
3
+ import { ATTRIBUTE_MOVABLE_HANDLE, createMovable } from "./movable/movable.embedded.mjs";
4
+ import "./movable/movable.standalone.mjs";
3
5
  import { on } from "@oscarpalmer/toretto/event";
4
6
  //#region src/js/dialog.ts
5
7
  var OuiDialog = class {
@@ -10,6 +12,13 @@ var OuiDialog = class {
10
12
  get open() {
11
13
  return this.#state.element.open;
12
14
  }
15
+ /**
16
+ * Open or close the dialog
17
+ */
18
+ set open(value) {
19
+ if (value === true) this.show();
20
+ else if (value === false) this.hide();
21
+ }
13
22
  constructor(state) {
14
23
  this.#state = state;
15
24
  }
@@ -52,6 +61,12 @@ function destroyDialog(state) {
52
61
  function getDialog(element) {
53
62
  return states.get(element)?.dialog;
54
63
  }
64
+ function getMovable(element) {
65
+ const handles = element.querySelectorAll(SELECTOR_MOVER);
66
+ if (handles.length === 0) return;
67
+ for (const handle of handles) handle.setAttribute(ATTRIBUTE_MOVABLE_HANDLE, "");
68
+ return createMovable(element, { container: element.getAttribute(ATTRIBUTE_CONTAINER) ?? void 0 });
69
+ }
55
70
  function getState(element) {
56
71
  const state = {
57
72
  element,
@@ -62,14 +77,19 @@ function getState(element) {
62
77
  const modal = source instanceof HTMLButtonElement && source.command === COMMAND_SHOW_MODAL || element.matches(SELECTOR_MODAL);
63
78
  element.setAttribute(ARIA_MODAL, String(modal));
64
79
  element.setAttribute(ATTRIBUTE_OPEN, "");
80
+ element.focus();
65
81
  } else {
66
82
  element.removeAttribute(ATTRIBUTE_OPEN);
67
83
  element.setAttribute(ARIA_MODAL, String(state.modal));
84
+ element.style.inset = "";
85
+ element.style.position = "";
86
+ element.style.transform = "";
68
87
  }
69
88
  })],
70
89
  modal: element.getAttribute(ARIA_MODAL) === TRUE
71
90
  };
72
91
  state.dialog = new OuiDialog(state);
92
+ state.movable = getMovable(element);
73
93
  return state;
74
94
  }
75
95
  function removeDialog(element) {
@@ -80,10 +100,12 @@ function removeDialog(element) {
80
100
  }
81
101
  const ARIA_MODAL = "aria-modal";
82
102
  const ATTRIBUTE = "oui-dialog";
103
+ const ATTRIBUTE_CONTAINER = `${ATTRIBUTE}-container`;
83
104
  const ATTRIBUTE_OPEN = `${ATTRIBUTE}-open`;
84
105
  const COMMAND_SHOW_MODAL = "show-modal";
85
106
  const EVENT_TOGGLE = "toggle";
86
107
  const MESSAGE = "The element must be an instance of HTMLDialogElement";
108
+ const SELECTOR_MOVER = `[${ATTRIBUTE}-mover]`;
87
109
  const SELECTOR_MODAL = ":modal";
88
110
  const TRUE = "true";
89
111
  const states = /* @__PURE__ */ new WeakMap();
@@ -0,0 +1,155 @@
1
+ import { StyleToggler } from "@oscarpalmer/toretto/style";
2
+ import { EventPosition, PlainObject } from "@oscarpalmer/atoms/models";
3
+
4
+ //#region src/js/movable/movable.embedded.d.ts
5
+ declare class OuiMovable extends OuiDraggable<OuiMovableState> {
6
+ #private;
7
+ constructor(element: HTMLElement, options?: CreateOuiDraggableOptions);
8
+ /**
9
+ * Destroys the _Movable_
10
+ */
11
+ destroy(): void;
12
+ }
13
+ type OuiMovableState = {
14
+ hasHandles?: boolean;
15
+ moved: boolean;
16
+ offset?: Partial<EventPosition>;
17
+ style: OuiMovableStyle;
18
+ };
19
+ type OuiMovableStyle = {
20
+ inset: string;
21
+ position: string;
22
+ };
23
+ /**
24
+ * Creates _(or retrieves)_ a _OuiMovable_ instance for an element
25
+ *
26
+ * @param element Element to make movable
27
+ * @returns _OuiMovable_ instance
28
+ */
29
+ declare function createMovable(element: HTMLElement, options?: CreateOuiDraggableOptions): OuiMovable;
30
+ declare const ATTRIBUTE_MOVABLE = "oui-movable";
31
+ declare const ATTRIBUTE_MOVABLE_HANDLE = "oui-movable-handle";
32
+ //#endregion
33
+ //#region src/js/sortable/sortable.embedded.d.ts
34
+ declare class OuiSortable extends OuiDraggable<OuiSortableState> {
35
+ constructor(element: HTMLElement, options?: CreateOuiDraggableOptions);
36
+ }
37
+ type OuiSortableState = {
38
+ connections: string | null;
39
+ origin?: HTMLElement;
40
+ };
41
+ /**
42
+ * Creates _(or retrieves)_ a _OuiSortable_ instance for an element
43
+ *
44
+ * @param element Element to make sortable
45
+ * @returns _OuiSortable_ instance
46
+ */
47
+ declare function createSortable(element: HTMLElement, options?: CreateOuiDraggableOptions): OuiSortable;
48
+ //#endregion
49
+ //#region src/js/internal/draggable.d.ts
50
+ type CreateOuiDraggableOptions = {
51
+ /**
52
+ * Container to hold the draggable element and restrict its movement within. Can be `body`, `document`, `window`, a _CSS_ selector, or an element. _(If not provided, the draggable element will not have any constraints)_
53
+ */
54
+ container?: string | HTMLElement;
55
+ /**
56
+ * Direction in which the element can be dragged. _(If not provided, the element can be dragged in any direction)_
57
+ */
58
+ direction?: OuiDraggableDirection;
59
+ };
60
+ type OuiDraggableDirection = 'horizontal' | 'vertical' | 'x' | 'y';
61
+ declare abstract class OuiDraggable<ExtraState extends PlainObject = PlainObject> {
62
+ #private;
63
+ get element(): HTMLElement;
64
+ constructor(name: keyof OuiDraggableStates, event: string, attribute: string, element: HTMLElement, options: OuiDraggableOptions<ExtraState>, extras: ExtraState);
65
+ destroy(): void;
66
+ }
67
+ type OuiDragBegin<State extends PlainObject = PlainObject> = (event: MouseEvent | TouchEvent, globals: OuiDraggableGlobals, item: OuiDraggableItem<State>, element: HTMLElement, handle: HTMLElement, position: EventPosition) => void;
68
+ type OuiDragCancel<State extends PlainObject = PlainObject> = (globals: OuiDraggableGlobals, item: OuiDraggableItem<State>) => void;
69
+ type OuiDragEnd<State extends PlainObject = PlainObject> = (event: MouseEvent | TouchEvent, globals: OuiDraggableGlobals, item: OuiDraggableItem<State>, reset: () => void) => void;
70
+ type OuiDragMove<State extends PlainObject = PlainObject> = (event: MouseEvent | TouchEvent, globals: OuiDraggableGlobals, item: OuiDraggableItem<State>, position: OuiDragMovePosition) => PlainObject | undefined;
71
+ type OuiDragMovePosition = {
72
+ calculated: EventPosition;
73
+ original: EventPosition;
74
+ };
75
+ type OuiDraggableBound<Property extends keyof OuiDraggableInstances = keyof OuiDraggableInstances, Instance extends OuiDraggableInstances[Property] = OuiDraggableInstances[Property]> = {
76
+ constructor: new (element: HTMLElement, options?: CreateOuiDraggableOptions) => Instance;
77
+ property: Property;
78
+ };
79
+ type OuiDraggableGlobals = {
80
+ container?: DOMRect;
81
+ element?: OuiDraggableGlobalsElement;
82
+ instances: WeakMap<HTMLElement, OuiDraggableInstances>;
83
+ offset?: EventPosition;
84
+ original?: EventPosition;
85
+ states: WeakMap<HTMLElement, OuiDraggableStates>;
86
+ };
87
+ type OuiDraggableGlobalsElement = {
88
+ node: HTMLElement;
89
+ rectangle: DOMRect;
90
+ };
91
+ type OuiDraggableInstances = {
92
+ movable?: OuiMovable;
93
+ sortable?: OuiSortable;
94
+ };
95
+ type OuiDraggableItem<ExtraState extends PlainObject = PlainObject> = {
96
+ instance: OuiDraggable<ExtraState>;
97
+ state: OuiDraggableState & ExtraState;
98
+ };
99
+ type OuiDraggableOptions<ExtraState extends PlainObject = PlainObject> = {
100
+ container: OuiDraggableOptionsContainer<ExtraState>;
101
+ direction: OuiDraggableOptionsDirection<ExtraState>;
102
+ drag: OuiDraggableOptionsDrag<ExtraState>;
103
+ input?: CreateOuiDraggableOptions;
104
+ position: OuiDraggableOptionsPosition<ExtraState>;
105
+ getDragged(): HTMLElement;
106
+ getOrigin(): HTMLElement | undefined;
107
+ };
108
+ type OuiDraggableOptionsContainer<ExtraState extends PlainObject = PlainObject> = {
109
+ attribute: string;
110
+ map: Map<HTMLElement, Set<OuiDraggable>>;
111
+ onDestroy?: OuiDraggableOptionsContainerOnDestroy<ExtraState>;
112
+ onInitialize?: OuiDraggableOptionsContainerOnInitialize;
113
+ };
114
+ type OuiDraggableOptionsContainerOnDestroy<ExtraState extends PlainObject = PlainObject> = (item: OuiDraggableItem<ExtraState>, container: HTMLElement, empty: boolean) => void;
115
+ type OuiDraggableOptionsContainerOnInitialize<ExtraState extends PlainObject = PlainObject> = (item: OuiDraggableItem<ExtraState>) => void;
116
+ type OuiDraggableOptionsDirection<ExtraState extends PlainObject = PlainObject> = {
117
+ attribute: string;
118
+ onAfter?: OuiDraggableOptionsDirectionOnAfter<ExtraState>;
119
+ };
120
+ type OuiDraggableOptionsDirectionOnAfter<ExtraState extends PlainObject = PlainObject> = (item: OuiDraggableItem<ExtraState>) => void;
121
+ type OuiDraggableOptionsDrag<ExtraState extends PlainObject = PlainObject> = {
122
+ onBegin: OuiDragBegin<ExtraState>;
123
+ onCancel: OuiDragCancel<ExtraState>;
124
+ onEnd: OuiDragEnd<ExtraState>;
125
+ onMove: OuiDragMove<ExtraState>;
126
+ };
127
+ type OuiDraggableOptionsPosition<ExtraState extends PlainObject = PlainObject> = {
128
+ getOffset: OuiDraggableOptionsPositionGetOffset<ExtraState>;
129
+ getOriginal: OuiDraggableOptionsPositionGetOriginal<ExtraState>;
130
+ };
131
+ type OuiDraggableOptionsPositionGetOffset<ExtraState extends PlainObject = PlainObject> = (globals: OuiDraggableGlobals, item: OuiDraggableItem<ExtraState>, element: HTMLElement, position: EventPosition) => EventPosition;
132
+ type OuiDraggableOptionsPositionGetOriginal<ExtraState extends PlainObject = PlainObject> = (globals: OuiDraggableGlobals, item: OuiDraggableItem<ExtraState>, position: EventPosition) => EventPosition;
133
+ type OuiDraggableState = {
134
+ attribute: string;
135
+ container?: HTMLElement;
136
+ element: HTMLElement;
137
+ event: string;
138
+ hasHandles?: boolean;
139
+ horizontal: boolean;
140
+ options: OuiDraggableOptions;
141
+ styling: StyleToggler;
142
+ vertical: boolean;
143
+ };
144
+ type OuiDraggableStates = {
145
+ movable?: OuiDraggableState;
146
+ sortable?: OuiDraggableState;
147
+ };
148
+ declare function addDraggable<Property extends keyof OuiDraggableInstances, Instance extends OuiDraggableInstances[Property]>(this: OuiDraggableBound<Property, Instance>, element: HTMLElement, options?: CreateOuiDraggableOptions): Instance;
149
+ declare function getDraggableStates(element: HTMLElement): OuiDraggableStates | undefined;
150
+ declare function removeDraggable<Property extends keyof OuiDraggableInstances, Instance extends OuiDraggableInstances[Property]>(this: {
151
+ constructor: new (element: HTMLElement) => Instance;
152
+ property: Property;
153
+ }, element: HTMLElement): void;
154
+ //#endregion
155
+ export { OuiDraggableGlobals as a, addDraggable as c, OuiSortable as d, createSortable as f, createMovable as g, OuiMovable as h, OuiDraggableBound as i, getDraggableStates as l, ATTRIBUTE_MOVABLE_HANDLE as m, OuiDragMovePosition as n, OuiDraggableItem as o, ATTRIBUTE_MOVABLE as p, OuiDraggable as r, OuiDraggableState as s, CreateOuiDraggableOptions as t, removeDraggable as u };
@@ -0,0 +1,2 @@
1
+ import { a as OuiFloatableOptions, c as createFloatable, i as OuiFloatable, l as getOnBeforeToggleListener, n as CreateOuiFloatableOptions, o as OuiFloatablePosition, r as FLOATABLE_STATE_OPEN, s as createEmbeddedFloatable, t as ATTRIBUTE_FLOATABLE, u as removeFloatable } from "../floatable.embedded-YxGwzgbE.mjs";
2
+ export { ATTRIBUTE_FLOATABLE, CreateOuiFloatableOptions, FLOATABLE_STATE_OPEN, OuiFloatable, OuiFloatableOptions, OuiFloatablePosition, createEmbeddedFloatable, createFloatable, getOnBeforeToggleListener, removeFloatable };
@@ -1,18 +1,18 @@
1
1
  import { on } from "@oscarpalmer/toretto/event";
2
2
  import { isPlainObject } from "@oscarpalmer/atoms/is";
3
3
  import { isHTMLOrSVGElement } from "@oscarpalmer/toretto/is";
4
- //#region src/js/floatable/embedded.ts
4
+ //#region src/js/floatable/floatable.embedded.ts
5
5
  var OuiFloatable = class {
6
6
  #destroyed = false;
7
7
  #state;
8
8
  /**
9
- * Is the _OuiFloatable_ open?
9
+ * Is the floatable open?
10
10
  */
11
11
  get open() {
12
12
  return this.#state.content.checkVisibility();
13
13
  }
14
14
  /**
15
- * Open or close the _OuiFloatable_
15
+ * Open or close the floatable
16
16
  */
17
17
  set open(value) {
18
18
  if (value === true) this.show();
@@ -25,12 +25,11 @@ var OuiFloatable = class {
25
25
  content.setAttribute(ATTRIBUTE_FLOATABLE, "");
26
26
  content.popover = "manual";
27
27
  }
28
- const anchorName = getAnchorName(anchor);
29
- anchor.style.anchorName = anchorName;
30
- content.style.positionAnchor = anchorName;
28
+ anchor.style.anchorName = state.name;
29
+ content.style.positionAnchor = state.name;
31
30
  }
32
31
  /**
33
- * Destroy the _OuiFloatable_, removing it from the DOM and cleaning up references
32
+ * Destroy the floatable, removing it from the DOM and cleaning up references
34
33
  */
35
34
  destroy() {
36
35
  if (this.#destroyed) return;
@@ -40,19 +39,19 @@ var OuiFloatable = class {
40
39
  this.#state.content = null;
41
40
  }
42
41
  /**
43
- * Closes the _OuiFloatable_
42
+ * Closes the floatable
44
43
  */
45
44
  hide() {
46
45
  if (!this.#destroyed && this.open) this.#state.content.hidePopover();
47
46
  }
48
47
  /**
49
- * Opens the _OuiFloatable_
48
+ * Opens the floatable
50
49
  */
51
50
  show() {
52
51
  if (!this.#destroyed && !this.open) this.#state.content.showPopover();
53
52
  }
54
53
  /**
55
- * Update the position of the _OuiFloatable_, with an optional new position
54
+ * Update the position of the floatable, with an optional new position
56
55
  *
57
56
  * @param position Optional new position
58
57
  */
@@ -79,24 +78,27 @@ function createEmbeddedFloatable(anchor, content, options) {
79
78
  */
80
79
  function createFloatable(anchor, content, options) {
81
80
  const { open, position } = getOptions(options);
82
- const floatable = createInstance(anchor, content, { position }, true);
81
+ const floatable = createInstance(anchor, content, {
82
+ position,
83
+ reusable: false
84
+ }, true);
83
85
  floatable?.update(position);
84
86
  if (open) floatable?.show();
85
87
  return floatable;
86
88
  }
87
89
  function createInstance(anchor, content, options, standalone) {
88
90
  if (!isHTMLOrSVGElement(anchor) || !isHTMLOrSVGElement(content)) throw new TypeError(MESSAGE);
89
- let floatable = instances.get(content);
91
+ let floatable = options.reusable ? void 0 : instances.get(content);
90
92
  if (floatable == null) {
91
93
  floatable = new OuiFloatable(getState(anchor, content, options), standalone);
92
- instances.set(content, floatable);
94
+ if (!options.reusable) instances.set(content, floatable);
93
95
  }
94
96
  return floatable;
95
97
  }
96
98
  function getOnBeforeToggleListener(element) {
97
99
  return on(element, EVENT_BEFORE, (event) => {
98
100
  const { newState, source } = event;
99
- if (newState === STATE_OPEN && source?.getAttribute(ARIA_DISABLED) === TRUE) event.preventDefault();
101
+ if (newState === "open" && source?.getAttribute(ARIA_DISABLED) === TRUE) event.preventDefault();
100
102
  }, { passive: false });
101
103
  }
102
104
  function getOptions(input) {
@@ -117,6 +119,7 @@ function getState(anchor, content, options) {
117
119
  return {
118
120
  anchor,
119
121
  content,
122
+ name: getAnchorName(anchor),
120
123
  options
121
124
  };
122
125
  }
@@ -125,7 +128,9 @@ function removeFloatable(content) {
125
128
  instances.delete(content);
126
129
  }
127
130
  function setPosition(state, override) {
128
- const area = AREAS[getPosition$1(state, override)];
131
+ const position = getPosition$1(state, override);
132
+ const area = AREAS[position];
133
+ state.content.style.positionAnchor = state.name;
129
134
  state.content.style.positionArea = area;
130
135
  state.content.setAttribute(ATTRIBUTE_POSITION, POSITIONS[area]);
131
136
  }
@@ -147,11 +152,11 @@ const ARIA_DISABLED = "aria-disabled";
147
152
  const ATTRIBUTE_FLOATABLE = "oui-floatable";
148
153
  const ATTRIBUTE_POSITION = "oui-position";
149
154
  const EVENT_BEFORE = "beforetoggle";
155
+ const FLOATABLE_STATE_OPEN = "open";
150
156
  const MESSAGE = "Anchor and content must be an HTMLElement or SVGElement";
151
157
  const POSITIONS = Object.fromEntries(Object.entries(AREAS).map(([position, area]) => [area, position]));
152
- const STATE_OPEN = "open";
153
158
  const TRUE = "true";
154
159
  const instances = /* @__PURE__ */ new WeakMap();
155
160
  let index = 0;
156
161
  //#endregion
157
- export { ATTRIBUTE_FLOATABLE, OuiFloatable, createEmbeddedFloatable, createFloatable, getOnBeforeToggleListener, removeFloatable };
162
+ export { ATTRIBUTE_FLOATABLE, FLOATABLE_STATE_OPEN, OuiFloatable, createEmbeddedFloatable, createFloatable, getOnBeforeToggleListener, removeFloatable };
@@ -0,0 +1,2 @@
1
+ import { c as createFloatable, i as OuiFloatable, n as CreateOuiFloatableOptions, o as OuiFloatablePosition } from "../floatable.embedded-YxGwzgbE.mjs";
2
+ export { type CreateOuiFloatableOptions, type OuiFloatable, type OuiFloatablePosition, createFloatable };
@@ -0,0 +1,2 @@
1
+ import { createFloatable } from "./floatable.embedded.mjs";
2
+ export { createFloatable };
@@ -1,41 +1,41 @@
1
1
  import { RemovableEventListener } from "@oscarpalmer/toretto/models";
2
2
 
3
- //#region src/js/floatable/embedded.d.ts
3
+ //#region src/js/floatable/floatable.embedded.d.ts
4
4
  type CreateOuiFloatableOptions = {
5
5
  /**
6
- * Open the _OuiFloatable_ when created? _(defaults to `true`)_
6
+ * Open the floatable when created? _(defaults to `true`)_
7
7
  */
8
8
  open?: boolean;
9
9
  /**
10
- * Position of the _OuiFloatable_ _(defaults to `below`)_
10
+ * Position of the floatable _(defaults to `below`)_
11
11
  */
12
12
  position?: OuiFloatablePosition;
13
13
  };
14
14
  declare class OuiFloatable {
15
15
  #private;
16
16
  /**
17
- * Is the _OuiFloatable_ open?
17
+ * Is the floatable open?
18
18
  */
19
19
  get open(): boolean;
20
20
  /**
21
- * Open or close the _OuiFloatable_
21
+ * Open or close the floatable
22
22
  */
23
23
  set open(value: boolean);
24
24
  constructor(state: OuiFloatableState, standalone: boolean);
25
25
  /**
26
- * Destroy the _OuiFloatable_, removing it from the DOM and cleaning up references
26
+ * Destroy the floatable, removing it from the DOM and cleaning up references
27
27
  */
28
28
  destroy(): void;
29
29
  /**
30
- * Closes the _OuiFloatable_
30
+ * Closes the floatable
31
31
  */
32
32
  hide(): void;
33
33
  /**
34
- * Opens the _OuiFloatable_
34
+ * Opens the floatable
35
35
  */
36
36
  show(): void;
37
37
  /**
38
- * Update the position of the _OuiFloatable_, with an optional new position
38
+ * Update the position of the floatable, with an optional new position
39
39
  *
40
40
  * @param position Optional new position
41
41
  */
@@ -44,11 +44,13 @@ declare class OuiFloatable {
44
44
  type OuiFloatableOptions = {
45
45
  attribute?: string;
46
46
  position: OuiFloatablePosition;
47
+ reusable: boolean;
47
48
  };
48
49
  type OuiFloatablePosition = 'above' | 'above-end' | 'above-start' | 'below' | 'below-end' | 'below-start' | 'end' | 'end-bottom' | 'end-top' | 'start' | 'start-bottom' | 'start-top';
49
50
  type OuiFloatableState = {
50
51
  anchor: HTMLElement;
51
52
  content: HTMLElement;
53
+ name: string;
52
54
  options: OuiFloatableOptions;
53
55
  };
54
56
  declare function createEmbeddedFloatable(anchor: HTMLElement, content: HTMLElement, options: OuiFloatableOptions): OuiFloatable;
@@ -64,5 +66,6 @@ declare function createFloatable(anchor: HTMLElement, content: HTMLElement, opti
64
66
  declare function getOnBeforeToggleListener(element: HTMLElement): RemovableEventListener;
65
67
  declare function removeFloatable(content: HTMLElement): void;
66
68
  declare const ATTRIBUTE_FLOATABLE = "oui-floatable";
69
+ declare const FLOATABLE_STATE_OPEN = "open";
67
70
  //#endregion
68
- export { createEmbeddedFloatable as a, removeFloatable as c, OuiFloatablePosition as i, OuiFloatable as n, createFloatable as o, OuiFloatableOptions as r, getOnBeforeToggleListener as s, ATTRIBUTE_FLOATABLE as t };
71
+ export { OuiFloatableOptions as a, createFloatable as c, OuiFloatable as i, getOnBeforeToggleListener as l, CreateOuiFloatableOptions as n, OuiFloatablePosition as o, FLOATABLE_STATE_OPEN as r, createEmbeddedFloatable as s, ATTRIBUTE_FLOATABLE as t, removeFloatable as u };
@@ -0,0 +1,2 @@
1
+ import { a as OuiFocusTrapOptions, i as OuiFocusTrap, n as ATTRIBUTE_FOCUSTRAP_CONTAIN, o as createFocusTrap, r as ATTRIBUTE_FOCUSTRAP_NOESCAPE, s as removeFocusTrap, t as ATTRIBUTE_FOCUSTRAP } from "../focus-trap.embedded-DR8NpZfr.mjs";
2
+ export { ATTRIBUTE_FOCUSTRAP, ATTRIBUTE_FOCUSTRAP_CONTAIN, ATTRIBUTE_FOCUSTRAP_NOESCAPE, OuiFocusTrap, OuiFocusTrapOptions, createFocusTrap, removeFocusTrap };
@@ -1,48 +1,49 @@
1
+ import { attributable } from "../internal/attributable.mjs";
1
2
  import { on } from "@oscarpalmer/toretto/event";
2
3
  import { isPlainObject } from "@oscarpalmer/atoms/is";
3
4
  import { isHTMLOrSVGElement } from "@oscarpalmer/toretto/is";
4
5
  import { clamp } from "@oscarpalmer/atoms/number";
5
6
  import { findAncestor } from "@oscarpalmer/toretto/find";
6
7
  import { getFocusable } from "@oscarpalmer/toretto/focusable";
7
- //#region src/js/focus-trap/embedded.ts
8
+ //#region src/js/focus-trap/focus-trap.embedded.ts
8
9
  var OuiFocusTrap = class {
9
10
  #destroyed = false;
10
11
  #tabIndex;
11
12
  #state;
12
13
  /**
13
- * Is focused maintained within the _FocusTrap_ when clicking outside of it?
14
+ * Is focused maintained within the _focus trap_ when clicking outside of it?
14
15
  */
15
16
  get contain() {
16
17
  return this.#state.element.hasAttribute(ATTRIBUTE_FOCUSTRAP_CONTAIN);
17
18
  }
18
19
  /**
19
- * Should focus be maintained within the _FocusTrap_ when clicking outside of it?
20
+ * Should focus be maintained within the _focus trap_ when clicking outside of it?
20
21
  */
21
22
  set contain(value) {
22
23
  if (value === true) this.#state.element.setAttribute(ATTRIBUTE_FOCUSTRAP_CONTAIN, "");
23
24
  else if (value === false) this.#state.element.removeAttribute(ATTRIBUTE_FOCUSTRAP_CONTAIN);
24
25
  }
25
26
  /**
26
- * Is the _FocusTrap_ disabled?
27
+ * Is the _focus trap_ disabled?
27
28
  */
28
29
  get disabled() {
29
30
  return this.#state.disabled;
30
31
  }
31
32
  /**
32
- * Should the _FocusTrap_ be disabled?
33
+ * Should the _focus trap_ be disabled?
33
34
  */
34
35
  set disabled(value) {
35
36
  if (value === true) this.disable();
36
37
  else if (value === false) this.enable();
37
38
  }
38
39
  /**
39
- * Is focus allowed to escape when pressing _Escape_ within the _FocusTrap_?
40
+ * Is focus allowed to escape when pressing _Escape_ within the _focus trap_?
40
41
  */
41
42
  get noescape() {
42
43
  return this.#state.element.hasAttribute(ATTRIBUTE_FOCUSTRAP_NOESCAPE);
43
44
  }
44
45
  /**
45
- * Should the _FocusTrap_ allow focus to escape when pressing _Escape_?
46
+ * Should the _focus trap_ allow focus to escape when pressing _Escape_?
46
47
  */
47
48
  set noescape(value) {
48
49
  if (value === true) this.#state.element.setAttribute(ATTRIBUTE_FOCUSTRAP_NOESCAPE, "");
@@ -58,7 +59,7 @@ var OuiFocusTrap = class {
58
59
  states.set(this, state);
59
60
  }
60
61
  /**
61
- * Destroys the _FocusTrap_
62
+ * Destroys the _focus trap_
62
63
  */
63
64
  destroy() {
64
65
  if (this.#destroyed) return;
@@ -73,32 +74,32 @@ var OuiFocusTrap = class {
73
74
  this.#state.element = void 0;
74
75
  }
75
76
  /**
76
- * Disables the _FocusTrap_
77
+ * Disables the _focus trap_
77
78
  */
78
79
  disable() {
79
80
  if (!this.#destroyed && !(this.disabled || this.#state.options.noescape)) setDisabled(this, this.#state, true);
80
81
  }
81
82
  /**
82
- * Enables the _FocusTrap_
83
+ * Enables the _focus trap_
83
84
  */
84
85
  enable() {
85
86
  if (!this.#destroyed && this.disabled) setDisabled(this, this.#state, false);
86
87
  }
87
88
  /**
88
- * Focuses the _FocusTrap_
89
+ * Focuses the _focus trap_
89
90
  *
90
- * @param last When `true`, focuses the last focusable element within the _FocusTrap_ instead of the first
91
+ * @param last When `true`, focuses the last focusable element within the _focus trap_ instead of the first
91
92
  */
92
93
  focus(last) {
93
94
  if (!this.#destroyed && !this.disabled) tabToTrap(this, getFocusable(this.#state.element), this.#state.element, last ? -1 : 0);
94
95
  }
95
96
  };
96
97
  /**
97
- * Creates _(or retrieves)_ a _FocusTrap_ for an element
98
+ * Creates _(or retrieves)_ a _focus trap_ for an element
98
99
  *
99
100
  * @param element Element to trap focus within
100
- * @param options _FocusTrap_ options
101
- * @returns _FocusTrap_ instance
101
+ * @param options _Focus trap_ options
102
+ * @returns _Focus trap_ instance
102
103
  */
103
104
  function createFocusTrap(element, options) {
104
105
  if (!isHTMLOrSVGElement(element)) throw new TypeError(MESSAGE);
@@ -226,6 +227,7 @@ const disabled = /* @__PURE__ */ new Set();
226
227
  const instances = /* @__PURE__ */ new WeakMap();
227
228
  const states = /* @__PURE__ */ new WeakMap();
228
229
  let lastTarget;
230
+ attributable(ATTRIBUTE_FOCUSTRAP, createFocusTrap, removeFocusTrap);
229
231
  on(document, "focusin", onFocusIn, EVENT_OPTIONS);
230
232
  on(document, "keydown", onKeydown, EVENT_OPTIONS);
231
233
  on(document, "mousedown", onPointerdown, EVENT_OPTIONS);
@@ -0,0 +1,2 @@
1
+ import { a as OuiFocusTrapOptions, i as OuiFocusTrap, o as createFocusTrap } from "../focus-trap.embedded-DR8NpZfr.mjs";
2
+ export { type OuiFocusTrap, type OuiFocusTrapOptions, createFocusTrap };
@@ -0,0 +1,2 @@
1
+ import { createFocusTrap } from "./focus-trap.embedded.mjs";
2
+ export { createFocusTrap };