@times-design-system/components-wordpress 1.12.1 → 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.
Files changed (40) hide show
  1. package/dist/STYLE_HANDLES.md +1 -1
  2. package/dist/blocks/ad-container/style.css +1 -1
  3. package/dist/blocks/ad-container/style.scss +2 -2
  4. package/dist/blocks/button/init.js +1 -1
  5. package/dist/blocks/button/render.php +9 -9
  6. package/dist/blocks/button/style.css +1 -1
  7. package/dist/blocks/button/style.scss +33 -33
  8. package/dist/blocks/chip/render.php +2 -2
  9. package/dist/blocks/chip/style.css +1 -1
  10. package/dist/blocks/chip/style.scss +74 -74
  11. package/dist/blocks/dialog-box/style.css +1 -1
  12. package/dist/blocks/dialog-box/style.scss +7 -6
  13. package/dist/blocks/divider/style.css +1 -1
  14. package/dist/blocks/divider/style.scss +2 -2
  15. package/dist/blocks/icon/style.scss +1 -1
  16. package/dist/blocks/icon-button/render.php +2 -2
  17. package/dist/blocks/icon-button/style.css +1 -1
  18. package/dist/blocks/icon-button/style.scss +33 -33
  19. package/dist/blocks/input/style.css +1 -1
  20. package/dist/blocks/input/style.scss +15 -14
  21. package/dist/blocks/input-helper-message/style.css +1 -1
  22. package/dist/blocks/input-helper-message/style.scss +6 -6
  23. package/dist/blocks/link/render.php +2 -2
  24. package/dist/blocks/link/style.css +1 -1
  25. package/dist/blocks/link/style.scss +19 -19
  26. package/dist/blocks/tab/style.css +1 -1
  27. package/dist/blocks/tab/style.scss +16 -16
  28. package/dist/blocks/tab-group/style.css +1 -1
  29. package/dist/blocks/tab-group/style.scss +3 -2
  30. package/dist/blocks/tag/render.php +2 -2
  31. package/dist/blocks/tag/style.css +1 -1
  32. package/dist/blocks/tag/style.scss +18 -18
  33. package/dist/blocks/text/style.scss +1 -1
  34. package/dist/blocks/toast/style.css +1 -1
  35. package/dist/blocks/toast/style.scss +13 -13
  36. package/dist/icon-data.json +1 -1
  37. package/dist/index.css +1 -1
  38. package/dist/index.css.map +1 -1
  39. package/dist/utils/render-icon.php +239 -103
  40. package/package.json +3 -3
@@ -15,15 +15,17 @@
15
15
  *
16
16
  * @var array
17
17
  */
