(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode("button.ce-inline-tool:disabled{color:#999;fill:#999;background:#fff}")),document.head.appendChild(e)}}catch(t){console.error("vite-plugin-css-injected-by-js",t)}})();
(function(n,i){typeof exports=="object"&&typeof module<"u"?module.exports=i():typeof define=="function"&&define.amd?define(i):(n=typeof globalThis<"u"?globalThis:n||self,n.ClearFormatting=i())})(this,function(){"use strict";var u=Object.defineProperty;var h=(n,i,o)=>i in n?u(n,i,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[i]=o;var r=(n,i,o)=>(h(n,typeof i!="symbol"?i+"":i,o),o);class n{static hasFormatting(t){if(t===void 0)return!1;let e=window.getSelection();if(e.rangeCount===0)return!1;let l=e.getRangeAt(0);if(l.cloneContents().children.length)return!0;let s=l.commonAncestorContainer;return s.nodeType===Node.TEXT_NODE&&(s=s.parentElement),s!==t}static clearFormatting(){let t=window.getSelection(),e=t.getRangeAt(0),c=e.cloneRange().extractContents().textContent,d=document.createTextNode(c);e.deleteContents(),e.insertNode(d),t.removeAllRanges(),t.addRange(e)}static findBlock(t){let e=t.anchorNode;return e.nodeType===Node.TEXT_NODE?e.parentElement.closest(".cdx-block"):e.closest(".cdx-block")}}const i={clearFormatting:"Clear formatting within selection"};class o{constructor({config:t,api:e}){r(this,"config",{shortcut:null,closeOnClick:!1,icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.7,7h3.1M17.1,9l.7-1.8c0-.1,0-.2-.1-.2h-3.8M11.1,14.6l-.9,2.4M13.8,7l-.7,2M10.2,17h-2M10.2,17h2"/><line x1="7" x2="17.8" y1="7" y2="17" stroke="currentColor" stroke-linecap="round" stroke-width="2"/></svg>'});r(this,"state",!1);r(this,"block",null);this.api=e,this.config={...this.config,...t},this.onInputHandler=this.onInputHandler.bind(this)}static get isInline(){return!0}static get sanitize(){}get title(){return this.api.i18n.t(i.clearFormatting)}get shortcut(){if(this.config.shortcut!==null)return this.config.shortcut}render(){return this.button=document.createElement("button"),this.button.type="button",this.button.id="json-editor-clear-formatting",this.button.innerHTML=this.config.icon,this.button.classList.add(this.api.styles.inlineToolButton),this.button}surround(t){t&&(n.clearFormatting(),this.config.closeOnClick&&this.api.inlineToolbar.close())}async checkState(t){this.block=n.findBlock(t);const e=document.querySelector(".codex-editor");e&&e.addEventListener("input",this.onInputHandler),this.updateState()}updateState(){this.api===void 0||this.button===void 0||(this.state=n.hasFormatting(this.block),this.button.disabled=!this.state,this.button.classList.toggle(this.api.styles.inlineToolButtonActive,this.state))}onInputHandler(t){t.target===this.block&&this.updateState()}clear(){const t=document.querySelector(".codex-editor");t&&t.removeEventListener("input",this.onInputHandler)}}return o});
