@jobber/design 0.27.9 → 0.28.1

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 (46) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/buildColors.js +15 -0
  3. package/buildFoundation.js +15 -0
  4. package/buildIconStyles.js +44 -0
  5. package/colors.js +138 -0
  6. package/foundation.css +33 -26
  7. package/foundation.js +7 -7
  8. package/foundation.scss +6 -6
  9. package/foundation_config/postcss-filter-rules/index.js +17 -0
  10. package/foundation_config/postcss.config.js +58 -0
  11. package/jobberStyle.js +243 -0
  12. package/npm-shrinkwrap.json +8594 -0
  13. package/package.json +18 -11
  14. package/rollup.config.js +41 -0
  15. package/src/Borders.mdx +65 -0
  16. package/src/Colors.mdx +295 -0
  17. package/src/Elevations.mdx +107 -0
  18. package/src/Radii.mdx +40 -0
  19. package/src/ResponsiveBreakpoints.mdx +48 -0
  20. package/src/Spacing.mdx +121 -0
  21. package/src/Typography.mdx +191 -0
  22. package/src/animation.mdx +82 -0
  23. package/src/borders.css +6 -0
  24. package/src/colors.css +178 -0
  25. package/src/elevations.css +12 -0
  26. package/src/foundation.css +11 -0
  27. package/src/icons/Colors.css +187 -0
  28. package/src/icons/Colors.css.d.ts +51 -0
  29. package/src/icons/Icon.css +102 -0
  30. package/src/icons/Icon.css.d.ts +37 -0
  31. package/src/icons/Sizes.css +14 -0
  32. package/src/icons/Sizes.css.d.ts +7 -0
  33. package/src/icons/getIcon.test.ts +73 -0
  34. package/src/icons/getIcon.ts +116 -0
  35. package/src/icons/iconMap.ts +430 -0
  36. package/src/icons/iconStyles.d.ts +262 -0
  37. package/src/icons/iconStyles.ts +269 -0
  38. package/src/index.ts +10 -0
  39. package/src/radii.css +6 -0
  40. package/src/responsiveBreakpoints.css +3 -0
  41. package/src/shadows.css +13 -0
  42. package/src/spacing.css +13 -0
  43. package/src/styles.css +9 -0
  44. package/src/timings.css +7 -0
  45. package/src/typography.css +53 -0
  46. package/tsconfig.json +70 -0
