Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ricos-styles

Package Overview
Dependencies
Maintainers
1
Versions
416
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ricos-styles - npm Package Compare versions

Comparing version 8.72.9 to 8.72.10

2

dist/cjs/index.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _extends=require("@babel/runtime/helpers/extends"),_objectWithoutPropertiesLoose=require("@babel/runtime/helpers/objectWithoutPropertiesLoose"),ricosContent=require("ricos-content"),utils=require("ricos-content/libs/utils"),_inheritsLoose=require("@babel/runtime/helpers/inheritsLoose"),ricosCommon=require("ricos-common"),lodash=require("lodash");function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var _extends__default=_interopDefaultLegacy(_extends),_objectWithoutPropertiesLoose__default=_interopDefaultLegacy(_objectWithoutPropertiesLoose),_inheritsLoose__default=_interopDefaultLegacy(_inheritsLoose),EmptyDecoration=function(){function EmptyDecoration(){this.type="UNRECOGNIZED"}var _proto=EmptyDecoration.prototype;return _proto.getDecoration=function(){return{}},_proto.fromCustomStyle=function(_customStyle){return new EmptyDecoration},_proto.toCustomStyle=function(){return{}},_proto.overrideWith=function(decoration){return decoration},EmptyDecoration}(),BoldDecoration=function(){function BoldDecoration(customStyle){this.type="BOLD",this.customStyle=void 0,this.customStyle=customStyle}BoldDecoration.of=function(decoration){if("BOLD"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);return new BoldDecoration({fontWeight:decoration.fontWeightValue||700})};var _proto=BoldDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,fontWeightValue:parseInt(this.customStyle.fontWeight,10)||700}},BoldDecoration.fromCustomStyle=function(customStyle){return new BoldDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return BoldDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof BoldDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new BoldDecoration(_extends__default.default({},this.customStyle,decoration.toCustomStyle()))},BoldDecoration}(),ColorDecoration=function(){function ColorDecoration(customStyle){this.type="COLOR",this.customStyle=void 0,this.customStyle=customStyle}ColorDecoration.of=function(decoration){if("COLOR"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);var _ref=decoration.colorData||{};return new ColorDecoration({color:_ref.foreground,backgroundColor:_ref.background})};var _proto=ColorDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,colorData:_extends__default.default({},this.customStyle.color&&{foreground:this.customStyle.color},this.customStyle.backgroundColor&&{background:this.customStyle.backgroundColor})}},ColorDecoration.fromCustomStyle=function(customStyle){return new ColorDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return ColorDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof ColorDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new ColorDecoration(_extends__default.default({},this.customStyle,decoration.toCustomStyle()))},ColorDecoration}(),FontSizeDecoration=function(){function FontSizeDecoration(customStyle){this.type="FONT_SIZE",this.customStyle=void 0,this.customStyle=customStyle}FontSizeDecoration.of=function(decoration){var _decoration$fontSizeD,_decoration$fontSizeD2,_decoration$fontSizeD3;if("FONT_SIZE"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);var value=null===(_decoration$fontSizeD=decoration.fontSizeData)||void 0===_decoration$fontSizeD?void 0:_decoration$fontSizeD.value,unit=null===(_decoration$fontSizeD2=decoration.fontSizeData)||void 0===_decoration$fontSizeD2||null===(_decoration$fontSizeD3=_decoration$fontSizeD2.unit)||void 0===_decoration$fontSizeD3?void 0:_decoration$fontSizeD3.toLocaleLowerCase();return new FontSizeDecoration(value?{fontSize:""+value+unit}:{})};var _proto=FontSizeDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,fontSizeData:{value:parseInt(this.customStyle.fontSize),unit:"PX"}}},FontSizeDecoration.fromCustomStyle=function(customStyle){return new FontSizeDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return FontSizeDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof FontSizeDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new FontSizeDecoration(_extends__default.default({},this.customStyle,decoration.toCustomStyle()))},FontSizeDecoration}(),ItalicDecoration=function(){function ItalicDecoration(customStyle){this.type="ITALIC",this.customStyle=void 0,this.customStyle=customStyle}ItalicDecoration.of=function(decoration){if("ITALIC"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);return new ItalicDecoration(decoration.italicData?{fontStyle:"italic"}:{})};var _proto=ItalicDecoration.prototype;return _proto.getDecoration=function(){var _this$customStyle$fon;return{type:this.type,italicData:null===(_this$customStyle$fon=this.customStyle.fontStyle)||void 0===_this$customStyle$fon?void 0:_this$customStyle$fon.includes("italic")}},ItalicDecoration.fromCustomStyle=function(customStyle){return new ItalicDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return ItalicDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof ItalicDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new ItalicDecoration(_extends__default.default({},this.customStyle,decoration.toCustomStyle()))},ItalicDecoration}(),_excluded=["color","backgroundColor"],Decorations=function(){function Decorations(textDecorations){this.decorations=void 0,this.decorations=textDecorations}Decorations.of=function(decorations){return new Decorations((decorations||[]).map(Decorations.toTextDecoration))},Decorations.fromCustomStyle=function(customStyle){var color=customStyle.color,backgroundColor=customStyle.backgroundColor,rest=_objectWithoutPropertiesLoose__default.default(customStyle,_excluded),colorStyle={color:color,backgroundColor:backgroundColor};return new Decorations(Object.entries(rest).map((function(_ref){var _ref2,k=_ref[0],v=_ref[1];return(_ref2={})[k]=v,_ref2})).concat([colorStyle]).map(Decorations.styleToDecoration))},Decorations.styleToDecoration=function(style){return ricosContent.firstRight(style,Decorations.empty,[[function(s){return!!s.fontWeight},function(s){return BoldDecoration.fromCustomStyle(s)}],[function(s){return!!s.fontSize},function(s){return FontSizeDecoration.fromCustomStyle(s)}],[function(s){return!!s.fontStyle},function(s){return ItalicDecoration.fromCustomStyle(s)}],[function(s){return!!s.color},function(s){return ColorDecoration.fromCustomStyle(s)}]])},Decorations.toTextDecoration=function(decoration){return ricosContent.firstRight(decoration,Decorations.empty,[[function(d){return"BOLD"===d.type},function(d){return BoldDecoration.of(d)}],[function(d){return"ITALIC"===d.type},function(d){return ItalicDecoration.of(d)}],[function(d){return"FONT_SIZE"===d.type},function(d){return FontSizeDecoration.of(d)}],[function(d){return"COLOR"===d.type},function(d){return ColorDecoration.of(d)}]])};var _proto=Decorations.prototype;return _proto.toDecorationArray=function(){return this.decorations.filter((function(d){return"UNRECOGNIZED"!==d.type})).map((function(d){return d.getDecoration()}))},_proto.byType=function(type){return this.decorations.find((function(d){return d.type===type}))||Decorations.empty},_proto.toCustomStyle=function(){return this.decorations.reduce((function(style,decoration){return _extends__default.default({},style,decoration.toCustomStyle())}),{})},_proto.overrideWith=function(decorations){var _this=this,overridenDecorations=decorations.map(Decorations.toTextDecoration).map((function(decoration){return _this.byType(decoration.type).overrideWith(decoration)})),types=overridenDecorations.map((function(decoration){return decoration.type}));return new Decorations(this.decorations.filter((function(decoration){return!types.includes(decoration.type)})).concat(overridenDecorations))},Decorations}();function flow(ab,bc,cd,de,ef,fg,gh,hi,ij){switch(arguments.length){case 1:return ab;case 2:return function(){return bc(ab.apply(this,arguments))};case 3:return function(){return cd(bc(ab.apply(this,arguments)))};case 4:return function(){return de(cd(bc(ab.apply(this,arguments))))};case 5:return function(){return ef(de(cd(bc(ab.apply(this,arguments)))))};case 6:return function(){return fg(ef(de(cd(bc(ab.apply(this,arguments))))))};case 7:return function(){return gh(fg(ef(de(cd(bc(ab.apply(this,arguments)))))))};case 8:return function(){return hi(gh(fg(ef(de(cd(bc(ab.apply(this,arguments))))))))};case 9:return function(){return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this,arguments)))))))))}}}Decorations.empty=new EmptyDecoration;var map=function(f){return function(fa){return fa.map((function(a){return f(a)}))}},Ord={equals:function(first,second){return first===second},compare:function(first,second){return first<second?-1:first>second?1:0}};function collect(O){if("function"==typeof O)return collect(Ord)(O);var keysO=function(O){return function(r){return Object.keys(r).sort(O.compare)}}(O);return function(f){return function(r){for(var out=[],_i=0,_a=keysO(r);_i<_a.length;_i++){var key=_a[_i];out.push(f(key,r[key]))}return out}}}var toArray=collect(Ord)((function(k,a){return[k,a]}));var fst=function(ea){return ea[0]},snd=function(ea){return ea[1]},bimap=function(f,g){return function(fa){return[g(fst(fa)),f(snd(fa))]}},CustomStyle=function(){function CustomStyle(key,customStyle){this.key=void 0,this.customStyle=void 0,this.key=key,this.customStyle=customStyle}var _proto=CustomStyle.prototype;return _proto.getKey=function(){return this.key},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(customStyle){if("empty"!==customStyle.key&&this.key!==customStyle.key)throw new Error("Different keys, "+this.key+" doesn't equal to "+customStyle.key);return new CustomStyle(this.key,_extends__default.default({},this.customStyle,customStyle.customStyle))},CustomStyle}(),EmptyCustomStyle=function(_CustomStyle){function EmptyCustomStyle(){return _CustomStyle.call(this,"empty",{})||this}return _inheritsLoose__default.default(EmptyCustomStyle,_CustomStyle),EmptyCustomStyle.prototype.overrideWith=function(customStyle){return customStyle},EmptyCustomStyle}(CustomStyle),textCustomStylesKeys=["h1","h2","h3","h4","h5","h6","p","quote","codeBlock"],CustomStyles=function(){function CustomStyles(customStyles){this.customStyles=void 0,this.customStyles=customStyles}CustomStyles.of=function(rawCustomStyles){return new CustomStyles(Object.entries(rawCustomStyles).map((function(_ref){var key=_ref[0],value=_ref[1];return new CustomStyle(key,value)})))},CustomStyles.fromTheme=function(theme){var customStyles=theme.customStyles||{},colors=ricosCommon.createPalette(theme.palette,theme.paletteConfig).colors,_ref2=colors||{},color=_ref2.textColor,backgroundColor=_ref2.bgColor;if(null!=colors&&colors.textColor||null!=colors&&colors.bgColor){var colorsCustomStyles=textCustomStylesKeys.reduce((function(acc,key){var _extends2;return _extends__default.default({},acc,((_extends2={})[key]={color:color,backgroundColor:backgroundColor},_extends2))}),{});return CustomStyles.of(colorsCustomStyles).overrideWith(CustomStyles.of(customStyles))}return CustomStyles.of(customStyles)};var _proto=CustomStyles.prototype;return _proto.toCustomStyles=function(){return this.customStyles.reduce((function(acc,style){var _ref3,customStyle=style.toCustomStyle();return _extends__default.default({},acc,lodash.isEmpty(customStyle)?{}:((_ref3={})[style.getKey()]=customStyle,_ref3))}),{})},_proto.byKey=function(key){return this.customStyles.find((function(style){return style.getKey()===key}))||CustomStyles.empty},_proto.overrideWith=function(customStyles){var _this=this,genericCustomStyles=textCustomStylesKeys.reduce((function(acc,key){var _extends3;return _extends__default.default({},acc,((_extends3={})[key]={},_extends3))}),{}),overridenCustomStyles=CustomStyles.of(genericCustomStyles).customStyles.map((function(style){return style.overrideWith(_this.byKey(style.getKey())).overrideWith(customStyles.byKey(style.getKey()))}));return new CustomStyles(overridenCustomStyles)},CustomStyles}();CustomStyles.empty=new EmptyCustomStyle;var RicosNodeStyle=function(){function RicosNodeStyle(nodeStyle){var _this=this;this.nodeStyle=void 0,this.getNodeStyle=function(){return _this.nodeStyle},this.toCustomStyle=function(){return{paddingBottom:_this.nodeStyle.paddingBottom,paddingTop:_this.nodeStyle.paddingTop}},this.overrideWith=function(NodeStyle){return void 0===NodeStyle&&(NodeStyle={}),RicosNodeStyle.of(_extends__default.default({},_this.nodeStyle,NodeStyle))},this.nodeStyle=nodeStyle}return RicosNodeStyle.of=function(nodeStyle){return new RicosNodeStyle(nodeStyle||{})},RicosNodeStyle}();RicosNodeStyle.fromCustomStyle=function(customStyle){var nodeStyle={paddingBottom:customStyle.paddingBottom,paddingTop:customStyle.paddingTop};return RicosNodeStyle.of(nodeStyle)};var RicosTextStyle=function(){function RicosTextStyle(_textStyle){var _this=this;this.textStyle=void 0,this.getTextStyle=function(){return _this.textStyle},this.toCustomStyle=function(){return{lineHeight:_this.textStyle.lineHeight}},this.overrideWith=function(textStyle){return RicosTextStyle.of(_extends__default.default({},_this.textStyle,textStyle))},this.textStyle=_textStyle}return RicosTextStyle.of=function(textStyle){return new RicosTextStyle(textStyle||{})},RicosTextStyle}();RicosTextStyle.fromCustomStyle=function(customStyle){var textStyle={lineHeight:customStyle.lineHeight};return RicosTextStyle.of(textStyle)};var _nodeTypeToDocumentKe,_nodeTypeToNodeDataKe,documentToThemeKeyMap={headerOne:"h1",headerTwo:"h2",headerThree:"h3",headerFour:"h4",headerFive:"h5",headerSix:"h6",paragraph:"p",blockquote:"quote",codeBlock:"codeBlock"},themeToDocumentKeyMap=function(a,ab,bc,cd,de,ef,fg,gh,hi){switch(arguments.length){case 1:return a;case 2:return ab(a);case 3:return bc(ab(a));case 4:return cd(bc(ab(a)));case 5:return de(cd(bc(ab(a))));case 6:return ef(de(cd(bc(ab(a)))));case 7:return fg(ef(de(cd(bc(ab(a))))));case 8:return gh(fg(ef(de(cd(bc(ab(a)))))));case 9:return hi(gh(fg(ef(de(cd(bc(ab(a))))))));default:for(var ret=arguments[0],i=1;i<arguments.length;i++)ret=arguments[i](ret);return ret}}(documentToThemeKeyMap,Object.entries,map((function(ea){return[snd(ea),fst(ea)]})),utils.fromEntries),toRicosCustomStyles=flow((function(documentStyle){return toArray(documentStyle)}),map(bimap((function(node){return _extends__default.default({},Decorations.of(node.decorations).toCustomStyle(),RicosNodeStyle.of(node.nodeStyle).toCustomStyle(),RicosTextStyle.of({lineHeight:node.lineHeight}).toCustomStyle())}),(function(nodeType){return documentToThemeKeyMap[nodeType]}))),(function(tuple){return utils.fromEntries(tuple)})),_toDocumentStyle=flow(Object.entries,map(bimap((function(customStyle){return{decorations:Decorations.fromCustomStyle(customStyle).toDecorationArray(),nodeStyle:RicosNodeStyle.fromCustomStyle(customStyle).getNodeStyle(),lineHeight:RicosTextStyle.fromCustomStyle(customStyle).getTextStyle().lineHeight}}),(function(customStyleKey){return themeToDocumentKeyMap[customStyleKey]}))),utils.fromEntries,JSON.stringify,JSON.parse),TextStyleTransformer=function(){function TextStyleTransformer(theme){this.theme=void 0,this.theme=theme}TextStyleTransformer.fromTheme=function(theme){return new TextStyleTransformer(theme||{})},TextStyleTransformer.fromDocumentStyle=function(documentStyle){return new TextStyleTransformer({customStyles:toRicosCustomStyles(documentStyle)})};var _proto=TextStyleTransformer.prototype;return _proto.toTheme=function(){return this.theme},_proto.toDocumentStyle=function(){return _toDocumentStyle(CustomStyles.fromTheme(this.theme).toCustomStyles())},TextStyleTransformer}(),RicosTextualTheme=function(){function RicosTextualTheme(theme){this.theme=void 0,this.documentStyle=void 0,this.theme=theme,this.documentStyle=TextStyleTransformer.fromTheme(this.theme).toDocumentStyle()}var _proto=RicosTextualTheme.prototype;return _proto.getDecoration=function(nodeType,decorationType){var textNodeStyle=this.documentStyle[nodeType];return Decorations.of((null==textNodeStyle?void 0:textNodeStyle.decorations)||[]).byType(decorationType)},_proto.getTextStyle=function(nodeType){var _this$documentStyle$n;return RicosTextStyle.of({lineHeight:null===(_this$documentStyle$n=this.documentStyle[nodeType])||void 0===_this$documentStyle$n?void 0:_this$documentStyle$n.lineHeight})},_proto.getNodeStyle=function(nodeType){var _this$documentStyle$n2;return RicosNodeStyle.of(null===(_this$documentStyle$n2=this.documentStyle[nodeType])||void 0===_this$documentStyle$n2?void 0:_this$documentStyle$n2.nodeStyle)},_proto.toStyleTag=function(){return ricosCommon.themeStrategy({ricosTheme:this.theme}).html},RicosTextualTheme}(),nodeTypeToDocumentKeyMap=((_nodeTypeToDocumentKe={})[1]="headerOne",_nodeTypeToDocumentKe[2]="headerTwo",_nodeTypeToDocumentKe[3]="headerThree",_nodeTypeToDocumentKe[4]="headerFour",_nodeTypeToDocumentKe[5]="headerFive",_nodeTypeToDocumentKe[6]="headerSix",_nodeTypeToDocumentKe.PARAGRAPH="paragraph",_nodeTypeToDocumentKe.BLOCKQUOTE="blockquote",_nodeTypeToDocumentKe.CODE_BLOCK="codeBlock",_nodeTypeToDocumentKe),nodeTypeToNodeDataKey=((_nodeTypeToNodeDataKe={}).HEADING="headingData",_nodeTypeToNodeDataKe.PARAGRAPH="paragraphData",_nodeTypeToNodeDataKe.BLOCKQUOTE="blockquoteData",_nodeTypeToNodeDataKe.CODE_BLOCK="codeBlockData",_nodeTypeToNodeDataKe),TextNodeTransformer=function(){function TextNodeTransformer(node){var _this=this;this.node=void 0,this.getDocumentStyleKey=function(){var level="HEADING"===_this.node.type?_this.node.headingData.level:void 0;return nodeTypeToDocumentKeyMap[level?(_this.node.type,level):_this.node.type]},this.node=node}var _proto=TextNodeTransformer.prototype;return _proto.getDecorations=function(){return(node=this.node,"BLOCKQUOTE"===node.type?node.nodes[0].nodes:node.nodes).reduce((function(acc,node){return acc.overrideWith(node.textData.decorations)}),Decorations.of([])).toDecorationArray();var node},_proto.getNodeStyle=function(){return this.node.style},_proto.getTextStyle=function(){var dataKey=nodeTypeToNodeDataKey[this.node.type];return this.node[dataKey].textStyle||{}},_proto.toDocumentStyle=function(){var _ref;return(_ref={})[this.getDocumentStyleKey()]={decorations:this.getDecorations(),nodeStyle:this.getNodeStyle(),lineHeight:this.getTextStyle().lineHeight},_ref},TextNodeTransformer}(),RicosTextNodeStyle=function RicosTextNodeStyle(_style){var _this=this;this.style=void 0,this.getTextNodeStyle=function(){return _this.style},this.overrideWith=function(style){var decorations=Decorations.of(_this.style.decorations).overrideWith(style.decorations).toDecorationArray(),nodeStyle=RicosNodeStyle.of(_this.style.nodeStyle).overrideWith(style.nodeStyle||{}).getNodeStyle(),lineHeight=RicosTextStyle.of({lineHeight:_this.style.lineHeight}).overrideWith({lineHeight:style.lineHeight}).getTextStyle().lineHeight,textNodeStyle=JSON.parse(JSON.stringify({decorations:decorations,nodeStyle:nodeStyle,lineHeight:lineHeight}));return new RicosTextNodeStyle(textNodeStyle)},this.style=_style},RicosDocumentStyle=function(){function RicosDocumentStyle(documentStyle){this.documentStyle=void 0,this.documentStyle=documentStyle}RicosDocumentStyle.fromNode=function(node){return new RicosDocumentStyle(new TextNodeTransformer(node).toDocumentStyle())};var _proto=RicosDocumentStyle.prototype;return _proto.getDecoration=function(nodeType,decorationType){var _this$documentStyle$n;return Decorations.of((null===(_this$documentStyle$n=this.documentStyle[nodeType])||void 0===_this$documentStyle$n?void 0:_this$documentStyle$n.decorations)||[]).byType(decorationType)},_proto.getTextStyle=function(nodeType){var _this$documentStyle$n2;return RicosTextStyle.of({lineHeight:null===(_this$documentStyle$n2=this.documentStyle[nodeType])||void 0===_this$documentStyle$n2?void 0:_this$documentStyle$n2.lineHeight})},_proto.getNodeStyle=function(nodeType){var _this$documentStyle$n3;return RicosNodeStyle.of(null===(_this$documentStyle$n3=this.documentStyle[nodeType])||void 0===_this$documentStyle$n3?void 0:_this$documentStyle$n3.nodeStyle)},_proto.toStyleTag=function(){var theme=TextStyleTransformer.fromDocumentStyle(this.documentStyle).toTheme();return new RicosTextualTheme(theme).toStyleTag()},_proto.toContent=function(){return this.documentStyle},_proto.setStyle=function(nodeType,textNodeStyle){var _extends2,style=new RicosTextNodeStyle(this.documentStyle[nodeType]||{decorations:[]}).overrideWith(textNodeStyle).getTextNodeStyle();return new RicosDocumentStyle(_extends__default.default({},this.documentStyle,((_extends2={})[nodeType]=style,_extends2)))},_proto.resetStyle=function(nodeType){var _extends3;return new RicosDocumentStyle(_extends__default.default({},this.documentStyle,((_extends3={})[nodeType]={},_extends3)))},_proto.mergeWith=function(documentStyle){return Object.entries(documentStyle).reduce((function(acc,_ref){var key=_ref[0],style=_ref[1];return acc.setStyle(key,style)}),new RicosDocumentStyle(this.documentStyle))},RicosDocumentStyle}(),RicosStyles=function(){function RicosStyles(){this.theme=void 0,this.documentStyle=void 0}var _proto=RicosStyles.prototype;return _proto.toStyleTags=function(){return[this.theme.toStyleTag(),this.documentStyle.toStyleTag()]},_proto.getDecoration=function(node,decorationType){if(!["PARAGRAPH","HEADING","BLOCKQUOTE","CODE_BLOCK"].includes(node.type))return{};var nodeType=new TextNodeTransformer(node).getDocumentStyleKey(),documentStyleDecoration=this.documentStyle.getDecoration(nodeType,decorationType);return this.theme.getDecoration(nodeType,decorationType).overrideWith(documentStyleDecoration).getDecoration()},_proto.getTextStyle=function(node){var nodeType=new TextNodeTransformer(node).getDocumentStyleKey(),documentStyleTextStyle=this.documentStyle.getTextStyle(nodeType);return this.theme.getTextStyle(nodeType).overrideWith(documentStyleTextStyle.getTextStyle()).getTextStyle()},_proto.getNodeStyle=function(node){var nodeType=new TextNodeTransformer(node).getDocumentStyleKey(),documentStyleNodeStyle=this.documentStyle.getNodeStyle(nodeType);return this.theme.getNodeStyle(nodeType).overrideWith(documentStyleNodeStyle.getNodeStyle()).getNodeStyle()},_proto.getTheme=function(){return this.theme},_proto.setTheme=function(theme){return this.theme=new RicosTextualTheme(theme),this},_proto.getDocumentStyle=function(){return this.documentStyle},_proto.setDocumentStyle=function(documentStyle){return this.documentStyle=new RicosDocumentStyle(documentStyle),this},RicosStyles}();exports.DocumentStyle=RicosDocumentStyle,exports.RicosStyles=RicosStyles;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _extends=require("@babel/runtime/helpers/extends"),_objectWithoutPropertiesLoose=require("@babel/runtime/helpers/objectWithoutPropertiesLoose"),ricosContent=require("ricos-content"),utils=require("ricos-content/libs/utils"),_inheritsLoose=require("@babel/runtime/helpers/inheritsLoose"),ricosCommon=require("ricos-common"),lodash=require("lodash"),converters=require("ricos-content/libs/converters");function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var _extends__default=_interopDefaultLegacy(_extends),_objectWithoutPropertiesLoose__default=_interopDefaultLegacy(_objectWithoutPropertiesLoose),_inheritsLoose__default=_interopDefaultLegacy(_inheritsLoose),EmptyDecoration=function(){function EmptyDecoration(){this.type="UNRECOGNIZED"}var _proto=EmptyDecoration.prototype;return _proto.getDecoration=function(){return{}},_proto.fromCustomStyle=function(_customStyle){return new EmptyDecoration},_proto.toCustomStyle=function(){return{}},_proto.overrideWith=function(decoration){return decoration},EmptyDecoration}(),BoldDecoration=function(){function BoldDecoration(customStyle){this.type="BOLD",this.customStyle=void 0,this.customStyle=customStyle}BoldDecoration.of=function(decoration){if("BOLD"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);return new BoldDecoration({fontWeight:decoration.fontWeightValue||700})};var _proto=BoldDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,fontWeightValue:parseInt(this.customStyle.fontWeight,10)||700}},BoldDecoration.fromCustomStyle=function(customStyle){return new BoldDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return BoldDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof BoldDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new BoldDecoration(_extends__default.default({},this.customStyle,decoration.toCustomStyle()))},BoldDecoration}(),ColorDecoration=function(){function ColorDecoration(customStyle){this.type="COLOR",this.customStyle=void 0,this.customStyle=customStyle}ColorDecoration.of=function(decoration){if("COLOR"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);var _ref=decoration.colorData||{};return new ColorDecoration({color:_ref.foreground,backgroundColor:_ref.background})};var _proto=ColorDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,colorData:_extends__default.default({},this.customStyle.color&&{foreground:this.customStyle.color},this.customStyle.backgroundColor&&{background:this.customStyle.backgroundColor})}},ColorDecoration.fromCustomStyle=function(customStyle){return new ColorDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return ColorDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof ColorDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new ColorDecoration(_extends__default.default({},this.customStyle,decoration.toCustomStyle()))},ColorDecoration}(),FontSizeDecoration=function(){function FontSizeDecoration(customStyle){this.type="FONT_SIZE",this.customStyle=void 0,this.customStyle=customStyle}FontSizeDecoration.of=function(decoration){var _decoration$fontSizeD,_decoration$fontSizeD2,_decoration$fontSizeD3;if("FONT_SIZE"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);var value=null===(_decoration$fontSizeD=decoration.fontSizeData)||void 0===_decoration$fontSizeD?void 0:_decoration$fontSizeD.value,unit=null===(_decoration$fontSizeD2=decoration.fontSizeData)||void 0===_decoration$fontSizeD2||null===(_decoration$fontSizeD3=_decoration$fontSizeD2.unit)||void 0===_decoration$fontSizeD3?void 0:_decoration$fontSizeD3.toLocaleLowerCase();return new FontSizeDecoration(value?{fontSize:""+value+unit}:{})};var _proto=FontSizeDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,fontSizeData:{value:parseInt(this.customStyle.fontSize),unit:"PX"}}},FontSizeDecoration.fromCustomStyle=function(customStyle){return new FontSizeDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return FontSizeDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof FontSizeDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new FontSizeDecoration(_extends__default.default({},this.customStyle,decoration.toCustomStyle()))},FontSizeDecoration}(),ItalicDecoration=function(){function ItalicDecoration(customStyle){this.type="ITALIC",this.customStyle=void 0,this.customStyle=customStyle}ItalicDecoration.of=function(decoration){if("ITALIC"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);return new ItalicDecoration(decoration.italicData?{fontStyle:"italic"}:{})};var _proto=ItalicDecoration.prototype;return _proto.getDecoration=function(){var _this$customStyle$fon;return{type:this.type,italicData:null===(_this$customStyle$fon=this.customStyle.fontStyle)||void 0===_this$customStyle$fon?void 0:_this$customStyle$fon.includes("italic")}},ItalicDecoration.fromCustomStyle=function(customStyle){return new ItalicDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return ItalicDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof ItalicDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new ItalicDecoration(_extends__default.default({},this.customStyle,decoration.toCustomStyle()))},ItalicDecoration}(),_excluded=["color","backgroundColor"],Decorations=function(){function Decorations(textDecorations){this.decorations=void 0,this.decorations=textDecorations}Decorations.of=function(decorations){return new Decorations((decorations||[]).map(Decorations.toTextDecoration))},Decorations.fromCustomStyle=function(customStyle){var color=customStyle.color,backgroundColor=customStyle.backgroundColor,rest=_objectWithoutPropertiesLoose__default.default(customStyle,_excluded),colorStyle={color:color,backgroundColor:backgroundColor};return new Decorations(Object.entries(rest).map((function(_ref){var _ref2,k=_ref[0],v=_ref[1];return(_ref2={})[k]=v,_ref2})).concat([colorStyle]).map(Decorations.styleToDecoration))},Decorations.styleToDecoration=function(style){return ricosContent.firstRight(style,Decorations.empty,[[function(s){return!!s.fontWeight},function(s){return BoldDecoration.fromCustomStyle(s)}],[function(s){return!!s.fontSize},function(s){return FontSizeDecoration.fromCustomStyle(s)}],[function(s){return!!s.fontStyle},function(s){return ItalicDecoration.fromCustomStyle(s)}],[function(s){return!!s.color},function(s){return ColorDecoration.fromCustomStyle(s)}]])},Decorations.toTextDecoration=function(decoration){return ricosContent.firstRight(decoration,Decorations.empty,[[function(d){return"BOLD"===d.type},function(d){return BoldDecoration.of(d)}],[function(d){return"ITALIC"===d.type},function(d){return ItalicDecoration.of(d)}],[function(d){return"FONT_SIZE"===d.type},function(d){return FontSizeDecoration.of(d)}],[function(d){return"COLOR"===d.type},function(d){return ColorDecoration.of(d)}]])};var _proto=Decorations.prototype;return _proto.toDecorationArray=function(){return this.decorations.filter((function(d){return"UNRECOGNIZED"!==d.type})).map((function(d){return d.getDecoration()}))},_proto.byType=function(type){return this.decorations.find((function(d){return d.type===type}))||Decorations.empty},_proto.toCustomStyle=function(){return this.decorations.reduce((function(style,decoration){return _extends__default.default({},style,decoration.toCustomStyle())}),{})},_proto.overrideWith=function(decorations){var _this=this,overridenDecorations=decorations.map(Decorations.toTextDecoration).map((function(decoration){return _this.byType(decoration.type).overrideWith(decoration)})),types=overridenDecorations.map((function(decoration){return decoration.type}));return new Decorations(this.decorations.filter((function(decoration){return!types.includes(decoration.type)})).concat(overridenDecorations))},Decorations}();function flow(ab,bc,cd,de,ef,fg,gh,hi,ij){switch(arguments.length){case 1:return ab;case 2:return function(){return bc(ab.apply(this,arguments))};case 3:return function(){return cd(bc(ab.apply(this,arguments)))};case 4:return function(){return de(cd(bc(ab.apply(this,arguments))))};case 5:return function(){return ef(de(cd(bc(ab.apply(this,arguments)))))};case 6:return function(){return fg(ef(de(cd(bc(ab.apply(this,arguments))))))};case 7:return function(){return gh(fg(ef(de(cd(bc(ab.apply(this,arguments)))))))};case 8:return function(){return hi(gh(fg(ef(de(cd(bc(ab.apply(this,arguments))))))))};case 9:return function(){return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this,arguments)))))))))}}}Decorations.empty=new EmptyDecoration;var map=function(f){return function(fa){return fa.map((function(a){return f(a)}))}},Ord={equals:function(first,second){return first===second},compare:function(first,second){return first<second?-1:first>second?1:0}};function collect(O){if("function"==typeof O)return collect(Ord)(O);var keysO=function(O){return function(r){return Object.keys(r).sort(O.compare)}}(O);return function(f){return function(r){for(var out=[],_i=0,_a=keysO(r);_i<_a.length;_i++){var key=_a[_i];out.push(f(key,r[key]))}return out}}}var toArray=collect(Ord)((function(k,a){return[k,a]}));var fst=function(ea){return ea[0]},snd=function(ea){return ea[1]},bimap=function(f,g){return function(fa){return[g(fst(fa)),f(snd(fa))]}},CustomStyle=function(){function CustomStyle(key,customStyle){this.key=void 0,this.customStyle=void 0,this.key=key,this.customStyle=customStyle}var _proto=CustomStyle.prototype;return _proto.getKey=function(){return this.key},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(customStyle){if("empty"!==customStyle.key&&this.key!==customStyle.key)throw new Error("Different keys, "+this.key+" doesn't equal to "+customStyle.key);return new CustomStyle(this.key,_extends__default.default({},this.customStyle,customStyle.customStyle))},CustomStyle}(),EmptyCustomStyle=function(_CustomStyle){function EmptyCustomStyle(){return _CustomStyle.call(this,"empty",{})||this}return _inheritsLoose__default.default(EmptyCustomStyle,_CustomStyle),EmptyCustomStyle.prototype.overrideWith=function(customStyle){return customStyle},EmptyCustomStyle}(CustomStyle),textCustomStylesKeys=["h1","h2","h3","h4","h5","h6","p","quote","codeBlock"],CustomStyles=function(){function CustomStyles(customStyles){this.customStyles=void 0,this.customStyles=customStyles}CustomStyles.of=function(rawCustomStyles){return new CustomStyles(Object.entries(rawCustomStyles).map((function(_ref){var key=_ref[0],value=_ref[1];return new CustomStyle(key,value)})))},CustomStyles.fromTheme=function(theme){var customStyles=theme.customStyles||{},colors=ricosCommon.createPalette(theme.palette,theme.paletteConfig).colors,_ref2=colors||{},color=_ref2.textColor,backgroundColor=_ref2.bgColor;if(null!=colors&&colors.textColor||null!=colors&&colors.bgColor){var colorsCustomStyles=textCustomStylesKeys.reduce((function(acc,key){var _extends2;return _extends__default.default({},acc,((_extends2={})[key]={color:color,backgroundColor:backgroundColor},_extends2))}),{});return CustomStyles.of(colorsCustomStyles).overrideWith(CustomStyles.of(customStyles))}return CustomStyles.of(customStyles)};var _proto=CustomStyles.prototype;return _proto.toCustomStyles=function(){return this.customStyles.reduce((function(acc,style){var _ref3,customStyle=style.toCustomStyle();return _extends__default.default({},acc,lodash.isEmpty(customStyle)?{}:((_ref3={})[style.getKey()]=customStyle,_ref3))}),{})},_proto.byKey=function(key){return this.customStyles.find((function(style){return style.getKey()===key}))||CustomStyles.empty},_proto.overrideWith=function(customStyles){var _this=this,genericCustomStyles=textCustomStylesKeys.reduce((function(acc,key){var _extends3;return _extends__default.default({},acc,((_extends3={})[key]={},_extends3))}),{}),overridenCustomStyles=CustomStyles.of(genericCustomStyles).customStyles.map((function(style){return style.overrideWith(_this.byKey(style.getKey())).overrideWith(customStyles.byKey(style.getKey()))}));return new CustomStyles(overridenCustomStyles)},CustomStyles}();CustomStyles.empty=new EmptyCustomStyle;var RicosNodeStyle=function(){function RicosNodeStyle(nodeStyle){var _this=this;this.nodeStyle=void 0,this.getNodeStyle=function(){return _this.nodeStyle},this.toCustomStyle=function(){return{paddingBottom:_this.nodeStyle.paddingBottom,paddingTop:_this.nodeStyle.paddingTop}},this.overrideWith=function(NodeStyle){return void 0===NodeStyle&&(NodeStyle={}),RicosNodeStyle.of(_extends__default.default({},_this.nodeStyle,NodeStyle))},this.nodeStyle=nodeStyle}return RicosNodeStyle.of=function(nodeStyle){return new RicosNodeStyle(nodeStyle||{})},RicosNodeStyle}();RicosNodeStyle.fromCustomStyle=function(customStyle){var nodeStyle={paddingBottom:customStyle.paddingBottom,paddingTop:customStyle.paddingTop};return RicosNodeStyle.of(nodeStyle)};var RicosTextStyle=function(){function RicosTextStyle(_textStyle){var _this=this;this.textStyle=void 0,this.getTextStyle=function(){return _this.textStyle},this.toCustomStyle=function(){return{lineHeight:_this.textStyle.lineHeight}},this.overrideWith=function(textStyle){return RicosTextStyle.of(_extends__default.default({},_this.textStyle,textStyle))},this.textStyle=_textStyle}return RicosTextStyle.of=function(textStyle){return new RicosTextStyle(textStyle||{})},RicosTextStyle}();RicosTextStyle.fromCustomStyle=function(customStyle){var textStyle={lineHeight:customStyle.lineHeight};return RicosTextStyle.of(textStyle)};var _nodeTypeToDocumentKe,_nodeTypeToNodeDataKe,documentToThemeKeyMap={headerOne:"h1",headerTwo:"h2",headerThree:"h3",headerFour:"h4",headerFive:"h5",headerSix:"h6",paragraph:"p",blockquote:"quote",codeBlock:"codeBlock"},themeToDocumentKeyMap=function(a,ab,bc,cd,de,ef,fg,gh,hi){switch(arguments.length){case 1:return a;case 2:return ab(a);case 3:return bc(ab(a));case 4:return cd(bc(ab(a)));case 5:return de(cd(bc(ab(a))));case 6:return ef(de(cd(bc(ab(a)))));case 7:return fg(ef(de(cd(bc(ab(a))))));case 8:return gh(fg(ef(de(cd(bc(ab(a)))))));case 9:return hi(gh(fg(ef(de(cd(bc(ab(a))))))));default:for(var ret=arguments[0],i=1;i<arguments.length;i++)ret=arguments[i](ret);return ret}}(documentToThemeKeyMap,Object.entries,map((function(ea){return[snd(ea),fst(ea)]})),utils.fromEntries),toRicosCustomStyles=flow((function(documentStyle){return toArray(documentStyle)}),map(bimap((function(node){return _extends__default.default({},Decorations.of(node.decorations).toCustomStyle(),RicosNodeStyle.of(node.nodeStyle).toCustomStyle(),RicosTextStyle.of({lineHeight:node.lineHeight}).toCustomStyle())}),(function(nodeType){return documentToThemeKeyMap[nodeType]}))),(function(tuple){return utils.fromEntries(tuple)})),_toDocumentStyle=flow(Object.entries,map(bimap((function(customStyle){return{decorations:Decorations.fromCustomStyle(customStyle).toDecorationArray(),nodeStyle:RicosNodeStyle.fromCustomStyle(customStyle).getNodeStyle(),lineHeight:RicosTextStyle.fromCustomStyle(customStyle).getTextStyle().lineHeight}}),(function(customStyleKey){return themeToDocumentKeyMap[customStyleKey]}))),utils.fromEntries,JSON.stringify,JSON.parse),TextStyleTransformer=function(){function TextStyleTransformer(theme){this.theme=void 0,this.theme=theme}TextStyleTransformer.fromTheme=function(theme){return new TextStyleTransformer(theme||{})},TextStyleTransformer.fromDocumentStyle=function(documentStyle){return new TextStyleTransformer({customStyles:toRicosCustomStyles(documentStyle)})};var _proto=TextStyleTransformer.prototype;return _proto.toTheme=function(){return this.theme},_proto.toDocumentStyle=function(){return _toDocumentStyle(CustomStyles.fromTheme(this.theme).toCustomStyles())},TextStyleTransformer}(),RicosTextualTheme=function(){function RicosTextualTheme(theme){this.theme=void 0,this.documentStyle=void 0,this.theme=theme,this.documentStyle=TextStyleTransformer.fromTheme(this.theme).toDocumentStyle()}var _proto=RicosTextualTheme.prototype;return _proto.getDecoration=function(nodeType,decorationType){var textNodeStyle=this.documentStyle[nodeType];return Decorations.of((null==textNodeStyle?void 0:textNodeStyle.decorations)||[]).byType(decorationType)},_proto.getTextStyle=function(nodeType){var _this$documentStyle$n;return RicosTextStyle.of({lineHeight:null===(_this$documentStyle$n=this.documentStyle[nodeType])||void 0===_this$documentStyle$n?void 0:_this$documentStyle$n.lineHeight})},_proto.getNodeStyle=function(nodeType){var _this$documentStyle$n2;return RicosNodeStyle.of(null===(_this$documentStyle$n2=this.documentStyle[nodeType])||void 0===_this$documentStyle$n2?void 0:_this$documentStyle$n2.nodeStyle)},_proto.toStyleTag=function(){return ricosCommon.themeStrategy({ricosTheme:this.theme}).html},RicosTextualTheme}(),nodeTypeToDocumentKeyMap=((_nodeTypeToDocumentKe={})[1]="headerOne",_nodeTypeToDocumentKe[2]="headerTwo",_nodeTypeToDocumentKe[3]="headerThree",_nodeTypeToDocumentKe[4]="headerFour",_nodeTypeToDocumentKe[5]="headerFive",_nodeTypeToDocumentKe[6]="headerSix",_nodeTypeToDocumentKe.PARAGRAPH="paragraph",_nodeTypeToDocumentKe.BLOCKQUOTE="blockquote",_nodeTypeToDocumentKe.CODE_BLOCK="codeBlock",_nodeTypeToDocumentKe),nodeTypeToNodeDataKey=((_nodeTypeToNodeDataKe={}).HEADING="headingData",_nodeTypeToNodeDataKe.PARAGRAPH="paragraphData",_nodeTypeToNodeDataKe.BLOCKQUOTE="blockquoteData",_nodeTypeToNodeDataKe.CODE_BLOCK="codeBlockData",_nodeTypeToNodeDataKe),TextNodeTransformer=function(){function TextNodeTransformer(node){var _this=this;this.node=void 0,this.getDocumentStyleKey=function(){var level="HEADING"===_this.node.type?_this.node.headingData.level:void 0;return nodeTypeToDocumentKeyMap[level?(_this.node.type,level):_this.node.type]},this.node=node}var _proto=TextNodeTransformer.prototype;return _proto.getDecorations=function(){return(node=this.node,"BLOCKQUOTE"===node.type?node.nodes[0].nodes:node.nodes).reduce((function(acc,node){return acc.overrideWith(node.textData.decorations)}),Decorations.of([])).toDecorationArray();var node},_proto.getNodeStyle=function(){return this.node.style},_proto.getTextStyle=function(){var dataKey=nodeTypeToNodeDataKey[this.node.type];return this.node[dataKey].textStyle||{}},_proto.toDocumentStyle=function(){var _ref;return(_ref={})[this.getDocumentStyleKey()]={decorations:this.getDecorations(),nodeStyle:this.getNodeStyle(),lineHeight:this.getTextStyle().lineHeight},_ref},TextNodeTransformer}(),RicosTextNodeStyle=function RicosTextNodeStyle(_style){var _this=this;this.style=void 0,this.getTextNodeStyle=function(){return _this.style},this.overrideWith=function(style){var decorations=Decorations.of(_this.style.decorations).overrideWith(style.decorations).toDecorationArray(),nodeStyle=RicosNodeStyle.of(_this.style.nodeStyle).overrideWith(style.nodeStyle||{}).getNodeStyle(),lineHeight=RicosTextStyle.of({lineHeight:_this.style.lineHeight}).overrideWith({lineHeight:style.lineHeight}).getTextStyle().lineHeight,textNodeStyle=JSON.parse(JSON.stringify({decorations:decorations,nodeStyle:nodeStyle,lineHeight:lineHeight}));return new RicosTextNodeStyle(textNodeStyle)},this.style=_style},RicosDocumentStyle=function(){function RicosDocumentStyle(documentStyle){this.documentStyle=void 0,this.documentStyle=documentStyle}RicosDocumentStyle.fromNode=function(node){return new RicosDocumentStyle(new TextNodeTransformer(node).toDocumentStyle())};var _proto=RicosDocumentStyle.prototype;return _proto.getDecoration=function(nodeType,decorationType){var _this$documentStyle$n;return Decorations.of((null===(_this$documentStyle$n=this.documentStyle[nodeType])||void 0===_this$documentStyle$n?void 0:_this$documentStyle$n.decorations)||[]).byType(decorationType)},_proto.getDecorations=function(node){var _this$documentStyle$d,documentStyleKey=new TextNodeTransformer(node).getDocumentStyleKey();return Decorations.of((null===(_this$documentStyle$d=this.documentStyle[documentStyleKey])||void 0===_this$documentStyle$d?void 0:_this$documentStyle$d.decorations)||[]).toDecorationArray()},_proto.getTextStyle=function(nodeType){var _this$documentStyle$n2;return RicosTextStyle.of({lineHeight:null===(_this$documentStyle$n2=this.documentStyle[nodeType])||void 0===_this$documentStyle$n2?void 0:_this$documentStyle$n2.lineHeight})},_proto.getNodeStyle=function(nodeType){var _this$documentStyle$n3;return RicosNodeStyle.of(null===(_this$documentStyle$n3=this.documentStyle[nodeType])||void 0===_this$documentStyle$n3?void 0:_this$documentStyle$n3.nodeStyle)},_proto.toStyleTag=function(){var theme=TextStyleTransformer.fromDocumentStyle(this.documentStyle).toTheme();return new RicosTextualTheme(theme).toStyleTag()},_proto.toContent=function(){return this.documentStyle},_proto.setStyle=function(nodeType,textNodeStyle){var _extends2,style=new RicosTextNodeStyle(this.documentStyle[nodeType]||{decorations:[]}).overrideWith(textNodeStyle).getTextNodeStyle();return new RicosDocumentStyle(_extends__default.default({},this.documentStyle,((_extends2={})[nodeType]=style,_extends2)))},_proto.resetStyle=function(nodeType){var _extends3;return new RicosDocumentStyle(_extends__default.default({},this.documentStyle,((_extends3={})[nodeType]={},_extends3)))},_proto.mergeWith=function(documentStyle){return Object.entries(documentStyle).reduce((function(acc,_ref){var key=_ref[0],style=_ref[1];return acc.setStyle(key,style)}),new RicosDocumentStyle(this.documentStyle))},RicosDocumentStyle}(),RicosStyles=function(){function RicosStyles(){this.theme=void 0,this.documentStyle=void 0}var _proto=RicosStyles.prototype;return _proto.toStyleTags=function(){return[this.theme.toStyleTag(),this.documentStyle.toStyleTag()]},_proto.getDecoration=function(node,decorationType){if(!["PARAGRAPH","HEADING","BLOCKQUOTE","CODE_BLOCK"].includes(node.type))return{};var nodeType=new TextNodeTransformer(node).getDocumentStyleKey(),documentStyleDecoration=this.documentStyle.getDecoration(nodeType,decorationType);return this.theme.getDecoration(nodeType,decorationType).overrideWith(documentStyleDecoration).getDecoration()},_proto.getTextStyle=function(node){var nodeType=new TextNodeTransformer(node).getDocumentStyleKey(),documentStyleTextStyle=this.documentStyle.getTextStyle(nodeType);return this.theme.getTextStyle(nodeType).overrideWith(documentStyleTextStyle.getTextStyle()).getTextStyle()},_proto.getNodeStyle=function(node){var nodeType=new TextNodeTransformer(node).getDocumentStyleKey(),documentStyleNodeStyle=this.documentStyle.getNodeStyle(nodeType);return this.theme.getNodeStyle(nodeType).overrideWith(documentStyleNodeStyle.getNodeStyle()).getNodeStyle()},_proto.getTheme=function(){return this.theme},_proto.setTheme=function(theme){return this.theme=new RicosTextualTheme(theme),this},_proto.getDocumentStyle=function(){return this.documentStyle},_proto.setDocumentStyle=function(documentStyle){return this.documentStyle=new RicosDocumentStyle(documentStyle),this},_proto.toDraftDocumentStyle=function(){return converters.parseDocStyle(this.documentStyle.toContent())},RicosStyles}();exports.DocumentStyle=RicosDocumentStyle,exports.RicosStyles=RicosStyles;
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

