@riverbankcms/sdk 0.164.0 → 0.166.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_dts/{BlocksIslandsHydrator-CubPwupc.d.ts → BlocksIslandsHydrator-CPvN6RBW.d.ts} +1 -1
- package/dist/_dts/{Page-CDzsagB2.d.ts → Page-rW0xgQCA.d.ts} +18 -256
- package/dist/_dts/{SdkPreviewMode-CPRQbRCI.d.ts → SdkPreviewMode-BWZh2WCk.d.ts} +107 -72
- package/dist/_dts/{client-CbeYTSry.d.ts → client-D4BXQEZc.d.ts} +5 -1
- package/dist/_dts/{content-types--uYRIcIF.d.ts → content-types-MUzta0l9.d.ts} +3 -3
- package/dist/_dts/{contracts-DJQYAOsv.d.ts → contracts-Cl9Xh1DO.d.ts} +4 -4
- package/dist/_dts/{footerPageOutline-CKkhBwgJ.d.ts → footerPageOutline-4BgLKehl.d.ts} +6 -6
- package/dist/_dts/{generatePageMetadata--qd7NCIA.d.ts → generatePageMetadata-BsmJ0qKh.d.ts} +2 -2
- package/dist/_dts/{index-wegfy7lf.d.ts → index--qflsCiy.d.ts} +4 -3
- package/dist/_dts/{index-CjdIn9-_.d.ts → index-BgJ2aU5c.d.ts} +2 -2
- package/dist/_dts/{index-BZE-1azr.d.ts → index-Bmboeb49.d.ts} +2 -2
- package/dist/_dts/{index-BpEbwDM7.d.ts → index-DdcwPqQN.d.ts} +4 -4
- package/dist/_dts/{index-DriYVLfT.d.ts → index-ahxQCUc7.d.ts} +2 -2
- package/dist/_dts/{index-DYQFmf--.d.ts → index-kQ5xkM6X.d.ts} +1 -1
- package/dist/_dts/{index-JS8WYgD3.d.ts → index-mMMvLLAJ.d.ts} +2996 -3079
- package/dist/_dts/{index-D_pQO-AS.d.ts → index-wbBZ0awa.d.ts} +49398 -48202
- package/dist/_dts/{loadContent-DUi94Qfk.d.ts → loadContent-BG5IAV-V.d.ts} +9 -6
- package/dist/_dts/resolveBlockData-Cmcle_zV.d.ts +136 -0
- package/dist/_dts/{resolvePageContent-JDE0ry6T.d.ts → resolvePageContent-BRJUTFoH.d.ts} +3 -2
- package/dist/_dts/sdk/src/bookings/index.d.ts +2 -2
- package/dist/_dts/sdk/src/client/types.d.ts +2 -2
- package/dist/_dts/sdk/src/client.d.ts +9 -6
- 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 +20 -0
- package/dist/_dts/sdk/src/data/resolveBlockData.d.ts +2 -0
- package/dist/_dts/sdk/src/data/types.d.ts +54 -0
- package/dist/_dts/sdk/src/index.d.ts +8 -8
- package/dist/_dts/sdk/src/manifest/index.d.ts +3 -3
- package/dist/_dts/sdk/src/metadata/index.d.ts +1 -1
- package/dist/_dts/sdk/src/navigation/index.d.ts +2 -2
- package/dist/_dts/sdk/src/next/index.d.ts +9 -8
- package/dist/_dts/sdk/src/next/middleware.d.ts +2 -2
- package/dist/_dts/sdk/src/page-converter/index.d.ts +36 -48
- package/dist/_dts/sdk/src/portal/client.d.ts +1 -1
- package/dist/_dts/sdk/src/prebuild/index.d.ts +1 -1
- package/dist/_dts/sdk/src/preview-next/before-render.d.ts +2 -2
- package/dist/_dts/sdk/src/preview-next/client/index.d.ts +2 -2
- package/dist/_dts/sdk/src/preview-next/client/runtime.d.ts +1 -1
- package/dist/_dts/sdk/src/rendering/client.d.ts +2 -2
- package/dist/_dts/sdk/src/rendering/components/pageShared.d.ts +2 -0
- package/dist/_dts/sdk/src/rendering/helpers/loadPage.d.ts +3 -0
- package/dist/_dts/sdk/src/rendering/helpers/pageRuntimeSupport.d.ts +257 -0
- package/dist/_dts/sdk/src/rendering/index.d.ts +8 -7
- package/dist/_dts/sdk/src/rendering/islands/client.d.ts +1 -1
- package/dist/_dts/sdk/src/rendering/server.d.ts +3 -3
- package/dist/_dts/{themeAdmission-D_qtGYAT.d.ts → sdk/src/rendering/themeAdmission.d.ts} +3 -1
- package/dist/_dts/sdk/src/routing/index.d.ts +5 -5
- package/dist/_dts/sdk/src/server.d.ts +7 -5
- package/dist/_dts/sdk/src/spam-protection/index.d.ts +2 -2
- package/dist/_dts/sdk/src/theme/index.d.ts +1 -1
- package/dist/_dts/{types-DiciZDrk.d.ts → types-BX3Y-EW3.d.ts} +3 -3
- package/dist/_dts/{types-DubJnBnI.d.ts → types-DF54stxv.d.ts} +8 -7
- package/dist/_dts/{types-W40f2olO.d.ts → types-DuiHLiPo.d.ts} +2 -2
- package/dist/_dts/{validation-BF4_zNkR.d.ts → validation-Bxi0f81D.d.ts} +4 -4
- package/dist/client/{BlocksIslandsHydrator-64hFxF02.mjs → BlocksIslandsHydrator-DwiRGtgh.mjs} +31 -24
- package/dist/client/{BookingMailingListNote-CSQyFm9J.mjs → BookingMailingListNote-DOWOZYlK.mjs} +2 -2
- package/dist/client/{CalendarNavigationChevron-Bvkx8Z7Y.mjs → CalendarNavigationChevron-5a0x0vcC.mjs} +7 -7
- package/dist/client/{CheckboxChoice-3PhxDxgR.mjs → CheckboxChoice-CZ-anOqV.mjs} +1 -1
- package/dist/client/{DemoBookingPortalAccess-pt2xXBQp.mjs → DemoBookingPortalAccess-B2qLkPRB.mjs} +6 -6
- package/dist/client/{DemoPortalSignInLink-Qw780EfW.mjs → DemoPortalSignInLink-B9YrzZt2.mjs} +1 -1
- package/dist/client/{EventCalendar.client-DWoboRW5.mjs → EventCalendar.client-BhADnDCg.mjs} +17 -10
- package/dist/client/{EventCombined.client-C98ucpcP.mjs → EventCombined.client-jik34zTb.mjs} +8 -8
- package/dist/client/{EventEmbeddedCheckoutStep-DHRlFfkp.mjs → EventEmbeddedCheckoutStep-D_14yqAU.mjs} +27 -2
- package/dist/client/{EventItem-hrSyTApW.mjs → EventItem-CMKrtkT7.mjs} +33 -12
- package/dist/client/{EventListWeekNavigation-C3t7H13W.mjs → EventListWeekNavigation-AGHjxy6C.mjs} +1 -1
- package/dist/client/{EventListing.client-Cp11sBX_.mjs → EventListing.client-DZeDM0Qt.mjs} +3 -3
- package/dist/client/{EventListing.view-Dd5QHIAf.mjs → EventListing.view-3BBRdNVa.mjs} +70 -15
- package/dist/client/{EventRegistrationPayment-ByT88VHR.mjs → EventRegistrationPayment-CpNcpga4.mjs} +108 -11
- package/dist/client/{LocationMapActions-BsepG5Vv.mjs → LocationMapActions-D5-H9ooQ.mjs} +2 -2
- package/dist/client/{MapDrawingSvg-R4JMT4yd.mjs → MapDrawingSvg-C30geMl-.mjs} +1 -1
- package/dist/client/{Page-Dub71o3c.mjs → Page-DNDZLRlB.mjs} +3388 -11530
- package/dist/client/{ProtectedSubmitButton-DGbgGvdh.mjs → ProtectedSubmitButton-8DuDw2ag.mjs} +1 -1
- package/dist/client/{SpamProtectionWidget-CRsKTQV-.mjs → SpamProtectionWidget-CCF6YLUX.mjs} +5 -3
- package/dist/client/{StepIndicator-Bp7MyutT.mjs → StepIndicator-Bin7YR0A.mjs} +3 -3
- package/dist/client/{TabBarFragment-C4WJyybx.mjs → TabBarFragment-_IAthZVM.mjs} +1 -1
- package/dist/client/{ThemedButton-BGVwNwE-.mjs → ThemedButton-8jUc02mZ.mjs} +64 -2
- package/dist/client/{accordion-vCG_JC5t.mjs → accordion-uVqNowRX.mjs} +1 -1
- package/dist/client/{altchaProtection-BWchRM3v.mjs → altchaProtection-DjIV9A5n.mjs} +1 -1
- package/dist/client/{booking-form.client-CHTbcZJM.mjs → booking-form.client-w-PvyWBv.mjs} +19 -14
- package/dist/client/{bookingForm-BxbUbzUr.mjs → bookingForm-DNMojb6A.mjs} +4 -4
- package/dist/client/bookings.mjs +6 -6
- package/dist/client/{carousel-FM1mkkL0.mjs → carousel-C8kxI3Dm.mjs} +2 -2
- package/dist/client/{carousel.client-ChoLiWwD.mjs → carousel.client-BO7sCEpH.mjs} +1 -1
- package/dist/client/{cart-BDFhbh9j.mjs → cart-DCxjE3Is.mjs} +3 -3
- package/dist/client/{cart.client-x3HOke6T.mjs → cart.client-Ceeng8fB.mjs} +1 -1
- package/dist/client/{checkout-BibhwnTd.mjs → checkout-B0EKbeVv.mjs} +3 -3
- package/dist/client/{checkout.client-CE4jUi0G.mjs → checkout.client-DtPj3fYk.mjs} +1 -1
- package/dist/client/client.mjs +9465 -15
- package/dist/client/{context-BNAM7NsW.mjs → context-n6IZigd3.mjs} +8 -6
- package/dist/client/cta-CDeAwYoN.mjs +121 -0
- package/dist/client/{dateFormatting-QwBSo0hK.mjs → dateFormatting-BWPzdeZE.mjs} +1 -1
- package/dist/client/{demoPortalMagicLink-NwKJk6gn.mjs → demoPortalMagicLink-BdXu0fj-.mjs} +1 -1
- package/dist/client/{enhanceHeaderSection-D4zqEBDl.mjs → enhanceHeaderSection-VHfv8M6-.mjs} +3 -3
- package/dist/client/{event-details.client-jFyFjOIC.mjs → event-details.client-Cfr1_Cj4.mjs} +2 -2
- package/dist/client/{event-registration.client-BK_jVv3R.mjs → event-registration.client-BhygihpQ.mjs} +43 -17
- package/dist/client/{eventCalendar-DSkzejQh.mjs → eventCalendar-B4XCL9u6.mjs} +4 -4
- package/dist/client/{eventCombined-BG-BEaYh.mjs → eventCombined-DVjz4wdf.mjs} +4 -4
- package/dist/client/{eventDetails-BhIwXAKe.mjs → eventDetails-B0DA1Nw1.mjs} +2 -2
- package/dist/client/{eventListing-DQtyO1Xj.mjs → eventListing-2-xjn2nz.mjs} +4 -4
- package/dist/client/{eventRegistration-DRTz8X0M.mjs → eventRegistration-ng4iGo9O.mjs} +4 -4
- package/dist/client/{form-GXqjObPC.mjs → form-BeNQiZ2V.mjs} +3 -3
- package/dist/client/{form.client-CoKNba2e.mjs → form.client-BFdCKlp7.mjs} +7 -7
- package/dist/client/{form.parts-magB_epJ.mjs → form.parts-C7gLK3jh.mjs} +3 -3
- package/dist/client/{formatDate-BiloOyjS.mjs → formatDate-CWfelfMt.mjs} +1 -1
- package/dist/client/gifting/client.mjs +4 -5
- package/dist/client/{headerSection-BMQCPHT3.mjs → headerSection-CalNAShx.mjs} +2 -2
- package/dist/client/{mediaAssets-BX-vWwQc.mjs → mediaAssets-DpPauppt.mjs} +1 -1
- package/dist/client/{mediaContext-CdqGYlWl.mjs → mediaContext-BLo4NtjP.mjs} +25 -19
- package/dist/client/{newsletter-form.client-8orCez1z.mjs → newsletter-form.client-Dq7GHGXU.mjs} +9 -9
- package/dist/client/{newsletter-form.parts-D8NgHY_F.mjs → newsletter-form.parts-BSMDYQiS.mjs} +2 -2
- package/dist/client/{newsletterForm-BhBNsS3n.mjs → newsletterForm-snzZ4L6i.mjs} +3 -3
- package/dist/client/{noop-C2vZse15.mjs → noop-D-RG9eR3.mjs} +399 -169
- package/dist/client/portal/client.mjs +13 -14
- package/dist/client/{product-detail.client-CQ0k0fbH.mjs → product-detail.client-Gu0INDb7.mjs} +1 -1
- package/dist/client/{product-list.client-Xlr1P0x9.mjs → product-list.client-BmH40fNf.mjs} +1 -1
- package/dist/client/{productDetail-BsCao6X4.mjs → productDetail-DsPUmJ0z.mjs} +3 -3
- package/dist/client/{productList-Cc-PmbEe.mjs → productList-DjGrjOwD.mjs} +3 -3
- package/dist/client/{propsDecoder-DikkDJ9x.mjs → propsDecoder-kTVPMnfD.mjs} +4 -4
- package/dist/client/{registry.server-BpLZo3bC.mjs → registry.server-CKK_RXZo.mjs} +350 -424
- package/dist/client/rendering/client.mjs +29 -28
- package/dist/client/rendering/islands.mjs +1 -1
- package/dist/client/rendering.mjs +70 -8
- package/dist/client/{richText-coerce-WuMYrBm3.mjs → richText-coerce-BcjTX-7h.mjs} +1 -1
- package/dist/client/{routeIslandApiConfig-DNx6b07x.mjs → routeIslandApiConfig-CaXesATK.mjs} +1 -1
- package/dist/client/{shop-DyXtB5TD.mjs → shop-DLufMauE.mjs} +3 -3
- package/dist/client/{shop-commerce-xjWH7-Ym.mjs → shop-commerce-BxYYXLNK.mjs} +12 -12
- package/dist/client/{shop-commerce-store-CbBsS1kD.mjs → shop-commerce-store-Dp3Nl5YK.mjs} +1 -1
- package/dist/client/{shop.client-QOKqQPgK.mjs → shop.client-CBy9_alG.mjs} +13 -13
- package/dist/client/{shop.interactive-BQdm441g.mjs → shop.interactive-BM0NRsFQ.mjs} +265 -24
- package/dist/client/{shopShared-CyW6MU48.mjs → shopShared-lS23OQE-.mjs} +2 -2
- package/dist/client/site-styles-D8jEPGxA.mjs +3 -0
- package/dist/{preview-next/client/ThemedButton-g7NPrsGp.mjs → client/site-styles-DELkUk9s.mjs} +25654 -17259
- package/dist/client/spam-protection.mjs +2 -2
- package/dist/client/src-DjnxOjXG.mjs +217 -0
- package/dist/client/surfaceTransportMarker-BXepAVF6.mjs +152 -0
- package/dist/client/{timetableModel-BgdkhRuA.mjs → timetableModel-DzRWikCU.mjs} +157 -139
- package/dist/client/types-sF-IrGQr.mjs +633 -0
- package/dist/client/{useAvailableSlots-wmdo6uZ8.mjs → useAvailableSlots-C3LphWDX.mjs} +8 -5
- package/dist/client/{useBookingNowIso-CUExAee1.mjs → useBookingNowIso-Da-f9iHw.mjs} +1 -1
- package/dist/client/{useDiscountApply-BRM-OoTN.mjs → useDiscountApply-SLoWhcen.mjs} +3 -3
- package/dist/client/{useDiscountCodeUi-BEIvL31G.mjs → useDiscountCodeUi-D6a2BJij.mjs} +1 -1
- package/dist/client/{useEventPagination-Dk3g64we.mjs → useEventPagination-Ccr4TZlm.mjs} +12 -159
- package/dist/client/{view-BnaOmrap.mjs → view-8w4GA8rf.mjs} +4 -4
- package/dist/client/{view-vhKGFfC3.mjs → view-DAVEoe8A.mjs} +310 -247
- package/dist/client/{wizardSteps-xqU4q63H.mjs → wizardSteps-DNpajrAH.mjs} +495 -173
- package/dist/preview-next/before-render.mjs +4 -141
- package/dist/preview-next/client/ArrangementLookControls-DY5TzhEa.mjs +31197 -0
- package/dist/preview-next/client/{EventEmbeddedCheckoutStep-43wIAWr4.mjs → EventEmbeddedCheckoutStep-C_h1cMYm.mjs} +33 -4
- package/dist/preview-next/client/{LocationPickerEnvironment-QtSG2Bl-.mjs → LocationPickerEnvironment-D56RD3e_.mjs} +1 -1
- package/dist/preview-next/client/{MapLibreEditMap-B-rohNcG.mjs → MapLibreEditMap-DFnyCckr.mjs} +2 -2
- package/dist/preview-next/client/PreviewEditorSidebar-DdnhmdFO.mjs +37049 -0
- package/dist/preview-next/client/PreviewEditorUI-C7ZmYE33.mjs +1189 -0
- package/dist/preview-next/client/PreviewShell-DnO38NaL.mjs +4707 -0
- package/dist/preview-next/client/SdkPreviewModeRuntime-D2OtoRMB.mjs +4258 -0
- package/dist/preview-next/client/SiteChromeCustomizeButton-eIu2RejJ.mjs +71144 -0
- package/dist/preview-next/client/ThemedButton-C0dgGJ5k.mjs +2006 -0
- package/dist/preview-next/client/{lucide-react-CA9cpo0P.mjs → lucide-react-CPBCf6QT.mjs} +15 -2
- package/dist/preview-next/client/previewAssistantSlot-Bp1AlAxx.mjs +110560 -0
- package/dist/preview-next/client/previewChromeSurface-D2cREDJ5.mjs +190 -0
- package/dist/preview-next/client/runtime.mjs +3 -3
- package/dist/preview-next/client/sdk-runtime-DK0PUhLL.mjs +5 -0
- package/dist/preview-next/client/useAutosaveStatus--Pw8vnef.mjs +138 -0
- package/dist/preview-next/client/useBlockCustomizeControls-C1Rl73N4.mjs +2724 -0
- package/dist/preview-next/client/useOpenBlockForSetup-CL3842FM.mjs +28 -0
- package/dist/preview-next/keepAlive.mjs +27 -4
- package/dist/preview-next/middleware.mjs +2 -2
- package/dist/preview-next/{route-contract-D5tHZEz5.mjs → route-contract-Bq7SUX3K.mjs} +143 -126
- package/dist/preview-next/{session-P1R_ajT7.mjs → session-DU6zpYUQ.mjs} +1 -1
- package/dist/preview-next/session.mjs +1 -1
- package/dist/server/{Block.shared-Iy7g11iP.mjs → Block.shared-wXr7Iwhs.mjs} +7 -4
- package/dist/server/{src-cbbK3Bho.mjs → ThemeScopeCore-BI2mld9R.mjs} +1153 -2523
- package/dist/server/accessibleSurfaces-CuN8U_iU.mjs +2102 -0
- package/dist/server/{bindings-BVJGgUT0.mjs → bindings-DjdUq9FR.mjs} +2 -3
- package/dist/server/{publicProducts-D3Fc5TKk.mjs → client-07UeMDzA.mjs} +2492 -357
- package/dist/server/config-validation.mjs +1 -1
- package/dist/server/config.mjs +33 -2
- package/dist/server/data/dataLoaderContext.mjs +2 -0
- package/dist/server/data/resolveBlockData.mjs +2 -0
- package/dist/server/data/types.mjs +1 -0
- package/dist/server/dataLoaderContext-B3fXA54R.mjs +47 -0
- package/dist/server/identity-Bn9OQiT1.mjs +6 -0
- package/dist/server/index.mjs +3 -3
- package/dist/server/{loadContent-BuintpdO.mjs → loadContent-ClpaSlBb.mjs} +6 -5
- package/dist/server/{loadPage-Dk4wea8M.mjs → loadPage-BwtVqpaA.mjs} +4 -2
- package/dist/server/manifest.mjs +1 -1
- package/dist/server/media-DnlczCMA.mjs +231 -0
- package/dist/server/mode-Cv_TG9gP.mjs +63 -0
- package/dist/server/next/middleware.mjs +1 -1
- package/dist/server/next/revalidate.mjs +1 -1
- package/dist/server/next.mjs +13 -13
- package/dist/server/opaqueSurface-3YSDPtDe.mjs +54 -0
- package/dist/server/{overrideResolution-BDiQWM7D.mjs → overrideResolution-Du_w3LY4.mjs} +2 -1
- package/dist/server/overrides-CD4d-1w7.mjs +177 -0
- package/dist/server/page-converter.mjs +243 -91
- package/dist/server/pageRenderPlan-BShULdc2.mjs +4055 -0
- package/dist/server/{themeAdmission-BdY8lP-K.mjs → pageRuntimeSupport-C4Dh5-mB.mjs} +13 -28
- package/dist/server/{overrides-DVemf-GV.mjs → pageShared-HdKFBpaX.mjs} +3594 -1726
- package/dist/server/parseThemeForPersistence-CJMrEkze.mjs +52 -0
- package/dist/server/{prebuild-DubLNgRH.mjs → prebuild-Cl-bkaMA.mjs} +1 -1
- package/dist/server/prebuild.mjs +1 -1
- package/dist/server/prefetchBlockData-C4yUmz-r.mjs +786 -0
- package/dist/server/publicProducts-W9hDRwjz.mjs +64 -0
- package/dist/server/{registry-zjd1P2Dl.mjs → registry-TFPJdGQi.mjs} +20901 -792
- package/dist/server/rendering/components/pageShared.mjs +2 -0
- package/dist/server/rendering/helpers/loadPage.mjs +2 -0
- package/dist/server/rendering/helpers/pageRuntimeSupport.mjs +2 -0
- package/dist/server/rendering/server.mjs +5 -4
- package/dist/server/rendering/themeAdmission.mjs +2 -0
- package/dist/server/rendering.mjs +11 -10
- package/dist/server/repeaterFields-MIz7r1ez.mjs +9 -0
- package/dist/server/{resolveBlockData-CZJ--nH6.mjs → resolveBlockData-OHlOXlOE.mjs} +6 -48
- package/dist/server/resolveButtonColourStates-lry2ORwX.mjs +2672 -0
- package/dist/server/{richTextSchema-YYc85FX4.mjs → richTextSchema-Euhuj-7V.mjs} +26 -1
- package/dist/server/routing.mjs +1 -1
- package/dist/server/schema-C2PqHrMo.mjs +2523 -0
- package/dist/server/server.mjs +3 -3
- package/dist/server/theme-bridge.mjs +1031 -1
- package/dist/server/theme.mjs +2 -1
- package/dist/server/themeAdmission-DGSAlFUK.mjs +18 -0
- package/dist/server/{three-pass-converter-Chnb1XD-.mjs → three-pass-converter-_j2UE2tR.mjs} +1 -1
- package/dist/server/validation-CDd6m8Ry.mjs +140 -0
- package/dist/server/{validation-CGH-Xs4E.mjs → validation-DIBFZeMB.mjs} +419 -3
- package/dist/server/{version-DoOG6F13.mjs → version-DZWZM1H6.mjs} +1 -1
- package/dist/styles/index.css +924 -10
- package/package.json +39 -1
- package/dist/_dts/previewCompiler-BVVgDSdq.d.ts +0 -1
- package/dist/client/cta-ChiN1Vgg.mjs +0 -80
- package/dist/client/purchase-BMsWpx8y.mjs +0 -894
- package/dist/client/schema-DMUkBtIO.mjs +0 -15915
- package/dist/client/site-styles-BLHYJ8S7.mjs +0 -12339
- package/dist/client/src-VIsPY-kw.mjs +0 -62
- package/dist/preview-next/client/PreviewEditorSidebar-C3AQVxQt.mjs +0 -5441
- package/dist/preview-next/client/PreviewEditorUI-C-1zDCR_.mjs +0 -756
- package/dist/preview-next/client/SdkPreviewModeRuntime-B47yHFL0.mjs +0 -9130
- package/dist/preview-next/client/SdkPreviewModeRuntime-C6Rhm2NQ.mjs +0 -3
- package/dist/preview-next/client/previewAuthStore-By_zfrS5.mjs +0 -212195
- package/dist/preview-next/client/previewChromeSurface-Cjwxv90x.mjs +0 -85
- package/dist/preview-next/client/result-BjJUoxUF.mjs +0 -16
- package/dist/preview-next/client/sdk-runtime-BG2HYvQj.mjs +0 -4
- package/dist/preview-next/client/siteStyleAccess-BiSyYyyr.mjs +0 -14178
- package/dist/preview-next/client/spinner-DnWpeDp2.mjs +0 -67
- package/dist/preview-next/refresh-contract-uQ6BXgLJ.mjs +0 -25
- package/dist/server/bindings-Dgt_0goJ.mjs +0 -17
- package/dist/server/client-CiKaE8ms.mjs +0 -2330
- package/dist/server/effectiveNavLinkStyle-EDSdd_oK.mjs +0 -11574
- package/dist/server/loadPage-BwjncpJf.mjs +0 -2
- package/dist/server/prefetchBlockData-Bnbwoe5n.mjs +0 -4156
- package/dist/server/schema-BlTWmTSl.mjs +0 -16142
- package/dist/server/site-styles-yHytcXIB.mjs +0 -768
- package/dist/server/siteChromeOverlayClearance-D0uCNZ7E.mjs +0 -802
|
@@ -0,0 +1,2672 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
//#region ../theme-core/src/tokens/colorTokenParts.ts
|
|
3
|
+
function parseOpacityPercent(source) {
|
|
4
|
+
const trimmed = source.trim();
|
|
5
|
+
if (!trimmed) return null;
|
|
6
|
+
if (!/^\d{1,3}(?:\.\d+)?$/.test(trimmed)) return null;
|
|
7
|
+
const value = Number(trimmed);
|
|
8
|
+
if (!Number.isFinite(value)) return null;
|
|
9
|
+
if (value < 0 || value > 100) return null;
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function parseColorTokenParts(source) {
|
|
13
|
+
const trimmed = source.trim();
|
|
14
|
+
if (trimmed.startsWith("raw:")) return {
|
|
15
|
+
kind: "raw",
|
|
16
|
+
value: trimmed.slice(4)
|
|
17
|
+
};
|
|
18
|
+
const [token, opacityRaw, extra] = trimmed.split("/");
|
|
19
|
+
if (!token || extra !== void 0) return {
|
|
20
|
+
kind: "invalid",
|
|
21
|
+
token: trimmed
|
|
22
|
+
};
|
|
23
|
+
if (opacityRaw === void 0) return {
|
|
24
|
+
kind: "token",
|
|
25
|
+
token,
|
|
26
|
+
opacityPercent: null
|
|
27
|
+
};
|
|
28
|
+
const opacityPercent = parseOpacityPercent(opacityRaw);
|
|
29
|
+
if (opacityPercent === null) return {
|
|
30
|
+
kind: "invalid",
|
|
31
|
+
token: trimmed
|
|
32
|
+
};
|
|
33
|
+
return {
|
|
34
|
+
kind: "token",
|
|
35
|
+
token,
|
|
36
|
+
opacityPercent
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region ../theme-core/src/tokens/blockColorTokens.ts
|
|
41
|
+
const blockColorTokenNames = [
|
|
42
|
+
"text",
|
|
43
|
+
"heading",
|
|
44
|
+
"mutedText",
|
|
45
|
+
"surface",
|
|
46
|
+
"background",
|
|
47
|
+
"foreground",
|
|
48
|
+
"border",
|
|
49
|
+
"primary",
|
|
50
|
+
"secondary",
|
|
51
|
+
"accent",
|
|
52
|
+
"success",
|
|
53
|
+
"warning",
|
|
54
|
+
"info",
|
|
55
|
+
"error",
|
|
56
|
+
"destructive",
|
|
57
|
+
"scrim",
|
|
58
|
+
"shadow",
|
|
59
|
+
"onPrimary",
|
|
60
|
+
"onSecondary",
|
|
61
|
+
"onAccent",
|
|
62
|
+
"onSuccess",
|
|
63
|
+
"onWarning",
|
|
64
|
+
"onInfo",
|
|
65
|
+
"onError",
|
|
66
|
+
"onDestructive",
|
|
67
|
+
"onSurface",
|
|
68
|
+
"onText"
|
|
69
|
+
];
|
|
70
|
+
const blockColorTokenNameSet = new Set(blockColorTokenNames);
|
|
71
|
+
function isBlockColorToken(value) {
|
|
72
|
+
if (typeof value !== "string") return false;
|
|
73
|
+
const parts = parseColorTokenParts(value);
|
|
74
|
+
return parts.kind === "token" && blockColorTokenNameSet.has(parts.token);
|
|
75
|
+
}
|
|
76
|
+
function parseBlockColorToken(value) {
|
|
77
|
+
if (!isBlockColorToken(value)) return null;
|
|
78
|
+
return value.trim();
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region ../theme-core/src/tokens/themeColorTokens.ts
|
|
82
|
+
/**
|
|
83
|
+
* Known palette role token names. This is the low-level source of truth for
|
|
84
|
+
* palette roles used by palette variants, Theme V2 schemas, and runtime color
|
|
85
|
+
* reference parsing.
|
|
86
|
+
*/
|
|
87
|
+
const PALETTE_TOKEN_NAMES = [
|
|
88
|
+
"primary",
|
|
89
|
+
"primaryForeground",
|
|
90
|
+
"secondary",
|
|
91
|
+
"accent",
|
|
92
|
+
"success",
|
|
93
|
+
"warning",
|
|
94
|
+
"destructive",
|
|
95
|
+
"background",
|
|
96
|
+
"surface",
|
|
97
|
+
"surfaceAlt",
|
|
98
|
+
"muted",
|
|
99
|
+
"text",
|
|
100
|
+
"border"
|
|
101
|
+
];
|
|
102
|
+
const paletteTokenNameSchema = z.enum(PALETTE_TOKEN_NAMES);
|
|
103
|
+
const themeColorBaseTokenNames = [
|
|
104
|
+
...PALETTE_TOKEN_NAMES,
|
|
105
|
+
...blockColorTokenNames,
|
|
106
|
+
"white",
|
|
107
|
+
"neutral",
|
|
108
|
+
"primaryText",
|
|
109
|
+
"secondaryForeground",
|
|
110
|
+
"accentForeground"
|
|
111
|
+
];
|
|
112
|
+
const themeColorBaseTokenSet = new Set(themeColorBaseTokenNames);
|
|
113
|
+
const shadeStepSet = /* @__PURE__ */ new Set([
|
|
114
|
+
"50",
|
|
115
|
+
"100",
|
|
116
|
+
"200",
|
|
117
|
+
"300",
|
|
118
|
+
"400",
|
|
119
|
+
"500",
|
|
120
|
+
"600",
|
|
121
|
+
"700",
|
|
122
|
+
"800",
|
|
123
|
+
"900",
|
|
124
|
+
"950"
|
|
125
|
+
]);
|
|
126
|
+
function isKnownBaseToken(value) {
|
|
127
|
+
return themeColorBaseTokenSet.has(value);
|
|
128
|
+
}
|
|
129
|
+
function isKnownShadeToken(value) {
|
|
130
|
+
const match = value.match(/^([a-zA-Z][a-zA-Z0-9]*)(?:-([0-9]{2,3}))$/);
|
|
131
|
+
if (!match) return false;
|
|
132
|
+
const [, base, shade] = match;
|
|
133
|
+
return Boolean(base && shade && isKnownBaseToken(base) && shadeStepSet.has(shade));
|
|
134
|
+
}
|
|
135
|
+
function isThemeColorTokenBase(value) {
|
|
136
|
+
return isKnownBaseToken(value) || isKnownShadeToken(value);
|
|
137
|
+
}
|
|
138
|
+
function isThemeColorToken(value) {
|
|
139
|
+
if (typeof value !== "string") return false;
|
|
140
|
+
const parts = parseColorTokenParts(value);
|
|
141
|
+
return parts.kind === "token" && isThemeColorTokenBase(parts.token);
|
|
142
|
+
}
|
|
143
|
+
function parseThemeColorToken(value) {
|
|
144
|
+
if (!isThemeColorToken(value)) return null;
|
|
145
|
+
return value.trim();
|
|
146
|
+
}
|
|
147
|
+
const themeColorTokenSchema = z.string().min(1).refine((value) => Boolean(isThemeColorToken(value)), "Expected a known Theme V2 color token");
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region ../theme-core/src/utils/colorStyles.ts
|
|
150
|
+
const COLOR_VAR_PREFIX = "--tb-";
|
|
151
|
+
function parseToken(source) {
|
|
152
|
+
const parts = parseColorTokenParts(source);
|
|
153
|
+
if (parts.kind === "raw") return {
|
|
154
|
+
token: source,
|
|
155
|
+
raw: parts.value
|
|
156
|
+
};
|
|
157
|
+
if (parts.kind === "invalid") return { token: source };
|
|
158
|
+
return {
|
|
159
|
+
token: parts.token,
|
|
160
|
+
opacityPercent: parts.opacityPercent === null ? void 0 : parts.opacityPercent
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const SURFACE_TEXT_ROLE_BY_TOKEN = {
|
|
164
|
+
text: "text",
|
|
165
|
+
heading: "heading",
|
|
166
|
+
mutedText: "supporting"
|
|
167
|
+
};
|
|
168
|
+
function surfaceRoleForTextToken(token) {
|
|
169
|
+
return Object.prototype.hasOwnProperty.call(SURFACE_TEXT_ROLE_BY_TOKEN, token) ? SURFACE_TEXT_ROLE_BY_TOKEN[token] : null;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Converts a theme color token to a CSS rgb value.
|
|
173
|
+
* This is the primary function for applying theme colors to CSS properties.
|
|
174
|
+
*
|
|
175
|
+
* @param token - Theme color token (semantic, with opacity, or raw)
|
|
176
|
+
* @returns CSS color value (rgb with optional alpha, or raw CSS value)
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* rgbColorValue('primary') // => 'rgb(var(--tb-primary))'
|
|
180
|
+
* rgbColorValue('surface/95') // => 'rgb(var(--tb-surface) / 0.95)'
|
|
181
|
+
* rgbColorValue('raw:transparent') // => 'transparent'
|
|
182
|
+
*/
|
|
183
|
+
function rgbColorValue(token) {
|
|
184
|
+
const { token: baseToken, opacityPercent, raw } = parseToken(token);
|
|
185
|
+
if (raw) return raw;
|
|
186
|
+
const cssVar = `${COLOR_VAR_PREFIX}${baseToken}`;
|
|
187
|
+
if (opacityPercent === void 0) return `rgb(var(${cssVar}))`;
|
|
188
|
+
return `rgb(var(${cssVar}) / ${opacityPercent / 100})`;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Converts a theme color token to a CSS variable reference.
|
|
192
|
+
* Note: This returns the base variable without rgb() wrapper, ignoring opacity.
|
|
193
|
+
*
|
|
194
|
+
* @param token - Theme color token
|
|
195
|
+
* @returns CSS variable reference
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* cssVarValue('primary') // => 'var(--tb-primary)'
|
|
199
|
+
* cssVarValue('surface/95') // => 'var(--tb-surface)' (opacity ignored)
|
|
200
|
+
*/
|
|
201
|
+
function cssVarValue(token) {
|
|
202
|
+
const { token: baseToken } = parseToken(token);
|
|
203
|
+
return `var(${COLOR_VAR_PREFIX}${baseToken})`;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Creates a backgroundColor style object from a theme token.
|
|
207
|
+
*
|
|
208
|
+
* @param token - Theme color token
|
|
209
|
+
* @returns CSSProperties with backgroundColor
|
|
210
|
+
*/
|
|
211
|
+
function backgroundColorStyle(token) {
|
|
212
|
+
return { backgroundColor: rgbColorValue(token) };
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Converts a text color token to a CSS color value that follows the enclosing
|
|
216
|
+
* surface. The semantic text tokens (`text`, `heading`, `mutedText`) resolve
|
|
217
|
+
* to the surface foreground variables, so text adapts when a section's
|
|
218
|
+
* background changes; any other token is a fixed theme color.
|
|
219
|
+
*
|
|
220
|
+
* @param token - Theme color token
|
|
221
|
+
* @returns CSS color value
|
|
222
|
+
*/
|
|
223
|
+
function textColorValue(token) {
|
|
224
|
+
const parsed = parseToken(token);
|
|
225
|
+
const surfaceRole = parsed.raw ? null : surfaceRoleForTextToken(parsed.token);
|
|
226
|
+
if (!surfaceRole) return rgbColorValue(token);
|
|
227
|
+
return parsed.opacityPercent === void 0 ? surfaceForegroundValue(surfaceRole) : surfaceForegroundValueWithOpacity(surfaceRole, parsed.opacityPercent);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Creates a text color style object from a theme token.
|
|
231
|
+
*
|
|
232
|
+
* @param token - Theme color token
|
|
233
|
+
* @returns CSSProperties with color
|
|
234
|
+
*/
|
|
235
|
+
function textColorStyle(token) {
|
|
236
|
+
return { color: textColorValue(token) };
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Creates a border color style object from a theme token.
|
|
240
|
+
*
|
|
241
|
+
* @param token - Theme color token
|
|
242
|
+
* @returns CSSProperties with borderColor
|
|
243
|
+
*/
|
|
244
|
+
function borderColorStyle(token) {
|
|
245
|
+
return { borderColor: rgbColorValue(token) };
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Merges multiple CSSProperties objects into a single object.
|
|
249
|
+
* Later styles override earlier ones. Undefined values are filtered out.
|
|
250
|
+
* Returns undefined if the merged result is empty.
|
|
251
|
+
*
|
|
252
|
+
* @param styles - Variable number of CSSProperties objects (can be undefined)
|
|
253
|
+
* @returns Merged CSSProperties object, or undefined if empty
|
|
254
|
+
*
|
|
255
|
+
* @example
|
|
256
|
+
* mergeStyles(
|
|
257
|
+
* backgroundColorStyle('surface'),
|
|
258
|
+
* textColorStyle('text'),
|
|
259
|
+
* borderColorStyle('border')
|
|
260
|
+
* )
|
|
261
|
+
* // => { backgroundColor: '...', color: '...', borderColor: '...' }
|
|
262
|
+
*/
|
|
263
|
+
function mergeStyles(...styles) {
|
|
264
|
+
const merged = {};
|
|
265
|
+
for (const style of styles) {
|
|
266
|
+
if (!style) continue;
|
|
267
|
+
Object.assign(merged, style);
|
|
268
|
+
}
|
|
269
|
+
return Object.keys(merged).length ? merged : void 0;
|
|
270
|
+
}
|
|
271
|
+
//#endregion
|
|
272
|
+
//#region ../theme-core/src/surfaces/foregroundContract.ts
|
|
273
|
+
const SURFACE_FOREGROUND_CSS_VARS = {
|
|
274
|
+
text: "--rb-surface-text-color",
|
|
275
|
+
heading: "--rb-surface-heading-color",
|
|
276
|
+
link: "--rb-surface-link-color",
|
|
277
|
+
linkHover: "--rb-surface-link-hover-color",
|
|
278
|
+
supporting: "--rb-surface-supporting-color",
|
|
279
|
+
muted: "--rb-surface-muted-color",
|
|
280
|
+
line: "--rb-surface-line-color",
|
|
281
|
+
mark: "--rb-surface-mark-color"
|
|
282
|
+
};
|
|
283
|
+
const DEFAULT_SURFACE_TEXT_COLOR = "rgb(var(--tb-text, 17 24 39))";
|
|
284
|
+
const DEFAULT_SURFACE_LINK_COLOR = "rgb(var(--tb-primary, var(--tb-text, 17 24 39)))";
|
|
285
|
+
const DEFAULT_SURFACE_SUPPORTING_COLOR = "rgb(var(--tb-mutedText, 100 116 139))";
|
|
286
|
+
const DEFAULT_ROLE_FALLBACKS = {
|
|
287
|
+
text: DEFAULT_SURFACE_TEXT_COLOR,
|
|
288
|
+
heading: DEFAULT_SURFACE_TEXT_COLOR,
|
|
289
|
+
link: DEFAULT_SURFACE_LINK_COLOR,
|
|
290
|
+
linkHover: DEFAULT_SURFACE_LINK_COLOR,
|
|
291
|
+
supporting: DEFAULT_SURFACE_SUPPORTING_COLOR,
|
|
292
|
+
muted: DEFAULT_SURFACE_SUPPORTING_COLOR
|
|
293
|
+
};
|
|
294
|
+
function requireSurfaceColorValue(role, value) {
|
|
295
|
+
const normalized = value.trim();
|
|
296
|
+
if (normalized.length === 0) throw new RangeError(`Surface foreground ${role} must be a non-empty CSS color.`);
|
|
297
|
+
return normalized;
|
|
298
|
+
}
|
|
299
|
+
function completeSurfaceForegrounds(input) {
|
|
300
|
+
const text = requireSurfaceColorValue("text", input.text);
|
|
301
|
+
const link = input.link === void 0 ? text : requireSurfaceColorValue("link", input.link);
|
|
302
|
+
return {
|
|
303
|
+
text,
|
|
304
|
+
heading: input.heading === void 0 ? text : requireSurfaceColorValue("heading", input.heading),
|
|
305
|
+
link,
|
|
306
|
+
linkHover: input.linkHover === void 0 ? link : requireSurfaceColorValue("linkHover", input.linkHover),
|
|
307
|
+
muted: input.muted === void 0 ? text : requireSurfaceColorValue("muted", input.muted),
|
|
308
|
+
supporting: input.supporting === void 0 ? text : requireSurfaceColorValue("supporting", input.supporting)
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function surfaceForegroundValue(role, outsideProviderFallback = DEFAULT_ROLE_FALLBACKS[role]) {
|
|
312
|
+
const roleVariable = SURFACE_FOREGROUND_CSS_VARS[role];
|
|
313
|
+
const fallback = requireSurfaceColorValue("fallback", outsideProviderFallback);
|
|
314
|
+
if (role === "text") return `var(${roleVariable}, ${fallback})`;
|
|
315
|
+
if (role === "linkHover") return `var(${roleVariable}, ${surfaceForegroundValue("link", fallback)})`;
|
|
316
|
+
return `var(${roleVariable}, var(${SURFACE_FOREGROUND_CSS_VARS.text}, ${fallback}))`;
|
|
317
|
+
}
|
|
318
|
+
/** The three solved inks, published beside the foreground roles by the same surfaces. */
|
|
319
|
+
const SURFACE_INK_CSS_VARS = {
|
|
320
|
+
brand: "--rb-surface-brand-color",
|
|
321
|
+
accent: "--rb-surface-accent-color",
|
|
322
|
+
focus: "--rb-surface-focus-color"
|
|
323
|
+
};
|
|
324
|
+
/**
|
|
325
|
+
* The declarations for a surface's ink publication. An exact ink is a token
|
|
326
|
+
* reference (`rgb(var(--tb-primary))`), so a site's own token value wins; a
|
|
327
|
+
* nudged or replaced ink is a literal colour.
|
|
328
|
+
*/
|
|
329
|
+
function surfaceInkStyle(publication) {
|
|
330
|
+
switch (publication.kind) {
|
|
331
|
+
case "none": return {};
|
|
332
|
+
case "reset": return inkVariables(() => "initial");
|
|
333
|
+
case "solved": return inkVariables((role) => {
|
|
334
|
+
const ink = publication.inks[role];
|
|
335
|
+
const token = parseThemeColorToken(ink);
|
|
336
|
+
return token ? rgbColorValue(token) : ink;
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
function surfaceInkDeclarations(publication) {
|
|
341
|
+
return Object.entries(surfaceInkStyle(publication)).map(([property, value]) => `${property}: ${value};`);
|
|
342
|
+
}
|
|
343
|
+
function inkVariables(value) {
|
|
344
|
+
return {
|
|
345
|
+
[SURFACE_INK_CSS_VARS.brand]: value("brand"),
|
|
346
|
+
[SURFACE_INK_CSS_VARS.accent]: value("accent"),
|
|
347
|
+
[SURFACE_INK_CSS_VARS.focus]: value("focus")
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function surfaceForegroundValueWithOpacity(role, opacityPercent) {
|
|
351
|
+
if (!Number.isFinite(opacityPercent) || opacityPercent < 0 || opacityPercent > 100) throw new RangeError("Surface foreground opacity must be between 0 and 100.");
|
|
352
|
+
return `color-mix(in srgb, ${surfaceForegroundValue(role)} ${opacityPercent}%, transparent)`;
|
|
353
|
+
}
|
|
354
|
+
function surfaceForegroundStyle(input) {
|
|
355
|
+
const foregrounds = completeSurfaceForegrounds(input);
|
|
356
|
+
return {
|
|
357
|
+
color: foregrounds.text,
|
|
358
|
+
[SURFACE_FOREGROUND_CSS_VARS.text]: foregrounds.text,
|
|
359
|
+
[SURFACE_FOREGROUND_CSS_VARS.heading]: foregrounds.heading,
|
|
360
|
+
[SURFACE_FOREGROUND_CSS_VARS.link]: foregrounds.link,
|
|
361
|
+
[SURFACE_FOREGROUND_CSS_VARS.linkHover]: foregrounds.linkHover,
|
|
362
|
+
[SURFACE_FOREGROUND_CSS_VARS.supporting]: foregrounds.supporting,
|
|
363
|
+
...input.muted === void 0 ? {} : { [SURFACE_FOREGROUND_CSS_VARS.muted]: foregrounds.muted },
|
|
364
|
+
"--rb-surface-link-hover-decoration": hoverDecoration(input)
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
function surfaceForegroundDeclarations(input) {
|
|
368
|
+
return Object.entries(surfaceForegroundStyle(input)).map(([property, value]) => `${property}: ${value};`);
|
|
369
|
+
}
|
|
370
|
+
function surfaceForegroundInputFromResolved(foreground, color) {
|
|
371
|
+
const { roles } = foreground;
|
|
372
|
+
const value = (ink) => {
|
|
373
|
+
const token = parseThemeColorToken(ink);
|
|
374
|
+
return token ? color(token) : ink;
|
|
375
|
+
};
|
|
376
|
+
return {
|
|
377
|
+
text: value(roles.text),
|
|
378
|
+
heading: value(roles.heading),
|
|
379
|
+
link: value(roles.link),
|
|
380
|
+
linkHover: value(roles.linkHover),
|
|
381
|
+
supporting: value(roles.supporting),
|
|
382
|
+
hoverDecoration: foreground.hoverDecoration
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
function hoverDecoration(input) {
|
|
386
|
+
return input.hoverDecoration ?? "underline";
|
|
387
|
+
}
|
|
388
|
+
//#endregion
|
|
389
|
+
//#region ../theme-core/src/palette/utils/colorConversion.ts
|
|
390
|
+
const clamp01 = (x) => Math.max(0, Math.min(1, x));
|
|
391
|
+
const mod = (a, n) => (a % n + n) % n;
|
|
392
|
+
const deg = (x) => mod(x, 360);
|
|
393
|
+
const mix$1 = (a, b, t) => a + (b - a) * clamp01(t);
|
|
394
|
+
function hexToRgb(hex) {
|
|
395
|
+
const h = hex.replace(/^#/, "");
|
|
396
|
+
const m = h.length === 3 ? h.split("").map((c) => c + c).join("") : h;
|
|
397
|
+
if (m.length !== 6) throw new Error("Bad hex");
|
|
398
|
+
const int = parseInt(m, 16);
|
|
399
|
+
return {
|
|
400
|
+
r: int >> 16 & 255,
|
|
401
|
+
g: int >> 8 & 255,
|
|
402
|
+
b: int & 255
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
function rgbToHex(r, g, b) {
|
|
406
|
+
const to = (n) => Math.round(n).toString(16).padStart(2, "0");
|
|
407
|
+
return `#${to(r)}${to(g)}${to(b)}`;
|
|
408
|
+
}
|
|
409
|
+
function srgbToLinear(u) {
|
|
410
|
+
const x = u / 255;
|
|
411
|
+
return x <= .04045 ? x / 12.92 : Math.pow((x + .055) / 1.055, 2.4);
|
|
412
|
+
}
|
|
413
|
+
function linearToSrgb(x) {
|
|
414
|
+
return clamp01(x <= .0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - .055) * 255;
|
|
415
|
+
}
|
|
416
|
+
function rgbToHsl(r, g, b) {
|
|
417
|
+
const R = r / 255, G = g / 255, B = b / 255;
|
|
418
|
+
const max = Math.max(R, G, B), min = Math.min(R, G, B);
|
|
419
|
+
const d = max - min;
|
|
420
|
+
let h = 0;
|
|
421
|
+
if (d !== 0) {
|
|
422
|
+
switch (max) {
|
|
423
|
+
case R:
|
|
424
|
+
h = (G - B) / d + (G < B ? 6 : 0);
|
|
425
|
+
break;
|
|
426
|
+
case G:
|
|
427
|
+
h = (B - R) / d + 2;
|
|
428
|
+
break;
|
|
429
|
+
case B:
|
|
430
|
+
h = (R - G) / d + 4;
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
h *= 60;
|
|
434
|
+
}
|
|
435
|
+
const l = (max + min) / 2;
|
|
436
|
+
const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
|
|
437
|
+
return {
|
|
438
|
+
h,
|
|
439
|
+
s,
|
|
440
|
+
l
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
function srgbToOklab(r, g, b) {
|
|
444
|
+
const R = srgbToLinear(r), G = srgbToLinear(g), B = srgbToLinear(b);
|
|
445
|
+
const l = .4122214708 * R + .5363325363 * G + .0514459929 * B;
|
|
446
|
+
const m = .2119034982 * R + .6806995451 * G + .1073969566 * B;
|
|
447
|
+
const s = .0883024619 * R + .2817188376 * G + .6299787005 * B;
|
|
448
|
+
const l_ = Math.cbrt(l), m_ = Math.cbrt(m), s_ = Math.cbrt(s);
|
|
449
|
+
return {
|
|
450
|
+
L: .2104542553 * l_ + .793617785 * m_ - .0040720468 * s_,
|
|
451
|
+
a: 1.9779984951 * l_ - 2.428592205 * m_ + .4505937099 * s_,
|
|
452
|
+
b: .0259040371 * l_ + .7827717662 * m_ - .808675766 * s_
|
|
453
|
+
};
|
|
454
|
+
}
|
|
455
|
+
/** OKLab to linear sRGB, unclamped. The one owner of this matrix. */
|
|
456
|
+
function oklabToLinearSrgb(L, a, b) {
|
|
457
|
+
const l_ = Math.pow(L + .3963377774 * a + .2158037573 * b, 3);
|
|
458
|
+
const m_ = Math.pow(L - .1055613458 * a - .0638541728 * b, 3);
|
|
459
|
+
const s_ = Math.pow(L - .0894841775 * a - 1.291485548 * b, 3);
|
|
460
|
+
return {
|
|
461
|
+
r: 4.0767416621 * l_ - 3.3077115913 * m_ + .2309699292 * s_,
|
|
462
|
+
g: -1.2684380046 * l_ + 2.6097574011 * m_ - .3413193965 * s_,
|
|
463
|
+
b: -.0041960863 * l_ - .7034186147 * m_ + 1.707614701 * s_
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
function oklabToSrgb(L, a, b) {
|
|
467
|
+
const { r, g, b: B } = oklabToLinearSrgb(L, a, b);
|
|
468
|
+
return {
|
|
469
|
+
r: linearToSrgb(r),
|
|
470
|
+
g: linearToSrgb(g),
|
|
471
|
+
b: linearToSrgb(B)
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
function oklabToOklch(L, a, b) {
|
|
475
|
+
const C = Math.sqrt(a * a + b * b);
|
|
476
|
+
return {
|
|
477
|
+
L,
|
|
478
|
+
C,
|
|
479
|
+
h: C < 1e-7 ? 0 : deg(Math.atan2(b, a) * 180 / Math.PI)
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
function oklchToOklab(L, C, h) {
|
|
483
|
+
const hr = h * Math.PI / 180;
|
|
484
|
+
return {
|
|
485
|
+
L,
|
|
486
|
+
a: C * Math.cos(hr),
|
|
487
|
+
b: C * Math.sin(hr)
|
|
488
|
+
};
|
|
489
|
+
}
|
|
490
|
+
function inSRGB(r, g, b) {
|
|
491
|
+
return r >= 0 && r <= 255 && g >= 0 && g <= 255 && b >= 0 && b <= 255;
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* OKLCH to linear sRGB with no clamping, so a gamut test can see a channel
|
|
495
|
+
* that leaves [0, 1]. `oklabToSrgb` clamps before `inSRGB` looks, which is why
|
|
496
|
+
* `oklchToHexGamut` can clip; that function is left alone on purpose, because
|
|
497
|
+
* changing it would move every generated shade on live sites (issue 1633).
|
|
498
|
+
*/
|
|
499
|
+
function oklchToLinearSrgb(L, C, h) {
|
|
500
|
+
const { a, b } = oklchToOklab(L, C, h);
|
|
501
|
+
return oklabToLinearSrgb(L, a, b);
|
|
502
|
+
}
|
|
503
|
+
function inLinearSrgbGamut(rgb) {
|
|
504
|
+
return [
|
|
505
|
+
rgb.r,
|
|
506
|
+
rgb.g,
|
|
507
|
+
rgb.b
|
|
508
|
+
].every((v) => v >= -1e-6 && v <= 1.000001);
|
|
509
|
+
}
|
|
510
|
+
function oklchToHexGamut(L, C, h) {
|
|
511
|
+
let lo = 0, hi = C, best = 0;
|
|
512
|
+
for (let i = 0; i < 18; i++) {
|
|
513
|
+
const mid = (lo + hi) / 2;
|
|
514
|
+
const { a, b } = oklchToOklab(L, mid, h);
|
|
515
|
+
const { r, g, b: bb } = oklabToSrgb(L, a, b);
|
|
516
|
+
if (inSRGB(r, g, bb)) {
|
|
517
|
+
best = mid;
|
|
518
|
+
lo = mid;
|
|
519
|
+
} else hi = mid;
|
|
520
|
+
}
|
|
521
|
+
const { a, b } = oklchToOklab(L, best, h);
|
|
522
|
+
const { r, g, b: bb } = oklabToSrgb(L, a, b);
|
|
523
|
+
return rgbToHex(r, g, bb);
|
|
524
|
+
}
|
|
525
|
+
function featuresFromHex(hex) {
|
|
526
|
+
const { r, g, b } = hexToRgb(hex);
|
|
527
|
+
const { h, s, l } = rgbToHsl(r, g, b);
|
|
528
|
+
const { L, a, b: b2 } = srgbToOklab(r, g, b);
|
|
529
|
+
const { L: okL, C: okC, h: okH } = oklabToOklch(L, a, b2);
|
|
530
|
+
return {
|
|
531
|
+
r,
|
|
532
|
+
g,
|
|
533
|
+
b,
|
|
534
|
+
h,
|
|
535
|
+
s,
|
|
536
|
+
l,
|
|
537
|
+
v: Math.max(r, g, b) / 255,
|
|
538
|
+
Y: .2126 * srgbToLinear(r) + .7152 * srgbToLinear(g) + .0722 * srgbToLinear(b),
|
|
539
|
+
chroma: s,
|
|
540
|
+
okL,
|
|
541
|
+
okC,
|
|
542
|
+
okH,
|
|
543
|
+
hex
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
//#endregion
|
|
547
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/checkPrivateRedeclaration.js
|
|
548
|
+
function _checkPrivateRedeclaration(e, t) {
|
|
549
|
+
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
550
|
+
}
|
|
551
|
+
//#endregion
|
|
552
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/classPrivateFieldInitSpec.js
|
|
553
|
+
function _classPrivateFieldInitSpec(e, t, a) {
|
|
554
|
+
_checkPrivateRedeclaration(e, t), t.set(e, a);
|
|
555
|
+
}
|
|
556
|
+
//#endregion
|
|
557
|
+
//#region ../theme-core/src/palette/utils/contrast.ts
|
|
558
|
+
const ORDINARY_TEXT_MIN_CONTRAST_RATIO = 4.5;
|
|
559
|
+
function relativeLuminance(r, g, b) {
|
|
560
|
+
const R = srgbToLinear(r), G = srgbToLinear(g), B = srgbToLinear(b);
|
|
561
|
+
return .2126 * R + .7152 * G + .0722 * B;
|
|
562
|
+
}
|
|
563
|
+
function preparePaletteColourIndex(palette) {
|
|
564
|
+
const colours = [.../* @__PURE__ */ new Set([
|
|
565
|
+
...Object.values(palette),
|
|
566
|
+
"#000000",
|
|
567
|
+
"#ffffff",
|
|
568
|
+
"#FFFFFF"
|
|
569
|
+
])];
|
|
570
|
+
return Object.freeze(Object.fromEntries(colours.flatMap(colourIndexEntry)));
|
|
571
|
+
}
|
|
572
|
+
/** An unused unsupported colour must not turn preparation into an eager validation failure. */
|
|
573
|
+
function colourIndexEntry(hex) {
|
|
574
|
+
try {
|
|
575
|
+
return [[hex, colourLuminance(hex)]];
|
|
576
|
+
} catch {
|
|
577
|
+
return [];
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
function colourLuminance(hex) {
|
|
581
|
+
const { r, g, b } = hexToRgb(hex);
|
|
582
|
+
return relativeLuminance(r, g, b);
|
|
583
|
+
}
|
|
584
|
+
function indexedLuminance(hex, index) {
|
|
585
|
+
return (index && Object.prototype.hasOwnProperty.call(index, hex) ? index[hex] : void 0) ?? colourLuminance(hex);
|
|
586
|
+
}
|
|
587
|
+
var _certified = /* @__PURE__ */ new WeakMap();
|
|
588
|
+
/**
|
|
589
|
+
* A closed luminance range with `lo <= hi`. The private field means only
|
|
590
|
+
* `luminanceInterval` and `solidPaint` can make one, so the solver can trust
|
|
591
|
+
* the ordering without checking it again. The class itself is not exported.
|
|
592
|
+
*/
|
|
593
|
+
var Interval = class {
|
|
594
|
+
constructor(lo, hi) {
|
|
595
|
+
this.lo = lo;
|
|
596
|
+
this.hi = hi;
|
|
597
|
+
_classPrivateFieldInitSpec(this, _certified, true);
|
|
598
|
+
}
|
|
599
|
+
};
|
|
600
|
+
function toLuminance(y) {
|
|
601
|
+
if (!Number.isFinite(y) || y < 0 || y > 1) throw new Error(`Luminance must be in [0, 1]: ${y}`);
|
|
602
|
+
return y;
|
|
603
|
+
}
|
|
604
|
+
function luminanceInterval(lo, hi = lo) {
|
|
605
|
+
if (toLuminance(lo) > toLuminance(hi)) throw new Error(`Empty luminance interval: [${lo}, ${hi}]`);
|
|
606
|
+
return new Interval(lo, hi);
|
|
607
|
+
}
|
|
608
|
+
/** The relative luminance of a hex colour, read from the prepared index when given. */
|
|
609
|
+
function hexLuminance(hex, index) {
|
|
610
|
+
return toLuminance(indexedLuminance(hex, index));
|
|
611
|
+
}
|
|
612
|
+
/** The paint of a solid hex ground: a single point. */
|
|
613
|
+
function solidPaint(hex, index) {
|
|
614
|
+
const y = hexLuminance(hex, index);
|
|
615
|
+
return new Interval(y, y);
|
|
616
|
+
}
|
|
617
|
+
function luminanceRatio(a, b) {
|
|
618
|
+
return a >= b ? (a + .05) / (b + .05) : (b + .05) / (a + .05);
|
|
619
|
+
}
|
|
620
|
+
/** The lowest contrast an ink of luminance `ink` has against any point of `paint`. */
|
|
621
|
+
function worstContrast(ink, paint) {
|
|
622
|
+
if (ink >= paint.lo && ink <= paint.hi) return 1;
|
|
623
|
+
return Math.min(luminanceRatio(ink, paint.lo), luminanceRatio(ink, paint.hi));
|
|
624
|
+
}
|
|
625
|
+
function assertContrastRatio(ratio) {
|
|
626
|
+
if (!Number.isFinite(ratio) || ratio <= 1 || ratio > 21) throw new Error(`Contrast ratio must be above 1 and at most 21: ${ratio}`);
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* The one black-or-white rule: literal black or white, whichever contrasts more
|
|
630
|
+
* with the whole paint (black on a tie). It always returns, even when neither
|
|
631
|
+
* reaches the ratio a caller wants; callers decide what a shortfall means.
|
|
632
|
+
* A style's preferred neutral is a separate input (`neutralInk`) and never
|
|
633
|
+
* part of this rule.
|
|
634
|
+
*/
|
|
635
|
+
function maxContrastBlackOrWhite(paint) {
|
|
636
|
+
const blackContrast = (paint.lo + .05) / .05;
|
|
637
|
+
const whiteContrast = 1.05 / (paint.hi + .05);
|
|
638
|
+
return blackContrast >= whiteContrast ? {
|
|
639
|
+
ink: "black",
|
|
640
|
+
ratio: blackContrast
|
|
641
|
+
} : {
|
|
642
|
+
ink: "white",
|
|
643
|
+
ratio: whiteContrast
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
function contrastRatio(hex1, hex2, index) {
|
|
647
|
+
const L1 = indexedLuminance(hex1, index);
|
|
648
|
+
const L2 = indexedLuminance(hex2, index);
|
|
649
|
+
const [hi, lo] = L1 >= L2 ? [L1, L2] : [L2, L1];
|
|
650
|
+
return (hi + .05) / (lo + .05);
|
|
651
|
+
}
|
|
652
|
+
//#endregion
|
|
653
|
+
//#region ../theme-core/src/palette/colors.ts
|
|
654
|
+
const HEX_COLOR_REGEX = /^#[0-9a-f]{6}$/;
|
|
655
|
+
const NORMALIZABLE_HEX_REGEX = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
|
|
656
|
+
const THEME_PALETTE_COLOR_ORDER = [
|
|
657
|
+
"primary",
|
|
658
|
+
"secondary",
|
|
659
|
+
"accent",
|
|
660
|
+
"success",
|
|
661
|
+
"warning",
|
|
662
|
+
"destructive",
|
|
663
|
+
"background",
|
|
664
|
+
"surface",
|
|
665
|
+
"surfaceAlt",
|
|
666
|
+
"muted",
|
|
667
|
+
"text",
|
|
668
|
+
"primaryForeground",
|
|
669
|
+
"border"
|
|
670
|
+
];
|
|
671
|
+
const hexColorSchema = z.string().regex(HEX_COLOR_REGEX, "Hex must be #RRGGBB (lowercase)").transform((value) => value);
|
|
672
|
+
const paletteModeSchema = z.enum(["light", "dark"]);
|
|
673
|
+
const PALETTE_VALUE_KEY_PREFIX = "palette-value:v1|";
|
|
674
|
+
z.string().regex(/^[0-9a-f]{64}$/, "Palette hash must be a lowercase SHA-256 value").transform((value) => value);
|
|
675
|
+
const paletteColorsSchema = z.object({
|
|
676
|
+
primary: hexColorSchema,
|
|
677
|
+
primaryForeground: hexColorSchema,
|
|
678
|
+
secondary: hexColorSchema,
|
|
679
|
+
accent: hexColorSchema,
|
|
680
|
+
success: hexColorSchema,
|
|
681
|
+
warning: hexColorSchema,
|
|
682
|
+
destructive: hexColorSchema,
|
|
683
|
+
background: hexColorSchema,
|
|
684
|
+
surface: hexColorSchema,
|
|
685
|
+
surfaceAlt: hexColorSchema,
|
|
686
|
+
muted: hexColorSchema,
|
|
687
|
+
text: hexColorSchema,
|
|
688
|
+
border: hexColorSchema
|
|
689
|
+
}).strict().transform((value) => value);
|
|
690
|
+
function normalizePaletteHex(value) {
|
|
691
|
+
if (!NORMALIZABLE_HEX_REGEX.test(value)) return null;
|
|
692
|
+
const normalized = value.toLowerCase();
|
|
693
|
+
if (normalized.length === 7) return normalized;
|
|
694
|
+
const triplet = normalized.slice(1);
|
|
695
|
+
const red = triplet.charAt(0);
|
|
696
|
+
const green = triplet.charAt(1);
|
|
697
|
+
const blue = triplet.charAt(2);
|
|
698
|
+
return `#${red}${red}${green}${green}${blue}${blue}`;
|
|
699
|
+
}
|
|
700
|
+
function paletteColorsFromEntries(entries) {
|
|
701
|
+
const values = {};
|
|
702
|
+
for (const entry of entries) {
|
|
703
|
+
const parsedRole = paletteTokenNameSchema.safeParse(entry.name);
|
|
704
|
+
if (!parsedRole.success) return {
|
|
705
|
+
ok: false,
|
|
706
|
+
error: {
|
|
707
|
+
kind: "unknown-role",
|
|
708
|
+
role: entry.name
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
const role = parsedRole.data;
|
|
712
|
+
if (values[role] !== void 0) return {
|
|
713
|
+
ok: false,
|
|
714
|
+
error: {
|
|
715
|
+
kind: "duplicate-role",
|
|
716
|
+
role
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
const hex = normalizePaletteHex(entry.hex);
|
|
720
|
+
if (!hex) return {
|
|
721
|
+
ok: false,
|
|
722
|
+
error: {
|
|
723
|
+
kind: "invalid-color",
|
|
724
|
+
role,
|
|
725
|
+
value: entry.hex
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
values[role] = hex;
|
|
729
|
+
}
|
|
730
|
+
const missing = PALETTE_TOKEN_NAMES.filter((role) => values[role] === void 0);
|
|
731
|
+
if (missing.length > 0) return {
|
|
732
|
+
ok: false,
|
|
733
|
+
error: {
|
|
734
|
+
kind: "missing-roles",
|
|
735
|
+
roles: missing
|
|
736
|
+
}
|
|
737
|
+
};
|
|
738
|
+
return {
|
|
739
|
+
ok: true,
|
|
740
|
+
colors: paletteColorsSchema.parse(values)
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
function requirePaletteColorsFromEntries(entries) {
|
|
744
|
+
const result = paletteColorsFromEntries(entries);
|
|
745
|
+
if (result.ok) return result.colors;
|
|
746
|
+
throw new Error(`Invalid complete palette: ${result.error.kind}`);
|
|
747
|
+
}
|
|
748
|
+
function paletteColorEntries(colors) {
|
|
749
|
+
return THEME_PALETTE_COLOR_ORDER.map((name) => ({
|
|
750
|
+
name,
|
|
751
|
+
hex: colors[name]
|
|
752
|
+
}));
|
|
753
|
+
}
|
|
754
|
+
function paletteColorFingerprint(colors) {
|
|
755
|
+
return PALETTE_TOKEN_NAMES.map((name) => `${name}:${colors[name]}`).join("|");
|
|
756
|
+
}
|
|
757
|
+
function canonicalPaletteHashInput(colors, mode) {
|
|
758
|
+
return `${mode}|${paletteColorFingerprint(colors)}`;
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Stable curated-catalogue identity. Do not reorder roles: the order comes
|
|
762
|
+
* from PALETTE_TOKEN_NAMES through canonicalPaletteHashInput.
|
|
763
|
+
*/
|
|
764
|
+
function paletteValueKey(colors, mode) {
|
|
765
|
+
return `${PALETTE_VALUE_KEY_PREFIX}${canonicalPaletteHashInput(colors, mode)}`;
|
|
766
|
+
}
|
|
767
|
+
/** Parses only the exact v1 canonical form emitted by paletteValueKey. */
|
|
768
|
+
function parsePaletteValueKey(value) {
|
|
769
|
+
if (typeof value !== "string" || !value.startsWith(PALETTE_VALUE_KEY_PREFIX)) return null;
|
|
770
|
+
const [rawMode, ...rawRoles] = value.slice(17).split("|");
|
|
771
|
+
const mode = paletteModeSchema.safeParse(rawMode);
|
|
772
|
+
if (!mode.success || rawRoles.length !== PALETTE_TOKEN_NAMES.length) return null;
|
|
773
|
+
const colors = paletteColorsFromEntries(rawRoles.map((roleValue) => {
|
|
774
|
+
const separator = roleValue.indexOf(":");
|
|
775
|
+
return separator === -1 ? {
|
|
776
|
+
name: "",
|
|
777
|
+
hex: ""
|
|
778
|
+
} : {
|
|
779
|
+
name: roleValue.slice(0, separator),
|
|
780
|
+
hex: roleValue.slice(separator + 1)
|
|
781
|
+
};
|
|
782
|
+
}));
|
|
783
|
+
if (!colors.ok || paletteValueKey(colors.colors, mode.data) !== value) return null;
|
|
784
|
+
return value;
|
|
785
|
+
}
|
|
786
|
+
const paletteValueKeySchema = z.string().transform((value, ctx) => {
|
|
787
|
+
const parsed = parsePaletteValueKey(value);
|
|
788
|
+
if (parsed) return parsed;
|
|
789
|
+
ctx.addIssue({
|
|
790
|
+
code: "custom",
|
|
791
|
+
message: "Invalid canonical palette value key"
|
|
792
|
+
});
|
|
793
|
+
return z.NEVER;
|
|
794
|
+
});
|
|
795
|
+
//#endregion
|
|
796
|
+
//#region ../theme-core/src/palette/utils/textColor.ts
|
|
797
|
+
/**
|
|
798
|
+
* Pick the better of black/white text for a given background using actual
|
|
799
|
+
* contrast ratios, not a simple luminance cutoff. This is
|
|
800
|
+
* `maxContrastBlackOrWhite` for a solid ground.
|
|
801
|
+
*
|
|
802
|
+
* @param background - Background color in hex or rgb/rgba format (e.g., '#FFFFFF' or 'rgb(255, 255, 255)')
|
|
803
|
+
* @param _minContrast - Kept for callers. It cannot change the result: when
|
|
804
|
+
* only one of black or white reaches it, that one is also the better of the two.
|
|
805
|
+
* @returns '#000000' for light backgrounds, '#FFFFFF' for dark backgrounds
|
|
806
|
+
*/
|
|
807
|
+
function pickBlackOrWhiteTextColor(background, _minContrast = 4.5) {
|
|
808
|
+
const { r, g, b } = parseColorToRgb(background);
|
|
809
|
+
return maxContrastBlackOrWhite(luminanceInterval(relativeLuminance(r, g, b))).ink === "black" ? "#000000" : "#FFFFFF";
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* Backwards-compatible alias for callers that want the best black/white text
|
|
813
|
+
* color for a background.
|
|
814
|
+
*/
|
|
815
|
+
function getTextColorForBackground(background) {
|
|
816
|
+
return pickBlackOrWhiteTextColor(background);
|
|
817
|
+
}
|
|
818
|
+
function parseColorToRgb(input) {
|
|
819
|
+
const trimmed = input.trim();
|
|
820
|
+
if (trimmed.startsWith("#")) return hexToRgb(trimmed);
|
|
821
|
+
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);
|
|
822
|
+
if (rgbMatch?.[1] && rgbMatch[2] && rgbMatch[3]) return {
|
|
823
|
+
r: clamp255(Number(rgbMatch[1])),
|
|
824
|
+
g: clamp255(Number(rgbMatch[2])),
|
|
825
|
+
b: clamp255(Number(rgbMatch[3]))
|
|
826
|
+
};
|
|
827
|
+
throw new Error("Unsupported color format");
|
|
828
|
+
}
|
|
829
|
+
function clamp255(value) {
|
|
830
|
+
if (Number.isNaN(value)) return 0;
|
|
831
|
+
return Math.max(0, Math.min(255, value));
|
|
832
|
+
}
|
|
833
|
+
//#endregion
|
|
834
|
+
//#region ../theme-core/src/palette/utils/onColor.ts
|
|
835
|
+
const BACKGROUND_ROLE_NAMES = /* @__PURE__ */ new Set([
|
|
836
|
+
"primary",
|
|
837
|
+
"secondary",
|
|
838
|
+
"accent",
|
|
839
|
+
"success",
|
|
840
|
+
"warning",
|
|
841
|
+
"destructive",
|
|
842
|
+
"info",
|
|
843
|
+
"background",
|
|
844
|
+
"surface",
|
|
845
|
+
"surfaceAlt",
|
|
846
|
+
"muted",
|
|
847
|
+
"neutral"
|
|
848
|
+
]);
|
|
849
|
+
function onColorTokenName(backgroundToken) {
|
|
850
|
+
return `on${backgroundToken.split("-").filter((part) => part.length > 0).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")}`;
|
|
851
|
+
}
|
|
852
|
+
function isOnColorBackgroundCandidateToken(token) {
|
|
853
|
+
const role = token.match(/^(.*?)(?:-\d{2,3})?$/)?.[1] ?? token;
|
|
854
|
+
return BACKGROUND_ROLE_NAMES.has(role);
|
|
855
|
+
}
|
|
856
|
+
//#endregion
|
|
857
|
+
//#region ../theme-core/src/palette/generateShades.ts
|
|
858
|
+
function generateShades(hexColor, name) {
|
|
859
|
+
const shadeSteps = [
|
|
860
|
+
50,
|
|
861
|
+
100,
|
|
862
|
+
200,
|
|
863
|
+
300,
|
|
864
|
+
400,
|
|
865
|
+
500,
|
|
866
|
+
600,
|
|
867
|
+
700,
|
|
868
|
+
800,
|
|
869
|
+
900,
|
|
870
|
+
950
|
|
871
|
+
];
|
|
872
|
+
const base = featuresFromHex(hexColor);
|
|
873
|
+
const hue = base.okH;
|
|
874
|
+
const baseChroma = base.okC;
|
|
875
|
+
const toneMap = {
|
|
876
|
+
50: .975,
|
|
877
|
+
100: .945,
|
|
878
|
+
200: .89,
|
|
879
|
+
300: .82,
|
|
880
|
+
400: .74,
|
|
881
|
+
500: .66,
|
|
882
|
+
600: .58,
|
|
883
|
+
700: .49,
|
|
884
|
+
800: .4,
|
|
885
|
+
900: .28,
|
|
886
|
+
950: .16
|
|
887
|
+
};
|
|
888
|
+
const shadeDefs = shadeSteps.map((step, idx) => {
|
|
889
|
+
const t = idx / (shadeSteps.length - 1);
|
|
890
|
+
const L = toneMap[step];
|
|
891
|
+
const C = baseChroma * (.06 + .94 * Math.sin(Math.PI * t));
|
|
892
|
+
return {
|
|
893
|
+
name: `${name}-${step}`,
|
|
894
|
+
hex: oklchToHexGamut(L, C, hue)
|
|
895
|
+
};
|
|
896
|
+
});
|
|
897
|
+
shadeDefs.push({
|
|
898
|
+
name,
|
|
899
|
+
hex: hexColor
|
|
900
|
+
});
|
|
901
|
+
return shadeDefs;
|
|
902
|
+
}
|
|
903
|
+
//#endregion
|
|
904
|
+
//#region ../theme-core/src/palette/neutralScale.ts
|
|
905
|
+
function generateNeutralScale({ background, steps = 11, warm = false }) {
|
|
906
|
+
const isDark = background === "#000000" || background.startsWith("#0") || background.startsWith("#1");
|
|
907
|
+
const shadeNames = [
|
|
908
|
+
50,
|
|
909
|
+
100,
|
|
910
|
+
200,
|
|
911
|
+
300,
|
|
912
|
+
400,
|
|
913
|
+
500,
|
|
914
|
+
600,
|
|
915
|
+
700,
|
|
916
|
+
800,
|
|
917
|
+
900,
|
|
918
|
+
950
|
|
919
|
+
];
|
|
920
|
+
const count = Math.min(steps, shadeNames.length);
|
|
921
|
+
const scale = [];
|
|
922
|
+
for (let i = 0; i < count; i++) {
|
|
923
|
+
const shadeName = shadeNames[i] ?? shadeNames[shadeNames.length - 1] ?? 950;
|
|
924
|
+
const t = i / (count - 1);
|
|
925
|
+
const hex = oklchToHexGamut(isDark ? mix(.06, .92, t) : mix(.98, .1, t), .02, warm ? 85 : 250);
|
|
926
|
+
const name = `neutral-${shadeName}`;
|
|
927
|
+
scale.push({
|
|
928
|
+
name,
|
|
929
|
+
hex
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
return scale;
|
|
933
|
+
}
|
|
934
|
+
function mix(a, b, t) {
|
|
935
|
+
return a + (b - a) * Math.max(0, Math.min(1, t));
|
|
936
|
+
}
|
|
937
|
+
//#endregion
|
|
938
|
+
//#region ../theme-core/src/palette/expandPalette.ts
|
|
939
|
+
function colorsToMap(palette) {
|
|
940
|
+
const map = {};
|
|
941
|
+
for (const c of palette.colors) map[c.name] = c.hex;
|
|
942
|
+
return map;
|
|
943
|
+
}
|
|
944
|
+
function isBackgroundDark(hex) {
|
|
945
|
+
try {
|
|
946
|
+
return featuresFromHex(hex).Y < .5;
|
|
947
|
+
} catch {
|
|
948
|
+
return false;
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
const nonShadeablePaletteRoleNames = /* @__PURE__ */ new Set([
|
|
952
|
+
"success",
|
|
953
|
+
"warning",
|
|
954
|
+
"destructive"
|
|
955
|
+
]);
|
|
956
|
+
/**
|
|
957
|
+
* Status role aliases the persisted palette does not carry itself.
|
|
958
|
+
*
|
|
959
|
+
* Generators reference `--tb-error` (the site-style-owned input error border)
|
|
960
|
+
* and `--tb-info` (`.alert-info`, `.status-info`, the field-note rule), but the
|
|
961
|
+
* palette schema only defines `destructive` and has no `info` role at all.
|
|
962
|
+
* Without these aliases those declarations name variables that are never
|
|
963
|
+
* defined and browsers drop them. The SDK bridge resolves the same pair via
|
|
964
|
+
* TOKEN_ALIASES, so both runtimes agree on what a status token means.
|
|
965
|
+
*
|
|
966
|
+
* Runs after the danger → destructive promotion above, so `destructive` is
|
|
967
|
+
* already the single source of truth for the error colour.
|
|
968
|
+
*/
|
|
969
|
+
function statusAliasTokens(expanded) {
|
|
970
|
+
const aliases = {};
|
|
971
|
+
if (expanded.destructive) aliases.error = expanded.destructive;
|
|
972
|
+
if (expanded.accent) aliases.info = expanded.accent;
|
|
973
|
+
return aliases;
|
|
974
|
+
}
|
|
975
|
+
function expandPalette(palette, options = {}) {
|
|
976
|
+
return {
|
|
977
|
+
...expandBasePalette(palette),
|
|
978
|
+
...arrangementPaletteTokens(colorsToMap(palette), options)
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
function expandBasePalette(palette) {
|
|
982
|
+
const base = colorsToMap(palette);
|
|
983
|
+
const expanded = { ...base };
|
|
984
|
+
generateNeutralScale({
|
|
985
|
+
background: base.background || base.surface || "#ffffff",
|
|
986
|
+
steps: 11,
|
|
987
|
+
warm: false
|
|
988
|
+
}).forEach((n) => {
|
|
989
|
+
expanded[n.name] = n.hex;
|
|
990
|
+
});
|
|
991
|
+
for (const [name, hex] of Object.entries(base)) {
|
|
992
|
+
if (nonShadeablePaletteRoleNames.has(name)) continue;
|
|
993
|
+
if (hex) generateShades(hex, name).forEach((shade) => {
|
|
994
|
+
expanded[shade.name] = shade.hex;
|
|
995
|
+
});
|
|
996
|
+
}
|
|
997
|
+
if (base.text) expanded.body = base.text;
|
|
998
|
+
if (base.danger && !base.destructive) expanded.destructive = base.danger;
|
|
999
|
+
Object.assign(expanded, statusAliasTokens(expanded));
|
|
1000
|
+
const isDark = base.background ? isBackgroundDark(base.background) : false;
|
|
1001
|
+
expanded.mutedText = palette.meta?.mode === "dark" || isDark ? expanded["neutral-600"] ?? "#666" : expanded["neutral-500"] ?? "#888";
|
|
1002
|
+
for (const [token, hex] of Object.entries({ ...expanded })) {
|
|
1003
|
+
if (!hex || !isOnColorBackgroundCandidateToken(token)) continue;
|
|
1004
|
+
const onToken = onColorTokenName(token);
|
|
1005
|
+
if (expanded[onToken]) continue;
|
|
1006
|
+
expanded[onToken] = getTextColorForBackground(hex);
|
|
1007
|
+
}
|
|
1008
|
+
return expanded;
|
|
1009
|
+
}
|
|
1010
|
+
/** Derived decoration colours never become editable palette swatches. */
|
|
1011
|
+
function deriveSurfaceDecorationColors(ground, text, accent) {
|
|
1012
|
+
const ink = getTextColorForBackground(ground);
|
|
1013
|
+
return {
|
|
1014
|
+
line: firstContrastBlend(ground, text, ground, 1.5),
|
|
1015
|
+
mark: firstContrastBlend(accent, ink, ground, 3)
|
|
1016
|
+
};
|
|
1017
|
+
}
|
|
1018
|
+
/** Secondary ink is blended toward its ground, with an ordinary-text contrast floor. */
|
|
1019
|
+
function deriveSurfaceMutedColor(ground, text) {
|
|
1020
|
+
const start = hexToRgb(ground);
|
|
1021
|
+
const end = hexToRgb(text);
|
|
1022
|
+
const sample = (index) => rgbToHex(mix$1(start.r, end.r, index / 100), mix$1(start.g, end.g, index / 100), mix$1(start.b, end.b, index / 100));
|
|
1023
|
+
return firstSafeMutedSample(sample, ground, 0, 100);
|
|
1024
|
+
}
|
|
1025
|
+
/** The blend moves monotonically from the ground toward its validated ink. */
|
|
1026
|
+
function firstSafeMutedSample(sample, ground, low, high) {
|
|
1027
|
+
if (low === high) return sample(high);
|
|
1028
|
+
const middle = Math.floor((low + high) / 2);
|
|
1029
|
+
return contrastRatio(sample(middle), ground) >= 4.5 ? firstSafeMutedSample(sample, ground, low, middle) : firstSafeMutedSample(sample, ground, middle + 1, high);
|
|
1030
|
+
}
|
|
1031
|
+
function firstContrastBlend(from, to, ground, threshold) {
|
|
1032
|
+
const start = hexToRgb(from);
|
|
1033
|
+
const end = hexToRgb(to);
|
|
1034
|
+
return Array.from({ length: 101 }, (_, index) => {
|
|
1035
|
+
const amount = index / 100;
|
|
1036
|
+
return rgbToHex(mix$1(start.r, end.r, amount), mix$1(start.g, end.g, amount), mix$1(start.b, end.b, amount));
|
|
1037
|
+
}).find((hex) => contrastRatio(hex, ground) >= threshold) ?? to;
|
|
1038
|
+
}
|
|
1039
|
+
/** `markSource` names the colour surface marks are derived from when a style marks in its brand rather than its accent. */
|
|
1040
|
+
function arrangementPaletteTokens(base, options) {
|
|
1041
|
+
if (options.arrangement !== true || !base.text) return {};
|
|
1042
|
+
return {
|
|
1043
|
+
onText: getTextColorForBackground(base.text),
|
|
1044
|
+
...options.marksFrom === "primary" && base.primary ? { markSource: base.primary } : {}
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1047
|
+
//#endregion
|
|
1048
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/assertClassBrand.js
|
|
1049
|
+
function _assertClassBrand(e, t, n) {
|
|
1050
|
+
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
1051
|
+
throw new TypeError("Private element is not present on this object");
|
|
1052
|
+
}
|
|
1053
|
+
//#endregion
|
|
1054
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/classPrivateFieldSet2.js
|
|
1055
|
+
function _classPrivateFieldSet2(s, a, r) {
|
|
1056
|
+
return s.set(_assertClassBrand(s, a), r), r;
|
|
1057
|
+
}
|
|
1058
|
+
//#endregion
|
|
1059
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/classPrivateFieldGet2.js
|
|
1060
|
+
function _classPrivateFieldGet2(s, a) {
|
|
1061
|
+
return s.get(_assertClassBrand(s, a));
|
|
1062
|
+
}
|
|
1063
|
+
//#endregion
|
|
1064
|
+
//#region ../theme-core/src/palette/family.ts
|
|
1065
|
+
var _members = /* @__PURE__ */ new WeakMap();
|
|
1066
|
+
/**
|
|
1067
|
+
* Only `colourFamily` makes one (the class is not exported), so a caller can't
|
|
1068
|
+
* swap in its own members and still hand the solver a valid family. That
|
|
1069
|
+
* matters because `unpaintable` relies on the members running from black to
|
|
1070
|
+
* white.
|
|
1071
|
+
*/
|
|
1072
|
+
var Family = class {
|
|
1073
|
+
constructor(seed, members) {
|
|
1074
|
+
this.seed = seed;
|
|
1075
|
+
_classPrivateFieldInitSpec(this, _members, void 0);
|
|
1076
|
+
_classPrivateFieldSet2(_members, this, Object.freeze(members));
|
|
1077
|
+
}
|
|
1078
|
+
/** Unique by hex, ascending luminance. Includes the exact seed, black and white. */
|
|
1079
|
+
get members() {
|
|
1080
|
+
return _classPrivateFieldGet2(_members, this);
|
|
1081
|
+
}
|
|
1082
|
+
};
|
|
1083
|
+
const GAMUT_BISECTION_STEPS = 18;
|
|
1084
|
+
/** The highest chroma at or below `c` that stays inside sRGB at this lightness and hue. */
|
|
1085
|
+
function gamutChroma(l, c, h) {
|
|
1086
|
+
if (inLinearSrgbGamut(oklchToLinearSrgb(l, c, h))) return c;
|
|
1087
|
+
return Array.from({ length: GAMUT_BISECTION_STEPS }).reduce(({ lo, hi }) => {
|
|
1088
|
+
const mid = (lo + hi) / 2;
|
|
1089
|
+
return inLinearSrgbGamut(oklchToLinearSrgb(l, mid, h)) ? {
|
|
1090
|
+
lo: mid,
|
|
1091
|
+
hi
|
|
1092
|
+
} : {
|
|
1093
|
+
lo,
|
|
1094
|
+
hi: mid
|
|
1095
|
+
};
|
|
1096
|
+
}, {
|
|
1097
|
+
lo: 0,
|
|
1098
|
+
hi: c
|
|
1099
|
+
}).lo;
|
|
1100
|
+
}
|
|
1101
|
+
function oklabDistance(a, b) {
|
|
1102
|
+
return Math.hypot(a.L - b.L, a.a - b.a, a.b - b.b);
|
|
1103
|
+
}
|
|
1104
|
+
/** OKLab distance between two rendered opaque hex colours. */
|
|
1105
|
+
function hexOklabDistance(first, second) {
|
|
1106
|
+
const lab = (hex) => {
|
|
1107
|
+
const { r, g, b } = hexToRgb(hex);
|
|
1108
|
+
return srgbToOklab(r, g, b);
|
|
1109
|
+
};
|
|
1110
|
+
return oklabDistance(lab(first), lab(second));
|
|
1111
|
+
}
|
|
1112
|
+
function colourFamily(seedHex) {
|
|
1113
|
+
if (!/^#[0-9a-f]{6}$/i.test(seedHex)) throw new Error(`Expected an opaque #rrggbb colour: ${seedHex}`);
|
|
1114
|
+
const features = featuresFromHex(seedHex.toLowerCase());
|
|
1115
|
+
const seed = member(seedHex.toLowerCase(), {
|
|
1116
|
+
l: features.okL,
|
|
1117
|
+
c: features.okC,
|
|
1118
|
+
h: features.okH
|
|
1119
|
+
});
|
|
1120
|
+
const seedTaper = Math.max(.001, Math.sin(Math.PI * seed.sample.l));
|
|
1121
|
+
const samples = Array.from({ length: 513 }, (_, i) => {
|
|
1122
|
+
const l = i / 512;
|
|
1123
|
+
return sampleMember({
|
|
1124
|
+
l,
|
|
1125
|
+
c: gamutChroma(l, seed.sample.c * Math.min(1, Math.sin(Math.PI * l) / seedTaper), seed.sample.h),
|
|
1126
|
+
h: seed.sample.h
|
|
1127
|
+
});
|
|
1128
|
+
});
|
|
1129
|
+
return new Family(seed, [...new Map([seed, ...samples].map((candidate) => [candidate.hex, candidate]).reverse()).values()].sort((a, b) => a.y - b.y || (a.hex < b.hex ? -1 : a.hex > b.hex ? 1 : 0)));
|
|
1130
|
+
}
|
|
1131
|
+
function sampleMember(sample) {
|
|
1132
|
+
const { r, g, b } = oklchToLinearSrgb(sample.l, sample.c, sample.h);
|
|
1133
|
+
return member(rgbToHex(linearToSrgb(r), linearToSrgb(g), linearToSrgb(b)), sample);
|
|
1134
|
+
}
|
|
1135
|
+
function member(hex, sample) {
|
|
1136
|
+
const { r, g, b } = hexToRgb(hex);
|
|
1137
|
+
return {
|
|
1138
|
+
hex,
|
|
1139
|
+
y: hexLuminance(hex),
|
|
1140
|
+
oklab: srgbToOklab(r, g, b),
|
|
1141
|
+
sample
|
|
1142
|
+
};
|
|
1143
|
+
}
|
|
1144
|
+
//#endregion
|
|
1145
|
+
//#region ../theme-core/src/buttons/typography.ts
|
|
1146
|
+
const textTransformSchema = z.enum([
|
|
1147
|
+
"none",
|
|
1148
|
+
"uppercase",
|
|
1149
|
+
"lowercase",
|
|
1150
|
+
"capitalize"
|
|
1151
|
+
]);
|
|
1152
|
+
const fontWeightSchema = z.union([
|
|
1153
|
+
z.literal(400),
|
|
1154
|
+
z.literal(500),
|
|
1155
|
+
z.literal(600),
|
|
1156
|
+
z.literal(700),
|
|
1157
|
+
z.literal(800)
|
|
1158
|
+
]);
|
|
1159
|
+
const buttonTypographySchema = z.enum(["body", "heading"]);
|
|
1160
|
+
const letterSpacingSchema = z.enum([
|
|
1161
|
+
"tight",
|
|
1162
|
+
"normal",
|
|
1163
|
+
"slight",
|
|
1164
|
+
"loose",
|
|
1165
|
+
"wide"
|
|
1166
|
+
]);
|
|
1167
|
+
//#endregion
|
|
1168
|
+
//#region ../theme-core/src/buttons/types.ts
|
|
1169
|
+
/**
|
|
1170
|
+
* Standard semantic variant roles a theme exposes.
|
|
1171
|
+
*
|
|
1172
|
+
* Block content references variants by role; the active theme determines
|
|
1173
|
+
* what each role looks like.
|
|
1174
|
+
*/
|
|
1175
|
+
const VARIANT_ROLES = [
|
|
1176
|
+
"primary",
|
|
1177
|
+
"secondary",
|
|
1178
|
+
"outline",
|
|
1179
|
+
"ghost",
|
|
1180
|
+
"accent"
|
|
1181
|
+
];
|
|
1182
|
+
function isVariantRole(value) {
|
|
1183
|
+
return VARIANT_ROLES.includes(value);
|
|
1184
|
+
}
|
|
1185
|
+
/**
|
|
1186
|
+
* Canonical persisted/CSS-safe button variant identifier.
|
|
1187
|
+
*
|
|
1188
|
+
* IDs become class selectors, so keep the contract deliberately narrower than
|
|
1189
|
+
* an arbitrary string and shared with every authoring/runtime boundary.
|
|
1190
|
+
*/
|
|
1191
|
+
const buttonVariantIdSchema = z.string().min(1).max(50).regex(/^[a-z0-9-]+$/, "Button variant IDs may contain lowercase letters, numbers, and hyphens only").refine((value) => value !== "link" && value !== "tertiary", { message: "Retired button role IDs are not valid variant IDs" });
|
|
1192
|
+
function asSpecialVariantId(value) {
|
|
1193
|
+
const parsed = buttonVariantIdSchema.safeParse(value);
|
|
1194
|
+
if (!parsed.success) throw new Error("SpecialVariantId must be a CSS-safe button variant ID");
|
|
1195
|
+
return parsed.data;
|
|
1196
|
+
}
|
|
1197
|
+
/**
|
|
1198
|
+
* Magic alias the CSS generator emits for the highest-priority variant.
|
|
1199
|
+
*
|
|
1200
|
+
* Shared between generator and renderer so neither side hard-codes the string.
|
|
1201
|
+
*/
|
|
1202
|
+
const DEFAULT_VARIANT_ALIAS_ID = "default";
|
|
1203
|
+
function parseOpaqueButtonColourToken(value) {
|
|
1204
|
+
const token = parseThemeColorToken(value);
|
|
1205
|
+
if (token === null) return null;
|
|
1206
|
+
const parts = parseColorTokenParts(token);
|
|
1207
|
+
return parts.kind === "token" && parts.opacityPercent === null ? token : null;
|
|
1208
|
+
}
|
|
1209
|
+
function unsafeAsOpaqueButtonColourToken(value) {
|
|
1210
|
+
return value;
|
|
1211
|
+
}
|
|
1212
|
+
const opaqueButtonColourTokenSchema = themeColorTokenSchema.refine((value) => parseOpaqueButtonColourToken(value) !== null, "Button colour tokens must be opaque").transform((value) => {
|
|
1213
|
+
const token = parseOpaqueButtonColourToken(value);
|
|
1214
|
+
if (token === null) throw new Error("Invariant: opaque button token passed its schema");
|
|
1215
|
+
return token;
|
|
1216
|
+
});
|
|
1217
|
+
const contextualButtonHoverSchema = z.strictObject({
|
|
1218
|
+
kind: z.literal("shade-shift"),
|
|
1219
|
+
seedToken: opaqueButtonColourTokenSchema,
|
|
1220
|
+
fallbackDirection: z.enum(["lighter", "darker"]),
|
|
1221
|
+
preferredToken: opaqueButtonColourTokenSchema.optional()
|
|
1222
|
+
});
|
|
1223
|
+
const buttonShadeAmountSchema = z.number().finite().min(0).max(900).multipleOf(100);
|
|
1224
|
+
const buttonShadowIntensitySchema = z.enum([
|
|
1225
|
+
"subtle",
|
|
1226
|
+
"medium",
|
|
1227
|
+
"strong"
|
|
1228
|
+
]);
|
|
1229
|
+
/**
|
|
1230
|
+
* The complete persisted button-effect contract.
|
|
1231
|
+
*
|
|
1232
|
+
* Navigation has its own generic interactive-effect model. Button variants use
|
|
1233
|
+
* this closed union so unsupported effect IDs, unknown option keys, and unsafe
|
|
1234
|
+
* CSS values cannot become representable after the schema boundary.
|
|
1235
|
+
*/
|
|
1236
|
+
const buttonPressOffsetSchema = z.strictObject({
|
|
1237
|
+
x: z.number().int().min(0).max(12),
|
|
1238
|
+
y: z.number().int().min(0).max(12)
|
|
1239
|
+
});
|
|
1240
|
+
const buttonEffectApplicationSchema = z.discriminatedUnion("effectId", [
|
|
1241
|
+
z.strictObject({
|
|
1242
|
+
effectId: z.literal("darken-background"),
|
|
1243
|
+
options: z.strictObject({ amount: buttonShadeAmountSchema.optional() }).optional()
|
|
1244
|
+
}),
|
|
1245
|
+
z.strictObject({
|
|
1246
|
+
effectId: z.literal("lighten-background"),
|
|
1247
|
+
options: z.strictObject({ amount: buttonShadeAmountSchema.optional() }).optional()
|
|
1248
|
+
}),
|
|
1249
|
+
z.strictObject({
|
|
1250
|
+
effectId: z.literal("background-on-hover"),
|
|
1251
|
+
options: z.strictObject({ colorToken: opaqueButtonColourTokenSchema.optional() }).optional()
|
|
1252
|
+
}),
|
|
1253
|
+
z.strictObject({
|
|
1254
|
+
effectId: z.literal("animated-gradient"),
|
|
1255
|
+
options: z.strictObject({ direction: z.enum(["horizontal", "vertical"]).optional() }).optional()
|
|
1256
|
+
}),
|
|
1257
|
+
z.strictObject({
|
|
1258
|
+
effectId: z.literal("drop-shadow"),
|
|
1259
|
+
options: z.strictObject({ intensity: buttonShadowIntensitySchema.optional() }).optional()
|
|
1260
|
+
}),
|
|
1261
|
+
z.strictObject({
|
|
1262
|
+
effectId: z.literal("inner-shadow"),
|
|
1263
|
+
options: z.strictObject({}).optional()
|
|
1264
|
+
}),
|
|
1265
|
+
z.strictObject({
|
|
1266
|
+
effectId: z.literal("neumorphic-shadow"),
|
|
1267
|
+
options: z.strictObject({
|
|
1268
|
+
mode: z.enum(["raised", "pressed"]).optional(),
|
|
1269
|
+
intensity: buttonShadowIntensitySchema.optional()
|
|
1270
|
+
}).optional()
|
|
1271
|
+
}),
|
|
1272
|
+
z.strictObject({
|
|
1273
|
+
effectId: z.literal("retro-3d-shadow"),
|
|
1274
|
+
options: z.strictObject({}).optional()
|
|
1275
|
+
}),
|
|
1276
|
+
z.strictObject({
|
|
1277
|
+
effectId: z.literal("scale-up"),
|
|
1278
|
+
options: z.strictObject({ scale: z.enum([
|
|
1279
|
+
"1.02",
|
|
1280
|
+
"1.03",
|
|
1281
|
+
"1.05",
|
|
1282
|
+
"1.10"
|
|
1283
|
+
]).optional() }).optional()
|
|
1284
|
+
}),
|
|
1285
|
+
z.strictObject({
|
|
1286
|
+
effectId: z.literal("scale-down"),
|
|
1287
|
+
options: z.strictObject({ scale: z.enum([
|
|
1288
|
+
"0.90",
|
|
1289
|
+
"0.95",
|
|
1290
|
+
"0.97",
|
|
1291
|
+
"0.98"
|
|
1292
|
+
]).optional() }).optional()
|
|
1293
|
+
}),
|
|
1294
|
+
z.strictObject({
|
|
1295
|
+
effectId: z.literal("lift"),
|
|
1296
|
+
options: z.strictObject({ amount: z.enum([
|
|
1297
|
+
"0.125",
|
|
1298
|
+
"0.25",
|
|
1299
|
+
"0.5",
|
|
1300
|
+
"1"
|
|
1301
|
+
]).optional() }).optional()
|
|
1302
|
+
}),
|
|
1303
|
+
z.strictObject({
|
|
1304
|
+
effectId: z.literal("press-down"),
|
|
1305
|
+
options: z.strictObject({ offset: buttonPressOffsetSchema.optional() }).optional()
|
|
1306
|
+
}),
|
|
1307
|
+
z.strictObject({
|
|
1308
|
+
effectId: z.literal("pop"),
|
|
1309
|
+
options: z.strictObject({ intensity: z.enum([
|
|
1310
|
+
"subtle",
|
|
1311
|
+
"medium",
|
|
1312
|
+
"dramatic"
|
|
1313
|
+
]).optional() }).optional()
|
|
1314
|
+
}),
|
|
1315
|
+
z.strictObject({
|
|
1316
|
+
effectId: z.literal("border-bottom-grow"),
|
|
1317
|
+
options: z.strictObject({
|
|
1318
|
+
height: z.union([z.literal(1), z.literal(2)]).optional(),
|
|
1319
|
+
origin: z.enum([
|
|
1320
|
+
"left",
|
|
1321
|
+
"center",
|
|
1322
|
+
"right"
|
|
1323
|
+
]).optional(),
|
|
1324
|
+
persistent: z.boolean().optional(),
|
|
1325
|
+
colourRole: z.literal("mark").optional()
|
|
1326
|
+
}).optional()
|
|
1327
|
+
}),
|
|
1328
|
+
z.strictObject({
|
|
1329
|
+
effectId: z.literal("inner-dashed-outline"),
|
|
1330
|
+
options: z.strictObject({
|
|
1331
|
+
colourRole: z.enum(["ink", "mark"]),
|
|
1332
|
+
width: z.number().finite().min(.5).max(4),
|
|
1333
|
+
inset: z.number().finite().min(0).max(16)
|
|
1334
|
+
})
|
|
1335
|
+
}),
|
|
1336
|
+
z.strictObject({
|
|
1337
|
+
effectId: z.literal("sketchy-border"),
|
|
1338
|
+
options: z.strictObject({ intensity: buttonShadowIntensitySchema.optional() }).optional()
|
|
1339
|
+
})
|
|
1340
|
+
]);
|
|
1341
|
+
const cornerStyleSchema = z.enum([
|
|
1342
|
+
"square",
|
|
1343
|
+
"rounded",
|
|
1344
|
+
"pill"
|
|
1345
|
+
]);
|
|
1346
|
+
const shadowSizeSchema = z.enum([
|
|
1347
|
+
"none",
|
|
1348
|
+
"low",
|
|
1349
|
+
"medium",
|
|
1350
|
+
"high"
|
|
1351
|
+
]);
|
|
1352
|
+
const hoverTransformSchema = z.enum([
|
|
1353
|
+
"none",
|
|
1354
|
+
"lift",
|
|
1355
|
+
"scale",
|
|
1356
|
+
"press"
|
|
1357
|
+
]);
|
|
1358
|
+
z.enum(["none", "token"]);
|
|
1359
|
+
const buttonPaddingPresetSchema = z.enum([
|
|
1360
|
+
"compact",
|
|
1361
|
+
"default",
|
|
1362
|
+
"spacious"
|
|
1363
|
+
]);
|
|
1364
|
+
const gradientStyleSchema = z.enum([
|
|
1365
|
+
"linear",
|
|
1366
|
+
"radial",
|
|
1367
|
+
"conic"
|
|
1368
|
+
]);
|
|
1369
|
+
const gradientSharpnessSchema = z.enum([
|
|
1370
|
+
"smooth",
|
|
1371
|
+
"medium",
|
|
1372
|
+
"hard"
|
|
1373
|
+
]);
|
|
1374
|
+
const prioritySchema = z.union([
|
|
1375
|
+
z.literal(1),
|
|
1376
|
+
z.literal(2),
|
|
1377
|
+
z.literal(3)
|
|
1378
|
+
]);
|
|
1379
|
+
const variantRoleSchema = z.enum(VARIANT_ROLES);
|
|
1380
|
+
const buttonSurfaceFallbackSchema = z.discriminatedUnion("kind", [z.strictObject({ kind: z.literal("surface-outline") }), z.strictObject({
|
|
1381
|
+
kind: z.literal("variant"),
|
|
1382
|
+
role: variantRoleSchema
|
|
1383
|
+
})]);
|
|
1384
|
+
const standardButtonSurfacePolicy = {
|
|
1385
|
+
primary: [{ kind: "surface-outline" }],
|
|
1386
|
+
secondary: [{ kind: "surface-outline" }, {
|
|
1387
|
+
kind: "variant",
|
|
1388
|
+
role: "primary"
|
|
1389
|
+
}],
|
|
1390
|
+
outline: [{ kind: "surface-outline" }],
|
|
1391
|
+
ghost: [{ kind: "surface-outline" }],
|
|
1392
|
+
accent: [{ kind: "surface-outline" }, {
|
|
1393
|
+
kind: "variant",
|
|
1394
|
+
role: "primary"
|
|
1395
|
+
}]
|
|
1396
|
+
};
|
|
1397
|
+
const STANDARD_BUTTON_SURFACE_POLICY = Object.freeze(Object.fromEntries(VARIANT_ROLES.map((role) => [role, Object.freeze([...standardButtonSurfacePolicy[role]])])));
|
|
1398
|
+
function createStandardButtonSurfacePolicy() {
|
|
1399
|
+
return Object.fromEntries(VARIANT_ROLES.map((role) => [role, [...STANDARD_BUTTON_SURFACE_POLICY[role]]]));
|
|
1400
|
+
}
|
|
1401
|
+
const buttonSurfacePolicyShape = Object.fromEntries(VARIANT_ROLES.map((role) => [role, z.array(buttonSurfaceFallbackSchema).max(VARIANT_ROLES.length)]));
|
|
1402
|
+
const buttonSurfacePolicySchema = z.strictObject(buttonSurfacePolicyShape);
|
|
1403
|
+
const buttonSizeNameSchema = z.enum([
|
|
1404
|
+
"sm",
|
|
1405
|
+
"md",
|
|
1406
|
+
"lg",
|
|
1407
|
+
"xl"
|
|
1408
|
+
]);
|
|
1409
|
+
/**
|
|
1410
|
+
* CSS padding string in `"<vertical> <horizontal>"` shorthand form.
|
|
1411
|
+
*
|
|
1412
|
+
* Exactly two space-separated CSS length tokens. Each token is either the
|
|
1413
|
+
* literal `0` or a number followed by `rem`/`em`/`px`/`%`. This lets the
|
|
1414
|
+
* generator trust the shape rather than defensively defaulting downstream.
|
|
1415
|
+
*/
|
|
1416
|
+
const PADDING_TOKEN_PATTERN = /^(?:0|\d+(?:\.\d+)?(?:rem|em|px|%))$/;
|
|
1417
|
+
const paddingShorthandSchema = z.string().refine((value) => {
|
|
1418
|
+
const parts = value.split(/\s+/).filter(Boolean);
|
|
1419
|
+
return parts.length === 2 && parts.every((token) => PADDING_TOKEN_PATTERN.test(token));
|
|
1420
|
+
}, { message: "Padding must be two space-separated CSS length tokens (e.g. \"0.5rem 1rem\"). Use `0` for zero." });
|
|
1421
|
+
const buttonSizeConfigSchema = z.object({
|
|
1422
|
+
padding: paddingShorthandSchema,
|
|
1423
|
+
fontSize: z.string().optional(),
|
|
1424
|
+
borderRadius: z.string().optional()
|
|
1425
|
+
});
|
|
1426
|
+
/**
|
|
1427
|
+
* `xl` is optional on the wire so themes persisted before the `xl` size was
|
|
1428
|
+
* added (e.g. SWTS) continue to parse. When `xl` is missing the schema
|
|
1429
|
+
* backfills it from `lg`, keeping `ButtonSizes` a complete `sm/md/lg/xl` map
|
|
1430
|
+
* downstream — generators never need to deal with an undefined `xl`.
|
|
1431
|
+
*/
|
|
1432
|
+
const buttonSizesSchema = z.object({
|
|
1433
|
+
sm: buttonSizeConfigSchema,
|
|
1434
|
+
md: buttonSizeConfigSchema,
|
|
1435
|
+
lg: buttonSizeConfigSchema,
|
|
1436
|
+
xl: buttonSizeConfigSchema.optional()
|
|
1437
|
+
}).transform(({ sm, md, lg, xl }) => ({
|
|
1438
|
+
sm,
|
|
1439
|
+
md,
|
|
1440
|
+
lg,
|
|
1441
|
+
xl: xl ?? lg
|
|
1442
|
+
}));
|
|
1443
|
+
const buttonGlobalSettingsBaseSchema = z.strictObject({
|
|
1444
|
+
cornerStyle: cornerStyleSchema,
|
|
1445
|
+
cornerRadius: z.number().min(0).max(24).optional(),
|
|
1446
|
+
/**
|
|
1447
|
+
* Family-level shadow inherited by variants that don't set their own.
|
|
1448
|
+
* Optional and flat-by-default: when omitted, buttons carry no drop shadow
|
|
1449
|
+
* (`elevation: 'none'`). A personality opts the whole family into a shadow by
|
|
1450
|
+
* setting this; individual variants still override. There is no system-level
|
|
1451
|
+
* shadow-by-default — shadows only appear when explicitly declared.
|
|
1452
|
+
*/
|
|
1453
|
+
shadow: shadowSizeSchema.optional(),
|
|
1454
|
+
textTransform: textTransformSchema,
|
|
1455
|
+
fontWeight: fontWeightSchema,
|
|
1456
|
+
typography: buttonTypographySchema.optional(),
|
|
1457
|
+
fontSize: z.string().optional(),
|
|
1458
|
+
letterSpacing: letterSpacingSchema.optional(),
|
|
1459
|
+
italic: z.boolean().optional(),
|
|
1460
|
+
paddingPreset: buttonPaddingPresetSchema.optional(),
|
|
1461
|
+
hoverTransform: hoverTransformSchema,
|
|
1462
|
+
gradientStyle: gradientStyleSchema.optional(),
|
|
1463
|
+
gradientAngle: z.number().min(0).max(360).optional(),
|
|
1464
|
+
gradientSharpness: gradientSharpnessSchema.optional()
|
|
1465
|
+
});
|
|
1466
|
+
const buttonGlobalSettingsSchema = z.discriminatedUnion("hoverColor", [buttonGlobalSettingsBaseSchema.extend({
|
|
1467
|
+
hoverColor: z.literal("none"),
|
|
1468
|
+
hoverColorToken: z.never().optional()
|
|
1469
|
+
}), buttonGlobalSettingsBaseSchema.extend({
|
|
1470
|
+
hoverColor: z.literal("token"),
|
|
1471
|
+
hoverColorToken: opaqueButtonColourTokenSchema
|
|
1472
|
+
})]);
|
|
1473
|
+
const gradientDirectionSchema = z.enum([
|
|
1474
|
+
"to-r",
|
|
1475
|
+
"to-l",
|
|
1476
|
+
"to-t",
|
|
1477
|
+
"to-b",
|
|
1478
|
+
"to-tr",
|
|
1479
|
+
"to-tl",
|
|
1480
|
+
"to-br",
|
|
1481
|
+
"to-bl"
|
|
1482
|
+
]);
|
|
1483
|
+
const buttonColourTreatmentSchema = z.discriminatedUnion("type", [
|
|
1484
|
+
z.strictObject({
|
|
1485
|
+
type: z.literal("solid"),
|
|
1486
|
+
colorToken: opaqueButtonColourTokenSchema
|
|
1487
|
+
}),
|
|
1488
|
+
z.strictObject({
|
|
1489
|
+
type: z.literal("gradient"),
|
|
1490
|
+
stops: z.array(opaqueButtonColourTokenSchema).min(2).transform((stops) => {
|
|
1491
|
+
const [first, second, ...rest] = stops;
|
|
1492
|
+
if (first === void 0 || second === void 0) throw new Error("Invariant: gradient stops passed the minimum length schema");
|
|
1493
|
+
return [
|
|
1494
|
+
first,
|
|
1495
|
+
second,
|
|
1496
|
+
...rest
|
|
1497
|
+
];
|
|
1498
|
+
}),
|
|
1499
|
+
direction: gradientDirectionSchema,
|
|
1500
|
+
foregroundToken: opaqueButtonColourTokenSchema
|
|
1501
|
+
}),
|
|
1502
|
+
z.strictObject({
|
|
1503
|
+
type: z.literal("surface"),
|
|
1504
|
+
role: z.literal("link")
|
|
1505
|
+
})
|
|
1506
|
+
]);
|
|
1507
|
+
const buttonBackgroundSchema = buttonColourTreatmentSchema;
|
|
1508
|
+
const buttonBorderSchema = z.strictObject({
|
|
1509
|
+
widthClass: z.string(),
|
|
1510
|
+
marksBoundary: z.literal(true).optional(),
|
|
1511
|
+
ring: z.literal(true).optional(),
|
|
1512
|
+
boundaryInk: opaqueButtonColourTokenSchema.optional()
|
|
1513
|
+
});
|
|
1514
|
+
const buttonVariantAffordanceSchema = z.strictObject({ iconId: z.string().min(1) });
|
|
1515
|
+
const variantShadowSchema = z.strictObject({
|
|
1516
|
+
elevation: z.enum([
|
|
1517
|
+
"none",
|
|
1518
|
+
"low",
|
|
1519
|
+
"medium",
|
|
1520
|
+
"high"
|
|
1521
|
+
]),
|
|
1522
|
+
softness: z.enum([
|
|
1523
|
+
"crisp",
|
|
1524
|
+
"soft",
|
|
1525
|
+
"hard"
|
|
1526
|
+
]).nullable(),
|
|
1527
|
+
position: z.enum(["bottom", "bottom-right"]).default("bottom"),
|
|
1528
|
+
colorToken: opaqueButtonColourTokenSchema.optional()
|
|
1529
|
+
});
|
|
1530
|
+
/** Recipe states own every visual property; treatment owns its readable label. */
|
|
1531
|
+
const buttonVisualAppearanceSchema = z.strictObject({
|
|
1532
|
+
background: buttonColourTreatmentSchema,
|
|
1533
|
+
text: z.literal("treatment"),
|
|
1534
|
+
border: z.union([z.literal("none"), buttonBorderSchema]),
|
|
1535
|
+
borderRadius: z.string(),
|
|
1536
|
+
shadow: z.union([z.literal("focus-indicator"), variantShadowSchema]),
|
|
1537
|
+
sizes: buttonSizesSchema,
|
|
1538
|
+
typography: z.strictObject({
|
|
1539
|
+
fontWeight: fontWeightSchema,
|
|
1540
|
+
typography: buttonTypographySchema,
|
|
1541
|
+
fontSize: z.string().nullable(),
|
|
1542
|
+
letterSpacing: z.union([letterSpacingSchema, z.literal("heading")]).nullable(),
|
|
1543
|
+
italic: z.boolean(),
|
|
1544
|
+
textTransform: textTransformSchema
|
|
1545
|
+
}),
|
|
1546
|
+
effects: z.array(buttonEffectApplicationSchema),
|
|
1547
|
+
transform: z.literal("none").optional(),
|
|
1548
|
+
contextualHover: contextualButtonHoverSchema.optional()
|
|
1549
|
+
});
|
|
1550
|
+
const buttonVisualStatesSchema = z.strictObject({
|
|
1551
|
+
base: buttonVisualAppearanceSchema.extend({ shadow: variantShadowSchema }),
|
|
1552
|
+
hover: buttonVisualAppearanceSchema.extend({ shadow: variantShadowSchema }),
|
|
1553
|
+
focus: buttonVisualAppearanceSchema.extend({
|
|
1554
|
+
shadow: z.literal("focus-indicator"),
|
|
1555
|
+
indicator: z.strictObject({
|
|
1556
|
+
kind: z.literal("surface-ink"),
|
|
1557
|
+
width: z.union([z.literal(2), z.literal(3)]),
|
|
1558
|
+
offset: z.union([z.literal(3), z.literal(4)])
|
|
1559
|
+
}).optional()
|
|
1560
|
+
}),
|
|
1561
|
+
active: buttonVisualAppearanceSchema.extend({ shadow: variantShadowSchema }),
|
|
1562
|
+
disabled: buttonVisualAppearanceSchema.extend({ shadow: variantShadowSchema })
|
|
1563
|
+
});
|
|
1564
|
+
const variantEffectsSchema = z.strictObject({
|
|
1565
|
+
base: z.array(buttonEffectApplicationSchema).optional(),
|
|
1566
|
+
hover: z.array(buttonEffectApplicationSchema).optional(),
|
|
1567
|
+
active: z.array(buttonEffectApplicationSchema).optional(),
|
|
1568
|
+
focus: z.array(buttonEffectApplicationSchema).optional()
|
|
1569
|
+
});
|
|
1570
|
+
/**
|
|
1571
|
+
* Per-variant size overrides schema — every entry is optional.
|
|
1572
|
+
*
|
|
1573
|
+
* For each size key present, the values override the theme's `sizes` config
|
|
1574
|
+
* for that size on this variant. Missing sizes fall through to theme.sizes,
|
|
1575
|
+
* then system defaults.
|
|
1576
|
+
*/
|
|
1577
|
+
const variantSizeOverridesSchema = z.object({
|
|
1578
|
+
sm: buttonSizeConfigSchema.optional(),
|
|
1579
|
+
md: buttonSizeConfigSchema.optional(),
|
|
1580
|
+
lg: buttonSizeConfigSchema.optional(),
|
|
1581
|
+
xl: buttonSizeConfigSchema.optional()
|
|
1582
|
+
});
|
|
1583
|
+
/**
|
|
1584
|
+
* Unified variant schema. Every variant participates in the size system; the
|
|
1585
|
+
* optional `sizes` field lets a variant scale differently than the theme
|
|
1586
|
+
* default (e.g. link-style variants declaring zero horizontal padding at
|
|
1587
|
+
* every size).
|
|
1588
|
+
*/
|
|
1589
|
+
const buttonVariantSchema = z.strictObject({
|
|
1590
|
+
id: buttonVariantIdSchema,
|
|
1591
|
+
name: z.string().min(1).max(20),
|
|
1592
|
+
enabled: z.boolean(),
|
|
1593
|
+
priority: prioritySchema,
|
|
1594
|
+
visualStates: buttonVisualStatesSchema.optional(),
|
|
1595
|
+
background: buttonBackgroundSchema,
|
|
1596
|
+
/** Tailwind radius token (e.g. `'rounded-md'`). Omit to inherit from `global.cornerStyle`. */
|
|
1597
|
+
borderRadius: z.string().optional(),
|
|
1598
|
+
shadow: variantShadowSchema.optional(),
|
|
1599
|
+
border: buttonBorderSchema.optional(),
|
|
1600
|
+
hoverBackgroundToken: opaqueButtonColourTokenSchema.optional(),
|
|
1601
|
+
contextualHover: contextualButtonHoverSchema.optional(),
|
|
1602
|
+
effects: variantEffectsSchema.optional(),
|
|
1603
|
+
sizes: variantSizeOverridesSchema.optional(),
|
|
1604
|
+
affordance: buttonVariantAffordanceSchema.optional()
|
|
1605
|
+
});
|
|
1606
|
+
const buttonSystemSchema = z.strictObject({
|
|
1607
|
+
global: buttonGlobalSettingsSchema,
|
|
1608
|
+
variants: z.array(buttonVariantSchema).min(1).max(6),
|
|
1609
|
+
sizes: buttonSizesSchema.optional(),
|
|
1610
|
+
surfacePolicy: buttonSurfacePolicySchema.optional(),
|
|
1611
|
+
surfaceContexts: z.record(z.string(), z.strictObject({ primary: opaqueButtonColourTokenSchema })).optional()
|
|
1612
|
+
}).superRefine((system, ctx) => {
|
|
1613
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1614
|
+
system.variants.forEach((variant, index) => {
|
|
1615
|
+
if (seen.has(variant.id)) ctx.addIssue({
|
|
1616
|
+
code: "custom",
|
|
1617
|
+
path: [
|
|
1618
|
+
"variants",
|
|
1619
|
+
index,
|
|
1620
|
+
"id"
|
|
1621
|
+
],
|
|
1622
|
+
message: `Duplicate button variant ID: ${variant.id}`
|
|
1623
|
+
});
|
|
1624
|
+
seen.add(variant.id);
|
|
1625
|
+
});
|
|
1626
|
+
});
|
|
1627
|
+
//#endregion
|
|
1628
|
+
//#region ../theme-core/src/buttons/constants.ts
|
|
1629
|
+
/**
|
|
1630
|
+
* Shared constants for button CSS generation
|
|
1631
|
+
*
|
|
1632
|
+
* These mappings convert Tailwind-style tokens to actual CSS values.
|
|
1633
|
+
* Centralized here to eliminate duplication across multiple files.
|
|
1634
|
+
*/
|
|
1635
|
+
/**
|
|
1636
|
+
* Map Tailwind-style gradient direction tokens to CSS gradient directions
|
|
1637
|
+
*/
|
|
1638
|
+
const GRADIENT_DIRECTION_MAP = {
|
|
1639
|
+
"to-r": "to right",
|
|
1640
|
+
"to-l": "to left",
|
|
1641
|
+
"to-t": "to top",
|
|
1642
|
+
"to-b": "to bottom",
|
|
1643
|
+
"to-br": "to bottom right",
|
|
1644
|
+
"to-bl": "to bottom left",
|
|
1645
|
+
"to-tr": "to top right",
|
|
1646
|
+
"to-tl": "to top left"
|
|
1647
|
+
};
|
|
1648
|
+
/**
|
|
1649
|
+
* Map Tailwind border-radius tokens to CSS values
|
|
1650
|
+
*/
|
|
1651
|
+
const BORDER_RADIUS_MAP = {
|
|
1652
|
+
"rounded-none": "0",
|
|
1653
|
+
"rounded-3px": "3px",
|
|
1654
|
+
"rounded-10px": "10px",
|
|
1655
|
+
"rounded-sm": "0.125rem",
|
|
1656
|
+
"rounded": "0.25rem",
|
|
1657
|
+
"rounded-md": "0.375rem",
|
|
1658
|
+
"rounded-lg": "0.5rem",
|
|
1659
|
+
"rounded-xl": "0.75rem",
|
|
1660
|
+
"rounded-2xl": "1rem",
|
|
1661
|
+
"rounded-3xl": "1.5rem",
|
|
1662
|
+
"rounded-full": "9999px"
|
|
1663
|
+
};
|
|
1664
|
+
/**
|
|
1665
|
+
* Pixel offset per shadow elevation. Single source of truth shared by
|
|
1666
|
+
* `generateShadowValue` (the base box-shadow offset) and the `press-down`
|
|
1667
|
+
* effect (which translates the button by the same offset on hover). Keeping
|
|
1668
|
+
* these in one place ensures the "press into the shadow" illusion stays exact.
|
|
1669
|
+
*/
|
|
1670
|
+
const ELEVATION_OFFSET = {
|
|
1671
|
+
none: 0,
|
|
1672
|
+
low: 2,
|
|
1673
|
+
medium: 4,
|
|
1674
|
+
high: 6
|
|
1675
|
+
};
|
|
1676
|
+
/**
|
|
1677
|
+
* Generate shadow CSS value dynamically based on elevation, softness, and position
|
|
1678
|
+
*
|
|
1679
|
+
* This replaces the static shadow maps with a single dynamic function.
|
|
1680
|
+
* Benefits: single source of truth, easy to adjust algorithm, no redundancy.
|
|
1681
|
+
*
|
|
1682
|
+
* @param elevation - Shadow elevation level
|
|
1683
|
+
* @param softness - Shadow softness/blur style
|
|
1684
|
+
* @param position - Shadow position (bottom or bottom-right diagonal)
|
|
1685
|
+
* @returns CSS box-shadow value
|
|
1686
|
+
*/
|
|
1687
|
+
function generateShadowValue(elevation, softness, position = "bottom", color) {
|
|
1688
|
+
if (elevation === "none") return "none";
|
|
1689
|
+
const config = {
|
|
1690
|
+
low: {
|
|
1691
|
+
blur: 4,
|
|
1692
|
+
spread: 0
|
|
1693
|
+
},
|
|
1694
|
+
medium: {
|
|
1695
|
+
blur: 8,
|
|
1696
|
+
spread: -1
|
|
1697
|
+
},
|
|
1698
|
+
high: {
|
|
1699
|
+
blur: 12,
|
|
1700
|
+
spread: -2
|
|
1701
|
+
}
|
|
1702
|
+
}[elevation];
|
|
1703
|
+
const baseOffset = ELEVATION_OFFSET[elevation];
|
|
1704
|
+
const xOffset = position === "bottom-right" ? baseOffset : 0;
|
|
1705
|
+
const yOffset = baseOffset;
|
|
1706
|
+
switch (softness) {
|
|
1707
|
+
case null:
|
|
1708
|
+
case "soft": return `${xOffset}px ${yOffset}px ${config.blur}px ${config.spread}px ${color ?? "rgb(0 0 0 / 0.3)"}`;
|
|
1709
|
+
case "hard": return `${xOffset}px ${yOffset}px 0 0 ${color ?? "rgb(0 0 0 / 1)"}`;
|
|
1710
|
+
case "crisp": return `${xOffset}px ${yOffset}px ${baseOffset}px ${config.spread}px ${color ?? "rgb(0 0 0 / 0.4)"}`;
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
* Map Tailwind border-width tokens to CSS values
|
|
1715
|
+
*/
|
|
1716
|
+
const BORDER_WIDTH_MAP = {
|
|
1717
|
+
"border-0": "0px",
|
|
1718
|
+
"border": "1px",
|
|
1719
|
+
"border-2": "2px",
|
|
1720
|
+
"border-4": "4px",
|
|
1721
|
+
"border-8": "8px"
|
|
1722
|
+
};
|
|
1723
|
+
/**
|
|
1724
|
+
* Map Tailwind font-size tokens to CSS values
|
|
1725
|
+
*/
|
|
1726
|
+
const FONT_SIZE_MAP = {
|
|
1727
|
+
"text-xs": "0.75rem",
|
|
1728
|
+
"text-13px": "0.8125rem",
|
|
1729
|
+
"text-15px": "0.9375rem",
|
|
1730
|
+
"text-17px": "1.0625rem",
|
|
1731
|
+
"text-19px": "1.1875rem",
|
|
1732
|
+
"text-sm": "0.875rem",
|
|
1733
|
+
"text-base": "1rem",
|
|
1734
|
+
"text-lg": "1.125rem",
|
|
1735
|
+
"text-xl": "1.25rem",
|
|
1736
|
+
"text-2xl": "1.5rem"
|
|
1737
|
+
};
|
|
1738
|
+
/**
|
|
1739
|
+
* System defaults used when a theme doesn't supply its own `theme.buttons.sizes`.
|
|
1740
|
+
*
|
|
1741
|
+
* Every size is defined so the size class CSS always emits a complete rule and
|
|
1742
|
+
* variants are never naked. Referenced by `generateButtonCss` and surfaceable
|
|
1743
|
+
* from UI ("Showing default size ramp") without duplicating the values.
|
|
1744
|
+
*/
|
|
1745
|
+
const DEFAULT_BUTTON_SIZES = {
|
|
1746
|
+
sm: {
|
|
1747
|
+
padding: "0.5rem 1rem",
|
|
1748
|
+
fontSize: "text-sm"
|
|
1749
|
+
},
|
|
1750
|
+
md: { padding: "0.75rem 1.5rem" },
|
|
1751
|
+
lg: {
|
|
1752
|
+
padding: "1rem 2rem",
|
|
1753
|
+
fontSize: "text-lg"
|
|
1754
|
+
},
|
|
1755
|
+
xl: {
|
|
1756
|
+
padding: "1.25rem 2.5rem",
|
|
1757
|
+
fontSize: "text-xl"
|
|
1758
|
+
}
|
|
1759
|
+
};
|
|
1760
|
+
//#endregion
|
|
1761
|
+
//#region ../theme-core/src/utils/tokenOrColor.ts
|
|
1762
|
+
/**
|
|
1763
|
+
* Runtime color-reference fields intentionally accept any string, including
|
|
1764
|
+
* the legacy empty-string "no color" sentinel. Semantic validation needs
|
|
1765
|
+
* palette context and happens in `parseThemeColorReference`.
|
|
1766
|
+
*/
|
|
1767
|
+
const tokenOrCssColorValueSchema = z.string();
|
|
1768
|
+
const CSS_COLOR_FUNCTION_PATTERN = /^(?:rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch|color|color-mix|light-dark)\(/i;
|
|
1769
|
+
const CSS_HEX_COLOR_PATTERN = /^#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
1770
|
+
const CSS_COLOR_KEYWORDS = /* @__PURE__ */ new Set([
|
|
1771
|
+
"transparent",
|
|
1772
|
+
"currentcolor",
|
|
1773
|
+
"inherit",
|
|
1774
|
+
"initial",
|
|
1775
|
+
"revert",
|
|
1776
|
+
"revert-layer",
|
|
1777
|
+
"unset"
|
|
1778
|
+
]);
|
|
1779
|
+
const COMMON_CSS_NAMED_COLORS = /* @__PURE__ */ new Set([
|
|
1780
|
+
"black",
|
|
1781
|
+
"blue",
|
|
1782
|
+
"gray",
|
|
1783
|
+
"green",
|
|
1784
|
+
"grey",
|
|
1785
|
+
"orange",
|
|
1786
|
+
"pink",
|
|
1787
|
+
"purple",
|
|
1788
|
+
"red",
|
|
1789
|
+
"white",
|
|
1790
|
+
"yellow"
|
|
1791
|
+
]);
|
|
1792
|
+
function isCssColorLiteral(value) {
|
|
1793
|
+
const trimmed = value.trim();
|
|
1794
|
+
if (!trimmed) return false;
|
|
1795
|
+
return CSS_HEX_COLOR_PATTERN.test(trimmed) || CSS_COLOR_FUNCTION_PATTERN.test(trimmed) || /^var\(/i.test(trimmed) || CSS_COLOR_KEYWORDS.has(trimmed.toLowerCase());
|
|
1796
|
+
}
|
|
1797
|
+
function parseThemeToken(token) {
|
|
1798
|
+
const trimmed = token.trim();
|
|
1799
|
+
const match = trimmed.match(/^(.*?)-(\d{2,3})$/);
|
|
1800
|
+
if (!match) return {
|
|
1801
|
+
role: trimmed,
|
|
1802
|
+
shade: null
|
|
1803
|
+
};
|
|
1804
|
+
const role = match[1] ?? trimmed;
|
|
1805
|
+
const shade = match[2] ? Number(match[2]) : null;
|
|
1806
|
+
return {
|
|
1807
|
+
role,
|
|
1808
|
+
shade: Number.isFinite(shade) ? shade : null
|
|
1809
|
+
};
|
|
1810
|
+
}
|
|
1811
|
+
function parseContextThemeColorToken(value, context) {
|
|
1812
|
+
const parts = parseColorTokenParts(value);
|
|
1813
|
+
if (parts.kind !== "token") return null;
|
|
1814
|
+
if (!(Boolean(context?.palette?.[value.trim()]) || parts.opacityPercent !== null && Boolean(context?.palette?.[parts.token]))) return null;
|
|
1815
|
+
return value.trim();
|
|
1816
|
+
}
|
|
1817
|
+
function isTokenShapedTypo(value) {
|
|
1818
|
+
if (COMMON_CSS_NAMED_COLORS.has(value.toLowerCase())) return false;
|
|
1819
|
+
if (!/^[a-zA-Z][a-zA-Z0-9]*(?:-[a-zA-Z0-9]+)*(?:\/[^/]+)?$/.test(value)) return false;
|
|
1820
|
+
return !isCssColorLiteral(value);
|
|
1821
|
+
}
|
|
1822
|
+
function warnUnknownThemeColorReference(value) {
|
|
1823
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "production") return;
|
|
1824
|
+
if (!isTokenShapedTypo(value)) return;
|
|
1825
|
+
console.warn(`[theme-core] Unknown Theme V2 color token "${value}" treated as literal CSS. Use raw:* for deliberate custom CSS values.`);
|
|
1826
|
+
}
|
|
1827
|
+
function parseThemeColorReference(input, context) {
|
|
1828
|
+
const trimmed = input.trim();
|
|
1829
|
+
if (trimmed.startsWith("raw:")) return {
|
|
1830
|
+
kind: "literal-css",
|
|
1831
|
+
value: trimmed.slice(4)
|
|
1832
|
+
};
|
|
1833
|
+
const contextToken = parseContextThemeColorToken(trimmed, context);
|
|
1834
|
+
if (contextToken) return {
|
|
1835
|
+
kind: "palette-context-token",
|
|
1836
|
+
token: contextToken
|
|
1837
|
+
};
|
|
1838
|
+
const knownToken = parseThemeColorToken(trimmed);
|
|
1839
|
+
if (knownToken) return {
|
|
1840
|
+
kind: "theme-token",
|
|
1841
|
+
token: knownToken
|
|
1842
|
+
};
|
|
1843
|
+
warnUnknownThemeColorReference(trimmed);
|
|
1844
|
+
return {
|
|
1845
|
+
kind: "literal-css",
|
|
1846
|
+
value: trimmed
|
|
1847
|
+
};
|
|
1848
|
+
}
|
|
1849
|
+
function resolveThemeColorReferenceValue(input, context) {
|
|
1850
|
+
const reference = parseThemeColorReference(input, context);
|
|
1851
|
+
return reference.kind === "literal-css" ? reference.value : rgbColorValue(reference.token);
|
|
1852
|
+
}
|
|
1853
|
+
function resolveTokenOrCssColorValue(input, context) {
|
|
1854
|
+
return resolveThemeColorReferenceValue(input, context);
|
|
1855
|
+
}
|
|
1856
|
+
function resolveOnColorForThemeToken(token) {
|
|
1857
|
+
if (!parseThemeColorToken(token)) return null;
|
|
1858
|
+
const parts = parseColorTokenParts(token);
|
|
1859
|
+
if (parts.kind !== "token") return null;
|
|
1860
|
+
const { role, shade } = parseThemeToken(parts.token);
|
|
1861
|
+
const normalizedRole = role.trim();
|
|
1862
|
+
if (!normalizedRole) return null;
|
|
1863
|
+
if (!shade) return rgbColorValue(`on${normalizedRole.charAt(0).toUpperCase() + normalizedRole.slice(1)}`);
|
|
1864
|
+
return shade <= 400 ? "#000000" : "#FFFFFF";
|
|
1865
|
+
}
|
|
1866
|
+
//#endregion
|
|
1867
|
+
//#region ../theme-core/src/buttons/effectClassification.ts
|
|
1868
|
+
/**
|
|
1869
|
+
* Exhaustive live policy for every registered effect id.
|
|
1870
|
+
*
|
|
1871
|
+
* The resolver consumes the transition payload directly, so adding an effect
|
|
1872
|
+
* cannot update classification without also defining its runtime behavior.
|
|
1873
|
+
*/
|
|
1874
|
+
const BUTTON_EFFECT_POLICIES = {
|
|
1875
|
+
"darken-background": {
|
|
1876
|
+
classification: "colour-transition",
|
|
1877
|
+
transition: {
|
|
1878
|
+
kind: "adjust-shade",
|
|
1879
|
+
direction: "darker"
|
|
1880
|
+
}
|
|
1881
|
+
},
|
|
1882
|
+
"lighten-background": {
|
|
1883
|
+
classification: "colour-transition",
|
|
1884
|
+
transition: {
|
|
1885
|
+
kind: "adjust-shade",
|
|
1886
|
+
direction: "lighter"
|
|
1887
|
+
}
|
|
1888
|
+
},
|
|
1889
|
+
"background-on-hover": {
|
|
1890
|
+
classification: "colour-transition",
|
|
1891
|
+
transition: { kind: "replace-background" }
|
|
1892
|
+
},
|
|
1893
|
+
"background-on-hover-alpha": {
|
|
1894
|
+
classification: "unsupported-colour",
|
|
1895
|
+
reason: "alpha_requires_surface"
|
|
1896
|
+
},
|
|
1897
|
+
"fade-background": {
|
|
1898
|
+
classification: "unsupported-colour",
|
|
1899
|
+
reason: "changes_element_opacity"
|
|
1900
|
+
},
|
|
1901
|
+
"opacity-reduce": {
|
|
1902
|
+
classification: "unsupported-colour",
|
|
1903
|
+
reason: "changes_element_opacity"
|
|
1904
|
+
},
|
|
1905
|
+
"gradient-text": {
|
|
1906
|
+
classification: "unsupported-colour",
|
|
1907
|
+
reason: "changes_foreground"
|
|
1908
|
+
},
|
|
1909
|
+
"text-color-change": {
|
|
1910
|
+
classification: "unsupported-colour",
|
|
1911
|
+
reason: "changes_foreground"
|
|
1912
|
+
},
|
|
1913
|
+
"border-color-change": {
|
|
1914
|
+
classification: "unsupported-colour",
|
|
1915
|
+
reason: "changes_border"
|
|
1916
|
+
},
|
|
1917
|
+
"aurora-glow": {
|
|
1918
|
+
classification: "unsupported-background-overlay",
|
|
1919
|
+
reason: "unresolved_background_overlay"
|
|
1920
|
+
},
|
|
1921
|
+
"cosmic-stardust": {
|
|
1922
|
+
classification: "unsupported-background-overlay",
|
|
1923
|
+
reason: "unresolved_background_overlay"
|
|
1924
|
+
},
|
|
1925
|
+
"gradient-border-fill": {
|
|
1926
|
+
classification: "unsupported-background-overlay",
|
|
1927
|
+
reason: "unresolved_background_overlay"
|
|
1928
|
+
},
|
|
1929
|
+
"animated-gradient-border-fill": {
|
|
1930
|
+
classification: "unsupported-background-overlay",
|
|
1931
|
+
reason: "unresolved_background_overlay"
|
|
1932
|
+
},
|
|
1933
|
+
"nav-underline": {
|
|
1934
|
+
classification: "not-button",
|
|
1935
|
+
reason: "not_button_effect"
|
|
1936
|
+
},
|
|
1937
|
+
"nav-frosted-base": {
|
|
1938
|
+
classification: "not-button",
|
|
1939
|
+
reason: "not_button_effect"
|
|
1940
|
+
},
|
|
1941
|
+
"nav-frosted-hover": {
|
|
1942
|
+
classification: "not-button",
|
|
1943
|
+
reason: "not_button_effect"
|
|
1944
|
+
},
|
|
1945
|
+
"nav-frosted-active": {
|
|
1946
|
+
classification: "not-button",
|
|
1947
|
+
reason: "not_button_effect"
|
|
1948
|
+
},
|
|
1949
|
+
"animated-gradient": { classification: "non-colour" },
|
|
1950
|
+
"border-glow": {
|
|
1951
|
+
classification: "unsupported-colour",
|
|
1952
|
+
reason: "changes_shadow_colour"
|
|
1953
|
+
},
|
|
1954
|
+
"drop-shadow": { classification: "decorative-colour" },
|
|
1955
|
+
"inner-shadow": { classification: "decorative-colour" },
|
|
1956
|
+
"neumorphic-shadow": { classification: "decorative-colour" },
|
|
1957
|
+
"outer-glow": {
|
|
1958
|
+
classification: "unsupported-colour",
|
|
1959
|
+
reason: "changes_shadow_colour"
|
|
1960
|
+
},
|
|
1961
|
+
"retro-3d-shadow": { classification: "decorative-colour" },
|
|
1962
|
+
"scale-up": { classification: "non-colour" },
|
|
1963
|
+
"scale-down": { classification: "non-colour" },
|
|
1964
|
+
lift: { classification: "non-colour" },
|
|
1965
|
+
"press-down": { classification: "non-colour" },
|
|
1966
|
+
pop: { classification: "non-colour" },
|
|
1967
|
+
"border-bottom-grow": { classification: "non-colour" },
|
|
1968
|
+
"sketchy-border": { classification: "decorative-colour" },
|
|
1969
|
+
"inner-dashed-outline": { classification: "decorative-colour" },
|
|
1970
|
+
"pulse-animation": {
|
|
1971
|
+
classification: "unsupported-colour",
|
|
1972
|
+
reason: "changes_element_opacity"
|
|
1973
|
+
}
|
|
1974
|
+
};
|
|
1975
|
+
function validateButtonEffectOptions(effect) {
|
|
1976
|
+
const parsed = buttonEffectApplicationSchema.safeParse(effect);
|
|
1977
|
+
if (parsed.success) return { ok: true };
|
|
1978
|
+
const firstIssue = parsed.error.issues[0];
|
|
1979
|
+
const firstPathPart = firstIssue?.path[firstIssue.path.length - 1];
|
|
1980
|
+
return {
|
|
1981
|
+
ok: false,
|
|
1982
|
+
option: (firstIssue?.code === "unrecognized_keys" ? firstIssue.keys[0] : void 0) ?? (typeof firstPathPart === "string" ? firstPathPart : "options")
|
|
1983
|
+
};
|
|
1984
|
+
}
|
|
1985
|
+
function getButtonEffectPolicy(effectId) {
|
|
1986
|
+
return Object.prototype.hasOwnProperty.call(BUTTON_EFFECT_POLICIES, effectId) ? BUTTON_EFFECT_POLICIES[effectId] : null;
|
|
1987
|
+
}
|
|
1988
|
+
//#endregion
|
|
1989
|
+
//#region ../theme-core/src/buttons/buttonColourTransitions.ts
|
|
1990
|
+
function applyColourEffects(input) {
|
|
1991
|
+
return (input.effects ?? []).reduce((current, effect) => current.ok ? applyEffect(input, current, effect) : current, {
|
|
1992
|
+
ok: true,
|
|
1993
|
+
treatment: input.treatment,
|
|
1994
|
+
nonColourEffects: []
|
|
1995
|
+
});
|
|
1996
|
+
}
|
|
1997
|
+
function applyEffect(input, current, effect) {
|
|
1998
|
+
const policy = getButtonEffectPolicy(effect.effectId);
|
|
1999
|
+
if (policy === null) return unknownEffect(input, effect);
|
|
2000
|
+
if (policy.classification === "unsupported-colour" || policy.classification === "unsupported-background-overlay" || policy.classification === "not-button") return unsupportedEffect(input, effect, policy.reason);
|
|
2001
|
+
const options = validateButtonEffectOptions(effect);
|
|
2002
|
+
if (!options.ok) return invalidEffectOption(input, effect, options.option);
|
|
2003
|
+
return policy.classification === "colour-transition" ? transitionColour(input, current, effect) : {
|
|
2004
|
+
...current,
|
|
2005
|
+
nonColourEffects: [...current.nonColourEffects, effect]
|
|
2006
|
+
};
|
|
2007
|
+
}
|
|
2008
|
+
function transitionColour(input, current, effect) {
|
|
2009
|
+
if (effect.effectId === "background-on-hover") {
|
|
2010
|
+
const colorToken = readOpaqueToken(effect);
|
|
2011
|
+
return colorToken === null ? invalidEffectOption(input, effect, "colorToken") : {
|
|
2012
|
+
...current,
|
|
2013
|
+
treatment: {
|
|
2014
|
+
type: "solid",
|
|
2015
|
+
colorToken
|
|
2016
|
+
}
|
|
2017
|
+
};
|
|
2018
|
+
}
|
|
2019
|
+
if (effect.effectId !== "darken-background" && effect.effectId !== "lighten-background") return unknownEffect(input, effect);
|
|
2020
|
+
if (current.treatment.type !== "solid") return inapplicableEffect(input, effect, current.treatment);
|
|
2021
|
+
const amount = readShadeAmount(effect);
|
|
2022
|
+
if (amount === null) return invalidEffectOption(input, effect, "amount");
|
|
2023
|
+
return {
|
|
2024
|
+
...current,
|
|
2025
|
+
treatment: {
|
|
2026
|
+
type: "solid",
|
|
2027
|
+
colorToken: adjustShade(current.treatment.colorToken, effect.effectId === "darken-background" ? amount : -amount, input.palette)
|
|
2028
|
+
}
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
2031
|
+
function adjustShade(token, amount, palette) {
|
|
2032
|
+
const match = token.match(/^(.*)-(\d{2,3})$/);
|
|
2033
|
+
const base = match?.[1] ?? token;
|
|
2034
|
+
const currentShade = match?.[2] === void 0 ? 500 : Number(match[2]);
|
|
2035
|
+
const availableShades = [
|
|
2036
|
+
50,
|
|
2037
|
+
100,
|
|
2038
|
+
200,
|
|
2039
|
+
300,
|
|
2040
|
+
400,
|
|
2041
|
+
500,
|
|
2042
|
+
600,
|
|
2043
|
+
700,
|
|
2044
|
+
800,
|
|
2045
|
+
900,
|
|
2046
|
+
950
|
|
2047
|
+
].filter((shade) => typeof palette[`${base}-${shade}`] === "string");
|
|
2048
|
+
if (availableShades.length === 0) return token;
|
|
2049
|
+
const firstShade = availableShades[0];
|
|
2050
|
+
if (firstShade === void 0) return token;
|
|
2051
|
+
const exactIndex = availableShades.indexOf(currentShade);
|
|
2052
|
+
const startingIndex = exactIndex >= 0 ? exactIndex : availableShades.indexOf(availableShades.reduce((closestShade, shade) => Math.abs(shade - currentShade) < Math.abs(closestShade - currentShade) ? shade : closestShade, firstShade));
|
|
2053
|
+
const stepCount = Math.abs(amount) / 100;
|
|
2054
|
+
const direction = amount < 0 ? -1 : 1;
|
|
2055
|
+
const targetShade = availableShades[Math.max(0, Math.min(availableShades.length - 1, startingIndex + direction * stepCount))];
|
|
2056
|
+
return targetShade === void 0 ? token : unsafeAsOpaqueButtonColourToken(`${base}-${targetShade}`);
|
|
2057
|
+
}
|
|
2058
|
+
function readShadeAmount(effect) {
|
|
2059
|
+
const value = effect.options?.amount ?? 100;
|
|
2060
|
+
return typeof value === "number" && Number.isFinite(value) && value >= 0 && value % 100 === 0 ? value : null;
|
|
2061
|
+
}
|
|
2062
|
+
function readOpaqueToken(effect) {
|
|
2063
|
+
return parseOpaqueButtonColourToken(effect.options?.colorToken ?? "neutral-800");
|
|
2064
|
+
}
|
|
2065
|
+
function unsupportedEffect(input, effect, reason) {
|
|
2066
|
+
return {
|
|
2067
|
+
ok: false,
|
|
2068
|
+
error: {
|
|
2069
|
+
tag: "unsupported_colour_effect",
|
|
2070
|
+
variantId: input.variantId,
|
|
2071
|
+
state: input.state,
|
|
2072
|
+
effectId: effect.effectId,
|
|
2073
|
+
reason
|
|
2074
|
+
}
|
|
2075
|
+
};
|
|
2076
|
+
}
|
|
2077
|
+
function invalidEffectOption(input, effect, option) {
|
|
2078
|
+
return {
|
|
2079
|
+
ok: false,
|
|
2080
|
+
error: {
|
|
2081
|
+
tag: "invalid_colour_effect_options",
|
|
2082
|
+
variantId: input.variantId,
|
|
2083
|
+
state: input.state,
|
|
2084
|
+
effectId: effect.effectId,
|
|
2085
|
+
option
|
|
2086
|
+
}
|
|
2087
|
+
};
|
|
2088
|
+
}
|
|
2089
|
+
function inapplicableEffect(input, effect, treatment) {
|
|
2090
|
+
return {
|
|
2091
|
+
ok: false,
|
|
2092
|
+
error: {
|
|
2093
|
+
tag: "inapplicable_colour_effect",
|
|
2094
|
+
variantId: input.variantId,
|
|
2095
|
+
state: input.state,
|
|
2096
|
+
effectId: effect.effectId,
|
|
2097
|
+
treatment: treatment.type
|
|
2098
|
+
}
|
|
2099
|
+
};
|
|
2100
|
+
}
|
|
2101
|
+
function unknownEffect(input, effect) {
|
|
2102
|
+
return {
|
|
2103
|
+
ok: false,
|
|
2104
|
+
error: {
|
|
2105
|
+
tag: "unknown_button_effect",
|
|
2106
|
+
variantId: input.variantId,
|
|
2107
|
+
state: input.state,
|
|
2108
|
+
effectId: effect.effectId
|
|
2109
|
+
}
|
|
2110
|
+
};
|
|
2111
|
+
}
|
|
2112
|
+
//#endregion
|
|
2113
|
+
//#region ../theme-core/src/buttons/buttonColourContract.ts
|
|
2114
|
+
const BUTTON_VISUAL_STATES = [
|
|
2115
|
+
"base",
|
|
2116
|
+
"hover",
|
|
2117
|
+
"focus",
|
|
2118
|
+
"active",
|
|
2119
|
+
"disabled"
|
|
2120
|
+
];
|
|
2121
|
+
const BUTTON_CONTRAST_POLICY = {
|
|
2122
|
+
textMinimumRatio: 4.5,
|
|
2123
|
+
nonTextMinimumRatio: 3,
|
|
2124
|
+
filledMinimumDeltaE: .12,
|
|
2125
|
+
gradientSamplesPerSegment: 20,
|
|
2126
|
+
alphaBackgrounds: "reject-without-known-surface",
|
|
2127
|
+
disabled: "validated-colour-pair-with-muted-control-opacity"
|
|
2128
|
+
};
|
|
2129
|
+
function formatButtonColourContractError(error) {
|
|
2130
|
+
switch (error.tag) {
|
|
2131
|
+
case "unknown_palette_token": return `Button "${error.variantId}" ${error.state} state uses unknown palette token "${error.token}".`;
|
|
2132
|
+
case "insufficient_contrast": return `Button "${error.variantId}" ${error.state} state has ${error.ratio.toFixed(2)}:1 contrast (${error.requiredRatio}:1 required).`;
|
|
2133
|
+
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).`;
|
|
2134
|
+
case "unsupported_colour_effect": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" is not contrast-safe (${error.reason}).`;
|
|
2135
|
+
case "invalid_colour_effect_options": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" has an invalid ${error.option} option.`;
|
|
2136
|
+
case "inapplicable_colour_effect": return `Button "${error.variantId}" ${error.state} effect "${error.effectId}" cannot apply to a ${error.treatment} treatment.`;
|
|
2137
|
+
case "unknown_button_effect": return `Button "${error.variantId}" ${error.state} uses unknown effect "${error.effectId}".`;
|
|
2138
|
+
}
|
|
2139
|
+
}
|
|
2140
|
+
/** One separation decision for filled states and contextual hover candidates. */
|
|
2141
|
+
function buttonFillSeparation(fill, ground) {
|
|
2142
|
+
const deltaE = hexOklabDistance(fill, ground);
|
|
2143
|
+
return {
|
|
2144
|
+
deltaE,
|
|
2145
|
+
distinct: deltaE >= BUTTON_CONTRAST_POLICY.filledMinimumDeltaE
|
|
2146
|
+
};
|
|
2147
|
+
}
|
|
2148
|
+
/** All paint beneath the control; ordinary solids have just one ground. */
|
|
2149
|
+
const buttonSurfaceGrounds = (surface) => [surface.backgroundHex, ...surface.backgroundSamples ?? []];
|
|
2150
|
+
/** A filled state clears each ground by its fill OR a declared edge at 3:1. */
|
|
2151
|
+
function buttonSurfaceSeparation(fill, surface, edge) {
|
|
2152
|
+
const ink = edge?.border?.marksBoundary ? edge.border.boundaryInk ? edge.palette[edge.border.boundaryInk] : edge.labelInk : void 0;
|
|
2153
|
+
return buttonSurfaceGrounds(surface).map((ground) => {
|
|
2154
|
+
const separation = buttonFillSeparation(fill, ground);
|
|
2155
|
+
const distinct = separation.distinct || ink !== void 0 && contrastRatio(ink, ground) >= BUTTON_CONTRAST_POLICY.nonTextMinimumRatio;
|
|
2156
|
+
return {
|
|
2157
|
+
...separation,
|
|
2158
|
+
distinct,
|
|
2159
|
+
ground
|
|
2160
|
+
};
|
|
2161
|
+
}).reduce((worst, next) => {
|
|
2162
|
+
if (worst.distinct !== next.distinct) return worst.distinct ? next : worst;
|
|
2163
|
+
return next.deltaE < worst.deltaE ? next : worst;
|
|
2164
|
+
});
|
|
2165
|
+
}
|
|
2166
|
+
function validateButtonFillSeparation(input) {
|
|
2167
|
+
const token = input.border?.marksBoundary ? input.border.boundaryInk : void 0;
|
|
2168
|
+
if (token && !input.palette[token]) return {
|
|
2169
|
+
ok: false,
|
|
2170
|
+
error: {
|
|
2171
|
+
tag: "unknown_palette_token",
|
|
2172
|
+
variantId: input.variantId,
|
|
2173
|
+
state: input.state,
|
|
2174
|
+
token
|
|
2175
|
+
}
|
|
2176
|
+
};
|
|
2177
|
+
const separation = buttonSurfaceSeparation(input.buttonPaint, input.surface, input);
|
|
2178
|
+
return separation.distinct ? { ok: true } : {
|
|
2179
|
+
ok: false,
|
|
2180
|
+
error: {
|
|
2181
|
+
tag: "insufficient_surface_separation",
|
|
2182
|
+
variantId: input.variantId,
|
|
2183
|
+
state: input.state,
|
|
2184
|
+
buttonPaint: input.buttonPaint,
|
|
2185
|
+
surface: separation.ground,
|
|
2186
|
+
deltaE: separation.deltaE,
|
|
2187
|
+
requiredDeltaE: BUTTON_CONTRAST_POLICY.filledMinimumDeltaE
|
|
2188
|
+
}
|
|
2189
|
+
};
|
|
2190
|
+
}
|
|
2191
|
+
function validateButtonTextContrast(input) {
|
|
2192
|
+
const ratio = contrastRatio(input.backgroundHex, input.foregroundHex, input.colourIndex);
|
|
2193
|
+
return ratio >= BUTTON_CONTRAST_POLICY.textMinimumRatio ? { ok: true } : {
|
|
2194
|
+
ok: false,
|
|
2195
|
+
error: {
|
|
2196
|
+
tag: "insufficient_contrast",
|
|
2197
|
+
variantId: input.variantId,
|
|
2198
|
+
state: input.state,
|
|
2199
|
+
background: input.background,
|
|
2200
|
+
foreground: input.foreground,
|
|
2201
|
+
ratio,
|
|
2202
|
+
requiredRatio: BUTTON_CONTRAST_POLICY.textMinimumRatio
|
|
2203
|
+
}
|
|
2204
|
+
};
|
|
2205
|
+
}
|
|
2206
|
+
/** A text-token slab inverts the palette's text/background pair, including text shades. */
|
|
2207
|
+
function solidForegroundToken(backgroundToken) {
|
|
2208
|
+
return /^text(?:-\d+)?$/.test(backgroundToken) ? "background" : onColorTokenName(backgroundToken);
|
|
2209
|
+
}
|
|
2210
|
+
//#endregion
|
|
2211
|
+
//#region ../theme-core/src/buttons/contextualHover.ts
|
|
2212
|
+
function resolveContextualHoverPreference(input) {
|
|
2213
|
+
const preferred = input.instruction.preferredToken;
|
|
2214
|
+
if (preferred && isSafeCandidate(preferred, input.palette, input.surface, input.colourIndex, input.border)) return {
|
|
2215
|
+
kind: "resolved",
|
|
2216
|
+
token: preferred,
|
|
2217
|
+
repair: null
|
|
2218
|
+
};
|
|
2219
|
+
const contextual = resolveContextualHover(input);
|
|
2220
|
+
return contextual.kind === "resolved" ? {
|
|
2221
|
+
kind: "resolved",
|
|
2222
|
+
token: contextual.token,
|
|
2223
|
+
repair: preferred ? {
|
|
2224
|
+
kind: "preferred-token-replaced",
|
|
2225
|
+
preferredToken: preferred,
|
|
2226
|
+
contextualToken: contextual.token
|
|
2227
|
+
} : null
|
|
2228
|
+
} : contextual;
|
|
2229
|
+
}
|
|
2230
|
+
/**
|
|
2231
|
+
* Resolves semantic shade movement from real palette steps. The persisted
|
|
2232
|
+
* instruction owns the colour family and deterministic unknown-surface
|
|
2233
|
+
* fallback; a proven surface may select the opposite direction when it gives
|
|
2234
|
+
* the button stronger separation while retaining the shared contrast contract.
|
|
2235
|
+
*/
|
|
2236
|
+
function resolveContextualHover(input) {
|
|
2237
|
+
const candidates = shadeCandidates(input.instruction.seedToken, input.palette);
|
|
2238
|
+
if (candidates.length === 0) return {
|
|
2239
|
+
kind: "unavailable",
|
|
2240
|
+
reason: "no-distinct-shade"
|
|
2241
|
+
};
|
|
2242
|
+
const textSafe = candidates.filter((candidate) => hasSafeTextContrast(candidate.token, input.palette, input.colourIndex));
|
|
2243
|
+
if (textSafe.length === 0) return {
|
|
2244
|
+
kind: "unavailable",
|
|
2245
|
+
reason: "no-text-safe-candidate"
|
|
2246
|
+
};
|
|
2247
|
+
if (!input.surface) {
|
|
2248
|
+
const selected = textSafe.find((candidate) => candidate.direction === input.instruction.fallbackDirection) ?? textSafe[0];
|
|
2249
|
+
return selected ? {
|
|
2250
|
+
kind: "resolved",
|
|
2251
|
+
token: selected.token,
|
|
2252
|
+
direction: selected.direction,
|
|
2253
|
+
evidence: "fallback-direction"
|
|
2254
|
+
} : {
|
|
2255
|
+
kind: "unavailable",
|
|
2256
|
+
reason: "no-text-safe-candidate"
|
|
2257
|
+
};
|
|
2258
|
+
}
|
|
2259
|
+
const selected = selectSurfaceSafeHover(textSafe, {
|
|
2260
|
+
palette: input.palette,
|
|
2261
|
+
surface: input.surface,
|
|
2262
|
+
colourIndex: input.colourIndex,
|
|
2263
|
+
fallbackDirection: input.instruction.fallbackDirection,
|
|
2264
|
+
border: input.border
|
|
2265
|
+
});
|
|
2266
|
+
return selected ? {
|
|
2267
|
+
kind: "resolved",
|
|
2268
|
+
token: selected.token,
|
|
2269
|
+
direction: selected.direction,
|
|
2270
|
+
evidence: "known-surface"
|
|
2271
|
+
} : {
|
|
2272
|
+
kind: "unavailable",
|
|
2273
|
+
reason: "no-surface-safe-candidate"
|
|
2274
|
+
};
|
|
2275
|
+
}
|
|
2276
|
+
/** Rank the proven-surface candidates without mixing selection with fallback policy. */
|
|
2277
|
+
function selectSurfaceSafeHover(candidates, input) {
|
|
2278
|
+
return candidates.flatMap((candidate) => {
|
|
2279
|
+
const separation = buttonSurfaceSeparation(input.palette[candidate.token] ?? "", input.surface, {
|
|
2280
|
+
border: input.border,
|
|
2281
|
+
palette: input.palette,
|
|
2282
|
+
labelInk: input.palette[solidForegroundToken(candidate.token)] ?? ""
|
|
2283
|
+
});
|
|
2284
|
+
return separation.distinct ? [{
|
|
2285
|
+
...candidate,
|
|
2286
|
+
surfaceDistance: separation.deltaE
|
|
2287
|
+
}] : [];
|
|
2288
|
+
}).sort((left, right) => {
|
|
2289
|
+
const distanceDifference = left.distance - right.distance;
|
|
2290
|
+
if (distanceDifference !== 0) return distanceDifference;
|
|
2291
|
+
const contrastDifference = (right.surfaceDistance ?? 0) - (left.surfaceDistance ?? 0);
|
|
2292
|
+
if (contrastDifference !== 0) return contrastDifference;
|
|
2293
|
+
if (left.direction === right.direction) return left.token.localeCompare(right.token);
|
|
2294
|
+
return left.direction === input.fallbackDirection ? -1 : 1;
|
|
2295
|
+
})[0];
|
|
2296
|
+
}
|
|
2297
|
+
function shadeCandidates(seedToken, palette) {
|
|
2298
|
+
const match = String(seedToken).match(/^(.*?)(?:-(\d{2,3}))?$/);
|
|
2299
|
+
const family = match?.[1] ?? String(seedToken);
|
|
2300
|
+
const currentShade = match?.[2] ? Number(match[2]) : 500;
|
|
2301
|
+
const seedHex = palette[seedToken];
|
|
2302
|
+
const shades = Object.keys(palette).flatMap((token) => {
|
|
2303
|
+
const shade = token.match(new RegExp(`^${escapeRegExp(family)}-(\\d{2,3})$`));
|
|
2304
|
+
return shade?.[1] ? [Number(shade[1])] : [];
|
|
2305
|
+
}).filter((shade) => Number.isFinite(shade)).sort((left, right) => left - right);
|
|
2306
|
+
const lower = [...shades].filter((shade) => shade < currentShade).sort((left, right) => right - left);
|
|
2307
|
+
const higher = shades.filter((shade) => shade > currentShade);
|
|
2308
|
+
return [...lower.map((shade) => candidate(family, shade, currentShade, "lighter", seedHex, palette)), ...higher.map((shade) => candidate(family, shade, currentShade, "darker", seedHex, palette))].filter((value) => value !== null);
|
|
2309
|
+
}
|
|
2310
|
+
function candidate(family, shade, currentShade, direction, seedHex, palette) {
|
|
2311
|
+
const token = parseOpaqueButtonColourToken(`${family}-${shade}`);
|
|
2312
|
+
if (token === null) return null;
|
|
2313
|
+
const candidateHex = palette[token];
|
|
2314
|
+
if (!candidateHex || candidateHex === seedHex) return null;
|
|
2315
|
+
return {
|
|
2316
|
+
token,
|
|
2317
|
+
direction,
|
|
2318
|
+
distance: Math.abs(shade - currentShade),
|
|
2319
|
+
surfaceDistance: null
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2322
|
+
function hasSafeTextContrast(token, palette, colourIndex) {
|
|
2323
|
+
const background = palette[token];
|
|
2324
|
+
const foreground = palette[solidForegroundToken(token)];
|
|
2325
|
+
return typeof background === "string" && typeof foreground === "string" && contrastRatio(background, foreground, colourIndex) >= BUTTON_CONTRAST_POLICY.textMinimumRatio;
|
|
2326
|
+
}
|
|
2327
|
+
function isSafeCandidate(token, palette, surface, colourIndex, border) {
|
|
2328
|
+
if (!hasSafeTextContrast(token, palette, colourIndex)) return false;
|
|
2329
|
+
return surface ? buttonSurfaceSeparation(palette[token] ?? "", surface, {
|
|
2330
|
+
border,
|
|
2331
|
+
palette,
|
|
2332
|
+
labelInk: palette[solidForegroundToken(token)] ?? ""
|
|
2333
|
+
}).distinct : true;
|
|
2334
|
+
}
|
|
2335
|
+
function escapeRegExp(value) {
|
|
2336
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
2337
|
+
}
|
|
2338
|
+
//#endregion
|
|
2339
|
+
//#region ../theme-core/src/buttons/resolveButtonHoverTreatment.ts
|
|
2340
|
+
function resolveButtonHoverTreatment(input) {
|
|
2341
|
+
if (input.variant.contextualHover) {
|
|
2342
|
+
const contextual = resolveContextualHoverPreference({
|
|
2343
|
+
instruction: input.variant.contextualHover,
|
|
2344
|
+
palette: input.palette,
|
|
2345
|
+
colourIndex: input.colourIndex,
|
|
2346
|
+
surface: input.surface,
|
|
2347
|
+
border: input.variant.border
|
|
2348
|
+
});
|
|
2349
|
+
if (contextual.kind === "resolved") return {
|
|
2350
|
+
treatment: {
|
|
2351
|
+
type: "solid",
|
|
2352
|
+
colorToken: contextual.token
|
|
2353
|
+
},
|
|
2354
|
+
repair: contextual.repair
|
|
2355
|
+
};
|
|
2356
|
+
}
|
|
2357
|
+
const token = input.variant.hoverBackgroundToken ?? (input.global.hoverColor === "token" ? input.global.hoverColorToken : void 0);
|
|
2358
|
+
return {
|
|
2359
|
+
treatment: token === void 0 ? input.fallback : {
|
|
2360
|
+
type: "solid",
|
|
2361
|
+
colorToken: token
|
|
2362
|
+
},
|
|
2363
|
+
repair: null
|
|
2364
|
+
};
|
|
2365
|
+
}
|
|
2366
|
+
//#endregion
|
|
2367
|
+
//#region ../theme-core/src/buttons/resolveButtonColourStates.ts
|
|
2368
|
+
function mapVisualStates(value) {
|
|
2369
|
+
return {
|
|
2370
|
+
base: value("base"),
|
|
2371
|
+
hover: value("hover"),
|
|
2372
|
+
focus: value("focus"),
|
|
2373
|
+
active: value("active"),
|
|
2374
|
+
disabled: value("disabled")
|
|
2375
|
+
};
|
|
2376
|
+
}
|
|
2377
|
+
function compileButtonColourStates(input) {
|
|
2378
|
+
if (input.variant.visualStates) return compileDeclaredVisualStates(input, input.variant.visualStates);
|
|
2379
|
+
const base = applyColourEffects({
|
|
2380
|
+
variantId: input.variant.id,
|
|
2381
|
+
state: "base",
|
|
2382
|
+
treatment: input.variant.background,
|
|
2383
|
+
effects: input.variant.effects?.base,
|
|
2384
|
+
palette: input.palette
|
|
2385
|
+
});
|
|
2386
|
+
if (!base.ok) return base;
|
|
2387
|
+
const hover = resolveButtonHoverTreatment({
|
|
2388
|
+
variant: input.variant,
|
|
2389
|
+
global: input.global,
|
|
2390
|
+
fallback: base.treatment,
|
|
2391
|
+
palette: input.palette,
|
|
2392
|
+
surface: input.surface,
|
|
2393
|
+
colourIndex: input.colourIndex
|
|
2394
|
+
});
|
|
2395
|
+
const colours = collectStateColours(mapVisualStates((state) => compileVisualState(input, state, state === "hover" ? hover.treatment : base.treatment, base.nonColourEffects)));
|
|
2396
|
+
return colours.ok ? {
|
|
2397
|
+
...colours,
|
|
2398
|
+
contextualHoverRepair: hover.repair
|
|
2399
|
+
} : colours;
|
|
2400
|
+
}
|
|
2401
|
+
function compileDeclaredVisualStates(input, states) {
|
|
2402
|
+
const hover = resolveButtonHoverTreatment({
|
|
2403
|
+
...input,
|
|
2404
|
+
variant: {
|
|
2405
|
+
...input.variant,
|
|
2406
|
+
contextualHover: states.hover.contextualHover,
|
|
2407
|
+
border: states.hover.border === "none" ? void 0 : states.hover.border,
|
|
2408
|
+
hoverBackgroundToken: void 0
|
|
2409
|
+
},
|
|
2410
|
+
global: {
|
|
2411
|
+
...input.global,
|
|
2412
|
+
hoverColor: "none",
|
|
2413
|
+
hoverColorToken: void 0
|
|
2414
|
+
},
|
|
2415
|
+
fallback: states.hover.background
|
|
2416
|
+
});
|
|
2417
|
+
const colours = collectStateColours(mapVisualStates((state) => compileDeclaredVisualState(input, states, state, state === "hover" ? hover.treatment : states[state].background)));
|
|
2418
|
+
return colours.ok ? {
|
|
2419
|
+
...colours,
|
|
2420
|
+
focusIndicator: states.focus.indicator ? {
|
|
2421
|
+
kind: "surface-role",
|
|
2422
|
+
colorCss: input.surface?.foregroundCss ?? surfaceForegroundValue("text"),
|
|
2423
|
+
width: states.focus.indicator.width,
|
|
2424
|
+
offset: states.focus.indicator.offset,
|
|
2425
|
+
minimumSurfaceContrast: BUTTON_CONTRAST_POLICY.nonTextMinimumRatio
|
|
2426
|
+
} : colours.focusIndicator,
|
|
2427
|
+
contextualHoverRepair: hover.repair
|
|
2428
|
+
} : colours;
|
|
2429
|
+
}
|
|
2430
|
+
function compileDeclaredVisualState(input, states, state, treatment) {
|
|
2431
|
+
const appearance = states[state];
|
|
2432
|
+
const effects = state === "base" ? appearance.effects : [...states.base.effects, ...appearance.effects];
|
|
2433
|
+
const transition = applyColourEffects({
|
|
2434
|
+
variantId: input.variant.id,
|
|
2435
|
+
state,
|
|
2436
|
+
treatment,
|
|
2437
|
+
effects,
|
|
2438
|
+
palette: input.palette
|
|
2439
|
+
});
|
|
2440
|
+
if (!transition.ok) return transition;
|
|
2441
|
+
const resolved = resolveTreatment({
|
|
2442
|
+
variantId: input.variant.id,
|
|
2443
|
+
state,
|
|
2444
|
+
treatment: transition.treatment,
|
|
2445
|
+
border: appearance.border === "none" ? void 0 : appearance.border,
|
|
2446
|
+
palette: input.palette,
|
|
2447
|
+
surface: input.surface,
|
|
2448
|
+
colourIndex: input.colourIndex
|
|
2449
|
+
});
|
|
2450
|
+
return resolved.ok ? {
|
|
2451
|
+
...resolved,
|
|
2452
|
+
nonColourEffects: state === "disabled" ? [] : state === "base" ? transition.nonColourEffects : transition.nonColourEffects.filter((effect) => appearance.effects.includes(effect))
|
|
2453
|
+
} : resolved;
|
|
2454
|
+
}
|
|
2455
|
+
function compileVisualState(input, state, treatment, baseEffects) {
|
|
2456
|
+
const transition = state === "hover" || state === "focus" || state === "active" ? applyColourEffects({
|
|
2457
|
+
variantId: input.variant.id,
|
|
2458
|
+
state,
|
|
2459
|
+
treatment,
|
|
2460
|
+
effects: input.variant.effects?.[state],
|
|
2461
|
+
palette: input.palette
|
|
2462
|
+
}) : {
|
|
2463
|
+
ok: true,
|
|
2464
|
+
treatment,
|
|
2465
|
+
nonColourEffects: state === "base" ? baseEffects : []
|
|
2466
|
+
};
|
|
2467
|
+
if (!transition.ok) return transition;
|
|
2468
|
+
const resolved = resolveTreatment({
|
|
2469
|
+
variantId: input.variant.id,
|
|
2470
|
+
state,
|
|
2471
|
+
treatment: transition.treatment,
|
|
2472
|
+
palette: input.palette,
|
|
2473
|
+
surface: input.surface,
|
|
2474
|
+
colourIndex: input.colourIndex,
|
|
2475
|
+
border: input.variant.border
|
|
2476
|
+
});
|
|
2477
|
+
return resolved.ok ? {
|
|
2478
|
+
...resolved,
|
|
2479
|
+
nonColourEffects: transition.nonColourEffects
|
|
2480
|
+
} : resolved;
|
|
2481
|
+
}
|
|
2482
|
+
function collectStateColours(results) {
|
|
2483
|
+
if (!results.base.ok) return results.base;
|
|
2484
|
+
if (!results.hover.ok) return results.hover;
|
|
2485
|
+
if (!results.focus.ok) return results.focus;
|
|
2486
|
+
if (!results.active.ok) return results.active;
|
|
2487
|
+
if (!results.disabled.ok) return results.disabled;
|
|
2488
|
+
const states = {
|
|
2489
|
+
base: results.base.colour,
|
|
2490
|
+
hover: results.hover.colour,
|
|
2491
|
+
focus: results.focus.colour,
|
|
2492
|
+
active: results.active.colour,
|
|
2493
|
+
disabled: results.disabled.colour
|
|
2494
|
+
};
|
|
2495
|
+
return {
|
|
2496
|
+
ok: true,
|
|
2497
|
+
states,
|
|
2498
|
+
focusIndicator: resolveFocusIndicator(states.focus),
|
|
2499
|
+
nonColourEffects: Object.fromEntries(Object.entries(results).flatMap(([state, result]) => result.ok && result.nonColourEffects.length > 0 ? [[state, [...result.nonColourEffects]]] : []))
|
|
2500
|
+
};
|
|
2501
|
+
}
|
|
2502
|
+
function resolveTreatment(input) {
|
|
2503
|
+
const treatment = input.treatment;
|
|
2504
|
+
switch (treatment.type) {
|
|
2505
|
+
case "surface":
|
|
2506
|
+
if (input.surface) {
|
|
2507
|
+
const surface = input.surface;
|
|
2508
|
+
const foreground = buttonSurfaceGrounds(surface).map((backgroundHex) => validateButtonTextContrast({
|
|
2509
|
+
...input,
|
|
2510
|
+
background: "surface",
|
|
2511
|
+
backgroundHex,
|
|
2512
|
+
foreground: "surface-foreground",
|
|
2513
|
+
foregroundHex: surface.foregroundHex
|
|
2514
|
+
})).find((result) => !result.ok) ?? { ok: true };
|
|
2515
|
+
if (!foreground.ok) return foreground;
|
|
2516
|
+
}
|
|
2517
|
+
return {
|
|
2518
|
+
ok: true,
|
|
2519
|
+
colour: {
|
|
2520
|
+
kind: "surface",
|
|
2521
|
+
role: treatment.role,
|
|
2522
|
+
backgroundCss: "transparent",
|
|
2523
|
+
foregroundCss: input.surface?.foregroundCss ?? surfaceForegroundValue(treatment.role)
|
|
2524
|
+
}
|
|
2525
|
+
};
|
|
2526
|
+
case "solid": return resolveSolid(input, treatment.colorToken);
|
|
2527
|
+
case "gradient": return resolveGradient(input, treatment);
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
function resolveFocusIndicator(colour) {
|
|
2531
|
+
switch (colour.kind) {
|
|
2532
|
+
case "solid":
|
|
2533
|
+
case "known-solid": return {
|
|
2534
|
+
kind: "two-tone",
|
|
2535
|
+
innerCss: colour.foregroundCss,
|
|
2536
|
+
outerCss: colour.backgroundCss,
|
|
2537
|
+
minimumPairContrast: BUTTON_CONTRAST_POLICY.textMinimumRatio
|
|
2538
|
+
};
|
|
2539
|
+
case "gradient": return {
|
|
2540
|
+
kind: "two-tone",
|
|
2541
|
+
innerCss: colour.foregroundCss,
|
|
2542
|
+
outerCss: tokenCss(colour.backgroundTokens[0]),
|
|
2543
|
+
minimumPairContrast: BUTTON_CONTRAST_POLICY.textMinimumRatio
|
|
2544
|
+
};
|
|
2545
|
+
case "surface": return {
|
|
2546
|
+
kind: "surface-role",
|
|
2547
|
+
colorCss: colour.foregroundCss,
|
|
2548
|
+
minimumSurfaceContrast: BUTTON_CONTRAST_POLICY.nonTextMinimumRatio
|
|
2549
|
+
};
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
function resolveSolid(input, backgroundToken) {
|
|
2553
|
+
const backgroundHex = paletteHex(input, backgroundToken);
|
|
2554
|
+
if (!backgroundHex.ok) return backgroundHex;
|
|
2555
|
+
const ink = resolveSolidInk(input, backgroundToken, backgroundHex.hex);
|
|
2556
|
+
const boundary = input.surface ? validateButtonFillSeparation({
|
|
2557
|
+
...input,
|
|
2558
|
+
buttonPaint: backgroundHex.hex,
|
|
2559
|
+
surface: input.surface,
|
|
2560
|
+
labelInk: ink.foregroundHex
|
|
2561
|
+
}) : { ok: true };
|
|
2562
|
+
if (!boundary.ok) return boundary;
|
|
2563
|
+
return {
|
|
2564
|
+
ok: true,
|
|
2565
|
+
colour: ink.colour
|
|
2566
|
+
};
|
|
2567
|
+
}
|
|
2568
|
+
/** Preserve checked on-colours; a solid state's last resort belongs to its actual fill. */
|
|
2569
|
+
function resolveSolidInk(input, backgroundToken, backgroundHex) {
|
|
2570
|
+
const foregroundToken = unsafeAsOpaqueButtonColourToken(solidForegroundToken(backgroundToken));
|
|
2571
|
+
const candidate = input.palette[foregroundToken];
|
|
2572
|
+
if ((typeof candidate === "string" ? validateButtonTextContrast({
|
|
2573
|
+
...input,
|
|
2574
|
+
background: backgroundToken,
|
|
2575
|
+
backgroundHex,
|
|
2576
|
+
foreground: foregroundToken,
|
|
2577
|
+
foregroundHex: candidate
|
|
2578
|
+
}) : null)?.ok === true && typeof candidate === "string") return {
|
|
2579
|
+
foregroundHex: candidate,
|
|
2580
|
+
colour: {
|
|
2581
|
+
kind: "solid",
|
|
2582
|
+
backgroundToken,
|
|
2583
|
+
foregroundToken,
|
|
2584
|
+
backgroundCss: tokenCss(backgroundToken),
|
|
2585
|
+
foregroundCss: tokenCss(foregroundToken)
|
|
2586
|
+
}
|
|
2587
|
+
};
|
|
2588
|
+
const foregroundHex = pickBlackOrWhiteTextColor(backgroundHex);
|
|
2589
|
+
return {
|
|
2590
|
+
foregroundHex,
|
|
2591
|
+
colour: {
|
|
2592
|
+
kind: "known-solid",
|
|
2593
|
+
backgroundCss: tokenCss(backgroundToken),
|
|
2594
|
+
foregroundCss: foregroundHex
|
|
2595
|
+
}
|
|
2596
|
+
};
|
|
2597
|
+
}
|
|
2598
|
+
function resolveGradient(input, treatment) {
|
|
2599
|
+
const foregroundHex = paletteHex(input, treatment.foregroundToken);
|
|
2600
|
+
if (!foregroundHex.ok) return foregroundHex;
|
|
2601
|
+
const stopHexes = [];
|
|
2602
|
+
for (const token of treatment.stops) {
|
|
2603
|
+
const stop = paletteHex(input, token);
|
|
2604
|
+
if (!stop.ok) return stop;
|
|
2605
|
+
stopHexes.push(stop.hex);
|
|
2606
|
+
}
|
|
2607
|
+
for (let segment = 0; segment < stopHexes.length - 1; segment += 1) {
|
|
2608
|
+
const start = stopHexes[segment];
|
|
2609
|
+
const end = stopHexes[segment + 1];
|
|
2610
|
+
const startToken = treatment.stops[segment];
|
|
2611
|
+
const endToken = treatment.stops[segment + 1];
|
|
2612
|
+
if (start === void 0 || end === void 0 || startToken === void 0 || endToken === void 0) continue;
|
|
2613
|
+
for (let sample = 0; sample <= BUTTON_CONTRAST_POLICY.gradientSamplesPerSegment; sample += 1) {
|
|
2614
|
+
const position = sample / BUTTON_CONTRAST_POLICY.gradientSamplesPerSegment;
|
|
2615
|
+
const sampleHex = interpolateHex(start, end, position);
|
|
2616
|
+
const contrast = validateButtonTextContrast({
|
|
2617
|
+
...input,
|
|
2618
|
+
background: `${startToken}→${endToken}@${position.toFixed(2)}`,
|
|
2619
|
+
backgroundHex: sampleHex,
|
|
2620
|
+
foreground: treatment.foregroundToken,
|
|
2621
|
+
foregroundHex: foregroundHex.hex
|
|
2622
|
+
});
|
|
2623
|
+
if (!contrast.ok) return contrast;
|
|
2624
|
+
if (input.surface) {
|
|
2625
|
+
const boundary = validateButtonFillSeparation({
|
|
2626
|
+
...input,
|
|
2627
|
+
buttonPaint: sampleHex,
|
|
2628
|
+
labelInk: foregroundHex.hex,
|
|
2629
|
+
surface: input.surface
|
|
2630
|
+
});
|
|
2631
|
+
if (!boundary.ok) return boundary;
|
|
2632
|
+
}
|
|
2633
|
+
}
|
|
2634
|
+
}
|
|
2635
|
+
const direction = GRADIENT_DIRECTION_MAP[treatment.direction] ?? "to right";
|
|
2636
|
+
return {
|
|
2637
|
+
ok: true,
|
|
2638
|
+
colour: {
|
|
2639
|
+
kind: "gradient",
|
|
2640
|
+
backgroundTokens: treatment.stops,
|
|
2641
|
+
foregroundToken: treatment.foregroundToken,
|
|
2642
|
+
backgroundCss: `linear-gradient(${direction}, ${treatment.stops.map(tokenCss).join(", ")})`,
|
|
2643
|
+
foregroundCss: tokenCss(treatment.foregroundToken)
|
|
2644
|
+
}
|
|
2645
|
+
};
|
|
2646
|
+
}
|
|
2647
|
+
function paletteHex(input, token) {
|
|
2648
|
+
const hex = input.palette[token];
|
|
2649
|
+
return typeof hex === "string" ? {
|
|
2650
|
+
ok: true,
|
|
2651
|
+
hex
|
|
2652
|
+
} : {
|
|
2653
|
+
ok: false,
|
|
2654
|
+
error: {
|
|
2655
|
+
tag: "unknown_palette_token",
|
|
2656
|
+
variantId: input.variantId,
|
|
2657
|
+
state: input.state,
|
|
2658
|
+
token
|
|
2659
|
+
}
|
|
2660
|
+
};
|
|
2661
|
+
}
|
|
2662
|
+
function tokenCss(token) {
|
|
2663
|
+
return `rgb(var(--tb-${token}))`;
|
|
2664
|
+
}
|
|
2665
|
+
function interpolateHex(startHex, endHex, position) {
|
|
2666
|
+
const start = hexToRgb(startHex);
|
|
2667
|
+
const end = hexToRgb(endHex);
|
|
2668
|
+
const channel = (from, to) => Math.round(from + (to - from) * position).toString(16).padStart(2, "0");
|
|
2669
|
+
return `#${channel(start.r, end.r)}${channel(start.g, end.g)}${channel(start.b, end.b)}`;
|
|
2670
|
+
}
|
|
2671
|
+
//#endregion
|
|
2672
|
+
export { preparePaletteColourIndex as $, unsafeAsOpaqueButtonColourToken as A, parseThemeColorToken as At, hexColorSchema as B, buttonSizeNameSchema as C, borderColorStyle as Ct, createStandardButtonSurfacePolicy as D, textColorStyle as Dt, buttonVisualStatesSchema as E, rgbColorValue as Et, expandPalette as F, paletteModeSchema as G, paletteColorEntries as H, isOnColorBackgroundCandidateToken as I, requirePaletteColorsFromEntries as J, paletteValueKey as K, onColorTokenName as L, oklabDistance as M, parseBlockColorToken as Mt, deriveSurfaceDecorationColors as N, parseColorTokenParts as Nt, isVariantRole as O, textColorValue as Ot, deriveSurfaceMutedColor as P, maxContrastBlackOrWhite as Q, getTextColorForBackground as R, buttonPressOffsetSchema as S, backgroundColorStyle as St, buttonVariantIdSchema as T, mergeStyles as Tt, paletteColorsFromEntries as U, normalizePaletteHex as V, paletteColorsSchema as W, assertContrastRatio as X, ORDINARY_TEXT_MIN_CONTRAST_RATIO as Y, contrastRatio as Z, DEFAULT_VARIANT_ALIAS_ID as _, surfaceForegroundStyle as _t, isCssColorLiteral as a, oklabToOklch as at, asSpecialVariantId as b, surfaceInkDeclarations as bt, resolveThemeColorReferenceValue as c, oklchToOklab as ct, BORDER_RADIUS_MAP as d, DEFAULT_SURFACE_TEXT_COLOR as dt, relativeLuminance as et, BORDER_WIDTH_MAP as f, SURFACE_FOREGROUND_CSS_VARS as ft, generateShadowValue as g, surfaceForegroundInputFromResolved as gt, FONT_SIZE_MAP as h, surfaceForegroundDeclarations as ht, formatButtonColourContractError as i, hexToRgb as it, colourFamily as j, themeColorTokenSchema as jt, opaqueButtonColourTokenSchema as k, isThemeColorToken as kt, resolveTokenOrCssColorValue as l, rgbToHex as lt, ELEVATION_OFFSET as m, completeSurfaceForegrounds as mt, BUTTON_CONTRAST_POLICY as n, worstContrast as nt, parseThemeColorReference as o, oklabToSrgb as ot, DEFAULT_BUTTON_SIZES as p, SURFACE_INK_CSS_VARS as pt, paletteValueKeySchema as q, BUTTON_VISUAL_STATES as r, featuresFromHex as rt, resolveOnColorForThemeToken as s, oklchToHexGamut as st, compileButtonColourStates as t, solidPaint as tt, tokenOrCssColorValueSchema as u, srgbToOklab as ut, STANDARD_BUTTON_SURFACE_POLICY as v, surfaceForegroundValue as vt, buttonSystemSchema as w, cssVarValue as wt, buttonEffectApplicationSchema as x, surfaceInkStyle as xt, VARIANT_ROLES as y, surfaceForegroundValueWithOpacity as yt, pickBlackOrWhiteTextColor as z };
|