@bridge-ds/toolbar 0.5.0 → 0.7.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/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { B, D, b, u } from "./index-z72Zzzkb.js";
1
+ import { B, D, b, u } from "./index-LdnVzAG3.js";
2
2
  export {
3
3
  B as BridgeToolbar,
4
4
  D as DEFAULT_PROXY,
@@ -8,6 +8,8 @@ const DOCK_KEY = "bridge-admin:toolbar-dock";
8
8
  const OPEN_KEY = "bridge-admin:toolbar-open";
9
9
  const USE_PARAM = "bridge-use";
10
10
  const USE_KEY = "bridge-admin:use";
11
+ const REPO_PARAM = "bridge-repo";
12
+ const REPO_KEY = "bridge-admin:repo";
11
13
  const MAX_TOGETHER = 4;
12
14
  const safe = (fn, fallback) => {
13
15
  try {
@@ -38,6 +40,18 @@ function readChanges(search, storage) {
38
40
  }
39
41
  return storage ? parseChanges(safe(() => storage.getItem(SESSION_KEY), null)) : [];
40
42
  }
43
+ const REPO_RE = /^[\w.-]+\/[\w.-]+$/;
44
+ function readRepo(search, storage) {
45
+ const params = new URLSearchParams(search);
46
+ if (params.has(PARAM)) {
47
+ const raw = params.get(REPO_PARAM)?.trim() ?? "";
48
+ const repo = REPO_RE.test(raw) ? raw : null;
49
+ if (storage) safe(() => repo ? storage.setItem(REPO_KEY, repo) : storage.removeItem(REPO_KEY), void 0);
50
+ return repo;
51
+ }
52
+ const kept = storage ? safe(() => storage.getItem(REPO_KEY), null) : null;
53
+ return kept && REPO_RE.test(kept) ? kept : null;
54
+ }
41
55
  function readUse(search, storage) {
42
56
  const params = new URLSearchParams(search);
43
57
  if (params.has(PARAM)) return params.get(USE_PARAM);
@@ -76,6 +90,7 @@ function whereAmI(host, build) {
76
90
  const prodHost = build.production ? safe(() => new URL(build.production).host, null) : null;
77
91
  if (build.deployEnv === "production" || prodHost && host.toLowerCase() === prodHost.toLowerCase()) return "production";
78
92
  if (build.deployEnv === "preview") return "preview";
93
+ if (build.preview && isPreviewUrl(`https://${host}`, build.preview)) return "preview";
79
94
  return "local";
80
95
  }
81
96
  function shouldRender(input) {
@@ -289,11 +304,12 @@ function fromText(from, titleOf) {
289
304
  return `from ${names.length <= 2 ? names.join(" and ") : `${names.slice(0, -1).join(", ")} and ${names[names.length - 1]}`}`;
290
305
  }
291
306
  export {
292
- togetherLabel as A,
293
- changeSummary as B,
294
- dockAt as C,
295
- stepDock as D,
296
- DOCK_KEY as E,
307
+ placeToolbar as A,
308
+ togetherLabel as B,
309
+ changeSummary as C,
310
+ dockAt as D,
311
+ stepDock as E,
312
+ DOCK_KEY as F,
297
313
  MARKS_PARAM as M,
298
314
  OPEN_KEY as O,
299
315
  PARAM as P,
@@ -304,26 +320,26 @@ export {
304
320
  changedScreens as c,
305
321
  readableTitle as d,
306
322
  toggleIncluded as e,
307
- readReturn as f,
308
- readUse as g,
309
- shouldRender as h,
310
- readDock as i,
311
- readScroll as j,
312
- sameScreenOn as k,
323
+ readRepo as f,
324
+ readReturn as g,
325
+ readUse as h,
326
+ shouldRender as i,
327
+ readDock as j,
328
+ readScroll as k,
313
329
  liveTokensUrl as l,
314
- studioChangesUrl as m,
330
+ sameScreenOn as m,
315
331
  noVisibleDifference as n,
316
- studioChangeUrl as o,
317
- contrastRatio as p,
318
- toHex as q,
332
+ studioChangesUrl as o,
333
+ studioChangeUrl as p,
334
+ contrastRatio as q,
319
335
  readChanges as r,
320
336
  stepOfToken as s,
321
337
  tokenChanges as t,
322
- fromText as u,
323
- TOGETHER_HINT as v,
338
+ toHex as u,
339
+ fromText as v,
324
340
  whereAmI as w,
325
- isSubtle as x,
326
- isFlipKey as y,
327
- placeToolbar as z
341
+ TOGETHER_HINT as x,
342
+ isSubtle as y,
343
+ isFlipKey as z
328
344
  };
329
- //# sourceMappingURL=session-Dvma9jtT.js.map
345
+ //# sourceMappingURL=session-Bj7imFZm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-Bj7imFZm.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';\n/** How many areas a code change marks on the screen, carried from This change to Live product (markers.ts). */\nexport const MARKS_PARAM = 'bridge-marks';\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/**\n * The repository the change lives in, when it is not the product's own: the design team's copy (products[].design.repo).\n * Studio adds it to the link; the switch between This change and Live product keeps it (the whole query is carried).\n */\nexport const REPO_PARAM = 'bridge-repo';\nexport const REPO_KEY = 'bridge-admin:repo';\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\nconst REPO_RE = /^[\\w.-]+\\/[\\w.-]+$/;\n\n/**\n * The repository that came with the change (REPO_PARAM): from the address, kept for the session like the change, else\n * the session's. Null when none or not \"owner/name\"; config.ts only honors it when it is the product's design copy.\n */\nexport function readRepo(search: string, storage: StorageLike | null): string | null {\n const params = new URLSearchParams(search);\n if (params.has(PARAM)) {\n const raw = params.get(REPO_PARAM)?.trim() ?? '';\n const repo = REPO_RE.test(raw) ? raw : null;\n if (storage) safe(() => (repo ? storage.setItem(REPO_KEY, repo) : storage.removeItem(REPO_KEY)), undefined);\n return repo;\n }\n const kept = storage ? safe(() => storage.getItem(REPO_KEY), null) : null;\n return kept && REPO_RE.test(kept) ? kept : 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/**\n * Which deployment this page is: the product in production by host or by build, a preview, or a local build. A host\n * that matches the preview template is a preview even when the build does not say (Cloudflare Pages, Netlify and other\n * hosts set no VERCEL_ENV).\n */\nexport function whereAmI(host: string, build: Pick<BridgeBuild, 'production' | 'deployEnv'> & Partial<Pick<BridgeBuild, 'preview'>>): 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 if (build.preview && isPreviewUrl(`https://${host}`, build.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; marks?: number | null }): 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.delete(MARKS_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 // The areas a code change marks on this screen: Live product says how many wait on This change.\n if (typeof extra.marks === 'number' && extra.marks >= 0) params.set(MARKS_PARAM, String(extra.marks));\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":"AAoCO,MAAM,QAAQ;AAEd,MAAM,eAAe;AAErB,MAAM,eAAe;A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AAM,KAAM,QAAO;AACrC,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;"}
package/dist/session.d.ts CHANGED
@@ -42,6 +42,12 @@ export declare const OPEN_KEY = "bridge-admin:toolbar-open";
42
42
  /** Changes tried together: the picks of the tokens they set differently (core encodePicks), from Studio. */
43
43
  export declare const USE_PARAM = "bridge-use";
44
44
  export declare const USE_KEY = "bridge-admin:use";
45
+ /**
46
+ * The repository the change lives in, when it is not the product's own: the design team's copy (products[].design.repo).
47
+ * Studio adds it to the link; the switch between This change and Live product keeps it (the whole query is carried).
48
+ */
49
+ export declare const REPO_PARAM = "bridge-repo";
50
+ export declare const REPO_KEY = "bridge-admin:repo";
45
51
  /** At most this many changes are tried together. */
46
52
  export declare const MAX_TOGETHER = 4;
47
53
  /**
@@ -61,6 +67,11 @@ export declare function parseChanges(raw: string | null | undefined): number[];
61
67
  * memory. The picks (`bridge-use`) travel with the list and are kept, or forgotten, with it.
62
68
  */
63
69
  export declare function readChanges(search: string, storage: StorageLike | null): number[];
70
+ /**
71
+ * The repository that came with the change (REPO_PARAM): from the address, kept for the session like the change, else
72
+ * the session's. Null when none or not "owner/name"; config.ts only honors it when it is the product's design copy.
73
+ */
74
+ export declare function readRepo(search: string, storage: StorageLike | null): string | null;
64
75
  /** The picks that came with the list: from the address, else the session. */
65
76
  export declare function readUse(search: string, storage: StorageLike | null): string | null;
66
77
  /** A host that matches the product's preview template (`bridge-admin-git-{branch}-team.vercel.app`), https only. */
@@ -68,8 +79,12 @@ export declare function isPreviewUrl(raw: string | null | undefined, template: s
68
79
  /** The preview to return to from production, from `?bridge-return=` or the session. Only a preview host counts. */
69
80
  export declare function readReturn(search: string, storage: StorageLike | null, template: string | null): string | null;
70
81
  export type Where = 'production' | 'preview' | 'local';
71
- /** Which deployment this page is: the product in production by host or by build, a preview, or a local build. */
72
- export declare function whereAmI(host: string, build: Pick<BridgeBuild, 'production' | 'deployEnv'>): Where;
82
+ /**
83
+ * Which deployment this page is: the product in production by host or by build, a preview, or a local build. A host
84
+ * that matches the preview template is a preview even when the build does not say (Cloudflare Pages, Netlify and other
85
+ * hosts set no VERCEL_ENV).
86
+ */
87
+ export declare function whereAmI(host: string, build: Pick<BridgeBuild, 'production' | 'deployEnv'> & Partial<Pick<BridgeBuild, 'preview'>>): Where;
73
88
  /**
74
89
  * Whether the toolbar renders. Never without a change from Studio. In production only for the Before side of a code
75
90
  * change, that is with a preview to return to: production on its own renders nothing.
package/dist/together.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { combineChanges, buildTokenSet, previewOverrides, cssVarOf, resolve, parseColor, cssOf } from "@bridge-ds/core";
2
2
  import { changeEdits, decodePicks } from "@bridge-ds/core";
3
- import { s as stepOfToken, a as roleOfToken } from "./session-Dvma9jtT.js";
3
+ import { s as stepOfToken, a as roleOfToken } from "./session-Bj7imFZm.js";
4
4
  function togetherBase(latest, options, modes) {
5
5
  return { latest, options, modes, main: buildTokenSet(latest, options) };
6
6
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bridge-ds/toolbar",
3
- "version": "0.5.0",
3
+ "version": "0.7.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.26.0",
52
+ "@bridge-ds/core": "^0.27.0",
53
53
  "lucide-react": "1.58.0"
54
54
  },
55
55
  "peerDependencies": {