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.71.17 to 8.71.18-alpha.0

dist/src/bold-decoration.d.ts

2

dist/cjs/index.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _extends=require("@babel/runtime/helpers/extends"),ricosCommon=require("ricos-common");function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var _extends__default=_interopDefaultLegacy(_extends),toNoCase_1=function(string){return hasSpace.test(string)?string.toLowerCase():hasSeparator.test(string)?(function(string){return string.replace(separatorSplitter,(function(m,next){return next?" "+next:""}))}(string)||string).toLowerCase():hasCamel.test(string)?function(string){return string.replace(camelSplitter,(function(m,previous,uppers){return previous+" "+uppers.toLowerCase().split("").join(" ")}))}(string).toLowerCase():string.toLowerCase()},hasSpace=/\s/,hasSeparator=/(_|-|\.|:)/,hasCamel=/([a-z][A-Z]|[A-Z][a-z])/;var separatorSplitter=/[\W_]+(.|$)/g;var camelSplitter=/(.)([A-Z]+)/g;var toSpaceCase_1=function(string){return toNoCase_1(string).replace(/[\W_]+(.|$)/g,(function(matches,match){return match?" "+match:""})).trim()};var toCamelCase_1=function(string){return toSpaceCase_1(string).replace(/\s(\w)/g,(function(matches,letter){return letter.toUpperCase()}))};var toCustomStyleType=function(nodeType){return{headerOne:"h1",headerTwo:"h2",headerThree:"h3",headerFour:"h4",headerFive:"h5",headerSix:"h6",paragraph:"p"}[nodeType]},fromDecoration=function(decoration){var _decoration$fontSizeD,_decoration$colorData,type=decoration.type;return _extends__default.default({},"BOLD"===type&&{fontWeight:decoration.fontWeightValue},"FONT_SIZE"===type&&{fontSize:null===(_decoration$fontSizeD=decoration.fontSizeData)||void 0===_decoration$fontSizeD?void 0:_decoration$fontSizeD.value},"COLOR"===type&&{color:null===(_decoration$colorData=decoration.colorData)||void 0===_decoration$colorData?void 0:_decoration$colorData.foreground},"UNDERLINE"===type&&{textDecoration:"underline"},"ITALIC"===type&&{fontStyle:"italic"})},toTheme=function(documentStyle){return{customStyles:Object.entries(documentStyle).map((function(_ref5){var _ref6,key=_ref5[0],value=_ref5[1];return(_ref6={})[toCustomStyleType(key)]=value.decorations.map(fromDecoration).reduce((function(curr,val){return _extends__default.default({},curr,val)})),_ref6})).reduce((function(curr,value){return _extends__default.default({},curr,value)}),{})}},TextualTheme=function TextualTheme(_theme){var _this=this;this.theme=void 0,this.getDecoration=function(nodeType,decorationType){var _this$theme$customSty,textType=toCustomStyleType(nodeType),textStyle=null===(_this$theme$customSty=_this.theme.customStyles)||void 0===_this$theme$customSty?void 0:_this$theme$customSty[textType];return textStyle&&function(textStyle,decorationType){var _ref,_ref2,_textStyle$textDecora,_ref3,_textStyle$fontStyle,_ref4,type=toCamelCase_1(decorationType);return _extends__default.default({type:decorationType},"BOLD"===decorationType&&{fontWeightValue:parseInt(null==textStyle?void 0:textStyle.fontWeight)},"FONT_SIZE"===decorationType&&((_ref={})[type+"Data"]={value:textStyle[type],unit:"PX"},_ref),"COLOR"===decorationType&&((_ref2={})[type+"Data"]={foreground:textStyle[type]},_ref2),"UNDERLINE"===decorationType&&((_ref3={})[type+"Data"]=null==textStyle||null===(_textStyle$textDecora=textStyle.textDecoration)||void 0===_textStyle$textDecora?void 0:_textStyle$textDecora.includes(type),_ref3),"ITALIC"===decorationType&&((_ref4={})[type+"Data"]=null==textStyle||null===(_textStyle$fontStyle=textStyle.fontStyle)||void 0===_textStyle$fontStyle?void 0:_textStyle$fontStyle.includes(type),_ref4))}(textStyle,decorationType)},this.toStyleTag=function(){return ricosCommon.themeStrategy({ricosTheme:_this.theme}).html},this.setTheme=function(theme){return new TextualTheme(theme)},this.theme=_theme},DocumentStyle=function DocumentStyle(_documentStyle){var _this=this;this.documentStyle=void 0,this.getDecoration=function(nodeType,decorationType){var _this$documentStyle$n;return null===(_this$documentStyle$n=_this.documentStyle[nodeType])||void 0===_this$documentStyle$n?void 0:_this$documentStyle$n.decorations.filter((function(decoration){return decoration.type===decorationType}))[0]},this.toStyleTag=function(){return new TextualTheme(toTheme(_this.documentStyle)).toStyleTag()},this.toContent=function(){return _this.documentStyle},this.setStyle=function(nodeType,decorations){var _extends2;return new DocumentStyle(_extends__default.default({},_this.documentStyle,((_extends2={})[nodeType]={decorations:decorations},_extends2)))},this.setDocumentStyle=function(documentStyle){return new DocumentStyle(documentStyle)},this.documentStyle=_documentStyle},Styles=function(){function Styles(theme,documentStyle){var _this=this;this.theme=void 0,this.documentStyle=void 0,this.getDecoration=function(nodeType,decorationType){var documentStyleDecoration=_this.getDocumentStyle().getDecoration(nodeType,decorationType),themeDecoration=_this.getTheme().getDecoration(nodeType,decorationType);return documentStyleDecoration&&themeDecoration?_extends__default.default({},themeDecoration,documentStyleDecoration):documentStyleDecoration||themeDecoration},this.getTheme=function(){return new TextualTheme(_this.theme)},this.getDocumentStyle=function(){return new DocumentStyle(_this.documentStyle)},this.theme=theme,this.documentStyle=documentStyle}return Styles.prototype.toStyleTags=function(){throw new Error("Method not implemented.")},Styles}();exports.Styles=Styles;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),_extends=require("@babel/runtime/helpers/extends"),ricosContent=require("ricos-content"),utils=require("ricos-content/libs/utils"),ricosCommon=require("ricos-common");function _interopDefaultLegacy(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var React__default=_interopDefaultLegacy(React),_extends__default=_interopDefaultLegacy(_extends),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){var _decoration$colorData;if("COLOR"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);return new ColorDecoration(null!==(_decoration$colorData=decoration.colorData)&&void 0!==_decoration$colorData&&_decoration$colorData.foreground?{color:decoration.colorData.foreground}:{})};var _proto=ColorDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,colorData:{foreground:this.customStyle.color}}},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;if("FONT_SIZE"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);return new FontSizeDecoration(null!==(_decoration$fontSizeD=decoration.fontSizeData)&&void 0!==_decoration$fontSizeD&&_decoration$fontSizeD.value?{fontSize:null===(_decoration$fontSizeD2=decoration.fontSizeData)||void 0===_decoration$fontSizeD2?void 0:_decoration$fontSizeD2.value}:{})};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}(),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){return new Decorations(Object.entries(customStyle).map((function(_ref){var _ref2,k=_ref[0],v=_ref[1];return(_ref2={})[k]=v,_ref2})).map(Decorations.styleToDecoraiton))},Decorations.styleToDecoraiton=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.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())}),{})},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))]}},documentToThemeKeyMap={headerOne:"h1",headerTwo:"h2",headerThree:"h3",headerFour:"h4",headerFive:"h5",headerSix:"h6",paragraph:"p"},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 Decorations.of(node.decorations).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()}}),(function(customStyleKey){return themeToDocumentKeyMap[customStyleKey]}))),utils.fromEntries),TextStyle=function(){function TextStyle(customStyle){this.customStyle=void 0,this.customStyle=customStyle}TextStyle.fromTheme=function(theme){return new TextStyle(theme.customStyles||{})},TextStyle.fromDocumentStyle=function(documentStyle){return new TextStyle(toRicosCustomStyles(documentStyle))};var _proto=TextStyle.prototype;return _proto.toThemeCustomStyles=function(){return this.customStyle},_proto.toDocumentStyle=function(){return _toDocumentStyle(this.customStyle)},TextStyle}(),RicosTextualTheme=function(){function RicosTextualTheme(theme){this.theme=void 0,this.theme=theme}var _proto=RicosTextualTheme.prototype;return _proto.getDecoration=function(nodeType,decorationType){var textNodeStyle=TextStyle.fromTheme(this.theme).toDocumentStyle()[nodeType];return Decorations.of((null==textNodeStyle?void 0:textNodeStyle.decorations)||[]).byType(decorationType)},_proto.toStyleTag=function(){return ricosCommon.themeStrategy({ricosTheme:this.theme}).html},RicosTextualTheme}(),RicosDocumentStyle=function(){function RicosDocumentStyle(documentStyle){this.documentStyle=void 0,this.documentStyle=documentStyle}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.toStyleTag=function(){var customStyles=TextStyle.fromDocumentStyle(this.documentStyle).toThemeCustomStyles();return new RicosTextualTheme({customStyles:customStyles}).toStyleTag()},_proto.toContent=function(){return this.documentStyle},_proto.setStyle=function(nodeType,decorations){var _extends2;return new RicosDocumentStyle(_extends__default.default({},this.documentStyle,((_extends2={})[nodeType]={decorations:decorations},_extends2)))},RicosDocumentStyle}(),styles=new(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(nodeType,decorationType){var documentStyleDecoration=this.documentStyle.getDecoration(nodeType,decorationType);return this.theme.getDecoration(nodeType,decorationType).overrideWith(documentStyleDecoration).getDecoration()},_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}()),StylesContext=React__default.default.createContext(styles);exports.StylesContext=StylesContext;
//# sourceMappingURL=index.js.map

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

