@w3payments/common 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +375 -0
- package/dist/index.d.ts +25 -73
- package/dist/index.js +40 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -73
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,42 @@
|
|
|
1
|
+
const defaultTheme = {
|
|
2
|
+
primary: "#2563eb",
|
|
3
|
+
background: "#ffffff",
|
|
4
|
+
text: "#000000",
|
|
5
|
+
textSecondary: "#6b7280",
|
|
6
|
+
danger: "#dc2626",
|
|
7
|
+
success: "#16a34a",
|
|
8
|
+
warning: "#ca8a04",
|
|
9
|
+
border: "#e5e7eb",
|
|
10
|
+
fontFamily: "Inter, system-ui, sans-serif",
|
|
11
|
+
fontSizeBase: "14px",
|
|
12
|
+
fontSizeSmall: "12px",
|
|
13
|
+
fontSizeLarge: "32px",
|
|
14
|
+
fontWeightNormal: "400",
|
|
15
|
+
spacingUnit: "4px",
|
|
16
|
+
borderRadius: "8px",
|
|
17
|
+
buttonRadius: "6px"
|
|
18
|
+
};
|
|
19
|
+
const BUILT_IN_THEMES = {
|
|
20
|
+
default: defaultTheme,
|
|
21
|
+
night: {
|
|
22
|
+
...defaultTheme,
|
|
23
|
+
primary: "#0085FF",
|
|
24
|
+
background: "#14171D",
|
|
25
|
+
text: "#C9CED8",
|
|
26
|
+
textSecondary: "#8C99AD",
|
|
27
|
+
danger: "#F23154",
|
|
28
|
+
border: "#2B3039"
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const getThemeVariables = (themeName = "default", appearance) => {
|
|
32
|
+
const baseTheme = BUILT_IN_THEMES[themeName] || BUILT_IN_THEMES.default;
|
|
33
|
+
const finalVariables = { ...baseTheme, ...appearance?.variables };
|
|
34
|
+
const cssVars = {};
|
|
35
|
+
Object.entries(finalVariables).forEach(([key, value]) => {
|
|
36
|
+
cssVars[`--w3-${key}`] = value;
|
|
37
|
+
});
|
|
38
|
+
return cssVars;
|
|
39
|
+
};
|
|
1
40
|
class PaymentMethodService {
|
|
2
41
|
static instance;
|
|
3
42
|
paymentMethods = /* @__PURE__ */ new Map();
|
|
@@ -468,78 +507,6 @@ function truncateToCurrencyDecimals(value, currency) {
|
|
|
468
507
|
const truncatedDecimal = parts[1].substring(0, currency.decimals);
|
|
469
508
|
return truncatedDecimal.length > 0 ? `${parts[0]}.${truncatedDecimal}` : parts[0];
|
|
470
509
|
}
|
|
471
|
-
function camelToKebab(str) {
|
|
472
|
-
return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
|
473
|
-
}
|
|
474
|
-
function getDefaultVariables() {
|
|
475
|
-
return {
|
|
476
|
-
colorPrimary: "#6366f1",
|
|
477
|
-
colorPrimaryHover: "#4f46e5",
|
|
478
|
-
colorPrimaryLight: "#e0e7ff",
|
|
479
|
-
colorBackground: "#ffffff",
|
|
480
|
-
colorText: "#1f2937",
|
|
481
|
-
colorTextMuted: "#6b7280",
|
|
482
|
-
colorBorder: "#e5e7eb",
|
|
483
|
-
colorBorderLight: "#f3f4f6",
|
|
484
|
-
colorDanger: "#ef4444",
|
|
485
|
-
colorSuccess: "#10b981",
|
|
486
|
-
fontFamily: "system-ui, -apple-system, sans-serif",
|
|
487
|
-
fontSize: "1rem",
|
|
488
|
-
borderRadius: "0.5rem",
|
|
489
|
-
spacing: "1rem"
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
function getThemePreset(themeName) {
|
|
493
|
-
const defaults = getDefaultVariables();
|
|
494
|
-
switch (themeName) {
|
|
495
|
-
case "dark":
|
|
496
|
-
return {
|
|
497
|
-
...defaults,
|
|
498
|
-
colorPrimary: "#6366f1",
|
|
499
|
-
colorPrimaryHover: "#7c3aed",
|
|
500
|
-
colorPrimaryLight: "#1e1b4b",
|
|
501
|
-
colorBackground: "#111827",
|
|
502
|
-
colorText: "#f9fafb",
|
|
503
|
-
colorTextMuted: "#9ca3af",
|
|
504
|
-
colorBorder: "#374151",
|
|
505
|
-
colorBorderLight: "#4b5563"
|
|
506
|
-
};
|
|
507
|
-
case "light":
|
|
508
|
-
default:
|
|
509
|
-
return defaults;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
function applyTheme(themeInput, container) {
|
|
513
|
-
const theme = typeof themeInput === "string" ? { theme: themeInput } : themeInput;
|
|
514
|
-
const baseVariables = getThemePreset(theme.theme ?? "light");
|
|
515
|
-
const finalVariables = { ...baseVariables, ...theme.variables };
|
|
516
|
-
Object.entries(finalVariables).forEach(([key, value]) => {
|
|
517
|
-
if (value !== void 0) {
|
|
518
|
-
const cssVar = `--${camelToKebab(key)}`;
|
|
519
|
-
container.style.setProperty(cssVar, value);
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
if (theme.theme) {
|
|
523
|
-
container.setAttribute("data-theme", theme.theme);
|
|
524
|
-
}
|
|
525
|
-
if (theme.rules) {
|
|
526
|
-
applyComponentRules(theme.rules);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
function applyComponentRules(rules) {
|
|
530
|
-
const styleId = "w3-theme-rules";
|
|
531
|
-
let styleElement = document.getElementById(styleId);
|
|
532
|
-
if (!styleElement) {
|
|
533
|
-
styleElement = document.createElement("style");
|
|
534
|
-
styleElement.id = styleId;
|
|
535
|
-
document.head.appendChild(styleElement);
|
|
536
|
-
}
|
|
537
|
-
const css = Object.entries(rules).map(([selector, styles]) => {
|
|
538
|
-
const cssProperties = Object.entries(styles).map(([prop, value]) => `${camelToKebab(prop)}: ${value};`).join(" ");
|
|
539
|
-
return `.w3-widget ${selector} { ${cssProperties} }`;
|
|
540
|
-
}).join("\n");
|
|
541
|
-
styleElement.textContent = css;
|
|
542
|
-
}
|
|
543
510
|
function getDefaultExportFromCjs(x) {
|
|
544
511
|
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
545
512
|
}
|
|
@@ -2878,7 +2845,6 @@ export {
|
|
|
2878
2845
|
CURRENCIES,
|
|
2879
2846
|
NETWORKS,
|
|
2880
2847
|
PaymentMethodService,
|
|
2881
|
-
applyTheme,
|
|
2882
2848
|
copyToClipboard,
|
|
2883
2849
|
currencyService,
|
|
2884
2850
|
formatCurrencyDisplay,
|
|
@@ -2892,6 +2858,7 @@ export {
|
|
|
2892
2858
|
getCurrencyIcon,
|
|
2893
2859
|
getExchangeIcon,
|
|
2894
2860
|
getFiatIcon,
|
|
2861
|
+
getThemeVariables,
|
|
2895
2862
|
networkService,
|
|
2896
2863
|
paymentMethodService,
|
|
2897
2864
|
truncateToCurrencyDecimals,
|