@servicetitan/hammer-token 0.0.0-themeprovider-refactor.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 (37) hide show
  1. package/.turbo/turbo-build.log +28 -0
  2. package/.turbo/turbo-lint.log +4 -0
  3. package/CHANGELOG.md +260 -0
  4. package/build/web/core/css-utils/border.css +13 -0
  5. package/build/web/core/css-utils/color.css +89 -0
  6. package/build/web/core/css-utils/font.css +21 -0
  7. package/build/web/core/css-utils/spacing.css +204 -0
  8. package/build/web/core/css-utils/utils.css +322 -0
  9. package/build/web/core/index.js +4 -0
  10. package/build/web/core/primitive.js +115 -0
  11. package/build/web/core/primitive.scss +115 -0
  12. package/build/web/core/raw.js +125 -0
  13. package/build/web/core/semantic-variables.scss +150 -0
  14. package/build/web/core/semantic.js +463 -0
  15. package/build/web/core/semantic.scss +76 -0
  16. package/build/web/index.d.ts +4 -0
  17. package/build/web/index.js +3 -0
  18. package/config.js +345 -0
  19. package/package.json +25 -0
  20. package/src/global/primitive/breakpoint.json +19 -0
  21. package/src/global/primitive/color.json +231 -0
  22. package/src/global/primitive/duration.json +16 -0
  23. package/src/global/primitive/font.json +60 -0
  24. package/src/global/primitive/size.json +55 -0
  25. package/src/global/primitive/transition.json +16 -0
  26. package/src/theme/core/background.json +144 -0
  27. package/src/theme/core/border.json +84 -0
  28. package/src/theme/core/focus.json +31 -0
  29. package/src/theme/core/foreground.json +88 -0
  30. package/src/theme/core/overlay.json +134 -0
  31. package/src/theme/core/shadow.json +25 -0
  32. package/src/theme/core/status.json +46 -0
  33. package/src/theme/core/typography.json +79 -0
  34. package/src/utils/copy-css-utils-cli.js +49 -0
  35. package/src/utils/css-utils-format-utils.js +185 -0
  36. package/test.txt +1 -0
  37. package/type/types.ts +215 -0
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable @typescript-eslint/no-var-requires */
3
+ const { program } = require("commander");
4
+ const path = require("path");
5
+ const fs = require("fs");
6
+
7
+ function run() {
8
+ program
9
+ .command("copy-css-utils")
10
+ .description("Copy the CSS Utils files from hammer-token into your project")
11
+ .argument("<string>", "directory to copy CSS utils files to")
12
+ .option(
13
+ "-p, --prefix <char>",
14
+ "optionally override prefix from 'hammer-' to a custom one",
15
+ )
16
+ .action((dir, options) => {
17
+ console.log(`Copying CSS Utils files to: ${dir}`);
18
+ const cssUtilsFilesPathString = path.resolve(
19
+ __dirname,
20
+ "../../build/web/core/css-utils",
21
+ );
22
+ fs.cpSync(cssUtilsFilesPathString, dir, { recursive: true });
23
+ if (options.prefix) {
24
+ console.log(`Replacing ".hammer-" with ".${options.prefix}-"`);
25
+ const copiedFiles = fs.readdirSync(dir, { encoding: "utf-8" });
26
+ copiedFiles.forEach((file) => {
27
+ const fileWithDir = `${dir}/${file}`;
28
+ fs.readFile(fileWithDir, "utf-8", (err, contents) => {
29
+ if (err) {
30
+ return console.error(err);
31
+ }
32
+
33
+ const contentsWithNewPrefix = contents.replace(
34
+ /hammer/gi,
35
+ options.prefix,
36
+ );
37
+
38
+ fs.writeFile(fileWithDir, contentsWithNewPrefix, "utf-8", (e) => {
39
+ if (e) console.log(e);
40
+ });
41
+ });
42
+ });
43
+ }
44
+ });
45
+
46
+ program.parse();
47
+ }
48
+
49
+ run();
@@ -0,0 +1,185 @@
1
+ const DARK_MODE_CLASS = ".hammer-themeprovider-core-dark";
2
+
3
+ const cssUtilsFormatter = (dictionary, generateFn, hasDarkValues) => {
4
+ return dictionary.allTokens
5
+ .map((token) => {
6
+ let value = getVarValue(dictionary, token);
7
+ const name = `${token.name.replace("Default", "")}`;
8
+ if (hasDarkValues && token.attributes.appearance) {
9
+ const darkValue = getVarValue(dictionary, token, true);
10
+ return generateFn(name, value, darkValue);
11
+ }
12
+ return generateFn(name, value);
13
+ })
14
+ .flat()
15
+ .map((t) => `${t}`)
16
+ .sort((a, b) => a.localeCompare(b))
17
+ .join(`\n`);
18
+ };
19
+
20
+ const getNewValueFromRef = (value, ref) => {
21
+ return value.replace(ref.value, function () {
22
+ // fallback for nested vars
23
+ if (ref.name === undefined) {
24
+ return `${ref.value}`;
25
+ } else {
26
+ return `var(--${ref.name}, ${ref.value})`;
27
+ }
28
+ });
29
+ };
30
+
31
+ const colorHasAlphaValue = (value) => {
32
+ // e.g. var(--something)44 isn't valid
33
+ return /\)[\d]+/.test(value);
34
+ };
35
+
36
+ /**
37
+ * Allow for CSS var instead of static value
38
+ */
39
+ const getVarValue = (dictionary, token, isDarkValue) => {
40
+ let value;
41
+
42
+ if (isDarkValue) {
43
+ value = JSON.stringify(token.attributes.appearance.dark.value);
44
+ if (
45
+ dictionary.usesReference(token.original.attributes.appearance.dark.value)
46
+ ) {
47
+ const refs = dictionary.getReferences(
48
+ token.original.attributes.appearance.dark.value,
49
+ );
50
+ refs.forEach((ref) => {
51
+ const newValue = getNewValueFromRef(value, ref);
52
+ if (colorHasAlphaValue(newValue) === false) {
53
+ value = newValue;
54
+ }
55
+ });
56
+ }
57
+ } else {
58
+ value = JSON.stringify(token.value);
59
+ if (dictionary.usesReference(token.original.value)) {
60
+ const refs = dictionary.getReferences(token.original.value);
61
+ refs.forEach((ref) => {
62
+ const newValue = getNewValueFromRef(value, ref);
63
+ if (colorHasAlphaValue(newValue) === false) {
64
+ value = newValue;
65
+ }
66
+ });
67
+ }
68
+ }
69
+
70
+ return value.replaceAll('"', "");
71
+ };
72
+
73
+ const generateBorderClasses = (name, value) => {
74
+ const classes = [];
75
+
76
+ if (name.startsWith("border-radius")) {
77
+ classes.push(`.${name} {border-radius: ${value}}`);
78
+ } else if (name.startsWith("border-width")) {
79
+ classes.push(`.${name} {border-width: ${value}}`);
80
+ } else if (name.startsWith("border-color")) {
81
+ classes.push(`.${name} {border-color: ${value}}`);
82
+ }
83
+
84
+ return classes;
85
+ };
86
+
87
+ const generateColorClasses = (name, value, darkValue) => {
88
+ const classes = [];
89
+
90
+ if (name.startsWith("background-color")) {
91
+ classes.push(
92
+ `.${name.replace("background-color", "bg")} {background-color: ${value}}`,
93
+ `${DARK_MODE_CLASS} .${name.replace("background-color", "bg")} {background-color: ${darkValue}}`,
94
+ );
95
+ } else if (name.startsWith("foreground-color")) {
96
+ classes.push(
97
+ `.${name.replace("foreground-color", "c")} {color: ${value}}`,
98
+ `${DARK_MODE_CLASS} .${name.replace("foreground-color", "c")} {color: ${darkValue}}`,
99
+ );
100
+ } else if (name.startsWith("overlay-color")) {
101
+ classes.push(
102
+ `.${name.replace("overlay-color", "bg-overlay")} {background-color: ${value}}`,
103
+ `${DARK_MODE_CLASS} .${name.replace("overlay-color", "bg-overlay")} {background-color: ${darkValue}}`,
104
+ );
105
+ // primitives
106
+ // } else if (name.startsWith("color")) {
107
+ // classes.push(
108
+ // `.${name.replace("color", "c")} {color: ${value}}`,
109
+ // `.${name.replace("color", "bg")} {background-color: ${value}}`,
110
+ // );
111
+ } else if (name.startsWith("status-color")) {
112
+ classes.push(
113
+ `.${name.replace("status-color", "c-status")} {color: ${value}}`,
114
+ `.${name.replace("status-color", "bg-status")} {background-color: ${value}}`,
115
+ `${DARK_MODE_CLASS} .${name.replace("status-color", "c-status")} {color: ${darkValue}}`,
116
+ `${DARK_MODE_CLASS} .${name.replace("status-color", "bg-status")} {background-color: ${darkValue}}`,
117
+ );
118
+ if (!name.includes("danger")) {
119
+ classes.push(
120
+ `.${name.replace("status-color", "border-color-status")} {border-color: ${value}}`,
121
+ `${DARK_MODE_CLASS} .${name.replace("status-color", "border-color-status")} {border-color: ${darkValue}}`,
122
+ );
123
+ }
124
+ } else if (name.startsWith("border-color")) {
125
+ classes.push(`.${name} {border-color: ${value}}`);
126
+ }
127
+
128
+ return classes;
129
+ };
130
+
131
+ const generateFontClasses = (name, value) => {
132
+ const classes = [];
133
+
134
+ if (name.startsWith("typography")) {
135
+ if (name.includes("-font-family")) {
136
+ classes.push(
137
+ `.${name.replace("typography", "ff").replace("-font-family", "")} {font-family: ${value}}`,
138
+ );
139
+ } else if (name.includes("-font-weight")) {
140
+ classes.push(
141
+ `.${name.replace("typography", "fw").replace("-font-weight", "")} {font-weight: ${value}}`,
142
+ );
143
+ } else if (name.includes("-size")) {
144
+ classes.push(
145
+ `.${name.replace("typography", "fs").replace("-size", "")} {font-size: ${value}}`,
146
+ );
147
+ }
148
+ }
149
+
150
+ return classes;
151
+ };
152
+
153
+ const generateSpacingClasses = (name, value) => {
154
+ const nameWithoutPrefix = name.substring(name.indexOf("-"));
155
+
156
+ const directions = [
157
+ "inline-start",
158
+ "inline-end",
159
+ "block-start",
160
+ "block-end",
161
+ "block",
162
+ "inline",
163
+ ];
164
+ const classes = [];
165
+
166
+ directions.forEach((direction) => {
167
+ classes.push(
168
+ `.m-${direction}${nameWithoutPrefix} {margin-${direction}: var(--${name}, ${value})}`,
169
+ );
170
+ classes.push(
171
+ `.p-${direction}${nameWithoutPrefix} {padding-${direction}: var(--${name}, ${value})}`,
172
+ );
173
+ });
174
+
175
+ return classes;
176
+ };
177
+
178
+ module.exports = {
179
+ cssUtilsFormatter,
180
+ getVarValue,
181
+ generateBorderClasses,
182
+ generateColorClasses,
183
+ generateFontClasses,
184
+ generateSpacingClasses,
185
+ };
package/test.txt ADDED
@@ -0,0 +1 @@
1
+ v1.0.0!
package/type/types.ts ADDED
@@ -0,0 +1,215 @@
1
+ export type TokenObj = {
2
+ value: string;
3
+ attributes?: {
4
+ appearance?: {
5
+ dark?: {
6
+ value: string;
7
+ };
8
+ };
9
+ };
10
+ };
11
+
12
+ export type Primitive = {
13
+ ColorBlue100: TokenObj;
14
+ ColorBlue200: TokenObj;
15
+ ColorBlue300: TokenObj;
16
+ ColorBlue400: TokenObj;
17
+ ColorBlue500: TokenObj;
18
+ ColorBlue600: TokenObj;
19
+ ColorNeutral0: TokenObj;
20
+ ColorNeutral10: TokenObj;
21
+ ColorNeutral20: TokenObj;
22
+ ColorNeutral30: TokenObj;
23
+ ColorNeutral40: TokenObj;
24
+ ColorNeutral50: TokenObj;
25
+ ColorNeutral60: TokenObj;
26
+ ColorNeutral70: TokenObj;
27
+ ColorNeutral80: TokenObj;
28
+ ColorNeutral90: TokenObj;
29
+ ColorNeutral100: TokenObj;
30
+ ColorNeutral200: TokenObj;
31
+ ColorNeutral300: TokenObj;
32
+ ColorNeutral400: TokenObj;
33
+ ColorNeutral500: TokenObj;
34
+ ColorBlueGrey100: TokenObj;
35
+ ColorBlueGrey200: TokenObj;
36
+ ColorBlueGrey300: TokenObj;
37
+ ColorBlueGrey400: TokenObj;
38
+ ColorBlueGrey500: TokenObj;
39
+ ColorBlueGrey600: TokenObj;
40
+ ColorOrange100: TokenObj;
41
+ ColorOrange200: TokenObj;
42
+ ColorOrange300: TokenObj;
43
+ ColorOrange400: TokenObj;
44
+ ColorOrange500: TokenObj;
45
+ ColorOrange600: TokenObj;
46
+ ColorYellow100: TokenObj;
47
+ ColorYellow200: TokenObj;
48
+ ColorYellow300: TokenObj;
49
+ ColorYellow400: TokenObj;
50
+ ColorYellow500: TokenObj;
51
+ ColorYellow600: TokenObj;
52
+ ColorGreen100: TokenObj;
53
+ ColorGreen200: TokenObj;
54
+ ColorGreen300: TokenObj;
55
+ ColorGreen400: TokenObj;
56
+ ColorGreen500: TokenObj;
57
+ ColorGreen600: TokenObj;
58
+ ColorCyan100: TokenObj;
59
+ ColorCyan200: TokenObj;
60
+ ColorCyan300: TokenObj;
61
+ ColorCyan400: TokenObj;
62
+ ColorCyan500: TokenObj;
63
+ ColorCyan600: TokenObj;
64
+ ColorPurple100: TokenObj;
65
+ ColorPurple200: TokenObj;
66
+ ColorPurple300: TokenObj;
67
+ ColorPurple400: TokenObj;
68
+ ColorPurple500: TokenObj;
69
+ ColorPurple600: TokenObj;
70
+ ColorRed100: TokenObj;
71
+ ColorRed200: TokenObj;
72
+ ColorRed300: TokenObj;
73
+ ColorRed400: TokenObj;
74
+ ColorRed500: TokenObj;
75
+ ColorRed600: TokenObj;
76
+ ColorMagenta100: TokenObj;
77
+ ColorMagenta200: TokenObj;
78
+ ColorMagenta300: TokenObj;
79
+ ColorMagenta400: TokenObj;
80
+ ColorMagenta500: TokenObj;
81
+ ColorMagenta600: TokenObj;
82
+ Duration: TokenObj;
83
+ DurationInstant: TokenObj;
84
+ DurationFast: TokenObj;
85
+ DurationSlow: TokenObj;
86
+ FontFamilyBase: TokenObj;
87
+ FontFamilyDisplay: TokenObj;
88
+ FontLineHeightBase: TokenObj;
89
+ FontLineHeightDisplay: TokenObj;
90
+ FontWeightNormal: TokenObj;
91
+ FontWeightSemibold: TokenObj;
92
+ FontWeightBold: TokenObj;
93
+ FontSize100: TokenObj;
94
+ FontSize200: TokenObj;
95
+ FontSize300: TokenObj;
96
+ FontSize400: TokenObj;
97
+ FontSize500: TokenObj;
98
+ FontSize600: TokenObj;
99
+ FontSize700: TokenObj;
100
+ FontSize800: TokenObj;
101
+ FontSize900: TokenObj;
102
+ Size0: TokenObj;
103
+ Size1: TokenObj;
104
+ Size2: TokenObj;
105
+ Size3: TokenObj;
106
+ Size4: TokenObj;
107
+ Size5: TokenObj;
108
+ Size6: TokenObj;
109
+ Size7: TokenObj;
110
+ Size8: TokenObj;
111
+ Size9: TokenObj;
112
+ Size10: TokenObj;
113
+ Size11: TokenObj;
114
+ Size12: TokenObj;
115
+ Size13: TokenObj;
116
+ Size14: TokenObj;
117
+ SizeQuarter: TokenObj;
118
+ SizeHalf: TokenObj;
119
+ TransitionEase: TokenObj;
120
+ TransitionEaseIn: TokenObj;
121
+ TransitionEaseOut: TokenObj;
122
+ TransitionEaseInOut: TokenObj;
123
+ BreakpointSm: TokenObj;
124
+ BreakpointMd: TokenObj;
125
+ BreakpointLg: TokenObj;
126
+ BreakpointXl: TokenObj;
127
+ BreakpointXxl: TokenObj;
128
+ };
129
+
130
+ export type Semantic = {
131
+ BackgroundColor: TokenObj;
132
+ BackgroundColorStrong: TokenObj;
133
+ BackgroundColorStronger: TokenObj;
134
+ BackgroundColorStrongest: TokenObj;
135
+ BackgroundColorPrimary: TokenObj;
136
+ BackgroundColorPrimarySubdued: TokenObj;
137
+ BackgroundColorDanger: TokenObj;
138
+ BackgroundColorWarning: TokenObj;
139
+ BackgroundColorInverted: TokenObj;
140
+ BackgroundColorInvertedStrong: TokenObj;
141
+ BackgroundColorDisabled: TokenObj;
142
+ BorderRadiusNone: TokenObj;
143
+ BorderRadiusRounded: TokenObj;
144
+ BorderRadiusRoundedStrong: TokenObj;
145
+ BorderRadiusPill: TokenObj;
146
+ BorderRadiusCircular: TokenObj;
147
+ BorderWidthNone: TokenObj;
148
+ BorderWidth: TokenObj;
149
+ BorderWidthStrong: TokenObj;
150
+ BorderColor: TokenObj;
151
+ BorderColorStrong: TokenObj;
152
+ BorderColorSubdued: TokenObj;
153
+ BorderColorPrimary: TokenObj;
154
+ BorderColorDanger: TokenObj;
155
+ FocusRingColor: TokenObj;
156
+ FocusRingColorDanger: TokenObj;
157
+ FocusRingWidth: TokenObj;
158
+ ForegroundColor: TokenObj;
159
+ ForegroundColorSubdued: TokenObj;
160
+ ForegroundColorPrimary: TokenObj;
161
+ ForegroundColorDanger: TokenObj;
162
+ ForegroundColorInverted: TokenObj;
163
+ ForegroundColorOnPrimary: TokenObj;
164
+ ForegroundColorOnDanger: TokenObj;
165
+ ForegroundColorOnWarning: TokenObj;
166
+ OverlayColorActive: TokenObj;
167
+ OverlayColorActivePrimary: TokenObj;
168
+ OverlayColorActiveDanger: TokenObj;
169
+ OverlayColorActiveOn: TokenObj;
170
+ OverlayColorActiveOnPrimary: TokenObj;
171
+ OverlayColorActiveOnDanger: TokenObj;
172
+ OverlayColorHover: TokenObj;
173
+ OverlayColorHoverPrimary: TokenObj;
174
+ OverlayColorHoverDanger: TokenObj;
175
+ OverlayColorHoverOn: TokenObj;
176
+ OverlayColorHoverOnPrimary: TokenObj;
177
+ OverlayColorHoverOnDanger: TokenObj;
178
+ ShadowColor: TokenObj;
179
+ ShadowSizeFlat: TokenObj;
180
+ ShadowSizeFloat: TokenObj;
181
+ ShadowSizeOverlay: TokenObj;
182
+ StatusColorInfo: TokenObj;
183
+ StatusColorDanger: TokenObj;
184
+ StatusColorSuccess: TokenObj;
185
+ StatusColorWarning: TokenObj;
186
+ TypographyParagraphSizeXsmall: TokenObj;
187
+ TypographyParagraphSizeSmall: TokenObj;
188
+ TypographyParagraphSize: TokenObj;
189
+ TypographyParagraphSizeLarge: TokenObj;
190
+ TypographyParagraphSizeXlarge: TokenObj;
191
+ TypographyParagraphFontWeight: TokenObj;
192
+ TypographyParagraphFontFamily: TokenObj;
193
+ TypographyHeadingSizeXsmall: TokenObj;
194
+ TypographyHeadingSizeSmall: TokenObj;
195
+ TypographyHeadingSize: TokenObj;
196
+ TypographyHeadingSizeLarge: TokenObj;
197
+ TypographyHeadingSizeXlarge: TokenObj;
198
+ TypographyHeadingFontWeight: TokenObj;
199
+ TypographyHeadingFontFamily: TokenObj;
200
+ TypographyLabelSizeXsmall: TokenObj;
201
+ TypographyLabelSizeSmall: TokenObj;
202
+ TypographyLabelSize: TokenObj;
203
+ TypographyLabelSizeLarge: TokenObj;
204
+ TypographyLabelSizeXlarge: TokenObj;
205
+ TypographyLabelFontWeight: TokenObj;
206
+ TypographyLabelFontFamily: TokenObj;
207
+ };
208
+
209
+ type Token = {
210
+ primitive: Primitive;
211
+ semantic: Semantic;
212
+ name: string;
213
+ };
214
+
215
+ export default Token;