carbon-react
Version:
A library of reusable React components for easily building user interfaces.
2 lines (1 loc) • 3.28 kB
JavaScript
"use strict";var t=require("lexical");function e(t,e,i){return e in t?Object.defineProperty(t,e,{value:i,enumerable:!0,configurable:!0,writable:!0}):t[e]=i,t}const i={title:{weight:"700",lineHeight:"30px",size:"24px"},subtitle:{weight:"500",lineHeight:"26.25px",size:"21px"},sectionHeader:{weight:"500",lineHeight:"22.5px",size:"18px"},sectionSubheader:{weight:"500",lineHeight:"20px",size:"16px"},paragraph:{weight:"400",lineHeight:"21px",size:"14px"}};class n extends t.TextNode{static getType(){return"styled-span"}static clone(t){return new n(t.__text,t.__fontWeight,t.__fontSize,t.__lineHeight,t.__key)}getFontWeight(){return this.__fontWeight}getFontSize(){return this.__fontSize}getLineHeight(){return this.__lineHeight}setFontWeight(t){this.getWritable().__fontWeight=t}setFontSize(t){this.getWritable().__fontSize=t}setLineHeight(t){this.getWritable().__lineHeight=t}getTypographyKey(){for(const t of Object.keys(i)){const{weight:e,size:n,lineHeight:r}=i[t];if(this.__fontWeight===e&&this.__fontSize===n&&this.__lineHeight===r)return t}return"paragraph"}exportDOM(){const t=document.createElement("span");return t.style.fontWeight=this.__fontWeight,t.style.fontSize=this.__fontSize,t.style.lineHeight=this.__lineHeight,t.textContent=this.getTextContent(),{element:t}}static importDOM(){return{span:t=>({conversion:()=>{const e=t.style.fontWeight||"400",i=t.style.fontSize||"14px",r=t.style.lineHeight||"21px";return{node:new n(t.textContent||"",e,i,r)}},priority:1})}}exportJSON(){return t=function(t){for(var i=1;i<arguments.length;i++){var n=null!=arguments[i]?arguments[i]:{},r=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(n).filter((function(t){return Object.getOwnPropertyDescriptor(n,t).enumerable})))),r.forEach((function(i){e(t,i,n[i])}))}return t}({},super.exportJSON()),i=null!=(i={type:"styled-span",version:1,fontWeight:this.__fontWeight,fontSize:this.__fontSize,lineHeight:this.__lineHeight})?i:{},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):function(t){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e.push.apply(e,i)}return e}(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))})),t;var t,i}static importJSON(t){return new n(t.text,t.fontWeight,t.fontSize,t.lineHeight)}createDOM(t){const e=super.createDOM(t);return e.style.fontWeight=this.__fontWeight,e.style.fontSize=this.__fontSize,e.style.lineHeight=this.__lineHeight,e}updateDOM(t,e,i){let n=super.updateDOM(this,e,i);return this.__fontWeight!==t.__fontWeight&&(e.style.fontWeight=this.__fontWeight,n=!0),this.__fontSize!==t.__fontSize&&(e.style.fontSize=this.__fontSize,n=!0),this.__lineHeight!==t.__lineHeight&&(e.style.lineHeight=this.__lineHeight,n=!0),n}static createFromOption(t,e=""){const{weight:r,size:o,lineHeight:s}=i[t];return new n(e,r,o,s)}constructor(t,i,n,r,o){super(t,o),e(this,"__fontWeight",void 0),e(this,"__fontSize",void 0),e(this,"__lineHeight",void 0),this.__fontWeight=i,this.__fontSize=n,this.__lineHeight=r}}exports.$createStyledSpanNode=function(t,e,i,r){return new n(t,e,i,r)},exports.$isStyledSpanNode=function(t){return t instanceof n},exports.StyledSpanNode=n;