@cleartrip/ct-design-text-editor-renderer 1.2.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ "use strict";var n=require("tslib"),e=require("react/jsx-runtime"),t=require("react"),r=require("styled-components"),i=require("@cleartrip/ct-design-typography"),o=require("@cleartrip/ct-design-conditional-wrap"),a=require("@cleartrip/ct-design-divider"),s=require("@cleartrip/ct-design-theme");function p(n){return n&&n.__esModule?n:{default:n}}var l,c=p(r),d=p(o),u=function(n){var e={};return[{id:1,style:{fontWeight:"700"}},{id:2,style:{fontStyle:"italic"}},{id:4,style:{textDecoration:"line-through"}},{id:8,style:{textDecoration:"underline"}},{id:12,style:{textDecoration:"line-through underline"}}].forEach((function(t){(n&t.id)===t.id&&Object.assign(e,t.style)})),e},h=function(n){return(null==n?void 0:n.length)?"ta-".concat(n):""},g=function(n){void 0===n&&(n="");var e={};return n.split(";").forEach((function(n){var t=n.split(":"),r=t[0],i=t[1];if(r){var o,a,s=(o=r.trim(),1===(a=o.split("-")).length?a[0]:a[0]+a.slice(1).map((function(n){return n[0].toUpperCase()+n.slice(1)})).join(""));e[s]=i.trim()}})),e},m={h1:{variant:"HM1",componentNode:"h1"},h2:{variant:"HM2",componentNode:"h2"},h3:{variant:"HM3",componentNode:"h3"},paragraph:{variant:"P2",componentNode:"p"},link:{variant:"L2",componentNode:"span"},list:{variant:"P2",componentNode:"li"}},x={h1:{variant:"HD3",componentNode:"h1"},h2:{variant:"HM1",componentNode:"h2"},h3:{variant:"HM2",componentNode:"h3"},paragraph:{variant:"P2",componentNode:"p"},link:{variant:"L2",componentNode:"span"},list:{variant:"P2",componentNode:"li"}},v=c.default.a(l||(l=n.__makeTemplateObject(["\n text-decoration: none;\n &:hover {\n text-decoration: underline;\n }\n"],["\n text-decoration: none;\n &:hover {\n text-decoration: underline;\n }\n"]))),f=function(r){var o,p=r.content,l=r.typographyConfig;if(!p)return null;var c=s.useThemeContext().platform,d=l||("desktop"===c?x:m),u=null===(o=p.children)||void 0===o?void 0:o.map((function(r,o){var s,p={key:{nodeIndex:o}},l=r.type;if("text"===l)return e.jsx(y,{node:r,props:p});if(0===(null===(s=r.children)||void 0===s?void 0:s.length))return e.jsx("br",{});var c=r.tag,u=r.indent,g=u?{paddingLeft:"".concat(16*u,"px")}:{},m=h(r.format),x=n.__assign({},g);if(p.classNames=m,p.style=x,"horizontalrule"===l)return e.jsx(a.Divider,n.__assign({},p));if("list"===l)return e.jsx(_,{props:p,node:r,typographyMapping:d},o);var j=null;return r.children&&(j=f({content:r,typographyConfig:d})),["heading","paragraph"].includes(l)?e.jsx(i.Typography,n.__assign({variant:d[c||l].variant,componentNode:d[c||l].componentNode},p,{children:j})):"link"===l?e.jsx(v,n.__assign({href:r.url,target:"_blank"},p,{children:e.jsx(i.Typography,n.__assign({variant:d[l].variant,componentNode:d[l].componentNode,color:"link"},p,{children:j}))})):"linebreak"===l?e.jsx("br",n.__assign({},p)):e.jsx(t.Fragment,n.__assign({},p,{children:j}))}));return e.jsxs(e.Fragment,{children:[" ",u]})},y=function(t){var r=t.node,i=t.props,o=u(r.format),a=g(r.style);return e.jsx(d.default,n.__assign({},i,{condition:!!o||!!a,wrap:function(t){return e.jsx("span",n.__assign({style:n.__assign(n.__assign({},o),a)},{children:t}))}},{children:e.jsx(e.Fragment,{children:r.text})}))},_=function(t){var r=t.node,o=t.typographyMapping,a=t.props,s="list",p=r.children.map((function(t,r){if("text"!==t.type)return e.jsx(i.Typography,n.__assign({variant:o[s].variant,componentNode:o[s].componentNode},{children:e.jsx(f,{content:t,typographyConfig:o})}),r)}));return"bullet"===r.listType?e.jsx("ul",n.__assign({className:"px-4"},a,{children:p})):e.jsx("ol",n.__assign({className:"px-4"},a,{children:p}))};exports.TextEditorRenderer=f,exports.desktopTypographyConfig=x,exports.formatAlignmentWithClasses=h,exports.formatText=u,exports.getStyleObjectFromString=g,exports.indentPaddingPx=16,exports.mobileTypographyConfig=m;
2
+ //# sourceMappingURL=ct-design-text-editor-renderer.browser.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ct-design-text-editor-renderer.browser.cjs.js","sources":["../../packages/components/TextEditorRenderer/src/utils.ts","../../packages/components/TextEditorRenderer/src/TextEditorRenderer.tsx"],"sourcesContent":[null,null],"names":["formatText","formatId","style","id","fontWeight","fontStyle","textDecoration","forEach","item","Object","assign","formatAlignmentWithClasses","format","length","getStyleObjectFromString","styleString","split","el","_a","property","value","propertyName","splitted","formattedProperty","trim","slice","map","word","toUpperCase","join","mobileTypographyConfig","h1","variant","componentNode","h2","h3","paragraph","link","list","desktopTypographyConfig","LinkTag","styled","default","a","templateObject_1","__makeTemplateObject","TextEditorRenderer","content","typographyConfig","platform","useThemeContext","typographyMapping","node","_b","children","nodeIndex","props","key","type","_jsx","RenderLeafNode","tag","indent","indentPadding","paddingLeft","classes","__assign","Divider","RenderList","childNode","includes","jsx","Typography","href","url","target","color","Fragment","_jsxs","_Fragment","formattedStyles","appliedStyles","ConditionalWrap","condition","wrap","text","listItems","elem","liIndex","listType","className"],"mappings":"8WAiBaA,EAAa,SAACC,GACzB,IAQMC,EAAQ,CAAA,EAQd,MAhBkB,CAChB,CAAEC,GAAI,EAAGD,MAAO,CAAEE,WAAY,QAC9B,CAAED,GAAI,EAAGD,MAAO,CAAEG,UAAW,WAC7B,CAAEF,GAAI,EAAGD,MAAO,CAAEI,eAAgB,iBAClC,CAAEH,GAAI,EAAGD,MAAO,CAAEI,eAAgB,cAClC,CAAEH,GAAI,GAAID,MAAO,CAAEI,eAAgB,4BAK3BC,SAAQ,SAACC,IACZP,EAAWO,EAAKL,MAAQK,EAAKL,IAChCM,OAAOC,OAAOR,EAAOM,EAAKN,MAE9B,IAEOA,CACT,EAEaS,EAA6B,SAACC,GACzC,OAAOA,aAAA,EAAAA,EAAQC,QAAS,aAAMD,GAAW,EAC3C,EAcaE,EAA2B,SAACC,QAAA,IAAAA,IAAAA,EA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emplateObject as n,__assign as t}from"tslib";import{jsx as e,jsxs as r,Fragment as o}from"react/jsx-runtime";import{Fragment as i}from"react";import a from"styled-components";import{Typography as p}from"@cleartrip/ct-design-typography";import c from"@cleartrip/ct-design-conditional-wrap";import{Divider as l}from"@cleartrip/ct-design-divider";import{useThemeContext as d}from"@cleartrip/ct-design-theme";var h,m=function(n){var t={};return[{id:1,style:{fontWeight:"700"}},{id:2,style:{fontStyle:"italic"}},{id:4,style:{textDecoration:"line-through"}},{id:8,style:{textDecoration:"underline"}},{id:12,style:{textDecoration:"line-through underline"}}].forEach((function(e){(n&e.id)===e.id&&Object.assign(t,e.style)})),t},s=function(n){return(null==n?void 0:n.length)?"ta-".concat(n):""},u=function(n){void 0===n&&(n="");var t={};return n.split(";").forEach((function(n){var e=n.split(":"),r=e[0],o=e[1];if(r){var i,a,p=(i=r.trim(),1===(a=i.split("-")).length?a[0]:a[0]+a.slice(1).map((function(n){return n[0].toUpperCase()+n.slice(1)})).join(""));t[p]=o.trim()}})),t},f={h1:{variant:"HM1",componentNode:"h1"},h2:{variant:"HM2",componentNode:"h2"},h3:{variant:"HM3",componentNode:"h3"},paragraph:{variant:"P2",componentNode:"p"},link:{variant:"L2",componentNode:"span"},list:{variant:"P2",componentNode:"li"}},v={h1:{variant:"HD3",componentNode:"h1"},h2:{variant:"HM1",componentNode:"h2"},h3:{variant:"HM2",componentNode:"h3"},paragraph:{variant:"P2",componentNode:"p"},link:{variant:"L2",componentNode:"span"},list:{variant:"P2",componentNode:"li"}},g=16,y=a.a(h||(h=n(["\n text-decoration: none;\n &:hover {\n text-decoration: underline;\n }\n"],["\n text-decoration: none;\n &:hover {\n text-decoration: underline;\n }\n"]))),N=function(n){var a,c=n.content,h=n.typographyConfig;if(!c)return null;var m=d().platform,u=h||("desktop"===m?v:f),g=null===(a=c.children)||void 0===a?void 0:a.map((function(n,r){var o,a={key:{nodeIndex:r}},c=n.type;if("text"===c)return e(x,{node:n,props:a});if(0===(null===(o=n.children)||void 0===o?void 0:o.length))return e("br",{});var d=n.tag,h=n.indent,m=h?{paddingLeft:"".concat(16*h,"px")}:{},f=s(n.format),v=t({},m);if(a.classNames=f,a.style=v,"horizontalrule"===c)return e(l,t({},a));if("list"===c)return e(k,{props:a,node:n,typographyMapping:u},r);var g=null;return n.children&&(g=N({content:n,typographyConfig:u})),["heading","paragraph"].includes(c)?e(p,t({variant:u[d||c].variant,componentNode:u[d||c].componentNode},a,{children:g})):"link"===c?e(y,t({href:n.url,target:"_blank"},a,{children:e(p,t({variant:u[c].variant,componentNode:u[c].componentNode,color:"link"},a,{children:g}))})):"linebreak"===c?e("br",t({},a)):e(i,t({},a,{children:g}))}));return r(o,{children:[" ",g]})},x=function(n){var r=n.node,i=n.props,a=m(r.format),p=u(r.style);return e(c,t({},i,{condition:!!a||!!p,wrap:function(n){return e("span",t({style:t(t({},a),p)},{children:n}))}},{children:e(o,{children:r.text})}))},k=function(n){var r=n.node,o=n.typographyMapping,i=n.props,a="list",c=r.children.map((function(n,r){if("text"!==n.type)return e(p,t({variant:o[a].variant,componentNode:o[a].componentNode},{children:e(N,{content:n,typographyConfig:o})}),r)}));return"bullet"===r.listType?e("ul",t({className:"px-4"},i,{children:c})):e("ol",t({className:"px-4"},i,{children:c}))};export{N as TextEditorRenderer,v as desktopTypographyConfig,s as formatAlignmentWithClasses,m as formatText,u as getStyleObjectFromString,g as indentPaddingPx,f as mobileTypographyConfig};
2
+ //# sourceMappingURL=ct-design-text-editor-renderer.browser.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ct-design-text-editor-renderer.browser.esm.js","sources":["../../packages/components/TextEditorRenderer/src/utils.ts","../../packages/components/TextEditorRenderer/src/TextEditorRenderer.tsx"],"sourcesContent":[null,null],"names":["formatText","formatId","style","id","fontWeight","fontStyle","textDecoration","forEach","item","Object","assign","formatAlignmentWithClasses","format","length","getStyleObjectFromString","styleString","split","el","_a","property","value","propertyName","splitted","formattedProperty","trim","slice","map","word","toUpperCase","join","mobileTypographyConfig","h1","variant","componentNode","h2","h3","paragraph","link","list","desktopTypographyConfig","indentPaddingPx","LinkTag","styled","a","templateObject_1","__makeTemplateObject","TextEditorRenderer","content","typographyConfig","platform","useThemeContext","typographyMapping","node","_b","children","nodeIndex","props","key","type","_jsx","RenderLeafNode","tag","indent","indentPadding","paddingLeft","classes","__assign","Divider","RenderList","childNode","includes","Typography","href","url","target","color","Fragment","_jsxs","_Fragment","formattedStyles","appliedStyles","ConditionalWrap","condition","wrap","text","listItems","elem","liIndex","listType","className"],"mappings":"maAiBO,MAAMA,EAAa,SAACC,GACzB,IAQMC,EAAQ,CAAA,EAQd,MAhBkB,CAChB,CAAEC,GAAI,EAAGD,MAAO,CAAEE,WAAY,QAC9B,CAAED,GAAI,EAAGD,MAAO,CAAEG,UAAW,WAC7B,CAAEF,GAAI,EAAGD,MAAO,CAAEI,eAAgB,iBAClC,CAAEH,GAAI,EAAGD,MAAO,CAAEI,eAAgB,cAClC,CAAEH,GAAI,GAAID,MAAO,CAAEI,eAAgB,4BAK3BC,SAAQ,SAACC,IACZP,EAAWO,EAAKL,MAAQK,EAAKL,IAChCM,OAAOC,OAAOR,EAAOM,EAAKN,MAE9B,IAEOA,CACT,EAEaS,EAA6B,SAACC,GACzC,OAAOA,aAAA,EAAAA,EAAQC,QAAS,aAAMD,GAAW,EAC3C,EAcaE,EAA2B,SAACC,QAAA,IAAAA,IAAAA,EAAgB,IACvD,IAAMb,EAAgC,CAAA,EAStC,OARAa,EAAYC,MAAM,KAAKT,SAAQ,SAACU,GACxB,IAAAC,EAAoBD,EAAGD,MAAM,KAA5BG,EAAQD,EAAA,GAAEE,OACjB,GAAKD,EAAL,CAEA,IAlB6BE,EACzBC,EAiBEC,GAlBuBF,EAkBqBF,EAASK,OAhBrC,KADlBF,EAAWD,EAAaL,MAAM,MACvBH,OAAqBS,EAAS,GAEzCA,EAAS,GACTA,EACGG,MAAM,GACNC,KAAI,SAACC,GAAS,OAAAA,EAAK,GAAGC,cAAgB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AMzD,MAAKgE,EAAAA,EAAA,GAAOa,GAAoBC,cAAkB1B,IAAgB,GAAA,CAAAA,SAE5FK,cAAGP,EAAKgC,SAGd,EAEMhB,EAAa,SAAClD,GAClB,IAAAkC,SACAD,EAAiBjC,EAAAiC,kBACjBK,EAAKtC,EAAAsC,MAMCE,EAAO,OACP2B,EAAYjC,EAAKE,SAAS5B,KAAI,SAAC4D,EAAMC,GACzC,GAAkB,SAAdD,EAAK5B,KACP,OACEC,EAACY,EACCL,EAAA,CAAAlC,QAASmB,EAAkBO,GAAM1B,QACjCC,cAAekB,EAAkBO,GAAMzB,eAGvC,CAAAqB,SAAAK,EAACb,EAAkB,CAACC,QAASuC,EAAMtC,iBAAkBG,MAFhDoC,EAKb,IACA,MAAyB,WAAlBnC,EAAKoC,SACV7B,EAAI,KAAAO,EAAA,CAAAuB,UAAU,QAAWjC,EAAK,CAAAF,SAC3B+B,KAGH1B,EAAI,KAAAO,EAAA,CAAAuB,UAAU,QAAWjC,EAAK,CAAAF,SAC3B+B,IAGP"}
@@ -0,0 +1,178 @@
1
+ 'use strict';
2
+
3
+ var tslib = require('tslib');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+ var react = require('react');
6
+ var styled = require('styled-components');
7
+ var ctDesignTypography = require('@cleartrip/ct-design-typography');
8
+ var ConditionalWrap = require('@cleartrip/ct-design-conditional-wrap');
9
+ var ctDesignDivider = require('@cleartrip/ct-design-divider');
10
+ var ctDesignTheme = require('@cleartrip/ct-design-theme');
11
+
12
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
13
+
14
+ var styled__default = /*#__PURE__*/_interopDefault(styled);
15
+ var ConditionalWrap__default = /*#__PURE__*/_interopDefault(ConditionalWrap);
16
+
17
+ var formatText = function (formatId) {
18
+ var formatMap = [
19
+ { id: 1, style: { fontWeight: '700' } },
20
+ { id: 2, style: { fontStyle: 'italic' } },
21
+ { id: 4, style: { textDecoration: 'line-through' } },
22
+ { id: 8, style: { textDecoration: 'underline' } },
23
+ { id: 12, style: { textDecoration: 'line-through underline' } },
24
+ ];
25
+ var style = {};
26
+ formatMap.forEach(function (item) {
27
+ if ((formatId & item.id) === item.id) {
28
+ Object.assign(style, item.style);
29
+ }
30
+ });
31
+ return style;
32
+ };
33
+ var formatAlignmentWithClasses = function (format) {
34
+ return (format === null || format === void 0 ? void 0 : format.length) ? "ta-".concat(format) : '';
35
+ };
36
+ var formatStringToCamelCase = function (propertyName) {
37
+ var splitted = propertyName.split('-');
38
+ if (splitted.length === 1)
39
+ return splitted[0];
40
+ return (splitted[0] +
41
+ splitted
42
+ .slice(1)
43
+ .map(function (word) { return word[0].toUpperCase() + word.slice(1); })
44
+ .join(''));
45
+ };
46
+ var getStyleObjectFromString = function (styleString) {
47
+ if (styleString === void 0) { styleString = ''; }
48
+ var style = {};
49
+ styleString.split(';').forEach(function (el) {
50
+ var _a = el.split(':'), property = _a[0], value = _a[1];
51
+ if (!property)
52
+ return;
53
+ var formattedProperty = formatStringToCamelCase(property.trim());
54
+ style[formattedProperty] = value.trim();
55
+ });
56
+ return style;
57
+ };
58
+ var mobileTypographyConfig = {
59
+ h1: {
60
+ variant: 'HM1',
61
+ componentNode: 'h1',
62
+ },
63
+ h2: {
64
+ variant: 'HM2',
65
+ componentNode: 'h2',
66
+ },
67
+ h3: {
68
+ variant: 'HM3',
69
+ componentNode: 'h3',
70
+ },
71
+ paragraph: {
72
+ variant: 'P2',
73
+ componentNode: 'p',
74
+ },
75
+ link: {
76
+ variant: 'L2',
77
+ componentNode: 'span',
78
+ },
79
+ list: {
80
+ variant: 'P2',
81
+ componentNode: 'li',
82
+ },
83
+ };
84
+ var desktopTypographyConfig = {
85
+ h1: {
86
+ variant: 'HD3',
87
+ componentNode: 'h1',
88
+ },
89
+ h2: {
90
+ variant: 'HM1',
91
+ componentNode: 'h2',
92
+ },
93
+ h3: {
94
+ variant: 'HM2',
95
+ componentNode: 'h3',
96
+ },
97
+ paragraph: {
98
+ variant: 'P2',
99
+ componentNode: 'p',
100
+ },
101
+ link: {
102
+ variant: 'L2',
103
+ componentNode: 'span',
104
+ },
105
+ list: {
106
+ variant: 'P2',
107
+ componentNode: 'li',
108
+ },
109
+ };
110
+ var indentPaddingPx = 16;
111
+
112
+ var LinkTag = styled__default.default.a(templateObject_1 || (templateObject_1 = tslib.__makeTemplateObject(["\n text-decoration: none;\n &:hover {\n text-decoration: underline;\n }\n"], ["\n text-decoration: none;\n &:hover {\n text-decoration: underline;\n }\n"])));
113
+ var TextEditorRenderer = function (_a) {
114
+ var _b;
115
+ var content = _a.content, typographyConfig = _a.typographyConfig;
116
+ if (!content)
117
+ return null;
118
+ var platform = ctDesignTheme.useThemeContext().platform;
119
+ var typographyMapping = typographyConfig || (platform === 'desktop' ? desktopTypographyConfig : mobileTypographyConfig);
120
+ var node = (_b = content.children) === null || _b === void 0 ? void 0 : _b.map(function (node, nodeIndex) {
121
+ var _a;
122
+ var props = { key: { nodeIndex: nodeIndex } };
123
+ var type = node.type;
124
+ if (type === 'text')
125
+ return jsxRuntime.jsx(RenderLeafNode, { node: node, props: props });
126
+ if (((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) === 0)
127
+ return jsxRuntime.jsx("br", {});
128
+ var tag = node.tag, indent = node.indent;
129
+ var indentPadding = indent ? { paddingLeft: "".concat(indentPaddingPx * indent, "px") } : {};
130
+ var classes = formatAlignmentWithClasses(node.format);
131
+ var style = tslib.__assign({}, indentPadding);
132
+ props['classNames'] = classes;
133
+ props['style'] = style;
134
+ if (type === 'horizontalrule')
135
+ return jsxRuntime.jsx(ctDesignDivider.Divider, tslib.__assign({}, props));
136
+ if (type === 'list') {
137
+ return jsxRuntime.jsx(RenderList, { props: props, node: node, typographyMapping: typographyMapping }, nodeIndex);
138
+ }
139
+ var childNode = null;
140
+ if (node.children)
141
+ childNode = TextEditorRenderer({ content: node, typographyConfig: typographyMapping });
142
+ if (['heading', 'paragraph'].includes(type)) {
143
+ return (jsxRuntime.jsx(ctDesignTypography.Typography, tslib.__assign({ variant: typographyMapping[tag || type].variant, componentNode: typographyMapping[tag || type].componentNode }, props, { children: childNode })));
144
+ }
145
+ if (type === 'link') {
146
+ return (jsxRuntime.jsx(LinkTag, tslib.__assign({ href: node.url, target: '_blank' }, props, { children: jsxRuntime.jsx(ctDesignTypography.Typography, tslib.__assign({ variant: typographyMapping[type].variant, componentNode: typographyMapping[type].componentNode, color: 'link' }, props, { children: childNode })) })));
147
+ }
148
+ if (type === 'linebreak')
149
+ return jsxRuntime.jsx("br", tslib.__assign({}, props));
150
+ return jsxRuntime.jsx(react.Fragment, tslib.__assign({}, props, { children: childNode }));
151
+ });
152
+ return jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [" ", node] });
153
+ };
154
+ var RenderLeafNode = function (_a) {
155
+ var node = _a.node, props = _a.props;
156
+ var formattedStyles = formatText(node.format);
157
+ var appliedStyles = getStyleObjectFromString(node.style);
158
+ return (jsxRuntime.jsx(ConditionalWrap__default.default, tslib.__assign({}, props, { condition: !!formattedStyles || !!appliedStyles, wrap: function (children) { return jsxRuntime.jsx("span", tslib.__assign({ style: tslib.__assign(tslib.__assign({}, formattedStyles), appliedStyles) }, { children: children })); } }, { children: jsxRuntime.jsx(jsxRuntime.Fragment, { children: node.text }) })));
159
+ };
160
+ var RenderList = function (_a) {
161
+ var node = _a.node, typographyMapping = _a.typographyMapping, props = _a.props;
162
+ var type = 'list';
163
+ var listItems = node.children.map(function (elem, liIndex) {
164
+ if (elem.type !== 'text')
165
+ return (jsxRuntime.jsx(ctDesignTypography.Typography, tslib.__assign({ variant: typographyMapping[type].variant, componentNode: typographyMapping[type].componentNode }, { children: jsxRuntime.jsx(TextEditorRenderer, { content: elem, typographyConfig: typographyMapping }) }), liIndex));
166
+ });
167
+ return node.listType === 'bullet' ? (jsxRuntime.jsx("ul", tslib.__assign({ className: 'px-4' }, props, { children: listItems }))) : (jsxRuntime.jsx("ol", tslib.__assign({ className: 'px-4' }, props, { children: listItems })));
168
+ };
169
+ var templateObject_1;
170
+
171
+ exports.TextEditorRenderer = TextEditorRenderer;
172
+ exports.desktopTypographyConfig = desktopTypographyConfig;
173
+ exports.formatAlignmentWithClasses = formatAlignmentWithClasses;
174
+ exports.formatText = formatText;
175
+ exports.getStyleObjectFromString = getStyleObjectFromString;
176
+ exports.indentPaddingPx = indentPaddingPx;
177
+ exports.mobileTypographyConfig = mobileTypographyConfig;
178
+ //# sourceMappingURL=ct-design-text-editor-renderer.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ct-design-text-editor-renderer.cjs.js","sources":["../../packages/components/TextEditorRenderer/src/utils.ts","../../packages/components/TextEditorRenderer/src/TextEditorRenderer.tsx"],"sourcesContent":[null,null],"names":["styled","__makeTemplateObject","useThemeContext","_jsx","__assign","Divider","Typography","Fragment","_jsxs","_Fragment","ConditionalWrap"],"mappings":";;;;;;;;;;;;;;;;AAiBO,IAAM,UAAU,GAAG,UAAC,QAAgB,EAAA;AACzC,IAAA,IAAM,SAAS,GAAG;QAChB,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;QACvC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE;QACzC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,cAAc,EAAE,cAAc,EAAE,EAAE;QACpD,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,EAAE;QACjD,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,cAAc,EAAE,wBAAwB,EAAE,EAAE;KAChE,CAAC;IAEF,IAAM,KAAK,GAAG,EAAE,CAAC;AAEjB,IAAA,SAAS,CAAC,OAAO,CAAC,UAAC,IAAI,EAAA;QACrB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE,MAAM,IAAI,CAAC,EAAE,EAAE;YACpC,MAAM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,SAAS,EAAC,MAAM,IAAK,KAAK,EAAA,EAAA,QAAA,EAC3B,SAAS,EAAA,CAAA,CACP,KAELD,cAAI,CAAA,IAAA,EAAAC,cAAA,CAAA,EAAA,SAAS,EAAC,MAAM,IAAK,KAAK,EAAA,EAAA,QAAA,EAC3B,SAAS,EAAA,CAAA,CACP,CACN,CAAC;AACJ,CAAC,CAAC;;;;;;;;;;;"}
@@ -0,0 +1,165 @@
1
+ import { __makeTemplateObject, __assign } from 'tslib';
2
+ import { jsx, jsxs, Fragment as Fragment$1 } from 'react/jsx-runtime';
3
+ import { Fragment } from 'react';
4
+ import styled from 'styled-components';
5
+ import { Typography } from '@cleartrip/ct-design-typography';
6
+ import ConditionalWrap from '@cleartrip/ct-design-conditional-wrap';
7
+ import { Divider } from '@cleartrip/ct-design-divider';
8
+ import { useThemeContext } from '@cleartrip/ct-design-theme';
9
+
10
+ var formatText = function (formatId) {
11
+ var formatMap = [
12
+ { id: 1, style: { fontWeight: '700' } },
13
+ { id: 2, style: { fontStyle: 'italic' } },
14
+ { id: 4, style: { textDecoration: 'line-through' } },
15
+ { id: 8, style: { textDecoration: 'underline' } },
16
+ { id: 12, style: { textDecoration: 'line-through underline' } },
17
+ ];
18
+ var style = {};
19
+ formatMap.forEach(function (item) {
20
+ if ((formatId & item.id) === item.id) {
21
+ Object.assign(style, item.style);
22
+ }
23
+ });
24
+ return style;
25
+ };
26
+ var formatAlignmentWithClasses = function (format) {
27
+ return (format === null || format === void 0 ? void 0 : format.length) ? "ta-".concat(format) : '';
28
+ };
29
+ var formatStringToCamelCase = function (propertyName) {
30
+ var splitted = propertyName.split('-');
31
+ if (splitted.length === 1)
32
+ return splitted[0];
33
+ return (splitted[0] +
34
+ splitted
35
+ .slice(1)
36
+ .map(function (word) { return word[0].toUpperCase() + word.slice(1); })
37
+ .join(''));
38
+ };
39
+ var getStyleObjectFromString = function (styleString) {
40
+ if (styleString === void 0) { styleString = ''; }
41
+ var style = {};
42
+ styleString.split(';').forEach(function (el) {
43
+ var _a = el.split(':'), property = _a[0], value = _a[1];
44
+ if (!property)
45
+ return;
46
+ var formattedProperty = formatStringToCamelCase(property.trim());
47
+ style[formattedProperty] = value.trim();
48
+ });
49
+ return style;
50
+ };
51
+ var mobileTypographyConfig = {
52
+ h1: {
53
+ variant: 'HM1',
54
+ componentNode: 'h1',
55
+ },
56
+ h2: {
57
+ variant: 'HM2',
58
+ componentNode: 'h2',
59
+ },
60
+ h3: {
61
+ variant: 'HM3',
62
+ componentNode: 'h3',
63
+ },
64
+ paragraph: {
65
+ variant: 'P2',
66
+ componentNode: 'p',
67
+ },
68
+ link: {
69
+ variant: 'L2',
70
+ componentNode: 'span',
71
+ },
72
+ list: {
73
+ variant: 'P2',
74
+ componentNode: 'li',
75
+ },
76
+ };
77
+ var desktopTypographyConfig = {
78
+ h1: {
79
+ variant: 'HD3',
80
+ componentNode: 'h1',
81
+ },
82
+ h2: {
83
+ variant: 'HM1',
84
+ componentNode: 'h2',
85
+ },
86
+ h3: {
87
+ variant: 'HM2',
88
+ componentNode: 'h3',
89
+ },
90
+ paragraph: {
91
+ variant: 'P2',
92
+ componentNode: 'p',
93
+ },
94
+ link: {
95
+ variant: 'L2',
96
+ componentNode: 'span',
97
+ },
98
+ list: {
99
+ variant: 'P2',
100
+ componentNode: 'li',
101
+ },
102
+ };
103
+ var indentPaddingPx = 16;
104
+
105
+ var LinkTag = styled.a(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n text-decoration: none;\n &:hover {\n text-decoration: underline;\n }\n"], ["\n text-decoration: none;\n &:hover {\n text-decoration: underline;\n }\n"])));
106
+ var TextEditorRenderer = function (_a) {
107
+ var _b;
108
+ var content = _a.content, typographyConfig = _a.typographyConfig;
109
+ if (!content)
110
+ return null;
111
+ var platform = useThemeContext().platform;
112
+ var typographyMapping = typographyConfig || (platform === 'desktop' ? desktopTypographyConfig : mobileTypographyConfig);
113
+ var node = (_b = content.children) === null || _b === void 0 ? void 0 : _b.map(function (node, nodeIndex) {
114
+ var _a;
115
+ var props = { key: { nodeIndex: nodeIndex } };
116
+ var type = node.type;
117
+ if (type === 'text')
118
+ return jsx(RenderLeafNode, { node: node, props: props });
119
+ if (((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) === 0)
120
+ return jsx("br", {});
121
+ var tag = node.tag, indent = node.indent;
122
+ var indentPadding = indent ? { paddingLeft: "".concat(indentPaddingPx * indent, "px") } : {};
123
+ var classes = formatAlignmentWithClasses(node.format);
124
+ var style = __assign({}, indentPadding);
125
+ props['classNames'] = classes;
126
+ props['style'] = style;
127
+ if (type === 'horizontalrule')
128
+ return jsx(Divider, __assign({}, props));
129
+ if (type === 'list') {
130
+ return jsx(RenderList, { props: props, node: node, typographyMapping: typographyMapping }, nodeIndex);
131
+ }
132
+ var childNode = null;
133
+ if (node.children)
134
+ childNode = TextEditorRenderer({ content: node, typographyConfig: typographyMapping });
135
+ if (['heading', 'paragraph'].includes(type)) {
136
+ return (jsx(Typography, __assign({ variant: typographyMapping[tag || type].variant, componentNode: typographyMapping[tag || type].componentNode }, props, { children: childNode })));
137
+ }
138
+ if (type === 'link') {
139
+ return (jsx(LinkTag, __assign({ href: node.url, target: '_blank' }, props, { children: jsx(Typography, __assign({ variant: typographyMapping[type].variant, componentNode: typographyMapping[type].componentNode, color: 'link' }, props, { children: childNode })) })));
140
+ }
141
+ if (type === 'linebreak')
142
+ return jsx("br", __assign({}, props));
143
+ return jsx(Fragment, __assign({}, props, { children: childNode }));
144
+ });
145
+ return jsxs(Fragment$1, { children: [" ", node] });
146
+ };
147
+ var RenderLeafNode = function (_a) {
148
+ var node = _a.node, props = _a.props;
149
+ var formattedStyles = formatText(node.format);
150
+ var appliedStyles = getStyleObjectFromString(node.style);
151
+ return (jsx(ConditionalWrap, __assign({}, props, { condition: !!formattedStyles || !!appliedStyles, wrap: function (children) { return jsx("span", __assign({ style: __assign(__assign({}, formattedStyles), appliedStyles) }, { children: children })); } }, { children: jsx(Fragment$1, { children: node.text }) })));
152
+ };
153
+ var RenderList = function (_a) {
154
+ var node = _a.node, typographyMapping = _a.typographyMapping, props = _a.props;
155
+ var type = 'list';
156
+ var listItems = node.children.map(function (elem, liIndex) {
157
+ if (elem.type !== 'text')
158
+ return (jsx(Typography, __assign({ variant: typographyMapping[type].variant, componentNode: typographyMapping[type].componentNode }, { children: jsx(TextEditorRenderer, { content: elem, typographyConfig: typographyMapping }) }), liIndex));
159
+ });
160
+ return node.listType === 'bullet' ? (jsx("ul", __assign({ className: 'px-4' }, props, { children: listItems }))) : (jsx("ol", __assign({ className: 'px-4' }, props, { children: listItems })));
161
+ };
162
+ var templateObject_1;
163
+
164
+ export { TextEditorRenderer, desktopTypographyConfig, formatAlignmentWithClasses, formatText, getStyleObjectFromString, indentPaddingPx, mobileTypographyConfig };
165
+ //# sourceMappingURL=ct-design-text-editor-renderer.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ct-design-text-editor-renderer.esm.js","sources":["../../packages/components/TextEditorRenderer/src/utils.ts","../../packages/components/TextEditorRenderer/src/TextEditorRenderer.tsx"],"sourcesContent":[null,null],"names":["_jsx","_jsxs","_Fragment"],"mappings":";;;;;;;;;AAiBO,IAAM,UAAU,GAAG,UAAC,QAAgB,EAAA;AACzC,IAAA,IAAM,SAAS,GAAG;QAChB,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE;QACvC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE;QACzC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,cAAc,EAAE,cAAc,EAAE,EAAE;QACpD,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,cAAc,EAAE,WAAW,EAAE,EAAE;QACjD,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,cAAc,EAAE,wBAAwB,EAAE,EAAE;KAChE,CAAC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CAAI,KAFrE,OAAO,CAGD,EACb;AACN,KAAC,CAAC,CAAC;AACH,IAAA,OAAO,IAAI,CAAC,QAAQ,KAAK,QAAQ,IAC/BA,GAAI,CAAA,IAAA,EAAA,QAAA,CAAA,EAAA,SAAS,EAAC,MAAM,IAAK,KAAK,EAAA,EAAA,QAAA,EAC3B,SAAS,EAAA,CAAA,CACP,KAELA,GAAI,CAAA,IAAA,EAAA,QAAA,CAAA,EAAA,SAAS,EAAC,MAAM,IAAK,KAAK,EAAA,EAAA,QAAA,EAC3B,SAAS,EAAA,CAAA,CACP,CACN,CAAC;AACJ,CAAC,CAAC;;;;;"}
@@ -0,0 +1,216 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react/jsx-runtime'), require('react'), require('styled-components'), require('@cleartrip/ct-design-typography'), require('@cleartrip/ct-design-conditional-wrap'), require('@cleartrip/ct-design-divider'), require('@cleartrip/ct-design-theme')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'react/jsx-runtime', 'react', 'styled-components', '@cleartrip/ct-design-typography', '@cleartrip/ct-design-conditional-wrap', '@cleartrip/ct-design-divider', '@cleartrip/ct-design-theme'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.CTDesignSystemTextEditorRenderer = {}, global.jsxRuntime, global.React, global.styled, global.ctDesignTypography, global.ConditionalWrap, global.ctDesignDivider, global.ctDesignTheme));
5
+ })(this, (function (exports, jsxRuntime, react, styled, ctDesignTypography, ConditionalWrap, ctDesignDivider, ctDesignTheme) { 'use strict';
6
+
7
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
+
9
+ var styled__default = /*#__PURE__*/_interopDefault(styled);
10
+ var ConditionalWrap__default = /*#__PURE__*/_interopDefault(ConditionalWrap);
11
+
12
+ /******************************************************************************
13
+ Copyright (c) Microsoft Corporation.
14
+
15
+ Permission to use, copy, modify, and/or distribute this software for any
16
+ purpose with or without fee is hereby granted.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
19
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
20
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
21
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
23
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
24
+ PERFORMANCE OF THIS SOFTWARE.
25
+ ***************************************************************************** */
26
+ /* global Reflect, Promise, SuppressedError, Symbol */
27
+
28
+ var __assign = function () {
29
+ __assign = Object.assign || function __assign(t) {
30
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
31
+ s = arguments[i];
32
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
33
+ }
34
+ return t;
35
+ };
36
+ return __assign.apply(this, arguments);
37
+ };
38
+ function __makeTemplateObject(cooked, raw) {
39
+ if (Object.defineProperty) {
40
+ Object.defineProperty(cooked, "raw", {
41
+ value: raw
42
+ });
43
+ } else {
44
+ cooked.raw = raw;
45
+ }
46
+ return cooked;
47
+ }
48
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
49
+ var e = new Error(message);
50
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
51
+ };
52
+
53
+ var formatText = function (formatId) {
54
+ var formatMap = [
55
+ { id: 1, style: { fontWeight: '700' } },
56
+ { id: 2, style: { fontStyle: 'italic' } },
57
+ { id: 4, style: { textDecoration: 'line-through' } },
58
+ { id: 8, style: { textDecoration: 'underline' } },
59
+ { id: 12, style: { textDecoration: 'line-through underline' } },
60
+ ];
61
+ var style = {};
62
+ formatMap.forEach(function (item) {
63
+ if ((formatId & item.id) === item.id) {
64
+ Object.assign(style, item.style);
65
+ }
66
+ });
67
+ return style;
68
+ };
69
+ var formatAlignmentWithClasses = function (format) {
70
+ return (format === null || format === void 0 ? void 0 : format.length) ? "ta-".concat(format) : '';
71
+ };
72
+ var formatStringToCamelCase = function (propertyName) {
73
+ var splitted = propertyName.split('-');
74
+ if (splitted.length === 1)
75
+ return splitted[0];
76
+ return (splitted[0] +
77
+ splitted
78
+ .slice(1)
79
+ .map(function (word) { return word[0].toUpperCase() + word.slice(1); })
80
+ .join(''));
81
+ };
82
+ var getStyleObjectFromString = function (styleString) {
83
+ if (styleString === void 0) { styleString = ''; }
84
+ var style = {};
85
+ styleString.split(';').forEach(function (el) {
86
+ var _a = el.split(':'), property = _a[0], value = _a[1];
87
+ if (!property)
88
+ return;
89
+ var formattedProperty = formatStringToCamelCase(property.trim());
90
+ style[formattedProperty] = value.trim();
91
+ });
92
+ return style;
93
+ };
94
+ var mobileTypographyConfig = {
95
+ h1: {
96
+ variant: 'HM1',
97
+ componentNode: 'h1',
98
+ },
99
+ h2: {
100
+ variant: 'HM2',
101
+ componentNode: 'h2',
102
+ },
103
+ h3: {
104
+ variant: 'HM3',
105
+ componentNode: 'h3',
106
+ },
107
+ paragraph: {
108
+ variant: 'P2',
109
+ componentNode: 'p',
110
+ },
111
+ link: {
112
+ variant: 'L2',
113
+ componentNode: 'span',
114
+ },
115
+ list: {
116
+ variant: 'P2',
117
+ componentNode: 'li',
118
+ },
119
+ };
120
+ var desktopTypographyConfig = {
121
+ h1: {
122
+ variant: 'HD3',
123
+ componentNode: 'h1',
124
+ },
125
+ h2: {
126
+ variant: 'HM1',
127
+ componentNode: 'h2',
128
+ },
129
+ h3: {
130
+ variant: 'HM2',
131
+ componentNode: 'h3',
132
+ },
133
+ paragraph: {
134
+ variant: 'P2',
135
+ componentNode: 'p',
136
+ },
137
+ link: {
138
+ variant: 'L2',
139
+ componentNode: 'span',
140
+ },
141
+ list: {
142
+ variant: 'P2',
143
+ componentNode: 'li',
144
+ },
145
+ };
146
+ var indentPaddingPx = 16;
147
+
148
+ var LinkTag = styled__default.default.a(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n text-decoration: none;\n &:hover {\n text-decoration: underline;\n }\n"], ["\n text-decoration: none;\n &:hover {\n text-decoration: underline;\n }\n"])));
149
+ var TextEditorRenderer = function (_a) {
150
+ var _b;
151
+ var content = _a.content, typographyConfig = _a.typographyConfig;
152
+ if (!content)
153
+ return null;
154
+ var platform = ctDesignTheme.useThemeContext().platform;
155
+ var typographyMapping = typographyConfig || (platform === 'desktop' ? desktopTypographyConfig : mobileTypographyConfig);
156
+ var node = (_b = content.children) === null || _b === void 0 ? void 0 : _b.map(function (node, nodeIndex) {
157
+ var _a;
158
+ var props = { key: { nodeIndex: nodeIndex } };
159
+ var type = node.type;
160
+ if (type === 'text')
161
+ return jsxRuntime.jsx(RenderLeafNode, { node: node, props: props });
162
+ if (((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) === 0)
163
+ return jsxRuntime.jsx("br", {});
164
+ var tag = node.tag, indent = node.indent;
165
+ var indentPadding = indent ? { paddingLeft: "".concat(indentPaddingPx * indent, "px") } : {};
166
+ var classes = formatAlignmentWithClasses(node.format);
167
+ var style = __assign({}, indentPadding);
168
+ props['classNames'] = classes;
169
+ props['style'] = style;
170
+ if (type === 'horizontalrule')
171
+ return jsxRuntime.jsx(ctDesignDivider.Divider, __assign({}, props));
172
+ if (type === 'list') {
173
+ return jsxRuntime.jsx(RenderList, { props: props, node: node, typographyMapping: typographyMapping }, nodeIndex);
174
+ }
175
+ var childNode = null;
176
+ if (node.children)
177
+ childNode = TextEditorRenderer({ content: node, typographyConfig: typographyMapping });
178
+ if (['heading', 'paragraph'].includes(type)) {
179
+ return (jsxRuntime.jsx(ctDesignTypography.Typography, __assign({ variant: typographyMapping[tag || type].variant, componentNode: typographyMapping[tag || type].componentNode }, props, { children: childNode })));
180
+ }
181
+ if (type === 'link') {
182
+ return (jsxRuntime.jsx(LinkTag, __assign({ href: node.url, target: '_blank' }, props, { children: jsxRuntime.jsx(ctDesignTypography.Typography, __assign({ variant: typographyMapping[type].variant, componentNode: typographyMapping[type].componentNode, color: 'link' }, props, { children: childNode })) })));
183
+ }
184
+ if (type === 'linebreak')
185
+ return jsxRuntime.jsx("br", __assign({}, props));
186
+ return jsxRuntime.jsx(react.Fragment, __assign({}, props, { children: childNode }));
187
+ });
188
+ return jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [" ", node] });
189
+ };
190
+ var RenderLeafNode = function (_a) {
191
+ var node = _a.node, props = _a.props;
192
+ var formattedStyles = formatText(node.format);
193
+ var appliedStyles = getStyleObjectFromString(node.style);
194
+ return (jsxRuntime.jsx(ConditionalWrap__default.default, __assign({}, props, { condition: !!formattedStyles || !!appliedStyles, wrap: function (children) { return jsxRuntime.jsx("span", __assign({ style: __assign(__assign({}, formattedStyles), appliedStyles) }, { children: children })); } }, { children: jsxRuntime.jsx(jsxRuntime.Fragment, { children: node.text }) })));
195
+ };
196
+ var RenderList = function (_a) {
197
+ var node = _a.node, typographyMapping = _a.typographyMapping, props = _a.props;
198
+ var type = 'list';
199
+ var listItems = node.children.map(function (elem, liIndex) {
200
+ if (elem.type !== 'text')
201
+ return (jsxRuntime.jsx(ctDesignTypography.Typography, __assign({ variant: typographyMapping[type].variant, componentNode: typographyMapping[type].componentNode }, { children: jsxRuntime.jsx(TextEditorRenderer, { content: elem, typographyConfig: typographyMapping }) }), liIndex));
202
+ });
203
+ return node.listType === 'bullet' ? (jsxRuntime.jsx("ul", __assign({ className: 'px-4' }, props, { children: listItems }))) : (jsxRuntime.jsx("ol", __assign({ className: 'px-4' }, props, { children: listItems })));
204
+ };
205
+ var templateObject_1;
206
+
207
+ exports.TextEditorRenderer = TextEditorRenderer;
208
+ exports.desktopTypographyConfig = desktopTypographyConfig;
209
+ exports.formatAlignmentWithClasses = formatAlignmentWithClasses;
210
+ exports.formatText = formatText;
211
+ exports.getStyleObjectFromString = getStyleObjectFromString;
212
+ exports.indentPaddingPx = indentPaddingPx;
213
+ exports.mobileTypographyConfig = mobileTypographyConfig;
214
+
215
+ }));
216
+ //# sourceMappingURL=ct-design-text-editor-renderer.umd.js.map