handoff-app-next 2.0.0-canary.1

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 (1578) hide show
  1. package/Changelog.md +2069 -0
  2. package/License.md +19 -0
  3. package/README.md +461 -0
  4. package/components.json +21 -0
  5. package/config/config.template.js +95 -0
  6. package/config/config.template.ts +54 -0
  7. package/config/docs/design.md +14 -0
  8. package/config/docs/foundations/border-radius.md +6 -0
  9. package/config/docs/foundations/colors.md +7 -0
  10. package/config/docs/foundations/effects.md +8 -0
  11. package/config/docs/foundations/elevation.md +6 -0
  12. package/config/docs/foundations/focus.md +6 -0
  13. package/config/docs/foundations/fonts.md +7 -0
  14. package/config/docs/foundations/grid.md +21 -0
  15. package/config/docs/foundations/icon.md +6 -0
  16. package/config/docs/foundations/icons.md +6 -0
  17. package/config/docs/foundations/logo.md +7 -0
  18. package/config/docs/foundations/logos.md +7 -0
  19. package/config/docs/foundations/motion.md +6 -0
  20. package/config/docs/foundations/spacing.md +7 -0
  21. package/config/docs/foundations/typography.md +8 -0
  22. package/config/docs/foundations.md +44 -0
  23. package/config/docs/guidelines.md +11 -0
  24. package/config/docs/index.md +9 -0
  25. package/config/docs/playground.md +14 -0
  26. package/config/docs/system/figma-sync.md +14 -0
  27. package/config/docs/system/tokens/foundations/colors.md +24 -0
  28. package/config/docs/system/tokens/foundations/effects.md +21 -0
  29. package/config/docs/system/tokens/foundations/spacing.md +22 -0
  30. package/config/docs/system/tokens/foundations/typography.md +24 -0
  31. package/config/docs/system.md +13 -0
  32. package/config/templates/component/template.hbs +6 -0
  33. package/config/templates/component/template.js +0 -0
  34. package/config/templates/component/template.json +45 -0
  35. package/config/templates/component/template.scss +2 -0
  36. package/config/templates/page.md +11 -0
  37. package/config/templates/page.mdx +49 -0
  38. package/config/templates/template.html +7 -0
  39. package/dist/app/components/Component/Cards.d.ts +25 -0
  40. package/dist/app/components/Component/Cards.jsx +27 -0
  41. package/dist/app/lib/adapter-kit/types.d.ts +581 -0
  42. package/dist/app/lib/adapter-kit/types.js +36 -0
  43. package/dist/app/lib/hubspot-field-map.d.ts +170 -0
  44. package/dist/app/lib/hubspot-field-map.js +538 -0
  45. package/dist/app/lib/hubspot-module/build-module.d.ts +136 -0
  46. package/dist/app/lib/hubspot-module/build-module.js +122 -0
  47. package/dist/app/lib/hubspot-module/context.d.ts +111 -0
  48. package/dist/app/lib/hubspot-module/context.js +228 -0
  49. package/dist/app/lib/hubspot-module/fields/boolean.d.ts +8 -0
  50. package/dist/app/lib/hubspot-module/fields/boolean.js +22 -0
  51. package/dist/app/lib/hubspot-module/fields/button.d.ts +19 -0
  52. package/dist/app/lib/hubspot-module/fields/button.js +66 -0
  53. package/dist/app/lib/hubspot-module/fields/fields.d.ts +20 -0
  54. package/dist/app/lib/hubspot-module/fields/fields.js +93 -0
  55. package/dist/app/lib/hubspot-module/fields/generic.d.ts +33 -0
  56. package/dist/app/lib/hubspot-module/fields/generic.js +150 -0
  57. package/dist/app/lib/hubspot-module/fields/hubdb.d.ts +14 -0
  58. package/dist/app/lib/hubspot-module/fields/hubdb.js +155 -0
  59. package/dist/app/lib/hubspot-module/fields/image.d.ts +27 -0
  60. package/dist/app/lib/hubspot-module/fields/image.js +59 -0
  61. package/dist/app/lib/hubspot-module/fields/menu.d.ts +8 -0
  62. package/dist/app/lib/hubspot-module/fields/menu.js +12 -0
  63. package/dist/app/lib/hubspot-module/fields/object.d.ts +11 -0
  64. package/dist/app/lib/hubspot-module/fields/object.js +31 -0
  65. package/dist/app/lib/hubspot-module/fields/select.d.ts +17 -0
  66. package/dist/app/lib/hubspot-module/fields/select.js +37 -0
  67. package/dist/app/lib/hubspot-module/fields/text.d.ts +15 -0
  68. package/dist/app/lib/hubspot-module/fields/text.js +63 -0
  69. package/dist/app/lib/hubspot-module/fields/url.d.ts +35 -0
  70. package/dist/app/lib/hubspot-module/fields/url.js +57 -0
  71. package/dist/app/lib/hubspot-module/fields/utils.d.ts +20 -0
  72. package/dist/app/lib/hubspot-module/fields/utils.js +33 -0
  73. package/dist/app/lib/hubspot-module/fields/video.d.ts +21 -0
  74. package/dist/app/lib/hubspot-module/fields/video.js +70 -0
  75. package/dist/app/lib/hubspot-module/index.d.ts +20 -0
  76. package/dist/app/lib/hubspot-module/index.js +17 -0
  77. package/dist/app/lib/hubspot-module/transpile.d.ts +27 -0
  78. package/dist/app/lib/hubspot-module/transpile.js +658 -0
  79. package/dist/app/lib/hubspot-module/types.d.ts +204 -0
  80. package/dist/app/lib/hubspot-module/types.js +47 -0
  81. package/dist/app/lib/hubspot-module-build.d.ts +33 -0
  82. package/dist/app/lib/hubspot-module-build.js +41 -0
  83. package/dist/app-builder/build.d.ts +21 -0
  84. package/dist/app-builder/build.js +649 -0
  85. package/dist/app-builder/client-config.d.ts +17 -0
  86. package/dist/app-builder/client-config.js +106 -0
  87. package/dist/app-builder/config-diff/index.d.ts +4 -0
  88. package/dist/app-builder/config-diff/index.js +3 -0
  89. package/dist/app-builder/config-diff/registry.d.ts +9 -0
  90. package/dist/app-builder/config-diff/registry.js +15 -0
  91. package/dist/app-builder/config-diff/snapshot.d.ts +13 -0
  92. package/dist/app-builder/config-diff/snapshot.js +38 -0
  93. package/dist/app-builder/config-diff/strategies/pattern.d.ts +2 -0
  94. package/dist/app-builder/config-diff/strategies/pattern.js +66 -0
  95. package/dist/app-builder/config-diff/types.d.ts +33 -0
  96. package/dist/app-builder/config-diff/types.js +1 -0
  97. package/dist/app-builder/index.d.ts +6 -0
  98. package/dist/app-builder/index.js +4 -0
  99. package/dist/app-builder/path-contract.d.ts +23 -0
  100. package/dist/app-builder/path-contract.js +60 -0
  101. package/dist/app-builder/paths.d.ts +24 -0
  102. package/dist/app-builder/paths.js +82 -0
  103. package/dist/app-builder/watchers/component.d.ts +15 -0
  104. package/dist/app-builder/watchers/component.js +58 -0
  105. package/dist/app-builder/watchers/utils.d.ts +14 -0
  106. package/dist/app-builder/watchers/utils.js +31 -0
  107. package/dist/app-builder/watchers.d.ts +44 -0
  108. package/dist/app-builder/watchers.js +299 -0
  109. package/dist/app-builder/websocket.d.ts +12 -0
  110. package/dist/app-builder/websocket.js +56 -0
  111. package/dist/cache/build-cache.d.ts +169 -0
  112. package/dist/cache/build-cache.js +421 -0
  113. package/dist/cache/file-state.d.ts +58 -0
  114. package/dist/cache/file-state.js +122 -0
  115. package/dist/cache/index.d.ts +3 -0
  116. package/dist/cache/index.js +6 -0
  117. package/dist/cache/push-state.d.ts +69 -0
  118. package/dist/cache/push-state.js +156 -0
  119. package/dist/cli/create.d.ts +5 -0
  120. package/dist/cli/create.js +301 -0
  121. package/dist/cli/eject.d.ts +17 -0
  122. package/dist/cli/eject.js +82 -0
  123. package/dist/cli/fetch-design-md.d.ts +14 -0
  124. package/dist/cli/fetch-design-md.js +62 -0
  125. package/dist/cli/figma-audit.d.ts +7 -0
  126. package/dist/cli/figma-audit.js +55 -0
  127. package/dist/cli/init-claude-core.d.ts +26 -0
  128. package/dist/cli/init-claude-core.js +81 -0
  129. package/dist/cli/make.d.ts +12 -0
  130. package/dist/cli/make.js +178 -0
  131. package/dist/cli/scaffold.d.ts +5 -0
  132. package/dist/cli/scaffold.js +504 -0
  133. package/dist/cli/sync/apply-declaration-pull.d.ts +14 -0
  134. package/dist/cli/sync/apply-declaration-pull.js +184 -0
  135. package/dist/cli/sync/apply-pull.d.ts +24 -0
  136. package/dist/cli/sync/apply-pull.js +174 -0
  137. package/dist/cli/sync/cli-auth-store.d.ts +12 -0
  138. package/dist/cli/sync/cli-auth-store.js +44 -0
  139. package/dist/cli/sync/collect-build-artifacts.d.ts +17 -0
  140. package/dist/cli/sync/collect-build-artifacts.js +143 -0
  141. package/dist/cli/sync/collect-referenced-images.d.ts +36 -0
  142. package/dist/cli/sync/collect-referenced-images.js +165 -0
  143. package/dist/cli/sync/declaration-patch.d.ts +9 -0
  144. package/dist/cli/sync/declaration-patch.js +196 -0
  145. package/dist/cli/sync/hash.d.ts +2 -0
  146. package/dist/cli/sync/hash.js +11 -0
  147. package/dist/cli/sync/open-browser.d.ts +5 -0
  148. package/dist/cli/sync/open-browser.js +37 -0
  149. package/dist/cli/sync/push-provenance.d.ts +25 -0
  150. package/dist/cli/sync/push-provenance.js +82 -0
  151. package/dist/cli/sync/push-registry-content.d.ts +132 -0
  152. package/dist/cli/sync/push-registry-content.js +854 -0
  153. package/dist/cli/sync/push-shared-assets.d.ts +26 -0
  154. package/dist/cli/sync/push-shared-assets.js +33 -0
  155. package/dist/cli/sync/resolve-declaration-payload.d.ts +8 -0
  156. package/dist/cli/sync/resolve-declaration-payload.js +208 -0
  157. package/dist/cli/sync/resolve-declaration.d.ts +5 -0
  158. package/dist/cli/sync/resolve-declaration.js +12 -0
  159. package/dist/cli/sync/run-cli-login.d.ts +9 -0
  160. package/dist/cli/sync/run-cli-login.js +81 -0
  161. package/dist/cli/sync/run-history-purge.d.ts +19 -0
  162. package/dist/cli/sync/run-history-purge.js +112 -0
  163. package/dist/cli/sync/run-pull.d.ts +9 -0
  164. package/dist/cli/sync/run-pull.js +92 -0
  165. package/dist/cli/sync/run-push.d.ts +47 -0
  166. package/dist/cli/sync/run-push.js +585 -0
  167. package/dist/cli/sync/run-sync-status.d.ts +2 -0
  168. package/dist/cli/sync/run-sync-status.js +30 -0
  169. package/dist/cli/sync/sync-remote-env.d.ts +14 -0
  170. package/dist/cli/sync/sync-remote-env.js +52 -0
  171. package/dist/cli/sync/sync-state.d.ts +15 -0
  172. package/dist/cli/sync/sync-state.js +26 -0
  173. package/dist/cli/tokens/ensure-default-brand.d.ts +18 -0
  174. package/dist/cli/tokens/ensure-default-brand.js +95 -0
  175. package/dist/cli/tokens/migrate-legacy.d.ts +23 -0
  176. package/dist/cli/tokens/migrate-legacy.js +213 -0
  177. package/dist/cli/tokens/parse-css-brands.d.ts +25 -0
  178. package/dist/cli/tokens/parse-css-brands.js +148 -0
  179. package/dist/cli/tokens/transform.d.ts +12 -0
  180. package/dist/cli/tokens/transform.js +126 -0
  181. package/dist/cli.d.ts +2 -0
  182. package/dist/cli.js +56 -0
  183. package/dist/commands/audit/figma-components.d.ts +8 -0
  184. package/dist/commands/audit/figma-components.js +27 -0
  185. package/dist/commands/build/app.d.ts +8 -0
  186. package/dist/commands/build/app.js +22 -0
  187. package/dist/commands/build/components.d.ts +7 -0
  188. package/dist/commands/build/components.js +17 -0
  189. package/dist/commands/build/hubspot.d.ts +56 -0
  190. package/dist/commands/build/hubspot.js +177 -0
  191. package/dist/commands/dev/index.d.ts +6 -0
  192. package/dist/commands/dev/index.js +14 -0
  193. package/dist/commands/eject/config.d.ts +6 -0
  194. package/dist/commands/eject/config.js +14 -0
  195. package/dist/commands/eject/pages.d.ts +6 -0
  196. package/dist/commands/eject/pages.js +14 -0
  197. package/dist/commands/eject/theme.d.ts +6 -0
  198. package/dist/commands/eject/theme.js +14 -0
  199. package/dist/commands/fetch/index.d.ts +6 -0
  200. package/dist/commands/fetch/index.js +14 -0
  201. package/dist/commands/history-purge.d.ts +19 -0
  202. package/dist/commands/history-purge.js +52 -0
  203. package/dist/commands/index.d.ts +1 -0
  204. package/dist/commands/index.js +66 -0
  205. package/dist/commands/init/index.d.ts +5 -0
  206. package/dist/commands/init/index.js +12 -0
  207. package/dist/commands/init/vercel.d.ts +6 -0
  208. package/dist/commands/init/vercel.js +99 -0
  209. package/dist/commands/init-claude.d.ts +9 -0
  210. package/dist/commands/init-claude.js +47 -0
  211. package/dist/commands/login.d.ts +9 -0
  212. package/dist/commands/login.js +28 -0
  213. package/dist/commands/logout.d.ts +6 -0
  214. package/dist/commands/logout.js +16 -0
  215. package/dist/commands/make/component.d.ts +7 -0
  216. package/dist/commands/make/component.js +23 -0
  217. package/dist/commands/make/page.d.ts +8 -0
  218. package/dist/commands/make/page.js +33 -0
  219. package/dist/commands/make/template.d.ts +8 -0
  220. package/dist/commands/make/template.js +33 -0
  221. package/dist/commands/mcp-init.d.ts +12 -0
  222. package/dist/commands/mcp-init.js +94 -0
  223. package/dist/commands/mcp-token.d.ts +7 -0
  224. package/dist/commands/mcp-token.js +23 -0
  225. package/dist/commands/prepare-runtime.d.ts +7 -0
  226. package/dist/commands/prepare-runtime.js +28 -0
  227. package/dist/commands/pull.d.ts +7 -0
  228. package/dist/commands/pull.js +18 -0
  229. package/dist/commands/push-all.d.ts +23 -0
  230. package/dist/commands/push-all.js +146 -0
  231. package/dist/commands/push-assets.d.ts +8 -0
  232. package/dist/commands/push-assets.js +40 -0
  233. package/dist/commands/push-tokens.d.ts +8 -0
  234. package/dist/commands/push-tokens.js +40 -0
  235. package/dist/commands/push.d.ts +14 -0
  236. package/dist/commands/push.js +75 -0
  237. package/dist/commands/scaffold/index.d.ts +6 -0
  238. package/dist/commands/scaffold/index.js +15 -0
  239. package/dist/commands/start/index.d.ts +6 -0
  240. package/dist/commands/start/index.js +14 -0
  241. package/dist/commands/sync-status.d.ts +6 -0
  242. package/dist/commands/sync-status.js +14 -0
  243. package/dist/commands/tokens-build.d.ts +7 -0
  244. package/dist/commands/tokens-build.js +104 -0
  245. package/dist/commands/types.d.ts +5 -0
  246. package/dist/commands/types.js +1 -0
  247. package/dist/commands/utils.d.ts +18 -0
  248. package/dist/commands/utils.js +19 -0
  249. package/dist/commands/validate/components.d.ts +7 -0
  250. package/dist/commands/validate/components.js +19 -0
  251. package/dist/commands/validate.d.ts +11 -0
  252. package/dist/commands/validate.js +163 -0
  253. package/dist/commands/vercel-build.d.ts +7 -0
  254. package/dist/commands/vercel-build.js +81 -0
  255. package/dist/config/declaration-module-load.d.ts +6 -0
  256. package/dist/config/declaration-module-load.js +68 -0
  257. package/dist/config/defaults.d.ts +16 -0
  258. package/dist/config/defaults.js +60 -0
  259. package/dist/config/helpers.d.ts +7 -0
  260. package/dist/config/helpers.js +29 -0
  261. package/dist/config/index.d.ts +7 -0
  262. package/dist/config/index.js +11 -0
  263. package/dist/config/loader.d.ts +20 -0
  264. package/dist/config/loader.js +107 -0
  265. package/dist/config/normalizers/declaration.d.ts +11 -0
  266. package/dist/config/normalizers/declaration.js +122 -0
  267. package/dist/config/normalizers/pattern.d.ts +8 -0
  268. package/dist/config/normalizers/pattern.js +31 -0
  269. package/dist/config/runtime.d.ts +42 -0
  270. package/dist/config/runtime.js +337 -0
  271. package/dist/config/validator.d.ts +9 -0
  272. package/dist/config/validator.js +22 -0
  273. package/dist/declarations/codegen.d.ts +57 -0
  274. package/dist/declarations/codegen.js +279 -0
  275. package/dist/declarations/helpers.d.ts +6 -0
  276. package/dist/declarations/helpers.js +20 -0
  277. package/dist/declarations/index.d.ts +2 -0
  278. package/dist/declarations/index.js +1 -0
  279. package/dist/declarations/types.d.ts +193 -0
  280. package/dist/declarations/types.js +1 -0
  281. package/dist/figma/component-linking.d.ts +164 -0
  282. package/dist/figma/component-linking.js +1080 -0
  283. package/dist/figma/image-fills.d.ts +32 -0
  284. package/dist/figma/image-fills.js +211 -0
  285. package/dist/generated/build-meta.d.ts +4 -0
  286. package/dist/generated/build-meta.js +6 -0
  287. package/dist/index.d.ts +115 -0
  288. package/dist/index.js +301 -0
  289. package/dist/pipeline/archive.d.ts +19 -0
  290. package/dist/pipeline/archive.js +62 -0
  291. package/dist/pipeline/components.d.ts +5 -0
  292. package/dist/pipeline/components.js +7 -0
  293. package/dist/pipeline/documentation.d.ts +3 -0
  294. package/dist/pipeline/documentation.js +64 -0
  295. package/dist/pipeline/figma.d.ts +11 -0
  296. package/dist/pipeline/figma.js +142 -0
  297. package/dist/pipeline/hubspot/config.d.ts +179 -0
  298. package/dist/pipeline/hubspot/config.js +171 -0
  299. package/dist/pipeline/hubspot/emit.d.ts +101 -0
  300. package/dist/pipeline/hubspot/emit.js +283 -0
  301. package/dist/pipeline/index.d.ts +14 -0
  302. package/dist/pipeline/index.js +34 -0
  303. package/dist/pipeline/patterns.d.ts +8 -0
  304. package/dist/pipeline/patterns.js +8 -0
  305. package/dist/pipeline/styles.d.ts +10 -0
  306. package/dist/pipeline/styles.js +127 -0
  307. package/dist/pipeline/validation.d.ts +6 -0
  308. package/dist/pipeline/validation.js +23 -0
  309. package/dist/transformers/docgen/index.d.ts +24 -0
  310. package/dist/transformers/docgen/index.js +244 -0
  311. package/dist/transformers/plugins/csf-render.d.ts +5 -0
  312. package/dist/transformers/plugins/csf-render.js +406 -0
  313. package/dist/transformers/plugins/handlebars-previews.d.ts +12 -0
  314. package/dist/transformers/plugins/handlebars-previews.js +128 -0
  315. package/dist/transformers/plugins/index.d.ts +11 -0
  316. package/dist/transformers/plugins/index.js +10 -0
  317. package/dist/transformers/plugins/slot-probe-candidates.d.ts +159 -0
  318. package/dist/transformers/plugins/slot-probe-candidates.js +279 -0
  319. package/dist/transformers/plugins/slot-probe.d.ts +66 -0
  320. package/dist/transformers/plugins/slot-probe.js +298 -0
  321. package/dist/transformers/plugins/ssr-render.d.ts +33 -0
  322. package/dist/transformers/plugins/ssr-render.js +531 -0
  323. package/dist/transformers/plugins.d.ts +14 -0
  324. package/dist/transformers/plugins.js +15 -0
  325. package/dist/transformers/preview/component/api.d.ts +22 -0
  326. package/dist/transformers/preview/component/api.js +146 -0
  327. package/dist/transformers/preview/component/artifacts.d.ts +3 -0
  328. package/dist/transformers/preview/component/artifacts.js +103 -0
  329. package/dist/transformers/preview/component/build-shared-bundles.d.ts +83 -0
  330. package/dist/transformers/preview/component/build-shared-bundles.js +400 -0
  331. package/dist/transformers/preview/component/builder.d.ts +29 -0
  332. package/dist/transformers/preview/component/builder.js +638 -0
  333. package/dist/transformers/preview/component/css.d.ts +68 -0
  334. package/dist/transformers/preview/component/css.js +219 -0
  335. package/dist/transformers/preview/component/field-annotations.d.ts +129 -0
  336. package/dist/transformers/preview/component/field-annotations.js +325 -0
  337. package/dist/transformers/preview/component/html.d.ts +21 -0
  338. package/dist/transformers/preview/component/html.js +80 -0
  339. package/dist/transformers/preview/component/javascript.d.ts +24 -0
  340. package/dist/transformers/preview/component/javascript.js +162 -0
  341. package/dist/transformers/preview/component/normalizer.d.ts +35 -0
  342. package/dist/transformers/preview/component/normalizer.js +56 -0
  343. package/dist/transformers/preview/component/playwright-shared.d.ts +70 -0
  344. package/dist/transformers/preview/component/playwright-shared.js +164 -0
  345. package/dist/transformers/preview/component/preview-assets.d.ts +55 -0
  346. package/dist/transformers/preview/component/preview-assets.js +144 -0
  347. package/dist/transformers/preview/component/preview-merge.d.ts +53 -0
  348. package/dist/transformers/preview/component/preview-merge.js +50 -0
  349. package/dist/transformers/preview/component/preview-select.d.ts +86 -0
  350. package/dist/transformers/preview/component/preview-select.js +150 -0
  351. package/dist/transformers/preview/component/preview-server.d.ts +41 -0
  352. package/dist/transformers/preview/component/preview-server.js +112 -0
  353. package/dist/transformers/preview/component/preview-validation.d.ts +64 -0
  354. package/dist/transformers/preview/component/preview-validation.js +194 -0
  355. package/dist/transformers/preview/component/previews.d.ts +9 -0
  356. package/dist/transformers/preview/component/previews.js +6 -0
  357. package/dist/transformers/preview/component/screenshot.d.ts +90 -0
  358. package/dist/transformers/preview/component/screenshot.js +282 -0
  359. package/dist/transformers/preview/component/serialized-elements.d.ts +86 -0
  360. package/dist/transformers/preview/component/serialized-elements.js +118 -0
  361. package/dist/transformers/preview/component/summary.d.ts +6 -0
  362. package/dist/transformers/preview/component/summary.js +41 -0
  363. package/dist/transformers/preview/component.d.ts +13 -0
  364. package/dist/transformers/preview/component.js +26 -0
  365. package/dist/transformers/preview/height-reporter.d.ts +27 -0
  366. package/dist/transformers/preview/height-reporter.js +32 -0
  367. package/dist/transformers/preview/pattern/api.d.ts +11 -0
  368. package/dist/transformers/preview/pattern/api.js +58 -0
  369. package/dist/transformers/preview/pattern/builder.d.ts +17 -0
  370. package/dist/transformers/preview/pattern/builder.js +149 -0
  371. package/dist/transformers/preview/pattern/html.d.ts +25 -0
  372. package/dist/transformers/preview/pattern/html.js +95 -0
  373. package/dist/transformers/preview/slots.d.ts +109 -0
  374. package/dist/transformers/preview/slots.js +13 -0
  375. package/dist/transformers/preview/types.d.ts +292 -0
  376. package/dist/transformers/preview/types.js +7 -0
  377. package/dist/transformers/types.d.ts +60 -0
  378. package/dist/transformers/types.js +1 -0
  379. package/dist/transformers/utils/build.d.ts +27 -0
  380. package/dist/transformers/utils/build.js +77 -0
  381. package/dist/transformers/utils/csf.d.ts +16 -0
  382. package/dist/transformers/utils/csf.js +29 -0
  383. package/dist/transformers/utils/handlebars.d.ts +32 -0
  384. package/dist/transformers/utils/handlebars.js +73 -0
  385. package/dist/transformers/utils/html.d.ts +18 -0
  386. package/dist/transformers/utils/html.js +40 -0
  387. package/dist/transformers/utils/index.d.ts +13 -0
  388. package/dist/transformers/utils/index.js +20 -0
  389. package/dist/transformers/utils/module.d.ts +13 -0
  390. package/dist/transformers/utils/module.js +41 -0
  391. package/dist/transformers/utils/schema-loader.d.ts +19 -0
  392. package/dist/transformers/utils/schema-loader.js +61 -0
  393. package/dist/transformers/utils/schema.d.ts +33 -0
  394. package/dist/transformers/utils/schema.js +517 -0
  395. package/dist/transformers/utils/string.d.ts +36 -0
  396. package/dist/transformers/utils/string.js +52 -0
  397. package/dist/transformers/utils/svg-sprite.d.ts +16 -0
  398. package/dist/transformers/utils/svg-sprite.js +114 -0
  399. package/dist/transformers/utils/usage.d.ts +23 -0
  400. package/dist/transformers/utils/usage.js +282 -0
  401. package/dist/transformers/utils/vite-logger.d.ts +2 -0
  402. package/dist/transformers/utils/vite-logger.js +30 -0
  403. package/dist/transformers/validation/runner.d.ts +67 -0
  404. package/dist/transformers/validation/runner.js +277 -0
  405. package/dist/transformers/vite-config.d.ts +3 -0
  406. package/dist/transformers/vite-config.js +18 -0
  407. package/dist/tsconfig.tsbuildinfo +1 -0
  408. package/dist/types/config.d.ts +472 -0
  409. package/dist/types/config.js +1 -0
  410. package/dist/types/font.d.ts +3 -0
  411. package/dist/types/font.js +1 -0
  412. package/dist/types/handoff-sync.d.ts +132 -0
  413. package/dist/types/handoff-sync.js +5 -0
  414. package/dist/types/history-purge.d.ts +112 -0
  415. package/dist/types/history-purge.js +18 -0
  416. package/dist/types/icon.d.ts +8 -0
  417. package/dist/types/icon.js +1 -0
  418. package/dist/types/preview.d.ts +138 -0
  419. package/dist/types/preview.js +1 -0
  420. package/dist/types/validation.d.ts +200 -0
  421. package/dist/types/validation.js +11 -0
  422. package/dist/utils/asset-upload-limits.d.ts +87 -0
  423. package/dist/utils/asset-upload-limits.js +129 -0
  424. package/dist/utils/design-md.d.ts +55 -0
  425. package/dist/utils/design-md.js +107 -0
  426. package/dist/utils/duration.d.ts +2 -0
  427. package/dist/utils/duration.js +2 -0
  428. package/dist/utils/filter.d.ts +31 -0
  429. package/dist/utils/filter.js +109 -0
  430. package/dist/utils/fs.d.ts +8 -0
  431. package/dist/utils/fs.js +31 -0
  432. package/dist/utils/index.d.ts +6 -0
  433. package/dist/utils/index.js +6 -0
  434. package/dist/utils/line-diff.d.ts +25 -0
  435. package/dist/utils/line-diff.js +74 -0
  436. package/dist/utils/logger.d.ts +50 -0
  437. package/dist/utils/logger.js +158 -0
  438. package/dist/utils/path.d.ts +21 -0
  439. package/dist/utils/path.js +50 -0
  440. package/dist/utils/port.d.ts +15 -0
  441. package/dist/utils/port.js +38 -0
  442. package/dist/utils/rich-text.d.ts +228 -0
  443. package/dist/utils/rich-text.js +1087 -0
  444. package/dist/validators/axe.d.ts +47 -0
  445. package/dist/validators/axe.js +222 -0
  446. package/dist/validators/contrast.d.ts +33 -0
  447. package/dist/validators/contrast.js +235 -0
  448. package/dist/validators/index.d.ts +30 -0
  449. package/dist/validators/index.js +26 -0
  450. package/dist/validators/schema.d.ts +34 -0
  451. package/dist/validators/schema.js +138 -0
  452. package/docs/DEPENDENCIES.md +26 -0
  453. package/docs/DEPLOYMENT.md +110 -0
  454. package/docs/LOCAL-RIG.md +305 -0
  455. package/docs/README.md +15 -0
  456. package/docs/REGISTRY-SETUP.md +353 -0
  457. package/docs/STANDALONE-INSTALL.md +70 -0
  458. package/docs/WORKSPACE-PACKAGE-JSON.md +125 -0
  459. package/docs/api.md +657 -0
  460. package/docs/api_spec.yaml +450 -0
  461. package/docs/cli.md +86 -0
  462. package/docs/schemas/component.schema.json +167 -0
  463. package/docs/schemas/examples/button.json +83 -0
  464. package/drizzle.config.ts +10 -0
  465. package/package.json +271 -0
  466. package/postcss.config.mjs +8 -0
  467. package/scripts/assert-standalone-install.mjs +60 -0
  468. package/src/app/app/[...slug]/DocCatchAllClient.tsx +103 -0
  469. package/src/app/app/[...slug]/page.tsx +101 -0
  470. package/src/app/app/account/AccountClient.tsx +116 -0
  471. package/src/app/app/account/IntegrationsSection.tsx +273 -0
  472. package/src/app/app/account/SanityCard.tsx +473 -0
  473. package/src/app/app/account/ai-cost/page.tsx +141 -0
  474. package/src/app/app/account/appearance/AppearanceClient.tsx +433 -0
  475. package/src/app/app/account/appearance/page.tsx +52 -0
  476. package/src/app/app/account/integrations/page.tsx +37 -0
  477. package/src/app/app/account/layout.tsx +82 -0
  478. package/src/app/app/account/page.tsx +41 -0
  479. package/src/app/app/account/users/UsersClient.tsx +244 -0
  480. package/src/app/app/account/users/page.tsx +36 -0
  481. package/src/app/app/actions/ai-generate.ts +25 -0
  482. package/src/app/app/actions/components.ts +126 -0
  483. package/src/app/app/actions/patterns.ts +289 -0
  484. package/src/app/app/admin/ai-cost/AiCostClient.tsx +236 -0
  485. package/src/app/app/admin/ai-cost/page.tsx +56 -0
  486. package/src/app/app/admin/builds/BuildsClient.tsx +527 -0
  487. package/src/app/app/admin/builds/page.tsx +41 -0
  488. package/src/app/app/admin/integrations/page.tsx +32 -0
  489. package/src/app/app/admin/pages/PagesClient.tsx +282 -0
  490. package/src/app/app/admin/pages/edit/PageEditorClient.tsx +157 -0
  491. package/src/app/app/admin/pages/edit/page.tsx +48 -0
  492. package/src/app/app/admin/pages/page.tsx +31 -0
  493. package/src/app/app/admin/protection/ProtectionClient.tsx +235 -0
  494. package/src/app/app/admin/protection/page.tsx +33 -0
  495. package/src/app/app/admin/reference/ReferenceClient.tsx +150 -0
  496. package/src/app/app/admin/reference/page.tsx +38 -0
  497. package/src/app/app/admin/users/page.tsx +11 -0
  498. package/src/app/app/api/account/route.ts +36 -0
  499. package/src/app/app/api/admin/builds/status/route.ts +34 -0
  500. package/src/app/app/api/admin/cleanup-versions/route.ts +64 -0
  501. package/src/app/app/api/admin/contract-limit-audit/route.ts +126 -0
  502. package/src/app/app/api/admin/contract-render-audit/route.ts +116 -0
  503. package/src/app/app/api/admin/field-bridge-audit/route.ts +152 -0
  504. package/src/app/app/api/admin/migrate/route.ts +47 -0
  505. package/src/app/app/api/admin/playground-turns/route.ts +85 -0
  506. package/src/app/app/api/admin/purge-history/route.ts +119 -0
  507. package/src/app/app/api/auth/[...nextauth]/route.ts +30 -0
  508. package/src/app/app/api/component/[...path]/route.ts +141 -0
  509. package/src/app/app/api/component-artifact/[...path]/route.ts +18 -0
  510. package/src/app/app/api/components/route.ts +78 -0
  511. package/src/app/app/api/figma-plugin/auth/device/route.ts +40 -0
  512. package/src/app/app/api/figma-plugin/auth/revoke/route.ts +15 -0
  513. package/src/app/app/api/figma-plugin/auth/token/route.ts +50 -0
  514. package/src/app/app/api/figma-plugin/foundations/commit/route.ts +111 -0
  515. package/src/app/app/api/figma-plugin/foundations/preview/route.ts +69 -0
  516. package/src/app/app/api/figma-plugin/foundations/route.ts +49 -0
  517. package/src/app/app/api/handoff/admin/appearance/route.ts +80 -0
  518. package/src/app/app/api/handoff/admin/backfill-artifact-blobs/route.ts +48 -0
  519. package/src/app/app/api/handoff/admin/build-tasks/kill/route.ts +43 -0
  520. package/src/app/app/api/handoff/admin/build-tasks/route.ts +21 -0
  521. package/src/app/app/api/handoff/admin/invite/route.ts +18 -0
  522. package/src/app/app/api/handoff/admin/normalize-previews/route.ts +107 -0
  523. package/src/app/app/api/handoff/admin/reference-materials/route.ts +69 -0
  524. package/src/app/app/api/handoff/admin/remove/route.ts +18 -0
  525. package/src/app/app/api/handoff/admin/resend-invite/route.ts +18 -0
  526. package/src/app/app/api/handoff/admin/role/route.ts +18 -0
  527. package/src/app/app/api/handoff/admin/users/route.ts +16 -0
  528. package/src/app/app/api/handoff/ai/analyze-layout-guide/route.ts +172 -0
  529. package/src/app/app/api/handoff/ai/analyze-layout-guide/wireframe-style/wireframe-example-1.png +0 -0
  530. package/src/app/app/api/handoff/ai/analyze-layout-guide/wireframe-style/wireframe-example-2.png +0 -0
  531. package/src/app/app/api/handoff/ai/chat/route.ts +217 -0
  532. package/src/app/app/api/handoff/ai/component-screenshot/route.ts +43 -0
  533. package/src/app/app/api/handoff/ai/debug-foundation-raster/route.ts +162 -0
  534. package/src/app/app/api/handoff/ai/design-artifact/[id]/clone/route.ts +68 -0
  535. package/src/app/app/api/handoff/ai/design-artifact/[id]/public/route.ts +37 -0
  536. package/src/app/app/api/handoff/ai/design-artifact/[id]/route.ts +99 -0
  537. package/src/app/app/api/handoff/ai/design-artifact/[id]/status/route.ts +44 -0
  538. package/src/app/app/api/handoff/ai/design-artifact/route.ts +405 -0
  539. package/src/app/app/api/handoff/ai/design-artifact-extract/route.ts +37 -0
  540. package/src/app/app/api/handoff/ai/design-generation-job/[id]/route.ts +67 -0
  541. package/src/app/app/api/handoff/ai/design-generation-jobs/route.ts +23 -0
  542. package/src/app/app/api/handoff/ai/design-jobs/run/route.ts +102 -0
  543. package/src/app/app/api/handoff/ai/extract-url/route.ts +34 -0
  544. package/src/app/app/api/handoff/ai/foundation-preview/route.ts +44 -0
  545. package/src/app/app/api/handoff/ai/generate-component/route.ts +137 -0
  546. package/src/app/app/api/handoff/ai/generate-design/route.ts +210 -0
  547. package/src/app/app/api/handoff/ai/generate-image/route.ts +72 -0
  548. package/src/app/app/api/handoff/ai/generate-pattern/route.ts +86 -0
  549. package/src/app/app/api/handoff/ai/playground-chat/refine/route.ts +52 -0
  550. package/src/app/app/api/handoff/ai/playground-chat/route.ts +102 -0
  551. package/src/app/app/api/handoff/ai/status/route.ts +14 -0
  552. package/src/app/app/api/handoff/artifact-asset/route.ts +88 -0
  553. package/src/app/app/api/handoff/assets/[id]/raw/route.ts +49 -0
  554. package/src/app/app/api/handoff/assets/[id]/route.ts +76 -0
  555. package/src/app/app/api/handoff/assets/collections/route.ts +54 -0
  556. package/src/app/app/api/handoff/assets/confirm/route.ts +80 -0
  557. package/src/app/app/api/handoff/assets/icon-sets/route.ts +47 -0
  558. package/src/app/app/api/handoff/assets/presign/route.ts +41 -0
  559. package/src/app/app/api/handoff/assets/route.ts +89 -0
  560. package/src/app/app/api/handoff/assets/upload/route.ts +152 -0
  561. package/src/app/app/api/handoff/assets/usages/[id]/route.ts +21 -0
  562. package/src/app/app/api/handoff/assets/usages/route.ts +69 -0
  563. package/src/app/app/api/handoff/auth/request-reset/route.ts +9 -0
  564. package/src/app/app/api/handoff/auth/reset-password/route.ts +17 -0
  565. package/src/app/app/api/handoff/capture/health/route.ts +86 -0
  566. package/src/app/app/api/handoff/capture/jobs/route.ts +75 -0
  567. package/src/app/app/api/handoff/capture/run/route.ts +112 -0
  568. package/src/app/app/api/handoff/changelog/pushes/route.ts +49 -0
  569. package/src/app/app/api/handoff/changelog/route.ts +28 -0
  570. package/src/app/app/api/handoff/changes/why/route.ts +41 -0
  571. package/src/app/app/api/handoff/cms/connections/route.ts +182 -0
  572. package/src/app/app/api/handoff/cms/sanity/callback/route.ts +18 -0
  573. package/src/app/app/api/handoff/cms/sanity/categories/route.ts +146 -0
  574. package/src/app/app/api/handoff/cms/sanity/connect/route.ts +15 -0
  575. package/src/app/app/api/handoff/cms/sanity/publish/route.ts +161 -0
  576. package/src/app/app/api/handoff/cms/sanity/token/route.ts +87 -0
  577. package/src/app/app/api/handoff/components/[id]/screenshot.png/route.ts +101 -0
  578. package/src/app/app/api/handoff/components/[id]/thumbnail.svg/route.ts +158 -0
  579. package/src/app/app/api/handoff/components/build/route.ts +26 -0
  580. package/src/app/app/api/handoff/components/history/contract/route.ts +33 -0
  581. package/src/app/app/api/handoff/components/history/route.ts +35 -0
  582. package/src/app/app/api/handoff/components/history/version/route.ts +36 -0
  583. package/src/app/app/api/handoff/components/route.ts +56 -0
  584. package/src/app/app/api/handoff/components/validation/route.ts +36 -0
  585. package/src/app/app/api/handoff/design/workspace/brand-imagery-image/route.ts +75 -0
  586. package/src/app/app/api/handoff/design/workspace/route.ts +163 -0
  587. package/src/app/app/api/handoff/figma/component-properties/route.ts +34 -0
  588. package/src/app/app/api/handoff/figma/components/route.ts +21 -0
  589. package/src/app/app/api/handoff/figma/components/sync/route.ts +50 -0
  590. package/src/app/app/api/handoff/figma/fetch/route.ts +126 -0
  591. package/src/app/app/api/handoff/guest/assets/route.ts +52 -0
  592. package/src/app/app/api/handoff/guest/enter/route.ts +169 -0
  593. package/src/app/app/api/handoff/guest/submission/route.ts +209 -0
  594. package/src/app/app/api/handoff/guest/submission/submit/route.ts +63 -0
  595. package/src/app/app/api/handoff/image-slots/route.ts +24 -0
  596. package/src/app/app/api/handoff/navigation/prune/route.ts +106 -0
  597. package/src/app/app/api/handoff/pages/route.ts +90 -0
  598. package/src/app/app/api/handoff/patterns/[id]/clone/route.ts +69 -0
  599. package/src/app/app/api/handoff/patterns/[id]/manifest/route.ts +102 -0
  600. package/src/app/app/api/handoff/patterns/[id]/notes/route.ts +101 -0
  601. package/src/app/app/api/handoff/patterns/[id]/route.ts +41 -0
  602. package/src/app/app/api/handoff/patterns/[id]/thumbnail.svg/route.ts +70 -0
  603. package/src/app/app/api/handoff/patterns/route.ts +77 -0
  604. package/src/app/app/api/handoff/reference-materials/route.ts +40 -0
  605. package/src/app/app/api/handoff/review/[id]/route.ts +172 -0
  606. package/src/app/app/api/handoff/review/[id]/voice/route.ts +58 -0
  607. package/src/app/app/api/handoff/review/route.ts +31 -0
  608. package/src/app/app/api/handoff/share/[token]/route.ts +82 -0
  609. package/src/app/app/api/handoff/share/links/route.ts +48 -0
  610. package/src/app/app/api/handoff/share/route.ts +172 -0
  611. package/src/app/app/api/handoff/site-protection/route.ts +85 -0
  612. package/src/app/app/api/handoff/site-protection/unlock/route.ts +62 -0
  613. package/src/app/app/api/handoff/templates/[id]/submissions/route.ts +41 -0
  614. package/src/app/app/api/mcp/route.ts +39 -0
  615. package/src/app/app/api/oauth/authorization-server-metadata/route.ts +30 -0
  616. package/src/app/app/api/oauth/authorize/route.ts +158 -0
  617. package/src/app/app/api/oauth/device/approve/route.ts +32 -0
  618. package/src/app/app/api/oauth/device/route.ts +34 -0
  619. package/src/app/app/api/oauth/protected-resource-metadata/route.ts +26 -0
  620. package/src/app/app/api/oauth/register/route.ts +43 -0
  621. package/src/app/app/api/oauth/token/route.ts +94 -0
  622. package/src/app/app/api/openapi/route.ts +38 -0
  623. package/src/app/app/api/patterns/route.ts +8 -0
  624. package/src/app/app/api/registry/assets/ingest/route.ts +204 -0
  625. package/src/app/app/api/registry/assets/ingest-figma-fills/route.ts +81 -0
  626. package/src/app/app/api/registry/components/[id]/previews/[previewId]/route.ts +56 -0
  627. package/src/app/app/api/registry/components/[id]/previews/route.ts +66 -0
  628. package/src/app/app/api/registry/config/route.ts +50 -0
  629. package/src/app/app/api/registry/dtcg/download/route.ts +78 -0
  630. package/src/app/app/api/registry/dtcg/route.ts +133 -0
  631. package/src/app/app/api/registry/fonts/route.ts +67 -0
  632. package/src/app/app/api/registry/icons/download/route.ts +52 -0
  633. package/src/app/app/api/registry/icons/route.ts +47 -0
  634. package/src/app/app/api/registry/image-slots/route.ts +68 -0
  635. package/src/app/app/api/registry/logo.svg/route.ts +45 -0
  636. package/src/app/app/api/registry/logos/route.ts +47 -0
  637. package/src/app/app/api/registry/navigation/route.ts +52 -0
  638. package/src/app/app/api/registry/pages/route.ts +67 -0
  639. package/src/app/app/api/registry/theme/route.ts +51 -0
  640. package/src/app/app/api/registry/theme.css/route.ts +34 -0
  641. package/src/app/app/api/registry/tokens/route.ts +59 -0
  642. package/src/app/app/api/sync/changes/route.ts +24 -0
  643. package/src/app/app/api/sync/shared-assets/route.ts +79 -0
  644. package/src/app/app/api/sync/status/route.ts +12 -0
  645. package/src/app/app/api/sync/upload/route.ts +109 -0
  646. package/src/app/app/assets/AssetsClient.tsx +670 -0
  647. package/src/app/app/assets/[id]/AssetDetailClient.tsx +319 -0
  648. package/src/app/app/assets/[id]/page.tsx +8 -0
  649. package/src/app/app/assets/fonts/page.tsx +5 -0
  650. package/src/app/app/assets/logos/page.tsx +5 -0
  651. package/src/app/app/assets/page.tsx +5 -0
  652. package/src/app/app/cli/device/CliDeviceClient.tsx +104 -0
  653. package/src/app/app/cli/device/page.tsx +45 -0
  654. package/src/app/app/design/DesignClient.tsx +1682 -0
  655. package/src/app/app/design/SessionHistoryPanel.tsx +116 -0
  656. package/src/app/app/design/assets/[id]/page.tsx +11 -0
  657. package/src/app/app/design/assets/icons/page.tsx +8 -0
  658. package/src/app/app/design/assets/page.tsx +8 -0
  659. package/src/app/app/design/library/[id]/SavedDesignDetailClient.tsx +892 -0
  660. package/src/app/app/design/library/[id]/page.tsx +40 -0
  661. package/src/app/app/design/library/[id]/share/SharePublicClient.tsx +107 -0
  662. package/src/app/app/design/library/[id]/share/page.tsx +22 -0
  663. package/src/app/app/design/library/page.tsx +12 -0
  664. package/src/app/app/design/page.tsx +158 -0
  665. package/src/app/app/design/settings/SettingsClient.tsx +648 -0
  666. package/src/app/app/design/settings/page.tsx +41 -0
  667. package/src/app/app/design/settings/settings-constants.ts +96 -0
  668. package/src/app/app/design/v1/DesignClient.tsx +1316 -0
  669. package/src/app/app/design/v1/page.tsx +103 -0
  670. package/src/app/app/design/workbench-session.ts +54 -0
  671. package/src/app/app/design/workbench-types.ts +72 -0
  672. package/src/app/app/dev/local-setup/LocalSetupClient.tsx +119 -0
  673. package/src/app/app/dev/local-setup/McpSetupSection.tsx +174 -0
  674. package/src/app/app/dev/local-setup/page.tsx +5 -0
  675. package/src/app/app/developer/api/route.ts +13 -0
  676. package/src/app/app/developer/cli/page.tsx +192 -0
  677. package/src/app/app/developer/layout.tsx +57 -0
  678. package/src/app/app/developer/local-setup/page.tsx +37 -0
  679. package/src/app/app/developer/mcp/page.tsx +74 -0
  680. package/src/app/app/developer/page.tsx +111 -0
  681. package/src/app/app/developer/push-pull/page.tsx +130 -0
  682. package/src/app/app/fonts/[filename]/route.ts +41 -0
  683. package/src/app/app/foundations/[...slug]/page.tsx +83 -0
  684. package/src/app/app/foundations/assets/[id]/page.tsx +35 -0
  685. package/src/app/app/foundations/assets/page.tsx +31 -0
  686. package/src/app/app/foundations/border-radius/page.tsx +179 -0
  687. package/src/app/app/foundations/colors/page.tsx +166 -0
  688. package/src/app/app/foundations/effects/page.tsx +124 -0
  689. package/src/app/app/foundations/elevation/page.tsx +209 -0
  690. package/src/app/app/foundations/error.tsx +22 -0
  691. package/src/app/app/foundations/grid/page.tsx +315 -0
  692. package/src/app/app/foundations/icons/IconsPageClient.tsx +100 -0
  693. package/src/app/app/foundations/icons/[name]/SingleIconClient.tsx +231 -0
  694. package/src/app/app/foundations/icons/[name]/page.tsx +44 -0
  695. package/src/app/app/foundations/icons/page.tsx +58 -0
  696. package/src/app/app/foundations/logo/page.tsx +213 -0
  697. package/src/app/app/foundations/motion/page.tsx +228 -0
  698. package/src/app/app/foundations/page.tsx +65 -0
  699. package/src/app/app/foundations/spacing/page.tsx +171 -0
  700. package/src/app/app/foundations/typography/page.tsx +115 -0
  701. package/src/app/app/layout.tsx +131 -0
  702. package/src/app/app/library/LibraryClient.tsx +567 -0
  703. package/src/app/app/library/page.tsx +46 -0
  704. package/src/app/app/login/LoginClient.tsx +75 -0
  705. package/src/app/app/login/page.tsx +33 -0
  706. package/src/app/app/page.tsx +178 -0
  707. package/src/app/app/patterns/PatternBrowserClient.tsx +263 -0
  708. package/src/app/app/patterns/page.tsx +14 -0
  709. package/src/app/app/playground/PlaygroundClient.tsx +84 -0
  710. package/src/app/app/playground/[id]/page.tsx +215 -0
  711. package/src/app/app/playground/page.tsx +79 -0
  712. package/src/app/app/providers.tsx +72 -0
  713. package/src/app/app/reset-password/ResetPasswordClient.tsx +89 -0
  714. package/src/app/app/reset-password/page.tsx +24 -0
  715. package/src/app/app/review/ReviewClient.tsx +31 -0
  716. package/src/app/app/review/page.tsx +56 -0
  717. package/src/app/app/s/[token]/page.tsx +317 -0
  718. package/src/app/app/setup/SetupClient.tsx +87 -0
  719. package/src/app/app/setup/actions.ts +53 -0
  720. package/src/app/app/setup/page.tsx +28 -0
  721. package/src/app/app/system/FigmaFetchControls.tsx +163 -0
  722. package/src/app/app/system/FigmaSyncPanel.tsx +357 -0
  723. package/src/app/app/system/NewComponentForm.tsx +272 -0
  724. package/src/app/app/system/SystemPageClient.tsx +137 -0
  725. package/src/app/app/system/changelog/ChangelogClient.tsx +608 -0
  726. package/src/app/app/system/changelog/page.tsx +28 -0
  727. package/src/app/app/system/component/[component]/ComponentAssetsPanel.tsx +108 -0
  728. package/src/app/app/system/component/[component]/ComponentDetailClient.tsx +420 -0
  729. package/src/app/app/system/component/[component]/ComponentImageSlotsPanel.tsx +163 -0
  730. package/src/app/app/system/component/[component]/ComponentVersionHistory.tsx +430 -0
  731. package/src/app/app/system/component/[component]/VersionCompare.tsx +267 -0
  732. package/src/app/app/system/component/[component]/page.tsx +68 -0
  733. package/src/app/app/system/component/page.tsx +5 -0
  734. package/src/app/app/system/figma-sync/FigmaSyncPageClient.tsx +35 -0
  735. package/src/app/app/system/figma-sync/page.tsx +21 -0
  736. package/src/app/app/system/health/ComponentHealthTable.tsx +217 -0
  737. package/src/app/app/system/health/HealthDashboardClient.tsx +141 -0
  738. package/src/app/app/system/health/RuleBreakdownTable.tsx +123 -0
  739. package/src/app/app/system/health/ScoreBadge.tsx +58 -0
  740. package/src/app/app/system/health/TrendChart.tsx +76 -0
  741. package/src/app/app/system/health/ValidatorBreakdownBars.tsx +35 -0
  742. package/src/app/app/system/health/health-types.ts +7 -0
  743. package/src/app/app/system/health/page.tsx +100 -0
  744. package/src/app/app/system/page.tsx +21 -0
  745. package/src/app/app/system/pattern/[pattern]/PatternDetailClient.tsx +216 -0
  746. package/src/app/app/system/pattern/[pattern]/page.tsx +53 -0
  747. package/src/app/app/system/pattern/page.tsx +5 -0
  748. package/src/app/app/unlock/UnlockClient.tsx +100 -0
  749. package/src/app/app/unlock/page.tsx +40 -0
  750. package/src/app/components/Auth/AuthControls.tsx +146 -0
  751. package/src/app/components/Brief/BuildList.tsx +78 -0
  752. package/src/app/components/Brief/BuildPanel.tsx +460 -0
  753. package/src/app/components/Brief/export-blocks.ts +47 -0
  754. package/src/app/components/Chat/ChatActionCard.tsx +97 -0
  755. package/src/app/components/Chat/ChatChangelogFeed.tsx +252 -0
  756. package/src/app/components/Chat/ChatComponentGrid.tsx +144 -0
  757. package/src/app/components/Chat/ChatContext.tsx +192 -0
  758. package/src/app/components/Chat/ChatDrawer.tsx +162 -0
  759. package/src/app/components/Chat/ChatFab.tsx +41 -0
  760. package/src/app/components/Chat/ChatInput.tsx +150 -0
  761. package/src/app/components/Chat/ChatMessage.tsx +125 -0
  762. package/src/app/components/Chat/ChatValidationPanel.tsx +161 -0
  763. package/src/app/components/CloudFeatureGate.tsx +27 -0
  764. package/src/app/components/Component/BestPracticesCard.tsx +36 -0
  765. package/src/app/components/Component/Cards.tsx +76 -0
  766. package/src/app/components/Component/ComponentLists.tsx +279 -0
  767. package/src/app/components/Component/ComponentWorkbenchDialog.tsx +230 -0
  768. package/src/app/components/Component/InlineComponentEditor.tsx +163 -0
  769. package/src/app/components/Component/PageSliceResolver.tsx +81 -0
  770. package/src/app/components/Component/Preview.tsx +1091 -0
  771. package/src/app/components/Component/slices/BestPracticesSlice.tsx +14 -0
  772. package/src/app/components/Component/slices/CardsSlice.tsx +17 -0
  773. package/src/app/components/Component/slices/ComponentDisplaySlice.tsx +101 -0
  774. package/src/app/components/Component/slices/PropertiesSlice.tsx +24 -0
  775. package/src/app/components/Component/slices/TextSlice.tsx +23 -0
  776. package/src/app/components/Component/slices/ValidationResultsSlice.tsx +31 -0
  777. package/src/app/components/Component/slices/index.ts +14 -0
  778. package/src/app/components/Component/usePreviews.ts +97 -0
  779. package/src/app/components/ComponentDesignTokens.tsx +271 -0
  780. package/src/app/components/ComponentGuidelines.tsx +21 -0
  781. package/src/app/components/ComponentNotFound.tsx +35 -0
  782. package/src/app/components/ComponentSearch.tsx +96 -0
  783. package/src/app/components/CopyCode.tsx +59 -0
  784. package/src/app/components/CopyToClipboard.tsx +63 -0
  785. package/src/app/components/Design/DevHandoffPanel.tsx +481 -0
  786. package/src/app/components/DownloadTokens.tsx +78 -0
  787. package/src/app/components/Footer.tsx +46 -0
  788. package/src/app/components/Foundations/BrandColorSwatches.tsx +151 -0
  789. package/src/app/components/Foundations/ColorContrast.tsx +179 -0
  790. package/src/app/components/Foundations/ColorGrid.tsx +199 -0
  791. package/src/app/components/Foundations/ColorInfo.tsx +64 -0
  792. package/src/app/components/Foundations/ColorSpaces.tsx +119 -0
  793. package/src/app/components/Foundations/ColorTailwind.tsx +58 -0
  794. package/src/app/components/Foundations/ColorsDisplay.tsx +136 -0
  795. package/src/app/components/Foundations/DisplayLogo.tsx +16 -0
  796. package/src/app/components/Foundations/IconCatalogGrid.tsx +145 -0
  797. package/src/app/components/Foundations/ProvenanceBadge.tsx +40 -0
  798. package/src/app/components/Foundations/RulesSheet.tsx +204 -0
  799. package/src/app/components/Foundations/TokenOutputTabs.tsx +88 -0
  800. package/src/app/components/Foundations/TypographyExample.tsx +275 -0
  801. package/src/app/components/Guest/GuestAuthoring.tsx +589 -0
  802. package/src/app/components/Guest/GuestEditor.tsx +157 -0
  803. package/src/app/components/Hero.tsx +42 -0
  804. package/src/app/components/InlineEdit/InlineEditField.tsx +162 -0
  805. package/src/app/components/InlineEdit/InlineEditHeader.tsx +98 -0
  806. package/src/app/components/Layout/BuildBadge.tsx +90 -0
  807. package/src/app/components/Layout/Header.tsx +54 -0
  808. package/src/app/components/Layout/Main.tsx +84 -0
  809. package/src/app/components/Markdown/CodeHighlight.tsx +328 -0
  810. package/src/app/components/Markdown/MarkdownComponents.tsx +270 -0
  811. package/src/app/components/Markdown/MarkdownEditor.tsx +153 -0
  812. package/src/app/components/Markdown/WysiwygEditor.tsx +364 -0
  813. package/src/app/components/Markdown/wysiwyg.css +89 -0
  814. package/src/app/components/ModeSwitcher.tsx +29 -0
  815. package/src/app/components/NavLink.tsx +26 -0
  816. package/src/app/components/Navigation/AnchorNav.tsx +94 -0
  817. package/src/app/components/Navigation/AnchorNavLink.tsx +41 -0
  818. package/src/app/components/Navigation/AnchorNavNew.tsx +27 -0
  819. package/src/app/components/Navigation/MainNav.tsx +84 -0
  820. package/src/app/components/Navigation/MobileNav.tsx +123 -0
  821. package/src/app/components/Navigation/PrevNextNav.tsx +53 -0
  822. package/src/app/components/Navigation/SideNav.tsx +336 -0
  823. package/src/app/components/Navigation/anchor-slugify.ts +6 -0
  824. package/src/app/components/Playground/AiChatPanel.tsx +1483 -0
  825. package/src/app/components/Playground/ComponentCard.tsx +65 -0
  826. package/src/app/components/Playground/ComponentLibrary.tsx +228 -0
  827. package/src/app/components/Playground/CoverImagePicker.tsx +281 -0
  828. package/src/app/components/Playground/EditContext.tsx +247 -0
  829. package/src/app/components/Playground/EditSheet.tsx +82 -0
  830. package/src/app/components/Playground/FieldGuardrailsContext.ts +31 -0
  831. package/src/app/components/Playground/FieldLinkContext.ts +138 -0
  832. package/src/app/components/Playground/FieldMediaContext.ts +50 -0
  833. package/src/app/components/Playground/FindingsList.tsx +149 -0
  834. package/src/app/components/Playground/MediaBrowser.tsx +397 -0
  835. package/src/app/components/Playground/PageChecks.tsx +71 -0
  836. package/src/app/components/Playground/PageTitle.tsx +93 -0
  837. package/src/app/components/Playground/PlaygroundBuilder.tsx +1271 -0
  838. package/src/app/components/Playground/PlaygroundContext.tsx +990 -0
  839. package/src/app/components/Playground/PlaygroundWorkbench.tsx +260 -0
  840. package/src/app/components/Playground/Preview.tsx +1465 -0
  841. package/src/app/components/Playground/PublishToSanityDialog.tsx +468 -0
  842. package/src/app/components/Playground/SavePatternDialog.tsx +231 -0
  843. package/src/app/components/Playground/ShareTemplate.tsx +503 -0
  844. package/src/app/components/Playground/SortableItem.tsx +94 -0
  845. package/src/app/components/Playground/Wizard/ApiKeySettings.tsx +139 -0
  846. package/src/app/components/Playground/Wizard/PageImporter.tsx +384 -0
  847. package/src/app/components/Playground/Wizard/WizardDialog.tsx +329 -0
  848. package/src/app/components/Playground/Wizard/llm-client.ts +87 -0
  849. package/src/app/components/Playground/Wizard/prompt-builder.ts +134 -0
  850. package/src/app/components/Playground/Wizard/response-parser.ts +80 -0
  851. package/src/app/components/Playground/fields/ButtonField.tsx +24 -0
  852. package/src/app/components/Playground/fields/Field.tsx +344 -0
  853. package/src/app/components/Playground/fields/FieldLabel.tsx +9 -0
  854. package/src/app/components/Playground/fields/FunctionField.tsx +19 -0
  855. package/src/app/components/Playground/fields/ImageField.tsx +239 -0
  856. package/src/app/components/Playground/fields/LinkField.tsx +24 -0
  857. package/src/app/components/Playground/fields/RawJsonField.tsx +60 -0
  858. package/src/app/components/Playground/fields/RichTextField.tsx +220 -0
  859. package/src/app/components/Playground/fields/SelectField.tsx +55 -0
  860. package/src/app/components/Playground/fields/SlotField.tsx +40 -0
  861. package/src/app/components/Playground/fields/TextField.tsx +125 -0
  862. package/src/app/components/Playground/fields/VideoFileField.tsx +67 -0
  863. package/src/app/components/Playground/fields/content-only.ts +121 -0
  864. package/src/app/components/Playground/fields/field-type.ts +84 -0
  865. package/src/app/components/Playground/fields/reseed.ts +140 -0
  866. package/src/app/components/Playground/inline-edit-script.ts +596 -0
  867. package/src/app/components/Playground/link-guard-script.ts +50 -0
  868. package/src/app/components/Playground/types.ts +76 -0
  869. package/src/app/components/Playground/usePublishToSanity.ts +153 -0
  870. package/src/app/components/Review/ReviewQueueClient.tsx +288 -0
  871. package/src/app/components/SideNav/Custom.tsx +40 -0
  872. package/src/app/components/SideNavNew.tsx +280 -0
  873. package/src/app/components/Typography/Headers.tsx +50 -0
  874. package/src/app/components/Validation/ValidationFrameworkResults.tsx +208 -0
  875. package/src/app/components/Validation/ValidationResults.tsx +60 -0
  876. package/src/app/components/cards/CardsWithIcons.tsx +38 -0
  877. package/src/app/components/context/AuthUiContext.tsx +13 -0
  878. package/src/app/components/context/ConfigContext.tsx +43 -0
  879. package/src/app/components/context/HandoffCapabilitiesContext.tsx +40 -0
  880. package/src/app/components/context/HotReloadProvider.tsx +38 -0
  881. package/src/app/components/context/PreviewContext.tsx +135 -0
  882. package/src/app/components/library/AssetCard.tsx +166 -0
  883. package/src/app/components/library/KindPicker.tsx +66 -0
  884. package/src/app/components/library/LaneTabs.tsx +54 -0
  885. package/src/app/components/library/LifecycleBadge.tsx +28 -0
  886. package/src/app/components/library/LifecyclePicker.tsx +53 -0
  887. package/src/app/components/library/MetaControl.tsx +294 -0
  888. package/src/app/components/library/OwnerAttribution.tsx +106 -0
  889. package/src/app/components/library/PageNotes.tsx +191 -0
  890. package/src/app/components/library/PageOrigin.tsx +124 -0
  891. package/src/app/components/library/VisibilityBadge.tsx +25 -0
  892. package/src/app/components/library/VisibilityPicker.tsx +56 -0
  893. package/src/app/components/library/index.ts +7 -0
  894. package/src/app/components/ui/accordion.tsx +49 -0
  895. package/src/app/components/ui/alert.tsx +39 -0
  896. package/src/app/components/ui/attachment.tsx +204 -0
  897. package/src/app/components/ui/badge.tsx +32 -0
  898. package/src/app/components/ui/breadcrumb.tsx +68 -0
  899. package/src/app/components/ui/bubble.tsx +125 -0
  900. package/src/app/components/ui/button.tsx +45 -0
  901. package/src/app/components/ui/card.tsx +76 -0
  902. package/src/app/components/ui/collapsible.tsx +9 -0
  903. package/src/app/components/ui/dialog.tsx +80 -0
  904. package/src/app/components/ui/drawer.tsx +103 -0
  905. package/src/app/components/ui/dropdown-menu.tsx +176 -0
  906. package/src/app/components/ui/input.tsx +22 -0
  907. package/src/app/components/ui/json-tree-view.tsx +250 -0
  908. package/src/app/components/ui/label.tsx +24 -0
  909. package/src/app/components/ui/marker.tsx +69 -0
  910. package/src/app/components/ui/message-scroller.tsx +130 -0
  911. package/src/app/components/ui/message.tsx +92 -0
  912. package/src/app/components/ui/mobile-nav.tsx +95 -0
  913. package/src/app/components/ui/navigation-menu.tsx +116 -0
  914. package/src/app/components/ui/popover.tsx +31 -0
  915. package/src/app/components/ui/radio-group.tsx +36 -0
  916. package/src/app/components/ui/select.tsx +132 -0
  917. package/src/app/components/ui/separator.tsx +29 -0
  918. package/src/app/components/ui/sheet.tsx +140 -0
  919. package/src/app/components/ui/sidebar.tsx +609 -0
  920. package/src/app/components/ui/skeleton.tsx +15 -0
  921. package/src/app/components/ui/switch.tsx +29 -0
  922. package/src/app/components/ui/table.tsx +60 -0
  923. package/src/app/components/ui/tabs.tsx +53 -0
  924. package/src/app/components/ui/textarea.tsx +19 -0
  925. package/src/app/components/ui/toggle-group.tsx +51 -0
  926. package/src/app/components/ui/toggle.tsx +39 -0
  927. package/src/app/components/ui/tooltip.tsx +30 -0
  928. package/src/app/components/util/colors.ts +93 -0
  929. package/src/app/components/util/dtcg.ts +50 -0
  930. package/src/app/components/util/index.ts +963 -0
  931. package/src/app/components/util/theme-provider.tsx +11 -0
  932. package/src/app/components/util/token.ts +70 -0
  933. package/src/app/components.json +21 -0
  934. package/src/app/css/index.css +275 -0
  935. package/src/app/css/theme.css +14 -0
  936. package/src/app/css.d.ts +1 -0
  937. package/src/app/hooks/use-mobile.tsx +17 -0
  938. package/src/app/instrumentation.ts +39 -0
  939. package/src/app/lib/adapter-kit/errors.ts +141 -0
  940. package/src/app/lib/adapter-kit/types.ts +637 -0
  941. package/src/app/lib/admin-build-tasks-types.ts +41 -0
  942. package/src/app/lib/api-path.ts +12 -0
  943. package/src/app/lib/asset-search.ts +167 -0
  944. package/src/app/lib/asset-types.ts +88 -0
  945. package/src/app/lib/asset-upload-source.ts +314 -0
  946. package/src/app/lib/auth.ts +244 -0
  947. package/src/app/lib/authoring-guardrails.ts +591 -0
  948. package/src/app/lib/authoring-shapes.ts +261 -0
  949. package/src/app/lib/authz/guest.ts +131 -0
  950. package/src/app/lib/authz/notes.ts +102 -0
  951. package/src/app/lib/authz/policy.ts +228 -0
  952. package/src/app/lib/authz/review.ts +180 -0
  953. package/src/app/lib/authz/vocab.ts +175 -0
  954. package/src/app/lib/brief-components.ts +212 -0
  955. package/src/app/lib/build-audits.ts +239 -0
  956. package/src/app/lib/capture-chromium-plan.ts +123 -0
  957. package/src/app/lib/capture-determinism.ts +397 -0
  958. package/src/app/lib/capture-kinds.ts +207 -0
  959. package/src/app/lib/change-digest.ts +108 -0
  960. package/src/app/lib/chat-turn-guards.ts +149 -0
  961. package/src/app/lib/cli-sync-jwt.ts +110 -0
  962. package/src/app/lib/client/poll-generation-job.ts +85 -0
  963. package/src/app/lib/client-name.ts +29 -0
  964. package/src/app/lib/cms-migration-prompt.ts +99 -0
  965. package/src/app/lib/component-capture.ts +156 -0
  966. package/src/app/lib/component-id.ts +14 -0
  967. package/src/app/lib/component-thumbnail.ts +200 -0
  968. package/src/app/lib/composition-summary.ts +84 -0
  969. package/src/app/lib/content-length-plan.ts +512 -0
  970. package/src/app/lib/contract-limit-audit.ts +228 -0
  971. package/src/app/lib/contract-render-audit.ts +208 -0
  972. package/src/app/lib/data/component-row.ts +121 -0
  973. package/src/app/lib/data/components-digest.ts +116 -0
  974. package/src/app/lib/data/dynamic-provider.ts +765 -0
  975. package/src/app/lib/data/has-payload.ts +18 -0
  976. package/src/app/lib/data/hybrid-provider.ts +6 -0
  977. package/src/app/lib/data/index.ts +45 -0
  978. package/src/app/lib/data/menu-merge.ts +417 -0
  979. package/src/app/lib/data/page-metadata.ts +85 -0
  980. package/src/app/lib/data/pattern-merge.ts +78 -0
  981. package/src/app/lib/data/static-provider.ts +237 -0
  982. package/src/app/lib/data/types.ts +125 -0
  983. package/src/app/lib/db/auto-migrate.ts +205 -0
  984. package/src/app/lib/db/bootstrap-admin.ts +45 -0
  985. package/src/app/lib/db/capture-job-queries.ts +333 -0
  986. package/src/app/lib/db/changelog-queries.ts +623 -0
  987. package/src/app/lib/db/cms-connection-config.ts +21 -0
  988. package/src/app/lib/db/cms-connection-queries.ts +218 -0
  989. package/src/app/lib/db/component-artifact-queries.ts +115 -0
  990. package/src/app/lib/db/component-facets.ts +535 -0
  991. package/src/app/lib/db/component-preview-queries.ts +224 -0
  992. package/src/app/lib/db/component-version-queries.ts +682 -0
  993. package/src/app/lib/db/dialect.ts +15 -0
  994. package/src/app/lib/db/event-log-store.ts +47 -0
  995. package/src/app/lib/db/grant-queries.ts +827 -0
  996. package/src/app/lib/db/history-purge-plan.ts +446 -0
  997. package/src/app/lib/db/history-purge.ts +233 -0
  998. package/src/app/lib/db/index.ts +92 -0
  999. package/src/app/lib/db/migrations/0000_init.sql +226 -0
  1000. package/src/app/lib/db/migrations/0001_design_workspace.sql +12 -0
  1001. package/src/app/lib/db/migrations/0002_boring_ricochet.sql +50 -0
  1002. package/src/app/lib/db/migrations/0003_demonic_flatman.sql +41 -0
  1003. package/src/app/lib/db/migrations/0004_validation_runs.sql +18 -0
  1004. package/src/app/lib/db/migrations/0005_component_versions.sql +21 -0
  1005. package/src/app/lib/db/migrations/0006_token_and_page_changes.sql +40 -0
  1006. package/src/app/lib/db/migrations/0007_design_spec.sql +9 -0
  1007. package/src/app/lib/db/migrations/0008_design_generation_jobs.sql +22 -0
  1008. package/src/app/lib/db/migrations/0009_assets.sql +80 -0
  1009. package/src/app/lib/db/migrations/0010_registry_dtcg.sql +13 -0
  1010. package/src/app/lib/db/migrations/0011_dtcg_brands.sql +5 -0
  1011. package/src/app/lib/db/migrations/0012_icon_logo_registry.sql +13 -0
  1012. package/src/app/lib/db/migrations/0013_registry_fonts.sql +13 -0
  1013. package/src/app/lib/db/migrations/0014_asset_blobs.sql +9 -0
  1014. package/src/app/lib/db/migrations/0015_appearance.sql +7 -0
  1015. package/src/app/lib/db/migrations/0016_image_slots.sql +16 -0
  1016. package/src/app/lib/db/migrations/0017_component_preview.sql +20 -0
  1017. package/src/app/lib/db/migrations/0018_token_change_details.sql +26 -0
  1018. package/src/app/lib/db/migrations/0019_change_why.sql +18 -0
  1019. package/src/app/lib/db/migrations/0020_pattern_change.sql +17 -0
  1020. package/src/app/lib/db/migrations/0021_mcp_oauth_connector.sql +37 -0
  1021. package/src/app/lib/db/migrations/0022_dtcg_source.sql +21 -0
  1022. package/src/app/lib/db/migrations/0023_perf_indexes.sql +30 -0
  1023. package/src/app/lib/db/migrations/0024_phase_b_visibility.sql +40 -0
  1024. package/src/app/lib/db/migrations/0027_guest_authoring.sql +49 -0
  1025. package/src/app/lib/db/migrations/0028_invite_to_build.sql +99 -0
  1026. package/src/app/lib/db/migrations/0029_pages_templates_reflow.sql +121 -0
  1027. package/src/app/lib/db/migrations/0030_retire_briefs.sql +71 -0
  1028. package/src/app/lib/db/migrations/0031_drop_brief_columns.sql +32 -0
  1029. package/src/app/lib/db/migrations/0033_site_protection.sql +45 -0
  1030. package/src/app/lib/db/migrations/0034_brand_imagery.sql +8 -0
  1031. package/src/app/lib/db/migrations/0035_history_provenance.sql +42 -0
  1032. package/src/app/lib/db/migrations/0036_cms_connections.sql +68 -0
  1033. package/src/app/lib/db/migrations/0037_component_preview_purpose.sql +17 -0
  1034. package/src/app/lib/db/migrations/0038_capture_job.sql +87 -0
  1035. package/src/app/lib/db/migrations/meta/0000_snapshot.json +1424 -0
  1036. package/src/app/lib/db/migrations/meta/0002_snapshot.json +1644 -0
  1037. package/src/app/lib/db/migrations/meta/0003_snapshot.json +1820 -0
  1038. package/src/app/lib/db/migrations/meta/_journal.json +258 -0
  1039. package/src/app/lib/db/note-queries.ts +184 -0
  1040. package/src/app/lib/db/pattern-write.ts +1094 -0
  1041. package/src/app/lib/db/property-delta.ts +117 -0
  1042. package/src/app/lib/db/push-grouping.ts +256 -0
  1043. package/src/app/lib/db/queries.ts +2426 -0
  1044. package/src/app/lib/db/registry-queries.ts +607 -0
  1045. package/src/app/lib/db/schema-active.ts +2 -0
  1046. package/src/app/lib/db/schema-pg.ts +1201 -0
  1047. package/src/app/lib/db/schema.ts +2 -0
  1048. package/src/app/lib/db/seed.ts +117 -0
  1049. package/src/app/lib/db/sync-queries.ts +542 -0
  1050. package/src/app/lib/db/token-flatten.ts +95 -0
  1051. package/src/app/lib/db/validation-queries.ts +82 -0
  1052. package/src/app/lib/db/version-baseline.ts +42 -0
  1053. package/src/app/lib/design-workspace-client.ts +194 -0
  1054. package/src/app/lib/design-workspace-format.ts +294 -0
  1055. package/src/app/lib/docx-copy.ts +279 -0
  1056. package/src/app/lib/dtcg-axes.ts +138 -0
  1057. package/src/app/lib/dtcg-normalizer.ts +370 -0
  1058. package/src/app/lib/edit-operations.ts +275 -0
  1059. package/src/app/lib/email.ts +199 -0
  1060. package/src/app/lib/error-summary.ts +79 -0
  1061. package/src/app/lib/evals/cases.ts +678 -0
  1062. package/src/app/lib/evals/copy-coverage.ts +147 -0
  1063. package/src/app/lib/evals/copy-decks.ts +296 -0
  1064. package/src/app/lib/field-lens.ts +308 -0
  1065. package/src/app/lib/field-marks.ts +206 -0
  1066. package/src/app/lib/figma-plugin-contract.ts +104 -0
  1067. package/src/app/lib/figma-sync-types.ts +56 -0
  1068. package/src/app/lib/generated/build-meta.ts +8 -0
  1069. package/src/app/lib/guest-editable.ts +371 -0
  1070. package/src/app/lib/handoff-capabilities.ts +91 -0
  1071. package/src/app/lib/health-types.ts +324 -0
  1072. package/src/app/lib/hubspot-field-map.ts +770 -0
  1073. package/src/app/lib/hubspot-module/build-module.ts +238 -0
  1074. package/src/app/lib/hubspot-module/context.ts +259 -0
  1075. package/src/app/lib/hubspot-module/fields/boolean.ts +24 -0
  1076. package/src/app/lib/hubspot-module/fields/button.ts +70 -0
  1077. package/src/app/lib/hubspot-module/fields/fields.ts +104 -0
  1078. package/src/app/lib/hubspot-module/fields/generic.ts +183 -0
  1079. package/src/app/lib/hubspot-module/fields/hubdb.ts +168 -0
  1080. package/src/app/lib/hubspot-module/fields/image.ts +65 -0
  1081. package/src/app/lib/hubspot-module/fields/menu.ts +14 -0
  1082. package/src/app/lib/hubspot-module/fields/object.ts +42 -0
  1083. package/src/app/lib/hubspot-module/fields/select.ts +43 -0
  1084. package/src/app/lib/hubspot-module/fields/text.ts +68 -0
  1085. package/src/app/lib/hubspot-module/fields/url.ts +57 -0
  1086. package/src/app/lib/hubspot-module/fields/utils.ts +36 -0
  1087. package/src/app/lib/hubspot-module/fields/video.ts +75 -0
  1088. package/src/app/lib/hubspot-module/index.ts +30 -0
  1089. package/src/app/lib/hubspot-module/transpile.ts +727 -0
  1090. package/src/app/lib/hubspot-module/types.ts +238 -0
  1091. package/src/app/lib/hubspot-module-build.ts +50 -0
  1092. package/src/app/lib/image-bytes.ts +133 -0
  1093. package/src/app/lib/image-dimensions.ts +214 -0
  1094. package/src/app/lib/image-field-write.ts +51 -0
  1095. package/src/app/lib/image-generation-request.ts +142 -0
  1096. package/src/app/lib/image-target.ts +175 -0
  1097. package/src/app/lib/json-shape.ts +121 -0
  1098. package/src/app/lib/library-image-seed.ts +236 -0
  1099. package/src/app/lib/login-required-messages.ts +17 -0
  1100. package/src/app/lib/mcp/apps/component-gallery.bundle.ts +2 -0
  1101. package/src/app/lib/mcp/apps/component-gallery.client.ts +208 -0
  1102. package/src/app/lib/mcp/apps/component-preview.bundle.ts +2 -0
  1103. package/src/app/lib/mcp/apps/component-preview.client.ts +140 -0
  1104. package/src/app/lib/mcp/apps/token-palette.bundle.ts +2 -0
  1105. package/src/app/lib/mcp/apps/token-palette.client.ts +199 -0
  1106. package/src/app/lib/mcp/contract-report.ts +200 -0
  1107. package/src/app/lib/mcp/create-server.ts +2622 -0
  1108. package/src/app/lib/mcp/history-shapes.ts +72 -0
  1109. package/src/app/lib/mcp/project-profile.ts +82 -0
  1110. package/src/app/lib/mcp/scaffold-helpers.ts +93 -0
  1111. package/src/app/lib/mcp/stack-guides/bootstrap-handlebars.md +62 -0
  1112. package/src/app/lib/mcp/stack-guides/react-scss.md +7 -0
  1113. package/src/app/lib/mcp/stack-guides/react-tailwind.md +9 -0
  1114. package/src/app/lib/mcp/stack-guides/tailwind-handlebars.md +142 -0
  1115. package/src/app/lib/mcp/stack-guides.ts +68 -0
  1116. package/src/app/lib/mcp/tool-catalog.ts +132 -0
  1117. package/src/app/lib/mcp-auth.ts +85 -0
  1118. package/src/app/lib/merge-block-values.ts +868 -0
  1119. package/src/app/lib/normalize-preview-values.ts +244 -0
  1120. package/src/app/lib/notify.ts +213 -0
  1121. package/src/app/lib/oauth-scopes.ts +33 -0
  1122. package/src/app/lib/page-exemplars.ts +112 -0
  1123. package/src/app/lib/page-manifest.ts +162 -0
  1124. package/src/app/lib/page-provenance.ts +231 -0
  1125. package/src/app/lib/page-slug.ts +68 -0
  1126. package/src/app/lib/page-title.ts +44 -0
  1127. package/src/app/lib/page-urls.ts +41 -0
  1128. package/src/app/lib/passwords.ts +33 -0
  1129. package/src/app/lib/pattern-payload.ts +122 -0
  1130. package/src/app/lib/pattern-thumbnail.ts +234 -0
  1131. package/src/app/lib/placeholder-audit.ts +196 -0
  1132. package/src/app/lib/placeholder-copy.ts +370 -0
  1133. package/src/app/lib/playground-prompt-link.ts +46 -0
  1134. package/src/app/lib/preview-groups.ts +107 -0
  1135. package/src/app/lib/preview-purpose-labels.ts +37 -0
  1136. package/src/app/lib/preview-purpose.ts +37 -0
  1137. package/src/app/lib/preview-render-target.ts +27 -0
  1138. package/src/app/lib/preview-url.ts +15 -0
  1139. package/src/app/lib/publish-to-sanity-state.ts +605 -0
  1140. package/src/app/lib/rate-limit.ts +75 -0
  1141. package/src/app/lib/remote-handoff-client.ts +33 -0
  1142. package/src/app/lib/sanity-assets.ts +211 -0
  1143. package/src/app/lib/sanity-categories.ts +178 -0
  1144. package/src/app/lib/sanity-config.ts +266 -0
  1145. package/src/app/lib/sanity-integration-state.ts +235 -0
  1146. package/src/app/lib/sanity-mapping.ts +3284 -0
  1147. package/src/app/lib/sanity-portable-text.ts +640 -0
  1148. package/src/app/lib/sanity-publish.ts +337 -0
  1149. package/src/app/lib/sanity-references.ts +295 -0
  1150. package/src/app/lib/server/admin-users.ts +162 -0
  1151. package/src/app/lib/server/ai-client.ts +633 -0
  1152. package/src/app/lib/server/ai-proxy.ts +70 -0
  1153. package/src/app/lib/server/api-gate.ts +148 -0
  1154. package/src/app/lib/server/appearance.ts +169 -0
  1155. package/src/app/lib/server/asset-generation-worker.ts +133 -0
  1156. package/src/app/lib/server/asset-ingest-store.ts +55 -0
  1157. package/src/app/lib/server/asset-ingest.ts +347 -0
  1158. package/src/app/lib/server/auth-reset.ts +107 -0
  1159. package/src/app/lib/server/capture-browser.ts +130 -0
  1160. package/src/app/lib/server/capture-harness.ts +319 -0
  1161. package/src/app/lib/server/capture-worker.ts +178 -0
  1162. package/src/app/lib/server/change-why.ts +195 -0
  1163. package/src/app/lib/server/cli-device-oauth.ts +159 -0
  1164. package/src/app/lib/server/cms-providers.ts +53 -0
  1165. package/src/app/lib/server/component-build-preload.cjs +3 -0
  1166. package/src/app/lib/server/component-build-worker.ts +196 -0
  1167. package/src/app/lib/server/component-builder.ts +96 -0
  1168. package/src/app/lib/server/component-capture-reads.ts +172 -0
  1169. package/src/app/lib/server/component-generation-context.ts +165 -0
  1170. package/src/app/lib/server/component-generation-images.ts +40 -0
  1171. package/src/app/lib/server/component-generation-llm.ts +232 -0
  1172. package/src/app/lib/server/component-generation-run.ts +289 -0
  1173. package/src/app/lib/server/component-generation-schedule.ts +12 -0
  1174. package/src/app/lib/server/component-preview-screenshot.ts +111 -0
  1175. package/src/app/lib/server/component-scaffold.ts +88 -0
  1176. package/src/app/lib/server/component-visual-compare.ts +90 -0
  1177. package/src/app/lib/server/design-artifact-persist.ts +49 -0
  1178. package/src/app/lib/server/design-asset-extractor.ts +414 -0
  1179. package/src/app/lib/server/design-asset-schedule.ts +36 -0
  1180. package/src/app/lib/server/design-asset-worker-spawn.ts +64 -0
  1181. package/src/app/lib/server/design-asset-worker.ts +24 -0
  1182. package/src/app/lib/server/design-generation-worker.ts +281 -0
  1183. package/src/app/lib/server/design-prompt-builder.ts +322 -0
  1184. package/src/app/lib/server/design-spec-generator.ts +739 -0
  1185. package/src/app/lib/server/design-spec-types.ts +219 -0
  1186. package/src/app/lib/server/design-system-context.ts +141 -0
  1187. package/src/app/lib/server/design-token-summary.ts +133 -0
  1188. package/src/app/lib/server/design-workspace.ts +230 -0
  1189. package/src/app/lib/server/dev-handoff.ts +334 -0
  1190. package/src/app/lib/server/doc-pages.ts +442 -0
  1191. package/src/app/lib/server/event-log.ts +138 -0
  1192. package/src/app/lib/server/fetch-asset-bytes.ts +161 -0
  1193. package/src/app/lib/server/figma-audit-api.ts +188 -0
  1194. package/src/app/lib/server/figma-auth.ts +113 -0
  1195. package/src/app/lib/server/figma-fetch-runner.ts +241 -0
  1196. package/src/app/lib/server/figma-fetch-worker.ts +130 -0
  1197. package/src/app/lib/server/figma-fetch.ts +90 -0
  1198. package/src/app/lib/server/figma-fills-ingest.ts +201 -0
  1199. package/src/app/lib/server/figma-plugin-properties-sync.ts +438 -0
  1200. package/src/app/lib/server/figma-sync-service.ts +1076 -0
  1201. package/src/app/lib/server/find-assets.ts +53 -0
  1202. package/src/app/lib/server/foundation-image.tsx +671 -0
  1203. package/src/app/lib/server/generation-queue-health.ts +108 -0
  1204. package/src/app/lib/server/guest-context.ts +62 -0
  1205. package/src/app/lib/server/guest-session.ts +153 -0
  1206. package/src/app/lib/server/handoff-app-paths.ts +77 -0
  1207. package/src/app/lib/server/handoff-component-patch.ts +123 -0
  1208. package/src/app/lib/server/handoff-config-load.ts +29 -0
  1209. package/src/app/lib/server/handoff-config-project.ts +104 -0
  1210. package/src/app/lib/server/mcp-oauth-connector.ts +269 -0
  1211. package/src/app/lib/server/node-tsx-worker-launcher.cjs +32 -0
  1212. package/src/app/lib/server/oauth-state.ts +83 -0
  1213. package/src/app/lib/server/passphrase.ts +121 -0
  1214. package/src/app/lib/server/pattern-api-map.ts +123 -0
  1215. package/src/app/lib/server/playground-chat.ts +1890 -0
  1216. package/src/app/lib/server/public-api-paths.ts +34 -0
  1217. package/src/app/lib/server/reference-material-generator.ts +341 -0
  1218. package/src/app/lib/server/reference-material-ids.ts +8 -0
  1219. package/src/app/lib/server/reference-material-persist.ts +25 -0
  1220. package/src/app/lib/server/reference-material-schedule.ts +13 -0
  1221. package/src/app/lib/server/registry-cache.ts +110 -0
  1222. package/src/app/lib/server/request-public-url.ts +19 -0
  1223. package/src/app/lib/server/runtime-config.ts +43 -0
  1224. package/src/app/lib/server/s3-assets.ts +188 -0
  1225. package/src/app/lib/server/sanity-connection.ts +176 -0
  1226. package/src/app/lib/server/sanity-oauth.ts +34 -0
  1227. package/src/app/lib/server/scaffold-args.ts +392 -0
  1228. package/src/app/lib/server/secret-box.ts +85 -0
  1229. package/src/app/lib/server/serverless-chromium.ts +93 -0
  1230. package/src/app/lib/server/share-link-token.ts +106 -0
  1231. package/src/app/lib/server/site-protection.ts +145 -0
  1232. package/src/app/lib/server/spawn-tsx-worker.ts +47 -0
  1233. package/src/app/lib/server/store-image-asset.ts +220 -0
  1234. package/src/app/lib/server/token-freshness.ts +23 -0
  1235. package/src/app/lib/server/unlock-cookie.ts +70 -0
  1236. package/src/app/lib/server/upload-asset-to-library.ts +128 -0
  1237. package/src/app/lib/server/url-extract.ts +117 -0
  1238. package/src/app/lib/server/voice-audit.ts +209 -0
  1239. package/src/app/lib/set-at-args-path.ts +36 -0
  1240. package/src/app/lib/site-gate.ts +374 -0
  1241. package/src/app/lib/slot-capabilities.ts +487 -0
  1242. package/src/app/lib/source-copy.ts +295 -0
  1243. package/src/app/lib/storage/artifact-images.ts +225 -0
  1244. package/src/app/lib/storage/capture-artifacts.ts +109 -0
  1245. package/src/app/lib/swap-image-src.ts +121 -0
  1246. package/src/app/lib/sync-auth.ts +124 -0
  1247. package/src/app/lib/tool-payload.ts +101 -0
  1248. package/src/app/lib/turn-log.ts +78 -0
  1249. package/src/app/lib/url-safety.ts +46 -0
  1250. package/src/app/lib/utils.ts +35 -0
  1251. package/src/app/lib/workbench-level.ts +56 -0
  1252. package/src/app/middleware-hook.mjs +2 -0
  1253. package/src/app/next-env.d.ts +6 -0
  1254. package/src/app/next.config.mjs +355 -0
  1255. package/src/app/postcss.config.mjs +8 -0
  1256. package/src/app/proxy.ts +133 -0
  1257. package/src/app/public/assets/css/preview.css +27 -0
  1258. package/src/app/public/assets/design/blocks/callout-cta.jpg +0 -0
  1259. package/src/app/public/assets/design/blocks/carousel.png +0 -0
  1260. package/src/app/public/assets/design/blocks/container.png +0 -0
  1261. package/src/app/public/assets/design/blocks/customer-stories.jpg +0 -0
  1262. package/src/app/public/assets/design/blocks/faq.jpg +0 -0
  1263. package/src/app/public/assets/design/blocks/features-comparison.jpg +0 -0
  1264. package/src/app/public/assets/design/blocks/table.jpg +0 -0
  1265. package/src/app/public/assets/images/blocks.svg +150 -0
  1266. package/src/app/public/assets/images/check-circle.svg +10 -0
  1267. package/src/app/public/assets/images/colors.svg +186 -0
  1268. package/src/app/public/assets/images/components.png +0 -0
  1269. package/src/app/public/assets/images/components.svg +183 -0
  1270. package/src/app/public/assets/images/illustration-sample-2.svg +102 -0
  1271. package/src/app/public/assets/images/illustration-sample-3.svg +124 -0
  1272. package/src/app/public/assets/images/illustration-sample-bw-1.svg +84 -0
  1273. package/src/app/public/assets/images/illustration-sample-bw-2.svg +88 -0
  1274. package/src/app/public/assets/images/illustration-sample-bw-3.svg +125 -0
  1275. package/src/app/public/assets/images/illustration-sample.svg +110 -0
  1276. package/src/app/public/assets/images/typography.svg +279 -0
  1277. package/src/app/public/assets/images/usage-correct.png +0 -0
  1278. package/src/app/public/assets/images/usage-wrong.png +0 -0
  1279. package/src/app/public/assets/images/x-circle.svg +10 -0
  1280. package/src/app/public/assets/js/preview.js +90 -0
  1281. package/src/app/public/assets/svg/activity.svg +1 -0
  1282. package/src/app/public/assets/svg/add.svg +1 -0
  1283. package/src/app/public/assets/svg/airplay.svg +1 -0
  1284. package/src/app/public/assets/svg/alert-circle.svg +1 -0
  1285. package/src/app/public/assets/svg/alert-octagon.svg +1 -0
  1286. package/src/app/public/assets/svg/alert-triangle.svg +1 -0
  1287. package/src/app/public/assets/svg/align-center.svg +1 -0
  1288. package/src/app/public/assets/svg/align-justify.svg +1 -0
  1289. package/src/app/public/assets/svg/align-left.svg +1 -0
  1290. package/src/app/public/assets/svg/arrow-down-circle.svg +1 -0
  1291. package/src/app/public/assets/svg/arrow-left-circle.svg +1 -0
  1292. package/src/app/public/assets/svg/arrow-right-circle.svg +1 -0
  1293. package/src/app/public/assets/svg/arrow-right.svg +4 -0
  1294. package/src/app/public/assets/svg/arrow-up-circle.svg +1 -0
  1295. package/src/app/public/assets/svg/bell-off.svg +1 -0
  1296. package/src/app/public/assets/svg/bell.svg +1 -0
  1297. package/src/app/public/assets/svg/camera.svg +1 -0
  1298. package/src/app/public/assets/svg/cast.svg +1 -0
  1299. package/src/app/public/assets/svg/check.svg +1 -0
  1300. package/src/app/public/assets/svg/clock.svg +1 -0
  1301. package/src/app/public/assets/svg/code.svg +1 -0
  1302. package/src/app/public/assets/svg/component-accordion.svg +56 -0
  1303. package/src/app/public/assets/svg/component-alert.svg +34 -0
  1304. package/src/app/public/assets/svg/component-button.svg +63 -0
  1305. package/src/app/public/assets/svg/component-checkbox.svg +41 -0
  1306. package/src/app/public/assets/svg/component-input.svg +30 -0
  1307. package/src/app/public/assets/svg/component-modal.svg +63 -0
  1308. package/src/app/public/assets/svg/component-pagination.svg +82 -0
  1309. package/src/app/public/assets/svg/component-radio.svg +15 -0
  1310. package/src/app/public/assets/svg/component-select.svg +48 -0
  1311. package/src/app/public/assets/svg/component-switch.svg +6 -0
  1312. package/src/app/public/assets/svg/component-table.svg +45 -0
  1313. package/src/app/public/assets/svg/component-tabs.svg +34 -0
  1314. package/src/app/public/assets/svg/component-tooltip.svg +60 -0
  1315. package/src/app/public/assets/svg/component.svg +48 -0
  1316. package/src/app/public/assets/svg/copy.svg +1 -0
  1317. package/src/app/public/assets/svg/delivery.svg +1 -0
  1318. package/src/app/public/assets/svg/download.svg +1 -0
  1319. package/src/app/public/assets/svg/file-jpg.svg +20 -0
  1320. package/src/app/public/assets/svg/file-svg.svg +31 -0
  1321. package/src/app/public/assets/svg/file-zip.svg +24 -0
  1322. package/src/app/public/assets/svg/hero-brand-assets.svg +44 -0
  1323. package/src/app/public/assets/svg/hero-colors.svg +10 -0
  1324. package/src/app/public/assets/svg/hero-components.svg +68 -0
  1325. package/src/app/public/assets/svg/hero-design.svg +20 -0
  1326. package/src/app/public/assets/svg/hero-effects.svg +1 -0
  1327. package/src/app/public/assets/svg/illustration-sample.svg +82 -0
  1328. package/src/app/public/assets/svg/image.svg +8 -0
  1329. package/src/app/public/assets/svg/link.svg +1 -0
  1330. package/src/app/public/assets/svg/logo.svg +8 -0
  1331. package/src/app/public/assets/svg/moon.svg +1 -0
  1332. package/src/app/public/assets/svg/motiv-logo-dark-example.svg +11 -0
  1333. package/src/app/public/assets/svg/motiv-logo-example.svg +11 -0
  1334. package/src/app/public/assets/svg/plus-circle.svg +1 -0
  1335. package/src/app/public/assets/svg/react.svg +10 -0
  1336. package/src/app/public/assets/svg/search-laptop.svg +20 -0
  1337. package/src/app/public/assets/svg/search.svg +1 -0
  1338. package/src/app/public/assets/svg/send.svg +10 -0
  1339. package/src/app/public/assets/svg/share.svg +1 -0
  1340. package/src/app/public/assets/svg/small-accordion.svg +9 -0
  1341. package/src/app/public/assets/svg/small-button.svg +9 -0
  1342. package/src/app/public/assets/svg/small-pagination.svg +14 -0
  1343. package/src/app/public/assets/svg/small-radio.svg +15 -0
  1344. package/src/app/public/assets/svg/small-select.svg +9 -0
  1345. package/src/app/public/assets/svg/small-table.svg +16 -0
  1346. package/src/app/public/assets/svg/small-toggle.svg +9 -0
  1347. package/src/app/public/assets/svg/sun.svg +1 -0
  1348. package/src/app/public/assets/svg/token-alignment.svg +5 -0
  1349. package/src/app/public/assets/svg/token-border-radius.svg +3 -0
  1350. package/src/app/public/assets/svg/token-border-width.svg +10 -0
  1351. package/src/app/public/assets/svg/token-spacing-horizontal.svg +8 -0
  1352. package/src/app/public/assets/svg/token-spacing-vertical.svg +8 -0
  1353. package/src/app/public/assets/svg/token-type-small.svg +5 -0
  1354. package/src/app/public/assets/svg/x.svg +1 -0
  1355. package/src/app/public/assets/svg/zap.svg +1 -0
  1356. package/src/app/public/favicon.ico +0 -0
  1357. package/src/app/public/fonts/readme.md +4 -0
  1358. package/src/app/public/handoff-logo.svg +38 -0
  1359. package/src/app/public/logo.svg +13 -0
  1360. package/src/app/public/openapi.yaml +1818 -0
  1361. package/src/app/public/robots.txt +0 -0
  1362. package/src/app/tsconfig.json +53 -0
  1363. package/src/app/types/middleware-hook.d.ts +10 -0
  1364. package/src/app/types/next-auth-augmentation.d.ts +20 -0
  1365. package/src/app-builder/README.md +43 -0
  1366. package/src/app-builder/build.ts +741 -0
  1367. package/src/app-builder/client-config.ts +124 -0
  1368. package/src/app-builder/config-diff/index.ts +4 -0
  1369. package/src/app-builder/config-diff/registry.ts +23 -0
  1370. package/src/app-builder/config-diff/snapshot.ts +51 -0
  1371. package/src/app-builder/config-diff/strategies/pattern.ts +80 -0
  1372. package/src/app-builder/config-diff/types.ts +36 -0
  1373. package/src/app-builder/index.ts +7 -0
  1374. package/src/app-builder/path-contract.ts +81 -0
  1375. package/src/app-builder/paths.ts +90 -0
  1376. package/src/app-builder/watchers/component.ts +72 -0
  1377. package/src/app-builder/watchers/utils.ts +44 -0
  1378. package/src/app-builder/watchers.ts +345 -0
  1379. package/src/app-builder/websocket.ts +72 -0
  1380. package/src/cache/README.md +49 -0
  1381. package/src/cache/build-cache.ts +567 -0
  1382. package/src/cache/file-state.ts +170 -0
  1383. package/src/cache/index.ts +46 -0
  1384. package/src/cache/push-state.ts +201 -0
  1385. package/src/cli/README.md +12 -0
  1386. package/src/cli/create.ts +366 -0
  1387. package/src/cli/eject.ts +93 -0
  1388. package/src/cli/fetch-design-md.ts +60 -0
  1389. package/src/cli/figma-audit.ts +76 -0
  1390. package/src/cli/init-claude-core.ts +111 -0
  1391. package/src/cli/make.ts +203 -0
  1392. package/src/cli/scaffold.ts +651 -0
  1393. package/src/cli/sync/apply-declaration-pull.ts +257 -0
  1394. package/src/cli/sync/apply-pull.ts +223 -0
  1395. package/src/cli/sync/cli-auth-store.ts +51 -0
  1396. package/src/cli/sync/collect-build-artifacts.ts +159 -0
  1397. package/src/cli/sync/collect-referenced-images.ts +204 -0
  1398. package/src/cli/sync/declaration-patch.ts +192 -0
  1399. package/src/cli/sync/hash.ts +12 -0
  1400. package/src/cli/sync/open-browser.ts +37 -0
  1401. package/src/cli/sync/push-provenance.ts +109 -0
  1402. package/src/cli/sync/push-registry-content.ts +1025 -0
  1403. package/src/cli/sync/push-shared-assets.ts +62 -0
  1404. package/src/cli/sync/resolve-declaration-payload.ts +231 -0
  1405. package/src/cli/sync/resolve-declaration.ts +18 -0
  1406. package/src/cli/sync/run-cli-login.ts +110 -0
  1407. package/src/cli/sync/run-history-purge.ts +142 -0
  1408. package/src/cli/sync/run-pull.ts +112 -0
  1409. package/src/cli/sync/run-push.ts +702 -0
  1410. package/src/cli/sync/run-sync-status.ts +37 -0
  1411. package/src/cli/sync/sync-remote-env.ts +64 -0
  1412. package/src/cli/sync/sync-state.ts +42 -0
  1413. package/src/cli/tokens/ensure-default-brand.ts +115 -0
  1414. package/src/cli/tokens/migrate-legacy.ts +261 -0
  1415. package/src/cli/tokens/parse-css-brands.ts +208 -0
  1416. package/src/cli/tokens/transform.ts +134 -0
  1417. package/src/cli.ts +62 -0
  1418. package/src/commands/README.md +25 -0
  1419. package/src/commands/audit/figma-components.ts +37 -0
  1420. package/src/commands/build/app.ts +32 -0
  1421. package/src/commands/build/components.ts +25 -0
  1422. package/src/commands/build/hubspot.ts +267 -0
  1423. package/src/commands/dev/index.ts +20 -0
  1424. package/src/commands/eject/config.ts +20 -0
  1425. package/src/commands/eject/pages.ts +20 -0
  1426. package/src/commands/eject/theme.ts +20 -0
  1427. package/src/commands/fetch/index.ts +20 -0
  1428. package/src/commands/history-purge.ts +67 -0
  1429. package/src/commands/index.ts +67 -0
  1430. package/src/commands/init/index.ts +17 -0
  1431. package/src/commands/init/vercel.ts +112 -0
  1432. package/src/commands/init-claude.ts +61 -0
  1433. package/src/commands/login.ts +39 -0
  1434. package/src/commands/logout.ts +22 -0
  1435. package/src/commands/make/component.ts +34 -0
  1436. package/src/commands/make/page.ts +47 -0
  1437. package/src/commands/make/template.ts +47 -0
  1438. package/src/commands/mcp-init.ts +111 -0
  1439. package/src/commands/mcp-token.ts +32 -0
  1440. package/src/commands/prepare-runtime.ts +39 -0
  1441. package/src/commands/pull.ts +28 -0
  1442. package/src/commands/push-all.ts +202 -0
  1443. package/src/commands/push-assets.ts +52 -0
  1444. package/src/commands/push-tokens.ts +52 -0
  1445. package/src/commands/push.ts +91 -0
  1446. package/src/commands/scaffold/index.ts +22 -0
  1447. package/src/commands/start/index.ts +20 -0
  1448. package/src/commands/sync-status.ts +21 -0
  1449. package/src/commands/tokens-build.ts +118 -0
  1450. package/src/commands/types.ts +6 -0
  1451. package/src/commands/utils.ts +21 -0
  1452. package/src/commands/validate/components.ts +27 -0
  1453. package/src/commands/validate.ts +189 -0
  1454. package/src/commands/vercel-build.ts +96 -0
  1455. package/src/config/README.md +32 -0
  1456. package/src/config/declaration-module-load.ts +74 -0
  1457. package/src/config/defaults.ts +78 -0
  1458. package/src/config/helpers.ts +43 -0
  1459. package/src/config/index.ts +16 -0
  1460. package/src/config/loader.ts +131 -0
  1461. package/src/config/normalizers/declaration.ts +180 -0
  1462. package/src/config/normalizers/pattern.ts +56 -0
  1463. package/src/config/runtime.ts +426 -0
  1464. package/src/config/validator.ts +24 -0
  1465. package/src/declarations/codegen.ts +367 -0
  1466. package/src/declarations/helpers.ts +36 -0
  1467. package/src/declarations/index.ts +20 -0
  1468. package/src/declarations/types.ts +214 -0
  1469. package/src/figma/component-linking.ts +1415 -0
  1470. package/src/figma/image-fills.ts +247 -0
  1471. package/src/generated/build-meta.ts +8 -0
  1472. package/src/index.d.ts +13 -0
  1473. package/src/index.ts +369 -0
  1474. package/src/pipeline/README.md +21 -0
  1475. package/src/pipeline/archive.ts +75 -0
  1476. package/src/pipeline/components.ts +9 -0
  1477. package/src/pipeline/documentation.ts +77 -0
  1478. package/src/pipeline/figma.ts +173 -0
  1479. package/src/pipeline/hubspot/config.ts +288 -0
  1480. package/src/pipeline/hubspot/emit.ts +385 -0
  1481. package/src/pipeline/index.ts +38 -0
  1482. package/src/pipeline/patterns.ts +12 -0
  1483. package/src/pipeline/styles.ts +154 -0
  1484. package/src/pipeline/validation.ts +25 -0
  1485. package/src/stacks/bootstrap-handlebars.md +117 -0
  1486. package/src/stacks/react-scss.md +126 -0
  1487. package/src/stacks/react-tailwind.md +123 -0
  1488. package/src/stacks/tailwind-handlebars.md +142 -0
  1489. package/src/transformers/README.md +19 -0
  1490. package/src/transformers/docgen/index.ts +305 -0
  1491. package/src/transformers/plugins/csf-render.ts +485 -0
  1492. package/src/transformers/plugins/handlebars-previews.ts +194 -0
  1493. package/src/transformers/plugins/index.ts +14 -0
  1494. package/src/transformers/plugins/slot-probe-candidates.ts +386 -0
  1495. package/src/transformers/plugins/slot-probe.ts +366 -0
  1496. package/src/transformers/plugins/ssr-render.ts +622 -0
  1497. package/src/transformers/plugins.ts +17 -0
  1498. package/src/transformers/preview/component/api.ts +175 -0
  1499. package/src/transformers/preview/component/artifacts.ts +112 -0
  1500. package/src/transformers/preview/component/build-shared-bundles.ts +453 -0
  1501. package/src/transformers/preview/component/builder.ts +754 -0
  1502. package/src/transformers/preview/component/css.ts +253 -0
  1503. package/src/transformers/preview/component/field-annotations.ts +400 -0
  1504. package/src/transformers/preview/component/html.ts +96 -0
  1505. package/src/transformers/preview/component/javascript.ts +182 -0
  1506. package/src/transformers/preview/component/normalizer.ts +83 -0
  1507. package/src/transformers/preview/component/playwright-shared.ts +183 -0
  1508. package/src/transformers/preview/component/preview-assets.ts +158 -0
  1509. package/src/transformers/preview/component/preview-merge.ts +95 -0
  1510. package/src/transformers/preview/component/preview-select.ts +184 -0
  1511. package/src/transformers/preview/component/preview-server.ts +128 -0
  1512. package/src/transformers/preview/component/preview-validation.ts +255 -0
  1513. package/src/transformers/preview/component/previews.ts +12 -0
  1514. package/src/transformers/preview/component/screenshot.ts +306 -0
  1515. package/src/transformers/preview/component/serialized-elements.ts +124 -0
  1516. package/src/transformers/preview/component/summary.ts +54 -0
  1517. package/src/transformers/preview/component.ts +31 -0
  1518. package/src/transformers/preview/height-reporter.ts +37 -0
  1519. package/src/transformers/preview/pattern/api.ts +83 -0
  1520. package/src/transformers/preview/pattern/builder.ts +192 -0
  1521. package/src/transformers/preview/pattern/html.ts +115 -0
  1522. package/src/transformers/preview/slots.ts +105 -0
  1523. package/src/transformers/preview/types.ts +302 -0
  1524. package/src/transformers/types.ts +68 -0
  1525. package/src/transformers/utils/build.ts +85 -0
  1526. package/src/transformers/utils/csf.ts +48 -0
  1527. package/src/transformers/utils/handlebars.ts +92 -0
  1528. package/src/transformers/utils/html.ts +44 -0
  1529. package/src/transformers/utils/index.ts +27 -0
  1530. package/src/transformers/utils/module.ts +54 -0
  1531. package/src/transformers/utils/schema-loader.ts +68 -0
  1532. package/src/transformers/utils/schema.ts +569 -0
  1533. package/src/transformers/utils/string.ts +55 -0
  1534. package/src/transformers/utils/svg-sprite.ts +139 -0
  1535. package/src/transformers/utils/usage.ts +317 -0
  1536. package/src/transformers/utils/vite-logger.ts +33 -0
  1537. package/src/transformers/validation/runner.ts +351 -0
  1538. package/src/transformers/vite-config.ts +21 -0
  1539. package/src/types/README.md +12 -0
  1540. package/src/types/config.ts +482 -0
  1541. package/src/types/font.ts +3 -0
  1542. package/src/types/handoff-sync.ts +145 -0
  1543. package/src/types/history-purge.ts +141 -0
  1544. package/src/types/icon.ts +8 -0
  1545. package/src/types/preview.ts +136 -0
  1546. package/src/types/validation.ts +213 -0
  1547. package/src/utils/README.md +14 -0
  1548. package/src/utils/asset-upload-limits.ts +157 -0
  1549. package/src/utils/design-md.ts +152 -0
  1550. package/src/utils/duration.ts +3 -0
  1551. package/src/utils/filter.ts +134 -0
  1552. package/src/utils/fs.ts +35 -0
  1553. package/src/utils/index.ts +6 -0
  1554. package/src/utils/line-diff.ts +80 -0
  1555. package/src/utils/logger.ts +176 -0
  1556. package/src/utils/path.ts +61 -0
  1557. package/src/utils/port.ts +46 -0
  1558. package/src/utils/rich-text.ts +1202 -0
  1559. package/src/validators/axe.ts +288 -0
  1560. package/src/validators/contrast.ts +270 -0
  1561. package/src/validators/index.ts +42 -0
  1562. package/src/validators/schema.ts +191 -0
  1563. package/tailwind.config.ts +96 -0
  1564. package/templates/default/README.md.tpl +15 -0
  1565. package/templates/default/components/button/Button.jsx.tpl +64 -0
  1566. package/templates/default/components/button/Button.tsx.tpl +92 -0
  1567. package/templates/default/components/button/button.react.handoff.js.tpl +31 -0
  1568. package/templates/default/components/button/button.react.handoff.ts.tpl +31 -0
  1569. package/templates/default/env.tpl +2 -0
  1570. package/templates/default/gitignore.tpl +7 -0
  1571. package/templates/default/handoff.config.js.tpl +216 -0
  1572. package/templates/default/handoff.config.ts.tpl +196 -0
  1573. package/templates/default/handoff.config.with-examples.js.tpl +215 -0
  1574. package/templates/default/handoff.config.with-examples.ts.tpl +208 -0
  1575. package/templates/default/package.json.tpl +19 -0
  1576. package/templates/default/tsconfig.json.tpl +24 -0
  1577. package/templates/workflows/hubspot-deploy.yml +134 -0
  1578. package/tsconfig.json +30 -0
@@ -0,0 +1,1202 @@
1
+ /**
2
+ * HTML ↔ Portable Text ↔ copy — one module, because six call sites have to agree.
3
+ *
4
+ * Portable Text is the canonical stored shape for `editorType: 'richtext'` args (roadmap 7). HTML is
5
+ * derived at three boundaries — render (canvas / SSR / Handlebars), the MCP wire, and agent-facing
6
+ * Markdown — so every one of those has to produce the *same* bytes from the same blocks, or a page saves
7
+ * a version it did not change.
8
+ *
9
+ * **Why this lives in `src/utils` and not `src/app/lib`.** `preview-validation.ts` measures the same
10
+ * values on the server side and sits under `src/transformers`, which is compiled into `dist` while
11
+ * `src/app` is excluded from that build (`tsconfig.json`). A single measurement shared by the rail, the
12
+ * inline overlay, the submit gate and the registry write can therefore only live on this side of the
13
+ * line. It is pure and isomorphic — `node-html-parser` and nothing else — because both editor commit
14
+ * sites run in the browser.
15
+ *
16
+ * **Why not `@portabletext/block-tools`.** It needs `@sanity/schema`, a compiled schema and `jsdom`:
17
+ * server-only, and the commit sites are not.
18
+ *
19
+ * **Why a hand-written serializer rather than `@portabletext/to-html`.** Byte-stability is the whole
20
+ * point — the `content/previews` facet hash moves when the derived HTML moves, and a version that says
21
+ * "changed" when nobody changed anything is worse than no history at all. A serializer we own cannot
22
+ * drift under a patch release, and it costs one dependency less in the browser bundle.
23
+ *
24
+ * **Losslessness is by construction, not by care.** Anything the block schema cannot represent —
25
+ * `<table>`, `<iframe>`, an attributed `<div>`, a `<span class=…>`, an unknown tag — becomes a
26
+ * `{_type:'html'}` block holding the original markup verbatim. The React registry's `blockContent`
27
+ * and `titleBlockContent` both already declare an `html` member, so it survives publication too. No round
28
+ * trip silently deletes an author's markup.
29
+ *
30
+ * **Keys are positional and deterministic** (`b0`, `b0s1`, `b0d0`), never uuids or content hashes:
31
+ * otherwise every save re-keys every block and churns the previews facet into fake versions.
32
+ */
33
+
34
+ import { parse, type HTMLElement as ParsedElement, type Node as ParsedNode } from 'node-html-parser';
35
+
36
+ // ─────────────────────────────────────────────────────────────────────────────
37
+ // Shape
38
+ // ─────────────────────────────────────────────────────────────────────────────
39
+
40
+ /** Block styles = the intersection of what the editor toolbar emits and what the React registry's `blockContent` accepts. */
41
+ export type PortableTextStyle = 'normal' | 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'blockquote';
42
+
43
+ /** Decorators, in the order they are always written and always nested. `underline` because the React registry declares it. */
44
+ export type PortableTextDecorator = 'strong' | 'em' | 'underline' | 'code';
45
+
46
+ export interface PortableTextSpan {
47
+ _type: 'span';
48
+ _key: string;
49
+ text: string;
50
+ /** Decorators in {@link DECORATOR_ORDER}, then at most one `markDefs` key. */
51
+ marks: string[];
52
+ }
53
+
54
+ /** `target`/`rel` are kept because the React registry's `linkAnnotation` has a home for them, and losing `_blank` is invisible until a demo click navigates away. */
55
+ export interface PortableTextLink {
56
+ _type: 'link';
57
+ _key: string;
58
+ href: string;
59
+ target?: string;
60
+ rel?: string;
61
+ }
62
+
63
+ export interface PortableTextBlock {
64
+ _type: 'block';
65
+ _key: string;
66
+ style: PortableTextStyle;
67
+ listItem?: 'bullet' | 'number';
68
+ /** 1-based nesting depth; only present on list items. Nested lists are flattened in and re-nested out. */
69
+ level?: number;
70
+ children: PortableTextSpan[];
71
+ markDefs: PortableTextLink[];
72
+ }
73
+
74
+ /** The escape hatch. Holds the original markup verbatim; never synthesised, only ever carried. */
75
+ export interface PortableTextHtmlBlock {
76
+ _type: 'html';
77
+ _key: string;
78
+ html: string;
79
+ }
80
+
81
+ export type PortableTextNode = PortableTextBlock | PortableTextHtmlBlock;
82
+ export type PortableText = PortableTextNode[];
83
+
84
+ /** The one order decorators are written in, so two equal values serialize to equal bytes. */
85
+ const DECORATOR_ORDER: PortableTextDecorator[] = ['strong', 'em', 'underline', 'code'];
86
+
87
+ const DECORATOR_TAG: Record<PortableTextDecorator, string> = {
88
+ strong: 'strong',
89
+ em: 'em',
90
+ underline: 'u',
91
+ code: 'code',
92
+ };
93
+
94
+ // ─────────────────────────────────────────────────────────────────────────────
95
+ // HTML → copy (the counting path)
96
+ // ─────────────────────────────────────────────────────────────────────────────
97
+
98
+ /**
99
+ * A handful of named entities, plus numeric escapes.
100
+ *
101
+ * Deliberately not a full entity table: this exists to *count* characters, and the long tail of named entities
102
+ * contributes one character each whether it is decoded or not, so getting it wrong costs nothing. `&nbsp;` is the
103
+ * one that matters, because rich-text editors emit it constantly and leaving it encoded would count 6 for a space.
104
+ */
105
+ const NAMED_ENTITIES: Record<string, string> = {
106
+ amp: '&',
107
+ lt: '<',
108
+ gt: '>',
109
+ quot: '"',
110
+ apos: "'",
111
+ nbsp: ' ',
112
+ };
113
+
114
+ /**
115
+ * Tags that sit *inside* a run of text, so removing them must not introduce a space.
116
+ *
117
+ * The distinction matters for counting. Turning every tag into a space fuses nothing but **invents** one:
118
+ * `<b>Lorem ipsum dolor sit amet</b>,` reads back as `Lorem ipsum dolor sit amet ,` — a space before the comma, one
119
+ * character too many, and it happens once per inline tag adjacent to punctuation. Caught by measuring accordion's
120
+ * own shipped copy, which reported 184 for 183 characters of text (2026-08-11).
121
+ *
122
+ * `br` is deliberately absent: it is a visible break, so it *should* count as a space.
123
+ */
124
+ const INLINE_TAGS = new Set(
125
+ ('a abbr b bdi bdo cite code data dfn em i kbd mark q rp rt ruby s samp small span strong sub sup time u var wbr')
126
+ .split(' ')
127
+ );
128
+
129
+ /** Rich-text HTML → the copy a reader sees, for counting purposes. */
130
+ export function richTextToCopy(html: string): string {
131
+ return (
132
+ html
133
+ // Script/style bodies are not copy. Richtext should never carry them; cheap insurance if it does.
134
+ .replace(/<(script|style)\b[^>]*>[\s\S]*?<\/\1>/gi, '')
135
+ .replace(/<!--[\s\S]*?-->/g, '')
136
+ /**
137
+ * A **block** boundary is a word boundary — `<p>a</p><p>b</p>` must not count as one 2-character word — while
138
+ * an inline boundary is not one. See `INLINE_TAGS`.
139
+ */
140
+ .replace(/<\/?([a-z][a-z0-9-]*)\b[^>]*>/gi, (_, name: string) =>
141
+ INLINE_TAGS.has(name.toLowerCase()) ? '' : ' '
142
+ )
143
+ // Anything left that looked like a tag but named nothing (`<>`, a stray `<`), dropped without a space.
144
+ .replace(/<[^>]*>/g, '')
145
+ .replace(/&#x([0-9a-f]+);/gi, (_, hex: string) => String.fromCodePoint(parseInt(hex, 16)))
146
+ .replace(/&#(\d+);/g, (_, dec: string) => String.fromCodePoint(Number(dec)))
147
+ .replace(/&([a-z]+);/gi, (whole, name: string) => NAMED_ENTITIES[name.toLowerCase()] ?? whole)
148
+ // Collapse the whitespace the tag substitution just introduced, so the count matches what is read.
149
+ .replace(/\s+/g, ' ')
150
+ .trim()
151
+ );
152
+ }
153
+
154
+ /**
155
+ * Decode exactly what {@link richTextToCopy} decodes, and **leave every other entity reference alone**.
156
+ *
157
+ * That asymmetry is load-bearing in both directions. Decoding `&mdash;` here would put a literal em dash in the
158
+ * span, `richTextToCopy` would still report `&mdash;`, and the two measurements — the counter in the rail and the
159
+ * gate at submit — would disagree by six characters. Leaving it encoded, and refusing to re-escape it on the way
160
+ * out, also makes the round trip byte-identical for the long tail nobody enumerated.
161
+ *
162
+ * `&nbsp;` decodes to a real non-breaking space rather than `richTextToCopy`'s plain one: `\s` matches U+00A0, so
163
+ * the collapse step in {@link portableTextToPlainText} lands on the same character anyway, and the markup keeps a
164
+ * space an author deliberately made non-breaking.
165
+ */
166
+ function decodeEntities(raw: string): string {
167
+ return raw
168
+ .replace(/&#x([0-9a-f]+);/gi, (_, hex: string) => String.fromCodePoint(parseInt(hex, 16)))
169
+ .replace(/&#(\d+);/g, (_, dec: string) => String.fromCodePoint(Number(dec)))
170
+ .replace(/&([a-z]+);/gi, (whole, name: string) => {
171
+ const key = name.toLowerCase();
172
+ if (key === 'nbsp') return '\u00A0';
173
+ return NAMED_ENTITIES[key] ?? whole;
174
+ });
175
+ }
176
+
177
+ /** `&` is only escaped when it does NOT already open an entity reference — see {@link decodeEntities}. */
178
+ const BARE_AMPERSAND = /&(?!(?:#\d+|#x[0-9a-f]+|[a-z][a-z0-9]*);)/gi;
179
+
180
+ function escapeText(text: string): string {
181
+ return text
182
+ .replace(BARE_AMPERSAND, '&amp;')
183
+ .replace(/</g, '&lt;')
184
+ .replace(/>/g, '&gt;')
185
+ .replace(/\u00A0/g, '&nbsp;')
186
+ // `<br>` and not `<br/>`: it is what `document.execCommand` writes, so a value the editor produced and a
187
+ // value we produced are the same bytes.
188
+ .replace(/\n/g, '<br>');
189
+ }
190
+
191
+ function escapeAttribute(value: string): string {
192
+ return value
193
+ .replace(BARE_AMPERSAND, '&amp;')
194
+ .replace(/</g, '&lt;')
195
+ .replace(/>/g, '&gt;')
196
+ .replace(/"/g, '&quot;');
197
+ }
198
+
199
+ // ─────────────────────────────────────────────────────────────────────────────
200
+ // HTML → Portable Text
201
+ // ─────────────────────────────────────────────────────────────────────────────
202
+
203
+ const NODE_ELEMENT = 1;
204
+ const NODE_TEXT = 3;
205
+
206
+ const HEADING_STYLES: Record<string, PortableTextStyle> = {
207
+ h1: 'h1',
208
+ h2: 'h2',
209
+ h3: 'h3',
210
+ h4: 'h4',
211
+ h5: 'h5',
212
+ h6: 'h6',
213
+ };
214
+
215
+ /**
216
+ * Tags handled by the block walker rather than the inline walker.
217
+ *
218
+ * Anything here that is not `p`/`div`/heading/`blockquote`/`ul`/`ol` reaches the escape hatch as its own block,
219
+ * which is the point: a `<table>` between two paragraphs stays a table between two paragraphs.
220
+ */
221
+ const BLOCK_TAGS = new Set([
222
+ 'p', 'div', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'blockquote', 'ul', 'ol',
223
+ 'table', 'thead', 'tbody', 'tfoot', 'tr', 'td', 'th', 'caption', 'colgroup',
224
+ 'figure', 'figcaption', 'hr', 'pre', 'section', 'article', 'aside', 'header', 'footer',
225
+ 'nav', 'main', 'address', 'form', 'fieldset', 'dl', 'dt', 'dd', 'li',
226
+ 'script', 'style', 'noscript', 'template',
227
+ ]);
228
+
229
+ /** Thrown, caught, and turned into a `{_type:'html'}` block. Never escapes this module. */
230
+ class Unrepresentable extends Error {}
231
+
232
+ interface DraftSpan {
233
+ text: string;
234
+ decorators: PortableTextDecorator[];
235
+ link?: { href: string; target?: string; rel?: string };
236
+ }
237
+
238
+ type DraftBlock =
239
+ | { kind: 'block'; style: PortableTextStyle; listItem?: 'bullet' | 'number'; level?: number; spans: DraftSpan[] }
240
+ | { kind: 'html'; html: string };
241
+
242
+ function tagOf(node: ParsedNode): string {
243
+ return ((node as ParsedElement).rawTagName ?? '').toLowerCase();
244
+ }
245
+
246
+ function attributeNames(el: ParsedElement): string[] {
247
+ return Object.keys(el.rawAttributes ?? {});
248
+ }
249
+
250
+ /**
251
+ * A `style` attribute is kept only when **every** declaration in it maps to a decorator.
252
+ *
253
+ * `font-weight: normal` inside a bold run is a real instruction and we have nowhere to put it, so it takes the
254
+ * whole block to the escape hatch rather than quietly rendering bold. `execCommand` emits all three spellings
255
+ * below, which is why they are here and not in the tag table.
256
+ */
257
+ function decoratorsFromStyle(style: string): PortableTextDecorator[] | null {
258
+ const found: PortableTextDecorator[] = [];
259
+ for (const declaration of style.split(';')) {
260
+ const trimmed = declaration.trim();
261
+ if (!trimmed) continue;
262
+ const [rawProp, ...rest] = trimmed.split(':');
263
+ const prop = rawProp.trim().toLowerCase();
264
+ const value = rest.join(':').trim().toLowerCase();
265
+ if ((prop === 'text-decoration' || prop === 'text-decoration-line') && value.includes('underline')) {
266
+ found.push('underline');
267
+ } else if (prop === 'font-weight' && /^(bold|bolder|[6-9]00)$/.test(value)) {
268
+ found.push('strong');
269
+ } else if (prop === 'font-style' && /^(italic|oblique)$/.test(value)) {
270
+ found.push('em');
271
+ } else {
272
+ return null;
273
+ }
274
+ }
275
+ return found;
276
+ }
277
+
278
+ function withDecorator(
279
+ decorators: PortableTextDecorator[],
280
+ added: PortableTextDecorator[]
281
+ ): PortableTextDecorator[] {
282
+ const set = new Set([...decorators, ...added]);
283
+ return DECORATOR_ORDER.filter((d) => set.has(d));
284
+ }
285
+
286
+ /**
287
+ * Inline walk. Throws {@link Unrepresentable} rather than guessing, so the caller can hand the whole element to
288
+ * the escape hatch with its markup intact.
289
+ */
290
+ function walkInline(
291
+ nodes: ParsedNode[],
292
+ decorators: PortableTextDecorator[],
293
+ link: DraftSpan['link'],
294
+ out: DraftSpan[]
295
+ ): void {
296
+ for (const node of nodes) {
297
+ if (node.nodeType === NODE_TEXT) {
298
+ out.push({ text: decodeEntities((node as unknown as { rawText: string }).rawText), decorators, link });
299
+ continue;
300
+ }
301
+ if (node.nodeType !== NODE_ELEMENT) {
302
+ // A comment. `richTextToCopy` drops them without a space, so dropping them here keeps the two measurements
303
+ // equal; it is also the only thing this module discards, and it is not markup a reader ever sees.
304
+ continue;
305
+ }
306
+ const el = node as ParsedElement;
307
+ const tag = tagOf(el);
308
+ const attrs = attributeNames(el);
309
+
310
+ if (tag === 'br') {
311
+ if (attrs.length) throw new Unrepresentable();
312
+ out.push({ text: '\n', decorators, link });
313
+ continue;
314
+ }
315
+
316
+ if (BLOCK_TAGS.has(tag)) throw new Unrepresentable();
317
+
318
+ if (tag === 'a') {
319
+ if (link) throw new Unrepresentable();
320
+ if (attrs.some((a) => !['href', 'target', 'rel'].includes(a.toLowerCase()))) throw new Unrepresentable();
321
+ const href = el.getAttribute('href');
322
+ if (typeof href !== 'string') throw new Unrepresentable();
323
+ const next: DraftSpan['link'] = { href };
324
+ const target = el.getAttribute('target');
325
+ const rel = el.getAttribute('rel');
326
+ if (target) next.target = target;
327
+ if (rel) next.rel = rel;
328
+ walkInline(el.childNodes, decorators, next, out);
329
+ continue;
330
+ }
331
+
332
+ // The six spellings. `execCommand` emits `<b>`/`<i>` where the schema says `strong`/`em`, and underline
333
+ // arrives as a tag OR as a style — all normalised here, once, so nothing downstream has to know.
334
+ let added: PortableTextDecorator[] | null = null;
335
+ if (tag === 'strong' || tag === 'b') added = ['strong'];
336
+ else if (tag === 'em' || tag === 'i') added = ['em'];
337
+ else if (tag === 'u') added = ['underline'];
338
+ else if (tag === 'code') added = ['code'];
339
+ else if (tag === 'span') added = [];
340
+
341
+ if (added === null) throw new Unrepresentable();
342
+
343
+ const styleAttr = el.getAttribute('style');
344
+ if (styleAttr !== undefined && styleAttr !== null) {
345
+ const fromStyle = decoratorsFromStyle(styleAttr);
346
+ if (fromStyle === null) throw new Unrepresentable();
347
+ added = [...added, ...fromStyle];
348
+ }
349
+ if (attrs.some((a) => a.toLowerCase() !== 'style')) throw new Unrepresentable();
350
+
351
+ walkInline(el.childNodes, withDecorator(decorators, added), link, out);
352
+ }
353
+ }
354
+
355
+ function sameSpanFormatting(a: DraftSpan, b: DraftSpan): boolean {
356
+ if (a.decorators.length !== b.decorators.length) return false;
357
+ if (a.decorators.some((d, i) => d !== b.decorators[i])) return false;
358
+ if (!a.link !== !b.link) return false;
359
+ if (!a.link || !b.link) return true;
360
+ return a.link.href === b.link.href && a.link.target === b.link.target && a.link.rel === b.link.rel;
361
+ }
362
+
363
+ /** Merge adjacent spans that carry the same formatting and drop the empty ones — the shape a re-parse produces. */
364
+ function normalizeSpans(spans: DraftSpan[]): DraftSpan[] {
365
+ const merged: DraftSpan[] = [];
366
+ for (const span of spans) {
367
+ if (!span.text) continue;
368
+ const last = merged[merged.length - 1];
369
+ if (last && sameSpanFormatting(last, span)) {
370
+ last.text += span.text;
371
+ continue;
372
+ }
373
+ merged.push({ ...span });
374
+ }
375
+ // Portable Text blocks always have at least one child; an empty paragraph is still a paragraph.
376
+ return merged.length ? merged : [{ text: '', decorators: [] }];
377
+ }
378
+
379
+ function inlineDraft(el: ParsedElement, style: PortableTextStyle): DraftBlock {
380
+ const spans: DraftSpan[] = [];
381
+ walkInline(el.childNodes, [], undefined, spans);
382
+ return { kind: 'block', style, spans: normalizeSpans(spans) };
383
+ }
384
+
385
+ function hasBlockChild(el: ParsedElement): boolean {
386
+ return el.childNodes.some((n) => n.nodeType === NODE_ELEMENT && BLOCK_TAGS.has(tagOf(n)));
387
+ }
388
+
389
+ /**
390
+ * Lists flatten to `listItem` + `level`, and the whole list escapes if any part of it does.
391
+ *
392
+ * All-or-nothing on purpose: an `<li>` lifted out of its `<ul>` into a raw-HTML block would render as a stray
393
+ * bullet-less line, so a list we cannot fully represent is better kept whole.
394
+ */
395
+ function walkList(el: ParsedElement, ordered: boolean, level: number, out: DraftBlock[]): void {
396
+ if (attributeNames(el).length) throw new Unrepresentable();
397
+ for (const child of el.childNodes) {
398
+ if (child.nodeType === NODE_TEXT) {
399
+ if ((child as unknown as { rawText: string }).rawText.trim()) throw new Unrepresentable();
400
+ continue;
401
+ }
402
+ if (child.nodeType !== NODE_ELEMENT) continue;
403
+ const li = child as ParsedElement;
404
+ if (tagOf(li) !== 'li' || attributeNames(li).length) throw new Unrepresentable();
405
+
406
+ const inline: ParsedNode[] = [];
407
+ const nested: ParsedElement[] = [];
408
+ for (const node of li.childNodes) {
409
+ const isList = node.nodeType === NODE_ELEMENT && (tagOf(node) === 'ul' || tagOf(node) === 'ol');
410
+ if (isList) {
411
+ nested.push(node as ParsedElement);
412
+ continue;
413
+ }
414
+ // Copy after a nested list has nowhere to go in a flattened model — it would silently move above the
415
+ // sub-list on the way out. Escape the list instead of reordering someone's words.
416
+ if (nested.length && !(node.nodeType === NODE_TEXT && !(node as unknown as { rawText: string }).rawText.trim())) {
417
+ throw new Unrepresentable();
418
+ }
419
+ inline.push(node);
420
+ }
421
+
422
+ const spans: DraftSpan[] = [];
423
+ walkInline(inline, [], undefined, spans);
424
+ out.push({
425
+ kind: 'block',
426
+ style: 'normal',
427
+ listItem: ordered ? 'number' : 'bullet',
428
+ level,
429
+ spans: normalizeSpans(spans),
430
+ });
431
+ for (const sub of nested) walkList(sub, tagOf(sub) === 'ol', level + 1, out);
432
+ }
433
+ }
434
+
435
+ function walkBlocks(nodes: ParsedNode[], out: DraftBlock[]): void {
436
+ let run: ParsedNode[] = [];
437
+
438
+ const flushRun = () => {
439
+ if (!run.length) return;
440
+ const pending = run;
441
+ run = [];
442
+ // Whitespace between two blocks is layout, not an empty paragraph.
443
+ if (!pending.some((n) => n.nodeType !== NODE_TEXT || (n as unknown as { rawText: string }).rawText.trim())) return;
444
+ const spans: DraftSpan[] = [];
445
+ try {
446
+ walkInline(pending, [], undefined, spans);
447
+ } catch {
448
+ out.push({ kind: 'html', html: pending.map((n) => n.toString()).join('') });
449
+ return;
450
+ }
451
+ out.push({ kind: 'block', style: 'normal', spans: normalizeSpans(spans) });
452
+ };
453
+
454
+ for (const node of nodes) {
455
+ if (node.nodeType !== NODE_ELEMENT || !BLOCK_TAGS.has(tagOf(node))) {
456
+ run.push(node);
457
+ continue;
458
+ }
459
+ flushRun();
460
+ const el = node as ParsedElement;
461
+ const tag = tagOf(el);
462
+ const attributed = attributeNames(el).length > 0;
463
+
464
+ try {
465
+ if (attributed) throw new Unrepresentable();
466
+ if (tag === 'ul' || tag === 'ol') {
467
+ const items: DraftBlock[] = [];
468
+ walkList(el, tag === 'ol', 1, items);
469
+ out.push(...items);
470
+ } else if (tag === 'div') {
471
+ // A `<div>` is a line the editor made, unless it is a wrapper — in which case its children are the lines.
472
+ if (hasBlockChild(el)) walkBlocks(el.childNodes, out);
473
+ else out.push(inlineDraft(el, 'normal'));
474
+ } else if (tag === 'blockquote') {
475
+ if (hasBlockChild(el)) {
476
+ const inner: DraftBlock[] = [];
477
+ walkBlocks(el.childNodes, inner);
478
+ for (const b of inner) {
479
+ if (b.kind === 'block' && b.style === 'normal' && !b.listItem) b.style = 'blockquote';
480
+ }
481
+ out.push(...inner);
482
+ } else {
483
+ out.push(inlineDraft(el, 'blockquote'));
484
+ }
485
+ } else if (tag === 'p') {
486
+ out.push(inlineDraft(el, 'normal'));
487
+ } else if (HEADING_STYLES[tag]) {
488
+ out.push(inlineDraft(el, HEADING_STYLES[tag]));
489
+ } else {
490
+ throw new Unrepresentable();
491
+ }
492
+ } catch {
493
+ out.push({ kind: 'html', html: el.outerHTML });
494
+ }
495
+ }
496
+ flushRun();
497
+ }
498
+
499
+ function keyDrafts(drafts: DraftBlock[]): PortableText {
500
+ return drafts.map((draft, i): PortableTextNode => {
501
+ if (draft.kind === 'html') return { _type: 'html', _key: `b${i}`, html: draft.html };
502
+
503
+ const markDefs: PortableTextLink[] = [];
504
+ const keyBySignature = new Map<string, string>();
505
+ const signature = (link: NonNullable<DraftSpan['link']>) =>
506
+ JSON.stringify([link.href, link.target ?? null, link.rel ?? null]);
507
+
508
+ const children = draft.spans.map((span, j): PortableTextSpan => {
509
+ const marks: string[] = [...span.decorators];
510
+ if (span.link) {
511
+ const sig = signature(span.link);
512
+ let key = keyBySignature.get(sig);
513
+ if (!key) {
514
+ key = `b${i}d${markDefs.length}`;
515
+ keyBySignature.set(sig, key);
516
+ const def: PortableTextLink = { _type: 'link', _key: key, href: span.link.href };
517
+ if (span.link.target) def.target = span.link.target;
518
+ if (span.link.rel) def.rel = span.link.rel;
519
+ markDefs.push(def);
520
+ }
521
+ marks.push(key);
522
+ }
523
+ return { _type: 'span', _key: `b${i}s${j}`, text: span.text, marks };
524
+ });
525
+
526
+ // Property order is fixed, and `listItem`/`level` are omitted rather than set to undefined on a
527
+ // non-list block: `JSON.stringify` is what the previews facet hashes, so key order IS the value.
528
+ return draft.listItem
529
+ ? {
530
+ _type: 'block',
531
+ _key: `b${i}`,
532
+ style: draft.style,
533
+ listItem: draft.listItem,
534
+ level: draft.level ?? 1,
535
+ children,
536
+ markDefs,
537
+ }
538
+ : { _type: 'block', _key: `b${i}`, style: draft.style, children, markDefs };
539
+ });
540
+ }
541
+
542
+ /** HTML → Portable Text. Total: any input produces a value, and nothing in the input is dropped. */
543
+ export function htmlToPortableText(html: unknown): PortableText {
544
+ if (typeof html !== 'string' || !html) return [];
545
+ const drafts: DraftBlock[] = [];
546
+ walkBlocks(parse(html).childNodes, drafts);
547
+ return keyDrafts(drafts);
548
+ }
549
+
550
+ /**
551
+ * Renumber `_key`s positionally across a list of blocks assembled from more than one parse.
552
+ *
553
+ * {@link keyDrafts} numbers from `b0` on every call, so concatenating two parses collides every key — and a
554
+ * duplicate `_key` is the one thing Portable Text consumers are entitled to assume cannot happen. Applied to a
555
+ * single parse this is the identity in value (the keys are already `b0…bn`), which is why the paragraph-list
556
+ * path below can run it unconditionally.
557
+ *
558
+ * Spread-then-overwrite rather than rebuilt literals: an existing key keeps its position under spread, and
559
+ * `JSON.stringify` is what the previews facet hashes, so key ORDER is part of the value.
560
+ */
561
+ function rekeyPositionally(nodes: PortableTextNode[]): PortableText {
562
+ return nodes.map((node, i): PortableTextNode => {
563
+ if (node._type === 'html') return { ...node, _key: `b${i}` };
564
+ // `markDefs` first: the spans' `marks` reference these keys, so the rename table has to exist before them.
565
+ const renamed = new Map<string, string>();
566
+ const markDefs = (Array.isArray(node.markDefs) ? node.markDefs : []).map((def, d) => {
567
+ const key = `b${i}d${d}`;
568
+ renamed.set(def._key, key);
569
+ return { ...def, _key: key };
570
+ });
571
+ const children = (Array.isArray(node.children) ? node.children : []).map((span, j) => ({
572
+ ...span,
573
+ _key: `b${i}s${j}`,
574
+ marks: (Array.isArray(span.marks) ? span.marks : []).map((mark) => renamed.get(mark) ?? mark),
575
+ }));
576
+ return { ...node, _key: `b${i}`, children, markDefs };
577
+ });
578
+ }
579
+
580
+ /**
581
+ * A **paragraph list** — `['First paragraph.', 'Second.']`.
582
+ *
583
+ * The shape a richtext slot took before one value could hold more than one paragraph: the component's `render`
584
+ * mapped each item to its own `<p>`. It is legitimate stored content, not a mistake, which is why it is coerced
585
+ * rather than refused (roadmap 7 item 7). An EMPTY array is deliberately not one, for the same reason
586
+ * {@link isPortableText} rejects it — `[]` is indistinguishable from an empty repeater.
587
+ */
588
+ function isParagraphList(value: unknown): value is string[] {
589
+ return Array.isArray(value) && value.length > 0 && value.every((item) => typeof item === 'string');
590
+ }
591
+
592
+ /** An **explicit heading** — `{ level: 'h1', text: 'Title' }`. `tag`/`html` are the spellings the React registry's builder accepts. */
593
+ interface HeadingValue {
594
+ level?: unknown;
595
+ tag?: unknown;
596
+ text?: unknown;
597
+ html?: unknown;
598
+ }
599
+
600
+ const HEADING_KEYS = new Set(['level', 'tag', 'text', 'html']);
601
+
602
+ /**
603
+ * Tight on purpose: a plain object carrying copy and NOTHING but heading keys.
604
+ *
605
+ * A repeater row is also `{ … text … }` — a card, a stat, a nav item — and coercing one into a single heading
606
+ * block would replace a whole row with its caption. Requiring the key set to be a subset of
607
+ * {@link HEADING_KEYS} is what makes the two impossible to confuse without asking the contract.
608
+ */
609
+ function isHeadingValue(value: unknown): value is HeadingValue {
610
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
611
+ const keys = Object.keys(value as Record<string, unknown>);
612
+ if (!keys.length || !keys.every((key) => HEADING_KEYS.has(key))) return false;
613
+ const { text, html } = value as HeadingValue;
614
+ return typeof text === 'string' || typeof html === 'string';
615
+ }
616
+
617
+ const HEADING_LEVEL = /^h?([1-6])$/;
618
+
619
+ /**
620
+ * A declared level → a block style.
621
+ *
622
+ * Absent means `normal`, which is the same block a bare string produces — so `{ text: 'Title' }` and `'Title'`
623
+ * are the same rich text, and only an EXPLICIT level makes a heading. A level outside 1–6 is clamped rather
624
+ * than dropped: someone who wrote one meant "this is a heading", and the only open question is which.
625
+ */
626
+ function headingStyle(level: unknown): PortableTextStyle {
627
+ if (typeof level === 'number' && Number.isFinite(level)) {
628
+ return `h${Math.min(6, Math.max(1, Math.trunc(level)))}` as PortableTextStyle;
629
+ }
630
+ if (typeof level === 'string') {
631
+ const match = HEADING_LEVEL.exec(level.trim().toLowerCase());
632
+ if (match) return `h${match[1]}` as PortableTextStyle;
633
+ }
634
+ return 'normal';
635
+ }
636
+
637
+ /** `{ level, text }` → one styled block, with `text` parsed so inline marks survive the move. */
638
+ function headingBlocks(value: HeadingValue): PortableText {
639
+ const source = typeof value.text === 'string' ? value.text : typeof value.html === 'string' ? value.html : '';
640
+ const blocks = htmlToPortableText(source);
641
+ const style = headingStyle(value.level ?? value.tag);
642
+ if (style === 'normal') return blocks;
643
+ // Only a paragraph is promoted: a heading the copy already carries, or an escape-hatch block, outranks the
644
+ // wrapper level — the same precedence the renderer applies when markup and a target tag disagree.
645
+ return blocks.map((node) => (node._type === 'block' && node.style === 'normal' ? { ...node, style } : node));
646
+ }
647
+
648
+ // ─────────────────────────────────────────────────────────────────────────────
649
+ // Portable Text → HTML / copy / Markdown
650
+ // ─────────────────────────────────────────────────────────────────────────────
651
+
652
+ function spanHtml(span: PortableTextSpan, markDefs: PortableTextLink[]): string {
653
+ let html = escapeText(typeof span.text === 'string' ? span.text : '');
654
+ const marks = Array.isArray(span.marks) ? span.marks : [];
655
+ // Innermost first, so the nesting is `a > strong > em > u > code` every time.
656
+ for (let i = DECORATOR_ORDER.length - 1; i >= 0; i -= 1) {
657
+ const decorator = DECORATOR_ORDER[i];
658
+ if (marks.includes(decorator)) html = `<${DECORATOR_TAG[decorator]}>${html}</${DECORATOR_TAG[decorator]}>`;
659
+ }
660
+ const link = markDefs.find((d) => d && d._type === 'link' && marks.includes(d._key));
661
+ if (link) {
662
+ const attrs = [` href="${escapeAttribute(link.href ?? '')}"`];
663
+ if (link.target) attrs.push(` target="${escapeAttribute(link.target)}"`);
664
+ if (link.rel) attrs.push(` rel="${escapeAttribute(link.rel)}"`);
665
+ html = `<a${attrs.join('')}>${html}</a>`;
666
+ }
667
+ return html;
668
+ }
669
+
670
+ function childrenHtml(block: PortableTextBlock): string {
671
+ const markDefs = Array.isArray(block.markDefs) ? block.markDefs : [];
672
+ const spans = Array.isArray(block.children) ? block.children : [];
673
+ // Adjacent spans with identical marks are merged rather than emitted twice. A parse never produces them, but a
674
+ // value authored elsewhere can, and a re-parse would merge them — so merging here is what makes
675
+ // PT→HTML→PT→HTML a fixed point rather than a two-step settle.
676
+ const out: string[] = [];
677
+ let pending: PortableTextSpan | null = null;
678
+ const flush = () => {
679
+ if (pending) out.push(spanHtml(pending, markDefs));
680
+ pending = null;
681
+ };
682
+ for (const span of spans) {
683
+ const text = typeof span?.text === 'string' ? span.text : '';
684
+ const marks = Array.isArray(span?.marks) ? span.marks : [];
685
+ if (!text) continue;
686
+ if (pending && pending.marks.length === marks.length && pending.marks.every((m, i) => m === marks[i])) {
687
+ pending = { ...pending, text: pending.text + text };
688
+ continue;
689
+ }
690
+ flush();
691
+ pending = { _type: 'span', _key: span._key, text, marks };
692
+ }
693
+ flush();
694
+ return out.join('');
695
+ }
696
+
697
+ function isListBlock(node: unknown): node is PortableTextBlock {
698
+ return !!node && (node as PortableTextBlock)._type === 'block' && !!(node as PortableTextBlock).listItem;
699
+ }
700
+
701
+ function serializeList(blocks: PortableText, start: number, level: number): { html: string; next: number } {
702
+ const first = blocks[start] as PortableTextBlock;
703
+ const listItem = first.listItem;
704
+ const tag = listItem === 'number' ? 'ol' : 'ul';
705
+ let i = start;
706
+ let html = `<${tag}>`;
707
+ while (i < blocks.length) {
708
+ const block = blocks[i];
709
+ if (!isListBlock(block)) break;
710
+ const blockLevel = typeof block.level === 'number' ? block.level : 1;
711
+ if (blockLevel < level) break;
712
+ if (blockLevel === level && block.listItem !== listItem) break;
713
+ let inner: string;
714
+ if (blockLevel > level) {
715
+ // A sub-list with no parent item (a value authored by hand). Nest it rather than lose the indent.
716
+ const sub = serializeList(blocks, i, level + 1);
717
+ inner = sub.html;
718
+ i = sub.next;
719
+ } else {
720
+ inner = childrenHtml(block);
721
+ i += 1;
722
+ while (i < blocks.length && isListBlock(blocks[i]) && ((blocks[i] as PortableTextBlock).level ?? 1) > level) {
723
+ const sub = serializeList(blocks, i, level + 1);
724
+ inner += sub.html;
725
+ i = sub.next;
726
+ }
727
+ }
728
+ html += `<li>${inner}</li>`;
729
+ }
730
+ return { html: `${html}</${tag}>`, next: i };
731
+ }
732
+
733
+ /** Portable Text → HTML. Deterministic and byte-stable: the same blocks always produce the same string. */
734
+ export function portableTextToHtml(value: unknown): string {
735
+ if (typeof value === 'string') return value;
736
+ if (!Array.isArray(value)) return '';
737
+ const blocks = value as PortableText;
738
+ let html = '';
739
+ let i = 0;
740
+ while (i < blocks.length) {
741
+ const block = blocks[i];
742
+ if (!block || typeof block !== 'object') {
743
+ i += 1;
744
+ continue;
745
+ }
746
+ if ((block as PortableTextHtmlBlock)._type === 'html') {
747
+ html += (block as PortableTextHtmlBlock).html ?? '';
748
+ i += 1;
749
+ continue;
750
+ }
751
+ if (isListBlock(block)) {
752
+ const list = serializeList(blocks, i, 1);
753
+ html += list.html;
754
+ i = list.next;
755
+ continue;
756
+ }
757
+ const b = block as unknown as PortableTextBlock;
758
+ const tag = b.style && b.style !== 'normal' ? b.style : 'p';
759
+ html += `<${tag}>${childrenHtml(b)}</${tag}>`;
760
+ i += 1;
761
+ }
762
+ return html;
763
+ }
764
+
765
+ /**
766
+ * Portable Text → the copy a reader sees.
767
+ *
768
+ * Agrees with {@link richTextToCopy} character for character — asserted over every real React-registry richtext preview
769
+ * value in `test/rich-text.test.ts` — because the limit an author sees in the rail and the limit that refuses
770
+ * their submission have to be the same number. Spans concatenate (an inline boundary is not a word boundary);
771
+ * blocks join on a space (a block boundary is).
772
+ */
773
+ export function portableTextToPlainText(value: unknown): string {
774
+ if (typeof value === 'string') return richTextToCopy(value);
775
+ if (!Array.isArray(value)) return '';
776
+ const parts = (value as PortableText).map((block) => {
777
+ if (!block || typeof block !== 'object') return '';
778
+ if ((block as PortableTextHtmlBlock)._type === 'html') {
779
+ return richTextToCopy((block as PortableTextHtmlBlock).html ?? '');
780
+ }
781
+ const children = (block as PortableTextBlock).children;
782
+ if (!Array.isArray(children)) return '';
783
+ return children.map((s) => (typeof s?.text === 'string' ? s.text : '')).join('');
784
+ });
785
+ return parts.join(' ').replace(/\s+/g, ' ').trim();
786
+ }
787
+
788
+ /**
789
+ * The length a content limit is measured against, whichever shape the value is in.
790
+ *
791
+ * **One function, because four places have to agree**: the counter in the rail, the counter in the inline
792
+ * overlay, the submit gate, and `validatePreviewValues` on the registry's write path. Before this they measured
793
+ * raw string length everywhere, which is correct for text and wrong for richtext — 26 of the Handlebars
794
+ * registry's ruled fields are richtext, and their limits were being enforced against HTML while the editor showed no counter at all. An
795
+ * author could be blocked by a limit they could not see, counting tags they never typed (the maintainer, 2026-08-11).
796
+ *
797
+ * A block array needs no flag: it carries its own shape, and `.length` on one counts *blocks*, so a three-
798
+ * paragraph answer would measure 3 against a 240-character rule and pass anything. The `richtext` flag stays for
799
+ * strings, where HTML and plain text are indistinguishable, and a string measures raw without it — an authored
800
+ * `rules.content.max` was set against HTML and must not change meaning.
801
+ */
802
+ export function measuredCopyLength(value: unknown, richtext = false): number {
803
+ if (isPortableText(value)) return portableTextToPlainText(value).length;
804
+ if (typeof value !== 'string') return 0;
805
+ return richtext ? richTextToCopy(value).length : value.length;
806
+ }
807
+
808
+ /**
809
+ * The lengths a content **limit** is measured against: one per block.
810
+ *
811
+ * The per-item path of {@link measuredCopyLength}, and the reason it exists is roadmap 7 item 7. A paragraph
812
+ * list carried a `rules.content.max` **per item** — `preview-validation` says so in as many words, and the React
813
+ * registry's components declare their maxima as a per-piece-of-copy role floor (body 240, title 70). Migrating that list
814
+ * into one Portable Text value would have handed the same rule a joined length: `two-column-content.bodySlot`
815
+ * measures 390–819 characters combined against a 240 limit, so the seven previews the migration converts would
816
+ * all have become invalid the moment they were written. Measured per block they measure exactly what they
817
+ * measured as a list, which is the point — a backfill must not change which values pass their limit.
818
+ *
819
+ * Safe in the other direction too, and checked rather than assumed: across the React-registry rig only 2 of 406
820
+ * stored richtext strings parse to more than one block, and neither one's verdict moves.
821
+ *
822
+ * A non-Portable-Text value is one length — `measuredCopyLength`'s own answer — so a caller can use this
823
+ * everywhere without special-casing strings.
824
+ */
825
+ export function blockCopyLengths(value: unknown): number[] {
826
+ if (!isPortableText(value)) return [measuredCopyLength(value)];
827
+ return value.map((block) => portableTextToPlainText([block]).length);
828
+ }
829
+
830
+ function markdownSpan(span: PortableTextSpan, markDefs: PortableTextLink[]): string {
831
+ const marks = Array.isArray(span.marks) ? span.marks : [];
832
+ let text = typeof span.text === 'string' ? span.text : '';
833
+ if (!text) return '';
834
+ if (marks.includes('code')) text = `\`${text}\``;
835
+ // Markdown has no underline, and a `<u>` is what every renderer that reads this understands.
836
+ if (marks.includes('underline')) text = `<u>${text}</u>`;
837
+ if (marks.includes('em')) text = `*${text}*`;
838
+ if (marks.includes('strong')) text = `**${text}**`;
839
+ const link = markDefs.find((d) => d && d._type === 'link' && marks.includes(d._key));
840
+ if (link) text = `[${text}](${link.href ?? ''})`;
841
+ return text;
842
+ }
843
+
844
+ /** Portable Text → Markdown, for the agent-facing boundary. */
845
+ export function portableTextToMarkdown(value: unknown): string {
846
+ if (typeof value === 'string') return portableTextToMarkdown(htmlToPortableText(value));
847
+ if (!Array.isArray(value)) return '';
848
+ let numbering: number[] = [];
849
+ const lines = (value as PortableText).map((block) => {
850
+ if (!block || typeof block !== 'object') return '';
851
+ if ((block as PortableTextHtmlBlock)._type === 'html') {
852
+ numbering = [];
853
+ return (block as PortableTextHtmlBlock).html ?? '';
854
+ }
855
+ const b = block as PortableTextBlock;
856
+ const markDefs = Array.isArray(b.markDefs) ? b.markDefs : [];
857
+ const text = (Array.isArray(b.children) ? b.children : []).map((s) => markdownSpan(s, markDefs)).join('');
858
+ if (b.listItem) {
859
+ const level = typeof b.level === 'number' && b.level > 0 ? b.level : 1;
860
+ numbering = numbering.slice(0, level);
861
+ numbering[level - 1] = (numbering[level - 1] ?? 0) + 1;
862
+ const indent = ' '.repeat(level - 1);
863
+ return `${indent}${b.listItem === 'number' ? `${numbering[level - 1]}.` : '-'} ${text}`;
864
+ }
865
+ numbering = [];
866
+ if (b.style === 'blockquote') return `> ${text}`;
867
+ const heading = /^h([1-6])$/.exec(b.style ?? '');
868
+ if (heading) return `${'#'.repeat(Number(heading[1]))} ${text}`;
869
+ return text;
870
+ });
871
+ // List items are one block each but read as one list; everything else gets a blank line.
872
+ let out = '';
873
+ (value as PortableText).forEach((block, i) => {
874
+ const line = lines[i];
875
+ if (i > 0) {
876
+ const previous = (value as PortableText)[i - 1];
877
+ const bothList = isListBlock(previous) && isListBlock(block);
878
+ out += bothList ? '\n' : '\n\n';
879
+ }
880
+ out += line;
881
+ });
882
+ return out.trim();
883
+ }
884
+
885
+ // ─────────────────────────────────────────────────────────────────────────────
886
+ // Tolerant readers — what keeps every existing HTML string working untouched
887
+ // ─────────────────────────────────────────────────────────────────────────────
888
+
889
+ /**
890
+ * Is this a Portable Text value?
891
+ *
892
+ * Strict about `_type` so it can never be true of an ordinary array of rows. An **empty** array is deliberately
893
+ * not Portable Text: it is indistinguishable from an empty repeater, and reading it as blocks would rewrite a
894
+ * value nobody edited.
895
+ */
896
+ export function isPortableText(value: unknown): value is PortableText {
897
+ if (!Array.isArray(value) || value.length === 0) return false;
898
+ return value.every(
899
+ (node) =>
900
+ !!node &&
901
+ typeof node === 'object' &&
902
+ !Array.isArray(node) &&
903
+ ((node as { _type?: unknown })._type === 'block' || (node as { _type?: unknown })._type === 'html')
904
+ );
905
+ }
906
+
907
+ /**
908
+ * Anything → Portable Text. A Portable Text value is returned as it is; anything else is read into blocks.
909
+ *
910
+ * **Four shapes, because four shapes are stored.** Two are original: a Portable Text array, and an HTML string.
911
+ * Two more are the legitimate non-string values a richtext slot has always been allowed to hold, and they are
912
+ * coerced here — not in each reader — so the migration, the MCP boundary and the editor cannot disagree about
913
+ * what one of them means (roadmap 7 item 7):
914
+ *
915
+ * - a **paragraph list** (`['First.', 'Second.']`) → one block per item, keys renumbered across the whole list.
916
+ * One value, many blocks: exactly what Portable Text exists to express, and what the list was standing in for.
917
+ * - an **explicit heading** (`{ level: 'h1', text: 'Title' }`) → one block whose `style` carries the level, with
918
+ * the text parsed so its inline marks survive.
919
+ *
920
+ * Anything else — a serialized React element, a repeater row, a number — is empty, and a caller that gets `[]`
921
+ * back has learned that this value is not rich text it can read.
922
+ */
923
+ export function asPortableText(value: unknown): PortableText {
924
+ if (isPortableText(value)) return value;
925
+ if (typeof value === 'string') return htmlToPortableText(value);
926
+ if (isParagraphList(value)) {
927
+ const blocks: PortableTextNode[] = [];
928
+ for (const paragraph of value) blocks.push(...htmlToPortableText(paragraph));
929
+ return rekeyPositionally(blocks);
930
+ }
931
+ if (isHeadingValue(value)) return headingBlocks(value);
932
+ return [];
933
+ }
934
+
935
+ /**
936
+ * The copy a **stored** value reads as, computed per shape and WITHOUT going through {@link asPortableText}.
937
+ *
938
+ * The migration's refusal check compares this against `portableTextToPlainText` of the blocks, and the whole
939
+ * point is that the two arrive by different routes: `richTextToCopy` is a regex tag-strip, the blocks come from
940
+ * a real parser, and a disagreement between them is the signal that a conversion would move what a reader reads.
941
+ * Routing both sides through the parser would make the check pass by construction and assert nothing.
942
+ *
943
+ * A paragraph list joins on a space because each item rendered as its own `<p>` — a block boundary is a word
944
+ * boundary, the same rule {@link portableTextToPlainText} follows.
945
+ */
946
+ export function storedRichTextCopy(value: unknown): string {
947
+ if (isPortableText(value)) return portableTextToPlainText(value);
948
+ if (typeof value === 'string') return richTextToCopy(value);
949
+ if (isParagraphList(value)) {
950
+ return value.map(richTextToCopy).filter(Boolean).join(' ').replace(/\s+/g, ' ').trim();
951
+ }
952
+ if (isHeadingValue(value)) {
953
+ return richTextToCopy(typeof value.text === 'string' ? value.text : (value.html as string) ?? '');
954
+ }
955
+ return '';
956
+ }
957
+
958
+ /**
959
+ * Anything → what a renderer wants.
960
+ *
961
+ * **A string is returned by identity** — same reference, not a re-serialization — which is the single fact that
962
+ * keeps the Handlebars context, the props JSON and therefore every built artifact byte-identical while nothing
963
+ * writes Portable Text yet. Non-string, non-Portable-Text values pass through untouched for the same reason.
964
+ *
965
+ * **Deliberately NOT tolerant the way {@link asPortableText} is.** A paragraph list and a `{ level, text }`
966
+ * heading are rich text this module can read, but serializing them HERE would rewrite what a component's
967
+ * `render` receives — `applyRenderFns` calls this on every annotated field — and so would move built output for
968
+ * nine React-registry previews before the migration has written anything. The staged rollout rests on that not happening:
969
+ * conversion is a thing the backfill does once, on purpose, not a thing a render does silently. A value the
970
+ * migration has not converted keeps rendering exactly as it renders today, forever.
971
+ */
972
+ export function asHtml<T>(value: T): T | string {
973
+ if (isPortableText(value)) return portableTextToHtml(value);
974
+ return value;
975
+ }
976
+
977
+ // ─────────────────────────────────────────────────────────────────────────────
978
+ // The render boundary
979
+ // ─────────────────────────────────────────────────────────────────────────────
980
+
981
+ /** Just enough of a property descriptor to know which fields hold rich text. */
982
+ interface WirePropertyMeta {
983
+ editorType?: unknown;
984
+ items?: { properties?: Record<string, WirePropertyMeta> };
985
+ properties?: Record<string, WirePropertyMeta>;
986
+ }
987
+
988
+ function declaredRichtextKeys(properties: unknown): Set<string> {
989
+ const keys = new Set<string>();
990
+ if (!properties || typeof properties !== 'object' || Array.isArray(properties)) return keys;
991
+ for (const [key, meta] of Object.entries(properties as Record<string, WirePropertyMeta>)) {
992
+ if (meta && typeof meta === 'object' && meta.editorType === 'richtext') keys.add(key);
993
+ }
994
+ return keys;
995
+ }
996
+
997
+ /**
998
+ * Convert in place, returning the **same reference** when nothing changed.
999
+ *
1000
+ * Reference equality is the point, not an optimisation: the canvas re-renders on identity (`prev[i] !== c`),
1001
+ * and a fresh object graph on every render would turn a no-op into a full rebuild of every block.
1002
+ */
1003
+ function convertToWire(value: unknown): unknown {
1004
+ if (isPortableText(value)) return portableTextToHtml(value);
1005
+ if (Array.isArray(value)) {
1006
+ let changed = false;
1007
+ const next = value.map((item) => {
1008
+ const converted = convertToWire(item);
1009
+ if (converted !== item) changed = true;
1010
+ return converted;
1011
+ });
1012
+ return changed ? next : value;
1013
+ }
1014
+ if (value && typeof value === 'object') {
1015
+ let changed = false;
1016
+ const next: Record<string, unknown> = {};
1017
+ for (const [key, item] of Object.entries(value as Record<string, unknown>)) {
1018
+ const converted = convertToWire(item);
1019
+ if (converted !== item) changed = true;
1020
+ next[key] = converted;
1021
+ }
1022
+ return changed ? next : value;
1023
+ }
1024
+ return value;
1025
+ }
1026
+
1027
+ /**
1028
+ * Block args → what a renderer is handed: Portable Text serialized to HTML, everything else untouched.
1029
+ *
1030
+ * **This is the change that keeps the Handlebars registry working and needs zero registry rebuilds.** The
1031
+ * `-client.mjs` `__map` is baked into every built artifact; Portable Text reaching it would render
1032
+ * `[object Object]` on all 84 components until every one was rebuilt and re-pushed. Converting here — before
1033
+ * the Handlebars context, before the props JSON, before every `update-props` postMessage — means the wire
1034
+ * contract never changes: `{{{bodySlot}}}` gets the HTML string it has always got.
1035
+ *
1036
+ * **For a string value this is the identity function, reference and all**, which is what makes it safe to land
1037
+ * before anything writes Portable Text: byte-identical output, asserted in `test/rich-text.test.ts` and by the
1038
+ * Handlebars diff gate.
1039
+ *
1040
+ * `properties` resolves the one ambiguity shape alone cannot. An empty array is not Portable Text — it is
1041
+ * indistinguishable from an empty repeater, and `isPortableText` rightly refuses to guess — but on a field the
1042
+ * component *declares* `editorType: 'richtext'`, `[]` means empty rich text and has to reach the renderer as an
1043
+ * empty string.
1044
+ */
1045
+ export function toWireArgs<T>(data: T, properties?: unknown): T {
1046
+ const converted = convertToWire(data) as T;
1047
+ const richtextKeys = declaredRichtextKeys(properties);
1048
+ if (!richtextKeys.size || !converted || typeof converted !== 'object' || Array.isArray(converted)) {
1049
+ return converted;
1050
+ }
1051
+ const record = converted as Record<string, unknown>;
1052
+ let emptied: Record<string, unknown> | null = null;
1053
+ for (const key of richtextKeys) {
1054
+ if (Array.isArray(record[key]) && (record[key] as unknown[]).length === 0) {
1055
+ emptied = emptied ?? { ...record };
1056
+ emptied[key] = '';
1057
+ }
1058
+ }
1059
+ return (emptied ?? record) as T;
1060
+ }
1061
+
1062
+ // ─────────────────────────────────────────────────────────────────────────────
1063
+ // The MCP boundary — descriptor-driven, because shape alone cannot tell
1064
+ // ─────────────────────────────────────────────────────────────────────────────
1065
+
1066
+ /** How an agent asked to be handed rich text. Storage is Portable Text either way. */
1067
+ export type RichTextFormat = 'html' | 'portableText' | 'markdown';
1068
+
1069
+ /**
1070
+ * Nesting, in all four spellings the codebase uses.
1071
+ *
1072
+ * A **contract** (`handoff_component.properties`) nests through `properties` and `items.properties`; a
1073
+ * **field annotation** (the `fields` report a scaffold returns) nests through `fields` and `itemFields`. They
1074
+ * describe the same tree and this walk has to work on either, because the MCP write path is handed the first
1075
+ * and the chat merge is handed the second. Accepting both here is one place to be tolerant instead of two
1076
+ * walkers that would drift.
1077
+ */
1078
+ interface RichTextPropertyMeta {
1079
+ editorType?: unknown;
1080
+ type?: unknown;
1081
+ properties?: unknown;
1082
+ fields?: unknown;
1083
+ items?: { editorType?: unknown; type?: unknown; properties?: unknown };
1084
+ itemFields?: unknown;
1085
+ }
1086
+
1087
+ /** Matches `MAX_ANNOTATION_DEPTH` in the projection: nothing is declared below this, so nothing is found there. */
1088
+ const MAX_RICHTEXT_DEPTH = 5;
1089
+
1090
+ const asRecord = (value: unknown): Record<string, RichTextPropertyMeta> | null =>
1091
+ value && typeof value === 'object' && !Array.isArray(value)
1092
+ ? (value as Record<string, RichTextPropertyMeta>)
1093
+ : null;
1094
+
1095
+ const declaresRichtext = (meta: { editorType?: unknown; type?: unknown } | undefined): boolean =>
1096
+ meta?.editorType === 'richtext' || (meta?.editorType === undefined && meta?.type === 'richtext');
1097
+
1098
+ function mapValue(
1099
+ value: unknown,
1100
+ meta: RichTextPropertyMeta,
1101
+ map: RichTextMapper,
1102
+ depth: number,
1103
+ path: string
1104
+ ): unknown {
1105
+ if (declaresRichtext(meta)) return map(value, path);
1106
+ if (depth >= MAX_RICHTEXT_DEPTH || value == null) return value;
1107
+
1108
+ if (Array.isArray(value)) {
1109
+ const rowProps = asRecord(meta.items?.properties) ?? asRecord(meta.itemFields);
1110
+ let changed = false;
1111
+ const next = value.map((row, i) => {
1112
+ // A scalar array of rich text — `of: 'richtext'` — is the item descriptor's business, not a record's.
1113
+ if (declaresRichtext(meta.items as { editorType?: unknown; type?: unknown } | undefined)) {
1114
+ const mapped = map(row, `${path}[${i}]`);
1115
+ if (mapped !== row) changed = true;
1116
+ return mapped;
1117
+ }
1118
+ if (!rowProps) return row;
1119
+ const mapped = mapRecord(row, rowProps, map, depth + 1, `${path}[${i}]`);
1120
+ if (mapped !== row) changed = true;
1121
+ return mapped;
1122
+ });
1123
+ return changed ? next : value;
1124
+ }
1125
+
1126
+ const childProps = asRecord(meta.properties) ?? asRecord(meta.fields);
1127
+ if (childProps) return mapRecord(value, childProps, map, depth + 1, path);
1128
+ return value;
1129
+ }
1130
+
1131
+ function mapRecord(
1132
+ value: unknown,
1133
+ properties: Record<string, RichTextPropertyMeta>,
1134
+ map: RichTextMapper,
1135
+ depth: number,
1136
+ path: string
1137
+ ): unknown {
1138
+ if (!value || typeof value !== 'object' || Array.isArray(value)) return value;
1139
+ const record = value as Record<string, unknown>;
1140
+ let next: Record<string, unknown> | null = null;
1141
+ for (const [key, meta] of Object.entries(properties)) {
1142
+ if (!meta || typeof meta !== 'object') continue;
1143
+ if (!(key in record)) continue;
1144
+ const mapped = mapValue(record[key], meta, map, depth, path ? `${path}.${key}` : key);
1145
+ if (mapped === record[key]) continue;
1146
+ next = next ?? { ...record };
1147
+ next[key] = mapped;
1148
+ }
1149
+ return next ?? record;
1150
+ }
1151
+
1152
+ /**
1153
+ * What a rich-text value becomes. Returning the value untouched is how "nothing changed" is signalled.
1154
+ *
1155
+ * `path` is the dotted position the value was found at (`cards[0].body`). Every conversion ignores it; the
1156
+ * migration reports with it, and a refusal nobody can locate is a refusal nobody can fix.
1157
+ */
1158
+ export type RichTextMapper = (value: unknown, path: string) => unknown;
1159
+
1160
+ /**
1161
+ * Apply `map` to every value a component **declares** as rich text, at any depth its contract describes.
1162
+ *
1163
+ * Descriptor-driven rather than shape-driven, and that is the whole point: `toWireArgs` can convert on the way
1164
+ * *out* by looking at the value, because Portable Text is recognisable on sight. On the way *in* it is not —
1165
+ * an HTML string and a headline are both strings, and guessing would wrap a plain headline in blocks the
1166
+ * component never asked for. Only the contract knows.
1167
+ *
1168
+ * Returns the **same reference** when nothing matched, for the same reason `toWireArgs` does: the canvas
1169
+ * re-renders on identity, so a fresh object graph turns a no-op into a full rebuild.
1170
+ */
1171
+ export function mapRichTextFields<T>(data: T, properties: unknown, map: RichTextMapper): T {
1172
+ const props = asRecord(properties);
1173
+ if (!props) return data;
1174
+ return mapRecord(data, props, map, 1, '') as T;
1175
+ }
1176
+
1177
+ /**
1178
+ * Agent-supplied args → what is stored: HTML parsed into Portable Text, Portable Text left alone.
1179
+ *
1180
+ * The MCP wire keeps taking HTML — no agent prompt has to change on ship day — and the registry keeps the
1181
+ * canonical shape. An empty string stays an empty string rather than becoming an empty block array, matching
1182
+ * what the rail commits for an empty field.
1183
+ */
1184
+ export function toStoredArgs<T>(data: T, properties: unknown): T {
1185
+ return mapRichTextFields(data, properties, (value) =>
1186
+ typeof value === 'string' && value ? htmlToPortableText(value) : value
1187
+ );
1188
+ }
1189
+
1190
+ /**
1191
+ * Stored args → what an agent asked for.
1192
+ *
1193
+ * `html` is the default everywhere, and is the shape-driven `toWireArgs` rather than a second walk: HTML is
1194
+ * what every existing caller already receives, and converting on sight also catches a value stored under a
1195
+ * contract that has since moved on. `portableText` is the honest canonical shape for a caller that wants it,
1196
+ * and `markdown` is the compact one for a caller reading copy rather than editing markup.
1197
+ */
1198
+ export function toReadArgs<T>(data: T, properties: unknown, format: RichTextFormat = 'html'): T {
1199
+ if (format === 'portableText') return data;
1200
+ if (format === 'markdown') return mapRichTextFields(data, properties, (value) => portableTextToMarkdown(value));
1201
+ return toWireArgs(data, properties);
1202
+ }