@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.
Files changed (44) hide show
  1. package/dist/css/badge.css +10 -10
  2. package/dist/css/button.css +9 -9
  3. package/dist/css/color.css +99 -99
  4. package/dist/css/content.css +1 -1
  5. package/dist/css/flex.css +39 -39
  6. package/dist/css/form.css +29 -56
  7. package/dist/css/message.css +6 -6
  8. package/dist/css/reset.css +3 -2
  9. package/dist/css/table.css +4 -4
  10. package/dist/css/tooltip.css +18 -1
  11. package/dist/js/attributable.full.js +29 -41
  12. package/dist/js/floatable.full.js +322 -337
  13. package/dist/js/focus-trap/embedded.full.js +252 -195
  14. package/dist/js/focus-trap/standalone.full.js +283 -238
  15. package/dist/js/index.js +3 -3
  16. package/dist/js/oui.full.js +1170 -1193
  17. package/dist/js/popover.full.js +568 -630
  18. package/dist/js/popover.js +1 -1
  19. package/dist/js/splitter.full.js +533 -369
  20. package/dist/js/splitter.js +2 -2
  21. package/dist/js/tooltip.full.js +488 -554
  22. package/dist/js/tooltip.js +1 -1
  23. package/package.json +19 -19
  24. package/src/css/a11y.scss +1 -1
  25. package/src/css/badge.scss +23 -19
  26. package/src/css/button.scss +9 -9
  27. package/src/css/color.scss +99 -99
  28. package/src/css/content.scss +6 -8
  29. package/src/css/flex.scss +21 -20
  30. package/src/css/form.scss +37 -60
  31. package/src/css/message.scss +8 -12
  32. package/src/css/mixins.scss +11 -12
  33. package/src/css/popover.scss +2 -2
  34. package/src/css/reset.scss +14 -14
  35. package/src/css/splitter.scss +15 -13
  36. package/src/css/table.scss +11 -11
  37. package/src/css/tooltip.scss +25 -4
  38. package/src/js/attributable.ts +3 -10
  39. package/src/js/floatable.ts +7 -25
  40. package/src/js/focus-trap/embedded.ts +6 -24
  41. package/src/js/popover.ts +3 -3
  42. package/src/js/splitter.ts +9 -39
  43. package/src/js/tooltip.ts +5 -17
  44. package/dist/css/value.css +0 -1
