coupdoeil 1.0.0.pre.alpha.1

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 (60) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +1 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +6 -0
  5. data/Rakefile +8 -0
  6. data/app/assets/config/coupdoeil_manifest.js +1 -0
  7. data/app/assets/javascripts/coupdoeil.js +2289 -0
  8. data/app/assets/javascripts/coupdoeil.min.js +2 -0
  9. data/app/assets/javascripts/coupdoeil.min.js.map +1 -0
  10. data/app/assets/stylesheets/coupdoeil/application.css +15 -0
  11. data/app/assets/stylesheets/coupdoeil/hovercard-animation.css +44 -0
  12. data/app/assets/stylesheets/coupdoeil/hovercard-arrow.css +39 -0
  13. data/app/assets/stylesheets/coupdoeil/hovercard.css +84 -0
  14. data/app/controllers/coupdoeil/hovercards_controller.rb +46 -0
  15. data/app/helpers/coupdoeil/application_helper.rb +16 -0
  16. data/app/javascript/coupdoeil/elements/coupdoeil_element.js +33 -0
  17. data/app/javascript/coupdoeil/events/onclick.js +68 -0
  18. data/app/javascript/coupdoeil/events/onmouseover.js +86 -0
  19. data/app/javascript/coupdoeil/events.js +19 -0
  20. data/app/javascript/coupdoeil/hovercard/actions.js +60 -0
  21. data/app/javascript/coupdoeil/hovercard/attributes.js +33 -0
  22. data/app/javascript/coupdoeil/hovercard/cache.js +18 -0
  23. data/app/javascript/coupdoeil/hovercard/closing.js +81 -0
  24. data/app/javascript/coupdoeil/hovercard/config.js +15 -0
  25. data/app/javascript/coupdoeil/hovercard/controller.js +22 -0
  26. data/app/javascript/coupdoeil/hovercard/opening.js +139 -0
  27. data/app/javascript/coupdoeil/hovercard/optionsParser.js +117 -0
  28. data/app/javascript/coupdoeil/hovercard/positioning.js +74 -0
  29. data/app/javascript/coupdoeil/hovercard/state_check.js +11 -0
  30. data/app/javascript/coupdoeil/hovercard.js +6 -0
  31. data/app/javascript/coupdoeil/index.js +1 -0
  32. data/app/models/coupdoeil/hovercard/option/animation.rb +20 -0
  33. data/app/models/coupdoeil/hovercard/option/cache.rb +19 -0
  34. data/app/models/coupdoeil/hovercard/option/loading.rb +19 -0
  35. data/app/models/coupdoeil/hovercard/option/offset.rb +35 -0
  36. data/app/models/coupdoeil/hovercard/option/placement.rb +44 -0
  37. data/app/models/coupdoeil/hovercard/option/trigger.rb +19 -0
  38. data/app/models/coupdoeil/hovercard/option.rb +45 -0
  39. data/app/models/coupdoeil/hovercard/options_set.rb +57 -0
  40. data/app/models/coupdoeil/hovercard/registry.rb +25 -0
  41. data/app/models/coupdoeil/hovercard/setup.rb +44 -0
  42. data/app/models/coupdoeil/hovercard/view_context_delegation.rb +18 -0
  43. data/app/models/coupdoeil/hovercard.rb +115 -0
  44. data/app/models/coupdoeil/params.rb +83 -0
  45. data/app/models/coupdoeil/tag.rb +45 -0
  46. data/app/style/hovercard-animation.scss +44 -0
  47. data/app/style/hovercard-arrow.scss +40 -0
  48. data/app/style/hovercard.scss +2 -0
  49. data/app/views/layouts/coupdoeil/application.html.erb +15 -0
  50. data/config/routes.rb +3 -0
  51. data/lib/coupdoeil/engine.rb +62 -0
  52. data/lib/coupdoeil/version.rb +3 -0
  53. data/lib/coupdoeil.rb +6 -0
  54. data/lib/generators/coupdoeil/hovercard/USAGE +15 -0
  55. data/lib/generators/coupdoeil/hovercard/hovercard_generator.rb +22 -0
  56. data/lib/generators/coupdoeil/hovercard/templates/hovercard.rb.tt +8 -0
  57. data/lib/generators/coupdoeil/install/install_generator.rb +71 -0
  58. data/lib/generators/coupdoeil/install/templates/layout.html.erb.tt +14 -0
  59. data/lib/tasks/coupdoeil_tasks.rake +4 -0
  60. metadata +129 -0
@@ -0,0 +1,2289 @@
1
+ class HovercardController {
2
+ constructor(coupdoeilElement) {
3
+ this.coupdoeilElement = coupdoeilElement;
4
+ this.card = null;
5
+ this.children = new Set;
6
+ this.parent = null;
7
+ this.closingRequest = null;
8
+ this.openingDelay = null;
9
+ this.fetchDelay = null;
10
+ }
11
+ get isOpen() {
12
+ return !!this.coupdoeilElement.dataset.hovercardOpen;
13
+ }
14
+ get isClosed() {
15
+ return !this.isOpen;
16
+ }
17
+ }
18
+
19
+ const HOVERCARD_CLASS_NAME = "coupdoeil--hovercard";
20
+
21
+ const HOVERCARD_SELECTOR = `.${HOVERCARD_CLASS_NAME}`;
22
+
23
+ const HOVERCARD_CLOSE_BTN_SELECTOR = "[data-hovercard-close]";
24
+
25
+ const defaultConfig = {
26
+ closingDelay: 150,
27
+ fetchDelay: 100,
28
+ openingDelay: 200
29
+ };
30
+
31
+ const OPTIONS = {
32
+ animation: {
33
+ getter: getAnimation
34
+ },
35
+ cache: {
36
+ getter: getCache
37
+ },
38
+ offset: {
39
+ getter: getOffset
40
+ },
41
+ placement: {
42
+ getter: getPlacement
43
+ },
44
+ loading: {
45
+ getter: getLoading
46
+ },
47
+ trigger: {
48
+ getter: getTrigger$1
49
+ }
50
+ };
51
+
52
+ const ORDERED_OPTIONS = [ "trigger", "loading", "cache", "animation", "placement", "offset" ];
53
+
54
+ const TRIGGERS = [ "hover", "click" ];
55
+
56
+ const ANIMATIONS = [ false, "slide-in", "fade-in", "slide-out", "custom" ];
57
+
58
+ const PLACEMENTS = [ "auto", "top", "top-start", "top-end", "right", "right-start", "right-end", "bottom", "bottom-start", "bottom-end", "left", "left-start", "left-end" ];
59
+
60
+ const LOADINGS = [ "asyn", "preload", "lazy" ];
61
+
62
+ function parseCSSSize(value) {
63
+ if (typeof value === "number") {
64
+ return value;
65
+ } else if (/^(-?\d+\.?\d+)px$/.test(value)) {
66
+ return parseFloat(value);
67
+ } else if (/^(-?\d*\.?\d+)rem$/.test(value)) {
68
+ return parseFloat(value) * parseFloat(getComputedStyle(document.documentElement).fontSize);
69
+ }
70
+ return 0;
71
+ }
72
+
73
+ function getOffset(optionsInt) {
74
+ const offsetBits = Number(BigInt(optionsInt) >> BigInt(23));
75
+ if (offsetBits === 0) return 0;
76
+ const isNegative = (offsetBits & 1) === 1;
77
+ const isREM = (offsetBits & 2) === 2;
78
+ const decimals = offsetBits >> 2 & 2047;
79
+ const integer = offsetBits >> 2 + 11;
80
+ const CSSSize = `${isNegative ? "-" : ""}${integer}.${decimals}${isREM ? "rem" : "px"}`;
81
+ return parseCSSSize(CSSSize);
82
+ }
83
+
84
+ function getPlacement(optionsInt) {
85
+ const placementBits = optionsInt >> 7 & 65535;
86
+ let shift = 0;
87
+ let lastPlacement = null;
88
+ const placements = [];
89
+ while (lastPlacement !== "auto" && shift < 16) {
90
+ lastPlacement = PLACEMENTS[placementBits >> shift & 15];
91
+ placements.push(lastPlacement);
92
+ shift += 4;
93
+ }
94
+ return placements;
95
+ }
96
+
97
+ function getAnimation(optionsInt) {
98
+ return ANIMATIONS[(optionsInt & 56) >> 4];
99
+ }
100
+
101
+ function getCache(optionsInt) {
102
+ return (optionsInt & 8) === 8;
103
+ }
104
+
105
+ function getLoading(optionsInt) {
106
+ return LOADINGS[optionsInt & 3 >> 1];
107
+ }
108
+
109
+ function getTrigger$1(optionsInt) {
110
+ return TRIGGERS[optionsInt & 1];
111
+ }
112
+
113
+ const HovercardOptions = {
114
+ animation: undefined,
115
+ cache: undefined,
116
+ offset: undefined,
117
+ placement: undefined,
118
+ loading: undefined,
119
+ trigger: undefined
120
+ };
121
+
122
+ function extractOptionsFromElement(coupdoeilElement) {
123
+ const optionsInt = coupdoeilElement.hovercardController.optionsInt ||= parseOtionsInt(coupdoeilElement);
124
+ const options = Object.create(HovercardOptions);
125
+ for (const option of ORDERED_OPTIONS) {
126
+ options[option] = OPTIONS[option].getter(optionsInt);
127
+ }
128
+ return options;
129
+ }
130
+
131
+ function parseOtionsInt(coupdoeilElement) {
132
+ const optionsString = coupdoeilElement.getAttribute("hc");
133
+ return parseInt(optionsString, 36);
134
+ }
135
+
136
+ function extractOptionFromElement(coupdoeilElement, optionName) {
137
+ const optionsInt = coupdoeilElement.hovercardController.optionsInt ||= parseOtionsInt(coupdoeilElement);
138
+ return OPTIONS[optionName].getter(optionsInt);
139
+ }
140
+
141
+ function getType(controller) {
142
+ return controller.coupdoeilElement.getAttribute("hc-type");
143
+ }
144
+
145
+ function getParams(controller) {
146
+ return controller.coupdoeilElement.getAttribute("hc-params");
147
+ }
148
+
149
+ function getTrigger(controller) {
150
+ return extractOptionFromElement(controller.coupdoeilElement, "trigger");
151
+ }
152
+
153
+ function triggeredOnClick(controller) {
154
+ return getTrigger(controller) === "click";
155
+ }
156
+
157
+ function noTriggeredOnClick(controller) {
158
+ return getTrigger(controller) !== "click";
159
+ }
160
+
161
+ function triggeredOnHover(controller) {
162
+ return getTrigger(controller) === "hover";
163
+ }
164
+
165
+ function notTriggeredOnHover(controller) {
166
+ return getTrigger(controller) !== "hover";
167
+ }
168
+
169
+ function preloadedContentElement(controller) {
170
+ return controller.coupdoeilElement.querySelector(".hovercard-content");
171
+ }
172
+
173
+ const hovercardContentHTMLMap = new Map;
174
+
175
+ function cacheMapKey(controller) {
176
+ if (preloadedContentElement(controller)) {
177
+ return controller.coupdoeilElement.uniqueId;
178
+ }
179
+ return getType(controller) + getParams(controller);
180
+ }
181
+
182
+ function getHovercardContentHTML(controller) {
183
+ return hovercardContentHTMLMap.get(cacheMapKey(controller));
184
+ }
185
+
186
+ function setHovercardContentHTML(controller, value) {
187
+ hovercardContentHTMLMap.set(cacheMapKey(controller), value);
188
+ }
189
+
190
+ async function enter(element, transitionName = null) {
191
+ element.classList.remove("hidden");
192
+ await transition("enter", element, transitionName);
193
+ }
194
+
195
+ async function leave(element, transitionName = null) {
196
+ await transition("leave", element, transitionName);
197
+ element.classList.add("hidden");
198
+ }
199
+
200
+ async function transition(direction, element, animation) {
201
+ const dataset = element.dataset;
202
+ const animationClass = animation ? `${animation}-${direction}` : direction;
203
+ let transition = `transition${direction.charAt(0).toUpperCase() + direction.slice(1)}`;
204
+ const genesis = dataset[transition] ? dataset[transition].split(" ") : [ animationClass ];
205
+ const start = dataset[`${transition}Start`] ? dataset[`${transition}Start`].split(" ") : [ `${animationClass}-start` ];
206
+ const end = dataset[`${transition}End`] ? dataset[`${transition}End`].split(" ") : [ `${animationClass}-end` ];
207
+ addClasses(element, genesis);
208
+ addClasses(element, start);
209
+ await nextFrame();
210
+ removeClasses(element, start);
211
+ addClasses(element, end);
212
+ await afterTransition(element);
213
+ removeClasses(element, end);
214
+ removeClasses(element, genesis);
215
+ }
216
+
217
+ function addClasses(element, classes) {
218
+ element.classList.add(...classes);
219
+ }
220
+
221
+ function removeClasses(element, classes) {
222
+ element.classList.remove(...classes);
223
+ }
224
+
225
+ function nextFrame() {
226
+ return new Promise((resolve => {
227
+ requestAnimationFrame((() => {
228
+ requestAnimationFrame(resolve);
229
+ }));
230
+ }));
231
+ }
232
+
233
+ function afterTransition(element) {
234
+ return new Promise((resolve => {
235
+ const computedDuration = getComputedStyle(element).transitionDuration.split(",")[0];
236
+ const duration = Number(computedDuration.replace("s", "")) * 1e3;
237
+ setTimeout((() => {
238
+ resolve();
239
+ }), duration);
240
+ }));
241
+ }
242
+
243
+ function detachFromParent(controller) {
244
+ if (controller.parent) {
245
+ controller.parent.children.delete(controller);
246
+ controller.parent = null;
247
+ }
248
+ }
249
+
250
+ function cancelCloseRequest(controller) {
251
+ clearTimeout(controller.closingRequest);
252
+ controller.closingRequest = null;
253
+ }
254
+
255
+ function closeNow(controller, allowAnimation = true) {
256
+ if (controller.closing || controller.isClosed) return;
257
+ controller.closing = true;
258
+ cancelOpenCloseActions(controller);
259
+ controller.children.forEach((childController => {
260
+ closeNow(childController);
261
+ }));
262
+ detachFromParent(controller);
263
+ if (allowAnimation && controller.card.dataset.animation) {
264
+ closeWithAnimation(controller);
265
+ } else {
266
+ closeWithoutAnimation(controller);
267
+ }
268
+ }
269
+
270
+ async function closeWithAnimation(controller) {
271
+ await leave(controller.card, "hovercard");
272
+ closeWithoutAnimation(controller);
273
+ }
274
+
275
+ function closeWithoutAnimation(controller) {
276
+ controller.card.remove();
277
+ controller.card = null;
278
+ delete controller.closing;
279
+ delete controller.coupdoeilElement.dataset.hovercardOpen;
280
+ }
281
+
282
+ function clear(controller) {
283
+ closeNow(controller, false);
284
+ }
285
+
286
+ function closeLater(controller) {
287
+ cancelOpenCloseActions(controller);
288
+ controller.closingRequest = setTimeout((() => {
289
+ closeNow(controller);
290
+ }), defaultConfig.closingDelay);
291
+ }
292
+
293
+ function closeChildrenNow(controller) {
294
+ controller.children.forEach((childController => {
295
+ closeNow(childController);
296
+ }));
297
+ }
298
+
299
+ function closeOnHoverChildrenLater(controller) {
300
+ controller.children.forEach((childController => {
301
+ if (triggeredOnHover(childController)) {
302
+ closeLater(childController);
303
+ }
304
+ }));
305
+ }
306
+
307
+ const CURRENT_HOVERCARDS_BY_ID = new Map;
308
+
309
+ window.hovercads = CURRENT_HOVERCARDS_BY_ID;
310
+
311
+ function clearHovercardContentCache() {
312
+ hovercardContentHTMLMap.clear();
313
+ }
314
+
315
+ function currentHovercardsById() {
316
+ return CURRENT_HOVERCARDS_BY_ID;
317
+ }
318
+
319
+ function addToCurrents(coupdoeilElement) {
320
+ CURRENT_HOVERCARDS_BY_ID.set(coupdoeilElement.uniqueId, coupdoeilElement);
321
+ }
322
+
323
+ function closeAllNow() {
324
+ for (const coupdoeilElement of CURRENT_HOVERCARDS_BY_ID.values()) {
325
+ closeNow(coupdoeilElement.hovercardController);
326
+ removeFromCurrents(coupdoeilElement);
327
+ }
328
+ }
329
+
330
+ function clearAll() {
331
+ for (const coupdoeilElement of CURRENT_HOVERCARDS_BY_ID.values()) {
332
+ clear(coupdoeilElement.hovercardController);
333
+ removeFromCurrents(coupdoeilElement);
334
+ }
335
+ }
336
+
337
+ function closeTriggeredOnHoverNow() {
338
+ for (const coupdoeilElement of CURRENT_HOVERCARDS_BY_ID.values()) {
339
+ if (triggeredOnHover(coupdoeilElement.hovercardController)) {
340
+ closeNow(coupdoeilElement.hovercardController);
341
+ removeFromCurrents(coupdoeilElement);
342
+ }
343
+ }
344
+ }
345
+
346
+ function closeTriggeredOnHoverLater() {
347
+ for (const coupdoeilElement of CURRENT_HOVERCARDS_BY_ID.values()) {
348
+ if (triggeredOnHover(coupdoeilElement.hovercardController)) {
349
+ closeLater(coupdoeilElement.hovercardController);
350
+ removeFromCurrents(coupdoeilElement);
351
+ }
352
+ }
353
+ }
354
+
355
+ function removeFromCurrents(coupdoeilElement) {
356
+ CURRENT_HOVERCARDS_BY_ID.delete(coupdoeilElement.uniqueId);
357
+ }
358
+
359
+ function cancelOpenCloseActions(controller) {
360
+ cancelOpening(controller);
361
+ cancelCloseRequest(controller);
362
+ }
363
+
364
+ const sides = [ "top", "right", "bottom", "left" ];
365
+
366
+ const alignments = [ "start", "end" ];
367
+
368
+ const placements = sides.reduce(((acc, side) => acc.concat(side, side + "-" + alignments[0], side + "-" + alignments[1])), []);
369
+
370
+ const min = Math.min;
371
+
372
+ const max = Math.max;
373
+
374
+ const round = Math.round;
375
+
376
+ const createCoords = v => ({
377
+ x: v,
378
+ y: v
379
+ });
380
+
381
+ const oppositeSideMap = {
382
+ left: "right",
383
+ right: "left",
384
+ bottom: "top",
385
+ top: "bottom"
386
+ };
387
+
388
+ const oppositeAlignmentMap = {
389
+ start: "end",
390
+ end: "start"
391
+ };
392
+
393
+ function clamp(start, value, end) {
394
+ return max(start, min(value, end));
395
+ }
396
+
397
+ function evaluate(value, param) {
398
+ return typeof value === "function" ? value(param) : value;
399
+ }
400
+
401
+ function getSide(placement) {
402
+ return placement.split("-")[0];
403
+ }
404
+
405
+ function getAlignment(placement) {
406
+ return placement.split("-")[1];
407
+ }
408
+
409
+ function getOppositeAxis(axis) {
410
+ return axis === "x" ? "y" : "x";
411
+ }
412
+
413
+ function getAxisLength(axis) {
414
+ return axis === "y" ? "height" : "width";
415
+ }
416
+
417
+ function getSideAxis(placement) {
418
+ return [ "top", "bottom" ].includes(getSide(placement)) ? "y" : "x";
419
+ }
420
+
421
+ function getAlignmentAxis(placement) {
422
+ return getOppositeAxis(getSideAxis(placement));
423
+ }
424
+
425
+ function getAlignmentSides(placement, rects, rtl) {
426
+ if (rtl === void 0) {
427
+ rtl = false;
428
+ }
429
+ const alignment = getAlignment(placement);
430
+ const alignmentAxis = getAlignmentAxis(placement);
431
+ const length = getAxisLength(alignmentAxis);
432
+ let mainAlignmentSide = alignmentAxis === "x" ? alignment === (rtl ? "end" : "start") ? "right" : "left" : alignment === "start" ? "bottom" : "top";
433
+ if (rects.reference[length] > rects.floating[length]) {
434
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
435
+ }
436
+ return [ mainAlignmentSide, getOppositePlacement(mainAlignmentSide) ];
437
+ }
438
+
439
+ function getExpandedPlacements(placement) {
440
+ const oppositePlacement = getOppositePlacement(placement);
441
+ return [ getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement) ];
442
+ }
443
+
444
+ function getOppositeAlignmentPlacement(placement) {
445
+ return placement.replace(/start|end/g, (alignment => oppositeAlignmentMap[alignment]));
446
+ }
447
+
448
+ function getSideList(side, isStart, rtl) {
449
+ const lr = [ "left", "right" ];
450
+ const rl = [ "right", "left" ];
451
+ const tb = [ "top", "bottom" ];
452
+ const bt = [ "bottom", "top" ];
453
+ switch (side) {
454
+ case "top":
455
+ case "bottom":
456
+ if (rtl) return isStart ? rl : lr;
457
+ return isStart ? lr : rl;
458
+
459
+ case "left":
460
+ case "right":
461
+ return isStart ? tb : bt;
462
+
463
+ default:
464
+ return [];
465
+ }
466
+ }
467
+
468
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
469
+ const alignment = getAlignment(placement);
470
+ let list = getSideList(getSide(placement), direction === "start", rtl);
471
+ if (alignment) {
472
+ list = list.map((side => side + "-" + alignment));
473
+ if (flipAlignment) {
474
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
475
+ }
476
+ }
477
+ return list;
478
+ }
479
+
480
+ function getOppositePlacement(placement) {
481
+ return placement.replace(/left|right|bottom|top/g, (side => oppositeSideMap[side]));
482
+ }
483
+
484
+ function expandPaddingObject(padding) {
485
+ return {
486
+ top: 0,
487
+ right: 0,
488
+ bottom: 0,
489
+ left: 0,
490
+ ...padding
491
+ };
492
+ }
493
+
494
+ function getPaddingObject(padding) {
495
+ return typeof padding !== "number" ? expandPaddingObject(padding) : {
496
+ top: padding,
497
+ right: padding,
498
+ bottom: padding,
499
+ left: padding
500
+ };
501
+ }
502
+
503
+ function rectToClientRect(rect) {
504
+ const {x: x, y: y, width: width, height: height} = rect;
505
+ return {
506
+ width: width,
507
+ height: height,
508
+ top: y,
509
+ left: x,
510
+ right: x + width,
511
+ bottom: y + height,
512
+ x: x,
513
+ y: y
514
+ };
515
+ }
516
+
517
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
518
+ let {reference: reference, floating: floating} = _ref;
519
+ const sideAxis = getSideAxis(placement);
520
+ const alignmentAxis = getAlignmentAxis(placement);
521
+ const alignLength = getAxisLength(alignmentAxis);
522
+ const side = getSide(placement);
523
+ const isVertical = sideAxis === "y";
524
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
525
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
526
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
527
+ let coords;
528
+ switch (side) {
529
+ case "top":
530
+ coords = {
531
+ x: commonX,
532
+ y: reference.y - floating.height
533
+ };
534
+ break;
535
+
536
+ case "bottom":
537
+ coords = {
538
+ x: commonX,
539
+ y: reference.y + reference.height
540
+ };
541
+ break;
542
+
543
+ case "right":
544
+ coords = {
545
+ x: reference.x + reference.width,
546
+ y: commonY
547
+ };
548
+ break;
549
+
550
+ case "left":
551
+ coords = {
552
+ x: reference.x - floating.width,
553
+ y: commonY
554
+ };
555
+ break;
556
+
557
+ default:
558
+ coords = {
559
+ x: reference.x,
560
+ y: reference.y
561
+ };
562
+ }
563
+ switch (getAlignment(placement)) {
564
+ case "start":
565
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
566
+ break;
567
+
568
+ case "end":
569
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
570
+ break;
571
+ }
572
+ return coords;
573
+ }
574
+
575
+ const computePosition$1 = async (reference, floating, config) => {
576
+ const {placement: placement = "bottom", strategy: strategy = "absolute", middleware: middleware = [], platform: platform} = config;
577
+ const validMiddleware = middleware.filter(Boolean);
578
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
579
+ let rects = await platform.getElementRects({
580
+ reference: reference,
581
+ floating: floating,
582
+ strategy: strategy
583
+ });
584
+ let {x: x, y: y} = computeCoordsFromPlacement(rects, placement, rtl);
585
+ let statefulPlacement = placement;
586
+ let middlewareData = {};
587
+ let resetCount = 0;
588
+ for (let i = 0; i < validMiddleware.length; i++) {
589
+ const {name: name, fn: fn} = validMiddleware[i];
590
+ const {x: nextX, y: nextY, data: data, reset: reset} = await fn({
591
+ x: x,
592
+ y: y,
593
+ initialPlacement: placement,
594
+ placement: statefulPlacement,
595
+ strategy: strategy,
596
+ middlewareData: middlewareData,
597
+ rects: rects,
598
+ platform: platform,
599
+ elements: {
600
+ reference: reference,
601
+ floating: floating
602
+ }
603
+ });
604
+ x = nextX != null ? nextX : x;
605
+ y = nextY != null ? nextY : y;
606
+ middlewareData = {
607
+ ...middlewareData,
608
+ [name]: {
609
+ ...middlewareData[name],
610
+ ...data
611
+ }
612
+ };
613
+ if (reset && resetCount <= 50) {
614
+ resetCount++;
615
+ if (typeof reset === "object") {
616
+ if (reset.placement) {
617
+ statefulPlacement = reset.placement;
618
+ }
619
+ if (reset.rects) {
620
+ rects = reset.rects === true ? await platform.getElementRects({
621
+ reference: reference,
622
+ floating: floating,
623
+ strategy: strategy
624
+ }) : reset.rects;
625
+ }
626
+ ({x: x, y: y} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
627
+ }
628
+ i = -1;
629
+ }
630
+ }
631
+ return {
632
+ x: x,
633
+ y: y,
634
+ placement: statefulPlacement,
635
+ strategy: strategy,
636
+ middlewareData: middlewareData
637
+ };
638
+ };
639
+
640
+ async function detectOverflow$1(state, options) {
641
+ var _await$platform$isEle;
642
+ if (options === void 0) {
643
+ options = {};
644
+ }
645
+ const {x: x, y: y, platform: platform, rects: rects, elements: elements, strategy: strategy} = state;
646
+ const {boundary: boundary = "clippingAncestors", rootBoundary: rootBoundary = "viewport", elementContext: elementContext = "floating", altBoundary: altBoundary = false, padding: padding = 0} = evaluate(options, state);
647
+ const paddingObject = getPaddingObject(padding);
648
+ const altContext = elementContext === "floating" ? "reference" : "floating";
649
+ const element = elements[altBoundary ? altContext : elementContext];
650
+ const clippingClientRect = rectToClientRect(await platform.getClippingRect({
651
+ element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating)),
652
+ boundary: boundary,
653
+ rootBoundary: rootBoundary,
654
+ strategy: strategy
655
+ }));
656
+ const rect = elementContext === "floating" ? {
657
+ x: x,
658
+ y: y,
659
+ width: rects.floating.width,
660
+ height: rects.floating.height
661
+ } : rects.reference;
662
+ const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
663
+ const offsetScale = await (platform.isElement == null ? void 0 : platform.isElement(offsetParent)) ? await (platform.getScale == null ? void 0 : platform.getScale(offsetParent)) || {
664
+ x: 1,
665
+ y: 1
666
+ } : {
667
+ x: 1,
668
+ y: 1
669
+ };
670
+ const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
671
+ elements: elements,
672
+ rect: rect,
673
+ offsetParent: offsetParent,
674
+ strategy: strategy
675
+ }) : rect);
676
+ return {
677
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
678
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
679
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
680
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
681
+ };
682
+ }
683
+
684
+ const arrow$1 = options => ({
685
+ name: "arrow",
686
+ options: options,
687
+ async fn(state) {
688
+ const {x: x, y: y, placement: placement, rects: rects, platform: platform, elements: elements, middlewareData: middlewareData} = state;
689
+ const {element: element, padding: padding = 0} = evaluate(options, state) || {};
690
+ if (element == null) {
691
+ return {};
692
+ }
693
+ const paddingObject = getPaddingObject(padding);
694
+ const coords = {
695
+ x: x,
696
+ y: y
697
+ };
698
+ const axis = getAlignmentAxis(placement);
699
+ const length = getAxisLength(axis);
700
+ const arrowDimensions = await platform.getDimensions(element);
701
+ const isYAxis = axis === "y";
702
+ const minProp = isYAxis ? "top" : "left";
703
+ const maxProp = isYAxis ? "bottom" : "right";
704
+ const clientProp = isYAxis ? "clientHeight" : "clientWidth";
705
+ const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
706
+ const startDiff = coords[axis] - rects.reference[axis];
707
+ const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
708
+ let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
709
+ if (!clientSize || !await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent))) {
710
+ clientSize = elements.floating[clientProp] || rects.floating[length];
711
+ }
712
+ const centerToReference = endDiff / 2 - startDiff / 2;
713
+ const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
714
+ const minPadding = min(paddingObject[minProp], largestPossiblePadding);
715
+ const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
716
+ const min$1 = minPadding;
717
+ const max = clientSize - arrowDimensions[length] - maxPadding;
718
+ const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
719
+ const offset = clamp(min$1, center, max);
720
+ const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
721
+ const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;
722
+ return {
723
+ [axis]: coords[axis] + alignmentOffset,
724
+ data: {
725
+ [axis]: offset,
726
+ centerOffset: center - offset - alignmentOffset,
727
+ ...shouldAddOffset && {
728
+ alignmentOffset: alignmentOffset
729
+ }
730
+ },
731
+ reset: shouldAddOffset
732
+ };
733
+ }
734
+ });
735
+
736
+ function getPlacementList(alignment, autoAlignment, allowedPlacements) {
737
+ const allowedPlacementsSortedByAlignment = alignment ? [ ...allowedPlacements.filter((placement => getAlignment(placement) === alignment)), ...allowedPlacements.filter((placement => getAlignment(placement) !== alignment)) ] : allowedPlacements.filter((placement => getSide(placement) === placement));
738
+ return allowedPlacementsSortedByAlignment.filter((placement => {
739
+ if (alignment) {
740
+ return getAlignment(placement) === alignment || (autoAlignment ? getOppositeAlignmentPlacement(placement) !== placement : false);
741
+ }
742
+ return true;
743
+ }));
744
+ }
745
+
746
+ const autoPlacement$1 = function(options) {
747
+ if (options === void 0) {
748
+ options = {};
749
+ }
750
+ return {
751
+ name: "autoPlacement",
752
+ options: options,
753
+ async fn(state) {
754
+ var _middlewareData$autoP, _middlewareData$autoP2, _placementsThatFitOnE;
755
+ const {rects: rects, middlewareData: middlewareData, placement: placement, platform: platform, elements: elements} = state;
756
+ const {crossAxis: crossAxis = false, alignment: alignment, allowedPlacements: allowedPlacements = placements, autoAlignment: autoAlignment = true, ...detectOverflowOptions} = evaluate(options, state);
757
+ const placements$1 = alignment !== undefined || allowedPlacements === placements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements;
758
+ const overflow = await detectOverflow$1(state, detectOverflowOptions);
759
+ const currentIndex = ((_middlewareData$autoP = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP.index) || 0;
760
+ const currentPlacement = placements$1[currentIndex];
761
+ if (currentPlacement == null) {
762
+ return {};
763
+ }
764
+ const alignmentSides = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));
765
+ if (placement !== currentPlacement) {
766
+ return {
767
+ reset: {
768
+ placement: placements$1[0]
769
+ }
770
+ };
771
+ }
772
+ const currentOverflows = [ overflow[getSide(currentPlacement)], overflow[alignmentSides[0]], overflow[alignmentSides[1]] ];
773
+ const allOverflows = [ ...((_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.overflows) || [], {
774
+ placement: currentPlacement,
775
+ overflows: currentOverflows
776
+ } ];
777
+ const nextPlacement = placements$1[currentIndex + 1];
778
+ if (nextPlacement) {
779
+ return {
780
+ data: {
781
+ index: currentIndex + 1,
782
+ overflows: allOverflows
783
+ },
784
+ reset: {
785
+ placement: nextPlacement
786
+ }
787
+ };
788
+ }
789
+ const placementsSortedByMostSpace = allOverflows.map((d => {
790
+ const alignment = getAlignment(d.placement);
791
+ return [ d.placement, alignment && crossAxis ? d.overflows.slice(0, 2).reduce(((acc, v) => acc + v), 0) : d.overflows[0], d.overflows ];
792
+ })).sort(((a, b) => a[1] - b[1]));
793
+ const placementsThatFitOnEachSide = placementsSortedByMostSpace.filter((d => d[2].slice(0, getAlignment(d[0]) ? 2 : 3).every((v => v <= 0))));
794
+ const resetPlacement = ((_placementsThatFitOnE = placementsThatFitOnEachSide[0]) == null ? void 0 : _placementsThatFitOnE[0]) || placementsSortedByMostSpace[0][0];
795
+ if (resetPlacement !== placement) {
796
+ return {
797
+ data: {
798
+ index: currentIndex + 1,
799
+ overflows: allOverflows
800
+ },
801
+ reset: {
802
+ placement: resetPlacement
803
+ }
804
+ };
805
+ }
806
+ return {};
807
+ }
808
+ };
809
+ };
810
+
811
+ const flip = function(options) {
812
+ if (options === void 0) {
813
+ options = {};
814
+ }
815
+ return {
816
+ name: "flip",
817
+ options: options,
818
+ async fn(state) {
819
+ var _middlewareData$arrow, _middlewareData$flip;
820
+ const {placement: placement, middlewareData: middlewareData, rects: rects, initialPlacement: initialPlacement, platform: platform, elements: elements} = state;
821
+ const {mainAxis: checkMainAxis = true, crossAxis: checkCrossAxis = true, fallbackPlacements: specifiedFallbackPlacements, fallbackStrategy: fallbackStrategy = "bestFit", fallbackAxisSideDirection: fallbackAxisSideDirection = "none", flipAlignment: flipAlignment = true, ...detectOverflowOptions} = evaluate(options, state);
822
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
823
+ return {};
824
+ }
825
+ const side = getSide(placement);
826
+ const initialSideAxis = getSideAxis(initialPlacement);
827
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
828
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
829
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [ getOppositePlacement(initialPlacement) ] : getExpandedPlacements(initialPlacement));
830
+ const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== "none";
831
+ if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
832
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
833
+ }
834
+ const placements = [ initialPlacement, ...fallbackPlacements ];
835
+ const overflow = await detectOverflow$1(state, detectOverflowOptions);
836
+ const overflows = [];
837
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
838
+ if (checkMainAxis) {
839
+ overflows.push(overflow[side]);
840
+ }
841
+ if (checkCrossAxis) {
842
+ const sides = getAlignmentSides(placement, rects, rtl);
843
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
844
+ }
845
+ overflowsData = [ ...overflowsData, {
846
+ placement: placement,
847
+ overflows: overflows
848
+ } ];
849
+ if (!overflows.every((side => side <= 0))) {
850
+ var _middlewareData$flip2, _overflowsData$filter;
851
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
852
+ const nextPlacement = placements[nextIndex];
853
+ if (nextPlacement) {
854
+ return {
855
+ data: {
856
+ index: nextIndex,
857
+ overflows: overflowsData
858
+ },
859
+ reset: {
860
+ placement: nextPlacement
861
+ }
862
+ };
863
+ }
864
+ let resetPlacement = (_overflowsData$filter = overflowsData.filter((d => d.overflows[0] <= 0)).sort(((a, b) => a.overflows[1] - b.overflows[1]))[0]) == null ? void 0 : _overflowsData$filter.placement;
865
+ if (!resetPlacement) {
866
+ switch (fallbackStrategy) {
867
+ case "bestFit":
868
+ {
869
+ var _overflowsData$filter2;
870
+ const placement = (_overflowsData$filter2 = overflowsData.filter((d => {
871
+ if (hasFallbackAxisSideDirection) {
872
+ const currentSideAxis = getSideAxis(d.placement);
873
+ return currentSideAxis === initialSideAxis || currentSideAxis === "y";
874
+ }
875
+ return true;
876
+ })).map((d => [ d.placement, d.overflows.filter((overflow => overflow > 0)).reduce(((acc, overflow) => acc + overflow), 0) ])).sort(((a, b) => a[1] - b[1]))[0]) == null ? void 0 : _overflowsData$filter2[0];
877
+ if (placement) {
878
+ resetPlacement = placement;
879
+ }
880
+ break;
881
+ }
882
+
883
+ case "initialPlacement":
884
+ resetPlacement = initialPlacement;
885
+ break;
886
+ }
887
+ }
888
+ if (placement !== resetPlacement) {
889
+ return {
890
+ reset: {
891
+ placement: resetPlacement
892
+ }
893
+ };
894
+ }
895
+ }
896
+ return {};
897
+ }
898
+ };
899
+ };
900
+
901
+ function getSideOffsets(overflow, rect) {
902
+ return {
903
+ top: overflow.top - rect.height,
904
+ right: overflow.right - rect.width,
905
+ bottom: overflow.bottom - rect.height,
906
+ left: overflow.left - rect.width
907
+ };
908
+ }
909
+
910
+ function isAnySideFullyClipped(overflow) {
911
+ return sides.some((side => overflow[side] >= 0));
912
+ }
913
+
914
+ const hide = function(options) {
915
+ if (options === void 0) {
916
+ options = {};
917
+ }
918
+ return {
919
+ name: "hide",
920
+ options: options,
921
+ async fn(state) {
922
+ const {rects: rects} = state;
923
+ const {strategy: strategy = "referenceHidden", ...detectOverflowOptions} = evaluate(options, state);
924
+ switch (strategy) {
925
+ case "referenceHidden":
926
+ {
927
+ const overflow = await detectOverflow$1(state, {
928
+ ...detectOverflowOptions,
929
+ elementContext: "reference"
930
+ });
931
+ const offsets = getSideOffsets(overflow, rects.reference);
932
+ return {
933
+ data: {
934
+ referenceHiddenOffsets: offsets,
935
+ referenceHidden: isAnySideFullyClipped(offsets)
936
+ }
937
+ };
938
+ }
939
+
940
+ case "escaped":
941
+ {
942
+ const overflow = await detectOverflow$1(state, {
943
+ ...detectOverflowOptions,
944
+ altBoundary: true
945
+ });
946
+ const offsets = getSideOffsets(overflow, rects.floating);
947
+ return {
948
+ data: {
949
+ escapedOffsets: offsets,
950
+ escaped: isAnySideFullyClipped(offsets)
951
+ }
952
+ };
953
+ }
954
+
955
+ default:
956
+ {
957
+ return {};
958
+ }
959
+ }
960
+ }
961
+ };
962
+ };
963
+
964
+ function getBoundingRect(rects) {
965
+ const minX = min(...rects.map((rect => rect.left)));
966
+ const minY = min(...rects.map((rect => rect.top)));
967
+ const maxX = max(...rects.map((rect => rect.right)));
968
+ const maxY = max(...rects.map((rect => rect.bottom)));
969
+ return {
970
+ x: minX,
971
+ y: minY,
972
+ width: maxX - minX,
973
+ height: maxY - minY
974
+ };
975
+ }
976
+
977
+ function getRectsByLine(rects) {
978
+ const sortedRects = rects.slice().sort(((a, b) => a.y - b.y));
979
+ const groups = [];
980
+ let prevRect = null;
981
+ for (let i = 0; i < sortedRects.length; i++) {
982
+ const rect = sortedRects[i];
983
+ if (!prevRect || rect.y - prevRect.y > prevRect.height / 2) {
984
+ groups.push([ rect ]);
985
+ } else {
986
+ groups[groups.length - 1].push(rect);
987
+ }
988
+ prevRect = rect;
989
+ }
990
+ return groups.map((rect => rectToClientRect(getBoundingRect(rect))));
991
+ }
992
+
993
+ const inline = function(options) {
994
+ if (options === void 0) {
995
+ options = {};
996
+ }
997
+ return {
998
+ name: "inline",
999
+ options: options,
1000
+ async fn(state) {
1001
+ const {placement: placement, elements: elements, rects: rects, platform: platform, strategy: strategy} = state;
1002
+ const {padding: padding = 2, x: x, y: y} = evaluate(options, state);
1003
+ const nativeClientRects = Array.from(await (platform.getClientRects == null ? void 0 : platform.getClientRects(elements.reference)) || []);
1004
+ const clientRects = getRectsByLine(nativeClientRects);
1005
+ const fallback = rectToClientRect(getBoundingRect(nativeClientRects));
1006
+ const paddingObject = getPaddingObject(padding);
1007
+ function getBoundingClientRect() {
1008
+ if (clientRects.length === 2 && clientRects[0].left > clientRects[1].right && x != null && y != null) {
1009
+ return clientRects.find((rect => x > rect.left - paddingObject.left && x < rect.right + paddingObject.right && y > rect.top - paddingObject.top && y < rect.bottom + paddingObject.bottom)) || fallback;
1010
+ }
1011
+ if (clientRects.length >= 2) {
1012
+ if (getSideAxis(placement) === "y") {
1013
+ const firstRect = clientRects[0];
1014
+ const lastRect = clientRects[clientRects.length - 1];
1015
+ const isTop = getSide(placement) === "top";
1016
+ const top = firstRect.top;
1017
+ const bottom = lastRect.bottom;
1018
+ const left = isTop ? firstRect.left : lastRect.left;
1019
+ const right = isTop ? firstRect.right : lastRect.right;
1020
+ const width = right - left;
1021
+ const height = bottom - top;
1022
+ return {
1023
+ top: top,
1024
+ bottom: bottom,
1025
+ left: left,
1026
+ right: right,
1027
+ width: width,
1028
+ height: height,
1029
+ x: left,
1030
+ y: top
1031
+ };
1032
+ }
1033
+ const isLeftSide = getSide(placement) === "left";
1034
+ const maxRight = max(...clientRects.map((rect => rect.right)));
1035
+ const minLeft = min(...clientRects.map((rect => rect.left)));
1036
+ const measureRects = clientRects.filter((rect => isLeftSide ? rect.left === minLeft : rect.right === maxRight));
1037
+ const top = measureRects[0].top;
1038
+ const bottom = measureRects[measureRects.length - 1].bottom;
1039
+ const left = minLeft;
1040
+ const right = maxRight;
1041
+ const width = right - left;
1042
+ const height = bottom - top;
1043
+ return {
1044
+ top: top,
1045
+ bottom: bottom,
1046
+ left: left,
1047
+ right: right,
1048
+ width: width,
1049
+ height: height,
1050
+ x: left,
1051
+ y: top
1052
+ };
1053
+ }
1054
+ return fallback;
1055
+ }
1056
+ const resetRects = await platform.getElementRects({
1057
+ reference: {
1058
+ getBoundingClientRect: getBoundingClientRect
1059
+ },
1060
+ floating: elements.floating,
1061
+ strategy: strategy
1062
+ });
1063
+ if (rects.reference.x !== resetRects.reference.x || rects.reference.y !== resetRects.reference.y || rects.reference.width !== resetRects.reference.width || rects.reference.height !== resetRects.reference.height) {
1064
+ return {
1065
+ reset: {
1066
+ rects: resetRects
1067
+ }
1068
+ };
1069
+ }
1070
+ return {};
1071
+ }
1072
+ };
1073
+ };
1074
+
1075
+ async function convertValueToCoords(state, options) {
1076
+ const {placement: placement, platform: platform, elements: elements} = state;
1077
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
1078
+ const side = getSide(placement);
1079
+ const alignment = getAlignment(placement);
1080
+ const isVertical = getSideAxis(placement) === "y";
1081
+ const mainAxisMulti = [ "left", "top" ].includes(side) ? -1 : 1;
1082
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
1083
+ const rawValue = evaluate(options, state);
1084
+ let {mainAxis: mainAxis, crossAxis: crossAxis, alignmentAxis: alignmentAxis} = typeof rawValue === "number" ? {
1085
+ mainAxis: rawValue,
1086
+ crossAxis: 0,
1087
+ alignmentAxis: null
1088
+ } : {
1089
+ mainAxis: rawValue.mainAxis || 0,
1090
+ crossAxis: rawValue.crossAxis || 0,
1091
+ alignmentAxis: rawValue.alignmentAxis
1092
+ };
1093
+ if (alignment && typeof alignmentAxis === "number") {
1094
+ crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
1095
+ }
1096
+ return isVertical ? {
1097
+ x: crossAxis * crossAxisMulti,
1098
+ y: mainAxis * mainAxisMulti
1099
+ } : {
1100
+ x: mainAxis * mainAxisMulti,
1101
+ y: crossAxis * crossAxisMulti
1102
+ };
1103
+ }
1104
+
1105
+ const offset$1 = function(options) {
1106
+ if (options === void 0) {
1107
+ options = 0;
1108
+ }
1109
+ return {
1110
+ name: "offset",
1111
+ options: options,
1112
+ async fn(state) {
1113
+ var _middlewareData$offse, _middlewareData$arrow;
1114
+ const {x: x, y: y, placement: placement, middlewareData: middlewareData} = state;
1115
+ const diffCoords = await convertValueToCoords(state, options);
1116
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
1117
+ return {};
1118
+ }
1119
+ return {
1120
+ x: x + diffCoords.x,
1121
+ y: y + diffCoords.y,
1122
+ data: {
1123
+ ...diffCoords,
1124
+ placement: placement
1125
+ }
1126
+ };
1127
+ }
1128
+ };
1129
+ };
1130
+
1131
+ const shift = function(options) {
1132
+ if (options === void 0) {
1133
+ options = {};
1134
+ }
1135
+ return {
1136
+ name: "shift",
1137
+ options: options,
1138
+ async fn(state) {
1139
+ const {x: x, y: y, placement: placement} = state;
1140
+ const {mainAxis: checkMainAxis = true, crossAxis: checkCrossAxis = false, limiter: limiter = {
1141
+ fn: _ref => {
1142
+ let {x: x, y: y} = _ref;
1143
+ return {
1144
+ x: x,
1145
+ y: y
1146
+ };
1147
+ }
1148
+ }, ...detectOverflowOptions} = evaluate(options, state);
1149
+ const coords = {
1150
+ x: x,
1151
+ y: y
1152
+ };
1153
+ const overflow = await detectOverflow$1(state, detectOverflowOptions);
1154
+ const crossAxis = getSideAxis(getSide(placement));
1155
+ const mainAxis = getOppositeAxis(crossAxis);
1156
+ let mainAxisCoord = coords[mainAxis];
1157
+ let crossAxisCoord = coords[crossAxis];
1158
+ if (checkMainAxis) {
1159
+ const minSide = mainAxis === "y" ? "top" : "left";
1160
+ const maxSide = mainAxis === "y" ? "bottom" : "right";
1161
+ const min = mainAxisCoord + overflow[minSide];
1162
+ const max = mainAxisCoord - overflow[maxSide];
1163
+ mainAxisCoord = clamp(min, mainAxisCoord, max);
1164
+ }
1165
+ if (checkCrossAxis) {
1166
+ const minSide = crossAxis === "y" ? "top" : "left";
1167
+ const maxSide = crossAxis === "y" ? "bottom" : "right";
1168
+ const min = crossAxisCoord + overflow[minSide];
1169
+ const max = crossAxisCoord - overflow[maxSide];
1170
+ crossAxisCoord = clamp(min, crossAxisCoord, max);
1171
+ }
1172
+ const limitedCoords = limiter.fn({
1173
+ ...state,
1174
+ [mainAxis]: mainAxisCoord,
1175
+ [crossAxis]: crossAxisCoord
1176
+ });
1177
+ return {
1178
+ ...limitedCoords,
1179
+ data: {
1180
+ x: limitedCoords.x - x,
1181
+ y: limitedCoords.y - y,
1182
+ enabled: {
1183
+ [mainAxis]: checkMainAxis,
1184
+ [crossAxis]: checkCrossAxis
1185
+ }
1186
+ }
1187
+ };
1188
+ }
1189
+ };
1190
+ };
1191
+
1192
+ const limitShift = function(options) {
1193
+ if (options === void 0) {
1194
+ options = {};
1195
+ }
1196
+ return {
1197
+ options: options,
1198
+ fn(state) {
1199
+ const {x: x, y: y, placement: placement, rects: rects, middlewareData: middlewareData} = state;
1200
+ const {offset: offset = 0, mainAxis: checkMainAxis = true, crossAxis: checkCrossAxis = true} = evaluate(options, state);
1201
+ const coords = {
1202
+ x: x,
1203
+ y: y
1204
+ };
1205
+ const crossAxis = getSideAxis(placement);
1206
+ const mainAxis = getOppositeAxis(crossAxis);
1207
+ let mainAxisCoord = coords[mainAxis];
1208
+ let crossAxisCoord = coords[crossAxis];
1209
+ const rawOffset = evaluate(offset, state);
1210
+ const computedOffset = typeof rawOffset === "number" ? {
1211
+ mainAxis: rawOffset,
1212
+ crossAxis: 0
1213
+ } : {
1214
+ mainAxis: 0,
1215
+ crossAxis: 0,
1216
+ ...rawOffset
1217
+ };
1218
+ if (checkMainAxis) {
1219
+ const len = mainAxis === "y" ? "height" : "width";
1220
+ const limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis;
1221
+ const limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis;
1222
+ if (mainAxisCoord < limitMin) {
1223
+ mainAxisCoord = limitMin;
1224
+ } else if (mainAxisCoord > limitMax) {
1225
+ mainAxisCoord = limitMax;
1226
+ }
1227
+ }
1228
+ if (checkCrossAxis) {
1229
+ var _middlewareData$offse, _middlewareData$offse2;
1230
+ const len = mainAxis === "y" ? "width" : "height";
1231
+ const isOriginSide = [ "top", "left" ].includes(getSide(placement));
1232
+ const limitMin = rects.reference[crossAxis] - rects.floating[len] + (isOriginSide ? ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse[crossAxis]) || 0 : 0) + (isOriginSide ? 0 : computedOffset.crossAxis);
1233
+ const limitMax = rects.reference[crossAxis] + rects.reference[len] + (isOriginSide ? 0 : ((_middlewareData$offse2 = middlewareData.offset) == null ? void 0 : _middlewareData$offse2[crossAxis]) || 0) - (isOriginSide ? computedOffset.crossAxis : 0);
1234
+ if (crossAxisCoord < limitMin) {
1235
+ crossAxisCoord = limitMin;
1236
+ } else if (crossAxisCoord > limitMax) {
1237
+ crossAxisCoord = limitMax;
1238
+ }
1239
+ }
1240
+ return {
1241
+ [mainAxis]: mainAxisCoord,
1242
+ [crossAxis]: crossAxisCoord
1243
+ };
1244
+ }
1245
+ };
1246
+ };
1247
+
1248
+ const size = function(options) {
1249
+ if (options === void 0) {
1250
+ options = {};
1251
+ }
1252
+ return {
1253
+ name: "size",
1254
+ options: options,
1255
+ async fn(state) {
1256
+ var _state$middlewareData, _state$middlewareData2;
1257
+ const {placement: placement, rects: rects, platform: platform, elements: elements} = state;
1258
+ const {apply: apply = () => {}, ...detectOverflowOptions} = evaluate(options, state);
1259
+ const overflow = await detectOverflow$1(state, detectOverflowOptions);
1260
+ const side = getSide(placement);
1261
+ const alignment = getAlignment(placement);
1262
+ const isYAxis = getSideAxis(placement) === "y";
1263
+ const {width: width, height: height} = rects.floating;
1264
+ let heightSide;
1265
+ let widthSide;
1266
+ if (side === "top" || side === "bottom") {
1267
+ heightSide = side;
1268
+ widthSide = alignment === (await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)) ? "start" : "end") ? "left" : "right";
1269
+ } else {
1270
+ widthSide = side;
1271
+ heightSide = alignment === "end" ? "top" : "bottom";
1272
+ }
1273
+ const maximumClippingHeight = height - overflow.top - overflow.bottom;
1274
+ const maximumClippingWidth = width - overflow.left - overflow.right;
1275
+ const overflowAvailableHeight = min(height - overflow[heightSide], maximumClippingHeight);
1276
+ const overflowAvailableWidth = min(width - overflow[widthSide], maximumClippingWidth);
1277
+ const noShift = !state.middlewareData.shift;
1278
+ let availableHeight = overflowAvailableHeight;
1279
+ let availableWidth = overflowAvailableWidth;
1280
+ if ((_state$middlewareData = state.middlewareData.shift) != null && _state$middlewareData.enabled.x) {
1281
+ availableWidth = maximumClippingWidth;
1282
+ }
1283
+ if ((_state$middlewareData2 = state.middlewareData.shift) != null && _state$middlewareData2.enabled.y) {
1284
+ availableHeight = maximumClippingHeight;
1285
+ }
1286
+ if (noShift && !alignment) {
1287
+ const xMin = max(overflow.left, 0);
1288
+ const xMax = max(overflow.right, 0);
1289
+ const yMin = max(overflow.top, 0);
1290
+ const yMax = max(overflow.bottom, 0);
1291
+ if (isYAxis) {
1292
+ availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right));
1293
+ } else {
1294
+ availableHeight = height - 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max(overflow.top, overflow.bottom));
1295
+ }
1296
+ }
1297
+ await apply({
1298
+ ...state,
1299
+ availableWidth: availableWidth,
1300
+ availableHeight: availableHeight
1301
+ });
1302
+ const nextDimensions = await platform.getDimensions(elements.floating);
1303
+ if (width !== nextDimensions.width || height !== nextDimensions.height) {
1304
+ return {
1305
+ reset: {
1306
+ rects: true
1307
+ }
1308
+ };
1309
+ }
1310
+ return {};
1311
+ }
1312
+ };
1313
+ };
1314
+
1315
+ function hasWindow() {
1316
+ return typeof window !== "undefined";
1317
+ }
1318
+
1319
+ function getNodeName(node) {
1320
+ if (isNode(node)) {
1321
+ return (node.nodeName || "").toLowerCase();
1322
+ }
1323
+ return "#document";
1324
+ }
1325
+
1326
+ function getWindow(node) {
1327
+ var _node$ownerDocument;
1328
+ return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
1329
+ }
1330
+
1331
+ function getDocumentElement(node) {
1332
+ var _ref;
1333
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
1334
+ }
1335
+
1336
+ function isNode(value) {
1337
+ if (!hasWindow()) {
1338
+ return false;
1339
+ }
1340
+ return value instanceof Node || value instanceof getWindow(value).Node;
1341
+ }
1342
+
1343
+ function isElement(value) {
1344
+ if (!hasWindow()) {
1345
+ return false;
1346
+ }
1347
+ return value instanceof Element || value instanceof getWindow(value).Element;
1348
+ }
1349
+
1350
+ function isHTMLElement(value) {
1351
+ if (!hasWindow()) {
1352
+ return false;
1353
+ }
1354
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
1355
+ }
1356
+
1357
+ function isShadowRoot(value) {
1358
+ if (!hasWindow() || typeof ShadowRoot === "undefined") {
1359
+ return false;
1360
+ }
1361
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
1362
+ }
1363
+
1364
+ function isOverflowElement(element) {
1365
+ const {overflow: overflow, overflowX: overflowX, overflowY: overflowY, display: display} = getComputedStyle$1(element);
1366
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && ![ "inline", "contents" ].includes(display);
1367
+ }
1368
+
1369
+ function isTableElement(element) {
1370
+ return [ "table", "td", "th" ].includes(getNodeName(element));
1371
+ }
1372
+
1373
+ function isTopLayer(element) {
1374
+ return [ ":popover-open", ":modal" ].some((selector => {
1375
+ try {
1376
+ return element.matches(selector);
1377
+ } catch (e) {
1378
+ return false;
1379
+ }
1380
+ }));
1381
+ }
1382
+
1383
+ function isContainingBlock(elementOrCss) {
1384
+ const webkit = isWebKit();
1385
+ const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
1386
+ return css.transform !== "none" || css.perspective !== "none" || (css.containerType ? css.containerType !== "normal" : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== "none" : false) || !webkit && (css.filter ? css.filter !== "none" : false) || [ "transform", "perspective", "filter" ].some((value => (css.willChange || "").includes(value))) || [ "paint", "layout", "strict", "content" ].some((value => (css.contain || "").includes(value)));
1387
+ }
1388
+
1389
+ function getContainingBlock(element) {
1390
+ let currentNode = getParentNode(element);
1391
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
1392
+ if (isContainingBlock(currentNode)) {
1393
+ return currentNode;
1394
+ } else if (isTopLayer(currentNode)) {
1395
+ return null;
1396
+ }
1397
+ currentNode = getParentNode(currentNode);
1398
+ }
1399
+ return null;
1400
+ }
1401
+
1402
+ function isWebKit() {
1403
+ if (typeof CSS === "undefined" || !CSS.supports) return false;
1404
+ return CSS.supports("-webkit-backdrop-filter", "none");
1405
+ }
1406
+
1407
+ function isLastTraversableNode(node) {
1408
+ return [ "html", "body", "#document" ].includes(getNodeName(node));
1409
+ }
1410
+
1411
+ function getComputedStyle$1(element) {
1412
+ return getWindow(element).getComputedStyle(element);
1413
+ }
1414
+
1415
+ function getNodeScroll(element) {
1416
+ if (isElement(element)) {
1417
+ return {
1418
+ scrollLeft: element.scrollLeft,
1419
+ scrollTop: element.scrollTop
1420
+ };
1421
+ }
1422
+ return {
1423
+ scrollLeft: element.scrollX,
1424
+ scrollTop: element.scrollY
1425
+ };
1426
+ }
1427
+
1428
+ function getParentNode(node) {
1429
+ if (getNodeName(node) === "html") {
1430
+ return node;
1431
+ }
1432
+ const result = node.assignedSlot || node.parentNode || isShadowRoot(node) && node.host || getDocumentElement(node);
1433
+ return isShadowRoot(result) ? result.host : result;
1434
+ }
1435
+
1436
+ function getNearestOverflowAncestor(node) {
1437
+ const parentNode = getParentNode(node);
1438
+ if (isLastTraversableNode(parentNode)) {
1439
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
1440
+ }
1441
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
1442
+ return parentNode;
1443
+ }
1444
+ return getNearestOverflowAncestor(parentNode);
1445
+ }
1446
+
1447
+ function getOverflowAncestors(node, list, traverseIframes) {
1448
+ var _node$ownerDocument2;
1449
+ if (list === void 0) {
1450
+ list = [];
1451
+ }
1452
+ if (traverseIframes === void 0) {
1453
+ traverseIframes = true;
1454
+ }
1455
+ const scrollableAncestor = getNearestOverflowAncestor(node);
1456
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
1457
+ const win = getWindow(scrollableAncestor);
1458
+ if (isBody) {
1459
+ const frameElement = getFrameElement(win);
1460
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
1461
+ }
1462
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
1463
+ }
1464
+
1465
+ function getFrameElement(win) {
1466
+ return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
1467
+ }
1468
+
1469
+ function getCssDimensions(element) {
1470
+ const css = getComputedStyle$1(element);
1471
+ let width = parseFloat(css.width) || 0;
1472
+ let height = parseFloat(css.height) || 0;
1473
+ const hasOffset = isHTMLElement(element);
1474
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
1475
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
1476
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
1477
+ if (shouldFallback) {
1478
+ width = offsetWidth;
1479
+ height = offsetHeight;
1480
+ }
1481
+ return {
1482
+ width: width,
1483
+ height: height,
1484
+ $: shouldFallback
1485
+ };
1486
+ }
1487
+
1488
+ function unwrapElement(element) {
1489
+ return !isElement(element) ? element.contextElement : element;
1490
+ }
1491
+
1492
+ function getScale(element) {
1493
+ const domElement = unwrapElement(element);
1494
+ if (!isHTMLElement(domElement)) {
1495
+ return createCoords(1);
1496
+ }
1497
+ const rect = domElement.getBoundingClientRect();
1498
+ const {width: width, height: height, $: $} = getCssDimensions(domElement);
1499
+ let x = ($ ? round(rect.width) : rect.width) / width;
1500
+ let y = ($ ? round(rect.height) : rect.height) / height;
1501
+ if (!x || !Number.isFinite(x)) {
1502
+ x = 1;
1503
+ }
1504
+ if (!y || !Number.isFinite(y)) {
1505
+ y = 1;
1506
+ }
1507
+ return {
1508
+ x: x,
1509
+ y: y
1510
+ };
1511
+ }
1512
+
1513
+ const noOffsets = createCoords(0);
1514
+
1515
+ function getVisualOffsets(element) {
1516
+ const win = getWindow(element);
1517
+ if (!isWebKit() || !win.visualViewport) {
1518
+ return noOffsets;
1519
+ }
1520
+ return {
1521
+ x: win.visualViewport.offsetLeft,
1522
+ y: win.visualViewport.offsetTop
1523
+ };
1524
+ }
1525
+
1526
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
1527
+ if (isFixed === void 0) {
1528
+ isFixed = false;
1529
+ }
1530
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
1531
+ return false;
1532
+ }
1533
+ return isFixed;
1534
+ }
1535
+
1536
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
1537
+ if (includeScale === void 0) {
1538
+ includeScale = false;
1539
+ }
1540
+ if (isFixedStrategy === void 0) {
1541
+ isFixedStrategy = false;
1542
+ }
1543
+ const clientRect = element.getBoundingClientRect();
1544
+ const domElement = unwrapElement(element);
1545
+ let scale = createCoords(1);
1546
+ if (includeScale) {
1547
+ if (offsetParent) {
1548
+ if (isElement(offsetParent)) {
1549
+ scale = getScale(offsetParent);
1550
+ }
1551
+ } else {
1552
+ scale = getScale(element);
1553
+ }
1554
+ }
1555
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
1556
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
1557
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
1558
+ let width = clientRect.width / scale.x;
1559
+ let height = clientRect.height / scale.y;
1560
+ if (domElement) {
1561
+ const win = getWindow(domElement);
1562
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
1563
+ let currentWin = win;
1564
+ let currentIFrame = getFrameElement(currentWin);
1565
+ while (currentIFrame && offsetParent && offsetWin !== currentWin) {
1566
+ const iframeScale = getScale(currentIFrame);
1567
+ const iframeRect = currentIFrame.getBoundingClientRect();
1568
+ const css = getComputedStyle$1(currentIFrame);
1569
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
1570
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
1571
+ x *= iframeScale.x;
1572
+ y *= iframeScale.y;
1573
+ width *= iframeScale.x;
1574
+ height *= iframeScale.y;
1575
+ x += left;
1576
+ y += top;
1577
+ currentWin = getWindow(currentIFrame);
1578
+ currentIFrame = getFrameElement(currentWin);
1579
+ }
1580
+ }
1581
+ return rectToClientRect({
1582
+ width: width,
1583
+ height: height,
1584
+ x: x,
1585
+ y: y
1586
+ });
1587
+ }
1588
+
1589
+ function getWindowScrollBarX(element, rect) {
1590
+ const leftScroll = getNodeScroll(element).scrollLeft;
1591
+ if (!rect) {
1592
+ return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
1593
+ }
1594
+ return rect.left + leftScroll;
1595
+ }
1596
+
1597
+ function getHTMLOffset(documentElement, scroll, ignoreScrollbarX) {
1598
+ if (ignoreScrollbarX === void 0) {
1599
+ ignoreScrollbarX = false;
1600
+ }
1601
+ const htmlRect = documentElement.getBoundingClientRect();
1602
+ const x = htmlRect.left + scroll.scrollLeft - (ignoreScrollbarX ? 0 : getWindowScrollBarX(documentElement, htmlRect));
1603
+ const y = htmlRect.top + scroll.scrollTop;
1604
+ return {
1605
+ x: x,
1606
+ y: y
1607
+ };
1608
+ }
1609
+
1610
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
1611
+ let {elements: elements, rect: rect, offsetParent: offsetParent, strategy: strategy} = _ref;
1612
+ const isFixed = strategy === "fixed";
1613
+ const documentElement = getDocumentElement(offsetParent);
1614
+ const topLayer = elements ? isTopLayer(elements.floating) : false;
1615
+ if (offsetParent === documentElement || topLayer && isFixed) {
1616
+ return rect;
1617
+ }
1618
+ let scroll = {
1619
+ scrollLeft: 0,
1620
+ scrollTop: 0
1621
+ };
1622
+ let scale = createCoords(1);
1623
+ const offsets = createCoords(0);
1624
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
1625
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
1626
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
1627
+ scroll = getNodeScroll(offsetParent);
1628
+ }
1629
+ if (isHTMLElement(offsetParent)) {
1630
+ const offsetRect = getBoundingClientRect(offsetParent);
1631
+ scale = getScale(offsetParent);
1632
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
1633
+ offsets.y = offsetRect.y + offsetParent.clientTop;
1634
+ }
1635
+ }
1636
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll, true) : createCoords(0);
1637
+ return {
1638
+ width: rect.width * scale.x,
1639
+ height: rect.height * scale.y,
1640
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
1641
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
1642
+ };
1643
+ }
1644
+
1645
+ function getClientRects(element) {
1646
+ return Array.from(element.getClientRects());
1647
+ }
1648
+
1649
+ function getDocumentRect(element) {
1650
+ const html = getDocumentElement(element);
1651
+ const scroll = getNodeScroll(element);
1652
+ const body = element.ownerDocument.body;
1653
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
1654
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
1655
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
1656
+ const y = -scroll.scrollTop;
1657
+ if (getComputedStyle$1(body).direction === "rtl") {
1658
+ x += max(html.clientWidth, body.clientWidth) - width;
1659
+ }
1660
+ return {
1661
+ width: width,
1662
+ height: height,
1663
+ x: x,
1664
+ y: y
1665
+ };
1666
+ }
1667
+
1668
+ function getViewportRect(element, strategy) {
1669
+ const win = getWindow(element);
1670
+ const html = getDocumentElement(element);
1671
+ const visualViewport = win.visualViewport;
1672
+ let width = html.clientWidth;
1673
+ let height = html.clientHeight;
1674
+ let x = 0;
1675
+ let y = 0;
1676
+ if (visualViewport) {
1677
+ width = visualViewport.width;
1678
+ height = visualViewport.height;
1679
+ const visualViewportBased = isWebKit();
1680
+ if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
1681
+ x = visualViewport.offsetLeft;
1682
+ y = visualViewport.offsetTop;
1683
+ }
1684
+ }
1685
+ return {
1686
+ width: width,
1687
+ height: height,
1688
+ x: x,
1689
+ y: y
1690
+ };
1691
+ }
1692
+
1693
+ function getInnerBoundingClientRect(element, strategy) {
1694
+ const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
1695
+ const top = clientRect.top + element.clientTop;
1696
+ const left = clientRect.left + element.clientLeft;
1697
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
1698
+ const width = element.clientWidth * scale.x;
1699
+ const height = element.clientHeight * scale.y;
1700
+ const x = left * scale.x;
1701
+ const y = top * scale.y;
1702
+ return {
1703
+ width: width,
1704
+ height: height,
1705
+ x: x,
1706
+ y: y
1707
+ };
1708
+ }
1709
+
1710
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
1711
+ let rect;
1712
+ if (clippingAncestor === "viewport") {
1713
+ rect = getViewportRect(element, strategy);
1714
+ } else if (clippingAncestor === "document") {
1715
+ rect = getDocumentRect(getDocumentElement(element));
1716
+ } else if (isElement(clippingAncestor)) {
1717
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
1718
+ } else {
1719
+ const visualOffsets = getVisualOffsets(element);
1720
+ rect = {
1721
+ x: clippingAncestor.x - visualOffsets.x,
1722
+ y: clippingAncestor.y - visualOffsets.y,
1723
+ width: clippingAncestor.width,
1724
+ height: clippingAncestor.height
1725
+ };
1726
+ }
1727
+ return rectToClientRect(rect);
1728
+ }
1729
+
1730
+ function hasFixedPositionAncestor(element, stopNode) {
1731
+ const parentNode = getParentNode(element);
1732
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
1733
+ return false;
1734
+ }
1735
+ return getComputedStyle$1(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
1736
+ }
1737
+
1738
+ function getClippingElementAncestors(element, cache) {
1739
+ const cachedResult = cache.get(element);
1740
+ if (cachedResult) {
1741
+ return cachedResult;
1742
+ }
1743
+ let result = getOverflowAncestors(element, [], false).filter((el => isElement(el) && getNodeName(el) !== "body"));
1744
+ let currentContainingBlockComputedStyle = null;
1745
+ const elementIsFixed = getComputedStyle$1(element).position === "fixed";
1746
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
1747
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
1748
+ const computedStyle = getComputedStyle$1(currentNode);
1749
+ const currentNodeIsContaining = isContainingBlock(currentNode);
1750
+ if (!currentNodeIsContaining && computedStyle.position === "fixed") {
1751
+ currentContainingBlockComputedStyle = null;
1752
+ }
1753
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && [ "absolute", "fixed" ].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
1754
+ if (shouldDropCurrentNode) {
1755
+ result = result.filter((ancestor => ancestor !== currentNode));
1756
+ } else {
1757
+ currentContainingBlockComputedStyle = computedStyle;
1758
+ }
1759
+ currentNode = getParentNode(currentNode);
1760
+ }
1761
+ cache.set(element, result);
1762
+ return result;
1763
+ }
1764
+
1765
+ function getClippingRect(_ref) {
1766
+ let {element: element, boundary: boundary, rootBoundary: rootBoundary, strategy: strategy} = _ref;
1767
+ const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
1768
+ const clippingAncestors = [ ...elementClippingAncestors, rootBoundary ];
1769
+ const firstClippingAncestor = clippingAncestors[0];
1770
+ const clippingRect = clippingAncestors.reduce(((accRect, clippingAncestor) => {
1771
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
1772
+ accRect.top = max(rect.top, accRect.top);
1773
+ accRect.right = min(rect.right, accRect.right);
1774
+ accRect.bottom = min(rect.bottom, accRect.bottom);
1775
+ accRect.left = max(rect.left, accRect.left);
1776
+ return accRect;
1777
+ }), getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
1778
+ return {
1779
+ width: clippingRect.right - clippingRect.left,
1780
+ height: clippingRect.bottom - clippingRect.top,
1781
+ x: clippingRect.left,
1782
+ y: clippingRect.top
1783
+ };
1784
+ }
1785
+
1786
+ function getDimensions(element) {
1787
+ const {width: width, height: height} = getCssDimensions(element);
1788
+ return {
1789
+ width: width,
1790
+ height: height
1791
+ };
1792
+ }
1793
+
1794
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
1795
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
1796
+ const documentElement = getDocumentElement(offsetParent);
1797
+ const isFixed = strategy === "fixed";
1798
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
1799
+ let scroll = {
1800
+ scrollLeft: 0,
1801
+ scrollTop: 0
1802
+ };
1803
+ const offsets = createCoords(0);
1804
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
1805
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
1806
+ scroll = getNodeScroll(offsetParent);
1807
+ }
1808
+ if (isOffsetParentAnElement) {
1809
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
1810
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
1811
+ offsets.y = offsetRect.y + offsetParent.clientTop;
1812
+ } else if (documentElement) {
1813
+ offsets.x = getWindowScrollBarX(documentElement);
1814
+ }
1815
+ }
1816
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
1817
+ const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
1818
+ const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
1819
+ return {
1820
+ x: x,
1821
+ y: y,
1822
+ width: rect.width,
1823
+ height: rect.height
1824
+ };
1825
+ }
1826
+
1827
+ function isStaticPositioned(element) {
1828
+ return getComputedStyle$1(element).position === "static";
1829
+ }
1830
+
1831
+ function getTrueOffsetParent(element, polyfill) {
1832
+ if (!isHTMLElement(element) || getComputedStyle$1(element).position === "fixed") {
1833
+ return null;
1834
+ }
1835
+ if (polyfill) {
1836
+ return polyfill(element);
1837
+ }
1838
+ let rawOffsetParent = element.offsetParent;
1839
+ if (getDocumentElement(element) === rawOffsetParent) {
1840
+ rawOffsetParent = rawOffsetParent.ownerDocument.body;
1841
+ }
1842
+ return rawOffsetParent;
1843
+ }
1844
+
1845
+ function getOffsetParent(element, polyfill) {
1846
+ const win = getWindow(element);
1847
+ if (isTopLayer(element)) {
1848
+ return win;
1849
+ }
1850
+ if (!isHTMLElement(element)) {
1851
+ let svgOffsetParent = getParentNode(element);
1852
+ while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
1853
+ if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
1854
+ return svgOffsetParent;
1855
+ }
1856
+ svgOffsetParent = getParentNode(svgOffsetParent);
1857
+ }
1858
+ return win;
1859
+ }
1860
+ let offsetParent = getTrueOffsetParent(element, polyfill);
1861
+ while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
1862
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
1863
+ }
1864
+ if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
1865
+ return win;
1866
+ }
1867
+ return offsetParent || getContainingBlock(element) || win;
1868
+ }
1869
+
1870
+ const getElementRects = async function(data) {
1871
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
1872
+ const getDimensionsFn = this.getDimensions;
1873
+ const floatingDimensions = await getDimensionsFn(data.floating);
1874
+ return {
1875
+ reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
1876
+ floating: {
1877
+ x: 0,
1878
+ y: 0,
1879
+ width: floatingDimensions.width,
1880
+ height: floatingDimensions.height
1881
+ }
1882
+ };
1883
+ };
1884
+
1885
+ function isRTL(element) {
1886
+ return getComputedStyle$1(element).direction === "rtl";
1887
+ }
1888
+
1889
+ const platform = {
1890
+ convertOffsetParentRelativeRectToViewportRelativeRect: convertOffsetParentRelativeRectToViewportRelativeRect,
1891
+ getDocumentElement: getDocumentElement,
1892
+ getClippingRect: getClippingRect,
1893
+ getOffsetParent: getOffsetParent,
1894
+ getElementRects: getElementRects,
1895
+ getClientRects: getClientRects,
1896
+ getDimensions: getDimensions,
1897
+ getScale: getScale,
1898
+ isElement: isElement,
1899
+ isRTL: isRTL
1900
+ };
1901
+
1902
+ const detectOverflow = detectOverflow$1;
1903
+
1904
+ const offset = offset$1;
1905
+
1906
+ const autoPlacement = autoPlacement$1;
1907
+
1908
+ shift;
1909
+
1910
+ flip;
1911
+
1912
+ size;
1913
+
1914
+ hide;
1915
+
1916
+ const arrow = arrow$1;
1917
+
1918
+ inline;
1919
+
1920
+ limitShift;
1921
+
1922
+ const computePosition = (reference, floating, options) => {
1923
+ const cache = new Map;
1924
+ const mergedOptions = {
1925
+ platform: platform,
1926
+ ...options
1927
+ };
1928
+ const platformWithCache = {
1929
+ ...mergedOptions.platform,
1930
+ _c: cache
1931
+ };
1932
+ return computePosition$1(reference, floating, {
1933
+ ...mergedOptions,
1934
+ platform: platformWithCache
1935
+ });
1936
+ };
1937
+
1938
+ async function positionHovercard(controller, options) {
1939
+ let {placement: placements, offset: offsetValue} = options;
1940
+ const placement = placements[0];
1941
+ const arrowElement = controller.card.querySelector("[data-hovercard-arrow]");
1942
+ const middleware = [ AutoPositioningWithFallbacks(placements) ];
1943
+ if (arrowElement) {
1944
+ const arrowSize = arrowElement.clientWidth;
1945
+ offsetValue += arrowSize;
1946
+ middleware.push(arrow({
1947
+ element: arrowElement
1948
+ }));
1949
+ }
1950
+ middleware.push(offset(offsetValue));
1951
+ const computedPosition = await computePosition(controller.coupdoeilElement, controller.card, {
1952
+ placement: placement,
1953
+ middleware: middleware
1954
+ });
1955
+ const {x: x, y: y, placement: actualPlacement} = computedPosition;
1956
+ if (arrowElement) {
1957
+ positionArrow(arrowElement, computedPosition);
1958
+ }
1959
+ controller.card.dataset.placement = actualPlacement;
1960
+ Object.assign(controller.card.style, {
1961
+ left: `${x}px`,
1962
+ top: `${y}px`
1963
+ });
1964
+ }
1965
+
1966
+ const AutoPositioningWithFallbacks = placements => {
1967
+ let placementIndex = 0;
1968
+ return {
1969
+ name: "autoPlacement",
1970
+ async fn(state) {
1971
+ if (state.placement === "auto") {
1972
+ return autoPlacement().fn(state);
1973
+ }
1974
+ const {top: top, bottom: bottom, left: left, right: right} = await detectOverflow(state);
1975
+ const isOverflowing = top > 0 || bottom > 0 || left > 0 || right > 0;
1976
+ if (placements[placementIndex] !== "auto" && isOverflowing) {
1977
+ placementIndex++;
1978
+ return {
1979
+ reset: {
1980
+ placement: placements[placementIndex] || "auto"
1981
+ }
1982
+ };
1983
+ } else if (isOverflowing) {
1984
+ return autoPlacement().fn(state);
1985
+ }
1986
+ return {};
1987
+ }
1988
+ };
1989
+ };
1990
+
1991
+ const OPPOSITE_SIDES = {
1992
+ right: "left",
1993
+ left: "right",
1994
+ top: "bottom",
1995
+ bottom: "top"
1996
+ };
1997
+
1998
+ function positionArrow(arrowElement, computedData) {
1999
+ const arrowSize = arrowElement.clientWidth;
2000
+ const {placement: placement, middlewareData: {arrow: arrowData}} = computedData;
2001
+ const side = placement.split("-")[0];
2002
+ const oppositeSide = OPPOSITE_SIDES[side];
2003
+ const {x: x, y: y} = arrowData;
2004
+ const {borderWidth: parentBorderWidht} = getComputedStyle(arrowElement.parentElement);
2005
+ Object.assign(arrowElement.style, {
2006
+ left: x != null ? `${x}px` : "",
2007
+ top: y != null ? `${y}px` : "",
2008
+ [oppositeSide]: `calc(${-arrowSize}px + ${parentBorderWidht})`
2009
+ });
2010
+ }
2011
+
2012
+ function cancelOpening(controller) {
2013
+ clearTimeout(controller.openingDelay);
2014
+ controller.openingDelay = null;
2015
+ clearTimeout(controller.fetchDelay);
2016
+ controller.fetchDelay = null;
2017
+ delete controller.coupdoeilElement.openingHovercard;
2018
+ }
2019
+
2020
+ async function openHovercard(controller, {parent: parent}) {
2021
+ if (controller.isOpen) {
2022
+ cancelCloseRequest(controller);
2023
+ return addToCurrents(controller.coupdoeilElement);
2024
+ }
2025
+ if (parent) {
2026
+ controller.parent = parent;
2027
+ parent.children.add(controller);
2028
+ }
2029
+ const delayOptions = getDelayOptionsForController(controller);
2030
+ const options = extractOptionsFromElement(controller.coupdoeilElement);
2031
+ const {cache: cache} = options;
2032
+ controller.openingDelay = new Promise((resolve => {
2033
+ if (getHovercardContentHTML(controller) && cache) {
2034
+ setTimeout(resolve, delayOptions.reOpening);
2035
+ } else {
2036
+ setTimeout(resolve, delayOptions.actualOpening);
2037
+ }
2038
+ }));
2039
+ if (!getHovercardContentHTML(controller) || !cache) {
2040
+ controller.fetchDelay = new Promise((resolve => {
2041
+ setTimeout(resolve, delayOptions.fetch);
2042
+ }));
2043
+ await controller.fetchDelay;
2044
+ if (!controller.fetchDelay) {
2045
+ return;
2046
+ }
2047
+ controller.fetchDelay = null;
2048
+ const html = preloadedContentElement(controller)?.innerHTML || await fetchHovercardContent(controller);
2049
+ setHovercardContentHTML(controller, html);
2050
+ }
2051
+ await controller.openingDelay;
2052
+ const parentIsClosedOrClosing = controller.parent && (controller.parent.isClosed || controller.parent.closingRequest);
2053
+ if (controller.openingDelay && !parentIsClosedOrClosing) {
2054
+ controller.openingDelay = null;
2055
+ await display(controller, options);
2056
+ }
2057
+ }
2058
+
2059
+ async function display(controller, options) {
2060
+ if (controller.isOpen) return;
2061
+ cancelCloseRequest(controller);
2062
+ controller.card = buildHovercardElement(controller, options);
2063
+ document.body.appendChild(controller.card);
2064
+ if (options.animation) {
2065
+ controller.card.dataset.animation = options.animation;
2066
+ }
2067
+ requestAnimationFrame((async () => {
2068
+ controller.card.style.opacity = "0";
2069
+ controller.card.classList.remove("hidden");
2070
+ requestAnimationFrame((async () => {
2071
+ await positionHovercard(controller, options);
2072
+ controller.card.classList.add("hidden");
2073
+ controller.card.style.removeProperty("opacity");
2074
+ requestAnimationFrame((async () => {
2075
+ addToCurrents(controller.coupdoeilElement);
2076
+ delete controller.coupdoeilElement.openingHovercard;
2077
+ controller.coupdoeilElement.dataset.hovercardOpen = true;
2078
+ await enter(controller.card, "hovercard");
2079
+ }));
2080
+ }));
2081
+ }));
2082
+ }
2083
+
2084
+ function getDelayOptionsForController(controller) {
2085
+ if (triggeredOnClick(controller)) {
2086
+ return {
2087
+ reOpening: 0,
2088
+ actualOpening: 0,
2089
+ fetch: 0
2090
+ };
2091
+ }
2092
+ return {
2093
+ fetch: defaultConfig.fetchDelay,
2094
+ reOpening: defaultConfig.fetchDelay + defaultConfig.openingDelay,
2095
+ actualOpening: defaultConfig.openingDelay - defaultConfig.fetchDelay
2096
+ };
2097
+ }
2098
+
2099
+ function fetchHovercardContent(controller) {
2100
+ const type = getType(controller);
2101
+ const params = getParams(controller);
2102
+ const authenticityToken = document.querySelector("meta[name=csrf-token]").content;
2103
+ let url = `/coupdoeil/hovercard`;
2104
+ const opts = {
2105
+ method: "POST",
2106
+ headers: {
2107
+ "Content-Type": "application/json"
2108
+ },
2109
+ body: JSON.stringify({
2110
+ params: params,
2111
+ action_name: type,
2112
+ authenticity_token: authenticityToken
2113
+ })
2114
+ };
2115
+ return fetch(url, opts).then((response => {
2116
+ if (response.status >= 400) {
2117
+ throw "error while fetching hovercard content";
2118
+ }
2119
+ return response.text();
2120
+ }));
2121
+ }
2122
+
2123
+ function buildHovercardElement(controller, options) {
2124
+ const el = document.createElement("div");
2125
+ el.setAttribute("role", "dialog");
2126
+ el.classList.add(HOVERCARD_CLASS_NAME, "hidden");
2127
+ el.style.cssText = "position: absolute; left: 0; top: 0;";
2128
+ el.innerHTML = getHovercardContentHTML(controller);
2129
+ el.controller = controller;
2130
+ el.dataset.placement = options.placement;
2131
+ return el;
2132
+ }
2133
+
2134
+ function generateUniqueId() {
2135
+ const array = new Uint32Array(1);
2136
+ window.crypto.getRandomValues(array);
2137
+ return array[0];
2138
+ }
2139
+
2140
+ class CoupdoeilElement extends HTMLElement {
2141
+ constructor() {
2142
+ super();
2143
+ this.uniqueId = generateUniqueId();
2144
+ this.hovercardController = new HovercardController(this);
2145
+ }
2146
+ openHovercard() {
2147
+ if (this.openingHovercard || this.hovercardController.isOpen) return;
2148
+ this.openingHovercard = true;
2149
+ const parent = this.closest(HOVERCARD_SELECTOR)?.controller;
2150
+ addToCurrents(this);
2151
+ return openHovercard(this.hovercardController, {
2152
+ parent: parent
2153
+ });
2154
+ }
2155
+ closeHovercard() {
2156
+ closeNow(this.hovercardController);
2157
+ }
2158
+ }
2159
+
2160
+ function isElementCloseHovercardButton(element) {
2161
+ return element.closest(HOVERCARD_CLOSE_BTN_SELECTOR) || element.dataset.hasOwnProperty("hovercardClose");
2162
+ }
2163
+
2164
+ function isAnyHovercardOpened() {
2165
+ return currentHovercardsById().size > 0;
2166
+ }
2167
+
2168
+ const coupdoeilOnClickEvent = ({target: clickedElement}) => {
2169
+ const coupdoeilElement = clickedElement.closest("coup-doeil");
2170
+ const hovercardElement = clickedElement.closest(HOVERCARD_SELECTOR);
2171
+ if (coupdoeilElement && hovercardElement) {
2172
+ handleClickedCoupdoeilWithinHovercard(coupdoeilElement);
2173
+ } else if (coupdoeilElement) {
2174
+ handleClickedCoupdoeilOutsideHovercard(coupdoeilElement);
2175
+ } else if (hovercardElement) {
2176
+ handleClickOutsideCoupdoeilButWithinHovercard(hovercardElement, clickedElement);
2177
+ } else {
2178
+ handleClickOutsideCoupdoeilAndHovercard();
2179
+ }
2180
+ };
2181
+
2182
+ function handleClickedCoupdoeilWithinHovercard(coupdoeilElement, _hovercardElement) {
2183
+ const hovercard = coupdoeilElement.hovercardController;
2184
+ if (noTriggeredOnClick(hovercard)) return;
2185
+ if (hovercard.isOpen) {
2186
+ closeNow(hovercard);
2187
+ } else {
2188
+ coupdoeilElement.openHovercard();
2189
+ }
2190
+ }
2191
+
2192
+ function handleClickedCoupdoeilOutsideHovercard(coupdoeilElement) {
2193
+ const hovercard = coupdoeilElement.hovercardController;
2194
+ if (noTriggeredOnClick(hovercard)) return;
2195
+ if (hovercard.isOpen) {
2196
+ closeNow(hovercard);
2197
+ } else {
2198
+ closeAllNow();
2199
+ coupdoeilElement.openHovercard();
2200
+ }
2201
+ }
2202
+
2203
+ function handleClickOutsideCoupdoeilButWithinHovercard(hovercardElement, clickedElement) {
2204
+ const hovercard = hovercardElement.controller;
2205
+ if (isElementCloseHovercardButton(clickedElement)) {
2206
+ closeNow(hovercard);
2207
+ } else if (hovercard.children.size > 0) {
2208
+ closeChildrenNow(hovercard);
2209
+ }
2210
+ }
2211
+
2212
+ function handleClickOutsideCoupdoeilAndHovercard() {
2213
+ closeAllNow();
2214
+ }
2215
+
2216
+ const onMouseOver = ({target: hoveredElement}) => {
2217
+ const coupdoeilElement = hoveredElement.closest("coup-doeil");
2218
+ const hovercardElement = hoveredElement.closest(HOVERCARD_SELECTOR);
2219
+ if (coupdoeilElement && hovercardElement) {
2220
+ handleMouseOverCoupdoeilWithinHovercard(coupdoeilElement, hovercardElement);
2221
+ } else if (coupdoeilElement) {
2222
+ handleMouseOverCoupdoeilOutsideHovercard(coupdoeilElement);
2223
+ } else if (hovercardElement) {
2224
+ handleOverOutsideCoupdoeilButWithinHovercard(hovercardElement);
2225
+ } else {
2226
+ handleOverOutsideCoupdoeilAndHovercard();
2227
+ }
2228
+ };
2229
+
2230
+ function handleMouseOverCoupdoeilWithinHovercard(coupdoeilElement, hovercardElement) {
2231
+ const childHovercard = coupdoeilElement.hovercardController;
2232
+ const parentHovercard = hovercardElement.controller;
2233
+ if (notTriggeredOnHover(childHovercard)) return;
2234
+ if (childHovercard.isOpen) {
2235
+ closeChildrenNow(childHovercard);
2236
+ } else {
2237
+ closeChildrenNow(parentHovercard);
2238
+ coupdoeilElement.openHovercard();
2239
+ }
2240
+ }
2241
+
2242
+ function handleMouseOverCoupdoeilOutsideHovercard(coupdoeilElement) {
2243
+ const hovercard = coupdoeilElement.hovercardController;
2244
+ if (notTriggeredOnHover(hovercard)) return;
2245
+ if (hovercard.isClosed) {
2246
+ closeTriggeredOnHoverNow();
2247
+ coupdoeilElement.openHovercard();
2248
+ } else if (hovercard.closingRequest) {
2249
+ cancelCloseRequest(hovercard);
2250
+ addToCurrents(coupdoeilElement);
2251
+ }
2252
+ }
2253
+
2254
+ function handleOverOutsideCoupdoeilAndHovercard() {
2255
+ if (isAnyHovercardOpened()) {
2256
+ closeTriggeredOnHoverLater();
2257
+ }
2258
+ }
2259
+
2260
+ function handleOverOutsideCoupdoeilButWithinHovercard(hovercardElement) {
2261
+ const hovercard = hovercardElement.controller;
2262
+ if (hovercard.closingRequest) {
2263
+ cancelCloseRequest(hovercard);
2264
+ addToCurrents(hovercard.coupdoeilElement);
2265
+ } else if (hovercard.children.size > 0) {
2266
+ closeOnHoverChildrenLater(hovercard);
2267
+ }
2268
+ }
2269
+
2270
+ document.addEventListener("DOMContentLoaded", (() => {
2271
+ clearHovercardContentCache();
2272
+ document.addEventListener("click", coupdoeilOnClickEvent);
2273
+ document.documentElement.addEventListener("mouseover", onMouseOver, {
2274
+ passive: true
2275
+ });
2276
+ if (window.Turbo) {
2277
+ document.addEventListener("turbo:before-cache", (_event => {
2278
+ clearAll();
2279
+ }));
2280
+ document.addEventListener("turbo:load", (_event => {
2281
+ clearAll();
2282
+ clearHovercardContentCache();
2283
+ }));
2284
+ }
2285
+ }));
2286
+
2287
+ if (customElements.get("coup-doeil") === undefined) {
2288
+ customElements.define("coup-doeil", CoupdoeilElement);
2289
+ }