@lightningjs/blits 0.10.0 → 1.0.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/docs/essentials/displaying_text.md +1 -1
  3. package/package.json +3 -3
  4. package/src/component/base/events.js +1 -1
  5. package/src/component/base/utils.js +34 -1
  6. package/src/component/setup/props.js +3 -1
  7. package/src/component/setup/props.test.js +51 -19
  8. package/src/component.d.ts +2 -1
  9. package/src/component.js +20 -13
  10. package/src/components/Circle.js +13 -12
  11. package/src/components/FPScounter.js +388 -536
  12. package/src/components/Image.js +7 -9
  13. package/src/components/Layout.js +49 -0
  14. package/src/components/Layout.orig.js +34 -0
  15. package/src/components/RouterView.js +6 -10
  16. package/src/components/Sprite.js +10 -12
  17. package/src/components/index.js +2 -2
  18. package/src/components/index.orig.js +2 -2
  19. package/src/engine.js +1 -1
  20. package/src/engines/L3/element.js +193 -180
  21. package/src/engines/L3/element.test.js +170 -0
  22. package/src/engines/L3/fontLoader.js +4 -5
  23. package/src/engines/L3/index.js +2 -2
  24. package/src/engines/L3/launch.js +7 -13
  25. package/src/engines/L3/shaderLoader.js +12 -0
  26. package/src/engines/index.js +1 -1
  27. package/src/launch.d.ts +19 -2
  28. package/src/lib/codegenerator/generator.js +212 -84
  29. package/src/lib/codegenerator/generator.test.js +657 -942
  30. package/src/lib/colors/colors.js +59 -46
  31. package/src/lib/precompiler/precompiler.js +2 -1
  32. package/src/lib/reactivity/effect.js +10 -13
  33. package/src/lib/reactivity/reactive.js +24 -14
  34. package/src/lib/symbols.js +1 -0
  35. package/src/router/router.js +17 -3
  36. package/boilerplate/js/default/src/renderer.js +0 -4
  37. package/src/components/Text.js +0 -119
  38. package/src/components/Text.orig.js +0 -81
