This commit is contained in:
Iliyan Angelov
2025-09-14 23:24:25 +03:00
commit c67067a2a4
71311 changed files with 6800714 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
# Change Log
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
# [5.5.0](https://github.com/gregberge/svgr/tree/master/packages/hast-util-to-babel-ast/compare/v5.4.0...v5.5.0) (2020-11-15)
**Note:** Version bump only for package @svgr/hast-util-to-babel-ast
# [5.4.0](https://github.com/gregberge/svgr/tree/master/packages/hast-util-to-babel-ast/compare/v5.3.1...v5.4.0) (2020-04-27)
**Note:** Version bump only for package @svgr/hast-util-to-babel-ast
## [5.0.1](https://github.com/gregberge/svgr/tree/master/packages/hast-util-to-babel-ast/compare/v5.0.0...v5.0.1) (2019-12-29)
### Bug Fixes
* fix engines in package.json ([a45d6fc](https://github.com/gregberge/svgr/tree/master/packages/hast-util-to-babel-ast/commit/a45d6fc8b43402bec60ed4e9273f90fdc65a23a7))
## [4.3.2](https://github.com/gregberge/svgr/tree/master/packages/hast-util-to-babel-ast/compare/v4.3.1...v4.3.2) (2019-07-15)
### Performance Improvements
* replace rehype with svg-parser ([#321](https://github.com/gregberge/svgr/tree/master/packages/hast-util-to-babel-ast/issues/321)) ([7eb5ef6](https://github.com/gregberge/svgr/tree/master/packages/hast-util-to-babel-ast/commit/7eb5ef6))
## [4.3.1](https://github.com/gregberge/svgr/tree/master/packages/hast-util-to-babel-ast/compare/v4.3.0...v4.3.1) (2019-07-01)
**Note:** Version bump only for package @svgr/hast-util-to-babel-ast
# [4.2.0](https://github.com/gregberge/svgr/tree/master/packages/hast-util-to-babel-ast/compare/v4.1.0...v4.2.0) (2019-04-11)
### Bug Fixes
* **hast-util-to-babel-ast:** correctly handle aria attributes ([23d12aa](https://github.com/gregberge/svgr/tree/master/packages/hast-util-to-babel-ast/commit/23d12aa)), closes [#279](https://github.com/gregberge/svgr/tree/master/packages/hast-util-to-babel-ast/issues/279)
# [4.1.0](https://github.com/gregberge/svgr/compare/v4.0.4...v4.1.0) (2018-11-24)
**Note:** Version bump only for package @svgr/hast-util-to-babel-ast
## [4.0.3](https://github.com/gregberge/svgr/compare/v4.0.2...v4.0.3) (2018-11-13)
### Bug Fixes
* upgrade dependencies ([7e2195f](https://github.com/gregberge/svgr/commit/7e2195f))
## [4.0.2](https://github.com/gregberge/svgr/compare/v4.0.1...v4.0.2) (2018-11-08)
### Bug Fixes
* **hast-util-to-babel-ast:** replace tabs by spaces in attributes ([b0f3d19](https://github.com/gregberge/svgr/commit/b0f3d19)), closes [#219](https://github.com/gregberge/svgr/issues/219)
## [4.0.1](https://github.com/gregberge/svgr/compare/v4.0.0...v4.0.1) (2018-11-08)
### Bug Fixes
* **hast-util-to-babel-ast:** correctly transforms data & aria attributes ([99711c4](https://github.com/gregberge/svgr/commit/99711c4)), closes [#221](https://github.com/gregberge/svgr/issues/221)
* **hast-util-to-babel-ast:** replace line-breaks in attributes ([00a2625](https://github.com/gregberge/svgr/commit/00a2625)), closes [#219](https://github.com/gregberge/svgr/issues/219)
# [4.0.0](https://github.com/gregberge/svgr/compare/v3.1.0...v4.0.0) (2018-11-04)
### Features
* **v4:** new architecture ([ac8b8ca](https://github.com/gregberge/svgr/commit/ac8b8ca))
### BREAKING CHANGES
* **v4:** - `template` option must now returns a Babel AST
- `@svgr/core` does not include svgo & prettier by default

View File

@@ -0,0 +1,7 @@
Copyright 2017 Smooth Code
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,28 @@
# @svgr/hast-util-to-babel-ast
[![Build Status](https://img.shields.io/travis/smooth-code/svgr.svg)](https://travis-ci.org/smooth-code/svgr)
[![Version](https://img.shields.io/npm/v/@svgr/hast-util-to-babel-ast.svg)](https://www.npmjs.com/package/@svgr/hast-util-to-babel-ast)
[![MIT License](https://img.shields.io/npm/l/@svgr/hast-util-to-babel-ast.svg)](https://github.com/smooth-code/svgr/blob/master/LICENSE)
Transforms HAST into Babel AST.
## Install
```
npm install --save-dev @svgr/hast-util-to-babel-ast
```
## Usage
```js
import { parse } from 'svg-parser'
import toBabelAST from '@svgr/hast-util-to-babel-ast'
const hastTree = parse(`<svg></svg>`)
const babelTree = hastToBabelAst(hastTree)
```
## License
MIT

View File

@@ -0,0 +1,28 @@
"use strict";
exports.__esModule = true;
exports.default = void 0;
var _one = _interopRequireDefault(require("./one"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* Transform the children of `parent`. */
function all(h, parent) {
const nodes = parent.children || [];
const {
length
} = nodes;
const values = [];
let index = -1;
while (++index < length) {
const result = (0, _one.default)(h, nodes[index], parent);
values.push(result);
}
return values.filter(node => node);
}
var _default = all;
exports.default = _default;

View File

@@ -0,0 +1,80 @@
"use strict";
exports.__esModule = true;
exports.default = void 0;
var t = _interopRequireWildcard(require("@babel/types"));
var _util = require("./util");
var _stringToObjectStyle = _interopRequireDefault(require("./stringToObjectStyle"));
var _mappings = require("./mappings");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function convertAriaAttribute(kebabKey) {
const [aria, ...parts] = kebabKey.split('-');
return `${aria}-${parts.join('').toLowerCase()}`;
}
function getKey(key, value, node) {
const lowerCaseKey = key.toLowerCase();
const mappedElementAttribute = _mappings.ELEMENT_ATTRIBUTE_MAPPING[node.name] && _mappings.ELEMENT_ATTRIBUTE_MAPPING[node.name][lowerCaseKey];
const mappedAttribute = _mappings.ATTRIBUTE_MAPPING[lowerCaseKey];
if (mappedElementAttribute || mappedAttribute) {
return t.jsxIdentifier(mappedElementAttribute || mappedAttribute);
}
const kebabKey = (0, _util.kebabCase)(key);
if (kebabKey.startsWith('aria-')) {
return t.jsxIdentifier(convertAriaAttribute(kebabKey));
}
if (kebabKey.startsWith('data-')) {
return t.jsxIdentifier(kebabKey);
}
return t.jsxIdentifier(key);
}
function getValue(key, value) {
// Handle className
if (Array.isArray(value)) {
return t.stringLiteral((0, _util.replaceSpaces)(value.join(' ')));
}
if (key === 'style') {
return t.jsxExpressionContainer((0, _stringToObjectStyle.default)(value));
}
if ((0, _util.isNumeric)(value)) {
return t.jsxExpressionContainer(t.numericLiteral(Number(value)));
}
return t.stringLiteral((0, _util.replaceSpaces)(value));
}
const getAttributes = node => {
const keys = Object.keys(node.properties);
const attributes = [];
let index = -1;
while (++index < keys.length) {
const key = keys[index];
const value = node.properties[key];
const attribute = t.jsxAttribute(getKey(key, value, node), getValue(key, value, node));
attributes.push(attribute);
}
return attributes;
};
var _default = getAttributes;
exports.default = _default;

View File

@@ -0,0 +1,65 @@
"use strict";
exports.__esModule = true;
exports.element = exports.text = exports.comment = exports.root = void 0;
var t = _interopRequireWildcard(require("@babel/types"));
var _all = _interopRequireDefault(require("./all"));
var _getAttributes = _interopRequireDefault(require("./getAttributes"));
var _mappings = require("./mappings");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const root = (h, node) => t.program((0, _all.default)(h, node));
exports.root = root;
const comment = (h, node, parent) => {
if (parent.type === 'root') {
return null;
}
const expression = t.jsxEmptyExpression();
t.addComment(expression, 'inner', node.value);
return t.jsxExpressionContainer(expression);
};
exports.comment = comment;
const text = (h, node, parent) => {
if (parent.type === 'root') {
return null;
}
if (node.value.match(/^\s+$/)) {
return null;
}
return t.jsxExpressionContainer(t.stringLiteral(node.value));
};
exports.text = text;
const element = (h, node, parent) => {
const children = (0, _all.default)(h, node);
const selfClosing = children.length === 0;
const name = _mappings.ELEMENT_TAG_NAME_MAPPING[node.tagName] || node.tagName;
const openingElement = t.jsxOpeningElement(t.jsxIdentifier(name), (0, _getAttributes.default)(node), selfClosing);
const closingElement = !selfClosing ? t.jsxClosingElement(t.jsxIdentifier(name)) : null;
const jsxElement = t.jsxElement(openingElement, closingElement, children);
if (parent.type === 'root') {
return t.expressionStatement(jsxElement);
}
return jsxElement;
};
exports.element = element;

View File

@@ -0,0 +1,25 @@
"use strict";
exports.__esModule = true;
exports.default = void 0;
var handlers = _interopRequireWildcard(require("./handlers"));
var _one = _interopRequireDefault(require("./one"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const h = {
handlers
};
function toBabelAST(tree) {
return (0, _one.default)(h, tree);
}
var _default = toBabelAST;
exports.default = _default;

View File

@@ -0,0 +1,599 @@
"use strict";
exports.__esModule = true;
exports.ELEMENT_TAG_NAME_MAPPING = exports.ELEMENT_ATTRIBUTE_MAPPING = exports.ATTRIBUTE_MAPPING = void 0;
// From https://raw.githubusercontent.com/facebook/react/master/packages/react-dom/src/shared/possibleStandardNames.js
const ATTRIBUTE_MAPPING = {
// HTML
accept: 'accept',
acceptcharset: 'acceptCharset',
'accept-charset': 'acceptCharset',
accesskey: 'accessKey',
action: 'action',
allowfullscreen: 'allowFullScreen',
alt: 'alt',
as: 'as',
async: 'async',
autocapitalize: 'autoCapitalize',
autocomplete: 'autoComplete',
autocorrect: 'autoCorrect',
autofocus: 'autoFocus',
autoplay: 'autoPlay',
autosave: 'autoSave',
capture: 'capture',
cellpadding: 'cellPadding',
cellspacing: 'cellSpacing',
challenge: 'challenge',
charset: 'charSet',
checked: 'checked',
children: 'children',
cite: 'cite',
class: 'className',
classid: 'classID',
classname: 'className',
cols: 'cols',
colspan: 'colSpan',
content: 'content',
contenteditable: 'contentEditable',
contextmenu: 'contextMenu',
controls: 'controls',
controlslist: 'controlsList',
coords: 'coords',
crossorigin: 'crossOrigin',
dangerouslysetinnerhtml: 'dangerouslySetInnerHTML',
data: 'data',
datetime: 'dateTime',
default: 'default',
defaultchecked: 'defaultChecked',
defaultvalue: 'defaultValue',
defer: 'defer',
dir: 'dir',
disabled: 'disabled',
download: 'download',
draggable: 'draggable',
enctype: 'encType',
for: 'htmlFor',
form: 'form',
formmethod: 'formMethod',
formaction: 'formAction',
formenctype: 'formEncType',
formnovalidate: 'formNoValidate',
formtarget: 'formTarget',
frameborder: 'frameBorder',
headers: 'headers',
height: 'height',
hidden: 'hidden',
high: 'high',
href: 'href',
hreflang: 'hrefLang',
htmlfor: 'htmlFor',
httpequiv: 'httpEquiv',
'http-equiv': 'httpEquiv',
icon: 'icon',
id: 'id',
innerhtml: 'innerHTML',
inputmode: 'inputMode',
integrity: 'integrity',
is: 'is',
itemid: 'itemID',
itemprop: 'itemProp',
itemref: 'itemRef',
itemscope: 'itemScope',
itemtype: 'itemType',
keyparams: 'keyParams',
keytype: 'keyType',
kind: 'kind',
label: 'label',
lang: 'lang',
list: 'list',
loop: 'loop',
low: 'low',
manifest: 'manifest',
marginwidth: 'marginWidth',
marginheight: 'marginHeight',
max: 'max',
maxlength: 'maxLength',
media: 'media',
mediagroup: 'mediaGroup',
method: 'method',
min: 'min',
minlength: 'minLength',
multiple: 'multiple',
muted: 'muted',
name: 'name',
nomodule: 'noModule',
nonce: 'nonce',
novalidate: 'noValidate',
open: 'open',
optimum: 'optimum',
pattern: 'pattern',
placeholder: 'placeholder',
playsinline: 'playsInline',
poster: 'poster',
preload: 'preload',
profile: 'profile',
radiogroup: 'radioGroup',
readonly: 'readOnly',
referrerpolicy: 'referrerPolicy',
rel: 'rel',
required: 'required',
reversed: 'reversed',
role: 'role',
rows: 'rows',
rowspan: 'rowSpan',
sandbox: 'sandbox',
scope: 'scope',
scoped: 'scoped',
scrolling: 'scrolling',
seamless: 'seamless',
selected: 'selected',
shape: 'shape',
size: 'size',
sizes: 'sizes',
span: 'span',
spellcheck: 'spellCheck',
src: 'src',
srcdoc: 'srcDoc',
srclang: 'srcLang',
srcset: 'srcSet',
start: 'start',
step: 'step',
style: 'style',
summary: 'summary',
tabindex: 'tabIndex',
target: 'target',
title: 'title',
type: 'type',
usemap: 'useMap',
value: 'value',
width: 'width',
wmode: 'wmode',
wrap: 'wrap',
// SVG
about: 'about',
accentheight: 'accentHeight',
'accent-height': 'accentHeight',
accumulate: 'accumulate',
additive: 'additive',
alignmentbaseline: 'alignmentBaseline',
'alignment-baseline': 'alignmentBaseline',
allowreorder: 'allowReorder',
alphabetic: 'alphabetic',
amplitude: 'amplitude',
arabicform: 'arabicForm',
'arabic-form': 'arabicForm',
ascent: 'ascent',
attributename: 'attributeName',
attributetype: 'attributeType',
autoreverse: 'autoReverse',
azimuth: 'azimuth',
basefrequency: 'baseFrequency',
baselineshift: 'baselineShift',
'baseline-shift': 'baselineShift',
baseprofile: 'baseProfile',
bbox: 'bbox',
begin: 'begin',
bias: 'bias',
by: 'by',
calcmode: 'calcMode',
capheight: 'capHeight',
'cap-height': 'capHeight',
clip: 'clip',
clippath: 'clipPath',
'clip-path': 'clipPath',
clippathunits: 'clipPathUnits',
cliprule: 'clipRule',
'clip-rule': 'clipRule',
color: 'color',
colorinterpolation: 'colorInterpolation',
'color-interpolation': 'colorInterpolation',
colorinterpolationfilters: 'colorInterpolationFilters',
'color-interpolation-filters': 'colorInterpolationFilters',
colorprofile: 'colorProfile',
'color-profile': 'colorProfile',
colorrendering: 'colorRendering',
'color-rendering': 'colorRendering',
contentscripttype: 'contentScriptType',
contentstyletype: 'contentStyleType',
cursor: 'cursor',
cx: 'cx',
cy: 'cy',
d: 'd',
datatype: 'datatype',
decelerate: 'decelerate',
descent: 'descent',
diffuseconstant: 'diffuseConstant',
direction: 'direction',
display: 'display',
divisor: 'divisor',
dominantbaseline: 'dominantBaseline',
'dominant-baseline': 'dominantBaseline',
dur: 'dur',
dx: 'dx',
dy: 'dy',
edgemode: 'edgeMode',
elevation: 'elevation',
enablebackground: 'enableBackground',
'enable-background': 'enableBackground',
end: 'end',
exponent: 'exponent',
externalresourcesrequired: 'externalResourcesRequired',
fill: 'fill',
fillopacity: 'fillOpacity',
'fill-opacity': 'fillOpacity',
fillrule: 'fillRule',
'fill-rule': 'fillRule',
filter: 'filter',
filterres: 'filterRes',
filterunits: 'filterUnits',
floodopacity: 'floodOpacity',
'flood-opacity': 'floodOpacity',
floodcolor: 'floodColor',
'flood-color': 'floodColor',
focusable: 'focusable',
fontfamily: 'fontFamily',
'font-family': 'fontFamily',
fontsize: 'fontSize',
'font-size': 'fontSize',
fontsizeadjust: 'fontSizeAdjust',
'font-size-adjust': 'fontSizeAdjust',
fontstretch: 'fontStretch',
'font-stretch': 'fontStretch',
fontstyle: 'fontStyle',
'font-style': 'fontStyle',
fontvariant: 'fontVariant',
'font-variant': 'fontVariant',
fontweight: 'fontWeight',
'font-weight': 'fontWeight',
format: 'format',
from: 'from',
fx: 'fx',
fy: 'fy',
g1: 'g1',
g2: 'g2',
glyphname: 'glyphName',
'glyph-name': 'glyphName',
glyphorientationhorizontal: 'glyphOrientationHorizontal',
'glyph-orientation-horizontal': 'glyphOrientationHorizontal',
glyphorientationvertical: 'glyphOrientationVertical',
'glyph-orientation-vertical': 'glyphOrientationVertical',
glyphref: 'glyphRef',
gradienttransform: 'gradientTransform',
gradientunits: 'gradientUnits',
hanging: 'hanging',
horizadvx: 'horizAdvX',
'horiz-adv-x': 'horizAdvX',
horizoriginx: 'horizOriginX',
'horiz-origin-x': 'horizOriginX',
ideographic: 'ideographic',
imagerendering: 'imageRendering',
'image-rendering': 'imageRendering',
in2: 'in2',
in: 'in',
inlist: 'inlist',
intercept: 'intercept',
k1: 'k1',
k2: 'k2',
k3: 'k3',
k4: 'k4',
k: 'k',
kernelmatrix: 'kernelMatrix',
kernelunitlength: 'kernelUnitLength',
kerning: 'kerning',
keypoints: 'keyPoints',
keysplines: 'keySplines',
keytimes: 'keyTimes',
lengthadjust: 'lengthAdjust',
letterspacing: 'letterSpacing',
'letter-spacing': 'letterSpacing',
lightingcolor: 'lightingColor',
'lighting-color': 'lightingColor',
limitingconeangle: 'limitingConeAngle',
local: 'local',
markerend: 'markerEnd',
'marker-end': 'markerEnd',
markerheight: 'markerHeight',
markermid: 'markerMid',
'marker-mid': 'markerMid',
markerstart: 'markerStart',
'marker-start': 'markerStart',
markerunits: 'markerUnits',
markerwidth: 'markerWidth',
mask: 'mask',
maskcontentunits: 'maskContentUnits',
maskunits: 'maskUnits',
mathematical: 'mathematical',
mode: 'mode',
numoctaves: 'numOctaves',
offset: 'offset',
opacity: 'opacity',
operator: 'operator',
order: 'order',
orient: 'orient',
orientation: 'orientation',
origin: 'origin',
overflow: 'overflow',
overlineposition: 'overlinePosition',
'overline-position': 'overlinePosition',
overlinethickness: 'overlineThickness',
'overline-thickness': 'overlineThickness',
paintorder: 'paintOrder',
'paint-order': 'paintOrder',
panose1: 'panose1',
'panose-1': 'panose1',
pathlength: 'pathLength',
patterncontentunits: 'patternContentUnits',
patterntransform: 'patternTransform',
patternunits: 'patternUnits',
pointerevents: 'pointerEvents',
'pointer-events': 'pointerEvents',
points: 'points',
pointsatx: 'pointsAtX',
pointsaty: 'pointsAtY',
pointsatz: 'pointsAtZ',
prefix: 'prefix',
preservealpha: 'preserveAlpha',
preserveaspectratio: 'preserveAspectRatio',
primitiveunits: 'primitiveUnits',
property: 'property',
r: 'r',
radius: 'radius',
refx: 'refX',
refy: 'refY',
renderingintent: 'renderingIntent',
'rendering-intent': 'renderingIntent',
repeatcount: 'repeatCount',
repeatdur: 'repeatDur',
requiredextensions: 'requiredExtensions',
requiredfeatures: 'requiredFeatures',
resource: 'resource',
restart: 'restart',
result: 'result',
results: 'results',
rotate: 'rotate',
rx: 'rx',
ry: 'ry',
scale: 'scale',
security: 'security',
seed: 'seed',
shaperendering: 'shapeRendering',
'shape-rendering': 'shapeRendering',
slope: 'slope',
spacing: 'spacing',
specularconstant: 'specularConstant',
specularexponent: 'specularExponent',
speed: 'speed',
spreadmethod: 'spreadMethod',
startoffset: 'startOffset',
stddeviation: 'stdDeviation',
stemh: 'stemh',
stemv: 'stemv',
stitchtiles: 'stitchTiles',
stopcolor: 'stopColor',
'stop-color': 'stopColor',
stopopacity: 'stopOpacity',
'stop-opacity': 'stopOpacity',
strikethroughposition: 'strikethroughPosition',
'strikethrough-position': 'strikethroughPosition',
strikethroughthickness: 'strikethroughThickness',
'strikethrough-thickness': 'strikethroughThickness',
string: 'string',
stroke: 'stroke',
strokedasharray: 'strokeDasharray',
'stroke-dasharray': 'strokeDasharray',
strokedashoffset: 'strokeDashoffset',
'stroke-dashoffset': 'strokeDashoffset',
strokelinecap: 'strokeLinecap',
'stroke-linecap': 'strokeLinecap',
strokelinejoin: 'strokeLinejoin',
'stroke-linejoin': 'strokeLinejoin',
strokemiterlimit: 'strokeMiterlimit',
'stroke-miterlimit': 'strokeMiterlimit',
strokewidth: 'strokeWidth',
'stroke-width': 'strokeWidth',
strokeopacity: 'strokeOpacity',
'stroke-opacity': 'strokeOpacity',
suppresscontenteditablewarning: 'suppressContentEditableWarning',
suppresshydrationwarning: 'suppressHydrationWarning',
surfacescale: 'surfaceScale',
systemlanguage: 'systemLanguage',
tablevalues: 'tableValues',
targetx: 'targetX',
targety: 'targetY',
textanchor: 'textAnchor',
'text-anchor': 'textAnchor',
textdecoration: 'textDecoration',
'text-decoration': 'textDecoration',
textlength: 'textLength',
textrendering: 'textRendering',
'text-rendering': 'textRendering',
to: 'to',
transform: 'transform',
typeof: 'typeof',
u1: 'u1',
u2: 'u2',
underlineposition: 'underlinePosition',
'underline-position': 'underlinePosition',
underlinethickness: 'underlineThickness',
'underline-thickness': 'underlineThickness',
unicode: 'unicode',
unicodebidi: 'unicodeBidi',
'unicode-bidi': 'unicodeBidi',
unicoderange: 'unicodeRange',
'unicode-range': 'unicodeRange',
unitsperem: 'unitsPerEm',
'units-per-em': 'unitsPerEm',
unselectable: 'unselectable',
valphabetic: 'vAlphabetic',
'v-alphabetic': 'vAlphabetic',
values: 'values',
vectoreffect: 'vectorEffect',
'vector-effect': 'vectorEffect',
version: 'version',
vertadvy: 'vertAdvY',
'vert-adv-y': 'vertAdvY',
vertoriginx: 'vertOriginX',
'vert-origin-x': 'vertOriginX',
vertoriginy: 'vertOriginY',
'vert-origin-y': 'vertOriginY',
vhanging: 'vHanging',
'v-hanging': 'vHanging',
videographic: 'vIdeographic',
'v-ideographic': 'vIdeographic',
viewbox: 'viewBox',
viewtarget: 'viewTarget',
visibility: 'visibility',
vmathematical: 'vMathematical',
'v-mathematical': 'vMathematical',
vocab: 'vocab',
widths: 'widths',
wordspacing: 'wordSpacing',
'word-spacing': 'wordSpacing',
writingmode: 'writingMode',
'writing-mode': 'writingMode',
x1: 'x1',
x2: 'x2',
x: 'x',
xchannelselector: 'xChannelSelector',
xheight: 'xHeight',
'x-height': 'xHeight',
xlinkactuate: 'xlinkActuate',
'xlink:actuate': 'xlinkActuate',
xlinkarcrole: 'xlinkArcrole',
'xlink:arcrole': 'xlinkArcrole',
xlinkhref: 'xlinkHref',
'xlink:href': 'xlinkHref',
xlinkrole: 'xlinkRole',
'xlink:role': 'xlinkRole',
xlinkshow: 'xlinkShow',
'xlink:show': 'xlinkShow',
xlinktitle: 'xlinkTitle',
'xlink:title': 'xlinkTitle',
xlinktype: 'xlinkType',
'xlink:type': 'xlinkType',
xmlbase: 'xmlBase',
'xml:base': 'xmlBase',
xmllang: 'xmlLang',
'xml:lang': 'xmlLang',
xmlns: 'xmlns',
'xml:space': 'xmlSpace',
xmlnsxlink: 'xmlnsXlink',
'xmlns:xlink': 'xmlnsXlink',
xmlspace: 'xmlSpace',
y1: 'y1',
y2: 'y2',
y: 'y',
ychannelselector: 'yChannelSelector',
z: 'z',
zoomandpan: 'zoomAndPan'
};
exports.ATTRIBUTE_MAPPING = ATTRIBUTE_MAPPING;
const ELEMENT_ATTRIBUTE_MAPPING = {
input: {
checked: 'defaultChecked',
value: 'defaultValue',
maxlength: 'maxLength'
},
form: {
enctype: 'encType'
}
}; // Reference: https://developer.mozilla.org/en-US/docs/Web/SVG/Element#SVG_elements
exports.ELEMENT_ATTRIBUTE_MAPPING = ELEMENT_ATTRIBUTE_MAPPING;
const ELEMENT_TAG_NAME_MAPPING = {
a: 'a',
altglyph: 'altGlyph',
altglyphdef: 'altGlyphDef',
altglyphitem: 'altGlyphItem',
animate: 'animate',
animatecolor: 'animateColor',
animatemotion: 'animateMotion',
animatetransform: 'animateTransform',
audio: 'audio',
canvas: 'canvas',
circle: 'circle',
clippath: 'clipPath',
'color-profile': 'colorProfile',
cursor: 'cursor',
defs: 'defs',
desc: 'desc',
discard: 'discard',
ellipse: 'ellipse',
feblend: 'feBlend',
fecolormatrix: 'feColorMatrix',
fecomponenttransfer: 'feComponentTransfer',
fecomposite: 'feComposite',
feconvolvematrix: 'feConvolveMatrix',
fediffuselighting: 'feDiffuseLighting',
fedisplacementmap: 'feDisplacementMap',
fedistantlight: 'feDistantLight',
fedropshadow: 'feDropShadow',
feflood: 'feFlood',
fefunca: 'feFuncA',
fefuncb: 'feFuncB',
fefuncg: 'feFuncG',
fefuncr: 'feFuncR',
fegaussianblur: 'feGaussianBlur',
feimage: 'feImage',
femerge: 'feMerge',
femergenode: 'feMergeNode',
femorphology: 'feMorphology',
feoffset: 'feOffset',
fepointlight: 'fePointLight',
fespecularlighting: 'feSpecularLighting',
fespotlight: 'feSpotLight',
fetile: 'feTile',
feturbulence: 'feTurbulence',
filter: 'filter',
font: 'font',
'font-face': 'fontFace',
'font-face-format': 'fontFaceFormat',
'font-face-name': 'fontFaceName',
'font-face-src': 'fontFaceSrc',
'font-face-uri': 'fontFaceUri',
foreignobject: 'foreignObject',
g: 'g',
glyph: 'glyph',
glyphref: 'glyphRef',
hatch: 'hatch',
hatchpath: 'hatchpath',
hkern: 'hkern',
iframe: 'iframe',
image: 'image',
line: 'line',
lineargradient: 'linearGradient',
marker: 'marker',
mask: 'mask',
mesh: 'mesh',
meshgradient: 'meshgradient',
meshpatch: 'meshpatch',
meshrow: 'meshrow',
metadata: 'metadata',
'missing-glyph': 'missingGlyph',
mpath: 'mpath',
path: 'path',
pattern: 'pattern',
polygon: 'polygon',
polyline: 'polyline',
radialgradient: 'radialGradient',
rect: 'rect',
script: 'script',
set: 'set',
solidcolor: 'solidcolor',
stop: 'stop',
style: 'style',
svg: 'svg',
switch: 'switch',
symbol: 'symbol',
text: 'text',
textpath: 'textPath',
title: 'title',
tref: 'tref',
tspan: 'tspan',
unknown: 'unknown',
use: 'use',
video: 'video',
view: 'view',
vkern: 'vkern'
};
exports.ELEMENT_TAG_NAME_MAPPING = ELEMENT_TAG_NAME_MAPPING;

View File

@@ -0,0 +1,23 @@
"use strict";
exports.__esModule = true;
exports.default = void 0;
function one(h, node, parent) {
const type = node && node.type;
const fn = h.handlers[type];
/* Fail on non-nodes. */
if (!type) {
throw new Error(`Expected node, got \`${node}\``);
}
if (!fn) {
throw new Error(`Node of type ${type} is unknown`);
}
return fn(h, node, parent);
}
var _default = one;
exports.default = _default;

View File

@@ -0,0 +1,83 @@
"use strict";
exports.__esModule = true;
exports.default = void 0;
var t = _interopRequireWildcard(require("@babel/types"));
var _util = require("./util");
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
// Inspired by https://github.com/reactjs/react-magic/blob/master/src/htmltojsx.js
/**
* Determines if the CSS value can be converted from a
* 'px' suffixed string to a numeric value.
*
* @param {string} value CSS property value
* @return {boolean}
*/
function isConvertiblePixelValue(value) {
return /^\d+px$/.test(value);
}
/**
* Format style key into JSX style object key.
*
* @param {string} key
* @return {string}
*/
function formatKey(key) {
key = key.toLowerCase(); // Don't capitalize -ms- prefix
if (/^-ms-/.test(key)) key = key.substr(1);
return t.identifier((0, _util.hyphenToCamelCase)(key));
}
/**
* Format style value into JSX style object value.
*
* @param {string} key
* @return {string}
*/
function formatValue(value) {
if ((0, _util.isNumeric)(value)) return t.numericLiteral(Number(value));
if (isConvertiblePixelValue(value)) return t.numericLiteral(Number((0, _util.trimEnd)(value, 'px')));
return t.stringLiteral(value);
}
/**
* Handle parsing of inline styles.
*
* @param {string} rawStyle
* @returns {object}
*/
function stringToObjectStyle(rawStyle) {
const entries = rawStyle.split(';');
const properties = [];
let index = -1;
while (++index < entries.length) {
const entry = entries[index];
const style = entry.trim();
const firstColon = style.indexOf(':');
const value = style.substr(firstColon + 1).trim();
const key = style.substr(0, firstColon);
if (key !== '') {
const property = t.objectProperty(formatKey(key), formatValue(value));
properties.push(property);
}
}
return t.objectExpression(properties);
}
var _default = stringToObjectStyle;
exports.default = _default;

View File

@@ -0,0 +1,54 @@
"use strict";
exports.__esModule = true;
exports.isNumeric = isNumeric;
exports.hyphenToCamelCase = hyphenToCamelCase;
exports.trimEnd = trimEnd;
exports.kebabCase = kebabCase;
exports.replaceSpaces = replaceSpaces;
/**
* Determines if the specified string consists entirely of numeric characters.
*
* @param {*} [value]
* @returns {boolean}
*/
function isNumeric(value) {
return !Number.isNaN(value - parseFloat(value));
}
/**
* Convert a hyphenated string to camelCase.
*
* @param {string} string
* @returns {string}
*/
function hyphenToCamelCase(string) {
return string.replace(/-(.)/g, (match, chr) => chr.toUpperCase());
}
/**
* Trim the specified substring off the string. If the string does not end
* with the specified substring, this is a no-op.
*
* @param {string} haystack String to search in
* @param {string} needle String to search for
* @return {string}
*/
function trimEnd(haystack, needle) {
return haystack.endsWith(needle) ? haystack.slice(0, -needle.length) : haystack;
}
const KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g;
function kebabCase(str) {
return str.replace(KEBAB_REGEX, match => `-${match.toLowerCase()}`);
}
const SPACES_REGEXP = /[\t\r\n\u0085\u2028\u2029]+/g;
function replaceSpaces(str) {
return str.replace(SPACES_REGEXP, ' ');
}

View File

@@ -0,0 +1,37 @@
{
"name": "@svgr/hast-util-to-babel-ast",
"description": "Transform HAST to Babel AST (JSX)",
"version": "5.5.0",
"main": "lib/index.js",
"repository": "https://github.com/gregberge/svgr/tree/master/packages/hast-util-to-babel-ast",
"author": "Greg Bergé <berge.greg@gmail.com>",
"publishConfig": {
"access": "public"
},
"keywords": [
"html",
"hast",
"babel",
"hast-util",
"unist-util",
"unist"
],
"engines": {
"node": ">=10"
},
"homepage": "https://react-svgr.com",
"funding": {
"type": "github",
"url": "https://github.com/sponsors/gregberge"
},
"license": "MIT",
"scripts": {
"prebuild": "rm -rf lib/",
"build": "babel --config-file ../../babel.config.js -d lib --ignore \"**/*.test.js\" src",
"prepublishOnly": "yarn run build"
},
"dependencies": {
"@babel/types": "^7.12.6"
},
"gitHead": "b5920550bd966f876cb65c5e23af180461e5aa23"
}