@riverbankcms/sdk 0.182.0 → 0.184.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (231) hide show
  1. package/CHANGELOG.md +79 -0
  2. package/README.md +83 -4
  3. package/dist/_dts/{BlocksIslandsHydrator-Bvw2bUif.d.ts → BlocksIslandsHydrator-DjBTJYiF.d.ts} +1 -1
  4. package/dist/_dts/{Page-B2EAT-bE.d.ts → Page-BpXEM2ET.d.ts} +7 -7
  5. package/dist/_dts/{SdkPreviewMode-D0vww6rh.d.ts → SdkPreviewMode-Bb3h7KRE.d.ts} +2 -2
  6. package/dist/_dts/{client-D6T430bk.d.ts → client-DgTRRtl_.d.ts} +14 -1
  7. package/dist/_dts/{content-types-wZVWccC6.d.ts → content-types-DZQJp_ak.d.ts} +9 -16
  8. package/dist/_dts/{contracts-B-vtOcr8.d.ts → contracts-Ww1fmd-c.d.ts} +3 -3
  9. package/dist/_dts/{generatePageMetadata-CxfwHE6z.d.ts → generatePageMetadata-BGc7dju6.d.ts} +2 -2
  10. package/dist/_dts/{index-CciRW_w1.d.ts → index-BECaUNYs.d.ts} +2 -2
  11. package/dist/_dts/{index-CEyYMhLJ.d.ts → index-Cc85KVLW.d.ts} +3 -3
  12. package/dist/_dts/{index-CQrb3Ccc.d.ts → index-Cni4jykw.d.ts} +4 -4
  13. package/dist/_dts/{index-DIU-wL1M.d.ts → index-DxxTQ_0V.d.ts} +2 -2
  14. package/dist/_dts/{index-Cqxis-nv.d.ts → index-W9-7djG3.d.ts} +1 -1
  15. package/dist/_dts/{index-DqPKdeTk.d.ts → index-ukS-Ffem.d.ts} +1 -1
  16. package/dist/_dts/{loadContent-D0wrxiSp.d.ts → loadContent-BlSWTlbD.d.ts} +7 -7
  17. package/dist/_dts/{request-DEwxUSw8.d.ts → request-CZz2BoXJ.d.ts} +89478 -88093
  18. package/dist/_dts/{resolveBlockData-VaG_MYbN.d.ts → resolveBlockData-D12HXnS3.d.ts} +5 -5
  19. package/dist/_dts/{resolvePageContent-DTwklC_v.d.ts → resolvePageContent-BteMsSGP.d.ts} +1 -1
  20. package/dist/_dts/sdk/src/bookings/index.d.ts +2 -2
  21. package/dist/_dts/sdk/src/client/types.d.ts +2 -2
  22. package/dist/_dts/sdk/src/client.d.ts +7 -7
  23. package/dist/_dts/sdk/src/config/index.d.ts +7 -7
  24. package/dist/_dts/sdk/src/config/template-validation.d.ts +1 -1
  25. package/dist/_dts/sdk/src/config/validation.d.ts +1 -1
  26. package/dist/_dts/sdk/src/data/dataLoaderContext.d.ts +2 -2
  27. package/dist/_dts/sdk/src/data/resolveBlockData.d.ts +1 -1
  28. package/dist/_dts/sdk/src/data/types.d.ts +2 -2
  29. package/dist/_dts/sdk/src/gifting/client.d.ts +1 -1
  30. package/dist/_dts/sdk/src/index.d.ts +8 -8
  31. package/dist/_dts/sdk/src/manifest/index.d.ts +3 -3
  32. package/dist/_dts/sdk/src/metadata/index.d.ts +1 -1
  33. package/dist/_dts/sdk/src/navigation/index.d.ts +3 -3
  34. package/dist/_dts/sdk/src/next/index.d.ts +7 -7
  35. package/dist/_dts/sdk/src/next/middleware.d.ts +2 -2
  36. package/dist/_dts/sdk/src/page-converter/index.d.ts +3 -3
  37. package/dist/_dts/sdk/src/portal/client.d.ts +1 -1
  38. package/dist/_dts/sdk/src/portal/index.d.ts +10 -2
  39. package/dist/_dts/sdk/src/prebuild/index.d.ts +1 -1
  40. package/dist/_dts/sdk/src/preview-next/before-render.d.ts +2 -2
  41. package/dist/_dts/sdk/src/preview-next/client/index.d.ts +2 -2
  42. package/dist/_dts/sdk/src/preview-next/client/runtime.d.ts +1 -1
  43. package/dist/_dts/sdk/src/rendering/client.d.ts +2 -2
  44. package/dist/_dts/sdk/src/rendering/components/pageShared.d.ts +1 -1
  45. package/dist/_dts/sdk/src/rendering/helpers/loadPage.d.ts +1 -1
  46. package/dist/_dts/sdk/src/rendering/helpers/pageRuntimeSupport.d.ts +4 -4
  47. package/dist/_dts/sdk/src/rendering/index.d.ts +6 -6
  48. package/dist/_dts/sdk/src/rendering/islands/client.d.ts +1 -1
  49. package/dist/_dts/sdk/src/rendering/server.d.ts +2 -2
  50. package/dist/_dts/sdk/src/rendering/themeAdmission.d.ts +1 -1
  51. package/dist/_dts/sdk/src/routing/index.d.ts +6 -6
  52. package/dist/_dts/sdk/src/server.d.ts +5 -5
  53. package/dist/_dts/sdk/src/spam-protection/index.d.ts +2 -2
  54. package/dist/_dts/sdk/src/theme/index.d.ts +126 -2
  55. package/dist/_dts/{serviceBookingOutline-DtQuFlID.d.ts → serviceBookingOutline-aTlOvO3U.d.ts} +16 -8
  56. package/dist/_dts/{types-B3RjeBLV.d.ts → types-Bi7R07RX.d.ts} +45 -4
  57. package/dist/_dts/{types-BvUSGQrw.d.ts → types-CCcQlRBi.d.ts} +22 -12
  58. package/dist/_dts/{types-CkRFtBqd.d.ts → types-Du4aMnWC.d.ts} +13 -15
  59. package/dist/_dts/{validation-BZA3DhcV.d.ts → validation-CjCWVmwe.d.ts} +4 -4
  60. package/dist/client/{BlocksIslandsHydrator-CQMf0HdN.mjs → BlocksIslandsHydrator-CFLWxjxR.mjs} +22 -18
  61. package/dist/client/{BookingMailingListNote-7kdvuPow.mjs → BookingMailingListNote-C4LcfwyA.mjs} +8 -8
  62. package/dist/client/{BookingQuestionFields-BJI7mZuV.mjs → BookingQuestionFields-DdcmoHqQ.mjs} +2 -2
  63. package/dist/client/{CalendarAction-D_Glwvz2.mjs → CalendarAction-DYGewmvh.mjs} +1 -1
  64. package/dist/client/{CalendarNavigationChevron-DPUD6wjy.mjs → CalendarNavigationChevron-ZfrUiiiI.mjs} +25 -8
  65. package/dist/client/{CheckboxChoice-C8i4NraK.mjs → CheckboxChoice-CTMIII37.mjs} +1 -1
  66. package/dist/client/{DemoBookingPortalAccess-8kwNF9HN.mjs → DemoBookingPortalAccess-pzkGVkgG.mjs} +7 -5
  67. package/dist/client/{EventCalendar.client-Dhb14bcC.mjs → EventCalendar.client-Ct1B3xI4.mjs} +10 -10
  68. package/dist/client/{EventCombined.client-C1jEZBN9.mjs → EventCombined.client-DgfNtcgW.mjs} +9 -9
  69. package/dist/client/{EventEmbeddedCheckoutStep-BGkbUhuw.mjs → EventEmbeddedCheckoutStep-CjoaG1zy.mjs} +1 -1
  70. package/dist/client/{EventItem-Bb0ppG2N.mjs → EventItem-KGKkK19N.mjs} +29 -14
  71. package/dist/client/{EventListWeekNavigation-DMryCaNV.mjs → EventListWeekNavigation-Ba9ezxuC.mjs} +1 -1
  72. package/dist/client/{EventListing.client-BuH5kKA3.mjs → EventListing.client-xFKRDLwC.mjs} +3 -3
  73. package/dist/client/{EventListing.view-DsqvuulZ.mjs → EventListing.view-Dy36vWHi.mjs} +84 -7
  74. package/dist/client/{EventRegistrationPayment-D4FvQSFF.mjs → EventRegistrationPayment-Dth9L00x.mjs} +118 -76
  75. package/dist/client/{Page-sV6BJkXX.mjs → Page-DB5KODiu.mjs} +4491 -1398
  76. package/dist/client/{ProtectedSubmitButton-BNnKuir8.mjs → ProtectedSubmitButton-CY6u5sQa.mjs} +1 -1
  77. package/dist/client/{SiteTermsAgreementField-VfSd6JU-.mjs → SiteTermsAgreementField-BDVP_HeK.mjs} +3 -3
  78. package/dist/client/{StepIndicator-B6o5B7g3.mjs → StepIndicator-CLgDVzCs.mjs} +1 -1
  79. package/dist/client/{StepIndicator-BTqO7cJl.mjs → StepIndicator-DRyZ8igu.mjs} +7 -7
  80. package/dist/client/{ThemedButton-PFOhXktM.mjs → ThemedButton-C4rCsPCt.mjs} +52 -10
  81. package/dist/client/{accessibleSurfaces-BogaGutk.mjs → accessibleSurfaces-CqroimVQ.mjs} +1024 -619
  82. package/dist/client/{accordion-6cuswD_s.mjs → accordion-BQYRP5xV.mjs} +1 -1
  83. package/dist/client/{booking-form.client-BOMe_SKi.mjs → booking-form.client-B7ckDuOC.mjs} +191 -71
  84. package/dist/client/{bookingForm-DSCH-VHo.mjs → bookingForm-BeD4650p.mjs} +7 -6
  85. package/dist/client/bookings.mjs +5 -5
  86. package/dist/client/{boxStyleClassNames-BFuqZCfz.mjs → boxStyleClassNames-CA7FirMH.mjs} +2 -2
  87. package/dist/client/buttonParts-C39GC0kz.mjs +1518 -0
  88. package/dist/client/{carousel-CGyQVV1M.mjs → carousel-DJ9Aa1m3.mjs} +2 -2
  89. package/dist/client/{carousel.client-BtLwHefX.mjs → carousel.client-DKWqVHHh.mjs} +1 -1
  90. package/dist/client/{cart-BYOe7MCh.mjs → cart-DdCenbTy.mjs} +3 -3
  91. package/dist/client/{cart.client-BKFkaXdV.mjs → cart.client-BQm06qNw.mjs} +1 -1
  92. package/dist/client/{checkout-Dwd7Di77.mjs → checkout-45wPQULN.mjs} +3 -3
  93. package/dist/client/{checkout.client-C25hpi-z.mjs → checkout.client-bSv4cc5z.mjs} +1 -1
  94. package/dist/client/{checkoutUrls-tG788sw0.mjs → checkoutUrls-CwlaMl3W.mjs} +1 -1
  95. package/dist/client/client.mjs +460 -119
  96. package/dist/client/{constants-DdxFG3Ic.mjs → constants-DXV4KR7l.mjs} +1 -1
  97. package/dist/client/{context-Hi1RuYEM.mjs → context-lCPfX-xe.mjs} +15 -5
  98. package/dist/client/{dateFormatting-C8vBCHuo.mjs → dateFormatting-HvfmS_cH.mjs} +1 -1
  99. package/dist/client/{demoPortalMagicLink-BAL5UIDG.mjs → demoPortalMagicLink-Ce3Gyin_.mjs} +1 -1
  100. package/dist/client/{enhanceHeaderSection-Dv1Lr9kJ.mjs → enhanceHeaderSection-CGcDE9aE.mjs} +4 -4
  101. package/dist/client/{event-registration.client-dB_Z7bb-.mjs → event-registration.client-DlPfn4YG.mjs} +52 -29
  102. package/dist/client/{eventCalendar-CQnRA4Ww.mjs → eventCalendar-CioAdryV.mjs} +4 -4
  103. package/dist/client/{eventCombined-BDOG1hVp.mjs → eventCombined-Dwt0G6ez.mjs} +4 -4
  104. package/dist/client/{eventListing-DSVmhy9n.mjs → eventListing-B3H9ifOC.mjs} +4 -4
  105. package/dist/client/{eventRegistration-CD5mRtEH.mjs → eventRegistration-Do7cAhXb.mjs} +7 -6
  106. package/dist/client/{form-DWnlEVSK.mjs → form-CsqzgC6v.mjs} +3 -3
  107. package/dist/client/{form.client-D7zmeqNI.mjs → form.client-DVDB7hY6.mjs} +5 -5
  108. package/dist/client/{form.parts-C-G6N_MK.mjs → form.parts-1q2rzSYt.mjs} +3 -3
  109. package/dist/client/gifting/client.mjs +16 -9
  110. package/dist/client/{gifting-Cn0jidP5.mjs → gifting-BrXQGX-k.mjs} +4 -4
  111. package/dist/client/{gifting.client-DVo1YFLs.mjs → gifting.client--zAjnY5N.mjs} +155 -85
  112. package/dist/client/gifting.interactive-CrwHpUJG.mjs +207 -0
  113. package/dist/client/gifting.parts-CcKdDaQq.mjs +124 -0
  114. package/dist/client/{headerSection-DjQuj_6v.mjs → headerSection-DlcDH4bi.mjs} +2 -2
  115. package/dist/client/{noop-jesvJXEE.mjs → islands-dMh0Oxli.mjs} +16103 -7965
  116. package/dist/client/{newsletter-form.client-rIYPziZC.mjs → newsletter-form.client-BxA1PsdS.mjs} +6 -6
  117. package/dist/client/{newsletter-form.interactive-DVt3enLr.mjs → newsletter-form.interactive-D0iRg7p2.mjs} +229 -197
  118. package/dist/client/{newsletter-form.parts-CH6dGfdn.mjs → newsletter-form.parts-Dmuklz0r.mjs} +2 -2
  119. package/dist/client/{newsletterForm-Cg8cBDHd.mjs → newsletterForm-CBzvgIfg.mjs} +3 -3
  120. package/dist/client/portal/client.mjs +51 -35
  121. package/dist/client/{portalOrders-oEoTvzkW.mjs → portalOrders-tCxS04g0.mjs} +3 -2
  122. package/dist/client/{portalRoutes-ByyVZfVq.mjs → portalRoutes-DiGibcZI.mjs} +31 -9
  123. package/dist/client/portalSession-0XhXyTxT.mjs +41 -0
  124. package/dist/client/{product-detail.client-5aHq-vuu.mjs → product-detail.client-D9MP8hvH.mjs} +1 -1
  125. package/dist/client/{product-list.client-CyAk5rnC.mjs → product-list.client-wCz1qcUY.mjs} +1 -1
  126. package/dist/client/{productDetail-B8aZ2mqY.mjs → productDetail-D9-fCY6c.mjs} +3 -3
  127. package/dist/client/{productList-BuLemmod.mjs → productList-PJyxXSac.mjs} +3 -3
  128. package/dist/client/{propsDecoder-0Unsqn3R.mjs → propsDecoder-B8lrKGPw.mjs} +4 -2
  129. package/dist/client/{registry.server-DzvtVVD0.mjs → registry.server-CI63JVHW.mjs} +2444 -1078
  130. package/dist/client/rendering/client.mjs +32 -28
  131. package/dist/client/rendering/islands.mjs +1 -1
  132. package/dist/client/rendering.mjs +5 -5
  133. package/dist/client/{richText-coerce-Bnng7JFA.mjs → richText-coerce-Jt9hDHdh.mjs} +2 -2
  134. package/dist/client/{routeIslandApiConfig-BGfcc9sk.mjs → routeIslandApiConfig-ZSPcJWx1.mjs} +1 -1
  135. package/dist/client/runtimeResponse-DlPBWBd9.mjs +3 -0
  136. package/dist/client/{runtimeResponse-DAPVRToN.mjs → runtimeResponse-_iW9oEYc.mjs} +1 -1
  137. package/dist/client/{shop-GuMqnDL-.mjs → shop-CbdJlWOw.mjs} +3 -3
  138. package/dist/client/{shop-commerce-D5bDY1o1.mjs → shop-commerce-BqLbzUUn.mjs} +47 -28
  139. package/dist/client/{shop-commerce-store-B7sHnLwI.mjs → shop-commerce-store-BT0-zRqN.mjs} +1 -1
  140. package/dist/client/{shop-discount-apply.state-Dos2zdC2.mjs → shop-discount-apply.state-Cws0lnSb.mjs} +2 -2
  141. package/dist/client/{shop.client-uvj5GDZb.mjs → shop.client-0cNErhJT.mjs} +54 -24
  142. package/dist/client/{shopShared-3giNWE3H.mjs → shopShared-COuQ2MhQ.mjs} +2 -2
  143. package/dist/client/spam-protection.mjs +1 -1
  144. package/dist/client/{src-CmXh3JWs.mjs → src-Do_s2lqH.mjs} +11 -18
  145. package/dist/client/{timetableModel-GA-hn1qM.mjs → timetableModel-DqI6U1BS.mjs} +11 -8
  146. package/dist/client/{urlParams-C2QHo1Pa.mjs → useAutomaticDiscountPreview-CeVUVzGf.mjs} +44 -1
  147. package/dist/client/{useAvailableSlots-CBneCxbG.mjs → useAvailableSlots-B0mjVhZr.mjs} +2 -2
  148. package/dist/client/{useDiscountCodeUi-D0kGF0C7.mjs → useDiscountCodeUi-B_hfgdAP.mjs} +6 -2
  149. package/dist/client/{useEventPagination-xX8n_Tuu.mjs → useEventPagination-Ct4A6iR1.mjs} +14 -16
  150. package/dist/client/{view-DOyZc-DF.mjs → view-Cj151w4m.mjs} +24 -9
  151. package/dist/client/{wizardSteps-B952ify5.mjs → wizardSteps-B3gsXNnb.mjs} +283 -222
  152. package/dist/preview-next/client/{EventEmbeddedCheckoutStep-aRJjq4x8.mjs → EventEmbeddedCheckoutStep-CVy9oapv.mjs} +1 -1
  153. package/dist/preview-next/client/{LocationPickerEnvironment-BW3dRFIv.mjs → LocationPickerEnvironment-DuRUwUrK.mjs} +1 -1
  154. package/dist/preview-next/client/{MapLibreEditMap-Db9BHyXh.mjs → MapLibreEditMap-CdSDYBq9.mjs} +2 -2
  155. package/dist/preview-next/client/{PageSectionToolbar-BI3UCdpu.mjs → PageSectionToolbar-Dv4CW0AQ.mjs} +952 -138
  156. package/dist/preview-next/client/{PreviewEditorSidebar-jkfLVOgY.mjs → PreviewEditorSidebar-B7WW58uE.mjs} +4774 -2040
  157. package/dist/preview-next/client/{PreviewEditorUI-DwJQs4hM.mjs → PreviewEditorUI-BnJ1ughv.mjs} +71 -47
  158. package/dist/preview-next/client/{PreviewShell-BAxAkuz8.mjs → PreviewShell-C7qWzAe4.mjs} +72 -40
  159. package/dist/preview-next/client/{SdkPreviewModeRuntime-0UVB-39f.mjs → SdkPreviewModeRuntime-CYi4UHtG.mjs} +135 -30
  160. package/dist/preview-next/client/{ThemedButton-CVYz7h68.mjs → ThemedButton-CRgbU75r.mjs} +799 -17
  161. package/dist/preview-next/client/{lucide-react-00FF_oar.mjs → lucide-react-B4c6U3ZU.mjs} +11 -1
  162. package/dist/preview-next/client/{previewAssistantSlot-BgiYk3PB.mjs → previewAssistantSlot-DrUoRNu9.mjs} +24203 -9291
  163. package/dist/preview-next/client/{previewChromeRoot-tieNdF3E.mjs → previewChromeRoot-CEYp90mM.mjs} +3 -90
  164. package/dist/preview-next/client/runtime.mjs +3 -3
  165. package/dist/preview-next/client/{sdk-runtime-DXb_Evl0.mjs → sdk-runtime-DnO2_c0A.mjs} +2 -2
  166. package/dist/preview-next/client/{siteStyleAccess-BlN0jt2c.mjs → siteStyleAccess-B3PwHw2z.mjs} +46 -11
  167. package/dist/preview-next/client/{useAutosaveStatus-BUEPA4oL.mjs → useAutosaveStatus-DrdQ4ier.mjs} +49 -3
  168. package/dist/preview-next/client/{useOpenBlockForSetup-BVfr5P--.mjs → useOpenBlockForSetup-kuGRKaRL.mjs} +2008 -448
  169. package/dist/preview-next/container-responsive.css +469 -2
  170. package/dist/preview-next/editor-chrome.css +23 -2
  171. package/dist/preview-next/keepAlive.mjs +1 -1
  172. package/dist/preview-next/middleware.mjs +1 -1
  173. package/dist/preview-next/{route-contract-BHTBA48n.mjs → route-contract-CwrXkLT3.mjs} +177 -43
  174. package/dist/server/{Block.shared-hGoyEdjJ.mjs → Block.shared-C5ucphCJ.mjs} +5 -5
  175. package/dist/server/{ThemeScopeCore-BfUCTOwj.mjs → ThemeScopeCore-DvbqYXdK.mjs} +46 -10
  176. package/dist/server/{accessibleSurfaces-Dskni4Xj.mjs → accessibleSurfaces-CAcf1lHT.mjs} +732 -176
  177. package/dist/server/{accordions-By_0Ykks.mjs → accordions-DjcsqjCK.mjs} +1 -1
  178. package/dist/server/{bindings-DMJH4bvo.mjs → bindings-CFw4M-gZ.mjs} +69 -248
  179. package/dist/server/{client-DrwlRNAH.mjs → client-D0XCgITW.mjs} +488 -119
  180. package/dist/server/config-validation.mjs +1 -1
  181. package/dist/server/config.mjs +2 -2
  182. package/dist/server/{constants-CeMywaiD.mjs → constants-BZduY8jG.mjs} +31 -8
  183. package/dist/server/data/resolveBlockData.mjs +1 -1
  184. package/dist/server/index.mjs +4 -4
  185. package/dist/server/{loadContent-D0prFflT.mjs → loadContent-C-qyB8Tq.mjs} +11 -10
  186. package/dist/server/{loadPage-CBLke9pJ.mjs → loadPage-BpKKmi8E.mjs} +3 -3
  187. package/dist/server/lookMediaFrame-EFws7tAj.mjs +31835 -0
  188. package/dist/server/manifest.mjs +2 -2
  189. package/dist/server/{navigation-wrcuWmgp.mjs → navigation-DYkuiNXa.mjs} +1 -1
  190. package/dist/server/navigation.mjs +1 -1
  191. package/dist/server/next.mjs +9 -9
  192. package/dist/server/{overrideResolution-DUgCEH8z.mjs → overrideResolution-DmZn4xUE.mjs} +1 -1
  193. package/dist/server/page-converter.mjs +18 -5
  194. package/dist/server/{pageRenderPlan-BHrmogsW.mjs → pageRenderPlan-DRB7cUZ0.mjs} +674 -298
  195. package/dist/server/{pageRuntimeSupport-D2-YMRei.mjs → pageRuntimeSupport-Uv1xDieJ.mjs} +13 -6
  196. package/dist/server/{pageShared-CG8O31Eo.mjs → pageShared-BdQF875z.mjs} +911 -516
  197. package/dist/server/{parseThemeForPersistence-CrPlbJEN.mjs → parseThemeForPersistence-CwcWZL7u.mjs} +3 -3
  198. package/dist/server/{portal-pG_uhsI2.mjs → portal-BQ8qiQnk.mjs} +22 -2
  199. package/dist/server/portal.mjs +3 -3
  200. package/dist/server/{prebuild-C8Amvzce.mjs → prebuild-B51QZVNe.mjs} +1 -1
  201. package/dist/server/prebuild.mjs +1 -1
  202. package/dist/server/{prefetchBlockData-BxUETRIZ.mjs → prefetchBlockData-CppDAfJW.mjs} +4 -4
  203. package/dist/server/{registry-Cc88-23f.mjs → registry-Bf4W8Qa7.mjs} +7585 -24378
  204. package/dist/server/rendering/components/pageShared.mjs +1 -1
  205. package/dist/server/rendering/helpers/loadPage.mjs +1 -1
  206. package/dist/server/rendering/helpers/pageRuntimeSupport.mjs +1 -1
  207. package/dist/server/rendering/server.mjs +4 -4
  208. package/dist/server/rendering.mjs +10 -10
  209. package/dist/server/{resolveBlockData-OG3KOkig.mjs → resolveBlockData-DMHAZooQ.mjs} +2 -2
  210. package/dist/server/{expandPalette-ehuW8r2g.mjs → resolveButtonColourStates-BMtAAPzp.mjs} +1670 -1346
  211. package/dist/server/{responseMedia-IfH65QAH.mjs → responseMedia-DKYfR518.mjs} +1 -1
  212. package/dist/server/{schema-CwfxQjc4.mjs → schema-DGaihVwp.mjs} +300 -29
  213. package/dist/server/server.mjs +3 -3
  214. package/dist/server/{servicePageContent-BcFuhhD7.mjs → servicePageContent-CRvmreX7.mjs} +40 -16
  215. package/dist/server/theme-bridge.mjs +5 -4
  216. package/dist/server/theme.mjs +2 -2
  217. package/dist/server/{three-pass-converter-DPaUPTfl.mjs → three-pass-converter-mcy2E1Yd.mjs} +2 -2
  218. package/dist/server/{titleSourceSchema-NhK6azFS.mjs → titleSourceSchema-B2qFOUwZ.mjs} +4 -5
  219. package/dist/server/{typeGuards-CTW_9AXq.mjs → typeGuards-DZOaGTEv.mjs} +126 -126
  220. package/dist/server/{types-BKaBZFjD.mjs → types-C_S0pWbR.mjs} +487 -9
  221. package/dist/server/{validation-BovmbS8N.mjs → validation-CUtNT_EZ.mjs} +14 -10
  222. package/dist/server/{version-hws4hgyX.mjs → version-DebJQ4zn.mjs} +1 -1
  223. package/dist/server/{video-Cdr3wh-q.mjs → video-DBaeSawZ.mjs} +1 -1
  224. package/dist/styles/index.css +2987 -168
  225. package/package.json +1 -1
  226. package/dist/client/gifting.parts-Bak93gD2.mjs +0 -86
  227. package/dist/client/runtimeResponse-nXT8VAMl.mjs +0 -3
  228. package/dist/client/types-BEaKfam_.mjs +0 -778
  229. package/dist/server/customCss-C9kgPHvr.mjs +0 -247
  230. package/dist/server/lookMediaFrame-H0fi4bJk.mjs +0 -2701
  231. package/dist/server/media-gvfIw3z8.mjs +0 -216
