@brucesantos/design-space 0.9.0 → 0.9.2

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.
@@ -14,8 +14,9 @@ export type ScreenNode = {
14
14
  description: string | undefined;
15
15
  route: RouteDefinition;
16
16
  /**
17
- * Caminho concreto para abrir a tela quando não há variação: o `path` com
18
- * `*` removido. Parâmetros `:id` ficam literais.
17
+ * Caminho concreto para abrir a tela sem cenário: o `path` com os exemplos de
18
+ * `route.params` no lugar dos parâmetros. `*` sem exemplo é removido; `:id`
19
+ * sem exemplo fica literal.
19
20
  */
20
21
  href: string;
21
22
  /** Cenários da rota, na ordem de `scenarios`. */
@@ -63,6 +64,11 @@ export type Registry = {
63
64
  /** Telas na ordem de `routes`, cada uma com suas variações. */
64
65
  screens: ScreenNode[];
65
66
  issues: ValidationIssue[];
67
+ /**
68
+ * `product.defaultPersona`, quando é uma persona registrada. É a persona de
69
+ * toda tela e cenário sem persona própria.
70
+ */
71
+ defaultPersona: string | undefined;
66
72
  scenario: (id: string | undefined) => Scenario | undefined;
67
73
  component: (id: string | undefined) => ComponentPreview | undefined;
68
74
  componentFixture: (componentId: string | undefined, fixtureId: string | undefined) => ComponentPreviewFixture | undefined;
@@ -95,7 +101,10 @@ export type Registry = {
95
101
  }) => ControlResolution;
96
102
  /** Regras de um cenário, resolvidas e na ordem declarada. */
97
103
  rulesOf: (scenario: Scenario | undefined) => Rule[];
98
- /** Permissões efetivas: as do cenário, ou as da persona quando ausentes. */
104
+ /**
105
+ * Permissões efetivas: as do cenário, ou as da persona dele quando ausentes —
106
+ * e a persona dele é a própria ou, na falta, a padrão do produto.
107
+ */
99
108
  permissionsOf: (scenario: Scenario | undefined) => string[];
100
109
  /** Variações da tela que renderiza `route`. */
101
110
  scenariosForRoute: (route: string, options?: ScenarioQueryOptions) => Scenario[];
@@ -13,3 +13,8 @@ export declare function matchPath(pattern: string, path: string): Record<string,
13
13
  * e `/requests/:id`, a literal ganha, independente da ordem de declaração.
14
14
  */
15
15
  export declare function resolveRoute(routes: RouteDefinition[], path: string): RouteMatch | undefined;
16
+ /**
17
+ * Caminho concreto de uma rota sem cenário: cada `:param` com exemplo em
18
+ * `params` recebe o exemplo, e o curinga final recebe `params["*"]` ou some.
19
+ */
20
+ export declare function screenHref(path: string, params?: Record<string, string>): string;
@@ -17,6 +17,8 @@ export type PanelProps = {
17
17
  onTab: (tab: PanelTab) => void;
18
18
  onOpenScenario: (scenarioId: string) => void;
19
19
  onOpenComponent: (componentId: string) => void;
20
+ /** Abre uma tela sem cenário, no `href` dela (com os exemplos de `route.params`). */
21
+ onOpenScreen?: (screenId: string) => void;
20
22
  onChange: (patch: Partial<ControlsState>) => void;
21
23
  width: number;
22
24
  onResize: (width: number) => void;
@@ -25,8 +27,8 @@ export type PanelProps = {
25
27
  };
26
28
  export declare function Panel(props: PanelProps): import("react").JSX.Element;
27
29
  /**
28
- * Até quatro opções curtas cabem como botões segmentados na largura do painel;
29
- * acima disso, um select.
30
+ * Mantido por compatibilidade com a 0.9.0: o painel passou a usar select para
31
+ * todo controle.
30
32
  */
31
33
  export declare function isSegmentedControl(control: Control): boolean;
32
34
  /** Cmd/Ctrl+F: o filtro do painel no lugar da busca do navegador. */
@@ -2,7 +2,7 @@
2
2
  * Ícones do chrome: traço simples, `currentColor`, 16px. Sem texto, sem cor.
3
3
  * Todo ícone é decorativo; o nome acessível fica no botão que o contém.
4
4
  */
5
- export type IconName = "mobile" | "tablet" | "desktop" | "fit" | "rotate" | "minus" | "plus" | "link" | "check" | "fullscreen" | "sun" | "moon" | "panel" | "alert" | "chevron" | "search" | "copy";
5
+ export type IconName = "mobile" | "tablet" | "desktop" | "fit" | "rotate" | "minus" | "plus" | "link" | "arrow-up-right" | "check" | "fullscreen" | "sun" | "moon" | "panel" | "alert" | "chevron" | "search" | "copy";
6
6
  export declare function Icon({ name, size }: {
7
7
  name: IconName;
8
8
  size?: number;
@@ -49,6 +49,7 @@ export type Labels = {
49
49
  infoTab: string;
50
50
  resize: string;
51
51
  variationsList: string;
52
+ componentVariations: string;
52
53
  defaultVariation: string;
53
54
  defaultVariationHint: string;
54
55
  noVariations: string;
package/dist/testing.js CHANGED
@@ -1,4 +1,4 @@
1
- import { F as s, v as t, y as i, x as a, s as n } from "./index-DxIx4GAk.js";
1
+ import { F as s, v as t, z as i, y as a, j as n } from "./index-Bj69Oe2X.js";
2
2
  function c(o = "http://localhost:5173") {
3
3
  const r = typeof process < "u" ? process.env : {};
4
4
  return (r.PREVIEW_URL || r.BASE_URL || o).replace(/\/$/, "");
@@ -159,6 +159,13 @@ export type RouteDefinition = {
159
159
  expected?: string[];
160
160
  /** Ids do catálogo usados pela tela (mesmo papel de `Scenario.components`). */
161
161
  components?: string[];
162
+ /**
163
+ * Valores de exemplo dos parâmetros do `path` (`{ id: "REQ-1" }` para
164
+ * `/requests/:id`), e de `*` quando houver. O motor usa sempre que precisa
165
+ * abrir a tela sem cenário — lateral, variação padrão, links de Informações e
166
+ * "Copiar para o PR". Sem eles, o caminho abre literal (`/requests/:id`).
167
+ */
168
+ params?: Record<string, string>;
162
169
  };
163
170
  export type ScreenProps = {
164
171
  /** Parâmetros dinâmicos casados da rota. */
@@ -266,6 +273,12 @@ export type ProductDefinition = {
266
273
  */
267
274
  scenarios: Scenario[];
268
275
  personas: Persona[];
276
+ /**
277
+ * Persona efetiva de toda tela e todo cenário sem persona própria. Sem ela, a
278
+ * tela sem cenário abre sem persona (e sem permissões). Persona do cenário e
279
+ * a escolhida no painel continuam vencendo.
280
+ */
281
+ defaultPersona?: string;
269
282
  fixtures: Fixture[];
270
283
  rules?: Rule[];
271
284
  /** Rotas declarativas. Cada rota é uma tela na lista de Telas. */
@@ -357,8 +370,20 @@ export type ScenarioContext = {
357
370
  viewport: ViewportSetting;
358
371
  themeMode: string | undefined;
359
372
  locale: string | undefined;
360
- /** Navega dentro do Design Space preservando os controles ativos. */
361
- navigate: (to: string) => void;
373
+ /**
374
+ * Navega dentro do Design Space, também de dentro do quadro.
375
+ *
376
+ * - `navigate("/x")`, sem query: a query atual segue inteira; numa tela
377
+ * diferente, os `c.*` da anterior ficam para trás.
378
+ * - `navigate("/x?a=1")` ou com `options.controls`: o destino manda na query.
379
+ * O contexto do motor (persona, rede, viewport, tema, idioma, fonte de
380
+ * dados, handoff…) é preservado quando o destino não o traz; `scenario`,
381
+ * `fixture`, `component` e os `c.*` da tela anterior não. A persona que vinha
382
+ * do cenário deixado para trás vira parâmetro explícito.
383
+ * - `options.controls` vira `c.*` do destino; valor igual ao padrão da tela
384
+ * de destino não entra na URL.
385
+ */
386
+ navigate: (to: string, options?: NavigateOptions) => void;
362
387
  /** Abre outro cenário por id. */
363
388
  openScenario: (scenarioId: string) => void;
364
389
  /**
@@ -371,6 +396,19 @@ export type ScenarioContext = {
371
396
  * controle de sobreposição para "nenhuma"). Atualiza a URL.
372
397
  */
373
398
  setControl: (id: string, value: string) => void;
399
+ /**
400
+ * Muda vários controles numa única atualização de URL. Chamadas seguidas de
401
+ * `setControl`/`setControls` no mesmo ciclo se acumulam: cada uma parte do
402
+ * estado mais recente, não do valor da última renderização.
403
+ */
404
+ setControls: (patch: Record<string, string>) => void;
405
+ };
406
+ /** Opções de {@link ScenarioContext.navigate}. */
407
+ export type NavigateOptions = {
408
+ /** Controles da tela de destino (id → value), escritos como `c.<id>`. */
409
+ controls?: Record<string, string>;
410
+ /** Substitui a entrada atual do histórico em vez de criar uma nova. */
411
+ replace?: boolean;
374
412
  };
375
413
  export type ViewportSetting = {
376
414
  /** `mobile`, `tablet`, `desktop`, `fit` ou `custom` (só por URL). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brucesantos/design-space",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Motor neutro do Bananas Design Space: telas como rotas com variações, catálogo de componentes, chrome em preto e branco com a UI do produto num iframe, deep links e controles de persona/viewport/rede. Não contém UI de cliente.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -1,439 +0,0 @@
1
- const U = [
2
- "success",
3
- "loading",
4
- "empty",
5
- "error",
6
- "slow"
7
- ];
8
- function F(e, r) {
9
- const o = e.split("/").filter(Boolean), n = z(r).split("/").filter(Boolean), i = {};
10
- for (const [d, c] of o.entries()) {
11
- if (c === "*")
12
- return i["*"] = n.slice(d).join("/"), i;
13
- const h = n[d];
14
- if (h === void 0) return null;
15
- if (c.startsWith(":")) {
16
- i[c.slice(1)] = h;
17
- continue;
18
- }
19
- if (c !== h) return null;
20
- }
21
- return o.length !== n.length ? null : i;
22
- }
23
- function j(e, r) {
24
- const o = [...e].sort((n, i) => C(i.path) - C(n.path));
25
- for (const n of o) {
26
- const i = F(n.path, r);
27
- if (i) return { definition: n, params: i };
28
- }
29
- }
30
- function C(e) {
31
- const r = e.split("/").filter(Boolean);
32
- let o = r.length;
33
- for (const n of r)
34
- n === "*" ? o -= 2 : n.startsWith(":") ? o += 1 : o += 4;
35
- return o;
36
- }
37
- function z(e) {
38
- const r = e.split("?")[0] ?? e;
39
- try {
40
- return decodeURI(r);
41
- } catch {
42
- return r;
43
- }
44
- }
45
- const P = /^[a-z0-9]+([.\-][a-z0-9]+)*$/, M = /^[A-Za-z0-9][A-Za-z0-9_.-]*$/;
46
- function f(e) {
47
- return typeof e == "string" && e.trim().length > 0;
48
- }
49
- function E(e, r) {
50
- const o = [], n = f(e?.id) ? `scenario:${e.id}` : `scenario[${r ?? "?"}]`, i = (c) => o.push({ level: "error", where: n, message: c }), d = (c) => o.push({ level: "warning", where: n, message: c });
51
- return f(e?.id) ? P.test(e.id) || i(
52
- "`id` deve ser minúsculo, em kebab-case, com pontos opcionais: `requests.approve-blocked` ou `approve-blocked`."
53
- ) : i("`id` é obrigatório."), f(e?.title) || i("`title` é obrigatório e deve usar o vocabulário do negócio."), f(e?.route) ? e.route.startsWith("/") || i("`route` deve começar com `/`.") : i("`route` é obrigatório."), e?.persona !== void 0 && !f(e.persona) && i("`persona`, quando informada, deve ser o id de uma persona registrada."), f(e?.fixture) || i("`fixture` é obrigatório. O padrão do ambiente é dado sintético (D-05)."), e?.components !== void 0 && !Array.isArray(e.components) && i("`components`, quando informado, deve ser uma lista de ids de componente."), e?.network && !U.includes(e.network) && i(`\`network\` deve ser um de: ${U.join(", ")}.`), e?.expected?.length || d(
54
- "Sem `expected`, o cenário não vira caso verificável no handoff — é tela bonita sem critério (risco: prototype theater)."
55
- ), o;
56
- }
57
- function V(e) {
58
- const r = [], o = (s, t, a) => r.push({ level: s, where: t, message: a }), n = new Set(e.personas?.map((s) => s.id) ?? []), i = new Set(e.fixtures?.map((s) => s.id) ?? []), d = new Set(e.rules?.map((s) => s.id) ?? []), c = /* @__PURE__ */ new Set();
59
- f(e.id) || o("error", "product", "`id` é obrigatório."), f(e.name) || o("error", "product", "`name` é obrigatório."), !e.routes?.length && e.scenarios?.length && o("error", "product", "`routes` está vazio: nenhum cenário conseguirá renderizar."), "modules" in e && o(
60
- "warning",
61
- "product",
62
- "`modules` foi removido na 0.8.0 e é ignorado: cada rota é uma tela, e os cenários da rota são as variações dela."
63
- );
64
- const h = /* @__PURE__ */ new Set();
65
- for (const [s, t] of (e.routes ?? []).entries()) {
66
- const a = `route:${t?.path ?? s}`;
67
- if (!f(t?.path)) {
68
- o("error", a, "`path` é obrigatório.");
69
- continue;
70
- }
71
- t.path.startsWith("/") || o("error", a, "`path` deve começar com `/`."), h.has(t.path) && o("error", a, `\`path\` duplicado: ${t.path}. Cada rota é uma tela.`), h.add(t.path), typeof t.screen != "function" && typeof t.screen != "object" && o("error", a, "`screen` é obrigatório."), t.name !== void 0 && !f(t.name) && o("warning", a, "`name` vazio: a tela aparece com o título do primeiro cenário."), t.group !== void 0 && !f(t.group) && o("warning", a, "`group` vazio: a tela aparece fora de qualquer fluxo."), t.expected !== void 0 && !Array.isArray(t.expected) && o("error", a, "`expected`, quando informado, deve ser uma lista de frases."), t.components !== void 0 && !Array.isArray(t.components) && o("error", a, "`components`, quando informado, deve ser uma lista de ids de componente."), t.controls !== void 0 && (Array.isArray(t.controls) ? L(t.controls, a, o) : o("error", a, "`controls`, quando informado, deve ser uma lista de grupos de controles."));
72
- }
73
- const w = /* @__PURE__ */ new Set();
74
- for (const [s, t] of (e.components ?? []).entries()) {
75
- const a = `component:${t?.id ?? s}`;
76
- f(t?.id) ? P.test(t.id) ? w.has(t.id) ? o("error", a, `\`id\` duplicado: ${t.id}.`) : w.add(t.id) : o("error", a, "`id` deve ser minúsculo em kebab-case ou usar pontos para agrupamento.") : o("error", a, "`id` é obrigatório."), f(t?.name) || o("error", a, "`name` é obrigatório."), typeof t?.preview != "function" && typeof t?.preview != "object" && o("error", a, "`preview` é obrigatório."), t?.source !== void 0 && typeof t.source != "string" && o("error", a, "`source`, quando informado, é texto livre.");
77
- const l = /* @__PURE__ */ new Set();
78
- for (const [$, g] of (t?.fixtures ?? []).entries()) {
79
- const p = `${a}/fixture:${g?.id ?? $}`;
80
- f(g?.id) ? P.test(g.id) ? l.has(g.id) ? o("error", p, `Id de fixture do componente duplicado: \`${g.id}\`.`) : l.add(g.id) : o(
81
- "error",
82
- p,
83
- `Id de fixture do componente inválido: \`${g.id}\`. Use minúsculas em kebab-case.`
84
- ) : o("error", p, "`id` da fixture do componente é obrigatório."), f(g?.label) || o("error", p, "`label` da fixture do componente é obrigatório."), (!g || !("data" in g)) && o("error", p, "`data` da fixture do componente é obrigatório.");
85
- }
86
- t?.defaultFixture && !l.has(t.defaultFixture) && o(
87
- "error",
88
- a,
89
- `\`defaultFixture\` aponta para fixture inexistente: \`${t.defaultFixture}\`.`
90
- );
91
- }
92
- for (const s of e.routes ?? []) {
93
- if (!f(s?.path)) continue;
94
- const t = `route:${s.path}`;
95
- for (const a of Array.isArray(s.components) ? s.components : [])
96
- w.has(a) || o(
97
- "warning",
98
- t,
99
- `Componente não registrado: \`${a}\`. Ele não aparece em "Componentes usados".`
100
- );
101
- for (const a of Array.isArray(s.controls) ? s.controls : [])
102
- a?.component !== void 0 && !w.has(a.component) && o(
103
- "warning",
104
- `${t}/group:${a.id}`,
105
- `Componente não registrado: \`${a.component}\`. O grupo aparece sem link para o catálogo.`
106
- );
107
- }
108
- for (const [s, t] of (e.scenarios ?? []).entries()) {
109
- r.push(...E(t, s));
110
- const a = `scenario:${t?.id ?? s}`;
111
- t?.id && (c.has(t.id) && o("error", a, `\`id\` duplicado: ${t.id}.`), c.add(t.id)), t?.persona && !n.has(t.persona) && o("error", a, `Persona não registrada: \`${t.persona}\`.`), t?.fixture && !i.has(t.fixture) && o("error", a, `Fixture não registrada: \`${t.fixture}\`.`);
112
- for (const l of t?.rules ?? [])
113
- d.has(l) || o("error", a, `Regra não registrada: \`${l}\`.`);
114
- for (const l of Array.isArray(t?.components) ? t.components : [])
115
- w.has(l) || o(
116
- "warning",
117
- a,
118
- `Componente não registrado: \`${l}\`. Ele não aparece em "Componentes usados".`
119
- );
120
- if (t?.controls !== void 0) {
121
- if (!t.controls || typeof t.controls != "object" || Array.isArray(t.controls))
122
- o("error", a, "`controls`, quando informado, é um objeto de id do controle → valor.");
123
- else if (t.route) {
124
- const l = j(e.routes ?? [], t.route.split("?")[0] ?? t.route), $ = Array.isArray(l?.definition.controls) ? l.definition.controls : [], g = new Map(
125
- $.flatMap((p) => Array.isArray(p?.controls) ? p.controls : []).map((p) => [
126
- p?.id,
127
- p
128
- ])
129
- );
130
- for (const [p, k] of Object.entries(t.controls)) {
131
- const x = g.get(p);
132
- x ? (x.options ?? []).some((A) => A?.value === k) || o(
133
- "error",
134
- a,
135
- `Valor \`${k}\` não é opção do controle \`${p}\`. Opções: ${(x.options ?? []).map((A) => `\`${A?.value}\``).join(", ")}.`
136
- ) : o(
137
- "error",
138
- a,
139
- `Controle \`${p}\` não existe na tela \`${l?.definition.path ?? t.route}\`.`
140
- );
141
- }
142
- }
143
- }
144
- t?.route && !q(t.route, e) && o(
145
- "error",
146
- a,
147
- `Rota \`${t.route}\` não casa com nenhuma rota declarada. O deep link abriria a tela de rota inexistente.`
148
- );
149
- }
150
- const u = e.dataSources?.default;
151
- return u && u !== "fixtures" && (new Set(e.dataSources?.adapters?.map((t) => t.id) ?? []).has(u) || o("error", "product", `\`dataSources.default\` aponta para adapter inexistente: \`${u}\`.`), o(
152
- "warning",
153
- "product",
154
- "A fonte padrão não é `fixtures`. O padrão do ambiente é dado sintético e determinístico (D-05); API real entra como adapter opcional, com justificativa."
155
- )), r;
156
- }
157
- function L(e, r, o) {
158
- const n = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
159
- for (const [d, c] of e.entries()) {
160
- const h = `${r}/group:${c?.id ?? d}`;
161
- if (f(c?.id) ? n.has(c.id) ? o("error", h, `\`id\` de grupo duplicado na tela: \`${c.id}\`.`) : n.add(c.id) : o("error", h, "`id` do grupo de controles é obrigatório."), f(c?.title) || o("error", h, "`title` do grupo é obrigatório."), !Array.isArray(c?.controls)) {
162
- o("error", h, "`controls` do grupo deve ser uma lista.");
163
- continue;
164
- }
165
- for (const [w, u] of c.controls.entries()) {
166
- const s = `${h}/control:${u?.id ?? w}`;
167
- f(u?.id) ? M.test(u.id) ? i.has(u.id) ? o("error", s, `\`id\` de controle duplicado na tela: \`${u.id}\`.`) : i.add(u.id) : o(
168
- "error",
169
- s,
170
- `Id de controle inválido: \`${u.id}\`. Use letras, números, \`-\`, \`_\` ou \`.\`, sem espaço: ele vira \`c.<id>\` na URL.`
171
- ) : o("error", s, "`id` do controle é obrigatório."), f(u?.label) || o("error", s, "`label` do controle é obrigatório.");
172
- const t = Array.isArray(u?.options) ? u.options : [];
173
- if (t.length === 0) {
174
- o("error", s, "`options` precisa de ao menos uma opção.");
175
- continue;
176
- }
177
- const a = /* @__PURE__ */ new Set();
178
- for (const l of t)
179
- f(l?.value) ? a.has(l.value) ? o("error", s, `Opção duplicada: \`${l.value}\`.`) : a.add(l.value) : o("error", s, "Toda opção precisa de `value`."), f(l?.label) || o("error", s, `A opção \`${l?.value ?? "?"}\` precisa de \`label\`.`);
180
- u.default !== void 0 && !a.has(u.default) && o(
181
- "error",
182
- s,
183
- `\`default\` não é uma das opções: \`${u.default}\`. Opções: ${[...a].map((l) => `\`${l}\``).join(", ")}.`
184
- );
185
- }
186
- }
187
- }
188
- function q(e, r) {
189
- const o = e.split("?")[0] ?? e;
190
- return (r.routes ?? []).some((n) => _(n.path, o));
191
- }
192
- function _(e, r) {
193
- const o = e.split("/").filter(Boolean), n = r.split("/").filter(Boolean);
194
- for (const [i, d] of o.entries()) {
195
- if (d === "*") return !0;
196
- const c = n[i];
197
- if (c === void 0) return !1;
198
- if (!d.startsWith(":") && d !== c)
199
- return !1;
200
- }
201
- return o.length === n.length;
202
- }
203
- function Z(e) {
204
- return e.some((r) => r.level === "error");
205
- }
206
- function G(e) {
207
- return e.length === 0 ? "Nenhum problema encontrado." : e.map((r) => `${r.level === "error" ? "✖" : "▲"} ${r.where}
208
- ${r.message}`).join(`
209
- `);
210
- }
211
- const v = {
212
- enabled: "handoff",
213
- scenario: "allowScenario",
214
- route: "allowRoute",
215
- component: "allowComponent"
216
- };
217
- function Q(e) {
218
- if (e.get(v.enabled) === "1")
219
- return I({
220
- scenarios: e.getAll(v.scenario),
221
- routes: e.getAll(v.route),
222
- components: e.getAll(v.component)
223
- });
224
- }
225
- function B(e, r) {
226
- for (const n of Object.values(v)) e.delete(n);
227
- if (!r) return;
228
- e.set(v.enabled, "1");
229
- const o = I(r);
230
- for (const n of o.scenarios ?? []) e.append(v.scenario, n);
231
- for (const n of o.routes ?? []) e.append(v.route, n);
232
- for (const n of o.components ?? []) e.append(v.component, n);
233
- }
234
- function I(e) {
235
- const r = S(e.scenarios), o = S(e.routes), n = S(e.components);
236
- return {
237
- ...r.length ? { scenarios: r } : {},
238
- ...o.length ? { routes: o } : {},
239
- ...n.length ? { components: n } : {}
240
- };
241
- }
242
- function W(e, r) {
243
- return !e || !!(r && e.scenarios?.includes(r));
244
- }
245
- function X(e, r) {
246
- return !e || !!(r && e.components?.includes(r));
247
- }
248
- function Y(e, r, o = []) {
249
- return !e || r === "/" ? !0 : [
250
- ...e.routes ?? [],
251
- ...o.filter((i) => W(e, i.id)).map((i) => i.route)
252
- ].some((i) => F(i, r) !== null);
253
- }
254
- function S(e) {
255
- return [...new Set((e ?? []).map((r) => r.trim()).filter(Boolean))].sort();
256
- }
257
- const m = {
258
- scenario: "scenario",
259
- component: "component",
260
- persona: "persona",
261
- fixture: "fixture",
262
- network: "network",
263
- viewport: "viewport",
264
- customWidth: "w",
265
- themeMode: "theme",
266
- locale: "locale",
267
- dataSource: "source",
268
- chromeTheme: "appearance",
269
- chrome: "chrome",
270
- inspector: "panel",
271
- panelTab: "tab",
272
- zoom: "zoom",
273
- rotated: "rotate"
274
- }, b = "c.";
275
- function J(e) {
276
- const r = typeof e == "string" ? new URLSearchParams(e) : e, o = {};
277
- for (const [n, i] of r) {
278
- if (!n.startsWith(b)) continue;
279
- const d = n.slice(b.length);
280
- d && (o[d] = i);
281
- }
282
- return o;
283
- }
284
- function ee(e) {
285
- for (const r of [...e.keys()])
286
- r.startsWith(b) && e.delete(r);
287
- }
288
- function N(e) {
289
- return typeof e == "boolean" ? e ? "1" : "0" : String(e);
290
- }
291
- function O(e, r = {}) {
292
- for (const [o, n] of Object.entries(r)) {
293
- if (n == null) continue;
294
- if (o === "handoff") {
295
- B(e, n);
296
- continue;
297
- }
298
- if (o === "screenControls") {
299
- for (const [d, c] of Object.entries(n))
300
- e.set(`${b}${d}`, c);
301
- continue;
302
- }
303
- const i = m[o];
304
- i && e.set(i, N(n));
305
- }
306
- }
307
- const y = "ds-frame", D = "data-ds-frame", T = [
308
- m.chromeTheme,
309
- m.chrome,
310
- m.inspector,
311
- m.panelTab,
312
- m.zoom,
313
- m.rotated
314
- ];
315
- function oe(e, r) {
316
- const o = new URLSearchParams(r);
317
- for (const n of T) o.delete(n);
318
- return o.delete(y), o.set(y, "1"), `${e || "/"}?${o.toString()}`;
319
- }
320
- function re(e) {
321
- const r = new URL(e, "http://design-space.invalid");
322
- r.searchParams.delete(y);
323
- const o = r.searchParams.toString();
324
- return { path: r.pathname || "/", search: o ? `?${o}` : "" };
325
- }
326
- function te(e) {
327
- const r = new URL(e, "http://design-space.invalid");
328
- return `${r.pathname}|${r.searchParams.get(m.component) ?? ""}`;
329
- }
330
- function ne(e, r) {
331
- const o = new URLSearchParams(e), n = new URLSearchParams(r);
332
- o.delete(y);
333
- for (const d of T) {
334
- o.delete(d);
335
- const c = n.get(d);
336
- c !== null && o.set(d, c);
337
- }
338
- const i = o.toString();
339
- return i ? `?${i}` : "";
340
- }
341
- function H(e) {
342
- if (!e || typeof e != "object") return !1;
343
- const r = e;
344
- if (r.ds !== 1 || typeof r.type != "string") return !1;
345
- switch (r.type) {
346
- case "ready":
347
- case "location":
348
- return typeof r.url == "string";
349
- case "navigate":
350
- return typeof r.url == "string";
351
- case "shortcut":
352
- return ["C", "K", "F"].includes(r.key);
353
- default:
354
- return !1;
355
- }
356
- }
357
- function ie(e, r) {
358
- if (e.origin === r.origin && !(!r.source || e.source !== r.source))
359
- return H(e.data) ? e.data : void 0;
360
- }
361
- function ae(e, r, o) {
362
- try {
363
- e?.postMessage(r, o);
364
- } catch {
365
- }
366
- }
367
- function se(e = typeof window > "u" ? void 0 : window) {
368
- if (!e) return !1;
369
- if (new URLSearchParams(e.location.search).get(y) === "1") return !0;
370
- try {
371
- return !!e.frameElement?.hasAttribute(D);
372
- } catch {
373
- return !1;
374
- }
375
- }
376
- function R(e = {}) {
377
- const r = e.branchUrl || void 0, o = e.deploymentUrl || void 0, n = e.commit || void 0, i = e.env || "development", d = r && `https://${r}` || o && `https://${o}` || (typeof window < "u" ? window.location.origin : "http://localhost:5173");
378
- return {
379
- env: i,
380
- origin: d.replace(/\/$/, ""),
381
- branchUrl: r,
382
- deploymentUrl: o,
383
- branch: e.branch || void 0,
384
- commit: n,
385
- shortCommit: n?.slice(0, 7),
386
- isDeployed: i === "preview" || i === "production"
387
- };
388
- }
389
- function K(e, r = {}) {
390
- const o = r.origin ?? R().origin, n = new URL(e.route, o);
391
- return n.searchParams.set(m.scenario, e.id), e.persona && n.searchParams.set(m.persona, e.persona), n.searchParams.set(m.fixture, e.fixture), e.network && e.network !== "success" && n.searchParams.set(m.network, e.network), O(n.searchParams, r.overrides), n.toString();
392
- }
393
- function ce(e, r = {}) {
394
- const o = r.origin ?? R().origin, n = new URL("/", o), i = r.fixture ?? e.fixtures?.find((d) => d.id === e.defaultFixture)?.id ?? e.fixtures?.[0]?.id;
395
- return n.searchParams.set(m.component, e.id), i && n.searchParams.set(m.fixture, i), O(n.searchParams, r.overrides), n.toString();
396
- }
397
- function de(e, r) {
398
- const o = r.commit ?? R().commit;
399
- if (!o) return;
400
- const n = r.template.replaceAll("{shortCommit}", o.slice(0, 7)).replaceAll("{commit}", o);
401
- return K(e, { origin: n });
402
- }
403
- export {
404
- I as A,
405
- N as B,
406
- b as C,
407
- E as D,
408
- D as F,
409
- v as H,
410
- U as N,
411
- m as P,
412
- X as a,
413
- Y as b,
414
- J as c,
415
- B as d,
416
- ae as e,
417
- re as f,
418
- ee as g,
419
- W as h,
420
- ie as i,
421
- O as j,
422
- T as k,
423
- te as l,
424
- se as m,
425
- R as n,
426
- ne as o,
427
- Q as p,
428
- y as q,
429
- j as r,
430
- K as s,
431
- oe as t,
432
- de as u,
433
- V as v,
434
- ce as w,
435
- G as x,
436
- Z as y,
437
- F as z
438
- };
439
- //# sourceMappingURL=index-DxIx4GAk.js.map