@@ -0,0 +1,170 @@
1
+ /*
2
+ * Copyright 2023 Comcast Cable Communications Management, LLC
3
+ * Licensed under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License.
5
+ * You may obtain a copy of the License at
6
+ *
7
+ * http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ *
15
+ * SPDX-License-Identifier: Apache-2.0
16
+ */
17
+
18
+ import test from 'tape'
19
+ import element from './element.js'
20
+ import { renderer } from './launch.js'
21
+ import { EventEmitter } from 'node:events'
22
+ import { initLog } from '../../lib/log.js'
23
+ import symbols from '../../lib/symbols.js'
24
+
25
+ initLog()
26
+
27
+ test('Type', (assert) => {
28
+ assert.ok(element instanceof Function, 'Element should be a factory function')
29
+ assert.end()
30
+ })
31
+
32
+ test('Destroy', (assert) => {
33
+ const el = element({}, {})
34
+ el.node = { destroy: () => {} }
35
+ const capture = assert.capture(el.node, 'destroy')
36
+
37
+ el.destroy()
38
+
39
+ const calls = capture()
40
+ assert.ok(calls.length > 0, 'Node destroy should be invoked')
41
+ assert.end()
42
+ })
43
+
44
+ test('NodeId', (assert) => {
45
+ const el = element({}, {})
46
+ el.node = { id: 123 }
47
+
48
+ const result = el.nodeId
49
+
50
+ assert.equal(result, 123, 'NodeId should be correct')
51
+ assert.end()
52
+ })
53
+
54
+ test('Ref', (assert) => {
55
+ const el = element({}, {})
56
+ el.props = { ref: 123 }
57
+
58
+ const result = el.ref
59
+
60
+ assert.equal(result, 123, 'Ref should be correct')
61
+ assert.end()
62
+ })
63
+
64
+ test('Parent', (assert) => {
65
+ const el = element({}, {})
66
+ el.node = { parent: 'foo' }
67
+
68
+ const result = el.parent
69
+
70
+ assert.equal(result, 'foo', 'Parent should be correct')
71
+ assert.end()
72
+ })
73
+
74
+ test('Children', (assert) => {
75
+ const el = element({}, {})
76
+ el.node = 'foo'
77
+ el.component[symbols.getChildren] = () => [
78
+ { id: 0, parent: 'bar' },
79
+ { id: 1, parent: 'foo' },
80
+ { id: 2, parent: undefined },
81
+ { id: 3, parent: 0 },
82
+ { id: 4, parent: 'foo' },
83
+ ]
84
+
85
+ const result = el.children
86
+
87
+ assert.equal(result.length, 2, 'Children amount should be correct')
88
+ assert.deepEqual(
89
+ result.map((c) => c.id),
90
+ [1, 4],
91
+ 'Children should be correct'
92
+ )
93
+ assert.end()
94
+ })
95
+
96
+ test('Element - Set `w` property', (assert) => {
97
+ assert.capture(renderer, 'createNode', () => new EventEmitter())
98
+ const el = createElement()
99
+
100
+ el.set('w', 100)
101
+
102
+ assert.equal(el.node['width'], 100, 'Node width parameter should be set')
103
+ assert.equal(el.props.props['width'], 100, 'Props width parameter should be set')
104
+ assert.equal(el.props.raw.get('w'), 100, "Props' raw map entry should be added")
105
+ assert.end()
106
+ })
107
+
108
+ test('Element - Set `mount` property', (assert) => {
109
+ assert.capture(renderer, 'createNode', () => new EventEmitter())
110
+ const el = createElement()
111
+ const value = { x: 10, y: 20 }
112
+
113
+ el.set('mount', value)
114
+
115
+ assert.equal(el.node['mountX'], 10, 'Node mountX parameter should be set')
116
+ assert.equal(el.node['mountY'], 20, 'Node mountY parameter should be set')
117
+ assert.equal(el.props.props['mountX'], 10, 'Props mountX parameter should be set')
118
+ assert.equal(el.props.props['mountY'], 20, 'Props mountY parameter should be set')
119
+ assert.equal(el.props.raw.get('mount'), value, "Props' raw map entry should be added")
120
+ assert.end()
121
+ })
122
+
123
+ test('Element - Set `color` property', (assert) => {
124
+ assert.capture(renderer, 'createNode', () => new EventEmitter())
125
+ const el = createElement()
126
+
127
+ el.set('color', 'azure')
128
+
129
+ assert.equal(el.node['color'], '0xf0ffffff', 'Node color parameter should be set')
130
+ assert.equal(el.props.props['color'], '0xf0ffffff', 'Props color parameter should be set')
131
+ assert.equal(el.props.raw.get('color'), 'azure', "Props' raw map entry should be added")
132
+ assert.end()
133
+ })
134
+
135
+ test('Element - Set `src` property', (assert) => {
136
+ assert.capture(renderer, 'createNode', () => new EventEmitter())
137
+ const el = createElement()
138
+ const value = 'file://foo.html'
139
+
140
+ el.set('src', value)
141
+
142
+ assert.equal(el.node['src'], value, 'Node src parameter should be set')
143
+ assert.equal(el.props.props['src'], value, 'Props src parameter should be set')
144
+ assert.equal(el.props.raw.get('src'), value, "Props' raw map entry should be added")
145
+ assert.equal(el.props.props['color'], 0xffffffff, 'Props default color parameter should be set')
146
+ assert.end()
147
+ })
148
+
149
+ test('Element - Set `texture` property', (assert) => {
150
+ assert.capture(renderer, 'createNode', () => new EventEmitter())
151
+ const el = createElement()
152
+
153
+ el.set('texture', 'foo')
154
+
155
+ assert.equal(el.node['texture'], 'foo', 'Node texture parameter should be set')
156
+ assert.equal(el.props.props['texture'], 'foo', 'Props texture parameter should be set')
157
+ assert.equal(el.props.raw.get('texture'), 'foo', "Props' raw map entry should be added")
158
+ assert.equal(el.props.props['color'], 0xffffffff, 'Props default color parameter should be set')
159
+ assert.end()
160
+ })
161
+
162
+ function createElement() {
163
+ const el = element({}, {})
164
+ el.populate({
165
+ parent: {
166
+ node: new EventEmitter(),
167
+ },
168
+ })
169
+ return el
170
+ }
@@ -1,10 +1,9 @@
1
- import { WebTrFontFace, SdfTrFontFace } from '@lightningjs/renderer/core'
2
-
3
- import Settings from '../../settings'
4
- import { renderer } from './launch'
1
+ import { SdfTrFontFace, WebTrFontFace } from '@lightningjs/renderer'
2
+ import Settings from '../../settings.js'
3
+ import { renderer } from './launch.js'
5
4
 
6
5
  export default () => {
7
- const stage = renderer.driver.stage
6
+ const stage = renderer.stage
8
7
  Settings.get('fonts', []).forEach((font) => {
9
8
  if (font.type === 'sdf' || font.type === 'msdf') {
10
9
  // automatically map png key to file name
@@ -1,5 +1,5 @@
1
- import Element from './element'
2
- import Launch from './launch'
1
+ import Element from './element.js'
2
+ import Launch from './launch.js'
3
3
 
4
4
  export default {
5
5
  Element,
@@ -15,23 +15,16 @@
15
15
  * SPDX-License-Identifier: Apache-2.0
16
16
  */
17
17
 
18
- import { MainCoreDriver, RendererMain } from '@lightningjs/renderer'
19
- // import RendererWorker from '@lightningjs/renderer/workers/renderer?worker'
18
+ import { RendererMain } from '@lightningjs/renderer'
20
19
  import { Log } from '../../lib/log.js'
21
20
  import { screenResolutions } from '../../lib/utils.js'
22
21
  import colors from '../../lib/colors/colors.js'
23
22
  import fontLoader from './fontLoader.js'
23
+ import shaderLoader from './shaderLoader.js'
24
24
 
25
- export let renderer
25
+ export let renderer = {}
26
26
 
27
27
  export default (App, target, settings = {}) => {
28
- const driver = new MainCoreDriver()
29
- // settings.multithreaded === true
30
- // ? new ThreadXRenderDriver({
31
- // RendererWorker,
32
- // })
33
- // : new MainRenderDriver()
34
-
35
28
  if ('fontLoader' in settings) {
36
29
  Log.warn(
37
30
  `
@@ -64,8 +57,7 @@ You can remove the option from your \`src/index.js\`-file. And you can safely re
64
57
  'gpuMemoryLimit' in settings ? settings.gpuMemoryLimit * 1024 * 1024 : 200 * 1024 * 1024,
65
58
  renderMode: 'renderMode' in settings ? settings.renderMode : 'webgl',
66
59
  },
67
- target,
68
- driver
60
+ target
69
61
  )
70
62
 
71
63
  const initApp = () => {
@@ -78,7 +70,9 @@ You can remove the option from your \`src/index.js\`-file. And you can safely re
78
70
  }
79
71
  }
80
72
 
81
- renderer.init().then(fontLoader).then(initApp)
73
+ shaderLoader()
74
+ fontLoader()
75
+ initApp()
82
76
 
83
77
  return renderer
84
78
  }
@@ -0,0 +1,12 @@
1
+ import Settings from '../../settings.js'
2
+ import { renderer } from './launch.js'
3
+
4
+ export default () => {
5
+ const stage = renderer.stage
6
+ Settings.get('shaders', []).forEach((shader) => {
7
+ stage.shManager.registerShaderType(shader.name, shader.type)
8
+ })
9
+ Settings.get('effects', []).forEach((effect) => {
10
+ stage.shManager.registerShaderType(effect.name, effect.type)
11
+ })
12
+ }
@@ -1 +1 @@
1
- export { default as L3 } from './L3'
1
+ export { default as L3 } from './L3/index.js'
package/src/launch.d.ts CHANGED
@@ -16,7 +16,7 @@
16
16
  */
17
17
 
18
18
  import ApplicationInstance from './application'
19
- import {type Stage} from '@lightningjs/renderer'
19
+ import {type Stage, type ShaderEffect as RendererShaderEffect, type WebGlCoreShader} from '@lightningjs/renderer'
20
20
  interface WebFont {
21
21
  /**
22
22
  * Name of the font family
@@ -61,6 +61,15 @@ type SdfFont = {
61
61
  type: 'msdf' | 'sdf',
62
62
  } & (SdfFontWithFile | SdfFontWithPngJson)
63
63
 
64
+ type Shader = {
65
+ name: string,
66
+ type: WebGlCoreShader
67
+ }
68
+
69
+ type ShaderEffect = {
70
+ name: string,
71
+ type: RendererShaderEffect
72
+ }
64
73
 
65
74
  type ScreenResolutions = 'hd' | '720p' | 720 | 'fhd' | 'fullhd' | '1080p' | 1080 | '4k' | '2160p' | 2160
66
75
 
@@ -101,13 +110,21 @@ export interface Settings {
101
110
  * Fonts to be used in the Application
102
111
  */
103
112
  fonts?: Font[],
113
+ /**
114
+ * Effects to be used by DynamicShader
115
+ */
116
+ effects?: ShaderEffect[],
117
+ /**
118
+ * Shaders to be used in the application
119
+ */
120
+ shaders?: Shader[],
104
121
  /**
105
122
  * Default font family to use in the Application when no font attribute is specified
106
123
  * on a Text-component
107
124
  *
108
125
  * The default font must be registered in the `fonts` array in the settings.
109
126
  *
110
- * Defaults to `lato` font family
127
+ * Defaults to `sans-serif` font family, which is the default of the Lightning Renderer
111
128
  */
112
129
  defaultFont?: string,
113
130
  /**