import _extends from"@babel/runtime/helpers/extends";import _objectWithoutPropertiesLoose from"@babel/runtime/helpers/objectWithoutPropertiesLoose";import{firstRight}from"ricos-content";import{fromEntries}from"ricos-content/libs/utils";import _inheritsLoose from"@babel/runtime/helpers/inheritsLoose";import{createPalette,themeStrategy}from"ricos-common";import{isEmpty}from"lodash";var EmptyDecoration=function(){function EmptyDecoration(){this.type="UNRECOGNIZED"}var _proto=EmptyDecoration.prototype;return _proto.getDecoration=function(){return{}},_proto.fromCustomStyle=function(_customStyle){return new EmptyDecoration},_proto.toCustomStyle=function(){return{}},_proto.overrideWith=function(decoration){return decoration},EmptyDecoration}(),BoldDecoration=function(){function BoldDecoration(customStyle){this.type="BOLD",this.customStyle=void 0,this.customStyle=customStyle}BoldDecoration.of=function(decoration){if("BOLD"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);return new BoldDecoration({fontWeight:decoration.fontWeightValue||700})};var _proto=BoldDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,fontWeightValue:parseInt(this.customStyle.fontWeight,10)||700}},BoldDecoration.fromCustomStyle=function(customStyle){return new BoldDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return BoldDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof BoldDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new BoldDecoration(_extends({},this.customStyle,decoration.toCustomStyle()))},BoldDecoration}(),ColorDecoration=function(){function ColorDecoration(customStyle){this.type="COLOR",this.customStyle=void 0,this.customStyle=customStyle}ColorDecoration.of=function(decoration){if("COLOR"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);var _ref=decoration.colorData||{};return new ColorDecoration({color:_ref.foreground,backgroundColor:_ref.background})};var _proto=ColorDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,colorData:_extends({},this.customStyle.color&&{foreground:this.customStyle.color},this.customStyle.backgroundColor&&{background:this.customStyle.backgroundColor})}},ColorDecoration.fromCustomStyle=function(customStyle){return new ColorDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return ColorDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof ColorDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new ColorDecoration(_extends({},this.customStyle,decoration.toCustomStyle()))},ColorDecoration}(),FontSizeDecoration=function(){function FontSizeDecoration(customStyle){this.type="FONT_SIZE",this.customStyle=void 0,this.customStyle=customStyle}FontSizeDecoration.of=function(decoration){var _decoration$fontSizeD,_decoration$fontSizeD2,_decoration$fontSizeD3;if("FONT_SIZE"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);var value=null===(_decoration$fontSizeD=decoration.fontSizeData)||void 0===_decoration$fontSizeD?void 0:_decoration$fontSizeD.value,unit=null===(_decoration$fontSizeD2=decoration.fontSizeData)||void 0===_decoration$fontSizeD2||null===(_decoration$fontSizeD3=_decoration$fontSizeD2.unit)||void 0===_decoration$fontSizeD3?void 0:_decoration$fontSizeD3.toLocaleLowerCase();return new FontSizeDecoration(value?{fontSize:""+value+unit}:{})};var _proto=FontSizeDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,fontSizeData:{value:parseInt(this.customStyle.fontSize),unit:"PX"}}},FontSizeDecoration.fromCustomStyle=function(customStyle){return new FontSizeDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return FontSizeDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof FontSizeDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new FontSizeDecoration(_extends({},this.customStyle,decoration.toCustomStyle()))},FontSizeDecoration}(),ItalicDecoration=function(){function ItalicDecoration(customStyle){this.type="ITALIC",this.customStyle=void 0,this.customStyle=customStyle}ItalicDecoration.of=function(decoration){if("ITALIC"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);return new ItalicDecoration(decoration.italicData?{fontStyle:"italic"}:{})};var _proto=ItalicDecoration.prototype;return _proto.getDecoration=function(){var _this$customStyle$fon;return{type:this.type,italicData:null===(_this$customStyle$fon=this.customStyle.fontStyle)||void 0===_this$customStyle$fon?void 0:_this$customStyle$fon.includes("italic")}},ItalicDecoration.fromCustomStyle=function(customStyle){return new ItalicDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return ItalicDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof ItalicDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new ItalicDecoration(_extends({},this.customStyle,decoration.toCustomStyle()))},ItalicDecoration}(),_excluded=["color","backgroundColor"],Decorations=function(){function Decorations(textDecorations){this.decorations=void 0,this.decorations=textDecorations}Decorations.of=function(decorations){return new Decorations((decorations||[]).map(Decorations.toTextDecoration))},Decorations.fromCustomStyle=function(customStyle){var color=customStyle.color,backgroundColor=customStyle.backgroundColor,rest=_objectWithoutPropertiesLoose(customStyle,_excluded),colorStyle={color:color,backgroundColor:backgroundColor};return new Decorations(Object.entries(rest).map((function(_ref){var _ref2,k=_ref[0],v=_ref[1];return(_ref2={})[k]=v,_ref2})).concat([colorStyle]).map(Decorations.styleToDecoration))},Decorations.styleToDecoration=function(style){return firstRight(style,Decorations.empty,[[function(s){return!!s.fontWeight},function(s){return BoldDecoration.fromCustomStyle(s)}],[function(s){return!!s.fontSize},function(s){return FontSizeDecoration.fromCustomStyle(s)}],[function(s){return!!s.fontStyle},function(s){return ItalicDecoration.fromCustomStyle(s)}],[function(s){return!!s.color},function(s){return ColorDecoration.fromCustomStyle(s)}]])},Decorations.toTextDecoration=function(decoration){return firstRight(decoration,Decorations.empty,[[function(d){return"BOLD"===d.type},function(d){return BoldDecoration.of(d)}],[function(d){return"ITALIC"===d.type},function(d){return ItalicDecoration.of(d)}],[function(d){return"FONT_SIZE"===d.type},function(d){return FontSizeDecoration.of(d)}],[function(d){return"COLOR"===d.type},function(d){return ColorDecoration.of(d)}]])};var _proto=Decorations.prototype;return _proto.toDecorationArray=function(){return this.decorations.filter((function(d){return"UNRECOGNIZED"!==d.type})).map((function(d){return d.getDecoration()}))},_proto.byType=function(type){return this.decorations.find((function(d){return d.type===type}))||Decorations.empty},_proto.toCustomStyle=function(){return this.decorations.reduce((function(style,decoration){return _extends({},style,decoration.toCustomStyle())}),{})},_proto.overrideWith=function(decorations){var _this=this,overridenDecorations=decorations.map(Decorations.toTextDecoration).map((function(decoration){return _this.byType(decoration.type).overrideWith(decoration)})),types=overridenDecorations.map((function(decoration){return decoration.type}));return new Decorations(this.decorations.filter((function(decoration){return!types.includes(decoration.type)})).concat(overridenDecorations))},Decorations}();function flow(ab,bc,cd,de,ef,fg,gh,hi,ij){switch(arguments.length){case 1:return ab;case 2:return function(){return bc(ab.apply(this,arguments))};case 3:return function(){return cd(bc(ab.apply(this,arguments)))};case 4:return function(){return de(cd(bc(ab.apply(this,arguments))))};case 5:return function(){return ef(de(cd(bc(ab.apply(this,arguments)))))};case 6:return function(){return fg(ef(de(cd(bc(ab.apply(this,arguments))))))};case 7:return function(){return gh(fg(ef(de(cd(bc(ab.apply(this,arguments)))))))};case 8:return function(){return hi(gh(fg(ef(de(cd(bc(ab.apply(this,arguments))))))))};case 9:return function(){return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this,arguments)))))))))}}}Decorations.empty=new EmptyDecoration;var map=function(f){return function(fa){return fa.map((function(a){return f(a)}))}},Ord={equals:function(first,second){return first===second},compare:function(first,second){return first<second?-1:first>second?1:0}};function collect(O){if("function"==typeof O)return collect(Ord)(O);var keysO=function(O){return function(r){return Object.keys(r).sort(O.compare)}}(O);return function(f){return function(r){for(var out=[],_i=0,_a=keysO(r);_i<_a.length;_i++){var key=_a[_i];out.push(f(key,r[key]))}return out}}}var toArray=collect(Ord)((function(k,a){return[k,a]}));var fst=function(ea){return ea[0]},snd=function(ea){return ea[1]},bimap=function(f,g){return function(fa){return[g(fst(fa)),f(snd(fa))]}},CustomStyle=function(){function CustomStyle(key,customStyle){this.key=void 0,this.customStyle=void 0,this.key=key,this.customStyle=customStyle}var _proto=CustomStyle.prototype;return _proto.getKey=function(){return this.key},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(customStyle){if("empty"!==customStyle.key&&this.key!==customStyle.key)throw new Error("Different keys, "+this.key+" doesn't equal to "+customStyle.key);return new CustomStyle(this.key,_extends({},this.customStyle,customStyle.customStyle))},CustomStyle}(),EmptyCustomStyle=function(_CustomStyle){function EmptyCustomStyle(){return _CustomStyle.call(this,"empty",{})||this}return _inheritsLoose(EmptyCustomStyle,_CustomStyle),EmptyCustomStyle.prototype.overrideWith=function(customStyle){return customStyle},EmptyCustomStyle}(CustomStyle),textCustomStylesKeys=["h1","h2","h3","h4","h5","h6","p","quote","codeBlock"],CustomStyles=function(){function CustomStyles(customStyles){this.customStyles=void 0,this.customStyles=customStyles}CustomStyles.of=function(rawCustomStyles){return new CustomStyles(Object.entries(rawCustomStyles).map((function(_ref){var key=_ref[0],value=_ref[1];return new CustomStyle(key,value)})))},CustomStyles.fromTheme=function(theme){var customStyles=theme.customStyles||{},colors=createPalette(theme.palette,theme.paletteConfig).colors,_ref2=colors||{},color=_ref2.textColor,backgroundColor=_ref2.bgColor;if(null!=colors&&colors.textColor||null!=colors&&colors.bgColor){var colorsCustomStyles=textCustomStylesKeys.reduce((function(acc,key){var _extends2;return _extends({},acc,((_extends2={})[key]={color:color,backgroundColor:backgroundColor},_extends2))}),{});return CustomStyles.of(colorsCustomStyles).overrideWith(CustomStyles.of(customStyles))}return CustomStyles.of(customStyles)};var _proto=CustomStyles.prototype;return _proto.toCustomStyles=function(){return this.customStyles.reduce((function(acc,style){var _ref3,customStyle=style.toCustomStyle();return _extends({},acc,isEmpty(customStyle)?{}:((_ref3={})[style.getKey()]=customStyle,_ref3))}),{})},_proto.byKey=function(key){return this.customStyles.find((function(style){return style.getKey()===key}))||CustomStyles.empty},_proto.overrideWith=function(customStyles){var _this=this,genericCustomStyles=textCustomStylesKeys.reduce((function(acc,key){var _extends3;return _extends({},acc,((_extends3={})[key]={},_extends3))}),{}),overridenCustomStyles=CustomStyles.of(genericCustomStyles).customStyles.map((function(style){return style.overrideWith(_this.byKey(style.getKey())).overrideWith(customStyles.byKey(style.getKey()))}));return new CustomStyles(overridenCustomStyles)},CustomStyles}();CustomStyles.empty=new EmptyCustomStyle;var RicosNodeStyle=function(){function RicosNodeStyle(nodeStyle){var _this=this;this.nodeStyle=void 0,this.getNodeStyle=function(){return _this.nodeStyle},this.toCustomStyle=function(){return{paddingBottom:_this.nodeStyle.paddingBottom,paddingTop:_this.nodeStyle.paddingTop}},this.overrideWith=function(NodeStyle){return void 0===NodeStyle&&(NodeStyle={}),RicosNodeStyle.of(_extends({},_this.nodeStyle,NodeStyle))},this.nodeStyle=nodeStyle}return RicosNodeStyle.of=function(nodeStyle){return new RicosNodeStyle(nodeStyle||{})},RicosNodeStyle}();RicosNodeStyle.fromCustomStyle=function(customStyle){var nodeStyle={paddingBottom:customStyle.paddingBottom,paddingTop:customStyle.paddingTop};return RicosNodeStyle.of(nodeStyle)};var RicosTextStyle=function(){function RicosTextStyle(_textStyle){var _this=this;this.textStyle=void 0,this.getTextStyle=function(){return _this.textStyle},this.toCustomStyle=function(){return{lineHeight:_this.textStyle.lineHeight}},this.overrideWith=function(textStyle){return RicosTextStyle.of(_extends({},_this.textStyle,textStyle))},this.textStyle=_textStyle}return RicosTextStyle.of=function(textStyle){return new RicosTextStyle(textStyle||{})},RicosTextStyle}();RicosTextStyle.fromCustomStyle=function(customStyle){var textStyle={lineHeight:customStyle.lineHeight};return RicosTextStyle.of(textStyle)};var _nodeTypeToDocumentKe,_nodeTypeToNodeDataKe,documentToThemeKeyMap={headerOne:"h1",headerTwo:"h2",headerThree:"h3",headerFour:"h4",headerFive:"h5",headerSix:"h6",paragraph:"p",blockquote:"quote",codeBlock:"codeBlock"},themeToDocumentKeyMap=function(a,ab,bc,cd,de,ef,fg,gh,hi){switch(arguments.length){case 1:return a;case 2:return ab(a);case 3:return bc(ab(a));case 4:return cd(bc(ab(a)));case 5:return de(cd(bc(ab(a))));case 6:return ef(de(cd(bc(ab(a)))));case 7:return fg(ef(de(cd(bc(ab(a))))));case 8:return gh(fg(ef(de(cd(bc(ab(a)))))));case 9:return hi(gh(fg(ef(de(cd(bc(ab(a))))))));default:for(var ret=arguments[0],i=1;i<arguments.length;i++)ret=arguments[i](ret);return ret}}(documentToThemeKeyMap,Object.entries,map((function(ea){return[snd(ea),fst(ea)]})),fromEntries),toRicosCustomStyles=flow((function(documentStyle){return toArray(documentStyle)}),map(bimap((function(node){return _extends({},Decorations.of(node.decorations).toCustomStyle(),RicosNodeStyle.of(node.nodeStyle).toCustomStyle(),RicosTextStyle.of({lineHeight:node.lineHeight}).toCustomStyle())}),(function(nodeType){return documentToThemeKeyMap[nodeType]}))),(function(tuple){return fromEntries(tuple)})),_toDocumentStyle=flow(Object.entries,map(bimap((function(customStyle){return{decorations:Decorations.fromCustomStyle(customStyle).toDecorationArray(),nodeStyle:RicosNodeStyle.fromCustomStyle(customStyle).getNodeStyle(),lineHeight:RicosTextStyle.fromCustomStyle(customStyle).getTextStyle().lineHeight}}),(function(customStyleKey){return themeToDocumentKeyMap[customStyleKey]}))),fromEntries,JSON.stringify,JSON.parse),TextStyleTransformer=function(){function TextStyleTransformer(theme){this.theme=void 0,this.theme=theme}TextStyleTransformer.fromTheme=function(theme){return new TextStyleTransformer(theme||{})},TextStyleTransformer.fromDocumentStyle=function(documentStyle){return new TextStyleTransformer({customStyles:toRicosCustomStyles(documentStyle)})};var _proto=TextStyleTransformer.prototype;return _proto.toTheme=function(){return this.theme},_proto.toDocumentStyle=function(){return _toDocumentStyle(CustomStyles.fromTheme(this.theme).toCustomStyles())},TextStyleTransformer}(),RicosTextualTheme=function(){function RicosTextualTheme(theme){this.theme=void 0,this.documentStyle=void 0,this.theme=theme,this.documentStyle=TextStyleTransformer.fromTheme(this.theme).toDocumentStyle()}var _proto=RicosTextualTheme.prototype;return _proto.getDecoration=function(nodeType,decorationType){var textNodeStyle=this.documentStyle[nodeType];return Decorations.of((null==textNodeStyle?void 0:textNodeStyle.decorations)||[]).byType(decorationType)},_proto.getTextStyle=function(nodeType){var _this$documentStyle$n;return RicosTextStyle.of({lineHeight:null===(_this$documentStyle$n=this.documentStyle[nodeType])||void 0===_this$documentStyle$n?void 0:_this$documentStyle$n.lineHeight})},_proto.getNodeStyle=function(nodeType){var _this$documentStyle$n2;return RicosNodeStyle.of(null===(_this$documentStyle$n2=this.documentStyle[nodeType])||void 0===_this$documentStyle$n2?void 0:_this$documentStyle$n2.nodeStyle)},_proto.toStyleTag=function(){return themeStrategy({ricosTheme:this.theme}).html},RicosTextualTheme}(),nodeTypeToDocumentKeyMap=((_nodeTypeToDocumentKe={})[1]="headerOne",_nodeTypeToDocumentKe[2]="headerTwo",_nodeTypeToDocumentKe[3]="headerThree",_nodeTypeToDocumentKe[4]="headerFour",_nodeTypeToDocumentKe[5]="headerFive",_nodeTypeToDocumentKe[6]="headerSix",_nodeTypeToDocumentKe.PARAGRAPH="paragraph",_nodeTypeToDocumentKe.BLOCKQUOTE="blockquote",_nodeTypeToDocumentKe.CODE_BLOCK="codeBlock",_nodeTypeToDocumentKe),nodeTypeToNodeDataKey=((_nodeTypeToNodeDataKe={}).HEADING="headingData",_nodeTypeToNodeDataKe.PARAGRAPH="paragraphData",_nodeTypeToNodeDataKe.BLOCKQUOTE="blockquoteData",_nodeTypeToNodeDataKe.CODE_BLOCK="codeBlockData",_nodeTypeToNodeDataKe),TextNodeTransformer=function(){function TextNodeTransformer(node){var _this=this;this.node=void 0,this.getDocumentStyleKey=function(){var level="HEADING"===_this.node.type?_this.node.headingData.level:void 0;return nodeTypeToDocumentKeyMap[level?(_this.node.type,level):_this.node.type]},this.node=node}var _proto=TextNodeTransformer.prototype;return _proto.getDecorations=function(){return(node=this.node,"BLOCKQUOTE"===node.type?node.nodes[0].nodes:node.nodes).reduce((function(acc,node){return acc.overrideWith(node.textData.decorations)}),Decorations.of([])).toDecorationArray();var node},_proto.getNodeStyle=function(){return this.node.style},_proto.getTextStyle=function(){var dataKey=nodeTypeToNodeDataKey[this.node.type];return this.node[dataKey].textStyle||{}},_proto.toDocumentStyle=function(){var _ref;return(_ref={})[this.getDocumentStyleKey()]={decorations:this.getDecorations(),nodeStyle:this.getNodeStyle(),lineHeight:this.getTextStyle().lineHeight},_ref},TextNodeTransformer}(),RicosTextNodeStyle=function RicosTextNodeStyle(_style){var _this=this;this.style=void 0,this.getTextNodeStyle=function(){return _this.style},this.overrideWith=function(style){var decorations=Decorations.of(_this.style.decorations).overrideWith(style.decorations).toDecorationArray(),nodeStyle=RicosNodeStyle.of(_this.style.nodeStyle).overrideWith(style.nodeStyle||{}).getNodeStyle(),lineHeight=RicosTextStyle.of({lineHeight:_this.style.lineHeight}).overrideWith({lineHeight:style.lineHeight}).getTextStyle().lineHeight,textNodeStyle=JSON.parse(JSON.stringify({decorations:decorations,nodeStyle:nodeStyle,lineHeight:lineHeight}));return new RicosTextNodeStyle(textNodeStyle)},this.style=_style},RicosDocumentStyle=function(){function RicosDocumentStyle(documentStyle){this.documentStyle=void 0,this.documentStyle=documentStyle}RicosDocumentStyle.fromNode=function(node){return new RicosDocumentStyle(new TextNodeTransformer(node).toDocumentStyle())};var _proto=RicosDocumentStyle.prototype;return _proto.getDecoration=function(nodeType,decorationType){var _this$documentStyle$n;return Decorations.of((null===(_this$documentStyle$n=this.documentStyle[nodeType])||void 0===_this$documentStyle$n?void 0:_this$documentStyle$n.decorations)||[]).byType(decorationType)},_proto.getTextStyle=function(nodeType){var _this$documentStyle$n2;return RicosTextStyle.of({lineHeight:null===(_this$documentStyle$n2=this.documentStyle[nodeType])||void 0===_this$documentStyle$n2?void 0:_this$documentStyle$n2.lineHeight})},_proto.getNodeStyle=function(nodeType){var _this$documentStyle$n3;return RicosNodeStyle.of(null===(_this$documentStyle$n3=this.documentStyle[nodeType])||void 0===_this$documentStyle$n3?void 0:_this$documentStyle$n3.nodeStyle)},_proto.toStyleTag=function(){var theme=TextStyleTransformer.fromDocumentStyle(this.documentStyle).toTheme();return new RicosTextualTheme(theme).toStyleTag()},_proto.toContent=function(){return this.documentStyle},_proto.setStyle=function(nodeType,textNodeStyle){var _extends2,style=new RicosTextNodeStyle(this.documentStyle[nodeType]||{decorations:[]}).overrideWith(textNodeStyle).getTextNodeStyle();return new RicosDocumentStyle(_extends({},this.documentStyle,((_extends2={})[nodeType]=style,_extends2)))},_proto.resetStyle=function(nodeType){var _extends3;return new RicosDocumentStyle(_extends({},this.documentStyle,((_extends3={})[nodeType]={},_extends3)))},_proto.mergeWith=function(documentStyle){return Object.entries(documentStyle).reduce((function(acc,_ref){var key=_ref[0],style=_ref[1];return acc.setStyle(key,style)}),new RicosDocumentStyle(this.documentStyle))},RicosDocumentStyle}(),RicosStyles=function(){function RicosStyles(){this.theme=void 0,this.documentStyle=void 0}var _proto=RicosStyles.prototype;return _proto.toStyleTags=function(){return[this.theme.toStyleTag(),this.documentStyle.toStyleTag()]},_proto.getDecoration=function(node,decorationType){if(!["PARAGRAPH","HEADING","BLOCKQUOTE","CODE_BLOCK"].includes(node.type))return{};var nodeType=new TextNodeTransformer(node).getDocumentStyleKey(),documentStyleDecoration=this.documentStyle.getDecoration(nodeType,decorationType);return this.theme.getDecoration(nodeType,decorationType).overrideWith(documentStyleDecoration).getDecoration()},_proto.getTextStyle=function(node){var nodeType=new TextNodeTransformer(node).getDocumentStyleKey(),documentStyleTextStyle=this.documentStyle.getTextStyle(nodeType);return this.theme.getTextStyle(nodeType).overrideWith(documentStyleTextStyle.getTextStyle()).getTextStyle()},_proto.getNodeStyle=function(node){var nodeType=new TextNodeTransformer(node).getDocumentStyleKey(),documentStyleNodeStyle=this.documentStyle.getNodeStyle(nodeType);return this.theme.getNodeStyle(nodeType).overrideWith(documentStyleNodeStyle.getNodeStyle()).getNodeStyle()},_proto.getTheme=function(){return this.theme},_proto.setTheme=function(theme){return this.theme=new RicosTextualTheme(theme),this},_proto.getDocumentStyle=function(){return this.documentStyle},_proto.setDocumentStyle=function(documentStyle){return this.documentStyle=new RicosDocumentStyle(documentStyle),this},RicosStyles}();export{RicosDocumentStyle as DocumentStyle,RicosStyles};
import _extends from"@babel/runtime/helpers/extends";import _objectWithoutPropertiesLoose from"@babel/runtime/helpers/objectWithoutPropertiesLoose";import{firstRight}from"ricos-content";import{fromEntries}from"ricos-content/libs/utils";import _inheritsLoose from"@babel/runtime/helpers/inheritsLoose";import{createPalette,themeStrategy}from"ricos-common";import{isEmpty}from"lodash";import{parseDocStyle}from"ricos-content/libs/converters";var EmptyDecoration=function(){function EmptyDecoration(){this.type="UNRECOGNIZED"}var _proto=EmptyDecoration.prototype;return _proto.getDecoration=function(){return{}},_proto.fromCustomStyle=function(_customStyle){return new EmptyDecoration},_proto.toCustomStyle=function(){return{}},_proto.overrideWith=function(decoration){return decoration},EmptyDecoration}(),BoldDecoration=function(){function BoldDecoration(customStyle){this.type="BOLD",this.customStyle=void 0,this.customStyle=customStyle}BoldDecoration.of=function(decoration){if("BOLD"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);return new BoldDecoration({fontWeight:decoration.fontWeightValue||700})};var _proto=BoldDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,fontWeightValue:parseInt(this.customStyle.fontWeight,10)||700}},BoldDecoration.fromCustomStyle=function(customStyle){return new BoldDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return BoldDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof BoldDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new BoldDecoration(_extends({},this.customStyle,decoration.toCustomStyle()))},BoldDecoration}(),ColorDecoration=function(){function ColorDecoration(customStyle){this.type="COLOR",this.customStyle=void 0,this.customStyle=customStyle}ColorDecoration.of=function(decoration){if("COLOR"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);var _ref=decoration.colorData||{};return new ColorDecoration({color:_ref.foreground,backgroundColor:_ref.background})};var _proto=ColorDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,colorData:_extends({},this.customStyle.color&&{foreground:this.customStyle.color},this.customStyle.backgroundColor&&{background:this.customStyle.backgroundColor})}},ColorDecoration.fromCustomStyle=function(customStyle){return new ColorDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return ColorDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof ColorDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new ColorDecoration(_extends({},this.customStyle,decoration.toCustomStyle()))},ColorDecoration}(),FontSizeDecoration=function(){function FontSizeDecoration(customStyle){this.type="FONT_SIZE",this.customStyle=void 0,this.customStyle=customStyle}FontSizeDecoration.of=function(decoration){var _decoration$fontSizeD,_decoration$fontSizeD2,_decoration$fontSizeD3;if("FONT_SIZE"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);var value=null===(_decoration$fontSizeD=decoration.fontSizeData)||void 0===_decoration$fontSizeD?void 0:_decoration$fontSizeD.value,unit=null===(_decoration$fontSizeD2=decoration.fontSizeData)||void 0===_decoration$fontSizeD2||null===(_decoration$fontSizeD3=_decoration$fontSizeD2.unit)||void 0===_decoration$fontSizeD3?void 0:_decoration$fontSizeD3.toLocaleLowerCase();return new FontSizeDecoration(value?{fontSize:""+value+unit}:{})};var _proto=FontSizeDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,fontSizeData:{value:parseInt(this.customStyle.fontSize),unit:"PX"}}},FontSizeDecoration.fromCustomStyle=function(customStyle){return new FontSizeDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return FontSizeDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof FontSizeDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new FontSizeDecoration(_extends({},this.customStyle,decoration.toCustomStyle()))},FontSizeDecoration}(),ItalicDecoration=function(){function ItalicDecoration(customStyle){this.type="ITALIC",this.customStyle=void 0,this.customStyle=customStyle}ItalicDecoration.of=function(decoration){if("ITALIC"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);return new ItalicDecoration(decoration.italicData?{fontStyle:"italic"}:{})};var _proto=ItalicDecoration.prototype;return _proto.getDecoration=function(){var _this$customStyle$fon;return{type:this.type,italicData:null===(_this$customStyle$fon=this.customStyle.fontStyle)||void 0===_this$customStyle$fon?void 0:_this$customStyle$fon.includes("italic")}},ItalicDecoration.fromCustomStyle=function(customStyle){return new ItalicDecoration(customStyle)},_proto.fromCustomStyle=function(customStyle){return ItalicDecoration.fromCustomStyle(customStyle)},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(decoration){if(!(decoration instanceof ItalicDecoration||decoration instanceof EmptyDecoration))throw new TypeError("invalid merge decoration "+decoration);return new ItalicDecoration(_extends({},this.customStyle,decoration.toCustomStyle()))},ItalicDecoration}(),_excluded=["color","backgroundColor"],Decorations=function(){function Decorations(textDecorations){this.decorations=void 0,this.decorations=textDecorations}Decorations.of=function(decorations){return new Decorations((decorations||[]).map(Decorations.toTextDecoration))},Decorations.fromCustomStyle=function(customStyle){var color=customStyle.color,backgroundColor=customStyle.backgroundColor,rest=_objectWithoutPropertiesLoose(customStyle,_excluded),colorStyle={color:color,backgroundColor:backgroundColor};return new Decorations(Object.entries(rest).map((function(_ref){var _ref2,k=_ref[0],v=_ref[1];return(_ref2={})[k]=v,_ref2})).concat([colorStyle]).map(Decorations.styleToDecoration))},Decorations.styleToDecoration=function(style){return firstRight(style,Decorations.empty,[[function(s){return!!s.fontWeight},function(s){return BoldDecoration.fromCustomStyle(s)}],[function(s){return!!s.fontSize},function(s){return FontSizeDecoration.fromCustomStyle(s)}],[function(s){return!!s.fontStyle},function(s){return ItalicDecoration.fromCustomStyle(s)}],[function(s){return!!s.color},function(s){return ColorDecoration.fromCustomStyle(s)}]])},Decorations.toTextDecoration=function(decoration){return firstRight(decoration,Decorations.empty,[[function(d){return"BOLD"===d.type},function(d){return BoldDecoration.of(d)}],[function(d){return"ITALIC"===d.type},function(d){return ItalicDecoration.of(d)}],[function(d){return"FONT_SIZE"===d.type},function(d){return FontSizeDecoration.of(d)}],[function(d){return"COLOR"===d.type},function(d){return ColorDecoration.of(d)}]])};var _proto=Decorations.prototype;return _proto.toDecorationArray=function(){return this.decorations.filter((function(d){return"UNRECOGNIZED"!==d.type})).map((function(d){return d.getDecoration()}))},_proto.byType=function(type){return this.decorations.find((function(d){return d.type===type}))||Decorations.empty},_proto.toCustomStyle=function(){return this.decorations.reduce((function(style,decoration){return _extends({},style,decoration.toCustomStyle())}),{})},_proto.overrideWith=function(decorations){var _this=this,overridenDecorations=decorations.map(Decorations.toTextDecoration).map((function(decoration){return _this.byType(decoration.type).overrideWith(decoration)})),types=overridenDecorations.map((function(decoration){return decoration.type}));return new Decorations(this.decorations.filter((function(decoration){return!types.includes(decoration.type)})).concat(overridenDecorations))},Decorations}();function flow(ab,bc,cd,de,ef,fg,gh,hi,ij){switch(arguments.length){case 1:return ab;case 2:return function(){return bc(ab.apply(this,arguments))};case 3:return function(){return cd(bc(ab.apply(this,arguments)))};case 4:return function(){return de(cd(bc(ab.apply(this,arguments))))};case 5:return function(){return ef(de(cd(bc(ab.apply(this,arguments)))))};case 6:return function(){return fg(ef(de(cd(bc(ab.apply(this,arguments))))))};case 7:return function(){return gh(fg(ef(de(cd(bc(ab.apply(this,arguments)))))))};case 8:return function(){return hi(gh(fg(ef(de(cd(bc(ab.apply(this,arguments))))))))};case 9:return function(){return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this,arguments)))))))))}}}Decorations.empty=new EmptyDecoration;var map=function(f){return function(fa){return fa.map((function(a){return f(a)}))}},Ord={equals:function(first,second){return first===second},compare:function(first,second){return first<second?-1:first>second?1:0}};function collect(O){if("function"==typeof O)return collect(Ord)(O);var keysO=function(O){return function(r){return Object.keys(r).sort(O.compare)}}(O);return function(f){return function(r){for(var out=[],_i=0,_a=keysO(r);_i<_a.length;_i++){var key=_a[_i];out.push(f(key,r[key]))}return out}}}var toArray=collect(Ord)((function(k,a){return[k,a]}));var fst=function(ea){return ea[0]},snd=function(ea){return ea[1]},bimap=function(f,g){return function(fa){return[g(fst(fa)),f(snd(fa))]}},CustomStyle=function(){function CustomStyle(key,customStyle){this.key=void 0,this.customStyle=void 0,this.key=key,this.customStyle=customStyle}var _proto=CustomStyle.prototype;return _proto.getKey=function(){return this.key},_proto.toCustomStyle=function(){return this.customStyle},_proto.overrideWith=function(customStyle){if("empty"!==customStyle.key&&this.key!==customStyle.key)throw new Error("Different keys, "+this.key+" doesn't equal to "+customStyle.key);return new CustomStyle(this.key,_extends({},this.customStyle,customStyle.customStyle))},CustomStyle}(),EmptyCustomStyle=function(_CustomStyle){function EmptyCustomStyle(){return _CustomStyle.call(this,"empty",{})||this}return _inheritsLoose(EmptyCustomStyle,_CustomStyle),EmptyCustomStyle.prototype.overrideWith=function(customStyle){return customStyle},EmptyCustomStyle}(CustomStyle),textCustomStylesKeys=["h1","h2","h3","h4","h5","h6","p","quote","codeBlock"],CustomStyles=function(){function CustomStyles(customStyles){this.customStyles=void 0,this.customStyles=customStyles}CustomStyles.of=function(rawCustomStyles){return new CustomStyles(Object.entries(rawCustomStyles).map((function(_ref){var key=_ref[0],value=_ref[1];return new CustomStyle(key,value)})))},CustomStyles.fromTheme=function(theme){var customStyles=theme.customStyles||{},colors=createPalette(theme.palette,theme.paletteConfig).colors,_ref2=colors||{},color=_ref2.textColor,backgroundColor=_ref2.bgColor;if(null!=colors&&colors.textColor||null!=colors&&colors.bgColor){var colorsCustomStyles=textCustomStylesKeys.reduce((function(acc,key){var _extends2;return _extends({},acc,((_extends2={})[key]={color:color,backgroundColor:backgroundColor},_extends2))}),{});return CustomStyles.of(colorsCustomStyles).overrideWith(CustomStyles.of(customStyles))}return CustomStyles.of(customStyles)};var _proto=CustomStyles.prototype;return _proto.toCustomStyles=function(){return this.customStyles.reduce((function(acc,style){var _ref3,customStyle=style.toCustomStyle();return _extends({},acc,isEmpty(customStyle)?{}:((_ref3={})[style.getKey()]=customStyle,_ref3))}),{})},_proto.byKey=function(key){return this.customStyles.find((function(style){return style.getKey()===key}))||CustomStyles.empty},_proto.overrideWith=function(customStyles){var _this=this,genericCustomStyles=textCustomStylesKeys.reduce((function(acc,key){var _extends3;return _extends({},acc,((_extends3={})[key]={},_extends3))}),{}),overridenCustomStyles=CustomStyles.of(genericCustomStyles).customStyles.map((function(style){return style.overrideWith(_this.byKey(style.getKey())).overrideWith(customStyles.byKey(style.getKey()))}));return new CustomStyles(overridenCustomStyles)},CustomStyles}();CustomStyles.empty=new EmptyCustomStyle;var RicosNodeStyle=function(){function RicosNodeStyle(nodeStyle){var _this=this;this.nodeStyle=void 0,this.getNodeStyle=function(){return _this.nodeStyle},this.toCustomStyle=function(){return{paddingBottom:_this.nodeStyle.paddingBottom,paddingTop:_this.nodeStyle.paddingTop}},this.overrideWith=function(NodeStyle){return void 0===NodeStyle&&(NodeStyle={}),RicosNodeStyle.of(_extends({},_this.nodeStyle,NodeStyle))},this.nodeStyle=nodeStyle}return RicosNodeStyle.of=function(nodeStyle){return new RicosNodeStyle(nodeStyle||{})},RicosNodeStyle}();RicosNodeStyle.fromCustomStyle=function(customStyle){var nodeStyle={paddingBottom:customStyle.paddingBottom,paddingTop:customStyle.paddingTop};return RicosNodeStyle.of(nodeStyle)};var RicosTextStyle=function(){function RicosTextStyle(_textStyle){var _this=this;this.textStyle=void 0,this.getTextStyle=function(){return _this.textStyle},this.toCustomStyle=function(){return{lineHeight:_this.textStyle.lineHeight}},this.overrideWith=function(textStyle){return RicosTextStyle.of(_extends({},_this.textStyle,textStyle))},this.textStyle=_textStyle}return RicosTextStyle.of=function(textStyle){return new RicosTextStyle(textStyle||{})},RicosTextStyle}();RicosTextStyle.fromCustomStyle=function(customStyle){var textStyle={lineHeight:customStyle.lineHeight};return RicosTextStyle.of(textStyle)};var _nodeTypeToDocumentKe,_nodeTypeToNodeDataKe,documentToThemeKeyMap={headerOne:"h1",headerTwo:"h2",headerThree:"h3",headerFour:"h4",headerFive:"h5",headerSix:"h6",paragraph:"p",blockquote:"quote",codeBlock:"codeBlock"},themeToDocumentKeyMap=function(a,ab,bc,cd,de,ef,fg,gh,hi){switch(arguments.length){case 1:return a;case 2:return ab(a);case 3:return bc(ab(a));case 4:return cd(bc(ab(a)));case 5:return de(cd(bc(ab(a))));case 6:return ef(de(cd(bc(ab(a)))));case 7:return fg(ef(de(cd(bc(ab(a))))));case 8:return gh(fg(ef(de(cd(bc(ab(a)))))));case 9:return hi(gh(fg(ef(de(cd(bc(ab(a))))))));default:for(var ret=arguments[0],i=1;i<arguments.length;i++)ret=arguments[i](ret);return ret}}(documentToThemeKeyMap,Object.entries,map((function(ea){return[snd(ea),fst(ea)]})),fromEntries),toRicosCustomStyles=flow((function(documentStyle){return toArray(documentStyle)}),map(bimap((function(node){return _extends({},Decorations.of(node.decorations).toCustomStyle(),RicosNodeStyle.of(node.nodeStyle).toCustomStyle(),RicosTextStyle.of({lineHeight:node.lineHeight}).toCustomStyle())}),(function(nodeType){return documentToThemeKeyMap[nodeType]}))),(function(tuple){return fromEntries(tuple)})),_toDocumentStyle=flow(Object.entries,map(bimap((function(customStyle){return{decorations:Decorations.fromCustomStyle(customStyle).toDecorationArray(),nodeStyle:RicosNodeStyle.fromCustomStyle(customStyle).getNodeStyle(),lineHeight:RicosTextStyle.fromCustomStyle(customStyle).getTextStyle().lineHeight}}),(function(customStyleKey){return themeToDocumentKeyMap[customStyleKey]}))),fromEntries,JSON.stringify,JSON.parse),TextStyleTransformer=function(){function TextStyleTransformer(theme){this.theme=void 0,this.theme=theme}TextStyleTransformer.fromTheme=function(theme){return new TextStyleTransformer(theme||{})},TextStyleTransformer.fromDocumentStyle=function(documentStyle){return new TextStyleTransformer({customStyles:toRicosCustomStyles(documentStyle)})};var _proto=TextStyleTransformer.prototype;return _proto.toTheme=function(){return this.theme},_proto.toDocumentStyle=function(){return _toDocumentStyle(CustomStyles.fromTheme(this.theme).toCustomStyles())},TextStyleTransformer}(),RicosTextualTheme=function(){function RicosTextualTheme(theme){this.theme=void 0,this.documentStyle=void 0,this.theme=theme,this.documentStyle=TextStyleTransformer.fromTheme(this.theme).toDocumentStyle()}var _proto=RicosTextualTheme.prototype;return _proto.getDecoration=function(nodeType,decorationType){var textNodeStyle=this.documentStyle[nodeType];return Decorations.of((null==textNodeStyle?void 0:textNodeStyle.decorations)||[]).byType(decorationType)},_proto.getTextStyle=function(nodeType){var _this$documentStyle$n;return RicosTextStyle.of({lineHeight:null===(_this$documentStyle$n=this.documentStyle[nodeType])||void 0===_this$documentStyle$n?void 0:_this$documentStyle$n.lineHeight})},_proto.getNodeStyle=function(nodeType){var _this$documentStyle$n2;return RicosNodeStyle.of(null===(_this$documentStyle$n2=this.documentStyle[nodeType])||void 0===_this$documentStyle$n2?void 0:_this$documentStyle$n2.nodeStyle)},_proto.toStyleTag=function(){return themeStrategy({ricosTheme:this.theme}).html},RicosTextualTheme}(),nodeTypeToDocumentKeyMap=((_nodeTypeToDocumentKe={})[1]="headerOne",_nodeTypeToDocumentKe[2]="headerTwo",_nodeTypeToDocumentKe[3]="headerThree",_nodeTypeToDocumentKe[4]="headerFour",_nodeTypeToDocumentKe[5]="headerFive",_nodeTypeToDocumentKe[6]="headerSix",_nodeTypeToDocumentKe.PARAGRAPH="paragraph",_nodeTypeToDocumentKe.BLOCKQUOTE="blockquote",_nodeTypeToDocumentKe.CODE_BLOCK="codeBlock",_nodeTypeToDocumentKe),nodeTypeToNodeDataKey=((_nodeTypeToNodeDataKe={}).HEADING="headingData",_nodeTypeToNodeDataKe.PARAGRAPH="paragraphData",_nodeTypeToNodeDataKe.BLOCKQUOTE="blockquoteData",_nodeTypeToNodeDataKe.CODE_BLOCK="codeBlockData",_nodeTypeToNodeDataKe),TextNodeTransformer=function(){function TextNodeTransformer(node){var _this=this;this.node=void 0,this.getDocumentStyleKey=function(){var level="HEADING"===_this.node.type?_this.node.headingData.level:void 0;return nodeTypeToDocumentKeyMap[level?(_this.node.type,level):_this.node.type]},this.node=node}var _proto=TextNodeTransformer.prototype;return _proto.getDecorations=function(){return(node=this.node,"BLOCKQUOTE"===node.type?node.nodes[0].nodes:node.nodes).reduce((function(acc,node){return acc.overrideWith(node.textData.decorations)}),Decorations.of([])).toDecorationArray();var node},_proto.getNodeStyle=function(){return this.node.style},_proto.getTextStyle=function(){var dataKey=nodeTypeToNodeDataKey[this.node.type];return this.node[dataKey].textStyle||{}},_proto.toDocumentStyle=function(){var _ref;return(_ref={})[this.getDocumentStyleKey()]={decorations:this.getDecorations(),nodeStyle:this.getNodeStyle(),lineHeight:this.getTextStyle().lineHeight},_ref},TextNodeTransformer}(),RicosTextNodeStyle=function RicosTextNodeStyle(_style){var _this=this;this.style=void 0,this.getTextNodeStyle=function(){return _this.style},this.overrideWith=function(style){var decorations=Decorations.of(_this.style.decorations).overrideWith(style.decorations).toDecorationArray(),nodeStyle=RicosNodeStyle.of(_this.style.nodeStyle).overrideWith(style.nodeStyle||{}).getNodeStyle(),lineHeight=RicosTextStyle.of({lineHeight:_this.style.lineHeight}).overrideWith({lineHeight:style.lineHeight}).getTextStyle().lineHeight,textNodeStyle=JSON.parse(JSON.stringify({decorations:decorations,nodeStyle:nodeStyle,lineHeight:lineHeight}));return new RicosTextNodeStyle(textNodeStyle)},this.style=_style},RicosDocumentStyle=function(){function RicosDocumentStyle(documentStyle){this.documentStyle=void 0,this.documentStyle=documentStyle}RicosDocumentStyle.fromNode=function(node){return new RicosDocumentStyle(new TextNodeTransformer(node).toDocumentStyle())};var _proto=RicosDocumentStyle.prototype;return _proto.getDecoration=function(nodeType,decorationType){var _this$documentStyle$n;return Decorations.of((null===(_this$documentStyle$n=this.documentStyle[nodeType])||void 0===_this$documentStyle$n?void 0:_this$documentStyle$n.decorations)||[]).byType(decorationType)},_proto.getDecorations=function(node){var _this$documentStyle$d,documentStyleKey=new TextNodeTransformer(node).getDocumentStyleKey();return Decorations.of((null===(_this$documentStyle$d=this.documentStyle[documentStyleKey])||void 0===_this$documentStyle$d?void 0:_this$documentStyle$d.decorations)||[]).toDecorationArray()},_proto.getTextStyle=function(nodeType){var _this$documentStyle$n2;return RicosTextStyle.of({lineHeight:null===(_this$documentStyle$n2=this.documentStyle[nodeType])||void 0===_this$documentStyle$n2?void 0:_this$documentStyle$n2.lineHeight})},_proto.getNodeStyle=function(nodeType){var _this$documentStyle$n3;return RicosNodeStyle.of(null===(_this$documentStyle$n3=this.documentStyle[nodeType])||void 0===_this$documentStyle$n3?void 0:_this$documentStyle$n3.nodeStyle)},_proto.toStyleTag=function(){var theme=TextStyleTransformer.fromDocumentStyle(this.documentStyle).toTheme();return new RicosTextualTheme(theme).toStyleTag()},_proto.toContent=function(){return this.documentStyle},_proto.setStyle=function(nodeType,textNodeStyle){var _extends2,style=new RicosTextNodeStyle(this.documentStyle[nodeType]||{decorations:[]}).overrideWith(textNodeStyle).getTextNodeStyle();return new RicosDocumentStyle(_extends({},this.documentStyle,((_extends2={})[nodeType]=style,_extends2)))},_proto.resetStyle=function(nodeType){var _extends3;return new RicosDocumentStyle(_extends({},this.documentStyle,((_extends3={})[nodeType]={},_extends3)))},_proto.mergeWith=function(documentStyle){return Object.entries(documentStyle).reduce((function(acc,_ref){var key=_ref[0],style=_ref[1];return acc.setStyle(key,style)}),new RicosDocumentStyle(this.documentStyle))},RicosDocumentStyle}(),RicosStyles=function(){function RicosStyles(){this.theme=void 0,this.documentStyle=void 0}var _proto=RicosStyles.prototype;return _proto.toStyleTags=function(){return[this.theme.toStyleTag(),this.documentStyle.toStyleTag()]},_proto.getDecoration=function(node,decorationType){if(!["PARAGRAPH","HEADING","BLOCKQUOTE","CODE_BLOCK"].includes(node.type))return{};var nodeType=new TextNodeTransformer(node).getDocumentStyleKey(),documentStyleDecoration=this.documentStyle.getDecoration(nodeType,decorationType);return this.theme.getDecoration(nodeType,decorationType).overrideWith(documentStyleDecoration).getDecoration()},_proto.getTextStyle=function(node){var nodeType=new TextNodeTransformer(node).getDocumentStyleKey(),documentStyleTextStyle=this.documentStyle.getTextStyle(nodeType);return this.theme.getTextStyle(nodeType).overrideWith(documentStyleTextStyle.getTextStyle()).getTextStyle()},_proto.getNodeStyle=function(node){var nodeType=new TextNodeTransformer(node).getDocumentStyleKey(),documentStyleNodeStyle=this.documentStyle.getNodeStyle(nodeType);return this.theme.getNodeStyle(nodeType).overrideWith(documentStyleNodeStyle.getNodeStyle()).getNodeStyle()},_proto.getTheme=function(){return this.theme},_proto.setTheme=function(theme){return this.theme=new RicosTextualTheme(theme),this},_proto.getDocumentStyle=function(){return this.documentStyle},_proto.setDocumentStyle=function(documentStyle){return this.documentStyle=new RicosDocumentStyle(documentStyle),this},_proto.toDraftDocumentStyle=function(){return parseDocStyle(this.documentStyle.toContent())},RicosStyles}();export{RicosDocumentStyle as DocumentStyle,RicosStyles};
//# sourceMappingURL=index.js.map
/// <reference types="react" />
import type { Decoration_Type, DocumentStyle as RichContentDocumentStyle, TextNodeStyle } from 'ricos-schema';
import type { Decoration_Type, DocumentStyle as RichContentDocumentStyle, TextNodeStyle, Decoration } from 'ricos-schema';
import type { TextDecoration } from '../models/decoration';

