@riverbankcms/sdk 0.183.0 → 0.185.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/README.md +34 -1
- package/dist/_dts/{BlocksIslandsHydrator-X1_G96iN.d.ts → BlocksIslandsHydrator-Bu0O7l4p.d.ts} +1 -1
- package/dist/_dts/{Page-CEqZJZEE.d.ts → Page-DYoL0IWL.d.ts} +7 -7
- package/dist/_dts/{SdkPreviewMode-DQejfbXL.d.ts → SdkPreviewMode-DgFAiR8r.d.ts} +2 -2
- package/dist/_dts/{client-B_B_amKD.d.ts → client-BKdjJ7A0.d.ts} +35 -4
- package/dist/_dts/{content-types-Dhx5Ocvx.d.ts → content-types-6K7zlJuF.d.ts} +2 -2
- package/dist/_dts/{contracts-FeOnfoa1.d.ts → contracts-CUR8ccnX.d.ts} +3 -3
- package/dist/_dts/{generatePageMetadata-m70J6tit.d.ts → generatePageMetadata-CveWSMew.d.ts} +2 -2
- package/dist/_dts/{index-CjAkEWAp.d.ts → index-6WypKfbu.d.ts} +4 -4
- package/dist/_dts/{index-iuFrbIjt.d.ts → index-BMwrFX_K.d.ts} +1 -1
- package/dist/_dts/{index-BxCmCit0.d.ts → index-Bp5lk6I8.d.ts} +1 -1
- package/dist/_dts/{index-BOpUh8kO.d.ts → index-DTKn1H8g.d.ts} +3 -3
- package/dist/_dts/{index-Bizdaxji.d.ts → index-DX-Xe54X.d.ts} +2 -2
- package/dist/_dts/{index-liuhlOX7.d.ts → index-SD1fTP_7.d.ts} +2 -2
- package/dist/_dts/{loadContent-D4wrTIIw.d.ts → loadContent-BN8GtRsL.d.ts} +7 -7
- package/dist/_dts/{request-Gn0O1blj.d.ts → request-BwYvMqLf.d.ts} +78461 -77905
- package/dist/_dts/{resolveBlockData-D5duwuqS.d.ts → resolveBlockData-CYy0VlSK.d.ts} +5 -5
- package/dist/_dts/{resolvePageContent-xzJ3c9Na.d.ts → resolvePageContent-BwUDLi_W.d.ts} +1 -1
- 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/gifting/client.d.ts +1 -1
- package/dist/_dts/sdk/src/index.d.ts +7 -7
- 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 +3 -3
- 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/portal/index.d.ts +10 -2
- 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 -4
- 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 +6 -6
- 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 +36 -1
- package/dist/_dts/{serviceBookingOutline-B1gyJon_.d.ts → serviceBookingOutline-CMNev0gz.d.ts} +19 -8
- package/dist/_dts/{types-DBNuMtSk.d.ts → types-BBazdRQf.d.ts} +9 -10
- package/dist/_dts/{types-DHMcuoeQ.d.ts → types-BwngWRQ8.d.ts} +13 -15
- package/dist/_dts/{types-BoITy0rA.d.ts → types-C9_amrul.d.ts} +6 -2
- package/dist/_dts/{validation-BIPO-XlE.d.ts → validation-B58kUTuV.d.ts} +4 -4
- package/dist/client/{BlocksIslandsHydrator-Ct8slgRk.mjs → BlocksIslandsHydrator-CooOPhs3.mjs} +17 -17
- package/dist/client/{BookingMailingListNote-qqTxGGS4.mjs → BookingMailingListNote-D_khdttF.mjs} +61 -62
- package/dist/client/{BookingQuestionFields-DCh9MUIF.mjs → BookingQuestionFields-Bia1E7Cj.mjs} +49 -36
- package/dist/client/{CalendarAction-RcdaStG7.mjs → CalendarAction-C-AbMmct.mjs} +2 -2
- package/dist/client/{CalendarNavigationChevron-D7Wt-Oaa.mjs → CalendarNavigationChevron-oaHxRbUO.mjs} +7 -7
- package/dist/client/{CheckboxChoice-BdGxZWeg.mjs → CheckboxChoice-CTMIII37.mjs} +1 -1
- package/dist/client/{DemoBookingPortalAccess-HFVkoOac.mjs → DemoBookingPortalAccess-M2xKYQjX.mjs} +7 -5
- package/dist/client/{EventCalendar.client-BtkJW8bA.mjs → EventCalendar.client-By7e9nyF.mjs} +11 -11
- package/dist/client/{EventCombined.client-DxaGjFFS.mjs → EventCombined.client-BdRZXB14.mjs} +10 -10
- package/dist/client/EventEmbeddedCheckoutStep-CJoxbx2Y.mjs +147 -0
- package/dist/client/{EventItem-Fr2qi2C2.mjs → EventItem-CDMa9zOX.mjs} +5 -5
- package/dist/client/{EventListWeekNavigation-BRMaq0ky.mjs → EventListWeekNavigation-B8WKaCrN.mjs} +1 -1
- package/dist/client/{EventListing.client-BhGxfbjt.mjs → EventListing.client-BEGiiFnO.mjs} +3 -3
- package/dist/client/{EventListing.view-COuEJzbO.mjs → EventListing.view-B6LOK-z4.mjs} +84 -7
- package/dist/client/{EventRegistrationPayment-BTLYhVxD.mjs → EventRegistrationPayment-CARdr15t.mjs} +140 -68
- package/dist/client/{Page-CgbQZP5g.mjs → Page-uP7AKSyp.mjs} +1762 -521
- package/dist/client/{ProtectedSubmitButton-BG7my0Qf.mjs → ProtectedSubmitButton-CY6u5sQa.mjs} +1 -1
- package/dist/client/SiteChoiceGroup-BZ5I0Vhy.mjs +96 -0
- package/dist/client/{SiteTermsAgreementField-DQNkfNLA.mjs → SiteTermsAgreementField-BDqRo2C5.mjs} +3 -3
- package/dist/client/{StepIndicator-DvPekKeM.mjs → StepIndicator-BWrXAKvs.mjs} +1 -1
- package/dist/client/{StepIndicator-DyXoI3ob.mjs → StepIndicator-Cb3NMw-Y.mjs} +30 -18
- package/dist/client/{ThemedButton-Bc9DBbVp.mjs → ThemedButton-C4rCsPCt.mjs} +11 -2
- package/dist/client/{accessibleSurfaces-wj4Rloo5.mjs → accessibleSurfaces-q-dDOwsW.mjs} +750 -560
- package/dist/client/{accordion-BVXfjnh-.mjs → accordion-BYW2YSUN.mjs} +1 -1
- package/dist/client/{booking-form.client-DycPGtke.mjs → booking-form.client-DAlWWWjV.mjs} +110 -72
- package/dist/client/{bookingCalendar--aWnqFDn.mjs → bookingCalendar-9nFa_do4.mjs} +6 -2
- package/dist/client/{bookingForm-DrWSUqL3.mjs → bookingForm-DtVk9p5l.mjs} +7 -6
- package/dist/client/bookings.mjs +5 -5
- package/dist/client/{boxStyleClassNames-CduDRcIk.mjs → boxStyleClassNames-CaSq3-r-.mjs} +2 -2
- package/dist/client/{EventEmbeddedCheckoutStep-B2c5dR49.mjs → browserStripe-Dh-LcDoW.mjs} +36 -142
- package/dist/client/{buttonParts-CJEtVOUy.mjs → buttonParts-C39GC0kz.mjs} +9 -2
- package/dist/client/{carousel-DyCLMP8s.mjs → carousel-msur7fxW.mjs} +2 -2
- package/dist/client/{carousel.client-DffP_Nv0.mjs → carousel.client-DKWqVHHh.mjs} +1 -1
- package/dist/client/{cart-BuEp_cj4.mjs → cart-Bx-JuY2n.mjs} +3 -3
- package/dist/client/{cart.client-CAO39uDG.mjs → cart.client-hB_9MimN.mjs} +1 -1
- package/dist/client/{checkout-BoxzT64s.mjs → checkout-BVWZn5Qu.mjs} +3 -3
- package/dist/client/{checkout.client-IGUy7XOx.mjs → checkout.client-Bt_GtHW9.mjs} +1 -1
- package/dist/client/{checkoutUrls-D0UsiFmm.mjs → checkoutUrls-CP-rQOZV.mjs} +1 -1
- package/dist/client/client.mjs +61 -48
- package/dist/client/{constants-C_8AxMdm.mjs → constants-yA1RJGXD.mjs} +1 -1
- package/dist/client/{context-D1L0pe__.mjs → context-CG77Keax.mjs} +43 -6
- package/dist/client/{dateFormatting-HvfmS_cH.mjs → dateFormatting-DIRIgfYr.mjs} +1 -1
- package/dist/client/{demoPortalMagicLink-BunFTnIq.mjs → demoPortalMagicLink-CgzNiOQ0.mjs} +1 -1
- package/dist/client/{enhanceHeaderSection-CtLAG651.mjs → enhanceHeaderSection-DgzZNM2M.mjs} +4 -4
- package/dist/client/{event-registration.client-DiSxkBUP.mjs → event-registration.client-Ckb4aDE9.mjs} +118 -74
- package/dist/client/{eventCalendar-DUnhwZ1o.mjs → eventCalendar-lqqQSzBQ.mjs} +4 -4
- package/dist/client/{eventCombined-BvBQo0nF.mjs → eventCombined-BIMyHrd-.mjs} +4 -4
- package/dist/client/{eventListing-aTLifOX7.mjs → eventListing-CBYxfvNf.mjs} +4 -4
- package/dist/client/{eventRegistration-DFd7pr09.mjs → eventRegistration-BhAqvkCb.mjs} +7 -6
- package/dist/client/{form-Dikmc2AO.mjs → form-CkOfk-Eb.mjs} +3 -3
- package/dist/client/{form.client-zHaQK5I9.mjs → form.client-Whi43oio.mjs} +5 -5
- package/dist/client/{form.parts-BLl9n8TH.mjs → form.parts-BgsWo2Me.mjs} +3 -3
- package/dist/client/gifting/client.mjs +8 -8
- package/dist/client/{gifting-CufPM38H.mjs → gifting-XtNpLcFI.mjs} +4 -4
- package/dist/client/{gifting.client--N1GaSY8.mjs → gifting.client-CraWj4I4.mjs} +174 -73
- package/dist/client/{gifting.interactive-D9MK4HkV.mjs → gifting.interactive-DiPDObN0.mjs} +61 -10
- package/dist/client/{gifting.parts-CRtiRzo-.mjs → gifting.parts-_mgGOcbA.mjs} +17 -43
- package/dist/client/{headerSection-BIaBpmk3.mjs → headerSection-CPIN3VSU.mjs} +2 -2
- package/dist/client/{islands-DJDLGQEm.mjs → islands-C95FyxUF.mjs} +1996 -1178
- package/dist/client/{newsletter-form.client-wg_JHTxm.mjs → newsletter-form.client-BgVJdKVe.mjs} +7 -7
- package/dist/client/{newsletter-form.interactive-hzpkW9NQ.mjs → newsletter-form.interactive-DpcfRbI_.mjs} +39 -18
- package/dist/client/{newsletter-form.parts-CgzpSv9p.mjs → newsletter-form.parts-poPgHrUh.mjs} +2 -2
- package/dist/client/{newsletterForm-CvxLiEBT.mjs → newsletterForm-Dt6wFjTe.mjs} +3 -3
- package/dist/client/portal/client.mjs +999 -81
- package/dist/client/{portalOrders-tCxS04g0.mjs → portalOrders-CAfjTyV9.mjs} +1 -1
- package/dist/client/{portalRoutes-DTHlWg_F.mjs → portalRoutes-D3Ttfv5x.mjs} +54 -12
- package/dist/client/portalSession-0XhXyTxT.mjs +41 -0
- package/dist/client/presentation-CudSUZ6Q.mjs +169 -0
- package/dist/client/{product-detail.client-22Q7zgjN.mjs → product-detail.client-BrBNT7Mq.mjs} +1 -1
- package/dist/client/{product-list.client-DFWYvK8z.mjs → product-list.client-CftTl7n6.mjs} +1 -1
- package/dist/client/{productDetail-DhZAwo60.mjs → productDetail-b1tpt585.mjs} +3 -3
- package/dist/client/{productList-BiVpbZK2.mjs → productList-DRT5sabi.mjs} +3 -3
- package/dist/client/{propsDecoder-DFYqKnLy.mjs → propsDecoder-Co1VXFaW.mjs} +4 -4
- package/dist/client/{registry.server-C3OBRg7x.mjs → registry.server-0UDNY7dO.mjs} +796 -715
- package/dist/client/rendering/client.mjs +28 -27
- package/dist/client/rendering/islands.mjs +1 -1
- package/dist/client/rendering.mjs +5 -5
- package/dist/client/{richText-coerce-ms477Z08.mjs → richText-coerce-BFDEPZZA.mjs} +2 -2
- package/dist/client/{routeIslandApiConfig-B6nQeqvH.mjs → routeIslandApiConfig-DtqRutuX.mjs} +1 -1
- package/dist/client/{runtimeResponse-BYqsV1Kb.mjs → runtimeResponse-DBVXbcuz.mjs} +1 -1
- package/dist/client/runtimeResponse-LQnQdtNI.mjs +3 -0
- package/dist/client/{shop-xt4dQ3HH.mjs → shop-DL3CYR7i.mjs} +3 -3
- package/dist/client/{shop-commerce-DVsIcPaI.mjs → shop-commerce-CDth2_qq.mjs} +45 -27
- package/dist/client/{shop-commerce-store-7mO6KY7_.mjs → shop-commerce-store-CE0aaSHJ.mjs} +1 -1
- package/dist/client/{shop-discount-apply.state-L1Vge8tG.mjs → shop-discount-apply.state-p4aXtVsF.mjs} +2 -2
- package/dist/client/{shop.client-DNJfD3VQ.mjs → shop.client-BI2iw6Z3.mjs} +83 -29
- package/dist/client/{shopShared-DS8t6749.mjs → shopShared-BNWzgWAC.mjs} +2 -2
- package/dist/client/spam-protection.mjs +1 -1
- package/dist/client/{src-Do_s2lqH.mjs → src-CJf3u16T.mjs} +1 -1
- package/dist/{preview-next/client/src-lX6heoDA.mjs → client/src-CMuv8vSO.mjs} +5 -1
- package/dist/client/src-CXOxpNtj.mjs +3 -0
- package/dist/client/{timetableModel-Dy3nNfTG.mjs → timetableModel-DZzGD6rS.mjs} +9 -9
- package/dist/client/{urlParams-C2QHo1Pa.mjs → useAutomaticDiscountPreview-CJDylOUe.mjs} +44 -1
- package/dist/client/{useAvailableSlots-DcjtDpUu.mjs → useAvailableSlots-nD6nuvSW.mjs} +2 -2
- package/dist/client/{useDiscountCodeUi-DvdFFWOT.mjs → useDiscountCodeUi-DMtTHqex.mjs} +6 -2
- package/dist/client/{useEventPagination-Cq-7sU5_.mjs → useEventPagination-CM-DCokc.mjs} +14 -16
- package/dist/client/{view-4gnPcpWJ.mjs → view-CHOhliHv.mjs} +4 -4
- package/dist/client/{wizardSteps-DDvL3iza.mjs → wizardSteps-BbroaNkT.mjs} +277 -87
- package/dist/preview-next/client/{EventEmbeddedCheckoutStep-CLqSRUpt.mjs → EventEmbeddedCheckoutStep-CVy9oapv.mjs} +1 -1
- package/dist/preview-next/client/{LocationPickerEnvironment-CIdAg-Tm.mjs → LocationPickerEnvironment-DuRUwUrK.mjs} +1 -1
- package/dist/preview-next/client/{MapLibreEditMap-Bm85jX35.mjs → MapLibreEditMap-CdSDYBq9.mjs} +2 -2
- package/dist/preview-next/client/{PageSectionToolbar-D8srnz9R.mjs → PageSectionToolbar-CR99z8BL.mjs} +582 -195
- package/dist/preview-next/client/{PreviewEditorSidebar-DVpk5cqp.mjs → PreviewEditorSidebar-BaKS6H8F.mjs} +1096 -283
- package/dist/preview-next/client/{PreviewEditorUI-XoTtHSFH.mjs → PreviewEditorUI-D6IG119o.mjs} +65 -16
- package/dist/preview-next/client/{PreviewShell-VQHsRg2u.mjs → PreviewShell-CKjkFOZS.mjs} +39 -12
- package/dist/preview-next/client/{SdkPreviewModeRuntime-CLdF9f6o.mjs → SdkPreviewModeRuntime-BexDQWGj.mjs} +128 -27
- package/dist/preview-next/client/{ThemedButton-ORNN4x-3.mjs → ThemedButton-CRgbU75r.mjs} +18 -2
- package/dist/preview-next/client/{lucide-react-eAi3tDAr.mjs → lucide-react-B4c6U3ZU.mjs} +1 -1
- package/dist/preview-next/client/{previewAssistantSlot-CqH91EwA.mjs → previewAssistantSlot-DcEwU9l_.mjs} +7192 -3039
- package/dist/preview-next/client/{previewChromeRoot-B3ySEu6p.mjs → previewChromeRoot-VqseF0yf.mjs} +1 -1
- package/dist/preview-next/client/runtime.mjs +3 -3
- package/dist/preview-next/client/{sdk-runtime-CdpSupcr.mjs → sdk-runtime-DcoVpKUf.mjs} +2 -2
- package/dist/preview-next/client/{siteStyleAccess-C6eOP6QW.mjs → siteStyleAccess-BL1fZnUD.mjs} +16 -10
- package/dist/{client/src-uwCpbHXG.mjs → preview-next/client/src-B5x3r4cg.mjs} +5 -1
- package/dist/preview-next/client/src-CrT7h--V.mjs +3 -0
- package/dist/preview-next/client/{useAutosaveStatus-BhPg4e-r.mjs → useAutosaveStatus-CdFnzKac.mjs} +3 -3
- package/dist/preview-next/client/{useOpenBlockForSetup-BaWUF9D7.mjs → useOpenBlockForSetup-B62h7dhR.mjs} +4 -3
- package/dist/preview-next/container-responsive.css +158 -3
- package/dist/preview-next/keepAlive.mjs +1 -1
- package/dist/preview-next/middleware.mjs +1 -1
- package/dist/preview-next/{route-contract-Ch0X99vE.mjs → route-contract-CQfEvfbg.mjs} +54 -41
- package/dist/server/{Block.shared-B2FmczLO.mjs → Block.shared-CbGnxkWX.mjs} +5 -5
- package/dist/server/{ThemeScopeCore-DtAyv9qA.mjs → ThemeScopeCore-BjxlpVaV.mjs} +34 -8
- package/dist/server/{accessibleSurfaces-BtPqb76u.mjs → accessibleSurfaces-CZ7pLuJ7.mjs} +317 -148
- package/dist/server/{accordions-vzdZ2Wt1.mjs → accordions-C_C52VkS.mjs} +1 -1
- package/dist/server/{bindings-B_9JuU66.mjs → bindings-D-n66Oqc.mjs} +68 -247
- package/dist/server/{client-DC7cjiSw.mjs → client-BGGlrkft.mjs} +64 -47
- package/dist/server/config-validation.mjs +1 -1
- package/dist/server/config.mjs +2 -2
- package/dist/server/{constants-d6nPNJpe.mjs → constants-TkO9Uxma.mjs} +51 -9
- package/dist/server/data/resolveBlockData.mjs +1 -1
- package/dist/server/index.mjs +3 -3
- package/dist/server/{loadContent-hb27HYic.mjs → loadContent-8H1hHdXo.mjs} +4 -4
- package/dist/server/{loadPage-JToD8wDD.mjs → loadPage-BZyqF_g3.mjs} +3 -3
- package/dist/server/lookMediaFrame-Dw6R9B0L.mjs +31837 -0
- package/dist/server/manifest.mjs +2 -2
- package/dist/server/{navigation-B2WhGofA.mjs → navigation-9TOyY5Zf.mjs} +1 -1
- package/dist/server/navigation.mjs +1 -1
- package/dist/server/next.mjs +9 -9
- package/dist/server/{overrideResolution-vD5KTClL.mjs → overrideResolution-CuduOS6V.mjs} +1 -1
- package/dist/server/page-converter.mjs +17 -4
- package/dist/server/{pageRenderPlan-CdqJ1NQZ.mjs → pageRenderPlan-DmP0HVMu.mjs} +618 -209
- package/dist/server/{pageRuntimeSupport-CAhr4oOf.mjs → pageRuntimeSupport-BQ1dWs1V.mjs} +12 -5
- package/dist/server/{pageShared-m80Xu2pd.mjs → pageShared-ALu7y5Dq.mjs} +836 -516
- package/dist/server/{parseThemeForPersistence-CRwOZfpa.mjs → parseThemeForPersistence-D_8I28BB.mjs} +3 -3
- package/dist/server/{portal-B2wCQno_.mjs → portal-P4oHSRho.mjs} +23 -2
- package/dist/server/portal.mjs +3 -3
- package/dist/server/{prebuild-BWIkFaXq.mjs → prebuild-BLL6RhjS.mjs} +1 -1
- package/dist/server/prebuild.mjs +1 -1
- package/dist/server/{prefetchBlockData-D1PHU-K9.mjs → prefetchBlockData-aR5W1dVF.mjs} +3 -3
- package/dist/server/{registry-KtsOsAzY.mjs → registry-DD_s7l3Y.mjs} +1575 -28658
- 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 +4 -4
- package/dist/server/rendering.mjs +9 -9
- package/dist/server/{resolveBlockData-sjIDJYl7.mjs → resolveBlockData-DnQ2N0lI.mjs} +2 -2
- package/dist/server/{expandPalette-DxPrNOAB.mjs → resolveButtonColourStates-ChlP4NJ9.mjs} +1662 -1430
- package/dist/server/{responseMedia-IfH65QAH.mjs → responseMedia-D6F1tvIm.mjs} +1 -1
- package/dist/server/{schema-BBEqquBM.mjs → schema-ClDfFtz2.mjs} +261 -6
- package/dist/server/server.mjs +3 -3
- package/dist/server/{servicePageContent-ChEZDRwU.mjs → servicePageContent-CsUerbJ1.mjs} +15 -12
- package/dist/server/theme-bridge.mjs +5 -4
- package/dist/server/theme.mjs +2 -2
- package/dist/server/{three-pass-converter-DKCIBeb1.mjs → three-pass-converter-CLJrZb7s.mjs} +1 -1
- package/dist/server/{titleSourceSchema-DybHErxH.mjs → titleSourceSchema-DA_iErtG.mjs} +2 -3
- package/dist/server/{types-vyz09w64.mjs → types-CcKy8_tj.mjs} +14 -5
- package/dist/server/{validation-Cvi-1TZZ.mjs → validation-BbImAsVs.mjs} +5 -5
- package/dist/server/{version-B-icAIV1.mjs → version-BY48jPoe.mjs} +1 -1
- package/dist/styles/index.css +684 -181
- package/package.json +1 -1
- package/dist/client/appointment-service-categories-Cl2pqw-z.mjs +0 -70
- package/dist/client/runtimeResponse-CUX_lldL.mjs +0 -3
- package/dist/client/src-DqMbCjI1.mjs +0 -3
- package/dist/preview-next/client/src-EO5QoRlU.mjs +0 -3
- package/dist/server/customCss-rtIfEYwQ.mjs +0 -230
- package/dist/server/lookMediaFrame-CTsycLLK.mjs +0 -2756
- package/dist/server/media-gvfIw3z8.mjs +0 -216
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as parseColorTokenParts, J as normalizePaletteHex, K as hexColorSchema, O as surfaceForegroundValue, Q as paletteModeSchema, U as PALETTE_TOKEN_NAMES, W as absoluteInkColors, X as paletteColorsFromEntries, c as buttonEffectApplicationSchema, m as parseOpaqueButtonColourToken, q as isThemeColorToken, s as unsafeAsOpaqueButtonColourToken } from "./types-CcKy8_tj.mjs";
|
|
2
|
+
import { o as err, s as ok, t as parseMediaAssetId } from "./media-BRmYrnzb.mjs";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
//#region ../theme-core/src/palette/utils/colorConversion.ts
|
|
4
5
|
const clamp01 = (x) => Math.max(0, Math.min(1, x));
|
|
@@ -321,91 +322,6 @@ const paletteValueKeySchema = z.string().transform((value, ctx) => {
|
|
|
321
322
|
return z.NEVER;
|
|
322
323
|
});
|
|
323
324
|
//#endregion
|
|
324
|
-
//#region ../theme-core/src/palette/utils/opaqueSurfaceColor.ts
|
|
325
|
-
/** Resolve an opaque colour, compositing alpha against an explicit underlay. */
|
|
326
|
-
function resolveOpaqueSurfaceHex(reference, palette, underlayReference) {
|
|
327
|
-
const opaque = resolveConcreteColorHex(reference, palette);
|
|
328
|
-
if (opaque) return opaque;
|
|
329
|
-
if (!underlayReference) return null;
|
|
330
|
-
const underlayHex = resolveConcreteColorHex(underlayReference, palette);
|
|
331
|
-
if (!underlayHex) return null;
|
|
332
|
-
const parts = parseColorTokenParts(reference);
|
|
333
|
-
if (parts.kind === "token" && parts.opacityPercent !== null) {
|
|
334
|
-
const foregroundHex = normalizePaletteHex(palette[parts.token] ?? "");
|
|
335
|
-
return foregroundHex ? compositeHex$1(foregroundHex, underlayHex, parts.opacityPercent / 100) : null;
|
|
336
|
-
}
|
|
337
|
-
const rgba = parseRgba(parts.kind === "raw" ? parts.value : reference);
|
|
338
|
-
return rgba ? compositeHex$1(rgbToHex(rgba.r, rgba.g, rgba.b), underlayHex, rgba.alpha) : null;
|
|
339
|
-
}
|
|
340
|
-
/** Resolve a colour reference only when it is already fully opaque. */
|
|
341
|
-
function resolveConcreteColorHex(reference, palette) {
|
|
342
|
-
const literalHex = normalizePaletteHex(reference);
|
|
343
|
-
if (literalHex) return literalHex;
|
|
344
|
-
const parts = parseColorTokenParts(reference);
|
|
345
|
-
if (parts.kind === "token") {
|
|
346
|
-
if (parts.opacityPercent !== null) return null;
|
|
347
|
-
return normalizePaletteHex(palette[parts.token] ?? "");
|
|
348
|
-
}
|
|
349
|
-
const literal = parts.kind === "raw" ? parts.value : reference;
|
|
350
|
-
if (literal.toLowerCase() === "black") return "#000000";
|
|
351
|
-
if (literal.toLowerCase() === "white") return "#ffffff";
|
|
352
|
-
return normalizePaletteHex(literal);
|
|
353
|
-
}
|
|
354
|
-
function compositeHex$1(foregroundHex, underlayHex, alpha) {
|
|
355
|
-
const foreground = hexToRgb(foregroundHex);
|
|
356
|
-
const underlay = hexToRgb(underlayHex);
|
|
357
|
-
const channel = (foregroundValue, underlayValue) => Math.round(foregroundValue * alpha + underlayValue * (1 - alpha));
|
|
358
|
-
return rgbToHex(channel(foreground.r, underlay.r), channel(foreground.g, underlay.g), channel(foreground.b, underlay.b));
|
|
359
|
-
}
|
|
360
|
-
function parseRgba(value) {
|
|
361
|
-
const match = value.trim().match(/^rgba?\(\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*(?:,|\/)\s*([\d.]+%?))?\s*\)$/i);
|
|
362
|
-
if (!match) return null;
|
|
363
|
-
const [, rSource, gSource, bSource] = match;
|
|
364
|
-
if (!rSource || !gSource || !bSource) return null;
|
|
365
|
-
const r = Number(rSource);
|
|
366
|
-
const g = Number(gSource);
|
|
367
|
-
const b = Number(bSource);
|
|
368
|
-
const alpha = parseAlpha(match[4]);
|
|
369
|
-
if (alpha === null || !isRgbChannel(r) || !isRgbChannel(g) || !isRgbChannel(b)) return null;
|
|
370
|
-
return {
|
|
371
|
-
r,
|
|
372
|
-
g,
|
|
373
|
-
b,
|
|
374
|
-
alpha
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
function parseAlpha(source) {
|
|
378
|
-
if (!source) return 1;
|
|
379
|
-
const value = source.endsWith("%") ? Number(source.slice(0, -1)) / 100 : Number(source);
|
|
380
|
-
return Number.isFinite(value) && value >= 0 && value <= 1 ? value : null;
|
|
381
|
-
}
|
|
382
|
-
function isRgbChannel(value) {
|
|
383
|
-
return Number.isFinite(value) && value >= 0 && value <= 255;
|
|
384
|
-
}
|
|
385
|
-
//#endregion
|
|
386
|
-
//#region ../theme-core/src/palette/utils/onColor.ts
|
|
387
|
-
const BACKGROUND_ROLE_NAMES = /* @__PURE__ */ new Set([
|
|
388
|
-
"primary",
|
|
389
|
-
"secondary",
|
|
390
|
-
"accent",
|
|
391
|
-
"success",
|
|
392
|
-
"warning",
|
|
393
|
-
"destructive",
|
|
394
|
-
"info",
|
|
395
|
-
"background",
|
|
396
|
-
"surface",
|
|
397
|
-
"surfaceAlt",
|
|
398
|
-
"muted",
|
|
399
|
-
"neutral"
|
|
400
|
-
]);
|
|
401
|
-
function onColorTokenName(backgroundToken) {
|
|
402
|
-
return `on${backgroundToken.split("-").filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")}`;
|
|
403
|
-
}
|
|
404
|
-
function isOnColorBackgroundCandidateToken(token) {
|
|
405
|
-
const role = token.match(/^(.*?)(?:-\d{2,3})?$/)?.[1] ?? token;
|
|
406
|
-
return BACKGROUND_ROLE_NAMES.has(role);
|
|
407
|
-
}
|
|
408
|
-
//#endregion
|
|
409
325
|
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/assertClassBrand.js
|
|
410
326
|
function _assertClassBrand(e, t, n) {
|
|
411
327
|
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
@@ -666,12 +582,12 @@ function paletteInkOnSolid(groundHex, roles) {
|
|
|
666
582
|
}
|
|
667
583
|
/**
|
|
668
584
|
* The ink as token emitters write it: the role's theme token, so CSS follows
|
|
669
|
-
* the palette's variables, or
|
|
585
|
+
* the palette's variables, or a fixed absolute black/white token.
|
|
670
586
|
*/
|
|
671
587
|
function paletteInkToken(ink) {
|
|
672
|
-
|
|
673
|
-
if (!isThemeColorToken(
|
|
674
|
-
return
|
|
588
|
+
const token = ink.kind === "role" ? ink.role : ink.hex === "#000000" ? "absoluteBlack" : "absoluteWhite";
|
|
589
|
+
if (!isThemeColorToken(token)) throw new Error(`Palette ink is not a theme token: ${token}`);
|
|
590
|
+
return token;
|
|
675
591
|
}
|
|
676
592
|
/**
|
|
677
593
|
* Secondary text that has to read on several grounds (a surface and the tinted
|
|
@@ -714,1491 +630,1807 @@ function paletteMutedInkOnSolid(ground, preferred, roles) {
|
|
|
714
630
|
return ink.hex;
|
|
715
631
|
}
|
|
716
632
|
//#endregion
|
|
717
|
-
//#region ../theme-core/src/palette/utils/
|
|
718
|
-
/**
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
return literalInkHex(maxContrastBlackOrWhite(luminanceInterval(relativeLuminance(r, g, b))).ink);
|
|
633
|
+
//#region ../theme-core/src/palette/utils/opaqueSurfaceColor.ts
|
|
634
|
+
/** Resolve an opaque colour, compositing alpha against an explicit underlay. */
|
|
635
|
+
function resolveOpaqueSurfaceHex(reference, palette, underlayReference) {
|
|
636
|
+
const opaque = resolveConcreteColorHex(reference, palette);
|
|
637
|
+
if (opaque) return opaque;
|
|
638
|
+
if (!underlayReference) return null;
|
|
639
|
+
const underlayHex = resolveConcreteColorHex(underlayReference, palette);
|
|
640
|
+
if (!underlayHex) return null;
|
|
641
|
+
const parts = parseColorTokenParts(reference);
|
|
642
|
+
if (parts.kind === "token" && parts.opacityPercent !== null) {
|
|
643
|
+
const foregroundHex = resolveConcreteColorHex(parts.token, palette);
|
|
644
|
+
return foregroundHex ? compositeHex$1(foregroundHex, underlayHex, parts.opacityPercent / 100) : null;
|
|
645
|
+
}
|
|
646
|
+
const rgba = parseRgba(parts.kind === "raw" ? parts.value : reference);
|
|
647
|
+
return rgba ? compositeHex$1(rgbToHex(rgba.r, rgba.g, rgba.b), underlayHex, rgba.alpha) : null;
|
|
733
648
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
649
|
+
/** Resolve a colour reference only when it is already fully opaque. */
|
|
650
|
+
function resolveConcreteColorHex(reference, palette) {
|
|
651
|
+
const literalHex = normalizePaletteHex(reference);
|
|
652
|
+
if (literalHex) return literalHex;
|
|
653
|
+
const parts = parseColorTokenParts(reference);
|
|
654
|
+
if (parts.kind === "token") {
|
|
655
|
+
if (parts.opacityPercent !== null) return null;
|
|
656
|
+
return normalizePaletteHex((parts.token === "absoluteBlack" || parts.token === "absoluteWhite" ? absoluteInkColors[parts.token] : palette[parts.token]) ?? "");
|
|
657
|
+
}
|
|
658
|
+
const literal = parts.kind === "raw" ? parts.value : reference;
|
|
659
|
+
if (literal.toLowerCase() === "black") return "#000000";
|
|
660
|
+
if (literal.toLowerCase() === "white") return "#ffffff";
|
|
661
|
+
return normalizePaletteHex(literal);
|
|
662
|
+
}
|
|
663
|
+
function compositeHex$1(foregroundHex, underlayHex, alpha) {
|
|
664
|
+
const foreground = hexToRgb(foregroundHex);
|
|
665
|
+
const underlay = hexToRgb(underlayHex);
|
|
666
|
+
const channel = (foregroundValue, underlayValue) => Math.round(foregroundValue * alpha + underlayValue * (1 - alpha));
|
|
667
|
+
return rgbToHex(channel(foreground.r, underlay.r), channel(foreground.g, underlay.g), channel(foreground.b, underlay.b));
|
|
668
|
+
}
|
|
669
|
+
function parseRgba(value) {
|
|
670
|
+
const match = value.trim().match(/^rgba?\(\s*([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*,\s*|\s+)([\d.]+)(?:\s*(?:,|\/)\s*([\d.]+%?))?\s*\)$/i);
|
|
671
|
+
if (!match) return null;
|
|
672
|
+
const [, rSource, gSource, bSource] = match;
|
|
673
|
+
if (!rSource || !gSource || !bSource) return null;
|
|
674
|
+
const r = Number(rSource);
|
|
675
|
+
const g = Number(gSource);
|
|
676
|
+
const b = Number(bSource);
|
|
677
|
+
const alpha = parseAlpha(match[4]);
|
|
678
|
+
if (alpha === null || !isRgbChannel(r) || !isRgbChannel(g) || !isRgbChannel(b)) return null;
|
|
679
|
+
return {
|
|
680
|
+
r,
|
|
681
|
+
g,
|
|
682
|
+
b,
|
|
683
|
+
alpha
|
|
742
684
|
};
|
|
743
|
-
throw new Error("Unsupported color format");
|
|
744
685
|
}
|
|
745
|
-
function
|
|
746
|
-
if (
|
|
747
|
-
|
|
686
|
+
function parseAlpha(source) {
|
|
687
|
+
if (!source) return 1;
|
|
688
|
+
const value = source.endsWith("%") ? Number(source.slice(0, -1)) / 100 : Number(source);
|
|
689
|
+
return Number.isFinite(value) && value >= 0 && value <= 1 ? value : null;
|
|
690
|
+
}
|
|
691
|
+
function isRgbChannel(value) {
|
|
692
|
+
return Number.isFinite(value) && value >= 0 && value <= 255;
|
|
748
693
|
}
|
|
749
694
|
//#endregion
|
|
750
|
-
//#region ../theme-core/src/
|
|
695
|
+
//#region ../theme-core/src/palette/generateShades.ts
|
|
696
|
+
function generateShades(hexColor, name) {
|
|
697
|
+
const shadeSteps = [
|
|
698
|
+
50,
|
|
699
|
+
100,
|
|
700
|
+
200,
|
|
701
|
+
300,
|
|
702
|
+
400,
|
|
703
|
+
500,
|
|
704
|
+
600,
|
|
705
|
+
700,
|
|
706
|
+
800,
|
|
707
|
+
900,
|
|
708
|
+
950
|
|
709
|
+
];
|
|
710
|
+
const base = featuresFromHex(hexColor);
|
|
711
|
+
const hue = base.okH;
|
|
712
|
+
const baseChroma = base.okC;
|
|
713
|
+
const toneMap = {
|
|
714
|
+
50: .975,
|
|
715
|
+
100: .945,
|
|
716
|
+
200: .89,
|
|
717
|
+
300: .82,
|
|
718
|
+
400: .74,
|
|
719
|
+
500: .66,
|
|
720
|
+
600: .58,
|
|
721
|
+
700: .49,
|
|
722
|
+
800: .4,
|
|
723
|
+
900: .28,
|
|
724
|
+
950: .16
|
|
725
|
+
};
|
|
726
|
+
const shadeDefs = shadeSteps.map((step, idx) => {
|
|
727
|
+
const t = idx / (shadeSteps.length - 1);
|
|
728
|
+
const L = toneMap[step];
|
|
729
|
+
const C = baseChroma * (.06 + .94 * Math.sin(Math.PI * t));
|
|
730
|
+
return {
|
|
731
|
+
name: `${name}-${step}`,
|
|
732
|
+
hex: oklchToHexGamut(L, C, hue)
|
|
733
|
+
};
|
|
734
|
+
});
|
|
735
|
+
shadeDefs.push({
|
|
736
|
+
name,
|
|
737
|
+
hex: hexColor
|
|
738
|
+
});
|
|
739
|
+
return shadeDefs;
|
|
740
|
+
}
|
|
741
|
+
//#endregion
|
|
742
|
+
//#region ../theme-core/src/palette/neutralScale.ts
|
|
743
|
+
/** The cool slate tint every scale had before #1863, kept for grounds with no hue to lend. */
|
|
744
|
+
const SLATE_NEUTRAL_TINT = {
|
|
745
|
+
hue: 250,
|
|
746
|
+
chroma: .02
|
|
747
|
+
};
|
|
748
|
+
/** Below this OKLCH chroma a background reads as plain white, grey or black, so its hue is noise. */
|
|
749
|
+
const ACHROMATIC_CHROMA = .005;
|
|
751
750
|
/**
|
|
752
|
-
*
|
|
753
|
-
*
|
|
754
|
-
*
|
|
755
|
-
*
|
|
751
|
+
* The tint a palette's greys take from its background: the background's own
|
|
752
|
+
* hue at no more than the slate scale's chroma, so a cream site gets warm greys.
|
|
753
|
+
* A background with no hue to lend (white, `#fafafa`, a missing or unreadable
|
|
754
|
+
* value) keeps the slate tint, so those palettes keep their exact neutrals.
|
|
756
755
|
*/
|
|
756
|
+
function neutralTint(background) {
|
|
757
|
+
const parsed = hexColorSchema.safeParse(background?.toLowerCase());
|
|
758
|
+
if (!parsed.success) return SLATE_NEUTRAL_TINT;
|
|
759
|
+
const { r, g, b } = hexToRgb(parsed.data);
|
|
760
|
+
const { L, a, b: ob } = srgbToOklab(r, g, b);
|
|
761
|
+
const { C, h } = oklabToOklch(L, a, ob);
|
|
762
|
+
return C < ACHROMATIC_CHROMA ? SLATE_NEUTRAL_TINT : {
|
|
763
|
+
hue: h,
|
|
764
|
+
chroma: Math.min(C, SLATE_NEUTRAL_TINT.chroma)
|
|
765
|
+
};
|
|
766
|
+
}
|
|
757
767
|
/**
|
|
758
|
-
*
|
|
768
|
+
* A neutral scale from near-white (`neutral-50`) to near-black (`neutral-950`)
|
|
769
|
+
* on every palette, light or dark. Readers that want "the ground" or "the
|
|
770
|
+
* text" ask the palette for those roles, not a fixed end of this scale.
|
|
759
771
|
*/
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
low: 2,
|
|
795
|
-
medium: 4,
|
|
796
|
-
high: 6
|
|
797
|
-
};
|
|
772
|
+
function generateNeutralScale({ steps = 11, tint = SLATE_NEUTRAL_TINT } = {}) {
|
|
773
|
+
const shadeNames = [
|
|
774
|
+
50,
|
|
775
|
+
100,
|
|
776
|
+
200,
|
|
777
|
+
300,
|
|
778
|
+
400,
|
|
779
|
+
500,
|
|
780
|
+
600,
|
|
781
|
+
700,
|
|
782
|
+
800,
|
|
783
|
+
900,
|
|
784
|
+
950
|
|
785
|
+
];
|
|
786
|
+
const count = Math.min(steps, shadeNames.length);
|
|
787
|
+
return shadeNames.slice(0, count).map((shadeName, index) => ({
|
|
788
|
+
name: `neutral-${shadeName}`,
|
|
789
|
+
hex: oklchToHexGamut(mix(.98, .1, index / (count - 1)), tint.chroma, tint.hue)
|
|
790
|
+
}));
|
|
791
|
+
}
|
|
792
|
+
function mix(a, b, t) {
|
|
793
|
+
return a + (b - a) * Math.max(0, Math.min(1, t));
|
|
794
|
+
}
|
|
795
|
+
//#endregion
|
|
796
|
+
//#region ../theme-core/src/palette/utils/scrimContrast.ts
|
|
797
|
+
const WHITE = "#ffffff";
|
|
798
|
+
const BLACK = "#000000";
|
|
799
|
+
/** `top` at `alpha` over opaque `bottom`, blended as CSS paints an overlay. */
|
|
800
|
+
function compositeHex(topHex, alpha, bottomHex) {
|
|
801
|
+
const top = hexToRgb(topHex);
|
|
802
|
+
const bottom = hexToRgb(bottomHex);
|
|
803
|
+
const mix = (a, b) => Math.round(alpha * a + (1 - alpha) * b);
|
|
804
|
+
return rgbToHex(mix(top.r, bottom.r), mix(top.g, bottom.g), mix(top.b, bottom.b));
|
|
805
|
+
}
|
|
798
806
|
/**
|
|
799
|
-
*
|
|
800
|
-
*
|
|
801
|
-
*
|
|
802
|
-
* Benefits: single source of truth, easy to adjust algorithm, no redundancy.
|
|
803
|
-
*
|
|
804
|
-
* @param elevation - Shadow elevation level
|
|
805
|
-
* @param softness - Shadow softness/blur style
|
|
806
|
-
* @param position - Shadow position (bottom or bottom-right diagonal)
|
|
807
|
-
* @returns CSS box-shadow value
|
|
807
|
+
* The lowest contrast `foreground` can reach over `scrim` at `alpha` laid on
|
|
808
|
+
* any pixel. A foreground whose luminance falls inside the range the
|
|
809
|
+
* composites can take has a worst case of 1:1.
|
|
808
810
|
*/
|
|
809
|
-
function
|
|
810
|
-
|
|
811
|
-
const
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
blur: 12,
|
|
822
|
-
spread: -2
|
|
823
|
-
}
|
|
824
|
-
}[elevation];
|
|
825
|
-
const baseOffset = ELEVATION_OFFSET[elevation];
|
|
826
|
-
const xOffset = position === "bottom-right" ? baseOffset : 0;
|
|
827
|
-
const yOffset = baseOffset;
|
|
828
|
-
switch (softness) {
|
|
829
|
-
case null:
|
|
830
|
-
case "soft": return `${xOffset}px ${yOffset}px ${config.blur}px ${config.spread}px ${color ?? "rgb(0 0 0 / 0.3)"}`;
|
|
831
|
-
case "hard": return `${xOffset}px ${yOffset}px 0 0 ${color ?? "rgb(0 0 0 / 1)"}`;
|
|
832
|
-
case "crisp": return `${xOffset}px ${yOffset}px ${baseOffset}px ${config.spread}px ${color ?? "rgb(0 0 0 / 0.4)"}`;
|
|
833
|
-
}
|
|
811
|
+
function worstCaseScrimContrast(input) {
|
|
812
|
+
const overWhite = compositeHex(input.scrimHex, input.alpha, WHITE);
|
|
813
|
+
const overBlack = compositeHex(input.scrimHex, input.alpha, BLACK);
|
|
814
|
+
const luminance = (hex) => {
|
|
815
|
+
const { r, g, b } = hexToRgb(hex);
|
|
816
|
+
return relativeLuminance(r, g, b);
|
|
817
|
+
};
|
|
818
|
+
const foreground = luminance(input.foregroundHex);
|
|
819
|
+
const low = luminance(overBlack);
|
|
820
|
+
const high = luminance(overWhite);
|
|
821
|
+
if (foreground >= low && foreground <= high) return 1;
|
|
822
|
+
return Math.min(contrastRatio(input.foregroundHex, overWhite), contrastRatio(input.foregroundHex, overBlack));
|
|
834
823
|
}
|
|
835
824
|
/**
|
|
836
|
-
*
|
|
825
|
+
* The smallest scrim opacity, in hundredths, at which every foreground keeps
|
|
826
|
+
* `threshold` contrast over any pixel. `null` when even an opaque scrim fails,
|
|
827
|
+
* which means the foreground was never legible on the scrim colour itself.
|
|
837
828
|
*/
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
};
|
|
845
|
-
|
|
846
|
-
|
|
829
|
+
function minimumScrimOpacity(input) {
|
|
830
|
+
const passes = (alpha) => input.foregroundHexes.every((foregroundHex) => worstCaseScrimContrast({
|
|
831
|
+
foregroundHex,
|
|
832
|
+
scrimHex: input.scrimHex,
|
|
833
|
+
alpha
|
|
834
|
+
}) >= input.threshold);
|
|
835
|
+
return Array.from({ length: 101 }, (_, hundredths) => hundredths / 100).find(passes) ?? null;
|
|
836
|
+
}
|
|
837
|
+
/** Shared samples for literal RGB washes and palette-token gradient veils. */
|
|
838
|
+
function gradientScrimSamples(gradient, alpha, palette) {
|
|
839
|
+
const literal = [...gradient.matchAll(/rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*([\d.]+))?\s*\)/g)].map((stop) => ({
|
|
840
|
+
hex: rgbToHex(Number(stop[1]), Number(stop[2]), Number(stop[3])),
|
|
841
|
+
alpha: alpha * (stop[4] === void 0 ? 1 : Number(stop[4]))
|
|
842
|
+
}));
|
|
843
|
+
const tokens = [...gradient.matchAll(/var\(--tb-([\w-]+)\)/g)].flatMap((stop) => {
|
|
844
|
+
const hex = stop[1] ? resolveConcreteColorHex(stop[1], palette) : null;
|
|
845
|
+
return hex ? [{
|
|
846
|
+
hex,
|
|
847
|
+
alpha
|
|
848
|
+
}] : [];
|
|
849
|
+
});
|
|
850
|
+
return [...literal, ...tokens];
|
|
851
|
+
}
|
|
852
|
+
/** The ink with the stronger worst-pixel guarantee identifies the veil tone.
|
|
853
|
+
* No readable samples (or a tie) leaves classification to the foreground owner.
|
|
847
854
|
*/
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
"
|
|
858
|
-
|
|
859
|
-
|
|
855
|
+
function scrimTone(samples) {
|
|
856
|
+
if (samples.length === 0) return null;
|
|
857
|
+
const worst = (foregroundHex) => Math.min(...samples.map((sample) => worstCaseScrimContrast({
|
|
858
|
+
foregroundHex,
|
|
859
|
+
scrimHex: sample.hex,
|
|
860
|
+
alpha: sample.alpha
|
|
861
|
+
})));
|
|
862
|
+
const white = worst(WHITE);
|
|
863
|
+
const black = worst(BLACK);
|
|
864
|
+
return white === black ? null : white > black ? "dark" : "light";
|
|
865
|
+
}
|
|
866
|
+
//#endregion
|
|
867
|
+
//#region ../theme-core/src/palette/utils/textColor.ts
|
|
860
868
|
/**
|
|
861
|
-
*
|
|
869
|
+
* Pick the better of black/white text for a given background using actual
|
|
870
|
+
* contrast ratios, not a simple luminance cutoff. This is
|
|
871
|
+
* `maxContrastBlackOrWhite` for a solid ground. It is the literal fallback
|
|
872
|
+
* only: where a palette is in scope, `paletteInkOnSolid` tries the site's own
|
|
873
|
+
* background and text colours first.
|
|
862
874
|
*
|
|
863
|
-
*
|
|
864
|
-
*
|
|
865
|
-
*
|
|
875
|
+
* @param background - Background color in hex or rgb/rgba format (e.g., '#FFFFFF' or 'rgb(255, 255, 255)')
|
|
876
|
+
* @param _minContrast - Kept for callers. It cannot change the result: when
|
|
877
|
+
* only one of black or white reaches it, that one is also the better of the two.
|
|
878
|
+
* @returns '#000000' for light backgrounds, '#FFFFFF' for dark backgrounds
|
|
866
879
|
*/
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
fontSize: "text-sm"
|
|
871
|
-
},
|
|
872
|
-
md: { padding: "0.75rem 1.5rem" },
|
|
873
|
-
lg: {
|
|
874
|
-
padding: "1rem 2rem",
|
|
875
|
-
fontSize: "text-lg"
|
|
876
|
-
},
|
|
877
|
-
xl: {
|
|
878
|
-
padding: "1.25rem 2.5rem",
|
|
879
|
-
fontSize: "text-xl"
|
|
880
|
-
}
|
|
881
|
-
};
|
|
882
|
-
//#endregion
|
|
883
|
-
//#region ../theme-core/src/buttons/buttonColourContract.ts
|
|
884
|
-
const BUTTON_CONTRAST_POLICY = {
|
|
885
|
-
textMinimumRatio: 4.5,
|
|
886
|
-
nonTextMinimumRatio: 3,
|
|
887
|
-
filledMinimumDeltaE: .12,
|
|
888
|
-
gradientSamplesPerSegment: 20,
|
|
889
|
-
alphaBackgrounds: "reject-without-known-surface",
|
|
890
|
-
disabled: "validated-colour-pair-with-muted-control-opacity"
|
|
891
|
-
};
|
|
892
|
-
function formatButtonColourContractError(error) {
|
|
893
|
-
switch (error.tag) {
|
|
894
|
-
case "unknown_palette_token": return `Button "${error.variantId}" ${error.state} state uses unknown palette token "${error.token}".`;
|
|
895
|
-
case "insufficient_contrast": return `Button "${error.variantId}" ${error.state} state has ${error.ratio.toFixed(2)}:1 contrast (${error.requiredRatio}:1 required).`;
|
|
896
|
-
case "insufficient_surface_separation": return `Button "${error.variantId}" ${error.state} state is indistinguishable from its surface at OKLab distance ${error.deltaE.toFixed(3)} (${error.requiredDeltaE} required).`;
|
|
897
|
-
case "unsupported_colour_effect": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" is not contrast-safe (${error.reason}).`;
|
|
898
|
-
case "invalid_colour_effect_options": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" has an invalid ${error.option} option.`;
|
|
899
|
-
case "inapplicable_colour_effect": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" cannot apply to a ${error.treatment} treatment.`;
|
|
900
|
-
case "unknown_button_effect": return `Button "${error.variantId}" ${error.state} uses unknown effect "${error.effectId}".`;
|
|
901
|
-
}
|
|
880
|
+
function pickBlackOrWhiteTextColor(background, _minContrast = 4.5) {
|
|
881
|
+
const { r, g, b } = parseColorToRgb(background);
|
|
882
|
+
return literalInkHex(maxContrastBlackOrWhite(luminanceInterval(relativeLuminance(r, g, b))).ink);
|
|
902
883
|
}
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
884
|
+
function parseColorToRgb(input) {
|
|
885
|
+
const trimmed = input.trim();
|
|
886
|
+
if (trimmed.startsWith("#")) return hexToRgb(trimmed);
|
|
887
|
+
const rgbMatch = trimmed.match(/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(?:\s*,\s*(?:0|1|0?\.\d+))?\s*\)$/i);
|
|
888
|
+
if (rgbMatch?.[1] && rgbMatch[2] && rgbMatch[3]) return {
|
|
889
|
+
r: clamp255(Number(rgbMatch[1])),
|
|
890
|
+
g: clamp255(Number(rgbMatch[2])),
|
|
891
|
+
b: clamp255(Number(rgbMatch[3]))
|
|
909
892
|
};
|
|
893
|
+
throw new Error("Unsupported color format");
|
|
910
894
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
function buttonSurfaceSeparation(fill, surface, edge) {
|
|
915
|
-
return buttonGroundSeparation(fill, buttonSurfaceGrounds(surface), edge);
|
|
895
|
+
function clamp255(value) {
|
|
896
|
+
if (Number.isNaN(value)) return 0;
|
|
897
|
+
return Math.max(0, Math.min(255, value));
|
|
916
898
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
function
|
|
934
|
-
|
|
935
|
-
if (token && !input.palette[token]) return {
|
|
936
|
-
ok: false,
|
|
937
|
-
error: {
|
|
938
|
-
tag: "unknown_palette_token",
|
|
939
|
-
variantId: input.variantId,
|
|
940
|
-
state: input.state,
|
|
941
|
-
token
|
|
942
|
-
}
|
|
943
|
-
};
|
|
944
|
-
const separation = buttonSurfaceSeparation(input.buttonPaint, input.surface, input);
|
|
945
|
-
return separation.distinct ? { ok: true } : {
|
|
946
|
-
ok: false,
|
|
947
|
-
error: {
|
|
948
|
-
tag: "insufficient_surface_separation",
|
|
949
|
-
variantId: input.variantId,
|
|
950
|
-
state: input.state,
|
|
951
|
-
buttonPaint: input.buttonPaint,
|
|
952
|
-
surface: separation.ground,
|
|
953
|
-
deltaE: separation.deltaE,
|
|
954
|
-
requiredDeltaE: BUTTON_CONTRAST_POLICY.filledMinimumDeltaE
|
|
955
|
-
}
|
|
956
|
-
};
|
|
957
|
-
}
|
|
958
|
-
function validateButtonTextContrast(input) {
|
|
959
|
-
const ratio = contrastRatio(input.backgroundHex, input.foregroundHex, input.colourIndex);
|
|
960
|
-
return ratio >= BUTTON_CONTRAST_POLICY.textMinimumRatio ? { ok: true } : {
|
|
961
|
-
ok: false,
|
|
962
|
-
error: {
|
|
963
|
-
tag: "insufficient_contrast",
|
|
964
|
-
variantId: input.variantId,
|
|
965
|
-
state: input.state,
|
|
966
|
-
background: input.background,
|
|
967
|
-
foreground: input.foreground,
|
|
968
|
-
ratio,
|
|
969
|
-
requiredRatio: BUTTON_CONTRAST_POLICY.textMinimumRatio
|
|
970
|
-
}
|
|
971
|
-
};
|
|
899
|
+
//#endregion
|
|
900
|
+
//#region ../theme-core/src/palette/utils/onColor.ts
|
|
901
|
+
const BACKGROUND_ROLE_NAMES = /* @__PURE__ */ new Set([
|
|
902
|
+
"primary",
|
|
903
|
+
"secondary",
|
|
904
|
+
"accent",
|
|
905
|
+
"success",
|
|
906
|
+
"warning",
|
|
907
|
+
"destructive",
|
|
908
|
+
"info",
|
|
909
|
+
"background",
|
|
910
|
+
"surface",
|
|
911
|
+
"surfaceAlt",
|
|
912
|
+
"muted",
|
|
913
|
+
"neutral"
|
|
914
|
+
]);
|
|
915
|
+
function onColorTokenName(backgroundToken) {
|
|
916
|
+
return `on${backgroundToken.split("-").filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")}`;
|
|
972
917
|
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
return
|
|
918
|
+
function isOnColorBackgroundCandidateToken(token) {
|
|
919
|
+
const role = token.match(/^(.*?)(?:-\d{2,3})?$/)?.[1] ?? token;
|
|
920
|
+
return BACKGROUND_ROLE_NAMES.has(role);
|
|
976
921
|
}
|
|
977
922
|
//#endregion
|
|
978
|
-
//#region ../theme-core/src/
|
|
923
|
+
//#region ../theme-core/src/palette/expandPalette.ts
|
|
924
|
+
function colorsToMap(palette) {
|
|
925
|
+
const map = {};
|
|
926
|
+
for (const c of palette.colors) map[c.name] = c.hex;
|
|
927
|
+
return map;
|
|
928
|
+
}
|
|
929
|
+
const nonShadeablePaletteRoleNames = /* @__PURE__ */ new Set([
|
|
930
|
+
"success",
|
|
931
|
+
"warning",
|
|
932
|
+
"destructive"
|
|
933
|
+
]);
|
|
979
934
|
/**
|
|
980
|
-
*
|
|
935
|
+
* Status role aliases the persisted palette does not carry itself.
|
|
981
936
|
*
|
|
982
|
-
*
|
|
983
|
-
*
|
|
937
|
+
* Generators reference `--tb-error` (the site-style-owned input error border)
|
|
938
|
+
* and `--tb-info` (`.alert-info`, `.status-info`, the field-note rule), but the
|
|
939
|
+
* palette schema only defines `destructive` and has no `info` role at all.
|
|
940
|
+
* Without these aliases those declarations name variables that are never
|
|
941
|
+
* defined and browsers drop them. The SDK bridge resolves the same pair via
|
|
942
|
+
* TOKEN_ALIASES, so both runtimes agree on what a status token means.
|
|
943
|
+
*
|
|
944
|
+
* Runs after the danger → destructive promotion above, so `destructive` is
|
|
945
|
+
* already the single source of truth for the error colour.
|
|
984
946
|
*/
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
},
|
|
993
|
-
"lighten-background": {
|
|
994
|
-
classification: "colour-transition",
|
|
995
|
-
transition: {
|
|
996
|
-
kind: "adjust-shade",
|
|
997
|
-
direction: "lighter"
|
|
998
|
-
}
|
|
999
|
-
},
|
|
1000
|
-
"background-on-hover": {
|
|
1001
|
-
classification: "colour-transition",
|
|
1002
|
-
transition: { kind: "replace-background" }
|
|
1003
|
-
},
|
|
1004
|
-
"background-on-hover-alpha": {
|
|
1005
|
-
classification: "unsupported-colour",
|
|
1006
|
-
reason: "alpha_requires_surface"
|
|
1007
|
-
},
|
|
1008
|
-
"fade-background": {
|
|
1009
|
-
classification: "unsupported-colour",
|
|
1010
|
-
reason: "changes_element_opacity"
|
|
1011
|
-
},
|
|
1012
|
-
"opacity-reduce": {
|
|
1013
|
-
classification: "unsupported-colour",
|
|
1014
|
-
reason: "changes_element_opacity"
|
|
1015
|
-
},
|
|
1016
|
-
"gradient-text": {
|
|
1017
|
-
classification: "unsupported-colour",
|
|
1018
|
-
reason: "changes_foreground"
|
|
1019
|
-
},
|
|
1020
|
-
"text-color-change": {
|
|
1021
|
-
classification: "unsupported-colour",
|
|
1022
|
-
reason: "changes_foreground"
|
|
1023
|
-
},
|
|
1024
|
-
"border-color-change": {
|
|
1025
|
-
classification: "unsupported-colour",
|
|
1026
|
-
reason: "changes_border"
|
|
1027
|
-
},
|
|
1028
|
-
"aurora-glow": {
|
|
1029
|
-
classification: "unsupported-background-overlay",
|
|
1030
|
-
reason: "unresolved_background_overlay"
|
|
1031
|
-
},
|
|
1032
|
-
"cosmic-stardust": {
|
|
1033
|
-
classification: "unsupported-background-overlay",
|
|
1034
|
-
reason: "unresolved_background_overlay"
|
|
1035
|
-
},
|
|
1036
|
-
"gradient-border-fill": {
|
|
1037
|
-
classification: "unsupported-background-overlay",
|
|
1038
|
-
reason: "unresolved_background_overlay"
|
|
1039
|
-
},
|
|
1040
|
-
"animated-gradient-border-fill": {
|
|
1041
|
-
classification: "unsupported-background-overlay",
|
|
1042
|
-
reason: "unresolved_background_overlay"
|
|
1043
|
-
},
|
|
1044
|
-
"nav-underline": {
|
|
1045
|
-
classification: "not-button",
|
|
1046
|
-
reason: "not_button_effect"
|
|
1047
|
-
},
|
|
1048
|
-
"nav-frosted-base": {
|
|
1049
|
-
classification: "not-button",
|
|
1050
|
-
reason: "not_button_effect"
|
|
1051
|
-
},
|
|
1052
|
-
"nav-frosted-hover": {
|
|
1053
|
-
classification: "not-button",
|
|
1054
|
-
reason: "not_button_effect"
|
|
1055
|
-
},
|
|
1056
|
-
"nav-frosted-active": {
|
|
1057
|
-
classification: "not-button",
|
|
1058
|
-
reason: "not_button_effect"
|
|
1059
|
-
},
|
|
1060
|
-
"animated-gradient": { classification: "non-colour" },
|
|
1061
|
-
"border-glow": {
|
|
1062
|
-
classification: "unsupported-colour",
|
|
1063
|
-
reason: "changes_shadow_colour"
|
|
1064
|
-
},
|
|
1065
|
-
"drop-shadow": { classification: "decorative-colour" },
|
|
1066
|
-
"inner-shadow": { classification: "decorative-colour" },
|
|
1067
|
-
"neumorphic-shadow": { classification: "decorative-colour" },
|
|
1068
|
-
"outer-glow": {
|
|
1069
|
-
classification: "unsupported-colour",
|
|
1070
|
-
reason: "changes_shadow_colour"
|
|
1071
|
-
},
|
|
1072
|
-
"retro-3d-shadow": { classification: "decorative-colour" },
|
|
1073
|
-
"scale-up": { classification: "non-colour" },
|
|
1074
|
-
"scale-down": { classification: "non-colour" },
|
|
1075
|
-
lift: { classification: "non-colour" },
|
|
1076
|
-
"press-down": { classification: "non-colour" },
|
|
1077
|
-
pop: { classification: "non-colour" },
|
|
1078
|
-
"border-bottom-grow": { classification: "non-colour" },
|
|
1079
|
-
"sketchy-border": { classification: "decorative-colour" },
|
|
1080
|
-
"inner-dashed-outline": { classification: "decorative-colour" },
|
|
1081
|
-
"pulse-animation": {
|
|
1082
|
-
classification: "unsupported-colour",
|
|
1083
|
-
reason: "changes_element_opacity"
|
|
1084
|
-
}
|
|
1085
|
-
};
|
|
1086
|
-
function validateButtonEffectOptions(effect) {
|
|
1087
|
-
const parsed = buttonEffectApplicationSchema.safeParse(effect);
|
|
1088
|
-
if (parsed.success) return { ok: true };
|
|
1089
|
-
const firstIssue = parsed.error.issues[0];
|
|
1090
|
-
const firstPathPart = firstIssue?.path[firstIssue.path.length - 1];
|
|
947
|
+
function statusAliasTokens(expanded) {
|
|
948
|
+
const aliases = {};
|
|
949
|
+
if (expanded.destructive) aliases.error = expanded.destructive;
|
|
950
|
+
if (expanded.accent) aliases.info = expanded.accent;
|
|
951
|
+
return aliases;
|
|
952
|
+
}
|
|
953
|
+
function expandPalette(palette, options = {}) {
|
|
1091
954
|
return {
|
|
1092
|
-
|
|
1093
|
-
|
|
955
|
+
...expandBasePalette(palette),
|
|
956
|
+
...arrangementPaletteTokens(colorsToMap(palette), options)
|
|
1094
957
|
};
|
|
1095
958
|
}
|
|
1096
|
-
function
|
|
1097
|
-
|
|
1098
|
-
}
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
nonColourEffects: []
|
|
959
|
+
function expandBasePalette(palette) {
|
|
960
|
+
const base = colorsToMap(palette);
|
|
961
|
+
const expanded = { ...base };
|
|
962
|
+
const roles = paletteInkRoles(base);
|
|
963
|
+
generateNeutralScale({
|
|
964
|
+
steps: 11,
|
|
965
|
+
tint: neutralTint(base.background)
|
|
966
|
+
}).forEach((n) => {
|
|
967
|
+
expanded[n.name] = n.hex;
|
|
1106
968
|
});
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
const options = validateButtonEffectOptions(effect);
|
|
1113
|
-
if (!options.ok) return invalidEffectOption(input, effect, options.option);
|
|
1114
|
-
return policy.classification === "colour-transition" ? transitionColour(input, current, effect) : {
|
|
1115
|
-
...current,
|
|
1116
|
-
nonColourEffects: [...current.nonColourEffects, effect]
|
|
1117
|
-
};
|
|
1118
|
-
}
|
|
1119
|
-
function transitionColour(input, current, effect) {
|
|
1120
|
-
if (effect.effectId === "background-on-hover") {
|
|
1121
|
-
const colorToken = readOpaqueToken(effect);
|
|
1122
|
-
return colorToken === null ? invalidEffectOption(input, effect, "colorToken") : {
|
|
1123
|
-
...current,
|
|
1124
|
-
treatment: {
|
|
1125
|
-
type: "solid",
|
|
1126
|
-
colorToken
|
|
1127
|
-
}
|
|
1128
|
-
};
|
|
969
|
+
for (const [name, hex] of Object.entries(base)) {
|
|
970
|
+
if (nonShadeablePaletteRoleNames.has(name)) continue;
|
|
971
|
+
if (hex) generateShades(hex, name).forEach((shade) => {
|
|
972
|
+
expanded[shade.name] = shade.hex;
|
|
973
|
+
});
|
|
1129
974
|
}
|
|
1130
|
-
if (
|
|
1131
|
-
if (
|
|
1132
|
-
|
|
1133
|
-
|
|
975
|
+
if (base.text) expanded.body = base.text;
|
|
976
|
+
if (base.danger && !base.destructive) expanded.destructive = base.danger;
|
|
977
|
+
Object.assign(expanded, statusAliasTokens(expanded));
|
|
978
|
+
expanded.mutedText = readableMutedText(expanded["neutral-500"] ?? "#888", base, roles);
|
|
979
|
+
for (const [token, hex] of Object.entries({ ...expanded })) {
|
|
980
|
+
if (!hex || !isOnColorBackgroundCandidateToken(token)) continue;
|
|
981
|
+
const onToken = onColorTokenName(token);
|
|
982
|
+
if (expanded[onToken]) continue;
|
|
983
|
+
expanded[onToken] = paletteInkOnSolid(hex, roles).hex;
|
|
984
|
+
}
|
|
985
|
+
Object.assign(expanded, groundMutedInkTokens(expanded));
|
|
986
|
+
return expanded;
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* The strongest tints booking and registration screens lay over a ground
|
|
990
|
+
* where secondary text sits: selected option cards, event tiles and summaries
|
|
991
|
+
* tint `primary` at 5–10% (`blocks/vars/appointment-booking.ts`,
|
|
992
|
+
* `blocks/vars/event-registration.ts`, `blocks-static/event-registration.css`),
|
|
993
|
+
* the appointment summary and hover rows tint `text`/`onSurface` at 5%, and the
|
|
994
|
+
* registration summary lays `muted` at 42%. A weaker tint of the same colour
|
|
995
|
+
* sits between the ground and these, so solving against the strongest covers it.
|
|
996
|
+
* A selected card lays its tint over its own ground, so the same list applies
|
|
997
|
+
* over the surface and over the page background that event option cards paint.
|
|
998
|
+
* A new tint under secondary text belongs here, and the CSS paints it with
|
|
999
|
+
* the ground's faded tint token (`groundTintToken`) before the colour itself;
|
|
1000
|
+
* `secondaryTextTints.test.ts` fails if the CSS lays one that isn't covered or
|
|
1001
|
+
* doesn't read that token.
|
|
1002
|
+
*/
|
|
1003
|
+
const SURFACE_SECONDARY_TEXT_TINTS = [
|
|
1004
|
+
{
|
|
1005
|
+
token: "primary",
|
|
1006
|
+
alpha: .1
|
|
1007
|
+
},
|
|
1008
|
+
{
|
|
1009
|
+
token: "text",
|
|
1010
|
+
alpha: .05
|
|
1011
|
+
},
|
|
1012
|
+
{
|
|
1013
|
+
token: "onSurface",
|
|
1014
|
+
alpha: .05
|
|
1015
|
+
},
|
|
1016
|
+
{
|
|
1017
|
+
token: "muted",
|
|
1018
|
+
alpha: .42
|
|
1019
|
+
}
|
|
1020
|
+
];
|
|
1021
|
+
/** The strongest tint alpha per colour, for the CSS that paints those tints. */
|
|
1022
|
+
const SURFACE_SECONDARY_TEXT_TINT_ALPHA = Object.fromEntries(SURFACE_SECONDARY_TEXT_TINTS.map(({ token, alpha }) => [token, alpha]));
|
|
1023
|
+
/**
|
|
1024
|
+
* The grounds booking and registration secondary text sits on, with the token
|
|
1025
|
+
* its solved muted ink is published as: the surface (panels, details) and the
|
|
1026
|
+
* page background (event registration's option, ticket and payment cards).
|
|
1027
|
+
*/
|
|
1028
|
+
const MUTED_INK_TOKENS = {
|
|
1029
|
+
surface: "onSurfaceMuted",
|
|
1030
|
+
background: "onBackgroundMuted"
|
|
1031
|
+
};
|
|
1032
|
+
/**
|
|
1033
|
+
* Secondary text on a ground, solved rather than faded from the ground's
|
|
1034
|
+
* on-colour in CSS, against the ground and every tint laid over it.
|
|
1035
|
+
*
|
|
1036
|
+
* Some palettes admit no single ink for all of them: a mid-tone surface with a
|
|
1037
|
+
* dark `primary` tint and a light `muted` one. The plain ground always has one
|
|
1038
|
+
* (black or white reads on any solid), so the ground is kept, each tint is kept
|
|
1039
|
+
* in list order while one ink still reads on everything kept so far, and the
|
|
1040
|
+
* tints that can't join are faded toward the ground until that ink reads on
|
|
1041
|
+
* them too. Fading the tint rather than giving it an ink of its own keeps every
|
|
1042
|
+
* line of text on it (titles and prices as well as secondary text) close to the
|
|
1043
|
+
* ground its colours were chosen for. Hosted palettes and the SDK bridge both
|
|
1044
|
+
* derive it here.
|
|
1045
|
+
*/
|
|
1046
|
+
function groundMutedInk(palette, ground) {
|
|
1047
|
+
const groundHex = palette[ground];
|
|
1048
|
+
if (!groundHex) return null;
|
|
1049
|
+
const preferred = palette[onColorTokenName(ground)] ?? null;
|
|
1050
|
+
const roles = paletteInkRoles(palette);
|
|
1051
|
+
const initial = {
|
|
1052
|
+
grounds: [groundHex],
|
|
1053
|
+
hex: paletteMutedInkOnSolid(groundHex, preferred, roles),
|
|
1054
|
+
uncovered: []
|
|
1055
|
+
};
|
|
1056
|
+
const solved = SURFACE_SECONDARY_TEXT_TINTS.reduce((kept, { token, alpha }) => {
|
|
1057
|
+
const tintHex = palette[token];
|
|
1058
|
+
if (!tintHex) return kept;
|
|
1059
|
+
const grounds = [...kept.grounds, compositeHex(tintHex, alpha, groundHex)];
|
|
1060
|
+
const ink = paletteMutedInk(grounds, preferred, roles);
|
|
1061
|
+
return ink.kind === "unpaintable" ? {
|
|
1062
|
+
...kept,
|
|
1063
|
+
uncovered: [...kept.uncovered, {
|
|
1064
|
+
token,
|
|
1065
|
+
alpha,
|
|
1066
|
+
tintHex
|
|
1067
|
+
}]
|
|
1068
|
+
} : {
|
|
1069
|
+
...kept,
|
|
1070
|
+
grounds,
|
|
1071
|
+
hex: ink.hex
|
|
1072
|
+
};
|
|
1073
|
+
}, initial);
|
|
1134
1074
|
return {
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
}
|
|
1075
|
+
hex: solved.hex,
|
|
1076
|
+
fadedTints: solved.uncovered.map(({ token, alpha, tintHex }) => ({
|
|
1077
|
+
token,
|
|
1078
|
+
hex: tintFadedUntilInkReads(tintHex, alpha, groundHex, solved.hex)
|
|
1079
|
+
}))
|
|
1140
1080
|
};
|
|
1141
1081
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
const currentShade = match?.[2] === void 0 ? 500 : Number(match[2]);
|
|
1146
|
-
const availableShades = [
|
|
1147
|
-
50,
|
|
1148
|
-
100,
|
|
1149
|
-
200,
|
|
1150
|
-
300,
|
|
1151
|
-
400,
|
|
1152
|
-
500,
|
|
1153
|
-
600,
|
|
1154
|
-
700,
|
|
1155
|
-
800,
|
|
1156
|
-
900,
|
|
1157
|
-
950
|
|
1158
|
-
].filter((shade) => typeof palette[`${base}-${shade}`] === "string");
|
|
1159
|
-
if (availableShades.length === 0) return token;
|
|
1160
|
-
const firstShade = availableShades[0];
|
|
1161
|
-
if (firstShade === void 0) return token;
|
|
1162
|
-
const exactIndex = availableShades.indexOf(currentShade);
|
|
1163
|
-
const startingIndex = exactIndex >= 0 ? exactIndex : availableShades.indexOf(availableShades.reduce((closestShade, shade) => Math.abs(shade - currentShade) < Math.abs(closestShade - currentShade) ? shade : closestShade, firstShade));
|
|
1164
|
-
const stepCount = Math.abs(amount) / 100;
|
|
1165
|
-
const direction = amount < 0 ? -1 : 1;
|
|
1166
|
-
const targetShade = availableShades[Math.max(0, Math.min(availableShades.length - 1, startingIndex + direction * stepCount))];
|
|
1167
|
-
return targetShade === void 0 ? token : unsafeAsOpaqueButtonColourToken(`${base}-${targetShade}`);
|
|
1082
|
+
/** The tint colour a ground publishes in place of a tint its muted ink can't read on, e.g. `surfaceTintMuted`. */
|
|
1083
|
+
function groundTintToken(ground, tint) {
|
|
1084
|
+
return `${ground}Tint${tint.charAt(0).toUpperCase()}${tint.slice(1)}`;
|
|
1168
1085
|
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1086
|
+
/**
|
|
1087
|
+
* The tint blended toward the ground in 1% steps, stopping at the first that
|
|
1088
|
+
* the ink reads on when laid at `alpha`. The ground itself always reads, since
|
|
1089
|
+
* the ink was solved on it.
|
|
1090
|
+
*/
|
|
1091
|
+
function tintFadedUntilInkReads(tintHex, alpha, groundHex, inkHex) {
|
|
1092
|
+
const tint = hexToRgb(tintHex);
|
|
1093
|
+
const ground = hexToRgb(groundHex);
|
|
1094
|
+
return Array.from({ length: 101 }, (_, index) => {
|
|
1095
|
+
const amount = index / 100;
|
|
1096
|
+
return rgbToHex(mix$1(tint.r, ground.r, amount), mix$1(tint.g, ground.g, amount), mix$1(tint.b, ground.b, amount));
|
|
1097
|
+
}).find((hex) => contrastRatio(inkHex, compositeHex(hex, alpha, groundHex)) >= 4.5) ?? groundHex;
|
|
1172
1098
|
}
|
|
1173
|
-
|
|
1174
|
-
|
|
1099
|
+
/**
|
|
1100
|
+
* The muted ink tokens a palette doesn't store itself, and the faded tint
|
|
1101
|
+
* colours of each ground whose ink is solved here, as hex.
|
|
1102
|
+
*/
|
|
1103
|
+
function groundMutedInkTokens(palette) {
|
|
1104
|
+
return Object.fromEntries(Object.entries(MUTED_INK_TOKENS).flatMap(([ground, token]) => {
|
|
1105
|
+
if (palette[token]) return [];
|
|
1106
|
+
const ink = groundMutedInk(palette, ground);
|
|
1107
|
+
if (!ink) return [];
|
|
1108
|
+
const faded = ink.fadedTints.map(({ token: tint, hex }) => [groundTintToken(ground, tint), hex]);
|
|
1109
|
+
return [[token, ink.hex], ...faded.filter(([name]) => !palette[name])];
|
|
1110
|
+
}));
|
|
1175
1111
|
}
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
}
|
|
1186
|
-
};
|
|
1112
|
+
/**
|
|
1113
|
+
* The neutral step stays when it reads on the ground. Otherwise (a dark palette
|
|
1114
|
+
* on a mid-tone ground, or a tinted light one) it's the ground-to-text blend
|
|
1115
|
+
* with a 4.5:1 floor, heading for the palette's own ink on that ground.
|
|
1116
|
+
*/
|
|
1117
|
+
function readableMutedText(step, base, roles) {
|
|
1118
|
+
const ground = base.background || base.surface;
|
|
1119
|
+
if (!ground || contrastRatio(step, ground) >= 4.5) return step;
|
|
1120
|
+
return paletteMutedInkOnSolid(ground, null, roles);
|
|
1187
1121
|
}
|
|
1188
|
-
|
|
1122
|
+
/**
|
|
1123
|
+
* Derived decoration colours never become editable palette swatches. The mark
|
|
1124
|
+
* blends toward literal black or white: it's a graphic endpoint for a 3:1
|
|
1125
|
+
* search, not text, so it stays off the palette ink rule.
|
|
1126
|
+
*/
|
|
1127
|
+
/** `backdrops` lists every colour the decorations sit on, such as each step of a radial glow. */
|
|
1128
|
+
function deriveSurfaceDecorationColors(ground, text, accent, backdrops = [ground]) {
|
|
1129
|
+
const ink = pickBlackOrWhiteTextColor(ground);
|
|
1189
1130
|
return {
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
tag: "invalid_colour_effect_options",
|
|
1193
|
-
variantId: input.variantId,
|
|
1194
|
-
state: input.state,
|
|
1195
|
-
effectId: effect.effectId,
|
|
1196
|
-
option
|
|
1197
|
-
}
|
|
1131
|
+
line: deriveSurfaceLineColor(ground, text, backdrops),
|
|
1132
|
+
mark: firstContrastBlend(accent, ink, backdrops, 3)
|
|
1198
1133
|
};
|
|
1199
1134
|
}
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
};
|
|
1135
|
+
/**
|
|
1136
|
+
* Secondary ink blended from its ground toward its text, reading at 4.5:1 over
|
|
1137
|
+
* every backdrop a sampled finish paints under it. When no blend reads on all of
|
|
1138
|
+
* them the text itself is kept (or, with no concrete text, the ink solved on
|
|
1139
|
+
* the ground alone).
|
|
1140
|
+
*/
|
|
1141
|
+
function deriveSurfaceMutedColor(ground, text, backdrops = [ground], roles = null) {
|
|
1142
|
+
const ink = paletteMutedInk([ground, ...backdrops], text, roles);
|
|
1143
|
+
if (ink.kind === "muted") return ink.hex;
|
|
1144
|
+
return text ?? paletteMutedInkOnSolid(ground, null, roles);
|
|
1211
1145
|
}
|
|
1212
|
-
|
|
1146
|
+
/** A section rule is a quiet ground-to-text blend, certified over the complete backing. */
|
|
1147
|
+
function deriveSurfaceLineColor(ground, text, backdrops = [ground]) {
|
|
1148
|
+
return firstContrastBlend(ground, text, backdrops, 1.5);
|
|
1149
|
+
}
|
|
1150
|
+
function firstContrastBlend(from, to, backdrops, threshold) {
|
|
1151
|
+
const start = hexToRgb(from);
|
|
1152
|
+
const end = hexToRgb(to);
|
|
1153
|
+
const luminances = backdrops.map((backdrop) => hexLuminance(backdrop));
|
|
1154
|
+
const paint = luminanceInterval(Math.min(...luminances), Math.max(...luminances));
|
|
1155
|
+
return Array.from({ length: 101 }, (_, index) => {
|
|
1156
|
+
const amount = index / 100;
|
|
1157
|
+
return rgbToHex(mix$1(start.r, end.r, amount), mix$1(start.g, end.g, amount), mix$1(start.b, end.b, amount));
|
|
1158
|
+
}).find((hex) => worstContrast(hexLuminance(hex), paint) >= threshold) ?? to;
|
|
1159
|
+
}
|
|
1160
|
+
/** `markSource` names the colour surface marks are derived from when a style marks in its brand rather than its accent. */
|
|
1161
|
+
function arrangementPaletteTokens(base, options) {
|
|
1162
|
+
if (options.arrangement !== true || !base.text) return {};
|
|
1213
1163
|
return {
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
tag: "unknown_button_effect",
|
|
1217
|
-
variantId: input.variantId,
|
|
1218
|
-
state: input.state,
|
|
1219
|
-
effectId: effect.effectId
|
|
1220
|
-
}
|
|
1164
|
+
onText: base.onText ?? paletteInkOnSolid(base.text, paletteInkRoles(base)).hex,
|
|
1165
|
+
...options.marksFrom === "primary" && base.primary ? { markSource: base.primary } : {}
|
|
1221
1166
|
};
|
|
1222
1167
|
}
|
|
1223
1168
|
//#endregion
|
|
1224
|
-
//#region ../
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1169
|
+
//#region ../media-core/src/identifiers.ts
|
|
1170
|
+
function slugifyMediaIdentifier(value) {
|
|
1171
|
+
return value.toLowerCase().trim().replace(/[^a-z0-9\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-");
|
|
1172
|
+
}
|
|
1173
|
+
function parseMediaIdentifier(value) {
|
|
1174
|
+
if (typeof value !== "string") return err({ kind: "not_string" });
|
|
1175
|
+
const trimmed = value.trim();
|
|
1176
|
+
if (trimmed.length === 0) return err({ kind: "empty_identifier" });
|
|
1177
|
+
const normalized = slugifyMediaIdentifier(trimmed);
|
|
1178
|
+
if (normalized.length === 0) return err({
|
|
1179
|
+
kind: "empty_after_normalization",
|
|
1180
|
+
value
|
|
1181
|
+
});
|
|
1182
|
+
return ok(normalized);
|
|
1183
|
+
}
|
|
1230
1184
|
/**
|
|
1231
|
-
*
|
|
1232
|
-
*
|
|
1233
|
-
* (`preferredToken`): those buttons rest as an outline and fill only on hover,
|
|
1234
|
-
* so the fill has to read against the ground on its own. A button edge can keep
|
|
1235
|
-
* a darker fill distinct, but it then looks like a hole in the panel.
|
|
1185
|
+
* Admits identifiers read from trusted persistence without repairing dirty data in memory.
|
|
1186
|
+
* User input should use parseMediaIdentifier, which intentionally canonicalizes it.
|
|
1236
1187
|
*/
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
const
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
/**
|
|
1251
|
-
|
|
1252
|
-
const
|
|
1253
|
-
if (
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
};
|
|
1258
|
-
|
|
1259
|
-
|
|
1188
|
+
function parseCanonicalMediaIdentifier(value) {
|
|
1189
|
+
if (typeof value !== "string") return err({ kind: "not_string" });
|
|
1190
|
+
const parsed = parseMediaIdentifier(value);
|
|
1191
|
+
if (!parsed.ok) return parsed;
|
|
1192
|
+
if (value !== parsed.value) return err({
|
|
1193
|
+
kind: "non_canonical_identifier",
|
|
1194
|
+
value,
|
|
1195
|
+
canonical: parsed.value
|
|
1196
|
+
});
|
|
1197
|
+
return parsed;
|
|
1198
|
+
}
|
|
1199
|
+
//#endregion
|
|
1200
|
+
//#region ../media-core/src/mediaIdentifierSchema.ts
|
|
1201
|
+
/** Strict stored-reference admission delegates the canonical identifier decision. */
|
|
1202
|
+
const mediaIdentifierSchema = z.string().transform((value, context) => {
|
|
1203
|
+
const parsed = parseCanonicalMediaIdentifier(value);
|
|
1204
|
+
if (parsed.ok) return parsed.value;
|
|
1205
|
+
context.addIssue({
|
|
1206
|
+
code: "custom",
|
|
1207
|
+
message: "Expected a canonical media identifier"
|
|
1208
|
+
});
|
|
1209
|
+
return z.NEVER;
|
|
1210
|
+
});
|
|
1211
|
+
//#endregion
|
|
1212
|
+
//#region ../media-core/src/mediaKinds.ts
|
|
1213
|
+
const mediaTypeDiscriminants = [
|
|
1214
|
+
"image",
|
|
1215
|
+
"video",
|
|
1216
|
+
"audio",
|
|
1217
|
+
"document",
|
|
1218
|
+
"spreadsheet",
|
|
1219
|
+
"archive"
|
|
1220
|
+
];
|
|
1221
|
+
const DISPLAY_MEDIA_KINDS = [
|
|
1222
|
+
"image",
|
|
1223
|
+
"video",
|
|
1224
|
+
"audio"
|
|
1225
|
+
];
|
|
1226
|
+
const PUBLIC_FILE_FIELD_KINDS = [
|
|
1227
|
+
"document",
|
|
1228
|
+
"spreadsheet",
|
|
1229
|
+
"archive",
|
|
1230
|
+
"audio"
|
|
1231
|
+
];
|
|
1232
|
+
function isDisplayMediaKind(kind) {
|
|
1233
|
+
return DISPLAY_MEDIA_KINDS.includes(kind);
|
|
1234
|
+
}
|
|
1235
|
+
//#endregion
|
|
1236
|
+
//#region ../media-core/src/renderableMediaAsset.ts
|
|
1237
|
+
/** Shared identifier indexing for admitted site-scoped projections. */
|
|
1238
|
+
function buildMediaIdentifierIndex(assets) {
|
|
1239
|
+
const index = new Map(assets.map((asset) => [asset.identifier, asset]));
|
|
1240
|
+
if (index.size !== assets.length) throw new Error("Duplicate media identifier in a site asset list");
|
|
1241
|
+
return index;
|
|
1242
|
+
}
|
|
1243
|
+
/** Index already admitted projections, including runtime registration updates. */
|
|
1244
|
+
function indexRenderableMediaAssets(assets) {
|
|
1245
|
+
if (!assets.length) return void 0;
|
|
1246
|
+
const byId = new Map(assets.map((asset) => [asset.id, asset]));
|
|
1247
|
+
const byIdentifier = buildMediaIdentifierIndex(assets);
|
|
1248
|
+
if (byId.size !== assets.length) throw new Error("Duplicate media asset identity in a site asset list");
|
|
1260
1249
|
return {
|
|
1250
|
+
assets,
|
|
1251
|
+
byId,
|
|
1252
|
+
byIdentifier
|
|
1253
|
+
};
|
|
1254
|
+
}
|
|
1255
|
+
/** A portable reference never uses an incidental UUID, URL or storage snapshot for identity. */
|
|
1256
|
+
function resolveManagedMediaReference(reference, index) {
|
|
1257
|
+
const asset = index?.byIdentifier.get(reference.identifier);
|
|
1258
|
+
return asset ? {
|
|
1261
1259
|
kind: "resolved",
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
} : null
|
|
1260
|
+
reference,
|
|
1261
|
+
asset
|
|
1262
|
+
} : {
|
|
1263
|
+
kind: "missing",
|
|
1264
|
+
reference
|
|
1268
1265
|
};
|
|
1269
1266
|
}
|
|
1267
|
+
//#endregion
|
|
1268
|
+
//#region ../media-core/src/renderableMediaAssetAdmission.ts
|
|
1269
|
+
const mediaAssetIdSchema = z.string().transform((value, context) => {
|
|
1270
|
+
const parsed = parseMediaAssetId(value);
|
|
1271
|
+
if (parsed.ok) return parsed.value;
|
|
1272
|
+
context.addIssue({
|
|
1273
|
+
code: "custom",
|
|
1274
|
+
message: "Expected a media asset ID"
|
|
1275
|
+
});
|
|
1276
|
+
return z.NEVER;
|
|
1277
|
+
});
|
|
1278
|
+
const nonemptyStorageValue = z.string().refine((value) => value.trim().length > 0);
|
|
1279
|
+
const renderableMediaAssetSchema = z.object({
|
|
1280
|
+
id: mediaAssetIdSchema,
|
|
1281
|
+
identifier: mediaIdentifierSchema,
|
|
1282
|
+
storageBucket: nonemptyStorageValue,
|
|
1283
|
+
storagePath: nonemptyStorageValue,
|
|
1284
|
+
mimeType: nonemptyStorageValue,
|
|
1285
|
+
filename: z.string().optional(),
|
|
1286
|
+
width: z.number().positive().nullable(),
|
|
1287
|
+
height: z.number().positive().nullable()
|
|
1288
|
+
});
|
|
1289
|
+
/** Admission precedes the identifier-only runtime resolution decision. */
|
|
1290
|
+
function buildRenderableMediaAssetIndex(assets) {
|
|
1291
|
+
if (!assets?.length) return void 0;
|
|
1292
|
+
return indexRenderableMediaAssets(assets.map((asset) => renderableMediaAssetSchema.parse(asset)));
|
|
1293
|
+
}
|
|
1294
|
+
//#endregion
|
|
1295
|
+
//#region ../media-core/src/media.ts
|
|
1296
|
+
const hotspotSchema = z.object({
|
|
1297
|
+
x: z.number().min(0).max(1),
|
|
1298
|
+
y: z.number().min(0).max(1),
|
|
1299
|
+
radius: z.number().optional()
|
|
1300
|
+
});
|
|
1301
|
+
const rotationSchema = z.union([
|
|
1302
|
+
z.literal(0),
|
|
1303
|
+
z.literal(90),
|
|
1304
|
+
z.literal(180),
|
|
1305
|
+
z.literal(270)
|
|
1306
|
+
]);
|
|
1307
|
+
const rectSchema = z.tuple([
|
|
1308
|
+
z.number(),
|
|
1309
|
+
z.number(),
|
|
1310
|
+
z.number(),
|
|
1311
|
+
z.number()
|
|
1312
|
+
]);
|
|
1313
|
+
const aspectCropSchema = z.object({
|
|
1314
|
+
aspect: z.preprocess((value) => value == null ? void 0 : value, z.string().optional()),
|
|
1315
|
+
rect: z.preprocess((value) => value == null ? void 0 : value, rectSchema.optional()),
|
|
1316
|
+
hotspot: z.preprocess((value) => value == null ? void 0 : value, hotspotSchema.optional()),
|
|
1317
|
+
rotation: z.preprocess((value) => value == null ? void 0 : value, rotationSchema.optional())
|
|
1318
|
+
});
|
|
1319
|
+
const mediaTransformSchema = z.object({
|
|
1320
|
+
aspectCrops: z.preprocess((value) => {
|
|
1321
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return;
|
|
1322
|
+
return value;
|
|
1323
|
+
}, z.record(z.string(), aspectCropSchema.catch({}))).optional(),
|
|
1324
|
+
rect: rectSchema.optional(),
|
|
1325
|
+
hotspot: hotspotSchema.optional(),
|
|
1326
|
+
rotation: rotationSchema.optional()
|
|
1327
|
+
});
|
|
1328
|
+
const mediaPosterSchema = z.discriminatedUnion("tag", [z.object({
|
|
1329
|
+
tag: z.literal("media"),
|
|
1330
|
+
identifier: mediaIdentifierSchema
|
|
1331
|
+
}).strict(), z.object({
|
|
1332
|
+
tag: z.literal("external-src"),
|
|
1333
|
+
src: z.string().url()
|
|
1334
|
+
}).strict()]);
|
|
1335
|
+
const mediaUsageShape = {
|
|
1336
|
+
purpose: z.string().optional(),
|
|
1337
|
+
placeholder: z.boolean().default(true).optional(),
|
|
1338
|
+
alt: z.string().optional(),
|
|
1339
|
+
filename: z.string().optional(),
|
|
1340
|
+
width: z.number().optional(),
|
|
1341
|
+
height: z.number().optional(),
|
|
1342
|
+
poster: mediaPosterSchema.optional(),
|
|
1343
|
+
transform: mediaTransformSchema.optional()
|
|
1344
|
+
};
|
|
1345
|
+
const environmentExclusions = {
|
|
1346
|
+
assetId: z.never().optional(),
|
|
1347
|
+
id: z.never().optional(),
|
|
1348
|
+
src: z.never().optional(),
|
|
1349
|
+
storageBucket: z.never().optional(),
|
|
1350
|
+
storagePath: z.never().optional(),
|
|
1351
|
+
mimeType: z.never().optional()
|
|
1352
|
+
};
|
|
1353
|
+
const mediaBaseSchema = z.object({
|
|
1354
|
+
...mediaUsageShape,
|
|
1355
|
+
...environmentExclusions,
|
|
1356
|
+
identifier: mediaIdentifierSchema
|
|
1357
|
+
}).strict();
|
|
1358
|
+
const imageMediaSchema = mediaBaseSchema.extend({ type: z.literal("image") });
|
|
1359
|
+
const videoMediaSchema = mediaBaseSchema.extend({ type: z.literal("video") });
|
|
1360
|
+
const mediaSchema = mediaBaseSchema.extend({ type: z.enum(mediaTypeDiscriminants) });
|
|
1361
|
+
const persistableMediaSchema = mediaSchema;
|
|
1362
|
+
const externalMediaSchema = z.object({
|
|
1363
|
+
...mediaUsageShape,
|
|
1364
|
+
...environmentExclusions,
|
|
1365
|
+
type: z.enum(mediaTypeDiscriminants),
|
|
1366
|
+
src: z.string().min(1),
|
|
1367
|
+
identifier: z.never().optional()
|
|
1368
|
+
}).strict();
|
|
1369
|
+
const assetMediaSchema = z.object({
|
|
1370
|
+
...mediaUsageShape,
|
|
1371
|
+
...environmentExclusions,
|
|
1372
|
+
type: z.enum(mediaTypeDiscriminants),
|
|
1373
|
+
asset: renderableMediaAssetSchema,
|
|
1374
|
+
identifier: z.never().optional()
|
|
1375
|
+
}).strict();
|
|
1376
|
+
const runtimeMediaSchema = z.union([
|
|
1377
|
+
mediaSchema,
|
|
1378
|
+
externalMediaSchema,
|
|
1379
|
+
assetMediaSchema
|
|
1380
|
+
]);
|
|
1381
|
+
//#endregion
|
|
1382
|
+
//#region ../theme-core/src/buttons/constants.ts
|
|
1270
1383
|
/**
|
|
1271
|
-
*
|
|
1272
|
-
*
|
|
1273
|
-
* A hover should read as the same button, stronger. The choice is made on the
|
|
1274
|
-
* colours themselves, not on shade numbers (a brand colour is rarely the 500
|
|
1275
|
-
* step of its scale). Hard limits come first: the label stays readable, the
|
|
1276
|
-
* hover stands apart from a known surface, and a button that rests filled
|
|
1277
|
-
* stays recognisably itself. `HOVER_PREFERENCE` then ranks what's left.
|
|
1384
|
+
* Shared constants for button CSS generation
|
|
1278
1385
|
*
|
|
1279
|
-
*
|
|
1280
|
-
*
|
|
1281
|
-
* stands in for "stronger".
|
|
1386
|
+
* These mappings convert Tailwind-style tokens to actual CSS values.
|
|
1387
|
+
* Centralized here to eliminate duplication across multiple files.
|
|
1282
1388
|
*/
|
|
1283
|
-
function resolveContextualHover(input) {
|
|
1284
|
-
const shades = shadeCandidates(input);
|
|
1285
|
-
if (shades.length === 0) return {
|
|
1286
|
-
kind: "unavailable",
|
|
1287
|
-
reason: "no-distinct-shade"
|
|
1288
|
-
};
|
|
1289
|
-
const readable = shades.filter((shade) => labelReadable(shade.hex, shade.labelInk, input.colourIndex));
|
|
1290
|
-
if (readable.length === 0) return {
|
|
1291
|
-
kind: "unavailable",
|
|
1292
|
-
reason: "no-text-safe-candidate"
|
|
1293
|
-
};
|
|
1294
|
-
const restLabel = seedFilledRestLabel(input.rest, input.instruction.seedToken);
|
|
1295
|
-
const selected = pickHover(readable.filter((shade) => standsApartFromSurface(shade.hex, shade.labelInk, input) && (restLabel === void 0 || staysTheSameFilledButton(shade, restLabel))));
|
|
1296
|
-
const surfaceKnown = input.surface !== void 0;
|
|
1297
|
-
if (!selected) return {
|
|
1298
|
-
kind: "unavailable",
|
|
1299
|
-
reason: surfaceKnown ? "no-surface-safe-candidate" : "no-text-safe-candidate"
|
|
1300
|
-
};
|
|
1301
|
-
return {
|
|
1302
|
-
kind: "resolved",
|
|
1303
|
-
token: selected.token,
|
|
1304
|
-
direction: selected.direction,
|
|
1305
|
-
evidence: surfaceKnown ? "known-surface" : "fallback-direction"
|
|
1306
|
-
};
|
|
1307
|
-
}
|
|
1308
|
-
const visible = (shade) => shade.distance >= MINIMUM_VISIBLE_STEP;
|
|
1309
1389
|
/**
|
|
1310
|
-
*
|
|
1311
|
-
|
|
1390
|
+
* Map Tailwind-style gradient direction tokens to CSS gradient directions
|
|
1391
|
+
*/
|
|
1392
|
+
const GRADIENT_DIRECTION_MAP = {
|
|
1393
|
+
"to-r": "to right",
|
|
1394
|
+
"to-l": "to left",
|
|
1395
|
+
"to-t": "to top",
|
|
1396
|
+
"to-b": "to bottom",
|
|
1397
|
+
"to-br": "to bottom right",
|
|
1398
|
+
"to-bl": "to bottom left",
|
|
1399
|
+
"to-tr": "to top right",
|
|
1400
|
+
"to-tl": "to top left"
|
|
1401
|
+
};
|
|
1402
|
+
/**
|
|
1403
|
+
* Map Tailwind border-radius tokens to CSS values
|
|
1404
|
+
*/
|
|
1405
|
+
const BORDER_RADIUS_MAP = {
|
|
1406
|
+
"rounded-none": "0",
|
|
1407
|
+
"rounded-3px": "3px",
|
|
1408
|
+
"rounded-10px": "10px",
|
|
1409
|
+
"rounded-sm": "0.125rem",
|
|
1410
|
+
"rounded": "0.25rem",
|
|
1411
|
+
"rounded-md": "0.375rem",
|
|
1412
|
+
"rounded-lg": "0.5rem",
|
|
1413
|
+
"rounded-xl": "0.75rem",
|
|
1414
|
+
"rounded-2xl": "1rem",
|
|
1415
|
+
"rounded-3xl": "1.5rem",
|
|
1416
|
+
"rounded-full": "9999px"
|
|
1417
|
+
};
|
|
1418
|
+
/**
|
|
1419
|
+
* Pixel offset per shadow elevation. Single source of truth shared by
|
|
1420
|
+
* `generateShadowValue` (the base box-shadow offset) and the `press-down`
|
|
1421
|
+
* effect (which translates the button by the same offset on hover). Keeping
|
|
1422
|
+
* these in one place ensures the "press into the shadow" illusion stays exact.
|
|
1423
|
+
*/
|
|
1424
|
+
const ELEVATION_OFFSET = {
|
|
1425
|
+
none: 0,
|
|
1426
|
+
low: 2,
|
|
1427
|
+
medium: 4,
|
|
1428
|
+
high: 6
|
|
1429
|
+
};
|
|
1430
|
+
/**
|
|
1431
|
+
* Generate shadow CSS value dynamically based on elevation, softness, and position
|
|
1312
1432
|
*
|
|
1313
|
-
*
|
|
1314
|
-
*
|
|
1315
|
-
*
|
|
1316
|
-
*
|
|
1317
|
-
*
|
|
1433
|
+
* This replaces the static shadow maps with a single dynamic function.
|
|
1434
|
+
* Benefits: single source of truth, easy to adjust algorithm, no redundancy.
|
|
1435
|
+
*
|
|
1436
|
+
* @param elevation - Shadow elevation level
|
|
1437
|
+
* @param softness - Shadow softness/blur style
|
|
1438
|
+
* @param position - Shadow position (bottom or bottom-right diagonal)
|
|
1439
|
+
* @returns CSS box-shadow value
|
|
1318
1440
|
*/
|
|
1319
|
-
|
|
1320
|
-
(
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1441
|
+
function generateShadowValue(elevation, softness, position = "bottom", color) {
|
|
1442
|
+
if (elevation === "none") return "none";
|
|
1443
|
+
const config = {
|
|
1444
|
+
low: {
|
|
1445
|
+
blur: 4,
|
|
1446
|
+
spread: 0
|
|
1447
|
+
},
|
|
1448
|
+
medium: {
|
|
1449
|
+
blur: 8,
|
|
1450
|
+
spread: -1
|
|
1451
|
+
},
|
|
1452
|
+
high: {
|
|
1453
|
+
blur: 12,
|
|
1454
|
+
spread: -2
|
|
1455
|
+
}
|
|
1456
|
+
}[elevation];
|
|
1457
|
+
const baseOffset = ELEVATION_OFFSET[elevation];
|
|
1458
|
+
const xOffset = position === "bottom-right" ? baseOffset : 0;
|
|
1459
|
+
const yOffset = baseOffset;
|
|
1460
|
+
switch (softness) {
|
|
1461
|
+
case null:
|
|
1462
|
+
case "soft": return `${xOffset}px ${yOffset}px ${config.blur}px ${config.spread}px ${color ?? "rgb(0 0 0 / 0.3)"}`;
|
|
1463
|
+
case "hard": return `${xOffset}px ${yOffset}px 0 0 ${color ?? "rgb(0 0 0 / 1)"}`;
|
|
1464
|
+
case "crisp": return `${xOffset}px ${yOffset}px ${baseOffset}px ${config.spread}px ${color ?? "rgb(0 0 0 / 0.4)"}`;
|
|
1330
1465
|
}
|
|
1331
1466
|
}
|
|
1332
|
-
function nearestVisibleStep(shades) {
|
|
1333
|
-
const byDistance = [...shades].sort((left, right) => left.distance - right.distance || left.token.localeCompare(right.token));
|
|
1334
|
-
return byDistance.find(visible) ?? byDistance[byDistance.length - 1];
|
|
1335
|
-
}
|
|
1336
|
-
/** The label ink of a button that rests filled with the seed; undefined when it rests some other way (it fills only on hover). */
|
|
1337
|
-
function seedFilledRestLabel(rest, seed) {
|
|
1338
|
-
return rest.kind === "solid" && rest.colorToken === seed ? rest.labelInk : void 0;
|
|
1339
|
-
}
|
|
1340
1467
|
/**
|
|
1341
|
-
*
|
|
1342
|
-
* hover. A shade that needs the other label ink is only allowed a near step
|
|
1343
|
-
* away (a jump across the scale with the label flipped looks like another
|
|
1344
|
-
* button), and a shade the other way has to keep the hue. A button that fills
|
|
1345
|
-
* only on hover changes its label anyway, so this doesn't apply to it.
|
|
1468
|
+
* Map Tailwind border-width tokens to CSS values
|
|
1346
1469
|
*/
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
}
|
|
1406
|
-
|
|
1407
|
-
|
|
1470
|
+
const BORDER_WIDTH_MAP = {
|
|
1471
|
+
"border-0": "0px",
|
|
1472
|
+
"border": "1px",
|
|
1473
|
+
"border-2": "2px",
|
|
1474
|
+
"border-4": "4px",
|
|
1475
|
+
"border-8": "8px"
|
|
1476
|
+
};
|
|
1477
|
+
/**
|
|
1478
|
+
* Map Tailwind font-size tokens to CSS values
|
|
1479
|
+
*/
|
|
1480
|
+
const FONT_SIZE_MAP = {
|
|
1481
|
+
"text-xs": "0.75rem",
|
|
1482
|
+
"text-13px": "0.8125rem",
|
|
1483
|
+
"text-15px": "0.9375rem",
|
|
1484
|
+
"text-17px": "1.0625rem",
|
|
1485
|
+
"text-19px": "1.1875rem",
|
|
1486
|
+
"text-sm": "0.875rem",
|
|
1487
|
+
"text-base": "1rem",
|
|
1488
|
+
"text-lg": "1.125rem",
|
|
1489
|
+
"text-xl": "1.25rem",
|
|
1490
|
+
"text-2xl": "1.5rem"
|
|
1491
|
+
};
|
|
1492
|
+
/**
|
|
1493
|
+
* System defaults used when a theme doesn't supply its own `theme.buttons.sizes`.
|
|
1494
|
+
*
|
|
1495
|
+
* Every size is defined so the size class CSS always emits a complete rule and
|
|
1496
|
+
* variants are never naked. Referenced by `generateButtonCss` and surfaceable
|
|
1497
|
+
* from UI ("Showing default size ramp") without duplicating the values.
|
|
1498
|
+
*/
|
|
1499
|
+
const DEFAULT_BUTTON_SIZES = {
|
|
1500
|
+
sm: {
|
|
1501
|
+
padding: "0.5rem 1rem",
|
|
1502
|
+
fontSize: "text-sm"
|
|
1503
|
+
},
|
|
1504
|
+
md: { padding: "0.75rem 1.5rem" },
|
|
1505
|
+
lg: {
|
|
1506
|
+
padding: "1rem 2rem",
|
|
1507
|
+
fontSize: "text-lg"
|
|
1508
|
+
},
|
|
1509
|
+
xl: {
|
|
1510
|
+
padding: "1.25rem 2.5rem",
|
|
1511
|
+
fontSize: "text-xl"
|
|
1512
|
+
}
|
|
1513
|
+
};
|
|
1514
|
+
//#endregion
|
|
1515
|
+
//#region ../theme-core/src/buttons/buttonColourContract.ts
|
|
1516
|
+
const BUTTON_CONTRAST_POLICY = {
|
|
1517
|
+
textMinimumRatio: 4.5,
|
|
1518
|
+
nonTextMinimumRatio: 3,
|
|
1519
|
+
filledMinimumDeltaE: .12,
|
|
1520
|
+
gradientSamplesPerSegment: 20,
|
|
1521
|
+
alphaBackgrounds: "reject-without-known-surface",
|
|
1522
|
+
disabled: "validated-colour-pair-with-muted-control-opacity"
|
|
1523
|
+
};
|
|
1524
|
+
function formatButtonColourContractError(error) {
|
|
1525
|
+
switch (error.tag) {
|
|
1526
|
+
case "unknown_palette_token": return `Button "${error.variantId}" ${error.state} state uses unknown palette token "${error.token}".`;
|
|
1527
|
+
case "insufficient_contrast": return `Button "${error.variantId}" ${error.state} state has ${error.ratio.toFixed(2)}:1 contrast (${error.requiredRatio}:1 required).`;
|
|
1528
|
+
case "insufficient_surface_separation": return `Button "${error.variantId}" ${error.state} state is indistinguishable from its surface at OKLab distance ${error.deltaE.toFixed(3)} (${error.requiredDeltaE} required).`;
|
|
1529
|
+
case "unsupported_colour_effect": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" is not contrast-safe (${error.reason}).`;
|
|
1530
|
+
case "invalid_colour_effect_options": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" has an invalid ${error.option} option.`;
|
|
1531
|
+
case "inapplicable_colour_effect": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" cannot apply to a ${error.treatment} treatment.`;
|
|
1532
|
+
case "unknown_button_effect": return `Button "${error.variantId}" ${error.state} uses unknown effect "${error.effectId}".`;
|
|
1533
|
+
}
|
|
1408
1534
|
}
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
const
|
|
1535
|
+
/** One separation decision for filled states and contextual hover candidates. */
|
|
1536
|
+
function buttonFillSeparation(fill, ground) {
|
|
1537
|
+
const deltaE = hexOklabDistance(fill, ground);
|
|
1412
1538
|
return {
|
|
1413
|
-
|
|
1414
|
-
|
|
1539
|
+
deltaE,
|
|
1540
|
+
distinct: deltaE >= BUTTON_CONTRAST_POLICY.filledMinimumDeltaE
|
|
1415
1541
|
};
|
|
1416
1542
|
}
|
|
1417
|
-
|
|
1418
|
-
|
|
1543
|
+
/** All paint beneath the control; ordinary solids have just one ground. */
|
|
1544
|
+
const buttonSurfaceGrounds = (surface) => [surface.backgroundHex, ...surface.backgroundSamples ?? []];
|
|
1545
|
+
/** A filled state clears each ground by its fill OR a declared edge at 3:1. */
|
|
1546
|
+
function buttonSurfaceSeparation(fill, surface, edge) {
|
|
1547
|
+
return buttonGroundSeparation(fill, buttonSurfaceGrounds(surface), edge);
|
|
1419
1548
|
}
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
const
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
rest: input.rest
|
|
1431
|
-
});
|
|
1432
|
-
if (contextual.kind === "resolved") return {
|
|
1433
|
-
treatment: {
|
|
1434
|
-
type: "solid",
|
|
1435
|
-
colorToken: contextual.token
|
|
1436
|
-
},
|
|
1437
|
-
repair: contextual.repair
|
|
1549
|
+
/** The worst ground for a fill: the first it fails to stand out from, otherwise the closest. */
|
|
1550
|
+
function buttonGroundSeparation(fill, grounds, edge) {
|
|
1551
|
+
const ink = edge?.border?.marksBoundary ? edge.border.boundaryInk ? resolveConcreteColorHex(edge.border.boundaryInk, edge.palette) ?? void 0 : edge.labelInk : void 0;
|
|
1552
|
+
return grounds.map((ground) => {
|
|
1553
|
+
const separation = buttonFillSeparation(fill, ground);
|
|
1554
|
+
const distinct = separation.distinct || ink !== void 0 && contrastRatio(ink, ground) >= BUTTON_CONTRAST_POLICY.nonTextMinimumRatio;
|
|
1555
|
+
return {
|
|
1556
|
+
...separation,
|
|
1557
|
+
distinct,
|
|
1558
|
+
ground
|
|
1438
1559
|
};
|
|
1439
|
-
}
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
type: "solid",
|
|
1444
|
-
colorToken: token
|
|
1445
|
-
},
|
|
1446
|
-
repair: null
|
|
1447
|
-
};
|
|
1560
|
+
}).reduce((worst, next) => {
|
|
1561
|
+
if (worst.distinct !== next.distinct) return worst.distinct ? next : worst;
|
|
1562
|
+
return next.deltaE < worst.deltaE ? next : worst;
|
|
1563
|
+
});
|
|
1448
1564
|
}
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1565
|
+
function validateButtonFillSeparation(input) {
|
|
1566
|
+
const token = input.border?.marksBoundary ? input.border.boundaryInk : void 0;
|
|
1567
|
+
if (token && !resolveConcreteColorHex(token, input.palette)) return {
|
|
1568
|
+
ok: false,
|
|
1569
|
+
error: {
|
|
1570
|
+
tag: "unknown_palette_token",
|
|
1571
|
+
variantId: input.variantId,
|
|
1572
|
+
state: input.state,
|
|
1573
|
+
token
|
|
1574
|
+
}
|
|
1575
|
+
};
|
|
1576
|
+
const separation = buttonSurfaceSeparation(input.buttonPaint, input.surface, input);
|
|
1577
|
+
return separation.distinct ? { ok: true } : {
|
|
1578
|
+
ok: false,
|
|
1579
|
+
error: {
|
|
1580
|
+
tag: "insufficient_surface_separation",
|
|
1581
|
+
variantId: input.variantId,
|
|
1582
|
+
state: input.state,
|
|
1583
|
+
buttonPaint: input.buttonPaint,
|
|
1584
|
+
surface: separation.ground,
|
|
1585
|
+
deltaE: separation.deltaE,
|
|
1586
|
+
requiredDeltaE: BUTTON_CONTRAST_POLICY.filledMinimumDeltaE
|
|
1587
|
+
}
|
|
1458
1588
|
};
|
|
1459
1589
|
}
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
});
|
|
1475
|
-
if (!base.ok) return base;
|
|
1476
|
-
const hover = resolveButtonHoverTreatment({
|
|
1477
|
-
variant: input.variant,
|
|
1478
|
-
global: input.global,
|
|
1479
|
-
fallback: base.treatment,
|
|
1480
|
-
rest: restingFill({
|
|
1481
|
-
...input,
|
|
1482
|
-
variantId: input.variant.id,
|
|
1483
|
-
state: "base"
|
|
1484
|
-
}, base.treatment),
|
|
1485
|
-
palette: input.palette,
|
|
1486
|
-
surface: input.surface,
|
|
1487
|
-
colourIndex: input.colourIndex
|
|
1488
|
-
});
|
|
1489
|
-
const colours = collectStateColours(mapVisualStates((state) => compileVisualState(input, state, state === "hover" ? hover.treatment : base.treatment, base.nonColourEffects)));
|
|
1490
|
-
return colours.ok ? {
|
|
1491
|
-
...colours,
|
|
1492
|
-
contextualHoverRepair: hover.repair
|
|
1493
|
-
} : colours;
|
|
1590
|
+
function validateButtonTextContrast(input) {
|
|
1591
|
+
const ratio = contrastRatio(input.backgroundHex, input.foregroundHex, input.colourIndex);
|
|
1592
|
+
return ratio >= BUTTON_CONTRAST_POLICY.textMinimumRatio ? { ok: true } : {
|
|
1593
|
+
ok: false,
|
|
1594
|
+
error: {
|
|
1595
|
+
tag: "insufficient_contrast",
|
|
1596
|
+
variantId: input.variantId,
|
|
1597
|
+
state: input.state,
|
|
1598
|
+
background: input.background,
|
|
1599
|
+
foreground: input.foreground,
|
|
1600
|
+
ratio,
|
|
1601
|
+
requiredRatio: BUTTON_CONTRAST_POLICY.textMinimumRatio
|
|
1602
|
+
}
|
|
1603
|
+
};
|
|
1494
1604
|
}
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
variant: {
|
|
1499
|
-
...input.variant,
|
|
1500
|
-
contextualHover: states.hover.contextualHover,
|
|
1501
|
-
border: buttonStateBorder(input.variant, "hover"),
|
|
1502
|
-
hoverBackgroundToken: void 0
|
|
1503
|
-
},
|
|
1504
|
-
global: {
|
|
1505
|
-
...input.global,
|
|
1506
|
-
hoverColor: "none",
|
|
1507
|
-
hoverColorToken: void 0
|
|
1508
|
-
},
|
|
1509
|
-
fallback: states.hover.background,
|
|
1510
|
-
rest: restingFill({
|
|
1511
|
-
...input,
|
|
1512
|
-
variantId: input.variant.id,
|
|
1513
|
-
state: "base"
|
|
1514
|
-
}, states.base.background)
|
|
1515
|
-
});
|
|
1516
|
-
const colours = collectStateColours(mapVisualStates((state) => compileDeclaredVisualState(input, states, state, state === "hover" ? hover.treatment : states[state].background)));
|
|
1517
|
-
return colours.ok ? {
|
|
1518
|
-
...colours,
|
|
1519
|
-
focusIndicator: states.focus.indicator ? {
|
|
1520
|
-
kind: "surface-role",
|
|
1521
|
-
colorCss: input.surface?.foregroundCss ?? surfaceForegroundValue("text"),
|
|
1522
|
-
width: states.focus.indicator.width,
|
|
1523
|
-
offset: states.focus.indicator.offset,
|
|
1524
|
-
minimumSurfaceContrast: BUTTON_CONTRAST_POLICY.nonTextMinimumRatio
|
|
1525
|
-
} : colours.focusIndicator,
|
|
1526
|
-
contextualHoverRepair: hover.repair
|
|
1527
|
-
} : colours;
|
|
1605
|
+
/** A text-token slab inverts the palette's text/background pair, including text shades. */
|
|
1606
|
+
function solidForegroundToken(backgroundToken) {
|
|
1607
|
+
return /^text(?:-\d+)?$/.test(backgroundToken) ? "background" : onColorTokenName(backgroundToken);
|
|
1528
1608
|
}
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1609
|
+
//#endregion
|
|
1610
|
+
//#region ../theme-core/src/buttons/effectClassification.ts
|
|
1611
|
+
/**
|
|
1612
|
+
* Exhaustive live policy for every registered effect id.
|
|
1613
|
+
*
|
|
1614
|
+
* The resolver consumes the transition payload directly, so adding an effect
|
|
1615
|
+
* cannot update classification without also defining its runtime behavior.
|
|
1616
|
+
*/
|
|
1617
|
+
const BUTTON_EFFECT_POLICIES = {
|
|
1618
|
+
"darken-background": {
|
|
1619
|
+
classification: "colour-transition",
|
|
1620
|
+
transition: {
|
|
1621
|
+
kind: "adjust-shade",
|
|
1622
|
+
direction: "darker"
|
|
1623
|
+
}
|
|
1624
|
+
},
|
|
1625
|
+
"lighten-background": {
|
|
1626
|
+
classification: "colour-transition",
|
|
1627
|
+
transition: {
|
|
1628
|
+
kind: "adjust-shade",
|
|
1629
|
+
direction: "lighter"
|
|
1630
|
+
}
|
|
1631
|
+
},
|
|
1632
|
+
"background-on-hover": {
|
|
1633
|
+
classification: "colour-transition",
|
|
1634
|
+
transition: { kind: "replace-background" }
|
|
1635
|
+
},
|
|
1636
|
+
"background-on-hover-alpha": {
|
|
1637
|
+
classification: "unsupported-colour",
|
|
1638
|
+
reason: "alpha_requires_surface"
|
|
1639
|
+
},
|
|
1640
|
+
"fade-background": {
|
|
1641
|
+
classification: "unsupported-colour",
|
|
1642
|
+
reason: "changes_element_opacity"
|
|
1643
|
+
},
|
|
1644
|
+
"opacity-reduce": {
|
|
1645
|
+
classification: "unsupported-colour",
|
|
1646
|
+
reason: "changes_element_opacity"
|
|
1647
|
+
},
|
|
1648
|
+
"gradient-text": {
|
|
1649
|
+
classification: "unsupported-colour",
|
|
1650
|
+
reason: "changes_foreground"
|
|
1651
|
+
},
|
|
1652
|
+
"text-color-change": {
|
|
1653
|
+
classification: "unsupported-colour",
|
|
1654
|
+
reason: "changes_foreground"
|
|
1655
|
+
},
|
|
1656
|
+
"border-color-change": {
|
|
1657
|
+
classification: "unsupported-colour",
|
|
1658
|
+
reason: "changes_border"
|
|
1659
|
+
},
|
|
1660
|
+
"aurora-glow": {
|
|
1661
|
+
classification: "unsupported-background-overlay",
|
|
1662
|
+
reason: "unresolved_background_overlay"
|
|
1663
|
+
},
|
|
1664
|
+
"cosmic-stardust": {
|
|
1665
|
+
classification: "unsupported-background-overlay",
|
|
1666
|
+
reason: "unresolved_background_overlay"
|
|
1667
|
+
},
|
|
1668
|
+
"gradient-border-fill": {
|
|
1669
|
+
classification: "unsupported-background-overlay",
|
|
1670
|
+
reason: "unresolved_background_overlay"
|
|
1671
|
+
},
|
|
1672
|
+
"animated-gradient-border-fill": {
|
|
1673
|
+
classification: "unsupported-background-overlay",
|
|
1674
|
+
reason: "unresolved_background_overlay"
|
|
1675
|
+
},
|
|
1676
|
+
"nav-underline": {
|
|
1677
|
+
classification: "not-button",
|
|
1678
|
+
reason: "not_button_effect"
|
|
1679
|
+
},
|
|
1680
|
+
"nav-frosted-base": {
|
|
1681
|
+
classification: "not-button",
|
|
1682
|
+
reason: "not_button_effect"
|
|
1683
|
+
},
|
|
1684
|
+
"nav-frosted-hover": {
|
|
1685
|
+
classification: "not-button",
|
|
1686
|
+
reason: "not_button_effect"
|
|
1687
|
+
},
|
|
1688
|
+
"nav-frosted-active": {
|
|
1689
|
+
classification: "not-button",
|
|
1690
|
+
reason: "not_button_effect"
|
|
1691
|
+
},
|
|
1692
|
+
"animated-gradient": { classification: "non-colour" },
|
|
1693
|
+
"border-glow": {
|
|
1694
|
+
classification: "unsupported-colour",
|
|
1695
|
+
reason: "changes_shadow_colour"
|
|
1696
|
+
},
|
|
1697
|
+
"drop-shadow": { classification: "decorative-colour" },
|
|
1698
|
+
"inner-shadow": { classification: "decorative-colour" },
|
|
1699
|
+
"neumorphic-shadow": { classification: "decorative-colour" },
|
|
1700
|
+
"outer-glow": {
|
|
1701
|
+
classification: "unsupported-colour",
|
|
1702
|
+
reason: "changes_shadow_colour"
|
|
1703
|
+
},
|
|
1704
|
+
"retro-3d-shadow": { classification: "decorative-colour" },
|
|
1705
|
+
"scale-up": { classification: "non-colour" },
|
|
1706
|
+
"scale-down": { classification: "non-colour" },
|
|
1707
|
+
lift: { classification: "non-colour" },
|
|
1708
|
+
"press-down": { classification: "non-colour" },
|
|
1709
|
+
pop: { classification: "non-colour" },
|
|
1710
|
+
"border-bottom-grow": { classification: "non-colour" },
|
|
1711
|
+
"sketchy-border": { classification: "decorative-colour" },
|
|
1712
|
+
"inner-dashed-outline": { classification: "decorative-colour" },
|
|
1713
|
+
"pulse-animation": {
|
|
1714
|
+
classification: "unsupported-colour",
|
|
1715
|
+
reason: "changes_element_opacity"
|
|
1716
|
+
}
|
|
1717
|
+
};
|
|
1718
|
+
function validateButtonEffectOptions(effect) {
|
|
1719
|
+
const parsed = buttonEffectApplicationSchema.safeParse(effect);
|
|
1720
|
+
if (parsed.success) return { ok: true };
|
|
1721
|
+
const firstIssue = parsed.error.issues[0];
|
|
1722
|
+
const firstPathPart = firstIssue?.path[firstIssue.path.length - 1];
|
|
1723
|
+
return {
|
|
1724
|
+
ok: false,
|
|
1725
|
+
option: (firstIssue?.code === "unrecognized_keys" ? firstIssue.keys[0] : void 0) ?? (typeof firstPathPart === "string" ? firstPathPart : "options")
|
|
1726
|
+
};
|
|
1553
1727
|
}
|
|
1554
|
-
function
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
}) : {
|
|
1728
|
+
function getButtonEffectPolicy(effectId) {
|
|
1729
|
+
return Object.prototype.hasOwnProperty.call(BUTTON_EFFECT_POLICIES, effectId) ? BUTTON_EFFECT_POLICIES[effectId] : null;
|
|
1730
|
+
}
|
|
1731
|
+
//#endregion
|
|
1732
|
+
//#region ../theme-core/src/buttons/buttonColourTransitions.ts
|
|
1733
|
+
function applyColourEffects(input) {
|
|
1734
|
+
return (input.effects ?? []).reduce((current, effect) => current.ok ? applyEffect(input, current, effect) : current, {
|
|
1562
1735
|
ok: true,
|
|
1563
|
-
treatment,
|
|
1564
|
-
nonColourEffects:
|
|
1565
|
-
};
|
|
1566
|
-
if (!transition.ok) return transition;
|
|
1567
|
-
const resolved = resolveTreatment({
|
|
1568
|
-
variantId: input.variant.id,
|
|
1569
|
-
state,
|
|
1570
|
-
treatment: transition.treatment,
|
|
1571
|
-
palette: input.palette,
|
|
1572
|
-
surface: input.surface,
|
|
1573
|
-
colourIndex: input.colourIndex,
|
|
1574
|
-
border: buttonStateBorder(input.variant, state)
|
|
1736
|
+
treatment: input.treatment,
|
|
1737
|
+
nonColourEffects: []
|
|
1575
1738
|
});
|
|
1576
|
-
return resolved.ok ? {
|
|
1577
|
-
...resolved,
|
|
1578
|
-
nonColourEffects: transition.nonColourEffects
|
|
1579
|
-
} : resolved;
|
|
1580
1739
|
}
|
|
1581
|
-
function
|
|
1582
|
-
|
|
1583
|
-
if (
|
|
1584
|
-
if (
|
|
1585
|
-
|
|
1586
|
-
if (!
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
focus: results.focus.colour,
|
|
1591
|
-
active: results.active.colour,
|
|
1592
|
-
disabled: results.disabled.colour
|
|
1593
|
-
};
|
|
1594
|
-
return {
|
|
1595
|
-
ok: true,
|
|
1596
|
-
states,
|
|
1597
|
-
focusIndicator: resolveFocusIndicator(states.focus),
|
|
1598
|
-
nonColourEffects: Object.fromEntries(Object.entries(results).flatMap(([state, result]) => result.ok && result.nonColourEffects.length > 0 ? [[state, [...result.nonColourEffects]]] : []))
|
|
1740
|
+
function applyEffect(input, current, effect) {
|
|
1741
|
+
const policy = getButtonEffectPolicy(effect.effectId);
|
|
1742
|
+
if (policy === null) return unknownEffect(input, effect);
|
|
1743
|
+
if (policy.classification === "unsupported-colour" || policy.classification === "unsupported-background-overlay" || policy.classification === "not-button") return unsupportedEffect(input, effect, policy.reason);
|
|
1744
|
+
const options = validateButtonEffectOptions(effect);
|
|
1745
|
+
if (!options.ok) return invalidEffectOption(input, effect, options.option);
|
|
1746
|
+
return policy.classification === "colour-transition" ? transitionColour(input, current, effect) : {
|
|
1747
|
+
...current,
|
|
1748
|
+
nonColourEffects: [...current.nonColourEffects, effect]
|
|
1599
1749
|
};
|
|
1600
1750
|
}
|
|
1601
|
-
function
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
background: "surface",
|
|
1610
|
-
backgroundHex,
|
|
1611
|
-
foreground: "surface-foreground",
|
|
1612
|
-
foregroundHex: surface.foregroundHex
|
|
1613
|
-
})).find((result) => !result.ok) ?? { ok: true };
|
|
1614
|
-
if (!foreground.ok) return foreground;
|
|
1751
|
+
function transitionColour(input, current, effect) {
|
|
1752
|
+
if (effect.effectId === "background-on-hover") {
|
|
1753
|
+
const colorToken = readOpaqueToken(effect);
|
|
1754
|
+
return colorToken === null ? invalidEffectOption(input, effect, "colorToken") : {
|
|
1755
|
+
...current,
|
|
1756
|
+
treatment: {
|
|
1757
|
+
type: "solid",
|
|
1758
|
+
colorToken
|
|
1615
1759
|
}
|
|
1616
|
-
return {
|
|
1617
|
-
ok: true,
|
|
1618
|
-
colour: {
|
|
1619
|
-
kind: "surface",
|
|
1620
|
-
role: treatment.role,
|
|
1621
|
-
backgroundCss: "transparent",
|
|
1622
|
-
foregroundCss: input.surface?.foregroundCss ?? surfaceForegroundValue(treatment.role)
|
|
1623
|
-
}
|
|
1624
|
-
};
|
|
1625
|
-
case "solid": return resolveSolid(input, treatment.colorToken, treatment.foregroundToken);
|
|
1626
|
-
case "gradient": return resolveGradient(input, treatment);
|
|
1627
|
-
}
|
|
1628
|
-
}
|
|
1629
|
-
function resolveFocusIndicator(colour) {
|
|
1630
|
-
switch (colour.kind) {
|
|
1631
|
-
case "solid":
|
|
1632
|
-
case "known-solid": return {
|
|
1633
|
-
kind: "two-tone",
|
|
1634
|
-
innerCss: colour.foregroundCss,
|
|
1635
|
-
outerCss: colour.backgroundCss,
|
|
1636
|
-
minimumPairContrast: BUTTON_CONTRAST_POLICY.textMinimumRatio
|
|
1637
|
-
};
|
|
1638
|
-
case "gradient": return {
|
|
1639
|
-
kind: "two-tone",
|
|
1640
|
-
innerCss: colour.foregroundCss,
|
|
1641
|
-
outerCss: tokenCss(colour.backgroundTokens[0]),
|
|
1642
|
-
minimumPairContrast: BUTTON_CONTRAST_POLICY.textMinimumRatio
|
|
1643
|
-
};
|
|
1644
|
-
case "surface": return {
|
|
1645
|
-
kind: "surface-role",
|
|
1646
|
-
colorCss: colour.foregroundCss,
|
|
1647
|
-
minimumSurfaceContrast: BUTTON_CONTRAST_POLICY.nonTextMinimumRatio
|
|
1648
1760
|
};
|
|
1649
1761
|
}
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
const
|
|
1653
|
-
if (
|
|
1654
|
-
const ink = resolveSolidInk(input, backgroundToken, backgroundHex.hex, preferredForeground);
|
|
1655
|
-
const boundary = input.surface ? validateButtonFillSeparation({
|
|
1656
|
-
...input,
|
|
1657
|
-
buttonPaint: backgroundHex.hex,
|
|
1658
|
-
surface: input.surface,
|
|
1659
|
-
labelInk: ink.foregroundHex
|
|
1660
|
-
}) : { ok: true };
|
|
1661
|
-
if (!boundary.ok) return boundary;
|
|
1762
|
+
if (effect.effectId !== "darken-background" && effect.effectId !== "lighten-background") return unknownEffect(input, effect);
|
|
1763
|
+
if (current.treatment.type !== "solid") return inapplicableEffect(input, effect, current.treatment);
|
|
1764
|
+
const amount = readShadeAmount(effect);
|
|
1765
|
+
if (amount === null) return invalidEffectOption(input, effect, "amount");
|
|
1662
1766
|
return {
|
|
1663
|
-
|
|
1664
|
-
|
|
1767
|
+
...current,
|
|
1768
|
+
treatment: {
|
|
1769
|
+
type: "solid",
|
|
1770
|
+
colorToken: adjustShade(current.treatment.colorToken, effect.effectId === "darken-background" ? amount : -amount, input.palette)
|
|
1771
|
+
}
|
|
1665
1772
|
};
|
|
1666
1773
|
}
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1774
|
+
function adjustShade(token, amount, palette) {
|
|
1775
|
+
const match = token.match(/^(.*)-(\d{2,3})$/);
|
|
1776
|
+
const base = match?.[1] ?? token;
|
|
1777
|
+
const currentShade = match?.[2] === void 0 ? 500 : Number(match[2]);
|
|
1778
|
+
const availableShades = [
|
|
1779
|
+
50,
|
|
1780
|
+
100,
|
|
1781
|
+
200,
|
|
1782
|
+
300,
|
|
1783
|
+
400,
|
|
1784
|
+
500,
|
|
1785
|
+
600,
|
|
1786
|
+
700,
|
|
1787
|
+
800,
|
|
1788
|
+
900,
|
|
1789
|
+
950
|
|
1790
|
+
].filter((shade) => typeof palette[`${base}-${shade}`] === "string");
|
|
1791
|
+
if (availableShades.length === 0) return token;
|
|
1792
|
+
const firstShade = availableShades[0];
|
|
1793
|
+
if (firstShade === void 0) return token;
|
|
1794
|
+
const exactIndex = availableShades.indexOf(currentShade);
|
|
1795
|
+
const startingIndex = exactIndex >= 0 ? exactIndex : availableShades.indexOf(availableShades.reduce((closestShade, shade) => Math.abs(shade - currentShade) < Math.abs(closestShade - currentShade) ? shade : closestShade, firstShade));
|
|
1796
|
+
const stepCount = Math.abs(amount) / 100;
|
|
1797
|
+
const direction = amount < 0 ? -1 : 1;
|
|
1798
|
+
const targetShade = availableShades[Math.max(0, Math.min(availableShades.length - 1, startingIndex + direction * stepCount))];
|
|
1799
|
+
return targetShade === void 0 ? token : unsafeAsOpaqueButtonColourToken(`${base}-${targetShade}`);
|
|
1674
1800
|
}
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
const hex = input.palette[treatment.colorToken];
|
|
1679
|
-
if (hex === void 0) return { kind: "not-solid" };
|
|
1680
|
-
const ink = resolveSolidInk(input, treatment.colorToken, hex, treatment.foregroundToken);
|
|
1681
|
-
return {
|
|
1682
|
-
kind: "solid",
|
|
1683
|
-
colorToken: treatment.colorToken,
|
|
1684
|
-
labelInk: ink.foregroundHex
|
|
1685
|
-
};
|
|
1801
|
+
function readShadeAmount(effect) {
|
|
1802
|
+
const value = effect.options?.amount ?? 100;
|
|
1803
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value % 100 === 0 ? value : null;
|
|
1686
1804
|
}
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
if (preferredForeground !== void 0) {
|
|
1690
|
-
const preferred = checkedSolidInk(input, backgroundToken, backgroundHex, preferredForeground);
|
|
1691
|
-
if (preferred) return preferred;
|
|
1692
|
-
}
|
|
1693
|
-
return checkedSolidInk(input, backgroundToken, backgroundHex, unsafeAsOpaqueButtonColourToken(solidForegroundToken(backgroundToken))) ?? paletteSolidInk(input, backgroundToken, backgroundHex);
|
|
1805
|
+
function readOpaqueToken(effect) {
|
|
1806
|
+
return parseOpaqueButtonColourToken(effect.options?.colorToken ?? "neutral-800");
|
|
1694
1807
|
}
|
|
1695
|
-
function
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
foregroundHex: candidate,
|
|
1705
|
-
colour: {
|
|
1706
|
-
kind: "solid",
|
|
1707
|
-
backgroundToken,
|
|
1708
|
-
foregroundToken,
|
|
1709
|
-
backgroundCss: tokenCss(backgroundToken),
|
|
1710
|
-
foregroundCss: tokenCss(foregroundToken)
|
|
1808
|
+
function unsupportedEffect(input, effect, reason) {
|
|
1809
|
+
return {
|
|
1810
|
+
ok: false,
|
|
1811
|
+
error: {
|
|
1812
|
+
tag: "unsupported_colour_effect",
|
|
1813
|
+
variantId: input.variantId,
|
|
1814
|
+
state: input.state,
|
|
1815
|
+
effectId: effect.effectId,
|
|
1816
|
+
reason
|
|
1711
1817
|
}
|
|
1712
1818
|
};
|
|
1713
|
-
return null;
|
|
1714
1819
|
}
|
|
1715
|
-
|
|
1716
|
-
function paletteSolidInk(input, backgroundToken, backgroundHex) {
|
|
1717
|
-
const ink = paletteInkOnSolid(backgroundHex, paletteInkRoles(input.palette));
|
|
1718
|
-
const role = ink.kind === "role" ? checkedSolidInk(input, backgroundToken, backgroundHex, unsafeAsOpaqueButtonColourToken(ink.role)) : null;
|
|
1719
|
-
if (role) return role;
|
|
1720
|
-
const literal = pickBlackOrWhiteTextColor(backgroundHex);
|
|
1820
|
+
function invalidEffectOption(input, effect, option) {
|
|
1721
1821
|
return {
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1822
|
+
ok: false,
|
|
1823
|
+
error: {
|
|
1824
|
+
tag: "invalid_colour_effect_options",
|
|
1825
|
+
variantId: input.variantId,
|
|
1826
|
+
state: input.state,
|
|
1827
|
+
effectId: effect.effectId,
|
|
1828
|
+
option
|
|
1727
1829
|
}
|
|
1728
1830
|
};
|
|
1729
1831
|
}
|
|
1730
|
-
function
|
|
1731
|
-
const foregroundHex = paletteHex(input, treatment.foregroundToken);
|
|
1732
|
-
if (!foregroundHex.ok) return foregroundHex;
|
|
1733
|
-
const stopHexes = [];
|
|
1734
|
-
for (const token of treatment.stops) {
|
|
1735
|
-
const stop = paletteHex(input, token);
|
|
1736
|
-
if (!stop.ok) return stop;
|
|
1737
|
-
stopHexes.push(stop.hex);
|
|
1738
|
-
}
|
|
1739
|
-
for (let segment = 0; segment < stopHexes.length - 1; segment += 1) {
|
|
1740
|
-
const start = stopHexes[segment];
|
|
1741
|
-
const end = stopHexes[segment + 1];
|
|
1742
|
-
const startToken = treatment.stops[segment];
|
|
1743
|
-
const endToken = treatment.stops[segment + 1];
|
|
1744
|
-
if (start === void 0 || end === void 0 || startToken === void 0 || endToken === void 0) continue;
|
|
1745
|
-
for (let sample = 0; sample <= BUTTON_CONTRAST_POLICY.gradientSamplesPerSegment; sample += 1) {
|
|
1746
|
-
const position = sample / BUTTON_CONTRAST_POLICY.gradientSamplesPerSegment;
|
|
1747
|
-
const sampleHex = interpolateHex(start, end, position);
|
|
1748
|
-
const contrast = validateButtonTextContrast({
|
|
1749
|
-
...input,
|
|
1750
|
-
background: `${startToken}→${endToken}@${position.toFixed(2)}`,
|
|
1751
|
-
backgroundHex: sampleHex,
|
|
1752
|
-
foreground: treatment.foregroundToken,
|
|
1753
|
-
foregroundHex: foregroundHex.hex
|
|
1754
|
-
});
|
|
1755
|
-
if (!contrast.ok) return contrast;
|
|
1756
|
-
if (input.surface) {
|
|
1757
|
-
const boundary = validateButtonFillSeparation({
|
|
1758
|
-
...input,
|
|
1759
|
-
buttonPaint: sampleHex,
|
|
1760
|
-
labelInk: foregroundHex.hex,
|
|
1761
|
-
surface: input.surface
|
|
1762
|
-
});
|
|
1763
|
-
if (!boundary.ok) return boundary;
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
}
|
|
1767
|
-
const direction = GRADIENT_DIRECTION_MAP[treatment.direction] ?? "to right";
|
|
1832
|
+
function inapplicableEffect(input, effect, treatment) {
|
|
1768
1833
|
return {
|
|
1769
|
-
ok:
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1834
|
+
ok: false,
|
|
1835
|
+
error: {
|
|
1836
|
+
tag: "inapplicable_colour_effect",
|
|
1837
|
+
variantId: input.variantId,
|
|
1838
|
+
state: input.state,
|
|
1839
|
+
effectId: effect.effectId,
|
|
1840
|
+
treatment: treatment.type
|
|
1776
1841
|
}
|
|
1777
1842
|
};
|
|
1778
1843
|
}
|
|
1779
|
-
function
|
|
1780
|
-
|
|
1781
|
-
return typeof hex === "string" ? {
|
|
1782
|
-
ok: true,
|
|
1783
|
-
hex
|
|
1784
|
-
} : {
|
|
1844
|
+
function unknownEffect(input, effect) {
|
|
1845
|
+
return {
|
|
1785
1846
|
ok: false,
|
|
1786
1847
|
error: {
|
|
1787
|
-
tag: "
|
|
1848
|
+
tag: "unknown_button_effect",
|
|
1788
1849
|
variantId: input.variantId,
|
|
1789
1850
|
state: input.state,
|
|
1790
|
-
|
|
1851
|
+
effectId: effect.effectId
|
|
1791
1852
|
}
|
|
1792
1853
|
};
|
|
1793
1854
|
}
|
|
1794
|
-
function tokenCss(token) {
|
|
1795
|
-
return `rgb(var(--tb-${token}))`;
|
|
1796
|
-
}
|
|
1797
|
-
function interpolateHex(startHex, endHex, position) {
|
|
1798
|
-
const start = hexToRgb(startHex);
|
|
1799
|
-
const end = hexToRgb(endHex);
|
|
1800
|
-
const channel = (from, to) => Math.round(from + (to - from) * position).toString(16).padStart(2, "0");
|
|
1801
|
-
return `#${channel(start.r, end.r)}${channel(start.g, end.g)}${channel(start.b, end.b)}`;
|
|
1802
|
-
}
|
|
1803
|
-
//#endregion
|
|
1804
|
-
//#region ../theme-core/src/palette/generateShades.ts
|
|
1805
|
-
function generateShades(hexColor, name) {
|
|
1806
|
-
const shadeSteps = [
|
|
1807
|
-
50,
|
|
1808
|
-
100,
|
|
1809
|
-
200,
|
|
1810
|
-
300,
|
|
1811
|
-
400,
|
|
1812
|
-
500,
|
|
1813
|
-
600,
|
|
1814
|
-
700,
|
|
1815
|
-
800,
|
|
1816
|
-
900,
|
|
1817
|
-
950
|
|
1818
|
-
];
|
|
1819
|
-
const base = featuresFromHex(hexColor);
|
|
1820
|
-
const hue = base.okH;
|
|
1821
|
-
const baseChroma = base.okC;
|
|
1822
|
-
const toneMap = {
|
|
1823
|
-
50: .975,
|
|
1824
|
-
100: .945,
|
|
1825
|
-
200: .89,
|
|
1826
|
-
300: .82,
|
|
1827
|
-
400: .74,
|
|
1828
|
-
500: .66,
|
|
1829
|
-
600: .58,
|
|
1830
|
-
700: .49,
|
|
1831
|
-
800: .4,
|
|
1832
|
-
900: .28,
|
|
1833
|
-
950: .16
|
|
1834
|
-
};
|
|
1835
|
-
const shadeDefs = shadeSteps.map((step, idx) => {
|
|
1836
|
-
const t = idx / (shadeSteps.length - 1);
|
|
1837
|
-
const L = toneMap[step];
|
|
1838
|
-
const C = baseChroma * (.06 + .94 * Math.sin(Math.PI * t));
|
|
1839
|
-
return {
|
|
1840
|
-
name: `${name}-${step}`,
|
|
1841
|
-
hex: oklchToHexGamut(L, C, hue)
|
|
1842
|
-
};
|
|
1843
|
-
});
|
|
1844
|
-
shadeDefs.push({
|
|
1845
|
-
name,
|
|
1846
|
-
hex: hexColor
|
|
1847
|
-
});
|
|
1848
|
-
return shadeDefs;
|
|
1849
|
-
}
|
|
1850
1855
|
//#endregion
|
|
1851
|
-
//#region ../theme-core/src/
|
|
1852
|
-
/** The cool slate tint every scale had before #1863, kept for grounds with no hue to lend. */
|
|
1853
|
-
const SLATE_NEUTRAL_TINT = {
|
|
1854
|
-
hue: 250,
|
|
1855
|
-
chroma: .02
|
|
1856
|
-
};
|
|
1857
|
-
/** Below this OKLCH chroma a background reads as plain white, grey or black, so its hue is noise. */
|
|
1858
|
-
const ACHROMATIC_CHROMA = .005;
|
|
1856
|
+
//#region ../theme-core/src/buttons/contextualHover.ts
|
|
1859
1857
|
/**
|
|
1860
|
-
* The
|
|
1861
|
-
*
|
|
1862
|
-
* A background with no hue to lend (white, `#fafafa`, a missing or unreadable
|
|
1863
|
-
* value) keeps the slate tint, so those palettes keep their exact neutrals.
|
|
1858
|
+
* The smallest OKLab move that reads as a hover. Neighbouring steps of a
|
|
1859
|
+
* palette scale are about 0.06 to 0.08 apart.
|
|
1864
1860
|
*/
|
|
1865
|
-
|
|
1866
|
-
const parsed = hexColorSchema.safeParse(background?.toLowerCase());
|
|
1867
|
-
if (!parsed.success) return SLATE_NEUTRAL_TINT;
|
|
1868
|
-
const { r, g, b } = hexToRgb(parsed.data);
|
|
1869
|
-
const { L, a, b: ob } = srgbToOklab(r, g, b);
|
|
1870
|
-
const { C, h } = oklabToOklch(L, a, ob);
|
|
1871
|
-
return C < ACHROMATIC_CHROMA ? SLATE_NEUTRAL_TINT : {
|
|
1872
|
-
hue: h,
|
|
1873
|
-
chroma: Math.min(C, SLATE_NEUTRAL_TINT.chroma)
|
|
1874
|
-
};
|
|
1875
|
-
}
|
|
1861
|
+
const MINIMUM_VISIBLE_STEP = .04;
|
|
1876
1862
|
/**
|
|
1877
|
-
*
|
|
1878
|
-
*
|
|
1879
|
-
*
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
500,
|
|
1889
|
-
600,
|
|
1890
|
-
700,
|
|
1891
|
-
800,
|
|
1892
|
-
900,
|
|
1893
|
-
950
|
|
1894
|
-
];
|
|
1895
|
-
const count = Math.min(steps, shadeNames.length);
|
|
1896
|
-
return shadeNames.slice(0, count).map((shadeName, index) => ({
|
|
1897
|
-
name: `neutral-${shadeName}`,
|
|
1898
|
-
hex: oklchToHexGamut(mix(.98, .1, index / (count - 1)), tint.chroma, tint.hue)
|
|
1899
|
-
}));
|
|
1900
|
-
}
|
|
1901
|
-
function mix(a, b, t) {
|
|
1902
|
-
return a + (b - a) * Math.max(0, Math.min(1, t));
|
|
1903
|
-
}
|
|
1904
|
-
//#endregion
|
|
1905
|
-
//#region ../theme-core/src/palette/utils/scrimContrast.ts
|
|
1906
|
-
const WHITE = "#ffffff";
|
|
1907
|
-
const BLACK = "#000000";
|
|
1908
|
-
/** `top` at `alpha` over opaque `bottom`, blended as CSS paints an overlay. */
|
|
1909
|
-
function compositeHex(topHex, alpha, bottomHex) {
|
|
1910
|
-
const top = hexToRgb(topHex);
|
|
1911
|
-
const bottom = hexToRgb(bottomHex);
|
|
1912
|
-
const mix = (a, b) => Math.round(alpha * a + (1 - alpha) * b);
|
|
1913
|
-
return rgbToHex(mix(top.r, bottom.r), mix(top.g, bottom.g), mix(top.b, bottom.b));
|
|
1914
|
-
}
|
|
1863
|
+
* The contrast at which a fill reads as a fill rather than a shadow on its
|
|
1864
|
+
* ground. It applies when the recipe names the ink to fill with
|
|
1865
|
+
* (`preferredToken`): those buttons rest as an outline and fill only on hover,
|
|
1866
|
+
* so the fill has to read against the ground on its own. A button edge can keep
|
|
1867
|
+
* a darker fill distinct, but it then looks like a hole in the panel.
|
|
1868
|
+
*/
|
|
1869
|
+
const FILL_CLEARS_GROUND = 1.5;
|
|
1870
|
+
/** Two label inks closer than this read as the same ink (a near-black for black); a light label against a dark one is far above it. */
|
|
1871
|
+
const SAME_LABEL_INK = 3;
|
|
1872
|
+
/** A step a filled button can change its label for: one or two neighbouring shades of its scale. */
|
|
1873
|
+
const NEAR_STEP = .2;
|
|
1915
1874
|
/**
|
|
1916
|
-
* The
|
|
1917
|
-
*
|
|
1918
|
-
*
|
|
1875
|
+
* The ends of a scale are often close to neutral black or white. A shade below
|
|
1876
|
+
* the dark end or above the light end (OKLab lightness) that has under this
|
|
1877
|
+
* share of the seed's chroma reads as grey, black or white, not as the button.
|
|
1919
1878
|
*/
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1879
|
+
const HUELESS_DARK_END = .2;
|
|
1880
|
+
const HUELESS_LIGHT_END = .94;
|
|
1881
|
+
const HUE_KEPT_SHARE = .5;
|
|
1882
|
+
/** The recipe's own hover ink wins when it holds; otherwise the shade shift decides. */
|
|
1883
|
+
function resolveContextualHoverPreference(input) {
|
|
1884
|
+
const preferred = input.instruction.preferredToken;
|
|
1885
|
+
if (preferred && preferredInkHolds(preferred, input)) return {
|
|
1886
|
+
kind: "resolved",
|
|
1887
|
+
token: preferred,
|
|
1888
|
+
repair: null
|
|
1889
|
+
};
|
|
1890
|
+
const contextual = resolveContextualHover(input);
|
|
1891
|
+
if (contextual.kind === "unavailable") return contextual;
|
|
1892
|
+
return {
|
|
1893
|
+
kind: "resolved",
|
|
1894
|
+
token: contextual.token,
|
|
1895
|
+
repair: preferred ? {
|
|
1896
|
+
kind: "preferred-token-replaced",
|
|
1897
|
+
preferredToken: preferred,
|
|
1898
|
+
contextualToken: contextual.token
|
|
1899
|
+
} : null
|
|
1926
1900
|
};
|
|
1927
|
-
const foreground = luminance(input.foregroundHex);
|
|
1928
|
-
const low = luminance(overBlack);
|
|
1929
|
-
const high = luminance(overWhite);
|
|
1930
|
-
if (foreground >= low && foreground <= high) return 1;
|
|
1931
|
-
return Math.min(contrastRatio(input.foregroundHex, overWhite), contrastRatio(input.foregroundHex, overBlack));
|
|
1932
1901
|
}
|
|
1933
1902
|
/**
|
|
1934
|
-
*
|
|
1935
|
-
*
|
|
1936
|
-
*
|
|
1903
|
+
* Chooses the hover fill from the seed's own shade family, so the hue stays.
|
|
1904
|
+
*
|
|
1905
|
+
* A hover should read as the same button, stronger. The choice is made on the
|
|
1906
|
+
* colours themselves, not on shade numbers (a brand colour is rarely the 500
|
|
1907
|
+
* step of its scale). Hard limits come first: the label stays readable, the
|
|
1908
|
+
* hover stands apart from a known surface, and a button that rests filled
|
|
1909
|
+
* stays recognisably itself. `HOVER_PREFERENCE` then ranks what's left.
|
|
1910
|
+
*
|
|
1911
|
+
* The ground is the proven surface, or the palette's page colour when the
|
|
1912
|
+
* surface is unknown. With neither, the instruction's fallback direction
|
|
1913
|
+
* stands in for "stronger".
|
|
1937
1914
|
*/
|
|
1938
|
-
function
|
|
1939
|
-
const
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
}
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1915
|
+
function resolveContextualHover(input) {
|
|
1916
|
+
const shades = shadeCandidates(input);
|
|
1917
|
+
if (shades.length === 0) return {
|
|
1918
|
+
kind: "unavailable",
|
|
1919
|
+
reason: "no-distinct-shade"
|
|
1920
|
+
};
|
|
1921
|
+
const readable = shades.filter((shade) => labelReadable(shade.hex, shade.labelInk, input.colourIndex));
|
|
1922
|
+
if (readable.length === 0) return {
|
|
1923
|
+
kind: "unavailable",
|
|
1924
|
+
reason: "no-text-safe-candidate"
|
|
1925
|
+
};
|
|
1926
|
+
const restLabel = seedFilledRestLabel(input.rest, input.instruction.seedToken);
|
|
1927
|
+
const selected = pickHover(readable.filter((shade) => standsApartFromSurface(shade.hex, shade.labelInk, input) && (restLabel === void 0 || staysTheSameFilledButton(shade, restLabel))));
|
|
1928
|
+
const surfaceKnown = input.surface !== void 0;
|
|
1929
|
+
if (!selected) return {
|
|
1930
|
+
kind: "unavailable",
|
|
1931
|
+
reason: surfaceKnown ? "no-surface-safe-candidate" : "no-text-safe-candidate"
|
|
1932
|
+
};
|
|
1933
|
+
return {
|
|
1934
|
+
kind: "resolved",
|
|
1935
|
+
token: selected.token,
|
|
1936
|
+
direction: selected.direction,
|
|
1937
|
+
evidence: surfaceKnown ? "known-surface" : "fallback-direction"
|
|
1938
|
+
};
|
|
1960
1939
|
}
|
|
1961
|
-
|
|
1962
|
-
|
|
1940
|
+
const visible = (shade) => shade.distance >= MINIMUM_VISIBLE_STEP;
|
|
1941
|
+
/**
|
|
1942
|
+
* Where the hover is looked for, in order. The first group with a shade wins,
|
|
1943
|
+
* and within it the nearest visible step (or, with none visible, the furthest).
|
|
1944
|
+
*
|
|
1945
|
+
* 1. Stronger, keeping the hue, and clearing the ground when the recipe names a fill ink.
|
|
1946
|
+
* 2. Stronger, keeping the hue.
|
|
1947
|
+
* 3. The other way, keeping the hue: a visible hover beats a hue-less or invisible one.
|
|
1948
|
+
* 4. Any stronger shade.
|
|
1949
|
+
* 5. Any shade the other way.
|
|
1963
1950
|
*/
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
const
|
|
1973
|
-
|
|
1951
|
+
const HOVER_PREFERENCE = [
|
|
1952
|
+
(shade) => shade.stronger && shade.keepsHue && visible(shade) && shade.fillClearsGround,
|
|
1953
|
+
(shade) => shade.stronger && shade.keepsHue && visible(shade),
|
|
1954
|
+
(shade) => !shade.stronger && shade.keepsHue && visible(shade),
|
|
1955
|
+
(shade) => shade.stronger,
|
|
1956
|
+
() => true
|
|
1957
|
+
];
|
|
1958
|
+
function pickHover(allowed) {
|
|
1959
|
+
for (const inGroup of HOVER_PREFERENCE) {
|
|
1960
|
+
const group = allowed.filter(inGroup);
|
|
1961
|
+
if (group.length > 0) return nearestVisibleStep(group);
|
|
1962
|
+
}
|
|
1974
1963
|
}
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1964
|
+
function nearestVisibleStep(shades) {
|
|
1965
|
+
const byDistance = [...shades].sort((left, right) => left.distance - right.distance || left.token.localeCompare(right.token));
|
|
1966
|
+
return byDistance.find(visible) ?? byDistance[byDistance.length - 1];
|
|
1967
|
+
}
|
|
1968
|
+
/** The label ink of a button that rests filled with the seed; undefined when it rests some other way (it fills only on hover). */
|
|
1969
|
+
function seedFilledRestLabel(rest, seed) {
|
|
1970
|
+
return rest.kind === "solid" && rest.colorToken === seed ? rest.labelInk : void 0;
|
|
1981
1971
|
}
|
|
1982
|
-
const nonShadeablePaletteRoleNames = /* @__PURE__ */ new Set([
|
|
1983
|
-
"success",
|
|
1984
|
-
"warning",
|
|
1985
|
-
"destructive"
|
|
1986
|
-
]);
|
|
1987
1972
|
/**
|
|
1988
|
-
*
|
|
1989
|
-
*
|
|
1990
|
-
*
|
|
1991
|
-
* and
|
|
1992
|
-
*
|
|
1993
|
-
* Without these aliases those declarations name variables that are never
|
|
1994
|
-
* defined and browsers drop them. The SDK bridge resolves the same pair via
|
|
1995
|
-
* TOKEN_ALIASES, so both runtimes agree on what a status token means.
|
|
1996
|
-
*
|
|
1997
|
-
* Runs after the danger → destructive promotion above, so `destructive` is
|
|
1998
|
-
* already the single source of truth for the error colour.
|
|
1973
|
+
* A button that rests filled with the seed should still read as itself on
|
|
1974
|
+
* hover. A shade that needs the other label ink is only allowed a near step
|
|
1975
|
+
* away (a jump across the scale with the label flipped looks like another
|
|
1976
|
+
* button), and a shade the other way has to keep the hue. A button that fills
|
|
1977
|
+
* only on hover changes its label anyway, so this doesn't apply to it.
|
|
1999
1978
|
*/
|
|
2000
|
-
function
|
|
2001
|
-
|
|
2002
|
-
if (expanded.destructive) aliases.error = expanded.destructive;
|
|
2003
|
-
if (expanded.accent) aliases.info = expanded.accent;
|
|
2004
|
-
return aliases;
|
|
1979
|
+
function staysTheSameFilledButton(shade, restLabel) {
|
|
1980
|
+
return (contrastRatio(shade.labelInk, restLabel) < SAME_LABEL_INK || shade.distance <= NEAR_STEP) && (shade.stronger || shade.keepsHue);
|
|
2005
1981
|
}
|
|
2006
|
-
function
|
|
2007
|
-
return
|
|
2008
|
-
|
|
2009
|
-
|
|
1982
|
+
function labelReadable(hex, labelInk, colourIndex) {
|
|
1983
|
+
return labelInk !== void 0 && contrastRatio(hex, labelInk, colourIndex) >= BUTTON_CONTRAST_POLICY.textMinimumRatio;
|
|
1984
|
+
}
|
|
1985
|
+
/** On a proven surface, the fill stands apart from it by colour or by a declared edge. */
|
|
1986
|
+
function standsApartFromSurface(hex, labelInk, input) {
|
|
1987
|
+
return input.surface === void 0 || buttonSurfaceSeparation(hex, input.surface, {
|
|
1988
|
+
border: input.border,
|
|
1989
|
+
palette: input.palette,
|
|
1990
|
+
labelInk
|
|
1991
|
+
}).distinct;
|
|
1992
|
+
}
|
|
1993
|
+
/** The recipe's own hover ink holds when its label reads and, on a proven surface, it stands apart and clears the surface as a fill. */
|
|
1994
|
+
function preferredInkHolds(token, input) {
|
|
1995
|
+
const hex = resolveConcreteColorHex(token, input.palette);
|
|
1996
|
+
const labelInk = resolveConcreteColorHex(solidForegroundToken(token), input.palette) ?? void 0;
|
|
1997
|
+
if (hex === null || !labelReadable(hex, labelInk, input.colourIndex)) return false;
|
|
1998
|
+
return input.surface === void 0 || standsApartFromSurface(hex, labelInk, input) && contrastRatio(hex, input.surface.backgroundHex, input.colourIndex) >= FILL_CLEARS_GROUND;
|
|
1999
|
+
}
|
|
2000
|
+
/** The other steps of the seed's scale (`primary-100` … `primary-950`), measured against the seed and the ground. */
|
|
2001
|
+
function shadeCandidates(input) {
|
|
2002
|
+
const { instruction, palette, colourIndex } = input;
|
|
2003
|
+
const seedHex = resolveConcreteColorHex(instruction.seedToken, palette);
|
|
2004
|
+
if (seedHex === null) return [];
|
|
2005
|
+
const family = String(instruction.seedToken).match(/^(.*?)(?:-\d{2,3})?$/)?.[1] ?? String(instruction.seedToken);
|
|
2006
|
+
const step = new RegExp(`^${escapeRegExp(family)}-\\d{2,3}$`);
|
|
2007
|
+
const ground = input.surface?.backgroundHex ?? palette.background;
|
|
2008
|
+
const seed = {
|
|
2009
|
+
hex: seedHex,
|
|
2010
|
+
lightness: contrastRatio(seedHex, "#000000"),
|
|
2011
|
+
chroma: oklab(seedHex).chroma,
|
|
2012
|
+
ground: ground === void 0 ? void 0 : {
|
|
2013
|
+
contrast: (hex) => contrastRatio(hex, ground, colourIndex),
|
|
2014
|
+
restContrast: contrastRatio(seedHex, ground, colourIndex)
|
|
2015
|
+
}
|
|
2010
2016
|
};
|
|
2017
|
+
return Object.keys(palette).flatMap((name) => {
|
|
2018
|
+
const token = step.test(name) ? parseOpaqueButtonColourToken(name) : null;
|
|
2019
|
+
const hex = token === null ? void 0 : palette[token];
|
|
2020
|
+
return token === null || hex === void 0 || hex === seedHex ? [] : [describeShade(token, hex, seed, input)];
|
|
2021
|
+
});
|
|
2011
2022
|
}
|
|
2012
|
-
function
|
|
2013
|
-
const
|
|
2014
|
-
const
|
|
2015
|
-
const
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2023
|
+
function describeShade(token, hex, seed, input) {
|
|
2024
|
+
const { instruction, palette } = input;
|
|
2025
|
+
const direction = contrastRatio(hex, "#000000") > seed.lightness ? "lighter" : "darker";
|
|
2026
|
+
const groundContrast = seed.ground?.contrast(hex);
|
|
2027
|
+
return {
|
|
2028
|
+
token,
|
|
2029
|
+
hex,
|
|
2030
|
+
direction,
|
|
2031
|
+
labelInk: resolveConcreteColorHex(solidForegroundToken(token), palette) ?? void 0,
|
|
2032
|
+
distance: hexOklabDistance(seed.hex, hex),
|
|
2033
|
+
stronger: seed.ground === void 0 ? direction === instruction.fallbackDirection : seed.ground.contrast(hex) >= seed.ground.restContrast,
|
|
2034
|
+
keepsHue: keepsHue(oklab(hex), seed.chroma),
|
|
2035
|
+
fillClearsGround: instruction.preferredToken !== void 0 && groundContrast !== void 0 && groundContrast >= FILL_CLEARS_GROUND
|
|
2036
|
+
};
|
|
2037
|
+
}
|
|
2038
|
+
function keepsHue(shade, seedChroma) {
|
|
2039
|
+
return !(shade.lightness < HUELESS_DARK_END || shade.lightness > HUELESS_LIGHT_END) || shade.chroma >= seedChroma * HUE_KEPT_SHARE;
|
|
2040
|
+
}
|
|
2041
|
+
function oklab(hex) {
|
|
2042
|
+
const { r, g, b } = hexToRgb(hex);
|
|
2043
|
+
const lab = srgbToOklab(r, g, b);
|
|
2044
|
+
return {
|
|
2045
|
+
lightness: lab.L,
|
|
2046
|
+
chroma: Math.hypot(lab.a, lab.b)
|
|
2047
|
+
};
|
|
2048
|
+
}
|
|
2049
|
+
function escapeRegExp(value) {
|
|
2050
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2051
|
+
}
|
|
2052
|
+
//#endregion
|
|
2053
|
+
//#region ../theme-core/src/buttons/resolveButtonHoverTreatment.ts
|
|
2054
|
+
function resolveButtonHoverTreatment(input) {
|
|
2055
|
+
if (input.variant.contextualHover) {
|
|
2056
|
+
const contextual = resolveContextualHoverPreference({
|
|
2057
|
+
instruction: input.variant.contextualHover,
|
|
2058
|
+
palette: input.palette,
|
|
2059
|
+
colourIndex: input.colourIndex,
|
|
2060
|
+
surface: input.surface,
|
|
2061
|
+
border: input.variant.border,
|
|
2062
|
+
rest: input.rest
|
|
2026
2063
|
});
|
|
2064
|
+
if (contextual.kind === "resolved") return {
|
|
2065
|
+
treatment: {
|
|
2066
|
+
type: "solid",
|
|
2067
|
+
colorToken: contextual.token
|
|
2068
|
+
},
|
|
2069
|
+
repair: contextual.repair
|
|
2070
|
+
};
|
|
2027
2071
|
}
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
expanded[onToken] = paletteInkOnSolid(hex, roles).hex;
|
|
2037
|
-
}
|
|
2038
|
-
Object.assign(expanded, groundMutedInkTokens(expanded));
|
|
2039
|
-
return expanded;
|
|
2072
|
+
const token = input.variant.hoverBackgroundToken ?? (input.global.hoverColor === "token" ? input.global.hoverColorToken : void 0);
|
|
2073
|
+
return {
|
|
2074
|
+
treatment: token === void 0 ? input.fallback : {
|
|
2075
|
+
type: "solid",
|
|
2076
|
+
colorToken: token
|
|
2077
|
+
},
|
|
2078
|
+
repair: null
|
|
2079
|
+
};
|
|
2040
2080
|
}
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
const
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2081
|
+
//#endregion
|
|
2082
|
+
//#region ../theme-core/src/buttons/resolveButtonColourStates.ts
|
|
2083
|
+
function mapVisualStates(value) {
|
|
2084
|
+
return {
|
|
2085
|
+
base: value("base"),
|
|
2086
|
+
hover: value("hover"),
|
|
2087
|
+
focus: value("focus"),
|
|
2088
|
+
active: value("active"),
|
|
2089
|
+
disabled: value("disabled")
|
|
2090
|
+
};
|
|
2091
|
+
}
|
|
2092
|
+
/** The border a state draws: its declared appearance's, otherwise the variant's. */
|
|
2093
|
+
function buttonStateBorder(variant, state) {
|
|
2094
|
+
const appearance = variant.visualStates?.[state];
|
|
2095
|
+
if (!appearance) return variant.border;
|
|
2096
|
+
return appearance.border === "none" ? void 0 : appearance.border;
|
|
2097
|
+
}
|
|
2098
|
+
function compileButtonColourStates(input) {
|
|
2099
|
+
if (input.variant.visualStates) return compileDeclaredVisualStates(input, input.variant.visualStates);
|
|
2100
|
+
const base = applyColourEffects({
|
|
2101
|
+
variantId: input.variant.id,
|
|
2102
|
+
state: "base",
|
|
2103
|
+
treatment: input.variant.background,
|
|
2104
|
+
effects: input.variant.effects?.base,
|
|
2105
|
+
palette: input.palette
|
|
2106
|
+
});
|
|
2107
|
+
if (!base.ok) return base;
|
|
2108
|
+
const hover = resolveButtonHoverTreatment({
|
|
2109
|
+
variant: input.variant,
|
|
2110
|
+
global: input.global,
|
|
2111
|
+
fallback: base.treatment,
|
|
2112
|
+
rest: restingFill({
|
|
2113
|
+
...input,
|
|
2114
|
+
variantId: input.variant.id,
|
|
2115
|
+
state: "base"
|
|
2116
|
+
}, base.treatment),
|
|
2117
|
+
palette: input.palette,
|
|
2118
|
+
surface: input.surface,
|
|
2119
|
+
colourIndex: input.colourIndex
|
|
2120
|
+
});
|
|
2121
|
+
const colours = collectStateColours(mapVisualStates((state) => compileVisualState(input, state, state === "hover" ? hover.treatment : base.treatment, base.nonColourEffects)));
|
|
2122
|
+
return colours.ok ? {
|
|
2123
|
+
...colours,
|
|
2124
|
+
contextualHoverRepair: hover.repair
|
|
2125
|
+
} : colours;
|
|
2126
|
+
}
|
|
2127
|
+
function compileDeclaredVisualStates(input, states) {
|
|
2128
|
+
const hover = resolveButtonHoverTreatment({
|
|
2129
|
+
...input,
|
|
2130
|
+
variant: {
|
|
2131
|
+
...input.variant,
|
|
2132
|
+
contextualHover: states.hover.contextualHover,
|
|
2133
|
+
border: buttonStateBorder(input.variant, "hover"),
|
|
2134
|
+
hoverBackgroundToken: void 0
|
|
2135
|
+
},
|
|
2136
|
+
global: {
|
|
2137
|
+
...input.global,
|
|
2138
|
+
hoverColor: "none",
|
|
2139
|
+
hoverColorToken: void 0
|
|
2140
|
+
},
|
|
2141
|
+
fallback: states.hover.background,
|
|
2142
|
+
rest: restingFill({
|
|
2143
|
+
...input,
|
|
2144
|
+
variantId: input.variant.id,
|
|
2145
|
+
state: "base"
|
|
2146
|
+
}, states.base.background)
|
|
2147
|
+
});
|
|
2148
|
+
const colours = collectStateColours(mapVisualStates((state) => compileDeclaredVisualState(input, states, state, state === "hover" ? hover.treatment : states[state].background)));
|
|
2149
|
+
return colours.ok ? {
|
|
2150
|
+
...colours,
|
|
2151
|
+
focusIndicator: states.focus.indicator ? {
|
|
2152
|
+
kind: "surface-role",
|
|
2153
|
+
colorCss: input.surface?.foregroundCss ?? surfaceForegroundValue("text"),
|
|
2154
|
+
width: states.focus.indicator.width,
|
|
2155
|
+
offset: states.focus.indicator.offset,
|
|
2156
|
+
minimumSurfaceContrast: BUTTON_CONTRAST_POLICY.nonTextMinimumRatio
|
|
2157
|
+
} : colours.focusIndicator,
|
|
2158
|
+
contextualHoverRepair: hover.repair
|
|
2159
|
+
} : colours;
|
|
2160
|
+
}
|
|
2161
|
+
function compileDeclaredVisualState(input, states, state, treatment) {
|
|
2162
|
+
const appearance = states[state];
|
|
2163
|
+
const effects = state === "base" ? appearance.effects : [...states.base.effects, ...appearance.effects];
|
|
2164
|
+
const transition = applyColourEffects({
|
|
2165
|
+
variantId: input.variant.id,
|
|
2166
|
+
state,
|
|
2167
|
+
treatment,
|
|
2168
|
+
effects,
|
|
2169
|
+
palette: input.palette
|
|
2170
|
+
});
|
|
2171
|
+
if (!transition.ok) return transition;
|
|
2172
|
+
const resolved = resolveTreatment({
|
|
2173
|
+
variantId: input.variant.id,
|
|
2174
|
+
state,
|
|
2175
|
+
treatment: transition.treatment,
|
|
2176
|
+
border: buttonStateBorder(input.variant, state),
|
|
2177
|
+
palette: input.palette,
|
|
2178
|
+
surface: input.surface,
|
|
2179
|
+
colourIndex: input.colourIndex
|
|
2180
|
+
});
|
|
2181
|
+
return resolved.ok ? {
|
|
2182
|
+
...resolved,
|
|
2183
|
+
nonColourEffects: state === "disabled" ? [] : state === "base" ? transition.nonColourEffects : transition.nonColourEffects.filter((effect) => appearance.effects.includes(effect))
|
|
2184
|
+
} : resolved;
|
|
2185
|
+
}
|
|
2186
|
+
function compileVisualState(input, state, treatment, baseEffects) {
|
|
2187
|
+
const transition = state === "hover" || state === "focus" || state === "active" ? applyColourEffects({
|
|
2188
|
+
variantId: input.variant.id,
|
|
2189
|
+
state,
|
|
2190
|
+
treatment,
|
|
2191
|
+
effects: input.variant.effects?.[state],
|
|
2192
|
+
palette: input.palette
|
|
2193
|
+
}) : {
|
|
2194
|
+
ok: true,
|
|
2195
|
+
treatment,
|
|
2196
|
+
nonColourEffects: state === "base" ? baseEffects : []
|
|
2197
|
+
};
|
|
2198
|
+
if (!transition.ok) return transition;
|
|
2199
|
+
const resolved = resolveTreatment({
|
|
2200
|
+
variantId: input.variant.id,
|
|
2201
|
+
state,
|
|
2202
|
+
treatment: transition.treatment,
|
|
2203
|
+
palette: input.palette,
|
|
2204
|
+
surface: input.surface,
|
|
2205
|
+
colourIndex: input.colourIndex,
|
|
2206
|
+
border: buttonStateBorder(input.variant, state)
|
|
2207
|
+
});
|
|
2208
|
+
return resolved.ok ? {
|
|
2209
|
+
...resolved,
|
|
2210
|
+
nonColourEffects: transition.nonColourEffects
|
|
2211
|
+
} : resolved;
|
|
2212
|
+
}
|
|
2213
|
+
function collectStateColours(results) {
|
|
2214
|
+
if (!results.base.ok) return results.base;
|
|
2215
|
+
if (!results.hover.ok) return results.hover;
|
|
2216
|
+
if (!results.focus.ok) return results.focus;
|
|
2217
|
+
if (!results.active.ok) return results.active;
|
|
2218
|
+
if (!results.disabled.ok) return results.disabled;
|
|
2219
|
+
const states = {
|
|
2220
|
+
base: results.base.colour,
|
|
2221
|
+
hover: results.hover.colour,
|
|
2222
|
+
focus: results.focus.colour,
|
|
2223
|
+
active: results.active.colour,
|
|
2224
|
+
disabled: results.disabled.colour
|
|
2108
2225
|
};
|
|
2109
|
-
const solved = SURFACE_SECONDARY_TEXT_TINTS.reduce((kept, { token, alpha }) => {
|
|
2110
|
-
const tintHex = palette[token];
|
|
2111
|
-
if (!tintHex) return kept;
|
|
2112
|
-
const grounds = [...kept.grounds, compositeHex(tintHex, alpha, groundHex)];
|
|
2113
|
-
const ink = paletteMutedInk(grounds, preferred, roles);
|
|
2114
|
-
return ink.kind === "unpaintable" ? {
|
|
2115
|
-
...kept,
|
|
2116
|
-
uncovered: [...kept.uncovered, {
|
|
2117
|
-
token,
|
|
2118
|
-
alpha,
|
|
2119
|
-
tintHex
|
|
2120
|
-
}]
|
|
2121
|
-
} : {
|
|
2122
|
-
...kept,
|
|
2123
|
-
grounds,
|
|
2124
|
-
hex: ink.hex
|
|
2125
|
-
};
|
|
2126
|
-
}, initial);
|
|
2127
2226
|
return {
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
}))
|
|
2227
|
+
ok: true,
|
|
2228
|
+
states,
|
|
2229
|
+
focusIndicator: resolveFocusIndicator(states.focus),
|
|
2230
|
+
nonColourEffects: Object.fromEntries(Object.entries(results).flatMap(([state, result]) => result.ok && result.nonColourEffects.length > 0 ? [[state, [...result.nonColourEffects]]] : []))
|
|
2133
2231
|
};
|
|
2134
2232
|
}
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2233
|
+
function resolveTreatment(input) {
|
|
2234
|
+
const treatment = input.treatment;
|
|
2235
|
+
switch (treatment.type) {
|
|
2236
|
+
case "surface":
|
|
2237
|
+
if (input.surface) {
|
|
2238
|
+
const surface = input.surface;
|
|
2239
|
+
const foreground = buttonSurfaceGrounds(surface).map((backgroundHex) => validateButtonTextContrast({
|
|
2240
|
+
...input,
|
|
2241
|
+
background: "surface",
|
|
2242
|
+
backgroundHex,
|
|
2243
|
+
foreground: "surface-foreground",
|
|
2244
|
+
foregroundHex: surface.foregroundHex
|
|
2245
|
+
})).find((result) => !result.ok) ?? { ok: true };
|
|
2246
|
+
if (!foreground.ok) return foreground;
|
|
2247
|
+
}
|
|
2248
|
+
return {
|
|
2249
|
+
ok: true,
|
|
2250
|
+
colour: {
|
|
2251
|
+
kind: "surface",
|
|
2252
|
+
role: treatment.role,
|
|
2253
|
+
backgroundCss: "transparent",
|
|
2254
|
+
foregroundCss: input.surface?.foregroundCss ?? surfaceForegroundValue(treatment.role)
|
|
2255
|
+
}
|
|
2256
|
+
};
|
|
2257
|
+
case "solid": return resolveSolid(input, treatment.colorToken, treatment.foregroundToken);
|
|
2258
|
+
case "gradient": return resolveGradient(input, treatment);
|
|
2259
|
+
}
|
|
2138
2260
|
}
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2261
|
+
function resolveFocusIndicator(colour) {
|
|
2262
|
+
switch (colour.kind) {
|
|
2263
|
+
case "solid":
|
|
2264
|
+
case "known-solid": return {
|
|
2265
|
+
kind: "two-tone",
|
|
2266
|
+
innerCss: colour.foregroundCss,
|
|
2267
|
+
outerCss: colour.backgroundCss,
|
|
2268
|
+
minimumPairContrast: BUTTON_CONTRAST_POLICY.textMinimumRatio
|
|
2269
|
+
};
|
|
2270
|
+
case "gradient": return {
|
|
2271
|
+
kind: "two-tone",
|
|
2272
|
+
innerCss: colour.foregroundCss,
|
|
2273
|
+
outerCss: tokenCss(colour.backgroundTokens[0]),
|
|
2274
|
+
minimumPairContrast: BUTTON_CONTRAST_POLICY.textMinimumRatio
|
|
2275
|
+
};
|
|
2276
|
+
case "surface": return {
|
|
2277
|
+
kind: "surface-role",
|
|
2278
|
+
colorCss: colour.foregroundCss,
|
|
2279
|
+
minimumSurfaceContrast: BUTTON_CONTRAST_POLICY.nonTextMinimumRatio
|
|
2280
|
+
};
|
|
2281
|
+
}
|
|
2151
2282
|
}
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2283
|
+
function resolveSolid(input, backgroundToken, preferredForeground) {
|
|
2284
|
+
const backgroundHex = paletteHex(input, backgroundToken);
|
|
2285
|
+
if (!backgroundHex.ok) return backgroundHex;
|
|
2286
|
+
const ink = resolveSolidInk(input, backgroundToken, backgroundHex.hex, preferredForeground);
|
|
2287
|
+
const boundary = input.surface ? validateButtonFillSeparation({
|
|
2288
|
+
...input,
|
|
2289
|
+
buttonPaint: backgroundHex.hex,
|
|
2290
|
+
surface: input.surface,
|
|
2291
|
+
labelInk: ink.foregroundHex
|
|
2292
|
+
}) : { ok: true };
|
|
2293
|
+
if (!boundary.ok) return boundary;
|
|
2294
|
+
return {
|
|
2295
|
+
ok: true,
|
|
2296
|
+
colour: ink.colour
|
|
2297
|
+
};
|
|
2164
2298
|
}
|
|
2165
2299
|
/**
|
|
2166
|
-
*
|
|
2167
|
-
*
|
|
2168
|
-
*
|
|
2300
|
+
* One solid fill's colours as any button paints them, for chrome that dresses
|
|
2301
|
+
* itself as a button outside the variant CSS (the header's inverted CTA): the
|
|
2302
|
+
* requested label when it reads, else the fill's on-colour, else black or white.
|
|
2169
2303
|
*/
|
|
2170
|
-
function
|
|
2171
|
-
|
|
2172
|
-
if (!ground || contrastRatio(step, ground) >= 4.5) return step;
|
|
2173
|
-
return paletteMutedInkOnSolid(ground, null, roles);
|
|
2304
|
+
function resolveSolidButtonColour(input, backgroundToken, preferredForeground) {
|
|
2305
|
+
return resolveSolid(input, backgroundToken, preferredForeground);
|
|
2174
2306
|
}
|
|
2175
|
-
/**
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
const ink = pickBlackOrWhiteTextColor(ground);
|
|
2307
|
+
/** A solid rest fill with the label ink resolveSolidInk gives it, so a contextual hover compares against the ink visitors see. */
|
|
2308
|
+
function restingFill(input, treatment) {
|
|
2309
|
+
if (treatment.type !== "solid") return { kind: "not-solid" };
|
|
2310
|
+
const hex = resolveConcreteColorHex(treatment.colorToken, input.palette);
|
|
2311
|
+
if (hex === null) return { kind: "not-solid" };
|
|
2312
|
+
const ink = resolveSolidInk(input, treatment.colorToken, hex, treatment.foregroundToken);
|
|
2182
2313
|
return {
|
|
2183
|
-
|
|
2184
|
-
|
|
2314
|
+
kind: "solid",
|
|
2315
|
+
colorToken: treatment.colorToken,
|
|
2316
|
+
labelInk: ink.foregroundHex
|
|
2185
2317
|
};
|
|
2186
2318
|
}
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2319
|
+
/** Preserve checked on-colours (a requested label colour first); a solid state's last resort is the palette ink for its actual fill. */
|
|
2320
|
+
function resolveSolidInk(input, backgroundToken, backgroundHex, preferredForeground) {
|
|
2321
|
+
if (preferredForeground !== void 0) {
|
|
2322
|
+
const preferred = checkedSolidInk(input, backgroundToken, backgroundHex, preferredForeground);
|
|
2323
|
+
if (preferred) return preferred;
|
|
2324
|
+
}
|
|
2325
|
+
return checkedSolidInk(input, backgroundToken, backgroundHex, unsafeAsOpaqueButtonColourToken(solidForegroundToken(backgroundToken))) ?? paletteSolidInk(input, backgroundToken, backgroundHex);
|
|
2194
2326
|
}
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
if (
|
|
2327
|
+
function checkedSolidInk(input, backgroundToken, backgroundHex, foregroundToken) {
|
|
2328
|
+
const candidate = resolveConcreteColorHex(foregroundToken, input.palette);
|
|
2329
|
+
if ((typeof candidate === "string" ? validateButtonTextContrast({
|
|
2330
|
+
...input,
|
|
2331
|
+
background: backgroundToken,
|
|
2332
|
+
backgroundHex,
|
|
2333
|
+
foreground: foregroundToken,
|
|
2334
|
+
foregroundHex: candidate
|
|
2335
|
+
}) : null)?.ok === true && typeof candidate === "string") return {
|
|
2336
|
+
foregroundHex: candidate,
|
|
2337
|
+
colour: {
|
|
2338
|
+
kind: "solid",
|
|
2339
|
+
backgroundToken,
|
|
2340
|
+
foregroundToken,
|
|
2341
|
+
backgroundCss: tokenCss(backgroundToken),
|
|
2342
|
+
foregroundCss: tokenCss(foregroundToken)
|
|
2343
|
+
}
|
|
2344
|
+
};
|
|
2345
|
+
return null;
|
|
2346
|
+
}
|
|
2347
|
+
/** The palette's own background or text as the label where it reads (as a checked token), else literal black or white. */
|
|
2348
|
+
function paletteSolidInk(input, backgroundToken, backgroundHex) {
|
|
2349
|
+
const ink = paletteInkOnSolid(backgroundHex, paletteInkRoles(input.palette));
|
|
2350
|
+
const role = ink.kind === "role" ? checkedSolidInk(input, backgroundToken, backgroundHex, unsafeAsOpaqueButtonColourToken(ink.role)) : null;
|
|
2351
|
+
if (role) return role;
|
|
2352
|
+
const literal = pickBlackOrWhiteTextColor(backgroundHex);
|
|
2198
2353
|
return {
|
|
2199
|
-
|
|
2200
|
-
|
|
2354
|
+
foregroundHex: literal,
|
|
2355
|
+
colour: {
|
|
2356
|
+
kind: "known-solid",
|
|
2357
|
+
backgroundCss: tokenCss(backgroundToken),
|
|
2358
|
+
foregroundCss: literal
|
|
2359
|
+
}
|
|
2360
|
+
};
|
|
2361
|
+
}
|
|
2362
|
+
function resolveGradient(input, treatment) {
|
|
2363
|
+
const foregroundHex = paletteHex(input, treatment.foregroundToken);
|
|
2364
|
+
if (!foregroundHex.ok) return foregroundHex;
|
|
2365
|
+
const stopHexes = [];
|
|
2366
|
+
for (const token of treatment.stops) {
|
|
2367
|
+
const stop = paletteHex(input, token);
|
|
2368
|
+
if (!stop.ok) return stop;
|
|
2369
|
+
stopHexes.push(stop.hex);
|
|
2370
|
+
}
|
|
2371
|
+
for (let segment = 0; segment < stopHexes.length - 1; segment += 1) {
|
|
2372
|
+
const start = stopHexes[segment];
|
|
2373
|
+
const end = stopHexes[segment + 1];
|
|
2374
|
+
const startToken = treatment.stops[segment];
|
|
2375
|
+
const endToken = treatment.stops[segment + 1];
|
|
2376
|
+
if (start === void 0 || end === void 0 || startToken === void 0 || endToken === void 0) continue;
|
|
2377
|
+
for (let sample = 0; sample <= BUTTON_CONTRAST_POLICY.gradientSamplesPerSegment; sample += 1) {
|
|
2378
|
+
const position = sample / BUTTON_CONTRAST_POLICY.gradientSamplesPerSegment;
|
|
2379
|
+
const sampleHex = interpolateHex(start, end, position);
|
|
2380
|
+
const contrast = validateButtonTextContrast({
|
|
2381
|
+
...input,
|
|
2382
|
+
background: `${startToken}→${endToken}@${position.toFixed(2)}`,
|
|
2383
|
+
backgroundHex: sampleHex,
|
|
2384
|
+
foreground: treatment.foregroundToken,
|
|
2385
|
+
foregroundHex: foregroundHex.hex
|
|
2386
|
+
});
|
|
2387
|
+
if (!contrast.ok) return contrast;
|
|
2388
|
+
if (input.surface) {
|
|
2389
|
+
const boundary = validateButtonFillSeparation({
|
|
2390
|
+
...input,
|
|
2391
|
+
buttonPaint: sampleHex,
|
|
2392
|
+
labelInk: foregroundHex.hex,
|
|
2393
|
+
surface: input.surface
|
|
2394
|
+
});
|
|
2395
|
+
if (!boundary.ok) return boundary;
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
const direction = GRADIENT_DIRECTION_MAP[treatment.direction] ?? "to right";
|
|
2400
|
+
return {
|
|
2401
|
+
ok: true,
|
|
2402
|
+
colour: {
|
|
2403
|
+
kind: "gradient",
|
|
2404
|
+
backgroundTokens: treatment.stops,
|
|
2405
|
+
foregroundToken: treatment.foregroundToken,
|
|
2406
|
+
backgroundCss: `linear-gradient(${direction}, ${treatment.stops.map(tokenCss).join(", ")})`,
|
|
2407
|
+
foregroundCss: tokenCss(treatment.foregroundToken)
|
|
2408
|
+
}
|
|
2409
|
+
};
|
|
2410
|
+
}
|
|
2411
|
+
function paletteHex(input, token) {
|
|
2412
|
+
const hex = resolveConcreteColorHex(token, input.palette);
|
|
2413
|
+
return typeof hex === "string" ? {
|
|
2414
|
+
ok: true,
|
|
2415
|
+
hex
|
|
2416
|
+
} : {
|
|
2417
|
+
ok: false,
|
|
2418
|
+
error: {
|
|
2419
|
+
tag: "unknown_palette_token",
|
|
2420
|
+
variantId: input.variantId,
|
|
2421
|
+
state: input.state,
|
|
2422
|
+
token
|
|
2423
|
+
}
|
|
2201
2424
|
};
|
|
2202
2425
|
}
|
|
2426
|
+
function tokenCss(token) {
|
|
2427
|
+
return `rgb(var(--tb-${token}))`;
|
|
2428
|
+
}
|
|
2429
|
+
function interpolateHex(startHex, endHex, position) {
|
|
2430
|
+
const start = hexToRgb(startHex);
|
|
2431
|
+
const end = hexToRgb(endHex);
|
|
2432
|
+
const channel = (from, to) => Math.round(from + (to - from) * position).toString(16).padStart(2, "0");
|
|
2433
|
+
return `#${channel(start.r, end.r)}${channel(start.g, end.g)}${channel(start.b, end.b)}`;
|
|
2434
|
+
}
|
|
2203
2435
|
//#endregion
|
|
2204
|
-
export {
|
|
2436
|
+
export { requirePaletteColorsFromEntries as $, deriveSurfaceDecorationColors as A, minimumScrimOpacity as B, PUBLIC_FILE_FIELD_KINDS as C, parseCanonicalMediaIdentifier as D, mediaIdentifierSchema as E, isOnColorBackgroundCandidateToken as F, neutralInk as G, resolveConcreteColorHex as H, onColorTokenName as I, paletteInkRoles as J, paletteInk as K, pickBlackOrWhiteTextColor as L, deriveSurfaceMutedColor as M, expandPalette as N, parseMediaIdentifier as O, groundMutedInkTokens as P, paletteValueKeySchema as Q, compositeHex as R, resolveManagedMediaReference as S, mediaTypeDiscriminants as T, resolveOpaqueSurfaceHex as U, scrimTone as V, inkFrom as W, colourFamily as X, paletteInkToken as Y, paletteValueKey as Z, runtimeMediaSchema as _, formatButtonColourContractError as a, solidPaint as at, renderableMediaAssetSchema as b, DEFAULT_BUTTON_SIZES as c, hexToRgb as ct, generateShadowValue as d, oklabToSrgb as dt, ORDINARY_TEXT_MIN_CONTRAST_RATIO as et, assetMediaSchema as f, oklchToHexGamut as ft, persistableMediaSchema as g, mediaSchema as h, srgbToOklab as ht, BUTTON_CONTRAST_POLICY as i, preparePaletteColourIndex as it, deriveSurfaceLineColor as j, SURFACE_SECONDARY_TEXT_TINT_ALPHA as k, ELEVATION_OFFSET as l, linearToSrgb as lt, imageMediaSchema as m, rgbToHex as mt, compileButtonColourStates as n, hexLuminance as nt, BORDER_RADIUS_MAP as o, worstContrast as ot, externalMediaSchema as p, oklchToOklab as pt, paletteInkOnSolid as q, resolveSolidButtonColour as r, luminanceInterval as rt, BORDER_WIDTH_MAP as s, featuresFromHex as st, buttonStateBorder as t, contrastRatio as tt, FONT_SIZE_MAP as u, oklabToOklch as ut, videoMediaSchema as v, isDisplayMediaKind as w, indexRenderableMediaAssets as x, buildRenderableMediaAssetIndex as y, gradientScrimSamples as z };
|