@oscarpalmer/oui 0.18.0 → 0.19.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 +10 -10
- package/dist/css/button.css +9 -9
- package/dist/css/color.css +99 -99
- package/dist/css/content.css +1 -1
- package/dist/css/flex.css +39 -39
- package/dist/css/form.css +29 -56
- package/dist/css/message.css +6 -6
- package/dist/css/reset.css +3 -2
- package/dist/css/table.css +4 -4
- package/dist/css/tooltip.css +18 -1
- package/dist/js/attributable.full.js +29 -41
- package/dist/js/floatable.full.js +322 -337
- package/dist/js/focus-trap/embedded.full.js +252 -195
- package/dist/js/focus-trap/standalone.full.js +283 -238
- package/dist/js/index.js +3 -3
- package/dist/js/oui.full.js +1170 -1193
- package/dist/js/popover.full.js +568 -630
- package/dist/js/popover.js +1 -1
- package/dist/js/splitter.full.js +533 -369
- package/dist/js/splitter.js +2 -2
- package/dist/js/tooltip.full.js +488 -554
- package/dist/js/tooltip.js +1 -1
- package/package.json +19 -19
- package/src/css/a11y.scss +1 -1
- package/src/css/badge.scss +23 -19
- package/src/css/button.scss +9 -9
- package/src/css/color.scss +99 -99
- package/src/css/content.scss +6 -8
- package/src/css/flex.scss +21 -20
- package/src/css/form.scss +37 -60
- package/src/css/message.scss +8 -12
- package/src/css/mixins.scss +11 -12
- package/src/css/popover.scss +2 -2
- package/src/css/reset.scss +14 -14
- package/src/css/splitter.scss +15 -13
- package/src/css/table.scss +11 -11
- package/src/css/tooltip.scss +25 -4
- package/src/js/attributable.ts +3 -10
- package/src/js/floatable.ts +7 -25
- package/src/js/focus-trap/embedded.ts +6 -24
- package/src/js/popover.ts +3 -3
- package/src/js/splitter.ts +9 -39
- package/src/js/tooltip.ts +5 -17
- package/dist/css/value.css +0 -1
|
@@ -1,11 +1,4 @@
|
|
|
1
|
-
function
|
|
2
|
-
return typeof value === "object" && value != null && typeof value.addEventListener === "function" && typeof value.removeEventListener === "function" && typeof value.dispatchEvent === "function";
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
function getBoolean(value, defaultValue) {
|
|
6
|
-
return defaultValue ?? false;
|
|
7
|
-
}
|
|
8
|
-
|
|
1
|
+
function noop() {}
|
|
9
2
|
function calculate() {
|
|
10
3
|
return new Promise((resolve) => {
|
|
11
4
|
const values = [];
|
|
@@ -13,37 +6,122 @@ function calculate() {
|
|
|
13
6
|
function step(now) {
|
|
14
7
|
if (last != null) values.push(now - last);
|
|
15
8
|
last = now;
|
|
16
|
-
if (values.length >=
|
|
17
|
-
|
|
18
|
-
resolve(median);
|
|
19
|
-
} else requestAnimationFrame(step);
|
|
9
|
+
if (values.length >= TOTAL) resolve(values.sort().slice(TRIM_PART, -TRIM_PART).reduce((first, second) => first + second, 0) / (values.length - TRIM_TOTAL));
|
|
10
|
+
else requestAnimationFrame(step);
|
|
20
11
|
}
|
|
21
12
|
requestAnimationFrame(step);
|
|
22
13
|
});
|
|
23
14
|
}
|
|
24
|
-
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
calculate()
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
var TOTAL = 10;
|
|
16
|
+
var TRIM_PART = 2;
|
|
17
|
+
var TRIM_TOTAL = 4;
|
|
18
|
+
await calculate();
|
|
19
|
+
function getBoolean(value, defaultValue) {
|
|
20
|
+
return typeof value === "boolean" ? value : defaultValue ?? false;
|
|
21
|
+
}
|
|
22
|
+
function isEventTarget(value) {
|
|
23
|
+
return typeof value === "object" && value != null && typeof value.addEventListener === "function" && typeof value.removeEventListener === "function" && typeof value.dispatchEvent === "function";
|
|
24
|
+
}
|
|
25
|
+
function addDelegatedHandler(doc, type, name, passive) {
|
|
26
|
+
if (DELEGATED.has(name)) return;
|
|
27
|
+
DELEGATED.add(name);
|
|
28
|
+
doc.addEventListener(type, passive ? HANDLER_PASSIVE : HANDLER_ACTIVE, { passive });
|
|
29
|
+
}
|
|
30
|
+
function addDelegatedListener(target, type, name, listener, passive) {
|
|
31
|
+
target[name] ??= /* @__PURE__ */ new Set();
|
|
32
|
+
target[name].add(listener);
|
|
33
|
+
addDelegatedHandler(document, type, name, passive);
|
|
34
|
+
return () => {
|
|
35
|
+
removeDelegatedListener(target, name, listener);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function delegatedEventHandler(event) {
|
|
39
|
+
const key = `${EVENT_PREFIX}${event.type}${this ? EVENT_SUFFIX_PASSIVE : EVENT_SUFFIX_ACTIVE}`;
|
|
40
|
+
const items = event.composedPath();
|
|
41
|
+
const { length } = items;
|
|
42
|
+
let target = items[0];
|
|
43
|
+
Object.defineProperties(event, {
|
|
44
|
+
currentTarget: {
|
|
45
|
+
configurable: true,
|
|
46
|
+
get() {
|
|
47
|
+
return target;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
target: {
|
|
51
|
+
configurable: true,
|
|
52
|
+
value: target
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
for (let index = 0; index < length; index += 1) {
|
|
56
|
+
const item = items[index];
|
|
57
|
+
const listeners = item[key];
|
|
58
|
+
if (item.disabled || listeners == null) continue;
|
|
59
|
+
target = item;
|
|
60
|
+
for (const listener of listeners) {
|
|
61
|
+
listener.call(item, event);
|
|
62
|
+
if (event.cancelBubble) return;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function getDelegatedName(target, type, options) {
|
|
67
|
+
if (isEventTarget(target) && EVENT_TYPES.has(type) && !options.capture && !options.once && options.signal == null) return `${EVENT_PREFIX}${type}${options.passive ? EVENT_SUFFIX_PASSIVE : EVENT_SUFFIX_ACTIVE}`;
|
|
68
|
+
}
|
|
69
|
+
function removeDelegatedListener(target, name, listener) {
|
|
70
|
+
const handlers = target[name];
|
|
71
|
+
if (handlers == null || !handlers.has(listener)) return false;
|
|
72
|
+
handlers.delete(listener);
|
|
73
|
+
if (handlers.size === 0) target[name] = void 0;
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
var DELEGATED = /* @__PURE__ */ new Set();
|
|
77
|
+
var EVENT_PREFIX = "@";
|
|
78
|
+
var EVENT_SUFFIX_ACTIVE = ":active";
|
|
79
|
+
var EVENT_SUFFIX_PASSIVE = ":passive";
|
|
80
|
+
var EVENT_TYPES = new Set([
|
|
81
|
+
"beforeinput",
|
|
82
|
+
"click",
|
|
83
|
+
"dblclick",
|
|
84
|
+
"contextmenu",
|
|
85
|
+
"focusin",
|
|
86
|
+
"focusout",
|
|
87
|
+
"input",
|
|
88
|
+
"keydown",
|
|
89
|
+
"keyup",
|
|
90
|
+
"mousedown",
|
|
91
|
+
"mousemove",
|
|
92
|
+
"mouseout",
|
|
93
|
+
"mouseover",
|
|
94
|
+
"mouseup",
|
|
95
|
+
"pointerdown",
|
|
96
|
+
"pointermove",
|
|
97
|
+
"pointerout",
|
|
98
|
+
"pointerover",
|
|
99
|
+
"pointerup",
|
|
100
|
+
"touchend",
|
|
101
|
+
"touchmove",
|
|
102
|
+
"touchstart"
|
|
103
|
+
]);
|
|
104
|
+
var HANDLER_ACTIVE = delegatedEventHandler.bind(false);
|
|
105
|
+
var HANDLER_PASSIVE = delegatedEventHandler.bind(true);
|
|
30
106
|
function createEventOptions(options) {
|
|
31
107
|
return {
|
|
32
|
-
capture: getBoolean(),
|
|
33
|
-
once: getBoolean(),
|
|
108
|
+
capture: getBoolean(options?.capture),
|
|
109
|
+
once: getBoolean(options?.once),
|
|
34
110
|
passive: getBoolean(options?.passive, true),
|
|
35
|
-
signal: options?.signal
|
|
111
|
+
signal: options?.signal instanceof AbortSignal ? options.signal : void 0
|
|
36
112
|
};
|
|
37
113
|
}
|
|
38
114
|
function on(target, type, listener, options) {
|
|
39
115
|
if (!isEventTarget(target) || typeof type !== "string" || typeof listener !== "function") return noop;
|
|
40
116
|
const extended = createEventOptions(options);
|
|
117
|
+
const delegated = getDelegatedName(target, type, extended);
|
|
118
|
+
if (delegated != null) return addDelegatedListener(target, type, delegated, listener, extended.passive);
|
|
41
119
|
target.addEventListener(type, listener, extended);
|
|
120
|
+
if (extended.once) return noop;
|
|
42
121
|
return () => {
|
|
43
122
|
target.removeEventListener(type, listener, extended);
|
|
44
123
|
};
|
|
45
124
|
}
|
|
46
|
-
|
|
47
125
|
function findAncestor(origin, selector) {
|
|
48
126
|
if (!(origin instanceof Element) || selector == null) return null;
|
|
49
127
|
if (typeof selector === "string") {
|
|
@@ -59,355 +137,262 @@ function findAncestor(origin, selector) {
|
|
|
59
137
|
}
|
|
60
138
|
return parent;
|
|
61
139
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
state.active.add(this);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
state.active.delete(this);
|
|
112
|
-
}
|
|
113
|
-
if (this.options.interactive) {
|
|
114
|
-
if (active) {
|
|
115
|
-
state.order.push(this);
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
const index = state.order.indexOf(this);
|
|
119
|
-
if (index > -1) {
|
|
120
|
-
state.order.splice(index, 1);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (active) {
|
|
125
|
-
activate(this);
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
deactivate(this);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
//
|
|
140
|
+
var Floatable = class {
|
|
141
|
+
active = false;
|
|
142
|
+
disabled = false;
|
|
143
|
+
frame;
|
|
144
|
+
ignoreFocus = false;
|
|
145
|
+
constructor(options) {
|
|
146
|
+
this.options = options;
|
|
147
|
+
initialize(this);
|
|
148
|
+
}
|
|
149
|
+
destroy() {
|
|
150
|
+
stop(this);
|
|
151
|
+
const state = getState();
|
|
152
|
+
state?.active.delete(this);
|
|
153
|
+
state?.mapped.delete(this.options.anchor);
|
|
154
|
+
state?.mapped.delete(this.options.content);
|
|
155
|
+
this.options.anchor = void 0;
|
|
156
|
+
this.options.content = void 0;
|
|
157
|
+
}
|
|
158
|
+
disable() {
|
|
159
|
+
if (this.disabled) return;
|
|
160
|
+
this.disabled = true;
|
|
161
|
+
stop(this);
|
|
162
|
+
getState()?.active.delete(this);
|
|
163
|
+
}
|
|
164
|
+
enable() {
|
|
165
|
+
if (!this.disabled) return;
|
|
166
|
+
this.disabled = false;
|
|
167
|
+
initialize(this);
|
|
168
|
+
}
|
|
169
|
+
toggle(active, ignoreFocus) {
|
|
170
|
+
if (this.disabled || this.active === active) return;
|
|
171
|
+
const state = getState();
|
|
172
|
+
if (state == null) return;
|
|
173
|
+
this.ignoreFocus = !active && (ignoreFocus ?? false);
|
|
174
|
+
stop(this);
|
|
175
|
+
if (active) state.active.add(this);
|
|
176
|
+
else state.active.delete(this);
|
|
177
|
+
if (this.options.interactive) if (active) state.order.push(this);
|
|
178
|
+
else {
|
|
179
|
+
const index = state.order.indexOf(this);
|
|
180
|
+
if (index > -1) state.order.splice(index, 1);
|
|
181
|
+
}
|
|
182
|
+
if (active) activate(this);
|
|
183
|
+
else deactivate(this);
|
|
184
|
+
}
|
|
185
|
+
};
|
|
133
186
|
function activate(floatable) {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
187
|
+
floatable.active = true;
|
|
188
|
+
document.body.append(floatable.options.content);
|
|
189
|
+
floatable.options.content.hidden = false;
|
|
190
|
+
updatePosition(floatable);
|
|
138
191
|
}
|
|
139
192
|
function closeAbove(element) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
floatable.options.content === element);
|
|
146
|
-
if (index === -1 || index === state.order.length - 1) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
while (index < state.order.length - 1) {
|
|
150
|
-
void state.order.pop()?.toggle(false, true);
|
|
151
|
-
}
|
|
193
|
+
const state = getState();
|
|
194
|
+
if (state == null) return;
|
|
195
|
+
const index = state.order.findIndex((floatable) => floatable.options.anchor === element || floatable.options.content === element);
|
|
196
|
+
if (index === -1 || index === state.order.length - 1) return;
|
|
197
|
+
while (index < state.order.length - 1) state.order.pop()?.toggle(false, true);
|
|
152
198
|
}
|
|
153
199
|
function closeAll() {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
void floatable.toggle(false, true);
|
|
159
|
-
}
|
|
200
|
+
const state = getState();
|
|
201
|
+
const floatables = [...state?.active ?? []];
|
|
202
|
+
state?.active.clear();
|
|
203
|
+
for (const floatable of floatables) floatable.toggle(false, true);
|
|
160
204
|
}
|
|
161
205
|
function closeNonInteractive(state) {
|
|
162
|
-
|
|
163
|
-
if (!floatable.options.interactive) {
|
|
164
|
-
void floatable.toggle(false);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
206
|
+
for (const floatable of state.active) if (!floatable.options.interactive) floatable.toggle(false);
|
|
167
207
|
}
|
|
168
208
|
function deactivate(floatable) {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
209
|
+
floatable.active = false;
|
|
210
|
+
floatable.options.content.hidden = true;
|
|
211
|
+
floatable.options.anchor.insertAdjacentElement(INSERT_AFTEREND, floatable.options.content);
|
|
212
|
+
floatable.options.onAfter?.(false);
|
|
173
213
|
}
|
|
174
214
|
function getState() {
|
|
175
|
-
|
|
215
|
+
return window._oscarpalmer_oui_floatable;
|
|
176
216
|
}
|
|
177
217
|
function getX(anchor, content, position) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
if (position.startsWith(POSITION_HORIZONTAL)) {
|
|
195
|
-
if (anchor.right + content.width <= window.innerWidth) {
|
|
196
|
-
return anchor.right;
|
|
197
|
-
}
|
|
198
|
-
return anchor.left - content.width;
|
|
199
|
-
}
|
|
200
|
-
const left = anchor.left + (anchor.width - content.width) / 2;
|
|
201
|
-
return left < 0 ? 0 : left;
|
|
218
|
+
if (position.endsWith(POSITION_SUFFIX_END)) {
|
|
219
|
+
const end = anchor.right - content.width;
|
|
220
|
+
return end < 0 ? 0 : end;
|
|
221
|
+
}
|
|
222
|
+
if (position.endsWith(POSITION_SUFFIX_START)) {
|
|
223
|
+
const start = anchor.left;
|
|
224
|
+
return start + content.width > window.innerWidth ? window.innerWidth - content.width : start;
|
|
225
|
+
}
|
|
226
|
+
if (position.startsWith(POSITION_END)) return anchor.right;
|
|
227
|
+
if (position.startsWith(POSITION_START)) return anchor.left - content.width;
|
|
228
|
+
if (position.startsWith(POSITION_HORIZONTAL)) {
|
|
229
|
+
if (anchor.right + content.width <= window.innerWidth) return anchor.right;
|
|
230
|
+
return anchor.left - content.width;
|
|
231
|
+
}
|
|
232
|
+
const left = anchor.left + (anchor.width - content.width) / 2;
|
|
233
|
+
return left < 0 ? 0 : left;
|
|
202
234
|
}
|
|
203
235
|
function getY(anchor, content, position, preferAbove) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if (position.startsWith(POSITION_VERTICAL)) {
|
|
221
|
-
if (preferAbove && anchor.top - content.height >= 0) {
|
|
222
|
-
return anchor.top - content.height;
|
|
223
|
-
}
|
|
224
|
-
if (anchor.bottom + content.height <= document.body.clientHeight) {
|
|
225
|
-
return anchor.bottom;
|
|
226
|
-
}
|
|
227
|
-
return anchor.top - content.height;
|
|
228
|
-
}
|
|
229
|
-
return anchor.top + (anchor.height - content.height) / 2;
|
|
236
|
+
if (position.startsWith(POSITION_ABOVE)) return anchor.top - content.height;
|
|
237
|
+
if (position.startsWith(POSITION_BELOW)) return anchor.bottom;
|
|
238
|
+
if (position.endsWith(POSITION_BOTTOM)) {
|
|
239
|
+
const bottom = anchor.bottom - content.height;
|
|
240
|
+
return bottom < 0 ? 0 : bottom;
|
|
241
|
+
}
|
|
242
|
+
if (position.endsWith(POSITION_TOP)) {
|
|
243
|
+
const top = anchor.top;
|
|
244
|
+
return top + content.height > window.innerHeight ? window.innerHeight - content.height : top;
|
|
245
|
+
}
|
|
246
|
+
if (position.startsWith(POSITION_VERTICAL)) {
|
|
247
|
+
if (preferAbove && anchor.top - content.height >= 0) return anchor.top - content.height;
|
|
248
|
+
if (anchor.bottom + content.height <= document.body.clientHeight) return anchor.bottom;
|
|
249
|
+
return anchor.top - content.height;
|
|
250
|
+
}
|
|
251
|
+
return anchor.top + (anchor.height - content.height) / 2;
|
|
230
252
|
}
|
|
231
253
|
function initialize(floatable) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
254
|
+
const { anchor, content, interactive } = floatable.options;
|
|
255
|
+
if (interactive) {
|
|
256
|
+
anchor.setAttribute(ATTRIBUTE_ANCHOR, "");
|
|
257
|
+
content.setAttribute(ATTRIBUTE_CONTENT, "");
|
|
258
|
+
}
|
|
259
|
+
content.style.position = "fixed";
|
|
260
|
+
content.style.inset = "0 auto auto 0";
|
|
261
|
+
content.style.zIndex = "10";
|
|
262
|
+
const state = getState();
|
|
263
|
+
state?.mapped.set(anchor, floatable);
|
|
264
|
+
state?.mapped.set(content, floatable);
|
|
243
265
|
}
|
|
244
266
|
function isDisabled(element) {
|
|
245
|
-
|
|
246
|
-
element.readOnly ||
|
|
247
|
-
element.getAttribute('aria-disabled') === 'true');
|
|
267
|
+
return element.disabled || element.readOnly || element.getAttribute("aria-disabled") === "true";
|
|
248
268
|
}
|
|
249
269
|
function onClick(event) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
else if (related.hasAttribute(ATTRIBUTE_CONTENT)) {
|
|
255
|
-
closeAbove(related);
|
|
256
|
-
}
|
|
257
|
-
else if (!isDisabled(related)) {
|
|
258
|
-
toggle(related);
|
|
259
|
-
}
|
|
270
|
+
const related = findAncestor(event.target, SELECTOR_ALL);
|
|
271
|
+
if (!(related instanceof HTMLElement)) closeAll();
|
|
272
|
+
else if (related.hasAttribute(ATTRIBUTE_CONTENT)) closeAbove(related);
|
|
273
|
+
else if (!isDisabled(related)) toggle(related);
|
|
260
274
|
}
|
|
261
275
|
function onKeyDown(event) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
if (!(related instanceof HTMLElement)) {
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
closeAbove(related);
|
|
275
|
-
const floatable = state.mapped.get(related);
|
|
276
|
-
if (floatable != null) {
|
|
277
|
-
void floatable.toggle(false);
|
|
278
|
-
}
|
|
276
|
+
if (event.key !== "Escape") return;
|
|
277
|
+
const state = getState();
|
|
278
|
+
if (state == null || state.active.size === 0) return;
|
|
279
|
+
closeNonInteractive(state);
|
|
280
|
+
const related = findAncestor(event.target, SELECTOR_CONTENT);
|
|
281
|
+
if (!(related instanceof HTMLElement)) return;
|
|
282
|
+
closeAbove(related);
|
|
283
|
+
const floatable = state.mapped.get(related);
|
|
284
|
+
if (floatable != null) floatable.toggle(false);
|
|
279
285
|
}
|
|
280
286
|
function stop(floatable) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
floatable.frame = undefined;
|
|
287
|
+
if (floatable.frame != null) cancelAnimationFrame(floatable.frame);
|
|
288
|
+
floatable.frame = void 0;
|
|
285
289
|
}
|
|
286
290
|
function toggle(anchor) {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
else {
|
|
298
|
-
closeAbove(content);
|
|
299
|
-
}
|
|
300
|
-
void floatable.toggle(!active);
|
|
291
|
+
const floatable = getState()?.mapped.get(anchor);
|
|
292
|
+
if (floatable == null) {
|
|
293
|
+
closeAll();
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
const active = Boolean(floatable.active);
|
|
297
|
+
const content = findAncestor(floatable.options.anchor, SELECTOR_CONTENT);
|
|
298
|
+
if (content == null) closeAll();
|
|
299
|
+
else closeAbove(content);
|
|
300
|
+
floatable.toggle(!active);
|
|
301
301
|
}
|
|
302
302
|
function updatePosition(floatable) {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
floatable.options.content.style.height = '';
|
|
340
|
-
}
|
|
341
|
-
if (left + content.width > window.innerWidth) {
|
|
342
|
-
floatable.options.content.style.width = `${window.innerWidth - left}px`;
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
floatable.options.content.style.width = '';
|
|
346
|
-
}
|
|
347
|
-
// floatable.options.content.style.inset = `${top}px auto auto ${left}px`;
|
|
348
|
-
floatable.options.content.style.transform = `translate3d(${left}px, ${top}px, 0)`;
|
|
349
|
-
floatable.frame = requestAnimationFrame(run);
|
|
350
|
-
if (!runOnAfter) {
|
|
351
|
-
runOnAfter = true;
|
|
352
|
-
floatable.options.onAfter?.(true);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
floatable.frame = requestAnimationFrame(run);
|
|
303
|
+
let position = floatable.options.anchor.getAttribute(floatable.options.positionAttribute)?.trim() ?? floatable.options.defaultPosition;
|
|
304
|
+
if (!POSITIONS.has(position)) position = floatable.options.defaultPosition;
|
|
305
|
+
let previousAnchor;
|
|
306
|
+
let previousContent;
|
|
307
|
+
let calculated = false;
|
|
308
|
+
let runOnAfter = false;
|
|
309
|
+
function run() {
|
|
310
|
+
const anchor = floatable.options.anchor.getBoundingClientRect();
|
|
311
|
+
const content = floatable.options.content.getBoundingClientRect();
|
|
312
|
+
if (calculated) {
|
|
313
|
+
if (previousAnchor != null && previousContent != null) {
|
|
314
|
+
if (PROPERTIES.every((property) => anchor[property] === previousAnchor[property]) && PROPERTIES.every((property) => content[property] === previousContent[property])) {
|
|
315
|
+
floatable.frame = requestAnimationFrame(run);
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
} else calculated = true;
|
|
320
|
+
update(anchor, content);
|
|
321
|
+
}
|
|
322
|
+
function update(anchor, content) {
|
|
323
|
+
previousAnchor = anchor;
|
|
324
|
+
previousContent = content;
|
|
325
|
+
const left = getX(anchor, content, position);
|
|
326
|
+
const top = getY(anchor, content, position, floatable.options.preferAbove);
|
|
327
|
+
if (top + content.height > window.innerHeight) floatable.options.content.style.height = `${window.innerHeight - top}px`;
|
|
328
|
+
else floatable.options.content.style.height = "";
|
|
329
|
+
if (left + content.width > window.innerWidth) floatable.options.content.style.width = `${window.innerWidth - left}px`;
|
|
330
|
+
else floatable.options.content.style.width = "";
|
|
331
|
+
floatable.options.content.style.transform = `translate3d(${left}px, ${top}px, 0)`;
|
|
332
|
+
floatable.frame = requestAnimationFrame(run);
|
|
333
|
+
if (!runOnAfter) {
|
|
334
|
+
runOnAfter = true;
|
|
335
|
+
floatable.options.onAfter?.(true);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
floatable.frame = requestAnimationFrame(run);
|
|
356
339
|
}
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
const
|
|
360
|
-
const
|
|
361
|
-
const
|
|
362
|
-
const
|
|
363
|
-
const
|
|
364
|
-
const
|
|
365
|
-
const
|
|
366
|
-
const
|
|
367
|
-
const
|
|
368
|
-
const
|
|
369
|
-
const
|
|
370
|
-
const POSITION_VERTICAL = 'vertical';
|
|
340
|
+
const ATTRIBUTE_ANCHOR = "oui-floatable-anchor";
|
|
341
|
+
const ATTRIBUTE_CONTENT = "oui-floatable-content";
|
|
342
|
+
const INSERT_AFTEREND = "afterend";
|
|
343
|
+
const POSITION_ABOVE = "above";
|
|
344
|
+
const POSITION_BELOW = "below";
|
|
345
|
+
const POSITION_BOTTOM = "bottom";
|
|
346
|
+
const POSITION_END = "end";
|
|
347
|
+
const POSITION_HORIZONTAL = "horizontal";
|
|
348
|
+
const POSITION_START = "start";
|
|
349
|
+
const POSITION_SUFFIX_END = "-end";
|
|
350
|
+
const POSITION_SUFFIX_START = "-start";
|
|
351
|
+
const POSITION_TOP = "top";
|
|
352
|
+
const POSITION_VERTICAL = "vertical";
|
|
371
353
|
const POSITIONS = new Set([
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
354
|
+
"above",
|
|
355
|
+
"above-end",
|
|
356
|
+
"above-start",
|
|
357
|
+
"below",
|
|
358
|
+
"below-end",
|
|
359
|
+
"below-start",
|
|
360
|
+
"end",
|
|
361
|
+
"end-bottom",
|
|
362
|
+
"end-top",
|
|
363
|
+
"horizontal",
|
|
364
|
+
"horizontal-bottom",
|
|
365
|
+
"horizontal-top",
|
|
366
|
+
"start",
|
|
367
|
+
"start-bottom",
|
|
368
|
+
"start-top",
|
|
369
|
+
"vertical",
|
|
370
|
+
"vertical-end",
|
|
371
|
+
"vertical-start"
|
|
390
372
|
]);
|
|
391
|
-
const PROPERTIES = [
|
|
373
|
+
const PROPERTIES = [
|
|
374
|
+
"bottom",
|
|
375
|
+
"left",
|
|
376
|
+
"right",
|
|
377
|
+
"top"
|
|
378
|
+
];
|
|
392
379
|
const SELECTOR_ALL = `[${ATTRIBUTE_ANCHOR}], [${ATTRIBUTE_CONTENT}]`;
|
|
393
380
|
const SELECTOR_CONTENT = `[${ATTRIBUTE_CONTENT}]`;
|
|
394
|
-
//
|
|
395
381
|
if (window._oscarpalmer_oui_floatable == null) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
382
|
+
Object.defineProperty(window, "_oscarpalmer_oui_floatable", {
|
|
383
|
+
enumerable: false,
|
|
384
|
+
value: {
|
|
385
|
+
active: /* @__PURE__ */ new Set(),
|
|
386
|
+
mapped: /* @__PURE__ */ new Map(),
|
|
387
|
+
order: []
|
|
388
|
+
},
|
|
389
|
+
writable: false
|
|
390
|
+
});
|
|
391
|
+
on(document, "keydown", (event) => {
|
|
392
|
+
onKeyDown(event);
|
|
393
|
+
});
|
|
394
|
+
on(document, "click", (event) => {
|
|
395
|
+
onClick(event);
|
|
396
|
+
});
|
|
411
397
|
}
|
|
412
|
-
|
|
413
398
|
export { Floatable, deactivate };
|