package/jobberStyle.js ADDED
@@ -0,0 +1,243 @@
1
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
+ const fs = require("fs");
3
+ // eslint-disable-next-line import/no-internal-modules
4
+ const customPropertiesObject = require("./src/foundation.js");
5
+
6
+ const regexExpressions = {
7
+ cssVars: /var\((.*)\)/,
8
+ calculations: /calc\((.*)\)/,
9
+ rgbVars: /rgb\(var\((.*)\)\)/,
10
+ rgbaVars: /rgba\(var\((.*)\),?(.*)\)/,
11
+ removeAllNonNumerals: /[^0-9.+\-/*]/gi,
12
+ extractAllVarGroups: /var\(.*?\)/g,
13
+ };
14
+
15
+ const customProperties = customPropertiesObject.customProperties;
16
+
17
+ const resolvedCssVars = getResolvedCSSVars(customProperties);
18
+
19
+ const jsonContent =
20
+ "export const JobberStyle = " + JSON.stringify(resolvedCssVars, undefined, 2);
21
+
22
+ fs.writeFile("./foundation.js", jsonContent, "utf8", function (err) {
23
+ if (err) {
24
+ console.log("An error occured while writing JSON object to File.");
25
+ return console.log(err);
26
+ }
27
+ console.log("JSON file has been saved.");
28
+ });
29
+
30
+ const scssColors = getResolvedSCSSVariables(resolvedCssVars);
31
+
32
+ fs.writeFile(
33
+ "./foundation.scss",
34
+ scssColors.join("\n"),
35
+ "utf-8",
36
+ function (err) {
37
+ if (err) {
38
+ console.log("An error occured while writing SCSS to File.");
39
+ return console.log(err);
40
+ }
41
+ console.log("SCSS file has been saved.");
42
+ },
43
+ );
44
+
45
+ /**
46
+ * Recursively resolve css custom properties.
47
+ *
48
+ * eg:
49
+ * ```
50
+ * jobberStyle(`
51
+ * "--base": "5px",
52
+ * "--foo": "calc(var(--base) * 2),
53
+ * `);
54
+ * ```
55
+ * =>
56
+ * ```
57
+ * {
58
+ * "--base": "5",
59
+ * "--foo": "10",
60
+ * }
61
+ * ```
62
+ */
63
+
64
+ function jobberStyle(styling) {
65
+ const styleValue = customProperties[styling];
66
+
67
+ //varRegexResult returns --base-unit from var(--base-unit)
68
+ const varRegexResult = regexExpressions.cssVars.exec(styleValue);
69
+ //rgbVarRegexResult returns --base-unit from rgb(var(--base-unit))
70
+ const rgbVarRegexResult = regexExpressions.rgbVars.exec(styleValue);
71
+ //rgbaVarRegexResult returns --base-unit and alpha (if exists) from rgba(var(--base-unit), alpha)
72
+ const rgbaVarRegexResult = regexExpressions.rgbaVars.exec(styleValue);
73
+
74
+ //calcRegexResult returns var(--base-unit) / 16 from calc(var(--base-unit) / 16)
75
+ const calcRegexResult = regexExpressions.calculations.exec(styleValue);
76
+ if (calcRegexResult) {
77
+ return handleCalc(calcRegexResult);
78
+ } else if (rgbVarRegexResult) {
79
+ return jobberStyle(rgbVarRegexResult[1]);
80
+ } else if (rgbaVarRegexResult) {
81
+ return handleRbga(rgbaVarRegexResult);
82
+ } else if (varRegexResult) {
83
+ return jobberStyle(varRegexResult[1]);
84
+ } else {
85
+ return isSpacingValue(styleValue) ? parseFloat(styleValue) : styleValue;
86
+ }
87
+ }
88
+
89
+ function handleCalc(calcRegexResult) {
90
+ const finalExpression = handleExpressionsInCalc(calcRegexResult);
91
+ // eslint-disable-next-line no-new-func
92
+ const calculatedValue = new Function(
93
+ "return " +
94
+ finalExpression.replace(regexExpressions.removeAllNonNumerals, ""),
95
+ )();
96
+ return isSpacingValue(calculatedValue)
97
+ ? parseFloat(calculatedValue)
98
+ : calculatedValue;
99
+ }
100
+
101
+ function handleRbga(rgbaVarRegexResult) {
102
+ let resolved = "rgba(" + jobberStyle(rgbaVarRegexResult[1]);
103
+ if (rgbaVarRegexResult[2]) {
104
+ resolved += "," + rgbaVarRegexResult[2];
105
+ }
106
+ resolved += ")";
107
+
108
+ return resolved;
109
+ }
110
+
111
+ function handleExpressionsInCalc(calcRegexResult) {
112
+ const calcExtract = calcRegexResult[1];
113
+ const varGroups = calcExtract.match(regexExpressions.extractAllVarGroups);
114
+ let finalExpression = calcExtract;
115
+ varGroups &&
116
+ varGroups.forEach(group => {
117
+ const cssVariableRegexResult = regexExpressions.cssVars.exec(group);
118
+ if (cssVariableRegexResult) {
119
+ finalExpression = resolveCssVarsInExpression({
120
+ group,
121
+ cssVariableRegexResult,
122
+ finalExpression,
123
+ });
124
+ }
125
+ });
126
+ return finalExpression;
127
+ }
128
+
129
+ function resolveCssVarsInExpression({
130
+ group,
131
+ cssVariableRegexResult,
132
+ finalExpression,
133
+ }) {
134
+ const cssVariable = cssVariableRegexResult[1];
135
+ const realValue = jobberStyle(cssVariable);
136
+ const unresolvedCssVariable = group;
137
+ return finalExpression.replace(unresolvedCssVariable, realValue);
138
+ }
139
+
140
+ function isSpacingValue(value) {
141
+ return !!String(value).match(
142
+ /(^\d+(px|%|rem|em|ex|ch|vw|vh|vmin|vmax)$)|(^\d+$)/,
143
+ );
144
+ }
145
+
146
+ function getResolvedCSSVars(cssProperties) {
147
+ const allKeys = Object.keys(cssProperties);
148
+ return allKeys.reduce((acc, key) => {
149
+ const newKey = key.replace("--", "");
150
+ acc[newKey] = jobberStyle(key);
151
+ return acc;
152
+ }, {});
153
+ }
154
+
155
+ function getResolvedSCSSVariables(cssProperties) {
156
+ const allKeys = Object.keys(cssProperties);
157
+
158
+ return allKeys.reduce((acc, cssVar) => {
159
+ const propertyValue = getPropertyValue(cssVar);
160
+
161
+ if (propertyValue) {
162
+ return [...acc, `$${cssVar}: ${propertyValue};`];
163
+ }
164
+
165
+ return acc;
166
+ }, []);
167
+ }
168
+
169
+ function resolveShadow(shadowValue) {
170
+ const splitValue = shadowValue.split(" ").filter(n => n);
171
+
172
+ return splitValue
173
+ .map(value => {
174
+ const varRegexResult = regexExpressions.cssVars.exec(value);
175
+
176
+ if (varRegexResult) {
177
+ const result = jobberStyle(varRegexResult[1]);
178
+ const suffix = typeof result === "string" ? "" : "px";
179
+
180
+ return `${result}${suffix}`;
181
+ }
182
+
183
+ return value;
184
+ })
185
+ .join(" ");
186
+ }
187
+
188
+ function getVariableType(cssVar) {
189
+ const includesInArray = v => cssVar.includes(v);
190
+
191
+ const isSizeVariables = ["border", "radius"].some(includesInArray);
192
+ const isSimpleVariables = [
193
+ "color",
194
+ "timing",
195
+ "elevation",
196
+ "lineHeight",
197
+ "fontFamily",
198
+ "letterSpacing-base",
199
+ ].some(includesInArray);
200
+ const isCalcVariables = ["space", "letterSpacing-loose", "fontSize"].some(
201
+ includesInArray,
202
+ );
203
+ const isShadowVariable = cssVar.includes("shadow");
204
+
205
+ if (isSimpleVariables) return "simple";
206
+ if (isSizeVariables) return "size";
207
+ if (isCalcVariables) return "calc";
208
+ if (isShadowVariable) return "shadow";
209
+ }
210
+
211
+ function getPropertyValue(cssVar) {
212
+ const customPropertyValue = customProperties["--" + cssVar];
213
+ const variableType = getVariableType(cssVar);
214
+
215
+ switch (variableType) {
216
+ case "simple":
217
+ return `${resolvedCssVars[cssVar]}`;
218
+ case "calc": {
219
+ const calcRegexResult = regexExpressions.calculations.exec(
220
+ removeNewLines(customPropertyValue),
221
+ );
222
+
223
+ return `${handleCalc(calcRegexResult)}px`;
224
+ }
225
+ case "size": {
226
+ const suffix = customPropertyValue.includes("%") ? "%" : "px";
227
+ return `${resolvedCssVars[cssVar]}${suffix}`;
228
+ }
229
+ case "shadow":
230
+ return `${resolveShadow(customPropertyValue)}`;
231
+ default:
232
+ return "";
233
+ }
234
+ }
235
+
236
+ /**
237
+ *
238
+ * Removes all types of line breaks from the text
239
+ * Reference: https://stackoverflow.com/a/10805198
240
+ */
241
+ function removeNewLines(text) {
242
+ return text.replace(/(\r\n|\n|\r)/gm, "");
243
+ }