pacem-less 0.51.4-abel → 0.51.4-babbage

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/pacem/body.less CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  &, body {
4
4
  font-family: @font_std;
5
- background-color: @color_root_background;
6
- color: @color_light;
5
+ background-color: ~"var(--@{PCSS}-color-root)";// @color_root_background;
6
+ color:~"var(--@{PCSS}-color-default)";//@color_light;
7
7
  font-size: @font_size;
8
8
  }
9
9
 
package/pacem/pacem.less CHANGED
@@ -152,7 +152,6 @@ html .@{PCSS}-preloader {
152
152
  }
153
153
 
154
154
  @{shell}:root when (@shell_only = false), (@full_theme = true) {
155
-
156
155
  // fonts
157
156
  @import "@{fonts}";
158
157
 
@@ -183,6 +182,60 @@ html .@{PCSS}-preloader {
183
182
  @_size__11: 11px;
184
183
  @_size__12: 12px;
185
184
 
185
+ @_colors: root, background, default, invert, primary, secondary, accent, info, success, warning, danger, error, disabled, green, yellow, brown, red, pink, blue, orange, purple, teal, gray;
186
+
187
+ & when (@palette_prebuilt = true) {
188
+
189
+ --@{PCSS}-prebuilt: true;
190
+
191
+ each(@_colors, {
192
+
193
+ @_color_var: ~"color_@{value}";
194
+ @_color_rgb_var: ~"color_@{value}_rgb";
195
+ @_color_inv_var: ~"color_@{value}_inv";
196
+ @_color_inv_rgb_var: ~"color_@{value}_inv_rgb";
197
+ @_color_container_var: ~"color_@{value}_container";
198
+ @_color_container_rgb_var: ~"color_@{value}_container_rgb";
199
+ @_color_container_inv_var: ~"color_@{value}_container_inv";
200
+ @_color_container_inv_rgb_var: ~"color_@{value}_container_inv_rgb";
201
+ @_color_active_var: ~"color_@{value}_active";
202
+ @_color_active_rgb_var: ~"color_@{value}_active_rgb";
203
+ @_color_active_inv_var: ~"color_@{value}_active_inv";
204
+ @_color_active_inv_rgb_var: ~"color_@{value}_active_inv_rgb";
205
+ @_color_container_active_var: ~"color_@{value}_container_active";
206
+ @_color_container_active_rgb_var: ~"color_@{value}_container_active_rgb";
207
+ @_color_container_active_inv_var: ~"color_@{value}_container_active_inv";
208
+ @_color_container_active_inv_rgb_var: ~"color_@{value}_container_active_inv_rgb";
209
+ @_color_emphasis_var: ~"color_@{value}_emphasis";
210
+ @_color_emphasis_rgb_var: ~"color_@{value}_emphasis_rgb";
211
+
212
+
213
+ --@{PCSS}-color-@{value}: @@_color_var;
214
+ --@{PCSS}-color-@{value}-rgb: @@_color_rgb_var;
215
+ --@{PCSS}-color-@{value}-inverse: @@_color_inv_var;
216
+ --@{PCSS}-color-@{value}-inverse-rgb: @@_color_inv_rgb_var;
217
+
218
+ --@{PCSS}-color-@{value}-hover: @@_color_active_var;
219
+ --@{PCSS}-color-@{value}-hover-rgb: @@_color_active_rgb_var;
220
+ --@{PCSS}-color-@{value}-inverse-hover: @@_color_active_inv_var;
221
+ --@{PCSS}-color-@{value}-inverse-hover-rgb: @@_color_active_inv_rgb_var;
222
+
223
+ --@{PCSS}-color-@{value}-emphasis-hover: @@_color_emphasis_var;
224
+ --@{PCSS}-color-@{value}-emphasis-hover-rgb: @@_color_emphasis_rgb_var;
225
+
226
+ --@{PCSS}-color-@{value}-container: @@_color_container_var;
227
+ --@{PCSS}-color-@{value}-container-rgb: @@_color_container_rgb_var;
228
+ --@{PCSS}-color-@{value}-container-inverse: @@_color_container_inv_var;
229
+ --@{PCSS}-color-@{value}-container-inverse-rgb: @@_color_container_inv_rgb_var;
230
+
231
+ --@{PCSS}-color-@{value}-container-hover: @@_color_container_active_var;
232
+ --@{PCSS}-color-@{value}-container-hover-rgb: @@_color_container_active_rgb_var;
233
+ --@{PCSS}-color-@{value}-container-inverse-hover: @@_color_container_active_inv_var;
234
+ --@{PCSS}-color-@{value}-container-inverse-hover-rgb: @@_color_container_active_inv_rgb_var;
235
+ });
236
+ }
237
+
238
+
186
239
  @_dark_cont_amount: 70; // how much black to add (background)
187
240
  @_dark_on_amount: 60; // how much white to add (foreground)
188
241
  @_dark_cont_amount_hover: 15; // how much white to add (background) hover/focus/active state
@@ -203,6 +256,10 @@ html .@{PCSS}-preloader {
203
256
  --@{PCSS}-color-@{key}-rgb: @_r, @_g, @_b;
204
257
  }
205
258
 
259
+ & when(@palette_prebuilt = false){
260
+
261
+ --@{PCSS}-prebuilt: false;
262
+
206
263
  @__color_background: @color_background;
207
264
  @__color_background_inv: @color_default;
208
265
  @__color_root: @color_root_background;
@@ -251,8 +308,6 @@ html .@{PCSS}-preloader {
251
308
  @__color_gray: @palette_gray;
252
309
  @__color_gray_inv: @palette_gray_inv;
253
310
 
254
- @_colors: root, background, default, invert, primary, secondary, accent, info, success, warning, danger, error, disabled, green, yellow, brown, red, pink, blue, orange, purple, teal, gray;
255
-
256
311
  // basic palette
257
312
  each(@_colors, {
258
313
 
@@ -289,12 +344,13 @@ each(@_colors, {
289
344
  .ChannelizeColor(~"@{value}-container-inverse-hover", @_color_container_inv_hover);
290
345
 
291
346
  });
292
-
347
+ }
293
348
  --@{PCSS}-color-disabled-button: @color_button_back_disabled;
294
349
  .ChannelizeColor(disabled-button, @color_button_back_disabled);
295
350
  --@{PCSS}-color-disabled-button-inverse: @color_button_fore_disabled;
296
351
  .ChannelizeColor(disabled-button-inverse, @color_button_fore_disabled);
297
352
  --@{PCSS}-color-border: @color_border;
353
+
298
354
  // spacing + sizing
299
355
  --@{PCSS}-grid-cell: @grid_cell;
300
356
  --@{PCSS}-grid-spacing: @grid_spacing;
File without changes
File without changes
@@ -375,6 +375,9 @@
375
375
  @easing_out_back_custom: cubic-bezier(0.0, 1.6, 1.0, 0.8);
376
376
  @easing_out_bump: cubic-bezier(0.0, 1.6, 0.0, 1.0);
377
377
 
378
+ // programmatically built palette
379
+ @import "palette-dark";
380
+
378
381
  .Background(@clr_bg) {
379
382
  .Background();
380
383
  background-color: @clr_bg;
@@ -114,3 +114,6 @@
114
114
  /*.FormFieldItemBorders() {
115
115
  border: @border_field_size solid;
116
116
  }*/
117
+
118
+ // programmatically built palette
119
+ @import "palette-light";
@@ -45,6 +45,7 @@
45
45
  /*#endregion*/
46
46
  @color_background: @color_blue;
47
47
  @color_root_background: @color_background;
48
+ @color_root: @color_background;
48
49
  @color_default: #fff; // @color_light;
49
50
  @color_title_inv: #1b2733;
50
51
  @color_title: #4fd1d9; // #317396;
@@ -209,10 +209,9 @@
209
209
  }
210
210
  }
211
211
 
212
- .@{PCSS}-preloader{
212
+ .@{PCSS}-preloader {
213
213
  // background
214
- .GradientRadial(0%, 50%, @color_background, @color_root_background);
215
- background-color: @color_root_background;
214
+ .GradientRadial(0%, 50%, ~"var(--@{PCSS}-color-background)", ~"var(--@{PCSS}-color-root)");
215
+ background-color: ~"var(--@{PCSS}-color-root)";
216
216
  background-size: contain;
217
-
218
217
  }
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.51.4-abel",
2
+ "version": "0.51.4-babbage",
3
3
  "name": "pacem-less",
4
4
  "homepage": "https://js.pacem.it",
5
5
  "repository": {
@@ -13,6 +13,7 @@
13
13
  "README.md",
14
14
  "LICENSE",
15
15
  "NOTICE",
16
+ "themebuilder.js",
16
17
  "package.json"
17
18
  ],
18
19
  "author": {
package/shared.less CHANGED
@@ -10,6 +10,7 @@
10
10
  @semantic_colors: root, background, default, invert, primary, secondary, accent, info, success, warning, danger, error, disabled;
11
11
  @all_colors: root, background, default, invert, primary, secondary, accent, info, success, warning, danger, error, disabled, green, yellow, brown, red, pink, blue, orange, purple, teal, gray;
12
12
 
13
+ @palette_prebuilt: false;
13
14
 
14
15
  .Ellipsed(@max-width) {
15
16
  white-space: nowrap;
@@ -0,0 +1,224 @@
1
+ const fs = require('fs');
2
+ const vm = require('vm');
3
+ const path = require('path');
4
+ const yargs = require('yargs');
5
+ const argv = yargs
6
+ .option('theme', {
7
+ alias: 't',
8
+ type: 'string',
9
+ description: 'Theme (dark or light)',
10
+ })
11
+ .option('name', {
12
+ alias: 'n',
13
+ type: 'string',
14
+ description: 'Theme name',
15
+ })
16
+ .option('src', {
17
+ alias: 's',
18
+ type: 'string',
19
+ description: 'Palette file containing the color variables in JSON format.',
20
+ })
21
+ .option('out', {
22
+ alias: 'o',
23
+ type: 'string',
24
+ description: 'Output file (overrides name option).',
25
+ })
26
+ .option('pacemjs', {
27
+ type: 'string',
28
+ description: 'PacemJS javascript files folder.',
29
+ })
30
+ .option('void', {
31
+ type: 'string',
32
+ description: 'Creates an empty palette file.',
33
+ })
34
+ .help()
35
+ .argv;
36
+ const darkTheme = argv.theme === 'dark';
37
+ const themeName = argv.name ?? (darkTheme ? 'dark' : 'light');
38
+ function include(filename) {
39
+ const code = fs.readFileSync(filename, 'utf-8');
40
+ vm.runInThisContext(code, filename);
41
+ }
42
+ function importScripts(filepath) {
43
+ include(filepath);
44
+ }
45
+ function absolutePath(relativePath) {
46
+ return path.join(__dirname, relativePath);
47
+ }
48
+ const pjs = argv.pacemjs ?? absolutePath("../../dist/js");
49
+ importScripts(path.join(pjs, "pacem-foundation.js"));
50
+ importScripts(path.join(pjs, "pacem-numerical.js"));
51
+ function readFile(src) {
52
+ if (src == null) {
53
+ return null;
54
+ }
55
+ const json = fs.readFileSync(src, 'utf-8');
56
+ return JSON.parse(json);
57
+ }
58
+ const palette = readFile(argv.src) ?? {
59
+ background: '#1e2336',
60
+ primary: '#429bbb',
61
+ secondary: '#5e7881',
62
+ accent: '#ff0085',
63
+ success: '#4dc2b4',
64
+ warning: '#c5c023',
65
+ error: '#BF215B',
66
+ danger: '#fa1f1f',
67
+ info: '#99d4ff',
68
+ green: '#1ebb8f',
69
+ yellow: '#c2b010',
70
+ brown: '#a6715e',
71
+ red: '#dd2020',
72
+ pink: '#ff0085',
73
+ blue: '#116e8b',
74
+ orange: '#d46d00',
75
+ purple: '#624472',
76
+ teal: '#429bbb',
77
+ gray: '#808080',
78
+ };
79
+ const WCAG_MINIMUM_CONTRAST = 3;
80
+ const WCAG_NORMAL_TEXT_CONTRAST = 4.5;
81
+ const WCAG_SAFE_CONTRAST = 7;
82
+ const WCAG_MAX_CONTRAST = 17;
83
+ const SURFACE_LIGHT = .95;
84
+ const SURFACE_DARK = .02;
85
+ const MIN_SATURATION = .175;
86
+ const searchFn = Pacem.Mathematics.DataAnalysis.SearchFunctions.goldenRatio;
87
+ function isColorLight(clr) {
88
+ return Pacem.Colors.luminance(clr) >= .2;
89
+ }
90
+ function contrastColor(baseColor, targetContrast = WCAG_NORMAL_TEXT_CONTRAST) {
91
+ const { h, s, l, a } = Pacem.Colors.hsl(baseColor);
92
+ const isDark = !isColorLight(baseColor);
93
+ const min = isDark ? l : 0;
94
+ const max = isDark ? 1 : l;
95
+ const newL = searchFn(min, max, x => Math.abs(targetContrast - Pacem.Colors.contrastRatio(baseColor, { h, s, l: x, a })));
96
+ return Pacem.Colors.rgb({ h, s, l: newL, a });
97
+ }
98
+ function luminanceColor(baseColor, targetLuminance) {
99
+ const { h, s, a } = Pacem.Colors.hsl(baseColor);
100
+ const newL = searchFn(0, 1, x => Math.abs(targetLuminance - Pacem.Colors.luminance({ h, s, l: x, a })));
101
+ return Pacem.Colors.rgb({ h, s, l: newL, a });
102
+ }
103
+ function colorModule(clr, name, arg2) {
104
+ const isDisabled = name === 'disabled';
105
+ const isSurfaceColor = name === 'root' || name === 'background' || isDisabled;
106
+ const isDesaturated = isDisabled || name === 'gray';
107
+ const forcedContrast = (arg2 && typeof arg2 === 'number') ? arg2 : (isDisabled ? 1.7 : null);
108
+ const baseContrast = forcedContrast ?? (isSurfaceColor ? WCAG_MAX_CONTRAST : WCAG_SAFE_CONTRAST);
109
+ const contrastClr = arg2 && typeof arg2 === 'object' ? arg2 : null;
110
+ const surfaceLight = name === 'background' ? SURFACE_LIGHT + .015 : SURFACE_LIGHT;
111
+ const isColorRight = isSurfaceColor ? (darkTheme ? Pacem.Colors.luminance(clr) <= SURFACE_DARK : Pacem.Colors.luminance(clr) >= surfaceLight)
112
+ : isColorLight(clr) === darkTheme;
113
+ const darkTargetLuminance = isDisabled ? (SURFACE_DARK + .02) : (isSurfaceColor ? SURFACE_DARK : .175);
114
+ const lightTargetLuminance = isDisabled ? (surfaceLight - .1) : (isSurfaceColor ? surfaceLight : .333);
115
+ const referenceColor = isColorRight ? clr
116
+ : (isSurfaceColor ? (!darkTheme ? luminanceColor(clr, lightTargetLuminance) : luminanceColor(clr, darkTargetLuminance))
117
+ : (darkTheme ? luminanceColor(clr, lightTargetLuminance) : luminanceColor(clr, darkTargetLuminance)));
118
+ let actualColor = contrastClr ? clr : referenceColor;
119
+ if (isDesaturated) {
120
+ const { h, s, l, a } = Pacem.Colors.hsl(actualColor);
121
+ if (s > MIN_SATURATION) {
122
+ actualColor = Pacem.Colors.rgb({ h, s: MIN_SATURATION, l, a });
123
+ }
124
+ }
125
+ const luminanceBackContainer = darkTheme ? .075 : .5;
126
+ const luminanceBackActiveOffset = darkTheme ? (isSurfaceColor ? .035 : .1) : (isSurfaceColor ? -.08 : -.06);
127
+ const contrastForeActive = forcedContrast ?? WCAG_SAFE_CONTRAST;
128
+ const contrast = contrastClr ?? contrastColor(actualColor, baseContrast);
129
+ const container = luminanceColor(actualColor, luminanceBackContainer);
130
+ const containerContrast = contrastColor(container, isDisabled ? forcedContrast : WCAG_NORMAL_TEXT_CONTRAST);
131
+ const active = isDisabled ? actualColor : luminanceColor(actualColor, Pacem.Colors.luminance(actualColor) + luminanceBackActiveOffset);
132
+ const activeContrast = isDisabled ? contrast : contrastColor(active, contrastForeActive);
133
+ const containerActive = isDisabled ? container : luminanceColor(container, Pacem.Colors.luminance(container) + luminanceBackActiveOffset);
134
+ const containerActiveContrast = contrastColor(containerActive, contrastForeActive);
135
+ const emphasis = isDesaturated ? Pacem.Colors.lighten(actualColor, .1) : Pacem.Colors.saturate(actualColor, 1.2);
136
+ return {
137
+ base: actualColor,
138
+ contrast,
139
+ active,
140
+ activeContrast,
141
+ containerActive,
142
+ container,
143
+ emphasis,
144
+ containerActiveContrast,
145
+ containerContrast
146
+ };
147
+ }
148
+ const lessVariables = {};
149
+ let backgroundModule;
150
+ let rootModule;
151
+ const a255 = (x) => Math.round(x * 255);
152
+ const a255s = (c) => `${a255(c.r)}, ${a255(c.g)}, ${a255(c.b)}`;
153
+ const pushLessVariables = (name, mod) => {
154
+ lessVariables[`@color_${name}`] = Pacem.Colors.stringify(mod.base);
155
+ lessVariables[`@color_${name}_rgb`] = a255s(mod.base);
156
+ lessVariables[`@color_${name}_inv`] = Pacem.Colors.stringify(mod.contrast);
157
+ lessVariables[`@color_${name}_inv_rgb`] = a255s(mod.contrast);
158
+ lessVariables[`@color_${name}_container`] = Pacem.Colors.stringify(mod.container);
159
+ lessVariables[`@color_${name}_container_rgb`] = a255s(mod.container);
160
+ lessVariables[`@color_${name}_container_inv`] = Pacem.Colors.stringify(mod.containerContrast);
161
+ lessVariables[`@color_${name}_container_inv_rgb`] = a255s(mod.containerContrast);
162
+ lessVariables[`@color_${name}_active`] = Pacem.Colors.stringify(mod.active);
163
+ lessVariables[`@color_${name}_active_rgb`] = a255s(mod.active);
164
+ lessVariables[`@color_${name}_active_inv`] = Pacem.Colors.stringify(mod.activeContrast);
165
+ lessVariables[`@color_${name}_active_inv_rgb`] = a255s(mod.activeContrast);
166
+ lessVariables[`@color_${name}_container_active`] = Pacem.Colors.stringify(mod.containerActive);
167
+ lessVariables[`@color_${name}_container_active_rgb`] = a255s(mod.containerActive);
168
+ lessVariables[`@color_${name}_container_active_inv`] = Pacem.Colors.stringify(mod.containerActiveContrast);
169
+ lessVariables[`@color_${name}_container_active_inv_rgb`] = a255s(mod.containerActiveContrast);
170
+ lessVariables[`@color_${name}_emphasis`] = Pacem.Colors.stringify(mod.emphasis);
171
+ lessVariables[`@color_${name}_emphasis_rgb`] = a255s(mod.emphasis);
172
+ };
173
+ for (let name in palette) {
174
+ const color = Pacem.Colors.parse(palette[name]);
175
+ const mod = colorModule(color, name);
176
+ if (name === 'background') {
177
+ backgroundModule = mod;
178
+ }
179
+ if (name === 'root') {
180
+ rootModule = mod;
181
+ }
182
+ pushLessVariables(name, mod);
183
+ }
184
+ if (!('root' in palette)) {
185
+ const rootColor = Pacem.Colors.darken(backgroundModule.base, darkTheme ? .02 : .01);
186
+ rootModule = colorModule(rootColor, 'root');
187
+ pushLessVariables('root', rootModule);
188
+ }
189
+ if (!('disabled' in palette)) {
190
+ const disabledColor = darkTheme ? Pacem.Colors.lighten(backgroundModule.base, .04) : Pacem.Colors.darken(backgroundModule.base, .085);
191
+ pushLessVariables('disabled', colorModule(disabledColor, 'disabled'));
192
+ }
193
+ if (!('default' in palette)) {
194
+ for (let name of ['default', 'invert']) {
195
+ lessVariables[`@color_${name}`] = Pacem.Colors.stringify(rootModule.contrast);
196
+ lessVariables[`@color_${name}_rgb`] = a255s(rootModule.contrast);
197
+ lessVariables[`@color_${name}_inv`] = Pacem.Colors.stringify(rootModule.base);
198
+ lessVariables[`@color_${name}_inv_rgb`] = a255s(rootModule.base);
199
+ lessVariables[`@color_${name}_container`] = Pacem.Colors.stringify(rootModule.containerContrast);
200
+ lessVariables[`@color_${name}_container_rgb`] = a255s(rootModule.containerContrast);
201
+ lessVariables[`@color_${name}_container_inv`] = Pacem.Colors.stringify(rootModule.container);
202
+ lessVariables[`@color_${name}_container_inv_rgb`] = a255s(rootModule.container);
203
+ lessVariables[`@color_${name}_active`] = Pacem.Colors.stringify(rootModule.activeContrast);
204
+ lessVariables[`@color_${name}_active_rgb`] = a255s(rootModule.activeContrast);
205
+ lessVariables[`@color_${name}_active_inv`] = Pacem.Colors.stringify(rootModule.active);
206
+ lessVariables[`@color_${name}_active_inv_rgb`] = a255s(rootModule.active);
207
+ lessVariables[`@color_${name}_container_active`] = Pacem.Colors.stringify(rootModule.containerActiveContrast);
208
+ lessVariables[`@color_${name}_container_active_rgb`] = a255s(rootModule.containerActiveContrast);
209
+ lessVariables[`@color_${name}_container_active_inv`] = Pacem.Colors.stringify(rootModule.containerActive);
210
+ lessVariables[`@color_${name}_container_active_inv_rgb`] = a255s(rootModule.containerActive);
211
+ lessVariables[`@color_${name}_emphasis`] = lessVariables[`@color_${name}`];
212
+ lessVariables[`@color_${name}_emphasis_rgb`] = lessVariables[`@color_${name}_rgb`];
213
+ }
214
+ }
215
+ let lessText = '@palette_prebuilt: true;\r\n';
216
+ for (let name in lessVariables) {
217
+ const hex = lessVariables[name];
218
+ lessText += `${name}: ${hex};\r\n`;
219
+ }
220
+ const target = argv.out ?? absolutePath('./pacem/palette-' + themeName + '.less');
221
+ if (!Pacem.NullChecker.isNull(argv.void)) {
222
+ lessText = '';
223
+ }
224
+ fs.writeFileSync(target, lessText);