reshaped 2.6.1 → 2.6.3

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.
@@ -7,7 +7,7 @@ import Theme from "../Theme/index.js";
7
7
  import Text from "../Text/index.js";
8
8
  import s from "./Toast.module.css";
9
9
  const Toast = (props) => {
10
- const { size = "small", text, children, color = "inverted", icon, title, actionsSlot, startSlot, collapsed, attributes, } = props;
10
+ const { size = "small", text, children, color = "inverted", icon, title, actionsSlot, startSlot, collapsed, className, attributes, } = props;
11
11
  let backgroundColor = color === "inverted" || color === "neutral" ? "elevation-overlay" : color;
12
12
  if (color === "neutral")
13
13
  backgroundColor = collapsed ? "neutral" : "elevation-overlay";
@@ -23,7 +23,7 @@ const Toast = (props) => {
23
23
  title,
24
24
  " ")),
25
25
  React.createElement(Text, { variant: "body-3", as: textTagName }, text)));
26
- const toastNode = (React.createElement(View, { backgroundColor: backgroundColor, borderColor: borderColor, padding: 4, borderRadius: "medium", animated: true, direction: "row", gap: 3, align: isLarge ? "start" : "center", className: s.toast, attributes: attributes },
26
+ const toastNode = (React.createElement(View, { backgroundColor: backgroundColor, borderColor: borderColor, padding: 4, borderRadius: "medium", animated: true, direction: "row", gap: 3, align: isLarge ? "start" : "center", className: [s.toast, className], attributes: attributes },
27
27
  icon && React.createElement(Icon, { size: 5, svg: icon, className: s.icon }),
28
28
  startSlot && !icon && React.createElement(View.Item, null, startSlot),
29
29
  React.createElement(View.Item, { grow: true },
@@ -14,6 +14,7 @@ export type Props = {
14
14
  children?: React.ReactNode;
15
15
  actionsSlot?: React.ReactNode;
16
16
  color?: "neutral" | "primary" | "critical" | "positive" | "inverted";
17
+ className?: G.ClassName;
17
18
  attributes?: G.Attributes<"div", Props>;
18
19
  };
19
20
  export type ProviderProps = {
@@ -92,6 +92,6 @@ const ToastContainer = (props) => {
92
92
  transitionDuration: resizingRef.current ? "0s" : undefined,
93
93
  }, onTransitionEnd: handleTransitionEnd, onFocus: stopTimer, onBlur: startTimer },
94
94
  React.createElement("span", { className: s.wrapper },
95
- React.createElement(Toast, Object.assign({}, toastProps, { collapsed: index > 0 && !inspected, attributes: { ref: wrapperRef } })))));
95
+ React.createElement(Toast, Object.assign({}, toastProps, { collapsed: index > 0 && !inspected, attributes: Object.assign(Object.assign({}, toastProps.attributes), { ref: wrapperRef }) })))));
96
96
  };
97
97
  export default ToastContainer;
@@ -7,8 +7,8 @@ exports.getTheme = void 0;
7
7
  const reshaped_1 = __importDefault(require("../themes/_generator/definitions/reshaped"));
8
8
  const base_1 = __importDefault(require("../themes/_generator/definitions/base"));
9
9
  const string_1 = require("../utilities/string");
10
- const color_1 = require("../utilities/color");
11
10
  const mergeDefinitions_1 = __importDefault(require("../themes/_generator/utilities/mergeDefinitions"));
