UNPKG

flowtoken

Version:

![flow token demo](https://nextjs-omega-five-46.vercel.app/demo.gif)

37 lines (36 loc) 2.37 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const react_1 = __importDefault(require("react")); // Not a react component, but returns a function that returns a react component // to be used as a custom code renderer in the SyntaxHighlighter component const customCodeRenderer = ({ animation, animationDuration, animationTimingFunction }) => { // Memoize the animation style to avoid recreating it for each text segment const animationStyle = { animationName: animation || '', animationDuration, animationTimingFunction, animationIterationCount: 1, whiteSpace: 'pre-wrap', display: 'inline-block', }; return ({ rows, stylesheet, useInlineStyles }) => rows.map((node, i) => { var _a; return (react_1.default.createElement("div", { key: i, style: ((_a = node.properties) === null || _a === void 0 ? void 0 : _a.style) || {} }, node.children.map((token, key) => { var _a, _b, _c; // Extract and apply styles from the stylesheet if available and inline styles are used const tokenStyles = useInlineStyles && stylesheet ? Object.assign(Object.assign({}, stylesheet[(_a = token === null || token === void 0 ? void 0 : token.properties) === null || _a === void 0 ? void 0 : _a.className[1]]), (_b = token.properties) === null || _b === void 0 ? void 0 : _b.style) : ((_c = token.properties) === null || _c === void 0 ? void 0 : _c.style) || {}; return (react_1.default.createElement("span", { key: key, style: tokenStyles }, token.children && token.children[0].value.split(' ').map((word, index) => (react_1.default.createElement("span", { key: index, style: { animationName: animation || '', animationDuration, animationTimingFunction, animationIterationCount: 1, whiteSpace: 'pre-wrap', display: 'inline-block', } }, word + (index < token.children[0].value.split(' ').length - 1 ? ' ' : '')))))); }))); }); }; exports.default = customCodeRenderer; // Cannot use React.memo here as this is a function that returns a function