@delopay/sdk 0.475.0 → 0.477.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/airwallexCard.cjs.map +1 -1
- package/dist/branding.cjs.map +1 -1
- package/dist/cardFormStyles.cjs.map +1 -1
- package/dist/checkoutSession.cjs +2 -2
- package/dist/checkoutSession.cjs.map +1 -1
- package/dist/checkoutSession.js +1 -1
- package/dist/chunk-244VZFFO.cjs.map +1 -1
- package/dist/chunk-2IJRBJXW.cjs.map +1 -1
- package/dist/chunk-34PC72O7.cjs.map +1 -1
- package/dist/chunk-3GBWQWTP.cjs.map +1 -1
- package/dist/chunk-3YBBJT3Y.cjs.map +1 -1
- package/dist/chunk-44QBWVRS.cjs.map +1 -1
- package/dist/chunk-4EKAWNYI.cjs.map +1 -1
- package/dist/chunk-4LN4BR2T.cjs.map +1 -1
- package/dist/chunk-4T4XHPYN.cjs.map +1 -1
- package/dist/chunk-5CITBN33.cjs.map +1 -1
- package/dist/chunk-5HCKC4HF.cjs.map +1 -1
- package/dist/chunk-5O2JSQYA.cjs.map +1 -1
- package/dist/chunk-5QS67SBO.cjs.map +1 -1
- package/dist/chunk-6EBY2KKL.cjs.map +1 -1
- package/dist/chunk-6LFOM6HV.cjs.map +1 -1
- package/dist/chunk-6LOWE2YI.cjs.map +1 -1
- package/dist/chunk-6LSG5Z4T.cjs.map +1 -1
- package/dist/chunk-6SU2MTN2.cjs.map +1 -1
- package/dist/chunk-6YCDLSIU.cjs.map +1 -1
- package/dist/chunk-75E5WNJG.cjs.map +1 -1
- package/dist/chunk-7JV6VVO7.cjs.map +1 -1
- package/dist/chunk-7QZCUXWB.cjs.map +1 -1
- package/dist/chunk-7VXF5D67.cjs.map +1 -1
- package/dist/chunk-7WAQX26D.cjs.map +1 -1
- package/dist/chunk-ABWAYMN5.cjs.map +1 -1
- package/dist/chunk-ACZ2R47X.cjs.map +1 -1
- package/dist/chunk-AYUYJO3I.cjs.map +1 -1
- package/dist/chunk-BCA3TCGS.cjs.map +1 -1
- package/dist/chunk-BP6KDQ6I.cjs.map +1 -1
- package/dist/chunk-BRY3W7N3.cjs.map +1 -1
- package/dist/chunk-CAMALM35.cjs.map +1 -1
- package/dist/chunk-CCN44NZJ.cjs.map +1 -1
- package/dist/chunk-CR3JBTP3.cjs.map +1 -1
- package/dist/chunk-CYDHHARQ.cjs.map +1 -1
- package/dist/chunk-DJASVBOJ.cjs.map +1 -1
- package/dist/{chunk-Q6XF7JSF.js → chunk-DM75PLU4.js} +5 -2
- package/dist/{chunk-Q6XF7JSF.js.map → chunk-DM75PLU4.js.map} +1 -1
- package/dist/chunk-EEB2HDYL.cjs.map +1 -1
- package/dist/chunk-ENPSUWTS.cjs.map +1 -1
- package/dist/chunk-EQ6P6ZND.cjs.map +1 -1
- package/dist/{chunk-ZZ2JZOQF.cjs → chunk-EUR6PY6P.cjs} +3 -3
- package/dist/chunk-EUR6PY6P.cjs.map +1 -0
- package/dist/{chunk-AUQHR6FY.js → chunk-EWFORYPH.js} +2 -2
- package/dist/chunk-EXPWQBI3.cjs.map +1 -1
- package/dist/chunk-F3I5DOWV.cjs.map +1 -1
- package/dist/chunk-F46K5H3U.cjs.map +1 -1
- package/dist/chunk-F6S3WCCB.cjs.map +1 -1
- package/dist/chunk-FQRC4NJG.cjs.map +1 -1
- package/dist/chunk-FYISDU2Y.cjs.map +1 -1
- package/dist/chunk-GG52SAHA.cjs.map +1 -1
- package/dist/chunk-GK5FWN4H.cjs.map +1 -1
- package/dist/chunk-GSQN5EOO.cjs.map +1 -1
- package/dist/chunk-GW7IHYXR.cjs.map +1 -1
- package/dist/chunk-GWSVQXEY.cjs.map +1 -1
- package/dist/chunk-HLHML5ES.cjs.map +1 -1
- package/dist/chunk-HLKFUOAQ.cjs.map +1 -1
- package/dist/chunk-HLYGHP6F.cjs.map +1 -1
- package/dist/chunk-HSJABE7X.cjs.map +1 -1
- package/dist/chunk-I2W7AO4B.cjs.map +1 -1
- package/dist/chunk-I2XGNALG.cjs.map +1 -1
- package/dist/{chunk-NAHX6XYV.cjs → chunk-IGHAJNC6.cjs} +5 -2
- package/dist/chunk-IGHAJNC6.cjs.map +1 -0
- package/dist/chunk-IKXGA2Z5.cjs.map +1 -1
- package/dist/chunk-IR2LFKKA.cjs.map +1 -1
- package/dist/chunk-J4ZB7MU4.cjs.map +1 -1
- package/dist/chunk-JPPRDMTJ.cjs.map +1 -1
- package/dist/chunk-K5Q2H3VD.cjs.map +1 -1
- package/dist/chunk-KD5Y2YWK.cjs.map +1 -1
- package/dist/chunk-KJDMNF2T.cjs.map +1 -1
- package/dist/chunk-KLONGJCL.cjs.map +1 -1
- package/dist/chunk-KOB6MOAV.cjs.map +1 -1
- package/dist/chunk-KSJ7JLR3.cjs.map +1 -1
- package/dist/chunk-LJ2EG6JK.cjs.map +1 -1
- package/dist/{chunk-TENIWK2K.js → chunk-LJNZEDLG.js} +2 -2
- package/dist/chunk-LLYY4TCZ.cjs.map +1 -1
- package/dist/chunk-LYIBTVK6.cjs.map +1 -1
- package/dist/chunk-M3HWE7KT.cjs.map +1 -1
- package/dist/chunk-M3SJHFT4.cjs.map +1 -1
- package/dist/chunk-MCNDMK7F.cjs.map +1 -1
- package/dist/chunk-MLG6NXI6.cjs.map +1 -1
- package/dist/chunk-NFB3S2E6.cjs.map +1 -1
- package/dist/chunk-NYL3BNHR.cjs.map +1 -1
- package/dist/chunk-O4AYHLQX.cjs.map +1 -1
- package/dist/chunk-OAEKP665.cjs.map +1 -1
- package/dist/chunk-ODPNVNYE.cjs.map +1 -1
- package/dist/chunk-OG2KJAYD.cjs.map +1 -1
- package/dist/chunk-OMQJTXFL.cjs.map +1 -1
- package/dist/chunk-ORCK5GQ3.cjs.map +1 -1
- package/dist/chunk-OWP7XBY2.cjs.map +1 -1
- package/dist/chunk-OYZP6NF6.cjs.map +1 -1
- package/dist/chunk-P4UILJVU.cjs.map +1 -1
- package/dist/chunk-P6JLNQ6L.cjs.map +1 -1
- package/dist/chunk-P7DYLUUI.cjs.map +1 -1
- package/dist/chunk-PKAE6AQT.cjs.map +1 -1
- package/dist/chunk-Q7M7DO7M.cjs.map +1 -1
- package/dist/chunk-QKUWFMZP.cjs.map +1 -1
- package/dist/chunk-QRSA72B3.cjs.map +1 -1
- package/dist/chunk-QYNRNDIY.cjs.map +1 -1
- package/dist/chunk-R4GA6BVP.cjs.map +1 -1
- package/dist/chunk-R5VYSZ3Q.cjs.map +1 -1
- package/dist/chunk-RHFUXHQN.cjs.map +1 -1
- package/dist/chunk-RI42IDRR.cjs.map +1 -1
- package/dist/chunk-RSVLVW4L.cjs.map +1 -1
- package/dist/chunk-S77LQWYC.cjs.map +1 -1
- package/dist/chunk-S7SBNOGS.cjs.map +1 -1
- package/dist/chunk-TMAJE5P2.cjs.map +1 -1
- package/dist/chunk-TNIJ6OSH.cjs.map +1 -1
- package/dist/{chunk-I7SIQMGY.cjs → chunk-TNKDP6UJ.cjs} +3 -3
- package/dist/chunk-TNKDP6UJ.cjs.map +1 -0
- package/dist/chunk-U3JK7NBG.cjs.map +1 -1
- package/dist/chunk-UGSM7RJ2.cjs.map +1 -1
- package/dist/chunk-UKLZAOLW.cjs.map +1 -1
- package/dist/chunk-V47G7P6L.cjs.map +1 -1
- package/dist/chunk-VH5A6SMU.cjs.map +1 -1
- package/dist/chunk-VHMH4QMY.cjs.map +1 -1
- package/dist/chunk-VYC7WUM5.cjs.map +1 -1
- package/dist/chunk-VZ3BSIVU.cjs.map +1 -1
- package/dist/chunk-W457XUA6.cjs.map +1 -1
- package/dist/chunk-WHDI3TMP.cjs.map +1 -1
- package/dist/chunk-WITCPKNL.cjs.map +1 -1
- package/dist/chunk-WX6NP7UU.cjs.map +1 -1
- package/dist/chunk-XQLRIBVR.cjs.map +1 -1
- package/dist/chunk-Y7LSSRNJ.cjs.map +1 -1
- package/dist/chunk-YK3P5QNZ.cjs.map +1 -1
- package/dist/chunk-ZKPVUCQV.cjs.map +1 -1
- package/dist/chunk-ZUULK36E.cjs.map +1 -1
- package/dist/client.cjs +2 -2
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +1 -1
- package/dist/core.cjs.map +1 -1
- package/dist/currencies.cjs.map +1 -1
- package/dist/enigmaCardForm.cjs.map +1 -1
- package/dist/error.cjs.map +1 -1
- package/dist/eventStream.cjs.map +1 -1
- package/dist/exportDownload.cjs.map +1 -1
- package/dist/feeProgram.cjs.map +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -3
- package/dist/internal/resources/admin.cjs.map +1 -1
- package/dist/internal/resources/admin.d.cts +1 -1
- package/dist/internal/resources/admin.d.ts +1 -1
- package/dist/internal/resources/adminBranding.cjs.map +1 -1
- package/dist/internal/resources/adminBranding.d.cts +1 -1
- package/dist/internal/resources/adminBranding.d.ts +1 -1
- package/dist/internal/resources/adminCheckoutDomains.cjs.map +1 -1
- package/dist/internal/resources/adminCheckoutDomains.d.cts +1 -1
- package/dist/internal/resources/adminCheckoutDomains.d.ts +1 -1
- package/dist/internal/resources/adminFeePlans.cjs.map +1 -1
- package/dist/internal/resources/adminFeePlans.d.cts +1 -1
- package/dist/internal/resources/adminFeePlans.d.ts +1 -1
- package/dist/internal/resources/adminFileScans.cjs.map +1 -1
- package/dist/internal/resources/adminFileScans.d.cts +1 -1
- package/dist/internal/resources/adminFileScans.d.ts +1 -1
- package/dist/internal/resources/adminIndustries.cjs.map +1 -1
- package/dist/internal/resources/adminIndustries.d.cts +1 -1
- package/dist/internal/resources/adminIndustries.d.ts +1 -1
- package/dist/internal/resources/adminLive.cjs.map +1 -1
- package/dist/internal/resources/adminNotices.cjs.map +1 -1
- package/dist/internal/resources/adminNotices.d.cts +1 -1
- package/dist/internal/resources/adminNotices.d.ts +1 -1
- package/dist/internal/resources/adminPortal.cjs.map +1 -1
- package/dist/internal/resources/adminPortal.d.cts +1 -1
- package/dist/internal/resources/adminPortal.d.ts +1 -1
- package/dist/internal/resources/adminSupport.cjs.map +1 -1
- package/dist/internal/resources/adminSupport.d.cts +1 -1
- package/dist/internal/resources/adminSupport.d.ts +1 -1
- package/dist/internal/resources/auditLogs.cjs.map +1 -1
- package/dist/internal/resources/auditLogs.d.cts +1 -1
- package/dist/internal/resources/auditLogs.d.ts +1 -1
- package/dist/internal/resources/cache.cjs.map +1 -1
- package/dist/internal/resources/cardIssuers.cjs.map +1 -1
- package/dist/internal/resources/cardIssuers.d.cts +1 -1
- package/dist/internal/resources/cardIssuers.d.ts +1 -1
- package/dist/internal/resources/configs.cjs.map +1 -1
- package/dist/internal/resources/connectorRestrictionRules.cjs.map +1 -1
- package/dist/internal/resources/connectorRestrictionRules.d.cts +1 -1
- package/dist/internal/resources/connectorRestrictionRules.d.ts +1 -1
- package/dist/internal/resources/connectorRestrictions.cjs.map +1 -1
- package/dist/internal/resources/connectorRestrictions.d.cts +1 -1
- package/dist/internal/resources/connectorRestrictions.d.ts +1 -1
- package/dist/internal/resources/diagnostic.cjs.map +1 -1
- package/dist/internal/resources/diagnostic.d.cts +1 -1
- package/dist/internal/resources/diagnostic.d.ts +1 -1
- package/dist/internal/resources/gsm.cjs.map +1 -1
- package/dist/internal/resources/gsm.d.cts +1 -1
- package/dist/internal/resources/gsm.d.ts +1 -1
- package/dist/internal/resources/nativeRenewals.cjs.map +1 -1
- package/dist/internal/resources/nativeRenewals.d.cts +1 -1
- package/dist/internal/resources/nativeRenewals.d.ts +1 -1
- package/dist/internal/resources/platformBilling.cjs.map +1 -1
- package/dist/internal/resources/platformBilling.d.cts +1 -1
- package/dist/internal/resources/platformBilling.d.ts +1 -1
- package/dist/internal/resources/platformFees.cjs.map +1 -1
- package/dist/internal/resources/platformMessageTemplates.cjs.map +1 -1
- package/dist/internal/resources/platformSettings.cjs.map +1 -1
- package/dist/internal/resources/platformSettings.d.cts +1 -1
- package/dist/internal/resources/platformSettings.d.ts +1 -1
- package/dist/internal.cjs +5 -5
- package/dist/internal.cjs.map +1 -1
- package/dist/internal.d.cts +1 -1
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +3 -3
- package/dist/listQuery.cjs.map +1 -1
- package/dist/panes.cjs.map +1 -1
- package/dist/paymentPresentation.cjs.map +1 -1
- package/dist/recordCounter.cjs.map +1 -1
- package/dist/resources/aiTools.cjs.map +1 -1
- package/dist/resources/analytics.cjs.map +1 -1
- package/dist/resources/analyticsDashboard.cjs.map +1 -1
- package/dist/resources/apiKeys.cjs.map +1 -1
- package/dist/resources/audit.cjs.map +1 -1
- package/dist/resources/authentication.cjs.map +1 -1
- package/dist/resources/availabilityOverrides.cjs.map +1 -1
- package/dist/resources/billing.cjs.map +1 -1
- package/dist/resources/buyerAccount.cjs.map +1 -1
- package/dist/resources/buyerBlocklist.cjs.map +1 -1
- package/dist/resources/buyerConversations.cjs.map +1 -1
- package/dist/resources/buyerEvidenceReviews.cjs.map +1 -1
- package/dist/resources/buyerPortal.cjs.map +1 -1
- package/dist/resources/cards.cjs.map +1 -1
- package/dist/resources/chargebackPrevention.cjs.map +1 -1
- package/dist/resources/checkoutDomains.cjs.map +1 -1
- package/dist/resources/checkoutMethods.cjs.map +1 -1
- package/dist/resources/checkoutRecovery.cjs.map +1 -1
- package/dist/resources/checkoutTemplates.cjs.map +1 -1
- package/dist/resources/connectors.cjs.map +1 -1
- package/dist/resources/contentEncryption.cjs.map +1 -1
- package/dist/resources/costRules.cjs.map +1 -1
- package/dist/resources/customers.cjs.map +1 -1
- package/dist/resources/deploymentBranding.cjs.map +1 -1
- package/dist/resources/disputes.cjs.map +1 -1
- package/dist/resources/ephemeralKeys.cjs.map +1 -1
- package/dist/resources/events.cjs.map +1 -1
- package/dist/resources/export.cjs.map +1 -1
- package/dist/resources/externalRecords.cjs.map +1 -1
- package/dist/resources/featureMatrix.cjs.map +1 -1
- package/dist/resources/fees.cjs.map +1 -1
- package/dist/resources/files.cjs.map +1 -1
- package/dist/resources/forex.cjs.map +1 -1
- package/dist/resources/identityVerifications.cjs.map +1 -1
- package/dist/resources/industries.cjs.map +1 -1
- package/dist/resources/invoiceSettings.cjs.map +1 -1
- package/dist/resources/invoices.cjs.map +1 -1
- package/dist/resources/live.cjs.map +1 -1
- package/dist/resources/mandates.cjs.map +1 -1
- package/dist/resources/merchantAccounts.cjs.map +1 -1
- package/dist/resources/messageTemplates.cjs.map +1 -1
- package/dist/resources/notices.cjs.map +1 -1
- package/dist/resources/operationLimits.cjs.map +1 -1
- package/dist/resources/paymentLinks.cjs.map +1 -1
- package/dist/resources/paymentMethods.cjs.map +1 -1
- package/dist/resources/payments.cjs.map +1 -1
- package/dist/resources/payoutDestinations.cjs.map +1 -1
- package/dist/resources/payouts.cjs.map +1 -1
- package/dist/resources/paypalDisputes.cjs.map +1 -1
- package/dist/resources/persons.cjs.map +1 -1
- package/dist/resources/poll.cjs.map +1 -1
- package/dist/resources/processorCosts.cjs.map +1 -1
- package/dist/resources/processorImports.cjs.map +1 -1
- package/dist/resources/products.cjs.map +1 -1
- package/dist/resources/profileAcquirers.cjs.map +1 -1
- package/dist/resources/profiles.cjs.map +1 -1
- package/dist/resources/projects.cjs.map +1 -1
- package/dist/resources/refunds.cjs.map +1 -1
- package/dist/resources/regions.cjs.map +1 -1
- package/dist/resources/relay.cjs.map +1 -1
- package/dist/resources/risk.cjs.map +1 -1
- package/dist/resources/routing.cjs.map +1 -1
- package/dist/resources/search.cjs.map +1 -1
- package/dist/resources/sellToRestrictions.cjs.map +1 -1
- package/dist/resources/settings.cjs.map +1 -1
- package/dist/resources/settlement.cjs.map +1 -1
- package/dist/resources/shopLabels.cjs.map +1 -1
- package/dist/resources/shopify.cjs +2 -2
- package/dist/resources/shopify.cjs.map +1 -1
- package/dist/resources/shopify.d.cts +4 -1
- package/dist/resources/shopify.d.ts +4 -1
- package/dist/resources/shopify.js +1 -1
- package/dist/resources/shops.cjs.map +1 -1
- package/dist/resources/stripeConnect.cjs.map +1 -1
- package/dist/resources/subscriptions.cjs.map +1 -1
- package/dist/resources/support.cjs.map +1 -1
- package/dist/resources/threeDsRules.cjs.map +1 -1
- package/dist/resources/users.cjs.map +1 -1
- package/dist/resources/vatRates.cjs.map +1 -1
- package/dist/resources/verification.cjs.map +1 -1
- package/dist/resources/webhooks.cjs.map +1 -1
- package/dist/resources/whopResolutionCases.cjs.map +1 -1
- package/dist/trustedOrigins.cjs.map +1 -1
- package/dist/{types-BD4UoPj8.d.cts → types-B3aryu0m.d.cts} +8 -0
- package/dist/{types-CX-yJoOh.d.ts → types-oEDLbeac.d.ts} +8 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +27 -1
- package/dist/types.d.ts +27 -1
- package/package.json +1 -1
- package/dist/chunk-I7SIQMGY.cjs.map +0 -1
- package/dist/chunk-NAHX6XYV.cjs.map +0 -1
- package/dist/chunk-ZZ2JZOQF.cjs.map +0 -1
- /package/dist/{chunk-AUQHR6FY.js.map → chunk-EWFORYPH.js.map} +0 -0
- /package/dist/{chunk-TENIWK2K.js.map → chunk-LJNZEDLG.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/tmp/pub-sdk-0475-w5/dist/chunk-LYIBTVK6.cjs","../src/branding.ts"],"names":["s"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACkOO,SAAS,mBAAA,CACd,SAAA,EACA,KAAA,EACA,QAAA,EACS;AACT,EAAA,GAAA,CAAI,UAAA,IAAc,UAAA,EAAY,OAAO,KAAA;AACrC,EAAA,OAAO,CAAA,CAAE,MAAA,IAAU,SAAA,GAAA,CAAa,SAAA,IAAa,cAAA,GAAiB,SAAA,IAAa,WAAA,CAAA,CAAA;AAC7E;AAwCO,SAAS,mBAAA,CACd,QAAA,EAIA,UAA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EAAA;AACT;AAQM;AACA;AAGO;AACA;AAGA;AAeA;AACL,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACR;AAGa;AACX,EAAA;AACF;AAGa;AAQG;AACP,EAAA;AACT;AAEgB;AACR,EAAA;AACN,EAAA;AACO,EAAA;AACT;AAOgB;AACV,EAAA;AACA,EAAA;AACG,EAAA;AACT;AAQgB;AACR,EAAA;AACF,EAAA;AACA,EAAA;AACA,EAAA;AACF,IAAA;AACM,EAAA;AACN,IAAA;AACF,EAAA;AACI,EAAA;AACJ,EAAA;AACQ,IAAA;AACF,IAAA;AACE,IAAA;AACR,EAAA;AACO,EAAA;AACT;AAEgB;AACP,EAAA;AACT;AAMgB;AACV,EAAA;AACA,EAAA;AACA,EAAA;AACF,IAAA;AACM,EAAA;AACN,IAAA;AACF,EAAA;AACI,EAAA;AACE,EAAA;AACN,EAAA;AACO,IAAA;AACH,MAAA;AACF,IAAA;AACM,IAAA;AACN,IAAA;AACM,MAAA;AACJ,MAAA;AACI,MAAA;AACJ,MAAA;AACF,IAAA;AACI,IAAA;AACN,EAAA;AACO,EAAA;AACT;AAMgB;AACR,EAAA;AACN,EAAA;AACQ,IAAA;AACN,IAAA;AACE,MAAA;AACI,MAAA;AACN,IAAA;AACI,IAAA;AACN,EAAA;AACO,EAAA;AACT;AAES;AACD,EAAA;AACC,EAAA;AACT;AAEgB;AACP,EAAA;AACT;AAQgB;AACN,EAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACF,IAAA;AACE,IAAA;AACF,IAAA;AACJ,IAAA;AACF,EAAA;AACF;AAUgB;AAOR,EAAA;AAGF,EAAA;AACI,IAAA;AASA,IAAA;AACF,IAAA;AACJ,IAAA;AACE,MAAA;AACI,MAAA;AACN,IAAA;AACF,EAAA;AACI,EAAA;AACI,IAAA;AACF,IAAA;AACN,EAAA;AACO,EAAA;AAC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vB,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAEA,EAAA;AAAW;AAER,EAAA;AACL;AAEa;AACR,EAAA;AACA,EAAA;AAAA;AAAA;AAAA;AAIH,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACF;AAYa;AACR,EAAA;AACH,EAAA;AACA,EAAA;AACA,EAAA;AACM,EAAA;AACN,EAAA;AACO,EAAA;AACC,EAAA;AACR,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAAc;AAAA;AAAA;AAId,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACF;AAGgB;AACP,EAAA;AACT;AAMgB;AACP,EAAA;AACF,IAAA;AACH,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACF,IAAA;AAAA;AAAA;AAAA;AAIA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACF,EAAA;AACF;AAEgB;AACP,EAAA;AACF,IAAA;AACH,IA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gB;AACV,EAAA;AACA,EAAA;AACA,EAAA;AACF,IAAA;AACM,EAAA;AACN,IAAA;AACF,EAAA;AACO,EAAA;AACT;AAGgB;AACV,EAAA;AACG,EAAA;AACT;AAOgB;AACP,EAAA;AACL,IAAA;AACE,MAAA;AACI,QAAA;AACJ,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACD,IAAA;AACH,EAAA;AACF;AAYgB;AACP,EAAA;AACT;AAOgB;AAIP,EAAA;AACT;AAiBgB;AAKP,EAAA;AAGT;AAIa;AAIA;AAEA;AACX,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACF;AAIa;AACA;AAKG;AACP,EAAA;AACT;AAIgB;AACP,EAAA;AACT;AAIa;AAEA;AACX,EAAA;AACA,EAAA;AACA,EAAA;AACF;AAEa;AACX,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACF;AAKa;AAIX,EAAA;AACA,EAAA;AACQ,EAAA;AACV;AAIa;AACX,EAAA;AACA,EAAA;AACF;AAEgB;AACN,EAAA;AACV;AAIgB;AACP,EAAA;AACT;AAEgB;AACP,EAAA;AACT;AAES;AAIH,EAAA;AACA,EAAA;AACE,IAAA;AACF,MAAA;AACF,IAAA;AACE,MAAA;AACF,IAAA;AACF,EAAA;AACK,EAAA;AACC,EAAA;AACN,EAAA;AAKM,IAAA;AACN,EAAA;AACO,EAAA;AACT;AAUS;AACD,EAAA;AACC,EAAA;AACT;AAMS;AACF,EAAA;AACC,EAAA;AACA,EAAA;AACF,IAAA;AACF,IAAA;AACA,IAAA;AACF,EAAA;AACM,EAAA;AACA,EAAA;AACF,IAAA;AACF,IAAA;AACA,IAAA;AACF,EAAA;AACM,EAAA;AACC,EAAA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A;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AAEA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AAA8C;AAAA;AAAA;AAAA;AAAA;AAO9C,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AAEA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AAAsF;AAAA;AAGtF,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AAEA,IAAA;AAEG,IAAA;AACL,EAAA;AACF;AAiCgB;AAIR,EAAA;AACE,IAAA;AACN,IAAA;AACF,EAAA;AAIM,EAAA;AAGA,EAAA;AACJ,IAAA;AACM,IAAA;AACN,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAqB;AAAA;AAAA;AAAA;AAAA;AAMrB,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAqC;AAAA;AAGrC,IAAA;AACC,IAAA;AACH,EAAA;AAOI,EAAA;AACF,IAAA;AACF,EAAA;AAEM,EAAA;AACF,EAAA;AAIA,EAAA;AACF,IAAA;AACF,EAA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A;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AAAA;AAAA;AAGA,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AAAkE;AAAA;AAAA;AAAA;AAAA;AAOlE,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AAAwE;AAAA;AAGxE,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AAEA,IAAA;AACG,IAAA;AACL,EAAA;AACF;AAES;AACA,EAAA;AACT;AAOS;AACF,EAAA;AACE,EAAA;AAGC,IAAA;AACJ,IAAA;AACA,IAAA;AAIA,IAAA;AAIA,IAAA;AAKD,EAAA;AACL;AAWgB;AACR,EAAA;AACD,IAAA;AACL,EAAA;AAEI,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAEA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAEA,EAAA;AACA,EAAA;AAEA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAKA,EAAA;AACA,EAAA;AAIA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AACA,EAAA;AAGJ,EAAA;AACE,IAAA;AACA,IAAA;AAKF,EAAA;AACI,EAAA;AAEA,EAAA;AACJ,EAAA;AACE,IAAA;AACE,IAAA;AACJ,EAAA;AACF;AAEgB;AACN,EAAA;AACD,IAAA;AACH,MAAA;AACG,IAAA;AACA,IAAA;AACL,IAAA;AACE,MAAA;AACJ,EAAA;AACF;ADjzDU;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/tmp/pub-sdk-0475-w5/dist/chunk-LYIBTVK6.cjs","sourcesContent":[null,"// Checkout branding — typed shape, design tokens, palettes, persistence\n// codec, CSS sanitizer, and DOM helpers for `--dp-*` CSS variables.\n//\n// Both the hosted checkout and the dashboard's branding form consume this\n// module.\n//\n// Persistence: top-level fields own the \"loud\" tokens (logo, theme,\n// payment_button_*, background_colour, etc.). Everything else lives in\n// `sdk_ui_rules.branding` as a nested string-keyed map — booleans and\n// numbers round-trip as strings, the trust-badge list is JSON-stringified.\n\nimport {\n AIRWALLEX_AUTOFILL_TREATMENTS,\n AIRWALLEX_CARD_PRESETS,\n AIRWALLEX_FIELD_CHROMES,\n AIRWALLEX_FIELD_FONT_SIZES,\n AIRWALLEX_FIELD_WEIGHTS,\n AIRWALLEX_FOCUS_RINGS,\n AIRWALLEX_LABEL_STYLES,\n type AirwallexAutofillTreatment,\n type AirwallexCardPreset,\n type AirwallexFieldChrome,\n type AirwallexFieldFontSize,\n type AirwallexFieldWeight,\n type AirwallexFocusRing,\n type AirwallexLabelStyle,\n} from './airwallexCard';\nimport {\n APPLE_PAY_BUTTON_STYLES,\n APPLE_PAY_BUTTON_TYPES,\n CARD_FIELD_CHROMES,\n CARD_FIELD_FONT_SIZES,\n CARD_FIELD_WEIGHTS,\n CARD_FOCUS_RINGS,\n GOOGLE_PAY_BUTTON_COLORS,\n GOOGLE_PAY_BUTTON_TYPES,\n NOMUPAY_FORM_STYLES,\n PAYPAL_CARD_LAYOUTS,\n PAYPAL_LABEL_STYLES,\n STRIPE_INPUT_STYLES,\n STRIPE_LABEL_PLACEMENTS,\n STRIPE_SPACINGS,\n STRIPE_THEMES,\n WHOP_ACCENT_COLORS,\n WHOP_BILLING_DETAILS,\n WHOP_CARD_PRESETS,\n WHOP_EMAIL_LABELS,\n WHOP_GRAY_COLORS,\n WHOP_RADII,\n WHOP_SELECTIONS,\n WHOP_SHADOWS,\n type ApplePayButtonStyle,\n type ApplePayButtonType,\n type CardFieldChrome,\n type CardFieldFontSize,\n type CardFieldWeight,\n type CardFocusRing,\n type GooglePayButtonColor,\n type GooglePayButtonType,\n type NomupayFormStyle,\n type PaypalCardLayout,\n type PaypalLabelStyle,\n type StripeInputStyle,\n type StripeLabelPlacement,\n type StripeSpacing,\n type StripeTheme,\n type WhopAccentColor,\n type WhopBillingDetails,\n type WhopCardPreset,\n type WhopEmailLabel,\n type WhopRadius,\n type WhopSelection,\n type WhopShadow,\n type WhopGrayColor,\n} from './cardFormStyles';\nimport type { VaultFormAppearance } from './types';\nimport {\n decodeEnigmaCardForm,\n DEFAULT_ENIGMA_CARD_FORM,\n encodeEnigmaCardForm,\n enigmaNamesInside,\n type EnigmaCardFormSettings,\n} from './enigmaCardForm';\n\n// --- Types --------------------------------------------------------------\n\nexport type CornerRadius = 'square' | 'small' | 'medium' | 'large' | 'pill';\n\n// Surfaces and inputs never make sense pill-shaped (a pill input ends up with\n// half-circle ends crammed against text). The form picker only exposes these\n// four; if a stale 'pill' value lands here from older saved data, decode\n// drops it back to 'medium'. Buttons and badges still allow 'pill'.\nexport type NonPillRadius = Exclude<CornerRadius, 'pill'>;\n\n// Spacing scales — split apart so the merchant can independently tune\n// surface padding, vertical rhythm, input height and pay-button height. Used\n// to live as a single `density` enum but that conflated four dimensions.\nexport type SpacingScale = 'compact' | 'comfortable' | 'spacious';\nexport type SizeScale = 'sm' | 'md' | 'lg';\nexport type SurfaceStyle = 'flat' | 'outlined' | 'elevated';\n\nexport type FontFamily =\n | 'inter'\n | 'system'\n | 'serif'\n | 'mono'\n | 'roboto'\n | 'poppins'\n | 'manrope'\n | 'dm-sans'\n | 'space-grotesk'\n | 'plex-sans'\n | 'work-sans'\n | 'open-sans'\n | 'lora'\n | 'playfair'\n | 'plex-mono'\n | 'jetbrains-mono';\n\nexport type FontWeight = 'regular' | 'medium' | 'semibold' | 'bold';\nexport type LayoutStyle = 'compact' | 'split';\nexport type SummaryPosition = 'left' | 'right';\n\n// Stripe Elements only supports two label modes (\"above\" or hidden via the\n// .Label-collapse hack); a \"floating\" label is not a Stripe concept and\n// would only render in our own mock — preview was lying about it. Persisted\n// `'floating'` is silently decoded to `'above'` for back-compat.\nexport type LabelStyle = 'above' | 'hidden';\n\n// Stripe Elements layout. Honored inside the StripeCardPane only — other\n// connector panes stack vertically regardless of this setting.\nexport type PaymentLayout = 'tabs' | 'accordion' | 'spaced_accordion';\n\nexport type LogoShape = 'square' | 'rounded' | 'circle';\nexport type LogoSize = 'sm' | 'md' | 'lg';\n\n// --- Provider surcharge / discount disclosure ---------------------------\n//\n// With surcharges scoped to the provider rather than to the payment method,\n// two tiles on one checkout can cost the buyer different amounts — so the\n// figure has to be legible on the tile, before the choice, not only in the\n// breakdown after it. These control how that figure is painted; whether there\n// is one at all is the router's answer, per pane.\n//\n// Nothing here can invent a figure or change one. A merchant who would rather\n// not disclose per-tile turns it off with `showSurcharge` and keeps the\n// breakdown inside the pane, which is where the disclosure lived before.\n\n// Where the figure sits relative to the tile's label.\n//\n// `inline` follows the label text immediately, so the price reads as part of\n// the name — good for short labels.\n// `trailing` pushes it to the tile's trailing edge on the label's own line: the\n// price reads as a property of the tile, and the tile's height does not change,\n// which matters because most tiles carry no figure at all and a row that grows\n// only for some of them makes the list look ragged.\n// `below` puts it under the sublabel, for merchants whose labels are long\n// enough that a trailing figure would crowd them.\n// `above` puts it over the label as an eyebrow, which is the one position that\n// reads before the method name rather than after it.\nexport type SurchargePosition =\n | 'inline'\n | 'trailing'\n | 'below'\n | 'above'\n | 'cornerStart'\n | 'cornerEnd';\n\n// Where the rows drawn as the wallet's OWN button (Apple Pay / Google Pay with\n// `native_element` applying in this render) are placed.\n//\n// Not within their section — they leave it. Every such row is lifted out of the\n// catalogue into one express strip, and this says where on the payment surface\n// that strip goes:\n//\n// `top` above everything, the custom fields included;\n// `belowFields` under the merchant's custom fields, still above the card form\n// and every section;\n// `belowCard` directly under the card form, above the remaining sections\n// (with no card form in this render, it falls back to\n// `belowFields`);\n// `bottom` under the last section, the last thing offered.\n//\n// The rows keep their own relative order in the strip whichever end it sits at.\n// Decided from the pane's setting for the render context, not from a later\n// fallback to the tile, so a row never moves under the buyer.\nexport type NativeElementPosition = 'top' | 'belowFields' | 'belowCard' | 'bottom';\n\n// How the figure is painted.\n//\n// `plain` is text in the configured colour. `badge` fills the shape with a tint\n// of it. `outline` draws the border only — the middle weight, for a checkout\n// whose tiles are already busy. `solid` fills with the colour itself and writes\n// on it in whichever of black or white reads better, which is the loudest\n// option and the one to reach for when the figure must not be missed.\n// `underline` keeps the text weight of `plain` and adds a rule beneath it.\n// `ribbon` runs the figure diagonally across a corner of the tile — the one\n// treatment that reads before the label rather than beside it, for a merchant\n// steering hard toward a cheaper provider.\nexport type SurchargeStyle = 'plain' | 'badge' | 'outline' | 'solid' | 'underline' | 'ribbon';\n\n// The border drawn around the shapes `badge`, `outline`, `solid` and `ribbon`\n// paint. `outline` draws nothing BUT its border, so `none` there would erase\n// the style rather than restyle it and reads as `thin` instead.\nexport type SurchargeBorderWidth = 'none' | 'thin' | 'medium' | 'thick';\n\n// How that border is drawn. `dashed` and `dotted` read as provisional, which\n// suits a promotional discount; `solid` is the neutral default.\nexport type SurchargeBorderStyle = 'solid' | 'dashed' | 'dotted';\n\n// The figure's type size, relative to the tile's own text.\nexport type SurchargeSize = 'sm' | 'md' | 'lg';\n\n// The corner treatment of the shapes `badge`, `outline` and `solid` draw.\n// Ignored by `plain` and `underline`, which draw no shape.\nexport type SurchargeShape = 'pill' | 'rounded' | 'square';\n\n// How heavily the figure is set.\nexport type SurchargeWeight = 'regular' | 'medium' | 'bold';\n\n// Whether the figure carries an explicit sign.\n//\n// `always` writes `+` on a surcharge and `−` on a discount (U+2212, not a\n// hyphen, so it aligns with the digits). `minusOnly` writes the minus and\n// leaves a surcharge unsigned, which reads as a price rather than as an\n// adjustment. `none` writes neither and leans entirely on the two colours —\n// legible only when a merchant configures one direction, and offered because a\n// merchant who only ever discounts should not have to explain a plus sign.\nexport type SurchargeSign = 'always' | 'minusOnly' | 'none';\n\n// Whether the figure names itself.\n//\n// `amount` is the figure alone. `labelled` prefixes the localized word for the\n// direction (\"Surcharge\" / \"Discount\"), which costs horizontal room and buys a\n// tile nobody has to interpret.\nexport type SurchargeLabelMode = 'amount' | 'labelled';\n\n// WHICH figure the tile prints, and in which order when it prints both.\n//\n// A discount and a surcharge are the same mechanism pointed in opposite\n// directions, but they are not the same message: a saving is something a\n// merchant advertises and a percentage is the persuasive half of it (\"20%\n// off\"), while a fee is something a merchant discloses and the money is the\n// half the buyer actually cares about. So the two directions carry this\n// setting separately — `discountFigure` and `surchargeFigure` — rather than\n// sharing one.\n//\n// The two figures always describe the same money. The router derives the\n// percentage from the charge rather than from the merchant's rule, so a fixed\n// rule states its share of this cart and a taxed rate states the share the\n// buyer actually pays. That is what makes showing either — or both — safe.\nexport type SurchargeFigureMode = 'amount' | 'percent' | 'amountThenPercent' | 'percentThenAmount';\n\n/**\n * Whether the tile has room to print the wording alongside the figure.\n *\n * One pairing says no: the diagonal ribbon at either corner. That band is\n * clipped by the tile it crosses, and the readable length is set by how far the\n * corner is inset — roughly 75px on a standard payment tile, against roughly\n * 107px for a labelled figure at the default size. Printing the word there\n * clips the *figure*, and a half-shown price is worse than a plain one, so the\n * word is what gives way.\n *\n * Exported, and shared by the buyer-facing checkout and the dashboard's live\n * preview, because the two must reach the same answer. A preview that promises\n * a word the checkout will not print is the one failure a preview cannot have.\n */\nexport function surchargeShowsLabel(\n labelMode: SurchargeLabelMode,\n style: SurchargeStyle,\n position: SurchargePosition,\n): boolean {\n if (labelMode !== 'labelled') return false;\n return !(style === 'ribbon' && (position === 'cornerStart' || position === 'cornerEnd'));\n}\n\n/** One of the two things a tile can print. */\nexport type SurchargeFigurePart = 'amount' | 'percent';\n\n/** Exactly what one tile prints, in order. See {@link surchargeFigurePlan}. */\nexport interface SurchargeFigurePlan {\n /** The leading figure. Always present — a tile with nothing to say renders nothing at all. */\n first: SurchargeFigurePart;\n /** The trailing figure, parenthesised by the renderer, or `null` for one figure. */\n second: SurchargeFigurePart | null;\n /** Whether the localized direction word prefixes the whole thing. */\n label: boolean;\n}\n\n/**\n * What one tile prints: which figures, in which order, and whether the word\n * comes with them.\n *\n * One function rather than a rule per surface, because the buyer-facing tile\n * and the dashboard's live preview must reach the same answer. A preview that\n * shows a percentage the checkout will not print — or prints in the other\n * order — is the one failure a preview cannot have.\n *\n * Three things it decides, in order of how much they cost to get wrong:\n *\n * * **No percentage available, no percentage printed.** `percentAvailable` is\n * false when the router sent none, which happens on an order of zero. A\n * merchant who asked for `percent` gets the amount instead — never a blank\n * tile, and never `0%`. This is the fallback the whole design leans on: the\n * amount is exact in every case, so it is what every degradation lands on.\n * * **A corner ribbon prints one figure.** The band crossing a tile's corner\n * is clipped to roughly 75px of readable length; two figures and a word do\n * not fit, and clipping a *price* is worse than showing less of one. It\n * keeps the merchant's leading figure — their own statement of which half\n * matters — and drops the trailing one along with the word.\n * * **Direction picks the setting.** `discountFigure` for a credit,\n * `surchargeFigure` for a charge, because a saving and a fee are not the\n * same message even though they are the same mechanism.\n */\nexport function surchargeFigurePlan(\n branding: Pick<\n CheckoutBranding,\n 'surchargeFigure' | 'discountFigure' | 'surchargeLabel' | 'surchargeStyle' | 'surchargePosition'\n >,\n isDiscount: boolean,\n percentAvailable: boolean,\n): SurchargeFigurePlan {\n const mode = isDiscount ? branding.discountFigure : branding.surchargeFigure;\n const label = surchargeShowsLabel(\n branding.surchargeLabel,\n branding.surchargeStyle,\n branding.surchargePosition,\n );\n\n // Money only, whatever was asked for: there is no second figure to state.\n if (!percentAvailable) return { first: 'amount', second: null, label };\n\n const ordered: Record<SurchargeFigureMode, [SurchargeFigurePart, SurchargeFigurePart | null]> = {\n amount: ['amount', null],\n percent: ['percent', null],\n amountThenPercent: ['amount', 'percent'],\n percentThenAmount: ['percent', 'amount'],\n };\n const [first, second] = ordered[mode];\n\n // The corner ribbon keeps the merchant's leading figure and nothing else.\n // `surchargeShowsLabel` has already dropped the word for the same reason, so\n // this is the same rule applied to the second figure.\n const cornerRibbon =\n branding.surchargeStyle === 'ribbon' &&\n (branding.surchargePosition === 'cornerStart' || branding.surchargePosition === 'cornerEnd');\n\n return { first, second: cornerRibbon ? null : second, label };\n}\n\n/**\n * Black or white, whichever reads better on `color` — for the `solid` style,\n * which writes on the configured colour itself.\n *\n * Picked by contrast rather than by a luminance threshold so the answer is the\n * one WCAG would give, and falls back to white on an unparseable colour, which\n * is what the rest of this module does with a colour it cannot read.\n */\nexport function readableInkOn(color: string): string {\n const onBlack = contrastRatio(color, '#000000');\n const onWhite = contrastRatio(color, '#ffffff');\n if (onBlack === null || onWhite === null) return '#ffffff';\n return onBlack >= onWhite ? '#000000' : '#ffffff';\n}\n\n/** Type size per {@link SurchargeSize}, relative to the tile's own text. */\nconst SURCHARGE_FONT_SIZE: Record<SurchargeSize, string> = {\n sm: '0.6875rem',\n md: '0.8125rem',\n lg: '0.9375rem',\n};\n\n/** Shape padding per {@link SurchargeSize}. Grows with the type. */\nconst SURCHARGE_PAD: Record<SurchargeSize, string> = {\n sm: '1px 6px',\n md: '2px 8px',\n lg: '3px 10px',\n};\n\n/** Corner radius per {@link SurchargeShape}. */\nconst SURCHARGE_RADIUS: Record<SurchargeShape, string> = {\n pill: '999px',\n rounded: '6px',\n square: '0px',\n};\n\n/** Border thickness per {@link SurchargeBorderWidth}. */\nconst SURCHARGE_BORDER_WIDTH: Record<SurchargeBorderWidth, string> = {\n none: '0px',\n thin: '1px',\n medium: '2px',\n thick: '3px',\n};\n\n/** Font weight per {@link SurchargeWeight}. */\nconst SURCHARGE_FONT_WEIGHT: Record<SurchargeWeight, string> = {\n regular: '400',\n medium: '600',\n bold: '700',\n};\n\n/**\n * The values each disclosure axis accepts, in the order a picker should offer\n * them: quietest first, so a merchant scrolling down is turning the figure up.\n *\n * Exported because both the dashboard's picker and this module's decoder need\n * the same list, and a picker offering a value the decoder rejects is a control\n * that silently does nothing.\n */\nexport const SURCHARGE_POSITIONS: readonly SurchargePosition[] = [\n 'trailing',\n 'inline',\n 'below',\n 'above',\n 'cornerStart',\n 'cornerEnd',\n];\n// Ordered as they read down the page, which is the order the dashboard's select\n// offers them in.\nexport const NATIVE_ELEMENT_POSITIONS: readonly NativeElementPosition[] = [\n 'top',\n 'belowFields',\n 'belowCard',\n 'bottom',\n];\nexport const SURCHARGE_STYLES: readonly SurchargeStyle[] = [\n 'plain',\n 'underline',\n 'outline',\n 'badge',\n 'solid',\n 'ribbon',\n];\nexport const SURCHARGE_BORDER_WIDTHS: readonly SurchargeBorderWidth[] = [\n 'none',\n 'thin',\n 'medium',\n 'thick',\n];\nexport const SURCHARGE_BORDER_STYLES: readonly SurchargeBorderStyle[] = [\n 'solid',\n 'dashed',\n 'dotted',\n];\nexport const SURCHARGE_SIZES: readonly SurchargeSize[] = ['sm', 'md', 'lg'];\n\n/**\n * Whether a style draws a shape behind the figure, and therefore whether\n * {@link SurchargeShape} means anything for it.\n *\n * `plain` and `underline` paint text. A dashboard that leaves the corner picker\n * live under them offers a control that changes nothing on screen, which is how\n * a merchant decides the whole panel is broken; one that hides it loses their\n * choice when they switch back. Disabled is the answer, and this is the\n * predicate it needs.\n */\nexport function surchargeStyleDrawsAShape(style: SurchargeStyle): boolean {\n return style === 'badge' || style === 'outline' || style === 'solid';\n}\nexport const SURCHARGE_SHAPES: readonly SurchargeShape[] = ['pill', 'rounded', 'square'];\nexport const SURCHARGE_WEIGHTS: readonly SurchargeWeight[] = ['regular', 'medium', 'bold'];\nexport const SURCHARGE_SIGNS: readonly SurchargeSign[] = ['always', 'minusOnly', 'none'];\nexport const SURCHARGE_LABEL_MODES: readonly SurchargeLabelMode[] = ['amount', 'labelled'];\nexport const SURCHARGE_FIGURE_MODES: readonly SurchargeFigureMode[] = [\n 'amount',\n 'percent',\n 'amountThenPercent',\n 'percentThenAmount',\n];\n\n/**\n * The buyer locales the checkout ships copy for, and therefore the ones a\n * merchant can override.\n *\n * Driven from here rather than restated in the dashboard, so a locale added to\n * the checkout cannot leave the dashboard offering one fewer box than the\n * buyer-facing render reads.\n */\nexport const CHECKOUT_LOCALES = [\n 'en',\n 'de',\n 'fr',\n 'es',\n 'it',\n 'nl',\n // Simplified and traditional are separate dictionaries in the checkout,\n // not region variants: they use different characters, so a merchant who\n // writes one has not written the other.\n 'zh',\n 'zh-Hant',\n 'hi',\n 'ar',\n] as const;\nexport type CheckoutLocale = (typeof CHECKOUT_LOCALES)[number];\n\n/**\n * Locales written right-to-left, for a UI that renders a merchant's override\n * next to the others.\n *\n * A dashboard field holding Arabic needs `dir=\"rtl\"` on the input itself:\n * without it the caret jumps, punctuation lands on the wrong end, and what the\n * merchant types is not what the buyer will see. Exported rather than kept in\n * the dashboard so the buyer-facing checkout and the editor agree on which\n * locales that is.\n */\nexport const RTL_CHECKOUT_LOCALES: readonly CheckoutLocale[] = ['ar'];\n\n/**\n * `dir` for a checkout locale — `'rtl'` for Arabic, `'ltr'` for the rest.\n *\n * Resolved on the **base language**, the same way `checkoutCopy` resolves an\n * override. Comparing the full string looked equivalent and was not: a buyer\n * sending `ar-EG` gets the `ar` copy from `checkoutCopy` and would have got\n * `ltr` from here — Arabic text in a left-to-right layout, which is the exact\n * failure this function exists to prevent. Case is folded for the same reason;\n * `Accept-Language` may arrive as `AR`.\n */\nexport function checkoutLocaleDir(locale: string): 'ltr' | 'rtl' {\n const base = String(locale ?? '')\n .toLowerCase()\n .split('-')[0];\n return (RTL_CHECKOUT_LOCALES as readonly string[]).includes(base) ? 'rtl' : 'ltr';\n}\n\n/**\n * The copy fields a merchant may write once per locale.\n *\n * Each has a flat `<field>` and a `<field>Translations` map beside it. The flat\n * value is what every existing merchant already has and stays authoritative\n * wherever no override is set — which is what makes this additive: a profile\n * saved before translations existed renders exactly as it did, in every locale.\n */\nexport const LOCALIZABLE_COPY_FIELDS = [\n 'headerText',\n 'payButtonLabel',\n 'cardTermsMessage',\n 'footerText',\n] as const;\nexport type LocalizableCopyField = (typeof LOCALIZABLE_COPY_FIELDS)[number];\n\n/** The translations key that belongs to a copy field. */\nexport function copyTranslationsKey(\n field: LocalizableCopyField,\n): `${LocalizableCopyField}Translations` {\n return `${field}Translations`;\n}\n\n/**\n * One piece of merchant copy, in the buyer's locale.\n *\n * Exact locale wins (`de-AT`), then its base language (`de`), then the flat\n * field — the same order `customFieldText` resolves in, because a merchant who\n * has learnt one of these should not have to learn the other.\n *\n * Returning the flat value rather than `''` is the backward-compatibility\n * guarantee: an override is an addition to what a merchant already wrote, never\n * a replacement for it, so an empty or missing map changes nothing.\n */\nexport function checkoutCopy(\n branding: CheckoutBranding,\n field: LocalizableCopyField,\n locale?: string,\n): string {\n const translated = translationFor(branding[copyTranslationsKey(field)], locale);\n return translated ?? branding[field];\n}\n\n/**\n * The merchant's own word for one direction, or `null` to use the checkout's\n * built-in one.\n *\n * `null` rather than a default string because the fallback is *localized* and\n * lives in the buyer-facing bundle — this module has no i18n of its own, and\n * inventing an English default here would print \"Discount\" to a German buyer.\n *\n * A merchant who sets nothing therefore keeps the shipped wording in both\n * languages, which is the intended default and already reads well.\n */\nexport function surchargeWordFor(\n branding: Pick<CheckoutBranding, 'surchargeWordTranslations' | 'discountWordTranslations'>,\n isDiscount: boolean,\n locale?: string,\n): string | null {\n return translationFor(\n isDiscount ? branding.discountWordTranslations : branding.surchargeWordTranslations,\n locale,\n );\n}\n\nexport interface TrustBadge {\n id: string;\n label: string;\n textColor: string;\n backgroundColor: string;\n borderColor: string | null;\n}\n\n// --- Notices -------------------------------------------------\n//\n// A notice is one short reassurance line on the checkout — a line icon and a\n// text — in one of two places. It replaces the trust badges as the default:\n// a badge carries its own three colours, so every theme had to recolour the\n// stock pair and a dark theme still wore light chips; a notice\n// carries none and is drawn in the checkout's own muted text and accent\n// colour, so it follows whatever palette the merchant picks. Its text is\n// written per locale, which a badge's never was.\n//\n// Persisted JSON-stringified under `sdk_ui_rules.branding.notices`, the same\n// transport as `trustBadges` and `customFields`.\n\n/**\n * Where a notice is drawn.\n *\n * - `summary`: under the order summary in the split layout; under the compact\n * header when there is no summary pane.\n * - `payment`: at the bottom of the payment element, under the pay button.\n */\nexport type NoticeSection = 'summary' | 'payment';\nexport const NOTICE_SECTIONS: readonly NoticeSection[] = ['summary', 'payment'];\n\n/**\n * How many notices one section draws. More than three stops reading as\n * reassurance and starts reading as small print, so the decoder drops the\n * overflow and the editor refuses a fourth.\n */\nexport const NOTICES_PER_SECTION = 3;\n\n/** Longest notice text, per locale. A notice is one line, not a paragraph. */\nexport const NOTICE_LABEL_MAX_LENGTH = 80;\n\n/** The marks a notice can carry, in the order the editor's grid offers them. */\nexport const NOTICE_ICONS = [\n 'lock',\n 'shield',\n 'check',\n 'truck',\n 'package',\n 'refresh',\n 'star',\n 'support',\n 'globe',\n 'tag',\n 'heart',\n 'leaf',\n 'clock',\n 'bank',\n] as const;\nexport type NoticeIcon = (typeof NOTICE_ICONS)[number];\n\n/** What an unknown or missing icon decodes to. */\nexport const NOTICE_ICON_FALLBACK: NoticeIcon = 'check';\n\n/**\n * Each mark as SVG path data on a 24×24 grid, stroked (not filled) with round\n * caps and joins.\n *\n * Kept here rather than drawn twice so the checkout and the customizer's icon\n * grid cannot disagree about what \"shield\" looks like: both render these\n * strings, and a mark added to `NOTICE_ICONS` without paths is a type error.\n * Every shape is a `<path>` — circles, rectangles and polylines included —\n * so a renderer needs one element type and no per-icon template.\n */\nexport const NOTICE_ICON_PATHS: Readonly<Record<NoticeIcon, readonly string[]>> = {\n lock: [\n 'M6 10h12a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2z',\n 'M8 10V7a4 4 0 0 1 8 0v3',\n ],\n shield: ['M12 3l7 3v6c0 4.2-2.9 7.6-7 9-4.1-1.4-7-4.8-7-9V6z', 'M9 12l2.5 2.5 4-4.5'],\n check: ['M21 12a9 9 0 1 1-18 0a9 9 0 1 1 18 0z', 'M8 12.5l3 3 5-6'],\n truck: [\n 'M3 7.5h10v9H3z',\n 'M13 11h4l3 3v2.5h-7z',\n 'M8.8 18a1.8 1.8 0 1 1-3.6 0a1.8 1.8 0 1 1 3.6 0z',\n 'M18.8 18a1.8 1.8 0 1 1-3.6 0a1.8 1.8 0 1 1 3.6 0z',\n ],\n package: [\n 'M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z',\n 'M12 22V12',\n 'M3.29 7L12 12l8.71-5',\n ],\n refresh: ['M20 12a8 8 0 1 1-2.5-5.8', 'M20 4v5h-5'],\n star: ['m12 3.6 2.6 5.3 5.9.9-4.3 4.1 1 5.8-5.2-2.7-5.2 2.7 1-5.8-4.3-4.1 5.9-.9z'],\n support: [\n 'M5 13v-1a7 7 0 0 1 14 0v1',\n 'M3.5 14.5a1.8 1.8 0 0 1 1.8-1.8H7v5H5.3a1.8 1.8 0 0 1-1.8-1.8z',\n 'M20.5 14.5a1.8 1.8 0 0 0-1.8-1.8H17v5h1.7a1.8 1.8 0 0 0 1.8-1.8z',\n 'M19 17.7v.8a2.5 2.5 0 0 1-2.5 2.5H13',\n ],\n globe: [\n 'M21 12a9 9 0 1 1-18 0a9 9 0 1 1 18 0z',\n 'M3 12h18',\n 'M12 3a14 14 0 0 1 0 18a14 14 0 0 1 0-18z',\n ],\n tag: ['M11 3H4v7l10 10 7-7z', 'M9.1 7a1.3 1.3 0 1 1-2.6 0a1.3 1.3 0 1 1 2.6 0z'],\n heart: ['M12 20s-7-4.4-7-9.3A3.9 3.9 0 0 1 12 8a3.9 3.9 0 0 1 7 2.7c0 4.9-7 9.3-7 9.3z'],\n leaf: ['M20 4c0 9-5.4 13-9.5 13A4.5 4.5 0 0 1 6 12.5C6 7 12 4 20 4z', 'M4 20c2-4.5 5-7.5 9-9.5'],\n clock: ['M21 12a9 9 0 1 1-18 0a9 9 0 1 1 18 0z', 'M12 7v5l3 2'],\n bank: ['M3 9.5 12 4l9 5.5', 'M5 10v8M9.5 10v8M14.5 10v8M19 10v8', 'M3 20h18'],\n};\n\nexport function isNoticeIcon(value: unknown): value is NoticeIcon {\n return typeof value === 'string' && (NOTICE_ICONS as readonly string[]).includes(value);\n}\n\nexport interface CheckoutNotice {\n /** Stable across edits and drags; `[A-Za-z0-9_-]`, at most 40 characters. */\n id: string;\n section: NoticeSection;\n icon: NoticeIcon;\n /** Default-language text, and what every locale without an override reads. */\n label: string;\n /** Per-locale overrides of `label`; a blank entry means \"use `label`\". */\n labelTranslations: CustomFieldTranslations;\n}\n\n// Merchant-defined checkout inputs. Rendered by the buyer-facing checkout\n// above the payment surface; submitted values land in the payment's\n// `metadata` under each field's `key`. Persisted JSON-stringified under\n// `sdk_ui_rules.branding.customFields` (same transport as trustBadges).\n// `checkbox` is a single opt-in box (terms acceptance, marketing consent),\n// not a multi-select. Its submitted value is always the string `'true'` or\n// `'false'` — never absent — so a merchant can tell \"declined\" from \"never\n// asked\" in the payment's metadata, which is what makes it usable as a\n// consent record. See `CHECKBOX_CHECKED` / `isCheckboxChecked`.\nexport type CustomFieldType = 'text' | 'textarea' | 'password' | 'email' | 'select' | 'checkbox';\n\n// Per-locale overrides ('de', 'en', …). Missing locale falls back to the\n// default-language string on the field itself — see `customFieldText`.\nexport type CustomFieldTranslations = Record<string, string>;\n\nexport interface CustomFieldOption {\n value: string;\n label: string;\n labelTranslations: CustomFieldTranslations;\n}\n\n// --- Conditional visibility ---------------------------------------------\n//\n// A field can be gated on facts the payment already carries when the\n// checkout renders: the intent's `metadata` (which a shop integration fills\n// per product/category — see the WordPress plugin's product metadata), its\n// `currency`, or its `amount`. This is what lets one profile serve a\n// \"Windows key\" order (no fields) and a \"Spotify account\" order (login\n// fields) without two shops.\n//\n// Evaluation is authoritative on the **backend**: `form_payment_link_data`\n// drops non-matching fields from the payload the buyer's browser receives,\n// so merchant metadata never leaves the server and the rules can't be\n// tampered with client-side. The implementation here is the shared\n// specification (and drives the dashboard's builder); the API applies the\n// same rules and must stay behaviorally identical.\nexport type CustomFieldConditionSource = 'metadata' | 'currency' | 'amount';\n\n// String operators apply to metadata + currency; numeric ones (`gt`…`lte`)\n// apply to amount and to metadata values that parse as numbers.\nexport type CustomFieldOperator =\n | 'equals'\n | 'not_equals'\n | 'contains'\n | 'not_contains'\n | 'starts_with'\n | 'ends_with'\n | 'in'\n | 'not_in'\n | 'exists'\n | 'not_exists'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte';\n\nexport interface CustomFieldCondition {\n // Stable identity for editor list operations (reorder/remove). Not part\n // of the semantics.\n id: string;\n source: CustomFieldConditionSource;\n // Metadata key to read. Ignored (and persisted empty) for currency/amount.\n key: string;\n operator: CustomFieldOperator;\n // Right-hand operand. `in`/`not_in` read it as a comma-separated list;\n // `exists`/`not_exists` ignore it; amount comparisons parse it as an\n // integer in the currency's minor unit (1000 = 10.00).\n value: string;\n}\n\nexport interface CustomFieldVisibility {\n // `always` — unconditional (the default, and what every pre-feature field\n // decodes to). `match` — evaluate `conditions`.\n mode: 'always' | 'match';\n // How to combine multiple conditions.\n match: 'all' | 'any';\n conditions: CustomFieldCondition[];\n}\n\nexport interface CheckoutCustomField {\n // Stable identity for editor list operations (reorder/remove).\n id: string;\n // Metadata key the submitted value is stored under. Must be unique per\n // profile; the editor enforces `CUSTOM_FIELD_KEY_PATTERN`.\n key: string;\n type: CustomFieldType;\n // Default-language copy; `*Translations` maps override per locale.\n label: string;\n labelTranslations: CustomFieldTranslations;\n placeholder: string;\n placeholderTranslations: CustomFieldTranslations;\n helpText: string;\n helpTextTranslations: CustomFieldTranslations;\n required: boolean;\n // Disabled fields stay configured but are neither rendered nor submitted.\n enabled: boolean;\n // Length bounds apply to text/textarea/password/email; null = unbounded.\n minLength: number | null;\n maxLength: number | null;\n // Prefill for text-like fields; for selects, the option `value` selected\n // initially (empty = placeholder \"choose\" state).\n defaultValue: string;\n // Select choices; ignored for other types.\n options: CustomFieldOption[];\n // Conditional display. Always populated by the decoder — fields without a\n // persisted rule decode to `{ mode: 'always', … }`.\n visibility: CustomFieldVisibility;\n}\n\nexport interface CheckoutBranding extends EnigmaCardFormSettings {\n // Brand identity\n displayName: string;\n logoUrl: string;\n tagline: string;\n showLogo: boolean;\n logoShape: LogoShape;\n logoSize: LogoSize;\n\n // Color tokens\n primary: string;\n background: string;\n surface: string;\n text: string;\n heading: string;\n muted: string;\n border: string;\n accentText: string;\n buttonBackground: string;\n buttonText: string;\n\n // Typography\n fontFamily: FontFamily;\n headingWeight: FontWeight;\n\n // Shape — granular per-element. Surfaces & inputs use a narrower union\n // (no pill) because pill cards/inputs are always wrong; button and badge\n // keep the full `CornerRadius` since pill is a legitimate look there.\n radiusSurface: NonPillRadius;\n radiusInput: NonPillRadius;\n radiusButton: CornerRadius;\n radiusBadge: CornerRadius;\n surfaceStyle: SurfaceStyle;\n\n // Spacing — four independent dimensions.\n surfacePadding: SpacingScale;\n verticalGap: SpacingScale;\n inputSize: SizeScale;\n buttonSize: SizeScale;\n\n // Layout\n layout: LayoutStyle;\n summaryPosition: SummaryPosition;\n showOrderSummary: boolean;\n summaryGradient: boolean;\n showTotal: boolean;\n totalLabel: string;\n showCurrencyCode: boolean;\n showOrderItems: boolean;\n\n // Hosted-checkout exit. It is only drawn when the payment resolves a\n // cancel URL; these fields decide whether and how that destination is shown.\n cancelLinkEnabled: boolean;\n cancelLinkPosition: 'top' | 'bottom';\n cancelLinkStyle: 'link' | 'button';\n\n // Provider surcharge / discount disclosure. `showSurcharge` false hides the\n // per-tile figure entirely; the in-pane breakdown is unaffected, since that\n // one is the merchant's existing legal disclosure rather than a steering\n // signal. The two colours are separate on purpose: a surcharge and a discount\n // are opposite news for the buyer and reading them in one colour is exactly\n // the mistake a minus sign is easy to miss in.\n showSurcharge: boolean;\n surchargePosition: SurchargePosition;\n // Where the express strip of wallet buttons goes on the payment surface.\n // Only rows that actually draw a button are lifted into it; a surface with\n // none has no strip.\n nativeElementPosition: NativeElementPosition;\n // One button per line in that strip, instead of side by side.\n //\n // Off by default, because two wallets on one line is what the strip is for:\n // Apple Pay and Google Pay are one choice made twice, and a buyer is offered\n // at most one of them on any given browser anyway — the second track is\n // usually the card form arriving sooner rather than a second button. On for\n // a merchant who wants each button full width: a wide brand mark, a checkout\n // narrow enough that two tracks crowd, or simply their own taste.\n //\n // The strip already stacks on its own when the surface is too narrow to seat\n // two; this makes it stack at every width.\n nativeElementStacked: boolean;\n surchargeStyle: SurchargeStyle;\n surchargeSize: SurchargeSize;\n surchargeShape: SurchargeShape;\n surchargeBorderWidth: SurchargeBorderWidth;\n surchargeBorderStyle: SurchargeBorderStyle;\n surchargeWeight: SurchargeWeight;\n surchargeSign: SurchargeSign;\n surchargeUppercase: boolean;\n surchargeLabel: SurchargeLabelMode;\n surchargeFigure: SurchargeFigureMode;\n discountFigure: SurchargeFigureMode;\n surchargeWordTranslations: CustomFieldTranslations;\n discountWordTranslations: CustomFieldTranslations;\n surchargeColor: string;\n discountColor: string;\n\n // Trust badges (fully customizable; empty = hide row). No longer a default:\n // new shops start with none and get `notices` instead; a shop that customised\n // its badges keeps them. See `resolveNoticesAndBadges`.\n trustBadges: TrustBadge[];\n\n // Reassurance lines — icon + per-locale text — in the summary and at the\n // bottom of the payment element (empty = none).\n notices: CheckoutNotice[];\n\n // Merchant-defined checkout inputs (empty = no custom fields section).\n customFields: CheckoutCustomField[];\n\n // Where each payment-method section renders, 1-100, lower first.\n methodSectionOrder: MethodSectionOrder;\n\n // The merchant's name for a section, per locale. Empty = use the built-in\n // name, or the id itself for a section with none.\n methodSectionLabels: MethodSectionLabels;\n\n // Copy. All of these are optional in the persisted form: empty string\n // means \"unset\" and consumers should fall back (e.g. payButtonLabel falls\n // back to a localized \"Pay $X\" string).\n headerText: string;\n headerTextTranslations: CustomFieldTranslations;\n payButtonLabel: string;\n payButtonLabelTranslations: CustomFieldTranslations;\n cardTermsMessage: string;\n cardTermsMessageTranslations: CustomFieldTranslations;\n footerText: string;\n footerTextTranslations: CustomFieldTranslations;\n supportEmail: string;\n\n // Stripe Elements behavior. `paymentLayout` only affects what's painted\n // inside Stripe's iframe; non-Stripe connector panes stack vertically\n // regardless. `labelStyle` is also Stripe-iframe scope.\n paymentLayout: PaymentLayout;\n labelStyle: LabelStyle;\n\n // The Airwallex card surface. Scoped to that pane by name because that is\n // the only rail these reach: Stripe's element is themed through its own\n // Appearance API and the vault's fields are our DOM, so a field weight\n // written here would quietly do nothing on either. See `airwallexCard.ts`\n // for the geometry these sit on top of.\n //\n // `airwallexCardPreset` is the only one that can be EMPTY, and that is the\n // hinge of the whole migration: empty means \"the merchant has not chosen\n // here\", which lets the connector account's own `integration_style` keep\n // deciding for every shop configured before this section existed. A default\n // of `split_fields_labelled` on this field would override all of them\n // silently. `resolveAirwallexCardPreset` is the resolution.\n airwallexCardPreset: AirwallexCardPreset | '';\n // Removes the card form from the shop's checkout entirely. Money-affecting\n // and therefore off by default: with this on, no buyer can pay by card.\n airwallexHideCard: boolean;\n // Drops the \"Card\" heading over the Airwallex form. Presentation only, and\n // scoped to this rail because it is this rail's form the merchant is looking\n // at when they turn it off: a shop whose form is the first thing on the\n // checkout has no use for a word naming what the fields obviously are.\n //\n // The section is what loses its NAME, not its disclosure — a surcharge or\n // discount chip on the card rail still renders on that line, because what it\n // says is the money the buyer is about to be charged.\n airwallexHideCardTitle: boolean;\n airwallexFieldChrome: AirwallexFieldChrome;\n // Empty means \"whatever the preset says\" — see `resolveAirwallexLabelStyle`.\n airwallexLabelStyle: AirwallexLabelStyle | '';\n airwallexFieldFontSize: AirwallexFieldFontSize;\n airwallexFieldWeight: AirwallexFieldWeight;\n airwallexFocusRing: AirwallexFocusRing;\n airwallexAutofill: AirwallexAutofillTreatment;\n airwallexValidTint: boolean;\n // Decorative marks, and nothing more — they do not narrow what Airwallex\n // accepts. See `AIRWALLEX_NETWORK_MARKS`.\n airwallexNetworkMarks: boolean;\n\n // The Stripe Payment Element's own look (`cardFormStyles.ts`). Applied over\n // the colour, font and radius tokens above, inside Stripe's iframe.\n stripeTheme: StripeTheme;\n stripeInputs: StripeInputStyle;\n stripeLabels: StripeLabelPlacement;\n stripeSpacing: StripeSpacing;\n stripeFieldFontSize: CardFieldFontSize;\n stripeFieldWeight: CardFieldWeight;\n stripeFocusRing: CardFocusRing;\n stripeDisableAnimations: boolean;\n\n // PayPal Card Fields and Mollie Components. Boxes and captions are our DOM;\n // the type size and weight reach the text inside PayPal's iframes.\n paypalCardLayout: PaypalCardLayout;\n paypalLabelStyle: PaypalLabelStyle;\n paypalFieldChrome: CardFieldChrome;\n mollieFieldChrome: CardFieldChrome;\n paypalFieldFontSize: CardFieldFontSize;\n mollieFieldFontSize: CardFieldFontSize;\n paypalFieldWeight: CardFieldWeight;\n mollieFieldWeight: CardFieldWeight;\n paypalFocusRing: CardFocusRing;\n mollieFocusRing: CardFocusRing;\n paypalValidTint: boolean;\n\n // e-Payouts' Pay with card. PayPal's card fields too,\n // so the same seven knobs, but the shop's own: changing the PayPal card\n // form leaves this one alone. A stored look from before this section has\n // none of these keys, and reads the PayPal ones, which is what the form\n // followed until then (see `decodeBranding`).\n epayoutsCardLayout: PaypalCardLayout;\n epayoutsLabelStyle: PaypalLabelStyle;\n epayoutsFieldChrome: CardFieldChrome;\n epayoutsFieldFontSize: CardFieldFontSize;\n epayoutsFieldWeight: CardFieldWeight;\n epayoutsFocusRing: CardFocusRing;\n epayoutsValidTint: boolean;\n\n // NomuPay's COPYandPAY widget: `wpwlOptions` for the form, the checkout's\n // CSS on its `.wpwl-*` boxes, and the Apple Pay and Google Pay buttons the\n // same widget draws. `auto` follows the checkout's theme, as before.\n nomupayFormStyle: NomupayFormStyle;\n nomupayShowLabels: boolean;\n nomupayShowPlaceholders: boolean;\n nomupayShowCvvHint: boolean;\n nomupayFieldChrome: CardFieldChrome;\n nomupayFieldFontSize: CardFieldFontSize;\n nomupayFocusRing: CardFocusRing;\n nomupayApplePayButtonStyle: ApplePayButtonStyle;\n nomupayApplePayButtonType: ApplePayButtonType;\n nomupayGooglePayButtonColor: GooglePayButtonColor;\n nomupayGooglePayButtonType: GooglePayButtonType;\n\n // MicroPayment's JSBridge frame: the checkout draws the holder and expiry\n // inputs and the box around the provider's PAN and CVC frames itself, and\n // hands the type size and weight into those frames.\n micropaymentFieldChrome: CardFieldChrome;\n micropaymentFieldFontSize: CardFieldFontSize;\n micropaymentFieldWeight: CardFieldWeight;\n micropaymentFocusRing: CardFocusRing;\n\n // Whop's Payment Elements: the element and layout (`whopCardPreset`), the\n // palette Whop draws its own controls in, and per-part CSS for the boxes,\n // all inside Whop's frames. See `cardFormStyles.ts`.\n whopCardPreset: WhopCardPreset;\n whopAccentColor: WhopAccentColor;\n whopGrayColor: WhopGrayColor;\n whopBillingDetails: WhopBillingDetails;\n // `accordion` only: each method in its own card, with space between.\n whopSeparated: boolean;\n whopEmailLabel: WhopEmailLabel;\n whopFieldChrome: CardFieldChrome;\n // Kept for stored brandings and no longer read: Whop draws the card digits\n // at its own size and weight and marks focus itself, so neither the\n // checkout nor the dashboard uses these three.\n whopFieldFontSize: CardFieldFontSize;\n whopFieldWeight: CardFieldWeight;\n whopFocusRing: CardFocusRing;\n // The corners of Whop's form, its drop shadow, whether the method list\n // shows each method's icon, and how it marks the chosen method.\n whopRadius: WhopRadius;\n whopShadow: WhopShadow;\n whopMethodIcons: boolean;\n whopSelection: WhopSelection;\n\n // Footer\n showPoweredBy: boolean;\n\n // Advanced — raw CSS appended after brand-token CSS variables are\n // applied, so its declarations win cascade order. Sanitized at render\n // time (see `sanitizeCustomCss`); persisted as-typed under\n // `sdk_ui_rules.branding.customCss`.\n customCss: string;\n}\n\n// --- Token maps ---------------------------------------------------------\n\n// Self-hostable font stacks. The buyer-facing checkout bundles these via\n// @fontsource* packages; the variable-font names ('Inter Variable', …) are\n// listed first so the smaller variable file is preferred when bundled.\nconst FONT_STACKS: Record<FontFamily, string> = {\n inter: \"'Inter Variable', 'Inter', system-ui, -apple-system, sans-serif\",\n system:\n \"system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif\",\n serif: \"Georgia, 'Times New Roman', serif\",\n mono: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',\n roboto: \"'Roboto', system-ui, sans-serif\",\n poppins: \"'Poppins', system-ui, sans-serif\",\n manrope: \"'Manrope Variable', 'Manrope', system-ui, sans-serif\",\n 'dm-sans': \"'DM Sans Variable', 'DM Sans', system-ui, sans-serif\",\n 'space-grotesk': \"'Space Grotesk Variable', 'Space Grotesk', system-ui, sans-serif\",\n 'plex-sans': \"'IBM Plex Sans', system-ui, sans-serif\",\n 'work-sans': \"'Work Sans Variable', 'Work Sans', system-ui, sans-serif\",\n 'open-sans': \"'Open Sans Variable', 'Open Sans', system-ui, sans-serif\",\n lora: \"'Lora Variable', 'Lora', Georgia, serif\",\n playfair: \"'Playfair Display Variable', 'Playfair Display', Georgia, serif\",\n 'plex-mono': \"'IBM Plex Mono', ui-monospace, monospace\",\n 'jetbrains-mono': \"'JetBrains Mono Variable', 'JetBrains Mono', ui-monospace, monospace\",\n};\n\nconst RADIUS_PX: Record<CornerRadius, string> = {\n square: '0px',\n small: '6px',\n medium: '12px',\n large: '20px',\n pill: '999px',\n};\n\nconst FONT_WEIGHT_NUMERIC: Record<FontWeight, string> = {\n regular: '400',\n medium: '500',\n semibold: '600',\n bold: '700',\n};\n\nconst SURFACE_PAD: Record<SpacingScale, string> = {\n compact: '1rem',\n comfortable: '1.5rem',\n spacious: '2rem',\n};\n\nconst VERTICAL_GAP: Record<SpacingScale, string> = {\n compact: '0.75rem',\n comfortable: '1rem',\n spacious: '1.5rem',\n};\n\nconst INPUT_PAD: Record<SizeScale, string> = {\n sm: '0.5rem 0.75rem',\n md: '0.625rem 0.75rem',\n lg: '0.875rem 0.875rem',\n};\n\nconst BUTTON_PAD: Record<SizeScale, string> = {\n sm: '0.625rem 1rem',\n md: '0.875rem 1.25rem',\n lg: '1.125rem 1.5rem',\n};\n\nexport function fontStack(family: FontFamily): string {\n return FONT_STACKS[family] ?? FONT_STACKS.inter;\n}\n\nexport function radiusValue(radius: CornerRadius): string {\n return RADIUS_PX[radius] ?? RADIUS_PX.medium;\n}\n\nexport function fontWeightValue(weight: FontWeight): string {\n return FONT_WEIGHT_NUMERIC[weight] ?? '600';\n}\n\nexport function surfacePadValue(scale: SpacingScale): string {\n return SURFACE_PAD[scale] ?? SURFACE_PAD.comfortable;\n}\n\nexport function verticalGapValue(scale: SpacingScale): string {\n return VERTICAL_GAP[scale] ?? VERTICAL_GAP.comfortable;\n}\n\nexport function inputPadValue(size: SizeScale): string {\n return INPUT_PAD[size] ?? INPUT_PAD.md;\n}\n\nexport function buttonPadValue(size: SizeScale): string {\n return BUTTON_PAD[size] ?? BUTTON_PAD.md;\n}\n\n/**\n * The look a vault's own card form takes to match a checkout with this\n * branding: pass it to `CheckoutSession.vaultCollectSession`.\n *\n * `danger` is the colour of an invalid field's border. The checkout picks it\n * for contrast on the surface, which this module does not measure, so the\n * caller supplies it.\n */\nexport function vaultFormAppearance(\n b: CheckoutBranding,\n danger?: string,\n options: { designed?: boolean } = {},\n): VaultFormAppearance {\n const border = b.enigmaBorder || b.border;\n const look: VaultFormAppearance = {\n surface: b.surface,\n text: b.text,\n border,\n accent: b.enigmaAccent || b.primary,\n ...(danger ? { danger } : {}),\n font: b.fontFamily,\n radius: b.radiusInput,\n size: b.inputSize,\n labels: b.labelStyle,\n };\n if (!options.designed) return look;\n // The Enigma card form's own settings, asked for only by a\n // caller that draws the answered `layout`: a designed form hides Enigma's\n // own field names and \"Save card\" caption, which that caller draws instead.\n // A security-code form takes only the look above.\n return {\n ...look,\n chrome: b.enigmaChrome,\n label: enigmaNamesInside(b) ? 'inside' : 'above',\n hints: b.enigmaHints,\n order: b.enigmaFieldOrder,\n marks: b.enigmaMarks,\n focus: b.enigmaFocusRing,\n motion: b.enigmaFieldMotion,\n height: b.enigmaFieldHeight,\n gap: b.enigmaRowGap,\n corner: b.enigmaCorner,\n fill: b.enigmaFill || enigmaDefaultFill(b.surface, b.text),\n ...(b.enigmaStyleMode === 'custom' ? { custom: true } : {}),\n };\n}\n\n/** A filled field's tint when the shop sets none: 6% of the text in the surface. */\nexport function enigmaDefaultFill(surface: string, text: string): string {\n const channels = (hex: string): [number, number, number] | null => {\n const v = hex.trim().replace('#', '');\n const full = v.length === 3 ? v.replace(/./g, '$&$&') : v;\n if (!/^[0-9a-fA-F]{6}$/.test(full)) return null;\n return [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16)) as [number, number, number];\n };\n const s = channels(surface) ?? [255, 255, 255];\n const t = channels(text) ?? [30, 41, 59];\n return `#${s\n .map((value, i) =>\n Math.round(value * 0.94 + (t[i] ?? 0) * 0.06)\n .toString(16)\n .padStart(2, '0'),\n )\n .join('')}`;\n}\n\nexport function logoDimensions(size: LogoSize): { px: number; radius: number } {\n switch (size) {\n case 'sm':\n return { px: 36, radius: 8 };\n case 'lg':\n return { px: 64, radius: 16 };\n case 'md':\n default:\n return { px: 48, radius: 12 };\n }\n}\n\nconst HEX_RE = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/;\n\nexport function isHexColor(value: string): boolean {\n return HEX_RE.test(value.trim());\n}\n\n/**\n * A CSS `<hex-color>`: whole token, leading `#` REQUIRED.\n *\n * ⚠️ The `#` is not pedantry here. `applyBrandingVariables` writes branding\n * values into custom properties unchanged (`el.style.setProperty(k, v)`), and\n * a custom property accepts any token stream — it is only interpreted when\n * substituted into a typed property, where `000` is not a colour and the\n * declaration is dropped. So a contrast API that accepted `'000'` would hand\n * back `21` for a pair that renders as nothing at all: approving a palette\n * that never reaches the screen is worse than refusing to judge it.\n */\nconst CSS_HEX_RE = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;\n\n/**\n * The same shape with the `#` optional, for {@link isDarkSurface} ONLY.\n *\n * That function has stripped an optional hash since it was written, and\n * `'5a5a5a'` is a real colour whose answer is correct — tightening it onto the\n * CSS form would answer correct input wrongly. New API does not inherit the\n * tolerance; the existing caller keeps it.\n */\nconst LENIENT_HEX_RE = /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;\n\n/** `[r, g, b]` in 0–255, or `null` when the token is not a colour. */\nfunction parseHexChannels(value: string, pattern: RegExp): [number, number, number] | null {\n const match = pattern.exec(value.trim());\n if (!match) return null;\n const digits = match[1] as string;\n const full =\n digits.length === 3\n ? digits\n .split('')\n .map((c) => c + c)\n .join('')\n : digits;\n return [\n parseInt(full.slice(0, 2), 16),\n parseInt(full.slice(2, 4), 16),\n parseInt(full.slice(4, 6), 16),\n ];\n}\n\n/** WCAG 2.1 relative luminance (1.4.3), with the sRGB linearisation. */\nfunction relativeLuminance([r, g, b]: [number, number, number]): number {\n const [lr, lg, lb] = [r, g, b].map((channel) => {\n const c = channel / 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n }) as [number, number, number];\n return 0.2126 * lr + 0.7152 * lg + 0.0722 * lb;\n}\n\n/** Minimum contrast for body text — WCAG 2.1 success criterion 1.4.3. */\nexport const WCAG_AA_TEXT = 4.5;\n\n/**\n * Minimum contrast for non-text UI — WCAG 2.1 success criterion 1.4.11.\n * Focus rings, borders, icons carrying meaning.\n */\nexport const WCAG_AA_UI = 3;\n\n/**\n * WCAG 2.1 contrast ratio between two colours, 1–21. Order does not matter.\n *\n * Compare against {@link WCAG_AA_TEXT} or {@link WCAG_AA_UI}:\n *\n * ```ts\n * const ratio = contrastRatio(branding.surface, branding.text);\n * if (ratio === null || ratio < WCAG_AA_TEXT) useDefaultPalette();\n * ```\n *\n * ⚠️ Returns `null` — never a number — when either colour cannot be parsed.\n * That is the load-bearing part of this signature. Every colour bug this API\n * exists to prevent came from a helper answering with a plausible value for\n * something it could not read, and a `0` or a `21` here would be silently\n * believed by exactly the branch that is deciding whether text is legible.\n *\n * Accepts `#rgb` and `#rrggbb` — a CSS `<hex-color>`. ⚠️ A hash-less token is\n * `null`, not a ratio: `applyBrandingVariables` writes branding values into\n * custom properties verbatim, so `'000'` reaches CSS as something that is not a\n * colour. Returning `21` for it would approve a palette that never renders.\n * ({@link isDarkSurface} keeps its historical hash-less tolerance; this is new\n * API and does not inherit it.)\n */\nexport function contrastRatio(a: string, b: string): number | null {\n const first = parseHexChannels(a, CSS_HEX_RE);\n const second = parseHexChannels(b, CSS_HEX_RE);\n if (!first || !second) return null;\n const [x, y] = [relativeLuminance(first), relativeLuminance(second)];\n const lighter = Math.max(x, y);\n const darker = Math.min(x, y);\n return (lighter + 0.05) / (darker + 0.05);\n}\n\n/**\n * Crude perceived-luminance check — picks the right Stripe Elements preset\n * (`'night'` vs `'stripe'`) when the merchant has a dark surface.\n *\n * ⚠️ **This is not a readability test. Use {@link contrastRatio} for that.**\n * It is a YIQ luma split at 128, and on real brand colours its verdict and\n * actual legibility are not merely imprecise relative to each other — they can\n * be anti-correlated:\n *\n * | colour | `isDarkSurface` | vs white | |\n * | --- | --- | --- | --- |\n * | `#ff00ff` | `true` | 3.14:1 | fails AA text |\n * | `#00ff00` | `false` | 1.37:1 | fails AA text |\n * | `#0000ff` | `true` | 8.59:1 | passes |\n *\n * A caller picking text colour from this gets the wrong answer on both failing\n * cases. It is kept because choosing a Stripe preset is a legitimate and\n * different question.\n *\n * Inputs that are not a 3-/6-digit hex fall through to \"light\", the safer\n * assumption for the default palette.\n */\nexport function isDarkSurface(color: string): boolean {\n // ⚠️ Was a length check plus `parseInt` plus `Number.isNaN`, which let six\n // values the package's own validator rejects through as \"dark\" — `parseInt`\n // accepts a valid prefix, so `parseInt('0g', 16)` is `0`, not `NaN`. The\n // comment above already promised these fall through to \"light\"; now they do.\n const channels = parseHexChannels(color, LENIENT_HEX_RE);\n if (!channels) return false;\n const [r, g, b] = channels;\n const luma = (r * 299 + g * 587 + b * 114) / 1000;\n return luma < 128;\n}\n\n// --- Defaults -----------------------------------------------------------\n\n// Light-mode DeloPay-branded baseline. Hex values come straight from\n// `design-guidelines/colors.md`:\n// - #1E4FEB is `--color-dp-blue`, the wordmark/icon brand blue\n// - #0A1130 is `--color-dp-blue-dark`, the wordmark navy\n// - the rest are slate-50 / slate-200 / slate-500 / slate-800 from the\n// design system's neutral ramp.\n// Picked for: high contrast, neutral surroundings, brand-blue accents,\n// confident navy CTA. Reads \"fintech\" without feeling cold.\nconst LIGHT_PALETTE = {\n primary: '#1E4FEB',\n background: '#f8fafc',\n surface: '#ffffff',\n text: '#1e293b',\n heading: '#0A1130',\n muted: '#64748b',\n border: '#e2e8f0',\n accentText: '#1E4FEB',\n buttonBackground: '#0A1130',\n buttonText: '#ffffff',\n} as const;\n\nexport const DEFAULT_BADGES: TrustBadge[] = [\n {\n id: 'secure',\n label: 'Secure',\n textColor: '#047857',\n backgroundColor: '#ecfdf5',\n borderColor: '#a7f3d0',\n },\n {\n id: 'ssl',\n label: '256-bit SSL',\n textColor: '#1E4FEB',\n backgroundColor: '#eff6ff',\n borderColor: '#bfdbfe',\n },\n];\n\n// Dark-mode equivalents of DEFAULT_BADGES. Dark trust chips need solid hex\n// (the form's color picker only accepts hex), so we pick the design system's\n// success-900 / info-900 backdrops paired with their *-400 foreground tokens.\nexport const DEFAULT_BADGES_DARK: TrustBadge[] = [\n {\n id: 'secure',\n label: 'Secure',\n textColor: '#34d399',\n backgroundColor: '#064e3b',\n borderColor: '#065f46',\n },\n {\n id: 'ssl',\n label: '256-bit SSL',\n textColor: '#60a5fa',\n backgroundColor: '#172554',\n borderColor: '#1e40af',\n },\n];\n\n/**\n * The notices every shop starts with.\n *\n * The same two claims the stock badges made — the payment is secure, the\n * connection is TLS-encrypted — and nothing more. A default is shown on every\n * shop that has not written its own, so it may only say what is true of every\n * shop: \"free shipping\" or \"tax included\" are the merchant's to claim, never\n * ours.\n *\n * `label` is English and there is deliberately no `en` override, so the\n * customizer's Default tab edits what an English buyer reads. The other nine\n * checkout locales are written out, because a German buyer reading \"Secure\n * payment\" is exactly what the badges did wrong.\n */\nexport const DEFAULT_NOTICES: readonly CheckoutNotice[] = [\n {\n id: 'secure',\n section: 'summary',\n icon: 'shield',\n label: 'Secure payment',\n labelTranslations: {\n de: 'Sichere Zahlung',\n fr: 'Paiement sécurisé',\n es: 'Pago seguro',\n it: 'Pagamento sicuro',\n nl: 'Veilig betalen',\n zh: '安全支付',\n 'zh-Hant': '安全付款',\n hi: 'सुरक्षित भुगतान',\n ar: 'دفع آمن',\n },\n },\n {\n id: 'ssl',\n section: 'summary',\n icon: 'lock',\n label: 'Encrypted · 256-bit SSL',\n labelTranslations: {\n de: 'Verschlüsselt · 256-Bit-SSL',\n fr: 'Chiffré · SSL 256 bits',\n es: 'Cifrado · SSL de 256 bits',\n it: 'Crittografato · SSL a 256 bit',\n nl: 'Versleuteld · 256-bit SSL',\n zh: '加密 · 256 位 SSL',\n 'zh-Hant': '加密 · 256 位元 SSL',\n hi: 'एन्क्रिप्टेड · 256-बिट SSL',\n ar: 'مشفّر · SSL بطول 256 بت',\n },\n },\n];\n\n/** A deep copy of `DEFAULT_NOTICES`, safe to edit. */\nexport function defaultNotices(): CheckoutNotice[] {\n return DEFAULT_NOTICES.map(cloneNotice);\n}\n\nexport function cloneNotice(notice: CheckoutNotice): CheckoutNotice {\n return { ...notice, labelTranslations: { ...notice.labelTranslations } };\n}\n\n/** `#rrggbb` → its three channels, or `null` for anything else. */\nfunction hexChannels(hex: string): [number, number, number] | null {\n const raw = /^#([0-9a-f]{6})$/i.exec(hex.trim())?.[1];\n if (!raw) return null;\n return [\n parseInt(raw.slice(0, 2), 16),\n parseInt(raw.slice(2, 4), 16),\n parseInt(raw.slice(4, 6), 16),\n ];\n}\n\n/**\n * Whether a badge colouring is one the dashboard's theme gallery generated.\n *\n * From 2026-09-03 the built-in themes shipped the stock pair recoloured from\n * the theme (the dashboard's `themeBadges`): text = the primary,\n * fill = the surface mixed 8 % towards it, border = mixed 30 %, rounded per\n * channel. Those shops never chose their badge colours either, so they count\n * as stock. The surface is not stored with the badges, so it is recovered:\n * each channel is searched for a surface value that reproduces BOTH the fill\n * and the border — a hand-picked colouring passes that by accident only when\n * the merchant happened to type the exact generated hexes.\n *\n * Frozen on purpose: this recognises what was shipped, so it must not follow\n * any later change to how themes look.\n */\nfunction isThemeTintedBadgeColouring(textColor: string, fill: string, border: string): boolean {\n const primary = hexChannels(textColor);\n const bg = hexChannels(fill);\n const line = hexChannels(border);\n if (!primary || !bg || !line) return false;\n const mixed = (surface: number, to: number, share: number): number =>\n Math.round(surface + (to - surface) * share);\n return primary.every((p, i) => {\n for (let surface = 0; surface <= 255; surface += 1) {\n if (mixed(surface, p, 0.08) === bg[i] && mixed(surface, p, 0.3) === line[i]) return true;\n }\n return false;\n });\n}\n\n/**\n * Whether a badge list is a default DeloPay shipped rather than something the\n * merchant configured.\n *\n * Stock means the two stock badges — `secure` / \"Secure\", then `ssl` /\n * \"256-bit SSL\" — in a colouring DeloPay generated: the light default, the\n * dark default, or a theme colouring (`isThemeTintedBadgeColouring`, the same\n * one on both badges). Anything else was edited: a changed label, an added,\n * removed or reordered badge, a recolour, and an empty list — a merchant who\n * removed both badges chose to show nothing.\n */\nexport function isDefaultBadgeSet(badges: readonly TrustBadge[]): boolean {\n if (badges.length !== DEFAULT_BADGES.length) return false;\n const sameContent = badges.every(\n (badge, i) => badge.id === DEFAULT_BADGES[i]?.id && badge.label === DEFAULT_BADGES[i]?.label,\n );\n if (!sameContent) return false;\n\n const colouring = (set: readonly TrustBadge[]): string =>\n set\n .map((b) => [b.textColor, b.backgroundColor, b.borderColor ?? ''].join('|').toLowerCase())\n .join('/');\n const mine = colouring(badges);\n if (mine === colouring(DEFAULT_BADGES) || mine === colouring(DEFAULT_BADGES_DARK)) return true;\n\n // A theme gave both badges one colouring, border included.\n const [first] = badges;\n const border = first?.borderColor;\n if (!first || !border) return false;\n const same = (a: string | null, b: string): boolean =>\n (a ?? '').toLowerCase() === b.toLowerCase();\n return (\n badges.every(\n (b) =>\n same(b.textColor, first.textColor) &&\n same(b.backgroundColor, first.backgroundColor) &&\n same(b.borderColor, border),\n ) && isThemeTintedBadgeColouring(first.textColor, first.backgroundColor, border)\n );\n}\n\n/**\n * Decide a shop's badges and notices from what it has saved.\n *\n * `null` means the key is absent from what was saved (or unreadable). The\n * rule, in order:\n *\n * 1. Notices saved → they decide; badges are whatever was saved (none if\n * absent). Every save since notices exist writes the key, so from a shop's\n * first save on this is the only branch it takes — which is what makes\n * \"removed every notice\" stick instead of re-migrating to the defaults.\n * 2. No notices, and no badges or the stock badges → the badges go and the\n * default notices come in. This is every shop that never touched its trust\n * row.\n * 3. No notices, and badges the merchant configured → they stay exactly as\n * they are, and no notices are added: a shop that designed its own trust\n * row keeps it, and one that removed it keeps it removed.\n *\n * Decode-time only. Nothing is written until the merchant saves.\n */\nexport function resolveNoticesAndBadges(\n savedBadges: TrustBadge[] | null,\n savedNotices: CheckoutNotice[] | null,\n): { trustBadges: TrustBadge[]; notices: CheckoutNotice[] } {\n if (savedNotices !== null) {\n return { trustBadges: savedBadges ?? [], notices: savedNotices };\n }\n if (savedBadges === null || isDefaultBadgeSet(savedBadges)) {\n return { trustBadges: [], notices: defaultNotices() };\n }\n return { trustBadges: savedBadges, notices: [] };\n}\n\n// --- Method sections: order and captions -------------------------\n//\n// Two branding fields for the checkout's payment-method groups: the order they\n// render in, and the merchant's own name for each. A section's identity is a\n// key, and a key with no caption prints as itself.\n\nconst METHOD_SECTION_ORDER_KEY = 'methodSectionOrder';\nconst METHOD_SECTION_LABELS_KEY = 'methodSectionLabels';\n\n/** Inclusive bounds of one section's order number. */\nexport const MIN_SECTION_ORDER = 1;\nexport const MAX_SECTION_ORDER = 100;\n\n/** Ceiling on one caption. */\nexport const MAX_SECTION_LABEL_LENGTH = 120;\n\nexport interface MethodSectionSpec {\n readonly id: string;\n /** `sections.*` translation key, used when uncaptioned. */\n readonly labelKey: string;\n readonly order: number;\n}\n\n/**\n * Every known section, with its default number. Lower renders first.\n *\n * Array order is also the tie-break between two sections sharing a number, so\n * it is a display order rather than an arbitrary list.\n */\nexport const METHOD_SECTIONS: readonly MethodSectionSpec[] = [\n { id: 'card', labelKey: 'sections.card', order: 10 },\n { id: 'wallet', labelKey: 'sections.wallets', order: 20 },\n { id: 'bnpl', labelKey: 'sections.bnpl', order: 30 },\n { id: 'bank_redirect', labelKey: 'sections.onlineBanking', order: 40 },\n { id: 'bank_transfer', labelKey: 'sections.bankTransfer', order: 45 },\n { id: 'crypto', labelKey: 'sections.cryptocurrency', order: 50 },\n { id: 'game_items', labelKey: 'sections.gameItems', order: 60 },\n { id: 'voucher', labelKey: 'sections.vouchers', order: 70 },\n { id: 'gift_card', labelKey: 'sections.giftCards', order: 75 },\n { id: 'reward', labelKey: 'sections.rewards', order: 80 },\n { id: 'cash', labelKey: 'sections.cash', order: 90 },\n];\n\n/** Ids that mean an existing section under another name. */\nexport const SECTION_ALIASES: Readonly<Record<string, string>> = {\n card_redirect: 'card',\n};\n\n/** Where an id this list does not know goes: last, not first. */\nexport const UNKNOWN_SECTION_ORDER = MAX_SECTION_ORDER;\n\n/** Section id → order number. */\nexport type MethodSectionOrder = Record<string, number>;\n\n/** Section id → locale → the merchant's caption. */\nexport type MethodSectionLabels = Record<string, Record<string, string>>;\n\nexport function canonicalSectionId(category: string): string {\n return SECTION_ALIASES[category] ?? category;\n}\n\nexport function defaultMethodSectionOrder(): MethodSectionOrder {\n const order: MethodSectionOrder = {};\n for (const section of METHOD_SECTIONS) order[section.id] = section.order;\n return order;\n}\n\n/**\n * One order number, validated. `null` for anything that is not an integer in\n * range, so the caller can fall back to the default rather than clamp — a\n * `999` is a mistake, and \"last\" is a guess at what was meant.\n */\nexport function validSectionOrder(raw: unknown): number | null {\n if (typeof raw !== 'number' || !Number.isInteger(raw)) return null;\n if (raw < MIN_SECTION_ORDER || raw > MAX_SECTION_ORDER) return null;\n return raw;\n}\n\n/**\n * The order from a raw bag value. Total, like `decodeBadges`: anything\n * malformed gives the defaults, one bad number costs only its own section, an\n * unknown id is kept so a newer consumer can place it, and an alias folds onto\n * the section it names.\n */\nexport function decodeMethodSectionOrder(raw: string | undefined): MethodSectionOrder {\n const order = defaultMethodSectionOrder();\n if (raw === undefined) return order;\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return order;\n }\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return order;\n for (const [key, value] of Object.entries(parsed as Record<string, unknown>)) {\n const valid = validSectionOrder(value);\n if (valid === null) continue;\n order[canonicalSectionId(key)] = valid;\n }\n return order;\n}\n\nexport function encodeMethodSectionOrder(order: MethodSectionOrder): string {\n return JSON.stringify(order);\n}\n\n/**\n * Captions from a raw bag value. Tolerant for the same reason as the order,\n * and blank strings are dropped so an emptied field round-trips as absence.\n */\nexport function decodeMethodSectionLabels(raw: string | undefined): MethodSectionLabels {\n if (raw === undefined) return {};\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return {};\n }\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return {};\n const labels: MethodSectionLabels = {};\n for (const [section, byLocale] of Object.entries(parsed as Record<string, unknown>)) {\n if (!section || byLocale === null || typeof byLocale !== 'object' || Array.isArray(byLocale)) {\n continue;\n }\n const kept: Record<string, string> = {};\n for (const [locale, text] of Object.entries(byLocale as Record<string, unknown>)) {\n if (typeof text !== 'string') continue;\n const trimmed = text.trim();\n if (!trimmed) continue;\n kept[locale] = trimmed.slice(0, MAX_SECTION_LABEL_LENGTH);\n }\n if (Object.keys(kept).length > 0) labels[canonicalSectionId(section)] = kept;\n }\n return labels;\n}\n\n/**\n * Captions for the bag, or `null` when there are none — so an untouched\n * profile's bag is unchanged by this field existing, as `customFields` does.\n */\nexport function encodeMethodSectionLabels(labels: MethodSectionLabels): string | null {\n const cleaned: MethodSectionLabels = {};\n for (const [section, byLocale] of Object.entries(labels)) {\n const kept: Record<string, string> = {};\n for (const [locale, text] of Object.entries(byLocale)) {\n const trimmed = (text ?? '').trim();\n if (trimmed) kept[locale] = trimmed.slice(0, MAX_SECTION_LABEL_LENGTH);\n }\n if (Object.keys(kept).length > 0) cleaned[section] = kept;\n }\n return Object.keys(cleaned).length > 0 ? JSON.stringify(cleaned) : null;\n}\n\nfunction sectionCatalogueIndex(sectionId: string): number {\n const index = METHOD_SECTIONS.findIndex((section) => section.id === sectionId);\n return index === -1 ? METHOD_SECTIONS.length : index;\n}\n\nexport function sectionOrderOf(order: MethodSectionOrder, category: string): number {\n return order[canonicalSectionId(category)] ?? UNKNOWN_SECTION_ORDER;\n}\n\n/**\n * Compare two section ids: the merchant's number, then this list, then the id.\n *\n * The last two keys are properties of the build rather than of any response,\n * which is what stops two sections on one number swapping between renders.\n */\nexport function compareSections(order: MethodSectionOrder): (a: string, b: string) => number {\n return (a, b) => {\n const left = canonicalSectionId(a);\n const right = canonicalSectionId(b);\n const byOrder = sectionOrderOf(order, left) - sectionOrderOf(order, right);\n if (byOrder !== 0) return byOrder;\n const byCatalogue = sectionCatalogueIndex(left) - sectionCatalogueIndex(right);\n if (byCatalogue !== 0) return byCatalogue;\n return left < right ? -1 : left > right ? 1 : 0;\n };\n}\n\n/**\n * What to print above a section: the merchant's caption for this locale, then\n * their caption in any locale they wrote, then the caller's own name for a\n * section it knows, then the raw id.\n *\n * `translate` must return `undefined` for a key it has no entry for, or step 3\n * swallows the fall-through and prints `sections.<id>`.\n */\nexport function sectionLabel(\n labels: MethodSectionLabels,\n category: string,\n locale: string,\n knownKey: string | undefined,\n translate: (key: string) => string | undefined,\n): string {\n const id = canonicalSectionId(category);\n // `in` rather than `Object.hasOwn`: this package targets a lower `lib` than\n // its consumers, and the map is built by the decoder above.\n if (id in labels) {\n const captions = labels[id] as Record<string, string>;\n // Through `translationFor`, like every other localized branding field: it\n // folds case and walks parent locales, so `de-AT` finds `de`. An exact\n // lookup missed that and fell to the any-caption step below, which returns\n // whichever locale is first in the map — English, for a caption set written\n // `en` then `de`. A German buyer read an English heading.\n // Trimmed: `translationFor` accepts any non-empty string, and a\n // whitespace-only caption is not a caption. The decoder drops those, so\n // this only bites a caller that built the map itself.\n const matched = translationFor(captions, locale)?.trim();\n if (matched) return matched;\n for (const value of Object.values(captions)) {\n const any = value.trim();\n if (any) return any;\n }\n }\n if (knownKey) {\n const translated = translate(knownKey);\n if (translated) return translated;\n }\n return category;\n}\n\n/** Accept either the decoded map or the bag's JSON string. */\nfunction parseSectionOrderLoose(raw: unknown): MethodSectionOrder {\n if (typeof raw === 'string') return decodeMethodSectionOrder(raw);\n if (raw !== null && typeof raw === 'object' && !Array.isArray(raw)) {\n return decodeMethodSectionOrder(JSON.stringify(raw));\n }\n return defaultMethodSectionOrder();\n}\n\n/** Same, for captions. */\nfunction parseSectionLabelsLoose(raw: unknown): MethodSectionLabels {\n if (typeof raw === 'string') return decodeMethodSectionLabels(raw);\n if (raw !== null && typeof raw === 'object' && !Array.isArray(raw)) {\n return decodeMethodSectionLabels(JSON.stringify(raw));\n }\n return {};\n}\n\n/** The `sections.*` key for a known id, or `undefined`. */\nexport function knownSectionLabelKey(category: string): string | undefined {\n const id = canonicalSectionId(category);\n return METHOD_SECTIONS.find((section) => section.id === id)?.labelKey;\n}\n\nconst DEFAULT_BRANDING_BASE: Omit<\n CheckoutBranding,\n | keyof typeof LIGHT_PALETTE\n | 'trustBadges'\n | 'notices'\n | 'customFields'\n | 'methodSectionOrder'\n | 'methodSectionLabels'\n> = {\n displayName: '',\n logoUrl: '',\n tagline: '',\n // Logo + summary gradient OFF by default — an unconfigured DeloPay\n // checkout reads cleaner without a placeholder logo block, and the\n // gradient implies a primary tint the merchant hasn't yet picked.\n showLogo: false,\n logoShape: 'rounded',\n logoSize: 'md',\n\n fontFamily: 'inter',\n headingWeight: 'semibold',\n\n radiusSurface: 'medium',\n radiusInput: 'medium',\n radiusButton: 'medium',\n radiusBadge: 'pill',\n surfaceStyle: 'elevated',\n surfacePadding: 'comfortable',\n verticalGap: 'comfortable',\n inputSize: 'md',\n buttonSize: 'md',\n\n // Disclosure on by default: with provider-scoped pricing the tile is where\n // the buyer chooses between prices, and a price they cannot see is one they\n // find out about on the statement.\n showSurcharge: true,\n surchargePosition: 'trailing',\n // The button is the surface a buyer recognises fastest; it leads its section\n // unless the merchant says otherwise.\n nativeElementPosition: 'top',\n // Side by side — see the field.\n nativeElementStacked: false,\n surchargeStyle: 'badge',\n surchargeSize: 'sm',\n surchargeShape: 'pill',\n surchargeBorderWidth: 'thin',\n surchargeBorderStyle: 'solid',\n surchargeWeight: 'medium',\n surchargeSign: 'always',\n surchargeUppercase: false,\n // Named, not bare. A tile that reads \"-EUR 2.50\" beside a brand name is a\n // number with no subject — buyers read it as the price, not as a change to\n // it. \"Discount -EUR 2.50\" needs no interpreting, and the word is what makes\n // the default configuration legible without the merchant touching anything.\n surchargeLabel: 'labelled',\n // The two directions default differently on purpose, which is the whole\n // reason they are two settings. A fee is something a buyer acts on in money,\n // so it leads with money and says nothing else. A saving is something worth\n // advertising, and the share is the persuasive half of it — \"-5.1% (EUR\n // 2.50)\" sells what \"-EUR 2.50\" merely states, and the amount is still right\n // there beside it.\n surchargeFigure: 'amount',\n discountFigure: 'percentThenAmount',\n // Empty: the checkout's own localized words are the default, in every\n // language it ships. A merchant fills these in only to say it differently.\n surchargeWordTranslations: {},\n discountWordTranslations: {},\n // amber-700 / emerald-700, not the 600s: the `plain` style renders the\n // disclosure as coloured TEXT, so it is bound by `WCAG_AA_TEXT` (4.5) rather\n // than by the 3:1 a coloured shape would be, and the 600s come to 3.19 and\n // 3.77 against the default white surface. These are 5.02 and 5.48, pinned by\n // tests. Far enough apart to read as opposite news at a glance rather than as\n // two shades of \"extra\".\n surchargeColor: '#b45309',\n discountColor: '#047857',\n\n layout: 'split',\n summaryPosition: 'left',\n showOrderSummary: true,\n summaryGradient: false,\n showTotal: true,\n totalLabel: 'Total',\n showCurrencyCode: false,\n showOrderItems: true,\n cancelLinkEnabled: true,\n cancelLinkPosition: 'top',\n cancelLinkStyle: 'link',\n\n // Each flat field keeps its meaning: what the merchant wrote, used in every\n // locale that carries no override. Empty maps therefore change nothing for a\n // profile saved before translations existed.\n headerText: '',\n headerTextTranslations: {},\n payButtonLabel: '',\n payButtonLabelTranslations: {},\n cardTermsMessage: '',\n cardTermsMessageTranslations: {},\n footerText: '',\n footerTextTranslations: {},\n supportEmail: '',\n\n paymentLayout: 'tabs',\n labelStyle: 'above',\n showPoweredBy: true,\n\n // Every one of these defaults to what the Airwallex pane already did before\n // the section existed, so a merchant who never opens it sees no change:\n // empty preset (defer to the connector account), an outlined box, 16px /\n // 500 type, no focus ring, the browser's own autofill highlight, no valid\n // tint, no marks. The single deliberate change of behaviour is not here —\n // it is the fallback at the END of `resolveAirwallexCardPreset`, which\n // moves a shop that configured NOTHING from the combined row to the\n // labelled split form.\n airwallexCardPreset: '',\n // Off. With this on, no buyer can pay by card on the shop.\n airwallexHideCard: false,\n // Off: the section is named, like every other section on the surface.\n airwallexHideCardTitle: false,\n airwallexFieldChrome: 'outlined',\n airwallexLabelStyle: '',\n airwallexFieldFontSize: 'md',\n airwallexFieldWeight: 'medium',\n airwallexFocusRing: 'none',\n airwallexAutofill: 'system',\n airwallexValidTint: false,\n airwallexNetworkMarks: false,\n\n // Every card-form field below starts on what its pane drew before the\n // setting existed, so a merchant who never opens a section sees no change.\n stripeTheme: 'auto',\n stripeInputs: 'spaced',\n stripeLabels: 'above',\n stripeSpacing: 'comfortable',\n stripeFieldFontSize: 'md',\n stripeFieldWeight: 'medium',\n stripeFocusRing: 'strong',\n stripeDisableAnimations: false,\n paypalCardLayout: 'split',\n paypalLabelStyle: 'above',\n paypalFieldChrome: 'outlined',\n mollieFieldChrome: 'outlined',\n paypalFieldFontSize: 'md',\n mollieFieldFontSize: 'md',\n paypalFieldWeight: 'regular',\n mollieFieldWeight: 'regular',\n paypalFocusRing: 'strong',\n mollieFocusRing: 'strong',\n paypalValidTint: false,\n epayoutsCardLayout: 'split',\n epayoutsLabelStyle: 'above',\n epayoutsFieldChrome: 'outlined',\n epayoutsFieldFontSize: 'md',\n epayoutsFieldWeight: 'regular',\n epayoutsFocusRing: 'strong',\n epayoutsValidTint: false,\n nomupayFormStyle: 'plain',\n nomupayShowLabels: true,\n nomupayShowPlaceholders: true,\n nomupayShowCvvHint: false,\n nomupayFieldChrome: 'outlined',\n nomupayFieldFontSize: 'md',\n nomupayFocusRing: 'none',\n nomupayApplePayButtonStyle: 'auto',\n nomupayApplePayButtonType: 'pay',\n nomupayGooglePayButtonColor: 'auto',\n nomupayGooglePayButtonType: 'pay',\n micropaymentFieldChrome: 'outlined',\n micropaymentFieldFontSize: 'md',\n micropaymentFieldWeight: 'regular',\n micropaymentFocusRing: 'strong',\n whopCardPreset: 'card_stacked',\n whopAccentColor: 'auto',\n whopGrayColor: 'auto',\n whopBillingDetails: 'minimal',\n whopSeparated: false,\n whopEmailLabel: 'above',\n whopFieldChrome: 'outlined',\n whopFieldFontSize: 'md',\n whopFieldWeight: 'regular',\n whopFocusRing: 'strong',\n whopRadius: 'checkout',\n whopShadow: 'soft',\n whopMethodIcons: true,\n whopSelection: 'radio_tint',\n\n customCss: '',\n // The Enigma Vault card form: the Stripe-like template.\n ...DEFAULT_ENIGMA_CARD_FORM,\n};\n\nexport const DEFAULT_BRANDING: CheckoutBranding = {\n ...DEFAULT_BRANDING_BASE,\n ...LIGHT_PALETTE,\n // No badges by default any more — notices took their place.\n // `DEFAULT_BADGES` stays exported because `isDefaultBadgeSet` still has to\n // recognise the pair on shops saved before.\n trustBadges: [],\n notices: defaultNotices(),\n customFields: [],\n methodSectionOrder: defaultMethodSectionOrder(),\n methodSectionLabels: {},\n};\n\n// Dark counterpart to DEFAULT_BRANDING. Same form-only fields stay empty\n// (logo / display name / tagline / copy) — only visual tokens diverge.\n// Palette mirrors the design-guidelines dark ramp:\n// - background = slate-950, surface = slate-900 → soft contrast.\n// - text = slate-200, heading = slate-50 → AA+ contrast on the surface.\n// - muted = slate-400, border = slate-800 → chrome that fades into the bg.\n// - accentText = primary-400, button bg = brand blue → brand pops on dark\n// where the light theme's near-black navy CTA would disappear.\n// - surfaceStyle = 'flat' because soft drop-shadows don't read on dark\n// surfaces; the existing 'elevated' shadow tokens are tuned for light.\nexport const DEFAULT_BRANDING_DARK: CheckoutBranding = {\n ...DEFAULT_BRANDING_BASE,\n primary: '#1E4FEB',\n background: '#020617',\n surface: '#0f172a',\n text: '#e2e8f0',\n heading: '#f8fafc',\n muted: '#94a3b8',\n border: '#1e293b',\n accentText: '#60a5fa',\n buttonBackground: '#1E4FEB',\n buttonText: '#ffffff',\n surfaceStyle: 'flat',\n // amber-400 / emerald-400: the 700s above are far too dark to read on\n // slate-900, and this pair is the same news in the same order at the light\n // end of the ramp — 10.69 and 9.29 against the dark surface, also pinned.\n surchargeColor: '#fbbf24',\n discountColor: '#34d399',\n trustBadges: [],\n notices: defaultNotices(),\n customFields: [],\n methodSectionOrder: defaultMethodSectionOrder(),\n methodSectionLabels: {},\n};\n\n// Back-compat alias. Prefer `DEFAULT_BRANDING` directly.\nexport function defaultBranding(): CheckoutBranding {\n return cloneBranding(DEFAULT_BRANDING);\n}\n\n// Deep-ish clone — needed because the form mutates state reactively and we\n// don't want shared TrustBadge / CheckoutCustomField object refs across the\n// loaded/edit/default snapshots. Spread is shallow; array elements would\n// otherwise be shared between snapshots, breaking reset.\nexport function cloneBranding(b: CheckoutBranding): CheckoutBranding {\n return {\n ...b,\n trustBadges: b.trustBadges.map((badge) => ({ ...badge })),\n notices: b.notices.map(cloneNotice),\n customFields: b.customFields.map(cloneCustomField),\n methodSectionOrder: { ...b.methodSectionOrder },\n methodSectionLabels: Object.fromEntries(\n Object.entries(b.methodSectionLabels).map(([id, byLocale]) => [id, { ...byLocale }]),\n ),\n // Copied, not shared. A spread alone would leave the clone pointing at the\n // original's maps, and the dashboard edits a clone precisely so the form\n // can be abandoned without touching what is saved.\n surchargeWordTranslations: { ...b.surchargeWordTranslations },\n discountWordTranslations: { ...b.discountWordTranslations },\n headerTextTranslations: { ...b.headerTextTranslations },\n payButtonLabelTranslations: { ...b.payButtonLabelTranslations },\n cardTermsMessageTranslations: { ...b.cardTermsMessageTranslations },\n footerTextTranslations: { ...b.footerTextTranslations },\n };\n}\n\nexport function cloneCustomField(f: CheckoutCustomField): CheckoutCustomField {\n return {\n ...f,\n labelTranslations: { ...f.labelTranslations },\n placeholderTranslations: { ...f.placeholderTranslations },\n helpTextTranslations: { ...f.helpTextTranslations },\n options: f.options.map((o) => ({ ...o, labelTranslations: { ...o.labelTranslations } })),\n visibility: {\n ...f.visibility,\n conditions: f.visibility.conditions.map((c) => ({ ...c })),\n },\n };\n}\n\n// --- Sanitizer ----------------------------------------------------------\n\n// Hard cap on the persisted custom CSS payload. Mirrors the editor's\n// validation; oversized input is dropped to null rather than truncated,\n// since a half-truncated rule is worse than no rule.\nexport const CUSTOM_CSS_MAX_LENGTH = 50_000;\n\n// Strip CSS tokens that turn a stylesheet into a delivery vector before\n// handing the merchant's input to the renderer. The list isn't exhaustive\n// — it's the everyday surface area:\n//\n// - `</style` would let injected text break out of the <style> block and\n// parse as HTML/JS. Replaced with a benign token (not removed) so\n// `</styled-tag` (unlikely but possible inside a content: string)\n// doesn't silently merge into surrounding text.\n// - `@import` would let the merchant pull in a remote stylesheet on\n// every buyer page-load (analytics by side-channel; possible buyer-IP\n// leak).\n// - `expression(…)` was a legacy IE construct that ran JS from CSS.\n// - `behavior:` and `-moz-binding:` ditto for IE/old-Gecko.\n// - `javascript:` URLs in url(...) execute on resource load in some\n// browsers/contexts.\n//\n// Anything else passes through. The merchant can still write whatever\n// declarations they like (background images, gradients, transforms,\n// keyframes, container queries, …).\nexport function sanitizeCustomCss(raw: string | null | undefined): string | null {\n if (typeof raw !== 'string') return null;\n const trimmed = raw.trim();\n if (trimmed.length === 0) return null;\n if (trimmed.length > CUSTOM_CSS_MAX_LENGTH) return null;\n\n let out = trimmed;\n out = out.replace(/<\\/style/gi, '<\\\\/style');\n out = out.replace(/@import\\b[^;]*;?/gi, '');\n out = out.replace(/expression\\s*\\(/gi, '/* expression( */');\n out = out.replace(/(^|[^a-z-])behavior\\s*:/gi, '$1/* behavior: */');\n out = out.replace(/-moz-binding\\s*:/gi, '/* -moz-binding: */');\n out = out.replace(/url\\s*\\(\\s*[\"']?\\s*javascript:/gi, 'url(invalid:');\n return out;\n}\n\n// --- Codec --------------------------------------------------------------\n\n// Structural shape the decoder reads. Both `CheckoutDetails` (public buyer\n// payload) and `BusinessPaymentLinkConfig` (merchant config request shape)\n// satisfy this via duck typing — they each fill some of these and leave the\n// rest undefined. `merchant_*` and `seller_*`/`logo` are aliases for the\n// same API field, surfaced under different names by the two payloads.\nexport interface BrandingSource {\n // Identity (one or the other, depending on payload shape)\n merchant_name?: string | null;\n seller_name?: string | null;\n merchant_logo?: string | null;\n logo?: string | null;\n merchant_description?: string | null;\n\n // Visual\n theme?: string | null;\n background_colour?: string | null;\n payment_button_colour?: string | null;\n payment_button_text_colour?: string | null;\n\n // Copy\n payment_form_header_text?: string | null;\n payment_button_text?: string | null;\n custom_message_for_card_terms?: string | null;\n\n // Footer\n branding_visibility?: boolean | null;\n\n // Stripe\n sdk_layout?: string | null;\n payment_form_label_type?: string | null;\n\n // The bag for everything else\n sdk_ui_rules?: Record<string, Record<string, string> | null | undefined> | null;\n}\n\nconst BRANDING_GROUP_KEY = 'branding';\n\nconst ALL_FONT_FAMILIES: readonly FontFamily[] = [\n 'inter',\n 'system',\n 'serif',\n 'mono',\n 'roboto',\n 'poppins',\n 'manrope',\n 'dm-sans',\n 'space-grotesk',\n 'plex-sans',\n 'work-sans',\n 'open-sans',\n 'lora',\n 'playfair',\n 'plex-mono',\n 'jetbrains-mono',\n];\n\nconst ALL_RADII: readonly CornerRadius[] = ['square', 'small', 'medium', 'large', 'pill'];\nconst NON_PILL_RADII: readonly NonPillRadius[] = ['square', 'small', 'medium', 'large'];\n\nfunction pickEnum<T extends string>(value: unknown, allowed: readonly T[], fallback: T): T {\n if (typeof value !== 'string') return fallback;\n return (allowed as readonly string[]).includes(value) ? (value as T) : fallback;\n}\n\n/**\n * `pickEnum` for a field whose \"unset\" state is the empty string.\n *\n * Anything not on the list — absent, blank, or a token this build has not\n * heard of — decodes to `''`, which every consumer reads as \"defer\". That is\n * the difference between this and `pickEnum`: there the unknown becomes a\n * concrete value and starts overriding whatever it was deferring to.\n */\nfunction pickEnumOrEmpty<T extends string>(value: unknown, allowed: readonly T[]): T | '' {\n if (typeof value !== 'string') return '';\n return (allowed as readonly string[]).includes(value) ? (value as T) : '';\n}\n\nfunction parseBool(value: unknown, fallback: boolean): boolean {\n if (typeof value === 'boolean') return value;\n if (value === 'true') return true;\n if (value === 'false') return false;\n return fallback;\n}\n\nfunction s(value: string | null | undefined): string {\n return typeof value === 'string' ? value : '';\n}\n\n// Decode the JSON-encoded trust badges stored under\n// `sdk_ui_rules.branding.trustBadges`. Tolerant: a malformed payload,\n// missing fields, or wrong types fall through to null so the caller can\n// substitute the default badge set. An explicit empty array means \"no\n// badges\" (we honor it — merchants who hide the row need a way to express\n// that).\nexport function decodeBadges(raw: string | undefined): TrustBadge[] | null {\n if (raw === undefined) return null;\n try {\n const parsed: unknown = JSON.parse(raw);\n if (!Array.isArray(parsed)) return null;\n return parsed\n .filter((b): b is Record<string, unknown> => !!b && typeof b === 'object')\n .map((b, i) => ({\n id: typeof b['id'] === 'string' && b['id'] ? (b['id'] as string) : `badge-${i}`,\n label: typeof b['label'] === 'string' ? (b['label'] as string) : '',\n textColor: typeof b['textColor'] === 'string' ? (b['textColor'] as string) : '#0f172a',\n backgroundColor:\n typeof b['backgroundColor'] === 'string' ? (b['backgroundColor'] as string) : '#f1f5f9',\n borderColor:\n typeof b['borderColor'] === 'string' && b['borderColor']\n ? (b['borderColor'] as string)\n : null,\n }))\n .filter((b) => b.label.length > 0);\n } catch {\n return null;\n }\n}\n\nexport function encodeBadges(badges: TrustBadge[]): string {\n return JSON.stringify(\n badges.map((b) => ({\n id: b.id,\n label: b.label,\n textColor: b.textColor,\n backgroundColor: b.backgroundColor,\n ...(b.borderColor ? { borderColor: b.borderColor } : {}),\n })),\n );\n}\n\n// --- Notices codec --------------------------------------------\n\n/** A notice id is code-shaped: it keys a drag, never a buyer's eyes. */\nconst NOTICE_ID_MAX_LENGTH = 40;\n\nfunction capNoticeText(value: string): string {\n return Array.from(value).slice(0, NOTICE_LABEL_MAX_LENGTH).join('');\n}\n\n/**\n * Normalize a list of notices from any source — the bag, an import file.\n *\n * Total, like `decodeBadges`: every buyer sees these, so a malformed entry\n * degrades to a smaller list, never to a broken page.\n *\n * - not an object → dropped;\n * - unknown section → `summary`; unknown icon → `NOTICE_ICON_FALLBACK`;\n * - id cleaned to `[A-Za-z0-9_-]`, a missing or repeated one replaced, so the\n * editor can track every row across a drag;\n * - text cut to `NOTICE_LABEL_MAX_LENGTH` characters, blank overrides dropped;\n * - a notice with no text in any language → dropped (it would draw an icon\n * with nothing beside it);\n * - past `NOTICES_PER_SECTION` in its section → dropped, first come first\n * kept, so what is stored is what is drawn.\n */\nfunction normalizeNotices(list: readonly unknown[]): CheckoutNotice[] {\n const seen = new Set<string>();\n const perSection = new Map<NoticeSection, number>();\n const out: CheckoutNotice[] = [];\n\n list.forEach((raw, index) => {\n if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return;\n const src = raw as Record<string, unknown>;\n\n const label = typeof src['label'] === 'string' ? capNoticeText(src['label']) : '';\n const labelTranslations: CustomFieldTranslations = {};\n for (const [locale, text] of Object.entries(parseTranslations(src['labelTranslations']))) {\n labelTranslations[locale] = capNoticeText(text);\n }\n if (label.trim().length === 0 && Object.keys(labelTranslations).length === 0) return;\n\n const section = pickEnum<NoticeSection>(src['section'], NOTICE_SECTIONS, 'summary');\n const used = perSection.get(section) ?? 0;\n if (used >= NOTICES_PER_SECTION) return;\n perSection.set(section, used + 1);\n\n let id =\n typeof src['id'] === 'string'\n ? src['id'].replace(/[^A-Za-z0-9_-]/g, '').slice(0, NOTICE_ID_MAX_LENGTH)\n : '';\n if (!id || seen.has(id)) id = `notice-${index + 1}`;\n while (seen.has(id)) id = `${id}x`;\n seen.add(id);\n\n out.push({\n id,\n section,\n icon: isNoticeIcon(src['icon']) ? src['icon'] : NOTICE_ICON_FALLBACK,\n label,\n labelTranslations,\n });\n });\n\n return out;\n}\n\n/**\n * Decode `sdk_ui_rules.branding.notices`.\n *\n * `null` when the key is absent or not a JSON array — \"this shop has no say\n * about notices\", which `resolveNoticesAndBadges` turns into the migration.\n * An empty array is a say: the merchant removed every notice.\n */\nexport function decodeNotices(raw: string | undefined): CheckoutNotice[] | null {\n if (raw === undefined) return null;\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return null;\n }\n return Array.isArray(parsed) ? normalizeNotices(parsed) : null;\n}\n\n/** The import file's form: an array inline rather than a JSON string. */\nexport function parseNoticesLoose(raw: unknown): CheckoutNotice[] | null {\n if (typeof raw === 'string') return decodeNotices(raw);\n return Array.isArray(raw) ? normalizeNotices(raw) : null;\n}\n\n/**\n * Encode notices for the bag. Always a JSON array, `[]` included: the key's\n * presence is what tells a later decode that the shop has decided, so it must\n * be written even when there is nothing in it.\n */\nexport function encodeNotices(notices: readonly CheckoutNotice[]): string {\n return JSON.stringify(\n notices.map((n) => {\n const translations = Object.entries(n.labelTranslations).filter(\n ([, text]) => text.trim().length > 0,\n );\n return {\n id: n.id,\n section: n.section,\n icon: n.icon,\n label: n.label,\n ...(translations.length > 0 ? { labelTranslations: Object.fromEntries(translations) } : {}),\n };\n }),\n );\n}\n\n/**\n * A notice's text in the buyer's locale: exact locale, then its base\n * language, then the default text — the order every other piece of merchant\n * copy resolves in (`checkoutCopy`, `customFieldText`).\n *\n * `''` when the notice has no text for this locale: a notice written only in\n * some languages, with no default, is one the merchant shows only in those\n * languages (the POC's \"empty means: not in this language\"). It is not a\n * notice to draw without words — use `shownNotices`, which leaves it out.\n */\nexport function noticeText(notice: CheckoutNotice, locale?: string): string {\n return translationFor(notice.labelTranslations, locale) ?? notice.label;\n}\n\n/**\n * The notices one section draws, in order, capped at `NOTICES_PER_SECTION`.\n * The decoder already caps; this caps again for state that never went through\n * it, such as the customizer's unsaved edits in the live preview.\n */\nexport function noticesIn(\n notices: readonly CheckoutNotice[],\n section: NoticeSection,\n): CheckoutNotice[] {\n return notices.filter((n) => n.section === section).slice(0, NOTICES_PER_SECTION);\n}\n\n/** One notice as a buyer sees it: the notice, and its text in their locale. */\nexport interface ShownNotice {\n notice: CheckoutNotice;\n text: string;\n}\n\n/**\n * What one section draws for a buyer: its notices (capped, as `noticesIn`),\n * each with its text in `locale`, leaving out every notice with no text there.\n *\n * The one place that decides it, so no renderer can draw an icon with nothing\n * beside it. A notice written only in German is simply absent for an English\n * buyer — the cap is applied first, as the decoder applies it, so what a\n * merchant stored in a section is what can ever be drawn from it.\n */\nexport function shownNotices(\n notices: readonly CheckoutNotice[],\n section: NoticeSection,\n locale?: string,\n): ShownNotice[] {\n return noticesIn(notices, section)\n .map((notice) => ({ notice, text: noticeText(notice, locale).trim() }))\n .filter((entry) => entry.text.length > 0);\n}\n\n// --- Custom checkout fields codec ---------------------------------------\n\nexport const CUSTOM_FIELDS_MAX = 20;\n// Metadata keys: start with a letter, then letters/digits/underscore/dash.\n// Keeps keys safe for every downstream metadata consumer (dashboards,\n// exports, PSP forwarding).\nexport const CUSTOM_FIELD_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,39}$/;\n\nexport const ALL_CUSTOM_FIELD_TYPES: readonly CustomFieldType[] = [\n 'text',\n 'textarea',\n 'password',\n 'email',\n 'select',\n 'checkbox',\n];\n\n// The two values a checkbox field ever submits. Kept as strings because the\n// whole metadata bag is `Record<string, string>` on the wire.\nexport const CHECKBOX_CHECKED = 'true';\nexport const CHECKBOX_UNCHECKED = 'false';\n\n/** Whether a stored/submitted checkbox value counts as ticked. Tolerant of\n * case and padding so a value round-tripped through a shop integration\n * ('True', ' true ') still reads correctly. */\nexport function isCheckboxChecked(value: string | null | undefined): boolean {\n return typeof value === 'string' && value.trim().toLowerCase() === CHECKBOX_CHECKED;\n}\n\n/** Types whose value is free text, so length bounds and a placeholder apply.\n * `select` and `checkbox` are choice controls and have neither. */\nexport function customFieldIsTextLike(type: CustomFieldType): boolean {\n return type !== 'select' && type !== 'checkbox';\n}\n\n// Rule-builder vocabulary. Kept next to the codec so the editor, the\n// evaluator and the Rust mirror all read from one list.\nexport const CUSTOM_FIELD_CONDITIONS_MAX = 10;\n\nexport const ALL_CUSTOM_FIELD_CONDITION_SOURCES: readonly CustomFieldConditionSource[] = [\n 'metadata',\n 'currency',\n 'amount',\n];\n\nexport const ALL_CUSTOM_FIELD_OPERATORS: readonly CustomFieldOperator[] = [\n 'equals',\n 'not_equals',\n 'contains',\n 'not_contains',\n 'starts_with',\n 'ends_with',\n 'in',\n 'not_in',\n 'exists',\n 'not_exists',\n 'gt',\n 'gte',\n 'lt',\n 'lte',\n];\n\n// Which operators make sense per source. Currency is a closed 3-letter set,\n// so substring/numeric operators would only ever confuse; amount is numeric,\n// so string operators don't apply. Metadata is free-form and gets all of them.\nexport const CUSTOM_FIELD_OPERATORS_BY_SOURCE: Record<\n CustomFieldConditionSource,\n readonly CustomFieldOperator[]\n> = {\n metadata: ALL_CUSTOM_FIELD_OPERATORS,\n currency: ['equals', 'not_equals', 'in', 'not_in'],\n amount: ['equals', 'not_equals', 'gt', 'gte', 'lt', 'lte'],\n};\n\n// Operators that ignore the right-hand operand — the editor hides the value\n// input for these, and validation must not demand a value.\nexport const CUSTOM_FIELD_VALUELESS_OPERATORS: readonly CustomFieldOperator[] = [\n 'exists',\n 'not_exists',\n];\n\nexport function customFieldOperatorTakesValue(operator: CustomFieldOperator): boolean {\n return !CUSTOM_FIELD_VALUELESS_OPERATORS.includes(operator);\n}\n\n// The operator a condition falls back to when its source changes and the\n// current operator isn't valid for the new source.\nexport function defaultOperatorForSource(source: CustomFieldConditionSource): CustomFieldOperator {\n return CUSTOM_FIELD_OPERATORS_BY_SOURCE[source][0] ?? 'equals';\n}\n\nexport function defaultCustomFieldVisibility(): CustomFieldVisibility {\n return { mode: 'always', match: 'all', conditions: [] };\n}\n\nfunction parseTranslations(raw: unknown): CustomFieldTranslations {\n // The branding bag stores every value as a string, so a map persisted there\n // arrives as JSON; an import file and a custom field carry it inline. Both\n // reach this, and a string that is not JSON is simply not a map.\n let value = raw;\n if (typeof value === 'string') {\n try {\n value = JSON.parse(value) as unknown;\n } catch {\n return {};\n }\n }\n if (!value || typeof value !== 'object' || Array.isArray(value)) return {};\n const out: CustomFieldTranslations = {};\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n // Own properties only: a persisted key of `__proto__` or `constructor`\n // must not reach the object being built, and `Object.entries` already\n // gives own enumerable keys only — the length check is what drops a blank\n // override, which means \"no override\" rather than \"render nothing\".\n if (typeof v === 'string' && v.trim().length > 0) out[k] = v;\n }\n return out;\n}\n\n/**\n * A translations map for the branding bag, or `undefined` when there is\n * nothing to store.\n *\n * Omitting the key rather than writing `{}` keeps the bag of a merchant who\n * never opened the translations strip byte-identical to what it was before\n * these fields existed.\n */\nfunction encodeTranslations(map: CustomFieldTranslations): string | undefined {\n const entries = Object.entries(map).filter(([, v]) => v.trim().length > 0);\n return entries.length > 0 ? JSON.stringify(Object.fromEntries(entries)) : undefined;\n}\n\n// Normalize one persisted condition. Total: an unusable source/operator\n// falls back rather than dropping the row, so a rule authored by a newer\n// dashboard never silently becomes \"always visible\" on an older\n// decoder — it becomes a stricter, still-evaluable rule.\nfunction normalizeCondition(raw: unknown, index: number): CustomFieldCondition | null {\n if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;\n const c = raw as Record<string, unknown>;\n const source = pickEnum<CustomFieldConditionSource>(\n c['source'],\n ALL_CUSTOM_FIELD_CONDITION_SOURCES,\n 'metadata',\n );\n const allowed = CUSTOM_FIELD_OPERATORS_BY_SOURCE[source];\n const operator = pickEnum<CustomFieldOperator>(\n c['operator'],\n allowed,\n defaultOperatorForSource(source),\n );\n const rawValue = c['value'];\n return {\n id: typeof c['id'] === 'string' && c['id'] ? (c['id'] as string) : `cond-${index}`,\n source,\n // Only metadata conditions carry a key; drop anything else so the\n // encoded form stays canonical.\n key: source === 'metadata' && typeof c['key'] === 'string' ? c['key'].trim() : '',\n operator,\n value:\n typeof rawValue === 'string'\n ? rawValue\n : typeof rawValue === 'number' || typeof rawValue === 'boolean'\n ? String(rawValue)\n : '',\n };\n}\n\nfunction normalizeVisibility(raw: unknown): CustomFieldVisibility {\n if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return defaultCustomFieldVisibility();\n const v = raw as Record<string, unknown>;\n const conditions: CustomFieldCondition[] = Array.isArray(v['conditions'])\n ? (v['conditions'] as unknown[])\n .slice(0, CUSTOM_FIELD_CONDITIONS_MAX)\n .map(normalizeCondition)\n .filter((c): c is CustomFieldCondition => c !== null)\n : [];\n return {\n mode: pickEnum<'always' | 'match'>(v['mode'], ['always', 'match'], 'always'),\n match: pickEnum<'all' | 'any'>(v['match'], ['all', 'any'], 'all'),\n conditions,\n };\n}\n\nfunction parseBoundedInt(raw: unknown): number | null {\n const n = typeof raw === 'number' ? raw : typeof raw === 'string' ? Number(raw) : NaN;\n if (!Number.isInteger(n) || n < 0) return null;\n return Math.min(n, 5000);\n}\n\n// Normalize one persisted/imported field object. Total: anything malformed\n// falls back per-property; returns null only when there is no usable key.\nfunction normalizeCustomField(raw: unknown, index: number): CheckoutCustomField | null {\n if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;\n const f = raw as Record<string, unknown>;\n const key = typeof f['key'] === 'string' ? f['key'].trim() : '';\n if (!CUSTOM_FIELD_KEY_PATTERN.test(key)) return null;\n\n const type = pickEnum<CustomFieldType>(f['type'], ALL_CUSTOM_FIELD_TYPES, 'text');\n\n const options: CustomFieldOption[] =\n type === 'select' && Array.isArray(f['options'])\n ? (f['options'] as unknown[])\n .filter((o): o is Record<string, unknown> => !!o && typeof o === 'object')\n .map((o) => {\n const value = typeof o['value'] === 'string' ? o['value'] : '';\n return {\n value,\n label: typeof o['label'] === 'string' && o['label'] ? (o['label'] as string) : value,\n labelTranslations: parseTranslations(o['labelTranslations']),\n };\n })\n .filter((o) => o.value.length > 0)\n : [];\n\n // Length bounds are meaningless for choice controls; drop them at decode\n // so a field switched to checkbox/select can't carry stale bounds that\n // would then be validated against 'true'/'false'.\n const textLike = customFieldIsTextLike(type);\n const minLength = textLike ? parseBoundedInt(f['minLength']) : null;\n const maxLength = textLike ? parseBoundedInt(f['maxLength']) : null;\n\n // A checkbox default is a tick state, not free text: anything that isn't\n // truthy normalizes to unchecked, so the control can never start in a\n // third state.\n const rawDefault = typeof f['defaultValue'] === 'string' ? f['defaultValue'] : '';\n const defaultValue =\n type === 'checkbox'\n ? isCheckboxChecked(rawDefault)\n ? CHECKBOX_CHECKED\n : CHECKBOX_UNCHECKED\n : rawDefault;\n\n return {\n id: typeof f['id'] === 'string' && f['id'] ? (f['id'] as string) : `field-${index}`,\n key,\n type,\n label: typeof f['label'] === 'string' && f['label'] ? (f['label'] as string) : key,\n labelTranslations: parseTranslations(f['labelTranslations']),\n placeholder: typeof f['placeholder'] === 'string' ? (f['placeholder'] as string) : '',\n placeholderTranslations: parseTranslations(f['placeholderTranslations']),\n helpText: typeof f['helpText'] === 'string' ? (f['helpText'] as string) : '',\n helpTextTranslations: parseTranslations(f['helpTextTranslations']),\n required: parseBool(f['required'], false),\n enabled: parseBool(f['enabled'], true),\n minLength,\n // Guard inverted bounds at decode so consumers never see min > max.\n maxLength: maxLength !== null && minLength !== null && maxLength < minLength ? null : maxLength,\n defaultValue,\n options,\n visibility: normalizeVisibility(f['visibility']),\n };\n}\n\n// Parse an array of field objects (already JSON-parsed). Null when the\n// input isn't an array — callers fall back to \"no custom fields\". Duplicate\n// keys keep the first occurrence; the list is capped at CUSTOM_FIELDS_MAX.\nexport function parseCustomFieldsLoose(raw: unknown): CheckoutCustomField[] | null {\n if (!Array.isArray(raw)) return null;\n const seen = new Set<string>();\n const out: CheckoutCustomField[] = [];\n for (let i = 0; i < raw.length && out.length < CUSTOM_FIELDS_MAX; i++) {\n const field = normalizeCustomField(raw[i], i);\n if (!field || seen.has(field.key)) continue;\n seen.add(field.key);\n out.push(field);\n }\n return out;\n}\n\n// Decode the JSON-encoded custom fields stored under\n// `sdk_ui_rules.branding.customFields`. Tolerant like `decodeBadges`:\n// malformed payloads fall through to null.\nexport function decodeCustomFields(raw: string | undefined): CheckoutCustomField[] | null {\n if (raw === undefined) return null;\n try {\n return parseCustomFieldsLoose(JSON.parse(raw));\n } catch {\n return null;\n }\n}\n\nexport function encodeCustomFields(fields: CheckoutCustomField[]): string {\n const nonEmpty = (m: CustomFieldTranslations): CustomFieldTranslations | undefined => {\n const entries = Object.entries(m).filter(([, v]) => v.trim().length > 0);\n return entries.length > 0 ? Object.fromEntries(entries) : undefined;\n };\n return JSON.stringify(\n fields.map((f) => ({\n id: f.id,\n key: f.key,\n type: f.type,\n label: f.label,\n ...(nonEmpty(f.labelTranslations)\n ? { labelTranslations: nonEmpty(f.labelTranslations) }\n : {}),\n ...(f.placeholder ? { placeholder: f.placeholder } : {}),\n ...(nonEmpty(f.placeholderTranslations)\n ? { placeholderTranslations: nonEmpty(f.placeholderTranslations) }\n : {}),\n ...(f.helpText ? { helpText: f.helpText } : {}),\n ...(nonEmpty(f.helpTextTranslations)\n ? { helpTextTranslations: nonEmpty(f.helpTextTranslations) }\n : {}),\n ...(f.required ? { required: true } : {}),\n ...(f.enabled ? {} : { enabled: false }),\n // Length bounds only exist for free-text types; a choice control that\n // still carries them is stale state the decoder would drop anyway.\n ...(customFieldIsTextLike(f.type) && f.minLength !== null ? { minLength: f.minLength } : {}),\n ...(customFieldIsTextLike(f.type) && f.maxLength !== null ? { maxLength: f.maxLength } : {}),\n // A checkbox persists only \"starts ticked\"; unticked is the decoder's\n // default, so writing 'false' would be noise on every such field.\n ...(f.type === 'checkbox'\n ? isCheckboxChecked(f.defaultValue)\n ? { defaultValue: CHECKBOX_CHECKED }\n : {}\n : f.defaultValue\n ? { defaultValue: f.defaultValue }\n : {}),\n ...(f.type === 'select' ? { options: f.options } : {}),\n // Omitted for unconditional fields so the stored blob (and every\n // pre-feature payload) stays byte-identical to what it was.\n ...(f.visibility.mode === 'match' ? { visibility: encodeVisibility(f.visibility) } : {}),\n })),\n );\n}\n\nfunction encodeVisibility(v: CustomFieldVisibility): Record<string, unknown> {\n return {\n mode: v.mode,\n match: v.match,\n conditions: v.conditions.map((c) => ({\n id: c.id,\n source: c.source,\n ...(c.source === 'metadata' && c.key ? { key: c.key } : {}),\n operator: c.operator,\n ...(customFieldOperatorTakesValue(c.operator) && c.value ? { value: c.value } : {}),\n })),\n };\n}\n\n// --- Conditional-visibility evaluator -----------------------------------\n\n/** Facts a rule can read. `amount` is in the currency's minor unit (what\n * the payment intent stores); `metadata` values are already flattened to\n * strings by `customFieldContextFromMetadata`. */\nexport interface CustomFieldContext {\n amount: number;\n currency: string;\n metadata: Record<string, string>;\n}\n\n/** Flatten a payment's raw `metadata` object into the string map a rule\n * compares against. Arrays join on `,` so a list-shaped value stays usable\n * with `contains` / `in`; objects fall back to JSON. Mirrors the Rust\n * side's `flatten_metadata`. */\nexport function customFieldContextFromMetadata(raw: unknown): Record<string, string> {\n const out: Record<string, string> = {};\n if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return out;\n for (const [key, value] of Object.entries(raw as Record<string, unknown>)) {\n const flat = flattenMetadataValue(value);\n if (flat !== null) out[key] = flat;\n }\n return out;\n}\n\nfunction flattenMetadataValue(value: unknown): string | null {\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n if (value === null || value === undefined) return null;\n if (Array.isArray(value)) {\n return value\n .map((v) => flattenMetadataValue(v))\n .filter((v): v is string => v !== null)\n .join(',');\n }\n try {\n return JSON.stringify(value);\n } catch {\n return null;\n }\n}\n\n// Case- and whitespace-insensitive: merchants type `Windows` in the builder\n// and the shop sends `windows`. Exact-case matching would be a support\n// ticket generator.\nfunction norm(value: string): string {\n return value.trim().toLowerCase();\n}\n\n// Decimal-float grammar, deliberately narrower than `Number()`.\n//\n// `Number()` accepts radix-prefixed literals — `Number('0x10') === 16` — while\n// the router's Rust mirror uses `f64::from_str`, which rejects them. Left\n// unconstrained, a metadata value of `0x10` would satisfy `gte 5` in the\n// dashboard's builder and fail it on the backend: the merchant sees one\n// rule, buyers get another. This regex is `f64::from_str`'s number grammar\n// (sign, digits with optional point, optional exponent); `inf`/`nan` are\n// excluded here rather than by the finiteness check below, which matches\n// Rust filtering them out too.\nconst DECIMAL_NUMBER_PATTERN = /^[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][+-]?\\d+)?$/;\n\n// Both implementations compare as f64, so they round identically. Payment\n// amounts in minor units are far below 2^53, where that is lossless.\nfunction numeric(value: string): number | null {\n const trimmed = value.trim();\n if (!DECIMAL_NUMBER_PATTERN.test(trimmed)) return null;\n const n = Number(trimmed);\n return Number.isFinite(n) ? n : null;\n}\n\nfunction splitList(value: string): string[] {\n return value\n .split(',')\n .map((part) => norm(part))\n .filter((part) => part.length > 0);\n}\n\n/** Resolve the left-hand operand. `undefined` means \"the metadata key is\n * absent\" — which only `exists`/`not_exists` distinguish from empty. */\nfunction operandFor(condition: CustomFieldCondition, ctx: CustomFieldContext): string | undefined {\n switch (condition.source) {\n case 'currency':\n return ctx.currency;\n case 'amount':\n return String(ctx.amount);\n case 'metadata':\n return Object.prototype.hasOwnProperty.call(ctx.metadata, condition.key)\n ? ctx.metadata[condition.key]\n : undefined;\n }\n}\n\nexport function evaluateCustomFieldCondition(\n condition: CustomFieldCondition,\n ctx: CustomFieldContext,\n): boolean {\n const raw = operandFor(condition, ctx);\n const actual = raw ?? '';\n const expected = condition.value;\n\n switch (condition.operator) {\n case 'exists':\n return raw !== undefined && raw.trim().length > 0;\n case 'not_exists':\n return raw === undefined || raw.trim().length === 0;\n case 'equals':\n return norm(actual) === norm(expected);\n case 'not_equals':\n return norm(actual) !== norm(expected);\n case 'contains':\n return norm(actual).includes(norm(expected));\n case 'not_contains':\n return !norm(actual).includes(norm(expected));\n case 'starts_with':\n return norm(actual).startsWith(norm(expected));\n case 'ends_with':\n return norm(actual).endsWith(norm(expected));\n case 'in':\n return splitList(expected).includes(norm(actual));\n case 'not_in':\n return !splitList(expected).includes(norm(actual));\n case 'gt':\n case 'gte':\n case 'lt':\n case 'lte': {\n // Both sides must be numbers. A non-numeric metadata value never\n // matches a numeric comparison (rather than coercing to 0).\n const a = numeric(actual);\n const b = numeric(expected);\n if (a === null || b === null) return false;\n if (condition.operator === 'gt') return a > b;\n if (condition.operator === 'gte') return a >= b;\n if (condition.operator === 'lt') return a < b;\n return a <= b;\n }\n }\n}\n\n/**\n * Whether a field's rule matches the payment.\n *\n * Fail-open in two spots, deliberately: `mode: 'always'` and a `match` rule\n * with no conditions both resolve to visible. A half-authored rule should\n * never silently swallow a field the merchant needs collected — the\n * dashboard flags the empty rule as a validation issue instead.\n */\nexport function evaluateCustomFieldVisibility(\n field: CheckoutCustomField,\n ctx: CustomFieldContext,\n): boolean {\n const { mode, match, conditions } = field.visibility;\n if (mode !== 'match' || conditions.length === 0) return true;\n return match === 'any'\n ? conditions.some((c) => evaluateCustomFieldCondition(c, ctx))\n : conditions.every((c) => evaluateCustomFieldCondition(c, ctx));\n}\n\n/** Filter a field list to what the buyer should see for this payment.\n * Disabled fields are dropped here too — the two reasons a field doesn't\n * render are the same to every consumer. */\nexport function visibleCustomFields(\n fields: CheckoutCustomField[],\n ctx: CustomFieldContext,\n): CheckoutCustomField[] {\n return fields.filter((f) => f.enabled && evaluateCustomFieldVisibility(f, ctx));\n}\n\n// Exact-locale-then-base-language lookup. Own-property + string checks so\n// a hostile or odd locale string ('constructor', '__proto__') can never\n// surface a prototype-chain member as a \"translation\".\n/**\n * Look up one locale's override, walking from most to least specific.\n *\n * Two things this does that an exact-then-base lookup did not, both of which\n * became reachable the moment `zh-Hant` joined the locale list:\n *\n * - **Every parent tag, not just the base.** `zh-Hant-TW` now finds a stored\n * `zh-Hant` before falling through to `zh`. Jumping straight to the base\n * skipped the script entirely, so a Taiwanese buyer read the merchant's\n * simplified copy while a `zh-Hant` box sat filled in beside it.\n * - **Case-insensitive keys.** Locale tags are case-insensitive by spec and\n * arrive both ways — `zh-hant` from a hand-written link, `zh-Hant` from the\n * dashboard. A case-sensitive miss looks exactly like \"no translation\".\n *\n * The map's own casing is preserved on write; only the comparison folds.\n */\nfunction translationFor(map: CustomFieldTranslations, locale?: string): string | null {\n if (!locale) return null;\n\n const folded = new Map<string, string>();\n for (const [k, v] of Object.entries(map)) {\n if (typeof v === 'string' && v.length > 0 && !folded.has(k.toLowerCase())) {\n folded.set(k.toLowerCase(), v);\n }\n }\n\n const parts = locale.toLowerCase().split('-');\n for (let i = parts.length; i > 0; i -= 1) {\n const hit = folded.get(parts.slice(0, i).join('-'));\n if (hit) return hit;\n }\n return null;\n}\n\n// Resolve the display string for a field part in a buyer locale.\n// Exact locale wins ('de-AT'), then its base language ('de'), then the\n// field's default-language string; labels finally fall back to the key so\n// a field is never rendered nameless.\nexport function customFieldText(\n field: CheckoutCustomField,\n part: 'label' | 'placeholder' | 'helpText',\n locale?: string,\n): string {\n const map =\n part === 'label'\n ? field.labelTranslations\n : part === 'placeholder'\n ? field.placeholderTranslations\n : field.helpTextTranslations;\n const translated = translationFor(map, locale);\n if (translated) return translated;\n const fallback = field[part];\n if (fallback) return fallback;\n return part === 'label' ? field.key : '';\n}\n\nexport function customFieldOptionLabel(option: CustomFieldOption, locale?: string): string {\n return translationFor(option.labelTranslations, locale) ?? (option.label || option.value);\n}\n\n// Read a branding source into a fully-resolved CheckoutBranding.\n// Flat fields are authoritative when set; the bag fills in everything not\n// reachable via flat columns. Persisted `labelStyle: 'floating'` (legacy\n// \"floating\" mock) decodes to `'above'`.\nexport function decodeBranding(source: BrandingSource | null | undefined): CheckoutBranding {\n if (!source) return cloneBranding(DEFAULT_BRANDING);\n\n const extras: Record<string, string> = (source.sdk_ui_rules?.[BRANDING_GROUP_KEY] ??\n {}) as Record<string, string>;\n\n // Badges and notices are decided together: which one a shop gets depends\n // on what it saved of both.\n const trustRow = resolveNoticesAndBadges(\n decodeBadges(extras['trustBadges']),\n decodeNotices(extras['notices']),\n );\n const decodedCustomFields = decodeCustomFields(extras['customFields']);\n\n // Identity name: public payloads call it `merchant_name`, request payloads\n // call it `seller_name`. Same API field; pick whichever is present.\n const displayName = s(source.merchant_name) || s(source.seller_name);\n const logoUrl = s(source.merchant_logo) || s(source.logo);\n\n // Tagline lives in the bag, but `merchant_description` is its public\n // surface. Either may fill it; bag wins if both are set.\n const tagline = s(extras['tagline']) || s(source.merchant_description);\n\n // Stripe label style: the bag's `labelStyle` is the new source of truth;\n // the legacy flat `payment_form_label_type` is consulted only when the\n // bag is empty. `'floating'` (a legacy preview-only value that Stripe\n // Elements never honored) decodes to `'above'`. `'never'` (legacy API\n // wording) decodes to `'hidden'`.\n const labelStyle: LabelStyle = (() => {\n const fromBag = extras['labelStyle'];\n if (fromBag === 'above' || fromBag === 'hidden') return fromBag;\n if (fromBag === 'floating') return 'above';\n const legacy = source.payment_form_label_type;\n if (legacy === 'above' || legacy === 'floating') return 'above';\n if (legacy === 'hidden' || legacy === 'never') return 'hidden';\n return DEFAULT_BRANDING.labelStyle;\n })();\n\n return {\n displayName,\n logoUrl,\n tagline,\n showLogo: parseBool(extras['showLogo'], DEFAULT_BRANDING.showLogo),\n logoShape: pickEnum<LogoShape>(\n extras['logoShape'],\n ['square', 'rounded', 'circle'],\n DEFAULT_BRANDING.logoShape,\n ),\n logoSize: pickEnum<LogoSize>(extras['logoSize'], ['sm', 'md', 'lg'], DEFAULT_BRANDING.logoSize),\n\n primary: s(source.theme) || DEFAULT_BRANDING.primary,\n background: s(source.background_colour) || DEFAULT_BRANDING.background,\n surface: s(extras['surface']) || DEFAULT_BRANDING.surface,\n text: s(extras['text']) || DEFAULT_BRANDING.text,\n heading: s(extras['heading']) || s(extras['text']) || DEFAULT_BRANDING.heading,\n muted: s(extras['muted']) || DEFAULT_BRANDING.muted,\n border: s(extras['border']) || DEFAULT_BRANDING.border,\n accentText: s(extras['accentText']) || s(source.theme) || DEFAULT_BRANDING.accentText,\n buttonBackground:\n s(source.payment_button_colour) || s(source.theme) || DEFAULT_BRANDING.buttonBackground,\n buttonText: s(source.payment_button_text_colour) || DEFAULT_BRANDING.buttonText,\n\n fontFamily: pickEnum<FontFamily>(\n extras['fontFamily'],\n ALL_FONT_FAMILIES,\n DEFAULT_BRANDING.fontFamily,\n ),\n headingWeight: pickEnum<FontWeight>(\n extras['headingWeight'],\n ['regular', 'medium', 'semibold', 'bold'],\n DEFAULT_BRANDING.headingWeight,\n ),\n\n radiusSurface: pickEnum<NonPillRadius>(\n extras['radiusSurface'],\n NON_PILL_RADII,\n DEFAULT_BRANDING.radiusSurface,\n ),\n radiusInput: pickEnum<NonPillRadius>(\n extras['radiusInput'],\n NON_PILL_RADII,\n DEFAULT_BRANDING.radiusInput,\n ),\n radiusButton: pickEnum<CornerRadius>(\n extras['radiusButton'],\n ALL_RADII,\n DEFAULT_BRANDING.radiusButton,\n ),\n radiusBadge: pickEnum<CornerRadius>(\n extras['radiusBadge'],\n ALL_RADII,\n DEFAULT_BRANDING.radiusBadge,\n ),\n surfaceStyle: pickEnum<SurfaceStyle>(\n extras['surfaceStyle'],\n ['flat', 'outlined', 'elevated'],\n DEFAULT_BRANDING.surfaceStyle,\n ),\n surfacePadding: pickEnum<SpacingScale>(\n extras['surfacePadding'],\n ['compact', 'comfortable', 'spacious'],\n DEFAULT_BRANDING.surfacePadding,\n ),\n verticalGap: pickEnum<SpacingScale>(\n extras['verticalGap'],\n ['compact', 'comfortable', 'spacious'],\n DEFAULT_BRANDING.verticalGap,\n ),\n inputSize: pickEnum<SizeScale>(\n extras['inputSize'],\n ['sm', 'md', 'lg'],\n DEFAULT_BRANDING.inputSize,\n ),\n buttonSize: pickEnum<SizeScale>(\n extras['buttonSize'],\n ['sm', 'md', 'lg'],\n DEFAULT_BRANDING.buttonSize,\n ),\n\n showSurcharge: parseBool(extras['showSurcharge'], DEFAULT_BRANDING.showSurcharge),\n surchargePosition: pickEnum<SurchargePosition>(\n extras['surchargePosition'],\n SURCHARGE_POSITIONS,\n DEFAULT_BRANDING.surchargePosition,\n ),\n nativeElementStacked: parseBool(\n extras['nativeElementStacked'],\n DEFAULT_BRANDING.nativeElementStacked,\n ),\n nativeElementPosition: pickEnum<NativeElementPosition>(\n extras['nativeElementPosition'],\n NATIVE_ELEMENT_POSITIONS,\n DEFAULT_BRANDING.nativeElementPosition,\n ),\n surchargeStyle: pickEnum<SurchargeStyle>(\n extras['surchargeStyle'],\n SURCHARGE_STYLES,\n DEFAULT_BRANDING.surchargeStyle,\n ),\n surchargeSize: pickEnum<SurchargeSize>(\n extras['surchargeSize'],\n SURCHARGE_SIZES,\n DEFAULT_BRANDING.surchargeSize,\n ),\n surchargeShape: pickEnum<SurchargeShape>(\n extras['surchargeShape'],\n SURCHARGE_SHAPES,\n DEFAULT_BRANDING.surchargeShape,\n ),\n surchargeBorderWidth: pickEnum<SurchargeBorderWidth>(\n extras['surchargeBorderWidth'],\n SURCHARGE_BORDER_WIDTHS,\n DEFAULT_BRANDING.surchargeBorderWidth,\n ),\n surchargeBorderStyle: pickEnum<SurchargeBorderStyle>(\n extras['surchargeBorderStyle'],\n SURCHARGE_BORDER_STYLES,\n DEFAULT_BRANDING.surchargeBorderStyle,\n ),\n surchargeWeight: pickEnum<SurchargeWeight>(\n extras['surchargeWeight'],\n SURCHARGE_WEIGHTS,\n DEFAULT_BRANDING.surchargeWeight,\n ),\n surchargeSign: pickEnum<SurchargeSign>(\n extras['surchargeSign'],\n SURCHARGE_SIGNS,\n DEFAULT_BRANDING.surchargeSign,\n ),\n surchargeUppercase: parseBool(\n extras['surchargeUppercase'],\n DEFAULT_BRANDING.surchargeUppercase,\n ),\n surchargeLabel: pickEnum<SurchargeLabelMode>(\n extras['surchargeLabel'],\n SURCHARGE_LABEL_MODES,\n DEFAULT_BRANDING.surchargeLabel,\n ),\n surchargeFigure: pickEnum<SurchargeFigureMode>(\n extras['surchargeFigure'],\n SURCHARGE_FIGURE_MODES,\n DEFAULT_BRANDING.surchargeFigure,\n ),\n discountFigure: pickEnum<SurchargeFigureMode>(\n extras['discountFigure'],\n SURCHARGE_FIGURE_MODES,\n DEFAULT_BRANDING.discountFigure,\n ),\n surchargeWordTranslations: parseTranslations(extras['surchargeWordTranslations']),\n discountWordTranslations: parseTranslations(extras['discountWordTranslations']),\n headerTextTranslations: parseTranslations(extras['headerTextTranslations']),\n payButtonLabelTranslations: parseTranslations(extras['payButtonLabelTranslations']),\n cardTermsMessageTranslations: parseTranslations(extras['cardTermsMessageTranslations']),\n footerTextTranslations: parseTranslations(extras['footerTextTranslations']),\n surchargeColor: s(extras['surchargeColor']) || DEFAULT_BRANDING.surchargeColor,\n discountColor: s(extras['discountColor']) || DEFAULT_BRANDING.discountColor,\n\n layout: pickEnum<LayoutStyle>(extras['layout'], ['compact', 'split'], DEFAULT_BRANDING.layout),\n summaryPosition: pickEnum<SummaryPosition>(\n extras['summaryPosition'],\n ['left', 'right'],\n DEFAULT_BRANDING.summaryPosition,\n ),\n showOrderSummary: parseBool(extras['showOrderSummary'], DEFAULT_BRANDING.showOrderSummary),\n summaryGradient: parseBool(extras['summaryGradient'], DEFAULT_BRANDING.summaryGradient),\n showTotal: parseBool(extras['showTotal'], DEFAULT_BRANDING.showTotal),\n totalLabel: s(extras['totalLabel']) || DEFAULT_BRANDING.totalLabel,\n showCurrencyCode: parseBool(extras['showCurrencyCode'], DEFAULT_BRANDING.showCurrencyCode),\n showOrderItems: parseBool(extras['showOrderItems'], DEFAULT_BRANDING.showOrderItems),\n cancelLinkEnabled: parseBool(extras['cancelLinkEnabled'], DEFAULT_BRANDING.cancelLinkEnabled),\n cancelLinkPosition: pickEnum<'top' | 'bottom'>(\n extras['cancelLinkPosition'],\n ['top', 'bottom'],\n DEFAULT_BRANDING.cancelLinkPosition,\n ),\n cancelLinkStyle: pickEnum<'link' | 'button'>(\n extras['cancelLinkStyle'],\n ['link', 'button'],\n DEFAULT_BRANDING.cancelLinkStyle,\n ),\n\n trustBadges: trustRow.trustBadges,\n notices: trustRow.notices,\n customFields: decodedCustomFields ?? [],\n methodSectionOrder: decodeMethodSectionOrder(extras[METHOD_SECTION_ORDER_KEY]),\n methodSectionLabels: decodeMethodSectionLabels(extras[METHOD_SECTION_LABELS_KEY]),\n\n headerText: s(source.payment_form_header_text),\n payButtonLabel: s(source.payment_button_text),\n cardTermsMessage: s(source.custom_message_for_card_terms),\n footerText: s(extras['footerText']),\n supportEmail: s(extras['supportEmail']),\n\n paymentLayout: pickEnum<PaymentLayout>(\n source.sdk_layout,\n ['tabs', 'accordion', 'spaced_accordion'],\n DEFAULT_BRANDING.paymentLayout,\n ),\n labelStyle,\n showPoweredBy: source.branding_visibility !== false,\n\n // The two that can be empty use `pickEnumOrEmpty`, not `pickEnum`: a\n // value this build does not know has to decode to \"unset\" and defer, the\n // same as a key that was never written. Sending it to a concrete default\n // instead would make an older checkout override the connector account of\n // a merchant who picked a preset a newer dashboard offers.\n airwallexCardPreset: pickEnumOrEmpty<AirwallexCardPreset>(\n extras['airwallexCardPreset'],\n AIRWALLEX_CARD_PRESETS,\n ),\n airwallexHideCard: parseBool(extras['airwallexHideCard'], DEFAULT_BRANDING.airwallexHideCard),\n airwallexHideCardTitle: parseBool(\n extras['airwallexHideCardTitle'],\n DEFAULT_BRANDING.airwallexHideCardTitle,\n ),\n airwallexFieldChrome: pickEnum<AirwallexFieldChrome>(\n extras['airwallexFieldChrome'],\n AIRWALLEX_FIELD_CHROMES,\n DEFAULT_BRANDING.airwallexFieldChrome,\n ),\n airwallexLabelStyle: pickEnumOrEmpty<AirwallexLabelStyle>(\n extras['airwallexLabelStyle'],\n AIRWALLEX_LABEL_STYLES,\n ),\n airwallexFieldFontSize: pickEnum<AirwallexFieldFontSize>(\n extras['airwallexFieldFontSize'],\n AIRWALLEX_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.airwallexFieldFontSize,\n ),\n airwallexFieldWeight: pickEnum<AirwallexFieldWeight>(\n extras['airwallexFieldWeight'],\n AIRWALLEX_FIELD_WEIGHTS,\n DEFAULT_BRANDING.airwallexFieldWeight,\n ),\n airwallexFocusRing: pickEnum<AirwallexFocusRing>(\n extras['airwallexFocusRing'],\n AIRWALLEX_FOCUS_RINGS,\n DEFAULT_BRANDING.airwallexFocusRing,\n ),\n airwallexAutofill: pickEnum<AirwallexAutofillTreatment>(\n extras['airwallexAutofill'],\n AIRWALLEX_AUTOFILL_TREATMENTS,\n DEFAULT_BRANDING.airwallexAutofill,\n ),\n airwallexValidTint: parseBool(\n extras['airwallexValidTint'],\n DEFAULT_BRANDING.airwallexValidTint,\n ),\n airwallexNetworkMarks: parseBool(\n extras['airwallexNetworkMarks'],\n DEFAULT_BRANDING.airwallexNetworkMarks,\n ),\n\n stripeTheme: pickEnum<StripeTheme>(\n extras['stripeTheme'],\n STRIPE_THEMES,\n DEFAULT_BRANDING.stripeTheme,\n ),\n stripeInputs: pickEnum<StripeInputStyle>(\n extras['stripeInputs'],\n STRIPE_INPUT_STYLES,\n DEFAULT_BRANDING.stripeInputs,\n ),\n stripeLabels: pickEnum<StripeLabelPlacement>(\n extras['stripeLabels'],\n STRIPE_LABEL_PLACEMENTS,\n DEFAULT_BRANDING.stripeLabels,\n ),\n stripeSpacing: pickEnum<StripeSpacing>(\n extras['stripeSpacing'],\n STRIPE_SPACINGS,\n DEFAULT_BRANDING.stripeSpacing,\n ),\n stripeFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['stripeFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.stripeFieldFontSize,\n ),\n stripeFieldWeight: pickEnum<CardFieldWeight>(\n extras['stripeFieldWeight'],\n CARD_FIELD_WEIGHTS,\n DEFAULT_BRANDING.stripeFieldWeight,\n ),\n stripeFocusRing: pickEnum<CardFocusRing>(\n extras['stripeFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.stripeFocusRing,\n ),\n stripeDisableAnimations: parseBool(\n extras['stripeDisableAnimations'],\n DEFAULT_BRANDING.stripeDisableAnimations,\n ),\n paypalCardLayout: pickEnum<PaypalCardLayout>(\n extras['paypalCardLayout'],\n PAYPAL_CARD_LAYOUTS,\n DEFAULT_BRANDING.paypalCardLayout,\n ),\n paypalLabelStyle: pickEnum<PaypalLabelStyle>(\n extras['paypalLabelStyle'],\n PAYPAL_LABEL_STYLES,\n DEFAULT_BRANDING.paypalLabelStyle,\n ),\n paypalFieldChrome: pickEnum<CardFieldChrome>(\n extras['paypalFieldChrome'],\n CARD_FIELD_CHROMES,\n DEFAULT_BRANDING.paypalFieldChrome,\n ),\n mollieFieldChrome: pickEnum<CardFieldChrome>(\n extras['mollieFieldChrome'],\n CARD_FIELD_CHROMES,\n DEFAULT_BRANDING.mollieFieldChrome,\n ),\n paypalFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['paypalFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.paypalFieldFontSize,\n ),\n mollieFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['mollieFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.mollieFieldFontSize,\n ),\n paypalFieldWeight: pickEnum<CardFieldWeight>(\n extras['paypalFieldWeight'],\n CARD_FIELD_WEIGHTS,\n DEFAULT_BRANDING.paypalFieldWeight,\n ),\n mollieFieldWeight: pickEnum<CardFieldWeight>(\n extras['mollieFieldWeight'],\n CARD_FIELD_WEIGHTS,\n DEFAULT_BRANDING.mollieFieldWeight,\n ),\n paypalFocusRing: pickEnum<CardFocusRing>(\n extras['paypalFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.paypalFocusRing,\n ),\n mollieFocusRing: pickEnum<CardFocusRing>(\n extras['mollieFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.mollieFocusRing,\n ),\n micropaymentFieldChrome: pickEnum<CardFieldChrome>(\n extras['micropaymentFieldChrome'],\n CARD_FIELD_CHROMES,\n DEFAULT_BRANDING.micropaymentFieldChrome,\n ),\n micropaymentFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['micropaymentFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.micropaymentFieldFontSize,\n ),\n micropaymentFieldWeight: pickEnum<CardFieldWeight>(\n extras['micropaymentFieldWeight'],\n CARD_FIELD_WEIGHTS,\n DEFAULT_BRANDING.micropaymentFieldWeight,\n ),\n micropaymentFocusRing: pickEnum<CardFocusRing>(\n extras['micropaymentFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.micropaymentFocusRing,\n ),\n whopCardPreset: pickEnum<WhopCardPreset>(\n extras['whopCardPreset'],\n WHOP_CARD_PRESETS,\n DEFAULT_BRANDING.whopCardPreset,\n ),\n whopAccentColor: pickEnum<WhopAccentColor>(\n extras['whopAccentColor'],\n WHOP_ACCENT_COLORS,\n DEFAULT_BRANDING.whopAccentColor,\n ),\n whopGrayColor: pickEnum<WhopGrayColor>(\n extras['whopGrayColor'],\n WHOP_GRAY_COLORS,\n DEFAULT_BRANDING.whopGrayColor,\n ),\n whopBillingDetails: pickEnum<WhopBillingDetails>(\n extras['whopBillingDetails'],\n WHOP_BILLING_DETAILS,\n DEFAULT_BRANDING.whopBillingDetails,\n ),\n whopSeparated: parseBool(extras['whopSeparated'], DEFAULT_BRANDING.whopSeparated),\n whopEmailLabel: pickEnum<WhopEmailLabel>(\n extras['whopEmailLabel'],\n WHOP_EMAIL_LABELS,\n DEFAULT_BRANDING.whopEmailLabel,\n ),\n whopFieldChrome: pickEnum<CardFieldChrome>(\n extras['whopFieldChrome'],\n CARD_FIELD_CHROMES,\n DEFAULT_BRANDING.whopFieldChrome,\n ),\n whopFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['whopFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.whopFieldFontSize,\n ),\n whopFieldWeight: pickEnum<CardFieldWeight>(\n extras['whopFieldWeight'],\n CARD_FIELD_WEIGHTS,\n DEFAULT_BRANDING.whopFieldWeight,\n ),\n whopFocusRing: pickEnum<CardFocusRing>(\n extras['whopFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.whopFocusRing,\n ),\n whopRadius: pickEnum<WhopRadius>(extras['whopRadius'], WHOP_RADII, DEFAULT_BRANDING.whopRadius),\n whopShadow: pickEnum<WhopShadow>(\n extras['whopShadow'],\n WHOP_SHADOWS,\n DEFAULT_BRANDING.whopShadow,\n ),\n whopMethodIcons: parseBool(extras['whopMethodIcons'], DEFAULT_BRANDING.whopMethodIcons),\n whopSelection: pickEnum<WhopSelection>(\n extras['whopSelection'],\n WHOP_SELECTIONS,\n DEFAULT_BRANDING.whopSelection,\n ),\n paypalValidTint: parseBool(extras['paypalValidTint'], DEFAULT_BRANDING.paypalValidTint),\n // A look stored before e-Payouts had its own keys has none: the form keeps\n // the PayPal values it was drawn with until then.\n epayoutsCardLayout: pickEnum<PaypalCardLayout>(\n extras['epayoutsCardLayout'],\n PAYPAL_CARD_LAYOUTS,\n pickEnum<PaypalCardLayout>(\n extras['paypalCardLayout'],\n PAYPAL_CARD_LAYOUTS,\n DEFAULT_BRANDING.epayoutsCardLayout,\n ),\n ),\n epayoutsLabelStyle: pickEnum<PaypalLabelStyle>(\n extras['epayoutsLabelStyle'],\n PAYPAL_LABEL_STYLES,\n pickEnum<PaypalLabelStyle>(\n extras['paypalLabelStyle'],\n PAYPAL_LABEL_STYLES,\n DEFAULT_BRANDING.epayoutsLabelStyle,\n ),\n ),\n epayoutsFieldChrome: pickEnum<CardFieldChrome>(\n extras['epayoutsFieldChrome'],\n CARD_FIELD_CHROMES,\n pickEnum<CardFieldChrome>(\n extras['paypalFieldChrome'],\n CARD_FIELD_CHROMES,\n DEFAULT_BRANDING.epayoutsFieldChrome,\n ),\n ),\n epayoutsFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['epayoutsFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n pickEnum<CardFieldFontSize>(\n extras['paypalFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.epayoutsFieldFontSize,\n ),\n ),\n epayoutsFieldWeight: pickEnum<CardFieldWeight>(\n extras['epayoutsFieldWeight'],\n CARD_FIELD_WEIGHTS,\n pickEnum<CardFieldWeight>(\n extras['paypalFieldWeight'],\n CARD_FIELD_WEIGHTS,\n DEFAULT_BRANDING.epayoutsFieldWeight,\n ),\n ),\n epayoutsFocusRing: pickEnum<CardFocusRing>(\n extras['epayoutsFocusRing'],\n CARD_FOCUS_RINGS,\n pickEnum<CardFocusRing>(\n extras['paypalFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.epayoutsFocusRing,\n ),\n ),\n epayoutsValidTint: parseBool(\n extras['epayoutsValidTint'],\n parseBool(extras['paypalValidTint'], DEFAULT_BRANDING.epayoutsValidTint),\n ),\n nomupayFormStyle: pickEnum<NomupayFormStyle>(\n extras['nomupayFormStyle'],\n NOMUPAY_FORM_STYLES,\n DEFAULT_BRANDING.nomupayFormStyle,\n ),\n nomupayShowLabels: parseBool(extras['nomupayShowLabels'], DEFAULT_BRANDING.nomupayShowLabels),\n nomupayShowPlaceholders: parseBool(\n extras['nomupayShowPlaceholders'],\n DEFAULT_BRANDING.nomupayShowPlaceholders,\n ),\n nomupayShowCvvHint: parseBool(\n extras['nomupayShowCvvHint'],\n DEFAULT_BRANDING.nomupayShowCvvHint,\n ),\n nomupayFieldChrome: pickEnum<CardFieldChrome>(\n extras['nomupayFieldChrome'],\n CARD_FIELD_CHROMES,\n DEFAULT_BRANDING.nomupayFieldChrome,\n ),\n nomupayFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['nomupayFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.nomupayFieldFontSize,\n ),\n nomupayFocusRing: pickEnum<CardFocusRing>(\n extras['nomupayFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.nomupayFocusRing,\n ),\n nomupayApplePayButtonStyle: pickEnum<ApplePayButtonStyle>(\n extras['nomupayApplePayButtonStyle'],\n APPLE_PAY_BUTTON_STYLES,\n DEFAULT_BRANDING.nomupayApplePayButtonStyle,\n ),\n nomupayApplePayButtonType: pickEnum<ApplePayButtonType>(\n extras['nomupayApplePayButtonType'],\n APPLE_PAY_BUTTON_TYPES,\n DEFAULT_BRANDING.nomupayApplePayButtonType,\n ),\n nomupayGooglePayButtonColor: pickEnum<GooglePayButtonColor>(\n extras['nomupayGooglePayButtonColor'],\n GOOGLE_PAY_BUTTON_COLORS,\n DEFAULT_BRANDING.nomupayGooglePayButtonColor,\n ),\n nomupayGooglePayButtonType: pickEnum<GooglePayButtonType>(\n extras['nomupayGooglePayButtonType'],\n GOOGLE_PAY_BUTTON_TYPES,\n DEFAULT_BRANDING.nomupayGooglePayButtonType,\n ),\n\n customCss: s(extras['customCss']),\n\n ...decodeEnigmaCardForm(extras),\n };\n}\n\n// Encoded request shape — the union of fields the encoder fills. Compatible\n// with `BusinessPaymentLinkConfig` / `PaymentLinkConfigRequest` via\n// structural typing on the consumer side.\nexport interface EncodedBranding {\n theme: string;\n logo: string | null;\n seller_name: string | null;\n sdk_layout: PaymentLayout;\n payment_button_text: string | null;\n payment_button_colour: string;\n payment_button_text_colour: string;\n background_colour: string;\n payment_form_header_text: string | null;\n payment_form_label_type: 'above' | 'never';\n custom_message_for_card_terms: string | null;\n sdk_ui_rules: Record<string, Record<string, string>>;\n branding_visibility: boolean;\n}\n\n// Encode a CheckoutBranding into the API request shape. `base` is the\n// existing config (if any) -- preserves bag entries the form doesn't surface\n// (other sdk_ui_rules groups, business_specific_configs, etc.) by spreading\n// it through.\n//\n// `TBase` is constrained to `object | null | undefined` (not\n// `Record<string, unknown>`) so consumers can pass interface-typed values\n// directly. TS interfaces don't get an implicit string index signature, so\n// they don't structurally satisfy `Record<string, unknown>` even when their\n// property values would all unify to `unknown` — `object` admits them\n// without forcing a cast at every call site. We only spread the value, so\n// no index-signature semantics are needed at runtime.\nexport function encodeBranding<TBase extends object | null | undefined>(\n branding: CheckoutBranding,\n base?: TBase,\n): EncodedBranding & (TBase extends object ? TBase : Record<string, never>) {\n const trim = (v: string): string | null => {\n const t = v.trim();\n return t.length > 0 ? t : null;\n };\n\n // We only read one property off `base` and structural typing on `object`\n // doesn't permit index access, so go through `unknown` here.\n const existingRules = ((base as unknown as Record<string, unknown> | undefined)?.[\n 'sdk_ui_rules'\n ] ?? {}) as Record<string, Record<string, string>>;\n const extras: Record<string, string> = {\n surface: branding.surface,\n text: branding.text,\n heading: branding.heading,\n muted: branding.muted,\n border: branding.border,\n accentText: branding.accentText,\n fontFamily: branding.fontFamily,\n headingWeight: branding.headingWeight,\n radiusSurface: branding.radiusSurface,\n radiusInput: branding.radiusInput,\n radiusButton: branding.radiusButton,\n radiusBadge: branding.radiusBadge,\n surfaceStyle: branding.surfaceStyle,\n surfacePadding: branding.surfacePadding,\n verticalGap: branding.verticalGap,\n inputSize: branding.inputSize,\n buttonSize: branding.buttonSize,\n showSurcharge: String(branding.showSurcharge),\n surchargePosition: branding.surchargePosition,\n nativeElementPosition: branding.nativeElementPosition,\n nativeElementStacked: String(branding.nativeElementStacked),\n surchargeStyle: branding.surchargeStyle,\n surchargeSize: branding.surchargeSize,\n surchargeShape: branding.surchargeShape,\n surchargeBorderWidth: branding.surchargeBorderWidth,\n surchargeBorderStyle: branding.surchargeBorderStyle,\n surchargeWeight: branding.surchargeWeight,\n surchargeSign: branding.surchargeSign,\n surchargeUppercase: String(branding.surchargeUppercase),\n surchargeLabel: branding.surchargeLabel,\n surchargeFigure: branding.surchargeFigure,\n discountFigure: branding.discountFigure,\n surchargeColor: branding.surchargeColor,\n discountColor: branding.discountColor,\n layout: branding.layout,\n summaryPosition: branding.summaryPosition,\n showOrderSummary: String(branding.showOrderSummary),\n summaryGradient: String(branding.summaryGradient),\n showTotal: String(branding.showTotal),\n totalLabel: branding.totalLabel,\n showCurrencyCode: String(branding.showCurrencyCode),\n showOrderItems: String(branding.showOrderItems),\n cancelLinkEnabled: String(branding.cancelLinkEnabled),\n cancelLinkPosition: branding.cancelLinkPosition,\n cancelLinkStyle: branding.cancelLinkStyle,\n showLogo: String(branding.showLogo),\n logoShape: branding.logoShape,\n logoSize: branding.logoSize,\n labelStyle: branding.labelStyle,\n // Written unconditionally, empty string included. The encoder REPLACES\n // `sdk_ui_rules.branding` wholesale, so a key it skips is a key it\n // deletes — and here the empty string is a real value (\"no choice made\"),\n // not an absence. Omitting it would be indistinguishable from omitting it\n // by accident, which is how `summaryOrder` was lost.\n airwallexCardPreset: branding.airwallexCardPreset,\n airwallexHideCard: String(branding.airwallexHideCard),\n airwallexHideCardTitle: String(branding.airwallexHideCardTitle),\n airwallexFieldChrome: branding.airwallexFieldChrome,\n airwallexLabelStyle: branding.airwallexLabelStyle,\n airwallexFieldFontSize: branding.airwallexFieldFontSize,\n airwallexFieldWeight: branding.airwallexFieldWeight,\n airwallexFocusRing: branding.airwallexFocusRing,\n airwallexAutofill: branding.airwallexAutofill,\n airwallexValidTint: String(branding.airwallexValidTint),\n airwallexNetworkMarks: String(branding.airwallexNetworkMarks),\n stripeTheme: branding.stripeTheme,\n stripeInputs: branding.stripeInputs,\n stripeLabels: branding.stripeLabels,\n stripeSpacing: branding.stripeSpacing,\n stripeFieldFontSize: branding.stripeFieldFontSize,\n stripeFieldWeight: branding.stripeFieldWeight,\n stripeFocusRing: branding.stripeFocusRing,\n stripeDisableAnimations: String(branding.stripeDisableAnimations),\n paypalCardLayout: branding.paypalCardLayout,\n paypalLabelStyle: branding.paypalLabelStyle,\n paypalFieldChrome: branding.paypalFieldChrome,\n mollieFieldChrome: branding.mollieFieldChrome,\n paypalFieldFontSize: branding.paypalFieldFontSize,\n mollieFieldFontSize: branding.mollieFieldFontSize,\n paypalFieldWeight: branding.paypalFieldWeight,\n mollieFieldWeight: branding.mollieFieldWeight,\n paypalFocusRing: branding.paypalFocusRing,\n mollieFocusRing: branding.mollieFocusRing,\n micropaymentFieldChrome: branding.micropaymentFieldChrome,\n micropaymentFieldFontSize: branding.micropaymentFieldFontSize,\n micropaymentFieldWeight: branding.micropaymentFieldWeight,\n micropaymentFocusRing: branding.micropaymentFocusRing,\n whopCardPreset: branding.whopCardPreset,\n whopAccentColor: branding.whopAccentColor,\n whopGrayColor: branding.whopGrayColor,\n whopBillingDetails: branding.whopBillingDetails,\n whopSeparated: String(branding.whopSeparated),\n whopEmailLabel: branding.whopEmailLabel,\n whopFieldChrome: branding.whopFieldChrome,\n whopFieldFontSize: branding.whopFieldFontSize,\n whopFieldWeight: branding.whopFieldWeight,\n whopFocusRing: branding.whopFocusRing,\n whopRadius: branding.whopRadius,\n whopShadow: branding.whopShadow,\n whopMethodIcons: String(branding.whopMethodIcons),\n whopSelection: branding.whopSelection,\n paypalValidTint: String(branding.paypalValidTint),\n epayoutsCardLayout: branding.epayoutsCardLayout,\n epayoutsLabelStyle: branding.epayoutsLabelStyle,\n epayoutsFieldChrome: branding.epayoutsFieldChrome,\n epayoutsFieldFontSize: branding.epayoutsFieldFontSize,\n epayoutsFieldWeight: branding.epayoutsFieldWeight,\n epayoutsFocusRing: branding.epayoutsFocusRing,\n epayoutsValidTint: String(branding.epayoutsValidTint),\n nomupayFormStyle: branding.nomupayFormStyle,\n nomupayShowLabels: String(branding.nomupayShowLabels),\n nomupayShowPlaceholders: String(branding.nomupayShowPlaceholders),\n nomupayShowCvvHint: String(branding.nomupayShowCvvHint),\n nomupayFieldChrome: branding.nomupayFieldChrome,\n nomupayFieldFontSize: branding.nomupayFieldFontSize,\n nomupayFocusRing: branding.nomupayFocusRing,\n nomupayApplePayButtonStyle: branding.nomupayApplePayButtonStyle,\n nomupayApplePayButtonType: branding.nomupayApplePayButtonType,\n nomupayGooglePayButtonColor: branding.nomupayGooglePayButtonColor,\n nomupayGooglePayButtonType: branding.nomupayGooglePayButtonType,\n // Always written, `[]` included — its presence is what stops a later\n // decode from migrating the shop again (`resolveNoticesAndBadges`).\n notices: encodeNotices(branding.notices),\n [METHOD_SECTION_ORDER_KEY]: encodeMethodSectionOrder(branding.methodSectionOrder),\n };\n // Badges only when there are some. Not for tidiness: this group\n // is rebuilt on every save, so a writer that predates notices drops them.\n // Such a writer decodes a missing `trustBadges` to its stock pair and saves\n // that, which decodes here to the default notices again. Had `[]` been\n // written, it would save `[]` back, and `[]` without notices reads as \"the\n // merchant removed the trust row\", so the checkout would show nothing.\n if (branding.trustBadges.length > 0) {\n extras['trustBadges'] = encodeBadges(branding.trustBadges);\n }\n // Written only when there is one, so an untouched profile's bag is unchanged.\n const sectionLabels = encodeMethodSectionLabels(branding.methodSectionLabels);\n if (sectionLabels) extras[METHOD_SECTION_LABELS_KEY] = sectionLabels;\n // Omit the key entirely when there are no fields — decode treats a\n // missing entry the same as an empty list, and the bag stays clean for\n // merchants who never touch the feature.\n if (branding.customFields.length > 0) {\n extras['customFields'] = encodeCustomFields(branding.customFields);\n }\n // Localized copy, each written only when the merchant actually set one, so\n // an untouched profile's bag is unchanged by this feature existing.\n for (const key of [\n 'surchargeWordTranslations',\n 'discountWordTranslations',\n 'headerTextTranslations',\n 'payButtonLabelTranslations',\n 'cardTermsMessageTranslations',\n 'footerTextTranslations',\n ] as const) {\n const encoded = encodeTranslations(branding[key]);\n if (encoded) extras[key] = encoded;\n }\n const tagline = trim(branding.tagline);\n if (tagline) extras['tagline'] = tagline;\n const footer = trim(branding.footerText);\n if (footer) extras['footerText'] = footer;\n const support = trim(branding.supportEmail);\n if (support) extras['supportEmail'] = support;\n // Persist raw — sanitization runs at render time so we keep the merchant's\n // input as-typed (preserves comments, whitespace) and let the checkout\n // strip dangerous tokens consistently across all readers.\n const css = trim(branding.customCss);\n if (css) extras['customCss'] = css;\n Object.assign(extras, encodeEnigmaCardForm(branding));\n\n const nextRules: Record<string, Record<string, string>> = {\n ...existingRules,\n [BRANDING_GROUP_KEY]: extras,\n };\n\n // Map `hidden` back to the legacy `never` token the API's label type\n // enum understands. `floating` no longer exists.\n const legacyLabel: 'above' | 'never' = branding.labelStyle === 'hidden' ? 'never' : 'above';\n\n const flatFields: EncodedBranding = {\n theme: branding.primary,\n logo: trim(branding.logoUrl),\n seller_name: trim(branding.displayName),\n sdk_layout: branding.paymentLayout,\n payment_button_text: trim(branding.payButtonLabel),\n payment_button_colour: branding.buttonBackground,\n payment_button_text_colour: branding.buttonText,\n background_colour: branding.background,\n payment_form_header_text: trim(branding.headerText),\n payment_form_label_type: legacyLabel,\n custom_message_for_card_terms: trim(branding.cardTermsMessage),\n sdk_ui_rules: nextRules,\n branding_visibility: branding.showPoweredBy,\n };\n\n // Spread `base` first to preserve fields the encoder doesn't surface\n // (show_card_terms, show_card_form_by_default, hide_card_nickname_field,\n // enable_button_only_on_form_ready, skip_status_screen,\n // transaction_details, background_image, details_layout,\n // custom_message_for_payment_method_types, payment_link_ui_rules,\n // color_icon_card_cvc_error, is_setup_mandate_flow,\n // enabled_saved_payment_method, display_sdk_only,\n // business_specific_configs, domain_name, allowed_domains).\n return {\n ...base,\n ...flatFields,\n } as EncodedBranding & (TBase extends object ? TBase : Record<string, never>);\n}\n\n// --- Import / Export envelope ------------------------------------------\n\n// Versioned envelope used by the merchant dashboard's \"Import /\n// Export\" buttons. Bumping `version` is informational; the importer is\n// graceful and accepts any version (or no envelope at all).\nexport const BRANDING_EXPORT_FORMAT = 'delopay-checkout-branding';\nexport const BRANDING_EXPORT_VERSION = 1;\n\nexport interface BrandingExport {\n format: typeof BRANDING_EXPORT_FORMAT;\n version: number;\n exported_at: string;\n branding: CheckoutBranding;\n}\n\nexport function buildBrandingExport(branding: CheckoutBranding): BrandingExport {\n return {\n format: BRANDING_EXPORT_FORMAT,\n version: BRANDING_EXPORT_VERSION,\n exported_at: new Date().toISOString(),\n branding: cloneBranding(branding),\n };\n}\n\n// Resolve arbitrary JSON into a fully-typed CheckoutBranding. Designed to\n// never throw — every field is independently validated against its type\n// and silently falls back to the light-mode default if missing or\n// malformed:\n// - extra fields the form doesn't know about are ignored,\n// - missing fields inherit defaults,\n// - hex colors that fail the regex stay at the default,\n// - enums outside the allowed set fall back,\n// - a payload with no recognizable shape produces DEFAULT_BRANDING.\n//\n// Accepts either a bare CheckoutBranding object or an envelope produced by\n// `buildBrandingExport()`. The caller (the import handler) only needs to\n// catch JSON.parse errors; everything past that point is total.\nexport function parseImportedBranding(raw: unknown): CheckoutBranding {\n // Unwrap the envelope if present. Don't gate on version — bumping it is\n // informational; this function is the migration layer.\n const root: Record<string, unknown> | null =\n isObject(raw) && isObject(raw['branding'])\n ? (raw['branding'] as Record<string, unknown>)\n : isObject(raw)\n ? raw\n : null;\n\n if (!root) return cloneBranding(DEFAULT_BRANDING);\n\n const dflt = DEFAULT_BRANDING;\n const sStr = (v: unknown, fallback: string): string => (typeof v === 'string' ? v : fallback);\n const sHex = (v: unknown, fallback: string): string =>\n typeof v === 'string' && isHexColor(v) ? v : fallback;\n\n // The same rule as `decodeBranding`: an export made before notices existed\n // carries badges only, and is migrated exactly as a saved shop would be.\n const { trustBadges, notices } = resolveNoticesAndBadges(\n parseTrustBadgesLoose(root['trustBadges']),\n parseNoticesLoose(root['notices']),\n );\n const customFields = parseCustomFieldsLoose(root['customFields']) ?? [];\n\n // `floating` from older exports normalizes to `above`; see decodeBranding.\n const labelStyle: LabelStyle = (() => {\n const v = root['labelStyle'];\n if (v === 'above' || v === 'hidden') return v;\n return dflt.labelStyle;\n })();\n\n return {\n displayName: sStr(root['displayName'], dflt.displayName),\n logoUrl: sStr(root['logoUrl'], dflt.logoUrl),\n tagline: sStr(root['tagline'], dflt.tagline),\n showLogo: parseBool(root['showLogo'], dflt.showLogo),\n logoShape: pickEnum<LogoShape>(\n root['logoShape'],\n ['square', 'rounded', 'circle'],\n dflt.logoShape,\n ),\n logoSize: pickEnum<LogoSize>(root['logoSize'], ['sm', 'md', 'lg'], dflt.logoSize),\n\n primary: sHex(root['primary'], dflt.primary),\n background: sHex(root['background'], dflt.background),\n surface: sHex(root['surface'], dflt.surface),\n text: sHex(root['text'], dflt.text),\n heading: sHex(root['heading'], dflt.heading),\n muted: sHex(root['muted'], dflt.muted),\n border: sHex(root['border'], dflt.border),\n accentText: sHex(root['accentText'], dflt.accentText),\n buttonBackground: sHex(root['buttonBackground'], dflt.buttonBackground),\n buttonText: sHex(root['buttonText'], dflt.buttonText),\n\n fontFamily: pickEnum<FontFamily>(root['fontFamily'], ALL_FONT_FAMILIES, dflt.fontFamily),\n headingWeight: pickEnum<FontWeight>(\n root['headingWeight'],\n ['regular', 'medium', 'semibold', 'bold'],\n dflt.headingWeight,\n ),\n\n radiusSurface: pickEnum<NonPillRadius>(\n root['radiusSurface'],\n NON_PILL_RADII,\n dflt.radiusSurface,\n ),\n radiusInput: pickEnum<NonPillRadius>(root['radiusInput'], NON_PILL_RADII, dflt.radiusInput),\n radiusButton: pickEnum<CornerRadius>(root['radiusButton'], ALL_RADII, dflt.radiusButton),\n radiusBadge: pickEnum<CornerRadius>(root['radiusBadge'], ALL_RADII, dflt.radiusBadge),\n surfaceStyle: pickEnum<SurfaceStyle>(\n root['surfaceStyle'],\n ['flat', 'outlined', 'elevated'],\n dflt.surfaceStyle,\n ),\n surfacePadding: pickEnum<SpacingScale>(\n root['surfacePadding'],\n ['compact', 'comfortable', 'spacious'],\n dflt.surfacePadding,\n ),\n verticalGap: pickEnum<SpacingScale>(\n root['verticalGap'],\n ['compact', 'comfortable', 'spacious'],\n dflt.verticalGap,\n ),\n inputSize: pickEnum<SizeScale>(root['inputSize'], ['sm', 'md', 'lg'], dflt.inputSize),\n buttonSize: pickEnum<SizeScale>(root['buttonSize'], ['sm', 'md', 'lg'], dflt.buttonSize),\n\n showSurcharge: parseBool(root['showSurcharge'], dflt.showSurcharge),\n surchargePosition: pickEnum<SurchargePosition>(\n root['surchargePosition'],\n SURCHARGE_POSITIONS,\n dflt.surchargePosition,\n ),\n nativeElementStacked: parseBool(root['nativeElementStacked'], dflt.nativeElementStacked),\n nativeElementPosition: pickEnum<NativeElementPosition>(\n root['nativeElementPosition'],\n NATIVE_ELEMENT_POSITIONS,\n dflt.nativeElementPosition,\n ),\n surchargeStyle: pickEnum<SurchargeStyle>(\n root['surchargeStyle'],\n SURCHARGE_STYLES,\n dflt.surchargeStyle,\n ),\n surchargeSize: pickEnum<SurchargeSize>(\n root['surchargeSize'],\n SURCHARGE_SIZES,\n dflt.surchargeSize,\n ),\n surchargeShape: pickEnum<SurchargeShape>(\n root['surchargeShape'],\n SURCHARGE_SHAPES,\n dflt.surchargeShape,\n ),\n surchargeBorderWidth: pickEnum<SurchargeBorderWidth>(\n root['surchargeBorderWidth'],\n SURCHARGE_BORDER_WIDTHS,\n dflt.surchargeBorderWidth,\n ),\n surchargeBorderStyle: pickEnum<SurchargeBorderStyle>(\n root['surchargeBorderStyle'],\n SURCHARGE_BORDER_STYLES,\n dflt.surchargeBorderStyle,\n ),\n surchargeWeight: pickEnum<SurchargeWeight>(\n root['surchargeWeight'],\n SURCHARGE_WEIGHTS,\n dflt.surchargeWeight,\n ),\n surchargeSign: pickEnum<SurchargeSign>(\n root['surchargeSign'],\n SURCHARGE_SIGNS,\n dflt.surchargeSign,\n ),\n surchargeUppercase: parseBool(root['surchargeUppercase'], dflt.surchargeUppercase),\n surchargeLabel: pickEnum<SurchargeLabelMode>(\n root['surchargeLabel'],\n SURCHARGE_LABEL_MODES,\n dflt.surchargeLabel,\n ),\n surchargeFigure: pickEnum<SurchargeFigureMode>(\n root['surchargeFigure'],\n SURCHARGE_FIGURE_MODES,\n dflt.surchargeFigure,\n ),\n discountFigure: pickEnum<SurchargeFigureMode>(\n root['discountFigure'],\n SURCHARGE_FIGURE_MODES,\n dflt.discountFigure,\n ),\n surchargeWordTranslations: parseTranslations(root['surchargeWordTranslations']),\n discountWordTranslations: parseTranslations(root['discountWordTranslations']),\n headerTextTranslations: parseTranslations(root['headerTextTranslations']),\n payButtonLabelTranslations: parseTranslations(root['payButtonLabelTranslations']),\n cardTermsMessageTranslations: parseTranslations(root['cardTermsMessageTranslations']),\n footerTextTranslations: parseTranslations(root['footerTextTranslations']),\n surchargeColor: sHex(root['surchargeColor'], dflt.surchargeColor),\n discountColor: sHex(root['discountColor'], dflt.discountColor),\n\n layout: pickEnum<LayoutStyle>(root['layout'], ['compact', 'split'], dflt.layout),\n summaryPosition: pickEnum<SummaryPosition>(\n root['summaryPosition'],\n ['left', 'right'],\n dflt.summaryPosition,\n ),\n showOrderSummary: parseBool(root['showOrderSummary'], dflt.showOrderSummary),\n summaryGradient: parseBool(root['summaryGradient'], dflt.summaryGradient),\n showTotal: parseBool(root['showTotal'], dflt.showTotal),\n totalLabel: sStr(root['totalLabel'], dflt.totalLabel),\n showCurrencyCode: parseBool(root['showCurrencyCode'], dflt.showCurrencyCode),\n showOrderItems: parseBool(root['showOrderItems'], dflt.showOrderItems),\n\n trustBadges,\n notices,\n customFields,\n cancelLinkEnabled: parseBool(root['cancelLinkEnabled'], dflt.cancelLinkEnabled),\n cancelLinkPosition: pickEnum<'top' | 'bottom'>(\n root['cancelLinkPosition'],\n ['top', 'bottom'],\n dflt.cancelLinkPosition,\n ),\n cancelLinkStyle: pickEnum<'link' | 'button'>(\n root['cancelLinkStyle'],\n ['link', 'button'],\n dflt.cancelLinkStyle,\n ),\n // An export writes the decoded maps; a hand-written file may carry the\n // JSON strings the bag uses. Both are accepted, and neither is required.\n methodSectionOrder: parseSectionOrderLoose(root[METHOD_SECTION_ORDER_KEY]),\n methodSectionLabels: parseSectionLabelsLoose(root[METHOD_SECTION_LABELS_KEY]),\n\n headerText: sStr(root['headerText'], dflt.headerText),\n payButtonLabel: sStr(root['payButtonLabel'], dflt.payButtonLabel),\n cardTermsMessage: sStr(root['cardTermsMessage'], dflt.cardTermsMessage),\n footerText: sStr(root['footerText'], dflt.footerText),\n supportEmail: sStr(root['supportEmail'], dflt.supportEmail),\n\n paymentLayout: pickEnum<PaymentLayout>(\n root['paymentLayout'],\n ['tabs', 'accordion', 'spaced_accordion'],\n dflt.paymentLayout,\n ),\n labelStyle,\n showPoweredBy: parseBool(root['showPoweredBy'], dflt.showPoweredBy),\n\n // An imported profile that predates this section carries none of these\n // and lands on the defaults — which is to say on \"defer\", so importing an\n // old export into a shop does not take that shop's connector setting\n // away. The one field that would be dangerous to import loosely is the\n // hide switch, and `parseBool` only says true for a literal `true`.\n airwallexCardPreset: pickEnumOrEmpty<AirwallexCardPreset>(\n root['airwallexCardPreset'],\n AIRWALLEX_CARD_PRESETS,\n ),\n airwallexHideCard: parseBool(root['airwallexHideCard'], dflt.airwallexHideCard),\n airwallexHideCardTitle: parseBool(root['airwallexHideCardTitle'], dflt.airwallexHideCardTitle),\n airwallexFieldChrome: pickEnum<AirwallexFieldChrome>(\n root['airwallexFieldChrome'],\n AIRWALLEX_FIELD_CHROMES,\n dflt.airwallexFieldChrome,\n ),\n airwallexLabelStyle: pickEnumOrEmpty<AirwallexLabelStyle>(\n root['airwallexLabelStyle'],\n AIRWALLEX_LABEL_STYLES,\n ),\n airwallexFieldFontSize: pickEnum<AirwallexFieldFontSize>(\n root['airwallexFieldFontSize'],\n AIRWALLEX_FIELD_FONT_SIZES,\n dflt.airwallexFieldFontSize,\n ),\n airwallexFieldWeight: pickEnum<AirwallexFieldWeight>(\n root['airwallexFieldWeight'],\n AIRWALLEX_FIELD_WEIGHTS,\n dflt.airwallexFieldWeight,\n ),\n airwallexFocusRing: pickEnum<AirwallexFocusRing>(\n root['airwallexFocusRing'],\n AIRWALLEX_FOCUS_RINGS,\n dflt.airwallexFocusRing,\n ),\n airwallexAutofill: pickEnum<AirwallexAutofillTreatment>(\n root['airwallexAutofill'],\n AIRWALLEX_AUTOFILL_TREATMENTS,\n dflt.airwallexAutofill,\n ),\n airwallexValidTint: parseBool(root['airwallexValidTint'], dflt.airwallexValidTint),\n airwallexNetworkMarks: parseBool(root['airwallexNetworkMarks'], dflt.airwallexNetworkMarks),\n\n stripeTheme: pickEnum<StripeTheme>(root['stripeTheme'], STRIPE_THEMES, dflt.stripeTheme),\n stripeInputs: pickEnum<StripeInputStyle>(\n root['stripeInputs'],\n STRIPE_INPUT_STYLES,\n dflt.stripeInputs,\n ),\n stripeLabels: pickEnum<StripeLabelPlacement>(\n root['stripeLabels'],\n STRIPE_LABEL_PLACEMENTS,\n dflt.stripeLabels,\n ),\n stripeSpacing: pickEnum<StripeSpacing>(\n root['stripeSpacing'],\n STRIPE_SPACINGS,\n dflt.stripeSpacing,\n ),\n stripeFieldFontSize: pickEnum<CardFieldFontSize>(\n root['stripeFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.stripeFieldFontSize,\n ),\n stripeFieldWeight: pickEnum<CardFieldWeight>(\n root['stripeFieldWeight'],\n CARD_FIELD_WEIGHTS,\n dflt.stripeFieldWeight,\n ),\n stripeFocusRing: pickEnum<CardFocusRing>(\n root['stripeFocusRing'],\n CARD_FOCUS_RINGS,\n dflt.stripeFocusRing,\n ),\n stripeDisableAnimations: parseBool(\n root['stripeDisableAnimations'],\n dflt.stripeDisableAnimations,\n ),\n paypalCardLayout: pickEnum<PaypalCardLayout>(\n root['paypalCardLayout'],\n PAYPAL_CARD_LAYOUTS,\n dflt.paypalCardLayout,\n ),\n paypalLabelStyle: pickEnum<PaypalLabelStyle>(\n root['paypalLabelStyle'],\n PAYPAL_LABEL_STYLES,\n dflt.paypalLabelStyle,\n ),\n paypalFieldChrome: pickEnum<CardFieldChrome>(\n root['paypalFieldChrome'],\n CARD_FIELD_CHROMES,\n dflt.paypalFieldChrome,\n ),\n mollieFieldChrome: pickEnum<CardFieldChrome>(\n root['mollieFieldChrome'],\n CARD_FIELD_CHROMES,\n dflt.mollieFieldChrome,\n ),\n paypalFieldFontSize: pickEnum<CardFieldFontSize>(\n root['paypalFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.paypalFieldFontSize,\n ),\n mollieFieldFontSize: pickEnum<CardFieldFontSize>(\n root['mollieFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.mollieFieldFontSize,\n ),\n paypalFieldWeight: pickEnum<CardFieldWeight>(\n root['paypalFieldWeight'],\n CARD_FIELD_WEIGHTS,\n dflt.paypalFieldWeight,\n ),\n mollieFieldWeight: pickEnum<CardFieldWeight>(\n root['mollieFieldWeight'],\n CARD_FIELD_WEIGHTS,\n dflt.mollieFieldWeight,\n ),\n paypalFocusRing: pickEnum<CardFocusRing>(\n root['paypalFocusRing'],\n CARD_FOCUS_RINGS,\n dflt.paypalFocusRing,\n ),\n mollieFocusRing: pickEnum<CardFocusRing>(\n root['mollieFocusRing'],\n CARD_FOCUS_RINGS,\n dflt.mollieFocusRing,\n ),\n micropaymentFieldChrome: pickEnum<CardFieldChrome>(\n root['micropaymentFieldChrome'],\n CARD_FIELD_CHROMES,\n dflt.micropaymentFieldChrome,\n ),\n micropaymentFieldFontSize: pickEnum<CardFieldFontSize>(\n root['micropaymentFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.micropaymentFieldFontSize,\n ),\n micropaymentFieldWeight: pickEnum<CardFieldWeight>(\n root['micropaymentFieldWeight'],\n CARD_FIELD_WEIGHTS,\n dflt.micropaymentFieldWeight,\n ),\n micropaymentFocusRing: pickEnum<CardFocusRing>(\n root['micropaymentFocusRing'],\n CARD_FOCUS_RINGS,\n dflt.micropaymentFocusRing,\n ),\n whopCardPreset: pickEnum<WhopCardPreset>(\n root['whopCardPreset'],\n WHOP_CARD_PRESETS,\n dflt.whopCardPreset,\n ),\n whopAccentColor: pickEnum<WhopAccentColor>(\n root['whopAccentColor'],\n WHOP_ACCENT_COLORS,\n dflt.whopAccentColor,\n ),\n whopGrayColor: pickEnum<WhopGrayColor>(\n root['whopGrayColor'],\n WHOP_GRAY_COLORS,\n dflt.whopGrayColor,\n ),\n whopBillingDetails: pickEnum<WhopBillingDetails>(\n root['whopBillingDetails'],\n WHOP_BILLING_DETAILS,\n dflt.whopBillingDetails,\n ),\n whopSeparated: parseBool(root['whopSeparated'], dflt.whopSeparated),\n whopEmailLabel: pickEnum<WhopEmailLabel>(\n root['whopEmailLabel'],\n WHOP_EMAIL_LABELS,\n dflt.whopEmailLabel,\n ),\n whopFieldChrome: pickEnum<CardFieldChrome>(\n root['whopFieldChrome'],\n CARD_FIELD_CHROMES,\n dflt.whopFieldChrome,\n ),\n whopFieldFontSize: pickEnum<CardFieldFontSize>(\n root['whopFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.whopFieldFontSize,\n ),\n whopFieldWeight: pickEnum<CardFieldWeight>(\n root['whopFieldWeight'],\n CARD_FIELD_WEIGHTS,\n dflt.whopFieldWeight,\n ),\n whopFocusRing: pickEnum<CardFocusRing>(\n root['whopFocusRing'],\n CARD_FOCUS_RINGS,\n dflt.whopFocusRing,\n ),\n whopRadius: pickEnum<WhopRadius>(root['whopRadius'], WHOP_RADII, dflt.whopRadius),\n whopShadow: pickEnum<WhopShadow>(root['whopShadow'], WHOP_SHADOWS, dflt.whopShadow),\n whopMethodIcons: parseBool(root['whopMethodIcons'], dflt.whopMethodIcons),\n whopSelection: pickEnum<WhopSelection>(\n root['whopSelection'],\n WHOP_SELECTIONS,\n dflt.whopSelection,\n ),\n paypalValidTint: parseBool(root['paypalValidTint'], dflt.paypalValidTint),\n // A look stored before e-Payouts had its own keys has none: the form keeps\n // the PayPal values it was drawn with until then.\n epayoutsCardLayout: pickEnum<PaypalCardLayout>(\n root['epayoutsCardLayout'],\n PAYPAL_CARD_LAYOUTS,\n pickEnum<PaypalCardLayout>(\n root['paypalCardLayout'],\n PAYPAL_CARD_LAYOUTS,\n dflt.epayoutsCardLayout,\n ),\n ),\n epayoutsLabelStyle: pickEnum<PaypalLabelStyle>(\n root['epayoutsLabelStyle'],\n PAYPAL_LABEL_STYLES,\n pickEnum<PaypalLabelStyle>(\n root['paypalLabelStyle'],\n PAYPAL_LABEL_STYLES,\n dflt.epayoutsLabelStyle,\n ),\n ),\n epayoutsFieldChrome: pickEnum<CardFieldChrome>(\n root['epayoutsFieldChrome'],\n CARD_FIELD_CHROMES,\n pickEnum<CardFieldChrome>(\n root['paypalFieldChrome'],\n CARD_FIELD_CHROMES,\n dflt.epayoutsFieldChrome,\n ),\n ),\n epayoutsFieldFontSize: pickEnum<CardFieldFontSize>(\n root['epayoutsFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n pickEnum<CardFieldFontSize>(\n root['paypalFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.epayoutsFieldFontSize,\n ),\n ),\n epayoutsFieldWeight: pickEnum<CardFieldWeight>(\n root['epayoutsFieldWeight'],\n CARD_FIELD_WEIGHTS,\n pickEnum<CardFieldWeight>(\n root['paypalFieldWeight'],\n CARD_FIELD_WEIGHTS,\n dflt.epayoutsFieldWeight,\n ),\n ),\n epayoutsFocusRing: pickEnum<CardFocusRing>(\n root['epayoutsFocusRing'],\n CARD_FOCUS_RINGS,\n pickEnum<CardFocusRing>(root['paypalFocusRing'], CARD_FOCUS_RINGS, dflt.epayoutsFocusRing),\n ),\n epayoutsValidTint: parseBool(\n root['epayoutsValidTint'],\n parseBool(root['paypalValidTint'], dflt.epayoutsValidTint),\n ),\n nomupayFormStyle: pickEnum<NomupayFormStyle>(\n root['nomupayFormStyle'],\n NOMUPAY_FORM_STYLES,\n dflt.nomupayFormStyle,\n ),\n nomupayShowLabels: parseBool(root['nomupayShowLabels'], dflt.nomupayShowLabels),\n nomupayShowPlaceholders: parseBool(\n root['nomupayShowPlaceholders'],\n dflt.nomupayShowPlaceholders,\n ),\n nomupayShowCvvHint: parseBool(root['nomupayShowCvvHint'], dflt.nomupayShowCvvHint),\n nomupayFieldChrome: pickEnum<CardFieldChrome>(\n root['nomupayFieldChrome'],\n CARD_FIELD_CHROMES,\n dflt.nomupayFieldChrome,\n ),\n nomupayFieldFontSize: pickEnum<CardFieldFontSize>(\n root['nomupayFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.nomupayFieldFontSize,\n ),\n nomupayFocusRing: pickEnum<CardFocusRing>(\n root['nomupayFocusRing'],\n CARD_FOCUS_RINGS,\n dflt.nomupayFocusRing,\n ),\n nomupayApplePayButtonStyle: pickEnum<ApplePayButtonStyle>(\n root['nomupayApplePayButtonStyle'],\n APPLE_PAY_BUTTON_STYLES,\n dflt.nomupayApplePayButtonStyle,\n ),\n nomupayApplePayButtonType: pickEnum<ApplePayButtonType>(\n root['nomupayApplePayButtonType'],\n APPLE_PAY_BUTTON_TYPES,\n dflt.nomupayApplePayButtonType,\n ),\n nomupayGooglePayButtonColor: pickEnum<GooglePayButtonColor>(\n root['nomupayGooglePayButtonColor'],\n GOOGLE_PAY_BUTTON_COLORS,\n dflt.nomupayGooglePayButtonColor,\n ),\n nomupayGooglePayButtonType: pickEnum<GooglePayButtonType>(\n root['nomupayGooglePayButtonType'],\n GOOGLE_PAY_BUTTON_TYPES,\n dflt.nomupayGooglePayButtonType,\n ),\n\n customCss: sStr(root['customCss'], dflt.customCss).slice(0, CUSTOM_CSS_MAX_LENGTH),\n ...decodeEnigmaCardForm(root),\n };\n}\n\nfunction isObject(v: unknown): v is Record<string, unknown> {\n return typeof v === 'object' && v !== null && !Array.isArray(v);\n}\n\n// Loose trust-badge parser used by the importer. Unlike `decodeBadges`\n// (which reads the JSON-stringified API bag), this accepts an array of\n// objects directly. Returns null when the input isn't an array — the\n// caller falls back to the default badge set; an explicit empty array is\n// honored.\nfunction parseTrustBadgesLoose(raw: unknown): TrustBadge[] | null {\n if (!Array.isArray(raw)) return null;\n return raw\n .filter(isObject)\n .map((b, i) => ({\n id: typeof b['id'] === 'string' && b['id'] ? (b['id'] as string) : `badge-${i}`,\n label: typeof b['label'] === 'string' ? (b['label'] as string) : '',\n textColor:\n typeof b['textColor'] === 'string' && isHexColor(b['textColor'] as string)\n ? (b['textColor'] as string)\n : '#0f172a',\n backgroundColor:\n typeof b['backgroundColor'] === 'string' && isHexColor(b['backgroundColor'] as string)\n ? (b['backgroundColor'] as string)\n : '#f1f5f9',\n borderColor:\n typeof b['borderColor'] === 'string' && isHexColor(b['borderColor'] as string)\n ? (b['borderColor'] as string)\n : null,\n }))\n .filter((b) => b.label.length > 0);\n}\n\n// --- DOM helpers --------------------------------------------------------\n\n// Write branding tokens onto a target element as CSS custom properties.\n// The buyer-facing checkout sets these on `<html>` so every component sees\n// the same set, including Stripe Elements (indirectly via\n// appearance.variables). The merchant dashboard's preview component\n// uses an analogous `--p-*` set with `var(--dp-*, fallback)` indirection so\n// a custom-CSS rule like `:root{--dp-primary:red}` overrides the preview\n// without re-typing the whole brand.\nexport function applyBrandingVariables(el: HTMLElement, b: CheckoutBranding): void {\n const set = (k: string, v: string) => {\n el.style.setProperty(k, v);\n };\n\n set('--dp-primary', b.primary);\n set('--dp-bg', b.background);\n set('--dp-surface', b.surface);\n set('--dp-text', b.text);\n set('--dp-heading', b.heading);\n set('--dp-muted', b.muted);\n set('--dp-border', b.border);\n set('--dp-accent-text', b.accentText);\n set('--dp-btn-bg', b.buttonBackground);\n set('--dp-btn-fg', b.buttonText);\n\n set('--dp-radius-surface', radiusValue(b.radiusSurface));\n set('--dp-radius-input', radiusValue(b.radiusInput));\n set('--dp-radius-button', radiusValue(b.radiusButton));\n set('--dp-radius-badge', radiusValue(b.radiusBadge));\n\n set('--dp-font', fontStack(b.fontFamily));\n set('--dp-heading-weight', fontWeightValue(b.headingWeight));\n\n set('--dp-pad-surface', SURFACE_PAD[b.surfacePadding]);\n set('--dp-gap-vertical', VERTICAL_GAP[b.verticalGap]);\n set('--dp-input-pad', INPUT_PAD[b.inputSize]);\n set('--dp-button-pad', BUTTON_PAD[b.buttonSize]);\n\n // Published whatever `showSurcharge` says: the flag decides whether a figure\n // renders, not what colour it would be, and a stylesheet that reads the\n // variable must not get an empty string when the merchant has one configured.\n set('--dp-surcharge', b.surchargeColor);\n set('--dp-discount', b.discountColor);\n // What `solid` writes ON the fill. Computed here rather than in a stylesheet\n // because CSS cannot ask a colour how light it is, and picking one fixed ink\n // would make either a pale amber or a deep emerald unreadable.\n set('--dp-surcharge-ink', readableInkOn(b.surchargeColor));\n set('--dp-discount-ink', readableInkOn(b.discountColor));\n set('--dp-surcharge-size', SURCHARGE_FONT_SIZE[b.surchargeSize]);\n set('--dp-surcharge-pad', SURCHARGE_PAD[b.surchargeSize]);\n set('--dp-surcharge-radius', SURCHARGE_RADIUS[b.surchargeShape]);\n set('--dp-surcharge-weight', SURCHARGE_FONT_WEIGHT[b.surchargeWeight]);\n // `outline` draws nothing BUT its border, so `none` there would erase the\n // style rather than restyle it — it reads as `thin` instead.\n set(\n '--dp-surcharge-border-width',\n SURCHARGE_BORDER_WIDTH[\n b.surchargeStyle === 'outline' && b.surchargeBorderWidth === 'none'\n ? 'thin'\n : b.surchargeBorderWidth\n ],\n );\n set('--dp-surcharge-border-style', b.surchargeBorderStyle);\n\n set('--dp-shadow', shadowFor(b.surfaceStyle));\n set(\n '--dp-surface-border',\n b.surfaceStyle === 'outlined' ? `1px solid ${b.border}` : '1px solid transparent',\n );\n}\n\nexport function shadowFor(style: SurfaceStyle): string {\n switch (style) {\n case 'elevated':\n return '0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 32px -12px rgba(15, 23, 42, 0.08)';\n case 'outlined':\n case 'flat':\n default:\n return 'none';\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["/tmp/sdk-pub-w3/dist/chunk-LYIBTVK6.cjs","../src/branding.ts"],"names":["s"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACkOO,SAAS,mBAAA,CACd,SAAA,EACA,KAAA,EACA,QAAA,EACS;AACT,EAAA,GAAA,CAAI,UAAA,IAAc,UAAA,EAAY,OAAO,KAAA;AACrC,EAAA,OAAO,CAAA,CAAE,MAAA,IAAU,SAAA,GAAA,CAAa,SAAA,IAAa,cAAA,GAAiB,SAAA,IAAa,WAAA,CAAA,CAAA;AAC7E;AAwCO,SAAS,mBAAA,CACd,QAAA,EAIA,UAAA,EACA,gBAAA,EACqB;AACrB,EAAA,MAAM,KAAA,EAAO,WAAA,EAAa,QAAA,CAAS,eAAA,EAAiB,QAAA,CAAS,eAAA;AAC7D,EAAA,MAAM,MAAA,EAAQ,mBAAA;AAAA,IACZ,QAAA,CAAS,cAAA;AAAA,IACT,QAAA,CAAS,cAAA;AAAA,IACT,QAAA,CAAS;AAAA,EACX,CAAA;AAGA,EAAA,GAAA,CAAI,CAAC,gBAAA,E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AA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACA,IAAA;AACM,IAAA;AACN,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AAEA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AAEA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AAEA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AAEA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AAA8C;AAAA;AAAA;AAAA;AAAA;AAO9C,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AAEA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AAAsF;AAAA;AAGtF,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AAEA,IAAA;AAEG,IAAA;AACL,EAAA;AACF;AAiCgB;AAIR,EAAA;AACE,IAAA;AACN,IAAA;AACF,EAAA;AAIM,EAAA;AAGA,EAAA;AACJ,IAAA;AACM,IAAA;AACN,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;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A;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AAAA;AAAA;AAGA,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACE,MAAA;AACC,MAAA;AACD,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AAAkE;AAAA;AAAA;AAAA;AAAA;AAOlE,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACF,IAAA;AACA,IAAA;AAAwE;AAAA;AAGxE,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAAA;AACA,IAAA;AACE,MAAA;AACA,MAAA;AACA,MAAA;AACE,QAAA;AACA,QAAA;AACA,QAAA;AACF,MAAA;AACF,IAA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AEgB;AACN,EAAA;AACD,IAAA;AACH,MAAA;AACG,IAAA;AACA,IAAA;AACL,IAAA;AACE,MAAA;AACJ,EAAA;AACF;ADjzDU;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/tmp/sdk-pub-w3/dist/chunk-LYIBTVK6.cjs","sourcesContent":[null,"// Checkout branding — typed shape, design tokens, palettes, persistence\n// codec, CSS sanitizer, and DOM helpers for `--dp-*` CSS variables.\n//\n// Both the hosted checkout and the dashboard's branding form consume this\n// module.\n//\n// Persistence: top-level fields own the \"loud\" tokens (logo, theme,\n// payment_button_*, background_colour, etc.). Everything else lives in\n// `sdk_ui_rules.branding` as a nested string-keyed map — booleans and\n// numbers round-trip as strings, the trust-badge list is JSON-stringified.\n\nimport {\n AIRWALLEX_AUTOFILL_TREATMENTS,\n AIRWALLEX_CARD_PRESETS,\n AIRWALLEX_FIELD_CHROMES,\n AIRWALLEX_FIELD_FONT_SIZES,\n AIRWALLEX_FIELD_WEIGHTS,\n AIRWALLEX_FOCUS_RINGS,\n AIRWALLEX_LABEL_STYLES,\n type AirwallexAutofillTreatment,\n type AirwallexCardPreset,\n type AirwallexFieldChrome,\n type AirwallexFieldFontSize,\n type AirwallexFieldWeight,\n type AirwallexFocusRing,\n type AirwallexLabelStyle,\n} from './airwallexCard';\nimport {\n APPLE_PAY_BUTTON_STYLES,\n APPLE_PAY_BUTTON_TYPES,\n CARD_FIELD_CHROMES,\n CARD_FIELD_FONT_SIZES,\n CARD_FIELD_WEIGHTS,\n CARD_FOCUS_RINGS,\n GOOGLE_PAY_BUTTON_COLORS,\n GOOGLE_PAY_BUTTON_TYPES,\n NOMUPAY_FORM_STYLES,\n PAYPAL_CARD_LAYOUTS,\n PAYPAL_LABEL_STYLES,\n STRIPE_INPUT_STYLES,\n STRIPE_LABEL_PLACEMENTS,\n STRIPE_SPACINGS,\n STRIPE_THEMES,\n WHOP_ACCENT_COLORS,\n WHOP_BILLING_DETAILS,\n WHOP_CARD_PRESETS,\n WHOP_EMAIL_LABELS,\n WHOP_GRAY_COLORS,\n WHOP_RADII,\n WHOP_SELECTIONS,\n WHOP_SHADOWS,\n type ApplePayButtonStyle,\n type ApplePayButtonType,\n type CardFieldChrome,\n type CardFieldFontSize,\n type CardFieldWeight,\n type CardFocusRing,\n type GooglePayButtonColor,\n type GooglePayButtonType,\n type NomupayFormStyle,\n type PaypalCardLayout,\n type PaypalLabelStyle,\n type StripeInputStyle,\n type StripeLabelPlacement,\n type StripeSpacing,\n type StripeTheme,\n type WhopAccentColor,\n type WhopBillingDetails,\n type WhopCardPreset,\n type WhopEmailLabel,\n type WhopRadius,\n type WhopSelection,\n type WhopShadow,\n type WhopGrayColor,\n} from './cardFormStyles';\nimport type { VaultFormAppearance } from './types';\nimport {\n decodeEnigmaCardForm,\n DEFAULT_ENIGMA_CARD_FORM,\n encodeEnigmaCardForm,\n enigmaNamesInside,\n type EnigmaCardFormSettings,\n} from './enigmaCardForm';\n\n// --- Types --------------------------------------------------------------\n\nexport type CornerRadius = 'square' | 'small' | 'medium' | 'large' | 'pill';\n\n// Surfaces and inputs never make sense pill-shaped (a pill input ends up with\n// half-circle ends crammed against text). The form picker only exposes these\n// four; if a stale 'pill' value lands here from older saved data, decode\n// drops it back to 'medium'. Buttons and badges still allow 'pill'.\nexport type NonPillRadius = Exclude<CornerRadius, 'pill'>;\n\n// Spacing scales — split apart so the merchant can independently tune\n// surface padding, vertical rhythm, input height and pay-button height. Used\n// to live as a single `density` enum but that conflated four dimensions.\nexport type SpacingScale = 'compact' | 'comfortable' | 'spacious';\nexport type SizeScale = 'sm' | 'md' | 'lg';\nexport type SurfaceStyle = 'flat' | 'outlined' | 'elevated';\n\nexport type FontFamily =\n | 'inter'\n | 'system'\n | 'serif'\n | 'mono'\n | 'roboto'\n | 'poppins'\n | 'manrope'\n | 'dm-sans'\n | 'space-grotesk'\n | 'plex-sans'\n | 'work-sans'\n | 'open-sans'\n | 'lora'\n | 'playfair'\n | 'plex-mono'\n | 'jetbrains-mono';\n\nexport type FontWeight = 'regular' | 'medium' | 'semibold' | 'bold';\nexport type LayoutStyle = 'compact' | 'split';\nexport type SummaryPosition = 'left' | 'right';\n\n// Stripe Elements only supports two label modes (\"above\" or hidden via the\n// .Label-collapse hack); a \"floating\" label is not a Stripe concept and\n// would only render in our own mock — preview was lying about it. Persisted\n// `'floating'` is silently decoded to `'above'` for back-compat.\nexport type LabelStyle = 'above' | 'hidden';\n\n// Stripe Elements layout. Honored inside the StripeCardPane only — other\n// connector panes stack vertically regardless of this setting.\nexport type PaymentLayout = 'tabs' | 'accordion' | 'spaced_accordion';\n\nexport type LogoShape = 'square' | 'rounded' | 'circle';\nexport type LogoSize = 'sm' | 'md' | 'lg';\n\n// --- Provider surcharge / discount disclosure ---------------------------\n//\n// With surcharges scoped to the provider rather than to the payment method,\n// two tiles on one checkout can cost the buyer different amounts — so the\n// figure has to be legible on the tile, before the choice, not only in the\n// breakdown after it. These control how that figure is painted; whether there\n// is one at all is the router's answer, per pane.\n//\n// Nothing here can invent a figure or change one. A merchant who would rather\n// not disclose per-tile turns it off with `showSurcharge` and keeps the\n// breakdown inside the pane, which is where the disclosure lived before.\n\n// Where the figure sits relative to the tile's label.\n//\n// `inline` follows the label text immediately, so the price reads as part of\n// the name — good for short labels.\n// `trailing` pushes it to the tile's trailing edge on the label's own line: the\n// price reads as a property of the tile, and the tile's height does not change,\n// which matters because most tiles carry no figure at all and a row that grows\n// only for some of them makes the list look ragged.\n// `below` puts it under the sublabel, for merchants whose labels are long\n// enough that a trailing figure would crowd them.\n// `above` puts it over the label as an eyebrow, which is the one position that\n// reads before the method name rather than after it.\nexport type SurchargePosition =\n | 'inline'\n | 'trailing'\n | 'below'\n | 'above'\n | 'cornerStart'\n | 'cornerEnd';\n\n// Where the rows drawn as the wallet's OWN button (Apple Pay / Google Pay with\n// `native_element` applying in this render) are placed.\n//\n// Not within their section — they leave it. Every such row is lifted out of the\n// catalogue into one express strip, and this says where on the payment surface\n// that strip goes:\n//\n// `top` above everything, the custom fields included;\n// `belowFields` under the merchant's custom fields, still above the card form\n// and every section;\n// `belowCard` directly under the card form, above the remaining sections\n// (with no card form in this render, it falls back to\n// `belowFields`);\n// `bottom` under the last section, the last thing offered.\n//\n// The rows keep their own relative order in the strip whichever end it sits at.\n// Decided from the pane's setting for the render context, not from a later\n// fallback to the tile, so a row never moves under the buyer.\nexport type NativeElementPosition = 'top' | 'belowFields' | 'belowCard' | 'bottom';\n\n// How the figure is painted.\n//\n// `plain` is text in the configured colour. `badge` fills the shape with a tint\n// of it. `outline` draws the border only — the middle weight, for a checkout\n// whose tiles are already busy. `solid` fills with the colour itself and writes\n// on it in whichever of black or white reads better, which is the loudest\n// option and the one to reach for when the figure must not be missed.\n// `underline` keeps the text weight of `plain` and adds a rule beneath it.\n// `ribbon` runs the figure diagonally across a corner of the tile — the one\n// treatment that reads before the label rather than beside it, for a merchant\n// steering hard toward a cheaper provider.\nexport type SurchargeStyle = 'plain' | 'badge' | 'outline' | 'solid' | 'underline' | 'ribbon';\n\n// The border drawn around the shapes `badge`, `outline`, `solid` and `ribbon`\n// paint. `outline` draws nothing BUT its border, so `none` there would erase\n// the style rather than restyle it and reads as `thin` instead.\nexport type SurchargeBorderWidth = 'none' | 'thin' | 'medium' | 'thick';\n\n// How that border is drawn. `dashed` and `dotted` read as provisional, which\n// suits a promotional discount; `solid` is the neutral default.\nexport type SurchargeBorderStyle = 'solid' | 'dashed' | 'dotted';\n\n// The figure's type size, relative to the tile's own text.\nexport type SurchargeSize = 'sm' | 'md' | 'lg';\n\n// The corner treatment of the shapes `badge`, `outline` and `solid` draw.\n// Ignored by `plain` and `underline`, which draw no shape.\nexport type SurchargeShape = 'pill' | 'rounded' | 'square';\n\n// How heavily the figure is set.\nexport type SurchargeWeight = 'regular' | 'medium' | 'bold';\n\n// Whether the figure carries an explicit sign.\n//\n// `always` writes `+` on a surcharge and `−` on a discount (U+2212, not a\n// hyphen, so it aligns with the digits). `minusOnly` writes the minus and\n// leaves a surcharge unsigned, which reads as a price rather than as an\n// adjustment. `none` writes neither and leans entirely on the two colours —\n// legible only when a merchant configures one direction, and offered because a\n// merchant who only ever discounts should not have to explain a plus sign.\nexport type SurchargeSign = 'always' | 'minusOnly' | 'none';\n\n// Whether the figure names itself.\n//\n// `amount` is the figure alone. `labelled` prefixes the localized word for the\n// direction (\"Surcharge\" / \"Discount\"), which costs horizontal room and buys a\n// tile nobody has to interpret.\nexport type SurchargeLabelMode = 'amount' | 'labelled';\n\n// WHICH figure the tile prints, and in which order when it prints both.\n//\n// A discount and a surcharge are the same mechanism pointed in opposite\n// directions, but they are not the same message: a saving is something a\n// merchant advertises and a percentage is the persuasive half of it (\"20%\n// off\"), while a fee is something a merchant discloses and the money is the\n// half the buyer actually cares about. So the two directions carry this\n// setting separately — `discountFigure` and `surchargeFigure` — rather than\n// sharing one.\n//\n// The two figures always describe the same money. The router derives the\n// percentage from the charge rather than from the merchant's rule, so a fixed\n// rule states its share of this cart and a taxed rate states the share the\n// buyer actually pays. That is what makes showing either — or both — safe.\nexport type SurchargeFigureMode = 'amount' | 'percent' | 'amountThenPercent' | 'percentThenAmount';\n\n/**\n * Whether the tile has room to print the wording alongside the figure.\n *\n * One pairing says no: the diagonal ribbon at either corner. That band is\n * clipped by the tile it crosses, and the readable length is set by how far the\n * corner is inset — roughly 75px on a standard payment tile, against roughly\n * 107px for a labelled figure at the default size. Printing the word there\n * clips the *figure*, and a half-shown price is worse than a plain one, so the\n * word is what gives way.\n *\n * Exported, and shared by the buyer-facing checkout and the dashboard's live\n * preview, because the two must reach the same answer. A preview that promises\n * a word the checkout will not print is the one failure a preview cannot have.\n */\nexport function surchargeShowsLabel(\n labelMode: SurchargeLabelMode,\n style: SurchargeStyle,\n position: SurchargePosition,\n): boolean {\n if (labelMode !== 'labelled') return false;\n return !(style === 'ribbon' && (position === 'cornerStart' || position === 'cornerEnd'));\n}\n\n/** One of the two things a tile can print. */\nexport type SurchargeFigurePart = 'amount' | 'percent';\n\n/** Exactly what one tile prints, in order. See {@link surchargeFigurePlan}. */\nexport interface SurchargeFigurePlan {\n /** The leading figure. Always present — a tile with nothing to say renders nothing at all. */\n first: SurchargeFigurePart;\n /** The trailing figure, parenthesised by the renderer, or `null` for one figure. */\n second: SurchargeFigurePart | null;\n /** Whether the localized direction word prefixes the whole thing. */\n label: boolean;\n}\n\n/**\n * What one tile prints: which figures, in which order, and whether the word\n * comes with them.\n *\n * One function rather than a rule per surface, because the buyer-facing tile\n * and the dashboard's live preview must reach the same answer. A preview that\n * shows a percentage the checkout will not print — or prints in the other\n * order — is the one failure a preview cannot have.\n *\n * Three things it decides, in order of how much they cost to get wrong:\n *\n * * **No percentage available, no percentage printed.** `percentAvailable` is\n * false when the router sent none, which happens on an order of zero. A\n * merchant who asked for `percent` gets the amount instead — never a blank\n * tile, and never `0%`. This is the fallback the whole design leans on: the\n * amount is exact in every case, so it is what every degradation lands on.\n * * **A corner ribbon prints one figure.** The band crossing a tile's corner\n * is clipped to roughly 75px of readable length; two figures and a word do\n * not fit, and clipping a *price* is worse than showing less of one. It\n * keeps the merchant's leading figure — their own statement of which half\n * matters — and drops the trailing one along with the word.\n * * **Direction picks the setting.** `discountFigure` for a credit,\n * `surchargeFigure` for a charge, because a saving and a fee are not the\n * same message even though they are the same mechanism.\n */\nexport function surchargeFigurePlan(\n branding: Pick<\n CheckoutBranding,\n 'surchargeFigure' | 'discountFigure' | 'surchargeLabel' | 'surchargeStyle' | 'surchargePosition'\n >,\n isDiscount: boolean,\n percentAvailable: boolean,\n): SurchargeFigurePlan {\n const mode = isDiscount ? branding.discountFigure : branding.surchargeFigure;\n const label = surchargeShowsLabel(\n branding.surchargeLabel,\n branding.surchargeStyle,\n branding.surchargePosition,\n );\n\n // Money only, whatever was asked for: there is no second figure to state.\n if (!percentAvailable) return { first: 'amount', second: null, label };\n\n const ordered: Record<SurchargeFigureMode, [SurchargeFigurePart, SurchargeFigurePart | null]> = {\n amount: ['amount', null],\n percent: ['percent', null],\n amountThenPercent: ['amount', 'percent'],\n percentThenAmount: ['percent', 'amount'],\n };\n const [first, second] = ordered[mode];\n\n // The corner ribbon keeps the merchant's leading figure and nothing else.\n // `surchargeShowsLabel` has already dropped the word for the same reason, so\n // this is the same rule applied to the second figure.\n const cornerRibbon =\n branding.surchargeStyle === 'ribbon' &&\n (branding.surchargePosition === 'cornerStart' || branding.surchargePosition === 'cornerEnd');\n\n return { first, second: cornerRibbon ? null : second, label };\n}\n\n/**\n * Black or white, whichever reads better on `color` — for the `solid` style,\n * which writes on the configured colour itself.\n *\n * Picked by contrast rather than by a luminance threshold so the answer is the\n * one WCAG would give, and falls back to white on an unparseable colour, which\n * is what the rest of this module does with a colour it cannot read.\n */\nexport function readableInkOn(color: string): string {\n const onBlack = contrastRatio(color, '#000000');\n const onWhite = contrastRatio(color, '#ffffff');\n if (onBlack === null || onWhite === null) return '#ffffff';\n return onBlack >= onWhite ? '#000000' : '#ffffff';\n}\n\n/** Type size per {@link SurchargeSize}, relative to the tile's own text. */\nconst SURCHARGE_FONT_SIZE: Record<SurchargeSize, string> = {\n sm: '0.6875rem',\n md: '0.8125rem',\n lg: '0.9375rem',\n};\n\n/** Shape padding per {@link SurchargeSize}. Grows with the type. */\nconst SURCHARGE_PAD: Record<SurchargeSize, string> = {\n sm: '1px 6px',\n md: '2px 8px',\n lg: '3px 10px',\n};\n\n/** Corner radius per {@link SurchargeShape}. */\nconst SURCHARGE_RADIUS: Record<SurchargeShape, string> = {\n pill: '999px',\n rounded: '6px',\n square: '0px',\n};\n\n/** Border thickness per {@link SurchargeBorderWidth}. */\nconst SURCHARGE_BORDER_WIDTH: Record<SurchargeBorderWidth, string> = {\n none: '0px',\n thin: '1px',\n medium: '2px',\n thick: '3px',\n};\n\n/** Font weight per {@link SurchargeWeight}. */\nconst SURCHARGE_FONT_WEIGHT: Record<SurchargeWeight, string> = {\n regular: '400',\n medium: '600',\n bold: '700',\n};\n\n/**\n * The values each disclosure axis accepts, in the order a picker should offer\n * them: quietest first, so a merchant scrolling down is turning the figure up.\n *\n * Exported because both the dashboard's picker and this module's decoder need\n * the same list, and a picker offering a value the decoder rejects is a control\n * that silently does nothing.\n */\nexport const SURCHARGE_POSITIONS: readonly SurchargePosition[] = [\n 'trailing',\n 'inline',\n 'below',\n 'above',\n 'cornerStart',\n 'cornerEnd',\n];\n// Ordered as they read down the page, which is the order the dashboard's select\n// offers them in.\nexport const NATIVE_ELEMENT_POSITIONS: readonly NativeElementPosition[] = [\n 'top',\n 'belowFields',\n 'belowCard',\n 'bottom',\n];\nexport const SURCHARGE_STYLES: readonly SurchargeStyle[] = [\n 'plain',\n 'underline',\n 'outline',\n 'badge',\n 'solid',\n 'ribbon',\n];\nexport const SURCHARGE_BORDER_WIDTHS: readonly SurchargeBorderWidth[] = [\n 'none',\n 'thin',\n 'medium',\n 'thick',\n];\nexport const SURCHARGE_BORDER_STYLES: readonly SurchargeBorderStyle[] = [\n 'solid',\n 'dashed',\n 'dotted',\n];\nexport const SURCHARGE_SIZES: readonly SurchargeSize[] = ['sm', 'md', 'lg'];\n\n/**\n * Whether a style draws a shape behind the figure, and therefore whether\n * {@link SurchargeShape} means anything for it.\n *\n * `plain` and `underline` paint text. A dashboard that leaves the corner picker\n * live under them offers a control that changes nothing on screen, which is how\n * a merchant decides the whole panel is broken; one that hides it loses their\n * choice when they switch back. Disabled is the answer, and this is the\n * predicate it needs.\n */\nexport function surchargeStyleDrawsAShape(style: SurchargeStyle): boolean {\n return style === 'badge' || style === 'outline' || style === 'solid';\n}\nexport const SURCHARGE_SHAPES: readonly SurchargeShape[] = ['pill', 'rounded', 'square'];\nexport const SURCHARGE_WEIGHTS: readonly SurchargeWeight[] = ['regular', 'medium', 'bold'];\nexport const SURCHARGE_SIGNS: readonly SurchargeSign[] = ['always', 'minusOnly', 'none'];\nexport const SURCHARGE_LABEL_MODES: readonly SurchargeLabelMode[] = ['amount', 'labelled'];\nexport const SURCHARGE_FIGURE_MODES: readonly SurchargeFigureMode[] = [\n 'amount',\n 'percent',\n 'amountThenPercent',\n 'percentThenAmount',\n];\n\n/**\n * The buyer locales the checkout ships copy for, and therefore the ones a\n * merchant can override.\n *\n * Driven from here rather than restated in the dashboard, so a locale added to\n * the checkout cannot leave the dashboard offering one fewer box than the\n * buyer-facing render reads.\n */\nexport const CHECKOUT_LOCALES = [\n 'en',\n 'de',\n 'fr',\n 'es',\n 'it',\n 'nl',\n // Simplified and traditional are separate dictionaries in the checkout,\n // not region variants: they use different characters, so a merchant who\n // writes one has not written the other.\n 'zh',\n 'zh-Hant',\n 'hi',\n 'ar',\n] as const;\nexport type CheckoutLocale = (typeof CHECKOUT_LOCALES)[number];\n\n/**\n * Locales written right-to-left, for a UI that renders a merchant's override\n * next to the others.\n *\n * A dashboard field holding Arabic needs `dir=\"rtl\"` on the input itself:\n * without it the caret jumps, punctuation lands on the wrong end, and what the\n * merchant types is not what the buyer will see. Exported rather than kept in\n * the dashboard so the buyer-facing checkout and the editor agree on which\n * locales that is.\n */\nexport const RTL_CHECKOUT_LOCALES: readonly CheckoutLocale[] = ['ar'];\n\n/**\n * `dir` for a checkout locale — `'rtl'` for Arabic, `'ltr'` for the rest.\n *\n * Resolved on the **base language**, the same way `checkoutCopy` resolves an\n * override. Comparing the full string looked equivalent and was not: a buyer\n * sending `ar-EG` gets the `ar` copy from `checkoutCopy` and would have got\n * `ltr` from here — Arabic text in a left-to-right layout, which is the exact\n * failure this function exists to prevent. Case is folded for the same reason;\n * `Accept-Language` may arrive as `AR`.\n */\nexport function checkoutLocaleDir(locale: string): 'ltr' | 'rtl' {\n const base = String(locale ?? '')\n .toLowerCase()\n .split('-')[0];\n return (RTL_CHECKOUT_LOCALES as readonly string[]).includes(base) ? 'rtl' : 'ltr';\n}\n\n/**\n * The copy fields a merchant may write once per locale.\n *\n * Each has a flat `<field>` and a `<field>Translations` map beside it. The flat\n * value is what every existing merchant already has and stays authoritative\n * wherever no override is set — which is what makes this additive: a profile\n * saved before translations existed renders exactly as it did, in every locale.\n */\nexport const LOCALIZABLE_COPY_FIELDS = [\n 'headerText',\n 'payButtonLabel',\n 'cardTermsMessage',\n 'footerText',\n] as const;\nexport type LocalizableCopyField = (typeof LOCALIZABLE_COPY_FIELDS)[number];\n\n/** The translations key that belongs to a copy field. */\nexport function copyTranslationsKey(\n field: LocalizableCopyField,\n): `${LocalizableCopyField}Translations` {\n return `${field}Translations`;\n}\n\n/**\n * One piece of merchant copy, in the buyer's locale.\n *\n * Exact locale wins (`de-AT`), then its base language (`de`), then the flat\n * field — the same order `customFieldText` resolves in, because a merchant who\n * has learnt one of these should not have to learn the other.\n *\n * Returning the flat value rather than `''` is the backward-compatibility\n * guarantee: an override is an addition to what a merchant already wrote, never\n * a replacement for it, so an empty or missing map changes nothing.\n */\nexport function checkoutCopy(\n branding: CheckoutBranding,\n field: LocalizableCopyField,\n locale?: string,\n): string {\n const translated = translationFor(branding[copyTranslationsKey(field)], locale);\n return translated ?? branding[field];\n}\n\n/**\n * The merchant's own word for one direction, or `null` to use the checkout's\n * built-in one.\n *\n * `null` rather than a default string because the fallback is *localized* and\n * lives in the buyer-facing bundle — this module has no i18n of its own, and\n * inventing an English default here would print \"Discount\" to a German buyer.\n *\n * A merchant who sets nothing therefore keeps the shipped wording in both\n * languages, which is the intended default and already reads well.\n */\nexport function surchargeWordFor(\n branding: Pick<CheckoutBranding, 'surchargeWordTranslations' | 'discountWordTranslations'>,\n isDiscount: boolean,\n locale?: string,\n): string | null {\n return translationFor(\n isDiscount ? branding.discountWordTranslations : branding.surchargeWordTranslations,\n locale,\n );\n}\n\nexport interface TrustBadge {\n id: string;\n label: string;\n textColor: string;\n backgroundColor: string;\n borderColor: string | null;\n}\n\n// --- Notices -------------------------------------------------\n//\n// A notice is one short reassurance line on the checkout — a line icon and a\n// text — in one of two places. It replaces the trust badges as the default:\n// a badge carries its own three colours, so every theme had to recolour the\n// stock pair and a dark theme still wore light chips; a notice\n// carries none and is drawn in the checkout's own muted text and accent\n// colour, so it follows whatever palette the merchant picks. Its text is\n// written per locale, which a badge's never was.\n//\n// Persisted JSON-stringified under `sdk_ui_rules.branding.notices`, the same\n// transport as `trustBadges` and `customFields`.\n\n/**\n * Where a notice is drawn.\n *\n * - `summary`: under the order summary in the split layout; under the compact\n * header when there is no summary pane.\n * - `payment`: at the bottom of the payment element, under the pay button.\n */\nexport type NoticeSection = 'summary' | 'payment';\nexport const NOTICE_SECTIONS: readonly NoticeSection[] = ['summary', 'payment'];\n\n/**\n * How many notices one section draws. More than three stops reading as\n * reassurance and starts reading as small print, so the decoder drops the\n * overflow and the editor refuses a fourth.\n */\nexport const NOTICES_PER_SECTION = 3;\n\n/** Longest notice text, per locale. A notice is one line, not a paragraph. */\nexport const NOTICE_LABEL_MAX_LENGTH = 80;\n\n/** The marks a notice can carry, in the order the editor's grid offers them. */\nexport const NOTICE_ICONS = [\n 'lock',\n 'shield',\n 'check',\n 'truck',\n 'package',\n 'refresh',\n 'star',\n 'support',\n 'globe',\n 'tag',\n 'heart',\n 'leaf',\n 'clock',\n 'bank',\n] as const;\nexport type NoticeIcon = (typeof NOTICE_ICONS)[number];\n\n/** What an unknown or missing icon decodes to. */\nexport const NOTICE_ICON_FALLBACK: NoticeIcon = 'check';\n\n/**\n * Each mark as SVG path data on a 24×24 grid, stroked (not filled) with round\n * caps and joins.\n *\n * Kept here rather than drawn twice so the checkout and the customizer's icon\n * grid cannot disagree about what \"shield\" looks like: both render these\n * strings, and a mark added to `NOTICE_ICONS` without paths is a type error.\n * Every shape is a `<path>` — circles, rectangles and polylines included —\n * so a renderer needs one element type and no per-icon template.\n */\nexport const NOTICE_ICON_PATHS: Readonly<Record<NoticeIcon, readonly string[]>> = {\n lock: [\n 'M6 10h12a2 2 0 0 1 2 2v7a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2z',\n 'M8 10V7a4 4 0 0 1 8 0v3',\n ],\n shield: ['M12 3l7 3v6c0 4.2-2.9 7.6-7 9-4.1-1.4-7-4.8-7-9V6z', 'M9 12l2.5 2.5 4-4.5'],\n check: ['M21 12a9 9 0 1 1-18 0a9 9 0 1 1 18 0z', 'M8 12.5l3 3 5-6'],\n truck: [\n 'M3 7.5h10v9H3z',\n 'M13 11h4l3 3v2.5h-7z',\n 'M8.8 18a1.8 1.8 0 1 1-3.6 0a1.8 1.8 0 1 1 3.6 0z',\n 'M18.8 18a1.8 1.8 0 1 1-3.6 0a1.8 1.8 0 1 1 3.6 0z',\n ],\n package: [\n 'M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z',\n 'M12 22V12',\n 'M3.29 7L12 12l8.71-5',\n ],\n refresh: ['M20 12a8 8 0 1 1-2.5-5.8', 'M20 4v5h-5'],\n star: ['m12 3.6 2.6 5.3 5.9.9-4.3 4.1 1 5.8-5.2-2.7-5.2 2.7 1-5.8-4.3-4.1 5.9-.9z'],\n support: [\n 'M5 13v-1a7 7 0 0 1 14 0v1',\n 'M3.5 14.5a1.8 1.8 0 0 1 1.8-1.8H7v5H5.3a1.8 1.8 0 0 1-1.8-1.8z',\n 'M20.5 14.5a1.8 1.8 0 0 0-1.8-1.8H17v5h1.7a1.8 1.8 0 0 0 1.8-1.8z',\n 'M19 17.7v.8a2.5 2.5 0 0 1-2.5 2.5H13',\n ],\n globe: [\n 'M21 12a9 9 0 1 1-18 0a9 9 0 1 1 18 0z',\n 'M3 12h18',\n 'M12 3a14 14 0 0 1 0 18a14 14 0 0 1 0-18z',\n ],\n tag: ['M11 3H4v7l10 10 7-7z', 'M9.1 7a1.3 1.3 0 1 1-2.6 0a1.3 1.3 0 1 1 2.6 0z'],\n heart: ['M12 20s-7-4.4-7-9.3A3.9 3.9 0 0 1 12 8a3.9 3.9 0 0 1 7 2.7c0 4.9-7 9.3-7 9.3z'],\n leaf: ['M20 4c0 9-5.4 13-9.5 13A4.5 4.5 0 0 1 6 12.5C6 7 12 4 20 4z', 'M4 20c2-4.5 5-7.5 9-9.5'],\n clock: ['M21 12a9 9 0 1 1-18 0a9 9 0 1 1 18 0z', 'M12 7v5l3 2'],\n bank: ['M3 9.5 12 4l9 5.5', 'M5 10v8M9.5 10v8M14.5 10v8M19 10v8', 'M3 20h18'],\n};\n\nexport function isNoticeIcon(value: unknown): value is NoticeIcon {\n return typeof value === 'string' && (NOTICE_ICONS as readonly string[]).includes(value);\n}\n\nexport interface CheckoutNotice {\n /** Stable across edits and drags; `[A-Za-z0-9_-]`, at most 40 characters. */\n id: string;\n section: NoticeSection;\n icon: NoticeIcon;\n /** Default-language text, and what every locale without an override reads. */\n label: string;\n /** Per-locale overrides of `label`; a blank entry means \"use `label`\". */\n labelTranslations: CustomFieldTranslations;\n}\n\n// Merchant-defined checkout inputs. Rendered by the buyer-facing checkout\n// above the payment surface; submitted values land in the payment's\n// `metadata` under each field's `key`. Persisted JSON-stringified under\n// `sdk_ui_rules.branding.customFields` (same transport as trustBadges).\n// `checkbox` is a single opt-in box (terms acceptance, marketing consent),\n// not a multi-select. Its submitted value is always the string `'true'` or\n// `'false'` — never absent — so a merchant can tell \"declined\" from \"never\n// asked\" in the payment's metadata, which is what makes it usable as a\n// consent record. See `CHECKBOX_CHECKED` / `isCheckboxChecked`.\nexport type CustomFieldType = 'text' | 'textarea' | 'password' | 'email' | 'select' | 'checkbox';\n\n// Per-locale overrides ('de', 'en', …). Missing locale falls back to the\n// default-language string on the field itself — see `customFieldText`.\nexport type CustomFieldTranslations = Record<string, string>;\n\nexport interface CustomFieldOption {\n value: string;\n label: string;\n labelTranslations: CustomFieldTranslations;\n}\n\n// --- Conditional visibility ---------------------------------------------\n//\n// A field can be gated on facts the payment already carries when the\n// checkout renders: the intent's `metadata` (which a shop integration fills\n// per product/category — see the WordPress plugin's product metadata), its\n// `currency`, or its `amount`. This is what lets one profile serve a\n// \"Windows key\" order (no fields) and a \"Spotify account\" order (login\n// fields) without two shops.\n//\n// Evaluation is authoritative on the **backend**: `form_payment_link_data`\n// drops non-matching fields from the payload the buyer's browser receives,\n// so merchant metadata never leaves the server and the rules can't be\n// tampered with client-side. The implementation here is the shared\n// specification (and drives the dashboard's builder); the API applies the\n// same rules and must stay behaviorally identical.\nexport type CustomFieldConditionSource = 'metadata' | 'currency' | 'amount';\n\n// String operators apply to metadata + currency; numeric ones (`gt`…`lte`)\n// apply to amount and to metadata values that parse as numbers.\nexport type CustomFieldOperator =\n | 'equals'\n | 'not_equals'\n | 'contains'\n | 'not_contains'\n | 'starts_with'\n | 'ends_with'\n | 'in'\n | 'not_in'\n | 'exists'\n | 'not_exists'\n | 'gt'\n | 'gte'\n | 'lt'\n | 'lte';\n\nexport interface CustomFieldCondition {\n // Stable identity for editor list operations (reorder/remove). Not part\n // of the semantics.\n id: string;\n source: CustomFieldConditionSource;\n // Metadata key to read. Ignored (and persisted empty) for currency/amount.\n key: string;\n operator: CustomFieldOperator;\n // Right-hand operand. `in`/`not_in` read it as a comma-separated list;\n // `exists`/`not_exists` ignore it; amount comparisons parse it as an\n // integer in the currency's minor unit (1000 = 10.00).\n value: string;\n}\n\nexport interface CustomFieldVisibility {\n // `always` — unconditional (the default, and what every pre-feature field\n // decodes to). `match` — evaluate `conditions`.\n mode: 'always' | 'match';\n // How to combine multiple conditions.\n match: 'all' | 'any';\n conditions: CustomFieldCondition[];\n}\n\nexport interface CheckoutCustomField {\n // Stable identity for editor list operations (reorder/remove).\n id: string;\n // Metadata key the submitted value is stored under. Must be unique per\n // profile; the editor enforces `CUSTOM_FIELD_KEY_PATTERN`.\n key: string;\n type: CustomFieldType;\n // Default-language copy; `*Translations` maps override per locale.\n label: string;\n labelTranslations: CustomFieldTranslations;\n placeholder: string;\n placeholderTranslations: CustomFieldTranslations;\n helpText: string;\n helpTextTranslations: CustomFieldTranslations;\n required: boolean;\n // Disabled fields stay configured but are neither rendered nor submitted.\n enabled: boolean;\n // Length bounds apply to text/textarea/password/email; null = unbounded.\n minLength: number | null;\n maxLength: number | null;\n // Prefill for text-like fields; for selects, the option `value` selected\n // initially (empty = placeholder \"choose\" state).\n defaultValue: string;\n // Select choices; ignored for other types.\n options: CustomFieldOption[];\n // Conditional display. Always populated by the decoder — fields without a\n // persisted rule decode to `{ mode: 'always', … }`.\n visibility: CustomFieldVisibility;\n}\n\nexport interface CheckoutBranding extends EnigmaCardFormSettings {\n // Brand identity\n displayName: string;\n logoUrl: string;\n tagline: string;\n showLogo: boolean;\n logoShape: LogoShape;\n logoSize: LogoSize;\n\n // Color tokens\n primary: string;\n background: string;\n surface: string;\n text: string;\n heading: string;\n muted: string;\n border: string;\n accentText: string;\n buttonBackground: string;\n buttonText: string;\n\n // Typography\n fontFamily: FontFamily;\n headingWeight: FontWeight;\n\n // Shape — granular per-element. Surfaces & inputs use a narrower union\n // (no pill) because pill cards/inputs are always wrong; button and badge\n // keep the full `CornerRadius` since pill is a legitimate look there.\n radiusSurface: NonPillRadius;\n radiusInput: NonPillRadius;\n radiusButton: CornerRadius;\n radiusBadge: CornerRadius;\n surfaceStyle: SurfaceStyle;\n\n // Spacing — four independent dimensions.\n surfacePadding: SpacingScale;\n verticalGap: SpacingScale;\n inputSize: SizeScale;\n buttonSize: SizeScale;\n\n // Layout\n layout: LayoutStyle;\n summaryPosition: SummaryPosition;\n showOrderSummary: boolean;\n summaryGradient: boolean;\n showTotal: boolean;\n totalLabel: string;\n showCurrencyCode: boolean;\n showOrderItems: boolean;\n\n // Hosted-checkout exit. It is only drawn when the payment resolves a\n // cancel URL; these fields decide whether and how that destination is shown.\n cancelLinkEnabled: boolean;\n cancelLinkPosition: 'top' | 'bottom';\n cancelLinkStyle: 'link' | 'button';\n\n // Provider surcharge / discount disclosure. `showSurcharge` false hides the\n // per-tile figure entirely; the in-pane breakdown is unaffected, since that\n // one is the merchant's existing legal disclosure rather than a steering\n // signal. The two colours are separate on purpose: a surcharge and a discount\n // are opposite news for the buyer and reading them in one colour is exactly\n // the mistake a minus sign is easy to miss in.\n showSurcharge: boolean;\n surchargePosition: SurchargePosition;\n // Where the express strip of wallet buttons goes on the payment surface.\n // Only rows that actually draw a button are lifted into it; a surface with\n // none has no strip.\n nativeElementPosition: NativeElementPosition;\n // One button per line in that strip, instead of side by side.\n //\n // Off by default, because two wallets on one line is what the strip is for:\n // Apple Pay and Google Pay are one choice made twice, and a buyer is offered\n // at most one of them on any given browser anyway — the second track is\n // usually the card form arriving sooner rather than a second button. On for\n // a merchant who wants each button full width: a wide brand mark, a checkout\n // narrow enough that two tracks crowd, or simply their own taste.\n //\n // The strip already stacks on its own when the surface is too narrow to seat\n // two; this makes it stack at every width.\n nativeElementStacked: boolean;\n surchargeStyle: SurchargeStyle;\n surchargeSize: SurchargeSize;\n surchargeShape: SurchargeShape;\n surchargeBorderWidth: SurchargeBorderWidth;\n surchargeBorderStyle: SurchargeBorderStyle;\n surchargeWeight: SurchargeWeight;\n surchargeSign: SurchargeSign;\n surchargeUppercase: boolean;\n surchargeLabel: SurchargeLabelMode;\n surchargeFigure: SurchargeFigureMode;\n discountFigure: SurchargeFigureMode;\n surchargeWordTranslations: CustomFieldTranslations;\n discountWordTranslations: CustomFieldTranslations;\n surchargeColor: string;\n discountColor: string;\n\n // Trust badges (fully customizable; empty = hide row). No longer a default:\n // new shops start with none and get `notices` instead; a shop that customised\n // its badges keeps them. See `resolveNoticesAndBadges`.\n trustBadges: TrustBadge[];\n\n // Reassurance lines — icon + per-locale text — in the summary and at the\n // bottom of the payment element (empty = none).\n notices: CheckoutNotice[];\n\n // Merchant-defined checkout inputs (empty = no custom fields section).\n customFields: CheckoutCustomField[];\n\n // Where each payment-method section renders, 1-100, lower first.\n methodSectionOrder: MethodSectionOrder;\n\n // The merchant's name for a section, per locale. Empty = use the built-in\n // name, or the id itself for a section with none.\n methodSectionLabels: MethodSectionLabels;\n\n // Copy. All of these are optional in the persisted form: empty string\n // means \"unset\" and consumers should fall back (e.g. payButtonLabel falls\n // back to a localized \"Pay $X\" string).\n headerText: string;\n headerTextTranslations: CustomFieldTranslations;\n payButtonLabel: string;\n payButtonLabelTranslations: CustomFieldTranslations;\n cardTermsMessage: string;\n cardTermsMessageTranslations: CustomFieldTranslations;\n footerText: string;\n footerTextTranslations: CustomFieldTranslations;\n supportEmail: string;\n\n // Stripe Elements behavior. `paymentLayout` only affects what's painted\n // inside Stripe's iframe; non-Stripe connector panes stack vertically\n // regardless. `labelStyle` is also Stripe-iframe scope.\n paymentLayout: PaymentLayout;\n labelStyle: LabelStyle;\n\n // The Airwallex card surface. Scoped to that pane by name because that is\n // the only rail these reach: Stripe's element is themed through its own\n // Appearance API and the vault's fields are our DOM, so a field weight\n // written here would quietly do nothing on either. See `airwallexCard.ts`\n // for the geometry these sit on top of.\n //\n // `airwallexCardPreset` is the only one that can be EMPTY, and that is the\n // hinge of the whole migration: empty means \"the merchant has not chosen\n // here\", which lets the connector account's own `integration_style` keep\n // deciding for every shop configured before this section existed. A default\n // of `split_fields_labelled` on this field would override all of them\n // silently. `resolveAirwallexCardPreset` is the resolution.\n airwallexCardPreset: AirwallexCardPreset | '';\n // Removes the card form from the shop's checkout entirely. Money-affecting\n // and therefore off by default: with this on, no buyer can pay by card.\n airwallexHideCard: boolean;\n // Drops the \"Card\" heading over the Airwallex form. Presentation only, and\n // scoped to this rail because it is this rail's form the merchant is looking\n // at when they turn it off: a shop whose form is the first thing on the\n // checkout has no use for a word naming what the fields obviously are.\n //\n // The section is what loses its NAME, not its disclosure — a surcharge or\n // discount chip on the card rail still renders on that line, because what it\n // says is the money the buyer is about to be charged.\n airwallexHideCardTitle: boolean;\n airwallexFieldChrome: AirwallexFieldChrome;\n // Empty means \"whatever the preset says\" — see `resolveAirwallexLabelStyle`.\n airwallexLabelStyle: AirwallexLabelStyle | '';\n airwallexFieldFontSize: AirwallexFieldFontSize;\n airwallexFieldWeight: AirwallexFieldWeight;\n airwallexFocusRing: AirwallexFocusRing;\n airwallexAutofill: AirwallexAutofillTreatment;\n airwallexValidTint: boolean;\n // Decorative marks, and nothing more — they do not narrow what Airwallex\n // accepts. See `AIRWALLEX_NETWORK_MARKS`.\n airwallexNetworkMarks: boolean;\n\n // The Stripe Payment Element's own look (`cardFormStyles.ts`). Applied over\n // the colour, font and radius tokens above, inside Stripe's iframe.\n stripeTheme: StripeTheme;\n stripeInputs: StripeInputStyle;\n stripeLabels: StripeLabelPlacement;\n stripeSpacing: StripeSpacing;\n stripeFieldFontSize: CardFieldFontSize;\n stripeFieldWeight: CardFieldWeight;\n stripeFocusRing: CardFocusRing;\n stripeDisableAnimations: boolean;\n\n // PayPal Card Fields and Mollie Components. Boxes and captions are our DOM;\n // the type size and weight reach the text inside PayPal's iframes.\n paypalCardLayout: PaypalCardLayout;\n paypalLabelStyle: PaypalLabelStyle;\n paypalFieldChrome: CardFieldChrome;\n mollieFieldChrome: CardFieldChrome;\n paypalFieldFontSize: CardFieldFontSize;\n mollieFieldFontSize: CardFieldFontSize;\n paypalFieldWeight: CardFieldWeight;\n mollieFieldWeight: CardFieldWeight;\n paypalFocusRing: CardFocusRing;\n mollieFocusRing: CardFocusRing;\n paypalValidTint: boolean;\n\n // e-Payouts' Pay with card. PayPal's card fields too,\n // so the same seven knobs, but the shop's own: changing the PayPal card\n // form leaves this one alone. A stored look from before this section has\n // none of these keys, and reads the PayPal ones, which is what the form\n // followed until then (see `decodeBranding`).\n epayoutsCardLayout: PaypalCardLayout;\n epayoutsLabelStyle: PaypalLabelStyle;\n epayoutsFieldChrome: CardFieldChrome;\n epayoutsFieldFontSize: CardFieldFontSize;\n epayoutsFieldWeight: CardFieldWeight;\n epayoutsFocusRing: CardFocusRing;\n epayoutsValidTint: boolean;\n\n // NomuPay's COPYandPAY widget: `wpwlOptions` for the form, the checkout's\n // CSS on its `.wpwl-*` boxes, and the Apple Pay and Google Pay buttons the\n // same widget draws. `auto` follows the checkout's theme, as before.\n nomupayFormStyle: NomupayFormStyle;\n nomupayShowLabels: boolean;\n nomupayShowPlaceholders: boolean;\n nomupayShowCvvHint: boolean;\n nomupayFieldChrome: CardFieldChrome;\n nomupayFieldFontSize: CardFieldFontSize;\n nomupayFocusRing: CardFocusRing;\n nomupayApplePayButtonStyle: ApplePayButtonStyle;\n nomupayApplePayButtonType: ApplePayButtonType;\n nomupayGooglePayButtonColor: GooglePayButtonColor;\n nomupayGooglePayButtonType: GooglePayButtonType;\n\n // MicroPayment's JSBridge frame: the checkout draws the holder and expiry\n // inputs and the box around the provider's PAN and CVC frames itself, and\n // hands the type size and weight into those frames.\n micropaymentFieldChrome: CardFieldChrome;\n micropaymentFieldFontSize: CardFieldFontSize;\n micropaymentFieldWeight: CardFieldWeight;\n micropaymentFocusRing: CardFocusRing;\n\n // Whop's Payment Elements: the element and layout (`whopCardPreset`), the\n // palette Whop draws its own controls in, and per-part CSS for the boxes,\n // all inside Whop's frames. See `cardFormStyles.ts`.\n whopCardPreset: WhopCardPreset;\n whopAccentColor: WhopAccentColor;\n whopGrayColor: WhopGrayColor;\n whopBillingDetails: WhopBillingDetails;\n // `accordion` only: each method in its own card, with space between.\n whopSeparated: boolean;\n whopEmailLabel: WhopEmailLabel;\n whopFieldChrome: CardFieldChrome;\n // Kept for stored brandings and no longer read: Whop draws the card digits\n // at its own size and weight and marks focus itself, so neither the\n // checkout nor the dashboard uses these three.\n whopFieldFontSize: CardFieldFontSize;\n whopFieldWeight: CardFieldWeight;\n whopFocusRing: CardFocusRing;\n // The corners of Whop's form, its drop shadow, whether the method list\n // shows each method's icon, and how it marks the chosen method.\n whopRadius: WhopRadius;\n whopShadow: WhopShadow;\n whopMethodIcons: boolean;\n whopSelection: WhopSelection;\n\n // Footer\n showPoweredBy: boolean;\n\n // Advanced — raw CSS appended after brand-token CSS variables are\n // applied, so its declarations win cascade order. Sanitized at render\n // time (see `sanitizeCustomCss`); persisted as-typed under\n // `sdk_ui_rules.branding.customCss`.\n customCss: string;\n}\n\n// --- Token maps ---------------------------------------------------------\n\n// Self-hostable font stacks. The buyer-facing checkout bundles these via\n// @fontsource* packages; the variable-font names ('Inter Variable', …) are\n// listed first so the smaller variable file is preferred when bundled.\nconst FONT_STACKS: Record<FontFamily, string> = {\n inter: \"'Inter Variable', 'Inter', system-ui, -apple-system, sans-serif\",\n system:\n \"system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif\",\n serif: \"Georgia, 'Times New Roman', serif\",\n mono: 'ui-monospace, SFMono-Regular, Menlo, Consolas, monospace',\n roboto: \"'Roboto', system-ui, sans-serif\",\n poppins: \"'Poppins', system-ui, sans-serif\",\n manrope: \"'Manrope Variable', 'Manrope', system-ui, sans-serif\",\n 'dm-sans': \"'DM Sans Variable', 'DM Sans', system-ui, sans-serif\",\n 'space-grotesk': \"'Space Grotesk Variable', 'Space Grotesk', system-ui, sans-serif\",\n 'plex-sans': \"'IBM Plex Sans', system-ui, sans-serif\",\n 'work-sans': \"'Work Sans Variable', 'Work Sans', system-ui, sans-serif\",\n 'open-sans': \"'Open Sans Variable', 'Open Sans', system-ui, sans-serif\",\n lora: \"'Lora Variable', 'Lora', Georgia, serif\",\n playfair: \"'Playfair Display Variable', 'Playfair Display', Georgia, serif\",\n 'plex-mono': \"'IBM Plex Mono', ui-monospace, monospace\",\n 'jetbrains-mono': \"'JetBrains Mono Variable', 'JetBrains Mono', ui-monospace, monospace\",\n};\n\nconst RADIUS_PX: Record<CornerRadius, string> = {\n square: '0px',\n small: '6px',\n medium: '12px',\n large: '20px',\n pill: '999px',\n};\n\nconst FONT_WEIGHT_NUMERIC: Record<FontWeight, string> = {\n regular: '400',\n medium: '500',\n semibold: '600',\n bold: '700',\n};\n\nconst SURFACE_PAD: Record<SpacingScale, string> = {\n compact: '1rem',\n comfortable: '1.5rem',\n spacious: '2rem',\n};\n\nconst VERTICAL_GAP: Record<SpacingScale, string> = {\n compact: '0.75rem',\n comfortable: '1rem',\n spacious: '1.5rem',\n};\n\nconst INPUT_PAD: Record<SizeScale, string> = {\n sm: '0.5rem 0.75rem',\n md: '0.625rem 0.75rem',\n lg: '0.875rem 0.875rem',\n};\n\nconst BUTTON_PAD: Record<SizeScale, string> = {\n sm: '0.625rem 1rem',\n md: '0.875rem 1.25rem',\n lg: '1.125rem 1.5rem',\n};\n\nexport function fontStack(family: FontFamily): string {\n return FONT_STACKS[family] ?? FONT_STACKS.inter;\n}\n\nexport function radiusValue(radius: CornerRadius): string {\n return RADIUS_PX[radius] ?? RADIUS_PX.medium;\n}\n\nexport function fontWeightValue(weight: FontWeight): string {\n return FONT_WEIGHT_NUMERIC[weight] ?? '600';\n}\n\nexport function surfacePadValue(scale: SpacingScale): string {\n return SURFACE_PAD[scale] ?? SURFACE_PAD.comfortable;\n}\n\nexport function verticalGapValue(scale: SpacingScale): string {\n return VERTICAL_GAP[scale] ?? VERTICAL_GAP.comfortable;\n}\n\nexport function inputPadValue(size: SizeScale): string {\n return INPUT_PAD[size] ?? INPUT_PAD.md;\n}\n\nexport function buttonPadValue(size: SizeScale): string {\n return BUTTON_PAD[size] ?? BUTTON_PAD.md;\n}\n\n/**\n * The look a vault's own card form takes to match a checkout with this\n * branding: pass it to `CheckoutSession.vaultCollectSession`.\n *\n * `danger` is the colour of an invalid field's border. The checkout picks it\n * for contrast on the surface, which this module does not measure, so the\n * caller supplies it.\n */\nexport function vaultFormAppearance(\n b: CheckoutBranding,\n danger?: string,\n options: { designed?: boolean } = {},\n): VaultFormAppearance {\n const border = b.enigmaBorder || b.border;\n const look: VaultFormAppearance = {\n surface: b.surface,\n text: b.text,\n border,\n accent: b.enigmaAccent || b.primary,\n ...(danger ? { danger } : {}),\n font: b.fontFamily,\n radius: b.radiusInput,\n size: b.inputSize,\n labels: b.labelStyle,\n };\n if (!options.designed) return look;\n // The Enigma card form's own settings, asked for only by a\n // caller that draws the answered `layout`: a designed form hides Enigma's\n // own field names and \"Save card\" caption, which that caller draws instead.\n // A security-code form takes only the look above.\n return {\n ...look,\n chrome: b.enigmaChrome,\n label: enigmaNamesInside(b) ? 'inside' : 'above',\n hints: b.enigmaHints,\n order: b.enigmaFieldOrder,\n marks: b.enigmaMarks,\n focus: b.enigmaFocusRing,\n motion: b.enigmaFieldMotion,\n height: b.enigmaFieldHeight,\n gap: b.enigmaRowGap,\n corner: b.enigmaCorner,\n fill: b.enigmaFill || enigmaDefaultFill(b.surface, b.text),\n ...(b.enigmaStyleMode === 'custom' ? { custom: true } : {}),\n };\n}\n\n/** A filled field's tint when the shop sets none: 6% of the text in the surface. */\nexport function enigmaDefaultFill(surface: string, text: string): string {\n const channels = (hex: string): [number, number, number] | null => {\n const v = hex.trim().replace('#', '');\n const full = v.length === 3 ? v.replace(/./g, '$&$&') : v;\n if (!/^[0-9a-fA-F]{6}$/.test(full)) return null;\n return [0, 2, 4].map((i) => parseInt(full.slice(i, i + 2), 16)) as [number, number, number];\n };\n const s = channels(surface) ?? [255, 255, 255];\n const t = channels(text) ?? [30, 41, 59];\n return `#${s\n .map((value, i) =>\n Math.round(value * 0.94 + (t[i] ?? 0) * 0.06)\n .toString(16)\n .padStart(2, '0'),\n )\n .join('')}`;\n}\n\nexport function logoDimensions(size: LogoSize): { px: number; radius: number } {\n switch (size) {\n case 'sm':\n return { px: 36, radius: 8 };\n case 'lg':\n return { px: 64, radius: 16 };\n case 'md':\n default:\n return { px: 48, radius: 12 };\n }\n}\n\nconst HEX_RE = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/;\n\nexport function isHexColor(value: string): boolean {\n return HEX_RE.test(value.trim());\n}\n\n/**\n * A CSS `<hex-color>`: whole token, leading `#` REQUIRED.\n *\n * ⚠️ The `#` is not pedantry here. `applyBrandingVariables` writes branding\n * values into custom properties unchanged (`el.style.setProperty(k, v)`), and\n * a custom property accepts any token stream — it is only interpreted when\n * substituted into a typed property, where `000` is not a colour and the\n * declaration is dropped. So a contrast API that accepted `'000'` would hand\n * back `21` for a pair that renders as nothing at all: approving a palette\n * that never reaches the screen is worse than refusing to judge it.\n */\nconst CSS_HEX_RE = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;\n\n/**\n * The same shape with the `#` optional, for {@link isDarkSurface} ONLY.\n *\n * That function has stripped an optional hash since it was written, and\n * `'5a5a5a'` is a real colour whose answer is correct — tightening it onto the\n * CSS form would answer correct input wrongly. New API does not inherit the\n * tolerance; the existing caller keeps it.\n */\nconst LENIENT_HEX_RE = /^#?([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/;\n\n/** `[r, g, b]` in 0–255, or `null` when the token is not a colour. */\nfunction parseHexChannels(value: string, pattern: RegExp): [number, number, number] | null {\n const match = pattern.exec(value.trim());\n if (!match) return null;\n const digits = match[1] as string;\n const full =\n digits.length === 3\n ? digits\n .split('')\n .map((c) => c + c)\n .join('')\n : digits;\n return [\n parseInt(full.slice(0, 2), 16),\n parseInt(full.slice(2, 4), 16),\n parseInt(full.slice(4, 6), 16),\n ];\n}\n\n/** WCAG 2.1 relative luminance (1.4.3), with the sRGB linearisation. */\nfunction relativeLuminance([r, g, b]: [number, number, number]): number {\n const [lr, lg, lb] = [r, g, b].map((channel) => {\n const c = channel / 255;\n return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;\n }) as [number, number, number];\n return 0.2126 * lr + 0.7152 * lg + 0.0722 * lb;\n}\n\n/** Minimum contrast for body text — WCAG 2.1 success criterion 1.4.3. */\nexport const WCAG_AA_TEXT = 4.5;\n\n/**\n * Minimum contrast for non-text UI — WCAG 2.1 success criterion 1.4.11.\n * Focus rings, borders, icons carrying meaning.\n */\nexport const WCAG_AA_UI = 3;\n\n/**\n * WCAG 2.1 contrast ratio between two colours, 1–21. Order does not matter.\n *\n * Compare against {@link WCAG_AA_TEXT} or {@link WCAG_AA_UI}:\n *\n * ```ts\n * const ratio = contrastRatio(branding.surface, branding.text);\n * if (ratio === null || ratio < WCAG_AA_TEXT) useDefaultPalette();\n * ```\n *\n * ⚠️ Returns `null` — never a number — when either colour cannot be parsed.\n * That is the load-bearing part of this signature. Every colour bug this API\n * exists to prevent came from a helper answering with a plausible value for\n * something it could not read, and a `0` or a `21` here would be silently\n * believed by exactly the branch that is deciding whether text is legible.\n *\n * Accepts `#rgb` and `#rrggbb` — a CSS `<hex-color>`. ⚠️ A hash-less token is\n * `null`, not a ratio: `applyBrandingVariables` writes branding values into\n * custom properties verbatim, so `'000'` reaches CSS as something that is not a\n * colour. Returning `21` for it would approve a palette that never renders.\n * ({@link isDarkSurface} keeps its historical hash-less tolerance; this is new\n * API and does not inherit it.)\n */\nexport function contrastRatio(a: string, b: string): number | null {\n const first = parseHexChannels(a, CSS_HEX_RE);\n const second = parseHexChannels(b, CSS_HEX_RE);\n if (!first || !second) return null;\n const [x, y] = [relativeLuminance(first), relativeLuminance(second)];\n const lighter = Math.max(x, y);\n const darker = Math.min(x, y);\n return (lighter + 0.05) / (darker + 0.05);\n}\n\n/**\n * Crude perceived-luminance check — picks the right Stripe Elements preset\n * (`'night'` vs `'stripe'`) when the merchant has a dark surface.\n *\n * ⚠️ **This is not a readability test. Use {@link contrastRatio} for that.**\n * It is a YIQ luma split at 128, and on real brand colours its verdict and\n * actual legibility are not merely imprecise relative to each other — they can\n * be anti-correlated:\n *\n * | colour | `isDarkSurface` | vs white | |\n * | --- | --- | --- | --- |\n * | `#ff00ff` | `true` | 3.14:1 | fails AA text |\n * | `#00ff00` | `false` | 1.37:1 | fails AA text |\n * | `#0000ff` | `true` | 8.59:1 | passes |\n *\n * A caller picking text colour from this gets the wrong answer on both failing\n * cases. It is kept because choosing a Stripe preset is a legitimate and\n * different question.\n *\n * Inputs that are not a 3-/6-digit hex fall through to \"light\", the safer\n * assumption for the default palette.\n */\nexport function isDarkSurface(color: string): boolean {\n // ⚠️ Was a length check plus `parseInt` plus `Number.isNaN`, which let six\n // values the package's own validator rejects through as \"dark\" — `parseInt`\n // accepts a valid prefix, so `parseInt('0g', 16)` is `0`, not `NaN`. The\n // comment above already promised these fall through to \"light\"; now they do.\n const channels = parseHexChannels(color, LENIENT_HEX_RE);\n if (!channels) return false;\n const [r, g, b] = channels;\n const luma = (r * 299 + g * 587 + b * 114) / 1000;\n return luma < 128;\n}\n\n// --- Defaults -----------------------------------------------------------\n\n// Light-mode DeloPay-branded baseline. Hex values come straight from\n// `design-guidelines/colors.md`:\n// - #1E4FEB is `--color-dp-blue`, the wordmark/icon brand blue\n// - #0A1130 is `--color-dp-blue-dark`, the wordmark navy\n// - the rest are slate-50 / slate-200 / slate-500 / slate-800 from the\n// design system's neutral ramp.\n// Picked for: high contrast, neutral surroundings, brand-blue accents,\n// confident navy CTA. Reads \"fintech\" without feeling cold.\nconst LIGHT_PALETTE = {\n primary: '#1E4FEB',\n background: '#f8fafc',\n surface: '#ffffff',\n text: '#1e293b',\n heading: '#0A1130',\n muted: '#64748b',\n border: '#e2e8f0',\n accentText: '#1E4FEB',\n buttonBackground: '#0A1130',\n buttonText: '#ffffff',\n} as const;\n\nexport const DEFAULT_BADGES: TrustBadge[] = [\n {\n id: 'secure',\n label: 'Secure',\n textColor: '#047857',\n backgroundColor: '#ecfdf5',\n borderColor: '#a7f3d0',\n },\n {\n id: 'ssl',\n label: '256-bit SSL',\n textColor: '#1E4FEB',\n backgroundColor: '#eff6ff',\n borderColor: '#bfdbfe',\n },\n];\n\n// Dark-mode equivalents of DEFAULT_BADGES. Dark trust chips need solid hex\n// (the form's color picker only accepts hex), so we pick the design system's\n// success-900 / info-900 backdrops paired with their *-400 foreground tokens.\nexport const DEFAULT_BADGES_DARK: TrustBadge[] = [\n {\n id: 'secure',\n label: 'Secure',\n textColor: '#34d399',\n backgroundColor: '#064e3b',\n borderColor: '#065f46',\n },\n {\n id: 'ssl',\n label: '256-bit SSL',\n textColor: '#60a5fa',\n backgroundColor: '#172554',\n borderColor: '#1e40af',\n },\n];\n\n/**\n * The notices every shop starts with.\n *\n * The same two claims the stock badges made — the payment is secure, the\n * connection is TLS-encrypted — and nothing more. A default is shown on every\n * shop that has not written its own, so it may only say what is true of every\n * shop: \"free shipping\" or \"tax included\" are the merchant's to claim, never\n * ours.\n *\n * `label` is English and there is deliberately no `en` override, so the\n * customizer's Default tab edits what an English buyer reads. The other nine\n * checkout locales are written out, because a German buyer reading \"Secure\n * payment\" is exactly what the badges did wrong.\n */\nexport const DEFAULT_NOTICES: readonly CheckoutNotice[] = [\n {\n id: 'secure',\n section: 'summary',\n icon: 'shield',\n label: 'Secure payment',\n labelTranslations: {\n de: 'Sichere Zahlung',\n fr: 'Paiement sécurisé',\n es: 'Pago seguro',\n it: 'Pagamento sicuro',\n nl: 'Veilig betalen',\n zh: '安全支付',\n 'zh-Hant': '安全付款',\n hi: 'सुरक्षित भुगतान',\n ar: 'دفع آمن',\n },\n },\n {\n id: 'ssl',\n section: 'summary',\n icon: 'lock',\n label: 'Encrypted · 256-bit SSL',\n labelTranslations: {\n de: 'Verschlüsselt · 256-Bit-SSL',\n fr: 'Chiffré · SSL 256 bits',\n es: 'Cifrado · SSL de 256 bits',\n it: 'Crittografato · SSL a 256 bit',\n nl: 'Versleuteld · 256-bit SSL',\n zh: '加密 · 256 位 SSL',\n 'zh-Hant': '加密 · 256 位元 SSL',\n hi: 'एन्क्रिप्टेड · 256-बिट SSL',\n ar: 'مشفّر · SSL بطول 256 بت',\n },\n },\n];\n\n/** A deep copy of `DEFAULT_NOTICES`, safe to edit. */\nexport function defaultNotices(): CheckoutNotice[] {\n return DEFAULT_NOTICES.map(cloneNotice);\n}\n\nexport function cloneNotice(notice: CheckoutNotice): CheckoutNotice {\n return { ...notice, labelTranslations: { ...notice.labelTranslations } };\n}\n\n/** `#rrggbb` → its three channels, or `null` for anything else. */\nfunction hexChannels(hex: string): [number, number, number] | null {\n const raw = /^#([0-9a-f]{6})$/i.exec(hex.trim())?.[1];\n if (!raw) return null;\n return [\n parseInt(raw.slice(0, 2), 16),\n parseInt(raw.slice(2, 4), 16),\n parseInt(raw.slice(4, 6), 16),\n ];\n}\n\n/**\n * Whether a badge colouring is one the dashboard's theme gallery generated.\n *\n * From 2026-09-03 the built-in themes shipped the stock pair recoloured from\n * the theme (the dashboard's `themeBadges`): text = the primary,\n * fill = the surface mixed 8 % towards it, border = mixed 30 %, rounded per\n * channel. Those shops never chose their badge colours either, so they count\n * as stock. The surface is not stored with the badges, so it is recovered:\n * each channel is searched for a surface value that reproduces BOTH the fill\n * and the border — a hand-picked colouring passes that by accident only when\n * the merchant happened to type the exact generated hexes.\n *\n * Frozen on purpose: this recognises what was shipped, so it must not follow\n * any later change to how themes look.\n */\nfunction isThemeTintedBadgeColouring(textColor: string, fill: string, border: string): boolean {\n const primary = hexChannels(textColor);\n const bg = hexChannels(fill);\n const line = hexChannels(border);\n if (!primary || !bg || !line) return false;\n const mixed = (surface: number, to: number, share: number): number =>\n Math.round(surface + (to - surface) * share);\n return primary.every((p, i) => {\n for (let surface = 0; surface <= 255; surface += 1) {\n if (mixed(surface, p, 0.08) === bg[i] && mixed(surface, p, 0.3) === line[i]) return true;\n }\n return false;\n });\n}\n\n/**\n * Whether a badge list is a default DeloPay shipped rather than something the\n * merchant configured.\n *\n * Stock means the two stock badges — `secure` / \"Secure\", then `ssl` /\n * \"256-bit SSL\" — in a colouring DeloPay generated: the light default, the\n * dark default, or a theme colouring (`isThemeTintedBadgeColouring`, the same\n * one on both badges). Anything else was edited: a changed label, an added,\n * removed or reordered badge, a recolour, and an empty list — a merchant who\n * removed both badges chose to show nothing.\n */\nexport function isDefaultBadgeSet(badges: readonly TrustBadge[]): boolean {\n if (badges.length !== DEFAULT_BADGES.length) return false;\n const sameContent = badges.every(\n (badge, i) => badge.id === DEFAULT_BADGES[i]?.id && badge.label === DEFAULT_BADGES[i]?.label,\n );\n if (!sameContent) return false;\n\n const colouring = (set: readonly TrustBadge[]): string =>\n set\n .map((b) => [b.textColor, b.backgroundColor, b.borderColor ?? ''].join('|').toLowerCase())\n .join('/');\n const mine = colouring(badges);\n if (mine === colouring(DEFAULT_BADGES) || mine === colouring(DEFAULT_BADGES_DARK)) return true;\n\n // A theme gave both badges one colouring, border included.\n const [first] = badges;\n const border = first?.borderColor;\n if (!first || !border) return false;\n const same = (a: string | null, b: string): boolean =>\n (a ?? '').toLowerCase() === b.toLowerCase();\n return (\n badges.every(\n (b) =>\n same(b.textColor, first.textColor) &&\n same(b.backgroundColor, first.backgroundColor) &&\n same(b.borderColor, border),\n ) && isThemeTintedBadgeColouring(first.textColor, first.backgroundColor, border)\n );\n}\n\n/**\n * Decide a shop's badges and notices from what it has saved.\n *\n * `null` means the key is absent from what was saved (or unreadable). The\n * rule, in order:\n *\n * 1. Notices saved → they decide; badges are whatever was saved (none if\n * absent). Every save since notices exist writes the key, so from a shop's\n * first save on this is the only branch it takes — which is what makes\n * \"removed every notice\" stick instead of re-migrating to the defaults.\n * 2. No notices, and no badges or the stock badges → the badges go and the\n * default notices come in. This is every shop that never touched its trust\n * row.\n * 3. No notices, and badges the merchant configured → they stay exactly as\n * they are, and no notices are added: a shop that designed its own trust\n * row keeps it, and one that removed it keeps it removed.\n *\n * Decode-time only. Nothing is written until the merchant saves.\n */\nexport function resolveNoticesAndBadges(\n savedBadges: TrustBadge[] | null,\n savedNotices: CheckoutNotice[] | null,\n): { trustBadges: TrustBadge[]; notices: CheckoutNotice[] } {\n if (savedNotices !== null) {\n return { trustBadges: savedBadges ?? [], notices: savedNotices };\n }\n if (savedBadges === null || isDefaultBadgeSet(savedBadges)) {\n return { trustBadges: [], notices: defaultNotices() };\n }\n return { trustBadges: savedBadges, notices: [] };\n}\n\n// --- Method sections: order and captions -------------------------\n//\n// Two branding fields for the checkout's payment-method groups: the order they\n// render in, and the merchant's own name for each. A section's identity is a\n// key, and a key with no caption prints as itself.\n\nconst METHOD_SECTION_ORDER_KEY = 'methodSectionOrder';\nconst METHOD_SECTION_LABELS_KEY = 'methodSectionLabels';\n\n/** Inclusive bounds of one section's order number. */\nexport const MIN_SECTION_ORDER = 1;\nexport const MAX_SECTION_ORDER = 100;\n\n/** Ceiling on one caption. */\nexport const MAX_SECTION_LABEL_LENGTH = 120;\n\nexport interface MethodSectionSpec {\n readonly id: string;\n /** `sections.*` translation key, used when uncaptioned. */\n readonly labelKey: string;\n readonly order: number;\n}\n\n/**\n * Every known section, with its default number. Lower renders first.\n *\n * Array order is also the tie-break between two sections sharing a number, so\n * it is a display order rather than an arbitrary list.\n */\nexport const METHOD_SECTIONS: readonly MethodSectionSpec[] = [\n { id: 'card', labelKey: 'sections.card', order: 10 },\n { id: 'wallet', labelKey: 'sections.wallets', order: 20 },\n { id: 'bnpl', labelKey: 'sections.bnpl', order: 30 },\n { id: 'bank_redirect', labelKey: 'sections.onlineBanking', order: 40 },\n { id: 'bank_transfer', labelKey: 'sections.bankTransfer', order: 45 },\n { id: 'crypto', labelKey: 'sections.cryptocurrency', order: 50 },\n { id: 'game_items', labelKey: 'sections.gameItems', order: 60 },\n { id: 'voucher', labelKey: 'sections.vouchers', order: 70 },\n { id: 'gift_card', labelKey: 'sections.giftCards', order: 75 },\n { id: 'reward', labelKey: 'sections.rewards', order: 80 },\n { id: 'cash', labelKey: 'sections.cash', order: 90 },\n];\n\n/** Ids that mean an existing section under another name. */\nexport const SECTION_ALIASES: Readonly<Record<string, string>> = {\n card_redirect: 'card',\n};\n\n/** Where an id this list does not know goes: last, not first. */\nexport const UNKNOWN_SECTION_ORDER = MAX_SECTION_ORDER;\n\n/** Section id → order number. */\nexport type MethodSectionOrder = Record<string, number>;\n\n/** Section id → locale → the merchant's caption. */\nexport type MethodSectionLabels = Record<string, Record<string, string>>;\n\nexport function canonicalSectionId(category: string): string {\n return SECTION_ALIASES[category] ?? category;\n}\n\nexport function defaultMethodSectionOrder(): MethodSectionOrder {\n const order: MethodSectionOrder = {};\n for (const section of METHOD_SECTIONS) order[section.id] = section.order;\n return order;\n}\n\n/**\n * One order number, validated. `null` for anything that is not an integer in\n * range, so the caller can fall back to the default rather than clamp — a\n * `999` is a mistake, and \"last\" is a guess at what was meant.\n */\nexport function validSectionOrder(raw: unknown): number | null {\n if (typeof raw !== 'number' || !Number.isInteger(raw)) return null;\n if (raw < MIN_SECTION_ORDER || raw > MAX_SECTION_ORDER) return null;\n return raw;\n}\n\n/**\n * The order from a raw bag value. Total, like `decodeBadges`: anything\n * malformed gives the defaults, one bad number costs only its own section, an\n * unknown id is kept so a newer consumer can place it, and an alias folds onto\n * the section it names.\n */\nexport function decodeMethodSectionOrder(raw: string | undefined): MethodSectionOrder {\n const order = defaultMethodSectionOrder();\n if (raw === undefined) return order;\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return order;\n }\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return order;\n for (const [key, value] of Object.entries(parsed as Record<string, unknown>)) {\n const valid = validSectionOrder(value);\n if (valid === null) continue;\n order[canonicalSectionId(key)] = valid;\n }\n return order;\n}\n\nexport function encodeMethodSectionOrder(order: MethodSectionOrder): string {\n return JSON.stringify(order);\n}\n\n/**\n * Captions from a raw bag value. Tolerant for the same reason as the order,\n * and blank strings are dropped so an emptied field round-trips as absence.\n */\nexport function decodeMethodSectionLabels(raw: string | undefined): MethodSectionLabels {\n if (raw === undefined) return {};\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return {};\n }\n if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) return {};\n const labels: MethodSectionLabels = {};\n for (const [section, byLocale] of Object.entries(parsed as Record<string, unknown>)) {\n if (!section || byLocale === null || typeof byLocale !== 'object' || Array.isArray(byLocale)) {\n continue;\n }\n const kept: Record<string, string> = {};\n for (const [locale, text] of Object.entries(byLocale as Record<string, unknown>)) {\n if (typeof text !== 'string') continue;\n const trimmed = text.trim();\n if (!trimmed) continue;\n kept[locale] = trimmed.slice(0, MAX_SECTION_LABEL_LENGTH);\n }\n if (Object.keys(kept).length > 0) labels[canonicalSectionId(section)] = kept;\n }\n return labels;\n}\n\n/**\n * Captions for the bag, or `null` when there are none — so an untouched\n * profile's bag is unchanged by this field existing, as `customFields` does.\n */\nexport function encodeMethodSectionLabels(labels: MethodSectionLabels): string | null {\n const cleaned: MethodSectionLabels = {};\n for (const [section, byLocale] of Object.entries(labels)) {\n const kept: Record<string, string> = {};\n for (const [locale, text] of Object.entries(byLocale)) {\n const trimmed = (text ?? '').trim();\n if (trimmed) kept[locale] = trimmed.slice(0, MAX_SECTION_LABEL_LENGTH);\n }\n if (Object.keys(kept).length > 0) cleaned[section] = kept;\n }\n return Object.keys(cleaned).length > 0 ? JSON.stringify(cleaned) : null;\n}\n\nfunction sectionCatalogueIndex(sectionId: string): number {\n const index = METHOD_SECTIONS.findIndex((section) => section.id === sectionId);\n return index === -1 ? METHOD_SECTIONS.length : index;\n}\n\nexport function sectionOrderOf(order: MethodSectionOrder, category: string): number {\n return order[canonicalSectionId(category)] ?? UNKNOWN_SECTION_ORDER;\n}\n\n/**\n * Compare two section ids: the merchant's number, then this list, then the id.\n *\n * The last two keys are properties of the build rather than of any response,\n * which is what stops two sections on one number swapping between renders.\n */\nexport function compareSections(order: MethodSectionOrder): (a: string, b: string) => number {\n return (a, b) => {\n const left = canonicalSectionId(a);\n const right = canonicalSectionId(b);\n const byOrder = sectionOrderOf(order, left) - sectionOrderOf(order, right);\n if (byOrder !== 0) return byOrder;\n const byCatalogue = sectionCatalogueIndex(left) - sectionCatalogueIndex(right);\n if (byCatalogue !== 0) return byCatalogue;\n return left < right ? -1 : left > right ? 1 : 0;\n };\n}\n\n/**\n * What to print above a section: the merchant's caption for this locale, then\n * their caption in any locale they wrote, then the caller's own name for a\n * section it knows, then the raw id.\n *\n * `translate` must return `undefined` for a key it has no entry for, or step 3\n * swallows the fall-through and prints `sections.<id>`.\n */\nexport function sectionLabel(\n labels: MethodSectionLabels,\n category: string,\n locale: string,\n knownKey: string | undefined,\n translate: (key: string) => string | undefined,\n): string {\n const id = canonicalSectionId(category);\n // `in` rather than `Object.hasOwn`: this package targets a lower `lib` than\n // its consumers, and the map is built by the decoder above.\n if (id in labels) {\n const captions = labels[id] as Record<string, string>;\n // Through `translationFor`, like every other localized branding field: it\n // folds case and walks parent locales, so `de-AT` finds `de`. An exact\n // lookup missed that and fell to the any-caption step below, which returns\n // whichever locale is first in the map — English, for a caption set written\n // `en` then `de`. A German buyer read an English heading.\n // Trimmed: `translationFor` accepts any non-empty string, and a\n // whitespace-only caption is not a caption. The decoder drops those, so\n // this only bites a caller that built the map itself.\n const matched = translationFor(captions, locale)?.trim();\n if (matched) return matched;\n for (const value of Object.values(captions)) {\n const any = value.trim();\n if (any) return any;\n }\n }\n if (knownKey) {\n const translated = translate(knownKey);\n if (translated) return translated;\n }\n return category;\n}\n\n/** Accept either the decoded map or the bag's JSON string. */\nfunction parseSectionOrderLoose(raw: unknown): MethodSectionOrder {\n if (typeof raw === 'string') return decodeMethodSectionOrder(raw);\n if (raw !== null && typeof raw === 'object' && !Array.isArray(raw)) {\n return decodeMethodSectionOrder(JSON.stringify(raw));\n }\n return defaultMethodSectionOrder();\n}\n\n/** Same, for captions. */\nfunction parseSectionLabelsLoose(raw: unknown): MethodSectionLabels {\n if (typeof raw === 'string') return decodeMethodSectionLabels(raw);\n if (raw !== null && typeof raw === 'object' && !Array.isArray(raw)) {\n return decodeMethodSectionLabels(JSON.stringify(raw));\n }\n return {};\n}\n\n/** The `sections.*` key for a known id, or `undefined`. */\nexport function knownSectionLabelKey(category: string): string | undefined {\n const id = canonicalSectionId(category);\n return METHOD_SECTIONS.find((section) => section.id === id)?.labelKey;\n}\n\nconst DEFAULT_BRANDING_BASE: Omit<\n CheckoutBranding,\n | keyof typeof LIGHT_PALETTE\n | 'trustBadges'\n | 'notices'\n | 'customFields'\n | 'methodSectionOrder'\n | 'methodSectionLabels'\n> = {\n displayName: '',\n logoUrl: '',\n tagline: '',\n // Logo + summary gradient OFF by default — an unconfigured DeloPay\n // checkout reads cleaner without a placeholder logo block, and the\n // gradient implies a primary tint the merchant hasn't yet picked.\n showLogo: false,\n logoShape: 'rounded',\n logoSize: 'md',\n\n fontFamily: 'inter',\n headingWeight: 'semibold',\n\n radiusSurface: 'medium',\n radiusInput: 'medium',\n radiusButton: 'medium',\n radiusBadge: 'pill',\n surfaceStyle: 'elevated',\n surfacePadding: 'comfortable',\n verticalGap: 'comfortable',\n inputSize: 'md',\n buttonSize: 'md',\n\n // Disclosure on by default: with provider-scoped pricing the tile is where\n // the buyer chooses between prices, and a price they cannot see is one they\n // find out about on the statement.\n showSurcharge: true,\n surchargePosition: 'trailing',\n // The button is the surface a buyer recognises fastest; it leads its section\n // unless the merchant says otherwise.\n nativeElementPosition: 'top',\n // Side by side — see the field.\n nativeElementStacked: false,\n surchargeStyle: 'badge',\n surchargeSize: 'sm',\n surchargeShape: 'pill',\n surchargeBorderWidth: 'thin',\n surchargeBorderStyle: 'solid',\n surchargeWeight: 'medium',\n surchargeSign: 'always',\n surchargeUppercase: false,\n // Named, not bare. A tile that reads \"-EUR 2.50\" beside a brand name is a\n // number with no subject — buyers read it as the price, not as a change to\n // it. \"Discount -EUR 2.50\" needs no interpreting, and the word is what makes\n // the default configuration legible without the merchant touching anything.\n surchargeLabel: 'labelled',\n // The two directions default differently on purpose, which is the whole\n // reason they are two settings. A fee is something a buyer acts on in money,\n // so it leads with money and says nothing else. A saving is something worth\n // advertising, and the share is the persuasive half of it — \"-5.1% (EUR\n // 2.50)\" sells what \"-EUR 2.50\" merely states, and the amount is still right\n // there beside it.\n surchargeFigure: 'amount',\n discountFigure: 'percentThenAmount',\n // Empty: the checkout's own localized words are the default, in every\n // language it ships. A merchant fills these in only to say it differently.\n surchargeWordTranslations: {},\n discountWordTranslations: {},\n // amber-700 / emerald-700, not the 600s: the `plain` style renders the\n // disclosure as coloured TEXT, so it is bound by `WCAG_AA_TEXT` (4.5) rather\n // than by the 3:1 a coloured shape would be, and the 600s come to 3.19 and\n // 3.77 against the default white surface. These are 5.02 and 5.48, pinned by\n // tests. Far enough apart to read as opposite news at a glance rather than as\n // two shades of \"extra\".\n surchargeColor: '#b45309',\n discountColor: '#047857',\n\n layout: 'split',\n summaryPosition: 'left',\n showOrderSummary: true,\n summaryGradient: false,\n showTotal: true,\n totalLabel: 'Total',\n showCurrencyCode: false,\n showOrderItems: true,\n cancelLinkEnabled: true,\n cancelLinkPosition: 'top',\n cancelLinkStyle: 'link',\n\n // Each flat field keeps its meaning: what the merchant wrote, used in every\n // locale that carries no override. Empty maps therefore change nothing for a\n // profile saved before translations existed.\n headerText: '',\n headerTextTranslations: {},\n payButtonLabel: '',\n payButtonLabelTranslations: {},\n cardTermsMessage: '',\n cardTermsMessageTranslations: {},\n footerText: '',\n footerTextTranslations: {},\n supportEmail: '',\n\n paymentLayout: 'tabs',\n labelStyle: 'above',\n showPoweredBy: true,\n\n // Every one of these defaults to what the Airwallex pane already did before\n // the section existed, so a merchant who never opens it sees no change:\n // empty preset (defer to the connector account), an outlined box, 16px /\n // 500 type, no focus ring, the browser's own autofill highlight, no valid\n // tint, no marks. The single deliberate change of behaviour is not here —\n // it is the fallback at the END of `resolveAirwallexCardPreset`, which\n // moves a shop that configured NOTHING from the combined row to the\n // labelled split form.\n airwallexCardPreset: '',\n // Off. With this on, no buyer can pay by card on the shop.\n airwallexHideCard: false,\n // Off: the section is named, like every other section on the surface.\n airwallexHideCardTitle: false,\n airwallexFieldChrome: 'outlined',\n airwallexLabelStyle: '',\n airwallexFieldFontSize: 'md',\n airwallexFieldWeight: 'medium',\n airwallexFocusRing: 'none',\n airwallexAutofill: 'system',\n airwallexValidTint: false,\n airwallexNetworkMarks: false,\n\n // Every card-form field below starts on what its pane drew before the\n // setting existed, so a merchant who never opens a section sees no change.\n stripeTheme: 'auto',\n stripeInputs: 'spaced',\n stripeLabels: 'above',\n stripeSpacing: 'comfortable',\n stripeFieldFontSize: 'md',\n stripeFieldWeight: 'medium',\n stripeFocusRing: 'strong',\n stripeDisableAnimations: false,\n paypalCardLayout: 'split',\n paypalLabelStyle: 'above',\n paypalFieldChrome: 'outlined',\n mollieFieldChrome: 'outlined',\n paypalFieldFontSize: 'md',\n mollieFieldFontSize: 'md',\n paypalFieldWeight: 'regular',\n mollieFieldWeight: 'regular',\n paypalFocusRing: 'strong',\n mollieFocusRing: 'strong',\n paypalValidTint: false,\n epayoutsCardLayout: 'split',\n epayoutsLabelStyle: 'above',\n epayoutsFieldChrome: 'outlined',\n epayoutsFieldFontSize: 'md',\n epayoutsFieldWeight: 'regular',\n epayoutsFocusRing: 'strong',\n epayoutsValidTint: false,\n nomupayFormStyle: 'plain',\n nomupayShowLabels: true,\n nomupayShowPlaceholders: true,\n nomupayShowCvvHint: false,\n nomupayFieldChrome: 'outlined',\n nomupayFieldFontSize: 'md',\n nomupayFocusRing: 'none',\n nomupayApplePayButtonStyle: 'auto',\n nomupayApplePayButtonType: 'pay',\n nomupayGooglePayButtonColor: 'auto',\n nomupayGooglePayButtonType: 'pay',\n micropaymentFieldChrome: 'outlined',\n micropaymentFieldFontSize: 'md',\n micropaymentFieldWeight: 'regular',\n micropaymentFocusRing: 'strong',\n whopCardPreset: 'card_stacked',\n whopAccentColor: 'auto',\n whopGrayColor: 'auto',\n whopBillingDetails: 'minimal',\n whopSeparated: false,\n whopEmailLabel: 'above',\n whopFieldChrome: 'outlined',\n whopFieldFontSize: 'md',\n whopFieldWeight: 'regular',\n whopFocusRing: 'strong',\n whopRadius: 'checkout',\n whopShadow: 'soft',\n whopMethodIcons: true,\n whopSelection: 'radio_tint',\n\n customCss: '',\n // The Enigma Vault card form: the Stripe-like template.\n ...DEFAULT_ENIGMA_CARD_FORM,\n};\n\nexport const DEFAULT_BRANDING: CheckoutBranding = {\n ...DEFAULT_BRANDING_BASE,\n ...LIGHT_PALETTE,\n // No badges by default any more — notices took their place.\n // `DEFAULT_BADGES` stays exported because `isDefaultBadgeSet` still has to\n // recognise the pair on shops saved before.\n trustBadges: [],\n notices: defaultNotices(),\n customFields: [],\n methodSectionOrder: defaultMethodSectionOrder(),\n methodSectionLabels: {},\n};\n\n// Dark counterpart to DEFAULT_BRANDING. Same form-only fields stay empty\n// (logo / display name / tagline / copy) — only visual tokens diverge.\n// Palette mirrors the design-guidelines dark ramp:\n// - background = slate-950, surface = slate-900 → soft contrast.\n// - text = slate-200, heading = slate-50 → AA+ contrast on the surface.\n// - muted = slate-400, border = slate-800 → chrome that fades into the bg.\n// - accentText = primary-400, button bg = brand blue → brand pops on dark\n// where the light theme's near-black navy CTA would disappear.\n// - surfaceStyle = 'flat' because soft drop-shadows don't read on dark\n// surfaces; the existing 'elevated' shadow tokens are tuned for light.\nexport const DEFAULT_BRANDING_DARK: CheckoutBranding = {\n ...DEFAULT_BRANDING_BASE,\n primary: '#1E4FEB',\n background: '#020617',\n surface: '#0f172a',\n text: '#e2e8f0',\n heading: '#f8fafc',\n muted: '#94a3b8',\n border: '#1e293b',\n accentText: '#60a5fa',\n buttonBackground: '#1E4FEB',\n buttonText: '#ffffff',\n surfaceStyle: 'flat',\n // amber-400 / emerald-400: the 700s above are far too dark to read on\n // slate-900, and this pair is the same news in the same order at the light\n // end of the ramp — 10.69 and 9.29 against the dark surface, also pinned.\n surchargeColor: '#fbbf24',\n discountColor: '#34d399',\n trustBadges: [],\n notices: defaultNotices(),\n customFields: [],\n methodSectionOrder: defaultMethodSectionOrder(),\n methodSectionLabels: {},\n};\n\n// Back-compat alias. Prefer `DEFAULT_BRANDING` directly.\nexport function defaultBranding(): CheckoutBranding {\n return cloneBranding(DEFAULT_BRANDING);\n}\n\n// Deep-ish clone — needed because the form mutates state reactively and we\n// don't want shared TrustBadge / CheckoutCustomField object refs across the\n// loaded/edit/default snapshots. Spread is shallow; array elements would\n// otherwise be shared between snapshots, breaking reset.\nexport function cloneBranding(b: CheckoutBranding): CheckoutBranding {\n return {\n ...b,\n trustBadges: b.trustBadges.map((badge) => ({ ...badge })),\n notices: b.notices.map(cloneNotice),\n customFields: b.customFields.map(cloneCustomField),\n methodSectionOrder: { ...b.methodSectionOrder },\n methodSectionLabels: Object.fromEntries(\n Object.entries(b.methodSectionLabels).map(([id, byLocale]) => [id, { ...byLocale }]),\n ),\n // Copied, not shared. A spread alone would leave the clone pointing at the\n // original's maps, and the dashboard edits a clone precisely so the form\n // can be abandoned without touching what is saved.\n surchargeWordTranslations: { ...b.surchargeWordTranslations },\n discountWordTranslations: { ...b.discountWordTranslations },\n headerTextTranslations: { ...b.headerTextTranslations },\n payButtonLabelTranslations: { ...b.payButtonLabelTranslations },\n cardTermsMessageTranslations: { ...b.cardTermsMessageTranslations },\n footerTextTranslations: { ...b.footerTextTranslations },\n };\n}\n\nexport function cloneCustomField(f: CheckoutCustomField): CheckoutCustomField {\n return {\n ...f,\n labelTranslations: { ...f.labelTranslations },\n placeholderTranslations: { ...f.placeholderTranslations },\n helpTextTranslations: { ...f.helpTextTranslations },\n options: f.options.map((o) => ({ ...o, labelTranslations: { ...o.labelTranslations } })),\n visibility: {\n ...f.visibility,\n conditions: f.visibility.conditions.map((c) => ({ ...c })),\n },\n };\n}\n\n// --- Sanitizer ----------------------------------------------------------\n\n// Hard cap on the persisted custom CSS payload. Mirrors the editor's\n// validation; oversized input is dropped to null rather than truncated,\n// since a half-truncated rule is worse than no rule.\nexport const CUSTOM_CSS_MAX_LENGTH = 50_000;\n\n// Strip CSS tokens that turn a stylesheet into a delivery vector before\n// handing the merchant's input to the renderer. The list isn't exhaustive\n// — it's the everyday surface area:\n//\n// - `</style` would let injected text break out of the <style> block and\n// parse as HTML/JS. Replaced with a benign token (not removed) so\n// `</styled-tag` (unlikely but possible inside a content: string)\n// doesn't silently merge into surrounding text.\n// - `@import` would let the merchant pull in a remote stylesheet on\n// every buyer page-load (analytics by side-channel; possible buyer-IP\n// leak).\n// - `expression(…)` was a legacy IE construct that ran JS from CSS.\n// - `behavior:` and `-moz-binding:` ditto for IE/old-Gecko.\n// - `javascript:` URLs in url(...) execute on resource load in some\n// browsers/contexts.\n//\n// Anything else passes through. The merchant can still write whatever\n// declarations they like (background images, gradients, transforms,\n// keyframes, container queries, …).\nexport function sanitizeCustomCss(raw: string | null | undefined): string | null {\n if (typeof raw !== 'string') return null;\n const trimmed = raw.trim();\n if (trimmed.length === 0) return null;\n if (trimmed.length > CUSTOM_CSS_MAX_LENGTH) return null;\n\n let out = trimmed;\n out = out.replace(/<\\/style/gi, '<\\\\/style');\n out = out.replace(/@import\\b[^;]*;?/gi, '');\n out = out.replace(/expression\\s*\\(/gi, '/* expression( */');\n out = out.replace(/(^|[^a-z-])behavior\\s*:/gi, '$1/* behavior: */');\n out = out.replace(/-moz-binding\\s*:/gi, '/* -moz-binding: */');\n out = out.replace(/url\\s*\\(\\s*[\"']?\\s*javascript:/gi, 'url(invalid:');\n return out;\n}\n\n// --- Codec --------------------------------------------------------------\n\n// Structural shape the decoder reads. Both `CheckoutDetails` (public buyer\n// payload) and `BusinessPaymentLinkConfig` (merchant config request shape)\n// satisfy this via duck typing — they each fill some of these and leave the\n// rest undefined. `merchant_*` and `seller_*`/`logo` are aliases for the\n// same API field, surfaced under different names by the two payloads.\nexport interface BrandingSource {\n // Identity (one or the other, depending on payload shape)\n merchant_name?: string | null;\n seller_name?: string | null;\n merchant_logo?: string | null;\n logo?: string | null;\n merchant_description?: string | null;\n\n // Visual\n theme?: string | null;\n background_colour?: string | null;\n payment_button_colour?: string | null;\n payment_button_text_colour?: string | null;\n\n // Copy\n payment_form_header_text?: string | null;\n payment_button_text?: string | null;\n custom_message_for_card_terms?: string | null;\n\n // Footer\n branding_visibility?: boolean | null;\n\n // Stripe\n sdk_layout?: string | null;\n payment_form_label_type?: string | null;\n\n // The bag for everything else\n sdk_ui_rules?: Record<string, Record<string, string> | null | undefined> | null;\n}\n\nconst BRANDING_GROUP_KEY = 'branding';\n\nconst ALL_FONT_FAMILIES: readonly FontFamily[] = [\n 'inter',\n 'system',\n 'serif',\n 'mono',\n 'roboto',\n 'poppins',\n 'manrope',\n 'dm-sans',\n 'space-grotesk',\n 'plex-sans',\n 'work-sans',\n 'open-sans',\n 'lora',\n 'playfair',\n 'plex-mono',\n 'jetbrains-mono',\n];\n\nconst ALL_RADII: readonly CornerRadius[] = ['square', 'small', 'medium', 'large', 'pill'];\nconst NON_PILL_RADII: readonly NonPillRadius[] = ['square', 'small', 'medium', 'large'];\n\nfunction pickEnum<T extends string>(value: unknown, allowed: readonly T[], fallback: T): T {\n if (typeof value !== 'string') return fallback;\n return (allowed as readonly string[]).includes(value) ? (value as T) : fallback;\n}\n\n/**\n * `pickEnum` for a field whose \"unset\" state is the empty string.\n *\n * Anything not on the list — absent, blank, or a token this build has not\n * heard of — decodes to `''`, which every consumer reads as \"defer\". That is\n * the difference between this and `pickEnum`: there the unknown becomes a\n * concrete value and starts overriding whatever it was deferring to.\n */\nfunction pickEnumOrEmpty<T extends string>(value: unknown, allowed: readonly T[]): T | '' {\n if (typeof value !== 'string') return '';\n return (allowed as readonly string[]).includes(value) ? (value as T) : '';\n}\n\nfunction parseBool(value: unknown, fallback: boolean): boolean {\n if (typeof value === 'boolean') return value;\n if (value === 'true') return true;\n if (value === 'false') return false;\n return fallback;\n}\n\nfunction s(value: string | null | undefined): string {\n return typeof value === 'string' ? value : '';\n}\n\n// Decode the JSON-encoded trust badges stored under\n// `sdk_ui_rules.branding.trustBadges`. Tolerant: a malformed payload,\n// missing fields, or wrong types fall through to null so the caller can\n// substitute the default badge set. An explicit empty array means \"no\n// badges\" (we honor it — merchants who hide the row need a way to express\n// that).\nexport function decodeBadges(raw: string | undefined): TrustBadge[] | null {\n if (raw === undefined) return null;\n try {\n const parsed: unknown = JSON.parse(raw);\n if (!Array.isArray(parsed)) return null;\n return parsed\n .filter((b): b is Record<string, unknown> => !!b && typeof b === 'object')\n .map((b, i) => ({\n id: typeof b['id'] === 'string' && b['id'] ? (b['id'] as string) : `badge-${i}`,\n label: typeof b['label'] === 'string' ? (b['label'] as string) : '',\n textColor: typeof b['textColor'] === 'string' ? (b['textColor'] as string) : '#0f172a',\n backgroundColor:\n typeof b['backgroundColor'] === 'string' ? (b['backgroundColor'] as string) : '#f1f5f9',\n borderColor:\n typeof b['borderColor'] === 'string' && b['borderColor']\n ? (b['borderColor'] as string)\n : null,\n }))\n .filter((b) => b.label.length > 0);\n } catch {\n return null;\n }\n}\n\nexport function encodeBadges(badges: TrustBadge[]): string {\n return JSON.stringify(\n badges.map((b) => ({\n id: b.id,\n label: b.label,\n textColor: b.textColor,\n backgroundColor: b.backgroundColor,\n ...(b.borderColor ? { borderColor: b.borderColor } : {}),\n })),\n );\n}\n\n// --- Notices codec --------------------------------------------\n\n/** A notice id is code-shaped: it keys a drag, never a buyer's eyes. */\nconst NOTICE_ID_MAX_LENGTH = 40;\n\nfunction capNoticeText(value: string): string {\n return Array.from(value).slice(0, NOTICE_LABEL_MAX_LENGTH).join('');\n}\n\n/**\n * Normalize a list of notices from any source — the bag, an import file.\n *\n * Total, like `decodeBadges`: every buyer sees these, so a malformed entry\n * degrades to a smaller list, never to a broken page.\n *\n * - not an object → dropped;\n * - unknown section → `summary`; unknown icon → `NOTICE_ICON_FALLBACK`;\n * - id cleaned to `[A-Za-z0-9_-]`, a missing or repeated one replaced, so the\n * editor can track every row across a drag;\n * - text cut to `NOTICE_LABEL_MAX_LENGTH` characters, blank overrides dropped;\n * - a notice with no text in any language → dropped (it would draw an icon\n * with nothing beside it);\n * - past `NOTICES_PER_SECTION` in its section → dropped, first come first\n * kept, so what is stored is what is drawn.\n */\nfunction normalizeNotices(list: readonly unknown[]): CheckoutNotice[] {\n const seen = new Set<string>();\n const perSection = new Map<NoticeSection, number>();\n const out: CheckoutNotice[] = [];\n\n list.forEach((raw, index) => {\n if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return;\n const src = raw as Record<string, unknown>;\n\n const label = typeof src['label'] === 'string' ? capNoticeText(src['label']) : '';\n const labelTranslations: CustomFieldTranslations = {};\n for (const [locale, text] of Object.entries(parseTranslations(src['labelTranslations']))) {\n labelTranslations[locale] = capNoticeText(text);\n }\n if (label.trim().length === 0 && Object.keys(labelTranslations).length === 0) return;\n\n const section = pickEnum<NoticeSection>(src['section'], NOTICE_SECTIONS, 'summary');\n const used = perSection.get(section) ?? 0;\n if (used >= NOTICES_PER_SECTION) return;\n perSection.set(section, used + 1);\n\n let id =\n typeof src['id'] === 'string'\n ? src['id'].replace(/[^A-Za-z0-9_-]/g, '').slice(0, NOTICE_ID_MAX_LENGTH)\n : '';\n if (!id || seen.has(id)) id = `notice-${index + 1}`;\n while (seen.has(id)) id = `${id}x`;\n seen.add(id);\n\n out.push({\n id,\n section,\n icon: isNoticeIcon(src['icon']) ? src['icon'] : NOTICE_ICON_FALLBACK,\n label,\n labelTranslations,\n });\n });\n\n return out;\n}\n\n/**\n * Decode `sdk_ui_rules.branding.notices`.\n *\n * `null` when the key is absent or not a JSON array — \"this shop has no say\n * about notices\", which `resolveNoticesAndBadges` turns into the migration.\n * An empty array is a say: the merchant removed every notice.\n */\nexport function decodeNotices(raw: string | undefined): CheckoutNotice[] | null {\n if (raw === undefined) return null;\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch {\n return null;\n }\n return Array.isArray(parsed) ? normalizeNotices(parsed) : null;\n}\n\n/** The import file's form: an array inline rather than a JSON string. */\nexport function parseNoticesLoose(raw: unknown): CheckoutNotice[] | null {\n if (typeof raw === 'string') return decodeNotices(raw);\n return Array.isArray(raw) ? normalizeNotices(raw) : null;\n}\n\n/**\n * Encode notices for the bag. Always a JSON array, `[]` included: the key's\n * presence is what tells a later decode that the shop has decided, so it must\n * be written even when there is nothing in it.\n */\nexport function encodeNotices(notices: readonly CheckoutNotice[]): string {\n return JSON.stringify(\n notices.map((n) => {\n const translations = Object.entries(n.labelTranslations).filter(\n ([, text]) => text.trim().length > 0,\n );\n return {\n id: n.id,\n section: n.section,\n icon: n.icon,\n label: n.label,\n ...(translations.length > 0 ? { labelTranslations: Object.fromEntries(translations) } : {}),\n };\n }),\n );\n}\n\n/**\n * A notice's text in the buyer's locale: exact locale, then its base\n * language, then the default text — the order every other piece of merchant\n * copy resolves in (`checkoutCopy`, `customFieldText`).\n *\n * `''` when the notice has no text for this locale: a notice written only in\n * some languages, with no default, is one the merchant shows only in those\n * languages (the POC's \"empty means: not in this language\"). It is not a\n * notice to draw without words — use `shownNotices`, which leaves it out.\n */\nexport function noticeText(notice: CheckoutNotice, locale?: string): string {\n return translationFor(notice.labelTranslations, locale) ?? notice.label;\n}\n\n/**\n * The notices one section draws, in order, capped at `NOTICES_PER_SECTION`.\n * The decoder already caps; this caps again for state that never went through\n * it, such as the customizer's unsaved edits in the live preview.\n */\nexport function noticesIn(\n notices: readonly CheckoutNotice[],\n section: NoticeSection,\n): CheckoutNotice[] {\n return notices.filter((n) => n.section === section).slice(0, NOTICES_PER_SECTION);\n}\n\n/** One notice as a buyer sees it: the notice, and its text in their locale. */\nexport interface ShownNotice {\n notice: CheckoutNotice;\n text: string;\n}\n\n/**\n * What one section draws for a buyer: its notices (capped, as `noticesIn`),\n * each with its text in `locale`, leaving out every notice with no text there.\n *\n * The one place that decides it, so no renderer can draw an icon with nothing\n * beside it. A notice written only in German is simply absent for an English\n * buyer — the cap is applied first, as the decoder applies it, so what a\n * merchant stored in a section is what can ever be drawn from it.\n */\nexport function shownNotices(\n notices: readonly CheckoutNotice[],\n section: NoticeSection,\n locale?: string,\n): ShownNotice[] {\n return noticesIn(notices, section)\n .map((notice) => ({ notice, text: noticeText(notice, locale).trim() }))\n .filter((entry) => entry.text.length > 0);\n}\n\n// --- Custom checkout fields codec ---------------------------------------\n\nexport const CUSTOM_FIELDS_MAX = 20;\n// Metadata keys: start with a letter, then letters/digits/underscore/dash.\n// Keeps keys safe for every downstream metadata consumer (dashboards,\n// exports, PSP forwarding).\nexport const CUSTOM_FIELD_KEY_PATTERN = /^[A-Za-z][A-Za-z0-9_-]{0,39}$/;\n\nexport const ALL_CUSTOM_FIELD_TYPES: readonly CustomFieldType[] = [\n 'text',\n 'textarea',\n 'password',\n 'email',\n 'select',\n 'checkbox',\n];\n\n// The two values a checkbox field ever submits. Kept as strings because the\n// whole metadata bag is `Record<string, string>` on the wire.\nexport const CHECKBOX_CHECKED = 'true';\nexport const CHECKBOX_UNCHECKED = 'false';\n\n/** Whether a stored/submitted checkbox value counts as ticked. Tolerant of\n * case and padding so a value round-tripped through a shop integration\n * ('True', ' true ') still reads correctly. */\nexport function isCheckboxChecked(value: string | null | undefined): boolean {\n return typeof value === 'string' && value.trim().toLowerCase() === CHECKBOX_CHECKED;\n}\n\n/** Types whose value is free text, so length bounds and a placeholder apply.\n * `select` and `checkbox` are choice controls and have neither. */\nexport function customFieldIsTextLike(type: CustomFieldType): boolean {\n return type !== 'select' && type !== 'checkbox';\n}\n\n// Rule-builder vocabulary. Kept next to the codec so the editor, the\n// evaluator and the Rust mirror all read from one list.\nexport const CUSTOM_FIELD_CONDITIONS_MAX = 10;\n\nexport const ALL_CUSTOM_FIELD_CONDITION_SOURCES: readonly CustomFieldConditionSource[] = [\n 'metadata',\n 'currency',\n 'amount',\n];\n\nexport const ALL_CUSTOM_FIELD_OPERATORS: readonly CustomFieldOperator[] = [\n 'equals',\n 'not_equals',\n 'contains',\n 'not_contains',\n 'starts_with',\n 'ends_with',\n 'in',\n 'not_in',\n 'exists',\n 'not_exists',\n 'gt',\n 'gte',\n 'lt',\n 'lte',\n];\n\n// Which operators make sense per source. Currency is a closed 3-letter set,\n// so substring/numeric operators would only ever confuse; amount is numeric,\n// so string operators don't apply. Metadata is free-form and gets all of them.\nexport const CUSTOM_FIELD_OPERATORS_BY_SOURCE: Record<\n CustomFieldConditionSource,\n readonly CustomFieldOperator[]\n> = {\n metadata: ALL_CUSTOM_FIELD_OPERATORS,\n currency: ['equals', 'not_equals', 'in', 'not_in'],\n amount: ['equals', 'not_equals', 'gt', 'gte', 'lt', 'lte'],\n};\n\n// Operators that ignore the right-hand operand — the editor hides the value\n// input for these, and validation must not demand a value.\nexport const CUSTOM_FIELD_VALUELESS_OPERATORS: readonly CustomFieldOperator[] = [\n 'exists',\n 'not_exists',\n];\n\nexport function customFieldOperatorTakesValue(operator: CustomFieldOperator): boolean {\n return !CUSTOM_FIELD_VALUELESS_OPERATORS.includes(operator);\n}\n\n// The operator a condition falls back to when its source changes and the\n// current operator isn't valid for the new source.\nexport function defaultOperatorForSource(source: CustomFieldConditionSource): CustomFieldOperator {\n return CUSTOM_FIELD_OPERATORS_BY_SOURCE[source][0] ?? 'equals';\n}\n\nexport function defaultCustomFieldVisibility(): CustomFieldVisibility {\n return { mode: 'always', match: 'all', conditions: [] };\n}\n\nfunction parseTranslations(raw: unknown): CustomFieldTranslations {\n // The branding bag stores every value as a string, so a map persisted there\n // arrives as JSON; an import file and a custom field carry it inline. Both\n // reach this, and a string that is not JSON is simply not a map.\n let value = raw;\n if (typeof value === 'string') {\n try {\n value = JSON.parse(value) as unknown;\n } catch {\n return {};\n }\n }\n if (!value || typeof value !== 'object' || Array.isArray(value)) return {};\n const out: CustomFieldTranslations = {};\n for (const [k, v] of Object.entries(value as Record<string, unknown>)) {\n // Own properties only: a persisted key of `__proto__` or `constructor`\n // must not reach the object being built, and `Object.entries` already\n // gives own enumerable keys only — the length check is what drops a blank\n // override, which means \"no override\" rather than \"render nothing\".\n if (typeof v === 'string' && v.trim().length > 0) out[k] = v;\n }\n return out;\n}\n\n/**\n * A translations map for the branding bag, or `undefined` when there is\n * nothing to store.\n *\n * Omitting the key rather than writing `{}` keeps the bag of a merchant who\n * never opened the translations strip byte-identical to what it was before\n * these fields existed.\n */\nfunction encodeTranslations(map: CustomFieldTranslations): string | undefined {\n const entries = Object.entries(map).filter(([, v]) => v.trim().length > 0);\n return entries.length > 0 ? JSON.stringify(Object.fromEntries(entries)) : undefined;\n}\n\n// Normalize one persisted condition. Total: an unusable source/operator\n// falls back rather than dropping the row, so a rule authored by a newer\n// dashboard never silently becomes \"always visible\" on an older\n// decoder — it becomes a stricter, still-evaluable rule.\nfunction normalizeCondition(raw: unknown, index: number): CustomFieldCondition | null {\n if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;\n const c = raw as Record<string, unknown>;\n const source = pickEnum<CustomFieldConditionSource>(\n c['source'],\n ALL_CUSTOM_FIELD_CONDITION_SOURCES,\n 'metadata',\n );\n const allowed = CUSTOM_FIELD_OPERATORS_BY_SOURCE[source];\n const operator = pickEnum<CustomFieldOperator>(\n c['operator'],\n allowed,\n defaultOperatorForSource(source),\n );\n const rawValue = c['value'];\n return {\n id: typeof c['id'] === 'string' && c['id'] ? (c['id'] as string) : `cond-${index}`,\n source,\n // Only metadata conditions carry a key; drop anything else so the\n // encoded form stays canonical.\n key: source === 'metadata' && typeof c['key'] === 'string' ? c['key'].trim() : '',\n operator,\n value:\n typeof rawValue === 'string'\n ? rawValue\n : typeof rawValue === 'number' || typeof rawValue === 'boolean'\n ? String(rawValue)\n : '',\n };\n}\n\nfunction normalizeVisibility(raw: unknown): CustomFieldVisibility {\n if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return defaultCustomFieldVisibility();\n const v = raw as Record<string, unknown>;\n const conditions: CustomFieldCondition[] = Array.isArray(v['conditions'])\n ? (v['conditions'] as unknown[])\n .slice(0, CUSTOM_FIELD_CONDITIONS_MAX)\n .map(normalizeCondition)\n .filter((c): c is CustomFieldCondition => c !== null)\n : [];\n return {\n mode: pickEnum<'always' | 'match'>(v['mode'], ['always', 'match'], 'always'),\n match: pickEnum<'all' | 'any'>(v['match'], ['all', 'any'], 'all'),\n conditions,\n };\n}\n\nfunction parseBoundedInt(raw: unknown): number | null {\n const n = typeof raw === 'number' ? raw : typeof raw === 'string' ? Number(raw) : NaN;\n if (!Number.isInteger(n) || n < 0) return null;\n return Math.min(n, 5000);\n}\n\n// Normalize one persisted/imported field object. Total: anything malformed\n// falls back per-property; returns null only when there is no usable key.\nfunction normalizeCustomField(raw: unknown, index: number): CheckoutCustomField | null {\n if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;\n const f = raw as Record<string, unknown>;\n const key = typeof f['key'] === 'string' ? f['key'].trim() : '';\n if (!CUSTOM_FIELD_KEY_PATTERN.test(key)) return null;\n\n const type = pickEnum<CustomFieldType>(f['type'], ALL_CUSTOM_FIELD_TYPES, 'text');\n\n const options: CustomFieldOption[] =\n type === 'select' && Array.isArray(f['options'])\n ? (f['options'] as unknown[])\n .filter((o): o is Record<string, unknown> => !!o && typeof o === 'object')\n .map((o) => {\n const value = typeof o['value'] === 'string' ? o['value'] : '';\n return {\n value,\n label: typeof o['label'] === 'string' && o['label'] ? (o['label'] as string) : value,\n labelTranslations: parseTranslations(o['labelTranslations']),\n };\n })\n .filter((o) => o.value.length > 0)\n : [];\n\n // Length bounds are meaningless for choice controls; drop them at decode\n // so a field switched to checkbox/select can't carry stale bounds that\n // would then be validated against 'true'/'false'.\n const textLike = customFieldIsTextLike(type);\n const minLength = textLike ? parseBoundedInt(f['minLength']) : null;\n const maxLength = textLike ? parseBoundedInt(f['maxLength']) : null;\n\n // A checkbox default is a tick state, not free text: anything that isn't\n // truthy normalizes to unchecked, so the control can never start in a\n // third state.\n const rawDefault = typeof f['defaultValue'] === 'string' ? f['defaultValue'] : '';\n const defaultValue =\n type === 'checkbox'\n ? isCheckboxChecked(rawDefault)\n ? CHECKBOX_CHECKED\n : CHECKBOX_UNCHECKED\n : rawDefault;\n\n return {\n id: typeof f['id'] === 'string' && f['id'] ? (f['id'] as string) : `field-${index}`,\n key,\n type,\n label: typeof f['label'] === 'string' && f['label'] ? (f['label'] as string) : key,\n labelTranslations: parseTranslations(f['labelTranslations']),\n placeholder: typeof f['placeholder'] === 'string' ? (f['placeholder'] as string) : '',\n placeholderTranslations: parseTranslations(f['placeholderTranslations']),\n helpText: typeof f['helpText'] === 'string' ? (f['helpText'] as string) : '',\n helpTextTranslations: parseTranslations(f['helpTextTranslations']),\n required: parseBool(f['required'], false),\n enabled: parseBool(f['enabled'], true),\n minLength,\n // Guard inverted bounds at decode so consumers never see min > max.\n maxLength: maxLength !== null && minLength !== null && maxLength < minLength ? null : maxLength,\n defaultValue,\n options,\n visibility: normalizeVisibility(f['visibility']),\n };\n}\n\n// Parse an array of field objects (already JSON-parsed). Null when the\n// input isn't an array — callers fall back to \"no custom fields\". Duplicate\n// keys keep the first occurrence; the list is capped at CUSTOM_FIELDS_MAX.\nexport function parseCustomFieldsLoose(raw: unknown): CheckoutCustomField[] | null {\n if (!Array.isArray(raw)) return null;\n const seen = new Set<string>();\n const out: CheckoutCustomField[] = [];\n for (let i = 0; i < raw.length && out.length < CUSTOM_FIELDS_MAX; i++) {\n const field = normalizeCustomField(raw[i], i);\n if (!field || seen.has(field.key)) continue;\n seen.add(field.key);\n out.push(field);\n }\n return out;\n}\n\n// Decode the JSON-encoded custom fields stored under\n// `sdk_ui_rules.branding.customFields`. Tolerant like `decodeBadges`:\n// malformed payloads fall through to null.\nexport function decodeCustomFields(raw: string | undefined): CheckoutCustomField[] | null {\n if (raw === undefined) return null;\n try {\n return parseCustomFieldsLoose(JSON.parse(raw));\n } catch {\n return null;\n }\n}\n\nexport function encodeCustomFields(fields: CheckoutCustomField[]): string {\n const nonEmpty = (m: CustomFieldTranslations): CustomFieldTranslations | undefined => {\n const entries = Object.entries(m).filter(([, v]) => v.trim().length > 0);\n return entries.length > 0 ? Object.fromEntries(entries) : undefined;\n };\n return JSON.stringify(\n fields.map((f) => ({\n id: f.id,\n key: f.key,\n type: f.type,\n label: f.label,\n ...(nonEmpty(f.labelTranslations)\n ? { labelTranslations: nonEmpty(f.labelTranslations) }\n : {}),\n ...(f.placeholder ? { placeholder: f.placeholder } : {}),\n ...(nonEmpty(f.placeholderTranslations)\n ? { placeholderTranslations: nonEmpty(f.placeholderTranslations) }\n : {}),\n ...(f.helpText ? { helpText: f.helpText } : {}),\n ...(nonEmpty(f.helpTextTranslations)\n ? { helpTextTranslations: nonEmpty(f.helpTextTranslations) }\n : {}),\n ...(f.required ? { required: true } : {}),\n ...(f.enabled ? {} : { enabled: false }),\n // Length bounds only exist for free-text types; a choice control that\n // still carries them is stale state the decoder would drop anyway.\n ...(customFieldIsTextLike(f.type) && f.minLength !== null ? { minLength: f.minLength } : {}),\n ...(customFieldIsTextLike(f.type) && f.maxLength !== null ? { maxLength: f.maxLength } : {}),\n // A checkbox persists only \"starts ticked\"; unticked is the decoder's\n // default, so writing 'false' would be noise on every such field.\n ...(f.type === 'checkbox'\n ? isCheckboxChecked(f.defaultValue)\n ? { defaultValue: CHECKBOX_CHECKED }\n : {}\n : f.defaultValue\n ? { defaultValue: f.defaultValue }\n : {}),\n ...(f.type === 'select' ? { options: f.options } : {}),\n // Omitted for unconditional fields so the stored blob (and every\n // pre-feature payload) stays byte-identical to what it was.\n ...(f.visibility.mode === 'match' ? { visibility: encodeVisibility(f.visibility) } : {}),\n })),\n );\n}\n\nfunction encodeVisibility(v: CustomFieldVisibility): Record<string, unknown> {\n return {\n mode: v.mode,\n match: v.match,\n conditions: v.conditions.map((c) => ({\n id: c.id,\n source: c.source,\n ...(c.source === 'metadata' && c.key ? { key: c.key } : {}),\n operator: c.operator,\n ...(customFieldOperatorTakesValue(c.operator) && c.value ? { value: c.value } : {}),\n })),\n };\n}\n\n// --- Conditional-visibility evaluator -----------------------------------\n\n/** Facts a rule can read. `amount` is in the currency's minor unit (what\n * the payment intent stores); `metadata` values are already flattened to\n * strings by `customFieldContextFromMetadata`. */\nexport interface CustomFieldContext {\n amount: number;\n currency: string;\n metadata: Record<string, string>;\n}\n\n/** Flatten a payment's raw `metadata` object into the string map a rule\n * compares against. Arrays join on `,` so a list-shaped value stays usable\n * with `contains` / `in`; objects fall back to JSON. Mirrors the Rust\n * side's `flatten_metadata`. */\nexport function customFieldContextFromMetadata(raw: unknown): Record<string, string> {\n const out: Record<string, string> = {};\n if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return out;\n for (const [key, value] of Object.entries(raw as Record<string, unknown>)) {\n const flat = flattenMetadataValue(value);\n if (flat !== null) out[key] = flat;\n }\n return out;\n}\n\nfunction flattenMetadataValue(value: unknown): string | null {\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n if (value === null || value === undefined) return null;\n if (Array.isArray(value)) {\n return value\n .map((v) => flattenMetadataValue(v))\n .filter((v): v is string => v !== null)\n .join(',');\n }\n try {\n return JSON.stringify(value);\n } catch {\n return null;\n }\n}\n\n// Case- and whitespace-insensitive: merchants type `Windows` in the builder\n// and the shop sends `windows`. Exact-case matching would be a support\n// ticket generator.\nfunction norm(value: string): string {\n return value.trim().toLowerCase();\n}\n\n// Decimal-float grammar, deliberately narrower than `Number()`.\n//\n// `Number()` accepts radix-prefixed literals — `Number('0x10') === 16` — while\n// the router's Rust mirror uses `f64::from_str`, which rejects them. Left\n// unconstrained, a metadata value of `0x10` would satisfy `gte 5` in the\n// dashboard's builder and fail it on the backend: the merchant sees one\n// rule, buyers get another. This regex is `f64::from_str`'s number grammar\n// (sign, digits with optional point, optional exponent); `inf`/`nan` are\n// excluded here rather than by the finiteness check below, which matches\n// Rust filtering them out too.\nconst DECIMAL_NUMBER_PATTERN = /^[+-]?(?:\\d+\\.?\\d*|\\.\\d+)(?:[eE][+-]?\\d+)?$/;\n\n// Both implementations compare as f64, so they round identically. Payment\n// amounts in minor units are far below 2^53, where that is lossless.\nfunction numeric(value: string): number | null {\n const trimmed = value.trim();\n if (!DECIMAL_NUMBER_PATTERN.test(trimmed)) return null;\n const n = Number(trimmed);\n return Number.isFinite(n) ? n : null;\n}\n\nfunction splitList(value: string): string[] {\n return value\n .split(',')\n .map((part) => norm(part))\n .filter((part) => part.length > 0);\n}\n\n/** Resolve the left-hand operand. `undefined` means \"the metadata key is\n * absent\" — which only `exists`/`not_exists` distinguish from empty. */\nfunction operandFor(condition: CustomFieldCondition, ctx: CustomFieldContext): string | undefined {\n switch (condition.source) {\n case 'currency':\n return ctx.currency;\n case 'amount':\n return String(ctx.amount);\n case 'metadata':\n return Object.prototype.hasOwnProperty.call(ctx.metadata, condition.key)\n ? ctx.metadata[condition.key]\n : undefined;\n }\n}\n\nexport function evaluateCustomFieldCondition(\n condition: CustomFieldCondition,\n ctx: CustomFieldContext,\n): boolean {\n const raw = operandFor(condition, ctx);\n const actual = raw ?? '';\n const expected = condition.value;\n\n switch (condition.operator) {\n case 'exists':\n return raw !== undefined && raw.trim().length > 0;\n case 'not_exists':\n return raw === undefined || raw.trim().length === 0;\n case 'equals':\n return norm(actual) === norm(expected);\n case 'not_equals':\n return norm(actual) !== norm(expected);\n case 'contains':\n return norm(actual).includes(norm(expected));\n case 'not_contains':\n return !norm(actual).includes(norm(expected));\n case 'starts_with':\n return norm(actual).startsWith(norm(expected));\n case 'ends_with':\n return norm(actual).endsWith(norm(expected));\n case 'in':\n return splitList(expected).includes(norm(actual));\n case 'not_in':\n return !splitList(expected).includes(norm(actual));\n case 'gt':\n case 'gte':\n case 'lt':\n case 'lte': {\n // Both sides must be numbers. A non-numeric metadata value never\n // matches a numeric comparison (rather than coercing to 0).\n const a = numeric(actual);\n const b = numeric(expected);\n if (a === null || b === null) return false;\n if (condition.operator === 'gt') return a > b;\n if (condition.operator === 'gte') return a >= b;\n if (condition.operator === 'lt') return a < b;\n return a <= b;\n }\n }\n}\n\n/**\n * Whether a field's rule matches the payment.\n *\n * Fail-open in two spots, deliberately: `mode: 'always'` and a `match` rule\n * with no conditions both resolve to visible. A half-authored rule should\n * never silently swallow a field the merchant needs collected — the\n * dashboard flags the empty rule as a validation issue instead.\n */\nexport function evaluateCustomFieldVisibility(\n field: CheckoutCustomField,\n ctx: CustomFieldContext,\n): boolean {\n const { mode, match, conditions } = field.visibility;\n if (mode !== 'match' || conditions.length === 0) return true;\n return match === 'any'\n ? conditions.some((c) => evaluateCustomFieldCondition(c, ctx))\n : conditions.every((c) => evaluateCustomFieldCondition(c, ctx));\n}\n\n/** Filter a field list to what the buyer should see for this payment.\n * Disabled fields are dropped here too — the two reasons a field doesn't\n * render are the same to every consumer. */\nexport function visibleCustomFields(\n fields: CheckoutCustomField[],\n ctx: CustomFieldContext,\n): CheckoutCustomField[] {\n return fields.filter((f) => f.enabled && evaluateCustomFieldVisibility(f, ctx));\n}\n\n// Exact-locale-then-base-language lookup. Own-property + string checks so\n// a hostile or odd locale string ('constructor', '__proto__') can never\n// surface a prototype-chain member as a \"translation\".\n/**\n * Look up one locale's override, walking from most to least specific.\n *\n * Two things this does that an exact-then-base lookup did not, both of which\n * became reachable the moment `zh-Hant` joined the locale list:\n *\n * - **Every parent tag, not just the base.** `zh-Hant-TW` now finds a stored\n * `zh-Hant` before falling through to `zh`. Jumping straight to the base\n * skipped the script entirely, so a Taiwanese buyer read the merchant's\n * simplified copy while a `zh-Hant` box sat filled in beside it.\n * - **Case-insensitive keys.** Locale tags are case-insensitive by spec and\n * arrive both ways — `zh-hant` from a hand-written link, `zh-Hant` from the\n * dashboard. A case-sensitive miss looks exactly like \"no translation\".\n *\n * The map's own casing is preserved on write; only the comparison folds.\n */\nfunction translationFor(map: CustomFieldTranslations, locale?: string): string | null {\n if (!locale) return null;\n\n const folded = new Map<string, string>();\n for (const [k, v] of Object.entries(map)) {\n if (typeof v === 'string' && v.length > 0 && !folded.has(k.toLowerCase())) {\n folded.set(k.toLowerCase(), v);\n }\n }\n\n const parts = locale.toLowerCase().split('-');\n for (let i = parts.length; i > 0; i -= 1) {\n const hit = folded.get(parts.slice(0, i).join('-'));\n if (hit) return hit;\n }\n return null;\n}\n\n// Resolve the display string for a field part in a buyer locale.\n// Exact locale wins ('de-AT'), then its base language ('de'), then the\n// field's default-language string; labels finally fall back to the key so\n// a field is never rendered nameless.\nexport function customFieldText(\n field: CheckoutCustomField,\n part: 'label' | 'placeholder' | 'helpText',\n locale?: string,\n): string {\n const map =\n part === 'label'\n ? field.labelTranslations\n : part === 'placeholder'\n ? field.placeholderTranslations\n : field.helpTextTranslations;\n const translated = translationFor(map, locale);\n if (translated) return translated;\n const fallback = field[part];\n if (fallback) return fallback;\n return part === 'label' ? field.key : '';\n}\n\nexport function customFieldOptionLabel(option: CustomFieldOption, locale?: string): string {\n return translationFor(option.labelTranslations, locale) ?? (option.label || option.value);\n}\n\n// Read a branding source into a fully-resolved CheckoutBranding.\n// Flat fields are authoritative when set; the bag fills in everything not\n// reachable via flat columns. Persisted `labelStyle: 'floating'` (legacy\n// \"floating\" mock) decodes to `'above'`.\nexport function decodeBranding(source: BrandingSource | null | undefined): CheckoutBranding {\n if (!source) return cloneBranding(DEFAULT_BRANDING);\n\n const extras: Record<string, string> = (source.sdk_ui_rules?.[BRANDING_GROUP_KEY] ??\n {}) as Record<string, string>;\n\n // Badges and notices are decided together: which one a shop gets depends\n // on what it saved of both.\n const trustRow = resolveNoticesAndBadges(\n decodeBadges(extras['trustBadges']),\n decodeNotices(extras['notices']),\n );\n const decodedCustomFields = decodeCustomFields(extras['customFields']);\n\n // Identity name: public payloads call it `merchant_name`, request payloads\n // call it `seller_name`. Same API field; pick whichever is present.\n const displayName = s(source.merchant_name) || s(source.seller_name);\n const logoUrl = s(source.merchant_logo) || s(source.logo);\n\n // Tagline lives in the bag, but `merchant_description` is its public\n // surface. Either may fill it; bag wins if both are set.\n const tagline = s(extras['tagline']) || s(source.merchant_description);\n\n // Stripe label style: the bag's `labelStyle` is the new source of truth;\n // the legacy flat `payment_form_label_type` is consulted only when the\n // bag is empty. `'floating'` (a legacy preview-only value that Stripe\n // Elements never honored) decodes to `'above'`. `'never'` (legacy API\n // wording) decodes to `'hidden'`.\n const labelStyle: LabelStyle = (() => {\n const fromBag = extras['labelStyle'];\n if (fromBag === 'above' || fromBag === 'hidden') return fromBag;\n if (fromBag === 'floating') return 'above';\n const legacy = source.payment_form_label_type;\n if (legacy === 'above' || legacy === 'floating') return 'above';\n if (legacy === 'hidden' || legacy === 'never') return 'hidden';\n return DEFAULT_BRANDING.labelStyle;\n })();\n\n return {\n displayName,\n logoUrl,\n tagline,\n showLogo: parseBool(extras['showLogo'], DEFAULT_BRANDING.showLogo),\n logoShape: pickEnum<LogoShape>(\n extras['logoShape'],\n ['square', 'rounded', 'circle'],\n DEFAULT_BRANDING.logoShape,\n ),\n logoSize: pickEnum<LogoSize>(extras['logoSize'], ['sm', 'md', 'lg'], DEFAULT_BRANDING.logoSize),\n\n primary: s(source.theme) || DEFAULT_BRANDING.primary,\n background: s(source.background_colour) || DEFAULT_BRANDING.background,\n surface: s(extras['surface']) || DEFAULT_BRANDING.surface,\n text: s(extras['text']) || DEFAULT_BRANDING.text,\n heading: s(extras['heading']) || s(extras['text']) || DEFAULT_BRANDING.heading,\n muted: s(extras['muted']) || DEFAULT_BRANDING.muted,\n border: s(extras['border']) || DEFAULT_BRANDING.border,\n accentText: s(extras['accentText']) || s(source.theme) || DEFAULT_BRANDING.accentText,\n buttonBackground:\n s(source.payment_button_colour) || s(source.theme) || DEFAULT_BRANDING.buttonBackground,\n buttonText: s(source.payment_button_text_colour) || DEFAULT_BRANDING.buttonText,\n\n fontFamily: pickEnum<FontFamily>(\n extras['fontFamily'],\n ALL_FONT_FAMILIES,\n DEFAULT_BRANDING.fontFamily,\n ),\n headingWeight: pickEnum<FontWeight>(\n extras['headingWeight'],\n ['regular', 'medium', 'semibold', 'bold'],\n DEFAULT_BRANDING.headingWeight,\n ),\n\n radiusSurface: pickEnum<NonPillRadius>(\n extras['radiusSurface'],\n NON_PILL_RADII,\n DEFAULT_BRANDING.radiusSurface,\n ),\n radiusInput: pickEnum<NonPillRadius>(\n extras['radiusInput'],\n NON_PILL_RADII,\n DEFAULT_BRANDING.radiusInput,\n ),\n radiusButton: pickEnum<CornerRadius>(\n extras['radiusButton'],\n ALL_RADII,\n DEFAULT_BRANDING.radiusButton,\n ),\n radiusBadge: pickEnum<CornerRadius>(\n extras['radiusBadge'],\n ALL_RADII,\n DEFAULT_BRANDING.radiusBadge,\n ),\n surfaceStyle: pickEnum<SurfaceStyle>(\n extras['surfaceStyle'],\n ['flat', 'outlined', 'elevated'],\n DEFAULT_BRANDING.surfaceStyle,\n ),\n surfacePadding: pickEnum<SpacingScale>(\n extras['surfacePadding'],\n ['compact', 'comfortable', 'spacious'],\n DEFAULT_BRANDING.surfacePadding,\n ),\n verticalGap: pickEnum<SpacingScale>(\n extras['verticalGap'],\n ['compact', 'comfortable', 'spacious'],\n DEFAULT_BRANDING.verticalGap,\n ),\n inputSize: pickEnum<SizeScale>(\n extras['inputSize'],\n ['sm', 'md', 'lg'],\n DEFAULT_BRANDING.inputSize,\n ),\n buttonSize: pickEnum<SizeScale>(\n extras['buttonSize'],\n ['sm', 'md', 'lg'],\n DEFAULT_BRANDING.buttonSize,\n ),\n\n showSurcharge: parseBool(extras['showSurcharge'], DEFAULT_BRANDING.showSurcharge),\n surchargePosition: pickEnum<SurchargePosition>(\n extras['surchargePosition'],\n SURCHARGE_POSITIONS,\n DEFAULT_BRANDING.surchargePosition,\n ),\n nativeElementStacked: parseBool(\n extras['nativeElementStacked'],\n DEFAULT_BRANDING.nativeElementStacked,\n ),\n nativeElementPosition: pickEnum<NativeElementPosition>(\n extras['nativeElementPosition'],\n NATIVE_ELEMENT_POSITIONS,\n DEFAULT_BRANDING.nativeElementPosition,\n ),\n surchargeStyle: pickEnum<SurchargeStyle>(\n extras['surchargeStyle'],\n SURCHARGE_STYLES,\n DEFAULT_BRANDING.surchargeStyle,\n ),\n surchargeSize: pickEnum<SurchargeSize>(\n extras['surchargeSize'],\n SURCHARGE_SIZES,\n DEFAULT_BRANDING.surchargeSize,\n ),\n surchargeShape: pickEnum<SurchargeShape>(\n extras['surchargeShape'],\n SURCHARGE_SHAPES,\n DEFAULT_BRANDING.surchargeShape,\n ),\n surchargeBorderWidth: pickEnum<SurchargeBorderWidth>(\n extras['surchargeBorderWidth'],\n SURCHARGE_BORDER_WIDTHS,\n DEFAULT_BRANDING.surchargeBorderWidth,\n ),\n surchargeBorderStyle: pickEnum<SurchargeBorderStyle>(\n extras['surchargeBorderStyle'],\n SURCHARGE_BORDER_STYLES,\n DEFAULT_BRANDING.surchargeBorderStyle,\n ),\n surchargeWeight: pickEnum<SurchargeWeight>(\n extras['surchargeWeight'],\n SURCHARGE_WEIGHTS,\n DEFAULT_BRANDING.surchargeWeight,\n ),\n surchargeSign: pickEnum<SurchargeSign>(\n extras['surchargeSign'],\n SURCHARGE_SIGNS,\n DEFAULT_BRANDING.surchargeSign,\n ),\n surchargeUppercase: parseBool(\n extras['surchargeUppercase'],\n DEFAULT_BRANDING.surchargeUppercase,\n ),\n surchargeLabel: pickEnum<SurchargeLabelMode>(\n extras['surchargeLabel'],\n SURCHARGE_LABEL_MODES,\n DEFAULT_BRANDING.surchargeLabel,\n ),\n surchargeFigure: pickEnum<SurchargeFigureMode>(\n extras['surchargeFigure'],\n SURCHARGE_FIGURE_MODES,\n DEFAULT_BRANDING.surchargeFigure,\n ),\n discountFigure: pickEnum<SurchargeFigureMode>(\n extras['discountFigure'],\n SURCHARGE_FIGURE_MODES,\n DEFAULT_BRANDING.discountFigure,\n ),\n surchargeWordTranslations: parseTranslations(extras['surchargeWordTranslations']),\n discountWordTranslations: parseTranslations(extras['discountWordTranslations']),\n headerTextTranslations: parseTranslations(extras['headerTextTranslations']),\n payButtonLabelTranslations: parseTranslations(extras['payButtonLabelTranslations']),\n cardTermsMessageTranslations: parseTranslations(extras['cardTermsMessageTranslations']),\n footerTextTranslations: parseTranslations(extras['footerTextTranslations']),\n surchargeColor: s(extras['surchargeColor']) || DEFAULT_BRANDING.surchargeColor,\n discountColor: s(extras['discountColor']) || DEFAULT_BRANDING.discountColor,\n\n layout: pickEnum<LayoutStyle>(extras['layout'], ['compact', 'split'], DEFAULT_BRANDING.layout),\n summaryPosition: pickEnum<SummaryPosition>(\n extras['summaryPosition'],\n ['left', 'right'],\n DEFAULT_BRANDING.summaryPosition,\n ),\n showOrderSummary: parseBool(extras['showOrderSummary'], DEFAULT_BRANDING.showOrderSummary),\n summaryGradient: parseBool(extras['summaryGradient'], DEFAULT_BRANDING.summaryGradient),\n showTotal: parseBool(extras['showTotal'], DEFAULT_BRANDING.showTotal),\n totalLabel: s(extras['totalLabel']) || DEFAULT_BRANDING.totalLabel,\n showCurrencyCode: parseBool(extras['showCurrencyCode'], DEFAULT_BRANDING.showCurrencyCode),\n showOrderItems: parseBool(extras['showOrderItems'], DEFAULT_BRANDING.showOrderItems),\n cancelLinkEnabled: parseBool(extras['cancelLinkEnabled'], DEFAULT_BRANDING.cancelLinkEnabled),\n cancelLinkPosition: pickEnum<'top' | 'bottom'>(\n extras['cancelLinkPosition'],\n ['top', 'bottom'],\n DEFAULT_BRANDING.cancelLinkPosition,\n ),\n cancelLinkStyle: pickEnum<'link' | 'button'>(\n extras['cancelLinkStyle'],\n ['link', 'button'],\n DEFAULT_BRANDING.cancelLinkStyle,\n ),\n\n trustBadges: trustRow.trustBadges,\n notices: trustRow.notices,\n customFields: decodedCustomFields ?? [],\n methodSectionOrder: decodeMethodSectionOrder(extras[METHOD_SECTION_ORDER_KEY]),\n methodSectionLabels: decodeMethodSectionLabels(extras[METHOD_SECTION_LABELS_KEY]),\n\n headerText: s(source.payment_form_header_text),\n payButtonLabel: s(source.payment_button_text),\n cardTermsMessage: s(source.custom_message_for_card_terms),\n footerText: s(extras['footerText']),\n supportEmail: s(extras['supportEmail']),\n\n paymentLayout: pickEnum<PaymentLayout>(\n source.sdk_layout,\n ['tabs', 'accordion', 'spaced_accordion'],\n DEFAULT_BRANDING.paymentLayout,\n ),\n labelStyle,\n showPoweredBy: source.branding_visibility !== false,\n\n // The two that can be empty use `pickEnumOrEmpty`, not `pickEnum`: a\n // value this build does not know has to decode to \"unset\" and defer, the\n // same as a key that was never written. Sending it to a concrete default\n // instead would make an older checkout override the connector account of\n // a merchant who picked a preset a newer dashboard offers.\n airwallexCardPreset: pickEnumOrEmpty<AirwallexCardPreset>(\n extras['airwallexCardPreset'],\n AIRWALLEX_CARD_PRESETS,\n ),\n airwallexHideCard: parseBool(extras['airwallexHideCard'], DEFAULT_BRANDING.airwallexHideCard),\n airwallexHideCardTitle: parseBool(\n extras['airwallexHideCardTitle'],\n DEFAULT_BRANDING.airwallexHideCardTitle,\n ),\n airwallexFieldChrome: pickEnum<AirwallexFieldChrome>(\n extras['airwallexFieldChrome'],\n AIRWALLEX_FIELD_CHROMES,\n DEFAULT_BRANDING.airwallexFieldChrome,\n ),\n airwallexLabelStyle: pickEnumOrEmpty<AirwallexLabelStyle>(\n extras['airwallexLabelStyle'],\n AIRWALLEX_LABEL_STYLES,\n ),\n airwallexFieldFontSize: pickEnum<AirwallexFieldFontSize>(\n extras['airwallexFieldFontSize'],\n AIRWALLEX_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.airwallexFieldFontSize,\n ),\n airwallexFieldWeight: pickEnum<AirwallexFieldWeight>(\n extras['airwallexFieldWeight'],\n AIRWALLEX_FIELD_WEIGHTS,\n DEFAULT_BRANDING.airwallexFieldWeight,\n ),\n airwallexFocusRing: pickEnum<AirwallexFocusRing>(\n extras['airwallexFocusRing'],\n AIRWALLEX_FOCUS_RINGS,\n DEFAULT_BRANDING.airwallexFocusRing,\n ),\n airwallexAutofill: pickEnum<AirwallexAutofillTreatment>(\n extras['airwallexAutofill'],\n AIRWALLEX_AUTOFILL_TREATMENTS,\n DEFAULT_BRANDING.airwallexAutofill,\n ),\n airwallexValidTint: parseBool(\n extras['airwallexValidTint'],\n DEFAULT_BRANDING.airwallexValidTint,\n ),\n airwallexNetworkMarks: parseBool(\n extras['airwallexNetworkMarks'],\n DEFAULT_BRANDING.airwallexNetworkMarks,\n ),\n\n stripeTheme: pickEnum<StripeTheme>(\n extras['stripeTheme'],\n STRIPE_THEMES,\n DEFAULT_BRANDING.stripeTheme,\n ),\n stripeInputs: pickEnum<StripeInputStyle>(\n extras['stripeInputs'],\n STRIPE_INPUT_STYLES,\n DEFAULT_BRANDING.stripeInputs,\n ),\n stripeLabels: pickEnum<StripeLabelPlacement>(\n extras['stripeLabels'],\n STRIPE_LABEL_PLACEMENTS,\n DEFAULT_BRANDING.stripeLabels,\n ),\n stripeSpacing: pickEnum<StripeSpacing>(\n extras['stripeSpacing'],\n STRIPE_SPACINGS,\n DEFAULT_BRANDING.stripeSpacing,\n ),\n stripeFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['stripeFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.stripeFieldFontSize,\n ),\n stripeFieldWeight: pickEnum<CardFieldWeight>(\n extras['stripeFieldWeight'],\n CARD_FIELD_WEIGHTS,\n DEFAULT_BRANDING.stripeFieldWeight,\n ),\n stripeFocusRing: pickEnum<CardFocusRing>(\n extras['stripeFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.stripeFocusRing,\n ),\n stripeDisableAnimations: parseBool(\n extras['stripeDisableAnimations'],\n DEFAULT_BRANDING.stripeDisableAnimations,\n ),\n paypalCardLayout: pickEnum<PaypalCardLayout>(\n extras['paypalCardLayout'],\n PAYPAL_CARD_LAYOUTS,\n DEFAULT_BRANDING.paypalCardLayout,\n ),\n paypalLabelStyle: pickEnum<PaypalLabelStyle>(\n extras['paypalLabelStyle'],\n PAYPAL_LABEL_STYLES,\n DEFAULT_BRANDING.paypalLabelStyle,\n ),\n paypalFieldChrome: pickEnum<CardFieldChrome>(\n extras['paypalFieldChrome'],\n CARD_FIELD_CHROMES,\n DEFAULT_BRANDING.paypalFieldChrome,\n ),\n mollieFieldChrome: pickEnum<CardFieldChrome>(\n extras['mollieFieldChrome'],\n CARD_FIELD_CHROMES,\n DEFAULT_BRANDING.mollieFieldChrome,\n ),\n paypalFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['paypalFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.paypalFieldFontSize,\n ),\n mollieFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['mollieFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.mollieFieldFontSize,\n ),\n paypalFieldWeight: pickEnum<CardFieldWeight>(\n extras['paypalFieldWeight'],\n CARD_FIELD_WEIGHTS,\n DEFAULT_BRANDING.paypalFieldWeight,\n ),\n mollieFieldWeight: pickEnum<CardFieldWeight>(\n extras['mollieFieldWeight'],\n CARD_FIELD_WEIGHTS,\n DEFAULT_BRANDING.mollieFieldWeight,\n ),\n paypalFocusRing: pickEnum<CardFocusRing>(\n extras['paypalFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.paypalFocusRing,\n ),\n mollieFocusRing: pickEnum<CardFocusRing>(\n extras['mollieFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.mollieFocusRing,\n ),\n micropaymentFieldChrome: pickEnum<CardFieldChrome>(\n extras['micropaymentFieldChrome'],\n CARD_FIELD_CHROMES,\n DEFAULT_BRANDING.micropaymentFieldChrome,\n ),\n micropaymentFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['micropaymentFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.micropaymentFieldFontSize,\n ),\n micropaymentFieldWeight: pickEnum<CardFieldWeight>(\n extras['micropaymentFieldWeight'],\n CARD_FIELD_WEIGHTS,\n DEFAULT_BRANDING.micropaymentFieldWeight,\n ),\n micropaymentFocusRing: pickEnum<CardFocusRing>(\n extras['micropaymentFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.micropaymentFocusRing,\n ),\n whopCardPreset: pickEnum<WhopCardPreset>(\n extras['whopCardPreset'],\n WHOP_CARD_PRESETS,\n DEFAULT_BRANDING.whopCardPreset,\n ),\n whopAccentColor: pickEnum<WhopAccentColor>(\n extras['whopAccentColor'],\n WHOP_ACCENT_COLORS,\n DEFAULT_BRANDING.whopAccentColor,\n ),\n whopGrayColor: pickEnum<WhopGrayColor>(\n extras['whopGrayColor'],\n WHOP_GRAY_COLORS,\n DEFAULT_BRANDING.whopGrayColor,\n ),\n whopBillingDetails: pickEnum<WhopBillingDetails>(\n extras['whopBillingDetails'],\n WHOP_BILLING_DETAILS,\n DEFAULT_BRANDING.whopBillingDetails,\n ),\n whopSeparated: parseBool(extras['whopSeparated'], DEFAULT_BRANDING.whopSeparated),\n whopEmailLabel: pickEnum<WhopEmailLabel>(\n extras['whopEmailLabel'],\n WHOP_EMAIL_LABELS,\n DEFAULT_BRANDING.whopEmailLabel,\n ),\n whopFieldChrome: pickEnum<CardFieldChrome>(\n extras['whopFieldChrome'],\n CARD_FIELD_CHROMES,\n DEFAULT_BRANDING.whopFieldChrome,\n ),\n whopFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['whopFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.whopFieldFontSize,\n ),\n whopFieldWeight: pickEnum<CardFieldWeight>(\n extras['whopFieldWeight'],\n CARD_FIELD_WEIGHTS,\n DEFAULT_BRANDING.whopFieldWeight,\n ),\n whopFocusRing: pickEnum<CardFocusRing>(\n extras['whopFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.whopFocusRing,\n ),\n whopRadius: pickEnum<WhopRadius>(extras['whopRadius'], WHOP_RADII, DEFAULT_BRANDING.whopRadius),\n whopShadow: pickEnum<WhopShadow>(\n extras['whopShadow'],\n WHOP_SHADOWS,\n DEFAULT_BRANDING.whopShadow,\n ),\n whopMethodIcons: parseBool(extras['whopMethodIcons'], DEFAULT_BRANDING.whopMethodIcons),\n whopSelection: pickEnum<WhopSelection>(\n extras['whopSelection'],\n WHOP_SELECTIONS,\n DEFAULT_BRANDING.whopSelection,\n ),\n paypalValidTint: parseBool(extras['paypalValidTint'], DEFAULT_BRANDING.paypalValidTint),\n // A look stored before e-Payouts had its own keys has none: the form keeps\n // the PayPal values it was drawn with until then.\n epayoutsCardLayout: pickEnum<PaypalCardLayout>(\n extras['epayoutsCardLayout'],\n PAYPAL_CARD_LAYOUTS,\n pickEnum<PaypalCardLayout>(\n extras['paypalCardLayout'],\n PAYPAL_CARD_LAYOUTS,\n DEFAULT_BRANDING.epayoutsCardLayout,\n ),\n ),\n epayoutsLabelStyle: pickEnum<PaypalLabelStyle>(\n extras['epayoutsLabelStyle'],\n PAYPAL_LABEL_STYLES,\n pickEnum<PaypalLabelStyle>(\n extras['paypalLabelStyle'],\n PAYPAL_LABEL_STYLES,\n DEFAULT_BRANDING.epayoutsLabelStyle,\n ),\n ),\n epayoutsFieldChrome: pickEnum<CardFieldChrome>(\n extras['epayoutsFieldChrome'],\n CARD_FIELD_CHROMES,\n pickEnum<CardFieldChrome>(\n extras['paypalFieldChrome'],\n CARD_FIELD_CHROMES,\n DEFAULT_BRANDING.epayoutsFieldChrome,\n ),\n ),\n epayoutsFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['epayoutsFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n pickEnum<CardFieldFontSize>(\n extras['paypalFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.epayoutsFieldFontSize,\n ),\n ),\n epayoutsFieldWeight: pickEnum<CardFieldWeight>(\n extras['epayoutsFieldWeight'],\n CARD_FIELD_WEIGHTS,\n pickEnum<CardFieldWeight>(\n extras['paypalFieldWeight'],\n CARD_FIELD_WEIGHTS,\n DEFAULT_BRANDING.epayoutsFieldWeight,\n ),\n ),\n epayoutsFocusRing: pickEnum<CardFocusRing>(\n extras['epayoutsFocusRing'],\n CARD_FOCUS_RINGS,\n pickEnum<CardFocusRing>(\n extras['paypalFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.epayoutsFocusRing,\n ),\n ),\n epayoutsValidTint: parseBool(\n extras['epayoutsValidTint'],\n parseBool(extras['paypalValidTint'], DEFAULT_BRANDING.epayoutsValidTint),\n ),\n nomupayFormStyle: pickEnum<NomupayFormStyle>(\n extras['nomupayFormStyle'],\n NOMUPAY_FORM_STYLES,\n DEFAULT_BRANDING.nomupayFormStyle,\n ),\n nomupayShowLabels: parseBool(extras['nomupayShowLabels'], DEFAULT_BRANDING.nomupayShowLabels),\n nomupayShowPlaceholders: parseBool(\n extras['nomupayShowPlaceholders'],\n DEFAULT_BRANDING.nomupayShowPlaceholders,\n ),\n nomupayShowCvvHint: parseBool(\n extras['nomupayShowCvvHint'],\n DEFAULT_BRANDING.nomupayShowCvvHint,\n ),\n nomupayFieldChrome: pickEnum<CardFieldChrome>(\n extras['nomupayFieldChrome'],\n CARD_FIELD_CHROMES,\n DEFAULT_BRANDING.nomupayFieldChrome,\n ),\n nomupayFieldFontSize: pickEnum<CardFieldFontSize>(\n extras['nomupayFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n DEFAULT_BRANDING.nomupayFieldFontSize,\n ),\n nomupayFocusRing: pickEnum<CardFocusRing>(\n extras['nomupayFocusRing'],\n CARD_FOCUS_RINGS,\n DEFAULT_BRANDING.nomupayFocusRing,\n ),\n nomupayApplePayButtonStyle: pickEnum<ApplePayButtonStyle>(\n extras['nomupayApplePayButtonStyle'],\n APPLE_PAY_BUTTON_STYLES,\n DEFAULT_BRANDING.nomupayApplePayButtonStyle,\n ),\n nomupayApplePayButtonType: pickEnum<ApplePayButtonType>(\n extras['nomupayApplePayButtonType'],\n APPLE_PAY_BUTTON_TYPES,\n DEFAULT_BRANDING.nomupayApplePayButtonType,\n ),\n nomupayGooglePayButtonColor: pickEnum<GooglePayButtonColor>(\n extras['nomupayGooglePayButtonColor'],\n GOOGLE_PAY_BUTTON_COLORS,\n DEFAULT_BRANDING.nomupayGooglePayButtonColor,\n ),\n nomupayGooglePayButtonType: pickEnum<GooglePayButtonType>(\n extras['nomupayGooglePayButtonType'],\n GOOGLE_PAY_BUTTON_TYPES,\n DEFAULT_BRANDING.nomupayGooglePayButtonType,\n ),\n\n customCss: s(extras['customCss']),\n\n ...decodeEnigmaCardForm(extras),\n };\n}\n\n// Encoded request shape — the union of fields the encoder fills. Compatible\n// with `BusinessPaymentLinkConfig` / `PaymentLinkConfigRequest` via\n// structural typing on the consumer side.\nexport interface EncodedBranding {\n theme: string;\n logo: string | null;\n seller_name: string | null;\n sdk_layout: PaymentLayout;\n payment_button_text: string | null;\n payment_button_colour: string;\n payment_button_text_colour: string;\n background_colour: string;\n payment_form_header_text: string | null;\n payment_form_label_type: 'above' | 'never';\n custom_message_for_card_terms: string | null;\n sdk_ui_rules: Record<string, Record<string, string>>;\n branding_visibility: boolean;\n}\n\n// Encode a CheckoutBranding into the API request shape. `base` is the\n// existing config (if any) -- preserves bag entries the form doesn't surface\n// (other sdk_ui_rules groups, business_specific_configs, etc.) by spreading\n// it through.\n//\n// `TBase` is constrained to `object | null | undefined` (not\n// `Record<string, unknown>`) so consumers can pass interface-typed values\n// directly. TS interfaces don't get an implicit string index signature, so\n// they don't structurally satisfy `Record<string, unknown>` even when their\n// property values would all unify to `unknown` — `object` admits them\n// without forcing a cast at every call site. We only spread the value, so\n// no index-signature semantics are needed at runtime.\nexport function encodeBranding<TBase extends object | null | undefined>(\n branding: CheckoutBranding,\n base?: TBase,\n): EncodedBranding & (TBase extends object ? TBase : Record<string, never>) {\n const trim = (v: string): string | null => {\n const t = v.trim();\n return t.length > 0 ? t : null;\n };\n\n // We only read one property off `base` and structural typing on `object`\n // doesn't permit index access, so go through `unknown` here.\n const existingRules = ((base as unknown as Record<string, unknown> | undefined)?.[\n 'sdk_ui_rules'\n ] ?? {}) as Record<string, Record<string, string>>;\n const extras: Record<string, string> = {\n surface: branding.surface,\n text: branding.text,\n heading: branding.heading,\n muted: branding.muted,\n border: branding.border,\n accentText: branding.accentText,\n fontFamily: branding.fontFamily,\n headingWeight: branding.headingWeight,\n radiusSurface: branding.radiusSurface,\n radiusInput: branding.radiusInput,\n radiusButton: branding.radiusButton,\n radiusBadge: branding.radiusBadge,\n surfaceStyle: branding.surfaceStyle,\n surfacePadding: branding.surfacePadding,\n verticalGap: branding.verticalGap,\n inputSize: branding.inputSize,\n buttonSize: branding.buttonSize,\n showSurcharge: String(branding.showSurcharge),\n surchargePosition: branding.surchargePosition,\n nativeElementPosition: branding.nativeElementPosition,\n nativeElementStacked: String(branding.nativeElementStacked),\n surchargeStyle: branding.surchargeStyle,\n surchargeSize: branding.surchargeSize,\n surchargeShape: branding.surchargeShape,\n surchargeBorderWidth: branding.surchargeBorderWidth,\n surchargeBorderStyle: branding.surchargeBorderStyle,\n surchargeWeight: branding.surchargeWeight,\n surchargeSign: branding.surchargeSign,\n surchargeUppercase: String(branding.surchargeUppercase),\n surchargeLabel: branding.surchargeLabel,\n surchargeFigure: branding.surchargeFigure,\n discountFigure: branding.discountFigure,\n surchargeColor: branding.surchargeColor,\n discountColor: branding.discountColor,\n layout: branding.layout,\n summaryPosition: branding.summaryPosition,\n showOrderSummary: String(branding.showOrderSummary),\n summaryGradient: String(branding.summaryGradient),\n showTotal: String(branding.showTotal),\n totalLabel: branding.totalLabel,\n showCurrencyCode: String(branding.showCurrencyCode),\n showOrderItems: String(branding.showOrderItems),\n cancelLinkEnabled: String(branding.cancelLinkEnabled),\n cancelLinkPosition: branding.cancelLinkPosition,\n cancelLinkStyle: branding.cancelLinkStyle,\n showLogo: String(branding.showLogo),\n logoShape: branding.logoShape,\n logoSize: branding.logoSize,\n labelStyle: branding.labelStyle,\n // Written unconditionally, empty string included. The encoder REPLACES\n // `sdk_ui_rules.branding` wholesale, so a key it skips is a key it\n // deletes — and here the empty string is a real value (\"no choice made\"),\n // not an absence. Omitting it would be indistinguishable from omitting it\n // by accident, which is how `summaryOrder` was lost.\n airwallexCardPreset: branding.airwallexCardPreset,\n airwallexHideCard: String(branding.airwallexHideCard),\n airwallexHideCardTitle: String(branding.airwallexHideCardTitle),\n airwallexFieldChrome: branding.airwallexFieldChrome,\n airwallexLabelStyle: branding.airwallexLabelStyle,\n airwallexFieldFontSize: branding.airwallexFieldFontSize,\n airwallexFieldWeight: branding.airwallexFieldWeight,\n airwallexFocusRing: branding.airwallexFocusRing,\n airwallexAutofill: branding.airwallexAutofill,\n airwallexValidTint: String(branding.airwallexValidTint),\n airwallexNetworkMarks: String(branding.airwallexNetworkMarks),\n stripeTheme: branding.stripeTheme,\n stripeInputs: branding.stripeInputs,\n stripeLabels: branding.stripeLabels,\n stripeSpacing: branding.stripeSpacing,\n stripeFieldFontSize: branding.stripeFieldFontSize,\n stripeFieldWeight: branding.stripeFieldWeight,\n stripeFocusRing: branding.stripeFocusRing,\n stripeDisableAnimations: String(branding.stripeDisableAnimations),\n paypalCardLayout: branding.paypalCardLayout,\n paypalLabelStyle: branding.paypalLabelStyle,\n paypalFieldChrome: branding.paypalFieldChrome,\n mollieFieldChrome: branding.mollieFieldChrome,\n paypalFieldFontSize: branding.paypalFieldFontSize,\n mollieFieldFontSize: branding.mollieFieldFontSize,\n paypalFieldWeight: branding.paypalFieldWeight,\n mollieFieldWeight: branding.mollieFieldWeight,\n paypalFocusRing: branding.paypalFocusRing,\n mollieFocusRing: branding.mollieFocusRing,\n micropaymentFieldChrome: branding.micropaymentFieldChrome,\n micropaymentFieldFontSize: branding.micropaymentFieldFontSize,\n micropaymentFieldWeight: branding.micropaymentFieldWeight,\n micropaymentFocusRing: branding.micropaymentFocusRing,\n whopCardPreset: branding.whopCardPreset,\n whopAccentColor: branding.whopAccentColor,\n whopGrayColor: branding.whopGrayColor,\n whopBillingDetails: branding.whopBillingDetails,\n whopSeparated: String(branding.whopSeparated),\n whopEmailLabel: branding.whopEmailLabel,\n whopFieldChrome: branding.whopFieldChrome,\n whopFieldFontSize: branding.whopFieldFontSize,\n whopFieldWeight: branding.whopFieldWeight,\n whopFocusRing: branding.whopFocusRing,\n whopRadius: branding.whopRadius,\n whopShadow: branding.whopShadow,\n whopMethodIcons: String(branding.whopMethodIcons),\n whopSelection: branding.whopSelection,\n paypalValidTint: String(branding.paypalValidTint),\n epayoutsCardLayout: branding.epayoutsCardLayout,\n epayoutsLabelStyle: branding.epayoutsLabelStyle,\n epayoutsFieldChrome: branding.epayoutsFieldChrome,\n epayoutsFieldFontSize: branding.epayoutsFieldFontSize,\n epayoutsFieldWeight: branding.epayoutsFieldWeight,\n epayoutsFocusRing: branding.epayoutsFocusRing,\n epayoutsValidTint: String(branding.epayoutsValidTint),\n nomupayFormStyle: branding.nomupayFormStyle,\n nomupayShowLabels: String(branding.nomupayShowLabels),\n nomupayShowPlaceholders: String(branding.nomupayShowPlaceholders),\n nomupayShowCvvHint: String(branding.nomupayShowCvvHint),\n nomupayFieldChrome: branding.nomupayFieldChrome,\n nomupayFieldFontSize: branding.nomupayFieldFontSize,\n nomupayFocusRing: branding.nomupayFocusRing,\n nomupayApplePayButtonStyle: branding.nomupayApplePayButtonStyle,\n nomupayApplePayButtonType: branding.nomupayApplePayButtonType,\n nomupayGooglePayButtonColor: branding.nomupayGooglePayButtonColor,\n nomupayGooglePayButtonType: branding.nomupayGooglePayButtonType,\n // Always written, `[]` included — its presence is what stops a later\n // decode from migrating the shop again (`resolveNoticesAndBadges`).\n notices: encodeNotices(branding.notices),\n [METHOD_SECTION_ORDER_KEY]: encodeMethodSectionOrder(branding.methodSectionOrder),\n };\n // Badges only when there are some. Not for tidiness: this group\n // is rebuilt on every save, so a writer that predates notices drops them.\n // Such a writer decodes a missing `trustBadges` to its stock pair and saves\n // that, which decodes here to the default notices again. Had `[]` been\n // written, it would save `[]` back, and `[]` without notices reads as \"the\n // merchant removed the trust row\", so the checkout would show nothing.\n if (branding.trustBadges.length > 0) {\n extras['trustBadges'] = encodeBadges(branding.trustBadges);\n }\n // Written only when there is one, so an untouched profile's bag is unchanged.\n const sectionLabels = encodeMethodSectionLabels(branding.methodSectionLabels);\n if (sectionLabels) extras[METHOD_SECTION_LABELS_KEY] = sectionLabels;\n // Omit the key entirely when there are no fields — decode treats a\n // missing entry the same as an empty list, and the bag stays clean for\n // merchants who never touch the feature.\n if (branding.customFields.length > 0) {\n extras['customFields'] = encodeCustomFields(branding.customFields);\n }\n // Localized copy, each written only when the merchant actually set one, so\n // an untouched profile's bag is unchanged by this feature existing.\n for (const key of [\n 'surchargeWordTranslations',\n 'discountWordTranslations',\n 'headerTextTranslations',\n 'payButtonLabelTranslations',\n 'cardTermsMessageTranslations',\n 'footerTextTranslations',\n ] as const) {\n const encoded = encodeTranslations(branding[key]);\n if (encoded) extras[key] = encoded;\n }\n const tagline = trim(branding.tagline);\n if (tagline) extras['tagline'] = tagline;\n const footer = trim(branding.footerText);\n if (footer) extras['footerText'] = footer;\n const support = trim(branding.supportEmail);\n if (support) extras['supportEmail'] = support;\n // Persist raw — sanitization runs at render time so we keep the merchant's\n // input as-typed (preserves comments, whitespace) and let the checkout\n // strip dangerous tokens consistently across all readers.\n const css = trim(branding.customCss);\n if (css) extras['customCss'] = css;\n Object.assign(extras, encodeEnigmaCardForm(branding));\n\n const nextRules: Record<string, Record<string, string>> = {\n ...existingRules,\n [BRANDING_GROUP_KEY]: extras,\n };\n\n // Map `hidden` back to the legacy `never` token the API's label type\n // enum understands. `floating` no longer exists.\n const legacyLabel: 'above' | 'never' = branding.labelStyle === 'hidden' ? 'never' : 'above';\n\n const flatFields: EncodedBranding = {\n theme: branding.primary,\n logo: trim(branding.logoUrl),\n seller_name: trim(branding.displayName),\n sdk_layout: branding.paymentLayout,\n payment_button_text: trim(branding.payButtonLabel),\n payment_button_colour: branding.buttonBackground,\n payment_button_text_colour: branding.buttonText,\n background_colour: branding.background,\n payment_form_header_text: trim(branding.headerText),\n payment_form_label_type: legacyLabel,\n custom_message_for_card_terms: trim(branding.cardTermsMessage),\n sdk_ui_rules: nextRules,\n branding_visibility: branding.showPoweredBy,\n };\n\n // Spread `base` first to preserve fields the encoder doesn't surface\n // (show_card_terms, show_card_form_by_default, hide_card_nickname_field,\n // enable_button_only_on_form_ready, skip_status_screen,\n // transaction_details, background_image, details_layout,\n // custom_message_for_payment_method_types, payment_link_ui_rules,\n // color_icon_card_cvc_error, is_setup_mandate_flow,\n // enabled_saved_payment_method, display_sdk_only,\n // business_specific_configs, domain_name, allowed_domains).\n return {\n ...base,\n ...flatFields,\n } as EncodedBranding & (TBase extends object ? TBase : Record<string, never>);\n}\n\n// --- Import / Export envelope ------------------------------------------\n\n// Versioned envelope used by the merchant dashboard's \"Import /\n// Export\" buttons. Bumping `version` is informational; the importer is\n// graceful and accepts any version (or no envelope at all).\nexport const BRANDING_EXPORT_FORMAT = 'delopay-checkout-branding';\nexport const BRANDING_EXPORT_VERSION = 1;\n\nexport interface BrandingExport {\n format: typeof BRANDING_EXPORT_FORMAT;\n version: number;\n exported_at: string;\n branding: CheckoutBranding;\n}\n\nexport function buildBrandingExport(branding: CheckoutBranding): BrandingExport {\n return {\n format: BRANDING_EXPORT_FORMAT,\n version: BRANDING_EXPORT_VERSION,\n exported_at: new Date().toISOString(),\n branding: cloneBranding(branding),\n };\n}\n\n// Resolve arbitrary JSON into a fully-typed CheckoutBranding. Designed to\n// never throw — every field is independently validated against its type\n// and silently falls back to the light-mode default if missing or\n// malformed:\n// - extra fields the form doesn't know about are ignored,\n// - missing fields inherit defaults,\n// - hex colors that fail the regex stay at the default,\n// - enums outside the allowed set fall back,\n// - a payload with no recognizable shape produces DEFAULT_BRANDING.\n//\n// Accepts either a bare CheckoutBranding object or an envelope produced by\n// `buildBrandingExport()`. The caller (the import handler) only needs to\n// catch JSON.parse errors; everything past that point is total.\nexport function parseImportedBranding(raw: unknown): CheckoutBranding {\n // Unwrap the envelope if present. Don't gate on version — bumping it is\n // informational; this function is the migration layer.\n const root: Record<string, unknown> | null =\n isObject(raw) && isObject(raw['branding'])\n ? (raw['branding'] as Record<string, unknown>)\n : isObject(raw)\n ? raw\n : null;\n\n if (!root) return cloneBranding(DEFAULT_BRANDING);\n\n const dflt = DEFAULT_BRANDING;\n const sStr = (v: unknown, fallback: string): string => (typeof v === 'string' ? v : fallback);\n const sHex = (v: unknown, fallback: string): string =>\n typeof v === 'string' && isHexColor(v) ? v : fallback;\n\n // The same rule as `decodeBranding`: an export made before notices existed\n // carries badges only, and is migrated exactly as a saved shop would be.\n const { trustBadges, notices } = resolveNoticesAndBadges(\n parseTrustBadgesLoose(root['trustBadges']),\n parseNoticesLoose(root['notices']),\n );\n const customFields = parseCustomFieldsLoose(root['customFields']) ?? [];\n\n // `floating` from older exports normalizes to `above`; see decodeBranding.\n const labelStyle: LabelStyle = (() => {\n const v = root['labelStyle'];\n if (v === 'above' || v === 'hidden') return v;\n return dflt.labelStyle;\n })();\n\n return {\n displayName: sStr(root['displayName'], dflt.displayName),\n logoUrl: sStr(root['logoUrl'], dflt.logoUrl),\n tagline: sStr(root['tagline'], dflt.tagline),\n showLogo: parseBool(root['showLogo'], dflt.showLogo),\n logoShape: pickEnum<LogoShape>(\n root['logoShape'],\n ['square', 'rounded', 'circle'],\n dflt.logoShape,\n ),\n logoSize: pickEnum<LogoSize>(root['logoSize'], ['sm', 'md', 'lg'], dflt.logoSize),\n\n primary: sHex(root['primary'], dflt.primary),\n background: sHex(root['background'], dflt.background),\n surface: sHex(root['surface'], dflt.surface),\n text: sHex(root['text'], dflt.text),\n heading: sHex(root['heading'], dflt.heading),\n muted: sHex(root['muted'], dflt.muted),\n border: sHex(root['border'], dflt.border),\n accentText: sHex(root['accentText'], dflt.accentText),\n buttonBackground: sHex(root['buttonBackground'], dflt.buttonBackground),\n buttonText: sHex(root['buttonText'], dflt.buttonText),\n\n fontFamily: pickEnum<FontFamily>(root['fontFamily'], ALL_FONT_FAMILIES, dflt.fontFamily),\n headingWeight: pickEnum<FontWeight>(\n root['headingWeight'],\n ['regular', 'medium', 'semibold', 'bold'],\n dflt.headingWeight,\n ),\n\n radiusSurface: pickEnum<NonPillRadius>(\n root['radiusSurface'],\n NON_PILL_RADII,\n dflt.radiusSurface,\n ),\n radiusInput: pickEnum<NonPillRadius>(root['radiusInput'], NON_PILL_RADII, dflt.radiusInput),\n radiusButton: pickEnum<CornerRadius>(root['radiusButton'], ALL_RADII, dflt.radiusButton),\n radiusBadge: pickEnum<CornerRadius>(root['radiusBadge'], ALL_RADII, dflt.radiusBadge),\n surfaceStyle: pickEnum<SurfaceStyle>(\n root['surfaceStyle'],\n ['flat', 'outlined', 'elevated'],\n dflt.surfaceStyle,\n ),\n surfacePadding: pickEnum<SpacingScale>(\n root['surfacePadding'],\n ['compact', 'comfortable', 'spacious'],\n dflt.surfacePadding,\n ),\n verticalGap: pickEnum<SpacingScale>(\n root['verticalGap'],\n ['compact', 'comfortable', 'spacious'],\n dflt.verticalGap,\n ),\n inputSize: pickEnum<SizeScale>(root['inputSize'], ['sm', 'md', 'lg'], dflt.inputSize),\n buttonSize: pickEnum<SizeScale>(root['buttonSize'], ['sm', 'md', 'lg'], dflt.buttonSize),\n\n showSurcharge: parseBool(root['showSurcharge'], dflt.showSurcharge),\n surchargePosition: pickEnum<SurchargePosition>(\n root['surchargePosition'],\n SURCHARGE_POSITIONS,\n dflt.surchargePosition,\n ),\n nativeElementStacked: parseBool(root['nativeElementStacked'], dflt.nativeElementStacked),\n nativeElementPosition: pickEnum<NativeElementPosition>(\n root['nativeElementPosition'],\n NATIVE_ELEMENT_POSITIONS,\n dflt.nativeElementPosition,\n ),\n surchargeStyle: pickEnum<SurchargeStyle>(\n root['surchargeStyle'],\n SURCHARGE_STYLES,\n dflt.surchargeStyle,\n ),\n surchargeSize: pickEnum<SurchargeSize>(\n root['surchargeSize'],\n SURCHARGE_SIZES,\n dflt.surchargeSize,\n ),\n surchargeShape: pickEnum<SurchargeShape>(\n root['surchargeShape'],\n SURCHARGE_SHAPES,\n dflt.surchargeShape,\n ),\n surchargeBorderWidth: pickEnum<SurchargeBorderWidth>(\n root['surchargeBorderWidth'],\n SURCHARGE_BORDER_WIDTHS,\n dflt.surchargeBorderWidth,\n ),\n surchargeBorderStyle: pickEnum<SurchargeBorderStyle>(\n root['surchargeBorderStyle'],\n SURCHARGE_BORDER_STYLES,\n dflt.surchargeBorderStyle,\n ),\n surchargeWeight: pickEnum<SurchargeWeight>(\n root['surchargeWeight'],\n SURCHARGE_WEIGHTS,\n dflt.surchargeWeight,\n ),\n surchargeSign: pickEnum<SurchargeSign>(\n root['surchargeSign'],\n SURCHARGE_SIGNS,\n dflt.surchargeSign,\n ),\n surchargeUppercase: parseBool(root['surchargeUppercase'], dflt.surchargeUppercase),\n surchargeLabel: pickEnum<SurchargeLabelMode>(\n root['surchargeLabel'],\n SURCHARGE_LABEL_MODES,\n dflt.surchargeLabel,\n ),\n surchargeFigure: pickEnum<SurchargeFigureMode>(\n root['surchargeFigure'],\n SURCHARGE_FIGURE_MODES,\n dflt.surchargeFigure,\n ),\n discountFigure: pickEnum<SurchargeFigureMode>(\n root['discountFigure'],\n SURCHARGE_FIGURE_MODES,\n dflt.discountFigure,\n ),\n surchargeWordTranslations: parseTranslations(root['surchargeWordTranslations']),\n discountWordTranslations: parseTranslations(root['discountWordTranslations']),\n headerTextTranslations: parseTranslations(root['headerTextTranslations']),\n payButtonLabelTranslations: parseTranslations(root['payButtonLabelTranslations']),\n cardTermsMessageTranslations: parseTranslations(root['cardTermsMessageTranslations']),\n footerTextTranslations: parseTranslations(root['footerTextTranslations']),\n surchargeColor: sHex(root['surchargeColor'], dflt.surchargeColor),\n discountColor: sHex(root['discountColor'], dflt.discountColor),\n\n layout: pickEnum<LayoutStyle>(root['layout'], ['compact', 'split'], dflt.layout),\n summaryPosition: pickEnum<SummaryPosition>(\n root['summaryPosition'],\n ['left', 'right'],\n dflt.summaryPosition,\n ),\n showOrderSummary: parseBool(root['showOrderSummary'], dflt.showOrderSummary),\n summaryGradient: parseBool(root['summaryGradient'], dflt.summaryGradient),\n showTotal: parseBool(root['showTotal'], dflt.showTotal),\n totalLabel: sStr(root['totalLabel'], dflt.totalLabel),\n showCurrencyCode: parseBool(root['showCurrencyCode'], dflt.showCurrencyCode),\n showOrderItems: parseBool(root['showOrderItems'], dflt.showOrderItems),\n\n trustBadges,\n notices,\n customFields,\n cancelLinkEnabled: parseBool(root['cancelLinkEnabled'], dflt.cancelLinkEnabled),\n cancelLinkPosition: pickEnum<'top' | 'bottom'>(\n root['cancelLinkPosition'],\n ['top', 'bottom'],\n dflt.cancelLinkPosition,\n ),\n cancelLinkStyle: pickEnum<'link' | 'button'>(\n root['cancelLinkStyle'],\n ['link', 'button'],\n dflt.cancelLinkStyle,\n ),\n // An export writes the decoded maps; a hand-written file may carry the\n // JSON strings the bag uses. Both are accepted, and neither is required.\n methodSectionOrder: parseSectionOrderLoose(root[METHOD_SECTION_ORDER_KEY]),\n methodSectionLabels: parseSectionLabelsLoose(root[METHOD_SECTION_LABELS_KEY]),\n\n headerText: sStr(root['headerText'], dflt.headerText),\n payButtonLabel: sStr(root['payButtonLabel'], dflt.payButtonLabel),\n cardTermsMessage: sStr(root['cardTermsMessage'], dflt.cardTermsMessage),\n footerText: sStr(root['footerText'], dflt.footerText),\n supportEmail: sStr(root['supportEmail'], dflt.supportEmail),\n\n paymentLayout: pickEnum<PaymentLayout>(\n root['paymentLayout'],\n ['tabs', 'accordion', 'spaced_accordion'],\n dflt.paymentLayout,\n ),\n labelStyle,\n showPoweredBy: parseBool(root['showPoweredBy'], dflt.showPoweredBy),\n\n // An imported profile that predates this section carries none of these\n // and lands on the defaults — which is to say on \"defer\", so importing an\n // old export into a shop does not take that shop's connector setting\n // away. The one field that would be dangerous to import loosely is the\n // hide switch, and `parseBool` only says true for a literal `true`.\n airwallexCardPreset: pickEnumOrEmpty<AirwallexCardPreset>(\n root['airwallexCardPreset'],\n AIRWALLEX_CARD_PRESETS,\n ),\n airwallexHideCard: parseBool(root['airwallexHideCard'], dflt.airwallexHideCard),\n airwallexHideCardTitle: parseBool(root['airwallexHideCardTitle'], dflt.airwallexHideCardTitle),\n airwallexFieldChrome: pickEnum<AirwallexFieldChrome>(\n root['airwallexFieldChrome'],\n AIRWALLEX_FIELD_CHROMES,\n dflt.airwallexFieldChrome,\n ),\n airwallexLabelStyle: pickEnumOrEmpty<AirwallexLabelStyle>(\n root['airwallexLabelStyle'],\n AIRWALLEX_LABEL_STYLES,\n ),\n airwallexFieldFontSize: pickEnum<AirwallexFieldFontSize>(\n root['airwallexFieldFontSize'],\n AIRWALLEX_FIELD_FONT_SIZES,\n dflt.airwallexFieldFontSize,\n ),\n airwallexFieldWeight: pickEnum<AirwallexFieldWeight>(\n root['airwallexFieldWeight'],\n AIRWALLEX_FIELD_WEIGHTS,\n dflt.airwallexFieldWeight,\n ),\n airwallexFocusRing: pickEnum<AirwallexFocusRing>(\n root['airwallexFocusRing'],\n AIRWALLEX_FOCUS_RINGS,\n dflt.airwallexFocusRing,\n ),\n airwallexAutofill: pickEnum<AirwallexAutofillTreatment>(\n root['airwallexAutofill'],\n AIRWALLEX_AUTOFILL_TREATMENTS,\n dflt.airwallexAutofill,\n ),\n airwallexValidTint: parseBool(root['airwallexValidTint'], dflt.airwallexValidTint),\n airwallexNetworkMarks: parseBool(root['airwallexNetworkMarks'], dflt.airwallexNetworkMarks),\n\n stripeTheme: pickEnum<StripeTheme>(root['stripeTheme'], STRIPE_THEMES, dflt.stripeTheme),\n stripeInputs: pickEnum<StripeInputStyle>(\n root['stripeInputs'],\n STRIPE_INPUT_STYLES,\n dflt.stripeInputs,\n ),\n stripeLabels: pickEnum<StripeLabelPlacement>(\n root['stripeLabels'],\n STRIPE_LABEL_PLACEMENTS,\n dflt.stripeLabels,\n ),\n stripeSpacing: pickEnum<StripeSpacing>(\n root['stripeSpacing'],\n STRIPE_SPACINGS,\n dflt.stripeSpacing,\n ),\n stripeFieldFontSize: pickEnum<CardFieldFontSize>(\n root['stripeFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.stripeFieldFontSize,\n ),\n stripeFieldWeight: pickEnum<CardFieldWeight>(\n root['stripeFieldWeight'],\n CARD_FIELD_WEIGHTS,\n dflt.stripeFieldWeight,\n ),\n stripeFocusRing: pickEnum<CardFocusRing>(\n root['stripeFocusRing'],\n CARD_FOCUS_RINGS,\n dflt.stripeFocusRing,\n ),\n stripeDisableAnimations: parseBool(\n root['stripeDisableAnimations'],\n dflt.stripeDisableAnimations,\n ),\n paypalCardLayout: pickEnum<PaypalCardLayout>(\n root['paypalCardLayout'],\n PAYPAL_CARD_LAYOUTS,\n dflt.paypalCardLayout,\n ),\n paypalLabelStyle: pickEnum<PaypalLabelStyle>(\n root['paypalLabelStyle'],\n PAYPAL_LABEL_STYLES,\n dflt.paypalLabelStyle,\n ),\n paypalFieldChrome: pickEnum<CardFieldChrome>(\n root['paypalFieldChrome'],\n CARD_FIELD_CHROMES,\n dflt.paypalFieldChrome,\n ),\n mollieFieldChrome: pickEnum<CardFieldChrome>(\n root['mollieFieldChrome'],\n CARD_FIELD_CHROMES,\n dflt.mollieFieldChrome,\n ),\n paypalFieldFontSize: pickEnum<CardFieldFontSize>(\n root['paypalFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.paypalFieldFontSize,\n ),\n mollieFieldFontSize: pickEnum<CardFieldFontSize>(\n root['mollieFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.mollieFieldFontSize,\n ),\n paypalFieldWeight: pickEnum<CardFieldWeight>(\n root['paypalFieldWeight'],\n CARD_FIELD_WEIGHTS,\n dflt.paypalFieldWeight,\n ),\n mollieFieldWeight: pickEnum<CardFieldWeight>(\n root['mollieFieldWeight'],\n CARD_FIELD_WEIGHTS,\n dflt.mollieFieldWeight,\n ),\n paypalFocusRing: pickEnum<CardFocusRing>(\n root['paypalFocusRing'],\n CARD_FOCUS_RINGS,\n dflt.paypalFocusRing,\n ),\n mollieFocusRing: pickEnum<CardFocusRing>(\n root['mollieFocusRing'],\n CARD_FOCUS_RINGS,\n dflt.mollieFocusRing,\n ),\n micropaymentFieldChrome: pickEnum<CardFieldChrome>(\n root['micropaymentFieldChrome'],\n CARD_FIELD_CHROMES,\n dflt.micropaymentFieldChrome,\n ),\n micropaymentFieldFontSize: pickEnum<CardFieldFontSize>(\n root['micropaymentFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.micropaymentFieldFontSize,\n ),\n micropaymentFieldWeight: pickEnum<CardFieldWeight>(\n root['micropaymentFieldWeight'],\n CARD_FIELD_WEIGHTS,\n dflt.micropaymentFieldWeight,\n ),\n micropaymentFocusRing: pickEnum<CardFocusRing>(\n root['micropaymentFocusRing'],\n CARD_FOCUS_RINGS,\n dflt.micropaymentFocusRing,\n ),\n whopCardPreset: pickEnum<WhopCardPreset>(\n root['whopCardPreset'],\n WHOP_CARD_PRESETS,\n dflt.whopCardPreset,\n ),\n whopAccentColor: pickEnum<WhopAccentColor>(\n root['whopAccentColor'],\n WHOP_ACCENT_COLORS,\n dflt.whopAccentColor,\n ),\n whopGrayColor: pickEnum<WhopGrayColor>(\n root['whopGrayColor'],\n WHOP_GRAY_COLORS,\n dflt.whopGrayColor,\n ),\n whopBillingDetails: pickEnum<WhopBillingDetails>(\n root['whopBillingDetails'],\n WHOP_BILLING_DETAILS,\n dflt.whopBillingDetails,\n ),\n whopSeparated: parseBool(root['whopSeparated'], dflt.whopSeparated),\n whopEmailLabel: pickEnum<WhopEmailLabel>(\n root['whopEmailLabel'],\n WHOP_EMAIL_LABELS,\n dflt.whopEmailLabel,\n ),\n whopFieldChrome: pickEnum<CardFieldChrome>(\n root['whopFieldChrome'],\n CARD_FIELD_CHROMES,\n dflt.whopFieldChrome,\n ),\n whopFieldFontSize: pickEnum<CardFieldFontSize>(\n root['whopFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.whopFieldFontSize,\n ),\n whopFieldWeight: pickEnum<CardFieldWeight>(\n root['whopFieldWeight'],\n CARD_FIELD_WEIGHTS,\n dflt.whopFieldWeight,\n ),\n whopFocusRing: pickEnum<CardFocusRing>(\n root['whopFocusRing'],\n CARD_FOCUS_RINGS,\n dflt.whopFocusRing,\n ),\n whopRadius: pickEnum<WhopRadius>(root['whopRadius'], WHOP_RADII, dflt.whopRadius),\n whopShadow: pickEnum<WhopShadow>(root['whopShadow'], WHOP_SHADOWS, dflt.whopShadow),\n whopMethodIcons: parseBool(root['whopMethodIcons'], dflt.whopMethodIcons),\n whopSelection: pickEnum<WhopSelection>(\n root['whopSelection'],\n WHOP_SELECTIONS,\n dflt.whopSelection,\n ),\n paypalValidTint: parseBool(root['paypalValidTint'], dflt.paypalValidTint),\n // A look stored before e-Payouts had its own keys has none: the form keeps\n // the PayPal values it was drawn with until then.\n epayoutsCardLayout: pickEnum<PaypalCardLayout>(\n root['epayoutsCardLayout'],\n PAYPAL_CARD_LAYOUTS,\n pickEnum<PaypalCardLayout>(\n root['paypalCardLayout'],\n PAYPAL_CARD_LAYOUTS,\n dflt.epayoutsCardLayout,\n ),\n ),\n epayoutsLabelStyle: pickEnum<PaypalLabelStyle>(\n root['epayoutsLabelStyle'],\n PAYPAL_LABEL_STYLES,\n pickEnum<PaypalLabelStyle>(\n root['paypalLabelStyle'],\n PAYPAL_LABEL_STYLES,\n dflt.epayoutsLabelStyle,\n ),\n ),\n epayoutsFieldChrome: pickEnum<CardFieldChrome>(\n root['epayoutsFieldChrome'],\n CARD_FIELD_CHROMES,\n pickEnum<CardFieldChrome>(\n root['paypalFieldChrome'],\n CARD_FIELD_CHROMES,\n dflt.epayoutsFieldChrome,\n ),\n ),\n epayoutsFieldFontSize: pickEnum<CardFieldFontSize>(\n root['epayoutsFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n pickEnum<CardFieldFontSize>(\n root['paypalFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.epayoutsFieldFontSize,\n ),\n ),\n epayoutsFieldWeight: pickEnum<CardFieldWeight>(\n root['epayoutsFieldWeight'],\n CARD_FIELD_WEIGHTS,\n pickEnum<CardFieldWeight>(\n root['paypalFieldWeight'],\n CARD_FIELD_WEIGHTS,\n dflt.epayoutsFieldWeight,\n ),\n ),\n epayoutsFocusRing: pickEnum<CardFocusRing>(\n root['epayoutsFocusRing'],\n CARD_FOCUS_RINGS,\n pickEnum<CardFocusRing>(root['paypalFocusRing'], CARD_FOCUS_RINGS, dflt.epayoutsFocusRing),\n ),\n epayoutsValidTint: parseBool(\n root['epayoutsValidTint'],\n parseBool(root['paypalValidTint'], dflt.epayoutsValidTint),\n ),\n nomupayFormStyle: pickEnum<NomupayFormStyle>(\n root['nomupayFormStyle'],\n NOMUPAY_FORM_STYLES,\n dflt.nomupayFormStyle,\n ),\n nomupayShowLabels: parseBool(root['nomupayShowLabels'], dflt.nomupayShowLabels),\n nomupayShowPlaceholders: parseBool(\n root['nomupayShowPlaceholders'],\n dflt.nomupayShowPlaceholders,\n ),\n nomupayShowCvvHint: parseBool(root['nomupayShowCvvHint'], dflt.nomupayShowCvvHint),\n nomupayFieldChrome: pickEnum<CardFieldChrome>(\n root['nomupayFieldChrome'],\n CARD_FIELD_CHROMES,\n dflt.nomupayFieldChrome,\n ),\n nomupayFieldFontSize: pickEnum<CardFieldFontSize>(\n root['nomupayFieldFontSize'],\n CARD_FIELD_FONT_SIZES,\n dflt.nomupayFieldFontSize,\n ),\n nomupayFocusRing: pickEnum<CardFocusRing>(\n root['nomupayFocusRing'],\n CARD_FOCUS_RINGS,\n dflt.nomupayFocusRing,\n ),\n nomupayApplePayButtonStyle: pickEnum<ApplePayButtonStyle>(\n root['nomupayApplePayButtonStyle'],\n APPLE_PAY_BUTTON_STYLES,\n dflt.nomupayApplePayButtonStyle,\n ),\n nomupayApplePayButtonType: pickEnum<ApplePayButtonType>(\n root['nomupayApplePayButtonType'],\n APPLE_PAY_BUTTON_TYPES,\n dflt.nomupayApplePayButtonType,\n ),\n nomupayGooglePayButtonColor: pickEnum<GooglePayButtonColor>(\n root['nomupayGooglePayButtonColor'],\n GOOGLE_PAY_BUTTON_COLORS,\n dflt.nomupayGooglePayButtonColor,\n ),\n nomupayGooglePayButtonType: pickEnum<GooglePayButtonType>(\n root['nomupayGooglePayButtonType'],\n GOOGLE_PAY_BUTTON_TYPES,\n dflt.nomupayGooglePayButtonType,\n ),\n\n customCss: sStr(root['customCss'], dflt.customCss).slice(0, CUSTOM_CSS_MAX_LENGTH),\n ...decodeEnigmaCardForm(root),\n };\n}\n\nfunction isObject(v: unknown): v is Record<string, unknown> {\n return typeof v === 'object' && v !== null && !Array.isArray(v);\n}\n\n// Loose trust-badge parser used by the importer. Unlike `decodeBadges`\n// (which reads the JSON-stringified API bag), this accepts an array of\n// objects directly. Returns null when the input isn't an array — the\n// caller falls back to the default badge set; an explicit empty array is\n// honored.\nfunction parseTrustBadgesLoose(raw: unknown): TrustBadge[] | null {\n if (!Array.isArray(raw)) return null;\n return raw\n .filter(isObject)\n .map((b, i) => ({\n id: typeof b['id'] === 'string' && b['id'] ? (b['id'] as string) : `badge-${i}`,\n label: typeof b['label'] === 'string' ? (b['label'] as string) : '',\n textColor:\n typeof b['textColor'] === 'string' && isHexColor(b['textColor'] as string)\n ? (b['textColor'] as string)\n : '#0f172a',\n backgroundColor:\n typeof b['backgroundColor'] === 'string' && isHexColor(b['backgroundColor'] as string)\n ? (b['backgroundColor'] as string)\n : '#f1f5f9',\n borderColor:\n typeof b['borderColor'] === 'string' && isHexColor(b['borderColor'] as string)\n ? (b['borderColor'] as string)\n : null,\n }))\n .filter((b) => b.label.length > 0);\n}\n\n// --- DOM helpers --------------------------------------------------------\n\n// Write branding tokens onto a target element as CSS custom properties.\n// The buyer-facing checkout sets these on `<html>` so every component sees\n// the same set, including Stripe Elements (indirectly via\n// appearance.variables). The merchant dashboard's preview component\n// uses an analogous `--p-*` set with `var(--dp-*, fallback)` indirection so\n// a custom-CSS rule like `:root{--dp-primary:red}` overrides the preview\n// without re-typing the whole brand.\nexport function applyBrandingVariables(el: HTMLElement, b: CheckoutBranding): void {\n const set = (k: string, v: string) => {\n el.style.setProperty(k, v);\n };\n\n set('--dp-primary', b.primary);\n set('--dp-bg', b.background);\n set('--dp-surface', b.surface);\n set('--dp-text', b.text);\n set('--dp-heading', b.heading);\n set('--dp-muted', b.muted);\n set('--dp-border', b.border);\n set('--dp-accent-text', b.accentText);\n set('--dp-btn-bg', b.buttonBackground);\n set('--dp-btn-fg', b.buttonText);\n\n set('--dp-radius-surface', radiusValue(b.radiusSurface));\n set('--dp-radius-input', radiusValue(b.radiusInput));\n set('--dp-radius-button', radiusValue(b.radiusButton));\n set('--dp-radius-badge', radiusValue(b.radiusBadge));\n\n set('--dp-font', fontStack(b.fontFamily));\n set('--dp-heading-weight', fontWeightValue(b.headingWeight));\n\n set('--dp-pad-surface', SURFACE_PAD[b.surfacePadding]);\n set('--dp-gap-vertical', VERTICAL_GAP[b.verticalGap]);\n set('--dp-input-pad', INPUT_PAD[b.inputSize]);\n set('--dp-button-pad', BUTTON_PAD[b.buttonSize]);\n\n // Published whatever `showSurcharge` says: the flag decides whether a figure\n // renders, not what colour it would be, and a stylesheet that reads the\n // variable must not get an empty string when the merchant has one configured.\n set('--dp-surcharge', b.surchargeColor);\n set('--dp-discount', b.discountColor);\n // What `solid` writes ON the fill. Computed here rather than in a stylesheet\n // because CSS cannot ask a colour how light it is, and picking one fixed ink\n // would make either a pale amber or a deep emerald unreadable.\n set('--dp-surcharge-ink', readableInkOn(b.surchargeColor));\n set('--dp-discount-ink', readableInkOn(b.discountColor));\n set('--dp-surcharge-size', SURCHARGE_FONT_SIZE[b.surchargeSize]);\n set('--dp-surcharge-pad', SURCHARGE_PAD[b.surchargeSize]);\n set('--dp-surcharge-radius', SURCHARGE_RADIUS[b.surchargeShape]);\n set('--dp-surcharge-weight', SURCHARGE_FONT_WEIGHT[b.surchargeWeight]);\n // `outline` draws nothing BUT its border, so `none` there would erase the\n // style rather than restyle it — it reads as `thin` instead.\n set(\n '--dp-surcharge-border-width',\n SURCHARGE_BORDER_WIDTH[\n b.surchargeStyle === 'outline' && b.surchargeBorderWidth === 'none'\n ? 'thin'\n : b.surchargeBorderWidth\n ],\n );\n set('--dp-surcharge-border-style', b.surchargeBorderStyle);\n\n set('--dp-shadow', shadowFor(b.surfaceStyle));\n set(\n '--dp-surface-border',\n b.surfaceStyle === 'outlined' ? `1px solid ${b.border}` : '1px solid transparent',\n );\n}\n\nexport function shadowFor(style: SurfaceStyle): string {\n switch (style) {\n case 'elevated':\n return '0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 32px -12px rgba(15, 23, 42, 0.08)';\n case 'outlined':\n case 'flat':\n default:\n return 'none';\n }\n}\n"]}
|