@riverbankcms/sdk 0.165.0 → 0.167.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 (246) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +5 -0
  3. package/dist/_dts/{BlocksIslandsHydrator-CdsSMQEv.d.ts → BlocksIslandsHydrator-Dgb-ptph.d.ts} +1 -1
  4. package/dist/_dts/{Page-D6gp2Ipb.d.ts → Page-Bs3WxFgr.d.ts} +20 -258
  5. package/dist/_dts/{SdkPreviewMode-DNXAvnet.d.ts → SdkPreviewMode-DtUCsaHY.d.ts} +26 -3
  6. package/dist/_dts/{client-BkkExozE.d.ts → client-CwsI23pj.d.ts} +13 -1
  7. package/dist/_dts/{content-types-CXNAD7ef.d.ts → content-types-CAeP_-cV.d.ts} +3 -3
  8. package/dist/_dts/{contracts-XRXhbLWP.d.ts → contracts-BXHCiF-b.d.ts} +8 -5
  9. package/dist/_dts/{footerPageOutline-BP2bJYdY.d.ts → footerPageOutline-Bb2gbppW.d.ts} +6 -6
  10. package/dist/_dts/{generatePageMetadata-DcMtbztV.d.ts → generatePageMetadata-DaBBDx7M.d.ts} +2 -2
  11. package/dist/_dts/{index-DKNEgSOS.d.ts → index-5_jf52sZ.d.ts} +2 -2
  12. package/dist/_dts/{index-CQfJhOEA.d.ts → index-C20yUyob.d.ts} +1 -1
  13. package/dist/_dts/{index-CRRiddNp.d.ts → index-CS6b1B-c.d.ts} +4 -4
  14. package/dist/_dts/{index-B4ozSzFP.d.ts → index-ChpjHK0U.d.ts} +9737 -8316
  15. package/dist/_dts/{index-BdkHhyf8.d.ts → index-D7EbliE3.d.ts} +1 -1
  16. package/dist/_dts/{index-RXkE3a7M.d.ts → index-DeHDwMfu.d.ts} +4 -3
  17. package/dist/_dts/{index-DAPTSmBM.d.ts → index-RugyUnqR.d.ts} +2499 -2218
  18. package/dist/_dts/{index-C_3kdrUb.d.ts → index-bDln38Hm.d.ts} +2 -2
  19. package/dist/_dts/{loadContent-B9vJMq3s.d.ts → loadContent-CTqcL7CS.d.ts} +9 -6
  20. package/dist/_dts/resolveBlockData-C3s9WMPs.d.ts +136 -0
  21. package/dist/_dts/{resolvePageContent-DIQyYUi-.d.ts → resolvePageContent-JPwgRxwh.d.ts} +3 -2
  22. package/dist/_dts/sdk/src/bookings/index.d.ts +2 -2
  23. package/dist/_dts/sdk/src/client/types.d.ts +2 -2
  24. package/dist/_dts/sdk/src/client.d.ts +9 -6
  25. package/dist/_dts/sdk/src/config/index.d.ts +6 -6
  26. package/dist/_dts/sdk/src/config/template-validation.d.ts +1 -1
  27. package/dist/_dts/sdk/src/config/validation.d.ts +1 -1
  28. package/dist/_dts/sdk/src/data/dataLoaderContext.d.ts +20 -0
  29. package/dist/_dts/sdk/src/data/resolveBlockData.d.ts +2 -0
  30. package/dist/_dts/sdk/src/data/types.d.ts +54 -0
  31. package/dist/_dts/sdk/src/index.d.ts +8 -8
  32. package/dist/_dts/sdk/src/manifest/index.d.ts +3 -3
  33. package/dist/_dts/sdk/src/metadata/index.d.ts +6 -1
  34. package/dist/_dts/sdk/src/navigation/index.d.ts +2 -2
  35. package/dist/_dts/sdk/src/next/index.d.ts +9 -8
  36. package/dist/_dts/sdk/src/next/middleware.d.ts +2 -2
  37. package/dist/_dts/sdk/src/page-converter/index.d.ts +36 -48
  38. package/dist/_dts/sdk/src/portal/client.d.ts +1 -1
  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 +2 -0
  45. package/dist/_dts/sdk/src/rendering/helpers/loadPage.d.ts +3 -0
  46. package/dist/_dts/sdk/src/rendering/helpers/pageRuntimeSupport.d.ts +260 -0
  47. package/dist/_dts/sdk/src/rendering/index.d.ts +8 -7
  48. package/dist/_dts/sdk/src/rendering/islands/client.d.ts +1 -1
  49. package/dist/_dts/sdk/src/rendering/server.d.ts +3 -3
  50. package/dist/_dts/{themeAdmission-D_qtGYAT.d.ts → sdk/src/rendering/themeAdmission.d.ts} +3 -1
  51. package/dist/_dts/sdk/src/routing/index.d.ts +5 -5
  52. package/dist/_dts/sdk/src/server.d.ts +7 -5
  53. package/dist/_dts/sdk/src/spam-protection/index.d.ts +2 -2
  54. package/dist/_dts/sdk/src/theme/index.d.ts +1 -1
  55. package/dist/_dts/{types-BDF73NzM.d.ts → types-BlaCuPLr.d.ts} +2 -2
  56. package/dist/_dts/{types-Cl0nP6al.d.ts → types-CwtTcaQP.d.ts} +3 -3
  57. package/dist/_dts/{types-mstFvhK4.d.ts → types-D-WElMCy.d.ts} +8 -7
  58. package/dist/_dts/{validation-DVWqSvjK.d.ts → validation-Y5wD9fGK.d.ts} +4 -4
  59. package/dist/client/{BlocksIslandsHydrator-CzKpH9Pm.mjs → BlocksIslandsHydrator-DFqkx158.mjs} +31 -24
  60. package/dist/client/{BookingMailingListNote-rUqsBN7L.mjs → BookingMailingListNote-CCVXX1LN.mjs} +2 -2
  61. package/dist/client/{CalendarNavigationChevron-YGzw2IPB.mjs → CalendarNavigationChevron-DQwJ7BPx.mjs} +167 -18
  62. package/dist/client/{CheckboxChoice-DlTC4J2a.mjs → CheckboxChoice-CZ-anOqV.mjs} +1 -1
  63. package/dist/client/{DemoBookingPortalAccess-D2LyS_Bi.mjs → DemoBookingPortalAccess-DdkY86qI.mjs} +6 -6
  64. package/dist/client/{DemoPortalSignInLink-BaFg2Uit.mjs → DemoPortalSignInLink-B9YrzZt2.mjs} +1 -1
  65. package/dist/client/{EventCalendar.client-tRrhPscX.mjs → EventCalendar.client-DAeQPV76.mjs} +11 -30
  66. package/dist/client/{EventCombined.client-6cfAVtnZ.mjs → EventCombined.client-Bus9R0bj.mjs} +137 -61
  67. package/dist/client/{EventEmbeddedCheckoutStep-CDNUpI0S.mjs → EventEmbeddedCheckoutStep-D_14yqAU.mjs} +27 -2
  68. package/dist/client/{EventItem-dILw2PN_.mjs → EventItem-DPBLjGwj.mjs} +75 -13
  69. package/dist/client/{EventListWeekNavigation-ClgLtjNY.mjs → EventListWeekNavigation-D6cwU82_.mjs} +1 -1
  70. package/dist/client/{EventListing.client-BNueAHmU.mjs → EventListing.client-Bogi_SnJ.mjs} +3 -3
  71. package/dist/client/{EventListing.view-DtVbKVkt.mjs → EventListing.view-CEumpN7i.mjs} +35 -51
  72. package/dist/client/{EventRegistrationPayment-CzkG0NSJ.mjs → EventRegistrationPayment-CIQw6vNy.mjs} +113 -11
  73. package/dist/client/{LocationMapActions-zWQsJhE5.mjs → LocationMapActions-BVO-qx4q.mjs} +2 -2
  74. package/dist/client/{MapDrawingSvg-D1AO_o4h.mjs → MapDrawingSvg-CcGaFawl.mjs} +22 -2
  75. package/dist/client/{Page-DUr2YhFR.mjs → Page-D4_H_u9V.mjs} +23892 -32266
  76. package/dist/client/{ProtectedSubmitButton-2fJqT_NR.mjs → ProtectedSubmitButton-8DuDw2ag.mjs} +1 -1
  77. package/dist/client/{StepIndicator-udNHcpOT.mjs → StepIndicator-Dptantmg.mjs} +3 -3
  78. package/dist/client/{TabBarFragment-C_kt-PXh.mjs → TabBarFragment-BxEGsKUx.mjs} +19 -19
  79. package/dist/client/{ThemedButton-Cfbo1bfh.mjs → ThemedButton-8jUc02mZ.mjs} +64 -2
  80. package/dist/client/{accordion-3CYNWzTS.mjs → accordion--EUHmEGa.mjs} +1 -1
  81. package/dist/client/{booking-form.client-BSbWgLyx.mjs → booking-form.client-BCXwOnhc.mjs} +19 -14
  82. package/dist/client/{bookingForm-2MoFBWSt.mjs → bookingForm-sHHcdism.mjs} +4 -4
  83. package/dist/client/bookings.mjs +6 -6
  84. package/dist/client/{carousel-Cu5mcpO-.mjs → carousel-Cp9xPBFZ.mjs} +2 -2
  85. package/dist/client/{carousel.client-CQLV8_Al.mjs → carousel.client-BO7sCEpH.mjs} +1 -1
  86. package/dist/client/{cart-CDc6x9cR.mjs → cart-CCZZC-Lq.mjs} +3 -3
  87. package/dist/client/{cart.client-BWS2r5Ef.mjs → cart.client-B7JfA19I.mjs} +1 -1
  88. package/dist/client/{checkout-CkxPqSwD.mjs → checkout-CipmYL4A.mjs} +3 -3
  89. package/dist/client/{checkout.client-DJfomKQc.mjs → checkout.client-DraalWdH.mjs} +1 -1
  90. package/dist/client/client.mjs +9550 -17
  91. package/dist/client/{context-CBV21-9L.mjs → context-Cv3QHjAF.mjs} +11 -6
  92. package/dist/client/{cta-Bw-al3cs.mjs → cta-P2vJVTEn.mjs} +45 -28
  93. package/dist/client/{dateFormatting-CFIUJ4Uf.mjs → dateFormatting-D8D47VT4.mjs} +1 -1
  94. package/dist/client/{demoPortalMagicLink-D0veHJyi.mjs → demoPortalMagicLink-CXWZoV-d.mjs} +1 -1
  95. package/dist/client/{enhanceHeaderSection-CEqqq92r.mjs → enhanceHeaderSection-BkAro1DJ.mjs} +4 -4
  96. package/dist/client/{event-details.client-Bk2kQ7ax.mjs → event-details.client-dLmyuPap.mjs} +2 -2
  97. package/dist/client/{event-registration.client-QMqtIywj.mjs → event-registration.client-BEhC2_-Y.mjs} +34 -20
  98. package/dist/client/{eventCalendar-BTDTMosr.mjs → eventCalendar-FBMS2Cpb.mjs} +4 -4
  99. package/dist/client/{eventCombined-BC7a709c.mjs → eventCombined-BrBhUvGe.mjs} +4 -4
  100. package/dist/client/{eventDetails-DL08GpUc.mjs → eventDetails-C7WUrbZ2.mjs} +2 -2
  101. package/dist/client/{eventListing-BfzuEQp_.mjs → eventListing-Bih-BgQM.mjs} +4 -4
  102. package/dist/client/{eventRegistration-Lfyzh1Ab.mjs → eventRegistration-DfTlqGbl.mjs} +4 -4
  103. package/dist/client/{form-L-xZOBUS.mjs → form-Bw1uuiUs.mjs} +3 -3
  104. package/dist/client/{form.client-BtpK3TZW.mjs → form.client-pZ-9gN33.mjs} +5 -5
  105. package/dist/client/{form.parts-Djos5Un4.mjs → form.parts-PXlu6XQO.mjs} +3 -3
  106. package/dist/client/{formatDate-DGmrm7YB.mjs → formatDate-DI3DP48e.mjs} +1 -1
  107. package/dist/client/gifting/client.mjs +3 -4
  108. package/dist/client/{headerSection-f16OGkz-.mjs → headerSection-BpJYUMd6.mjs} +2 -2
  109. package/dist/client/{mediaAssets-DHAmrVIi.mjs → mediaAssets-DpPauppt.mjs} +1 -1
  110. package/dist/client/{mediaContext-CwT6ZOm7.mjs → mediaContext-BLo4NtjP.mjs} +25 -19
  111. package/dist/client/{newsletter-form.client-DpHNZc7k.mjs → newsletter-form.client-CSoP0cGR.mjs} +6 -6
  112. package/dist/client/{newsletter-form.parts-CLGH20PL.mjs → newsletter-form.parts-DDbX_Sj0.mjs} +2 -2
  113. package/dist/client/{newsletterForm-BEU0Ocu9.mjs → newsletterForm-vCxYRar_.mjs} +3 -3
  114. package/dist/client/{noop-CQU7tiMg.mjs → noop-ByVtIWf4.mjs} +420 -170
  115. package/dist/client/portal/client.mjs +13 -14
  116. package/dist/client/{product-detail.client-Be-om1BT.mjs → product-detail.client-7Pi6avM-.mjs} +1 -1
  117. package/dist/client/{product-list.client-DR7hD5Vs.mjs → product-list.client-DEad-Pma.mjs} +1 -1
  118. package/dist/client/{productDetail-BD42UOmG.mjs → productDetail-G1SMXG13.mjs} +3 -3
  119. package/dist/client/{productList-CSk8sXCl.mjs → productList-B21TGdpT.mjs} +3 -3
  120. package/dist/client/{propsDecoder-C_Y6VYnF.mjs → propsDecoder-B3vIBkex.mjs} +4 -5
  121. package/dist/client/{registry.server-CIKtTsCl.mjs → registry.server-B8aQhJpO.mjs} +399 -473
  122. package/dist/client/rendering/client.mjs +29 -28
  123. package/dist/client/rendering/islands.mjs +1 -1
  124. package/dist/client/rendering.mjs +70 -8
  125. package/dist/client/{richText-coerce-spWtx86G.mjs → richText-coerce-DHkBtO0G.mjs} +1 -1
  126. package/dist/client/{routeIslandApiConfig-CROHPlYS.mjs → routeIslandApiConfig-DbHX4JOS.mjs} +1 -1
  127. package/dist/client/{shop-commerce-CDUohm_2.mjs → shop-commerce-B2UmrQg_.mjs} +12 -12
  128. package/dist/client/{shop-commerce-store-B9nw4lRP.mjs → shop-commerce-store-B7n-Z7nY.mjs} +1 -1
  129. package/dist/client/{shop-DscvMz86.mjs → shop-mqyoOvOK.mjs} +3 -3
  130. package/dist/client/{shop.client-M3kNsVPi.mjs → shop.client-BH-BBnA9.mjs} +13 -13
  131. package/dist/client/{shop.interactive-BGmkdIAZ.mjs → shop.interactive-mdM3UMWG.mjs} +74 -36
  132. package/dist/client/{shopShared-BdWp6LHa.mjs → shopShared-CXF5wxdg.mjs} +2 -2
  133. package/dist/client/site-styles-CMCUxsIM.mjs +3 -0
  134. package/dist/{preview-next/client/ThemedButton-Dc6aJ34Z.mjs → client/site-styles-D56hT2u1.mjs} +26000 -16565
  135. package/dist/client/spam-protection.mjs +1 -1
  136. package/dist/client/src-DjnxOjXG.mjs +217 -0
  137. package/dist/client/surfaceTransportMarker-BXepAVF6.mjs +152 -0
  138. package/dist/client/{timetableModel-Dynh5-j4.mjs → timetableModel-CrC80EOG.mjs} +13 -140
  139. package/dist/client/types-sF-IrGQr.mjs +633 -0
  140. package/dist/client/{useAvailableSlots-Cw9paRPY.mjs → useAvailableSlots-C4LOaI_Z.mjs} +8 -5
  141. package/dist/client/{useBookingNowIso-C9SF2rC6.mjs → useBookingNowIso-BDmWkYUW.mjs} +1 -1
  142. package/dist/client/{useDiscountApply-B-QJfBg0.mjs → useDiscountApply-6Q0nToVA.mjs} +3 -3
  143. package/dist/client/{useDiscountCodeUi-Uvum8q9d.mjs → useDiscountCodeUi-CM-DTX5X.mjs} +1 -1
  144. package/dist/client/{useEventPagination-BfM3xk6j.mjs → useEventPagination-Bcs89BR5.mjs} +9 -9
  145. package/dist/client/{view-DlkCDfuN.mjs → view-BN-fxyfq.mjs} +287 -232
  146. package/dist/client/{view-DXOuduIr.mjs → view-Dh2tGoS0.mjs} +4 -4
  147. package/dist/client/{wizardSteps-DManVJpc.mjs → wizardSteps-DtkhwKXK.mjs} +468 -149
  148. package/dist/preview-next/before-render.mjs +3 -140
  149. package/dist/preview-next/client/ArrangementLookControls-D4VjPs-r.mjs +31197 -0
  150. package/dist/preview-next/client/{EventEmbeddedCheckoutStep-Die6Y25O.mjs → EventEmbeddedCheckoutStep-C_h1cMYm.mjs} +33 -4
  151. package/dist/preview-next/client/{LocationPickerEnvironment-Bp4BHLCL.mjs → LocationPickerEnvironment-D56RD3e_.mjs} +1 -1
  152. package/dist/preview-next/client/{MapLibreEditMap-Cb0JhM9p.mjs → MapLibreEditMap-DFnyCckr.mjs} +2 -2
  153. package/dist/preview-next/client/PreviewEditorSidebar-Ckr2zk_L.mjs +37247 -0
  154. package/dist/preview-next/client/{PreviewEditorUI-CxwlLBGw.mjs → PreviewEditorUI-KOZgw_gS.mjs} +45 -17
  155. package/dist/preview-next/client/PreviewShell-CyO2V4kB.mjs +4757 -0
  156. package/dist/preview-next/client/SdkPreviewModeRuntime-DW3uKvNF.mjs +4258 -0
  157. package/dist/preview-next/client/SiteChromeCustomizeButton-CU9VD-7O.mjs +72202 -0
  158. package/dist/preview-next/client/ThemedButton-C0dgGJ5k.mjs +2006 -0
  159. package/dist/preview-next/client/{lucide-react-CqxuVAyz.mjs → lucide-react-CPBCf6QT.mjs} +15 -2
  160. package/dist/preview-next/client/previewAssistantSlot-DBi-WybM.mjs +112193 -0
  161. package/dist/preview-next/client/{previewChromeSurface-yuwnDP3B.mjs → previewChromeSurface-BhkUJst9.mjs} +90 -28
  162. package/dist/preview-next/client/runtime.mjs +3 -3
  163. package/dist/preview-next/client/sdk-runtime-BjCb6lOn.mjs +5 -0
  164. package/dist/preview-next/client/{editorStatusDecision-DR4BBKhy.mjs → useAutosaveStatus-CKxTaC3j.mjs} +40 -3
  165. package/dist/preview-next/client/useBlockCustomizeControls-B7MLTjBX.mjs +2633 -0
  166. package/dist/preview-next/client/useOpenBlockForSetup-BTUc0g9X.mjs +28 -0
  167. package/dist/preview-next/keepAlive.mjs +25 -2
  168. package/dist/preview-next/middleware.mjs +1 -1
  169. package/dist/preview-next/{route-contract-BBAJjFIz.mjs → route-contract-Bv3nkdpV.mjs} +215 -118
  170. package/dist/server/{Block.shared-ClFI3qpX.mjs → Block.shared-4fMqzltx.mjs} +7 -4
  171. package/dist/server/{src-DsYPhTbs.mjs → ThemeScopeCore-C72VC_lR.mjs} +894 -2556
  172. package/dist/server/accessibleSurfaces-B_Y_dA20.mjs +2305 -0
  173. package/dist/server/{bindings-Bi8EoRZD.mjs → bindings-ConMYJ2U.mjs} +2 -3
  174. package/dist/server/{publicProducts-Bz8loTRn.mjs → client-Cot-H5fQ.mjs} +2558 -343
  175. package/dist/server/config-validation.mjs +1 -1
  176. package/dist/server/config.mjs +33 -2
  177. package/dist/server/data/dataLoaderContext.mjs +2 -0
  178. package/dist/server/data/resolveBlockData.mjs +2 -0
  179. package/dist/server/data/types.mjs +1 -0
  180. package/dist/server/dataLoaderContext-B3fXA54R.mjs +47 -0
  181. package/dist/server/identity-Bn9OQiT1.mjs +6 -0
  182. package/dist/server/index.mjs +3 -3
  183. package/dist/server/{loadContent-dEEhQxL7.mjs → loadContent-BkaWYEwt.mjs} +6 -5
  184. package/dist/server/{loadPage-DBFBad8A.mjs → loadPage-kviUdH8c.mjs} +4 -2
  185. package/dist/server/manifest.mjs +1 -1
  186. package/dist/server/media-DnlczCMA.mjs +231 -0
  187. package/dist/server/metadata.mjs +5 -1
  188. package/dist/server/mode-Cv_TG9gP.mjs +63 -0
  189. package/dist/server/next/revalidate.mjs +9 -4
  190. package/dist/server/next.mjs +11 -11
  191. package/dist/server/opaqueSurface-BTnS09GS.mjs +54 -0
  192. package/dist/server/{overrideResolution-BIJbiXYc.mjs → overrideResolution-itXZCXs7.mjs} +2 -1
  193. package/dist/server/overrides-CD4d-1w7.mjs +177 -0
  194. package/dist/server/page-converter.mjs +243 -91
  195. package/dist/server/pageRenderPlan-CDyn7iLy.mjs +4162 -0
  196. package/dist/server/{themeAdmission-CSknYpxk.mjs → pageRuntimeSupport-DZ6cLxrM.mjs} +13 -28
  197. package/dist/server/{overrides-DhF87Vsd.mjs → pageShared-Q_Vij87H.mjs} +3808 -1928
  198. package/dist/server/parseThemeForPersistence-CDrF51tJ.mjs +52 -0
  199. package/dist/server/{prebuild-DaemmWQL.mjs → prebuild-DOG4MkOy.mjs} +1 -1
  200. package/dist/server/prebuild.mjs +1 -1
  201. package/dist/server/prefetchBlockData-DlprLLsc.mjs +756 -0
  202. package/dist/server/{registry-Cdvz1OtL.mjs → registry-BPFcpn6k.mjs} +21838 -709
  203. package/dist/server/rendering/components/pageShared.mjs +2 -0
  204. package/dist/server/rendering/helpers/loadPage.mjs +2 -0
  205. package/dist/server/rendering/helpers/pageRuntimeSupport.mjs +2 -0
  206. package/dist/server/rendering/server.mjs +5 -4
  207. package/dist/server/rendering/themeAdmission.mjs +2 -0
  208. package/dist/server/rendering.mjs +11 -10
  209. package/dist/server/repeaterFields-MIz7r1ez.mjs +9 -0
  210. package/dist/server/{resolveBlockData-CLpAJWWf.mjs → resolveBlockData-BHvfGD4y.mjs} +6 -48
  211. package/dist/server/resolveButtonColourStates-OXFRGn5M.mjs +2682 -0
  212. package/dist/server/responseMedia-D8J3VAFs.mjs +115 -0
  213. package/dist/server/{richTextSchema-YYc85FX4.mjs → richTextSchema-Euhuj-7V.mjs} +26 -1
  214. package/dist/server/routing.mjs +1 -1
  215. package/dist/server/schema-DEizlyi4.mjs +2524 -0
  216. package/dist/server/server.mjs +3 -3
  217. package/dist/server/theme-bridge.mjs +1031 -1
  218. package/dist/server/theme.mjs +2 -1
  219. package/dist/server/themeAdmission-DGSAlFUK.mjs +18 -0
  220. package/dist/server/{three-pass-converter-Chnb1XD-.mjs → three-pass-converter-_j2UE2tR.mjs} +1 -1
  221. package/dist/server/validation-CDd6m8Ry.mjs +140 -0
  222. package/dist/server/{validation-DYxhLzqQ.mjs → validation-bl6WcAi_.mjs} +419 -3
  223. package/dist/server/{version-Beu4q-Gv.mjs → version-BLXZ31S-.mjs} +1 -1
  224. package/dist/styles/index.css +710 -29
  225. package/package.json +39 -1
  226. package/dist/client/events-BmqPeeQm.mjs +0 -20
  227. package/dist/client/purchase-BV5xfaZH.mjs +0 -894
  228. package/dist/client/schema-BdSglH2X.mjs +0 -16084
  229. package/dist/client/site-styles-CWHmlVT5.mjs +0 -14503
  230. package/dist/client/src-VIsPY-kw.mjs +0 -62
  231. package/dist/preview-next/client/PreviewEditorSidebar-DEP3xD9K.mjs +0 -5810
  232. package/dist/preview-next/client/SdkPreviewModeRuntime-Cpe-XP8e.mjs +0 -3
  233. package/dist/preview-next/client/SdkPreviewModeRuntime-QDkMPASV.mjs +0 -8059
  234. package/dist/preview-next/client/SiteChromeCustomizeButton-1JaoGOKX.mjs +0 -9367
  235. package/dist/preview-next/client/previewSidebarNavigation-AXUj9-qQ.mjs +0 -224683
  236. package/dist/preview-next/client/result-BjJUoxUF.mjs +0 -16
  237. package/dist/preview-next/client/sdk-runtime-O-eA9-rV.mjs +0 -4
  238. package/dist/preview-next/refresh-contract-uQ6BXgLJ.mjs +0 -25
  239. package/dist/server/bindings-Dgt_0goJ.mjs +0 -17
  240. package/dist/server/client-DfMDbZ41.mjs +0 -2330
  241. package/dist/server/effectiveNavLinkStyle-BHIYPVG1.mjs +0 -13713
  242. package/dist/server/loadPage-CnVB-aeL.mjs +0 -2
  243. package/dist/server/prefetchBlockData-FwcsT5H2.mjs +0 -4359
  244. package/dist/server/schema-uSA_x1Zh.mjs +0 -16311
  245. package/dist/server/site-styles-CntHn2KI.mjs +0 -793
  246. package/dist/server/siteChromeOverlayClearance-DqP40Ka0.mjs +0 -802
