libreria-astro-lefebvre 0.2.43 → 0.2.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "libreria-astro-lefebvre",
3
- "version": "0.2.43",
3
+ "version": "0.2.45",
4
4
  "description": "Librería de componentes Astro, React y Vue para Lefebvre",
5
5
  "author": "Equipo web desarrollo Lefebvre",
6
6
  "type": "module",
@@ -75,7 +75,7 @@ const structuredData = `<script type="application/ld+json">
75
75
  cursor-pointer border border-transparent md:border-0
76
76
  hover:bg-[rgba(107,58,8,0.08)] rounded-full ${identifier}button
77
77
  ${index === 0 ? 'active' : ''}
78
- bg-[#ebe7da] text-gray-100 max-w-10 max-h-5 text-[0px] md:w-[150px]
78
+ bg-[#ebe7da] text-gray-100 max-w-10 max-h-5 text-[0px] md:w-auto
79
79
  md:bg-transparent md:text-[#403830] md:max-w-none md:max-h-none md:text-[16px]
80
80
  `}
81
81
  >{tab.name}</button>
@@ -13,7 +13,36 @@ const allOpen = initialState === 'all-open';
13
13
  // Prefijo único por instancia para enlazar botón ↔ panel (aria-controls / aria-labelledby) sin colisionar si hay varios FAQ en la misma página.
14
14
  const uid = 'faq-' + Math.random().toString(36).substring(2, 10);
15
15
 
