@buffcore/cli 0.8.41 → 0.8.43

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.
Files changed (219) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/commands/agents-file.d.ts +5 -0
  3. package/dist/commands/agents-file.js +30 -7
  4. package/dist/commands/change.d.ts +4 -0
  5. package/dist/commands/change.js +12 -5
  6. package/dist/commands/create-block.d.ts +2 -1
  7. package/dist/commands/create-block.js +7 -5
  8. package/dist/commands/create.d.ts +3 -2
  9. package/dist/commands/create.en.js +1 -1
  10. package/dist/commands/create.es.js +1 -1
  11. package/dist/commands/create.js +8 -6
  12. package/dist/commands/design/check.d.ts +2 -0
  13. package/dist/commands/design/check.js +6 -0
  14. package/dist/commands/design/journey-roles.d.ts +6 -0
  15. package/dist/commands/design/journey-roles.js +60 -0
  16. package/dist/commands/design/references.d.ts +12 -0
  17. package/dist/commands/design/references.js +44 -0
  18. package/dist/commands/design/tells-text.js +2 -2
  19. package/dist/commands/design/tells.d.ts +3 -1
  20. package/dist/commands/design/tells.en.d.ts +2 -0
  21. package/dist/commands/design/tells.en.js +2 -0
  22. package/dist/commands/design/tells.es.js +2 -0
  23. package/dist/commands/design/tells.js +10 -7
  24. package/dist/commands/dev.js +3 -0
  25. package/dist/commands/extension/places-approval.d.ts +1 -1
  26. package/dist/commands/port-claims.d.ts +23 -0
  27. package/dist/commands/port-claims.js +95 -0
  28. package/dist/commands/prototype/browser.d.ts +9 -4
  29. package/dist/commands/prototype/browser.js +26 -18
  30. package/dist/commands/prototype/comp-record.d.ts +27 -0
  31. package/dist/commands/prototype/comp-record.js +85 -0
  32. package/dist/commands/prototype/comp-words.d.ts +12 -0
  33. package/dist/commands/prototype/comp-words.js +24 -0
  34. package/dist/commands/prototype/comp.d.ts +26 -0
  35. package/dist/commands/prototype/comp.js +71 -0
  36. package/dist/commands/prototype/export-base.d.ts +27 -0
  37. package/dist/commands/prototype/export-base.js +80 -0
  38. package/dist/commands/prototype/export.d.ts +3 -2
  39. package/dist/commands/prototype/export.js +13 -6
  40. package/dist/commands/prototype/index.js +1 -0
  41. package/dist/commands/prototype/media-ready.d.ts +8 -0
  42. package/dist/commands/prototype/media-ready.js +36 -0
  43. package/dist/commands/prototype/messages.en.d.ts +6 -0
  44. package/dist/commands/prototype/messages.en.js +6 -0
  45. package/dist/commands/prototype/messages.js +6 -0
  46. package/dist/commands/prototype/milestone-versions.d.ts +1 -1
  47. package/dist/commands/prototype/record-look-child.js +4 -1
  48. package/dist/commands/prototype/scene.d.ts +3 -1
  49. package/dist/commands/prototype/scene.js +22 -6
  50. package/dist/commands/prototype/snapshot-command.js +1 -1
  51. package/dist/commands/prototype/snapshot-inputs.js +35 -7
  52. package/dist/commands/prototype/snapshot-setup.d.ts +12 -1
  53. package/dist/commands/prototype/snapshot-setup.js +31 -6
  54. package/dist/commands/prototype/snapshot.d.ts +2 -0
  55. package/dist/commands/prototype/snapshot.js +2 -1
  56. package/dist/commands/prototype/versions.d.ts +3 -3
  57. package/dist/commands/ui/agents-route.d.ts +2 -0
  58. package/dist/commands/ui/agents-route.js +8 -5
  59. package/dist/commands/ui/approval-authority.d.ts +1 -1
  60. package/dist/commands/ui/approve.js +7 -1
  61. package/dist/commands/ui/chat/allow-folder.js +23 -77
  62. package/dist/commands/ui/chat/claude-permissions.d.ts +21 -0
  63. package/dist/commands/ui/chat/claude-permissions.js +69 -0
  64. package/dist/commands/ui/chat/codex-idle.d.ts +2 -0
  65. package/dist/commands/ui/chat/codex-overrides.js +2 -1
  66. package/dist/commands/ui/chat/codex-permissions.d.ts +12 -0
  67. package/dist/commands/ui/chat/codex-permissions.js +97 -0
  68. package/dist/commands/ui/chat/command-parts.d.ts +33 -0
  69. package/dist/commands/ui/chat/command-parts.js +219 -0
  70. package/dist/commands/ui/chat/command-wrappers.d.ts +21 -0
  71. package/dist/commands/ui/chat/command-wrappers.js +100 -0
  72. package/dist/commands/ui/chat/design-deletes.d.ts +1 -0
  73. package/dist/commands/ui/chat/design-deletes.js +39 -0
  74. package/dist/commands/ui/chat/fresh-critique.d.ts +28 -0
  75. package/dist/commands/ui/chat/fresh-critique.js +121 -0
  76. package/dist/commands/ui/chat/fresh-launch.d.ts +31 -0
  77. package/dist/commands/ui/chat/fresh-launch.js +122 -0
  78. package/dist/commands/ui/chat/fresh-prompts.d.ts +17 -0
  79. package/dist/commands/ui/chat/fresh-prompts.js +76 -0
  80. package/dist/commands/ui/chat/fresh-report.d.ts +8 -0
  81. package/dist/commands/ui/chat/fresh-report.js +36 -0
  82. package/dist/commands/ui/chat/fresh-routes.d.ts +3 -0
  83. package/dist/commands/ui/chat/fresh-routes.js +64 -0
  84. package/dist/commands/ui/chat/fresh-settings.d.ts +12 -0
  85. package/dist/commands/ui/chat/fresh-settings.js +66 -0
  86. package/dist/commands/ui/chat/fresh-store.d.ts +17 -0
  87. package/dist/commands/ui/chat/fresh-store.js +67 -0
  88. package/dist/commands/ui/chat/fresh.d.ts +31 -0
  89. package/dist/commands/ui/chat/fresh.en.d.ts +7 -0
  90. package/dist/commands/ui/chat/fresh.en.js +7 -0
  91. package/dist/commands/ui/chat/fresh.es.d.ts +7 -0
  92. package/dist/commands/ui/chat/fresh.es.js +7 -0
  93. package/dist/commands/ui/chat/fresh.js +112 -0
  94. package/dist/commands/ui/chat/launch-input.d.ts +4 -2
  95. package/dist/commands/ui/chat/launch-input.js +16 -3
  96. package/dist/commands/ui/chat/limit-mentions.d.ts +5 -0
  97. package/dist/commands/ui/chat/limit-mentions.js +94 -0
  98. package/dist/commands/ui/chat/limit-patterns.d.ts +15 -0
  99. package/dist/commands/ui/chat/limit-patterns.js +182 -0
  100. package/dist/commands/ui/chat/limits-hook.d.ts +1 -0
  101. package/dist/commands/ui/chat/limits-hook.js +30 -0
  102. package/dist/commands/ui/chat/limits.d.ts +44 -0
  103. package/dist/commands/ui/chat/limits.en.d.ts +20 -0
  104. package/dist/commands/ui/chat/limits.en.js +20 -0
  105. package/dist/commands/ui/chat/limits.es.d.ts +2 -0
  106. package/dist/commands/ui/chat/limits.es.js +19 -0
  107. package/dist/commands/ui/chat/limits.js +236 -0
  108. package/dist/commands/ui/chat/local-settings.d.ts +17 -0
  109. package/dist/commands/ui/chat/local-settings.js +73 -0
  110. package/dist/commands/ui/chat/opencode-config.d.ts +22 -0
  111. package/dist/commands/ui/chat/opencode-config.js +83 -0
  112. package/dist/commands/ui/chat/parse-claude.js +25 -5
  113. package/dist/commands/ui/chat/permission-ask.d.ts +44 -0
  114. package/dist/commands/ui/chat/permission-ask.js +145 -0
  115. package/dist/commands/ui/chat/permission-channel.d.ts +18 -0
  116. package/dist/commands/ui/chat/permission-channel.js +67 -0
  117. package/dist/commands/ui/chat/permission-route.d.ts +10 -0
  118. package/dist/commands/ui/chat/permission-route.js +47 -0
  119. package/dist/commands/ui/chat/permission-tool.d.ts +1 -0
  120. package/dist/commands/ui/chat/permission-tool.js +86 -0
  121. package/dist/commands/ui/chat/permissions.d.ts +11 -12
  122. package/dist/commands/ui/chat/permissions.js +20 -102
  123. package/dist/commands/ui/chat/planning-limits.d.ts +12 -0
  124. package/dist/commands/ui/chat/planning-limits.js +46 -0
  125. package/dist/commands/ui/chat/process.js +4 -1
  126. package/dist/commands/ui/chat/prompt.d.ts +8 -1
  127. package/dist/commands/ui/chat/prompt.en.d.ts +4 -0
  128. package/dist/commands/ui/chat/prompt.en.js +4 -0
  129. package/dist/commands/ui/chat/prompt.es.d.ts +4 -0
  130. package/dist/commands/ui/chat/prompt.es.js +4 -0
  131. package/dist/commands/ui/chat/prompt.js +18 -50
  132. package/dist/commands/ui/chat/publish-limits.d.ts +4 -0
  133. package/dist/commands/ui/chat/publish-limits.js +97 -0
  134. package/dist/commands/ui/chat/recorded-turn.js +6 -0
  135. package/dist/commands/ui/chat/routes.js +2 -0
  136. package/dist/commands/ui/chat/secret-folders.d.ts +16 -0
  137. package/dist/commands/ui/chat/secret-folders.js +35 -0
  138. package/dist/commands/ui/chat/stdin-shells.d.ts +8 -0
  139. package/dist/commands/ui/chat/stdin-shells.js +102 -0
  140. package/dist/commands/ui/chat/step-rules.d.ts +13 -0
  141. package/dist/commands/ui/chat/step-rules.js +47 -0
  142. package/dist/commands/ui/chat/store.js +11 -2
  143. package/dist/commands/ui/chat/stream.en.d.ts +6 -0
  144. package/dist/commands/ui/chat/stream.en.js +6 -0
  145. package/dist/commands/ui/chat/stream.es.d.ts +6 -0
  146. package/dist/commands/ui/chat/stream.es.js +6 -0
  147. package/dist/commands/ui/chat/stream.js +8 -2
  148. package/dist/commands/ui/chat/turn-guard.d.ts +27 -0
  149. package/dist/commands/ui/chat/turn-guard.js +86 -0
  150. package/dist/commands/ui/chat/turn-input.d.ts +3 -2
  151. package/dist/commands/ui/chat/turn-input.js +3 -1
  152. package/dist/commands/ui/chat/turn-scenes.d.ts +19 -0
  153. package/dist/commands/ui/chat/turn-scenes.js +44 -0
  154. package/dist/commands/ui/chat/turn-state.d.ts +11 -0
  155. package/dist/commands/ui/chat/turn.js +9 -3
  156. package/dist/commands/ui/comp-approval.d.ts +6 -0
  157. package/dist/commands/ui/comp-approval.js +42 -0
  158. package/dist/commands/ui/host.js +3 -0
  159. package/dist/commands/ui/index.js +18 -6
  160. package/dist/commands/ui/level-route.js +8 -3
  161. package/dist/commands/ui/loop-approve.d.ts +4 -4
  162. package/dist/commands/ui/page.d.ts +19 -1
  163. package/dist/commands/ui/page.js +9 -6
  164. package/dist/commands/ui/places-change.d.ts +1 -1
  165. package/dist/commands/ui/plan-structure.d.ts +12 -2
  166. package/dist/commands/ui/plan-structure.en.d.ts +4 -0
  167. package/dist/commands/ui/plan-structure.en.js +4 -0
  168. package/dist/commands/ui/plan-structure.es.d.ts +4 -0
  169. package/dist/commands/ui/plan-structure.es.js +4 -0
  170. package/dist/commands/ui/plan-structure.js +48 -14
  171. package/dist/commands/ui/prototype-comp-route.d.ts +7 -0
  172. package/dist/commands/ui/prototype-comp-route.js +109 -0
  173. package/dist/commands/ui/prototype-main.d.ts +3 -1
  174. package/dist/commands/ui/prototype-scenes-child.js +6 -1
  175. package/dist/commands/ui/prototype-scenes-read.d.ts +1 -0
  176. package/dist/commands/ui/prototype-scenes-route.js +7 -1
  177. package/dist/commands/ui/prototype-snapshot-session.d.ts +1 -1
  178. package/dist/commands/ui/prototype-snapshot-session.js +3 -0
  179. package/dist/commands/ui/prototype-snapshot.d.ts +1 -1
  180. package/dist/commands/ui/routes.d.ts +6 -3
  181. package/dist/commands/ui/routes.js +3 -3
  182. package/dist/commands/ui/save-commit.js +6 -2
  183. package/dist/commands/ui/save-publish.js +3 -0
  184. package/dist/commands/ui/server-options.js +2 -0
  185. package/dist/commands/ui/server.d.ts +12 -22
  186. package/dist/commands/ui/server.js +10 -48
  187. package/dist/commands/ui/snapshot-runners.d.ts +22 -0
  188. package/dist/commands/ui/snapshot-runners.js +45 -0
  189. package/dist/commands/ui/structure-surface.d.ts +6 -0
  190. package/dist/commands/ui/structure-surface.js +94 -0
  191. package/dist/commands/ui/studio-routes.d.ts +1 -0
  192. package/dist/commands/ui/studio-routes.js +5 -0
  193. package/dist/commands/ui/studio-state.d.ts +9 -4
  194. package/dist/commands/ui/studio-state.js +1 -0
  195. package/dist/commands/ui/studio-versions.d.ts +3 -3
  196. package/dist/commands/ui/studio.en.d.ts +13 -0
  197. package/dist/commands/ui/studio.en.js +13 -0
  198. package/dist/commands/ui/studio.es.d.ts +13 -0
  199. package/dist/commands/ui/studio.es.js +13 -0
  200. package/dist/commands/ui/theme-option.d.ts +8 -0
  201. package/dist/commands/ui/theme-option.js +40 -0
  202. package/dist/commands/ui/theme-values.d.ts +5 -0
  203. package/dist/commands/ui/theme-values.js +113 -0
  204. package/dist/ui/page.js +94 -94
  205. package/docs/PROCESS.md +5 -0
  206. package/docs/PROTOTYPE.md +24 -1
  207. package/docs/WORKBENCH.md +76 -22
  208. package/package.json +11 -11
  209. package/skills/ape-critique/SKILL.md +16 -6
  210. package/skills/ape-design-system/SKILL.md +4 -3
  211. package/skills/ape-plan-change/SKILL.md +7 -3
  212. package/skills/ape-prototype/SKILL.md +12 -1
  213. package/templates/example/apps/app/src/i18n/en.ts +2 -0
  214. package/templates/example/apps/app/src/i18n/es.json +2 -0
  215. package/templates/product/apps/admin/src/fonts.ts +2 -1
  216. package/templates/product/apps/app/src/fonts.ts +5 -1
  217. package/templates/product/apps/app/src/i18n/en.ts +2 -0
  218. package/templates/product/apps/app/src/i18n/es.json +2 -0
  219. package/templates/product/prototype/journeys.ts +3 -0
@@ -1,5 +1,18 @@
1
1
  export declare const en: {
2
2
  'ui.title': string;
3
+ 'ui.theme.refused': string;
4
+ 'ui.theme.shape': string;
5
+ 'ui.theme.mode': string;
6
+ 'ui.theme.name': string;
7
+ 'ui.theme.color': string;
8
+ 'ui.theme.shadow': string;
9
+ 'ui.theme.tokens': string;
10
+ 'ui.theme.number': string;
11
+ 'ui.theme.easing': string;
12
+ 'ui.theme.font': string;
13
+ 'ui.theme.key': string;
14
+ 'ui.theme.label': string;
15
+ 'ui.theme.allow': string;
3
16
  'ui.request.invalid': string;
4
17
  'ui.outside.signIn': string;
5
18
  'ui.outside.timeout': string;
@@ -1,5 +1,18 @@
1
1
  export const en = {
2
2
  'ui.title': '{name} studio',
3
+ 'ui.theme.refused': 'The studio cannot start with this theme ({count} problems):',
4
+ 'ui.theme.shape': "theme: not a theme like studioTheme; make one with extendStudioTheme('{ key, label, color, … }')",
5
+ 'ui.theme.mode': "{mode}: not one of the studio's modes (light, dark, contrast)",
6
+ 'ui.theme.name': '{where}: {name} is not a token name (lowercase letters, digits and dashes)',
7
+ 'ui.theme.color': '{where}: {name} must be a #rrggbb, rgb() or rgba() color',
8
+ 'ui.theme.shadow': '{where}: {name} must be none, or shadows made of lengths, #colors, rgb() or rgba(), and inset',
9
+ 'ui.theme.tokens': '{where}: {name} must be a #rrggbb color, a length, a number or a shadow',
10
+ 'ui.theme.number': '{where}: {name} must be a number',
11
+ 'ui.theme.easing': 'easing: {name} must be four numbers',
12
+ 'ui.theme.font': 'font: {name} must list family names of letters, digits, spaces, dashes and underscores',
13
+ 'ui.theme.key': 'key: must be 1 to 64 letters, digits, dashes or underscores',
14
+ 'ui.theme.label': 'label: must be one line of text',
15
+ 'ui.theme.allow': "allow: a host's theme may set aside only the studio's own checks (control-edges, status-words)",
3
16
  'ui.request.invalid': 'Not a request the studio takes.',
4
17
  'ui.outside.signIn': 'Outside sources need host sign-in.',
5
18
  'ui.outside.timeout': 'The outside source time limit must be a whole number from 1 to 30,000 milliseconds.',
@@ -4,6 +4,19 @@ export declare const es: {
4
4
  'ui.outside.source': string;
5
5
  'ui.outside.unavailable': string;
6
6
  'ui.title': string;
7
+ 'ui.theme.refused': string;
8
+ 'ui.theme.shape': string;
9
+ 'ui.theme.mode': string;
10
+ 'ui.theme.name': string;
11
+ 'ui.theme.color': string;
12
+ 'ui.theme.shadow': string;
13
+ 'ui.theme.tokens': string;
14
+ 'ui.theme.number': string;
15
+ 'ui.theme.easing': string;
16
+ 'ui.theme.font': string;
17
+ 'ui.theme.key': string;
18
+ 'ui.theme.label': string;
19
+ 'ui.theme.allow': string;
7
20
  'ui.request.invalid': string;
8
21
  'ui.address.local': string;
9
22
  'ui.studio': string;
@@ -4,6 +4,19 @@ export const es = {
4
4
  'ui.outside.source': 'Una fuente externa necesita un nombre en texto sin formato de 1 a 40 caracteres y una función de lectura.',
5
5
  'ui.outside.unavailable': 'No hay fuentes externas disponibles.',
6
6
  'ui.title': 'Estudio de {name}',
7
+ 'ui.theme.refused': 'El estudio no puede iniciarse con este tema ({count} problemas):',
8
+ 'ui.theme.shape': "tema: no es un tema como studioTheme; créalo con extendStudioTheme('{ key, label, color, … }')",
9
+ 'ui.theme.mode': '{mode}: no es uno de los modos del estudio (light, dark, contrast)',
10
+ 'ui.theme.name': '{where}: {name} no es un nombre de token (minúsculas, dígitos y guiones)',
11
+ 'ui.theme.color': '{where}: {name} debe ser un color #rrggbb, rgb() o rgba()',
12
+ 'ui.theme.shadow': '{where}: {name} debe ser none, o sombras hechas de longitudes, #colores, rgb() o rgba(), e inset',
13
+ 'ui.theme.tokens': '{where}: {name} debe ser un color #rrggbb, una longitud, un número o una sombra',
14
+ 'ui.theme.number': '{where}: {name} debe ser un número',
15
+ 'ui.theme.easing': 'easing: {name} debe ser cuatro números',
16
+ 'ui.theme.font': 'font: {name} debe listar nombres de familia de letras, dígitos, espacios, guiones y guiones bajos',
17
+ 'ui.theme.key': 'key: debe tener de 1 a 64 letras, dígitos, guiones o guiones bajos',
18
+ 'ui.theme.label': 'label: debe ser una sola línea de texto',
19
+ 'ui.theme.allow': 'allow: el tema de un anfitrión solo puede apartar las comprobaciones propias del estudio (control-edges, status-words)',
7
20
  'ui.request.invalid': 'El estudio no admite esta solicitud.',
8
21
  'ui.address.local': 'Solo la dirección de este equipo abre el estudio.',
9
22
  'ui.studio': 'Abrir el estudio con datos reales (vista previa)',
@@ -0,0 +1,8 @@
1
+ import { type Theme } from '@buffcore/tokens';
2
+ /**
3
+ * Every value's shape (`themeValueProblems`), then `checkTheme`'s colors and contrast. What the
4
+ * checks cannot read is one problem; each problem is listed once.
5
+ */
6
+ export declare function themeProblems(theme: Theme): string[];
7
+ /** The theme as plain data for the page, or a refusal listing every problem. */
8
+ export declare function checkedTheme(theme: Theme | undefined): Theme | undefined;
@@ -0,0 +1,40 @@
1
+ // A host's theme for the studio (`createUiServer({ theme })`): the same `Theme` as `studioTheme`,
2
+ // checked at start. Every problem is listed at once; a theme with any is refused, never drawn.
3
+ import { checkTheme } from '@buffcore/tokens';
4
+ import { studioT } from './studio-messages.js';
5
+ import { themeValueProblems } from './theme-values.js';
6
+ /**
7
+ * Every value's shape (`themeValueProblems`), then `checkTheme`'s colors and contrast. What the
8
+ * checks cannot read is one problem; each problem is listed once.
9
+ */
10
+ export function themeProblems(theme) {
11
+ if (!theme || typeof theme !== 'object' || !theme.color || typeof theme.color !== 'object')
12
+ return [studioT('ui.theme.shape')];
13
+ const problems = [];
14
+ try {
15
+ JSON.stringify(theme);
16
+ problems.push(...themeValueProblems(theme));
17
+ }
18
+ catch {
19
+ return [studioT('ui.theme.shape')];
20
+ }
21
+ try {
22
+ problems.push(...checkTheme(theme));
23
+ }
24
+ catch {
25
+ problems.push(studioT('ui.theme.shape'));
26
+ }
27
+ return [...new Set(problems)];
28
+ }
29
+ /** The theme as plain data for the page, or a refusal listing every problem. */
30
+ export function checkedTheme(theme) {
31
+ if (theme === undefined)
32
+ return undefined;
33
+ const problems = themeProblems(theme);
34
+ if (problems.length)
35
+ throw new Error([
36
+ studioT('ui.theme.refused', { count: problems.length }),
37
+ ...problems.map((p) => `- ${p}`),
38
+ ].join('\n'));
39
+ return JSON.parse(JSON.stringify(theme));
40
+ }
@@ -0,0 +1,5 @@
1
+ import { type Theme } from '@buffcore/tokens';
2
+ /** `none`, or comma-separated shadows made of lengths, #colors, rgb()/rgba() and `inset`. */
3
+ export declare function isShadow(value: string): boolean;
4
+ /** Every value of a host's theme that `checkTheme` does not read, checked by kind. */
5
+ export declare function themeValueProblems(theme: Theme): string[];
@@ -0,0 +1,113 @@
1
+ // What a host's theme may hold, value by value, before any of it reaches the page's <style>.
2
+ // `checkTheme` checks a theme's colors and contrast; this checks the shape of every other value
3
+ // against a narrow grammar per kind, so host text can only ever be a token value, never CSS.
4
+ import { modes, numberTokens } from '@buffcore/tokens';
5
+ import { studioT } from './studio-messages.js';
6
+ /** The studio's own set-aside checks: the only ones a host's theme may carry. */
7
+ const STUDIO_ALLOWANCES = new Set(['control-edges', 'status-words']);
8
+ const MODES = new Set(modes);
9
+ const NAME = /^[a-z][a-z0-9-]*$/;
10
+ const COLOR = /^#[0-9a-fA-F]{6}$/;
11
+ const NUM = String.raw `(?:\d+|\d*\.\d+)`;
12
+ const LENGTH = new RegExp(`^-?${NUM}(?:px|em|rem|%)?$`);
13
+ const PART = String.raw `\s*${NUM}%?\s*`;
14
+ const RGB = new RegExp(String.raw `^rgba?\((?:${PART},${PART},${PART}(?:,${PART})?|\s*${NUM}%?\s+${NUM}%?\s+${NUM}%?\s*(?:/${PART})?)\)$`);
15
+ const SHADOW_TOKEN = /\s*(rgba?\([^()]*\)|#[0-9a-fA-F]{3,8}|inset|-?(?:\d+|\d*\.\d+)(?:px|em|rem)?|,)\s*/y;
16
+ const FAMILY = /^[\p{L}\p{N}][\p{L}\p{N} _-]{0,63}$/u;
17
+ const KEY = /^[A-Za-z0-9_-]{1,64}$/;
18
+ const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
19
+ const isNumber = (value) => typeof value === 'number' && Number.isFinite(value);
20
+ /** `none`, or comma-separated shadows made of lengths, #colors, rgb()/rgba() and `inset`. */
21
+ export function isShadow(value) {
22
+ if (value.trim() === 'none')
23
+ return true;
24
+ SHADOW_TOKEN.lastIndex = 0;
25
+ let segment = 0;
26
+ while (SHADOW_TOKEN.lastIndex < value.length) {
27
+ const match = SHADOW_TOKEN.exec(value);
28
+ if (!match)
29
+ return false;
30
+ const token = match[1];
31
+ if (token === ',') {
32
+ if (!segment)
33
+ return false;
34
+ segment = 0;
35
+ }
36
+ else if (token.startsWith('rgb') && !RGB.test(token))
37
+ return false;
38
+ else
39
+ segment++;
40
+ }
41
+ return segment > 0;
42
+ }
43
+ const isToken = (value) => COLOR.test(value) || LENGTH.test(value) || RGB.test(value) || isShadow(value);
44
+ /** Every value of a host's theme that `checkTheme` does not read, checked by kind. */
45
+ export function themeValueProblems(theme) {
46
+ const problems = [];
47
+ const name = (where, key) => {
48
+ if (NAME.test(key))
49
+ return true;
50
+ problems.push(studioT('ui.theme.name', { where, name: key.slice(0, 40) }));
51
+ return false;
52
+ };
53
+ const byMode = (group, ok) => {
54
+ const perMode = theme[group];
55
+ if (perMode === undefined && group === 'tokens')
56
+ return;
57
+ if (!isRecord(perMode))
58
+ return problems.push(studioT('ui.theme.shape'));
59
+ for (const [mode, values] of Object.entries(perMode)) {
60
+ if (!MODES.has(mode)) {
61
+ problems.push(studioT('ui.theme.mode', { mode: mode.slice(0, 40) }));
62
+ continue;
63
+ }
64
+ if (!isRecord(values))
65
+ continue;
66
+ for (const [key, value] of Object.entries(values))
67
+ if (name(mode, key) && !(typeof value === 'string' && ok(value)))
68
+ problems.push(studioT(`ui.theme.${group}`, { where: mode, name: key }));
69
+ }
70
+ };
71
+ if (typeof theme.key !== 'string' || !KEY.test(theme.key))
72
+ problems.push(studioT('ui.theme.key'));
73
+ if (typeof theme.label !== 'string' || !theme.label.trim() || /[\p{Cc}]/u.test(theme.label))
74
+ problems.push(studioT('ui.theme.label'));
75
+ byMode('color', (value) => COLOR.test(value) || RGB.test(value));
76
+ byMode('shadow', isShadow);
77
+ byMode('tokens', isToken);
78
+ for (const group of Object.keys(numberTokens)) {
79
+ const values = theme[group];
80
+ if (!isRecord(values)) {
81
+ problems.push(studioT('ui.theme.shape'));
82
+ continue;
83
+ }
84
+ for (const [key, value] of Object.entries(values))
85
+ if (name(group, key) && !isNumber(value))
86
+ problems.push(studioT('ui.theme.number', { where: group, name: key }));
87
+ }
88
+ if (!isRecord(theme.easing))
89
+ problems.push(studioT('ui.theme.shape'));
90
+ else
91
+ for (const [key, value] of Object.entries(theme.easing))
92
+ if (name('easing', key) &&
93
+ !(Array.isArray(value) && value.length === 4 && value.every(isNumber)))
94
+ problems.push(studioT('ui.theme.easing', { name: key }));
95
+ const font = theme.font;
96
+ if (!isRecord(font) || !isRecord(font.fallbacks))
97
+ problems.push(studioT('ui.theme.shape'));
98
+ else
99
+ for (const [key, faces] of [
100
+ ['display', font.display],
101
+ ['body', font.body],
102
+ ['mono', font.mono],
103
+ ...Object.entries(font.fallbacks).map(([script, face]) => [`fallbacks.${script}`, [face]]),
104
+ ])
105
+ if (!Array.isArray(faces) ||
106
+ !faces.length ||
107
+ !faces.every((f) => typeof f === 'string' && FAMILY.test(f)))
108
+ problems.push(studioT('ui.theme.font', { name: key }));
109
+ if (theme.allow !== undefined &&
110
+ !(Array.isArray(theme.allow) && theme.allow.every((a) => STUDIO_ALLOWANCES.has(a))))
111
+ problems.push(studioT('ui.theme.allow'));
112
+ return problems;
113
+ }