@bridge-ds/toolbar 0.1.0 → 0.2.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 +6 -1
- package/dist/BridgeToolbar.d.ts +6 -0
- package/dist/{Toolbar-B-p9ZCvk.js → Toolbar-CzR1TM9x.js} +24 -28
- package/dist/Toolbar-CzR1TM9x.js.map +1 -0
- package/dist/config.d.ts +4 -1
- package/dist/github.d.ts +5 -2
- package/dist/{index-yvFRSnsp.js → index-3f0I3tAL.js} +54 -6
- package/dist/index-3f0I3tAL.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/reads.d.ts +22 -0
- package/dist/session-CzlIsFDY.js.map +1 -1
- package/dist/session.d.ts +2 -0
- package/package.json +2 -2
- package/dist/Toolbar-B-p9ZCvk.js.map +0 -1
- package/dist/index-yvFRSnsp.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import { lazy, useState, Suspense, useEffect, useMemo } from "react";
|
|
3
3
|
import { r as readChanges } from "./session-CzlIsFDY.js";
|
|
4
|
-
const Toolbar = lazy(() => import("./Toolbar-
|
|
4
|
+
const Toolbar = lazy(() => import("./Toolbar-CzR1TM9x.js"));
|
|
5
5
|
function asked() {
|
|
6
6
|
let store = null;
|
|
7
7
|
try {
|
|
@@ -44,6 +44,48 @@ function useDocumentScope() {
|
|
|
44
44
|
[here]
|
|
45
45
|
);
|
|
46
46
|
}
|
|
47
|
+
const DEFAULT_PROXY = "https://bridge.floriangouloubi.com";
|
|
48
|
+
const API = "https://api.github.com";
|
|
49
|
+
const RAW = "https://raw.githubusercontent.com";
|
|
50
|
+
class ReadError extends Error {
|
|
51
|
+
constructor(message, status) {
|
|
52
|
+
super(message);
|
|
53
|
+
this.status = status;
|
|
54
|
+
}
|
|
55
|
+
status;
|
|
56
|
+
}
|
|
57
|
+
const LIMIT = "GitHub limits reads without an account to 60 an hour. Try again later.";
|
|
58
|
+
const errorOf = (status) => new ReadError(status === 403 || status === 429 ? LIMIT : `GitHub answered ${status}.`, status);
|
|
59
|
+
const down = /* @__PURE__ */ new Set();
|
|
60
|
+
const proxyRefused = (r) => r.status === 400 || r.status === 401 || r.status === 403 || r.status === 409 || r.status === 429 || r.status >= 500;
|
|
61
|
+
const segments = (path) => path.split("/").map(encodeURIComponent).join("/");
|
|
62
|
+
function githubReads({ team, proxy, fetch: f = (...a) => fetch(...a) }) {
|
|
63
|
+
const base = proxy ? proxy.replace(/\/+$/, "") : null;
|
|
64
|
+
async function read2(gh, accept, direct) {
|
|
65
|
+
if (base && !down.has(base)) {
|
|
66
|
+
try {
|
|
67
|
+
const r = await f(`${base}/api/contribute?repo=${encodeURIComponent(team)}&gh=${encodeURIComponent(gh)}`, { headers: { Accept: accept }, credentials: "omit" });
|
|
68
|
+
if (!proxyRefused(r)) return r;
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
down.add(base);
|
|
72
|
+
}
|
|
73
|
+
return f(direct, direct.startsWith(API) ? { headers: { Accept: accept } } : {});
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
async api(path) {
|
|
77
|
+
const r = await read2(path, "application/vnd.github+json", `${API}${path}`);
|
|
78
|
+
if (!r.ok) throw errorOf(r.status);
|
|
79
|
+
return await r.json();
|
|
80
|
+
},
|
|
81
|
+
async file(owner, repo, ref, path) {
|
|
82
|
+
const gh = `/repos/${owner}/${repo}/contents/${segments(path)}${ref ? `?ref=${encodeURIComponent(ref)}` : ""}`;
|
|
83
|
+
const r = await read2(gh, "application/vnd.github.raw", `${RAW}/${owner}/${repo}/${ref ?? "HEAD"}/${segments(path)}`);
|
|
84
|
+
if (!r.ok) throw errorOf(r.status);
|
|
85
|
+
return r.text();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
47
89
|
const REPO = /^[\w.-]+\/[\w.-]+$/;
|
|
48
90
|
function buildFromConfig(raw, ds, product, overrides = {}) {
|
|
49
91
|
if (!raw || typeof raw !== "object" || !REPO.test(ds)) return null;
|
|
@@ -60,6 +102,7 @@ function buildFromConfig(raw, ds, product, overrides = {}) {
|
|
|
60
102
|
production: pick(overrides.production, entry.production ?? config.previews?.production?.[product]),
|
|
61
103
|
preview: pick(overrides.preview, entry.preview ?? config.previews?.apps?.[product]),
|
|
62
104
|
deployEnv: overrides.deployEnv ?? null,
|
|
105
|
+
...overrides.proxy !== void 0 ? { proxy: overrides.proxy } : {},
|
|
63
106
|
defaultBranch: config.repo?.defaultBranch ?? "main",
|
|
64
107
|
tokensRoot: config.tokens?.root ?? "packages/tokens/src",
|
|
65
108
|
product,
|
|
@@ -67,7 +110,7 @@ function buildFromConfig(raw, ds, product, overrides = {}) {
|
|
|
67
110
|
};
|
|
68
111
|
}
|
|
69
112
|
const cacheKey = (ds) => `bridge-toolbar:config:v1:${ds}`;
|
|
70
|
-
async function loadBuild(ds, product, overrides = {}) {
|
|
113
|
+
async function loadBuild(ds, product, overrides = {}, gh) {
|
|
71
114
|
let config = null;
|
|
72
115
|
try {
|
|
73
116
|
const cached = window.sessionStorage.getItem(cacheKey(ds));
|
|
@@ -76,9 +119,12 @@ async function loadBuild(ds, product, overrides = {}) {
|
|
|
76
119
|
}
|
|
77
120
|
if (!config) {
|
|
78
121
|
if (!REPO.test(ds)) throw new Error(`"${ds}" is not a GitHub repository (owner/name).`);
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
122
|
+
const [owner, name] = ds.split("/");
|
|
123
|
+
const reads = githubReads({ team: ds, proxy: overrides.proxy === void 0 ? DEFAULT_PROXY : overrides.proxy });
|
|
124
|
+
const text = await reads.file(owner, name, null, "bridge.config.json").catch((e) => {
|
|
125
|
+
throw new Error(`Could not read bridge.config.json from ${ds} (${e.message})`);
|
|
126
|
+
});
|
|
127
|
+
config = JSON.parse(text);
|
|
82
128
|
try {
|
|
83
129
|
window.sessionStorage.setItem(cacheKey(ds), JSON.stringify(config));
|
|
84
130
|
} catch {
|
|
@@ -90,8 +136,10 @@ async function loadBuild(ds, product, overrides = {}) {
|
|
|
90
136
|
}
|
|
91
137
|
export {
|
|
92
138
|
BridgeToolbar as B,
|
|
139
|
+
DEFAULT_PROXY as D,
|
|
93
140
|
buildFromConfig as b,
|
|
141
|
+
githubReads as g,
|
|
94
142
|
loadBuild as l,
|
|
95
143
|
useDocumentScope as u
|
|
96
144
|
};
|
|
97
|
-
//# sourceMappingURL=index-
|
|
145
|
+
//# sourceMappingURL=index-3f0I3tAL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-3f0I3tAL.js","sources":["../src/BridgeToolbar.tsx","../src/scope.ts","../src/reads.ts","../src/config.ts"],"sourcesContent":["// The one line a product mounts at its root: <BridgeToolbar ds=\"owner/design-system\" product=\"checkout\" />. It renders\n// nothing and loads nothing unless Bridge Studio opened the page with `?bridge=<change>` (kept for the session), then\n// loads the toolbar itself as one lazy chunk, with its styles.\nimport { lazy, Suspense, useState } from 'react';\nimport { readChanges, type BridgeBuild } from './session';\nimport type { ToolbarScope, ToolbarShop } from './scope';\nimport type { TogetherBase } from './together';\n\nexport interface BridgeToolbarProps {\n /** The design system repository, \"owner/name\". The toolbar reads its bridge.config.json when Studio opens the page. */\n ds?: string;\n /** This product's key in the design system's bridge.config.json products[] (\"checkout\"). */\n product?: string;\n /** Overrides of what the config says: production Studio, this product in production, its preview template. */\n studio?: string | null;\n production?: string | null;\n preview?: string | null;\n /**\n * Bridge's origin, whose read proxy serves the toolbar's GitHub reads (no limit of 60 an hour per visitor). Default\n * production Bridge (https://bridge.floriangouloubi.com); null reads GitHub directly. GitHub directly anyway when\n * Bridge refuses or cannot be reached.\n */\n proxy?: string | null;\n /** The deploy environment (\"production\", \"preview\"), when the host tells it at build time (VERCEL_ENV). */\n deployEnv?: string | null;\n /** Every fact at once, read at build time: no config read at run time (the Admin demo passes it). */\n build?: BridgeBuild;\n /** A hook that says where the page is and moves it (theme, shop). Default: the attributes ThemeProvider sets on <html>. */\n scope?: () => ToolbarScope;\n /** The shops of a multi-brand product, for the screens list and \"Switch to <shop>\". */\n shops?: ToolbarShop[];\n /** The latest library's token files as a combination base: lets Studio's \"Try them together\" run here. */\n together?: () => Promise<TogetherBase>;\n}\n\nconst Toolbar = lazy(() => import('./Toolbar'));\n\nfunction asked(): boolean {\n let store: Storage | null = null;\n try {\n store = window.sessionStorage;\n } catch {\n store = null;\n }\n return readChanges(window.location.search, store).length > 0;\n}\n\n/** Mounted once at the app root. Without a change from Studio it renders nothing and loads nothing. */\nexport function BridgeToolbar(props: BridgeToolbarProps) {\n const [on] = useState(() => typeof window !== 'undefined' && asked());\n if (!on) return null;\n return (\n <Suspense fallback={null}>\n <Toolbar {...props} />\n </Suspense>\n );\n}\n","// Where the page is (theme, brand, density, shop) and how the toolbar moves it there. A product passes its own hook\n// when it keeps these in state (the Admin demo's preferences); by default the toolbar reads the attributes the\n// design system's ThemeProvider (asRoot) puts on <html> and sets data-theme there.\nimport { useEffect, useMemo, useState } from 'react';\n\nexport interface ToolbarScope {\n theme: 'light' | 'dark';\n brand: string;\n density: string;\n /** The shop (tenant) the page shows, when the product has several. */\n shop?: string;\n /** Moves the page to a theme, a shop or both, in one step. */\n set: (next: { theme?: 'light' | 'dark'; shop?: string }) => void;\n}\n\n/** A shop of a multi-brand product: its id (in `?tenant=` links), its name and its brand. */\nexport interface ToolbarShop {\n id: string;\n name: string;\n brand: string;\n}\n\nconst read = () => {\n const el = document.documentElement;\n return {\n theme: (el.getAttribute('data-theme') === 'dark' ? 'dark' : 'light') as 'light' | 'dark',\n brand: el.getAttribute('data-brand') || 'bridge',\n density: el.getAttribute('data-density') || 'comfortable',\n };\n};\n\n/** The default scope: <html data-theme data-brand data-density>, kept in sync. */\nexport function useDocumentScope(): ToolbarScope {\n const [here, setHere] = useState(read);\n useEffect(() => {\n const mo = new MutationObserver(() => setHere((p) => {\n const n = read();\n return n.theme === p.theme && n.brand === p.brand && n.density === p.density ? p : n;\n }));\n mo.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme', 'data-brand', 'data-density'] });\n return () => mo.disconnect();\n }, []);\n return useMemo(\n () => ({\n ...here,\n set: (next) => {\n if (next.theme) document.documentElement.setAttribute('data-theme', next.theme);\n },\n }),\n [here],\n );\n}\n","// How the toolbar reads GitHub: through Bridge's read proxy (GET <proxy>/api/contribute?repo=<design system>&gh=<path>,\n// allow-listed, cached, with a read-only token on the server), so a visitor never meets GitHub's limit of 60 anonymous\n// reads an hour per address. When Bridge refuses or cannot be reached (an older Bridge, a design system it does not\n// serve, an origin its config does not name), the toolbar reads GitHub directly, as before, for the rest of the page.\n// The requests stay \"simple\" (GET, Accept only, no credentials): no CORS preflight, no cookie sent.\n\n/** Production Bridge: the read proxy the toolbar uses unless the product says otherwise. */\nexport const DEFAULT_PROXY = 'https://bridge.floriangouloubi.com';\n\nconst API = 'https://api.github.com';\nconst RAW = 'https://raw.githubusercontent.com';\n\nexport interface ReadsOptions {\n /** The design system repository (\"owner/name\"): Bridge serves its reads and those of the products it lists. */\n team: string;\n /** Bridge's origin, or null to read GitHub directly. */\n proxy: string | null;\n fetch?: typeof fetch;\n}\n\nexport interface Reads {\n /** A GitHub REST read under /repos/<owner>/<name>/..., as JSON. */\n api<T>(path: string): Promise<T>;\n /** A file of a repository at a ref (a sha or a branch; none: the default branch), as text. */\n file(owner: string, repo: string, ref: string | null, path: string): Promise<string>;\n}\n\nexport class ReadError extends Error {\n constructor(\n message: string,\n readonly status: number,\n ) {\n super(message);\n }\n}\n\nconst LIMIT = 'GitHub limits reads without an account to 60 an hour. Try again later.';\nconst errorOf = (status: number) => new ReadError(status === 403 || status === 429 ? LIMIT : `GitHub answered ${status}.`, status);\n\n/** Proxies that refused or did not answer on this page: every later read goes to GitHub directly. */\nconst down = new Set<string>();\n\n/** Tests start fresh. */\nexport function resetReads() {\n down.clear();\n}\n\n/**\n * Bridge's answer is GitHub's when it read GitHub (any status but its own refusals). Its own: 400 (a path it does not\n * take), 401 (no reader), 403 (not allowed, origin), 409 (app missing), 429 (busy), 5xx; then GitHub directly.\n */\nconst proxyRefused = (r: Response) => r.status === 400 || r.status === 401 || r.status === 403 || r.status === 409 || r.status === 429 || r.status >= 500;\n\nconst segments = (path: string) => path.split('/').map(encodeURIComponent).join('/');\n\nexport function githubReads({ team, proxy, fetch: f = (...a) => fetch(...a) }: ReadsOptions): Reads {\n const base = proxy ? proxy.replace(/\\/+$/, '') : null;\n\n /** Bridge first, then GitHub. `direct` is GitHub's own URL for the same read. */\n async function read(gh: string, accept: string, direct: string): Promise<Response> {\n if (base && !down.has(base)) {\n try {\n const r = await f(`${base}/api/contribute?repo=${encodeURIComponent(team)}&gh=${encodeURIComponent(gh)}`, { headers: { Accept: accept }, credentials: 'omit' });\n if (!proxyRefused(r)) return r;\n } catch {\n // Unreachable, or the browser refused the answer (CORS): GitHub directly.\n }\n down.add(base);\n }\n return f(direct, direct.startsWith(API) ? { headers: { Accept: accept } } : {});\n }\n\n return {\n async api<T>(path: string): Promise<T> {\n const r = await read(path, 'application/vnd.github+json', `${API}${path}`);\n if (!r.ok) throw errorOf(r.status);\n return (await r.json()) as T;\n },\n async file(owner, repo, ref, path) {\n const gh = `/repos/${owner}/${repo}/contents/${segments(path)}${ref ? `?ref=${encodeURIComponent(ref)}` : ''}`;\n const r = await read(gh, 'application/vnd.github.raw', `${RAW}/${owner}/${repo}/${ref ?? 'HEAD'}/${segments(path)}`);\n if (!r.ok) throw errorOf(r.status);\n return r.text();\n },\n };\n}\n","// Where a product's toolbar gets its facts when it is mounted with only the design system repository and its product\n// key: the design system's bridge.config.json, read once per session through Bridge's read proxy (GitHub directly when\n// Bridge refuses; public repositories, no account). Pure part (buildFromConfig) is tested; loadBuild adds the read and\n// the session cache.\nimport { DEFAULT_PROXY, githubReads, type Reads } from './reads';\nimport type { BridgeBuild } from './session';\n\ninterface ConfigLike {\n repo?: { owner?: string; name?: string; defaultBranch?: string };\n tokens?: { root?: string };\n previews?: { apps?: Record<string, string | undefined>; production?: Record<string, string | undefined> };\n products?: { key?: string; repo?: string; preview?: string; production?: string }[];\n}\n\n/** Values the product sets itself win over the config: the Studio, production and preview URLs. */\nexport interface BuildOverrides {\n studio?: string | null;\n production?: string | null;\n preview?: string | null;\n deployEnv?: string | null;\n /** Bridge's origin for reads (default production Bridge), null to read GitHub directly. */\n proxy?: string | null;\n}\n\nconst REPO = /^[\\w.-]+\\/[\\w.-]+$/;\n\n/**\n * The toolbar's facts for one product of a design system config: its repository (its own, else the design system's),\n * production Studio, its production URL and preview template. Null when the product is not in the config.\n */\nexport function buildFromConfig(raw: unknown, ds: string, product: string, overrides: BuildOverrides = {}): BridgeBuild | null {\n if (!raw || typeof raw !== 'object' || !REPO.test(ds)) return null;\n const config = raw as ConfigLike;\n const entry = (config.products ?? []).find((p) => p?.key === product);\n if (!entry) return null;\n const own = entry.repo && REPO.test(entry.repo) ? entry.repo : null;\n const [owner, repo] = (own ?? ds).split('/') as [string, string];\n const pick = (v: string | null | undefined, fallback: string | null | undefined) => (v !== undefined ? v : (fallback ?? null));\n return {\n owner,\n repo,\n studio: pick(overrides.studio, config.previews?.production?.docs),\n production: pick(overrides.production, entry.production ?? config.previews?.production?.[product]),\n preview: pick(overrides.preview, entry.preview ?? config.previews?.apps?.[product]),\n deployEnv: overrides.deployEnv ?? null,\n ...(overrides.proxy !== undefined ? { proxy: overrides.proxy } : {}),\n defaultBranch: config.repo?.defaultBranch ?? 'main',\n tokensRoot: config.tokens?.root ?? 'packages/tokens/src',\n product,\n ds,\n };\n}\n\nconst cacheKey = (ds: string) => `bridge-toolbar:config:v1:${ds}`;\n\n/** Reads the design system's bridge.config.json (its default branch), kept for the session. */\nexport async function loadBuild(ds: string, product: string, overrides: BuildOverrides = {}, gh?: Reads): Promise<BridgeBuild> {\n let config: unknown = null;\n try {\n const cached = window.sessionStorage.getItem(cacheKey(ds));\n if (cached) config = JSON.parse(cached);\n } catch {\n // Storage blocked or a broken entry: read it again.\n }\n if (!config) {\n if (!REPO.test(ds)) throw new Error(`\"${ds}\" is not a GitHub repository (owner/name).`);\n const [owner, name] = ds.split('/') as [string, string];\n const reads = gh ?? githubReads({ team: ds, proxy: overrides.proxy === undefined ? DEFAULT_PROXY : overrides.proxy });\n const text = await reads.file(owner, name, null, 'bridge.config.json').catch((e: Error) => {\n throw new Error(`Could not read bridge.config.json from ${ds} (${e.message})`);\n });\n config = JSON.parse(text);\n try {\n window.sessionStorage.setItem(cacheKey(ds), JSON.stringify(config));\n } catch {\n // Storage blocked: the next page reads it again.\n }\n }\n const build = buildFromConfig(config, ds, product, overrides);\n if (!build) throw new Error(`No product \"${product}\" in ${ds}'s bridge.config.json.`);\n return build;\n}\n"],"names":["read"],"mappings":";;;AAmCA,MAAM,UAAU,KAAK,MAAM,OAAO,uBAAW,CAAC;AAE9C,SAAS,QAAiB;AACxB,MAAI,QAAwB;AAC5B,MAAI;AACF,YAAQ,OAAO;AAAA,EACjB,QAAQ;AACN,YAAQ;AAAA,EACV;AACA,SAAO,YAAY,OAAO,SAAS,QAAQ,KAAK,EAAE,SAAS;AAC7D;AAGO,SAAS,cAAc,OAA2B;AACvD,QAAM,CAAC,EAAE,IAAI,SAAS,MAAM,OAAO,WAAW,eAAe,OAAO;AACpE,MAAI,CAAC,GAAI,QAAO;AAChB,SACE,oBAAC,YAAS,UAAU,MAClB,8BAAC,SAAA,EAAS,GAAG,OAAO,EAAA,CACtB;AAEJ;AClCA,MAAM,OAAO,MAAM;AACjB,QAAM,KAAK,SAAS;AACpB,SAAO;AAAA,IACL,OAAQ,GAAG,aAAa,YAAY,MAAM,SAAS,SAAS;AAAA,IAC5D,OAAO,GAAG,aAAa,YAAY,KAAK;AAAA,IACxC,SAAS,GAAG,aAAa,cAAc,KAAK;AAAA,EAAA;AAEhD;AAGO,SAAS,mBAAiC;AAC/C,QAAM,CAAC,MAAM,OAAO,IAAI,SAAS,IAAI;AACrC,YAAU,MAAM;AACd,UAAM,K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I,GAAG,MAAM,GAAG;AAClC,UAAM,QAAc,YAAY,EAAE,MAAM,IAAI,OAAO,UAAU,UAAU,SAAY,gBAAgB,UAAU,OAAO;AACpH,UAAM,OAAO,MAAM,MAAM,KAAK,OAAO,MAAM,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAa;AACzF,YAAM,IAAI,MAAM,0CAA0C,EAAE,KAAK,EAAE,OAAO,GAAG;AAAA,IAC/E,CAAC;AACD,aAAS,KAAK,MAAM,IAAI;AACxB,QAAI;AACF,aAAO,eAAe,QAAQ,SAAS,EAAE,GAAG,KAAK,UAAU,MAAM,CAAC;AAAA,IACpE,QAAQ;AAAA,IAER;AAAA,EACF;AACA,QAAM,QAAQ,gBAAgB,QAAQ,IAAI,SAAS,SAAS;AAC5D,MAAI,CAAC,MAAO,OAAM,IAAI,MAAM,eAAe,OAAO,QAAQ,EAAE,wBAAwB;AACpF,SAAO;AACT;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { BridgeToolbar, type BridgeToolbarProps } from './BridgeToolbar';
|
|
2
2
|
export { useDocumentScope, type ToolbarScope, type ToolbarShop } from './scope';
|
|
3
3
|
export { buildFromConfig, type BuildOverrides } from './config';
|
|
4
|
+
export { DEFAULT_PROXY } from './reads';
|
|
4
5
|
export type { BridgeBuild } from './session';
|
|
5
6
|
export type { TogetherBase } from './together';
|
package/dist/index.js
CHANGED
package/dist/reads.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Production Bridge: the read proxy the toolbar uses unless the product says otherwise. */
|
|
2
|
+
export declare const DEFAULT_PROXY = "https://bridge.floriangouloubi.com";
|
|
3
|
+
export interface ReadsOptions {
|
|
4
|
+
/** The design system repository ("owner/name"): Bridge serves its reads and those of the products it lists. */
|
|
5
|
+
team: string;
|
|
6
|
+
/** Bridge's origin, or null to read GitHub directly. */
|
|
7
|
+
proxy: string | null;
|
|
8
|
+
fetch?: typeof fetch;
|
|
9
|
+
}
|
|
10
|
+
export interface Reads {
|
|
11
|
+
/** A GitHub REST read under /repos/<owner>/<name>/..., as JSON. */
|
|
12
|
+
api<T>(path: string): Promise<T>;
|
|
13
|
+
/** A file of a repository at a ref (a sha or a branch; none: the default branch), as text. */
|
|
14
|
+
file(owner: string, repo: string, ref: string | null, path: string): Promise<string>;
|
|
15
|
+
}
|
|
16
|
+
export declare class ReadError extends Error {
|
|
17
|
+
readonly status: number;
|
|
18
|
+
constructor(message: string, status: number);
|
|
19
|
+
}
|
|
20
|
+
/** Tests start fresh. */
|
|
21
|
+
export declare function resetReads(): void;
|
|
22
|
+
export declare function githubReads({ team, proxy, fetch: f }: ReadsOptions): Reads;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-CzlIsFDY.js","sources":["../src/session.ts"],"sourcesContent":["// The Bridge toolbar's pure logic: when it shows, which change it follows, what Before and After mean for that\n// change, and the screens it lists. A product opens it only when Bridge Studio links here with `?bridge=<change>`;\n// production renders nothing, except the Before side of a code change, which arrives with a handoff from a preview.\n\nexport interface StorageLike {\n getItem(key: string): string | null;\n setItem(key: string, value: string): void;\n removeItem(key: string): void;\n}\n\n/**\n * What the toolbar knows about the product and its design system: from bridge.config.json (the product's entry in\n * products[] and previews), read at build time (the Admin demo) or from the design system repository at run time.\n */\nexport interface BridgeBuild {\n /** The repository whose pull requests `?bridge=<n>` names: the product's own repository, else the design system's. */\n owner: string;\n repo: string;\n /** Production Studio (previews.production.docs): the link back and the shipped tokens.css. */\n studio: string | null;\n /** The product in production (products[].production, else previews.production.<key>): Before of a code change. */\n production: string | null;\n /** The product's preview template (products[].preview): only these hosts may hand a code change over to production. */\n preview: string | null;\n /** VERCEL_ENV of the build ('production', 'preview', 'development'), null when unknown. */\n deployEnv: string | null;\n /** The library branch (repo.defaultBranch) and the token files' root (tokens.root): changes tried together. */\n defaultBranch?: string;\n tokensRoot?: string;\n /** The product's key (products[].key) and the design system repository (\"owner/name\"), for the way back to Studio. */\n product?: string;\n ds?: string;\n}\n\nexport const PARAM = 'bridge';\n/** Where After lives for a code change, carried to production on Before. */\nexport const RETURN_PARAM = 'bridge-return';\n/** Scroll position carried across a Before/After navigation. */\nexport const SCROLL_PARAM = 'bridge-scroll';\nexport const SESSION_KEY = 'bridge-admin:change';\nexport const RETURN_KEY = 'bridge-admin:return';\nexport const DOCK_KEY = 'bridge-admin:toolbar-dock';\nexport const OPEN_KEY = 'bridge-admin:toolbar-open';\n/** Changes tried together: the picks of the tokens they set differently (core encodePicks), from Studio. */\nexport const USE_PARAM = 'bridge-use';\nexport const USE_KEY = 'bridge-admin:use';\n/** At most this many changes are tried together. */\nexport const MAX_TOGETHER = 4;\n\nconst safe = <T>(fn: () => T, fallback: T): T => {\n try {\n return fn();\n } catch {\n return fallback;\n }\n};\n\n/**\n * The change the toolbar follows: `?bridge=<n>` wins and is kept for the session (the admin's hash router keeps the\n * query, a reload or a new path does not need it again); `?bridge=off` forgets it. Blocked storage only loses the\n * memory, never the toolbar of the current page.\n */\nexport function readChange(search: string, storage: StorageLike | null): number | null {\n return readChanges(search, storage)[0] ?? null;\n}\n\n/**\n * The change numbers in \"101\" or \"101,118,120\" (an encoded comma too): positive, at most 7 digits, no repeats, at\n * most MAX_TOGETHER. Anything else in the list makes it unreadable (empty), never a guess.\n */\nexport function parseChanges(raw: string | null | undefined): number[] {\n const parts = (raw ?? '').trim().split(/,|%2C/i).map((p) => p.trim());\n if (!parts.every((p) => /^\\d{1,7}$/.test(p) && Number(p) > 0)) return [];\n return [...new Set(parts.map(Number))].slice(0, MAX_TOGETHER);\n}\n\n/**\n * The changes the toolbar follows: one from \"Try it in the product\", 2 to 4 from \"Try them together\". Same memory as\n * one change: `?bridge=` wins and is kept for the session, `?bridge=off` forgets it, blocked storage only loses the\n * memory. The picks (`bridge-use`) travel with the list and are kept, or forgotten, with it.\n */\nexport function readChanges(search: string, storage: StorageLike | null): number[] {\n const params = new URLSearchParams(search);\n if (params.has(PARAM)) {\n const list = parseChanges(params.get(PARAM));\n if (!list.length) {\n if (storage) safe(() => (storage.removeItem(SESSION_KEY), storage.removeItem(USE_KEY)), undefined);\n return [];\n }\n if (storage) {\n safe(() => storage.setItem(SESSION_KEY, list.join(',')), undefined);\n const use = params.get(USE_PARAM);\n safe(() => (use && list.length > 1 ? storage.setItem(USE_KEY, use) : storage.removeItem(USE_KEY)), undefined);\n }\n return list;\n }\n return storage ? parseChanges(safe(() => storage.getItem(SESSION_KEY), null)) : [];\n}\n\n/** The picks that came with the list: from the address, else the session. */\nexport function readUse(search: string, storage: StorageLike | null): string | null {\n const params = new URLSearchParams(search);\n if (params.has(PARAM)) return params.get(USE_PARAM);\n return storage ? safe(() => storage.getItem(USE_KEY), null) : null;\n}\n\n/** A host that matches the product's preview template (`bridge-admin-git-{branch}-team.vercel.app`), https only. */\nexport function isPreviewUrl(raw: string | null | undefined, template: string | null): boolean {\n if (!raw || !template) return false;\n let url: URL;\n let tpl: URL;\n try {\n url = new URL(raw);\n tpl = new URL(template.replace(/\\{[a-z]+\\}/gi, 'x'));\n } catch {\n return false;\n }\n if (url.protocol !== 'https:' || url.username || url.password || url.port) return false;\n const tplHost = /^https?:\\/\\/([^/?#]+)/i.exec(template)?.[1]?.toLowerCase();\n if (!tplHost || tpl.protocol !== 'https:') return false;\n const pattern = new RegExp(`^${tplHost.split(/\\{[a-z]+\\}/i).map((p) => p.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')).join('[a-z0-9-]+')}$`);\n return pattern.test(url.hostname.toLowerCase());\n}\n\n/** The preview to return to from production, from `?bridge-return=` or the session. Only a preview host counts. */\nexport function readReturn(search: string, storage: StorageLike | null, template: string | null): string | null {\n const raw = new URLSearchParams(search).get(RETURN_PARAM);\n if (raw !== null) {\n if (isPreviewUrl(raw, template)) {\n const origin = new URL(raw).origin;\n if (storage) safe(() => storage.setItem(RETURN_KEY, origin), undefined);\n return origin;\n }\n return null;\n }\n const stored = storage ? safe(() => storage.getItem(RETURN_KEY), null) : null;\n return isPreviewUrl(stored, template) ? new URL(stored!).origin : null;\n}\n\nexport type Where = 'production' | 'preview' | 'local';\n\n/** Which deployment this page is: the product in production by host or by build, a preview, or a local build. */\nexport function whereAmI(host: string, build: Pick<BridgeBuild, 'production' | 'deployEnv'>): Where {\n const prodHost = build.production ? safe(() => new URL(build.production!).host, null) : null;\n if (build.deployEnv === 'production' || (prodHost && host.toLowerCase() === prodHost.toLowerCase())) return 'production';\n if (build.deployEnv === 'preview') return 'preview';\n return 'local';\n}\n\n/**\n * Whether the toolbar renders. Never without a change from Studio. In production only for the Before side of a code\n * change, that is with a preview to return to: production on its own renders nothing.\n */\nexport function shouldRender(input: { change: number | null; where: Where; returnTo: string | null; together?: boolean }): boolean {\n if (input.change === null) return false;\n // Changes tried together run on production: no preview holds all of them.\n if (input.together) return true;\n if (input.where === 'production') return input.returnTo !== null;\n return true;\n}\n\n/** \"These 3 changes\": the After side of changes tried together, counting the ones switched on. */\nexport const togetherLabel = (n: number) => (n === 1 ? 'This change' : `These ${n} changes`);\n\n/** The one hint line of changes tried together: where they run and why. */\nexport const TOGETHER_HINT = \"The live product, with these changes' tokens applied in your browser only. No preview has all of them together.\";\n\n/** Show what changed found nothing on this screen for changes tried together. */\nexport const TOGETHER_EMPTY_LINE = \"These changes don't touch this screen. Try another screen.\";\n\n/** Switches one change on or off, keeping the order Studio listed them in. */\nexport function toggleIncluded(all: number[], included: number[], n: number, on: boolean): number[] {\n const next = new Set(included);\n if (on) next.add(n);\n else next.delete(n);\n return all.filter((x) => next.has(x));\n}\n\n/** Studio's Changes list, where changes are tried together (and the way back). */\nexport function studioChangesUrl(build: Pick<BridgeBuild, 'studio' | 'owner' | 'repo'>): string {\n return build.studio ? `${build.studio.replace(/\\/$/, '')}/studio/changes/` : `https://github.com/${build.owner}/${build.repo}/pulls`;\n}\n\nexport type ChangeMode = 'tokens' | 'code';\n\n/** Token files (DTCG and the contrast gate) and changesets only: Before swaps tokens live. Anything else is code. */\nexport function changeMode(files: string[]): ChangeMode {\n const tokenOnly = files.length > 0 && files.every((f) => f.endsWith('.tokens.json') || /contrast\\.checks\\.json$/.test(f) || f.startsWith('.changeset/'));\n return tokenOnly ? 'tokens' : 'code';\n}\n\n/** The live tokens (main's build, served by production Studio at `/tokens.css`), or null when not configured. */\nexport function liveTokensUrl(build: Pick<BridgeBuild, 'studio'>): string | null {\n return build.studio ? safe(() => new URL('tokens.css', build.studio!.replace(/\\/?$/, '/')).href, null) : null;\n}\n\n/**\n * Studio's page for the change. A change in a product's own repository (an exploration there) opens as\n * `?exploration=<n>&product=<key>`; a change of the design system repository as `?pr=<n>`.\n */\nexport function studioChangeUrl(build: Pick<BridgeBuild, 'studio' | 'owner' | 'repo' | 'product' | 'ds'>, change: number): string {\n if (!build.studio) return `https://github.com/${build.owner}/${build.repo}/pull/${change}`;\n const studio = build.studio.replace(/\\/$/, '');\n const own = build.product && build.ds && build.ds.toLowerCase() !== `${build.owner}/${build.repo}`.toLowerCase();\n return own ? `${studio}/studio/changes/?exploration=${change}&product=${encodeURIComponent(build.product!)}` : `${studio}/studio/changes/?pr=${change}`;\n}\n\n/** Shape of a visual impact manifest that the toolbar reads (written by @bridge-ds/visual). */\nexport interface ManifestShot {\n kind: 'story' | 'route';\n label: string;\n route?: string;\n tenant?: string;\n theme: string;\n status: string;\n percent: number;\n}\n\nexport interface Screen {\n label: string;\n route: string;\n tenant: string;\n theme: string;\n percent: number;\n}\n\n/** The product screens the change alters, most changed first, one entry per screen, shop and theme. */\nexport function changedScreens(shots: ManifestShot[] | null | undefined): Screen[] {\n if (!Array.isArray(shots)) return [];\n const seen = new Set<string>();\n return shots\n .filter((s) => s.kind === 'route' && s.route && s.tenant && (s.status === 'changed' || s.status === 'added'))\n .sort((a, b) => b.percent - a.percent)\n .filter((s) => {\n const key = `${s.route}|${s.tenant}|${s.theme}`;\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n })\n .map((s) => ({ label: s.label, route: s.route!, tenant: s.tenant!, theme: s.theme, percent: s.percent }));\n}\n\n/**\n * The same page on another deployment (code changes: production for Before, the preview for After), with the\n * change, the way back and the scroll position in the query. The hash route (ra-core) is kept.\n */\nexport function sameScreenOn(target: string, here: { search: string; hash: string }, extra: { change: number; returnTo?: string | null; scroll?: number }): string {\n const url = new URL(target);\n const params = new URLSearchParams(here.search);\n params.delete(RETURN_PARAM);\n params.delete(SCROLL_PARAM);\n params.set(PARAM, String(extra.change));\n if (extra.returnTo) params.set(RETURN_PARAM, extra.returnTo);\n if (extra.scroll && extra.scroll > 0) params.set(SCROLL_PARAM, String(Math.round(extra.scroll)));\n url.pathname = '/';\n url.search = params.toString();\n url.hash = here.hash;\n return url.href;\n}\n\n/** The scroll position a Before/After navigation carried, once: the caller removes it from the address. */\nexport function readScroll(search: string): number | null {\n const raw = new URLSearchParams(search).get(SCROLL_PARAM);\n return raw && /^\\d{1,7}$/.test(raw) ? Number(raw) : null;\n}\n\nexport type Dock = 'start' | 'center' | 'end';\nconst DOCKS: Dock[] = ['start', 'center', 'end'];\n\n/** Bottom right by default: the corner a back office leaves free most often. */\nexport function readDock(storage: StorageLike | null): Dock {\n const v = storage ? safe(() => storage.getItem(DOCK_KEY), null) : null;\n return DOCKS.includes(v as Dock) ? (v as Dock) : 'end';\n}\n\n/** One step left (-1) or right (+1), stopping at the edges. */\nexport function stepDock(dock: Dock, step: -1 | 1): Dock {\n return DOCKS[Math.min(DOCKS.length - 1, Math.max(0, DOCKS.indexOf(dock) + step))]!;\n}\n\n/** The dock nearest to where a drag ended: thirds of the viewport width. */\nexport function dockAt(x: number, width: number): Dock {\n if (width <= 0) return 'center';\n const r = x / width;\n return r < 1 / 3 ? 'start' : r > 2 / 3 ? 'end' : 'center';\n}\n\n/** Title of a change as people read it: conventional prefixes (\"tokens: \") dropped, first letter up. */\nexport function readableTitle(title: string): string {\n const t = title.replace(/^\\s*[a-z]+(\\([^)]*\\))?!?:\\s*/i, '').trim() || title.trim();\n return t.charAt(0).toUpperCase() + t.slice(1);\n}\n\n/** The B shortcut flips Before and After, unless the person is typing or holds a modifier. */\nexport function isFlipKey(e: { key: string; altKey: boolean; ctrlKey: boolean; metaKey: boolean; target: unknown }): boolean {\n if (e.altKey || e.ctrlKey || e.metaKey || e.key.toLowerCase() !== 'b') return false;\n const t = e.target as { tagName?: string; isContentEditable?: boolean; closest?: (s: string) => unknown } | null;\n if (!t) return true;\n if (t.isContentEditable) return false;\n const tag = (t.tagName ?? '').toLowerCase();\n if (tag === 'input' || tag === 'textarea' || tag === 'select') return false;\n return !(t.closest && t.closest('[role=\"combobox\"], [role=\"textbox\"], [role=\"searchbox\"]'));\n}\n\nexport interface Rect {\n left: number;\n top: number;\n right: number;\n bottom: number;\n}\n\nconst overlaps = (a: Rect, b: Rect, margin: number) => a.left < b.right + margin && a.right > b.left - margin && a.top < b.bottom + margin && a.bottom > b.top - margin;\n\n/**\n * Where the toolbar goes so it never covers a primary or submit button of the page: the chosen dock if it is free,\n * else the opposite corner, else the centre, else the chosen dock lifted just above the buttons it would cover. The\n * docks sit inside the area [left, right] (the content column, so it never sits over the sidebar).\n */\nexport function placeToolbar(input: { left: number; right: number; vh: number; w: number; h: number; gutter: number; preferred: Dock; obstacles: Rect[]; margin?: number }): { dock: Dock; lift: number } {\n const { left: areaLeft, right: areaRight, vh, w, h, gutter, preferred, obstacles } = input;\n const margin = input.margin ?? 8;\n const rectAt = (dock: Dock, lift = 0): Rect => {\n const left = dock === 'start' ? areaLeft : dock === 'end' ? areaRight - w : (areaLeft + areaRight - w) / 2;\n const bottom = vh - gutter - lift;\n return { left, right: left + w, top: bottom - h, bottom };\n };\n const opposite: Dock = preferred === 'start' ? 'end' : 'start';\n const order: Dock[] = [preferred, opposite, ...DOCKS.filter((d) => d !== preferred && d !== opposite)];\n for (const dock of order) {\n const r = rectAt(dock);\n if (!obstacles.some((o) => overlaps(r, o, margin))) return { dock, lift: 0 };\n }\n // Every dock covers something: stay put and rise above the highest button in the way.\n const base = rectAt(preferred);\n const inWay = obstacles.filter((o) => o.left < base.right + margin && o.right > base.left - margin && o.bottom > base.top - margin);\n const top = Math.min(...inWay.map((o) => o.top));\n const lift = Math.max(0, Math.ceil(base.bottom - (top - margin)));\n return { dock: preferred, lift: Math.min(lift, Math.max(0, vh - h - 2 * gutter)) };\n}\n\n/** What one token file can change on screen: a theme and a brand, or every one of them (null). */\nfunction fileScope(file: string): { theme: string | null; brand: string | null } | 'none' {\n if (file.startsWith('.changeset/')) return 'none';\n let m = /(?:^|\\/)semantic\\/([a-z0-9-]+)\\.tokens\\.json$/i.exec(file);\n if (m && m[1] !== 'base') return { theme: m[1]!, brand: null };\n m = /(?:^|\\/)brands\\/([a-z0-9-]+)\\.([a-z0-9-]+)\\.tokens\\.json$/i.exec(file);\n if (m) return { theme: m[2]!, brand: m[1]! };\n m = /(?:^|\\/)brands\\/([a-z0-9-]+)\\.tokens\\.json$/i.exec(file);\n if (m) return { theme: null, brand: m[1]! };\n // Primitives, base, density, components and anything else: could change every theme and brand.\n return { theme: null, brand: null };\n}\n\nexport type NoDifference = { kind: 'theme'; here: string; touched: string } | { kind: 'brand'; here: string; touched: string };\n\n/**\n * Whether a token change shows nothing in this theme and brand, from the token files it edits (DTCG layers named\n * semantic/<theme>, brands/<brand>.<theme>, brands/<brand>). Null when it may show, or when that cannot be told:\n * never claims \"no difference\" on a guess.\n */\nexport function noVisibleDifference(files: string[], here: { theme: string; brand: string }): NoDifference | null {\n const scopes = files.map(fileScope).filter((s): s is { theme: string | null; brand: string | null } => s !== 'none');\n if (!scopes.length) return null;\n const hits = (theme: string, brand: string) => scopes.some((s) => (s.theme === null || s.theme === theme) && (s.brand === null || s.brand === brand));\n if (hits(here.theme, here.brand)) return null;\n const theme = scopes.find((s) => s.theme !== null && s.theme !== here.theme && (s.brand === null || s.brand === here.brand))?.theme;\n if (theme) return { kind: 'theme', here: here.theme, touched: theme };\n const brand = scopes.find((s) => s.brand !== null && s.brand !== here.brand)?.brand;\n return brand ? { kind: 'brand', here: here.brand, touched: brand } : null;\n}\n\n/** \"darker default background.\" The change title as a short phrase after \"This change:\". */\nexport function changeSummary(title: string): string {\n const t = readableTitle(title).replace(/[.\\s]+$/, '');\n if (!t) return '';\n const lower = /^[A-Z][a-z]/.test(t) ? t.charAt(0).toLowerCase() + t.slice(1) : t;\n return `${lower}.`;\n}\n\nexport interface TokenChange {\n /** Token path, \"color.bg.default\". */\n path: string;\n /** CSS variable the token builds to, \"--color-bg-default\". */\n cssVar: string;\n /** The role it plays, what designers call it: \"Page canvas\" (its description), \"Brand primary\" (a palette role). */\n name: string;\n /** The exact step, second: \"Primary 700\" for a palette step, null for a semantic token. */\n step: string | null;\n type: string | null;\n /** The theme and brand its file applies to (null: every one). */\n theme: string | null;\n brand: string | null;\n}\n\ntype TokenNode = { $value?: unknown; $type?: string; $description?: string; [k: string]: unknown };\ntype Leaf = { value: string; type: string | null; description: string | null };\n\nfunction leaves(node: unknown, path: string[] = [], inheritedType: string | null = null, out = new Map<string, Leaf>()): Map<string, Leaf> {\n if (!node || typeof node !== 'object') return out;\n const n = node as TokenNode;\n const type = typeof n.$type === 'string' ? n.$type : inheritedType;\n if ('$value' in n) {\n out.set(path.join('.'), { value: JSON.stringify(n.$value), type, description: typeof n.$description === 'string' ? n.$description : null });\n return out;\n }\n for (const [k, v] of Object.entries(n)) if (!k.startsWith('$')) leaves(v, [...path, k], type, out);\n return out;\n}\n\n/** Palette roles a brand re-points (brands/<brand>.tokens.json), in designers' words. */\nconst PALETTE_ROLES: Record<string, string> = { primary: 'Brand primary', link: 'Link', neutral: 'Neutral', accent: 'Accent', success: 'Success', warning: 'Warning', danger: 'Danger', info: 'Info', categorical: 'Chart colours' };\n\n/** The role a token plays: its description's first phrase, a palette role (\"Brand primary\"), else its path in words. */\nexport function roleOfToken(path: string, description: string | null): string {\n const first = description?.split(/[.:;(]/)[0]?.trim();\n if (first && first.length <= 40) return first;\n const m = /^palette\\.([a-z-]+)\\./.exec(path);\n if (m) return PALETTE_ROLES[m[1]!] ?? designerName(`palette.${m[1]}`, null);\n return designerName(path, null);\n}\n\n/** The palette step, shown second: \"palette.primary.700\" -> \"Primary 700\"; null for other tokens. */\nexport function stepOfToken(path: string): string | null {\n return path.startsWith('palette.') ? designerName(path, null) : null;\n}\n\n/** Designer name of a token: the first phrase of its description, else its path in words (\"Bg default\"). */\nexport function designerName(path: string, description: string | null): string {\n const first = description?.split(/[.:;(]/)[0]?.trim();\n if (first && first.length <= 40) return first;\n const words = path.replace(/^(color|palette)\\./, '').split('.').join(' ');\n return words.charAt(0).toUpperCase() + words.slice(1);\n}\n\n/**\n * The tokens one file changes between two versions of it (parsed DTCG JSON, null when the file is added or removed):\n * every leaf whose $value differs, with the theme and brand its layer applies to.\n */\nexport function tokenChanges(file: string, before: unknown, after: unknown): TokenChange[] {\n const scope = fileScope(file);\n if (scope === 'none') return [];\n const a = leaves(before);\n const b = leaves(after);\n const out: TokenChange[] = [];\n for (const path of new Set([...a.keys(), ...b.keys()])) {\n const x = a.get(path);\n const y = b.get(path);\n if (x?.value === y?.value) continue;\n out.push({\n path,\n cssVar: `--${path.split('.').join('-')}`,\n name: roleOfToken(path, y?.description ?? x?.description ?? null),\n step: stepOfToken(path),\n type: y?.type ?? x?.type ?? null,\n theme: scope.theme,\n brand: scope.brand,\n });\n }\n return out;\n}\n\n/** WCAG contrast ratio between two rgb() colours, or null when either is not rgb (a non-colour value). */\nexport function contrastRatio(a: string, b: string): number | null {\n const lum = (c: string) => {\n const m = /^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)/.exec(c.trim());\n if (!m) return null;\n const [r, g, bl] = [m[1], m[2], m[3]].map((n) => {\n const v = Number(n) / 255;\n return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;\n }) as [number, number, number];\n return 0.2126 * r + 0.7152 * g + 0.0722 * bl;\n };\n const x = lum(a);\n const y = lum(b);\n if (x === null || y === null) return null;\n return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);\n}\n\n/** Two colours under 1.1:1 read as the same at a glance: the swatch says \"Subtle change\" so it does not look broken. */\nexport const isSubtle = (a: string, b: string): boolean => {\n const r = contrastRatio(a, b);\n return r !== null && r < 1.1;\n};\n\n/** rgb(245, 247, 249) -> #f5f7f9; anything else as is. */\nexport function toHex(color: string): string {\n const m = /^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*([\\d.]+))?\\)$/.exec(color.trim());\n if (!m) return color;\n const hex = [m[1], m[2], m[3]].map((n) => Number(n).toString(16).padStart(2, '0')).join('');\n return m[4] !== undefined && Number(m[4]) < 1 ? `#${hex}${Math.round(Number(m[4]) * 255).toString(16).padStart(2, '0')}` : `#${hex}`;\n}\n\n/** \"from Darker default background\", \"from #101 and #118\": which change a token's value comes from (changes tried together). */\nexport function fromText(from: number[], titleOf: (n: number) => string | null): string {\n const names = from.map((n) => titleOf(n) ?? `#${n}`);\n return `from ${names.length <= 2 ? names.join(' and ') : `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`}`;\n}\n"],"names":["lift","theme","brand"],"mappings":"AAkCO,MAAM,QAAQ;AAEd,MAAM,eAAe;AAErB,MAAM,eAAe;AACrB,MAAM,cAAc;AACpB,MAAM,aAAa;AACnB,MAAM,WAAW;AACjB,MAAM,WAAW;AAEjB,MAAM,YAAY;AAClB,MAAM,UAAU;AAEhB,MAAM,eAAe;AAE5B,MAAM,OAAO,CAAI,IAAa,aAAmB;AAC/C,MAAI;AACF,WAAO,GAAA;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAeO,SAAS,aAAa,KAA0C;AACrE,QAAM,SAAS,OAAO,IAAI,KAAA,EAAO,MAAM,QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,MAAM;AACpE,MAAI,CAAC,MAAM,MAAM,CAAC,MAAM,YAAY,KAAK,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,UAAU,CAAA;AACtE,SAAO,CAAC,GAAG,IAAI,IAAI,MAAM,IAAI,MAAM,CAAC,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ACrC,UAAQ,KAAK,IAAI,GAAG,CAAC,IAAI,SAAS,KAAK,IAAI,GAAG,CAAC,IAAI;AACrD;AAGO,MAAM,WAAW,CAAC,GAAW,MAAuB;AACzD,QAAM,IAAI,cAAc,GAAG,CAAC;AAC5B,SAAO,MAAM,QAAQ,IAAI;AAC3B;AAGO,SAAS,MAAM,OAAuB;AAC3C,QAAM,IAAI,sDAAsD,KAAK,MAAM,MAAM;AACjF,MAAI,CAAC,EAAG,QAAO;AACf,QAAM,MAAM,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,IAAI,CAAC,MAAM,OAAO,CAAC,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAC1F,SAAO,EAAE,CAAC,MAAM,UAAa,OAAO,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,GAAG,GAAG,KAAK,MAAM,OAAO,EAAE,CAAC,CAAC,IAAI,GAAG,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,KAAK,IAAI,GAAG;AACpI;AAGO,SAAS,SAAS,MAAgB,SAA+C;AACtF,QAAM,QAAQ,KAAK,IAAI,CAAC,MAAM,QAAQ,CAAC,KAAK,IAAI,CAAC,EAAE;AACnD,SAAO,QAAQ,MAAM,UAAU,IAAI,MAAM,KAAK,OAAO,IAAI,GAAG,MAAM,MAAM,GAAG,EAAE,EAAE,KAAK,IAAI,CAAC,QAAQ,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE;AAC5H;"}
|
|
1
|
+
{"version":3,"file":"session-CzlIsFDY.js","sources":["../src/session.ts"],"sourcesContent":["// The Bridge toolbar's pure logic: when it shows, which change it follows, what Before and After mean for that\n// change, and the screens it lists. A product opens it only when Bridge Studio links here with `?bridge=<change>`;\n// production renders nothing, except the Before side of a code change, which arrives with a handoff from a preview.\n\nexport interface StorageLike {\n getItem(key: string): string | null;\n setItem(key: string, value: string): void;\n removeItem(key: string): void;\n}\n\n/**\n * What the toolbar knows about the product and its design system: from bridge.config.json (the product's entry in\n * products[] and previews), read at build time (the Admin demo) or from the design system repository at run time.\n */\nexport interface BridgeBuild {\n /** The repository whose pull requests `?bridge=<n>` names: the product's own repository, else the design system's. */\n owner: string;\n repo: string;\n /** Production Studio (previews.production.docs): the link back and the shipped tokens.css. */\n studio: string | null;\n /** The product in production (products[].production, else previews.production.<key>): Before of a code change. */\n production: string | null;\n /** The product's preview template (products[].preview): only these hosts may hand a code change over to production. */\n preview: string | null;\n /** VERCEL_ENV of the build ('production', 'preview', 'development'), null when unknown. */\n deployEnv: string | null;\n /** The library branch (repo.defaultBranch) and the token files' root (tokens.root): changes tried together. */\n defaultBranch?: string;\n tokensRoot?: string;\n /** The product's key (products[].key) and the design system repository (\"owner/name\"), for the way back to Studio. */\n product?: string;\n ds?: string;\n /** Bridge's origin for GitHub reads (its read proxy); default production Bridge, null to read GitHub directly. */\n proxy?: string | null;\n}\n\nexport const PARAM = 'bridge';\n/** Where After lives for a code change, carried to production on Before. */\nexport const RETURN_PARAM = 'bridge-return';\n/** Scroll position carried across a Before/After navigation. */\nexport const SCROLL_PARAM = 'bridge-scroll';\nexport const SESSION_KEY = 'bridge-admin:change';\nexport const RETURN_KEY = 'bridge-admin:return';\nexport const DOCK_KEY = 'bridge-admin:toolbar-dock';\nexport const OPEN_KEY = 'bridge-admin:toolbar-open';\n/** Changes tried together: the picks of the tokens they set differently (core encodePicks), from Studio. */\nexport const USE_PARAM = 'bridge-use';\nexport const USE_KEY = 'bridge-admin:use';\n/** At most this many changes are tried together. */\nexport const MAX_TOGETHER = 4;\n\nconst safe = <T>(fn: () => T, fallback: T): T => {\n try {\n return fn();\n } catch {\n return fallback;\n }\n};\n\n/**\n * The change the toolbar follows: `?bridge=<n>` wins and is kept for the session (the admin's hash router keeps the\n * query, a reload or a new path does not need it again); `?bridge=off` forgets it. Blocked storage only loses the\n * memory, never the toolbar of the current page.\n */\nexport function readChange(search: string, storage: StorageLike | null): number | null {\n return readChanges(search, storage)[0] ?? null;\n}\n\n/**\n * The change numbers in \"101\" or \"101,118,120\" (an encoded comma too): positive, at most 7 digits, no repeats, at\n * most MAX_TOGETHER. Anything else in the list makes it unreadable (empty), never a guess.\n */\nexport function parseChanges(raw: string | null | undefined): number[] {\n const parts = (raw ?? '').trim().split(/,|%2C/i).map((p) => p.trim());\n if (!parts.every((p) => /^\\d{1,7}$/.test(p) && Number(p) > 0)) return [];\n return [...new Set(parts.map(Number))].slice(0, MAX_TOGETHER);\n}\n\n/**\n * The changes the toolbar follows: one from \"Try it in the product\", 2 to 4 from \"Try them together\". Same memory as\n * one change: `?bridge=` wins and is kept for the session, `?bridge=off` forgets it, blocked storage only loses the\n * memory. The picks (`bridge-use`) travel with the list and are kept, or forgotten, with it.\n */\nexport function readChanges(search: string, storage: StorageLike | null): number[] {\n const params = new URLSearchParams(search);\n if (params.has(PARAM)) {\n const list = parseChanges(params.get(PARAM));\n if (!list.length) {\n if (storage) safe(() => (storage.removeItem(SESSION_KEY), storage.removeItem(USE_KEY)), undefined);\n return [];\n }\n if (storage) {\n safe(() => storage.setItem(SESSION_KEY, list.join(',')), undefined);\n const use = params.get(USE_PARAM);\n safe(() => (use && list.length > 1 ? storage.setItem(USE_KEY, use) : storage.removeItem(USE_KEY)), undefined);\n }\n return list;\n }\n return storage ? parseChanges(safe(() => storage.getItem(SESSION_KEY), null)) : [];\n}\n\n/** The picks that came with the list: from the address, else the session. */\nexport function readUse(search: string, storage: StorageLike | null): string | null {\n const params = new URLSearchParams(search);\n if (params.has(PARAM)) return params.get(USE_PARAM);\n return storage ? safe(() => storage.getItem(USE_KEY), null) : null;\n}\n\n/** A host that matches the product's preview template (`bridge-admin-git-{branch}-team.vercel.app`), https only. */\nexport function isPreviewUrl(raw: string | null | undefined, template: string | null): boolean {\n if (!raw || !template) return false;\n let url: URL;\n let tpl: URL;\n try {\n url = new URL(raw);\n tpl = new URL(template.replace(/\\{[a-z]+\\}/gi, 'x'));\n } catch {\n return false;\n }\n if (url.protocol !== 'https:' || url.username || url.password || url.port) return false;\n const tplHost = /^https?:\\/\\/([^/?#]+)/i.exec(template)?.[1]?.toLowerCase();\n if (!tplHost || tpl.protocol !== 'https:') return false;\n const pattern = new RegExp(`^${tplHost.split(/\\{[a-z]+\\}/i).map((p) => p.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&')).join('[a-z0-9-]+')}$`);\n return pattern.test(url.hostname.toLowerCase());\n}\n\n/** The preview to return to from production, from `?bridge-return=` or the session. Only a preview host counts. */\nexport function readReturn(search: string, storage: StorageLike | null, template: string | null): string | null {\n const raw = new URLSearchParams(search).get(RETURN_PARAM);\n if (raw !== null) {\n if (isPreviewUrl(raw, template)) {\n const origin = new URL(raw).origin;\n if (storage) safe(() => storage.setItem(RETURN_KEY, origin), undefined);\n return origin;\n }\n return null;\n }\n const stored = storage ? safe(() => storage.getItem(RETURN_KEY), null) : null;\n return isPreviewUrl(stored, template) ? new URL(stored!).origin : null;\n}\n\nexport type Where = 'production' | 'preview' | 'local';\n\n/** Which deployment this page is: the product in production by host or by build, a preview, or a local build. */\nexport function whereAmI(host: string, build: Pick<BridgeBuild, 'production' | 'deployEnv'>): Where {\n const prodHost = build.production ? safe(() => new URL(build.production!).host, null) : null;\n if (build.deployEnv === 'production' || (prodHost && host.toLowerCase() === prodHost.toLowerCase())) return 'production';\n if (build.deployEnv === 'preview') return 'preview';\n return 'local';\n}\n\n/**\n * Whether the toolbar renders. Never without a change from Studio. In production only for the Before side of a code\n * change, that is with a preview to return to: production on its own renders nothing.\n */\nexport function shouldRender(input: { change: number | null; where: Where; returnTo: string | null; together?: boolean }): boolean {\n if (input.change === null) return false;\n // Changes tried together run on production: no preview holds all of them.\n if (input.together) return true;\n if (input.where === 'production') return input.returnTo !== null;\n return true;\n}\n\n/** \"These 3 changes\": the After side of changes tried together, counting the ones switched on. */\nexport const togetherLabel = (n: number) => (n === 1 ? 'This change' : `These ${n} changes`);\n\n/** The one hint line of changes tried together: where they run and why. */\nexport const TOGETHER_HINT = \"The live product, with these changes' tokens applied in your browser only. No preview has all of them together.\";\n\n/** Show what changed found nothing on this screen for changes tried together. */\nexport const TOGETHER_EMPTY_LINE = \"These changes don't touch this screen. Try another screen.\";\n\n/** Switches one change on or off, keeping the order Studio listed them in. */\nexport function toggleIncluded(all: number[], included: number[], n: number, on: boolean): number[] {\n const next = new Set(included);\n if (on) next.add(n);\n else next.delete(n);\n return all.filter((x) => next.has(x));\n}\n\n/** Studio's Changes list, where changes are tried together (and the way back). */\nexport function studioChangesUrl(build: Pick<BridgeBuild, 'studio' | 'owner' | 'repo'>): string {\n return build.studio ? `${build.studio.replace(/\\/$/, '')}/studio/changes/` : `https://github.com/${build.owner}/${build.repo}/pulls`;\n}\n\nexport type ChangeMode = 'tokens' | 'code';\n\n/** Token files (DTCG and the contrast gate) and changesets only: Before swaps tokens live. Anything else is code. */\nexport function changeMode(files: string[]): ChangeMode {\n const tokenOnly = files.length > 0 && files.every((f) => f.endsWith('.tokens.json') || /contrast\\.checks\\.json$/.test(f) || f.startsWith('.changeset/'));\n return tokenOnly ? 'tokens' : 'code';\n}\n\n/** The live tokens (main's build, served by production Studio at `/tokens.css`), or null when not configured. */\nexport function liveTokensUrl(build: Pick<BridgeBuild, 'studio'>): string | null {\n return build.studio ? safe(() => new URL('tokens.css', build.studio!.replace(/\\/?$/, '/')).href, null) : null;\n}\n\n/**\n * Studio's page for the change. A change in a product's own repository (an exploration there) opens as\n * `?exploration=<n>&product=<key>`; a change of the design system repository as `?pr=<n>`.\n */\nexport function studioChangeUrl(build: Pick<BridgeBuild, 'studio' | 'owner' | 'repo' | 'product' | 'ds'>, change: number): string {\n if (!build.studio) return `https://github.com/${build.owner}/${build.repo}/pull/${change}`;\n const studio = build.studio.replace(/\\/$/, '');\n const own = build.product && build.ds && build.ds.toLowerCase() !== `${build.owner}/${build.repo}`.toLowerCase();\n return own ? `${studio}/studio/changes/?exploration=${change}&product=${encodeURIComponent(build.product!)}` : `${studio}/studio/changes/?pr=${change}`;\n}\n\n/** Shape of a visual impact manifest that the toolbar reads (written by @bridge-ds/visual). */\nexport interface ManifestShot {\n kind: 'story' | 'route';\n label: string;\n route?: string;\n tenant?: string;\n theme: string;\n status: string;\n percent: number;\n}\n\nexport interface Screen {\n label: string;\n route: string;\n tenant: string;\n theme: string;\n percent: number;\n}\n\n/** The product screens the change alters, most changed first, one entry per screen, shop and theme. */\nexport function changedScreens(shots: ManifestShot[] | null | undefined): Screen[] {\n if (!Array.isArray(shots)) return [];\n const seen = new Set<string>();\n return shots\n .filter((s) => s.kind === 'route' && s.route && s.tenant && (s.status === 'changed' || s.status === 'added'))\n .sort((a, b) => b.percent - a.percent)\n .filter((s) => {\n const key = `${s.route}|${s.tenant}|${s.theme}`;\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n })\n .map((s) => ({ label: s.label, route: s.route!, tenant: s.tenant!, theme: s.theme, percent: s.percent }));\n}\n\n/**\n * The same page on another deployment (code changes: production for Before, the preview for After), with the\n * change, the way back and the scroll position in the query. The hash route (ra-core) is kept.\n */\nexport function sameScreenOn(target: string, here: { search: string; hash: string }, extra: { change: number; returnTo?: string | null; scroll?: number }): string {\n const url = new URL(target);\n const params = new URLSearchParams(here.search);\n params.delete(RETURN_PARAM);\n params.delete(SCROLL_PARAM);\n params.set(PARAM, String(extra.change));\n if (extra.returnTo) params.set(RETURN_PARAM, extra.returnTo);\n if (extra.scroll && extra.scroll > 0) params.set(SCROLL_PARAM, String(Math.round(extra.scroll)));\n url.pathname = '/';\n url.search = params.toString();\n url.hash = here.hash;\n return url.href;\n}\n\n/** The scroll position a Before/After navigation carried, once: the caller removes it from the address. */\nexport function readScroll(search: string): number | null {\n const raw = new URLSearchParams(search).get(SCROLL_PARAM);\n return raw && /^\\d{1,7}$/.test(raw) ? Number(raw) : null;\n}\n\nexport type Dock = 'start' | 'center' | 'end';\nconst DOCKS: Dock[] = ['start', 'center', 'end'];\n\n/** Bottom right by default: the corner a back office leaves free most often. */\nexport function readDock(storage: StorageLike | null): Dock {\n const v = storage ? safe(() => storage.getItem(DOCK_KEY), null) : null;\n return DOCKS.includes(v as Dock) ? (v as Dock) : 'end';\n}\n\n/** One step left (-1) or right (+1), stopping at the edges. */\nexport function stepDock(dock: Dock, step: -1 | 1): Dock {\n return DOCKS[Math.min(DOCKS.length - 1, Math.max(0, DOCKS.indexOf(dock) + step))]!;\n}\n\n/** The dock nearest to where a drag ended: thirds of the viewport width. */\nexport function dockAt(x: number, width: number): Dock {\n if (width <= 0) return 'center';\n const r = x / width;\n return r < 1 / 3 ? 'start' : r > 2 / 3 ? 'end' : 'center';\n}\n\n/** Title of a change as people read it: conventional prefixes (\"tokens: \") dropped, first letter up. */\nexport function readableTitle(title: string): string {\n const t = title.replace(/^\\s*[a-z]+(\\([^)]*\\))?!?:\\s*/i, '').trim() || title.trim();\n return t.charAt(0).toUpperCase() + t.slice(1);\n}\n\n/** The B shortcut flips Before and After, unless the person is typing or holds a modifier. */\nexport function isFlipKey(e: { key: string; altKey: boolean; ctrlKey: boolean; metaKey: boolean; target: unknown }): boolean {\n if (e.altKey || e.ctrlKey || e.metaKey || e.key.toLowerCase() !== 'b') return false;\n const t = e.target as { tagName?: string; isContentEditable?: boolean; closest?: (s: string) => unknown } | null;\n if (!t) return true;\n if (t.isContentEditable) return false;\n const tag = (t.tagName ?? '').toLowerCase();\n if (tag === 'input' || tag === 'textarea' || tag === 'select') return false;\n return !(t.closest && t.closest('[role=\"combobox\"], [role=\"textbox\"], [role=\"searchbox\"]'));\n}\n\nexport interface Rect {\n left: number;\n top: number;\n right: number;\n bottom: number;\n}\n\nconst overlaps = (a: Rect, b: Rect, margin: number) => a.left < b.right + margin && a.right > b.left - margin && a.top < b.bottom + margin && a.bottom > b.top - margin;\n\n/**\n * Where the toolbar goes so it never covers a primary or submit button of the page: the chosen dock if it is free,\n * else the opposite corner, else the centre, else the chosen dock lifted just above the buttons it would cover. The\n * docks sit inside the area [left, right] (the content column, so it never sits over the sidebar).\n */\nexport function placeToolbar(input: { left: number; right: number; vh: number; w: number; h: number; gutter: number; preferred: Dock; obstacles: Rect[]; margin?: number }): { dock: Dock; lift: number } {\n const { left: areaLeft, right: areaRight, vh, w, h, gutter, preferred, obstacles } = input;\n const margin = input.margin ?? 8;\n const rectAt = (dock: Dock, lift = 0): Rect => {\n const left = dock === 'start' ? areaLeft : dock === 'end' ? areaRight - w : (areaLeft + areaRight - w) / 2;\n const bottom = vh - gutter - lift;\n return { left, right: left + w, top: bottom - h, bottom };\n };\n const opposite: Dock = preferred === 'start' ? 'end' : 'start';\n const order: Dock[] = [preferred, opposite, ...DOCKS.filter((d) => d !== preferred && d !== opposite)];\n for (const dock of order) {\n const r = rectAt(dock);\n if (!obstacles.some((o) => overlaps(r, o, margin))) return { dock, lift: 0 };\n }\n // Every dock covers something: stay put and rise above the highest button in the way.\n const base = rectAt(preferred);\n const inWay = obstacles.filter((o) => o.left < base.right + margin && o.right > base.left - margin && o.bottom > base.top - margin);\n const top = Math.min(...inWay.map((o) => o.top));\n const lift = Math.max(0, Math.ceil(base.bottom - (top - margin)));\n return { dock: preferred, lift: Math.min(lift, Math.max(0, vh - h - 2 * gutter)) };\n}\n\n/** What one token file can change on screen: a theme and a brand, or every one of them (null). */\nfunction fileScope(file: string): { theme: string | null; brand: string | null } | 'none' {\n if (file.startsWith('.changeset/')) return 'none';\n let m = /(?:^|\\/)semantic\\/([a-z0-9-]+)\\.tokens\\.json$/i.exec(file);\n if (m && m[1] !== 'base') return { theme: m[1]!, brand: null };\n m = /(?:^|\\/)brands\\/([a-z0-9-]+)\\.([a-z0-9-]+)\\.tokens\\.json$/i.exec(file);\n if (m) return { theme: m[2]!, brand: m[1]! };\n m = /(?:^|\\/)brands\\/([a-z0-9-]+)\\.tokens\\.json$/i.exec(file);\n if (m) return { theme: null, brand: m[1]! };\n // Primitives, base, density, components and anything else: could change every theme and brand.\n return { theme: null, brand: null };\n}\n\nexport type NoDifference = { kind: 'theme'; here: string; touched: string } | { kind: 'brand'; here: string; touched: string };\n\n/**\n * Whether a token change shows nothing in this theme and brand, from the token files it edits (DTCG layers named\n * semantic/<theme>, brands/<brand>.<theme>, brands/<brand>). Null when it may show, or when that cannot be told:\n * never claims \"no difference\" on a guess.\n */\nexport function noVisibleDifference(files: string[], here: { theme: string; brand: string }): NoDifference | null {\n const scopes = files.map(fileScope).filter((s): s is { theme: string | null; brand: string | null } => s !== 'none');\n if (!scopes.length) return null;\n const hits = (theme: string, brand: string) => scopes.some((s) => (s.theme === null || s.theme === theme) && (s.brand === null || s.brand === brand));\n if (hits(here.theme, here.brand)) return null;\n const theme = scopes.find((s) => s.theme !== null && s.theme !== here.theme && (s.brand === null || s.brand === here.brand))?.theme;\n if (theme) return { kind: 'theme', here: here.theme, touched: theme };\n const brand = scopes.find((s) => s.brand !== null && s.brand !== here.brand)?.brand;\n return brand ? { kind: 'brand', here: here.brand, touched: brand } : null;\n}\n\n/** \"darker default background.\" The change title as a short phrase after \"This change:\". */\nexport function changeSummary(title: string): string {\n const t = readableTitle(title).replace(/[.\\s]+$/, '');\n if (!t) return '';\n const lower = /^[A-Z][a-z]/.test(t) ? t.charAt(0).toLowerCase() + t.slice(1) : t;\n return `${lower}.`;\n}\n\nexport interface TokenChange {\n /** Token path, \"color.bg.default\". */\n path: string;\n /** CSS variable the token builds to, \"--color-bg-default\". */\n cssVar: string;\n /** The role it plays, what designers call it: \"Page canvas\" (its description), \"Brand primary\" (a palette role). */\n name: string;\n /** The exact step, second: \"Primary 700\" for a palette step, null for a semantic token. */\n step: string | null;\n type: string | null;\n /** The theme and brand its file applies to (null: every one). */\n theme: string | null;\n brand: string | null;\n}\n\ntype TokenNode = { $value?: unknown; $type?: string; $description?: string; [k: string]: unknown };\ntype Leaf = { value: string; type: string | null; description: string | null };\n\nfunction leaves(node: unknown, path: string[] = [], inheritedType: string | null = null, out = new Map<string, Leaf>()): Map<string, Leaf> {\n if (!node || typeof node !== 'object') return out;\n const n = node as TokenNode;\n const type = typeof n.$type === 'string' ? n.$type : inheritedType;\n if ('$value' in n) {\n out.set(path.join('.'), { value: JSON.stringify(n.$value), type, description: typeof n.$description === 'string' ? n.$description : null });\n return out;\n }\n for (const [k, v] of Object.entries(n)) if (!k.startsWith('$')) leaves(v, [...path, k], type, out);\n return out;\n}\n\n/** Palette roles a brand re-points (brands/<brand>.tokens.json), in designers' words. */\nconst PALETTE_ROLES: Record<string, string> = { primary: 'Brand primary', link: 'Link', neutral: 'Neutral', accent: 'Accent', success: 'Success', warning: 'Warning', danger: 'Danger', info: 'Info', categorical: 'Chart colours' };\n\n/** The role a token plays: its description's first phrase, a palette role (\"Brand primary\"), else its path in words. */\nexport function roleOfToken(path: string, description: string | null): string {\n const first = description?.split(/[.:;(]/)[0]?.trim();\n if (first && first.length <= 40) return first;\n const m = /^palette\\.([a-z-]+)\\./.exec(path);\n if (m) return PALETTE_ROLES[m[1]!] ?? designerName(`palette.${m[1]}`, null);\n return designerName(path, null);\n}\n\n/** The palette step, shown second: \"palette.primary.700\" -> \"Primary 700\"; null for other tokens. */\nexport function stepOfToken(path: string): string | null {\n return path.startsWith('palette.') ? designerName(path, null) : null;\n}\n\n/** Designer name of a token: the first phrase of its description, else its path in words (\"Bg default\"). */\nexport function designerName(path: string, description: string | null): string {\n const first = description?.split(/[.:;(]/)[0]?.trim();\n if (first && first.length <= 40) return first;\n const words = path.replace(/^(color|palette)\\./, '').split('.').join(' ');\n return words.charAt(0).toUpperCase() + words.slice(1);\n}\n\n/**\n * The tokens one file changes between two versions of it (parsed DTCG JSON, null when the file is added or removed):\n * every leaf whose $value differs, with the theme and brand its layer applies to.\n */\nexport function tokenChanges(file: string, before: unknown, after: unknown): TokenChange[] {\n const scope = fileScope(file);\n if (scope === 'none') return [];\n const a = leaves(before);\n const b = leaves(after);\n const out: TokenChange[] = [];\n for (const path of new Set([...a.keys(), ...b.keys()])) {\n const x = a.get(path);\n const y = b.get(path);\n if (x?.value === y?.value) continue;\n out.push({\n path,\n cssVar: `--${path.split('.').join('-')}`,\n name: roleOfToken(path, y?.description ?? x?.description ?? null),\n step: stepOfToken(path),\n type: y?.type ?? x?.type ?? null,\n theme: scope.theme,\n brand: scope.brand,\n });\n }\n return out;\n}\n\n/** WCAG contrast ratio between two rgb() colours, or null when either is not rgb (a non-colour value). */\nexport function contrastRatio(a: string, b: string): number | null {\n const lum = (c: string) => {\n const m = /^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)/.exec(c.trim());\n if (!m) return null;\n const [r, g, bl] = [m[1], m[2], m[3]].map((n) => {\n const v = Number(n) / 255;\n return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;\n }) as [number, number, number];\n return 0.2126 * r + 0.7152 * g + 0.0722 * bl;\n };\n const x = lum(a);\n const y = lum(b);\n if (x === null || y === null) return null;\n return (Math.max(x, y) + 0.05) / (Math.min(x, y) + 0.05);\n}\n\n/** Two colours under 1.1:1 read as the same at a glance: the swatch says \"Subtle change\" so it does not look broken. */\nexport const isSubtle = (a: string, b: string): boolean => {\n const r = contrastRatio(a, b);\n return r !== null && r < 1.1;\n};\n\n/** rgb(245, 247, 249) -> #f5f7f9; anything else as is. */\nexport function toHex(color: string): string {\n const m = /^rgba?\\((\\d+),\\s*(\\d+),\\s*(\\d+)(?:,\\s*([\\d.]+))?\\)$/.exec(color.trim());\n if (!m) return color;\n const hex = [m[1], m[2], m[3]].map((n) => Number(n).toString(16).padStart(2, '0')).join('');\n return m[4] !== undefined && Number(m[4]) < 1 ? `#${hex}${Math.round(Number(m[4]) * 255).toString(16).padStart(2, '0')}` : `#${hex}`;\n}\n\n/** \"from Darker default background\", \"from #101 and #118\": which change a token's value comes from (changes tried together). */\nexport function fromText(from: number[], titleOf: (n: number) => string | null): string {\n const names = from.map((n) => titleOf(n) ?? `#${n}`);\n return `from ${names.length <= 2 ? names.join(' and ') : `${names.slice(0, -1).join(', ')} and ${names[names.length - 1]}`}`;\n}\n"],"names":["lift","theme","brand"],"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AAG,GAAG,CAAC,KAAK,IAAI,GAAG;AACpI;AAGO,SAAS,SAAS,MAAgB,SAA+C;AACtF,QAAM,QAAQ,KAAK,IAAI,CAAC,MAAM,QAAQ,CAAC,KAAK,IAAI,CAAC,EAAE;AACnD,SAAO,QAAQ,MAAM,UAAU,IAAI,MAAM,KAAK,OAAO,IAAI,GAAG,MAAM,MAAM,GAAG,EAAE,EAAE,KAAK,IAAI,CAAC,QAAQ,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE;AAC5H;"}
|
package/dist/session.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export interface BridgeBuild {
|
|
|
25
25
|
/** The product's key (products[].key) and the design system repository ("owner/name"), for the way back to Studio. */
|
|
26
26
|
product?: string;
|
|
27
27
|
ds?: string;
|
|
28
|
+
/** Bridge's origin for GitHub reads (its read proxy); default production Bridge, null to read GitHub directly. */
|
|
29
|
+
proxy?: string | null;
|
|
28
30
|
}
|
|
29
31
|
export declare const PARAM = "bridge";
|
|
30
32
|
/** Where After lives for a code change, carried to production on Before. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bridge-ds/toolbar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The Bridge toolbar for a product built with the Bridge design system: opened from Bridge Studio with ?bridge=<change>, it flips the real product between before and after and shows what changed.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"build:package": "node ../../scripts/build-packages.mjs toolbar"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@bridge-ds/core": "^0.
|
|
52
|
+
"@bridge-ds/core": "^0.23.0",
|
|
53
53
|
"lucide-react": "1.58.0"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|