@@ -1,4 +1,5 @@
1
- import { G as paletteColorsFromEntries, H as isThemeColorToken, J as parseColorTokenParts, U as normalizePaletteHex, V as hexColorSchema, c as buttonEffectApplicationSchema, m as parseOpaqueButtonColourToken, q as paletteModeSchema, s as unsafeAsOpaqueButtonColourToken, w as surfaceForegroundValue, z as PALETTE_TOKEN_NAMES } from "./types-BKaBZFjD.mjs";
1
+ import { $ as parseColorTokenParts, J as normalizePaletteHex, K as hexColorSchema, O as surfaceForegroundValue, Q as paletteModeSchema, U as PALETTE_TOKEN_NAMES, W as absoluteInkColors, X as paletteColorsFromEntries, c as buttonEffectApplicationSchema, m as parseOpaqueButtonColourToken, q as isThemeColorToken, s as unsafeAsOpaqueButtonColourToken } from "./types-C_S0pWbR.mjs";
2
+ import { o as err, s as ok, t as parseMediaAssetId } from "./media-BRmYrnzb.mjs";
2
3
  import { z } from "zod";
3
4
  //#region ../theme-core/src/palette/utils/colorConversion.ts
4
5
  const clamp01 = (x) => Math.max(0, Math.min(1, x));
@@ -321,91 +322,6 @@ const paletteValueKeySchema = z.string().transform((value, ctx) => {
321
322
  return z.NEVER;
322
323
  });
323
324
  //#endregion
324
- //#region ../theme-core/src/palette/utils/opaqueSurfaceColor.ts
325
- /** Resolve an opaque colour, compositing alpha against an explicit underlay. */
326
- function resolveOpaqueSurfaceHex(reference, palette, underlayReference) {
327
- const opaque = resolveConcreteColorHex(reference, palette);
328
- if (opaque) return opaque;
329
- if (!underlayReference) return null;
330
- const underlayHex = resolveConcreteColorHex(underlayReference, palette);
331
- if (!underlayHex) return null;
332
- const parts = parseColorTokenParts(reference);
333
- if (parts.kind === "token" && parts.opacityPercent !== null) {
334
- const foregroundHex = normalizePaletteHex(palette[parts.token] ?? "");
335
- return foregroundHex ? compositeHex$1(foregroundHex, underlayHex, parts.opacityPercent / 100) : null;
336
- }
337
- const rgba = parseRgba(parts.kind === "raw" ? parts.value : reference);
338
- return rgba ? compositeHex$1(rgbToHex(rgba.r, rgba.g, rgba.b), underlayHex, rgba.alpha) : null;
339
- }
340
- /** Resolve a colour reference only when it is already fully opaque. */
341
- function resolveConcreteColorHex(reference, palette) {
342
- const literalHex = normalizePaletteHex(reference);
343
- if (literalHex) return literalHex;
344
- const parts = parseColorTokenParts(reference);
345
- if (parts.kind === "token") {
346
- if (parts.opacityPercent !== null) return null;
347
- return normalizePaletteHex(palette[parts.token] ?? "");
348
- }
349
- const literal = parts.kind === "raw" ? parts.value : reference;
350
- if (literal.toLowerCase() === "black") return "#000000";
351
- if (literal.toLowerCase() === "white") return "#ffffff";
352
- return normalizePaletteHex(literal);
353
- }
354
- function compositeHex$1(foregroundHex, underlayHex, alpha) {
355
- const foreground = hexToRgb(foregroundHex);
356
- const underlay = hexToRgb(underlayHex);
357
- const channel = (foregroundValue, underlayValue) => Math.round(foregroundValue * alpha + underlayValue * (1 - alpha));
358
- return rgbToHex(channel(foreground.r, underlay.r), channel(foreground.g, underlay.g), channel(foreground.b, underlay.b));
359
- }
360
- function parseRgba(value) {
361
- const match = value.trim().match(/^rgba?\(\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*(?:,|\/)\s*([\d.]+%?))?\s*\)$/i);
362
- if (!match) return null;
363
- const [, rSource, gSource, bSource] = match;
364
- if (!rSource || !gSource || !bSource) return null;
365
- const r = Number(rSource);
366
- const g = Number(gSource);
367
- const b = Number(bSource);
368
- const alpha = parseAlpha(match[4]);
369
- if (alpha === null || !isRgbChannel(r) || !isRgbChannel(g) || !isRgbChannel(b)) return null;
370
- return {
371
- r,
372
- g,
373
- b,
374
- alpha
375
- };
376
- }
377
- function parseAlpha(source) {
378
- if (!source) return 1;
379
- const value = source.endsWith("%") ? Number(source.slice(0, -1)) / 100 : Number(source);
380
- return Number.isFinite(value) && value >= 0 && value <= 1 ? value : null;
381
- }
382
- function isRgbChannel(value) {
383
- return Number.isFinite(value) && value >= 0 && value <= 255;
384
- }
385
- //#endregion
386
- //#region ../theme-core/src/palette/utils/onColor.ts
387
- const BACKGROUND_ROLE_NAMES = /* @__PURE__ */ new Set([
388
- "primary",
389
- "secondary",
390
- "accent",
391
- "success",
392
- "warning",
393
- "destructive",
394
- "info",
395
- "background",
396
- "surface",
397
- "surfaceAlt",
398
- "muted",
399
- "neutral"
400
- ]);
401
- function onColorTokenName(backgroundToken) {
402
- return `on${backgroundToken.split("-").filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")}`;
403
- }
404
- function isOnColorBackgroundCandidateToken(token) {
405
- const role = token.match(/^(.*?)(?:-\d{2,3})?$/)?.[1] ?? token;
406
- return BACKGROUND_ROLE_NAMES.has(role);
407
- }
408
- //#endregion
409
325
  //#region \0@oxc-project+runtime@0.137.0/helpers/esm/assertClassBrand.js
