Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

199 linhas
5.0 KiB

  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _JSXElement = _interopRequireDefault(require("./JSXElement"));
  7. var _JSXAttribute = _interopRequireDefault(require("./JSXAttribute"));
  8. var _JSXComment = _interopRequireDefault(require("./JSXComment"));
  9. var _JSXText = _interopRequireDefault(require("./JSXText"));
  10. var _util = require("./util");
  11. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  12. const ATTRIBUTE_MAPPING = {
  13. for: 'htmlFor',
  14. class: 'className',
  15. autoreverse: 'autoReverse',
  16. externalresourcesrequired: 'externalResourcesRequired'
  17. };
  18. const ELEMENT_ATTRIBUTE_MAPPING = {
  19. input: {
  20. checked: 'defaultChecked',
  21. value: 'defaultValue',
  22. maxlength: 'maxLength'
  23. },
  24. form: {
  25. enctype: 'encType'
  26. } // Reference: https://developer.mozilla.org/en-US/docs/Web/SVG/Element#SVG_elements
  27. };
  28. const ELEMENT_TAG_NAME_MAPPING = {
  29. a: 'a',
  30. altglyph: 'altGlyph',
  31. altglyphdef: 'altGlyphDef',
  32. altglyphitem: 'altGlyphItem',
  33. animate: 'animate',
  34. animatecolor: 'animateColor',
  35. animatemotion: 'animateMotion',
  36. animatetransform: 'animateTransform',
  37. audio: 'audio',
  38. canvas: 'canvas',
  39. circle: 'circle',
  40. clippath: 'clipPath',
  41. 'color-profile': 'colorProfile',
  42. cursor: 'cursor',
  43. defs: 'defs',
  44. desc: 'desc',
  45. discard: 'discard',
  46. ellipse: 'ellipse',
  47. feblend: 'feBlend',
  48. fecolormatrix: 'feColorMatrix',
  49. fecomponenttransfer: 'feComponentTransfer',
  50. fecomposite: 'feComposite',
  51. feconvolvematrix: 'feConvolveMatrix',
  52. fediffuselighting: 'feDiffuseLighting',
  53. fedisplacementmap: 'feDisplacementMap',
  54. fedistantlight: 'feDistantLight',
  55. fedropshadow: 'feDropShadow',
  56. feflood: 'feFlood',
  57. fefunca: 'feFuncA',
  58. fefuncb: 'feFuncB',
  59. fefuncg: 'feFuncG',
  60. fefuncr: 'feFuncR',
  61. fegaussianblur: 'feGaussianBlur',
  62. feimage: 'feImage',
  63. femerge: 'feMerge',
  64. femergenode: 'feMergeNode',
  65. femorphology: 'feMorphology',
  66. feoffset: 'feOffset',
  67. fepointlight: 'fePointLight',
  68. fespecularlighting: 'feSpecularLighting',
  69. fespotlight: 'feSpotLight',
  70. fetile: 'feTile',
  71. feturbulence: 'feTurbulence',
  72. filter: 'filter',
  73. font: 'font',
  74. 'font-face': 'fontFace',
  75. 'font-face-format': 'fontFaceFormat',
  76. 'font-face-name': 'fontFaceName',
  77. 'font-face-src': 'fontFaceSrc',
  78. 'font-face-uri': 'fontFaceUri',
  79. foreignobject: 'foreignObject',
  80. g: 'g',
  81. glyph: 'glyph',
  82. glyphref: 'glyphRef',
  83. hatch: 'hatch',
  84. hatchpath: 'hatchpath',
  85. hkern: 'hkern',
  86. iframe: 'iframe',
  87. image: 'image',
  88. line: 'line',
  89. lineargradient: 'linearGradient',
  90. marker: 'marker',
  91. mask: 'mask',
  92. mesh: 'mesh',
  93. meshgradient: 'meshgradient',
  94. meshpatch: 'meshpatch',
  95. meshrow: 'meshrow',
  96. metadata: 'metadata',
  97. 'missing-glyph': 'missingGlyph',
  98. mpath: 'mpath',
  99. path: 'path',
  100. pattern: 'pattern',
  101. polygon: 'polygon',
  102. polyline: 'polyline',
  103. radialgradient: 'radialGradient',
  104. rect: 'rect',
  105. script: 'script',
  106. set: 'set',
  107. solidcolor: 'solidcolor',
  108. stop: 'stop',
  109. style: 'style',
  110. svg: 'svg',
  111. switch: 'switch',
  112. symbol: 'symbol',
  113. text: 'text',
  114. textpath: 'textPath',
  115. title: 'title',
  116. tref: 'tref',
  117. tspan: 'tspan',
  118. unknown: 'unknown',
  119. use: 'use',
  120. video: 'video',
  121. view: 'view',
  122. vkern: 'vkern'
  123. };
  124. function getAttributeName(attribute, node) {
  125. if (!attribute.name.startsWith('aria-') && !attribute.name.startsWith('data-')) {
  126. return ELEMENT_ATTRIBUTE_MAPPING[node.name] && ELEMENT_ATTRIBUTE_MAPPING[node.name][attribute.name] || ATTRIBUTE_MAPPING[attribute.name] || (0, _util.hyphenToCamelCase)(attribute.name.replace(':', '-'));
  127. }
  128. return attribute.name;
  129. }
  130. function transformTagName(tagName) {
  131. const lowercaseTagName = tagName.toLowerCase();
  132. return ELEMENT_TAG_NAME_MAPPING[lowercaseTagName] || lowercaseTagName;
  133. }
  134. function getAttributeValue(attribute) {
  135. return attribute.value;
  136. }
  137. function listToArray(list) {
  138. const array = [];
  139. for (let i = 0; i < list.length; i += 1) {
  140. array.push(list[i]);
  141. }
  142. return array;
  143. }
  144. var _default = {
  145. HTMLElement: {
  146. enter(path) {
  147. const jsxElement = new _JSXElement.default();
  148. jsxElement.name = transformTagName(path.node.tagName);
  149. jsxElement.attributes = listToArray(path.node.attributes);
  150. jsxElement.children = listToArray(path.node.childNodes);
  151. path.replace(jsxElement);
  152. }
  153. },
  154. HTMLAttribute: {
  155. enter(path) {
  156. const jsxAttribute = new _JSXAttribute.default();
  157. jsxAttribute.name = getAttributeName(path.node, path.parent);
  158. jsxAttribute.value = getAttributeValue(path.node);
  159. jsxAttribute.literal = (0, _util.isNumeric)(jsxAttribute.value);
  160. path.replace(jsxAttribute);
  161. }
  162. },
  163. HTMLComment: {
  164. enter(path) {
  165. const jsxComment = new _JSXComment.default();
  166. jsxComment.text = path.node.textContent.trim();
  167. path.replace(jsxComment);
  168. }
  169. },
  170. HTMLText: {
  171. enter(path) {
  172. const jsxText = new _JSXText.default();
  173. jsxText.text = path.node.textContent.trim();
  174. path.replace(jsxText);
  175. }
  176. }
  177. };
  178. exports.default = _default;