@@ -1,11 +1,4 @@
1
- function isEventTarget(value) {
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 >= CALCULATION_TOTAL) {
17
- const median = values.sort().slice(2, -2).reduce((first, second) => first + second, 0) / (values.length - CALCULATION_TRIM);
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
- function noop() {}
25
- var CALCULATION_TOTAL = 10;
26
- var CALCULATION_TRIM = 4;
27
- calculate().then((value) => {
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
- class Floatable {
64
- options;
65
- active = false;
66
- disabled = false;
67
- frame;
68
- ignoreFocus = false;
69
- constructor(options) {
70
- this.options = options;
71
- initialize(this);
72
- }
73
- destroy() {
74
- stop(this);
75
- const state = getState();
76
- state?.active.delete(this);
77
- state?.mapped.delete(this.options.anchor);
78
- state?.mapped.delete(this.options.content);
79
- this.options.anchor = undefined;
80
- this.options.content = undefined;
81
- }
82
- disable() {
83
- if (this.disabled) {
84
- return;
85
- }
86
- this.disabled = true;
87
- stop(this);
88
- getState()?.active.delete(this);
89
- }
90
- enable() {
91
- if (!this.disabled) {
92
- return;
93
- }
94
- this.disabled = false;
95
- initialize(this);
96
- }
97
- toggle(active, ignoreFocus) {
98
- if (this.disabled || this.active === active) {
99
- return;
100
- }
101
- const state = getState();
102
- if (state == null) {
103
- return;
104
- }
105
- this.ignoreFocus = !active && (ignoreFocus ?? false);
106
- stop(this);
107
- if (active) {
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
- floatable.active = true;
135
- document.body.append(floatable.options.content);
136
- floatable.options.content.hidden = false;
137
- updatePosition(floatable);
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
- const state = getState();
141
- if (state == null) {
142
- return;
143
- }
144
- const index = state.order.findIndex(floatable => floatable.options.anchor === element ||
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
- const state = getState();
155
- const floatables = [...(state?.active ?? [])];
156
- state?.active.clear();
157
- for (const floatable of floatables) {
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
- for (const floatable of state.active) {
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
- floatable.active = false;
170
- floatable.options.content.hidden = true;
171
- floatable.options.anchor.insertAdjacentElement(INSERT_AFTEREND, floatable.options.content);
172
- floatable.options.onAfter?.(false);
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
- return window._oscarpalmer_oui_floatable;
215
+ return window._oscarpalmer_oui_floatable;
176
216
  }
177
217
  function getX(anchor, content, position) {
178
- if (position.endsWith(POSITION_SUFFIX_END)) {
179
- const end = anchor.right - content.width;
180
- return end < 0 ? 0 : end;
181
- }
182
- if (position.endsWith(POSITION_SUFFIX_START)) {
183
- const start = anchor.left;
184
- return start + content.width > window.innerWidth
185
- ? window.innerWidth - content.width
186
- : start;
187
- }
188
- if (position.startsWith(POSITION_END)) {
189
- return anchor.right;
190
- }
191
- if (position.startsWith(POSITION_START)) {
192
- return anchor.left - content.width;
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
- if (position.startsWith(POSITION_ABOVE)) {
205
- return anchor.top - content.height;
206
- }
207
- if (position.startsWith(POSITION_BELOW)) {
208
- return anchor.bottom;
209
- }
210
- if (position.endsWith(POSITION_BOTTOM)) {
211
- const bottom = anchor.bottom - content.height;
212
- return bottom < 0 ? 0 : bottom;
213
- }
214
- if (position.endsWith(POSITION_TOP)) {
215
- const top = anchor.top;
216
- return top + content.height > window.innerHeight
217
- ? window.innerHeight - content.height
218
- : top;
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
- const { anchor, content, interactive } = floatable.options;
233
- if (interactive) {
234
- anchor.setAttribute(ATTRIBUTE_ANCHOR, '');
235
- content.setAttribute(ATTRIBUTE_CONTENT, '');
236
- }
237
- content.style.position = 'fixed';
238
- content.style.inset = '0 auto auto 0';
239
- content.style.zIndex = '10';
240
- const state = getState();
241
- state?.mapped.set(anchor, floatable);
242
- state?.mapped.set(content, floatable);
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
- return (element.disabled ||
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
- const related = findAncestor(event.target, SELECTOR_ALL);
251
- if (!(related instanceof HTMLElement)) {
252
- closeAll();
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
- if (event.key !== 'Escape') {
263
- return;
264
- }
265
- const state = getState();
266
- if (state == null || state.active.size === 0) {
267
- return;
268
- }
269
- closeNonInteractive(state);
270
- const related = findAncestor(event.target, SELECTOR_CONTENT);
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
- if (floatable.frame != null) {
282
- cancelAnimationFrame(floatable.frame);
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
- const floatable = getState()?.mapped.get(anchor);
288
- if (floatable == null) {
289
- closeAll();
290
- return;
291
- }
292
- const active = Boolean(floatable.active);
293
- const content = findAncestor(floatable.options.anchor, SELECTOR_CONTENT);
294
- if (content == null) {
295
- closeAll();
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
- let position = floatable.options.anchor
304
- .getAttribute(floatable.options.positionAttribute)
305
- ?.trim() ?? floatable.options.defaultPosition;
306
- if (!POSITIONS.has(position)) {
307
- position = floatable.options.defaultPosition;
308
- }
309
- let previousAnchor;
310
- let previousContent;
311
- let calculated = false;
312
- let runOnAfter = false;
313
- function run() {
314
- const anchor = floatable.options.anchor.getBoundingClientRect();
315
- const content = floatable.options.content.getBoundingClientRect();
316
- if (calculated) {
317
- if (previousAnchor != null && previousContent != null) {
318
- if (PROPERTIES.every(property => anchor[property] === previousAnchor[property]) &&
319
- PROPERTIES.every(property => content[property] === previousContent[property])) {
320
- floatable.frame = requestAnimationFrame(run);
321
- return;
322
- }
323
- }
324
- }
325
- else {
326
- calculated = true;
327
- }
328
- update(anchor, content);
329
- }
330
- function update(anchor, content) {
331
- previousAnchor = anchor;
332
- previousContent = content;
333
- const left = getX(anchor, content, position);
334
- const top = getY(anchor, content, position, floatable.options.preferAbove);
335
- if (top + content.height > window.innerHeight) {
336
- floatable.options.content.style.height = `${window.innerHeight - top}px`;
337
- }
338
- else {
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 ATTRIBUTE_ANCHOR = 'oui-floatable-anchor';
359
- const ATTRIBUTE_CONTENT = 'oui-floatable-content';
360
- const INSERT_AFTEREND = 'afterend';
361
- const POSITION_ABOVE = 'above';
362
- const POSITION_BELOW = 'below';
363
- const POSITION_BOTTOM = 'bottom';
364
- const POSITION_END = 'end';
365
- const POSITION_HORIZONTAL = 'horizontal';
366
- const POSITION_START = 'start';
367
- const POSITION_SUFFIX_END = '-end';
368
- const POSITION_SUFFIX_START = '-start';
369
- const POSITION_TOP = 'top';
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
- 'above',
373
- 'above-end',
374
- 'above-start',
375
- 'below',
376
- 'below-end',
377
- 'below-start',
378
- 'end',
379
- 'end-bottom',
380
- 'end-top',
381
- 'horizontal',
382
- 'horizontal-bottom',
383
- 'horizontal-top',
384
- 'start',
385
- 'start-bottom',
386
- 'start-top',
387
- 'vertical',
388
- 'vertical-end',
389
- 'vertical-start',
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 = ['bottom', 'left', 'right', 'top'];
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
- Object.defineProperty(window, '_oscarpalmer_oui_floatable', {
397
- enumerable: false,
398
- value: {
399
- active: new Set(),
400
- mapped: new Map(),
401
- order: [],
402
- },
403
- writable: false,
404
- });
405
- on(document, 'keydown', event => {
406
- onKeyDown(event);
407
- });
408
- on(document, 'click', event => {
409
- onClick(event);
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 };