@marvalt/dstyler 0.1.3 → 0.1.6
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 +42 -0
- package/dist/index.d.ts +73 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +282 -154
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +284 -153
- package/dist/index.js.map +1 -1
- package/dist/providers/ThemeProvider.d.ts +11 -2
- package/dist/providers/ThemeProvider.d.ts.map +1 -1
- package/dist/utils/createColorMapper.d.ts +51 -0
- package/dist/utils/createColorMapper.d.ts.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,172 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var React = require('react');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @license GPL-3.0-or-later
|
|
7
|
+
*
|
|
8
|
+
* This file is part of the MarVAlt Open SDK.
|
|
9
|
+
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
10
|
+
*/
|
|
11
|
+
const defaultTokens = {
|
|
12
|
+
colors: {
|
|
13
|
+
primary: '#1a73e8',
|
|
14
|
+
secondary: '#34a853',
|
|
15
|
+
background: '#ffffff',
|
|
16
|
+
text: '#222222',
|
|
17
|
+
default: '#ffffff',
|
|
18
|
+
alternate: '#f5f5f5',
|
|
19
|
+
highlight: '#e8f0fe',
|
|
20
|
+
},
|
|
21
|
+
spacing: {
|
|
22
|
+
sm: 8,
|
|
23
|
+
md: 16,
|
|
24
|
+
lg: 32,
|
|
25
|
+
xl: 64,
|
|
26
|
+
},
|
|
27
|
+
typography: {
|
|
28
|
+
body: 'Inter, sans-serif',
|
|
29
|
+
heading: 'Inter, sans-serif',
|
|
30
|
+
scale: 1.2,
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @license GPL-3.0-or-later
|
|
36
|
+
*
|
|
37
|
+
* This file is part of the MarVAlt Open SDK.
|
|
38
|
+
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* Convert WordPress theme styles to design tokens
|
|
42
|
+
*/
|
|
43
|
+
function convertWordPressToTokens(wpStyles) {
|
|
44
|
+
if (!wpStyles) {
|
|
45
|
+
return defaultTokens;
|
|
46
|
+
}
|
|
47
|
+
const tokens = {
|
|
48
|
+
...defaultTokens,
|
|
49
|
+
colors: {
|
|
50
|
+
...defaultTokens.colors,
|
|
51
|
+
...(wpStyles.colors?.primary && { primary: wpStyles.colors.primary }),
|
|
52
|
+
...(wpStyles.colors?.secondary && { secondary: wpStyles.colors.secondary }),
|
|
53
|
+
...(wpStyles.colors?.text && { text: wpStyles.colors.text }),
|
|
54
|
+
...(wpStyles.colors?.background && {
|
|
55
|
+
background: wpStyles.colors.background,
|
|
56
|
+
default: wpStyles.colors.background,
|
|
57
|
+
}),
|
|
58
|
+
},
|
|
59
|
+
typography: {
|
|
60
|
+
...defaultTokens.typography,
|
|
61
|
+
...(wpStyles.typography?.heading_font_family && {
|
|
62
|
+
heading: wpStyles.typography.heading_font_family
|
|
63
|
+
}),
|
|
64
|
+
...(wpStyles.typography?.body_font_family && {
|
|
65
|
+
body: wpStyles.typography.body_font_family
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
// Generate alternate and highlight colors from primary/background
|
|
70
|
+
if (tokens.colors.primary && tokens.colors.background) {
|
|
71
|
+
// Alternate: slightly darker/lighter than background
|
|
72
|
+
tokens.colors.alternate = adjustBrightness(tokens.colors.background, -0.05);
|
|
73
|
+
// Highlight: tinted with primary color
|
|
74
|
+
tokens.colors.highlight = blendColors(tokens.colors.background, tokens.colors.primary, 0.1);
|
|
75
|
+
}
|
|
76
|
+
return tokens;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Adjust brightness of a hex color
|
|
80
|
+
*/
|
|
81
|
+
function adjustBrightness(hex, amount) {
|
|
82
|
+
const num = parseInt(hex.replace('#', ''), 16);
|
|
83
|
+
const r = Math.max(0, Math.min(255, ((num >> 16) & 0xff) + (amount * 255)));
|
|
84
|
+
const g = Math.max(0, Math.min(255, ((num >> 8) & 0xff) + (amount * 255)));
|
|
85
|
+
const b = Math.max(0, Math.min(255, (num & 0xff) + (amount * 255)));
|
|
86
|
+
return `#${((r << 16) | (g << 8) | b).toString(16).padStart(6, '0')}`;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Blend two colors
|
|
90
|
+
*/
|
|
91
|
+
function blendColors(color1, color2, ratio) {
|
|
92
|
+
const c1 = hexToRgb(color1);
|
|
93
|
+
const c2 = hexToRgb(color2);
|
|
94
|
+
if (!c1 || !c2)
|
|
95
|
+
return color1;
|
|
96
|
+
const r = Math.round(c1.r + (c2.r - c1.r) * ratio);
|
|
97
|
+
const g = Math.round(c1.g + (c2.g - c1.g) * ratio);
|
|
98
|
+
const b = Math.round(c1.b + (c2.b - c1.b) * ratio);
|
|
99
|
+
return `rgb(${r}, ${g}, ${b})`;
|
|
100
|
+
}
|
|
101
|
+
function hexToRgb(hex) {
|
|
102
|
+
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
103
|
+
return result
|
|
104
|
+
? {
|
|
105
|
+
r: parseInt(result[1], 16),
|
|
106
|
+
g: parseInt(result[2], 16),
|
|
107
|
+
b: parseInt(result[3], 16),
|
|
108
|
+
}
|
|
109
|
+
: null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @license GPL-3.0-or-later
|
|
114
|
+
*
|
|
115
|
+
* This file is part of the MarVAlt Open SDK.
|
|
116
|
+
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
117
|
+
*/
|
|
118
|
+
/**
|
|
119
|
+
* Inject CSS variables from design tokens into the document
|
|
120
|
+
*/
|
|
121
|
+
function injectCSSVariables(tokens) {
|
|
122
|
+
if (typeof document === 'undefined')
|
|
123
|
+
return;
|
|
124
|
+
const root = document.documentElement;
|
|
125
|
+
// Colors
|
|
126
|
+
root.style.setProperty('--dstyler-color-primary', tokens.colors.primary);
|
|
127
|
+
root.style.setProperty('--dstyler-color-secondary', tokens.colors.secondary);
|
|
128
|
+
root.style.setProperty('--dstyler-color-background', tokens.colors.background);
|
|
129
|
+
root.style.setProperty('--dstyler-color-text', tokens.colors.text);
|
|
130
|
+
root.style.setProperty('--dstyler-color-default', tokens.colors.default);
|
|
131
|
+
root.style.setProperty('--dstyler-color-alternate', tokens.colors.alternate);
|
|
132
|
+
root.style.setProperty('--dstyler-color-highlight', tokens.colors.highlight);
|
|
133
|
+
// Spacing
|
|
134
|
+
root.style.setProperty('--dstyler-spacing-sm', `${tokens.spacing.sm}px`);
|
|
135
|
+
root.style.setProperty('--dstyler-spacing-md', `${tokens.spacing.md}px`);
|
|
136
|
+
root.style.setProperty('--dstyler-spacing-lg', `${tokens.spacing.lg}px`);
|
|
137
|
+
root.style.setProperty('--dstyler-spacing-xl', `${tokens.spacing.xl}px`);
|
|
138
|
+
// Typography
|
|
139
|
+
root.style.setProperty('--dstyler-font-body', tokens.typography.body);
|
|
140
|
+
root.style.setProperty('--dstyler-font-heading', tokens.typography.heading);
|
|
141
|
+
root.style.setProperty('--dstyler-font-scale', tokens.typography.scale.toString());
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @license GPL-3.0-or-later
|
|
146
|
+
*
|
|
147
|
+
* This file is part of the MarVAlt Open SDK.
|
|
148
|
+
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
149
|
+
*/
|
|
150
|
+
/**
|
|
151
|
+
* ThemeProvider - Provides design tokens to the application
|
|
152
|
+
*
|
|
153
|
+
* Priority order:
|
|
154
|
+
* 1. customTokens (highest priority - overrides everything)
|
|
155
|
+
* 2. WordPress styles (converted to tokens)
|
|
156
|
+
* 3. Default tokens (fallback)
|
|
157
|
+
*/
|
|
158
|
+
const ThemeProvider = ({ children, wpStyles, customTokens }) => {
|
|
159
|
+
React.useEffect(() => {
|
|
160
|
+
// Use custom tokens if provided, otherwise convert WordPress styles
|
|
161
|
+
const tokens = customTokens || convertWordPressToTokens(wpStyles);
|
|
162
|
+
injectCSSVariables(tokens);
|
|
163
|
+
}, [wpStyles, customTokens]);
|
|
164
|
+
// Return children if provided, otherwise return null (theme still applies via useEffect)
|
|
165
|
+
if (children === undefined || children === null) {
|
|
166
|
+
return null;
|
|
167
|
+
}
|
|
168
|
+
return React.createElement(React.Fragment, null, children);
|
|
169
|
+
};
|
|
4
170
|
|
|
5
171
|
var jsxRuntime = {exports: {}};
|
|
6
172
|
|
|
@@ -338,7 +504,7 @@ function requireReactJsxRuntime_development () {
|
|
|
338
504
|
object.$$typeof === REACT_ELEMENT_TYPE
|
|
339
505
|
);
|
|
340
506
|
}
|
|
341
|
-
var React =
|
|
507
|
+
var React$1 = React,
|
|
342
508
|
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
|
|
343
509
|
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
|
|
344
510
|
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
|
|
@@ -354,7 +520,7 @@ function requireReactJsxRuntime_development () {
|
|
|
354
520
|
REACT_ACTIVITY_TYPE = Symbol.for("react.activity"),
|
|
355
521
|
REACT_CLIENT_REFERENCE = Symbol.for("react.client.reference"),
|
|
356
522
|
ReactSharedInternals =
|
|
357
|
-
React.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
|
|
523
|
+
React$1.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE,
|
|
358
524
|
hasOwnProperty = Object.prototype.hasOwnProperty,
|
|
359
525
|
isArrayImpl = Array.isArray,
|
|
360
526
|
createTask = console.createTask
|
|
@@ -362,15 +528,15 @@ function requireReactJsxRuntime_development () {
|
|
|
362
528
|
: function () {
|
|
363
529
|
return null;
|
|
364
530
|
};
|
|
365
|
-
React = {
|
|
531
|
+
React$1 = {
|
|
366
532
|
react_stack_bottom_frame: function (callStackForError) {
|
|
367
533
|
return callStackForError();
|
|
368
534
|
}
|
|
369
535
|
};
|
|
370
536
|
var specialPropKeyWarningShown;
|
|
371
537
|
var didWarnAboutElementRef = {};
|
|
372
|
-
var unknownOwnerDebugStack = React.react_stack_bottom_frame.bind(
|
|
373
|
-
React,
|
|
538
|
+
var unknownOwnerDebugStack = React$1.react_stack_bottom_frame.bind(
|
|
539
|
+
React$1,
|
|
374
540
|
UnknownOwner
|
|
375
541
|
)();
|
|
376
542
|
var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
|
|
@@ -416,153 +582,6 @@ if (process.env.NODE_ENV === 'production') {
|
|
|
416
582
|
|
|
417
583
|
var jsxRuntimeExports = jsxRuntime.exports;
|
|
418
584
|
|
|
419
|
-
/**
|
|
420
|
-
* @license GPL-3.0-or-later
|
|
421
|
-
*
|
|
422
|
-
* This file is part of the MarVAlt Open SDK.
|
|
423
|
-
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
424
|
-
*/
|
|
425
|
-
const defaultTokens = {
|
|
426
|
-
colors: {
|
|
427
|
-
primary: '#1a73e8',
|
|
428
|
-
secondary: '#34a853',
|
|
429
|
-
background: '#ffffff',
|
|
430
|
-
text: '#222222',
|
|
431
|
-
default: '#ffffff',
|
|
432
|
-
alternate: '#f5f5f5',
|
|
433
|
-
highlight: '#e8f0fe',
|
|
434
|
-
},
|
|
435
|
-
spacing: {
|
|
436
|
-
sm: 8,
|
|
437
|
-
md: 16,
|
|
438
|
-
lg: 32,
|
|
439
|
-
xl: 64,
|
|
440
|
-
},
|
|
441
|
-
typography: {
|
|
442
|
-
body: 'Inter, sans-serif',
|
|
443
|
-
heading: 'Inter, sans-serif',
|
|
444
|
-
scale: 1.2,
|
|
445
|
-
},
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* @license GPL-3.0-or-later
|
|
450
|
-
*
|
|
451
|
-
* This file is part of the MarVAlt Open SDK.
|
|
452
|
-
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
453
|
-
*/
|
|
454
|
-
/**
|
|
455
|
-
* Convert WordPress theme styles to design tokens
|
|
456
|
-
*/
|
|
457
|
-
function convertWordPressToTokens(wpStyles) {
|
|
458
|
-
if (!wpStyles) {
|
|
459
|
-
return defaultTokens;
|
|
460
|
-
}
|
|
461
|
-
const tokens = {
|
|
462
|
-
...defaultTokens,
|
|
463
|
-
colors: {
|
|
464
|
-
...defaultTokens.colors,
|
|
465
|
-
...(wpStyles.colors?.primary && { primary: wpStyles.colors.primary }),
|
|
466
|
-
...(wpStyles.colors?.secondary && { secondary: wpStyles.colors.secondary }),
|
|
467
|
-
...(wpStyles.colors?.text && { text: wpStyles.colors.text }),
|
|
468
|
-
...(wpStyles.colors?.background && {
|
|
469
|
-
background: wpStyles.colors.background,
|
|
470
|
-
default: wpStyles.colors.background,
|
|
471
|
-
}),
|
|
472
|
-
},
|
|
473
|
-
typography: {
|
|
474
|
-
...defaultTokens.typography,
|
|
475
|
-
...(wpStyles.typography?.heading_font_family && {
|
|
476
|
-
heading: wpStyles.typography.heading_font_family
|
|
477
|
-
}),
|
|
478
|
-
...(wpStyles.typography?.body_font_family && {
|
|
479
|
-
body: wpStyles.typography.body_font_family
|
|
480
|
-
}),
|
|
481
|
-
},
|
|
482
|
-
};
|
|
483
|
-
// Generate alternate and highlight colors from primary/background
|
|
484
|
-
if (tokens.colors.primary && tokens.colors.background) {
|
|
485
|
-
// Alternate: slightly darker/lighter than background
|
|
486
|
-
tokens.colors.alternate = adjustBrightness(tokens.colors.background, -0.05);
|
|
487
|
-
// Highlight: tinted with primary color
|
|
488
|
-
tokens.colors.highlight = blendColors(tokens.colors.background, tokens.colors.primary, 0.1);
|
|
489
|
-
}
|
|
490
|
-
return tokens;
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Adjust brightness of a hex color
|
|
494
|
-
*/
|
|
495
|
-
function adjustBrightness(hex, amount) {
|
|
496
|
-
const num = parseInt(hex.replace('#', ''), 16);
|
|
497
|
-
const r = Math.max(0, Math.min(255, ((num >> 16) & 0xff) + (amount * 255)));
|
|
498
|
-
const g = Math.max(0, Math.min(255, ((num >> 8) & 0xff) + (amount * 255)));
|
|
499
|
-
const b = Math.max(0, Math.min(255, (num & 0xff) + (amount * 255)));
|
|
500
|
-
return `#${((r << 16) | (g << 8) | b).toString(16).padStart(6, '0')}`;
|
|
501
|
-
}
|
|
502
|
-
/**
|
|
503
|
-
* Blend two colors
|
|
504
|
-
*/
|
|
505
|
-
function blendColors(color1, color2, ratio) {
|
|
506
|
-
const c1 = hexToRgb(color1);
|
|
507
|
-
const c2 = hexToRgb(color2);
|
|
508
|
-
if (!c1 || !c2)
|
|
509
|
-
return color1;
|
|
510
|
-
const r = Math.round(c1.r + (c2.r - c1.r) * ratio);
|
|
511
|
-
const g = Math.round(c1.g + (c2.g - c1.g) * ratio);
|
|
512
|
-
const b = Math.round(c1.b + (c2.b - c1.b) * ratio);
|
|
513
|
-
return `rgb(${r}, ${g}, ${b})`;
|
|
514
|
-
}
|
|
515
|
-
function hexToRgb(hex) {
|
|
516
|
-
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
|
517
|
-
return result
|
|
518
|
-
? {
|
|
519
|
-
r: parseInt(result[1], 16),
|
|
520
|
-
g: parseInt(result[2], 16),
|
|
521
|
-
b: parseInt(result[3], 16),
|
|
522
|
-
}
|
|
523
|
-
: null;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* @license GPL-3.0-or-later
|
|
528
|
-
*
|
|
529
|
-
* This file is part of the MarVAlt Open SDK.
|
|
530
|
-
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
531
|
-
*/
|
|
532
|
-
/**
|
|
533
|
-
* Inject CSS variables from design tokens into the document
|
|
534
|
-
*/
|
|
535
|
-
function injectCSSVariables(tokens) {
|
|
536
|
-
if (typeof document === 'undefined')
|
|
537
|
-
return;
|
|
538
|
-
const root = document.documentElement;
|
|
539
|
-
// Colors
|
|
540
|
-
root.style.setProperty('--dstyler-color-primary', tokens.colors.primary);
|
|
541
|
-
root.style.setProperty('--dstyler-color-secondary', tokens.colors.secondary);
|
|
542
|
-
root.style.setProperty('--dstyler-color-background', tokens.colors.background);
|
|
543
|
-
root.style.setProperty('--dstyler-color-text', tokens.colors.text);
|
|
544
|
-
root.style.setProperty('--dstyler-color-default', tokens.colors.default);
|
|
545
|
-
root.style.setProperty('--dstyler-color-alternate', tokens.colors.alternate);
|
|
546
|
-
root.style.setProperty('--dstyler-color-highlight', tokens.colors.highlight);
|
|
547
|
-
// Spacing
|
|
548
|
-
root.style.setProperty('--dstyler-spacing-sm', `${tokens.spacing.sm}px`);
|
|
549
|
-
root.style.setProperty('--dstyler-spacing-md', `${tokens.spacing.md}px`);
|
|
550
|
-
root.style.setProperty('--dstyler-spacing-lg', `${tokens.spacing.lg}px`);
|
|
551
|
-
root.style.setProperty('--dstyler-spacing-xl', `${tokens.spacing.xl}px`);
|
|
552
|
-
// Typography
|
|
553
|
-
root.style.setProperty('--dstyler-font-body', tokens.typography.body);
|
|
554
|
-
root.style.setProperty('--dstyler-font-heading', tokens.typography.heading);
|
|
555
|
-
root.style.setProperty('--dstyler-font-scale', tokens.typography.scale.toString());
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
const ThemeProvider = ({ children, wpStyles }) => {
|
|
559
|
-
require$$0.useEffect(() => {
|
|
560
|
-
const tokens = convertWordPressToTokens(wpStyles);
|
|
561
|
-
injectCSSVariables(tokens);
|
|
562
|
-
}, [wpStyles]);
|
|
563
|
-
return jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: children });
|
|
564
|
-
};
|
|
565
|
-
|
|
566
585
|
/**
|
|
567
586
|
* @license GPL-3.0-or-later
|
|
568
587
|
*
|
|
@@ -929,6 +948,115 @@ const StyledPage = ({ page, registry }) => {
|
|
|
929
948
|
return (jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: styledSections.map((section) => (jsxRuntimeExports.jsx(AutoSection, { section: section, registry: registry }, section.id))) }));
|
|
930
949
|
};
|
|
931
950
|
|
|
951
|
+
/**
|
|
952
|
+
* @license GPL-3.0-or-later
|
|
953
|
+
*
|
|
954
|
+
* This file is part of the MarVAlt Open SDK.
|
|
955
|
+
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
956
|
+
*/
|
|
957
|
+
/**
|
|
958
|
+
* Responsive utility functions
|
|
959
|
+
*/
|
|
960
|
+
function getResponsiveValue(mobile, tablet, desktop) {
|
|
961
|
+
if (!tablet && !desktop) {
|
|
962
|
+
return typeof mobile === 'number' ? `${mobile}px` : mobile;
|
|
963
|
+
}
|
|
964
|
+
// For now, return mobile value
|
|
965
|
+
// In the future, this could use CSS custom properties with media queries
|
|
966
|
+
return typeof mobile === 'number' ? `${mobile}px` : mobile;
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
/**
|
|
970
|
+
* @license GPL-3.0-or-later
|
|
971
|
+
*
|
|
972
|
+
* This file is part of the MarVAlt Open SDK.
|
|
973
|
+
* Copyright (c) 2025 Vibune Pty Ltd.
|
|
974
|
+
*/
|
|
975
|
+
/**
|
|
976
|
+
* Create a colorMapper from design tokens
|
|
977
|
+
*
|
|
978
|
+
* This utility helps bridge dstyler design tokens with wparser's color mapping system.
|
|
979
|
+
* It generates a ColorMapper function that maps WordPress theme color names to CSS classes
|
|
980
|
+
* based on your design tokens.
|
|
981
|
+
*
|
|
982
|
+
* @param tokens - Design tokens containing color definitions
|
|
983
|
+
* @param overrides - Optional overrides for specific WordPress color names
|
|
984
|
+
* @returns A ColorMapper function compatible with wparser
|
|
985
|
+
*
|
|
986
|
+
* @example
|
|
987
|
+
* ```typescript
|
|
988
|
+
* import { createColorMapperFromTokens } from '@marvalt/dstyler';
|
|
989
|
+
* import { loadTheme } from '@/config/themes';
|
|
990
|
+
*
|
|
991
|
+
* const tokens = await loadTheme();
|
|
992
|
+
* const colorMapper = createColorMapperFromTokens(tokens, {
|
|
993
|
+
* 'accent-6': 'bg-[#4a90a4] text-white', // Custom override
|
|
994
|
+
* });
|
|
995
|
+
* ```
|
|
996
|
+
*/
|
|
997
|
+
function createColorMapperFromTokens(tokens, overrides) {
|
|
998
|
+
return (wpColorName) => {
|
|
999
|
+
// Use overrides first if provided
|
|
1000
|
+
if (wpColorName && overrides?.[wpColorName]) {
|
|
1001
|
+
return overrides[wpColorName];
|
|
1002
|
+
}
|
|
1003
|
+
// Map WordPress theme colors to design tokens
|
|
1004
|
+
// Using Tailwind's arbitrary value syntax for hex colors
|
|
1005
|
+
const defaultMap = {
|
|
1006
|
+
'base': `bg-[${tokens.colors.background}]`,
|
|
1007
|
+
'contrast': `bg-[${tokens.colors.text}] text-[${tokens.colors.background}]`,
|
|
1008
|
+
'transparent': 'bg-transparent',
|
|
1009
|
+
'accent-1': `bg-[${tokens.colors.primary}] text-white`,
|
|
1010
|
+
'accent-2': `bg-[${tokens.colors.secondary}] text-white`,
|
|
1011
|
+
'accent-3': `bg-[${tokens.colors.highlight}] text-[${tokens.colors.text}]`,
|
|
1012
|
+
'accent-4': `bg-[${tokens.colors.alternate}] text-[${tokens.colors.text}]`,
|
|
1013
|
+
'accent-5': `bg-[${tokens.colors.default}] text-[${tokens.colors.text}]`,
|
|
1014
|
+
'accent-6': `bg-[${tokens.colors.primary}] text-white`, // Fallback to primary if accent-6 not defined
|
|
1015
|
+
};
|
|
1016
|
+
return wpColorName ? defaultMap[wpColorName] || null : null;
|
|
1017
|
+
};
|
|
1018
|
+
}
|
|
1019
|
+
/**
|
|
1020
|
+
* Create a colorMapper with semantic Tailwind classes
|
|
1021
|
+
*
|
|
1022
|
+
* Alternative version that uses semantic Tailwind classes (bg-primary, bg-secondary, etc.)
|
|
1023
|
+
* instead of arbitrary values. Use this if your Tailwind config has these colors defined.
|
|
1024
|
+
*
|
|
1025
|
+
* @param tokens - Design tokens (used for reference, but classes are semantic)
|
|
1026
|
+
* @param overrides - Optional overrides for specific WordPress color names
|
|
1027
|
+
* @returns A ColorMapper function compatible with wparser
|
|
1028
|
+
*
|
|
1029
|
+
* @example
|
|
1030
|
+
* ```typescript
|
|
1031
|
+
* const colorMapper = createColorMapperWithSemanticClasses(tokens, {
|
|
1032
|
+
* 'accent-1': 'bg-primary text-primary-foreground',
|
|
1033
|
+
* 'accent-2': 'bg-secondary text-secondary-foreground',
|
|
1034
|
+
* });
|
|
1035
|
+
* ```
|
|
1036
|
+
*/
|
|
1037
|
+
function createColorMapperWithSemanticClasses(tokens, overrides) {
|
|
1038
|
+
return (wpColorName) => {
|
|
1039
|
+
// Use overrides first if provided
|
|
1040
|
+
if (wpColorName && overrides?.[wpColorName]) {
|
|
1041
|
+
return overrides[wpColorName];
|
|
1042
|
+
}
|
|
1043
|
+
// Map WordPress theme colors to semantic Tailwind classes
|
|
1044
|
+
// Assumes your Tailwind config has primary, secondary, muted, etc. defined
|
|
1045
|
+
const defaultMap = {
|
|
1046
|
+
'base': 'bg-white',
|
|
1047
|
+
'contrast': 'bg-gray-900 text-white',
|
|
1048
|
+
'transparent': 'bg-transparent',
|
|
1049
|
+
'accent-1': 'bg-primary text-primary-foreground',
|
|
1050
|
+
'accent-2': 'bg-secondary text-secondary-foreground',
|
|
1051
|
+
'accent-3': 'bg-muted text-muted-foreground',
|
|
1052
|
+
'accent-4': 'bg-gray-200 text-gray-900',
|
|
1053
|
+
'accent-5': 'bg-gray-100 text-gray-900',
|
|
1054
|
+
'accent-6': 'bg-primary text-primary-foreground', // Fallback
|
|
1055
|
+
};
|
|
1056
|
+
return wpColorName ? defaultMap[wpColorName] || null : null;
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
|
|
932
1060
|
exports.AutoBlock = AutoBlock;
|
|
933
1061
|
exports.AutoSection = AutoSection;
|
|
934
1062
|
exports.FooterMinimal = FooterMinimal;
|
|
@@ -938,9 +1066,12 @@ exports.SectionWave = SectionWave;
|
|
|
938
1066
|
exports.StyledPage = StyledPage;
|
|
939
1067
|
exports.ThemeProvider = ThemeProvider;
|
|
940
1068
|
exports.convertWordPressToTokens = convertWordPressToTokens;
|
|
1069
|
+
exports.createColorMapperFromTokens = createColorMapperFromTokens;
|
|
1070
|
+
exports.createColorMapperWithSemanticClasses = createColorMapperWithSemanticClasses;
|
|
941
1071
|
exports.defaultTokens = defaultTokens;
|
|
942
1072
|
exports.detectSections = detectSections;
|
|
943
1073
|
exports.determineSectionStyle = determineSectionStyle;
|
|
1074
|
+
exports.getResponsiveValue = getResponsiveValue;
|
|
944
1075
|
exports.injectCSSVariables = injectCSSVariables;
|
|
945
1076
|
exports.selectBlockRenderer = selectBlockRenderer;
|
|
946
1077
|
exports.selectTemplate = selectTemplate;
|