UNPKG

@es-js/eshtml

Version:

EsHTML: HTML en Español

227 lines (208 loc) 8.21 kB
'use strict'; const utils = require('@es-js/core/utils'); var dist = {}; var isJson = isJSON; isJSON.strict = strict; function isJSON (str, pass_object) { if (pass_object && isObject(str)) return true; if (!isString(str)) return false; str = str.replace(/\s/g, '').replace(/\n|\r/, ''); if (/^\{(.*?)\}$/.test(str)) return /"(.*?)":(.*?)/g.test(str); if (/^\[(.*?)\]$/.test(str)) { return str.replace(/^\[/, '') .replace(/\]$/, '') .replace(/},{/g, '}\n{') .split(/\n/) .map(function (s) { return isJSON(s); }) .reduce(function (prev, curr) { return !!curr; }); } return false; } function strict (str) { if (isObject(str)) { return true; } try { return JSON.parse(str) && true; } catch (ex) { return false; } } function isString (x) { return Object.prototype.toString.call(x) === '[object String]'; } function isObject (obj) { return Object.prototype.toString.call(obj) === '[object Object]'; } Object.defineProperty(dist, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var I=Object.defineProperty,U=Object.defineProperties;var _=Object.getOwnPropertyDescriptors;var N=Object.getOwnPropertySymbols;var j=Object.prototype.hasOwnProperty,v=Object.prototype.propertyIsEnumerable;var g=(o,r,n)=>r in o?I(o,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):o[r]=n,b=(o,r)=>{for(var n in r||(r={}))j.call(r,n)&&g(o,n,r[n]);if(N)for(var n of N(r))v.call(r,n)&&g(o,n,r[n]);return o},R=(o,r)=>U(o,_(r));var _isjson = isJson; var _isjson2 = _interopRequireDefault(_isjson);var $;(function(s){s[s.Smart=0]="Smart",s[s.Single=1]="Single",s[s.Double=2]="Double";})($||($= dist.quoteStyleEnum ={}));var d;(function(c){c.tag="tag",c.slash="slash",c.default="default",c.closeAs="closeAs";})(d||(d= dist.closingSingleTagOptionEnum ={}));var i;(function(s){s.tag="tag",s.slash="slash",s.default="default";})(i||(i= dist.closingSingleTagTypeEnum ={}));var y=["area","base","br","col","command","embed","hr","img","input","keygen","link","menuitem","meta","param","source","track","wbr"],L=/[\t\n\f\r "'`=<>]/,B={closingSingleTag:void 0,quoteAllAttributes:!0,replaceQuote:!0,quoteStyle:2};function q(o,r={}){var x;let n=y;r.singleTags&&(n=[...new Set([...y,...r.singleTags])]),r=R(b(b({},B),r),{singleTags:n});let{singleTags:s,closingSingleTag:c,quoteAllAttributes:k,replaceQuote:Q,quoteStyle:p}=r,h=(x=s==null?void 0:s.filter(a=>a instanceof RegExp))!=null?x:[];return Array.isArray(o)||(o||(o=""),o=[o]),u(o);function u(a){let t="";for(let e of a){if(e===!1||e===void 0||e===null||typeof e=="string"&&e.length===0||Number.isNaN(e))continue;if(Array.isArray(e)){if(e.length===0)continue;t+=u(e);continue}if(typeof e=="string"||typeof e=="number"){t+=e;continue}if(Array.isArray(e.content)||(e.content||(e.content=""),e.content=[e.content]),e.tag===!1){t+=u(e.content);continue}let f=typeof e.tag=="string"?e.tag:"div";t+=`<${f}`,e.attrs&&(t+=w(e.attrs));let l={[i.tag]:`></${f}>`,[i.slash]:" />",[i.default]:">"};if(m(f)){switch(c){case d.tag:t+=l[i.tag];break;case d.slash:t+=l[i.slash];break;case d.closeAs:t+=l[e.closeAs?i[e.closeAs]:i.default];break;default:t+=l[i.default];}e.content&&(t+=u(e.content));}else if(c===d.closeAs&&e.closeAs){let D=e.closeAs?i[e.closeAs]:i.default;t+=`${l[D]}${u(e.content)}`;}else t+=`>${u(e.content)}</${f}>`;}return t}function m(a){return h.length>0?h.some(t=>t.test(a)):!!(s==null?void 0:s.includes(a.toLowerCase()))}function w(a){let t="";for(let[e,f]of Object.entries(a))if(typeof f=="string")if(_isjson2.default.call(void 0, f))t+=A(e,f);else if(k||L.test(f)){let l=f;Q&&(l=f.replace(/"/g,"&quot;")),t+=A(e,l,p);}else f===""?t+=` ${e}`:t+=` ${e}=${f}`;else f===!0?t+=` ${e}`:typeof f=="number"&&(t+=A(e,f,p));return t}function A(a,t,e=1){return e===1?` ${a}='${t}'`:e===2?` ${a}="${t}"`:typeof t=="string"&&t.includes('"')?` ${a}='${t}'`:` ${a}="${t}"`}}dist.closingSingleTagOptionEnum = d; dist.closingSingleTagTypeEnum = i; dist.quoteStyleEnum = $; var render$1 = dist.render = q; const dictionary$1 = /* @__PURE__ */ new Map([ // Document Structure ["html", "eshtml"], ["head", "cabecera"], ["body", "cuerpo"], ["title", "titulo"], // Metadata Elements ["base", "base"], ["link", "recurso"], ["meta", "meta"], ["style", "estilo"], // Sectioning Content ["address", "direccion"], ["article", "articulo"], ["aside", "lateral"], ["footer", "pie-pagina"], ["header", "encabezado"], ["h1", "t1"], ["h2", "t2"], ["h3", "t3"], ["h4", "t4"], ["h5", "t5"], ["h6", "t6"], ["hgroup", "grupo-encabezados"], ["main", "principal"], ["nav", "navegacion"], ["section", "seccion"], // Text Content ["blockquote", "cita-bloque"], ["dd", "definicion-descripcion"], ["div", "division"], ["dl", "lista-definiciones"], ["dt", "termino-definicion"], ["figcaption", "figura-leyenda"], ["figure", "figura"], ["hr", "linea-horizontal"], ["li", "lista-elemento"], ["ol", "lista-ordenada"], ["p", "parrafo"], ["pre", "preformateado"], ["ul", "lista-desordenada"], // Inline Text Semantics ["a", "enlace"], ["abbr", "abreviatura"], ["b", "negrita"], ["bdi", "aislamiento-direccion-texto"], ["bdo", "anulacion-direccion-texto"], ["br", "salto-linea"], ["cite", "cita"], ["code", "codigo-bloque"], ["data", "datos"], ["dfn", "definicion"], ["em", "enfasis"], ["i", "cursiva"], ["kbd", "tecla"], ["mark", "marcado"], ["q", "cita-corta"], ["rp", "rp"], ["rt", "rt"], ["ruby", "ruby"], ["s", "tachado"], ["samp", "muestra"], ["small", "peque\xF1o"], ["span", "segmento"], ["strong", "fuerte"], ["sub", "subindice"], ["sup", "superindice"], ["time", "hora"], ["u", "subrayado"], ["var", "variable"], ["wbr", "salto-linea-opcional"], // Multimedia Elements ["area", "area"], ["audio", "audio"], ["img", "imagen"], ["map", "mapa"], ["track", "pista"], ["video", "video"], // Embedded Content ["embed", "incrustar"], ["iframe", "marco-integrado"], ["object", "objeto"], ["param", "parametro"], ["picture", "imagen-adaptativa"], ["source", "origen"], // Scripting Elements ["canvas", "canvas"], ["noscript", "sin-codigo"], ["script", "codigo"], // Table Elements ["caption", "tabla-leyenda"], ["col", "columna"], ["colgroup", "grupo-columnas"], ["table", "tabla"], ["tbody", "tabla-cuerpo"], ["td", "tabla-celda"], ["tfoot", "tabla-pie"], ["th", "tabla-celda-encabezado"], ["thead", "tabla-encabezado"], ["tr", "tabla-fila"], // Form Elements ["button", "boton"], ["datalist", "lista-datos"], ["fieldset", "conjunto-campos"], ["form", "formulario"], ["input", "entrada"], ["label", "etiqueta"], ["legend", "leyenda"], ["meter", "medidor"], ["optgroup", "grupo-opciones"], ["option", "opcion"], ["output", "salida"], ["progress", "progreso"], ["select", "seleccion"], ["textarea", "area-texto"], // Interactive Elements ["menu", "menu"], ["details", "detalles"], ["dialog", "dialogo"], ["summary", "resumen"], // Web Components ["template", "plantilla"], ["slot", "ranura"], // SVG and Math ["svg", "grafico-vectorial"] // Deprecated (No soportadas en HTML5 o reemplazadas) // ['acronimo', 'acronym'], // ['applet', 'applet'], // ['base-fuente', 'basefont'], // ['grande', 'big'], // ['centrar', 'center'], // ['directorio', 'dir'], // ['fuente', 'font'], // ['marco', 'frame'], // ['conjunto-marcos', 'frameset'], // ['sin-marcos', 'noframes'], // ['teletipo', 'tt'], ]); function getDictionary(inverted = false) { if (!inverted) { return utils.invertMap(dictionary$1); } return dictionary$1; } const dictionary = getDictionary(true); function render(tree) { return render$1(tree, { singleTags: [ "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "menuitem", "meta", "param", "source", "track", "wbr" ].map((tag) => dictionary.get(tag) || tag) }); } exports.getDictionary = getDictionary; exports.render = render;