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