@delopay/sdk 0.18.3 → 0.19.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/index.cjs CHANGED
@@ -22,7 +22,14 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  Analytics: () => Analytics,
24
24
  AnalyticsDashboard: () => AnalyticsDashboard,
25
+ BRANDING_EXPORT_FORMAT: () => BRANDING_EXPORT_FORMAT,
26
+ BRANDING_EXPORT_VERSION: () => BRANDING_EXPORT_VERSION,
27
+ CUSTOM_CSS_MAX_LENGTH: () => CUSTOM_CSS_MAX_LENGTH,
25
28
  Cards: () => Cards,
29
+ DEFAULT_BADGES: () => DEFAULT_BADGES,
30
+ DEFAULT_BADGES_DARK: () => DEFAULT_BADGES_DARK,
31
+ DEFAULT_BRANDING: () => DEFAULT_BRANDING,
32
+ DEFAULT_BRANDING_DARK: () => DEFAULT_BRANDING_DARK,
26
33
  Delopay: () => Delopay,
27
34
  DelopayAuthenticationError: () => DelopayAuthenticationError,
28
35
  DelopayError: () => DelopayError,
@@ -32,7 +39,28 @@ __export(index_exports, {
32
39
  Forex: () => Forex,
33
40
  Regions: () => Regions,
34
41
  Subscriptions: () => Subscriptions,
35
- Webhooks: () => Webhooks
42
+ Webhooks: () => Webhooks,
43
+ applyBrandingVariables: () => applyBrandingVariables,
44
+ buildBrandingExport: () => buildBrandingExport,
45
+ buttonPadValue: () => buttonPadValue,
46
+ cloneBranding: () => cloneBranding,
47
+ decodeBadges: () => decodeBadges,
48
+ decodeBranding: () => decodeBranding,
49
+ defaultBranding: () => defaultBranding,
50
+ encodeBadges: () => encodeBadges,
51
+ encodeBranding: () => encodeBranding,
52
+ fontStack: () => fontStack,
53
+ fontWeightValue: () => fontWeightValue,
54
+ inputPadValue: () => inputPadValue,
55
+ isDarkSurface: () => isDarkSurface,
56
+ isHexColor: () => isHexColor,
57
+ logoDimensions: () => logoDimensions,
58
+ parseImportedBranding: () => parseImportedBranding,
59
+ radiusValue: () => radiusValue,
60
+ sanitizeCustomCss: () => sanitizeCustomCss,
61
+ shadowFor: () => shadowFor,
62
+ surfacePadValue: () => surfacePadValue,
63
+ verticalGapValue: () => verticalGapValue
36
64
  });
37
65
  module.exports = __toCommonJS(index_exports);
38
66
 
@@ -2922,11 +2950,653 @@ var Delopay = class {
2922
2950
  };
2923
2951
  /** Utility for verifying incoming webhook signatures (static, no instance needed). */
2924
2952
  Delopay.webhooks = Webhooks;
