"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const k=require("./anchoredPopover-BzqGPOAE.js");let n=null,d=null,x=null,i="#000000";const u='[data-theme="dark"], .dark, .editora-theme-dark',w=["#000000","#ffffff","#808080","#ff0000","#00ff00","#0000ff","#ffff00","#ff00ff","#00ffff","#ffa500","#800080","#ffc0cb"];function y(){const e=window.getSelection();if(e&&e.rangeCount>0){const c=e.getRangeAt(0).startContainer,l=c.nodeType===Node.ELEMENT_NODE?c:c.parentElement;if(l){const r=l.closest('[data-editora-editor="true"], .rte-editor, .editora-editor');if(r)return r}}const o=document.activeElement;return o?o.closest('[data-editora-editor="true"], .rte-editor, .editora-editor'):null}function C(e){const o=window.__editoraLastCommand,t=window.__editoraLastCommandButton;if(o===e&&t&&t.isConnected){const a=window.getComputedStyle(t),s=t.getBoundingClientRect();if(a.display!=="none"&&a.visibility!=="hidden"&&a.pointerEvents!=="none"&&!(s.width===0&&s.height===0))return t}const c=a=>{for(const s of a){const b=window.getComputedStyle(s),h=s.getBoundingClientRect();if(!(b.display==="none"||b.visibility==="hidden"||b.pointerEvents==="none")&&!(h.width===0&&h.height===0))return s}return null},l=y();if(l){const a=Array.from(l.querySelectorAll(`[data-command="${e}"]`)),s=c(a);if(s)return s}const r=Array.from(document.querySelectorAll(`[data-command="${e}"]`));return c(r)}function E(e){if(e?.closest(u))return!0;const o=window.getSelection();if(o&&o.rangeCount>0){const c=o.getRangeAt(0).startContainer;if((c.nodeType===Node.ELEMENT_NODE?c:c.parentElement)?.closest(u))return!0}return document.activeElement?.closest(u)?!0:document.body.matches(u)||document.documentElement.matches(u)}function f(e){return k.applyColorToSelection({color:e,className:"rte-text-color",styleProperty:"color",commands:["foreColor"],savedRange:x,getActiveEditorRoot:y,warnMessage:"[TextColor] Could not apply color for current selection"})}function S(){const e=window.getSelection();if(!e||e.rangeCount===0)return"#000000";let t=e.getRangeAt(0).startContainer;for(;t&&t!==document.body;){if(t.nodeType===Node.ELEMENT_NODE){const c=t,l=c.style.color||window.getComputedStyle(c).color;if(l&&l!=="rgb(0, 0, 0)")return T(l)}t=t.parentNode}return"#000000"}function T(e){if(e.startsWith("#"))return e;const o=e.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);if(!o)return"#000000";const t=parseInt(o[1]),c=parseInt(o[2]),l=parseInt(o[3]);return"#"+[t,c,l].map(r=>{const a=r.toString(16);return a.length===1?"0"+a:a}).join("")}function A(e){const o=window.getSelection();o&&o.rangeCount>0&&(x=o.getRangeAt(0).cloneRange()),i=S(),n=document.createElement("div"),n.className="rte-inline-color-picker",E(e)&&n.classList.add("rte-theme-dark"),n.addEventListener("click",t=>t.stopPropagation()),n.innerHTML=`
    <div class="rte-color-picker-header">
      <span class="rte-color-picker-title">Text Color</span>
      <button class="rte-color-picker-close" aria-label="Close">×</button>
    </div>
    
    <div class="rte-color-picker-body">
      <!-- Current Color Preview -->
      <div class="rte-color-preview-section">
        <div class="rte-color-preview-box" style="background-color: ${i}; ${i==="#ffffff"?"border: 1px solid #ccc;":""}"></div>
        <span class="rte-color-preview-label">${i.toUpperCase()}</span>
      </div>

      <!-- Preset Colors -->
      <div class="rte-color-section">
        <label class="rte-color-section-label">Colors</label>
        <div class="rte-color-palette">
          ${w.map(t=>`
            <button
              class="rte-color-swatch ${i===t?"selected":""}"
              style="background-color: ${t}; ${t==="#ffffff"?"border: 1px solid #ccc;":""}"
              data-color="${t}"
              title="${t.toUpperCase()}"
              aria-label="${t.toUpperCase()}"
            ></button>
          `).join("")}
        </div>
      </div>

      <!-- Custom Color -->
      <div class="rte-color-section">
        <label class="rte-color-section-label">Custom</label>
        <div class="rte-custom-color-inputs">
          <input
            type="color"
            value="${i}"
            class="rte-color-input-native"
            aria-label="Color picker"
          />
          <input
            type="text"
            value="${i}"
            placeholder="#000000"
            pattern="^#[0-9A-Fa-f]{6}$"
            class="rte-color-input-text"
            aria-label="Hex color input"
          />
        </div>
      </div>
    </div>
  `,document.body.appendChild(n),d&&(d.destroy(),d=null),d=k.attachAnchoredPopover({popover:n,anchor:e,onClose:p,gap:4,margin:8,zIndex:1e4}),L()}function L(){if(!n)return;n.querySelector(".rte-color-picker-close")?.addEventListener("click",()=>p()),n.querySelectorAll(".rte-color-swatch").forEach(l=>{l.addEventListener("click",()=>{const r=l.getAttribute("data-color");r&&(i=r,f(r),p())})});const t=n.querySelector(".rte-color-input-native");t?.addEventListener("change",l=>{const r=l.target.value;i=r,f(r),p()});const c=n.querySelector(".rte-color-input-text");c?.addEventListener("change",l=>{const r=l.target.value;/^#[0-9A-Fa-f]{6}$/.test(r)&&(i=r,f(r),p())}),t?.addEventListener("input",l=>{const r=l.target.value;i=r,m(r),v(r),$(r)}),c?.addEventListener("input",l=>{const r=l.target.value;/^#[0-9A-Fa-f]{6}$/.test(r)&&(i=r,m(r),v(r),P(r))})}function m(e){if(!n)return;const o=n.querySelector(".rte-color-preview-box"),t=n.querySelector(".rte-color-preview-label");o&&(o.style.backgroundColor=e,o.style.border=e==="#ffffff"?"1px solid #ccc":"none"),t&&(t.textContent=e.toUpperCase())}function v(e){if(!n)return;n.querySelectorAll(".rte-color-swatch").forEach(t=>{t.getAttribute("data-color")===e?t.classList.add("selected"):t.classList.remove("selected")})}function P(e){if(!n)return;const o=n.querySelector(".rte-color-input-native");o&&(o.value=e)}function $(e){if(!n)return;const o=n.querySelector(".rte-color-input-text");o&&(o.value=e)}function p(){d&&(d.destroy(),d=null),n&&(n.remove(),n=null),x=null}function _(){if(g(),n)return p(),!0;const e=C("openTextColorPicker");return e?(A(e),!0):!1}function g(){if(!window.__textColorPluginInitialized&&(window.__textColorPluginInitialized=!0,!document.getElementById("text-color-plugin-styles"))){const e=document.createElement("style");e.id="text-color-plugin-styles",e.textContent=`
      .rte-inline-color-picker {
        background: white;
        border-radius: 8px;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
        width: 220px;
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
      }

      .rte-color-picker-header {
        padding: 12px 16px;
        border-bottom: 1px solid #eee;
        display: flex;
        justify-content: space-between;
        align-items: center;
      }

      .rte-color-picker-title {
        font-size: 14px;
        font-weight: 600;
        color: #333;
      }

      .rte-color-picker-close {
        background: none;
        border: none;
        font-size: 24px;
        cursor: pointer;
        color: #999;
        padding: 0;
        width: 24px;
        height: 24px;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1;
      }

      .rte-color-picker-close:hover {
        color: #333;
      }

      .rte-color-picker-body {
        padding: 8px;
      }

      .rte-color-preview-section {
        display: flex;
        align-items: center;
        gap: 12px;
        margin-bottom: 8px;
        padding: 6px;
        background-color: #f8f9fa;
        border-radius: 6px;
        border: 1px solid #e0e0e0;
      }

      .rte-color-preview-box {
        width: 24px;
        height: 24px;
        border-radius: 4px;
        flex-shrink: 0;
      }

      .rte-color-preview-label {
        font-size: 13px;
        font-weight: 500;
        color: #666;
        font-family: monospace;
      }

      .rte-color-section {
        margin-bottom: 16px;
      }

      .rte-color-section:last-child {
        margin-bottom: 0;
      }

      .rte-color-section-label {
        display: block;
        font-size: 12px;
        font-weight: 600;
        color: #666;
        margin-bottom: 8px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
      }

      .rte-color-palette {
        display: grid;
        grid-template-columns: repeat(7, 1fr);
        gap: 6px;
        max-width: 180px;
      }

      .rte-color-swatch {
        width: 100%;
        aspect-ratio: 1;
        border: 1px solid #e0e0e0;
        border-radius: 3px;
        cursor: pointer;
        transition: all 0.15s ease;
        padding: 0;
        min-height: 20px;
      }

      .rte-color-swatch:hover {
        transform: scale(1.05);
        border-color: #ccc;
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
      }

      .rte-color-swatch.selected {
        border-color: #1976d2;
        box-shadow: 0 0 0 1px rgba(25, 118, 210, 0.3);
      }

      .rte-custom-color-inputs {
        display: flex;
        gap: 8px;
      }

      .rte-color-input-native {
        width: 50px;
        height: 26px;
        border: 1px solid #ddd;
        border-radius: 4px;
        cursor: pointer;
        padding: 2px;
      }

      .rte-color-input-text {
        flex: 1;
        height: 26px;
        width: 50px;
        border: 1px solid #ddd;
        border-radius: 4px;
        padding: 0 12px;
        font-size: 13px;
        font-family: monospace;
      }

      .rte-color-input-text:focus {
        outline: none;
        border-color: #1976d2;
      }

      .rte-color-picker-footer {
        padding: 12px 16px;
        border-top: 1px solid #eee;
        display: flex;
        gap: 8px;
        justify-content: flex-end;
      }

      .rte-btn-primary,
      .rte-btn-secondary {
        padding: 6px 16px;
        border-radius: 4px;
        font-size: 13px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s;
        border: none;
      }

      .rte-btn-primary {
        background-color: #1976d2;
        color: white;
      }

      .rte-btn-primary:hover {
        background-color: #1565c0;
      }

      .rte-btn-secondary {
        background-color: #f5f5f5;
        color: #333;
        border: 1px solid #ddd;
      }

      .rte-btn-secondary:hover {
        background-color: #eeeeee;
      }

      .rte-inline-color-picker.rte-theme-dark {
        background: #1f2937;
        border: 1px solid #4b5563;
        box-shadow: 0 14px 30px rgba(0, 0, 0, 0.5);
      }

      .rte-inline-color-picker.rte-theme-dark .rte-color-picker-header {
        border-bottom-color: #3b4657;
      }

      .rte-inline-color-picker.rte-theme-dark .rte-color-picker-title {
        color: #e2e8f0;
      }

      .rte-inline-color-picker.rte-theme-dark .rte-color-picker-close {
        color: #94a3b8;
      }

      .rte-inline-color-picker.rte-theme-dark .rte-color-picker-close:hover {
        color: #f8fafc;
      }

      .rte-inline-color-picker.rte-theme-dark .rte-color-preview-section {
        background-color: #111827;
        border-color: #4b5563;
      }

      .rte-inline-color-picker.rte-theme-dark .rte-color-preview-label {
        color: #cbd5e1;
      }

      .rte-inline-color-picker.rte-theme-dark .rte-color-section-label {
        color: #9fb0c6;
      }

      .rte-inline-color-picker.rte-theme-dark .rte-color-swatch {
        border-color: #4b5563;
      }

      .rte-inline-color-picker.rte-theme-dark .rte-color-swatch:hover {
        border-color: #7a8ba5;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
      }

      .rte-inline-color-picker.rte-theme-dark .rte-color-swatch.selected {
        border-color: #58a6ff;
        box-shadow: 0 0 0 1px rgba(88, 166, 255, 0.4);
      }

      .rte-inline-color-picker.rte-theme-dark .rte-color-input-native,
      .rte-inline-color-picker.rte-theme-dark .rte-color-input-text {
        background: #111827;
        border-color: #4b5563;
        color: #e2e8f0;
      }

      .rte-inline-color-picker.rte-theme-dark .rte-color-input-text::placeholder {
        color: #94a3b8;
      }

      .rte-inline-color-picker.rte-theme-dark .rte-color-input-text:focus {
        border-color: #58a6ff;
      }
    `,document.head.appendChild(e)}}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",g):setTimeout(g,100);const M=()=>({name:"textColor",marks:{textColor:{attrs:{color:{default:"#000000"}},parseDOM:[{tag:"span[style*=color]",getAttrs:e=>{const t=(e.getAttribute("style")||"").match(/color:\s*([^;]+)/);return t?{color:t[1]}:null}},{tag:"font[color]",getAttrs:e=>{const o=e.getAttribute("color");return o?{color:o}:null}}],toDOM:e=>["span",{style:`color: ${e.attrs?.color||"#000000"}`,class:"rte-text-color"},0]}},toolbar:[{label:"Text Color",command:"openTextColorPicker",icon:'<svg width="24" height="24" focusable="false"><g fill-rule="evenodd"><path class="tox-icon-text-color__color" d="M3 18h18v3H3z" fill="currentColor"></path><path d="M8.7 16h-.8a.5.5 0 0 1-.5-.6l2.7-9c.1-.3.3-.4.5-.4h2.8c.2 0 .4.1.5.4l2.7 9a.5.5 0 0 1-.5.6h-.8a.5.5 0 0 1-.4-.4l-.7-2.2c0-.3-.3-.4-.5-.4h-3.4c-.2 0-.4.1-.5.4l-.7 2.2c0 .3-.2.4-.4.4Zm2.6-7.6-.6 2a.5.5 0 0 0 .5.6h1.6a.5.5 0 0 0 .5-.6l-.6-2c0-.3-.3-.4-.5-.4h-.4c-.2 0-.4.1-.5.4Z"></path></g></svg>'}],commands:{openTextColorPicker:()=>_(),setTextColor:e=>e?f(e):!1},keymap:{}});exports.TextColorPlugin=M;
