@lightningjs/blits 0.7.4 → 0.8.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ # v0.8.1
4
+
5
+ _9 mar 2024_
6
+
7
+ - Added pre-processing of hardcoded colors used in the template
8
+ - Upgraded Lightning renderer to v0.7.5
9
+ - Removed explicit destroy of child nodes, as the renderer now takes care of this
10
+ - Re-added support for clipping
11
+
12
+ # v0.8.0
13
+
14
+ _1 mar 2024_
15
+
16
+ - Added `this.$clearIntervals()` and `this.$clearTimeouts()` methods that clear all intervals and timers set on a certain component
17
+ - **Breaking change:** Renamed the key `function` to `easing` in the transitions object used to specify a custom easing functio (deprecation notice added)
18
+
3
19
  # v0.7.4
4
20
 
5
21
  _28 feb 2024_
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightningjs/blits",
3
- "version": "0.7.4",
3
+ "version": "0.8.1",
4
4
  "description": "Blits: The Lightning 3 App Development Framework",
5
5
  "bin": "bin/index.js",
6
6
  "exports": {
@@ -40,13 +40,12 @@
40
40
  "husky": "^7.0.4",
41
41
  "jsdom": "24.0.0",
42
42
  "lint-staged": "^12.3.3",
43
- "ora": "^7.0.1",
44
43
  "prettier": "^2.5.1",
45
44
  "tap-diff": "^0.1.1",
46
45
  "tape": "^5.5.0"
47
46
  },
48
47
  "dependencies": {
49
- "@lightningjs/renderer": "^0.7.4",
48
+ "@lightningjs/renderer": "^0.7.5",
50
49
  "@lightningjs/vite-plugin-import-chunk-url": "^0.3.0",
51
50
  "execa": "^8.0.1",
52
51
  "kolorist": "^1.8.0",
@@ -35,7 +35,7 @@ declare namespace Application {
35
35
  /**
36
36
  * Easing function to apply to the transition
37
37
  */
38
- function?: string,
38
+ easing?: string,
39
39
  /**
40
40
  * Delay before the transition starts in milliseconds
41
41
  */
package/src/element.js CHANGED
@@ -21,6 +21,21 @@ import colors from './lib/colors/colors.js'
21
21
  import { Log } from './lib/log.js'
22
22
  import symbols from './lib/symbols.js'
23
23
 
24
+ const deprecationMsg = `
25
+ ----------------------------------------------------------------------------------------------------
26
+ Deprecation notice:
27
+ ----------------------------------------------------------------------------------------------------
28
+
29
+ The property for defining a transition easing function has been renamed from "function" to "easing".
30
+
31
+ Please update your code like the example below to keep your custom easing function.
32
+
33
+ Before: <Element :y.transition=“{v: $y, function: ‘ease-in-out’}” />
34
+
35
+ After: <Element :y.transition=“{v: $y, easing: ‘ease-in-out’}” />
36
+
37
+ `
38
+
24
39
  const isTransition = (value) => {
25
40
  return typeof value === 'object' && 'transition' in value
26
41
  }
@@ -192,6 +207,9 @@ const Props = {
192
207
  })
193
208
  this._set.add('effects')
194
209
  },
210
+ set clipping(v) {
211
+ this._props.clipping = v
212
+ },
195
213
  set fontFamily(v) {
196
214
  this._props.fontFamily = v
197
215
  },