2953
+
2954
+ // src/branding.ts
2955
+ var FONT_STACKS = {
2956
+ inter: "'Inter Variable', 'Inter', system-ui, -apple-system, sans-serif",
2957
+ system: "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif",
2958
+ serif: "Georgia, 'Times New Roman', serif",
2959
+ mono: "ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",
2960
+ roboto: "'Roboto', system-ui, sans-serif",
2961
+ poppins: "'Poppins', system-ui, sans-serif",
2962
+ manrope: "'Manrope Variable', 'Manrope', system-ui, sans-serif",
2963
+ "dm-sans": "'DM Sans Variable', 'DM Sans', system-ui, sans-serif",
2964
+ "space-grotesk": "'Space Grotesk Variable', 'Space Grotesk', system-ui, sans-serif",
2965
+ "plex-sans": "'IBM Plex Sans', system-ui, sans-serif",
2966
+ "work-sans": "'Work Sans Variable', 'Work Sans', system-ui, sans-serif",
2967
+ "open-sans": "'Open Sans Variable', 'Open Sans', system-ui, sans-serif",
2968
+ lora: "'Lora Variable', 'Lora', Georgia, serif",
2969
+ playfair: "'Playfair Display Variable', 'Playfair Display', Georgia, serif",
2970
+ "plex-mono": "'IBM Plex Mono', ui-monospace, monospace",
2971
+ "jetbrains-mono": "'JetBrains Mono Variable', 'JetBrains Mono', ui-monospace, monospace"
2972
+ };
2973
+ var RADIUS_PX = {
2974
+ square: "0px",
2975
+ small: "6px",
2976
+ medium: "12px",
2977
+ large: "20px",
2978
+ pill: "999px"
2979
+ };
2980
+ var FONT_WEIGHT_NUMERIC = {
2981
+ regular: "400",
2982
+ medium: "500",
2983
+ semibold: "600",
2984
+ bold: "700"
2985
+ };
2986
+ var SURFACE_PAD = {
2987
+ compact: "1rem",
2988
+ comfortable: "1.5rem",
2989
+ spacious: "2rem"
2990
+ };
2991
+ var VERTICAL_GAP = {
2992
+ compact: "0.75rem",
2993
+ comfortable: "1rem",
2994
+ spacious: "1.5rem"
2995
+ };
2996
+ var INPUT_PAD = {
2997
+ sm: "0.5rem 0.75rem",
2998
+ md: "0.625rem 0.75rem",
2999
+ lg: "0.875rem 0.875rem"
3000
+ };
3001
+ var BUTTON_PAD = {
3002
+ sm: "0.625rem 1rem",
3003
+ md: "0.875rem 1.25rem",
3004
+ lg: "1.125rem 1.5rem"
3005
+ };
3006
+ function fontStack(family) {
3007
+ return FONT_STACKS[family] ?? FONT_STACKS.inter;
3008
+ }
3009
+ function radiusValue(radius) {
3010
+ return RADIUS_PX[radius] ?? RADIUS_PX.medium;
3011
+ }
3012
+ function fontWeightValue(weight) {
3013
+ return FONT_WEIGHT_NUMERIC[weight] ?? "600";
3014
+ }
3015
+ function surfacePadValue(scale) {
3016
+ return SURFACE_PAD[scale] ?? SURFACE_PAD.comfortable;
3017
+ }
3018
+ function verticalGapValue(scale) {
3019
+ return VERTICAL_GAP[scale] ?? VERTICAL_GAP.comfortable;
3020
+ }
3021
+ function inputPadValue(size) {
3022
+ return INPUT_PAD[size] ?? INPUT_PAD.md;
3023
+ }
3024
+ function buttonPadValue(size) {
3025
+ return BUTTON_PAD[size] ?? BUTTON_PAD.md;
3026
+ }
3027
+ function logoDimensions(size) {
3028
+ switch (size) {
3029
+ case "sm":
3030
+ return { px: 36, radius: 8 };
3031
+ case "lg":
3032
+ return { px: 64, radius: 16 };
3033
+ case "md":
3034
+ default:
3035
+ return { px: 48, radius: 12 };
3036
+ }
3037
+ }
3038
+ var HEX_RE = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/;
3039
+ function isHexColor(value) {
3040
+ return HEX_RE.test(value.trim());
3041
+ }
3042
+ function isDarkSurface(color) {
3043
+ const m = color.replace("#", "").trim();
3044
+ if (m.length !== 3 && m.length !== 6) return false;
3045
+ const full = m.length === 3 ? m.split("").map((c) => c + c).join("") : m;
3046
+ const r = parseInt(full.slice(0, 2), 16);
3047
+ const g = parseInt(full.slice(2, 4), 16);
3048
+ const b = parseInt(full.slice(4, 6), 16);
3049
+ if ([r, g, b].some(Number.isNaN)) return false;
3050
+ const luma = (r * 299 + g * 587 + b * 114) / 1e3;
3051
+ return luma < 128;
3052
+ }
3053
+ var LIGHT_PALETTE = {
3054
+ primary: "#1E4FEB",
3055
+ background: "#f8fafc",
3056
+ surface: "#ffffff",
3057
+ text: "#1e293b",
3058
+ heading: "#0A1130",
3059
+ muted: "#64748b",
3060
+ border: "#e2e8f0",
3061
+ accentText: "#1E4FEB",
3062
+ buttonBackground: "#0A1130",
3063
+ buttonText: "#ffffff"
3064
+ };
3065
+ var DEFAULT_BADGES = [
3066
+ {
3067
+ id: "secure",
3068
+ label: "Secure",
3069
+ textColor: "#047857",
3070
+ backgroundColor: "#ecfdf5",
3071
+ borderColor: "#a7f3d0"
3072
+ },
3073
+ {
3074
+ id: "ssl",
3075
+ label: "256-bit SSL",
3076
+ textColor: "#1E4FEB",
3077
+ backgroundColor: "#eff6ff",
3078
+ borderColor: "#bfdbfe"
3079
+ }
3080
+ ];
3081
+ var DEFAULT_BADGES_DARK = [
3082
+ {
3083
+ id: "secure",
3084
+ label: "Secure",
3085
+ textColor: "#34d399",
3086
+ backgroundColor: "#064e3b",
3087
+ borderColor: "#065f46"
3088
+ },
3089
+ {
3090
+ id: "ssl",
3091
+ label: "256-bit SSL",
3092
+ textColor: "#60a5fa",
3093
+ backgroundColor: "#172554",
3094
+ borderColor: "#1e40af"
3095
+ }
3096
+ ];
3097
+ var DEFAULT_BRANDING_BASE = {
3098
+ displayName: "",
3099
+ logoUrl: "",
3100
+ tagline: "",
3101
+ // Logo + summary gradient OFF by default — an unconfigured DeloPay
3102
+ // checkout reads cleaner without a placeholder logo block, and the
3103
+ // gradient implies a primary tint the merchant hasn't yet picked.
3104
+ showLogo: false,
3105
+ logoShape: "rounded",
3106
+ logoSize: "md",
3107
+ fontFamily: "inter",
3108
+ headingWeight: "semibold",
3109
+ radiusSurface: "medium",
3110
+ radiusInput: "medium",
3111
+ radiusButton: "medium",
3112
+ radiusBadge: "pill",
3113
+ surfaceStyle: "elevated",
3114
+ surfacePadding: "comfortable",
3115
+ verticalGap: "comfortable",
3116
+ inputSize: "md",
3117
+ buttonSize: "md",
3118
+ layout: "split",
3119
+ summaryPosition: "left",
3120
+ showOrderSummary: true,
3121
+ summaryGradient: false,
3122
+ showTotal: true,
3123
+ totalLabel: "Total",
3124
+ showCurrencyCode: false,
3125
+ showOrderItems: true,
3126
+ headerText: "",
3127
+ payButtonLabel: "",
3128
+ cardTermsMessage: "",
3129
+ footerText: "",
3130
+ supportEmail: "",
3131
+ paymentLayout: "tabs",
3132
+ labelStyle: "above",
3133
+ showPoweredBy: true,
3134
+ customCss: ""
3135
+ };
3136
+ var DEFAULT_BRANDING = {
3137
+ ...DEFAULT_BRANDING_BASE,
3138
+ ...LIGHT_PALETTE,
3139
+ trustBadges: DEFAULT_BADGES.map((b) => ({ ...b }))
3140
+ };
3141
+ var DEFAULT_BRANDING_DARK = {
3142
+ ...DEFAULT_BRANDING_BASE,
3143
+ primary: "#1E4FEB",
3144
+ background: "#020617",
3145
+ surface: "#0f172a",
3146
+ text: "#e2e8f0",
3147
+ heading: "#f8fafc",
3148
+ muted: "#94a3b8",
3149
+ border: "#1e293b",
3150
+ accentText: "#60a5fa",
3151
+ buttonBackground: "#1E4FEB",
3152
+ buttonText: "#ffffff",
3153
+ surfaceStyle: "flat",
3154
+ trustBadges: DEFAULT_BADGES_DARK.map((b) => ({ ...b }))
3155
+ };
3156
+ function defaultBranding() {
3157
+ return cloneBranding(DEFAULT_BRANDING);
3158
+ }
3159
+ function cloneBranding(b) {
3160
+ return { ...b, trustBadges: b.trustBadges.map((badge) => ({ ...badge })) };
3161
+ }
3162
+ var CUSTOM_CSS_MAX_LENGTH = 5e4;
3163
+ function sanitizeCustomCss(raw) {
3164
+ if (typeof raw !== "string") return null;
3165
+ const trimmed = raw.trim();
3166
+ if (trimmed.length === 0) return null;
3167
+ if (trimmed.length > CUSTOM_CSS_MAX_LENGTH) return null;
3168
+ let out = trimmed;
3169
+ out = out.replace(/<\/style/gi, "<\\/style");
3170
+ out = out.replace(/@import\b[^;]*;?/gi, "");
3171
+ out = out.replace(/expression\s*\(/gi, "/* expression( */");
3172
+ out = out.replace(/(^|[^a-z-])behavior\s*:/gi, "$1/* behavior: */");
3173
+ out = out.replace(/-moz-binding\s*:/gi, "/* -moz-binding: */");
3174
+ out = out.replace(/url\s*\(\s*["']?\s*javascript:/gi, "url(invalid:");
3175
+ return out;
3176
+ }
3177
+ var BRANDING_GROUP_KEY = "branding";
3178
+ var ALL_FONT_FAMILIES = [
3179
+ "inter",
3180
+ "system",
3181
+ "serif",
3182
+ "mono",
3183
+ "roboto",
3184
+ "poppins",
3185
+ "manrope",
3186
+ "dm-sans",
3187
+ "space-grotesk",
3188
+ "plex-sans",
3189
+ "work-sans",
3190
+ "open-sans",
3191
+ "lora",
3192
+ "playfair",
3193
+ "plex-mono",
3194
+ "jetbrains-mono"
3195
+ ];
3196
+ var ALL_RADII = ["square", "small", "medium", "large", "pill"];
3197
+ var NON_PILL_RADII = ["square", "small", "medium", "large"];
3198
+ function pickEnum(value, allowed, fallback) {
3199
+ if (typeof value !== "string") return fallback;
3200
+ return allowed.includes(value) ? value : fallback;
3201
+ }
3202
+ function parseBool(value, fallback) {
3203
+ if (typeof value === "boolean") return value;
3204
+ if (value === "true") return true;
3205
+ if (value === "false") return false;
3206
+ return fallback;
3207
+ }
3208
+ function s(value) {
3209
+ return typeof value === "string" ? value : "";
3210
+ }
3211
+ function decodeBadges(raw) {
3212
+ if (raw === void 0) return null;
3213
+ try {
3214
+ const parsed = JSON.parse(raw);
3215
+ if (!Array.isArray(parsed)) return null;
3216
+ return parsed.filter((b) => !!b && typeof b === "object").map((b, i) => ({
3217
+ id: typeof b["id"] === "string" && b["id"] ? b["id"] : `badge-${i}`,
3218
+ label: typeof b["label"] === "string" ? b["label"] : "",
3219
+ textColor: typeof b["textColor"] === "string" ? b["textColor"] : "#0f172a",
3220
+ backgroundColor: typeof b["backgroundColor"] === "string" ? b["backgroundColor"] : "#f1f5f9",
3221
+ borderColor: typeof b["borderColor"] === "string" && b["borderColor"] ? b["borderColor"] : null
3222
+ })).filter((b) => b.label.length > 0);
3223
+ } catch {
3224
+ return null;
3225
+ }
3226
+ }
3227
+ function encodeBadges(badges) {
3228
+ return JSON.stringify(
3229
+ badges.map((b) => ({
3230
+ id: b.id,
3231
+ label: b.label,
3232
+ textColor: b.textColor,
3233
+ backgroundColor: b.backgroundColor,
3234
+ ...b.borderColor ? { borderColor: b.borderColor } : {}
3235
+ }))
3236
+ );
3237
+ }
3238
+ function decodeBranding(source) {
3239
+ if (!source) return cloneBranding(DEFAULT_BRANDING);
3240
+ const extras = source.sdk_ui_rules?.[BRANDING_GROUP_KEY] ?? {};
3241
+ const decodedBadges = decodeBadges(extras["trustBadges"]);
3242
+ const displayName = s(source.merchant_name) || s(source.seller_name);
3243
+ const logoUrl = s(source.merchant_logo) || s(source.logo);
3244
+ const tagline = s(extras["tagline"]) || s(source.merchant_description);
3245
+ const labelStyle = (() => {
3246
+ const fromBag = extras["labelStyle"];
3247
+ if (fromBag === "above" || fromBag === "hidden") return fromBag;
3248
+ if (fromBag === "floating") return "above";
3249
+ const legacy = source.payment_form_label_type;
3250
+ if (legacy === "above" || legacy === "floating") return "above";
3251
+ if (legacy === "hidden" || legacy === "never") return "hidden";
3252
+ return DEFAULT_BRANDING.labelStyle;
3253
+ })();
3254
+ return {
3255
+ displayName,
3256
+ logoUrl,
3257
+ tagline,
3258
+ showLogo: parseBool(extras["showLogo"], DEFAULT_BRANDING.showLogo),
3259
+ logoShape: pickEnum(
3260
+ extras["logoShape"],
3261
+ ["square", "rounded", "circle"],
3262
+ DEFAULT_BRANDING.logoShape
3263
+ ),
3264
+ logoSize: pickEnum(extras["logoSize"], ["sm", "md", "lg"], DEFAULT_BRANDING.logoSize),
3265
+ primary: s(source.theme) || DEFAULT_BRANDING.primary,
3266
+ background: s(source.background_colour) || DEFAULT_BRANDING.background,
3267
+ surface: s(extras["surface"]) || DEFAULT_BRANDING.surface,
3268
+ text: s(extras["text"]) || DEFAULT_BRANDING.text,
3269
+ heading: s(extras["heading"]) || s(extras["text"]) || DEFAULT_BRANDING.heading,
3270
+ muted: s(extras["muted"]) || DEFAULT_BRANDING.muted,
3271
+ border: s(extras["border"]) || DEFAULT_BRANDING.border,
3272
+ accentText: s(extras["accentText"]) || s(source.theme) || DEFAULT_BRANDING.accentText,
3273
+ buttonBackground: s(source.payment_button_colour) || s(source.theme) || DEFAULT_BRANDING.buttonBackground,
3274
+ buttonText: s(source.payment_button_text_colour) || DEFAULT_BRANDING.buttonText,
3275
+ fontFamily: pickEnum(
3276
+ extras["fontFamily"],
3277
+ ALL_FONT_FAMILIES,
3278
+ DEFAULT_BRANDING.fontFamily
3279
+ ),
3280
+ headingWeight: pickEnum(
3281
+ extras["headingWeight"],
3282
+ ["regular", "medium", "semibold", "bold"],
3283
+ DEFAULT_BRANDING.headingWeight
3284
+ ),
3285
+ radiusSurface: pickEnum(
3286
+ extras["radiusSurface"],
3287
+ NON_PILL_RADII,
3288
+ DEFAULT_BRANDING.radiusSurface
3289
+ ),
3290
+ radiusInput: pickEnum(
3291
+ extras["radiusInput"],
3292
+ NON_PILL_RADII,
3293
+ DEFAULT_BRANDING.radiusInput
3294
+ ),
3295
+ radiusButton: pickEnum(
3296
+ extras["radiusButton"],
3297
+ ALL_RADII,
3298
+ DEFAULT_BRANDING.radiusButton
3299
+ ),
3300
+ radiusBadge: pickEnum(
3301
+ extras["radiusBadge"],
3302
+ ALL_RADII,
3303
+ DEFAULT_BRANDING.radiusBadge
3304
+ ),
3305
+ surfaceStyle: pickEnum(
3306
+ extras["surfaceStyle"],
3307
+ ["flat", "outlined", "elevated"],
3308
+ DEFAULT_BRANDING.surfaceStyle
3309
+ ),
3310
+ surfacePadding: pickEnum(
3311
+ extras["surfacePadding"],
3312
+ ["compact", "comfortable", "spacious"],
3313
+ DEFAULT_BRANDING.surfacePadding
3314
+ ),
3315
+ verticalGap: pickEnum(
3316
+ extras["verticalGap"],
3317
+ ["compact", "comfortable", "spacious"],
3318
+ DEFAULT_BRANDING.verticalGap
3319
+ ),
3320
+ inputSize: pickEnum(
3321
+ extras["inputSize"],
3322
+ ["sm", "md", "lg"],
3323
+ DEFAULT_BRANDING.inputSize
3324
+ ),
3325
+ buttonSize: pickEnum(
3326
+ extras["buttonSize"],
3327
+ ["sm", "md", "lg"],
3328
+ DEFAULT_BRANDING.buttonSize
3329
+ ),
3330
+ layout: pickEnum(
3331
+ extras["layout"],
3332
+ ["compact", "split"],
3333
+ DEFAULT_BRANDING.layout
3334
+ ),
3335
+ summaryPosition: pickEnum(
3336
+ extras["summaryPosition"],
3337
+ ["left", "right"],
3338
+ DEFAULT_BRANDING.summaryPosition
3339
+ ),
3340
+ showOrderSummary: parseBool(extras["showOrderSummary"], DEFAULT_BRANDING.showOrderSummary),
3341
+ summaryGradient: parseBool(extras["summaryGradient"], DEFAULT_BRANDING.summaryGradient),
3342
+ showTotal: parseBool(extras["showTotal"], DEFAULT_BRANDING.showTotal),
3343
+ totalLabel: s(extras["totalLabel"]) || DEFAULT_BRANDING.totalLabel,
3344
+ showCurrencyCode: parseBool(extras["showCurrencyCode"], DEFAULT_BRANDING.showCurrencyCode),
3345
+ showOrderItems: parseBool(extras["showOrderItems"], DEFAULT_BRANDING.showOrderItems),
3346
+ trustBadges: decodedBadges ?? DEFAULT_BRANDING.trustBadges.map((b) => ({ ...b })),
3347
+ headerText: s(source.payment_form_header_text),
3348
+ payButtonLabel: s(source.payment_button_text),
3349
+ cardTermsMessage: s(source.custom_message_for_card_terms),
3350
+ footerText: s(extras["footerText"]),
3351
+ supportEmail: s(extras["supportEmail"]),
3352
+ paymentLayout: pickEnum(
3353
+ source.sdk_layout,
3354
+ ["tabs", "accordion", "spaced_accordion"],
3355
+ DEFAULT_BRANDING.paymentLayout
3356
+ ),
3357
+ labelStyle,
3358
+ showPoweredBy: source.branding_visibility !== false,
3359
+ customCss: s(extras["customCss"])
3360
+ };
3361
+ }
3362
+ function encodeBranding(branding, base) {
3363
+ const trim = (v) => {
3364
+ const t = v.trim();
3365
+ return t.length > 0 ? t : null;
3366
+ };
3367
+ const existingRules = base?.["sdk_ui_rules"] ?? {};
3368
+ const extras = {
3369
+ surface: branding.surface,
3370
+ text: branding.text,
3371
+ heading: branding.heading,
3372
+ muted: branding.muted,
3373
+ border: branding.border,
3374
+ accentText: branding.accentText,
3375
+ fontFamily: branding.fontFamily,
3376
+ headingWeight: branding.headingWeight,
3377
+ radiusSurface: branding.radiusSurface,
3378
+ radiusInput: branding.radiusInput,
3379
+ radiusButton: branding.radiusButton,
3380
+ radiusBadge: branding.radiusBadge,
3381
+ surfaceStyle: branding.surfaceStyle,
3382
+ surfacePadding: branding.surfacePadding,
3383
+ verticalGap: branding.verticalGap,
3384
+ inputSize: branding.inputSize,
3385
+ buttonSize: branding.buttonSize,
3386
+ layout: branding.layout,
3387
+ summaryPosition: branding.summaryPosition,
3388
+ showOrderSummary: String(branding.showOrderSummary),
3389
+ summaryGradient: String(branding.summaryGradient),
3390
+ showTotal: String(branding.showTotal),
3391
+ totalLabel: branding.totalLabel,
3392
+ showCurrencyCode: String(branding.showCurrencyCode),
3393
+ showOrderItems: String(branding.showOrderItems),
3394
+ showLogo: String(branding.showLogo),
3395
+ logoShape: branding.logoShape,
3396
+ logoSize: branding.logoSize,
3397
+ labelStyle: branding.labelStyle,
3398
+ trustBadges: encodeBadges(branding.trustBadges)
3399
+ };
3400
+ const tagline = trim(branding.tagline);
3401
+ if (tagline) extras["tagline"] = tagline;
3402
+ const footer = trim(branding.footerText);
3403
+ if (footer) extras["footerText"] = footer;
3404
+ const support = trim(branding.supportEmail);
3405
+ if (support) extras["supportEmail"] = support;
3406
+ const css = trim(branding.customCss);
3407
+ if (css) extras["customCss"] = css;
3408
+ const nextRules = {
3409
+ ...existingRules,
3410
+ [BRANDING_GROUP_KEY]: extras
3411
+ };
3412
+ const legacyLabel = branding.labelStyle === "hidden" ? "never" : "above";
3413
+ const flatFields = {
3414
+ theme: branding.primary,
3415
+ logo: trim(branding.logoUrl),
3416
+ seller_name: trim(branding.displayName),
3417
+ sdk_layout: branding.paymentLayout,
3418
+ payment_button_text: trim(branding.payButtonLabel),
3419
+ payment_button_colour: branding.buttonBackground,
3420
+ payment_button_text_colour: branding.buttonText,
3421
+ background_colour: branding.background,
3422
+ payment_form_header_text: trim(branding.headerText),
3423
+ payment_form_label_type: legacyLabel,
3424
+ custom_message_for_card_terms: trim(branding.cardTermsMessage),
3425
+ sdk_ui_rules: nextRules,
3426
+ branding_visibility: branding.showPoweredBy
3427
+ };
3428
+ return {
3429
+ ...base,
3430
+ ...flatFields
3431
+ };
3432
+ }
3433
+ var BRANDING_EXPORT_FORMAT = "delopay-checkout-branding";
3434
+ var BRANDING_EXPORT_VERSION = 1;
3435
+ function buildBrandingExport(branding) {
3436
+ return {
3437
+ format: BRANDING_EXPORT_FORMAT,
3438
+ version: BRANDING_EXPORT_VERSION,
3439
+ exported_at: (/* @__PURE__ */ new Date()).toISOString(),
3440
+ branding: cloneBranding(branding)
3441
+ };
3442
+ }
3443
+ function parseImportedBranding(raw) {
3444
+ const root = isObject(raw) && isObject(raw["branding"]) ? raw["branding"] : isObject(raw) ? raw : null;
3445
+ if (!root) return cloneBranding(DEFAULT_BRANDING);
3446
+ const dflt = DEFAULT_BRANDING;
3447
+ const sStr = (v, fallback) => typeof v === "string" ? v : fallback;
3448
+ const sHex = (v, fallback) => typeof v === "string" && isHexColor(v) ? v : fallback;
3449
+ const trustBadges = parseTrustBadgesLoose(root["trustBadges"]) ?? dflt.trustBadges.map((b) => ({ ...b }));
3450
+ const labelStyle = (() => {
3451
+ const v = root["labelStyle"];
3452
+ if (v === "above" || v === "hidden") return v;
3453
+ return dflt.labelStyle;
3454
+ })();
3455
+ return {
3456
+ displayName: sStr(root["displayName"], dflt.displayName),
3457
+ logoUrl: sStr(root["logoUrl"], dflt.logoUrl),
3458
+ tagline: sStr(root["tagline"], dflt.tagline),
3459
+ showLogo: parseBool(root["showLogo"], dflt.showLogo),
3460
+ logoShape: pickEnum(
3461
+ root["logoShape"],
3462
+ ["square", "rounded", "circle"],
3463
+ dflt.logoShape
3464
+ ),
3465
+ logoSize: pickEnum(root["logoSize"], ["sm", "md", "lg"], dflt.logoSize),
3466
+ primary: sHex(root["primary"], dflt.primary),
3467
+ background: sHex(root["background"], dflt.background),
3468
+ surface: sHex(root["surface"], dflt.surface),
3469
+ text: sHex(root["text"], dflt.text),
3470
+ heading: sHex(root["heading"], dflt.heading),
3471
+ muted: sHex(root["muted"], dflt.muted),
3472
+ border: sHex(root["border"], dflt.border),
3473
+ accentText: sHex(root["accentText"], dflt.accentText),
3474
+ buttonBackground: sHex(root["buttonBackground"], dflt.buttonBackground),
3475
+ buttonText: sHex(root["buttonText"], dflt.buttonText),
3476
+ fontFamily: pickEnum(root["fontFamily"], ALL_FONT_FAMILIES, dflt.fontFamily),
3477
+ headingWeight: pickEnum(
3478
+ root["headingWeight"],
3479
+ ["regular", "medium", "semibold", "bold"],
3480
+ dflt.headingWeight
3481
+ ),
3482
+ radiusSurface: pickEnum(
3483
+ root["radiusSurface"],
3484
+ NON_PILL_RADII,
3485
+ dflt.radiusSurface
3486
+ ),
3487
+ radiusInput: pickEnum(root["radiusInput"], NON_PILL_RADII, dflt.radiusInput),
3488
+ radiusButton: pickEnum(root["radiusButton"], ALL_RADII, dflt.radiusButton),
3489
+ radiusBadge: pickEnum(root["radiusBadge"], ALL_RADII, dflt.radiusBadge),
3490
+ surfaceStyle: pickEnum(
3491
+ root["surfaceStyle"],
3492
+ ["flat", "outlined", "elevated"],
3493
+ dflt.surfaceStyle
3494
+ ),
3495
+ surfacePadding: pickEnum(
3496
+ root["surfacePadding"],
3497
+ ["compact", "comfortable", "spacious"],
3498
+ dflt.surfacePadding
3499
+ ),
3500
+ verticalGap: pickEnum(
3501
+ root["verticalGap"],
3502
+ ["compact", "comfortable", "spacious"],
3503
+ dflt.verticalGap
3504
+ ),
3505
+ inputSize: pickEnum(root["inputSize"], ["sm", "md", "lg"], dflt.inputSize),
3506
+ buttonSize: pickEnum(root["buttonSize"], ["sm", "md", "lg"], dflt.buttonSize),
3507
+ layout: pickEnum(root["layout"], ["compact", "split"], dflt.layout),
3508
+ summaryPosition: pickEnum(
3509
+ root["summaryPosition"],
3510
+ ["left", "right"],
3511
+ dflt.summaryPosition
3512
+ ),
3513
+ showOrderSummary: parseBool(root["showOrderSummary"], dflt.showOrderSummary),
3514
+ summaryGradient: parseBool(root["summaryGradient"], dflt.summaryGradient),
3515
+ showTotal: parseBool(root["showTotal"], dflt.showTotal),
3516
+ totalLabel: sStr(root["totalLabel"], dflt.totalLabel),
3517
+ showCurrencyCode: parseBool(root["showCurrencyCode"], dflt.showCurrencyCode),
3518
+ showOrderItems: parseBool(root["showOrderItems"], dflt.showOrderItems),
3519
+ trustBadges,
3520
+ headerText: sStr(root["headerText"], dflt.headerText),
3521
+ payButtonLabel: sStr(root["payButtonLabel"], dflt.payButtonLabel),
3522
+ cardTermsMessage: sStr(root["cardTermsMessage"], dflt.cardTermsMessage),
3523
+ footerText: sStr(root["footerText"], dflt.footerText),
3524
+ supportEmail: sStr(root["supportEmail"], dflt.supportEmail),
3525
+ paymentLayout: pickEnum(
3526
+ root["paymentLayout"],
3527
+ ["tabs", "accordion", "spaced_accordion"],
3528
+ dflt.paymentLayout
3529
+ ),
3530
+ labelStyle,
3531
+ showPoweredBy: parseBool(root["showPoweredBy"], dflt.showPoweredBy),
3532
+ customCss: sStr(root["customCss"], dflt.customCss).slice(0, CUSTOM_CSS_MAX_LENGTH)
3533
+ };
3534
+ }
3535
+ function isObject(v) {
3536
+ return typeof v === "object" && v !== null && !Array.isArray(v);
3537
+ }
3538
+ function parseTrustBadgesLoose(raw) {
3539
+ if (!Array.isArray(raw)) return null;
3540
+ return raw.filter(isObject).map((b, i) => ({
3541
+ id: typeof b["id"] === "string" && b["id"] ? b["id"] : `badge-${i}`,
3542
+ label: typeof b["label"] === "string" ? b["label"] : "",
3543
+ textColor: typeof b["textColor"] === "string" && isHexColor(b["textColor"]) ? b["textColor"] : "#0f172a",
3544
+ backgroundColor: typeof b["backgroundColor"] === "string" && isHexColor(b["backgroundColor"]) ? b["backgroundColor"] : "#f1f5f9",
3545
+ borderColor: typeof b["borderColor"] === "string" && isHexColor(b["borderColor"]) ? b["borderColor"] : null
3546
+ })).filter((b) => b.label.length > 0);
3547
+ }
3548
+ function applyBrandingVariables(el, b) {
3549
+ const set = (k, v) => {
3550
+ el.style.setProperty(k, v);
3551
+ };
3552
+ set("--dp-primary", b.primary);
3553
+ set("--dp-bg", b.background);
3554
+ set("--dp-surface", b.surface);
3555
+ set("--dp-text", b.text);
3556
+ set("--dp-heading", b.heading);
3557
+ set("--dp-muted", b.muted);
3558
+ set("--dp-border", b.border);
3559
+ set("--dp-accent-text", b.accentText);
3560
+ set("--dp-btn-bg", b.buttonBackground);
3561
+ set("--dp-btn-fg", b.buttonText);
3562
+ set("--dp-radius-surface", radiusValue(b.radiusSurface));
3563
+ set("--dp-radius-input", radiusValue(b.radiusInput));
3564
+ set("--dp-radius-button", radiusValue(b.radiusButton));
3565
+ set("--dp-radius-badge", radiusValue(b.radiusBadge));
3566
+ set("--dp-font", fontStack(b.fontFamily));
3567
+ set("--dp-heading-weight", fontWeightValue(b.headingWeight));
3568
+ set("--dp-pad-surface", SURFACE_PAD[b.surfacePadding]);
3569
+ set("--dp-gap-vertical", VERTICAL_GAP[b.verticalGap]);
3570
+ set("--dp-input-pad", INPUT_PAD[b.inputSize]);
3571
+ set("--dp-button-pad", BUTTON_PAD[b.buttonSize]);
3572
+ set("--dp-shadow", shadowFor(b.surfaceStyle));
3573
+ set(
3574
+ "--dp-surface-border",
3575
+ b.surfaceStyle === "outlined" ? `1px solid ${b.border}` : "1px solid transparent"
3576
+ );
3577
+ }
3578
+ function shadowFor(style) {
3579
+ switch (style) {
3580
+ case "elevated":
3581
+ return "0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 32px -12px rgba(15, 23, 42, 0.08)";
3582
+ case "outlined":
3583
+ case "flat":
3584
+ default:
3585
+ return "none";
3586
+ }
3587
+ }
2925
3588
  // Annotate the CommonJS export names for ESM import in node:
2926
3589
  0 && (module.exports = {
2927
3590
  Analytics,
2928
3591
  AnalyticsDashboard,
3592
+ BRANDING_EXPORT_FORMAT,
3593
+ BRANDING_EXPORT_VERSION,
3594
+ CUSTOM_CSS_MAX_LENGTH,
2929
3595
  Cards,
3596
+ DEFAULT_BADGES,
3597
+ DEFAULT_BADGES_DARK,
3598
+ DEFAULT_BRANDING,
3599
+ DEFAULT_BRANDING_DARK,
2930
3600
  Delopay,
2931
3601
  DelopayAuthenticationError,
2932
3602
  DelopayError,
@@ -2936,6 +3606,27 @@ Delopay.webhooks = Webhooks;
2936
3606
  Forex,
2937
3607
  Regions,
2938
3608
  Subscriptions,
2939
- Webhooks
3609
+ Webhooks,
3610
+ applyBrandingVariables,
3611
+ buildBrandingExport,
3612
+ buttonPadValue,
3613
+ cloneBranding,
3614
+ decodeBadges,
3615
+ decodeBranding,
3616
+ defaultBranding,
3617
+ encodeBadges,
3618
+ encodeBranding,
3619
+ fontStack,
3620
+ fontWeightValue,
3621
+ inputPadValue,
3622
+ isDarkSurface,
3623
+ isHexColor,
3624
+ logoDimensions,
3625
+ parseImportedBranding,
3626
+ radiusValue,
3627
+ sanitizeCustomCss,
3628
+ shadowFor,
3629
+ surfacePadValue,
3630
+ verticalGapValue
2940
3631
  });
2941
3632
  //# sourceMappingURL=index.cjs.map