410
326
  function _assertClassBrand(e, t, n) {
411
327
  if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
@@ -666,12 +582,12 @@ function paletteInkOnSolid(groundHex, roles) {
666
582
  }
667
583
  /**
668
584
  * The ink as token emitters write it: the role's theme token, so CSS follows
669
- * the palette's variables, or the literal hex.
585
+ * the palette's variables, or a fixed absolute black/white token.
670
586
  */
671
587
  function paletteInkToken(ink) {
672
- if (ink.kind === "literal") return ink.hex;
673
- if (!isThemeColorToken(ink.role)) throw new Error(`Palette ink role is not a theme token: ${ink.role}`);
674
- return ink.role;
588
+ const token = ink.kind === "role" ? ink.role : ink.hex === "#000000" ? "absoluteBlack" : "absoluteWhite";
589
+ if (!isThemeColorToken(token)) throw new Error(`Palette ink is not a theme token: ${token}`);
590
+ return token;
675
591
  }
676
592
  /**
677
593
  * Secondary text that has to read on several grounds (a surface and the tinted
@@ -714,1004 +630,1152 @@ function paletteMutedInkOnSolid(ground, preferred, roles) {
714
630
  return ink.hex;
715
631
  }
716
632
  //#endregion
717
- //#region ../theme-core/src/palette/utils/textColor.ts
718
- /**
719
- * Pick the better of black/white text for a given background using actual
720
- * contrast ratios, not a simple luminance cutoff. This is
721
- * `maxContrastBlackOrWhite` for a solid ground. It is the literal fallback
722
- * only: where a palette is in scope, `paletteInkOnSolid` tries the site's own
723
- * background and text colours first.
724
- *
725
- * @param background - Background color in hex or rgb/rgba format (e.g., '#FFFFFF' or 'rgb(255, 255, 255)')
726
- * @param _minContrast - Kept for callers. It cannot change the result: when
727
- * only one of black or white reaches it, that one is also the better of the two.
728
- * @returns '#000000' for light backgrounds, '#FFFFFF' for dark backgrounds
729
- */
730
- function pickBlackOrWhiteTextColor(background, _minContrast = 4.5) {
731
- const { r, g, b } = parseColorToRgb(background);
732
- return literalInkHex(maxContrastBlackOrWhite(luminanceInterval(relativeLuminance(r, g, b))).ink);
633
+ //#region ../theme-core/src/palette/utils/opaqueSurfaceColor.ts
634
+ /** Resolve an opaque colour, compositing alpha against an explicit underlay. */
635
+ function resolveOpaqueSurfaceHex(reference, palette, underlayReference) {
636
+ const opaque = resolveConcreteColorHex(reference, palette);
637
+ if (opaque) return opaque;
638
+ if (!underlayReference) return null;
639
+ const underlayHex = resolveConcreteColorHex(underlayReference, palette);
640
+ if (!underlayHex) return null;
641
+ const parts = parseColorTokenParts(reference);
642
+ if (parts.kind === "token" && parts.opacityPercent !== null) {
643
+ const foregroundHex = resolveConcreteColorHex(parts.token, palette);
644
+ return foregroundHex ? compositeHex$1(foregroundHex, underlayHex, parts.opacityPercent / 100) : null;
645
+ }
646
+ const rgba = parseRgba(parts.kind === "raw" ? parts.value : reference);
647
+ return rgba ? compositeHex$1(rgbToHex(rgba.r, rgba.g, rgba.b), underlayHex, rgba.alpha) : null;
733
648
  }
734
- function parseColorToRgb(input) {
735
- const trimmed = input.trim();
736
- if (trimmed.startsWith("#")) return hexToRgb(trimmed);
737
- const rgbMatch = trimmed.match(/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)$/i);
738
- if (rgbMatch?.[1] && rgbMatch[2] && rgbMatch[3]) return {
739
- r: clamp255(Number(rgbMatch[1])),
740
- g: clamp255(Number(rgbMatch[2])),
741
- b: clamp255(Number(rgbMatch[3]))
649
+ /** Resolve a colour reference only when it is already fully opaque. */
650
+ function resolveConcreteColorHex(reference, palette) {
651
+ const literalHex = normalizePaletteHex(reference);
652
+ if (literalHex) return literalHex;
653
+ const parts = parseColorTokenParts(reference);
654
+ if (parts.kind === "token") {
655
+ if (parts.opacityPercent !== null) return null;
656
+ return normalizePaletteHex((parts.token === "absoluteBlack" || parts.token === "absoluteWhite" ? absoluteInkColors[parts.token] : palette[parts.token]) ?? "");
657
+ }
658
+ const literal = parts.kind === "raw" ? parts.value : reference;
659
+ if (literal.toLowerCase() === "black") return "#000000";
660
+ if (literal.toLowerCase() === "white") return "#ffffff";
661
+ return normalizePaletteHex(literal);
662
+ }
663
+ function compositeHex$1(foregroundHex, underlayHex, alpha) {
664
+ const foreground = hexToRgb(foregroundHex);
665
+ const underlay = hexToRgb(underlayHex);
666
+ const channel = (foregroundValue, underlayValue) => Math.round(foregroundValue * alpha + underlayValue * (1 - alpha));
667
+ return rgbToHex(channel(foreground.r, underlay.r), channel(foreground.g, underlay.g), channel(foreground.b, underlay.b));
668
+ }
669
+ function parseRgba(value) {
670
+ const match = value.trim().match(/^rgba?\(\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*(?:,|\/)\s*([\d.]+%?))?\s*\)$/i);
671
+ if (!match) return null;
672
+ const [, rSource, gSource, bSource] = match;
673
+ if (!rSource || !gSource || !bSource) return null;
674
+ const r = Number(rSource);
675
+ const g = Number(gSource);
676
+ const b = Number(bSource);
677
+ const alpha = parseAlpha(match[4]);
678
+ if (alpha === null || !isRgbChannel(r) || !isRgbChannel(g) || !isRgbChannel(b)) return null;
679
+ return {
680
+ r,
681
+ g,
682
+ b,
683
+ alpha
742
684
  };
743
- throw new Error("Unsupported color format");
744
685
  }
745
- function clamp255(value) {
746
- if (Number.isNaN(value)) return 0;
747
- return Math.max(0, Math.min(255, value));
686
+ function parseAlpha(source) {
687
+ if (!source) return 1;
688
+ const value = source.endsWith("%") ? Number(source.slice(0, -1)) / 100 : Number(source);
689
+ return Number.isFinite(value) && value >= 0 && value <= 1 ? value : null;
690
+ }
691
+ function isRgbChannel(value) {
692
+ return Number.isFinite(value) && value >= 0 && value <= 255;
748
693
  }
749
694
  //#endregion
750
- //#region ../theme-core/src/buttons/constants.ts
695
+ //#region ../theme-core/src/palette/generateShades.ts
696
+ function generateShades(hexColor, name) {
697
+ const shadeSteps = [
698
+ 50,
699
+ 100,
700
+ 200,
701
+ 300,
702
+ 400,
703
+ 500,
704
+ 600,
705
+ 700,
706
+ 800,
707
+ 900,
708
+ 950
709
+ ];
710
+ const base = featuresFromHex(hexColor);
711
+ const hue = base.okH;
712
+ const baseChroma = base.okC;
713
+ const toneMap = {
714
+ 50: .975,
715
+ 100: .945,
716
+ 200: .89,
717
+ 300: .82,
718
+ 400: .74,
719
+ 500: .66,
720
+ 600: .58,
721
+ 700: .49,
722
+ 800: .4,
723
+ 900: .28,
724
+ 950: .16
725
+ };
726
+ const shadeDefs = shadeSteps.map((step, idx) => {
727
+ const t = idx / (shadeSteps.length - 1);
728
+ const L = toneMap[step];
729
+ const C = baseChroma * (.06 + .94 * Math.sin(Math.PI * t));
730
+ return {
731
+ name: `${name}-${step}`,
732
+ hex: oklchToHexGamut(L, C, hue)
733
+ };
734
+ });
735
+ shadeDefs.push({
736
+ name,
737
+ hex: hexColor
738
+ });
739
+ return shadeDefs;
740
+ }
741
+ //#endregion
742
+ //#region ../theme-core/src/palette/neutralScale.ts
743
+ /** The cool slate tint every scale had before #1863, kept for grounds with no hue to lend. */
744
+ const SLATE_NEUTRAL_TINT = {
745
+ hue: 250,
746
+ chroma: .02
747
+ };
748
+ /** Below this OKLCH chroma a background reads as plain white, grey or black, so its hue is noise. */
749
+ const ACHROMATIC_CHROMA = .005;
751
750
  /**
752
- * Shared constants for button CSS generation
753
- *
754
- * These mappings convert Tailwind-style tokens to actual CSS values.
755
- * Centralized here to eliminate duplication across multiple files.
751
+ * The tint a palette's greys take from its background: the background's own
752
+ * hue at no more than the slate scale's chroma, so a cream site gets warm greys.
753
+ * A background with no hue to lend (white, `#fafafa`, a missing or unreadable
754
+ * value) keeps the slate tint, so those palettes keep their exact neutrals.
756
755
  */
756
+ function neutralTint(background) {
757
+ const parsed = hexColorSchema.safeParse(background?.toLowerCase());
758
+ if (!parsed.success) return SLATE_NEUTRAL_TINT;
759
+ const { r, g, b } = hexToRgb(parsed.data);
760
+ const { L, a, b: ob } = srgbToOklab(r, g, b);
761
+ const { C, h } = oklabToOklch(L, a, ob);
762
+ return C < ACHROMATIC_CHROMA ? SLATE_NEUTRAL_TINT : {
763
+ hue: h,
764
+ chroma: Math.min(C, SLATE_NEUTRAL_TINT.chroma)
765
+ };
766
+ }
757
767
  /**
758
- * Map Tailwind-style gradient direction tokens to CSS gradient directions
768
+ * A neutral scale from near-white (`neutral-50`) to near-black (`neutral-950`)
769
+ * on every palette, light or dark. Readers that want "the ground" or "the
770
+ * text" ask the palette for those roles, not a fixed end of this scale.
759
771
  */
760
- const GRADIENT_DIRECTION_MAP = {
761
- "to-r": "to right",
762
- "to-l": "to left",
763
- "to-t": "to top",
764
- "to-b": "to bottom",
765
- "to-br": "to bottom right",
766
- "to-bl": "to bottom left",
767
- "to-tr": "to top right",
768
- "to-tl": "to top left"
769
- };
770
- /**
771
- * Map Tailwind border-radius tokens to CSS values
772
- */
773
- const BORDER_RADIUS_MAP = {
774
- "rounded-none": "0",
775
- "rounded-3px": "3px",
776
- "rounded-10px": "10px",
777
- "rounded-sm": "0.125rem",
778
- "rounded": "0.25rem",
779
- "rounded-md": "0.375rem",
780
- "rounded-lg": "0.5rem",
781
- "rounded-xl": "0.75rem",
782
- "rounded-2xl": "1rem",
783
- "rounded-3xl": "1.5rem",
784
- "rounded-full": "9999px"
785
- };
786
- /**
787
- * Pixel offset per shadow elevation. Single source of truth shared by
788
- * `generateShadowValue` (the base box-shadow offset) and the `press-down`
789
- * effect (which translates the button by the same offset on hover). Keeping
790
- * these in one place ensures the "press into the shadow" illusion stays exact.
791
- */
792
- const ELEVATION_OFFSET = {
793
- none: 0,
794
- low: 2,
795
- medium: 4,
796
- high: 6
797
- };
772
+ function generateNeutralScale({ steps = 11, tint = SLATE_NEUTRAL_TINT } = {}) {
773
+ const shadeNames = [
774
+ 50,
775
+ 100,
776
+ 200,
777
+ 300,
778
+ 400,
779
+ 500,
780
+ 600,
781
+ 700,
782
+ 800,
783
+ 900,
784
+ 950
785
+ ];
786
+ const count = Math.min(steps, shadeNames.length);
787
+ return shadeNames.slice(0, count).map((shadeName, index) => ({
788
+ name: `neutral-${shadeName}`,
789
+ hex: oklchToHexGamut(mix(.98, .1, index / (count - 1)), tint.chroma, tint.hue)
790
+ }));
791
+ }
792
+ function mix(a, b, t) {
793
+ return a + (b - a) * Math.max(0, Math.min(1, t));
794
+ }
795
+ //#endregion
796
+ //#region ../theme-core/src/palette/utils/scrimContrast.ts
797
+ const WHITE = "#ffffff";
798
+ const BLACK = "#000000";
799
+ /** `top` at `alpha` over opaque `bottom`, blended as CSS paints an overlay. */
800
+ function compositeHex(topHex, alpha, bottomHex) {
801
+ const top = hexToRgb(topHex);
802
+ const bottom = hexToRgb(bottomHex);
803
+ const mix = (a, b) => Math.round(alpha * a + (1 - alpha) * b);
804
+ return rgbToHex(mix(top.r, bottom.r), mix(top.g, bottom.g), mix(top.b, bottom.b));
805
+ }
798
806
  /**
799
- * Generate shadow CSS value dynamically based on elevation, softness, and position
800
- *
801
- * This replaces the static shadow maps with a single dynamic function.
802
- * Benefits: single source of truth, easy to adjust algorithm, no redundancy.
803
- *
804
- * @param elevation - Shadow elevation level
805
- * @param softness - Shadow softness/blur style
806
- * @param position - Shadow position (bottom or bottom-right diagonal)
807
- * @returns CSS box-shadow value
807
+ * The lowest contrast `foreground` can reach over `scrim` at `alpha` laid on
808
+ * any pixel. A foreground whose luminance falls inside the range the
809
+ * composites can take has a worst case of 1:1.
808
810
  */
809
- function generateShadowValue(elevation, softness, position = "bottom", color) {
810
- if (elevation === "none") return "none";
811
- const config = {
812
- low: {
813
- blur: 4,
814
- spread: 0
815
- },
816
- medium: {
817
- blur: 8,
818
- spread: -1
819
- },
820
- high: {
821
- blur: 12,
822
- spread: -2
823
- }
824
- }[elevation];
825
- const baseOffset = ELEVATION_OFFSET[elevation];
826
- const xOffset = position === "bottom-right" ? baseOffset : 0;
827
- const yOffset = baseOffset;
828
- switch (softness) {
829
- case null:
830
- case "soft": return `${xOffset}px ${yOffset}px ${config.blur}px ${config.spread}px ${color ?? "rgb(0 0 0 / 0.3)"}`;
831
- case "hard": return `${xOffset}px ${yOffset}px 0 0 ${color ?? "rgb(0 0 0 / 1)"}`;
832
- case "crisp": return `${xOffset}px ${yOffset}px ${baseOffset}px ${config.spread}px ${color ?? "rgb(0 0 0 / 0.4)"}`;
833
- }
811
+ function worstCaseScrimContrast(input) {
812
+ const overWhite = compositeHex(input.scrimHex, input.alpha, WHITE);
813
+ const overBlack = compositeHex(input.scrimHex, input.alpha, BLACK);
814
+ const luminance = (hex) => {
815
+ const { r, g, b } = hexToRgb(hex);
816
+ return relativeLuminance(r, g, b);
817
+ };
818
+ const foreground = luminance(input.foregroundHex);
819
+ const low = luminance(overBlack);
820
+ const high = luminance(overWhite);
821
+ if (foreground >= low && foreground <= high) return 1;
822
+ return Math.min(contrastRatio(input.foregroundHex, overWhite), contrastRatio(input.foregroundHex, overBlack));
834
823
  }
835
824
  /**
836
- * Map Tailwind border-width tokens to CSS values
825
+ * The smallest scrim opacity, in hundredths, at which every foreground keeps
826
+ * `threshold` contrast over any pixel. `null` when even an opaque scrim fails,
827
+ * which means the foreground was never legible on the scrim colour itself.
837
828
  */
838
- const BORDER_WIDTH_MAP = {
839
- "border-0": "0px",
840
- "border": "1px",
841
- "border-2": "2px",
842
- "border-4": "4px",
843
- "border-8": "8px"
844
- };
845
- /**
846
- * Map Tailwind font-size tokens to CSS values
829
+ function minimumScrimOpacity(input) {
830
+ const passes = (alpha) => input.foregroundHexes.every((foregroundHex) => worstCaseScrimContrast({
831
+ foregroundHex,
832
+ scrimHex: input.scrimHex,
833
+ alpha
834
+ }) >= input.threshold);
835
+ return Array.from({ length: 101 }, (_, hundredths) => hundredths / 100).find(passes) ?? null;
836
+ }
837
+ /** Shared samples for literal RGB washes and palette-token gradient veils. */
838
+ function gradientScrimSamples(gradient, alpha, palette) {
839
+ const literal = [...gradient.matchAll(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/g)].map((stop) => ({
840
+ hex: rgbToHex(Number(stop[1]), Number(stop[2]), Number(stop[3])),
841
+ alpha: alpha * (stop[4] === void 0 ? 1 : Number(stop[4]))
842
+ }));
843
+ const tokens = [...gradient.matchAll(/var\(--tb-([\w-]+)\)/g)].flatMap((stop) => {
844
+ const hex = stop[1] ? resolveConcreteColorHex(stop[1], palette) : null;
845
+ return hex ? [{
846
+ hex,
847
+ alpha
848
+ }] : [];
849
+ });
850
+ return [...literal, ...tokens];
851
+ }
852
+ /** The ink with the stronger worst-pixel guarantee identifies the veil tone.
853
+ * No readable samples (or a tie) leaves classification to the foreground owner.
847
854
  */
848
- const FONT_SIZE_MAP = {
849
- "text-xs": "0.75rem",
850
- "text-13px": "0.8125rem",
851
- "text-15px": "0.9375rem",
852
- "text-17px": "1.0625rem",
853
- "text-19px": "1.1875rem",
854
- "text-sm": "0.875rem",
855
- "text-base": "1rem",
856
- "text-lg": "1.125rem",
857
- "text-xl": "1.25rem",
858
- "text-2xl": "1.5rem"
859
- };
855
+ function scrimTone(samples) {
856
+ if (samples.length === 0) return null;
857
+ const worst = (foregroundHex) => Math.min(...samples.map((sample) => worstCaseScrimContrast({
858
+ foregroundHex,
859
+ scrimHex: sample.hex,
860
+ alpha: sample.alpha
861
+ })));
862
+ const white = worst(WHITE);
863
+ const black = worst(BLACK);
864
+ return white === black ? null : white > black ? "dark" : "light";
865
+ }
866
+ //#endregion
867
+ //#region ../theme-core/src/palette/utils/textColor.ts
860
868
  /**
861
- * System defaults used when a theme doesn't supply its own `theme.buttons.sizes`.
869
+ * Pick the better of black/white text for a given background using actual
870
+ * contrast ratios, not a simple luminance cutoff. This is
871
+ * `maxContrastBlackOrWhite` for a solid ground. It is the literal fallback
872
+ * only: where a palette is in scope, `paletteInkOnSolid` tries the site's own
873
+ * background and text colours first.
862
874
  *
863
- * Every size is defined so the size class CSS always emits a complete rule and
864
- * variants are never naked. Referenced by `generateButtonCss` and surfaceable
865
- * from UI ("Showing default size ramp") without duplicating the values.
875
+ * @param background - Background color in hex or rgb/rgba format (e.g., '#FFFFFF' or 'rgb(255, 255, 255)')
876
+ * @param _minContrast - Kept for callers. It cannot change the result: when
877
+ * only one of black or white reaches it, that one is also the better of the two.
878
+ * @returns '#000000' for light backgrounds, '#FFFFFF' for dark backgrounds
866
879
  */
867
- const DEFAULT_BUTTON_SIZES = {
868
- sm: {
869
- padding: "0.5rem 1rem",
870
- fontSize: "text-sm"
871
- },
872
- md: { padding: "0.75rem 1.5rem" },
873
- lg: {
874
- padding: "1rem 2rem",
875
- fontSize: "text-lg"
876
- },
877
- xl: {
878
- padding: "1.25rem 2.5rem",
879
- fontSize: "text-xl"
880
- }
881
- };
882
- //#endregion
883
- //#region ../theme-core/src/buttons/buttonColourContract.ts
884
- const BUTTON_CONTRAST_POLICY = {
885
- textMinimumRatio: 4.5,
886
- nonTextMinimumRatio: 3,
887
- filledMinimumDeltaE: .12,
888
- gradientSamplesPerSegment: 20,
889
- alphaBackgrounds: "reject-without-known-surface",
890
- disabled: "validated-colour-pair-with-muted-control-opacity"
891
- };
892
- function formatButtonColourContractError(error) {
893
- switch (error.tag) {
894
- case "unknown_palette_token": return `Button "${error.variantId}" ${error.state} state uses unknown palette token "${error.token}".`;
895
- case "insufficient_contrast": return `Button "${error.variantId}" ${error.state} state has ${error.ratio.toFixed(2)}:1 contrast (${error.requiredRatio}:1 required).`;
896
- case "insufficient_surface_separation": return `Button "${error.variantId}" ${error.state} state is indistinguishable from its surface at OKLab distance ${error.deltaE.toFixed(3)} (${error.requiredDeltaE} required).`;
897
- case "unsupported_colour_effect": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" is not contrast-safe (${error.reason}).`;
898
- case "invalid_colour_effect_options": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" has an invalid ${error.option} option.`;
899
- case "inapplicable_colour_effect": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" cannot apply to a ${error.treatment} treatment.`;
900
- case "unknown_button_effect": return `Button "${error.variantId}" ${error.state} uses unknown effect "${error.effectId}".`;
901
- }
880
+ function pickBlackOrWhiteTextColor(background, _minContrast = 4.5) {
881
+ const { r, g, b } = parseColorToRgb(background);
882
+ return literalInkHex(maxContrastBlackOrWhite(luminanceInterval(relativeLuminance(r, g, b))).ink);
902
883
  }
903
- /** One separation decision for filled states and contextual hover candidates. */
904
- function buttonFillSeparation(fill, ground) {
905
- const deltaE = hexOklabDistance(fill, ground);
906
- return {
907
- deltaE,
908
- distinct: deltaE >= BUTTON_CONTRAST_POLICY.filledMinimumDeltaE
884
+ function parseColorToRgb(input) {
885
+ const trimmed = input.trim();
886
+ if (trimmed.startsWith("#")) return hexToRgb(trimmed);
887
+ const rgbMatch = trimmed.match(/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)$/i);
888
+ if (rgbMatch?.[1] && rgbMatch[2] && rgbMatch[3]) return {
889
+ r: clamp255(Number(rgbMatch[1])),
890
+ g: clamp255(Number(rgbMatch[2])),
891
+ b: clamp255(Number(rgbMatch[3]))
909
892
  };
893
+ throw new Error("Unsupported color format");
910
894
  }
911
- /** All paint beneath the control; ordinary solids have just one ground. */
912
- const buttonSurfaceGrounds = (surface) => [surface.backgroundHex, ...surface.backgroundSamples ?? []];
913
- /** A filled state clears each ground by its fill OR a declared edge at 3:1. */
914
- function buttonSurfaceSeparation(fill, surface, edge) {
915
- return buttonGroundSeparation(fill, buttonSurfaceGrounds(surface), edge);
895
+ function clamp255(value) {
896
+ if (Number.isNaN(value)) return 0;
897
+ return Math.max(0, Math.min(255, value));
916
898
  }
917
- /** The worst ground for a fill: the first it fails to stand out from, otherwise the closest. */
918
- function buttonGroundSeparation(fill, grounds, edge) {
919
- const ink = edge?.border?.marksBoundary ? edge.border.boundaryInk ? edge.palette[edge.border.boundaryInk] : edge.labelInk : void 0;
920
- return grounds.map((ground) => {
921
- const separation = buttonFillSeparation(fill, ground);
922
- const distinct = separation.distinct || ink !== void 0 && contrastRatio(ink, ground) >= BUTTON_CONTRAST_POLICY.nonTextMinimumRatio;
923
- return {
924
- ...separation,
925
- distinct,
926
- ground
927
- };
928
- }).reduce((worst, next) => {
929
- if (worst.distinct !== next.distinct) return worst.distinct ? next : worst;
930
- return next.deltaE < worst.deltaE ? next : worst;
931
- });
932
- }
933
- function validateButtonFillSeparation(input) {
934
- const token = input.border?.marksBoundary ? input.border.boundaryInk : void 0;
935
- if (token && !input.palette[token]) return {
936
- ok: false,
937
- error: {
938
- tag: "unknown_palette_token",
939
- variantId: input.variantId,
940
- state: input.state,
941
- token
942
- }
943
- };
944
- const separation = buttonSurfaceSeparation(input.buttonPaint, input.surface, input);
945
- return separation.distinct ? { ok: true } : {
946
- ok: false,
947
- error: {
948
- tag: "insufficient_surface_separation",
949
- variantId: input.variantId,
950
- state: input.state,
951
- buttonPaint: input.buttonPaint,
952
- surface: separation.ground,
953
- deltaE: separation.deltaE,
954
- requiredDeltaE: BUTTON_CONTRAST_POLICY.filledMinimumDeltaE
955
- }
956
- };
957
- }
958
- function validateButtonTextContrast(input) {
959
- const ratio = contrastRatio(input.backgroundHex, input.foregroundHex, input.colourIndex);
960
- return ratio >= BUTTON_CONTRAST_POLICY.textMinimumRatio ? { ok: true } : {
961
- ok: false,
962
- error: {
963
- tag: "insufficient_contrast",
964
- variantId: input.variantId,
965
- state: input.state,
966
- background: input.background,
967
- foreground: input.foreground,
968
- ratio,
969
- requiredRatio: BUTTON_CONTRAST_POLICY.textMinimumRatio
970
- }
971
- };
899
+ //#endregion
900
+ //#region ../theme-core/src/palette/utils/onColor.ts
901
+ const BACKGROUND_ROLE_NAMES = /* @__PURE__ */ new Set([
902
+ "primary",
903
+ "secondary",
904
+ "accent",
905
+ "success",
906
+ "warning",
907
+ "destructive",
908
+ "info",
909
+ "background",
910
+ "surface",
911
+ "surfaceAlt",
912
+ "muted",
913
+ "neutral"
914
+ ]);
915
+ function onColorTokenName(backgroundToken) {
916
+ return `on${backgroundToken.split("-").filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")}`;
972
917
  }
973
- /** A text-token slab inverts the palette's text/background pair, including text shades. */
974
- function solidForegroundToken(backgroundToken) {
975
- return /^text(?:-\d+)?$/.test(backgroundToken) ? "background" : onColorTokenName(backgroundToken);
918
+ function isOnColorBackgroundCandidateToken(token) {
919
+ const role = token.match(/^(.*?)(?:-\d{2,3})?$/)?.[1] ?? token;
920
+ return BACKGROUND_ROLE_NAMES.has(role);
976
921
  }
977
922
  //#endregion
978
- //#region ../theme-core/src/buttons/effectClassification.ts
923
+ //#region ../theme-core/src/palette/expandPalette.ts
924
+ function colorsToMap(palette) {
925
+ const map = {};
926
+ for (const c of palette.colors) map[c.name] = c.hex;
927
+ return map;
928
+ }
929
+ const nonShadeablePaletteRoleNames = /* @__PURE__ */ new Set([
930
+ "success",
931
+ "warning",
932
+ "destructive"
933
+ ]);
979
934
  /**
980
- * Exhaustive live policy for every registered effect id.
935
+ * Status role aliases the persisted palette does not carry itself.
981
936
  *
982
- * The resolver consumes the transition payload directly, so adding an effect
983
- * cannot update classification without also defining its runtime behavior.
937
+ * Generators reference `--tb-error` (the site-style-owned input error border)
938
+ * and `--tb-info` (`.alert-info`, `.status-info`, the field-note rule), but the
939
+ * palette schema only defines `destructive` and has no `info` role at all.
940
+ * Without these aliases those declarations name variables that are never
941
+ * defined and browsers drop them. The SDK bridge resolves the same pair via
942
+ * TOKEN_ALIASES, so both runtimes agree on what a status token means.
943
+ *
944
+ * Runs after the danger → destructive promotion above, so `destructive` is
945
+ * already the single source of truth for the error colour.
984
946
  */
985
- const BUTTON_EFFECT_POLICIES = {
986
- "darken-background": {
987
- classification: "colour-transition",
988
- transition: {
989
- kind: "adjust-shade",
990
- direction: "darker"
991
- }
992
- },
993
- "lighten-background": {
994
- classification: "colour-transition",
995
- transition: {
996
- kind: "adjust-shade",
997
- direction: "lighter"
998
- }
999
- },
1000
- "background-on-hover": {
1001
- classification: "colour-transition",
1002
- transition: { kind: "replace-background" }
1003
- },
1004
- "background-on-hover-alpha": {
1005
- classification: "unsupported-colour",
1006
- reason: "alpha_requires_surface"
1007
- },
1008
- "fade-background": {
1009
- classification: "unsupported-colour",
1010
- reason: "changes_element_opacity"
1011
- },
1012
- "opacity-reduce": {
1013
- classification: "unsupported-colour",
1014
- reason: "changes_element_opacity"
1015
- },
1016
- "gradient-text": {
1017
- classification: "unsupported-colour",
1018
- reason: "changes_foreground"
1019
- },
1020
- "text-color-change": {
1021
- classification: "unsupported-colour",
1022
- reason: "changes_foreground"
1023
- },
1024
- "border-color-change": {
1025
- classification: "unsupported-colour",
1026
- reason: "changes_border"
1027
- },
1028
- "aurora-glow": {
1029
- classification: "unsupported-background-overlay",
1030
- reason: "unresolved_background_overlay"
1031
- },
1032
- "cosmic-stardust": {
1033
- classification: "unsupported-background-overlay",
1034
- reason: "unresolved_background_overlay"
1035
- },
1036
- "gradient-border-fill": {
1037
- classification: "unsupported-background-overlay",
1038
- reason: "unresolved_background_overlay"
1039
- },
1040
- "animated-gradient-border-fill": {
1041
- classification: "unsupported-background-overlay",
1042
- reason: "unresolved_background_overlay"
1043
- },
1044
- "nav-underline": {
1045
- classification: "not-button",
1046
- reason: "not_button_effect"
1047
- },
1048
- "nav-frosted-base": {
1049
- classification: "not-button",
1050
- reason: "not_button_effect"
1051
- },
1052
- "nav-frosted-hover": {
1053
- classification: "not-button",
1054
- reason: "not_button_effect"
1055
- },
1056
- "nav-frosted-active": {
1057
- classification: "not-button",
1058
- reason: "not_button_effect"
1059
- },
1060
- "animated-gradient": { classification: "non-colour" },
1061
- "border-glow": {
1062
- classification: "unsupported-colour",
1063
- reason: "changes_shadow_colour"
1064
- },
1065
- "drop-shadow": { classification: "decorative-colour" },
1066
- "inner-shadow": { classification: "decorative-colour" },
1067
- "neumorphic-shadow": { classification: "decorative-colour" },
1068
- "outer-glow": {
1069
- classification: "unsupported-colour",
1070
- reason: "changes_shadow_colour"
1071
- },
1072
- "retro-3d-shadow": { classification: "decorative-colour" },
1073
- "scale-up": { classification: "non-colour" },
1074
- "scale-down": { classification: "non-colour" },
1075
- lift: { classification: "non-colour" },
1076
- "press-down": { classification: "non-colour" },
1077
- pop: { classification: "non-colour" },
1078
- "border-bottom-grow": { classification: "non-colour" },
1079
- "sketchy-border": { classification: "decorative-colour" },
1080
- "inner-dashed-outline": { classification: "decorative-colour" },
1081
- "pulse-animation": {
1082
- classification: "unsupported-colour",
1083
- reason: "changes_element_opacity"
1084
- }
1085
- };
1086
- function validateButtonEffectOptions(effect) {
1087
- const parsed = buttonEffectApplicationSchema.safeParse(effect);
1088
- if (parsed.success) return { ok: true };
1089
- const firstIssue = parsed.error.issues[0];
1090
- const firstPathPart = firstIssue?.path[firstIssue.path.length - 1];
947
+ function statusAliasTokens(expanded) {
948
+ const aliases = {};
949
+ if (expanded.destructive) aliases.error = expanded.destructive;
950
+ if (expanded.accent) aliases.info = expanded.accent;
951
+ return aliases;
952
+ }
953
+ function expandPalette(palette, options = {}) {
1091
954
  return {
1092
- ok: false,
1093
- option: (firstIssue?.code === "unrecognized_keys" ? firstIssue.keys[0] : void 0) ?? (typeof firstPathPart === "string" ? firstPathPart : "options")
955
+ ...expandBasePalette(palette),
956
+ ...arrangementPaletteTokens(colorsToMap(palette), options)
1094
957
  };
1095
958
  }
1096
- function getButtonEffectPolicy(effectId) {
1097
- return Object.prototype.hasOwnProperty.call(BUTTON_EFFECT_POLICIES, effectId) ? BUTTON_EFFECT_POLICIES[effectId] : null;
1098
- }
1099
- //#endregion
1100
- //#region ../theme-core/src/buttons/buttonColourTransitions.ts
1101
- function applyColourEffects(input) {
1102
- return (input.effects ?? []).reduce((current, effect) => current.ok ? applyEffect(input, current, effect) : current, {
1103
- ok: true,
1104
- treatment: input.treatment,
1105
- nonColourEffects: []
959
+ function expandBasePalette(palette) {
960
+ const base = colorsToMap(palette);
961
+ const expanded = { ...base };
962
+ const roles = paletteInkRoles(base);
963
+ generateNeutralScale({
964
+ steps: 11,
965
+ tint: neutralTint(base.background)
966
+ }).forEach((n) => {
967
+ expanded[n.name] = n.hex;
1106
968
  });
1107
- }
1108
- function applyEffect(input, current, effect) {
1109
- const policy = getButtonEffectPolicy(effect.effectId);
1110
- if (policy === null) return unknownEffect(input, effect);
1111
- if (policy.classification === "unsupported-colour" || policy.classification === "unsupported-background-overlay" || policy.classification === "not-button") return unsupportedEffect(input, effect, policy.reason);
1112
- const options = validateButtonEffectOptions(effect);
1113
- if (!options.ok) return invalidEffectOption(input, effect, options.option);
1114
- return policy.classification === "colour-transition" ? transitionColour(input, current, effect) : {
1115
- ...current,
1116
- nonColourEffects: [...current.nonColourEffects, effect]
1117
- };
1118
- }
1119
- function transitionColour(input, current, effect) {
1120
- if (effect.effectId === "background-on-hover") {
1121
- const colorToken = readOpaqueToken(effect);
1122
- return colorToken === null ? invalidEffectOption(input, effect, "colorToken") : {
1123
- ...current,
1124
- treatment: {
1125
- type: "solid",
1126
- colorToken
1127
- }
1128
- };
969
+ for (const [name, hex] of Object.entries(base)) {
970
+ if (nonShadeablePaletteRoleNames.has(name)) continue;
971
+ if (hex) generateShades(hex, name).forEach((shade) => {
972
+ expanded[shade.name] = shade.hex;
973
+ });
1129
974
  }
1130
- if (effect.effectId !== "darken-background" && effect.effectId !== "lighten-background") return unknownEffect(input, effect);
1131
- if (current.treatment.type !== "solid") return inapplicableEffect(input, effect, current.treatment);
1132
- const amount = readShadeAmount(effect);
1133
- if (amount === null) return invalidEffectOption(input, effect, "amount");
975
+ if (base.text) expanded.body = base.text;
976
+ if (base.danger && !base.destructive) expanded.destructive = base.danger;
977
+ Object.assign(expanded, statusAliasTokens(expanded));
978
+ expanded.mutedText = readableMutedText(expanded["neutral-500"] ?? "#888", base, roles);
979
+ for (const [token, hex] of Object.entries({ ...expanded })) {
980
+ if (!hex || !isOnColorBackgroundCandidateToken(token)) continue;
981
+ const onToken = onColorTokenName(token);
982
+ if (expanded[onToken]) continue;
983
+ expanded[onToken] = paletteInkOnSolid(hex, roles).hex;
984
+ }
985
+ Object.assign(expanded, groundMutedInkTokens(expanded));
986
+ return expanded;
987
+ }
988
+ /**
989
+ * The strongest tints booking and registration screens lay over a ground
990
+ * where secondary text sits: selected option cards, event tiles and summaries
991
+ * tint `primary` at 5–10% (`blocks/vars/appointment-booking.ts`,
992
+ * `blocks/vars/event-registration.ts`, `blocks-static/event-registration.css`),
993
+ * the appointment summary and hover rows tint `text`/`onSurface` at 5%, and the
994
+ * registration summary lays `muted` at 42%. A weaker tint of the same colour
995
+ * sits between the ground and these, so solving against the strongest covers it.
996
+ * A selected card lays its tint over its own ground, so the same list applies
997
+ * over the surface and over the page background that event option cards paint.
998
+ * A new tint under secondary text belongs here, and the CSS paints it with
999
+ * the ground's faded tint token (`groundTintToken`) before the colour itself;
1000
+ * `secondaryTextTints.test.ts` fails if the CSS lays one that isn't covered or
1001
+ * doesn't read that token.
1002
+ */
1003
+ const SURFACE_SECONDARY_TEXT_TINTS = [
1004
+ {
1005
+ token: "primary",
1006
+ alpha: .1
1007
+ },
1008
+ {
1009
+ token: "text",
1010
+ alpha: .05
1011
+ },
1012
+ {
1013
+ token: "onSurface",
1014
+ alpha: .05
1015
+ },
1016
+ {
1017
+ token: "muted",
1018
+ alpha: .42
1019
+ }
1020
+ ];
1021
+ /** The strongest tint alpha per colour, for the CSS that paints those tints. */
1022
+ const SURFACE_SECONDARY_TEXT_TINT_ALPHA = Object.fromEntries(SURFACE_SECONDARY_TEXT_TINTS.map(({ token, alpha }) => [token, alpha]));
1023
+ /**
1024
+ * The grounds booking and registration secondary text sits on, with the token
1025
+ * its solved muted ink is published as: the surface (panels, details) and the
1026
+ * page background (event registration's option, ticket and payment cards).
1027
+ */
1028
+ const MUTED_INK_TOKENS = {
1029
+ surface: "onSurfaceMuted",
1030
+ background: "onBackgroundMuted"
1031
+ };
1032
+ /**
1033
+ * Secondary text on a ground, solved rather than faded from the ground's
1034
+ * on-colour in CSS, against the ground and every tint laid over it.
1035
+ *
1036
+ * Some palettes admit no single ink for all of them: a mid-tone surface with a
1037
+ * dark `primary` tint and a light `muted` one. The plain ground always has one
1038
+ * (black or white reads on any solid), so the ground is kept, each tint is kept
1039
+ * in list order while one ink still reads on everything kept so far, and the
1040
+ * tints that can't join are faded toward the ground until that ink reads on
1041
+ * them too. Fading the tint rather than giving it an ink of its own keeps every
1042
+ * line of text on it (titles and prices as well as secondary text) close to the
1043
+ * ground its colours were chosen for. Hosted palettes and the SDK bridge both
1044
+ * derive it here.
1045
+ */
1046
+ function groundMutedInk(palette, ground) {
1047
+ const groundHex = palette[ground];
1048
+ if (!groundHex) return null;
1049
+ const preferred = palette[onColorTokenName(ground)] ?? null;
1050
+ const roles = paletteInkRoles(palette);
1051
+ const initial = {
1052
+ grounds: [groundHex],
1053
+ hex: paletteMutedInkOnSolid(groundHex, preferred, roles),
1054
+ uncovered: []
1055
+ };
1056
+ const solved = SURFACE_SECONDARY_TEXT_TINTS.reduce((kept, { token, alpha }) => {
1057
+ const tintHex = palette[token];
1058
+ if (!tintHex) return kept;
1059
+ const grounds = [...kept.grounds, compositeHex(tintHex, alpha, groundHex)];
1060
+ const ink = paletteMutedInk(grounds, preferred, roles);
1061
+ return ink.kind === "unpaintable" ? {
1062
+ ...kept,
1063
+ uncovered: [...kept.uncovered, {
1064
+ token,
1065
+ alpha,
1066
+ tintHex
1067
+ }]
1068
+ } : {
1069
+ ...kept,
1070
+ grounds,
1071
+ hex: ink.hex
1072
+ };
1073
+ }, initial);
1134
1074
  return {
1135
- ...current,
1136
- treatment: {
1137
- type: "solid",
1138
- colorToken: adjustShade(current.treatment.colorToken, effect.effectId === "darken-background" ? amount : -amount, input.palette)
1139
- }
1075
+ hex: solved.hex,
1076
+ fadedTints: solved.uncovered.map(({ token, alpha, tintHex }) => ({
1077
+ token,
1078
+ hex: tintFadedUntilInkReads(tintHex, alpha, groundHex, solved.hex)
1079
+ }))
1140
1080
  };
1141
1081
  }
1142
- function adjustShade(token, amount, palette) {
1143
- const match = token.match(/^(.*)-(\d{2,3})$/);
1144
- const base = match?.[1] ?? token;
1145
- const currentShade = match?.[2] === void 0 ? 500 : Number(match[2]);
1146
- const availableShades = [
1147
- 50,
1148
- 100,
1149
- 200,
1150
- 300,
1151
- 400,
1152
- 500,
1153
- 600,
1154
- 700,
1155
- 800,
1156
- 900,
1157
- 950
1158
- ].filter((shade) => typeof palette[`${base}-${shade}`] === "string");
1159
- if (availableShades.length === 0) return token;
1160
- const firstShade = availableShades[0];
1161
- if (firstShade === void 0) return token;
1162
- const exactIndex = availableShades.indexOf(currentShade);
1163
- const startingIndex = exactIndex >= 0 ? exactIndex : availableShades.indexOf(availableShades.reduce((closestShade, shade) => Math.abs(shade - currentShade) < Math.abs(closestShade - currentShade) ? shade : closestShade, firstShade));
1164
- const stepCount = Math.abs(amount) / 100;
1165
- const direction = amount < 0 ? -1 : 1;
1166
- const targetShade = availableShades[Math.max(0, Math.min(availableShades.length - 1, startingIndex + direction * stepCount))];
1167
- return targetShade === void 0 ? token : unsafeAsOpaqueButtonColourToken(`${base}-${targetShade}`);
1082
+ /** The tint colour a ground publishes in place of a tint its muted ink can't read on, e.g. `surfaceTintMuted`. */
1083
+ function groundTintToken(ground, tint) {
1084
+ return `${ground}Tint${tint.charAt(0).toUpperCase()}${tint.slice(1)}`;
1168
1085
  }
1169
- function readShadeAmount(effect) {
1170
- const value = effect.options?.amount ?? 100;
1171
- return typeof value === "number" && Number.isFinite(value) && value >= 0 && value % 100 === 0 ? value : null;
1086
+ /**
1087
+ * The tint blended toward the ground in 1% steps, stopping at the first that
1088
+ * the ink reads on when laid at `alpha`. The ground itself always reads, since
1089
+ * the ink was solved on it.
1090
+ */
1091
+ function tintFadedUntilInkReads(tintHex, alpha, groundHex, inkHex) {
1092
+ const tint = hexToRgb(tintHex);
1093
+ const ground = hexToRgb(groundHex);
1094
+ return Array.from({ length: 101 }, (_, index) => {
1095
+ const amount = index / 100;
1096
+ return rgbToHex(mix$1(tint.r, ground.r, amount), mix$1(tint.g, ground.g, amount), mix$1(tint.b, ground.b, amount));
1097
+ }).find((hex) => contrastRatio(inkHex, compositeHex(hex, alpha, groundHex)) >= 4.5) ?? groundHex;
1172
1098
  }
1173
- function readOpaqueToken(effect) {
1174
- return parseOpaqueButtonColourToken(effect.options?.colorToken ?? "neutral-800");
1099
+ /**
1100
+ * The muted ink tokens a palette doesn't store itself, and the faded tint
1101
+ * colours of each ground whose ink is solved here, as hex.
1102
+ */
1103
+ function groundMutedInkTokens(palette) {
1104
+ return Object.fromEntries(Object.entries(MUTED_INK_TOKENS).flatMap(([ground, token]) => {
1105
+ if (palette[token]) return [];
1106
+ const ink = groundMutedInk(palette, ground);
1107
+ if (!ink) return [];
1108
+ const faded = ink.fadedTints.map(({ token: tint, hex }) => [groundTintToken(ground, tint), hex]);
1109
+ return [[token, ink.hex], ...faded.filter(([name]) => !palette[name])];
1110
+ }));
1175
1111
  }
1176
- function unsupportedEffect(input, effect, reason) {
1177
- return {
1178
- ok: false,
1179
- error: {
1180
- tag: "unsupported_colour_effect",
1181
- variantId: input.variantId,
1182
- state: input.state,
1183
- effectId: effect.effectId,
1184
- reason
1185
- }
1186
- };
1112
+ /**
1113
+ * The neutral step stays when it reads on the ground. Otherwise (a dark palette
1114
+ * on a mid-tone ground, or a tinted light one) it's the ground-to-text blend
1115
+ * with a 4.5:1 floor, heading for the palette's own ink on that ground.
1116
+ */
1117
+ function readableMutedText(step, base, roles) {
1118
+ const ground = base.background || base.surface;
1119
+ if (!ground || contrastRatio(step, ground) >= 4.5) return step;
1120
+ return paletteMutedInkOnSolid(ground, null, roles);
1187
1121
  }
1188
- function invalidEffectOption(input, effect, option) {
1122
+ /**
1123
+ * Derived decoration colours never become editable palette swatches. The mark
1124
+ * blends toward literal black or white: it's a graphic endpoint for a 3:1
1125
+ * search, not text, so it stays off the palette ink rule.
1126
+ */
1127
+ /** `backdrops` lists every colour the decorations sit on, such as each step of a radial glow. */
1128
+ function deriveSurfaceDecorationColors(ground, text, accent, backdrops = [ground]) {
1129
+ const ink = pickBlackOrWhiteTextColor(ground);
1189
1130
  return {
1190
- ok: false,
1191
- error: {
1192
- tag: "invalid_colour_effect_options",
1193
- variantId: input.variantId,
1194
- state: input.state,
1195
- effectId: effect.effectId,
1196
- option
1197
- }
1131
+ line: deriveSurfaceLineColor(ground, text, backdrops),
1132
+ mark: firstContrastBlend(accent, ink, backdrops, 3)
1198
1133
  };
1199
1134
  }
1200
- function inapplicableEffect(input, effect, treatment) {
1201
- return {
1202
- ok: false,
1203
- error: {
1204
- tag: "inapplicable_colour_effect",
1205
- variantId: input.variantId,
1206
- state: input.state,
1207
- effectId: effect.effectId,
1208
- treatment: treatment.type
1209
- }
1210
- };
1135
+ /**
1136
+ * Secondary ink blended from its ground toward its text, reading at 4.5:1 over
1137
+ * every backdrop a sampled finish paints under it. When no blend reads on all of
1138
+ * them the text itself is kept (or, with no concrete text, the ink solved on
1139
+ * the ground alone).
1140
+ */
1141
+ function deriveSurfaceMutedColor(ground, text, backdrops = [ground], roles = null) {
1142
+ const ink = paletteMutedInk([ground, ...backdrops], text, roles);
1143
+ if (ink.kind === "muted") return ink.hex;
1144
+ return text ?? paletteMutedInkOnSolid(ground, null, roles);
1211
1145
  }
1212
- function unknownEffect(input, effect) {
1146
+ /** A section rule is a quiet ground-to-text blend, certified over the complete backing. */
1147
+ function deriveSurfaceLineColor(ground, text, backdrops = [ground]) {
1148
+ return firstContrastBlend(ground, text, backdrops, 1.5);
1149
+ }
1150
+ function firstContrastBlend(from, to, backdrops, threshold) {
1151
+ const start = hexToRgb(from);
1152
+ const end = hexToRgb(to);
1153
+ const luminances = backdrops.map((backdrop) => hexLuminance(backdrop));
1154
+ const paint = luminanceInterval(Math.min(...luminances), Math.max(...luminances));
1155
+ return Array.from({ length: 101 }, (_, index) => {
1156
+ const amount = index / 100;
1157
+ return rgbToHex(mix$1(start.r, end.r, amount), mix$1(start.g, end.g, amount), mix$1(start.b, end.b, amount));
1158
+ }).find((hex) => worstContrast(hexLuminance(hex), paint) >= threshold) ?? to;
1159
+ }
1160
+ /** `markSource` names the colour surface marks are derived from when a style marks in its brand rather than its accent. */
1161
+ function arrangementPaletteTokens(base, options) {
1162
+ if (options.arrangement !== true || !base.text) return {};
1213
1163
  return {
1214
- ok: false,
1215
- error: {
1216
- tag: "unknown_button_effect",
1217
- variantId: input.variantId,
1218
- state: input.state,
1219
- effectId: effect.effectId
1220
- }
1164
+ onText: base.onText ?? paletteInkOnSolid(base.text, paletteInkRoles(base)).hex,
1165
+ ...options.marksFrom === "primary" && base.primary ? { markSource: base.primary } : {}
1221
1166
  };
1222
1167
  }
1223
1168
  //#endregion
1224
- //#region ../theme-core/src/buttons/contextualHover.ts
1225
- function resolveContextualHoverPreference(input) {
1226
- const preferred = input.instruction.preferredToken;
1227
- if (preferred && isSafeCandidate(preferred, input.palette, input.surface, input.colourIndex, input.border)) return {
1228
- kind: "resolved",
1229
- token: preferred,
1230
- repair: null
1231
- };
1232
- const contextual = resolveContextualHover(input);
1233
- return contextual.kind === "resolved" ? {
1234
- kind: "resolved",
1235
- token: contextual.token,
1236
- repair: preferred ? {
1237
- kind: "preferred-token-replaced",
1238
- preferredToken: preferred,
1239
- contextualToken: contextual.token
1240
- } : null
1241
- } : contextual;
1169
+ //#region ../media-core/src/identifiers.ts
1170
+ function slugifyMediaIdentifier(value) {
1171
+ return value.toLowerCase().trim().replace(/[^a-z0-9\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-");
1172
+ }
1173
+ function parseMediaIdentifier(value) {
1174
+ if (typeof value !== "string") return err({ kind: "not_string" });
1175
+ const trimmed = value.trim();
1176
+ if (trimmed.length === 0) return err({ kind: "empty_identifier" });
1177
+ const normalized = slugifyMediaIdentifier(trimmed);
1178
+ if (normalized.length === 0) return err({
1179
+ kind: "empty_after_normalization",
1180
+ value
1181
+ });
1182
+ return ok(normalized);
1242
1183
  }
1243
1184
  /**
1244
- * Resolves semantic shade movement from real palette steps. The persisted
1245
- * instruction owns the colour family and deterministic unknown-surface
1246
- * fallback; a proven surface may select the opposite direction when it gives
1247
- * the button stronger separation while retaining the shared contrast contract.
1185
+ * Admits identifiers read from trusted persistence without repairing dirty data in memory.
1186
+ * User input should use parseMediaIdentifier, which intentionally canonicalizes it.
1248
1187
  */
1249
- function resolveContextualHover(input) {
1250
- const candidates = shadeCandidates(input.instruction.seedToken, input.palette);
1251
- if (candidates.length === 0) return {
1252
- kind: "unavailable",
1253
- reason: "no-distinct-shade"
1254
- };
1255
- const textSafe = candidates.filter((candidate) => hasSafeTextContrast(candidate.token, input.palette, input.colourIndex));
1256
- if (textSafe.length === 0) return {
1257
- kind: "unavailable",
1258
- reason: "no-text-safe-candidate"
1259
- };
1260
- if (!input.surface) {
1261
- const selected = textSafe.find((candidate) => candidate.direction === input.instruction.fallbackDirection) ?? textSafe[0];
1262
- return selected ? {
1263
- kind: "resolved",
1264
- token: selected.token,
1265
- direction: selected.direction,
1266
- evidence: "fallback-direction"
1267
- } : {
1268
- kind: "unavailable",
1269
- reason: "no-text-safe-candidate"
1270
- };
1271
- }
1272
- const selected = selectSurfaceSafeHover(textSafe, {
1273
- palette: input.palette,
1274
- surface: input.surface,
1275
- colourIndex: input.colourIndex,
1276
- fallbackDirection: input.instruction.fallbackDirection,
1277
- border: input.border
1188
+ function parseCanonicalMediaIdentifier(value) {
1189
+ if (typeof value !== "string") return err({ kind: "not_string" });
1190
+ const parsed = parseMediaIdentifier(value);
1191
+ if (!parsed.ok) return parsed;
1192
+ if (value !== parsed.value) return err({
1193
+ kind: "non_canonical_identifier",
1194
+ value,
1195
+ canonical: parsed.value
1278
1196
  });
1279
- return selected ? {
1280
- kind: "resolved",
1281
- token: selected.token,
1282
- direction: selected.direction,
1283
- evidence: "known-surface"
1284
- } : {
1285
- kind: "unavailable",
1286
- reason: "no-surface-safe-candidate"
1287
- };
1197
+ return parsed;
1288
1198
  }
1289
- /** Rank the proven-surface candidates without mixing selection with fallback policy. */
1290
- function selectSurfaceSafeHover(candidates, input) {
1291
- return candidates.flatMap((candidate) => {
1292
- const separation = buttonSurfaceSeparation(input.palette[candidate.token] ?? "", input.surface, {
1293
- border: input.border,
1294
- palette: input.palette,
1295
- labelInk: input.palette[solidForegroundToken(candidate.token)] ?? ""
1296
- });
1297
- return separation.distinct ? [{
1298
- ...candidate,
1299
- surfaceDistance: separation.deltaE
1300
- }] : [];
1301
- }).sort((left, right) => {
1302
- const distanceDifference = left.distance - right.distance;
1303
- if (distanceDifference !== 0) return distanceDifference;
1304
- const contrastDifference = (right.surfaceDistance ?? 0) - (left.surfaceDistance ?? 0);
1305
- if (contrastDifference !== 0) return contrastDifference;
1306
- if (left.direction === right.direction) return left.token.localeCompare(right.token);
1307
- return left.direction === input.fallbackDirection ? -1 : 1;
1308
- })[0];
1309
- }
1310
- function shadeCandidates(seedToken, palette) {
1311
- const match = String(seedToken).match(/^(.*?)(?:-(\d{2,3}))?$/);
1312
- const family = match?.[1] ?? String(seedToken);
1313
- const currentShade = match?.[2] ? Number(match[2]) : 500;
1314
- const seedHex = palette[seedToken];
1315
- const shades = Object.keys(palette).flatMap((token) => {
1316
- const shade = token.match(new RegExp(`^${escapeRegExp(family)}-(\\d{2,3})$`));
1317
- return shade?.[1] ? [Number(shade[1])] : [];
1318
- }).filter((shade) => Number.isFinite(shade)).sort((left, right) => left - right);
1319
- const lower = [...shades].filter((shade) => shade < currentShade).sort((left, right) => right - left);
1320
- const higher = shades.filter((shade) => shade > currentShade);
1321
- return [...lower.map((shade) => candidate(family, shade, currentShade, "lighter", seedHex, palette)), ...higher.map((shade) => candidate(family, shade, currentShade, "darker", seedHex, palette))].filter((value) => value !== null);
1322
- }
1323
- function candidate(family, shade, currentShade, direction, seedHex, palette) {
1324
- const token = parseOpaqueButtonColourToken(`${family}-${shade}`);
1325
- if (token === null) return null;
1326
- const candidateHex = palette[token];
1327
- if (!candidateHex || candidateHex === seedHex) return null;
1199
+ //#endregion
1200
+ //#region ../media-core/src/mediaIdentifierSchema.ts
1201
+ /** Strict stored-reference admission delegates the canonical identifier decision. */
1202
+ const mediaIdentifierSchema = z.string().transform((value, context) => {
1203
+ const parsed = parseCanonicalMediaIdentifier(value);
1204
+ if (parsed.ok) return parsed.value;
1205
+ context.addIssue({
1206
+ code: "custom",
1207
+ message: "Expected a canonical media identifier"
1208
+ });
1209
+ return z.NEVER;
1210
+ });
1211
+ //#endregion
1212
+ //#region ../media-core/src/mediaKinds.ts
1213
+ const mediaTypeDiscriminants = [
1214
+ "image",
1215
+ "video",
1216
+ "audio",
1217
+ "document",
1218
+ "spreadsheet",
1219
+ "archive"
1220
+ ];
1221
+ const DISPLAY_MEDIA_KINDS = [
1222
+ "image",
1223
+ "video",
1224
+ "audio"
1225
+ ];
1226
+ const PUBLIC_FILE_FIELD_KINDS = [
1227
+ "document",
1228
+ "spreadsheet",
1229
+ "archive",
1230
+ "audio"
1231
+ ];
1232
+ function isDisplayMediaKind(kind) {
1233
+ return DISPLAY_MEDIA_KINDS.includes(kind);
1234
+ }
1235
+ //#endregion
1236
+ //#region ../media-core/src/renderableMediaAsset.ts
1237
+ /** Shared identifier indexing for admitted site-scoped projections. */
1238
+ function buildMediaIdentifierIndex(assets) {
1239
+ const index = new Map(assets.map((asset) => [asset.identifier, asset]));
1240
+ if (index.size !== assets.length) throw new Error("Duplicate media identifier in a site asset list");
1241
+ return index;
1242
+ }
1243
+ /** Index already admitted projections, including runtime registration updates. */
1244
+ function indexRenderableMediaAssets(assets) {
1245
+ if (!assets.length) return void 0;
1246
+ const byId = new Map(assets.map((asset) => [asset.id, asset]));
1247
+ const byIdentifier = buildMediaIdentifierIndex(assets);
1248
+ if (byId.size !== assets.length) throw new Error("Duplicate media asset identity in a site asset list");
1328
1249
  return {
1329
- token,
1330
- direction,
1331
- distance: Math.abs(shade - currentShade),
1332
- surfaceDistance: null
1250
+ assets,
1251
+ byId,
1252
+ byIdentifier
1333
1253
  };
1334
1254
  }
1335
- function hasSafeTextContrast(token, palette, colourIndex) {
1336
- const background = palette[token];
1337
- const foreground = palette[solidForegroundToken(token)];
1338
- return typeof background === "string" && typeof foreground === "string" && contrastRatio(background, foreground, colourIndex) >= BUTTON_CONTRAST_POLICY.textMinimumRatio;
1339
- }
1340
- function isSafeCandidate(token, palette, surface, colourIndex, border) {
1341
- if (!hasSafeTextContrast(token, palette, colourIndex)) return false;
1342
- return surface ? buttonSurfaceSeparation(palette[token] ?? "", surface, {
1343
- border,
1344
- palette,
1345
- labelInk: palette[solidForegroundToken(token)] ?? ""
1346
- }).distinct : true;
1255
+ /** A portable reference never uses an incidental UUID, URL or storage snapshot for identity. */
1256
+ function resolveManagedMediaReference(reference, index) {
1257
+ const asset = index?.byIdentifier.get(reference.identifier);
1258
+ return asset ? {
1259
+ kind: "resolved",
1260
+ reference,
1261
+ asset
1262
+ } : {
1263
+ kind: "missing",
1264
+ reference
1265
+ };
1347
1266
  }
1348
- function escapeRegExp(value) {
1349
- return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1267
+ //#endregion
1268
+ //#region ../media-core/src/renderableMediaAssetAdmission.ts
1269
+ const mediaAssetIdSchema = z.string().transform((value, context) => {
1270
+ const parsed = parseMediaAssetId(value);
1271
+ if (parsed.ok) return parsed.value;
1272
+ context.addIssue({
1273
+ code: "custom",
1274
+ message: "Expected a media asset ID"
1275
+ });
1276
+ return z.NEVER;
1277
+ });
1278
+ const nonemptyStorageValue = z.string().refine((value) => value.trim().length > 0);
1279
+ const renderableMediaAssetSchema = z.object({
1280
+ id: mediaAssetIdSchema,
1281
+ identifier: mediaIdentifierSchema,
1282
+ storageBucket: nonemptyStorageValue,
1283
+ storagePath: nonemptyStorageValue,
1284
+ mimeType: nonemptyStorageValue,
1285
+ filename: z.string().optional(),
1286
+ width: z.number().positive().nullable(),
1287
+ height: z.number().positive().nullable()
1288
+ });
1289
+ /** Admission precedes the identifier-only runtime resolution decision. */
1290
+ function buildRenderableMediaAssetIndex(assets) {
1291
+ if (!assets?.length) return void 0;
1292
+ return indexRenderableMediaAssets(assets.map((asset) => renderableMediaAssetSchema.parse(asset)));
1350
1293
  }
1351
1294
  //#endregion
1352
- //#region ../theme-core/src/buttons/resolveButtonHoverTreatment.ts
1353
- function resolveButtonHoverTreatment(input) {
1354
- if (input.variant.contextualHover) {
1355
- const contextual = resolveContextualHoverPreference({
1356
- instruction: input.variant.contextualHover,
1357
- palette: input.palette,
1358
- colourIndex: input.colourIndex,
1359
- surface: input.surface,
1360
- border: input.variant.border
1361
- });
1362
- if (contextual.kind === "resolved") return {
1363
- treatment: {
1364
- type: "solid",
1365
- colorToken: contextual.token
1366
- },
1367
- repair: contextual.repair
1368
- };
1369
- }
1370
- const token = input.variant.hoverBackgroundToken ?? (input.global.hoverColor === "token" ? input.global.hoverColorToken : void 0);
1371
- return {
1372
- treatment: token === void 0 ? input.fallback : {
1373
- type: "solid",
1374
- colorToken: token
1295
+ //#region ../media-core/src/media.ts
1296
+ const hotspotSchema = z.object({
1297
+ x: z.number().min(0).max(1),
1298
+ y: z.number().min(0).max(1),
1299
+ radius: z.number().optional()
1300
+ });
1301
+ const rotationSchema = z.union([
1302
+ z.literal(0),
1303
+ z.literal(90),
1304
+ z.literal(180),
1305
+ z.literal(270)
1306
+ ]);
1307
+ const rectSchema = z.tuple([
1308
+ z.number(),
1309
+ z.number(),
1310
+ z.number(),
1311
+ z.number()
1312
+ ]);
1313
+ const aspectCropSchema = z.object({
1314
+ aspect: z.preprocess((value) => value == null ? void 0 : value, z.string().optional()),
1315
+ rect: z.preprocess((value) => value == null ? void 0 : value, rectSchema.optional()),
1316
+ hotspot: z.preprocess((value) => value == null ? void 0 : value, hotspotSchema.optional()),
1317
+ rotation: z.preprocess((value) => value == null ? void 0 : value, rotationSchema.optional())
1318
+ });
1319
+ const mediaTransformSchema = z.object({
1320
+ aspectCrops: z.preprocess((value) => {
1321
+ if (!value || typeof value !== "object" || Array.isArray(value)) return;
1322
+ return value;
1323
+ }, z.record(z.string(), aspectCropSchema.catch({}))).optional(),
1324
+ rect: rectSchema.optional(),
1325
+ hotspot: hotspotSchema.optional(),
1326
+ rotation: rotationSchema.optional()
1327
+ });
1328
+ const mediaPosterSchema = z.discriminatedUnion("tag", [z.object({
1329
+ tag: z.literal("media"),
1330
+ identifier: mediaIdentifierSchema
1331
+ }).strict(), z.object({
1332
+ tag: z.literal("external-src"),
1333
+ src: z.string().url()
1334
+ }).strict()]);
1335
+ const mediaUsageShape = {
1336
+ purpose: z.string().optional(),
1337
+ placeholder: z.boolean().default(true).optional(),
1338
+ alt: z.string().optional(),
1339
+ filename: z.string().optional(),
1340
+ width: z.number().optional(),
1341
+ height: z.number().optional(),
1342
+ poster: mediaPosterSchema.optional(),
1343
+ transform: mediaTransformSchema.optional()
1344
+ };
1345
+ const environmentExclusions = {
1346
+ assetId: z.never().optional(),
1347
+ id: z.never().optional(),
1348
+ src: z.never().optional(),
1349
+ storageBucket: z.never().optional(),
1350
+ storagePath: z.never().optional(),
1351
+ mimeType: z.never().optional()
1352
+ };
1353
+ const mediaBaseSchema = z.object({
1354
+ ...mediaUsageShape,
1355
+ ...environmentExclusions,
1356
+ identifier: mediaIdentifierSchema
1357
+ }).strict();
1358
+ const imageMediaSchema = mediaBaseSchema.extend({ type: z.literal("image") });
1359
+ const videoMediaSchema = mediaBaseSchema.extend({ type: z.literal("video") });
1360
+ const mediaSchema = mediaBaseSchema.extend({ type: z.enum(mediaTypeDiscriminants) });
1361
+ const persistableMediaSchema = mediaSchema;
1362
+ const externalMediaSchema = z.object({
1363
+ ...mediaUsageShape,
1364
+ ...environmentExclusions,
1365
+ type: z.enum(mediaTypeDiscriminants),
1366
+ src: z.string().min(1),
1367
+ identifier: z.never().optional()
1368
+ }).strict();
1369
+ const assetMediaSchema = z.object({
1370
+ ...mediaUsageShape,
1371
+ ...environmentExclusions,
1372
+ type: z.enum(mediaTypeDiscriminants),
1373
+ asset: renderableMediaAssetSchema,
1374
+ identifier: z.never().optional()
1375
+ }).strict();
1376
+ const runtimeMediaSchema = z.union([
1377
+ mediaSchema,
1378
+ externalMediaSchema,
1379
+ assetMediaSchema
1380
+ ]);
1381
+ //#endregion
1382
+ //#region ../theme-core/src/buttons/constants.ts
1383
+ /**
1384
+ * Shared constants for button CSS generation
1385
+ *
1386
+ * These mappings convert Tailwind-style tokens to actual CSS values.
1387
+ * Centralized here to eliminate duplication across multiple files.
1388
+ */
1389
+ /**
1390
+ * Map Tailwind-style gradient direction tokens to CSS gradient directions
1391
+ */
1392
+ const GRADIENT_DIRECTION_MAP = {
1393
+ "to-r": "to right",
1394
+ "to-l": "to left",
1395
+ "to-t": "to top",
1396
+ "to-b": "to bottom",
1397
+ "to-br": "to bottom right",
1398
+ "to-bl": "to bottom left",
1399
+ "to-tr": "to top right",
1400
+ "to-tl": "to top left"
1401
+ };
1402
+ /**
1403
+ * Map Tailwind border-radius tokens to CSS values
1404
+ */
1405
+ const BORDER_RADIUS_MAP = {
1406
+ "rounded-none": "0",
1407
+ "rounded-3px": "3px",
1408
+ "rounded-10px": "10px",
1409
+ "rounded-sm": "0.125rem",
1410
+ "rounded": "0.25rem",
1411
+ "rounded-md": "0.375rem",
1412
+ "rounded-lg": "0.5rem",
1413
+ "rounded-xl": "0.75rem",
1414
+ "rounded-2xl": "1rem",
1415
+ "rounded-3xl": "1.5rem",
1416
+ "rounded-full": "9999px"
1417
+ };
1418
+ /**
1419
+ * Pixel offset per shadow elevation. Single source of truth shared by
1420
+ * `generateShadowValue` (the base box-shadow offset) and the `press-down`
1421
+ * effect (which translates the button by the same offset on hover). Keeping
1422
+ * these in one place ensures the "press into the shadow" illusion stays exact.
1423
+ */
1424
+ const ELEVATION_OFFSET = {
1425
+ none: 0,
1426
+ low: 2,
1427
+ medium: 4,
1428
+ high: 6
1429
+ };
1430
+ /**
1431
+ * Generate shadow CSS value dynamically based on elevation, softness, and position
1432
+ *
1433
+ * This replaces the static shadow maps with a single dynamic function.
1434
+ * Benefits: single source of truth, easy to adjust algorithm, no redundancy.
1435
+ *
1436
+ * @param elevation - Shadow elevation level
1437
+ * @param softness - Shadow softness/blur style
1438
+ * @param position - Shadow position (bottom or bottom-right diagonal)
1439
+ * @returns CSS box-shadow value
1440
+ */
1441
+ function generateShadowValue(elevation, softness, position = "bottom", color) {
1442
+ if (elevation === "none") return "none";
1443
+ const config = {
1444
+ low: {
1445
+ blur: 4,
1446
+ spread: 0
1375
1447
  },
1376
- repair: null
1377
- };
1448
+ medium: {
1449
+ blur: 8,
1450
+ spread: -1
1451
+ },
1452
+ high: {
1453
+ blur: 12,
1454
+ spread: -2
1455
+ }
1456
+ }[elevation];
1457
+ const baseOffset = ELEVATION_OFFSET[elevation];
1458
+ const xOffset = position === "bottom-right" ? baseOffset : 0;
1459
+ const yOffset = baseOffset;
1460
+ switch (softness) {
1461
+ case null:
1462
+ case "soft": return `${xOffset}px ${yOffset}px ${config.blur}px ${config.spread}px ${color ?? "rgb(0 0 0 / 0.3)"}`;
1463
+ case "hard": return `${xOffset}px ${yOffset}px 0 0 ${color ?? "rgb(0 0 0 / 1)"}`;
1464
+ case "crisp": return `${xOffset}px ${yOffset}px ${baseOffset}px ${config.spread}px ${color ?? "rgb(0 0 0 / 0.4)"}`;
1465
+ }
1378
1466
  }
1467
+ /**
1468
+ * Map Tailwind border-width tokens to CSS values
1469
+ */
1470
+ const BORDER_WIDTH_MAP = {
1471
+ "border-0": "0px",
1472
+ "border": "1px",
1473
+ "border-2": "2px",
1474
+ "border-4": "4px",
1475
+ "border-8": "8px"
1476
+ };
1477
+ /**
1478
+ * Map Tailwind font-size tokens to CSS values
1479
+ */
1480
+ const FONT_SIZE_MAP = {
1481
+ "text-xs": "0.75rem",
1482
+ "text-13px": "0.8125rem",
1483
+ "text-15px": "0.9375rem",
1484
+ "text-17px": "1.0625rem",
1485
+ "text-19px": "1.1875rem",
1486
+ "text-sm": "0.875rem",
1487
+ "text-base": "1rem",
1488
+ "text-lg": "1.125rem",
1489
+ "text-xl": "1.25rem",
1490
+ "text-2xl": "1.5rem"
1491
+ };
1492
+ /**
1493
+ * System defaults used when a theme doesn't supply its own `theme.buttons.sizes`.
1494
+ *
1495
+ * Every size is defined so the size class CSS always emits a complete rule and
1496
+ * variants are never naked. Referenced by `generateButtonCss` and surfaceable
1497
+ * from UI ("Showing default size ramp") without duplicating the values.
1498
+ */
1499
+ const DEFAULT_BUTTON_SIZES = {
1500
+ sm: {
1501
+ padding: "0.5rem 1rem",
1502
+ fontSize: "text-sm"
1503
+ },
1504
+ md: { padding: "0.75rem 1.5rem" },
1505
+ lg: {
1506
+ padding: "1rem 2rem",
1507
+ fontSize: "text-lg"
1508
+ },
1509
+ xl: {
1510
+ padding: "1.25rem 2.5rem",
1511
+ fontSize: "text-xl"
1512
+ }
1513
+ };
1379
1514
  //#endregion
1380
- //#region ../theme-core/src/buttons/resolveButtonColourStates.ts
1381
- function mapVisualStates(value) {
1515
+ //#region ../theme-core/src/buttons/buttonColourContract.ts
1516
+ const BUTTON_CONTRAST_POLICY = {
1517
+ textMinimumRatio: 4.5,
1518
+ nonTextMinimumRatio: 3,
1519
+ filledMinimumDeltaE: .12,
1520
+ gradientSamplesPerSegment: 20,
1521
+ alphaBackgrounds: "reject-without-known-surface",
1522
+ disabled: "validated-colour-pair-with-muted-control-opacity"
1523
+ };
1524
+ function formatButtonColourContractError(error) {
1525
+ switch (error.tag) {
1526
+ case "unknown_palette_token": return `Button "${error.variantId}" ${error.state} state uses unknown palette token "${error.token}".`;
1527
+ case "insufficient_contrast": return `Button "${error.variantId}" ${error.state} state has ${error.ratio.toFixed(2)}:1 contrast (${error.requiredRatio}:1 required).`;
1528
+ case "insufficient_surface_separation": return `Button "${error.variantId}" ${error.state} state is indistinguishable from its surface at OKLab distance ${error.deltaE.toFixed(3)} (${error.requiredDeltaE} required).`;
1529
+ case "unsupported_colour_effect": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" is not contrast-safe (${error.reason}).`;
1530
+ case "invalid_colour_effect_options": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" has an invalid ${error.option} option.`;
1531
+ case "inapplicable_colour_effect": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" cannot apply to a ${error.treatment} treatment.`;
1532
+ case "unknown_button_effect": return `Button "${error.variantId}" ${error.state} uses unknown effect "${error.effectId}".`;
1533
+ }
1534
+ }
1535
+ /** One separation decision for filled states and contextual hover candidates. */
1536
+ function buttonFillSeparation(fill, ground) {
1537
+ const deltaE = hexOklabDistance(fill, ground);
1382
1538
  return {
1383
- base: value("base"),
1384
- hover: value("hover"),
1385
- focus: value("focus"),
1386
- active: value("active"),
1387
- disabled: value("disabled")
1539
+ deltaE,
1540
+ distinct: deltaE >= BUTTON_CONTRAST_POLICY.filledMinimumDeltaE
1388
1541
  };
1389
1542
  }
1390
- /** The border a state draws: its declared appearance's, otherwise the variant's. */
1391
- function buttonStateBorder(variant, state) {
1392
- const appearance = variant.visualStates?.[state];
1393
- if (!appearance) return variant.border;
1394
- return appearance.border === "none" ? void 0 : appearance.border;
1543
+ /** All paint beneath the control; ordinary solids have just one ground. */
1544
+ const buttonSurfaceGrounds = (surface) => [surface.backgroundHex, ...surface.backgroundSamples ?? []];
1545
+ /** A filled state clears each ground by its fill OR a declared edge at 3:1. */
1546
+ function buttonSurfaceSeparation(fill, surface, edge) {
1547
+ return buttonGroundSeparation(fill, buttonSurfaceGrounds(surface), edge);
1395
1548
  }
1396
- function compileButtonColourStates(input) {
1397
- if (input.variant.visualStates) return compileDeclaredVisualStates(input, input.variant.visualStates);
1398
- const base = applyColourEffects({
1399
- variantId: input.variant.id,
1400
- state: "base",
1401
- treatment: input.variant.background,
1402
- effects: input.variant.effects?.base,
1403
- palette: input.palette
1404
- });
1405
- if (!base.ok) return base;
1406
- const hover = resolveButtonHoverTreatment({
1407
- variant: input.variant,
1408
- global: input.global,
1409
- fallback: base.treatment,
1410
- palette: input.palette,
1411
- surface: input.surface,
1412
- colourIndex: input.colourIndex
1413
- });
1414
- const colours = collectStateColours(mapVisualStates((state) => compileVisualState(input, state, state === "hover" ? hover.treatment : base.treatment, base.nonColourEffects)));
1415
- return colours.ok ? {
1416
- ...colours,
1417
- contextualHoverRepair: hover.repair
1418
- } : colours;
1419
- }
1420
- function compileDeclaredVisualStates(input, states) {
1421
- const hover = resolveButtonHoverTreatment({
1422
- ...input,
1423
- variant: {
1424
- ...input.variant,
1425
- contextualHover: states.hover.contextualHover,
1426
- border: buttonStateBorder(input.variant, "hover"),
1427
- hoverBackgroundToken: void 0
1428
- },
1429
- global: {
1430
- ...input.global,
1431
- hoverColor: "none",
1432
- hoverColorToken: void 0
1433
- },
1434
- fallback: states.hover.background
1435
- });
1436
- const colours = collectStateColours(mapVisualStates((state) => compileDeclaredVisualState(input, states, state, state === "hover" ? hover.treatment : states[state].background)));
1437
- return colours.ok ? {
1438
- ...colours,
1439
- focusIndicator: states.focus.indicator ? {
1440
- kind: "surface-role",
1441
- colorCss: input.surface?.foregroundCss ?? surfaceForegroundValue("text"),
1442
- width: states.focus.indicator.width,
1443
- offset: states.focus.indicator.offset,
1444
- minimumSurfaceContrast: BUTTON_CONTRAST_POLICY.nonTextMinimumRatio
1445
- } : colours.focusIndicator,
1446
- contextualHoverRepair: hover.repair
1447
- } : colours;
1448
- }
1449
- function compileDeclaredVisualState(input, states, state, treatment) {
1450
- const appearance = states[state];
1451
- const effects = state === "base" ? appearance.effects : [...states.base.effects, ...appearance.effects];
1452
- const transition = applyColourEffects({
1453
- variantId: input.variant.id,
1454
- state,
1455
- treatment,
1456
- effects,
1457
- palette: input.palette
1458
- });
1459
- if (!transition.ok) return transition;
1460
- const resolved = resolveTreatment({
1461
- variantId: input.variant.id,
1462
- state,
1463
- treatment: transition.treatment,
1464
- border: buttonStateBorder(input.variant, state),
1465
- palette: input.palette,
1466
- surface: input.surface,
1467
- colourIndex: input.colourIndex
1468
- });
1469
- return resolved.ok ? {
1470
- ...resolved,
1471
- nonColourEffects: state === "disabled" ? [] : state === "base" ? transition.nonColourEffects : transition.nonColourEffects.filter((effect) => appearance.effects.includes(effect))
1472
- } : resolved;
1473
- }
1474
- function compileVisualState(input, state, treatment, baseEffects) {
1475
- const transition = state === "hover" || state === "focus" || state === "active" ? applyColourEffects({
1476
- variantId: input.variant.id,
1477
- state,
1478
- treatment,
1479
- effects: input.variant.effects?.[state],
1480
- palette: input.palette
1481
- }) : {
1482
- ok: true,
1483
- treatment,
1484
- nonColourEffects: state === "base" ? baseEffects : []
1485
- };
1486
- if (!transition.ok) return transition;
1487
- const resolved = resolveTreatment({
1488
- variantId: input.variant.id,
1489
- state,
1490
- treatment: transition.treatment,
1491
- palette: input.palette,
1492
- surface: input.surface,
1493
- colourIndex: input.colourIndex,
1494
- border: buttonStateBorder(input.variant, state)
1549
+ /** The worst ground for a fill: the first it fails to stand out from, otherwise the closest. */
1550
+ function buttonGroundSeparation(fill, grounds, edge) {
1551
+ const ink = edge?.border?.marksBoundary ? edge.border.boundaryInk ? resolveConcreteColorHex(edge.border.boundaryInk, edge.palette) ?? void 0 : edge.labelInk : void 0;
1552
+ return grounds.map((ground) => {
1553
+ const separation = buttonFillSeparation(fill, ground);
1554
+ const distinct = separation.distinct || ink !== void 0 && contrastRatio(ink, ground) >= BUTTON_CONTRAST_POLICY.nonTextMinimumRatio;
1555
+ return {
1556
+ ...separation,
1557
+ distinct,
1558
+ ground
1559
+ };
1560
+ }).reduce((worst, next) => {
1561
+ if (worst.distinct !== next.distinct) return worst.distinct ? next : worst;
1562
+ return next.deltaE < worst.deltaE ? next : worst;
1495
1563
  });
1496
- return resolved.ok ? {
1497
- ...resolved,
1498
- nonColourEffects: transition.nonColourEffects
1499
- } : resolved;
1500
1564
  }
1501
- function collectStateColours(results) {
1502
- if (!results.base.ok) return results.base;
1503
- if (!results.hover.ok) return results.hover;
1504
- if (!results.focus.ok) return results.focus;
1505
- if (!results.active.ok) return results.active;
1506
- if (!results.disabled.ok) return results.disabled;
1507
- const states = {
1508
- base: results.base.colour,
1509
- hover: results.hover.colour,
1510
- focus: results.focus.colour,
1511
- active: results.active.colour,
1512
- disabled: results.disabled.colour
1565
+ function validateButtonFillSeparation(input) {
1566
+ const token = input.border?.marksBoundary ? input.border.boundaryInk : void 0;
1567
+ if (token && !resolveConcreteColorHex(token, input.palette)) return {
1568
+ ok: false,
1569
+ error: {
1570
+ tag: "unknown_palette_token",
1571
+ variantId: input.variantId,
1572
+ state: input.state,
1573
+ token
1574
+ }
1513
1575
  };
1514
- return {
1515
- ok: true,
1516
- states,
1517
- focusIndicator: resolveFocusIndicator(states.focus),
1518
- nonColourEffects: Object.fromEntries(Object.entries(results).flatMap(([state, result]) => result.ok && result.nonColourEffects.length > 0 ? [[state, [...result.nonColourEffects]]] : []))
1576
+ const separation = buttonSurfaceSeparation(input.buttonPaint, input.surface, input);
1577
+ return separation.distinct ? { ok: true } : {
1578
+ ok: false,
1579
+ error: {
1580
+ tag: "insufficient_surface_separation",
1581
+ variantId: input.variantId,
1582
+ state: input.state,
1583
+ buttonPaint: input.buttonPaint,
1584
+ surface: separation.ground,
1585
+ deltaE: separation.deltaE,
1586
+ requiredDeltaE: BUTTON_CONTRAST_POLICY.filledMinimumDeltaE
1587
+ }
1519
1588
  };
1520
1589
  }
1521
- function resolveTreatment(input) {
1522
- const treatment = input.treatment;
1523
- switch (treatment.type) {
1524
- case "surface":
1525
- if (input.surface) {
1526
- const surface = input.surface;
1527
- const foreground = buttonSurfaceGrounds(surface).map((backgroundHex) => validateButtonTextContrast({
1528
- ...input,
1529
- background: "surface",
1530
- backgroundHex,
1531
- foreground: "surface-foreground",
1532
- foregroundHex: surface.foregroundHex
1533
- })).find((result) => !result.ok) ?? { ok: true };
1534
- if (!foreground.ok) return foreground;
1535
- }
1536
- return {
1537
- ok: true,
1538
- colour: {
1539
- kind: "surface",
1540
- role: treatment.role,
1541
- backgroundCss: "transparent",
1542
- foregroundCss: input.surface?.foregroundCss ?? surfaceForegroundValue(treatment.role)
1543
- }
1544
- };
1545
- case "solid": return resolveSolid(input, treatment.colorToken, treatment.foregroundToken);
1546
- case "gradient": return resolveGradient(input, treatment);
1547
- }
1548
- }
1549
- function resolveFocusIndicator(colour) {
1550
- switch (colour.kind) {
1551
- case "solid":
1552
- case "known-solid": return {
1553
- kind: "two-tone",
1554
- innerCss: colour.foregroundCss,
1555
- outerCss: colour.backgroundCss,
1556
- minimumPairContrast: BUTTON_CONTRAST_POLICY.textMinimumRatio
1557
- };
1558
- case "gradient": return {
1559
- kind: "two-tone",
1560
- innerCss: colour.foregroundCss,
1561
- outerCss: tokenCss(colour.backgroundTokens[0]),
1562
- minimumPairContrast: BUTTON_CONTRAST_POLICY.textMinimumRatio
1563
- };
1564
- case "surface": return {
1565
- kind: "surface-role",
1566
- colorCss: colour.foregroundCss,
1567
- minimumSurfaceContrast: BUTTON_CONTRAST_POLICY.nonTextMinimumRatio
1568
- };
1569
- }
1570
- }
1571
- function resolveSolid(input, backgroundToken, preferredForeground) {
1572
- const backgroundHex = paletteHex(input, backgroundToken);
1573
- if (!backgroundHex.ok) return backgroundHex;
1574
- const ink = resolveSolidInk(input, backgroundToken, backgroundHex.hex, preferredForeground);
1575
- const boundary = input.surface ? validateButtonFillSeparation({
1576
- ...input,
1577
- buttonPaint: backgroundHex.hex,
1578
- surface: input.surface,
1579
- labelInk: ink.foregroundHex
1580
- }) : { ok: true };
1581
- if (!boundary.ok) return boundary;
1582
- return {
1583
- ok: true,
1584
- colour: ink.colour
1590
+ function validateButtonTextContrast(input) {
1591
+ const ratio = contrastRatio(input.backgroundHex, input.foregroundHex, input.colourIndex);
1592
+ return ratio >= BUTTON_CONTRAST_POLICY.textMinimumRatio ? { ok: true } : {
1593
+ ok: false,
1594
+ error: {
1595
+ tag: "insufficient_contrast",
1596
+ variantId: input.variantId,
1597
+ state: input.state,
1598
+ background: input.background,
1599
+ foreground: input.foreground,
1600
+ ratio,
1601
+ requiredRatio: BUTTON_CONTRAST_POLICY.textMinimumRatio
1602
+ }
1585
1603
  };
1586
1604
  }
1605
+ /** A text-token slab inverts the palette's text/background pair, including text shades. */
1606
+ function solidForegroundToken(backgroundToken) {
1607
+ return /^text(?:-\d+)?$/.test(backgroundToken) ? "background" : onColorTokenName(backgroundToken);
1608
+ }
1609
+ //#endregion
1610
+ //#region ../theme-core/src/buttons/effectClassification.ts
1587
1611
  /**
1588
- * One solid fill's colours as any button paints them, for chrome that dresses
1589
- * itself as a button outside the variant CSS (the header's inverted CTA): the
1590
- * requested label when it reads, else the fill's on-colour, else black or white.
1612
+ * Exhaustive live policy for every registered effect id.
1613
+ *
1614
+ * The resolver consumes the transition payload directly, so adding an effect
1615
+ * cannot update classification without also defining its runtime behavior.
1591
1616
  */
1592
- function resolveSolidButtonColour(input, backgroundToken, preferredForeground) {
1593
- return resolveSolid(input, backgroundToken, preferredForeground);
1594
- }
1595
- /** Preserve checked on-colours (a requested label colour first); a solid state's last resort is the palette ink for its actual fill. */
1596
- function resolveSolidInk(input, backgroundToken, backgroundHex, preferredForeground) {
1597
- if (preferredForeground !== void 0) {
1598
- const preferred = checkedSolidInk(input, backgroundToken, backgroundHex, preferredForeground);
1599
- if (preferred) return preferred;
1600
- }
1601
- return checkedSolidInk(input, backgroundToken, backgroundHex, unsafeAsOpaqueButtonColourToken(solidForegroundToken(backgroundToken))) ?? paletteSolidInk(input, backgroundToken, backgroundHex);
1602
- }
1603
- function checkedSolidInk(input, backgroundToken, backgroundHex, foregroundToken) {
1604
- const candidate = input.palette[foregroundToken];
1605
- if ((typeof candidate === "string" ? validateButtonTextContrast({
1606
- ...input,
1607
- background: backgroundToken,
1608
- backgroundHex,
1609
- foreground: foregroundToken,
1610
- foregroundHex: candidate
1611
- }) : null)?.ok === true && typeof candidate === "string") return {
1612
- foregroundHex: candidate,
1613
- colour: {
1614
- kind: "solid",
1615
- backgroundToken,
1616
- foregroundToken,
1617
- backgroundCss: tokenCss(backgroundToken),
1618
- foregroundCss: tokenCss(foregroundToken)
1617
+ const BUTTON_EFFECT_POLICIES = {
1618
+ "darken-background": {
1619
+ classification: "colour-transition",
1620
+ transition: {
1621
+ kind: "adjust-shade",
1622
+ direction: "darker"
1623
+ }
1624
+ },
1625
+ "lighten-background": {
1626
+ classification: "colour-transition",
1627
+ transition: {
1628
+ kind: "adjust-shade",
1629
+ direction: "lighter"
1619
1630
  }
1631
+ },
1632
+ "background-on-hover": {
1633
+ classification: "colour-transition",
1634
+ transition: { kind: "replace-background" }
1635
+ },
1636
+ "background-on-hover-alpha": {
1637
+ classification: "unsupported-colour",
1638
+ reason: "alpha_requires_surface"
1639
+ },
1640
+ "fade-background": {
1641
+ classification: "unsupported-colour",
1642
+ reason: "changes_element_opacity"
1643
+ },
1644
+ "opacity-reduce": {
1645
+ classification: "unsupported-colour",
1646
+ reason: "changes_element_opacity"
1647
+ },
1648
+ "gradient-text": {
1649
+ classification: "unsupported-colour",
1650
+ reason: "changes_foreground"
1651
+ },
1652
+ "text-color-change": {
1653
+ classification: "unsupported-colour",
1654
+ reason: "changes_foreground"
1655
+ },
1656
+ "border-color-change": {
1657
+ classification: "unsupported-colour",
1658
+ reason: "changes_border"
1659
+ },
1660
+ "aurora-glow": {
1661
+ classification: "unsupported-background-overlay",
1662
+ reason: "unresolved_background_overlay"
1663
+ },
1664
+ "cosmic-stardust": {
1665
+ classification: "unsupported-background-overlay",
1666
+ reason: "unresolved_background_overlay"
1667
+ },
1668
+ "gradient-border-fill": {
1669
+ classification: "unsupported-background-overlay",
1670
+ reason: "unresolved_background_overlay"
1671
+ },
1672
+ "animated-gradient-border-fill": {
1673
+ classification: "unsupported-background-overlay",
1674
+ reason: "unresolved_background_overlay"
1675
+ },
1676
+ "nav-underline": {
1677
+ classification: "not-button",
1678
+ reason: "not_button_effect"
1679
+ },
1680
+ "nav-frosted-base": {
1681
+ classification: "not-button",
1682
+ reason: "not_button_effect"
1683
+ },
1684
+ "nav-frosted-hover": {
1685
+ classification: "not-button",
1686
+ reason: "not_button_effect"
1687
+ },
1688
+ "nav-frosted-active": {
1689
+ classification: "not-button",
1690
+ reason: "not_button_effect"
1691
+ },
1692
+ "animated-gradient": { classification: "non-colour" },
1693
+ "border-glow": {
1694
+ classification: "unsupported-colour",
1695
+ reason: "changes_shadow_colour"
1696
+ },
1697
+ "drop-shadow": { classification: "decorative-colour" },
1698
+ "inner-shadow": { classification: "decorative-colour" },
1699
+ "neumorphic-shadow": { classification: "decorative-colour" },
1700
+ "outer-glow": {
1701
+ classification: "unsupported-colour",
1702
+ reason: "changes_shadow_colour"
1703
+ },
1704
+ "retro-3d-shadow": { classification: "decorative-colour" },
1705
+ "scale-up": { classification: "non-colour" },
1706
+ "scale-down": { classification: "non-colour" },
1707
+ lift: { classification: "non-colour" },
1708
+ "press-down": { classification: "non-colour" },
1709
+ pop: { classification: "non-colour" },
1710
+ "border-bottom-grow": { classification: "non-colour" },
1711
+ "sketchy-border": { classification: "decorative-colour" },
1712
+ "inner-dashed-outline": { classification: "decorative-colour" },
1713
+ "pulse-animation": {
1714
+ classification: "unsupported-colour",
1715
+ reason: "changes_element_opacity"
1716
+ }
1717
+ };
1718
+ function validateButtonEffectOptions(effect) {
1719
+ const parsed = buttonEffectApplicationSchema.safeParse(effect);
1720
+ if (parsed.success) return { ok: true };
1721
+ const firstIssue = parsed.error.issues[0];
1722
+ const firstPathPart = firstIssue?.path[firstIssue.path.length - 1];
1723
+ return {
1724
+ ok: false,
1725
+ option: (firstIssue?.code === "unrecognized_keys" ? firstIssue.keys[0] : void 0) ?? (typeof firstPathPart === "string" ? firstPathPart : "options")
1620
1726
  };
1621
- return null;
1622
1727
  }
1623
- /** The palette's own background or text as the label where it reads (as a checked token), else literal black or white. */
1624
- function paletteSolidInk(input, backgroundToken, backgroundHex) {
1625
- const ink = paletteInkOnSolid(backgroundHex, paletteInkRoles(input.palette));
1626
- const role = ink.kind === "role" ? checkedSolidInk(input, backgroundToken, backgroundHex, unsafeAsOpaqueButtonColourToken(ink.role)) : null;
1627
- if (role) return role;
1628
- const literal = pickBlackOrWhiteTextColor(backgroundHex);
1629
- return {
1630
- foregroundHex: literal,
1631
- colour: {
1632
- kind: "known-solid",
1633
- backgroundCss: tokenCss(backgroundToken),
1634
- foregroundCss: literal
1635
- }
1728
+ function getButtonEffectPolicy(effectId) {
1729
+ return Object.prototype.hasOwnProperty.call(BUTTON_EFFECT_POLICIES, effectId) ? BUTTON_EFFECT_POLICIES[effectId] : null;
1730
+ }
1731
+ //#endregion
1732
+ //#region ../theme-core/src/buttons/buttonColourTransitions.ts
1733
+ function applyColourEffects(input) {
1734
+ return (input.effects ?? []).reduce((current, effect) => current.ok ? applyEffect(input, current, effect) : current, {
1735
+ ok: true,
1736
+ treatment: input.treatment,
1737
+ nonColourEffects: []
1738
+ });
1739
+ }
1740
+ function applyEffect(input, current, effect) {
1741
+ const policy = getButtonEffectPolicy(effect.effectId);
1742
+ if (policy === null) return unknownEffect(input, effect);
1743
+ if (policy.classification === "unsupported-colour" || policy.classification === "unsupported-background-overlay" || policy.classification === "not-button") return unsupportedEffect(input, effect, policy.reason);
1744
+ const options = validateButtonEffectOptions(effect);
1745
+ if (!options.ok) return invalidEffectOption(input, effect, options.option);
1746
+ return policy.classification === "colour-transition" ? transitionColour(input, current, effect) : {
1747
+ ...current,
1748
+ nonColourEffects: [...current.nonColourEffects, effect]
1636
1749
  };
1637
1750
  }
1638
- function resolveGradient(input, treatment) {
1639
- const foregroundHex = paletteHex(input, treatment.foregroundToken);
1640
- if (!foregroundHex.ok) return foregroundHex;
1641
- const stopHexes = [];
1642
- for (const token of treatment.stops) {
1643
- const stop = paletteHex(input, token);
1644
- if (!stop.ok) return stop;
1645
- stopHexes.push(stop.hex);
1646
- }
1647
- for (let segment = 0; segment < stopHexes.length - 1; segment += 1) {
1648
- const start = stopHexes[segment];
1649
- const end = stopHexes[segment + 1];
1650
- const startToken = treatment.stops[segment];
1651
- const endToken = treatment.stops[segment + 1];
1652
- if (start === void 0 || end === void 0 || startToken === void 0 || endToken === void 0) continue;
1653
- for (let sample = 0; sample <= BUTTON_CONTRAST_POLICY.gradientSamplesPerSegment; sample += 1) {
1654
- const position = sample / BUTTON_CONTRAST_POLICY.gradientSamplesPerSegment;
1655
- const sampleHex = interpolateHex(start, end, position);
1656
- const contrast = validateButtonTextContrast({
1657
- ...input,
1658
- background: `${startToken}→${endToken}@${position.toFixed(2)}`,
1659
- backgroundHex: sampleHex,
1660
- foreground: treatment.foregroundToken,
1661
- foregroundHex: foregroundHex.hex
1662
- });
1663
- if (!contrast.ok) return contrast;
1664
- if (input.surface) {
1665
- const boundary = validateButtonFillSeparation({
1666
- ...input,
1667
- buttonPaint: sampleHex,
1668
- labelInk: foregroundHex.hex,
1669
- surface: input.surface
1670
- });
1671
- if (!boundary.ok) return boundary;
1751
+ function transitionColour(input, current, effect) {
1752
+ if (effect.effectId === "background-on-hover") {
1753
+ const colorToken = readOpaqueToken(effect);
1754
+ return colorToken === null ? invalidEffectOption(input, effect, "colorToken") : {
1755
+ ...current,
1756
+ treatment: {
1757
+ type: "solid",
1758
+ colorToken
1672
1759
  }
1673
- }
1760
+ };
1674
1761
  }
1675
- const direction = GRADIENT_DIRECTION_MAP[treatment.direction] ?? "to right";
1762
+ if (effect.effectId !== "darken-background" && effect.effectId !== "lighten-background") return unknownEffect(input, effect);
1763
+ if (current.treatment.type !== "solid") return inapplicableEffect(input, effect, current.treatment);
1764
+ const amount = readShadeAmount(effect);
1765
+ if (amount === null) return invalidEffectOption(input, effect, "amount");
1676
1766
  return {
1677
- ok: true,
1678
- colour: {
1679
- kind: "gradient",
1680
- backgroundTokens: treatment.stops,
1681
- foregroundToken: treatment.foregroundToken,
1682
- backgroundCss: `linear-gradient(${direction}, ${treatment.stops.map(tokenCss).join(", ")})`,
1683
- foregroundCss: tokenCss(treatment.foregroundToken)
1684
- }
1685
- };
1686
- }
1687
- function paletteHex(input, token) {
1688
- const hex = input.palette[token];
1689
- return typeof hex === "string" ? {
1690
- ok: true,
1691
- hex
1692
- } : {
1693
- ok: false,
1694
- error: {
1695
- tag: "unknown_palette_token",
1696
- variantId: input.variantId,
1697
- state: input.state,
1698
- token
1767
+ ...current,
1768
+ treatment: {
1769
+ type: "solid",
1770
+ colorToken: adjustShade(current.treatment.colorToken, effect.effectId === "darken-background" ? amount : -amount, input.palette)
1699
1771
  }
1700
1772
  };
1701
1773
  }
1702
- function tokenCss(token) {
1703
- return `rgb(var(--tb-${token}))`;
1704
- }
1705
- function interpolateHex(startHex, endHex, position) {
1706
- const start = hexToRgb(startHex);
1707
- const end = hexToRgb(endHex);
1708
- const channel = (from, to) => Math.round(from + (to - from) * position).toString(16).padStart(2, "0");
1709
- return `#${channel(start.r, end.r)}${channel(start.g, end.g)}${channel(start.b, end.b)}`;
1710
- }
1711
- //#endregion
1712
- //#region ../theme-core/src/palette/generateShades.ts
1713
- function generateShades(hexColor, name) {
1714
- const shadeSteps = [
1774
+ function adjustShade(token, amount, palette) {
1775
+ const match = token.match(/^(.*)-(\d{2,3})$/);
1776
+ const base = match?.[1] ?? token;
1777
+ const currentShade = match?.[2] === void 0 ? 500 : Number(match[2]);
1778
+ const availableShades = [
1715
1779
  50,
1716
1780
  100,
1717
1781
  200,
@@ -1723,390 +1787,650 @@ function generateShades(hexColor, name) {
1723
1787
  800,
1724
1788
  900,
1725
1789
  950
1726
- ];
1727
- const base = featuresFromHex(hexColor);
1728
- const hue = base.okH;
1729
- const baseChroma = base.okC;
1730
- const toneMap = {
1731
- 50: .975,
1732
- 100: .945,
1733
- 200: .89,
1734
- 300: .82,
1735
- 400: .74,
1736
- 500: .66,
1737
- 600: .58,
1738
- 700: .49,
1739
- 800: .4,
1740
- 900: .28,
1741
- 950: .16
1790
+ ].filter((shade) => typeof palette[`${base}-${shade}`] === "string");
1791
+ if (availableShades.length === 0) return token;
1792
+ const firstShade = availableShades[0];
1793
+ if (firstShade === void 0) return token;
1794
+ const exactIndex = availableShades.indexOf(currentShade);
1795
+ const startingIndex = exactIndex >= 0 ? exactIndex : availableShades.indexOf(availableShades.reduce((closestShade, shade) => Math.abs(shade - currentShade) < Math.abs(closestShade - currentShade) ? shade : closestShade, firstShade));
1796
+ const stepCount = Math.abs(amount) / 100;
1797
+ const direction = amount < 0 ? -1 : 1;
1798
+ const targetShade = availableShades[Math.max(0, Math.min(availableShades.length - 1, startingIndex + direction * stepCount))];
1799
+ return targetShade === void 0 ? token : unsafeAsOpaqueButtonColourToken(`${base}-${targetShade}`);
1800
+ }
1801
+ function readShadeAmount(effect) {
1802
+ const value = effect.options?.amount ?? 100;
1803
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 && value % 100 === 0 ? value : null;
1804
+ }
1805
+ function readOpaqueToken(effect) {
1806
+ return parseOpaqueButtonColourToken(effect.options?.colorToken ?? "neutral-800");
1807
+ }
1808
+ function unsupportedEffect(input, effect, reason) {
1809
+ return {
1810
+ ok: false,
1811
+ error: {
1812
+ tag: "unsupported_colour_effect",
1813
+ variantId: input.variantId,
1814
+ state: input.state,
1815
+ effectId: effect.effectId,
1816
+ reason
1817
+ }
1742
1818
  };
1743
- const shadeDefs = shadeSteps.map((step, idx) => {
1744
- const t = idx / (shadeSteps.length - 1);
1745
- const L = toneMap[step];
1746
- const C = baseChroma * (.06 + .94 * Math.sin(Math.PI * t));
1747
- return {
1748
- name: `${name}-${step}`,
1749
- hex: oklchToHexGamut(L, C, hue)
1750
- };
1751
- });
1752
- shadeDefs.push({
1753
- name,
1754
- hex: hexColor
1755
- });
1756
- return shadeDefs;
1757
1819
  }
1758
- //#endregion
1759
- //#region ../theme-core/src/palette/neutralScale.ts
1760
- /** The cool slate tint every scale had before #1863, kept for grounds with no hue to lend. */
1761
- const SLATE_NEUTRAL_TINT = {
1762
- hue: 250,
1763
- chroma: .02
1764
- };
1765
- /** Below this OKLCH chroma a background reads as plain white, grey or black, so its hue is noise. */
1766
- const ACHROMATIC_CHROMA = .005;
1767
- /**
1768
- * The tint a palette's greys take from its background: the background's own
1769
- * hue at no more than the slate scale's chroma, so a cream site gets warm greys.
1770
- * A background with no hue to lend (white, `#fafafa`, a missing or unreadable
1771
- * value) keeps the slate tint, so those palettes keep their exact neutrals.
1772
- */
1773
- function neutralTint(background) {
1774
- const parsed = hexColorSchema.safeParse(background?.toLowerCase());
1775
- if (!parsed.success) return SLATE_NEUTRAL_TINT;
1776
- const { r, g, b } = hexToRgb(parsed.data);
1777
- const { L, a, b: ob } = srgbToOklab(r, g, b);
1778
- const { C, h } = oklabToOklch(L, a, ob);
1779
- return C < ACHROMATIC_CHROMA ? SLATE_NEUTRAL_TINT : {
1780
- hue: h,
1781
- chroma: Math.min(C, SLATE_NEUTRAL_TINT.chroma)
1820
+ function invalidEffectOption(input, effect, option) {
1821
+ return {
1822
+ ok: false,
1823
+ error: {
1824
+ tag: "invalid_colour_effect_options",
1825
+ variantId: input.variantId,
1826
+ state: input.state,
1827
+ effectId: effect.effectId,
1828
+ option
1829
+ }
1782
1830
  };
1783
1831
  }
1784
- /**
1785
- * A neutral scale from near-white (`neutral-50`) to near-black (`neutral-950`)
1786
- * on every palette, light or dark. Readers that want "the ground" or "the
1787
- * text" ask the palette for those roles, not a fixed end of this scale.
1788
- */
1789
- function generateNeutralScale({ steps = 11, tint = SLATE_NEUTRAL_TINT } = {}) {
1790
- const shadeNames = [
1791
- 50,
1792
- 100,
1793
- 200,
1794
- 300,
1795
- 400,
1796
- 500,
1797
- 600,
1798
- 700,
1799
- 800,
1800
- 900,
1801
- 950
1802
- ];
1803
- const count = Math.min(steps, shadeNames.length);
1804
- return shadeNames.slice(0, count).map((shadeName, index) => ({
1805
- name: `neutral-${shadeName}`,
1806
- hex: oklchToHexGamut(mix(.98, .1, index / (count - 1)), tint.chroma, tint.hue)
1807
- }));
1832
+ function inapplicableEffect(input, effect, treatment) {
1833
+ return {
1834
+ ok: false,
1835
+ error: {
1836
+ tag: "inapplicable_colour_effect",
1837
+ variantId: input.variantId,
1838
+ state: input.state,
1839
+ effectId: effect.effectId,
1840
+ treatment: treatment.type
1841
+ }
1842
+ };
1808
1843
  }
1809
- function mix(a, b, t) {
1810
- return a + (b - a) * Math.max(0, Math.min(1, t));
1844
+ function unknownEffect(input, effect) {
1845
+ return {
1846
+ ok: false,
1847
+ error: {
1848
+ tag: "unknown_button_effect",
1849
+ variantId: input.variantId,
1850
+ state: input.state,
1851
+ effectId: effect.effectId
1852
+ }
1853
+ };
1811
1854
  }
1812
1855
  //#endregion
1813
- //#region ../theme-core/src/palette/utils/scrimContrast.ts
1814
- const WHITE = "#ffffff";
1815
- const BLACK = "#000000";
1816
- /** `top` at `alpha` over opaque `bottom`, blended as CSS paints an overlay. */
1817
- function compositeHex(topHex, alpha, bottomHex) {
1818
- const top = hexToRgb(topHex);
1819
- const bottom = hexToRgb(bottomHex);
1820
- const mix = (a, b) => Math.round(alpha * a + (1 - alpha) * b);
1821
- return rgbToHex(mix(top.r, bottom.r), mix(top.g, bottom.g), mix(top.b, bottom.b));
1822
- }
1856
+ //#region ../theme-core/src/buttons/contextualHover.ts
1823
1857
  /**
1824
- * The lowest contrast `foreground` can reach over `scrim` at `alpha` laid on
1825
- * any pixel. A foreground whose luminance falls inside the range the
1826
- * composites can take has a worst case of 1:1.
1858
+ * The smallest OKLab move that reads as a hover. Neighbouring steps of a
1859
+ * palette scale are about 0.06 to 0.08 apart.
1827
1860
  */
1828
- function worstCaseScrimContrast(input) {
1829
- const overWhite = compositeHex(input.scrimHex, input.alpha, WHITE);
1830
- const overBlack = compositeHex(input.scrimHex, input.alpha, BLACK);
1831
- const luminance = (hex) => {
1832
- const { r, g, b } = hexToRgb(hex);
1833
- return relativeLuminance(r, g, b);
1834
- };
1835
- const foreground = luminance(input.foregroundHex);
1836
- const low = luminance(overBlack);
1837
- const high = luminance(overWhite);
1838
- if (foreground >= low && foreground <= high) return 1;
1839
- return Math.min(contrastRatio(input.foregroundHex, overWhite), contrastRatio(input.foregroundHex, overBlack));
1840
- }
1861
+ const MINIMUM_VISIBLE_STEP = .04;
1841
1862
  /**
1842
- * The smallest scrim opacity, in hundredths, at which every foreground keeps
1843
- * `threshold` contrast over any pixel. `null` when even an opaque scrim fails,
1844
- * which means the foreground was never legible on the scrim colour itself.
1863
+ * The contrast at which a fill reads as a fill rather than a shadow on its
1864
+ * ground. It applies when the recipe names the ink to fill with
1865
+ * (`preferredToken`): those buttons rest as an outline and fill only on hover,
1866
+ * so the fill has to read against the ground on its own. A button edge can keep
1867
+ * a darker fill distinct, but it then looks like a hole in the panel.
1845
1868
  */
1846
- function minimumScrimOpacity(input) {
1847
- const passes = (alpha) => input.foregroundHexes.every((foregroundHex) => worstCaseScrimContrast({
1848
- foregroundHex,
1849
- scrimHex: input.scrimHex,
1850
- alpha
1851
- }) >= input.threshold);
1852
- return Array.from({ length: 101 }, (_, hundredths) => hundredths / 100).find(passes) ?? null;
1853
- }
1854
- /** Shared samples for literal RGB washes and palette-token gradient veils. */
1855
- function gradientScrimSamples(gradient, alpha, palette) {
1856
- const literal = [...gradient.matchAll(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/g)].map((stop) => ({
1857
- hex: rgbToHex(Number(stop[1]), Number(stop[2]), Number(stop[3])),
1858
- alpha: alpha * (stop[4] === void 0 ? 1 : Number(stop[4]))
1859
- }));
1860
- const tokens = [...gradient.matchAll(/var\(--tb-([\w-]+)\)/g)].flatMap((stop) => {
1861
- const hex = stop[1] ? resolveConcreteColorHex(stop[1], palette) : null;
1862
- return hex ? [{
1863
- hex,
1864
- alpha
1865
- }] : [];
1866
- });
1867
- return [...literal, ...tokens];
1868
- }
1869
- /** The ink with the stronger worst-pixel guarantee identifies the veil tone.
1870
- * No readable samples (or a tie) leaves classification to the foreground owner.
1869
+ const FILL_CLEARS_GROUND = 1.5;
1870
+ /** Two label inks closer than this read as the same ink (a near-black for black); a light label against a dark one is far above it. */
1871
+ const SAME_LABEL_INK = 3;
1872
+ /** A step a filled button can change its label for: one or two neighbouring shades of its scale. */
1873
+ const NEAR_STEP = .2;
1874
+ /**
1875
+ * The ends of a scale are often close to neutral black or white. A shade below
1876
+ * the dark end or above the light end (OKLab lightness) that has under this
1877
+ * share of the seed's chroma reads as grey, black or white, not as the button.
1871
1878
  */
1872
- function scrimTone(samples) {
1873
- if (samples.length === 0) return null;
1874
- const worst = (foregroundHex) => Math.min(...samples.map((sample) => worstCaseScrimContrast({
1875
- foregroundHex,
1876
- scrimHex: sample.hex,
1877
- alpha: sample.alpha
1878
- })));
1879
- const white = worst(WHITE);
1880
- const black = worst(BLACK);
1881
- return white === black ? null : white > black ? "dark" : "light";
1882
- }
1883
- //#endregion
1884
- //#region ../theme-core/src/palette/expandPalette.ts
1885
- function colorsToMap(palette) {
1886
- const map = {};
1887
- for (const c of palette.colors) map[c.name] = c.hex;
1888
- return map;
1879
+ const HUELESS_DARK_END = .2;
1880
+ const HUELESS_LIGHT_END = .94;
1881
+ const HUE_KEPT_SHARE = .5;
1882
+ /** The recipe's own hover ink wins when it holds; otherwise the shade shift decides. */
1883
+ function resolveContextualHoverPreference(input) {
1884
+ const preferred = input.instruction.preferredToken;
1885
+ if (preferred && preferredInkHolds(preferred, input)) return {
1886
+ kind: "resolved",
1887
+ token: preferred,
1888
+ repair: null
1889
+ };
1890
+ const contextual = resolveContextualHover(input);
1891
+ if (contextual.kind === "unavailable") return contextual;
1892
+ return {
1893
+ kind: "resolved",
1894
+ token: contextual.token,
1895
+ repair: preferred ? {
1896
+ kind: "preferred-token-replaced",
1897
+ preferredToken: preferred,
1898
+ contextualToken: contextual.token
1899
+ } : null
1900
+ };
1889
1901
  }
1890
- const nonShadeablePaletteRoleNames = /* @__PURE__ */ new Set([
1891
- "success",
1892
- "warning",
1893
- "destructive"
1894
- ]);
1895
1902
  /**
1896
- * Status role aliases the persisted palette does not carry itself.
1903
+ * Chooses the hover fill from the seed's own shade family, so the hue stays.
1897
1904
  *
1898
- * Generators reference `--tb-error` (the site-style-owned input error border)
1899
- * and `--tb-info` (`.alert-info`, `.status-info`, the field-note rule), but the
1900
- * palette schema only defines `destructive` and has no `info` role at all.
1901
- * Without these aliases those declarations name variables that are never
1902
- * defined and browsers drop them. The SDK bridge resolves the same pair via
1903
- * TOKEN_ALIASES, so both runtimes agree on what a status token means.
1905
+ * A hover should read as the same button, stronger. The choice is made on the
1906
+ * colours themselves, not on shade numbers (a brand colour is rarely the 500
1907
+ * step of its scale). Hard limits come first: the label stays readable, the
1908
+ * hover stands apart from a known surface, and a button that rests filled
1909
+ * stays recognisably itself. `HOVER_PREFERENCE` then ranks what's left.
1904
1910
  *
1905
- * Runs after the danger → destructive promotion above, so `destructive` is
1906
- * already the single source of truth for the error colour.
1911
+ * The ground is the proven surface, or the palette's page colour when the
1912
+ * surface is unknown. With neither, the instruction's fallback direction
1913
+ * stands in for "stronger".
1907
1914
  */
1908
- function statusAliasTokens(expanded) {
1909
- const aliases = {};
1910
- if (expanded.destructive) aliases.error = expanded.destructive;
1911
- if (expanded.accent) aliases.info = expanded.accent;
1912
- return aliases;
1913
- }
1914
- function expandPalette(palette, options = {}) {
1915
+ function resolveContextualHover(input) {
1916
+ const shades = shadeCandidates(input);
1917
+ if (shades.length === 0) return {
1918
+ kind: "unavailable",
1919
+ reason: "no-distinct-shade"
1920
+ };
1921
+ const readable = shades.filter((shade) => labelReadable(shade.hex, shade.labelInk, input.colourIndex));
1922
+ if (readable.length === 0) return {
1923
+ kind: "unavailable",
1924
+ reason: "no-text-safe-candidate"
1925
+ };
1926
+ const restLabel = seedFilledRestLabel(input.rest, input.instruction.seedToken);
1927
+ const selected = pickHover(readable.filter((shade) => standsApartFromSurface(shade.hex, shade.labelInk, input) && (restLabel === void 0 || staysTheSameFilledButton(shade, restLabel))));
1928
+ const surfaceKnown = input.surface !== void 0;
1929
+ if (!selected) return {
1930
+ kind: "unavailable",
1931
+ reason: surfaceKnown ? "no-surface-safe-candidate" : "no-text-safe-candidate"
1932
+ };
1915
1933
  return {
1916
- ...expandBasePalette(palette),
1917
- ...arrangementPaletteTokens(colorsToMap(palette), options)
1934
+ kind: "resolved",
1935
+ token: selected.token,
1936
+ direction: selected.direction,
1937
+ evidence: surfaceKnown ? "known-surface" : "fallback-direction"
1918
1938
  };
1919
1939
  }
1920
- function expandBasePalette(palette) {
1921
- const base = colorsToMap(palette);
1922
- const expanded = { ...base };
1923
- const roles = paletteInkRoles(base);
1924
- generateNeutralScale({
1925
- steps: 11,
1926
- tint: neutralTint(base.background)
1927
- }).forEach((n) => {
1928
- expanded[n.name] = n.hex;
1929
- });
1930
- for (const [name, hex] of Object.entries(base)) {
1931
- if (nonShadeablePaletteRoleNames.has(name)) continue;
1932
- if (hex) generateShades(hex, name).forEach((shade) => {
1933
- expanded[shade.name] = shade.hex;
1934
- });
1935
- }
1936
- if (base.text) expanded.body = base.text;
1937
- if (base.danger && !base.destructive) expanded.destructive = base.danger;
1938
- Object.assign(expanded, statusAliasTokens(expanded));
1939
- expanded.mutedText = readableMutedText(expanded["neutral-500"] ?? "#888", base, roles);
1940
- for (const [token, hex] of Object.entries({ ...expanded })) {
1941
- if (!hex || !isOnColorBackgroundCandidateToken(token)) continue;
1942
- const onToken = onColorTokenName(token);
1943
- if (expanded[onToken]) continue;
1944
- expanded[onToken] = paletteInkOnSolid(hex, roles).hex;
1945
- }
1946
- Object.assign(expanded, groundMutedInkTokens(expanded));
1947
- return expanded;
1948
- }
1940
+ const visible = (shade) => shade.distance >= MINIMUM_VISIBLE_STEP;
1949
1941
  /**
1950
- * The strongest tints booking and registration screens lay over a ground
1951
- * where secondary text sits: selected option cards, event tiles and summaries
1952
- * tint `primary` at 5–10% (`blocks/vars/appointment-booking.ts`,
1953
- * `blocks/vars/event-registration.ts`, `blocks-static/event-registration.css`),
1954
- * the appointment summary and hover rows tint `text`/`onSurface` at 5%, and the
1955
- * registration summary lays `muted` at 42%. A weaker tint of the same colour
1956
- * sits between the ground and these, so solving against the strongest covers it.
1957
- * A selected card lays its tint over its own ground, so the same list applies
1958
- * over the surface and over the page background that event option cards paint.
1959
- * A new tint under secondary text belongs here, and the CSS paints it with
1960
- * the ground's faded tint token (`groundTintToken`) before the colour itself;
1961
- * `secondaryTextTints.test.ts` fails if the CSS lays one that isn't covered or
1962
- * doesn't read that token.
1942
+ * Where the hover is looked for, in order. The first group with a shade wins,
1943
+ * and within it the nearest visible step (or, with none visible, the furthest).
1944
+ *
1945
+ * 1. Stronger, keeping the hue, and clearing the ground when the recipe names a fill ink.
1946
+ * 2. Stronger, keeping the hue.
1947
+ * 3. The other way, keeping the hue: a visible hover beats a hue-less or invisible one.
1948
+ * 4. Any stronger shade.
1949
+ * 5. Any shade the other way.
1963
1950
  */
1964
- const SURFACE_SECONDARY_TEXT_TINTS = [
1965
- {
1966
- token: "primary",
1967
- alpha: .1
1968
- },
1969
- {
1970
- token: "text",
1971
- alpha: .05
1972
- },
1973
- {
1974
- token: "onSurface",
1975
- alpha: .05
1976
- },
1977
- {
1978
- token: "muted",
1979
- alpha: .42
1980
- }
1951
+ const HOVER_PREFERENCE = [
1952
+ (shade) => shade.stronger && shade.keepsHue && visible(shade) && shade.fillClearsGround,
1953
+ (shade) => shade.stronger && shade.keepsHue && visible(shade),
1954
+ (shade) => !shade.stronger && shade.keepsHue && visible(shade),
1955
+ (shade) => shade.stronger,
1956
+ () => true
1981
1957
  ];
1982
- /** The strongest tint alpha per colour, for the CSS that paints those tints. */
1983
- const SURFACE_SECONDARY_TEXT_TINT_ALPHA = Object.fromEntries(SURFACE_SECONDARY_TEXT_TINTS.map(({ token, alpha }) => [token, alpha]));
1984
- /**
1985
- * The grounds booking and registration secondary text sits on, with the token
1986
- * its solved muted ink is published as: the surface (panels, details) and the
1987
- * page background (event registration's option, ticket and payment cards).
1988
- */
1989
- const MUTED_INK_TOKENS = {
1990
- surface: "onSurfaceMuted",
1991
- background: "onBackgroundMuted"
1992
- };
1958
+ function pickHover(allowed) {
1959
+ for (const inGroup of HOVER_PREFERENCE) {
1960
+ const group = allowed.filter(inGroup);
1961
+ if (group.length > 0) return nearestVisibleStep(group);
1962
+ }
1963
+ }
1964
+ function nearestVisibleStep(shades) {
1965
+ const byDistance = [...shades].sort((left, right) => left.distance - right.distance || left.token.localeCompare(right.token));
1966
+ return byDistance.find(visible) ?? byDistance[byDistance.length - 1];
1967
+ }
1968
+ /** The label ink of a button that rests filled with the seed; undefined when it rests some other way (it fills only on hover). */
1969
+ function seedFilledRestLabel(rest, seed) {
1970
+ return rest.kind === "solid" && rest.colorToken === seed ? rest.labelInk : void 0;
1971
+ }
1993
1972
  /**
1994
- * Secondary text on a ground, solved rather than faded from the ground's
1995
- * on-colour in CSS, against the ground and every tint laid over it.
1996
- *
1997
- * Some palettes admit no single ink for all of them: a mid-tone surface with a
1998
- * dark `primary` tint and a light `muted` one. The plain ground always has one
1999
- * (black or white reads on any solid), so the ground is kept, each tint is kept
2000
- * in list order while one ink still reads on everything kept so far, and the
2001
- * tints that can't join are faded toward the ground until that ink reads on
2002
- * them too. Fading the tint rather than giving it an ink of its own keeps every
2003
- * line of text on it (titles and prices as well as secondary text) close to the
2004
- * ground its colours were chosen for. Hosted palettes and the SDK bridge both
2005
- * derive it here.
1973
+ * A button that rests filled with the seed should still read as itself on
1974
+ * hover. A shade that needs the other label ink is only allowed a near step
1975
+ * away (a jump across the scale with the label flipped looks like another
1976
+ * button), and a shade the other way has to keep the hue. A button that fills
1977
+ * only on hover changes its label anyway, so this doesn't apply to it.
2006
1978
  */
2007
- function groundMutedInk(palette, ground) {
2008
- const groundHex = palette[ground];
2009
- if (!groundHex) return null;
2010
- const preferred = palette[onColorTokenName(ground)] ?? null;
2011
- const roles = paletteInkRoles(palette);
2012
- const initial = {
2013
- grounds: [groundHex],
2014
- hex: paletteMutedInkOnSolid(groundHex, preferred, roles),
2015
- uncovered: []
1979
+ function staysTheSameFilledButton(shade, restLabel) {
1980
+ return (contrastRatio(shade.labelInk, restLabel) < SAME_LABEL_INK || shade.distance <= NEAR_STEP) && (shade.stronger || shade.keepsHue);
1981
+ }
1982
+ function labelReadable(hex, labelInk, colourIndex) {
1983
+ return labelInk !== void 0 && contrastRatio(hex, labelInk, colourIndex) >= BUTTON_CONTRAST_POLICY.textMinimumRatio;
1984
+ }
1985
+ /** On a proven surface, the fill stands apart from it by colour or by a declared edge. */
1986
+ function standsApartFromSurface(hex, labelInk, input) {
1987
+ return input.surface === void 0 || buttonSurfaceSeparation(hex, input.surface, {
1988
+ border: input.border,
1989
+ palette: input.palette,
1990
+ labelInk
1991
+ }).distinct;
1992
+ }
1993
+ /** The recipe's own hover ink holds when its label reads and, on a proven surface, it stands apart and clears the surface as a fill. */
1994
+ function preferredInkHolds(token, input) {
1995
+ const hex = resolveConcreteColorHex(token, input.palette);
1996
+ const labelInk = resolveConcreteColorHex(solidForegroundToken(token), input.palette) ?? void 0;
1997
+ if (hex === null || !labelReadable(hex, labelInk, input.colourIndex)) return false;
1998
+ return input.surface === void 0 || standsApartFromSurface(hex, labelInk, input) && contrastRatio(hex, input.surface.backgroundHex, input.colourIndex) >= FILL_CLEARS_GROUND;
1999
+ }
2000
+ /** The other steps of the seed's scale (`primary-100` … `primary-950`), measured against the seed and the ground. */
2001
+ function shadeCandidates(input) {
2002
+ const { instruction, palette, colourIndex } = input;
2003
+ const seedHex = resolveConcreteColorHex(instruction.seedToken, palette);
2004
+ if (seedHex === null) return [];
2005
+ const family = String(instruction.seedToken).match(/^(.*?)(?:-\d{2,3})?$/)?.[1] ?? String(instruction.seedToken);
2006
+ const step = new RegExp(`^${escapeRegExp(family)}-\\d{2,3}$`);
2007
+ const ground = input.surface?.backgroundHex ?? palette.background;
2008
+ const seed = {
2009
+ hex: seedHex,
2010
+ lightness: contrastRatio(seedHex, "#000000"),
2011
+ chroma: oklab(seedHex).chroma,
2012
+ ground: ground === void 0 ? void 0 : {
2013
+ contrast: (hex) => contrastRatio(hex, ground, colourIndex),
2014
+ restContrast: contrastRatio(seedHex, ground, colourIndex)
2015
+ }
2016
+ };
2017
+ return Object.keys(palette).flatMap((name) => {
2018
+ const token = step.test(name) ? parseOpaqueButtonColourToken(name) : null;
2019
+ const hex = token === null ? void 0 : palette[token];
2020
+ return token === null || hex === void 0 || hex === seedHex ? [] : [describeShade(token, hex, seed, input)];
2021
+ });
2022
+ }
2023
+ function describeShade(token, hex, seed, input) {
2024
+ const { instruction, palette } = input;
2025
+ const direction = contrastRatio(hex, "#000000") > seed.lightness ? "lighter" : "darker";
2026
+ const groundContrast = seed.ground?.contrast(hex);
2027
+ return {
2028
+ token,
2029
+ hex,
2030
+ direction,
2031
+ labelInk: resolveConcreteColorHex(solidForegroundToken(token), palette) ?? void 0,
2032
+ distance: hexOklabDistance(seed.hex, hex),
2033
+ stronger: seed.ground === void 0 ? direction === instruction.fallbackDirection : seed.ground.contrast(hex) >= seed.ground.restContrast,
2034
+ keepsHue: keepsHue(oklab(hex), seed.chroma),
2035
+ fillClearsGround: instruction.preferredToken !== void 0 && groundContrast !== void 0 && groundContrast >= FILL_CLEARS_GROUND
2036
+ };
2037
+ }
2038
+ function keepsHue(shade, seedChroma) {
2039
+ return !(shade.lightness < HUELESS_DARK_END || shade.lightness > HUELESS_LIGHT_END) || shade.chroma >= seedChroma * HUE_KEPT_SHARE;
2040
+ }
2041
+ function oklab(hex) {
2042
+ const { r, g, b } = hexToRgb(hex);
2043
+ const lab = srgbToOklab(r, g, b);
2044
+ return {
2045
+ lightness: lab.L,
2046
+ chroma: Math.hypot(lab.a, lab.b)
2047
+ };
2048
+ }
2049
+ function escapeRegExp(value) {
2050
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2051
+ }
2052
+ //#endregion
2053
+ //#region ../theme-core/src/buttons/resolveButtonHoverTreatment.ts
2054
+ function resolveButtonHoverTreatment(input) {
2055
+ if (input.variant.contextualHover) {
2056
+ const contextual = resolveContextualHoverPreference({
2057
+ instruction: input.variant.contextualHover,
2058
+ palette: input.palette,
2059
+ colourIndex: input.colourIndex,
2060
+ surface: input.surface,
2061
+ border: input.variant.border,
2062
+ rest: input.rest
2063
+ });
2064
+ if (contextual.kind === "resolved") return {
2065
+ treatment: {
2066
+ type: "solid",
2067
+ colorToken: contextual.token
2068
+ },
2069
+ repair: contextual.repair
2070
+ };
2071
+ }
2072
+ const token = input.variant.hoverBackgroundToken ?? (input.global.hoverColor === "token" ? input.global.hoverColorToken : void 0);
2073
+ return {
2074
+ treatment: token === void 0 ? input.fallback : {
2075
+ type: "solid",
2076
+ colorToken: token
2077
+ },
2078
+ repair: null
2079
+ };
2080
+ }
2081
+ //#endregion
2082
+ //#region ../theme-core/src/buttons/resolveButtonColourStates.ts
2083
+ function mapVisualStates(value) {
2084
+ return {
2085
+ base: value("base"),
2086
+ hover: value("hover"),
2087
+ focus: value("focus"),
2088
+ active: value("active"),
2089
+ disabled: value("disabled")
2090
+ };
2091
+ }
2092
+ /** The border a state draws: its declared appearance's, otherwise the variant's. */
2093
+ function buttonStateBorder(variant, state) {
2094
+ const appearance = variant.visualStates?.[state];
2095
+ if (!appearance) return variant.border;
2096
+ return appearance.border === "none" ? void 0 : appearance.border;
2097
+ }
2098
+ function compileButtonColourStates(input) {
2099
+ if (input.variant.visualStates) return compileDeclaredVisualStates(input, input.variant.visualStates);
2100
+ const base = applyColourEffects({
2101
+ variantId: input.variant.id,
2102
+ state: "base",
2103
+ treatment: input.variant.background,
2104
+ effects: input.variant.effects?.base,
2105
+ palette: input.palette
2106
+ });
2107
+ if (!base.ok) return base;
2108
+ const hover = resolveButtonHoverTreatment({
2109
+ variant: input.variant,
2110
+ global: input.global,
2111
+ fallback: base.treatment,
2112
+ rest: restingFill({
2113
+ ...input,
2114
+ variantId: input.variant.id,
2115
+ state: "base"
2116
+ }, base.treatment),
2117
+ palette: input.palette,
2118
+ surface: input.surface,
2119
+ colourIndex: input.colourIndex
2120
+ });
2121
+ const colours = collectStateColours(mapVisualStates((state) => compileVisualState(input, state, state === "hover" ? hover.treatment : base.treatment, base.nonColourEffects)));
2122
+ return colours.ok ? {
2123
+ ...colours,
2124
+ contextualHoverRepair: hover.repair
2125
+ } : colours;
2126
+ }
2127
+ function compileDeclaredVisualStates(input, states) {
2128
+ const hover = resolveButtonHoverTreatment({
2129
+ ...input,
2130
+ variant: {
2131
+ ...input.variant,
2132
+ contextualHover: states.hover.contextualHover,
2133
+ border: buttonStateBorder(input.variant, "hover"),
2134
+ hoverBackgroundToken: void 0
2135
+ },
2136
+ global: {
2137
+ ...input.global,
2138
+ hoverColor: "none",
2139
+ hoverColorToken: void 0
2140
+ },
2141
+ fallback: states.hover.background,
2142
+ rest: restingFill({
2143
+ ...input,
2144
+ variantId: input.variant.id,
2145
+ state: "base"
2146
+ }, states.base.background)
2147
+ });
2148
+ const colours = collectStateColours(mapVisualStates((state) => compileDeclaredVisualState(input, states, state, state === "hover" ? hover.treatment : states[state].background)));
2149
+ return colours.ok ? {
2150
+ ...colours,
2151
+ focusIndicator: states.focus.indicator ? {
2152
+ kind: "surface-role",
2153
+ colorCss: input.surface?.foregroundCss ?? surfaceForegroundValue("text"),
2154
+ width: states.focus.indicator.width,
2155
+ offset: states.focus.indicator.offset,
2156
+ minimumSurfaceContrast: BUTTON_CONTRAST_POLICY.nonTextMinimumRatio
2157
+ } : colours.focusIndicator,
2158
+ contextualHoverRepair: hover.repair
2159
+ } : colours;
2160
+ }
2161
+ function compileDeclaredVisualState(input, states, state, treatment) {
2162
+ const appearance = states[state];
2163
+ const effects = state === "base" ? appearance.effects : [...states.base.effects, ...appearance.effects];
2164
+ const transition = applyColourEffects({
2165
+ variantId: input.variant.id,
2166
+ state,
2167
+ treatment,
2168
+ effects,
2169
+ palette: input.palette
2170
+ });
2171
+ if (!transition.ok) return transition;
2172
+ const resolved = resolveTreatment({
2173
+ variantId: input.variant.id,
2174
+ state,
2175
+ treatment: transition.treatment,
2176
+ border: buttonStateBorder(input.variant, state),
2177
+ palette: input.palette,
2178
+ surface: input.surface,
2179
+ colourIndex: input.colourIndex
2180
+ });
2181
+ return resolved.ok ? {
2182
+ ...resolved,
2183
+ nonColourEffects: state === "disabled" ? [] : state === "base" ? transition.nonColourEffects : transition.nonColourEffects.filter((effect) => appearance.effects.includes(effect))
2184
+ } : resolved;
2185
+ }
2186
+ function compileVisualState(input, state, treatment, baseEffects) {
2187
+ const transition = state === "hover" || state === "focus" || state === "active" ? applyColourEffects({
2188
+ variantId: input.variant.id,
2189
+ state,
2190
+ treatment,
2191
+ effects: input.variant.effects?.[state],
2192
+ palette: input.palette
2193
+ }) : {
2194
+ ok: true,
2195
+ treatment,
2196
+ nonColourEffects: state === "base" ? baseEffects : []
2197
+ };
2198
+ if (!transition.ok) return transition;
2199
+ const resolved = resolveTreatment({
2200
+ variantId: input.variant.id,
2201
+ state,
2202
+ treatment: transition.treatment,
2203
+ palette: input.palette,
2204
+ surface: input.surface,
2205
+ colourIndex: input.colourIndex,
2206
+ border: buttonStateBorder(input.variant, state)
2207
+ });
2208
+ return resolved.ok ? {
2209
+ ...resolved,
2210
+ nonColourEffects: transition.nonColourEffects
2211
+ } : resolved;
2212
+ }
2213
+ function collectStateColours(results) {
2214
+ if (!results.base.ok) return results.base;
2215
+ if (!results.hover.ok) return results.hover;
2216
+ if (!results.focus.ok) return results.focus;
2217
+ if (!results.active.ok) return results.active;
2218
+ if (!results.disabled.ok) return results.disabled;
2219
+ const states = {
2220
+ base: results.base.colour,
2221
+ hover: results.hover.colour,
2222
+ focus: results.focus.colour,
2223
+ active: results.active.colour,
2224
+ disabled: results.disabled.colour
2016
2225
  };
2017
- const solved = SURFACE_SECONDARY_TEXT_TINTS.reduce((kept, { token, alpha }) => {
2018
- const tintHex = palette[token];
2019
- if (!tintHex) return kept;
2020
- const grounds = [...kept.grounds, compositeHex(tintHex, alpha, groundHex)];
2021
- const ink = paletteMutedInk(grounds, preferred, roles);
2022
- return ink.kind === "unpaintable" ? {
2023
- ...kept,
2024
- uncovered: [...kept.uncovered, {
2025
- token,
2026
- alpha,
2027
- tintHex
2028
- }]
2029
- } : {
2030
- ...kept,
2031
- grounds,
2032
- hex: ink.hex
2033
- };
2034
- }, initial);
2035
2226
  return {
2036
- hex: solved.hex,
2037
- fadedTints: solved.uncovered.map(({ token, alpha, tintHex }) => ({
2038
- token,
2039
- hex: tintFadedUntilInkReads(tintHex, alpha, groundHex, solved.hex)
2040
- }))
2227
+ ok: true,
2228
+ states,
2229
+ focusIndicator: resolveFocusIndicator(states.focus),
2230
+ nonColourEffects: Object.fromEntries(Object.entries(results).flatMap(([state, result]) => result.ok && result.nonColourEffects.length > 0 ? [[state, [...result.nonColourEffects]]] : []))
2041
2231
  };
2042
2232
  }
2043
- /** The tint colour a ground publishes in place of a tint its muted ink can't read on, e.g. `surfaceTintMuted`. */
2044
- function groundTintToken(ground, tint) {
2045
- return `${ground}Tint${tint.charAt(0).toUpperCase()}${tint.slice(1)}`;
2233
+ function resolveTreatment(input) {
2234
+ const treatment = input.treatment;
2235
+ switch (treatment.type) {
2236
+ case "surface":
2237
+ if (input.surface) {
2238
+ const surface = input.surface;
2239
+ const foreground = buttonSurfaceGrounds(surface).map((backgroundHex) => validateButtonTextContrast({
2240
+ ...input,
2241
+ background: "surface",
2242
+ backgroundHex,
2243
+ foreground: "surface-foreground",
2244
+ foregroundHex: surface.foregroundHex
2245
+ })).find((result) => !result.ok) ?? { ok: true };
2246
+ if (!foreground.ok) return foreground;
2247
+ }
2248
+ return {
2249
+ ok: true,
2250
+ colour: {
2251
+ kind: "surface",
2252
+ role: treatment.role,
2253
+ backgroundCss: "transparent",
2254
+ foregroundCss: input.surface?.foregroundCss ?? surfaceForegroundValue(treatment.role)
2255
+ }
2256
+ };
2257
+ case "solid": return resolveSolid(input, treatment.colorToken, treatment.foregroundToken);
2258
+ case "gradient": return resolveGradient(input, treatment);
2259
+ }
2046
2260
  }
2047
- /**
2048
- * The tint blended toward the ground in 1% steps, stopping at the first that
2049
- * the ink reads on when laid at `alpha`. The ground itself always reads, since
2050
- * the ink was solved on it.
2051
- */
2052
- function tintFadedUntilInkReads(tintHex, alpha, groundHex, inkHex) {
2053
- const tint = hexToRgb(tintHex);
2054
- const ground = hexToRgb(groundHex);
2055
- return Array.from({ length: 101 }, (_, index) => {
2056
- const amount = index / 100;
2057
- return rgbToHex(mix$1(tint.r, ground.r, amount), mix$1(tint.g, ground.g, amount), mix$1(tint.b, ground.b, amount));
2058
- }).find((hex) => contrastRatio(inkHex, compositeHex(hex, alpha, groundHex)) >= 4.5) ?? groundHex;
2261
+ function resolveFocusIndicator(colour) {
2262
+ switch (colour.kind) {
2263
+ case "solid":
2264
+ case "known-solid": return {
2265
+ kind: "two-tone",
2266
+ innerCss: colour.foregroundCss,
2267
+ outerCss: colour.backgroundCss,
2268
+ minimumPairContrast: BUTTON_CONTRAST_POLICY.textMinimumRatio
2269
+ };
2270
+ case "gradient": return {
2271
+ kind: "two-tone",
2272
+ innerCss: colour.foregroundCss,
2273
+ outerCss: tokenCss(colour.backgroundTokens[0]),
2274
+ minimumPairContrast: BUTTON_CONTRAST_POLICY.textMinimumRatio
2275
+ };
2276
+ case "surface": return {
2277
+ kind: "surface-role",
2278
+ colorCss: colour.foregroundCss,
2279
+ minimumSurfaceContrast: BUTTON_CONTRAST_POLICY.nonTextMinimumRatio
2280
+ };
2281
+ }
2059
2282
  }
2060
- /**
2061
- * The muted ink tokens a palette doesn't store itself, and the faded tint
2062
- * colours of each ground whose ink is solved here, as hex.
2063
- */
2064
- function groundMutedInkTokens(palette) {
2065
- return Object.fromEntries(Object.entries(MUTED_INK_TOKENS).flatMap(([ground, token]) => {
2066
- if (palette[token]) return [];
2067
- const ink = groundMutedInk(palette, ground);
2068
- if (!ink) return [];
2069
- const faded = ink.fadedTints.map(({ token: tint, hex }) => [groundTintToken(ground, tint), hex]);
2070
- return [[token, ink.hex], ...faded.filter(([name]) => !palette[name])];
2071
- }));
2283
+ function resolveSolid(input, backgroundToken, preferredForeground) {
2284
+ const backgroundHex = paletteHex(input, backgroundToken);
2285
+ if (!backgroundHex.ok) return backgroundHex;
2286
+ const ink = resolveSolidInk(input, backgroundToken, backgroundHex.hex, preferredForeground);
2287
+ const boundary = input.surface ? validateButtonFillSeparation({
2288
+ ...input,
2289
+ buttonPaint: backgroundHex.hex,
2290
+ surface: input.surface,
2291
+ labelInk: ink.foregroundHex
2292
+ }) : { ok: true };
2293
+ if (!boundary.ok) return boundary;
2294
+ return {
2295
+ ok: true,
2296
+ colour: ink.colour
2297
+ };
2072
2298
  }
2073
2299
  /**
2074
- * The neutral step stays when it reads on the ground. Otherwise (a dark palette
2075
- * on a mid-tone ground, or a tinted light one) it's the ground-to-text blend
2076
- * with a 4.5:1 floor, heading for the palette's own ink on that ground.
2300
+ * One solid fill's colours as any button paints them, for chrome that dresses
2301
+ * itself as a button outside the variant CSS (the header's inverted CTA): the
2302
+ * requested label when it reads, else the fill's on-colour, else black or white.
2077
2303
  */
2078
- function readableMutedText(step, base, roles) {
2079
- const ground = base.background || base.surface;
2080
- if (!ground || contrastRatio(step, ground) >= 4.5) return step;
2081
- return paletteMutedInkOnSolid(ground, null, roles);
2304
+ function resolveSolidButtonColour(input, backgroundToken, preferredForeground) {
2305
+ return resolveSolid(input, backgroundToken, preferredForeground);
2082
2306
  }
2083
- /**
2084
- * Derived decoration colours never become editable palette swatches. The mark
2085
- * blends toward literal black or white: it's a graphic endpoint for a 3:1
2086
- * search, not text, so it stays off the palette ink rule.
2087
- */
2088
- function deriveSurfaceDecorationColors(ground, text, accent) {
2089
- const ink = pickBlackOrWhiteTextColor(ground);
2307
+ /** A solid rest fill with the label ink resolveSolidInk gives it, so a contextual hover compares against the ink visitors see. */
2308
+ function restingFill(input, treatment) {
2309
+ if (treatment.type !== "solid") return { kind: "not-solid" };
2310
+ const hex = resolveConcreteColorHex(treatment.colorToken, input.palette);
2311
+ if (hex === null) return { kind: "not-solid" };
2312
+ const ink = resolveSolidInk(input, treatment.colorToken, hex, treatment.foregroundToken);
2090
2313
  return {
2091
- line: firstContrastBlend(ground, text, ground, 1.5),
2092
- mark: firstContrastBlend(accent, ink, ground, 3)
2314
+ kind: "solid",
2315
+ colorToken: treatment.colorToken,
2316
+ labelInk: ink.foregroundHex
2093
2317
  };
2094
2318
  }
2095
- function firstContrastBlend(from, to, ground, threshold) {
2096
- const start = hexToRgb(from);
2097
- const end = hexToRgb(to);
2098
- return Array.from({ length: 101 }, (_, index) => {
2099
- const amount = index / 100;
2100
- return rgbToHex(mix$1(start.r, end.r, amount), mix$1(start.g, end.g, amount), mix$1(start.b, end.b, amount));
2101
- }).find((hex) => contrastRatio(hex, ground) >= threshold) ?? to;
2319
+ /** Preserve checked on-colours (a requested label colour first); a solid state's last resort is the palette ink for its actual fill. */
2320
+ function resolveSolidInk(input, backgroundToken, backgroundHex, preferredForeground) {
2321
+ if (preferredForeground !== void 0) {
2322
+ const preferred = checkedSolidInk(input, backgroundToken, backgroundHex, preferredForeground);
2323
+ if (preferred) return preferred;
2324
+ }
2325
+ return checkedSolidInk(input, backgroundToken, backgroundHex, unsafeAsOpaqueButtonColourToken(solidForegroundToken(backgroundToken))) ?? paletteSolidInk(input, backgroundToken, backgroundHex);
2102
2326
  }
2103
- /** `markSource` names the colour surface marks are derived from when a style marks in its brand rather than its accent. */
2104
- function arrangementPaletteTokens(base, options) {
2105
- if (options.arrangement !== true || !base.text) return {};
2327
+ function checkedSolidInk(input, backgroundToken, backgroundHex, foregroundToken) {
2328
+ const candidate = resolveConcreteColorHex(foregroundToken, input.palette);
2329
+ if ((typeof candidate === "string" ? validateButtonTextContrast({
2330
+ ...input,
2331
+ background: backgroundToken,
2332
+ backgroundHex,
2333
+ foreground: foregroundToken,
2334
+ foregroundHex: candidate
2335
+ }) : null)?.ok === true && typeof candidate === "string") return {
2336
+ foregroundHex: candidate,
2337
+ colour: {
2338
+ kind: "solid",
2339
+ backgroundToken,
2340
+ foregroundToken,
2341
+ backgroundCss: tokenCss(backgroundToken),
2342
+ foregroundCss: tokenCss(foregroundToken)
2343
+ }
2344
+ };
2345
+ return null;
2346
+ }
2347
+ /** The palette's own background or text as the label where it reads (as a checked token), else literal black or white. */
2348
+ function paletteSolidInk(input, backgroundToken, backgroundHex) {
2349
+ const ink = paletteInkOnSolid(backgroundHex, paletteInkRoles(input.palette));
2350
+ const role = ink.kind === "role" ? checkedSolidInk(input, backgroundToken, backgroundHex, unsafeAsOpaqueButtonColourToken(ink.role)) : null;
2351
+ if (role) return role;
2352
+ const literal = pickBlackOrWhiteTextColor(backgroundHex);
2106
2353
  return {
2107
- onText: base.onText ?? paletteInkOnSolid(base.text, paletteInkRoles(base)).hex,
2108
- ...options.marksFrom === "primary" && base.primary ? { markSource: base.primary } : {}
2354
+ foregroundHex: literal,
2355
+ colour: {
2356
+ kind: "known-solid",
2357
+ backgroundCss: tokenCss(backgroundToken),
2358
+ foregroundCss: literal
2359
+ }
2360
+ };
2361
+ }
2362
+ function resolveGradient(input, treatment) {
2363
+ const foregroundHex = paletteHex(input, treatment.foregroundToken);
2364
+ if (!foregroundHex.ok) return foregroundHex;
2365
+ const stopHexes = [];
2366
+ for (const token of treatment.stops) {
2367
+ const stop = paletteHex(input, token);
2368
+ if (!stop.ok) return stop;
2369
+ stopHexes.push(stop.hex);
2370
+ }
2371
+ for (let segment = 0; segment < stopHexes.length - 1; segment += 1) {
2372
+ const start = stopHexes[segment];
2373
+ const end = stopHexes[segment + 1];
2374
+ const startToken = treatment.stops[segment];
2375
+ const endToken = treatment.stops[segment + 1];
2376
+ if (start === void 0 || end === void 0 || startToken === void 0 || endToken === void 0) continue;
2377
+ for (let sample = 0; sample <= BUTTON_CONTRAST_POLICY.gradientSamplesPerSegment; sample += 1) {
2378
+ const position = sample / BUTTON_CONTRAST_POLICY.gradientSamplesPerSegment;
2379
+ const sampleHex = interpolateHex(start, end, position);
2380
+ const contrast = validateButtonTextContrast({
2381
+ ...input,
2382
+ background: `${startToken}→${endToken}@${position.toFixed(2)}`,
2383
+ backgroundHex: sampleHex,
2384
+ foreground: treatment.foregroundToken,
2385
+ foregroundHex: foregroundHex.hex
2386
+ });
2387
+ if (!contrast.ok) return contrast;
2388
+ if (input.surface) {
2389
+ const boundary = validateButtonFillSeparation({
2390
+ ...input,
2391
+ buttonPaint: sampleHex,
2392
+ labelInk: foregroundHex.hex,
2393
+ surface: input.surface
2394
+ });
2395
+ if (!boundary.ok) return boundary;
2396
+ }
2397
+ }
2398
+ }
2399
+ const direction = GRADIENT_DIRECTION_MAP[treatment.direction] ?? "to right";
2400
+ return {
2401
+ ok: true,
2402
+ colour: {
2403
+ kind: "gradient",
2404
+ backgroundTokens: treatment.stops,
2405
+ foregroundToken: treatment.foregroundToken,
2406
+ backgroundCss: `linear-gradient(${direction}, ${treatment.stops.map(tokenCss).join(", ")})`,
2407
+ foregroundCss: tokenCss(treatment.foregroundToken)
2408
+ }
2409
+ };
2410
+ }
2411
+ function paletteHex(input, token) {
2412
+ const hex = resolveConcreteColorHex(token, input.palette);
2413
+ return typeof hex === "string" ? {
2414
+ ok: true,
2415
+ hex
2416
+ } : {
2417
+ ok: false,
2418
+ error: {
2419
+ tag: "unknown_palette_token",
2420
+ variantId: input.variantId,
2421
+ state: input.state,
2422
+ token
2423
+ }
2109
2424
  };
2110
2425
  }
2426
+ function tokenCss(token) {
2427
+ return `rgb(var(--tb-${token}))`;
2428
+ }
2429
+ function interpolateHex(startHex, endHex, position) {
2430
+ const start = hexToRgb(startHex);
2431
+ const end = hexToRgb(endHex);
2432
+ const channel = (from, to) => Math.round(from + (to - from) * position).toString(16).padStart(2, "0");
2433
+ return `#${channel(start.r, end.r)}${channel(start.g, end.g)}${channel(start.b, end.b)}`;
2434
+ }
2111
2435
  //#endregion
2112
- export { onColorTokenName as A, preparePaletteColourIndex as B, paletteInk as C, paletteMutedInkOnSolid as D, paletteInkToken as E, requirePaletteColorsFromEntries as F, oklabToSrgb as G, featuresFromHex as H, ORDINARY_TEXT_MIN_CONTRAST_RATIO as I, rgbToHex as J, oklchToHexGamut as K, contrastRatio as L, resolveOpaqueSurfaceHex as M, paletteValueKey as N, colourFamily as O, paletteValueKeySchema as P, hexLuminance as R, neutralInk as S, paletteInkRoles as T, hexToRgb as U, solidPaint as V, oklabToOklch as W, srgbToOklab as Y, ELEVATION_OFFSET as _, compositeHex as a, pickBlackOrWhiteTextColor as b, scrimTone as c, resolveSolidButtonColour as d, BUTTON_CONTRAST_POLICY as f, DEFAULT_BUTTON_SIZES as g, BORDER_WIDTH_MAP as h, groundMutedInkTokens as i, resolveConcreteColorHex as j, isOnColorBackgroundCandidateToken as k, buttonStateBorder as l, BORDER_RADIUS_MAP as m, deriveSurfaceDecorationColors as n, gradientScrimSamples as o, formatButtonColourContractError as p, oklchToOklab as q, expandPalette as r, minimumScrimOpacity as s, SURFACE_SECONDARY_TEXT_TINT_ALPHA as t, compileButtonColourStates as u, FONT_SIZE_MAP as v, paletteInkOnSolid as w, inkFrom as x, generateShadowValue as y, luminanceInterval as z };
2436
+ export { requirePaletteColorsFromEntries as $, deriveSurfaceDecorationColors as A, minimumScrimOpacity as B, PUBLIC_FILE_FIELD_KINDS as C, parseCanonicalMediaIdentifier as D, mediaIdentifierSchema as E, isOnColorBackgroundCandidateToken as F, neutralInk as G, resolveConcreteColorHex as H, onColorTokenName as I, paletteInkRoles as J, paletteInk as K, pickBlackOrWhiteTextColor as L, deriveSurfaceMutedColor as M, expandPalette as N, parseMediaIdentifier as O, groundMutedInkTokens as P, paletteValueKeySchema as Q, compositeHex as R, resolveManagedMediaReference as S, mediaTypeDiscriminants as T, resolveOpaqueSurfaceHex as U, scrimTone as V, inkFrom as W, colourFamily as X, paletteInkToken as Y, paletteValueKey as Z, runtimeMediaSchema as _, formatButtonColourContractError as a, solidPaint as at, renderableMediaAssetSchema as b, DEFAULT_BUTTON_SIZES as c, hexToRgb as ct, generateShadowValue as d, oklabToSrgb as dt, ORDINARY_TEXT_MIN_CONTRAST_RATIO as et, assetMediaSchema as f, oklchToHexGamut as ft, persistableMediaSchema as g, mediaSchema as h, srgbToOklab as ht, BUTTON_CONTRAST_POLICY as i, preparePaletteColourIndex as it, deriveSurfaceLineColor as j, SURFACE_SECONDARY_TEXT_TINT_ALPHA as k, ELEVATION_OFFSET as l, linearToSrgb as lt, imageMediaSchema as m, rgbToHex as mt, compileButtonColourStates as n, hexLuminance as nt, BORDER_RADIUS_MAP as o, worstContrast as ot, externalMediaSchema as p, oklchToOklab as pt, paletteInkOnSolid as q, resolveSolidButtonColour as r, luminanceInterval as rt, BORDER_WIDTH_MAP as s, featuresFromHex as st, buttonStateBorder as t, contrastRatio as tt, FONT_SIZE_MAP as u, oklabToOklch as ut, videoMediaSchema as v, isDisplayMediaKind as w, indexRenderableMediaAssets as x, buildRenderableMediaAssetIndex as y, gradientScrimSamples as z };