overtype 2.0.0 → 2.0.2

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/dist/overtype.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * OverType v2.0.0
2
+ * OverType v2.0.2
3
3
  * A lightweight markdown editor library with perfect WYSIWYG alignment
4
4
  * @license MIT
5
5
  * @author Demo User
@@ -131,7 +131,7 @@ var MarkdownParser = class {
131
131
  return html.replace(/^((?: )*)-\s+\[([ xX])\]\s+(.+)$/, (match, indent, checked, content) => {
132
132
  if (isPreviewMode) {
133
133
  const isChecked = checked.toLowerCase() === "x";
134
- return `${indent}<li class="task-list"><input type="checkbox" disabled ${isChecked ? "checked" : ""}> ${content}</li>`;
134
+ return `${indent}<li class="task-list"><input type="checkbox" ${isChecked ? "checked" : ""}> ${content}</li>`;
135
135
  } else {
136
136
  return `${indent}<li class="task-list"><span class="syntax-marker">- [${checked}] </span>${content}</li>`;
137
137
  }
@@ -1865,8 +1865,8 @@ function generateStyles(options = {}) {
1865
1865
 
1866
1866
  /* Container base styles after reset */
1867
1867
  .overtype-container {
1868
- display: grid !important;
1869
- grid-template-rows: auto 1fr auto !important;
1868
+ display: flex !important;
1869
+ flex-direction: column !important;
1870
1870
  width: 100% !important;
1871
1871
  height: 100% !important;
1872
1872
  position: relative !important; /* Override reset - needed for absolute children */
@@ -1886,10 +1886,10 @@ function generateStyles(options = {}) {
1886
1886
  /* Auto-resize mode styles */
1887
1887
  .overtype-container.overtype-auto-resize {
1888
1888
  height: auto !important;
1889
- grid-template-rows: auto auto auto !important;
1890
1889
  }
1891
-
1890
+
1892
1891
  .overtype-container.overtype-auto-resize .overtype-wrapper {
1892
+ flex: 0 0 auto !important; /* Don't grow/shrink, use explicit height */
1893
1893
  height: auto !important;
1894
1894
  min-height: 60px !important;
1895
1895
  overflow: visible !important;
@@ -1898,11 +1898,10 @@ function generateStyles(options = {}) {
1898
1898
  .overtype-wrapper {
1899
1899
  position: relative !important; /* Override reset - needed for absolute children */
1900
1900
  width: 100% !important;
1901
- height: 100% !important; /* Take full height of grid cell */
1901
+ flex: 1 1 0 !important; /* Grow to fill remaining space, with flex-basis: 0 */
1902
1902
  min-height: 60px !important; /* Minimum usable height */
1903
1903
  overflow: hidden !important;
1904
1904
  background: var(--bg-secondary, #ffffff) !important;
1905
- grid-row: 2 !important; /* Always second row in grid */
1906
1905
  z-index: 1; /* Below toolbar and dropdown */
1907
1906
  }
1908
1907
 
@@ -2237,7 +2236,7 @@ function generateStyles(options = {}) {
2237
2236
 
2238
2237
  /* Stats bar */
2239
2238
 
2240
- /* Stats bar - positioned by grid, not absolute */
2239
+ /* Stats bar - positioned by flexbox */
2241
2240
  .overtype-stats {
2242
2241
  height: 40px !important;
2243
2242
  padding: 0 20px !important;
@@ -2249,7 +2248,7 @@ function generateStyles(options = {}) {
2249
2248
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
2250
2249
  font-size: 0.85rem !important;
2251
2250
  color: #666 !important;
2252
- grid-row: 3 !important; /* Always third row in grid */
2251
+ flex-shrink: 0 !important; /* Don't shrink */
2253
2252
  }
2254
2253
 
2255
2254
  /* Dark theme stats bar */
@@ -2292,7 +2291,6 @@ function generateStyles(options = {}) {
2292
2291
  -webkit-overflow-scrolling: touch !important;
2293
2292
  flex-shrink: 0 !important;
2294
2293
  height: auto !important;
2295
- grid-row: 1 !important; /* Always first row in grid */
2296
2294
  position: relative !important; /* Override reset */
2297
2295
  z-index: 100 !important; /* Ensure toolbar is above wrapper */
2298
2296
  scrollbar-width: thin; /* Thin scrollbar on Firefox */
@@ -2362,9 +2360,6 @@ function generateStyles(options = {}) {
2362
2360
  }
2363
2361
 
2364
2362
  /* Adjust wrapper when toolbar is present */
2365
- .overtype-container .overtype-toolbar + .overtype-wrapper {
2366
- }
2367
-
2368
2363
  /* Mobile toolbar adjustments */
2369
2364
  @media (max-width: 640px) {
2370
2365
  .overtype-toolbar {
@@ -2635,36 +2630,42 @@ function generateStyles(options = {}) {
2635
2630
  height: 2px !important;
2636
2631
  }
2637
2632
 
2638
- /* Link Tooltip - CSS Anchor Positioning */
2633
+ /* Link Tooltip - Base styles (all browsers) */
2634
+ .overtype-link-tooltip {
2635
+ /* Visual styles that work for both positioning methods */
2636
+ background: #333 !important;
2637
+ color: white !important;
2638
+ padding: 6px 10px !important;
2639
+ border-radius: 16px !important;
2640
+ font-size: 12px !important;
2641
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
2642
+ display: none !important;
2643
+ z-index: 10000 !important;
2644
+ cursor: pointer !important;
2645
+ box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
2646
+ max-width: 300px !important;
2647
+ white-space: nowrap !important;
2648
+ overflow: hidden !important;
2649
+ text-overflow: ellipsis !important;
2650
+
2651
+ /* Base positioning for Floating UI fallback */
2652
+ position: absolute;
2653
+ }
2654
+
2655
+ .overtype-link-tooltip.visible {
2656
+ display: flex !important;
2657
+ }
2658
+
2659
+ /* CSS Anchor Positioning (modern browsers only) */
2639
2660
  @supports (position-anchor: --x) and (position-area: center) {
2640
2661
  .overtype-link-tooltip {
2641
- position: absolute;
2662
+ /* Only anchor positioning specific properties */
2642
2663
  position-anchor: var(--target-anchor, --link-0);
2643
2664
  position-area: block-end center;
2644
2665
  margin-top: 8px !important;
2645
-
2646
- background: #333 !important;
2647
- color: white !important;
2648
- padding: 6px 10px !important;
2649
- border-radius: 16px !important;
2650
- font-size: 12px !important;
2651
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
2652
- display: none !important;
2653
- z-index: 10000 !important;
2654
- cursor: pointer !important;
2655
- box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
2656
- max-width: 300px !important;
2657
- white-space: nowrap !important;
2658
- overflow: hidden !important;
2659
- text-overflow: ellipsis !important;
2660
-
2661
2666
  position-try: most-width block-end inline-end, flip-inline, block-start center;
2662
2667
  position-visibility: anchors-visible;
2663
2668
  }
2664
-
2665
- .overtype-link-tooltip.visible {
2666
- display: flex !important;
2667
- }
2668
2669
  }
2669
2670
 
2670
2671
  ${mobileStyles}
@@ -2697,7 +2698,7 @@ var Toolbar = class {
2697
2698
  this.container.appendChild(button);
2698
2699
  }
2699
2700
  });
2700
- this.editor.wrapper.insertBefore(this.container, this.editor.wrapper.firstChild);
2701
+ this.editor.container.insertBefore(this.container, this.editor.wrapper);
2701
2702
  }
2702
2703
  /**
2703
2704
  * Create a toolbar separator
@@ -2922,9 +2923,26 @@ var LinkTooltip = class {
2922
2923
  this.currentLink = null;
2923
2924
  this.hideTimeout = null;
2924
2925
  this.visibilityChangeHandler = null;
2926
+ this.useFloatingUI = false;
2927
+ this.floatingUI = null;
2925
2928
  this.init();
2926
2929
  }
2927
- init() {
2930
+ async init() {
2931
+ const supportsAnchorPositioning = CSS.supports("position-anchor: --x") && CSS.supports("position-area: center");
2932
+ if (!supportsAnchorPositioning) {
2933
+ try {
2934
+ const importFn = new Function("url", "return import(url)");
2935
+ const { computePosition, offset, shift, flip } = await importFn(
2936
+ "https://cdn.jsdelivr.net/npm/@floating-ui/dom@1.7.4/+esm"
2937
+ );
2938
+ this.floatingUI = { computePosition, offset, shift, flip };
2939
+ this.useFloatingUI = true;
2940
+ } catch (error) {
2941
+ console.warn("Failed to load Floating UI fallback:", error);
2942
+ this.floatingUI = null;
2943
+ this.useFloatingUI = false;
2944
+ }
2945
+ }
2928
2946
  this.createTooltip();
2929
2947
  this.editor.textarea.addEventListener("selectionchange", () => this.checkCursorPosition());
2930
2948
  this.editor.textarea.addEventListener("keyup", (e) => {
@@ -2933,7 +2951,13 @@ var LinkTooltip = class {
2933
2951
  }
2934
2952
  });
2935
2953
  this.editor.textarea.addEventListener("input", () => this.hide());
2936
- this.editor.textarea.addEventListener("scroll", () => this.hide());
2954
+ this.editor.textarea.addEventListener("scroll", () => {
2955
+ if (this.useFloatingUI && this.currentLink) {
2956
+ this.showWithFloatingUI(this.currentLink);
2957
+ } else {
2958
+ this.hide();
2959
+ }
2960
+ });
2937
2961
  this.editor.textarea.addEventListener("blur", () => this.hide());
2938
2962
  this.visibilityChangeHandler = () => {
2939
2963
  if (document.hidden) {
@@ -2942,7 +2966,6 @@ var LinkTooltip = class {
2942
2966
  };
2943
2967
  document.addEventListener("visibilitychange", this.visibilityChangeHandler);
2944
2968
  this.tooltip.addEventListener("mouseenter", () => this.cancelHide());
2945
- this.tooltip.addEventListener("mouseleave", () => this.scheduleHide());
2946
2969
  }
2947
2970
  createTooltip() {
2948
2971
  this.tooltip = document.createElement("div");
@@ -3003,9 +3026,52 @@ var LinkTooltip = class {
3003
3026
  this.cancelHide();
3004
3027
  const urlSpan = this.tooltip.querySelector(".overtype-link-tooltip-url");
3005
3028
  urlSpan.textContent = linkInfo.url;
3006
- this.tooltip.style.setProperty("--target-anchor", `--link-${linkInfo.index}`);
3029
+ if (this.useFloatingUI) {
3030
+ this.showWithFloatingUI(linkInfo);
3031
+ } else {
3032
+ this.showWithAnchorPositioning(linkInfo);
3033
+ }
3007
3034
  this.tooltip.classList.add("visible");
3008
3035
  }
3036
+ showWithAnchorPositioning(linkInfo) {
3037
+ this.tooltip.style.setProperty("--target-anchor", `--link-${linkInfo.index}`);
3038
+ }
3039
+ async showWithFloatingUI(linkInfo) {
3040
+ const anchorElement = this.findAnchorElement(linkInfo.index);
3041
+ if (!anchorElement) {
3042
+ return;
3043
+ }
3044
+ const rect = anchorElement.getBoundingClientRect();
3045
+ if (rect.width === 0 || rect.height === 0) {
3046
+ return;
3047
+ }
3048
+ try {
3049
+ const { x, y } = await this.floatingUI.computePosition(
3050
+ anchorElement,
3051
+ this.tooltip,
3052
+ {
3053
+ placement: "bottom",
3054
+ middleware: [
3055
+ this.floatingUI.offset(8),
3056
+ this.floatingUI.shift({ padding: 8 }),
3057
+ this.floatingUI.flip()
3058
+ ]
3059
+ }
3060
+ );
3061
+ Object.assign(this.tooltip.style, {
3062
+ left: `${x}px`,
3063
+ top: `${y}px`,
3064
+ position: "absolute"
3065
+ });
3066
+ } catch (error) {
3067
+ console.warn("Floating UI positioning failed:", error);
3068
+ return;
3069
+ }
3070
+ }
3071
+ findAnchorElement(linkIndex) {
3072
+ const preview = this.editor.preview;
3073
+ return preview.querySelector(`a[style*="--link-${linkIndex}"]`);
3074
+ }
3009
3075
  hide() {
3010
3076
  this.tooltip.classList.remove("visible");
3011
3077
  this.currentLink = null;
@@ -3031,6 +3097,8 @@ var LinkTooltip = class {
3031
3097
  }
3032
3098
  this.tooltip = null;
3033
3099
  this.currentLink = null;
3100
+ this.floatingUI = null;
3101
+ this.useFloatingUI = false;
3034
3102
  }
3035
3103
  };
3036
3104
 
@@ -3485,22 +3553,10 @@ var _OverType = class _OverType {
3485
3553
  this._updateStats();
3486
3554
  }
3487
3555
  this.element.appendChild(this.container);
3488
- if (window.location.pathname.includes("demo.html")) {
3489
- console.log("_createDOM completed:", {
3490
- elementId: this.element.id,
3491
- autoResize: this.options.autoResize,
3492
- containerClasses: this.container.className,
3493
- hasStats: !!this.statsBar,
3494
- hasToolbar: this.options.toolbar
3495
- });
3496
- }
3497
3556
  if (this.options.autoResize) {
3498
3557
  this._setupAutoResize();
3499
3558
  } else {
3500
3559
  this.container.classList.remove("overtype-auto-resize");
3501
- if (window.location.pathname.includes("demo.html")) {
3502
- console.log("Removed auto-resize class from:", this.element.id);
3503
- }
3504
3560
  }
3505
3561
  }
3506
3562
  /**
@@ -4003,6 +4059,7 @@ var _OverType = class _OverType {
4003
4059
  */
4004
4060
  showNormalEditMode() {
4005
4061
  this.container.dataset.mode = "normal";
4062
+ this.updatePreview();
4006
4063
  requestAnimationFrame(() => {
4007
4064
  this.textarea.scrollTop = this.preview.scrollTop;
4008
4065
  this.textarea.scrollLeft = this.preview.scrollLeft;
@@ -4030,6 +4087,7 @@ var _OverType = class _OverType {
4030
4087
  */
4031
4088
  showPreviewMode() {
4032
4089
  this.container.dataset.mode = "preview";
4090
+ this.updatePreview();
4033
4091
  return this;
4034
4092
  }
4035
4093
  /**