bitwrench 2.0.16 → 2.0.18
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 +127 -38
- package/dist/bitwrench-bccl.cjs.js +13 -9
- package/dist/bitwrench-bccl.cjs.min.js +2 -2
- package/dist/bitwrench-bccl.esm.js +13 -9
- package/dist/bitwrench-bccl.esm.min.js +2 -2
- package/dist/bitwrench-bccl.umd.js +13 -9
- package/dist/bitwrench-bccl.umd.min.js +2 -2
- package/dist/bitwrench-code-edit.cjs.js +1 -1
- package/dist/bitwrench-code-edit.cjs.min.js +1 -1
- package/dist/bitwrench-code-edit.es5.js +1 -1
- package/dist/bitwrench-code-edit.es5.min.js +1 -1
- package/dist/bitwrench-code-edit.esm.js +1 -1
- package/dist/bitwrench-code-edit.esm.min.js +1 -1
- package/dist/bitwrench-code-edit.umd.js +1 -1
- package/dist/bitwrench-code-edit.umd.min.js +1 -1
- package/dist/bitwrench-lean.cjs.js +1438 -920
- package/dist/bitwrench-lean.cjs.min.js +20 -20
- package/dist/bitwrench-lean.es5.js +1518 -1105
- package/dist/bitwrench-lean.es5.min.js +18 -18
- package/dist/bitwrench-lean.esm.js +1437 -920
- package/dist/bitwrench-lean.esm.min.js +20 -20
- package/dist/bitwrench-lean.umd.js +1438 -920
- package/dist/bitwrench-lean.umd.min.js +20 -20
- package/dist/bitwrench-util-css.cjs.js +236 -0
- package/dist/bitwrench-util-css.cjs.min.js +22 -0
- package/dist/bitwrench-util-css.es5.js +414 -0
- package/dist/bitwrench-util-css.es5.min.js +21 -0
- package/dist/bitwrench-util-css.esm.js +230 -0
- package/dist/bitwrench-util-css.esm.min.js +21 -0
- package/dist/bitwrench-util-css.umd.js +242 -0
- package/dist/bitwrench-util-css.umd.min.js +21 -0
- package/dist/bitwrench.cjs.js +1450 -928
- package/dist/bitwrench.cjs.min.js +21 -21
- package/dist/bitwrench.css +456 -132
- package/dist/bitwrench.es5.js +1563 -1140
- package/dist/bitwrench.es5.min.js +19 -19
- package/dist/bitwrench.esm.js +1450 -929
- package/dist/bitwrench.esm.min.js +21 -21
- package/dist/bitwrench.min.css +1 -1
- package/dist/bitwrench.umd.js +1450 -928
- package/dist/bitwrench.umd.min.js +21 -21
- package/dist/builds.json +178 -90
- package/dist/bwserve.cjs.js +528 -68
- package/dist/bwserve.esm.js +527 -69
- package/dist/sri.json +44 -36
- package/package.json +5 -2
- package/readme.html +136 -49
- package/src/bitwrench-bccl.js +12 -8
- package/src/bitwrench-color-utils.js +31 -9
- package/src/bitwrench-esm-entry.js +11 -0
- package/src/bitwrench-styles.js +439 -232
- package/src/bitwrench-util-css.js +229 -0
- package/src/bitwrench.js +979 -630
- package/src/bwserve/attach.js +57 -0
- package/src/bwserve/bwclient.js +141 -0
- package/src/bwserve/bwshell.js +102 -0
- package/src/bwserve/client.js +151 -1
- package/src/bwserve/index.js +139 -29
- package/src/cli/attach.js +555 -0
- package/src/cli/convert.js +2 -5
- package/src/cli/index.js +7 -0
- package/src/cli/inject.js +1 -1
- package/src/cli/layout-default.js +47 -32
- package/src/cli/serve.js +6 -2
- package/src/generate-css.js +11 -4
- package/src/vendor/html2canvas.min.js +20 -0
- package/src/version.js +3 -3
- package/src/bwserve/shell.js +0 -103
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* bitwrench-util-css.js - Rule-based CSS utility parser plugin
|
|
3
|
+
*
|
|
4
|
+
* Replaces the old static `bw.u` dictionary with a parser that generates
|
|
5
|
+
* style objects, CSS strings, or class names from shorthand tokens.
|
|
6
|
+
*
|
|
7
|
+
* Three output methods:
|
|
8
|
+
* bw.u('flex gap4 p4') → { display: 'flex', gap: '1rem', padding: '1rem' }
|
|
9
|
+
* bw.u.css('flex gap4 p4') → "display:flex;gap:1rem;padding:1rem"
|
|
10
|
+
* bw.u.cls('flex gap4 p4') → "bw_flex bw_gap_4 bw_p_4"
|
|
11
|
+
* bw.u.extend({ name: fn }) → register custom rules
|
|
12
|
+
*
|
|
13
|
+
* Can be loaded standalone (browser script tag after bitwrench.umd.js),
|
|
14
|
+
* or imported as an ES module / CJS module.
|
|
15
|
+
*
|
|
16
|
+
* @module bitwrench-util-css
|
|
17
|
+
* @license BSD-2-Clause
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
// -- Scale: n → rem (0.25rem increments) ---------------------------------
|
|
21
|
+
function _rem(n) { return (n * 0.25) + 'rem'; }
|
|
22
|
+
|
|
23
|
+
// -- Built-in parametric rules -------------------------------------------
|
|
24
|
+
// Each returns a style object or null (not recognized).
|
|
25
|
+
var PARAMETRIC = {
|
|
26
|
+
p: function(n) { return { padding: _rem(n) }; },
|
|
27
|
+
pt: function(n) { return { paddingTop: _rem(n) }; },
|
|
28
|
+
pb: function(n) { return { paddingBottom: _rem(n) }; },
|
|
29
|
+
pl: function(n) { return { paddingLeft: _rem(n) }; },
|
|
30
|
+
pr: function(n) { return { paddingRight: _rem(n) }; },
|
|
31
|
+
px: function(n) { return { paddingLeft: _rem(n), paddingRight: _rem(n) }; },
|
|
32
|
+
py: function(n) { return { paddingTop: _rem(n), paddingBottom: _rem(n) }; },
|
|
33
|
+
m: function(n) { return { margin: _rem(n) }; },
|
|
34
|
+
mt: function(n) { return { marginTop: _rem(n) }; },
|
|
35
|
+
mb: function(n) { return { marginBottom: _rem(n) }; },
|
|
36
|
+
ml: function(n) { return { marginLeft: _rem(n) }; },
|
|
37
|
+
mr: function(n) { return { marginRight: _rem(n) }; },
|
|
38
|
+
mx: function(n) { return { marginLeft: _rem(n), marginRight: _rem(n) }; },
|
|
39
|
+
my: function(n) { return { marginTop: _rem(n), marginBottom: _rem(n) }; },
|
|
40
|
+
gap: function(n) { return { gap: _rem(n) }; },
|
|
41
|
+
w: function(n) { return { width: _rem(n) }; },
|
|
42
|
+
h: function(n) { return { height: _rem(n) }; },
|
|
43
|
+
rounded: function(n) { return { borderRadius: _rem(n) }; },
|
|
44
|
+
textSm: function() { return { fontSize: '0.875rem' }; },
|
|
45
|
+
textBase: function() { return { fontSize: '1rem' }; },
|
|
46
|
+
textLg: function() { return { fontSize: '1.125rem' }; },
|
|
47
|
+
textXl: function() { return { fontSize: '1.25rem' }; },
|
|
48
|
+
text2xl: function() { return { fontSize: '1.5rem' }; },
|
|
49
|
+
text3xl: function() { return { fontSize: '1.875rem' }; }
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// -- Static keywords (no numeric param) ----------------------------------
|
|
53
|
+
var STATICS = {
|
|
54
|
+
flex: { display: 'flex' },
|
|
55
|
+
flexCol: { display: 'flex', flexDirection: 'column' },
|
|
56
|
+
flexRow: { display: 'flex', flexDirection: 'row' },
|
|
57
|
+
flexWrap: { display: 'flex', flexWrap: 'wrap' },
|
|
58
|
+
block: { display: 'block' },
|
|
59
|
+
inline: { display: 'inline' },
|
|
60
|
+
hidden: { display: 'none' },
|
|
61
|
+
bold: { fontWeight: '700' },
|
|
62
|
+
semibold: { fontWeight: '600' },
|
|
63
|
+
italic: { fontStyle: 'italic' },
|
|
64
|
+
textCenter: { textAlign: 'center' },
|
|
65
|
+
textRight: { textAlign: 'right' },
|
|
66
|
+
justifyCenter: { justifyContent: 'center' },
|
|
67
|
+
justifyBetween: { justifyContent: 'space-between' },
|
|
68
|
+
justifyEnd: { justifyContent: 'flex-end' },
|
|
69
|
+
alignCenter: { alignItems: 'center' },
|
|
70
|
+
alignStart: { alignItems: 'flex-start' },
|
|
71
|
+
alignEnd: { alignItems: 'flex-end' },
|
|
72
|
+
wFull: { width: '100%' },
|
|
73
|
+
hFull: { height: '100%' },
|
|
74
|
+
transition: { transition: 'all 0.2s ease' }
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// -- Custom rules (added via u.extend) -----------------------------------
|
|
78
|
+
var _custom = {};
|
|
79
|
+
|
|
80
|
+
// -- Token parser --------------------------------------------------------
|
|
81
|
+
// Regex: split on whitespace
|
|
82
|
+
var _splitRe = /\s+/;
|
|
83
|
+
|
|
84
|
+
// Match parametric token: name + digits, e.g. "p4", "gap8", "rounded2"
|
|
85
|
+
var _paramRe = /^([a-zA-Z]+?)(\d+)$/;
|
|
86
|
+
|
|
87
|
+
// Match color rules: bg-<name>, text-<name>, bg-[#hex]
|
|
88
|
+
var _bgBracketRe = /^bg-\[([^\]]+)\]$/;
|
|
89
|
+
var _textBracketRe = /^text-\[([^\]]+)\]$/;
|
|
90
|
+
var _bgNameRe = /^bg-(.+)$/;
|
|
91
|
+
var _textNameRe = /^text-(.+)$/;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Parse a single token into a style object, or null if unknown.
|
|
95
|
+
*/
|
|
96
|
+
function _parseToken(token) {
|
|
97
|
+
// 1. Custom rules first
|
|
98
|
+
if (_custom[token]) {
|
|
99
|
+
var val = _custom[token];
|
|
100
|
+
return typeof val === 'function' ? val(token) : val;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 2. Static keywords
|
|
104
|
+
if (STATICS[token]) return STATICS[token];
|
|
105
|
+
|
|
106
|
+
// 3. Parametric rules (e.g. p4, gap8, mb2)
|
|
107
|
+
var pm = _paramRe.exec(token);
|
|
108
|
+
if (pm) {
|
|
109
|
+
var name = pm[1];
|
|
110
|
+
var num = parseInt(pm[2], 10);
|
|
111
|
+
if (PARAMETRIC[name]) return PARAMETRIC[name](num);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 4. Non-numeric parametric (text sizes like textSm)
|
|
115
|
+
if (PARAMETRIC[token]) return PARAMETRIC[token]();
|
|
116
|
+
|
|
117
|
+
// 5. Color: bg-[#hex]
|
|
118
|
+
var bgBr = _bgBracketRe.exec(token);
|
|
119
|
+
if (bgBr) return { background: bgBr[1] };
|
|
120
|
+
|
|
121
|
+
// 6. Color: text-[#hex]
|
|
122
|
+
var textBr = _textBracketRe.exec(token);
|
|
123
|
+
if (textBr) return { color: textBr[1] };
|
|
124
|
+
|
|
125
|
+
// 7. Color: bg-<name>
|
|
126
|
+
var bgN = _bgNameRe.exec(token);
|
|
127
|
+
if (bgN) return { background: bgN[1] };
|
|
128
|
+
|
|
129
|
+
// 8. Color: text-<name>
|
|
130
|
+
var textN = _textNameRe.exec(token);
|
|
131
|
+
if (textN) return { color: textN[1] };
|
|
132
|
+
|
|
133
|
+
// Unknown → silently ignored
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Parse a space-separated string of utility tokens into a merged style object.
|
|
139
|
+
*
|
|
140
|
+
* @param {string} str - Space-separated utility tokens
|
|
141
|
+
* @returns {Object} Merged style object
|
|
142
|
+
*/
|
|
143
|
+
function u(str) {
|
|
144
|
+
if (!str || typeof str !== 'string') return {};
|
|
145
|
+
var tokens = str.trim().split(_splitRe);
|
|
146
|
+
var result = {};
|
|
147
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
148
|
+
var style = _parseToken(tokens[i]);
|
|
149
|
+
if (style) {
|
|
150
|
+
var keys = Object.keys(style);
|
|
151
|
+
for (var j = 0; j < keys.length; j++) {
|
|
152
|
+
result[keys[j]] = style[keys[j]];
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Parse tokens and return a CSS declaration string.
|
|
161
|
+
*
|
|
162
|
+
* @param {string} str - Space-separated utility tokens
|
|
163
|
+
* @returns {string} CSS declarations (e.g. "display:flex;gap:1rem")
|
|
164
|
+
*/
|
|
165
|
+
u.css = function(str) {
|
|
166
|
+
var style = u(str);
|
|
167
|
+
var parts = [];
|
|
168
|
+
var keys = Object.keys(style);
|
|
169
|
+
for (var i = 0; i < keys.length; i++) {
|
|
170
|
+
// Convert camelCase to kebab-case
|
|
171
|
+
var prop = keys[i].replace(/([A-Z])/g, function(m) { return '-' + m.toLowerCase(); });
|
|
172
|
+
parts.push(prop + ':' + style[keys[i]]);
|
|
173
|
+
}
|
|
174
|
+
return parts.join(';');
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Parse tokens and return BEM-style class names (bw_ prefixed).
|
|
179
|
+
*
|
|
180
|
+
* @param {string} str - Space-separated utility tokens
|
|
181
|
+
* @returns {string} Space-separated class names
|
|
182
|
+
*/
|
|
183
|
+
u.cls = function(str) {
|
|
184
|
+
if (!str || typeof str !== 'string') return '';
|
|
185
|
+
var tokens = str.trim().split(_splitRe);
|
|
186
|
+
var classes = [];
|
|
187
|
+
for (var i = 0; i < tokens.length; i++) {
|
|
188
|
+
var token = tokens[i];
|
|
189
|
+
// Only emit classes for recognized tokens
|
|
190
|
+
if (_parseToken(token)) {
|
|
191
|
+
// Convert camelCase to underscore, digits get underscore prefix
|
|
192
|
+
var cls = 'bw_' + token
|
|
193
|
+
.replace(/([A-Z])/g, function(m) { return '_' + m.toLowerCase(); })
|
|
194
|
+
.replace(/(\d+)/g, function(m) { return '_' + m; });
|
|
195
|
+
classes.push(cls);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return classes.join(' ');
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Register custom rules. Each key is a token name, value is either
|
|
203
|
+
* a style object or a function returning a style object.
|
|
204
|
+
*
|
|
205
|
+
* @param {Object} rules - Map of token → style object or function
|
|
206
|
+
*/
|
|
207
|
+
u.extend = function(rules) {
|
|
208
|
+
if (!rules || typeof rules !== 'object') return;
|
|
209
|
+
var keys = Object.keys(rules);
|
|
210
|
+
for (var i = 0; i < keys.length; i++) {
|
|
211
|
+
_custom[keys[i]] = rules[keys[i]];
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
// -- Plugin installation -------------------------------------------------
|
|
216
|
+
function install(bw) {
|
|
217
|
+
if (!bw) return;
|
|
218
|
+
bw.utilCSS = u;
|
|
219
|
+
bw.u = u;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Auto-install if bw is on window (script tag usage)
|
|
223
|
+
if (typeof window !== 'undefined' && window.bw) {
|
|
224
|
+
install(window.bw);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// -- Exports --------------------------------------------------------------
|
|
228
|
+
export { u as utilCSS, install };
|
|
229
|
+
export default { utilCSS: u, install };
|