@times-design-system/components-wordpress 1.13.0 → 1.14.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/STYLE_HANDLES.md +1 -1
- package/dist/blocks/ad-container/style.css +1 -1
- package/dist/blocks/ad-container/style.scss +2 -2
- package/dist/blocks/button/init.js +1 -1
- package/dist/blocks/button/style.css +1 -1
- package/dist/blocks/button/style.scss +33 -33
- package/dist/blocks/chip/style.css +1 -1
- package/dist/blocks/chip/style.scss +74 -74
- package/dist/blocks/dialog-box/style.css +1 -1
- package/dist/blocks/dialog-box/style.scss +7 -6
- package/dist/blocks/divider/style.css +1 -1
- package/dist/blocks/divider/style.scss +2 -2
- package/dist/blocks/icon/style.scss +1 -1
- package/dist/blocks/icon-button/render.php +2 -2
- package/dist/blocks/icon-button/style.css +1 -1
- package/dist/blocks/icon-button/style.scss +33 -33
- package/dist/blocks/input/style.css +1 -1
- package/dist/blocks/input/style.scss +15 -14
- package/dist/blocks/input-helper-message/style.css +1 -1
- package/dist/blocks/input-helper-message/style.scss +6 -6
- package/dist/blocks/link/style.css +1 -1
- package/dist/blocks/link/style.scss +19 -19
- package/dist/blocks/tab/style.css +1 -1
- package/dist/blocks/tab/style.scss +16 -16
- package/dist/blocks/tab-group/style.css +1 -1
- package/dist/blocks/tab-group/style.scss +3 -2
- package/dist/blocks/tag/style.css +1 -1
- package/dist/blocks/tag/style.scss +18 -18
- package/dist/blocks/text/style.scss +1 -1
- package/dist/blocks/toast/style.css +1 -1
- package/dist/blocks/toast/style.scss +13 -13
- package/dist/icon-data.json +1 -1
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/utils/render-icon.php +126 -117
- package/package.json +3 -3
|
@@ -15,15 +15,17 @@
|
|
|
15
15
|
*
|
|
16
16
|
* @var array
|
|
17
17
|
*/
|
|
18
|
-
|
|
19
|
-
'
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
]
|
|
18
|
+
if (!defined('ICON_SIZE_MAP')) {
|
|
19
|
+
define('ICON_SIZE_MAP', [
|
|
20
|
+
'2xsmall' => ['width' => 12, 'height' => 12],
|
|
21
|
+
'xsmall' => ['width' => 16, 'height' => 16],
|
|
22
|
+
'small' => ['width' => 20, 'height' => 20],
|
|
23
|
+
'medium' => ['width' => 24, 'height' => 24],
|
|
24
|
+
'large' => ['width' => 28, 'height' => 28],
|
|
25
|
+
'xlarge' => ['width' => 32, 'height' => 32],
|
|
26
|
+
'2xlarge' => ['width' => 40, 'height' => 40],
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* Load icon data from JSON file
|
|
@@ -32,31 +34,30 @@ const ICON_SIZE_MAP = [
|
|
|
32
34
|
*
|
|
33
35
|
* @return array|false Icon data array with 'icons' key, or false on failure
|
|
34
36
|
*/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
+
if (!function_exists('tds_load_icon_data')) {
|
|
38
|
+
function tds_load_icon_data() {
|
|
39
|
+
static $icon_data = null;
|
|
37
40
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
if ($icon_data !== null) {
|
|
42
|
+
return $icon_data;
|
|
43
|
+
}
|
|
41
44
|
|
|
42
|
-
|
|
43
|
-
|
|
45
|
+
$plugin_dir = dirname(dirname(__DIR__));
|
|
46
|
+
$icon_data_path = $plugin_dir . '/dist/icon-data.json';
|
|
44
47
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
if (!file_exists($icon_data_path)) {
|
|
49
|
+
// If icon data hasn't been extracted yet, log a warning and return false
|
|
50
|
+
// This is normal during first install or if build hasn't been run
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
$json_content = file_get_contents($icon_data_path);
|
|
55
|
+
$icon_data = json_decode($json_content, true);
|
|
53
56
|
|
|
54
|
-
|
|
57
|
+
return $icon_data ?: false;
|
|
58
|
+
}
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
/**
|
|
58
|
-
* Get icon SVG by name and optional variant
|
|
59
|
-
*
|
|
60
61
|
/**
|
|
61
62
|
* Get icon SVG content from icon data store
|
|
62
63
|
*
|
|
@@ -65,25 +66,27 @@ function tds_load_icon_data() {
|
|
|
65
66
|
* @param string $icon_name Icon name with variant (e.g., 'filled_arrow_left', 'outlined_check')
|
|
66
67
|
* @return string|false SVG content or false if not found
|
|
67
68
|
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
if (!function_exists('tds_get_icon_svg')) {
|
|
70
|
+
function tds_get_icon_svg($icon_name) {
|
|
71
|
+
if (empty($icon_name)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
72
74
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
$icon_data = tds_load_icon_data();
|
|
76
|
+
if (!$icon_data || !isset($icon_data['icons'])) {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
77
79
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
// Sanitize the icon name (includes variant prefix)
|
|
81
|
+
$icon_name = sanitize_key($icon_name);
|
|
82
|
+
|
|
83
|
+
// Look up icon directly (icon name already includes variant)
|
|
84
|
+
if (isset($icon_data['icons'][$icon_name])) {
|
|
85
|
+
return $icon_data['icons'][$icon_name];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return false;
|
|
84
89
|
}
|
|
85
|
-
|
|
86
|
-
return false;
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
/**
|
|
@@ -96,28 +99,30 @@ function tds_get_icon_svg($icon_name) {
|
|
|
96
99
|
* @param string $class Optional CSS class to add to the SVG
|
|
97
100
|
* @return string HTML SVG string or empty string if icon not found
|
|
98
101
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
if (!function_exists('tds_render_icon')) {
|
|
103
|
+
function tds_render_icon($icon_name, $size_name = 'medium', $class = '') {
|
|
104
|
+
if (empty($icon_name)) {
|
|
105
|
+
return '';
|
|
106
|
+
}
|
|
103
107
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
$svg_content = tds_get_icon_svg($icon_name);
|
|
109
|
+
if (!$svg_content) {
|
|
110
|
+
// Icon not found - log debug info if WP_DEBUG is enabled
|
|
111
|
+
if (defined('WP_DEBUG') && WP_DEBUG) {
|
|
112
|
+
error_log("Icon not found: {$variant}-{$icon_name}");
|
|
113
|
+
}
|
|
114
|
+
return '';
|
|
109
115
|
}
|
|
110
|
-
return '';
|
|
111
|
-
}
|
|
112
116
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
// Get dimensions for the size
|
|
118
|
+
$size_name = sanitize_key($size_name ?? 'medium');
|
|
119
|
+
$dimensions = ICON_SIZE_MAP[$size_name] ?? ICON_SIZE_MAP['medium'];
|
|
116
120
|
|
|
117
|
-
|
|
118
|
-
|
|
121
|
+
// Parse SVG to add width/height attributes
|
|
122
|
+
$svg_content = tds_inject_svg_dimensions($svg_content, $dimensions['width'], $dimensions['height'], $class);
|
|
119
123
|
|
|
120
|
-
|
|
124
|
+
return $svg_content;
|
|
125
|
+
}
|
|
121
126
|
}
|
|
122
127
|
|
|
123
128
|
/**
|
|
@@ -132,51 +137,53 @@ function tds_render_icon($icon_name, $size_name = 'medium', $class = '') {
|
|
|
132
137
|
* @param string $class Optional CSS class
|
|
133
138
|
* @return string Modified SVG
|
|
134
139
|
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
$svg =
|
|
148
|
-
|
|
140
|
+
if (!function_exists('tds_inject_svg_dimensions')) {
|
|
141
|
+
function tds_inject_svg_dimensions($svg, $width, $height, $class = '') {
|
|
142
|
+
// Remove or replace existing width/height attributes, then add the correct ones
|
|
143
|
+
// Match width="...", width='...' or width=... patterns and replace with new value
|
|
144
|
+
$svg = preg_replace('/width="[^"]*"/', sprintf('width="%d"', $width), $svg);
|
|
145
|
+
$svg = preg_replace('/width=\'[^\']*\'/', sprintf('width="%d"', $width), $svg);
|
|
146
|
+
|
|
147
|
+
// Same for height
|
|
148
|
+
$svg = preg_replace('/height="[^"]*"/', sprintf('height="%d"', $height), $svg);
|
|
149
|
+
$svg = preg_replace('/height=\'[^\']*\'/', sprintf('height="%d"', $height), $svg);
|
|
150
|
+
|
|
151
|
+
// If SVG still doesn't have width/height (fallback for edge cases), inject them
|
|
152
|
+
if (strpos($svg, 'width=') === false || strpos($svg, 'height=') === false) {
|
|
153
|
+
$svg = str_replace('<svg', sprintf('<svg width="%d" height="%d"', $width, $height), $svg);
|
|
154
|
+
}
|
|
149
155
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
156
|
+
// Replace fill attributes with currentcolor
|
|
157
|
+
$svg = preg_replace('/fill="[^"]*"/i', 'fill="currentcolor"', $svg);
|
|
158
|
+
|
|
159
|
+
// Replace stroke attributes with currentcolor
|
|
160
|
+
$svg = preg_replace('/stroke="[^"]*"/i', 'stroke="currentcolor"', $svg);
|
|
161
|
+
|
|
162
|
+
// Handle fill in style attributes: style="fill: #xxx" or style="...fill: #xxx..."
|
|
163
|
+
$svg = preg_replace('/style="([^"]*)fill:\s*[^;}"]+/i', 'style="$1fill: currentcolor', $svg);
|
|
164
|
+
|
|
165
|
+
// Handle stroke in style attributes: style="stroke: #xxx" or style="...stroke: #xxx..."
|
|
166
|
+
$svg = preg_replace('/style="([^"]*)stroke:\s*[^;}"]+/i', 'style="$1stroke: currentcolor', $svg);
|
|
161
167
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
168
|
+
// Add class if provided
|
|
169
|
+
if (!empty($class)) {
|
|
170
|
+
$class_attr = sanitize_html_class($class);
|
|
171
|
+
if (preg_match('/class="([^"]*)"/', $svg, $matches)) {
|
|
172
|
+
// Class already exists, append to it
|
|
173
|
+
$existing_class = $matches[1];
|
|
174
|
+
$svg = str_replace(
|
|
175
|
+
sprintf('class="%s"', $existing_class),
|
|
176
|
+
sprintf('class="%s %s"', $existing_class, $class_attr),
|
|
177
|
+
$svg
|
|
178
|
+
);
|
|
179
|
+
} else {
|
|
180
|
+
// No class attribute, add one
|
|
181
|
+
$svg = str_replace('<svg', sprintf('<svg class="%s"', $class_attr), $svg);
|
|
182
|
+
}
|
|
176
183
|
}
|
|
177
|
-
}
|
|
178
184
|
|
|
179
|
-
|
|
185
|
+
return $svg;
|
|
186
|
+
}
|
|
180
187
|
}
|
|
181
188
|
|
|
182
189
|
/**
|
|
@@ -226,23 +233,24 @@ function tds_render_icon_wrapper($icon_name, $size_name = 'medium', $position =
|
|
|
226
233
|
* @param string $svg SVG HTML string to sanitize
|
|
227
234
|
* @return string Sanitized SVG safe for output
|
|
228
235
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
236
|
+
if (!function_exists('tds_kses_svg')) {
|
|
237
|
+
function tds_kses_svg($svg) {
|
|
238
|
+
if (empty($svg)) {
|
|
239
|
+
return '';
|
|
240
|
+
}
|
|
233
241
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
$allowed_tags = array(
|
|
243
|
+
'svg' => array(
|
|
244
|
+
'xmlns' => true,
|
|
245
|
+
'viewBox' => true,
|
|
246
|
+
'width' => true,
|
|
247
|
+
'height' => true,
|
|
248
|
+
'class' => true,
|
|
249
|
+
'style' => true,
|
|
250
|
+
'aria-hidden' => true,
|
|
251
|
+
'role' => true,
|
|
252
|
+
'data-*' => true,
|
|
253
|
+
),
|
|
246
254
|
'g' => array(
|
|
247
255
|
'class' => true,
|
|
248
256
|
'id' => true,
|
|
@@ -342,4 +350,5 @@ function tds_kses_svg($svg) {
|
|
|
342
350
|
);
|
|
343
351
|
|
|
344
352
|
return wp_kses($svg, $allowed_tags);
|
|
353
|
+
}
|
|
345
354
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@times-design-system/components-wordpress",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Times Design System Gutenberg blocks for WordPress Full Site Editing",
|
|
6
6
|
"keywords": [
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@times-design-system/theme-scss": "^2.
|
|
73
|
+
"@times-design-system/theme-scss": "^2.9.0",
|
|
74
74
|
"@wordpress/block-editor": "^12.0.0",
|
|
75
75
|
"@wordpress/blocks": "^12.0.0",
|
|
76
76
|
"@wordpress/components": "^25.0.0",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"typescript": "^5.0.0",
|
|
102
102
|
"vitest": "^1.0.4"
|
|
103
103
|
},
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "4546787f4cf8edb08cd9f63f6905b6e2182edda8"
|
|
105
105
|
}
|