overtype 1.0.5 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +26 -0
- package/dist/overtype.esm.js +1428 -3
- package/dist/overtype.esm.js.map +4 -4
- package/dist/overtype.js +1428 -3
- package/dist/overtype.js.map +4 -4
- package/dist/overtype.min.js +83 -51
- package/package.json +2 -1
- package/src/link-tooltip.js +269 -0
- package/src/overtype.js +51 -2
- package/src/parser.js +19 -0
- package/src/styles.js +3 -1
package/dist/overtype.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OverType v1.0
|
|
2
|
+
* OverType v1.1.0
|
|
3
3
|
* A lightweight markdown editor library with perfect WYSIWYG alignment
|
|
4
4
|
* @license MIT
|
|
5
5
|
* @author Demo User
|
|
@@ -149,9 +149,18 @@ var MarkdownParser = class {
|
|
|
149
149
|
static parseInlineElements(text) {
|
|
150
150
|
let html = text;
|
|
151
151
|
html = this.parseInlineCode(html);
|
|
152
|
+
const codeBlocks = /* @__PURE__ */ new Map();
|
|
153
|
+
html = html.replace(/(<code>.*?<\/code>)/g, (match) => {
|
|
154
|
+
const placeholder = `\uE000${codeBlocks.size}\uE001`;
|
|
155
|
+
codeBlocks.set(placeholder, match);
|
|
156
|
+
return placeholder;
|
|
157
|
+
});
|
|
152
158
|
html = this.parseLinks(html);
|
|
153
159
|
html = this.parseBold(html);
|
|
154
160
|
html = this.parseItalic(html);
|
|
161
|
+
codeBlocks.forEach((codeBlock, placeholder) => {
|
|
162
|
+
html = html.replace(placeholder, codeBlock);
|
|
163
|
+
});
|
|
155
164
|
return html;
|
|
156
165
|
}
|
|
157
166
|
/**
|
|
@@ -1273,7 +1282,7 @@ function generateStyles(options = {}) {
|
|
|
1273
1282
|
const {
|
|
1274
1283
|
fontSize = "14px",
|
|
1275
1284
|
lineHeight = 1.6,
|
|
1276
|
-
fontFamily = "
|
|
1285
|
+
fontFamily = "ui-monospace, 'SFMono-Regular', 'Menlo', 'Consolas', 'Liberation Mono', monospace",
|
|
1277
1286
|
padding = "20px",
|
|
1278
1287
|
theme = null,
|
|
1279
1288
|
mobile = {}
|
|
@@ -1487,6 +1496,8 @@ function generateStyles(options = {}) {
|
|
|
1487
1496
|
padding: 0 !important;
|
|
1488
1497
|
border-radius: 2px !important;
|
|
1489
1498
|
font-family: inherit !important;
|
|
1499
|
+
font-size: inherit !important;
|
|
1500
|
+
line-height: inherit !important;
|
|
1490
1501
|
font-weight: normal !important;
|
|
1491
1502
|
}
|
|
1492
1503
|
|
|
@@ -1962,6 +1973,1389 @@ var Toolbar = class {
|
|
|
1962
1973
|
}
|
|
1963
1974
|
};
|
|
1964
1975
|
|
|
1976
|
+
// node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs
|
|
1977
|
+
var min = Math.min;
|
|
1978
|
+
var max = Math.max;
|
|
1979
|
+
var round = Math.round;
|
|
1980
|
+
var createCoords = (v) => ({
|
|
1981
|
+
x: v,
|
|
1982
|
+
y: v
|
|
1983
|
+
});
|
|
1984
|
+
var oppositeSideMap = {
|
|
1985
|
+
left: "right",
|
|
1986
|
+
right: "left",
|
|
1987
|
+
bottom: "top",
|
|
1988
|
+
top: "bottom"
|
|
1989
|
+
};
|
|
1990
|
+
var oppositeAlignmentMap = {
|
|
1991
|
+
start: "end",
|
|
1992
|
+
end: "start"
|
|
1993
|
+
};
|
|
1994
|
+
function clamp(start, value, end) {
|
|
1995
|
+
return max(start, min(value, end));
|
|
1996
|
+
}
|
|
1997
|
+
function evaluate(value, param) {
|
|
1998
|
+
return typeof value === "function" ? value(param) : value;
|
|
1999
|
+
}
|
|
2000
|
+
function getSide(placement) {
|
|
2001
|
+
return placement.split("-")[0];
|
|
2002
|
+
}
|
|
2003
|
+
function getAlignment(placement) {
|
|
2004
|
+
return placement.split("-")[1];
|
|
2005
|
+
}
|
|
2006
|
+
function getOppositeAxis(axis) {
|
|
2007
|
+
return axis === "x" ? "y" : "x";
|
|
2008
|
+
}
|
|
2009
|
+
function getAxisLength(axis) {
|
|
2010
|
+
return axis === "y" ? "height" : "width";
|
|
2011
|
+
}
|
|
2012
|
+
var yAxisSides = /* @__PURE__ */ new Set(["top", "bottom"]);
|
|
2013
|
+
function getSideAxis(placement) {
|
|
2014
|
+
return yAxisSides.has(getSide(placement)) ? "y" : "x";
|
|
2015
|
+
}
|
|
2016
|
+
function getAlignmentAxis(placement) {
|
|
2017
|
+
return getOppositeAxis(getSideAxis(placement));
|
|
2018
|
+
}
|
|
2019
|
+
function getAlignmentSides(placement, rects, rtl) {
|
|
2020
|
+
if (rtl === void 0) {
|
|
2021
|
+
rtl = false;
|
|
2022
|
+
}
|
|
2023
|
+
const alignment = getAlignment(placement);
|
|
2024
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
2025
|
+
const length = getAxisLength(alignmentAxis);
|
|
2026
|
+
let mainAlignmentSide = alignmentAxis === "x" ? alignment === (rtl ? "end" : "start") ? "right" : "left" : alignment === "start" ? "bottom" : "top";
|
|
2027
|
+
if (rects.reference[length] > rects.floating[length]) {
|
|
2028
|
+
mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
|
|
2029
|
+
}
|
|
2030
|
+
return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
|
|
2031
|
+
}
|
|
2032
|
+
function getExpandedPlacements(placement) {
|
|
2033
|
+
const oppositePlacement = getOppositePlacement(placement);
|
|
2034
|
+
return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
|
|
2035
|
+
}
|
|
2036
|
+
function getOppositeAlignmentPlacement(placement) {
|
|
2037
|
+
return placement.replace(/start|end/g, (alignment) => oppositeAlignmentMap[alignment]);
|
|
2038
|
+
}
|
|
2039
|
+
var lrPlacement = ["left", "right"];
|
|
2040
|
+
var rlPlacement = ["right", "left"];
|
|
2041
|
+
var tbPlacement = ["top", "bottom"];
|
|
2042
|
+
var btPlacement = ["bottom", "top"];
|
|
2043
|
+
function getSideList(side, isStart, rtl) {
|
|
2044
|
+
switch (side) {
|
|
2045
|
+
case "top":
|
|
2046
|
+
case "bottom":
|
|
2047
|
+
if (rtl)
|
|
2048
|
+
return isStart ? rlPlacement : lrPlacement;
|
|
2049
|
+
return isStart ? lrPlacement : rlPlacement;
|
|
2050
|
+
case "left":
|
|
2051
|
+
case "right":
|
|
2052
|
+
return isStart ? tbPlacement : btPlacement;
|
|
2053
|
+
default:
|
|
2054
|
+
return [];
|
|
2055
|
+
}
|
|
2056
|
+
}
|
|
2057
|
+
function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
|
|
2058
|
+
const alignment = getAlignment(placement);
|
|
2059
|
+
let list = getSideList(getSide(placement), direction === "start", rtl);
|
|
2060
|
+
if (alignment) {
|
|
2061
|
+
list = list.map((side) => side + "-" + alignment);
|
|
2062
|
+
if (flipAlignment) {
|
|
2063
|
+
list = list.concat(list.map(getOppositeAlignmentPlacement));
|
|
2064
|
+
}
|
|
2065
|
+
}
|
|
2066
|
+
return list;
|
|
2067
|
+
}
|
|
2068
|
+
function getOppositePlacement(placement) {
|
|
2069
|
+
return placement.replace(/left|right|bottom|top/g, (side) => oppositeSideMap[side]);
|
|
2070
|
+
}
|
|
2071
|
+
function expandPaddingObject(padding) {
|
|
2072
|
+
return {
|
|
2073
|
+
top: 0,
|
|
2074
|
+
right: 0,
|
|
2075
|
+
bottom: 0,
|
|
2076
|
+
left: 0,
|
|
2077
|
+
...padding
|
|
2078
|
+
};
|
|
2079
|
+
}
|
|
2080
|
+
function getPaddingObject(padding) {
|
|
2081
|
+
return typeof padding !== "number" ? expandPaddingObject(padding) : {
|
|
2082
|
+
top: padding,
|
|
2083
|
+
right: padding,
|
|
2084
|
+
bottom: padding,
|
|
2085
|
+
left: padding
|
|
2086
|
+
};
|
|
2087
|
+
}
|
|
2088
|
+
function rectToClientRect(rect) {
|
|
2089
|
+
const {
|
|
2090
|
+
x,
|
|
2091
|
+
y,
|
|
2092
|
+
width,
|
|
2093
|
+
height
|
|
2094
|
+
} = rect;
|
|
2095
|
+
return {
|
|
2096
|
+
width,
|
|
2097
|
+
height,
|
|
2098
|
+
top: y,
|
|
2099
|
+
left: x,
|
|
2100
|
+
right: x + width,
|
|
2101
|
+
bottom: y + height,
|
|
2102
|
+
x,
|
|
2103
|
+
y
|
|
2104
|
+
};
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
// node_modules/@floating-ui/core/dist/floating-ui.core.mjs
|
|
2108
|
+
function computeCoordsFromPlacement(_ref, placement, rtl) {
|
|
2109
|
+
let {
|
|
2110
|
+
reference,
|
|
2111
|
+
floating
|
|
2112
|
+
} = _ref;
|
|
2113
|
+
const sideAxis = getSideAxis(placement);
|
|
2114
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
2115
|
+
const alignLength = getAxisLength(alignmentAxis);
|
|
2116
|
+
const side = getSide(placement);
|
|
2117
|
+
const isVertical = sideAxis === "y";
|
|
2118
|
+
const commonX = reference.x + reference.width / 2 - floating.width / 2;
|
|
2119
|
+
const commonY = reference.y + reference.height / 2 - floating.height / 2;
|
|
2120
|
+
const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
|
|
2121
|
+
let coords;
|
|
2122
|
+
switch (side) {
|
|
2123
|
+
case "top":
|
|
2124
|
+
coords = {
|
|
2125
|
+
x: commonX,
|
|
2126
|
+
y: reference.y - floating.height
|
|
2127
|
+
};
|
|
2128
|
+
break;
|
|
2129
|
+
case "bottom":
|
|
2130
|
+
coords = {
|
|
2131
|
+
x: commonX,
|
|
2132
|
+
y: reference.y + reference.height
|
|
2133
|
+
};
|
|
2134
|
+
break;
|
|
2135
|
+
case "right":
|
|
2136
|
+
coords = {
|
|
2137
|
+
x: reference.x + reference.width,
|
|
2138
|
+
y: commonY
|
|
2139
|
+
};
|
|
2140
|
+
break;
|
|
2141
|
+
case "left":
|
|
2142
|
+
coords = {
|
|
2143
|
+
x: reference.x - floating.width,
|
|
2144
|
+
y: commonY
|
|
2145
|
+
};
|
|
2146
|
+
break;
|
|
2147
|
+
default:
|
|
2148
|
+
coords = {
|
|
2149
|
+
x: reference.x,
|
|
2150
|
+
y: reference.y
|
|
2151
|
+
};
|
|
2152
|
+
}
|
|
2153
|
+
switch (getAlignment(placement)) {
|
|
2154
|
+
case "start":
|
|
2155
|
+
coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
|
|
2156
|
+
break;
|
|
2157
|
+
case "end":
|
|
2158
|
+
coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
|
|
2159
|
+
break;
|
|
2160
|
+
}
|
|
2161
|
+
return coords;
|
|
2162
|
+
}
|
|
2163
|
+
var computePosition = async (reference, floating, config) => {
|
|
2164
|
+
const {
|
|
2165
|
+
placement = "bottom",
|
|
2166
|
+
strategy = "absolute",
|
|
2167
|
+
middleware = [],
|
|
2168
|
+
platform: platform2
|
|
2169
|
+
} = config;
|
|
2170
|
+
const validMiddleware = middleware.filter(Boolean);
|
|
2171
|
+
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(floating));
|
|
2172
|
+
let rects = await platform2.getElementRects({
|
|
2173
|
+
reference,
|
|
2174
|
+
floating,
|
|
2175
|
+
strategy
|
|
2176
|
+
});
|
|
2177
|
+
let {
|
|
2178
|
+
x,
|
|
2179
|
+
y
|
|
2180
|
+
} = computeCoordsFromPlacement(rects, placement, rtl);
|
|
2181
|
+
let statefulPlacement = placement;
|
|
2182
|
+
let middlewareData = {};
|
|
2183
|
+
let resetCount = 0;
|
|
2184
|
+
for (let i = 0; i < validMiddleware.length; i++) {
|
|
2185
|
+
const {
|
|
2186
|
+
name,
|
|
2187
|
+
fn
|
|
2188
|
+
} = validMiddleware[i];
|
|
2189
|
+
const {
|
|
2190
|
+
x: nextX,
|
|
2191
|
+
y: nextY,
|
|
2192
|
+
data,
|
|
2193
|
+
reset
|
|
2194
|
+
} = await fn({
|
|
2195
|
+
x,
|
|
2196
|
+
y,
|
|
2197
|
+
initialPlacement: placement,
|
|
2198
|
+
placement: statefulPlacement,
|
|
2199
|
+
strategy,
|
|
2200
|
+
middlewareData,
|
|
2201
|
+
rects,
|
|
2202
|
+
platform: platform2,
|
|
2203
|
+
elements: {
|
|
2204
|
+
reference,
|
|
2205
|
+
floating
|
|
2206
|
+
}
|
|
2207
|
+
});
|
|
2208
|
+
x = nextX != null ? nextX : x;
|
|
2209
|
+
y = nextY != null ? nextY : y;
|
|
2210
|
+
middlewareData = {
|
|
2211
|
+
...middlewareData,
|
|
2212
|
+
[name]: {
|
|
2213
|
+
...middlewareData[name],
|
|
2214
|
+
...data
|
|
2215
|
+
}
|
|
2216
|
+
};
|
|
2217
|
+
if (reset && resetCount <= 50) {
|
|
2218
|
+
resetCount++;
|
|
2219
|
+
if (typeof reset === "object") {
|
|
2220
|
+
if (reset.placement) {
|
|
2221
|
+
statefulPlacement = reset.placement;
|
|
2222
|
+
}
|
|
2223
|
+
if (reset.rects) {
|
|
2224
|
+
rects = reset.rects === true ? await platform2.getElementRects({
|
|
2225
|
+
reference,
|
|
2226
|
+
floating,
|
|
2227
|
+
strategy
|
|
2228
|
+
}) : reset.rects;
|
|
2229
|
+
}
|
|
2230
|
+
({
|
|
2231
|
+
x,
|
|
2232
|
+
y
|
|
2233
|
+
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
|
|
2234
|
+
}
|
|
2235
|
+
i = -1;
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
return {
|
|
2239
|
+
x,
|
|
2240
|
+
y,
|
|
2241
|
+
placement: statefulPlacement,
|
|
2242
|
+
strategy,
|
|
2243
|
+
middlewareData
|
|
2244
|
+
};
|
|
2245
|
+
};
|
|
2246
|
+
async function detectOverflow(state, options) {
|
|
2247
|
+
var _await$platform$isEle;
|
|
2248
|
+
if (options === void 0) {
|
|
2249
|
+
options = {};
|
|
2250
|
+
}
|
|
2251
|
+
const {
|
|
2252
|
+
x,
|
|
2253
|
+
y,
|
|
2254
|
+
platform: platform2,
|
|
2255
|
+
rects,
|
|
2256
|
+
elements,
|
|
2257
|
+
strategy
|
|
2258
|
+
} = state;
|
|
2259
|
+
const {
|
|
2260
|
+
boundary = "clippingAncestors",
|
|
2261
|
+
rootBoundary = "viewport",
|
|
2262
|
+
elementContext = "floating",
|
|
2263
|
+
altBoundary = false,
|
|
2264
|
+
padding = 0
|
|
2265
|
+
} = evaluate(options, state);
|
|
2266
|
+
const paddingObject = getPaddingObject(padding);
|
|
2267
|
+
const altContext = elementContext === "floating" ? "reference" : "floating";
|
|
2268
|
+
const element = elements[altBoundary ? altContext : elementContext];
|
|
2269
|
+
const clippingClientRect = rectToClientRect(await platform2.getClippingRect({
|
|
2270
|
+
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)),
|
|
2271
|
+
boundary,
|
|
2272
|
+
rootBoundary,
|
|
2273
|
+
strategy
|
|
2274
|
+
}));
|
|
2275
|
+
const rect = elementContext === "floating" ? {
|
|
2276
|
+
x,
|
|
2277
|
+
y,
|
|
2278
|
+
width: rects.floating.width,
|
|
2279
|
+
height: rects.floating.height
|
|
2280
|
+
} : rects.reference;
|
|
2281
|
+
const offsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(elements.floating));
|
|
2282
|
+
const offsetScale = await (platform2.isElement == null ? void 0 : platform2.isElement(offsetParent)) ? await (platform2.getScale == null ? void 0 : platform2.getScale(offsetParent)) || {
|
|
2283
|
+
x: 1,
|
|
2284
|
+
y: 1
|
|
2285
|
+
} : {
|
|
2286
|
+
x: 1,
|
|
2287
|
+
y: 1
|
|
2288
|
+
};
|
|
2289
|
+
const elementClientRect = rectToClientRect(platform2.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform2.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
2290
|
+
elements,
|
|
2291
|
+
rect,
|
|
2292
|
+
offsetParent,
|
|
2293
|
+
strategy
|
|
2294
|
+
}) : rect);
|
|
2295
|
+
return {
|
|
2296
|
+
top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
|
|
2297
|
+
bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
|
|
2298
|
+
left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
|
|
2299
|
+
right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
|
|
2300
|
+
};
|
|
2301
|
+
}
|
|
2302
|
+
var flip = function(options) {
|
|
2303
|
+
if (options === void 0) {
|
|
2304
|
+
options = {};
|
|
2305
|
+
}
|
|
2306
|
+
return {
|
|
2307
|
+
name: "flip",
|
|
2308
|
+
options,
|
|
2309
|
+
async fn(state) {
|
|
2310
|
+
var _middlewareData$arrow, _middlewareData$flip;
|
|
2311
|
+
const {
|
|
2312
|
+
placement,
|
|
2313
|
+
middlewareData,
|
|
2314
|
+
rects,
|
|
2315
|
+
initialPlacement,
|
|
2316
|
+
platform: platform2,
|
|
2317
|
+
elements
|
|
2318
|
+
} = state;
|
|
2319
|
+
const {
|
|
2320
|
+
mainAxis: checkMainAxis = true,
|
|
2321
|
+
crossAxis: checkCrossAxis = true,
|
|
2322
|
+
fallbackPlacements: specifiedFallbackPlacements,
|
|
2323
|
+
fallbackStrategy = "bestFit",
|
|
2324
|
+
fallbackAxisSideDirection = "none",
|
|
2325
|
+
flipAlignment = true,
|
|
2326
|
+
...detectOverflowOptions
|
|
2327
|
+
} = evaluate(options, state);
|
|
2328
|
+
if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
2329
|
+
return {};
|
|
2330
|
+
}
|
|
2331
|
+
const side = getSide(placement);
|
|
2332
|
+
const initialSideAxis = getSideAxis(initialPlacement);
|
|
2333
|
+
const isBasePlacement = getSide(initialPlacement) === initialPlacement;
|
|
2334
|
+
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
|
|
2335
|
+
const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
|
|
2336
|
+
const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== "none";
|
|
2337
|
+
if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
|
|
2338
|
+
fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
|
|
2339
|
+
}
|
|
2340
|
+
const placements2 = [initialPlacement, ...fallbackPlacements];
|
|
2341
|
+
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
2342
|
+
const overflows = [];
|
|
2343
|
+
let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
|
|
2344
|
+
if (checkMainAxis) {
|
|
2345
|
+
overflows.push(overflow[side]);
|
|
2346
|
+
}
|
|
2347
|
+
if (checkCrossAxis) {
|
|
2348
|
+
const sides2 = getAlignmentSides(placement, rects, rtl);
|
|
2349
|
+
overflows.push(overflow[sides2[0]], overflow[sides2[1]]);
|
|
2350
|
+
}
|
|
2351
|
+
overflowsData = [...overflowsData, {
|
|
2352
|
+
placement,
|
|
2353
|
+
overflows
|
|
2354
|
+
}];
|
|
2355
|
+
if (!overflows.every((side2) => side2 <= 0)) {
|
|
2356
|
+
var _middlewareData$flip2, _overflowsData$filter;
|
|
2357
|
+
const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
|
|
2358
|
+
const nextPlacement = placements2[nextIndex];
|
|
2359
|
+
if (nextPlacement) {
|
|
2360
|
+
const ignoreCrossAxisOverflow = checkCrossAxis === "alignment" ? initialSideAxis !== getSideAxis(nextPlacement) : false;
|
|
2361
|
+
if (!ignoreCrossAxisOverflow || // We leave the current main axis only if every placement on that axis
|
|
2362
|
+
// overflows the main axis.
|
|
2363
|
+
overflowsData.every((d) => getSideAxis(d.placement) === initialSideAxis ? d.overflows[0] > 0 : true)) {
|
|
2364
|
+
return {
|
|
2365
|
+
data: {
|
|
2366
|
+
index: nextIndex,
|
|
2367
|
+
overflows: overflowsData
|
|
2368
|
+
},
|
|
2369
|
+
reset: {
|
|
2370
|
+
placement: nextPlacement
|
|
2371
|
+
}
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
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;
|
|
2376
|
+
if (!resetPlacement) {
|
|
2377
|
+
switch (fallbackStrategy) {
|
|
2378
|
+
case "bestFit": {
|
|
2379
|
+
var _overflowsData$filter2;
|
|
2380
|
+
const placement2 = (_overflowsData$filter2 = overflowsData.filter((d) => {
|
|
2381
|
+
if (hasFallbackAxisSideDirection) {
|
|
2382
|
+
const currentSideAxis = getSideAxis(d.placement);
|
|
2383
|
+
return currentSideAxis === initialSideAxis || // Create a bias to the `y` side axis due to horizontal
|
|
2384
|
+
// reading directions favoring greater width.
|
|
2385
|
+
currentSideAxis === "y";
|
|
2386
|
+
}
|
|
2387
|
+
return true;
|
|
2388
|
+
}).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];
|
|
2389
|
+
if (placement2) {
|
|
2390
|
+
resetPlacement = placement2;
|
|
2391
|
+
}
|
|
2392
|
+
break;
|
|
2393
|
+
}
|
|
2394
|
+
case "initialPlacement":
|
|
2395
|
+
resetPlacement = initialPlacement;
|
|
2396
|
+
break;
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
if (placement !== resetPlacement) {
|
|
2400
|
+
return {
|
|
2401
|
+
reset: {
|
|
2402
|
+
placement: resetPlacement
|
|
2403
|
+
}
|
|
2404
|
+
};
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
return {};
|
|
2408
|
+
}
|
|
2409
|
+
};
|
|
2410
|
+
};
|
|
2411
|
+
var originSides = /* @__PURE__ */ new Set(["left", "top"]);
|
|
2412
|
+
async function convertValueToCoords(state, options) {
|
|
2413
|
+
const {
|
|
2414
|
+
placement,
|
|
2415
|
+
platform: platform2,
|
|
2416
|
+
elements
|
|
2417
|
+
} = state;
|
|
2418
|
+
const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
|
|
2419
|
+
const side = getSide(placement);
|
|
2420
|
+
const alignment = getAlignment(placement);
|
|
2421
|
+
const isVertical = getSideAxis(placement) === "y";
|
|
2422
|
+
const mainAxisMulti = originSides.has(side) ? -1 : 1;
|
|
2423
|
+
const crossAxisMulti = rtl && isVertical ? -1 : 1;
|
|
2424
|
+
const rawValue = evaluate(options, state);
|
|
2425
|
+
let {
|
|
2426
|
+
mainAxis,
|
|
2427
|
+
crossAxis,
|
|
2428
|
+
alignmentAxis
|
|
2429
|
+
} = typeof rawValue === "number" ? {
|
|
2430
|
+
mainAxis: rawValue,
|
|
2431
|
+
crossAxis: 0,
|
|
2432
|
+
alignmentAxis: null
|
|
2433
|
+
} : {
|
|
2434
|
+
mainAxis: rawValue.mainAxis || 0,
|
|
2435
|
+
crossAxis: rawValue.crossAxis || 0,
|
|
2436
|
+
alignmentAxis: rawValue.alignmentAxis
|
|
2437
|
+
};
|
|
2438
|
+
if (alignment && typeof alignmentAxis === "number") {
|
|
2439
|
+
crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
|
|
2440
|
+
}
|
|
2441
|
+
return isVertical ? {
|
|
2442
|
+
x: crossAxis * crossAxisMulti,
|
|
2443
|
+
y: mainAxis * mainAxisMulti
|
|
2444
|
+
} : {
|
|
2445
|
+
x: mainAxis * mainAxisMulti,
|
|
2446
|
+
y: crossAxis * crossAxisMulti
|
|
2447
|
+
};
|
|
2448
|
+
}
|
|
2449
|
+
var offset = function(options) {
|
|
2450
|
+
if (options === void 0) {
|
|
2451
|
+
options = 0;
|
|
2452
|
+
}
|
|
2453
|
+
return {
|
|
2454
|
+
name: "offset",
|
|
2455
|
+
options,
|
|
2456
|
+
async fn(state) {
|
|
2457
|
+
var _middlewareData$offse, _middlewareData$arrow;
|
|
2458
|
+
const {
|
|
2459
|
+
x,
|
|
2460
|
+
y,
|
|
2461
|
+
placement,
|
|
2462
|
+
middlewareData
|
|
2463
|
+
} = state;
|
|
2464
|
+
const diffCoords = await convertValueToCoords(state, options);
|
|
2465
|
+
if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
2466
|
+
return {};
|
|
2467
|
+
}
|
|
2468
|
+
return {
|
|
2469
|
+
x: x + diffCoords.x,
|
|
2470
|
+
y: y + diffCoords.y,
|
|
2471
|
+
data: {
|
|
2472
|
+
...diffCoords,
|
|
2473
|
+
placement
|
|
2474
|
+
}
|
|
2475
|
+
};
|
|
2476
|
+
}
|
|
2477
|
+
};
|
|
2478
|
+
};
|
|
2479
|
+
var shift = function(options) {
|
|
2480
|
+
if (options === void 0) {
|
|
2481
|
+
options = {};
|
|
2482
|
+
}
|
|
2483
|
+
return {
|
|
2484
|
+
name: "shift",
|
|
2485
|
+
options,
|
|
2486
|
+
async fn(state) {
|
|
2487
|
+
const {
|
|
2488
|
+
x,
|
|
2489
|
+
y,
|
|
2490
|
+
placement
|
|
2491
|
+
} = state;
|
|
2492
|
+
const {
|
|
2493
|
+
mainAxis: checkMainAxis = true,
|
|
2494
|
+
crossAxis: checkCrossAxis = false,
|
|
2495
|
+
limiter = {
|
|
2496
|
+
fn: (_ref) => {
|
|
2497
|
+
let {
|
|
2498
|
+
x: x2,
|
|
2499
|
+
y: y2
|
|
2500
|
+
} = _ref;
|
|
2501
|
+
return {
|
|
2502
|
+
x: x2,
|
|
2503
|
+
y: y2
|
|
2504
|
+
};
|
|
2505
|
+
}
|
|
2506
|
+
},
|
|
2507
|
+
...detectOverflowOptions
|
|
2508
|
+
} = evaluate(options, state);
|
|
2509
|
+
const coords = {
|
|
2510
|
+
x,
|
|
2511
|
+
y
|
|
2512
|
+
};
|
|
2513
|
+
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
2514
|
+
const crossAxis = getSideAxis(getSide(placement));
|
|
2515
|
+
const mainAxis = getOppositeAxis(crossAxis);
|
|
2516
|
+
let mainAxisCoord = coords[mainAxis];
|
|
2517
|
+
let crossAxisCoord = coords[crossAxis];
|
|
2518
|
+
if (checkMainAxis) {
|
|
2519
|
+
const minSide = mainAxis === "y" ? "top" : "left";
|
|
2520
|
+
const maxSide = mainAxis === "y" ? "bottom" : "right";
|
|
2521
|
+
const min2 = mainAxisCoord + overflow[minSide];
|
|
2522
|
+
const max2 = mainAxisCoord - overflow[maxSide];
|
|
2523
|
+
mainAxisCoord = clamp(min2, mainAxisCoord, max2);
|
|
2524
|
+
}
|
|
2525
|
+
if (checkCrossAxis) {
|
|
2526
|
+
const minSide = crossAxis === "y" ? "top" : "left";
|
|
2527
|
+
const maxSide = crossAxis === "y" ? "bottom" : "right";
|
|
2528
|
+
const min2 = crossAxisCoord + overflow[minSide];
|
|
2529
|
+
const max2 = crossAxisCoord - overflow[maxSide];
|
|
2530
|
+
crossAxisCoord = clamp(min2, crossAxisCoord, max2);
|
|
2531
|
+
}
|
|
2532
|
+
const limitedCoords = limiter.fn({
|
|
2533
|
+
...state,
|
|
2534
|
+
[mainAxis]: mainAxisCoord,
|
|
2535
|
+
[crossAxis]: crossAxisCoord
|
|
2536
|
+
});
|
|
2537
|
+
return {
|
|
2538
|
+
...limitedCoords,
|
|
2539
|
+
data: {
|
|
2540
|
+
x: limitedCoords.x - x,
|
|
2541
|
+
y: limitedCoords.y - y,
|
|
2542
|
+
enabled: {
|
|
2543
|
+
[mainAxis]: checkMainAxis,
|
|
2544
|
+
[crossAxis]: checkCrossAxis
|
|
2545
|
+
}
|
|
2546
|
+
}
|
|
2547
|
+
};
|
|
2548
|
+
}
|
|
2549
|
+
};
|
|
2550
|
+
};
|
|
2551
|
+
|
|
2552
|
+
// node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.mjs
|
|
2553
|
+
function hasWindow() {
|
|
2554
|
+
return typeof window !== "undefined";
|
|
2555
|
+
}
|
|
2556
|
+
function getNodeName(node) {
|
|
2557
|
+
if (isNode(node)) {
|
|
2558
|
+
return (node.nodeName || "").toLowerCase();
|
|
2559
|
+
}
|
|
2560
|
+
return "#document";
|
|
2561
|
+
}
|
|
2562
|
+
function getWindow(node) {
|
|
2563
|
+
var _node$ownerDocument;
|
|
2564
|
+
return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
|
|
2565
|
+
}
|
|
2566
|
+
function getDocumentElement(node) {
|
|
2567
|
+
var _ref;
|
|
2568
|
+
return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
|
|
2569
|
+
}
|
|
2570
|
+
function isNode(value) {
|
|
2571
|
+
if (!hasWindow()) {
|
|
2572
|
+
return false;
|
|
2573
|
+
}
|
|
2574
|
+
return value instanceof Node || value instanceof getWindow(value).Node;
|
|
2575
|
+
}
|
|
2576
|
+
function isElement(value) {
|
|
2577
|
+
if (!hasWindow()) {
|
|
2578
|
+
return false;
|
|
2579
|
+
}
|
|
2580
|
+
return value instanceof Element || value instanceof getWindow(value).Element;
|
|
2581
|
+
}
|
|
2582
|
+
function isHTMLElement(value) {
|
|
2583
|
+
if (!hasWindow()) {
|
|
2584
|
+
return false;
|
|
2585
|
+
}
|
|
2586
|
+
return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
|
|
2587
|
+
}
|
|
2588
|
+
function isShadowRoot(value) {
|
|
2589
|
+
if (!hasWindow() || typeof ShadowRoot === "undefined") {
|
|
2590
|
+
return false;
|
|
2591
|
+
}
|
|
2592
|
+
return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
|
|
2593
|
+
}
|
|
2594
|
+
var invalidOverflowDisplayValues = /* @__PURE__ */ new Set(["inline", "contents"]);
|
|
2595
|
+
function isOverflowElement(element) {
|
|
2596
|
+
const {
|
|
2597
|
+
overflow,
|
|
2598
|
+
overflowX,
|
|
2599
|
+
overflowY,
|
|
2600
|
+
display
|
|
2601
|
+
} = getComputedStyle(element);
|
|
2602
|
+
return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !invalidOverflowDisplayValues.has(display);
|
|
2603
|
+
}
|
|
2604
|
+
var tableElements = /* @__PURE__ */ new Set(["table", "td", "th"]);
|
|
2605
|
+
function isTableElement(element) {
|
|
2606
|
+
return tableElements.has(getNodeName(element));
|
|
2607
|
+
}
|
|
2608
|
+
var topLayerSelectors = [":popover-open", ":modal"];
|
|
2609
|
+
function isTopLayer(element) {
|
|
2610
|
+
return topLayerSelectors.some((selector) => {
|
|
2611
|
+
try {
|
|
2612
|
+
return element.matches(selector);
|
|
2613
|
+
} catch (_e) {
|
|
2614
|
+
return false;
|
|
2615
|
+
}
|
|
2616
|
+
});
|
|
2617
|
+
}
|
|
2618
|
+
var transformProperties = ["transform", "translate", "scale", "rotate", "perspective"];
|
|
2619
|
+
var willChangeValues = ["transform", "translate", "scale", "rotate", "perspective", "filter"];
|
|
2620
|
+
var containValues = ["paint", "layout", "strict", "content"];
|
|
2621
|
+
function isContainingBlock(elementOrCss) {
|
|
2622
|
+
const webkit = isWebKit();
|
|
2623
|
+
const css = isElement(elementOrCss) ? getComputedStyle(elementOrCss) : elementOrCss;
|
|
2624
|
+
return transformProperties.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) || willChangeValues.some((value) => (css.willChange || "").includes(value)) || containValues.some((value) => (css.contain || "").includes(value));
|
|
2625
|
+
}
|
|
2626
|
+
function getContainingBlock(element) {
|
|
2627
|
+
let currentNode = getParentNode(element);
|
|
2628
|
+
while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
2629
|
+
if (isContainingBlock(currentNode)) {
|
|
2630
|
+
return currentNode;
|
|
2631
|
+
} else if (isTopLayer(currentNode)) {
|
|
2632
|
+
return null;
|
|
2633
|
+
}
|
|
2634
|
+
currentNode = getParentNode(currentNode);
|
|
2635
|
+
}
|
|
2636
|
+
return null;
|
|
2637
|
+
}
|
|
2638
|
+
function isWebKit() {
|
|
2639
|
+
if (typeof CSS === "undefined" || !CSS.supports)
|
|
2640
|
+
return false;
|
|
2641
|
+
return CSS.supports("-webkit-backdrop-filter", "none");
|
|
2642
|
+
}
|
|
2643
|
+
var lastTraversableNodeNames = /* @__PURE__ */ new Set(["html", "body", "#document"]);
|
|
2644
|
+
function isLastTraversableNode(node) {
|
|
2645
|
+
return lastTraversableNodeNames.has(getNodeName(node));
|
|
2646
|
+
}
|
|
2647
|
+
function getComputedStyle(element) {
|
|
2648
|
+
return getWindow(element).getComputedStyle(element);
|
|
2649
|
+
}
|
|
2650
|
+
function getNodeScroll(element) {
|
|
2651
|
+
if (isElement(element)) {
|
|
2652
|
+
return {
|
|
2653
|
+
scrollLeft: element.scrollLeft,
|
|
2654
|
+
scrollTop: element.scrollTop
|
|
2655
|
+
};
|
|
2656
|
+
}
|
|
2657
|
+
return {
|
|
2658
|
+
scrollLeft: element.scrollX,
|
|
2659
|
+
scrollTop: element.scrollY
|
|
2660
|
+
};
|
|
2661
|
+
}
|
|
2662
|
+
function getParentNode(node) {
|
|
2663
|
+
if (getNodeName(node) === "html") {
|
|
2664
|
+
return node;
|
|
2665
|
+
}
|
|
2666
|
+
const result = (
|
|
2667
|
+
// Step into the shadow DOM of the parent of a slotted node.
|
|
2668
|
+
node.assignedSlot || // DOM Element detected.
|
|
2669
|
+
node.parentNode || // ShadowRoot detected.
|
|
2670
|
+
isShadowRoot(node) && node.host || // Fallback.
|
|
2671
|
+
getDocumentElement(node)
|
|
2672
|
+
);
|
|
2673
|
+
return isShadowRoot(result) ? result.host : result;
|
|
2674
|
+
}
|
|
2675
|
+
function getNearestOverflowAncestor(node) {
|
|
2676
|
+
const parentNode = getParentNode(node);
|
|
2677
|
+
if (isLastTraversableNode(parentNode)) {
|
|
2678
|
+
return node.ownerDocument ? node.ownerDocument.body : node.body;
|
|
2679
|
+
}
|
|
2680
|
+
if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
|
|
2681
|
+
return parentNode;
|
|
2682
|
+
}
|
|
2683
|
+
return getNearestOverflowAncestor(parentNode);
|
|
2684
|
+
}
|
|
2685
|
+
function getOverflowAncestors(node, list, traverseIframes) {
|
|
2686
|
+
var _node$ownerDocument2;
|
|
2687
|
+
if (list === void 0) {
|
|
2688
|
+
list = [];
|
|
2689
|
+
}
|
|
2690
|
+
if (traverseIframes === void 0) {
|
|
2691
|
+
traverseIframes = true;
|
|
2692
|
+
}
|
|
2693
|
+
const scrollableAncestor = getNearestOverflowAncestor(node);
|
|
2694
|
+
const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
|
|
2695
|
+
const win = getWindow(scrollableAncestor);
|
|
2696
|
+
if (isBody) {
|
|
2697
|
+
const frameElement = getFrameElement(win);
|
|
2698
|
+
return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
|
|
2699
|
+
}
|
|
2700
|
+
return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
|
|
2701
|
+
}
|
|
2702
|
+
function getFrameElement(win) {
|
|
2703
|
+
return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
|
|
2704
|
+
}
|
|
2705
|
+
|
|
2706
|
+
// node_modules/@floating-ui/dom/dist/floating-ui.dom.mjs
|
|
2707
|
+
function getCssDimensions(element) {
|
|
2708
|
+
const css = getComputedStyle(element);
|
|
2709
|
+
let width = parseFloat(css.width) || 0;
|
|
2710
|
+
let height = parseFloat(css.height) || 0;
|
|
2711
|
+
const hasOffset = isHTMLElement(element);
|
|
2712
|
+
const offsetWidth = hasOffset ? element.offsetWidth : width;
|
|
2713
|
+
const offsetHeight = hasOffset ? element.offsetHeight : height;
|
|
2714
|
+
const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
|
|
2715
|
+
if (shouldFallback) {
|
|
2716
|
+
width = offsetWidth;
|
|
2717
|
+
height = offsetHeight;
|
|
2718
|
+
}
|
|
2719
|
+
return {
|
|
2720
|
+
width,
|
|
2721
|
+
height,
|
|
2722
|
+
$: shouldFallback
|
|
2723
|
+
};
|
|
2724
|
+
}
|
|
2725
|
+
function unwrapElement(element) {
|
|
2726
|
+
return !isElement(element) ? element.contextElement : element;
|
|
2727
|
+
}
|
|
2728
|
+
function getScale(element) {
|
|
2729
|
+
const domElement = unwrapElement(element);
|
|
2730
|
+
if (!isHTMLElement(domElement)) {
|
|
2731
|
+
return createCoords(1);
|
|
2732
|
+
}
|
|
2733
|
+
const rect = domElement.getBoundingClientRect();
|
|
2734
|
+
const {
|
|
2735
|
+
width,
|
|
2736
|
+
height,
|
|
2737
|
+
$
|
|
2738
|
+
} = getCssDimensions(domElement);
|
|
2739
|
+
let x = ($ ? round(rect.width) : rect.width) / width;
|
|
2740
|
+
let y = ($ ? round(rect.height) : rect.height) / height;
|
|
2741
|
+
if (!x || !Number.isFinite(x)) {
|
|
2742
|
+
x = 1;
|
|
2743
|
+
}
|
|
2744
|
+
if (!y || !Number.isFinite(y)) {
|
|
2745
|
+
y = 1;
|
|
2746
|
+
}
|
|
2747
|
+
return {
|
|
2748
|
+
x,
|
|
2749
|
+
y
|
|
2750
|
+
};
|
|
2751
|
+
}
|
|
2752
|
+
var noOffsets = /* @__PURE__ */ createCoords(0);
|
|
2753
|
+
function getVisualOffsets(element) {
|
|
2754
|
+
const win = getWindow(element);
|
|
2755
|
+
if (!isWebKit() || !win.visualViewport) {
|
|
2756
|
+
return noOffsets;
|
|
2757
|
+
}
|
|
2758
|
+
return {
|
|
2759
|
+
x: win.visualViewport.offsetLeft,
|
|
2760
|
+
y: win.visualViewport.offsetTop
|
|
2761
|
+
};
|
|
2762
|
+
}
|
|
2763
|
+
function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
|
|
2764
|
+
if (isFixed === void 0) {
|
|
2765
|
+
isFixed = false;
|
|
2766
|
+
}
|
|
2767
|
+
if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
|
|
2768
|
+
return false;
|
|
2769
|
+
}
|
|
2770
|
+
return isFixed;
|
|
2771
|
+
}
|
|
2772
|
+
function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
|
|
2773
|
+
if (includeScale === void 0) {
|
|
2774
|
+
includeScale = false;
|
|
2775
|
+
}
|
|
2776
|
+
if (isFixedStrategy === void 0) {
|
|
2777
|
+
isFixedStrategy = false;
|
|
2778
|
+
}
|
|
2779
|
+
const clientRect = element.getBoundingClientRect();
|
|
2780
|
+
const domElement = unwrapElement(element);
|
|
2781
|
+
let scale = createCoords(1);
|
|
2782
|
+
if (includeScale) {
|
|
2783
|
+
if (offsetParent) {
|
|
2784
|
+
if (isElement(offsetParent)) {
|
|
2785
|
+
scale = getScale(offsetParent);
|
|
2786
|
+
}
|
|
2787
|
+
} else {
|
|
2788
|
+
scale = getScale(element);
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
|
|
2792
|
+
let x = (clientRect.left + visualOffsets.x) / scale.x;
|
|
2793
|
+
let y = (clientRect.top + visualOffsets.y) / scale.y;
|
|
2794
|
+
let width = clientRect.width / scale.x;
|
|
2795
|
+
let height = clientRect.height / scale.y;
|
|
2796
|
+
if (domElement) {
|
|
2797
|
+
const win = getWindow(domElement);
|
|
2798
|
+
const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
|
|
2799
|
+
let currentWin = win;
|
|
2800
|
+
let currentIFrame = getFrameElement(currentWin);
|
|
2801
|
+
while (currentIFrame && offsetParent && offsetWin !== currentWin) {
|
|
2802
|
+
const iframeScale = getScale(currentIFrame);
|
|
2803
|
+
const iframeRect = currentIFrame.getBoundingClientRect();
|
|
2804
|
+
const css = getComputedStyle(currentIFrame);
|
|
2805
|
+
const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
|
|
2806
|
+
const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
|
|
2807
|
+
x *= iframeScale.x;
|
|
2808
|
+
y *= iframeScale.y;
|
|
2809
|
+
width *= iframeScale.x;
|
|
2810
|
+
height *= iframeScale.y;
|
|
2811
|
+
x += left;
|
|
2812
|
+
y += top;
|
|
2813
|
+
currentWin = getWindow(currentIFrame);
|
|
2814
|
+
currentIFrame = getFrameElement(currentWin);
|
|
2815
|
+
}
|
|
2816
|
+
}
|
|
2817
|
+
return rectToClientRect({
|
|
2818
|
+
width,
|
|
2819
|
+
height,
|
|
2820
|
+
x,
|
|
2821
|
+
y
|
|
2822
|
+
});
|
|
2823
|
+
}
|
|
2824
|
+
function getWindowScrollBarX(element, rect) {
|
|
2825
|
+
const leftScroll = getNodeScroll(element).scrollLeft;
|
|
2826
|
+
if (!rect) {
|
|
2827
|
+
return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
|
|
2828
|
+
}
|
|
2829
|
+
return rect.left + leftScroll;
|
|
2830
|
+
}
|
|
2831
|
+
function getHTMLOffset(documentElement, scroll, ignoreScrollbarX) {
|
|
2832
|
+
if (ignoreScrollbarX === void 0) {
|
|
2833
|
+
ignoreScrollbarX = false;
|
|
2834
|
+
}
|
|
2835
|
+
const htmlRect = documentElement.getBoundingClientRect();
|
|
2836
|
+
const x = htmlRect.left + scroll.scrollLeft - (ignoreScrollbarX ? 0 : (
|
|
2837
|
+
// RTL <body> scrollbar.
|
|
2838
|
+
getWindowScrollBarX(documentElement, htmlRect)
|
|
2839
|
+
));
|
|
2840
|
+
const y = htmlRect.top + scroll.scrollTop;
|
|
2841
|
+
return {
|
|
2842
|
+
x,
|
|
2843
|
+
y
|
|
2844
|
+
};
|
|
2845
|
+
}
|
|
2846
|
+
function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
|
|
2847
|
+
let {
|
|
2848
|
+
elements,
|
|
2849
|
+
rect,
|
|
2850
|
+
offsetParent,
|
|
2851
|
+
strategy
|
|
2852
|
+
} = _ref;
|
|
2853
|
+
const isFixed = strategy === "fixed";
|
|
2854
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
2855
|
+
const topLayer = elements ? isTopLayer(elements.floating) : false;
|
|
2856
|
+
if (offsetParent === documentElement || topLayer && isFixed) {
|
|
2857
|
+
return rect;
|
|
2858
|
+
}
|
|
2859
|
+
let scroll = {
|
|
2860
|
+
scrollLeft: 0,
|
|
2861
|
+
scrollTop: 0
|
|
2862
|
+
};
|
|
2863
|
+
let scale = createCoords(1);
|
|
2864
|
+
const offsets = createCoords(0);
|
|
2865
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
2866
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
2867
|
+
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
|
|
2868
|
+
scroll = getNodeScroll(offsetParent);
|
|
2869
|
+
}
|
|
2870
|
+
if (isHTMLElement(offsetParent)) {
|
|
2871
|
+
const offsetRect = getBoundingClientRect(offsetParent);
|
|
2872
|
+
scale = getScale(offsetParent);
|
|
2873
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
2874
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
2875
|
+
}
|
|
2876
|
+
}
|
|
2877
|
+
const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll, true) : createCoords(0);
|
|
2878
|
+
return {
|
|
2879
|
+
width: rect.width * scale.x,
|
|
2880
|
+
height: rect.height * scale.y,
|
|
2881
|
+
x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
|
|
2882
|
+
y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
|
|
2883
|
+
};
|
|
2884
|
+
}
|
|
2885
|
+
function getClientRects(element) {
|
|
2886
|
+
return Array.from(element.getClientRects());
|
|
2887
|
+
}
|
|
2888
|
+
function getDocumentRect(element) {
|
|
2889
|
+
const html = getDocumentElement(element);
|
|
2890
|
+
const scroll = getNodeScroll(element);
|
|
2891
|
+
const body = element.ownerDocument.body;
|
|
2892
|
+
const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
|
|
2893
|
+
const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
|
|
2894
|
+
let x = -scroll.scrollLeft + getWindowScrollBarX(element);
|
|
2895
|
+
const y = -scroll.scrollTop;
|
|
2896
|
+
if (getComputedStyle(body).direction === "rtl") {
|
|
2897
|
+
x += max(html.clientWidth, body.clientWidth) - width;
|
|
2898
|
+
}
|
|
2899
|
+
return {
|
|
2900
|
+
width,
|
|
2901
|
+
height,
|
|
2902
|
+
x,
|
|
2903
|
+
y
|
|
2904
|
+
};
|
|
2905
|
+
}
|
|
2906
|
+
function getViewportRect(element, strategy) {
|
|
2907
|
+
const win = getWindow(element);
|
|
2908
|
+
const html = getDocumentElement(element);
|
|
2909
|
+
const visualViewport = win.visualViewport;
|
|
2910
|
+
let width = html.clientWidth;
|
|
2911
|
+
let height = html.clientHeight;
|
|
2912
|
+
let x = 0;
|
|
2913
|
+
let y = 0;
|
|
2914
|
+
if (visualViewport) {
|
|
2915
|
+
width = visualViewport.width;
|
|
2916
|
+
height = visualViewport.height;
|
|
2917
|
+
const visualViewportBased = isWebKit();
|
|
2918
|
+
if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
|
|
2919
|
+
x = visualViewport.offsetLeft;
|
|
2920
|
+
y = visualViewport.offsetTop;
|
|
2921
|
+
}
|
|
2922
|
+
}
|
|
2923
|
+
return {
|
|
2924
|
+
width,
|
|
2925
|
+
height,
|
|
2926
|
+
x,
|
|
2927
|
+
y
|
|
2928
|
+
};
|
|
2929
|
+
}
|
|
2930
|
+
var absoluteOrFixed = /* @__PURE__ */ new Set(["absolute", "fixed"]);
|
|
2931
|
+
function getInnerBoundingClientRect(element, strategy) {
|
|
2932
|
+
const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
|
|
2933
|
+
const top = clientRect.top + element.clientTop;
|
|
2934
|
+
const left = clientRect.left + element.clientLeft;
|
|
2935
|
+
const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
|
|
2936
|
+
const width = element.clientWidth * scale.x;
|
|
2937
|
+
const height = element.clientHeight * scale.y;
|
|
2938
|
+
const x = left * scale.x;
|
|
2939
|
+
const y = top * scale.y;
|
|
2940
|
+
return {
|
|
2941
|
+
width,
|
|
2942
|
+
height,
|
|
2943
|
+
x,
|
|
2944
|
+
y
|
|
2945
|
+
};
|
|
2946
|
+
}
|
|
2947
|
+
function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
|
|
2948
|
+
let rect;
|
|
2949
|
+
if (clippingAncestor === "viewport") {
|
|
2950
|
+
rect = getViewportRect(element, strategy);
|
|
2951
|
+
} else if (clippingAncestor === "document") {
|
|
2952
|
+
rect = getDocumentRect(getDocumentElement(element));
|
|
2953
|
+
} else if (isElement(clippingAncestor)) {
|
|
2954
|
+
rect = getInnerBoundingClientRect(clippingAncestor, strategy);
|
|
2955
|
+
} else {
|
|
2956
|
+
const visualOffsets = getVisualOffsets(element);
|
|
2957
|
+
rect = {
|
|
2958
|
+
x: clippingAncestor.x - visualOffsets.x,
|
|
2959
|
+
y: clippingAncestor.y - visualOffsets.y,
|
|
2960
|
+
width: clippingAncestor.width,
|
|
2961
|
+
height: clippingAncestor.height
|
|
2962
|
+
};
|
|
2963
|
+
}
|
|
2964
|
+
return rectToClientRect(rect);
|
|
2965
|
+
}
|
|
2966
|
+
function hasFixedPositionAncestor(element, stopNode) {
|
|
2967
|
+
const parentNode = getParentNode(element);
|
|
2968
|
+
if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
|
|
2969
|
+
return false;
|
|
2970
|
+
}
|
|
2971
|
+
return getComputedStyle(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
|
|
2972
|
+
}
|
|
2973
|
+
function getClippingElementAncestors(element, cache) {
|
|
2974
|
+
const cachedResult = cache.get(element);
|
|
2975
|
+
if (cachedResult) {
|
|
2976
|
+
return cachedResult;
|
|
2977
|
+
}
|
|
2978
|
+
let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
|
|
2979
|
+
let currentContainingBlockComputedStyle = null;
|
|
2980
|
+
const elementIsFixed = getComputedStyle(element).position === "fixed";
|
|
2981
|
+
let currentNode = elementIsFixed ? getParentNode(element) : element;
|
|
2982
|
+
while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
2983
|
+
const computedStyle = getComputedStyle(currentNode);
|
|
2984
|
+
const currentNodeIsContaining = isContainingBlock(currentNode);
|
|
2985
|
+
if (!currentNodeIsContaining && computedStyle.position === "fixed") {
|
|
2986
|
+
currentContainingBlockComputedStyle = null;
|
|
2987
|
+
}
|
|
2988
|
+
const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && absoluteOrFixed.has(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
|
|
2989
|
+
if (shouldDropCurrentNode) {
|
|
2990
|
+
result = result.filter((ancestor) => ancestor !== currentNode);
|
|
2991
|
+
} else {
|
|
2992
|
+
currentContainingBlockComputedStyle = computedStyle;
|
|
2993
|
+
}
|
|
2994
|
+
currentNode = getParentNode(currentNode);
|
|
2995
|
+
}
|
|
2996
|
+
cache.set(element, result);
|
|
2997
|
+
return result;
|
|
2998
|
+
}
|
|
2999
|
+
function getClippingRect(_ref) {
|
|
3000
|
+
let {
|
|
3001
|
+
element,
|
|
3002
|
+
boundary,
|
|
3003
|
+
rootBoundary,
|
|
3004
|
+
strategy
|
|
3005
|
+
} = _ref;
|
|
3006
|
+
const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
|
|
3007
|
+
const clippingAncestors = [...elementClippingAncestors, rootBoundary];
|
|
3008
|
+
const firstClippingAncestor = clippingAncestors[0];
|
|
3009
|
+
const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
|
|
3010
|
+
const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
|
|
3011
|
+
accRect.top = max(rect.top, accRect.top);
|
|
3012
|
+
accRect.right = min(rect.right, accRect.right);
|
|
3013
|
+
accRect.bottom = min(rect.bottom, accRect.bottom);
|
|
3014
|
+
accRect.left = max(rect.left, accRect.left);
|
|
3015
|
+
return accRect;
|
|
3016
|
+
}, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
|
|
3017
|
+
return {
|
|
3018
|
+
width: clippingRect.right - clippingRect.left,
|
|
3019
|
+
height: clippingRect.bottom - clippingRect.top,
|
|
3020
|
+
x: clippingRect.left,
|
|
3021
|
+
y: clippingRect.top
|
|
3022
|
+
};
|
|
3023
|
+
}
|
|
3024
|
+
function getDimensions(element) {
|
|
3025
|
+
const {
|
|
3026
|
+
width,
|
|
3027
|
+
height
|
|
3028
|
+
} = getCssDimensions(element);
|
|
3029
|
+
return {
|
|
3030
|
+
width,
|
|
3031
|
+
height
|
|
3032
|
+
};
|
|
3033
|
+
}
|
|
3034
|
+
function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
|
|
3035
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
3036
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
3037
|
+
const isFixed = strategy === "fixed";
|
|
3038
|
+
const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
|
|
3039
|
+
let scroll = {
|
|
3040
|
+
scrollLeft: 0,
|
|
3041
|
+
scrollTop: 0
|
|
3042
|
+
};
|
|
3043
|
+
const offsets = createCoords(0);
|
|
3044
|
+
function setLeftRTLScrollbarOffset() {
|
|
3045
|
+
offsets.x = getWindowScrollBarX(documentElement);
|
|
3046
|
+
}
|
|
3047
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
3048
|
+
if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
|
|
3049
|
+
scroll = getNodeScroll(offsetParent);
|
|
3050
|
+
}
|
|
3051
|
+
if (isOffsetParentAnElement) {
|
|
3052
|
+
const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
|
|
3053
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
3054
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
3055
|
+
} else if (documentElement) {
|
|
3056
|
+
setLeftRTLScrollbarOffset();
|
|
3057
|
+
}
|
|
3058
|
+
}
|
|
3059
|
+
if (isFixed && !isOffsetParentAnElement && documentElement) {
|
|
3060
|
+
setLeftRTLScrollbarOffset();
|
|
3061
|
+
}
|
|
3062
|
+
const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
|
|
3063
|
+
const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
|
|
3064
|
+
const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
|
|
3065
|
+
return {
|
|
3066
|
+
x,
|
|
3067
|
+
y,
|
|
3068
|
+
width: rect.width,
|
|
3069
|
+
height: rect.height
|
|
3070
|
+
};
|
|
3071
|
+
}
|
|
3072
|
+
function isStaticPositioned(element) {
|
|
3073
|
+
return getComputedStyle(element).position === "static";
|
|
3074
|
+
}
|
|
3075
|
+
function getTrueOffsetParent(element, polyfill) {
|
|
3076
|
+
if (!isHTMLElement(element) || getComputedStyle(element).position === "fixed") {
|
|
3077
|
+
return null;
|
|
3078
|
+
}
|
|
3079
|
+
if (polyfill) {
|
|
3080
|
+
return polyfill(element);
|
|
3081
|
+
}
|
|
3082
|
+
let rawOffsetParent = element.offsetParent;
|
|
3083
|
+
if (getDocumentElement(element) === rawOffsetParent) {
|
|
3084
|
+
rawOffsetParent = rawOffsetParent.ownerDocument.body;
|
|
3085
|
+
}
|
|
3086
|
+
return rawOffsetParent;
|
|
3087
|
+
}
|
|
3088
|
+
function getOffsetParent(element, polyfill) {
|
|
3089
|
+
const win = getWindow(element);
|
|
3090
|
+
if (isTopLayer(element)) {
|
|
3091
|
+
return win;
|
|
3092
|
+
}
|
|
3093
|
+
if (!isHTMLElement(element)) {
|
|
3094
|
+
let svgOffsetParent = getParentNode(element);
|
|
3095
|
+
while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
|
|
3096
|
+
if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
|
|
3097
|
+
return svgOffsetParent;
|
|
3098
|
+
}
|
|
3099
|
+
svgOffsetParent = getParentNode(svgOffsetParent);
|
|
3100
|
+
}
|
|
3101
|
+
return win;
|
|
3102
|
+
}
|
|
3103
|
+
let offsetParent = getTrueOffsetParent(element, polyfill);
|
|
3104
|
+
while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
|
|
3105
|
+
offsetParent = getTrueOffsetParent(offsetParent, polyfill);
|
|
3106
|
+
}
|
|
3107
|
+
if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
|
|
3108
|
+
return win;
|
|
3109
|
+
}
|
|
3110
|
+
return offsetParent || getContainingBlock(element) || win;
|
|
3111
|
+
}
|
|
3112
|
+
var getElementRects = async function(data) {
|
|
3113
|
+
const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
|
|
3114
|
+
const getDimensionsFn = this.getDimensions;
|
|
3115
|
+
const floatingDimensions = await getDimensionsFn(data.floating);
|
|
3116
|
+
return {
|
|
3117
|
+
reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
|
|
3118
|
+
floating: {
|
|
3119
|
+
x: 0,
|
|
3120
|
+
y: 0,
|
|
3121
|
+
width: floatingDimensions.width,
|
|
3122
|
+
height: floatingDimensions.height
|
|
3123
|
+
}
|
|
3124
|
+
};
|
|
3125
|
+
};
|
|
3126
|
+
function isRTL(element) {
|
|
3127
|
+
return getComputedStyle(element).direction === "rtl";
|
|
3128
|
+
}
|
|
3129
|
+
var platform = {
|
|
3130
|
+
convertOffsetParentRelativeRectToViewportRelativeRect,
|
|
3131
|
+
getDocumentElement,
|
|
3132
|
+
getClippingRect,
|
|
3133
|
+
getOffsetParent,
|
|
3134
|
+
getElementRects,
|
|
3135
|
+
getClientRects,
|
|
3136
|
+
getDimensions,
|
|
3137
|
+
getScale,
|
|
3138
|
+
isElement,
|
|
3139
|
+
isRTL
|
|
3140
|
+
};
|
|
3141
|
+
var offset2 = offset;
|
|
3142
|
+
var shift2 = shift;
|
|
3143
|
+
var flip2 = flip;
|
|
3144
|
+
var computePosition2 = (reference, floating, options) => {
|
|
3145
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3146
|
+
const mergedOptions = {
|
|
3147
|
+
platform,
|
|
3148
|
+
...options
|
|
3149
|
+
};
|
|
3150
|
+
const platformWithCache = {
|
|
3151
|
+
...mergedOptions.platform,
|
|
3152
|
+
_c: cache
|
|
3153
|
+
};
|
|
3154
|
+
return computePosition(reference, floating, {
|
|
3155
|
+
...mergedOptions,
|
|
3156
|
+
platform: platformWithCache
|
|
3157
|
+
});
|
|
3158
|
+
};
|
|
3159
|
+
|
|
3160
|
+
// src/link-tooltip.js
|
|
3161
|
+
var LinkTooltip = class {
|
|
3162
|
+
constructor(editor) {
|
|
3163
|
+
this.editor = editor;
|
|
3164
|
+
this.tooltip = null;
|
|
3165
|
+
this.currentLink = null;
|
|
3166
|
+
this.hideTimeout = null;
|
|
3167
|
+
this.isMouseInTooltip = false;
|
|
3168
|
+
this.isMouseInLink = false;
|
|
3169
|
+
this.init();
|
|
3170
|
+
}
|
|
3171
|
+
init() {
|
|
3172
|
+
this.createTooltip();
|
|
3173
|
+
this.editor.textarea.addEventListener("selectionchange", () => this.checkCursorPosition());
|
|
3174
|
+
this.editor.textarea.addEventListener("input", () => this.checkCursorPosition());
|
|
3175
|
+
this.editor.textarea.addEventListener("keyup", (e) => {
|
|
3176
|
+
if (e.key.includes("Arrow")) {
|
|
3177
|
+
this.checkCursorPosition();
|
|
3178
|
+
}
|
|
3179
|
+
});
|
|
3180
|
+
this.editor.textarea.addEventListener("scroll", () => this.hide());
|
|
3181
|
+
this.tooltip.addEventListener("mouseenter", () => {
|
|
3182
|
+
this.isMouseInTooltip = true;
|
|
3183
|
+
this.cancelHide();
|
|
3184
|
+
});
|
|
3185
|
+
this.tooltip.addEventListener("mouseleave", () => {
|
|
3186
|
+
this.isMouseInTooltip = false;
|
|
3187
|
+
this.scheduleHide();
|
|
3188
|
+
});
|
|
3189
|
+
}
|
|
3190
|
+
createTooltip() {
|
|
3191
|
+
this.tooltip = document.createElement("div");
|
|
3192
|
+
this.tooltip.className = "overtype-link-tooltip";
|
|
3193
|
+
this.tooltip.style.cssText = `
|
|
3194
|
+
position: absolute;
|
|
3195
|
+
background: #333;
|
|
3196
|
+
color: white;
|
|
3197
|
+
padding: 6px 10px;
|
|
3198
|
+
border-radius: 16px;
|
|
3199
|
+
font-size: 12px;
|
|
3200
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
|
3201
|
+
display: none;
|
|
3202
|
+
z-index: 10000;
|
|
3203
|
+
cursor: pointer;
|
|
3204
|
+
box-shadow: 0 2px 8px rgba(0,0,0,0.3);
|
|
3205
|
+
max-width: 300px;
|
|
3206
|
+
white-space: nowrap;
|
|
3207
|
+
overflow: hidden;
|
|
3208
|
+
text-overflow: ellipsis;
|
|
3209
|
+
transition: opacity 0.2s;
|
|
3210
|
+
opacity: 0;
|
|
3211
|
+
`;
|
|
3212
|
+
this.tooltip.innerHTML = `
|
|
3213
|
+
<span style="display: flex; align-items: center; gap: 6px;">
|
|
3214
|
+
<svg width="12" height="12" viewBox="0 0 20 20" fill="currentColor" style="flex-shrink: 0;">
|
|
3215
|
+
<path d="M11 3a1 1 0 100 2h2.586l-6.293 6.293a1 1 0 101.414 1.414L15 6.414V9a1 1 0 102 0V4a1 1 0 00-1-1h-5z"></path>
|
|
3216
|
+
<path d="M5 5a2 2 0 00-2 2v8a2 2 0 002 2h8a2 2 0 002-2v-3a1 1 0 10-2 0v3H5V7h3a1 1 0 000-2H5z"></path>
|
|
3217
|
+
</svg>
|
|
3218
|
+
<span class="overtype-link-tooltip-url"></span>
|
|
3219
|
+
</span>
|
|
3220
|
+
`;
|
|
3221
|
+
this.tooltip.addEventListener("click", (e) => {
|
|
3222
|
+
e.preventDefault();
|
|
3223
|
+
e.stopPropagation();
|
|
3224
|
+
if (this.currentLink) {
|
|
3225
|
+
window.open(this.currentLink.url, "_blank");
|
|
3226
|
+
this.hide();
|
|
3227
|
+
}
|
|
3228
|
+
});
|
|
3229
|
+
document.body.appendChild(this.tooltip);
|
|
3230
|
+
}
|
|
3231
|
+
checkCursorPosition() {
|
|
3232
|
+
const cursorPos = this.editor.textarea.selectionStart;
|
|
3233
|
+
const text = this.editor.textarea.value;
|
|
3234
|
+
const link = this.findLinkAtPosition(text, cursorPos);
|
|
3235
|
+
if (link) {
|
|
3236
|
+
this.isMouseInLink = true;
|
|
3237
|
+
if (!this.currentLink || this.currentLink.start !== link.start || this.currentLink.url !== link.url) {
|
|
3238
|
+
this.show(link);
|
|
3239
|
+
}
|
|
3240
|
+
} else {
|
|
3241
|
+
this.isMouseInLink = false;
|
|
3242
|
+
this.scheduleHide();
|
|
3243
|
+
}
|
|
3244
|
+
}
|
|
3245
|
+
findLinkAtPosition(text, position) {
|
|
3246
|
+
const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
3247
|
+
let match;
|
|
3248
|
+
while ((match = linkRegex.exec(text)) !== null) {
|
|
3249
|
+
const start = match.index;
|
|
3250
|
+
const end = match.index + match[0].length;
|
|
3251
|
+
if (position >= start && position <= end) {
|
|
3252
|
+
return {
|
|
3253
|
+
start,
|
|
3254
|
+
end,
|
|
3255
|
+
text: match[1],
|
|
3256
|
+
url: match[2],
|
|
3257
|
+
fullMatch: match[0]
|
|
3258
|
+
};
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
return null;
|
|
3262
|
+
}
|
|
3263
|
+
async show(link) {
|
|
3264
|
+
this.currentLink = link;
|
|
3265
|
+
this.cancelHide();
|
|
3266
|
+
const urlSpan = this.tooltip.querySelector(".overtype-link-tooltip-url");
|
|
3267
|
+
urlSpan.textContent = link.url;
|
|
3268
|
+
const linkElement = this.findLinkElementInPreview(link);
|
|
3269
|
+
if (linkElement) {
|
|
3270
|
+
await this.positionTooltip(linkElement);
|
|
3271
|
+
} else {
|
|
3272
|
+
await this.positionTooltipAtCursor(link);
|
|
3273
|
+
}
|
|
3274
|
+
this.tooltip.style.display = "block";
|
|
3275
|
+
this.tooltip.offsetHeight;
|
|
3276
|
+
this.tooltip.style.opacity = "1";
|
|
3277
|
+
}
|
|
3278
|
+
findLinkElementInPreview(link) {
|
|
3279
|
+
const links = this.editor.preview.querySelectorAll("a");
|
|
3280
|
+
for (const linkEl of links) {
|
|
3281
|
+
const urlSpans = linkEl.querySelectorAll(".syntax-marker");
|
|
3282
|
+
for (const span of urlSpans) {
|
|
3283
|
+
if (span.textContent === link.url) {
|
|
3284
|
+
return linkEl;
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
}
|
|
3288
|
+
return null;
|
|
3289
|
+
}
|
|
3290
|
+
async positionTooltip(referenceEl) {
|
|
3291
|
+
const { x, y } = await computePosition2(referenceEl, this.tooltip, {
|
|
3292
|
+
placement: "bottom",
|
|
3293
|
+
middleware: [
|
|
3294
|
+
offset2(6),
|
|
3295
|
+
flip2(),
|
|
3296
|
+
shift2({ padding: 10 })
|
|
3297
|
+
]
|
|
3298
|
+
});
|
|
3299
|
+
Object.assign(this.tooltip.style, {
|
|
3300
|
+
left: `${x}px`,
|
|
3301
|
+
top: `${y}px`
|
|
3302
|
+
});
|
|
3303
|
+
}
|
|
3304
|
+
async positionTooltipAtCursor(link) {
|
|
3305
|
+
const textarea = this.editor.textarea;
|
|
3306
|
+
const measurer = document.createElement("div");
|
|
3307
|
+
measurer.style.cssText = window.getComputedStyle(textarea).cssText;
|
|
3308
|
+
measurer.style.position = "absolute";
|
|
3309
|
+
measurer.style.visibility = "hidden";
|
|
3310
|
+
measurer.style.whiteSpace = "pre-wrap";
|
|
3311
|
+
measurer.style.wordWrap = "break-word";
|
|
3312
|
+
const textBeforeCursor = textarea.value.substring(0, link.start + link.fullMatch.length / 2);
|
|
3313
|
+
measurer.textContent = textBeforeCursor;
|
|
3314
|
+
document.body.appendChild(measurer);
|
|
3315
|
+
const textHeight = measurer.offsetHeight;
|
|
3316
|
+
document.body.removeChild(measurer);
|
|
3317
|
+
const rect = textarea.getBoundingClientRect();
|
|
3318
|
+
const x = rect.left + rect.width / 2;
|
|
3319
|
+
const y = rect.top + Math.min(textHeight, rect.height - 50);
|
|
3320
|
+
Object.assign(this.tooltip.style, {
|
|
3321
|
+
left: `${x}px`,
|
|
3322
|
+
top: `${y}px`,
|
|
3323
|
+
transform: "translateX(-50%)"
|
|
3324
|
+
});
|
|
3325
|
+
}
|
|
3326
|
+
hide() {
|
|
3327
|
+
this.tooltip.style.opacity = "0";
|
|
3328
|
+
setTimeout(() => {
|
|
3329
|
+
if (this.tooltip.style.opacity === "0") {
|
|
3330
|
+
this.tooltip.style.display = "none";
|
|
3331
|
+
this.currentLink = null;
|
|
3332
|
+
}
|
|
3333
|
+
}, 200);
|
|
3334
|
+
}
|
|
3335
|
+
scheduleHide() {
|
|
3336
|
+
this.cancelHide();
|
|
3337
|
+
this.hideTimeout = setTimeout(() => {
|
|
3338
|
+
if (!this.isMouseInTooltip && !this.isMouseInLink) {
|
|
3339
|
+
this.hide();
|
|
3340
|
+
}
|
|
3341
|
+
}, 300);
|
|
3342
|
+
}
|
|
3343
|
+
cancelHide() {
|
|
3344
|
+
if (this.hideTimeout) {
|
|
3345
|
+
clearTimeout(this.hideTimeout);
|
|
3346
|
+
this.hideTimeout = null;
|
|
3347
|
+
}
|
|
3348
|
+
}
|
|
3349
|
+
destroy() {
|
|
3350
|
+
this.cancelHide();
|
|
3351
|
+
if (this.tooltip && this.tooltip.parentNode) {
|
|
3352
|
+
this.tooltip.parentNode.removeChild(this.tooltip);
|
|
3353
|
+
}
|
|
3354
|
+
this.tooltip = null;
|
|
3355
|
+
this.currentLink = null;
|
|
3356
|
+
}
|
|
3357
|
+
};
|
|
3358
|
+
|
|
1965
3359
|
// src/overtype.js
|
|
1966
3360
|
var _OverType = class _OverType {
|
|
1967
3361
|
/**
|
|
@@ -2020,6 +3414,7 @@ var _OverType = class _OverType {
|
|
|
2020
3414
|
this._buildFromScratch();
|
|
2021
3415
|
}
|
|
2022
3416
|
this.shortcuts = new ShortcutsManager(this);
|
|
3417
|
+
this.linkTooltip = new LinkTooltip(this);
|
|
2023
3418
|
if (this.options.toolbar) {
|
|
2024
3419
|
this.toolbar = new Toolbar(this);
|
|
2025
3420
|
this.toolbar.create();
|
|
@@ -2044,7 +3439,7 @@ var _OverType = class _OverType {
|
|
|
2044
3439
|
// Typography
|
|
2045
3440
|
fontSize: "14px",
|
|
2046
3441
|
lineHeight: 1.6,
|
|
2047
|
-
fontFamily: "
|
|
3442
|
+
fontFamily: "ui-monospace, 'SFMono-Regular', 'Menlo', 'Consolas', 'Liberation Mono', monospace",
|
|
2048
3443
|
padding: "16px",
|
|
2049
3444
|
// Mobile styles
|
|
2050
3445
|
mobile: {
|
|
@@ -2290,6 +3685,36 @@ var _OverType = class _OverType {
|
|
|
2290
3685
|
* @private
|
|
2291
3686
|
*/
|
|
2292
3687
|
handleKeydown(event) {
|
|
3688
|
+
if (event.key === "Tab") {
|
|
3689
|
+
event.preventDefault();
|
|
3690
|
+
const start = this.textarea.selectionStart;
|
|
3691
|
+
const end = this.textarea.selectionEnd;
|
|
3692
|
+
const value = this.textarea.value;
|
|
3693
|
+
if (start !== end && event.shiftKey) {
|
|
3694
|
+
const before = value.substring(0, start);
|
|
3695
|
+
const selection = value.substring(start, end);
|
|
3696
|
+
const after = value.substring(end);
|
|
3697
|
+
const lines = selection.split("\n");
|
|
3698
|
+
const outdented = lines.map((line) => line.replace(/^ /, "")).join("\n");
|
|
3699
|
+
this.textarea.value = before + outdented + after;
|
|
3700
|
+
this.textarea.selectionStart = start;
|
|
3701
|
+
this.textarea.selectionEnd = start + outdented.length;
|
|
3702
|
+
} else if (start !== end) {
|
|
3703
|
+
const before = value.substring(0, start);
|
|
3704
|
+
const selection = value.substring(start, end);
|
|
3705
|
+
const after = value.substring(end);
|
|
3706
|
+
const lines = selection.split("\n");
|
|
3707
|
+
const indented = lines.map((line) => " " + line).join("\n");
|
|
3708
|
+
this.textarea.value = before + indented + after;
|
|
3709
|
+
this.textarea.selectionStart = start;
|
|
3710
|
+
this.textarea.selectionEnd = start + indented.length;
|
|
3711
|
+
} else {
|
|
3712
|
+
this.textarea.value = value.substring(0, start) + " " + value.substring(end);
|
|
3713
|
+
this.textarea.selectionStart = this.textarea.selectionEnd = start + 2;
|
|
3714
|
+
}
|
|
3715
|
+
this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
|
|
3716
|
+
return;
|
|
3717
|
+
}
|
|
2293
3718
|
const handled = this.shortcuts.handleKeydown(event);
|
|
2294
3719
|
if (!handled && this.options.onKeydown) {
|
|
2295
3720
|
this.options.onKeydown(event, this);
|