@reqvire-org/ads 0.3.43 → 0.3.44
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 +5 -1
- package/dist/assets.mjs +48 -2
- package/dist/bootstrap-ds/ADS.md +2 -2
- package/dist/bootstrap-ds/README.md +6 -4
- package/dist/bootstrap-ds/design-system/assets/brand/README.md +26 -19
- package/dist/bootstrap-ds/design-system/assets/brand/app-icon.svg +4 -0
- package/dist/bootstrap-ds/design-system/assets/brand/logo.dark.svg +6 -0
- package/dist/bootstrap-ds/design-system/assets/brand/logo.svg +6 -0
- package/dist/bootstrap-ds/design-system/components/Content/Logo/Logo.ads.fixture.ts +1 -0
- package/dist/bootstrap-ds/design-system/components/Content/Logo/Logo.ads.scenario.tsx +12 -0
- package/dist/bootstrap-ds/design-system/components/Content/Logo/Logo.tsx +41 -0
- package/dist/bootstrap-ds/design-system/components/Content/Logo/README.md +10 -0
- package/dist/bootstrap-ds/design-system/index.ts +1 -0
- package/dist/bootstrap-ds/design-system/review/brand-preview/BrandPreview.tsx +115 -0
- package/dist/bootstrap-ds/design-system/review/index.ts +1 -0
- package/dist/bootstrap-ds/design-system/tokens/Brand.ads.fixture.ts +12 -0
- package/dist/bootstrap-ds/design-system/tokens/Brand.ads.scenario.tsx +4 -0
- package/dist/bootstrap-ds/ds.config.json +2 -1
- package/dist/bootstrap-ds-preact/ds.config.json +2 -1
- package/dist/brand-assets.mjs +136 -3
- package/dist/check.mjs +4 -2
- package/dist/config.mjs +49 -1
- package/dist/init.mjs +3 -2
- package/dist/mcp/preview-widget.bundle.js +1 -1
- package/dist/mcp/project-widget.bundle.js +1 -1
- package/dist/mcp/server.mjs +5 -2
- package/dist/preview-bun.mjs +4 -2
- package/dist/preview-resources.mjs +1 -1
- package/dist/scenarios.mjs +11 -4
- package/dist/skills/ads-designer/SKILL.md +9 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/ADS.md +2 -2
- package/dist/skills/ads-designer/assets/bootstrap-ds/README.md +6 -4
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/assets/brand/README.md +26 -19
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/assets/brand/app-icon.svg +4 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/assets/brand/logo.dark.svg +6 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/assets/brand/logo.svg +6 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/components/Content/Logo/Logo.ads.fixture.ts +1 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/components/Content/Logo/Logo.ads.scenario.tsx +12 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/components/Content/Logo/Logo.tsx +41 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/components/Content/Logo/README.md +10 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/index.ts +1 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/review/brand-preview/BrandPreview.tsx +115 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/review/index.ts +1 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/tokens/Brand.ads.fixture.ts +12 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/design-system/tokens/Brand.ads.scenario.tsx +4 -0
- package/dist/skills/ads-designer/assets/bootstrap-ds/ds.config.json +2 -1
- package/dist/skills/ads-designer/assets/bootstrap-ds-preact/ds.config.json +2 -1
- package/dist/skills/ads-designer/references/branding.md +89 -0
- package/dist/skills/ads-import/references/branding.md +10 -3
- package/dist/token-fixtures.mjs +2 -2
- package/docs/ADS.md +5 -2
- package/docs/CHANGELOG.md +35 -12
- package/docs/GUIDE.md +41 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -249,7 +249,11 @@ Change values in `design-system/tokens/`, keeping the
|
|
|
249
249
|
[shared token names](docs/ADS.md#shared-token-contract), such as `--accent` and
|
|
250
250
|
`--font-sans`.
|
|
251
251
|
|
|
252
|
-
Keep original artwork
|
|
252
|
+
Keep original artwork, with its use, credits and license in a README, in
|
|
253
|
+
`design-system/assets/brand/`; `ads check` warns about undescribed, unlicensed,
|
|
254
|
+
unpreviewed or unused artwork. Name dark-theme variants `<name>.dark.svg`.
|
|
255
|
+
Committed native and export icons (`assets.targets`: SVG, PNG, ICO, ICNS) and UI
|
|
256
|
+
icon sets (`assets.glyphs`) are generated by `ads assets` and checked for freshness.
|
|
253
257
|
To generate web icons, add this to `ds.config.json`:
|
|
254
258
|
|
|
255
259
|
```json
|
package/dist/assets.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { existsSync, lstatSync, readdirSync } from "node:fs";
|
|
1
|
+
import { existsSync, lstatSync, readFileSync, readdirSync } from "node:fs";
|
|
2
2
|
import { spawnSync } from "node:child_process";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { isInside } from "./config.mjs";
|
|
5
|
-
import { brandFiles, brandSourceDiagnostic } from "./brand-assets.mjs";
|
|
5
|
+
import { brandFiles, brandSourceDiagnostic, staleBrandOutputs } from "./brand-assets.mjs";
|
|
6
6
|
|
|
7
7
|
function assetFiles(directory, prefix = "") {
|
|
8
8
|
const stat = lstatSync(directory, { throwIfNoEntry: false });
|
|
@@ -17,10 +17,56 @@ function assetFiles(directory, prefix = "") {
|
|
|
17
17
|
return files.sort();
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
const sourceExtensions = /\.(?:[cm]?[jt]sx?|css|html|svg)$/;
|
|
21
|
+
const previewFile = /(?:\.ads)?\.(?:scenario\.tsx?|fixture\.ts)$/;
|
|
22
|
+
/** Text of the project's own source files, for finding which brand artwork is referenced. */
|
|
23
|
+
function sourceTexts(directories, skipped) {
|
|
24
|
+
const texts = [];
|
|
25
|
+
const visit = directory => {
|
|
26
|
+
const stat = lstatSync(directory, { throwIfNoEntry: false });
|
|
27
|
+
if (!stat || stat.isSymbolicLink() || !stat.isDirectory() || skipped.some(skip => directory === skip || isInside(skip, directory))) return;
|
|
28
|
+
for (const entry of readdirSync(directory, { withFileTypes: true })) {
|
|
29
|
+
const file = path.join(directory, entry.name);
|
|
30
|
+
if (entry.isDirectory()) { if (!["node_modules", ".git"].includes(entry.name)) visit(file); }
|
|
31
|
+
else if (entry.isFile() && sourceExtensions.test(entry.name)) texts.push({ file, text: readFileSync(file, "utf8") });
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
for (const directory of directories) visit(directory);
|
|
35
|
+
return texts;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Brand artwork is documented, licensed, previewed and used. Generated outputs match their masters. */
|
|
39
|
+
function inspectBrand({ root, dsRoot, config }) {
|
|
40
|
+
const diagnostics = [];
|
|
41
|
+
const relative = file => path.relative(root, file).replaceAll("\\", "/") || ".";
|
|
42
|
+
for (const { file, message } of staleBrandOutputs({ root, dsRoot, config })) diagnostics.push({ rule: "brand-output-stale", file, line: 1, column: 1, message });
|
|
43
|
+
const brand = path.join(dsRoot, "assets/brand");
|
|
44
|
+
const artwork = assetFiles(brand).filter(file => file.toLowerCase().endsWith(".svg"));
|
|
45
|
+
if (!artwork.length) return diagnostics;
|
|
46
|
+
const warn = (rule, file, message) => diagnostics.push({ rule, severity: "warning", file: relative(file), line: 1, column: 1, guidanceUri: "ads://guides/branding", message });
|
|
47
|
+
const readmeFile = path.join(brand, "README.md");
|
|
48
|
+
const readme = existsSync(readmeFile) ? readFileSync(readmeFile, "utf8") : null;
|
|
49
|
+
if (readme === null) warn("brand-readme", brand, "Describe each artwork in assets/brand/README.md: its use, suitable backgrounds, credits and license.");
|
|
50
|
+
else if (!/licen[cs]e/i.test(readme)) warn("brand-license", readmeFile, "State the license (or ownership) of the brand artwork in assets/brand/README.md.");
|
|
51
|
+
const generated = [...config.assets.generatedPaths.map(entry => path.resolve(root, entry)), path.join(root, ".ds")];
|
|
52
|
+
const sources = sourceTexts([dsRoot, path.join(root, config.sourceDir ?? "src")], [path.join(dsRoot, "assets"), ...generated]);
|
|
53
|
+
const configured = new Set([config.assets.iconSource, ...config.assets.targets.map(target => target.from)].filter(Boolean).map(file => path.join(dsRoot, file)));
|
|
54
|
+
const previews = path.join(dsRoot, config.tokenDir);
|
|
55
|
+
for (const name of artwork) {
|
|
56
|
+
const file = path.join(brand, name), base = path.basename(name);
|
|
57
|
+
if (readme !== null && !readme.includes(base)) warn("brand-readme", file, `Describe ${base} in assets/brand/README.md: its use, suitable backgrounds, credits and license.`);
|
|
58
|
+
const referencing = sources.filter(source => source.text.includes(base));
|
|
59
|
+
if (!referencing.some(source => isInside(previews, source.file) && previewFile.test(source.file))) warn("brand-preview", file, `Show ${base} in a token-folder brand scenario, so it can be reviewed with the foundation.`);
|
|
60
|
+
if (!configured.has(file) && !referencing.some(source => !previewFile.test(source.file))) warn("brand-unused", file, `${base} is not used by any component, assets.iconSource or assets.targets. Use it or remove it.`);
|
|
61
|
+
}
|
|
62
|
+
return diagnostics;
|
|
63
|
+
}
|
|
64
|
+
|
|
20
65
|
export function inspectAssets({ root, dsRoot, config, trackingRoot = root }) {
|
|
21
66
|
const diagnostics = [];
|
|
22
67
|
const sourceDiagnostic = brandSourceDiagnostic({ root, dsRoot, config });
|
|
23
68
|
if (sourceDiagnostic) diagnostics.push(sourceDiagnostic);
|
|
69
|
+
diagnostics.push(...inspectBrand({ root, dsRoot, config }));
|
|
24
70
|
function report(rule, file, message) { diagnostics.push({ rule, file: path.relative(root, file).replaceAll("\\", "/") || ".", line: 1, column: 1, message }); }
|
|
25
71
|
const assetRoot = path.join(dsRoot, "assets");
|
|
26
72
|
// Every mount is compared with the canonical ADS assets. Public mounts are
|
package/dist/bootstrap-ds/ADS.md
CHANGED
|
@@ -24,8 +24,8 @@ The starter declares React in `ds.config.json`. Keep that choice, JSX, runtime
|
|
|
24
24
|
dependencies and the preview mount adapter consistent. Init records a choice for
|
|
25
25
|
an unconfigured project; it does not convert copied React source to Preact.
|
|
26
26
|
|
|
27
|
-
The starter has one example of each layer (Button, TextField, SearchBar,
|
|
28
|
-
SearchPage). Rename, restyle or replace them; add only what the product needs.
|
|
27
|
+
The starter has one example of each layer (Button, Logo, TextField, SearchBar,
|
|
28
|
+
SearchPage) and placeholder brand artwork. Rename, restyle or replace them; add only what the product needs.
|
|
29
29
|
Keep the ADS in root `design-system/`, beside application `src/`.
|
|
30
30
|
Keep public exports in `design-system/index.ts`; consumers use its `@ds` alias.
|
|
31
31
|
`styles.css` is the foundation CSS entry and contains token imports only.
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
This private React or Preact TypeScript workspace contains semantic CSS tokens, a project-owned
|
|
4
4
|
token review renderer, a public barrel, Linaria extraction and a preview compiler
|
|
5
5
|
adapter, plus one example of each layer to build on: two token groups (Color; Space, type &
|
|
6
|
-
motion),
|
|
7
|
-
`components/Forms/TextField`), one pattern
|
|
8
|
-
composition (`composition/Search/SearchPage`)
|
|
9
|
-
|
|
6
|
+
motion) and a Brand preview, components in three groups (`components/Actions/Button`,
|
|
7
|
+
`components/Content/Logo`, `components/Forms/TextField`), one pattern
|
|
8
|
+
(`patterns/Search/SearchBar`) and one composition (`composition/Search/SearchPage`),
|
|
9
|
+
plus placeholder brand artwork in `assets/brand/` (a logo with its dark-theme
|
|
10
|
+
variant, and the app icon that `assets.iconSource` names). Rename, restyle or
|
|
11
|
+
replace them as the product's own; it has no fonts. The minimal showcase shell and MCP client
|
|
10
12
|
come from ADS tooling.
|
|
11
13
|
|
|
12
14
|
Read the local [contract](ADS.md) and the
|
|
@@ -1,29 +1,36 @@
|
|
|
1
1
|
# Project branding
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
The starter's placeholder artwork. Replace each file with the product's own and keep this
|
|
4
|
+
table current: `ads check` warns about artwork that is undescribed, unlicensed, unused or
|
|
5
|
+
missing from the brand scenario (`tokens/Brand.ads.scenario.tsx`).
|
|
6
|
+
|
|
7
|
+
| File | Use | Backgrounds |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| `logo.svg` | Logo in the UI (`components/Content/Logo`), light theme | Light surfaces |
|
|
10
|
+
| `logo.dark.svg` | The same logo for the dark theme | Dark surfaces |
|
|
11
|
+
| `app-icon.svg` | Master for web icons (`assets.iconSource`) and any `assets.targets` | Any; it has its own fill and padding |
|
|
12
|
+
|
|
13
|
+
License: placeholder artwork made for the ADS starter, free to use, change or remove
|
|
14
|
+
(MIT, like ADS). Record the real artwork's credits and license here when it replaces this.
|
|
15
|
+
|
|
16
|
+
## How branding works
|
|
6
17
|
|
|
7
18
|
UI branding uses the project-owned shared roles in `tokens/`: change values such as
|
|
8
19
|
`--accent`, `--font-sans`, and `--radius-md`. Components own `--ds-*` variables;
|
|
9
20
|
patterns and development review helpers own `--ux-*`; the showcase owns
|
|
10
|
-
`--showcase-*`. Do not introduce a
|
|
11
|
-
|
|
21
|
+
`--showcase-*`. Do not introduce a brand-prefixed token vocabulary or override
|
|
22
|
+
component state variables.
|
|
23
|
+
|
|
24
|
+
Name a dark-theme variant `<name>.dark.svg`; the component showing the artwork renders
|
|
25
|
+
both and the theme picks one. Fixed colors belong inside the artwork only.
|
|
12
26
|
|
|
13
27
|
Put licensed font files in `assets/fonts/` and their declarations in
|
|
14
28
|
`tokens/fonts.css`. Keep that optional import first in `styles.css`.
|
|
15
29
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
After `ads init`, the normal npm or Bun build generates `favicon.svg`,
|
|
24
|
-
`favicon.ico` (16/32/48), `apple-touch-icon.png` (180), `icon-192.png`, and
|
|
25
|
-
`icon-512.png` in ignored `.ds/assets/`. Run `ads assets` to regenerate manually.
|
|
26
|
-
Outputs retain the artwork's colors and transparent background; provide an
|
|
27
|
-
appropriate source background if a platform needs one. Mount this directory
|
|
28
|
-
through the application's existing bundler and keep app manifest metadata in
|
|
29
|
-
the application. Edit the original SVG, never generated variants.
|
|
30
|
+
`assets.iconSource` (here `assets/brand/app-icon.svg`) makes every build generate
|
|
31
|
+
`favicon.svg`, `favicon.ico` (16/32/48), `apple-touch-icon.png` (180), `icon-192.png` and
|
|
32
|
+
`icon-512.png` in ignored `.ds/assets/`; mount that folder through the application's
|
|
33
|
+
bundler and keep the manifest in the application. Native launchers, tray icons and
|
|
34
|
+
upload exports are committed `assets.targets` (PNG, ICO, ICNS or SVG copies), kept
|
|
35
|
+
fresh by `ads assets` and checked by `ads check`. Edit the masters here, never
|
|
36
|
+
generated files. See the [branding guide](https://github.com/reqvire-org/ads/blob/main/skills/ads-designer/references/branding.md).
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160 40" role="img" aria-label="Starter">
|
|
2
|
+
<rect x="2" y="4" width="32" height="32" rx="8" fill="#fb7185"/>
|
|
3
|
+
<circle cx="18" cy="20" r="7" fill="#17191e"/>
|
|
4
|
+
<rect x="46" y="12" width="68" height="7" rx="3.5" fill="#f8fafc"/>
|
|
5
|
+
<rect x="46" y="24" width="44" height="5" rx="2.5" fill="#94a3b8"/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 160 40" role="img" aria-label="Starter">
|
|
2
|
+
<rect x="2" y="4" width="32" height="32" rx="8" fill="#c62648"/>
|
|
3
|
+
<circle cx="18" cy="20" r="7" fill="#ffffff"/>
|
|
4
|
+
<rect x="46" y="12" width="68" height="7" rx="3.5" fill="#1e293b"/>
|
|
5
|
+
<rect x="46" y="24" width="44" height="5" rx="2.5" fill="#64748b"/>
|
|
6
|
+
</svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const fixture = { title: "Logo", label: "Starter" } as const;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Logo } from "@ds";
|
|
2
|
+
import { DemoFrame } from "@ds/review";
|
|
3
|
+
import { fixture } from "./Logo.ads.fixture";
|
|
4
|
+
export const scenario = { title: fixture.title, covers: ["Logo"] };
|
|
5
|
+
export default function Scenario() {
|
|
6
|
+
return (
|
|
7
|
+
<DemoFrame>
|
|
8
|
+
<Logo label={fixture.label} />
|
|
9
|
+
<Logo label={fixture.label} size="large" />
|
|
10
|
+
</DemoFrame>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { css, cx } from "@linaria/atomic";
|
|
2
|
+
import logo from "../../../assets/brand/logo.svg?url";
|
|
3
|
+
import logoDark from "../../../assets/brand/logo.dark.svg?url";
|
|
4
|
+
|
|
5
|
+
export interface LogoProps {
|
|
6
|
+
/** The product name, read by assistive technology. */
|
|
7
|
+
label: string;
|
|
8
|
+
size?: "small" | "large";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const base = css`
|
|
12
|
+
display: inline-flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
`;
|
|
15
|
+
const sizes = {
|
|
16
|
+
small: css`height: var(--space-12);`,
|
|
17
|
+
large: css`height: calc(var(--space-16) * 2);`,
|
|
18
|
+
};
|
|
19
|
+
const image = css`
|
|
20
|
+
display: block;
|
|
21
|
+
height: 100%;
|
|
22
|
+
width: auto;
|
|
23
|
+
`;
|
|
24
|
+
// Both variants are in the page; the theme shows one, so switching needs no script.
|
|
25
|
+
const light = css`
|
|
26
|
+
:root[data-theme="dark"] & { display: none; }
|
|
27
|
+
`;
|
|
28
|
+
const dark = css`
|
|
29
|
+
display: none;
|
|
30
|
+
:root[data-theme="dark"] & { display: block; }
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
/** The product logo, in its light- or dark-theme artwork. */
|
|
34
|
+
export function Logo({ label, size = "small" }: LogoProps) {
|
|
35
|
+
return (
|
|
36
|
+
<span className={cx("ds-logo", base, sizes[size])} role="img" aria-label={label}>
|
|
37
|
+
<img className={cx(image, light)} src={logo} alt="" />
|
|
38
|
+
<img className={cx(image, dark)} src={logoDark} alt="" />
|
|
39
|
+
</span>
|
|
40
|
+
);
|
|
41
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Logo
|
|
2
|
+
|
|
3
|
+
The product logo from `assets/brand/`: `logo.svg` in the light theme and `logo.dark.svg`
|
|
4
|
+
in the dark theme. Both images are in the page and the theme shows one, so switching
|
|
5
|
+
themes needs no script. `label` is the accessible name.
|
|
6
|
+
|
|
7
|
+
| Prop | Type | Default |
|
|
8
|
+
|---|---|---|
|
|
9
|
+
| `label` | `string` | — |
|
|
10
|
+
| `size` | `"small" \| "large"` | `"small"` |
|
|
@@ -3,5 +3,6 @@ import "./styles.css";
|
|
|
3
3
|
|
|
4
4
|
// Public components and patterns. Add new ones here as they are implemented.
|
|
5
5
|
export { Button, type ButtonProps } from "./components/Actions/Button/Button";
|
|
6
|
+
export { Logo, type LogoProps } from "./components/Content/Logo/Logo";
|
|
6
7
|
export { TextField, type TextFieldProps } from "./components/Forms/TextField/TextField";
|
|
7
8
|
export { SearchBar, type SearchBarProps } from "./patterns/Search/SearchBar/SearchBar";
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { css, cx } from "@linaria/atomic";
|
|
2
|
+
|
|
3
|
+
export interface BrandArtwork {
|
|
4
|
+
name: string;
|
|
5
|
+
use: string;
|
|
6
|
+
/** The default (light theme) artwork's URL. */
|
|
7
|
+
src: string;
|
|
8
|
+
/** Its dark-theme variant, `<name>.dark.svg`, when it has one. */
|
|
9
|
+
darkSrc?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface BrandPreviewProps {
|
|
12
|
+
title: string;
|
|
13
|
+
artwork: readonly BrandArtwork[];
|
|
14
|
+
/** The `assets.iconSource` master, shown at the generated web icon sizes. */
|
|
15
|
+
icon?: { name: string; src: string; sizes: readonly number[] };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const page = css`
|
|
19
|
+
display: flex;
|
|
20
|
+
flex-direction: column;
|
|
21
|
+
gap: var(--space-12);
|
|
22
|
+
padding: var(--space-8);
|
|
23
|
+
`;
|
|
24
|
+
const heading = css`
|
|
25
|
+
margin: 0;
|
|
26
|
+
font-size: var(--text-base);
|
|
27
|
+
font-weight: var(--weight-semibold);
|
|
28
|
+
color: var(--text-body);
|
|
29
|
+
`;
|
|
30
|
+
const grid = css`
|
|
31
|
+
display: grid;
|
|
32
|
+
grid-template-columns: repeat(auto-fill, minmax(calc(var(--space-16) * 8), 1fr));
|
|
33
|
+
gap: var(--space-8);
|
|
34
|
+
`;
|
|
35
|
+
const tile = css`
|
|
36
|
+
display: flex;
|
|
37
|
+
flex-direction: column;
|
|
38
|
+
gap: var(--space-4);
|
|
39
|
+
padding: var(--space-8);
|
|
40
|
+
border: var(--border-w) solid var(--border-default);
|
|
41
|
+
border-radius: var(--radius-md);
|
|
42
|
+
background: var(--bg-surface);
|
|
43
|
+
`;
|
|
44
|
+
const stage = css`
|
|
45
|
+
display: flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
justify-content: center;
|
|
48
|
+
min-height: calc(var(--space-16) * 3);
|
|
49
|
+
`;
|
|
50
|
+
const art = css`
|
|
51
|
+
max-width: 100%;
|
|
52
|
+
max-height: calc(var(--space-16) * 3);
|
|
53
|
+
`;
|
|
54
|
+
const label = css`
|
|
55
|
+
font-size: var(--text-sm);
|
|
56
|
+
color: var(--text-muted);
|
|
57
|
+
overflow-wrap: anywhere;
|
|
58
|
+
`;
|
|
59
|
+
// Paired artwork shows the variant of the current theme, as the UI does.
|
|
60
|
+
const light = css`:root[data-theme="dark"] & { display: none; }`;
|
|
61
|
+
const dark = css`
|
|
62
|
+
display: none;
|
|
63
|
+
:root[data-theme="dark"] & { display: block; }
|
|
64
|
+
`;
|
|
65
|
+
const icons = css`
|
|
66
|
+
display: flex;
|
|
67
|
+
flex-wrap: wrap;
|
|
68
|
+
align-items: flex-end;
|
|
69
|
+
gap: var(--space-8);
|
|
70
|
+
`;
|
|
71
|
+
const iconTile = css`
|
|
72
|
+
display: flex;
|
|
73
|
+
flex-direction: column;
|
|
74
|
+
align-items: center;
|
|
75
|
+
gap: var(--space-2);
|
|
76
|
+
`;
|
|
77
|
+
// Small sizes show at their real pixels; large ones are scaled down to fit the tile.
|
|
78
|
+
const iconImage = css`
|
|
79
|
+
max-width: calc(var(--space-16) * 4);
|
|
80
|
+
max-height: calc(var(--space-16) * 4);
|
|
81
|
+
`;
|
|
82
|
+
|
|
83
|
+
/** Development-only review of the brand artwork and the app icon at its generated sizes. */
|
|
84
|
+
export function BrandPreview({ title, artwork, icon }: BrandPreviewProps) {
|
|
85
|
+
return (
|
|
86
|
+
<section aria-label={title} className={cx("ux-brand-preview", page)}>
|
|
87
|
+
<h1 className={heading}>{title}</h1>
|
|
88
|
+
<div className={grid}>
|
|
89
|
+
{artwork.map(item => (
|
|
90
|
+
<article key={item.name} className={tile} aria-label={item.name}>
|
|
91
|
+
<div className={stage}>
|
|
92
|
+
<img className={cx(art, item.darkSrc ? light : undefined)} src={item.src} alt="" />
|
|
93
|
+
{item.darkSrc ? <img className={cx(art, dark)} src={item.darkSrc} alt="" /> : null}
|
|
94
|
+
</div>
|
|
95
|
+
<code className={label}>{item.darkSrc ? `${item.name} · ${item.name.replace(/\.svg$/, ".dark.svg")}` : item.name}</code>
|
|
96
|
+
<small className={label}>{item.use}</small>
|
|
97
|
+
</article>
|
|
98
|
+
))}
|
|
99
|
+
</div>
|
|
100
|
+
{icon ? (
|
|
101
|
+
<div className={tile} aria-label="App icon">
|
|
102
|
+
<div className={icons}>
|
|
103
|
+
{icon.sizes.map(size => (
|
|
104
|
+
<div key={size} className={iconTile}>
|
|
105
|
+
<img className={iconImage} src={icon.src} alt="" width={size} height={size} />
|
|
106
|
+
<small className={label}>{size}px</small>
|
|
107
|
+
</div>
|
|
108
|
+
))}
|
|
109
|
+
</div>
|
|
110
|
+
<code className={label}>{icon.name}</code>
|
|
111
|
+
</div>
|
|
112
|
+
) : null}
|
|
113
|
+
</section>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import logo from "../assets/brand/logo.svg?url";
|
|
2
|
+
import logoDark from "../assets/brand/logo.dark.svg?url";
|
|
3
|
+
import appIcon from "../assets/brand/app-icon.svg?url";
|
|
4
|
+
|
|
5
|
+
export const fixture = {
|
|
6
|
+
title: "Brand",
|
|
7
|
+
artwork: [
|
|
8
|
+
{ name: "logo.svg", use: "Logo in the UI (Logo component)", src: logo, darkSrc: logoDark },
|
|
9
|
+
{ name: "app-icon.svg", use: "Master for the web icons and committed targets", src: appIcon },
|
|
10
|
+
],
|
|
11
|
+
icon: { name: "app-icon.svg", src: appIcon, sizes: [16, 32, 48, 180, 192, 512] },
|
|
12
|
+
} as const;
|
package/dist/brand-assets.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { existsSync, lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { isInside, loadConfig } from "./config.mjs";
|
|
4
5
|
|
|
@@ -45,11 +46,143 @@ function ico(entries) {
|
|
|
45
46
|
return result;
|
|
46
47
|
}
|
|
47
48
|
|
|
49
|
+
const sha256 = bytes => createHash("sha256").update(bytes).digest("hex");
|
|
50
|
+
// Bump when rendering changes, so committed outputs are regenerated.
|
|
51
|
+
const renderer = "ads-brand-targets-1";
|
|
52
|
+
/** The committed record of rendered targets: what each output was made from. */
|
|
53
|
+
export const targetsManifest = "assets/generated.json";
|
|
54
|
+
|
|
55
|
+
/** A target's identity: its master's bytes and its settings, never the rendered pixels. */
|
|
56
|
+
function fingerprint(dsRoot, target) {
|
|
57
|
+
const { from, to, ...settings } = target;
|
|
58
|
+
return sha256(JSON.stringify({ renderer, to, settings, source: sha256(readFileSync(path.join(dsRoot, from))) }));
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function readManifest(dsRoot) {
|
|
62
|
+
try { const value = JSON.parse(readFileSync(path.join(dsRoot, targetsManifest), "utf8")); return value?.outputs && typeof value.outputs === "object" ? value.outputs : {}; }
|
|
63
|
+
catch { return {}; }
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// PNG-encoded ICNS entries by pixel size (a 1024 image is the 512@2x slot).
|
|
67
|
+
const icnsTypes = { 16: "icp4", 32: "icp5", 64: "icp6", 128: "ic07", 256: "ic08", 512: "ic09", 1024: "ic10" };
|
|
68
|
+
function icns(entries) {
|
|
69
|
+
const chunks = entries.map(({ size, buffer }) => {
|
|
70
|
+
const header = Buffer.alloc(8);
|
|
71
|
+
header.write(icnsTypes[size], 0, "ascii");
|
|
72
|
+
header.writeUInt32BE(buffer.length + 8, 4);
|
|
73
|
+
return Buffer.concat([header, buffer]);
|
|
74
|
+
});
|
|
75
|
+
const header = Buffer.alloc(8);
|
|
76
|
+
header.write("icns", 0, "ascii");
|
|
77
|
+
header.writeUInt32BE(8 + chunks.reduce((total, chunk) => total + chunk.length, 0), 4);
|
|
78
|
+
return Buffer.concat([header, ...chunks]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function renderTarget(sharp, source, target) {
|
|
82
|
+
const format = path.extname(target.to).toLowerCase();
|
|
83
|
+
if (format === ".svg") return source;
|
|
84
|
+
const background = target.background;
|
|
85
|
+
const png = async (width, height) => {
|
|
86
|
+
let image = sharp(source, { density: Math.max(72, Math.ceil(Math.max(width, height) * 1.5)) })
|
|
87
|
+
.resize(width, height, { fit: "contain", background: { r: 0, g: 0, b: 0, alpha: 0 } });
|
|
88
|
+
if (background) image = image.flatten({ background });
|
|
89
|
+
return image.png().toBuffer();
|
|
90
|
+
};
|
|
91
|
+
if (format === ".png") return png(target.width ?? target.size, target.height ?? target.size);
|
|
92
|
+
const sizes = [...target.sizes].sort((a, b) => a - b);
|
|
93
|
+
const entries = [];
|
|
94
|
+
for (const size of sizes) entries.push({ size, buffer: await png(size, size) });
|
|
95
|
+
return format === ".ico" ? ico(entries.map(entry => ({ ...entry, size: entry.size === 256 ? 0 : entry.size }))) : icns(entries);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The glyph set as its generated module, or null without one. */
|
|
99
|
+
export function glyphModule({ dsRoot, config }) {
|
|
100
|
+
const glyphs = config.assets.glyphs;
|
|
101
|
+
if (!glyphs) return null;
|
|
102
|
+
const directory = path.join(dsRoot, glyphs.source);
|
|
103
|
+
const aliasFile = path.join(directory, "aliases.json");
|
|
104
|
+
const aliases = existsSync(aliasFile) ? JSON.parse(readFileSync(aliasFile, "utf8")) : {};
|
|
105
|
+
const attributes = glyphs.attributes ?? {};
|
|
106
|
+
const map = {};
|
|
107
|
+
for (const name of readdirSync(directory).filter(name => name.endsWith(".svg")).sort()) {
|
|
108
|
+
const id = name.slice(0, -4);
|
|
109
|
+
if (Object.hasOwn(aliases, id)) continue;
|
|
110
|
+
const svg = readFileSync(path.join(directory, name), "utf8").replace(/<\?xml[\s\S]*?\?>/g, "").trim()
|
|
111
|
+
.replace(/<svg\b([^>]*)>/, (_match, own) => {
|
|
112
|
+
const missing = Object.entries(attributes).filter(([key]) => !new RegExp(`(?:^|\\s)${key}=`).test(own)).map(([key, value]) => ` ${key}="${value}"`).join("");
|
|
113
|
+
return `<svg${missing}${own}>`;
|
|
114
|
+
});
|
|
115
|
+
map[id] = svg;
|
|
116
|
+
}
|
|
117
|
+
for (const [alias, target] of Object.entries(aliases)) if (!Object.hasOwn(map, target)) throw new Error(`${path.join(glyphs.source, "aliases.json")}: ${alias} names a missing glyph ${target}.`);
|
|
118
|
+
return `// Generated by \`ads assets\` from ${glyphs.source}/. Edit the SVGs, not this file.\n`
|
|
119
|
+
+ `export const glyphs = ${JSON.stringify(map, null, 2)} as const;\n`
|
|
120
|
+
+ `export const glyphAliases = ${JSON.stringify(aliases, null, 2)} as const;\n`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Committed outputs that no longer match their masters, settings or rendered bytes. */
|
|
124
|
+
export function staleBrandOutputs(options) {
|
|
125
|
+
const { root, dsRoot, config } = options;
|
|
126
|
+
const stale = [];
|
|
127
|
+
const recorded = readManifest(dsRoot);
|
|
128
|
+
for (const target of config.assets.targets) {
|
|
129
|
+
const file = path.join(root, target.to);
|
|
130
|
+
const entry = recorded[target.to];
|
|
131
|
+
let reason = null;
|
|
132
|
+
if (!existsSync(file)) reason = "is missing";
|
|
133
|
+
else if (!entry || entry.fingerprint !== fingerprint(dsRoot, target)) reason = `no longer matches ${target.from} or its settings`;
|
|
134
|
+
else if (entry.sha256 !== sha256(readFileSync(file))) reason = "was changed by hand";
|
|
135
|
+
if (reason) stale.push({ file: target.to, message: `${target.to} ${reason}. Run ads assets.` });
|
|
136
|
+
}
|
|
137
|
+
const glyphs = config.assets.glyphs;
|
|
138
|
+
if (glyphs) {
|
|
139
|
+
const file = path.join(dsRoot, glyphs.output);
|
|
140
|
+
let expected;
|
|
141
|
+
try { expected = glyphModule(options); } catch (error) { stale.push({ file: path.relative(root, file), message: error.message }); }
|
|
142
|
+
if (expected !== undefined && (!existsSync(file) || readFileSync(file, "utf8") !== expected)) stale.push({ file: path.relative(root, file).replaceAll("\\", "/"), message: `${glyphs.output} is out of date with ${glyphs.source}/. Run ads assets.` });
|
|
143
|
+
}
|
|
144
|
+
return stale;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/** Renders committed targets and the glyph module; unchanged outputs are left alone. */
|
|
148
|
+
async function generateCommitted(options) {
|
|
149
|
+
const { root, dsRoot, config } = options;
|
|
150
|
+
const written = [];
|
|
151
|
+
const recorded = readManifest(dsRoot), next = {};
|
|
152
|
+
let sharp;
|
|
153
|
+
for (const target of config.assets.targets) {
|
|
154
|
+
const file = path.join(root, target.to);
|
|
155
|
+
const print = fingerprint(dsRoot, target);
|
|
156
|
+
const entry = recorded[target.to];
|
|
157
|
+
if (entry?.fingerprint === print && existsSync(file) && entry.sha256 === sha256(readFileSync(file))) { next[target.to] = entry; continue; }
|
|
158
|
+
sharp ??= (await import("sharp")).default;
|
|
159
|
+
const bytes = await renderTarget(sharp, readFileSync(path.join(dsRoot, target.from)), target);
|
|
160
|
+
assertOutput(root, file);
|
|
161
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
162
|
+
writeFileSync(file, bytes);
|
|
163
|
+
written.push(file);
|
|
164
|
+
next[target.to] = { from: target.from, fingerprint: print, sha256: sha256(bytes) };
|
|
165
|
+
}
|
|
166
|
+
const manifest = path.join(dsRoot, targetsManifest);
|
|
167
|
+
if (config.assets.targets.length) {
|
|
168
|
+
const sorted = Object.fromEntries(Object.entries(next).sort(([a], [b]) => a.localeCompare(b)));
|
|
169
|
+
const text = `${JSON.stringify({ schemaVersion: 1, outputs: sorted }, null, 2)}\n`;
|
|
170
|
+
if (!existsSync(manifest) || readFileSync(manifest, "utf8") !== text) { writeFileSync(manifest, text); written.push(manifest); }
|
|
171
|
+
} else if (existsSync(manifest)) { rmSync(manifest); written.push(manifest); }
|
|
172
|
+
const glyphs = glyphModule(options);
|
|
173
|
+
if (glyphs !== null) {
|
|
174
|
+
const file = path.join(dsRoot, config.assets.glyphs.output);
|
|
175
|
+
if (!existsSync(file) || readFileSync(file, "utf8") !== glyphs) { assertOutput(root, file); mkdirSync(path.dirname(file), { recursive: true }); writeFileSync(file, glyphs); written.push(file); }
|
|
176
|
+
}
|
|
177
|
+
return written;
|
|
178
|
+
}
|
|
179
|
+
|
|
48
180
|
export async function generateBrandAssets(directory = process.cwd()) {
|
|
49
181
|
const options = loadConfig(directory);
|
|
50
182
|
const { root, dsRoot, config } = options;
|
|
51
183
|
const output = path.join(root, ".ds/assets");
|
|
52
|
-
|
|
184
|
+
const committed = await generateCommitted(options);
|
|
185
|
+
if (!config.assets.iconSource) return { directory: output, files: [], committed, skipped: !committed.length && !config.assets.targets.length && !config.assets.glyphs };
|
|
53
186
|
const diagnostic = brandSourceDiagnostic(options);
|
|
54
187
|
if (diagnostic) throw new Error(`${diagnostic.file} [${diagnostic.rule}] ${diagnostic.message}`);
|
|
55
188
|
assertOutput(root, output, { directory: true });
|
|
@@ -78,5 +211,5 @@ export async function generateBrandAssets(directory = process.cwd()) {
|
|
|
78
211
|
mkdirSync(output, { recursive: true });
|
|
79
212
|
for (const name of brandFiles) renameSync(path.join(staging, name), path.join(output, name));
|
|
80
213
|
} finally { rmSync(staging, { recursive: true, force: true }); }
|
|
81
|
-
return { directory: output, files: brandFiles.map((name) => path.join(output, name)), skipped: false };
|
|
214
|
+
return { directory: output, files: brandFiles.map((name) => path.join(output, name)), committed, skipped: false };
|
|
82
215
|
}
|
package/dist/check.mjs
CHANGED
|
@@ -54,7 +54,9 @@ export function checkProject(directory, { trackingRoot } = {}) {
|
|
|
54
54
|
const tokenInventory = inspectTokens(root, options);
|
|
55
55
|
const declaredTokens = new Set(tokenInventory.tokens.map((token) => token.name));
|
|
56
56
|
diagnostics.push(...tokenInventory.diagnostics);
|
|
57
|
-
|
|
57
|
+
const assetFindings = inspectAssets(options);
|
|
58
|
+
diagnostics.push(...assetFindings.filter(finding => finding.severity !== "warning"));
|
|
59
|
+
const assetAdvisories = assetFindings.filter(finding => finding.severity === "warning");
|
|
58
60
|
const resolveImport = importResolver(options);
|
|
59
61
|
const units = inspectUnits(options);
|
|
60
62
|
options.testOwner = file => units.owner(units.relative(path.relative(root,file)));
|
|
@@ -336,7 +338,7 @@ export function checkProject(directory, { trackingRoot } = {}) {
|
|
|
336
338
|
inspectDesignAliases(layerStyles,options,report);
|
|
337
339
|
// Bounded clients should see actionable warnings before source-analysis limits.
|
|
338
340
|
for (const { file, css, offset } of layerStyles) layers.inspectStyles(file, css, offset);
|
|
339
|
-
advisories.push(...(tokenInventory.advisories??[]));
|
|
341
|
+
advisories.push(...(tokenInventory.advisories??[]), ...assetAdvisories);
|
|
340
342
|
advisories.sort((first, second) => Number(first.severity === "info") - Number(second.severity === "info"));
|
|
341
343
|
const uniqueDiagnostics=[...new Map(diagnostics.map(diagnostic=>[JSON.stringify([diagnostic.file,diagnostic.rule,diagnostic.line,diagnostic.column,diagnostic.message]),diagnostic])).values()];
|
|
342
344
|
return architectureEvidence({ ok: uniqueDiagnostics.length === 0, diagnostics:uniqueDiagnostics, ...(advisories.length ? { advisories } : {}) });
|