@@ -13,2 +13,3 @@ import type { DocumentStyle, TextNodeType } from '../models/styles';

getDecoration(nodeType: TextNodeType, decorationType: Decoration_Type): TextDecoration;
getDecorations(node: ParagraphNode | HeadingNode): Decoration[];
getTextStyle(nodeType: TextNodeType): RicosTextStyle;

@@ -15,0 +16,0 @@ getNodeStyle(nodeType: TextNodeType): RicosNodeStyle;

@@ -20,3 +20,4 @@ import type { ReactElement } from 'react';

setDocumentStyle(documentStyle: RichContentDocumentStyle): this;
toDraftDocumentStyle(): {};
}
//# sourceMappingURL=styles.d.ts.map
{
"name": "ricos-styles",
"version": "8.72.9",
"version": "8.72.10",
"author": {

@@ -38,9 +38,9 @@ "name": "Aviv Maimon",

"fp-ts": "^2.11.0",
"ricos-common": "8.72.9",
"ricos-schema": "8.72.9",
"ricos-types": "8.72.9",
"ricos-common": "8.72.10",
"ricos-schema": "8.72.10",
"ricos-types": "8.72.10",
"to-camel-case": "1.0.0"
},
"devDependencies": {
"ricos-content": "8.72.9"
"ricos-content": "8.72.10"
},

@@ -47,0 +47,0 @@ "peerDependencies": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc