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