@micazoyolli/foundation 0.3.1 → 0.3.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nadia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -3,17 +3,25 @@
3
3
  [![npm version](https://img.shields.io/npm/v/@micazoyolli/foundation.svg)](https://www.npmjs.com/package/@micazoyolli/foundation)
4
4
  [![license](https://img.shields.io/npm/l/@micazoyolli/foundation.svg)](./LICENSE)
5
5
 
6
- Fundamentos frontend no visuales para construir repos independientes con una base tecnica consistente.
6
+ Fundamentos frontend no visuales para construir repos independientes con una base técnica consistente.
7
7
 
8
- Foundation centraliza mecanicas pequenas que se repiten entre proyectos: tokens SCSS base, mixins responsive, helpers TypeScript, primitivas DOM de accesibilidad y utilidades SEO/build. No incluye React, componentes visuales, tokens de marca, layouts ni metadata especifica.
8
+ Foundation centraliza mecánicas pequeñas que se repiten entre proyectos: tokens SCSS base, mixins responsive, helpers TypeScript, primitivas DOM de accesibilidad y utilidades SEO/build. No incluye React, componentes visuales, tokens de marca, layouts ni metadata específica.
9
9
 
10
- ## Documentacion
10
+ ## Documentation
11
11
 
12
- La documentacion completa esta en:
12
+ La documentación principal vive en [foundation.nadia.dev](https://foundation.nadia.dev). Ahí está la guía completa, arquitectura, ejemplos, compatibilidad y referencia de la API.
13
13
 
14
- [https://foundation.nadia.dev](https://foundation.nadia.dev)
14
+ ## Features
15
15
 
16
- ## Instalacion
16
+ - Tokens SCSS base: spacing, radius, z-index, motion y breakpoints.
17
+ - Mixins SCSS para responsive y reduced motion.
18
+ - `cx` y guards TypeScript pequeños.
19
+ - Helpers DOM para metadata client-side.
20
+ - Primitivas de accesibilidad para focus, Escape, scroll lock y media protegida.
21
+ - Helpers SEO/build para canonical, sitemap, HTML estático y escaping.
22
+ - Sin dependencias runtime pesadas y sin React.
23
+
24
+ ## Instalación
17
25
 
18
26
  ```bash
19
27
  yarn add @micazoyolli/foundation
@@ -42,19 +50,19 @@ const canonical = getCanonicalUrl('https://example.com', '/contacto');
42
50
  }
43
51
  ```
44
52
 
45
- ## Caracteristicas
53
+ ## Compatibilidad
46
54
 
47
- - Tokens SCSS base: spacing, radius, z-index, motion y breakpoints.
48
- - Mixins SCSS para responsive y reduced motion.
49
- - `cx` y guards TypeScript pequenos.
50
- - Helpers DOM para metadata client-side.
51
- - Primitivas de accesibilidad para focus, Escape, scroll lock y media protegida.
52
- - Helpers SEO/build para canonical, sitemap, HTML estatico y escaping.
53
- - Sin dependencias runtime pesadas y sin React.
55
+ Foundation es framework agnostic y puede usarse con React, Next.js, Vue, Angular, Astro, Vite y Node según el helper utilizado.
54
56
 
55
- ## Compatibilidad
57
+ ## Resources
56
58
 
57
- Foundation puede usarse con React, Next.js, Vue, Angular, Astro, Vite y scripts Node segun el tipo de helper. Los helpers DOM deben ejecutarse solo en navegador.
59
+ - Documentation: [foundation.nadia.dev](https://foundation.nadia.dev)
60
+ - GitHub: [github.com/micazoyolli/foundation](https://github.com/micazoyolli/foundation)
61
+ - npm: [npmjs.com/package/@micazoyolli/foundation](https://www.npmjs.com/package/@micazoyolli/foundation)
62
+
63
+ ## Ecosistema
64
+
65
+ Foundation forma parte del ecosistema técnico de [`<micazoyolli />`](https://nadia.dev). La librería sostiene las piezas repetibles para que cada proyecto pueda conservar su propia identidad visual, contenido y experiencia.
58
66
 
59
67
  ## Scripts
60
68
 
@@ -64,6 +72,10 @@ yarn test
64
72
  yarn docs:build
65
73
  ```
66
74
 
67
- ## Autoria
75
+ ## Autoría
76
+
77
+ Una creación de [`<micazoyolli />`](https://nadia.dev)
78
+
79
+ ## Licencia
68
80
 
69
- Una creacion de [`<micazoyolli />`](https://nadia.dev)
81
+ MIT
@@ -7,30 +7,40 @@ export const FOCUSABLE_SELECTOR = [
7
7
  'textarea:not([disabled])',
8
8
  '[tabindex]:not([tabindex="-1"])',
9
9
  ].join(',');
10
+ const getDocumentRef = (documentRef) => {
11
+ if (documentRef)
12
+ return documentRef;
13
+ if (typeof document !== 'undefined')
14
+ return document;
15
+ throw new ReferenceError('A document reference is required outside the browser.');
16
+ };
17
+ const getActiveElement = () => typeof document !== 'undefined' ? document.activeElement : undefined;
10
18
  const canReceiveFocus = (element) => !element.disabled
11
19
  && element.getAttribute('aria-hidden') !== 'true'
12
20
  && element.tabIndex !== -1;
13
21
  export const getFocusableElements = (container) => Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR)).filter(canReceiveFocus);
14
- export const lockBodyScroll = (documentRef = document) => {
15
- const previousOverflow = documentRef.body.style.overflow;
16
- documentRef.body.style.overflow = 'hidden';
22
+ export const lockBodyScroll = (documentRef) => {
23
+ const currentDocument = getDocumentRef(documentRef);
24
+ const previousOverflow = currentDocument.body.style.overflow;
25
+ currentDocument.body.style.overflow = 'hidden';
17
26
  return {
18
- document: documentRef,
27
+ document: currentDocument,
19
28
  previousOverflow,
20
29
  };
21
30
  };
22
31
  export const unlockBodyScroll = (lock) => {
23
32
  lock.document.body.style.overflow = lock.previousOverflow;
24
33
  };
25
- export const restoreFocus = (element, documentRef = document) => {
26
- if (!element || !documentRef.body.contains(element))
34
+ export const restoreFocus = (element, documentRef) => {
35
+ const currentDocument = getDocumentRef(documentRef);
36
+ if (!element || !currentDocument.body.contains(element))
27
37
  return;
28
38
  const focusable = element;
29
39
  if (typeof focusable.focus === 'function') {
30
40
  focusable.focus();
31
41
  }
32
42
  };
33
- export const trapTabKey = (event, container, activeElement = document.activeElement) => {
43
+ export const trapTabKey = (event, container, activeElement = getActiveElement()) => {
34
44
  if (event.key !== 'Tab')
35
45
  return false;
36
46
  const focusableElements = getFocusableElements(container);
@@ -1,2 +1,2 @@
1
- export const isElement = (target) => target instanceof Element;
2
- export const isHTMLElement = (target) => target instanceof HTMLElement;
1
+ export const isElement = (target) => typeof Element !== 'undefined' && target instanceof Element;
2
+ export const isHTMLElement = (target) => typeof HTMLElement !== 'undefined' && target instanceof HTMLElement;
package/dist/seo/dom.js CHANGED
@@ -1,34 +1,44 @@
1
- export const updateDocumentTitle = (title, documentRef = document) => {
2
- documentRef.title = title;
1
+ const getDocumentRef = (documentRef) => {
2
+ if (documentRef)
3
+ return documentRef;
4
+ if (typeof document !== 'undefined')
5
+ return document;
6
+ throw new ReferenceError('A document reference is required outside the browser.');
3
7
  };
4
- export const upsertMeta = (selector, attributes, documentRef = document) => {
5
- let element = documentRef.head.querySelector(selector);
8
+ export const updateDocumentTitle = (title, documentRef) => {
9
+ getDocumentRef(documentRef).title = title;
10
+ };
11
+ export const upsertMeta = (selector, attributes, documentRef) => {
12
+ const currentDocument = getDocumentRef(documentRef);
13
+ let element = currentDocument.head.querySelector(selector);
6
14
  if (!element) {
7
- element = documentRef.createElement('meta');
8
- documentRef.head.appendChild(element);
15
+ element = currentDocument.createElement('meta');
16
+ currentDocument.head.appendChild(element);
9
17
  }
10
18
  Object.entries(attributes).forEach(([name, value]) => {
11
19
  element?.setAttribute(name, value);
12
20
  });
13
21
  return element;
14
22
  };
15
- export const upsertCanonical = (href, documentRef = document) => {
16
- let element = documentRef.head.querySelector('link[rel="canonical"]');
23
+ export const upsertCanonical = (href, documentRef) => {
24
+ const currentDocument = getDocumentRef(documentRef);
25
+ let element = currentDocument.head.querySelector('link[rel="canonical"]');
17
26
  if (!element) {
18
- element = documentRef.createElement('link');
27
+ element = currentDocument.createElement('link');
19
28
  element.rel = 'canonical';
20
- documentRef.head.appendChild(element);
29
+ currentDocument.head.appendChild(element);
21
30
  }
22
31
  element.href = href;
23
32
  return element;
24
33
  };
25
- export const upsertAlternate = (hreflang, href, documentRef = document) => {
26
- let element = documentRef.head.querySelector(`link[rel="alternate"][hreflang="${hreflang}"]`);
34
+ export const upsertAlternate = (hreflang, href, documentRef) => {
35
+ const currentDocument = getDocumentRef(documentRef);
36
+ let element = currentDocument.head.querySelector(`link[rel="alternate"][hreflang="${hreflang}"]`);
27
37
  if (!element) {
28
- element = documentRef.createElement('link');
38
+ element = currentDocument.createElement('link');
29
39
  element.rel = 'alternate';
30
40
  element.hreflang = hreflang;
31
- documentRef.head.appendChild(element);
41
+ currentDocument.head.appendChild(element);
32
42
  }
33
43
  element.href = href;
34
44
  return element;
package/dist/seo/html.js CHANGED
@@ -1,5 +1,9 @@
1
+ import { escapeHtml } from './text.js';
1
2
  const escapeRegExp = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2
3
  const insertBeforeHeadEnd = (html, tag) => html.includes('</head>') ? html.replace('</head>', ` ${tag}\n </head>`) : html;
4
+ const getMetaTag = (name, content) => `<meta name="${name}" content="${escapeHtml(content)}" />`;
5
+ const getPropertyMetaTag = (property, content) => `<meta property="${property}" content="${escapeHtml(content)}" />`;
6
+ const getLinkTag = (rel, href, attributes = '') => `<link rel="${rel}"${attributes} href="${escapeHtml(href)}" />`;
3
7
  export const upsertMetaTag = (html, selector, tag) => {
4
8
  const pattern = new RegExp(`<meta\\s+${escapeRegExp(selector)}[^>]*>`);
5
9
  if (pattern.test(html)) {
@@ -16,46 +20,46 @@ export const upsertLinkTag = (html, selector, tag) => {
16
20
  };
17
21
  export const removeAlternateLinks = (html) => html.replace(/\s*<link\s+rel="alternate"\s+hreflang="[^"]+"\s+href="[^"]+"\s*\/?>\n?/g, '');
18
22
  export const getAlternateLinkTags = (alternates) => alternates
19
- .map(({ href, hreflang }) => `<link rel="alternate" hreflang="${hreflang}" href="${href}" />`)
23
+ .map(({ href, hreflang }) => getLinkTag('alternate', href, ` hreflang="${escapeHtml(hreflang)}"`))
20
24
  .join('\n ');
21
25
  export const applyHtmlMetadata = (html, metadata, alternates = []) => {
22
26
  let next = html;
23
27
  if (metadata.lang) {
24
- next = next.replace(/<html\s+lang="[^"]*">/, `<html lang="${metadata.lang}">`);
28
+ next = next.replace(/<html\s+lang="[^"]*">/, `<html lang="${escapeHtml(metadata.lang)}">`);
25
29
  }
26
30
  if (metadata.title) {
27
- next = next.replace(/<title>[\s\S]*?<\/title>/, `<title>${metadata.title}</title>`);
28
- next = upsertMetaTag(next, 'name="title"', `<meta name="title" content="${metadata.title}" />`);
29
- next = upsertMetaTag(next, 'property="og:title"', `<meta property="og:title" content="${metadata.title}" />`);
30
- next = upsertMetaTag(next, 'name="twitter:title"', `<meta name="twitter:title" content="${metadata.title}" />`);
31
+ next = next.replace(/<title>[\s\S]*?<\/title>/, `<title>${escapeHtml(metadata.title)}</title>`);
32
+ next = upsertMetaTag(next, 'name="title"', getMetaTag('title', metadata.title));
33
+ next = upsertMetaTag(next, 'property="og:title"', getPropertyMetaTag('og:title', metadata.title));
34
+ next = upsertMetaTag(next, 'name="twitter:title"', getMetaTag('twitter:title', metadata.title));
31
35
  }
32
36
  if (metadata.description) {
33
- next = upsertMetaTag(next, 'name="description"', `<meta name="description" content="${metadata.description}" />`);
34
- next = upsertMetaTag(next, 'property="og:description"', `<meta property="og:description" content="${metadata.description}" />`);
35
- next = upsertMetaTag(next, 'name="twitter:description"', `<meta name="twitter:description" content="${metadata.description}" />`);
37
+ next = upsertMetaTag(next, 'name="description"', getMetaTag('description', metadata.description));
38
+ next = upsertMetaTag(next, 'property="og:description"', getPropertyMetaTag('og:description', metadata.description));
39
+ next = upsertMetaTag(next, 'name="twitter:description"', getMetaTag('twitter:description', metadata.description));
36
40
  }
37
41
  if (metadata.canonical) {
38
- next = upsertMetaTag(next, 'property="og:url"', `<meta property="og:url" content="${metadata.canonical}" />`);
39
- next = upsertLinkTag(next, 'rel="canonical"', `<link rel="canonical" href="${metadata.canonical}" />`);
42
+ next = upsertMetaTag(next, 'property="og:url"', getPropertyMetaTag('og:url', metadata.canonical));
43
+ next = upsertLinkTag(next, 'rel="canonical"', getLinkTag('canonical', metadata.canonical));
40
44
  }
41
45
  if (metadata.image) {
42
- next = upsertMetaTag(next, 'property="og:image"', `<meta property="og:image" content="${metadata.image}" />`);
43
- next = upsertMetaTag(next, 'name="twitter:image"', `<meta name="twitter:image" content="${metadata.image}" />`);
46
+ next = upsertMetaTag(next, 'property="og:image"', getPropertyMetaTag('og:image', metadata.image));
47
+ next = upsertMetaTag(next, 'name="twitter:image"', getMetaTag('twitter:image', metadata.image));
44
48
  }
45
49
  if (metadata.robots) {
46
- next = upsertMetaTag(next, 'name="robots"', `<meta name="robots" content="${metadata.robots}" />`);
50
+ next = upsertMetaTag(next, 'name="robots"', getMetaTag('robots', metadata.robots));
47
51
  }
48
52
  if (metadata.siteName) {
49
- next = upsertMetaTag(next, 'property="og:site_name"', `<meta property="og:site_name" content="${metadata.siteName}" />`);
53
+ next = upsertMetaTag(next, 'property="og:site_name"', getPropertyMetaTag('og:site_name', metadata.siteName));
50
54
  }
51
55
  if (metadata.ogImageWidth) {
52
- next = upsertMetaTag(next, 'property="og:image:width"', `<meta property="og:image:width" content="${metadata.ogImageWidth}" />`);
56
+ next = upsertMetaTag(next, 'property="og:image:width"', getPropertyMetaTag('og:image:width', String(metadata.ogImageWidth)));
53
57
  }
54
58
  if (metadata.ogImageHeight) {
55
- next = upsertMetaTag(next, 'property="og:image:height"', `<meta property="og:image:height" content="${metadata.ogImageHeight}" />`);
59
+ next = upsertMetaTag(next, 'property="og:image:height"', getPropertyMetaTag('og:image:height', String(metadata.ogImageHeight)));
56
60
  }
57
61
  if (metadata.twitterCard) {
58
- next = upsertMetaTag(next, 'name="twitter:card"', `<meta name="twitter:card" content="${metadata.twitterCard}" />`);
62
+ next = upsertMetaTag(next, 'name="twitter:card"', getMetaTag('twitter:card', metadata.twitterCard));
59
63
  }
60
64
  if (alternates.length > 0) {
61
65
  next = removeAlternateLinks(next);
package/package.json CHANGED
@@ -1,9 +1,29 @@
1
1
  {
2
2
  "name": "@micazoyolli/foundation",
3
- "version": "0.3.1",
4
- "description": "Fundamentos frontend no visuales para el ecosistema tecnico de Nad.",
3
+ "version": "0.3.2",
4
+ "description": "Fundamentos frontend no visuales para el ecosistema técnico de Nad.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
+ "homepage": "https://foundation.nadia.dev",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/micazoyolli/foundation.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/micazoyolli/foundation/issues"
14
+ },
15
+ "keywords": [
16
+ "frontend",
17
+ "design-tokens",
18
+ "scss",
19
+ "accessibility",
20
+ "seo",
21
+ "typescript",
22
+ "vitepress"
23
+ ],
24
+ "engines": {
25
+ "node": ">=20"
26
+ },
7
27
  "main": "dist/index.js",
8
28
  "types": "dist/index.d.ts",
9
29
  "exports": {
@@ -32,6 +52,7 @@
32
52
  "test": "yarn build && node --test tests/*.test.mjs"
33
53
  },
34
54
  "devDependencies": {
55
+ "sass-embedded": "^1.100.0",
35
56
  "typescript": "6.0.3",
36
57
  "vitepress": "^1.6.4"
37
58
  },