UNPKG

jodit-pro

Version:

PRO Version of Jodit Editor

6 lines (5 loc) 3.88 kB
var O=Object.defineProperty;var b=(u,o)=>O(u,"name",{value:o,configurable:!0});var f,_=function(u,o,e,d){var n=arguments.length,r=n<3?o:d===null?d=Object.getOwnPropertyDescriptor(o,e):d,l;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")r=Reflect.decorate(u,o,e,d);else for(var t=u.length-1;t>=0;t--)(l=u[t])&&(r=(n<3?l(r):n>3?l(o,e,r):l(o,e))||r);return n>3&&r&&Object.defineProperty(o,e,r),r},x;import{component as R,watch as B}from"jodit/esm/core/decorators/index.js";import{css as w}from"jodit/esm/core/helpers/index.js";import{isString as I}from"jodit/esm/core/helpers/checker/index.js";import{assert as v}from"jodit/esm/core/helpers/utils/assert.js";import{UIElement as X}from"jodit/esm/core/ui/index.js";let p=x=(f=class extends X{className(){return"UIGButton"}constructor(o,e){super(o),this.style=e,this.__updateStyles()}__updateStyles(){const{style:o}=this,e=this.getElm("button");v(e!=null,"button element does not exist");const d=this.getElm("wrapper");v(d!=null,"wrapper element does not exist"),d.style.backgroundColor=o.previewBgColor,x.applyStyle(o,e)}static applyStyle(o,e){const d=b(n=>I(n)?n:n+"px","_");e.innerText=o.text||"css",e.setAttribute("href",o.href),w(e,{background:o.solid?null:`linear-gradient(to bottom, ${o.bgStart} 5%, ${o.bgEnd} 100%)`,backgroundColor:o.bgStart,borderRadius:d(o.borderRadius),border:`${d(o.borderSize)} solid ${o.borderColor}`,display:"inline-block",cursor:"pointer",color:o.fontColor,fontFamily:o.fontFamily,fontSize:d(o.fontSize),fontWeight:o.fontWeight?"bold":null,fontStyle:o.fontItalic?"italic":null,padding:`${d(o.paddingY)} ${d(o.paddingX)}`,textDecoration:"none"}),w(e,{textShadow:o.textShadow?[o.textShadowOffsetX,o.textShadowOffsetY,o.textShadowBlurRadius,o.textShadowColor].map(d).join(" "):null}),w(e,{boxShadow:o.boxShadow?[o.boxShadowInset?"inset":"",o.boxShadowOffsetX,o.boxShadowOffsetY,o.boxShadowBlurRadius,o.boxShadowSpreadRadius,o.boxShadowColor].map(d).join(" "):null})}update(){this.__updateStyles()}render(){return`<div> <div class='&__wrapper'> <button class='&__button'>css</button> </div> </div>`}static extractStyle(o,e){var d,n,r,l;const t=((d=e.ownerDocument.defaultView)===null||d===void 0?void 0:d.getComputedStyle(e))||{},C=b(()=>{var c,a;const i={solid:!0,bgStart:(c=t.backgroundColor)!==null&&c!==void 0?c:"#44c767",bgEnd:(a=t.backgroundColor)!==null&&a!==void 0?a:"#44c767"},S=t.backgroundImage;if(S&&/linear-gradient/.test(S)){const s=/linear-gradient\((.+)\s+[0-9]+%,\s+(.+)\s+[0-9]+%\)/.exec(S);s&&(i.solid=!1,i.bgStart=s[1]||i.bgStart,i.bgEnd=s[2]||"#5cbf2a")}return i},"extractColors"),m=b((c,a,i,S)=>{const s=t[i];return!s||["none","inherit","initial","unset"].includes(s)?{[i]:!1}:(s.replace(/,\s/g,",").split(/\s+/).forEach(h=>{if(/[0-9.]+(px|pt|em|%)/.test(h)){const g=c.shift();g&&(a[g]=h)}else h==="inset"?a.boxShadowInset=!0:a[S]=h}),a[i]=!0,a)},"extractShadow");Object.assign(o,{text:e.innerText,className:e.className,href:e.getAttribute("href")||"",...C(),borderColor:(n=t?.borderColor)!==null&&n!==void 0?n:"#18ab29",borderRadius:(r=t?.borderRadius)!==null&&r!==void 0?r:0,borderSize:(l=t?.borderWidth)!==null&&l!==void 0?l:1,...m(["boxShadowOffsetX","boxShadowOffsetY","boxShadowBlurRadius","boxShadowSpreadRadius"],{boxShadowBlurRadius:0,boxShadowColor:"#3dc21b",boxShadowInset:!1,boxShadowOffsetX:0,boxShadowOffsetY:0,boxShadowSpreadRadius:0},"boxShadow","boxShadowColor"),fontColor:t.color,fontFamily:t.fontFamily,fontSize:t.fontSize,fontWeight:t.fontWeight==="bold",fontItalic:t.fontStyle==="italic",paddingX:t.paddingLeft,paddingY:t.paddingTop,...m(["textShadowOffsetX","textShadowOffsetY","textShadowBlurRadius"],{textShadowBlurRadius:0,textShadowColor:"#2f6627",textShadowOffsetX:0,textShadowOffsetY:1},"textShadow","textShadowColor")})}},b(f,"UIGButton"),f);_([B("style")],p.prototype,"__updateStyles",null),p=x=_([R],p);export{p as UIGButton};