@riverbankcms/sdk 0.167.0 → 0.169.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.
- package/dist/_dts/{BlocksIslandsHydrator-Dgb-ptph.d.ts → BlocksIslandsHydrator-DpROiz12.d.ts} +1 -1
- package/dist/_dts/{Page-Bs3WxFgr.d.ts → Page-DHBBDRC_.d.ts} +7 -6
- package/dist/_dts/{SdkPreviewMode-DtUCsaHY.d.ts → SdkPreviewMode-CG7Qib7u.d.ts} +2 -2
- package/dist/_dts/{client-CwsI23pj.d.ts → client-MURxFla9.d.ts} +90 -418
- package/dist/_dts/{content-types-CAeP_-cV.d.ts → content-types-ClBGjxBV.d.ts} +2 -2
- package/dist/_dts/{contracts-BXHCiF-b.d.ts → contracts-CHNvzh0y.d.ts} +6 -4
- package/dist/_dts/{footerPageOutline-Bb2gbppW.d.ts → footerPageOutline-DQM934Fm.d.ts} +6 -6
- package/dist/_dts/{generatePageMetadata-DaBBDx7M.d.ts → generatePageMetadata-ConZaEqB.d.ts} +2 -2
- package/dist/_dts/{index-CS6b1B-c.d.ts → index-BaDqRekr.d.ts} +4 -4
- package/dist/_dts/{index-bDln38Hm.d.ts → index-CVB5wgbz.d.ts} +2 -2
- package/dist/_dts/{index-D7EbliE3.d.ts → index-CiR_oPYT.d.ts} +3 -3
- package/dist/_dts/{index-5_jf52sZ.d.ts → index-CovKPftP.d.ts} +2 -2
- package/dist/_dts/{index-C20yUyob.d.ts → index-DCw8LO4M.d.ts} +1 -1
- package/dist/_dts/index-DDaX-K2D.d.ts +14 -0
- package/dist/_dts/{index-DeHDwMfu.d.ts → index-rfAssXq0.d.ts} +3 -3
- package/dist/_dts/{loadContent-CTqcL7CS.d.ts → loadContent-CRLKVVDP.d.ts} +7 -7
- package/dist/_dts/previewCompiler-BVVgDSdq.d.ts +1 -0
- package/dist/_dts/{index-ChpjHK0U.d.ts → request-DeVetKBr.d.ts} +81273 -46979
- package/dist/_dts/{resolveBlockData-C3s9WMPs.d.ts → resolveBlockData-C5KYFeig.d.ts} +5 -5
- package/dist/_dts/{resolvePageContent-JPwgRxwh.d.ts → resolvePageContent-D8MZWyNO.d.ts} +2 -2
- package/dist/_dts/sdk/src/bookings/index.d.ts +2 -2
- package/dist/_dts/sdk/src/client/types.d.ts +2 -2
- package/dist/_dts/sdk/src/client.d.ts +7 -7
- package/dist/_dts/sdk/src/config/index.d.ts +6 -6
- package/dist/_dts/sdk/src/config/template-validation.d.ts +1 -1
- package/dist/_dts/sdk/src/config/validation.d.ts +1 -1
- package/dist/_dts/sdk/src/data/dataLoaderContext.d.ts +2 -2
- package/dist/_dts/sdk/src/data/resolveBlockData.d.ts +1 -1
- package/dist/_dts/sdk/src/data/types.d.ts +2 -2
- package/dist/_dts/sdk/src/index.d.ts +8 -8
- package/dist/_dts/sdk/src/manifest/index.d.ts +3 -3
- package/dist/_dts/sdk/src/metadata/index.d.ts +1 -1
- package/dist/_dts/sdk/src/navigation/index.d.ts +2 -2
- package/dist/_dts/sdk/src/next/index.d.ts +7 -7
- package/dist/_dts/sdk/src/next/middleware.d.ts +2 -2
- package/dist/_dts/sdk/src/page-converter/index.d.ts +3 -3
- package/dist/_dts/sdk/src/portal/client.d.ts +1 -1
- package/dist/_dts/sdk/src/prebuild/index.d.ts +1 -1
- package/dist/_dts/sdk/src/preview-next/before-render.d.ts +2 -2
- package/dist/_dts/sdk/src/preview-next/client/index.d.ts +2 -2
- package/dist/_dts/sdk/src/preview-next/client/runtime.d.ts +1 -1
- package/dist/_dts/sdk/src/rendering/client.d.ts +2 -2
- package/dist/_dts/sdk/src/rendering/components/pageShared.d.ts +1 -1
- package/dist/_dts/sdk/src/rendering/helpers/loadPage.d.ts +1 -1
- package/dist/_dts/sdk/src/rendering/helpers/pageRuntimeSupport.d.ts +4 -5
- package/dist/_dts/sdk/src/rendering/index.d.ts +6 -6
- package/dist/_dts/sdk/src/rendering/islands/client.d.ts +1 -1
- package/dist/_dts/sdk/src/rendering/server.d.ts +2 -2
- package/dist/_dts/sdk/src/rendering/themeAdmission.d.ts +1 -1
- package/dist/_dts/sdk/src/routing/index.d.ts +5 -5
- package/dist/_dts/sdk/src/server.d.ts +5 -5
- package/dist/_dts/sdk/src/spam-protection/index.d.ts +2 -2
- package/dist/_dts/sdk/src/theme/index.d.ts +1 -1
- package/dist/_dts/{types-BlaCuPLr.d.ts → types-B4MBlP_B.d.ts} +4 -2
- package/dist/_dts/{types-D-WElMCy.d.ts → types-Fj31kIi2.d.ts} +7 -7
- package/dist/_dts/{types-CwtTcaQP.d.ts → types-OwqfS8Gn.d.ts} +3 -3
- package/dist/_dts/{validation-Y5wD9fGK.d.ts → validation-B1Fa8o_b.d.ts} +4 -4
- package/dist/client/{BlocksIslandsHydrator-DFqkx158.mjs → BlocksIslandsHydrator-qq4Vhs7k.mjs} +21 -21
- package/dist/client/BookingMailingListNote-y3qWjnOo.mjs +957 -0
- package/dist/client/BookingQuestionFields-DjLjd0vc.mjs +359 -0
- package/dist/client/{CalendarNavigationChevron-DQwJ7BPx.mjs → CalendarNavigationChevron-VM7C2fdh.mjs} +8 -8
- package/dist/client/{CheckboxChoice-CZ-anOqV.mjs → CheckboxChoice-W_uiRgDK.mjs} +1 -1
- package/dist/client/{DemoBookingPortalAccess-DdkY86qI.mjs → DemoBookingPortalAccess-C2QCj_Ta.mjs} +68 -12
- package/dist/client/{EventCalendar.client-DAeQPV76.mjs → EventCalendar.client-DDjz7tuX.mjs} +10 -10
- package/dist/client/{EventCombined.client-Bus9R0bj.mjs → EventCombined.client-CeYbNsch.mjs} +9 -9
- package/dist/client/{EventEmbeddedCheckoutStep-D_14yqAU.mjs → EventEmbeddedCheckoutStep-Cf-HRHtb.mjs} +1 -1
- package/dist/client/{EventItem-DPBLjGwj.mjs → EventItem-B5J0IeF4.mjs} +37 -15
- package/dist/client/{EventListWeekNavigation-D6cwU82_.mjs → EventListWeekNavigation-eH04D8-V.mjs} +1 -1
- package/dist/client/{EventListing.client-Bogi_SnJ.mjs → EventListing.client-slpvrTrM.mjs} +3 -3
- package/dist/client/{EventListing.view-CEumpN7i.mjs → EventListing.view-BYBaElec.mjs} +34 -16
- package/dist/client/{EventRegistrationPayment-CIQw6vNy.mjs → EventRegistrationPayment-Do7Q0wRG.mjs} +362 -90
- package/dist/client/{LocationMapActions-BVO-qx4q.mjs → LocationMapActions-BFp2uQQQ.mjs} +2 -2
- package/dist/client/{MapDrawingSvg-CcGaFawl.mjs → MapDrawingSvg-DDWfmgpA.mjs} +1 -1
- package/dist/client/{Page-D4_H_u9V.mjs → Page-Dv9eIOGr.mjs} +4475 -1600
- package/dist/client/{ProtectedSubmitButton-8DuDw2ag.mjs → ProtectedSubmitButton-C3H26pN9.mjs} +1 -1
- package/dist/client/{StepIndicator-Dptantmg.mjs → StepIndicator-BZNUd0-v.mjs} +3 -3
- package/dist/client/{TabBarFragment-BxEGsKUx.mjs → TabBarFragment-DkVKtK5a.mjs} +1 -1
- package/dist/client/{ThemedButton-8jUc02mZ.mjs → ThemedButton-BdnEwA38.mjs} +2 -5
- package/dist/client/accessibleSurfaces-chpD4C2c.mjs +4278 -0
- package/dist/client/{accordion--EUHmEGa.mjs → accordion-BCtVxnDZ.mjs} +1 -1
- package/dist/client/{booking-form.client-BCXwOnhc.mjs → booking-form.client-Cr5G-HHO.mjs} +1323 -567
- package/dist/client/{bookingForm-sHHcdism.mjs → bookingForm-B1Fc62Sl.mjs} +9 -5
- package/dist/client/bookingQuestions-BHq83mzS.mjs +13 -0
- package/dist/client/{bookingRoute-Bqlyu5Vb.mjs → bookingRoute-D6DlxYx6.mjs} +6 -2
- package/dist/client/bookings.mjs +28 -20
- package/dist/client/{carousel-Cp9xPBFZ.mjs → carousel-DW-HgjvT.mjs} +3 -3
- package/dist/client/{carousel.client-BO7sCEpH.mjs → carousel.client-BD4DXMtI.mjs} +62 -16
- package/dist/client/{carousel.shared-DBnWEJzo.mjs → carousel.shared-BFQ3kBEw.mjs} +6 -3
- package/dist/client/{cart-CCZZC-Lq.mjs → cart-D1zWe4R7.mjs} +3 -3
- package/dist/client/{cart.client-B7JfA19I.mjs → cart.client-CIfbTLHS.mjs} +1 -1
- package/dist/client/{checkout-CipmYL4A.mjs → checkout-fDCNZ3IT.mjs} +3 -3
- package/dist/client/{checkout.client-DraalWdH.mjs → checkout.client-C4l2KjtV.mjs} +1 -1
- package/dist/client/{checkoutUrls-CYj06rX1.mjs → checkoutUrls-cWL6I-Vz.mjs} +3 -2
- package/dist/client/client.mjs +287 -63
- package/dist/client/{context-Cv3QHjAF.mjs → context-DQnTyApV.mjs} +320 -4
- package/dist/client/creditProducts-CMOmhWm2.mjs +364 -0
- package/dist/client/{cta-P2vJVTEn.mjs → cta-Bj5WHgcv.mjs} +2 -2
- package/dist/client/{dateFormatting-D8D47VT4.mjs → dateFormatting-Bv6kjUW3.mjs} +1 -1
- package/dist/client/{demoPortalMagicLink-CXWZoV-d.mjs → demoPortalMagicLink-3uVu3WgG.mjs} +1 -1
- package/dist/client/{site-styles-D56hT2u1.mjs → display-CT8KMSpH.mjs} +19832 -17912
- package/dist/client/{enhanceHeaderSection-BkAro1DJ.mjs → enhanceHeaderSection-B27KFGDv.mjs} +4 -3
- package/dist/client/{event-details.client-dLmyuPap.mjs → event-details.client-CL4Lqz2c.mjs} +1 -1
- package/dist/client/{event-registration.client-BEhC2_-Y.mjs → event-registration.client-Dj3Kyp5X.mjs} +118 -241
- package/dist/client/{eventCalendar-FBMS2Cpb.mjs → eventCalendar-DGsdSF8J.mjs} +4 -4
- package/dist/client/{eventCombined-BrBhUvGe.mjs → eventCombined-DFSVDJ3D.mjs} +4 -4
- package/dist/client/{eventDetails-C7WUrbZ2.mjs → eventDetails-DzMskXYA.mjs} +2 -2
- package/dist/client/{eventListing-Bih-BgQM.mjs → eventListing-CpFFcAUr.mjs} +4 -4
- package/dist/client/{eventRegistration-DfTlqGbl.mjs → eventRegistration-BipMUOCw.mjs} +8 -5
- package/dist/client/{form-Bw1uuiUs.mjs → form-57k2JQnm.mjs} +3 -3
- package/dist/client/{form.client-pZ-9gN33.mjs → form.client-CCl6CpRJ.mjs} +5 -5
- package/dist/client/{form.parts-PXlu6XQO.mjs → form.parts-BOJ1yDDf.mjs} +3 -3
- package/dist/client/{formatDate-DI3DP48e.mjs → formatDate-BGlhrmhF.mjs} +1 -1
- package/dist/client/gifting/client.mjs +3 -3
- package/dist/client/{headerSection-BpJYUMd6.mjs → headerSection-q_bEzfhW.mjs} +2 -2
- package/dist/client/{mediaAssets-DpPauppt.mjs → mediaAssets-B99AP7ai.mjs} +1 -1
- package/dist/client/{mediaContext-BLo4NtjP.mjs → mediaContext-Fusweriw.mjs} +1 -1
- package/dist/client/{newsletter-form.client-CSoP0cGR.mjs → newsletter-form.client-CiqKAmPs.mjs} +6 -6
- package/dist/client/{newsletter-form.parts-DDbX_Sj0.mjs → newsletter-form.parts-x1RzAMNO.mjs} +2 -2
- package/dist/client/{newsletterForm-vCxYRar_.mjs → newsletterForm-Cn7h4zFe.mjs} +3 -3
- package/dist/client/{noop-ByVtIWf4.mjs → noop-B_f7RqLD.mjs} +544 -494
- package/dist/client/portal/client.mjs +86 -231
- package/dist/client/{product-detail.client-7Pi6avM-.mjs → product-detail.client-rWUvpVvZ.mjs} +1 -1
- package/dist/client/{product-list.client-DEad-Pma.mjs → product-list.client-J0wDOmKv.mjs} +1 -1
- package/dist/client/{productDetail-G1SMXG13.mjs → productDetail-LtCkMrJ0.mjs} +3 -3
- package/dist/client/{productList-B21TGdpT.mjs → productList-C0MLeh-v.mjs} +3 -3
- package/dist/client/{propsDecoder-B3vIBkex.mjs → propsDecoder-CAmEkJ6Y.mjs} +5 -4
- package/dist/client/{registry.server-B8aQhJpO.mjs → registry.server-Bf2YX_4v.mjs} +2218 -2435
- package/dist/client/{surfaceTransportMarker-BXepAVF6.mjs → renderableMediaAssetAdmission-BlfqYLJW.mjs} +1 -18
- package/dist/client/rendering/client.mjs +30 -30
- package/dist/client/rendering/islands.mjs +1 -1
- package/dist/client/rendering.mjs +10 -9
- package/dist/client/{richText-coerce-DHkBtO0G.mjs → richText-coerce-BTurYEao.mjs} +1 -1
- package/dist/client/{routeIslandApiConfig-DbHX4JOS.mjs → routeIslandApiConfig-UdAlnZGQ.mjs} +1 -1
- package/dist/client/runtimeResponse-BP-L6exS.mjs +3 -0
- package/dist/client/runtimeResponse-Dg4XFsuM.mjs +9 -0
- package/dist/client/{shop-mqyoOvOK.mjs → shop-Dkn6EasY.mjs} +3 -3
- package/dist/client/{shop-commerce-B2UmrQg_.mjs → shop-commerce-bo0Z6kwf.mjs} +13 -13
- package/dist/client/{shop-commerce-store-B7n-Z7nY.mjs → shop-commerce-store-Ckxa4_jI.mjs} +1 -1
- package/dist/client/{shop.client-BH-BBnA9.mjs → shop.client-B_GqU6_U.mjs} +111 -32
- package/dist/client/{shop.interactive-mdM3UMWG.mjs → shop.interactive-C6L_Ig5F.mjs} +87 -528
- package/dist/client/{shopShared-CXF5wxdg.mjs → shopShared-CO1Y8lFd.mjs} +2 -2
- package/dist/client/spam-protection.mjs +1 -1
- package/dist/client/src-BozhJ43Z.mjs +3 -0
- package/dist/client/{src-1PJxc8KO.mjs → src-xrjaKaCj.mjs} +6 -8
- package/dist/client/surfaceTransportMarker-BuwkYxsI.mjs +19 -0
- package/dist/client/{timetableModel-CrC80EOG.mjs → timetableModel-D62jfOxZ.mjs} +12 -12
- package/dist/client/{types-sF-IrGQr.mjs → types-5fOsPIpL.mjs} +248 -111
- package/dist/client/{useAvailableSlots-C4LOaI_Z.mjs → useAvailableSlots-CStfVmyY.mjs} +3 -3
- package/dist/client/{useDiscountApply-6Q0nToVA.mjs → useDiscountApply-Ca2pHUDu.mjs} +6 -4
- package/dist/client/{useDiscountCodeUi-CM-DTX5X.mjs → useDiscountCodeUi-AEifktGO.mjs} +1 -1
- package/dist/client/{useEventPagination-Bcs89BR5.mjs → useEventPagination-uxnUWI2v.mjs} +7 -7
- package/dist/client/{view-BN-fxyfq.mjs → view-B6KSxQMO.mjs} +11 -7
- package/dist/client/{view-Dh2tGoS0.mjs → view-SVnWic7i.mjs} +3 -4
- package/dist/preview-next/client/{ArrangementLookControls-D4VjPs-r.mjs → ArrangementLookControls-kbdqYkWM.mjs} +26 -17
- package/dist/preview-next/client/{EventEmbeddedCheckoutStep-C_h1cMYm.mjs → EventEmbeddedCheckoutStep-8-qtHjpb.mjs} +1 -1
- package/dist/preview-next/client/{LocationPickerEnvironment-D56RD3e_.mjs → LocationPickerEnvironment-CZQ4vkRe.mjs} +1 -1
- package/dist/preview-next/client/{MapLibreEditMap-DFnyCckr.mjs → MapLibreEditMap-CP4w7T_0.mjs} +2 -2
- package/dist/preview-next/client/{PreviewEditorSidebar-Ckr2zk_L.mjs → PreviewEditorSidebar-DI_LhsMQ.mjs} +212 -55
- package/dist/preview-next/client/{PreviewEditorUI-KOZgw_gS.mjs → PreviewEditorUI-yyD-ZREP.mjs} +6 -6
- package/dist/preview-next/client/{PreviewShell-CyO2V4kB.mjs → PreviewShell-YauP65Gi.mjs} +199 -155
- package/dist/preview-next/client/{SdkPreviewModeRuntime-DW3uKvNF.mjs → SdkPreviewModeRuntime-Bl7jQMI1.mjs} +32 -32
- package/dist/preview-next/client/{SiteChromeCustomizeButton-CU9VD-7O.mjs → SiteChromeCustomizeButton-CQFRP9aM.mjs} +4772 -3687
- package/dist/preview-next/client/{ThemedButton-C0dgGJ5k.mjs → ThemedButton-BQU45t-E.mjs} +260 -121
- package/dist/preview-next/client/{lucide-react-CPBCf6QT.mjs → lucide-react-DkZ8fO-G.mjs} +1 -1
- package/dist/preview-next/client/{previewAssistantSlot-DBi-WybM.mjs → previewAssistantSlot-DSR0IdAw.mjs} +16547 -13046
- package/dist/preview-next/client/{previewChromeSurface-BhkUJst9.mjs → previewChromeSurface-uSnVzeNs.mjs} +1 -1
- package/dist/preview-next/client/runtime.mjs +3 -3
- package/dist/preview-next/client/{sdk-runtime-BjCb6lOn.mjs → sdk-runtime-6Q0RVJTQ.mjs} +2 -2
- package/dist/preview-next/client/{src-DY8JCJdE.mjs → src-DzXUmsyK.mjs} +6 -8
- package/dist/preview-next/client/src-LUhVXBEQ.mjs +3 -0
- package/dist/preview-next/client/{useAutosaveStatus-CKxTaC3j.mjs → useAutosaveStatus-Cdx3kAGm.mjs} +2 -2
- package/dist/preview-next/client/{useBlockCustomizeControls-B7MLTjBX.mjs → useBlockCustomizeControls-ZrWdhcB6.mjs} +2 -2
- package/dist/preview-next/client/{useOpenBlockForSetup-BTUc0g9X.mjs → useOpenBlockForSetup-CK-GWb9k.mjs} +1 -1
- package/dist/preview-next/keepAlive.mjs +1 -1
- package/dist/preview-next/middleware.mjs +1 -1
- package/dist/preview-next/{route-contract-Bv3nkdpV.mjs → route-contract-BU1m9SV3.mjs} +212 -0
- package/dist/server/{Block.shared-4fMqzltx.mjs → Block.shared-4vx7wzxj.mjs} +5 -5
- package/dist/server/{ThemeScopeCore-C72VC_lR.mjs → ThemeScopeCore-C3HLgqBF.mjs} +463 -127
- package/dist/server/{accessibleSurfaces-B_Y_dA20.mjs → accessibleSurfaces-108nxyGc.mjs} +319 -131
- package/dist/server/{bindings-ConMYJ2U.mjs → bindings-TAQbo2P5.mjs} +2 -2
- package/dist/server/{booking-form.reserved-fields-BWRF7509.mjs → booking-form.reserved-fields-Cqp13TKc.mjs} +1 -0
- package/dist/server/{client-Cot-H5fQ.mjs → client-DzCxEl3L.mjs} +308 -61
- package/dist/server/config-validation.mjs +1 -1
- package/dist/server/config.mjs +1 -1
- package/dist/server/{validation-CDd6m8Ry.mjs → customCss-QymcmOZ-.mjs} +12 -55
- package/dist/server/data/resolveBlockData.mjs +1 -1
- package/dist/server/headerVariant-8O5MvxIU.mjs +464 -0
- package/dist/server/{identity-Bn9OQiT1.mjs → identity-20XHqyuO.mjs} +1 -1
- package/dist/server/index.mjs +3 -3
- package/dist/server/{loadContent-BkaWYEwt.mjs → loadContent-BO1M9Hdf.mjs} +4 -5
- package/dist/server/{loadPage-kviUdH8c.mjs → loadPage-BvWzmZcD.mjs} +2 -2
- package/dist/server/manifest.mjs +1 -1
- package/dist/server/{media-DnlczCMA.mjs → media-Brn9FW5s.mjs} +15 -1
- package/dist/server/{mode-Cv_TG9gP.mjs → mode-bkFS8glh.mjs} +4 -2
- package/dist/server/next.mjs +6 -6
- package/dist/server/{opaqueSurface-BTnS09GS.mjs → opaqueSurface-BawlEAd_.mjs} +6 -6
- package/dist/server/{overrideResolution-itXZCXs7.mjs → overrideResolution-fxuB1zZg.mjs} +1 -1
- package/dist/server/page-converter.mjs +3 -3
- package/dist/server/{pageRenderPlan-CDyn7iLy.mjs → pageRenderPlan-DzduDSqY.mjs} +255 -158
- package/dist/server/{pageRuntimeSupport-DZ6cLxrM.mjs → pageRuntimeSupport-BU8pwTNx.mjs} +291 -5
- package/dist/server/{pageShared-Q_Vij87H.mjs → pageShared-CSOJ8p8E.mjs} +1303 -907
- package/dist/server/{schema-DEizlyi4.mjs → parseThemeForPersistence-BebSeE17.mjs} +593 -1592
- package/dist/server/{prebuild-DOG4MkOy.mjs → prebuild-C5ZYo7wA.mjs} +1 -1
- package/dist/server/prebuild.mjs +1 -1
- package/dist/server/{prefetchBlockData-DlprLLsc.mjs → prefetchBlockData-BvbxqeKn.mjs} +5 -4
- package/dist/server/{registry-BPFcpn6k.mjs → registry-Fv-7D8o2.mjs} +4595 -4045
- package/dist/server/rendering/components/pageShared.mjs +1 -1
- package/dist/server/rendering/helpers/loadPage.mjs +1 -1
- package/dist/server/rendering/helpers/pageRuntimeSupport.mjs +1 -1
- package/dist/server/rendering/server.mjs +3 -3
- package/dist/server/rendering.mjs +8 -8
- package/dist/server/{resolveBlockData-BHvfGD4y.mjs → resolveBlockData-xPgkvoWS.mjs} +1 -1
- package/dist/server/{resolveButtonColourStates-OXFRGn5M.mjs → resolveButtonColourStates-Cn6j8Ee0.mjs} +399 -518
- package/dist/server/{responseMedia-D8J3VAFs.mjs → responseMedia-t6gs0cB7.mjs} +2 -2
- package/dist/server/{richTextSchema-Euhuj-7V.mjs → richTextSchema-DQ2NBP0n.mjs} +5 -16
- package/dist/server/server.mjs +3 -3
- package/dist/server/theme-bridge.mjs +2 -3
- package/dist/server/theme.mjs +1 -2
- package/dist/server/{three-pass-converter-_j2UE2tR.mjs → three-pass-converter-CQWdnfjV.mjs} +1 -1
- package/dist/server/{validation-bl6WcAi_.mjs → validation-DddhgNdb.mjs} +58 -9
- package/dist/server/{version-BLXZ31S-.mjs → version-D_W2mt8w.mjs} +1 -1
- package/dist/styles/index.css +342 -67
- package/package.json +4 -3
- package/dist/_dts/index-CXsnaCGe.d.ts +0 -10
- package/dist/_dts/index-RugyUnqR.d.ts +0 -31535
- package/dist/client/BookingMailingListNote-CCVXX1LN.mjs +0 -331
- package/dist/client/DemoPortalSignInLink-B9YrzZt2.mjs +0 -19
- package/dist/client/creditProducts-BOWi1QLp.mjs +0 -62
- package/dist/client/site-styles-CMCUxsIM.mjs +0 -3
- package/dist/client/src-CdRISvQp.mjs +0 -3
- package/dist/client/src-DjnxOjXG.mjs +0 -217
- package/dist/client/useBookingNowIso-BDmWkYUW.mjs +0 -58
- package/dist/client/wizardSteps-DtkhwKXK.mjs +0 -6933
- package/dist/preview-next/client/src-BP8771hw.mjs +0 -3
- package/dist/server/parseThemeForPersistence-CDrF51tJ.mjs +0 -52
|
@@ -0,0 +1,4278 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { C as paletteColorsFromEntries, D as parseThemeColorToken, E as parseColorTokenParts, T as paletteModeSchema, _ as PALETTE_TOKEN_NAMES, c as buttonEffectApplicationSchema, g as VARIANT_ROLES, m as parseOpaqueButtonColourToken, n as STANDARD_BUTTON_SURFACE_POLICY, p as opaqueButtonColourTokenSchema, s as unsafeAsOpaqueButtonColourToken, u as buttonSystemSchema, x as normalizePaletteHex, y as hexColorSchema } from "./types-5fOsPIpL.mjs";
|
|
3
|
+
import { t as SURFACE_TRANSPORT_KEY } from "./surfaceTransportMarker-BuwkYxsI.mjs";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region ../theme-core/src/palette/utils/colorConversion.ts
|
|
6
|
+
const clamp01 = (x) => Math.max(0, Math.min(1, x));
|
|
7
|
+
const mod = (a, n) => (a % n + n) % n;
|
|
8
|
+
const deg = (x) => mod(x, 360);
|
|
9
|
+
const mix$1 = (a, b, t) => a + (b - a) * clamp01(t);
|
|
10
|
+
function hexToRgb(hex) {
|
|
11
|
+
const h = hex.replace(/^#/, "");
|
|
12
|
+
const m = h.length === 3 ? h.split("").map((c) => c + c).join("") : h;
|
|
13
|
+
if (m.length !== 6) throw new Error("Bad hex");
|
|
14
|
+
const int = parseInt(m, 16);
|
|
15
|
+
return {
|
|
16
|
+
r: int >> 16 & 255,
|
|
17
|
+
g: int >> 8 & 255,
|
|
18
|
+
b: int & 255
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function rgbToHex(r, g, b) {
|
|
22
|
+
const to = (n) => Math.round(n).toString(16).padStart(2, "0");
|
|
23
|
+
return `#${to(r)}${to(g)}${to(b)}`;
|
|
24
|
+
}
|
|
25
|
+
function srgbToLinear(u) {
|
|
26
|
+
const x = u / 255;
|
|
27
|
+
return x <= .04045 ? x / 12.92 : Math.pow((x + .055) / 1.055, 2.4);
|
|
28
|
+
}
|
|
29
|
+
function linearToSrgb(x) {
|
|
30
|
+
return clamp01(x <= .0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - .055) * 255;
|
|
31
|
+
}
|
|
32
|
+
function rgbToHsl(r, g, b) {
|
|
33
|
+
const R = r / 255, G = g / 255, B = b / 255;
|
|
34
|
+
const max = Math.max(R, G, B), min = Math.min(R, G, B);
|
|
35
|
+
const d = max - min;
|
|
36
|
+
let h = 0;
|
|
37
|
+
if (d !== 0) {
|
|
38
|
+
switch (max) {
|
|
39
|
+
case R:
|
|
40
|
+
h = (G - B) / d + (G < B ? 6 : 0);
|
|
41
|
+
break;
|
|
42
|
+
case G:
|
|
43
|
+
h = (B - R) / d + 2;
|
|
44
|
+
break;
|
|
45
|
+
case B:
|
|
46
|
+
h = (R - G) / d + 4;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
h *= 60;
|
|
50
|
+
}
|
|
51
|
+
const l = (max + min) / 2;
|
|
52
|
+
const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
|
|
53
|
+
return {
|
|
54
|
+
h,
|
|
55
|
+
s,
|
|
56
|
+
l
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function srgbToOklab(r, g, b) {
|
|
60
|
+
const R = srgbToLinear(r), G = srgbToLinear(g), B = srgbToLinear(b);
|
|
61
|
+
const l = .4122214708 * R + .5363325363 * G + .0514459929 * B;
|
|
62
|
+
const m = .2119034982 * R + .6806995451 * G + .1073969566 * B;
|
|
63
|
+
const s = .0883024619 * R + .2817188376 * G + .6299787005 * B;
|
|
64
|
+
const l_ = Math.cbrt(l), m_ = Math.cbrt(m), s_ = Math.cbrt(s);
|
|
65
|
+
return {
|
|
66
|
+
L: .2104542553 * l_ + .793617785 * m_ - .0040720468 * s_,
|
|
67
|
+
a: 1.9779984951 * l_ - 2.428592205 * m_ + .4505937099 * s_,
|
|
68
|
+
b: .0259040371 * l_ + .7827717662 * m_ - .808675766 * s_
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** OKLab to linear sRGB, unclamped. The one owner of this matrix. */
|
|
72
|
+
function oklabToLinearSrgb(L, a, b) {
|
|
73
|
+
const l_ = Math.pow(L + .3963377774 * a + .2158037573 * b, 3);
|
|
74
|
+
const m_ = Math.pow(L - .1055613458 * a - .0638541728 * b, 3);
|
|
75
|
+
const s_ = Math.pow(L - .0894841775 * a - 1.291485548 * b, 3);
|
|
76
|
+
return {
|
|
77
|
+
r: 4.0767416621 * l_ - 3.3077115913 * m_ + .2309699292 * s_,
|
|
78
|
+
g: -1.2684380046 * l_ + 2.6097574011 * m_ - .3413193965 * s_,
|
|
79
|
+
b: -.0041960863 * l_ - .7034186147 * m_ + 1.707614701 * s_
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
function oklabToSrgb(L, a, b) {
|
|
83
|
+
const { r, g, b: B } = oklabToLinearSrgb(L, a, b);
|
|
84
|
+
return {
|
|
85
|
+
r: linearToSrgb(r),
|
|
86
|
+
g: linearToSrgb(g),
|
|
87
|
+
b: linearToSrgb(B)
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
function oklabToOklch(L, a, b) {
|
|
91
|
+
const C = Math.sqrt(a * a + b * b);
|
|
92
|
+
return {
|
|
93
|
+
L,
|
|
94
|
+
C,
|
|
95
|
+
h: C < 1e-7 ? 0 : deg(Math.atan2(b, a) * 180 / Math.PI)
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function oklchToOklab(L, C, h) {
|
|
99
|
+
const hr = h * Math.PI / 180;
|
|
100
|
+
return {
|
|
101
|
+
L,
|
|
102
|
+
a: C * Math.cos(hr),
|
|
103
|
+
b: C * Math.sin(hr)
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function inSRGB(r, g, b) {
|
|
107
|
+
return r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* OKLCH to linear sRGB with no clamping, so a gamut test can see a channel
|
|
111
|
+
* that leaves [0, 1]. `oklabToSrgb` clamps before `inSRGB` looks, which is why
|
|
112
|
+
* `oklchToHexGamut` can clip; that function is left alone on purpose, because
|
|
113
|
+
* changing it would move every generated shade on live sites (issue 1633).
|
|
114
|
+
*/
|
|
115
|
+
function oklchToLinearSrgb(L, C, h) {
|
|
116
|
+
const { a, b } = oklchToOklab(L, C, h);
|
|
117
|
+
return oklabToLinearSrgb(L, a, b);
|
|
118
|
+
}
|
|
119
|
+
function inLinearSrgbGamut(rgb) {
|
|
120
|
+
return [
|
|
121
|
+
rgb.r,
|
|
122
|
+
rgb.g,
|
|
123
|
+
rgb.b
|
|
124
|
+
].every((v) => v >= -1e-6 && v <= 1.000001);
|
|
125
|
+
}
|
|
126
|
+
function oklchToHexGamut(L, C, h) {
|
|
127
|
+
let lo = 0, hi = C, best = 0;
|
|
128
|
+
for (let i = 0; i < 18; i++) {
|
|
129
|
+
const mid = (lo + hi) / 2;
|
|
130
|
+
const { a, b } = oklchToOklab(L, mid, h);
|
|
131
|
+
const { r, g, b: bb } = oklabToSrgb(L, a, b);
|
|
132
|
+
if (inSRGB(r, g, bb)) {
|
|
133
|
+
best = mid;
|
|
134
|
+
lo = mid;
|
|
135
|
+
} else hi = mid;
|
|
136
|
+
}
|
|
137
|
+
const { a, b } = oklchToOklab(L, best, h);
|
|
138
|
+
const { r, g, b: bb } = oklabToSrgb(L, a, b);
|
|
139
|
+
return rgbToHex(r, g, bb);
|
|
140
|
+
}
|
|
141
|
+
function featuresFromHex(hex) {
|
|
142
|
+
const { r, g, b } = hexToRgb(hex);
|
|
143
|
+
const { h, s, l } = rgbToHsl(r, g, b);
|
|
144
|
+
const { L, a, b: b2 } = srgbToOklab(r, g, b);
|
|
145
|
+
const { L: okL, C: okC, h: okH } = oklabToOklch(L, a, b2);
|
|
146
|
+
return {
|
|
147
|
+
r,
|
|
148
|
+
g,
|
|
149
|
+
b,
|
|
150
|
+
h,
|
|
151
|
+
s,
|
|
152
|
+
l,
|
|
153
|
+
v: Math.max(r, g, b) / 255,
|
|
154
|
+
Y: .2126 * srgbToLinear(r) + .7152 * srgbToLinear(g) + .0722 * srgbToLinear(b),
|
|
155
|
+
chroma: s,
|
|
156
|
+
okL,
|
|
157
|
+
okC,
|
|
158
|
+
okH,
|
|
159
|
+
hex
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/checkPrivateRedeclaration.js
|
|
164
|
+
function _checkPrivateRedeclaration(e, t) {
|
|
165
|
+
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
166
|
+
}
|
|
167
|
+
//#endregion
|
|
168
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/classPrivateFieldInitSpec.js
|
|
169
|
+
function _classPrivateFieldInitSpec(e, t, a) {
|
|
170
|
+
_checkPrivateRedeclaration(e, t), t.set(e, a);
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region ../theme-core/src/palette/utils/contrast.ts
|
|
174
|
+
const ORDINARY_TEXT_MIN_CONTRAST_RATIO = 4.5;
|
|
175
|
+
function relativeLuminance(r, g, b) {
|
|
176
|
+
const R = srgbToLinear(r), G = srgbToLinear(g), B = srgbToLinear(b);
|
|
177
|
+
return .2126 * R + .7152 * G + .0722 * B;
|
|
178
|
+
}
|
|
179
|
+
function preparePaletteColourIndex(palette) {
|
|
180
|
+
const colours = [.../* @__PURE__ */ new Set([
|
|
181
|
+
...Object.values(palette),
|
|
182
|
+
"#000000",
|
|
183
|
+
"#ffffff",
|
|
184
|
+
"#FFFFFF"
|
|
185
|
+
])];
|
|
186
|
+
return Object.freeze(Object.fromEntries(colours.flatMap(colourIndexEntry)));
|
|
187
|
+
}
|
|
188
|
+
/** An unused unsupported colour must not turn preparation into an eager validation failure. */
|
|
189
|
+
function colourIndexEntry(hex) {
|
|
190
|
+
try {
|
|
191
|
+
return [[hex, colourLuminance(hex)]];
|
|
192
|
+
} catch {
|
|
193
|
+
return [];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function colourLuminance(hex) {
|
|
197
|
+
const { r, g, b } = hexToRgb(hex);
|
|
198
|
+
return relativeLuminance(r, g, b);
|
|
199
|
+
}
|
|
200
|
+
function indexedLuminance(hex, index) {
|
|
201
|
+
return (index && Object.prototype.hasOwnProperty.call(index, hex) ? index[hex] : void 0) ?? colourLuminance(hex);
|
|
202
|
+
}
|
|
203
|
+
var _certified = /* @__PURE__ */ new WeakMap();
|
|
204
|
+
/**
|
|
205
|
+
* A closed luminance range with `lo <= hi`. The private field means only
|
|
206
|
+
* `luminanceInterval` and `solidPaint` can make one, so the solver can trust
|
|
207
|
+
* the ordering without checking it again. The class itself is not exported.
|
|
208
|
+
*/
|
|
209
|
+
var Interval = class {
|
|
210
|
+
constructor(lo, hi) {
|
|
211
|
+
this.lo = lo;
|
|
212
|
+
this.hi = hi;
|
|
213
|
+
_classPrivateFieldInitSpec(this, _certified, true);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
function toLuminance(y) {
|
|
217
|
+
if (!Number.isFinite(y) || y < 0 || y > 1) throw new Error(`Luminance must be in [0, 1]: ${y}`);
|
|
218
|
+
return y;
|
|
219
|
+
}
|
|
220
|
+
function luminanceInterval(lo, hi = lo) {
|
|
221
|
+
if (toLuminance(lo) > toLuminance(hi)) throw new Error(`Empty luminance interval: [${lo}, ${hi}]`);
|
|
222
|
+
return new Interval(lo, hi);
|
|
223
|
+
}
|
|
224
|
+
/** The relative luminance of a hex colour, read from the prepared index when given. */
|
|
225
|
+
function hexLuminance(hex, index) {
|
|
226
|
+
return toLuminance(indexedLuminance(hex, index));
|
|
227
|
+
}
|
|
228
|
+
/** The paint of a solid hex ground: a single point. */
|
|
229
|
+
function solidPaint(hex, index) {
|
|
230
|
+
const y = hexLuminance(hex, index);
|
|
231
|
+
return new Interval(y, y);
|
|
232
|
+
}
|
|
233
|
+
function luminanceRatio(a, b) {
|
|
234
|
+
return a >= b ? (a + .05) / (b + .05) : (b + .05) / (a + .05);
|
|
235
|
+
}
|
|
236
|
+
/** The lowest contrast an ink of luminance `ink` has against any point of `paint`. */
|
|
237
|
+
function worstContrast(ink, paint) {
|
|
238
|
+
if (ink >= paint.lo && ink <= paint.hi) return 1;
|
|
239
|
+
return Math.min(luminanceRatio(ink, paint.lo), luminanceRatio(ink, paint.hi));
|
|
240
|
+
}
|
|
241
|
+
function assertContrastRatio(ratio) {
|
|
242
|
+
if (!Number.isFinite(ratio) || ratio <= 1 || ratio > 21) throw new Error(`Contrast ratio must be above 1 and at most 21: ${ratio}`);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* The one black-or-white rule: literal black or white, whichever contrasts more
|
|
246
|
+
* with the whole paint (black on a tie). It always returns, even when neither
|
|
247
|
+
* reaches the ratio a caller wants; callers decide what a shortfall means.
|
|
248
|
+
* A style's preferred neutral is a separate input (`neutralInk`) and never
|
|
249
|
+
* part of this rule.
|
|
250
|
+
*/
|
|
251
|
+
function maxContrastBlackOrWhite(paint) {
|
|
252
|
+
const blackContrast = (paint.lo + .05) / .05;
|
|
253
|
+
const whiteContrast = 1.05 / (paint.hi + .05);
|
|
254
|
+
return blackContrast >= whiteContrast ? {
|
|
255
|
+
ink: "black",
|
|
256
|
+
ratio: blackContrast
|
|
257
|
+
} : {
|
|
258
|
+
ink: "white",
|
|
259
|
+
ratio: whiteContrast
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function contrastRatio(hex1, hex2, index) {
|
|
263
|
+
const L1 = indexedLuminance(hex1, index);
|
|
264
|
+
const L2 = indexedLuminance(hex2, index);
|
|
265
|
+
const [hi, lo] = L1 >= L2 ? [L1, L2] : [L2, L1];
|
|
266
|
+
return (hi + .05) / (lo + .05);
|
|
267
|
+
}
|
|
268
|
+
//#endregion
|
|
269
|
+
//#region ../theme-core/src/palette/colors.ts
|
|
270
|
+
const PALETTE_VALUE_KEY_PREFIX = "palette-value:v1|";
|
|
271
|
+
z.string().regex(/^[0-9a-f]{64}$/, "Palette hash must be a lowercase SHA-256 value").transform((value) => value);
|
|
272
|
+
function requirePaletteColorsFromEntries(entries) {
|
|
273
|
+
const result = paletteColorsFromEntries(entries);
|
|
274
|
+
if (result.ok) return result.colors;
|
|
275
|
+
throw new Error(`Invalid complete palette: ${result.error.kind}`);
|
|
276
|
+
}
|
|
277
|
+
function paletteColorFingerprint(colors) {
|
|
278
|
+
return PALETTE_TOKEN_NAMES.map((name) => `${name}:${colors[name]}`).join("|");
|
|
279
|
+
}
|
|
280
|
+
function canonicalPaletteHashInput(colors, mode) {
|
|
281
|
+
return `${mode}|${paletteColorFingerprint(colors)}`;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Stable curated-catalogue identity. Do not reorder roles: the order comes
|
|
285
|
+
* from PALETTE_TOKEN_NAMES through canonicalPaletteHashInput.
|
|
286
|
+
*/
|
|
287
|
+
function paletteValueKey(colors, mode) {
|
|
288
|
+
return `${PALETTE_VALUE_KEY_PREFIX}${canonicalPaletteHashInput(colors, mode)}`;
|
|
289
|
+
}
|
|
290
|
+
/** Parses only the exact v1 canonical form emitted by paletteValueKey. */
|
|
291
|
+
function parsePaletteValueKey(value) {
|
|
292
|
+
if (typeof value !== "string" || !value.startsWith(PALETTE_VALUE_KEY_PREFIX)) return null;
|
|
293
|
+
const [rawMode, ...rawRoles] = value.slice(17).split("|");
|
|
294
|
+
const mode = paletteModeSchema.safeParse(rawMode);
|
|
295
|
+
if (!mode.success || rawRoles.length !== PALETTE_TOKEN_NAMES.length) return null;
|
|
296
|
+
const colors = paletteColorsFromEntries(rawRoles.map((roleValue) => {
|
|
297
|
+
const separator = roleValue.indexOf(":");
|
|
298
|
+
return separator === -1 ? {
|
|
299
|
+
name: "",
|
|
300
|
+
hex: ""
|
|
301
|
+
} : {
|
|
302
|
+
name: roleValue.slice(0, separator),
|
|
303
|
+
hex: roleValue.slice(separator + 1)
|
|
304
|
+
};
|
|
305
|
+
}));
|
|
306
|
+
if (!colors.ok || paletteValueKey(colors.colors, mode.data) !== value) return null;
|
|
307
|
+
return value;
|
|
308
|
+
}
|
|
309
|
+
const paletteValueKeySchema = z.string().transform((value, ctx) => {
|
|
310
|
+
const parsed = parsePaletteValueKey(value);
|
|
311
|
+
if (parsed) return parsed;
|
|
312
|
+
ctx.addIssue({
|
|
313
|
+
code: "custom",
|
|
314
|
+
message: "Invalid canonical palette value key"
|
|
315
|
+
});
|
|
316
|
+
return z.NEVER;
|
|
317
|
+
});
|
|
318
|
+
//#endregion
|
|
319
|
+
//#region ../theme-core/src/palette/utils/opaqueSurfaceColor.ts
|
|
320
|
+
/** Resolve an opaque colour, compositing alpha against an explicit underlay. */
|
|
321
|
+
function resolveOpaqueSurfaceHex(reference, palette, underlayReference) {
|
|
322
|
+
const opaque = resolveConcreteColorHex(reference, palette);
|
|
323
|
+
if (opaque) return opaque;
|
|
324
|
+
if (!underlayReference) return null;
|
|
325
|
+
const underlayHex = resolveConcreteColorHex(underlayReference, palette);
|
|
326
|
+
if (!underlayHex) return null;
|
|
327
|
+
const parts = parseColorTokenParts(reference);
|
|
328
|
+
if (parts.kind === "token" && parts.opacityPercent !== null) {
|
|
329
|
+
const foregroundHex = normalizePaletteHex(palette[parts.token] ?? "");
|
|
330
|
+
return foregroundHex ? compositeHex$1(foregroundHex, underlayHex, parts.opacityPercent / 100) : null;
|
|
331
|
+
}
|
|
332
|
+
const rgba = parseRgba(parts.kind === "raw" ? parts.value : reference);
|
|
333
|
+
return rgba ? compositeHex$1(rgbToHex(rgba.r, rgba.g, rgba.b), underlayHex, rgba.alpha) : null;
|
|
334
|
+
}
|
|
335
|
+
/** Resolve a colour reference only when it is already fully opaque. */
|
|
336
|
+
function resolveConcreteColorHex(reference, palette) {
|
|
337
|
+
const literalHex = normalizePaletteHex(reference);
|
|
338
|
+
if (literalHex) return literalHex;
|
|
339
|
+
const parts = parseColorTokenParts(reference);
|
|
340
|
+
if (parts.kind === "token") {
|
|
341
|
+
if (parts.opacityPercent !== null) return null;
|
|
342
|
+
return normalizePaletteHex(palette[parts.token] ?? "");
|
|
343
|
+
}
|
|
344
|
+
const literal = parts.kind === "raw" ? parts.value : reference;
|
|
345
|
+
if (literal.toLowerCase() === "black") return "#000000";
|
|
346
|
+
if (literal.toLowerCase() === "white") return "#ffffff";
|
|
347
|
+
return normalizePaletteHex(literal);
|
|
348
|
+
}
|
|
349
|
+
function compositeHex$1(foregroundHex, underlayHex, alpha) {
|
|
350
|
+
const foreground = hexToRgb(foregroundHex);
|
|
351
|
+
const underlay = hexToRgb(underlayHex);
|
|
352
|
+
const channel = (foregroundValue, underlayValue) => Math.round(foregroundValue * alpha + underlayValue * (1 - alpha));
|
|
353
|
+
return rgbToHex(channel(foreground.r, underlay.r), channel(foreground.g, underlay.g), channel(foreground.b, underlay.b));
|
|
354
|
+
}
|
|
355
|
+
function parseRgba(value) {
|
|
356
|
+
const match = value.trim().match(/^rgba?\(\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*(?:,|\/)\s*([\d.]+%?))?\s*\)$/i);
|
|
357
|
+
if (!match) return null;
|
|
358
|
+
const [, rSource, gSource, bSource] = match;
|
|
359
|
+
if (!rSource || !gSource || !bSource) return null;
|
|
360
|
+
const r = Number(rSource);
|
|
361
|
+
const g = Number(gSource);
|
|
362
|
+
const b = Number(bSource);
|
|
363
|
+
const alpha = parseAlpha(match[4]);
|
|
364
|
+
if (alpha === null || !isRgbChannel(r) || !isRgbChannel(g) || !isRgbChannel(b)) return null;
|
|
365
|
+
return {
|
|
366
|
+
r,
|
|
367
|
+
g,
|
|
368
|
+
b,
|
|
369
|
+
alpha
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
function parseAlpha(source) {
|
|
373
|
+
if (!source) return 1;
|
|
374
|
+
const value = source.endsWith("%") ? Number(source.slice(0, -1)) / 100 : Number(source);
|
|
375
|
+
return Number.isFinite(value) && value >= 0 && value <= 1 ? value : null;
|
|
376
|
+
}
|
|
377
|
+
function isRgbChannel(value) {
|
|
378
|
+
return Number.isFinite(value) && value >= 0 && value <= 255;
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region ../theme-core/src/site-styles/ownedThemeSnapshot.ts
|
|
382
|
+
const ownedThemeValues = /* @__PURE__ */ new WeakSet();
|
|
383
|
+
function isOwnedThemeValue(value) {
|
|
384
|
+
return ownedThemeValues.has(value);
|
|
385
|
+
}
|
|
386
|
+
/** Copy before freezing: the editor still owns its source data. */
|
|
387
|
+
function ownedThemeSnapshot(input) {
|
|
388
|
+
return typeof input === "object" && input !== null && isOwnedThemeValue(input) ? input : freezeOwnedThemeValue(structuredClone(input));
|
|
389
|
+
}
|
|
390
|
+
/** Only freshly owned data belongs here; no caller-owned object is frozen. */
|
|
391
|
+
function freezeOwnedThemeValue(value) {
|
|
392
|
+
if (typeof value === "object" && value !== null) {
|
|
393
|
+
if (ownedThemeValues.has(value)) return value;
|
|
394
|
+
Object.values(value).forEach(freezeOwnedThemeValue);
|
|
395
|
+
Object.freeze(value);
|
|
396
|
+
ownedThemeValues.add(value);
|
|
397
|
+
}
|
|
398
|
+
return value;
|
|
399
|
+
}
|
|
400
|
+
//#endregion
|
|
401
|
+
//#region ../theme-core/src/surfaces/foregroundContract.ts
|
|
402
|
+
const SURFACE_FOREGROUND_CSS_VARS = {
|
|
403
|
+
text: "--rb-surface-text-color",
|
|
404
|
+
heading: "--rb-surface-heading-color",
|
|
405
|
+
link: "--rb-surface-link-color",
|
|
406
|
+
linkHover: "--rb-surface-link-hover-color",
|
|
407
|
+
supporting: "--rb-surface-supporting-color",
|
|
408
|
+
muted: "--rb-surface-muted-color",
|
|
409
|
+
line: "--rb-surface-line-color",
|
|
410
|
+
mark: "--rb-surface-mark-color"
|
|
411
|
+
};
|
|
412
|
+
const DEFAULT_SURFACE_TEXT_COLOR = "rgb(var(--tb-text, 17 24 39))";
|
|
413
|
+
const DEFAULT_SURFACE_LINK_COLOR = "rgb(var(--tb-primary, var(--tb-text, 17 24 39)))";
|
|
414
|
+
const DEFAULT_SURFACE_SUPPORTING_COLOR = "rgb(var(--tb-mutedText, 100 116 139))";
|
|
415
|
+
const DEFAULT_ROLE_FALLBACKS = {
|
|
416
|
+
text: DEFAULT_SURFACE_TEXT_COLOR,
|
|
417
|
+
heading: DEFAULT_SURFACE_TEXT_COLOR,
|
|
418
|
+
link: DEFAULT_SURFACE_LINK_COLOR,
|
|
419
|
+
linkHover: DEFAULT_SURFACE_LINK_COLOR,
|
|
420
|
+
supporting: DEFAULT_SURFACE_SUPPORTING_COLOR,
|
|
421
|
+
muted: DEFAULT_SURFACE_SUPPORTING_COLOR
|
|
422
|
+
};
|
|
423
|
+
function requireSurfaceColorValue(role, value) {
|
|
424
|
+
const normalized = value.trim();
|
|
425
|
+
if (normalized.length === 0) throw new RangeError(`Surface foreground ${role} must be a non-empty CSS color.`);
|
|
426
|
+
return normalized;
|
|
427
|
+
}
|
|
428
|
+
function completeSurfaceForegrounds(input) {
|
|
429
|
+
const text = requireSurfaceColorValue("text", input.text);
|
|
430
|
+
const link = input.link === void 0 ? text : requireSurfaceColorValue("link", input.link);
|
|
431
|
+
return {
|
|
432
|
+
text,
|
|
433
|
+
heading: input.heading === void 0 ? text : requireSurfaceColorValue("heading", input.heading),
|
|
434
|
+
link,
|
|
435
|
+
linkHover: input.linkHover === void 0 ? link : requireSurfaceColorValue("linkHover", input.linkHover),
|
|
436
|
+
muted: input.muted === void 0 ? text : requireSurfaceColorValue("muted", input.muted),
|
|
437
|
+
supporting: input.supporting === void 0 ? text : requireSurfaceColorValue("supporting", input.supporting)
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
function surfaceForegroundValue(role, outsideProviderFallback = DEFAULT_ROLE_FALLBACKS[role]) {
|
|
441
|
+
const roleVariable = SURFACE_FOREGROUND_CSS_VARS[role];
|
|
442
|
+
const fallback = requireSurfaceColorValue("fallback", outsideProviderFallback);
|
|
443
|
+
if (role === "text") return `var(${roleVariable}, ${fallback})`;
|
|
444
|
+
if (role === "linkHover") return `var(${roleVariable}, ${surfaceForegroundValue("link", fallback)})`;
|
|
445
|
+
return `var(${roleVariable}, var(${SURFACE_FOREGROUND_CSS_VARS.text}, ${fallback}))`;
|
|
446
|
+
}
|
|
447
|
+
/** The three solved inks, published beside the foreground roles by the same surfaces. */
|
|
448
|
+
const SURFACE_INK_CSS_VARS = {
|
|
449
|
+
brand: "--rb-surface-brand-color",
|
|
450
|
+
accent: "--rb-surface-accent-color",
|
|
451
|
+
focus: "--rb-surface-focus-color"
|
|
452
|
+
};
|
|
453
|
+
/**
|
|
454
|
+
* The declarations for a surface's ink publication. An exact ink is a token
|
|
455
|
+
* reference (`rgb(var(--tb-primary))`), so a site's own token value wins; a
|
|
456
|
+
* nudged or replaced ink is a literal colour.
|
|
457
|
+
*/
|
|
458
|
+
function surfaceInkStyle(publication) {
|
|
459
|
+
switch (publication.kind) {
|
|
460
|
+
case "none": return {};
|
|
461
|
+
case "reset": return inkVariables(() => "initial");
|
|
462
|
+
case "solved": return inkVariables((role) => {
|
|
463
|
+
const ink = publication.inks[role];
|
|
464
|
+
const token = parseThemeColorToken(ink);
|
|
465
|
+
return token ? rgbColorValue(token) : ink;
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
function surfaceInkDeclarations(publication) {
|
|
470
|
+
return Object.entries(surfaceInkStyle(publication)).map(([property, value]) => `${property}: ${value};`);
|
|
471
|
+
}
|
|
472
|
+
function inkVariables(value) {
|
|
473
|
+
return {
|
|
474
|
+
[SURFACE_INK_CSS_VARS.brand]: value("brand"),
|
|
475
|
+
[SURFACE_INK_CSS_VARS.accent]: value("accent"),
|
|
476
|
+
[SURFACE_INK_CSS_VARS.focus]: value("focus")
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
function surfaceForegroundValueWithOpacity(role, opacityPercent) {
|
|
480
|
+
if (!Number.isFinite(opacityPercent) || opacityPercent < 0 || opacityPercent > 100) throw new RangeError("Surface foreground opacity must be between 0 and 100.");
|
|
481
|
+
return `color-mix(in srgb, ${surfaceForegroundValue(role)} ${opacityPercent}%, transparent)`;
|
|
482
|
+
}
|
|
483
|
+
function surfaceForegroundStyle(input) {
|
|
484
|
+
const foregrounds = completeSurfaceForegrounds(input);
|
|
485
|
+
return {
|
|
486
|
+
color: foregrounds.text,
|
|
487
|
+
[SURFACE_FOREGROUND_CSS_VARS.text]: foregrounds.text,
|
|
488
|
+
[SURFACE_FOREGROUND_CSS_VARS.heading]: foregrounds.heading,
|
|
489
|
+
[SURFACE_FOREGROUND_CSS_VARS.link]: foregrounds.link,
|
|
490
|
+
[SURFACE_FOREGROUND_CSS_VARS.linkHover]: foregrounds.linkHover,
|
|
491
|
+
[SURFACE_FOREGROUND_CSS_VARS.supporting]: foregrounds.supporting,
|
|
492
|
+
...input.muted === void 0 ? {} : { [SURFACE_FOREGROUND_CSS_VARS.muted]: foregrounds.muted },
|
|
493
|
+
"--rb-surface-link-hover-decoration": hoverDecoration(input)
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
function surfaceForegroundDeclarations(input) {
|
|
497
|
+
return Object.entries(surfaceForegroundStyle(input)).map(([property, value]) => `${property}: ${value};`);
|
|
498
|
+
}
|
|
499
|
+
function surfaceForegroundInputFromResolved(foreground, color) {
|
|
500
|
+
const { roles } = foreground;
|
|
501
|
+
const value = (ink) => {
|
|
502
|
+
const token = parseThemeColorToken(ink);
|
|
503
|
+
return token ? color(token) : ink;
|
|
504
|
+
};
|
|
505
|
+
return {
|
|
506
|
+
text: value(roles.text),
|
|
507
|
+
heading: value(roles.heading),
|
|
508
|
+
link: value(roles.link),
|
|
509
|
+
linkHover: value(roles.linkHover),
|
|
510
|
+
supporting: value(roles.supporting),
|
|
511
|
+
hoverDecoration: foreground.hoverDecoration
|
|
512
|
+
};
|
|
513
|
+
}
|
|
514
|
+
function hoverDecoration(input) {
|
|
515
|
+
return input.hoverDecoration ?? "underline";
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Derive the hover foreground that belongs with a resolved resting foreground.
|
|
519
|
+
*
|
|
520
|
+
* A resting foreground is chosen to be legible against a known surface. A hover
|
|
521
|
+
* state derived from it stays within a bounded distance of that colour, so it
|
|
522
|
+
* inherits most of the resting colour's contrast margin instead of asserting
|
|
523
|
+
* an unrelated brand colour that no one checked against the surface.
|
|
524
|
+
*
|
|
525
|
+
* That bounded-distance property is what lets this be used on a transparent
|
|
526
|
+
* overlay header, where the backdrop is only partly knowable: the scrolled
|
|
527
|
+
* state composites a 60% glass tint over arbitrary page content, so no
|
|
528
|
+
* compile-time contrast proof is available there. Staying near a colour that
|
|
529
|
+
* is already trusted in both states is a weaker claim than a contrast proof,
|
|
530
|
+
* and it is one this function can actually keep.
|
|
531
|
+
*
|
|
532
|
+
* Returns `null` when the resting token is not a plain palette token — an
|
|
533
|
+
* already-faded or raw value has no well-defined softening, and the caller
|
|
534
|
+
* should leave hover alone rather than guess.
|
|
535
|
+
*/
|
|
536
|
+
function deriveForegroundHoverToken(restingToken) {
|
|
537
|
+
const parts = parseColorTokenParts(restingToken);
|
|
538
|
+
if (parts.kind !== "token") return null;
|
|
539
|
+
if (parts.opacityPercent !== null) return null;
|
|
540
|
+
return parseThemeColorToken(`${parts.token}/85`);
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Prefer an authored hover that survives every measured backdrop, then a
|
|
544
|
+
* checked softening of the resting colour. A null backdrop set represents a
|
|
545
|
+
* trusted treatment: only an explicit authored hover may change the colour.
|
|
546
|
+
* When neither option works, retain the resting colour and underline it.
|
|
547
|
+
*/
|
|
548
|
+
function planForegroundHover(input) {
|
|
549
|
+
const { restingToken, candidate, palette, backdrops } = input;
|
|
550
|
+
if (candidate && String(candidate) !== String(restingToken)) {
|
|
551
|
+
if (backdrops === null || survivesEveryBackdrop(candidate, palette, backdrops)) return {
|
|
552
|
+
kind: "candidate",
|
|
553
|
+
token: candidate,
|
|
554
|
+
decoration: "initial"
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
const resting = parseThemeColorToken(restingToken);
|
|
558
|
+
const softened = resting ? deriveForegroundHoverToken(resting) : null;
|
|
559
|
+
if (softened && backdrops && survivesEveryBackdrop(softened, palette, backdrops)) return {
|
|
560
|
+
kind: "softened",
|
|
561
|
+
token: softened,
|
|
562
|
+
decoration: "initial"
|
|
563
|
+
};
|
|
564
|
+
return {
|
|
565
|
+
kind: "resting",
|
|
566
|
+
token: restingToken,
|
|
567
|
+
decoration: "underline"
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
function survivesEveryBackdrop(token, palette, backdrops) {
|
|
571
|
+
return backdrops.length > 0 && backdrops.every((backdrop) => {
|
|
572
|
+
const foreground = resolveOpaqueSurfaceHex(token, palette, backdrop);
|
|
573
|
+
return foreground !== null && contrastRatio(foreground, backdrop) >= 4.5;
|
|
574
|
+
});
|
|
575
|
+
}
|
|
576
|
+
//#endregion
|
|
577
|
+
//#region ../site-contracts/src/renderResults/buttonTypes.ts
|
|
578
|
+
const BUTTON_VISUAL_STATES = [
|
|
579
|
+
"base",
|
|
580
|
+
"hover",
|
|
581
|
+
"focus",
|
|
582
|
+
"active",
|
|
583
|
+
"disabled"
|
|
584
|
+
];
|
|
585
|
+
//#endregion
|
|
586
|
+
//#region ../theme-core/src/palette/generateShades.ts
|
|
587
|
+
function generateShades(hexColor, name) {
|
|
588
|
+
const shadeSteps = [
|
|
589
|
+
50,
|
|
590
|
+
100,
|
|
591
|
+
200,
|
|
592
|
+
300,
|
|
593
|
+
400,
|
|
594
|
+
500,
|
|
595
|
+
600,
|
|
596
|
+
700,
|
|
597
|
+
800,
|
|
598
|
+
900,
|
|
599
|
+
950
|
|
600
|
+
];
|
|
601
|
+
const base = featuresFromHex(hexColor);
|
|
602
|
+
const hue = base.okH;
|
|
603
|
+
const baseChroma = base.okC;
|
|
604
|
+
const toneMap = {
|
|
605
|
+
50: .975,
|
|
606
|
+
100: .945,
|
|
607
|
+
200: .89,
|
|
608
|
+
300: .82,
|
|
609
|
+
400: .74,
|
|
610
|
+
500: .66,
|
|
611
|
+
600: .58,
|
|
612
|
+
700: .49,
|
|
613
|
+
800: .4,
|
|
614
|
+
900: .28,
|
|
615
|
+
950: .16
|
|
616
|
+
};
|
|
617
|
+
const shadeDefs = shadeSteps.map((step, idx) => {
|
|
618
|
+
const t = idx / (shadeSteps.length - 1);
|
|
619
|
+
const L = toneMap[step];
|
|
620
|
+
const C = baseChroma * (.06 + .94 * Math.sin(Math.PI * t));
|
|
621
|
+
return {
|
|
622
|
+
name: `${name}-${step}`,
|
|
623
|
+
hex: oklchToHexGamut(L, C, hue)
|
|
624
|
+
};
|
|
625
|
+
});
|
|
626
|
+
shadeDefs.push({
|
|
627
|
+
name,
|
|
628
|
+
hex: hexColor
|
|
629
|
+
});
|
|
630
|
+
return shadeDefs;
|
|
631
|
+
}
|
|
632
|
+
//#endregion
|
|
633
|
+
//#region ../theme-core/src/palette/neutralScale.ts
|
|
634
|
+
function generateNeutralScale({ background, steps = 11, warm = false }) {
|
|
635
|
+
const isDark = background === "#000000" || background.startsWith("#0") || background.startsWith("#1");
|
|
636
|
+
const shadeNames = [
|
|
637
|
+
50,
|
|
638
|
+
100,
|
|
639
|
+
200,
|
|
640
|
+
300,
|
|
641
|
+
400,
|
|
642
|
+
500,
|
|
643
|
+
600,
|
|
644
|
+
700,
|
|
645
|
+
800,
|
|
646
|
+
900,
|
|
647
|
+
950
|
|
648
|
+
];
|
|
649
|
+
const count = Math.min(steps, shadeNames.length);
|
|
650
|
+
const scale = [];
|
|
651
|
+
for (let i = 0; i < count; i++) {
|
|
652
|
+
const shadeName = shadeNames[i] ?? shadeNames[shadeNames.length - 1] ?? 950;
|
|
653
|
+
const t = i / (count - 1);
|
|
654
|
+
const hex = oklchToHexGamut(isDark ? mix(.06, .92, t) : mix(.98, .1, t), .02, warm ? 85 : 250);
|
|
655
|
+
const name = `neutral-${shadeName}`;
|
|
656
|
+
scale.push({
|
|
657
|
+
name,
|
|
658
|
+
hex
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
return scale;
|
|
662
|
+
}
|
|
663
|
+
function mix(a, b, t) {
|
|
664
|
+
return a + (b - a) * Math.max(0, Math.min(1, t));
|
|
665
|
+
}
|
|
666
|
+
//#endregion
|
|
667
|
+
//#region ../theme-core/src/palette/utils/textColor.ts
|
|
668
|
+
/**
|
|
669
|
+
* Pick the better of black/white text for a given background using actual
|
|
670
|
+
* contrast ratios, not a simple luminance cutoff. This is
|
|
671
|
+
* `maxContrastBlackOrWhite` for a solid ground.
|
|
672
|
+
*
|
|
673
|
+
* @param background - Background color in hex or rgb/rgba format (e.g., '#FFFFFF' or 'rgb(255, 255, 255)')
|
|
674
|
+
* @param _minContrast - Kept for callers. It cannot change the result: when
|
|
675
|
+
* only one of black or white reaches it, that one is also the better of the two.
|
|
676
|
+
* @returns '#000000' for light backgrounds, '#FFFFFF' for dark backgrounds
|
|
677
|
+
*/
|
|
678
|
+
function pickBlackOrWhiteTextColor(background, _minContrast = 4.5) {
|
|
679
|
+
const { r, g, b } = parseColorToRgb(background);
|
|
680
|
+
return maxContrastBlackOrWhite(luminanceInterval(relativeLuminance(r, g, b))).ink === "black" ? "#000000" : "#FFFFFF";
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* Backwards-compatible alias for callers that want the best black/white text
|
|
684
|
+
* color for a background.
|
|
685
|
+
*/
|
|
686
|
+
function getTextColorForBackground(background) {
|
|
687
|
+
return pickBlackOrWhiteTextColor(background);
|
|
688
|
+
}
|
|
689
|
+
function parseColorToRgb(input) {
|
|
690
|
+
const trimmed = input.trim();
|
|
691
|
+
if (trimmed.startsWith("#")) return hexToRgb(trimmed);
|
|
692
|
+
const rgbMatch = trimmed.match(/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)$/i);
|
|
693
|
+
if (rgbMatch?.[1] && rgbMatch[2] && rgbMatch[3]) return {
|
|
694
|
+
r: clamp255(Number(rgbMatch[1])),
|
|
695
|
+
g: clamp255(Number(rgbMatch[2])),
|
|
696
|
+
b: clamp255(Number(rgbMatch[3]))
|
|
697
|
+
};
|
|
698
|
+
throw new Error("Unsupported color format");
|
|
699
|
+
}
|
|
700
|
+
function clamp255(value) {
|
|
701
|
+
if (Number.isNaN(value)) return 0;
|
|
702
|
+
return Math.max(0, Math.min(255, value));
|
|
703
|
+
}
|
|
704
|
+
//#endregion
|
|
705
|
+
//#region ../theme-core/src/palette/utils/onColor.ts
|
|
706
|
+
const BACKGROUND_ROLE_NAMES = /* @__PURE__ */ new Set([
|
|
707
|
+
"primary",
|
|
708
|
+
"secondary",
|
|
709
|
+
"accent",
|
|
710
|
+
"success",
|
|
711
|
+
"warning",
|
|
712
|
+
"destructive",
|
|
713
|
+
"info",
|
|
714
|
+
"background",
|
|
715
|
+
"surface",
|
|
716
|
+
"surfaceAlt",
|
|
717
|
+
"muted",
|
|
718
|
+
"neutral"
|
|
719
|
+
]);
|
|
720
|
+
function onColorTokenName(backgroundToken) {
|
|
721
|
+
return `on${backgroundToken.split("-").filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")}`;
|
|
722
|
+
}
|
|
723
|
+
function isOnColorBackgroundCandidateToken(token) {
|
|
724
|
+
const role = token.match(/^(.*?)(?:-\d{2,3})?$/)?.[1] ?? token;
|
|
725
|
+
return BACKGROUND_ROLE_NAMES.has(role);
|
|
726
|
+
}
|
|
727
|
+
//#endregion
|
|
728
|
+
//#region ../theme-core/src/palette/expandPalette.ts
|
|
729
|
+
function colorsToMap(palette) {
|
|
730
|
+
const map = {};
|
|
731
|
+
for (const c of palette.colors) map[c.name] = c.hex;
|
|
732
|
+
return map;
|
|
733
|
+
}
|
|
734
|
+
function isBackgroundDark(hex) {
|
|
735
|
+
try {
|
|
736
|
+
return featuresFromHex(hex).Y < .5;
|
|
737
|
+
} catch {
|
|
738
|
+
return false;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
const nonShadeablePaletteRoleNames = /* @__PURE__ */ new Set([
|
|
742
|
+
"success",
|
|
743
|
+
"warning",
|
|
744
|
+
"destructive"
|
|
745
|
+
]);
|
|
746
|
+
/**
|
|
747
|
+
* Status role aliases the persisted palette does not carry itself.
|
|
748
|
+
*
|
|
749
|
+
* Generators reference `--tb-error` (the site-style-owned input error border)
|
|
750
|
+
* and `--tb-info` (`.alert-info`, `.status-info`, the field-note rule), but the
|
|
751
|
+
* palette schema only defines `destructive` and has no `info` role at all.
|
|
752
|
+
* Without these aliases those declarations name variables that are never
|
|
753
|
+
* defined and browsers drop them. The SDK bridge resolves the same pair via
|
|
754
|
+
* TOKEN_ALIASES, so both runtimes agree on what a status token means.
|
|
755
|
+
*
|
|
756
|
+
* Runs after the danger → destructive promotion above, so `destructive` is
|
|
757
|
+
* already the single source of truth for the error colour.
|
|
758
|
+
*/
|
|
759
|
+
function statusAliasTokens(expanded) {
|
|
760
|
+
const aliases = {};
|
|
761
|
+
if (expanded.destructive) aliases.error = expanded.destructive;
|
|
762
|
+
if (expanded.accent) aliases.info = expanded.accent;
|
|
763
|
+
return aliases;
|
|
764
|
+
}
|
|
765
|
+
function expandPalette(palette, options = {}) {
|
|
766
|
+
return {
|
|
767
|
+
...expandBasePalette(palette),
|
|
768
|
+
...arrangementPaletteTokens(colorsToMap(palette), options)
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
function expandBasePalette(palette) {
|
|
772
|
+
const base = colorsToMap(palette);
|
|
773
|
+
const expanded = { ...base };
|
|
774
|
+
generateNeutralScale({
|
|
775
|
+
background: base.background || base.surface || "#ffffff",
|
|
776
|
+
steps: 11,
|
|
777
|
+
warm: false
|
|
778
|
+
}).forEach((n) => {
|
|
779
|
+
expanded[n.name] = n.hex;
|
|
780
|
+
});
|
|
781
|
+
for (const [name, hex] of Object.entries(base)) {
|
|
782
|
+
if (nonShadeablePaletteRoleNames.has(name)) continue;
|
|
783
|
+
if (hex) generateShades(hex, name).forEach((shade) => {
|
|
784
|
+
expanded[shade.name] = shade.hex;
|
|
785
|
+
});
|
|
786
|
+
}
|
|
787
|
+
if (base.text) expanded.body = base.text;
|
|
788
|
+
if (base.danger && !base.destructive) expanded.destructive = base.danger;
|
|
789
|
+
Object.assign(expanded, statusAliasTokens(expanded));
|
|
790
|
+
const isDark = base.background ? isBackgroundDark(base.background) : false;
|
|
791
|
+
expanded.mutedText = palette.meta?.mode === "dark" || isDark ? expanded["neutral-600"] ?? "#666" : expanded["neutral-500"] ?? "#888";
|
|
792
|
+
for (const [token, hex] of Object.entries({ ...expanded })) {
|
|
793
|
+
if (!hex || !isOnColorBackgroundCandidateToken(token)) continue;
|
|
794
|
+
const onToken = onColorTokenName(token);
|
|
795
|
+
if (expanded[onToken]) continue;
|
|
796
|
+
expanded[onToken] = getTextColorForBackground(hex);
|
|
797
|
+
}
|
|
798
|
+
return expanded;
|
|
799
|
+
}
|
|
800
|
+
/** Derived decoration colours never become editable palette swatches. */
|
|
801
|
+
function deriveSurfaceDecorationColors(ground, text, accent) {
|
|
802
|
+
const ink = getTextColorForBackground(ground);
|
|
803
|
+
return {
|
|
804
|
+
line: firstContrastBlend(ground, text, ground, 1.5),
|
|
805
|
+
mark: firstContrastBlend(accent, ink, ground, 3)
|
|
806
|
+
};
|
|
807
|
+
}
|
|
808
|
+
/** Secondary ink is blended toward its ground, with an ordinary-text contrast floor. */
|
|
809
|
+
function deriveSurfaceMutedColor(ground, text) {
|
|
810
|
+
const start = hexToRgb(ground);
|
|
811
|
+
const end = hexToRgb(text);
|
|
812
|
+
const sample = (index) => rgbToHex(mix$1(start.r, end.r, index / 100), mix$1(start.g, end.g, index / 100), mix$1(start.b, end.b, index / 100));
|
|
813
|
+
return firstSafeMutedSample(sample, ground, 0, 100);
|
|
814
|
+
}
|
|
815
|
+
/** The blend moves monotonically from the ground toward its validated ink. */
|
|
816
|
+
function firstSafeMutedSample(sample, ground, low, high) {
|
|
817
|
+
if (low === high) return sample(high);
|
|
818
|
+
const middle = Math.floor((low + high) / 2);
|
|
819
|
+
return contrastRatio(sample(middle), ground) >= 4.5 ? firstSafeMutedSample(sample, ground, low, middle) : firstSafeMutedSample(sample, ground, middle + 1, high);
|
|
820
|
+
}
|
|
821
|
+
function firstContrastBlend(from, to, ground, threshold) {
|
|
822
|
+
const start = hexToRgb(from);
|
|
823
|
+
const end = hexToRgb(to);
|
|
824
|
+
return Array.from({ length: 101 }, (_, index) => {
|
|
825
|
+
const amount = index / 100;
|
|
826
|
+
return rgbToHex(mix$1(start.r, end.r, amount), mix$1(start.g, end.g, amount), mix$1(start.b, end.b, amount));
|
|
827
|
+
}).find((hex) => contrastRatio(hex, ground) >= threshold) ?? to;
|
|
828
|
+
}
|
|
829
|
+
/** `markSource` names the colour surface marks are derived from when a style marks in its brand rather than its accent. */
|
|
830
|
+
function arrangementPaletteTokens(base, options) {
|
|
831
|
+
if (options.arrangement !== true || !base.text) return {};
|
|
832
|
+
return {
|
|
833
|
+
onText: getTextColorForBackground(base.text),
|
|
834
|
+
...options.marksFrom === "primary" && base.primary ? { markSource: base.primary } : {}
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
//#endregion
|
|
838
|
+
//#region ../theme-core/src/surfaces/inkCertificate.ts
|
|
839
|
+
/**
|
|
840
|
+
* The ink certificate: every colour the site paints text or a mark on is held to
|
|
841
|
+
* its threshold here, on every backdrop it shows. An ink that misses takes the
|
|
842
|
+
* black/white ink that clears all of them; inks that pass are kept as they are,
|
|
843
|
+
* so a palette that already passes paints exactly what it declared. It never
|
|
844
|
+
* throws, because owner palettes are arbitrary.
|
|
845
|
+
*
|
|
846
|
+
* Surfaces (`certifySurface`), every measured foreground (`resolveSurfaceForeground`)
|
|
847
|
+
* and the chrome colours painted outside a foreground contract all certify here.
|
|
848
|
+
*/
|
|
849
|
+
const contrastThresholdByPolicy = {
|
|
850
|
+
"body-aa": 4.5,
|
|
851
|
+
"large-text-aa": 3,
|
|
852
|
+
decorative: 1
|
|
853
|
+
};
|
|
854
|
+
/** Headings are large text; every other foreground role is ordinary text. */
|
|
855
|
+
const surfaceTextPolicy = Object.freeze({
|
|
856
|
+
heading: "large-text-aa",
|
|
857
|
+
text: "body-aa",
|
|
858
|
+
link: "body-aa",
|
|
859
|
+
linkHover: "body-aa",
|
|
860
|
+
supporting: "body-aa",
|
|
861
|
+
muted: "body-aa"
|
|
862
|
+
});
|
|
863
|
+
/**
|
|
864
|
+
* Text shown only while a pointer hovers needs 3:1: the reader has already
|
|
865
|
+
* found it at rest, where it holds 4.5:1. States that stay on screen (open,
|
|
866
|
+
* the current-page link) keep the text threshold.
|
|
867
|
+
*/
|
|
868
|
+
const HOVER_TEXT_THRESHOLD = contrastThresholdByPolicy["large-text-aa"];
|
|
869
|
+
const FALLBACK_INKS = ["#000000", "#FFFFFF"];
|
|
870
|
+
const isFallbackInk = (ink) => FALLBACK_INKS.includes(ink);
|
|
871
|
+
function inkReference(ink) {
|
|
872
|
+
return isFallbackInk(ink) ? `raw:${ink}` : ink;
|
|
873
|
+
}
|
|
874
|
+
/** A token, `rgba()` or literal, composited over each backdrop, clears the threshold on all of them. */
|
|
875
|
+
function inkClearsBackdrops(ink, threshold, backdrops, measurement) {
|
|
876
|
+
return backdrops.every((backdrop) => {
|
|
877
|
+
const hex = resolveOpaqueSurfaceHex(ink, measurement.palette, backdrop);
|
|
878
|
+
return hex !== null && contrastRatio(hex, backdrop, measurement.colourIndex) >= threshold;
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
/** The black/white ink that clears every backdrop at ordinary-text contrast, preferring the best one for the painted end. */
|
|
882
|
+
function fallbackInk(backdrops, measurement) {
|
|
883
|
+
const [endpoint] = backdrops.slice(-1);
|
|
884
|
+
return [...endpoint ? [pickBlackOrWhiteTextColor(endpoint)] : [], ...FALLBACK_INKS].find((candidate) => inkClearsBackdrops(candidate, contrastThresholdByPolicy["body-aa"], backdrops, measurement)) ?? null;
|
|
885
|
+
}
|
|
886
|
+
function failingInks(inks, backdrops, measurement) {
|
|
887
|
+
return {
|
|
888
|
+
roles: Object.keys(inks.foreground).filter((role) => !inkClearsBackdrops(inks.foreground[role], contrastThresholdByPolicy[surfaceTextPolicy[role]], backdrops, measurement)),
|
|
889
|
+
mark: inks.mark !== void 0 && !inkClearsBackdrops(inks.mark, 3, backdrops, measurement) ? ["mark"] : []
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
function replaceFailing(inks, failing, ink) {
|
|
893
|
+
return {
|
|
894
|
+
foreground: {
|
|
895
|
+
...inks.foreground,
|
|
896
|
+
...Object.fromEntries(failing.roles.map((role) => [role, ink]))
|
|
897
|
+
},
|
|
898
|
+
...inks.mark === void 0 ? {} : { mark: failing.mark.length > 0 ? ink : inks.mark },
|
|
899
|
+
fallback: [...failing.roles, ...failing.mark]
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
/**
|
|
903
|
+
* Hold every role to its text policy and the mark to 3:1 on every backdrop.
|
|
904
|
+
* Null only when neither black nor white clears every backdrop, which only a
|
|
905
|
+
* radial tint's samples can do: `certifySolidSurfaceInks` is the total form for
|
|
906
|
+
* one solid backdrop.
|
|
907
|
+
*/
|
|
908
|
+
function certifySurfaceInks(inks, backdrops, measurement) {
|
|
909
|
+
const failing = failingInks(inks, backdrops, measurement);
|
|
910
|
+
if (failing.roles.length === 0 && failing.mark.length === 0) return {
|
|
911
|
+
...inks,
|
|
912
|
+
fallback: []
|
|
913
|
+
};
|
|
914
|
+
const ink = fallbackInk(backdrops, measurement);
|
|
915
|
+
return ink ? replaceFailing(inks, failing, ink) : null;
|
|
916
|
+
}
|
|
917
|
+
/** One solid backdrop: black or white always reaches 4.58:1 on it, so certification always succeeds. */
|
|
918
|
+
function certifySolidSurfaceInks(inks, backdrop, measurement) {
|
|
919
|
+
const failing = failingInks(inks, [backdrop], measurement);
|
|
920
|
+
if (failing.roles.length === 0 && failing.mark.length === 0) return {
|
|
921
|
+
...inks,
|
|
922
|
+
fallback: []
|
|
923
|
+
};
|
|
924
|
+
return replaceFailing(inks, failing, pickBlackOrWhiteTextColor(backdrop));
|
|
925
|
+
}
|
|
926
|
+
/** Kept when the ink clears the threshold, otherwise the black/white ink, which always clears a solid backdrop. */
|
|
927
|
+
function certifyPaint(place, ink, threshold, backdrop, measurement) {
|
|
928
|
+
return inkClearsBackdrops(ink, threshold, [backdrop], measurement) ? {
|
|
929
|
+
place,
|
|
930
|
+
ink,
|
|
931
|
+
backdrop,
|
|
932
|
+
threshold,
|
|
933
|
+
fallback: false
|
|
934
|
+
} : {
|
|
935
|
+
place,
|
|
936
|
+
ink: pickBlackOrWhiteTextColor(backdrop),
|
|
937
|
+
backdrop,
|
|
938
|
+
threshold,
|
|
939
|
+
fallback: true,
|
|
940
|
+
declared: ink
|
|
941
|
+
};
|
|
942
|
+
}
|
|
943
|
+
//#endregion
|
|
944
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/assertClassBrand.js
|
|
945
|
+
function _assertClassBrand(e, t, n) {
|
|
946
|
+
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
947
|
+
throw new TypeError("Private element is not present on this object");
|
|
948
|
+
}
|
|
949
|
+
//#endregion
|
|
950
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/classPrivateFieldSet2.js
|
|
951
|
+
function _classPrivateFieldSet2(s, a, r) {
|
|
952
|
+
return s.set(_assertClassBrand(s, a), r), r;
|
|
953
|
+
}
|
|
954
|
+
//#endregion
|
|
955
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/classPrivateFieldGet2.js
|
|
956
|
+
function _classPrivateFieldGet2(s, a) {
|
|
957
|
+
return s.get(_assertClassBrand(s, a));
|
|
958
|
+
}
|
|
959
|
+
//#endregion
|
|
960
|
+
//#region ../theme-core/src/palette/family.ts
|
|
961
|
+
var _members = /* @__PURE__ */ new WeakMap();
|
|
962
|
+
/**
|
|
963
|
+
* Only `colourFamily` makes one (the class is not exported), so a caller can't
|
|
964
|
+
* swap in its own members and still hand the solver a valid family. That
|
|
965
|
+
* matters because `unpaintable` relies on the members running from black to
|
|
966
|
+
* white.
|
|
967
|
+
*/
|
|
968
|
+
var Family = class {
|
|
969
|
+
constructor(seed, members) {
|
|
970
|
+
this.seed = seed;
|
|
971
|
+
_classPrivateFieldInitSpec(this, _members, void 0);
|
|
972
|
+
_classPrivateFieldSet2(_members, this, Object.freeze(members));
|
|
973
|
+
}
|
|
974
|
+
/** Unique by hex, ascending luminance. Includes the exact seed, black and white. */
|
|
975
|
+
get members() {
|
|
976
|
+
return _classPrivateFieldGet2(_members, this);
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
const GAMUT_BISECTION_STEPS = 18;
|
|
980
|
+
/** The highest chroma at or below `c` that stays inside sRGB at this lightness and hue. */
|
|
981
|
+
function gamutChroma(l, c, h) {
|
|
982
|
+
if (inLinearSrgbGamut(oklchToLinearSrgb(l, c, h))) return c;
|
|
983
|
+
return Array.from({ length: GAMUT_BISECTION_STEPS }).reduce(({ lo, hi }) => {
|
|
984
|
+
const mid = (lo + hi) / 2;
|
|
985
|
+
return inLinearSrgbGamut(oklchToLinearSrgb(l, mid, h)) ? {
|
|
986
|
+
lo: mid,
|
|
987
|
+
hi
|
|
988
|
+
} : {
|
|
989
|
+
lo,
|
|
990
|
+
hi: mid
|
|
991
|
+
};
|
|
992
|
+
}, {
|
|
993
|
+
lo: 0,
|
|
994
|
+
hi: c
|
|
995
|
+
}).lo;
|
|
996
|
+
}
|
|
997
|
+
function oklabDistance(a, b) {
|
|
998
|
+
return Math.hypot(a.L - b.L, a.a - b.a, a.b - b.b);
|
|
999
|
+
}
|
|
1000
|
+
/** OKLab distance between two rendered opaque hex colours. */
|
|
1001
|
+
function hexOklabDistance(first, second) {
|
|
1002
|
+
const lab = (hex) => {
|
|
1003
|
+
const { r, g, b } = hexToRgb(hex);
|
|
1004
|
+
return srgbToOklab(r, g, b);
|
|
1005
|
+
};
|
|
1006
|
+
return oklabDistance(lab(first), lab(second));
|
|
1007
|
+
}
|
|
1008
|
+
function colourFamily(seedHex) {
|
|
1009
|
+
if (!/^#[0-9a-f]{6}$/i.test(seedHex)) throw new Error(`Expected an opaque #rrggbb colour: ${seedHex}`);
|
|
1010
|
+
const features = featuresFromHex(seedHex.toLowerCase());
|
|
1011
|
+
const seed = member(seedHex.toLowerCase(), {
|
|
1012
|
+
l: features.okL,
|
|
1013
|
+
c: features.okC,
|
|
1014
|
+
h: features.okH
|
|
1015
|
+
});
|
|
1016
|
+
const seedTaper = Math.max(.001, Math.sin(Math.PI * seed.sample.l));
|
|
1017
|
+
const samples = Array.from({ length: 513 }, (_, i) => {
|
|
1018
|
+
const l = i / 512;
|
|
1019
|
+
return sampleMember({
|
|
1020
|
+
l,
|
|
1021
|
+
c: gamutChroma(l, seed.sample.c * Math.min(1, Math.sin(Math.PI * l) / seedTaper), seed.sample.h),
|
|
1022
|
+
h: seed.sample.h
|
|
1023
|
+
});
|
|
1024
|
+
});
|
|
1025
|
+
return new Family(seed, [...new Map([seed, ...samples].map((candidate) => [candidate.hex, candidate]).reverse()).values()].sort((a, b) => a.y - b.y || (a.hex < b.hex ? -1 : a.hex > b.hex ? 1 : 0)));
|
|
1026
|
+
}
|
|
1027
|
+
function sampleMember(sample) {
|
|
1028
|
+
const { r, g, b } = oklchToLinearSrgb(sample.l, sample.c, sample.h);
|
|
1029
|
+
return member(rgbToHex(linearToSrgb(r), linearToSrgb(g), linearToSrgb(b)), sample);
|
|
1030
|
+
}
|
|
1031
|
+
function member(hex, sample) {
|
|
1032
|
+
const { r, g, b } = hexToRgb(hex);
|
|
1033
|
+
return {
|
|
1034
|
+
hex,
|
|
1035
|
+
y: hexLuminance(hex),
|
|
1036
|
+
oklab: srgbToOklab(r, g, b),
|
|
1037
|
+
sample
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
//#endregion
|
|
1041
|
+
//#region ../theme-core/src/palette/utils/inkSolver.ts
|
|
1042
|
+
/**
|
|
1043
|
+
* How far (OKLab ΔE) a brand colour drawn as ink may be nudged along its own
|
|
1044
|
+
* family before it stops reading as that colour. Past this the caller uses
|
|
1045
|
+
* neutral or palette text instead (Will, 2026-10-14).
|
|
1046
|
+
*/
|
|
1047
|
+
const BRAND_INK_MAX_DELTA_E = .08;
|
|
1048
|
+
/**
|
|
1049
|
+
* The seed itself when it clears `paint`, otherwise the family member nearest
|
|
1050
|
+
* the seed (OKLab ΔE) that clears. On a light ground that is darker, on a dark
|
|
1051
|
+
* one lighter. A passing member further than `maxDistance` from the seed is
|
|
1052
|
+
* refused as `too-far`, which is distinct from `unpaintable`: the family runs
|
|
1053
|
+
* from black to white, so if no member clears, neither does black or white.
|
|
1054
|
+
*/
|
|
1055
|
+
function inkFrom(family, paint, ratio, maxDistance = BRAND_INK_MAX_DELTA_E) {
|
|
1056
|
+
assertContrastRatio(ratio);
|
|
1057
|
+
if (!Number.isFinite(maxDistance) || maxDistance < 0) throw new RangeError(`Maximum ink distance must be finite and not negative: ${maxDistance}`);
|
|
1058
|
+
const seedRatio = worstContrast(family.seed.y, paint);
|
|
1059
|
+
if (seedRatio >= ratio) return {
|
|
1060
|
+
kind: "ink",
|
|
1061
|
+
hex: family.seed.hex,
|
|
1062
|
+
ratio: seedRatio,
|
|
1063
|
+
source: "exact"
|
|
1064
|
+
};
|
|
1065
|
+
const nearest = family.members.reduce((best, member) => {
|
|
1066
|
+
const achieved = worstContrast(member.y, paint);
|
|
1067
|
+
if (achieved < ratio) return best;
|
|
1068
|
+
const distance = oklabDistance(member.oklab, family.seed.oklab);
|
|
1069
|
+
return best === null || distance < best.distance ? {
|
|
1070
|
+
hex: member.hex,
|
|
1071
|
+
distance,
|
|
1072
|
+
ratio: achieved
|
|
1073
|
+
} : best;
|
|
1074
|
+
}, null);
|
|
1075
|
+
if (nearest === null) return {
|
|
1076
|
+
kind: "unpaintable",
|
|
1077
|
+
interval: paint,
|
|
1078
|
+
ratio
|
|
1079
|
+
};
|
|
1080
|
+
if (nearest.distance > maxDistance) return {
|
|
1081
|
+
kind: "too-far",
|
|
1082
|
+
nearest: {
|
|
1083
|
+
hex: nearest.hex,
|
|
1084
|
+
distance: nearest.distance
|
|
1085
|
+
},
|
|
1086
|
+
maxDistance
|
|
1087
|
+
};
|
|
1088
|
+
return {
|
|
1089
|
+
kind: "ink",
|
|
1090
|
+
hex: nearest.hex,
|
|
1091
|
+
ratio: nearest.ratio,
|
|
1092
|
+
source: "family"
|
|
1093
|
+
};
|
|
1094
|
+
}
|
|
1095
|
+
//#endregion
|
|
1096
|
+
//#region ../theme-core/src/surfaces/surfaceInks.ts
|
|
1097
|
+
const INK_SEEDS = {
|
|
1098
|
+
brand: {
|
|
1099
|
+
token: "primary",
|
|
1100
|
+
ratio: ORDINARY_TEXT_MIN_CONTRAST_RATIO
|
|
1101
|
+
},
|
|
1102
|
+
accent: {
|
|
1103
|
+
token: "accent",
|
|
1104
|
+
ratio: ORDINARY_TEXT_MIN_CONTRAST_RATIO
|
|
1105
|
+
},
|
|
1106
|
+
focus: {
|
|
1107
|
+
token: "primary",
|
|
1108
|
+
ratio: 3
|
|
1109
|
+
}
|
|
1110
|
+
};
|
|
1111
|
+
/**
|
|
1112
|
+
* Solve the three inks for a measured solid paint. `textInk` is the surface's
|
|
1113
|
+
* own (already certified) text ink: it stands in when the owner's colour is
|
|
1114
|
+
* missing, or can only clear the paint by drifting too far from itself.
|
|
1115
|
+
* A block owner can supply an authored shade candidate for a local ink.
|
|
1116
|
+
*/
|
|
1117
|
+
function solveSurfaceInks(backdropHex, textInk, palette, candidates = {}) {
|
|
1118
|
+
const paint = solidPaint(backdropHex);
|
|
1119
|
+
const fallback = literalInk(resolveConcreteColorHex(textInk, palette) ?? pickBlackOrWhiteTextColor(backdropHex));
|
|
1120
|
+
return {
|
|
1121
|
+
brand: solveInk({
|
|
1122
|
+
...INK_SEEDS.brand,
|
|
1123
|
+
token: candidates.brand ?? INK_SEEDS.brand.token
|
|
1124
|
+
}, paint, palette, fallback),
|
|
1125
|
+
accent: solveInk({
|
|
1126
|
+
...INK_SEEDS.accent,
|
|
1127
|
+
token: candidates.accent ?? INK_SEEDS.accent.token
|
|
1128
|
+
}, paint, palette, fallback),
|
|
1129
|
+
focus: solveInk({
|
|
1130
|
+
...INK_SEEDS.focus,
|
|
1131
|
+
token: candidates.focus ?? INK_SEEDS.focus.token
|
|
1132
|
+
}, paint, palette, fallback)
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
function solveInk(seed, paint, palette, fallback) {
|
|
1136
|
+
const token = parseThemeColorToken(seed.token);
|
|
1137
|
+
const seedHex = hexColorSchema.safeParse(resolveConcreteColorHex(seed.token, palette));
|
|
1138
|
+
if (!token || !seedHex.success) return fallback;
|
|
1139
|
+
const solved = inkFrom(familyOf(seedHex.data), paint, seed.ratio);
|
|
1140
|
+
switch (solved.kind) {
|
|
1141
|
+
case "ink": return solved.source === "exact" ? token : literalInk(solved.hex);
|
|
1142
|
+
case "too-far":
|
|
1143
|
+
case "unpaintable": return fallback;
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
function literalInk(hex) {
|
|
1147
|
+
return hexColorSchema.parse(hex.toLowerCase());
|
|
1148
|
+
}
|
|
1149
|
+
const FAMILY_CACHE_LIMIT = 64;
|
|
1150
|
+
const families = /* @__PURE__ */ new Map();
|
|
1151
|
+
function familyOf(seed) {
|
|
1152
|
+
const cached = families.get(seed);
|
|
1153
|
+
if (cached) return cached;
|
|
1154
|
+
if (families.size >= FAMILY_CACHE_LIMIT) families.clear();
|
|
1155
|
+
const family = colourFamily(seed);
|
|
1156
|
+
families.set(seed, family);
|
|
1157
|
+
return family;
|
|
1158
|
+
}
|
|
1159
|
+
//#endregion
|
|
1160
|
+
//#region ../theme-core/src/surfaces/resolveSurfaceForeground.ts
|
|
1161
|
+
const FALLBACK_TEXT_TOKENS = [
|
|
1162
|
+
"text",
|
|
1163
|
+
"primaryForeground",
|
|
1164
|
+
"secondaryForeground",
|
|
1165
|
+
"accentForeground",
|
|
1166
|
+
"neutral-950",
|
|
1167
|
+
"neutral-50"
|
|
1168
|
+
];
|
|
1169
|
+
const CANONICAL_EQUIVALENT_TOKEN_ORDER = [
|
|
1170
|
+
"text",
|
|
1171
|
+
"primaryForeground",
|
|
1172
|
+
"secondaryForeground",
|
|
1173
|
+
"accentForeground",
|
|
1174
|
+
"onPrimary",
|
|
1175
|
+
"onSecondary",
|
|
1176
|
+
"onAccent",
|
|
1177
|
+
"onSurface",
|
|
1178
|
+
"neutral-950",
|
|
1179
|
+
"neutral-50"
|
|
1180
|
+
];
|
|
1181
|
+
function resolveSurfaceForeground(background, palette, candidates = {}, options = {}) {
|
|
1182
|
+
const authored = foregroundCandidates(background, candidates);
|
|
1183
|
+
if ("measuredBackdrop" in options) return resolveMeasuredForeground(background?.color ?? "background", options.measuredBackdrop, authored, palette);
|
|
1184
|
+
return resolveAuthoredBackground(background, palette, authored, options);
|
|
1185
|
+
}
|
|
1186
|
+
/** Legacy references may be measurable, inherited, or a trusted media treatment. */
|
|
1187
|
+
function resolveAuthoredBackground(background, palette, authored, options) {
|
|
1188
|
+
if (background === null) return resolveDeterministicForeground("background", {
|
|
1189
|
+
...authored,
|
|
1190
|
+
text: authored.text ?? "text"
|
|
1191
|
+
}, palette);
|
|
1192
|
+
if (background.type === "color") {
|
|
1193
|
+
const backgroundReference = normalizedReference(background.color);
|
|
1194
|
+
if (!backgroundReference || backgroundReference === "transparent") return { kind: "inherits" };
|
|
1195
|
+
return resolveDeterministicForeground(backgroundReference, authored, palette, options.compositeBase);
|
|
1196
|
+
}
|
|
1197
|
+
return resolveTrustedTreatmentForeground(authored, palette);
|
|
1198
|
+
}
|
|
1199
|
+
function foregroundCandidates(background, overrides) {
|
|
1200
|
+
return {
|
|
1201
|
+
text: candidateOrBackground(overrides.text, background?.textColor),
|
|
1202
|
+
heading: candidateOrBackground(overrides.heading, background?.headingColor),
|
|
1203
|
+
link: candidateOrBackground(overrides.link, background?.linkColor),
|
|
1204
|
+
linkHover: candidateOrBackground(overrides.linkHover),
|
|
1205
|
+
supporting: candidateOrBackground(overrides.supporting, background?.supportingColor)
|
|
1206
|
+
};
|
|
1207
|
+
}
|
|
1208
|
+
function candidateOrBackground(candidate, backgroundValue) {
|
|
1209
|
+
return candidate ?? backgroundValue ?? null;
|
|
1210
|
+
}
|
|
1211
|
+
function resolveDeterministicForeground(backgroundReference, candidates, palette, compositeBase) {
|
|
1212
|
+
const backgroundHex = resolveOpaqueSurfaceHex(backgroundReference, palette, compositeBase);
|
|
1213
|
+
if (!backgroundHex) return resolveTrustedTreatmentForeground(candidates, palette);
|
|
1214
|
+
return resolveMeasuredForeground(backgroundReference, backgroundHex, candidates, palette);
|
|
1215
|
+
}
|
|
1216
|
+
function resolveMeasuredForeground(backgroundReference, backgroundHex, candidates, palette) {
|
|
1217
|
+
const backgroundToken = paletteToken(backgroundReference);
|
|
1218
|
+
const derivedOnToken = backgroundToken ? onColorTokenName(backgroundToken) : null;
|
|
1219
|
+
const text = firstSafeToken([
|
|
1220
|
+
candidates.text,
|
|
1221
|
+
derivedOnToken,
|
|
1222
|
+
...FALLBACK_TEXT_TOKENS
|
|
1223
|
+
], backgroundHex, palette, derivedOnToken ? [derivedOnToken] : []) ?? pickBlackOrWhiteTextColor(backgroundHex);
|
|
1224
|
+
return certifiedForeground(knownForeground({
|
|
1225
|
+
text,
|
|
1226
|
+
heading: safeTokenOr(candidates.heading, text, backgroundHex, palette),
|
|
1227
|
+
link: safeTokenOr(candidates.link, text, backgroundHex, palette),
|
|
1228
|
+
supporting: safeTokenOr(candidates.supporting, text, backgroundHex, palette)
|
|
1229
|
+
}, {
|
|
1230
|
+
kind: "measured",
|
|
1231
|
+
backdropHex: backgroundHex,
|
|
1232
|
+
inks: solveSurfaceInks(backgroundHex, text, palette)
|
|
1233
|
+
}, candidates.linkHover, palette), palette);
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Every measured foreground goes through the ink certificate, whoever paints it
|
|
1237
|
+
* (sections, cards, header, footer, accordions). The candidates above are chosen
|
|
1238
|
+
* to pass, so the certificate is normally a no-op and the foreground is returned
|
|
1239
|
+
* as it was; an ink that misses takes black/white, and the solved inks follow
|
|
1240
|
+
* the certified text.
|
|
1241
|
+
*/
|
|
1242
|
+
function certifiedForeground(foreground, palette) {
|
|
1243
|
+
const { backdropHex } = foreground.provenance;
|
|
1244
|
+
const certified = certifySolidSurfaceInks({ foreground: foreground.roles }, backdropHex, { palette });
|
|
1245
|
+
if (certified.fallback.length === 0) return foreground;
|
|
1246
|
+
return {
|
|
1247
|
+
...foreground,
|
|
1248
|
+
roles: certified.foreground,
|
|
1249
|
+
provenance: {
|
|
1250
|
+
...foreground.provenance,
|
|
1251
|
+
inks: solveSurfaceInks(backdropHex, certified.foreground.text, palette),
|
|
1252
|
+
fallback: certified.fallback
|
|
1253
|
+
}
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
function resolveTrustedTreatmentForeground(candidates, palette) {
|
|
1257
|
+
const text = canonicalToken(candidates.text, palette);
|
|
1258
|
+
if (!text) return { kind: "unmeasured-paint" };
|
|
1259
|
+
return knownForeground({
|
|
1260
|
+
text,
|
|
1261
|
+
heading: canonicalToken(candidates.heading, palette) ?? text,
|
|
1262
|
+
link: canonicalToken(candidates.link, palette) ?? text,
|
|
1263
|
+
supporting: canonicalToken(candidates.supporting, palette) ?? text
|
|
1264
|
+
}, { kind: "trusted-treatment" }, candidates.linkHover, palette);
|
|
1265
|
+
}
|
|
1266
|
+
function knownForeground(roles, provenance, hoverCandidate, palette) {
|
|
1267
|
+
const hover = planForegroundHover({
|
|
1268
|
+
restingToken: roles.link,
|
|
1269
|
+
candidate: canonicalHoverToken(hoverCandidate, palette),
|
|
1270
|
+
palette,
|
|
1271
|
+
backdrops: provenance.kind === "measured" ? [provenance.backdropHex] : null
|
|
1272
|
+
});
|
|
1273
|
+
return {
|
|
1274
|
+
kind: "known",
|
|
1275
|
+
provenance,
|
|
1276
|
+
roles: {
|
|
1277
|
+
...roles,
|
|
1278
|
+
linkHover: hover.token,
|
|
1279
|
+
muted: provenance.kind === "measured" ? deriveSurfaceMutedColor(provenance.backdropHex, resolveConcreteColorHex(roles.text, palette) ?? provenance.backdropHex) : roles.text
|
|
1280
|
+
},
|
|
1281
|
+
hoverDecoration: hover.decoration
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
function canonicalHoverToken(reference, palette) {
|
|
1285
|
+
const token = parseThemeColorToken(reference);
|
|
1286
|
+
if (token) {
|
|
1287
|
+
const parts = parseColorTokenParts(token);
|
|
1288
|
+
if (parts.kind === "token" && resolveConcreteColorHex(parts.token, palette)) return token;
|
|
1289
|
+
}
|
|
1290
|
+
return canonicalToken(reference, palette);
|
|
1291
|
+
}
|
|
1292
|
+
/**
|
|
1293
|
+
* The one rule for what a resolved foreground publishes for the solved inks.
|
|
1294
|
+
* Only a measured paint under a publishing runtime publishes inks; any other
|
|
1295
|
+
* paint it owns resets them, and a paint it only inherits publishes nothing.
|
|
1296
|
+
*/
|
|
1297
|
+
function surfaceInkPublication(foreground, policy) {
|
|
1298
|
+
switch (foreground.kind) {
|
|
1299
|
+
case "inherits": return { kind: "none" };
|
|
1300
|
+
case "unmeasured-paint": return { kind: "reset" };
|
|
1301
|
+
case "known": return foreground.provenance.kind === "measured" && policy === "publish" ? {
|
|
1302
|
+
kind: "solved",
|
|
1303
|
+
inks: foreground.provenance.inks
|
|
1304
|
+
} : { kind: "reset" };
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
/** Keep a candidate only when it meets ordinary-text contrast on the ground. */
|
|
1308
|
+
function safeTokenOr(candidate, fallback, backgroundHex, palette) {
|
|
1309
|
+
return firstSafeToken([candidate], backgroundHex, palette) ?? fallback;
|
|
1310
|
+
}
|
|
1311
|
+
function firstSafeToken(candidates, backgroundHex, palette, preferredEquivalentTokens = []) {
|
|
1312
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1313
|
+
for (const candidate of candidates) {
|
|
1314
|
+
const token = canonicalToken(candidate, palette, preferredEquivalentTokens);
|
|
1315
|
+
if (!token || seen.has(token)) continue;
|
|
1316
|
+
seen.add(token);
|
|
1317
|
+
const foregroundHex = resolveConcreteColorHex(token, palette);
|
|
1318
|
+
if (foregroundHex && contrastRatio(backgroundHex, foregroundHex) >= 4.5) return token;
|
|
1319
|
+
}
|
|
1320
|
+
return null;
|
|
1321
|
+
}
|
|
1322
|
+
function canonicalToken(reference, palette, preferredEquivalentTokens = []) {
|
|
1323
|
+
const normalized = normalizedReference(reference);
|
|
1324
|
+
if (!normalized || normalized === "transparent") return null;
|
|
1325
|
+
const direct = parseThemeColorToken(normalized);
|
|
1326
|
+
if (direct && resolveConcreteColorHex(direct, palette)) return direct;
|
|
1327
|
+
const referenceHex = resolveConcreteColorHex(normalized, palette);
|
|
1328
|
+
if (!referenceHex) return null;
|
|
1329
|
+
const equivalent = [
|
|
1330
|
+
...preferredEquivalentTokens,
|
|
1331
|
+
...CANONICAL_EQUIVALENT_TOKEN_ORDER,
|
|
1332
|
+
...Object.keys(palette).sort()
|
|
1333
|
+
].find((token) => {
|
|
1334
|
+
const parsed = parseThemeColorToken(token);
|
|
1335
|
+
return parsed !== null && resolveConcreteColorHex(parsed, palette)?.toLowerCase() === referenceHex.toLowerCase();
|
|
1336
|
+
});
|
|
1337
|
+
return equivalent ? parseThemeColorToken(equivalent) : null;
|
|
1338
|
+
}
|
|
1339
|
+
function paletteToken(reference) {
|
|
1340
|
+
const parts = parseColorTokenParts(reference);
|
|
1341
|
+
return parts.kind === "token" && parts.opacityPercent === null ? parts.token : null;
|
|
1342
|
+
}
|
|
1343
|
+
function normalizedReference(value) {
|
|
1344
|
+
if (typeof value !== "string") return null;
|
|
1345
|
+
const normalized = value.trim();
|
|
1346
|
+
return normalized.length > 0 ? normalized : null;
|
|
1347
|
+
}
|
|
1348
|
+
//#endregion
|
|
1349
|
+
//#region ../theme-core/src/utils/colorStyles.ts
|
|
1350
|
+
const COLOR_VAR_PREFIX = "--tb-";
|
|
1351
|
+
function parseToken(source) {
|
|
1352
|
+
const parts = parseColorTokenParts(source);
|
|
1353
|
+
if (parts.kind === "raw") return {
|
|
1354
|
+
token: source,
|
|
1355
|
+
raw: parts.value
|
|
1356
|
+
};
|
|
1357
|
+
if (parts.kind === "invalid") return { token: source };
|
|
1358
|
+
return {
|
|
1359
|
+
token: parts.token,
|
|
1360
|
+
opacityPercent: parts.opacityPercent === null ? void 0 : parts.opacityPercent
|
|
1361
|
+
};
|
|
1362
|
+
}
|
|
1363
|
+
const SURFACE_TEXT_ROLE_BY_TOKEN = {
|
|
1364
|
+
text: "text",
|
|
1365
|
+
heading: "heading",
|
|
1366
|
+
mutedText: "supporting"
|
|
1367
|
+
};
|
|
1368
|
+
function surfaceRoleForTextToken(token) {
|
|
1369
|
+
return Object.prototype.hasOwnProperty.call(SURFACE_TEXT_ROLE_BY_TOKEN, token) ? SURFACE_TEXT_ROLE_BY_TOKEN[token] : null;
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Converts a theme color token to a CSS rgb value.
|
|
1373
|
+
* This is the primary function for applying theme colors to CSS properties.
|
|
1374
|
+
*
|
|
1375
|
+
* @param token - Theme color token (semantic, with opacity, or raw)
|
|
1376
|
+
* @returns CSS color value (rgb with optional alpha, or raw CSS value)
|
|
1377
|
+
*
|
|
1378
|
+
* @example
|
|
1379
|
+
* rgbColorValue('primary') // => 'rgb(var(--tb-primary))'
|
|
1380
|
+
* rgbColorValue('surface/95') // => 'rgb(var(--tb-surface) / 0.95)'
|
|
1381
|
+
* rgbColorValue('raw:transparent') // => 'transparent'
|
|
1382
|
+
*/
|
|
1383
|
+
function rgbColorValue(token) {
|
|
1384
|
+
const { token: baseToken, opacityPercent, raw } = parseToken(token);
|
|
1385
|
+
if (raw) return raw;
|
|
1386
|
+
const cssVar = `${COLOR_VAR_PREFIX}${baseToken}`;
|
|
1387
|
+
if (opacityPercent === void 0) return `rgb(var(${cssVar}))`;
|
|
1388
|
+
return `rgb(var(${cssVar}) / ${opacityPercent / 100})`;
|
|
1389
|
+
}
|
|
1390
|
+
/**
|
|
1391
|
+
* Converts a theme color token to a CSS variable reference.
|
|
1392
|
+
* Note: This returns the base variable without rgb() wrapper, ignoring opacity.
|
|
1393
|
+
*
|
|
1394
|
+
* @param token - Theme color token
|
|
1395
|
+
* @returns CSS variable reference
|
|
1396
|
+
*
|
|
1397
|
+
* @example
|
|
1398
|
+
* cssVarValue('primary') // => 'var(--tb-primary)'
|
|
1399
|
+
* cssVarValue('surface/95') // => 'var(--tb-surface)' (opacity ignored)
|
|
1400
|
+
*/
|
|
1401
|
+
function cssVarValue(token) {
|
|
1402
|
+
const { token: baseToken } = parseToken(token);
|
|
1403
|
+
return `var(${COLOR_VAR_PREFIX}${baseToken})`;
|
|
1404
|
+
}
|
|
1405
|
+
/**
|
|
1406
|
+
* Creates a backgroundColor style object from a theme token.
|
|
1407
|
+
*
|
|
1408
|
+
* @param token - Theme color token
|
|
1409
|
+
* @returns CSSProperties with backgroundColor
|
|
1410
|
+
*/
|
|
1411
|
+
function backgroundColorStyle(token) {
|
|
1412
|
+
return { backgroundColor: rgbColorValue(token) };
|
|
1413
|
+
}
|
|
1414
|
+
/**
|
|
1415
|
+
* Converts a text color token to a CSS color value that follows the enclosing
|
|
1416
|
+
* surface. The semantic text tokens (`text`, `heading`, `mutedText`) resolve
|
|
1417
|
+
* to the surface foreground variables, so text adapts when a section's
|
|
1418
|
+
* background changes; any other token is a fixed theme color.
|
|
1419
|
+
*
|
|
1420
|
+
* @param token - Theme color token
|
|
1421
|
+
* @returns CSS color value
|
|
1422
|
+
*/
|
|
1423
|
+
function textColorValue(token) {
|
|
1424
|
+
const parsed = parseToken(token);
|
|
1425
|
+
const surfaceRole = parsed.raw ? null : surfaceRoleForTextToken(parsed.token);
|
|
1426
|
+
if (!surfaceRole) return rgbColorValue(token);
|
|
1427
|
+
return parsed.opacityPercent === void 0 ? surfaceForegroundValue(surfaceRole) : surfaceForegroundValueWithOpacity(surfaceRole, parsed.opacityPercent);
|
|
1428
|
+
}
|
|
1429
|
+
/**
|
|
1430
|
+
* Creates a text color style object from a theme token.
|
|
1431
|
+
*
|
|
1432
|
+
* @param token - Theme color token
|
|
1433
|
+
* @returns CSSProperties with color
|
|
1434
|
+
*/
|
|
1435
|
+
function textColorStyle(token) {
|
|
1436
|
+
return { color: textColorValue(token) };
|
|
1437
|
+
}
|
|
1438
|
+
/**
|
|
1439
|
+
* Creates a border color style object from a theme token.
|
|
1440
|
+
*
|
|
1441
|
+
* @param token - Theme color token
|
|
1442
|
+
* @returns CSSProperties with borderColor
|
|
1443
|
+
*/
|
|
1444
|
+
function borderColorStyle(token) {
|
|
1445
|
+
return { borderColor: rgbColorValue(token) };
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1448
|
+
* Merges multiple CSSProperties objects into a single object.
|
|
1449
|
+
* Later styles override earlier ones. Undefined values are filtered out.
|
|
1450
|
+
* Returns undefined if the merged result is empty.
|
|
1451
|
+
*
|
|
1452
|
+
* @param styles - Variable number of CSSProperties objects (can be undefined)
|
|
1453
|
+
* @returns Merged CSSProperties object, or undefined if empty
|
|
1454
|
+
*
|
|
1455
|
+
* @example
|
|
1456
|
+
* mergeStyles(
|
|
1457
|
+
* backgroundColorStyle('surface'),
|
|
1458
|
+
* textColorStyle('text'),
|
|
1459
|
+
* borderColorStyle('border')
|
|
1460
|
+
* )
|
|
1461
|
+
* // => { backgroundColor: '...', color: '...', borderColor: '...' }
|
|
1462
|
+
*/
|
|
1463
|
+
function mergeStyles(...styles) {
|
|
1464
|
+
const merged = {};
|
|
1465
|
+
for (const style of styles) {
|
|
1466
|
+
if (!style) continue;
|
|
1467
|
+
Object.assign(merged, style);
|
|
1468
|
+
}
|
|
1469
|
+
return Object.keys(merged).length ? merged : void 0;
|
|
1470
|
+
}
|
|
1471
|
+
//#endregion
|
|
1472
|
+
//#region ../theme-core/src/utils/tokenOrColor.ts
|
|
1473
|
+
const CSS_COLOR_FUNCTION_PATTERN = /^(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch|color|color-mix|light-dark)\(/i;
|
|
1474
|
+
const CSS_HEX_COLOR_PATTERN = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
1475
|
+
const CSS_COLOR_KEYWORDS = /* @__PURE__ */ new Set([
|
|
1476
|
+
"transparent",
|
|
1477
|
+
"currentcolor",
|
|
1478
|
+
"inherit",
|
|
1479
|
+
"initial",
|
|
1480
|
+
"revert",
|
|
1481
|
+
"revert-layer",
|
|
1482
|
+
"unset"
|
|
1483
|
+
]);
|
|
1484
|
+
const COMMON_CSS_NAMED_COLORS = /* @__PURE__ */ new Set([
|
|
1485
|
+
"black",
|
|
1486
|
+
"blue",
|
|
1487
|
+
"gray",
|
|
1488
|
+
"green",
|
|
1489
|
+
"grey",
|
|
1490
|
+
"orange",
|
|
1491
|
+
"pink",
|
|
1492
|
+
"purple",
|
|
1493
|
+
"red",
|
|
1494
|
+
"white",
|
|
1495
|
+
"yellow"
|
|
1496
|
+
]);
|
|
1497
|
+
function isCssColorLiteral(value) {
|
|
1498
|
+
const trimmed = value.trim();
|
|
1499
|
+
if (!trimmed) return false;
|
|
1500
|
+
return CSS_HEX_COLOR_PATTERN.test(trimmed) || CSS_COLOR_FUNCTION_PATTERN.test(trimmed) || /^var\(/i.test(trimmed) || CSS_COLOR_KEYWORDS.has(trimmed.toLowerCase());
|
|
1501
|
+
}
|
|
1502
|
+
function parseThemeToken(token) {
|
|
1503
|
+
const trimmed = token.trim();
|
|
1504
|
+
const match = trimmed.match(/^(.*?)-(\d{2,3})$/);
|
|
1505
|
+
if (!match) return {
|
|
1506
|
+
role: trimmed,
|
|
1507
|
+
shade: null
|
|
1508
|
+
};
|
|
1509
|
+
const role = match[1] ?? trimmed;
|
|
1510
|
+
const shade = match[2] ? Number(match[2]) : null;
|
|
1511
|
+
return {
|
|
1512
|
+
role,
|
|
1513
|
+
shade: Number.isFinite(shade) ? shade : null
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
function parseContextThemeColorToken(value, context) {
|
|
1517
|
+
const parts = parseColorTokenParts(value);
|
|
1518
|
+
if (parts.kind !== "token") return null;
|
|
1519
|
+
if (!(Boolean(context?.palette?.[value.trim()]) || parts.opacityPercent !== null && Boolean(context?.palette?.[parts.token]))) return null;
|
|
1520
|
+
return value.trim();
|
|
1521
|
+
}
|
|
1522
|
+
function isTokenShapedTypo(value) {
|
|
1523
|
+
if (COMMON_CSS_NAMED_COLORS.has(value.toLowerCase())) return false;
|
|
1524
|
+
if (!/^[a-zA-Z][a-zA-Z0-9]*(?:-[a-zA-Z0-9]+)*(?:\/[^/]+)?$/.test(value)) return false;
|
|
1525
|
+
return !isCssColorLiteral(value);
|
|
1526
|
+
}
|
|
1527
|
+
function warnUnknownThemeColorReference(value) {
|
|
1528
|
+
if (!isTokenShapedTypo(value)) return;
|
|
1529
|
+
console.warn(`[theme-core] Unknown Theme V2 color token "${value}" treated as literal CSS. Use raw:* for deliberate custom CSS values.`);
|
|
1530
|
+
}
|
|
1531
|
+
function parseThemeColorReference(input, context) {
|
|
1532
|
+
const trimmed = input.trim();
|
|
1533
|
+
if (trimmed.startsWith("raw:")) return {
|
|
1534
|
+
kind: "literal-css",
|
|
1535
|
+
value: trimmed.slice(4)
|
|
1536
|
+
};
|
|
1537
|
+
const contextToken = parseContextThemeColorToken(trimmed, context);
|
|
1538
|
+
if (contextToken) return {
|
|
1539
|
+
kind: "palette-context-token",
|
|
1540
|
+
token: contextToken
|
|
1541
|
+
};
|
|
1542
|
+
const knownToken = parseThemeColorToken(trimmed);
|
|
1543
|
+
if (knownToken) return {
|
|
1544
|
+
kind: "theme-token",
|
|
1545
|
+
token: knownToken
|
|
1546
|
+
};
|
|
1547
|
+
warnUnknownThemeColorReference(trimmed);
|
|
1548
|
+
return {
|
|
1549
|
+
kind: "literal-css",
|
|
1550
|
+
value: trimmed
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
function resolveThemeColorReferenceValue(input, context) {
|
|
1554
|
+
const reference = parseThemeColorReference(input, context);
|
|
1555
|
+
return reference.kind === "literal-css" ? reference.value : rgbColorValue(reference.token);
|
|
1556
|
+
}
|
|
1557
|
+
function resolveTokenOrCssColorValue(input, context) {
|
|
1558
|
+
return resolveThemeColorReferenceValue(input, context);
|
|
1559
|
+
}
|
|
1560
|
+
function resolveOnColorForThemeToken(token) {
|
|
1561
|
+
if (!parseThemeColorToken(token)) return null;
|
|
1562
|
+
const parts = parseColorTokenParts(token);
|
|
1563
|
+
if (parts.kind !== "token") return null;
|
|
1564
|
+
const { role, shade } = parseThemeToken(parts.token);
|
|
1565
|
+
const normalizedRole = role.trim();
|
|
1566
|
+
if (!normalizedRole) return null;
|
|
1567
|
+
if (!shade) return rgbColorValue(`on${normalizedRole.charAt(0).toUpperCase() + normalizedRole.slice(1)}`);
|
|
1568
|
+
return shade <= 400 ? "#000000" : "#FFFFFF";
|
|
1569
|
+
}
|
|
1570
|
+
//#endregion
|
|
1571
|
+
//#region ../theme-core/src/buttons/styles/domain.ts
|
|
1572
|
+
const PUBLIC_BUTTON_ROLES = VARIANT_ROLES;
|
|
1573
|
+
function defineButtonStyleRecipe(recipe) {
|
|
1574
|
+
return recipe;
|
|
1575
|
+
}
|
|
1576
|
+
function mapButtonVisualAppearances(states, transform) {
|
|
1577
|
+
return {
|
|
1578
|
+
...states,
|
|
1579
|
+
base: transform(states.base, "base"),
|
|
1580
|
+
hover: transform(states.hover, "hover"),
|
|
1581
|
+
focus: transform(states.focus, "focus"),
|
|
1582
|
+
active: transform(states.active, "active"),
|
|
1583
|
+
disabled: transform(states.disabled, "disabled")
|
|
1584
|
+
};
|
|
1585
|
+
}
|
|
1586
|
+
function mapButtonRoleAppearances(roles, transform) {
|
|
1587
|
+
const role = (name) => transform(roles[name], name);
|
|
1588
|
+
return {
|
|
1589
|
+
primary: role("primary"),
|
|
1590
|
+
secondary: role("secondary"),
|
|
1591
|
+
outline: role("outline"),
|
|
1592
|
+
ghost: role("ghost"),
|
|
1593
|
+
accent: role("accent")
|
|
1594
|
+
};
|
|
1595
|
+
}
|
|
1596
|
+
//#endregion
|
|
1597
|
+
//#region ../theme-core/src/buttons/constants.ts
|
|
1598
|
+
/**
|
|
1599
|
+
* Shared constants for button CSS generation
|
|
1600
|
+
*
|
|
1601
|
+
* These mappings convert Tailwind-style tokens to actual CSS values.
|
|
1602
|
+
* Centralized here to eliminate duplication across multiple files.
|
|
1603
|
+
*/
|
|
1604
|
+
/**
|
|
1605
|
+
* Map Tailwind-style gradient direction tokens to CSS gradient directions
|
|
1606
|
+
*/
|
|
1607
|
+
const GRADIENT_DIRECTION_MAP = {
|
|
1608
|
+
"to-r": "to right",
|
|
1609
|
+
"to-l": "to left",
|
|
1610
|
+
"to-t": "to top",
|
|
1611
|
+
"to-b": "to bottom",
|
|
1612
|
+
"to-br": "to bottom right",
|
|
1613
|
+
"to-bl": "to bottom left",
|
|
1614
|
+
"to-tr": "to top right",
|
|
1615
|
+
"to-tl": "to top left"
|
|
1616
|
+
};
|
|
1617
|
+
/**
|
|
1618
|
+
* Map Tailwind border-radius tokens to CSS values
|
|
1619
|
+
*/
|
|
1620
|
+
const BORDER_RADIUS_MAP = {
|
|
1621
|
+
"rounded-none": "0",
|
|
1622
|
+
"rounded-3px": "3px",
|
|
1623
|
+
"rounded-10px": "10px",
|
|
1624
|
+
"rounded-sm": "0.125rem",
|
|
1625
|
+
"rounded": "0.25rem",
|
|
1626
|
+
"rounded-md": "0.375rem",
|
|
1627
|
+
"rounded-lg": "0.5rem",
|
|
1628
|
+
"rounded-xl": "0.75rem",
|
|
1629
|
+
"rounded-2xl": "1rem",
|
|
1630
|
+
"rounded-3xl": "1.5rem",
|
|
1631
|
+
"rounded-full": "9999px"
|
|
1632
|
+
};
|
|
1633
|
+
/**
|
|
1634
|
+
* Pixel offset per shadow elevation. Single source of truth shared by
|
|
1635
|
+
* `generateShadowValue` (the base box-shadow offset) and the `press-down`
|
|
1636
|
+
* effect (which translates the button by the same offset on hover). Keeping
|
|
1637
|
+
* these in one place ensures the "press into the shadow" illusion stays exact.
|
|
1638
|
+
*/
|
|
1639
|
+
const ELEVATION_OFFSET = {
|
|
1640
|
+
none: 0,
|
|
1641
|
+
low: 2,
|
|
1642
|
+
medium: 4,
|
|
1643
|
+
high: 6
|
|
1644
|
+
};
|
|
1645
|
+
/**
|
|
1646
|
+
* Generate shadow CSS value dynamically based on elevation, softness, and position
|
|
1647
|
+
*
|
|
1648
|
+
* This replaces the static shadow maps with a single dynamic function.
|
|
1649
|
+
* Benefits: single source of truth, easy to adjust algorithm, no redundancy.
|
|
1650
|
+
*
|
|
1651
|
+
* @param elevation - Shadow elevation level
|
|
1652
|
+
* @param softness - Shadow softness/blur style
|
|
1653
|
+
* @param position - Shadow position (bottom or bottom-right diagonal)
|
|
1654
|
+
* @returns CSS box-shadow value
|
|
1655
|
+
*/
|
|
1656
|
+
function generateShadowValue(elevation, softness, position = "bottom", color) {
|
|
1657
|
+
if (elevation === "none") return "none";
|
|
1658
|
+
const config = {
|
|
1659
|
+
low: {
|
|
1660
|
+
blur: 4,
|
|
1661
|
+
spread: 0
|
|
1662
|
+
},
|
|
1663
|
+
medium: {
|
|
1664
|
+
blur: 8,
|
|
1665
|
+
spread: -1
|
|
1666
|
+
},
|
|
1667
|
+
high: {
|
|
1668
|
+
blur: 12,
|
|
1669
|
+
spread: -2
|
|
1670
|
+
}
|
|
1671
|
+
}[elevation];
|
|
1672
|
+
const baseOffset = ELEVATION_OFFSET[elevation];
|
|
1673
|
+
const xOffset = position === "bottom-right" ? baseOffset : 0;
|
|
1674
|
+
const yOffset = baseOffset;
|
|
1675
|
+
switch (softness) {
|
|
1676
|
+
case null:
|
|
1677
|
+
case "soft": return `${xOffset}px ${yOffset}px ${config.blur}px ${config.spread}px ${color ?? "rgb(0 0 0 / 0.3)"}`;
|
|
1678
|
+
case "hard": return `${xOffset}px ${yOffset}px 0 0 ${color ?? "rgb(0 0 0 / 1)"}`;
|
|
1679
|
+
case "crisp": return `${xOffset}px ${yOffset}px ${baseOffset}px ${config.spread}px ${color ?? "rgb(0 0 0 / 0.4)"}`;
|
|
1680
|
+
}
|
|
1681
|
+
}
|
|
1682
|
+
/**
|
|
1683
|
+
* Map Tailwind border-width tokens to CSS values
|
|
1684
|
+
*/
|
|
1685
|
+
const BORDER_WIDTH_MAP = {
|
|
1686
|
+
"border-0": "0px",
|
|
1687
|
+
"border": "1px",
|
|
1688
|
+
"border-2": "2px",
|
|
1689
|
+
"border-4": "4px",
|
|
1690
|
+
"border-8": "8px"
|
|
1691
|
+
};
|
|
1692
|
+
/**
|
|
1693
|
+
* Map Tailwind font-size tokens to CSS values
|
|
1694
|
+
*/
|
|
1695
|
+
const FONT_SIZE_MAP = {
|
|
1696
|
+
"text-xs": "0.75rem",
|
|
1697
|
+
"text-13px": "0.8125rem",
|
|
1698
|
+
"text-15px": "0.9375rem",
|
|
1699
|
+
"text-17px": "1.0625rem",
|
|
1700
|
+
"text-19px": "1.1875rem",
|
|
1701
|
+
"text-sm": "0.875rem",
|
|
1702
|
+
"text-base": "1rem",
|
|
1703
|
+
"text-lg": "1.125rem",
|
|
1704
|
+
"text-xl": "1.25rem",
|
|
1705
|
+
"text-2xl": "1.5rem"
|
|
1706
|
+
};
|
|
1707
|
+
/**
|
|
1708
|
+
* System defaults used when a theme doesn't supply its own `theme.buttons.sizes`.
|
|
1709
|
+
*
|
|
1710
|
+
* Every size is defined so the size class CSS always emits a complete rule and
|
|
1711
|
+
* variants are never naked. Referenced by `generateButtonCss` and surfaceable
|
|
1712
|
+
* from UI ("Showing default size ramp") without duplicating the values.
|
|
1713
|
+
*/
|
|
1714
|
+
const DEFAULT_BUTTON_SIZES = {
|
|
1715
|
+
sm: {
|
|
1716
|
+
padding: "0.5rem 1rem",
|
|
1717
|
+
fontSize: "text-sm"
|
|
1718
|
+
},
|
|
1719
|
+
md: { padding: "0.75rem 1.5rem" },
|
|
1720
|
+
lg: {
|
|
1721
|
+
padding: "1rem 2rem",
|
|
1722
|
+
fontSize: "text-lg"
|
|
1723
|
+
},
|
|
1724
|
+
xl: {
|
|
1725
|
+
padding: "1.25rem 2.5rem",
|
|
1726
|
+
fontSize: "text-xl"
|
|
1727
|
+
}
|
|
1728
|
+
};
|
|
1729
|
+
//#endregion
|
|
1730
|
+
//#region ../theme-core/src/buttons/buttonAppearance.ts
|
|
1731
|
+
/** Expand persisted pre-recipe families at the rendering boundary, once. */
|
|
1732
|
+
function materializeRuntimeButtonAppearance(variant, global, theme, sizes) {
|
|
1733
|
+
if (variant.visualStates) return {
|
|
1734
|
+
...variant,
|
|
1735
|
+
visualStates: variant.visualStates
|
|
1736
|
+
};
|
|
1737
|
+
const shadow = variant.shadow ?? {
|
|
1738
|
+
elevation: global.shadow ?? "none",
|
|
1739
|
+
softness: theme.shadow.softness,
|
|
1740
|
+
position: theme.shadow.position
|
|
1741
|
+
};
|
|
1742
|
+
const typography = persistedTypography(global);
|
|
1743
|
+
const padding = {
|
|
1744
|
+
sm: resolvedSize(variant, sizes, "sm"),
|
|
1745
|
+
md: resolvedSize(variant, sizes, "md"),
|
|
1746
|
+
lg: resolvedSize(variant, sizes, "lg"),
|
|
1747
|
+
xl: resolvedSize(variant, sizes, "xl")
|
|
1748
|
+
};
|
|
1749
|
+
const shared = {
|
|
1750
|
+
background: variant.background,
|
|
1751
|
+
text: "treatment",
|
|
1752
|
+
border: variant.border ?? "none",
|
|
1753
|
+
borderRadius: variant.borderRadius ?? {
|
|
1754
|
+
square: "rounded-none",
|
|
1755
|
+
rounded: "rounded-md",
|
|
1756
|
+
pill: "rounded-full"
|
|
1757
|
+
}[global.cornerStyle],
|
|
1758
|
+
sizes: padding,
|
|
1759
|
+
typography
|
|
1760
|
+
};
|
|
1761
|
+
const hoverToken = variant.hoverBackgroundToken ?? (global.hoverColor === "token" ? global.hoverColorToken : void 0);
|
|
1762
|
+
const effects = (state) => (variant.effects?.[state] ?? []).map((effect) => {
|
|
1763
|
+
if (effect.effectId !== "press-down" || effect.options?.offset) return effect;
|
|
1764
|
+
const source = variant.shadow ?? theme.shadow;
|
|
1765
|
+
const offset = ELEVATION_OFFSET[source.elevation];
|
|
1766
|
+
return {
|
|
1767
|
+
...effect,
|
|
1768
|
+
options: { offset: {
|
|
1769
|
+
x: source.position === "bottom-right" ? offset : 0,
|
|
1770
|
+
y: offset
|
|
1771
|
+
} }
|
|
1772
|
+
};
|
|
1773
|
+
});
|
|
1774
|
+
return {
|
|
1775
|
+
...variant,
|
|
1776
|
+
visualStates: {
|
|
1777
|
+
base: {
|
|
1778
|
+
...shared,
|
|
1779
|
+
shadow,
|
|
1780
|
+
effects: effects("base")
|
|
1781
|
+
},
|
|
1782
|
+
hover: {
|
|
1783
|
+
...shared,
|
|
1784
|
+
background: hoverToken ? {
|
|
1785
|
+
type: "solid",
|
|
1786
|
+
colorToken: hoverToken
|
|
1787
|
+
} : shared.background,
|
|
1788
|
+
shadow,
|
|
1789
|
+
effects: effects("hover"),
|
|
1790
|
+
...variant.contextualHover ? { contextualHover: variant.contextualHover } : {}
|
|
1791
|
+
},
|
|
1792
|
+
focus: {
|
|
1793
|
+
...shared,
|
|
1794
|
+
shadow: "focus-indicator",
|
|
1795
|
+
effects: effects("focus")
|
|
1796
|
+
},
|
|
1797
|
+
active: {
|
|
1798
|
+
...shared,
|
|
1799
|
+
shadow,
|
|
1800
|
+
effects: effects("active")
|
|
1801
|
+
},
|
|
1802
|
+
disabled: {
|
|
1803
|
+
...shared,
|
|
1804
|
+
shadow: {
|
|
1805
|
+
elevation: "none",
|
|
1806
|
+
softness: null,
|
|
1807
|
+
position: "bottom"
|
|
1808
|
+
},
|
|
1809
|
+
effects: []
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
};
|
|
1813
|
+
}
|
|
1814
|
+
function persistedTypography(global) {
|
|
1815
|
+
return {
|
|
1816
|
+
fontWeight: global.fontWeight,
|
|
1817
|
+
typography: global.typography ?? "body",
|
|
1818
|
+
fontSize: global.fontSize ?? null,
|
|
1819
|
+
letterSpacing: global.letterSpacing ?? (global.typography === "heading" ? "heading" : null),
|
|
1820
|
+
italic: global.italic ?? false,
|
|
1821
|
+
textTransform: global.textTransform
|
|
1822
|
+
};
|
|
1823
|
+
}
|
|
1824
|
+
function resolvedSize(variant, sizes, name) {
|
|
1825
|
+
const override = variant.sizes?.[name];
|
|
1826
|
+
const fontSize = override?.fontSize ?? sizes[name].fontSize;
|
|
1827
|
+
return {
|
|
1828
|
+
padding: override?.padding ?? sizes[name].padding,
|
|
1829
|
+
...fontSize ? { fontSize } : {}
|
|
1830
|
+
};
|
|
1831
|
+
}
|
|
1832
|
+
function buttonTypographyDeclarations(type) {
|
|
1833
|
+
const spacing = type.letterSpacing === null ? null : type.letterSpacing === "heading" ? "var(--ls-heading)" : {
|
|
1834
|
+
tight: "-0.025em",
|
|
1835
|
+
normal: "0",
|
|
1836
|
+
slight: "0.01em",
|
|
1837
|
+
loose: "0.05em",
|
|
1838
|
+
wide: "0.125em"
|
|
1839
|
+
}[type.letterSpacing];
|
|
1840
|
+
return [
|
|
1841
|
+
["font-weight", String(type.fontWeight)],
|
|
1842
|
+
["font-family", type.typography === "heading" ? "var(--font-heading)" : "var(--font-body)"],
|
|
1843
|
+
...spacing === null ? [] : [["letter-spacing", spacing]],
|
|
1844
|
+
...type.italic ? [["font-style", "italic"]] : [],
|
|
1845
|
+
...type.fontSize === null ? [] : [["font-size", FONT_SIZE_MAP[type.fontSize] || "1rem"]],
|
|
1846
|
+
...type.textTransform === "none" ? [] : [["text-transform", type.textTransform]]
|
|
1847
|
+
];
|
|
1848
|
+
}
|
|
1849
|
+
function buttonRadius(radius) {
|
|
1850
|
+
return BORDER_RADIUS_MAP[radius] ?? BORDER_RADIUS_MAP.rounded ?? "0.375rem";
|
|
1851
|
+
}
|
|
1852
|
+
function buttonShadow(shadow, tokens) {
|
|
1853
|
+
return generateShadowValue(shadow.elevation, shadow.softness, shadow.position, shadow.colorToken ? tokens.getColor(shadow.colorToken) : void 0);
|
|
1854
|
+
}
|
|
1855
|
+
function buttonBorder(border, tokens) {
|
|
1856
|
+
return border === "none" ? null : `${BORDER_WIDTH_MAP[border.widthClass] || "1px"} solid ${border.boundaryInk ? tokens.getColor(border.boundaryInk) : "currentColor"}`;
|
|
1857
|
+
}
|
|
1858
|
+
function buttonTypographyChanges(base, state) {
|
|
1859
|
+
const original = new Map(buttonTypographyDeclarations(base));
|
|
1860
|
+
const declared = new Map(buttonTypographyDeclarations(state));
|
|
1861
|
+
const resets = [
|
|
1862
|
+
["font-style", "normal"],
|
|
1863
|
+
["text-transform", "none"],
|
|
1864
|
+
["letter-spacing", "normal"]
|
|
1865
|
+
].filter(([property]) => original.has(property) && !declared.has(property));
|
|
1866
|
+
return [...declared, ...resets].filter(([property, value]) => original.get(property) !== value);
|
|
1867
|
+
}
|
|
1868
|
+
/** Emit only changed declarations; identical states keep historical CSS bytes. */
|
|
1869
|
+
function buttonStateAppearanceDeclarations(base, state, tokens, disabled = false) {
|
|
1870
|
+
const border = buttonBorder(state.border, tokens);
|
|
1871
|
+
const radius = buttonRadius(state.borderRadius);
|
|
1872
|
+
const shadow = !disabled && state.shadow !== "focus-indicator" ? buttonShadow(state.shadow, tokens) : null;
|
|
1873
|
+
return [
|
|
1874
|
+
...buttonTypographyChanges(base.typography, state.typography),
|
|
1875
|
+
...buttonRadius(base.borderRadius) === radius ? [] : [["border-radius", radius]],
|
|
1876
|
+
...buttonBorder(base.border, tokens) === border ? [] : [["border", border ?? "none"]],
|
|
1877
|
+
...shadow === null || base.shadow === "focus-indicator" || buttonShadow(base.shadow, tokens) === shadow ? [] : [["box-shadow", shadow]]
|
|
1878
|
+
];
|
|
1879
|
+
}
|
|
1880
|
+
/** Surface paint is a context for the recipe, checked by the same colour owner. */
|
|
1881
|
+
function surfaceButtonSystem(system, primaryToken) {
|
|
1882
|
+
return primaryToken === void 0 ? system : {
|
|
1883
|
+
...system,
|
|
1884
|
+
variants: system.variants.map((variant) => variant.id === "primary" ? surfacePrimary(variant, primaryToken) : variant)
|
|
1885
|
+
};
|
|
1886
|
+
}
|
|
1887
|
+
function withoutColourTransitions(effects) {
|
|
1888
|
+
return effects.filter((effect) => effect.effectId !== "background-on-hover" && effect.effectId !== "darken-background" && effect.effectId !== "lighten-background");
|
|
1889
|
+
}
|
|
1890
|
+
function surfacePrimary(variant, token) {
|
|
1891
|
+
const background = {
|
|
1892
|
+
type: "solid",
|
|
1893
|
+
colorToken: token
|
|
1894
|
+
};
|
|
1895
|
+
return {
|
|
1896
|
+
...variant,
|
|
1897
|
+
background,
|
|
1898
|
+
hoverBackgroundToken: void 0,
|
|
1899
|
+
contextualHover: void 0,
|
|
1900
|
+
visualStates: variant.visualStates ? mapButtonVisualAppearances(variant.visualStates, (state) => ({
|
|
1901
|
+
...state,
|
|
1902
|
+
background,
|
|
1903
|
+
contextualHover: void 0,
|
|
1904
|
+
effects: withoutColourTransitions(state.effects)
|
|
1905
|
+
})) : void 0,
|
|
1906
|
+
effects: variant.effects === void 0 ? void 0 : Object.fromEntries([
|
|
1907
|
+
"base",
|
|
1908
|
+
"hover",
|
|
1909
|
+
"focus",
|
|
1910
|
+
"active"
|
|
1911
|
+
].flatMap((state) => variant.effects?.[state] ? [[state, withoutColourTransitions(variant.effects[state])]] : []))
|
|
1912
|
+
};
|
|
1913
|
+
}
|
|
1914
|
+
function paddingDeclarations(padding, borderWidth) {
|
|
1915
|
+
const parts = padding.split(/\s+/).filter(Boolean);
|
|
1916
|
+
if (parts.length !== 2) throw new Error(`Invariant: padding "${padding}" did not validate as two-token shorthand`);
|
|
1917
|
+
const [vertical, horizontal] = parts;
|
|
1918
|
+
if (borderWidth === "0px") return [["padding", `${vertical} ${horizontal}`]];
|
|
1919
|
+
if (vertical === horizontal) return [["padding", `calc(${vertical} - ${borderWidth})`]];
|
|
1920
|
+
return [
|
|
1921
|
+
["padding-top", `calc(${vertical} - ${borderWidth})`],
|
|
1922
|
+
["padding-bottom", `calc(${vertical} - ${borderWidth})`],
|
|
1923
|
+
["padding-left", `calc(${horizontal} - ${borderWidth})`],
|
|
1924
|
+
["padding-right", `calc(${horizontal} - ${borderWidth})`]
|
|
1925
|
+
];
|
|
1926
|
+
}
|
|
1927
|
+
//#endregion
|
|
1928
|
+
//#region ../theme-core/src/buttons/buttonColourContract.ts
|
|
1929
|
+
const BUTTON_CONTRAST_POLICY = {
|
|
1930
|
+
textMinimumRatio: 4.5,
|
|
1931
|
+
nonTextMinimumRatio: 3,
|
|
1932
|
+
filledMinimumDeltaE: .12,
|
|
1933
|
+
gradientSamplesPerSegment: 20,
|
|
1934
|
+
alphaBackgrounds: "reject-without-known-surface",
|
|
1935
|
+
disabled: "validated-colour-pair-with-muted-control-opacity"
|
|
1936
|
+
};
|
|
1937
|
+
function formatButtonColourContractError(error) {
|
|
1938
|
+
switch (error.tag) {
|
|
1939
|
+
case "unknown_palette_token": return `Button "${error.variantId}" ${error.state} state uses unknown palette token "${error.token}".`;
|
|
1940
|
+
case "insufficient_contrast": return `Button "${error.variantId}" ${error.state} state has ${error.ratio.toFixed(2)}:1 contrast (${error.requiredRatio}:1 required).`;
|
|
1941
|
+
case "insufficient_surface_separation": return `Button "${error.variantId}" ${error.state} state is indistinguishable from its surface at OKLab distance ${error.deltaE.toFixed(3)} (${error.requiredDeltaE} required).`;
|
|
1942
|
+
case "unsupported_colour_effect": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" is not contrast-safe (${error.reason}).`;
|
|
1943
|
+
case "invalid_colour_effect_options": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" has an invalid ${error.option} option.`;
|
|
1944
|
+
case "inapplicable_colour_effect": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" cannot apply to a ${error.treatment} treatment.`;
|
|
1945
|
+
case "unknown_button_effect": return `Button "${error.variantId}" ${error.state} uses unknown effect "${error.effectId}".`;
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
/** One separation decision for filled states and contextual hover candidates. */
|
|
1949
|
+
function buttonFillSeparation(fill, ground) {
|
|
1950
|
+
const deltaE = hexOklabDistance(fill, ground);
|
|
1951
|
+
return {
|
|
1952
|
+
deltaE,
|
|
1953
|
+
distinct: deltaE >= BUTTON_CONTRAST_POLICY.filledMinimumDeltaE
|
|
1954
|
+
};
|
|
1955
|
+
}
|
|
1956
|
+
/** All paint beneath the control; ordinary solids have just one ground. */
|
|
1957
|
+
const buttonSurfaceGrounds = (surface) => [surface.backgroundHex, ...surface.backgroundSamples ?? []];
|
|
1958
|
+
/** A filled state clears each ground by its fill OR a declared edge at 3:1. */
|
|
1959
|
+
function buttonSurfaceSeparation(fill, surface, edge) {
|
|
1960
|
+
return buttonGroundSeparation(fill, buttonSurfaceGrounds(surface), edge);
|
|
1961
|
+
}
|
|
1962
|
+
/** The worst ground for a fill: the first it fails to stand out from, otherwise the closest. */
|
|
1963
|
+
function buttonGroundSeparation(fill, grounds, edge) {
|
|
1964
|
+
const ink = edge?.border?.marksBoundary ? edge.border.boundaryInk ? edge.palette[edge.border.boundaryInk] : edge.labelInk : void 0;
|
|
1965
|
+
return grounds.map((ground) => {
|
|
1966
|
+
const separation = buttonFillSeparation(fill, ground);
|
|
1967
|
+
const distinct = separation.distinct || ink !== void 0 && contrastRatio(ink, ground) >= BUTTON_CONTRAST_POLICY.nonTextMinimumRatio;
|
|
1968
|
+
return {
|
|
1969
|
+
...separation,
|
|
1970
|
+
distinct,
|
|
1971
|
+
ground
|
|
1972
|
+
};
|
|
1973
|
+
}).reduce((worst, next) => {
|
|
1974
|
+
if (worst.distinct !== next.distinct) return worst.distinct ? next : worst;
|
|
1975
|
+
return next.deltaE < worst.deltaE ? next : worst;
|
|
1976
|
+
});
|
|
1977
|
+
}
|
|
1978
|
+
function validateButtonFillSeparation(input) {
|
|
1979
|
+
const token = input.border?.marksBoundary ? input.border.boundaryInk : void 0;
|
|
1980
|
+
if (token && !input.palette[token]) return {
|
|
1981
|
+
ok: false,
|
|
1982
|
+
error: {
|
|
1983
|
+
tag: "unknown_palette_token",
|
|
1984
|
+
variantId: input.variantId,
|
|
1985
|
+
state: input.state,
|
|
1986
|
+
token
|
|
1987
|
+
}
|
|
1988
|
+
};
|
|
1989
|
+
const separation = buttonSurfaceSeparation(input.buttonPaint, input.surface, input);
|
|
1990
|
+
return separation.distinct ? { ok: true } : {
|
|
1991
|
+
ok: false,
|
|
1992
|
+
error: {
|
|
1993
|
+
tag: "insufficient_surface_separation",
|
|
1994
|
+
variantId: input.variantId,
|
|
1995
|
+
state: input.state,
|
|
1996
|
+
buttonPaint: input.buttonPaint,
|
|
1997
|
+
surface: separation.ground,
|
|
1998
|
+
deltaE: separation.deltaE,
|
|
1999
|
+
requiredDeltaE: BUTTON_CONTRAST_POLICY.filledMinimumDeltaE
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
function validateButtonTextContrast(input) {
|
|
2004
|
+
const ratio = contrastRatio(input.backgroundHex, input.foregroundHex, input.colourIndex);
|
|
2005
|
+
return ratio >= BUTTON_CONTRAST_POLICY.textMinimumRatio ? { ok: true } : {
|
|
2006
|
+
ok: false,
|
|
2007
|
+
error: {
|
|
2008
|
+
tag: "insufficient_contrast",
|
|
2009
|
+
variantId: input.variantId,
|
|
2010
|
+
state: input.state,
|
|
2011
|
+
background: input.background,
|
|
2012
|
+
foreground: input.foreground,
|
|
2013
|
+
ratio,
|
|
2014
|
+
requiredRatio: BUTTON_CONTRAST_POLICY.textMinimumRatio
|
|
2015
|
+
}
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
/** A text-token slab inverts the palette's text/background pair, including text shades. */
|
|
2019
|
+
function solidForegroundToken(backgroundToken) {
|
|
2020
|
+
return /^text(?:-\d+)?$/.test(backgroundToken) ? "background" : onColorTokenName(backgroundToken);
|
|
2021
|
+
}
|
|
2022
|
+
//#endregion
|
|
2023
|
+
//#region ../theme-core/src/buttons/effectClassification.ts
|
|
2024
|
+
/**
|
|
2025
|
+
* Exhaustive live policy for every registered effect id.
|
|
2026
|
+
*
|
|
2027
|
+
* The resolver consumes the transition payload directly, so adding an effect
|
|
2028
|
+
* cannot update classification without also defining its runtime behavior.
|
|
2029
|
+
*/
|
|
2030
|
+
const BUTTON_EFFECT_POLICIES = {
|
|
2031
|
+
"darken-background": {
|
|
2032
|
+
classification: "colour-transition",
|
|
2033
|
+
transition: {
|
|
2034
|
+
kind: "adjust-shade",
|
|
2035
|
+
direction: "darker"
|
|
2036
|
+
}
|
|
2037
|
+
},
|
|
2038
|
+
"lighten-background": {
|
|
2039
|
+
classification: "colour-transition",
|
|
2040
|
+
transition: {
|
|
2041
|
+
kind: "adjust-shade",
|
|
2042
|
+
direction: "lighter"
|
|
2043
|
+
}
|
|
2044
|
+
},
|
|
2045
|
+
"background-on-hover": {
|
|
2046
|
+
classification: "colour-transition",
|
|
2047
|
+
transition: { kind: "replace-background" }
|
|
2048
|
+
},
|
|
2049
|
+
"background-on-hover-alpha": {
|
|
2050
|
+
classification: "unsupported-colour",
|
|
2051
|
+
reason: "alpha_requires_surface"
|
|
2052
|
+
},
|
|
2053
|
+
"fade-background": {
|
|
2054
|
+
classification: "unsupported-colour",
|
|
2055
|
+
reason: "changes_element_opacity"
|
|
2056
|
+
},
|
|
2057
|
+
"opacity-reduce": {
|
|
2058
|
+
classification: "unsupported-colour",
|
|
2059
|
+
reason: "changes_element_opacity"
|
|
2060
|
+
},
|
|
2061
|
+
"gradient-text": {
|
|
2062
|
+
classification: "unsupported-colour",
|
|
2063
|
+
reason: "changes_foreground"
|
|
2064
|
+
},
|
|
2065
|
+
"text-color-change": {
|
|
2066
|
+
classification: "unsupported-colour",
|
|
2067
|
+
reason: "changes_foreground"
|
|
2068
|
+
},
|
|
2069
|
+
"border-color-change": {
|
|
2070
|
+
classification: "unsupported-colour",
|
|
2071
|
+
reason: "changes_border"
|
|
2072
|
+
},
|
|
2073
|
+
"aurora-glow": {
|
|
2074
|
+
classification: "unsupported-background-overlay",
|
|
2075
|
+
reason: "unresolved_background_overlay"
|
|
2076
|
+
},
|
|
2077
|
+
"cosmic-stardust": {
|
|
2078
|
+
classification: "unsupported-background-overlay",
|
|
2079
|
+
reason: "unresolved_background_overlay"
|
|
2080
|
+
},
|
|
2081
|
+
"gradient-border-fill": {
|
|
2082
|
+
classification: "unsupported-background-overlay",
|
|
2083
|
+
reason: "unresolved_background_overlay"
|
|
2084
|
+
},
|
|
2085
|
+
"animated-gradient-border-fill": {
|
|
2086
|
+
classification: "unsupported-background-overlay",
|
|
2087
|
+
reason: "unresolved_background_overlay"
|
|
2088
|
+
},
|
|
2089
|
+
"nav-underline": {
|
|
2090
|
+
classification: "not-button",
|
|
2091
|
+
reason: "not_button_effect"
|
|
2092
|
+
},
|
|
2093
|
+
"nav-frosted-base": {
|
|
2094
|
+
classification: "not-button",
|
|
2095
|
+
reason: "not_button_effect"
|
|
2096
|
+
},
|
|
2097
|
+
"nav-frosted-hover": {
|
|
2098
|
+
classification: "not-button",
|
|
2099
|
+
reason: "not_button_effect"
|
|
2100
|
+
},
|
|
2101
|
+
"nav-frosted-active": {
|
|
2102
|
+
classification: "not-button",
|
|
2103
|
+
reason: "not_button_effect"
|
|
2104
|
+
},
|
|
2105
|
+
"animated-gradient": { classification: "non-colour" },
|
|
2106
|
+
"border-glow": {
|
|
2107
|
+
classification: "unsupported-colour",
|
|
2108
|
+
reason: "changes_shadow_colour"
|
|
2109
|
+
},
|
|
2110
|
+
"drop-shadow": { classification: "decorative-colour" },
|
|
2111
|
+
"inner-shadow": { classification: "decorative-colour" },
|
|
2112
|
+
"neumorphic-shadow": { classification: "decorative-colour" },
|
|
2113
|
+
"outer-glow": {
|
|
2114
|
+
classification: "unsupported-colour",
|
|
2115
|
+
reason: "changes_shadow_colour"
|
|
2116
|
+
},
|
|
2117
|
+
"retro-3d-shadow": { classification: "decorative-colour" },
|
|
2118
|
+
"scale-up": { classification: "non-colour" },
|
|
2119
|
+
"scale-down": { classification: "non-colour" },
|
|
2120
|
+
lift: { classification: "non-colour" },
|
|
2121
|
+
"press-down": { classification: "non-colour" },
|
|
2122
|
+
pop: { classification: "non-colour" },
|
|
2123
|
+
"border-bottom-grow": { classification: "non-colour" },
|
|
2124
|
+
"sketchy-border": { classification: "decorative-colour" },
|
|
2125
|
+
"inner-dashed-outline": { classification: "decorative-colour" },
|
|
2126
|
+
"pulse-animation": {
|
|
2127
|
+
classification: "unsupported-colour",
|
|
2128
|
+
reason: "changes_element_opacity"
|
|
2129
|
+
}
|
|
2130
|
+
};
|
|
2131
|
+
function validateButtonEffectOptions(effect) {
|
|
2132
|
+
const parsed = buttonEffectApplicationSchema.safeParse(effect);
|
|
2133
|
+
if (parsed.success) return { ok: true };
|
|
2134
|
+
const firstIssue = parsed.error.issues[0];
|
|
2135
|
+
const firstPathPart = firstIssue?.path[firstIssue.path.length - 1];
|
|
2136
|
+
return {
|
|
2137
|
+
ok: false,
|
|
2138
|
+
option: (firstIssue?.code === "unrecognized_keys" ? firstIssue.keys[0] : void 0) ?? (typeof firstPathPart === "string" ? firstPathPart : "options")
|
|
2139
|
+
};
|
|
2140
|
+
}
|
|
2141
|
+
function getButtonEffectPolicy(effectId) {
|
|
2142
|
+
return Object.prototype.hasOwnProperty.call(BUTTON_EFFECT_POLICIES, effectId) ? BUTTON_EFFECT_POLICIES[effectId] : null;
|
|
2143
|
+
}
|
|
2144
|
+
//#endregion
|
|
2145
|
+
//#region ../theme-core/src/buttons/buttonColourTransitions.ts
|
|
2146
|
+
function applyColourEffects(input) {
|
|
2147
|
+
return (input.effects ?? []).reduce((current, effect) => current.ok ? applyEffect(input, current, effect) : current, {
|
|
2148
|
+
ok: true,
|
|
2149
|
+
treatment: input.treatment,
|
|
2150
|
+
nonColourEffects: []
|
|
2151
|
+
});
|
|
2152
|
+
}
|
|
2153
|
+
function applyEffect(input, current, effect) {
|
|
2154
|
+
const policy = getButtonEffectPolicy(effect.effectId);
|
|
2155
|
+
if (policy === null) return unknownEffect(input, effect);
|
|
2156
|
+
if (policy.classification === "unsupported-colour" || policy.classification === "unsupported-background-overlay" || policy.classification === "not-button") return unsupportedEffect(input, effect, policy.reason);
|
|
2157
|
+
const options = validateButtonEffectOptions(effect);
|
|
2158
|
+
if (!options.ok) return invalidEffectOption(input, effect, options.option);
|
|
2159
|
+
return policy.classification === "colour-transition" ? transitionColour(input, current, effect) : {
|
|
2160
|
+
...current,
|
|
2161
|
+
nonColourEffects: [...current.nonColourEffects, effect]
|
|
2162
|
+
};
|
|
2163
|
+
}
|
|
2164
|
+
function transitionColour(input, current, effect) {
|
|
2165
|
+
if (effect.effectId === "background-on-hover") {
|
|
2166
|
+
const colorToken = readOpaqueToken(effect);
|
|
2167
|
+
return colorToken === null ? invalidEffectOption(input, effect, "colorToken") : {
|
|
2168
|
+
...current,
|
|
2169
|
+
treatment: {
|
|
2170
|
+
type: "solid",
|
|
2171
|
+
colorToken
|
|
2172
|
+
}
|
|
2173
|
+
};
|
|
2174
|
+
}
|
|
2175
|
+
if (effect.effectId !== "darken-background" && effect.effectId !== "lighten-background") return unknownEffect(input, effect);
|
|
2176
|
+
if (current.treatment.type !== "solid") return inapplicableEffect(input, effect, current.treatment);
|
|
2177
|
+
const amount = readShadeAmount(effect);
|
|
2178
|
+
if (amount === null) return invalidEffectOption(input, effect, "amount");
|
|
2179
|
+
return {
|
|
2180
|
+
...current,
|
|
2181
|
+
treatment: {
|
|
2182
|
+
type: "solid",
|
|
2183
|
+
colorToken: adjustShade(current.treatment.colorToken, effect.effectId === "darken-background" ? amount : -amount, input.palette)
|
|
2184
|
+
}
|
|
2185
|
+
};
|
|
2186
|
+
}
|
|
2187
|
+
function adjustShade(token, amount, palette) {
|
|
2188
|
+
const match = token.match(/^(.*)-(\d{2,3})$/);
|
|
2189
|
+
const base = match?.[1] ?? token;
|
|
2190
|
+
const currentShade = match?.[2] === void 0 ? 500 : Number(match[2]);
|
|
2191
|
+
const availableShades = [
|
|
2192
|
+
50,
|
|
2193
|
+
100,
|
|
2194
|
+
200,
|
|
2195
|
+
300,
|
|
2196
|
+
400,
|
|
2197
|
+
500,
|
|
2198
|
+
600,
|
|
2199
|
+
700,
|
|
2200
|
+
800,
|
|
2201
|
+
900,
|
|
2202
|
+
950
|
|
2203
|
+
].filter((shade) => typeof palette[`${base}-${shade}`] === "string");
|
|
2204
|
+
if (availableShades.length === 0) return token;
|
|
2205
|
+
const firstShade = availableShades[0];
|
|
2206
|
+
if (firstShade === void 0) return token;
|
|
2207
|
+
const exactIndex = availableShades.indexOf(currentShade);
|
|
2208
|
+
const startingIndex = exactIndex >= 0 ? exactIndex : availableShades.indexOf(availableShades.reduce((closestShade, shade) => Math.abs(shade - currentShade) < Math.abs(closestShade - currentShade) ? shade : closestShade, firstShade));
|
|
2209
|
+
const stepCount = Math.abs(amount) / 100;
|
|
2210
|
+
const direction = amount < 0 ? -1 : 1;
|
|
2211
|
+
const targetShade = availableShades[Math.max(0, Math.min(availableShades.length - 1, startingIndex + direction * stepCount))];
|
|
2212
|
+
return targetShade === void 0 ? token : unsafeAsOpaqueButtonColourToken(`${base}-${targetShade}`);
|
|
2213
|
+
}
|
|
2214
|
+
function readShadeAmount(effect) {
|
|
2215
|
+
const value = effect.options?.amount ?? 100;
|
|
2216
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value % 100 === 0 ? value : null;
|
|
2217
|
+
}
|
|
2218
|
+
function readOpaqueToken(effect) {
|
|
2219
|
+
return parseOpaqueButtonColourToken(effect.options?.colorToken ?? "neutral-800");
|
|
2220
|
+
}
|
|
2221
|
+
function unsupportedEffect(input, effect, reason) {
|
|
2222
|
+
return {
|
|
2223
|
+
ok: false,
|
|
2224
|
+
error: {
|
|
2225
|
+
tag: "unsupported_colour_effect",
|
|
2226
|
+
variantId: input.variantId,
|
|
2227
|
+
state: input.state,
|
|
2228
|
+
effectId: effect.effectId,
|
|
2229
|
+
reason
|
|
2230
|
+
}
|
|
2231
|
+
};
|
|
2232
|
+
}
|
|
2233
|
+
function invalidEffectOption(input, effect, option) {
|
|
2234
|
+
return {
|
|
2235
|
+
ok: false,
|
|
2236
|
+
error: {
|
|
2237
|
+
tag: "invalid_colour_effect_options",
|
|
2238
|
+
variantId: input.variantId,
|
|
2239
|
+
state: input.state,
|
|
2240
|
+
effectId: effect.effectId,
|
|
2241
|
+
option
|
|
2242
|
+
}
|
|
2243
|
+
};
|
|
2244
|
+
}
|
|
2245
|
+
function inapplicableEffect(input, effect, treatment) {
|
|
2246
|
+
return {
|
|
2247
|
+
ok: false,
|
|
2248
|
+
error: {
|
|
2249
|
+
tag: "inapplicable_colour_effect",
|
|
2250
|
+
variantId: input.variantId,
|
|
2251
|
+
state: input.state,
|
|
2252
|
+
effectId: effect.effectId,
|
|
2253
|
+
treatment: treatment.type
|
|
2254
|
+
}
|
|
2255
|
+
};
|
|
2256
|
+
}
|
|
2257
|
+
function unknownEffect(input, effect) {
|
|
2258
|
+
return {
|
|
2259
|
+
ok: false,
|
|
2260
|
+
error: {
|
|
2261
|
+
tag: "unknown_button_effect",
|
|
2262
|
+
variantId: input.variantId,
|
|
2263
|
+
state: input.state,
|
|
2264
|
+
effectId: effect.effectId
|
|
2265
|
+
}
|
|
2266
|
+
};
|
|
2267
|
+
}
|
|
2268
|
+
//#endregion
|
|
2269
|
+
//#region ../theme-core/src/buttons/contextualHover.ts
|
|
2270
|
+
function resolveContextualHoverPreference(input) {
|
|
2271
|
+
const preferred = input.instruction.preferredToken;
|
|
2272
|
+
if (preferred && isSafeCandidate(preferred, input.palette, input.surface, input.colourIndex, input.border)) return {
|
|
2273
|
+
kind: "resolved",
|
|
2274
|
+
token: preferred,
|
|
2275
|
+
repair: null
|
|
2276
|
+
};
|
|
2277
|
+
const contextual = resolveContextualHover(input);
|
|
2278
|
+
return contextual.kind === "resolved" ? {
|
|
2279
|
+
kind: "resolved",
|
|
2280
|
+
token: contextual.token,
|
|
2281
|
+
repair: preferred ? {
|
|
2282
|
+
kind: "preferred-token-replaced",
|
|
2283
|
+
preferredToken: preferred,
|
|
2284
|
+
contextualToken: contextual.token
|
|
2285
|
+
} : null
|
|
2286
|
+
} : contextual;
|
|
2287
|
+
}
|
|
2288
|
+
/**
|
|
2289
|
+
* Resolves semantic shade movement from real palette steps. The persisted
|
|
2290
|
+
* instruction owns the colour family and deterministic unknown-surface
|
|
2291
|
+
* fallback; a proven surface may select the opposite direction when it gives
|
|
2292
|
+
* the button stronger separation while retaining the shared contrast contract.
|
|
2293
|
+
*/
|
|
2294
|
+
function resolveContextualHover(input) {
|
|
2295
|
+
const candidates = shadeCandidates(input.instruction.seedToken, input.palette);
|
|
2296
|
+
if (candidates.length === 0) return {
|
|
2297
|
+
kind: "unavailable",
|
|
2298
|
+
reason: "no-distinct-shade"
|
|
2299
|
+
};
|
|
2300
|
+
const textSafe = candidates.filter((candidate) => hasSafeTextContrast(candidate.token, input.palette, input.colourIndex));
|
|
2301
|
+
if (textSafe.length === 0) return {
|
|
2302
|
+
kind: "unavailable",
|
|
2303
|
+
reason: "no-text-safe-candidate"
|
|
2304
|
+
};
|
|
2305
|
+
if (!input.surface) {
|
|
2306
|
+
const selected = textSafe.find((candidate) => candidate.direction === input.instruction.fallbackDirection) ?? textSafe[0];
|
|
2307
|
+
return selected ? {
|
|
2308
|
+
kind: "resolved",
|
|
2309
|
+
token: selected.token,
|
|
2310
|
+
direction: selected.direction,
|
|
2311
|
+
evidence: "fallback-direction"
|
|
2312
|
+
} : {
|
|
2313
|
+
kind: "unavailable",
|
|
2314
|
+
reason: "no-text-safe-candidate"
|
|
2315
|
+
};
|
|
2316
|
+
}
|
|
2317
|
+
const selected = selectSurfaceSafeHover(textSafe, {
|
|
2318
|
+
palette: input.palette,
|
|
2319
|
+
surface: input.surface,
|
|
2320
|
+
colourIndex: input.colourIndex,
|
|
2321
|
+
fallbackDirection: input.instruction.fallbackDirection,
|
|
2322
|
+
border: input.border
|
|
2323
|
+
});
|
|
2324
|
+
return selected ? {
|
|
2325
|
+
kind: "resolved",
|
|
2326
|
+
token: selected.token,
|
|
2327
|
+
direction: selected.direction,
|
|
2328
|
+
evidence: "known-surface"
|
|
2329
|
+
} : {
|
|
2330
|
+
kind: "unavailable",
|
|
2331
|
+
reason: "no-surface-safe-candidate"
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
/** Rank the proven-surface candidates without mixing selection with fallback policy. */
|
|
2335
|
+
function selectSurfaceSafeHover(candidates, input) {
|
|
2336
|
+
return candidates.flatMap((candidate) => {
|
|
2337
|
+
const separation = buttonSurfaceSeparation(input.palette[candidate.token] ?? "", input.surface, {
|
|
2338
|
+
border: input.border,
|
|
2339
|
+
palette: input.palette,
|
|
2340
|
+
labelInk: input.palette[solidForegroundToken(candidate.token)] ?? ""
|
|
2341
|
+
});
|
|
2342
|
+
return separation.distinct ? [{
|
|
2343
|
+
...candidate,
|
|
2344
|
+
surfaceDistance: separation.deltaE
|
|
2345
|
+
}] : [];
|
|
2346
|
+
}).sort((left, right) => {
|
|
2347
|
+
const distanceDifference = left.distance - right.distance;
|
|
2348
|
+
if (distanceDifference !== 0) return distanceDifference;
|
|
2349
|
+
const contrastDifference = (right.surfaceDistance ?? 0) - (left.surfaceDistance ?? 0);
|
|
2350
|
+
if (contrastDifference !== 0) return contrastDifference;
|
|
2351
|
+
if (left.direction === right.direction) return left.token.localeCompare(right.token);
|
|
2352
|
+
return left.direction === input.fallbackDirection ? -1 : 1;
|
|
2353
|
+
})[0];
|
|
2354
|
+
}
|
|
2355
|
+
function shadeCandidates(seedToken, palette) {
|
|
2356
|
+
const match = String(seedToken).match(/^(.*?)(?:-(\d{2,3}))?$/);
|
|
2357
|
+
const family = match?.[1] ?? String(seedToken);
|
|
2358
|
+
const currentShade = match?.[2] ? Number(match[2]) : 500;
|
|
2359
|
+
const seedHex = palette[seedToken];
|
|
2360
|
+
const shades = Object.keys(palette).flatMap((token) => {
|
|
2361
|
+
const shade = token.match(new RegExp(`^${escapeRegExp(family)}-(\\d{2,3})$`));
|
|
2362
|
+
return shade?.[1] ? [Number(shade[1])] : [];
|
|
2363
|
+
}).filter((shade) => Number.isFinite(shade)).sort((left, right) => left - right);
|
|
2364
|
+
const lower = [...shades].filter((shade) => shade < currentShade).sort((left, right) => right - left);
|
|
2365
|
+
const higher = shades.filter((shade) => shade > currentShade);
|
|
2366
|
+
return [...lower.map((shade) => candidate(family, shade, currentShade, "lighter", seedHex, palette)), ...higher.map((shade) => candidate(family, shade, currentShade, "darker", seedHex, palette))].filter((value) => value !== null);
|
|
2367
|
+
}
|
|
2368
|
+
function candidate(family, shade, currentShade, direction, seedHex, palette) {
|
|
2369
|
+
const token = parseOpaqueButtonColourToken(`${family}-${shade}`);
|
|
2370
|
+
if (token === null) return null;
|
|
2371
|
+
const candidateHex = palette[token];
|
|
2372
|
+
if (!candidateHex || candidateHex === seedHex) return null;
|
|
2373
|
+
return {
|
|
2374
|
+
token,
|
|
2375
|
+
direction,
|
|
2376
|
+
distance: Math.abs(shade - currentShade),
|
|
2377
|
+
surfaceDistance: null
|
|
2378
|
+
};
|
|
2379
|
+
}
|
|
2380
|
+
function hasSafeTextContrast(token, palette, colourIndex) {
|
|
2381
|
+
const background = palette[token];
|
|
2382
|
+
const foreground = palette[solidForegroundToken(token)];
|
|
2383
|
+
return typeof background === "string" && typeof foreground === "string" && contrastRatio(background, foreground, colourIndex) >= BUTTON_CONTRAST_POLICY.textMinimumRatio;
|
|
2384
|
+
}
|
|
2385
|
+
function isSafeCandidate(token, palette, surface, colourIndex, border) {
|
|
2386
|
+
if (!hasSafeTextContrast(token, palette, colourIndex)) return false;
|
|
2387
|
+
return surface ? buttonSurfaceSeparation(palette[token] ?? "", surface, {
|
|
2388
|
+
border,
|
|
2389
|
+
palette,
|
|
2390
|
+
labelInk: palette[solidForegroundToken(token)] ?? ""
|
|
2391
|
+
}).distinct : true;
|
|
2392
|
+
}
|
|
2393
|
+
function escapeRegExp(value) {
|
|
2394
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2395
|
+
}
|
|
2396
|
+
//#endregion
|
|
2397
|
+
//#region ../theme-core/src/buttons/resolveButtonHoverTreatment.ts
|
|
2398
|
+
function resolveButtonHoverTreatment(input) {
|
|
2399
|
+
if (input.variant.contextualHover) {
|
|
2400
|
+
const contextual = resolveContextualHoverPreference({
|
|
2401
|
+
instruction: input.variant.contextualHover,
|
|
2402
|
+
palette: input.palette,
|
|
2403
|
+
colourIndex: input.colourIndex,
|
|
2404
|
+
surface: input.surface,
|
|
2405
|
+
border: input.variant.border
|
|
2406
|
+
});
|
|
2407
|
+
if (contextual.kind === "resolved") return {
|
|
2408
|
+
treatment: {
|
|
2409
|
+
type: "solid",
|
|
2410
|
+
colorToken: contextual.token
|
|
2411
|
+
},
|
|
2412
|
+
repair: contextual.repair
|
|
2413
|
+
};
|
|
2414
|
+
}
|
|
2415
|
+
const token = input.variant.hoverBackgroundToken ?? (input.global.hoverColor === "token" ? input.global.hoverColorToken : void 0);
|
|
2416
|
+
return {
|
|
2417
|
+
treatment: token === void 0 ? input.fallback : {
|
|
2418
|
+
type: "solid",
|
|
2419
|
+
colorToken: token
|
|
2420
|
+
},
|
|
2421
|
+
repair: null
|
|
2422
|
+
};
|
|
2423
|
+
}
|
|
2424
|
+
//#endregion
|
|
2425
|
+
//#region ../theme-core/src/buttons/resolveButtonColourStates.ts
|
|
2426
|
+
function mapVisualStates(value) {
|
|
2427
|
+
return {
|
|
2428
|
+
base: value("base"),
|
|
2429
|
+
hover: value("hover"),
|
|
2430
|
+
focus: value("focus"),
|
|
2431
|
+
active: value("active"),
|
|
2432
|
+
disabled: value("disabled")
|
|
2433
|
+
};
|
|
2434
|
+
}
|
|
2435
|
+
/** The border a state draws: its declared appearance's, otherwise the variant's. */
|
|
2436
|
+
function buttonStateBorder(variant, state) {
|
|
2437
|
+
const appearance = variant.visualStates?.[state];
|
|
2438
|
+
if (!appearance) return variant.border;
|
|
2439
|
+
return appearance.border === "none" ? void 0 : appearance.border;
|
|
2440
|
+
}
|
|
2441
|
+
function compileButtonColourStates(input) {
|
|
2442
|
+
if (input.variant.visualStates) return compileDeclaredVisualStates(input, input.variant.visualStates);
|
|
2443
|
+
const base = applyColourEffects({
|
|
2444
|
+
variantId: input.variant.id,
|
|
2445
|
+
state: "base",
|
|
2446
|
+
treatment: input.variant.background,
|
|
2447
|
+
effects: input.variant.effects?.base,
|
|
2448
|
+
palette: input.palette
|
|
2449
|
+
});
|
|
2450
|
+
if (!base.ok) return base;
|
|
2451
|
+
const hover = resolveButtonHoverTreatment({
|
|
2452
|
+
variant: input.variant,
|
|
2453
|
+
global: input.global,
|
|
2454
|
+
fallback: base.treatment,
|
|
2455
|
+
palette: input.palette,
|
|
2456
|
+
surface: input.surface,
|
|
2457
|
+
colourIndex: input.colourIndex
|
|
2458
|
+
});
|
|
2459
|
+
const colours = collectStateColours(mapVisualStates((state) => compileVisualState(input, state, state === "hover" ? hover.treatment : base.treatment, base.nonColourEffects)));
|
|
2460
|
+
return colours.ok ? {
|
|
2461
|
+
...colours,
|
|
2462
|
+
contextualHoverRepair: hover.repair
|
|
2463
|
+
} : colours;
|
|
2464
|
+
}
|
|
2465
|
+
function compileDeclaredVisualStates(input, states) {
|
|
2466
|
+
const hover = resolveButtonHoverTreatment({
|
|
2467
|
+
...input,
|
|
2468
|
+
variant: {
|
|
2469
|
+
...input.variant,
|
|
2470
|
+
contextualHover: states.hover.contextualHover,
|
|
2471
|
+
border: buttonStateBorder(input.variant, "hover"),
|
|
2472
|
+
hoverBackgroundToken: void 0
|
|
2473
|
+
},
|
|
2474
|
+
global: {
|
|
2475
|
+
...input.global,
|
|
2476
|
+
hoverColor: "none",
|
|
2477
|
+
hoverColorToken: void 0
|
|
2478
|
+
},
|
|
2479
|
+
fallback: states.hover.background
|
|
2480
|
+
});
|
|
2481
|
+
const colours = collectStateColours(mapVisualStates((state) => compileDeclaredVisualState(input, states, state, state === "hover" ? hover.treatment : states[state].background)));
|
|
2482
|
+
return colours.ok ? {
|
|
2483
|
+
...colours,
|
|
2484
|
+
focusIndicator: states.focus.indicator ? {
|
|
2485
|
+
kind: "surface-role",
|
|
2486
|
+
colorCss: input.surface?.foregroundCss ?? surfaceForegroundValue("text"),
|
|
2487
|
+
width: states.focus.indicator.width,
|
|
2488
|
+
offset: states.focus.indicator.offset,
|
|
2489
|
+
minimumSurfaceContrast: BUTTON_CONTRAST_POLICY.nonTextMinimumRatio
|
|
2490
|
+
} : colours.focusIndicator,
|
|
2491
|
+
contextualHoverRepair: hover.repair
|
|
2492
|
+
} : colours;
|
|
2493
|
+
}
|
|
2494
|
+
function compileDeclaredVisualState(input, states, state, treatment) {
|
|
2495
|
+
const appearance = states[state];
|
|
2496
|
+
const effects = state === "base" ? appearance.effects : [...states.base.effects, ...appearance.effects];
|
|
2497
|
+
const transition = applyColourEffects({
|
|
2498
|
+
variantId: input.variant.id,
|
|
2499
|
+
state,
|
|
2500
|
+
treatment,
|
|
2501
|
+
effects,
|
|
2502
|
+
palette: input.palette
|
|
2503
|
+
});
|
|
2504
|
+
if (!transition.ok) return transition;
|
|
2505
|
+
const resolved = resolveTreatment({
|
|
2506
|
+
variantId: input.variant.id,
|
|
2507
|
+
state,
|
|
2508
|
+
treatment: transition.treatment,
|
|
2509
|
+
border: buttonStateBorder(input.variant, state),
|
|
2510
|
+
palette: input.palette,
|
|
2511
|
+
surface: input.surface,
|
|
2512
|
+
colourIndex: input.colourIndex
|
|
2513
|
+
});
|
|
2514
|
+
return resolved.ok ? {
|
|
2515
|
+
...resolved,
|
|
2516
|
+
nonColourEffects: state === "disabled" ? [] : state === "base" ? transition.nonColourEffects : transition.nonColourEffects.filter((effect) => appearance.effects.includes(effect))
|
|
2517
|
+
} : resolved;
|
|
2518
|
+
}
|
|
2519
|
+
function compileVisualState(input, state, treatment, baseEffects) {
|
|
2520
|
+
const transition = state === "hover" || state === "focus" || state === "active" ? applyColourEffects({
|
|
2521
|
+
variantId: input.variant.id,
|
|
2522
|
+
state,
|
|
2523
|
+
treatment,
|
|
2524
|
+
effects: input.variant.effects?.[state],
|
|
2525
|
+
palette: input.palette
|
|
2526
|
+
}) : {
|
|
2527
|
+
ok: true,
|
|
2528
|
+
treatment,
|
|
2529
|
+
nonColourEffects: state === "base" ? baseEffects : []
|
|
2530
|
+
};
|
|
2531
|
+
if (!transition.ok) return transition;
|
|
2532
|
+
const resolved = resolveTreatment({
|
|
2533
|
+
variantId: input.variant.id,
|
|
2534
|
+
state,
|
|
2535
|
+
treatment: transition.treatment,
|
|
2536
|
+
palette: input.palette,
|
|
2537
|
+
surface: input.surface,
|
|
2538
|
+
colourIndex: input.colourIndex,
|
|
2539
|
+
border: buttonStateBorder(input.variant, state)
|
|
2540
|
+
});
|
|
2541
|
+
return resolved.ok ? {
|
|
2542
|
+
...resolved,
|
|
2543
|
+
nonColourEffects: transition.nonColourEffects
|
|
2544
|
+
} : resolved;
|
|
2545
|
+
}
|
|
2546
|
+
function collectStateColours(results) {
|
|
2547
|
+
if (!results.base.ok) return results.base;
|
|
2548
|
+
if (!results.hover.ok) return results.hover;
|
|
2549
|
+
if (!results.focus.ok) return results.focus;
|
|
2550
|
+
if (!results.active.ok) return results.active;
|
|
2551
|
+
if (!results.disabled.ok) return results.disabled;
|
|
2552
|
+
const states = {
|
|
2553
|
+
base: results.base.colour,
|
|
2554
|
+
hover: results.hover.colour,
|
|
2555
|
+
focus: results.focus.colour,
|
|
2556
|
+
active: results.active.colour,
|
|
2557
|
+
disabled: results.disabled.colour
|
|
2558
|
+
};
|
|
2559
|
+
return {
|
|
2560
|
+
ok: true,
|
|
2561
|
+
states,
|
|
2562
|
+
focusIndicator: resolveFocusIndicator(states.focus),
|
|
2563
|
+
nonColourEffects: Object.fromEntries(Object.entries(results).flatMap(([state, result]) => result.ok && result.nonColourEffects.length > 0 ? [[state, [...result.nonColourEffects]]] : []))
|
|
2564
|
+
};
|
|
2565
|
+
}
|
|
2566
|
+
function resolveTreatment(input) {
|
|
2567
|
+
const treatment = input.treatment;
|
|
2568
|
+
switch (treatment.type) {
|
|
2569
|
+
case "surface":
|
|
2570
|
+
if (input.surface) {
|
|
2571
|
+
const surface = input.surface;
|
|
2572
|
+
const foreground = buttonSurfaceGrounds(surface).map((backgroundHex) => validateButtonTextContrast({
|
|
2573
|
+
...input,
|
|
2574
|
+
background: "surface",
|
|
2575
|
+
backgroundHex,
|
|
2576
|
+
foreground: "surface-foreground",
|
|
2577
|
+
foregroundHex: surface.foregroundHex
|
|
2578
|
+
})).find((result) => !result.ok) ?? { ok: true };
|
|
2579
|
+
if (!foreground.ok) return foreground;
|
|
2580
|
+
}
|
|
2581
|
+
return {
|
|
2582
|
+
ok: true,
|
|
2583
|
+
colour: {
|
|
2584
|
+
kind: "surface",
|
|
2585
|
+
role: treatment.role,
|
|
2586
|
+
backgroundCss: "transparent",
|
|
2587
|
+
foregroundCss: input.surface?.foregroundCss ?? surfaceForegroundValue(treatment.role)
|
|
2588
|
+
}
|
|
2589
|
+
};
|
|
2590
|
+
case "solid": return resolveSolid(input, treatment.colorToken);
|
|
2591
|
+
case "gradient": return resolveGradient(input, treatment);
|
|
2592
|
+
}
|
|
2593
|
+
}
|
|
2594
|
+
function resolveFocusIndicator(colour) {
|
|
2595
|
+
switch (colour.kind) {
|
|
2596
|
+
case "solid":
|
|
2597
|
+
case "known-solid": return {
|
|
2598
|
+
kind: "two-tone",
|
|
2599
|
+
innerCss: colour.foregroundCss,
|
|
2600
|
+
outerCss: colour.backgroundCss,
|
|
2601
|
+
minimumPairContrast: BUTTON_CONTRAST_POLICY.textMinimumRatio
|
|
2602
|
+
};
|
|
2603
|
+
case "gradient": return {
|
|
2604
|
+
kind: "two-tone",
|
|
2605
|
+
innerCss: colour.foregroundCss,
|
|
2606
|
+
outerCss: tokenCss(colour.backgroundTokens[0]),
|
|
2607
|
+
minimumPairContrast: BUTTON_CONTRAST_POLICY.textMinimumRatio
|
|
2608
|
+
};
|
|
2609
|
+
case "surface": return {
|
|
2610
|
+
kind: "surface-role",
|
|
2611
|
+
colorCss: colour.foregroundCss,
|
|
2612
|
+
minimumSurfaceContrast: BUTTON_CONTRAST_POLICY.nonTextMinimumRatio
|
|
2613
|
+
};
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
function resolveSolid(input, backgroundToken) {
|
|
2617
|
+
const backgroundHex = paletteHex(input, backgroundToken);
|
|
2618
|
+
if (!backgroundHex.ok) return backgroundHex;
|
|
2619
|
+
const ink = resolveSolidInk(input, backgroundToken, backgroundHex.hex);
|
|
2620
|
+
const boundary = input.surface ? validateButtonFillSeparation({
|
|
2621
|
+
...input,
|
|
2622
|
+
buttonPaint: backgroundHex.hex,
|
|
2623
|
+
surface: input.surface,
|
|
2624
|
+
labelInk: ink.foregroundHex
|
|
2625
|
+
}) : { ok: true };
|
|
2626
|
+
if (!boundary.ok) return boundary;
|
|
2627
|
+
return {
|
|
2628
|
+
ok: true,
|
|
2629
|
+
colour: ink.colour
|
|
2630
|
+
};
|
|
2631
|
+
}
|
|
2632
|
+
/** Preserve checked on-colours; a solid state's last resort belongs to its actual fill. */
|
|
2633
|
+
function resolveSolidInk(input, backgroundToken, backgroundHex) {
|
|
2634
|
+
const foregroundToken = unsafeAsOpaqueButtonColourToken(solidForegroundToken(backgroundToken));
|
|
2635
|
+
const candidate = input.palette[foregroundToken];
|
|
2636
|
+
if ((typeof candidate === "string" ? validateButtonTextContrast({
|
|
2637
|
+
...input,
|
|
2638
|
+
background: backgroundToken,
|
|
2639
|
+
backgroundHex,
|
|
2640
|
+
foreground: foregroundToken,
|
|
2641
|
+
foregroundHex: candidate
|
|
2642
|
+
}) : null)?.ok === true && typeof candidate === "string") return {
|
|
2643
|
+
foregroundHex: candidate,
|
|
2644
|
+
colour: {
|
|
2645
|
+
kind: "solid",
|
|
2646
|
+
backgroundToken,
|
|
2647
|
+
foregroundToken,
|
|
2648
|
+
backgroundCss: tokenCss(backgroundToken),
|
|
2649
|
+
foregroundCss: tokenCss(foregroundToken)
|
|
2650
|
+
}
|
|
2651
|
+
};
|
|
2652
|
+
const foregroundHex = pickBlackOrWhiteTextColor(backgroundHex);
|
|
2653
|
+
return {
|
|
2654
|
+
foregroundHex,
|
|
2655
|
+
colour: {
|
|
2656
|
+
kind: "known-solid",
|
|
2657
|
+
backgroundCss: tokenCss(backgroundToken),
|
|
2658
|
+
foregroundCss: foregroundHex
|
|
2659
|
+
}
|
|
2660
|
+
};
|
|
2661
|
+
}
|
|
2662
|
+
function resolveGradient(input, treatment) {
|
|
2663
|
+
const foregroundHex = paletteHex(input, treatment.foregroundToken);
|
|
2664
|
+
if (!foregroundHex.ok) return foregroundHex;
|
|
2665
|
+
const stopHexes = [];
|
|
2666
|
+
for (const token of treatment.stops) {
|
|
2667
|
+
const stop = paletteHex(input, token);
|
|
2668
|
+
if (!stop.ok) return stop;
|
|
2669
|
+
stopHexes.push(stop.hex);
|
|
2670
|
+
}
|
|
2671
|
+
for (let segment = 0; segment < stopHexes.length - 1; segment += 1) {
|
|
2672
|
+
const start = stopHexes[segment];
|
|
2673
|
+
const end = stopHexes[segment + 1];
|
|
2674
|
+
const startToken = treatment.stops[segment];
|
|
2675
|
+
const endToken = treatment.stops[segment + 1];
|
|
2676
|
+
if (start === void 0 || end === void 0 || startToken === void 0 || endToken === void 0) continue;
|
|
2677
|
+
for (let sample = 0; sample <= BUTTON_CONTRAST_POLICY.gradientSamplesPerSegment; sample += 1) {
|
|
2678
|
+
const position = sample / BUTTON_CONTRAST_POLICY.gradientSamplesPerSegment;
|
|
2679
|
+
const sampleHex = interpolateHex(start, end, position);
|
|
2680
|
+
const contrast = validateButtonTextContrast({
|
|
2681
|
+
...input,
|
|
2682
|
+
background: `${startToken}→${endToken}@${position.toFixed(2)}`,
|
|
2683
|
+
backgroundHex: sampleHex,
|
|
2684
|
+
foreground: treatment.foregroundToken,
|
|
2685
|
+
foregroundHex: foregroundHex.hex
|
|
2686
|
+
});
|
|
2687
|
+
if (!contrast.ok) return contrast;
|
|
2688
|
+
if (input.surface) {
|
|
2689
|
+
const boundary = validateButtonFillSeparation({
|
|
2690
|
+
...input,
|
|
2691
|
+
buttonPaint: sampleHex,
|
|
2692
|
+
labelInk: foregroundHex.hex,
|
|
2693
|
+
surface: input.surface
|
|
2694
|
+
});
|
|
2695
|
+
if (!boundary.ok) return boundary;
|
|
2696
|
+
}
|
|
2697
|
+
}
|
|
2698
|
+
}
|
|
2699
|
+
const direction = GRADIENT_DIRECTION_MAP[treatment.direction] ?? "to right";
|
|
2700
|
+
return {
|
|
2701
|
+
ok: true,
|
|
2702
|
+
colour: {
|
|
2703
|
+
kind: "gradient",
|
|
2704
|
+
backgroundTokens: treatment.stops,
|
|
2705
|
+
foregroundToken: treatment.foregroundToken,
|
|
2706
|
+
backgroundCss: `linear-gradient(${direction}, ${treatment.stops.map(tokenCss).join(", ")})`,
|
|
2707
|
+
foregroundCss: tokenCss(treatment.foregroundToken)
|
|
2708
|
+
}
|
|
2709
|
+
};
|
|
2710
|
+
}
|
|
2711
|
+
function paletteHex(input, token) {
|
|
2712
|
+
const hex = input.palette[token];
|
|
2713
|
+
return typeof hex === "string" ? {
|
|
2714
|
+
ok: true,
|
|
2715
|
+
hex
|
|
2716
|
+
} : {
|
|
2717
|
+
ok: false,
|
|
2718
|
+
error: {
|
|
2719
|
+
tag: "unknown_palette_token",
|
|
2720
|
+
variantId: input.variantId,
|
|
2721
|
+
state: input.state,
|
|
2722
|
+
token
|
|
2723
|
+
}
|
|
2724
|
+
};
|
|
2725
|
+
}
|
|
2726
|
+
function tokenCss(token) {
|
|
2727
|
+
return `rgb(var(--tb-${token}))`;
|
|
2728
|
+
}
|
|
2729
|
+
function interpolateHex(startHex, endHex, position) {
|
|
2730
|
+
const start = hexToRgb(startHex);
|
|
2731
|
+
const end = hexToRgb(endHex);
|
|
2732
|
+
const channel = (from, to) => Math.round(from + (to - from) * position).toString(16).padStart(2, "0");
|
|
2733
|
+
return `#${channel(start.r, end.r)}${channel(start.g, end.g)}${channel(start.b, end.b)}`;
|
|
2734
|
+
}
|
|
2735
|
+
//#endregion
|
|
2736
|
+
//#region ../theme-core/src/buttons/buttonSurfaceContext.ts
|
|
2737
|
+
/** The last resort, chosen by `maxContrastBlackOrWhite`. */
|
|
2738
|
+
const LITERAL_NEUTRALS = {
|
|
2739
|
+
black: {
|
|
2740
|
+
hex: "#000000",
|
|
2741
|
+
css: "#000000",
|
|
2742
|
+
source: "literal-css"
|
|
2743
|
+
},
|
|
2744
|
+
white: {
|
|
2745
|
+
hex: "#ffffff",
|
|
2746
|
+
css: "#ffffff",
|
|
2747
|
+
source: "literal-css"
|
|
2748
|
+
}
|
|
2749
|
+
};
|
|
2750
|
+
/**
|
|
2751
|
+
* Derive only what the rendered section can honestly prove about its backing.
|
|
2752
|
+
* Images, gradients, alpha/composite layers and arbitrary CSS remain unknown.
|
|
2753
|
+
*/
|
|
2754
|
+
function deriveButtonSurfaceContext(input, palette, fallbackToken, colourIndex) {
|
|
2755
|
+
const background = deriveKnownBackground(input, palette, fallbackToken);
|
|
2756
|
+
if (background.kind === "unknown") return background;
|
|
2757
|
+
const explicitForeground = resolveKnownColour(input.kind === "solid" || input.kind === "inherit" ? input.foreground ?? "" : "", palette);
|
|
2758
|
+
const foreground = explicitForeground && contrastRatio(background.colour.hex, explicitForeground.hex, colourIndex) >= 4.5 ? explicitForeground : LITERAL_NEUTRALS[maxContrastBlackOrWhite(solidPaint(background.colour.hex, colourIndex)).ink];
|
|
2759
|
+
return {
|
|
2760
|
+
kind: "known-solid",
|
|
2761
|
+
source: background.source,
|
|
2762
|
+
surface: {
|
|
2763
|
+
kind: "solid",
|
|
2764
|
+
backgroundHex: background.colour.hex,
|
|
2765
|
+
backgroundCss: background.colour.css,
|
|
2766
|
+
...input.kind === "solid" && input.backgroundSamples ? { backgroundSamples: input.backgroundSamples } : {},
|
|
2767
|
+
foregroundHex: foreground.hex,
|
|
2768
|
+
foregroundCss: foreground.css
|
|
2769
|
+
}
|
|
2770
|
+
};
|
|
2771
|
+
}
|
|
2772
|
+
function deriveKnownBackground(input, palette, fallbackToken) {
|
|
2773
|
+
switch (input.kind) {
|
|
2774
|
+
case "inherit": return fallbackBackground(fallbackToken, palette);
|
|
2775
|
+
case "image": return {
|
|
2776
|
+
kind: "unknown",
|
|
2777
|
+
reason: "image-background"
|
|
2778
|
+
};
|
|
2779
|
+
case "gradient": return {
|
|
2780
|
+
kind: "unknown",
|
|
2781
|
+
reason: "gradient-background"
|
|
2782
|
+
};
|
|
2783
|
+
case "unknown": return {
|
|
2784
|
+
kind: "unknown",
|
|
2785
|
+
reason: "unresolvable-colour"
|
|
2786
|
+
};
|
|
2787
|
+
case "solid": if (input.composited) return {
|
|
2788
|
+
kind: "unknown",
|
|
2789
|
+
reason: "composited-background"
|
|
2790
|
+
};
|
|
2791
|
+
}
|
|
2792
|
+
const authored = readNonEmptyString(input.color);
|
|
2793
|
+
const backgroundValue = authored ?? fallbackToken;
|
|
2794
|
+
if (!backgroundValue) return {
|
|
2795
|
+
kind: "unknown",
|
|
2796
|
+
reason: "missing-background"
|
|
2797
|
+
};
|
|
2798
|
+
const colour = resolveKnownSurfaceColour(backgroundValue, palette, authored ? fallbackToken : void 0);
|
|
2799
|
+
if (!colour) return {
|
|
2800
|
+
kind: "unknown",
|
|
2801
|
+
reason: "unresolvable-colour"
|
|
2802
|
+
};
|
|
2803
|
+
return {
|
|
2804
|
+
kind: "known",
|
|
2805
|
+
colour,
|
|
2806
|
+
source: authored ? colour.source : "fallback-token"
|
|
2807
|
+
};
|
|
2808
|
+
}
|
|
2809
|
+
function resolveKnownSurfaceColour(value, palette, underlayReference) {
|
|
2810
|
+
const hex = resolveOpaqueSurfaceHex(value, palette, underlayReference);
|
|
2811
|
+
if (!hex) return resolveKnownColour(value, palette);
|
|
2812
|
+
const reference = parseThemeColorReference(value, { palette });
|
|
2813
|
+
return {
|
|
2814
|
+
hex,
|
|
2815
|
+
css: resolveThemeColorReferenceValue(value, { palette }),
|
|
2816
|
+
source: reference.kind === "literal-css" ? "literal-css" : "palette-token"
|
|
2817
|
+
};
|
|
2818
|
+
}
|
|
2819
|
+
function fallbackBackground(fallbackToken, palette) {
|
|
2820
|
+
if (!fallbackToken) return {
|
|
2821
|
+
kind: "unknown",
|
|
2822
|
+
reason: "missing-background"
|
|
2823
|
+
};
|
|
2824
|
+
const colour = resolveKnownColour(fallbackToken, palette);
|
|
2825
|
+
return colour ? {
|
|
2826
|
+
kind: "known",
|
|
2827
|
+
colour,
|
|
2828
|
+
source: "fallback-token"
|
|
2829
|
+
} : {
|
|
2830
|
+
kind: "unknown",
|
|
2831
|
+
reason: "unresolvable-colour"
|
|
2832
|
+
};
|
|
2833
|
+
}
|
|
2834
|
+
function resolveSurfaceButtonContext(input) {
|
|
2835
|
+
if (!input.buttonSystem) return input.withoutButtonSystem === "reset" ? {
|
|
2836
|
+
kind: "reset",
|
|
2837
|
+
styles: contextualButtonSurfaceResetStyles()
|
|
2838
|
+
} : {
|
|
2839
|
+
kind: "inherit",
|
|
2840
|
+
styles: {}
|
|
2841
|
+
};
|
|
2842
|
+
const context = deriveButtonSurfaceContext(input.surface, input.palette, input.fallbackToken, input.colourIndex);
|
|
2843
|
+
if (context.kind !== "known-solid") return context.reason === "missing-background" ? {
|
|
2844
|
+
kind: "inherit",
|
|
2845
|
+
styles: {}
|
|
2846
|
+
} : {
|
|
2847
|
+
kind: "reset",
|
|
2848
|
+
styles: contextualButtonSurfaceResetStyles()
|
|
2849
|
+
};
|
|
2850
|
+
return knownSurfaceButtonContext({
|
|
2851
|
+
surface: context.surface,
|
|
2852
|
+
palette: input.palette,
|
|
2853
|
+
colourIndex: input.colourIndex,
|
|
2854
|
+
buttonSystem: surfaceButtonSystem(input.buttonSystem, input.primaryToken)
|
|
2855
|
+
});
|
|
2856
|
+
}
|
|
2857
|
+
function knownSurfaceButtonContext(input) {
|
|
2858
|
+
const roles = freezeOwnedThemeValue({
|
|
2859
|
+
primary: resolveContextualButtonRole({
|
|
2860
|
+
...input,
|
|
2861
|
+
role: "primary"
|
|
2862
|
+
}),
|
|
2863
|
+
secondary: resolveContextualButtonRole({
|
|
2864
|
+
...input,
|
|
2865
|
+
role: "secondary"
|
|
2866
|
+
}),
|
|
2867
|
+
outline: resolveContextualButtonRole({
|
|
2868
|
+
...input,
|
|
2869
|
+
role: "outline"
|
|
2870
|
+
}),
|
|
2871
|
+
ghost: resolveContextualButtonRole({
|
|
2872
|
+
...input,
|
|
2873
|
+
role: "ghost"
|
|
2874
|
+
}),
|
|
2875
|
+
accent: resolveContextualButtonRole({
|
|
2876
|
+
...input,
|
|
2877
|
+
role: "accent"
|
|
2878
|
+
})
|
|
2879
|
+
});
|
|
2880
|
+
const styles = Object.fromEntries(VARIANT_ROLES.flatMap((role) => Object.entries(contextualButtonSurfaceStyles(roles[role]))));
|
|
2881
|
+
return Object.defineProperty({
|
|
2882
|
+
kind: "resolved",
|
|
2883
|
+
styles,
|
|
2884
|
+
roles
|
|
2885
|
+
}, "roles", { enumerable: false });
|
|
2886
|
+
}
|
|
2887
|
+
function resolveContextualButtonRole(input) {
|
|
2888
|
+
const requested = findVariant(input.buttonSystem, input.role);
|
|
2889
|
+
if (!requested) return {
|
|
2890
|
+
kind: "unresolved",
|
|
2891
|
+
requestedRole: input.role,
|
|
2892
|
+
rejectedCandidates: []
|
|
2893
|
+
};
|
|
2894
|
+
const preferred = compileCandidate(requested, input);
|
|
2895
|
+
if (preferred.ok) return preferredButtonResolution(requested, preferred, input.role);
|
|
2896
|
+
return resolveFallbackButtonRole(input, requested, (input.buttonSystem.surfacePolicy ?? STANDARD_BUTTON_SURFACE_POLICY)[input.role], [{
|
|
2897
|
+
candidate: "preferred",
|
|
2898
|
+
error: preferred.error
|
|
2899
|
+
}]);
|
|
2900
|
+
}
|
|
2901
|
+
function preferredButtonResolution(requested, compiled, role) {
|
|
2902
|
+
const appearance = {
|
|
2903
|
+
requestedRole: role,
|
|
2904
|
+
states: compiled.states,
|
|
2905
|
+
focusIndicator: compiled.focusIndicator,
|
|
2906
|
+
boundary: boundaryForVariant(requested)
|
|
2907
|
+
};
|
|
2908
|
+
return compiled.contextualHoverRepair ? withBorderEvidence({
|
|
2909
|
+
...appearance,
|
|
2910
|
+
kind: "repaired",
|
|
2911
|
+
candidate: "contextual-hover",
|
|
2912
|
+
rejectedCandidates: []
|
|
2913
|
+
}, requested) : withBorderEvidence({
|
|
2914
|
+
...appearance,
|
|
2915
|
+
kind: "preferred"
|
|
2916
|
+
}, requested);
|
|
2917
|
+
}
|
|
2918
|
+
/** Ordered, lazy fallback selection; the rejected evidence belongs to this decision. */
|
|
2919
|
+
function resolveFallbackButtonRole(input, requested, fallbacks, rejected) {
|
|
2920
|
+
const [fallback, ...remaining] = fallbacks;
|
|
2921
|
+
if (!fallback) return {
|
|
2922
|
+
kind: "unresolved",
|
|
2923
|
+
requestedRole: input.role,
|
|
2924
|
+
rejectedCandidates: rejected
|
|
2925
|
+
};
|
|
2926
|
+
const candidate = candidateVariant(fallback, requested, input.buttonSystem);
|
|
2927
|
+
if (!candidate) return resolveFallbackButtonRole(input, requested, remaining, rejected);
|
|
2928
|
+
const compiled = compileCandidate(candidate.variant, input);
|
|
2929
|
+
return compiled.ok ? withBorderEvidence({
|
|
2930
|
+
kind: "repaired",
|
|
2931
|
+
requestedRole: input.role,
|
|
2932
|
+
candidate: candidate.name,
|
|
2933
|
+
states: candidate.name === "surface-outline" ? withSurfaceInversion(compiled.states, input.surface) : compiled.states,
|
|
2934
|
+
focusIndicator: compiled.focusIndicator,
|
|
2935
|
+
boundary: candidate.boundary,
|
|
2936
|
+
rejectedCandidates: rejected
|
|
2937
|
+
}, candidate.variant) : resolveFallbackButtonRole(input, requested, remaining, [...rejected, {
|
|
2938
|
+
candidate: candidate.name,
|
|
2939
|
+
error: compiled.error
|
|
2940
|
+
}]);
|
|
2941
|
+
}
|
|
2942
|
+
function contextualButtonSurfaceStyles(resolution) {
|
|
2943
|
+
if (resolution.kind === "unresolved") return resetActionVariables(resolution.requestedRole);
|
|
2944
|
+
const styles = {};
|
|
2945
|
+
for (const state of BUTTON_VISUAL_STATES) {
|
|
2946
|
+
const colour = resolution.states[state];
|
|
2947
|
+
const prefix = actionVariablePrefix(resolution.requestedRole, state);
|
|
2948
|
+
styles[`${prefix}-background-color`] = colour.kind === "solid" || colour.kind === "known-solid" ? colour.backgroundCss : "transparent";
|
|
2949
|
+
styles[`${prefix}-background-image`] = colour.kind === "gradient" ? colour.backgroundCss : "none";
|
|
2950
|
+
styles[`${prefix}-color`] = colour.foregroundCss;
|
|
2951
|
+
}
|
|
2952
|
+
const focus = resolution.focusIndicator;
|
|
2953
|
+
styles[actionVariableName(resolution.requestedRole, "focus", "outline")] = focus.kind === "two-tone" ? `2px solid ${focus.innerCss}` : `3px solid ${focus.colorCss}`;
|
|
2954
|
+
styles[actionVariableName(resolution.requestedRole, "focus", "outline-offset")] = focus.kind === "two-tone" ? "2px" : "3px";
|
|
2955
|
+
styles[actionVariableName(resolution.requestedRole, "focus", "box-shadow")] = focus.kind === "two-tone" ? `0 0 0 4px ${focus.outerCss}` : "none";
|
|
2956
|
+
const boundary = contextualBoundaryStyles(resolution.boundary);
|
|
2957
|
+
styles[actionVariableName(resolution.requestedRole, "base", "outline")] = boundary.outline;
|
|
2958
|
+
styles[actionVariableName(resolution.requestedRole, "base", "outline-offset")] = boundary.offset;
|
|
2959
|
+
return styles;
|
|
2960
|
+
}
|
|
2961
|
+
/**
|
|
2962
|
+
* Break an inherited surface contract when a nested element establishes a
|
|
2963
|
+
* backing whose colours cannot be proven (for example an image or gradient).
|
|
2964
|
+
*/
|
|
2965
|
+
function contextualButtonSurfaceResetStyles() {
|
|
2966
|
+
return Object.fromEntries(VARIANT_ROLES.flatMap((role) => Object.entries(resetActionVariables(role))));
|
|
2967
|
+
}
|
|
2968
|
+
function resetActionVariables(role) {
|
|
2969
|
+
const styles = {};
|
|
2970
|
+
for (const state of BUTTON_VISUAL_STATES) for (const property of [
|
|
2971
|
+
"background-color",
|
|
2972
|
+
"background-image",
|
|
2973
|
+
"color"
|
|
2974
|
+
]) styles[actionVariableName(role, state, property)] = "initial";
|
|
2975
|
+
for (const [state, property] of [
|
|
2976
|
+
["base", "outline"],
|
|
2977
|
+
["base", "outline-offset"],
|
|
2978
|
+
["focus", "outline"],
|
|
2979
|
+
["focus", "outline-offset"],
|
|
2980
|
+
["focus", "box-shadow"]
|
|
2981
|
+
]) styles[actionVariableName(role, state, property)] = "initial";
|
|
2982
|
+
return styles;
|
|
2983
|
+
}
|
|
2984
|
+
function withSurfaceInversion(states, surface) {
|
|
2985
|
+
const inverted = {
|
|
2986
|
+
kind: "known-solid",
|
|
2987
|
+
backgroundCss: surface.foregroundCss,
|
|
2988
|
+
foregroundCss: surface.backgroundCss
|
|
2989
|
+
};
|
|
2990
|
+
return {
|
|
2991
|
+
...states,
|
|
2992
|
+
hover: inverted,
|
|
2993
|
+
active: inverted
|
|
2994
|
+
};
|
|
2995
|
+
}
|
|
2996
|
+
function actionVariableName(role, state, property) {
|
|
2997
|
+
return `--rb-action-${role}-${state}-${property}`;
|
|
2998
|
+
}
|
|
2999
|
+
function actionVariableFallback(role, state, property, fallback) {
|
|
3000
|
+
return `var(${actionVariableName(role, state, property)}, ${fallback})`;
|
|
3001
|
+
}
|
|
3002
|
+
function actionVariablePrefix(role, state) {
|
|
3003
|
+
return `--rb-action-${role}-${state}`;
|
|
3004
|
+
}
|
|
3005
|
+
function compileCandidate(variant, context) {
|
|
3006
|
+
return compileButtonColourStates({
|
|
3007
|
+
variant,
|
|
3008
|
+
global: context.buttonSystem.global,
|
|
3009
|
+
palette: context.palette,
|
|
3010
|
+
surface: context.surface,
|
|
3011
|
+
colourIndex: context.colourIndex
|
|
3012
|
+
});
|
|
3013
|
+
}
|
|
3014
|
+
function candidateVariant(fallback, requested, system) {
|
|
3015
|
+
if (fallback.kind === "variant") {
|
|
3016
|
+
const variant = findVariant(system, fallback.role);
|
|
3017
|
+
return variant ? {
|
|
3018
|
+
name: fallback.role,
|
|
3019
|
+
variant,
|
|
3020
|
+
boundary: boundaryForVariant(variant)
|
|
3021
|
+
} : null;
|
|
3022
|
+
}
|
|
3023
|
+
const width = BORDER_WIDTH_MAP.border ?? "1px";
|
|
3024
|
+
return {
|
|
3025
|
+
name: "surface-outline",
|
|
3026
|
+
variant: {
|
|
3027
|
+
...requested,
|
|
3028
|
+
visualStates: void 0,
|
|
3029
|
+
background: {
|
|
3030
|
+
type: "surface",
|
|
3031
|
+
role: "link"
|
|
3032
|
+
},
|
|
3033
|
+
border: { widthClass: "border" },
|
|
3034
|
+
hoverBackgroundToken: void 0,
|
|
3035
|
+
contextualHover: void 0,
|
|
3036
|
+
effects: void 0
|
|
3037
|
+
},
|
|
3038
|
+
boundary: {
|
|
3039
|
+
width,
|
|
3040
|
+
color: "currentColor"
|
|
3041
|
+
}
|
|
3042
|
+
};
|
|
3043
|
+
}
|
|
3044
|
+
/** Each state's border travels with the decision, copied so freezing it never touches the caller's variant. */
|
|
3045
|
+
function withBorderEvidence(value, variant) {
|
|
3046
|
+
const borders = ownedThemeSnapshot(Object.fromEntries(BUTTON_VISUAL_STATES.map((state) => [state, buttonStateBorder(variant, state)])));
|
|
3047
|
+
return {
|
|
3048
|
+
...value,
|
|
3049
|
+
borders
|
|
3050
|
+
};
|
|
3051
|
+
}
|
|
3052
|
+
function boundaryForVariant(variant) {
|
|
3053
|
+
if (!variant.border) return null;
|
|
3054
|
+
return {
|
|
3055
|
+
...variant.border.ring ? { ring: true } : {},
|
|
3056
|
+
width: BORDER_WIDTH_MAP[variant.border.widthClass] ?? "1px",
|
|
3057
|
+
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"
|
|
3058
|
+
};
|
|
3059
|
+
}
|
|
3060
|
+
function findVariant(system, role) {
|
|
3061
|
+
return system.variants.find((variant) => variant.enabled && variant.id === role);
|
|
3062
|
+
}
|
|
3063
|
+
function resolveKnownColour(value, palette) {
|
|
3064
|
+
const reference = parseThemeColorReference(value, { palette });
|
|
3065
|
+
if (reference.kind !== "literal-css") {
|
|
3066
|
+
const token = String(reference.token);
|
|
3067
|
+
const paletteHex = palette[token];
|
|
3068
|
+
const hex = paletteHex ? normalizeOpaqueHex(paletteHex) : null;
|
|
3069
|
+
if (hex) return {
|
|
3070
|
+
hex,
|
|
3071
|
+
css: resolveThemeColorReferenceValue(value, { palette }),
|
|
3072
|
+
source: "palette-token"
|
|
3073
|
+
};
|
|
3074
|
+
const namedHex = NAMED_OPAQUE_COLOURS[token.toLowerCase()];
|
|
3075
|
+
return namedHex ? {
|
|
3076
|
+
hex: namedHex,
|
|
3077
|
+
css: token,
|
|
3078
|
+
source: "literal-css"
|
|
3079
|
+
} : null;
|
|
3080
|
+
}
|
|
3081
|
+
const hex = normalizeOpaqueCssColour(reference.value);
|
|
3082
|
+
return hex ? {
|
|
3083
|
+
hex,
|
|
3084
|
+
css: reference.value,
|
|
3085
|
+
source: "literal-css"
|
|
3086
|
+
} : null;
|
|
3087
|
+
}
|
|
3088
|
+
const NAMED_OPAQUE_COLOURS = {
|
|
3089
|
+
black: "#000000",
|
|
3090
|
+
white: "#ffffff",
|
|
3091
|
+
red: "#ff0000",
|
|
3092
|
+
green: "#008000",
|
|
3093
|
+
blue: "#0000ff",
|
|
3094
|
+
yellow: "#ffff00",
|
|
3095
|
+
gray: "#808080",
|
|
3096
|
+
grey: "#808080",
|
|
3097
|
+
orange: "#ffa500",
|
|
3098
|
+
purple: "#800080",
|
|
3099
|
+
pink: "#ffc0cb"
|
|
3100
|
+
};
|
|
3101
|
+
function normalizeOpaqueCssColour(value) {
|
|
3102
|
+
const trimmed = value.trim();
|
|
3103
|
+
const hex = normalizeOpaqueHex(trimmed);
|
|
3104
|
+
if (hex) return hex;
|
|
3105
|
+
return NAMED_OPAQUE_COLOURS[trimmed.toLowerCase()] ?? normalizeOpaqueRgb(trimmed) ?? normalizeOpaqueOklch(trimmed);
|
|
3106
|
+
}
|
|
3107
|
+
function normalizeOpaqueRgb(value) {
|
|
3108
|
+
const match = value.match(/^rgb\(\s*(\d{1,3})\s*[, ]\s*(\d{1,3})\s*[, ]\s*(\d{1,3})\s*\)$/i);
|
|
3109
|
+
if (!match) return null;
|
|
3110
|
+
const channels = match.slice(1).map(Number);
|
|
3111
|
+
if (channels.some((channel) => channel < 0 || channel > 255)) return null;
|
|
3112
|
+
const [red, green, blue] = channels;
|
|
3113
|
+
return red === void 0 || green === void 0 || blue === void 0 ? null : rgbToHex(red, green, blue);
|
|
3114
|
+
}
|
|
3115
|
+
function normalizeOpaqueOklch(value) {
|
|
3116
|
+
const match = value.match(/^oklch\(\s*([\d.]+)(%)?\s+([\d.]+)\s+([\d.]+)(?:deg)?\s*\)$/i);
|
|
3117
|
+
if (!match?.[1] || !match[3] || !match[4]) return null;
|
|
3118
|
+
const lightness = Number(match[1]) / (match[2] ? 100 : 1);
|
|
3119
|
+
const chroma = Number(match[3]);
|
|
3120
|
+
const hue = Number(match[4]);
|
|
3121
|
+
if (![
|
|
3122
|
+
lightness,
|
|
3123
|
+
chroma,
|
|
3124
|
+
hue
|
|
3125
|
+
].every(Number.isFinite)) return null;
|
|
3126
|
+
if (lightness < 0 || lightness > 1) return null;
|
|
3127
|
+
const lab = oklchToOklab(lightness, chroma, hue);
|
|
3128
|
+
const rgb = oklabToSrgb(lab.L, lab.a, lab.b);
|
|
3129
|
+
return rgbToHex(clampChannel(rgb.r), clampChannel(rgb.g), clampChannel(rgb.b));
|
|
3130
|
+
}
|
|
3131
|
+
function clampChannel(value) {
|
|
3132
|
+
return Math.max(0, Math.min(255, value));
|
|
3133
|
+
}
|
|
3134
|
+
function normalizeOpaqueHex(value) {
|
|
3135
|
+
const match = value.trim().match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);
|
|
3136
|
+
if (!match?.[1]) return null;
|
|
3137
|
+
return `#${(match[1].length === 3 ? match[1].split("").map((digit) => `${digit}${digit}`).join("") : match[1]).toLowerCase()}`;
|
|
3138
|
+
}
|
|
3139
|
+
function readNonEmptyString(value) {
|
|
3140
|
+
return typeof value === "string" && value.trim() ? value.trim() : null;
|
|
3141
|
+
}
|
|
3142
|
+
function contextualBoundaryStyles(boundary) {
|
|
3143
|
+
if (boundary === null) return {
|
|
3144
|
+
outline: "none",
|
|
3145
|
+
offset: "0px"
|
|
3146
|
+
};
|
|
3147
|
+
return {
|
|
3148
|
+
outline: `${boundary.width} solid ${boundary.color}`,
|
|
3149
|
+
offset: boundary.ring ? "3px" : `-${boundary.width}`
|
|
3150
|
+
};
|
|
3151
|
+
}
|
|
3152
|
+
//#endregion
|
|
3153
|
+
//#region ../theme-core/src/palette/utils/scrimContrast.ts
|
|
3154
|
+
const WHITE = "#ffffff";
|
|
3155
|
+
const BLACK = "#000000";
|
|
3156
|
+
/** `top` at `alpha` over opaque `bottom`, blended as CSS paints an overlay. */
|
|
3157
|
+
function compositeHex(topHex, alpha, bottomHex) {
|
|
3158
|
+
const top = hexToRgb(topHex);
|
|
3159
|
+
const bottom = hexToRgb(bottomHex);
|
|
3160
|
+
const mix = (a, b) => Math.round(alpha * a + (1 - alpha) * b);
|
|
3161
|
+
return rgbToHex(mix(top.r, bottom.r), mix(top.g, bottom.g), mix(top.b, bottom.b));
|
|
3162
|
+
}
|
|
3163
|
+
/**
|
|
3164
|
+
* The lowest contrast `foreground` can reach over `scrim` at `alpha` laid on
|
|
3165
|
+
* any pixel. A foreground whose luminance falls inside the range the
|
|
3166
|
+
* composites can take has a worst case of 1:1.
|
|
3167
|
+
*/
|
|
3168
|
+
function worstCaseScrimContrast(input) {
|
|
3169
|
+
const overWhite = compositeHex(input.scrimHex, input.alpha, WHITE);
|
|
3170
|
+
const overBlack = compositeHex(input.scrimHex, input.alpha, BLACK);
|
|
3171
|
+
const luminance = (hex) => {
|
|
3172
|
+
const { r, g, b } = hexToRgb(hex);
|
|
3173
|
+
return relativeLuminance(r, g, b);
|
|
3174
|
+
};
|
|
3175
|
+
const foreground = luminance(input.foregroundHex);
|
|
3176
|
+
const low = luminance(overBlack);
|
|
3177
|
+
const high = luminance(overWhite);
|
|
3178
|
+
if (foreground >= low && foreground <= high) return 1;
|
|
3179
|
+
return Math.min(contrastRatio(input.foregroundHex, overWhite), contrastRatio(input.foregroundHex, overBlack));
|
|
3180
|
+
}
|
|
3181
|
+
/** Shared samples for literal RGB washes and palette-token gradient veils. */
|
|
3182
|
+
function gradientScrimSamples(gradient, alpha, palette) {
|
|
3183
|
+
const literal = [...gradient.matchAll(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/g)].map((stop) => ({
|
|
3184
|
+
hex: rgbToHex(Number(stop[1]), Number(stop[2]), Number(stop[3])),
|
|
3185
|
+
alpha: alpha * (stop[4] === void 0 ? 1 : Number(stop[4]))
|
|
3186
|
+
}));
|
|
3187
|
+
const tokens = [...gradient.matchAll(/var\(--tb-([\w-]+)\)/g)].flatMap((stop) => {
|
|
3188
|
+
const hex = stop[1] ? resolveConcreteColorHex(stop[1], palette) : null;
|
|
3189
|
+
return hex ? [{
|
|
3190
|
+
hex,
|
|
3191
|
+
alpha
|
|
3192
|
+
}] : [];
|
|
3193
|
+
});
|
|
3194
|
+
return [...literal, ...tokens];
|
|
3195
|
+
}
|
|
3196
|
+
/** The ink with the stronger worst-pixel guarantee identifies the veil tone.
|
|
3197
|
+
* No readable samples (or a tie) leaves classification to the foreground owner.
|
|
3198
|
+
*/
|
|
3199
|
+
function scrimTone(samples) {
|
|
3200
|
+
if (samples.length === 0) return null;
|
|
3201
|
+
const worst = (foregroundHex) => Math.min(...samples.map((sample) => worstCaseScrimContrast({
|
|
3202
|
+
foregroundHex,
|
|
3203
|
+
scrimHex: sample.hex,
|
|
3204
|
+
alpha: sample.alpha
|
|
3205
|
+
})));
|
|
3206
|
+
const white = worst(WHITE);
|
|
3207
|
+
const black = worst(BLACK);
|
|
3208
|
+
return white === black ? null : white > black ? "dark" : "light";
|
|
3209
|
+
}
|
|
3210
|
+
//#endregion
|
|
3211
|
+
//#region ../theme-core/src/site-styles/accessibleSurfaces.ts
|
|
3212
|
+
const ON_BACKGROUND = { kind: "on-background" };
|
|
3213
|
+
const surfaceRecipes = {
|
|
3214
|
+
base: {
|
|
3215
|
+
backgroundCandidates: ["background", "surface"],
|
|
3216
|
+
headingCandidates: [
|
|
3217
|
+
"text",
|
|
3218
|
+
ON_BACKGROUND,
|
|
3219
|
+
"neutral-950",
|
|
3220
|
+
"neutral-50"
|
|
3221
|
+
],
|
|
3222
|
+
textCandidates: [
|
|
3223
|
+
"text",
|
|
3224
|
+
ON_BACKGROUND,
|
|
3225
|
+
"neutral-950",
|
|
3226
|
+
"neutral-50"
|
|
3227
|
+
],
|
|
3228
|
+
linkCandidates: [
|
|
3229
|
+
"primary",
|
|
3230
|
+
"text",
|
|
3231
|
+
ON_BACKGROUND,
|
|
3232
|
+
"neutral-950",
|
|
3233
|
+
"neutral-50"
|
|
3234
|
+
],
|
|
3235
|
+
supportingCandidates: ["mutedText"],
|
|
3236
|
+
inheritedBackground: true
|
|
3237
|
+
},
|
|
3238
|
+
"muted-band": {
|
|
3239
|
+
backgroundCandidates: [
|
|
3240
|
+
"muted",
|
|
3241
|
+
"surfaceAlt",
|
|
3242
|
+
"surface",
|
|
3243
|
+
"background"
|
|
3244
|
+
],
|
|
3245
|
+
headingCandidates: [
|
|
3246
|
+
ON_BACKGROUND,
|
|
3247
|
+
"text",
|
|
3248
|
+
"neutral-950",
|
|
3249
|
+
"neutral-50"
|
|
3250
|
+
],
|
|
3251
|
+
textCandidates: [
|
|
3252
|
+
ON_BACKGROUND,
|
|
3253
|
+
"text",
|
|
3254
|
+
"neutral-950",
|
|
3255
|
+
"neutral-50"
|
|
3256
|
+
],
|
|
3257
|
+
linkCandidates: [
|
|
3258
|
+
"primary",
|
|
3259
|
+
ON_BACKGROUND,
|
|
3260
|
+
"text",
|
|
3261
|
+
"neutral-950",
|
|
3262
|
+
"neutral-50"
|
|
3263
|
+
],
|
|
3264
|
+
supportingCandidates: [
|
|
3265
|
+
"mutedText",
|
|
3266
|
+
"secondary",
|
|
3267
|
+
ON_BACKGROUND
|
|
3268
|
+
],
|
|
3269
|
+
inheritedBackground: false
|
|
3270
|
+
},
|
|
3271
|
+
"accent-band": {
|
|
3272
|
+
backgroundCandidates: [
|
|
3273
|
+
"accent",
|
|
3274
|
+
"primary",
|
|
3275
|
+
"secondary"
|
|
3276
|
+
],
|
|
3277
|
+
headingCandidates: [
|
|
3278
|
+
ON_BACKGROUND,
|
|
3279
|
+
"primaryForeground",
|
|
3280
|
+
"background",
|
|
3281
|
+
"surface",
|
|
3282
|
+
"neutral-50",
|
|
3283
|
+
"neutral-950"
|
|
3284
|
+
],
|
|
3285
|
+
textCandidates: [
|
|
3286
|
+
ON_BACKGROUND,
|
|
3287
|
+
"primaryForeground",
|
|
3288
|
+
"background",
|
|
3289
|
+
"surface",
|
|
3290
|
+
"neutral-50",
|
|
3291
|
+
"neutral-950"
|
|
3292
|
+
],
|
|
3293
|
+
linkCandidates: [
|
|
3294
|
+
ON_BACKGROUND,
|
|
3295
|
+
"primaryForeground",
|
|
3296
|
+
"background",
|
|
3297
|
+
"surface",
|
|
3298
|
+
"neutral-50",
|
|
3299
|
+
"neutral-950"
|
|
3300
|
+
],
|
|
3301
|
+
supportingCandidates: [
|
|
3302
|
+
ON_BACKGROUND,
|
|
3303
|
+
"primaryForeground",
|
|
3304
|
+
"background",
|
|
3305
|
+
"surface"
|
|
3306
|
+
],
|
|
3307
|
+
inheritedBackground: false
|
|
3308
|
+
},
|
|
3309
|
+
"brand-depth-band": {
|
|
3310
|
+
backgroundCandidates: [
|
|
3311
|
+
"primary-800",
|
|
3312
|
+
"primary-900",
|
|
3313
|
+
"primary-700",
|
|
3314
|
+
"primary"
|
|
3315
|
+
],
|
|
3316
|
+
headingCandidates: [
|
|
3317
|
+
ON_BACKGROUND,
|
|
3318
|
+
"primaryForeground",
|
|
3319
|
+
"background",
|
|
3320
|
+
"surface",
|
|
3321
|
+
"neutral-50",
|
|
3322
|
+
"neutral-950"
|
|
3323
|
+
],
|
|
3324
|
+
textCandidates: [
|
|
3325
|
+
ON_BACKGROUND,
|
|
3326
|
+
"primaryForeground",
|
|
3327
|
+
"background",
|
|
3328
|
+
"surface",
|
|
3329
|
+
"neutral-50",
|
|
3330
|
+
"neutral-950"
|
|
3331
|
+
],
|
|
3332
|
+
linkCandidates: [
|
|
3333
|
+
ON_BACKGROUND,
|
|
3334
|
+
"primaryForeground",
|
|
3335
|
+
"background",
|
|
3336
|
+
"surface",
|
|
3337
|
+
"neutral-50",
|
|
3338
|
+
"neutral-950"
|
|
3339
|
+
],
|
|
3340
|
+
supportingCandidates: [
|
|
3341
|
+
ON_BACKGROUND,
|
|
3342
|
+
"primaryForeground",
|
|
3343
|
+
"background",
|
|
3344
|
+
"surface"
|
|
3345
|
+
],
|
|
3346
|
+
inheritedBackground: false
|
|
3347
|
+
}
|
|
3348
|
+
};
|
|
3349
|
+
const missingBackgroundTokens = {
|
|
3350
|
+
background: "#ffffff",
|
|
3351
|
+
foreground: "#000000"
|
|
3352
|
+
};
|
|
3353
|
+
/** Keep every successful legacy recipe; only exhausted candidates need neutral ink. */
|
|
3354
|
+
function resolveAccessibleSurfaceRecipe(input) {
|
|
3355
|
+
const result = tryAccessibleSurfaceRecipe(input);
|
|
3356
|
+
if (result.kind === "resolved-accessible-surface") return result;
|
|
3357
|
+
const recipe = surfaceRecipes[input.surface];
|
|
3358
|
+
const token = recipe.backgroundCandidates.find((candidate) => resolveConcreteColorHex(candidate, input.palette) !== null);
|
|
3359
|
+
const hex = token ? resolveConcreteColorHex(token, input.palette) : null;
|
|
3360
|
+
if (!token || !hex) return result;
|
|
3361
|
+
const ink = pickBlackOrWhiteTextColor(hex);
|
|
3362
|
+
const foreground = (role) => ({
|
|
3363
|
+
kind: "safe-token",
|
|
3364
|
+
role,
|
|
3365
|
+
token: asAccessibleSurfaceToken(ink),
|
|
3366
|
+
hex: ink,
|
|
3367
|
+
contrastRatio: contrastRatio(ink, hex)
|
|
3368
|
+
});
|
|
3369
|
+
return {
|
|
3370
|
+
kind: "resolved-accessible-surface",
|
|
3371
|
+
surface: input.surface,
|
|
3372
|
+
background: {
|
|
3373
|
+
token: asAccessibleSurfaceToken(token),
|
|
3374
|
+
hex,
|
|
3375
|
+
inherited: recipe.inheritedBackground
|
|
3376
|
+
},
|
|
3377
|
+
heading: {
|
|
3378
|
+
...foreground("heading"),
|
|
3379
|
+
role: "heading"
|
|
3380
|
+
},
|
|
3381
|
+
text: {
|
|
3382
|
+
...foreground("text"),
|
|
3383
|
+
role: "text"
|
|
3384
|
+
},
|
|
3385
|
+
link: {
|
|
3386
|
+
...foreground("link"),
|
|
3387
|
+
role: "link"
|
|
3388
|
+
},
|
|
3389
|
+
supporting: foreground("supporting"),
|
|
3390
|
+
rejectedCandidates: result.rejectedCandidates
|
|
3391
|
+
};
|
|
3392
|
+
}
|
|
3393
|
+
function tryAccessibleSurfaceRecipe(input) {
|
|
3394
|
+
const rejectedCandidates = [];
|
|
3395
|
+
const recipe = surfaceRecipes[input.surface];
|
|
3396
|
+
const threshold = contrastThresholdByPolicy[input.policy ?? "body-aa"];
|
|
3397
|
+
for (const backgroundToken of recipe.backgroundCandidates) {
|
|
3398
|
+
const backgroundHex = readPaletteHex(input.palette, backgroundToken);
|
|
3399
|
+
if (!backgroundHex) {
|
|
3400
|
+
rejectedCandidates.push({
|
|
3401
|
+
kind: "background-candidate",
|
|
3402
|
+
token: backgroundToken,
|
|
3403
|
+
reason: "missing-token"
|
|
3404
|
+
});
|
|
3405
|
+
continue;
|
|
3406
|
+
}
|
|
3407
|
+
const heading = resolveRequiredForeground({
|
|
3408
|
+
role: "heading",
|
|
3409
|
+
candidates: recipe.headingCandidates,
|
|
3410
|
+
backgroundToken,
|
|
3411
|
+
backgroundHex,
|
|
3412
|
+
palette: input.palette,
|
|
3413
|
+
threshold,
|
|
3414
|
+
rejectedCandidates
|
|
3415
|
+
});
|
|
3416
|
+
const text = resolveRequiredForeground({
|
|
3417
|
+
role: "text",
|
|
3418
|
+
candidates: recipe.textCandidates,
|
|
3419
|
+
backgroundToken,
|
|
3420
|
+
backgroundHex,
|
|
3421
|
+
palette: input.palette,
|
|
3422
|
+
threshold,
|
|
3423
|
+
rejectedCandidates
|
|
3424
|
+
});
|
|
3425
|
+
const link = resolveRequiredForeground({
|
|
3426
|
+
role: "link",
|
|
3427
|
+
candidates: recipe.linkCandidates,
|
|
3428
|
+
backgroundToken,
|
|
3429
|
+
backgroundHex,
|
|
3430
|
+
palette: input.palette,
|
|
3431
|
+
threshold,
|
|
3432
|
+
rejectedCandidates
|
|
3433
|
+
});
|
|
3434
|
+
if (!heading || !text || !link) continue;
|
|
3435
|
+
const supporting = resolveSupportingForeground({
|
|
3436
|
+
candidates: recipe.supportingCandidates,
|
|
3437
|
+
backgroundToken,
|
|
3438
|
+
backgroundHex,
|
|
3439
|
+
text,
|
|
3440
|
+
palette: input.palette,
|
|
3441
|
+
threshold,
|
|
3442
|
+
rejectedCandidates
|
|
3443
|
+
});
|
|
3444
|
+
return {
|
|
3445
|
+
kind: "resolved-accessible-surface",
|
|
3446
|
+
surface: input.surface,
|
|
3447
|
+
background: {
|
|
3448
|
+
token: asAccessibleSurfaceToken(backgroundToken),
|
|
3449
|
+
hex: backgroundHex,
|
|
3450
|
+
inherited: recipe.inheritedBackground
|
|
3451
|
+
},
|
|
3452
|
+
heading,
|
|
3453
|
+
text,
|
|
3454
|
+
link,
|
|
3455
|
+
supporting,
|
|
3456
|
+
rejectedCandidates
|
|
3457
|
+
};
|
|
3458
|
+
}
|
|
3459
|
+
return {
|
|
3460
|
+
kind: "accessible-surface-resolution-failure",
|
|
3461
|
+
surface: input.surface,
|
|
3462
|
+
reason: surfaceResolutionFailureReason(rejectedCandidates),
|
|
3463
|
+
rejectedCandidates
|
|
3464
|
+
};
|
|
3465
|
+
}
|
|
3466
|
+
function resolveRequiredForeground(input) {
|
|
3467
|
+
return resolveSafeToken({
|
|
3468
|
+
role: input.role,
|
|
3469
|
+
candidates: input.candidates,
|
|
3470
|
+
backgroundToken: input.backgroundToken,
|
|
3471
|
+
backgroundHex: input.backgroundHex,
|
|
3472
|
+
palette: input.palette,
|
|
3473
|
+
threshold: input.threshold,
|
|
3474
|
+
rejectedCandidates: input.rejectedCandidates
|
|
3475
|
+
});
|
|
3476
|
+
}
|
|
3477
|
+
function resolveSupportingForeground(input) {
|
|
3478
|
+
const resolved = resolveSafeToken({
|
|
3479
|
+
role: "supporting",
|
|
3480
|
+
candidates: input.candidates,
|
|
3481
|
+
backgroundToken: input.backgroundToken,
|
|
3482
|
+
backgroundHex: input.backgroundHex,
|
|
3483
|
+
palette: input.palette,
|
|
3484
|
+
threshold: input.threshold,
|
|
3485
|
+
rejectedCandidates: input.rejectedCandidates
|
|
3486
|
+
});
|
|
3487
|
+
if (resolved) return resolved;
|
|
3488
|
+
return {
|
|
3489
|
+
kind: "fallback-to-text",
|
|
3490
|
+
role: "supporting",
|
|
3491
|
+
token: input.text.token,
|
|
3492
|
+
hex: input.text.hex,
|
|
3493
|
+
contrastRatio: input.text.contrastRatio,
|
|
3494
|
+
reason: "supporting-token-unsafe"
|
|
3495
|
+
};
|
|
3496
|
+
}
|
|
3497
|
+
function resolveSafeToken(input) {
|
|
3498
|
+
for (const candidate of expandForegroundCandidates(input.candidates, input.backgroundToken)) {
|
|
3499
|
+
const foregroundHex = readPaletteHex(input.palette, candidate);
|
|
3500
|
+
if (!foregroundHex) {
|
|
3501
|
+
input.rejectedCandidates.push({
|
|
3502
|
+
kind: "foreground-candidate",
|
|
3503
|
+
role: input.role,
|
|
3504
|
+
token: candidate,
|
|
3505
|
+
reason: "missing-token"
|
|
3506
|
+
});
|
|
3507
|
+
continue;
|
|
3508
|
+
}
|
|
3509
|
+
const ratio = contrastRatio(foregroundHex, input.backgroundHex);
|
|
3510
|
+
if (ratio < input.threshold) {
|
|
3511
|
+
input.rejectedCandidates.push({
|
|
3512
|
+
kind: "foreground-candidate",
|
|
3513
|
+
role: input.role,
|
|
3514
|
+
token: candidate,
|
|
3515
|
+
reason: "contrast-too-low",
|
|
3516
|
+
contrastRatio: ratio
|
|
3517
|
+
});
|
|
3518
|
+
continue;
|
|
3519
|
+
}
|
|
3520
|
+
return {
|
|
3521
|
+
kind: "safe-token",
|
|
3522
|
+
role: input.role,
|
|
3523
|
+
token: asAccessibleSurfaceToken(candidate),
|
|
3524
|
+
hex: foregroundHex,
|
|
3525
|
+
contrastRatio: ratio
|
|
3526
|
+
};
|
|
3527
|
+
}
|
|
3528
|
+
return null;
|
|
3529
|
+
}
|
|
3530
|
+
function expandForegroundCandidates(candidates, backgroundToken) {
|
|
3531
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3532
|
+
const expanded = [];
|
|
3533
|
+
for (const candidate of candidates) {
|
|
3534
|
+
const token = expandForegroundCandidate(candidate, backgroundToken);
|
|
3535
|
+
if (seen.has(token)) continue;
|
|
3536
|
+
seen.add(token);
|
|
3537
|
+
expanded.push(token);
|
|
3538
|
+
}
|
|
3539
|
+
return expanded;
|
|
3540
|
+
}
|
|
3541
|
+
function expandForegroundCandidate(candidate, backgroundToken) {
|
|
3542
|
+
if (typeof candidate === "string") return candidate;
|
|
3543
|
+
switch (candidate.kind) {
|
|
3544
|
+
case "on-background": return onColorTokenName(backgroundToken);
|
|
3545
|
+
}
|
|
3546
|
+
}
|
|
3547
|
+
function readPaletteHex(palette, token) {
|
|
3548
|
+
const value = palette[token];
|
|
3549
|
+
return typeof value === "string" && value.trim().length > 0 ? value : null;
|
|
3550
|
+
}
|
|
3551
|
+
function asAccessibleSurfaceToken(token) {
|
|
3552
|
+
if (token.length === 0) throw new Error("AccessibleSurfaceToken must be non-empty.");
|
|
3553
|
+
return token;
|
|
3554
|
+
}
|
|
3555
|
+
function surfaceResolutionFailureReason(rejectedCandidates) {
|
|
3556
|
+
return rejectedCandidates.some((candidate) => candidate.kind === "foreground-candidate") ? "no-safe-foreground-candidate" : "no-background-candidate";
|
|
3557
|
+
}
|
|
3558
|
+
function missingBackgroundSurface(input) {
|
|
3559
|
+
const contrast = contrastRatio(missingBackgroundTokens.foreground, missingBackgroundTokens.background);
|
|
3560
|
+
const foreground = {
|
|
3561
|
+
kind: "safe-token",
|
|
3562
|
+
token: asAccessibleSurfaceToken(missingBackgroundTokens.foreground),
|
|
3563
|
+
hex: missingBackgroundTokens.foreground,
|
|
3564
|
+
contrastRatio: contrast
|
|
3565
|
+
};
|
|
3566
|
+
return {
|
|
3567
|
+
kind: "resolved-accessible-surface",
|
|
3568
|
+
surface: input.surface,
|
|
3569
|
+
background: {
|
|
3570
|
+
token: asAccessibleSurfaceToken(missingBackgroundTokens.background),
|
|
3571
|
+
hex: missingBackgroundTokens.background,
|
|
3572
|
+
inherited: false
|
|
3573
|
+
},
|
|
3574
|
+
heading: {
|
|
3575
|
+
...foreground,
|
|
3576
|
+
role: "heading"
|
|
3577
|
+
},
|
|
3578
|
+
text: {
|
|
3579
|
+
...foreground,
|
|
3580
|
+
role: "text"
|
|
3581
|
+
},
|
|
3582
|
+
link: {
|
|
3583
|
+
...foreground,
|
|
3584
|
+
role: "link"
|
|
3585
|
+
},
|
|
3586
|
+
supporting: {
|
|
3587
|
+
...foreground,
|
|
3588
|
+
role: "supporting"
|
|
3589
|
+
},
|
|
3590
|
+
rejectedCandidates: input.rejectedCandidates
|
|
3591
|
+
};
|
|
3592
|
+
}
|
|
3593
|
+
const surfaceOwners = /* @__PURE__ */ new WeakSet();
|
|
3594
|
+
const preparedIndexOwners = /* @__PURE__ */ new WeakSet();
|
|
3595
|
+
const surfaceTransports = /* @__PURE__ */ new WeakMap();
|
|
3596
|
+
const revisionOwners = /* @__PURE__ */ new WeakMap();
|
|
3597
|
+
const surfaceRevisionOwners = /* @__PURE__ */ new WeakMap();
|
|
3598
|
+
function ownSurfaceRevision(context) {
|
|
3599
|
+
const palette = ownedThemeSnapshot(context.palette);
|
|
3600
|
+
const buttonSystem = context.buttonSystem === void 0 ? void 0 : ownedThemeSnapshot(context.buttonSystem);
|
|
3601
|
+
if (!isOwnedThemeValue(palette)) throw new TypeError("A surface context needs a palette object.");
|
|
3602
|
+
const revisions = revisionOwners.get(palette) ?? /* @__PURE__ */ new Map();
|
|
3603
|
+
const existing = revisions.get(buttonSystem);
|
|
3604
|
+
if (existing) return existing;
|
|
3605
|
+
const revision = Object.freeze({
|
|
3606
|
+
palette,
|
|
3607
|
+
buttonSystem
|
|
3608
|
+
});
|
|
3609
|
+
surfaceRevisionOwners.set(revision, { revision });
|
|
3610
|
+
revisions.set(buttonSystem, revision);
|
|
3611
|
+
revisionOwners.set(palette, revisions);
|
|
3612
|
+
return revision;
|
|
3613
|
+
}
|
|
3614
|
+
/** Local computation keeps its colour index; transport references only the owning revision inputs. */
|
|
3615
|
+
function surfaceTransportContext(context) {
|
|
3616
|
+
const revision = ownSurfaceRevision(context);
|
|
3617
|
+
const result = Object.freeze({
|
|
3618
|
+
...revision,
|
|
3619
|
+
colourIndex: context.colourIndex,
|
|
3620
|
+
solvedInks: context.solvedInks
|
|
3621
|
+
});
|
|
3622
|
+
const preparedSurfaces = matchingPreparedSurfaceIndex(preparedSurfaceIndexFor(context), result);
|
|
3623
|
+
surfaceRevisionOwners.set(result, {
|
|
3624
|
+
revision,
|
|
3625
|
+
preparedSurfaces
|
|
3626
|
+
});
|
|
3627
|
+
return result;
|
|
3628
|
+
}
|
|
3629
|
+
function isResolvedSurface(value) {
|
|
3630
|
+
return typeof value === "object" && value !== null && surfaceOwners.has(value) && "kind" in value && (value.kind === "owned" || value.kind === "inherit");
|
|
3631
|
+
}
|
|
3632
|
+
/** Runtime serializers reject copies and forged structural objects, too. */
|
|
3633
|
+
function requireResolvedSurface(value) {
|
|
3634
|
+
if (!isResolvedSurface(value)) throw new Error("Surface must be produced by resolveSurface");
|
|
3635
|
+
}
|
|
3636
|
+
function resolveSurface(spec, context) {
|
|
3637
|
+
return spec.kind === "section" ? resolveSectionSurface(spec.background, context) : preparedSurfaceValue(spec, context) ?? certifySurface(spec, context);
|
|
3638
|
+
}
|
|
3639
|
+
function prepareSurfaceIndex(specs, context) {
|
|
3640
|
+
const snapshot = ownedThemeSnapshot({
|
|
3641
|
+
palette: context.palette,
|
|
3642
|
+
buttonSystem: context.buttonSystem,
|
|
3643
|
+
colourIndex: context.colourIndex,
|
|
3644
|
+
linkHoverToken: context.linkHoverToken,
|
|
3645
|
+
foreground: context.foreground,
|
|
3646
|
+
compositeBase: context.compositeBase,
|
|
3647
|
+
buttonContext: context.buttonContext,
|
|
3648
|
+
solvedInks: context.solvedInks
|
|
3649
|
+
});
|
|
3650
|
+
return surfaceIndexFromOwnedInputs(ownedThemeSnapshot(specs), snapshot);
|
|
3651
|
+
}
|
|
3652
|
+
/** Private construction path: both entry points above own and freeze these inputs. */
|
|
3653
|
+
function surfaceIndexFromOwnedInputs(specs, context) {
|
|
3654
|
+
const entries = [...new Map(specs.map((spec) => [surfaceResolutionKey(spec, context), spec]))].flatMap(([key, spec]) => preparedSurfaceEntry(key, spec, context));
|
|
3655
|
+
const index = Object.freeze({
|
|
3656
|
+
palette: context.palette,
|
|
3657
|
+
buttonSystem: context.buttonSystem,
|
|
3658
|
+
colourIndex: context.colourIndex,
|
|
3659
|
+
values: freezeOwnedThemeValue(Object.fromEntries(entries))
|
|
3660
|
+
});
|
|
3661
|
+
preparedIndexOwners.add(index);
|
|
3662
|
+
return index;
|
|
3663
|
+
}
|
|
3664
|
+
function preparedSurfaceEntry(key, spec, context) {
|
|
3665
|
+
try {
|
|
3666
|
+
return [[key, certifySurface(spec, context)]];
|
|
3667
|
+
} catch {
|
|
3668
|
+
return [];
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
function matchingPreparedSurfaceIndex(index, context) {
|
|
3672
|
+
return index && preparedIndexOwners.has(index) && index.palette === context.palette && index.buttonSystem === context.buttonSystem && index.colourIndex === context.colourIndex ? index : void 0;
|
|
3673
|
+
}
|
|
3674
|
+
function preparedSurfaceIndexFor(context) {
|
|
3675
|
+
return matchingPreparedSurfaceIndex(context.preparedSurfaces ?? surfaceRevisionOwners.get(context)?.preparedSurfaces, context);
|
|
3676
|
+
}
|
|
3677
|
+
function preparedSurfaceValue(spec, context) {
|
|
3678
|
+
return preparedSurfaceIndexFor(context)?.values[surfaceResolutionKey(spec, context)];
|
|
3679
|
+
}
|
|
3680
|
+
function surfaceResolutionKey(spec, context) {
|
|
3681
|
+
const declaration = spec.kind === "tint" ? {
|
|
3682
|
+
...spec,
|
|
3683
|
+
opacity: String(spec.opacity)
|
|
3684
|
+
} : spec;
|
|
3685
|
+
return JSON.stringify([
|
|
3686
|
+
declaration,
|
|
3687
|
+
context.linkHoverToken,
|
|
3688
|
+
context.foreground,
|
|
3689
|
+
context.compositeBase,
|
|
3690
|
+
context.buttonContext,
|
|
3691
|
+
context.solvedInks
|
|
3692
|
+
]);
|
|
3693
|
+
}
|
|
3694
|
+
function resolveSurfaceSpec(spec, context) {
|
|
3695
|
+
switch (spec.kind) {
|
|
3696
|
+
case "recipe": return resolveRecipeSurface(spec.intent, context);
|
|
3697
|
+
case "paint": return spec.paint.kind === "transparent" ? { kind: "inherit" } : resolveOwnedSurface(spec.paint, context);
|
|
3698
|
+
case "token": return resolveDeclaredSolidSurface({
|
|
3699
|
+
kind: "solid",
|
|
3700
|
+
token: spec.token
|
|
3701
|
+
}, {
|
|
3702
|
+
...context,
|
|
3703
|
+
buttonContext: surfaceButtonRequest(spec, context),
|
|
3704
|
+
...spec.foreground ? { foreground: {
|
|
3705
|
+
...context.foreground,
|
|
3706
|
+
...spec.foreground
|
|
3707
|
+
} } : {}
|
|
3708
|
+
});
|
|
3709
|
+
case "tint": return resolveTintSurface(spec, context);
|
|
3710
|
+
}
|
|
3711
|
+
}
|
|
3712
|
+
function resolveRecipeSurface(intent, context) {
|
|
3713
|
+
const result = resolveAccessibleSurfaceRecipe({
|
|
3714
|
+
surface: intent,
|
|
3715
|
+
palette: context.palette
|
|
3716
|
+
});
|
|
3717
|
+
const recipe = result.kind === "resolved-accessible-surface" ? result : missingBackgroundSurface({
|
|
3718
|
+
surface: intent,
|
|
3719
|
+
rejectedCandidates: result.rejectedCandidates
|
|
3720
|
+
});
|
|
3721
|
+
if (recipe.background.inherited) return { kind: "inherit" };
|
|
3722
|
+
return resolveDeclaredSolidSurface({
|
|
3723
|
+
kind: "solid",
|
|
3724
|
+
token: recipe.background.token
|
|
3725
|
+
}, {
|
|
3726
|
+
...context,
|
|
3727
|
+
foreground: recipeForegroundCandidates(recipe, context)
|
|
3728
|
+
});
|
|
3729
|
+
}
|
|
3730
|
+
/** Style rules replace recipe candidates before the shared foreground check. */
|
|
3731
|
+
function recipeForegroundCandidates(recipe, context) {
|
|
3732
|
+
const candidates = context.foreground ?? {};
|
|
3733
|
+
return {
|
|
3734
|
+
text: candidates.text ?? recipe.text.token,
|
|
3735
|
+
heading: candidates.heading ?? recipe.heading.token,
|
|
3736
|
+
link: candidates.link ?? recipe.link.token,
|
|
3737
|
+
supporting: candidates.supporting ?? recipe.supporting.token,
|
|
3738
|
+
linkHover: candidates.linkHover ?? context.linkHoverToken
|
|
3739
|
+
};
|
|
3740
|
+
}
|
|
3741
|
+
/** Declared grounds are parsed once; legacy stored paints use the unmeasured value arm. */
|
|
3742
|
+
function resolveDeclaredSolidSurface(paint, context) {
|
|
3743
|
+
return resolveOwnedSurface(paint, context, hexColorSchema.parse(resolveOpaqueSurfaceHex(paint.token, context.palette, context.compositeBase)));
|
|
3744
|
+
}
|
|
3745
|
+
function resolveOwnedSurface(paint, context, measuredBackdrop) {
|
|
3746
|
+
const resolved = resolveOwnedForeground(paint, context, measuredBackdrop);
|
|
3747
|
+
const decision = {
|
|
3748
|
+
kind: "owned",
|
|
3749
|
+
foreground: ownedForegroundRoles(resolved, paint.foregroundToken ?? "text", context.foreground),
|
|
3750
|
+
inks: ownedInkPublication(resolved, context),
|
|
3751
|
+
decorations: surfaceDecorationColors(resolved, context.palette),
|
|
3752
|
+
hoverDecoration: resolved.kind === "known" ? resolved.hoverDecoration : "underline"
|
|
3753
|
+
};
|
|
3754
|
+
const primaryButton = surfaceButtonRequest({
|
|
3755
|
+
kind: "paint",
|
|
3756
|
+
paint
|
|
3757
|
+
}, context)?.primary;
|
|
3758
|
+
if (paint.kind === "solid" && resolved.kind === "known" && resolved.provenance.kind === "measured") return {
|
|
3759
|
+
...decision,
|
|
3760
|
+
paint,
|
|
3761
|
+
foreground: resolved.roles,
|
|
3762
|
+
...primaryButton ? { primaryButton } : {},
|
|
3763
|
+
contrast: surfaceContrast(resolved.roles, resolved.provenance.backdropHex, context.palette, context.colourIndex)
|
|
3764
|
+
};
|
|
3765
|
+
const buttonContext = surfaceButtons(paint, resolved.kind === "known" ? resolved.roles.link : void 0, primaryButton, context);
|
|
3766
|
+
return paint.kind === "gradient" ? {
|
|
3767
|
+
...decision,
|
|
3768
|
+
paint,
|
|
3769
|
+
contrast: { kind: "unmeasured" },
|
|
3770
|
+
buttonContext
|
|
3771
|
+
} : {
|
|
3772
|
+
...decision,
|
|
3773
|
+
paint,
|
|
3774
|
+
contrast: {
|
|
3775
|
+
kind: "unmeasured",
|
|
3776
|
+
reason: "legacy-unresolvable-solid",
|
|
3777
|
+
source: "paint"
|
|
3778
|
+
},
|
|
3779
|
+
buttonContext
|
|
3780
|
+
};
|
|
3781
|
+
}
|
|
3782
|
+
/** A solid paint is measured against its own backdrop when it's known, otherwise over the composite base. */
|
|
3783
|
+
function resolveOwnedForeground(paint, context, measuredBackdrop) {
|
|
3784
|
+
const textColor = paint.foregroundToken ?? "text";
|
|
3785
|
+
const candidates = {
|
|
3786
|
+
linkHover: context.linkHoverToken,
|
|
3787
|
+
...context.foreground
|
|
3788
|
+
};
|
|
3789
|
+
if (paint.kind === "gradient") return resolveSurfaceForeground({
|
|
3790
|
+
type: "gradient",
|
|
3791
|
+
textColor
|
|
3792
|
+
}, context.palette, candidates, { compositeBase: context.compositeBase });
|
|
3793
|
+
const background = {
|
|
3794
|
+
type: "color",
|
|
3795
|
+
color: paint.token,
|
|
3796
|
+
textColor
|
|
3797
|
+
};
|
|
3798
|
+
return measuredBackdrop ? resolveSurfaceForeground(background, context.palette, candidates, { measuredBackdrop }) : resolveSurfaceForeground(background, context.palette, candidates, { compositeBase: context.compositeBase });
|
|
3799
|
+
}
|
|
3800
|
+
/** A paint the element owns but that resolves as inherited (an empty token) still blocks outer inks. */
|
|
3801
|
+
function ownedInkPublication(resolved, context) {
|
|
3802
|
+
const publication = surfaceInkPublication(resolved, context.solvedInks ?? "withhold");
|
|
3803
|
+
return publication.kind === "none" ? { kind: "reset" } : publication;
|
|
3804
|
+
}
|
|
3805
|
+
/** Unprovable legacy paint retains its declared foreground instead of inventing one. */
|
|
3806
|
+
function ownedForegroundRoles(resolved, text, candidates) {
|
|
3807
|
+
if (resolved.kind === "known") return resolved.roles;
|
|
3808
|
+
const candidate = candidates ?? {};
|
|
3809
|
+
const fallback = candidate.text ?? text;
|
|
3810
|
+
return completeSurfaceForegrounds({
|
|
3811
|
+
text: fallback,
|
|
3812
|
+
heading: candidate.heading ?? void 0,
|
|
3813
|
+
link: candidate.link ?? void 0,
|
|
3814
|
+
supporting: candidate.supporting ?? void 0,
|
|
3815
|
+
muted: fallback
|
|
3816
|
+
});
|
|
3817
|
+
}
|
|
3818
|
+
function surfaceButtons(paint, link, primaryToken, context, backgroundSamples) {
|
|
3819
|
+
return resolveSurfaceButtonContext({
|
|
3820
|
+
surface: paint.kind === "solid" ? {
|
|
3821
|
+
kind: "solid",
|
|
3822
|
+
color: paint.token,
|
|
3823
|
+
composited: false,
|
|
3824
|
+
foreground: link,
|
|
3825
|
+
...backgroundSamples ? { backgroundSamples } : {}
|
|
3826
|
+
} : { kind: "gradient" },
|
|
3827
|
+
palette: context.palette,
|
|
3828
|
+
colourIndex: context.colourIndex,
|
|
3829
|
+
buttonSystem: context.buttonSystem,
|
|
3830
|
+
fallbackToken: context.compositeBase,
|
|
3831
|
+
primaryToken,
|
|
3832
|
+
withoutButtonSystem: "reset"
|
|
3833
|
+
});
|
|
3834
|
+
}
|
|
3835
|
+
/** Buttons on a certified paint use the link ink the certificate kept, which may be the black/white fallback. */
|
|
3836
|
+
function withCertifiedButtons(decision, context) {
|
|
3837
|
+
const { primaryButton, ...certified } = decision;
|
|
3838
|
+
return {
|
|
3839
|
+
...certified,
|
|
3840
|
+
buttonContext: surfaceButtons(decision.paint, decision.foreground.link, primaryButton, context, tintGroundSamples(decision, context))
|
|
3841
|
+
};
|
|
3842
|
+
}
|
|
3843
|
+
/** A radial tint's grounds besides its painted end, so its buttons are judged on every sample. */
|
|
3844
|
+
function tintGroundSamples(decision, context) {
|
|
3845
|
+
if (decision.tintBase === void 0) return void 0;
|
|
3846
|
+
const [first, ...rest] = surfaceBackdrops(decision, context).slice(0, -1);
|
|
3847
|
+
return first === void 0 ? void 0 : [first, ...rest];
|
|
3848
|
+
}
|
|
3849
|
+
function surfaceContrast(roles, backdrop, palette, colourIndex) {
|
|
3850
|
+
const ratio = (token) => contrastRatio(resolveOpaqueSurfaceHex(token, palette, backdrop) ?? backdrop, backdrop, colourIndex);
|
|
3851
|
+
return {
|
|
3852
|
+
kind: "measured",
|
|
3853
|
+
ratios: {
|
|
3854
|
+
text: ratio(roles.text),
|
|
3855
|
+
heading: ratio(roles.heading),
|
|
3856
|
+
link: ratio(roles.link),
|
|
3857
|
+
linkHover: ratio(roles.linkHover),
|
|
3858
|
+
supporting: ratio(roles.supporting),
|
|
3859
|
+
muted: ratio(roles.muted)
|
|
3860
|
+
}
|
|
3861
|
+
};
|
|
3862
|
+
}
|
|
3863
|
+
/** Runtime backgrounds retain authored media, compositing and unknown foregrounds. */
|
|
3864
|
+
function resolveSectionSurface(background, context) {
|
|
3865
|
+
const foreground = background === null ? { kind: "inherits" } : resolveSurfaceForeground(background, context.palette, {
|
|
3866
|
+
linkHover: context.linkHoverToken,
|
|
3867
|
+
...context.foreground
|
|
3868
|
+
}, { compositeBase: context.compositeBase });
|
|
3869
|
+
const surface = background === null ? { kind: "inherit" } : background.type === "color" ? {
|
|
3870
|
+
kind: "solid",
|
|
3871
|
+
color: background.color,
|
|
3872
|
+
composited: false,
|
|
3873
|
+
foreground: foreground.kind === "known" ? foreground.roles.link : void 0
|
|
3874
|
+
} : background.type === "gradient" ? { kind: "gradient" } : { kind: "image" };
|
|
3875
|
+
const revision = ownSurfaceRevision(context);
|
|
3876
|
+
const buttonContext = resolveSurfaceButtonContext({
|
|
3877
|
+
surface,
|
|
3878
|
+
palette: revision.palette,
|
|
3879
|
+
buttonSystem: revision.buttonSystem,
|
|
3880
|
+
primaryToken: sectionPrimaryButtonToken(background, context),
|
|
3881
|
+
fallbackToken: context.compositeBase,
|
|
3882
|
+
withoutButtonSystem: "inherit"
|
|
3883
|
+
});
|
|
3884
|
+
const result = {
|
|
3885
|
+
kind: "section",
|
|
3886
|
+
foreground,
|
|
3887
|
+
inks: surfaceInkPublication(foreground, context.solvedInks ?? "withhold"),
|
|
3888
|
+
buttonStyles: buttonContext.styles,
|
|
3889
|
+
buttonContext,
|
|
3890
|
+
proof: sectionProof(background, foreground),
|
|
3891
|
+
revision,
|
|
3892
|
+
textPolicy: surfaceTextPolicy
|
|
3893
|
+
};
|
|
3894
|
+
Object.defineProperties(result, {
|
|
3895
|
+
buttonContext: { enumerable: false },
|
|
3896
|
+
proof: { enumerable: false },
|
|
3897
|
+
revision: { enumerable: false },
|
|
3898
|
+
textPolicy: { enumerable: false }
|
|
3899
|
+
});
|
|
3900
|
+
return freezeOwnedThemeValue(result);
|
|
3901
|
+
}
|
|
3902
|
+
function sectionPrimaryButtonToken(background, context) {
|
|
3903
|
+
if (background?.type !== "color" || typeof background.color !== "string") return void 0;
|
|
3904
|
+
return context.buttonSystem?.surfaceContexts?.[background.color]?.primary;
|
|
3905
|
+
}
|
|
3906
|
+
function surfaceDecorationColors(foreground, palette) {
|
|
3907
|
+
if (foreground.kind !== "known" || foreground.provenance.kind !== "measured") return void 0;
|
|
3908
|
+
const text = resolveConcreteColorHex(foreground.roles.text, palette);
|
|
3909
|
+
if (text === null) return void 0;
|
|
3910
|
+
return deriveSurfaceDecorationColors(foreground.provenance.backdropHex, text, palette.markSource ?? palette.accent ?? text);
|
|
3911
|
+
}
|
|
3912
|
+
/** Composite the declared palette tint before checking every foreground role. */
|
|
3913
|
+
function resolveTintSurface(spec, context) {
|
|
3914
|
+
const base = resolveSurface({
|
|
3915
|
+
kind: "token",
|
|
3916
|
+
token: spec.base
|
|
3917
|
+
}, context);
|
|
3918
|
+
const source = tintSource(spec.source, base, context.palette);
|
|
3919
|
+
const token = source ? resolveOpaqueSurfaceHex(`${source}/${spec.opacity}`, context.palette, spec.base) : null;
|
|
3920
|
+
const hex = source ? resolveConcreteColorHex(source, context.palette) : null;
|
|
3921
|
+
const tinted = token ?? (hex ? resolveOpaqueSurfaceHex(hexToRgba(hex, spec.opacity / 100), context.palette, spec.base) : null);
|
|
3922
|
+
if (!tinted) throw new Error(`Cannot derive tint on ${spec.base}`);
|
|
3923
|
+
const solid = resolveDeclaredSolidSurface({
|
|
3924
|
+
kind: "solid",
|
|
3925
|
+
token: tinted
|
|
3926
|
+
}, {
|
|
3927
|
+
...context,
|
|
3928
|
+
buttonContext: surfaceButtonRequest(spec, context),
|
|
3929
|
+
foreground: base.foreground
|
|
3930
|
+
});
|
|
3931
|
+
return spec.gradient === "radial" ? {
|
|
3932
|
+
...solid,
|
|
3933
|
+
inks: { kind: "reset" },
|
|
3934
|
+
tintBase: spec.base
|
|
3935
|
+
} : solid;
|
|
3936
|
+
}
|
|
3937
|
+
/**
|
|
3938
|
+
* The button colour a surface asks for, which it also hands to what is painted on it. An explicit request
|
|
3939
|
+
* wins; otherwise a paint asks for its own button context, and a shade for the context of the paint it shades.
|
|
3940
|
+
* The request is checked anew on every surface that receives it.
|
|
3941
|
+
*/
|
|
3942
|
+
function surfaceButtonRequest(spec, context) {
|
|
3943
|
+
const forToken = (token) => context.buttonContext ?? context.buttonSystem?.surfaceContexts?.[token];
|
|
3944
|
+
switch (spec.kind) {
|
|
3945
|
+
case "token": return spec.buttonContext ?? forToken(spec.token);
|
|
3946
|
+
case "tint": return spec.source === "shade" ? forToken(spec.base) : context.buttonContext;
|
|
3947
|
+
case "paint": return spec.paint.kind === "solid" ? forToken(spec.paint.token) : context.buttonContext;
|
|
3948
|
+
case "recipe": return context.buttonContext;
|
|
3949
|
+
}
|
|
3950
|
+
}
|
|
3951
|
+
/** Shade direction belongs to the palette, while the tint's base is the actual paint. */
|
|
3952
|
+
function tintSource(source, base, palette) {
|
|
3953
|
+
switch (source) {
|
|
3954
|
+
case "text": return base.foreground.text;
|
|
3955
|
+
case "mark": return base.decorations?.mark;
|
|
3956
|
+
case "shade": {
|
|
3957
|
+
const background = resolveOpaqueSurfaceHex("background", palette, "background");
|
|
3958
|
+
return background && featuresFromHex(background).Y < .5 ? "#ffffff" : "#000000";
|
|
3959
|
+
}
|
|
3960
|
+
}
|
|
3961
|
+
}
|
|
3962
|
+
function hexToRgba(hex, alpha) {
|
|
3963
|
+
const { r, g, b } = hexToRgb(hex);
|
|
3964
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
3965
|
+
}
|
|
3966
|
+
const foregroundInputSchema = z.object({
|
|
3967
|
+
text: z.string().nullable().optional(),
|
|
3968
|
+
heading: z.string().nullable().optional(),
|
|
3969
|
+
link: z.string().nullable().optional(),
|
|
3970
|
+
linkHover: z.string().nullable().optional(),
|
|
3971
|
+
supporting: z.string().nullable().optional()
|
|
3972
|
+
});
|
|
3973
|
+
const paintInputSchema = z.discriminatedUnion("kind", [
|
|
3974
|
+
z.object({
|
|
3975
|
+
kind: z.literal("solid"),
|
|
3976
|
+
token: z.string(),
|
|
3977
|
+
foregroundToken: z.string().optional()
|
|
3978
|
+
}),
|
|
3979
|
+
z.object({
|
|
3980
|
+
kind: z.literal("gradient"),
|
|
3981
|
+
foregroundToken: z.string().optional()
|
|
3982
|
+
}),
|
|
3983
|
+
z.object({ kind: z.literal("transparent") })
|
|
3984
|
+
]);
|
|
3985
|
+
const buttonInputSchema = z.object({ primary: opaqueButtonColourTokenSchema });
|
|
3986
|
+
const solvedInksSchema = z.enum(["publish", "withhold"]);
|
|
3987
|
+
const surfaceSpecSchema = z.discriminatedUnion("kind", [
|
|
3988
|
+
z.object({
|
|
3989
|
+
kind: z.literal("recipe"),
|
|
3990
|
+
intent: z.enum([
|
|
3991
|
+
"base",
|
|
3992
|
+
"muted-band",
|
|
3993
|
+
"accent-band",
|
|
3994
|
+
"brand-depth-band"
|
|
3995
|
+
])
|
|
3996
|
+
}),
|
|
3997
|
+
z.object({
|
|
3998
|
+
kind: z.literal("paint"),
|
|
3999
|
+
paint: paintInputSchema
|
|
4000
|
+
}),
|
|
4001
|
+
z.object({
|
|
4002
|
+
kind: z.literal("token"),
|
|
4003
|
+
token: z.string(),
|
|
4004
|
+
foreground: foregroundInputSchema.optional(),
|
|
4005
|
+
buttonContext: buttonInputSchema.optional()
|
|
4006
|
+
}),
|
|
4007
|
+
z.object({
|
|
4008
|
+
kind: z.literal("tint"),
|
|
4009
|
+
base: z.string(),
|
|
4010
|
+
source: z.enum([
|
|
4011
|
+
"text",
|
|
4012
|
+
"mark",
|
|
4013
|
+
"shade"
|
|
4014
|
+
]),
|
|
4015
|
+
opacity: z.number().finite(),
|
|
4016
|
+
gradient: z.literal("radial").optional()
|
|
4017
|
+
})
|
|
4018
|
+
]);
|
|
4019
|
+
const surfaceTransportSchema = z.object({ $surface: z.object({
|
|
4020
|
+
spec: surfaceSpecSchema,
|
|
4021
|
+
context: z.object({
|
|
4022
|
+
palette: z.record(z.string(), z.string()),
|
|
4023
|
+
buttonSystem: buttonSystemSchema.optional(),
|
|
4024
|
+
foreground: foregroundInputSchema.optional(),
|
|
4025
|
+
linkHoverToken: z.string().optional(),
|
|
4026
|
+
compositeBase: z.string().optional(),
|
|
4027
|
+
buttonContext: buttonInputSchema.optional(),
|
|
4028
|
+
solvedInks: solvedInksSchema.optional()
|
|
4029
|
+
})
|
|
4030
|
+
}) });
|
|
4031
|
+
/** Deserialised output is never evidence: parse the inputs and rerun their owner. */
|
|
4032
|
+
function parseResolvedSurface(value) {
|
|
4033
|
+
return resolveTransportedSurface(value);
|
|
4034
|
+
}
|
|
4035
|
+
function resolveTransportedSurface(value, solvedInks) {
|
|
4036
|
+
if (isResolvedSurface(value) && solvedInks === void 0) return value;
|
|
4037
|
+
const { spec, context } = isResolvedSurface(value) ? serializeResolvedSurface(value).$surface : surfaceTransportSchema.parse(value).$surface;
|
|
4038
|
+
return resolveSurface(spec, {
|
|
4039
|
+
...context,
|
|
4040
|
+
buttonSystem: context.buttonSystem,
|
|
4041
|
+
solvedInks: solvedInks ?? context.solvedInks
|
|
4042
|
+
});
|
|
4043
|
+
}
|
|
4044
|
+
/** Wire only the owner inputs; parsed CSS/results are recomputed, never trusted. */
|
|
4045
|
+
function serializeResolvedSurface(surface) {
|
|
4046
|
+
requireResolvedSurface(surface);
|
|
4047
|
+
const inputs = surfaceTransports.get(surface);
|
|
4048
|
+
if (!inputs) throw new Error("Missing surface inputs");
|
|
4049
|
+
return { $surface: inputs };
|
|
4050
|
+
}
|
|
4051
|
+
function certifySurface(spec, context) {
|
|
4052
|
+
const revision = ownSurfaceRevision(context);
|
|
4053
|
+
const inputs = {
|
|
4054
|
+
spec: ownedThemeSnapshot(spec),
|
|
4055
|
+
context: Object.freeze({
|
|
4056
|
+
...revision,
|
|
4057
|
+
...ownedThemeSnapshot({
|
|
4058
|
+
foreground: context.foreground,
|
|
4059
|
+
linkHoverToken: context.linkHoverToken,
|
|
4060
|
+
compositeBase: context.compositeBase,
|
|
4061
|
+
buttonContext: context.buttonContext,
|
|
4062
|
+
solvedInks: context.solvedInks
|
|
4063
|
+
})
|
|
4064
|
+
})
|
|
4065
|
+
};
|
|
4066
|
+
const decision = certifyThresholds(resolveSurfaceSpec(inputs.spec, inputs.context), inputs.context);
|
|
4067
|
+
const result = Object.assign(surfaceProof(decision, spec), {
|
|
4068
|
+
revision,
|
|
4069
|
+
textPolicy: surfaceTextPolicy,
|
|
4070
|
+
$surface: inputs
|
|
4071
|
+
});
|
|
4072
|
+
Object.defineProperties(result, {
|
|
4073
|
+
proof: { enumerable: false },
|
|
4074
|
+
revision: { enumerable: false },
|
|
4075
|
+
textPolicy: { enumerable: false }
|
|
4076
|
+
});
|
|
4077
|
+
surfaceOwners.add(result);
|
|
4078
|
+
surfaceTransports.set(result, inputs);
|
|
4079
|
+
return freezeOwnedThemeValue(result);
|
|
4080
|
+
}
|
|
4081
|
+
function isSolidSurfaceDecision(decision) {
|
|
4082
|
+
return decision.kind === "owned" && decision.contrast.kind === "measured";
|
|
4083
|
+
}
|
|
4084
|
+
function isSolidInkDecision(decision) {
|
|
4085
|
+
return decision.kind === "owned" && decision.contrast.kind === "measured";
|
|
4086
|
+
}
|
|
4087
|
+
const TINT_SAMPLE_ALPHAS = [
|
|
4088
|
+
0,
|
|
4089
|
+
.25,
|
|
4090
|
+
.5,
|
|
4091
|
+
.75,
|
|
4092
|
+
1
|
|
4093
|
+
];
|
|
4094
|
+
/**
|
|
4095
|
+
* The certificate asserts every threshold it measures, on every backdrop the
|
|
4096
|
+
* paint shows (each sample of a radial tint). It never throws, because owner
|
|
4097
|
+
* palettes are arbitrary: an ink that misses takes the black/white ink, and a
|
|
4098
|
+
* radial tint that no ink can clear paints flat. Buttons are derived from the
|
|
4099
|
+
* certified inks, so they never keep a link ink the certificate replaced, and
|
|
4100
|
+
* the button resolver judges them on every sample of a radial tint.
|
|
4101
|
+
*/
|
|
4102
|
+
function certifyThresholds(decision, context) {
|
|
4103
|
+
if (!isSolidInkDecision(decision)) return decision;
|
|
4104
|
+
const inks = withFallbackInks(decision, context);
|
|
4105
|
+
if (inks) return withCertifiedButtons(inks, context);
|
|
4106
|
+
const { tintBase: _flattened, ...flatTint } = decision;
|
|
4107
|
+
const flat = withFallbackInks(flatTint, context) ?? flatTint;
|
|
4108
|
+
return withCertifiedButtons({
|
|
4109
|
+
...flat,
|
|
4110
|
+
contrast: {
|
|
4111
|
+
...flat.contrast,
|
|
4112
|
+
fallback: ["radial-tint", ...flat.contrast.fallback ?? []]
|
|
4113
|
+
}
|
|
4114
|
+
}, context);
|
|
4115
|
+
}
|
|
4116
|
+
/** Every backdrop a solid paint shows: its colour, or each sample from a radial tint's base to its paint. */
|
|
4117
|
+
function surfaceBackdrops(decision, context) {
|
|
4118
|
+
const paint = resolveOpaqueSurfaceHex(decision.paint.token, context.palette, decision.tintBase ?? context.compositeBase);
|
|
4119
|
+
if (!paint) return [];
|
|
4120
|
+
const underlay = decision.tintBase ? resolveOpaqueSurfaceHex(decision.tintBase, context.palette, "background") : null;
|
|
4121
|
+
return underlay ? TINT_SAMPLE_ALPHAS.map((alpha) => compositeHex(paint, alpha, underlay)) : [paint];
|
|
4122
|
+
}
|
|
4123
|
+
/** Null only when no black/white ink clears every backdrop of a radial tint. */
|
|
4124
|
+
function withFallbackInks(decision, context) {
|
|
4125
|
+
const backdrops = surfaceBackdrops(decision, context);
|
|
4126
|
+
const [endpoint] = backdrops.slice(-1);
|
|
4127
|
+
if (!endpoint) return decision;
|
|
4128
|
+
const certified = certifySurfaceInks({
|
|
4129
|
+
foreground: decision.foreground,
|
|
4130
|
+
mark: decision.decorations?.mark
|
|
4131
|
+
}, backdrops, context);
|
|
4132
|
+
if (!certified) return null;
|
|
4133
|
+
if (certified.fallback.length === 0) return decision;
|
|
4134
|
+
const decorations = decision.decorations && certified.mark !== void 0 ? {
|
|
4135
|
+
...decision.decorations,
|
|
4136
|
+
mark: certified.mark
|
|
4137
|
+
} : decision.decorations;
|
|
4138
|
+
const contrast = surfaceContrast(certified.foreground, endpoint, context.palette, context.colourIndex);
|
|
4139
|
+
return {
|
|
4140
|
+
...decision,
|
|
4141
|
+
foreground: certified.foreground,
|
|
4142
|
+
decorations,
|
|
4143
|
+
contrast: {
|
|
4144
|
+
...contrast,
|
|
4145
|
+
fallback: certified.fallback
|
|
4146
|
+
}
|
|
4147
|
+
};
|
|
4148
|
+
}
|
|
4149
|
+
function surfaceProof(decision, spec) {
|
|
4150
|
+
if (decision.kind === "inherit") return {
|
|
4151
|
+
...decision,
|
|
4152
|
+
proof: "inherit"
|
|
4153
|
+
};
|
|
4154
|
+
if (!isSolidSurfaceDecision(decision)) return {
|
|
4155
|
+
...decision,
|
|
4156
|
+
proof: "unproven-media"
|
|
4157
|
+
};
|
|
4158
|
+
const proof = decision.tintBase !== void 0 ? "checked-gradient-or-scrim" : spec.kind === "tint" || /\/|rgba\(/.test(decision.paint.token) ? "checked-composited" : "checked-solid";
|
|
4159
|
+
return {
|
|
4160
|
+
...decision,
|
|
4161
|
+
proof
|
|
4162
|
+
};
|
|
4163
|
+
}
|
|
4164
|
+
function sectionProof(background, foreground) {
|
|
4165
|
+
if (background === null) return "inherit";
|
|
4166
|
+
if (foreground.kind !== "known" || foreground.provenance.kind !== "measured") return "unproven-media";
|
|
4167
|
+
return /\/|rgba\(/.test(background.color ?? "") ? "checked-composited" : "checked-solid";
|
|
4168
|
+
}
|
|
4169
|
+
/** One theme revision per JSON envelope, shared by all nested Look slots. */
|
|
4170
|
+
function serializeSurfaceTree(value) {
|
|
4171
|
+
const revisions = [];
|
|
4172
|
+
const indices = /* @__PURE__ */ new Map();
|
|
4173
|
+
const revisionIndex = (revision) => {
|
|
4174
|
+
const index = indices.get(revision) ?? revisions.length;
|
|
4175
|
+
if (!indices.has(revision)) {
|
|
4176
|
+
indices.set(revision, index);
|
|
4177
|
+
revisions.push(revision);
|
|
4178
|
+
}
|
|
4179
|
+
return index;
|
|
4180
|
+
};
|
|
4181
|
+
const encode = (item) => {
|
|
4182
|
+
const revision = isSurfaceTreeRecord(item) ? surfaceRevisionOwners.get(item)?.revision : void 0;
|
|
4183
|
+
if (revision) return {
|
|
4184
|
+
$surfaceRevision: revisionIndex(revision),
|
|
4185
|
+
solvedInks: isSurfaceTreeRecord(item) ? item.solvedInks : void 0
|
|
4186
|
+
};
|
|
4187
|
+
if (isResolvedSurface(item)) {
|
|
4188
|
+
const input = serializeResolvedSurface(item).$surface;
|
|
4189
|
+
const index = revisionIndex(item.revision);
|
|
4190
|
+
const { palette: _palette, buttonSystem: _buttons, ...context } = input.context;
|
|
4191
|
+
return { $surface: {
|
|
4192
|
+
spec: input.spec,
|
|
4193
|
+
context,
|
|
4194
|
+
revision: index
|
|
4195
|
+
} };
|
|
4196
|
+
}
|
|
4197
|
+
return mapSurfaceTreeChildren(item, encode);
|
|
4198
|
+
};
|
|
4199
|
+
const encoded = encode(value);
|
|
4200
|
+
return revisions.length === 0 ? encoded : { [SURFACE_TRANSPORT_KEY]: {
|
|
4201
|
+
revisions,
|
|
4202
|
+
value: encoded
|
|
4203
|
+
} };
|
|
4204
|
+
}
|
|
4205
|
+
const surfaceEnvelopeSchema = z.object({ [SURFACE_TRANSPORT_KEY]: z.object({
|
|
4206
|
+
revisions: z.array(z.object({
|
|
4207
|
+
palette: z.record(z.string(), z.string()),
|
|
4208
|
+
buttonSystem: buttonSystemSchema.optional()
|
|
4209
|
+
})),
|
|
4210
|
+
value: z.unknown()
|
|
4211
|
+
}) });
|
|
4212
|
+
const surfaceReferenceSchema = z.object({ $surface: z.object({
|
|
4213
|
+
spec: surfaceSpecSchema,
|
|
4214
|
+
revision: z.number().int().nonnegative(),
|
|
4215
|
+
context: z.object({
|
|
4216
|
+
foreground: foregroundInputSchema.optional(),
|
|
4217
|
+
linkHoverToken: z.string().optional(),
|
|
4218
|
+
compositeBase: z.string().optional(),
|
|
4219
|
+
buttonContext: buttonInputSchema.optional(),
|
|
4220
|
+
solvedInks: solvedInksSchema.optional()
|
|
4221
|
+
})
|
|
4222
|
+
}) });
|
|
4223
|
+
const surfaceRevisionReferenceSchema = z.object({
|
|
4224
|
+
$surfaceRevision: z.number().int().nonnegative(),
|
|
4225
|
+
solvedInks: solvedInksSchema.optional()
|
|
4226
|
+
});
|
|
4227
|
+
/** Recreate owner results before any island's ordinary schema consumes them. */
|
|
4228
|
+
function parseSurfaceTree(value, solvedInks) {
|
|
4229
|
+
if (isResolvedSurface(value)) return resolveTransportedSurface(value, solvedInks);
|
|
4230
|
+
const revision = isSurfaceTreeRecord(value) ? surfaceRevisionOwners.get(value)?.revision : void 0;
|
|
4231
|
+
if (revision) return solvedInks === void 0 ? value : surfaceTransportContext({
|
|
4232
|
+
...revision,
|
|
4233
|
+
solvedInks
|
|
4234
|
+
});
|
|
4235
|
+
if (!isSurfaceTreeRecord(value) || !("$surfaceTransport" in value)) return mapSurfaceTreeChildren(value, (item) => parseSurfaceTree(item, solvedInks));
|
|
4236
|
+
const envelope = surfaceEnvelopeSchema.parse(value)[SURFACE_TRANSPORT_KEY];
|
|
4237
|
+
const revisions = envelope.revisions.map((revision) => {
|
|
4238
|
+
return ownSurfaceRevision(ownedThemeSnapshot({
|
|
4239
|
+
palette: revision.palette,
|
|
4240
|
+
buttonSystem: revision.buttonSystem
|
|
4241
|
+
}));
|
|
4242
|
+
});
|
|
4243
|
+
const decode = (item) => {
|
|
4244
|
+
if (isSurfaceTreeRecord(item) && "$surfaceRevision" in item) {
|
|
4245
|
+
const reference = surfaceRevisionReferenceSchema.parse(item);
|
|
4246
|
+
const revision = revisions[reference.$surfaceRevision];
|
|
4247
|
+
if (!revision) throw new Error("Unknown surface revision");
|
|
4248
|
+
const policy = solvedInks ?? reference.solvedInks;
|
|
4249
|
+
return policy === void 0 ? revision : surfaceTransportContext({
|
|
4250
|
+
...revision,
|
|
4251
|
+
solvedInks: policy
|
|
4252
|
+
});
|
|
4253
|
+
}
|
|
4254
|
+
if (isSurfaceTreeRecord(item) && "$surface" in item) {
|
|
4255
|
+
const request = surfaceReferenceSchema.parse(item).$surface;
|
|
4256
|
+
const revision = revisions[request.revision];
|
|
4257
|
+
if (!revision) throw new Error("Unknown surface revision");
|
|
4258
|
+
return resolveSurface(request.spec, {
|
|
4259
|
+
...revision,
|
|
4260
|
+
...request.context,
|
|
4261
|
+
buttonSystem: revision.buttonSystem,
|
|
4262
|
+
solvedInks: solvedInks ?? request.context.solvedInks
|
|
4263
|
+
});
|
|
4264
|
+
}
|
|
4265
|
+
return mapSurfaceTreeChildren(item, decode);
|
|
4266
|
+
};
|
|
4267
|
+
return decode(envelope.value);
|
|
4268
|
+
}
|
|
4269
|
+
function isSurfaceTreeRecord(value) {
|
|
4270
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4271
|
+
}
|
|
4272
|
+
function mapSurfaceTreeChildren(value, map) {
|
|
4273
|
+
if (Array.isArray(value)) return value.map(map);
|
|
4274
|
+
if (value instanceof Date) return value;
|
|
4275
|
+
return isSurfaceTreeRecord(value) ? Object.fromEntries(Object.entries(value).map(([key, item]) => [key, map(item)])) : value;
|
|
4276
|
+
}
|
|
4277
|
+
//#endregion
|
|
4278
|
+
export { contrastThresholdByPolicy as $, defineButtonStyleRecipe as A, srgbToOklab as At, mergeStyles as B, paddingDeclarations as C, _classPrivateFieldInitSpec as Ct, FONT_SIZE_MAP as D, oklabToSrgb as Dt, ELEVATION_OFFSET as E, oklabToOklch as Et, resolveThemeColorReferenceValue as F, resolveSurfaceForeground as G, surfaceRoleForTextToken as H, resolveTokenOrCssColorValue as I, solveSurfaceInks as J, safeTokenOr as K, backgroundColorStyle as L, mapButtonVisualAppearances as M, isCssColorLiteral as N, generateShadowValue as O, oklchToHexGamut as Ot, resolveOnColorForThemeToken as P, certifyPaint as Q, borderColorStyle as R, materializeRuntimeButtonAppearance as S, preparePaletteColourIndex as St, DEFAULT_BUTTON_SIZES as T, hexToRgb as Tt, textColorStyle as U, rgbColorValue as V, textColorValue as W, _classPrivateFieldSet2 as X, _classPrivateFieldGet2 as Y, HOVER_TEXT_THRESHOLD as Z, buttonBorder as _, resolveOpaqueSurfaceHex as _t, resolveSurface as a, SURFACE_FOREGROUND_CSS_VARS as at, buttonStateAppearanceDeclarations as b, requirePaletteColorsFromEntries as bt, surfaceDecorationColors as c, surfaceForegroundInputFromResolved as ct, scrimTone as d, surfaceForegroundValueWithOpacity as dt, inkReference as et, actionVariableFallback as f, surfaceInkDeclarations as ft, formatButtonColourContractError as g, resolveConcreteColorHex as gt, BUTTON_CONTRAST_POLICY as h, ownedThemeSnapshot as ht, requireResolvedSurface as i, DEFAULT_SURFACE_TEXT_COLOR as it, mapButtonRoleAppearances as j, PUBLIC_BUTTON_ROLES as k, rgbToHex as kt, compositeHex as l, surfaceForegroundStyle as lt, compileButtonColourStates as m, freezeOwnedThemeValue as mt, parseSurfaceTree as n, getTextColorForBackground as nt, serializeSurfaceTree as o, SURFACE_INK_CSS_VARS as ot, contextualButtonSurfaceResetStyles as p, surfaceInkStyle as pt, surfaceInkPublication as q, prepareSurfaceIndex as r, planForegroundHover as rt, surfaceButtonRequest as s, surfaceForegroundDeclarations as st, parseResolvedSurface as t, expandPalette as tt, gradientScrimSamples as u, surfaceForegroundValue as ut, buttonRadius as v, paletteValueKey as vt, BORDER_WIDTH_MAP as w, featuresFromHex as wt, buttonTypographyDeclarations as x, contrastRatio as xt, buttonShadow as y, paletteValueKeySchema as yt, cssVarValue as z };
|