diff --git a/.gitignore b/.gitignore index 1002d97..0c8de3a 100644 --- a/.gitignore +++ b/.gitignore @@ -53,3 +53,4 @@ pnpm-lock.yaml .cofoundy/state/history.jsonl .cofoundy/state/**/worker-id* .cofoundy/state/**/*.lock +node_modules diff --git a/.storybook/main.ts b/.storybook/main.ts index b28e10f..dbe4909 100644 --- a/.storybook/main.ts +++ b/.storybook/main.ts @@ -7,6 +7,8 @@ const config: StorybookConfig = { '@storybook/addon-essentials', '@storybook/addon-interactions', ], + // Lockups de Cofoundy Identity → https://ui.cofoundy.dev/brand/identity/.svg (Casdoor los usa como logo). + staticDirs: [{ from: '../src/assets/brand/identity', to: '/brand/identity' }], framework: { name: '@storybook/react-vite', options: {}, diff --git a/CLAUDE.md b/CLAUDE.md index a82667e..4cf44cc 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -17,6 +17,10 @@ npm test # Run tests npm run test:watch # Watch mode npm run test:coverage # Coverage report +# Lockup de cada app de Cofoundy Identity (id.cofoundy.dev): una línea en +# src/assets/brand/identity/apps.json → SVG en ui.cofoundy.dev/brand/identity/.svg +npm run gen:lockups # verify:lockups en CI + # Build IIFE (standalone widget) npm run build:iife diff --git a/package.json b/package.json index 1e529e3..7450766 100644 --- a/package.json +++ b/package.json @@ -101,7 +101,7 @@ "test:watch": "vitest", "test:coverage": "vitest run --coverage", "storybook": "storybook dev -p 6006", - "build-storybook": "storybook build", + "build-storybook": "npm run verify:lockups && storybook build", "build:iife": "vite build --config vite.config.iife.ts", "build:iife:watch": "vite build --config vite.config.iife.ts --watch", "build:ds": "vite build -c vite.config.ds.ts && vite build -c vite.config.ds.ts --mode react && vite build -c vite.config.ds.ts --mode react-dom", @@ -109,6 +109,8 @@ "gen:agents": "tsx scripts/gen-atelier-agents-md.ts", "verify:agents": "tsx scripts/gen-atelier-agents-md.ts --check", "gen:springs": "tsx scripts/gen-spring-tokens.ts", - "verify:springs": "tsx scripts/gen-spring-tokens.ts --check" + "verify:springs": "tsx scripts/gen-spring-tokens.ts --check", + "gen:lockups": "tsx scripts/gen-identity-lockups.ts", + "verify:lockups": "tsx scripts/gen-identity-lockups.ts --check" } } diff --git a/scripts/fonts/OFL-space-grotesk.txt b/scripts/fonts/OFL-space-grotesk.txt new file mode 100644 index 0000000..d5666d7 --- /dev/null +++ b/scripts/fonts/OFL-space-grotesk.txt @@ -0,0 +1,93 @@ +Copyright 2020 The Space Grotesk Project Authors (https://github.com/floriankarsten/space-grotesk) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/scripts/fonts/space-grotesk-latin-600-normal.woff b/scripts/fonts/space-grotesk-latin-600-normal.woff new file mode 100644 index 0000000..b9da83f Binary files /dev/null and b/scripts/fonts/space-grotesk-latin-600-normal.woff differ diff --git a/scripts/gen-identity-lockups.ts b/scripts/gen-identity-lockups.ts new file mode 100644 index 0000000..06de011 --- /dev/null +++ b/scripts/gen-identity-lockups.ts @@ -0,0 +1,149 @@ +/** + * Lockup de cada aplicación de Cofoundy Identity (id.cofoundy.dev): isologo + «Cofoundy Identity» + * + el nombre de la app. Una sola plantilla; el nombre es la variable (src/assets/brand/identity/apps.json). + * Escribe un SVG por app, solo con trazos (sin fuentes), en src/assets/brand/identity/.svg. + * El deploy los publica en https://ui.cofoundy.dev/brand/identity/.svg y Casdoor los usa como `logo`. + * + * npm run gen:lockups # regenera + * npm run verify:lockups # CI: falla si un SVG no coincide con la lista o un nombre no cabe + * + * Cambiar el diseño = editar LAYOUT/INK aquí y regenerar: todas las apps cambian a la vez, sin tocar Casdoor. + */ +import { readFileSync, readdirSync, writeFileSync, unlinkSync } from "node:fs"; +import { resolve } from "node:path"; +import opentype, { type Font } from "opentype.js"; + +const ROOT = resolve(import.meta.dirname, ".."); +const OUT = resolve(ROOT, "src/assets/brand/identity"); +const LIST = resolve(OUT, "apps.json"); +const ISOLOGO = resolve(ROOT, "src/assets/brand/Isologo.svg"); +const TOKENS = resolve(ROOT, "src/styles/index.css"); + +/** Medidas en unidades del viewBox (alto total 240, como el lockup PNG anterior). */ +export const LAYOUT = { + height: 240, + isologo: 240, // lado del isologo (es cuadrado) + gap: 40, // isologo → texto + line1: { size: 64, baseline: 74 }, // «Cofoundy Identity», la marca común + line2: { size: 96, baseline: 198 }, // nombre de la app: lo que distingue una tarjeta de otra + oneLine: { size: 88, baseline: 152 }, // sin nombre: «Cofoundy Identity» solo, centrado en el isologo + tracking: -0.02, // em, igual que el Wordmark (logo-header.tsx) + padRight: 8, + maxRatio: 6, // ancho/alto: más ancho se vuelve ilegible a 250 px (login) y se corta en la tarjeta de /apps +}; + +/** Tintas: el azul de «Identity» es el token --cf-primary; las otras salen de las caras del isologo. */ +function ink() { + const iso = readFileSync(ISOLOGO, "utf8"); + const css = readFileSync(TOKENS, "utf8"); + const primary = css.match(/--cf-primary:\s*(#[0-9A-Fa-f]{6})/)?.[1]; + const need = (hex: string) => { + if (!iso.includes(`fill="${hex}"`)) throw new Error(`${hex} ya no es una cara de Isologo.svg: actualiza INK`); + return hex; + }; + if (!primary) throw new Error("no encontré --cf-primary en src/styles/index.css"); + return { cofoundy: need("#103D5C"), identity: primary, app: need("#103D5C") }; +} + +const font600 = opentype.parse(toArrayBuffer(readFileSync(resolve(ROOT, "scripts/fonts/space-grotesk-latin-600-normal.woff")))); + +function toArrayBuffer(b: Buffer): ArrayBuffer { + return b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength) as ArrayBuffer; +} + +function text(font: Font, s: string, x: number, y: number, size: number, fill: string, cls = "") { + const opts = { letterSpacing: LAYOUT.tracking }; + const d = font.getPath(s, x, y, size, opts).toPathData(2); + const width = font.getAdvanceWidth(s, size, opts); + const klass = cls ? ` class="${cls}"` : ""; + return { svg: ``, width }; +} + +/** El login de Casdoor pone fondo oscuro con prefers-color-scheme: dark; la tinta navy se aclara ahí. */ +const DARK = ``; + +function esc(s: string): string { + return s.replace(/&/g, "&").replace(//g, ">").replace(/"/g, """); +} + +function isologoInner(): string { + const iso = readFileSync(ISOLOGO, "utf8"); + const inner = iso.replace(/^[\s\S]*?]*>/, "").replace(/<\/svg>\s*$/, "").trim(); + const scale = LAYOUT.isologo / 701; + return `${inner}`; +} + +export function renderLockup(name: string): string { + const c = ink(); + const x = LAYOUT.isologo + LAYOUT.gap; + const l1 = name ? LAYOUT.line1 : LAYOUT.oneLine; + const a = text(font600, "Cofoundy", x, l1.baseline, l1.size, c.cofoundy, "ink"); + const space = font600.getAdvanceWidth(" ", l1.size); + const b = text(font600, "Identity", x + a.width + space, l1.baseline, l1.size, c.identity); + const parts = [a.svg, b.svg]; + let textWidth = a.width + space + b.width; + if (name) { + const n = text(font600, name, x, LAYOUT.line2.baseline, LAYOUT.line2.size, c.app, "ink"); + parts.push(n.svg); + textWidth = Math.max(textWidth, n.width); + } + const width = Math.ceil(x + textWidth + LAYOUT.padRight); + const label = esc(name ? `Cofoundy Identity · ${name}` : "Cofoundy Identity"); + return [ + ``, + ``, + `${label}`, + DARK, + isologoInner(), + ...parts, + ``, + "", + ].join("\n"); +} + +export function readApps(): Record { + const apps = JSON.parse(readFileSync(LIST, "utf8")).apps as Record; + for (const slug of Object.keys(apps)) { + if (!/^[a-z0-9-]+$/.test(slug)) throw new Error(`slug inválido: «${slug}» (solo a-z, 0-9 y guiones: va en la URL)`); + } + return apps; +} + +function main() { + const check = process.argv.includes("--check"); + const apps = readApps(); + const problems: string[] = []; + const expected = new Set(); + for (const [slug, name] of Object.entries(apps)) { + const svg = renderLockup(name); + const w = Number(svg.match(/viewBox="0 0 (\d+) /)?.[1]); + if (w / LAYOUT.height > LAYOUT.maxRatio) { + problems.push(`«${name}» no cabe (${(w / LAYOUT.height).toFixed(1)}:1 > ${LAYOUT.maxRatio}:1): acórtalo`); + continue; + } + const file = resolve(OUT, `${slug}.svg`); + expected.add(`${slug}.svg`); + if (check) { + let current = ""; + try { + current = readFileSync(file, "utf8"); + } catch { + /* falta */ + } + if (current !== svg) problems.push(`${slug}.svg no coincide con apps.json: corre npm run gen:lockups`); + } else { + writeFileSync(file, svg); + } + } + for (const f of readdirSync(OUT).filter((f) => f.endsWith(".svg") && !expected.has(f))) { + if (check) problems.push(`${f} sobra (no está en apps.json)`); + else unlinkSync(resolve(OUT, f)); + } + if (problems.length) { + console.error(problems.join("\n")); + process.exit(1); + } + console.log(`${check ? "ok" : "escritos"}: ${expected.size} lockups en src/assets/brand/identity/`); +} + +if (import.meta.url === `file://${process.argv[1]}`) main(); diff --git a/scripts/text-to-svg.cjs b/scripts/text-to-svg.cjs deleted file mode 100644 index 70c1f23..0000000 --- a/scripts/text-to-svg.cjs +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Convert text to SVG paths using a font file - * - * Usage: - * 1. Download font file (e.g., Recoleta-Bold.otf) - * 2. Place it in this directory - * 3. Run: node text-to-svg.js - * - * Dependencies: npm install opentype.js - */ - -const opentype = require('opentype.js'); -const fs = require('fs'); -const path = require('path'); - -// Configuration -const CONFIG = { - text: 'Cofoundy', - fontFile: '/Users/styreep/cofoundy/cotizations/resources/fonts/recoleta/Recoleta Regular.otf', - fontSize: 72, - outputFile: 'cofoundy-wordmark.svg', -}; - -async function textToSvg() { - const fontPath = CONFIG.fontFile.startsWith('/') ? CONFIG.fontFile : path.join(__dirname, CONFIG.fontFile); - - // Check if font file exists - if (!fs.existsSync(fontPath)) { - console.error(`\n❌ Font file not found: ${CONFIG.fontFile}`); - console.log('\nTo use this script:'); - console.log('1. Download Recoleta font from https://www.type.network/fonts/recoleta'); - console.log(' (They offer a free trial)'); - console.log(`2. Place the .otf or .ttf file in: ${__dirname}`); - console.log(`3. Update CONFIG.fontFile if the filename is different`); - console.log('4. Run this script again\n'); - process.exit(1); - } - - try { - // Load the font - const font = await opentype.load(fontPath); - - // Create path from text - const textPath = font.getPath(CONFIG.text, 0, CONFIG.fontSize, CONFIG.fontSize); - - // Get bounding box - const bbox = textPath.getBoundingBox(); - const width = Math.ceil(bbox.x2 - bbox.x1); - const height = Math.ceil(bbox.y2 - bbox.y1); - - // Generate SVG - const svg = ` - -`; - - // Also generate a version with the brand color - const svgBrand = ` - -`; - - // Save files - const outputPath = path.join(__dirname, CONFIG.outputFile); - const outputPathBrand = path.join(__dirname, CONFIG.outputFile.replace('.svg', '-brand.svg')); - - fs.writeFileSync(outputPath, svg); - fs.writeFileSync(outputPathBrand, svgBrand); - - console.log('\n✅ SVG wordmarks generated!'); - console.log(` ${outputPath} (currentColor)`); - console.log(` ${outputPathBrand} (brand blue)`); - console.log(`\n Size: ${width}x${height}px`); - console.log(` Font: ${font.names.fullName.en}`); - - } catch (error) { - console.error('Error:', error.message); - process.exit(1); - } -} - -textToSvg(); diff --git a/src/__tests__/identity-lockups.test.ts b/src/__tests__/identity-lockups.test.ts new file mode 100644 index 0000000..bad6678 --- /dev/null +++ b/src/__tests__/identity-lockups.test.ts @@ -0,0 +1,32 @@ +import { describe, expect, it } from "vitest"; +import { LAYOUT, readApps, renderLockup } from "../../scripts/gen-identity-lockups"; + +const ratio = (svg: string) => Number(svg.match(/viewBox="0 0 (\d+) /)?.[1]) / LAYOUT.height; + +describe("lockups de Cofoundy Identity", () => { + it("cada app de la lista cabe y lleva su nombre como texto accesible", () => { + for (const [, name] of Object.entries(readApps())) { + const svg = renderLockup(name); + expect(ratio(svg)).toBeLessThanOrEqual(LAYOUT.maxRatio); + expect(svg).toContain(name ? `Cofoundy Identity · ${name}` : "Cofoundy Identity"); + expect(svg).not.toMatch(/ { + expect(ratio(renderLockup("x".repeat(80)))).toBeGreaterThan(LAYOUT.maxRatio); + }); + + it("sin nombre: solo «Cofoundy Identity», sin segunda línea", () => { + const svg = renderLockup(""); + expect(svg).toContain('aria-label="Cofoundy Identity"'); + expect(svg.split("\n").filter((l) => /^ { + const svg = renderLockup("A & B"); + expect(svg).toContain("prefers-color-scheme: dark"); + expect(svg.match(/class="ink"/g)?.length).toBe(2); // «Cofoundy» + el nombre + expect(svg).toContain('aria-label="Cofoundy Identity · A & B"'); + }); +}); diff --git a/src/assets/brand/identity/apps.json b/src/assets/brand/identity/apps.json new file mode 100644 index 0000000..435ac5a --- /dev/null +++ b/src/assets/brand/identity/apps.json @@ -0,0 +1,14 @@ +{ + "$comment": "Marca de cada aplicación en Cofoundy Identity (id.cofoundy.dev). Cambiar un nombre o agregar una app = una línea aquí + `npm run gen:lockups`. El diseño vive en scripts/gen-identity-lockups.ts. Se publica en https://ui.cofoundy.dev/brand/identity/.svg", + "apps": { + "identity": "", + "oficina": "Oficina Virtual", + "basalt": "Basalt", + "basalt-ia": "Basalt · Conector IA", + "forms": "Forms", + "forms-ia": "Forms · Conector IA", + "gateway": "Gateway", + "gateway-ia": "Bóveda · Conector IA", + "motor-comercial": "Motor Comercial" + } +} diff --git a/src/assets/brand/identity/basalt-ia.svg b/src/assets/brand/identity/basalt-ia.svg new file mode 100644 index 0000000..aed96f2 --- /dev/null +++ b/src/assets/brand/identity/basalt-ia.svg @@ -0,0 +1,18 @@ + + +Cofoundy Identity · Basalt · Conector IA + + + + + + + + + + + + + + + diff --git a/src/assets/brand/identity/basalt.svg b/src/assets/brand/identity/basalt.svg new file mode 100644 index 0000000..d06066d --- /dev/null +++ b/src/assets/brand/identity/basalt.svg @@ -0,0 +1,18 @@ + + +Cofoundy Identity · Basalt + + + + + + + + + + + + + + + diff --git a/src/assets/brand/identity/forms-ia.svg b/src/assets/brand/identity/forms-ia.svg new file mode 100644 index 0000000..1302cc1 --- /dev/null +++ b/src/assets/brand/identity/forms-ia.svg @@ -0,0 +1,18 @@ + + +Cofoundy Identity · Forms · Conector IA + + + + + + + + + + + + + + + diff --git a/src/assets/brand/identity/forms.svg b/src/assets/brand/identity/forms.svg new file mode 100644 index 0000000..e86e59b --- /dev/null +++ b/src/assets/brand/identity/forms.svg @@ -0,0 +1,18 @@ + + +Cofoundy Identity · Forms + + + + + + + + + + + + + + + diff --git a/src/assets/brand/identity/gateway-ia.svg b/src/assets/brand/identity/gateway-ia.svg new file mode 100644 index 0000000..c7d47db --- /dev/null +++ b/src/assets/brand/identity/gateway-ia.svg @@ -0,0 +1,18 @@ + + +Cofoundy Identity · Bóveda · Conector IA + + + + + + + + + + + + + + + diff --git a/src/assets/brand/identity/gateway.svg b/src/assets/brand/identity/gateway.svg new file mode 100644 index 0000000..b5f105f --- /dev/null +++ b/src/assets/brand/identity/gateway.svg @@ -0,0 +1,18 @@ + + +Cofoundy Identity · Gateway + + + + + + + + + + + + + + + diff --git a/src/assets/brand/identity/identity.svg b/src/assets/brand/identity/identity.svg new file mode 100644 index 0000000..9c225e7 --- /dev/null +++ b/src/assets/brand/identity/identity.svg @@ -0,0 +1,17 @@ + + +Cofoundy Identity + + + + + + + + + + + + + + diff --git a/src/assets/brand/identity/motor-comercial.svg b/src/assets/brand/identity/motor-comercial.svg new file mode 100644 index 0000000..ff0a3f4 --- /dev/null +++ b/src/assets/brand/identity/motor-comercial.svg @@ -0,0 +1,18 @@ + + +Cofoundy Identity · Motor Comercial + + + + + + + + + + + + + + + diff --git a/src/assets/brand/identity/oficina.svg b/src/assets/brand/identity/oficina.svg new file mode 100644 index 0000000..a56443c --- /dev/null +++ b/src/assets/brand/identity/oficina.svg @@ -0,0 +1,18 @@ + + +Cofoundy Identity · Oficina Virtual + + + + + + + + + + + + + + + diff --git a/src/types/opentype.d.ts b/src/types/opentype.d.ts new file mode 100644 index 0000000..8bddfc2 --- /dev/null +++ b/src/types/opentype.d.ts @@ -0,0 +1,16 @@ +// Tipos mínimos de opentype.js (sin @types en el repo) para scripts/gen-identity-lockups.ts. +declare module "opentype.js" { + interface RenderOptions { + kerning?: boolean; + letterSpacing?: number; + } + export interface Path { + toPathData(decimalPlaces?: number): string; + } + export interface Font { + getPath(text: string, x: number, y: number, fontSize: number, options?: RenderOptions): Path; + getAdvanceWidth(text: string, fontSize: number, options?: RenderOptions): number; + } + const opentype: { parse(buffer: ArrayBuffer): Font }; + export default opentype; +}