@troychaplin/component2block 0.1.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/LICENSE +21 -0
- package/README.md +160 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +89 -0
- package/dist/cli.js.map +1 -0
- package/dist/config.d.ts +38 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +256 -0
- package/dist/config.js.map +1 -0
- package/dist/generators/content-scss.d.ts +3 -0
- package/dist/generators/content-scss.d.ts.map +1 -0
- package/dist/generators/content-scss.js +207 -0
- package/dist/generators/content-scss.js.map +1 -0
- package/dist/generators/fluid.d.ts +7 -0
- package/dist/generators/fluid.d.ts.map +1 -0
- package/dist/generators/fluid.js +31 -0
- package/dist/generators/fluid.js.map +1 -0
- package/dist/generators/fonts-css.d.ts +3 -0
- package/dist/generators/fonts-css.d.ts.map +1 -0
- package/dist/generators/fonts-css.js +33 -0
- package/dist/generators/fonts-css.js.map +1 -0
- package/dist/generators/integrate-php.d.ts +2 -0
- package/dist/generators/integrate-php.d.ts.map +1 -0
- package/dist/generators/integrate-php.js +9 -0
- package/dist/generators/integrate-php.js.map +1 -0
- package/dist/generators/theme-json.d.ts +3 -0
- package/dist/generators/theme-json.d.ts.map +1 -0
- package/dist/generators/theme-json.js +245 -0
- package/dist/generators/theme-json.js.map +1 -0
- package/dist/generators/tokens-css.d.ts +3 -0
- package/dist/generators/tokens-css.d.ts.map +1 -0
- package/dist/generators/tokens-css.js +32 -0
- package/dist/generators/tokens-css.js.map +1 -0
- package/dist/generators/tokens-wp-css.d.ts +3 -0
- package/dist/generators/tokens-wp-css.d.ts.map +1 -0
- package/dist/generators/tokens-wp-css.js +37 -0
- package/dist/generators/tokens-wp-css.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/preset.d.ts +13 -0
- package/dist/preset.d.ts.map +1 -0
- package/dist/preset.js +31 -0
- package/dist/preset.js.map +1 -0
- package/dist/types.d.ts +166 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +123 -0
- package/dist/types.js.map +1 -0
- package/package.json +58 -0
- package/templates/integrate.php.tpl +133 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
/**
|
|
3
|
+
* Component Library WordPress Integration
|
|
4
|
+
*
|
|
5
|
+
* Loads the library's theme.json as a default base layer and enqueues
|
|
6
|
+
* design token CSS variables. Automatically loads tokens.wp.css
|
|
7
|
+
* (themeable) if present, otherwise falls back to tokens.css (locked).
|
|
8
|
+
*
|
|
9
|
+
* Setup:
|
|
10
|
+
* 1. Copy this file, theme.json, and your token CSS file into your theme
|
|
11
|
+
* (e.g. assets/c2b/)
|
|
12
|
+
* 2. Add to your theme's functions.php:
|
|
13
|
+
* require_once get_template_directory() . '/assets/c2b/integrate.php';
|
|
14
|
+
*
|
|
15
|
+
* @package component2block
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
if ( ! defined( 'ABSPATH' ) ) {
|
|
19
|
+
exit;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Inject the library's theme.json as a WordPress default base layer.
|
|
24
|
+
*
|
|
25
|
+
* This registers design tokens (colors, spacing, fonts, etc.) as
|
|
26
|
+
* WordPress presets. The active theme's theme.json overrides any
|
|
27
|
+
* values defined here.
|
|
28
|
+
*/
|
|
29
|
+
add_filter( 'wp_theme_json_data_default', function ( $theme_json ) {
|
|
30
|
+
$library_json_path = __DIR__ . '/theme.json';
|
|
31
|
+
|
|
32
|
+
if ( ! file_exists( $library_json_path ) ) {
|
|
33
|
+
return $theme_json;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
$library_data = json_decode(
|
|
37
|
+
file_get_contents( $library_json_path ),
|
|
38
|
+
true
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
if ( ! is_array( $library_data ) ) {
|
|
42
|
+
return $theme_json;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return $theme_json->update_with( $library_data );
|
|
46
|
+
} );
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Enqueue design token CSS variables.
|
|
50
|
+
*
|
|
51
|
+
* Prefers tokens.wp.css (themeable — maps to --wp--preset--* variables)
|
|
52
|
+
* over tokens.css (locked — hardcoded values). Both are looked for in
|
|
53
|
+
* the same directory as this file.
|
|
54
|
+
*
|
|
55
|
+
* Loads on both the frontend and inside the block editor iframe.
|
|
56
|
+
*/
|
|
57
|
+
$c2b_enqueue_tokens = function () {
|
|
58
|
+
if ( file_exists( __DIR__ . '/tokens.wp.css' ) ) {
|
|
59
|
+
$file = 'tokens.wp.css';
|
|
60
|
+
} elseif ( file_exists( __DIR__ . '/tokens.css' ) ) {
|
|
61
|
+
$file = 'tokens.css';
|
|
62
|
+
} else {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
$base_url = content_url(
|
|
67
|
+
str_replace(
|
|
68
|
+
wp_normalize_path( WP_CONTENT_DIR ),
|
|
69
|
+
'',
|
|
70
|
+
wp_normalize_path( __DIR__ )
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
wp_enqueue_style(
|
|
75
|
+
'c2b-tokens',
|
|
76
|
+
$base_url . '/' . $file,
|
|
77
|
+
array(),
|
|
78
|
+
filemtime( __DIR__ . '/' . $file )
|
|
79
|
+
);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
add_action( 'wp_enqueue_scripts', $c2b_enqueue_tokens );
|
|
83
|
+
add_action( 'enqueue_block_editor_assets', $c2b_enqueue_tokens );
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Locked mode enforcement.
|
|
87
|
+
*
|
|
88
|
+
* When the library was built with wpThemeable: false (detected by the
|
|
89
|
+
* absence of tokens.wp.css), enforce design system restrictions at the
|
|
90
|
+
* theme layer so the theme's theme.json cannot override them:
|
|
91
|
+
*
|
|
92
|
+
* - Layout sizes (contentSize, wideSize) are locked
|
|
93
|
+
* - Custom color/gradient creation is disabled in the Site Editor
|
|
94
|
+
*
|
|
95
|
+
* When wpThemeable: true (tokens.wp.css exists), none of these
|
|
96
|
+
* restrictions apply — the theme has full control.
|
|
97
|
+
*/
|
|
98
|
+
if ( ! file_exists( __DIR__ . '/tokens.wp.css' ) ) {
|
|
99
|
+
add_filter( 'wp_theme_json_data_theme', function ( $theme_json ) {
|
|
100
|
+
$library_json_path = __DIR__ . '/theme.json';
|
|
101
|
+
|
|
102
|
+
if ( ! file_exists( $library_json_path ) ) {
|
|
103
|
+
return $theme_json;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
$library_data = json_decode(
|
|
107
|
+
file_get_contents( $library_json_path ),
|
|
108
|
+
true
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
if ( ! is_array( $library_data ) ) {
|
|
112
|
+
return $theme_json;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
$enforced = array(
|
|
116
|
+
'version' => $library_data['version'] ?? 3,
|
|
117
|
+
'settings' => array(
|
|
118
|
+
'color' => array(
|
|
119
|
+
'custom' => false,
|
|
120
|
+
'customDuotone' => false,
|
|
121
|
+
'customGradient' => false,
|
|
122
|
+
),
|
|
123
|
+
),
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
// Lock layout sizes if defined
|
|
127
|
+
if ( isset( $library_data['settings']['layout'] ) ) {
|
|
128
|
+
$enforced['settings']['layout'] = $library_data['settings']['layout'];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return $theme_json->update_with( $enforced );
|
|
132
|
+
} );
|
|
133
|
+
}
|