react-pdf-html-flabs-2 1.0.4 → 1.0.8
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.
- package/dist/parse.js +12 -31
- package/dist/parse.js.map +1 -1
- package/dist/renderers.js +41 -9
- package/dist/renderers.js.map +1 -1
- package/dist/styles.js +1 -0
- package/dist/styles.js.map +1 -1
- package/package.json +1 -1
package/dist/parse.js
CHANGED
|
@@ -16,12 +16,14 @@ const convertRule = (rule, source = 'style') => {
|
|
|
16
16
|
.map((entry) => (Object.assign(Object.assign({}, entry), { property: camelize(entry.property) })))
|
|
17
17
|
.reduce((style, { property, value }) => {
|
|
18
18
|
let valueString = css_tree_1.default.generate(value);
|
|
19
|
-
if (property && value) {
|
|
20
|
-
if (property
|
|
19
|
+
if (property && value !== undefined) {
|
|
20
|
+
if (property == 'fontFamily') {
|
|
21
21
|
valueString = valueString.replace(/["']+/g, '');
|
|
22
22
|
if (valueString.includes(',')) {
|
|
23
23
|
const reduced = valueString.split(',', 2)[0];
|
|
24
|
-
console.warn(
|
|
24
|
+
// console.warn(
|
|
25
|
+
// `react-pdf doesn't support fontFamily lists like "${valueString}". Reducing to "${reduced}".`
|
|
26
|
+
// );
|
|
25
27
|
}
|
|
26
28
|
return style;
|
|
27
29
|
}
|
|
@@ -33,10 +35,10 @@ const convertRule = (rule, source = 'style') => {
|
|
|
33
35
|
property = 'backgroundColor';
|
|
34
36
|
}
|
|
35
37
|
else {
|
|
36
|
-
console.warn(`${source}: Found unsupported style "${property}"`, {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
});
|
|
38
|
+
// console.warn(`${source}: Found unsupported style "${property}"`, {
|
|
39
|
+
// property,
|
|
40
|
+
// value,
|
|
41
|
+
// });
|
|
40
42
|
return style;
|
|
41
43
|
}
|
|
42
44
|
}
|
|
@@ -68,35 +70,14 @@ const convertRule = (rule, source = 'style') => {
|
|
|
68
70
|
color = part;
|
|
69
71
|
}
|
|
70
72
|
});
|
|
73
|
+
valueString = `${width} ${style} ${color}`;
|
|
71
74
|
}
|
|
72
|
-
|
|
73
|
-
const part = borderParts[0];
|
|
74
|
-
const partLower = part.toLowerCase();
|
|
75
|
-
if (widthRegex.test(partLower)) {
|
|
76
|
-
width = part;
|
|
77
|
-
}
|
|
78
|
-
else if (styleRegex.test(partLower)) {
|
|
79
|
-
if (partLower === 'none' || partLower === 'hidden') {
|
|
80
|
-
explicitNone = true;
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
style = partLower;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else if (colorRegex.test(part)) {
|
|
87
|
-
color = part;
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
console.warn(`${source}: Unrecognized border value "${valueString}"`);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
75
|
+
{
|
|
94
76
|
console.warn(`${source}: Unexpected border format "${valueString}"`);
|
|
95
77
|
}
|
|
96
78
|
if (explicitNone) {
|
|
97
79
|
return style; // ✅ do not apply this style at all
|
|
98
80
|
}
|
|
99
|
-
valueString = `${width} ${style} ${color}`;
|
|
100
81
|
}
|
|
101
82
|
else {
|
|
102
83
|
console.warn(`${source}: Invalid border value "${valueString}"`);
|
|
@@ -104,7 +85,7 @@ const convertRule = (rule, source = 'style') => {
|
|
|
104
85
|
}
|
|
105
86
|
}
|
|
106
87
|
if (property == 'border' && valueString == 'none')
|
|
107
|
-
valueString = '
|
|
88
|
+
valueString = '0px';
|
|
108
89
|
style[property] = valueString;
|
|
109
90
|
}
|
|
110
91
|
return style;
|
package/dist/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":";;;;;;AAAA,uDAM0B;AAE1B,wDAA+E;AAC/E,wEAAgD;AAEhD,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAc9B,MAAM,WAAW,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S,CAAC;SAClC,GAAG,CAAC,yBAAiB,CAAC,CAAC;IAC1B,OAAO;QACL,WAAW;QACX,WAAW,EAAE,IAAA,mBAAW,EAAC,IAAI,CAAgB;KAC9C,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC","sourcesContent":["import {\n HTMLElement,\n Node as HTMLNode,\n NodeType,\n parse,\n TextNode,\n} from 'node-html-parser';\nimport { Tag } from './tags';\nimport cssTree, { Block, Declaration, List, Rule, StyleSheet } from 'css-tree';\nimport supportedStyles from './supportedStyles';\nimport { HtmlStyle, HtmlStyles } from './styles';\nconst camelize = require('camelize');\n\nexport type HtmlContent = (HtmlElement | string)[];\n\nexport type HtmlElement = HTMLElement & {\n tag: Tag | 'string';\n parentNode: HtmlElement;\n style: HtmlStyle[];\n content: HtmlContent;\n indexOfType: number;\n querySelectorAll: (selector: string) => HtmlElement[];\n querySelector: (selector: string) => HtmlElement;\n};\n\nexport const convertRule = (\n rule: Block,\n source: string = 'style'\n): HtmlStyle => {\n const declarations = rule.children\n .filter((declaration) => declaration.type === 'Declaration')\n .toArray() as Declaration[];\n\n return declarations\n .map((entry) => ({\n ...entry,\n property: camelize(entry.property as string),\n }))\n .reduce((style, { property, value }: Declaration) => {\n let valueString = cssTree.generate(value);\n if (property && value) {\n if (property === 'fontFamily') {\n valueString = valueString.replace(/[\"']+/g, '');\n if (valueString.includes(',')) {\n const reduced = valueString.split(',', 2)[0];\n console.warn(\n `react-pdf doesn't support fontFamily lists like \"${valueString}\". Reducing to \"${reduced}\".`\n );\n }\n return style;\n } else if (!supportedStyles.includes(property)) {\n if (\n (property === 'background' &&\n /^#?[a-zA-Z0-9]+$/.test(valueString)) ||\n /^rgba?\\([0-9, ]+\\)$/i.test(valueString) ||\n /^hsla?\\([0-9.%, ]+\\)$/i.test(valueString)\n ) {\n property = 'backgroundColor';\n } else {\n console.warn(`${source}: Found unsupported style \"${property}\"`, {\n property,\n value,\n });\n return style;\n }\n }\n\n if (property.startsWith('border')) {\n if (typeof valueString === 'string' && valueString.trim() !== '') {\n const borderParts = valueString.split(' ').filter(Boolean);\n\n const widthRegex = /^\\d+(\\.\\d+)?(px|pt|em|rem|%)?$/i;\n const styleRegex =\n /^(solid|dashed|dotted|double|groove|ridge|inset|outset|none|hidden)$/i;\n const colorRegex = /^#|rgb|rgba|hsl|hsla|[a-zA-Z]+$/;\n\n let width = '1px';\n let style = 'solid';\n let color = 'black';\n\n let explicitNone = false;\n\n if (borderParts.length === 3) {\n borderParts.forEach((part) => {\n const partLower = part.toLowerCase();\n if (widthRegex.test(partLower)) {\n width = part;\n } else if (styleRegex.test(partLower)) {\n if (partLower === 'none' || partLower === 'hidden') {\n explicitNone = true;\n } else {\n style = partLower;\n }\n } else if (colorRegex.test(part)) {\n color = part;\n }\n });\n } else if (borderParts.length === 1) {\n const part = borderParts[0];\n const partLower = part.toLowerCase();\n\n if (widthRegex.test(partLower)) {\n width = part;\n } else if (styleRegex.test(partLower)) {\n if (partLower === 'none' || partLower === 'hidden') {\n explicitNone = true;\n } else {\n style = partLower;\n }\n } else if (colorRegex.test(part)) {\n color = part;\n } else {\n console.warn(\n `${source}: Unrecognized border value \"${valueString}\"`\n );\n }\n } else {\n console.warn(\n `${source}: Unexpected border format \"${valueString}\"`\n );\n }\n\n if (explicitNone) {\n return style; // ✅ do not apply this style at all\n }\n\n valueString = `${width} ${style} ${color}`;\n } else {\n console.warn(`${source}: Invalid border value \"${valueString}\"`);\n return style;\n }\n }\n\n if (property == 'border' && valueString == 'none') valueString = '0';\n style[property as keyof HtmlStyle] = valueString;\n }\n return style;\n }, {} as HtmlStyle);\n};\n\nexport const convertStylesheet = (stylesheet: string): HtmlStyles => {\n const response = {} as HtmlStyles;\n try {\n const parsed = cssTree.parse(stylesheet) as StyleSheet;\n const rules = parsed.children.filter(\n (rule) => rule.type === 'Rule' && rule.prelude?.type === 'SelectorList'\n ) as List<Rule>;\n rules.forEach((rule) => {\n const style = convertRule(rule.block);\n if (rule.prelude.type !== 'SelectorList') {\n return;\n }\n rule.prelude.children.forEach((selector) => {\n const selectorString = cssTree.generate(selector);\n response[selectorString] = style;\n });\n });\n } catch (e) {\n console.error(`Error parsing stylesheet: \"${stylesheet}\"`, e);\n }\n return response;\n};\n\nexport const convertElementStyle = (\n styleAttr: string,\n tag: string\n): HtmlStyle | undefined => {\n try {\n const parsed = cssTree.parse(`${tag} { ${styleAttr} }`) as StyleSheet;\n const rules = parsed.children.filter(\n (rule) => rule.type === 'Rule' && rule.prelude?.type === 'SelectorList'\n ) as List<Rule>;\n const firstRule = rules.first();\n return firstRule ? convertRule(firstRule.block, tag) : undefined;\n } catch (e) {\n console.error(\n `Error parsing style attribute \"${styleAttr}\" for tag: ${tag}`,\n e\n );\n }\n};\n\nexport const convertNode = (node: HTMLNode): HtmlElement | string => {\n if (node.nodeType === NodeType.TEXT_NODE) {\n return (node as TextNode).rawText;\n }\n if (node.nodeType === NodeType.COMMENT_NODE) {\n return '';\n }\n if (node.nodeType !== NodeType.ELEMENT_NODE) {\n throw new Error('Not sure what this is');\n }\n const html = node as HTMLElement;\n const content = html.childNodes.map(convertNode);\n const kindCounters: Record<string, number> = {};\n content.forEach((child) => {\n if (typeof child !== 'string') {\n child.indexOfType =\n child.tag in kindCounters\n ? (kindCounters[child.tag] = kindCounters[child.tag] + 1)\n : (kindCounters[child.tag] = 0);\n }\n });\n\n let style: HtmlStyle | undefined;\n if (html.attributes.style && html.attributes.style.trim()) {\n style = convertElementStyle(html.attributes.style, html.tagName);\n }\n\n return Object.assign(html, {\n tag: (html.tagName || '').toLowerCase() as Tag | string,\n style: style ? [style] : [],\n content,\n indexOfType: 0,\n }) as HtmlElement;\n};\n\nconst parseHtml = (\n text: string\n): { stylesheets: HtmlStyles[]; rootElement: HtmlElement } => {\n const html = parse(text, { comment: false });\n const stylesheets = html\n .querySelectorAll('style')\n .map((styleNode) =>\n styleNode.childNodes.map((textNode) => textNode.rawText.trim()).join('\\n')\n )\n .filter((styleText) => !!styleText)\n .map(convertStylesheet);\n return {\n stylesheets,\n rootElement: convertNode(html) as HtmlElement,\n };\n};\n\nexport default parseHtml;\n"]}
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../src/parse.ts"],"names":[],"mappings":";;;;;;AAAA,uDAM0B;AAE1B,wDAA+E;AAC/E,wEAAgD;AAEhD,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAc9B,MAAM,WAAW,GAAG,CACzB,IAAW,EACX,SAAiB,OAAO,EACb,EAAE;IACb,MAAM,YAAY,GAAG,IAAI,CAAC,QAAQ;SAC/B,MAAM,CAAC,CAAC,WAAW,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,KAAK,aAAa,CAAC;SAC3D,OAAO,EAAmB,CAAC;IAE9B,OAAO,YAAY;SAChB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,iCACX,KAAK,KACR,QAAQ,EAAE,QAAQ,CAAC,KAAK,CAAC,QAAkB,CAAC,IAC5C,CAAC;SACF,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAe,EAAE,EAAE;QAClD,IAAI,WAAW,GAAG,kBAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAC1C,IAAI,QAAQ,IAAI,KAAK,KAAK,SAAS,EAAE;YACnC,IAAI,QAAQ,IAAI,YAAY,EAAE;gBAC5B,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBAChD,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;oBAC7B,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC7C,gBAAgB;oBAChB,kGAAkG;oBAClG,KAAK;iBACN;gBACD,OAAO,KAAK,CAAC;aACd;iBAAM,IAAI,CAAC,yBAAe,CAAC,QAAQ,CAAC,QAAQ,CA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,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE;QACzB,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,WAAW,EAAkB;QACvD,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;QAC3B,OAAO;QACP,WAAW,EAAE,CAAC;KACf,CAAgB,CAAC;AACpB,CAAC,CAAC;AAjCW,QAAA,WAAW,eAiCtB;AAEF,MAAM,SAAS,GAAG,CAChB,IAAY,EAC6C,EAAE;IAC3D,MAAM,IAAI,GAAG,IAAA,wBAAK,EAAC,IAAI,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7C,MAAM,WAAW,GAAG,IAAI;SACrB,gBAAgB,CAAC,OAAO,CAAC;SACzB,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CACjB,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAC3E;SACA,MAAM,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;SAClC,GAAG,CAAC,yBAAiB,CAAC,CAAC;IAC1B,OAAO;QACL,WAAW;QACX,WAAW,EAAE,IAAA,mBAAW,EAAC,IAAI,CAAgB;KAC9C,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,SAAS,CAAC","sourcesContent":["import {\n HTMLElement,\n Node as HTMLNode,\n NodeType,\n parse,\n TextNode,\n} from 'node-html-parser';\nimport { Tag } from './tags';\nimport cssTree, { Block, Declaration, List, Rule, StyleSheet } from 'css-tree';\nimport supportedStyles from './supportedStyles';\nimport { HtmlStyle, HtmlStyles } from './styles';\nconst camelize = require('camelize');\n\nexport type HtmlContent = (HtmlElement | string)[];\n\nexport type HtmlElement = HTMLElement & {\n tag: Tag | 'string';\n parentNode: HtmlElement;\n style: HtmlStyle[];\n content: HtmlContent;\n indexOfType: number;\n querySelectorAll: (selector: string) => HtmlElement[];\n querySelector: (selector: string) => HtmlElement;\n};\n\nexport const convertRule = (\n rule: Block,\n source: string = 'style'\n): HtmlStyle => {\n const declarations = rule.children\n .filter((declaration) => declaration.type === 'Declaration')\n .toArray() as Declaration[];\n\n return declarations\n .map((entry) => ({\n ...entry,\n property: camelize(entry.property as string),\n }))\n .reduce((style, { property, value }: Declaration) => {\n let valueString = cssTree.generate(value);\n if (property && value !== undefined) {\n if (property == 'fontFamily') {\n valueString = valueString.replace(/[\"']+/g, '');\n if (valueString.includes(',')) {\n const reduced = valueString.split(',', 2)[0];\n // console.warn(\n // `react-pdf doesn't support fontFamily lists like \"${valueString}\". Reducing to \"${reduced}\".`\n // );\n }\n return style;\n } else if (!supportedStyles.includes(property)) {\n if (\n (property === 'background' &&\n /^#?[a-zA-Z0-9]+$/.test(valueString)) ||\n /^rgba?\\([0-9, ]+\\)$/i.test(valueString) ||\n /^hsla?\\([0-9.%, ]+\\)$/i.test(valueString)\n ) {\n property = 'backgroundColor';\n } else {\n // console.warn(`${source}: Found unsupported style \"${property}\"`, {\n // property,\n // value,\n // });\n return style;\n }\n }\n if (property.startsWith('border')) {\n if (typeof valueString === 'string' && valueString.trim() !== '') {\n const borderParts = valueString.split(' ').filter(Boolean);\n const widthRegex = /^\\d+(\\.\\d+)?(px|pt|em|rem|%)?$/i;\n const styleRegex =\n /^(solid|dashed|dotted|double|groove|ridge|inset|outset|none|hidden)$/i;\n const colorRegex = /^#|rgb|rgba|hsl|hsla|[a-zA-Z]+$/;\n\n let width = '1px';\n let style = 'solid';\n let color = 'black';\n\n let explicitNone = false;\n\n if (borderParts.length === 3) {\n borderParts.forEach((part) => {\n const partLower = part.toLowerCase();\n if (widthRegex.test(partLower)) {\n width = part;\n } else if (styleRegex.test(partLower)) {\n if (partLower === 'none' || partLower === 'hidden') {\n explicitNone = true;\n } else {\n style = partLower;\n }\n } else if (colorRegex.test(part)) {\n color = part;\n }\n });\n valueString = `${width} ${style} ${color}`;\n }\n {\n console.warn(\n `${source}: Unexpected border format \"${valueString}\"`\n );\n }\n\n if (explicitNone) {\n return style; // ✅ do not apply this style at all\n }\n } else {\n console.warn(`${source}: Invalid border value \"${valueString}\"`);\n return style;\n }\n }\n\n if (property == 'border' && valueString == 'none') valueString = '0px';\n style[property as keyof HtmlStyle] = valueString;\n }\n return style;\n }, {} as HtmlStyle);\n};\n\nexport const convertStylesheet = (stylesheet: string): HtmlStyles => {\n const response = {} as HtmlStyles;\n try {\n const parsed = cssTree.parse(stylesheet) as StyleSheet;\n const rules = parsed.children.filter(\n (rule) => rule.type === 'Rule' && rule.prelude?.type === 'SelectorList'\n ) as List<Rule>;\n rules.forEach((rule) => {\n const style = convertRule(rule.block);\n if (rule.prelude.type !== 'SelectorList') {\n return;\n }\n rule.prelude.children.forEach((selector) => {\n const selectorString = cssTree.generate(selector);\n response[selectorString] = style;\n });\n });\n } catch (e) {\n console.error(`Error parsing stylesheet: \"${stylesheet}\"`, e);\n }\n return response;\n};\n\nexport const convertElementStyle = (\n styleAttr: string,\n tag: string\n): HtmlStyle | undefined => {\n try {\n const parsed = cssTree.parse(`${tag} { ${styleAttr} }`) as StyleSheet;\n const rules = parsed.children.filter(\n (rule) => rule.type === 'Rule' && rule.prelude?.type === 'SelectorList'\n ) as List<Rule>;\n const firstRule = rules.first();\n return firstRule ? convertRule(firstRule.block, tag) : undefined;\n } catch (e) {\n console.error(\n `Error parsing style attribute \"${styleAttr}\" for tag: ${tag}`,\n e\n );\n }\n};\n\nexport const convertNode = (node: HTMLNode): HtmlElement | string => {\n if (node.nodeType === NodeType.TEXT_NODE) {\n return (node as TextNode).rawText;\n }\n if (node.nodeType === NodeType.COMMENT_NODE) {\n return '';\n }\n if (node.nodeType !== NodeType.ELEMENT_NODE) {\n throw new Error('Not sure what this is');\n }\n const html = node as HTMLElement;\n const content = html.childNodes.map(convertNode);\n const kindCounters: Record<string, number> = {};\n content.forEach((child) => {\n if (typeof child !== 'string') {\n child.indexOfType =\n child.tag in kindCounters\n ? (kindCounters[child.tag] = kindCounters[child.tag] + 1)\n : (kindCounters[child.tag] = 0);\n }\n });\n\n let style: HtmlStyle | undefined;\n if (html.attributes.style && html.attributes.style.trim()) {\n style = convertElementStyle(html.attributes.style, html.tagName);\n }\n\n return Object.assign(html, {\n tag: (html.tagName || '').toLowerCase() as Tag | string,\n style: style ? [style] : [],\n content,\n indexOfType: 0,\n }) as HtmlElement;\n};\n\nconst parseHtml = (\n text: string\n): { stylesheets: HtmlStyles[]; rootElement: HtmlElement } => {\n const html = parse(text, { comment: false });\n const stylesheets = html\n .querySelectorAll('style')\n .map((styleNode) =>\n styleNode.childNodes.map((textNode) => textNode.rawText.trim()).join('\\n')\n )\n .filter((styleText) => !!styleText)\n .map(convertStylesheet);\n return {\n stylesheets,\n rootElement: convertNode(html) as HtmlElement,\n };\n};\n\nexport default parseHtml;\n"]}
|
package/dist/renderers.js
CHANGED
|
@@ -17,9 +17,11 @@ const renderInline = ({ style, children }) => (react_1.default.createElement(ren
|
|
|
17
17
|
exports.renderInline = renderInline;
|
|
18
18
|
const renderCell = ({ style, element, children }) => {
|
|
19
19
|
const table = element.closest('table');
|
|
20
|
+
const tableAttributes = table === null || table === void 0 ? void 0 : table.attributes;
|
|
20
21
|
if (!table) {
|
|
21
22
|
throw new Error('td element rendered outside of a table');
|
|
22
23
|
}
|
|
24
|
+
const combinedStyle = style.reduce((acc, current) => Object.assign(acc, current), {});
|
|
23
25
|
const tableStyles = table.style.reduce((combined, tableStyle) => Object.assign(combined, tableStyle), {});
|
|
24
26
|
const baseStyles = {
|
|
25
27
|
border: tableStyles.border,
|
|
@@ -29,7 +31,7 @@ const renderCell = ({ style, element, children }) => {
|
|
|
29
31
|
};
|
|
30
32
|
if (tableStyles.borderSpacing &&
|
|
31
33
|
tableStyles.borderCollapse !== 'collapse') {
|
|
32
|
-
baseStyles.
|
|
34
|
+
baseStyles.borderWidth = tableStyles.borderWidth;
|
|
33
35
|
baseStyles.margin = tableStyles.borderSpacing;
|
|
34
36
|
}
|
|
35
37
|
else {
|
|
@@ -40,14 +42,26 @@ const renderCell = ({ style, element, children }) => {
|
|
|
40
42
|
baseStyles.borderTopWidth = tableStyles.borderWidth;
|
|
41
43
|
}
|
|
42
44
|
}
|
|
45
|
+
if ((tableAttributes === null || tableAttributes === void 0 ? void 0 : tableAttributes.border) == 0) {
|
|
46
|
+
baseStyles.borderRightWidth = '0px';
|
|
47
|
+
baseStyles.borderBottomWidth = '0px';
|
|
48
|
+
baseStyles.borderTopWidth = '0px';
|
|
49
|
+
baseStyles.borderLeftWidth = '0px';
|
|
50
|
+
}
|
|
43
51
|
const overrides = {};
|
|
44
|
-
if (element.attributes && element.attributes.colspan) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
// if (element.attributes && element.attributes.colspan) {
|
|
53
|
+
// const colspan = parseInt(element.attributes.colspan, 10);
|
|
54
|
+
// if (!isNaN(colspan)) {
|
|
55
|
+
// overrides.flexBasis = colspan;
|
|
56
|
+
// }
|
|
57
|
+
// }
|
|
58
|
+
if (combinedStyle.textAlign == 'center') {
|
|
59
|
+
overrides.alignItems = 'center';
|
|
60
|
+
}
|
|
61
|
+
if (combinedStyle.verticalAlign == 'center') {
|
|
62
|
+
overrides.justifyContent = 'center';
|
|
49
63
|
}
|
|
50
|
-
const finalStyles = Object.assign({}, baseStyles,
|
|
64
|
+
const finalStyles = Object.assign({}, baseStyles, combinedStyle, overrides);
|
|
51
65
|
if (!finalStyles.width)
|
|
52
66
|
finalStyles.flex = 1;
|
|
53
67
|
delete finalStyles.height;
|
|
@@ -117,16 +131,34 @@ const renderers = {
|
|
|
117
131
|
dimensions.height = height;
|
|
118
132
|
}
|
|
119
133
|
const finalStyles = Object.assign({}, ...style, dimensions);
|
|
120
|
-
return react_1.default.createElement(renderer_1.Image, { style: finalStyles,
|
|
134
|
+
return (react_1.default.createElement(renderer_1.Image, { style: finalStyles, source: {
|
|
135
|
+
uri: element.attributes.src,
|
|
136
|
+
body: null,
|
|
137
|
+
method: 'GET',
|
|
138
|
+
headers: {
|
|
139
|
+
'Cache-Control': 'no-cache',
|
|
140
|
+
'Access-Control-Allow-Origin': '*',
|
|
141
|
+
},
|
|
142
|
+
} }));
|
|
121
143
|
},
|
|
122
144
|
table: ({ element, style, children }) => {
|
|
145
|
+
var _a;
|
|
123
146
|
const tableStyles = element.style.reduce((combined, tableStyle) => Object.assign(combined, tableStyle), {});
|
|
147
|
+
const { border } = element.attributes;
|
|
124
148
|
const overrides = {};
|
|
125
149
|
if (!tableStyles.borderSpacing ||
|
|
126
150
|
tableStyles.borderCollapse === 'collapse') {
|
|
127
151
|
overrides.borderLeftWidth = 0;
|
|
128
152
|
overrides.borderTopWidth = 0;
|
|
129
153
|
}
|
|
154
|
+
if (border == 0) {
|
|
155
|
+
overrides.borderWidth = '0px';
|
|
156
|
+
overrides.borderStyle = 'none';
|
|
157
|
+
}
|
|
158
|
+
const borderColor = (_a = style.find((s) => s.borderColor && s.borderColor !== 'gray')) === null || _a === void 0 ? void 0 : _a.borderColor;
|
|
159
|
+
if (borderColor) {
|
|
160
|
+
overrides.borderColor = borderColor;
|
|
161
|
+
}
|
|
130
162
|
const finalStyles = Object.assign({}, ...style, overrides);
|
|
131
163
|
delete finalStyles.height;
|
|
132
164
|
return react_1.default.createElement(renderer_1.View, { style: finalStyles }, children);
|
|
@@ -136,7 +168,7 @@ const renderers = {
|
|
|
136
168
|
delete finalStyles.height;
|
|
137
169
|
return (react_1.default.createElement(renderer_1.View, { wrap: true, style: finalStyles }, children));
|
|
138
170
|
},
|
|
139
|
-
br: ({ style }) => (react_1.default.createElement(renderer_1.Text, { wrap:
|
|
171
|
+
br: ({ style }) => (react_1.default.createElement(renderer_1.Text, { wrap: true, style: style }, '\n')),
|
|
140
172
|
td: exports.renderCell,
|
|
141
173
|
th: exports.renderCell,
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,EAAE,WAAW,IAAG,QAAQ,CAAQ,CAAC;IACrD,CAAC;IACD,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,EAAE;QAC1B,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,GAAG,KAAK,CAAC,CAAC;QAChD,OAAO,WAAW,CAAC,MAAM,CAAC;QAC1B,OAAO,CACL,8BAAC,eAAI,IAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,IACjC,QAAQ,CACJ,CACR,CAAC;IACJ,CAAC;IACD,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CACjB,8BAAC,eAAI,IAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,IAC5B,IAAI,CACA,CACR;IACD,EAAE,EAAE,kBAAU;IACd,EAAE,EAAE,kBAAU;CACf,CAAC;AAEF,kBAAe,SAAS,CAAC","sourcesContent":["import React from 'react';\nimport { Link, Text, View, Image } from '@react-pdf/renderer';\nimport { HtmlRenderer, HtmlRenderers } from './render';\nimport { HtmlElement } from './parse';\nimport { HtmlStyle } from './styles';\nimport { lowerAlpha, orderedAlpha, upperAlpha } from './ordered.type';\n\nexport const renderNoop: HtmlRenderer = ({ children }) => <></>;\n\nexport const renderPassThrough: React.FC<React.PropsWithChildren<any>> = ({\n children,\n}) => children;\n\nexport const renderBlock: HtmlRenderer = ({ style, children }) => (\n <View style={style}>{children}</View>\n);\n\nexport const renderInline: HtmlRenderer = ({ style, children }) => (\n <Text style={style}>{children}</Text>\n);\n\nexport const renderCell: HtmlRenderer = ({ style, element, children }) => {\n const table = element.closest('table') as HtmlElement | undefined;\n if (!table) {\n throw new Error('td element rendered outside of a table');\n }\n const tableStyles = table.style.reduce(\n (combined, tableStyle) => Object.assign(combined, tableStyle),\n {} as HtmlStyle\n );\n\n const baseStyles: HtmlStyle = {\n border: tableStyles.border,\n borderColor: tableStyles.borderColor,\n borderWidth: tableStyles.borderWidth,\n borderStyle: tableStyles.borderStyle,\n };\n if (\n (tableStyles as any).borderSpacing &&\n (tableStyles as any).borderCollapse !== 'collapse'\n ) {\n baseStyles.width = tableStyles.borderWidth;\n baseStyles.margin = (tableStyles as any).borderSpacing;\n } else {\n baseStyles.borderRightWidth = 0;\n baseStyles.borderBottomWidth = 0;\n if (element.indexOfType !== 0) {\n baseStyles.borderLeftWidth = tableStyles.borderWidth;\n baseStyles.borderTopWidth = tableStyles.borderWidth;\n }\n }\n\n const overrides: HtmlStyle = {};\n if (element.attributes && element.attributes.colspan) {\n const colspan = parseInt(element.attributes.colspan, 10);\n if (!isNaN(colspan)) {\n overrides.flexBasis = colspan;\n }\n }\n\n const finalStyles = Object.assign({}, baseStyles, ...style, overrides);\n if (!finalStyles.width) finalStyles.flex = 1;\n delete finalStyles.height;\n return <View style={finalStyles}>{children}</View>;\n};\n\nconst renderers: HtmlRenderers = {\n style: renderNoop,\n script: renderNoop,\n html: renderPassThrough,\n li: ({ element, stylesheets, style, children }) => {\n const bulletStyles = stylesheets.map((stylesheet) => stylesheet.li_bullet);\n const contentStyles = stylesheets.map(\n (stylesheet) => stylesheet.li_content\n );\n const list: HtmlElement = element.closest('ol, ul') as HtmlElement;\n const ordered = list?.tag === 'ol' || element.parentNode.tag === 'ol';\n const listStyle =\n list?.style?.reduce(\n (combined, listStyle) => Object.assign(combined, listStyle),\n {} as HtmlStyle\n ) || {};\n const itemStyle = element.style.reduce(\n (combined, itemStyle) => Object.assign(combined, itemStyle),\n {} as HtmlStyle\n );\n const listStyleType =\n itemStyle.listStyleType ||\n itemStyle.listStyle ||\n listStyle.listStyleType ||\n listStyle.listStyle ||\n '';\n\n let bullet;\n if (listStyleType.includes('none')) {\n bullet = false;\n } else if (listStyleType.includes('url(')) {\n bullet = (\n <Image\n src={listStyleType.match(/\\((.*?)\\)/)[1].replace(/(['\"])/g, '')}\n />\n );\n } else if (ordered) {\n if (lowerAlpha.includes(listStyleType)) {\n bullet = (\n <Text>{orderedAlpha[element.indexOfType].toLowerCase()}.</Text>\n );\n } else if (upperAlpha.includes(listStyleType)) {\n bullet = (\n <Text>{orderedAlpha[element.indexOfType].toUpperCase()}.</Text>\n );\n } else {\n bullet = <Text>{element.indexOfType + 1}.</Text>;\n }\n } else {\n // if (listStyleType.includes('square')) {\n // bullet = <Text>■</Text>;\n // } else {\n bullet = <Text>•</Text>;\n // }\n }\n\n return (\n <View style={style}>\n {bullet && <View style={bulletStyles}>{bullet}</View>}\n <View style={contentStyles}>{children}</View>\n </View>\n );\n },\n a: ({ style, element, children }) => (\n <Link style={style} src={element.attributes.href}>\n {children}\n </Link>\n ),\n img: ({ style, element }) => {\n const { width, height } = element.attributes;\n const dimensions: any = {};\n if (width) {\n dimensions.width = width;\n }\n if (height) {\n dimensions.height = height;\n }\n const finalStyles = Object.assign({}, ...style, dimensions);\n return <Image style={finalStyles} src={element.attributes.src} />;\n },\n table: ({ element, style, children }) => {\n const tableStyles = element.style.reduce(\n (combined, tableStyle) => Object.assign(combined, tableStyle),\n {} as HtmlStyle\n );\n const overrides: HtmlStyle = {};\n if (\n !(tableStyles as any).borderSpacing ||\n (tableStyles as any).borderCollapse === 'collapse'\n ) {\n overrides.borderLeftWidth = 0;\n overrides.borderTopWidth = 0;\n }\n const finalStyles = Object.assign({}, ...style, overrides);\n delete finalStyles.height;\n return <View style={finalStyles}>{children}</View>;\n },\n tr: ({ style, children }) => {\n const finalStyles = Object.assign({}, ...style);\n delete finalStyles.height;\n return (\n <View wrap={true} style={finalStyles}>\n {children}\n </View>\n );\n },\n br: ({ style }) => (\n <Text wrap={false} style={style}>\n {'\\n'}\n </Text>\n ),\n td: renderCell,\n th: renderCell,\n};\n\nexport default renderers;\n"]}
|
|
1
|
+
{"version":3,"file":"renderers.js","sourceRoot":"","sources":["../src/renderers.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,kDAA8D;AAI9D,iDAAsE;AAE/D,MAAM,UAAU,GAAiB,CAAC,E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,EAAE,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CACjB,8BAAC,eAAI,IAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,IAC3B,IAAI,CACA,CACR;IACD,EAAE,EAAE,kBAAU;IACd,EAAE,EAAE,kBAAU;CACf,CAAC;AAEF,kBAAe,SAAS,CAAC","sourcesContent":["import React from 'react';\nimport { Link, Text, View, Image } from '@react-pdf/renderer';\nimport { HtmlRenderer, HtmlRenderers } from './render';\nimport { HtmlElement } from './parse';\nimport { HtmlStyle } from './styles';\nimport { lowerAlpha, orderedAlpha, upperAlpha } from './ordered.type';\n\nexport const renderNoop: HtmlRenderer = ({ children }) => <></>;\n\nexport const renderPassThrough: React.FC<React.PropsWithChildren<any>> = ({\n children,\n}) => children;\n\nexport const renderBlock: HtmlRenderer = ({ style, children }) => (\n <View style={style}>{children}</View>\n);\n\nexport const renderInline: HtmlRenderer = ({ style, children }) => (\n <Text style={style}>{children}</Text>\n);\n\nexport const renderCell: HtmlRenderer = ({ style, element, children }) => {\n const table = element.closest('table') as HtmlElement | undefined;\n const tableAttributes = table?.attributes as any;\n if (!table) {\n throw new Error('td element rendered outside of a table');\n }\n const combinedStyle = style.reduce(\n (acc, current) => Object.assign(acc, current),\n {} as HtmlStyle\n );\n const tableStyles = table.style.reduce(\n (combined, tableStyle) => Object.assign(combined, tableStyle),\n {} as HtmlStyle\n );\n\n const baseStyles: HtmlStyle = {\n border: tableStyles.border,\n borderColor: tableStyles.borderColor,\n borderWidth: tableStyles.borderWidth,\n borderStyle: tableStyles.borderStyle,\n };\n if (\n (tableStyles as any).borderSpacing &&\n (tableStyles as any).borderCollapse !== 'collapse'\n ) {\n baseStyles.borderWidth = tableStyles.borderWidth;\n baseStyles.margin = (tableStyles as any).borderSpacing;\n } else {\n baseStyles.borderRightWidth = 0;\n baseStyles.borderBottomWidth = 0;\n if (element.indexOfType !== 0) {\n baseStyles.borderLeftWidth = tableStyles.borderWidth;\n baseStyles.borderTopWidth = tableStyles.borderWidth;\n }\n }\n\n if (tableAttributes?.border == 0) {\n baseStyles.borderRightWidth = '0px';\n baseStyles.borderBottomWidth = '0px';\n baseStyles.borderTopWidth = '0px';\n baseStyles.borderLeftWidth = '0px';\n }\n const overrides: HtmlStyle = {};\n // if (element.attributes && element.attributes.colspan) {\n // const colspan = parseInt(element.attributes.colspan, 10);\n // if (!isNaN(colspan)) {\n // overrides.flexBasis = colspan;\n // }\n // }\n if (combinedStyle.textAlign == 'center') {\n overrides.alignItems = 'center';\n }\n\n if (combinedStyle.verticalAlign == 'center') {\n overrides.justifyContent = 'center';\n }\n\n const finalStyles = Object.assign({}, baseStyles, combinedStyle, overrides);\n if (!finalStyles.width) finalStyles.flex = 1;\n delete finalStyles.height;\n\n return <View style={finalStyles}>{children}</View>;\n};\n\nconst renderers: HtmlRenderers = {\n style: renderNoop,\n script: renderNoop,\n html: renderPassThrough,\n li: ({ element, stylesheets, style, children }) => {\n const bulletStyles = stylesheets.map((stylesheet) => stylesheet.li_bullet);\n const contentStyles = stylesheets.map(\n (stylesheet) => stylesheet.li_content\n );\n const list: HtmlElement = element.closest('ol, ul') as HtmlElement;\n const ordered = list?.tag === 'ol' || element.parentNode.tag === 'ol';\n const listStyle =\n list?.style?.reduce(\n (combined, listStyle) => Object.assign(combined, listStyle),\n {} as HtmlStyle\n ) || {};\n const itemStyle = element.style.reduce(\n (combined, itemStyle) => Object.assign(combined, itemStyle),\n {} as HtmlStyle\n );\n const listStyleType =\n itemStyle.listStyleType ||\n itemStyle.listStyle ||\n listStyle.listStyleType ||\n listStyle.listStyle ||\n '';\n\n let bullet;\n if (listStyleType.includes('none')) {\n bullet = false;\n } else if (listStyleType.includes('url(')) {\n bullet = (\n <Image\n src={listStyleType.match(/\\((.*?)\\)/)[1].replace(/(['\"])/g, '')}\n />\n );\n } else if (ordered) {\n if (lowerAlpha.includes(listStyleType)) {\n bullet = (\n <Text>{orderedAlpha[element.indexOfType].toLowerCase()}.</Text>\n );\n } else if (upperAlpha.includes(listStyleType)) {\n bullet = (\n <Text>{orderedAlpha[element.indexOfType].toUpperCase()}.</Text>\n );\n } else {\n bullet = <Text>{element.indexOfType + 1}.</Text>;\n }\n } else {\n // if (listStyleType.includes('square')) {\n // bullet = <Text>■</Text>;\n // } else {\n bullet = <Text>•</Text>;\n // }\n }\n return (\n <View style={style}>\n {bullet && <View style={bulletStyles}>{bullet}</View>}\n <View style={contentStyles}>{children}</View>\n </View>\n );\n },\n a: ({ style, element, children }) => (\n <Link style={style} src={element.attributes.href}>\n {children}\n </Link>\n ),\n img: ({ style, element }) => {\n const { width, height } = element.attributes;\n const dimensions: any = {};\n if (width) {\n dimensions.width = width;\n }\n if (height) {\n dimensions.height = height;\n }\n const finalStyles = Object.assign({}, ...style, dimensions);\n return (\n <Image\n style={finalStyles}\n source={{\n uri: element.attributes.src,\n body: null,\n method: 'GET',\n headers: {\n 'Cache-Control': 'no-cache',\n 'Access-Control-Allow-Origin': '*',\n },\n }}\n />\n );\n },\n table: ({ element, style, children }) => {\n const tableStyles = element.style.reduce(\n (combined, tableStyle) => Object.assign(combined, tableStyle),\n {} as HtmlStyle\n );\n const { border } = element.attributes as any;\n const overrides: HtmlStyle = {};\n if (\n !(tableStyles as any).borderSpacing ||\n (tableStyles as any).borderCollapse === 'collapse'\n ) {\n overrides.borderLeftWidth = 0;\n overrides.borderTopWidth = 0;\n }\n\n if (border == 0) {\n overrides.borderWidth = '0px';\n overrides.borderStyle = 'none';\n }\n const borderColor = style.find(\n (s) => s.borderColor && s.borderColor !== 'gray'\n )?.borderColor;\n if (borderColor) {\n overrides.borderColor = borderColor;\n }\n const finalStyles = Object.assign({}, ...style, overrides);\n delete finalStyles.height;\n return <View style={finalStyles}>{children}</View>;\n },\n tr: ({ style, children }) => {\n const finalStyles = Object.assign({}, ...style);\n delete finalStyles.height;\n return (\n <View wrap={true} style={finalStyles}>\n {children}\n </View>\n );\n },\n br: ({ style }) => (\n <Text wrap={true} style={style}>\n {'\\n'}\n </Text>\n ),\n td: renderCell,\n th: renderCell,\n};\n\nexport default renderers;\n"]}
|
package/dist/styles.js
CHANGED
package/dist/styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","sourceRoot":"","sources":["../src/styles.ts"],"names":[],"mappings":";;;AAAA,kDAAiD;AAe1C,MAAM,oBAAoB,GAAG,CAClC,QAAgB,EAChB,QAAiB,KAAK,EACV,EAAE;IACd,MAAM,EAAE,GAAG,CAAC,EAAU,EAAE,eAAuB,QAAQ,EAAE,EAAE,CAAC,EAAE,GAAG,YAAY,CAAC;IAE9E,IAAI,IAAI,GAAe;QACrB,IAAI,EAAE;YACJ,MAAM,EAAE,CAAC;YACT,UAAU,EAAE,aAAa;SAC1B;QACD,EAAE,EAAE;YACF,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;YACf,cAAc,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;YAC/B,UAAU,EAAE,MAAM;SACnB;QACD,EAAE,EAAE;YACF,QAAQ,EAAE,EAAE,CAAC,GAAG,CAAC;YACjB,cAAc,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;YACjC,UAAU,EAAE,MAAM;SACnB;QACD,EAAE,EAAE;YACF,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC;YAClB,cAAc,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC;YAC/B,UAAU,EAAE,MAAM;SACnB;QACD,EAAE,EAAE;YACF,QAAQ,EAAE,EAAE,CAAC,CAAC,CAAC;YACf,cAAc,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;YAC/B,UAAU,EAAE,MAAM;SACnB;QACD,EAAE,EAAE;YACF,QAAQ,EAAE,EAAE,CAAC,IAAI,CAAC;YAClB,cAAc,EAAE,EAAE,CAAC,IAAI,EAAE,E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,SAAS,CAAC,OAAO,GAAG,MAAM,CAAC;QAChC,IAAI,CAAC,KAAK,CAAC,cAAc,GAAG,UAAU,CAAC;QACvC,IAAI,CAAC,KAAK,CAAC,aAAa,GAAG,CAAC,CAAC;KAC9B;IAED,OAAO,qBAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC,CAAC;AAvKW,QAAA,oBAAoB,wBAuK/B","sourcesContent":["import { StyleSheet } from '@react-pdf/renderer';\nimport { Style } from '@react-pdf/types';\nimport { Tag } from './tags';\n\nexport type HtmlStyle =\n | (Style & {\n listStyle?: string;\n listStyleType?: string;\n borderSpacing?: number | string;\n borderCollapse?: string;\n })\n | any;\n\nexport type HtmlStyles = Record<Tag | string, HtmlStyle>;\n\nexport const createHtmlStylesheet = <T extends HtmlStyles>(\n fontSize: number,\n reset: boolean = false\n): HtmlStyles => {\n const em = (em: number, relativeSize: number = fontSize) => em * relativeSize;\n\n let base: HtmlStyles = {\n body: {\n margin: 8,\n fontFamily: 'Times-Roman',\n },\n h1: {\n fontSize: em(2),\n marginVertical: em(0.67, em(2)),\n fontWeight: 'bold',\n },\n h2: {\n fontSize: em(1.5),\n marginVertical: em(0.83, em(1.5)),\n fontWeight: 'bold',\n },\n h3: {\n fontSize: em(1.17),\n marginVertical: em(1, em(1.17)),\n fontWeight: 'bold',\n },\n h4: {\n fontSize: em(1),\n marginVertical: em(1.33, em(1)),\n fontWeight: 'bold',\n },\n h5: {\n fontSize: em(0.83),\n marginVertical: em(1.67, em(0.83)),\n fontWeight: 'bold',\n },\n h6: {\n fontSize: em(0.67),\n marginVertical: em(2.33, em(0.67)),\n fontWeight: 'bold',\n },\n p: {\n fontSize: em(1),\n marginVertical: em(1),\n },\n blockquote: {\n marginVertical: em(1),\n marginHorizontal: 30,\n },\n hr: {\n marginVertical: em(0.5),\n borderBottomWidth: 1,\n borderBottomColor: '#000',\n },\n address: {\n fontStyle: 'italic',\n },\n pre: {\n // fontFamily: 'monospace',\n // whiteSpace: 'pre',\n marginVertical: em(1),\n },\n b: {\n fontWeight: 'bold',\n },\n strong: {\n fontWeight: 'bold',\n },\n i: {\n fontStyle: 'italic',\n },\n em: {\n fontStyle: 'italic',\n },\n s: {\n textDecoration: 'line-through',\n },\n u: {\n textDecoration: 'underline',\n },\n cite: {\n fontStyle: 'italic',\n },\n code: {\n // fontFamily: 'monospace',\n },\n a: {\n textDecoration: 'underline',\n },\n ul: {\n marginVertical: em(1),\n },\n ol: {\n marginVertical: em(1),\n },\n li: {\n display: 'flex',\n flexDirection: 'row',\n paddingRight: 25,\n },\n li_bullet: {\n width: 30,\n textAlign: 'right',\n flexShrink: 0,\n flexGrow: 0,\n paddingRight: 5,\n },\n li_content: {\n textAlign: 'left',\n flexGrow: 1,\n },\n table: {\n display: 'flex',\n flexDirection: 'column',\n borderColor: 'gray',\n borderWidth: 1,\n // flexShrink: 1,\n borderCollapse: 'collapse',\n // borderSpacing: 2,\n },\n thead: {\n display: 'flex',\n flexDirection: 'column',\n },\n tbody: {\n display: 'flex',\n flexDirection: 'column',\n },\n tr: {\n display: 'flex',\n flexDirection: 'row',\n // flexShrink: 1,\n },\n td: {\n // flexGrow: 1,\n // flexShrink: 1,\n // flexBasis: 1,\n padding: 2,\n },\n th: {\n // flexGrow: 1,\n // flexShrink: 1,\n // flexBasis: 1,\n padding: 2,\n backgroundColor: '#f2f2f2',\n fontWeight: 'bold',\n },\n };\n\n if (reset) {\n for (const key of Object.keys(base)) {\n for (const style of Object.keys(base[key])) {\n if (\n style.startsWith('margin') ||\n style.startsWith('padding') ||\n style === 'fontSize'\n ) {\n delete (base as any)[key][style];\n }\n }\n }\n base.li_bullet.display = 'none';\n base.table.borderCollapse = 'collapse';\n base.table.borderSpacing = 0;\n }\n\n return StyleSheet.create(base);\n};\n"]}
|