import x from "../components/copy-button.js";
import { n as s, C as k } from "./lib-cortex-element.CVMmyPMC.js";
import { c as b } from "./component.styles.CRO4Odto.js";
import { i as p } from "./lit-element.jLBm65_O.js";
import { c as v } from "./custom-element.L4WJXn1j.js";
import { L as y } from "./i18n.BABe9hN4.js";
import { w } from "./watch.BCJD77bD.js";
import { e as m } from "./query.BBf1UFkC.js";
import { e as u } from "./class-map.BiVq-cVR.js";
import { o as P } from "./style-map.llVFPd__.js";
import { n as M } from "./when.Dr1es41R.js";
import { i as l, u as d } from "./static.UA3G1Deq.js";
const C = p`insert,span[format]{background-color:var(--cx-color-success-200)}delete{background-color:var(--cx-color-neutral-200);text-decoration:line-through}annotate{background-color:var(--cx-color-warning-200)}.ProseMirror figure[data-track*=deletion] [data-node-type=figure],.ProseMirror cx-rich-text-code-block[data-track*=deletion],.ProseMirror cx-rich-text-image-viewer[data-track*=deletion]{border:3px solid var(--cx-color-neutral);position:relative}.ProseMirror figure[data-track*=deletion] [data-node-type=figure]:after,.ProseMirror cx-rich-text-code-block[data-track*=deletion]:after,.ProseMirror cx-rich-text-image-viewer[data-track*=deletion]:after{content:"";box-sizing:border-box;pointer-events:none;background-image:repeating-linear-gradient(45deg, var(--cx-color-neutral), var(--cx-color-neutral) 10px, #fff 10px, #fff 20px);opacity:.4;width:100%;height:100%;position:absolute;top:0;left:0}.ProseMirror figure[data-track*=insertion] [data-node-type=figure],.ProseMirror cx-rich-text-code-block[data-track*=insertion],.ProseMirror cx-rich-text-image-viewer[data-track*=insertion]{border:3px solid var(--cx-color-success)}.ProseMirror figure[data-track*=annotation] [data-node-type=figure],.ProseMirror cx-rich-text-code-block[data-track*=annotation],.ProseMirror cx-rich-text-image-viewer[data-track*=annotation]{border:3px solid var(--cx-color-warning-200)}`, z = p`
  .column-resize-handle {
    background-color: var(--editor-table-resize-handle-color);
    bottom: -2px;
    height: unset !important;
    max-height: unset !important;
    pointer-events: none;
    position: absolute;
    right: -4px;
    top: -2px;
    width: 4px;
    z-index: 10000;
  }

  .column-resize-handle.bottom-handle {
    bottom: 0;
  }

  .column-resize-handle.top-handle {
    top: 0;
  }

  .row-resize-handle {
    background-color: var(--editor-table-resize-handle-color);
    bottom: -4px;
    height: 4px;
    left: -2px;
    max-width: unset !important;
    pointer-events: none;
    position: absolute;
    right: -2px;
    width: unset !important;
    z-index: 20, 10000;
  }

  .row-resize-handle.left-handle {
    left: 0;
  }

  .row-resize-handle.right-handle {
    right: 0;
  }

  .ProseMirror {
    --editor-table-resize-handle-color: #adf;
    outline: none;
    white-space: pre-wrap;
    line-height: normal;
  }

  .ProseMirror p {
    margin: 0;
  }

  .ProseMirror .tableWrapper .floating-button {
    opacity: 0;
    position: absolute;
    transition: opacity 0.2s ease-in-out;
  }

  .ProseMirror code .inline-boundary {
    background-color: #b4d7ff;
  }

  .ProseMirror .code-block-wrapper {
    background-color: var(--cx-color-neutral-50);
    border-radius: var(--cx-border-radius-medium);
    color: var(--cx-color-neutral-700);
    min-height: 3rem;
    padding: var(--cx-spacing-x-small);
    position: relative;
    white-space: normal;
  }

  .ProseMirror .code-block-wrapper cx-rte-code-block-toolbar {
    display: flex;
    gap: var(--cx-spacing-small);
    position: absolute;
    right: var(--cx-spacing-2x-small);
    top: var(--cx-spacing-2x-small);
  }

  .ProseMirror .code-block-wrapper cx-rte-code-block-toolbar,
  .ProseMirror .code-block-wrapper cx-rte-code-block-toolbar.hidden {
    opacity: 0;
    pointer-events: none;
  }

  .ProseMirror .code-block-wrapper:hover cx-rte-code-block-toolbar:not(.hidden),
  .ProseMirror .code-block-wrapper cx-rte-code-block-toolbar.open {
    opacity: 1;
    pointer-events: auto;
  }

  .ProseMirror .floating-button {
    position: absolute;
  }

  .ProseMirror .mce-item-anchor {
    position: relative;
    text-decoration: none !important;
  }

  /* Bookmark glyph: inline SVG mask (no FontAwesome / no extra font import). */
  .ProseMirror .mce-item-anchor::before {
    background-color: var(--cx-color-neutral-700);
    content: '';
    display: inline-block;
    height: 0.75rem;
    margin-inline-end: var(--cx-spacing-3x-small, 2px);
    -webkit-mask: url('data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20fill%3D%22black%22%20d%3D%22M17%203H7c-1.1%200-1.99.9-1.99%202L5%2021l7-3%207%203V5c0-1.1-.9-2-2-2zm0%2015l-5-2.18L7%2018V5h10v13z%22%2F%3E%3C%2Fsvg%3E')
      center / contain no-repeat;
    mask: url('data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%2024%2024%22%3E%3Cpath%20fill%3D%22black%22%20d%3D%22M17%203H7c-1.1%200-1.99.9-1.99%202L5%2021l7-3%207%203V5c0-1.1-.9-2-2-2zm0%2015l-5-2.18L7%2018V5h10v13z%22%2F%3E%3C%2Fsvg%3E')
      center / contain no-repeat;
    width: 0.75rem;
  }

  .ProseMirror .tableWrapper {
    position: relative;
  }

  .ProseMirror .tableWrapper:hover .floating-button,
  .ProseMirror .tableWrapper.ProseMirror-selectednode .floating-button {
    opacity: 1;
  }

  .ProseMirror code {
    font-family: monospace;
  }

  .ProseMirror code [class*='InLn-'] {
    font-family: inherit;
  }

  .ProseMirror blockquote {
    border-left: 3px solid var(--cx-color-neutral-300);
    display: block;
    margin-block-end: 1em;
    margin-block-start: 1em;
    margin-inline-end: 40px;
    margin-inline-start: 40px;
    padding-left: 1rem;
  }

  .ProseMirror p.is-editor-empty {
    font-family: var(--cx-font-sans);
    position: relative;
  }

  .ProseMirror p.is-editor-empty:first-child::before {
    color: var(--cx-color-neutral-1000);
    content: attr(data-placeholder);
    display: block;
    font-weight: 400;
    height: 100%;
    opacity: 0.25;
    overflow: hidden;
    pointer-events: none;
    position: absolute;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
  }

  .rich-text--editable .ProseMirror-selectednode>table {
    outline: 2px dashed var(--cx-color-primary);
    outline-offset: -2px;
  }

  .ProseMirror figure {
    margin: 0;
  }

  .ProseMirror table .selectedCell:after {
    background: var(--cx-color-neutral-300);
    bottom: 0;
    content: '';
    height: 100%;
    left: 0;
    opacity: 0.4;
    pointer-events: none;
    position: absolute;
    right: 0;
    top: 0;
    z-index: 2;
  }

  .ProseMirror table td,
  .ProseMirror table th {
    border: 1px dashed var(--cx-color-neutral-400);
    min-width: 1rem;
    position: relative;
  }

  .ProseMirror table[data-align='center'] {
    margin-left: auto;
    margin-right: auto;
  }

  .ProseMirror table[data-align='right'] {
    margin-left: auto;
  }

  .ProseMirror.cursor-col-resize {
    cursor: col-resize;
  }

  .ProseMirror.cursor-row-resize {
    cursor: row-resize;
  }

  pre[class*='language-'],
  code[class*='language-'] {
    color: #d4d4d4;
    font-size: var(--cx-font-size-x-small);
    text-shadow: none;
    font-family:
      Menlo, Monaco, Consolas, 'Andale Mono', 'Ubuntu Mono', 'Courier New',
      monospace;
    direction: ltr;
    text-align: left;
    white-space: pre;
    word-spacing: normal;
    word-break: normal;
    line-height: 1.5;
    tab-size: 4;
    hyphens: none;
  }

  pre[class*='language-']::selection,
  code[class*='language-']::selection,
  pre[class*='language-'] *::selection,
  code[class*='language-'] *::selection {
    text-shadow: none;
    background: #75a7ca;
  }

  @media print {
    pre[class*='language-'],
    code[class*='language-'] {
      text-shadow: none;
    }
  }

  pre[class*='language-'] {
    padding: 1em;
    margin: 0.5em 0;
    overflow: auto;
    background: #1e1e1e;
  }

  :not(pre) > code[class*='language-'] {
    padding: 0.1em 0.3em;
    border-radius: 0.3em;
    color: #db4c69;
    background: #f9f2f4;
  }

  /*********************************************************
* Tokens
*/
  .namespace {
    opacity: 0.7;
  }

  .token.doctype .token.doctype-tag {
    color: #569cd6;
  }

  .token.doctype .token.name {
    color: #9cdcfe;
  }

  .token.comment,
  .token.prolog {
    color: #6a9955;
  }

  .token.punctuation,
  .language-html .language-css .token.punctuation,
  .language-html .language-javascript .token.punctuation {
    color: #d4d4d4;
  }

  .token.property,
  .token.tag,
  .token.boolean,
  .token.number,
  .token.constant,
  .token.symbol,
  .token.deleted,
  .token.unit {
    color: #b5cea8;
  }

  .token.selector,
  .token.attr-name,
  .token.string,
  .token.char,
  .token.builtin,
  .token.inserted {
    color: #ce9178;
  }

  .language-css .token.string.url {
    text-decoration: underline;
  }

  .token.operator,
  .token.entity {
    color: #d4d4d4;
  }

  .token.operator.arrow {
    color: #569cd6;
  }

  .token.atrule {
    color: #ce9178;
  }

  .token.atrule .token.rule {
    color: #c586c0;
  }

  .token.atrule .token.url {
    color: #9cdcfe;
  }

  .token.atrule .token.url .token.function {
    color: #dcdcaa;
  }

  .token.atrule .token.url .token.punctuation {
    color: #d4d4d4;
  }

  .token.keyword {
    color: #569cd6;
  }

  .token.keyword.module,
  .token.keyword.control-flow {
    color: #c586c0;
  }

  .token.function,
  .token.function .token.maybe-class-name {
    color: #dcdcaa;
  }

  .token.regex {
    color: #d16969;
  }

  .token.important {
    color: #569cd6;
  }

  .token.italic {
    font-style: italic;
  }

  .token.constant {
    color: #9cdcfe;
  }

  .token.class-name,
  .token.maybe-class-name {
    color: #4ec9b0;
  }

  .token.console {
    color: #9cdcfe;
  }

  .token.parameter {
    color: #9cdcfe;
  }

  .token.interpolation {
    color: #9cdcfe;
  }

  .token.punctuation.interpolation-punctuation {
    color: #569cd6;
  }

  .token.boolean {
    color: #569cd6;
  }

  .token.property,
  .token.variable,
  .token.imports .token.maybe-class-name,
  .token.exports .token.maybe-class-name {
    color: #9cdcfe;
  }

  .token.selector {
    color: #d7ba7d;
  }

  .token.escape {
    color: #d7ba7d;
  }

  .token.tag {
    color: #569cd6;
  }

  .token.tag .token.punctuation {
    color: #808080;
  }

  .token.cdata {
    color: #808080;
  }

  .token.attr-name {
    color: #9cdcfe;
  }

  .token.attr-value,
  .token.attr-value .token.punctuation {
    color: #ce9178;
  }

  .token.attr-value .token.punctuation.attr-equals {
    color: #d4d4d4;
  }

  .token.entity {
    color: #569cd6;
  }

  .token.namespace {
    color: #4ec9b0;
  }

  /*********************************************************
* Language Specific
*/

  pre[class*='language-javascript'],
  code[class*='language-javascript'],
  pre[class*='language-jsx'],
  code[class*='language-jsx'],
  pre[class*='language-typescript'],
  code[class*='language-typescript'],
  pre[class*='language-tsx'],
  code[class*='language-tsx'] {
    color: #9cdcfe;
  }

  pre[class*='language-css'],
  code[class*='language-css'] {
    color: #ce9178;
  }

  pre[class*='language-html'],
  code[class*='language-html'] {
    color: #d4d4d4;
  }

  .language-regex .token.anchor {
    color: #dcdcaa;
  }

  .language-html .token.punctuation {
    color: #808080;
  }

  /*********************************************************
* Line highlighting
*/
  pre[data-line] {
    position: relative;
  }

  pre[class*='language-'] > code[class*='language-'] {
    position: relative;
    z-index: 1;
  }

  .line-highlight {
    position: absolute;
    left: 0;
    right: 0;
    padding: 0;
    margin-top: 1em;
    background: #f7ebc6;
    box-shadow: inset 5px 0 0 #f7d87c;
    z-index: 0;
    pointer-events: none;
    line-height: inherit;
    white-space: pre;
  }

  .bg-find-in-selection-range {
    background-color: var(--cx-color-neutral-300);
  }

  /* search result rules come after gray in cascade so they win when both classes land on the same element */
  .bg-search-result {
    background-color: var(--cx-color-success-300);
  }

  .bg-light-search-result {
    background-color: var(--cx-color-success-400);
  }

  /* when gray is nested inside a search-result span, let the outer green show through */
  .bg-search-result .bg-find-in-selection-range,
  .bg-light-search-result .bg-find-in-selection-range {
    background-color: transparent;
  }

  span.mention {
    cursor: not-allowed;
  }

  ${C}
`;
var o = /* @__PURE__ */ ((e) => (e.H1 = "h1", e.H2 = "h2", e.H3 = "h3", e.H4 = "h4", e.H5 = "h5", e.H6 = "h6", e))(o || {}), f = /* @__PURE__ */ ((e) => (e.Center = "center", e.Justify = "justify", e.Left = "left", e.Right = "right", e))(f || {});
const A = p`:host{--color:light-dark(#000,#fff);--font-family:var(--cx-font-sans);--text-align:left;--line-height:1;--padding:0;width:100%;display:block}:host([alignment=center]) .container{--text-align:center;justify-content:center}:host([alignment=right]) .container{--text-align:right;flex-direction:row-reverse}:host([alignment=left]) .container{--text-align:left;justify-content:flex-start}:host([alignment=justify]) .container{--text-align:justify;justify-content:flex-start}.container{padding:var(--padding,0px);flex-direction:row;align-items:center;display:flex}.container ::slotted(p),.container p{word-wrap:break-word}.heading{color:var(--color);font-family:var(--font-family);text-align:var(--text-align,left);max-width:100%;min-height:calc(var(--line-height,1) * 1em);flex:auto;min-height:1lh;margin-block:0}.container.container--has-copy-button .heading{flex:none;max-width:calc(100% - 32px)}.copy-button{opacity:0;transition:opacity var(--cx-transition-fast);color:var(--cx-color-neutral-600);pointer-events:none;user-select:none;line-height:0}.container:hover .copy-button,.copy-button:focus-within{opacity:1;pointer-events:auto;user-select:auto}.heading-1{font-size:var(--cx-font-size-3x-large);font-weight:var(--cx-font-weight-semibold);line-height:var(--line-height,var(--cx-line-height-3x-large))}.heading-2{font-size:var(--cx-font-size-2x-large);font-weight:var(--cx-font-weight-semibold);line-height:var(--line-height,var(--cx-line-height-3x-large))}.heading-3{font-size:var(--cx-font-size-x-large);font-weight:var(--cx-font-weight-semibold);line-height:var(--line-height,var(--cx-line-height-2x-large))}.heading-4{font-size:var(--cx-font-size-large);font-weight:var(--cx-font-weight-semibold);line-height:var(--line-height,var(--cx-line-height-x-large))}.heading-5{font-size:var(--cx-font-size-medium);font-weight:var(--cx-font-weight-semibold);line-height:var(--line-height,var(--cx-line-height-large))}.heading-6{font-size:var(--cx-font-size-small);font-weight:var(--cx-font-weight-semibold);line-height:var(--line-height,var(--cx-line-height-medium))}`;
var H = Object.defineProperty, L = Object.getOwnPropertyDescriptor, n = (e, r, a, i) => {
  for (var c = i > 1 ? void 0 : i ? L(r, a) : r, h = e.length - 1, g; h >= 0; h--)
    (g = e[h]) && (c = (i ? g(r, a, c) : g(c)) || c);
  return i && c && H(r, a, c), c;
};
const S = {
  [o.H1]: "heading-1",
  [o.H2]: "heading-2",
  [o.H3]: "heading-3",
  [o.H4]: "heading-4",
  [o.H5]: "heading-5",
  [o.H6]: "heading-6"
}, T = {
  [o.H1]: l`h1`,
  [o.H2]: l`h2`,
  [o.H3]: l`h3`,
  [o.H4]: l`h4`,
  [o.H5]: l`h5`,
  [o.H6]: l`h6`
};
let t = class extends k {
  constructor() {
    super(), this.localize = new y(this), this.variant = o.H6, this.fontSize = void 0, this.hasAnchorLink = !1, this.anchorLink = "", this.alignment = f.Left, this.disabledCopyButton = !1, this.cms5PageReadyTimeout = null, this.scrollToAnchor = () => {
      const e = this.getAnchorID();
      !e || e !== this.anchorID || this.scrollIntoView({
        block: "start"
      });
    }, this.handleClick = this.handleClick.bind(this), this.handleCMS5PageReady = this.handleCMS5PageReady.bind(this);
  }
  /**
   * Get the owner window
   */
  get ownerWindow() {
    return this.ownerDocument.defaultView ?? window;
  }
  /**
   * Get the anchor ID for the header.
   * If `hasAnchorLink` is false, it returns an empty string.
   * If `anchorLink` is provided, it returns that.
   * Otherwise, it generates an anchor based on the text content of the header,
   */
  get anchorID() {
    return this.hasAnchorLink && (this.anchorLink || this.textContent?.trim().replace(/\s+/g, "-").toLowerCase()) || "";
  }
  runFirstUpdated() {
    setTimeout(() => {
      this.scrollToAnchor();
    }, 200);
  }
  runConnectedCallback() {
    this.addEventListener("click", this.handleClick), this.setAttribute("role", "heading"), this.hasAnchorLink && (this.ownerWindow.addEventListener("hashchange", this.scrollToAnchor), this.ownerWindow.addEventListener(
      "cx-cms5-page-ready",
      this.handleCMS5PageReady,
      {
        once: !0
      }
    ));
  }
  disconnectedCallback() {
    super.disconnectedCallback(), this.removeEventListener("click", this.handleClick), this.ownerWindow.removeEventListener("hashchange", this.scrollToAnchor), this.ownerWindow.removeEventListener(
      "cx-cms5-page-ready",
      this.scrollToAnchor
    ), this.cms5PageReadyTimeout && (clearTimeout(this.cms5PageReadyTimeout), this.cms5PageReadyTimeout = null);
  }
  /**
   * Scroll to anchor after CMS5 page is ready
   * Wait 100ms for repaint reflow shift layout (not affect by fetching api in web component)
   */
  handleCMS5PageReady() {
    this.cms5PageReadyTimeout && clearTimeout(this.cms5PageReadyTimeout), this.cms5PageReadyTimeout = setTimeout(() => {
      this.scrollToAnchor();
    }, 100);
  }
  handleClick(e) {
    this.contentEditable === "true" && e.stopPropagation();
  }
  getAnchorID() {
    let e = "";
    const a = this.ownerWindow.location.href.split("#");
    return a.length > 1 && (e = decodeURIComponent(a[1])), e;
  }
  /**
   * After Tiptap editor is destroyed, the slot element is removed.
   * This method is used to re-add the slot element.
   */
  addSlotElement() {
    if (this.defaultSlot || !this.heading)
      return;
    const e = this.ownerDocument.createElement("slot");
    this.heading.appendChild(e);
  }
  handleHeadingChange() {
    this.setAttribute("aria-level", this.variant.replace("h", ""));
  }
  handleCopyButtonClick(e) {
    e.stopPropagation();
  }
  renderHeading(e) {
    const r = S[this.variant], a = T[this.variant], i = /\d/.test(this.fontSize || "");
    return d`<${a} part="heading" class=${u({ heading: !0, [r]: !0 })} style=${P({
      fontSize: i ? this.fontSize : void 0,
      /**
       * Reset line-height to the font's natural value so descenders fit
       * inside the heading box; the host's tight `--line-height: 1`
       * truncates glyph metrics at large custom font sizes and triggers a
       * scrollbar in overflow:auto parents (e.g. cx-column).
       */
      lineHeight: i ? "normal" : void 0
    })}>${e}</${a}>`;
  }
  render() {
    const e = this.hasAnchorLink ? `${this.ownerWindow.location.href.split("#")[0]}#${encodeURIComponent(this.anchorID)}` : "", r = this.hasAnchorLink && !this.disabledCopyButton;
    return d`<div part="base" class=${u({
      container: !0,
      "container--has-copy-button": r
    })}>${this.renderHeading(d`<slot></slot>`)}
        ${M(r, () => d`<cx-copy-button part="copy-button" class="copy-button" value=${e} hoist="" label=${this.localize.term("copy")} @click=${this.handleCopyButtonClick}><cx-icon slot="copy-icon" name="attachment"></cx-icon></cx-copy-button>`)}</div>`;
  }
};
t.styles = [
  b,
  z,
  A
];
t.dependencies = {
  "cx-copy-button": x
};
n([
  m("slot")
], t.prototype, "defaultSlot", 2);
n([
  m(".heading")
], t.prototype, "heading", 2);
n([
  s({ reflect: !0, type: String })
], t.prototype, "variant", 2);
n([
  s({ attribute: "font-size", reflect: !0, type: String })
], t.prototype, "fontSize", 2);
n([
  s({ attribute: "has-anchor-link", type: Boolean })
], t.prototype, "hasAnchorLink", 2);
n([
  s({ attribute: "anchor-link", type: String })
], t.prototype, "anchorLink", 2);
n([
  s({ type: String })
], t.prototype, "alignment", 2);
n([
  s({ attribute: "disabled-copy-button", reflect: !0, type: Boolean })
], t.prototype, "disabledCopyButton", 2);
n([
  w("variant")
], t.prototype, "handleHeadingChange", 1);
t = n([
  v("cx-header")
], t);
export {
  f as A,
  t as C,
  o as V
};
