diff --git a/CHANGELOG.md b/CHANGELOG.md
index f718845..83df48e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -44,6 +44,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+### Added
+- Auto theme that automatically switches between solar and cave based on system color scheme preference
+- Real-time theme updates when system color scheme changes
+- `resolveAutoTheme()` and `getSystemColorScheme()` helper functions in themes.js
+- Auto theme example page demonstrating system theme detection
+
+### Changed
+- Updated TypeScript definitions to include auto theme
+- Enhanced theme switching to support media query listeners
+- Improved theme cleanup in destroy method
+
## [2.0.6] - 2025-11-19
### 🐛 Bug Fixes
diff --git a/README.md b/README.md
index 7a9aaed..e3e142d 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# OverType
-A lightweight markdown editor library with perfect WYSIWYG alignment using an invisible textarea overlay technique. Includes optional toolbar. ~95KB minified with all features.
+A lightweight markdown editor library with perfect WYSIWYG alignment using an invisible textarea overlay technique. Includes optional toolbar. ~97KB minified with all features.
## Live Examples
@@ -15,11 +15,12 @@ A lightweight markdown editor library with perfect WYSIWYG alignment using an in
## Features
- 👻 **Invisible textarea overlay** - Transparent input layer overlaid on styled preview for seamless editing
-- 🎨 **Global theming** - Solar (light) and Cave (dark) themes that apply to all instances
+- 🎨 **Global theming** - Solar (light), Cave (dark), and Auto themes that apply to all instances
+- 🌓 **System theme detection** - Auto theme adapts to system color scheme preference
- ⌨️ **Keyboard shortcuts** - Common markdown shortcuts (Cmd/Ctrl+B for bold, etc.)
- 📱 **Mobile optimized** - Responsive design with mobile-specific styles
- 🔄 **DOM persistence aware** - Recovers from existing DOM (perfect for HyperClay and similar platforms)
-- 🚀 **Lightweight** - ~95KB minified
+- 🚀 **Lightweight** - ~97KB minified
- 🎯 **Optional toolbar** - Clean, minimal toolbar with all essential formatting
- ✨ **Smart shortcuts** - Keyboard shortcuts with selection preservation
- 📝 **Smart list continuation** - GitHub-style automatic list continuation on Enter
@@ -35,7 +36,7 @@ We overlap an invisible textarea on top of styled output, giving the illusion of
| Feature | OverType | HyperMD | Milkdown | TUI Editor | EasyMDE |
|---------|----------|---------|----------|------------|---------|
-| **Size** | ~95KB | 364.02 KB | 344.51 KB | 560.99 KB | 323.69 KB |
+| **Size** | ~97KB | 364.02 KB | 344.51 KB | 560.99 KB | 323.69 KB |
| **Dependencies** | Bundled | CodeMirror | ProseMirror + plugins | Multiple libs | CodeMirror |
| **Setup** | Single file | Complex config | Build step required | Complex config | Moderate |
| **Approach** | Invisible textarea | ContentEditable | ContentEditable | ContentEditable | CodeMirror |
@@ -264,6 +265,25 @@ const [editor] = new OverType('#editor', {
});
```
+### Auto Theme
+
+Automatically switch between light and dark themes based on the system's color scheme preference:
+
+```javascript
+const [editor] = new OverType('#editor', {
+ theme: 'auto' // Automatically uses 'solar' or 'cave' based on system preference
+});
+
+// Set auto theme globally
+OverType.setTheme('auto');
+```
+
+The `auto` theme:
+- Automatically switches between `solar` (light) and `cave` (dark) themes
+- Responds to system theme changes in real-time
+- Works at both instance and global levels
+- Ideal for apps that respect user system preferences
+
### Preview & HTML Export
Generate HTML previews or export the rendered content:
@@ -418,7 +438,7 @@ new OverType(target, options)
fontFamily: 'monospace',
padding: '16px',
- // Theme - 'solar', 'cave', or custom theme object
+ // Theme - 'solar' (light), 'cave' (dark), 'auto' (system), or custom theme object
theme: 'solar',
// Custom colors (override theme colors)
diff --git a/dist/overtype-webcomponent.esm.js b/dist/overtype-webcomponent.esm.js
index 9a3574e..ac31ed1 100644
--- a/dist/overtype-webcomponent.esm.js
+++ b/dist/overtype-webcomponent.esm.js
@@ -1,5 +1,5 @@
/**
- * OverType v2.1.0
+ * OverType v2.1.1
* A lightweight markdown editor library with perfect WYSIWYG alignment
* @license MIT
* @author David Miranda
@@ -914,9 +914,16 @@ var cave = {
// Even lighter - active button background
}
};
+var auto = {
+ name: "auto",
+ // The auto theme doesn't have its own colors; it uses solar or cave dynamically
+ colors: solar.colors
+ // Default to solar colors for initial render
+};
var themes = {
solar,
cave,
+ auto,
// Aliases for backward compatibility
light: solar,
dark: cave
@@ -928,6 +935,15 @@ function getTheme(theme) {
}
return theme;
}
+var _mq = null;
+function resolveAutoTheme(themeName) {
+ if (themeName !== "auto")
+ return themeName;
+ if (!_mq && window.matchMedia) {
+ _mq = window.matchMedia("(prefers-color-scheme: dark)");
+ }
+ return (_mq == null ? void 0 : _mq.matches) ? "cave" : "solar";
+}
function themeToCSSVars(colors) {
const vars = [];
for (const [key, value] of Object.entries(colors)) {
@@ -3359,6 +3375,7 @@ function toolbarButtonsChanged(prevButtons, nextButtons) {
return false;
}
var _OverType = class _OverType {
+ // Listener for global auto theme
/**
* Constructor - Always returns an array of instances
* @param {string|Element|NodeList|Array} target - Target element(s)
@@ -3402,6 +3419,8 @@ var _OverType = class _OverType {
_init(element, options = {}) {
this.element = element;
this.instanceTheme = options.theme || null;
+ this.autoThemeMediaQuery = null;
+ this.autoThemeListener = null;
this.options = this._mergeOptions(options);
this.instanceId = ++_OverType.instanceCount;
this.initialized = false;
@@ -3414,6 +3433,9 @@ var _OverType = class _OverType {
} else {
this._buildFromScratch();
}
+ if (this.instanceTheme) {
+ this.setTheme(this.instanceTheme);
+ }
this.shortcuts = new ShortcutsManager(this);
this._rebuildActionsMap();
this.linkTooltip = new LinkTooltip(this);
@@ -4053,18 +4075,75 @@ var _OverType = class _OverType {
* @returns {this} Returns this for chaining
*/
setTheme(theme) {
+ this._cleanupAuto();
this.instanceTheme = theme;
- const themeObj = typeof theme === "string" ? getTheme(theme) : theme;
- const themeName = typeof themeObj === "string" ? themeObj : themeObj.name;
- if (themeName) {
- this.container.setAttribute("data-theme", themeName);
+ if (theme === "auto") {
+ this._setupAuto();
+ this._applyTheme(resolveAutoTheme("auto"));
+ } else {
+ const themeObj = typeof theme === "string" ? getTheme(theme) : theme;
+ const themeName = themeObj.name || theme;
+ if (themeName) {
+ this.container.setAttribute("data-theme", themeName);
+ }
+ if (themeObj == null ? void 0 : themeObj.colors) {
+ this.container.style.cssText += themeToCSSVars(themeObj.colors);
+ }
+ this.updatePreview();
}
- if (themeObj && themeObj.colors) {
- const cssVars = themeToCSSVars(themeObj.colors);
- this.container.style.cssText += cssVars;
+ return this;
+ }
+ /**
+ * Apply a resolved theme name (used by auto theme)
+ * @private
+ */
+ _applyTheme(themeName) {
+ const themeObj = getTheme(themeName);
+ this.container.setAttribute("data-theme", "auto");
+ this.container.setAttribute("data-resolved-theme", themeName);
+ if (themeObj == null ? void 0 : themeObj.colors) {
+ this.container.style.cssText += themeToCSSVars(themeObj.colors);
}
this.updatePreview();
- return this;
+ }
+ /**
+ * Setup auto theme listener for instance
+ * @private
+ */
+ _setupAuto() {
+ var _a;
+ if (!window.matchMedia)
+ return;
+ _OverType._autoInstances.add(this);
+ if (!_OverType._mq) {
+ _OverType._mq = window.matchMedia("(prefers-color-scheme: dark)");
+ _OverType._mqListener = (e) => {
+ const theme = e.matches ? "cave" : "solar";
+ _OverType._autoInstances.forEach((inst) => inst._applyTheme(theme));
+ };
+ (_a = _OverType._mq.addEventListener || _OverType._mq.addListener) == null ? void 0 : _a.call(
+ _OverType._mq,
+ "change",
+ _OverType._mqListener
+ );
+ }
+ }
+ /**
+ * Clean up auto theme listener for instance
+ * @private
+ */
+ _cleanupAuto() {
+ var _a;
+ _OverType._autoInstances.delete(this);
+ if (_OverType._autoInstances.size === 0 && _OverType._mq) {
+ (_a = _OverType._mq.removeEventListener || _OverType._mq.removeListener) == null ? void 0 : _a.call(
+ _OverType._mq,
+ "change",
+ _OverType._mqListener
+ );
+ _OverType._mq = null;
+ _OverType._mqListener = null;
+ }
}
/**
* Set instance-specific code highlighter
@@ -4218,6 +4297,7 @@ var _OverType = class _OverType {
* Destroy the editor instance
*/
destroy() {
+ this._cleanupAuto();
this.element.overTypeInstance = null;
_OverType.instances.delete(this.element);
if (this.shortcuts) {
@@ -4317,45 +4397,106 @@ var _OverType = class _OverType {
document.head.appendChild(styleEl);
_OverType.stylesInjected = true;
}
+ /**
+ * Helper to update DOM elements with theme attributes
+ * @private
+ */
+ static _updateThemeAttrs(themeName, isAuto = false) {
+ const setTheme = (el) => {
+ if (isAuto) {
+ el.setAttribute("data-theme", "auto");
+ el.setAttribute("data-resolved-theme", themeName);
+ } else {
+ el.setAttribute("data-theme", themeName);
+ }
+ };
+ document.querySelectorAll(".overtype-container").forEach(setTheme);
+ document.querySelectorAll(".overtype-wrapper").forEach((w) => {
+ var _a;
+ if (!w.closest(".overtype-container"))
+ setTheme(w);
+ (_a = w._instance) == null ? void 0 : _a.updatePreview();
+ });
+ document.querySelectorAll("overtype-editor").forEach((wc) => {
+ var _a, _b, _c;
+ (_a = wc.setAttribute) == null ? void 0 : _a.call(wc, "theme", isAuto ? "auto" : themeName);
+ if (isAuto)
+ (_b = wc.setAttribute) == null ? void 0 : _b.call(wc, "data-resolved-theme", themeName);
+ (_c = wc.refreshTheme) == null ? void 0 : _c.call(wc);
+ });
+ }
/**
* Set global theme for all OverType instances
* @param {string|Object} theme - Theme name or custom theme object
* @param {Object} customColors - Optional color overrides
*/
static setTheme(theme, customColors = null) {
- let themeObj = typeof theme === "string" ? getTheme(theme) : theme;
+ _OverType._cleanupGlobalAuto();
+ if (theme === "auto") {
+ _OverType._setupGlobalAuto();
+ _OverType._applyGlobalTheme(resolveAutoTheme("auto"), customColors, true);
+ } else {
+ let themeObj = typeof theme === "string" ? getTheme(theme) : theme;
+ if (customColors) {
+ themeObj = mergeTheme(themeObj, customColors);
+ }
+ _OverType.currentTheme = themeObj;
+ _OverType.injectStyles(true);
+ const themeName = themeObj.name || theme;
+ if (themeName) {
+ _OverType._updateThemeAttrs(themeName);
+ }
+ }
+ }
+ /**
+ * Apply a resolved theme globally (used by auto theme)
+ * @private
+ * @param {string} themeName - Resolved theme name
+ * @param {Object} customColors - Optional color overrides
+ * @param {boolean} isAuto - Whether this is an auto theme
+ */
+ static _applyGlobalTheme(themeName, customColors = null, isAuto = false) {
+ let themeObj = getTheme(themeName);
if (customColors) {
themeObj = mergeTheme(themeObj, customColors);
}
_OverType.currentTheme = themeObj;
_OverType.injectStyles(true);
- document.querySelectorAll(".overtype-container").forEach((container) => {
- const themeName2 = typeof themeObj === "string" ? themeObj : themeObj.name;
- if (themeName2) {
- container.setAttribute("data-theme", themeName2);
- }
- });
- document.querySelectorAll(".overtype-wrapper").forEach((wrapper) => {
- if (!wrapper.closest(".overtype-container")) {
- const themeName2 = typeof themeObj === "string" ? themeObj : themeObj.name;
- if (themeName2) {
- wrapper.setAttribute("data-theme", themeName2);
- }
- }
- const instance = wrapper._instance;
- if (instance) {
- instance.updatePreview();
- }
- });
- const themeName = typeof themeObj === "string" ? themeObj : themeObj.name;
- document.querySelectorAll("overtype-editor").forEach((webComponent) => {
- if (themeName && typeof webComponent.setAttribute === "function") {
- webComponent.setAttribute("theme", themeName);
- }
- if (typeof webComponent.refreshTheme === "function") {
- webComponent.refreshTheme();
- }
- });
+ _OverType._updateThemeAttrs(themeName, isAuto);
+ }
+ /**
+ * Setup global auto theme listener
+ * @private
+ */
+ static _setupGlobalAuto() {
+ var _a;
+ if (!window.matchMedia || _OverType._globalAutoMq)
+ return;
+ _OverType._globalAutoMq = window.matchMedia("(prefers-color-scheme: dark)");
+ _OverType._globalAutoListener = (e) => {
+ _OverType._applyGlobalTheme(e.matches ? "cave" : "solar", null, true);
+ };
+ (_a = _OverType._globalAutoMq.addEventListener || _OverType._globalAutoMq.addListener) == null ? void 0 : _a.call(
+ _OverType._globalAutoMq,
+ "change",
+ _OverType._globalAutoListener
+ );
+ }
+ /**
+ * Clean up global auto theme listener
+ * @private
+ */
+ static _cleanupGlobalAuto() {
+ var _a;
+ if (_OverType._globalAutoMq && _OverType._globalAutoListener) {
+ (_a = _OverType._globalAutoMq.removeEventListener || _OverType._globalAutoMq.removeListener) == null ? void 0 : _a.call(
+ _OverType._globalAutoMq,
+ "change",
+ _OverType._globalAutoListener
+ );
+ _OverType._globalAutoMq = null;
+ _OverType._globalAutoListener = null;
+ }
}
/**
* Set global code highlighter for all OverType instances
@@ -4458,6 +4599,17 @@ __publicField(_OverType, "instances", /* @__PURE__ */ new WeakMap());
__publicField(_OverType, "stylesInjected", false);
__publicField(_OverType, "globalListenersInitialized", false);
__publicField(_OverType, "instanceCount", 0);
+// Instance-level auto theme tracking (when individual instances use auto theme)
+__publicField(_OverType, "_mq", null);
+// Shared media query for instance auto themes
+__publicField(_OverType, "_mqListener", null);
+// Shared listener for instance auto themes
+__publicField(_OverType, "_autoInstances", /* @__PURE__ */ new Set());
+// Track instances using auto theme
+// Global-level auto theme tracking (when OverType.setTheme('auto') is called)
+__publicField(_OverType, "_globalAutoMq", null);
+// Media query for global auto theme
+__publicField(_OverType, "_globalAutoListener", null);
var OverType = _OverType;
OverType.MarkdownParser = MarkdownParser;
OverType.ShortcutsManager = ShortcutsManager;
diff --git a/dist/overtype-webcomponent.js b/dist/overtype-webcomponent.js
index a1e631b..8c4cb99 100644
--- a/dist/overtype-webcomponent.js
+++ b/dist/overtype-webcomponent.js
@@ -1,5 +1,5 @@
/**
- * OverType v2.1.0
+ * OverType v2.1.1
* A lightweight markdown editor library with perfect WYSIWYG alignment
* @license MIT
* @author David Miranda
@@ -937,9 +937,16 @@ var OverTypeEditor = (() => {
// Even lighter - active button background
}
};
+ var auto = {
+ name: "auto",
+ // The auto theme doesn't have its own colors; it uses solar or cave dynamically
+ colors: solar.colors
+ // Default to solar colors for initial render
+ };
var themes = {
solar,
cave,
+ auto,
// Aliases for backward compatibility
light: solar,
dark: cave
@@ -951,6 +958,15 @@ var OverTypeEditor = (() => {
}
return theme;
}
+ var _mq = null;
+ function resolveAutoTheme(themeName) {
+ if (themeName !== "auto")
+ return themeName;
+ if (!_mq && window.matchMedia) {
+ _mq = window.matchMedia("(prefers-color-scheme: dark)");
+ }
+ return (_mq == null ? void 0 : _mq.matches) ? "cave" : "solar";
+ }
function themeToCSSVars(colors) {
const vars = [];
for (const [key, value] of Object.entries(colors)) {
@@ -3382,6 +3398,7 @@ ${blockSuffix}` : suffix;
return false;
}
var _OverType = class _OverType {
+ // Listener for global auto theme
/**
* Constructor - Always returns an array of instances
* @param {string|Element|NodeList|Array} target - Target element(s)
@@ -3425,6 +3442,8 @@ ${blockSuffix}` : suffix;
_init(element, options = {}) {
this.element = element;
this.instanceTheme = options.theme || null;
+ this.autoThemeMediaQuery = null;
+ this.autoThemeListener = null;
this.options = this._mergeOptions(options);
this.instanceId = ++_OverType.instanceCount;
this.initialized = false;
@@ -3437,6 +3456,9 @@ ${blockSuffix}` : suffix;
} else {
this._buildFromScratch();
}
+ if (this.instanceTheme) {
+ this.setTheme(this.instanceTheme);
+ }
this.shortcuts = new ShortcutsManager(this);
this._rebuildActionsMap();
this.linkTooltip = new LinkTooltip(this);
@@ -4076,18 +4098,75 @@ ${blockSuffix}` : suffix;
* @returns {this} Returns this for chaining
*/
setTheme(theme) {
+ this._cleanupAuto();
this.instanceTheme = theme;
- const themeObj = typeof theme === "string" ? getTheme(theme) : theme;
- const themeName = typeof themeObj === "string" ? themeObj : themeObj.name;
- if (themeName) {
- this.container.setAttribute("data-theme", themeName);
+ if (theme === "auto") {
+ this._setupAuto();
+ this._applyTheme(resolveAutoTheme("auto"));
+ } else {
+ const themeObj = typeof theme === "string" ? getTheme(theme) : theme;
+ const themeName = themeObj.name || theme;
+ if (themeName) {
+ this.container.setAttribute("data-theme", themeName);
+ }
+ if (themeObj == null ? void 0 : themeObj.colors) {
+ this.container.style.cssText += themeToCSSVars(themeObj.colors);
+ }
+ this.updatePreview();
}
- if (themeObj && themeObj.colors) {
- const cssVars = themeToCSSVars(themeObj.colors);
- this.container.style.cssText += cssVars;
+ return this;
+ }
+ /**
+ * Apply a resolved theme name (used by auto theme)
+ * @private
+ */
+ _applyTheme(themeName) {
+ const themeObj = getTheme(themeName);
+ this.container.setAttribute("data-theme", "auto");
+ this.container.setAttribute("data-resolved-theme", themeName);
+ if (themeObj == null ? void 0 : themeObj.colors) {
+ this.container.style.cssText += themeToCSSVars(themeObj.colors);
}
this.updatePreview();
- return this;
+ }
+ /**
+ * Setup auto theme listener for instance
+ * @private
+ */
+ _setupAuto() {
+ var _a;
+ if (!window.matchMedia)
+ return;
+ _OverType._autoInstances.add(this);
+ if (!_OverType._mq) {
+ _OverType._mq = window.matchMedia("(prefers-color-scheme: dark)");
+ _OverType._mqListener = (e) => {
+ const theme = e.matches ? "cave" : "solar";
+ _OverType._autoInstances.forEach((inst) => inst._applyTheme(theme));
+ };
+ (_a = _OverType._mq.addEventListener || _OverType._mq.addListener) == null ? void 0 : _a.call(
+ _OverType._mq,
+ "change",
+ _OverType._mqListener
+ );
+ }
+ }
+ /**
+ * Clean up auto theme listener for instance
+ * @private
+ */
+ _cleanupAuto() {
+ var _a;
+ _OverType._autoInstances.delete(this);
+ if (_OverType._autoInstances.size === 0 && _OverType._mq) {
+ (_a = _OverType._mq.removeEventListener || _OverType._mq.removeListener) == null ? void 0 : _a.call(
+ _OverType._mq,
+ "change",
+ _OverType._mqListener
+ );
+ _OverType._mq = null;
+ _OverType._mqListener = null;
+ }
}
/**
* Set instance-specific code highlighter
@@ -4241,6 +4320,7 @@ ${blockSuffix}` : suffix;
* Destroy the editor instance
*/
destroy() {
+ this._cleanupAuto();
this.element.overTypeInstance = null;
_OverType.instances.delete(this.element);
if (this.shortcuts) {
@@ -4340,45 +4420,106 @@ ${blockSuffix}` : suffix;
document.head.appendChild(styleEl);
_OverType.stylesInjected = true;
}
+ /**
+ * Helper to update DOM elements with theme attributes
+ * @private
+ */
+ static _updateThemeAttrs(themeName, isAuto = false) {
+ const setTheme = (el) => {
+ if (isAuto) {
+ el.setAttribute("data-theme", "auto");
+ el.setAttribute("data-resolved-theme", themeName);
+ } else {
+ el.setAttribute("data-theme", themeName);
+ }
+ };
+ document.querySelectorAll(".overtype-container").forEach(setTheme);
+ document.querySelectorAll(".overtype-wrapper").forEach((w) => {
+ var _a;
+ if (!w.closest(".overtype-container"))
+ setTheme(w);
+ (_a = w._instance) == null ? void 0 : _a.updatePreview();
+ });
+ document.querySelectorAll("overtype-editor").forEach((wc) => {
+ var _a, _b, _c;
+ (_a = wc.setAttribute) == null ? void 0 : _a.call(wc, "theme", isAuto ? "auto" : themeName);
+ if (isAuto)
+ (_b = wc.setAttribute) == null ? void 0 : _b.call(wc, "data-resolved-theme", themeName);
+ (_c = wc.refreshTheme) == null ? void 0 : _c.call(wc);
+ });
+ }
/**
* Set global theme for all OverType instances
* @param {string|Object} theme - Theme name or custom theme object
* @param {Object} customColors - Optional color overrides
*/
static setTheme(theme, customColors = null) {
- let themeObj = typeof theme === "string" ? getTheme(theme) : theme;
+ _OverType._cleanupGlobalAuto();
+ if (theme === "auto") {
+ _OverType._setupGlobalAuto();
+ _OverType._applyGlobalTheme(resolveAutoTheme("auto"), customColors, true);
+ } else {
+ let themeObj = typeof theme === "string" ? getTheme(theme) : theme;
+ if (customColors) {
+ themeObj = mergeTheme(themeObj, customColors);
+ }
+ _OverType.currentTheme = themeObj;
+ _OverType.injectStyles(true);
+ const themeName = themeObj.name || theme;
+ if (themeName) {
+ _OverType._updateThemeAttrs(themeName);
+ }
+ }
+ }
+ /**
+ * Apply a resolved theme globally (used by auto theme)
+ * @private
+ * @param {string} themeName - Resolved theme name
+ * @param {Object} customColors - Optional color overrides
+ * @param {boolean} isAuto - Whether this is an auto theme
+ */
+ static _applyGlobalTheme(themeName, customColors = null, isAuto = false) {
+ let themeObj = getTheme(themeName);
if (customColors) {
themeObj = mergeTheme(themeObj, customColors);
}
_OverType.currentTheme = themeObj;
_OverType.injectStyles(true);
- document.querySelectorAll(".overtype-container").forEach((container) => {
- const themeName2 = typeof themeObj === "string" ? themeObj : themeObj.name;
- if (themeName2) {
- container.setAttribute("data-theme", themeName2);
- }
- });
- document.querySelectorAll(".overtype-wrapper").forEach((wrapper) => {
- if (!wrapper.closest(".overtype-container")) {
- const themeName2 = typeof themeObj === "string" ? themeObj : themeObj.name;
- if (themeName2) {
- wrapper.setAttribute("data-theme", themeName2);
- }
- }
- const instance = wrapper._instance;
- if (instance) {
- instance.updatePreview();
- }
- });
- const themeName = typeof themeObj === "string" ? themeObj : themeObj.name;
- document.querySelectorAll("overtype-editor").forEach((webComponent) => {
- if (themeName && typeof webComponent.setAttribute === "function") {
- webComponent.setAttribute("theme", themeName);
- }
- if (typeof webComponent.refreshTheme === "function") {
- webComponent.refreshTheme();
- }
- });
+ _OverType._updateThemeAttrs(themeName, isAuto);
+ }
+ /**
+ * Setup global auto theme listener
+ * @private
+ */
+ static _setupGlobalAuto() {
+ var _a;
+ if (!window.matchMedia || _OverType._globalAutoMq)
+ return;
+ _OverType._globalAutoMq = window.matchMedia("(prefers-color-scheme: dark)");
+ _OverType._globalAutoListener = (e) => {
+ _OverType._applyGlobalTheme(e.matches ? "cave" : "solar", null, true);
+ };
+ (_a = _OverType._globalAutoMq.addEventListener || _OverType._globalAutoMq.addListener) == null ? void 0 : _a.call(
+ _OverType._globalAutoMq,
+ "change",
+ _OverType._globalAutoListener
+ );
+ }
+ /**
+ * Clean up global auto theme listener
+ * @private
+ */
+ static _cleanupGlobalAuto() {
+ var _a;
+ if (_OverType._globalAutoMq && _OverType._globalAutoListener) {
+ (_a = _OverType._globalAutoMq.removeEventListener || _OverType._globalAutoMq.removeListener) == null ? void 0 : _a.call(
+ _OverType._globalAutoMq,
+ "change",
+ _OverType._globalAutoListener
+ );
+ _OverType._globalAutoMq = null;
+ _OverType._globalAutoListener = null;
+ }
}
/**
* Set global code highlighter for all OverType instances
@@ -4481,6 +4622,17 @@ ${blockSuffix}` : suffix;
__publicField(_OverType, "stylesInjected", false);
__publicField(_OverType, "globalListenersInitialized", false);
__publicField(_OverType, "instanceCount", 0);
+ // Instance-level auto theme tracking (when individual instances use auto theme)
+ __publicField(_OverType, "_mq", null);
+ // Shared media query for instance auto themes
+ __publicField(_OverType, "_mqListener", null);
+ // Shared listener for instance auto themes
+ __publicField(_OverType, "_autoInstances", /* @__PURE__ */ new Set());
+ // Track instances using auto theme
+ // Global-level auto theme tracking (when OverType.setTheme('auto') is called)
+ __publicField(_OverType, "_globalAutoMq", null);
+ // Media query for global auto theme
+ __publicField(_OverType, "_globalAutoListener", null);
var OverType = _OverType;
OverType.MarkdownParser = MarkdownParser;
OverType.ShortcutsManager = ShortcutsManager;
diff --git a/dist/overtype-webcomponent.min.js b/dist/overtype-webcomponent.min.js
index f7b24ef..b34a4ba 100644
--- a/dist/overtype-webcomponent.min.js
+++ b/dist/overtype-webcomponent.min.js
@@ -1,19 +1,19 @@
/**
- * OverType v2.1.0
+ * OverType v2.1.1
* A lightweight markdown editor library with perfect WYSIWYG alignment
* @license MIT
* @author David Miranda
* https://github.com/panphora/overtype
*/
-var OverTypeEditor=(()=>{var j=Object.defineProperty;var Fe=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var Ve=Object.prototype.hasOwnProperty;var Ue=(n,e,t)=>e in n?j(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var De=(n,e)=>{for(var t in e)j(n,t,{get:e[t],enumerable:!0})},qe=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of Re(e))!Ve.call(n,o)&&o!==t&&j(n,o,{get:()=>e[o],enumerable:!(i=Fe(e,o))||i.enumerable});return n};var We=n=>qe(j({},"__esModule",{value:!0}),n);var E=(n,e,t)=>(Ue(n,typeof e!="symbol"?e+"":e,t),t);var ct={};De(ct,{default:()=>lt});var L=class{static resetLinkIndex(){this.linkIndex=0}static setCodeHighlighter(e){this.codeHighlighter=e}static setCustomSyntax(e){this.customSyntax=e}static applyCustomSyntax(e){return this.customSyntax?this.customSyntax(e):e}static escapeHtml(e){let t={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,i=>t[i])}static preserveIndentation(e,t){let o=t.match(/^(\s*)/)[1].replace(/ /g," ");return e.replace(/^\s*/,o)}static parseHeader(e){return e.replace(/^(#{1,3})\s(.+)$/,(t,i,o)=>{let r=i.length;return`${i} ${o} `})}static parseHorizontalRule(e){return e.match(/^(-{3,}|\*{3,}|_{3,})$/)?`
${e}
`:null}static parseBlockquote(e){return e.replace(/^> (.+)$/,(t,i)=>`> ${i} `)}static parseBulletList(e){return e.replace(/^((?: )*)([-*+])\s(.+)$/,(t,i,o,r)=>`${i}${o} ${r} `)}static parseTaskList(e,t=!1){return e.replace(/^((?: )*)-\s+\[([ xX])\]\s+(.+)$/,(i,o,r,s)=>{if(t){let a=r.toLowerCase()==="x";return`${o} ${s} `}else return`${o}- [${r}] ${s} `})}static parseNumberedList(e){return e.replace(/^((?: )*)(\d+\.)\s(.+)$/,(t,i,o,r)=>`${i}${o} ${r} `)}static parseCodeBlock(e){return/^`{3}[^`]*$/.test(e)?`${e}
`:null}static parseBold(e){return e=e.replace(/\*\*(.+?)\*\*/g,'** $1** '),e=e.replace(/__(.+?)__/g,'__ $1__ '),e}static parseItalic(e){return e=e.replace(new RegExp("(?])\\*(?!\\*)(.+?)(?* $1* '),e=e.replace(new RegExp("(?<=^|\\s)_(?!_)(.+?)(?_ $1_ '),e}static parseStrikethrough(e){return e=e.replace(new RegExp("(?~~ $1~~ '),e=e.replace(new RegExp("(?~ $1~ '),e}static parseInlineCode(e){return e.replace(new RegExp("(?$1 $2$3 ')}static sanitizeUrl(e){let t=e.trim(),i=t.toLowerCase(),r=["http://","https://","mailto:","ftp://","ftps://"].some(a=>i.startsWith(a)),s=t.startsWith("/")||t.startsWith("#")||t.startsWith("?")||t.startsWith(".")||!t.includes(":")&&!t.includes("//");return r||s?e:"#"}static parseLinks(e){return e.replace(/\[(.+?)\]\((.+?)\)/g,(t,i,o)=>{let r=`--link-${this.linkIndex++}`;return`[ ${i}](${o}) `})}static identifyAndProtectSanctuaries(e){let t=new Map,i=0,o=e,r=[],s=/\[([^\]]+)\]\(([^)]+)\)/g,a;for(;(a=s.exec(e))!==null;){let h=a.index+a[0].indexOf("](")+2,u=h+a[2].length;r.push({start:h,end:u})}let c=new RegExp("(?p>=f.start&&h<=f.end)||l.push({match:d[0],index:d.index,openTicks:d[1],content:d[2],closeTicks:d[3]})}return l.sort((p,h)=>h.index-p.index),l.forEach(p=>{let h=`\uE000${i++}\uE001`;t.set(h,{type:"code",original:p.match,openTicks:p.openTicks,content:p.content,closeTicks:p.closeTicks}),o=o.substring(0,p.index)+h+o.substring(p.index+p.match.length)}),o=o.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(p,h,u)=>{let f=`\uE000${i++}\uE001`;return t.set(f,{type:"link",original:p,linkText:h,url:u}),f}),{protectedText:o,sanctuaries:t}}static restoreAndTransformSanctuaries(e,t){return Array.from(t.keys()).sort((o,r)=>{let s=e.indexOf(o),a=e.indexOf(r);return s-a}).forEach(o=>{let r=t.get(o),s;if(r.type==="code")s=`${r.openTicks} ${r.content}${r.closeTicks} `;else if(r.type==="link"){let a=r.linkText;t.forEach((l,p)=>{if(a.includes(p)&&l.type==="code"){let h=`${l.openTicks} ${l.content}${l.closeTicks} `;a=a.replace(p,h)}}),a=this.parseStrikethrough(a),a=this.parseBold(a),a=this.parseItalic(a);let c=`--link-${this.linkIndex++}`;s=`[ ${a}](${r.url}) `}e=e.replace(o,s)}),e}static parseInlineElements(e){let{protectedText:t,sanctuaries:i}=this.identifyAndProtectSanctuaries(e),o=t;return o=this.parseStrikethrough(o),o=this.parseBold(o),o=this.parseItalic(o),o=this.restoreAndTransformSanctuaries(o,i),o}static parseLine(e,t=!1){let i=this.escapeHtml(e);i=this.preserveIndentation(i,e);let o=this.parseHorizontalRule(i);if(o)return o;let r=this.parseCodeBlock(i);return r||(i=this.parseHeader(i),i=this.parseBlockquote(i),i=this.parseTaskList(i,t),i=this.parseBulletList(i),i=this.parseNumberedList(i),i=this.parseInlineElements(i),i.trim()===""?"
":`${i}
`)}static parse(e,t=-1,i=!1,o,r=!1){this.resetLinkIndex();let s=e.split(`
-`),a=!1,d=s.map((l,p)=>{if(i&&p===t)return`${this.escapeHtml(l)||" "}
`;if(/^```[^`]*$/.test(l))return a=!a,this.applyCustomSyntax(this.parseLine(l,r));if(a){let u=this.escapeHtml(l);return`${this.preserveIndentation(u,l)||" "}
`}return this.applyCustomSyntax(this.parseLine(l,r))}).join("");return this.postProcessHTML(d,o)}static postProcessHTML(e,t){if(typeof document>"u"||!document)return this.postProcessHTMLManual(e,t);let i=document.createElement("div");i.innerHTML=e;let o=null,r=null,s=null,a=!1,c=Array.from(i.children);for(let d=0;d0&&(s._codeContent+=`
-`);let f=l.textContent.replace(/\u00A0/g," ");s._codeContent+=f,u.textContent.length>0&&(u.textContent+=`
-`),u.textContent+=f,l.remove();continue}let h=null;if(l.tagName==="DIV"&&(h=l.querySelector("li")),h){let u=h.classList.contains("bullet-list"),f=h.classList.contains("ordered-list");if(!u&&!f){o=null,r=null;continue}let m=u?"ul":"ol";(!o||r!==m)&&(o=document.createElement(m),i.insertBefore(o,l),r=m);let g=[];for(let v of l.childNodes)if(v.nodeType===3&&v.textContent.match(/^\u00A0+$/))g.push(v.cloneNode(!0));else if(v===h)break;g.forEach(v=>{h.insertBefore(v,h.firstChild)}),o.appendChild(h),l.remove()}else o=null,r=null}return i.innerHTML}static postProcessHTMLManual(e,t){let i=e;i=i.replace(/((?:(?: )*
.*?<\/li><\/div>\s*)+)/gs,r=>{let s=r.match(/(?: )*
.*?<\/li><\/div>/gs)||[];return s.length>0?""+s.map(c=>{let d=c.match(/((?: )*)
.*?<\/li>/);if(d&&l){let p=d[1];return l[0].replace(/ /,` ${p}`)}return l?l[0]:""}).filter(Boolean).join("")+"":r}),i=i.replace(/((?:(?: )*
.*?<\/li><\/div>\s*)+)/gs,r=>{let s=r.match(/(?: )*
.*?<\/li><\/div>/gs)||[];return s.length>0?""+s.map(c=>{let d=c.match(/((?: )*)
.*?<\/li>/);if(d&&l){let p=d[1];return l[0].replace(/ /,` ${p}`)}return l?l[0]:""}).filter(Boolean).join("")+"":r});let o=/(```[^<]*)<\/span><\/div>(.*?)(```)<\/span><\/div>/gs;return i=i.replace(o,(r,s,a,c)=>{let l=(a.match(/(.*?)<\/div>/gs)||[]).map(g=>g.replace(/
(.*?)<\/div>/s,"$1").replace(/ /g," ")).join(`
-`),p=s.slice(3).trim(),h=p?` class="language-${p}"`:"",u=l,f=t||this.codeHighlighter;if(f)try{let g=l.replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),v=f(g,p);v&&typeof v.then=="function"?console.warn("Async highlighters are not supported in Node.js (non-DOM) context. Use synchronous highlighters for server-side rendering."):v&&typeof v=="string"&&v.trim()&&(u=v)}catch(g){console.warn("Code highlighting failed:",g)}let m=`
${s}
`;return m+=`
${u}`,m+=`
${c}
`,m}),i}static getListContext(e,t){let i=e.split(`
-`),o=0,r=0,s=0;for(let h=0;h
=t){r=h,s=o;break}o+=u+1}let a=i[r],c=s+a.length,d=a.match(this.LIST_PATTERNS.checkbox);if(d)return{inList:!0,listType:"checkbox",indent:d[1],marker:"-",checked:d[2]==="x",content:d[3],lineStart:s,lineEnd:c,markerEndPos:s+d[1].length+d[2].length+5};let l=a.match(this.LIST_PATTERNS.bullet);if(l)return{inList:!0,listType:"bullet",indent:l[1],marker:l[2],content:l[3],lineStart:s,lineEnd:c,markerEndPos:s+l[1].length+l[2].length+1};let p=a.match(this.LIST_PATTERNS.numbered);return p?{inList:!0,listType:"numbered",indent:p[1],marker:parseInt(p[2]),content:p[3],lineStart:s,lineEnd:c,markerEndPos:s+p[1].length+p[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:a,lineStart:s,lineEnd:c,markerEndPos:s}}static createNewListItem(e){switch(e.listType){case"bullet":return`${e.indent}${e.marker} `;case"numbered":return`${e.indent}${e.marker+1}. `;case"checkbox":return`${e.indent}- [ ] `;default:return""}}static renumberLists(e){let t=e.split(`
-`),i=new Map,o=!1;return t.map(s=>{let a=s.match(this.LIST_PATTERNS.numbered);if(a){let c=a[1],d=c.length,l=a[3];o||i.clear();let p=(i.get(d)||0)+1;i.set(d,p);for(let[h]of i)h>d&&i.delete(h);return o=!0,`${c}${p}. ${l}`}else return(s.trim()===""||!s.match(/^\s/))&&(o=!1,i.clear()),s}).join(`
-`)}};E(L,"linkIndex",0),E(L,"codeHighlighter",null),E(L,"customSyntax",null),E(L,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var z=class{constructor(e){this.editor=e}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let o=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(o="toggleBold");break;case"i":e.shiftKey||(o="toggleItalic");break;case"k":e.shiftKey||(o="insertLink");break;case"7":e.shiftKey&&(o="toggleNumberedList");break;case"8":e.shiftKey&&(o="toggleBulletList");break}return o?(e.preventDefault(),this.editor.performAction(o,e),!0):!1}destroy(){}};var M={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",textPrimary:"#0d3b66",textSecondary:"#5a7a9b",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",del:"#ee964b",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",syntax:"#999999",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",rawLine:"#5a7a9b",border:"#e0e0e0",hoverBg:"#f0f0f0",primary:"#0d3b66",toolbarBg:"#ffffff",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca"}},Y={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",textPrimary:"#c5dde8",textSecondary:"#9fcfec",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",del:"#f6ae2d",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",syntax:"#7a8c98",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",rawLine:"#9fcfec",border:"#2a3f52",hoverBg:"#243546",primary:"#9fcfec",toolbarBg:"#1D2D3E",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52"}},ee={solar:M,cave:Y,light:M,dark:Y};function T(n){return typeof n=="string"?{...ee[n]||ee.solar,name:n}:n}function B(n){let e=[];for(let[t,i]of Object.entries(n)){let o=t.replace(/([A-Z])/g,"-$1").toLowerCase();e.push(`--${o}: ${i};`)}return e.join(`
-`)}function te(n,e={}){return{...n,colors:{...n.colors,...e}}}function F(n={}){let{fontSize:e="14px",lineHeight:t=1.6,fontFamily:i='"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:o="20px",theme:r=null,mobile:s={}}=n,a=Object.keys(s).length>0?`
+var OverTypeEditor=(()=>{var F=Object.defineProperty;var Ve=Object.getOwnPropertyDescriptor;var qe=Object.getOwnPropertyNames;var Ue=Object.prototype.hasOwnProperty;var De=(n,e,t)=>e in n?F(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var We=(n,e)=>{for(var t in e)F(n,t,{get:e[t],enumerable:!0})},Ke=(n,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of qe(e))!Ue.call(n,o)&&o!==t&&F(n,o,{get:()=>e[o],enumerable:!(i=Ve(e,o))||i.enumerable});return n};var Ge=n=>Ke(F({},"__esModule",{value:!0}),n);var E=(n,e,t)=>(De(n,typeof e!="symbol"?e+"":e,t),t);var ht={};We(ht,{default:()=>dt});var S=class{static resetLinkIndex(){this.linkIndex=0}static setCodeHighlighter(e){this.codeHighlighter=e}static setCustomSyntax(e){this.customSyntax=e}static applyCustomSyntax(e){return this.customSyntax?this.customSyntax(e):e}static escapeHtml(e){let t={"&":"&","<":"<",">":">",'"':""","'":"'"};return e.replace(/[&<>"']/g,i=>t[i])}static preserveIndentation(e,t){let o=t.match(/^(\s*)/)[1].replace(/ /g," ");return e.replace(/^\s*/,o)}static parseHeader(e){return e.replace(/^(#{1,3})\s(.+)$/,(t,i,o)=>{let r=i.length;return`${i} ${o} `})}static parseHorizontalRule(e){return e.match(/^(-{3,}|\*{3,}|_{3,})$/)?`${e}
`:null}static parseBlockquote(e){return e.replace(/^> (.+)$/,(t,i)=>`> ${i} `)}static parseBulletList(e){return e.replace(/^((?: )*)([-*+])\s(.+)$/,(t,i,o,r)=>`${i}${o} ${r} `)}static parseTaskList(e,t=!1){return e.replace(/^((?: )*)-\s+\[([ xX])\]\s+(.+)$/,(i,o,r,s)=>{if(t){let a=r.toLowerCase()==="x";return`${o} ${s} `}else return`${o}- [${r}] ${s} `})}static parseNumberedList(e){return e.replace(/^((?: )*)(\d+\.)\s(.+)$/,(t,i,o,r)=>`${i}${o} ${r} `)}static parseCodeBlock(e){return/^`{3}[^`]*$/.test(e)?`${e}
`:null}static parseBold(e){return e=e.replace(/\*\*(.+?)\*\*/g,'** $1** '),e=e.replace(/__(.+?)__/g,'__ $1__ '),e}static parseItalic(e){return e=e.replace(new RegExp("(?])\\*(?!\\*)(.+?)(?* $1* '),e=e.replace(new RegExp("(?<=^|\\s)_(?!_)(.+?)(?_ $1_ '),e}static parseStrikethrough(e){return e=e.replace(new RegExp("(?~~ $1~~ '),e=e.replace(new RegExp("(?~ $1~ '),e}static parseInlineCode(e){return e.replace(new RegExp("(?$1 $2$3 ')}static sanitizeUrl(e){let t=e.trim(),i=t.toLowerCase(),r=["http://","https://","mailto:","ftp://","ftps://"].some(a=>i.startsWith(a)),s=t.startsWith("/")||t.startsWith("#")||t.startsWith("?")||t.startsWith(".")||!t.includes(":")&&!t.includes("//");return r||s?e:"#"}static parseLinks(e){return e.replace(/\[(.+?)\]\((.+?)\)/g,(t,i,o)=>{let r=`--link-${this.linkIndex++}`;return`[ ${i}](${o}) `})}static identifyAndProtectSanctuaries(e){let t=new Map,i=0,o=e,r=[],s=/\[([^\]]+)\]\(([^)]+)\)/g,a;for(;(a=s.exec(e))!==null;){let u=a.index+a[0].indexOf("](")+2,m=u+a[2].length;r.push({start:u,end:m})}let c=new RegExp("(?p>=g.start&&u<=g.end)||l.push({match:d[0],index:d.index,openTicks:d[1],content:d[2],closeTicks:d[3]})}return l.sort((p,u)=>u.index-p.index),l.forEach(p=>{let u=`\uE000${i++}\uE001`;t.set(u,{type:"code",original:p.match,openTicks:p.openTicks,content:p.content,closeTicks:p.closeTicks}),o=o.substring(0,p.index)+u+o.substring(p.index+p.match.length)}),o=o.replace(/\[([^\]]+)\]\(([^)]+)\)/g,(p,u,m)=>{let g=`\uE000${i++}\uE001`;return t.set(g,{type:"link",original:p,linkText:u,url:m}),g}),{protectedText:o,sanctuaries:t}}static restoreAndTransformSanctuaries(e,t){return Array.from(t.keys()).sort((o,r)=>{let s=e.indexOf(o),a=e.indexOf(r);return s-a}).forEach(o=>{let r=t.get(o),s;if(r.type==="code")s=`${r.openTicks} ${r.content}${r.closeTicks} `;else if(r.type==="link"){let a=r.linkText;t.forEach((l,p)=>{if(a.includes(p)&&l.type==="code"){let u=`${l.openTicks} ${l.content}${l.closeTicks} `;a=a.replace(p,u)}}),a=this.parseStrikethrough(a),a=this.parseBold(a),a=this.parseItalic(a);let c=`--link-${this.linkIndex++}`;s=`[ ${a}](${r.url}) `}e=e.replace(o,s)}),e}static parseInlineElements(e){let{protectedText:t,sanctuaries:i}=this.identifyAndProtectSanctuaries(e),o=t;return o=this.parseStrikethrough(o),o=this.parseBold(o),o=this.parseItalic(o),o=this.restoreAndTransformSanctuaries(o,i),o}static parseLine(e,t=!1){let i=this.escapeHtml(e);i=this.preserveIndentation(i,e);let o=this.parseHorizontalRule(i);if(o)return o;let r=this.parseCodeBlock(i);return r||(i=this.parseHeader(i),i=this.parseBlockquote(i),i=this.parseTaskList(i,t),i=this.parseBulletList(i),i=this.parseNumberedList(i),i=this.parseInlineElements(i),i.trim()===""?"
":`${i}
`)}static parse(e,t=-1,i=!1,o,r=!1){this.resetLinkIndex();let s=e.split(`
+`),a=!1,d=s.map((l,p)=>{if(i&&p===t)return`${this.escapeHtml(l)||" "}
`;if(/^```[^`]*$/.test(l))return a=!a,this.applyCustomSyntax(this.parseLine(l,r));if(a){let m=this.escapeHtml(l);return`${this.preserveIndentation(m,l)||" "}
`}return this.applyCustomSyntax(this.parseLine(l,r))}).join("");return this.postProcessHTML(d,o)}static postProcessHTML(e,t){if(typeof document>"u"||!document)return this.postProcessHTMLManual(e,t);let i=document.createElement("div");i.innerHTML=e;let o=null,r=null,s=null,a=!1,c=Array.from(i.children);for(let d=0;d0&&(s._codeContent+=`
+`);let g=l.textContent.replace(/\u00A0/g," ");s._codeContent+=g,m.textContent.length>0&&(m.textContent+=`
+`),m.textContent+=g,l.remove();continue}let u=null;if(l.tagName==="DIV"&&(u=l.querySelector("li")),u){let m=u.classList.contains("bullet-list"),g=u.classList.contains("ordered-list");if(!m&&!g){o=null,r=null;continue}let f=m?"ul":"ol";(!o||r!==f)&&(o=document.createElement(f),i.insertBefore(o,l),r=f);let v=[];for(let y of l.childNodes)if(y.nodeType===3&&y.textContent.match(/^\u00A0+$/))v.push(y.cloneNode(!0));else if(y===u)break;v.forEach(y=>{u.insertBefore(y,u.firstChild)}),o.appendChild(u),l.remove()}else o=null,r=null}return i.innerHTML}static postProcessHTMLManual(e,t){let i=e;i=i.replace(/((?:(?: )*
.*?<\/li><\/div>\s*)+)/gs,r=>{let s=r.match(/(?: )*
.*?<\/li><\/div>/gs)||[];return s.length>0?""+s.map(c=>{let d=c.match(/((?: )*)
.*?<\/li>/);if(d&&l){let p=d[1];return l[0].replace(/ /,` ${p}`)}return l?l[0]:""}).filter(Boolean).join("")+"":r}),i=i.replace(/((?:(?: )*
.*?<\/li><\/div>\s*)+)/gs,r=>{let s=r.match(/(?: )*
.*?<\/li><\/div>/gs)||[];return s.length>0?""+s.map(c=>{let d=c.match(/((?: )*)
.*?<\/li>/);if(d&&l){let p=d[1];return l[0].replace(/ /,` ${p}`)}return l?l[0]:""}).filter(Boolean).join("")+"":r});let o=/(```[^<]*)<\/span><\/div>(.*?)(```)<\/span><\/div>/gs;return i=i.replace(o,(r,s,a,c)=>{let l=(a.match(/(.*?)<\/div>/gs)||[]).map(v=>v.replace(/
(.*?)<\/div>/s,"$1").replace(/ /g," ")).join(`
+`),p=s.slice(3).trim(),u=p?` class="language-${p}"`:"",m=l,g=t||this.codeHighlighter;if(g)try{let v=l.replace(/"/g,'"').replace(/'/g,"'").replace(/</g,"<").replace(/>/g,">").replace(/&/g,"&"),y=g(v,p);y&&typeof y.then=="function"?console.warn("Async highlighters are not supported in Node.js (non-DOM) context. Use synchronous highlighters for server-side rendering."):y&&typeof y=="string"&&y.trim()&&(m=y)}catch(v){console.warn("Code highlighting failed:",v)}let f=`
${s}
`;return f+=`
${m}`,f+=`
${c}
`,f}),i}static getListContext(e,t){let i=e.split(`
+`),o=0,r=0,s=0;for(let u=0;u
=t){r=u,s=o;break}o+=m+1}let a=i[r],c=s+a.length,d=a.match(this.LIST_PATTERNS.checkbox);if(d)return{inList:!0,listType:"checkbox",indent:d[1],marker:"-",checked:d[2]==="x",content:d[3],lineStart:s,lineEnd:c,markerEndPos:s+d[1].length+d[2].length+5};let l=a.match(this.LIST_PATTERNS.bullet);if(l)return{inList:!0,listType:"bullet",indent:l[1],marker:l[2],content:l[3],lineStart:s,lineEnd:c,markerEndPos:s+l[1].length+l[2].length+1};let p=a.match(this.LIST_PATTERNS.numbered);return p?{inList:!0,listType:"numbered",indent:p[1],marker:parseInt(p[2]),content:p[3],lineStart:s,lineEnd:c,markerEndPos:s+p[1].length+p[2].length+2}:{inList:!1,listType:null,indent:"",marker:null,content:a,lineStart:s,lineEnd:c,markerEndPos:s}}static createNewListItem(e){switch(e.listType){case"bullet":return`${e.indent}${e.marker} `;case"numbered":return`${e.indent}${e.marker+1}. `;case"checkbox":return`${e.indent}- [ ] `;default:return""}}static renumberLists(e){let t=e.split(`
+`),i=new Map,o=!1;return t.map(s=>{let a=s.match(this.LIST_PATTERNS.numbered);if(a){let c=a[1],d=c.length,l=a[3];o||i.clear();let p=(i.get(d)||0)+1;i.set(d,p);for(let[u]of i)u>d&&i.delete(u);return o=!0,`${c}${p}. ${l}`}else return(s.trim()===""||!s.match(/^\s/))&&(o=!1,i.clear()),s}).join(`
+`)}};E(S,"linkIndex",0),E(S,"codeHighlighter",null),E(S,"customSyntax",null),E(S,"LIST_PATTERNS",{bullet:/^(\s*)([-*+])\s+(.*)$/,numbered:/^(\s*)(\d+)\.\s+(.*)$/,checkbox:/^(\s*)-\s+\[([ x])\]\s+(.*)$/});var z=class{constructor(e){this.editor=e}handleKeydown(e){if(!(navigator.platform.toLowerCase().includes("mac")?e.metaKey:e.ctrlKey))return!1;let o=null;switch(e.key.toLowerCase()){case"b":e.shiftKey||(o="toggleBold");break;case"i":e.shiftKey||(o="toggleItalic");break;case"k":e.shiftKey||(o="insertLink");break;case"7":e.shiftKey&&(o="toggleNumberedList");break;case"8":e.shiftKey&&(o="toggleBulletList");break}return o?(e.preventDefault(),this.editor.performAction(o,e),!0):!1}destroy(){}};var A={name:"solar",colors:{bgPrimary:"#faf0ca",bgSecondary:"#ffffff",text:"#0d3b66",textPrimary:"#0d3b66",textSecondary:"#5a7a9b",h1:"#f95738",h2:"#ee964b",h3:"#3d8a51",strong:"#ee964b",em:"#f95738",del:"#ee964b",link:"#0d3b66",code:"#0d3b66",codeBg:"rgba(244, 211, 94, 0.4)",blockquote:"#5a7a9b",hr:"#5a7a9b",syntaxMarker:"rgba(13, 59, 102, 0.52)",syntax:"#999999",cursor:"#f95738",selection:"rgba(244, 211, 94, 0.4)",listMarker:"#ee964b",rawLine:"#5a7a9b",border:"#e0e0e0",hoverBg:"#f0f0f0",primary:"#0d3b66",toolbarBg:"#ffffff",toolbarIcon:"#0d3b66",toolbarHover:"#f5f5f5",toolbarActive:"#faf0ca"}},ie={name:"cave",colors:{bgPrimary:"#141E26",bgSecondary:"#1D2D3E",text:"#c5dde8",textPrimary:"#c5dde8",textSecondary:"#9fcfec",h1:"#d4a5ff",h2:"#f6ae2d",h3:"#9fcfec",strong:"#f6ae2d",em:"#9fcfec",del:"#f6ae2d",link:"#9fcfec",code:"#c5dde8",codeBg:"#1a232b",blockquote:"#9fcfec",hr:"#c5dde8",syntaxMarker:"rgba(159, 207, 236, 0.73)",syntax:"#7a8c98",cursor:"#f26419",selection:"rgba(51, 101, 138, 0.4)",listMarker:"#f6ae2d",rawLine:"#9fcfec",border:"#2a3f52",hoverBg:"#243546",primary:"#9fcfec",toolbarBg:"#1D2D3E",toolbarIcon:"#c5dde8",toolbarHover:"#243546",toolbarActive:"#2a3f52"}},Ze={name:"auto",colors:A.colors},ne={solar:A,cave:ie,auto:Ze,light:A,dark:ie};function _(n){return typeof n=="string"?{...ne[n]||ne.solar,name:n}:n}var N=null;function Z(n){return n!=="auto"?n:(!N&&window.matchMedia&&(N=window.matchMedia("(prefers-color-scheme: dark)")),N!=null&&N.matches?"cave":"solar")}function B(n){let e=[];for(let[t,i]of Object.entries(n)){let o=t.replace(/([A-Z])/g,"-$1").toLowerCase();e.push(`--${o}: ${i};`)}return e.join(`
+`)}function J(n,e={}){return{...n,colors:{...n.colors,...e}}}function R(n={}){let{fontSize:e="14px",lineHeight:t=1.6,fontFamily:i='"SF Mono", SFMono-Regular, Menlo, Monaco, "Cascadia Code", Consolas, "Roboto Mono", "Noto Sans Mono", "Droid Sans Mono", "Ubuntu Mono", "DejaVu Sans Mono", "Liberation Mono", "Courier New", Courier, monospace',padding:o="20px",theme:r=null,mobile:s={}}=n,a=Object.keys(s).length>0?`
@media (max-width: 640px) {
.overtype-wrapper .overtype-input,
.overtype-wrapper .overtype-preview {
@@ -861,28 +861,28 @@ var OverTypeEditor=(()=>{var j=Object.defineProperty;var Fe=Object.getOwnPropert
}
${a}
- `}var Ke=Object.defineProperty,ie=Object.getOwnPropertySymbols,Ze=Object.prototype.hasOwnProperty,Je=Object.prototype.propertyIsEnumerable,ne=(n,e,t)=>e in n?Ke(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,oe=(n,e)=>{for(var t in e||(e={}))Ze.call(e,t)&&ne(n,t,e[t]);if(ie)for(var t of ie(e))Je.call(e,t)&&ne(n,t,e[t]);return n},_={bold:{prefix:"**",suffix:"**",trimFirst:!0},italic:{prefix:"_",suffix:"_",trimFirst:!0},code:{prefix:"`",suffix:"`",blockPrefix:"```",blockSuffix:"```"},link:{prefix:"[",suffix:"](url)",replaceNext:"url",scanFor:"https?://"},bulletList:{prefix:"- ",multiline:!0,unorderedList:!0},numberedList:{prefix:"1. ",multiline:!0,orderedList:!0},quote:{prefix:"> ",multiline:!0,surroundWithNewlines:!0},taskList:{prefix:"- [ ] ",multiline:!0,surroundWithNewlines:!0},header1:{prefix:"# "},header2:{prefix:"## "},header3:{prefix:"### "},header4:{prefix:"#### "},header5:{prefix:"##### "},header6:{prefix:"###### "}};function Ge(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function H(n){return oe(oe({},Ge()),n)}var V=!1;function Qe(){return V}function y(n,e,t){V&&(console.group(`\u{1F50D} ${n}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function R(n,e){if(!V)return;let t=n.value.slice(n.selectionStart,n.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${n.selectionStart}-${n.selectionEnd}`),console.log("Selected text:",JSON.stringify(t)),console.log("Length:",t.length);let i=n.value.slice(Math.max(0,n.selectionStart-10),n.selectionStart),o=n.value.slice(n.selectionEnd,Math.min(n.value.length,n.selectionEnd+10));console.log("Context:",JSON.stringify(i)+"[SELECTION]"+JSON.stringify(o)),console.groupEnd()}function le(n){V&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(n.text)),console.log("New selection:",`${n.selectionStart}-${n.selectionEnd}`),console.groupEnd())}var A=null;function I(n,{text:e,selectionStart:t,selectionEnd:i}){let o=Qe();o&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${n.selectionStart}-${n.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",t,"-",i)),n.focus();let r=n.selectionStart,s=n.selectionEnd,a=n.value.slice(0,r),c=n.value.slice(s);o&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(c.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(n.value.slice(r,s))));let d=n.value,l=r!==s;if(A===null||A===!0){n.contentEditable="true";try{A=document.execCommand("insertText",!1,e),o&&console.log("execCommand returned:",A,"for text with",e.split(`
-`).length,"lines")}catch(p){A=!1,o&&console.log("execCommand threw error:",p)}n.contentEditable="false"}if(o&&(console.log("canInsertText before:",A),console.log("execCommand result:",A)),A){let p=a+e+c,h=n.value;o&&(console.log("Expected length:",p.length),console.log("Actual length:",h.length)),h!==p&&o&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(p.slice(0,100))),console.log("Actual:",JSON.stringify(h.slice(0,100))))}if(!A)if(o&&console.log("Using manual insertion"),n.value===d){o&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(p){}n.value=a+e+c;try{document.execCommand("ms-endUndoUnit")}catch(p){}n.dispatchEvent(new CustomEvent("input",{bubbles:!0,cancelable:!0}))}else o&&console.log("Value was changed by execCommand, skipping manual insertion");o&&console.log("Setting selection range:",t,i),t!=null&&i!=null?n.setSelectionRange(t,i):n.setSelectionRange(r,n.selectionEnd),o&&(console.log("Final value length:",n.value.length),console.groupEnd())}function re(n){return n.trim().split(`
-`).length>1}function Xe(n,e){let t=e;for(;n[t]&&n[t-1]!=null&&!n[t-1].match(/\s/);)t--;return t}function Ye(n,e,t){let i=e,o=t?/\n/:/\s/;for(;n[i]&&!n[i].match(o);)i++;return i}function ce(n){let e=n.value.split(`
-`),t=0;for(let i=0;i=t&&n.selectionStart=t&&n.selectionEnde in n?Je(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t,se=(n,e)=>{for(var t in e||(e={}))Qe.call(e,t)&&re(n,t,e[t]);if(oe)for(var t of oe(e))Xe.call(e,t)&&re(n,t,e[t]);return n},T={bold:{prefix:"**",suffix:"**",trimFirst:!0},italic:{prefix:"_",suffix:"_",trimFirst:!0},code:{prefix:"`",suffix:"`",blockPrefix:"```",blockSuffix:"```"},link:{prefix:"[",suffix:"](url)",replaceNext:"url",scanFor:"https?://"},bulletList:{prefix:"- ",multiline:!0,unorderedList:!0},numberedList:{prefix:"1. ",multiline:!0,orderedList:!0},quote:{prefix:"> ",multiline:!0,surroundWithNewlines:!0},taskList:{prefix:"- [ ] ",multiline:!0,surroundWithNewlines:!0},header1:{prefix:"# "},header2:{prefix:"## "},header3:{prefix:"### "},header4:{prefix:"#### "},header5:{prefix:"##### "},header6:{prefix:"###### "}};function Ye(){return{prefix:"",suffix:"",blockPrefix:"",blockSuffix:"",multiline:!1,replaceNext:"",prefixSpace:!1,scanFor:"",surroundWithNewlines:!1,orderedList:!1,unorderedList:!1,trimFirst:!1}}function M(n){return se(se({},Ye()),n)}var q=!1;function et(){return q}function b(n,e,t){q&&(console.group(`\u{1F50D} ${n}`),console.log(e),t&&console.log("Data:",t),console.groupEnd())}function V(n,e){if(!q)return;let t=n.value.slice(n.selectionStart,n.selectionEnd);console.group(`\u{1F4CD} Selection: ${e}`),console.log("Position:",`${n.selectionStart}-${n.selectionEnd}`),console.log("Selected text:",JSON.stringify(t)),console.log("Length:",t.length);let i=n.value.slice(Math.max(0,n.selectionStart-10),n.selectionStart),o=n.value.slice(n.selectionEnd,Math.min(n.value.length,n.selectionEnd+10));console.log("Context:",JSON.stringify(i)+"[SELECTION]"+JSON.stringify(o)),console.groupEnd()}function pe(n){q&&(console.group("\u{1F4DD} Result"),console.log("Text to insert:",JSON.stringify(n.text)),console.log("New selection:",`${n.selectionStart}-${n.selectionEnd}`),console.groupEnd())}var H=null;function $(n,{text:e,selectionStart:t,selectionEnd:i}){let o=et();o&&(console.group("\u{1F527} insertText"),console.log("Current selection:",`${n.selectionStart}-${n.selectionEnd}`),console.log("Text to insert:",JSON.stringify(e)),console.log("New selection to set:",t,"-",i)),n.focus();let r=n.selectionStart,s=n.selectionEnd,a=n.value.slice(0,r),c=n.value.slice(s);o&&(console.log("Before text (last 20):",JSON.stringify(a.slice(-20))),console.log("After text (first 20):",JSON.stringify(c.slice(0,20))),console.log("Selected text being replaced:",JSON.stringify(n.value.slice(r,s))));let d=n.value,l=r!==s;if(H===null||H===!0){n.contentEditable="true";try{H=document.execCommand("insertText",!1,e),o&&console.log("execCommand returned:",H,"for text with",e.split(`
+`).length,"lines")}catch(p){H=!1,o&&console.log("execCommand threw error:",p)}n.contentEditable="false"}if(o&&(console.log("canInsertText before:",H),console.log("execCommand result:",H)),H){let p=a+e+c,u=n.value;o&&(console.log("Expected length:",p.length),console.log("Actual length:",u.length)),u!==p&&o&&(console.log("execCommand changed the value but not as expected"),console.log("Expected:",JSON.stringify(p.slice(0,100))),console.log("Actual:",JSON.stringify(u.slice(0,100))))}if(!H)if(o&&console.log("Using manual insertion"),n.value===d){o&&console.log("Value unchanged, doing manual replacement");try{document.execCommand("ms-beginUndoUnit")}catch(p){}n.value=a+e+c;try{document.execCommand("ms-endUndoUnit")}catch(p){}n.dispatchEvent(new CustomEvent("input",{bubbles:!0,cancelable:!0}))}else o&&console.log("Value was changed by execCommand, skipping manual insertion");o&&console.log("Setting selection range:",t,i),t!=null&&i!=null?n.setSelectionRange(t,i):n.setSelectionRange(r,n.selectionEnd),o&&(console.log("Final value length:",n.value.length),console.groupEnd())}function ae(n){return n.trim().split(`
+`).length>1}function tt(n,e){let t=e;for(;n[t]&&n[t-1]!=null&&!n[t-1].match(/\s/);)t--;return t}function it(n,e,t){let i=e,o=t?/\n/:/\s/;for(;n[i]&&!n[i].match(o);)i++;return i}function de(n){let e=n.value.split(`
+`),t=0;for(let i=0;i=t&&n.selectionStart=t&&n.selectionEnd0&&s[a-1]!==`
`;)a--;if(r){let d=i;for(;d0?`${s}
-`:o,v=re(m)&&a&&a.length>0?`
-${a}`:r;if(d){let S=n.value[n.selectionStart-1];n.selectionStart!==0&&S!=null&&!S.match(/\s/)&&(g=` ${g}`)}m=et(n,g,v,e.multiline);let b=n.selectionStart,x=n.selectionEnd,$=c&&c.length>0&&v.indexOf(c)>-1&&m.length>0;if(p){let S=Z(n);t=S.newlinesToAppend,i=S.newlinesToPrepend,g=t+o,v+=i}if(m.startsWith(g)&&m.endsWith(v)){let S=m.slice(g.length,m.length-v.length);if(u===f){let C=u-g.length;C=Math.max(C,b),C=Math.min(C,b+S.length),b=x=C}else x=b+S.length;return{text:S,selectionStart:b,selectionEnd:x}}else if($)if(l&&l.length>0&&m.match(l)){v=v.replace(c,m);let S=g+v;return b=x=b+g.length,{text:S,selectionStart:b,selectionEnd:x}}else{let S=g+m+v;return b=b+g.length+m.length+v.indexOf(c),x=b+c.length,{text:S,selectionStart:b,selectionEnd:x}}else{let S=g+m+v;b=u+g.length,x=f+g.length;let C=m.match(/^\s*|\s*$/g);if(h&&C){let Q=C[0]||"",X=C[1]||"";S=Q+g+m.trim()+v+X,b+=Q.length,x-=X.length}return{text:S,selectionStart:b,selectionEnd:x}}}function pe(n,e){let{prefix:t,suffix:i,surroundWithNewlines:o}=e,r=n.value.slice(n.selectionStart,n.selectionEnd),s=n.selectionStart,a=n.selectionEnd,c=r.split(`
+`;)d++;n.selectionStart=a,n.selectionEnd=d}else de(n);let c=e(n);if(t.adjustSelection){let l=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix),p=t.adjustSelection(l,i,o,a);c.selectionStart=p.start,c.selectionEnd=p.end}else if(t.prefix){let l=n.value.slice(n.selectionStart,n.selectionEnd).startsWith(t.prefix);r?l?(c.selectionStart=Math.max(i-t.prefix.length,a),c.selectionEnd=c.selectionStart):(c.selectionStart=i+t.prefix.length,c.selectionEnd=c.selectionStart):l?(c.selectionStart=Math.max(i-t.prefix.length,a),c.selectionEnd=Math.max(o-t.prefix.length,a)):(c.selectionStart=i+t.prefix.length,c.selectionEnd=o+t.prefix.length)}return c}function D(n,e){let t,i,{prefix:o,suffix:r,blockPrefix:s,blockSuffix:a,replaceNext:c,prefixSpace:d,scanFor:l,surroundWithNewlines:p,trimFirst:u}=e,m=n.selectionStart,g=n.selectionEnd,f=n.value.slice(n.selectionStart,n.selectionEnd),v=ae(f)&&s&&s.length>0?`${s}
+`:o,y=ae(f)&&a&&a.length>0?`
+${a}`:r;if(d){let L=n.value[n.selectionStart-1];n.selectionStart!==0&&L!=null&&!L.match(/\s/)&&(v=` ${v}`)}f=nt(n,v,y,e.multiline);let w=n.selectionStart,x=n.selectionEnd,I=c&&c.length>0&&y.indexOf(c)>-1&&f.length>0;if(p){let L=Q(n);t=L.newlinesToAppend,i=L.newlinesToPrepend,v=t+o,y+=i}if(f.startsWith(v)&&f.endsWith(y)){let L=f.slice(v.length,f.length-y.length);if(m===g){let C=m-v.length;C=Math.max(C,w),C=Math.min(C,w+L.length),w=x=C}else x=w+L.length;return{text:L,selectionStart:w,selectionEnd:x}}else if(I)if(l&&l.length>0&&f.match(l)){y=y.replace(c,f);let L=v+y;return w=x=w+v.length,{text:L,selectionStart:w,selectionEnd:x}}else{let L=v+f+y;return w=w+v.length+f.length+y.indexOf(c),x=w+c.length,{text:L,selectionStart:w,selectionEnd:x}}else{let L=v+f+y;w=m+v.length,x=g+v.length;let C=f.match(/^\s*|\s*$/g);if(u&&C){let ee=C[0]||"",te=C[1]||"";L=ee+v+f.trim()+y+te,w+=ee.length,x-=te.length}return{text:L,selectionStart:w,selectionEnd:x}}}function he(n,e){let{prefix:t,suffix:i,surroundWithNewlines:o}=e,r=n.value.slice(n.selectionStart,n.selectionEnd),s=n.selectionStart,a=n.selectionEnd,c=r.split(`
`);if(c.every(l=>l.startsWith(t)&&(!i||l.endsWith(i))))r=c.map(l=>{let p=l.slice(t.length);return i&&(p=p.slice(0,p.length-i.length)),p}).join(`
`),a=s+r.length;else if(r=c.map(l=>t+l+(i||"")).join(`
-`),o){let{newlinesToAppend:l,newlinesToPrepend:p}=Z(n);s+=l.length,a=s+r.length,r=l+r+p}return{text:r,selectionStart:s,selectionEnd:a}}function se(n){let e=n.split(`
+`),o){let{newlinesToAppend:l,newlinesToPrepend:p}=Q(n);s+=l.length,a=s+r.length,r=l+r+p}return{text:r,selectionStart:s,selectionEnd:a}}function le(n){let e=n.split(`
`),t=/^\d+\.\s+/,i=e.every(r=>t.test(r)),o=e;return i&&(o=e.map(r=>r.replace(t,""))),{text:o.join(`
-`),processed:i}}function ae(n){let e=n.split(`
+`),processed:i}}function ce(n){let e=n.split(`
`),t="- ",i=e.every(r=>r.startsWith(t)),o=e;return i&&(o=e.map(r=>r.slice(t.length))),{text:o.join(`
-`),processed:i}}function N(n,e){return e?"- ":`${n+1}. `}function tt(n,e){let t,i,o;return n.orderedList?(t=se(e),i=ae(t.text),o=i.text):(t=ae(e),i=se(t.text),o=i.text),[t,i,o]}function it(n,e){let t=n.selectionStart===n.selectionEnd,i=n.selectionStart,o=n.selectionEnd;ce(n);let r=n.value.slice(n.selectionStart,n.selectionEnd),[s,a,c]=tt(e,r),d=c.split(`
-`).map((m,g)=>`${N(g,e.unorderedList)}${m}`),l=d.reduce((m,g,v)=>m+N(v,e.unorderedList).length,0),p=d.reduce((m,g,v)=>m+N(v,!e.unorderedList).length,0);if(s.processed)return t?(i=Math.max(i-N(0,e.unorderedList).length,0),o=i):(i=n.selectionStart,o=n.selectionEnd-l),{text:c,selectionStart:i,selectionEnd:o};let{newlinesToAppend:h,newlinesToPrepend:u}=Z(n),f=h+d.join(`
-`)+u;return t?(i=Math.max(i+N(0,e.unorderedList).length+h.length,0),o=i):a.processed?(i=Math.max(n.selectionStart+h.length,0),o=n.selectionEnd+h.length+l-p):(i=Math.max(n.selectionStart+h.length,0),o=n.selectionEnd+h.length+l),{text:f,selectionStart:i,selectionEnd:o}}function de(n,e){let t=U(n,i=>it(i,e),{adjustSelection:(i,o,r,s)=>{let a=n.value.slice(s,n.selectionEnd),c=/^\d+\.\s+/,d=/^- /,l=c.test(a),p=d.test(a),h=e.orderedList&&l||e.unorderedList&&p;if(o===r)if(h){let u=a.match(e.orderedList?c:d),f=u?u[0].length:0;return{start:Math.max(o-f,s),end:Math.max(o-f,s)}}else if(l||p){let u=a.match(l?c:d),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:o+g}}else{let u=e.unorderedList?2:3;return{start:o+u,end:o+u}}else if(h){let u=a.match(e.orderedList?c:d),f=u?u[0].length:0;return{start:Math.max(o-f,s),end:Math.max(r-f,s)}}else if(l||p){let u=a.match(l?c:d),f=u?u[0].length:0,g=(e.unorderedList?2:3)-f;return{start:o+g,end:r+g}}else{let u=e.unorderedList?2:3;return{start:o+u,end:r+u}}}});I(n,t)}function nt(n){if(!n)return[];let e=[],{selectionStart:t,selectionEnd:i,value:o}=n,r=o.split(`
-`),s=0,a="";for(let p of r){if(t>=s&&t<=s+p.length){a=p;break}s+=p.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let c=Math.max(0,t-10),d=Math.min(o.length,i+10),l=o.slice(c,d);if(l.includes("**")){let p=o.slice(Math.max(0,t-100),t),h=o.slice(i,Math.min(o.length,i+100)),u=p.lastIndexOf("**"),f=h.indexOf("**");u!==-1&&f!==-1&&e.push("bold")}if(l.includes("_")){let p=o.slice(Math.max(0,t-100),t),h=o.slice(i,Math.min(o.length,i+100)),u=p.lastIndexOf("_"),f=h.indexOf("_");u!==-1&&f!==-1&&e.push("italic")}if(l.includes("`")){let p=o.slice(Math.max(0,t-100),t),h=o.slice(i,Math.min(o.length,i+100));p.includes("`")&&h.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let p=o.slice(Math.max(0,t-100),t),h=o.slice(i,Math.min(o.length,i+100)),u=p.lastIndexOf("["),f=h.indexOf("]");u!==-1&&f!==-1&&o.slice(i+f+1,i+f+10).startsWith("(")&&e.push("link")}return e}function he(n){if(!n||n.disabled||n.readOnly)return;y("toggleBold","Starting"),R(n,"Before");let e=H(_.bold),t=D(n,e);le(t),I(n,t),R(n,"After")}function ue(n){if(!n||n.disabled||n.readOnly)return;let e=H(_.italic),t=D(n,e);I(n,t)}function me(n){if(!n||n.disabled||n.readOnly)return;let e=H(_.code),t=D(n,e);I(n,t)}function fe(n,e={}){if(!n||n.disabled||n.readOnly)return;let t=n.value.slice(n.selectionStart,n.selectionEnd),i=H(_.link);if(t&&t.match(/^https?:\/\//)&&!e.url?(i.suffix=`](${t})`,i.replaceNext=""):e.url&&(i.suffix=`](${e.url})`,i.replaceNext=""),e.text&&!t){let s=n.selectionStart;n.value=n.value.slice(0,s)+e.text+n.value.slice(s),n.selectionStart=s,n.selectionEnd=s+e.text.length}let r=D(n,i);I(n,r)}function ge(n){if(!n||n.disabled||n.readOnly)return;let e=H(_.bulletList);de(n,e)}function ve(n){if(!n||n.disabled||n.readOnly)return;let e=H(_.numberedList);de(n,e)}function ye(n){if(!n||n.disabled||n.readOnly)return;y("toggleQuote","Starting"),R(n,"Initial");let e=H(_.quote),t=U(n,i=>pe(i,e),{prefix:e.prefix});le(t),I(n,t),R(n,"Final")}function J(n){if(!n||n.disabled||n.readOnly)return;let e=H(_.taskList),t=U(n,i=>pe(i,e),{prefix:e.prefix});I(n,t)}function G(n,e=1,t=!1){if(!n||n.disabled||n.readOnly)return;(e<1||e>6)&&(e=1),y("insertHeader","============ START ============"),y("insertHeader",`Level: ${e}, Toggle: ${t}`),y("insertHeader",`Initial cursor: ${n.selectionStart}-${n.selectionEnd}`);let i=`header${e===1?"1":e}`,o=H(_[i]||_.header1);y("insertHeader",`Style prefix: "${o.prefix}"`);let r=n.value,s=n.selectionStart,a=n.selectionEnd,c=s;for(;c>0&&r[c-1]!==`
+`),processed:i}}function O(n,e){return e?"- ":`${n+1}. `}function ot(n,e){let t,i,o;return n.orderedList?(t=le(e),i=ce(t.text),o=i.text):(t=ce(e),i=le(t.text),o=i.text),[t,i,o]}function rt(n,e){let t=n.selectionStart===n.selectionEnd,i=n.selectionStart,o=n.selectionEnd;de(n);let r=n.value.slice(n.selectionStart,n.selectionEnd),[s,a,c]=ot(e,r),d=c.split(`
+`).map((f,v)=>`${O(v,e.unorderedList)}${f}`),l=d.reduce((f,v,y)=>f+O(y,e.unorderedList).length,0),p=d.reduce((f,v,y)=>f+O(y,!e.unorderedList).length,0);if(s.processed)return t?(i=Math.max(i-O(0,e.unorderedList).length,0),o=i):(i=n.selectionStart,o=n.selectionEnd-l),{text:c,selectionStart:i,selectionEnd:o};let{newlinesToAppend:u,newlinesToPrepend:m}=Q(n),g=u+d.join(`
+`)+m;return t?(i=Math.max(i+O(0,e.unorderedList).length+u.length,0),o=i):a.processed?(i=Math.max(n.selectionStart+u.length,0),o=n.selectionEnd+u.length+l-p):(i=Math.max(n.selectionStart+u.length,0),o=n.selectionEnd+u.length+l),{text:g,selectionStart:i,selectionEnd:o}}function ue(n,e){let t=U(n,i=>rt(i,e),{adjustSelection:(i,o,r,s)=>{let a=n.value.slice(s,n.selectionEnd),c=/^\d+\.\s+/,d=/^- /,l=c.test(a),p=d.test(a),u=e.orderedList&&l||e.unorderedList&&p;if(o===r)if(u){let m=a.match(e.orderedList?c:d),g=m?m[0].length:0;return{start:Math.max(o-g,s),end:Math.max(o-g,s)}}else if(l||p){let m=a.match(l?c:d),g=m?m[0].length:0,v=(e.unorderedList?2:3)-g;return{start:o+v,end:o+v}}else{let m=e.unorderedList?2:3;return{start:o+m,end:o+m}}else if(u){let m=a.match(e.orderedList?c:d),g=m?m[0].length:0;return{start:Math.max(o-g,s),end:Math.max(r-g,s)}}else if(l||p){let m=a.match(l?c:d),g=m?m[0].length:0,v=(e.unorderedList?2:3)-g;return{start:o+v,end:r+v}}else{let m=e.unorderedList?2:3;return{start:o+m,end:r+m}}}});$(n,t)}function st(n){if(!n)return[];let e=[],{selectionStart:t,selectionEnd:i,value:o}=n,r=o.split(`
+`),s=0,a="";for(let p of r){if(t>=s&&t<=s+p.length){a=p;break}s+=p.length+1}a.startsWith("- ")&&(a.startsWith("- [ ] ")||a.startsWith("- [x] ")?e.push("task-list"):e.push("bullet-list")),/^\d+\.\s/.test(a)&&e.push("numbered-list"),a.startsWith("> ")&&e.push("quote"),a.startsWith("# ")&&e.push("header"),a.startsWith("## ")&&e.push("header-2"),a.startsWith("### ")&&e.push("header-3");let c=Math.max(0,t-10),d=Math.min(o.length,i+10),l=o.slice(c,d);if(l.includes("**")){let p=o.slice(Math.max(0,t-100),t),u=o.slice(i,Math.min(o.length,i+100)),m=p.lastIndexOf("**"),g=u.indexOf("**");m!==-1&&g!==-1&&e.push("bold")}if(l.includes("_")){let p=o.slice(Math.max(0,t-100),t),u=o.slice(i,Math.min(o.length,i+100)),m=p.lastIndexOf("_"),g=u.indexOf("_");m!==-1&&g!==-1&&e.push("italic")}if(l.includes("`")){let p=o.slice(Math.max(0,t-100),t),u=o.slice(i,Math.min(o.length,i+100));p.includes("`")&&u.includes("`")&&e.push("code")}if(l.includes("[")&&l.includes("]")){let p=o.slice(Math.max(0,t-100),t),u=o.slice(i,Math.min(o.length,i+100)),m=p.lastIndexOf("["),g=u.indexOf("]");m!==-1&&g!==-1&&o.slice(i+g+1,i+g+10).startsWith("(")&&e.push("link")}return e}function me(n){if(!n||n.disabled||n.readOnly)return;b("toggleBold","Starting"),V(n,"Before");let e=M(T.bold),t=D(n,e);pe(t),$(n,t),V(n,"After")}function fe(n){if(!n||n.disabled||n.readOnly)return;let e=M(T.italic),t=D(n,e);$(n,t)}function ge(n){if(!n||n.disabled||n.readOnly)return;let e=M(T.code),t=D(n,e);$(n,t)}function ve(n,e={}){if(!n||n.disabled||n.readOnly)return;let t=n.value.slice(n.selectionStart,n.selectionEnd),i=M(T.link);if(t&&t.match(/^https?:\/\//)&&!e.url?(i.suffix=`](${t})`,i.replaceNext=""):e.url&&(i.suffix=`](${e.url})`,i.replaceNext=""),e.text&&!t){let s=n.selectionStart;n.value=n.value.slice(0,s)+e.text+n.value.slice(s),n.selectionStart=s,n.selectionEnd=s+e.text.length}let r=D(n,i);$(n,r)}function ye(n){if(!n||n.disabled||n.readOnly)return;let e=M(T.bulletList);ue(n,e)}function be(n){if(!n||n.disabled||n.readOnly)return;let e=M(T.numberedList);ue(n,e)}function we(n){if(!n||n.disabled||n.readOnly)return;b("toggleQuote","Starting"),V(n,"Initial");let e=M(T.quote),t=U(n,i=>he(i,e),{prefix:e.prefix});pe(t),$(n,t),V(n,"Final")}function X(n){if(!n||n.disabled||n.readOnly)return;let e=M(T.taskList),t=U(n,i=>he(i,e),{prefix:e.prefix});$(n,t)}function Y(n,e=1,t=!1){if(!n||n.disabled||n.readOnly)return;(e<1||e>6)&&(e=1),b("insertHeader","============ START ============"),b("insertHeader",`Level: ${e}, Toggle: ${t}`),b("insertHeader",`Initial cursor: ${n.selectionStart}-${n.selectionEnd}`);let i=`header${e===1?"1":e}`,o=M(T[i]||T.header1);b("insertHeader",`Style prefix: "${o.prefix}"`);let r=n.value,s=n.selectionStart,a=n.selectionEnd,c=s;for(;c>0&&r[c-1]!==`
`;)c--;let d=a;for(;d{let v=g.value.slice(g.selectionStart,g.selectionEnd);y("insertHeader",`Line in operation: "${v}"`);let b=v.replace(/^#{1,6}\s*/,"");y("insertHeader",`Cleaned line: "${b}"`);let x;return f?(y("insertHeader","ACTION: Toggling OFF - removing header"),x=b):h>0?(y("insertHeader",`ACTION: Replacing H${h} with H${e}`),x=o.prefix+b):(y("insertHeader","ACTION: Adding new header"),x=o.prefix+b),y("insertHeader",`New line: "${x}"`),{text:x,selectionStart:g.selectionStart,selectionEnd:g.selectionEnd}},{prefix:o.prefix,adjustSelection:(g,v,b,x)=>{if(y("insertHeader","Adjusting selection:"),y("insertHeader",` - isRemoving param: ${g}`),y("insertHeader",` - shouldToggleOff: ${f}`),y("insertHeader",` - selStart: ${v}, selEnd: ${b}`),y("insertHeader",` - lineStartPos: ${x}`),f){let $=Math.max(v-u,x);return y("insertHeader",` - Removing header, adjusting by -${u}`),{start:$,end:v===b?$:Math.max(b-u,x)}}else if(u>0){let $=o.prefix.length-u;return y("insertHeader",` - Replacing header, adjusting by ${$}`),{start:v+$,end:b+$}}else return y("insertHeader",` - Adding header, adjusting by +${o.prefix.length}`),{start:v+o.prefix.length,end:b+o.prefix.length}}});y("insertHeader",`Final result: text="${m.text}", cursor=${m.selectionStart}-${m.selectionEnd}`),y("insertHeader","============ END ============"),I(n,m)}function be(n){G(n,1,!0)}function we(n){G(n,2,!0)}function xe(n){G(n,3,!0)}function ke(n){return nt(n)}var q=class{constructor(e,t={}){this.editor=e,this.container=null,this.buttons={},this.toolbarButtons=t.toolbarButtons||[]}create(){this.container=document.createElement("div"),this.container.className="overtype-toolbar",this.container.setAttribute("role","toolbar"),this.container.setAttribute("aria-label","Formatting toolbar"),this.toolbarButtons.forEach(e=>{if(e.name==="separator"){let t=this.createSeparator();this.container.appendChild(t)}else{let t=this.createButton(e);this.buttons[e.name]=t,this.container.appendChild(t)}}),this.editor.container.insertBefore(this.container,this.editor.wrapper)}createSeparator(){let e=document.createElement("div");return e.className="overtype-toolbar-separator",e.setAttribute("role","separator"),e}createButton(e){let t=document.createElement("button");return t.className="overtype-toolbar-button",t.type="button",t.setAttribute("data-button",e.name),t.title=e.title||"",t.setAttribute("aria-label",e.title||e.name),t.innerHTML=this.sanitizeSVG(e.icon||""),e.name==="viewMode"?(t.classList.add("has-dropdown"),t.dataset.dropdown="true",t.addEventListener("click",i=>{i.preventDefault(),this.toggleViewModeDropdown(t)}),t):(t._clickHandler=i=>{i.preventDefault();let o=e.actionId||e.name;this.editor.performAction(o,i)},t.addEventListener("click",t._clickHandler),t)}async handleAction(e){if(e&&typeof e=="object"&&typeof e.action=="function"){this.editor.textarea.focus();try{return await e.action({editor:this.editor,getValue:()=>this.editor.getValue(),setValue:t=>this.editor.setValue(t),event:null}),!0}catch(t){return console.error(`Action "${e.name}" error:`,t),this.editor.wrapper.dispatchEvent(new CustomEvent("button-error",{detail:{buttonName:e.name,error:t}})),!1}}return typeof e=="string"?this.editor.performAction(e,null):!1}sanitizeSVG(e){return typeof e!="string"?"":e.replace(/
+