@@ -307,7 +325,9 @@ const Element = {
307
325
  easing:
308
326
  typeof transition === 'object'
309
327
  ? 'function' in transition
310
- ? transition.function
328
+ ? Log.warn(deprecationMsg)
329
+ : 'easing' in transition
330
+ ? transition.easing
311
331
  : 'ease'
312
332
  : 'ease',
313
333
  delay: typeof transition === 'object' ? ('delay' in transition ? transition.delay : 0) : 0,
@@ -19,52 +19,62 @@ import htmlColors from './htmlColors.js'
19
19
  import { Log } from '../log.js'
20
20
 
21
21
  export default {
22
- normalize(color = '') {
22
+ // The defaultColor parameter should be set to null when utilizing this function within the template parser.
23
+ // Because the template parser evaluates attribute values, even if they are not color codes,
24
+ // to determine whether they represent color values or not.
25
+ normalize(color = '', defaultColor = '0xffffffff') {
23
26
  color = color.toString()
24
27
 
25
- if (color.startsWith('0x')) {
26
- return color
27
- }
28
+ if (color.length > 0) {
29
+ const normalized = /^0x[0-9a-f]{8}$/
30
+ const hex = /^#?([0-9a-f]{3}|[0-9a-f]{6}|[0-9a-f]{8})$/i
31
+ const rgba =
32
+ /^(rgba?)\((\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\s*),(\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\s*),(\s*(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])\s*)(,(\s*(-?\d+(?:\.\d+)?)\s*))?\)$/
33
+ const hsla =
34
+ /^(hsla?)\((\s*(360|3[0-5][0-9]|[12]?[0-9]{1,2})\s*),(\s*(100|[1-9]?[0-9])\s*)%,(\s*(100|[1-9]?[0-9])\s*)%(,(\s*(1|0(?:\.\d+)?)\s*))?\)$/
35
+
36
+ if (normalized.test(color)) {
37
+ return color
38
+ }
28
39
 
29
- const rgbaRegex = /rgba?\((.+)\)/gi
30
- const hslaRegex = /hsla?\((.+)\)/gi
40
+ if (hex.test(color)) {
41
+ color = color.replace('#', '').toLowerCase()
42
+ if (color.length === 3) {
43
+ color = color
44
+ .split('')
45
+ .map((c) => c + c)
46
+ .join('')
47
+ }
31
48
 
32
- // RGB(A) color format
33
- if (rgbaRegex.test(color)) {
34
- const match = new RegExp(rgbaRegex).exec(color)
35
- if (match[1]) {
36
- color = match[1]
37
- .split(',')
38
- .map((c, i) => {
39
- if (i == 3) {
40
- c = Math.min(Math.max(Math.round(c * 255), 0), 255)
41
- }
42
- return parseInt(c).toString(16).padStart(2, '0')
43
- })
44
- .join('')
45
- return color.padEnd(8, 'f').padStart(10, '0x')
49
+ return '0x' + color.padEnd(8, 'f')
50
+ }
51
+
52
+ //rgb/a
53
+ const rgbaMatch = rgba.exec(color)
54
+ if (rgbaMatch) {
55
+ return (
56
+ '0x' +
57
+ parseInt(rgbaMatch[3]).toString(16).padStart(2, '0') +
58
+ parseInt(rgbaMatch[5]).toString(16).padStart(2, '0') +
59
+ parseInt(rgbaMatch[7]).toString(16).padStart(2, '0') +
60
+ (rgbaMatch[10] && rgbaMatch[1] === 'rgba'
61
+ ? Math.min(Math.max(Math.round(parseFloat(rgbaMatch[10]) * 255), 0), 255)
62
+ .toString(16)
63
+ .padStart(2, '0')
64
+ : 'ff')
65
+ )
66
+ }
67
+
68
+ if (hsla.test(color)) {
69
+ Log.warn('HSL(A) color format is not supported yet')
70
+ return '0xffffffff'
71
+ }
72
+
73
+ if (color in htmlColors) {
74
+ return htmlColors[color]
46
75
  }
47
- }
48
- // HSL(A) color format
49
- else if (hslaRegex.test(color)) {
50
- Log.warn('HSL(A) color format is not supported yet')
51
- return 0xffffffff
52
- }
53
- // HTMl name color format
54
- else if (color in htmlColors) {
55
- return htmlColors[color]
56
- }
57
- // hex rgba format
58
- else if (color.startsWith('#')) {
59
- color = color.substring(1)
60
- }
61
- if (color.length === 3) {
62
- color = color
63
- .split('')
64
- .map((c) => c + c)
65
- .join('')
66
76
  }
67
77
 
68
- return color.padEnd(8, 'f').padStart(10, '0x')
78
+ return defaultColor
69
79
  },
70
80
  }
@@ -27,8 +27,30 @@ test('Object', (assert) => {
27
27
  })
28
28
 
29
29
  test('6 character hex', (assert) => {
30
- const input = ['#ffffff', '#000000', '#c0ffee', '#7dd3fc', '#0c4a6e']
31
- const expected = ['0xffffffff', '0x000000ff', '0xc0ffeeff', '0x7dd3fcff', '0x0c4a6eff']
30
+ const input = [
31
+ '#ffffff',
32
+ '#000000',
33
+ '#c0ffee',
34
+ '#7dd3fc',
35
+ '#0c4a6e',
36
+ 'ffffff',
37
+ '000000',
38
+ 'c0ffee',
39
+ '7dd3fc',
40
+ '0c4a6e',
41
+ ]
42
+ const expected = [
43
+ '0xffffffff',
44
+ '0x000000ff',
45
+ '0xc0ffeeff',
46
+ '0x7dd3fcff',
47
+ '0x0c4a6eff',
48
+ '0xffffffff',
49
+ '0x000000ff',
50
+ '0xc0ffeeff',
51
+ '0x7dd3fcff',
52
+ '0x0c4a6eff',
53
+ ]
32
54
 
33
55
  const actual = input.map(colors.normalize)
34
56
 
@@ -41,8 +63,15 @@ test('6 character hex', (assert) => {
41
63
  })
42
64
 
43
65
  test('3 character hex', (assert) => {
44
- const input = ['#fff', '#000', '#c8c']
45
- const expected = ['0xffffffff', '0x000000ff', '0xcc88ccff']
66
+ const input = ['#fff', '#000', '#c8c', 'fff', '000', 'c8c']
67
+ const expected = [
68
+ '0xffffffff',
69
+ '0x000000ff',
70
+ '0xcc88ccff',
71
+ '0xffffffff',
72
+ '0x000000ff',
73
+ '0xcc88ccff',
74
+ ]
46
75
 
47
76
  const actual = input.map(colors.normalize)
48
77
 
@@ -55,8 +84,30 @@ test('3 character hex', (assert) => {
55
84
  })
56
85
 
57
86
  test('8 character hex (rgba)', (assert) => {
58
- const input = ['#ffffffff', '#000000ff', '#c0ffee80', '#7dd3fc10', '#0c4a6eff']
59
- const expected = ['0xffffffff', '0x000000ff', '0xc0ffee80', '0x7dd3fc10', '0x0c4a6eff']
87
+ const input = [
88
+ '#ffffffff',
89
+ '#000000ff',
90
+ '#c0ffee80',
91
+ '#7dd3fc10',
92
+ '#0c4a6eff',
93
+ 'ffffffff',
94
+ '000000ff',
95
+ 'c0ffee80',
96
+ '7dd3fc10',
97
+ '0c4a6eff',
98
+ ]
99
+ const expected = [
100
+ '0xffffffff',
101
+ '0x000000ff',
102
+ '0xc0ffee80',
103
+ '0x7dd3fc10',
104
+ '0x0c4a6eff',
105
+ '0xffffffff',
106
+ '0x000000ff',
107
+ '0xc0ffee80',
108
+ '0x7dd3fc10',
109
+ '0x0c4a6eff',
110
+ ]
60
111
 
61
112
  const actual = input.map(colors.normalize)
62
113
 
@@ -68,6 +119,44 @@ test('8 character hex (rgba)', (assert) => {
68
119
  assert.end()
69
120
  })
70
121
 
122
+ test('Invalid hex values', (assert) => {
123
+ const input = [
124
+ '#fde4',
125
+ '#1000',
126
+ '#ddc8c',
127
+ 'hg0',
128
+ '000fffa',
129
+ '#a',
130
+ '#0',
131
+ 'c8O',
132
+ 'fffff',
133
+ '000f00000',
134
+ '##000000',
135
+ ]
136
+ const expected = [
137
+ '0xffffffff',
138
+ '0xffffffff',
139
+ '0xffffffff',
140
+ '0xffffffff',
141
+ '0xffffffff',
142
+ '0xffffffff',
143
+ '0xffffffff',
144
+ '0xffffffff',
145
+ '0xffffffff',
146
+ '0xffffffff',
147
+ '0xffffffff',
148
+ ]
149
+
150
+ const actual = input.map((color) => colors.normalize(color))
151
+
152
+ assert.deepEqual(
153
+ actual,
154
+ expected,
155
+ 'Invalid hex values should return white color as the default color'
156
+ )
157
+ assert.end()
158
+ })
159
+
71
160
  test('RGB colors', (assert) => {
72
161
  const input = [
73
162
  'rgb(255,255,255)',
@@ -80,23 +169,35 @@ test('RGB colors', (assert) => {
80
169
 
81
170
  const actual = input.map(colors.normalize)
82
171
 
83
- assert.deepEqual(
84
- actual,
85
- expected,
86
- 'RGB codes prefixed with # should return the correct color in rgba format'
87
- )
172
+ assert.deepEqual(actual, expected, 'RGB codes should return the correct color in rgba format')
173
+ assert.end()
174
+ })
175
+
176
+ test('Invalid RGB colors', (assert) => {
177
+ const input = [
178
+ 'rgb(256,255,255)',
179
+ 'rgb(123,432,211)',
180
+ 'rgb(192, 255)',
181
+ 'rgb(125,, 211, 252)',
182
+ 'rgb(-12, 74, 110)',
183
+ ]
184
+ const expected = ['0xffffffff', '0xffffffff', '0xffffffff', '0xffffffff', '0xffffffff']
185
+
186
+ const actual = input.map((color) => colors.normalize(color))
187
+
188
+ assert.deepEqual(actual, expected, 'Invalid RGB codes should return white color in rgba format')
88
189
  assert.end()
89
190
  })
90
191
 
91
192
  test('RGBA colors', (assert) => {
92
193
  const input = [
93
- 'rgb(255,255,255,1)',
94
- 'rgb(0,0,0,1)',
95
- 'rgb(192, 255, 238, 0.5)',
96
- 'rgb(125, 211, 252, 0.1)',
97
- 'rgb(12, 74, 110, 0)',
98
- 'rgb(12, 74, 110, -0.5)', // negative alpha should become 0
99
- 'rgb(12, 74, 110, 1.2)', // highher than 1 alpha should become 1
194
+ 'rgba(255,255,255,1)',
195
+ 'rgba(0,0,0,1)',
196
+ 'rgba(192, 255, 238, 0.5)',
197
+ 'rgba(125, 211, 252, 0.1)',
198
+ 'rgba(12, 74, 110, 0)',
199
+ 'rgba(12, 74, 110, -0.5)', // negative alpha should become 0
200
+ 'rgba(12, 74, 110, 1.2)', // highher than 1 alpha should become 1
100
201
  ]
101
202
  const expected = [
102
203
  '0xffffffff',
@@ -110,61 +211,60 @@ test('RGBA colors', (assert) => {
110
211
 
111
212
  const actual = input.map(colors.normalize)
112
213
 
113
- assert.deepEqual(
114
- actual,
115
- expected,
116
- 'RGB codes prefixed with # should return the correct color in rgba format'
117
- )
214
+ assert.deepEqual(actual, expected, 'RGBA codes should return the correct color in rgba format')
118
215
  assert.end()
119
216
  })
120
217
 
121
- test('RGBA colors', (assert) => {
218
+ test('Invalid RGBA colors', (assert) => {
122
219
  const input = [
123
220
  'rgb(255,255,255,1)',
124
- 'rgb(0,0,0,1)',
125
- 'rgb(192, 255, 238, 0.5)',
126
- 'rgb(125, 211, 252, 0.1)',
127
- 'rgb(12, 74, 110, 0)',
128
- 'rgb(12, 74, 110, -0.5)', // negative alpha should become 0
129
- 'rgb(12, 74, 110, 1.2)', // highher than 1 alpha should become 1
221
+ 'rgba(0,0,0,a)',
222
+ 'rgba(192, 256, 238, 0.5)',
223
+ 'rgba(125, 252, 0.1)',
224
+ 'rgba(12,, 74, 110, 0)',
225
+ 'rgba(-12, 74, 110, -0.5)',
226
+ 'rgba(12, 74, 110, --1.2)',
130
227
  ]
131
228
  const expected = [
132
229
  '0xffffffff',
133
- '0x000000ff',
134
- '0xc0ffee80',
135
- '0x7dd3fc1a',
136
- '0x0c4a6e00',
137
- '0x0c4a6e00',
138
- '0x0c4a6eff',
230
+ '0xffffffff',
231
+ '0xffffffff',
232
+ '0xffffffff',
233
+ '0xffffffff',
234
+ '0xffffffff',
235
+ '0xffffffff',
139
236
  ]
140
237
 
238
+ const actual = input.map((color) => colors.normalize(color))
239
+
240
+ assert.deepEqual(actual, expected, 'Invalid RGBA codes should return white color in rgba format')
241
+ assert.end()
242
+ })
243
+
244
+ test('HTML colors', (assert) => {
245
+ const input = ['blanchedalmond', 'salmon', 'tomato', 'saddlebrown', 'red']
246
+ const expected = ['0xffebcdff', '0xfa8072ff', '0xff6347ff', '0x8b4513ff', '0xff0000ff']
247
+
141
248
  const actual = input.map(colors.normalize)
142
249
 
143
250
  assert.deepEqual(
144
251
  actual,
145
252
  expected,
146
- 'RGB codes prefixed with # should return the correct color in rgba format'
253
+ 'HTML color codes should return the correct color in rgba format'
147
254
  )
148
255
  assert.end()
149
256
  })
150
257
 
151
- test('HTML colors', (assert) => {
152
- const input = ['blanchedalmond', 'salmon', 'tomato', 'saddlebrown', 'red']
258
+ test('Invalid HTML colors', (assert) => {
259
+ const input = ['darkblanchedalmond', 'selmon', 'lighttomato', 'sadlebrown', 'darkbrown']
260
+ const expected = ['0xffffffff', '0xffffffff', '0xffffffff', '0xffffffff', '0xffffffff']
153
261
 
154
- const expected = [
155
- parseInt('0xffebcdff', 16),
156
- parseInt('0xfa8072ff', 16),
157
- parseInt('0xff6347ff', 16),
158
- parseInt('0x8b4513ff', 16),
159
- parseInt('0xff0000ff', 16),
160
- ]
161
-
162
- const actual = input.map(colors.normalize)
262
+ const actual = input.map((color) => colors.normalize(color))
163
263
 
164
264
  assert.deepEqual(
165
265
  actual,
166
266
  expected,
167
- 'RGB codes prefixed with # should return the correct color in rgba format'
267
+ 'Invalid HTML color codes should return white color in rgba format'
168
268
  )
169
269
  assert.end()
170
270
  })