@quenty/colorpalette 5.0.0-canary.331.7eefa75.0 → 5.0.0-canary.367.903617a.0

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/CHANGELOG.md CHANGED
@@ -3,7 +3,117 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- # [5.0.0-canary.331.7eefa75.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.12.0...@quenty/colorpalette@5.0.0-canary.331.7eefa75.0) (2023-02-27)
6
+ # [5.0.0-canary.367.903617a.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.23.0...@quenty/colorpalette@5.0.0-canary.367.903617a.0) (2023-06-09)
7
+
8
+ **Note:** Version bump only for package @quenty/colorpalette
9
+
10
+
11
+
12
+
13
+
14
+ # [4.23.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.22.0...@quenty/colorpalette@4.23.0) (2023-05-26)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * Fix unknown font construction in FontPalette ([b14b679](https://github.com/Quenty/NevermoreEngine/commit/b14b6799e0313fda7cd9977be7921d3edaba7fb2))
20
+
21
+
22
+ ### Features
23
+
24
+ * Initial refactor of guis to use ValueObject instead of ValueObject ([723aba0](https://github.com/Quenty/NevermoreEngine/commit/723aba0208cae7e06c9d8bf2d8f0092d042d70ea))
25
+
26
+
27
+
28
+
29
+
30
+ # [4.22.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.21.0...@quenty/colorpalette@4.22.0) (2023-05-08)
31
+
32
+
33
+ ### Features
34
+
35
+ * Add ColorGradeUtils.ensureGradeContrast(color, backing, amount) ([65a931b](https://github.com/Quenty/NevermoreEngine/commit/65a931b43b058c77585f1eb3b18b7614eb2a41cb))
36
+
37
+
38
+
39
+
40
+
41
+ # [4.21.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.20.0...@quenty/colorpalette@4.21.0) (2023-04-10)
42
+
43
+ **Note:** Version bump only for package @quenty/colorpalette
44
+
45
+
46
+
47
+
48
+
49
+ # [4.20.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.19.1...@quenty/colorpalette@4.20.0) (2023-04-07)
50
+
51
+
52
+ ### Features
53
+
54
+ * Add FontPalette:GetFontFaceValue(fontName) ([3411e11](https://github.com/Quenty/NevermoreEngine/commit/3411e116f2d48453a016d9dc15eab6ea64fb1bc4))
55
+
56
+
57
+
58
+
59
+
60
+ ## [4.19.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.19.0...@quenty/colorpalette@4.19.1) (2023-04-07)
61
+
62
+ **Note:** Version bump only for package @quenty/colorpalette
63
+
64
+
65
+
66
+
67
+
68
+ # [4.19.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.18.0...@quenty/colorpalette@4.19.0) (2023-04-06)
69
+
70
+ **Note:** Version bump only for package @quenty/colorpalette
71
+
72
+
73
+
74
+
75
+
76
+ # [4.18.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.17.0...@quenty/colorpalette@4.18.0) (2023-04-03)
77
+
78
+ **Note:** Version bump only for package @quenty/colorpalette
79
+
80
+
81
+
82
+
83
+
84
+ # [4.17.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.16.0...@quenty/colorpalette@4.17.0) (2023-03-31)
85
+
86
+ **Note:** Version bump only for package @quenty/colorpalette
87
+
88
+
89
+
90
+
91
+
92
+ # [4.16.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.15.0...@quenty/colorpalette@4.16.0) (2023-03-31)
93
+
94
+ **Note:** Version bump only for package @quenty/colorpalette
95
+
96
+
97
+
98
+
99
+
100
+ # [4.15.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.14.0...@quenty/colorpalette@4.15.0) (2023-03-06)
101
+
102
+ **Note:** Version bump only for package @quenty/colorpalette
103
+
104
+
105
+
106
+
107
+
108
+ # [4.14.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.13.0...@quenty/colorpalette@4.14.0) (2023-03-05)
109
+
110
+ **Note:** Version bump only for package @quenty/colorpalette
111
+
112
+
113
+
114
+
115
+
116
+ # [4.13.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/colorpalette@4.12.0...@quenty/colorpalette@4.13.0) (2023-02-27)
7
117
 
8
118
  **Note:** Version bump only for package @quenty/colorpalette
9
119
 
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014-2022 Quenty
3
+ Copyright (c) 2014-2023 James Onnen (Quenty)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/colorpalette",
3
- "version": "5.0.0-canary.331.7eefa75.0",
3
+ "version": "5.0.0-canary.367.903617a.0",
4
4
  "description": "Color palette system for Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -28,17 +28,17 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@quenty/baseobject": "6.1.0",
32
- "@quenty/blend": "7.0.0-canary.331.7eefa75.0",
33
- "@quenty/color3utils": "6.0.0-canary.331.7eefa75.0",
34
- "@quenty/colorpicker": "5.0.0-canary.331.7eefa75.0",
35
- "@quenty/loader": "6.1.0",
36
- "@quenty/maid": "2.4.0",
37
- "@quenty/math": "2.2.0",
38
- "@quenty/rx": "8.0.0-canary.331.7eefa75.0",
39
- "@quenty/signal": "2.3.0",
31
+ "@quenty/baseobject": "6.2.1",
32
+ "@quenty/blend": "7.0.0-canary.367.903617a.0",
33
+ "@quenty/color3utils": "6.0.0-canary.367.903617a.0",
34
+ "@quenty/colorpicker": "5.0.0-canary.367.903617a.0",
35
+ "@quenty/loader": "6.2.1",
36
+ "@quenty/maid": "2.5.0",
37
+ "@quenty/math": "3.0.0-canary.367.903617a.0",
38
+ "@quenty/rx": "7.11.0",
39
+ "@quenty/signal": "2.4.0",
40
40
  "@quenty/table": "3.2.0",
41
- "@quenty/valueobject": "8.0.0-canary.331.7eefa75.0"
41
+ "@quenty/valueobject": "8.0.0-canary.367.903617a.0"
42
42
  },
43
- "gitHead": "7eefa756f8bd892b1210349a8133d6d56992dffb"
43
+ "gitHead": "903617ace784bce6cc7e0a15093ee50566bd9b54"
44
44
  }
@@ -315,9 +315,7 @@ function ColorPalette:SetColor(colorName, color)
315
315
  error(("No color grade with name %q"):format(colorName))
316
316
  end
317
317
 
318
- self._colorMaid[colorName] = Blend.mount(self._colorValues[colorName], {
319
- Value = color;
320
- })
318
+ self._colorMaid[colorName] = self._colorValues[colorName]:Mount(color)
321
319
  end
322
320
 
323
321
  function ColorPalette:SetVividness(gradeName, vividness)
@@ -327,21 +325,18 @@ function ColorPalette:SetVividness(gradeName, vividness)
327
325
  error(("No vividness with name %q"):format(gradeName))
328
326
  end
329
327
 
330
- self._vividMaid[gradeName] = Blend.mount(self._vividnessValues[gradeName], {
331
- Value = vividness;
332
- })
328
+ self._vividMaid[gradeName] = self._vividnessValues[gradeName]:Mount(vividness)
333
329
  end
334
330
 
335
331
  function ColorPalette:SetColorGrade(gradeName, grade)
336
332
  assert(type(gradeName) == "string", "Bad colorName")
333
+ assert(grade, "Bad grade")
337
334
 
338
335
  if not self._colorGradeValues[gradeName] then
339
336
  error(("No color grade with name %q"):format(gradeName))
340
337
  end
341
338
 
342
- self._gradeMaid[gradeName] = Blend.mount(self._colorGradeValues[gradeName], {
343
- Value = grade;
344
- })
339
+ self._gradeMaid[gradeName] = self._colorGradeValues[gradeName]:Mount(grade)
345
340
  end
346
341
 
347
342
 
@@ -355,11 +350,11 @@ function ColorPalette:DefineColorGrade(gradeName, gradeValue, vividnessValue)
355
350
  assert(type(gradeName) == "string", "Bad gradeName")
356
351
 
357
352
  if self._colorGradeValues[gradeName] then
358
- warn(("Already defined grade of name %q"):format(gradeName))
353
+ warn(("[ColorPalette.DefineColorGrade] - Already defined grade of name %q"):format(gradeName))
359
354
  return
360
355
  end
361
356
 
362
- local colorGrade = Instance.new("NumberValue")
357
+ local colorGrade = ValueObject.new(0, "number")
363
358
  self._maid:GiveTask(colorGrade)
364
359
 
365
360
  local vividness = ValueObject.new(nil)
@@ -371,7 +366,7 @@ function ColorPalette:DefineColorGrade(gradeName, gradeValue, vividnessValue)
371
366
  self._vividnessValues[gradeName] = vividness
372
367
 
373
368
  self:SetVividness(gradeName, vividnessValue)
374
- self:SetColorGrade(gradeName, gradeValue)
369
+ self:SetColorGrade(gradeName, gradeValue or 0)
375
370
 
376
371
  self.ColorGradeAdded:Fire(gradeName)
377
372
 
@@ -382,12 +377,11 @@ function ColorPalette:DefineColorSwatch(colorName, value)
382
377
  assert(type(colorName) == "string", "Bad colorName")
383
378
 
384
379
  if self._swatches[colorName] then
385
- warn(("Already defined color of name %q"):format(colorName))
380
+ warn(("[ColorPalette.DefineColorGrade] -Already defined color of name %q"):format(colorName))
386
381
  return
387
382
  end
388
383
 
389
- local colorValue = Instance.new("Color3Value")
390
- colorValue.Value = value or Color3.new(0, 0, 0)
384
+ local colorValue = ValueObject.new(value or Color3.new(0, 0, 0), "Color3")
391
385
  self._maid:GiveTask(colorValue)
392
386
 
393
387
  local colorSwatch = ColorSwatch.new(colorValue)
@@ -8,6 +8,7 @@ local Maid = require("Maid")
8
8
  local Blend = require("Blend")
9
9
  local ColorPickerStoryUtils = require("ColorPickerStoryUtils")
10
10
  local ColorPalette = require("ColorPalette")
11
+ local ValueObject = require("ValueObject")
11
12
 
12
13
  local DARK_MODE_ENABLED = false
13
14
 
@@ -61,8 +62,7 @@ return function(target)
61
62
  end
62
63
 
63
64
  local function sampleGui(labelText)
64
- local mouseOver = Instance.new("NumberValue")
65
- mouseOver.Value = 0
65
+ local mouseOver = ValueObject.new(0, "number")
66
66
  maid:GiveTask(mouseOver)
67
67
 
68
68
  local percentMouseOver = Blend.Spring(mouseOver, 60)
@@ -25,6 +25,7 @@ function FontPalette.new()
25
25
  local self = setmetatable(BaseObject.new(), FontPalette)
26
26
 
27
27
  self._fonts = {}
28
+ self._fontFaces = {}
28
29
  self._defaultFontMap = {} -- [name] = Enum.Font.?
29
30
 
30
31
  self.FontAdded = Signal.new() -- :Fire(name)
@@ -96,21 +97,38 @@ end
96
97
  function FontPalette:ObserveFontFace(fontName, weight, style)
97
98
  assert(type(fontName) == "string", "Bad fontName")
98
99
 
100
+ if weight == nil and style == nil then
101
+ return self:GetFontFaceValue(fontName):Observe()
102
+ end
103
+
99
104
  return Rx.combineLatest({
100
- family = self:GetFontValue(fontName):Observe():Pipe({
101
- Rx.map(function(fontEnum)
102
- return Font.fromEnum(fontEnum).Family
103
- end);
104
- });
105
- weight = weight or Enum.FontWeight.Regular;
106
- style = style or Enum.FontStyle.Normal;
105
+ font = self:GetFontFaceValue(fontName):Observe();
106
+ weight = weight;
107
+ style = style;
107
108
  }):Pipe({
108
109
  Rx.map(function(state)
109
- return Font.new(state.family, state.weight, state.style)
110
+ return Font.new(state.font.Family, state.weight or state.font.Weight, state.style or state.font.Style)
110
111
  end);
111
112
  })
112
113
  end
113
114
 
115
+ --[=[
116
+ Gets a font value object for a given font.
117
+
118
+ @param fontName string
119
+ @return ValueObject<Enum.Font>
120
+ ]=]
121
+ function FontPalette:GetFontFaceValue(fontName)
122
+ assert(type(fontName) == "string", "Bad fontName")
123
+
124
+ local fontValue = self._fontFaces[fontName]
125
+ if not fontValue then
126
+ error(("No font with name %q"):format(fontName))
127
+ end
128
+
129
+ return fontValue
130
+ end
131
+
114
132
  --[=[
115
133
  Gets a font value object for a given font.
116
134
 
@@ -120,12 +138,12 @@ end
120
138
  function FontPalette:GetFontValue(fontName)
121
139
  assert(type(fontName) == "string", "Bad fontName")
122
140
 
123
- local font = self._fonts[fontName]
124
- if not font then
141
+ local fontValue = self._fonts[fontName]
142
+ if not fontValue then
125
143
  error(("No font with name %q"):format(fontName))
126
144
  end
127
145
 
128
- return font
146
+ return fontValue
129
147
  end
130
148
 
131
149
  --[=[
@@ -140,27 +158,71 @@ end
140
158
  Defines a new font into the palette which can be changed over time.
141
159
 
142
160
  @param fontName string
143
- @param font Font
144
- @return ValueObject<Enum.Font>
161
+ @param defaultFont Enum.Font | Font
162
+ @return ValueObject<Enum.Font | Font>
145
163
  ]=]
146
- function FontPalette:DefineFont(fontName, font)
164
+ function FontPalette:DefineFont(fontName, defaultFont)
147
165
  assert(type(fontName) == "string", "Bad fontName")
148
- assert(typeof(font) == "EnumItem", "Bad font")
166
+ assert(typeof(defaultFont) == "EnumItem" or typeof(defaultFont) == "Font", "Bad defaultFont")
149
167
 
150
168
  if self._fonts[fontName] then
151
- warn(("Already defined font of name %q"):format(fontName))
169
+ warn(("Already defined defaultFont of name %q"):format(fontName))
152
170
  return
153
171
  end
154
172
 
155
- local fontValue = ValueObject.new(font)
173
+ local defaultFontEnum
174
+ local defaultFontFace
175
+ if typeof(defaultFont) == "EnumItem" then
176
+ defaultFontEnum = defaultFont
177
+ defaultFontFace = Font.fromEnum(defaultFont)
178
+ elseif typeof(defaultFont) == "Font" then
179
+ defaultFontEnum = defaultFont
180
+ defaultFontFace = defaultFont
181
+ else
182
+ error("Bad defaultFont")
183
+ end
184
+
185
+ local fontValue = ValueObject.new(defaultFontEnum)
156
186
  self._maid:GiveTask(fontValue)
157
187
 
188
+ local fontFaceValue = ValueObject.new(defaultFontFace)
189
+ self._maid:GiveTask(fontFaceValue)
190
+
158
191
  self._fonts[fontName] = fontValue
159
- self._defaultFontMap[fontName] = font
192
+ self._fontFaces[fontName] = fontFaceValue
193
+ self._defaultFontMap[fontName] = defaultFont
194
+
195
+ self._maid:GiveTask(fontFaceValue.Changed:Connect(function(fontFace)
196
+ fontValue.Value = self:_tryToGetFontFace(fontFace)
197
+ end))
198
+
199
+ self._maid:GiveTask(fontValue.Changed:Connect(function(fontEnum)
200
+ -- Assume fontFace is set with something reasonable
201
+ if fontEnum ~= Enum.Font.Unknown then
202
+ local font = Font.fromEnum(fontEnum)
203
+ local current = fontFaceValue.Value
204
+ fontFaceValue.Value = Font.new(font.Family, current.Weight, current.Style)
205
+ end
206
+ end))
160
207
 
161
208
  self.FontAdded:Fire(fontName)
162
209
 
163
210
  return fontValue
164
211
  end
165
212
 
213
+ function FontPalette:_tryToGetFontFace(fontFace)
214
+ local assetName = string.gmatch(fontFace.Family, "rbxasset://fonts/families/([%w]+).json$")()
215
+
216
+ local fontEnum
217
+ pcall(function()
218
+ fontEnum = Enum.Font[assetName]
219
+ end)
220
+
221
+ if fontEnum then
222
+ return fontEnum
223
+ else
224
+ return Enum.Font.Unknown
225
+ end
226
+ end
227
+
166
228
  return FontPalette
@@ -53,8 +53,7 @@ return function(target)
53
53
  dark:Add("mouseOver", -15)
54
54
 
55
55
  local function sampleGui(labelText, gradePalette)
56
- local mouseOver = Instance.new("NumberValue")
57
- mouseOver.Value = 0
56
+ local mouseOver = ValueObject.new(0, "number")
58
57
  maid:GiveTask(mouseOver)
59
58
 
60
59
  local percentMouseOver = Blend.Spring(mouseOver, 60)
@@ -1,4 +1,11 @@
1
1
  --[=[
2
+ Helps with color grades, which is the concept where the darkness of the color
3
+ goes from 0 to 100, with a grade of 100 being white, and a grade of 0 being
4
+ black.
5
+
6
+ Grades ensure a human-readable contrast value which means a grade contrast
7
+ of 70 will always meet accessibility standards.
8
+
2
9
  @class ColorGradeUtils
3
10
  ]=]
4
11
 
@@ -8,6 +15,15 @@ local LuvColor3Utils = require("LuvColor3Utils")
8
15
 
9
16
  local ColorGradeUtils = {}
10
17
 
18
+ --[=[
19
+ Adds to the grade and picks the direction to ensure the best amount of contrast.
20
+ May consider using [ColorGradeUtils.ensureGradeContrast] for a more background
21
+ aware contrast picker.
22
+
23
+ @param grade number
24
+ @param difference number
25
+ @return Color3
26
+ ]=]
11
27
  function ColorGradeUtils.addGrade(grade, difference)
12
28
  local finalGrade = grade + difference
13
29
 
@@ -26,6 +42,48 @@ function ColorGradeUtils.addGrade(grade, difference)
26
42
  return finalGrade
27
43
  end
28
44
 
45
+ --[=[
46
+ Ensures the given contrast between the color and the backing, with
47
+ an adjustment to saturation to keep the UI loking good
48
+
49
+ @param color Color3
50
+ @param backing Color3
51
+ @param amount number -- Between 0 and 100
52
+ @return Color3
53
+ ]=]
54
+ function ColorGradeUtils.ensureGradeContrast(color, backing, amount)
55
+ local l, u, v = unpack(LuvColor3Utils.fromColor3(color))
56
+ local _, _, bv = unpack(LuvColor3Utils.fromColor3(backing))
57
+
58
+ local grade = 100 - v
59
+ local backingGrade = 100 - bv
60
+
61
+ local rel = grade - backingGrade
62
+
63
+ -- Increase
64
+ if math.abs(rel) >= amount then
65
+ return color
66
+ end
67
+
68
+ local newRel = math.sign(rel)*amount
69
+
70
+ local newGrade = math.clamp(backingGrade + newRel, 0, 100)
71
+ local otherNewGrade = math.clamp(backingGrade - newRel, 0, 100)
72
+
73
+ local finalGrade
74
+ if math.abs(newGrade - backingGrade) > math.abs(otherNewGrade - backingGrade) then
75
+ finalGrade = newGrade
76
+ else
77
+ finalGrade = otherNewGrade
78
+ end
79
+
80
+ -- The further away from the original color the more we reduce vividness
81
+ local proportion = math.min(amount, math.abs(finalGrade - grade))/amount
82
+ u = math.clamp((1 - 0.5*proportion)*u, 0, 100)
83
+
84
+ return LuvColor3Utils.toColor3({l, u, 100 - finalGrade})
85
+ end
86
+
29
87
  --[=[
30
88
  Gets the grade for a given color
31
89
 
@@ -39,6 +97,14 @@ function ColorGradeUtils.getGrade(color)
39
97
  return 100 - v
40
98
  end
41
99
 
100
+ --[=[
101
+ Converts a color into a graded version of that color.
102
+
103
+ @param baseColor Color3
104
+ @param colorGrade number -- 0 to 100
105
+ @param vividness number | nil
106
+ @return Color3
107
+ ]=]
42
108
  function ColorGradeUtils.getGradedColor(baseColor, colorGrade, vividness)
43
109
  assert(typeof(baseColor) == "Color3", "Bad baseColor")
44
110
  assert(type(vividness) == "number" or vividness == nil, "Bad vividness")