@@ -0,0 +1,2305 @@
1
+ import { $ as maxContrastBlackOrWhite, A as opaqueButtonColourTokenSchema, B as pickBlackOrWhiteTextColor, F as deriveSurfaceMutedColor, Ft as parseColorTokenParts, H as normalizePaletteHex, M as colourFamily, Mt as parseThemeColorToken, N as oklabDistance, P as deriveSurfaceDecorationColors, Q as contrastRatio, R as onColorTokenName, T as buttonSystemSchema, V as hexColorSchema, X as ORDINARY_TEXT_MIN_CONTRAST_RATIO, Z as assertContrastRatio, _ as generateShadowValue, at as hexToRgb, b as VARIANT_ROLES, f as BORDER_RADIUS_MAP, g as FONT_SIZE_MAP, h as ELEVATION_OFFSET, ht as completeSurfaceForegrounds, i as BUTTON_VISUAL_STATES, it as featuresFromHex, l as resolveThemeColorReferenceValue, lt as oklchToOklab, n as compileButtonColourStates, nt as solidPaint, p as BORDER_WIDTH_MAP, rt as worstContrast, s as parseThemeColorReference, st as oklabToSrgb, t as buttonStateBorder, tt as relativeLuminance, ut as rgbToHex, y as STANDARD_BUTTON_SURFACE_POLICY } from "./resolveButtonColourStates-OXFRGn5M.mjs";
2
+ import { z } from "zod";
3
+ //#region ../theme-core/src/palette/utils/opaqueSurfaceColor.ts
4
+ /** Resolve an opaque colour, compositing alpha against an explicit underlay. */
5
+ function resolveOpaqueSurfaceHex(reference, palette, underlayReference) {
6
+ const opaque = resolveConcreteColorHex(reference, palette);
7
+ if (opaque) return opaque;
8
+ if (!underlayReference) return null;
9
+ const underlayHex = resolveConcreteColorHex(underlayReference, palette);
10
+ if (!underlayHex) return null;
11
+ const parts = parseColorTokenParts(reference);
12
+ if (parts.kind === "token" && parts.opacityPercent !== null) {
13
+ const foregroundHex = normalizePaletteHex(palette[parts.token] ?? "");
14
+ return foregroundHex ? compositeHex$1(foregroundHex, underlayHex, parts.opacityPercent / 100) : null;
15
+ }
16
+ const rgba = parseRgba(parts.kind === "raw" ? parts.value : reference);
17
+ return rgba ? compositeHex$1(rgbToHex(rgba.r, rgba.g, rgba.b), underlayHex, rgba.alpha) : null;
18
+ }
19
+ /** Resolve a colour reference only when it is already fully opaque. */
20
+ function resolveConcreteColorHex(reference, palette) {
21
+ const literalHex = normalizePaletteHex(reference);
22
+ if (literalHex) return literalHex;
23
+ const parts = parseColorTokenParts(reference);
24
+ if (parts.kind === "token") {
25
+ if (parts.opacityPercent !== null) return null;
26
+ return normalizePaletteHex(palette[parts.token] ?? "");
27
+ }
28
+ const literal = parts.kind === "raw" ? parts.value : reference;
29
+ if (literal.toLowerCase() === "black") return "#000000";
30
+ if (literal.toLowerCase() === "white") return "#ffffff";
31
+ return normalizePaletteHex(literal);
32
+ }
33
+ function compositeHex$1(foregroundHex, underlayHex, alpha) {
34
+ const foreground = hexToRgb(foregroundHex);
35
+ const underlay = hexToRgb(underlayHex);
36
+ const channel = (foregroundValue, underlayValue) => Math.round(foregroundValue * alpha + underlayValue * (1 - alpha));
37
+ return rgbToHex(channel(foreground.r, underlay.r), channel(foreground.g, underlay.g), channel(foreground.b, underlay.b));
38
+ }
39
+ function parseRgba(value) {
40
+ const match = value.trim().match(/^rgba?\(\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*(?:,|\/)\s*([\d.]+%?))?\s*\)$/i);
41
+ if (!match) return null;
42
+ const [, rSource, gSource, bSource] = match;
43
+ if (!rSource || !gSource || !bSource) return null;
44
+ const r = Number(rSource);
45
+ const g = Number(gSource);
46
+ const b = Number(bSource);
47
+ const alpha = parseAlpha(match[4]);
48
+ if (alpha === null || !isRgbChannel(r) || !isRgbChannel(g) || !isRgbChannel(b)) return null;
49
+ return {
50
+ r,
51
+ g,
52
+ b,
53
+ alpha
54
+ };
55
+ }
56
+ function parseAlpha(source) {
57
+ if (!source) return 1;
58
+ const value = source.endsWith("%") ? Number(source.slice(0, -1)) / 100 : Number(source);
59
+ return Number.isFinite(value) && value >= 0 && value <= 1 ? value : null;
60
+ }
61
+ function isRgbChannel(value) {
62
+ return Number.isFinite(value) && value >= 0 && value <= 255;
63
+ }
64
+ /**
65
+ * Derive the hover foreground that belongs with a resolved resting foreground.
66
+ *
67
+ * A resting foreground is chosen to be legible against a known surface. A hover
68
+ * state derived from it stays within a bounded distance of that colour, so it
69
+ * inherits most of the resting colour's contrast margin instead of asserting
70
+ * an unrelated brand colour that no one checked against the surface.
71
+ *
72
+ * That bounded-distance property is what lets this be used on a transparent
73
+ * overlay header, where the backdrop is only partly knowable: the scrolled
74
+ * state composites a 60% glass tint over arbitrary page content, so no
75
+ * compile-time contrast proof is available there. Staying near a colour that
76
+ * is already trusted in both states is a weaker claim than a contrast proof,
77
+ * and it is one this function can actually keep.
78
+ *
79
+ * Returns `null` when the resting token is not a plain palette token — an
80
+ * already-faded or raw value has no well-defined softening, and the caller
81
+ * should leave hover alone rather than guess.
82
+ */
83
+ function deriveForegroundHoverToken(restingToken) {
84
+ const parts = parseColorTokenParts(restingToken);
85
+ if (parts.kind !== "token") return null;
86
+ if (parts.opacityPercent !== null) return null;
87
+ return parseThemeColorToken(`${parts.token}/85`);
88
+ }
89
+ /**
90
+ * Prefer an authored hover that survives every measured backdrop, then a
91
+ * checked softening of the resting colour. A null backdrop set represents a
92
+ * trusted treatment: only an explicit authored hover may change the colour.
93
+ * When neither option works, retain the resting colour and underline it.
94
+ */
95
+ function planForegroundHover(input) {
96
+ const { restingToken, candidate, palette, backdrops } = input;
97
+ if (candidate && String(candidate) !== String(restingToken)) {
98
+ if (backdrops === null || survivesEveryBackdrop(candidate, palette, backdrops)) return {
99
+ kind: "candidate",
100
+ token: candidate,
101
+ decoration: "initial"
102
+ };
103
+ }
104
+ const resting = parseThemeColorToken(restingToken);
105
+ const softened = resting ? deriveForegroundHoverToken(resting) : null;
106
+ if (softened && backdrops && survivesEveryBackdrop(softened, palette, backdrops)) return {
107
+ kind: "softened",
108
+ token: softened,
109
+ decoration: "initial"
110
+ };
111
+ return {
112
+ kind: "resting",
113
+ token: restingToken,
114
+ decoration: "underline"
115
+ };
116
+ }
117
+ function survivesEveryBackdrop(token, palette, backdrops) {
118
+ return backdrops.length > 0 && backdrops.every((backdrop) => {
119
+ const foreground = resolveOpaqueSurfaceHex(token, palette, backdrop);
120
+ return foreground !== null && contrastRatio(foreground, backdrop) >= 4.5;
121
+ });
122
+ }
123
+ //#endregion
124
+ //#region ../theme-core/src/palette/utils/inkSolver.ts
125
+ /**
126
+ * How far (OKLab ΔE) a brand colour drawn as ink may be nudged along its own
127
+ * family before it stops reading as that colour. Past this the caller uses
128
+ * neutral or palette text instead (Will, 2026-10-14).
129
+ */
130
+ const BRAND_INK_MAX_DELTA_E = .08;
131
+ /**
132
+ * The seed itself when it clears `paint`, otherwise the family member nearest
133
+ * the seed (OKLab ΔE) that clears. On a light ground that is darker, on a dark
134
+ * one lighter. A passing member further than `maxDistance` from the seed is
135
+ * refused as `too-far`, which is distinct from `unpaintable`: the family runs
136
+ * from black to white, so if no member clears, neither does black or white.
137
+ */
138
+ function inkFrom(family, paint, ratio, maxDistance = BRAND_INK_MAX_DELTA_E) {
139
+ assertContrastRatio(ratio);
140
+ if (!Number.isFinite(maxDistance) || maxDistance < 0) throw new RangeError(`Maximum ink distance must be finite and not negative: ${maxDistance}`);
141
+ const seedRatio = worstContrast(family.seed.y, paint);
142
+ if (seedRatio >= ratio) return {
143
+ kind: "ink",
144
+ hex: family.seed.hex,
145
+ ratio: seedRatio,
146
+ source: "exact"
147
+ };
148
+ const nearest = family.members.reduce((best, member) => {
149
+ const achieved = worstContrast(member.y, paint);
150
+ if (achieved < ratio) return best;
151
+ const distance = oklabDistance(member.oklab, family.seed.oklab);
152
+ return best === null || distance < best.distance ? {
153
+ hex: member.hex,
154
+ distance,
155
+ ratio: achieved
156
+ } : best;
157
+ }, null);
158
+ if (nearest === null) return {
159
+ kind: "unpaintable",
160
+ interval: paint,
161
+ ratio
162
+ };
163
+ if (nearest.distance > maxDistance) return {
164
+ kind: "too-far",
165
+ nearest: {
166
+ hex: nearest.hex,
167
+ distance: nearest.distance
168
+ },
169
+ maxDistance
170
+ };
171
+ return {
172
+ kind: "ink",
173
+ hex: nearest.hex,
174
+ ratio: nearest.ratio,
175
+ source: "family"
176
+ };
177
+ }
178
+ //#endregion
179
+ //#region ../theme-core/src/surfaces/surfaceInks.ts
180
+ const INK_SEEDS = {
181
+ brand: {
182
+ token: "primary",
183
+ ratio: ORDINARY_TEXT_MIN_CONTRAST_RATIO
184
+ },
185
+ accent: {
186
+ token: "accent",
187
+ ratio: ORDINARY_TEXT_MIN_CONTRAST_RATIO
188
+ },
189
+ focus: {
190
+ token: "primary",
191
+ ratio: 3
192
+ }
193
+ };
194
+ /**
195
+ * Solve the three inks for a measured solid paint. `textInk` is the surface's
196
+ * own (already certified) text ink: it stands in when the owner's colour is
197
+ * missing, or can only clear the paint by drifting too far from itself.
198
+ * A block owner can supply an authored shade candidate for a local ink.
199
+ */
200
+ function solveSurfaceInks(backdropHex, textInk, palette, candidates = {}) {
201
+ const paint = solidPaint(backdropHex);
202
+ const fallback = literalInk(resolveConcreteColorHex(textInk, palette) ?? pickBlackOrWhiteTextColor(backdropHex));
203
+ return {
204
+ brand: solveInk({
205
+ ...INK_SEEDS.brand,
206
+ token: candidates.brand ?? INK_SEEDS.brand.token
207
+ }, paint, palette, fallback),
208
+ accent: solveInk({
209
+ ...INK_SEEDS.accent,
210
+ token: candidates.accent ?? INK_SEEDS.accent.token
211
+ }, paint, palette, fallback),
212
+ focus: solveInk({
213
+ ...INK_SEEDS.focus,
214
+ token: candidates.focus ?? INK_SEEDS.focus.token
215
+ }, paint, palette, fallback)
216
+ };
217
+ }
218
+ function solveInk(seed, paint, palette, fallback) {
219
+ const token = parseThemeColorToken(seed.token);
220
+ const seedHex = hexColorSchema.safeParse(resolveConcreteColorHex(seed.token, palette));
221
+ if (!token || !seedHex.success) return fallback;
222
+ const solved = inkFrom(familyOf(seedHex.data), paint, seed.ratio);
223
+ switch (solved.kind) {
224
+ case "ink": return solved.source === "exact" ? token : literalInk(solved.hex);
225
+ case "too-far":
226
+ case "unpaintable": return fallback;
227
+ }
228
+ }
229
+ function literalInk(hex) {
230
+ return hexColorSchema.parse(hex.toLowerCase());
231
+ }
232
+ const FAMILY_CACHE_LIMIT = 64;
233
+ const families = /* @__PURE__ */ new Map();
234
+ function familyOf(seed) {
235
+ const cached = families.get(seed);
236
+ if (cached) return cached;
237
+ if (families.size >= FAMILY_CACHE_LIMIT) families.clear();
238
+ const family = colourFamily(seed);
239
+ families.set(seed, family);
240
+ return family;
241
+ }
242
+ //#endregion
243
+ //#region ../theme-core/src/surfaces/inkCertificate.ts
244
+ const contrastThresholdByPolicy = {
245
+ "body-aa": 4.5,
246
+ "large-text-aa": 3,
247
+ decorative: 1
248
+ };
249
+ /** Headings are large text; every other foreground role is ordinary text. */
250
+ const surfaceTextPolicy = Object.freeze({
251
+ heading: "large-text-aa",
252
+ text: "body-aa",
253
+ link: "body-aa",
254
+ linkHover: "body-aa",
255
+ supporting: "body-aa",
256
+ muted: "body-aa"
257
+ });
258
+ /**
259
+ * Text shown only while a pointer hovers needs 3:1: the reader has already
260
+ * found it at rest, where it holds 4.5:1. States that stay on screen (open,
261
+ * the current-page link) keep the text threshold.
262
+ */
263
+ const HOVER_TEXT_THRESHOLD = contrastThresholdByPolicy["large-text-aa"];
264
+ const FALLBACK_INKS = ["#000000", "#FFFFFF"];
265
+ const isFallbackInk = (ink) => FALLBACK_INKS.includes(ink);
266
+ function inkReference(ink) {
267
+ return isFallbackInk(ink) ? `raw:${ink}` : ink;
268
+ }
269
+ /** A token, `rgba()` or literal, composited over each backdrop, clears the threshold on all of them. */
270
+ function inkClearsBackdrops(ink, threshold, backdrops, measurement) {
271
+ return backdrops.every((backdrop) => {
272
+ const hex = resolveOpaqueSurfaceHex(ink, measurement.palette, backdrop);
273
+ return hex !== null && contrastRatio(hex, backdrop, measurement.colourIndex) >= threshold;
274
+ });
275
+ }
276
+ /** The black/white ink that clears every backdrop at ordinary-text contrast, preferring the best one for the painted end. */
277
+ function fallbackInk(backdrops, measurement) {
278
+ const [endpoint] = backdrops.slice(-1);
279
+ return [...endpoint ? [pickBlackOrWhiteTextColor(endpoint)] : [], ...FALLBACK_INKS].find((candidate) => inkClearsBackdrops(candidate, contrastThresholdByPolicy["body-aa"], backdrops, measurement)) ?? null;
280
+ }
281
+ function failingInks(inks, backdrops, measurement) {
282
+ return {
283
+ roles: Object.keys(inks.foreground).filter((role) => !inkClearsBackdrops(inks.foreground[role], contrastThresholdByPolicy[surfaceTextPolicy[role]], backdrops, measurement)),
284
+ mark: inks.mark !== void 0 && !inkClearsBackdrops(inks.mark, 3, backdrops, measurement) ? ["mark"] : []
285
+ };
286
+ }
287
+ function replaceFailing(inks, failing, ink) {
288
+ return {
289
+ foreground: {
290
+ ...inks.foreground,
291
+ ...Object.fromEntries(failing.roles.map((role) => [role, ink]))
292
+ },
293
+ ...inks.mark === void 0 ? {} : { mark: failing.mark.length > 0 ? ink : inks.mark },
294
+ fallback: [...failing.roles, ...failing.mark]
295
+ };
296
+ }
297
+ /**
298
+ * Hold every role to its text policy and the mark to 3:1 on every backdrop.
299
+ * Null only when neither black nor white clears every backdrop, which only a
300
+ * radial tint's samples can do: `certifySolidSurfaceInks` is the total form for
301
+ * one solid backdrop.
302
+ */
303
+ function certifySurfaceInks(inks, backdrops, measurement) {
304
+ const failing = failingInks(inks, backdrops, measurement);
305
+ if (failing.roles.length === 0 && failing.mark.length === 0) return {
306
+ ...inks,
307
+ fallback: []
308
+ };
309
+ const ink = fallbackInk(backdrops, measurement);
310
+ return ink ? replaceFailing(inks, failing, ink) : null;
311
+ }
312
+ /** One solid backdrop: black or white always reaches 4.58:1 on it, so certification always succeeds. */
313
+ function certifySolidSurfaceInks(inks, backdrop, measurement) {
314
+ const failing = failingInks(inks, [backdrop], measurement);
315
+ if (failing.roles.length === 0 && failing.mark.length === 0) return {
316
+ ...inks,
317
+ fallback: []
318
+ };
319
+ return replaceFailing(inks, failing, pickBlackOrWhiteTextColor(backdrop));
320
+ }
321
+ /** Kept when the ink clears the threshold, otherwise the black/white ink, which always clears a solid backdrop. */
322
+ function certifyPaint(place, ink, threshold, backdrop, measurement) {
323
+ return inkClearsBackdrops(ink, threshold, [backdrop], measurement) ? {
324
+ place,
325
+ ink,
326
+ backdrop,
327
+ threshold,
328
+ fallback: false
329
+ } : {
330
+ place,
331
+ ink: pickBlackOrWhiteTextColor(backdrop),
332
+ backdrop,
333
+ threshold,
334
+ fallback: true,
335
+ declared: ink
336
+ };
337
+ }
338
+ //#endregion
339
+ //#region ../theme-core/src/surfaces/resolveSurfaceForeground.ts
340
+ const FALLBACK_TEXT_TOKENS = [
341
+ "text",
342
+ "primaryForeground",
343
+ "secondaryForeground",
344
+ "accentForeground",
345
+ "neutral-950",
346
+ "neutral-50"
347
+ ];
348
+ const CANONICAL_EQUIVALENT_TOKEN_ORDER = [
349
+ "text",
350
+ "primaryForeground",
351
+ "secondaryForeground",
352
+ "accentForeground",
353
+ "onPrimary",
354
+ "onSecondary",
355
+ "onAccent",
356
+ "onSurface",
357
+ "neutral-950",
358
+ "neutral-50"
359
+ ];
360
+ function resolveSurfaceForeground(background, palette, candidates = {}, options = {}) {
361
+ const authored = foregroundCandidates(background, candidates);
362
+ if ("measuredBackdrop" in options) return resolveMeasuredForeground(background?.color ?? "background", options.measuredBackdrop, authored, palette);
363
+ return resolveAuthoredBackground(background, palette, authored, options);
364
+ }
365
+ /** Legacy references may be measurable, inherited, or a trusted media treatment. */
366
+ function resolveAuthoredBackground(background, palette, authored, options) {
367
+ if (background === null) return resolveDeterministicForeground("background", {
368
+ ...authored,
369
+ text: authored.text ?? "text"
370
+ }, palette);
371
+ if (background.type === "color") {
372
+ const backgroundReference = normalizedReference(background.color);
373
+ if (!backgroundReference || backgroundReference === "transparent") return { kind: "inherits" };
374
+ return resolveDeterministicForeground(backgroundReference, authored, palette, options.compositeBase);
375
+ }
376
+ return resolveTrustedTreatmentForeground(authored, palette);
377
+ }
378
+ function foregroundCandidates(background, overrides) {
379
+ return {
380
+ text: candidateOrBackground(overrides.text, background?.textColor),
381
+ heading: candidateOrBackground(overrides.heading, background?.headingColor),
382
+ link: candidateOrBackground(overrides.link, background?.linkColor),
383
+ linkHover: candidateOrBackground(overrides.linkHover),
384
+ supporting: candidateOrBackground(overrides.supporting, background?.supportingColor)
385
+ };
386
+ }
387
+ function candidateOrBackground(candidate, backgroundValue) {
388
+ return candidate ?? backgroundValue ?? null;
389
+ }
390
+ function resolveDeterministicForeground(backgroundReference, candidates, palette, compositeBase) {
391
+ const backgroundHex = resolveOpaqueSurfaceHex(backgroundReference, palette, compositeBase);
392
+ if (!backgroundHex) return resolveTrustedTreatmentForeground(candidates, palette);
393
+ return resolveMeasuredForeground(backgroundReference, backgroundHex, candidates, palette);
394
+ }
395
+ function resolveMeasuredForeground(backgroundReference, backgroundHex, candidates, palette) {
396
+ const backgroundToken = paletteToken(backgroundReference);
397
+ const derivedOnToken = backgroundToken ? onColorTokenName(backgroundToken) : null;
398
+ const text = firstSafeToken([
399
+ candidates.text,
400
+ derivedOnToken,
401
+ ...FALLBACK_TEXT_TOKENS
402
+ ], backgroundHex, palette, derivedOnToken ? [derivedOnToken] : []) ?? pickBlackOrWhiteTextColor(backgroundHex);
403
+ return certifiedForeground(knownForeground({
404
+ text,
405
+ heading: safeTokenOr(candidates.heading, text, backgroundHex, palette),
406
+ link: safeTokenOr(candidates.link, text, backgroundHex, palette),
407
+ supporting: safeTokenOr(candidates.supporting, text, backgroundHex, palette)
408
+ }, {
409
+ kind: "measured",
410
+ backdropHex: backgroundHex,
411
+ inks: solveSurfaceInks(backgroundHex, text, palette)
412
+ }, candidates.linkHover, palette), palette);
413
+ }
414
+ /**
415
+ * Every measured foreground goes through the ink certificate, whoever paints it
416
+ * (sections, cards, header, footer, accordions). The candidates above are chosen
417
+ * to pass, so the certificate is normally a no-op and the foreground is returned
418
+ * as it was; an ink that misses takes black/white, and the solved inks follow
419
+ * the certified text.
420
+ */
421
+ function certifiedForeground(foreground, palette) {
422
+ const { backdropHex } = foreground.provenance;
423
+ const certified = certifySolidSurfaceInks({ foreground: foreground.roles }, backdropHex, { palette });
424
+ if (certified.fallback.length === 0) return foreground;
425
+ return {
426
+ ...foreground,
427
+ roles: certified.foreground,
428
+ provenance: {
429
+ ...foreground.provenance,
430
+ inks: solveSurfaceInks(backdropHex, certified.foreground.text, palette),
431
+ fallback: certified.fallback
432
+ }
433
+ };
434
+ }
435
+ function resolveTrustedTreatmentForeground(candidates, palette) {
436
+ const text = canonicalToken(candidates.text, palette);
437
+ if (!text) return { kind: "unmeasured-paint" };
438
+ return knownForeground({
439
+ text,
440
+ heading: canonicalToken(candidates.heading, palette) ?? text,
441
+ link: canonicalToken(candidates.link, palette) ?? text,
442
+ supporting: canonicalToken(candidates.supporting, palette) ?? text
443
+ }, { kind: "trusted-treatment" }, candidates.linkHover, palette);
444
+ }
445
+ function knownForeground(roles, provenance, hoverCandidate, palette) {
446
+ const hover = planForegroundHover({
447
+ restingToken: roles.link,
448
+ candidate: canonicalHoverToken(hoverCandidate, palette),
449
+ palette,
450
+ backdrops: provenance.kind === "measured" ? [provenance.backdropHex] : null
451
+ });
452
+ return {
453
+ kind: "known",
454
+ provenance,
455
+ roles: {
456
+ ...roles,
457
+ linkHover: hover.token,
458
+ muted: provenance.kind === "measured" ? deriveSurfaceMutedColor(provenance.backdropHex, resolveConcreteColorHex(roles.text, palette) ?? provenance.backdropHex) : roles.text
459
+ },
460
+ hoverDecoration: hover.decoration
461
+ };
462
+ }
463
+ function canonicalHoverToken(reference, palette) {
464
+ const token = parseThemeColorToken(reference);
465
+ if (token) {
466
+ const parts = parseColorTokenParts(token);
467
+ if (parts.kind === "token" && resolveConcreteColorHex(parts.token, palette)) return token;
468
+ }
469
+ return canonicalToken(reference, palette);
470
+ }
471
+ /**
472
+ * The one rule for what a resolved foreground publishes for the solved inks.
473
+ * Only a measured paint under a publishing runtime publishes inks; any other
474
+ * paint it owns resets them, and a paint it only inherits publishes nothing.
475
+ */
476
+ function surfaceInkPublication(foreground, policy) {
477
+ switch (foreground.kind) {
478
+ case "inherits": return { kind: "none" };
479
+ case "unmeasured-paint": return { kind: "reset" };
480
+ case "known": return foreground.provenance.kind === "measured" && policy === "publish" ? {
481
+ kind: "solved",
482
+ inks: foreground.provenance.inks
483
+ } : { kind: "reset" };
484
+ }
485
+ }
486
+ /** Keep a candidate only when it meets ordinary-text contrast on the ground. */
487
+ function safeTokenOr(candidate, fallback, backgroundHex, palette) {
488
+ return firstSafeToken([candidate], backgroundHex, palette) ?? fallback;
489
+ }
490
+ function firstSafeToken(candidates, backgroundHex, palette, preferredEquivalentTokens = []) {
491
+ const seen = /* @__PURE__ */ new Set();
492
+ for (const candidate of candidates) {
493
+ const token = canonicalToken(candidate, palette, preferredEquivalentTokens);
494
+ if (!token || seen.has(token)) continue;
495
+ seen.add(token);
496
+ const foregroundHex = resolveConcreteColorHex(token, palette);
497
+ if (foregroundHex && contrastRatio(backgroundHex, foregroundHex) >= 4.5) return token;
498
+ }
499
+ return null;
500
+ }
501
+ function canonicalToken(reference, palette, preferredEquivalentTokens = []) {
502
+ const normalized = normalizedReference(reference);
503
+ if (!normalized || normalized === "transparent") return null;
504
+ const direct = parseThemeColorToken(normalized);
505
+ if (direct && resolveConcreteColorHex(direct, palette)) return direct;
506
+ const referenceHex = resolveConcreteColorHex(normalized, palette);
507
+ if (!referenceHex) return null;
508
+ const equivalent = [
509
+ ...preferredEquivalentTokens,
510
+ ...CANONICAL_EQUIVALENT_TOKEN_ORDER,
511
+ ...Object.keys(palette).sort()
512
+ ].find((token) => {
513
+ const parsed = parseThemeColorToken(token);
514
+ return parsed !== null && resolveConcreteColorHex(parsed, palette)?.toLowerCase() === referenceHex.toLowerCase();
515
+ });
516
+ return equivalent ? parseThemeColorToken(equivalent) : null;
517
+ }
518
+ function paletteToken(reference) {
519
+ const parts = parseColorTokenParts(reference);
520
+ return parts.kind === "token" && parts.opacityPercent === null ? parts.token : null;
521
+ }
522
+ function normalizedReference(value) {
523
+ if (typeof value !== "string") return null;
524
+ const normalized = value.trim();
525
+ return normalized.length > 0 ? normalized : null;
526
+ }
527
+ //#endregion
528
+ //#region ../theme-core/src/site-styles/ownedThemeSnapshot.ts
529
+ /** Copy before freezing: the editor still owns its source data. */
530
+ function ownedThemeSnapshot(input) {
531
+ return freezeOwnedThemeValue(structuredClone(input));
532
+ }
533
+ /** Only freshly owned data belongs here; no caller-owned object is frozen. */
534
+ function freezeOwnedThemeValue(value) {
535
+ if (typeof value === "object" && value !== null) {
536
+ Object.values(value).forEach(freezeOwnedThemeValue);
537
+ Object.freeze(value);
538
+ }
539
+ return value;
540
+ }
541
+ //#endregion
542
+ //#region ../theme-core/src/buttons/styles/domain.ts
543
+ const PUBLIC_BUTTON_ROLES = VARIANT_ROLES;
544
+ function defineButtonStyleRecipe(recipe) {
545
+ return recipe;
546
+ }
547
+ function mapButtonVisualAppearances(states, transform) {
548
+ return {
549
+ ...states,
550
+ base: transform(states.base, "base"),
551
+ hover: transform(states.hover, "hover"),
552
+ focus: transform(states.focus, "focus"),
553
+ active: transform(states.active, "active"),
554
+ disabled: transform(states.disabled, "disabled")
555
+ };
556
+ }
557
+ function mapButtonRoleAppearances(roles, transform) {
558
+ const role = (name) => transform(roles[name], name);
559
+ return {
560
+ primary: role("primary"),
561
+ secondary: role("secondary"),
562
+ outline: role("outline"),
563
+ ghost: role("ghost"),
564
+ accent: role("accent")
565
+ };
566
+ }
567
+ //#endregion
568
+ //#region ../theme-core/src/buttons/buttonAppearance.ts
569
+ /** Expand persisted pre-recipe families at the rendering boundary, once. */
570
+ function materializeRuntimeButtonAppearance(variant, global, theme, sizes) {
571
+ if (variant.visualStates) return {
572
+ ...variant,
573
+ visualStates: variant.visualStates
574
+ };
575
+ const shadow = variant.shadow ?? {
576
+ elevation: global.shadow ?? "none",
577
+ softness: theme.shadow.softness,
578
+ position: theme.shadow.position
579
+ };
580
+ const typography = persistedTypography(global);
581
+ const padding = {
582
+ sm: resolvedSize(variant, sizes, "sm"),
583
+ md: resolvedSize(variant, sizes, "md"),
584
+ lg: resolvedSize(variant, sizes, "lg"),
585
+ xl: resolvedSize(variant, sizes, "xl")
586
+ };
587
+ const shared = {
588
+ background: variant.background,
589
+ text: "treatment",
590
+ border: variant.border ?? "none",
591
+ borderRadius: variant.borderRadius ?? {
592
+ square: "rounded-none",
593
+ rounded: "rounded-md",
594
+ pill: "rounded-full"
595
+ }[global.cornerStyle],
596
+ sizes: padding,
597
+ typography
598
+ };
599
+ const hoverToken = variant.hoverBackgroundToken ?? (global.hoverColor === "token" ? global.hoverColorToken : void 0);
600
+ const effects = (state) => (variant.effects?.[state] ?? []).map((effect) => {
601
+ if (effect.effectId !== "press-down" || effect.options?.offset) return effect;
602
+ const source = variant.shadow ?? theme.shadow;
603
+ const offset = ELEVATION_OFFSET[source.elevation];
604
+ return {
605
+ ...effect,
606
+ options: { offset: {
607
+ x: source.position === "bottom-right" ? offset : 0,
608
+ y: offset
609
+ } }
610
+ };
611
+ });
612
+ return {
613
+ ...variant,
614
+ visualStates: {
615
+ base: {
616
+ ...shared,
617
+ shadow,
618
+ effects: effects("base")
619
+ },
620
+ hover: {
621
+ ...shared,
622
+ background: hoverToken ? {
623
+ type: "solid",
624
+ colorToken: hoverToken
625
+ } : shared.background,
626
+ shadow,
627
+ effects: effects("hover"),
628
+ ...variant.contextualHover ? { contextualHover: variant.contextualHover } : {}
629
+ },
630
+ focus: {
631
+ ...shared,
632
+ shadow: "focus-indicator",
633
+ effects: effects("focus")
634
+ },
635
+ active: {
636
+ ...shared,
637
+ shadow,
638
+ effects: effects("active")
639
+ },
640
+ disabled: {
641
+ ...shared,
642
+ shadow: {
643
+ elevation: "none",
644
+ softness: null,
645
+ position: "bottom"
646
+ },
647
+ effects: []
648
+ }
649
+ }
650
+ };
651
+ }
652
+ function persistedTypography(global) {
653
+ return {
654
+ fontWeight: global.fontWeight,
655
+ typography: global.typography ?? "body",
656
+ fontSize: global.fontSize ?? null,
657
+ letterSpacing: global.letterSpacing ?? (global.typography === "heading" ? "heading" : null),
658
+ italic: global.italic ?? false,
659
+ textTransform: global.textTransform
660
+ };
661
+ }
662
+ function resolvedSize(variant, sizes, name) {
663
+ const override = variant.sizes?.[name];
664
+ const fontSize = override?.fontSize ?? sizes[name].fontSize;
665
+ return {
666
+ padding: override?.padding ?? sizes[name].padding,
667
+ ...fontSize ? { fontSize } : {}
668
+ };
669
+ }
670
+ function buttonTypographyDeclarations(type) {
671
+ const spacing = type.letterSpacing === null ? null : type.letterSpacing === "heading" ? "var(--ls-heading)" : {
672
+ tight: "-0.025em",
673
+ normal: "0",
674
+ slight: "0.01em",
675
+ loose: "0.05em",
676
+ wide: "0.125em"
677
+ }[type.letterSpacing];
678
+ return [
679
+ ["font-weight", String(type.fontWeight)],
680
+ ["font-family", type.typography === "heading" ? "var(--font-heading)" : "var(--font-body)"],
681
+ ...spacing === null ? [] : [["letter-spacing", spacing]],
682
+ ...type.italic ? [["font-style", "italic"]] : [],
683
+ ...type.fontSize === null ? [] : [["font-size", FONT_SIZE_MAP[type.fontSize] || "1rem"]],
684
+ ...type.textTransform === "none" ? [] : [["text-transform", type.textTransform]]
685
+ ];
686
+ }
687
+ function buttonRadius(radius) {
688
+ return BORDER_RADIUS_MAP[radius] ?? BORDER_RADIUS_MAP.rounded ?? "0.375rem";
689
+ }
690
+ function buttonShadow(shadow, tokens) {
691
+ return generateShadowValue(shadow.elevation, shadow.softness, shadow.position, shadow.colorToken ? tokens.getColor(shadow.colorToken) : void 0);
692
+ }
693
+ function buttonBorder(border, tokens) {
694
+ return border === "none" ? null : `${BORDER_WIDTH_MAP[border.widthClass] || "1px"} solid ${border.boundaryInk ? tokens.getColor(border.boundaryInk) : "currentColor"}`;
695
+ }
696
+ function buttonTypographyChanges(base, state) {
697
+ const original = new Map(buttonTypographyDeclarations(base));
698
+ const declared = new Map(buttonTypographyDeclarations(state));
699
+ const resets = [
700
+ ["font-style", "normal"],
701
+ ["text-transform", "none"],
702
+ ["letter-spacing", "normal"]
703
+ ].filter(([property]) => original.has(property) && !declared.has(property));
704
+ return [...declared, ...resets].filter(([property, value]) => original.get(property) !== value);
705
+ }
706
+ /** Emit only changed declarations; identical states keep historical CSS bytes. */
707
+ function buttonStateAppearanceDeclarations(base, state, tokens, disabled = false) {
708
+ const border = buttonBorder(state.border, tokens);
709
+ const radius = buttonRadius(state.borderRadius);
710
+ const shadow = !disabled && state.shadow !== "focus-indicator" ? buttonShadow(state.shadow, tokens) : null;
711
+ return [
712
+ ...buttonTypographyChanges(base.typography, state.typography),
713
+ ...buttonRadius(base.borderRadius) === radius ? [] : [["border-radius", radius]],
714
+ ...buttonBorder(base.border, tokens) === border ? [] : [["border", border ?? "none"]],
715
+ ...shadow === null || base.shadow === "focus-indicator" || buttonShadow(base.shadow, tokens) === shadow ? [] : [["box-shadow", shadow]]
716
+ ];
717
+ }
718
+ /** Surface paint is a context for the recipe, checked by the same colour owner. */
719
+ function surfaceButtonSystem(system, primaryToken) {
720
+ return primaryToken === void 0 ? system : {
721
+ ...system,
722
+ variants: system.variants.map((variant) => variant.id === "primary" ? surfacePrimary(variant, primaryToken) : variant)
723
+ };
724
+ }
725
+ function withoutColourTransitions(effects) {
726
+ return effects.filter((effect) => effect.effectId !== "background-on-hover" && effect.effectId !== "darken-background" && effect.effectId !== "lighten-background");
727
+ }
728
+ function surfacePrimary(variant, token) {
729
+ const background = {
730
+ type: "solid",
731
+ colorToken: token
732
+ };
733
+ return {
734
+ ...variant,
735
+ background,
736
+ hoverBackgroundToken: void 0,
737
+ contextualHover: void 0,
738
+ visualStates: variant.visualStates ? mapButtonVisualAppearances(variant.visualStates, (state) => ({
739
+ ...state,
740
+ background,
741
+ contextualHover: void 0,
742
+ effects: withoutColourTransitions(state.effects)
743
+ })) : void 0,
744
+ effects: variant.effects === void 0 ? void 0 : Object.fromEntries([
745
+ "base",
746
+ "hover",
747
+ "focus",
748
+ "active"
749
+ ].flatMap((state) => variant.effects?.[state] ? [[state, withoutColourTransitions(variant.effects[state])]] : []))
750
+ };
751
+ }
752
+ function paddingDeclarations(padding, borderWidth) {
753
+ const parts = padding.split(/\s+/).filter(Boolean);
754
+ if (parts.length !== 2) throw new Error(`Invariant: padding "${padding}" did not validate as two-token shorthand`);
755
+ const [vertical, horizontal] = parts;
756
+ if (borderWidth === "0px") return [["padding", `${vertical} ${horizontal}`]];
757
+ if (vertical === horizontal) return [["padding", `calc(${vertical} - ${borderWidth})`]];
758
+ return [
759
+ ["padding-top", `calc(${vertical} - ${borderWidth})`],
760
+ ["padding-bottom", `calc(${vertical} - ${borderWidth})`],
761
+ ["padding-left", `calc(${horizontal} - ${borderWidth})`],
762
+ ["padding-right", `calc(${horizontal} - ${borderWidth})`]
763
+ ];
764
+ }
765
+ //#endregion
766
+ //#region ../theme-core/src/buttons/buttonSurfaceContext.ts
767
+ /** The last resort, chosen by `maxContrastBlackOrWhite`. */
768
+ const LITERAL_NEUTRALS = {
769
+ black: {
770
+ hex: "#000000",
771
+ css: "#000000",
772
+ source: "literal-css"
773
+ },
774
+ white: {
775
+ hex: "#ffffff",
776
+ css: "#ffffff",
777
+ source: "literal-css"
778
+ }
779
+ };
780
+ /**
781
+ * Derive only what the rendered section can honestly prove about its backing.
782
+ * Images, gradients, alpha/composite layers and arbitrary CSS remain unknown.
783
+ */
784
+ function deriveButtonSurfaceContext(input, palette, fallbackToken, colourIndex) {
785
+ const background = deriveKnownBackground(input, palette, fallbackToken);
786
+ if (background.kind === "unknown") return background;
787
+ const explicitForeground = resolveKnownColour(input.kind === "solid" || input.kind === "inherit" ? input.foreground ?? "" : "", palette);
788
+ const foreground = explicitForeground && contrastRatio(background.colour.hex, explicitForeground.hex, colourIndex) >= 4.5 ? explicitForeground : LITERAL_NEUTRALS[maxContrastBlackOrWhite(solidPaint(background.colour.hex, colourIndex)).ink];
789
+ return {
790
+ kind: "known-solid",
791
+ source: background.source,
792
+ surface: {
793
+ kind: "solid",
794
+ backgroundHex: background.colour.hex,
795
+ backgroundCss: background.colour.css,
796
+ ...input.kind === "solid" && input.backgroundSamples ? { backgroundSamples: input.backgroundSamples } : {},
797
+ foregroundHex: foreground.hex,
798
+ foregroundCss: foreground.css
799
+ }
800
+ };
801
+ }
802
+ function deriveKnownBackground(input, palette, fallbackToken) {
803
+ switch (input.kind) {
804
+ case "inherit": return fallbackBackground(fallbackToken, palette);
805
+ case "image": return {
806
+ kind: "unknown",
807
+ reason: "image-background"
808
+ };
809
+ case "gradient": return {
810
+ kind: "unknown",
811
+ reason: "gradient-background"
812
+ };
813
+ case "unknown": return {
814
+ kind: "unknown",
815
+ reason: "unresolvable-colour"
816
+ };
817
+ case "solid": if (input.composited) return {
818
+ kind: "unknown",
819
+ reason: "composited-background"
820
+ };
821
+ }
822
+ const authored = readNonEmptyString(input.color);
823
+ const backgroundValue = authored ?? fallbackToken;
824
+ if (!backgroundValue) return {
825
+ kind: "unknown",
826
+ reason: "missing-background"
827
+ };
828
+ const colour = resolveKnownSurfaceColour(backgroundValue, palette, authored ? fallbackToken : void 0);
829
+ if (!colour) return {
830
+ kind: "unknown",
831
+ reason: "unresolvable-colour"
832
+ };
833
+ return {
834
+ kind: "known",
835
+ colour,
836
+ source: authored ? colour.source : "fallback-token"
837
+ };
838
+ }
839
+ function resolveKnownSurfaceColour(value, palette, underlayReference) {
840
+ const hex = resolveOpaqueSurfaceHex(value, palette, underlayReference);
841
+ if (!hex) return resolveKnownColour(value, palette);
842
+ const reference = parseThemeColorReference(value, { palette });
843
+ return {
844
+ hex,
845
+ css: resolveThemeColorReferenceValue(value, { palette }),
846
+ source: reference.kind === "literal-css" ? "literal-css" : "palette-token"
847
+ };
848
+ }
849
+ function fallbackBackground(fallbackToken, palette) {
850
+ if (!fallbackToken) return {
851
+ kind: "unknown",
852
+ reason: "missing-background"
853
+ };
854
+ const colour = resolveKnownColour(fallbackToken, palette);
855
+ return colour ? {
856
+ kind: "known",
857
+ colour,
858
+ source: "fallback-token"
859
+ } : {
860
+ kind: "unknown",
861
+ reason: "unresolvable-colour"
862
+ };
863
+ }
864
+ function resolveSurfaceButtonContext(input) {
865
+ if (!input.buttonSystem) return input.withoutButtonSystem === "reset" ? {
866
+ kind: "reset",
867
+ styles: contextualButtonSurfaceResetStyles()
868
+ } : {
869
+ kind: "inherit",
870
+ styles: {}
871
+ };
872
+ const context = deriveButtonSurfaceContext(input.surface, input.palette, input.fallbackToken, input.colourIndex);
873
+ if (context.kind !== "known-solid") return context.reason === "missing-background" ? {
874
+ kind: "inherit",
875
+ styles: {}
876
+ } : {
877
+ kind: "reset",
878
+ styles: contextualButtonSurfaceResetStyles()
879
+ };
880
+ return knownSurfaceButtonContext({
881
+ surface: context.surface,
882
+ palette: input.palette,
883
+ colourIndex: input.colourIndex,
884
+ buttonSystem: surfaceButtonSystem(input.buttonSystem, input.primaryToken)
885
+ });
886
+ }
887
+ function knownSurfaceButtonContext(input) {
888
+ const roles = freezeOwnedThemeValue({
889
+ primary: resolveContextualButtonRole({
890
+ ...input,
891
+ role: "primary"
892
+ }),
893
+ secondary: resolveContextualButtonRole({
894
+ ...input,
895
+ role: "secondary"
896
+ }),
897
+ outline: resolveContextualButtonRole({
898
+ ...input,
899
+ role: "outline"
900
+ }),
901
+ ghost: resolveContextualButtonRole({
902
+ ...input,
903
+ role: "ghost"
904
+ }),
905
+ accent: resolveContextualButtonRole({
906
+ ...input,
907
+ role: "accent"
908
+ })
909
+ });
910
+ const styles = Object.fromEntries(VARIANT_ROLES.flatMap((role) => Object.entries(contextualButtonSurfaceStyles(roles[role]))));
911
+ return Object.defineProperty({
912
+ kind: "resolved",
913
+ styles,
914
+ roles
915
+ }, "roles", { enumerable: false });
916
+ }
917
+ function resolveContextualButtonRole(input) {
918
+ const requested = findVariant(input.buttonSystem, input.role);
919
+ if (!requested) return {
920
+ kind: "unresolved",
921
+ requestedRole: input.role,
922
+ rejectedCandidates: []
923
+ };
924
+ const preferred = compileCandidate(requested, input);
925
+ if (preferred.ok) return preferredButtonResolution(requested, preferred, input.role);
926
+ return resolveFallbackButtonRole(input, requested, (input.buttonSystem.surfacePolicy ?? STANDARD_BUTTON_SURFACE_POLICY)[input.role], [{
927
+ candidate: "preferred",
928
+ error: preferred.error
929
+ }]);
930
+ }
931
+ function preferredButtonResolution(requested, compiled, role) {
932
+ const appearance = {
933
+ requestedRole: role,
934
+ states: compiled.states,
935
+ focusIndicator: compiled.focusIndicator,
936
+ boundary: boundaryForVariant(requested)
937
+ };
938
+ return compiled.contextualHoverRepair ? withBorderEvidence({
939
+ ...appearance,
940
+ kind: "repaired",
941
+ candidate: "contextual-hover",
942
+ rejectedCandidates: []
943
+ }, requested) : withBorderEvidence({
944
+ ...appearance,
945
+ kind: "preferred"
946
+ }, requested);
947
+ }
948
+ /** Ordered, lazy fallback selection; the rejected evidence belongs to this decision. */
949
+ function resolveFallbackButtonRole(input, requested, fallbacks, rejected) {
950
+ const [fallback, ...remaining] = fallbacks;
951
+ if (!fallback) return {
952
+ kind: "unresolved",
953
+ requestedRole: input.role,
954
+ rejectedCandidates: rejected
955
+ };
956
+ const candidate = candidateVariant(fallback, requested, input.buttonSystem);
957
+ if (!candidate) return resolveFallbackButtonRole(input, requested, remaining, rejected);
958
+ const compiled = compileCandidate(candidate.variant, input);
959
+ return compiled.ok ? withBorderEvidence({
960
+ kind: "repaired",
961
+ requestedRole: input.role,
962
+ candidate: candidate.name,
963
+ states: candidate.name === "surface-outline" ? withSurfaceInversion(compiled.states, input.surface) : compiled.states,
964
+ focusIndicator: compiled.focusIndicator,
965
+ boundary: candidate.boundary,
966
+ rejectedCandidates: rejected
967
+ }, candidate.variant) : resolveFallbackButtonRole(input, requested, remaining, [...rejected, {
968
+ candidate: candidate.name,
969
+ error: compiled.error
970
+ }]);
971
+ }
972
+ function contextualButtonSurfaceStyles(resolution) {
973
+ if (resolution.kind === "unresolved") return resetActionVariables(resolution.requestedRole);
974
+ const styles = {};
975
+ for (const state of BUTTON_VISUAL_STATES) {
976
+ const colour = resolution.states[state];
977
+ const prefix = actionVariablePrefix(resolution.requestedRole, state);
978
+ styles[`${prefix}-background-color`] = colour.kind === "solid" || colour.kind === "known-solid" ? colour.backgroundCss : "transparent";
979
+ styles[`${prefix}-background-image`] = colour.kind === "gradient" ? colour.backgroundCss : "none";
980
+ styles[`${prefix}-color`] = colour.foregroundCss;
981
+ }
982
+ const focus = resolution.focusIndicator;
983
+ styles[actionVariableName(resolution.requestedRole, "focus", "outline")] = focus.kind === "two-tone" ? `2px solid ${focus.innerCss}` : `3px solid ${focus.colorCss}`;
984
+ styles[actionVariableName(resolution.requestedRole, "focus", "outline-offset")] = focus.kind === "two-tone" ? "2px" : "3px";
985
+ styles[actionVariableName(resolution.requestedRole, "focus", "box-shadow")] = focus.kind === "two-tone" ? `0 0 0 4px ${focus.outerCss}` : "none";
986
+ const boundary = contextualBoundaryStyles(resolution.boundary);
987
+ styles[actionVariableName(resolution.requestedRole, "base", "outline")] = boundary.outline;
988
+ styles[actionVariableName(resolution.requestedRole, "base", "outline-offset")] = boundary.offset;
989
+ return styles;
990
+ }
991
+ /**
992
+ * Break an inherited surface contract when a nested element establishes a
993
+ * backing whose colours cannot be proven (for example an image or gradient).
994
+ */
995
+ function contextualButtonSurfaceResetStyles() {
996
+ return Object.fromEntries(VARIANT_ROLES.flatMap((role) => Object.entries(resetActionVariables(role))));
997
+ }
998
+ function resetActionVariables(role) {
999
+ const styles = {};
1000
+ for (const state of BUTTON_VISUAL_STATES) for (const property of [
1001
+ "background-color",
1002
+ "background-image",
1003
+ "color"
1004
+ ]) styles[actionVariableName(role, state, property)] = "initial";
1005
+ for (const [state, property] of [
1006
+ ["base", "outline"],
1007
+ ["base", "outline-offset"],
1008
+ ["focus", "outline"],
1009
+ ["focus", "outline-offset"],
1010
+ ["focus", "box-shadow"]
1011
+ ]) styles[actionVariableName(role, state, property)] = "initial";
1012
+ return styles;
1013
+ }
1014
+ function withSurfaceInversion(states, surface) {
1015
+ const inverted = {
1016
+ kind: "known-solid",
1017
+ backgroundCss: surface.foregroundCss,
1018
+ foregroundCss: surface.backgroundCss
1019
+ };
1020
+ return {
1021
+ ...states,
1022
+ hover: inverted,
1023
+ active: inverted
1024
+ };
1025
+ }
1026
+ function actionVariableName(role, state, property) {
1027
+ return `--rb-action-${role}-${state}-${property}`;
1028
+ }
1029
+ function actionVariableFallback(role, state, property, fallback) {
1030
+ return `var(${actionVariableName(role, state, property)}, ${fallback})`;
1031
+ }
1032
+ function actionVariablePrefix(role, state) {
1033
+ return `--rb-action-${role}-${state}`;
1034
+ }
1035
+ function compileCandidate(variant, context) {
1036
+ return compileButtonColourStates({
1037
+ variant,
1038
+ global: context.buttonSystem.global,
1039
+ palette: context.palette,
1040
+ surface: context.surface,
1041
+ colourIndex: context.colourIndex
1042
+ });
1043
+ }
1044
+ function candidateVariant(fallback, requested, system) {
1045
+ if (fallback.kind === "variant") {
1046
+ const variant = findVariant(system, fallback.role);
1047
+ return variant ? {
1048
+ name: fallback.role,
1049
+ variant,
1050
+ boundary: boundaryForVariant(variant)
1051
+ } : null;
1052
+ }
1053
+ const width = BORDER_WIDTH_MAP.border ?? "1px";
1054
+ return {
1055
+ name: "surface-outline",
1056
+ variant: {
1057
+ ...requested,
1058
+ visualStates: void 0,
1059
+ background: {
1060
+ type: "surface",
1061
+ role: "link"
1062
+ },
1063
+ border: { widthClass: "border" },
1064
+ hoverBackgroundToken: void 0,
1065
+ contextualHover: void 0,
1066
+ effects: void 0
1067
+ },
1068
+ boundary: {
1069
+ width,
1070
+ color: "currentColor"
1071
+ }
1072
+ };
1073
+ }
1074
+ /** Each state's border travels with the decision, copied so freezing it never touches the caller's variant. */
1075
+ function withBorderEvidence(value, variant) {
1076
+ const borders = freezeOwnedThemeValue(ownedThemeSnapshot(Object.fromEntries(BUTTON_VISUAL_STATES.map((state) => [state, buttonStateBorder(variant, state)]))));
1077
+ return {
1078
+ ...value,
1079
+ borders
1080
+ };
1081
+ }
1082
+ function boundaryForVariant(variant) {
1083
+ if (!variant.border) return null;
1084
+ return {
1085
+ ...variant.border.ring ? { ring: true } : {},
1086
+ width: BORDER_WIDTH_MAP[variant.border.widthClass] ?? "1px",
1087
+ color: variant.border.boundaryInk ? `rgb(var(--tb-${variant.border.boundaryInk}))` : variant.border.ring ? "var(--rb-surface-mark-color, var(--rb-surface-link-color, currentColor))" : "currentColor"
1088
+ };
1089
+ }
1090
+ function findVariant(system, role) {
1091
+ return system.variants.find((variant) => variant.enabled && variant.id === role);
1092
+ }
1093
+ function resolveKnownColour(value, palette) {
1094
+ const reference = parseThemeColorReference(value, { palette });
1095
+ if (reference.kind !== "literal-css") {
1096
+ const token = String(reference.token);
1097
+ const paletteHex = palette[token];
1098
+ const hex = paletteHex ? normalizeOpaqueHex(paletteHex) : null;
1099
+ if (hex) return {
1100
+ hex,
1101
+ css: resolveThemeColorReferenceValue(value, { palette }),
1102
+ source: "palette-token"
1103
+ };
1104
+ const namedHex = NAMED_OPAQUE_COLOURS[token.toLowerCase()];
1105
+ return namedHex ? {
1106
+ hex: namedHex,
1107
+ css: token,
1108
+ source: "literal-css"
1109
+ } : null;
1110
+ }
1111
+ const hex = normalizeOpaqueCssColour(reference.value);
1112
+ return hex ? {
1113
+ hex,
1114
+ css: reference.value,
1115
+ source: "literal-css"
1116
+ } : null;
1117
+ }
1118
+ const NAMED_OPAQUE_COLOURS = {
1119
+ black: "#000000",
1120
+ white: "#ffffff",
1121
+ red: "#ff0000",
1122
+ green: "#008000",
1123
+ blue: "#0000ff",
1124
+ yellow: "#ffff00",
1125
+ gray: "#808080",
1126
+ grey: "#808080",
1127
+ orange: "#ffa500",
1128
+ purple: "#800080",
1129
+ pink: "#ffc0cb"
1130
+ };
1131
+ function normalizeOpaqueCssColour(value) {
1132
+ const trimmed = value.trim();
1133
+ const hex = normalizeOpaqueHex(trimmed);
1134
+ if (hex) return hex;
1135
+ return NAMED_OPAQUE_COLOURS[trimmed.toLowerCase()] ?? normalizeOpaqueRgb(trimmed) ?? normalizeOpaqueOklch(trimmed);
1136
+ }
1137
+ function normalizeOpaqueRgb(value) {
1138
+ const match = value.match(/^rgb\(\s*(\d{1,3})\s*[, ]\s*(\d{1,3})\s*[, ]\s*(\d{1,3})\s*\)$/i);
1139
+ if (!match) return null;
1140
+ const channels = match.slice(1).map(Number);
1141
+ if (channels.some((channel) => channel < 0 || channel > 255)) return null;
1142
+ const [red, green, blue] = channels;
1143
+ return red === void 0 || green === void 0 || blue === void 0 ? null : rgbToHex(red, green, blue);
1144
+ }
1145
+ function normalizeOpaqueOklch(value) {
1146
+ const match = value.match(/^oklch\(\s*([\d.]+)(%)?\s+([\d.]+)\s+([\d.]+)(?:deg)?\s*\)$/i);
1147
+ if (!match?.[1] || !match[3] || !match[4]) return null;
1148
+ const lightness = Number(match[1]) / (match[2] ? 100 : 1);
1149
+ const chroma = Number(match[3]);
1150
+ const hue = Number(match[4]);
1151
+ if (![
1152
+ lightness,
1153
+ chroma,
1154
+ hue
1155
+ ].every(Number.isFinite)) return null;
1156
+ if (lightness < 0 || lightness > 1) return null;
1157
+ const lab = oklchToOklab(lightness, chroma, hue);
1158
+ const rgb = oklabToSrgb(lab.L, lab.a, lab.b);
1159
+ return rgbToHex(clampChannel(rgb.r), clampChannel(rgb.g), clampChannel(rgb.b));
1160
+ }
1161
+ function clampChannel(value) {
1162
+ return Math.max(0, Math.min(255, value));
1163
+ }
1164
+ function normalizeOpaqueHex(value) {
1165
+ const match = value.trim().match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);
1166
+ if (!match?.[1]) return null;
1167
+ return `#${(match[1].length === 3 ? match[1].split("").map((digit) => `${digit}${digit}`).join("") : match[1]).toLowerCase()}`;
1168
+ }
1169
+ function readNonEmptyString(value) {
1170
+ return typeof value === "string" && value.trim() ? value.trim() : null;
1171
+ }
1172
+ function contextualBoundaryStyles(boundary) {
1173
+ if (boundary === null) return {
1174
+ outline: "none",
1175
+ offset: "0px"
1176
+ };
1177
+ return {
1178
+ outline: `${boundary.width} solid ${boundary.color}`,
1179
+ offset: boundary.ring ? "3px" : `-${boundary.width}`
1180
+ };
1181
+ }
1182
+ //#endregion
1183
+ //#region ../theme-core/src/palette/utils/scrimContrast.ts
1184
+ const WHITE = "#ffffff";
1185
+ const BLACK = "#000000";
1186
+ /** `top` at `alpha` over opaque `bottom`, blended as CSS paints an overlay. */
1187
+ function compositeHex(topHex, alpha, bottomHex) {
1188
+ const top = hexToRgb(topHex);
1189
+ const bottom = hexToRgb(bottomHex);
1190
+ const mix = (a, b) => Math.round(alpha * a + (1 - alpha) * b);
1191
+ return rgbToHex(mix(top.r, bottom.r), mix(top.g, bottom.g), mix(top.b, bottom.b));
1192
+ }
1193
+ /**
1194
+ * The lowest contrast `foreground` can reach over `scrim` at `alpha` laid on
1195
+ * any pixel. A foreground whose luminance falls inside the range the
1196
+ * composites can take has a worst case of 1:1.
1197
+ */
1198
+ function worstCaseScrimContrast(input) {
1199
+ const overWhite = compositeHex(input.scrimHex, input.alpha, WHITE);
1200
+ const overBlack = compositeHex(input.scrimHex, input.alpha, BLACK);
1201
+ const luminance = (hex) => {
1202
+ const { r, g, b } = hexToRgb(hex);
1203
+ return relativeLuminance(r, g, b);
1204
+ };
1205
+ const foreground = luminance(input.foregroundHex);
1206
+ const low = luminance(overBlack);
1207
+ const high = luminance(overWhite);
1208
+ if (foreground >= low && foreground <= high) return 1;
1209
+ return Math.min(contrastRatio(input.foregroundHex, overWhite), contrastRatio(input.foregroundHex, overBlack));
1210
+ }
1211
+ /** Shared samples for literal RGB washes and palette-token gradient veils. */
1212
+ function gradientScrimSamples(gradient, alpha, palette) {
1213
+ const literal = [...gradient.matchAll(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/g)].map((stop) => ({
1214
+ hex: rgbToHex(Number(stop[1]), Number(stop[2]), Number(stop[3])),
1215
+ alpha: alpha * (stop[4] === void 0 ? 1 : Number(stop[4]))
1216
+ }));
1217
+ const tokens = [...gradient.matchAll(/var\(--tb-([\w-]+)\)/g)].flatMap((stop) => {
1218
+ const hex = stop[1] ? resolveConcreteColorHex(stop[1], palette) : null;
1219
+ return hex ? [{
1220
+ hex,
1221
+ alpha
1222
+ }] : [];
1223
+ });
1224
+ return [...literal, ...tokens];
1225
+ }
1226
+ /** The ink with the stronger worst-pixel guarantee identifies the veil tone.
1227
+ * No readable samples (or a tie) leaves classification to the foreground owner.
1228
+ */
1229
+ function scrimTone(samples) {
1230
+ if (samples.length === 0) return null;
1231
+ const worst = (foregroundHex) => Math.min(...samples.map((sample) => worstCaseScrimContrast({
1232
+ foregroundHex,
1233
+ scrimHex: sample.hex,
1234
+ alpha: sample.alpha
1235
+ })));
1236
+ const white = worst(WHITE);
1237
+ const black = worst(BLACK);
1238
+ return white === black ? null : white > black ? "dark" : "light";
1239
+ }
1240
+ //#endregion
1241
+ //#region ../theme-core/src/site-styles/surfaceTransportMarker.ts
1242
+ /**
1243
+ * The envelope key `serializeSurfaceTree` writes and `parseSurfaceTree` reads.
1244
+ *
1245
+ * This module has no dependencies so browser code can check for transported
1246
+ * surfaces without loading the surface resolver, then import it only when
1247
+ * the payload needs it.
1248
+ */
1249
+ const SURFACE_TRANSPORT_KEY = "$surfaceTransport";
1250
+ //#endregion
1251
+ //#region ../theme-core/src/site-styles/accessibleSurfaces.ts
1252
+ const ON_BACKGROUND = { kind: "on-background" };
1253
+ const surfaceRecipes = {
1254
+ base: {
1255
+ backgroundCandidates: ["background", "surface"],
1256
+ headingCandidates: [
1257
+ "text",
1258
+ ON_BACKGROUND,
1259
+ "neutral-950",
1260
+ "neutral-50"
1261
+ ],
1262
+ textCandidates: [
1263
+ "text",
1264
+ ON_BACKGROUND,
1265
+ "neutral-950",
1266
+ "neutral-50"
1267
+ ],
1268
+ linkCandidates: [
1269
+ "primary",
1270
+ "text",
1271
+ ON_BACKGROUND,
1272
+ "neutral-950",
1273
+ "neutral-50"
1274
+ ],
1275
+ supportingCandidates: ["mutedText"],
1276
+ inheritedBackground: true
1277
+ },
1278
+ "muted-band": {
1279
+ backgroundCandidates: [
1280
+ "muted",
1281
+ "surfaceAlt",
1282
+ "surface",
1283
+ "background"
1284
+ ],
1285
+ headingCandidates: [
1286
+ ON_BACKGROUND,
1287
+ "text",
1288
+ "neutral-950",
1289
+ "neutral-50"
1290
+ ],
1291
+ textCandidates: [
1292
+ ON_BACKGROUND,
1293
+ "text",
1294
+ "neutral-950",
1295
+ "neutral-50"
1296
+ ],
1297
+ linkCandidates: [
1298
+ "primary",
1299
+ ON_BACKGROUND,
1300
+ "text",
1301
+ "neutral-950",
1302
+ "neutral-50"
1303
+ ],
1304
+ supportingCandidates: [
1305
+ "mutedText",
1306
+ "secondary",
1307
+ ON_BACKGROUND
1308
+ ],
1309
+ inheritedBackground: false
1310
+ },
1311
+ "accent-band": {
1312
+ backgroundCandidates: [
1313
+ "accent",
1314
+ "primary",
1315
+ "secondary"
1316
+ ],
1317
+ headingCandidates: [
1318
+ ON_BACKGROUND,
1319
+ "primaryForeground",
1320
+ "background",
1321
+ "surface",
1322
+ "neutral-50",
1323
+ "neutral-950"
1324
+ ],
1325
+ textCandidates: [
1326
+ ON_BACKGROUND,
1327
+ "primaryForeground",
1328
+ "background",
1329
+ "surface",
1330
+ "neutral-50",
1331
+ "neutral-950"
1332
+ ],
1333
+ linkCandidates: [
1334
+ ON_BACKGROUND,
1335
+ "primaryForeground",
1336
+ "background",
1337
+ "surface",
1338
+ "neutral-50",
1339
+ "neutral-950"
1340
+ ],
1341
+ supportingCandidates: [
1342
+ ON_BACKGROUND,
1343
+ "primaryForeground",
1344
+ "background",
1345
+ "surface"
1346
+ ],
1347
+ inheritedBackground: false
1348
+ },
1349
+ "brand-depth-band": {
1350
+ backgroundCandidates: [
1351
+ "primary-800",
1352
+ "primary-900",
1353
+ "primary-700",
1354
+ "primary"
1355
+ ],
1356
+ headingCandidates: [
1357
+ ON_BACKGROUND,
1358
+ "primaryForeground",
1359
+ "background",
1360
+ "surface",
1361
+ "neutral-50",
1362
+ "neutral-950"
1363
+ ],
1364
+ textCandidates: [
1365
+ ON_BACKGROUND,
1366
+ "primaryForeground",
1367
+ "background",
1368
+ "surface",
1369
+ "neutral-50",
1370
+ "neutral-950"
1371
+ ],
1372
+ linkCandidates: [
1373
+ ON_BACKGROUND,
1374
+ "primaryForeground",
1375
+ "background",
1376
+ "surface",
1377
+ "neutral-50",
1378
+ "neutral-950"
1379
+ ],
1380
+ supportingCandidates: [
1381
+ ON_BACKGROUND,
1382
+ "primaryForeground",
1383
+ "background",
1384
+ "surface"
1385
+ ],
1386
+ inheritedBackground: false
1387
+ }
1388
+ };
1389
+ const missingBackgroundTokens = {
1390
+ background: "#ffffff",
1391
+ foreground: "#000000"
1392
+ };
1393
+ /** Keep every successful legacy recipe; only exhausted candidates need neutral ink. */
1394
+ function resolveAccessibleSurfaceRecipe(input) {
1395
+ const result = tryAccessibleSurfaceRecipe(input);
1396
+ if (result.kind === "resolved-accessible-surface") return result;
1397
+ const recipe = surfaceRecipes[input.surface];
1398
+ const token = recipe.backgroundCandidates.find((candidate) => resolveConcreteColorHex(candidate, input.palette) !== null);
1399
+ const hex = token ? resolveConcreteColorHex(token, input.palette) : null;
1400
+ if (!token || !hex) return result;
1401
+ const ink = pickBlackOrWhiteTextColor(hex);
1402
+ const foreground = (role) => ({
1403
+ kind: "safe-token",
1404
+ role,
1405
+ token: asAccessibleSurfaceToken(ink),
1406
+ hex: ink,
1407
+ contrastRatio: contrastRatio(ink, hex)
1408
+ });
1409
+ return {
1410
+ kind: "resolved-accessible-surface",
1411
+ surface: input.surface,
1412
+ background: {
1413
+ token: asAccessibleSurfaceToken(token),
1414
+ hex,
1415
+ inherited: recipe.inheritedBackground
1416
+ },
1417
+ heading: {
1418
+ ...foreground("heading"),
1419
+ role: "heading"
1420
+ },
1421
+ text: {
1422
+ ...foreground("text"),
1423
+ role: "text"
1424
+ },
1425
+ link: {
1426
+ ...foreground("link"),
1427
+ role: "link"
1428
+ },
1429
+ supporting: foreground("supporting"),
1430
+ rejectedCandidates: result.rejectedCandidates
1431
+ };
1432
+ }
1433
+ function tryAccessibleSurfaceRecipe(input) {
1434
+ const rejectedCandidates = [];
1435
+ const recipe = surfaceRecipes[input.surface];
1436
+ const threshold = contrastThresholdByPolicy[input.policy ?? "body-aa"];
1437
+ for (const backgroundToken of recipe.backgroundCandidates) {
1438
+ const backgroundHex = readPaletteHex(input.palette, backgroundToken);
1439
+ if (!backgroundHex) {
1440
+ rejectedCandidates.push({
1441
+ kind: "background-candidate",
1442
+ token: backgroundToken,
1443
+ reason: "missing-token"
1444
+ });
1445
+ continue;
1446
+ }
1447
+ const heading = resolveRequiredForeground({
1448
+ role: "heading",
1449
+ candidates: recipe.headingCandidates,
1450
+ backgroundToken,
1451
+ backgroundHex,
1452
+ palette: input.palette,
1453
+ threshold,
1454
+ rejectedCandidates
1455
+ });
1456
+ const text = resolveRequiredForeground({
1457
+ role: "text",
1458
+ candidates: recipe.textCandidates,
1459
+ backgroundToken,
1460
+ backgroundHex,
1461
+ palette: input.palette,
1462
+ threshold,
1463
+ rejectedCandidates
1464
+ });
1465
+ const link = resolveRequiredForeground({
1466
+ role: "link",
1467
+ candidates: recipe.linkCandidates,
1468
+ backgroundToken,
1469
+ backgroundHex,
1470
+ palette: input.palette,
1471
+ threshold,
1472
+ rejectedCandidates
1473
+ });
1474
+ if (!heading || !text || !link) continue;
1475
+ const supporting = resolveSupportingForeground({
1476
+ candidates: recipe.supportingCandidates,
1477
+ backgroundToken,
1478
+ backgroundHex,
1479
+ text,
1480
+ palette: input.palette,
1481
+ threshold,
1482
+ rejectedCandidates
1483
+ });
1484
+ return {
1485
+ kind: "resolved-accessible-surface",
1486
+ surface: input.surface,
1487
+ background: {
1488
+ token: asAccessibleSurfaceToken(backgroundToken),
1489
+ hex: backgroundHex,
1490
+ inherited: recipe.inheritedBackground
1491
+ },
1492
+ heading,
1493
+ text,
1494
+ link,
1495
+ supporting,
1496
+ rejectedCandidates
1497
+ };
1498
+ }
1499
+ return {
1500
+ kind: "accessible-surface-resolution-failure",
1501
+ surface: input.surface,
1502
+ reason: surfaceResolutionFailureReason(rejectedCandidates),
1503
+ rejectedCandidates
1504
+ };
1505
+ }
1506
+ function resolveRequiredForeground(input) {
1507
+ return resolveSafeToken({
1508
+ role: input.role,
1509
+ candidates: input.candidates,
1510
+ backgroundToken: input.backgroundToken,
1511
+ backgroundHex: input.backgroundHex,
1512
+ palette: input.palette,
1513
+ threshold: input.threshold,
1514
+ rejectedCandidates: input.rejectedCandidates
1515
+ });
1516
+ }
1517
+ function resolveSupportingForeground(input) {
1518
+ const resolved = resolveSafeToken({
1519
+ role: "supporting",
1520
+ candidates: input.candidates,
1521
+ backgroundToken: input.backgroundToken,
1522
+ backgroundHex: input.backgroundHex,
1523
+ palette: input.palette,
1524
+ threshold: input.threshold,
1525
+ rejectedCandidates: input.rejectedCandidates
1526
+ });
1527
+ if (resolved) return resolved;
1528
+ return {
1529
+ kind: "fallback-to-text",
1530
+ role: "supporting",
1531
+ token: input.text.token,
1532
+ hex: input.text.hex,
1533
+ contrastRatio: input.text.contrastRatio,
1534
+ reason: "supporting-token-unsafe"
1535
+ };
1536
+ }
1537
+ function resolveSafeToken(input) {
1538
+ for (const candidate of expandForegroundCandidates(input.candidates, input.backgroundToken)) {
1539
+ const foregroundHex = readPaletteHex(input.palette, candidate);
1540
+ if (!foregroundHex) {
1541
+ input.rejectedCandidates.push({
1542
+ kind: "foreground-candidate",
1543
+ role: input.role,
1544
+ token: candidate,
1545
+ reason: "missing-token"
1546
+ });
1547
+ continue;
1548
+ }
1549
+ const ratio = contrastRatio(foregroundHex, input.backgroundHex);
1550
+ if (ratio < input.threshold) {
1551
+ input.rejectedCandidates.push({
1552
+ kind: "foreground-candidate",
1553
+ role: input.role,
1554
+ token: candidate,
1555
+ reason: "contrast-too-low",
1556
+ contrastRatio: ratio
1557
+ });
1558
+ continue;
1559
+ }
1560
+ return {
1561
+ kind: "safe-token",
1562
+ role: input.role,
1563
+ token: asAccessibleSurfaceToken(candidate),
1564
+ hex: foregroundHex,
1565
+ contrastRatio: ratio
1566
+ };
1567
+ }
1568
+ return null;
1569
+ }
1570
+ function expandForegroundCandidates(candidates, backgroundToken) {
1571
+ const seen = /* @__PURE__ */ new Set();
1572
+ const expanded = [];
1573
+ for (const candidate of candidates) {
1574
+ const token = expandForegroundCandidate(candidate, backgroundToken);
1575
+ if (seen.has(token)) continue;
1576
+ seen.add(token);
1577
+ expanded.push(token);
1578
+ }
1579
+ return expanded;
1580
+ }
1581
+ function expandForegroundCandidate(candidate, backgroundToken) {
1582
+ if (typeof candidate === "string") return candidate;
1583
+ switch (candidate.kind) {
1584
+ case "on-background": return onColorTokenName(backgroundToken);
1585
+ }
1586
+ }
1587
+ function readPaletteHex(palette, token) {
1588
+ const value = palette[token];
1589
+ return typeof value === "string" && value.trim().length > 0 ? value : null;
1590
+ }
1591
+ function asAccessibleSurfaceToken(token) {
1592
+ if (token.length === 0) throw new Error("AccessibleSurfaceToken must be non-empty.");
1593
+ return token;
1594
+ }
1595
+ function surfaceResolutionFailureReason(rejectedCandidates) {
1596
+ return rejectedCandidates.some((candidate) => candidate.kind === "foreground-candidate") ? "no-safe-foreground-candidate" : "no-background-candidate";
1597
+ }
1598
+ function missingBackgroundSurface(input) {
1599
+ const contrast = contrastRatio(missingBackgroundTokens.foreground, missingBackgroundTokens.background);
1600
+ const foreground = {
1601
+ kind: "safe-token",
1602
+ token: asAccessibleSurfaceToken(missingBackgroundTokens.foreground),
1603
+ hex: missingBackgroundTokens.foreground,
1604
+ contrastRatio: contrast
1605
+ };
1606
+ return {
1607
+ kind: "resolved-accessible-surface",
1608
+ surface: input.surface,
1609
+ background: {
1610
+ token: asAccessibleSurfaceToken(missingBackgroundTokens.background),
1611
+ hex: missingBackgroundTokens.background,
1612
+ inherited: false
1613
+ },
1614
+ heading: {
1615
+ ...foreground,
1616
+ role: "heading"
1617
+ },
1618
+ text: {
1619
+ ...foreground,
1620
+ role: "text"
1621
+ },
1622
+ link: {
1623
+ ...foreground,
1624
+ role: "link"
1625
+ },
1626
+ supporting: {
1627
+ ...foreground,
1628
+ role: "supporting"
1629
+ },
1630
+ rejectedCandidates: input.rejectedCandidates
1631
+ };
1632
+ }
1633
+ const resolvedSurfaceBrand = Symbol("ResolvedSurface");
1634
+ const surfaceOwners = /* @__PURE__ */ new WeakSet();
1635
+ const preparedIndexOwners = /* @__PURE__ */ new WeakSet();
1636
+ const surfaceTransports = /* @__PURE__ */ new WeakMap();
1637
+ const ownedRevisionInputs = /* @__PURE__ */ new WeakMap();
1638
+ const revisionOwners = /* @__PURE__ */ new WeakMap();
1639
+ const surfaceRevisionOwners = /* @__PURE__ */ new WeakMap();
1640
+ function ownSurfaceRevision(context) {
1641
+ if (!ownedRevisionInputs.get(context.palette)?.has(context.buttonSystem)) {
1642
+ const revision = ownedThemeSnapshot({
1643
+ palette: context.palette,
1644
+ buttonSystem: context.buttonSystem
1645
+ });
1646
+ registerOwnedRevisionInputs(revision);
1647
+ surfaceRevisionOwners.set(revision, { revision });
1648
+ revisionOwners.set(revision.palette, /* @__PURE__ */ new Map([[revision.buttonSystem, revision]]));
1649
+ return revision;
1650
+ }
1651
+ const revisions = revisionOwners.get(context.palette) ?? /* @__PURE__ */ new Map();
1652
+ const existing = revisions.get(context.buttonSystem);
1653
+ if (existing) return existing;
1654
+ const revision = Object.freeze({
1655
+ palette: context.palette,
1656
+ buttonSystem: context.buttonSystem
1657
+ });
1658
+ surfaceRevisionOwners.set(revision, { revision });
1659
+ revisions.set(context.buttonSystem, revision);
1660
+ revisionOwners.set(context.palette, revisions);
1661
+ return revision;
1662
+ }
1663
+ /** Local computation keeps its colour index; transport references only the owning revision inputs. */
1664
+ function surfaceTransportContext(context) {
1665
+ const revision = ownSurfaceRevision(context);
1666
+ const result = Object.freeze({
1667
+ ...revision,
1668
+ colourIndex: context.colourIndex,
1669
+ solvedInks: context.solvedInks
1670
+ });
1671
+ const preparedSurfaces = matchingPreparedSurfaceIndex(preparedSurfaceIndexFor(context), result);
1672
+ surfaceRevisionOwners.set(result, {
1673
+ revision,
1674
+ preparedSurfaces
1675
+ });
1676
+ return result;
1677
+ }
1678
+ /** Called only after copying and recursively freezing owner inputs. */
1679
+ function registerOwnedRevisionInputs(context) {
1680
+ const buttons = ownedRevisionInputs.get(context.palette) ?? /* @__PURE__ */ new Set();
1681
+ buttons.add(context.buttonSystem);
1682
+ ownedRevisionInputs.set(context.palette, buttons);
1683
+ }
1684
+ function isResolvedSurface(value) {
1685
+ return typeof value === "object" && value !== null && surfaceOwners.has(value) && "kind" in value && (value.kind === "owned" || value.kind === "inherit");
1686
+ }
1687
+ /** Runtime serializers reject copies and forged structural objects, too. */
1688
+ function requireResolvedSurface(value) {
1689
+ if (!isResolvedSurface(value)) throw new Error("Surface must be produced by resolveSurface");
1690
+ }
1691
+ function resolveSurface(spec, context) {
1692
+ return spec.kind === "section" ? resolveSectionSurface(spec.background, context) : preparedSurfaceValue(spec, context) ?? certifySurface(spec, context);
1693
+ }
1694
+ function matchingPreparedSurfaceIndex(index, context) {
1695
+ return index && preparedIndexOwners.has(index) && index.palette === context.palette && index.buttonSystem === context.buttonSystem && index.colourIndex === context.colourIndex ? index : void 0;
1696
+ }
1697
+ function preparedSurfaceIndexFor(context) {
1698
+ return matchingPreparedSurfaceIndex(context.preparedSurfaces ?? surfaceRevisionOwners.get(context)?.preparedSurfaces, context);
1699
+ }
1700
+ function preparedSurfaceValue(spec, context) {
1701
+ return preparedSurfaceIndexFor(context)?.values[surfaceResolutionKey(spec, context)];
1702
+ }
1703
+ function surfaceResolutionKey(spec, context) {
1704
+ const declaration = spec.kind === "tint" ? {
1705
+ ...spec,
1706
+ opacity: String(spec.opacity)
1707
+ } : spec;
1708
+ return JSON.stringify([
1709
+ declaration,
1710
+ context.linkHoverToken,
1711
+ context.foreground,
1712
+ context.compositeBase,
1713
+ context.buttonContext,
1714
+ context.solvedInks
1715
+ ]);
1716
+ }
1717
+ function resolveSurfaceSpec(spec, context) {
1718
+ switch (spec.kind) {
1719
+ case "recipe": return resolveRecipeSurface(spec.intent, context);
1720
+ case "paint": return spec.paint.kind === "transparent" ? { kind: "inherit" } : resolveOwnedSurface(spec.paint, context);
1721
+ case "token": return resolveDeclaredSolidSurface({
1722
+ kind: "solid",
1723
+ token: spec.token
1724
+ }, {
1725
+ ...context,
1726
+ buttonContext: surfaceButtonRequest(spec, context),
1727
+ ...spec.foreground ? { foreground: {
1728
+ ...context.foreground,
1729
+ ...spec.foreground
1730
+ } } : {}
1731
+ });
1732
+ case "tint": return resolveTintSurface(spec, context);
1733
+ }
1734
+ }
1735
+ function resolveRecipeSurface(intent, context) {
1736
+ const result = resolveAccessibleSurfaceRecipe({
1737
+ surface: intent,
1738
+ palette: context.palette
1739
+ });
1740
+ const recipe = result.kind === "resolved-accessible-surface" ? result : missingBackgroundSurface({
1741
+ surface: intent,
1742
+ rejectedCandidates: result.rejectedCandidates
1743
+ });
1744
+ if (recipe.background.inherited) return { kind: "inherit" };
1745
+ return resolveDeclaredSolidSurface({
1746
+ kind: "solid",
1747
+ token: recipe.background.token
1748
+ }, {
1749
+ ...context,
1750
+ foreground: recipeForegroundCandidates(recipe, context)
1751
+ });
1752
+ }
1753
+ /** Style rules replace recipe candidates before the shared foreground check. */
1754
+ function recipeForegroundCandidates(recipe, context) {
1755
+ const candidates = context.foreground ?? {};
1756
+ return {
1757
+ text: candidates.text ?? recipe.text.token,
1758
+ heading: candidates.heading ?? recipe.heading.token,
1759
+ link: candidates.link ?? recipe.link.token,
1760
+ supporting: candidates.supporting ?? recipe.supporting.token,
1761
+ linkHover: candidates.linkHover ?? context.linkHoverToken
1762
+ };
1763
+ }
1764
+ /** Declared grounds are parsed once; legacy stored paints use the unmeasured value arm. */
1765
+ function resolveDeclaredSolidSurface(paint, context) {
1766
+ return resolveOwnedSurface(paint, context, hexColorSchema.parse(resolveOpaqueSurfaceHex(paint.token, context.palette, context.compositeBase)));
1767
+ }
1768
+ function resolveOwnedSurface(paint, context, measuredBackdrop) {
1769
+ const resolved = resolveOwnedForeground(paint, context, measuredBackdrop);
1770
+ const decision = {
1771
+ kind: "owned",
1772
+ foreground: ownedForegroundRoles(resolved, paint.foregroundToken ?? "text", context.foreground),
1773
+ inks: ownedInkPublication(resolved, context),
1774
+ decorations: surfaceDecorationColors(resolved, context.palette),
1775
+ hoverDecoration: resolved.kind === "known" ? resolved.hoverDecoration : "underline"
1776
+ };
1777
+ const primaryButton = surfaceButtonRequest({
1778
+ kind: "paint",
1779
+ paint
1780
+ }, context)?.primary;
1781
+ if (paint.kind === "solid" && resolved.kind === "known" && resolved.provenance.kind === "measured") return {
1782
+ ...decision,
1783
+ paint,
1784
+ foreground: resolved.roles,
1785
+ ...primaryButton ? { primaryButton } : {},
1786
+ contrast: surfaceContrast(resolved.roles, resolved.provenance.backdropHex, context.palette, context.colourIndex)
1787
+ };
1788
+ const buttonContext = surfaceButtons(paint, resolved.kind === "known" ? resolved.roles.link : void 0, primaryButton, context);
1789
+ return paint.kind === "gradient" ? {
1790
+ ...decision,
1791
+ paint,
1792
+ contrast: { kind: "unmeasured" },
1793
+ buttonContext
1794
+ } : {
1795
+ ...decision,
1796
+ paint,
1797
+ contrast: {
1798
+ kind: "unmeasured",
1799
+ reason: "legacy-unresolvable-solid",
1800
+ source: "paint"
1801
+ },
1802
+ buttonContext
1803
+ };
1804
+ }
1805
+ /** A solid paint is measured against its own backdrop when it's known, otherwise over the composite base. */
1806
+ function resolveOwnedForeground(paint, context, measuredBackdrop) {
1807
+ const textColor = paint.foregroundToken ?? "text";
1808
+ const candidates = {
1809
+ linkHover: context.linkHoverToken,
1810
+ ...context.foreground
1811
+ };
1812
+ if (paint.kind === "gradient") return resolveSurfaceForeground({
1813
+ type: "gradient",
1814
+ textColor
1815
+ }, context.palette, candidates, { compositeBase: context.compositeBase });
1816
+ const background = {
1817
+ type: "color",
1818
+ color: paint.token,
1819
+ textColor
1820
+ };
1821
+ return measuredBackdrop ? resolveSurfaceForeground(background, context.palette, candidates, { measuredBackdrop }) : resolveSurfaceForeground(background, context.palette, candidates, { compositeBase: context.compositeBase });
1822
+ }
1823
+ /** A paint the element owns but that resolves as inherited (an empty token) still blocks outer inks. */
1824
+ function ownedInkPublication(resolved, context) {
1825
+ const publication = surfaceInkPublication(resolved, context.solvedInks ?? "withhold");
1826
+ return publication.kind === "none" ? { kind: "reset" } : publication;
1827
+ }
1828
+ /** Unprovable legacy paint retains its declared foreground instead of inventing one. */
1829
+ function ownedForegroundRoles(resolved, text, candidates) {
1830
+ if (resolved.kind === "known") return resolved.roles;
1831
+ const candidate = candidates ?? {};
1832
+ const fallback = candidate.text ?? text;
1833
+ return completeSurfaceForegrounds({
1834
+ text: fallback,
1835
+ heading: candidate.heading ?? void 0,
1836
+ link: candidate.link ?? void 0,
1837
+ supporting: candidate.supporting ?? void 0,
1838
+ muted: fallback
1839
+ });
1840
+ }
1841
+ function surfaceButtons(paint, link, primaryToken, context, backgroundSamples) {
1842
+ return resolveSurfaceButtonContext({
1843
+ surface: paint.kind === "solid" ? {
1844
+ kind: "solid",
1845
+ color: paint.token,
1846
+ composited: false,
1847
+ foreground: link,
1848
+ ...backgroundSamples ? { backgroundSamples } : {}
1849
+ } : { kind: "gradient" },
1850
+ palette: context.palette,
1851
+ colourIndex: context.colourIndex,
1852
+ buttonSystem: context.buttonSystem,
1853
+ fallbackToken: context.compositeBase,
1854
+ primaryToken,
1855
+ withoutButtonSystem: "reset"
1856
+ });
1857
+ }
1858
+ /** Buttons on a certified paint use the link ink the certificate kept, which may be the black/white fallback. */
1859
+ function withCertifiedButtons(decision, context) {
1860
+ const { primaryButton, ...certified } = decision;
1861
+ return {
1862
+ ...certified,
1863
+ buttonContext: surfaceButtons(decision.paint, decision.foreground.link, primaryButton, context, tintGroundSamples(decision, context))
1864
+ };
1865
+ }
1866
+ /** A radial tint's grounds besides its painted end, so its buttons are judged on every sample. */
1867
+ function tintGroundSamples(decision, context) {
1868
+ if (decision.tintBase === void 0) return void 0;
1869
+ const [first, ...rest] = surfaceBackdrops(decision, context).slice(0, -1);
1870
+ return first === void 0 ? void 0 : [first, ...rest];
1871
+ }
1872
+ function surfaceContrast(roles, backdrop, palette, colourIndex) {
1873
+ const ratio = (token) => contrastRatio(resolveOpaqueSurfaceHex(token, palette, backdrop) ?? backdrop, backdrop, colourIndex);
1874
+ return {
1875
+ kind: "measured",
1876
+ ratios: {
1877
+ text: ratio(roles.text),
1878
+ heading: ratio(roles.heading),
1879
+ link: ratio(roles.link),
1880
+ linkHover: ratio(roles.linkHover),
1881
+ supporting: ratio(roles.supporting),
1882
+ muted: ratio(roles.muted)
1883
+ }
1884
+ };
1885
+ }
1886
+ /** Runtime backgrounds retain authored media, compositing and unknown foregrounds. */
1887
+ function resolveSectionSurface(background, context) {
1888
+ const foreground = background === null ? { kind: "inherits" } : resolveSurfaceForeground(background, context.palette, {
1889
+ linkHover: context.linkHoverToken,
1890
+ ...context.foreground
1891
+ }, { compositeBase: context.compositeBase });
1892
+ const surface = background === null ? { kind: "inherit" } : background.type === "color" ? {
1893
+ kind: "solid",
1894
+ color: background.color,
1895
+ composited: false,
1896
+ foreground: foreground.kind === "known" ? foreground.roles.link : void 0
1897
+ } : background.type === "gradient" ? { kind: "gradient" } : { kind: "image" };
1898
+ const revision = ownSurfaceRevision(context);
1899
+ const buttonContext = resolveSurfaceButtonContext({
1900
+ surface,
1901
+ palette: revision.palette,
1902
+ buttonSystem: revision.buttonSystem,
1903
+ primaryToken: sectionPrimaryButtonToken(background, context),
1904
+ fallbackToken: context.compositeBase,
1905
+ withoutButtonSystem: "inherit"
1906
+ });
1907
+ const result = {
1908
+ kind: "section",
1909
+ foreground,
1910
+ inks: surfaceInkPublication(foreground, context.solvedInks ?? "withhold"),
1911
+ buttonStyles: buttonContext.styles,
1912
+ buttonContext,
1913
+ proof: sectionProof(background, foreground),
1914
+ revision,
1915
+ textPolicy: surfaceTextPolicy,
1916
+ [resolvedSurfaceBrand]: true
1917
+ };
1918
+ Object.defineProperties(result, {
1919
+ buttonContext: { enumerable: false },
1920
+ proof: { enumerable: false },
1921
+ revision: { enumerable: false },
1922
+ textPolicy: { enumerable: false }
1923
+ });
1924
+ return freezeOwnedThemeValue(result);
1925
+ }
1926
+ function sectionPrimaryButtonToken(background, context) {
1927
+ if (background?.type !== "color" || typeof background.color !== "string") return void 0;
1928
+ return context.buttonSystem?.surfaceContexts?.[background.color]?.primary;
1929
+ }
1930
+ function surfaceDecorationColors(foreground, palette) {
1931
+ if (foreground.kind !== "known" || foreground.provenance.kind !== "measured") return void 0;
1932
+ const text = resolveConcreteColorHex(foreground.roles.text, palette);
1933
+ if (text === null) return void 0;
1934
+ return deriveSurfaceDecorationColors(foreground.provenance.backdropHex, text, palette.markSource ?? palette.accent ?? text);
1935
+ }
1936
+ /** Composite the declared palette tint before checking every foreground role. */
1937
+ function resolveTintSurface(spec, context) {
1938
+ const base = resolveSurface({
1939
+ kind: "token",
1940
+ token: spec.base
1941
+ }, context);
1942
+ const source = tintSource(spec.source, base, context.palette);
1943
+ const token = source ? resolveOpaqueSurfaceHex(`${source}/${spec.opacity}`, context.palette, spec.base) : null;
1944
+ const hex = source ? resolveConcreteColorHex(source, context.palette) : null;
1945
+ const tinted = token ?? (hex ? resolveOpaqueSurfaceHex(hexToRgba(hex, spec.opacity / 100), context.palette, spec.base) : null);
1946
+ if (!tinted) throw new Error(`Cannot derive tint on ${spec.base}`);
1947
+ const solid = resolveDeclaredSolidSurface({
1948
+ kind: "solid",
1949
+ token: tinted
1950
+ }, {
1951
+ ...context,
1952
+ buttonContext: surfaceButtonRequest(spec, context),
1953
+ foreground: base.foreground
1954
+ });
1955
+ return spec.gradient === "radial" ? {
1956
+ ...solid,
1957
+ inks: { kind: "reset" },
1958
+ tintBase: spec.base
1959
+ } : solid;
1960
+ }
1961
+ /**
1962
+ * The button colour a surface asks for, which it also hands to what is painted on it. An explicit request
1963
+ * wins; otherwise a paint asks for its own button context, and a shade for the context of the paint it shades.
1964
+ * The request is checked anew on every surface that receives it.
1965
+ */
1966
+ function surfaceButtonRequest(spec, context) {
1967
+ const forToken = (token) => context.buttonContext ?? context.buttonSystem?.surfaceContexts?.[token];
1968
+ switch (spec.kind) {
1969
+ case "token": return spec.buttonContext ?? forToken(spec.token);
1970
+ case "tint": return spec.source === "shade" ? forToken(spec.base) : context.buttonContext;
1971
+ case "paint": return spec.paint.kind === "solid" ? forToken(spec.paint.token) : context.buttonContext;
1972
+ case "recipe": return context.buttonContext;
1973
+ }
1974
+ }
1975
+ /** Shade direction belongs to the palette, while the tint's base is the actual paint. */
1976
+ function tintSource(source, base, palette) {
1977
+ switch (source) {
1978
+ case "text": return base.foreground.text;
1979
+ case "mark": return base.decorations?.mark;
1980
+ case "shade": {
1981
+ const background = resolveOpaqueSurfaceHex("background", palette, "background");
1982
+ return background && featuresFromHex(background).Y < .5 ? "#ffffff" : "#000000";
1983
+ }
1984
+ }
1985
+ }
1986
+ function hexToRgba(hex, alpha) {
1987
+ const { r, g, b } = hexToRgb(hex);
1988
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
1989
+ }
1990
+ const foregroundInputSchema = z.object({
1991
+ text: z.string().nullable().optional(),
1992
+ heading: z.string().nullable().optional(),
1993
+ link: z.string().nullable().optional(),
1994
+ linkHover: z.string().nullable().optional(),
1995
+ supporting: z.string().nullable().optional()
1996
+ });
1997
+ const paintInputSchema = z.discriminatedUnion("kind", [
1998
+ z.object({
1999
+ kind: z.literal("solid"),
2000
+ token: z.string(),
2001
+ foregroundToken: z.string().optional()
2002
+ }),
2003
+ z.object({
2004
+ kind: z.literal("gradient"),
2005
+ foregroundToken: z.string().optional()
2006
+ }),
2007
+ z.object({ kind: z.literal("transparent") })
2008
+ ]);
2009
+ const buttonInputSchema = z.object({ primary: opaqueButtonColourTokenSchema });
2010
+ const solvedInksSchema = z.enum(["publish", "withhold"]);
2011
+ const surfaceSpecSchema = z.discriminatedUnion("kind", [
2012
+ z.object({
2013
+ kind: z.literal("recipe"),
2014
+ intent: z.enum([
2015
+ "base",
2016
+ "muted-band",
2017
+ "accent-band",
2018
+ "brand-depth-band"
2019
+ ])
2020
+ }),
2021
+ z.object({
2022
+ kind: z.literal("paint"),
2023
+ paint: paintInputSchema
2024
+ }),
2025
+ z.object({
2026
+ kind: z.literal("token"),
2027
+ token: z.string(),
2028
+ foreground: foregroundInputSchema.optional(),
2029
+ buttonContext: buttonInputSchema.optional()
2030
+ }),
2031
+ z.object({
2032
+ kind: z.literal("tint"),
2033
+ base: z.string(),
2034
+ source: z.enum([
2035
+ "text",
2036
+ "mark",
2037
+ "shade"
2038
+ ]),
2039
+ opacity: z.number().finite(),
2040
+ gradient: z.literal("radial").optional()
2041
+ })
2042
+ ]);
2043
+ const surfaceTransportSchema = z.object({ $surface: z.object({
2044
+ spec: surfaceSpecSchema,
2045
+ context: z.object({
2046
+ palette: z.record(z.string(), z.string()),
2047
+ buttonSystem: buttonSystemSchema.optional(),
2048
+ foreground: foregroundInputSchema.optional(),
2049
+ linkHoverToken: z.string().optional(),
2050
+ compositeBase: z.string().optional(),
2051
+ buttonContext: buttonInputSchema.optional(),
2052
+ solvedInks: solvedInksSchema.optional()
2053
+ })
2054
+ }) });
2055
+ /** Deserialised output is never evidence: parse the inputs and rerun their owner. */
2056
+ function parseResolvedSurface(value) {
2057
+ return resolveTransportedSurface(value);
2058
+ }
2059
+ function resolveTransportedSurface(value, solvedInks) {
2060
+ if (isResolvedSurface(value) && solvedInks === void 0) return value;
2061
+ const { spec, context } = isResolvedSurface(value) ? serializeResolvedSurface(value).$surface : surfaceTransportSchema.parse(value).$surface;
2062
+ return resolveSurface(spec, {
2063
+ ...context,
2064
+ buttonSystem: context.buttonSystem,
2065
+ solvedInks: solvedInks ?? context.solvedInks
2066
+ });
2067
+ }
2068
+ /** Wire only the owner inputs; parsed CSS/results are recomputed, never trusted. */
2069
+ function serializeResolvedSurface(surface) {
2070
+ requireResolvedSurface(surface);
2071
+ const inputs = surfaceTransports.get(surface);
2072
+ if (!inputs) throw new Error("Missing surface inputs");
2073
+ return { $surface: inputs };
2074
+ }
2075
+ function certifySurface(spec, context) {
2076
+ const revision = ownSurfaceRevision(context);
2077
+ const inputs = {
2078
+ spec: ownedThemeSnapshot(spec),
2079
+ context: Object.freeze({
2080
+ ...revision,
2081
+ ...ownedThemeSnapshot({
2082
+ foreground: context.foreground,
2083
+ linkHoverToken: context.linkHoverToken,
2084
+ compositeBase: context.compositeBase,
2085
+ buttonContext: context.buttonContext,
2086
+ solvedInks: context.solvedInks
2087
+ })
2088
+ })
2089
+ };
2090
+ const decision = certifyThresholds(resolveSurfaceSpec(inputs.spec, inputs.context), inputs.context);
2091
+ const result = Object.assign(surfaceProof(decision, spec), {
2092
+ [resolvedSurfaceBrand]: true,
2093
+ revision,
2094
+ textPolicy: surfaceTextPolicy,
2095
+ $surface: inputs
2096
+ });
2097
+ Object.defineProperties(result, {
2098
+ proof: { enumerable: false },
2099
+ revision: { enumerable: false },
2100
+ textPolicy: { enumerable: false }
2101
+ });
2102
+ surfaceOwners.add(result);
2103
+ surfaceTransports.set(result, inputs);
2104
+ return freezeOwnedThemeValue(result);
2105
+ }
2106
+ function isSolidSurfaceDecision(decision) {
2107
+ return decision.kind === "owned" && decision.contrast.kind === "measured";
2108
+ }
2109
+ function isSolidInkDecision(decision) {
2110
+ return decision.kind === "owned" && decision.contrast.kind === "measured";
2111
+ }
2112
+ const TINT_SAMPLE_ALPHAS = [
2113
+ 0,
2114
+ .25,
2115
+ .5,
2116
+ .75,
2117
+ 1
2118
+ ];
2119
+ /**
2120
+ * The certificate asserts every threshold it measures, on every backdrop the
2121
+ * paint shows (each sample of a radial tint). It never throws, because owner
2122
+ * palettes are arbitrary: an ink that misses takes the black/white ink, and a
2123
+ * radial tint that no ink can clear paints flat. Buttons are derived from the
2124
+ * certified inks, so they never keep a link ink the certificate replaced, and
2125
+ * the button resolver judges them on every sample of a radial tint.
2126
+ */
2127
+ function certifyThresholds(decision, context) {
2128
+ if (!isSolidInkDecision(decision)) return decision;
2129
+ const inks = withFallbackInks(decision, context);
2130
+ if (inks) return withCertifiedButtons(inks, context);
2131
+ const { tintBase: _flattened, ...flatTint } = decision;
2132
+ const flat = withFallbackInks(flatTint, context) ?? flatTint;
2133
+ return withCertifiedButtons({
2134
+ ...flat,
2135
+ contrast: {
2136
+ ...flat.contrast,
2137
+ fallback: ["radial-tint", ...flat.contrast.fallback ?? []]
2138
+ }
2139
+ }, context);
2140
+ }
2141
+ /** Every backdrop a solid paint shows: its colour, or each sample from a radial tint's base to its paint. */
2142
+ function surfaceBackdrops(decision, context) {
2143
+ const paint = resolveOpaqueSurfaceHex(decision.paint.token, context.palette, decision.tintBase ?? context.compositeBase);
2144
+ if (!paint) return [];
2145
+ const underlay = decision.tintBase ? resolveOpaqueSurfaceHex(decision.tintBase, context.palette, "background") : null;
2146
+ return underlay ? TINT_SAMPLE_ALPHAS.map((alpha) => compositeHex(paint, alpha, underlay)) : [paint];
2147
+ }
2148
+ /** Null only when no black/white ink clears every backdrop of a radial tint. */
2149
+ function withFallbackInks(decision, context) {
2150
+ const backdrops = surfaceBackdrops(decision, context);
2151
+ const [endpoint] = backdrops.slice(-1);
2152
+ if (!endpoint) return decision;
2153
+ const certified = certifySurfaceInks({
2154
+ foreground: decision.foreground,
2155
+ mark: decision.decorations?.mark
2156
+ }, backdrops, context);
2157
+ if (!certified) return null;
2158
+ if (certified.fallback.length === 0) return decision;
2159
+ const decorations = decision.decorations && certified.mark !== void 0 ? {
2160
+ ...decision.decorations,
2161
+ mark: certified.mark
2162
+ } : decision.decorations;
2163
+ const contrast = surfaceContrast(certified.foreground, endpoint, context.palette, context.colourIndex);
2164
+ return {
2165
+ ...decision,
2166
+ foreground: certified.foreground,
2167
+ decorations,
2168
+ contrast: {
2169
+ ...contrast,
2170
+ fallback: certified.fallback
2171
+ }
2172
+ };
2173
+ }
2174
+ function surfaceProof(decision, spec) {
2175
+ if (decision.kind === "inherit") return {
2176
+ ...decision,
2177
+ proof: "inherit"
2178
+ };
2179
+ if (!isSolidSurfaceDecision(decision)) return {
2180
+ ...decision,
2181
+ proof: "unproven-media"
2182
+ };
2183
+ const proof = decision.tintBase !== void 0 ? "checked-gradient-or-scrim" : spec.kind === "tint" || /\/|rgba\(/.test(decision.paint.token) ? "checked-composited" : "checked-solid";
2184
+ return {
2185
+ ...decision,
2186
+ proof
2187
+ };
2188
+ }
2189
+ function sectionProof(background, foreground) {
2190
+ if (background === null) return "inherit";
2191
+ if (foreground.kind !== "known" || foreground.provenance.kind !== "measured") return "unproven-media";
2192
+ return /\/|rgba\(/.test(background.color ?? "") ? "checked-composited" : "checked-solid";
2193
+ }
2194
+ /** One theme revision per JSON envelope, shared by all nested Look slots. */
2195
+ function serializeSurfaceTree(value) {
2196
+ const revisions = [];
2197
+ const indices = /* @__PURE__ */ new Map();
2198
+ const revisionIndex = (revision) => {
2199
+ const index = indices.get(revision) ?? revisions.length;
2200
+ if (!indices.has(revision)) {
2201
+ indices.set(revision, index);
2202
+ revisions.push(revision);
2203
+ }
2204
+ return index;
2205
+ };
2206
+ const encode = (item) => {
2207
+ const revision = isSurfaceTreeRecord(item) ? surfaceRevisionOwners.get(item)?.revision : void 0;
2208
+ if (revision) return {
2209
+ $surfaceRevision: revisionIndex(revision),
2210
+ solvedInks: isSurfaceTreeRecord(item) ? item.solvedInks : void 0
2211
+ };
2212
+ if (isResolvedSurface(item)) {
2213
+ const input = serializeResolvedSurface(item).$surface;
2214
+ const index = revisionIndex(item.revision);
2215
+ const { palette: _palette, buttonSystem: _buttons, ...context } = input.context;
2216
+ return { $surface: {
2217
+ spec: input.spec,
2218
+ context,
2219
+ revision: index
2220
+ } };
2221
+ }
2222
+ return mapSurfaceTreeChildren(item, encode);
2223
+ };
2224
+ const encoded = encode(value);
2225
+ return revisions.length === 0 ? encoded : { [SURFACE_TRANSPORT_KEY]: {
2226
+ revisions,
2227
+ value: encoded
2228
+ } };
2229
+ }
2230
+ const surfaceEnvelopeSchema = z.object({ [SURFACE_TRANSPORT_KEY]: z.object({
2231
+ revisions: z.array(z.object({
2232
+ palette: z.record(z.string(), z.string()),
2233
+ buttonSystem: buttonSystemSchema.optional()
2234
+ })),
2235
+ value: z.unknown()
2236
+ }) });
2237
+ const surfaceReferenceSchema = z.object({ $surface: z.object({
2238
+ spec: surfaceSpecSchema,
2239
+ revision: z.number().int().nonnegative(),
2240
+ context: z.object({
2241
+ foreground: foregroundInputSchema.optional(),
2242
+ linkHoverToken: z.string().optional(),
2243
+ compositeBase: z.string().optional(),
2244
+ buttonContext: buttonInputSchema.optional(),
2245
+ solvedInks: solvedInksSchema.optional()
2246
+ })
2247
+ }) });
2248
+ const surfaceRevisionReferenceSchema = z.object({
2249
+ $surfaceRevision: z.number().int().nonnegative(),
2250
+ solvedInks: solvedInksSchema.optional()
2251
+ });
2252
+ /** Recreate owner results before any island's ordinary schema consumes them. */
2253
+ function parseSurfaceTree(value, solvedInks) {
2254
+ if (isResolvedSurface(value)) return resolveTransportedSurface(value, solvedInks);
2255
+ const revision = isSurfaceTreeRecord(value) ? surfaceRevisionOwners.get(value)?.revision : void 0;
2256
+ if (revision) return solvedInks === void 0 ? value : surfaceTransportContext({
2257
+ ...revision,
2258
+ solvedInks
2259
+ });
2260
+ if (!isSurfaceTreeRecord(value) || !("$surfaceTransport" in value)) return mapSurfaceTreeChildren(value, (item) => parseSurfaceTree(item, solvedInks));
2261
+ const envelope = surfaceEnvelopeSchema.parse(value)[SURFACE_TRANSPORT_KEY];
2262
+ const revisions = envelope.revisions.map((revision) => {
2263
+ const owned = ownedThemeSnapshot({
2264
+ palette: revision.palette,
2265
+ buttonSystem: revision.buttonSystem
2266
+ });
2267
+ registerOwnedRevisionInputs(owned);
2268
+ return ownSurfaceRevision(owned);
2269
+ });
2270
+ const decode = (item) => {
2271
+ if (isSurfaceTreeRecord(item) && "$surfaceRevision" in item) {
2272
+ const reference = surfaceRevisionReferenceSchema.parse(item);
2273
+ const revision = revisions[reference.$surfaceRevision];
2274
+ if (!revision) throw new Error("Unknown surface revision");
2275
+ const policy = solvedInks ?? reference.solvedInks;
2276
+ return policy === void 0 ? revision : surfaceTransportContext({
2277
+ ...revision,
2278
+ solvedInks: policy
2279
+ });
2280
+ }
2281
+ if (isSurfaceTreeRecord(item) && "$surface" in item) {
2282
+ const request = surfaceReferenceSchema.parse(item).$surface;
2283
+ const revision = revisions[request.revision];
2284
+ if (!revision) throw new Error("Unknown surface revision");
2285
+ return resolveSurface(request.spec, {
2286
+ ...revision,
2287
+ ...request.context,
2288
+ buttonSystem: revision.buttonSystem,
2289
+ solvedInks: solvedInks ?? request.context.solvedInks
2290
+ });
2291
+ }
2292
+ return mapSurfaceTreeChildren(item, decode);
2293
+ };
2294
+ return decode(envelope.value);
2295
+ }
2296
+ function isSurfaceTreeRecord(value) {
2297
+ return typeof value === "object" && value !== null && !Array.isArray(value);
2298
+ }
2299
+ function mapSurfaceTreeChildren(value, map) {
2300
+ if (Array.isArray(value)) return value.map(map);
2301
+ if (value instanceof Date) return value;
2302
+ return isSurfaceTreeRecord(value) ? Object.fromEntries(Object.entries(value).map(([key, item]) => [key, map(item)])) : value;
2303
+ }
2304
+ //#endregion
2305
+ export { inkReference as A, mapButtonVisualAppearances as C, HOVER_TEXT_THRESHOLD as D, surfaceInkPublication as E, planForegroundHover as M, resolveConcreteColorHex as N, certifyPaint as O, resolveOpaqueSurfaceHex as P, mapButtonRoleAppearances as S, safeTokenOr as T, buttonTypographyDeclarations as _, serializeSurfaceTree as a, PUBLIC_BUTTON_ROLES as b, compositeHex as c, actionVariableFallback as d, contextualButtonSurfaceResetStyles as f, buttonStateAppearanceDeclarations as g, buttonShadow as h, resolveSurface as i, solveSurfaceInks as j, contrastThresholdByPolicy as k, gradientScrimSamples as l, buttonRadius as m, parseSurfaceTree as n, surfaceButtonRequest as o, buttonBorder as p, requireResolvedSurface as r, surfaceDecorationColors as s, parseResolvedSurface as t, scrimTone as u, materializeRuntimeButtonAppearance as v, resolveSurfaceForeground as w, defineButtonStyleRecipe as x, paddingDeclarations as y };