@delopay/sdk 0.18.3 → 0.19.1

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,649 @@ 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(extras["layout"], ["compact", "split"], DEFAULT_BRANDING.layout),
3331
+ summaryPosition: pickEnum(
3332
+ extras["summaryPosition"],
3333
+ ["left", "right"],
3334
+ DEFAULT_BRANDING.summaryPosition
3335
+ ),
3336
+ showOrderSummary: parseBool(extras["showOrderSummary"], DEFAULT_BRANDING.showOrderSummary),
3337
+ summaryGradient: parseBool(extras["summaryGradient"], DEFAULT_BRANDING.summaryGradient),
3338
+ showTotal: parseBool(extras["showTotal"], DEFAULT_BRANDING.showTotal),
3339
+ totalLabel: s(extras["totalLabel"]) || DEFAULT_BRANDING.totalLabel,
3340
+ showCurrencyCode: parseBool(extras["showCurrencyCode"], DEFAULT_BRANDING.showCurrencyCode),
3341
+ showOrderItems: parseBool(extras["showOrderItems"], DEFAULT_BRANDING.showOrderItems),
3342
+ trustBadges: decodedBadges ?? DEFAULT_BRANDING.trustBadges.map((b) => ({ ...b })),
3343
+ headerText: s(source.payment_form_header_text),
3344
+ payButtonLabel: s(source.payment_button_text),
3345
+ cardTermsMessage: s(source.custom_message_for_card_terms),
3346
+ footerText: s(extras["footerText"]),
3347
+ supportEmail: s(extras["supportEmail"]),
3348
+ paymentLayout: pickEnum(
3349
+ source.sdk_layout,
3350
+ ["tabs", "accordion", "spaced_accordion"],
3351
+ DEFAULT_BRANDING.paymentLayout
3352
+ ),
3353
+ labelStyle,
3354
+ showPoweredBy: source.branding_visibility !== false,
3355
+ customCss: s(extras["customCss"])
3356
+ };
3357
+ }
3358
+ function encodeBranding(branding, base) {
3359
+ const trim = (v) => {
3360
+ const t = v.trim();
3361
+ return t.length > 0 ? t : null;
3362
+ };
3363
+ const existingRules = base?.["sdk_ui_rules"] ?? {};
3364
+ const extras = {
3365
+ surface: branding.surface,
3366
+ text: branding.text,
3367
+ heading: branding.heading,
3368
+ muted: branding.muted,
3369
+ border: branding.border,
3370
+ accentText: branding.accentText,
3371
+ fontFamily: branding.fontFamily,
3372
+ headingWeight: branding.headingWeight,
3373
+ radiusSurface: branding.radiusSurface,
3374
+ radiusInput: branding.radiusInput,
3375
+ radiusButton: branding.radiusButton,
3376
+ radiusBadge: branding.radiusBadge,
3377
+ surfaceStyle: branding.surfaceStyle,
3378
+ surfacePadding: branding.surfacePadding,
3379
+ verticalGap: branding.verticalGap,
3380
+ inputSize: branding.inputSize,
3381
+ buttonSize: branding.buttonSize,
3382
+ layout: branding.layout,
3383
+ summaryPosition: branding.summaryPosition,
3384
+ showOrderSummary: String(branding.showOrderSummary),
3385
+ summaryGradient: String(branding.summaryGradient),
3386
+ showTotal: String(branding.showTotal),
3387
+ totalLabel: branding.totalLabel,
3388
+ showCurrencyCode: String(branding.showCurrencyCode),
3389
+ showOrderItems: String(branding.showOrderItems),
3390
+ showLogo: String(branding.showLogo),
3391
+ logoShape: branding.logoShape,
3392
+ logoSize: branding.logoSize,
3393
+ labelStyle: branding.labelStyle,
3394
+ trustBadges: encodeBadges(branding.trustBadges)
3395
+ };
3396
+ const tagline = trim(branding.tagline);
3397
+ if (tagline) extras["tagline"] = tagline;
3398
+ const footer = trim(branding.footerText);
3399
+ if (footer) extras["footerText"] = footer;
3400
+ const support = trim(branding.supportEmail);
3401
+ if (support) extras["supportEmail"] = support;
3402
+ const css = trim(branding.customCss);
3403
+ if (css) extras["customCss"] = css;
3404
+ const nextRules = {
3405
+ ...existingRules,
3406
+ [BRANDING_GROUP_KEY]: extras
3407
+ };
3408
+ const legacyLabel = branding.labelStyle === "hidden" ? "never" : "above";
3409
+ const flatFields = {
3410
+ theme: branding.primary,
3411
+ logo: trim(branding.logoUrl),
3412
+ seller_name: trim(branding.displayName),
3413
+ sdk_layout: branding.paymentLayout,
3414
+ payment_button_text: trim(branding.payButtonLabel),
3415
+ payment_button_colour: branding.buttonBackground,
3416
+ payment_button_text_colour: branding.buttonText,
3417
+ background_colour: branding.background,
3418
+ payment_form_header_text: trim(branding.headerText),
3419
+ payment_form_label_type: legacyLabel,
3420
+ custom_message_for_card_terms: trim(branding.cardTermsMessage),
3421
+ sdk_ui_rules: nextRules,
3422
+ branding_visibility: branding.showPoweredBy
3423
+ };
3424
+ return {
3425
+ ...base,
3426
+ ...flatFields
3427
+ };
3428
+ }
3429
+ var BRANDING_EXPORT_FORMAT = "delopay-checkout-branding";
3430
+ var BRANDING_EXPORT_VERSION = 1;
3431
+ function buildBrandingExport(branding) {
3432
+ return {
3433
+ format: BRANDING_EXPORT_FORMAT,
3434
+ version: BRANDING_EXPORT_VERSION,
3435
+ exported_at: (/* @__PURE__ */ new Date()).toISOString(),
3436
+ branding: cloneBranding(branding)
3437
+ };
3438
+ }
3439
+ function parseImportedBranding(raw) {
3440
+ const root = isObject(raw) && isObject(raw["branding"]) ? raw["branding"] : isObject(raw) ? raw : null;
3441
+ if (!root) return cloneBranding(DEFAULT_BRANDING);
3442
+ const dflt = DEFAULT_BRANDING;
3443
+ const sStr = (v, fallback) => typeof v === "string" ? v : fallback;
3444
+ const sHex = (v, fallback) => typeof v === "string" && isHexColor(v) ? v : fallback;
3445
+ const trustBadges = parseTrustBadgesLoose(root["trustBadges"]) ?? dflt.trustBadges.map((b) => ({ ...b }));
3446
+ const labelStyle = (() => {
3447
+ const v = root["labelStyle"];
3448
+ if (v === "above" || v === "hidden") return v;
3449
+ return dflt.labelStyle;
3450
+ })();
3451
+ return {
3452
+ displayName: sStr(root["displayName"], dflt.displayName),
3453
+ logoUrl: sStr(root["logoUrl"], dflt.logoUrl),
3454
+ tagline: sStr(root["tagline"], dflt.tagline),
3455
+ showLogo: parseBool(root["showLogo"], dflt.showLogo),
3456
+ logoShape: pickEnum(
3457
+ root["logoShape"],
3458
+ ["square", "rounded", "circle"],
3459
+ dflt.logoShape
3460
+ ),
3461
+ logoSize: pickEnum(root["logoSize"], ["sm", "md", "lg"], dflt.logoSize),
3462
+ primary: sHex(root["primary"], dflt.primary),
3463
+ background: sHex(root["background"], dflt.background),
3464
+ surface: sHex(root["surface"], dflt.surface),
3465
+ text: sHex(root["text"], dflt.text),
3466
+ heading: sHex(root["heading"], dflt.heading),
3467
+ muted: sHex(root["muted"], dflt.muted),
3468
+ border: sHex(root["border"], dflt.border),
3469
+ accentText: sHex(root["accentText"], dflt.accentText),
3470
+ buttonBackground: sHex(root["buttonBackground"], dflt.buttonBackground),
3471
+ buttonText: sHex(root["buttonText"], dflt.buttonText),
3472
+ fontFamily: pickEnum(root["fontFamily"], ALL_FONT_FAMILIES, dflt.fontFamily),
3473
+ headingWeight: pickEnum(
3474
+ root["headingWeight"],
3475
+ ["regular", "medium", "semibold", "bold"],
3476
+ dflt.headingWeight
3477
+ ),
3478
+ radiusSurface: pickEnum(
3479
+ root["radiusSurface"],
3480
+ NON_PILL_RADII,
3481
+ dflt.radiusSurface
3482
+ ),
3483
+ radiusInput: pickEnum(root["radiusInput"], NON_PILL_RADII, dflt.radiusInput),
3484
+ radiusButton: pickEnum(root["radiusButton"], ALL_RADII, dflt.radiusButton),
3485
+ radiusBadge: pickEnum(root["radiusBadge"], ALL_RADII, dflt.radiusBadge),
3486
+ surfaceStyle: pickEnum(
3487
+ root["surfaceStyle"],
3488
+ ["flat", "outlined", "elevated"],
3489
+ dflt.surfaceStyle
3490
+ ),
3491
+ surfacePadding: pickEnum(
3492
+ root["surfacePadding"],
3493
+ ["compact", "comfortable", "spacious"],
3494
+ dflt.surfacePadding
3495
+ ),
3496
+ verticalGap: pickEnum(
3497
+ root["verticalGap"],
3498
+ ["compact", "comfortable", "spacious"],
3499
+ dflt.verticalGap
3500
+ ),
3501
+ inputSize: pickEnum(root["inputSize"], ["sm", "md", "lg"], dflt.inputSize),
3502
+ buttonSize: pickEnum(root["buttonSize"], ["sm", "md", "lg"], dflt.buttonSize),
3503
+ layout: pickEnum(root["layout"], ["compact", "split"], dflt.layout),
3504
+ summaryPosition: pickEnum(
3505
+ root["summaryPosition"],
3506
+ ["left", "right"],
3507
+ dflt.summaryPosition
3508
+ ),
3509
+ showOrderSummary: parseBool(root["showOrderSummary"], dflt.showOrderSummary),
3510
+ summaryGradient: parseBool(root["summaryGradient"], dflt.summaryGradient),
3511
+ showTotal: parseBool(root["showTotal"], dflt.showTotal),
3512
+ totalLabel: sStr(root["totalLabel"], dflt.totalLabel),
3513
+ showCurrencyCode: parseBool(root["showCurrencyCode"], dflt.showCurrencyCode),
3514
+ showOrderItems: parseBool(root["showOrderItems"], dflt.showOrderItems),
3515
+ trustBadges,
3516
+ headerText: sStr(root["headerText"], dflt.headerText),
3517
+ payButtonLabel: sStr(root["payButtonLabel"], dflt.payButtonLabel),
3518
+ cardTermsMessage: sStr(root["cardTermsMessage"], dflt.cardTermsMessage),
3519
+ footerText: sStr(root["footerText"], dflt.footerText),
3520
+ supportEmail: sStr(root["supportEmail"], dflt.supportEmail),
3521
+ paymentLayout: pickEnum(
3522
+ root["paymentLayout"],
3523
+ ["tabs", "accordion", "spaced_accordion"],
3524
+ dflt.paymentLayout
3525
+ ),
3526
+ labelStyle,
3527
+ showPoweredBy: parseBool(root["showPoweredBy"], dflt.showPoweredBy),
3528
+ customCss: sStr(root["customCss"], dflt.customCss).slice(0, CUSTOM_CSS_MAX_LENGTH)
3529
+ };
3530
+ }
3531
+ function isObject(v) {
3532
+ return typeof v === "object" && v !== null && !Array.isArray(v);
3533
+ }
3534
+ function parseTrustBadgesLoose(raw) {
3535
+ if (!Array.isArray(raw)) return null;
3536
+ return raw.filter(isObject).map((b, i) => ({
3537
+ id: typeof b["id"] === "string" && b["id"] ? b["id"] : `badge-${i}`,
3538
+ label: typeof b["label"] === "string" ? b["label"] : "",
3539
+ textColor: typeof b["textColor"] === "string" && isHexColor(b["textColor"]) ? b["textColor"] : "#0f172a",
3540
+ backgroundColor: typeof b["backgroundColor"] === "string" && isHexColor(b["backgroundColor"]) ? b["backgroundColor"] : "#f1f5f9",
3541
+ borderColor: typeof b["borderColor"] === "string" && isHexColor(b["borderColor"]) ? b["borderColor"] : null
3542
+ })).filter((b) => b.label.length > 0);
3543
+ }
3544
+ function applyBrandingVariables(el, b) {
3545
+ const set = (k, v) => {
3546
+ el.style.setProperty(k, v);
3547
+ };
3548
+ set("--dp-primary", b.primary);
3549
+ set("--dp-bg", b.background);
3550
+ set("--dp-surface", b.surface);
3551
+ set("--dp-text", b.text);
3552
+ set("--dp-heading", b.heading);
3553
+ set("--dp-muted", b.muted);
3554
+ set("--dp-border", b.border);
3555
+ set("--dp-accent-text", b.accentText);
3556
+ set("--dp-btn-bg", b.buttonBackground);
3557
+ set("--dp-btn-fg", b.buttonText);
3558
+ set("--dp-radius-surface", radiusValue(b.radiusSurface));
3559
+ set("--dp-radius-input", radiusValue(b.radiusInput));
3560
+ set("--dp-radius-button", radiusValue(b.radiusButton));
3561
+ set("--dp-radius-badge", radiusValue(b.radiusBadge));
3562
+ set("--dp-font", fontStack(b.fontFamily));
3563
+ set("--dp-heading-weight", fontWeightValue(b.headingWeight));
3564
+ set("--dp-pad-surface", SURFACE_PAD[b.surfacePadding]);
3565
+ set("--dp-gap-vertical", VERTICAL_GAP[b.verticalGap]);
3566
+ set("--dp-input-pad", INPUT_PAD[b.inputSize]);
3567
+ set("--dp-button-pad", BUTTON_PAD[b.buttonSize]);
3568
+ set("--dp-shadow", shadowFor(b.surfaceStyle));
3569
+ set(
3570
+ "--dp-surface-border",
3571
+ b.surfaceStyle === "outlined" ? `1px solid ${b.border}` : "1px solid transparent"
3572
+ );
3573
+ }
3574
+ function shadowFor(style) {
3575
+ switch (style) {
3576
+ case "elevated":
3577
+ return "0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 32px -12px rgba(15, 23, 42, 0.08)";
3578
+ case "outlined":
3579
+ case "flat":
3580
+ default:
3581
+ return "none";
3582
+ }
3583
+ }
2925
3584
  // Annotate the CommonJS export names for ESM import in node:
2926
3585
  0 && (module.exports = {
2927
3586
  Analytics,
2928
3587
  AnalyticsDashboard,
3588
+ BRANDING_EXPORT_FORMAT,
3589
+ BRANDING_EXPORT_VERSION,
3590
+ CUSTOM_CSS_MAX_LENGTH,
2929
3591
  Cards,
3592
+ DEFAULT_BADGES,
3593
+ DEFAULT_BADGES_DARK,
3594
+ DEFAULT_BRANDING,
3595
+ DEFAULT_BRANDING_DARK,
2930
3596
  Delopay,
2931
3597
  DelopayAuthenticationError,
2932
3598
  DelopayError,
@@ -2936,6 +3602,27 @@ Delopay.webhooks = Webhooks;
2936
3602
  Forex,
2937
3603
  Regions,
2938
3604
  Subscriptions,
2939
- Webhooks
3605
+ Webhooks,
3606
+ applyBrandingVariables,
3607
+ buildBrandingExport,
3608
+ buttonPadValue,
3609
+ cloneBranding,
3610
+ decodeBadges,
3611
+ decodeBranding,
3612
+ defaultBranding,
3613
+ encodeBadges,
3614
+ encodeBranding,
3615
+ fontStack,
3616
+ fontWeightValue,
3617
+ inputPadValue,
3618
+ isDarkSurface,
3619
+ isHexColor,
3620
+ logoDimensions,
3621
+ parseImportedBranding,
3622
+ radiusValue,
3623
+ sanitizeCustomCss,
3624
+ shadowFor,
3625
+ surfacePadValue,
3626
+ verticalGapValue
2940
3627
  });
2941
3628
  //# sourceMappingURL=index.cjs.map