overtype 2.1.1 → 2.2.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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * OverType v2.1.0
2
+ * OverType v2.2.0
3
3
  * A lightweight markdown editor library with perfect WYSIWYG alignment
4
4
  * @license MIT
5
5
  * @author David Miranda
@@ -102,6 +102,7 @@ var OverTypeEditor = (() => {
102
102
  static parseHeader(html) {
103
103
  return html.replace(/^(#{1,3})\s(.+)$/, (match, hashes, content) => {
104
104
  const level = hashes.length;
105
+ content = this.parseInlineElements(content);
105
106
  return `<h${level}><span class="syntax-marker">${hashes} </span>${content}</h${level}>`;
106
107
  });
107
108
  }
@@ -133,6 +134,7 @@ var OverTypeEditor = (() => {
133
134
  */
134
135
  static parseBulletList(html) {
135
136
  return html.replace(/^((?:&nbsp;)*)([-*+])\s(.+)$/, (match, indent, marker, content) => {
137
+ content = this.parseInlineElements(content);
136
138
  return `${indent}<li class="bullet-list"><span class="syntax-marker">${marker} </span>${content}</li>`;
137
139
  });
138
140
  }
@@ -144,6 +146,7 @@ var OverTypeEditor = (() => {
144
146
  */
145
147
  static parseTaskList(html, isPreviewMode = false) {
146
148
  return html.replace(/^((?:&nbsp;)*)-\s+\[([ xX])\]\s+(.+)$/, (match, indent, checked, content) => {
149
+ content = this.parseInlineElements(content);
147
150
  if (isPreviewMode) {
148
151
  const isChecked = checked.toLowerCase() === "x";
149
152
  return `${indent}<li class="task-list"><input type="checkbox" ${isChecked ? "checked" : ""}> ${content}</li>`;
@@ -159,6 +162,7 @@ var OverTypeEditor = (() => {
159
162
  */
160
163
  static parseNumberedList(html) {
161
164
  return html.replace(/^((?:&nbsp;)*)(\d+\.)\s(.+)$/, (match, indent, marker, content) => {
165
+ content = this.parseInlineElements(content);
162
166
  return `${indent}<li class="ordered-list"><span class="syntax-marker">${marker} </span>${content}</li>`;
163
167
  });
164
168
  }
@@ -380,7 +384,9 @@ var OverTypeEditor = (() => {
380
384
  html = this.parseTaskList(html, isPreviewMode);
381
385
  html = this.parseBulletList(html);
382
386
  html = this.parseNumberedList(html);
383
- html = this.parseInlineElements(html);
387
+ if (!html.includes("<li") && !html.includes("<h")) {
388
+ html = this.parseInlineElements(html);
389
+ }
384
390
  if (html.trim() === "") {
385
391
  return "<div>&nbsp;</div>";
386
392
  }
@@ -869,8 +875,10 @@ var OverTypeEditor = (() => {
869
875
  // Yale Blue - icon color
870
876
  toolbarHover: "#f5f5f5",
871
877
  // Light gray - hover background
872
- toolbarActive: "#faf0ca"
878
+ toolbarActive: "#faf0ca",
873
879
  // Lemon Chiffon - active button background
880
+ placeholder: "#999999"
881
+ // Gray - placeholder text
874
882
  }
875
883
  };
876
884
  var cave = {
@@ -933,13 +941,16 @@ var OverTypeEditor = (() => {
933
941
  // Light blue-gray - icon color
934
942
  toolbarHover: "#243546",
935
943
  // Slightly lighter charcoal - hover background
936
- toolbarActive: "#2a3f52"
944
+ toolbarActive: "#2a3f52",
937
945
  // Even lighter - active button background
946
+ placeholder: "#6a7a88"
947
+ // Muted blue-gray - placeholder text
938
948
  }
939
949
  };
940
950
  var themes = {
941
951
  solar,
942
952
  cave,
953
+ auto: solar,
943
954
  // Aliases for backward compatibility
944
955
  light: solar,
945
956
  dark: cave
@@ -951,6 +962,12 @@ var OverTypeEditor = (() => {
951
962
  }
952
963
  return theme;
953
964
  }
965
+ function resolveAutoTheme(themeName) {
966
+ if (themeName !== "auto")
967
+ return themeName;
968
+ const mq = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)");
969
+ return (mq == null ? void 0 : mq.matches) ? "cave" : "solar";
970
+ }
954
971
  function themeToCSSVars(colors) {
955
972
  const vars = [];
956
973
  for (const [key, value] of Object.entries(colors)) {
@@ -1164,17 +1181,36 @@ var OverTypeEditor = (() => {
1164
1181
  /* Prevent mobile zoom on focus */
1165
1182
  touch-action: manipulation !important;
1166
1183
 
1167
- /* Disable autofill and spellcheck */
1184
+ /* Disable autofill */
1168
1185
  autocomplete: off !important;
1169
1186
  autocorrect: off !important;
1170
1187
  autocapitalize: off !important;
1171
- spellcheck: false !important;
1172
1188
  }
1173
1189
 
1174
1190
  .overtype-wrapper .overtype-input::selection {
1175
1191
  background-color: var(--selection, rgba(244, 211, 94, 0.4));
1176
1192
  }
1177
1193
 
1194
+ /* Placeholder shim - visible when textarea is empty */
1195
+ .overtype-wrapper .overtype-placeholder {
1196
+ position: absolute !important;
1197
+ top: 0 !important;
1198
+ left: 0 !important;
1199
+ width: 100% !important;
1200
+ z-index: 0 !important;
1201
+ pointer-events: none !important;
1202
+ user-select: none !important;
1203
+ font-family: ${fontFamily} !important;
1204
+ font-size: var(--instance-font-size, ${fontSize}) !important;
1205
+ line-height: var(--instance-line-height, ${lineHeight}) !important;
1206
+ padding: var(--instance-padding, ${padding}) !important;
1207
+ box-sizing: border-box !important;
1208
+ color: var(--placeholder, #999) !important;
1209
+ overflow: hidden !important;
1210
+ white-space: nowrap !important;
1211
+ text-overflow: ellipsis !important;
1212
+ }
1213
+
1178
1214
  /* Preview layer styles */
1179
1215
  .overtype-wrapper .overtype-preview {
1180
1216
  /* Layer positioning */
@@ -1442,6 +1478,10 @@ var OverTypeEditor = (() => {
1442
1478
 
1443
1479
 
1444
1480
  /* Toolbar Styles */
1481
+ .overtype-toolbar.overtype-toolbar-hidden {
1482
+ display: none !important;
1483
+ }
1484
+
1445
1485
  .overtype-toolbar {
1446
1486
  display: flex !important;
1447
1487
  align-items: center !important;
@@ -1716,19 +1756,14 @@ var OverTypeEditor = (() => {
1716
1756
 
1717
1757
  /* Code blocks - proper pre/code styling in preview mode */
1718
1758
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block {
1719
- background: #2d2d2d !important;
1720
- color: #f8f8f2 !important;
1759
+ background: var(--code-bg, rgba(244, 211, 94, 0.4)) !important;
1760
+ color: var(--code, #0d3b66) !important;
1721
1761
  padding: 1.2em !important;
1722
1762
  border-radius: 3px !important;
1723
1763
  overflow-x: auto !important;
1724
1764
  margin: 0 !important;
1725
1765
  display: block !important;
1726
1766
  }
1727
-
1728
- /* Cave theme code block background in preview mode */
1729
- .overtype-container[data-theme="cave"][data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block {
1730
- background: #11171F !important;
1731
- }
1732
1767
 
1733
1768
  .overtype-container[data-mode="preview"] .overtype-wrapper .overtype-preview pre.code-block code {
1734
1769
  background: transparent !important;
@@ -1793,16 +1828,17 @@ var OverTypeEditor = (() => {
1793
1828
  height: 2px !important;
1794
1829
  }
1795
1830
 
1796
- /* Link Tooltip - Base styles (all browsers) */
1831
+ /* Link Tooltip */
1797
1832
  .overtype-link-tooltip {
1798
- /* Visual styles that work for both positioning methods */
1799
1833
  background: #333 !important;
1800
1834
  color: white !important;
1801
1835
  padding: 6px 10px !important;
1802
1836
  border-radius: 16px !important;
1803
1837
  font-size: 12px !important;
1804
1838
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
1805
- display: none !important;
1839
+ display: flex !important;
1840
+ visibility: hidden !important;
1841
+ pointer-events: none !important;
1806
1842
  z-index: 10000 !important;
1807
1843
  cursor: pointer !important;
1808
1844
  box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
@@ -1810,25 +1846,14 @@ var OverTypeEditor = (() => {
1810
1846
  white-space: nowrap !important;
1811
1847
  overflow: hidden !important;
1812
1848
  text-overflow: ellipsis !important;
1813
-
1814
- /* Base positioning for Floating UI fallback */
1815
- position: absolute;
1849
+ position: fixed;
1850
+ top: 0;
1851
+ left: 0;
1816
1852
  }
1817
1853
 
1818
1854
  .overtype-link-tooltip.visible {
1819
- display: flex !important;
1820
- }
1821
-
1822
- /* CSS Anchor Positioning (modern browsers only) */
1823
- @supports (position-anchor: --x) and (position-area: center) {
1824
- .overtype-link-tooltip {
1825
- /* Only anchor positioning specific properties */
1826
- position-anchor: var(--target-anchor, --link-0);
1827
- position-area: block-end center;
1828
- margin-top: 8px !important;
1829
- position-try: most-width block-end inline-end, flip-inline, block-start center;
1830
- position-visibility: anchors-visible;
1831
- }
1855
+ visibility: visible !important;
1856
+ pointer-events: auto !important;
1832
1857
  }
1833
1858
 
1834
1859
  ${mobileStyles}
@@ -2910,6 +2935,16 @@ ${blockSuffix}` : suffix;
2910
2935
  } catch (error) {
2911
2936
  }
2912
2937
  }
2938
+ show() {
2939
+ if (this.container) {
2940
+ this.container.classList.remove("overtype-toolbar-hidden");
2941
+ }
2942
+ }
2943
+ hide() {
2944
+ if (this.container) {
2945
+ this.container.classList.add("overtype-toolbar-hidden");
2946
+ }
2947
+ }
2913
2948
  /**
2914
2949
  * Destroy toolbar and cleanup
2915
2950
  */
@@ -2931,6 +2966,1203 @@ ${blockSuffix}` : suffix;
2931
2966
  }
2932
2967
  };
2933
2968
 
2969
+ // node_modules/@floating-ui/utils/dist/floating-ui.utils.mjs
2970
+ var min = Math.min;
2971
+ var max = Math.max;
2972
+ var round = Math.round;
2973
+ var createCoords = (v) => ({
2974
+ x: v,
2975
+ y: v
2976
+ });
2977
+ var oppositeSideMap = {
2978
+ left: "right",
2979
+ right: "left",
2980
+ bottom: "top",
2981
+ top: "bottom"
2982
+ };
2983
+ var oppositeAlignmentMap = {
2984
+ start: "end",
2985
+ end: "start"
2986
+ };
2987
+ function clamp(start, value, end) {
2988
+ return max(start, min(value, end));
2989
+ }
2990
+ function evaluate(value, param) {
2991
+ return typeof value === "function" ? value(param) : value;
2992
+ }
2993
+ function getSide(placement) {
2994
+ return placement.split("-")[0];
2995
+ }
2996
+ function getAlignment(placement) {
2997
+ return placement.split("-")[1];
2998
+ }
2999
+ function getOppositeAxis(axis) {
3000
+ return axis === "x" ? "y" : "x";
3001
+ }
3002
+ function getAxisLength(axis) {
3003
+ return axis === "y" ? "height" : "width";
3004
+ }
3005
+ var yAxisSides = /* @__PURE__ */ new Set(["top", "bottom"]);
3006
+ function getSideAxis(placement) {
3007
+ return yAxisSides.has(getSide(placement)) ? "y" : "x";
3008
+ }
3009
+ function getAlignmentAxis(placement) {
3010
+ return getOppositeAxis(getSideAxis(placement));
3011
+ }
3012
+ function getAlignmentSides(placement, rects, rtl) {
3013
+ if (rtl === void 0) {
3014
+ rtl = false;
3015
+ }
3016
+ const alignment = getAlignment(placement);
3017
+ const alignmentAxis = getAlignmentAxis(placement);
3018
+ const length = getAxisLength(alignmentAxis);
3019
+ let mainAlignmentSide = alignmentAxis === "x" ? alignment === (rtl ? "end" : "start") ? "right" : "left" : alignment === "start" ? "bottom" : "top";
3020
+ if (rects.reference[length] > rects.floating[length]) {
3021
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
3022
+ }
3023
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
3024
+ }
3025
+ function getExpandedPlacements(placement) {
3026
+ const oppositePlacement = getOppositePlacement(placement);
3027
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
3028
+ }
3029
+ function getOppositeAlignmentPlacement(placement) {
3030
+ return placement.replace(/start|end/g, (alignment) => oppositeAlignmentMap[alignment]);
3031
+ }
3032
+ var lrPlacement = ["left", "right"];
3033
+ var rlPlacement = ["right", "left"];
3034
+ var tbPlacement = ["top", "bottom"];
3035
+ var btPlacement = ["bottom", "top"];
3036
+ function getSideList(side, isStart, rtl) {
3037
+ switch (side) {
3038
+ case "top":
3039
+ case "bottom":
3040
+ if (rtl)
3041
+ return isStart ? rlPlacement : lrPlacement;
3042
+ return isStart ? lrPlacement : rlPlacement;
3043
+ case "left":
3044
+ case "right":
3045
+ return isStart ? tbPlacement : btPlacement;
3046
+ default:
3047
+ return [];
3048
+ }
3049
+ }
3050
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
3051
+ const alignment = getAlignment(placement);
3052
+ let list = getSideList(getSide(placement), direction === "start", rtl);
3053
+ if (alignment) {
3054
+ list = list.map((side) => side + "-" + alignment);
3055
+ if (flipAlignment) {
3056
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
3057
+ }
3058
+ }
3059
+ return list;
3060
+ }
3061
+ function getOppositePlacement(placement) {
3062
+ return placement.replace(/left|right|bottom|top/g, (side) => oppositeSideMap[side]);
3063
+ }
3064
+ function expandPaddingObject(padding) {
3065
+ return {
3066
+ top: 0,
3067
+ right: 0,
3068
+ bottom: 0,
3069
+ left: 0,
3070
+ ...padding
3071
+ };
3072
+ }
3073
+ function getPaddingObject(padding) {
3074
+ return typeof padding !== "number" ? expandPaddingObject(padding) : {
3075
+ top: padding,
3076
+ right: padding,
3077
+ bottom: padding,
3078
+ left: padding
3079
+ };
3080
+ }
3081
+ function rectToClientRect(rect) {
3082
+ const {
3083
+ x,
3084
+ y,
3085
+ width,
3086
+ height
3087
+ } = rect;
3088
+ return {
3089
+ width,
3090
+ height,
3091
+ top: y,
3092
+ left: x,
3093
+ right: x + width,
3094
+ bottom: y + height,
3095
+ x,
3096
+ y
3097
+ };
3098
+ }
3099
+
3100
+ // node_modules/@floating-ui/core/dist/floating-ui.core.mjs
3101
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
3102
+ let {
3103
+ reference,
3104
+ floating
3105
+ } = _ref;
3106
+ const sideAxis = getSideAxis(placement);
3107
+ const alignmentAxis = getAlignmentAxis(placement);
3108
+ const alignLength = getAxisLength(alignmentAxis);
3109
+ const side = getSide(placement);
3110
+ const isVertical = sideAxis === "y";
3111
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
3112
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
3113
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
3114
+ let coords;
3115
+ switch (side) {
3116
+ case "top":
3117
+ coords = {
3118
+ x: commonX,
3119
+ y: reference.y - floating.height
3120
+ };
3121
+ break;
3122
+ case "bottom":
3123
+ coords = {
3124
+ x: commonX,
3125
+ y: reference.y + reference.height
3126
+ };
3127
+ break;
3128
+ case "right":
3129
+ coords = {
3130
+ x: reference.x + reference.width,
3131
+ y: commonY
3132
+ };
3133
+ break;
3134
+ case "left":
3135
+ coords = {
3136
+ x: reference.x - floating.width,
3137
+ y: commonY
3138
+ };
3139
+ break;
3140
+ default:
3141
+ coords = {
3142
+ x: reference.x,
3143
+ y: reference.y
3144
+ };
3145
+ }
3146
+ switch (getAlignment(placement)) {
3147
+ case "start":
3148
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
3149
+ break;
3150
+ case "end":
3151
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
3152
+ break;
3153
+ }
3154
+ return coords;
3155
+ }
3156
+ async function detectOverflow(state, options) {
3157
+ var _await$platform$isEle;
3158
+ if (options === void 0) {
3159
+ options = {};
3160
+ }
3161
+ const {
3162
+ x,
3163
+ y,
3164
+ platform: platform2,
3165
+ rects,
3166
+ elements,
3167
+ strategy
3168
+ } = state;
3169
+ const {
3170
+ boundary = "clippingAncestors",
3171
+ rootBoundary = "viewport",
3172
+ elementContext = "floating",
3173
+ altBoundary = false,
3174
+ padding = 0
3175
+ } = evaluate(options, state);
3176
+ const paddingObject = getPaddingObject(padding);
3177
+ const altContext = elementContext === "floating" ? "reference" : "floating";
3178
+ const element = elements[altBoundary ? altContext : elementContext];
3179
+ const clippingClientRect = rectToClientRect(await platform2.getClippingRect({
3180
+ 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)),
3181
+ boundary,
3182
+ rootBoundary,
3183
+ strategy
3184
+ }));
3185
+ const rect = elementContext === "floating" ? {
3186
+ x,
3187
+ y,
3188
+ width: rects.floating.width,
3189
+ height: rects.floating.height
3190
+ } : rects.reference;
3191
+ const offsetParent = await (platform2.getOffsetParent == null ? void 0 : platform2.getOffsetParent(elements.floating));
3192
+ const offsetScale = await (platform2.isElement == null ? void 0 : platform2.isElement(offsetParent)) ? await (platform2.getScale == null ? void 0 : platform2.getScale(offsetParent)) || {
3193
+ x: 1,
3194
+ y: 1
3195
+ } : {
3196
+ x: 1,
3197
+ y: 1
3198
+ };
3199
+ const elementClientRect = rectToClientRect(platform2.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform2.convertOffsetParentRelativeRectToViewportRelativeRect({
3200
+ elements,
3201
+ rect,
3202
+ offsetParent,
3203
+ strategy
3204
+ }) : rect);
3205
+ return {
3206
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
3207
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
3208
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
3209
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
3210
+ };
3211
+ }
3212
+ var computePosition = async (reference, floating, config) => {
3213
+ const {
3214
+ placement = "bottom",
3215
+ strategy = "absolute",
3216
+ middleware = [],
3217
+ platform: platform2
3218
+ } = config;
3219
+ const validMiddleware = middleware.filter(Boolean);
3220
+ const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(floating));
3221
+ let rects = await platform2.getElementRects({
3222
+ reference,
3223
+ floating,
3224
+ strategy
3225
+ });
3226
+ let {
3227
+ x,
3228
+ y
3229
+ } = computeCoordsFromPlacement(rects, placement, rtl);
3230
+ let statefulPlacement = placement;
3231
+ let middlewareData = {};
3232
+ let resetCount = 0;
3233
+ for (let i = 0; i < validMiddleware.length; i++) {
3234
+ var _platform$detectOverf;
3235
+ const {
3236
+ name,
3237
+ fn
3238
+ } = validMiddleware[i];
3239
+ const {
3240
+ x: nextX,
3241
+ y: nextY,
3242
+ data,
3243
+ reset
3244
+ } = await fn({
3245
+ x,
3246
+ y,
3247
+ initialPlacement: placement,
3248
+ placement: statefulPlacement,
3249
+ strategy,
3250
+ middlewareData,
3251
+ rects,
3252
+ platform: {
3253
+ ...platform2,
3254
+ detectOverflow: (_platform$detectOverf = platform2.detectOverflow) != null ? _platform$detectOverf : detectOverflow
3255
+ },
3256
+ elements: {
3257
+ reference,
3258
+ floating
3259
+ }
3260
+ });
3261
+ x = nextX != null ? nextX : x;
3262
+ y = nextY != null ? nextY : y;
3263
+ middlewareData = {
3264
+ ...middlewareData,
3265
+ [name]: {
3266
+ ...middlewareData[name],
3267
+ ...data
3268
+ }
3269
+ };
3270
+ if (reset && resetCount <= 50) {
3271
+ resetCount++;
3272
+ if (typeof reset === "object") {
3273
+ if (reset.placement) {
3274
+ statefulPlacement = reset.placement;
3275
+ }
3276
+ if (reset.rects) {
3277
+ rects = reset.rects === true ? await platform2.getElementRects({
3278
+ reference,
3279
+ floating,
3280
+ strategy
3281
+ }) : reset.rects;
3282
+ }
3283
+ ({
3284
+ x,
3285
+ y
3286
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
3287
+ }
3288
+ i = -1;
3289
+ }
3290
+ }
3291
+ return {
3292
+ x,
3293
+ y,
3294
+ placement: statefulPlacement,
3295
+ strategy,
3296
+ middlewareData
3297
+ };
3298
+ };
3299
+ var flip = function(options) {
3300
+ if (options === void 0) {
3301
+ options = {};
3302
+ }
3303
+ return {
3304
+ name: "flip",
3305
+ options,
3306
+ async fn(state) {
3307
+ var _middlewareData$arrow, _middlewareData$flip;
3308
+ const {
3309
+ placement,
3310
+ middlewareData,
3311
+ rects,
3312
+ initialPlacement,
3313
+ platform: platform2,
3314
+ elements
3315
+ } = state;
3316
+ const {
3317
+ mainAxis: checkMainAxis = true,
3318
+ crossAxis: checkCrossAxis = true,
3319
+ fallbackPlacements: specifiedFallbackPlacements,
3320
+ fallbackStrategy = "bestFit",
3321
+ fallbackAxisSideDirection = "none",
3322
+ flipAlignment = true,
3323
+ ...detectOverflowOptions
3324
+ } = evaluate(options, state);
3325
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
3326
+ return {};
3327
+ }
3328
+ const side = getSide(placement);
3329
+ const initialSideAxis = getSideAxis(initialPlacement);
3330
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
3331
+ const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
3332
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
3333
+ const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== "none";
3334
+ if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
3335
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
3336
+ }
3337
+ const placements2 = [initialPlacement, ...fallbackPlacements];
3338
+ const overflow = await platform2.detectOverflow(state, detectOverflowOptions);
3339
+ const overflows = [];
3340
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
3341
+ if (checkMainAxis) {
3342
+ overflows.push(overflow[side]);
3343
+ }
3344
+ if (checkCrossAxis) {
3345
+ const sides2 = getAlignmentSides(placement, rects, rtl);
3346
+ overflows.push(overflow[sides2[0]], overflow[sides2[1]]);
3347
+ }
3348
+ overflowsData = [...overflowsData, {
3349
+ placement,
3350
+ overflows
3351
+ }];
3352
+ if (!overflows.every((side2) => side2 <= 0)) {
3353
+ var _middlewareData$flip2, _overflowsData$filter;
3354
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
3355
+ const nextPlacement = placements2[nextIndex];
3356
+ if (nextPlacement) {
3357
+ const ignoreCrossAxisOverflow = checkCrossAxis === "alignment" ? initialSideAxis !== getSideAxis(nextPlacement) : false;
3358
+ if (!ignoreCrossAxisOverflow || // We leave the current main axis only if every placement on that axis
3359
+ // overflows the main axis.
3360
+ overflowsData.every((d) => getSideAxis(d.placement) === initialSideAxis ? d.overflows[0] > 0 : true)) {
3361
+ return {
3362
+ data: {
3363
+ index: nextIndex,
3364
+ overflows: overflowsData
3365
+ },
3366
+ reset: {
3367
+ placement: nextPlacement
3368
+ }
3369
+ };
3370
+ }
3371
+ }
3372
+ 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;
3373
+ if (!resetPlacement) {
3374
+ switch (fallbackStrategy) {
3375
+ case "bestFit": {
3376
+ var _overflowsData$filter2;
3377
+ const placement2 = (_overflowsData$filter2 = overflowsData.filter((d) => {
3378
+ if (hasFallbackAxisSideDirection) {
3379
+ const currentSideAxis = getSideAxis(d.placement);
3380
+ return currentSideAxis === initialSideAxis || // Create a bias to the `y` side axis due to horizontal
3381
+ // reading directions favoring greater width.
3382
+ currentSideAxis === "y";
3383
+ }
3384
+ return true;
3385
+ }).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];
3386
+ if (placement2) {
3387
+ resetPlacement = placement2;
3388
+ }
3389
+ break;
3390
+ }
3391
+ case "initialPlacement":
3392
+ resetPlacement = initialPlacement;
3393
+ break;
3394
+ }
3395
+ }
3396
+ if (placement !== resetPlacement) {
3397
+ return {
3398
+ reset: {
3399
+ placement: resetPlacement
3400
+ }
3401
+ };
3402
+ }
3403
+ }
3404
+ return {};
3405
+ }
3406
+ };
3407
+ };
3408
+ var originSides = /* @__PURE__ */ new Set(["left", "top"]);
3409
+ async function convertValueToCoords(state, options) {
3410
+ const {
3411
+ placement,
3412
+ platform: platform2,
3413
+ elements
3414
+ } = state;
3415
+ const rtl = await (platform2.isRTL == null ? void 0 : platform2.isRTL(elements.floating));
3416
+ const side = getSide(placement);
3417
+ const alignment = getAlignment(placement);
3418
+ const isVertical = getSideAxis(placement) === "y";
3419
+ const mainAxisMulti = originSides.has(side) ? -1 : 1;
3420
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
3421
+ const rawValue = evaluate(options, state);
3422
+ let {
3423
+ mainAxis,
3424
+ crossAxis,
3425
+ alignmentAxis
3426
+ } = typeof rawValue === "number" ? {
3427
+ mainAxis: rawValue,
3428
+ crossAxis: 0,
3429
+ alignmentAxis: null
3430
+ } : {
3431
+ mainAxis: rawValue.mainAxis || 0,
3432
+ crossAxis: rawValue.crossAxis || 0,
3433
+ alignmentAxis: rawValue.alignmentAxis
3434
+ };
3435
+ if (alignment && typeof alignmentAxis === "number") {
3436
+ crossAxis = alignment === "end" ? alignmentAxis * -1 : alignmentAxis;
3437
+ }
3438
+ return isVertical ? {
3439
+ x: crossAxis * crossAxisMulti,
3440
+ y: mainAxis * mainAxisMulti
3441
+ } : {
3442
+ x: mainAxis * mainAxisMulti,
3443
+ y: crossAxis * crossAxisMulti
3444
+ };
3445
+ }
3446
+ var offset = function(options) {
3447
+ if (options === void 0) {
3448
+ options = 0;
3449
+ }
3450
+ return {
3451
+ name: "offset",
3452
+ options,
3453
+ async fn(state) {
3454
+ var _middlewareData$offse, _middlewareData$arrow;
3455
+ const {
3456
+ x,
3457
+ y,
3458
+ placement,
3459
+ middlewareData
3460
+ } = state;
3461
+ const diffCoords = await convertValueToCoords(state, options);
3462
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
3463
+ return {};
3464
+ }
3465
+ return {
3466
+ x: x + diffCoords.x,
3467
+ y: y + diffCoords.y,
3468
+ data: {
3469
+ ...diffCoords,
3470
+ placement
3471
+ }
3472
+ };
3473
+ }
3474
+ };
3475
+ };
3476
+ var shift = function(options) {
3477
+ if (options === void 0) {
3478
+ options = {};
3479
+ }
3480
+ return {
3481
+ name: "shift",
3482
+ options,
3483
+ async fn(state) {
3484
+ const {
3485
+ x,
3486
+ y,
3487
+ placement,
3488
+ platform: platform2
3489
+ } = state;
3490
+ const {
3491
+ mainAxis: checkMainAxis = true,
3492
+ crossAxis: checkCrossAxis = false,
3493
+ limiter = {
3494
+ fn: (_ref) => {
3495
+ let {
3496
+ x: x2,
3497
+ y: y2
3498
+ } = _ref;
3499
+ return {
3500
+ x: x2,
3501
+ y: y2
3502
+ };
3503
+ }
3504
+ },
3505
+ ...detectOverflowOptions
3506
+ } = evaluate(options, state);
3507
+ const coords = {
3508
+ x,
3509
+ y
3510
+ };
3511
+ const overflow = await platform2.detectOverflow(state, detectOverflowOptions);
3512
+ const crossAxis = getSideAxis(getSide(placement));
3513
+ const mainAxis = getOppositeAxis(crossAxis);
3514
+ let mainAxisCoord = coords[mainAxis];
3515
+ let crossAxisCoord = coords[crossAxis];
3516
+ if (checkMainAxis) {
3517
+ const minSide = mainAxis === "y" ? "top" : "left";
3518
+ const maxSide = mainAxis === "y" ? "bottom" : "right";
3519
+ const min2 = mainAxisCoord + overflow[minSide];
3520
+ const max2 = mainAxisCoord - overflow[maxSide];
3521
+ mainAxisCoord = clamp(min2, mainAxisCoord, max2);
3522
+ }
3523
+ if (checkCrossAxis) {
3524
+ const minSide = crossAxis === "y" ? "top" : "left";
3525
+ const maxSide = crossAxis === "y" ? "bottom" : "right";
3526
+ const min2 = crossAxisCoord + overflow[minSide];
3527
+ const max2 = crossAxisCoord - overflow[maxSide];
3528
+ crossAxisCoord = clamp(min2, crossAxisCoord, max2);
3529
+ }
3530
+ const limitedCoords = limiter.fn({
3531
+ ...state,
3532
+ [mainAxis]: mainAxisCoord,
3533
+ [crossAxis]: crossAxisCoord
3534
+ });
3535
+ return {
3536
+ ...limitedCoords,
3537
+ data: {
3538
+ x: limitedCoords.x - x,
3539
+ y: limitedCoords.y - y,
3540
+ enabled: {
3541
+ [mainAxis]: checkMainAxis,
3542
+ [crossAxis]: checkCrossAxis
3543
+ }
3544
+ }
3545
+ };
3546
+ }
3547
+ };
3548
+ };
3549
+
3550
+ // node_modules/@floating-ui/utils/dist/floating-ui.utils.dom.mjs
3551
+ function hasWindow() {
3552
+ return typeof window !== "undefined";
3553
+ }
3554
+ function getNodeName(node) {
3555
+ if (isNode(node)) {
3556
+ return (node.nodeName || "").toLowerCase();
3557
+ }
3558
+ return "#document";
3559
+ }
3560
+ function getWindow(node) {
3561
+ var _node$ownerDocument;
3562
+ return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
3563
+ }
3564
+ function getDocumentElement(node) {
3565
+ var _ref;
3566
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
3567
+ }
3568
+ function isNode(value) {
3569
+ if (!hasWindow()) {
3570
+ return false;
3571
+ }
3572
+ return value instanceof Node || value instanceof getWindow(value).Node;
3573
+ }
3574
+ function isElement(value) {
3575
+ if (!hasWindow()) {
3576
+ return false;
3577
+ }
3578
+ return value instanceof Element || value instanceof getWindow(value).Element;
3579
+ }
3580
+ function isHTMLElement(value) {
3581
+ if (!hasWindow()) {
3582
+ return false;
3583
+ }
3584
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
3585
+ }
3586
+ function isShadowRoot(value) {
3587
+ if (!hasWindow() || typeof ShadowRoot === "undefined") {
3588
+ return false;
3589
+ }
3590
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
3591
+ }
3592
+ var invalidOverflowDisplayValues = /* @__PURE__ */ new Set(["inline", "contents"]);
3593
+ function isOverflowElement(element) {
3594
+ const {
3595
+ overflow,
3596
+ overflowX,
3597
+ overflowY,
3598
+ display
3599
+ } = getComputedStyle2(element);
3600
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !invalidOverflowDisplayValues.has(display);
3601
+ }
3602
+ var tableElements = /* @__PURE__ */ new Set(["table", "td", "th"]);
3603
+ function isTableElement(element) {
3604
+ return tableElements.has(getNodeName(element));
3605
+ }
3606
+ var topLayerSelectors = [":popover-open", ":modal"];
3607
+ function isTopLayer(element) {
3608
+ return topLayerSelectors.some((selector) => {
3609
+ try {
3610
+ return element.matches(selector);
3611
+ } catch (_e) {
3612
+ return false;
3613
+ }
3614
+ });
3615
+ }
3616
+ var transformProperties = ["transform", "translate", "scale", "rotate", "perspective"];
3617
+ var willChangeValues = ["transform", "translate", "scale", "rotate", "perspective", "filter"];
3618
+ var containValues = ["paint", "layout", "strict", "content"];
3619
+ function isContainingBlock(elementOrCss) {
3620
+ const webkit = isWebKit();
3621
+ const css = isElement(elementOrCss) ? getComputedStyle2(elementOrCss) : elementOrCss;
3622
+ 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));
3623
+ }
3624
+ function getContainingBlock(element) {
3625
+ let currentNode = getParentNode(element);
3626
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
3627
+ if (isContainingBlock(currentNode)) {
3628
+ return currentNode;
3629
+ } else if (isTopLayer(currentNode)) {
3630
+ return null;
3631
+ }
3632
+ currentNode = getParentNode(currentNode);
3633
+ }
3634
+ return null;
3635
+ }
3636
+ function isWebKit() {
3637
+ if (typeof CSS === "undefined" || !CSS.supports)
3638
+ return false;
3639
+ return CSS.supports("-webkit-backdrop-filter", "none");
3640
+ }
3641
+ var lastTraversableNodeNames = /* @__PURE__ */ new Set(["html", "body", "#document"]);
3642
+ function isLastTraversableNode(node) {
3643
+ return lastTraversableNodeNames.has(getNodeName(node));
3644
+ }
3645
+ function getComputedStyle2(element) {
3646
+ return getWindow(element).getComputedStyle(element);
3647
+ }
3648
+ function getNodeScroll(element) {
3649
+ if (isElement(element)) {
3650
+ return {
3651
+ scrollLeft: element.scrollLeft,
3652
+ scrollTop: element.scrollTop
3653
+ };
3654
+ }
3655
+ return {
3656
+ scrollLeft: element.scrollX,
3657
+ scrollTop: element.scrollY
3658
+ };
3659
+ }
3660
+ function getParentNode(node) {
3661
+ if (getNodeName(node) === "html") {
3662
+ return node;
3663
+ }
3664
+ const result = (
3665
+ // Step into the shadow DOM of the parent of a slotted node.
3666
+ node.assignedSlot || // DOM Element detected.
3667
+ node.parentNode || // ShadowRoot detected.
3668
+ isShadowRoot(node) && node.host || // Fallback.
3669
+ getDocumentElement(node)
3670
+ );
3671
+ return isShadowRoot(result) ? result.host : result;
3672
+ }
3673
+ function getNearestOverflowAncestor(node) {
3674
+ const parentNode = getParentNode(node);
3675
+ if (isLastTraversableNode(parentNode)) {
3676
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
3677
+ }
3678
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
3679
+ return parentNode;
3680
+ }
3681
+ return getNearestOverflowAncestor(parentNode);
3682
+ }
3683
+ function getOverflowAncestors(node, list, traverseIframes) {
3684
+ var _node$ownerDocument2;
3685
+ if (list === void 0) {
3686
+ list = [];
3687
+ }
3688
+ if (traverseIframes === void 0) {
3689
+ traverseIframes = true;
3690
+ }
3691
+ const scrollableAncestor = getNearestOverflowAncestor(node);
3692
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
3693
+ const win = getWindow(scrollableAncestor);
3694
+ if (isBody) {
3695
+ const frameElement = getFrameElement(win);
3696
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
3697
+ }
3698
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
3699
+ }
3700
+ function getFrameElement(win) {
3701
+ return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
3702
+ }
3703
+
3704
+ // node_modules/@floating-ui/dom/dist/floating-ui.dom.mjs
3705
+ function getCssDimensions(element) {
3706
+ const css = getComputedStyle2(element);
3707
+ let width = parseFloat(css.width) || 0;
3708
+ let height = parseFloat(css.height) || 0;
3709
+ const hasOffset = isHTMLElement(element);
3710
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
3711
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
3712
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
3713
+ if (shouldFallback) {
3714
+ width = offsetWidth;
3715
+ height = offsetHeight;
3716
+ }
3717
+ return {
3718
+ width,
3719
+ height,
3720
+ $: shouldFallback
3721
+ };
3722
+ }
3723
+ function unwrapElement(element) {
3724
+ return !isElement(element) ? element.contextElement : element;
3725
+ }
3726
+ function getScale(element) {
3727
+ const domElement = unwrapElement(element);
3728
+ if (!isHTMLElement(domElement)) {
3729
+ return createCoords(1);
3730
+ }
3731
+ const rect = domElement.getBoundingClientRect();
3732
+ const {
3733
+ width,
3734
+ height,
3735
+ $
3736
+ } = getCssDimensions(domElement);
3737
+ let x = ($ ? round(rect.width) : rect.width) / width;
3738
+ let y = ($ ? round(rect.height) : rect.height) / height;
3739
+ if (!x || !Number.isFinite(x)) {
3740
+ x = 1;
3741
+ }
3742
+ if (!y || !Number.isFinite(y)) {
3743
+ y = 1;
3744
+ }
3745
+ return {
3746
+ x,
3747
+ y
3748
+ };
3749
+ }
3750
+ var noOffsets = /* @__PURE__ */ createCoords(0);
3751
+ function getVisualOffsets(element) {
3752
+ const win = getWindow(element);
3753
+ if (!isWebKit() || !win.visualViewport) {
3754
+ return noOffsets;
3755
+ }
3756
+ return {
3757
+ x: win.visualViewport.offsetLeft,
3758
+ y: win.visualViewport.offsetTop
3759
+ };
3760
+ }
3761
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
3762
+ if (isFixed === void 0) {
3763
+ isFixed = false;
3764
+ }
3765
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
3766
+ return false;
3767
+ }
3768
+ return isFixed;
3769
+ }
3770
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
3771
+ if (includeScale === void 0) {
3772
+ includeScale = false;
3773
+ }
3774
+ if (isFixedStrategy === void 0) {
3775
+ isFixedStrategy = false;
3776
+ }
3777
+ const clientRect = element.getBoundingClientRect();
3778
+ const domElement = unwrapElement(element);
3779
+ let scale = createCoords(1);
3780
+ if (includeScale) {
3781
+ if (offsetParent) {
3782
+ if (isElement(offsetParent)) {
3783
+ scale = getScale(offsetParent);
3784
+ }
3785
+ } else {
3786
+ scale = getScale(element);
3787
+ }
3788
+ }
3789
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
3790
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
3791
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
3792
+ let width = clientRect.width / scale.x;
3793
+ let height = clientRect.height / scale.y;
3794
+ if (domElement) {
3795
+ const win = getWindow(domElement);
3796
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
3797
+ let currentWin = win;
3798
+ let currentIFrame = getFrameElement(currentWin);
3799
+ while (currentIFrame && offsetParent && offsetWin !== currentWin) {
3800
+ const iframeScale = getScale(currentIFrame);
3801
+ const iframeRect = currentIFrame.getBoundingClientRect();
3802
+ const css = getComputedStyle2(currentIFrame);
3803
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
3804
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
3805
+ x *= iframeScale.x;
3806
+ y *= iframeScale.y;
3807
+ width *= iframeScale.x;
3808
+ height *= iframeScale.y;
3809
+ x += left;
3810
+ y += top;
3811
+ currentWin = getWindow(currentIFrame);
3812
+ currentIFrame = getFrameElement(currentWin);
3813
+ }
3814
+ }
3815
+ return rectToClientRect({
3816
+ width,
3817
+ height,
3818
+ x,
3819
+ y
3820
+ });
3821
+ }
3822
+ function getWindowScrollBarX(element, rect) {
3823
+ const leftScroll = getNodeScroll(element).scrollLeft;
3824
+ if (!rect) {
3825
+ return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
3826
+ }
3827
+ return rect.left + leftScroll;
3828
+ }
3829
+ function getHTMLOffset(documentElement, scroll) {
3830
+ const htmlRect = documentElement.getBoundingClientRect();
3831
+ const x = htmlRect.left + scroll.scrollLeft - getWindowScrollBarX(documentElement, htmlRect);
3832
+ const y = htmlRect.top + scroll.scrollTop;
3833
+ return {
3834
+ x,
3835
+ y
3836
+ };
3837
+ }
3838
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
3839
+ let {
3840
+ elements,
3841
+ rect,
3842
+ offsetParent,
3843
+ strategy
3844
+ } = _ref;
3845
+ const isFixed = strategy === "fixed";
3846
+ const documentElement = getDocumentElement(offsetParent);
3847
+ const topLayer = elements ? isTopLayer(elements.floating) : false;
3848
+ if (offsetParent === documentElement || topLayer && isFixed) {
3849
+ return rect;
3850
+ }
3851
+ let scroll = {
3852
+ scrollLeft: 0,
3853
+ scrollTop: 0
3854
+ };
3855
+ let scale = createCoords(1);
3856
+ const offsets = createCoords(0);
3857
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
3858
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
3859
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
3860
+ scroll = getNodeScroll(offsetParent);
3861
+ }
3862
+ if (isHTMLElement(offsetParent)) {
3863
+ const offsetRect = getBoundingClientRect(offsetParent);
3864
+ scale = getScale(offsetParent);
3865
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
3866
+ offsets.y = offsetRect.y + offsetParent.clientTop;
3867
+ }
3868
+ }
3869
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
3870
+ return {
3871
+ width: rect.width * scale.x,
3872
+ height: rect.height * scale.y,
3873
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
3874
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
3875
+ };
3876
+ }
3877
+ function getClientRects(element) {
3878
+ return Array.from(element.getClientRects());
3879
+ }
3880
+ function getDocumentRect(element) {
3881
+ const html = getDocumentElement(element);
3882
+ const scroll = getNodeScroll(element);
3883
+ const body = element.ownerDocument.body;
3884
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
3885
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
3886
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
3887
+ const y = -scroll.scrollTop;
3888
+ if (getComputedStyle2(body).direction === "rtl") {
3889
+ x += max(html.clientWidth, body.clientWidth) - width;
3890
+ }
3891
+ return {
3892
+ width,
3893
+ height,
3894
+ x,
3895
+ y
3896
+ };
3897
+ }
3898
+ var SCROLLBAR_MAX = 25;
3899
+ function getViewportRect(element, strategy) {
3900
+ const win = getWindow(element);
3901
+ const html = getDocumentElement(element);
3902
+ const visualViewport = win.visualViewport;
3903
+ let width = html.clientWidth;
3904
+ let height = html.clientHeight;
3905
+ let x = 0;
3906
+ let y = 0;
3907
+ if (visualViewport) {
3908
+ width = visualViewport.width;
3909
+ height = visualViewport.height;
3910
+ const visualViewportBased = isWebKit();
3911
+ if (!visualViewportBased || visualViewportBased && strategy === "fixed") {
3912
+ x = visualViewport.offsetLeft;
3913
+ y = visualViewport.offsetTop;
3914
+ }
3915
+ }
3916
+ const windowScrollbarX = getWindowScrollBarX(html);
3917
+ if (windowScrollbarX <= 0) {
3918
+ const doc = html.ownerDocument;
3919
+ const body = doc.body;
3920
+ const bodyStyles = getComputedStyle(body);
3921
+ const bodyMarginInline = doc.compatMode === "CSS1Compat" ? parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight) || 0 : 0;
3922
+ const clippingStableScrollbarWidth = Math.abs(html.clientWidth - body.clientWidth - bodyMarginInline);
3923
+ if (clippingStableScrollbarWidth <= SCROLLBAR_MAX) {
3924
+ width -= clippingStableScrollbarWidth;
3925
+ }
3926
+ } else if (windowScrollbarX <= SCROLLBAR_MAX) {
3927
+ width += windowScrollbarX;
3928
+ }
3929
+ return {
3930
+ width,
3931
+ height,
3932
+ x,
3933
+ y
3934
+ };
3935
+ }
3936
+ var absoluteOrFixed = /* @__PURE__ */ new Set(["absolute", "fixed"]);
3937
+ function getInnerBoundingClientRect(element, strategy) {
3938
+ const clientRect = getBoundingClientRect(element, true, strategy === "fixed");
3939
+ const top = clientRect.top + element.clientTop;
3940
+ const left = clientRect.left + element.clientLeft;
3941
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
3942
+ const width = element.clientWidth * scale.x;
3943
+ const height = element.clientHeight * scale.y;
3944
+ const x = left * scale.x;
3945
+ const y = top * scale.y;
3946
+ return {
3947
+ width,
3948
+ height,
3949
+ x,
3950
+ y
3951
+ };
3952
+ }
3953
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
3954
+ let rect;
3955
+ if (clippingAncestor === "viewport") {
3956
+ rect = getViewportRect(element, strategy);
3957
+ } else if (clippingAncestor === "document") {
3958
+ rect = getDocumentRect(getDocumentElement(element));
3959
+ } else if (isElement(clippingAncestor)) {
3960
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
3961
+ } else {
3962
+ const visualOffsets = getVisualOffsets(element);
3963
+ rect = {
3964
+ x: clippingAncestor.x - visualOffsets.x,
3965
+ y: clippingAncestor.y - visualOffsets.y,
3966
+ width: clippingAncestor.width,
3967
+ height: clippingAncestor.height
3968
+ };
3969
+ }
3970
+ return rectToClientRect(rect);
3971
+ }
3972
+ function hasFixedPositionAncestor(element, stopNode) {
3973
+ const parentNode = getParentNode(element);
3974
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
3975
+ return false;
3976
+ }
3977
+ return getComputedStyle2(parentNode).position === "fixed" || hasFixedPositionAncestor(parentNode, stopNode);
3978
+ }
3979
+ function getClippingElementAncestors(element, cache) {
3980
+ const cachedResult = cache.get(element);
3981
+ if (cachedResult) {
3982
+ return cachedResult;
3983
+ }
3984
+ let result = getOverflowAncestors(element, [], false).filter((el) => isElement(el) && getNodeName(el) !== "body");
3985
+ let currentContainingBlockComputedStyle = null;
3986
+ const elementIsFixed = getComputedStyle2(element).position === "fixed";
3987
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
3988
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
3989
+ const computedStyle = getComputedStyle2(currentNode);
3990
+ const currentNodeIsContaining = isContainingBlock(currentNode);
3991
+ if (!currentNodeIsContaining && computedStyle.position === "fixed") {
3992
+ currentContainingBlockComputedStyle = null;
3993
+ }
3994
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === "static" && !!currentContainingBlockComputedStyle && absoluteOrFixed.has(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
3995
+ if (shouldDropCurrentNode) {
3996
+ result = result.filter((ancestor) => ancestor !== currentNode);
3997
+ } else {
3998
+ currentContainingBlockComputedStyle = computedStyle;
3999
+ }
4000
+ currentNode = getParentNode(currentNode);
4001
+ }
4002
+ cache.set(element, result);
4003
+ return result;
4004
+ }
4005
+ function getClippingRect(_ref) {
4006
+ let {
4007
+ element,
4008
+ boundary,
4009
+ rootBoundary,
4010
+ strategy
4011
+ } = _ref;
4012
+ const elementClippingAncestors = boundary === "clippingAncestors" ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
4013
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
4014
+ const firstClippingAncestor = clippingAncestors[0];
4015
+ const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
4016
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
4017
+ accRect.top = max(rect.top, accRect.top);
4018
+ accRect.right = min(rect.right, accRect.right);
4019
+ accRect.bottom = min(rect.bottom, accRect.bottom);
4020
+ accRect.left = max(rect.left, accRect.left);
4021
+ return accRect;
4022
+ }, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
4023
+ return {
4024
+ width: clippingRect.right - clippingRect.left,
4025
+ height: clippingRect.bottom - clippingRect.top,
4026
+ x: clippingRect.left,
4027
+ y: clippingRect.top
4028
+ };
4029
+ }
4030
+ function getDimensions(element) {
4031
+ const {
4032
+ width,
4033
+ height
4034
+ } = getCssDimensions(element);
4035
+ return {
4036
+ width,
4037
+ height
4038
+ };
4039
+ }
4040
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
4041
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
4042
+ const documentElement = getDocumentElement(offsetParent);
4043
+ const isFixed = strategy === "fixed";
4044
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
4045
+ let scroll = {
4046
+ scrollLeft: 0,
4047
+ scrollTop: 0
4048
+ };
4049
+ const offsets = createCoords(0);
4050
+ function setLeftRTLScrollbarOffset() {
4051
+ offsets.x = getWindowScrollBarX(documentElement);
4052
+ }
4053
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
4054
+ if (getNodeName(offsetParent) !== "body" || isOverflowElement(documentElement)) {
4055
+ scroll = getNodeScroll(offsetParent);
4056
+ }
4057
+ if (isOffsetParentAnElement) {
4058
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
4059
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
4060
+ offsets.y = offsetRect.y + offsetParent.clientTop;
4061
+ } else if (documentElement) {
4062
+ setLeftRTLScrollbarOffset();
4063
+ }
4064
+ }
4065
+ if (isFixed && !isOffsetParentAnElement && documentElement) {
4066
+ setLeftRTLScrollbarOffset();
4067
+ }
4068
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
4069
+ const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
4070
+ const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
4071
+ return {
4072
+ x,
4073
+ y,
4074
+ width: rect.width,
4075
+ height: rect.height
4076
+ };
4077
+ }
4078
+ function isStaticPositioned(element) {
4079
+ return getComputedStyle2(element).position === "static";
4080
+ }
4081
+ function getTrueOffsetParent(element, polyfill) {
4082
+ if (!isHTMLElement(element) || getComputedStyle2(element).position === "fixed") {
4083
+ return null;
4084
+ }
4085
+ if (polyfill) {
4086
+ return polyfill(element);
4087
+ }
4088
+ let rawOffsetParent = element.offsetParent;
4089
+ if (getDocumentElement(element) === rawOffsetParent) {
4090
+ rawOffsetParent = rawOffsetParent.ownerDocument.body;
4091
+ }
4092
+ return rawOffsetParent;
4093
+ }
4094
+ function getOffsetParent(element, polyfill) {
4095
+ const win = getWindow(element);
4096
+ if (isTopLayer(element)) {
4097
+ return win;
4098
+ }
4099
+ if (!isHTMLElement(element)) {
4100
+ let svgOffsetParent = getParentNode(element);
4101
+ while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
4102
+ if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
4103
+ return svgOffsetParent;
4104
+ }
4105
+ svgOffsetParent = getParentNode(svgOffsetParent);
4106
+ }
4107
+ return win;
4108
+ }
4109
+ let offsetParent = getTrueOffsetParent(element, polyfill);
4110
+ while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
4111
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
4112
+ }
4113
+ if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
4114
+ return win;
4115
+ }
4116
+ return offsetParent || getContainingBlock(element) || win;
4117
+ }
4118
+ var getElementRects = async function(data) {
4119
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
4120
+ const getDimensionsFn = this.getDimensions;
4121
+ const floatingDimensions = await getDimensionsFn(data.floating);
4122
+ return {
4123
+ reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
4124
+ floating: {
4125
+ x: 0,
4126
+ y: 0,
4127
+ width: floatingDimensions.width,
4128
+ height: floatingDimensions.height
4129
+ }
4130
+ };
4131
+ };
4132
+ function isRTL(element) {
4133
+ return getComputedStyle2(element).direction === "rtl";
4134
+ }
4135
+ var platform = {
4136
+ convertOffsetParentRelativeRectToViewportRelativeRect,
4137
+ getDocumentElement,
4138
+ getClippingRect,
4139
+ getOffsetParent,
4140
+ getElementRects,
4141
+ getClientRects,
4142
+ getDimensions,
4143
+ getScale,
4144
+ isElement,
4145
+ isRTL
4146
+ };
4147
+ var offset2 = offset;
4148
+ var shift2 = shift;
4149
+ var flip2 = flip;
4150
+ var computePosition2 = (reference, floating, options) => {
4151
+ const cache = /* @__PURE__ */ new Map();
4152
+ const mergedOptions = {
4153
+ platform,
4154
+ ...options
4155
+ };
4156
+ const platformWithCache = {
4157
+ ...mergedOptions.platform,
4158
+ _c: cache
4159
+ };
4160
+ return computePosition(reference, floating, {
4161
+ ...mergedOptions,
4162
+ platform: platformWithCache
4163
+ });
4164
+ };
4165
+
2934
4166
  // src/link-tooltip.js
2935
4167
  var LinkTooltip = class {
2936
4168
  constructor(editor) {
@@ -2939,27 +4171,10 @@ ${blockSuffix}` : suffix;
2939
4171
  this.currentLink = null;
2940
4172
  this.hideTimeout = null;
2941
4173
  this.visibilityChangeHandler = null;
2942
- this.useFloatingUI = false;
2943
- this.floatingUI = null;
2944
4174
  this.isTooltipHovered = false;
2945
4175
  this.init();
2946
4176
  }
2947
- async init() {
2948
- const supportsAnchorPositioning = CSS.supports("position-anchor: --x") && CSS.supports("position-area: center");
2949
- if (!supportsAnchorPositioning) {
2950
- try {
2951
- const importFn = new Function("url", "return import(url)");
2952
- const { computePosition, offset, shift, flip } = await importFn(
2953
- "https://cdn.jsdelivr.net/npm/@floating-ui/dom@1.7.4/+esm"
2954
- );
2955
- this.floatingUI = { computePosition, offset, shift, flip };
2956
- this.useFloatingUI = true;
2957
- } catch (error) {
2958
- console.warn("Failed to load Floating UI fallback:", error);
2959
- this.floatingUI = null;
2960
- this.useFloatingUI = false;
2961
- }
2962
- }
4177
+ init() {
2963
4178
  this.createTooltip();
2964
4179
  this.editor.textarea.addEventListener("selectionchange", () => this.checkCursorPosition());
2965
4180
  this.editor.textarea.addEventListener("keyup", (e) => {
@@ -2969,10 +4184,8 @@ ${blockSuffix}` : suffix;
2969
4184
  });
2970
4185
  this.editor.textarea.addEventListener("input", () => this.hide());
2971
4186
  this.editor.textarea.addEventListener("scroll", () => {
2972
- if (this.useFloatingUI && this.currentLink) {
2973
- this.showWithFloatingUI(this.currentLink);
2974
- } else {
2975
- this.hide();
4187
+ if (this.currentLink) {
4188
+ this.positionTooltip(this.currentLink);
2976
4189
  }
2977
4190
  });
2978
4191
  this.editor.textarea.addEventListener("blur", () => {
@@ -3049,22 +4262,17 @@ ${blockSuffix}` : suffix;
3049
4262
  }
3050
4263
  return null;
3051
4264
  }
3052
- show(linkInfo) {
4265
+ async show(linkInfo) {
3053
4266
  this.currentLink = linkInfo;
3054
4267
  this.cancelHide();
3055
4268
  const urlSpan = this.tooltip.querySelector(".overtype-link-tooltip-url");
3056
4269
  urlSpan.textContent = linkInfo.url;
3057
- if (this.useFloatingUI) {
3058
- this.showWithFloatingUI(linkInfo);
3059
- } else {
3060
- this.showWithAnchorPositioning(linkInfo);
4270
+ await this.positionTooltip(linkInfo);
4271
+ if (this.currentLink === linkInfo) {
4272
+ this.tooltip.classList.add("visible");
3061
4273
  }
3062
- this.tooltip.classList.add("visible");
3063
- }
3064
- showWithAnchorPositioning(linkInfo) {
3065
- this.tooltip.style.setProperty("--target-anchor", `--link-${linkInfo.index}`);
3066
4274
  }
3067
- async showWithFloatingUI(linkInfo) {
4275
+ async positionTooltip(linkInfo) {
3068
4276
  const anchorElement = this.findAnchorElement(linkInfo.index);
3069
4277
  if (!anchorElement) {
3070
4278
  return;
@@ -3074,26 +4282,26 @@ ${blockSuffix}` : suffix;
3074
4282
  return;
3075
4283
  }
3076
4284
  try {
3077
- const { x, y } = await this.floatingUI.computePosition(
4285
+ const { x, y } = await computePosition2(
3078
4286
  anchorElement,
3079
4287
  this.tooltip,
3080
4288
  {
4289
+ strategy: "fixed",
3081
4290
  placement: "bottom",
3082
4291
  middleware: [
3083
- this.floatingUI.offset(8),
3084
- this.floatingUI.shift({ padding: 8 }),
3085
- this.floatingUI.flip()
4292
+ offset2(8),
4293
+ shift2({ padding: 8 }),
4294
+ flip2()
3086
4295
  ]
3087
4296
  }
3088
4297
  );
3089
4298
  Object.assign(this.tooltip.style, {
3090
4299
  left: `${x}px`,
3091
4300
  top: `${y}px`,
3092
- position: "absolute"
4301
+ position: "fixed"
3093
4302
  });
3094
4303
  } catch (error) {
3095
4304
  console.warn("Floating UI positioning failed:", error);
3096
- return;
3097
4305
  }
3098
4306
  }
3099
4307
  findAnchorElement(linkIndex) {
@@ -3126,8 +4334,6 @@ ${blockSuffix}` : suffix;
3126
4334
  }
3127
4335
  this.tooltip = null;
3128
4336
  this.currentLink = null;
3129
- this.floatingUI = null;
3130
- this.useFloatingUI = false;
3131
4337
  this.isTooltipHovered = false;
3132
4338
  }
3133
4339
  };
@@ -3189,6 +4395,11 @@ ${blockSuffix}` : suffix;
3189
4395
  <rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="3" width="3" height="3" rx="0.5"></rect>
3190
4396
  <rect stroke="currentColor" fill="none" stroke-width="1.5" x="2" y="13" width="3" height="3" rx="0.5"></rect>
3191
4397
  <polyline stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" points="2.65 9.5 3.5 10.5 5 8.5"></polyline>
4398
+ </svg>`;
4399
+ var uploadIcon = `<svg viewBox="0 0 18 18">
4400
+ <path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2.25 12.375v1.688A1.688 1.688 0 0 0 3.938 15.75h10.124a1.688 1.688 0 0 0 1.688-1.688V12.375"></path>
4401
+ <path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5.063 6.188L9 2.25l3.938 3.938"></path>
4402
+ <path stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 2.25v10.125"></path>
3192
4403
  </svg>`;
3193
4404
  var eyeIcon = `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
3194
4405
  <path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" fill="none"></path>
@@ -3313,6 +4524,33 @@ ${blockSuffix}` : suffix;
3313
4524
  editor.textarea.dispatchEvent(new Event("input", { bubbles: true }));
3314
4525
  }
3315
4526
  },
4527
+ upload: {
4528
+ name: "upload",
4529
+ actionId: "uploadFile",
4530
+ icon: uploadIcon,
4531
+ title: "Upload File",
4532
+ action: ({ editor }) => {
4533
+ var _a, _b;
4534
+ if (!((_a = editor.options.fileUpload) == null ? void 0 : _a.enabled))
4535
+ return;
4536
+ const input = document.createElement("input");
4537
+ input.type = "file";
4538
+ input.multiple = true;
4539
+ if (((_b = editor.options.fileUpload.mimeTypes) == null ? void 0 : _b.length) > 0) {
4540
+ input.accept = editor.options.fileUpload.mimeTypes.join(",");
4541
+ }
4542
+ input.onchange = () => {
4543
+ var _a2;
4544
+ if (!((_a2 = input.files) == null ? void 0 : _a2.length))
4545
+ return;
4546
+ const dt = new DataTransfer();
4547
+ for (const f of input.files)
4548
+ dt.items.add(f);
4549
+ editor._handleDataTransfer(dt);
4550
+ };
4551
+ input.click();
4552
+ }
4553
+ },
3316
4554
  viewMode: {
3317
4555
  name: "viewMode",
3318
4556
  icon: eyeIcon,
@@ -3437,6 +4675,9 @@ ${blockSuffix}` : suffix;
3437
4675
  } else {
3438
4676
  this._buildFromScratch();
3439
4677
  }
4678
+ if (this.instanceTheme === "auto") {
4679
+ this.setTheme("auto");
4680
+ }
3440
4681
  this.shortcuts = new ShortcutsManager(this);
3441
4682
  this._rebuildActionsMap();
3442
4683
  this.linkTooltip = new LinkTooltip(this);
@@ -3494,8 +4735,10 @@ ${blockSuffix}` : suffix;
3494
4735
  statsFormatter: null,
3495
4736
  smartLists: true,
3496
4737
  // Enable smart list continuation
3497
- codeHighlighter: null
4738
+ codeHighlighter: null,
3498
4739
  // Per-instance code highlighter
4740
+ spellcheck: false
4741
+ // Browser spellcheck (disabled by default)
3499
4742
  };
3500
4743
  const { theme, colors, ...cleanOptions } = options;
3501
4744
  return {
@@ -3630,8 +4873,13 @@ ${blockSuffix}` : suffix;
3630
4873
  this.preview = document.createElement("div");
3631
4874
  this.preview.className = "overtype-preview";
3632
4875
  this.preview.setAttribute("aria-hidden", "true");
4876
+ this.placeholderEl = document.createElement("div");
4877
+ this.placeholderEl.className = "overtype-placeholder";
4878
+ this.placeholderEl.setAttribute("aria-hidden", "true");
4879
+ this.placeholderEl.textContent = this.options.placeholder;
3633
4880
  this.wrapper.appendChild(this.textarea);
3634
4881
  this.wrapper.appendChild(this.preview);
4882
+ this.wrapper.appendChild(this.placeholderEl);
3635
4883
  this.container.appendChild(this.wrapper);
3636
4884
  if (this.options.showStats) {
3637
4885
  this.statsBar = document.createElement("div");
@@ -3654,7 +4902,7 @@ ${blockSuffix}` : suffix;
3654
4902
  this.textarea.setAttribute("autocomplete", "off");
3655
4903
  this.textarea.setAttribute("autocorrect", "off");
3656
4904
  this.textarea.setAttribute("autocapitalize", "off");
3657
- this.textarea.setAttribute("spellcheck", "false");
4905
+ this.textarea.setAttribute("spellcheck", String(this.options.spellcheck));
3658
4906
  this.textarea.setAttribute("data-gramm", "false");
3659
4907
  this.textarea.setAttribute("data-gramm_editor", "false");
3660
4908
  this.textarea.setAttribute("data-enable-grammarly", "false");
@@ -3664,7 +4912,17 @@ ${blockSuffix}` : suffix;
3664
4912
  * @private
3665
4913
  */
3666
4914
  _createToolbar() {
3667
- const toolbarButtons2 = this.options.toolbarButtons || defaultToolbarButtons;
4915
+ var _a;
4916
+ let toolbarButtons2 = this.options.toolbarButtons || defaultToolbarButtons;
4917
+ if (((_a = this.options.fileUpload) == null ? void 0 : _a.enabled) && !toolbarButtons2.some((b) => (b == null ? void 0 : b.name) === "upload")) {
4918
+ const viewModeIdx = toolbarButtons2.findIndex((b) => (b == null ? void 0 : b.name) === "viewMode");
4919
+ if (viewModeIdx !== -1) {
4920
+ toolbarButtons2 = [...toolbarButtons2];
4921
+ toolbarButtons2.splice(viewModeIdx, 0, toolbarButtons.separator, toolbarButtons.upload);
4922
+ } else {
4923
+ toolbarButtons2 = [...toolbarButtons2, toolbarButtons.separator, toolbarButtons.upload];
4924
+ }
4925
+ }
3668
4926
  this.toolbar = new Toolbar(this, { toolbarButtons: toolbarButtons2 });
3669
4927
  this.toolbar.create();
3670
4928
  this._toolbarSelectionListener = () => {
@@ -3700,10 +4958,14 @@ ${blockSuffix}` : suffix;
3700
4958
  * @private
3701
4959
  */
3702
4960
  _rebuildActionsMap() {
4961
+ var _a;
3703
4962
  this.actionsById = buildActionsMap(defaultToolbarButtons);
3704
4963
  if (this.options.toolbarButtons) {
3705
4964
  Object.assign(this.actionsById, buildActionsMap(this.options.toolbarButtons));
3706
4965
  }
4966
+ if ((_a = this.options.fileUpload) == null ? void 0 : _a.enabled) {
4967
+ Object.assign(this.actionsById, buildActionsMap([toolbarButtons.upload]));
4968
+ }
3707
4969
  }
3708
4970
  /**
3709
4971
  * Apply options to the editor
@@ -3716,6 +4978,8 @@ ${blockSuffix}` : suffix;
3716
4978
  if (this.options.autoResize) {
3717
4979
  if (!this.container.classList.contains("overtype-auto-resize")) {
3718
4980
  this._setupAutoResize();
4981
+ } else {
4982
+ this._updateAutoHeight();
3719
4983
  }
3720
4984
  } else {
3721
4985
  this.container.classList.remove("overtype-auto-resize");
@@ -3727,8 +4991,119 @@ ${blockSuffix}` : suffix;
3727
4991
  this.toolbar.destroy();
3728
4992
  this.toolbar = null;
3729
4993
  }
4994
+ if (this.placeholderEl) {
4995
+ this.placeholderEl.textContent = this.options.placeholder;
4996
+ }
4997
+ if (this.options.fileUpload && !this.fileUploadInitialized) {
4998
+ this._initFileUpload();
4999
+ } else if (!this.options.fileUpload && this.fileUploadInitialized) {
5000
+ this._destroyFileUpload();
5001
+ }
3730
5002
  this.updatePreview();
3731
5003
  }
5004
+ _initFileUpload() {
5005
+ const options = this.options.fileUpload;
5006
+ if (!options || !options.enabled)
5007
+ return;
5008
+ options.maxSize = options.maxSize || 10 * 1024 * 1024;
5009
+ options.mimeTypes = options.mimeTypes || [];
5010
+ options.batch = options.batch || false;
5011
+ if (!options.onInsertFile || typeof options.onInsertFile !== "function") {
5012
+ console.warn("OverType: fileUpload.onInsertFile callback is required for file uploads.");
5013
+ return;
5014
+ }
5015
+ this._fileUploadCounter = 0;
5016
+ this._boundHandleFilePaste = this._handleFilePaste.bind(this);
5017
+ this._boundHandleFileDrop = this._handleFileDrop.bind(this);
5018
+ this._boundHandleDragOver = this._handleDragOver.bind(this);
5019
+ this.textarea.addEventListener("paste", this._boundHandleFilePaste);
5020
+ this.textarea.addEventListener("drop", this._boundHandleFileDrop);
5021
+ this.textarea.addEventListener("dragover", this._boundHandleDragOver);
5022
+ this.fileUploadInitialized = true;
5023
+ }
5024
+ _handleFilePaste(e) {
5025
+ var _a, _b;
5026
+ if (!((_b = (_a = e == null ? void 0 : e.clipboardData) == null ? void 0 : _a.files) == null ? void 0 : _b.length))
5027
+ return;
5028
+ e.preventDefault();
5029
+ this._handleDataTransfer(e.clipboardData);
5030
+ }
5031
+ _handleFileDrop(e) {
5032
+ var _a, _b;
5033
+ if (!((_b = (_a = e == null ? void 0 : e.dataTransfer) == null ? void 0 : _a.files) == null ? void 0 : _b.length))
5034
+ return;
5035
+ e.preventDefault();
5036
+ this._handleDataTransfer(e.dataTransfer);
5037
+ }
5038
+ _handleDataTransfer(dataTransfer) {
5039
+ const files = [];
5040
+ for (const file of dataTransfer.files) {
5041
+ if (file.size > this.options.fileUpload.maxSize)
5042
+ continue;
5043
+ if (this.options.fileUpload.mimeTypes.length > 0 && !this.options.fileUpload.mimeTypes.includes(file.type))
5044
+ continue;
5045
+ const id = ++this._fileUploadCounter;
5046
+ const prefix = file.type.startsWith("image/") ? "!" : "";
5047
+ const placeholder = `${prefix}[Uploading ${file.name} (#${id})...]()`;
5048
+ this.insertAtCursor(`${placeholder}
5049
+ `);
5050
+ if (this.options.fileUpload.batch) {
5051
+ files.push({ file, placeholder });
5052
+ continue;
5053
+ }
5054
+ this.options.fileUpload.onInsertFile(file).then((text) => {
5055
+ this.textarea.value = this.textarea.value.replace(placeholder, text);
5056
+ this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
5057
+ }, (error) => {
5058
+ console.error("OverType: File upload failed", error);
5059
+ this.textarea.value = this.textarea.value.replace(placeholder, "[Upload failed]()");
5060
+ this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
5061
+ });
5062
+ }
5063
+ if (this.options.fileUpload.batch && files.length > 0) {
5064
+ this.options.fileUpload.onInsertFile(files.map((f) => f.file)).then((result) => {
5065
+ const texts = Array.isArray(result) ? result : [result];
5066
+ texts.forEach((text, index) => {
5067
+ this.textarea.value = this.textarea.value.replace(files[index].placeholder, text);
5068
+ });
5069
+ this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
5070
+ }, (error) => {
5071
+ console.error("OverType: File upload failed", error);
5072
+ files.forEach(({ placeholder }) => {
5073
+ this.textarea.value = this.textarea.value.replace(placeholder, "[Upload failed]()");
5074
+ });
5075
+ this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
5076
+ });
5077
+ }
5078
+ }
5079
+ _handleDragOver(e) {
5080
+ e.preventDefault();
5081
+ }
5082
+ _destroyFileUpload() {
5083
+ this.textarea.removeEventListener("paste", this._boundHandleFilePaste);
5084
+ this.textarea.removeEventListener("drop", this._boundHandleFileDrop);
5085
+ this.textarea.removeEventListener("dragover", this._boundHandleDragOver);
5086
+ this._boundHandleFilePaste = null;
5087
+ this._boundHandleFileDrop = null;
5088
+ this._boundHandleDragOver = null;
5089
+ this.fileUploadInitialized = false;
5090
+ }
5091
+ insertAtCursor(text) {
5092
+ const start = this.textarea.selectionStart;
5093
+ const end = this.textarea.selectionEnd;
5094
+ let inserted = false;
5095
+ try {
5096
+ inserted = document.execCommand("insertText", false, text);
5097
+ } catch (_) {
5098
+ }
5099
+ if (!inserted) {
5100
+ const before = this.textarea.value.slice(0, start);
5101
+ const after = this.textarea.value.slice(end);
5102
+ this.textarea.value = before + text + after;
5103
+ this.textarea.setSelectionRange(start + text.length, start + text.length);
5104
+ }
5105
+ this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
5106
+ }
3732
5107
  /**
3733
5108
  * Update preview with parsed markdown
3734
5109
  */
@@ -3738,7 +5113,10 @@ ${blockSuffix}` : suffix;
3738
5113
  const activeLine = this._getCurrentLine(text, cursorPos);
3739
5114
  const isPreviewMode = this.container.dataset.mode === "preview";
3740
5115
  const html = MarkdownParser.parse(text, activeLine, this.options.showActiveLineRaw, this.options.codeHighlighter, isPreviewMode);
3741
- this.preview.innerHTML = html || '<span style="color: #808080;">Start typing...</span>';
5116
+ this.preview.innerHTML = html;
5117
+ if (this.placeholderEl) {
5118
+ this.placeholderEl.style.display = text ? "none" : "";
5119
+ }
3742
5120
  this._applyCodeBlockBackgrounds();
3743
5121
  if (this.options.showStats && this.statsBar) {
3744
5122
  this._updateStats();
@@ -3921,7 +5299,7 @@ ${blockSuffix}` : suffix;
3921
5299
  const cursorPos = this.textarea.selectionStart;
3922
5300
  const newValue = MarkdownParser.renumberLists(value);
3923
5301
  if (newValue !== value) {
3924
- let offset = 0;
5302
+ let offset3 = 0;
3925
5303
  const oldLines = value.split("\n");
3926
5304
  const newLines = newValue.split("\n");
3927
5305
  let charCount = 0;
@@ -3929,13 +5307,13 @@ ${blockSuffix}` : suffix;
3929
5307
  if (oldLines[i] !== newLines[i]) {
3930
5308
  const diff = newLines[i].length - oldLines[i].length;
3931
5309
  if (charCount + oldLines[i].length < cursorPos) {
3932
- offset += diff;
5310
+ offset3 += diff;
3933
5311
  }
3934
5312
  }
3935
5313
  charCount += oldLines[i].length + 1;
3936
5314
  }
3937
5315
  this.textarea.value = newValue;
3938
- const newCursorPos = cursorPos + offset;
5316
+ const newCursorPos = cursorPos + offset3;
3939
5317
  this.textarea.setSelectionRange(newCursorPos, newCursorPos);
3940
5318
  this.textarea.dispatchEvent(new Event("input", { bubbles: true }));
3941
5319
  }
@@ -4067,27 +5445,61 @@ ${blockSuffix}` : suffix;
4067
5445
  this.toolbar = null;
4068
5446
  this._createToolbar();
4069
5447
  }
5448
+ if (this.fileUploadInitialized) {
5449
+ this._destroyFileUpload();
5450
+ }
5451
+ if (this.options.fileUpload) {
5452
+ this._initFileUpload();
5453
+ }
4070
5454
  this._applyOptions();
4071
5455
  this.updatePreview();
4072
5456
  }
5457
+ showToolbar() {
5458
+ if (this.toolbar) {
5459
+ this.toolbar.show();
5460
+ } else {
5461
+ this._createToolbar();
5462
+ }
5463
+ }
5464
+ hideToolbar() {
5465
+ if (this.toolbar) {
5466
+ this.toolbar.hide();
5467
+ }
5468
+ }
4073
5469
  /**
4074
5470
  * Set theme for this instance
4075
5471
  * @param {string|Object} theme - Theme name or custom theme object
4076
5472
  * @returns {this} Returns this for chaining
4077
5473
  */
4078
5474
  setTheme(theme) {
5475
+ _OverType._autoInstances.delete(this);
4079
5476
  this.instanceTheme = theme;
4080
- const themeObj = typeof theme === "string" ? getTheme(theme) : theme;
4081
- const themeName = typeof themeObj === "string" ? themeObj : themeObj.name;
4082
- if (themeName) {
4083
- this.container.setAttribute("data-theme", themeName);
5477
+ if (theme === "auto") {
5478
+ _OverType._autoInstances.add(this);
5479
+ _OverType._startAutoListener();
5480
+ this._applyResolvedTheme(resolveAutoTheme("auto"));
5481
+ } else {
5482
+ const themeObj = typeof theme === "string" ? getTheme(theme) : theme;
5483
+ const themeName = typeof themeObj === "string" ? themeObj : themeObj.name;
5484
+ if (themeName) {
5485
+ this.container.setAttribute("data-theme", themeName);
5486
+ }
5487
+ if (themeObj && themeObj.colors) {
5488
+ const cssVars = themeToCSSVars(themeObj.colors);
5489
+ this.container.style.cssText += cssVars;
5490
+ }
5491
+ this.updatePreview();
4084
5492
  }
5493
+ _OverType._stopAutoListener();
5494
+ return this;
5495
+ }
5496
+ _applyResolvedTheme(themeName) {
5497
+ const themeObj = getTheme(themeName);
5498
+ this.container.setAttribute("data-theme", themeName);
4085
5499
  if (themeObj && themeObj.colors) {
4086
- const cssVars = themeToCSSVars(themeObj.colors);
4087
- this.container.style.cssText += cssVars;
5500
+ this.container.style.cssText = themeToCSSVars(themeObj.colors);
4088
5501
  }
4089
5502
  this.updatePreview();
4090
- return this;
4091
5503
  }
4092
5504
  /**
4093
5505
  * Set instance-specific code highlighter
@@ -4241,6 +5653,11 @@ ${blockSuffix}` : suffix;
4241
5653
  * Destroy the editor instance
4242
5654
  */
4243
5655
  destroy() {
5656
+ _OverType._autoInstances.delete(this);
5657
+ _OverType._stopAutoListener();
5658
+ if (this.fileUploadInitialized) {
5659
+ this._destroyFileUpload();
5660
+ }
4244
5661
  this.element.overTypeInstance = null;
4245
5662
  _OverType.instances.delete(this.element);
4246
5663
  if (this.shortcuts) {
@@ -4283,7 +5700,7 @@ ${blockSuffix}` : suffix;
4283
5700
  options[key] = _OverType._parseDataValue(attr.value);
4284
5701
  }
4285
5702
  }
4286
- return new _OverType(el, options);
5703
+ return new _OverType(el, options)[0];
4287
5704
  });
4288
5705
  }
4289
5706
  /**
@@ -4346,23 +5763,35 @@ ${blockSuffix}` : suffix;
4346
5763
  * @param {Object} customColors - Optional color overrides
4347
5764
  */
4348
5765
  static setTheme(theme, customColors = null) {
5766
+ _OverType._globalAutoTheme = false;
5767
+ _OverType._globalAutoCustomColors = null;
5768
+ if (theme === "auto") {
5769
+ _OverType._globalAutoTheme = true;
5770
+ _OverType._globalAutoCustomColors = customColors;
5771
+ _OverType._startAutoListener();
5772
+ _OverType._applyGlobalTheme(resolveAutoTheme("auto"), customColors);
5773
+ return;
5774
+ }
5775
+ _OverType._stopAutoListener();
5776
+ _OverType._applyGlobalTheme(theme, customColors);
5777
+ }
5778
+ static _applyGlobalTheme(theme, customColors = null) {
4349
5779
  let themeObj = typeof theme === "string" ? getTheme(theme) : theme;
4350
5780
  if (customColors) {
4351
5781
  themeObj = mergeTheme(themeObj, customColors);
4352
5782
  }
4353
5783
  _OverType.currentTheme = themeObj;
4354
5784
  _OverType.injectStyles(true);
5785
+ const themeName = typeof themeObj === "string" ? themeObj : themeObj.name;
4355
5786
  document.querySelectorAll(".overtype-container").forEach((container) => {
4356
- const themeName2 = typeof themeObj === "string" ? themeObj : themeObj.name;
4357
- if (themeName2) {
4358
- container.setAttribute("data-theme", themeName2);
5787
+ if (themeName) {
5788
+ container.setAttribute("data-theme", themeName);
4359
5789
  }
4360
5790
  });
4361
5791
  document.querySelectorAll(".overtype-wrapper").forEach((wrapper) => {
4362
5792
  if (!wrapper.closest(".overtype-container")) {
4363
- const themeName2 = typeof themeObj === "string" ? themeObj : themeObj.name;
4364
- if (themeName2) {
4365
- wrapper.setAttribute("data-theme", themeName2);
5793
+ if (themeName) {
5794
+ wrapper.setAttribute("data-theme", themeName);
4366
5795
  }
4367
5796
  }
4368
5797
  const instance = wrapper._instance;
@@ -4370,7 +5799,6 @@ ${blockSuffix}` : suffix;
4370
5799
  instance.updatePreview();
4371
5800
  }
4372
5801
  });
4373
- const themeName = typeof themeObj === "string" ? themeObj : themeObj.name;
4374
5802
  document.querySelectorAll("overtype-editor").forEach((webComponent) => {
4375
5803
  if (themeName && typeof webComponent.setAttribute === "function") {
4376
5804
  webComponent.setAttribute("theme", themeName);
@@ -4380,6 +5808,30 @@ ${blockSuffix}` : suffix;
4380
5808
  }
4381
5809
  });
4382
5810
  }
5811
+ static _startAutoListener() {
5812
+ if (_OverType._autoMediaQuery)
5813
+ return;
5814
+ if (!window.matchMedia)
5815
+ return;
5816
+ _OverType._autoMediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
5817
+ _OverType._autoMediaListener = (e) => {
5818
+ const resolved = e.matches ? "cave" : "solar";
5819
+ if (_OverType._globalAutoTheme) {
5820
+ _OverType._applyGlobalTheme(resolved, _OverType._globalAutoCustomColors);
5821
+ }
5822
+ _OverType._autoInstances.forEach((inst) => inst._applyResolvedTheme(resolved));
5823
+ };
5824
+ _OverType._autoMediaQuery.addEventListener("change", _OverType._autoMediaListener);
5825
+ }
5826
+ static _stopAutoListener() {
5827
+ if (_OverType._autoInstances.size > 0 || _OverType._globalAutoTheme)
5828
+ return;
5829
+ if (!_OverType._autoMediaQuery)
5830
+ return;
5831
+ _OverType._autoMediaQuery.removeEventListener("change", _OverType._autoMediaListener);
5832
+ _OverType._autoMediaQuery = null;
5833
+ _OverType._autoMediaListener = null;
5834
+ }
4383
5835
  /**
4384
5836
  * Set global code highlighter for all OverType instances
4385
5837
  * @param {Function|null} highlighter - Function that takes (code, language) and returns highlighted HTML
@@ -4481,6 +5933,11 @@ ${blockSuffix}` : suffix;
4481
5933
  __publicField(_OverType, "stylesInjected", false);
4482
5934
  __publicField(_OverType, "globalListenersInitialized", false);
4483
5935
  __publicField(_OverType, "instanceCount", 0);
5936
+ __publicField(_OverType, "_autoMediaQuery", null);
5937
+ __publicField(_OverType, "_autoMediaListener", null);
5938
+ __publicField(_OverType, "_autoInstances", /* @__PURE__ */ new Set());
5939
+ __publicField(_OverType, "_globalAutoTheme", false);
5940
+ __publicField(_OverType, "_globalAutoCustomColors", null);
4484
5941
  var OverType = _OverType;
4485
5942
  OverType.MarkdownParser = MarkdownParser;
4486
5943
  OverType.ShortcutsManager = ShortcutsManager;
@@ -4507,7 +5964,8 @@ ${blockSuffix}` : suffix;
4507
5964
  "autofocus",
4508
5965
  "show-stats",
4509
5966
  "smart-lists",
4510
- "readonly"
5967
+ "readonly",
5968
+ "spellcheck"
4511
5969
  ];
4512
5970
  var OverTypeEditor = class extends HTMLElement {
4513
5971
  constructor() {
@@ -4690,6 +6148,7 @@ ${blockSuffix}` : suffix;
4690
6148
  autoResize: this.hasAttribute("auto-resize"),
4691
6149
  showStats: this.hasAttribute("show-stats"),
4692
6150
  smartLists: !this.hasAttribute("smart-lists") || this.getAttribute("smart-lists") !== "false",
6151
+ spellcheck: this.hasAttribute("spellcheck") && this.getAttribute("spellcheck") !== "false",
4693
6152
  onChange: this._handleChange,
4694
6153
  onKeydown: this._handleKeydown
4695
6154
  };
@@ -4745,8 +6204,14 @@ ${blockSuffix}` : suffix;
4745
6204
  }
4746
6205
  break;
4747
6206
  case "placeholder":
4748
- if (this._editor.textarea) {
4749
- this._editor.textarea.placeholder = value || "";
6207
+ if (this._editor) {
6208
+ this._editor.options.placeholder = value || "";
6209
+ if (this._editor.textarea) {
6210
+ this._editor.textarea.placeholder = value || "";
6211
+ }
6212
+ if (this._editor.placeholderEl) {
6213
+ this._editor.placeholderEl.textContent = value || "";
6214
+ }
4750
6215
  }
4751
6216
  break;
4752
6217
  case "readonly":
@@ -4796,6 +6261,15 @@ ${blockSuffix}` : suffix;
4796
6261
  this._reinitializeEditor();
4797
6262
  break;
4798
6263
  }
6264
+ case "spellcheck":
6265
+ if (this._editor) {
6266
+ const enabled = this.hasAttribute("spellcheck") && this.getAttribute("spellcheck") !== "false";
6267
+ this._editor.options.spellcheck = enabled;
6268
+ if (this._editor.textarea) {
6269
+ this._editor.textarea.setAttribute("spellcheck", String(enabled));
6270
+ }
6271
+ }
6272
+ break;
4799
6273
  }
4800
6274
  }
4801
6275
  /**
@@ -5039,6 +6513,16 @@ ${blockSuffix}` : suffix;
5039
6513
  getEditor() {
5040
6514
  return this._editor;
5041
6515
  }
6516
+ showToolbar() {
6517
+ if (this._editor) {
6518
+ this._editor.showToolbar();
6519
+ }
6520
+ }
6521
+ hideToolbar() {
6522
+ if (this._editor) {
6523
+ this._editor.hideToolbar();
6524
+ }
6525
+ }
5042
6526
  };
5043
6527
  if (!customElements.get("overtype-editor")) {
5044
6528
  customElements.define("overtype-editor", OverTypeEditor);