11
+ const constants_1 = require("../themes/_generator/constants");
12
12
  const getTheme = (theme) => {
13
13
  const config = {
14
14
  backgroundColor: {},
@@ -30,7 +30,7 @@ const getTheme = (theme) => {
30
30
  if (tokenName.startsWith("background")) {
31
31
  const name = cssTokenName.replace("background-", "");
32
32
  config.backgroundColor[name] = configValue;
33
- if (color_1.bgWithDynamicForeground.includes(tokenName)) {
33
+ if (constants_1.bgWithDynamicForeground.includes(tokenName)) {
34
34
  const cssVariable = ["rs", "color", "on", cssTokenName].join("-");
35
35
  const configValue = `var(--${cssVariable})`;
36
36
  config.textColor[`on-${name}`] = configValue;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reshaped",
3
3
  "description": "Professionally crafted design system in React & Figma for building products of any scale and complexity",
4
- "version": "2.6.1",
4
+ "version": "2.6.3",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "email": "hello@reshaped.so",
7
7
  "homepage": "https://reshaped.so",
@@ -0,0 +1,2 @@
1
+ import { Name } from "./tokens/color/color.types";
2
+ export declare const bgWithDynamicForeground: Name[];
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.bgWithDynamicForeground = void 0;
4
+ exports.bgWithDynamicForeground = [
5
+ "backgroundNeutral",
6
+ "backgroundPrimary",
7
+ "backgroundCritical",
8
+ "backgroundPositive",
9
+ ];
@@ -11,8 +11,8 @@ import { getThemeCSS, generateThemeColors, baseThemeDefinition } from "../../ind
11
11
  export default { title: "Themes" };
12
12
  const css = getThemeCSS("green", {
13
13
  color: {
14
- backgroundPrimary: { hex: "#1abc9c", hexDark: "#16a085" },
15
- backgroundPrimaryHighlighted: { hex: "#16a085", hexDark: "#1abc9c" },
14
+ backgroundPrimary: { hex: "#1abc9c", hexDark: "#00E5C4" },
15
+ backgroundPrimaryHighlighted: { hex: "#16a085", hexDark: "#00E5C4" },
16
16
  },
17
17
  });
18
18
  const css2 = getThemeCSS("peach", {
@@ -1,4 +1,4 @@
1
- import type * as T from "./shadow.types";
2
1
  import type { Transformer } from "../types";
2
+ import type * as T from "./shadow.types";
3
3
  declare const transformedToken: Transformer<T.Token>;
4
4
  export default transformedToken;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const color_1 = require("../../../../utilities/color");
3
+ const color_1 = require("../../utilities/color");
4
4
  const transformedToken = (name, token, theme) => [
5
5
  {
6
6
  name,
@@ -11,7 +11,9 @@ const transformedToken = (name, token, theme) => [
11
11
  const blur = ` ${value.blurRadius || 0}px`;
12
12
  const spread = ` ${value.spreadRadius || 0}px`;
13
13
  const colorRef = theme.color[value.colorToken];
14
- const color = `rgba(${(0, color_1.hexToRgbString)(colorRef.hex)}, ${value.opacity || 1})`;
14
+ const rgb = (0, color_1.hexToRgb)(colorRef.hex);
15
+ const rgbString = `${rgb.r}, ${rgb.g}, ${rgb.b}`;
16
+ const color = `rgba(${rgbString}, ${value.opacity || 1})`;
15
17
  return `${value.offsetX}px ${value.offsetY}px${blur}${spread} ${color}`;
16
18
  })
17
19
  .join(", "),
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Some of the color conversion utilities are taken from https://github.com/hsluv/hsluv-javascript
3
+ * They have been rewritten for easier color transformations in the theme generation case
4
+ */
5
+ type RgbColor = {
6
+ r: number;
7
+ g: number;
8
+ b: number;
9
+ };
10
+ type HslColor = {
11
+ h: number;
12
+ s: number;
13
+ l: number;
14
+ };
15
+ type XyzColor = {
16
+ x: number;
17
+ y: number;
18
+ z: number;
19
+ };
20
+ type LuvColor = {
21
+ l: number;
22
+ u: number;
23
+ v: number;
24
+ };
25
+ type LchColor = {
26
+ l: number;
27
+ c: number;
28
+ h: number;
29
+ };
30
+ type BoundingLines = {
31
+ r0s: number;
32
+ r0i: number;
33
+ r1s: number;
34
+ r1i: number;
35
+ g0s: number;
36
+ g0i: number;
37
+ g1s: number;
38
+ g1i: number;
39
+ b0s: number;
40
+ b0i: number;
41
+ b1s: number;
42
+ b1i: number;
43
+ };
44
+ /**
45
+ * Color utilities
46
+ */
47
+ export declare const calculateBoundingLines: (l: number) => BoundingLines;
48
+ export declare const distanceFromOriginAngle: (slope: number, intercept: number, angle: number) => number;
49
+ export declare const calcMaxChromaHsluv: (h: number, boundingLines: BoundingLines) => number;
50
+ export declare function hexToRgb(hex: string): RgbColor;
51
+ export declare const rgbToHsl: ({ r, g, b }: RgbColor) => HslColor;
52
+ export declare const hslToRgb: ({ h, s, l }: HslColor) => RgbColor;
53
+ export declare const rgbToHex: ({ r, g, b }: RgbColor) => string;
54
+ export declare const toLinear: (c: number) => number;
55
+ export declare const fromLinear: (c: number) => number;
56
+ export declare const rgbToXyz: ({ r, g, b }: RgbColor) => {
57
+ x: number;
58
+ y: number;
59
+ z: number;
60
+ };
61
+ export declare const xyzToRgb: ({ x, y, z }: XyzColor) => RgbColor;
62
+ export declare const yToL: (y: number) => number;
63
+ export declare const lToY: (l: number) => number;
64
+ export declare const xyzToLuv: ({ x, y, z }: XyzColor) => LuvColor;
65
+ export declare const luvToXyz: ({ l, u, v }: LuvColor) => XyzColor;
66
+ export declare const luvToLch: ({ l, u, v }: LuvColor) => LchColor;
67
+ export declare const lchToLuv: ({ l, c, h }: LchColor) => LuvColor;
68
+ export declare const lchToHsluv: ({ l, c, h }: LchColor) => HslColor;
69
+ export declare const hsluvToLch: ({ h, s, l }: HslColor) => LchColor;
70
+ export declare const hsluvToHex: (hsl: HslColor) => string;
71
+ export declare const hexToHsl: (H: string) => HslColor;
72
+ export declare const hexToHsluv: (hex: string) => HslColor;
73
+ export declare const hslToHex: (hsl: HslColor) => string;
74
+ /**
75
+ * Normalizing utilities
76
+ */
77
+ export declare const getDarkModeLightnessDelta: (lightness: number, luminance: number) => number;
78
+ export declare const getLuminanceDelta: (luminance: number) => number;
79
+ export declare function getRgbLuminance({ r, g, b }: RgbColor): number;
80
+ export declare const getOnColor: (args: {
81
+ bgHexColor: string;
82
+ mode: "light" | "dark";
83
+ lightHexColor?: string;
84
+ darkHexColor?: string;
85
+ }) => string;
86
+ export {};
@@ -0,0 +1,359 @@
1
+ "use strict";
2
+ /**
3
+ * Some of the color conversion utilities are taken from https://github.com/hsluv/hsluv-javascript
4
+ * They have been rewritten for easier color transformations in the theme generation case
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.getOnColor = exports.getRgbLuminance = exports.getLuminanceDelta = exports.getDarkModeLightnessDelta = exports.hslToHex = exports.hexToHsluv = exports.hexToHsl = exports.hsluvToHex = exports.hsluvToLch = exports.lchToHsluv = exports.lchToLuv = exports.luvToLch = exports.luvToXyz = exports.xyzToLuv = exports.lToY = exports.yToL = exports.xyzToRgb = exports.rgbToXyz = exports.fromLinear = exports.toLinear = exports.rgbToHex = exports.hslToRgb = exports.rgbToHsl = exports.hexToRgb = exports.calcMaxChromaHsluv = exports.distanceFromOriginAngle = exports.calculateBoundingLines = void 0;
8
+ /**
9
+ * Constants
10
+ */
11
+ const epsilon = 0.0088564516;
12
+ const refY = 1.0;
13
+ const refU = 0.19783000664283;
14
+ const refV = 0.46831999493879;
15
+ const kappa = 903.2962962;
16
+ const mr0 = 3.240969941904521;
17
+ const mr1 = -1.537383177570093;
18
+ const mr2 = -0.498610760293;
19
+ const mg0 = -0.96924363628087;
20
+ const mg1 = 1.87596750150772;
21
+ const mg2 = 0.041555057407175;
22
+ const mb0 = 0.055630079696993;
23
+ const mb1 = -0.20397695888897;
24
+ const mb2 = 1.056971514242878;
25
+ /**
26
+ * Color utilities
27
+ */
28
+ const calculateBoundingLines = (l) => {
29
+ const sub1 = Math.pow(l + 16, 3) / 1560896;
30
+ const sub2 = sub1 > epsilon ? sub1 : l / kappa;
31
+ const s1r = sub2 * (284517 * mr0 - 94839 * mr2);
32
+ const s2r = sub2 * (838422 * mr2 + 769860 * mr1 + 731718 * mr0);
33
+ const s3r = sub2 * (632260 * mr2 - 126452 * mr1);
34
+ const s1g = sub2 * (284517 * mg0 - 94839 * mg2);
35
+ const s2g = sub2 * (838422 * mg2 + 769860 * mg1 + 731718 * mg0);
36
+ const s3g = sub2 * (632260 * mg2 - 126452 * mg1);
37
+ const s1b = sub2 * (284517 * mb0 - 94839 * mb2);
38
+ const s2b = sub2 * (838422 * mb2 + 769860 * mb1 + 731718 * mb0);
39
+ const s3b = sub2 * (632260 * mb2 - 126452 * mb1);
40
+ return {
41
+ r0s: s1r / s3r,
42
+ r0i: (s2r * l) / s3r,
43
+ r1s: s1r / (s3r + 126452),
44
+ r1i: ((s2r - 769860) * l) / (s3r + 126452),
45
+ g0s: s1g / s3g,
46
+ g0i: (s2g * l) / s3g,
47
+ g1s: s1g / (s3g + 126452),
48
+ g1i: ((s2g - 769860) * l) / (s3g + 126452),
49
+ b0s: s1b / s3b,
50
+ b0i: (s2b * l) / s3b,
51
+ b1s: s1b / (s3b + 126452),
52
+ b1i: ((s2b - 769860) * l) / (s3b + 126452),
53
+ };
54
+ };
55
+ exports.calculateBoundingLines = calculateBoundingLines;
56
+ const distanceFromOriginAngle = (slope, intercept, angle) => {
57
+ const d = intercept / (Math.sin(angle) - slope * Math.cos(angle));
58
+ return d < 0 ? Infinity : d;
59
+ };
60
+ exports.distanceFromOriginAngle = distanceFromOriginAngle;
61
+ const calcMaxChromaHsluv = (h, boundingLines) => {
62
+ const hueRad = (h / 360) * Math.PI * 2;
63
+ const r0 = (0, exports.distanceFromOriginAngle)(boundingLines.r0s, boundingLines.r0i, hueRad);
64
+ const r1 = (0, exports.distanceFromOriginAngle)(boundingLines.r1s, boundingLines.r1i, hueRad);
65
+ const g0 = (0, exports.distanceFromOriginAngle)(boundingLines.g0s, boundingLines.g0i, hueRad);
66
+ const g1 = (0, exports.distanceFromOriginAngle)(boundingLines.g1s, boundingLines.g1i, hueRad);
67
+ const b0 = (0, exports.distanceFromOriginAngle)(boundingLines.b0s, boundingLines.b0i, hueRad);
68
+ const b1 = (0, exports.distanceFromOriginAngle)(boundingLines.b1s, boundingLines.b1i, hueRad);
69
+ return Math.min(r0, r1, g0, g1, b0, b1);
70
+ };
71
+ exports.calcMaxChromaHsluv = calcMaxChromaHsluv;
72
+ function hexToRgb(hex) {
73
+ hex = hex.replace("#", "");
74
+ const r = parseInt(hex.substring(0, 2), 16);
75
+ const g = parseInt(hex.substring(2, 4), 16);
76
+ const b = parseInt(hex.substring(4, 6), 16);
77
+ return { r, g, b };
78
+ }
79
+ exports.hexToRgb = hexToRgb;
80
+ const rgbToHsl = ({ r, g, b }) => {
81
+ r /= 255;
82
+ g /= 255;
83
+ b /= 255;
84
+ const cmin = Math.min(r, g, b);
85
+ const cmax = Math.max(r, g, b);
86
+ const delta = cmax - cmin;
87
+ let h = 0;
88
+ let s = 0;
89
+ let l = 0;
90
+ if (delta == 0)
91
+ h = 0;
92
+ else if (cmax == r)
93
+ h = ((g - b) / delta) % 6;
94
+ else if (cmax == g)
95
+ h = (b - r) / delta + 2;
96
+ else
97
+ h = (r - g) / delta + 4;
98
+ h = Math.round(h * 60);
99
+ if (h < 0)
100
+ h += 360;
101
+ l = (cmax + cmin) / 2;
102
+ s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
103
+ s = +(s * 100).toFixed(1);
104
+ l = +(l * 100).toFixed(1);
105
+ return { h, s: Math.round(s), l: Math.round(l) };
106
+ };
107
+ exports.rgbToHsl = rgbToHsl;
108
+ const hslToRgb = ({ h, s, l }) => {
109
+ s /= 100;
110
+ l /= 100;
111
+ const c = (1 - Math.abs(2 * l - 1)) * s;
112
+ const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
113
+ const m = l - c / 2;
114
+ const isSector1 = 0 <= h && h < 60;
115
+ const isSector2 = 60 <= h && h < 120;
116
+ const isSector3 = 120 <= h && h < 180;
117
+ const isSector4 = 180 <= h && h < 240;
118
+ const isSector5 = 240 <= h && h < 300;
119
+ const isSector6 = 300 <= h && h < 360;
120
+ const r = isSector1 || isSector6 ? c : isSector2 || isSector5 ? x : 0;
121
+ const g = isSector1 || isSector4 ? x : isSector2 || isSector3 ? c : 0;
122
+ const b = isSector1 || isSector2 ? 0 : isSector3 || isSector6 ? x : c;
123
+ return {
124
+ r: Math.round((r + m) * 255),
125
+ g: Math.round((g + m) * 255),
126
+ b: Math.round((b + m) * 255),
127
+ };
128
+ };
129
+ exports.hslToRgb = hslToRgb;
130
+ const rgbToHex = ({ r, g, b }) => {
131
+ const red = Math.round(r).toString(16).padStart(2, "0");
132
+ const green = Math.round(g).toString(16).padStart(2, "0");
133
+ const blue = Math.round(b).toString(16).padStart(2, "0");
134
+ return `#${red}${green}${blue}`;
135
+ };
136
+ exports.rgbToHex = rgbToHex;
137
+ const toLinear = (c) => {
138
+ if (c > 0.04045)
139
+ return Math.pow((c + 0.055) / 1.055, 2.4);
140
+ return c / 12.92;
141
+ };
142
+ exports.toLinear = toLinear;
143
+ const fromLinear = (c) => {
144
+ if (c <= 0.0031308)
145
+ return 12.92 * c;
146
+ return 1.055 * Math.pow(c, 1 / 2.4) - 0.055;
147
+ };
148
+ exports.fromLinear = fromLinear;
149
+ const rgbToXyz = ({ r, g, b }) => {
150
+ const lr = (0, exports.toLinear)(r / 255);
151
+ const lg = (0, exports.toLinear)(g / 255);
152
+ const lb = (0, exports.toLinear)(b / 255);
153
+ return {
154
+ x: 0.41239079926595 * lr + 0.35758433938387 * lg + 0.18048078840183 * lb,
155
+ y: 0.21263900587151 * lr + 0.71516867876775 * lg + 0.072192315360733 * lb,
156
+ z: 0.019330818715591 * lr + 0.11919477979462 * lg + 0.95053215224966 * lb,
157
+ };
158
+ };
159
+ exports.rgbToXyz = rgbToXyz;
160
+ const xyzToRgb = ({ x, y, z }) => {
161
+ return {
162
+ r: (0, exports.fromLinear)(mr0 * x + mr1 * y + mr2 * z) * 255,
163
+ g: (0, exports.fromLinear)(mg0 * x + mg1 * y + mg2 * z) * 255,
164
+ b: (0, exports.fromLinear)(mb0 * x + mb1 * y + mb2 * z) * 255,
165
+ };
166
+ };
167
+ exports.xyzToRgb = xyzToRgb;
168
+ const yToL = (y) => {
169
+ if (y <= epsilon)
170
+ return (y / refY) * kappa;
171
+ return 116 * Math.pow(y / refY, 1 / 3) - 16;
172
+ };
173
+ exports.yToL = yToL;
174
+ const lToY = (l) => {
175
+ if (l <= 8)
176
+ return (refY * l) / kappa;
177
+ return refY * Math.pow((l + 16) / 116, 3);
178
+ };
179
+ exports.lToY = lToY;
180
+ const xyzToLuv = ({ x, y, z }) => {
181
+ const divider = x + 15 * y + 3 * z;
182
+ const varU = divider !== 0 ? (4 * x) / divider : NaN;
183
+ const varV = divider !== 0 ? (9 * y) / divider : NaN;
184
+ const l = (0, exports.yToL)(y);
185
+ return {
186
+ l,
187
+ u: l === 0 ? 0 : 13 * l * (varU - refU),
188
+ v: l === 0 ? 0 : 13 * l * (varV - refV),
189
+ };
190
+ };
191
+ exports.xyzToLuv = xyzToLuv;
192
+ const luvToXyz = ({ l, u, v }) => {
193
+ if (l === 0)
194
+ return { x: 0, y: 0, z: 0 };
195
+ const varU = u / (13 * l) + refU;
196
+ const varV = v / (13 * l) + refV;
197
+ const y = (0, exports.lToY)(l);
198
+ const x = 0 - (9 * y * varU) / ((varU - 4) * varV - varU * varV);
199
+ const z = (9 * y - 15 * varV * y - varV * x) / (3 * varV);
200
+ return { x, y, z };
201
+ };
202
+ exports.luvToXyz = luvToXyz;
203
+ const luvToLch = ({ l, u, v }) => {
204
+ const c = Math.sqrt(u * u + v * v);
205
+ let h;
206
+ if (c < 0.00000001) {
207
+ h = 0;
208
+ }
209
+ else {
210
+ const hrad = Math.atan2(v, u);
211
+ h = (hrad * 180.0) / Math.PI;
212
+ if (h < 0)
213
+ h = 360 + h;
214
+ }
215
+ return { l, c, h };
216
+ };
217
+ exports.luvToLch = luvToLch;
218
+ const lchToLuv = ({ l, c, h }) => {
219
+ const hrad = (h / 180.0) * Math.PI;
220
+ return {
221
+ l,
222
+ u: Math.cos(hrad) * c,
223
+ v: Math.sin(hrad) * c,
224
+ };
225
+ };
226
+ exports.lchToLuv = lchToLuv;
227
+ const lchToHsluv = ({ l, c, h }) => {
228
+ let s;
229
+ let newL;
230
+ if (l > 99.9999999) {
231
+ s = 0;
232
+ newL = 100;
233
+ }
234
+ else if (l < 0.00000001) {
235
+ s = 0;
236
+ newL = 0;
237
+ }
238
+ else {
239
+ const boundingLines = (0, exports.calculateBoundingLines)(l);
240
+ const max = (0, exports.calcMaxChromaHsluv)(h, boundingLines);
241
+ s = (c / max) * 100;
242
+ newL = l;
243
+ }
244
+ return { h, s, l: newL };
245
+ };
246
+ exports.lchToHsluv = lchToHsluv;
247
+ const hsluvToLch = ({ h, s, l }) => {
248
+ let newL;
249
+ let c;
250
+ if (l > 99.9999999) {
251
+ newL = 100;
252
+ c = 0;
253
+ }
254
+ else if (l < 0.00000001) {
255
+ newL = 0;
256
+ c = 0;
257
+ }
258
+ else {
259
+ const boundingLines = (0, exports.calculateBoundingLines)(l);
260
+ const max = (0, exports.calcMaxChromaHsluv)(h, boundingLines);
261
+ newL = l;
262
+ c = (max / 100) * s;
263
+ }
264
+ return { l: newL, c, h };
265
+ };
266
+ exports.hsluvToLch = hsluvToLch;
267
+ const hsluvToHex = (hsl) => {
268
+ const lch = (0, exports.hsluvToLch)(hsl);
269
+ const luv = (0, exports.lchToLuv)(lch);
270
+ const xyz = (0, exports.luvToXyz)(luv);
271
+ const rgb = (0, exports.xyzToRgb)(xyz);
272
+ return (0, exports.rgbToHex)(rgb);
273
+ };
274
+ exports.hsluvToHex = hsluvToHex;
275
+ const hexToHsl = (H) => {
276
+ const rgb = hexToRgb(H);
277
+ return (0, exports.rgbToHsl)(rgb);
278
+ };
279
+ exports.hexToHsl = hexToHsl;
280
+ const hexToHsluv = (hex) => {
281
+ const rgb = hexToRgb(hex);
282
+ const xyz = (0, exports.rgbToXyz)(rgb);
283
+ const luv = (0, exports.xyzToLuv)(xyz);
284
+ const lch = (0, exports.luvToLch)(luv);
285
+ return (0, exports.lchToHsluv)(lch);
286
+ };
287
+ exports.hexToHsluv = hexToHsluv;
288
+ const hslToHex = (hsl) => {
289
+ const rgb = (0, exports.hslToRgb)(hsl);
290
+ return (0, exports.rgbToHex)(rgb);
291
+ };
292
+ exports.hslToHex = hslToHex;
293
+ /**
294
+ * Normalizing utilities
295
+ */
296
+ const getDarkModeLightnessDelta = (lightness, luminance) => {
297
+ const perceivedLuminanceOrigin = 69.5;
298
+ const luminanceDistance = Math.abs(Math.round(luminance - perceivedLuminanceOrigin));
299
+ // Use a greater modifier for values around the luminance origin and decrease it for distant values
300
+ const luminanceModifier = 3 - (Math.min(luminanceDistance, 20) / 20) * 0.5;
301
+ const distance = luminanceDistance * luminanceModifier;
302
+ // Dark mode always reduces lightness but if the color was dark originally, we need to do it a slower pace
303
+ const slowdownModifier = luminanceDistance < 0 ? 2 : 1;
304
+ // Adjust the value based on the current lightness boundary
305
+ const delta = lightness / 100;
306
+ return (distance * delta) / slowdownModifier;
307
+ };
308
+ exports.getDarkModeLightnessDelta = getDarkModeLightnessDelta;
309
+ const getLuminanceDelta = (luminance) => {
310
+ return Math.max(0, luminance - 50) / 5;
311
+ };
312
+ exports.getLuminanceDelta = getLuminanceDelta;
313
+ function getRgbLuminance({ r, g, b }) {
314
+ r /= 255;
315
+ g /= 255;
316
+ b /= 255;
317
+ const y = 0.2126 * r + 0.7152 * g + 0.0722 * b;
318
+ // The CIE standard states 0.008856 but 216/24389 is the intent for 0.008856451679036
319
+ if (y <= 216 / 24389) {
320
+ // The CIE standard states 903.3, but 24389/27 is the intent, making 903.296296296296296
321
+ return y * (24389 / 27);
322
+ }
323
+ else {
324
+ return Math.pow(y, 1 / 3) * 116 - 16;
325
+ }
326
+ }
327
+ exports.getRgbLuminance = getRgbLuminance;
328
+ function getContrastLuminance({ r, g, b }) {
329
+ return (0.2126 * Math.pow(r / 255, 2.2) +
330
+ 0.7152 * Math.pow(g / 255, 2.2) +
331
+ 0.0722 * Math.pow(b / 255, 2.2));
332
+ }
333
+ function getApcaContrast(backgroundLuminance, textLuminance) {
334
+ // Calculate the contrast based on APCA
335
+ let Lc = textLuminance - backgroundLuminance;
336
+ return Math.abs(Lc); // Return the absolute value of contrast
337
+ }
338
+ const getOnColor = (args) => {
339
+ const { bgHexColor, mode, lightHexColor = "#ffffff", darkHexColor = "#000000" } = args;
340
+ const bgHexAlpha = bgHexColor.slice(7);
341
+ const bgAlpha = bgHexAlpha ? Number((parseInt(bgHexAlpha, 16) / 255).toFixed(2)) : 1;
342
+ const bgColor = hexToRgb(bgHexColor.slice(0, 7));
343
+ const baseColor = mode === "light" ? { r: 255, g: 255, b: 255 } : { r: 0, g: 0, b: 0 };
344
+ const { r, g, b } = {
345
+ r: (1 - bgAlpha) * baseColor.r + bgAlpha * bgColor.r,
346
+ g: (1 - bgAlpha) * baseColor.g + bgAlpha * bgColor.g,
347
+ b: (1 - bgAlpha) * baseColor.b + bgAlpha * bgColor.b,
348
+ };
349
+ // Calculate luminance for background and for white & black
350
+ let backgroundLuminance = getContrastLuminance({ r, g, b });
351
+ let whiteLuminance = getContrastLuminance({ r: 255, g: 255, b: 255 });
352
+ let blackLuminance = getContrastLuminance({ r: 0, g: 0, b: 0 });
353
+ // Calculate contrast
354
+ let contrastWithWhite = getApcaContrast(backgroundLuminance, whiteLuminance);
355
+ let contrastWithBlack = getApcaContrast(backgroundLuminance, blackLuminance);
356
+ // Choose the color with higher contrast
357
+ return contrastWithWhite > contrastWithBlack ? lightHexColor : darkHexColor;
358
+ };
359
+ exports.getOnColor = getOnColor;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const color_1 = require("../../../utilities/color");
3
+ const color_1 = require("./color");
4
+ const constants_1 = require("../constants");
4
5
  const string_1 = require("../../../utilities/string");
5
6
  const generateBackgroundColors = (definition, themeOptions) => {
6
7
  if (!definition.color)
@@ -11,14 +12,12 @@ const generateBackgroundColors = (definition, themeOptions) => {
11
12
  const generatedForegroundName = `on${(0, string_1.capitalize)(tokenName)}`;
12
13
  const generatedRGBName = `rgb${(0, string_1.capitalize)(tokenName)}`;
13
14
  const generateOnColorsFor = [
14
- "backgroundNeutral",
15
- "backgroundPrimary",
16
- "backgroundCritical",
17
- "backgroundPositive",
15
+ ...constants_1.bgWithDynamicForeground,
18
16
  ...((themeOptions === null || themeOptions === void 0 ? void 0 : themeOptions.generateOnColorsFor) || []),
19
17
  ];
20
18
  const needsDynamicForeground = generateOnColorsFor.includes(tokenName);
21
19
  const needsRGB = tokenName.startsWith("background") ||
20
+ tokenName.startsWith("border") ||
22
21
  tokenName.endsWith("black") ||
23
22
  tokenName.endsWith("white");
24
23
  if (!bgToken)
@@ -41,10 +40,12 @@ const generateBackgroundColors = (definition, themeOptions) => {
41
40
  };
42
41
  }
43
42
  if (needsRGB) {
43
+ const rgb = (0, color_1.hexToRgb)(bgToken.hex);
44
+ const rgbDark = bgToken.hexDark && (0, color_1.hexToRgb)(bgToken.hexDark);
44
45
  // eslint-disable-next-line no-param-reassign
45
46
  definition.color[generatedRGBName] = {
46
- hex: (0, color_1.hexToRgbString)(bgToken.hex),
47
- hexDark: bgToken.hexDark && (0, color_1.hexToRgbString)(bgToken.hexDark),
47
+ hex: `${rgb.r}, ${rgb.g}, ${rgb.b}`,
48
+ hexDark: rgbDark && `${rgbDark.r}, ${rgbDark.g}, ${rgbDark.b}`,
48
49
  };
49
50
  }
50
51
  });
@@ -1,14 +1,3 @@
1
- /**
2
- * Some of the color conversion utilities are taken from https://github.com/hsluv/hsluv-javascript
3
- * They have been rewritten for easier color transformations in the theme generation case
4
- */
5
- type RgbColor = {
6
- r: number;
7
- g: number;
8
- b: number;
9
- };
10
- export declare function hexToRgb(hex: string): RgbColor;
11
- export declare function getRgbLuminance({ r, g, b }: RgbColor): number;
12
1
  declare const generate: (args?: {
13
2
  primary?: string;
14
3
  critical?: string;