diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 5501403..40ea103 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -26,8 +26,8 @@ jobs: - name: Assemble public site run: | mkdir -p _site - cp index.html 3d.html embed.js og-image.png favicon.svg favicon.ico apple-touch-icon.png site.webmanifest robots.txt sitemap.xml _site/ - cp -R vendor docs examples _site/ + cp index.html 3d.html embed.js diagram-styles.json diagram-styles.schema.json og-image.png favicon.svg favicon.ico apple-touch-icon.png site.webmanifest robots.txt sitemap.xml _site/ + cp -R vendor docs examples diagram-styles _site/ touch _site/.nojekyll - uses: actions/configure-pages@v5 - uses: actions/upload-pages-artifact@v3 diff --git a/3d.html b/3d.html index 0fa414d..1529160 100644 --- a/3d.html +++ b/3d.html @@ -2195,50 +2195,15 @@

Flow
Explainer

} /* ---------- diagram styles + settings (same block in index.html and 3d.html) ---------- */ -// One entry per diagram style. Add a style by copying an entry; both pages read the same fields. +// Source of truth: diagram-styles/*.json (+ pack.json, diagram-styles.schema.json). Edit a style file, then: +// npm run styles:sync // 2D uses bg/bg2, blocks, neutral, ink, edge, accent, shadow, gridOp, sw, opacity; 3D also uses mat, rough, outline, ground, grid3. // Optional: chips (flat chip look: inset top square + pins), flat (block height factor), labMono / labUpper (plain monospace capital labels). /** @typedef {{name:string,desc:string,dark?:boolean,bg:string,bg2:string,blocks:string[],neutral:string,ink:string,edge:string,edge3d:string|null,accent:string,accentFg:string,plate:string,plateFg:string,plateBd:string,on:string,onFg:string,muted:string,zone:string,zoneBd:string,chip:string,labShadow:string,shadow:string,gridOp:number,grid3:number,ground:number,mat:string,rough:number,opacity:number,outline:number,sw:number,chips?:boolean,flat?:number,labMono?:boolean,labUpper?:boolean}} DiagramStyle */ +/* ---- begin generated STYLES (from diagram-styles/; run: node tools/sync-styles.mjs) ---- */ /** @type {Record} */ -const STYLES={ - original:{name:'Original',desc:'Pastel blocks on warm paper', - bg:'#f5f0e6',bg2:'#fbf7ee',blocks:['#a9c8f5','#b6e3b1','#cdbdf6','#f7da8c','#f5b9c5','#f8c59b','#a9e0dc'],neutral:'#e6e0d2', - ink:'#1f2430',edge:'#1f2430',edge3d:null,accent:'#ee5a3a',accentFg:'#fff', - plate:'#fffdf8',plateFg:'#1f2430',plateBd:'#1f2430',on:'#1f2430',onFg:'#f5f0e6',muted:'#6b6f7b', - zone:'rgba(31,36,48,.035)',zoneBd:'rgba(31,36,48,.45)',chip:'rgba(245,240,230,.75)',labShadow:'rgba(31,36,48,.2)',shadow:'rgba(31,36,48,.10)', - gridOp:.07,grid3:.075,ground:.2,mat:'standard',rough:.6,opacity:1,outline:0,sw:1}, - teal:{name:'Teal',desc:'Teal outlines, amber highlight', - bg:'#f3f8f9',bg2:'#ffffff',blocks:['#e6f4f6','#c4e6eb','#9fd5dd','#fff1cc','#d7eef1','#b8e2e8','#e3f2ee'],neutral:'#eef2f5', - ink:'#475569',edge:'#007c90',edge3d:'#007c90',accent:'#fcaf17',accentFg:'#1f1300', - plate:'#ffffff',plateFg:'#0f172a',plateBd:'#cbd5e1',on:'#007c90',onFg:'#ffffff',muted:'#64748b', - zone:'rgba(0,124,144,.04)',zoneBd:'rgba(0,124,144,.45)',chip:'rgba(255,255,255,.85)',labShadow:'rgba(15,23,42,.08)',shadow:'rgba(15,23,42,.07)', - gridOp:.06,grid3:.06,ground:.1,mat:'standard',rough:.7,opacity:1,outline:0,sw:1}, - line:{name:'Line Art',desc:'White blocks, bold outlines', - bg:'#ffffff',bg2:'#ffffff',blocks:['#ffffff'],neutral:'#ffffff', - ink:'#0f172a',edge:'#0f172a',edge3d:'#0f172a',accent:'#007c90',accentFg:'#fff', - plate:'#ffffff',plateFg:'#0f172a',plateBd:'#0f172a',on:'#0f172a',onFg:'#ffffff',muted:'#475569', - zone:'rgba(15,23,42,.02)',zoneBd:'rgba(15,23,42,.5)',chip:'rgba(255,255,255,.9)',labShadow:'rgba(15,23,42,.15)',shadow:'rgba(15,23,42,.06)', - gridOp:.06,grid3:.06,ground:.06,mat:'toon',rough:1,opacity:1,outline:.05,sw:1.5}, - blueprint:{name:'Blueprint',desc:'Dark background, wireframe',dark:true, - bg:'#071a2e',bg2:'#0b2540',blocks:['#0e3a52'],neutral:'#0e3a52', - ink:'#5eead4',edge:'#5eead4',edge3d:'#5eead4',accent:'#fcaf17',accentFg:'#1f1300', - plate:'rgba(7,26,46,.92)',plateFg:'#ccfbf1',plateBd:'rgba(94,234,212,.55)',on:'#fcaf17',onFg:'#1f1300',muted:'#7dd3c8', - zone:'rgba(94,234,212,.05)',zoneBd:'rgba(94,234,212,.4)',chip:'rgba(7,26,46,.75)',labShadow:'rgba(0,0,0,.3)',shadow:'rgba(0,0,0,.25)', - gridOp:.12,grid3:.12,ground:0,mat:'basic',rough:1,opacity:.45,outline:0,sw:1}, - glass:{name:'Glass',desc:'See-through blocks', - bg:'#eef6f8',bg2:'#fbfeff',blocks:['#7fc9d3','#9fd5dd','#c4e6eb','#fcd27a','#b8e2e8','#a8dbe3','#d4eef2'],neutral:'#d7ecf0', - ink:'#0f4c5c',edge:'#5b9aa6',edge3d:'#ffffff',accent:'#fcaf17',accentFg:'#1f1300', - plate:'rgba(255,255,255,.85)',plateFg:'#0f172a',plateBd:'rgba(15,76,92,.3)',on:'#007c90',onFg:'#ffffff',muted:'#3b6f7b', - zone:'rgba(0,124,144,.05)',zoneBd:'rgba(0,124,144,.35)',chip:'rgba(255,255,255,.75)',labShadow:'rgba(15,23,42,.08)',shadow:'rgba(15,76,92,.10)', - gridOp:.07,grid3:.07,ground:.1,mat:'glass',rough:.15,opacity:.6,outline:0,sw:1}, - circuit:{name:'Circuit',desc:'Dark board, flat chips, thin blue lines',dark:true, - bg:'#080c17',bg2:'#0e1527',blocks:['#1a2438','#1b2a42','#172236'],neutral:'#1a2438', - ink:'#4d6a90',edge:'#7393bd',edge3d:'#86a6d0',accent:'#bfe1ff',accentFg:'#0a0e1a', - plate:'transparent',plateFg:'#c9d6e8',plateBd:'transparent',on:'rgba(191,225,255,.12)',onFg:'#ffffff',muted:'#8094ae', - zone:'rgba(115,147,189,.05)',zoneBd:'rgba(115,147,189,.35)',chip:'rgba(8,12,23,.7)',labShadow:'transparent',shadow:'rgba(0,0,0,.35)', - gridOp:.11,grid3:.11,ground:0,mat:'basic',rough:1,opacity:1,outline:0,sw:.8, - chips:true,flat:.42,labMono:true,labUpper:true} -}; +const STYLES=/** @type {Record} */(JSON.parse("{\"original\":{\"name\":\"Original\",\"desc\":\"Pastel blocks on warm paper\",\"bg\":\"#f5f0e6\",\"bg2\":\"#fbf7ee\",\"blocks\":[\"#a9c8f5\",\"#b6e3b1\",\"#cdbdf6\",\"#f7da8c\",\"#f5b9c5\",\"#f8c59b\",\"#a9e0dc\"],\"neutral\":\"#e6e0d2\",\"ink\":\"#1f2430\",\"edge\":\"#1f2430\",\"edge3d\":null,\"accent\":\"#ee5a3a\",\"accentFg\":\"#fff\",\"plate\":\"#fffdf8\",\"plateFg\":\"#1f2430\",\"plateBd\":\"#1f2430\",\"on\":\"#1f2430\",\"onFg\":\"#f5f0e6\",\"muted\":\"#6b6f7b\",\"zone\":\"rgba(31,36,48,.035)\",\"zoneBd\":\"rgba(31,36,48,.45)\",\"chip\":\"rgba(245,240,230,.75)\",\"labShadow\":\"rgba(31,36,48,.2)\",\"shadow\":\"rgba(31,36,48,.10)\",\"gridOp\":0.07,\"grid3\":0.075,\"ground\":0.2,\"mat\":\"standard\",\"rough\":0.6,\"opacity\":1,\"outline\":0,\"sw\":1},\"teal\":{\"name\":\"Teal\",\"desc\":\"Teal outlines, amber highlight\",\"bg\":\"#f3f8f9\",\"bg2\":\"#ffffff\",\"blocks\":[\"#e6f4f6\",\"#c4e6eb\",\"#9fd5dd\",\"#fff1cc\",\"#d7eef1\",\"#b8e2e8\",\"#e3f2ee\"],\"neutral\":\"#eef2f5\",\"ink\":\"#475569\",\"edge\":\"#007c90\",\"edge3d\":\"#007c90\",\"accent\":\"#fcaf17\",\"accentFg\":\"#1f1300\",\"plate\":\"#ffffff\",\"plateFg\":\"#0f172a\",\"plateBd\":\"#cbd5e1\",\"on\":\"#007c90\",\"onFg\":\"#ffffff\",\"muted\":\"#64748b\",\"zone\":\"rgba(0,124,144,.04)\",\"zoneBd\":\"rgba(0,124,144,.45)\",\"chip\":\"rgba(255,255,255,.85)\",\"labShadow\":\"rgba(15,23,42,.08)\",\"shadow\":\"rgba(15,23,42,.07)\",\"gridOp\":0.06,\"grid3\":0.06,\"ground\":0.1,\"mat\":\"standard\",\"rough\":0.7,\"opacity\":1,\"outline\":0,\"sw\":1},\"line\":{\"name\":\"Line Art\",\"desc\":\"White blocks, bold outlines\",\"bg\":\"#ffffff\",\"bg2\":\"#ffffff\",\"blocks\":[\"#ffffff\"],\"neutral\":\"#ffffff\",\"ink\":\"#0f172a\",\"edge\":\"#0f172a\",\"edge3d\":\"#0f172a\",\"accent\":\"#007c90\",\"accentFg\":\"#fff\",\"plate\":\"#ffffff\",\"plateFg\":\"#0f172a\",\"plateBd\":\"#0f172a\",\"on\":\"#0f172a\",\"onFg\":\"#ffffff\",\"muted\":\"#475569\",\"zone\":\"rgba(15,23,42,.02)\",\"zoneBd\":\"rgba(15,23,42,.5)\",\"chip\":\"rgba(255,255,255,.9)\",\"labShadow\":\"rgba(15,23,42,.15)\",\"shadow\":\"rgba(15,23,42,.06)\",\"gridOp\":0.06,\"grid3\":0.06,\"ground\":0.06,\"mat\":\"toon\",\"rough\":1,\"opacity\":1,\"outline\":0.05,\"sw\":1.5},\"blueprint\":{\"name\":\"Blueprint\",\"desc\":\"Dark background, wireframe\",\"dark\":true,\"bg\":\"#071a2e\",\"bg2\":\"#0b2540\",\"blocks\":[\"#0e3a52\"],\"neutral\":\"#0e3a52\",\"ink\":\"#5eead4\",\"edge\":\"#5eead4\",\"edge3d\":\"#5eead4\",\"accent\":\"#fcaf17\",\"accentFg\":\"#1f1300\",\"plate\":\"rgba(7,26,46,.92)\",\"plateFg\":\"#ccfbf1\",\"plateBd\":\"rgba(94,234,212,.55)\",\"on\":\"#fcaf17\",\"onFg\":\"#1f1300\",\"muted\":\"#7dd3c8\",\"zone\":\"rgba(94,234,212,.05)\",\"zoneBd\":\"rgba(94,234,212,.4)\",\"chip\":\"rgba(7,26,46,.75)\",\"labShadow\":\"rgba(0,0,0,.3)\",\"shadow\":\"rgba(0,0,0,.25)\",\"gridOp\":0.12,\"grid3\":0.12,\"ground\":0,\"mat\":\"basic\",\"rough\":1,\"opacity\":0.45,\"outline\":0,\"sw\":1},\"glass\":{\"name\":\"Glass\",\"desc\":\"See-through blocks\",\"bg\":\"#eef6f8\",\"bg2\":\"#fbfeff\",\"blocks\":[\"#7fc9d3\",\"#9fd5dd\",\"#c4e6eb\",\"#fcd27a\",\"#b8e2e8\",\"#a8dbe3\",\"#d4eef2\"],\"neutral\":\"#d7ecf0\",\"ink\":\"#0f4c5c\",\"edge\":\"#5b9aa6\",\"edge3d\":\"#ffffff\",\"accent\":\"#fcaf17\",\"accentFg\":\"#1f1300\",\"plate\":\"rgba(255,255,255,.85)\",\"plateFg\":\"#0f172a\",\"plateBd\":\"rgba(15,76,92,.3)\",\"on\":\"#007c90\",\"onFg\":\"#ffffff\",\"muted\":\"#3b6f7b\",\"zone\":\"rgba(0,124,144,.05)\",\"zoneBd\":\"rgba(0,124,144,.35)\",\"chip\":\"rgba(255,255,255,.75)\",\"labShadow\":\"rgba(15,23,42,.08)\",\"shadow\":\"rgba(15,76,92,.10)\",\"gridOp\":0.07,\"grid3\":0.07,\"ground\":0.1,\"mat\":\"glass\",\"rough\":0.15,\"opacity\":0.6,\"outline\":0,\"sw\":1},\"circuit\":{\"name\":\"Circuit\",\"desc\":\"Dark board, flat chips, thin blue lines\",\"dark\":true,\"bg\":\"#080c17\",\"bg2\":\"#0e1527\",\"blocks\":[\"#1a2438\",\"#1b2a42\",\"#172236\"],\"neutral\":\"#1a2438\",\"ink\":\"#4d6a90\",\"edge\":\"#7393bd\",\"edge3d\":\"#86a6d0\",\"accent\":\"#bfe1ff\",\"accentFg\":\"#0a0e1a\",\"plate\":\"transparent\",\"plateFg\":\"#c9d6e8\",\"plateBd\":\"transparent\",\"on\":\"rgba(191,225,255,.12)\",\"onFg\":\"#ffffff\",\"muted\":\"#8094ae\",\"zone\":\"rgba(115,147,189,.05)\",\"zoneBd\":\"rgba(115,147,189,.35)\",\"chip\":\"rgba(8,12,23,.7)\",\"labShadow\":\"transparent\",\"shadow\":\"rgba(0,0,0,.35)\",\"gridOp\":0.11,\"grid3\":0.11,\"ground\":0,\"mat\":\"basic\",\"rough\":1,\"opacity\":1,\"outline\":0,\"sw\":0.8,\"chips\":true,\"flat\":0.42,\"labMono\":true,\"labUpper\":true}}")); +/* ---- end generated STYLES ---- */ let DS=STYLES.original,DSK='original'; const UI_ICON={check:'',chev:''}; const hashStyle=()=>{const m=location.hash.match(/[#&]s=([\w-]+)/);return m&&STYLES[m[1]]?m[1]:null}; diff --git a/AGENTS.md b/AGENTS.md index 154eebf..4322413 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -13,7 +13,7 @@ Turns pasted GitHub markdown (Mermaid flowchart, sequence, state, class, ER, gan - 3D: `analyse(cam)` computes label/box screen rects analytically (must match `.lab` CSS transforms); export draws HTML labels onto the WebGL frame and crops to content; "Find a clean angle" scores 64 camera angles. `window.__fx` is a test handle. - Site look: Solution Forest colours (teal `#007c90`, amber `#fcaf17`), Inter / Raleway self-hosted in `vendor/` (OFL). UI CSS uses `--brand`, `--ink`, `--line`… tokens; diagram CSS uses only `--d-*` tokens, which `useStyle()` sets from the active diagram style. -- Diagram styles: `STYLES` (original = default and must stay pixel-identical to the old look, teal, line, blueprint, glass) in the shared block `/* ---------- diagram styles + settings` … `end of diagram styles + settings`, synced to 3d.html by `tools/sync-parser.py`. Chosen style is saved in `localStorage` `flowx.style` and added to client links as `&s=` (`#c=&s=teal`); `restyle()` in each page re-renders. 2D reads `DS.edge/ink/blocks/sw/opacity…` in `prism()`/`render()`; 3D reads `DS.mat/edge3d/outline/ground…` in `blockMat()`/`render()`. +- Diagram styles: source of truth is `diagram-styles/` (one `.json` per style + `pack.json` order; schema `diagram-styles.schema.json`, format `flow-explainer.diagram-styles`). `npm run styles:sync` rebuilds generated `diagram-styles.json` and embeds `STYLES` into pages, then `tools/sync-parser.py`. `original` = default and must stay pixel-identical to the old look. Chosen style is saved in `localStorage` `flowx.style` and added to client links as `&s=` (`#c=&s=teal`); `restyle()` in each page re-renders. 2D reads `DS.edge/ink/blocks/sw/opacity…` in `prism()`/`render()`; 3D reads `DS.mat/edge3d/outline/ground…` in `blockMat()`/`render()`. `npm run check:sync` verifies folder ↔ bundle ↔ HTML ↔ 3d.html. - UI: ⚙ Settings popover (slide-out sheet ≤820px) with diagram style + 3D/2D; Copy client link opens a popover with the privacy notes (not uploaded / not encrypted); All steps is a `
` stepper (`stepsHtml()`), folded by default on phones. Header: **New** (empty editor, `#tplNew` template via “Use template”), **Examples** select (`#exHead`, mirrors `#exSel`), brand button opens the **About** dialog (`#about`, also footer “About”). - Branding: footer of both pages shows "GitHub · MIT License · Made by Solution Forest" (Solution Forest links to https://solutionforest.net/), plus a GitHub button in the header. No SF logo. Do not add personal demo-site links to the README or repo. - Live site: https://flow-explainer.laravel.cloud/ (Laravel Cloud, deployed from `main`, served by `server.js`). Backup: https://solutionforest.github.io/flow-explainer/ (GitHub Pages via `.github/workflows/pages.yml`, public files only). SEO/social: `` of both pages has description, canonical, Open Graph + Twitter card (`og-image.png`, 1200×630, made from the README cover), JSON-LD `WebApplication`; root files `favicon.svg/.ico`, `apple-touch-icon.png`, `site.webmanifest`, `robots.txt`, `sitemap.xml` use the Cloud domain. The built-in demo keeps the descriptive ``; loaded diagrams set it to their own title. diff --git a/README.md b/README.md index 88bf571..380d98c 100644 --- a/README.md +++ b/README.md @@ -261,7 +261,12 @@ Open **⚙ Settings** to change how the diagram looks. The same style is used in | Glass | See-through blocks | | Circuit | Dark board with flat chip-shaped blocks (inset top, pins), thin steel-blue lines and plain capital labels | -Each style is one entry in the `STYLES` list in `index.html` (background, block colours, outline, highlight, label colours, and the 3D material). To add a style, copy an entry, change the values, and run `python3 tools/sync-parser.py` so `3d.html` gets it too. The site itself always uses the Solution Forest colours; only the diagram changes. +Styles live in the **[`diagram-styles/`](diagram-styles/)** folder — **one JSON file per style** (`original.json`, `teal.json`, …) plus [`pack.json`](diagram-styles/pack.json) for order. Schema: [`diagram-styles.schema.json`](diagram-styles.schema.json) (format id `flow-explainer.diagram-styles`). Root [`diagram-styles.json`](diagram-styles.json) is a **generated** bundle for publishing; do not edit it by hand. Pages embed the pack so they stay standalone (no runtime fetch). To add or edit a style: + +1. Add or edit `diagram-styles/<id>.json` and list `<id>` in `pack.json` `order` (keep `original` — it must stay pixel-identical to the old look). +2. Run `npm run styles:sync` (rebuilds the bundle, writes into `index.html`, syncs `3d.html`). + +Client links still use `&s=<id>` (e.g. `&s=teal`). Loading arbitrary custom JSON in the browser is not supported yet — this ships the file format first. The site chrome always uses Solution Forest colours; only the diagram changes. **Icons:** the emoji on the blocks (🧑 💳 🗄️ …) are **shown by default**. **⚙ Settings → Icons → Hide** turns them off for a cleaner look. The choice is saved in your browser, and a client link made while they are hidden adds `&i=0` so the client sees the same. @@ -346,6 +351,10 @@ tools/sync-parser.py Copies the shared parser and diagram styles from index.htm tools/*.mjs Code checks (extract scripts, strict type check with baseline, sync check) server.js Tiny static server used on Laravel Cloud (npm start) embed.js Standalone script-tag embed loader (GitHub Pages + Cloud) +diagram-styles/ One JSON file per style + pack.json (source of truth) +diagram-styles.json Generated style bundle (do not edit; published on Pages) +diagram-styles.schema.json JSON Schema for the pack / each style +tools/sync-styles.mjs Assembles folder → bundle + embeds into index.html (npm run styles:sync) .github/workflows/pages.yml GitHub Pages backup (public files only) docs/images/ Images used in this README ``` diff --git a/diagram-styles.json b/diagram-styles.json new file mode 100644 index 0000000..24894e8 --- /dev/null +++ b/diagram-styles.json @@ -0,0 +1,237 @@ +{ + "$schema": "./diagram-styles.schema.json", + "format": "flow-explainer.diagram-styles", + "version": 1, + "styles": { + "original": { + "name": "Original", + "desc": "Pastel blocks on warm paper", + "bg": "#f5f0e6", + "bg2": "#fbf7ee", + "blocks": [ + "#a9c8f5", + "#b6e3b1", + "#cdbdf6", + "#f7da8c", + "#f5b9c5", + "#f8c59b", + "#a9e0dc" + ], + "neutral": "#e6e0d2", + "ink": "#1f2430", + "edge": "#1f2430", + "edge3d": null, + "accent": "#ee5a3a", + "accentFg": "#fff", + "plate": "#fffdf8", + "plateFg": "#1f2430", + "plateBd": "#1f2430", + "on": "#1f2430", + "onFg": "#f5f0e6", + "muted": "#6b6f7b", + "zone": "rgba(31,36,48,.035)", + "zoneBd": "rgba(31,36,48,.45)", + "chip": "rgba(245,240,230,.75)", + "labShadow": "rgba(31,36,48,.2)", + "shadow": "rgba(31,36,48,.10)", + "gridOp": 0.07, + "grid3": 0.075, + "ground": 0.2, + "mat": "standard", + "rough": 0.6, + "opacity": 1, + "outline": 0, + "sw": 1 + }, + "teal": { + "name": "Teal", + "desc": "Teal outlines, amber highlight", + "bg": "#f3f8f9", + "bg2": "#ffffff", + "blocks": [ + "#e6f4f6", + "#c4e6eb", + "#9fd5dd", + "#fff1cc", + "#d7eef1", + "#b8e2e8", + "#e3f2ee" + ], + "neutral": "#eef2f5", + "ink": "#475569", + "edge": "#007c90", + "edge3d": "#007c90", + "accent": "#fcaf17", + "accentFg": "#1f1300", + "plate": "#ffffff", + "plateFg": "#0f172a", + "plateBd": "#cbd5e1", + "on": "#007c90", + "onFg": "#ffffff", + "muted": "#64748b", + "zone": "rgba(0,124,144,.04)", + "zoneBd": "rgba(0,124,144,.45)", + "chip": "rgba(255,255,255,.85)", + "labShadow": "rgba(15,23,42,.08)", + "shadow": "rgba(15,23,42,.07)", + "gridOp": 0.06, + "grid3": 0.06, + "ground": 0.1, + "mat": "standard", + "rough": 0.7, + "opacity": 1, + "outline": 0, + "sw": 1 + }, + "line": { + "name": "Line Art", + "desc": "White blocks, bold outlines", + "bg": "#ffffff", + "bg2": "#ffffff", + "blocks": [ + "#ffffff" + ], + "neutral": "#ffffff", + "ink": "#0f172a", + "edge": "#0f172a", + "edge3d": "#0f172a", + "accent": "#007c90", + "accentFg": "#fff", + "plate": "#ffffff", + "plateFg": "#0f172a", + "plateBd": "#0f172a", + "on": "#0f172a", + "onFg": "#ffffff", + "muted": "#475569", + "zone": "rgba(15,23,42,.02)", + "zoneBd": "rgba(15,23,42,.5)", + "chip": "rgba(255,255,255,.9)", + "labShadow": "rgba(15,23,42,.15)", + "shadow": "rgba(15,23,42,.06)", + "gridOp": 0.06, + "grid3": 0.06, + "ground": 0.06, + "mat": "toon", + "rough": 1, + "opacity": 1, + "outline": 0.05, + "sw": 1.5 + }, + "blueprint": { + "name": "Blueprint", + "desc": "Dark background, wireframe", + "dark": true, + "bg": "#071a2e", + "bg2": "#0b2540", + "blocks": [ + "#0e3a52" + ], + "neutral": "#0e3a52", + "ink": "#5eead4", + "edge": "#5eead4", + "edge3d": "#5eead4", + "accent": "#fcaf17", + "accentFg": "#1f1300", + "plate": "rgba(7,26,46,.92)", + "plateFg": "#ccfbf1", + "plateBd": "rgba(94,234,212,.55)", + "on": "#fcaf17", + "onFg": "#1f1300", + "muted": "#7dd3c8", + "zone": "rgba(94,234,212,.05)", + "zoneBd": "rgba(94,234,212,.4)", + "chip": "rgba(7,26,46,.75)", + "labShadow": "rgba(0,0,0,.3)", + "shadow": "rgba(0,0,0,.25)", + "gridOp": 0.12, + "grid3": 0.12, + "ground": 0, + "mat": "basic", + "rough": 1, + "opacity": 0.45, + "outline": 0, + "sw": 1 + }, + "glass": { + "name": "Glass", + "desc": "See-through blocks", + "bg": "#eef6f8", + "bg2": "#fbfeff", + "blocks": [ + "#7fc9d3", + "#9fd5dd", + "#c4e6eb", + "#fcd27a", + "#b8e2e8", + "#a8dbe3", + "#d4eef2" + ], + "neutral": "#d7ecf0", + "ink": "#0f4c5c", + "edge": "#5b9aa6", + "edge3d": "#ffffff", + "accent": "#fcaf17", + "accentFg": "#1f1300", + "plate": "rgba(255,255,255,.85)", + "plateFg": "#0f172a", + "plateBd": "rgba(15,76,92,.3)", + "on": "#007c90", + "onFg": "#ffffff", + "muted": "#3b6f7b", + "zone": "rgba(0,124,144,.05)", + "zoneBd": "rgba(0,124,144,.35)", + "chip": "rgba(255,255,255,.75)", + "labShadow": "rgba(15,23,42,.08)", + "shadow": "rgba(15,76,92,.10)", + "gridOp": 0.07, + "grid3": 0.07, + "ground": 0.1, + "mat": "glass", + "rough": 0.15, + "opacity": 0.6, + "outline": 0, + "sw": 1 + }, + "circuit": { + "name": "Circuit", + "desc": "Dark board, flat chips, thin blue lines", + "dark": true, + "bg": "#080c17", + "bg2": "#0e1527", + "blocks": [ + "#1a2438", + "#1b2a42", + "#172236" + ], + "neutral": "#1a2438", + "ink": "#4d6a90", + "edge": "#7393bd", + "edge3d": "#86a6d0", + "accent": "#bfe1ff", + "accentFg": "#0a0e1a", + "plate": "transparent", + "plateFg": "#c9d6e8", + "plateBd": "transparent", + "on": "rgba(191,225,255,.12)", + "onFg": "#ffffff", + "muted": "#8094ae", + "zone": "rgba(115,147,189,.05)", + "zoneBd": "rgba(115,147,189,.35)", + "chip": "rgba(8,12,23,.7)", + "labShadow": "transparent", + "shadow": "rgba(0,0,0,.35)", + "gridOp": 0.11, + "grid3": 0.11, + "ground": 0, + "mat": "basic", + "rough": 1, + "opacity": 1, + "outline": 0, + "sw": 0.8, + "chips": true, + "flat": 0.42, + "labMono": true, + "labUpper": true + } + } +} diff --git a/diagram-styles.schema.json b/diagram-styles.schema.json new file mode 100644 index 0000000..c2f8e11 --- /dev/null +++ b/diagram-styles.schema.json @@ -0,0 +1,92 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://solutionforest.github.io/flow-explainer/diagram-styles.schema.json", + "title": "Flow Explainer diagram styles", + "description": "Assembled pack of diagram palettes. Authoring source is diagram-styles/ (one file per style + pack.json); diagram-styles.json is the generated bundle. Keys are stable ids used in Settings and in client links as &s=<key>.", + "type": "object", + "additionalProperties": false, + "required": ["format", "version", "styles"], + "properties": { + "$schema": { "type": "string" }, + "format": { + "const": "flow-explainer.diagram-styles", + "description": "Format id so other tools can recognise this file." + }, + "version": { + "type": "integer", + "minimum": 1, + "description": "Schema version for the styles object (bump when fields change meaning)." + }, + "styles": { + "type": "object", + "minProperties": 1, + "propertyNames": { "pattern": "^[a-z][a-z0-9-]*$" }, + "additionalProperties": { "$ref": "#/$defs/diagramStyle" } + } + }, + "$defs": { + "color": { + "type": "string", + "description": "CSS colour: hex, rgb(a), or named (e.g. transparent)." + }, + "diagramStyle": { + "type": "object", + "additionalProperties": false, + "required": [ + "name", "desc", "bg", "bg2", "blocks", "neutral", "ink", "edge", "edge3d", + "accent", "accentFg", "plate", "plateFg", "plateBd", "on", "onFg", "muted", + "zone", "zoneBd", "chip", "labShadow", "shadow", "gridOp", "grid3", "ground", + "mat", "rough", "opacity", "outline", "sw" + ], + "properties": { + "name": { "type": "string", "minLength": 1, "description": "Label in Settings." }, + "desc": { "type": "string", "description": "Short blurb under the name." }, + "dark": { "type": "boolean", "description": "Dark diagram chrome (body.d-dark)." }, + "bg": { "$ref": "#/$defs/color" }, + "bg2": { "$ref": "#/$defs/color", "description": "Secondary / vignette fill." }, + "blocks": { + "type": "array", + "minItems": 1, + "items": { "$ref": "#/$defs/color" }, + "description": "Palette cycled for groups / ranks." + }, + "neutral": { "$ref": "#/$defs/color" }, + "ink": { "$ref": "#/$defs/color" }, + "edge": { "$ref": "#/$defs/color", "description": "2D edge stroke." }, + "edge3d": { + "type": ["string", "null"], + "description": "3D edge colour; null = derive from ink." + }, + "accent": { "$ref": "#/$defs/color" }, + "accentFg": { "$ref": "#/$defs/color" }, + "plate": { "$ref": "#/$defs/color" }, + "plateFg": { "$ref": "#/$defs/color" }, + "plateBd": { "$ref": "#/$defs/color" }, + "on": { "$ref": "#/$defs/color" }, + "onFg": { "$ref": "#/$defs/color" }, + "muted": { "$ref": "#/$defs/color" }, + "zone": { "$ref": "#/$defs/color" }, + "zoneBd": { "$ref": "#/$defs/color" }, + "chip": { "$ref": "#/$defs/color" }, + "labShadow": { "$ref": "#/$defs/color" }, + "shadow": { "$ref": "#/$defs/color" }, + "gridOp": { "type": "number", "minimum": 0, "maximum": 1 }, + "grid3": { "type": "number", "minimum": 0, "maximum": 1 }, + "ground": { "type": "number", "minimum": 0, "maximum": 1 }, + "mat": { + "type": "string", + "enum": ["standard", "toon", "basic", "glass"], + "description": "3D material preset." + }, + "rough": { "type": "number", "minimum": 0, "maximum": 1 }, + "opacity": { "type": "number", "minimum": 0, "maximum": 1 }, + "outline": { "type": "number", "minimum": 0 }, + "sw": { "type": "number", "exclusiveMinimum": 0, "description": "2D stroke width." }, + "chips": { "type": "boolean", "description": "Circuit-style chip faces + pins." }, + "flat": { "type": "number", "exclusiveMinimum": 0, "description": "Block height factor." }, + "labMono": { "type": "boolean" }, + "labUpper": { "type": "boolean" } + } + } + } +} diff --git a/diagram-styles/README.md b/diagram-styles/README.md new file mode 100644 index 0000000..b367869 --- /dev/null +++ b/diagram-styles/README.md @@ -0,0 +1,18 @@ +# Diagram styles + +One JSON file per style. Edit here, then run: + +```bash +npm run styles:sync +``` + +That rebuilds root `diagram-styles.json` (published bundle) and embeds the pack into `index.html` / `3d.html`. + +| File | Role | +|------|------| +| `pack.json` | Format id, schema version, **display order** (must include `original`) | +| `<id>.json` | One style (`original.json`, `teal.json`, …) | +| `../diagram-styles.schema.json` | JSON Schema for the pack + each style | +| `../diagram-styles.json` | Generated bundle — do not edit by hand | + +Client / embed links use `&s=<id>` (the filename without `.json`). diff --git a/diagram-styles/blueprint.json b/diagram-styles/blueprint.json new file mode 100644 index 0000000..b7f4331 --- /dev/null +++ b/diagram-styles/blueprint.json @@ -0,0 +1,36 @@ +{ + "$schema": "../diagram-styles.schema.json#/$defs/diagramStyle", + "name": "Blueprint", + "desc": "Dark background, wireframe", + "dark": true, + "bg": "#071a2e", + "bg2": "#0b2540", + "blocks": [ + "#0e3a52" + ], + "neutral": "#0e3a52", + "ink": "#5eead4", + "edge": "#5eead4", + "edge3d": "#5eead4", + "accent": "#fcaf17", + "accentFg": "#1f1300", + "plate": "rgba(7,26,46,.92)", + "plateFg": "#ccfbf1", + "plateBd": "rgba(94,234,212,.55)", + "on": "#fcaf17", + "onFg": "#1f1300", + "muted": "#7dd3c8", + "zone": "rgba(94,234,212,.05)", + "zoneBd": "rgba(94,234,212,.4)", + "chip": "rgba(7,26,46,.75)", + "labShadow": "rgba(0,0,0,.3)", + "shadow": "rgba(0,0,0,.25)", + "gridOp": 0.12, + "grid3": 0.12, + "ground": 0, + "mat": "basic", + "rough": 1, + "opacity": 0.45, + "outline": 0, + "sw": 1 +} diff --git a/diagram-styles/circuit.json b/diagram-styles/circuit.json new file mode 100644 index 0000000..2a7ef69 --- /dev/null +++ b/diagram-styles/circuit.json @@ -0,0 +1,42 @@ +{ + "$schema": "../diagram-styles.schema.json#/$defs/diagramStyle", + "name": "Circuit", + "desc": "Dark board, flat chips, thin blue lines", + "dark": true, + "bg": "#080c17", + "bg2": "#0e1527", + "blocks": [ + "#1a2438", + "#1b2a42", + "#172236" + ], + "neutral": "#1a2438", + "ink": "#4d6a90", + "edge": "#7393bd", + "edge3d": "#86a6d0", + "accent": "#bfe1ff", + "accentFg": "#0a0e1a", + "plate": "transparent", + "plateFg": "#c9d6e8", + "plateBd": "transparent", + "on": "rgba(191,225,255,.12)", + "onFg": "#ffffff", + "muted": "#8094ae", + "zone": "rgba(115,147,189,.05)", + "zoneBd": "rgba(115,147,189,.35)", + "chip": "rgba(8,12,23,.7)", + "labShadow": "transparent", + "shadow": "rgba(0,0,0,.35)", + "gridOp": 0.11, + "grid3": 0.11, + "ground": 0, + "mat": "basic", + "rough": 1, + "opacity": 1, + "outline": 0, + "sw": 0.8, + "chips": true, + "flat": 0.42, + "labMono": true, + "labUpper": true +} diff --git a/diagram-styles/glass.json b/diagram-styles/glass.json new file mode 100644 index 0000000..3326bb9 --- /dev/null +++ b/diagram-styles/glass.json @@ -0,0 +1,41 @@ +{ + "$schema": "../diagram-styles.schema.json#/$defs/diagramStyle", + "name": "Glass", + "desc": "See-through blocks", + "bg": "#eef6f8", + "bg2": "#fbfeff", + "blocks": [ + "#7fc9d3", + "#9fd5dd", + "#c4e6eb", + "#fcd27a", + "#b8e2e8", + "#a8dbe3", + "#d4eef2" + ], + "neutral": "#d7ecf0", + "ink": "#0f4c5c", + "edge": "#5b9aa6", + "edge3d": "#ffffff", + "accent": "#fcaf17", + "accentFg": "#1f1300", + "plate": "rgba(255,255,255,.85)", + "plateFg": "#0f172a", + "plateBd": "rgba(15,76,92,.3)", + "on": "#007c90", + "onFg": "#ffffff", + "muted": "#3b6f7b", + "zone": "rgba(0,124,144,.05)", + "zoneBd": "rgba(0,124,144,.35)", + "chip": "rgba(255,255,255,.75)", + "labShadow": "rgba(15,23,42,.08)", + "shadow": "rgba(15,76,92,.10)", + "gridOp": 0.07, + "grid3": 0.07, + "ground": 0.1, + "mat": "glass", + "rough": 0.15, + "opacity": 0.6, + "outline": 0, + "sw": 1 +} diff --git a/diagram-styles/line.json b/diagram-styles/line.json new file mode 100644 index 0000000..9a3f940 --- /dev/null +++ b/diagram-styles/line.json @@ -0,0 +1,35 @@ +{ + "$schema": "../diagram-styles.schema.json#/$defs/diagramStyle", + "name": "Line Art", + "desc": "White blocks, bold outlines", + "bg": "#ffffff", + "bg2": "#ffffff", + "blocks": [ + "#ffffff" + ], + "neutral": "#ffffff", + "ink": "#0f172a", + "edge": "#0f172a", + "edge3d": "#0f172a", + "accent": "#007c90", + "accentFg": "#fff", + "plate": "#ffffff", + "plateFg": "#0f172a", + "plateBd": "#0f172a", + "on": "#0f172a", + "onFg": "#ffffff", + "muted": "#475569", + "zone": "rgba(15,23,42,.02)", + "zoneBd": "rgba(15,23,42,.5)", + "chip": "rgba(255,255,255,.9)", + "labShadow": "rgba(15,23,42,.15)", + "shadow": "rgba(15,23,42,.06)", + "gridOp": 0.06, + "grid3": 0.06, + "ground": 0.06, + "mat": "toon", + "rough": 1, + "opacity": 1, + "outline": 0.05, + "sw": 1.5 +} diff --git a/diagram-styles/original.json b/diagram-styles/original.json new file mode 100644 index 0000000..aa6ed84 --- /dev/null +++ b/diagram-styles/original.json @@ -0,0 +1,41 @@ +{ + "$schema": "../diagram-styles.schema.json#/$defs/diagramStyle", + "name": "Original", + "desc": "Pastel blocks on warm paper", + "bg": "#f5f0e6", + "bg2": "#fbf7ee", + "blocks": [ + "#a9c8f5", + "#b6e3b1", + "#cdbdf6", + "#f7da8c", + "#f5b9c5", + "#f8c59b", + "#a9e0dc" + ], + "neutral": "#e6e0d2", + "ink": "#1f2430", + "edge": "#1f2430", + "edge3d": null, + "accent": "#ee5a3a", + "accentFg": "#fff", + "plate": "#fffdf8", + "plateFg": "#1f2430", + "plateBd": "#1f2430", + "on": "#1f2430", + "onFg": "#f5f0e6", + "muted": "#6b6f7b", + "zone": "rgba(31,36,48,.035)", + "zoneBd": "rgba(31,36,48,.45)", + "chip": "rgba(245,240,230,.75)", + "labShadow": "rgba(31,36,48,.2)", + "shadow": "rgba(31,36,48,.10)", + "gridOp": 0.07, + "grid3": 0.075, + "ground": 0.2, + "mat": "standard", + "rough": 0.6, + "opacity": 1, + "outline": 0, + "sw": 1 +} diff --git a/diagram-styles/pack.json b/diagram-styles/pack.json new file mode 100644 index 0000000..eaa2168 --- /dev/null +++ b/diagram-styles/pack.json @@ -0,0 +1,13 @@ +{ + "$schema": "../diagram-styles.schema.json", + "format": "flow-explainer.diagram-styles", + "version": 1, + "order": [ + "original", + "teal", + "line", + "blueprint", + "glass", + "circuit" + ] +} diff --git a/diagram-styles/teal.json b/diagram-styles/teal.json new file mode 100644 index 0000000..83fab09 --- /dev/null +++ b/diagram-styles/teal.json @@ -0,0 +1,41 @@ +{ + "$schema": "../diagram-styles.schema.json#/$defs/diagramStyle", + "name": "Teal", + "desc": "Teal outlines, amber highlight", + "bg": "#f3f8f9", + "bg2": "#ffffff", + "blocks": [ + "#e6f4f6", + "#c4e6eb", + "#9fd5dd", + "#fff1cc", + "#d7eef1", + "#b8e2e8", + "#e3f2ee" + ], + "neutral": "#eef2f5", + "ink": "#475569", + "edge": "#007c90", + "edge3d": "#007c90", + "accent": "#fcaf17", + "accentFg": "#1f1300", + "plate": "#ffffff", + "plateFg": "#0f172a", + "plateBd": "#cbd5e1", + "on": "#007c90", + "onFg": "#ffffff", + "muted": "#64748b", + "zone": "rgba(0,124,144,.04)", + "zoneBd": "rgba(0,124,144,.45)", + "chip": "rgba(255,255,255,.85)", + "labShadow": "rgba(15,23,42,.08)", + "shadow": "rgba(15,23,42,.07)", + "gridOp": 0.06, + "grid3": 0.06, + "ground": 0.1, + "mat": "standard", + "rough": 0.7, + "opacity": 1, + "outline": 0, + "sw": 1 +} diff --git a/index.html b/index.html index 78c4ed7..075e472 100644 --- a/index.html +++ b/index.html @@ -2211,50 +2211,15 @@ <h2 id="aboutTitle">Flow<br><span>Explainer</span></h2> } /* ---------- diagram styles + settings (same block in index.html and 3d.html) ---------- */ -// One entry per diagram style. Add a style by copying an entry; both pages read the same fields. +// Source of truth: diagram-styles/*.json (+ pack.json, diagram-styles.schema.json). Edit a style file, then: +// npm run styles:sync // 2D uses bg/bg2, blocks, neutral, ink, edge, accent, shadow, gridOp, sw, opacity; 3D also uses mat, rough, outline, ground, grid3. // Optional: chips (flat chip look: inset top square + pins), flat (block height factor), labMono / labUpper (plain monospace capital labels). /** @typedef {{name:string,desc:string,dark?:boolean,bg:string,bg2:string,blocks:string[],neutral:string,ink:string,edge:string,edge3d:string|null,accent:string,accentFg:string,plate:string,plateFg:string,plateBd:string,on:string,onFg:string,muted:string,zone:string,zoneBd:string,chip:string,labShadow:string,shadow:string,gridOp:number,grid3:number,ground:number,mat:string,rough:number,opacity:number,outline:number,sw:number,chips?:boolean,flat?:number,labMono?:boolean,labUpper?:boolean}} DiagramStyle */ +/* ---- begin generated STYLES (from diagram-styles/; run: node tools/sync-styles.mjs) ---- */ /** @type {Record<string,DiagramStyle>} */ -const STYLES={ - original:{name:'Original',desc:'Pastel blocks on warm paper', - bg:'#f5f0e6',bg2:'#fbf7ee',blocks:['#a9c8f5','#b6e3b1','#cdbdf6','#f7da8c','#f5b9c5','#f8c59b','#a9e0dc'],neutral:'#e6e0d2', - ink:'#1f2430',edge:'#1f2430',edge3d:null,accent:'#ee5a3a',accentFg:'#fff', - plate:'#fffdf8',plateFg:'#1f2430',plateBd:'#1f2430',on:'#1f2430',onFg:'#f5f0e6',muted:'#6b6f7b', - zone:'rgba(31,36,48,.035)',zoneBd:'rgba(31,36,48,.45)',chip:'rgba(245,240,230,.75)',labShadow:'rgba(31,36,48,.2)',shadow:'rgba(31,36,48,.10)', - gridOp:.07,grid3:.075,ground:.2,mat:'standard',rough:.6,opacity:1,outline:0,sw:1}, - teal:{name:'Teal',desc:'Teal outlines, amber highlight', - bg:'#f3f8f9',bg2:'#ffffff',blocks:['#e6f4f6','#c4e6eb','#9fd5dd','#fff1cc','#d7eef1','#b8e2e8','#e3f2ee'],neutral:'#eef2f5', - ink:'#475569',edge:'#007c90',edge3d:'#007c90',accent:'#fcaf17',accentFg:'#1f1300', - plate:'#ffffff',plateFg:'#0f172a',plateBd:'#cbd5e1',on:'#007c90',onFg:'#ffffff',muted:'#64748b', - zone:'rgba(0,124,144,.04)',zoneBd:'rgba(0,124,144,.45)',chip:'rgba(255,255,255,.85)',labShadow:'rgba(15,23,42,.08)',shadow:'rgba(15,23,42,.07)', - gridOp:.06,grid3:.06,ground:.1,mat:'standard',rough:.7,opacity:1,outline:0,sw:1}, - line:{name:'Line Art',desc:'White blocks, bold outlines', - bg:'#ffffff',bg2:'#ffffff',blocks:['#ffffff'],neutral:'#ffffff', - ink:'#0f172a',edge:'#0f172a',edge3d:'#0f172a',accent:'#007c90',accentFg:'#fff', - plate:'#ffffff',plateFg:'#0f172a',plateBd:'#0f172a',on:'#0f172a',onFg:'#ffffff',muted:'#475569', - zone:'rgba(15,23,42,.02)',zoneBd:'rgba(15,23,42,.5)',chip:'rgba(255,255,255,.9)',labShadow:'rgba(15,23,42,.15)',shadow:'rgba(15,23,42,.06)', - gridOp:.06,grid3:.06,ground:.06,mat:'toon',rough:1,opacity:1,outline:.05,sw:1.5}, - blueprint:{name:'Blueprint',desc:'Dark background, wireframe',dark:true, - bg:'#071a2e',bg2:'#0b2540',blocks:['#0e3a52'],neutral:'#0e3a52', - ink:'#5eead4',edge:'#5eead4',edge3d:'#5eead4',accent:'#fcaf17',accentFg:'#1f1300', - plate:'rgba(7,26,46,.92)',plateFg:'#ccfbf1',plateBd:'rgba(94,234,212,.55)',on:'#fcaf17',onFg:'#1f1300',muted:'#7dd3c8', - zone:'rgba(94,234,212,.05)',zoneBd:'rgba(94,234,212,.4)',chip:'rgba(7,26,46,.75)',labShadow:'rgba(0,0,0,.3)',shadow:'rgba(0,0,0,.25)', - gridOp:.12,grid3:.12,ground:0,mat:'basic',rough:1,opacity:.45,outline:0,sw:1}, - glass:{name:'Glass',desc:'See-through blocks', - bg:'#eef6f8',bg2:'#fbfeff',blocks:['#7fc9d3','#9fd5dd','#c4e6eb','#fcd27a','#b8e2e8','#a8dbe3','#d4eef2'],neutral:'#d7ecf0', - ink:'#0f4c5c',edge:'#5b9aa6',edge3d:'#ffffff',accent:'#fcaf17',accentFg:'#1f1300', - plate:'rgba(255,255,255,.85)',plateFg:'#0f172a',plateBd:'rgba(15,76,92,.3)',on:'#007c90',onFg:'#ffffff',muted:'#3b6f7b', - zone:'rgba(0,124,144,.05)',zoneBd:'rgba(0,124,144,.35)',chip:'rgba(255,255,255,.75)',labShadow:'rgba(15,23,42,.08)',shadow:'rgba(15,76,92,.10)', - gridOp:.07,grid3:.07,ground:.1,mat:'glass',rough:.15,opacity:.6,outline:0,sw:1}, - circuit:{name:'Circuit',desc:'Dark board, flat chips, thin blue lines',dark:true, - bg:'#080c17',bg2:'#0e1527',blocks:['#1a2438','#1b2a42','#172236'],neutral:'#1a2438', - ink:'#4d6a90',edge:'#7393bd',edge3d:'#86a6d0',accent:'#bfe1ff',accentFg:'#0a0e1a', - plate:'transparent',plateFg:'#c9d6e8',plateBd:'transparent',on:'rgba(191,225,255,.12)',onFg:'#ffffff',muted:'#8094ae', - zone:'rgba(115,147,189,.05)',zoneBd:'rgba(115,147,189,.35)',chip:'rgba(8,12,23,.7)',labShadow:'transparent',shadow:'rgba(0,0,0,.35)', - gridOp:.11,grid3:.11,ground:0,mat:'basic',rough:1,opacity:1,outline:0,sw:.8, - chips:true,flat:.42,labMono:true,labUpper:true} -}; +const STYLES=/** @type {Record<string,DiagramStyle>} */(JSON.parse("{\"original\":{\"name\":\"Original\",\"desc\":\"Pastel blocks on warm paper\",\"bg\":\"#f5f0e6\",\"bg2\":\"#fbf7ee\",\"blocks\":[\"#a9c8f5\",\"#b6e3b1\",\"#cdbdf6\",\"#f7da8c\",\"#f5b9c5\",\"#f8c59b\",\"#a9e0dc\"],\"neutral\":\"#e6e0d2\",\"ink\":\"#1f2430\",\"edge\":\"#1f2430\",\"edge3d\":null,\"accent\":\"#ee5a3a\",\"accentFg\":\"#fff\",\"plate\":\"#fffdf8\",\"plateFg\":\"#1f2430\",\"plateBd\":\"#1f2430\",\"on\":\"#1f2430\",\"onFg\":\"#f5f0e6\",\"muted\":\"#6b6f7b\",\"zone\":\"rgba(31,36,48,.035)\",\"zoneBd\":\"rgba(31,36,48,.45)\",\"chip\":\"rgba(245,240,230,.75)\",\"labShadow\":\"rgba(31,36,48,.2)\",\"shadow\":\"rgba(31,36,48,.10)\",\"gridOp\":0.07,\"grid3\":0.075,\"ground\":0.2,\"mat\":\"standard\",\"rough\":0.6,\"opacity\":1,\"outline\":0,\"sw\":1},\"teal\":{\"name\":\"Teal\",\"desc\":\"Teal outlines, amber highlight\",\"bg\":\"#f3f8f9\",\"bg2\":\"#ffffff\",\"blocks\":[\"#e6f4f6\",\"#c4e6eb\",\"#9fd5dd\",\"#fff1cc\",\"#d7eef1\",\"#b8e2e8\",\"#e3f2ee\"],\"neutral\":\"#eef2f5\",\"ink\":\"#475569\",\"edge\":\"#007c90\",\"edge3d\":\"#007c90\",\"accent\":\"#fcaf17\",\"accentFg\":\"#1f1300\",\"plate\":\"#ffffff\",\"plateFg\":\"#0f172a\",\"plateBd\":\"#cbd5e1\",\"on\":\"#007c90\",\"onFg\":\"#ffffff\",\"muted\":\"#64748b\",\"zone\":\"rgba(0,124,144,.04)\",\"zoneBd\":\"rgba(0,124,144,.45)\",\"chip\":\"rgba(255,255,255,.85)\",\"labShadow\":\"rgba(15,23,42,.08)\",\"shadow\":\"rgba(15,23,42,.07)\",\"gridOp\":0.06,\"grid3\":0.06,\"ground\":0.1,\"mat\":\"standard\",\"rough\":0.7,\"opacity\":1,\"outline\":0,\"sw\":1},\"line\":{\"name\":\"Line Art\",\"desc\":\"White blocks, bold outlines\",\"bg\":\"#ffffff\",\"bg2\":\"#ffffff\",\"blocks\":[\"#ffffff\"],\"neutral\":\"#ffffff\",\"ink\":\"#0f172a\",\"edge\":\"#0f172a\",\"edge3d\":\"#0f172a\",\"accent\":\"#007c90\",\"accentFg\":\"#fff\",\"plate\":\"#ffffff\",\"plateFg\":\"#0f172a\",\"plateBd\":\"#0f172a\",\"on\":\"#0f172a\",\"onFg\":\"#ffffff\",\"muted\":\"#475569\",\"zone\":\"rgba(15,23,42,.02)\",\"zoneBd\":\"rgba(15,23,42,.5)\",\"chip\":\"rgba(255,255,255,.9)\",\"labShadow\":\"rgba(15,23,42,.15)\",\"shadow\":\"rgba(15,23,42,.06)\",\"gridOp\":0.06,\"grid3\":0.06,\"ground\":0.06,\"mat\":\"toon\",\"rough\":1,\"opacity\":1,\"outline\":0.05,\"sw\":1.5},\"blueprint\":{\"name\":\"Blueprint\",\"desc\":\"Dark background, wireframe\",\"dark\":true,\"bg\":\"#071a2e\",\"bg2\":\"#0b2540\",\"blocks\":[\"#0e3a52\"],\"neutral\":\"#0e3a52\",\"ink\":\"#5eead4\",\"edge\":\"#5eead4\",\"edge3d\":\"#5eead4\",\"accent\":\"#fcaf17\",\"accentFg\":\"#1f1300\",\"plate\":\"rgba(7,26,46,.92)\",\"plateFg\":\"#ccfbf1\",\"plateBd\":\"rgba(94,234,212,.55)\",\"on\":\"#fcaf17\",\"onFg\":\"#1f1300\",\"muted\":\"#7dd3c8\",\"zone\":\"rgba(94,234,212,.05)\",\"zoneBd\":\"rgba(94,234,212,.4)\",\"chip\":\"rgba(7,26,46,.75)\",\"labShadow\":\"rgba(0,0,0,.3)\",\"shadow\":\"rgba(0,0,0,.25)\",\"gridOp\":0.12,\"grid3\":0.12,\"ground\":0,\"mat\":\"basic\",\"rough\":1,\"opacity\":0.45,\"outline\":0,\"sw\":1},\"glass\":{\"name\":\"Glass\",\"desc\":\"See-through blocks\",\"bg\":\"#eef6f8\",\"bg2\":\"#fbfeff\",\"blocks\":[\"#7fc9d3\",\"#9fd5dd\",\"#c4e6eb\",\"#fcd27a\",\"#b8e2e8\",\"#a8dbe3\",\"#d4eef2\"],\"neutral\":\"#d7ecf0\",\"ink\":\"#0f4c5c\",\"edge\":\"#5b9aa6\",\"edge3d\":\"#ffffff\",\"accent\":\"#fcaf17\",\"accentFg\":\"#1f1300\",\"plate\":\"rgba(255,255,255,.85)\",\"plateFg\":\"#0f172a\",\"plateBd\":\"rgba(15,76,92,.3)\",\"on\":\"#007c90\",\"onFg\":\"#ffffff\",\"muted\":\"#3b6f7b\",\"zone\":\"rgba(0,124,144,.05)\",\"zoneBd\":\"rgba(0,124,144,.35)\",\"chip\":\"rgba(255,255,255,.75)\",\"labShadow\":\"rgba(15,23,42,.08)\",\"shadow\":\"rgba(15,76,92,.10)\",\"gridOp\":0.07,\"grid3\":0.07,\"ground\":0.1,\"mat\":\"glass\",\"rough\":0.15,\"opacity\":0.6,\"outline\":0,\"sw\":1},\"circuit\":{\"name\":\"Circuit\",\"desc\":\"Dark board, flat chips, thin blue lines\",\"dark\":true,\"bg\":\"#080c17\",\"bg2\":\"#0e1527\",\"blocks\":[\"#1a2438\",\"#1b2a42\",\"#172236\"],\"neutral\":\"#1a2438\",\"ink\":\"#4d6a90\",\"edge\":\"#7393bd\",\"edge3d\":\"#86a6d0\",\"accent\":\"#bfe1ff\",\"accentFg\":\"#0a0e1a\",\"plate\":\"transparent\",\"plateFg\":\"#c9d6e8\",\"plateBd\":\"transparent\",\"on\":\"rgba(191,225,255,.12)\",\"onFg\":\"#ffffff\",\"muted\":\"#8094ae\",\"zone\":\"rgba(115,147,189,.05)\",\"zoneBd\":\"rgba(115,147,189,.35)\",\"chip\":\"rgba(8,12,23,.7)\",\"labShadow\":\"transparent\",\"shadow\":\"rgba(0,0,0,.35)\",\"gridOp\":0.11,\"grid3\":0.11,\"ground\":0,\"mat\":\"basic\",\"rough\":1,\"opacity\":1,\"outline\":0,\"sw\":0.8,\"chips\":true,\"flat\":0.42,\"labMono\":true,\"labUpper\":true}}")); +/* ---- end generated STYLES ---- */ let DS=STYLES.original,DSK='original'; const UI_ICON={check:'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>',chev:'<svg class="chev" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="m6 9 6 6 6-6"/></svg>'}; const hashStyle=()=>{const m=location.hash.match(/[#&]s=([\w-]+)/);return m&&STYLES[m[1]]?m[1]:null}; diff --git a/package.json b/package.json index f286798..28a9f8b 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "start": "node server.js", "check": "npm run check:sync && npm run lint && npm run typecheck && npm run typecheck:strict && npm test", "check:sync": "node tools/check-sync.mjs", + "styles:sync": "node tools/sync-styles.mjs && python3 tools/sync-parser.py", "lint": "node tools/extract-scripts.mjs && eslint .check server.js embed.js tools tests eslint.config.mjs", "typecheck": "node tools/extract-scripts.mjs && tsc -p tsconfig.basic.json && tsc -p tsconfig.node.json", "typecheck:strict": "node tools/typecheck-strict.mjs", diff --git a/tests/parser.test.mjs b/tests/parser.test.mjs index b3ec667..f9c76c9 100644 --- a/tests/parser.test.mjs +++ b/tests/parser.test.mjs @@ -108,6 +108,26 @@ test('diagram styles define every field the renderers read', () => { assert.ok(core.STYLES.original && core.STYLES.circuit); }); +test('diagram-styles/ folder assembles to STYLES and the published bundle', () => { + const pack = JSON.parse(readFileSync(join(root, 'diagram-styles', 'pack.json'), 'utf8')); + assert.equal(pack.format, 'flow-explainer.diagram-styles'); + assert.ok(pack.order.includes('original')); + /** @type {Record<string, unknown>} */ + const fromFiles = {}; + for (const key of pack.order) { + const raw = JSON.parse(readFileSync(join(root, 'diagram-styles', key + '.json'), 'utf8')); + const { $schema, ...style } = raw; + void $schema; + fromFiles[key] = style; + } + assert.deepEqual(core.STYLES, fromFiles); + const bundle = JSON.parse(readFileSync(join(root, 'diagram-styles.json'), 'utf8')); + assert.equal(bundle.format, 'flow-explainer.diagram-styles'); + assert.deepEqual(bundle.styles, fromFiles); + const schema = JSON.parse(readFileSync(join(root, 'diagram-styles.schema.json'), 'utf8')); + assert.equal(schema.$defs.diagramStyle.required.includes('mat'), true); +}); + // Snapshot of every example's parsed result: catches any change in parser output. test('parser output matches the snapshot', () => { /** @type {Record<string, unknown>} */ diff --git a/tests/server.test.mjs b/tests/server.test.mjs index 2dd6ca8..f46bd88 100644 --- a/tests/server.test.mjs +++ b/tests/server.test.mjs @@ -18,6 +18,8 @@ test('assets load from the /3d/ and /embed/ sub-paths', () => { assert.equal(rel('/3d/favicon.svg'), 'favicon.svg'); assert.equal(rel('/robots.txt'), 'robots.txt'); assert.equal(rel('/embed.js'), 'embed.js'); + assert.equal(rel('/diagram-styles.json'), 'diagram-styles.json'); + assert.equal(rel('/diagram-styles.schema.json'), 'diagram-styles.schema.json'); }); test('private files and path tricks are refused', () => { diff --git a/tools/check-sync.mjs b/tools/check-sync.mjs index 6198499..8e0d931 100644 --- a/tools/check-sync.mjs +++ b/tools/check-sync.mjs @@ -1,7 +1,10 @@ #!/usr/bin/env node -// Fails if the shared blocks of 3d.html differ from index.html (see tools/sync-parser.py). +// Fails if diagram-styles.json ↔ index.html STYLES, or 3d.html shared blocks, are out of sync. import { execFileSync } from 'node:child_process'; import { dirname, join } from 'node:path'; import { fileURLToPath } from 'node:url'; const root = join(dirname(fileURLToPath(import.meta.url)), '..'); -execFileSync('python3', [join(root, 'tools/sync-parser.py'), '--check'], { stdio: 'inherit' }); +const run = (/** @type {string} */ cmd, /** @type {string[]} */ args) => + execFileSync(cmd, args, { stdio: 'inherit', cwd: root }); +run('node', [join(root, 'tools/sync-styles.mjs'), '--check']); +run('python3', [join(root, 'tools/sync-parser.py'), '--check']); diff --git a/tools/sync-styles.mjs b/tools/sync-styles.mjs new file mode 100644 index 0000000..7930c34 --- /dev/null +++ b/tools/sync-styles.mjs @@ -0,0 +1,127 @@ +#!/usr/bin/env node +/** + * diagram-styles/ is the source of truth (one JSON file per style + pack.json). + * This: + * 1. Assembles diagram-styles.json (published bundle for Pages / tools) + * 2. Embeds `styles` into index.html as `const STYLES=JSON.parse(...)` + * so the pages stay standalone (no fetch / no build step at runtime). + * + * node tools/sync-styles.mjs # write bundle + index.html + * node tools/sync-styles.mjs --check # exit 1 if either is out of date + * Then run: python3 tools/sync-parser.py + */ +import { readdirSync, readFileSync, writeFileSync } from 'node:fs'; +import { dirname, join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const root = join(dirname(fileURLToPath(import.meta.url)), '..'); +const dir = join(root, 'diagram-styles'); +const packPath = join(dir, 'pack.json'); +const bundlePath = join(root, 'diagram-styles.json'); +const htmlPath = join(root, 'index.html'); +const BEGIN = '/* ---- begin generated STYLES (from diagram-styles/; run: node tools/sync-styles.mjs) ---- */'; +const END = '/* ---- end generated STYLES ---- */'; +const check = process.argv.includes('--check'); + +const pack = JSON.parse(readFileSync(packPath, 'utf8')); +if (pack.format !== 'flow-explainer.diagram-styles') { + console.error('diagram-styles/pack.json: expected format "flow-explainer.diagram-styles"'); + process.exit(1); +} +if (!Array.isArray(pack.order) || !pack.order.includes('original')) { + console.error('diagram-styles/pack.json: order must include "original"'); + process.exit(1); +} + +/** @type {Record<string, unknown>} */ +const styles = {}; +for (const key of pack.order) { + if (!/^[a-z][a-z0-9-]*$/.test(key)) { + console.error('Invalid style id in pack.order:', key); + process.exit(1); + } + const file = join(dir, key + '.json'); + let raw; + try { + raw = JSON.parse(readFileSync(file, 'utf8')); + } catch (e) { + console.error('Missing or invalid style file:', file, e instanceof Error ? e.message : e); + process.exit(1); + } + const style = { ...raw }; + delete style.$schema; + if (!style.name || !style.bg || !Array.isArray(style.blocks)) { + console.error(key + '.json: missing required fields (name, bg, blocks, …)'); + process.exit(1); + } + styles[key] = style; +} + +const onDisk = readdirSync(dir).filter((f) => f.endsWith('.json') && f !== 'pack.json'); +for (const f of onDisk) { + const key = f.replace(/\.json$/, ''); + if (!pack.order.includes(key)) { + console.error('Orphan style file not listed in pack.order:', f); + process.exit(1); + } +} + +const bundle = { + $schema: './diagram-styles.schema.json', + format: 'flow-explainer.diagram-styles', + version: pack.version, + styles, +}; +const bundleText = JSON.stringify(bundle, null, 2) + '\n'; + +const payload = JSON.stringify(styles); +const block = [ + BEGIN, + '/** @type {Record<string,DiagramStyle>} */', + 'const STYLES=/** @type {Record<string,DiagramStyle>} */(JSON.parse(' + JSON.stringify(payload) + '));', + END, +].join('\n'); + +const html = readFileSync(htmlPath, 'utf8'); +const a = html.indexOf(BEGIN); +const b = html.indexOf(END); +// Allow either old or new marker comment during migration +let ai = a; +let bi = b; +let endMark = END; +if (ai < 0 || bi < 0) { + const oldBegin = '/* ---- begin generated STYLES (from diagram-styles.json; run: node tools/sync-styles.mjs) ---- */'; + ai = html.indexOf(oldBegin); + bi = html.indexOf(END); + endMark = END; +} +if (ai < 0 || bi < 0 || bi < ai) { + console.error('index.html is missing generated STYLES markers; expected:\n' + BEGIN + '\n...\n' + END); + process.exit(1); +} +const nextHtml = html.slice(0, ai) + block + html.slice(bi + endMark.length); + +let ok = true; +const curBundle = (() => { + try { + return readFileSync(bundlePath, 'utf8'); + } catch { + return null; + } +})(); +if (curBundle !== bundleText) { + if (check) { + console.error('diagram-styles.json is out of sync with diagram-styles/; run: npm run styles:sync'); + ok = false; + } else writeFileSync(bundlePath, bundleText), console.log('diagram-styles.json rebuilt from diagram-styles/'); +} else if (!check) console.log('diagram-styles.json already matches diagram-styles/'); + +if (nextHtml !== html) { + if (check) { + console.error('index.html STYLES are out of sync with diagram-styles/; run: npm run styles:sync'); + ok = false; + } else writeFileSync(htmlPath, nextHtml), console.log('index.html STYLES updated from diagram-styles/'); +} else if (!check) console.log('index.html STYLES already match diagram-styles/'); + +if (check && ok) console.log('diagram-styles/ → bundle + index.html in sync'); +process.exit(ok ? 0 : 1);