@zolomedia/bifrost-client 1.7.74
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/L1_Foundation/L1_Foundation.js +13 -0
- package/L1_Foundation/bootstrap/bootstrap.js +11 -0
- package/L1_Foundation/bootstrap/bootstrap_hooks.js +123 -0
- package/L1_Foundation/bootstrap/bootstrap_index.js +15 -0
- package/L1_Foundation/bootstrap/bootstrap_logger.js +135 -0
- package/L1_Foundation/bootstrap/cdn_loader.js +217 -0
- package/L1_Foundation/bootstrap/module_registry.js +102 -0
- package/L1_Foundation/bootstrap/prism_loader.js +164 -0
- package/L1_Foundation/config/client_config.js +110 -0
- package/L1_Foundation/config/config.js +7 -0
- package/L1_Foundation/connection/connection.js +8 -0
- package/L1_Foundation/connection/websocket_connection.js +122 -0
- package/L1_Foundation/constants/bifrost_constants.js +284 -0
- package/L1_Foundation/constants/constants.js +7 -0
- package/L1_Foundation/logger/logger.js +10 -0
- package/L2_Handling/L2_Handling.js +15 -0
- package/L2_Handling/cache/cache.js +22 -0
- package/L2_Handling/cache/cache_constants.js +69 -0
- package/L2_Handling/cache/orchestration/cache_manager.js +299 -0
- package/L2_Handling/cache/orchestration/cache_orchestrator.js +260 -0
- package/L2_Handling/cache/orchestration/orchestration.js +12 -0
- package/L2_Handling/cache/storage/session_manager.js +289 -0
- package/L2_Handling/cache/storage/storage.js +10 -0
- package/L2_Handling/cache/storage/storage_manager.js +590 -0
- package/L2_Handling/display/composite/composite.js +13 -0
- package/L2_Handling/display/composite/dashboard_renderer.js +221 -0
- package/L2_Handling/display/composite/swiper_renderer.js +564 -0
- package/L2_Handling/display/composite/terminal_renderer.js +922 -0
- package/L2_Handling/display/composite/wizard_conditional_renderer.js +274 -0
- package/L2_Handling/display/display.js +30 -0
- package/L2_Handling/display/feedback/feedback.js +11 -0
- package/L2_Handling/display/feedback/progressbar_renderer.js +418 -0
- package/L2_Handling/display/feedback/spinner_renderer.js +246 -0
- package/L2_Handling/display/inputs/button_renderer.js +634 -0
- package/L2_Handling/display/inputs/form_renderer.js +583 -0
- package/L2_Handling/display/inputs/input_renderer.js +658 -0
- package/L2_Handling/display/inputs/inputs.js +12 -0
- package/L2_Handling/display/navigation/menu_renderer.js +206 -0
- package/L2_Handling/display/navigation/navigation.js +11 -0
- package/L2_Handling/display/navigation/navigation_renderer.js +703 -0
- package/L2_Handling/display/orchestration/orchestration.js +11 -0
- package/L2_Handling/display/orchestration/renderer.js +430 -0
- package/L2_Handling/display/orchestration/zdisplay_orchestrator.js +1759 -0
- package/L2_Handling/display/outputs/alert_renderer.js +161 -0
- package/L2_Handling/display/outputs/audio_renderer.js +94 -0
- package/L2_Handling/display/outputs/card_renderer.js +229 -0
- package/L2_Handling/display/outputs/code_renderer.js +66 -0
- package/L2_Handling/display/outputs/dl_renderer.js +131 -0
- package/L2_Handling/display/outputs/header_renderer.js +162 -0
- package/L2_Handling/display/outputs/icon_renderer.js +107 -0
- package/L2_Handling/display/outputs/image_renderer.js +145 -0
- package/L2_Handling/display/outputs/list_renderer.js +190 -0
- package/L2_Handling/display/outputs/outputs.js +19 -0
- package/L2_Handling/display/outputs/table_renderer.js +765 -0
- package/L2_Handling/display/outputs/text_renderer.js +818 -0
- package/L2_Handling/display/outputs/typography_renderer.js +293 -0
- package/L2_Handling/display/outputs/video_renderer.js +116 -0
- package/L2_Handling/display/primitives/document_structure_primitives.js +319 -0
- package/L2_Handling/display/primitives/form_primitives.js +526 -0
- package/L2_Handling/display/primitives/generic_containers.js +109 -0
- package/L2_Handling/display/primitives/interactive_primitives.js +305 -0
- package/L2_Handling/display/primitives/link_primitives.js +552 -0
- package/L2_Handling/display/primitives/lists_primitives.js +262 -0
- package/L2_Handling/display/primitives/media_primitives.js +383 -0
- package/L2_Handling/display/primitives/primitives.js +19 -0
- package/L2_Handling/display/primitives/semantic_element_primitive.js +226 -0
- package/L2_Handling/display/primitives/table_primitives.js +528 -0
- package/L2_Handling/display/primitives/typography_primitives.js +175 -0
- package/L2_Handling/display/specialized/input_request_renderer.js +467 -0
- package/L2_Handling/display/specialized/specialized.js +10 -0
- package/L2_Handling/hooks/hooks.js +9 -0
- package/L2_Handling/hooks/menu_integration.js +57 -0
- package/L2_Handling/hooks/widget_hook_manager.js +292 -0
- package/L2_Handling/message/message.js +8 -0
- package/L2_Handling/message/message_handler.js +701 -0
- package/L2_Handling/navigation/navigation.js +8 -0
- package/L2_Handling/navigation/navigation_manager.js +403 -0
- package/L2_Handling/zhooks/features/cache_live.js +287 -0
- package/L2_Handling/zhooks/features/crumbs_live.js +292 -0
- package/L2_Handling/zhooks/zhooks_manager.js +65 -0
- package/L2_Handling/zvaf/zvaf.js +8 -0
- package/L2_Handling/zvaf/zvaf_manager.js +334 -0
- package/L3_Abstraction/L3_Abstraction.js +12 -0
- package/L3_Abstraction/orchestrator/container_unwrapper.js +101 -0
- package/L3_Abstraction/orchestrator/group_renderer.js +698 -0
- package/L3_Abstraction/orchestrator/input_event_handler.js +797 -0
- package/L3_Abstraction/orchestrator/metadata_processor.js +249 -0
- package/L3_Abstraction/orchestrator/navbar_builder.js +201 -0
- package/L3_Abstraction/orchestrator/orchestrator.js +13 -0
- package/L3_Abstraction/orchestrator/wizard_gate_handler.js +360 -0
- package/L3_Abstraction/renderer/renderer.js +1 -0
- package/L3_Abstraction/session/session.js +1 -0
- package/L4_Orchestration/L4_Orchestration.js +11 -0
- package/L4_Orchestration/client/client.js +1 -0
- package/L4_Orchestration/facade/facade.js +9 -0
- package/L4_Orchestration/facade/manager_registry.js +118 -0
- package/L4_Orchestration/facade/renderer_registry.js +274 -0
- package/L4_Orchestration/lifecycle/asset_loader.js +255 -0
- package/L4_Orchestration/lifecycle/initializer.js +135 -0
- package/L4_Orchestration/lifecycle/lifecycle.js +8 -0
- package/L4_Orchestration/rendering/facade.js +94 -0
- package/L4_Orchestration/rendering/rendering.js +7 -0
- package/LICENSE +21 -0
- package/README.md +82 -0
- package/bifrost_client.js +204 -0
- package/bifrost_core.js +1686 -0
- package/docs/ARCHITECTURE.md +111 -0
- package/docs/PROTOCOL.md +106 -0
- package/docs/RENDERERS.md +101 -0
- package/docs/SECURITY.md +92 -0
- package/package.json +24 -0
- package/syntax/prism-zconfig.js +41 -0
- package/syntax/prism-zenv.js +69 -0
- package/syntax/prism-zolo-theme.css +288 -0
- package/syntax/prism-zolo.js +380 -0
- package/syntax/prism-zschema.js +38 -0
- package/syntax/prism-zspark.js +25 -0
- package/syntax/prism-zui.js +68 -0
- package/zSys/accessibility/accessibility.js +10 -0
- package/zSys/accessibility/emoji_accessibility.js +173 -0
- package/zSys/dom/block_utils.js +122 -0
- package/zSys/dom/container_utils.js +370 -0
- package/zSys/dom/dom.js +13 -0
- package/zSys/dom/dom_utils.js +328 -0
- package/zSys/dom/encoding_utils.js +117 -0
- package/zSys/dom/style_utils.js +71 -0
- package/zSys/errors/error_display.js +299 -0
- package/zSys/errors/errors.js +10 -0
- package/zSys/theme/color_utils.js +274 -0
- package/zSys/theme/dark_mode_utils.js +272 -0
- package/zSys/theme/size_utils.js +256 -0
- package/zSys/theme/spacing_utils.js +405 -0
- package/zSys/theme/theme.js +14 -0
- package/zSys/theme/zbase.css +1735 -0
- package/zSys/theme/zbase_inject.js +161 -0
- package/zSys/theme/ztheme_utils.js +305 -0
- package/zSys/validation/error_boundary.js +201 -0
- package/zSys/validation/validation.js +11 -0
- package/zSys/validation/validation_utils.js +238 -0
- package/zSys/zSys.js +14 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Size Utilities - Generate and apply zTheme size classes
|
|
3
|
+
*
|
|
4
|
+
* "Off-road" utility module created during Bifrost refactoring
|
|
5
|
+
* Complements spacing_utils.js and color_utils.js
|
|
6
|
+
*
|
|
7
|
+
* zTheme doesn't have comprehensive size utilities built-in,
|
|
8
|
+
* so we provide programmatic sizing for common patterns:
|
|
9
|
+
* - Width/Height (responsive and fixed)
|
|
10
|
+
* - Min/Max dimensions
|
|
11
|
+
* - Aspect ratios
|
|
12
|
+
* - Icon sizes
|
|
13
|
+
* - Spinner sizes
|
|
14
|
+
*
|
|
15
|
+
* Layer: Utility (Layer 0.4)
|
|
16
|
+
* Dependencies: None (pure utility functions)
|
|
17
|
+
* Used by: All renderers that need programmatic sizing
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Standard size scale (matches zTheme spacing scale)
|
|
22
|
+
*/
|
|
23
|
+
const SIZE_SCALE = {
|
|
24
|
+
0: '0',
|
|
25
|
+
1: '0.25rem', // 4px
|
|
26
|
+
2: '0.5rem', // 8px
|
|
27
|
+
3: '0.75rem', // 12px
|
|
28
|
+
4: '1rem', // 16px
|
|
29
|
+
5: '1.25rem', // 20px
|
|
30
|
+
6: '1.5rem', // 24px
|
|
31
|
+
7: '1.75rem', // 28px
|
|
32
|
+
8: '2rem', // 32px
|
|
33
|
+
9: '2.25rem', // 36px
|
|
34
|
+
10: '2.5rem', // 40px
|
|
35
|
+
12: '3rem', // 48px
|
|
36
|
+
16: '4rem', // 64px
|
|
37
|
+
20: '5rem', // 80px
|
|
38
|
+
24: '6rem', // 96px
|
|
39
|
+
32: '8rem', // 128px
|
|
40
|
+
40: '10rem', // 160px
|
|
41
|
+
48: '12rem', // 192px
|
|
42
|
+
56: '14rem', // 224px
|
|
43
|
+
64: '16rem' // 256px
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Percentage sizes for responsive layouts
|
|
48
|
+
*/
|
|
49
|
+
const PERCENT_SIZES = {
|
|
50
|
+
'25': '25%',
|
|
51
|
+
'33': '33.333333%',
|
|
52
|
+
'50': '50%',
|
|
53
|
+
'66': '66.666667%',
|
|
54
|
+
'75': '75%',
|
|
55
|
+
'100': '100%',
|
|
56
|
+
auto: 'auto'
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Icon size presets (matching common icon libraries)
|
|
61
|
+
*/
|
|
62
|
+
const ICON_SIZES = {
|
|
63
|
+
xs: '0.75rem', // 12px
|
|
64
|
+
sm: '1rem', // 16px
|
|
65
|
+
md: '1.5rem', // 24px
|
|
66
|
+
lg: '2rem', // 32px
|
|
67
|
+
xl: '3rem', // 48px
|
|
68
|
+
'2xl': '4rem' // 64px
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Spinner size presets (matching Bootstrap/zTheme spinners)
|
|
73
|
+
*/
|
|
74
|
+
const SPINNER_SIZES = {
|
|
75
|
+
sm: { width: '1rem', height: '1rem', borderWidth: '0.15em' },
|
|
76
|
+
md: { width: '2rem', height: '2rem', borderWidth: '0.2em' },
|
|
77
|
+
lg: { width: '3rem', height: '3rem', borderWidth: '0.25em' }
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get width class
|
|
82
|
+
* @param {string|number} size - Size value (scale number, percent, or 'auto')
|
|
83
|
+
* @returns {string} Width class
|
|
84
|
+
*/
|
|
85
|
+
export function getWidthClass(size) {
|
|
86
|
+
if (typeof size === 'number' || !isNaN(size)) {
|
|
87
|
+
return `zW-${size}`;
|
|
88
|
+
}
|
|
89
|
+
return `zW-${size}`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Get height class
|
|
94
|
+
* @param {string|number} size - Size value (scale number, percent, or 'auto')
|
|
95
|
+
* @returns {string} Height class
|
|
96
|
+
*/
|
|
97
|
+
export function getHeightClass(size) {
|
|
98
|
+
if (typeof size === 'number' || !isNaN(size)) {
|
|
99
|
+
return `zH-${size}`;
|
|
100
|
+
}
|
|
101
|
+
return `zH-${size}`;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Apply width to element
|
|
106
|
+
* @param {HTMLElement} element - Target element
|
|
107
|
+
* @param {string|number} size - Size value
|
|
108
|
+
* @returns {HTMLElement} Element with width applied
|
|
109
|
+
*/
|
|
110
|
+
export function applyWidth(element, size) {
|
|
111
|
+
const value = SIZE_SCALE[size] || PERCENT_SIZES[size] || size;
|
|
112
|
+
element.style.width = value;
|
|
113
|
+
return element;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Apply height to element
|
|
118
|
+
* @param {HTMLElement} element - Target element
|
|
119
|
+
* @param {string|number} size - Size value
|
|
120
|
+
* @returns {HTMLElement} Element with height applied
|
|
121
|
+
*/
|
|
122
|
+
export function applyHeight(element, size) {
|
|
123
|
+
const value = SIZE_SCALE[size] || PERCENT_SIZES[size] || size;
|
|
124
|
+
element.style.height = value;
|
|
125
|
+
return element;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Apply dimensions (width and height) to element
|
|
130
|
+
* @param {HTMLElement} element - Target element
|
|
131
|
+
* @param {string|number} width - Width value
|
|
132
|
+
* @param {string|number} height - Height value (defaults to width for square)
|
|
133
|
+
* @returns {HTMLElement} Element with dimensions applied
|
|
134
|
+
*/
|
|
135
|
+
export function applyDimensions(element, width, height = width) {
|
|
136
|
+
applyWidth(element, width);
|
|
137
|
+
applyHeight(element, height);
|
|
138
|
+
return element;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Apply min-width to element
|
|
143
|
+
* @param {HTMLElement} element - Target element
|
|
144
|
+
* @param {string|number} size - Size value
|
|
145
|
+
* @returns {HTMLElement} Element with min-width applied
|
|
146
|
+
*/
|
|
147
|
+
export function applyMinWidth(element, size) {
|
|
148
|
+
const value = SIZE_SCALE[size] || PERCENT_SIZES[size] || size;
|
|
149
|
+
element.style.minWidth = value;
|
|
150
|
+
return element;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Apply max-width to element
|
|
155
|
+
* @param {HTMLElement} element - Target element
|
|
156
|
+
* @param {string|number} size - Size value
|
|
157
|
+
* @returns {HTMLElement} Element with max-width applied
|
|
158
|
+
*/
|
|
159
|
+
export function applyMaxWidth(element, size) {
|
|
160
|
+
const value = SIZE_SCALE[size] || PERCENT_SIZES[size] || size;
|
|
161
|
+
element.style.maxWidth = value;
|
|
162
|
+
return element;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Apply icon size to element
|
|
167
|
+
* @param {HTMLElement} element - Target element (icon)
|
|
168
|
+
* @param {string} size - Icon size (xs, sm, md, lg, xl, 2xl)
|
|
169
|
+
* @returns {HTMLElement} Element with icon size applied
|
|
170
|
+
*/
|
|
171
|
+
export function applyIconSize(element, size) {
|
|
172
|
+
const value = ICON_SIZES[size] || ICON_SIZES.md;
|
|
173
|
+
element.style.fontSize = value;
|
|
174
|
+
element.style.width = value;
|
|
175
|
+
element.style.height = value;
|
|
176
|
+
return element;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Apply spinner size to element
|
|
181
|
+
* @param {HTMLElement} element - Target element (spinner)
|
|
182
|
+
* @param {string} size - Spinner size (sm, md, lg)
|
|
183
|
+
* @returns {HTMLElement} Element with spinner size applied
|
|
184
|
+
*/
|
|
185
|
+
export function applySpinnerSize(element, size) {
|
|
186
|
+
const styles = SPINNER_SIZES[size] || SPINNER_SIZES.md;
|
|
187
|
+
element.style.width = styles.width;
|
|
188
|
+
element.style.height = styles.height;
|
|
189
|
+
element.style.borderWidth = styles.borderWidth;
|
|
190
|
+
return element;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Apply aspect ratio to element
|
|
195
|
+
* @param {HTMLElement} element - Target element
|
|
196
|
+
* @param {string} ratio - Aspect ratio (e.g., '16/9', '4/3', '1/1')
|
|
197
|
+
* @returns {HTMLElement} Element with aspect ratio applied
|
|
198
|
+
*/
|
|
199
|
+
export function applyAspectRatio(element, ratio) {
|
|
200
|
+
element.style.aspectRatio = ratio;
|
|
201
|
+
return element;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Apply sizing configuration object to element
|
|
206
|
+
* @param {HTMLElement} element - Target element
|
|
207
|
+
* @param {Object} config - Sizing configuration
|
|
208
|
+
* @param {string|number} [config.width] - Width
|
|
209
|
+
* @param {string|number} [config.height] - Height
|
|
210
|
+
* @param {string|number} [config.minWidth] - Min width
|
|
211
|
+
* @param {string|number} [config.maxWidth] - Max width
|
|
212
|
+
* @param {string|number} [config.minHeight] - Min height
|
|
213
|
+
* @param {string|number} [config.maxHeight] - Max height
|
|
214
|
+
* @param {string} [config.aspectRatio] - Aspect ratio
|
|
215
|
+
* @returns {HTMLElement} Element with sizing applied
|
|
216
|
+
*/
|
|
217
|
+
export function applySizing(element, config) {
|
|
218
|
+
if (config.width !== undefined) {
|
|
219
|
+
applyWidth(element, config.width);
|
|
220
|
+
}
|
|
221
|
+
if (config.height !== undefined) {
|
|
222
|
+
applyHeight(element, config.height);
|
|
223
|
+
}
|
|
224
|
+
if (config.minWidth !== undefined) {
|
|
225
|
+
applyMinWidth(element, config.minWidth);
|
|
226
|
+
}
|
|
227
|
+
if (config.maxWidth !== undefined) {
|
|
228
|
+
applyMaxWidth(element, config.maxWidth);
|
|
229
|
+
}
|
|
230
|
+
if (config.minHeight !== undefined) {
|
|
231
|
+
const value = SIZE_SCALE[config.minHeight] || PERCENT_SIZES[config.minHeight] || config.minHeight;
|
|
232
|
+
element.style.minHeight = value;
|
|
233
|
+
}
|
|
234
|
+
if (config.maxHeight !== undefined) {
|
|
235
|
+
const value = SIZE_SCALE[config.maxHeight] || PERCENT_SIZES[config.maxHeight] || config.maxHeight;
|
|
236
|
+
element.style.maxHeight = value;
|
|
237
|
+
}
|
|
238
|
+
if (config.aspectRatio !== undefined) {
|
|
239
|
+
applyAspectRatio(element, config.aspectRatio);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return element;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Get size value from scale or percent
|
|
247
|
+
* @param {string|number} size - Size key
|
|
248
|
+
* @returns {string} CSS size value
|
|
249
|
+
*/
|
|
250
|
+
export function getSizeValue(size) {
|
|
251
|
+
return SIZE_SCALE[size] || PERCENT_SIZES[size] || size;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Export constants for direct access
|
|
255
|
+
export { SIZE_SCALE, PERCENT_SIZES, ICON_SIZES, SPINNER_SIZES };
|
|
256
|
+
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Spacing Utilities - Layout Primitives
|
|
4
|
+
*
|
|
5
|
+
*
|
|
6
|
+
* Pure functions for generating and applying spacing classes.
|
|
7
|
+
* These are foundational primitives for consistent layout rhythm.
|
|
8
|
+
*
|
|
9
|
+
* @module rendering/spacing_utils
|
|
10
|
+
* @layer 0 (Foundation - below Layer 2 utilities)
|
|
11
|
+
* @pattern Pure Functions (no state, no side effects)
|
|
12
|
+
*
|
|
13
|
+
* Philosophy:
|
|
14
|
+
* - "Spacing first" - Rhythm and breathing room for all layouts
|
|
15
|
+
* - Pure functions (input → output, no side effects)
|
|
16
|
+
* - Uses zTheme spacing scale exclusively (0-5, auto, negative)
|
|
17
|
+
* - Generates class names programmatically (no hardcoded strings)
|
|
18
|
+
*
|
|
19
|
+
* zTheme Spacing Scale:
|
|
20
|
+
* - 0: 0 (remove spacing)
|
|
21
|
+
* - 1: 0.25rem (4px)
|
|
22
|
+
* - 2: 0.5rem (8px)
|
|
23
|
+
* - 3: 1rem (16px) Base unit
|
|
24
|
+
* - 4: 1.5rem (24px)
|
|
25
|
+
* - 5: 3rem (48px)
|
|
26
|
+
* - auto: Auto (for centering)
|
|
27
|
+
* - n1-n5: Negative margins (pull elements closer)
|
|
28
|
+
*
|
|
29
|
+
* Dependencies:
|
|
30
|
+
* - None (pure utility, no imports needed)
|
|
31
|
+
*
|
|
32
|
+
* Exports:
|
|
33
|
+
* - getMarginClass()
|
|
34
|
+
* - getPaddingClass()
|
|
35
|
+
* - getGapClass()
|
|
36
|
+
* - applySpacing()
|
|
37
|
+
*
|
|
38
|
+
* Example:
|
|
39
|
+
* ```javascript
|
|
40
|
+
* import { getMarginClass, getPaddingClass, applySpacing } from './spacing_utils.js';
|
|
41
|
+
*
|
|
42
|
+
* const mt = getMarginClass(4, 'top'); // 'zmt-4'
|
|
43
|
+
* const px = getPaddingClass(3, 'x'); // 'zpx-3'
|
|
44
|
+
* const gap = getGapClass(2); // 'zGap-2'
|
|
45
|
+
*
|
|
46
|
+
* applySpacing(element, { margin: { top: 4 }, padding: { x: 3 } });
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
//
|
|
51
|
+
// Margin Class Generators
|
|
52
|
+
//
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Generate margin class name (zTheme: zm-, zmt-, zmb-, zms-, zme-, zmx-, zmy-)
|
|
56
|
+
*
|
|
57
|
+
* Supports all zTheme margin patterns:
|
|
58
|
+
* - All sides: zm-{0-5|auto}
|
|
59
|
+
* - Top: zmt-{0-5|auto}
|
|
60
|
+
* - Bottom: zmb-{0-5} (no auto)
|
|
61
|
+
* - Start (left in LTR): zms-{0-5} (no auto)
|
|
62
|
+
* - End (right in LTR): zme-{0-5|auto}
|
|
63
|
+
* - X-axis (left + right): zmx-{0-5|auto}
|
|
64
|
+
* - Y-axis (top + bottom): zmy-{0-5|auto}
|
|
65
|
+
* - Negative: zm-n{1-5}, zmt-n{1-5}, zmb-n{1-5}, zms-n{1-5}, zme-n{1-5}, zmx-n{1-5}, zmy-n{1-5}
|
|
66
|
+
*
|
|
67
|
+
* @param {number|string|null} size - Size (0-5) or 'auto' or negative (e.g., -2)
|
|
68
|
+
* @param {string} [side=''] - Side ('top', 'bottom', 'start', 'end', 'x', 'y', or '' for all)
|
|
69
|
+
* @returns {string|null} Class name or null if invalid
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* getMarginClass(3); // 'zm-3' (all sides)
|
|
73
|
+
* getMarginClass(4, 'top'); // 'zmt-4'
|
|
74
|
+
* getMarginClass('auto'); // 'zm-auto'
|
|
75
|
+
* getMarginClass('auto', 'x'); // 'zmx-auto' (horizontal centering)
|
|
76
|
+
* getMarginClass(-2, 'top'); // 'zmt-n2' (negative margin, pull up)
|
|
77
|
+
*/
|
|
78
|
+
export function getMarginClass(size, side = '') {
|
|
79
|
+
// Handle null/undefined
|
|
80
|
+
if (size === null || size === undefined) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Normalize side
|
|
85
|
+
const sideMap = {
|
|
86
|
+
'top': 't',
|
|
87
|
+
'bottom': 'b',
|
|
88
|
+
'start': 's',
|
|
89
|
+
'end': 'e',
|
|
90
|
+
'x': 'x',
|
|
91
|
+
'y': 'y',
|
|
92
|
+
'': ''
|
|
93
|
+
};
|
|
94
|
+
const sideSuffix = sideMap[side] || '';
|
|
95
|
+
|
|
96
|
+
// Handle auto
|
|
97
|
+
if (size === 'auto') {
|
|
98
|
+
// Only these sides support auto in zTheme
|
|
99
|
+
if (sideSuffix === '' || sideSuffix === 't' || sideSuffix === 'e' || sideSuffix === 'x' || sideSuffix === 'y') {
|
|
100
|
+
return `zm${sideSuffix}-auto`;
|
|
101
|
+
}
|
|
102
|
+
return null; // zmb-auto and zms-auto don't exist
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Handle negative margins
|
|
106
|
+
if (typeof size === 'number' && size < 0) {
|
|
107
|
+
const absSize = Math.abs(size);
|
|
108
|
+
if (absSize >= 1 && absSize <= 5) {
|
|
109
|
+
return `zm${sideSuffix}-n${absSize}`;
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Handle positive sizes (0-5)
|
|
115
|
+
const numSize = typeof size === 'number' ? size : parseInt(size);
|
|
116
|
+
if (!isNaN(numSize) && numSize >= 0 && numSize <= 5) {
|
|
117
|
+
return `zm${sideSuffix}-${numSize}`;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Convenience functions for specific margin sides
|
|
125
|
+
*/
|
|
126
|
+
export const getMarginTopClass = (size) => getMarginClass(size, 'top');
|
|
127
|
+
export const getMarginBottomClass = (size) => getMarginClass(size, 'bottom');
|
|
128
|
+
export const getMarginStartClass = (size) => getMarginClass(size, 'start');
|
|
129
|
+
export const getMarginEndClass = (size) => getMarginClass(size, 'end');
|
|
130
|
+
export const getMarginXClass = (size) => getMarginClass(size, 'x');
|
|
131
|
+
export const getMarginYClass = (size) => getMarginClass(size, 'y');
|
|
132
|
+
|
|
133
|
+
//
|
|
134
|
+
// Padding Class Generators
|
|
135
|
+
//
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Generate padding class name (zTheme: zp-, zpt-, zpb-, zps-, zpe-, zpx-, zpy-)
|
|
139
|
+
*
|
|
140
|
+
* Supports all zTheme padding patterns:
|
|
141
|
+
* - All sides: zp-{0-5}
|
|
142
|
+
* - Top: zpt-{0-5}
|
|
143
|
+
* - Bottom: zpb-{0-5}
|
|
144
|
+
* - Start (left in LTR): zps-{0-5}
|
|
145
|
+
* - End (right in LTR): zpe-{0-5}
|
|
146
|
+
* - X-axis (left + right): zpx-{0-5}
|
|
147
|
+
* - Y-axis (top + bottom): zpy-{0-5}
|
|
148
|
+
*
|
|
149
|
+
* Note: Padding does NOT support 'auto' or negative values in zTheme
|
|
150
|
+
*
|
|
151
|
+
* @param {number|string|null} size - Size (0-5)
|
|
152
|
+
* @param {string} [side=''] - Side ('top', 'bottom', 'start', 'end', 'x', 'y', or '' for all)
|
|
153
|
+
* @returns {string|null} Class name or null if invalid
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* getPaddingClass(3); // 'zp-3' (all sides)
|
|
157
|
+
* getPaddingClass(4, 'top'); // 'zpt-4'
|
|
158
|
+
* getPaddingClass(2, 'x'); // 'zpx-2' (horizontal padding)
|
|
159
|
+
* getPaddingClass(5, 'y'); // 'zpy-5' (vertical padding)
|
|
160
|
+
*/
|
|
161
|
+
export function getPaddingClass(size, side = '') {
|
|
162
|
+
// Handle null/undefined
|
|
163
|
+
if (size === null || size === undefined) {
|
|
164
|
+
return null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Normalize side
|
|
168
|
+
const sideMap = {
|
|
169
|
+
'top': 't',
|
|
170
|
+
'bottom': 'b',
|
|
171
|
+
'start': 's',
|
|
172
|
+
'end': 'e',
|
|
173
|
+
'x': 'x',
|
|
174
|
+
'y': 'y',
|
|
175
|
+
'': ''
|
|
176
|
+
};
|
|
177
|
+
const sideSuffix = sideMap[side] || '';
|
|
178
|
+
|
|
179
|
+
// Padding does NOT support auto or negative values
|
|
180
|
+
const numSize = typeof size === 'number' ? size : parseInt(size);
|
|
181
|
+
if (!isNaN(numSize) && numSize >= 0 && numSize <= 5) {
|
|
182
|
+
return `zp${sideSuffix}-${numSize}`;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Convenience functions for specific padding sides
|
|
190
|
+
*/
|
|
191
|
+
export const getPaddingTopClass = (size) => getPaddingClass(size, 'top');
|
|
192
|
+
export const getPaddingBottomClass = (size) => getPaddingClass(size, 'bottom');
|
|
193
|
+
export const getPaddingStartClass = (size) => getPaddingClass(size, 'start');
|
|
194
|
+
export const getPaddingEndClass = (size) => getPaddingClass(size, 'end');
|
|
195
|
+
export const getPaddingXClass = (size) => getPaddingClass(size, 'x');
|
|
196
|
+
export const getPaddingYClass = (size) => getPaddingClass(size, 'y');
|
|
197
|
+
|
|
198
|
+
//
|
|
199
|
+
// Gap Class Generator
|
|
200
|
+
//
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Generate gap class name (zTheme: zGap-)
|
|
204
|
+
*
|
|
205
|
+
* For flex/grid containers to add spacing between child elements.
|
|
206
|
+
*
|
|
207
|
+
* @param {number|string|null} size - Size (0-5)
|
|
208
|
+
* @returns {string|null} Class name or null if invalid
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* getGapClass(3); // 'zGap-3' (1rem gap between items)
|
|
212
|
+
* getGapClass(2); // 'zGap-2' (0.5rem gap between items)
|
|
213
|
+
*/
|
|
214
|
+
export function getGapClass(size) {
|
|
215
|
+
// Handle null/undefined
|
|
216
|
+
if (size === null || size === undefined) {
|
|
217
|
+
return null;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const numSize = typeof size === 'number' ? size : parseInt(size);
|
|
221
|
+
if (!isNaN(numSize) && numSize >= 0 && numSize <= 5) {
|
|
222
|
+
return `zGap-${numSize}`;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
//
|
|
229
|
+
// Apply Spacing Function
|
|
230
|
+
//
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Apply spacing configuration to an element via config object
|
|
234
|
+
*
|
|
235
|
+
* This is a higher-level function for applying multiple spacing concerns at once.
|
|
236
|
+
*
|
|
237
|
+
* @param {HTMLElement} element - Element to apply spacing to
|
|
238
|
+
* @param {Object} config - Spacing configuration
|
|
239
|
+
* @param {Object} [config.margin] - Margin config ({ all, top, bottom, start, end, x, y })
|
|
240
|
+
* @param {Object} [config.padding] - Padding config ({ all, top, bottom, start, end, x, y })
|
|
241
|
+
* @param {number} [config.gap] - Gap size (0-5) for flex/grid containers
|
|
242
|
+
* @returns {HTMLElement} Element with spacing classes applied
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* // Apply multiple spacing values
|
|
246
|
+
* applySpacing(element, {
|
|
247
|
+
* margin: { top: 4, bottom: 3, x: 'auto' },
|
|
248
|
+
* padding: { x: 2, y: 3 },
|
|
249
|
+
* gap: 2
|
|
250
|
+
* });
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* // Apply simple spacing
|
|
254
|
+
* applySpacing(element, {
|
|
255
|
+
* margin: { all: 3 },
|
|
256
|
+
* padding: { all: 2 }
|
|
257
|
+
* });
|
|
258
|
+
*/
|
|
259
|
+
export function applySpacing(element, config = {}) {
|
|
260
|
+
const classes = [];
|
|
261
|
+
|
|
262
|
+
// Apply margins
|
|
263
|
+
if (config.margin) {
|
|
264
|
+
const m = config.margin;
|
|
265
|
+
|
|
266
|
+
// All sides
|
|
267
|
+
if (m.all !== undefined) {
|
|
268
|
+
const cls = getMarginClass(m.all);
|
|
269
|
+
if (cls) {
|
|
270
|
+
classes.push(cls);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
// Individual sides
|
|
275
|
+
if (m.top !== undefined) {
|
|
276
|
+
const cls = getMarginClass(m.top, 'top');
|
|
277
|
+
if (cls) {
|
|
278
|
+
classes.push(cls);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (m.bottom !== undefined) {
|
|
282
|
+
const cls = getMarginClass(m.bottom, 'bottom');
|
|
283
|
+
if (cls) {
|
|
284
|
+
classes.push(cls);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if (m.start !== undefined) {
|
|
288
|
+
const cls = getMarginClass(m.start, 'start');
|
|
289
|
+
if (cls) {
|
|
290
|
+
classes.push(cls);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (m.end !== undefined) {
|
|
294
|
+
const cls = getMarginClass(m.end, 'end');
|
|
295
|
+
if (cls) {
|
|
296
|
+
classes.push(cls);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// Axes
|
|
301
|
+
if (m.x !== undefined) {
|
|
302
|
+
const cls = getMarginClass(m.x, 'x');
|
|
303
|
+
if (cls) {
|
|
304
|
+
classes.push(cls);
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (m.y !== undefined) {
|
|
308
|
+
const cls = getMarginClass(m.y, 'y');
|
|
309
|
+
if (cls) {
|
|
310
|
+
classes.push(cls);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Apply padding
|
|
316
|
+
if (config.padding) {
|
|
317
|
+
const p = config.padding;
|
|
318
|
+
|
|
319
|
+
// All sides
|
|
320
|
+
if (p.all !== undefined) {
|
|
321
|
+
const cls = getPaddingClass(p.all);
|
|
322
|
+
if (cls) {
|
|
323
|
+
classes.push(cls);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// Individual sides
|
|
328
|
+
if (p.top !== undefined) {
|
|
329
|
+
const cls = getPaddingClass(p.top, 'top');
|
|
330
|
+
if (cls) {
|
|
331
|
+
classes.push(cls);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
if (p.bottom !== undefined) {
|
|
335
|
+
const cls = getPaddingClass(p.bottom, 'bottom');
|
|
336
|
+
if (cls) {
|
|
337
|
+
classes.push(cls);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
if (p.start !== undefined) {
|
|
341
|
+
const cls = getPaddingClass(p.start, 'start');
|
|
342
|
+
if (cls) {
|
|
343
|
+
classes.push(cls);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (p.end !== undefined) {
|
|
347
|
+
const cls = getPaddingClass(p.end, 'end');
|
|
348
|
+
if (cls) {
|
|
349
|
+
classes.push(cls);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// Axes
|
|
354
|
+
if (p.x !== undefined) {
|
|
355
|
+
const cls = getPaddingClass(p.x, 'x');
|
|
356
|
+
if (cls) {
|
|
357
|
+
classes.push(cls);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (p.y !== undefined) {
|
|
361
|
+
const cls = getPaddingClass(p.y, 'y');
|
|
362
|
+
if (cls) {
|
|
363
|
+
classes.push(cls);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
// Apply gap
|
|
369
|
+
if (config.gap !== undefined) {
|
|
370
|
+
const cls = getGapClass(config.gap);
|
|
371
|
+
if (cls) {
|
|
372
|
+
classes.push(cls);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// Apply all classes at once
|
|
377
|
+
if (classes.length > 0) {
|
|
378
|
+
element.classList.add(...classes);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
return element;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
//
|
|
385
|
+
// Default Export (for convenience)
|
|
386
|
+
//
|
|
387
|
+
export default {
|
|
388
|
+
getMarginClass,
|
|
389
|
+
getMarginTopClass,
|
|
390
|
+
getMarginBottomClass,
|
|
391
|
+
getMarginStartClass,
|
|
392
|
+
getMarginEndClass,
|
|
393
|
+
getMarginXClass,
|
|
394
|
+
getMarginYClass,
|
|
395
|
+
getPaddingClass,
|
|
396
|
+
getPaddingTopClass,
|
|
397
|
+
getPaddingBottomClass,
|
|
398
|
+
getPaddingStartClass,
|
|
399
|
+
getPaddingEndClass,
|
|
400
|
+
getPaddingXClass,
|
|
401
|
+
getPaddingYClass,
|
|
402
|
+
getGapClass,
|
|
403
|
+
applySpacing
|
|
404
|
+
};
|
|
405
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* zSys/theme - Theme Utilities Barrel
|
|
3
|
+
*
|
|
4
|
+
* zTheme integration utilities (colors, spacing, sizing, dark mode).
|
|
5
|
+
*
|
|
6
|
+
* @module zSys/theme
|
|
7
|
+
* @layer zSys (System Utilities)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export * from './color_utils.js';
|
|
11
|
+
export * from './size_utils.js';
|
|
12
|
+
export * from './spacing_utils.js';
|
|
13
|
+
export * from './ztheme_utils.js';
|
|
14
|
+
export * from './dark_mode_utils.js';
|