cuenti-dna 0.1.1-beta.2 → 0.1.1-beta.4

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/README.md CHANGED
@@ -23,9 +23,13 @@ pnpm add cuenti-dna@beta
23
23
 
24
24
  Cuando publiques una version estable, podras instalar con `@latest`.
25
25
 
26
- ### Inicializacion interactiva (estilo shadcn)
26
+ ### Inicializacion de estilos
27
27
 
28
- Al instalar `cuenti-dna` en una terminal interactiva, se abre automaticamente un asistente (wizard) para configurar estilos.
28
+ Durante la instalacion (`postinstall`):
29
+
30
+ - En terminal interactiva, se abre automaticamente un asistente (wizard) para configurar estilos.
31
+ - En entorno no interactivo, se intenta configurar automaticamente el primer archivo CSS detectado (por ejemplo `app/globals.css`, `src/index.css`, `src/main.css`, etc.).
32
+ - Si no se detecta un archivo CSS conocido, se muestra un mensaje de fallback para importar `cuenti-dna/styles.css` o ejecutar `init` manualmente.
29
33
 
30
34
  Tambien puedes ejecutarlo manualmente cuando quieras:
31
35
 
@@ -51,6 +55,8 @@ Este asistente:
51
55
  - Inserta un bloque gestionado por Cuenti y deja el contenido original del usuario al final.
52
56
  - Si hay colisiones de variables, pregunta si deseas sobrescribir.
53
57
 
58
+ Nota: `init` es opcional. Su objetivo es exponer tokens/variables en tu CSS para estilos propios del consumidor.
59
+
54
60
  Opciones utiles:
55
61
 
56
62
  ```bash
@@ -78,7 +84,9 @@ Importa los componentes desde el paquete:
78
84
  import { Input, Button } from 'cuenti-dna'
79
85
  ```
80
86
 
81
- Importa los estilos globales una sola vez en tu app (por ejemplo en el entrypoint):
87
+ Al importar `cuenti-dna`, la libreria inyecta automaticamente su `styles.css` compilado en runtime del navegador.
88
+
89
+ Si prefieres carga explicita (por ejemplo por politicas CSP o control manual), puedes importar los estilos en tu entrypoint:
82
90
 
83
91
  ```tsx
84
92
  import 'cuenti-dna/styles.css'
package/dist/index.cjs CHANGED
@@ -56,6 +56,47 @@ __export(index_exports, {
56
56
  });
57
57
  module.exports = __toCommonJS(index_exports);
58
58
 
59
+ // src/lib/runtime-styles.ts
60
+ var import_meta = {};
61
+ var STYLE_LINK_ID = "cuenti-dna-runtime-styles";
62
+ var canInjectStyles = () => typeof window !== "undefined" && typeof document !== "undefined";
63
+ var toFileHref = (filePath) => new URL(`file://${filePath.replace(/\\/g, "/")}`).href;
64
+ var resolveStylesHrefFromImportMeta = () => {
65
+ try {
66
+ return new URL("./styles.css", import_meta.url).href;
67
+ } catch {
68
+ return null;
69
+ }
70
+ };
71
+ var resolveStylesHrefFromCommonJsFilename = () => {
72
+ if (typeof __filename !== "string") {
73
+ return null;
74
+ }
75
+ try {
76
+ return new URL("./styles.css", toFileHref(__filename)).href;
77
+ } catch {
78
+ return null;
79
+ }
80
+ };
81
+ var resolveStylesHref = () => resolveStylesHrefFromImportMeta() ?? resolveStylesHrefFromCommonJsFilename();
82
+ var injectStylesheet = (href) => {
83
+ if (document.getElementById(STYLE_LINK_ID)) {
84
+ return;
85
+ }
86
+ const link = document.createElement("link");
87
+ link.id = STYLE_LINK_ID;
88
+ link.rel = "stylesheet";
89
+ link.href = href;
90
+ link.setAttribute("data-cuenti-dna", "runtime");
91
+ document.head.appendChild(link);
92
+ };
93
+ if (canInjectStyles()) {
94
+ const href = resolveStylesHref();
95
+ if (href) {
96
+ injectStylesheet(href);
97
+ }
98
+ }
99
+
59
100
  // src/components/forms/form.tsx
60
101
  var import_jsx_runtime = require("react/jsx-runtime");
61
102
  function Form({ children, ...props }) {