@bridge-ds/core 0.13.0 → 0.16.0
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 +25 -1
- package/bridge.config.schema.json +22 -0
- package/dist/audit/index.js +3 -3
- package/dist/component-scan.d.ts +158 -0
- package/dist/config.d.ts +22 -0
- package/dist/contrast-model.d.ts +43 -0
- package/dist/github-client.d.ts +166 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1446 -355
- package/dist/index.js.map +1 -1
- package/dist/node/fs-source.d.ts +5 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +53 -4
- package/dist/node/index.js.map +1 -1
- package/dist/{prod-branch-6ftQWwdu.js → prod-branch-CSM0c2OF.js} +148 -134
- package/dist/prod-branch-CSM0c2OF.js.map +1 -0
- package/dist/repo-access.d.ts +66 -0
- package/dist/repo-model.d.ts +176 -0
- package/dist/{suggestion-apply-bH6-gZrE.js → repo-source-73kARDJv.js} +478 -204
- package/dist/repo-source-73kARDJv.js.map +1 -0
- package/dist/repo-source-github.d.ts +43 -0
- package/dist/repo-source.d.ts +38 -0
- package/dist/{report-BeWNSjPk.js → report-DbE6yJCw.js} +2 -2
- package/dist/{report-BeWNSjPk.js.map → report-DbE6yJCw.js.map} +1 -1
- package/dist/snapshot.d.ts +137 -0
- package/dist/token-rows.d.ts +122 -0
- package/dist/try-in-product.d.ts +4 -1
- package/package.json +1 -1
- package/dist/prod-branch-6ftQWwdu.js.map +0 -1
- package/dist/suggestion-apply-bH6-gZrE.js.map +0 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import type { AuditMetrics, AuditReport } from './audit/types';
|
|
2
|
+
import type { ContrastPairResult } from './contrast-model';
|
|
3
|
+
import type { SpecCoverage } from './component-spec';
|
|
4
|
+
import { type RepoSource } from './repo-source';
|
|
5
|
+
import type { RepoModel } from './repo-model';
|
|
6
|
+
export declare const SNAPSHOT_SCHEMA_VERSION = 1;
|
|
7
|
+
/** Branch the bridge-data workflow publishes to, and the files on it. */
|
|
8
|
+
export declare const SNAPSHOT_BRANCH = "bridge-data";
|
|
9
|
+
export declare const SNAPSHOT_FILE = "snapshot.json";
|
|
10
|
+
export declare const SNAPSHOT_AUDITS_DIR = "audits";
|
|
11
|
+
/** Above this, a snapshot is refused (a published file the browser downloads whole). */
|
|
12
|
+
export declare const SNAPSHOT_MAX_BYTES = 5000000;
|
|
13
|
+
/** One adoption audit: the summary lives in snapshot.json, the full report in audits/<id>.json next to it. */
|
|
14
|
+
export interface SnapshotAudit {
|
|
15
|
+
id: string;
|
|
16
|
+
/** Path of the full report on the bridge-data branch ("audits/admin.json"). */
|
|
17
|
+
path: string;
|
|
18
|
+
label?: string;
|
|
19
|
+
generatedAt: string;
|
|
20
|
+
target: {
|
|
21
|
+
path: string;
|
|
22
|
+
files: number;
|
|
23
|
+
};
|
|
24
|
+
metrics: AuditMetrics;
|
|
25
|
+
}
|
|
26
|
+
/** A contrast pair as computed when the snapshot was written, without the token rows (the model has them). */
|
|
27
|
+
export type SnapshotContrastPair = Omit<ContrastPairResult, 'fgToken' | 'bgToken'>;
|
|
28
|
+
/** Counts for a header or a card, readable without loading the model. */
|
|
29
|
+
export interface SnapshotSummary {
|
|
30
|
+
tokens: number;
|
|
31
|
+
/** Null when the component scan was skipped. */
|
|
32
|
+
components: number | null;
|
|
33
|
+
contrast: {
|
|
34
|
+
pairs: number;
|
|
35
|
+
checks: number;
|
|
36
|
+
failing: number;
|
|
37
|
+
};
|
|
38
|
+
/** Components in Figma (generated or drafted) out of the visual ones, null without a specs file. */
|
|
39
|
+
figma: {
|
|
40
|
+
inFigma: number;
|
|
41
|
+
visual: number;
|
|
42
|
+
} | null;
|
|
43
|
+
}
|
|
44
|
+
export interface RepoSnapshot {
|
|
45
|
+
kind: 'bridge-snapshot';
|
|
46
|
+
schemaVersion: typeof SNAPSHOT_SCHEMA_VERSION;
|
|
47
|
+
tool: {
|
|
48
|
+
name: 'bridge';
|
|
49
|
+
version: string;
|
|
50
|
+
};
|
|
51
|
+
generatedAt: string;
|
|
52
|
+
repo: {
|
|
53
|
+
owner: string;
|
|
54
|
+
name: string;
|
|
55
|
+
branch: string;
|
|
56
|
+
};
|
|
57
|
+
/** Commit the snapshot was computed from. Fresh when it equals the default branch head. */
|
|
58
|
+
sourceSha: string;
|
|
59
|
+
/** Commit date of sourceSha (ISO), when known. */
|
|
60
|
+
committedAt?: string;
|
|
61
|
+
/** Every path the model listed (token root, components dir), so list() answers as the repository did. */
|
|
62
|
+
paths: string[];
|
|
63
|
+
/** Bodies of the files the model read, keyed by repo-relative path. */
|
|
64
|
+
files: Record<string, string>;
|
|
65
|
+
/**
|
|
66
|
+
* Figma coverage of component-specs.json without the specs themselves (the file is over 1 MB here, too big for
|
|
67
|
+
* the GitHub contents source). Null when the repository has no specs file.
|
|
68
|
+
*/
|
|
69
|
+
figma: {
|
|
70
|
+
path: string;
|
|
71
|
+
generated?: string;
|
|
72
|
+
coverage: SpecCoverage[];
|
|
73
|
+
} | null;
|
|
74
|
+
summary: SnapshotSummary;
|
|
75
|
+
/** Contrast results as computed when the snapshot was written (the model recomputes the same from files). */
|
|
76
|
+
contrast: {
|
|
77
|
+
path?: string;
|
|
78
|
+
pairs: SnapshotContrastPair[];
|
|
79
|
+
};
|
|
80
|
+
audits: SnapshotAudit[];
|
|
81
|
+
/** What could not be read when the snapshot was written. */
|
|
82
|
+
problems: string[];
|
|
83
|
+
/**
|
|
84
|
+
* The global stylesheet globs the model read (components.styles), their files among `files`. Absent from a snapshot
|
|
85
|
+
* written before Bridge read global stylesheets: a reader then reads those files from the repository.
|
|
86
|
+
*/
|
|
87
|
+
styles?: string[];
|
|
88
|
+
}
|
|
89
|
+
export declare class SnapshotError extends Error {
|
|
90
|
+
}
|
|
91
|
+
/** Validates a snapshot (text or parsed JSON). Throws SnapshotError naming the first problem. */
|
|
92
|
+
export declare function parseSnapshot(input: string | unknown): RepoSnapshot;
|
|
93
|
+
/** True when the snapshot was computed from `headSha` (the default branch head): use it instead of a live read. */
|
|
94
|
+
export declare const snapshotIsFresh: (snapshot: Pick<RepoSnapshot, "sourceSha">, headSha: string | undefined) => boolean;
|
|
95
|
+
/**
|
|
96
|
+
* A RepoSource over a snapshot. The Figma specs path serves a compact file with the coverage only (no component
|
|
97
|
+
* specs), so the model reads the coverage and leaves `specs.file` null.
|
|
98
|
+
*/
|
|
99
|
+
export declare function snapshotSource(snapshot: RepoSnapshot): RepoSource;
|
|
100
|
+
/**
|
|
101
|
+
* Wraps a source and records what it lists and reads, so a snapshot carries exactly the files the model needs and
|
|
102
|
+
* nothing else of the repository.
|
|
103
|
+
*/
|
|
104
|
+
export declare function recordingSource(source: RepoSource): {
|
|
105
|
+
source: RepoSource;
|
|
106
|
+
paths: Set<string>;
|
|
107
|
+
files: Map<string, string>;
|
|
108
|
+
};
|
|
109
|
+
/** Summary of an audit report for snapshot.json; the full report is written to `path`. */
|
|
110
|
+
export declare function snapshotAudit(id: string, report: AuditReport): SnapshotAudit;
|
|
111
|
+
/** A safe audit id from a label or path ("apps/admin/src" -> "apps-admin-src"). */
|
|
112
|
+
export declare const auditId: (s: string) => string;
|
|
113
|
+
export interface BuildSnapshotInput {
|
|
114
|
+
model: RepoModel;
|
|
115
|
+
/** From recordingSource(): what loadRepoModel listed and read. */
|
|
116
|
+
paths: Iterable<string>;
|
|
117
|
+
files: Map<string, string> | Record<string, string>;
|
|
118
|
+
version: string;
|
|
119
|
+
branch?: string;
|
|
120
|
+
committedAt?: string;
|
|
121
|
+
generatedAt?: string;
|
|
122
|
+
audits?: SnapshotAudit[];
|
|
123
|
+
}
|
|
124
|
+
/** Counts of a model for the snapshot summary. */
|
|
125
|
+
export declare function snapshotSummary(model: RepoModel): SnapshotSummary;
|
|
126
|
+
/** Assembles the snapshot from a model and the files it was read from. The specs file becomes the coverage list. */
|
|
127
|
+
export declare function buildSnapshot(input: BuildSnapshotInput): RepoSnapshot;
|
|
128
|
+
/** llms.txt next to snapshot.json on the bridge-data branch: the published design system in plain text, for agents. */
|
|
129
|
+
export declare const SNAPSHOT_LLMS_FILE = "llms.txt";
|
|
130
|
+
/** Above this many tokens, llms.txt lists the first ones and points at snapshot.json for the rest. */
|
|
131
|
+
export declare const LLMS_MAX_TOKENS = 600;
|
|
132
|
+
/**
|
|
133
|
+
* The design system of a snapshot as llms.txt (https://llmstxt.org): what it is, every token with its CSS variable and
|
|
134
|
+
* values per theme, and every component with its usage guidance. Written by `bridge snapshot`; the hosted Library
|
|
135
|
+
* links to it. Pure: the model the snapshot was computed from goes in, text comes out.
|
|
136
|
+
*/
|
|
137
|
+
export declare function snapshotLlmsTxt(model: RepoModel, snapshot: Pick<RepoSnapshot, 'repo' | 'sourceSha' | 'committedAt' | 'generatedAt'>): string;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { type BridgeConfig } from './config';
|
|
2
|
+
/** Token tiers of the rows, in resolution order: primitive <- brand <- semantic <- component. Density sits beside semantic. */
|
|
3
|
+
export type TokenRowTier = 'primitive' | 'brand' | 'semantic' | 'density' | 'component';
|
|
4
|
+
type Json = Record<string, unknown>;
|
|
5
|
+
export interface RawTokenEntry {
|
|
6
|
+
path: string[];
|
|
7
|
+
type: string;
|
|
8
|
+
value: unknown;
|
|
9
|
+
description?: string;
|
|
10
|
+
/** DTCG $deprecated: true, or a string explaining what to use instead. */
|
|
11
|
+
deprecated?: boolean | string;
|
|
12
|
+
/** Repo-relative file the token is declared in. */
|
|
13
|
+
file: string;
|
|
14
|
+
}
|
|
15
|
+
export interface PrimitiveRow {
|
|
16
|
+
path: string;
|
|
17
|
+
segments: string[];
|
|
18
|
+
type: string;
|
|
19
|
+
/** Resolved CSS value. */
|
|
20
|
+
css: string;
|
|
21
|
+
hex?: string;
|
|
22
|
+
cssVar: string;
|
|
23
|
+
figma: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
deprecated?: boolean | string;
|
|
26
|
+
raw: unknown;
|
|
27
|
+
file: string;
|
|
28
|
+
}
|
|
29
|
+
export interface TokenRowMode {
|
|
30
|
+
/** First alias target, or null when the value is literal. */
|
|
31
|
+
alias: string | null;
|
|
32
|
+
/** Every alias hop, from the token to the final primitive (palette roles included). */
|
|
33
|
+
chain: string[];
|
|
34
|
+
css: string;
|
|
35
|
+
hex?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface TokenRow {
|
|
38
|
+
path: string;
|
|
39
|
+
segments: string[];
|
|
40
|
+
type: string;
|
|
41
|
+
cssVar: string;
|
|
42
|
+
figma: string;
|
|
43
|
+
description?: string;
|
|
44
|
+
/** e.g. "color.action" or "elevation". */
|
|
45
|
+
group: string;
|
|
46
|
+
deprecated?: boolean | string;
|
|
47
|
+
tier: Exclude<TokenRowTier, 'primitive'>;
|
|
48
|
+
/** Source file(s) the token is declared in, repo-relative. */
|
|
49
|
+
file: string;
|
|
50
|
+
/** Values per theme in the default brand and default density. */
|
|
51
|
+
modes: Record<string, TokenRowMode>;
|
|
52
|
+
/** Values per brand x theme (default density). */
|
|
53
|
+
brands: Record<string, Record<string, TokenRowMode>>;
|
|
54
|
+
/** Density tokens only: value per density. */
|
|
55
|
+
densities?: Record<string, TokenRowMode>;
|
|
56
|
+
/** True when the brand x theme values differ from the default brand. */
|
|
57
|
+
brandSpecific: boolean;
|
|
58
|
+
}
|
|
59
|
+
/** Brand, theme and density lists the rows are computed for, with their defaults and display names. */
|
|
60
|
+
export interface TokenRowAxes {
|
|
61
|
+
brands: string[];
|
|
62
|
+
defaultBrand: string;
|
|
63
|
+
/** Display name per brand: the name a brand file records ($extensions dev.bridge.brand.name), else the slug in title case. */
|
|
64
|
+
brandLabels: Record<string, string>;
|
|
65
|
+
themes: string[];
|
|
66
|
+
densities: string[];
|
|
67
|
+
defaultDensity: string;
|
|
68
|
+
}
|
|
69
|
+
/** Repo-relative token files the rows read, from the tier folders of the config. */
|
|
70
|
+
export interface TokenRowFiles {
|
|
71
|
+
primitivesDir: string;
|
|
72
|
+
semanticDir: string;
|
|
73
|
+
brandsDir: string;
|
|
74
|
+
densityDir: string;
|
|
75
|
+
componentsDir: string;
|
|
76
|
+
baseFile: string;
|
|
77
|
+
semanticFile(theme: string): string;
|
|
78
|
+
brandFile(brand: string): string;
|
|
79
|
+
overrideFile(brand: string, theme: string): string;
|
|
80
|
+
densityFile(density: string): string;
|
|
81
|
+
}
|
|
82
|
+
export interface TokenRows extends TokenRowAxes {
|
|
83
|
+
primitives: PrimitiveRow[];
|
|
84
|
+
/** Semantic tier: themed (one file per theme) and theme-independent (base). */
|
|
85
|
+
semantic: TokenRow[];
|
|
86
|
+
/** Brand tier: palette, radius and font roles per brand. */
|
|
87
|
+
brand: TokenRow[];
|
|
88
|
+
density: TokenRow[];
|
|
89
|
+
component: TokenRow[];
|
|
90
|
+
/** Every non-primitive token: brand, semantic, density, component. */
|
|
91
|
+
all: TokenRow[];
|
|
92
|
+
/** Repo-relative paths of every token source file, in tier order (what the "last updated" line watches). */
|
|
93
|
+
sources: string[];
|
|
94
|
+
}
|
|
95
|
+
/** Brand, theme and density lists from bridge.config.json, as the docs pages iterate them. */
|
|
96
|
+
export declare function tokenRowAxes(config: BridgeConfig, readText?: (path: string) => string | undefined): TokenRowAxes;
|
|
97
|
+
/** The token files of each tier, repo-relative, from the config's tokens.root and tier folders. */
|
|
98
|
+
export declare function tokenRowFiles(config: BridgeConfig): TokenRowFiles;
|
|
99
|
+
/** Flattens one DTCG document into raw tokens, inheriting $type from groups. */
|
|
100
|
+
export declare function flattenTokenFile(node: Json, file: string, path?: string[], inheritedType?: string): RawTokenEntry[];
|
|
101
|
+
/** CSS text (and hex for colors) of a literal DTCG value. */
|
|
102
|
+
export declare function tokenValueCss(type: string, value: unknown): {
|
|
103
|
+
css: string;
|
|
104
|
+
hex?: string;
|
|
105
|
+
};
|
|
106
|
+
/** CSS variable of a token path ("color.bg.default" segments -> "--color-bg-default"). */
|
|
107
|
+
export declare const tokenRowCssVar: (segments: string[]) => string;
|
|
108
|
+
/** Figma variable name of a token path. */
|
|
109
|
+
export declare const tokenRowFigmaName: (segments: string[]) => string;
|
|
110
|
+
/**
|
|
111
|
+
* Builds the rows from the token files of a repo. `readText` returns a repo-relative file body (undefined when
|
|
112
|
+
* missing); `listFiles` returns the repo-relative files directly inside a directory. Throws on an alias that does not
|
|
113
|
+
* resolve and on a themed token missing from another theme, as the token build does.
|
|
114
|
+
*/
|
|
115
|
+
export declare function buildTokenRows(config: BridgeConfig, readText: (path: string) => string | undefined, listFiles: (dir: string) => string[]): TokenRows;
|
|
116
|
+
/** Every CSS variable the rows define: cssVar -> token path, tier and type. */
|
|
117
|
+
export declare function tokenRowIndex(rows: Pick<TokenRows, 'primitives' | 'all'>): Map<string, {
|
|
118
|
+
path: string;
|
|
119
|
+
kind: TokenRowTier;
|
|
120
|
+
type: string;
|
|
121
|
+
}>;
|
|
122
|
+
export {};
|
package/dist/try-in-product.d.ts
CHANGED
|
@@ -12,5 +12,8 @@ export declare function productPreview(apps: PreviewApps, ctx: {
|
|
|
12
12
|
sha: string;
|
|
13
13
|
fromFork?: boolean;
|
|
14
14
|
}, sources: BranchPreviewSources): string | null;
|
|
15
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* The preview with the toolbar on, at that screen (shop and theme in the query, the hash route ra-core reads), else home.
|
|
17
|
+
* Only http(s) previews: anything else (a javascript: or data: URL in a hostile comment) gives ''.
|
|
18
|
+
*/
|
|
16
19
|
export declare function tryInProductUrl(preview: string, pr: number, screen: ProductScreen | null): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bridge-ds/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Bridge core: bridge.config.json, DTCG token loading (tiers and layered modes), alias resolution, WCAG contrast, diffs, minimal-diff edits, PR body, the shared risk tier classifier, changesets and a fetch-based GitHub client. No Figma API, no DOM; Node-only helpers (git, reading a product folder) under @bridge-ds/core/node; the adoption audit under @bridge-ds/core/audit.",
|
|
6
6
|
"license": "MIT",
|