swiftui-react-native
Version:
A React Native component library inspired by SwiftUI
137 lines • 5.75 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShadowText = void 0;
const react_1 = __importDefault(require("react"));
const react_native_1 = require("react-native");
const border_1 = require("../../utils/border");
const fonts_1 = require("../../utils/fonts");
const frame_1 = require("../../utils/frame");
const padding_1 = require("../../utils/padding");
const transform_1 = require("../../utils/transform");
const ShadowText = ({ font = 'body', italic, padding, rotationEffect, fontWeight, bold, scaleEffect, border, frame, style, children, fontSize, }) => {
return (react_1.default.createElement(react_native_1.Text, { style: [
{
...(0, fonts_1.getFont)(font, fontSize, isBoldMarkdownText(children)
? 'bold'
: bold
? 'bold'
: fontWeight, italic),
...(0, padding_1.getPadding)(padding),
...(0, frame_1.getFrame)(frame),
...(0, border_1.getBorder)(border),
...(0, transform_1.getTransform)(scaleEffect, rotationEffect),
...(isCodeMarkdownText(children) && { letterSpacing: 1 }),
},
style,
] }, typeof children === 'string'
? stripMarkdownFromText(children)
: children));
};
exports.ShadowText = ShadowText;
function isBoldMarkdownText(md) {
const boldRegex = /\*\*(.*?)\*\*/g;
const boldMatches = md.match(boldRegex);
if (boldMatches)
return true;
else
return false;
}
function isCodeMarkdownText(md) {
const codeRegex = /`([^`]+)`/g;
const codeMatches = md.match(codeRegex);
if (codeMatches)
return true;
else
return false;
}
function stripMarkdownFromText(md) {
const options = {
listUnicodeChar: false,
stripListLeaders: true,
gfm: true,
useImgAltText: true,
abbr: false,
replaceLinksWithURL: false,
htmlTagsToSkip: [],
};
let output = md || '';
// Remove horizontal rules (stripListHeaders conflict with this rule, which is why it has been moved to the top)
output = output.replace(/^(-\s*?|\*\s*?|_\s*?){3,}\s*/gm, '');
try {
if (options.stripListLeaders) {
if (options.listUnicodeChar)
output = output.replace(/^([\s\t]*)([\*\-\+]|\d+\.)\s+/gm, options.listUnicodeChar + ' $1');
else
output = output.replace(/^([\s\t]*)([\*\-\+]|\d+\.)\s+/gm, '$1');
}
if (options.gfm) {
output = output
// Header
.replace(/\n={2,}/g, '\n')
// Fenced codeblocks
.replace(/~{3}.*\n/g, '')
// Strikethrough
.replace(/~~/g, '')
// Fenced codeblocks
.replace(/`{3}.*\n/g, '');
}
if (options.abbr) {
// Remove abbreviations
output = output.replace(/\*\[.*\]:.*\n/, '');
}
output = output
// Remove HTML tags
.replace(/<[^>]*>/g, '');
var htmlReplaceRegex = new RegExp('<[^>]*>', 'g');
if (options.htmlTagsToSkip.length > 0) {
// Using negative lookahead. Eg. (?!sup|sub) will not match 'sup' and 'sub' tags.
var joinedHtmlTagsToSkip = '(?!' + options.htmlTagsToSkip.join('|') + ')';
// Adding the lookahead literal with the default regex for html. Eg./<(?!sup|sub)[^>]*>/ig
htmlReplaceRegex = new RegExp('<' + joinedHtmlTagsToSkip + '[^>]*>', 'ig');
}
output = output
// Remove HTML tags
.replace(htmlReplaceRegex, '')
// Remove setext-style headers
.replace(/^[=\-]{2,}\s*$/g, '')
// Remove footnotes?
.replace(/\[\^.+?\](\: .*?$)?/g, '')
.replace(/\s{0,2}\[.*?\]: .*?$/g, '')
// Remove images
.replace(/\!\[(.*?)\][\[\(].*?[\]\)]/g, options.useImgAltText ? '$1' : '')
// Remove inline links
.replace(/\[([^\]]*?)\][\[\(].*?[\]\)]/g, options.replaceLinksWithURL ? '$2' : '$1')
// Remove blockquotes
.replace(/^(\n)?\s{0,3}>\s?/gm, '$1')
// .replace(/(^|\n)\s{0,3}>\s?/g, '\n\n')
// Remove reference-style links?
.replace(/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/g, '')
// Remove atx-style headers
.replace(/^(\n)?\s{0,}#{1,6}\s*( (.+))? +#+$|^(\n)?\s{0,}#{1,6}\s*( (.+))?$/gm, '$1$3$4$6')
// Remove * emphasis
.replace(/([\*]+)(\S)(.*?\S)??\1/g, '$2$3')
// Remove _ emphasis. Unlike *, _ emphasis gets rendered only if
// 1. Either there is a whitespace character before opening _ and after closing _.
// 2. Or _ is at the start/end of the string.
.replace(/(^|\W)([_]+)(\S)(.*?\S)??\2($|\W)/g, '$1$3$4$5')
// Remove code blocks
.replace(/(`{3,})(.*?)\1/gm, '$2')
// Remove inline code
.replace(/`(.+?)`/g, '$1')
// // Replace two or more newlines with exactly two? Not entirely sure this belongs here...
// .replace(/\n{2,}/g, '\n\n')
// // Remove newlines in a paragraph
// .replace(/(\S+)\n\s*(\S+)/g, '$1 $2')
// Replace strike through
.replace(/~(.*?)~/g, '$1');
}
catch (e) {
console.error(e);
return md;
}
return output;
}
//# sourceMappingURL=ShadowText.js.map