16
- const stripHtml = (html: string) => html.replace(/<[^>]*>/g, '');
16
+ // HTML guardado → texto plano: quita comentarios y etiquetas (saltos y bloques dejan un espacio), decodifica entidades comunes y colapsa espacios.
17
+ // Entidades con nombre: las del markup, símbolos y puntuación habituales; las vocales acentuadas, ñ y ç se componen con su marca (á, ñ, ü…).
18
+ const entities: Record<string, string> = {
19
+ nbsp: ' ', lt: '<', gt: '>', quot: '"', apos: "'", amp: '&',
20
+ iexcl: '¡', iquest: '¿', laquo: '«', raquo: '»', euro: '€', copy: '©', reg: '®', deg: '°', ordm: 'º', ordf: 'ª', sect: '§', middot: '·', szlig: 'ß',
21
+ ndash: '–', mdash: '—', hellip: '…', lsquo: '‘', rsquo: '’', ldquo: '“', rdquo: '”',
22
+ };
23
+ const accents: Record<string, string> = { acute: '́', grave: '̀', uml: '̈', circ: '̂', tilde: '̃', cedil: '̧' };
24
+ const namedEntity = (name: string, original: string) => {
25
+ if (Object.hasOwn(entities, name)) return entities[name];
26
+ const accented = /^([aeiouncy])(acute|grave|uml|circ|tilde|cedil)$/i.exec(name);
27
+ return accented ? (accented[1] + accents[accented[2].toLowerCase()]).normalize('NFC') : original;
28
+ };
29
+ // Referencias numéricas: 128–159 se leen como Windows-1252 (como hace el navegador); fuera de rango Unicode se deja el texto original en vez de lanzar RangeError.
30
+ const cp1252 = '€\0‚ƒ„…†‡ˆ‰Š‹Œ\0Ž\0\0‘’“”•–—˜™š›œ\0žŸ'; // 0x80–0x9F; \0 = sin asignar
31
+ const numericEntity = (code: number, original: string) => {
32
+ if (code >= 128 && code <= 159) return cp1252[code - 128] === '\0' ? original : cp1252[code - 128];
33
+ return code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : original;
34
+ };
35
+ const stripHtml = (html?: string | null) => String(html ?? '')
36
+ .replace(/<!--[\s\S]*?-->/g, '')
37
+ .replace(/<\/?(?:br|p|div|li|ul|ol|h[1-6])\b[^>]*>/gi, ' ')
38
+ .replace(/<[!?\/]?[a-z][^>]*>/gi, '')
39
+ .replace(/&(?:#(\d+)|#x([\da-f]+)|([a-z][a-z\d]*));/gi, (m, dec, hex, name) =>
40
+ dec ? numericEntity(+dec, m) : hex ? numericEntity(parseInt(hex, 16), m) : namedEntity(name, m))
41
+ .replace(/\s+/g, ' ')
42
+ .trim();
43
+
44
+ // El JSON-LD se inyecta con set:html: escapar "<" evita que un "</script>" (p. ej. decodificado desde &lt;/script&gt;) cierre el bloque.
45
+ const toJson = (text: string) => JSON.stringify(text).replace(/</g, '\\u003c');
17
46
 
18
47
  const structuredData = !noSchema && items.length > 0 ? `<script type="application/ld+json">
19
48
  {
@@ -22,10 +51,10 @@ const structuredData = !noSchema && items.length > 0 ? `<script type="applicatio
22
51
  "mainEntity": [
23
52
  ${items.map((item: { question: string; answer: string }) => `{
24
53
  "@type": "Question",
25
- "name": ${JSON.stringify(item.question)},
54
+ "name": ${toJson(stripHtml(item.question))},
26
55
  "acceptedAnswer": {
27
56
  "@type": "Answer",
28
- "text": ${JSON.stringify(stripHtml(item.answer))}
57
+ "text": ${toJson(stripHtml(item.answer))}
29
58
  }
30
59
  }`).join(',\n ')}
31
60
  ]
@@ -42,7 +71,7 @@ const structuredData = !noSchema && items.length > 0 ? `<script type="applicatio
42
71
  <div class="faq-item w-full flex flex-col gap-4 bg-white rounded-2xl p-6 shadow-[0_2px_4px_-2px_rgba(0,0,0,0.08),0_4px_8px_-2px_rgba(0,0,0,0.04)]">
43
72
  <h3 class="m-0 w-full">
44
73
  <button id={`${uid}-header-${index}`} aria-expanded={isOpen ? 'true' : 'false'} aria-controls={`${uid}-panel-${index}`} class="faq-toggle flex items-center gap-4 w-full cursor-pointer bg-transparent text-left">
45
- <span class="flex-1 min-w-0 font-heading text-2xl font-semibold leading-8 text-[#1b1b1b]">{item.question}</span>
74
+ <span class="flex-1 min-w-0 font-heading text-2xl font-semibold leading-8 text-[#1b1b1b]">{stripHtml(item.question)}</span>
46
75
  <svg class={`faq-arrow shrink-0 -scale-y-100 transition-transform duration-300${isOpen ? ' rotate-180' : ''}`} xmlns="http://www.w3.org/2000/svg" width="12" height="17" viewBox="0 0 12 17" fill="none">
47
76
  <path fill-rule="evenodd" clip-rule="evenodd" d="M5.81854 0.0209452C5.76196 0.0379263 5.68058 0.075179 5.6377 0.103713C5.52731 0.177114 0.11211 5.94283 0.0713747 6.03031C0.0105434 6.16092 -0.0154752 6.35561 0.00932299 6.49458C0.0418748 6.67705 0.0949975 6.78302 0.218129 6.91116C0.413508 7.1145 0.688797 7.17488 0.952965 7.07237C1.07784 7.02393 1.17979 6.91976 3.19161 4.78509L5.29941 2.54856L5.30521 9.26125L5.31102 15.974L5.37143 16.0956C5.50041 16.3553 5.72556 16.5 6.00049 16.5C6.27542 16.5 6.50057 16.3553 6.62955 16.0956L6.68996 15.974L6.69577 9.26113L6.70158 2.54832L8.80938 4.78504C10.8221 6.92094 10.9231 7.02407 11.048 7.07247C11.3123 7.17484 11.5875 7.11443 11.7829 6.91116C11.9048 6.78422 11.9591 6.677 11.9905 6.50095C12.0179 6.34771 11.9843 6.13743 11.9115 6.00629C11.8822 5.95345 10.6293 4.6055 9.12716 3.01089C6.9192 0.666875 6.37592 0.102152 6.29081 0.0624731C6.1555 -0.000599483 5.95033 -0.0186613 5.81854 0.0209452Z" fill="#d71635"/>
48
77
  </svg>