18
- const ICON_SIZE_MAP = [
19
- '2xsmall' => ['width' => 12, 'height' => 12],
20
- 'xsmall' => ['width' => 16, 'height' => 16],
21
- 'small' => ['width' => 20, 'height' => 20],
22
- 'medium' => ['width' => 24, 'height' => 24],
23
- 'large' => ['width' => 28, 'height' => 28],
24
- 'xlarge' => ['width' => 32, 'height' => 32],
25
- '2xlarge' => ['width' => 40, 'height' => 40],
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
- function tds_load_icon_data() {
36
- static $icon_data = null;
37
+ if (!function_exists('tds_load_icon_data')) {
38
+ function tds_load_icon_data() {
39
+ static $icon_data = null;
37
40
 
38
- if ($icon_data !== null) {
39
- return $icon_data;
40
- }
41
+ if ($icon_data !== null) {
42
+ return $icon_data;
43
+ }
41
44
 
42
- $plugin_dir = dirname(dirname(__DIR__));
43
- $icon_data_path = $plugin_dir . '/dist/icon-data.json';
45
+ $plugin_dir = dirname(dirname(__DIR__));
46
+ $icon_data_path = $plugin_dir . '/dist/icon-data.json';
44
47
 
45
- if (!file_exists($icon_data_path)) {
46
- // If icon data hasn't been extracted yet, log a warning and return false
47
- // This is normal during first install or if build hasn't been run
48
- return false;
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
- $json_content = file_get_contents($icon_data_path);
52
- $icon_data = json_decode($json_content, true);
54
+ $json_content = file_get_contents($icon_data_path);
55
+ $icon_data = json_decode($json_content, true);
53
56
 
54
- return $icon_data ?: false;
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
- function tds_get_icon_svg($icon_name) {
69
- if (empty($icon_name)) {
70
- return false;
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
- $icon_data = tds_load_icon_data();
74
- if (!$icon_data || !isset($icon_data['icons'])) {
75
- return false;
76
- }
75
+ $icon_data = tds_load_icon_data();
76
+ if (!$icon_data || !isset($icon_data['icons'])) {
77
+ return false;
78
+ }
77
79
 
78
- // Sanitize the icon name (includes variant prefix)
79
- $icon_name = sanitize_key($icon_name);
80
-
81
- // Look up icon directly (icon name already includes variant)
82
- if (isset($icon_data['icons'][$icon_name])) {
83
- return $icon_data['icons'][$icon_name];
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
- function tds_render_icon($icon_name, $size_name = 'medium', $class = '') {
100
- if (empty($icon_name)) {
101
- return '';
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
- $svg_content = tds_get_icon_svg($icon_name);
105
- if (!$svg_content) {
106
- // Icon not found - log debug info if WP_DEBUG is enabled
107
- if (defined('WP_DEBUG') && WP_DEBUG) {
108
- error_log("Icon not found: {$variant}-{$icon_name}");
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
- // Get dimensions for the size
114
- $size_name = sanitize_key($size_name ?? 'medium');
115
- $dimensions = ICON_SIZE_MAP[$size_name] ?? ICON_SIZE_MAP['medium'];
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
- // Parse SVG to add width/height attributes
118
- $svg_content = tds_inject_svg_dimensions($svg_content, $dimensions['width'], $dimensions['height'], $class);
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
- return $svg_content;
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
- function tds_inject_svg_dimensions($svg, $width, $height, $class = '') {
136
- // Remove or replace existing width/height attributes, then add the correct ones
137
- // Match width="...", width='...' or width=... patterns and replace with new value
138
- $svg = preg_replace('/width="[^"]*"/', sprintf('width="%d"', $width), $svg);
139
- $svg = preg_replace('/width=\'[^\']*\'/', sprintf('width="%d"', $width), $svg);
140
-
141
- // Same for height
142
- $svg = preg_replace('/height="[^"]*"/', sprintf('height="%d"', $height), $svg);
143
- $svg = preg_replace('/height=\'[^\']*\'/', sprintf('height="%d"', $height), $svg);
144
-
145
- // If SVG still doesn't have width/height (fallback for edge cases), inject them
146
- if (strpos($svg, 'width=') === false || strpos($svg, 'height=') === false) {
147
- $svg = str_replace('<svg', sprintf('<svg width="%d" height="%d"', $width, $height), $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
+ }
155
+
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);
149
167
 
150
- // Replace fill attributes with currentcolor
151
- $svg = preg_replace('/fill="[^"]*"/i', 'fill="currentcolor"', $svg);
152
-
153
- // Replace stroke attributes with currentcolor
154
- $svg = preg_replace('/stroke="[^"]*"/i', 'stroke="currentcolor"', $svg);
155
-
156
- // Handle fill in style attributes: style="fill: #xxx" or style="...fill: #xxx..."
157
- $svg = preg_replace('/style="([^"]*)fill:\s*[^;}"]+/i', 'style="$1fill: currentcolor', $svg);
158
-
159
- // Handle stroke in style attributes: style="stroke: #xxx" or style="...stroke: #xxx..."
160
- $svg = preg_replace('/style="([^"]*)stroke:\s*[^;}"]+/i', 'style="$1stroke: currentcolor', $svg);
161
-
162
- // Add class if provided
163
- if (!empty($class)) {
164
- $class_attr = sanitize_html_class($class);
165
- if (preg_match('/class="([^"]*)"/', $svg, $matches)) {
166
- // Class already exists, append to it
167
- $existing_class = $matches[1];
168
- $svg = str_replace(
169
- sprintf('class="%s"', $existing_class),
170
- sprintf('class="%s %s"', $existing_class, $class_attr),
171
- $svg
172
- );
173
- } else {
174
- // No class attribute, add one
175
- $svg = str_replace('<svg', sprintf('<svg class="%s"', $class_attr), $svg);
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
- return $svg;
185
+ return $svg;
186
+ }
180
187
  }
181
188
 
182
189
  /**
@@ -213,6 +220,135 @@ function tds_render_icon_wrapper($icon_name, $size_name = 'medium', $position =
213
220
  return sprintf(
214
221
  '<span class="%s">%s</span>',
215
222
  esc_attr($wrapper_class),
216
- wp_kses_post($svg)
223
+ tds_kses_svg($svg)
224
+ );
225
+ }
226
+
227
+ /**
228
+ * Sanitize SVG content safely for output in HTML
229
+ *
230
+ * WordPress's wp_kses_post() strips SVG tags by default.
231
+ * This function allows SVG tags and common attributes while maintaining security.
232
+ *
233
+ * @param string $svg SVG HTML string to sanitize
234
+ * @return string Sanitized SVG safe for output
235
+ */
236
+ if (!function_exists('tds_kses_svg')) {
237
+ function tds_kses_svg($svg) {
238
+ if (empty($svg)) {
239
+ return '';
240
+ }
241
+
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
+ ),
254
+ 'g' => array(
255
+ 'class' => true,
256
+ 'id' => true,
257
+ 'style' => true,
258
+ 'fill' => true,
259
+ 'stroke' => true,
260
+ 'transform' => true,
261
+ ),
262
+ 'path' => array(
263
+ 'class' => true,
264
+ 'id' => true,
265
+ 'd' => true,
266
+ 'fill' => true,
267
+ 'stroke' => true,
268
+ 'stroke-width' => true,
269
+ 'stroke-linecap' => true,
270
+ 'stroke-linejoin' => true,
271
+ 'style' => true,
272
+ 'transform' => true,
273
+ 'data-*' => true,
274
+ ),
275
+ 'circle' => array(
276
+ 'class' => true,
277
+ 'cx' => true,
278
+ 'cy' => true,
279
+ 'r' => true,
280
+ 'fill' => true,
281
+ 'stroke' => true,
282
+ 'style' => true,
283
+ ),
284
+ 'rect' => array(
285
+ 'class' => true,
286
+ 'x' => true,
287
+ 'y' => true,
288
+ 'width' => true,
289
+ 'height' => true,
290
+ 'fill' => true,
291
+ 'stroke' => true,
292
+ 'style' => true,
293
+ 'rx' => true,
294
+ 'ry' => true,
295
+ ),
296
+ 'polygon' => array(
297
+ 'class' => true,
298
+ 'points' => true,
299
+ 'fill' => true,
300
+ 'stroke' => true,
301
+ 'style' => true,
302
+ ),
303
+ 'polyline' => array(
304
+ 'class' => true,
305
+ 'points' => true,
306
+ 'fill' => true,
307
+ 'stroke' => true,
308
+ 'style' => true,
309
+ ),
310
+ 'line' => array(
311
+ 'class' => true,
312
+ 'x1' => true,
313
+ 'y1' => true,
314
+ 'x2' => true,
315
+ 'y2' => true,
316
+ 'stroke' => true,
317
+ 'stroke-width' => true,
318
+ 'style' => true,
319
+ ),
320
+ 'text' => array(
321
+ 'class' => true,
322
+ 'x' => true,
323
+ 'y' => true,
324
+ 'fill' => true,
325
+ 'style' => true,
326
+ 'text-anchor' => true,
327
+ ),
328
+ 'tspan' => array(
329
+ 'class' => true,
330
+ 'x' => true,
331
+ 'y' => true,
332
+ 'dx' => true,
333
+ 'dy' => true,
334
+ 'fill' => true,
335
+ 'style' => true,
336
+ ),
337
+ 'defs' => array(),
338
+ 'style' => array(
339
+ 'type' => true,
340
+ ),
341
+ 'use' => array(
342
+ 'href' => true,
343
+ 'xlink:href' => true,
344
+ 'x' => true,
345
+ 'y' => true,
346
+ 'width' => true,
347
+ 'height' => true,
348
+ 'class' => true,
349
+ ),
217
350
  );
351
+
352
+ return wp_kses($svg, $allowed_tags);
353
+ }
218
354
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@times-design-system/components-wordpress",
3
- "version": "1.12.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.8.0",
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": "9e5bbc79ba162448c3ba5e3434533e50645d9b2c"
104
+ "gitHead": "4546787f4cf8edb08cd9f63f6905b6e2182edda8"
105
105
  }