UNPKG

@formant/ava-react

Version:

React components of AVA.

79 lines (77 loc) 4.22 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/NarrativeTextVis/chore/plugin/createEntityPhraseFactory.tsx var createEntityPhraseFactory_exports = {}; __export(createEntityPhraseFactory_exports, { createEntityPhraseFactory: () => createEntityPhraseFactory }); module.exports = __toCommonJS(createEntityPhraseFactory_exports); var import_react = __toESM(require("react")); var import_lodash = require("lodash"); var import_utils = require("../../utils"); var import_createPhraseFactory = require("./createPhraseFactory"); function getMergedDescriptor(defaultDescriptor, customDescriptor) { const result = { ...defaultDescriptor, ...customDescriptor }; result.encoding = { ...(defaultDescriptor == null ? void 0 : defaultDescriptor.encoding) || {}, ...(customDescriptor == null ? void 0 : customDescriptor.encoding) || {} }; return result; } var createEntityPhraseFactory = (key, defaultDescriptor) => (customDescriptor, mode = "merge") => { const entityFactory = (0, import_createPhraseFactory.createPhraseFactory)(true); let entityDescriptor = (0, import_lodash.cloneDeep)(defaultDescriptor); if (customDescriptor) { entityDescriptor = mode === "overwrite" ? customDescriptor : getMergedDescriptor(defaultDescriptor, customDescriptor); } if (entityDescriptor.encoding) { const { color, bgColor, fontSize, fontWeight, underline } = entityDescriptor.encoding; const commonStyleFn = (0, import_utils.functionalize)(entityDescriptor == null ? void 0 : entityDescriptor.style, {}); const encodingStyle = (value, metadata, themeStyles) => { const args = [value, metadata, themeStyles]; return { ...commonStyleFn(...args), color: (0, import_utils.functionalize)(color, void 0)(...args), backgroundColor: (0, import_utils.functionalize)(bgColor, void 0)(...args), fontSize: (0, import_utils.functionalize)(fontSize, void 0)(...args), fontWeight: (0, import_utils.functionalize)(fontWeight, void 0)(...args), textDecoration: (0, import_utils.functionalize)(underline, false)(...args) ? "underline" : void 0 }; }; entityDescriptor.style = encodingStyle; const { prefix, suffix, inlineChart } = entityDescriptor.encoding; const { content } = entityDescriptor; entityDescriptor.content = (...args) => { const [value] = args; return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, (0, import_utils.functionalize)(prefix, null)(...args), content ? content(...args) : value, (0, import_utils.functionalize)(suffix, null)(...args), (0, import_utils.functionalize)(inlineChart, null)(...args)); }; delete entityDescriptor.encoding; } return entityFactory({ key, ...entityDescriptor }); }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { createEntityPhraseFactory });