@oscarpalmer/oui 0.17.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/reset.css +176 -56
- 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 +254 -169
- 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 -162
- package/dist/js/splitter.full.js +605 -0
- package/dist/js/splitter.js +263 -245
- package/dist/js/tooltip.full.js +679 -0
- package/dist/js/tooltip.js +159 -150
- 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/reset.scss +180 -54
- package/src/css/tooltip.scss +8 -0
- package/src/js/floatable.ts +380 -133
- 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 +50 -120
- package/src/js/splitter.ts +250 -103
- package/src/js/tooltip.ts +155 -68
- package/types/floatable.d.ts +17 -10
- 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 -176
- 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 -166
- package/dist/js/splitter.cjs +0 -272
- package/dist/js/tooltip.cjs +0 -166
- package/types/attributable.d.cts +0 -5
- package/types/floatable.d.cts +0 -20
- 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,166 +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(
|
|
38
|
-
toggle2,
|
|
39
|
-
content,
|
|
40
|
-
"position",
|
|
41
|
-
"below-start",
|
|
42
|
-
false
|
|
43
|
-
);
|
|
44
|
-
this.#focusTrap = focusTrap_embedded.createFocusTrap(content);
|
|
45
|
-
mapped.set(toggle2, this.#floatable);
|
|
46
|
-
mapped.set(content, this.#floatable);
|
|
47
|
-
}
|
|
48
|
-
close() {
|
|
49
|
-
this.hidePopover();
|
|
50
|
-
}
|
|
51
|
-
hidePopover() {
|
|
52
|
-
if (this.#floatable.active) {
|
|
53
|
-
closeAbove(this.#floatable.content);
|
|
54
|
-
floatable.deactivate(this.#floatable, active, order);
|
|
55
|
-
this.#floatable.anchor.focus();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
open() {
|
|
59
|
-
this.showPopover();
|
|
60
|
-
}
|
|
61
|
-
showPopover() {
|
|
62
|
-
if (!this.#floatable.active) {
|
|
63
|
-
toggle(this.#floatable.anchor);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
toggle() {
|
|
67
|
-
this.togglePopover();
|
|
68
|
-
}
|
|
69
|
-
togglePopover(options) {
|
|
70
|
-
if (typeof options === "boolean") {
|
|
71
|
-
if (options === true) {
|
|
72
|
-
this.showPopover();
|
|
73
|
-
} else {
|
|
74
|
-
this.hidePopover();
|
|
75
|
-
}
|
|
76
|
-
return options;
|
|
77
|
-
}
|
|
78
|
-
if (this.#floatable.active) {
|
|
79
|
-
this.hidePopover();
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
this.showPopover();
|
|
83
|
-
return true;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function closeAll() {
|
|
87
|
-
for (const floatable$1 of active) {
|
|
88
|
-
floatable.deactivate(floatable$1, active, order);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
function closeAbove(element) {
|
|
92
|
-
const index2 = order.findIndex(
|
|
93
|
-
(floatable2) => floatable2.anchor === element || floatable2.content === element
|
|
94
|
-
);
|
|
95
|
-
if (index2 === -1 || index2 === order.length - 1) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
while (index2 < order.length - 1) {
|
|
99
|
-
const floatable$1 = order.pop();
|
|
100
|
-
if (floatable$1 != null) {
|
|
101
|
-
floatable.deactivate(floatable$1, active, order);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
focus(order[index2].content);
|
|
105
|
-
}
|
|
106
|
-
function focus(content) {
|
|
107
|
-
let target = focusable.getFocusable(content)[0];
|
|
108
|
-
if (!(target instanceof HTMLElement)) {
|
|
109
|
-
target = content;
|
|
110
|
-
}
|
|
111
|
-
requestAnimationFrame(() => {
|
|
112
|
-
target.focus();
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
function onClick(event2) {
|
|
116
|
-
const related = find.findAncestor(
|
|
117
|
-
event2.target,
|
|
118
|
-
"[oui-popover-toggle], [oui-popover-content]"
|
|
119
|
-
);
|
|
120
|
-
if (!(related instanceof HTMLElement)) {
|
|
121
|
-
closeAll();
|
|
122
|
-
} else if (related.hasAttribute("oui-popover-content")) {
|
|
123
|
-
closeAbove(related);
|
|
124
|
-
} else {
|
|
125
|
-
toggle(related);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
function onKeydown(event2) {
|
|
129
|
-
if (event2.key !== "Escape" || order.length === 0) {
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
const related = find.findAncestor(event2.target, "[oui-popover-content]");
|
|
133
|
-
if (!(related instanceof HTMLElement)) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
closeAbove(related);
|
|
137
|
-
const floatable$1 = mapped.get(related);
|
|
138
|
-
if (floatable$1 != null) {
|
|
139
|
-
floatable.deactivate(floatable$1, active, order);
|
|
140
|
-
floatable$1.anchor.focus();
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function toggle(anchor) {
|
|
144
|
-
const content = find.findAncestor(anchor, "[oui-popover-content]");
|
|
145
|
-
if (content instanceof HTMLElement) {
|
|
146
|
-
closeAbove(content);
|
|
147
|
-
} else {
|
|
148
|
-
closeAll();
|
|
149
|
-
}
|
|
150
|
-
const floatable$1 = mapped.get(anchor);
|
|
151
|
-
if (floatable$1 == null) {
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
if (floatable$1.active) {
|
|
155
|
-
floatable.deactivate(floatable$1, active, order);
|
|
156
|
-
} else {
|
|
157
|
-
floatable.activate(floatable$1, active, order);
|
|
158
|
-
focus(floatable$1.content);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
customElements.define("oui-popover", OuiPopoverElement);
|
|
162
|
-
event.on(document, "click", onClick);
|
|
163
|
-
event.on(document, "keydown", onKeydown);
|
|
164
|
-
const active = /* @__PURE__ */ new Set();
|
|
165
|
-
const order = [];
|
|
166
|
-
exports.OuiPopoverElement = OuiPopoverElement;
|
package/dist/js/splitter.cjs
DELETED
|
@@ -1,272 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const is = require("@oscarpalmer/atoms/is");
|
|
4
|
-
const math = require("@oscarpalmer/atoms/math");
|
|
5
|
-
const number = require("@oscarpalmer/atoms/number");
|
|
6
|
-
const event = require("@oscarpalmer/toretto/event");
|
|
7
|
-
const find = require("@oscarpalmer/toretto/find");
|
|
8
|
-
class OuiSplitterElement extends HTMLElement {
|
|
9
|
-
#splitter;
|
|
10
|
-
constructor() {
|
|
11
|
-
super();
|
|
12
|
-
const panels = [...this.children].filter(
|
|
13
|
-
(child) => child instanceof HTMLElement
|
|
14
|
-
);
|
|
15
|
-
if (panels.length !== 2) {
|
|
16
|
-
throw new Error("oui-splitter must have exactly two panels.");
|
|
17
|
-
}
|
|
18
|
-
this.#splitter = new Splitter(this, panels);
|
|
19
|
-
}
|
|
20
|
-
connectedCallback() {
|
|
21
|
-
if (this.#splitter.types.auto) {
|
|
22
|
-
observer.observe(this);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
disconnectedCallback() {
|
|
26
|
-
if (this.#splitter.types.auto) {
|
|
27
|
-
observer.unobserve(this);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
let index = 0;
|
|
32
|
-
class Splitter {
|
|
33
|
-
constructor(element, panels) {
|
|
34
|
-
this.element = element;
|
|
35
|
-
this.panels = panels;
|
|
36
|
-
if (is.isNullableOrWhitespace(element.id)) {
|
|
37
|
-
element.id = `oui_splitter_${++index}`;
|
|
38
|
-
}
|
|
39
|
-
this.values = getValues(element);
|
|
40
|
-
this.handle = createHandle();
|
|
41
|
-
this.rectangle = element.getBoundingClientRect();
|
|
42
|
-
this.separator = createSeparator(this);
|
|
43
|
-
this.separator.append(this.handle);
|
|
44
|
-
panels[0].insertAdjacentElement("afterend", this.separator);
|
|
45
|
-
mapped.set(element, this);
|
|
46
|
-
mapped.set(this.handle, this);
|
|
47
|
-
setSize(this, this.values.now.current);
|
|
48
|
-
this.types = getTypes(this);
|
|
49
|
-
if (this.types.horizontal) {
|
|
50
|
-
this.element.setAttribute("oui-splitter-horizontal", "");
|
|
51
|
-
}
|
|
52
|
-
setAriaOrientation(this);
|
|
53
|
-
setAriaValue(this);
|
|
54
|
-
}
|
|
55
|
-
handle;
|
|
56
|
-
rectangle;
|
|
57
|
-
separator;
|
|
58
|
-
types;
|
|
59
|
-
values;
|
|
60
|
-
}
|
|
61
|
-
function createHandle() {
|
|
62
|
-
const handle = document.createElement("span");
|
|
63
|
-
handle.setAttribute("aria-hidden", "true");
|
|
64
|
-
handle.setAttribute("oui-splitter-handle", "");
|
|
65
|
-
return handle;
|
|
66
|
-
}
|
|
67
|
-
function createSeparator(splitter2) {
|
|
68
|
-
const separator = document.createElement("div");
|
|
69
|
-
separator.role = "separator";
|
|
70
|
-
separator.tabIndex = 0;
|
|
71
|
-
separator.setAttribute("aria-controls", splitter2.element.id);
|
|
72
|
-
separator.setAttribute("aria-label", "Resize panels");
|
|
73
|
-
separator.setAttribute("oui-splitter-separator", "");
|
|
74
|
-
return separator;
|
|
75
|
-
}
|
|
76
|
-
function getContained(min, value, max) {
|
|
77
|
-
return math.round(number.clamp(value, min, max), 6);
|
|
78
|
-
}
|
|
79
|
-
function getSize(splitter2, value) {
|
|
80
|
-
const { height, left, top, width } = splitter2.rectangle;
|
|
81
|
-
const offset = value - (splitter2.types.horizontal ? top : left);
|
|
82
|
-
const fraction = offset / (splitter2.types.horizontal ? height : width);
|
|
83
|
-
return getContained(splitter2.values.min, fraction, splitter2.values.max);
|
|
84
|
-
}
|
|
85
|
-
function getTypes(splitter2, width, height) {
|
|
86
|
-
const type = splitter2.element.getAttribute("type")?.trim() ?? "";
|
|
87
|
-
if (type === "horizontal") {
|
|
88
|
-
return {
|
|
89
|
-
auto: false,
|
|
90
|
-
horizontal: true
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
if (type === "auto") {
|
|
94
|
-
return {
|
|
95
|
-
auto: true,
|
|
96
|
-
horizontal: (height ?? splitter2.rectangle.height) > (width ?? splitter2.rectangle.width)
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
auto: false,
|
|
101
|
-
horizontal: false
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
function getValue(element, name, defaultValue) {
|
|
105
|
-
const value = element.getAttribute(name);
|
|
106
|
-
if (is.isNullableOrWhitespace(value)) {
|
|
107
|
-
return defaultValue;
|
|
108
|
-
}
|
|
109
|
-
const parsed = Number.parseFloat(value);
|
|
110
|
-
if (Number.isNaN(parsed)) {
|
|
111
|
-
return defaultValue;
|
|
112
|
-
}
|
|
113
|
-
return parsed < 0 ? defaultValue : parsed > 1 ? parsed / 100 : parsed;
|
|
114
|
-
}
|
|
115
|
-
function getValues(element) {
|
|
116
|
-
const values = {
|
|
117
|
-
max: getValue(element, "max", 0.9),
|
|
118
|
-
min: getValue(element, "min", 0.1),
|
|
119
|
-
now: {
|
|
120
|
-
current: 0.5,
|
|
121
|
-
previous: 0.5
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const value = getContained(
|
|
125
|
-
values.min,
|
|
126
|
-
getValue(element, "size", values.now.current),
|
|
127
|
-
values.max
|
|
128
|
-
);
|
|
129
|
-
values.now.current = value;
|
|
130
|
-
values.now.previous = value;
|
|
131
|
-
return values;
|
|
132
|
-
}
|
|
133
|
-
function onEnd(reset) {
|
|
134
|
-
if (splitter != null) {
|
|
135
|
-
splitter.handle.removeAttribute("oui-splitter-active");
|
|
136
|
-
splitter.separator.removeAttribute("oui-splitter-active");
|
|
137
|
-
if (reset) {
|
|
138
|
-
setSize(splitter, splitter.values.now.previous);
|
|
139
|
-
} else {
|
|
140
|
-
splitter.values.now.previous = splitter.values.now.current;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
splitter = void 0;
|
|
144
|
-
}
|
|
145
|
-
function onKeydown(event2) {
|
|
146
|
-
switch (true) {
|
|
147
|
-
case allKeys.has(event2.key):
|
|
148
|
-
onNavigate(event2);
|
|
149
|
-
break;
|
|
150
|
-
case event2.key === "Escape":
|
|
151
|
-
onEnd(true);
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
function onMousedown(event2) {
|
|
156
|
-
splitter = mapped.get(
|
|
157
|
-
find.findAncestor(
|
|
158
|
-
event2.target,
|
|
159
|
-
"[oui-splitter-handle]"
|
|
160
|
-
)
|
|
161
|
-
);
|
|
162
|
-
if (splitter == null) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
splitter.handle.setAttribute("oui-splitter-active", "");
|
|
166
|
-
splitter.separator.setAttribute("oui-splitter-active", "");
|
|
167
|
-
splitter.rectangle = splitter.element.getBoundingClientRect();
|
|
168
|
-
}
|
|
169
|
-
function onMousemove(event$1) {
|
|
170
|
-
if (splitter == null) {
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
const position = event.getPosition(event$1);
|
|
174
|
-
if (position != null) {
|
|
175
|
-
splitter.values.now.current = getSize(
|
|
176
|
-
splitter,
|
|
177
|
-
splitter.types.horizontal ? position.y : position.x
|
|
178
|
-
);
|
|
179
|
-
setSize(splitter, splitter.values.now.current);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
function onMouseup() {
|
|
183
|
-
if (splitter != null) {
|
|
184
|
-
onEnd(false);
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
function onNavigate(event2) {
|
|
188
|
-
const splitter2 = mapped.get(
|
|
189
|
-
find.findAncestor(
|
|
190
|
-
event2.target,
|
|
191
|
-
"[oui-splitter-handle]"
|
|
192
|
-
)
|
|
193
|
-
);
|
|
194
|
-
if (splitter2 == null) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
if (absoluteKeys.has(event2.key)) {
|
|
198
|
-
setSize(
|
|
199
|
-
splitter2,
|
|
200
|
-
event2.key === "End" ? splitter2.values.max : splitter2.values.min,
|
|
201
|
-
true
|
|
202
|
-
);
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
if (splitter2.types.horizontal && !horizontalKeys.has(event2.key) || !splitter2.types.horizontal && !verticalKeys.has(event2.key)) {
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
const modifier = negativeKeys.has(event2.key) ? -1 : 1;
|
|
209
|
-
setSize(splitter2, splitter2.values.now.current + modifier * 0.05, true);
|
|
210
|
-
}
|
|
211
|
-
function onObservation(entries) {
|
|
212
|
-
if (frame != null) {
|
|
213
|
-
cancelAnimationFrame(frame);
|
|
214
|
-
}
|
|
215
|
-
frame = requestAnimationFrame(() => {
|
|
216
|
-
for (const entry of entries) {
|
|
217
|
-
const splitter2 = mapped.get(entry.target);
|
|
218
|
-
if (splitter2 == null) {
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
splitter2.types = getTypes(
|
|
222
|
-
splitter2,
|
|
223
|
-
entry.contentRect.width,
|
|
224
|
-
entry.contentRect.height
|
|
225
|
-
);
|
|
226
|
-
if (splitter2.types.horizontal) {
|
|
227
|
-
splitter2.element.setAttribute("oui-splitter-horizontal", "");
|
|
228
|
-
} else {
|
|
229
|
-
splitter2.element.removeAttribute("oui-splitter-horizontal");
|
|
230
|
-
}
|
|
231
|
-
setAriaOrientation(splitter2);
|
|
232
|
-
}
|
|
233
|
-
frame = void 0;
|
|
234
|
-
});
|
|
235
|
-
}
|
|
236
|
-
function setAriaOrientation(splitter2) {
|
|
237
|
-
splitter2.separator.setAttribute(
|
|
238
|
-
"aria-orientation",
|
|
239
|
-
splitter2.types.horizontal ? "horizontal" : "vertical"
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
function setAriaValue(splitter2) {
|
|
243
|
-
splitter2.separator.setAttribute("aria-valuemax", String(splitter2.values.max));
|
|
244
|
-
splitter2.separator.setAttribute("aria-valuemin", String(splitter2.values.min));
|
|
245
|
-
splitter2.separator.setAttribute(
|
|
246
|
-
"aria-valuenow",
|
|
247
|
-
String(splitter2.values.now.current)
|
|
248
|
-
);
|
|
249
|
-
}
|
|
250
|
-
function setSize(splitter2, size, previous) {
|
|
251
|
-
splitter2.values.now.current = size;
|
|
252
|
-
if (previous) {
|
|
253
|
-
splitter2.values.now.previous = size;
|
|
254
|
-
}
|
|
255
|
-
splitter2.element.style.setProperty("--oui-splitter-size", `${size}`);
|
|
256
|
-
setAriaValue(splitter2);
|
|
257
|
-
}
|
|
258
|
-
const absoluteKeys = /* @__PURE__ */ new Set(["End", "Home"]);
|
|
259
|
-
const horizontalKeys = /* @__PURE__ */ new Set(["ArrowDown", "ArrowUp"]);
|
|
260
|
-
const mapped = /* @__PURE__ */ new WeakMap();
|
|
261
|
-
const observer = new ResizeObserver(onObservation);
|
|
262
|
-
const negativeKeys = /* @__PURE__ */ new Set(["ArrowLeft", "ArrowUp"]);
|
|
263
|
-
const verticalKeys = /* @__PURE__ */ new Set(["ArrowLeft", "ArrowRight"]);
|
|
264
|
-
const allKeys = /* @__PURE__ */ new Set([...absoluteKeys, ...horizontalKeys, ...verticalKeys]);
|
|
265
|
-
let frame;
|
|
266
|
-
let splitter;
|
|
267
|
-
customElements.define("oui-splitter", OuiSplitterElement);
|
|
268
|
-
event.on(document, "keydown", onKeydown);
|
|
269
|
-
event.on(document, "mousedown", onMousedown);
|
|
270
|
-
event.on(document, "mousemove", onMousemove);
|
|
271
|
-
event.on(document, "mouseup", onMouseup);
|
|
272
|
-
exports.OuiSplitterElement = OuiSplitterElement;
|