import _extends from"@babel/runtime/helpers/extends";import{themeStrategy}from"ricos-common";var toNoCase_1=function(string){return hasSpace.test(string)?string.toLowerCase():hasSeparator.test(string)?(function(string){return string.replace(separatorSplitter,(function(m,next){return next?" "+next:""}))}(string)||string).toLowerCase():hasCamel.test(string)?function(string){return string.replace(camelSplitter,(function(m,previous,uppers){return previous+" "+uppers.toLowerCase().split("").join(" ")}))}(string).toLowerCase():string.toLowerCase()},hasSpace=/\s/,hasSeparator=/(_|-|\.|:)/,hasCamel=/([a-z][A-Z]|[A-Z][a-z])/;var separatorSplitter=/[\W_]+(.|$)/g;var camelSplitter=/(.)([A-Z]+)/g;var toSpaceCase_1=function(string){return toNoCase_1(string).replace(/[\W_]+(.|$)/g,(function(matches,match){return match?" "+match:""})).trim()};var toCamelCase_1=function(string){return toSpaceCase_1(string).replace(/\s(\w)/g,(function(matches,letter){return letter.toUpperCase()}))};var toCustomStyleType=function(nodeType){return{headerOne:"h1",headerTwo:"h2",headerThree:"h3",headerFour:"h4",headerFive:"h5",headerSix:"h6",paragraph:"p"}[nodeType]},fromDecoration=function(decoration){var _decoration$fontSizeD,_decoration$colorData,type=decoration.type;return _extends({},"BOLD"===type&&{fontWeight:decoration.fontWeightValue},"FONT_SIZE"===type&&{fontSize:null===(_decoration$fontSizeD=decoration.fontSizeData)||void 0===_decoration$fontSizeD?void 0:_decoration$fontSizeD.value},"COLOR"===type&&{color:null===(_decoration$colorData=decoration.colorData)||void 0===_decoration$colorData?void 0:_decoration$colorData.foreground},"UNDERLINE"===type&&{textDecoration:"underline"},"ITALIC"===type&&{fontStyle:"italic"})},toTheme=function(documentStyle){return{customStyles:Object.entries(documentStyle).map((function(_ref5){var _ref6,key=_ref5[0],value=_ref5[1];return(_ref6={})[toCustomStyleType(key)]=value.decorations.map(fromDecoration).reduce((function(curr,val){return _extends({},curr,val)})),_ref6})).reduce((function(curr,value){return _extends({},curr,value)}),{})}},TextualTheme=function TextualTheme(_theme){var _this=this;this.theme=void 0,this.getDecoration=function(nodeType,decorationType){var _this$theme$customSty,textType=toCustomStyleType(nodeType),textStyle=null===(_this$theme$customSty=_this.theme.customStyles)||void 0===_this$theme$customSty?void 0:_this$theme$customSty[textType];return textStyle&&function(textStyle,decorationType){var _ref,_ref2,_textStyle$textDecora,_ref3,_textStyle$fontStyle,_ref4,type=toCamelCase_1(decorationType);return _extends({type:decorationType},"BOLD"===decorationType&&{fontWeightValue:parseInt(null==textStyle?void 0:textStyle.fontWeight)},"FONT_SIZE"===decorationType&&((_ref={})[type+"Data"]={value:textStyle[type],unit:"PX"},_ref),"COLOR"===decorationType&&((_ref2={})[type+"Data"]={foreground:textStyle[type]},_ref2),"UNDERLINE"===decorationType&&((_ref3={})[type+"Data"]=null==textStyle||null===(_textStyle$textDecora=textStyle.textDecoration)||void 0===_textStyle$textDecora?void 0:_textStyle$textDecora.includes(type),_ref3),"ITALIC"===decorationType&&((_ref4={})[type+"Data"]=null==textStyle||null===(_textStyle$fontStyle=textStyle.fontStyle)||void 0===_textStyle$fontStyle?void 0:_textStyle$fontStyle.includes(type),_ref4))}(textStyle,decorationType)},this.toStyleTag=function(){return themeStrategy({ricosTheme:_this.theme}).html},this.setTheme=function(theme){return new TextualTheme(theme)},this.theme=_theme},DocumentStyle=function DocumentStyle(_documentStyle){var _this=this;this.documentStyle=void 0,this.getDecoration=function(nodeType,decorationType){var _this$documentStyle$n;return null===(_this$documentStyle$n=_this.documentStyle[nodeType])||void 0===_this$documentStyle$n?void 0:_this$documentStyle$n.decorations.filter((function(decoration){return decoration.type===decorationType}))[0]},this.toStyleTag=function(){return new TextualTheme(toTheme(_this.documentStyle)).toStyleTag()},this.toContent=function(){return _this.documentStyle},this.setStyle=function(nodeType,decorations){var _extends2;return new DocumentStyle(_extends({},_this.documentStyle,((_extends2={})[nodeType]={decorations:decorations},_extends2)))},this.setDocumentStyle=function(documentStyle){return new DocumentStyle(documentStyle)},this.documentStyle=_documentStyle},Styles=function(){function Styles(theme,documentStyle){var _this=this;this.theme=void 0,this.documentStyle=void 0,this.getDecoration=function(nodeType,decorationType){var documentStyleDecoration=_this.getDocumentStyle().getDecoration(nodeType,decorationType),themeDecoration=_this.getTheme().getDecoration(nodeType,decorationType);return documentStyleDecoration&&themeDecoration?_extends({},themeDecoration,documentStyleDecoration):documentStyleDecoration||themeDecoration},this.getTheme=function(){return new TextualTheme(_this.theme)},this.getDocumentStyle=function(){return new DocumentStyle(_this.documentStyle)},this.theme=theme,this.documentStyle=documentStyle}return Styles.prototype.toStyleTags=function(){throw new Error("Method not implemented.")},Styles}();export{Styles};
import React from"react";import _extends from"@babel/runtime/helpers/extends";import{firstRight}from"ricos-content";import{fromEntries}from"ricos-content/libs/utils";import{themeStrategy}from"ricos-common";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){var _decoration$colorData;if("COLOR"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);return new ColorDecoration(null!==(_decoration$colorData=decoration.colorData)&&void 0!==_decoration$colorData&&_decoration$colorData.foreground?{color:decoration.colorData.foreground}:{})};var _proto=ColorDecoration.prototype;return _proto.getDecoration=function(){return{type:this.type,colorData:{foreground:this.customStyle.color}}},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;if("FONT_SIZE"!==decoration.type)throw new TypeError("invalid decoration initializer "+decoration);return new FontSizeDecoration(null!==(_decoration$fontSizeD=decoration.fontSizeData)&&void 0!==_decoration$fontSizeD&&_decoration$fontSizeD.value?{fontSize:null===(_decoration$fontSizeD2=decoration.fontSizeData)||void 0===_decoration$fontSizeD2?void 0:_decoration$fontSizeD2.value}:{})};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}(),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){return new Decorations(Object.entries(customStyle).map((function(_ref){var _ref2,k=_ref[0],v=_ref[1];return(_ref2={})[k]=v,_ref2})).map(Decorations.styleToDecoraiton))},Decorations.styleToDecoraiton=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.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())}),{})},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))]}},documentToThemeKeyMap={headerOne:"h1",headerTwo:"h2",headerThree:"h3",headerFour:"h4",headerFive:"h5",headerSix:"h6",paragraph:"p"},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 Decorations.of(node.decorations).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()}}),(function(customStyleKey){return themeToDocumentKeyMap[customStyleKey]}))),fromEntries),TextStyle=function(){function TextStyle(customStyle){this.customStyle=void 0,this.customStyle=customStyle}TextStyle.fromTheme=function(theme){return new TextStyle(theme.customStyles||{})},TextStyle.fromDocumentStyle=function(documentStyle){return new TextStyle(toRicosCustomStyles(documentStyle))};var _proto=TextStyle.prototype;return _proto.toThemeCustomStyles=function(){return this.customStyle},_proto.toDocumentStyle=function(){return _toDocumentStyle(this.customStyle)},TextStyle}(),RicosTextualTheme=function(){function RicosTextualTheme(theme){this.theme=void 0,this.theme=theme}var _proto=RicosTextualTheme.prototype;return _proto.getDecoration=function(nodeType,decorationType){var textNodeStyle=TextStyle.fromTheme(this.theme).toDocumentStyle()[nodeType];return Decorations.of((null==textNodeStyle?void 0:textNodeStyle.decorations)||[]).byType(decorationType)},_proto.toStyleTag=function(){return themeStrategy({ricosTheme:this.theme}).html},RicosTextualTheme}(),RicosDocumentStyle=function(){function RicosDocumentStyle(documentStyle){this.documentStyle=void 0,this.documentStyle=documentStyle}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.toStyleTag=function(){var customStyles=TextStyle.fromDocumentStyle(this.documentStyle).toThemeCustomStyles();return new RicosTextualTheme({customStyles:customStyles}).toStyleTag()},_proto.toContent=function(){return this.documentStyle},_proto.setStyle=function(nodeType,decorations){var _extends2;return new RicosDocumentStyle(_extends({},this.documentStyle,((_extends2={})[nodeType]={decorations:decorations},_extends2)))},RicosDocumentStyle}(),styles=new(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(nodeType,decorationType){var documentStyleDecoration=this.documentStyle.getDecoration(nodeType,decorationType);return this.theme.getDecoration(nodeType,decorationType).overrideWith(documentStyleDecoration).getDecoration()},_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}()),StylesContext=React.createContext(styles);export{StylesContext};
//# sourceMappingURL=index.js.map

