@micazoyolli/foundation 0.3.0 → 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
@@ -1,91 +1,81 @@
1
1
  # @micazoyolli/foundation
2
2
 
3
- Fundamentos compartidos no visuales para los proyectos de Micazoyolli.
3
+ [![npm version](https://img.shields.io/npm/v/@micazoyolli/foundation.svg)](https://www.npmjs.com/package/@micazoyolli/foundation)
4
+ [![license](https://img.shields.io/npm/l/@micazoyolli/foundation.svg)](./LICENSE)
4
5
 
5
- `@micazoyolli/foundation` centraliza utilidades pequenas y estables que ya se repiten entre repos independientes: tokens SCSS base, mixins responsive, helpers TypeScript, accesibilidad ligera y utilidades SEO/build. No incluye React, componentes visuales, tokens de marca, layouts ni metadata especifica de ningun proyecto.
6
+ Fundamentos frontend no visuales para construir repos independientes con una base técnica consistente.
6
7
 
7
- ## Instalacion
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
+
10
+ ## Documentation
11
+
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
+
14
+ ## Features
15
+
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
8
25
 
9
26
  ```bash
10
27
  yarn add @micazoyolli/foundation
11
28
  ```
12
29
 
13
- ## Entrypoints
14
-
15
- TypeScript:
30
+ ## TypeScript
16
31
 
17
32
  ```ts
18
33
  import { cx, getCanonicalUrl } from '@micazoyolli/foundation';
34
+
35
+ const className = cx('card', isActive && 'card--active');
36
+ const canonical = getCanonicalUrl('https://example.com', '/contacto');
19
37
  ```
20
38
 
21
- SCSS:
39
+ ## SCSS
22
40
 
23
41
  ```scss
24
42
  @use '@micazoyolli/foundation/scss' as foundation;
25
- ```
26
-
27
- ## Documentacion
28
-
29
- ### Primeros pasos
30
-
31
- - [Getting Started](./docs/getting-started.md)
32
- - [Installation](./docs/installation.md)
33
43
 
34
- ### SCSS
44
+ .section {
45
+ padding-block: foundation.$space-6;
35
46
 
36
- - [Breakpoints](./docs/scss/breakpoints.md)
37
- - [Spacing](./docs/scss/spacing.md)
38
- - [Motion](./docs/scss/motion.md)
39
- - [Mixins](./docs/scss/mixins.md)
40
-
41
- ### TypeScript
42
-
43
- - [DOM y accesibilidad](./docs/typescript/dom.md)
44
- - [SEO y build](./docs/typescript/seo.md)
45
- - [Utils](./docs/typescript/utils.md)
47
+ @include foundation.down(foundation.$breakpoint-md) {
48
+ padding-block: foundation.$space-4;
49
+ }
50
+ }
51
+ ```
46
52
 
47
- ### Proyecto
53
+ ## Compatibilidad
48
54
 
49
- - [Changelog](./docs/changelog.md)
50
- - [Roadmap](./docs/roadmap.md)
55
+ Foundation es framework agnostic y puede usarse con React, Next.js, Vue, Angular, Astro, Vite y Node según el helper utilizado.
51
56
 
52
- ## Que incluye
57
+ ## Resources
53
58
 
54
- - Tokens SCSS base para spacing, radius, z-index, motion y breakpoints.
55
- - Mixins SCSS para responsive y reduced motion.
56
- - `cx` para composicion simple de clases.
57
- - Guards TypeScript pequenos.
58
- - Helpers DOM/a11y para targets, teclado y media protegida.
59
- - Helpers DOM/a11y para foco, scroll lock, Escape y focus trap.
60
- - Helpers SEO/build para escaping, canonical, sitemap, metadata DOM y HTML estatico.
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)
61
62
 
62
- ## Que NO incluye
63
+ ## Ecosistema
63
64
 
64
- - Componentes React.
65
- - Botones, cards, layouts o grids visuales.
66
- - Tokens finales de marca, color o tipografia.
67
- - Metadata especifica de proyectos.
68
- - Logica de negocio.
69
- - Dependencias UI pesadas.
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.
70
66
 
71
67
  ## Scripts
72
68
 
73
69
  ```bash
74
- yarn install
75
70
  yarn build
76
- yarn clean
77
- yarn prepack
71
+ yarn test
72
+ yarn docs:build
78
73
  ```
79
74
 
80
- ## Proyectos que ya lo consumen
75
+ ## Autoría
81
76
 
82
- - TeInvitaASu Invitaciones
83
- - TeInvitaASu.Party
84
- - Micazoyolli
85
- - Estilo Natura
86
- - OhMamaMXX
87
- - WTFashion
77
+ Una creación de [`<micazoyolli />`](https://nadia.dev)
88
78
 
89
- ## Autora
79
+ ## Licencia
90
80
 
91
- 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.0",
4
- "description": "Fundamentos compartidos no visuales para los proyectos de Micazoyolli.",
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": {
@@ -25,11 +45,16 @@
25
45
  "build": "tsc -p tsconfig.json && yarn copy-scss",
26
46
  "clean": "rm -rf dist",
27
47
  "copy-scss": "rsync -av --include='*/' --include='*.scss' --exclude='*' src/scss/ dist/scss/",
48
+ "docs:build": "vitepress build docs",
49
+ "docs:dev": "vitepress dev docs --host 0.0.0.0",
50
+ "docs:preview": "vitepress preview docs --host 0.0.0.0",
28
51
  "prepack": "yarn build",
29
52
  "test": "yarn build && node --test tests/*.test.mjs"
30
53
  },
31
54
  "devDependencies": {
32
- "typescript": "6.0.3"
55
+ "sass-embedded": "^1.100.0",
56
+ "typescript": "6.0.3",
57
+ "vitepress": "^1.6.4"
33
58
  },
34
59
  "packageManager": "yarn@1.22.22"
35
60
  }