@oscarpalmer/oui 0.16.0 → 0.18.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.
- package/dist/css/badge.css +3 -3
- package/dist/css/content.css +9 -11
- package/dist/css/form.css +36 -22
- package/dist/css/message.css +4 -0
- package/dist/css/popover.css +3 -0
- package/dist/css/reset.css +176 -56
- package/dist/css/splitter.css +3 -3
- package/dist/css/tooltip.css +8 -0
- package/dist/js/attributable.full.js +48 -0
- package/dist/js/attributable.js +30 -45
- package/dist/js/floatable.full.js +413 -0
- package/dist/js/floatable.js +259 -132
- package/dist/js/focus-trap/embedded.full.js +351 -0
- package/dist/js/focus-trap/embedded.js +131 -131
- package/dist/js/focus-trap/standalone.full.js +402 -0
- package/dist/js/focus-trap/standalone.js +4 -4
- package/dist/js/index.js +4 -5
- package/dist/js/oui.full.js +1596 -0
- package/dist/js/popover.full.js +822 -0
- package/dist/js/popover.js +83 -156
- package/dist/js/splitter.full.js +605 -0
- package/dist/js/splitter.js +279 -200
- package/dist/js/tooltip.full.js +679 -0
- package/dist/js/tooltip.js +159 -144
- package/package.json +31 -59
- package/src/css/content.scss +1 -2
- package/src/css/form.scss +12 -4
- package/src/css/message.scss +3 -0
- package/src/css/mixins.scss +7 -0
- package/src/css/popover.scss +4 -0
- package/src/css/reset.scss +180 -54
- package/src/css/splitter.scss +3 -3
- package/src/css/tooltip.scss +8 -0
- package/src/js/floatable.ts +458 -124
- package/src/js/focus-trap/embedded.ts +149 -64
- package/src/js/focus-trap/standalone.ts +4 -4
- package/src/js/index.ts +1 -0
- package/src/js/popover.ts +51 -114
- package/src/js/splitter.ts +346 -109
- package/src/js/tooltip.ts +157 -63
- package/types/floatable.d.ts +19 -7
- package/types/focus-trap/embedded.d.ts +18 -5
- package/types/index.d.ts +1 -0
- package/types/popover.d.ts +2 -0
- package/types/splitter.d.ts +13 -1
- package/types/tooltip.d.ts +2 -1
- package/dist/js/attributable.cjs +0 -51
- package/dist/js/floatable.cjs +0 -134
- package/dist/js/focus-trap/embedded.cjs +0 -150
- package/dist/js/focus-trap/standalone.cjs +0 -8
- package/dist/js/index.cjs +0 -6
- package/dist/js/popover.cjs +0 -160
- package/dist/js/splitter.cjs +0 -211
- package/dist/js/tooltip.cjs +0 -160
- package/types/attributable.d.cts +0 -5
- package/types/floatable.d.cts +0 -16
- package/types/focus-trap/embedded.d.cts +0 -15
- package/types/focus-trap/standalone.d.cts +0 -3
- package/types/index.d.cts +0 -14
- package/types/popover.d.cts +0 -14
- package/types/splitter.d.cts +0 -10
- package/types/tooltip.d.cts +0 -3
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const number = require("@oscarpalmer/atoms/number");
|
|
4
|
-
const event = require("@oscarpalmer/toretto/event");
|
|
5
|
-
const find = require("@oscarpalmer/toretto/find");
|
|
6
|
-
const focusable = require("@oscarpalmer/toretto/focusable");
|
|
7
|
-
class FocusTrap {
|
|
8
|
-
constructor(element) {
|
|
9
|
-
this.element = element;
|
|
10
|
-
element.setAttribute("aria-modal", "true");
|
|
11
|
-
element.setAttribute("tabindex", "-1");
|
|
12
|
-
}
|
|
13
|
-
active = true;
|
|
14
|
-
destroy() {
|
|
15
|
-
this.element = void 0;
|
|
16
|
-
}
|
|
17
|
-
disable() {
|
|
18
|
-
if (this.active && !this.element.hasAttribute(`${selector}-noescape`)) {
|
|
19
|
-
setDisabled(this, true);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
enable() {
|
|
23
|
-
if (!this.active) {
|
|
24
|
-
setDisabled(this, false);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function createFocusTrap(element) {
|
|
29
|
-
let focusTrap = focusTraps.get(element);
|
|
30
|
-
if (focusTrap == null) {
|
|
31
|
-
focusTrap = new FocusTrap(element);
|
|
32
|
-
focusTraps.set(element, focusTrap);
|
|
33
|
-
}
|
|
34
|
-
return focusTrap;
|
|
35
|
-
}
|
|
36
|
-
function onEscape(event2) {
|
|
37
|
-
focusTraps.get(
|
|
38
|
-
find.findAncestor(event2.target, `[${selector}]`)
|
|
39
|
-
)?.disable();
|
|
40
|
-
}
|
|
41
|
-
function onFocusIn(event2) {
|
|
42
|
-
lastTarget = find.findAncestor(event2.target, `[${selector}]`) == null ? void 0 : event2.target;
|
|
43
|
-
}
|
|
44
|
-
function onKeydown(event2) {
|
|
45
|
-
switch (event2.key) {
|
|
46
|
-
case "Escape":
|
|
47
|
-
onEscape(event2);
|
|
48
|
-
break;
|
|
49
|
-
case "Tab":
|
|
50
|
-
onTab(event2);
|
|
51
|
-
break;
|
|
52
|
-
default:
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
function onPointerdown(event2) {
|
|
57
|
-
const lastFocusTrap = find.findAncestor(
|
|
58
|
-
lastTarget,
|
|
59
|
-
`[${selector}]`
|
|
60
|
-
);
|
|
61
|
-
const nextFocusTrap = find.findAncestor(
|
|
62
|
-
event2.target,
|
|
63
|
-
`[${selector}]`
|
|
64
|
-
);
|
|
65
|
-
if (lastFocusTrap != null && nextFocusTrap !== lastFocusTrap) {
|
|
66
|
-
event2.preventDefault();
|
|
67
|
-
lastTarget?.focus();
|
|
68
|
-
}
|
|
69
|
-
if (disabled.size === 0) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
for (const focusTrap of disabled) {
|
|
73
|
-
if (focusTrap.element !== nextFocusTrap) {
|
|
74
|
-
focusTrap.enable();
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
function onTab(event2) {
|
|
80
|
-
const element = find.findAncestor(
|
|
81
|
-
event2.target,
|
|
82
|
-
`[${selector}]`
|
|
83
|
-
);
|
|
84
|
-
const focusTrap = focusTraps.get(element);
|
|
85
|
-
if (focusTrap == null) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
if (focusTrap.active) {
|
|
89
|
-
event2.preventDefault();
|
|
90
|
-
}
|
|
91
|
-
const elements = focusable.getFocusable(element);
|
|
92
|
-
const index = elements.indexOf(event2.target);
|
|
93
|
-
if (index === -1 || elements.length === 0) {
|
|
94
|
-
tabToTrap(focusTrap, elements, element);
|
|
95
|
-
} else {
|
|
96
|
-
tabToElement(event2, focusTrap, elements, index);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
function setDisabled(focusTrap, value) {
|
|
100
|
-
focusTrap.element.setAttribute("aria-modal", String(!value));
|
|
101
|
-
focusTrap.active = !value;
|
|
102
|
-
if (value) {
|
|
103
|
-
disabled.add(focusTrap);
|
|
104
|
-
} else {
|
|
105
|
-
disabled.delete(focusTrap);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
function tabToElement(event2, focusTrap, elements, index) {
|
|
109
|
-
const next = number.clamp(
|
|
110
|
-
index + (event2.shiftKey ? -1 : 1),
|
|
111
|
-
0,
|
|
112
|
-
elements.length - 1,
|
|
113
|
-
true
|
|
114
|
-
);
|
|
115
|
-
if (!focusTrap.active) {
|
|
116
|
-
if (index === length - 1 && next === 0 || index === 0 && next === length - 1) {
|
|
117
|
-
lastTarget = void 0;
|
|
118
|
-
focusTrap.enable();
|
|
119
|
-
}
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
elements[next].focus();
|
|
123
|
-
lastTarget = elements[next];
|
|
124
|
-
}
|
|
125
|
-
function tabToTrap(focusTrap, elements, element) {
|
|
126
|
-
if (focusTrap.active) {
|
|
127
|
-
const next = length === 0 ? element : elements[0];
|
|
128
|
-
next.focus();
|
|
129
|
-
lastTarget = next;
|
|
130
|
-
} else {
|
|
131
|
-
lastTarget = void 0;
|
|
132
|
-
focusTrap.enable();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
const disabled = /* @__PURE__ */ new Set();
|
|
136
|
-
const eventOptions = {
|
|
137
|
-
capture: true,
|
|
138
|
-
passive: false
|
|
139
|
-
};
|
|
140
|
-
const focusTraps = /* @__PURE__ */ new WeakMap();
|
|
141
|
-
let lastTarget;
|
|
142
|
-
const selector = "oui-focus-trap";
|
|
143
|
-
event.on(document, "focusin", onFocusIn, eventOptions);
|
|
144
|
-
event.on(document, "keydown", onKeydown, eventOptions);
|
|
145
|
-
event.on(document, "mousedown", onPointerdown, eventOptions);
|
|
146
|
-
event.on(document, "touchstart", onPointerdown, eventOptions);
|
|
147
|
-
exports.FocusTrap = FocusTrap;
|
|
148
|
-
exports.createFocusTrap = createFocusTrap;
|
|
149
|
-
exports.focusTraps = focusTraps;
|
|
150
|
-
exports.selector = selector;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const attributable = require("../attributable.cjs");
|
|
3
|
-
const focusTrap_embedded = require("./embedded.cjs");
|
|
4
|
-
function removeFocusTraps(element) {
|
|
5
|
-
focusTrap_embedded.focusTraps.get(element)?.destroy();
|
|
6
|
-
focusTrap_embedded.focusTraps.delete(element);
|
|
7
|
-
}
|
|
8
|
-
attributable.attributable(focusTrap_embedded.selector, focusTrap_embedded.createFocusTrap, removeFocusTraps);
|
package/dist/js/index.cjs
DELETED
package/dist/js/popover.cjs
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const is = require("@oscarpalmer/atoms/is");
|
|
4
|
-
const event = require("@oscarpalmer/toretto/event");
|
|
5
|
-
const find = require("@oscarpalmer/toretto/find");
|
|
6
|
-
const focusable = require("@oscarpalmer/toretto/focusable");
|
|
7
|
-
const floatable = require("./floatable.cjs");
|
|
8
|
-
const focusTrap_embedded = require("./focus-trap/embedded.cjs");
|
|
9
|
-
const mapped = /* @__PURE__ */ new Map();
|
|
10
|
-
let index = 0;
|
|
11
|
-
class OuiPopoverElement extends HTMLElement {
|
|
12
|
-
#floatable;
|
|
13
|
-
#focusTrap;
|
|
14
|
-
constructor() {
|
|
15
|
-
super();
|
|
16
|
-
const content = this.querySelector(":scope > [oui-popover-content]");
|
|
17
|
-
const toggle2 = this.querySelector(":scope > [oui-popover-toggle]");
|
|
18
|
-
if (!(content instanceof HTMLElement)) {
|
|
19
|
-
throw new Error(
|
|
20
|
-
"A oui-popover must have a direct child element with the [oui-popover-content]-attribute"
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
if (!(toggle2 instanceof HTMLButtonElement)) {
|
|
24
|
-
throw new Error(
|
|
25
|
-
"A oui-popover must have a direct child element with the [oui-popover-toggle]-attribute and be a button"
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
content.hidden = true;
|
|
29
|
-
content.setAttribute("role", "dialog");
|
|
30
|
-
content.setAttribute("oui-focus-trap", "");
|
|
31
|
-
content.setAttribute("oui-focus-trap-noescape", "");
|
|
32
|
-
if (is.isNullableOrWhitespace(content.id)) {
|
|
33
|
-
content.setAttribute("id", `oui-popover-content-${++index}`);
|
|
34
|
-
}
|
|
35
|
-
toggle2.setAttribute("aria-controls", content.id);
|
|
36
|
-
toggle2.setAttribute("aria-haspopup", "dialog");
|
|
37
|
-
this.#floatable = new floatable.Floatable(toggle2, content);
|
|
38
|
-
this.#focusTrap = focusTrap_embedded.createFocusTrap(content);
|
|
39
|
-
mapped.set(toggle2, this.#floatable);
|
|
40
|
-
mapped.set(content, this.#floatable);
|
|
41
|
-
}
|
|
42
|
-
close() {
|
|
43
|
-
this.hidePopover();
|
|
44
|
-
}
|
|
45
|
-
hidePopover() {
|
|
46
|
-
if (this.#floatable.active) {
|
|
47
|
-
closeAbove(this.#floatable.content);
|
|
48
|
-
floatable.deactivate(this.#floatable, active, order);
|
|
49
|
-
this.#floatable.anchor.focus();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
open() {
|
|
53
|
-
this.showPopover();
|
|
54
|
-
}
|
|
55
|
-
showPopover() {
|
|
56
|
-
if (!this.#floatable.active) {
|
|
57
|
-
toggle(this.#floatable.anchor);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
toggle() {
|
|
61
|
-
this.togglePopover();
|
|
62
|
-
}
|
|
63
|
-
togglePopover(options) {
|
|
64
|
-
if (typeof options === "boolean") {
|
|
65
|
-
if (options === true) {
|
|
66
|
-
this.showPopover();
|
|
67
|
-
} else {
|
|
68
|
-
this.hidePopover();
|
|
69
|
-
}
|
|
70
|
-
return options;
|
|
71
|
-
}
|
|
72
|
-
if (this.#floatable.active) {
|
|
73
|
-
this.hidePopover();
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
this.showPopover();
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function closeAll() {
|
|
81
|
-
for (const floatable$1 of active) {
|
|
82
|
-
floatable.deactivate(floatable$1, active, order);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
function closeAbove(element) {
|
|
86
|
-
const index2 = order.findIndex(
|
|
87
|
-
(floatable2) => floatable2.anchor === element || floatable2.content === element
|
|
88
|
-
);
|
|
89
|
-
if (index2 === -1 || index2 === order.length - 1) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
while (index2 < order.length - 1) {
|
|
93
|
-
const floatable$1 = order.pop();
|
|
94
|
-
if (floatable$1 != null) {
|
|
95
|
-
floatable.deactivate(floatable$1, active, order);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
focus(order[index2].content);
|
|
99
|
-
}
|
|
100
|
-
function focus(content) {
|
|
101
|
-
let target = focusable.getFocusable(content)[0];
|
|
102
|
-
if (!(target instanceof HTMLElement)) {
|
|
103
|
-
target = content;
|
|
104
|
-
}
|
|
105
|
-
requestAnimationFrame(() => {
|
|
106
|
-
target.focus();
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
function onClick(event2) {
|
|
110
|
-
const related = find.findAncestor(
|
|
111
|
-
event2.target,
|
|
112
|
-
"[oui-popover-toggle], [oui-popover-content]"
|
|
113
|
-
);
|
|
114
|
-
if (!(related instanceof HTMLElement)) {
|
|
115
|
-
closeAll();
|
|
116
|
-
} else if (related.hasAttribute("oui-popover-content")) {
|
|
117
|
-
closeAbove(related);
|
|
118
|
-
} else {
|
|
119
|
-
toggle(related);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
function onKeydown(event2) {
|
|
123
|
-
if (event2.key !== "Escape" || order.length === 0) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const related = find.findAncestor(event2.target, "[oui-popover-content]");
|
|
127
|
-
if (!(related instanceof HTMLElement)) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
closeAbove(related);
|
|
131
|
-
const floatable$1 = mapped.get(related);
|
|
132
|
-
if (floatable$1 != null) {
|
|
133
|
-
floatable.deactivate(floatable$1, active, order);
|
|
134
|
-
floatable$1.anchor.focus();
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
function toggle(anchor) {
|
|
138
|
-
const content = find.findAncestor(anchor, "[oui-popover-content]");
|
|
139
|
-
if (content instanceof HTMLElement) {
|
|
140
|
-
closeAbove(content);
|
|
141
|
-
} else {
|
|
142
|
-
closeAll();
|
|
143
|
-
}
|
|
144
|
-
const floatable$1 = mapped.get(anchor);
|
|
145
|
-
if (floatable$1 == null) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
if (floatable$1.active) {
|
|
149
|
-
floatable.deactivate(floatable$1, active, order);
|
|
150
|
-
} else {
|
|
151
|
-
floatable.activate(floatable$1, active, order);
|
|
152
|
-
focus(floatable$1.content);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
customElements.define("oui-popover", OuiPopoverElement);
|
|
156
|
-
event.on(document, "click", onClick);
|
|
157
|
-
event.on(document, "keydown", onKeydown);
|
|
158
|
-
const active = /* @__PURE__ */ new Set();
|
|
159
|
-
const order = [];
|
|
160
|
-
exports.OuiPopoverElement = OuiPopoverElement;
|
package/dist/js/splitter.cjs
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const number = require("@oscarpalmer/atoms/number");
|
|
4
|
-
const event = require("@oscarpalmer/toretto/event");
|
|
5
|
-
const find = require("@oscarpalmer/toretto/find");
|
|
6
|
-
class OuiSplitterElement extends HTMLElement {
|
|
7
|
-
#splitter;
|
|
8
|
-
constructor() {
|
|
9
|
-
super();
|
|
10
|
-
const panels = [...this.children].filter(
|
|
11
|
-
(child) => child instanceof HTMLElement
|
|
12
|
-
);
|
|
13
|
-
if (panels.length !== 2) {
|
|
14
|
-
throw new Error("oui-splitter must have exactly two panels.");
|
|
15
|
-
}
|
|
16
|
-
this.#splitter = new Splitter(this, panels);
|
|
17
|
-
}
|
|
18
|
-
connectedCallback() {
|
|
19
|
-
if (this.#splitter.types.auto) {
|
|
20
|
-
observer.observe(this);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
disconnectedCallback() {
|
|
24
|
-
if (this.#splitter.types.auto) {
|
|
25
|
-
observer.unobserve(this);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
class Splitter {
|
|
30
|
-
constructor(element, panels) {
|
|
31
|
-
this.element = element;
|
|
32
|
-
this.panels = panels;
|
|
33
|
-
this.handle = createHandle();
|
|
34
|
-
this.rectangle = element.getBoundingClientRect();
|
|
35
|
-
this.separator = createSeparator();
|
|
36
|
-
this.separator.append(this.handle);
|
|
37
|
-
panels[0].insertAdjacentElement("afterend", this.separator);
|
|
38
|
-
mapped.set(element, this);
|
|
39
|
-
mapped.set(this.handle, this);
|
|
40
|
-
setSize(this, this.flex.value);
|
|
41
|
-
this.types = getTypes(this);
|
|
42
|
-
if (this.types.horizontal) {
|
|
43
|
-
this.element.setAttribute("oui-splitter-horizontal", "");
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
flex = {
|
|
47
|
-
previous: 0.5,
|
|
48
|
-
value: 0.5
|
|
49
|
-
};
|
|
50
|
-
handle;
|
|
51
|
-
rectangle;
|
|
52
|
-
separator;
|
|
53
|
-
types;
|
|
54
|
-
}
|
|
55
|
-
function createHandle() {
|
|
56
|
-
const handle = document.createElement("span");
|
|
57
|
-
handle.tabIndex = 0;
|
|
58
|
-
handle.setAttribute("aria-label", "Resize panels");
|
|
59
|
-
handle.setAttribute("oui-splitter-handle", "");
|
|
60
|
-
return handle;
|
|
61
|
-
}
|
|
62
|
-
function createSeparator() {
|
|
63
|
-
const separator = document.createElement("div");
|
|
64
|
-
separator.setAttribute("oui-splitter-separator", "");
|
|
65
|
-
return separator;
|
|
66
|
-
}
|
|
67
|
-
function getFlex(splitter2, value) {
|
|
68
|
-
const { height, left, top, width } = splitter2.rectangle;
|
|
69
|
-
const offset = value - (splitter2.types.horizontal ? top : left);
|
|
70
|
-
const fraction = offset / (splitter2.types.horizontal ? height : width);
|
|
71
|
-
return number.clamp(fraction, 0.1, 0.9);
|
|
72
|
-
}
|
|
73
|
-
function getTypes(splitter2, width, height) {
|
|
74
|
-
const type = splitter2.element.getAttribute("type")?.trim() ?? "";
|
|
75
|
-
if (type === "horizontal") {
|
|
76
|
-
return {
|
|
77
|
-
auto: false,
|
|
78
|
-
horizontal: true
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
if (type === "auto") {
|
|
82
|
-
return {
|
|
83
|
-
auto: true,
|
|
84
|
-
horizontal: (height ?? splitter2.rectangle.height) > (width ?? splitter2.rectangle.width)
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
return {
|
|
88
|
-
auto: false,
|
|
89
|
-
horizontal: false
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
function onEnd(reset) {
|
|
93
|
-
if (splitter != null) {
|
|
94
|
-
splitter.handle.removeAttribute("oui-splitter-active");
|
|
95
|
-
splitter.separator.removeAttribute("oui-splitter-active");
|
|
96
|
-
if (reset) {
|
|
97
|
-
setSize(splitter, splitter.flex.previous);
|
|
98
|
-
} else {
|
|
99
|
-
splitter.flex.previous = splitter.flex.value;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
splitter = void 0;
|
|
103
|
-
}
|
|
104
|
-
function onKeydown(event2) {
|
|
105
|
-
switch (true) {
|
|
106
|
-
case allKeys.has(event2.key):
|
|
107
|
-
onNavigate(event2);
|
|
108
|
-
break;
|
|
109
|
-
case event2.key === "Escape":
|
|
110
|
-
onEnd(true);
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function onMousedown(event2) {
|
|
115
|
-
splitter = mapped.get(
|
|
116
|
-
find.findAncestor(
|
|
117
|
-
event2.target,
|
|
118
|
-
"[oui-splitter-handle]"
|
|
119
|
-
)
|
|
120
|
-
);
|
|
121
|
-
if (splitter == null) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
splitter.handle.setAttribute("oui-splitter-active", "");
|
|
125
|
-
splitter.separator.setAttribute("oui-splitter-active", "");
|
|
126
|
-
splitter.rectangle = splitter.element.getBoundingClientRect();
|
|
127
|
-
}
|
|
128
|
-
function onMousemove(event$1) {
|
|
129
|
-
if (splitter == null) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
const position = event.getPosition(event$1);
|
|
133
|
-
if (position != null) {
|
|
134
|
-
splitter.flex.value = getFlex(
|
|
135
|
-
splitter,
|
|
136
|
-
splitter.types.horizontal ? position.y : position.x
|
|
137
|
-
);
|
|
138
|
-
setSize(splitter, splitter.flex.value);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
function onMouseup() {
|
|
142
|
-
if (splitter != null) {
|
|
143
|
-
onEnd(false);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
function onNavigate(event2) {
|
|
147
|
-
const splitter2 = mapped.get(
|
|
148
|
-
find.findAncestor(
|
|
149
|
-
event2.target,
|
|
150
|
-
"[oui-splitter-handle]"
|
|
151
|
-
)
|
|
152
|
-
);
|
|
153
|
-
if (splitter2 == null) {
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
if (absoluteKeys.has(event2.key)) {
|
|
157
|
-
setSize(splitter2, event2.key === "End" ? 0.9 : 0.1, true);
|
|
158
|
-
return;
|
|
159
|
-
}
|
|
160
|
-
if (splitter2.types.horizontal && !horizontalKeys.has(event2.key) || !splitter2.types.horizontal && !verticalKeys.has(event2.key)) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
const modifier = negativeKeys.has(event2.key) ? -1 : 1;
|
|
164
|
-
setSize(splitter2, splitter2.flex.value + modifier * 0.05, true);
|
|
165
|
-
}
|
|
166
|
-
function onObservation(entries) {
|
|
167
|
-
if (frame != null) {
|
|
168
|
-
cancelAnimationFrame(frame);
|
|
169
|
-
}
|
|
170
|
-
frame = requestAnimationFrame(() => {
|
|
171
|
-
for (const entry of entries) {
|
|
172
|
-
const splitter2 = mapped.get(entry.target);
|
|
173
|
-
if (splitter2 == null) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
splitter2.types = getTypes(
|
|
177
|
-
splitter2,
|
|
178
|
-
entry.contentRect.width,
|
|
179
|
-
entry.contentRect.height
|
|
180
|
-
);
|
|
181
|
-
if (splitter2.types.horizontal) {
|
|
182
|
-
splitter2.element.setAttribute("oui-splitter-horizontal", "");
|
|
183
|
-
} else {
|
|
184
|
-
splitter2.element.removeAttribute("oui-splitter-horizontal");
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
frame = void 0;
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
function setSize(splitter2, size, previous) {
|
|
191
|
-
splitter2.flex.value = size;
|
|
192
|
-
if (previous) {
|
|
193
|
-
splitter2.flex.previous = size;
|
|
194
|
-
}
|
|
195
|
-
splitter2.element.style.setProperty("--oui-splitter-size", `${size}`);
|
|
196
|
-
}
|
|
197
|
-
const absoluteKeys = /* @__PURE__ */ new Set(["End", "Home"]);
|
|
198
|
-
const horizontalKeys = /* @__PURE__ */ new Set(["ArrowDown", "ArrowUp"]);
|
|
199
|
-
const mapped = /* @__PURE__ */ new WeakMap();
|
|
200
|
-
const observer = new ResizeObserver(onObservation);
|
|
201
|
-
const negativeKeys = /* @__PURE__ */ new Set(["ArrowLeft", "ArrowUp"]);
|
|
202
|
-
const verticalKeys = /* @__PURE__ */ new Set(["ArrowLeft", "ArrowRight"]);
|
|
203
|
-
const allKeys = /* @__PURE__ */ new Set([...absoluteKeys, ...horizontalKeys, ...verticalKeys]);
|
|
204
|
-
let frame;
|
|
205
|
-
let splitter;
|
|
206
|
-
customElements.define("oui-splitter", OuiSplitterElement);
|
|
207
|
-
event.on(document, "keydown", onKeydown);
|
|
208
|
-
event.on(document, "mousedown", onMousedown);
|
|
209
|
-
event.on(document, "mousemove", onMousemove);
|
|
210
|
-
event.on(document, "mouseup", onMouseup);
|
|
211
|
-
exports.OuiSplitterElement = OuiSplitterElement;
|
package/dist/js/tooltip.cjs
DELETED
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const is = require("@oscarpalmer/atoms/is");
|
|
3
|
-
const event = require("@oscarpalmer/toretto/event");
|
|
4
|
-
const attributable = require("./attributable.cjs");
|
|
5
|
-
const floatable = require("./floatable.cjs");
|
|
6
|
-
class Tooltip {
|
|
7
|
-
abortController = new AbortController();
|
|
8
|
-
attributes;
|
|
9
|
-
floatable;
|
|
10
|
-
constructor(anchor, content) {
|
|
11
|
-
this.attributes = content.attributes;
|
|
12
|
-
this.floatable = new floatable.Floatable(anchor, content.element);
|
|
13
|
-
initialize(this);
|
|
14
|
-
}
|
|
15
|
-
destroy() {
|
|
16
|
-
floatable.deactivate(this.floatable, active);
|
|
17
|
-
reset(this.floatable.anchor, this.attributes);
|
|
18
|
-
this.abortController.abort();
|
|
19
|
-
this.floatable.content.remove();
|
|
20
|
-
this.floatable.destroy();
|
|
21
|
-
this.abortController = void 0;
|
|
22
|
-
this.attributes = void 0;
|
|
23
|
-
this.floatable = void 0;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
function addTooltip(anchor) {
|
|
27
|
-
if (tooltips.has(anchor)) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const content = getContent(anchor);
|
|
31
|
-
if (content != null) {
|
|
32
|
-
tooltips.set(anchor, new Tooltip(anchor, content));
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
function getContent(anchor) {
|
|
36
|
-
const attributes = {
|
|
37
|
-
ariaDescribedby: anchor.getAttribute("aria-describedby"),
|
|
38
|
-
ariaLabelledBy: anchor.getAttribute("aria-labelledby")
|
|
39
|
-
};
|
|
40
|
-
const wrapper = getWrapper(anchor);
|
|
41
|
-
const labelledElements = getElements(attributes.ariaLabelledBy);
|
|
42
|
-
if (labelledElements.length > 0) {
|
|
43
|
-
anchor.setAttribute("aria-labelledby", wrapper.id);
|
|
44
|
-
for (const element of labelledElements) {
|
|
45
|
-
wrapper.append(element);
|
|
46
|
-
}
|
|
47
|
-
return {
|
|
48
|
-
attributes,
|
|
49
|
-
element: wrapper
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
const describedElements = getElements(attributes.ariaDescribedby);
|
|
53
|
-
if (describedElements.length > 0) {
|
|
54
|
-
anchor.setAttribute("aria-describedby", wrapper.id);
|
|
55
|
-
for (const element of describedElements) {
|
|
56
|
-
wrapper.append(element);
|
|
57
|
-
}
|
|
58
|
-
return {
|
|
59
|
-
attributes,
|
|
60
|
-
element: wrapper
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
let content = anchor.getAttribute("aria-label");
|
|
64
|
-
if (is.isNullableOrWhitespace(content)) {
|
|
65
|
-
content = anchor.getAttribute("aria-description");
|
|
66
|
-
}
|
|
67
|
-
if (is.isNullableOrWhitespace(content)) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
const paragraph = document.createElement("p");
|
|
71
|
-
paragraph.textContent = content;
|
|
72
|
-
wrapper.append(paragraph);
|
|
73
|
-
return {
|
|
74
|
-
attributes,
|
|
75
|
-
element: wrapper
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
function getElements(attribute) {
|
|
79
|
-
const ids = attribute?.split(/\s+/) ?? [];
|
|
80
|
-
const elements = [];
|
|
81
|
-
for (const id of ids) {
|
|
82
|
-
if (is.isNullableOrWhitespace(id)) {
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
const element = document.querySelector(`#${id}`);
|
|
86
|
-
if (element instanceof HTMLElement) {
|
|
87
|
-
const cloned = element.cloneNode(true);
|
|
88
|
-
cloned.hidden = false;
|
|
89
|
-
elements.push(cloned);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return elements;
|
|
93
|
-
}
|
|
94
|
-
function getWrapper(anchor) {
|
|
95
|
-
const wrapper = document.createElement("div");
|
|
96
|
-
wrapper.setAttribute(`${selector}-content`, "");
|
|
97
|
-
wrapper.className = anchor.getAttribute(`${selector}-class`) ?? "";
|
|
98
|
-
wrapper.hidden = true;
|
|
99
|
-
wrapper.id = `${selector}-${++index}`;
|
|
100
|
-
wrapper.role = "tooltip";
|
|
101
|
-
wrapper.tabIndex = -1;
|
|
102
|
-
return wrapper;
|
|
103
|
-
}
|
|
104
|
-
function initialize(tooltip) {
|
|
105
|
-
const { abortController, floatable: floatable$1 } = tooltip;
|
|
106
|
-
const { anchor, content } = floatable$1;
|
|
107
|
-
anchor.insertAdjacentElement("afterend", content);
|
|
108
|
-
const elements = [anchor, content];
|
|
109
|
-
for (const element of elements) {
|
|
110
|
-
for (const event$1 of activateEvents) {
|
|
111
|
-
event.on(
|
|
112
|
-
element,
|
|
113
|
-
event$1,
|
|
114
|
-
() => {
|
|
115
|
-
floatable.activate(floatable$1, active, void 0, 250);
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
signal: abortController.signal
|
|
119
|
-
}
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
for (const event$1 of deactivateEvents) {
|
|
123
|
-
event.on(
|
|
124
|
-
element,
|
|
125
|
-
event$1,
|
|
126
|
-
() => {
|
|
127
|
-
floatable.deactivate(floatable$1, active, void 0, 250);
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
signal: abortController.signal
|
|
131
|
-
}
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
function removeTooltip(element) {
|
|
137
|
-
tooltips.get(element)?.destroy();
|
|
138
|
-
tooltips.delete(element);
|
|
139
|
-
}
|
|
140
|
-
function reset(anchor, attributes) {
|
|
141
|
-
if (attributes.ariaDescribedby == null) {
|
|
142
|
-
anchor.removeAttribute("aria-describedby");
|
|
143
|
-
} else {
|
|
144
|
-
anchor.setAttribute("aria-describedby", attributes.ariaDescribedby);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
const active = /* @__PURE__ */ new Set();
|
|
148
|
-
const activateEvents = ["focus", "mouseenter", "touchstart"];
|
|
149
|
-
const deactivateEvents = ["blur", "mouseleave"];
|
|
150
|
-
const selector = "oui-tooltip";
|
|
151
|
-
const tooltips = /* @__PURE__ */ new WeakMap();
|
|
152
|
-
let index = 0;
|
|
153
|
-
attributable.attributable(selector, addTooltip, removeTooltip);
|
|
154
|
-
event.on(document, "keydown", (event2) => {
|
|
155
|
-
if (event2.key === "Escape") {
|
|
156
|
-
for (const floatable$1 of active) {
|
|
157
|
-
floatable.deactivate(floatable$1, active);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
});
|