UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

2 lines (1 loc) 1.36 kB
var i=Object.defineProperty;var r=(s,t)=>i(s,"name",{value:t,configurable:!0});import{detectActiveStyle as m}from"./detect-active-style.js";import{IS_BLOCK as c}from"jodit/esm/core/constants.js";import{Dom as l}from"jodit/esm/core/dom/dom.js";function a(s,t){const n=s.s.current();if(!n)return null;if(c.test(t.element))return l.closest(n,l.isBlock,s.editor);let e=l.isElement(n)?n:n.parentNode;for(;e&&e!==s.editor;){if(l.isElement(e)&&e.nodeName.toLowerCase()===t.element)return e;e=e.parentNode}return null}r(a,"findTarget");function o(s,t){for(const n of t)s.classList.remove(n);s.className===""&&s.removeAttribute("class")}r(o,"removeClassesFromElement");function u(s,t){if(t.classes.length<=1)return;const n=s.s.current();if(n)if(c.test(t.element)){const e=l.closest(n,l.isBlock,s.editor);e&&o(e,t.classes.slice(1))}else{const e=a(s,t);e&&(o(e,t.classes.slice(1)),e.nodeName.toLowerCase()==="span"&&!e.attributes.length&&l.unwrap(e))}}r(u,"cleanupExtraClasses");function f(s,t){if(t.classes.length<=1)return;const n=a(s,t);if(n)for(let e=1;e<t.classes.length;e++)n.classList.add(t.classes[e])}r(f,"addExtraClasses");function h(s,t,n){const e=m(s,n);e&&(s.s.commitStyle({element:e.element,attributes:{class:e.classes[0]}}),u(s,e),e===t)||(s.s.commitStyle({element:t.element,attributes:{class:t.classes[0]}}),f(s,t))}r(h,"applyStyle");export{h as applyStyle};