@@ -10,3 +10,2 @@ import { Decoration_Type, FontSizeData_fontType } from 'ricos-schema';

italicData?: undefined;
underlineData?: undefined;
} | {

@@ -18,3 +17,2 @@ type: Decoration_Type;

italicData?: undefined;
underlineData?: undefined;
} | {

@@ -29,3 +27,2 @@ type: Decoration_Type;

italicData?: undefined;
underlineData?: undefined;
} | {

@@ -37,10 +34,2 @@ type: Decoration_Type;

fontSizeData?: undefined;
underlineData?: undefined;
} | {
type: Decoration_Type;
underlineData: boolean;
colorData?: undefined;
fontWeightValue?: undefined;
fontSizeData?: undefined;
italicData?: undefined;
})[];

@@ -52,4 +41,3 @@ export declare const customStyle: {

fontStyle: string;
textDecoration: string;
};
//# sourceMappingURL=consts.d.ts.map

@@ -1,12 +0,13 @@

import type { DocumentStyle as IDocumentStyle } from './models/styles';
import type { DocumentStyle as RichContentDocumentStyle } from 'ricos-schema';
export default class DocumentStyle implements IDocumentStyle {
/// <reference types="react" />
import type { Decoration, Decoration_Type, DocumentStyle as RichContentDocumentStyle } from 'ricos-schema';
import type { TextDecoration } from './models/decoration';
import type { DocumentStyle, TextNodeType } from './models/styles';
export default class RicosDocumentStyle implements DocumentStyle {
documentStyle: RichContentDocumentStyle;
constructor(documentStyle: RichContentDocumentStyle);
getDecoration: IDocumentStyle['getDecoration'];
toStyleTag: IDocumentStyle['toStyleTag'];
toContent: IDocumentStyle['toContent'];
setStyle: IDocumentStyle['setStyle'];
setDocumentStyle: IDocumentStyle['setDocumentStyle'];
getDecoration(nodeType: TextNodeType, decorationType: Decoration_Type): TextDecoration;
toStyleTag(): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
toContent(): RichContentDocumentStyle;
setStyle(nodeType: TextNodeType, decorations: Decoration[]): RicosDocumentStyle;
}
//# sourceMappingURL=document-style.d.ts.map

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

export { default as Styles } from './styles';
export { StylesContext } from './context';
//# sourceMappingURL=index.d.ts.map
import type { ReactElement } from 'react';
import type { DocumentStyle as RichContentDocumentStyle } from 'ricos-schema';
import type { Decoration_Type, DocumentStyle as RichContentDocumentStyle } from 'ricos-schema';
import type { RicosTheme } from 'ricos-types';
import type { Styles as IStyles } from './models/styles';
export default class Styles implements IStyles {
theme: RicosTheme;
documentStyle: RichContentDocumentStyle;
constructor(theme: RicosTheme, documentStyle: RichContentDocumentStyle);
import DocumentStyle from './document-style';
import type { Styles, TextNodeType } from './models/styles';
import TextualTheme from './textual-theme';
export default class RicosStyles implements Styles {
private theme;
private documentStyle;
toStyleTags(): ReactElement[];
getDecoration: IStyles['getDecoration'];
getTheme: IStyles['getTheme'];
getDocumentStyle: IStyles['getDocumentStyle'];
getDecoration(nodeType: TextNodeType, decorationType: Decoration_Type): import("ricos-schema").Decoration;
getTheme(): TextualTheme;
setTheme(theme: RicosTheme): this;
getDocumentStyle(): DocumentStyle;
setDocumentStyle(documentStyle: RichContentDocumentStyle): this;
}
//# sourceMappingURL=styles.d.ts.map

@@ -1,10 +0,12 @@

import type { TextualTheme as ITextualTheme } from './models/styles';
/// <reference types="react" />
import type { Decoration_Type } from 'ricos-schema';
import type { RicosTheme } from 'ricos-types';
export default class TextualTheme implements ITextualTheme {
import type { TextDecoration } from './models/decoration';
import type { TextNodeType, TextualTheme } from './models/styles';
export default class RicosTextualTheme implements TextualTheme {
theme: RicosTheme;
constructor(theme: RicosTheme);
getDecoration: ITextualTheme['getDecoration'];
toStyleTag: ITextualTheme['toStyleTag'];
setTheme: ITextualTheme['setTheme'];
getDecoration(nodeType: TextNodeType, decorationType: Decoration_Type): TextDecoration;
toStyleTag(): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
}
//# sourceMappingURL=textual-theme.d.ts.map
{
"name": "ricos-styles",
"version": "8.71.17",
"version": "8.71.18-alpha.0",
"author": {

@@ -37,5 +37,6 @@ "name": "Aviv Maimon",

"dependencies": {
"ricos-common": "8.71.17",
"ricos-schema": "8.71.17",
"ricos-types": "8.71.17",
"fp-ts": "^2.11.0",
"ricos-common": "8.71.18-alpha.0",
"ricos-schema": "8.71.18-alpha.0",
"ricos-types": "8.71.18-alpha.0",
"to-camel-case": "1.0.0"

@@ -42,0 +43,0 @@ },

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

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