mirror of
https://github.com/Snigdha-OS/documentation.git
synced 2025-09-13 20:14:56 +02:00
126 lines
4.3 KiB
JavaScript
126 lines
4.3 KiB
JavaScript
'use strict';
|
|
|
|
var addJSXAttribute = require('@svgr/babel-plugin-add-jsx-attribute');
|
|
var removeJSXAttribute = require('@svgr/babel-plugin-remove-jsx-attribute');
|
|
var removeJSXEmptyExpression = require('@svgr/babel-plugin-remove-jsx-empty-expression');
|
|
var replaceJSXAttributeValue = require('@svgr/babel-plugin-replace-jsx-attribute-value');
|
|
var svgDynamicTitle = require('@svgr/babel-plugin-svg-dynamic-title');
|
|
var svgEmDimensions = require('@svgr/babel-plugin-svg-em-dimensions');
|
|
var transformReactNativeSVG = require('@svgr/babel-plugin-transform-react-native-svg');
|
|
var transformSvgComponent = require('@svgr/babel-plugin-transform-svg-component');
|
|
|
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
|
|
var addJSXAttribute__default = /*#__PURE__*/_interopDefaultLegacy(addJSXAttribute);
|
|
var removeJSXAttribute__default = /*#__PURE__*/_interopDefaultLegacy(removeJSXAttribute);
|
|
var removeJSXEmptyExpression__default = /*#__PURE__*/_interopDefaultLegacy(removeJSXEmptyExpression);
|
|
var replaceJSXAttributeValue__default = /*#__PURE__*/_interopDefaultLegacy(replaceJSXAttributeValue);
|
|
var svgDynamicTitle__default = /*#__PURE__*/_interopDefaultLegacy(svgDynamicTitle);
|
|
var svgEmDimensions__default = /*#__PURE__*/_interopDefaultLegacy(svgEmDimensions);
|
|
var transformReactNativeSVG__default = /*#__PURE__*/_interopDefaultLegacy(transformReactNativeSVG);
|
|
var transformSvgComponent__default = /*#__PURE__*/_interopDefaultLegacy(transformSvgComponent);
|
|
|
|
const getAttributeValue = (value) => {
|
|
const literal = typeof value === "string" && value.startsWith("{") && value.endsWith("}");
|
|
return { value: literal ? value.slice(1, -1) : value, literal };
|
|
};
|
|
const propsToAttributes = (props) => {
|
|
return Object.keys(props).map((name) => {
|
|
const { literal, value } = getAttributeValue(props[name]);
|
|
return { name, literal, value };
|
|
});
|
|
};
|
|
function replaceMapToValues(replaceMap) {
|
|
return Object.keys(replaceMap).map((value) => {
|
|
const { literal, value: newValue } = getAttributeValue(replaceMap[value]);
|
|
return { value, newValue, literal };
|
|
});
|
|
}
|
|
const plugin = (_, opts) => {
|
|
let toRemoveAttributes = ["version"];
|
|
let toAddAttributes = [];
|
|
if (opts.svgProps) {
|
|
toAddAttributes = [...toAddAttributes, ...propsToAttributes(opts.svgProps)];
|
|
}
|
|
if (opts.ref) {
|
|
toAddAttributes = [
|
|
...toAddAttributes,
|
|
{
|
|
name: "ref",
|
|
value: "ref",
|
|
literal: true
|
|
}
|
|
];
|
|
}
|
|
if (opts.titleProp) {
|
|
toAddAttributes = [
|
|
...toAddAttributes,
|
|
{
|
|
name: "aria-labelledby",
|
|
value: "titleId",
|
|
literal: true
|
|
}
|
|
];
|
|
}
|
|
if (opts.descProp) {
|
|
toAddAttributes = [
|
|
...toAddAttributes,
|
|
{
|
|
name: "aria-describedby",
|
|
value: "descId",
|
|
literal: true
|
|
}
|
|
];
|
|
}
|
|
if (opts.expandProps) {
|
|
toAddAttributes = [
|
|
...toAddAttributes,
|
|
{
|
|
name: "props",
|
|
spread: true,
|
|
position: opts.expandProps === "start" || opts.expandProps === "end" ? opts.expandProps : void 0
|
|
}
|
|
];
|
|
}
|
|
if (!opts.dimensions) {
|
|
toRemoveAttributes = [...toRemoveAttributes, "width", "height"];
|
|
}
|
|
const plugins = [
|
|
[transformSvgComponent__default["default"], opts],
|
|
...opts.icon !== false && opts.dimensions ? [
|
|
[
|
|
svgEmDimensions__default["default"],
|
|
opts.icon !== true ? { width: opts.icon, height: opts.icon } : opts.native ? { width: 24, height: 24 } : {}
|
|
]
|
|
] : [],
|
|
[
|
|
removeJSXAttribute__default["default"],
|
|
{ elements: ["svg", "Svg"], attributes: toRemoveAttributes }
|
|
],
|
|
[
|
|
addJSXAttribute__default["default"],
|
|
{ elements: ["svg", "Svg"], attributes: toAddAttributes }
|
|
],
|
|
removeJSXEmptyExpression__default["default"]
|
|
];
|
|
if (opts.replaceAttrValues) {
|
|
plugins.push([
|
|
replaceJSXAttributeValue__default["default"],
|
|
{ values: replaceMapToValues(opts.replaceAttrValues) }
|
|
]);
|
|
}
|
|
if (opts.titleProp) {
|
|
plugins.push(svgDynamicTitle__default["default"]);
|
|
}
|
|
if (opts.descProp) {
|
|
plugins.push([svgDynamicTitle__default["default"], { tag: "desc" }, "desc"]);
|
|
}
|
|
if (opts.native) {
|
|
plugins.push(transformReactNativeSVG__default["default"]);
|
|
}
|
|
return { plugins };
|
|
};
|
|
|
|
module.exports = plugin;
|
|
//# sourceMappingURL=index.js.map
|